[
  {
    "path": "build-firmware.sh",
    "content": "#!/bin/bash\n\nDIR=\"$1\"\nNEXT_PARAM=\"\"\n\nif [ \"$1\" == \"-h\" ]\nthen\n\techo \"Usage: $0 [FMK directory] [-nopad | -min]\"\n\texit 1\nfi\n\nif [ \"$DIR\" == \"\" ] || [ \"$DIR\" == \"-nopad\" ] || [ \"$DIR\" == \"-min\" ]\nthen\n\tDIR=\"fmk\"\n\tNEXT_PARAM=\"$1\"\nelse\n\tNEXT_PARAM=\"$2\"\nfi\n\n# Need to extract file systems as ROOT\nif [ \"$UID\" != \"0\" ]\nthen\n        SUDO=\"sudo\"\nelse\n        SUDO=\"\"\nfi\n\nDIR=$(readlink -f $DIR)\n\n# Make sure we're operating out of the FMK directory\ncd $(dirname $(readlink -f $0))\n\n# Order matters here!\neval $(cat shared-ng.inc)\neval $(cat $CONFLOG)\nFSOUT=\"$DIR/new-filesystem.$FS_TYPE\"\n\nprintf \"Firmware Mod Kit (build-ng) ${VERSION}, (c)2011-2013 Craig Heffner, Jeremy Collake\\n\\n\"\n\nif [ ! -d \"$DIR\" ]\nthen\n\techo -e \"Usage: $0 [build directory] [-nopad]\\n\"\n\texit 1\nfi\n\n# Check if FMK has been built, and if not, build it\nif [ ! -e \"./src/crcalc/crcalc\" ]\nthen\n\techo \"Firmware-Mod-Kit has not been built yet. Building...\"\n\tcd src && ./configure && make\n\n\tif [ $? -eq 0 ]\n\tthen\n\t\tcd -\n\telse\n\t\techo \"Build failed! Quitting...\"\n\t\texit 1\n\tfi\nfi\n\necho \"Building new $FS_TYPE file system...\"\n\n# Clean up any previously created files\nrm -rf \"$FWOUT\" \"$FSOUT\"\n\n# Build the appropriate file system\ncase $FS_TYPE in\n\t\"squashfs\")\n\t\t# Check for squashfs 4.0 realtek, which requires the -comp option to build lzma images.\n\t\tif [ \"$(echo $MKFS | grep 'squashfs-4.0-realtek')\" != \"\" ] && [ \"$FS_COMPRESSION\" == \"lzma\" ]\n\t\tthen\n\t\t\tCOMP=\"-comp lzma\"\n\t\telse\n\t\t\tCOMP=\"\"\n\t\tfi\n\n\t\t# Mksquashfs 4.0 tools don't support the -le option; little endian is built by default\n\t\tif [ \"$(echo $MKFS | grep 'squashfs-4.')\" != \"\" ] && [ \"$ENDIANESS\" == \"-le\" ]\n\t\tthen\n\t\t\tENDIANESS=\"\"\n\t\tfi\n\t\t\n\t\t# Increasing the block size minimizes the resulting image size (larger dictionary). Max block size of 1MB.\n\t\tif [ \"$NEXT_PARAM\" == \"-min\" ]\n\t\tthen\n\t\t\techo \"Blocksize override (-min). Original used $((FS_BLOCKSIZE/1024))KB blocks. New firmware uses 1MB blocks.\"\n\t\t\tFS_BLOCKSIZE=\"$((1024*1024))\"\n\t\tfi\n\n\t\t# if blocksize var exists, then add '-b' parameter\n                if [ \"$FS_BLOCKSIZE\" != \"\" ]\n\t\tthen\n\t\t\tBS=\"-b $FS_BLOCKSIZE\"\n\t\tfi\n\n\t\t$SUDO $MKFS \"$ROOTFS\" \"$FSOUT\" $ENDIANESS $BS $COMP -all-root\n\t\t;;\n\t\"cramfs\")\n\t\t$SUDO $MKFS \"$ROOTFS\" \"$FSOUT\"\n\t\tif [ \"$ENDIANESS\" == \"-be\" ]\n\t\tthen\n\t\t\tmv \"$FSOUT\" \"$FSOUT.le\"\n\t\t\t./src/cramfsswap/cramfsswap \"$FSOUT.le\" \"$FSOUT\"\n\t\t\trm -f \"$FSOUT.le\"\n\t\tfi\n\t\t;;\n\t*)\n\t\techo \"Unsupported file system '$FS_TYPE'!\"\n\t\t;;\nesac\n\nif [ ! -e $FSOUT ]\nthen\n\techo \"Failed to create new file system! Quitting...\"\n\texit 1\nfi\n\n# Append the new file system to the first part of the original firmware file\ncp $HEADER_IMAGE $FWOUT\n$SUDO cat $FSOUT >> $FWOUT\n\n# Calculate and create any filler bytes required between the end of the file system and the footer / EOF.\nCUR_SIZE=$(ls -l $FWOUT | awk '{print $5}')\n((FILLER_SIZE=$FW_SIZE-$CUR_SIZE-$FOOTER_SIZE))\n\nif [ \"$FILLER_SIZE\" -lt 0 ]\nthen\n\techo \"ERROR: New firmware image will be larger than original image!\"\n\techo \"       Building firmware images larger than the original can brick your device!\"\n\techo \"       Try re-running with the -min option, or remove any unnecessary files from the file system.\"\n\techo \"       Refusing to create new firmware image.\"\n\techo \"\"\n\techo \"       Original file size: $FW_SIZE\"\n\techo \"       Current file size:  $CUR_SIZE\"\n\techo \"\"\n\techo \"       Quitting...\"\n\trm -f \"$FWOUT\" \"$FSOUT\"\n\texit 1\nelse\n\tif [ \"$NEXT_PARAM\" != \"-nopad\" ]; then\n\t\techo \"Remaining free bytes in firmware image: $FILLER_SIZE\"\n\t\tperl -e \"print \\\"\\xFF\\\"x$FILLER_SIZE\" >> \"$FWOUT\"\n\telse\n\t\techo \"Padding of firmware image disabled via -nopad\"\n\tfi\t\nfi\n\n# Append the footer to the new firmware image, if there is any footer\nif [ \"$FOOTER_SIZE\" -gt \"0\" ]\nthen\n\tcat $FOOTER_IMAGE >> \"$FWOUT\"\nfi\n\n# Calculate new checksum values for the firmware header\n# trx, dlob, uimage\n./src/crcalc/crcalc \"$FWOUT\" \"$BINLOG\"\n\nif [ $? -eq 0 ]\nthen\n\techo -n \"Finished! \"\nelse\n\techo -n \"Firmware header not supported; firmware checksums may be incorrect. \"\nfi\n\n# if a Buffalo image, then run encrypter - base on image name\nif [ \"$(echo $FWOUT | grep -i 'buffalo')\" != \"\" ]\nthen\t\n\t# product name, version, key, encryption type can be specified here\n\t$KEY=\"\" # specify full param, e.g. -k mykey\n\t$MAGIC=\"\"\n\t$PRODUCT=\"\"\n\t$LONGSTATE=\"\"\n\t./src/firmware-tools/buffalo-enc -i $FWOUT -o $FWOUT.buffalo.enc $KEY $MAGIC $PRODUCT $LONGSTATE\n\t#if [ $? -eq 0 ]\n\t#then\n\t#\techo \"Encrypted Buffalo image created.\"\n\t#else\n\t#\techo \"ERROR creating an encrypted Buffalo image\"\n\t#fi\nfi\n\necho \"New firmware image has been saved to: $FWOUT\"\n"
  },
  {
    "path": "check_for_upgrade.sh",
    "content": "#!/bin/sh\n## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\n# 20110224-1507-MCT - Needed quotes around a string compare.\n## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\necho \" Checking for updates ...\"\nmkdir update_check\ncd update_check\nSYSNAME=`uname`\nif [ `expr \"$SYSNAME\" : \"Darwin\"` = 6 ]; then\n\tcurl -O -s --connect-timeout 4 --retry 1 http://firmware-mod-kit.googlecode.com/svn/trunk/firmware_mod_kit_version.txt\nelse\n\twget --quiet --timeout=4 --tries=1 http://firmware-mod-kit.googlecode.com/svn/trunk/firmware_mod_kit_version.txt\nfi\ncd ..\nif [ ! -f \"update_check/firmware_mod_kit_version.txt\" ]; then\n\techo \"  ! WARNING: Could not check for update. No connectivity or server down?\"\n\trm -rf update_check\n\texit 1\nfi\nNEW_VERSION=`cat update_check/firmware_mod_kit_version.txt`\nCUR_VERSION=`cat firmware_mod_kit_version.txt`\nif [ \"$NEW_VERSION\" != \"$CUR_VERSION\" ]; then\n\techo \"  !!! There is a newer version available: $NEW_VERSION\"\n\techo \"     You are currently using $CUR_VERSION\"\nelse\n\techo \"  You have the latest version of this kit.\"\nfi\nrm -rf update_check\nexit 0\n"
  },
  {
    "path": "cleanup.sh",
    "content": "#!/bin/sh\n. ./shared.inc\nCleanup\n"
  },
  {
    "path": "creating_ipkg_packages.htm",
    "content": "<html>\n\n<head>\n<meta http-equiv=\"Content-Language\" content=\"en-us\">\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">\n<title>Creating IPKs</title>\n</head>\n\n<body>\n\n<p><b><font size=\"5\">IPK Creation Kit</font><br>\n</b>(c)2006 Jeremy Collake &lt;<a href=\"mailto:jeremy.collake@gmail.com\">jeremy.collake@gmail.com</a>&gt;<br>\n<br>\n<font color=\"#FF0000\">!!! <b>ALPHA STAGE OF DEVELOPMENT. MAY NOT WORK AND HAVE \nMANY PROBLEMS</b> !!!</font></p>\n<p>This document attempts to outline the process of creation of IPKG format \npackages with the IPK Creation Kit, giving specific emphasis on usage for \nembedded linux platforms such as <a href=\"http://www.openwrt.org\">OpenWrt</a> \nand <a href=\"http://www.dd-wrt.com\">DD-WRT</a>. It is a quick draft intended to \nencourage people to develop IPKs specific to certain firmwares for use with the\n<a href=\"http://www.bitsum.com/firmware_mod_kit.htm\">Firmware Modification Kit</a>, \na kit that allows easy modification of firmware images without recompiling the \nsources.</p>\n<p><b><font size=\"4\">The structure of an IPK</font></b></p>\n<p>IPK files are <b><i>archives</i></b> containing the following:</p>\n<ul>\n\t<li><u><b>data.tar.gz</b></u> :&nbsp; contains data.tar:<ul>\n\t\t<li><u><b>data.tar</b></u> : These are the files that will be installed \n\t\tto, or removed from, the file system. They are in their correct \n\t\tlocations in the directory tree starting at the root of the firmware \n\t\tfile system. For example:<ul>\n\t\t\t<li><font face=\"Courier\"><b>./</b>usr/sbin/package<br>\n\t\t\t./tmp/package_config<br>\n\t\t\t./etc/package_config <i>-&gt; symbolic link</i> -&gt; ../tmp/config_folder<br>\n\t\t\t./tmp/package_config/package.conf<br>\n\t\t\tNOTE: </font><i>the &quot;.&quot; directory must be included in the path names</i></li>\n\t\t</ul>\n\t\t</li>\n\t</ul>\n\t</li>\n\t<li><b><u>control.tar.gz</u> </b>: contains control.tar:<ul>\n\t\t<li><u><b>control.tar</b></u> : These are files which give information \n\t\tabout the package. For examples, it's name, version, and dependencies.<ul>\n\t\t\t<li>./control : describes the package</li>\n\t\t\t<li>./conffiles : indicates which files in the package are used for \n\t\t\tconfig files once installed</li>\n\t\t</ul>\n\t\t</li>\n\t</ul>\n\t</li>\n\t<li><b><u>debian_binary</u> </b>: the reason this exists is unknown. It's \n\tperhaps some platform or format indicator. It is a text file that consists \n\tof &quot;2.0&quot;. </li>\n</ul>\n<p>&nbsp;</p>\n<p><b><font size=\"4\">Using the IPK template</font></b></p>\n<p>The IPK template directory contained in the Firmware Modification Kit makes \nit particularly easy to create IPK files without having to manually create them \neach time.</p>\n<p><b><font size=\"4\">Creating your own IPK</font></b></p>\n<blockquote>\n\t<p><b><font size=\"4\">Step 1</font></b></p>\n\t<p>Copy or extract the IPK template directory to a new directory named after \n\tthe package you are creating an IPK for. If you are copying, use &quot;cp -r&quot; to \n\tcopy the entire directory and all its contents.</p>\n\t<p><b><font size=\"4\">Step 2</font></b></p>\n\t<p>In the new directory edit the &quot;<i>control</i>&quot; and &quot;<i>conffiles</i>&quot; \n\ttext files appropriately. The fields in &quot;control&quot; are probably \n\tself-explanatory:</p>\n\t<p><i><b>control:</b></i></p>\n\t<table border=\"0\" width=\"100%\" bgcolor=\"#FFFFCC\" id=\"table5\">\n\t\t<tr>\n\t\t\t<td><br>\n\t\t\t<font face=\"Courier\">Package: somepackage<br>\n\t\t\tPriority: optional<br>\n\t\t\tDepends: libpcap libncurses<br>\n\t\t\tSection: net<br>\n\t\t\tDescription: A minimal and secure package of great sorts.<br>\n\t\t\tMaintainer: Junior Jim-Bob &lt;juniorjim.bob.com&gt;<br>\n\t\t\tSource: N/A<br>\n\t\t\tVersion: 2.61-1<br>\n\t\t\tArchitecture: mipsel<br>\n&nbsp;</font></td>\n\t\t</tr>\n\t</table>\n\t<p>If you want to get fancy, the<i> Source</i> field can indicate a URL to \n\tdownload the data.tar.gz portion of the package. If instead the package \n\tfiles are included inside the PKG, leave &quot;N/A&quot; in this field.</p>\n\t<p>&quot;conffiles&quot; contains a listing of files in the package that are used for \n\tconfiguration storage. This is helpful to preserve the configuration of the \n\tpackage if it is updated, or if the configuration otherwise needs \n\tpreserving. It might look something like this after editing:</p>\n\t<p><i><b>conffiles:</b></i></p>\n\t<table border=\"0\" width=\"100%\" bgcolor=\"#FFFFCC\" id=\"table6\">\n\t\t<tr>\n\t\t\t<td><br>\n\t\t\t<font face=\"Courier\">/etc/package_config/package.conf<br>\n\t\t\t/etc/package_config/moreconfig.conf<br>\n&nbsp;</font></td>\n\t\t</tr>\n\t</table>\n\t<p><b><font size=\"4\">Step 3</font></b></p>\n\t<p>Copy the package files into the folder in the same relative directories \n\tto which they will be installed to the file system. Symbolic links are \n\tallowed. For example:</p>\n\t<table border=\"0\" width=\"100%\" bgcolor=\"#FFFFCC\" id=\"table7\">\n\t\t<tr>\n\t\t\t<td><br>\n\t\t\t<font face=\"Courier\">./usr/sbin/mypackage<br>\n\t\t\t./tmp/etc/package_config/<br>\n\t\t\t./etc/package_config/ ---(symbolic link)---&gt; \n\t\t\t../tmp/etc/package_config/<br>\n\t\t\t./tmp/etc/package_config/moreconfig.conf<br>\n&nbsp;</font></td>\n\t\t</tr>\n\t</table>\n\t<p>The above makes the /etc/package_config/ directory a symbolic link to \n\t/tmp/package_config/. This would be useful for firmwares that have a \n\tread-only /etc file system. On these systems, the configuration files could \n\treside on a ram disk and be emitted at boot-time based on input from some \n\tother store of configuration variables, like NVRAM.</p>\n\t<p><b><font size=\"4\">Step 4:</font></b></p>\n\t<p>Build the IPK. You're done, now simply build the IPK file with the script \n\tprovided. It's parameters are:</p>\n\t<p>MAKE_IPK.SH OUTPUT_PACKAGE_IPK IPK_BASE_DIRECTORY</p>\n\t<p><i><b>OUTPUT_PACKAGE_IPK</b> </i>: The IPK file to output. If it already \n\texists it will be over-written.<br>\n\t<i><b>IPK_BASE_DIRECTORY</b> </i>: The directory you created in step 1 and \n\thave been working with up until now.</p>\n\t<p>Example:</p>\n\t<table border=\"0\" width=\"100%\" bgcolor=\"#FFFFCC\" id=\"table8\">\n\t\t<tr>\n\t\t\t<td><br>\n\t\t\t<font face=\"Courier\">make_ipk.sh package.ipk ../package_ipk_dir<br>\n&nbsp;</font></td>\n\t\t</tr>\n\t</table>\n\t<p>&nbsp;</p>\n</blockquote>\n<p>To support this project:</p>\n<p>\n<input type=\"image\" src=\"https://www.paypal.com/en_US/i/btn/x-click-but21.gif\" border=\"0\" name=\"submit\" alt=\"Make payments with PayPal - it's fast, free and secure!\">\n<img alt=\"\" border=\"0\" src=\"https://www.paypal.com/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\"></p>\n<p>&nbsp;</p>\n<p><font size=\"2\">This document (c)2006 Jeremy Collake. <br>\nAll Rights reserved. This document may be freely republished in its unaltered \nand whole form only. Alterations or partial publishing requires approval of \nJeremy Collake &lt;<a href=\"mailto:jeremy@bitsum.com\">jeremy@bitsum.com</a>&gt;.</font></p>\n\n</body>\n\n</html>\n"
  },
  {
    "path": "ddwrt-gui-extract.sh",
    "content": "#!/bin/bash\n\nOUT=\"$1\"\nDIR=\"$2\"\n\nif [ \"$DIR\" == \"\" ]\nthen\n\tDIR=\"fmk/rootfs\"\nfi\n\nif [ \"$OUT\" == \"\" ]\nthen\n\tOUT=\"www\"\nfi\n\nif [ $UID -ne 0 ]\nthen\n\tSUDO=\"sudo\"\nfi\n\neval $(cat shared-ng.inc)\nHTTPD=\"$DIR/usr/sbin/httpd\"\nWWW=\"$DIR/etc/www\"\nKEYFILE=\"$DIR/webcomp.key\"\n\necho -e \"Firmware Mod Kit (ddwrt-gui-extract) $VERSION, (c)2013 Craig Heffner, Jeremy Collake\\nhttp://www.bitsum.com\\n\"\n\nif [ ! -d \"$DIR\" ] || [ \"$1\" == \"-h\" ] || [ \"$1\" == \"--help\" ]\nthen\n\techo -e \"Usage: $0 [output directory] [rootfs directory]\\n\"\n\texit 1\nfi\n\nif [ ! -e \"$HTTPD\" ] || [ ! -e \"$WWW\" ]\nthen\n\techo \"Unable to locate httpd / www files in directory $DIR. Quitting...\"\n\texit 1\nfi\n\n# Extract!\n# key file is written to rootfs, and since may have root ownership, sudo\nTMPFILE=`mktemp /tmp/$0.XXXXXX`\n./src/webcomp-tools/webdecomp --httpd=\"$HTTPD\" --www=\"$WWW\" --dir=\"$OUT\" --key=\"$TMPFILE\" --extract\n$SUDO cp \"$TMPFILE\" \"$KEYFILE\"\n\n"
  },
  {
    "path": "ddwrt-gui-rebuild.sh",
    "content": "#!/bin/bash\n\nWEBDIR=\"$1\"\nDIR=\"$2\"\n\nif [ \"$DIR\" == \"\" ]\nthen\n\tDIR=\"fmk/rootfs\"\nfi\n\nif [ \"$WEBDIR\" == \"\" ]\nthen\n\tWEBDIR=\"www\"\nfi\n\n# Web files were likely extracted as root, so we'll need root permissions to modify them\nif [ $UID -ne 0 ]\nthen\n\tSUDO=\"sudo\"\nfi\n\neval $(cat shared-ng.inc)\nHTTPD=\"$DIR/usr/sbin/httpd\"\nWWW=\"$DIR/etc/www\"\nKEYFILE=\"$DIR/webcomp.key\"\n\necho -e \"Firmware Mod Kit (ddwrt-gui-rebuild) $VERSION, (c)2011 Craig Heffner, Jeremy Collake\\nhttp://www.bitsum.com\\n\"\n\nif [ ! -d \"$DIR\" ] || [ \"$1\" == \"-h\" ] || [ \"$1\" == \"--help\" ]\nthen\n\techo -e \"Usage: $0 [input directory] [rootfs directory]\\n\"\n\texit 1\nfi\n\nif [ ! -e \"$HTTPD\" ] || [ ! -e \"$WWW\" ]\nthen\n\techo \"Unable to locate httpd / www files in directory $DIR. Quitting...\"\n\texit 1\nfi\n\n# Restore!\nTMPFILE=`mktemp /tmp/$0.XXXXXX`\n# we actually pass a temporary copy of the keyfile to the webdecomp tool so that \n# the actual keyfile won't be included in the compiled web file system\n$SUDO mv \"$KEYFILE\" \"$TMPFILE\"\n$SUDO ./src/webcomp-tools/webdecomp --httpd=\"$HTTPD\" --www=\"$WWW\" --dir=\"$WEBDIR\" --key=\"$TMPFILE\" --restore\n$SUDO mv \"$TMPFILE\" \"$KEYFILE\"\n\n"
  },
  {
    "path": "extract-firmware.sh",
    "content": "#!/bin/bash\n\nIMG=\"${1}\"\nDIR=\"${2}\"\n\nif [ \"${DIR}\" = \"\" ]\n then\n\tDIR=\"fmk\"\nfi\n\n# Need to extract file systems as ROOT\nif [ \"$(id -ru)\" != \"0\" ]\n then\n\tSUDO=\"sudo\"\nelse\n\tSUDO=\"\"\nfi\n\nIMG=$(readlink -f $IMG)\nDIR=$(readlink -f $DIR)\n\n# Make sure we're operating out of the FMK directory\ncd $(dirname $(readlink -f $0))\n\n# Source in/Import shared settings. ${DIR} MUST be defined prior to this!\n. ./shared-ng.inc\n\nprintf \"Firmware Mod Kit (build-ng) ${VERSION}, (c)2011-2013 Craig Heffner, Jeremy Collake\\n\\n\"\n\n# Check usage\nif [ \"${IMG}\" = \"\" ] || [ \"${IMG}\" = \"-h\" ]\n then\n\tprintf \"Usage: ${0} <firmware image>\\n\\n\"\n\texit 1\nfi\n\nif [ ! -f \"${IMG}\" ];\nthen\n\techo \"File does not exist!\"\n\texit 1\nfi\n\nif [ -e \"${DIR}\" ]\n then\n\techo \"Directory ${DIR} already exists! Quitting...\"\n\texit 1\nfi\n\n# Check if FMK has been built, and if not, build it\nif [ ! -e \"./src/crcalc/crcalc\" ]\n then\n\techo \"Firmware-Mod-Kit has not been built yet. Building...\"\n\tcd src && ./configure && make\n\n\tif [ ${?} -eq 0 ]\n\t then\n\t\tcd -\n\telse\n\t\techo \"Build failed! Quitting...\"\n\t\texit 1\n\tfi\nfi\n\n# Get the size, in bytes, of the target firmware image\nFW_SIZE=$(ls -l \"${IMG}\" | cut -d' ' -f5)\n\n# Create output directories\nmkdir -p \"${DIR}/logs\"\nmkdir -p \"${DIR}/image_parts\"\n\necho \"Scanning firmware...\"\n\n# Log binwalk results to the ${BINLOG} file, disable default filters, exclude invalid results,\n# and search only for trx, uimage, dlob, squashfs, and cramfs results.\n#${BINWALK} -f \"${BINLOG}\" -d -x invalid -y trx -y uimage -y dlob -y squashfs -y cramfs \"${IMG}\"\n${BINWALK} -f \"${BINLOG}\" \"${IMG}\"\n\n# Set Internal Field Separator (IFS) via two lines to newline only (bashism would be $'\\n')\nIFS='\n'\n\n# Header image offset is ALWAYS 0. Header checksums are simply updated by build-ng.sh.\nHEADER_IMAGE_OFFSET=0\n\n# Loop through binwalk log file\nfor LINE in IFS='\n'$(sort -n ${BINLOG} | grep -v -e '^DECIMAL' -e '^---')\n do\n\t# Get decimal file offset and the first word of the description\n\tOFFSET=$(echo ${LINE} | awk '{print $1}')\n\tDESCRIPTION=$(echo ${LINE} | awk '{print tolower($3)}')\n\n\t# Offset 0 is firmware header\n\tif [ \"${OFFSET}\" = \"0\" ]\n\t then\n\t\tHEADER_OFFSET=${OFFSET}\n\t\tHEADER_TYPE=${DESCRIPTION}\n\t\tHEADER_SIZE=$(echo ${LINE} | sed -e 's/.*header size: //' | cut -d' ' -f1)\n\t\tHEADER_IMAGE_SIZE=$(echo ${LINE} | sed -e 's/.*image size: //' | cut -d' ' -f1)\n\n\t# Check to see if this line is a file system entry\n\telif [ \"$(echo ${LINE} | grep -i filesystem)\" != \"\" ]\n\t then\n\t\tFS_OFFSET=${OFFSET}\n\t\tFS_TYPE=${DESCRIPTION}\n\n\t\t# Need to know endianess for re-assembly\n\t\tif [ \"$(echo ${LINE} | grep -i 'big endian')\" != \"\" ]\n\t\t then\n\t\t\tENDIANESS=\"-be\"\n\t\telse\n\t\t\tENDIANESS=\"-le\"\n\t\tfi\n\n\t\t# Check for LZMA compression in the file system. If not present, assume gzip.\n\t\t# This is only used for squashfs 4.0 images.\n\t\tif [ \"$(echo ${LINE} | grep -i 'lzma')\" != \"\" ]\n\t\t then\n\t\t\tFS_COMPRESSION=\"lzma\"\n\t\telse\n\t\t\tFS_COMPRESSION=\"gzip\"\n\t\tfi\n\n\t\t# Check for a block size (used only by mksquashfs)\n\t\tif [ \"$(echo ${LINE} | grep -i 'blocksize')\" != \"\" ]\n\t\tthen\n\t\t\tset -f\n\t\t\tIFS=,\n\t\t\tfor fsparam in ${LINE}\n\t\t\tdo\n\t\t\t\tif [[ $fsparam = *blocksize* ]]; then\n\t\t\t\t  fsparam=\"${fsparam##*blocksize: }\"\n\t\t\t\t  FS_BLOCKSIZE=\"${fsparam%* bytes}\"\n\t\t\t\t  break\n\t\t\t\tfi\n\t\t\tdone\n\t\tfi\n\t\tset +f; unset IFS\n\tfi\ndone\n\n# Header image size is everything from the header image offset (0) up to the file system\nHEADER_IMAGE_SIZE=$((${FS_OFFSET}-${HEADER_IMAGE_OFFSET}))\n\n# Extract the header + image up to the file system\necho \"Extracting ${HEADER_IMAGE_SIZE} bytes of ${HEADER_TYPE} header image at offset ${HEADER_IMAGE_OFFSET}\"\ndd if=\"${IMG}\" bs=${HEADER_IMAGE_SIZE} skip=${HEADER_IMAGE_OFFSET} count=1 of=\"${HEADER_IMAGE}\" 2>/dev/null\n\nif [ \"${FS_OFFSET}\" != \"\" ]\n then\n\techo \"Extracting ${FS_TYPE} file system at offset ${FS_OFFSET}\"\n\tdd if=\"${IMG}\" bs=${FS_OFFSET} skip=1 of=\"${FSIMG}\" 2>/dev/null\nelse\n\techo \"ERROR: No supported file system found! Aborting...\"\n\trm -rf \"${DIR}\"\n\texit 1\nfi\n\nFOOTER_SIZE=0\nFOOTER_OFFSET=0\n\n# Try to determine if there is a footer at the end of the firmware image.\n# Grab the last 10 lines of a hexdump of the firmware image, excluding the\n# last line in the hexdump. Reverse the line order and replace any lines\n# that start with '*' with the word 'FILLER'.\nfor LINE in $(hexdump -C ${IMG} | tail -11 | head -10 | sed -n '1!G;h;$p' | sed -e 's/^*/FILLER/')\n do\n\tif [ \"${LINE}\" = \"FILLER\" ]\n\t then\n\t\tbreak\n\telse\n\t\tFOOTER_SIZE=$((${FOOTER_SIZE}+16))\n\tfi\ndone\n\n# If a footer was found, dump it out\nif [ \"${FOOTER_SIZE}\" != \"0\" ]\n then\n\tFOOTER_OFFSET=$((${FW_SIZE}-${FOOTER_SIZE}))\n\techo \"Extracting ${FOOTER_SIZE} byte footer from offset ${FOOTER_OFFSET}\"\n\tdd if=\"${IMG}\" bs=1 skip=${FOOTER_OFFSET} count=${FOOTER_SIZE} of=\"${FOOTER_IMAGE}\" 2>/dev/null\nelse\n\tFOOTER_OFFSET=${FW_SIZE}\nfi\n\n# Log the parsed values to the CONFLOG for use when re-building the firmware\necho \"FW_SIZE='${FW_SIZE}'\" > ${CONFLOG}\necho \"HEADER_TYPE='${HEADER_TYPE}'\" >> ${CONFLOG}\necho \"HEADER_SIZE='${HEADER_SIZE}'\" >> ${CONFLOG}\necho \"HEADER_IMAGE_SIZE='${HEADER_IMAGE_SIZE}'\" >> ${CONFLOG}\necho \"HEADER_IMAGE_OFFSET='${HEADER_IMAGE_OFFSET}'\" >> ${CONFLOG}\necho \"FOOTER_SIZE='${FOOTER_SIZE}'\" >> ${CONFLOG}\necho \"FOOTER_OFFSET='${FOOTER_OFFSET}'\" >> ${CONFLOG}\necho \"FS_TYPE='${FS_TYPE}'\" >> ${CONFLOG}\necho \"FS_OFFSET='${FS_OFFSET}'\" >> ${CONFLOG}\necho \"FS_COMPRESSION='${FS_COMPRESSION}'\" >> ${CONFLOG}\necho \"FS_BLOCKSIZE='${FS_BLOCKSIZE}'\" >> ${CONFLOG}\necho \"ENDIANESS='${ENDIANESS}'\" >> ${CONFLOG}\n\n# Extract the file system and save the MKFS variable to the CONFLOG\ncase ${FS_TYPE} in\n\t\"squashfs\")\n\t\techo \"Extracting squashfs files...\"\n\t\t${SUDO} ./unsquashfs_all.sh \"${FSIMG}\" \"${ROOTFS}\" 2>/dev/null | grep MKFS >> \"${CONFLOG}\"\n\t\t;;\n\t\"cramfs\")\n\t\techo \"Extracting CramFS file system...\"\n\t\t${SUDO} ./uncramfs_all.sh \"${FSIMG}\" \"${ROOTFS}\" ${ENDIANESS} 2>/dev/null | grep MKFS >> \"${CONFLOG}\"\n\t\t;;\n\t*)\n\t\techo \"Unsupported file system '${FS_TYPE}'! Quitting...\"\n\t\trm -rf \"${DIR}\"\n\t\texit 1\n\t\t;;\nesac\n\n# Check if file system extraction was successful\nif [ ${?} -eq 0 ]\n then\n\techo \"Firmware extraction successful!\"\n\techo \"Firmware parts can be found in '${DIR}/*'\"\nelse\n\techo \"Firmware extraction failed!\"\n\trm -rf \"${DIR}\"\n\texit 1\nfi\n\nexit 0\n"
  },
  {
    "path": "firmware_mod_kit.htm",
    "content": "<html>\r\n\r\n<head>\r\n<meta http-equiv=\"Content-Language\" content=\"en-us\" />\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\" />\r\n<title>Firmware Modification Kit</title>\r\n<meta name=\"description\" content=\"Extract, Modify, Rebuild Firmware Images of various types\" />\r\n<meta name=\"keywords\" content=\"dd-wrt, ddwrt, openwrt, freewrt, squashfs, squashfs-lzma, hyperwrt, sveasoft, tomato, xwrt, x-wrt, firmware, binwalk, unsquashfs, wrt54g, wl530g, tew632brp, dir615, untrx, trx\" />\r\n</head>\r\n\r\n<body>\r\n\r\n<p><b><font size=\"6\">Firmware Modification Kit<br />\r\n</font></b><i><b>Giving YOU the power to customize your firmware<br />\r\n</b><font size=\"2\">documentation version 0.78 beta<br />\r\nall scripts, untrx, wrt_vx_imgtool, crcalc, binwalk and docs (c) 2006-2011<br />\r\nCraig Heffner &lt;heffnercj@gmail.com&gt;, Jeremy Collake &lt;jeremy.collake@gmail.com&gt;, and other contributors (see project page) <br />\r\nother portions (c) their respective holders</font></i></p>\r\n<p><b><span class=\"highlight\"><b>THERE ARE NEW DOCS:</b></span> This documentation may be superseded or extended by documentation at the <a href=\"http://code.google.com/p/firmware-mod-kit/wiki/Documentation\">Google Code project site</a>. An essentially new, and much improved, rendition is now available. Firmware-Mod-Kit-Ng ;)</b></p>\r\n<p><b><font size=\"4\">Contents</font></b></p>\r\n<p>I. <a href=\"#Description\">Description</a><br />\r\nII. <a href=\"#Why_is_this_useful\">Why is this useful?</a><br />\r\nIII. <a href=\"#Where_to_get_the_kit\">Where to get the kit</a><br />\r\nIV. <a href=\"#Requirements\">Requirements</a><br />\r\nV. <a href=\"#Compatibility\">Compatibility</a><br />\r\nVI. <a href=\"#Instructions\">Instructions</a><br />\r\n&nbsp;&nbsp;&nbsp; A. <a href=\"#Extracting_the_firmware_(extract_firmware.sh)\">\r\nextracting firmware</a><br />\r\n&nbsp;&nbsp;&nbsp; B.\r\n<a href=\"#Modifying_the_firmware_(manual_and/or_ipkg_install.sh)\">modifying \r\nfirmware</a><br />\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.<a href=\"#Installing_packages\"> \r\ninstalling packages</a><br />\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. <a href=\"#Removing_packages\">\r\nremoving packages</a><br />\r\n&nbsp;&nbsp;&nbsp; C. <a href=\"#Re-building_the_firmware_(build_firmware.sh)\">\r\nre-building firmware</a><br />\r\nVII. <a href=\"#Caveats\">Caveats</a><br />\r\n&nbsp;&nbsp;&nbsp; A. <a href=\"#Binary_compatibility_issues\">binary \r\ncompatibility issues</a><br />\r\n&nbsp;&nbsp;&nbsp; B. <a href=\"#Maximum_firmware_size\">maximum firmware size</a><br />\r\n&nbsp;&nbsp;&nbsp; C. <a href=\"#Solutions_to_case_sensitivity\">solutions to file \r\nsystem incompatibilities</a><br />\r\nVIII. <a href=\"#Acknowledgments\">Acknowledgements and more</a><br />\r\nIX. <a href=\"#Links\">Links</a><br />\r\nX. <a href=\"#Revision_history\">Revision history</a><br />\r\n<p>&nbsp;</p>\r\n<p><font size=\"5\"><b>I. <a name=\"Description\">Description</a></b><br />\r\n</font><br />\r\nThis kit gives the user the ability to make changes to a firmware image without \r\nrecompiling the firmware sources. It works by extracting the firmware into \r\nits component parts, then extracting the file system image (assuming its in one \r\nthe supported formats). The user can then make modifications \r\nto the extracted file system, and rebuild the firmware image.</p>\r\n<p>Although this kit completely automates the process, it is also useful for \r\nthose who need a handy collection of utilities to manipulate firmware images. The following utilities are included in this kit, along with scripts to \r\nautomate their use:</p>\r\n<table border=\"1\" width=\"100%\" id=\"table8\">\r\n\t<tr>\r\n\t\t<td><b>ASUSTRX</b></td>\r\n\t\t<td width=\"1457\">An extended version of ASUSTRX that can build both \r\n\t\t'normal' TRX files and, optionally, those with an ASUS <b><i>addver </i>\r\n\t\t</b>style header appended. It can also, uniquely, force segment offsets \r\n\t\tin the TRX (with -b switch) for compatibility with Marvell ASUS devices \r\n\t\tlike the WL-530g. \r\n\t\tThis tool replaces both 'normal' trx tool and addver. Current versions \r\n\t\tincluded are: 0.90 beta.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td height=\"23\"><b>ADDPATTERN</b></td>\r\n\t\t<td height=\"23\" width=\"1457\">Utility to pre-pend Linksys style HDR0 \r\n\t\theader to a TRX.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>ADDVER</b></td>\r\n\t\t<td width=\"1457\">ASUS utility to append a header to a TRX image that \r\n\t\tcontains version information. ASUSTRX includes this capability. Current \r\n\t\tversion: unversioned.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>BINWALK</b></td>\r\n\t\t<td width=\"1457\">Firmware analysis tool, used for searching firmware images\r\n\t\tfor known file types. Used by the extract-ng.sh script to identify valid\r\n\t\tfile systems inside firmware images. Current version included is 0.3.9. \r\n\t\tTool home page: http://binwalk.googlecode.com.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>CRAMFSCK</b></td>\r\n\t\t<td width=\"1457\">CRAMFS file system image checker and extractor. Current \r\n\t\tversions included are:&nbsp; 2.4x.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>CRCALC</b></td>\r\n\t\t<td width=\"1457\">Re-calculates and patches header checksums for TRX and \r\n\t\tuImage firmware headers.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td height=\"23\"><b>MKSQUASHFS</b></td>\r\n\t\t<td height=\"23\" width=\"1457\">Builds a squashfs file system image. \r\n\t\tCurrent versions included are: 2.1-r2, 3.0.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td height=\"25\"><b>MKCRAMFS</b></td>\r\n\t\t<td width=\"1457\" height=\"25\">Builds a cramfs file system image. Coming \r\n\t\tin next version. Current versions included are: 2.4x.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>MOTOROLA_BIN</b></td>\r\n\t\t<td width=\"1457\">A utility that prepends 8 byte headers to TRX images \r\n\t\tfor Motorola devices WR850G, WA840G, WE800G. Current version: \r\n\t\tunversioned.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>UNCRAMFS</b></td>\r\n\t\t<td width=\"1457\">Alternate tool to extracts a cramfs file system image. \r\n\t\tUse cramfsck instead whenever possible as it seems to be more reliable. Current versions \r\n\t\tincluded are: 0.7 (for cramfs v2.x).</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>UNCRAMFS-LZMA</b></td>\r\n\t\t<td width=\"1457\">Extracts an lzma cramfs file system image, specifically\r\n\t\tthose included in OpenRG based firmware. Current version included is 0.7rg.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>UNSQUASHFS</b></td>\r\n\t\t<td width=\"1457\">Extracts a zlib squashfs file system image. Current \r\n\t\tversions included are 1.0 for 3.0 images and 1.0 for 2.x images (my own \r\n\t\tblend).</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>UNSQUASHFS-LZMA</b></td>\r\n\t\t<td width=\"1457\">Extracts an lzma squashfs file system image. Current \r\n\t\tversions included are 1.0 for 3.0 images and 1.0 for 2.x images (my own \r\n\t\tblend). <i>Note: Not all squashfs-lzma patches are compatible with one \r\n\t\tanother. I'm working on adding support for all common squashfs-lzma \r\n\t\tvariations.</i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td><b>UNTRX</b></td>\r\n\t\t<td width=\"1457\">Splits TRX style firmwares into their component \r\n\t\tparts. Also supports pre-pended addpattern HDR0 style headers. This was \r\n\t\tdeveloped exclusively for this kit. Current versions included are: 0.45.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td height=\"23\"><b>WRT_VX_IMGTOOL</b></td>\r\n\t\t<td width=\"1457\" height=\"23\">Utility to generate VxWorks compatible \r\n\t\tfirmware images for the WRT54G(S) v5 series.</td>\r\n\t</tr>\r\n\t</table>\r\n<p>&nbsp;</p>\r\n<p><b><font size=\"4\">Tools/changes unique to this kit</font></b></p>\r\n<p>This kit doesn't just collect existing tools, it also offers new ones and \r\nmodifications to existing ones. Custom code currently is:</p>\r\n<p><b>ASUSTRX</b> - Modified to allow '-b' switch to force segment offsets \r\n(needed for some devices, like the WL-530g).<br />\r\n<b>CRCALC</b> - A new tool to re-calculate and patch the checksum fields for common\r\nfirmware headers. Currently TRX and uImage headers are supported.<br />\r\n<b>UNTRX</b> - A new tool to extract the contents of a TRX image into its component \r\nparts.<br />\r\n<b>UNSQUASHFS</b> - Custom blend that supports extraction of 2.x squashfs \r\nimages. This tool wasn't officially made available until squashfs 3.0, so up \r\nuntil now it wasn't available for 2.x images.<br />\r\n<b>WRT-VX-IMGTOOL</b> - A new tool to view, extract, build, and fix VxWorks \r\ncompatible firmware images for the WRT54G(S) v5 series.<br />\r\n<b>SPLITTER3</b> - Custom file splitter for certain types of linux firmware images.\r\n</p>\r\n<p><b><font size=\"5\">II. <a name=\"Why_is_this_useful\">Why is this useful?</a></font></b><br />\r\n<br />\r\nA list of some of the many reasons this might be desired are:</p>\r\n<ul>\r\n\r\n\t<li>add initialization scripts</li>\r\n\t<li>install new packages</li>\r\n\t<li>extend/change HTTP managed console</li>\r\n\t<li>remove un-needed packages</li>\r\n\t<li>mix-and-match packages from various flavors of the firmware image.</li>\r\n</ul>\r\n<p>\r\n<br />\r\n&nbsp;</p>\r\n<p><b><font size=\"5\">III. <a name=\"Where_to_get_the_kit\">Where to get the ki</a>t</font></b></p>\r\n<p>The best way to download and use this kit is to check out the sources from \r\nthe repository. The automated scripts all automatically build the executables, \r\nand the sources. It is easy as downloading something and using it that way. Also, if you are unable to use a simple SVN checkout, then\r\nit is likely that this kit is a danger to you because it is for advanced users. </p>\r\n\r\n<p>To anonymously check out the firmware-mod-kit:</p>\r\n<table border=\"0\" width=\"100%\" id=\"table9\" bgcolor=\"#F6F4EC\">\r\n\t<tr>\r\n\t\t<td><font face=\"Courier New\">&nbsp;mkdir firmware_mod_kit<br />\r\n&nbsp;cd firmware_mod_kit<br />\r\n&nbsp;svn checkout http://firmware-mod-kit.googlecode.com/svn/trunk/ firmware-mod-kit-read-only</font></td>\r\n\t</tr>\r\n</table>\r\n<p><br />\r\n<b><font size=\"4\">Kit downloads and links:</font></b></p>\r\n<p>Project hosting and repository (new):\r\n<a href=\"http://code.google.com/p/firmware-mod-kit/\">\r\nhttp://code.google.com/p/firmware-mod-kit/</a><br />\r\nGuest SVN Checkout: <i>svn checkout http://firmware-mod-kit.googlecode.com/svn/trunk/ firmware-mod-kit-read-only</i><br />\r\nUser forums can be found <a href=\"http://www.bitsum.com/forum/index.php?board=12.0\">\r\nhere</a>.</p>\r\n<p><b><font size=\"4\">Packages:</font></b></p>\r\n<p>All of the many OpenWrt packages should work with OpenWrt images and many \r\nother firmware images.</p>\r\n<p>An old (2009) specific collection of DD-WRT packages for use with the kit:\r\n<a href=\"http://www.bitsum.com/files/ddwrt_packages.tar.gz\">\r\nhttp://www.bitsum.com/files/ddwrt_packages.tar.gz</a> .<br />\r\n&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p><b><font size=\"5\">IV. <a name=\"Requirements\">Requirements</a></font></b></p>\r\n<p>I've worked to make sure the requirements are low enough for anyone to \r\nuse this kit. However, to reduce distribution costs and better represent the \r\nmulti-platform capabilities of this kit, the binary tools in the kit do \r\nautomatically build themselves the first time you run one of the scripts. Any \r\nmachine set up to build anything C or C++ on the machine will probably be ready. \r\nThe few requirements are all basic items that everyone has easy access to:</p>\r\n<ul>\r\n\t<li>A compatible platform. The following are specifically supported (or \r\n\tspecifically unsupported):<ul>\r\n\t<li><b>LINUX&nbsp;&nbsp;&nbsp;&nbsp; </b>(recommended)</li>\r\n\t<li><b>OS X&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b> <i>&nbsp;**warning: \r\n\tI don't test every build under OS X. It's up to you to email me if you have \r\n\tproblems under it. Current builds may have issues.**</i></li>\r\n\t<li>CYGWIN&nbsp; <i>**alpha stage testing (!! built firmwares may not boot \r\n\t!!)**</i></li>\r\n</ul>\r\n\t</li>\r\n\t<li>GNU C (gcc)</li>\r\n\t<li>GNU C++ (g++)</li>\r\n\t<li>GNU make</li>\r\n\t<li>Standard C runtime library development</li>\r\n\t<li>Standard C++ runtime library development</li>\r\n\t<li>Zlib library development (for Ubuntu it is zlib1g-dev)</li>\r\n\t<li>TAR and GZIP (optional, used by ipkg_install.sh)</li>\r\n</ul>\r\n<p>OS/X is not supported at this time. The kit is probably not far from compatibility, but easier to just install a linux VM.</p>\r\n<p></p>\r\n<p><b><font size=\"5\">V. <a name=\"Compatibility\">Compatibility</a></font></b></p>\r\n<p>Any TRX style firmware image format should that uses squashfs-lzma as a root \r\nfile system work fine. Firmwares that use regular zlib squashfs or unsupported \r\nfile systems will work if the steps that extract the file system and rebuild the \r\nfile system are tweaked. </p>\r\n<p>The kit can build firmware images for the following devices, amongst <u>many \r\nothers</u>:</p>\r\n<ul>\r\n\t<li>WRT54G v1 - v6</li>\r\n\t<li>WRT54GS v1 - v6</li>\r\n\t<li>WRTSL54G v?</li>\r\n\t<li>ASUS WL-330g</li>\r\n\t<li>ASUS WL-500g/p</li>\r\n\t<li>ASUS WL-520g</li>\r\n\t<li>ASUS WL-530g</li>\r\n\t<li>Belkin 7230-4 (some versions)</li>\r\n\t<li>Belkin 7231-4 (?)</li>\r\n\t<li>Buffalo WHR-G54S</li>\r\n\t<li>Buffalo WHR-HP-G54</li>\r\n\t<li>Siemens SE505</li>\r\n\t<li>Trendnet TEW-632BRP</li>\r\n\t<li>D-Link DIR-615 (maybe)</li>\r\n\t<li>... lots of others<font size=\"2\">*</font> ...</li>\r\n</ul>\r\n<p>The kit is known (or thought) to be compatible with the following firmwares:</p>\r\n<table border=\"0\" width=\"100%\" id=\"table3\">\r\n\t<tr>\r\n\t\t<td width=\"187\">DD-WRT v23</td>\r\n\t\t<td>tested&nbsp;- versions v23 SP1 and later are compatible (soon older \r\n\t\tversions too). <b>WARNING:</b> <i>Builds of \r\n\t\tDD-WRT later than 08/04/2006 (v23 SP2) have some protections against \r\n\t\tchanging the web UI.</i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">DD-WRT v24</td>\r\n\t\t<td>tested</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">OpenWrt White Russian</td>\r\n\t\t<td>tested</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">OpenWrt Kamikaze</td>\r\n\t\t<td><i>untested (should work) </i>- not really necessary, based on \r\n\t\tOpenWrt has its Image Builder.</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">FreeWrt</td>\r\n\t\t<td><i>untested - should work ok</i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">HyperWrt</td>\r\n\t\t<td><i>untested </i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">Ewrt</td>\r\n\t\t<td><i>untested</i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">Sveasoft Alchemy</td>\r\n\t\t<td><i>untested </i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">Sveasoft Talisman</td>\r\n\t\t<td><i>untested </i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">Linksys / other vendor</td>\r\n\t\t<td>not supported by scripts yet - haven't added cramfs handling</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">ASUS WL-330G</td>\r\n\t\t<td><i>untested - should work ok</i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">ASUS WL-520G</td>\r\n\t\t<td><i>untested - should work ok</i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">ASUS WL-530G</td>\r\n\t\t<td>supported</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">ASUS WL-550G</td>\r\n\t\t<td><i>untested&nbsp; - should work ok</i></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"187\">Trendnet TEW-632BRP</td>\r\n\t\t<td>tested</td>\r\n\t</tr>\t\r\n\t<tr>\r\n\t\t<td width=\"187\">DLink DIR-615</td>\r\n\t\t<td><i>untested</i></td>\r\n\t</tr>\t\r\n\r\n\t<tr>\r\n\t\t<td width=\"187\">many others<font size=\"2\">*</font></td>\r\n\t\t<td><i>untested </i></td>\r\n\t</tr>\r\n</table>\r\n<p><b><i>* Even if the kit doesn't automatically support the firmware or device you want, \r\nyou can manually use the tools inside to manipulate many firmware images, or \r\nrequest support be added.</i></b></p>\r\n<p>&nbsp;</p>\r\n<p><b><font size=\"5\">VI. <a name=\"Instructions\">Instructions</a><br />\r\n</font></b><br />\r\nI've scripts that simply and abstract the firmware modification process. Basically, it's a \r\none-step process to extract the firmware, and a one-step process to rebuild the \r\nfirmware. There are also scripts to install or remove individual packages or \r\nentire directories of packages.</p>\r\n<p>The procedure of calls is:</p>\r\n<ol>\r\n\t<li>extract_firmware.sh ....</li>\r\n\t<li>(optional) ipkg_install[_all]).sh ...</li>\r\n\t<li>(optional) ipkg_remove[_all].sh&nbsp;&nbsp; ...</li>\r\n\t<li>build_firmware.sh</li>\r\n</ol>\r\n<p>&nbsp;</p>\r\n<p><u><b><font size=\"4\">A.\r\n<a name=\"Extracting_the_firmware_(extract_firmware.sh)\">Extracting the firmware \r\n(extract_firmware.sh, extract-ng.sh)</a></font></b></u></p>\r\n<blockquote>\r\n\t<p>Simply run extract_firmware.sh with the following parameters. <i><b>You must \r\nrun this tool from inside the directory it exists in.</b></i></p>\r\n\t<table border=\"0\" width=\"100%\" bgcolor=\"#F6F4EC\" id=\"table1\">\r\n\t\t<tr>\r\n\t\t\t<td><br />$ ./extract_firmware.sh firmware.bin working_directory/<br />&nbsp;</td>\r\n\t\t</tr>\r\n\t</table>\r\n\t<p><br /><b>- firmware.bin</b> is the firmware image you want to extract, i.e. \r\nDD-WRT.v23_MICRO_GENERIC.BIN. <br /><b>- working_directory</b> is the working directory you want to use. This is \r\nwhere the intermediate files and the extracted file system will be stored. Note \r\nthat files in the working directory may be deleted!<br /><br />It doesn't matter which firmware image you supply, i.e. for a WRT54G or an ASUS \r\nWL-500G. These images are usually all the same and differ only in the header \r\nformat. The rebuilding process will create images for the various models.<br />\r\n\t<br />An extraction log is created as <i>extract.log</i>.</p>\r\n\r\n\t<p>If extract_firmware.sh fails, the newer extract-ng.sh can be used. Although newer and \r\n\t   less thoroughly tested than extract_firmware.sh, it is more flexible and can often\r\n\t   extract file systems that extract_firmware.sh cannot:\r\n\t</p>\r\n\r\n\t<table border=\"0\" width=\"100%\" bgcolor=\"#F6F4EC\" id=\"table3\">\r\n\t\t<tr>\r\n\t\t\t<td><br />$ ./extract-ng.sh firmware.bin working_directory/<br />&nbsp;</td>\r\n\t\t</tr>\r\n\t</table>\r\n\t\r\n</blockquote>\r\n<p>&nbsp;</p>\r\n<p><b><font size=\"4\"><u>B.\r\n<a name=\"Modifying_the_firmware_(manual_and/or_ipkg_install.sh)\">Making changes \r\nto the firmware's file system</a></u></font></b></p>\r\n<blockquote>\r\n\t<p>Modifying the firmware is simple. The file system is stored in the working \r\ndirectory you supplied to extract_firmware.sh. Here are the subfolders of this \r\ndirectory:<br /><br />&nbsp;&nbsp;&nbsp; <b>rootfs/ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \r\n\t</b>This is where the file system is. \r\nMake modifications here.<br />&nbsp;&nbsp;&nbsp; <b>image_parts/ <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \r\n\t</b>This is where intermediate files are stored. If you need to replace the \r\n\tkernel (not at all recommended), you can do so by replacing the appropriate \r\n\tfile here (usually segment2).<br />\r\n\t<b>&nbsp;&nbsp;&nbsp; installed_packages/<br />\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b>If you use the ipkg_install.sh \r\n\ttool, this is where packages you've installed after firmware extraction will \r\n\treside.<br /><br />One can manually change the files in rootfs and/or use the \r\n\tautomated package scripts.</p>\r\n\t<p>&nbsp;</p>\r\n\t<p><b><a name=\"Installing_packages\">Installing packages</a> (.IPK)</b></p>\r\n\t<blockquote>\r\n\t\t<p>In compliment to manually making changes, one can use pre-built IPKG \r\n\t\tformat package files with the ipkg_install/remove scripts. Although not \r\n\t\tall will work and a repository for packages verified to work has not yet \r\n\t\tbeen produced, many packages work just fine.</p>\r\n\t\t<p>Packages are pre-built collections of files pertaining to a set of software. \r\nOpenWrt and DD-WRT both use packages, and most are cross-compatible. These \r\npackages are stored in a tar/gzip archive of a pre-defined structure that \r\nincludes some control files. You can extract and copy the files manually, or use \r\nthe ipkg_install.sh script included with this kit. For a list of some of the \r\navailable packages (not all may work), see\r\n\t\t<a href=\"http://downloads.openwrt.org/whiterussian/packages/\">\r\n\t\thttp://downloads.openwrt.org/whiterussian/packages/</a> and\r\n\t\t<a href=\"http://ftp.selfnet.de/pub/openwrt/backports/rc5/\">http://ftp.selfnet.de/pub/openwrt/backports/rc5/</a> .\r\n\t\t<i>We are currently in the process of compiling a set of packages known \r\n\t\tto be good for DD-WRT ... to help in this matter please visit\r\n\t\t<a href=\"http://www.dd-wrt.com/phpBB2/viewtopic.php?t=2844\">here</a>.\r\n\t\t</i></p>\r\n\t\t<p><i>For information on how to create IPKs, see the\r\n\t\t<a href=\"creating_ipk_packages.htm\">IPK Creation Kit</a>.</i></p>\r\n\t\t<p>Example use:</p>\r\n\t\t<table border=\"0\" width=\"100%\" bgcolor=\"#F6F4EC\" id=\"table6\">\r\n\t\t\t<tr>\r\n\t\t\t\t<td><br />$ ./ipkg_install.sh some_package-1.2.5.ipk working_directory/<br />&nbsp;</td>\r\n\t\t\t</tr>\r\n\t\t</table>\r\n\t\t<p><b>some_package-1.2.5.ipkg </b>would be the filename of the package.<br />\r\n\t\t<b>working_directory</b> is the same working directory you supplied to the \r\nextract_firmware.sh script.</p>\r\n\t\t<p><b>Notes:</b></p>\r\n\t\t<p>A script, ipkg_install_all.sh is also available to install an entire \r\n\t\tfolder of packages.</p>\r\n\t\t<p>The collection of installed packages will be stored in <b><i>\r\n\t\tworking_directory/installed_packages </i></b>.</p>\r\n\t</blockquote>\r\n\t<p>&nbsp;</p>\r\n\t<p><b><a name=\"Removing_packages\">Removing packages</a> (.IPK)</b></p>\r\n\t<blockquote>\r\n\t\t<p>To remove packages there is the ipkg_remove.sh script. </p>\r\n\t\t<p>Example use:</p>\r\n\t\t<table border=\"0\" width=\"100%\" bgcolor=\"#F6F4EC\" id=\"table7\">\r\n\t\t\t<tr>\r\n\t\t\t\t<td><br />$ ./ipkg_remove.sh some_package-1.2.5.ipk working_directory/<br />&nbsp;</td>\r\n\t\t\t</tr>\r\n\t\t</table>\r\n\t\t<p><b>some_package-1.2.5.ipkg </b>would be the filename of the package.<br />\r\n\t\t<b>working_directory</b> is the same working directory you supplied to the \r\nextract_firmware.sh script.</p>\r\n\t\t<p><b>Notes:</b></p>\r\n\t\t<p>A script, ipkg_remove_all.sh is also available to install an entire \r\n\t\tfolder of packages.</p>\r\n\t\t<p>The collection of installed packages stored <b><i>\r\n\t\tworking_directory/installed_packages </i></b>will be updated to reflect \r\n\t\tthe change if successful.</p>\r\n\t</blockquote>\r\n\t<p>&nbsp;</p>\r\n</blockquote>\r\n<p><b><font size=\"4\"><u>C.\r\n<a name=\"Re-building_the_firmware_(build_firmware.sh)\">Re-building the firmware \r\n(build_firmware.sh, build-ng.sh)</a></u></font></b></p>\r\n<blockquote>\r\n\t<p>Rebuilding the firmware is as easy as extracting it. Use the \r\nbuild_firmware.sh script to automate the process.&nbsp; <i><b>You must run this \r\ntool from inside the directory it exists in.</b></i></p>\r\n\t<p>Example use:</p>\r\n\t<table border=\"0\" width=\"100%\" bgcolor=\"#F6F4EC\" id=\"table2\">\r\n\t\t<tr>\r\n\t\t\t<td><br />$ ./build_firmware.sh output_directory/ working_directory/<br />&nbsp;</td>\r\n\t\t</tr>\r\n\t</table>\r\n\t<p><b>- output_directory</b> is the path to which the created firmware images \r\nshould be stored. If images already exist here, they will be over-written. \r\nFirmware images for various models will be emitted (these images are all the \r\nsame but have different header patterns so they are accepted by the target \r\nmodels).<br /><b>- working_directory</b> is the working directory supplied to \r\nextract_firmware.sh.</p>\r\n\t<p>A building log is created as <i>build.log</i>.</p>\r\n\r\n\t<p>\r\n\t\tIf extract-ng.sh was used to extract the firmware image, build-ng.sh must be used\r\n\t\tto rebuild it:\r\n\t</p>\r\n\t<table border=\"0\" width=\"100%\" bgcolor=\"#F6F4EC\" id=\"table4\">\r\n\t\t<tr>\r\n\t\t\t<td><br />$ ./build-ng.sh working_directory/<br />&nbsp;</td>\r\n\t\t</tr>\r\n\t</table>\r\n</blockquote>\r\n<p>&nbsp;</p>\r\n<p><font size=\"5\"><b>VIII. <a name=\"Caveats\">Caveats</a></b></font></p>\r\n<p>There are a few things to watch out for when modifying firmware images. If \r\nyou make reasonable changes these problems will probably never affect you. Be \r\nwarned, this section may be technical in parts.</p>\r\n<p><b>A. <a name=\"Binary_compatibility_issues\">Binary compatibility issues</a></b></p>\r\n<ul>\r\n\t<li>If installing a <b>binary</b> package:&nbsp;\r\n\t<ul>\r\n\t\t<li>It is possible the uclibc or glibc library was pruned (unused \r\n\t\tobjects removed). In the unlikely event the binary package requires some of these \r\n\t\tpreviously unused (and now missing) functions, you may need to install \r\n\t\tto the firmware file system a new uclibc or glibc library. If you are \r\n\t\tinstalling another pruned uclibc or glibc library, then it is remotely \r\n\t\tpossible some pre-existing package requires objects not found in this \r\n\t\tnew library. In such a very rare case you can re-link the library or \r\n\t\tfind a full copy of the library to install.</li>\r\n\t\t<li>Different firmwares may use different kernel versions, or have \r\n\t\tdifferent kernel modules installed. If you get too wild with your \r\n\t\tmix-and-matching (i.e. use older versions with newer, or mixtures of \r\n\t\tdifferent firmwares all-together), problems can result. To install a new \r\n\t\tkernel (not at all recommended), replace the segment2 (or other) file found found in \r\n\t\tthe intermediate directory with an appropriate one (can be from another \r\n\t\tfirmware as long as lzma compression is used).</li>\r\n\t\t<li>Make sure any dependencies are also installed to the file system, \r\n\t\talong with initialization scripts.</li>\r\n\t</ul></li>\r\n\t<li>If making web UI changes:<ul>\r\n\t\t<li><b>WARNING:</b> DD-WRT builds dated later than 08/04/2006 \r\n\thave some protections against modifying the web UI.</li>\r\n\t</ul>\r\n\t<p>&nbsp;</p></li>\r\n</ul>\r\n<p><b>B. <a name=\"Maximum_firmware_size\">Maximum firmware size</a></b></p>\r\n<p>Currently, the maximum firmware image size supported by this kit is 5,898,240 \r\n(0x5A0000) bytes, but can be adjusted through the &quot;-m [size]&quot; parameter of the \r\nasustrx tool.</p>\r\n<p><br />\r\n<b>C. <a name=\"Solutions_to_case_sensitivity\">Solutions to file system \r\nincompatibilities</a></b></p>\r\n<p><b>! This section is very much a work in progress !</b></p>\r\n<p>The squashfs file system is case sensitive (i.e. teSt.bin ! = test.bin) and \r\nadheres to EXT2 naming rules. To support proper extraction of the file system, \r\nthe working directory should be on a case sensitive file system and support \r\nsymbolic links. The scripts \r\nwill warn you if you attempt to use as working directory on a case INsensitive \r\nfile system. You'll see a number of errors if you extract to a file system that \r\ndoesn't support symbolic links.</p>\r\n<p><b>Note:</b> <i>Case insensitivity doesn't always cause problems,</i> especially if the file \r\nsystem preserves case ok. It depends on the firmware and version. Most of the \r\ntime for DD-WRT as long as a case preserving file system is used as a working \r\ndirectory, all should work fine.</p>\r\n<p>These solutions apply to those using CYGWIN, or some other environment \r\nthat may not have a case sensitive file system by default. Linux users typically \r\ndo not have this problem since EXT2 and EXT3 file systems are case sensitive.\r\n</p>\r\n<p><br />\r\n<b>WARNING: THESE ARE IN EARLY STAGES OF TESTING AND MAY NOT WORK.</b></p>\r\n<table border=\"1\" width=\"100%\" id=\"table4\" cellpadding=\"5\">\r\n\t<tr>\r\n\t\t<td width=\"127\" height=\"33\">&nbsp;</td>\r\n\t\t<td width=\"162\" height=\"33\"><b>Applies to</b></td>\r\n\t\t<td height=\"33\"><b>Description</b></td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"127\" valign=\"top\"><b>SOLUTION 1</b></td>\r\n\t\t<td width=\"162\" height=\"30\" valign=\"top\">CYGWIN, OTHER</td>\r\n\t\t<td height=\"30\" valign=\"top\"><b>It's reported this does not work under \r\n\t\tCYGWIN</b> due to the CYGWIN utilities all being case INsensitive \r\n\t\t(thanks pagedude).<br />\r\n\t\t<br />\r\n\t\tUse a network share to a case sensitive file system. This is, by far, \r\n\t\tthe easiest solution. Simply use an appropriate network share for the \r\n\t\tworking directory.<br />\r\n&nbsp;</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"127\" height=\"30\" valign=\"top\"><b>SOLUTION 2</b></td>\r\n\t\t<td width=\"162\" valign=\"top\">CYGWIN</td>\r\n\t\t<td valign=\"top\"><br />\r\n\t\tFor NT partitions it's reported you can enable case sensitivity through \r\n\t\tthe following registry key, but <b>I do not know if this works or not</b>.<p>&nbsp;\\HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session \r\n\t\tManager\\kernel\\obcaseinsensitive [REG_DWORD] = 0<br />\r\n&nbsp;</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"127\" height=\"31\" valign=\"top\"><b>SOLUTION 3</b></td>\r\n\t\t<td width=\"162\" height=\"31\" valign=\"top\">OS X (not usually needed, at \r\n\t\tleast for DD-WRT)</td>\r\n\t\t<td height=\"31\" valign=\"top\"><br />\r\n\t\tOne can either\r\n\t\t<a href=\"http://www.macosxhints.com/article.php?story=200502011939237\">\r\n\t\tTurn on HSFX</a> for the boot disk, or (more easily) create a temporary \r\n\t\tHSFX case sensitive file system to use as a working directory.<p>Example \r\n\t\tof how to create a temporary HSFX case sensitive file system:<br />\r\n\t\t<br />\r\n\t\t<i>to create:<br />\r\n\t\t</i>$ hdiutil create -size 20m -fs HFSX -volname db90h -nouuid \r\n\t\ttest-image <br />\r\n\t\t<i>to mount:<br />\r\n\t\t</i>$ hdiutil attach test-image.dmg <br />\r\n\t\t<i>to un-mount:</i><br />\r\n\t\t$ hdiutil detach /Volumes/db90h </p>\r\n\t\t<p>(thanks solarflare for this information)<br />\r\n&nbsp;</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td width=\"127\" valign=\"top\"><b>SOLUTION 4</b></td>\r\n\t\t<td width=\"162\" valign=\"top\">CYGWIN<br />\r\n&nbsp;</td>\r\n\t\t<td valign=\"top\"><br />\r\n\t\tMount an ext2 files system. Eko, of DD-WRT forums, contributes this tip. \r\n\t\tMake a partition on a hard drive or USB thumb drive, then install &quot;<a href=\"http://www.fs-driver.org/\">Ext2 \r\n\t\tInstallable File System For Windows</a>&quot;. 10MB should generally be \r\n\t\tplenty of working directory space, but 20MB is suggested for more \r\n\t\toptimal file system performance.<br />\r\n&nbsp;</td>\r\n\t</tr>\r\n</table>\r\n<p>&nbsp; <b>&nbsp;&nbsp; </b></p>\r\n<p><font size=\"5\"><b>IV</b></font><b><font size=\"5\">. <a name=\"Acknowledgments\">\r\nAcknowledgments</a> and more </font></b></p>\r\n<p>The authors and maintainers of this kit are Jeremy Collake (db90h) and Craig Heffner.&nbsp; \r\nSpecial thanks to Solarflare, TexHex &lt;<a href=\"mailto:floh@fbesser.de\">floh@fbesser.de</a>&gt;, \r\nand others.</p>\r\n<p>If YOU would like to contribute to this kit, send me an email at\r\n<a href=\"mailto:jeremy.collake@gmail.com\">jeremy.collake@gmail.com</a> or visit \r\nthe current project hosting at\r\n<a href=\"http://code.google.com/p/firmware-mod-kit/\">\r\nhttp://code.google.com/p/firmware-mod-kit/</a> . Developers are welcome.</p>\r\n<p>&nbsp;</p>\r\n<p><b><font size=\"5\">X. <a name=\"Links\">Links</a></font></b></p>\r\n<ul>\r\n\t<li><i>&nbsp;<a href=\"creating_ipk_packages.htm\">IPK Creation Kit</a> (alpha \r\n\ttesting)</i></li>\r\n</ul>\r\n<p>&nbsp;</p>\r\n<p><b><font size=\"5\">X. <a name=\"Revision_history\">Revision history</a></font></b></p>\r\n\r\n<p>0.73</p>\r\n<ul>\r\n\t<li>New pre-req check and more modern build system (by Craig)</li>\r\n</ul>\r\n<p>0.72</p>\r\n<ul>\r\n\t<li>Fix for recent updates to linux build tools that mandated different command line ordering (by Craig)</li>\r\n</ul>\r\n\r\n<p>0.64-0.71</p>\r\n<ul>\r\n\t<li>See Google Code</li>\r\n\t<li>NG edition created by Craig Heffner (total new generation of kit)</li>\r\n</ul>\r\n<p>0.63</p>\r\n<ul>\r\n\t<li>Added support for a new raw linux type of firmware (completely untested on the rebuild side flash, so beware)</li>\r\n\t<li>Added new splitter3.cc to split up this linux raw firmware type into its segments</li>\r\n\t<li>Other misc tweaks</li>\r\n</ul>\r\n\r\n<p>0.60</p>\r\n<ul>\r\n\t<li>Fixed issue with non-standard du switches, i.e. under OS X.</li>\r\n\t<li>Fixed untrx inability to recognize squashfs signatures on big endian systems (patch from Jaifu Gao)</li>\r\n</ul>\r\n<p>0.58</p>\r\n<ul>\r\n\t<li>Removed multi-threaded brute testing of LZMA compression params from the 'damn small' variant DD-WRT v24 uses. This may fix some \r\n\t\treported problems of failed thread creation.</li>\r\n</ul>\r\n\r\n<p>0.56</p>\r\n<ul>\r\n\t<li>Add support DD-WRT v24 firmware images</li>\r\n\t<li>New unsquashfs variant written for DD-WRT v24</li>\r\n\t<li>Cleanup script output indentation, it was quite sloppy</li>\r\n\t<li>Apply some fixes and other tweaks</li>\r\n</ul>\r\n\r\n<p>0.54</p>\r\n<ul>\r\n\t<li>Add support for Trendnet TEW-632BRP images</li>\r\n\t<li>Add support for OpenWrt White Russian images</li>\r\n\t<li>Don't force root user, just warn</li>\r\n\t<li>Other maintenance and tweaks</li>\r\n</ul>\r\n\r\n<p>0.51</p>\r\n<ul>\r\n\t<li>Increased maximum supported size of TRX images (now can handle > 4MB images).</li>\r\n</ul>\r\n\r\n<p>0.50</p>\r\n<ul>\r\n\t<li>Removed unnecessary -lz parameter (zlib) from gcc.</li>\r\n</ul>\r\n<p>0.49</p>\r\n<ul>\r\n\t<li>unsquashfs: created first ever (afaik) blend of unsquashfs for squashfs \r\n\t2.x images.</li>\r\n\t<li>mksquashfs: added 2-1.r2. Script support remains todo.</li>\r\n\t<li>other misc. changes.</li>\r\n</ul>\r\n<p>0.48</p>\r\n<ul>\r\n\t<li>scripts: now use cramfsck -x to extract cramfs images instead of \r\n\tuncramfs. uncramfs proved to fail to extract some images.</li>\r\n\t<li>dirs: renamed cramfs-1.1 to cramfs-2.x to reflect the accurate version \r\n\tnumber.</li>\r\n</ul>\r\n<p>0.471</p>\r\n<ul>\r\n\t<li>motorola_bin: added source code.</li>\r\n</ul>\r\n<p>0.47</p>\r\n<ul>\r\n\t<li>wrt_vx_imgtool: added this utility, which can build, extract, view, and \r\n\tfix firmware images for WRT54G(s) v5/v6 series running VxWorks.</li>\r\n\t<li>motorola_bin: added this binary only (linux) utility. Build script \r\n\tdoesn't invoke it yet, but it's easy to use for those who need it.</li>\r\n\t<li>untrx: minor memory leak fixed.</li>\r\n\t<li>docs: added some device compatibility notes and other edits.</li>\r\n</ul>\r\n<p>0.46:</p>\r\n<ul>\r\n\t<li>scripts: added support for cramfs (testing)</li>\r\n\t<li>scripts: added support for WL-520/530/550G images (only 530g tested).</li>\r\n\t<li>sources: added cramfs 1.1 tools (mkcramfs, cramfsck)</li>\r\n\t<li>images: a symlink is now used between the TRX and generic image. \r\n\tPreviously, the intermediate TRX image was just renamed to the generic \r\n\timage.</li>\r\n\t<li>scripts: no longer show untrx output</li>\r\n\t<li>docs: minor additions</li>\r\n</ul>\r\n<p>0.45:</p>\r\n<ul>\r\n\t<li>untrx: added support for attempted detection of file system and version \r\n\tand emission of appropriately named segment.</li>\r\n\t<li>untrx: can now handle trx's that have less than 3 segments.</li>\r\n\t<li>untrx: complete overhauled (needed it). many changes.</li>\r\n\t<li>sources: moved squashfs 3.0 stuff to a dedicated directory.</li>\r\n\t<li>packages: added dd-wrt package for Samba. thanks TexHex &lt;<a href=\"mailto:floh@fbesser.de\">floh@fbesser.de</a>&gt;.</li>\r\n\t<li>asustrx: updated to add -b switch for padding segments (used by \r\n\tASUS).</li>\r\n\t<li>asustrx: other misc. enhancements.</li>\r\n\t<li>scripts: added check_for_upgrade.sh which automatically checks for a \r\n\tnewer version of the kit. It's launched when you use extract or build \r\n\tfirmware.</li>\r\n\t<li>scripts: many other fixes and enhancements.</li>\r\n</ul>\r\n<p>0.43:</p>\r\n<ul>\r\n\t<li>scripts: ipkg_remove.sh - rewritten core templated file removal. It \r\n\tactually works now.</li>\r\n\t<li>scripts: moved build stuff to shared.inc, as appropriate.</li>\r\n\t<li>packages: added dd-wrt package KAID, mainly for removal of this \r\n\tgargantuan (nearly 1MB uncompressed) package. Note: you can easily create \r\n\tyour own packages for easier removal of things you don't want by using the \r\n\tIPK template.</li>\r\n</ul>\r\n<p>0.42:</p>\r\n<ul>\r\n\t<li>ipk_template: added new ipk_template directory and make_ipk.sh script to \r\n\tcreate IPKG format packages (.IPK).</li>\r\n\t<li>packages: added my newly created ssmtp package with nvram-&gt;conf file \r\n\tstartup script. Installs completely into the DD-WRT file system.</li>\r\n\t<li>packages: added ddwrt_packages subdirectory which will include pre-built \r\n\tpackages custom tailored or known to work</li>\r\n\t<li>scripts: ipkg_install.sh numerous improvements and fixes.</li>\r\n\t<li>scripts: ipkg_remove.sh numerous improvements and fixes.</li>\r\n\t<li>scripts: ipkg_install.sh has new untested/alpha stage capabilities to \r\n\thandle IPKs with remote sources.</li>\r\n\t<li>docs: several updates</li>\r\n</ul>\r\n<p>0.40 beta&nbsp; (md5: 786472cfa03fb1cd70e1b025d091168b)</p>\r\n<ul>\r\n\t<li>scripts: ipkg_remove.sh - new script for basic IPK package removal</li>\r\n\t<li>scripts: ipkg_install.sh possible OS X fixes</li>\r\n\t<li>scripts: ipkg_install.sh changed technique of recording installed \r\n\tpackages</li>\r\n\t<li>scripts: ipkg_install.sh outputs control file so user can see \r\n\tdependencies and more</li>\r\n\t<li>scripts: several improvements</li>\r\n\t<li>docs: hopefully more readable format in places</li>\r\n\t<li>docs: many mods and extensions</li>\r\n</ul>\r\n<p>0.33 beta</p>\r\n<ul>\r\n\t<li>structure: moved tool source codes to src subfolder</li>\r\n\t<li>scripts: added ipkg_install_all.sh to install an entire folder of \r\n\tpackages.</li>\r\n\t<li>scripts: consolidated shared code into an 'include' script</li>\r\n\t<li>scripts: added forgotten parameter count check to ipkg_install.sh</li>\r\n\t<li>scripts other minor changes</li>\r\n</ul>\r\n<p>0.31 beta</p>\r\n<ul>\r\n\t<li>new tests indicate OS X with native HFS+ file system results in firmware \r\n\timages that work just fine! This build should be fully compatible with OS X \r\n\twithout even necessitating HSFX use for most firmwares.</li>\r\n\t<li>mksquashfs: fix for big endian machines (specifically ppc / OS X) \r\n\tresulting from change to support dd-wrt 08/10/06+ builds.</li>\r\n</ul>\r\n<p>0.30 beta</p>\r\n<ul>\r\n\t<li>scripts: created symlinks that omit the .sh extension</li>\r\n\t<li>scripts: expanded build success check</li>\r\n\t<li>scripts: fixed failure to exit if tools build failed</li>\r\n\t<li>scripts: other minor cosmetic improvements</li>\r\n\t<li>untrx: fixed a file handle leak in v0.28 beta</li>\r\n\t<li>docs: added example procedure to install SSMTP into DD-WRT image</li>\r\n\t<li>docs: added table of contents</li>\r\n\t<li>docs: misc. additions and revisions</li>\r\n</ul>\r\n<p>0.29 beta</p>\r\n<ul>\r\n\t<li>scripts: added ipkg_install.sh to install .IPK format packages.</li>\r\n</ul>\r\n<p>0.28 beta</p>\r\n<ul>\r\n\t<li>the v0.26 fix for changed signature of&nbsp; 08/10/06 builds was \r\n\tincomplete (test was flawed), resulting in builds that wouldn't run. fixed \r\n\tproperly now.</li>\r\n\t<li>mksquashfs: added -magic [file] parameter to embed whichever is used in \r\n\tthe original firmware</li>\r\n\t<li>untrx: added extraction of squashfs signature/magic for passing to \r\n\tmksquashfs</li>\r\n\t<li>docs: added more stuff</li>\r\n</ul>\r\n<p>0.27 beta</p>\r\n<ul>\r\n\t<li>scripts: changed warning about file system.</li>\r\n</ul>\r\n<p>0.26 beta</p>\r\n<ul>\r\n\t<li>Fixed compatibility with DD-WRT builds 08/10/06 and higher. Brainslayer \r\n\tplayed a joke on me. </li>\r\n</ul>\r\n<p>0.25 beta</p>\r\n<ul>\r\n\t<li>OS X now works. When using case insensitive file system though built \r\n\tfirmwares might have errata.</li>\r\n\t<li>trx: removed this tool due to odd command line parsing bug on (big \r\n\tendian?) OS X systems. asustrx now used in its place.</li>\r\n\t<li>scripts: file system case insensitive now warning, can be continued in \r\n\tdefault settings.</li>\r\n\t<li>untrx: fixed some endian problems. </li>\r\n\t<li>untrx: fixed a problem with U2ND headers (previous version only worked \r\n\ton trx/generic firmwares).</li>\r\n\t<li>docs: minor additions.</li>\r\n</ul>\r\n<p>0.23 beta</p>\r\n<ul>\r\n\t<li>package: removed linux executables, download now half size. Surely \r\n\teveryone can install basic build tools..</li>\r\n\t<li>scripts: added working directory file system test for case insensitivity \r\n\tand write access</li>\r\n\t<li>scripts: added option to continue on after warning when OS X or CYGWIN \r\n\tpresent</li>\r\n\t<li>scripts: removed pre-fixed script name, much cleaner looking output now</li>\r\n\t<li>scripts: added variable to choose whether or not to abort if file system \r\n\tfound incompatible</li>\r\n\t<li>scripts: added cleanup.sh script to clean tools and logs.</li>\r\n\t<li>untrx: renamed extfirmware to untrx, much more intuitive name</li>\r\n</ul>\r\n<p>0.22 beta</p>\r\n<ul>\r\n\t<li>scripts: added support for OS X</li>\r\n\t<li>scripts: added support for CYGWIN</li>\r\n\t<li>scripts: minor cosmetic work</li>\r\n\t<li>extfirmware: added endian neutrality</li>\r\n\t<li>trx: fixed OS X support</li>\r\n\t<li>asustrx: fixed OS X support</li>\r\n</ul>\r\n<p>0.20 beta</p>\r\n<ul>\r\n\t<li>scripts: added check for Linux and OS X and appropriate compatibility \r\n\tmessages</li>\r\n\t<li>extfirmware: added GNU license header</li>\r\n\t<li>extfirmware: removed some unnecessary header includes</li>\r\n\t<li>extfirmware: switched to u_int32_t for wider compatibility</li>\r\n\t<li>extfirmware: other minor improvements</li>\r\n\t<li>trx: increased maximum firmware size to 0x5A0000 (OpenWrt) from 0x3A0000 \r\n\t(DD-WRT).</li>\r\n\t<li>trx: switched to u_int32_t for wider compatibility</li>\r\n\t<li>makefile: uses gcc instead of cc now</li>\r\n\t<li>docs: several updates</li>\r\n</ul>\r\n<p>v0.15 beta</p>\r\n<ul>\r\n\t<li>Reworked scripts so they have cleaner, clearer output and use a log file \r\n\t(build.log and extract.log)</li>\r\n\t<li>Added more sanity checks in the scripts</li>\r\n\t<li>Documentation additions</li>\r\n\t<li>Misc. polishing</li>\r\n</ul>\r\n<p>v0.13 alpha: Documentation updates, re-included pre-built executables<br />\r\nv0.10 alpha: First decent public release.</p>\r\n<p>&nbsp;</p>\r\n\r\n<p>&nbsp;</p>\r\n<p><font size=\"2\">This document (c)2006-2011 Jeremy Collake and Craig Heffner. <br />\r\nAll Rights reserved. This document may be freely republished in its unaltered \r\nand whole form only. Alterations or partial publishing requires approval of \r\ncreator(s).</font></p>\r\n  \r\n<p><i><font size=\"2\">&nbsp;This kit is free software; you can redistribute it \r\nand/or modify<br />\r\n&nbsp;it under the terms of the GNU General Public License as published by<br />\r\n&nbsp;the Free Software Foundation; either version 2 of the License, or<br />\r\n&nbsp;(at your option) any later version.<br />\r\n<br />\r\n&nbsp;This program is distributed in the hope that it will be useful,<br />\r\n&nbsp;but WITHOUT ANY WARRANTY; without even the implied warranty of<br />\r\n&nbsp;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br />\r\n&nbsp;General Public License for more details.<br />\r\n<br />\r\n&nbsp;You should have received a copy of the GNU General Public License<br />\r\n&nbsp;along with this program; if not, write to the Free Software<br />\r\n&nbsp;Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font></i></p>\r\n  \r\n</body>\r\n\r\n</html>\r\n"
  },
  {
    "path": "firmware_mod_kit_version.txt",
    "content": "0.82\n"
  },
  {
    "path": "ipk_template/conffiles",
    "content": "test\n"
  },
  {
    "path": "ipk_template/control",
    "content": "Package: package_name\nPriority: optional\nSection: net\nDepends: libncurses\nDescription: Some package description.\nMaintainer: Some guy <someguy@somewhere.net>\nSource: N/A\nVersion: 1.01-1\nArchitecture: mipsel\n"
  },
  {
    "path": "ipk_template/debian_binary",
    "content": "2.0\n"
  },
  {
    "path": "ipk_template/make_ipk.sh",
    "content": "#!/bin/sh\nVERSION=\"0.01 alpha\"\n#\n# Title: make_ipk.sh\n# Author: Jeremy Collake <jeremy.collake@gmail.com>\n#\n# Creates a IPK from the given directory\n#\n#\necho \"$0 (c)2006 Jeremy Collake <jeremy.collake@gmail.com\"\n\nMIN_PARAMS=2\nif [ $# -lt $MIN_PARAMS ] || [ ! -d \"$2\" ]; then\n\techo \" Invalid usage!\"\n\techo \" USAGE: $0 IPK_OUTPUT_FILE IPK_BASE_FOLDER\"\n \texit 1\nfi\necho \"-----------begin-----------\" > make_ipkg.log\nOLD_DIR=`pwd`\nif [ -f \"$2\" ]; then\n\techo \" Erasing existing $2 ...\"\n\trm $2 \n#>> make_ipkg.log 2>&1\nfi\n##############################################\n# change to package ipk folder\n#\ncd \"$2\"\n##############################################\n# do some cleanup from any previous runs\n#\nrm \"packagetemp.tar\"\n##############################################\n# create control.tar\n#\necho \" Creating control.tar ...\"\ntar -cf \"control.tar\" \"./control\" \"./conffiles\"\nif [ $? != 0 ] || [ ! -f \"control.tar\" ]; then \n\techo \" ERROR: creation of $2/control.tar failed!\"\n\texit 2\t\nfi\n##############################################\n# create control.tar.gz\n#\necho \" Creating control.tar.gz ...\"\ngzip < \"control.tar\" > \"control.tar.gz\"\nif [ $? != 0 ] || [ ! -f \"control.tar.gz\" ]; then \n\techo \" ERROR: creation of $2/control.tar.gz failed!\"\n\texit 2\t\nfi\n##############################################\n# create data.tar\n#\n# exclude control, conffiles, this script (if it exists), \n# and anything else prudent to ignore\n#\necho \" Creating data.tar ...\"\nOUR_BASENAME=`basename $0`\nIPK_BASENAME=`basename $1`\n# just get top-level directories actually\nALL_FILES=`find \"./\" -maxdepth 1 | sed 1d` \nrm data.tar\nINPUT_FILES=\" \"\nfor i in $ALL_FILES; do\n\techo \"  Processing $i \"\n\tif [ -d $i ]; then\n\t\tINPUT_FILES=`echo $INPUT_FILES \"$i\"`\n\tfi\ndone\necho \" dbg.infiles: $INPUT_FILES\"\ntar \"--exclude=./control.tar\" \"--exclude=./control\" \"--exclude=./conffile*\" \"--exclude=./$OUR_BASENAME\" \"--exclude=./$IPK_BASENAME\" \"--exclude=./make_ipk*.log\" -cvf data.tar $INPUT_FILES\necho \" -------- current data.tar ----------\"\ntar -tvf data.tar\nif [ $? != 0 ] || [ ! -f \"data.tar\" ]; then \n\techo \" ERROR: creation of $2/data.tar failed!\"\n\texit 2\t\nfi\n##############################################\n# create data.tar.gz\n#\n# exclude control, conffiles, and this script if it's there..\n#\necho \" Creating data.tar.gz ...\"\nOUR_BASENAME=`basename $0`\ngzip < \"data.tar\" > \"data.tar.gz\"\nif [ $? != 0 ] || [ ! -f \"data.tar.gz\" ]; then \n\techo \" ERROR: creation of $2/data.tar.gz failed!\"\n\texit 2\t\nfi\n\n\n##############################################\n# create PACKAGE.tar\n#\ntar -cf \"packagetemp.tar\" \"./control.tar.gz\" \"./data.tar.gz\" \"./debian_binary\"\nif [ $? != 0 ] || [ ! -f \"packagetemp.tar\" ]; then \n\techo \" ERROR: creation of packagetemp.tar failed!\"\n\texit 2\t\nfi\n##############################################\n# finally gzip the result to PACKAGE.ipk\n#\ngzip < \"packagetemp.tar\" > \"$1\"\nif [ $? != 0 ] || [ ! -f $1 ]; then \n\techo \" ERROR: creation of $1 failed!\"\n\texit 2\t\nfi\necho \" Done. Created: $1\"\ncd $OLD_DIR\n"
  },
  {
    "path": "ipkg_install.sh",
    "content": "#!/bin/sh\n#\n# $Id: ipkg_install.sh 336 2012-08-04 00:12:14Z jeremy.collake@gmail.com $\n#\n. \"./shared.inc\"\n### 20110225-MCT The VERSION is set in the shared.inc file from a single external source now.\nVERSION=\"${SHARED_VERSION}\"\n#\n# Title: ipkg_install.sh\n# Author: Jeremy Collake <jeremy.collake@gmail.com>\n# Site: http://code.google.com/p/firmware-mod-kit/\n#\n# Do a really dumb package install. No dependencies,\n# removal, or anything. Just extract the data files\n# to the file system.\n#\n# See documentation at:\n#  http://www.bitsum.com/firmware_mod_kit.htm\n#\n# USAGE: ipkg_install.sh PACKAGE_SOURCE WORKING_DIRECTORY/\n#\n# PACKAGE_SOURCE is the path to the .PKG file. \n#\n# WORKING_DIRECTORY is the working directory supplied to\n#  extract_firmware.sh.\n#\n# Example:\n#\n# ./ipkg_install.sh nano_1.3.8-1_mipsel.ipk ../working_dir/\n#\n# todo: need to get full path of log file because directory\n#  change causes log files in both.\n#\n# todo: this does NOT work with sources that aren't local\n#  yet..\n#\n#\n#\necho \"$0 v$VERSION, (c)2006-2012 Jeremy Collake\"\necho \" !!WARNING!!! This script is in early alpha stage of development\"\n\n############################################333\n# CleanupTmp [base_dir] [package basename]\n#\n# basename=name w/o IPK (contrasts below labels)\nCleanupTmp()\n{\t\n\techo \" Cleanup\" >> /dev/null 2>&1\n\trm -rf \"$1/tmp\" >> /dev/null 2>&1\n\trm -f \"$1/$2\" >> /dev/null 2>&1\n}\n\n\n##################################################\nif [ ! $# = \"2\" ]; then\n\techo \" Invalid usage\"\n\techo \" USAGE: $0 PACKAGE_PATH WORKING_DIRECTORY\"\n\texit 1\nfi\nBASE_NAME=`basename $1`\necho \" Installing $BASE_NAME\"\n####################################################\nif [ ! -e \"$1\" ]; then\n\techo \" ERROR: $1 does not exist.\"\n\texit 1\nfi\n\nOLD_DIR=`pwd`\n##################################################\n# notes:\n# OS X's tar utility doesn't like GZIP'd TARs .. (re: not TAR'd GZIPs ..),\n#  else we could just use tar (which under linux accepts GZIPs as well).\n#\nmkdir -p \"$2/installed_packages/\" >> ipkg_install.log 2>&1\ncp $1 \"$2/installed_packages/\"\ncd \"$2/installed_packages\"\nINSIDE_NAME=`echo \"$BASE_NAME\" | sed \"s/.ipk/ /\"`\ngunzip < \"$BASE_NAME\" > \"$INSIDE_NAME\"\necho \" Assuming contents bore $INSIDE_NAME\"\nrm -rf tmp\nmkdir tmp\ntar -xf \"$INSIDE_NAME\" -C \"tmp/\"\nif [ $? != 0 ]; then\n\techo \" ERROR: Extraction failed or incompatible format.\"\n\tCleanupTmp \".\" \"$INSIDE_NAME\"\n\texit 1\nfi\n##################################################\necho \" --------------------------------------------\"\necho \" Examining control files $2/rootfs ...\"\necho \" Pay attention to the dependencies as you\"\necho \"  may need to install some of them ...\"\necho \ntar -xzvf \"tmp/control.tar.gz\" -C \"tmp/\"\nif [ $? != \"0\" ] || [ ! -e \"tmp/control\" ]; then\n\techo \" ERROR: Extraction failed of control files (missing from IPK?)\"\n\tCleanupTmp \".\" \"$INSIDE_NAME\"\n\tcd \"$OLD_DIR\"\n\texit 1\nelse\n\t# todo: add proper dependency checking and more\n\t#\nOLD_IFS=\"$IFS\"\nIFS=\"NEWLINE\"\n\tcat \"tmp/control\"\n\tfor i in $( cat \"tmp/control\" | sed \"s/N\\/A/ /\" ); do\t\t\n\t\t#echo \" | $i\"\n\t\tif [ `expr \"$i\" : \"Source\"` = 7 ]; then\t\t\t\nSOURCE_PATH=`echo $i | sed s/Source:/ /`\n\t\t\t#echo \" dbg: handling SOURCE of $SOURCE_PATH\"\n\t\t\tif [ `expr \"$SOURCE_PATH\" : \"http://\"` = 7 ] || [ `expr \"$SOURCE_PATH\" : \"ftp://\"` = 7 ]; then\n\t\t\t\techo \" Found remote source .. downloading\"\n\t\t\t\techo \" !! THIS PART IS UNTESTED. WHO KNOWS IF IT WORKS ATM ;p\"\n\t\t\t\twget \"$SOURCE_PATH\"\n\t\t\tfi\n\t\tfi\n\tdone\nfi\nIFS=\"$OLD_IFS\"\necho \" --------------------------------------------\"\n##################################################\necho \" Extracting data files to $2/rootfs ...\"\ntar --overwrite -xzvf \"tmp/data.tar.gz\" -C \"../rootfs\" \n# no longer do this, we'll let the user evaluate the tar output..\n#if [ \"$?\" != \"0\" ]; then\n#\techo \" ERROR: Extraction failed of data.tar.gz - missing from IPK?\"\n#\tCleanupTmp \".\" \"$INSIDE_NAME\"\n#\tcd \"$OLD_DIR\"\n#\texit 1\n#else\n\techo \" Package installed !\"\t\n#fi\n##################################################\nCleanupTmp \".\" \"$INSIDE_NAME\"\ncd \"$OLD_DIR\"\nexit 0\n"
  },
  {
    "path": "ipkg_install_all.sh",
    "content": "#!/bin/sh\n#\n# $Id: ipkg_install_all.sh 336 2012-08-04 00:12:14Z jeremy.collake@gmail.com $\n#\n. \"./shared.inc\"\n### 20110225-MCT The VERSION is set in the shared.inc file from a single external source now.\nVERSION=\"${SHARED_VERSION}\"\n#\n# Title: ipkg_install_all.sh\n# Author: Jeremy Collake <jeremy.collake@gmail.com>\n# Site: hhttp://code.google.com/p/firmware-mod-kit/\n#\n# Invoke ipkg_install for every package in the given\n# folder.\n#\n# See documentation at:\n#  http://www.bitsum.com/firmware_mod_kit.htm\n#\n# USAGE: ipkg_install_all.sh PACKAGES_FOLDER WORKING_DIRECTORY/\n#\n# PACKAGE_SOURCE is the path to the .PKG file(s). \n#\n# WORKING_DIRECTORY is the working directory supplied to\n#  extract_firmware.sh.\n#\n# Example:\n#\n# ./ipkg_install_all.sh ../packages ../working_dir/\n#\necho \"$0 v$VERSION, (c)2006-2012 Jeremy Collake\"\n##################################################\nif [ ! $# = \"2\" ]; then\n\techo \" Invalid usage\"\n\techo \" USAGE: $0 PACKAGE_PATH WORKING_DIRECTORY\"\n\texit 1\nfi\nBASE_NAME=`basename $1`\necho \" Installing $BASE_NAME\"\n##################################################\nif [ ! -e \"$1\" ]; then\n\techo \" ERROR: $1 does not exist.\"\n\texit 1\nfi\n##################################################\nfor i in $( ls \"$1\" ); do\n\t./ipkg_install.sh $1/$i $2\ndone\n"
  },
  {
    "path": "ipkg_remove.sh",
    "content": "#!/bin/sh\n#\n# $Id: ipkg_remove.sh 336 2012-08-04 00:12:14Z jeremy.collake@gmail.com $\n#\n. \"./shared.inc\"\n### 20110225-MCT The VERSION is set in the shared.inc file from a single external source now.\nVERSION=\"${SHARED_VERSION}\"\n##################################################\n#\n# Title: ipkg_remove.sh\n# Author: Jeremy Collake <jeremy.collake@gmail.com>\n# Site: hhttp://code.google.com/p/firmware-mod-kit/\n#\n#\n# USAGE: ipkg_remove.sh nano_1.3.8-1_mipsel.ipk WORKING_DIRECTORY/\n#\n#\n# Example:\n#\n# ./ipkg_remove.sh dd-wrt.v23_generic.bin std_generic\n#\n#\necho \"$0 v$VERSION, (c)2006-2012 Jeremy Collake\"\necho \" !!WARNING!!! This script is in early alpha stage of development\"\n##################################################\n# CleanupTmp [base_dir] [package basename]\n#\nCleanupTmp()\n{\n\trm -rf \"$1/tmp\"  >> /dev/null 2>&1\n\trm \"$/control.tar.gz\"  >> /dev/null 2>&1\n\trm \"$/data.tar.gz\" >> /dev/null 2>&1\n\trm \"$1/$2\" >> /dev/null 2>&1\n}\n\n###########################################################\n# DeleteWithFolderTemplate ( target_dir , template_dir )\n#\n# deletes files and folders from a target folder\n# based on their presence in a template folder \n# (all files/dirs in template folder deleted from \n#  target folder).\n#\n# This function calls itself recursively.\n#\n# One would think there'd be an easier way to accomplish\n# this, and maybe there is... I am not a bash guru.\n#\nDeleteWithFolderTemplate()\n{\n\nlocal TARGET_DIR=$1\nlocal TEMPLATE_DIR=$2\n\n#echo \" Processing folder $TEMPLATE_DIR ..\"\n##################################################\nfor i in `ls $TEMPLATE_DIR`; do\n\t#echo \" dbg: $TEMPLATE_DIR/$i\"\n\tif [ -d $TEMPLATE_DIR/$i ]; then\n\t\tif [ -L $TEMPLATE_DIR/$i ]; then\n\t\t\techo \" Removing symbolic link $TARGET_DIR/$i\"\n\t\t\trm $TARGET_DIR/$i >> /dev/null 2>&1\n\t\telse\n\t\t\tDeleteWithFolderTemplate $TARGET_DIR/$i $TEMPLATE_DIR/$i\n\t\t\t# now remove folder if empty\n\t\t\trmdir $TARGET_DIR/$i >> /dev/null 2>&1\n\t\tfi\n\telif [ -f $TEMPLATE_DIR/$i ]; then\n\t\techo \" Removing file at $TARGET_DIR/$i\"\t\t\n\t\trm $TARGET_DIR/$i >> /dev/null\t2>&1\n\telse\n\t\techo \" WARNING: Unknown file type at $TEMPLATE_DIR/$i\"\n\tfi\t\ndone\n}\n\n##################################################\nif [ ! $# = \"2\" ]; then\n\techo \" Invalid usage\"\n\techo \" USAGE: $0 PACKAGE_PATH WORKING_DIRECTORY\"\n\texit 1\nfi\n\nBASE_NAME=`basename $1`\necho \" Removing $BASE_NAME\"\n####################################################\nif [ ! -e \"$1\" ]; then\n\techo \" ERROR: $1 does not exist.\"\n\texit 1\nfi\n\nOLD_DIR=`pwd`\n##################################################\n# notes:\n# OS X's tar utility doesn't like GZIP'd TARs .. (re: not TAR'd GZIPs ..),\n#  else we could just use tar (wh##################################################ich under linux accepts GZIPs as well).\n#\nmkdir -p \"$2/installed_packages/\" >> ipkg_remove.log\t2>&1\ncp $1 \"$2/installed_packages/\"\ncd \"$2/installed_packages\"\nINSIDE_NAME=`echo \"$BASE_NAME\" | sed \"s/.ipk/ /\"`\ngunzip < \"$BASE_NAME\" > \"$INSIDE_NAME\"\necho \" Assuming contents bore $INSIDE_NAME\"\nrm -rf tmp\nmkdir tmp\ntar -xf \"$INSIDE_NAME\" -C \"tmp/\"  >> /dev/null 2>&1\nif [ $? != 0 ]; then\n\techo \" ERROR: Extraction failed or incompatible format.\"\n\t#CleanupTmp \".\" \"$INSIDE_NAME\"\n\texit 1\nfi\n\n##################################################\necho \" Removing files from $2/rootfs ...\"\nrm -rf \"tmp/data\"  >> /dev/null 2>&1\nmkdir -p \"tmp/data\"  >> /dev/null 2>&1\ntar -xzvf \"tmp/data.tar.gz\" -C \"tmp/data\"  >> /dev/null 2>&1\nif [ $? != 0 ]; then\n\techo \" ERROR: Extraction failed of data.tar.gz (missing from IPK?)\"\n\tCleanupTmp \".\" \"$INSIDE_NAME\"\n\tcd \"$OLD_DIR\"\n\texit 1\nelse\n\techo \" Package removed successfully!\"\t\nfi\n\n# \n# using . as a template, delete from working rootfs\n#\ncd \"$OLD_DIR\"\nDeleteWithFolderTemplate $2/rootfs \"$2/installed_packages/tmp/data\"\ncd \"$2/installed_packages\"\n\n##################################################\necho \" --------------------------------------------\"\necho \" Examining control files $2/rootfs ...\"\necho \" Pay attention to the dependencies as you\"\necho \"  may want to remove some of them if not\"\necho \"  used by any other installed package.\"\necho \ntar -xzf \"tmp/control.tar.gz\" -C \"tmp/\"\nif [ $? != 0 ] || [ ! -e \"tmp/control\" ]; then\n\techo \" ERROR: Extraction failed of control files (missing from IPK?)\"\n\tCleanupTmp \".\" \"$INSIDE_NAME\"\n\tcd \"$OLD_DIR\"\n\texit 1\nelse\t\n\t# todo: add proper dependency checking and more\n\tcat \"tmp/control\"\t\t\n\t# if successeful, remove the package from the installed_packages\n\t# folder\n\tCleanupTmp \".\" \"$INSIDE_NAME\"\n\techo \" Removing package IPK from installed_packages ...\"\n\tcd \"$OLD_DIR\"\t\t\t\nfi\necho \" --------------------------------------------\"\n##################################################\nexit 0\n"
  },
  {
    "path": "ipkg_remove_all.sh",
    "content": "#!/bin/sh\n#\n# $Id: ipkg_remove_all.sh 336 2012-08-04 00:12:14Z jeremy.collake@gmail.com $\n#\n. \"./shared.inc\"\n### 20110225-MCT The VERSION is set in the shared.inc file from a single external source now.\nVERSION=\"${SHARED_VERSION}\"\n#\n# Title: ipkg_install_all.sh\n# Author: Jeremy Collake <jeremy.collake@gmail.com>\n# Site: http://code.google.com/p/firmware-mod-kit/\n#\n# Invoke ipkg_install for every package in the given\n# folder.\n#\n# See documentation at:\n#  http://www.bitsum.com/firmware_mod_kit.htm\n#\n# USAGE: ipkg_remove_all.sh PACKAGES_FOLDER WORKING_DIRECTORY/\n#\n# PACKAGE_SOURCE is the path to the .PKG file(s). \n#\n# WORKING_DIRECTORY is the working directory supplied to\n#  extract_firmware.sh.\n#\n# Example:\n#\n# ./ipkg_remove_all.sh ../packages ../working_dir/\n#\necho \"$0 v$VERSION, (c)2006-2012 Jeremy Collake\"\n##################################################\nif [ ! $# = \"2\" ]; then\n\techo \" Invalid usage\"\n\techo \" USAGE: $0 PACKAGE_PATH WORKING_DIRECTORY\"\n\texit 1\nfi\nBASE_NAME=`basename $1`\necho \" Installing $BASE_NAME\"\n##################################################\nif [ ! -e \"$1\" ]; then\n\techo \" ERROR: $1 does not exist.\"\n\texit 1\nfi\n##################################################\nfor i in $( ls \"$1\" ); do\n\t\"./ipkg_remove.sh\" \"$1/$i\" \"$2\"\ndone\n"
  },
  {
    "path": "old-build.sh",
    "content": "#!/bin/sh\n#\n# $Id: build_firmware.sh 333 2012-08-03 22:59:39Z jeremy.collake@gmail.com $\n#\n. \"./shared.inc\"\n### 20110225-MCT The VERSION is set in the shared.inc file from a single external source now.\nVERSION=\"${SHARED_VERSION}\"\n#\n# Title: build_firmware.sh\n# Author: Jeremy Collake <jeremy.collake@gmail.com>\n# Site: http://code.google.com/p/firmware-mod-kit/\n#\n# USAGE: old-build.sh OUTPUT_DIRECTORY/ WORKING_DIRECOTRY/\n#\n# This scripts builds the firmware image from [WORKING_DIRECTORY],\n# with the following subdirectories:\n#\n#    image_parts/   <- firmware seperated\n#    rootfs/ \t    <- filesystem\n#\n# Example:\n#\n# ./old-build.sh new_firmwares/ std_generic/\n#\n## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\n# 20110225-0746-MCT - Added rebuild number.\n# + Enhanced previous patch to include a rebuild\n#   number that increments.\n# + Moved this log to below the authors space.\n# 20110224-1507-MCT - Two simple mods.\n# + Put the name of the build into an external file so that\n#   it's easier to customize.\n# + Modified a var to correct the spelling. :)\n#   Changed FIRMARE_BASE_NAME to FIRMWARE_BASE_NAME\n## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\n#\n\nEXIT_ON_FS_PROBLEM=\"0\"\n\necho\necho \" Firmware Mod Kit (extract) v$VERSION, (c)2010-2012 Jeremy Collake, - Newer NG edition by Craig Heffner\"\n\n#################################################################\n# function: BuildLinuxRawFirmwareType\n# puts together firmwares types like the TEW-632BRP\n#################################################################\nBuildLinuxRawFirmwareType() {\t\n\tOUTPUT_PATH=$1\n\tPARTS_PATH=$2\n\tOUTPUT_FIRMWARE_FILENAME=\"output-firmware.bin\"\n\techo \" Building firmware from directory $2 ...\"\t\t\n\tif [ ! -e \"$PARTS_PATH/rootfs/\" ]; then\n\t\techo \" ERROR: rootfs must exist\"\n\t\texit 1\n\tfi\n\tmkdir -p \"$OUTPUT_PATH\"\n\trm -f \"$PARTS_PATH/image_parts/squashfs-3-lzma.img\" \"$OUTPUT_PATH/$OUTPUT_FIRMWARE_FILENAME\" \"$PARTS_PATH/image_parts/rootfs.img\" \"$PARTS_PATH/image_parts/*.new\"\n\tif [ -f \"$PARTS_PATH/.squashfs3_lzma_fs\" ]; then\t\t\t\n\t\t# make squashfs image if marker present\n\t\techo \" Building squashfs-lzma file system (big endian) ...\"\n\t\tif [ -f \"$2/.linux_raw_type3\" ]; then\n\t\t\techo \" !!! WARNING: This raw embedded linux image type is UNTESTED - added Nov 6 2010\"\n\t\t\techo \" !!! DO NOT FLASH UNLESS YOU ARE PREPARED TO RECOVER FROM A BRICKED ROUTER\"\n\t\t\techo \" !!! YOU HAVE BEEN WARNED AND ASSUME LIABILITY FOR DAMAGES IF YOU DO FLASH IT\"\n\t\t\t./src/squashfs-3.0/mksquashfs-lzma \"$PARTS_PATH/rootfs/\" \"$PARTS_PATH/image_parts/squashfs-3-lzma.img\" -all-root -be -noappend -b 65536 2>/dev/null >> build.log\n\t\telse\n\t\t\t./src/squashfs-3.0/mksquashfs-lzma \"$PARTS_PATH/rootfs/\" \"$PARTS_PATH/image_parts/squashfs-3-lzma.img\" -all-root -be -noappend 2>/dev/null >> build.log\n\t\tfi\n\t\tln -s \"squashfs-3-lzma.img\" \"$PARTS_PATH/image_parts/rootfs.img\"\t\t\t\n\t\tfilesize=$(du -b \"$PARTS_PATH/image_parts/squashfs-3-lzma.img\" | cut -f 1)\n\telse\n\t\t# make jffs2 image if marker not present\n\t\techo \" Building JFFS2 file system (big endian) ...\"\n\t\t./src/jffs2/mkfs.jffs2 -r \"$PARTS_PATH/rootfs/\" -o \"$PARTS_PATH/image_parts/jffs2.img\" --big-endian --squash # 2>/dev/null >> build.log\n\t\tln -s \"jffs2.img\" \"$PARTS_PATH/image_parts/rootfs.img\"\n\t\tfilesize=$(du -b \"$PARTS_PATH/image_parts/jffs2.img\" | cut -f 1)\n\tfi\n\t# build firmware image\n\tcp \"$PARTS_PATH/image_parts/vmlinuz\" \"$OUTPUT_PATH/$OUTPUT_FIRMWARE_FILENAME\"\n\tif [ -f \"$2/.linux_raw_type3\" ]; then\n\t\techo \" Building RAW IMAGE TYPE 3\"\t\n\t\tcat \"$PARTS_PATH/image_parts/rootfs.img\" >> \"$OUTPUT_PATH/$OUTPUT_FIRMWARE_FILENAME\"\n\telse\n\t\tdd \"if=$PARTS_PATH/image_parts/rootfs.img\" \"of=$OUTPUT_PATH/$OUTPUT_FIRMWARE_FILENAME\" bs=1K seek=1024 2>/dev/null >> build.log\n\tfi\n\tif [ -f \"$PARTS_PATH/image_parts/hwid.txt\" ]; then\n\t\t# user report: prepend four NULL bytes to the platform ID, causes image to be accepted on \n\t\t#  either TEW-632BRP A1.0 or A1.1 by effectively nullifying the platform ID\n\t\t# \"\\000\\000\\000\\000\" >> \"$OUTPUT_PATH/$OUTPUT_FIRMWARE_FILENAME\"\n\t\t# now write platform ID\n\t\tcat \"$PARTS_PATH/image_parts/hwid.txt\" >> \"$OUTPUT_PATH/$OUTPUT_FIRMWARE_FILENAME\"\n\telse\n\t\techo \" ERROR: hwid.txt not found. This image needs a TARGET.\"\n\t\texit 1\n\tfi\t\n\tfilesize=$(du -b \"$OUTPUT_PATH/$OUTPUT_FIRMWARE_FILENAME\" | cut -f 1)\n\tif [ $filesize -ge 3866649 ]; then\n\t\techo \" WARNING: firmware image may be too large for routers with 4MB ROM ...\"\n\tfi\n\n}\n\n#################################################################\n# InvokeTRX ( OutputDir, WorkingDir, filesystem image filename )\n#################################################################\nInvokeTRX ()\n{\n\techo \" Building base firmware image (generic) ...\"\t\n\tSEGMENT_1=\"$2/image_parts/segment1\"\n\tif [ -f \"$2/image_parts/segment2\" ]; then\n\t\tSEGMENT_2=\"$2/image_parts/segment2\"\n\telse\n\t\tSEGMENT_2=\"\"\n\tfi\n\t# I switched to asustrx due to bug in trx with big endian OS X.\n\t#  it works just like trx if you don't supply a version number (skips addver appendage)\n\t\"src/asustrx\" -o \"$1/$FIRMWARE_BASE_NAME.trx\" \\\n\t\t$SEGMENT_1 $SEGMENT_2 \\\n\t\t\"$2/image_parts/$3\" \\\n\t\t\t>> build.log 2>&1\n\techo \" Building base firmware image (asus) ...\"\t\n\t\"src/asustrx\" -p WL500gx -v 1.9.2.7 -o \"$1/$FIRMWARE_BASE_NAME-asus.trx\" \\\n\t\t$SEGMENT_1 $SEGMENT_2 \\\n\t\t\"$2/image_parts/$3\" \\\n\t\t >> build.log 2>&1\n\n}\n\n#################################################################\n# CreateTargetImages ( OutputDir, WorkingDir )\n#\n# addpattern (HDR0) images. Maybe other model specific stuff\n# later.\n#################################################################\nCreateTargetImages ()\n{\n\techo \" Making $1/$FIRMWARE_BASE_NAME-wrtsl54gs.bin\"\n\tif [ ! -f \"$1/$FIRMWARE_BASE_NAME.trx\" ]; then\n\t\techo \" ERROR: Sanity check failed.\"\n\t\texit 1\n\tfi\n\t\"src/addpattern\" -4 -p W54U -v v4.20.6 -i \"$1/$FIRMWARE_BASE_NAME.trx\" \\\n\t\t -o \"$1/$FIRMWARE_BASE_NAME-wrtsl54gs.bin\" -g >> build.log 2>&1\n\techo \" Making $1/$FIRMWARE_BASE_NAME-wrt54g.bin\"\n\t\"src/addpattern\" -4 -p W54G -v v4.20.6 -i \"$1/$FIRMWARE_BASE_NAME.trx\" \\\n\t\t-o \"$1/$FIRMWARE_BASE_NAME-wrt54g.bin\" -g >> build.log 2>&1\n\techo \" Making $1/$FIRMWARE_BASE_NAME-wrt54gs.bin\"\n\t\"src/addpattern\" -4 -p W54S -v v4.70.6 -i \"$1/$FIRMWARE_BASE_NAME.trx\" \\\n\t\t-o \"$1/$FIRMWARE_BASE_NAME-wrt54gs.bin\" -g >> build.log 2>&1\n\techo \" Making $1/$FIRMWARE_BASE_NAME-wrt54gsv4.bin\"\n\t\"src/addpattern\" -4 -p W54s -v v1.05.0 -i \"$1/$FIRMWARE_BASE_NAME.trx\" \\\n\t\t-o \"$1/$FIRMWARE_BASE_NAME-wrt54gsv4.bin\" -g >> build.log 2>&1\n\techo \" Making $1/$FIRMWARE_BASE_NAME-generic.bin\"\n\tln -s \"$FIRMWARE_BASE_NAME.trx\" \"$1/$FIRMWARE_BASE_NAME-generic.bin\" >> build.log 2>&1\n}\n\n#################################################################\n# Build_WRT_Images( OutputDir, WorkingDir )\n#################################################################\nBuild_WRT_Images ()\n{\n\techo \" Building squashfs-lzma filesystem ...\"\n\tif [ -e \"$2/image_parts/squashfs-lzma-image-3_0\" ]; then\t\t\t\n\t\tif [ -f \"$2/image_parts/.sq_lzma_damn_small_variant_marker\" ]; then\n\t\t   echo \" Utilizing lzma damn small variant ...\"\t\t   \n\t\t   echo \" WARNING: Support for these recently added, not fully tested... be careful.\"\n\t\t   echo \"          Please report to jeremy.collake@gmail.com success or failure.\"\n\t\t   echo \" This may take a while ...\"\n\t\t   \"src/squashfs-3.0-lzma-damn-small-variant/mksquashfs-lzma\" \"$2/rootfs/\" \"$2/image_parts/squashfs-lzma-image-new\" \\\n\t\t\t-noappend -root-owned -le >> build.log\t\t\n\t\telse\n\t\t   echo \" Utilizing lzma standard variant ...\"\n\t\t   \"src/squashfs-3.0/mksquashfs-lzma\" \"$2/rootfs/\" \"$2/image_parts/squashfs-lzma-image-new\" \\\n\t\t\t-noappend -root-owned -le -magic \"$2/image_parts/squashfs_magic\" >> build.log\t\t\n\t\tfi\n\t\t# -magic to fix brainslayer changing squashfs signature in 08/10/06+ firmware images\n\t \tif [ $? != 0 ]; then\n\t\t\techo \" ERROR - mksquashfs failed.\"\n\t\t\texit 1\t\n\t\tfi\n\telif [ -f \"$2/image_parts/squashfs-lzma-image-2_x\" ]; then\n\t\t echo \" Utilizing squashfs lzma 2.1-r2 ...\"\n\t\t   \"src/squashfs-2.1-r2/mksquashfs-lzma\" \"$2/rootfs/\" \"$2/image_parts/squashfs-lzma-image-new\" \\\n\t\t\t-noappend -le >> build.log\t\n\telse\n\t\techo \" ERROR - Working directory contains no sqfs filesystem?\"\n\t\texit 1\n\tfi\t\n\t#################################################################\n\tInvokeTRX \"$1\" \"$2\" \"squashfs-lzma-image-new\"\n\tCreateTargetImages \"$1\" \"$2\" \t\n}\n\n#################################################################\n# MakeCramfs (output file, root dir)\n#\n# invokes mkcramfs\n#\n#################################################################\nMakeCramfs ()\n{\n\techo \" Building cramfs file system ...\"\n\t./src/cramfs-2.x/mkcramfs \"$2\" \"$1\" >> build.log 2>&1\n\tif [ $? != 0 ]; then\n\t\techo \" ERROR: creating cramfs file system failed.\".\n\t\texit \"$?\"\n\telse\n\t\techo \" Successfully created cramfs image.\"\n\tfi\n}\n\n#################################################################\n# Build_WL530G_Image (OutputDir, WorkingDir, fs image filename [only] )\n#\n# Builds an ASUS WL530/520/550G image.\n#\n#################################################################\nBuild_WL530G_Image ()\n{\n\techo \" Building wl-530/520/550g style image (static TRX offsets).\"\n\t./src/asustrx -p WL530g -v 1.9.4.6 -o \"$1/$FIRMWARE_BASE_NAME-wl530g.trx\" -b 32 \"$2/image_parts/segment1\" -b 655360 \"$2/image_parts/$3\"  >> build.log 2>&1\t\n}\n\n\n#################################################################\n#################################################################\n#################################################################\n\nif [ $# = 2 ]; then\n\tPlatformIdentify \n\t#################################################################\n\tTestFileSystemExit \"$1\" \"$2\"\n\t#################################################################\n\tTestIsRoot\n\t#################################################################\n\tif [ ! -f \"./old-build.sh\" ]; then\n\t\techo \" ERROR - You must run this script from the same directory as it is in!\"\n\t\texit 1\n\tfi\n\t#################################################################\n\n\tif [ ! -f .firmware_rebuild_number ] ; then\n\t\tFIRMWARE_REBUILD_NUMBER=1\n\t\techo ${FIRMWARE_REBUILD_NUMBER} > .firmware_rebuild_number\n\telse\n\t\tFIRMWARE_REBUILD_NUMBER=$( cat .firmware_rebuild_number )\n\t\t(( FIRMWARE_REBUILD_NUMBER+=1 ))\n\t\techo ${FIRMWARE_REBUILD_NUMBER} > .firmware_rebuild_number\n\tfi\n\tif [ ! -f .firmware_base_name ] ; then\n\t\tFIRMWARE_BASE_NAME=custom_image\n\t\techo $FIRMWARE_BASE_NAME > .firmware_base_name\n\telse\n\t\tFIRMWARE_BASE_NAME=\"$( cat .firmware_base_name )\"\n\tfi\n\tFIRMWARE_BASE_NAME=$( printf \"%s_%05d\" ${FIRMWARE_BASE_NAME} ${FIRMWARE_REBUILD_NUMBER} )\n\techo \"Rebuilt: ${FIRMWARE_BASE_NAME} With: Firmware Mod Kit (build) v$VERSION, (c)2010 Jeremy Collake\" > \"$2/rootfs/etc/rebuild_info\"\n\n\t#################################################################\n\t# remove deprecated stuff\n\tif [ -f \"./src/mksquashfs.c\" ] || [ -f \"mksquashfs.c\" ]; then\n\t\tDeprecateOldVersion\n\tfi\n\t#################################################################\n\t# Invoke BuildTools, which tries to build everything and then\n\t# sets up appropriate symlinks.\n\t#\n\tBuildTools \"build.log\"\n\t#################################################################\n\techo \" Preparing output directory $1 ...\"\n\tmkdir -p $1 >> build.log 2>&1\n\trm \"$1/$FIRMWARE_BASE_NAME*.*\" \"$1\" >> build.log 2>&1\n\t\n\tif [ -f \"$2/.linux_raw_type\" ]; then\n\t\techo \" Detected linux raw type firmware.\"\n\t\tBuildLinuxRawFirmwareType \"$1\" \"$2\"\t\t\n\telif [ -f \"$2/.linux_raw_type3\" ]; then\n\t\techo \" Detected linux raw type firmware.\"\n\t\tBuildLinuxRawFirmwareType \"$1\" \"$2\"\t\n\telif [ -f \"$2/image_parts/.trx-sqfs\" ]; then\n\t\techo \" Detected WRT squashfs-lzma style.\"\n\t\tBuild_WRT_Images \"$1\" \"$2\"\n\telif [ -f \"$2/image_parts/cramfs-image-x_x\" ]; then\n\t\techo \" Detected cramfs file system.\"\n\t\tTestIsRoot\n\t\t# remove old filename of new image..\n\t\trm -f \"$2/image_parts/cramfs-image-1.1\"\n\t\tMakeCramfs \"$2/image_parts/cramfs-image-new\" \"$2/rootfs\"\n\t\t# todo: rewrite this terrible test\n\t\tgrep \"530g\" \"$2/image_parts/cramfs-image-x_x\" >> build.log 2>&1\t\t\t\t\n\t\tif [ $? = \"0\" ]; then\n\t\t\tIS_530G_STYLE=1\n\t\tfi\n\t\tgrep \"550g\" \"$2/image_parts/cramfs-image-x_x\" >> build.log 2>&1\t\t\t\n\t\tif [ $? = \"0\" ]; then\n\t\t\tIS_530G_STYLE=1\n\t\tfi\n\t\tgrep \"520g\" \"$2/image_parts/cramfs-image-x_x\" >> build.log 2>&1\t\t\n\t\tif [ $? = \"0\" ]; then\n\t\t\tIS_530G_STYLE=1\n\t\tfi\n\t\tif [ \"$IS_530G_STYLE\" = \"1\" ]; then\t\t\n\t\t\tBuild_WL530G_Image \"$1\" \"$2\" \"cramfs-image-new\"\n\t\telse\n\t\t\techo \" No specific firmware type known, so am making standard images.\"\n\t\t\tInvokeTRX \"$1\" \"$2\" \"cramfs-image-new\"\n\t\t\tCreateTargetImages \"$1\" \"$2\"\t\t\t\n\t\tfi \n\telse\t\t\n\t\techo \" ERROR: Unknown or unsupported firmware image.\"\n\t\texit 1\n\tfi\n\n\techo \" Firmware images built.\"\n\tls -l \"$1\"\n\tmd5sum -b \"$1\"/${FIRMWARE_BASE_NAME}* > \"$1\"/${FIRMWARE_BASE_NAME}.md5sums\n\techo \" All done!\"\nelse\n\t#################################################################\n\techo \" Incorrect usage.\"\n\techo \" USAGE: $0 OUTPUT_DIR WORKING_DIR\"\n\texit 1\nfi\nexit 0\n"
  },
  {
    "path": "old-extract.sh",
    "content": "#!/bin/sh\n#\n# $Id: extract_firmware.sh 336 2012-08-04 00:12:14Z jeremy.collake@gmail.com $\n#\n. \"./shared.inc\"\n### 20110225-MCT The VERSION is set in the shared.inc file from a single external source now.\nVERSION=\"${SHARED_VERSION}\"\n#\n# Title: extract_firmware.sh\n# Author: Jeremy Collake <jeremy.collake@gmail.com>\n# Site: http://code.google.com/p/firmware-mod-kit/\n#\n# USAGE: old-extract.sh FIRMWARE_IMAGE.BIN WORKING_DIRECTORY/\n#\n# This scripts extacts the firmware image to [WORKING_DIRECTORY],\n# with the following subdirectories:\n#\n#    image_parts/   <- firmware seperated\n#    rootfs/ \t    <- extracted filesystem\n#\n# Example:\n#\n# ./old-extract.sh dd-wrt.v23_generic.bin std_generic\n#\n#\nEXIT_ON_FS_PROBLEM=\"0\"\n\necho\necho \" Firmware Mod Kit (extract) v$VERSION, (c)2010-2012 Jeremy Collake, - Newer NG edition by Craig Heffner\"\n\n#################################################################\n#\n# function: ExtractLinuxRawFirmwareType ()\n# \n# Extracts essentially 'raw' firmware images with kernel, filesystem, and hardware id\n# Example is the TrendNET TEW-632BRP router.\n#\nExtractLinuxRawFirmwareType ()\n{\n\t# $1 = input firmware\n\tPARTS_PATH=$2\t\n\techo \" Extracting $1 to $2 ...\"\n\tmkdir -p \"$PARTS_PATH/image_parts\"\n\tif [ $? = 0 ]; then\n \t\tdd \"if=$1\" \"of=$PARTS_PATH/image_parts/vmlinuz\" bs=1K count=1024 2>/dev/null >> extract.log\n \t\tdd \"if=$1\" \"of=$PARTS_PATH/image_parts/squashfs-3-lzma.img\" bs=1K skip=1024 2>/dev/null >> extract.log\n                SYSNAME=`uname`\n                if [ `expr \"$SYSNAME\" : \"Darwin\"` = 6 ]; then\n\t\t\tfilesize=$(ls -la $1 | awk '{print $5}')\n\t\telse\n\t\t\tfilesize=$(du --apparent-size --block-size=1 $1 | cut -f 1)\n\t\tfi\n\t\tfilesize=$((filesize - 24))\n\t\tdd \"if=$1\" \"of=$PARTS_PATH/image_parts/hwid.txt\" bs=1 skip=$filesize 2>/dev/null >> extract.log\n\t\t\"./src/squashfs-3.0/unsquashfs-lzma\" -dest \"$PARTS_PATH/rootfs\" \\\n\t\t\t\"$PARTS_PATH/image_parts/squashfs-3-lzma.img\" 2>/dev/null >> extract.log\n\t\tif [ -e \"$PARTS_PATH/rootfs/\" ]; then\n\t\t\t# write a marker to indicate the firmware image type and filesystem type\n\t\t\ttouch \"$PARTS_PATH/.linux_raw_type\"\n\t\t\ttouch \"$PARTS_PATH/.squashfs3_lzma_fs\"\n\t\tfi\n\telse\n\t\techo \" ERROR: Creating output directory..\"\n\tfi\t\n}\n\n#################################################################\n#\n# Main script entry \n#\n#################################################################\n\nif [ $# = 2 ]; then\n\tPlatformIdentify\n\t#################################################################\n\tTestFileSystemExit $1 $2\n\t#################################################################\n\tTestIsRoot\n\t#################################################################\n\tif [ -f \"$1\" ]; then\n\t\tif [ ! -f \"./old-extract.sh\" ]; then\n\t\t\techo \" ERROR - You must run this script from the same directory as it is in!\"\n\t\t\texit 1\n\t\tfi\n\t\t#################################################################\n\t\t# remove deprecated stuff\n\t\tif [ -f \"./src/mksquashfs.c\" ] || [ -f \"mksquashfs.c\" ]; then\n\t\t\tDeprecateOldVersion\n\t\tfi\n\t\t#################################################################\n\t\t# Invoke BuildTools, which tries to build everything and then\n\t\t# sets up appropriate symlinks.\n\t\t#\n\t\tBuildTools \"extract.log\"\t\t\t\t     \t\t\t\t\t\n\t\t#################################################################\t\t\n\t\techo \" Preparing working directory ...\"\n\t\techo \" Removing any previous files ...\"\n\t\trm -rf \"$2/rootfs\" >> extract.log 2>&1\n\t\trm -rf \"$2/image_parts\" >> extract.log 2>&1\n\t\trm -rf \"$2/installed_packages\" >> extract.log 2>&1\n\t\techo \" Creating directories ...\"\n\t\tmkdir -p \"$2/image_parts\" >> extract.log 2>&1\n\t\tmkdir -p \"$2/installed_packages\" >> extract.log 2>&1\n\t\techo \" Extracting firmware\"\n\t\t\"src/untrx\" \"$1\" \"$2/image_parts\" >> extract.log 2>&1\t\t\n\t \tif [ $? != 0 ]; then\n\t\t\techo \"! untrx failed, trying splitter3\";\n\t\t\t\"src/splitter3\" \"$1\" \"$2/image_parts\" >> extract.log 2>&1\n\t\t \tif [ $? != 0 ]; then\n\t\t\t\techo \" Not recognized by splitter3\";\n\t\t\t\t# exit 1\n\t\t\telse\n\t\t\t\ttouch \"$2/.linux_raw_type3\"\n\t\t\t\ttouch \"$2/.squashfs3_lzma_fs\"\n\t\t\tfi\n\t\tfi\n\t\t# if unknown version, then we'll just try to use the latest UnSquashFS we have\n\t\tif [ -f \"$2/image_parts/squashfs-lzma-image-x_x\" ]; then\t\n\t\t\tln -s \"squashfs-lzma-image-x_x\" \"$2/image_parts/squashfs-lzma-image-3_0\"\n\t\tfi\n\t\t# if squashfs 3.1 or 3.2, symlink it to 3.0 image, since they are compatible\n\t\tif [ -f \"$2/image_parts/squashfs-lzma-image-3_1\" ]; then\t\n\t\t\tln -s \"squashfs-lzma-image-3_1\" \"$2/image_parts/squashfs-lzma-image-3_0\"\n\t\tfi\n\t\tif [ -f \"$2/image_parts/squashfs-lzma-image-3_2\" ]; then\t\n\t\t\tln -s \"squashfs-lzma-image-3_2\" \"$2/image_parts/squashfs-lzma-image-3_0\"\n\t\tfi\n\t\tif [ -f \"$2/image_parts/squashfs-lzma-image-3_x\" ]; then\t\n\t\t\tln -s \"squashfs-lzma-image-3_x\" \"$2/image_parts/squashfs-lzma-image-3_0\"\n\t\tfi\n\t\tif [ -f \"$2/image_parts/squashfs-lzma-image-2_0\" ]; then\t\n\t\t\tln -s \"squashfs-lzma-image-2_0\" \"$2/image_parts/squashfs-lzma-image-2_x\"\n\t\tfi\n\t\tif [ -f \"$2/image_parts/squashfs-lzma-image-2_1\" ]; then\t\n\t\t\tln -s \"squashfs-lzma-image-2_1\" \"$2/image_parts/squashfs-lzma-image-2_x\"\n\t\tfi\n\t\t# now unsquashfs, if filesystem is squashfs\n\t\tif [ -f \"$2/image_parts/squashfs-lzma-image-3_0\" ]; then\n\t\t\techo \" Attempting squashfs 3.0 lzma ...\"\n\t \t\t\"src/squashfs-3.0/unsquashfs-lzma\" \\\n\t\t\t-dest \"$2/rootfs\" \"$2/image_parts/squashfs-lzma-image-3_0\" 2>/dev/null >> extract.log\n\t\t\tif [ ! -e \"$2/rootfs\" ]; then\t\t\t\t\n\t\t\t\techo \" Trying 'damn small' variant - used by DD-WRT v24 ...\"\t\t\t\t\t\t\t\t\n\t \t\t\t\"src/squashfs-3.0-lzma-damn-small-variant/unsquashfs-lzma\" \\\n\t\t\t\t\t-dest \"$2/rootfs\" \"$2/image_parts/squashfs-lzma-image-3_0\" 2>/dev/null >> extract.log\t\t\t\t\n\t\t\t\tif [ -e \"$2/rootfs\" ]; then\n\t\t\t\t\t# if it worked, then write a tag so we know which squashfs variant to build the fs with\n\t\t\t\t\ttouch \"$2/image_parts/.sq_lzma_damn_small_variant_marker\"\n\t\t\t\t\ttouch \"$2/image_parts/.trx-sqfs\"\t\t\t\n\t\t\t\tfi\n\t\t\telse\t\t\t\t\n\t\t\t\ttouch \"$2/image_parts/.trx-sqfs\"\t\t\t\n\t\t\tfi\n\t\telif [ -f \"$2/image_parts/squashfs-lzma-image-2_x\" ]; then\t\t\t\n\t\t\t\"src/squashfs-2.1-r2/unsquashfs-lzma\" \\\n\t\t\t-dest \"$2/rootfs\" \"$2/image_parts/squashfs-lzma-image-2_x\" 2>/dev/null >>extract.log\t\t\t\t\t\t\t\n\t\t\tif [ -e \"$2/rootfs\" ]; then\t\t\t\t\t\t\t\n\t\t\t\ttouch \"$2/image_parts/.trx-sqfs\"\n\t\t\telse\n\t\t\t\techo \" ERROR: extracting filesystem.\"\n\t\t\tfi\n\t\telif [ -f \"$2/image_parts/cramfs-image-x_x\" ]; then\n\t\t\tTestIsRoot\n\t\t\t\"src/cramfs-2.x/cramfsck\" \\\n\t\t\t\t-v -x \"$2/rootfs\" \"$2/image_parts/cramfs-image-x_x\" >> extract.log 2>&1\t\t\t\n\t\telse\n\t\t\techo \" Attempting raw linux style firmware package (i.e. TEW-632BRP) ...\"\n\t\t\tExtractLinuxRawFirmwareType \"$1\" \"$2\"\t\t\t\n\t\tfi\n\t\tif [ -e \"$2/rootfs\" ]; then\n\t\t\techo \" Firmware appears extracted correctly!\"\n\t\t\techo \" Now make changes and run build_firmware.sh.\"\n\t\telse\n\t\t\techo \" Error: filesystem not extracted properly.\"\n\t\t\techo \"  firmware image format not compatible?\"\n\t\t\texit 1\n\t\tfi\t\n\telse\n\t\techo \" $1 does not exist.. give me something to work with man!\"\n\tfi\nelse\n\techo \" Incorrect usage.\"\n\techo \" USAGE: $0 FIRMWARE_IMAGE.BIN WORKING_DIR\"\n\texit 1\nfi\nexit 0\n"
  },
  {
    "path": "shared-ng.inc",
    "content": "VERSION=$(cat firmware_mod_kit_version.txt)\nIMAGE_PARTS=\"$DIR/image_parts\"\nLOGS=\"$DIR/logs\"\nCONFLOG=\"$LOGS/config.log\"\nBINLOG=\"$LOGS/binwalk.log\"\nROOTFS=\"$DIR/rootfs\"\nFSIMG=\"$IMAGE_PARTS/rootfs.img\"\nHEADER_IMAGE=\"$IMAGE_PARTS/header.img\"\nFOOTER_IMAGE=\"$IMAGE_PARTS/footer.img\"\nFWOUT=\"$DIR/new-firmware.bin\"\nBINWALK=\"./src/binwalk-1.0/src/bin/binwalk-script -v -m ./src/binwalk-1.0/src/binwalk/magic/binwalk\"\n"
  },
  {
    "path": "shared.inc",
    "content": "#!/bin/sh\nSHARED_VERSION=\"$( cat firmware_mod_kit_version.txt )\"\n#\n# Title: shared.inc\n# Author: Jeremy Collake <jeremy.collake@gmail.com>\n#\n# Shared functions\n#\n#\n#\n\n#################################################################\nWarningPrompt ()\n{\n\tread -p \" [ Press any key to contrinue, or abort now with break signal (CTRL-C) ]\"\n}\n#################################################################\nPlatformIdentify ()\n{\nSYSNAME=`uname`\n\tif [ \"$SYSNAME\" = \"Linux\" ]; then\n\t\techo \" LINUX system detected. Compatibility ok.\"\t\n\telif [ `expr \"$SYSNAME\" : \"Darwin\"` = 6 ]; then\n\t\techo \" OS X system detected. **BETA TESTING**\"\n\t\techo \" This platform is not well tested.\"\n\t\tWarningPrompt\t\t\t\t\n\telif [ `expr \"$SYSNAME\" : \"CYGWIN\"` = 6 ]; then\n\t\techo \" CYGWIN system detected. **BETA TESTING** Built images may have problems.\"\n\t\techo \" This platform is not well tested.\"\n\t\tWarningPrompt\t\t\t\n\telse\n\t\techo \" Unknown system detected. Compatibility state is unknown.\"\n\t\tWarningPrompt\n\tfi\n}\n#################################################################\nTestFileSystemExit ()\n{\nINPUT_FILE=$1\nWORKING_DIR=$2\n\techo \" Testing file system of $WORKING_DIR ...\"\n\tmkdir -p \"$WORKING_DIR\" >> /dev/null 2>&1\n\trm \"$WORKING_DIR/test12345612.tmp\" >> /dev/null 2>&1\n\techo test > \"$WORKING_DIR/test12345612.tmp\"\n\tif [ -e \"$WORKING_DIR/teST12345612.tmp\" ]; then\n\t\techo \"  WARNING: File system $WORKING_DIR is not case sensitive.\"\t\t\n\t\techo \"      For some firmwares this can cause troubles in the\"\n\t\techo \"      built images that result in runtime errata or\"\n\t\techo \"      even refuse to boot.\"\n\t\tif [ $EXIT_ON_FS_PROBLEM = \"1\" ]; then\n\t\t\trm \"$WORKING_DIR/test12345612.tmp\" >> /dev/null 2>&1\n\t\t\texit 2\n\t\telse\n\t\t\tWarningPrompt\t\t\t\t\n\t\tfi\t\n\tfi\t\n\tif [ ! -e \"$WORKING_DIR/test12345612.tmp\" ]; then\n\t\techo \"  ERROR: File system $WORKING_DIR is not writable.\"\n\t\trm \"$WORKING_DIR/test12345612.tmp\" >> /dev/null 2>&1\n\t\texit 3\n\tfi\n\trm \"$WORKING_DIR/test12345612.tmp\" >> /dev/null 2>&1\n}\n#################################################################\n# LinkToolsBinraries (srcfolder, destfolder)\n#LinkToolsBinaries ()\n#{\n## deprecated v0.44\n#\tln -s -f $1/asustrx $2/asustrx\n#\tln -s -f $1/untrx $2/untrx\n#\tln -s -f $1/mksquashfs $2/mksquashfs\n#\tln -s -f $1/mksquashfs-lzma $2/mksquashfs-lzma\t\n#\tln -s -f $1/unsquashfs $2/unsquashfs\n#\tln -s -f $1/unsquashfs-lzma $2/unsquashfs-lzma\n#\tln -s -f $1/addpattern $2/addpattern\t\n#}\n\n#################################################################\n\nCleanCWD ()\n{\n\tmake clean >> cleanup.log 2>&1\n\trm -f src/*.log  >> cleanup.log 2>&1\n\trm -f *.log  >> cleanup.log 2>&1\n\trm -f *.o >> cleanup.log 2>&1\n\trm -f asustrx >> cleanup.log 2>&1\n\trm -f trx >> cleanup.log 2>&1\n\trm -f untrx >> cleanup.log 2>&1\n\trm -f addpattern >> cleanup.log 2>&1\n\trm -f mksquashfs >> cleanup.log 2>&1\n\trm -f mksquashfs-lzma >> cleanup.log 2>&1\n\trm -f unsquashfs >> cleanup.log 2>&1\n\trm -f unsquashfs-lzma >> cleanup.log 2>&1\n\t# cygwin\n\trm -f asustrx.exe >> cleanup.log 2>&1\n\trm -f trx.exe >> cleanup.log 2>&1\n\trm -f untrx.edxe >> cleanup.log 2>&1\n\trm -f addpattern.exe >> cleanup.log 2>&1\n\trm -f mksquashfs.exe >> cleanup.log 2>&1\n\trm -f mksquashfs-lzma.exe >> cleanup.log 2>&1\n\trm -f unsquashfs.exe >> cleanup.log 2>&1\n\trm -f unsquashfs-lzma.exe >> cleanup.log 2>&1\n\t# old name for untrx, deprecated\n\trm -f extfirmware* >> cleanup.log 2>&1\n\t# trx replaced with asustrx\n\trm -f trx.c >> cleanup.log 2>&1\n}\n\nCleanup ()\n{\n\tCleanCWD\n\tcd src\n\tCleanCWD\n\tcd ..\n}\n\n#################################################################\n# BuildTools ( LOG_FILE )\n#\n#\nBuildTools ()\n{\n\tlocal LOG_FILE=\"$1\"\n\t#################################################################\n\techo \" Building tools ...\"\n\t#make -C src > $LOG_FILE 2>&1\n\tcd src\n\t./configure && make > $LOG_FILE 2>&1\n\tcd -\n\n\tif [ $? = 0 ]; then\n\t\techo \" Build seems successful.\"\n\telse\n\t\techo \" ERROR - Build did not succeed. Check log file, you are probably\"\n\t\techo \"         missing one or more necessary pre-requisites. See docs for\"\n\t\techo \"         a list of pre-requsites.\"\n\t\tif [ -e \"src/untrx\" ]; then\n\t\t\techo \" CONTINUING anyway, attempting to use pre-built binaries (x32 linux)\"\t\n\t\telse\n\t\t\texit 1\n\t\tfi\n\tfi\n\t#################################################################\n\tlocal UNAME2=`uname`\n\tif [ `expr \"$UNAME2\" : \"CYGWIN\"` = 6 ]; then\n\t\tln -s -f \"src/asustrx.exe\" \"src/asustrx\" >> $LOG_FILE 2>&1\n\t\tln -s -f \"src/untrx.exe\" \"src/untrx\" >> $LOG_FILE 2>&1\n\t\tln -s -f \"src/addpattern.exe\" \"src/addpattern\" >> $LOG_FILE 2>&1\n\t\tln -s -f \"src/squashfs-3.0/mksquashfs-lzma.exe\" \"src/squashfs-3.0/mksquashfs-lzma\"  >> $LOG_FILE 2>&1\n\t\tln -s -f \"src/squashfs-3.0/unsquashfs-lzma.exe\" \"src/squashfs-3.0/unsquashfs-lzma\"  >> $LOG_FILE 2>&1\n\t\tln -s -f \"src/squashfs-3.0/mksquashfs.exe\" \"src/squashfs-3.0/mksquashfs\"  >> $LOG_FILE 2>&1\n\t\tln -s -f \"src/squashfs-3.0/unsquashfs.exe\" \"src/squashfs-3.0/unsquashfs\"  >> $LOG_FILE 2>&1\n\tfi\n\t#################################################################\n\t# cygwin: this can not be called before above block (no *. bins exist)\n\t#LinkToolsBinaries \"src\" \".\"\n}\n#################################################################\n# DeprecateOldVersion ()\n#\n# This is to automatically cleanup stuff that's been moved or removed\n#  since older versions. Aren't I nice?\n# \nDeprecateOldVersion ()\n{\n\t\techo \" Detected leftover stuff from an old version, cleaning\"\n\t\tmkdir \"src_backup\"  >> upgrade.log 2>&1\n\t\tmv \"*.c\" \"src_old_backup\"  >> upgrade.log 2>&1\n\t\tmv \"*.h\" \"src_old_backup\" >> upgrade.log 2>&1\n\t\tmv \"lzma\" \"src_old_backup\" >> upgrade.log 2>&1\n\t\tmv \"Makefile\" \"src_old_backup\" >> upgrade.log 2>&1\n\t\tmv src/cramfs-1.1 src_backup/  >> upgrade.log 2>&1\n\t\t# remove symbolic links from v0.43 and below\n\t\trm \"mksquashfs\" >> upgrade.log 2>&1\n\t\trm \"unsquashfs\" >> upgrade.log 2>&1\n\t\trm \"mksquashfs-lzma\" >> upgrade.log 2>&1\n\t\trm \"unsquashfs-lzma\" >> upgrade.log 2>&1\n\t\trm \"untrx\" >> upgrade.log 2>&1\n\t\trm \"asustrx\" >> upgrade.log 2>&1\n\t\trm \"addpattern\" >> upgrade.log 2>&1\n\t\t# remove old sources\n\t\tmv src/untrx.c src_old_backup >> upgrade.log 2>&1\n\t\tmv src/mksquashfs* src_old_backup >> upgrade.log 2>&1\n\t\tmv src/unsquashfs* src_old_backup >> upgrade.log 2>&1\n\t\tmv src/read_* src_old_backup >> upgrade.log 2>&1\n\t\tmv src/sort* src_old_backup >> upgrade.log 2>&1\n\t\tmv src/global.h src_old_backup >> upgrade.log 2>&1\n\t\tCleanup\t\t\t\n}\n\n\nTestIsRootAndExitIfNot()\n{\t\n\tif [ $(id -u) != \"0\" ]; then\n\t\techo \" ERROR: You must be 'root' when extracting and building some images.\"\n\t\techo \"        This is because some images need to create devices in your fs.\"\n\t\techo \"        For DD-WRT, do NOT extract or build as root, use standard user.\"\n\t\texit 1\n\tfi\n}\n\nTestIsRoot()\n{\t\n\tif [ $(id -u) != \"0\" ]; then\n\t\techo \" WARNING: You must be 'root' when extracting and building some images.\"\n\t\techo \"          This is because some images need to create devices in your fs.\"\n\t\techo \"          For DD-WRT, do NOT extract or build as root, use standard user.\"\n\tfi\n}\n"
  },
  {
    "path": "src/Makefile.in",
    "content": "CC := gcc\nCXX := g++\nINCLUDEDIR = .\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\n\nall: asustrx addpattern untrx motorola-bin splitter3 bffutils\n\tmake -C ./uncramfs/\n\tmake -C ./uncramfs-lzma/\n\tmake -C ./cramfs-2.x/\n\tmake -C ./cramfsswap/\n\tmake -C ./squashfs-2.1-r2/\n\tmake -C ./squashfs-3.0/\n\tmake -C ./squashfs-3.0-lzma-damn-small-variant/\n\tmake -C ./wrt_vx_imgtool/\n\tmake -C ./others/\n\tmake -C ./crcalc/\n\tmake -C ./webcomp-tools/\n\tmake -C ./firmware-tools/\n\naddpattern: addpattern.o\n\t$(CC) addpattern.o -o $@\n\nuntrx: untrx.o\n\t$(CXX) untrx.o -o $@\n\nsplitter3: splitter3.o\n\t$(CXX) splitter3.o -o $@\n\nasustrx: asustrx.o\n\t$(CC) asustrx.o -o $@\n\nmotorola-bin: motorola-bin.o\n\t$(CC) motorola-bin.o -o $@\n\nbffutils:\n\tmake -C ./bff/\n\nclean:\n\trm -f *.o\n\trm -f motorola-bin\n\trm -f untrx\n\trm -f asustrx\n\trm -f addpattern\n\trm -f splitter3\n\trm -f binwalk\n\tmake -C ./squashfs-2.1-r2/ clean\n\tmake -C ./squashfs-3.0 clean\n\tmake -C ./squashfs-3.0-lzma-damn-small-variant clean\n\tmake -C ./cramfs-2.x clean\n\tmake -C ./uncramfs clean\n\tmake -C ./uncramfs-lzma clean\n\tmake -C ./cramfsswap clean\n\tmake -C ./wrt_vx_imgtool clean\n\tmake -C ./others clean\n\tmake -C ./crcalc clean\n\tmake -C ./webcomp-tools clean\n\tmake -C ./binwalk*/src/ cleanall\n\tmake -C ./firmware-tools/ clean\n\tmake -C ./bff/ clean\n\ncleanall: clean\n\trm -rf Makefile config.* *.cache\n"
  },
  {
    "path": "src/addpattern.c",
    "content": "/*\n * Copyright (C) 2004  Manuel Novoa III  <mjn3@codepoet.org>\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n */\n\n/* July 29, 2004\n *\n * This is a hacked replacement for the 'addpattern' utility used to\n * create wrt54g .bin firmware files.  It isn't pretty, but it does\n * the job for me.\n *\n * Extensions:\n *  -v allows setting the version string on the command line.\n *  -{0|1} sets the (currently ignored) hw_ver flag in the header\n *      to 0 or 1 respectively.\n */\n\n/* January 12, 2005\n * \n * Modified by rodent at rodent dot za dot net\n * Support added for the new WRT54G v2.2 and WRT54GS v1.1 \"flags\"\n * Without the flags set to 0x7, the above units will refuse to flash.\n * \n * Extensions:\n *  -{0|1|2} sets {0|1} sets hw_ver flag to 0/1. {2} sets hw_ver to 1\n *     and adds the new hardware \"flags\" for the v2.2/v1.1 units\n*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n#include <unistd.h>\n#include <sys/stat.h>\n\n/**********************************************************************/\n\n#define CODE_ID\t\t\"U2ND\"\t\t/* from code_pattern.h */\n#define CODE_PATTERN   \"W54S\"\t/* from code_pattern.h */\n\n#define CYBERTAN_VERSION\t\"v3.37.2\" /* from cyutils.h */\n\n/* WRT54G v2.2 and WRT54GS v1.1 \"flags\" (from 3.37.32 firmware cyutils.h) */\n#define SUPPORT_4712_CHIP      0x0001\n#define SUPPORT_INTEL_FLASH    0x0002\n#define SUPPORT_5325E_SWITCH   0x0004\n\nstruct code_header {\t\t\t/* from cyutils.h */\n\tchar magic[4];\n\tchar res1[4];\t\t\t\t/* for extra magic */\n\tchar fwdate[3];\n\tchar fwvern[3];\n\tchar id[4];\t\t\t\t\t/* U2ND */\n\tchar hw_ver;    \t\t\t/* 0: for 4702, 1: for 4712 -- new in 2.04.3 */\n\tunsigned short flags;       /* SUPPORT_ flags new for 3.37.2 (WRT54G v2.2 and WRT54GS v1.1) */\n\tunsigned char res2[10];\n} ;\n\n/**********************************************************************/\n\nvoid usage(void) __attribute__ (( __noreturn__ ));\n\nvoid usage(void)\n{\n\tfprintf(stderr, \"Usage: addpattern [-i trxfile] [-o binfile] [-p pattern] [-g] [-v v#.#.#] [-{0|1|2|4}]\\n\");\n\texit(EXIT_FAILURE);\n}\n\nint main(int argc, char **argv)\n{\n\tchar buf[1024];\t/* keep this at 1k or adjust garbage calc below */\n\tstruct code_header *hdr;\n\tFILE *in = stdin;\n\tFILE *out = stdout;\n\tchar *ifn = NULL;\n\tchar *ofn = NULL;\n\tchar *pattern = CODE_PATTERN;\n\tchar *version = CYBERTAN_VERSION;\n\tint gflag = 0;\n\tint c;\n\tint v0, v1, v2;\n\tsize_t off, n;\n\ttime_t t;\n\tstruct tm *ptm;\n\n\tfprintf(stderr, \"mjn3's addpattern replacement - v0.81\\n\");\n\n\thdr = (struct code_header *) buf;\n\tmemset(hdr, 0, sizeof(struct code_header));\n\n\twhile ((c = getopt(argc, argv, \"i:o:p:gv:0124\")) != -1) {\n\t\tswitch (c) {\n\t\t\tcase 'i':\n\t\t\t\tifn = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'o':\n\t\t\t\tofn = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'p':\n\t\t\t\tpattern = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'g':\n\t\t\t\tgflag = 1;\n\t\t\t\tbreak;\n\t\t\tcase 'v':\t\t\t/* extension to allow setting version */\n\t\t\t\tversion = optarg;\n\t\t\t\tbreak;\n\t\t\tcase '0':\n\t\t\t\thdr->hw_ver = 0;\n\t\t\t\tbreak;\n\t\t\tcase '1':\n\t\t\t\thdr->hw_ver = 1;\n\t\t\t\tbreak;\n\t\t\tcase '2': \t\t\t/* new 54G v2.2 and 54GS v1.1 flags */\n\t\t\t\thdr->hw_ver = 1;\n\t\t\t\thdr->flags |= SUPPORT_4712_CHIP;\n\t\t\t\thdr->flags |= SUPPORT_INTEL_FLASH;\n\t\t\t\thdr->flags |= SUPPORT_5325E_SWITCH;\n\t\t\t\tbreak;\n\t\t\tcase '4':\n\t\t\t\t/* V4 firmware sets the flags to 0x1f */\n\t\t\t\thdr->hw_ver = 1;\n\t\t\t\thdr->flags = 0x1f;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tusage();\n\t\t}\n\t}\n\n\tif (optind != argc) {\n\t\tfprintf(stderr, \"illegal arg \\\"%s\\\"\\n\", argv[optind]);\n\t\tusage();\n\t}\n\n\tif (strlen(pattern) != 4) {\n\t\tfprintf(stderr, \"illegal pattern \\\"%s\\\": length != 4\\n\", pattern);\n\t\tusage();\n\t}\n\n\tif (ifn && !(in = fopen(ifn, \"r\"))) {\n\t\tfprintf(stderr, \"can not open \\\"%s\\\" for reading\\n\", ifn);\n\t\tusage();\n\t}\n\n\tif (ofn && !(out = fopen(ofn, \"w\"))) {\n\t\tfprintf(stderr, \"can not open \\\"%s\\\" for writing\\n\", ofn);\n\t\tusage();\n\t}\n\n\tif (time(&t) == (time_t)(-1)) {\n\t\tfprintf(stderr, \"time call failed\\n\");\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tptm = localtime(&t);\n\n\tif (3 != sscanf(version, \"v%d.%d.%d\", &v0, &v1, &v2)) {\n\t\tfprintf(stderr, \"bad version string \\\"%s\\\"\\n\", version);\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tmemcpy(&hdr->magic, pattern, 4);\n\thdr->fwdate[0] = ptm->tm_year % 100;\n\thdr->fwdate[1] = ptm->tm_mon + 1;\n\thdr->fwdate[2] = ptm->tm_mday;\n\thdr->fwvern[0] = v0;\n\thdr->fwvern[1] = v1;\n\thdr->fwvern[2] = v2;\n\tmemcpy(&hdr->id, CODE_ID, strlen(CODE_ID));\n\n\toff = sizeof(struct code_header);\n\n\tfprintf(stderr, \"writing firmware v%d.%d.%d on %d/%d/%d (y/m/d)\\n\",\n\t\t\tv0, v1, v2,\n\t\t\thdr->fwdate[0], hdr->fwdate[1], hdr->fwdate[2]);\n\n\n\twhile ((n = fread(buf + off, 1, sizeof(buf)-off, in) + off) > 0) {\n\t\toff = 0;\n\t\tif (n < sizeof(buf)) {\n\t\t\tif (ferror(in)) {\n\t\t\tFREAD_ERROR:\n\t\t\t\tfprintf(stderr, \"fread error\\n\");\n\t\t\t\treturn EXIT_FAILURE;\n\t\t\t}\n\t\t\tif (gflag) {\n\t\t\t\tgflag = sizeof(buf) - n;\n\t\t\t\tmemset(buf + n, 0xff, gflag);\n\t\t\t\tfprintf(stderr, \"adding %d bytes of garbage\\n\", gflag);\n\t\t\t\tn = sizeof(buf);\n\t\t\t}\n\t\t}\n\t\tif (!fwrite(buf, n, 1, out)) {\n\t\tFWRITE_ERROR:\n\t\t\tfprintf(stderr, \"fwrite error\\n\");\n\t\t\treturn EXIT_FAILURE;\n\t\t}\n\t}\n\t\n\tif (ferror(in)) {\n\t\tgoto FREAD_ERROR;\n\t}\n\n\tif (fflush(out)) {\n\t\tgoto FWRITE_ERROR;\n\t}\n\n\tfclose(in);\n\tfclose(out);\n\n\treturn EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/asustrx.c",
    "content": "/*\n * Copyright (C) 2004  Manuel Novoa III  <mjn3@codepoet.org>\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n */\n\n/* July 29, 2004\n *\n * This is a hacked replacement for the 'trx' utility used to create\n * wrt54g .trx firmware files.  It isn't pretty, but it does the job\n * for me.\n *\n * As an extension, you can specify a larger maximum length for the\n * .trx file using '-m'.  It will be rounded up to be a multiple of 4K.\n * NOTE: This space will be malloc()'d.\n *\n * August 16, 2004\n *\n * Sigh... Make it endian-neutral.\n *\n * TODO: Support '-b' option to specify offsets for each file.\n */\n\n/* March 04, 2005\n *\n * Copyright(c) 2005 Konstantin A. Klubnichkin and Oleg I. Vdovikin\n *\n * Added ASUS addver functionality, which is binary only\n *\n * addver is no longer needed, use utility like this\n *\n * asustrx -p WL500g -v 1.9.2.7 -o image.trx file [ file [ file ] ]  \n */\n \n /* September 22, 2006\n *\n * Copyright(c) 2006 Jeremy Collake <jeremy.collake@gmail.com>\n *\n * Added -b switch to force a segment start offset, padding up \n * to that point. This switch should immediately preceed filenames.\n *\n * Example of ASUS calls to their trx (addver called sperately):\n *\n *   trx -o WL530g_$(KVER).$(FVER)_$(LANGUAGE).bin -b 32 zImage -b 655360 target.cramfs\n * \n *\n * Also several other misc. changes where I saw appropriate.\n * \n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stddef.h>\n#include <stdint.h>\n#include <string.h>\n#include <errno.h>\n#include <unistd.h>\n#include <endian.h>\n#include <byteswap.h>\n#include <sys/types.h>\n\n// always flip, regardless of endianness of machine\nu_int32_t flip_endian(u_int32_t nValue)\n{\n\t// my crappy endian switch\n\tu_int32_t nR;\n\tu_int32_t nByte1=(nValue&0xff000000)>>24;\n\tu_int32_t nByte2=(nValue&0x00ff0000)>>16;\n\tu_int32_t nByte3=(nValue&0x0000ff00)>>8;\n\tu_int32_t nByte4=nValue&0x0ff;\n\tnR=nByte4<<24;\n\tnR|=(nByte3<<16);\n\tnR|=(nByte2<<8);\n\tnR|=nByte1;\n\treturn nR;\n}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define STORE32_LE(X)\t\tbswap_32(X)\n#define READ32_LE(X)\t\tbswap_32(X)\n#elif __BYTE_ORDER == __LITTLE_ENDIAN\n#define STORE32_LE(X)\t\t(X)\n#define READ32_LE(X)\t\t(X)\n#else\n#error unkown endianness!\n#endif\n/*jc end */\n\nuint32_t crc32buf(char *buf, size_t len);\n\n/**********************************************************************/\n/* from trxhdr.h */\n\n#define TRX_MAGIC\t0x30524448\t/* \"HDR0\" */\n#define TRX_VERSION\t1\n#define TRX_MAX_LEN\t0x9A0000    /* jc: change from 0x3A0000 */\n#define TRX_NO_HEADER\t1\t\t/* Do not write TRX header */\t\n\nstruct trx_header {\n\tuint32_t magic;\t\t\t/* \"HDR0\" */\n\tuint32_t len;\t\t\t/* Length of file including header */\n\tuint32_t crc32;\t\t\t/* 32-bit CRC from flag_version to end of file */\n\tuint32_t flag_version;\t/* 0:15 flags, 16:31 version */\n\tuint32_t offsets[3];\t/* Offsets of partitions from start of header */\n};\n\n/**********************************************************************/\n\nvoid usage(void) __attribute__ (( __noreturn__ ));\n\nvoid usage(void)\n{\n\tfprintf(stderr, \"Use: trx [-p prodid] [-v ver] [-o ofile] [-m maxlen] [-b offs] file [-b offs] [file [file]]\\n\");\n\texit(EXIT_FAILURE);\n}\n\nint main(int argc, char **argv)\n{\n\tFILE *out = stdout;\n\tFILE *in;\n\tchar *ofn = NULL;\n\tchar *buf;\n\tchar *e;\n\tint c, i;\n\tsize_t n;\n\tuint32_t cur_len;\t\n\tint boolSegmentSizesGiven=0; /* jc */\n\tint nSegementCount=0;\n\tunsigned long maxlen = TRX_MAX_LEN;\n\tstruct trx_header *p;\n\tstruct trx_header trxtemp;\n\tmemset(&trxtemp,0,sizeof(struct trx_header));\n\t\n\tstruct {\n\t\tuint8_t version[4];\t/* Firmware version */\n\t\tuint8_t prod_id[12];\t/* Product Id */\n\t\tuint8_t comp_hw[4][4];\t/* Compatible hw list maj-min min/maj-min max */\n\t\tuint8_t\tpad[32];\t/* Padding */\n\t} asus = {\n\t\t.prod_id    = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* jc: initialize .prod_id */\n\t\t.version \t= { 1, 9, 2, 7 }, /* version is set to 1.9.2.7 by default */\n\t\t.comp_hw[0]\t= { 0, 2, 2, 99 } /* hardcoded hw compat list 0.02 - 2.99 */\n\t};\n\n\tfprintf(stderr, \"mjn3's trx replacement - v0.90, modified to pack ASUS compatible trx\\n\");\n\t\n\twhile ((c = getopt(argc, argv, \"b:o:m:p:v:\")) != -1) {\n\t\tswitch (c) {\n\t\t\t/* jc */\n\t\t\tcase 'b':\t\t\t\n\t\t\t\tboolSegmentSizesGiven=1;\t\t\t \t\t\t\n\t\t\t\ttrxtemp.offsets[nSegementCount++]=STORE32_LE(strtoul(optarg, &e, 0));\n\t\t\t\tif ((e == optarg) || *e) \n\t\t\t\t{\n\t\t\t\t\tfprintf(stderr, \"illegal numeric string\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\t\t\t\n\t\t\t\tbreak;\n\t\t\t/* jc end */\t\t\t\n\t\t\tcase 'o':\n\t\t\t\tofn = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'm':\n\t\t\t\terrno = 0;\n\t\t\t\tmaxlen = strtoul(optarg, &e, 0);\n\t\t\t\tif (errno || (e == optarg) || *e) {\n\t\t\t\t\tfprintf(stderr, \"illegal numeric string\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\n#undef  ROUND\n#define ROUND 0x1000\n\t\t\t\tif (maxlen & (ROUND-1)) {\n\t\t\t\t\tmaxlen += (ROUND - (maxlen & (ROUND-1)));\n\t\t\t\t}\n\t\t\t\tif (maxlen < ROUND) {\n\t\t\t\t\tfprintf(stderr, \"maxlen too small (or wrapped)\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'p':\n\t\t\t\tif ((n = strlen(optarg)) > sizeof(asus.prod_id)) {\n\t\t\t\t\tfprintf(stderr, \"product id too long\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\n\t\t\t\tmemset(asus.prod_id, ' ', sizeof(asus.prod_id));\n\t\t\t\tmemcpy(asus.prod_id, optarg, n);\n\t\t\t\tbreak;\n\t\t\tcase 'v':\n\t\t\t\tfor (n = 0; n < sizeof(asus.version) / sizeof(asus.version[0]); n++)\n\t\t\t\t{\n\t\t\t\t\tif (n != 0 && optarg[0] == '.' && optarg[1]) optarg++;\n\t\t\t\t\telse if (n != 0) break;\n\t\t\t\t\t\n\t\t\t\t\tasus.version[n] = strtoul(optarg, &optarg, 10);\n\t\t\t\t}\n\t\t\t\tif (*optarg) \n\t\t\t\t{\n\t\t\t\t\tfprintf(stderr, \"invalid version string\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tusage();\n\t\t}\n\t}\n\n\tif (ofn && !(out = fopen(ofn, \"w\"))) \n\t{\n\t\tfprintf(stderr, \"can not open \\\"%s\\\" for writing\\n\", ofn);\n\t\tusage();\n\t}\n\n\tif (optind == argc) \n\t{\n\t\tfprintf(stderr, \"we require at least one arg\\n\");\n\t\tusage();\n\t}\n\n\tif (argc - optind > 3) \n\t{\n\t\tfprintf(stderr, \"too many args: %d > 3\\n\", argc - optind);\n\t\tusage();\n\t}\n\n\tif (maxlen > TRX_MAX_LEN) \t\n\t{\n\t\tfprintf(stderr, \"WARNING: maxlen exceeds default maximum!  Beware of overwriting nvram!\\n\");\n\t}\n\n\tif (!(buf = malloc(maxlen))) \n\t{\n\t\tfprintf(stderr, \"malloc failed\\n\");\n\t\treturn EXIT_FAILURE;\n\t}\n\tmemset(buf,0,maxlen); /* jc */\n\n\tp = (struct trx_header *) buf;\n\tmemcpy(p,&trxtemp,sizeof(struct trx_header)); /* jc */\n\tp->magic = STORE32_LE(TRX_MAGIC);\n\tcur_len = sizeof(struct trx_header);\n\tp->flag_version = STORE32_LE((TRX_VERSION << 16));\n\n\ti = 0;\n\n\twhile (optind < argc) {\t\t\n\t\t/* jc */\n\t\tif(!READ32_LE(p->offsets[i])) \n\t\t{\t\t\t\n\t\t\tp->offsets[i] = STORE32_LE(cur_len);\n\t\t}\n\t\telse\n\t\t{\t\t\t\n\t\t\tif(cur_len>READ32_LE(p->offsets[i]))\n\t\t\t{\n\t\t\t\tfprintf(stderr, \"offset too large\\n\");\n\t\t\t\treturn EXIT_FAILURE;\t\t\t\n\t\t\t}\n\t\t\tcur_len=READ32_LE(p->offsets[i]);\n\t\t}\n\t\t/* jc end */\n\n\t\tif (!(in = fopen(argv[optind], \"r\"))) {\n\t\t\tfprintf(stderr, \"can not open \\\"%s\\\" for reading\\n\", argv[optind]);\n\t\t\tusage();\n\t\t}\t\t\t\n\n\t\tn = fread(buf + cur_len, 1, maxlen - cur_len, in);\n\t\tif (!feof(in)) {\n\t\t\tfprintf(stderr, \"fread failure or file \\\"%s\\\" too large cur:%d max: %d\\n\",\n\t\t\t\t\targv[optind], cur_len, maxlen);\n\t\t\tfclose(in);\n\t\t\treturn EXIT_FAILURE;\n\t\t}\n\n\t\tfclose(in);\n\t\t\n\t\t++optind;\n\n\t\tif (optind < argc) {\n#undef  ROUND\n#define ROUND 4\n\t\t\tif (n & (ROUND-1)) {\n\t\t\t\tmemset(buf + cur_len + n, 0, ROUND - (n & (ROUND-1)));\n\t\t\t\tn += ROUND - (n & (ROUND-1));\n\t\t\t}\n\t\t}\n\n\t\tcur_len += n;\n\t\ti++;\n\t}\n\t\n\t/* reserve space for asus footer */\n\tif (asus.prod_id[0]) {\n\t\tcur_len += sizeof(asus);\n\t}\n\n#undef  ROUND\n#define ROUND 0x1000\n\tn = cur_len & (ROUND-1);\n\tif (n) {\n\t\tmemset(buf + cur_len, 0, ROUND - n);\n\t\tcur_len += ROUND - n;\n\t}\n\n\t/* add asus footer */\n\tif (asus.prod_id[0]) {\n\t\tmemcpy(buf + cur_len - sizeof(asus), &asus, sizeof(asus));\n\t}\n\t\n\tp->crc32 = crc32buf((char *) &p->flag_version,\n\t\t\t\t\t\tcur_len - offsetof(struct trx_header, flag_version));\n\tp->crc32 = STORE32_LE(p->crc32);\n\n\tp->len = STORE32_LE(cur_len);\n\n\tif (!fwrite(buf, cur_len, 1, out) || fflush(out)) {\n\t\tfprintf(stderr, \"fwrite failed\\n\");\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tfclose(out);\n\n\treturn EXIT_SUCCESS;\n}\n\n/**********************************************************************/\n/* The following was grabbed and tweaked from the old snippets collection\n * of public domain C code. */\n\n/**********************************************************************\\\n|* Demonstration program to compute the 32-bit CRC used as the frame  *|\n|* check sequence in ADCCP (ANSI X3.66, also known as FIPS PUB 71     *|\n|* and FED-STD-1003, the U.S. versions of CCITT's X.25 link-level     *|\n|* protocol).  The 32-bit FCS was added via the Federal Register,     *|\n|* 1 June 1982, p.23798.  I presume but don't know for certain that   *|\n|* this polynomial is or will be included in CCITT V.41, which        *|\n|* defines the 16-bit CRC (often called CRC-CCITT) polynomial.  FIPS  *|\n|* PUB 78 says that the 32-bit FCS reduces otherwise undetected       *|\n|* errors by a factor of 10^-5 over 16-bit FCS.                       *|\n\\**********************************************************************/\n\n/* Copyright (C) 1986 Gary S. Brown.  You may use this program, or\n   code or tables extracted from it, as desired without restriction.*/\n\n/* First, the polynomial itself and its table of feedback terms.  The  */\n/* polynomial is                                                       */\n/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */\n/* Note that we take it \"backwards\" and put the highest-order term in  */\n/* the lowest-order bit.  The X^32 term is \"implied\"; the LSB is the   */\n/* X^31 term, etc.  The X^0 term (usually shown as \"+1\") results in    */\n/* the MSB being 1.                                                    */\n\n/* Note that the usual hardware shift register implementation, which   */\n/* is what we're using (we're merely optimizing it by doing eight-bit  */\n/* chunks at a time) shifts bits into the lowest-order term.  In our   */\n/* implementation, that means shifting towards the right.  Why do we   */\n/* do it this way?  Because the calculated CRC must be transmitted in  */\n/* order from highest-order term to lowest-order term.  UARTs transmit */\n/* characters in order from LSB to MSB.  By storing the CRC this way,  */\n/* we hand it to the UART in the order low-byte to high-byte; the UART */\n/* sends each low-bit to hight-bit; and the result is transmission bit */\n/* by bit from highest- to lowest-order term without requiring any bit */\n/* shuffling on our part.  Reception works similarly.                  */\n\n/* The feedback terms table consists of 256, 32-bit entries.  Notes:   */\n/*                                                                     */\n/*  1. The table can be generated at runtime if desired; code to do so */\n/*     is shown later.  It might not be obvious, but the feedback      */\n/*     terms simply represent the results of eight shift/xor opera-    */\n/*     tions for all combinations of data and CRC register values.     */\n/*                                                                     */\n/*  2. The CRC accumulation logic is the same for all CRC polynomials, */\n/*     be they sixteen or thirty-two bits wide.  You simply choose the */\n/*     appropriate table.  Alternatively, because the table can be     */\n/*     generated at runtime, you can start by generating the table for */\n/*     the polynomial in question and use exactly the same \"updcrc\",   */\n/*     if your application needn't simultaneously handle two CRC       */\n/*     polynomials.  (Note, however, that XMODEM is strange.)          */\n/*                                                                     */\n/*  3. For 16-bit CRCs, the table entries need be only 16 bits wide;   */\n/*     of course, 32-bit entries work OK if the high 16 bits are zero. */\n/*                                                                     */\n/*  4. The values must be right-shifted by eight bits by the \"updcrc\"  */\n/*     logic; the shift must be unsigned (bring in zeroes).  On some   */\n/*     hardware you could probably optimize the shift in assembler by  */\n/*     using byte-swap instructions.                                   */\n\nstatic const uint32_t crc_32_tab[] = { /* CRC polynomial 0xedb88320 */\n0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,\n0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,\n0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,\n0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,\n0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,\n0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,\n0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,\n0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,\n0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,\n0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,\n0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,\n0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,\n0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,\n0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,\n0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,\n0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,\n0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\n0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d\n};\n\n#define UPDC32(octet,crc) (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8))\n\nuint32_t crc32buf(char *buf, size_t len)\n{\n      uint32_t crc;\n\n      crc = 0xFFFFFFFF;\n\n      for ( ; len; --len, ++buf)\n      {\n            crc = UPDC32(*buf, crc);\n      }\n\n      return crc;\n}\n"
  },
  {
    "path": "src/bff/Makefile",
    "content": "all:\n\tgcc bff_huffman_decompress.c -o bff_huffman_decompress\n\nclean:\n\trm -f bff_huffman_decompress\n\ndistclean: clean\n"
  },
  {
    "path": "src/bff/bff_huffman_decompress.c",
    "content": "/*-\n * Copyright (c) 2009 Xin LI <delphij@FreeBSD.org>\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n *    notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n *    notice, this list of conditions and the following disclaimer in the\n *    documentation and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n */\n\n// compile it using: gcc bff_huffman_decompress.c -o bff_huffman_decompress\n// use it as: ./bff_huffman_decompress sampleBff_file0 sampleBff_file0_parsed \n\n/*\n * pack(1) file format:\n *\n * The first byte is the header:\n *\t    00 - Level for the huffman tree (<=24)\n *\n * pack(1) will then store symbols (leaf) nodes count in each huffman\n * tree levels, each level would consume 1 byte (See [1]).\n *\n * After the symbol count table, there is the symbol table, storing\n * symbols represented by corresponding leaf node.  EOB is not being\n * explicitly transmitted (not necessary anyway) in the symbol table.\n *\n * Compressed data goes after the symbol table.\n *\n * NOTES\n *\n * [1] If we count EOB into the symbols, that would mean that we will\n * have at most 256 symbols in the huffman tree.  pack(1) rejects empty\n * file and files that just repeats one character, which means that we\n * will have at least 2 symbols.  Therefore, pack(1) would reduce the\n * last level symbol count by 2 which makes it a number in\n * range [0..254], so all levels' symbol count would fit into 1 byte.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#define\tPACK_HEADER_LENGTH\t1\n#define\tHTREE_MAXLEVEL\t\t24\n\n/*\n * unpack descriptor\n *\n * Represent the huffman tree in a similar way that pack(1) would\n * store in a packed file.  We store all symbols in a linear table,\n * and store pointers to each level's first symbol.  In addition to\n * that, maintain two counts for each level: inner nodes count and\n * leaf nodes count.\n */\ntypedef struct {\n\tint\t\tsymbol_size;\t/* Size of the symbol table */\n\tint\t\ttreelevels;\t/* Levels for the huffman tree */\n\n\tint\t\t*symbolsin;\t/* Table of leaf symbols count in\n\t\t\t\t\t   each level */\n\tint\t\t*inodesin;\t/* Table of internal nodes count in\n\t\t\t\t\t   each level */\n\n\tchar\t\t*symbol;\t/* The symbol table */\n\tchar\t\t*symbol_eob;\t/* Pointer to the EOB symbol */\n\tchar\t\t**tree;\t\t/* Decoding huffman tree (pointers to\n\t\t\t\t\t   first symbol of each tree level */\n\n\toff_t\t\tuncompressed_size; /* Uncompressed size */\n\tFILE\t\t*fpIn;\t\t/* Input stream */\n\tFILE\t\t*fpOut;\t\t/* Output stream */\n} unpack_descriptor_t;\n\nint maybe_err(char*fmt,...) {\n\n}\nint maybe_errx(char*fmt,...) {\n\n}\n\n/*\n * Release resource allocated to an unpack descriptor.\n *\n * Caller is responsible to make sure that all of these pointers are\n * initialized (in our case, they all point to valid memory block).\n * We don't zero out pointers here because nobody else would ever\n * reference the memory block without scrubbing them.\n */\nstatic void\nunpack_descriptor_fini(unpack_descriptor_t *unpackd)\n{\n\n\tfree(unpackd->symbolsin);\n\tfree(unpackd->inodesin);\n\tfree(unpackd->symbol);\n\tfree(unpackd->tree);\n\n\tfclose(unpackd->fpIn);\n\tfclose(unpackd->fpOut);\n}\n\n/*\n * Recursively fill the internal node count table\n */\nstatic void\nunpackd_fill_inodesin(const unpack_descriptor_t *unpackd, int level)\n{\n\n\t/*\n\t * The internal nodes would be 1/2 of total internal nodes and\n\t * leaf nodes in the next level.  For the last level there\n\t * would be no internal node by definition.\n\t */\n\tif (level < unpackd->treelevels) {\n\t\tunpackd_fill_inodesin(unpackd, level + 1);\n\t\tunpackd->inodesin[level] = (unpackd->inodesin[level + 1] +\n\t\t\t\t\t  unpackd->symbolsin[level + 1]) / 2;\n\t} else\n\t\tunpackd->inodesin[level] = 0;\n}\n\n/*\n * Update counter for accepted bytes\n */\nstatic void\naccepted_bytes(off_t *bytes_in, off_t newbytes)\n{\n\n\tif (bytes_in != NULL)\n\t\t(*bytes_in) += newbytes;\n}\n\n/*\n * Read file header and construct the tree.  Also, prepare the buffered I/O\n * for decode routine.\n *\n * Return value is uncompressed size.\n */\nstatic void\nunpack_parse_header(int in, int out, char *pre, size_t prelen, off_t *bytes_in,\n    unpack_descriptor_t *unpackd)\n{\n\tunsigned char hdr[PACK_HEADER_LENGTH];\t/* buffer for header */\n\tssize_t bytesread;\t\t/* Bytes read from the file */\n\tint i, j, thisbyte;\n\n\t/* Prepend the header buffer if we already read some data */\n\tif (prelen != 0)\n\t\tmemcpy(hdr, pre, prelen);\n\n\t/* Read in and fill the rest bytes of header */\n\tbytesread = read(in, hdr + prelen, PACK_HEADER_LENGTH - prelen);\n\tif (bytesread < 0)\n\t\tmaybe_err(\"Error reading pack header\");\n\n\taccepted_bytes(bytes_in, PACK_HEADER_LENGTH);\n\n\t/* Reset uncompressed size */\n\tunpackd->uncompressed_size = 0;\n\n\t/* Get the levels of the tree */\n\tunpackd->treelevels = hdr[0];\n\tif (unpackd->treelevels > HTREE_MAXLEVEL || unpackd->treelevels < 1)\n\t\tmaybe_errx(\"Huffman tree has insane levels\");\n\n\t/* Let libc take care for buffering from now on */\n\tif ((unpackd->fpIn = fdopen(in, \"r\")) == NULL)\n\t\tmaybe_err(\"Can not fdopen() input stream\");\n\tif ((unpackd->fpOut = fdopen(out, \"w\")) == NULL)\n\t\tmaybe_err(\"Can not fdopen() output stream\");\n\n\t/* Allocate for the tables of bounds and the tree itself */\n\tunpackd->inodesin =\n\t    calloc(unpackd->treelevels, sizeof(*(unpackd->inodesin)));\n\tunpackd->symbolsin =\n\t    calloc(unpackd->treelevels, sizeof(*(unpackd->symbolsin)));\n\tunpackd->tree =\n\t    calloc(unpackd->treelevels, (sizeof (*(unpackd->tree))));\n\tif (unpackd->inodesin == NULL || unpackd->symbolsin == NULL ||\n\t    unpackd->tree == NULL)\n\t\tmaybe_err(\"calloc\");\n\n\t/* We count from 0 so adjust to match array upper bound */\n\tunpackd->treelevels--;\n\n\t/* Read the levels symbol count table and calculate total */\n\tunpackd->symbol_size = 1;\t\t/* EOB */\n\tfor (i = 0; i <= unpackd->treelevels; i++) {\n\t\tif ((thisbyte = fgetc(unpackd->fpIn)) == EOF)\n\t\t\tmaybe_err(\"File appears to be truncated\");\n\t\tunpackd->symbolsin[i] = (unsigned char)thisbyte;\n\t\tunpackd->symbol_size += unpackd->symbolsin[i];\n\t}\n\taccepted_bytes(bytes_in, unpackd->treelevels);\n\tif (unpackd->symbol_size > 256)\n\t\tmaybe_errx(\"Bad symbol table\");\n\n\t/* Allocate for the symbol table, point symbol_eob at the beginning */\n\tunpackd->symbol_eob = unpackd->symbol = calloc(1, unpackd->symbol_size);\n\tif (unpackd->symbol == NULL)\n\t\tmaybe_err(\"calloc\");\n\n\t/*\n\t * Read in the symbol table, which contain [2, 256] symbols.\n\t * In order to fit the count in one byte, pack(1) would offset\n\t * it by reducing 2 from the actual number from the last level.\n\t *\n\t * We adjust the last level's symbol count by 1 here, because\n\t * the EOB symbol is not being transmitted explicitly.  Another\n\t * adjustment would be done later afterward.\n\t */\n\tunpackd->symbolsin[unpackd->treelevels]++;\n\tfor (i = 0; i <= unpackd->treelevels; i++) {\n\t\tunpackd->tree[i] = unpackd->symbol_eob;\n\t\tfor (j = 0; j < unpackd->symbolsin[i]; j++) {\n\t\t\tif ((thisbyte = fgetc(unpackd->fpIn)) == EOF)\n\t\t\t\tmaybe_errx(\"Symbol table truncated\");\n\t\t\t*unpackd->symbol_eob++ = (char)thisbyte;\n\t\t}\n\t\taccepted_bytes(bytes_in, unpackd->symbolsin[i]);\n\t}\n\n\t/* Now, take account for the EOB symbol as well */\n\tunpackd->symbolsin[unpackd->treelevels]++;\n\n\t/*\n\t * The symbolsin table has been constructed now.\n\t * Calculate the internal nodes count table based on it.\n\t */\n\tunpackd_fill_inodesin(unpackd, 0);\n}\n\n/*\n * Decode huffman stream, based on the huffman tree.\n */\nstatic void\nunpack_decode(unpack_descriptor_t *unpackd, off_t *bytes_in)\n{\n\tint thislevel, thiscode, thisbyte, inlevelindex;\n\tint i;\n\toff_t bytes_out = 0;\n\tconst char *thissymbol;\t/* The symbol pointer decoded from stream */\n\n\t/*\n\t * Decode huffman.  Fetch every bytes from the file, get it\n\t * into 'thiscode' bit-by-bit, then output the symbol we got\n\t * when one has been found.\n\t *\n\t * Assumption: sizeof(int) > ((max tree levels + 1) / 8).\n\t * bad things could happen if not.\n\t */\n\tthislevel = 0;\n\tthiscode = thisbyte = 0;\n\n\twhile ((thisbyte = fgetc(unpackd->fpIn)) != EOF) {\n\t\taccepted_bytes(bytes_in, 1);\n\n\t\t/*\n\t\t * Split one bit from thisbyte, from highest to lowest,\n\t\t * feed the bit into thiscode, until we got a symbol from\n\t\t * the tree.\n\t\t */\n\t\tfor (i = 7; i >= 0; i--) {\n\t\t\tthiscode = (thiscode << 1) | ((thisbyte >> i) & 1);\n\n\t\t\t/* Did we got a symbol? (referencing leaf node) */\n\t\t\tif (thiscode >= unpackd->inodesin[thislevel]) {\n\t\t\t\tinlevelindex =\n\t\t\t\t    thiscode - unpackd->inodesin[thislevel];\n\t\t\t\tif (inlevelindex > unpackd->symbolsin[thislevel])\n\t\t\t\t\tmaybe_errx(\"File corrupt\");\n\n\t\t\t\tthissymbol =\n\t\t\t\t    &(unpackd->tree[thislevel][inlevelindex]);\n\t\t\t\tif (thissymbol == unpackd->symbol_eob)\n\t\t\t\t\tgoto finished;\n\n\t\t\t\tfputc((*thissymbol), unpackd->fpOut);\n\t\t\t\tbytes_out++;\n\n\t\t\t\t/* Prepare for next input */\n\t\t\t\tthislevel = 0; thiscode = 0;\n\t\t\t} else {\n\t\t\t\tthislevel++;\n\t\t\t\tif (thislevel > unpackd->treelevels)\n\t\t\t\t\tmaybe_errx(\"File corrupt\");\n\t\t\t}\n\t\t}\n\t}\n\nfinished:\n\tif (bytes_out != unpackd->uncompressed_size)\n\t\tmaybe_errx(\"Premature EOF\");\n    unpackd->uncompressed_size=bytes_out;  // hack\n}\n\n/* Handler for pack(1)'ed file */\nstatic off_t\nunpack(int in, int out, char *pre, size_t prelen, off_t *bytes_in)\n{\n\tunpack_descriptor_t\tunpackd;\n\n\tunpack_parse_header(dup(in), dup(out), pre, prelen, bytes_in, &unpackd);\n\tunpack_decode(&unpackd, bytes_in);\n\tunpack_descriptor_fini(&unpackd);\n\n\t/* If we reached here, the unpack was successful */\n\treturn (unpackd.uncompressed_size);\n}\nvoid\nusage() {\n    printf(\"Usage:\\n    ./bff_huffman_decompress INFILE OUTFILE\\n\");\n}\nint\nmain(int argc,char**argv) {\n    if (argc<3) {\n        fprintf(stderr,\"[!] Please specify the input and output file as command line arguments\\n\");\n        usage();\n        return 1;\n    }\n    FILE*in=fopen(argv[1],\"r\");\n    if (!in) {\n        fprintf(stderr,\"[-] Could *not* open input file\\n\");\n        return 1;\n    }\n    int in_fd=fileno(in);\n    FILE*out=fopen(argv[2],\"w\");\n    if (!out) {\n        fprintf(stderr,\"[-] Could *not* open output file\\n\");\n        return 1;\n    }\n    int out_fd=fileno(out);\n    off_t uncompressed_size=unpack(in_fd,out_fd,0,0,0);\n    if (uncompressed_size>0) {\n        printf(\"[+] File was successfully decompressed, decompressed size is %lu (%luKB)\\n\",\n            uncompressed_size,uncompressed_size/1024);\n        return 0;\n    } else {\n        fprintf(stderr,\"[-] Decompression of the file *not* succeeded. FAILED!\\n\");\n        return 1;\n    }\n    return 0;\n}\n\n"
  },
  {
    "path": "src/bff/bffxtractor.py",
    "content": "#!/usr/bin/env python\n# A hacky extraction utility for extracting the contents of BFF volume entries.\n# It can't parse a BFF file itself, but expects the BFF volume entry to already \n# be extracted to a file; it then extracts the original file from the volume entry \n# file. Thus, it is best used with binwalk.\n\nimport os\nimport sys\nimport struct \nimport subprocess\n\n## {{{ http://code.activestate.com/recipes/82465/ (r4)\ndef _mkdir(newdir):\n    \"\"\"works the way a good mkdir should :)\n        - already exists, silently complete\n        - regular file in the way, raise an exception\n        - parent directory(ies) does not exist, make them as well\n    \"\"\"\n    if os.path.isdir(newdir):\n        pass\n    elif os.path.isfile(newdir):\n        raise OSError(\"a file with the same name as the desired \" \\\n                      \"dir, '%s', already exists.\" % newdir)\n    else:\n        head, tail = os.path.split(newdir)\n        if head and not os.path.isdir(head):\n            _mkdir(head)\n        #print \"_mkdir %s\" % repr(newdir)\n        if tail:\n            os.mkdir(newdir)\n## end of http://code.activestate.com/recipes/82465/ }}}\n\nHUFFMAN_MAGIC = 0xEA6C\nMAGICS = [0xEA6B, HUFFMAN_MAGIC, 0xEA6D]\nHEADER_SIZE = 64\nPOST_HEADER_SIZE = 40\n\nscript_path = os.path.dirname(os.path.realpath(__file__))\n\ntry:\n\tfd = open(sys.argv[1], 'rb')\nexcept:\n\tprint \"Usage: %s <BFF volume entry file>\" % sys.argv[0]\n\tsys.exit(1)\n\nheader = fd.read(HEADER_SIZE)\n\nmagic = struct.unpack(\"<H\", header[2:4])[0]\nfile_size = struct.unpack(\"<L\", header[56:60])[0]\n\nif magic not in MAGICS:\n\tprint \"Unrecognized magic bytes! Quitting.\"\n\tsys.exit(1)\n\nfilename = ''\nwhile True:\n\tbyte = fd.read(1)\n\tif not byte or byte == '\\x00':\n\t\tbreak\n\telse:\n\t\tfilename += byte\n\nfilename_len = len(filename)\noffset = HEADER_SIZE + POST_HEADER_SIZE + filename_len + (8 - (filename_len % 8))\n\nif '..' in filename:\n\tprint \"Dangerous file path '%s'! Quitting.\" % filename\n\tsys.exit(1)\n\nprint \"Extracting '%s'\" % filename\n_mkdir('./' + os.path.dirname(filename))\nif file_size:\n\tfd.seek(offset)\n\tfile_data = fd.read(file_size)\n\tfd.close()\n\n\tif len(file_data) != file_size:\n\t\tprint \"Warning: EOF encountered before the expected file size was reached!\"\n\n\tif magic == HUFFMAN_MAGIC:\n\t\tfpout = open(filename + '.packed', 'wb')\n\telse:\n\t\tfpout = open(filename, 'wb')\n\tfpout.write(file_data)\n\tfpout.close()\n\n\tif magic == HUFFMAN_MAGIC:\n\t\ttry:\n\t\t\t# Many thanks to Philipp for patching the huffman decoder to work!\n\t\t\tsubprocess.call([script_path + \"/bff_huffman_decompress\", filename + '.packed', filename])\n\t\t\tos.remove(filename + '.packed')\n\t\texcept:\n\t\t\tpass\nelse:\n\t_mkdir('./' + filename)\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/docs/README",
    "content": "DESCRIPTION\n\n\tBinwalk is a tool for searching a given binary image for embedded file types. Specifically,\n\tit was designed for identifying files embedded inside of firmware images. Binwalk file signatures\n\tare compatible with the magic signatures used by the Unix file utility.\n\n\tBinwalk includes a custom magic signature file, 'magic.binwalk'. This file contains improved \n\tsignatures for files that are commonly found in firmware images such as compressed/archived files, \n\tLinux kernels, bootloaders, filesystems, etc. \n\n\tSince version 0.3.3 an additional option, -C, is included. Specifying this option displays the \n\tvalue of each file offset in various data types (long, short, date, etc), as defined in magic.bincast.\n\tThis is useful for identifying header fields such as date and length values.\n\n\tSince version 0.3.8 an additional option, -A, is included. This option scans the specified file(s) for\n\texecutable code by searching for opcodes associated with the function prologues/epiloges of various\n\tarchitectures. These opcode signatures are defined in magic.binarch.\n\nUSAGE\n\n\tThe only required option for Binwalk is the files that you want to search:\n\n\t\t$ binwalk firmware1.bin firmware2.bin firmware3.bin\n\n\tBy default binwalk will include short signatures for gzip, lzma and jffs2 file fomats, and exclude \n\tinvalid results. These default filters can be disabled with the -d option, which will speed up the \n\tscan time but may cause binwalk to miss gzip, lzma or jffs2 files:\n\n\t\t$ binwalk -d firmware.bin\n\n\tIf searching for specific files, the scan time can be significantly improved by specifying the -T \n\toption. The -T option is implied when specific filters are specified via the -y option:\n\n\t\t$ binwalk -i jffs2 -T firmware.bin\n\t\t$ binwalk -y jffs2 firmware.bin\n\n\tBy default binwalk will use the signatures from the binwalk.magic file, but you may specify any other\n\tlibmagic-compatible signature file with the -m option. Note that for full maigc file compatibility,\n\tyou must specify the -s option to disable 'smart' matching:\n\n\t\t$ binwalk -m /usr/share/misc/magic -s firmware.bin\n\n\tBy default binwalk will check for valid file signatures anywhere in the target file. This means that\n\tscanning a 4MB file is the equivalent of running the Unix file utility 4 million times. To\n\tdecrease scan time, you may specify the byte alignment via the -b option. If, for example,\n\tyou specify a byte alignment of 16, then binwalk will assume that everything in the file is\n\t16-byte aligned and will only look for signatures every 16 bytes:\n\n\t\t$ binwalk -b 16 firmware.bin\n\n\tYou may also specify at what offset into the firmware image to start searching, and how many\n\tbytes should be searched. The following command searches 1000 bytes of data starting at an offset\n\tof 100:\n\t\t\n\t\t$ binwalk -o 100 -l 1000 firmware.bin\n\n\tAll integer arguments, such as -o, and -l, can be entered as decimal (ex: 16) or hexadecimal\n\t(ex: 0x10, \\x10, 10H, 10h) values.\n\n\tBy default, all magic signatures that are only two bytes long are ignored as they have a high\n\trate of false positive matches. To include these magic signatures, specify the -a option:\n\n\t\t$ binwalk -a firmware.bin\n\n\tYou can also include individual signatures from the default exclude list with the -i option:\n\n\t\t$ binwalk -i gzip firmware.bin\n\t\n\tInclude and exclude filters may also be specified in order to limit the search results. Multiple\n\tinclude / exclude filters may be specified, and are case insensitive. If an include filter is specified,\n\tonly descriptions that match that filter will be displayed. If an exclude filter is specified, all\n\tresults will be displayed except those that match the exclude filter. If both exclude and include\n\tfilters are specified, exclude filters trump include filters.\n\n\tOnly search for gzip results:\n\n\t\t$ binwalk -y gzip firmware.bin\n\n\tSearch for everything except results that contain the string 'invalid':\n\n\t\t$ binwalk -x invalid firmware.bin\n\n\tSearch only for results that are file systems, but that are not JFFS2 file systems:\n\n\t\t$ binwalk -y filesystem -x jffs2 firmware.bin\n\t\n\tTo update to the latest magic file definitions, use the -u option:\n\n\t\t# binwalk -u\n\nINSTALLATION\n\n\tTo build and install binwalk, run:\n\n\t\t$ ./configure\t\n\t\t$ make\n\t\t# make install\n\nDEPENDENCIES\n\n\tTo build from source, you must have the zlib and libcurl libraries. \n\tDebian users can install zlib and libcurl via apt-get:\n\n\t\t$ sudo apt-get install zlib1g-dev libcurl4-openssl-dev\n\t\n\tBinwalk is currently supported on the Linux and Mac OSX platforms. \n\t\nFILES\n\n\tdocs/README\t\tProject README file\n        src/binwalk.c\t\tMain binwalk source code file\n        src/binwalk.h\t\tMain binwalk source header file\n\tsrc/common.c\t\tCommon functions used by binwalk\n\tsrc/common.h\t\tCommon function declarations and definitions\n\tsrc/file-5.07.tar.gz\tUnix file utility source code\n\tsrc/filter.h\t\tFilter functions header file\n\tsrc/filter.c\t\tResult filtering functions\n\tsrc/magic.binarch\tCustom magic signature file for opcode scans\n        src/magic.bincast\tCustom magic signature file for casting data types\n        src/magic.binwalk\tCustom magic signature file for binwalk\n\tsrc/md5.c\t\tMD5 algorithm code by Peter Deutsch\n\tsrc/md5.h\t\tMD5 algorithm header by Peter Deutsch\n\tsrc/mparse.c\t\tMinimal magic file parsing library\n\tsrc/mparse.h\t\tParsing library header file\n\tsrc/update.c\t\tMagic file update routines\n\tsrc/update.h\t\tUpdates header file\n\nLICENSE\n\n\tThe MIT License\n\n\tCopyright (c) 2010 Craig Heffner\n\n\tPermission is hereby granted, free of charge, to any person obtaining a copy\n\tof this software and associated documentation files (the \"Software\"), to deal\n\tin the Software without restriction, including without limitation the rights\n\tto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\tcopies of the Software, and to permit persons to whom the Software is\n\tfurnished to do so, subject to the following conditions:\n\n\tThe above copyright notice and this permission notice shall be included in\n\tall copies or substantial portions of the Software.\n\n\tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\tIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\tFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\tAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\tLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\tOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n\tTHE SOFTWARE.\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/Makefile.in",
    "content": "CC=@CC@\nCFLAGS=@CFLAGS@\nLDFLAGS=@LDFLAGS@\nFILE=@FILE@\nMAGIC=magic\nprefix=@prefix@\nexec_prefix=@exec_prefix@\nMAGICPATH=@sysconfdir@/binwalk/$(MAGIC)\nETC=$(DESTDIR)@sysconfdir@/binwalk\nBIN=$(DESTDIR)@bindir@\n\nall: magi binwalk\n\nbinwalk: @DOFILE@ common.o md5.o mparse.o filter.o update.o\n\t$(CC) $(CFLAGS) -DMAGIC='\"$(MAGICPATH).binwalk\"' -DMAGIC_CAST='\"$(MAGICPATH).bincast\"' -DMAGIC_ARCH='\"$(MAGICPATH).binarch\"' binwalk.c -o binwalk *.o $(LDFLAGS)\n\nfile:\n\t(cd $(FILE)/src && make)\n\t(cp $(FILE)/src/*.o . && rm -f file.o)\n\t\ncommon.o:\n\t$(CC) $(CFLAGS) -c common.c\n\nmd5.o:\n\t$(CC) $(CFLAGS) -c md5.c\n\nmparse.o:\n\t$(CC) $(CFLAGS) -c mparse.c\n\nfilter.o:\n\t$(CC) $(CFLAGS) -c filter.c\n\nupdate.o:\n\t$(CC) $(CFLAGS) -c update.c\n\nmagi:\n\techo > $(MAGIC).binwalk\n\tfor FILE in magic/*; do \\\n\t\tcat $$FILE >> $(MAGIC).binwalk ; \\\n\tdone\n\ninstall:\n\tmkdir -p $(ETC)\n\tmkdir -p $(BIN)\n\tcp $(MAGIC).* $(ETC)\n\tcp binwalk $(BIN)/binwalk\n\nclean:\n\trm -f binwalk *.o\n\ncleanall: clean\n\trm -rf $(FILE)\n\trm -rf config.* *.cache\n\trm -f Makefile\n\ndistclean: cleanall\n\trm -rf $(ETC)\n\trm -f $(BIN)/binwalk\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/binwalk.c",
    "content": "#include <stdio.h>\n#include <stdlib.h>\n#include <getopt.h>\n#include <string.h>\n#include <time.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <sys/mman.h>\n#include <fcntl.h>\n#include <magic.h>\n#include \"update.h\"\n#include \"binwalk.h\"\n\nint main(int argc, char *argv[])\n{\n\tchar *out_file = NULL, *last_optarg = NULL;\n\tchar *magic_file_contents = NULL, *marker = NULL, *magic = NULL;\n\tsize_t mfsize = 0;\n\tint c = 0, i = 0;\n\tint filter_count = 0, magic_offset = 0, magic_size = 0, wildcard = 0, num_sigs = 0, check_magic_file = 0, fast_filter = 0;\n\tint update = 0, ignore_short_sigs = 1, use_default_filters = 1;\n\tint retval = EXIT_FAILURE;\n\tstruct magic_signature *signatures[MAX_SIGNATURES];\n\tstruct magic_filter *filters[MAX_FILTERS];\n\tstruct binconf config = { 0 };\n\n\tint long_opt_index = 0;\n\tchar *short_options = \"b:l:m:o:f:y:x:i:aAcCdkstvquh\";\n\tstruct option long_options[] = {\n\t\t\t{ \"align\", required_argument, NULL, 'b' },\n\t\t\t{ \"length\", required_argument, NULL, 'l' },\n\t\t\t{ \"magic\", required_argument, NULL, 'm' },\n\t\t\t{ \"offset\", required_argument, NULL, 'o' },\n\t\t\t{ \"file\", required_argument, NULL, 'f' },\n\t\t\t{ \"search\", required_argument, NULL, 'y' },\n\t\t\t{ \"exclude\", required_argument, NULL, 'x' },\n\t\t\t{ \"include\", required_argument, NULL, 'i' },\n\t\t\t{ \"all\", no_argument, NULL, 'a' },\n\t\t\t{ \"opcodes\", no_argument, NULL, 'A' },\n\t\t\t{ \"validate\", no_argument, NULL, 'c' },\n\t\t\t{ \"cast\", no_argument, NULL, 'C' },\n\t\t\t{ \"defaults\", no_argument, NULL, 'd' },\n\t\t\t{ \"keep-going\", no_argument, NULL, 'k' },\n\t\t\t{ \"smart\", no_argument, NULL, 's' },\n\t\t\t{ \"fast\", no_argument, NULL, 't' },\n\t\t\t{ \"verbose\", no_argument, NULL, 'v' },\n\t\t\t{ \"quiet\", no_argument, NULL, 'q' },\n\t\t\t{ \"update\", no_argument, NULL, 'u' },\n\t\t\t{ \"help\", no_argument, NULL, 'h' },\n\t\t\t{ 0, 0, 0, 0 }\n\t};\n\n\t/* Need at least one argument: the target file */\n\tif(argc == 1)\n\t{\n\t\tusage(argv[0]);\n\t\tgoto end;\n\t}\n\n\t/* Initialize global variables */\n\tmemset((void *) &globals,0,sizeof(globals));\n\t\n\t/* Initialize default configuration settings */\n\tconfig.flags = MAGIC_NONE;\n\tconfig.align = DEFAULT_BYTE_ALIGN;\n\tconfig.smart = 1;\n\n\twhile((c = getopt_long(argc, argv, short_options, long_options, &long_opt_index)) != -1)\n\t{\n\t\tswitch(c)\n\t\t{\n\t\t\tcase 'a':\n\t\t\t\tignore_short_sigs = 0;\n\t\t\t\tbreak;\n\t\t\tcase 'b':\n\t\t\t\tconfig.align = str2int(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\tcheck_magic_file = 1;\n\t\t\t\tbreak;\n\t\t\tcase 'C':\n\t\t\t\tconfig.magic = strdup(MAGIC_CAST);\n\t\t\t\tconfig.flags |= MAGIC_CONTINUE;\n\t\t\t\tbreak;\n\t\t\tcase 'A':\n\t\t\t\tconfig.magic = strdup(MAGIC_ARCH);\n\t\t\t\tignore_short_sigs = 0;\n\t\t\t\tbreak;\n\t\t\tcase 'f':\n\t\t\t\tout_file = strdup(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'i':\n\t\t\t\tadd_filter(filters, &filter_count, FILTER_ADD, optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'l':\n\t\t\t\tconfig.length = str2int(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'm':\n\t\t\t\tconfig.magic = strdup(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'o':\n\t\t\t\tconfig.offset = str2int(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'd':\n\t\t\t\tuse_default_filters = 0;\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\tconfig.smart = 0;\n\t\t\t\tbreak;\n\t\t\tcase 't':\n\t\t\t\tfast_filter = 1;\n\t\t\t\tbreak;\n\t\t\tcase 'k':\n\t\t\t\tconfig.flags |= MAGIC_CONTINUE;\n\t\t\t\tbreak;\n\t\t\tcase 'y':\n\t\t\t\tfast_filter = 1;\n\t\t\t\tuse_default_filters = 0;\n\t\t\t\tadd_filter(filters, &filter_count, FILTER_INCLUDE, optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'x':\n\t\t\t\tadd_filter(filters, &filter_count, FILTER_EXCLUDE, optarg);\n                                break;\n\t\t\tcase 'q':\n\t\t\t\tglobals.quiet = 1;\n\t\t\t\tbreak;\n\t\t\tcase 'u':\n\t\t\t\tupdate = 1;\n\t\t\t\tbreak;\n\t\t\tcase 'v':\n\t\t\t\tconfig.verbose = 1;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tusage(argv[0]);\n\t\t\t\tgoto end;\n\t\t}\n\n\t\t/* Keep a copy of the last optarg so we can distinguish between option arguments and file names later on */\n\t\tif(optarg)\n\t\t{\n\t\t\tif(last_optarg) free(last_optarg);\n\t\t\tlast_optarg = strdup(optarg);\n\t\t}\n\t}\n\n\t/* Update magic files from SVN repository */\n\tif(update)\n\t{\n\t\tprintf(\"Updating magic signatures...\");\n\t\tif(update_magic_file(BINWALK_UPDATE_URL, MAGIC) &&\n\t\t   update_magic_file(BINCAST_UPDATE_URL, MAGIC_CAST) &&\n\t\t   update_magic_file(BINARCH_UPDATE_URL, MAGIC_ARCH))\n\t\t{\n\t\t\tprintf(\"finished.\\n\");\n\t\t\tretval = EXIT_SUCCESS;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintf(\"failed.\\n\");\n\t\t}\n\t\tgoto end;\n\t}\n\n\t/* Unless otherwise specified, apply default filters */\n\tif(use_default_filters)\n\t{\n\t\tadd_filter(filters, &filter_count, FILTER_ADD, GZIP_FILTER);\n\t\tadd_filter(filters, &filter_count, FILTER_ADD, LZMA_FILTER);\n\t\tadd_filter(filters, &filter_count, FILTER_ADD, JFFS_FILTER);\n\t\tadd_filter(filters, &filter_count, FILTER_EXCLUDE, INVALID_FILTER);\n\t}\n\n\t/* Use the default magic file if none was specified on the command line */\n\tif(config.magic == NULL)\n\t{\n\t\tconfig.magic = strdup(MAGIC);\n\t}\n\n\t/* Initialize libmagic */\n\tconfig.cookie = magic_open(config.flags);\n\tif(!config.cookie)\n\t{\n\t\tfprintf(stderr,\"ERROR: Failed to initialize libmagic: %s\\n\", magic_error(config.cookie));\n\t\tgoto end;\n\t}\n\n\t/* Validate the magic file */\n\tif(check_magic_file)\n\t{ \n        \tif(magic_check(config.cookie, config.magic) != 0)\n        \t{\n        \t        fprintf(stderr, \"ERROR: Invalid magic file '%s': %s\\n\", config.magic, magic_error(config.cookie));\n\t\t} \n\t\telse \n\t\t{\n\t\t\tretval = EXIT_SUCCESS;\n\t\t}\n        \tgoto end;\n        }\n\n        /* If an output file was specified, open it */\n        if(out_file != NULL)\n\t{\n                globals.fsout = fopen(out_file,\"w\");\n                if(!globals.fsout)\n\t\t{\n                        perror(\"ERROR: Failed to open output file for writing\");\n                        goto end;\n                }\n        }\n\n\t/* Load the magic signatures file */\n\tif(magic_load(config.cookie, config.magic) == -1)\n\t{\n\t\tfprintf(stderr,\"ERROR: Failed to load magic file '%s': %s\\n\", config.magic, magic_error(config.cookie));\n\t\tgoto end;\n\t}\n\n\tif(config.smart)\n\t{\n\t\t/* Load magic signatures into the signatures struct array. */\n\t\tmagic_file_contents = (char *) file_read((char *) config.magic, &mfsize);\n\t\tmarker = magic_file_contents;\n\n\t\tfor(i=0; i<mfsize && num_sigs < MAX_SIGNATURES; i++)\n        \t{\n\t\t\t/* The first line for each magic entry will start with a decimal offset value. This is the line\n\t\t\t * that contains the actual signature, and is the one we want to parse. The rest are comments, \n\t\t\t * whitespace or subsequent signture parsing data that we let libmagic handle later on.\n\t\t\t */\n\t\t\tif(marker[0] >= '0' && marker[0] <= '9')\n\t\t\t{  \n\t\t\t\t/* Parse out the magic value, file offset and size for this entry */ \n\t\t\t\tmagic = parse_magic(marker, &magic_offset, &magic_size, &wildcard, filters, filter_count, ignore_short_sigs, fast_filter);\n\n\t\t\t\tif(magic && magic_size > 0)\n\t\t\t\t{\n\t\t\t\t\tsignatures[num_sigs] = malloc(sizeof(struct magic_signature));\n\t\t\t\t\tsignatures[num_sigs]->size = magic_size;\n\t\t\t\t\tsignatures[num_sigs]->offset = magic_offset;\n\t\t\t\t\tsignatures[num_sigs]->wildcard = wildcard;\n\t\t\t\t\tsignatures[num_sigs]->signature = malloc(magic_size);\n\t\t\t\t\tmemcpy(signatures[num_sigs]->signature, magic, magic_size);\n\t\t\t\t\tnum_sigs++;\n                       \t\t}\n\t\t\t\tif(magic) free(magic);\n                \t}\n\n\t\t\t/* Find the next new line. Break if not found, skip to the next character if one is found. */\n\t                marker = strstr(marker, \"\\n\");\n\t                if(!marker) break;\n\t                marker++;\n\t        }\n\t}\n\telse\n\t{\n\t\tnum_sigs = 1;\n\t}\n\n\t/* Process all the files specified on the command line */\n\tfor(i=argc-1; i>0; i--)\n        {\n\t\t/* If we've gotten to the arguments, we're done */\n                if((argv[i][0] == '-') ||\n                   ((last_optarg != NULL) && (strcmp(argv[i], last_optarg) == 0))\n\t\t)\n                {\n                        break;\n                }\n\n\t\tretval = process_file(argv[i], &config, signatures, num_sigs, filters, filter_count);\n        }\n\nend:\n        if(config.magic) free(config.magic);\n        if(magic_file_contents) munmap((void *) magic_file_contents, mfsize);\n        if(globals.fsout != NULL) fclose(globals.fsout);\n        if(config.cookie) magic_close(config.cookie);\n\treturn retval;\n}\n\n/* Search a file for magic signatures */\nint process_file(char *bin_file, struct binconf *config, struct magic_signature **signatures, int num_sigs, struct magic_filter **filters, int filter_count)\n{\n\tchar *md5 = NULL, *current_time = NULL, *ptr = NULL;\n\tconst void *buffer = NULL, *type = NULL;\n\tsize_t fsize = 0;\n\tint i = 0, j = 0, retval = EXIT_FAILURE;\n\n\t/* Read in the target file */\n\tbuffer = file_read(bin_file, &fsize);\n\tif(!buffer || fsize == 0)\n\t{\n\t\tfprintf(stderr,\"ERROR: Failed to read file '%s'.\\n\", bin_file);\n\t\tgoto end;\n\t}\n\n\t/* If no scan length was specified, scan the entire file */\n\tif(!config->length || config->length > fsize)\n\t{\n\t\tconfig->length = fsize;\n\t}\n\n\t/* Sanity check on the length + offset values */\n\tif((config->length + config->offset) > fsize)\n\t{\n\t\tconfig->length -= (config->length + config->offset) - fsize;\n\t}\n\n\tif(config->verbose)\n\t{\n\t\tmd5 = md5_string((void *) buffer,fsize);\n\t\tcurrent_time = timestamp();\n\t\tprint(\"\\n\");\n\t\tprint(\"Scan Time:    %s\\n\", current_time);\n\t\tprint(\"Magic File:   %s\\n\", config->magic);\n\t\tif(config->smart)\n\t\t{\n\t\t\tprint(\"Signatures:   %d\\n\", num_sigs);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprint(\"Signatures:   *\\n\");\n\t\t}\n\t\tprint(\"Target File:  %s\\n\", bin_file);\n\t\tprint(\"MD5 Checksum: %s\\n\", md5);\n\t\tif(current_time) free(current_time);\n\t\tif(md5) free(md5);\n\t}\n\n\tprint(\"\\nDECIMAL   \\tHEX       \\tDESCRIPTION\\n\");\n\tprint(\"-------------------------------------------------------------------------------------------------------\\n\");\n\n\t/* Loop through the file contents starting at the given offset.\n\t * Honor the given byte alignment (i.e., if align == 4, only look at every 4th byte).\n\t * Stop looping when length bytes have been searched, or when the end of the file is reached.\n\t */\n\tfor(i=config->offset; ((i-config->offset)<config->length && i<(fsize-config->align)); i+=config->align)\n\t{\n\t\tfor(j=0; j<num_sigs; j++)\n\t\t{\n\t\t\t/* Make sure we don't seek past the end of the buffer */\n\t\t\tif(!config->smart || (i+signatures[j]->offset < fsize))\n\t\t\t{\n\t\t\t\t/* Pre-screen data for magic file signatures prior to invoking libmagic. This significantly improves scan time. */\n\t\t\t\tif(!config->smart || \n\t\t\t\t   signatures[j]->wildcard == 1 || \n\t\t\t\t   memcmp((buffer+i+signatures[j]->offset), signatures[j]->signature, signatures[j]->size) == 0\n\t\t\t\t)\n\t\t\t\t{\n\t\t\t\t\t/* Since we found a signature match, ask libmagic to further examine the given offset into the file buffer */\n                        \t\ttype = magic_buffer(config->cookie, buffer+i, (fsize-i));\n\n                        \t\t/* Ignore NULL, \".*text.*\" and \"data\" responses */\n                        \t\tif(type != NULL && strncmp(type,DATA,DATA_SIZE) != 0 && strstr(type,TEXT) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\t\t/* \n\t\t\t\t\t\t * If filters were specified and the filter check specifies that\n\t\t\t\t\t\t * result should be excluded, then don't display it.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tif(filter_count > 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* Don't display anything that has been explicitly marked in the exclude list */\n\t\t\t\t\t\t\tif(filter_check(filters, filter_count, (char *) type) == RESULT_EXCLUDE)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n                                \t\n\t\t\t\t\t\t/* Prettify output if multiple matches were found at the same offset */\t\n\t\t\t\t\t\tif((config->flags | MAGIC_CONTINUE) == config->flags)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\twhile((ptr = strstr(type, MULTIPLE_MATCH_DELIM)))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmemcpy(ptr, MULTIPLE_MATCH_NEWLINE, MULTIPLE_MATCH_SIZE);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tprint(\"%-10d\\t0x%-8X\\t\",i,i);\n\t\t\t\t\t\tprint(\"%s\\n\",type);\n\t\t\t\t\t\tbreak;\n                        \t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprint(\"\\n\");\n\tretval = EXIT_SUCCESS;\n\nend:\n\tif(buffer) munmap((void *) buffer, fsize);\n\treturn retval;\n}\n\nvoid usage(char *progname)\n{\n\tfprintf(stderr,\"\\n\");\n\tfprintf(stderr,\"Binwalk v%s\\n\", PACKAGE_VERSION);\n\tfprintf(stderr,\"\\n\");\n\tfprintf(stderr,\"Usage: %s [OPTIONS] [FILE1] [FILE2] [FILE3] ...\\n\", progname);\n\tfprintf(stderr,\"\\n\");\n\tfprintf(stderr,USAGE_OPTIONS, MAGIC, GZIP_FILTER, LZMA_FILTER, JFFS_FILTER, INVALID_FILTER);\n\tfprintf(stderr,\"\\n\");\n\n\treturn;\n}\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/binwalk.h",
    "content": "#ifndef BINWALK_H\n#define BINWALK_H\n\n#include <magic.h>\n#include \"md5.h\"\n#include \"mparse.h\"\n#include \"filter.h\"\n#include \"common.h\"\n#include \"config.h\"\n\n/* These should get defined by the Makefile. If not, default to /etc/binwalk/magic.bin*. */\n#ifndef MAGIC\n#define MAGIC\t\t\t\"/etc/binwalk/magic.binwalk\"\n#endif\n#ifndef MAGIC_CAST\n#define MAGIC_CAST\t\t\"/etc/binwalk/magic.bincast\"\n#endif\n#ifndef MAGIC_ARCH\n#define MAGIC_ARCH\t\t\"/etc/binwalk/magic.binarch\"\n#endif\n\n#define DATA\t\t\t\"data\"\n#define DATA_SIZE\t\t4\n#define TEXT\t\t\t\"text\"\n#define DEFAULT_BYTE_ALIGN\t1\n#define PROGRESS_INTERVAL\t1000\n#define MAX_SIGNATURES\t\t8192\n#define MULTIPLE_MATCH_DELIM\t\"\\\\012- \"\n#define MULTIPLE_MATCH_NEWLINE\t\"\\r\\n\\t\\t\\t\\t\"\n#define MULTIPLE_MATCH_SIZE\t6\n#define GZIP_FILTER\t\t\"gzip\"\n#define LZMA_FILTER\t\t\"lzma\"\n#define JFFS_FILTER\t\t\"jffs2\"\n#define INVALID_FILTER\t\t\"invalid\"\n\n#define USAGE_OPTIONS\t\t\"\\\nOPTIONS\\n\\\n\\t-o, --offset=<int>            File offset to start searching at\\n\\\n\\t-l, --length=<int>            Number of bytes to search\\n\\\n\\t-b, --align=<int>             Set byte alignment\\n\\\n\\t-f, --file=<file>             Log results to file\\n\\\n\\t-m, --magic=<file>            Magic file to use [%s]\\n\\\n\\t-y, --search=<filter>         Only search for matches that have <filter> in their description (implies -n, -t)\\n\\\n\\t-x, --exclude=<filter>        Exclude matches that have <filter> in their description\\n\\\n\\t-i, --include=<filter>        Include matches that are normally excluded and that have <filter> in their description *\\n\\\n\\t-a, --all                     Search for all matches, including those that are normally excluded *\\n\\\n\\t-d, --defaults                Speed up scan by disabling default filters **\\n\\\n\\t-t, --fast                    Speed up scan by only loading signatures specified by -i or -y\\n\\\n\\t-u, --update                  Update magic signature files\\n\\\n\\t-v, --verbose                 Enable verbose mode\\n\\\n\\t-s, --smart                   Disable smart matching (implies -a)\\n\\\n\\t-k, --keep-going              Don't stop at the first match\\n\\\n\\t-c, --validate                Validate magic file\\n\\\n\\t-q, --quiet                   Supress output to stdout\\n\\\n\\t-A, --opcodes                 Scan for executable code (implies -a)\\n\\\n\\t-C, --cast                    Cast file contents as various data types (implies -k)\\n\\\n\\n\\n\\\n*  Signatures of two bytes or less are excluded by default. Use -i or -a to include them in the search.\\n\\\n\\n\\\n** Default filters include '%s', '%s' and '%s' results, and exclude '%s' results. Disabling the default\\n\\\n   filters will speed up scan time, but may miss these file types.\\n\\\n\"\n\nstruct magic_signature\n{\n\tint offset;\n\tint size;\n\tint wildcard;\n\tchar *signature;\n};\n\nstruct binconf\n{\n\tint smart;\n\tint verbose;\n\tint flags;\n\tint offset;\n\tint align;\n\tint length;\n\tchar *magic;\n\tmagic_t cookie;\n};\n\nvoid usage(char *progname);\nint process_file(char *bin_file, struct binconf *config, struct magic_signature **signatures, int num_sigs, struct magic_filter **filters, int filter_count);\n\n#endif\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/common.c",
    "content": "#include <stdio.h>\n#include <stdlib.h>\n#include <stdarg.h>\n#include <string.h>\n#include <time.h>\n#include <sys/mman.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <sys/ioctl.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include \"common.h\"\n\n#ifdef __linux\n#include <linux/fs.h>\n#endif\n\n/* Convert decimal and hexadecimal strings to integers */\nint str2int(char *str)\n{\n        int val = 0;\n        int strsize = 0;\n        int base = 10;\n        char *strptr = NULL;\n        char buffer[INT_MAX_STR_SIZE] = { 0 };\n\n\tif(str != NULL)\n\t{\n        \tstrsize = strlen(str);\n\n        \tif(strsize < INT_MAX_STR_SIZE)\n        \t{\n\n        \t\tmemcpy((void *) &buffer, str, strsize);\n        \t\tstrptr = (char *) &buffer;\n\t\n        \t\t/* If the string starts with '0x' or '\\x', or if it ends in 'h' or 'H', treat it as hex */\n        \t\tif(strsize >= 2)\n        \t\t{\n        \t\t        if(strptr[1] == 'x')\n        \t\t        {\n        \t\t                strptr += 2;\n        \t\t                base = 16;\n        \t\t        }\n        \t\t        else if(strptr[strsize-1] == 'h' || strptr[strsize-1] == 'H')\n        \t\t        {\n        \t\t                strptr[strsize-1] = '\\0';\n        \t\t                base = 16;\n        \t\t        }\n        \t\t}\n\t\n\t        \tval = strtol(strptr,NULL,base);\n\t\t}\n\t}\n\n        return val;\n}\n\n/* Reads in and returns the contents and size of a given file */\nconst void *file_read(char *file, size_t *fsize)\n{\n        int fd = 0;\n\tsize_t file_size = 0;\n        struct stat _fstat = { 0 };\n        const void *buffer = NULL;\n\n\tfd = open(file, O_RDONLY);\n        if(!fd)\n        {\n                perror(file);\n                goto end;\n        }\n\n        if(stat(file, &_fstat) == -1)\n        {\n\t\tperror(file);\n                goto end;\n        }\n\n        if(_fstat.st_size > 0)\n        {\n\t\tfile_size = _fstat.st_size;\n        }\n#ifdef __linux\n\telse\n\t{\n\t\tlong long long_file_size = 0;\n\n\t\t/* Special files may report a zero size in stat(); must get their file size via an ioctl call */\n\t\tif(ioctl(fd, BLKGETSIZE64, &long_file_size) == -1)\n\t\t{\n\t\t\tperror(\"ioctl\");\n\t\t\tgoto end;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfile_size = (size_t) long_file_size;\n\t\t}\n\t}\n#endif\n\n\tif(file_size > 0)\n\t{\n\t\tbuffer = mmap(NULL, file_size, PROT_READ, (MAP_SHARED | MAP_NORESERVE), fd, 0);\n\t\tif(buffer == MAP_FAILED)\n\t\t{\n\t\t\tperror(\"mmap\");\n\t\t\tbuffer = NULL;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t*fsize = file_size;\n\t\t}\n\t}\n\nend:\n        if(fd) close(fd);\n        return buffer;\n}\n\n/* Print messages to both the log file and stdout, as appropriate */\nvoid print(const char* format, ...)\n{\n        va_list args;\n\n        va_start(args,format);\n\n        if(globals.fsout != NULL)\n        {\n                vfprintf(globals.fsout,format,args);\n                fflush(globals.fsout);\n        }\n        if(globals.quiet == 0)\n        {\n                vfprintf(stdout,format,args);\n                fflush(stdout);\n        }\n\n        va_end(args);\n        return;\n}\n\n/* Returns the current timestamp as a string */\nchar *timestamp()\n{\n        time_t t = { 0 };\n        struct tm *tmp = NULL;\n        char *ts = NULL;\n\n        t = time(NULL);\n        tmp = localtime(&t);\n        if(!tmp)\n        {\n                perror(\"Localtime failure\");\n                goto end;\n        }\n\n        ts = malloc(MAX_TIMESTAMP_SIZE);\n        if(!ts)\n        {\n                perror(\"Malloc failure\");\n                goto end;\n        }\n        memset(ts,0,MAX_TIMESTAMP_SIZE);\n\n        if(strftime(ts,MAX_TIMESTAMP_SIZE-1,TIMESTAMP_FORMAT,tmp) == 0)\n        {\n                if(ts) free(ts);\n                ts = NULL;\n        }\n\nend:\n        return ts;\n}\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/common.h",
    "content": "#ifndef COMMON_H\n#define COMMON_H\n\n#define INT_MAX_STR_SIZE        1024\n#define MAX_TIMESTAMP_SIZE      1024\n#define TIMESTAMP_FORMAT        \"%b %d, %Y @ %T\"\n\n/* These globals are set once, read many */\nstruct bin_globals\n{\n        FILE *fsout;\n        int quiet;\n} globals;\n\nint str2int(char *str);\nconst void *file_read(char *file, size_t *fsize);\nvoid print(const char* format, ...);\nchar *timestamp();\n\n#endif\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/configure",
    "content": "#! /bin/sh\n# Guess values for system-dependent variables and create Makefiles.\n# Generated by GNU Autoconf 2.65 for binwalk 0.4.1.\n#\n# Report bugs to <http://code.google.com/p/binwalk/issues/list>.\n#\n#\n# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,\n# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,\n# Inc.\n#\n#\n# This configure script is free software; the Free Software Foundation\n# gives unlimited permission to copy, distribute and modify it.\n## -------------------- ##\n## M4sh Initialization. ##\n## -------------------- ##\n\n# Be more Bourne compatible\nDUALCASE=1; export DUALCASE # for MKS sh\nif test -n \"${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :\n  emulate sh\n  NULLCMD=:\n  # Pre-4.2 versions of Zsh do word splitting on ${1+\"$@\"}, which\n  # is contrary to our usage.  Disable this feature.\n  alias -g '${1+\"$@\"}'='\"$@\"'\n  setopt NO_GLOB_SUBST\nelse\n  case `(set -o) 2>/dev/null` in #(\n  *posix*) :\n    set -o posix ;; #(\n  *) :\n     ;;\nesac\nfi\n\n\nas_nl='\n'\nexport as_nl\n# Printing a long string crashes Solaris 7 /usr/bin/printf.\nas_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'\nas_echo=$as_echo$as_echo$as_echo$as_echo$as_echo\nas_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo\n# Prefer a ksh shell builtin over an external printf program on Solaris,\n# but without wasting forks for bash or zsh.\nif test -z \"$BASH_VERSION$ZSH_VERSION\" \\\n    && (test \"X`print -r -- $as_echo`\" = \"X$as_echo\") 2>/dev/null; then\n  as_echo='print -r --'\n  as_echo_n='print -rn --'\nelif (test \"X`printf %s $as_echo`\" = \"X$as_echo\") 2>/dev/null; then\n  as_echo='printf %s\\n'\n  as_echo_n='printf %s'\nelse\n  if test \"X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`\" = \"X-n $as_echo\"; then\n    as_echo_body='eval /usr/ucb/echo -n \"$1$as_nl\"'\n    as_echo_n='/usr/ucb/echo -n'\n  else\n    as_echo_body='eval expr \"X$1\" : \"X\\\\(.*\\\\)\"'\n    as_echo_n_body='eval\n      arg=$1;\n      case $arg in #(\n      *\"$as_nl\"*)\n\texpr \"X$arg\" : \"X\\\\(.*\\\\)$as_nl\";\n\targ=`expr \"X$arg\" : \".*$as_nl\\\\(.*\\\\)\"`;;\n      esac;\n      expr \"X$arg\" : \"X\\\\(.*\\\\)\" | tr -d \"$as_nl\"\n    '\n    export as_echo_n_body\n    as_echo_n='sh -c $as_echo_n_body as_echo'\n  fi\n  export as_echo_body\n  as_echo='sh -c $as_echo_body as_echo'\nfi\n\n# The user is always right.\nif test \"${PATH_SEPARATOR+set}\" != set; then\n  PATH_SEPARATOR=:\n  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {\n    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||\n      PATH_SEPARATOR=';'\n  }\nfi\n\n\n# IFS\n# We need space, tab and new line, in precisely that order.  Quoting is\n# there to prevent editors from complaining about space-tab.\n# (If _AS_PATH_WALK were called with IFS unset, it would disable word\n# splitting by setting IFS to empty value.)\nIFS=\" \"\"\t$as_nl\"\n\n# Find who we are.  Look in the path if we contain no directory separator.\ncase $0 in #((\n  *[\\\\/]* ) as_myself=$0 ;;\n  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    test -r \"$as_dir/$0\" && as_myself=$as_dir/$0 && break\n  done\nIFS=$as_save_IFS\n\n     ;;\nesac\n# We did not find ourselves, most probably we were run as `sh COMMAND'\n# in which case we are not to be found in the path.\nif test \"x$as_myself\" = x; then\n  as_myself=$0\nfi\nif test ! -f \"$as_myself\"; then\n  $as_echo \"$as_myself: error: cannot find myself; rerun with an absolute file name\" >&2\n  exit 1\nfi\n\n# Unset variables that we do not need and which cause bugs (e.g. in\n# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the \"|| exit 1\"\n# suppresses any \"Segmentation fault\" message there.  '((' could\n# trigger a bug in pdksh 5.2.14.\nfor as_var in BASH_ENV ENV MAIL MAILPATH\ndo eval test x\\${$as_var+set} = xset \\\n  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :\ndone\nPS1='$ '\nPS2='> '\nPS4='+ '\n\n# NLS nuisances.\nLC_ALL=C\nexport LC_ALL\nLANGUAGE=C\nexport LANGUAGE\n\n# CDPATH.\n(unset CDPATH) >/dev/null 2>&1 && unset CDPATH\n\nif test \"x$CONFIG_SHELL\" = x; then\n  as_bourne_compatible=\"if test -n \\\"\\${ZSH_VERSION+set}\\\" && (emulate sh) >/dev/null 2>&1; then :\n  emulate sh\n  NULLCMD=:\n  # Pre-4.2 versions of Zsh do word splitting on \\${1+\\\"\\$@\\\"}, which\n  # is contrary to our usage.  Disable this feature.\n  alias -g '\\${1+\\\"\\$@\\\"}'='\\\"\\$@\\\"'\n  setopt NO_GLOB_SUBST\nelse\n  case \\`(set -o) 2>/dev/null\\` in #(\n  *posix*) :\n    set -o posix ;; #(\n  *) :\n     ;;\nesac\nfi\n\"\n  as_required=\"as_fn_return () { (exit \\$1); }\nas_fn_success () { as_fn_return 0; }\nas_fn_failure () { as_fn_return 1; }\nas_fn_ret_success () { return 0; }\nas_fn_ret_failure () { return 1; }\n\nexitcode=0\nas_fn_success || { exitcode=1; echo as_fn_success failed.; }\nas_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }\nas_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }\nas_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }\nif ( set x; as_fn_ret_success y && test x = \\\"\\$1\\\" ); then :\n\nelse\n  exitcode=1; echo positional parameters were not saved.\nfi\ntest x\\$exitcode = x0 || exit 1\"\n  as_suggested=\"  as_lineno_1=\";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested\" as_lineno_1a=\\$LINENO\n  as_lineno_2=\";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested\" as_lineno_2a=\\$LINENO\n  eval 'test \\\"x\\$as_lineno_1'\\$as_run'\\\" != \\\"x\\$as_lineno_2'\\$as_run'\\\" &&\n  test \\\"x\\`expr \\$as_lineno_1'\\$as_run' + 1\\`\\\" = \\\"x\\$as_lineno_2'\\$as_run'\\\"' || exit 1\ntest \\$(( 1 + 1 )) = 2 || exit 1\"\n  if (eval \"$as_required\") 2>/dev/null; then :\n  as_have_required=yes\nelse\n  as_have_required=no\nfi\n  if test x$as_have_required = xyes && (eval \"$as_suggested\") 2>/dev/null; then :\n\nelse\n  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nas_found=false\nfor as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n  as_found=:\n  case $as_dir in #(\n\t /*)\n\t   for as_base in sh bash ksh sh5; do\n\t     # Try only shells that exist, to save several forks.\n\t     as_shell=$as_dir/$as_base\n\t     if { test -f \"$as_shell\" || test -f \"$as_shell.exe\"; } &&\n\t\t    { $as_echo \"$as_bourne_compatible\"\"$as_required\" | as_run=a \"$as_shell\"; } 2>/dev/null; then :\n  CONFIG_SHELL=$as_shell as_have_required=yes\n\t\t   if { $as_echo \"$as_bourne_compatible\"\"$as_suggested\" | as_run=a \"$as_shell\"; } 2>/dev/null; then :\n  break 2\nfi\nfi\n\t   done;;\n       esac\n  as_found=false\ndone\n$as_found || { if { test -f \"$SHELL\" || test -f \"$SHELL.exe\"; } &&\n\t      { $as_echo \"$as_bourne_compatible\"\"$as_required\" | as_run=a \"$SHELL\"; } 2>/dev/null; then :\n  CONFIG_SHELL=$SHELL as_have_required=yes\nfi; }\nIFS=$as_save_IFS\n\n\n      if test \"x$CONFIG_SHELL\" != x; then :\n  # We cannot yet assume a decent shell, so we have to provide a\n\t# neutralization value for shells without unset; and this also\n\t# works around shells that cannot unset nonexistent variables.\n\tBASH_ENV=/dev/null\n\tENV=/dev/null\n\t(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV\n\texport CONFIG_SHELL\n\texec \"$CONFIG_SHELL\" \"$as_myself\" ${1+\"$@\"}\nfi\n\n    if test x$as_have_required = xno; then :\n  $as_echo \"$0: This script requires a shell more modern than all\"\n  $as_echo \"$0: the shells that I found on your system.\"\n  if test x${ZSH_VERSION+set} = xset ; then\n    $as_echo \"$0: In particular, zsh $ZSH_VERSION has bugs and should\"\n    $as_echo \"$0: be upgraded to zsh 4.3.4 or later.\"\n  else\n    $as_echo \"$0: Please tell bug-autoconf@gnu.org and\n$0: http://code.google.com/p/binwalk/issues/list about your\n$0: system, including any error possibly output before this\n$0: message. Then install a modern shell, or manually run\n$0: the script under such a shell if you do have one.\"\n  fi\n  exit 1\nfi\nfi\nfi\nSHELL=${CONFIG_SHELL-/bin/sh}\nexport SHELL\n# Unset more variables known to interfere with behavior of common tools.\nCLICOLOR_FORCE= GREP_OPTIONS=\nunset CLICOLOR_FORCE GREP_OPTIONS\n\n## --------------------- ##\n## M4sh Shell Functions. ##\n## --------------------- ##\n# as_fn_unset VAR\n# ---------------\n# Portably unset VAR.\nas_fn_unset ()\n{\n  { eval $1=; unset $1;}\n}\nas_unset=as_fn_unset\n\n# as_fn_set_status STATUS\n# -----------------------\n# Set $? to STATUS, without forking.\nas_fn_set_status ()\n{\n  return $1\n} # as_fn_set_status\n\n# as_fn_exit STATUS\n# -----------------\n# Exit the shell with STATUS, even in a \"trap 0\" or \"set -e\" context.\nas_fn_exit ()\n{\n  set +e\n  as_fn_set_status $1\n  exit $1\n} # as_fn_exit\n\n# as_fn_mkdir_p\n# -------------\n# Create \"$as_dir\" as a directory, including parents if necessary.\nas_fn_mkdir_p ()\n{\n\n  case $as_dir in #(\n  -*) as_dir=./$as_dir;;\n  esac\n  test -d \"$as_dir\" || eval $as_mkdir_p || {\n    as_dirs=\n    while :; do\n      case $as_dir in #(\n      *\\'*) as_qdir=`$as_echo \"$as_dir\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"`;; #'(\n      *) as_qdir=$as_dir;;\n      esac\n      as_dirs=\"'$as_qdir' $as_dirs\"\n      as_dir=`$as_dirname -- \"$as_dir\" ||\n$as_expr X\"$as_dir\" : 'X\\(.*[^/]\\)//*[^/][^/]*/*$' \\| \\\n\t X\"$as_dir\" : 'X\\(//\\)[^/]' \\| \\\n\t X\"$as_dir\" : 'X\\(//\\)$' \\| \\\n\t X\"$as_dir\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X\"$as_dir\" |\n    sed '/^X\\(.*[^/]\\)\\/\\/*[^/][^/]*\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)[^/].*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n      test -d \"$as_dir\" && break\n    done\n    test -z \"$as_dirs\" || eval \"mkdir $as_dirs\"\n  } || test -d \"$as_dir\" || as_fn_error \"cannot create directory $as_dir\"\n\n\n} # as_fn_mkdir_p\n# as_fn_append VAR VALUE\n# ----------------------\n# Append the text in VALUE to the end of the definition contained in VAR. Take\n# advantage of any shell optimizations that allow amortized linear growth over\n# repeated appends, instead of the typical quadratic growth present in naive\n# implementations.\nif (eval \"as_var=1; as_var+=2; test x\\$as_var = x12\") 2>/dev/null; then :\n  eval 'as_fn_append ()\n  {\n    eval $1+=\\$2\n  }'\nelse\n  as_fn_append ()\n  {\n    eval $1=\\$$1\\$2\n  }\nfi # as_fn_append\n\n# as_fn_arith ARG...\n# ------------------\n# Perform arithmetic evaluation on the ARGs, and store the result in the\n# global $as_val. Take advantage of shells that can avoid forks. The arguments\n# must be portable across $(()) and expr.\nif (eval \"test \\$(( 1 + 1 )) = 2\") 2>/dev/null; then :\n  eval 'as_fn_arith ()\n  {\n    as_val=$(( $* ))\n  }'\nelse\n  as_fn_arith ()\n  {\n    as_val=`expr \"$@\" || test $? -eq 1`\n  }\nfi # as_fn_arith\n\n\n# as_fn_error ERROR [LINENO LOG_FD]\n# ---------------------------------\n# Output \"`basename $0`: error: ERROR\" to stderr. If LINENO and LOG_FD are\n# provided, also output the error to LOG_FD, referencing LINENO. Then exit the\n# script with status $?, using 1 if that was 0.\nas_fn_error ()\n{\n  as_status=$?; test $as_status -eq 0 && as_status=1\n  if test \"$3\"; then\n    as_lineno=${as_lineno-\"$2\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n    $as_echo \"$as_me:${as_lineno-$LINENO}: error: $1\" >&$3\n  fi\n  $as_echo \"$as_me: error: $1\" >&2\n  as_fn_exit $as_status\n} # as_fn_error\n\nif expr a : '\\(a\\)' >/dev/null 2>&1 &&\n   test \"X`expr 00001 : '.*\\(...\\)'`\" = X001; then\n  as_expr=expr\nelse\n  as_expr=false\nfi\n\nif (basename -- /) >/dev/null 2>&1 && test \"X`basename -- / 2>&1`\" = \"X/\"; then\n  as_basename=basename\nelse\n  as_basename=false\nfi\n\nif (as_dir=`dirname -- /` && test \"X$as_dir\" = X/) >/dev/null 2>&1; then\n  as_dirname=dirname\nelse\n  as_dirname=false\nfi\n\nas_me=`$as_basename -- \"$0\" ||\n$as_expr X/\"$0\" : '.*/\\([^/][^/]*\\)/*$' \\| \\\n\t X\"$0\" : 'X\\(//\\)$' \\| \\\n\t X\"$0\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X/\"$0\" |\n    sed '/^.*\\/\\([^/][^/]*\\)\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\/\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\/\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n\n# Avoid depending upon Character Ranges.\nas_cr_letters='abcdefghijklmnopqrstuvwxyz'\nas_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'\nas_cr_Letters=$as_cr_letters$as_cr_LETTERS\nas_cr_digits='0123456789'\nas_cr_alnum=$as_cr_Letters$as_cr_digits\n\n\n  as_lineno_1=$LINENO as_lineno_1a=$LINENO\n  as_lineno_2=$LINENO as_lineno_2a=$LINENO\n  eval 'test \"x$as_lineno_1'$as_run'\" != \"x$as_lineno_2'$as_run'\" &&\n  test \"x`expr $as_lineno_1'$as_run' + 1`\" = \"x$as_lineno_2'$as_run'\"' || {\n  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)\n  sed -n '\n    p\n    /[$]LINENO/=\n  ' <$as_myself |\n    sed '\n      s/[$]LINENO.*/&-/\n      t lineno\n      b\n      :lineno\n      N\n      :loop\n      s/[$]LINENO\\([^'$as_cr_alnum'_].*\\n\\)\\(.*\\)/\\2\\1\\2/\n      t loop\n      s/-\\n.*//\n    ' >$as_me.lineno &&\n  chmod +x \"$as_me.lineno\" ||\n    { $as_echo \"$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell\" >&2; as_fn_exit 1; }\n\n  # Don't try to exec as it changes $[0], causing all sort of problems\n  # (the dirname of $[0] is not the place where we might find the\n  # original and so on.  Autoconf is especially sensitive to this).\n  . \"./$as_me.lineno\"\n  # Exit status is that of the last command.\n  exit\n}\n\nECHO_C= ECHO_N= ECHO_T=\ncase `echo -n x` in #(((((\n-n*)\n  case `echo 'xy\\c'` in\n  *c*) ECHO_T='\t';;\t# ECHO_T is single tab character.\n  xy)  ECHO_C='\\c';;\n  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null\n       ECHO_T='\t';;\n  esac;;\n*)\n  ECHO_N='-n';;\nesac\n\nrm -f conf$$ conf$$.exe conf$$.file\nif test -d conf$$.dir; then\n  rm -f conf$$.dir/conf$$.file\nelse\n  rm -f conf$$.dir\n  mkdir conf$$.dir 2>/dev/null\nfi\nif (echo >conf$$.file) 2>/dev/null; then\n  if ln -s conf$$.file conf$$ 2>/dev/null; then\n    as_ln_s='ln -s'\n    # ... but there are two gotchas:\n    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.\n    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.\n    # In both cases, we have to default to `cp -p'.\n    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||\n      as_ln_s='cp -p'\n  elif ln conf$$.file conf$$ 2>/dev/null; then\n    as_ln_s=ln\n  else\n    as_ln_s='cp -p'\n  fi\nelse\n  as_ln_s='cp -p'\nfi\nrm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file\nrmdir conf$$.dir 2>/dev/null\n\nif mkdir -p . 2>/dev/null; then\n  as_mkdir_p='mkdir -p \"$as_dir\"'\nelse\n  test -d ./-p && rmdir ./-p\n  as_mkdir_p=false\nfi\n\nif test -x / >/dev/null 2>&1; then\n  as_test_x='test -x'\nelse\n  if ls -dL / >/dev/null 2>&1; then\n    as_ls_L_option=L\n  else\n    as_ls_L_option=\n  fi\n  as_test_x='\n    eval sh -c '\\''\n      if test -d \"$1\"; then\n\ttest -d \"$1/.\";\n      else\n\tcase $1 in #(\n\t-*)set \"./$1\";;\n\tesac;\n\tcase `ls -ld'$as_ls_L_option' \"$1\" 2>/dev/null` in #((\n\t???[sx]*):;;*)false;;esac;fi\n    '\\'' sh\n  '\nfi\nas_executable_p=$as_test_x\n\n# Sed expression to map a string onto a valid CPP name.\nas_tr_cpp=\"eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'\"\n\n# Sed expression to map a string onto a valid variable name.\nas_tr_sh=\"eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'\"\n\n\ntest -n \"$DJDIR\" || exec 7<&0 </dev/null\nexec 6>&1\n\n# Name of the host.\n# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,\n# so uname gets run too.\nac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`\n\n#\n# Initializations.\n#\nac_default_prefix=/usr/local\nac_clean_files=\nac_config_libobj_dir=.\nLIBOBJS=\ncross_compiling=no\nsubdirs=\nMFLAGS=\nMAKEFLAGS=\n\n# Identity of this package.\nPACKAGE_NAME='binwalk'\nPACKAGE_TARNAME='binwalk'\nPACKAGE_VERSION='0.4.1'\nPACKAGE_STRING='binwalk 0.4.1'\nPACKAGE_BUGREPORT='http://code.google.com/p/binwalk/issues/list'\nPACKAGE_URL=''\n\nac_unique_file=\"md5.c\"\n# Factoring default headers for most tests.\nac_includes_default=\"\\\n#include <stdio.h>\n#ifdef HAVE_SYS_TYPES_H\n# include <sys/types.h>\n#endif\n#ifdef HAVE_SYS_STAT_H\n# include <sys/stat.h>\n#endif\n#ifdef STDC_HEADERS\n# include <stdlib.h>\n# include <stddef.h>\n#else\n# ifdef HAVE_STDLIB_H\n#  include <stdlib.h>\n# endif\n#endif\n#ifdef HAVE_STRING_H\n# if !defined STDC_HEADERS && defined HAVE_MEMORY_H\n#  include <memory.h>\n# endif\n# include <string.h>\n#endif\n#ifdef HAVE_STRINGS_H\n# include <strings.h>\n#endif\n#ifdef HAVE_INTTYPES_H\n# include <inttypes.h>\n#endif\n#ifdef HAVE_STDINT_H\n# include <stdint.h>\n#endif\n#ifdef HAVE_UNISTD_H\n# include <unistd.h>\n#endif\"\n\nac_subst_vars='LTLIBOBJS\nDOFILE\nFILE\nLIBOBJS\nEGREP\nGREP\nCPP\nOBJEXT\nEXEEXT\nac_ct_CC\nCPPFLAGS\nLDFLAGS\nCFLAGS\nCC\ntarget_alias\nhost_alias\nbuild_alias\nLIBS\nECHO_T\nECHO_N\nECHO_C\nDEFS\nmandir\nlocaledir\nlibdir\npsdir\npdfdir\ndvidir\nhtmldir\ninfodir\ndocdir\noldincludedir\nincludedir\nlocalstatedir\nsharedstatedir\nsysconfdir\ndatadir\ndatarootdir\nlibexecdir\nsbindir\nbindir\nprogram_transform_name\nprefix\nexec_prefix\nPACKAGE_URL\nPACKAGE_BUGREPORT\nPACKAGE_STRING\nPACKAGE_VERSION\nPACKAGE_TARNAME\nPACKAGE_NAME\nPATH_SEPARATOR\nSHELL'\nac_subst_files=''\nac_user_opts='\nenable_option_checking\nenable_static\nenable_libmagic\nenable_updates\n'\n      ac_precious_vars='build_alias\nhost_alias\ntarget_alias\nCC\nCFLAGS\nLDFLAGS\nLIBS\nCPPFLAGS\nCPP'\n\n\n# Initialize some variables set by options.\nac_init_help=\nac_init_version=false\nac_unrecognized_opts=\nac_unrecognized_sep=\n# The variables have the same names as the options, with\n# dashes changed to underlines.\ncache_file=/dev/null\nexec_prefix=NONE\nno_create=\nno_recursion=\nprefix=NONE\nprogram_prefix=NONE\nprogram_suffix=NONE\nprogram_transform_name=s,x,x,\nsilent=\nsite=\nsrcdir=\nverbose=\nx_includes=NONE\nx_libraries=NONE\n\n# Installation directory options.\n# These are left unexpanded so users can \"make install exec_prefix=/foo\"\n# and all the variables that are supposed to be based on exec_prefix\n# by default will actually change.\n# Use braces instead of parens because sh, perl, etc. also accept them.\n# (The list follows the same order as the GNU Coding Standards.)\nbindir='${exec_prefix}/bin'\nsbindir='${exec_prefix}/sbin'\nlibexecdir='${exec_prefix}/libexec'\ndatarootdir='${prefix}/share'\ndatadir='${datarootdir}'\nsysconfdir='${prefix}/etc'\nsharedstatedir='${prefix}/com'\nlocalstatedir='${prefix}/var'\nincludedir='${prefix}/include'\noldincludedir='/usr/include'\ndocdir='${datarootdir}/doc/${PACKAGE_TARNAME}'\ninfodir='${datarootdir}/info'\nhtmldir='${docdir}'\ndvidir='${docdir}'\npdfdir='${docdir}'\npsdir='${docdir}'\nlibdir='${exec_prefix}/lib'\nlocaledir='${datarootdir}/locale'\nmandir='${datarootdir}/man'\n\nac_prev=\nac_dashdash=\nfor ac_option\ndo\n  # If the previous option needs an argument, assign it.\n  if test -n \"$ac_prev\"; then\n    eval $ac_prev=\\$ac_option\n    ac_prev=\n    continue\n  fi\n\n  case $ac_option in\n  *=*)\tac_optarg=`expr \"X$ac_option\" : '[^=]*=\\(.*\\)'` ;;\n  *)\tac_optarg=yes ;;\n  esac\n\n  # Accept the important Cygnus configure options, so we can diagnose typos.\n\n  case $ac_dashdash$ac_option in\n  --)\n    ac_dashdash=yes ;;\n\n  -bindir | --bindir | --bindi | --bind | --bin | --bi)\n    ac_prev=bindir ;;\n  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)\n    bindir=$ac_optarg ;;\n\n  -build | --build | --buil | --bui | --bu)\n    ac_prev=build_alias ;;\n  -build=* | --build=* | --buil=* | --bui=* | --bu=*)\n    build_alias=$ac_optarg ;;\n\n  -cache-file | --cache-file | --cache-fil | --cache-fi \\\n  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)\n    ac_prev=cache_file ;;\n  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \\\n  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)\n    cache_file=$ac_optarg ;;\n\n  --config-cache | -C)\n    cache_file=config.cache ;;\n\n  -datadir | --datadir | --datadi | --datad)\n    ac_prev=datadir ;;\n  -datadir=* | --datadir=* | --datadi=* | --datad=*)\n    datadir=$ac_optarg ;;\n\n  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \\\n  | --dataroo | --dataro | --datar)\n    ac_prev=datarootdir ;;\n  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \\\n  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)\n    datarootdir=$ac_optarg ;;\n\n  -disable-* | --disable-*)\n    ac_useropt=`expr \"x$ac_option\" : 'x-*disable-\\(.*\\)'`\n    # Reject names that are not valid shell variable names.\n    expr \"x$ac_useropt\" : \".*[^-+._$as_cr_alnum]\" >/dev/null &&\n      as_fn_error \"invalid feature name: $ac_useropt\"\n    ac_useropt_orig=$ac_useropt\n    ac_useropt=`$as_echo \"$ac_useropt\" | sed 's/[-+.]/_/g'`\n    case $ac_user_opts in\n      *\"\n\"enable_$ac_useropt\"\n\"*) ;;\n      *) ac_unrecognized_opts=\"$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig\"\n\t ac_unrecognized_sep=', ';;\n    esac\n    eval enable_$ac_useropt=no ;;\n\n  -docdir | --docdir | --docdi | --doc | --do)\n    ac_prev=docdir ;;\n  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)\n    docdir=$ac_optarg ;;\n\n  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)\n    ac_prev=dvidir ;;\n  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)\n    dvidir=$ac_optarg ;;\n\n  -enable-* | --enable-*)\n    ac_useropt=`expr \"x$ac_option\" : 'x-*enable-\\([^=]*\\)'`\n    # Reject names that are not valid shell variable names.\n    expr \"x$ac_useropt\" : \".*[^-+._$as_cr_alnum]\" >/dev/null &&\n      as_fn_error \"invalid feature name: $ac_useropt\"\n    ac_useropt_orig=$ac_useropt\n    ac_useropt=`$as_echo \"$ac_useropt\" | sed 's/[-+.]/_/g'`\n    case $ac_user_opts in\n      *\"\n\"enable_$ac_useropt\"\n\"*) ;;\n      *) ac_unrecognized_opts=\"$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig\"\n\t ac_unrecognized_sep=', ';;\n    esac\n    eval enable_$ac_useropt=\\$ac_optarg ;;\n\n  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \\\n  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \\\n  | --exec | --exe | --ex)\n    ac_prev=exec_prefix ;;\n  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \\\n  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \\\n  | --exec=* | --exe=* | --ex=*)\n    exec_prefix=$ac_optarg ;;\n\n  -gas | --gas | --ga | --g)\n    # Obsolete; use --with-gas.\n    with_gas=yes ;;\n\n  -help | --help | --hel | --he | -h)\n    ac_init_help=long ;;\n  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)\n    ac_init_help=recursive ;;\n  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)\n    ac_init_help=short ;;\n\n  -host | --host | --hos | --ho)\n    ac_prev=host_alias ;;\n  -host=* | --host=* | --hos=* | --ho=*)\n    host_alias=$ac_optarg ;;\n\n  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)\n    ac_prev=htmldir ;;\n  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \\\n  | --ht=*)\n    htmldir=$ac_optarg ;;\n\n  -includedir | --includedir | --includedi | --included | --include \\\n  | --includ | --inclu | --incl | --inc)\n    ac_prev=includedir ;;\n  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \\\n  | --includ=* | --inclu=* | --incl=* | --inc=*)\n    includedir=$ac_optarg ;;\n\n  -infodir | --infodir | --infodi | --infod | --info | --inf)\n    ac_prev=infodir ;;\n  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)\n    infodir=$ac_optarg ;;\n\n  -libdir | --libdir | --libdi | --libd)\n    ac_prev=libdir ;;\n  -libdir=* | --libdir=* | --libdi=* | --libd=*)\n    libdir=$ac_optarg ;;\n\n  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \\\n  | --libexe | --libex | --libe)\n    ac_prev=libexecdir ;;\n  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \\\n  | --libexe=* | --libex=* | --libe=*)\n    libexecdir=$ac_optarg ;;\n\n  -localedir | --localedir | --localedi | --localed | --locale)\n    ac_prev=localedir ;;\n  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)\n    localedir=$ac_optarg ;;\n\n  -localstatedir | --localstatedir | --localstatedi | --localstated \\\n  | --localstate | --localstat | --localsta | --localst | --locals)\n    ac_prev=localstatedir ;;\n  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \\\n  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)\n    localstatedir=$ac_optarg ;;\n\n  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)\n    ac_prev=mandir ;;\n  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)\n    mandir=$ac_optarg ;;\n\n  -nfp | --nfp | --nf)\n    # Obsolete; use --without-fp.\n    with_fp=no ;;\n\n  -no-create | --no-create | --no-creat | --no-crea | --no-cre \\\n  | --no-cr | --no-c | -n)\n    no_create=yes ;;\n\n  -no-recursion | --no-recursion | --no-recursio | --no-recursi \\\n  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)\n    no_recursion=yes ;;\n\n  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \\\n  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \\\n  | --oldin | --oldi | --old | --ol | --o)\n    ac_prev=oldincludedir ;;\n  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \\\n  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \\\n  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)\n    oldincludedir=$ac_optarg ;;\n\n  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)\n    ac_prev=prefix ;;\n  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)\n    prefix=$ac_optarg ;;\n\n  -program-prefix | --program-prefix | --program-prefi | --program-pref \\\n  | --program-pre | --program-pr | --program-p)\n    ac_prev=program_prefix ;;\n  -program-prefix=* | --program-prefix=* | --program-prefi=* \\\n  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)\n    program_prefix=$ac_optarg ;;\n\n  -program-suffix | --program-suffix | --program-suffi | --program-suff \\\n  | --program-suf | --program-su | --program-s)\n    ac_prev=program_suffix ;;\n  -program-suffix=* | --program-suffix=* | --program-suffi=* \\\n  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)\n    program_suffix=$ac_optarg ;;\n\n  -program-transform-name | --program-transform-name \\\n  | --program-transform-nam | --program-transform-na \\\n  | --program-transform-n | --program-transform- \\\n  | --program-transform | --program-transfor \\\n  | --program-transfo | --program-transf \\\n  | --program-trans | --program-tran \\\n  | --progr-tra | --program-tr | --program-t)\n    ac_prev=program_transform_name ;;\n  -program-transform-name=* | --program-transform-name=* \\\n  | --program-transform-nam=* | --program-transform-na=* \\\n  | --program-transform-n=* | --program-transform-=* \\\n  | --program-transform=* | --program-transfor=* \\\n  | --program-transfo=* | --program-transf=* \\\n  | --program-trans=* | --program-tran=* \\\n  | --progr-tra=* | --program-tr=* | --program-t=*)\n    program_transform_name=$ac_optarg ;;\n\n  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)\n    ac_prev=pdfdir ;;\n  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)\n    pdfdir=$ac_optarg ;;\n\n  -psdir | --psdir | --psdi | --psd | --ps)\n    ac_prev=psdir ;;\n  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)\n    psdir=$ac_optarg ;;\n\n  -q | -quiet | --quiet | --quie | --qui | --qu | --q \\\n  | -silent | --silent | --silen | --sile | --sil)\n    silent=yes ;;\n\n  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)\n    ac_prev=sbindir ;;\n  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \\\n  | --sbi=* | --sb=*)\n    sbindir=$ac_optarg ;;\n\n  -sharedstatedir | --sharedstatedir | --sharedstatedi \\\n  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \\\n  | --sharedst | --shareds | --shared | --share | --shar \\\n  | --sha | --sh)\n    ac_prev=sharedstatedir ;;\n  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \\\n  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \\\n  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \\\n  | --sha=* | --sh=*)\n    sharedstatedir=$ac_optarg ;;\n\n  -site | --site | --sit)\n    ac_prev=site ;;\n  -site=* | --site=* | --sit=*)\n    site=$ac_optarg ;;\n\n  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)\n    ac_prev=srcdir ;;\n  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)\n    srcdir=$ac_optarg ;;\n\n  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \\\n  | --syscon | --sysco | --sysc | --sys | --sy)\n    ac_prev=sysconfdir ;;\n  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \\\n  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)\n    sysconfdir=$ac_optarg ;;\n\n  -target | --target | --targe | --targ | --tar | --ta | --t)\n    ac_prev=target_alias ;;\n  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)\n    target_alias=$ac_optarg ;;\n\n  -v | -verbose | --verbose | --verbos | --verbo | --verb)\n    verbose=yes ;;\n\n  -version | --version | --versio | --versi | --vers | -V)\n    ac_init_version=: ;;\n\n  -with-* | --with-*)\n    ac_useropt=`expr \"x$ac_option\" : 'x-*with-\\([^=]*\\)'`\n    # Reject names that are not valid shell variable names.\n    expr \"x$ac_useropt\" : \".*[^-+._$as_cr_alnum]\" >/dev/null &&\n      as_fn_error \"invalid package name: $ac_useropt\"\n    ac_useropt_orig=$ac_useropt\n    ac_useropt=`$as_echo \"$ac_useropt\" | sed 's/[-+.]/_/g'`\n    case $ac_user_opts in\n      *\"\n\"with_$ac_useropt\"\n\"*) ;;\n      *) ac_unrecognized_opts=\"$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig\"\n\t ac_unrecognized_sep=', ';;\n    esac\n    eval with_$ac_useropt=\\$ac_optarg ;;\n\n  -without-* | --without-*)\n    ac_useropt=`expr \"x$ac_option\" : 'x-*without-\\(.*\\)'`\n    # Reject names that are not valid shell variable names.\n    expr \"x$ac_useropt\" : \".*[^-+._$as_cr_alnum]\" >/dev/null &&\n      as_fn_error \"invalid package name: $ac_useropt\"\n    ac_useropt_orig=$ac_useropt\n    ac_useropt=`$as_echo \"$ac_useropt\" | sed 's/[-+.]/_/g'`\n    case $ac_user_opts in\n      *\"\n\"with_$ac_useropt\"\n\"*) ;;\n      *) ac_unrecognized_opts=\"$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig\"\n\t ac_unrecognized_sep=', ';;\n    esac\n    eval with_$ac_useropt=no ;;\n\n  --x)\n    # Obsolete; use --with-x.\n    with_x=yes ;;\n\n  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \\\n  | --x-incl | --x-inc | --x-in | --x-i)\n    ac_prev=x_includes ;;\n  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \\\n  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)\n    x_includes=$ac_optarg ;;\n\n  -x-libraries | --x-libraries | --x-librarie | --x-librari \\\n  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)\n    ac_prev=x_libraries ;;\n  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \\\n  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)\n    x_libraries=$ac_optarg ;;\n\n  -*) as_fn_error \"unrecognized option: \\`$ac_option'\nTry \\`$0 --help' for more information.\"\n    ;;\n\n  *=*)\n    ac_envvar=`expr \"x$ac_option\" : 'x\\([^=]*\\)='`\n    # Reject names that are not valid shell variable names.\n    case $ac_envvar in #(\n      '' | [0-9]* | *[!_$as_cr_alnum]* )\n      as_fn_error \"invalid variable name: \\`$ac_envvar'\" ;;\n    esac\n    eval $ac_envvar=\\$ac_optarg\n    export $ac_envvar ;;\n\n  *)\n    # FIXME: should be removed in autoconf 3.0.\n    $as_echo \"$as_me: WARNING: you should use --build, --host, --target\" >&2\n    expr \"x$ac_option\" : \".*[^-._$as_cr_alnum]\" >/dev/null &&\n      $as_echo \"$as_me: WARNING: invalid host type: $ac_option\" >&2\n    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}\n    ;;\n\n  esac\ndone\n\nif test -n \"$ac_prev\"; then\n  ac_option=--`echo $ac_prev | sed 's/_/-/g'`\n  as_fn_error \"missing argument to $ac_option\"\nfi\n\nif test -n \"$ac_unrecognized_opts\"; then\n  case $enable_option_checking in\n    no) ;;\n    fatal) as_fn_error \"unrecognized options: $ac_unrecognized_opts\" ;;\n    *)     $as_echo \"$as_me: WARNING: unrecognized options: $ac_unrecognized_opts\" >&2 ;;\n  esac\nfi\n\n# Check all directory arguments for consistency.\nfor ac_var in\texec_prefix prefix bindir sbindir libexecdir datarootdir \\\n\t\tdatadir sysconfdir sharedstatedir localstatedir includedir \\\n\t\toldincludedir docdir infodir htmldir dvidir pdfdir psdir \\\n\t\tlibdir localedir mandir\ndo\n  eval ac_val=\\$$ac_var\n  # Remove trailing slashes.\n  case $ac_val in\n    */ )\n      ac_val=`expr \"X$ac_val\" : 'X\\(.*[^/]\\)' \\| \"X$ac_val\" : 'X\\(.*\\)'`\n      eval $ac_var=\\$ac_val;;\n  esac\n  # Be sure to have absolute directory names.\n  case $ac_val in\n    [\\\\/$]* | ?:[\\\\/]* )  continue;;\n    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;\n  esac\n  as_fn_error \"expected an absolute directory name for --$ac_var: $ac_val\"\ndone\n\n# There might be people who depend on the old broken behavior: `$host'\n# used to hold the argument of --host etc.\n# FIXME: To remove some day.\nbuild=$build_alias\nhost=$host_alias\ntarget=$target_alias\n\n# FIXME: To remove some day.\nif test \"x$host_alias\" != x; then\n  if test \"x$build_alias\" = x; then\n    cross_compiling=maybe\n    $as_echo \"$as_me: WARNING: If you wanted to set the --build type, don't use --host.\n    If a cross compiler is detected then cross compile mode will be used.\" >&2\n  elif test \"x$build_alias\" != \"x$host_alias\"; then\n    cross_compiling=yes\n  fi\nfi\n\nac_tool_prefix=\ntest -n \"$host_alias\" && ac_tool_prefix=$host_alias-\n\ntest \"$silent\" = yes && exec 6>/dev/null\n\n\nac_pwd=`pwd` && test -n \"$ac_pwd\" &&\nac_ls_di=`ls -di .` &&\nac_pwd_ls_di=`cd \"$ac_pwd\" && ls -di .` ||\n  as_fn_error \"working directory cannot be determined\"\ntest \"X$ac_ls_di\" = \"X$ac_pwd_ls_di\" ||\n  as_fn_error \"pwd does not report name of working directory\"\n\n\n# Find the source files, if location was not specified.\nif test -z \"$srcdir\"; then\n  ac_srcdir_defaulted=yes\n  # Try the directory containing this script, then the parent directory.\n  ac_confdir=`$as_dirname -- \"$as_myself\" ||\n$as_expr X\"$as_myself\" : 'X\\(.*[^/]\\)//*[^/][^/]*/*$' \\| \\\n\t X\"$as_myself\" : 'X\\(//\\)[^/]' \\| \\\n\t X\"$as_myself\" : 'X\\(//\\)$' \\| \\\n\t X\"$as_myself\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X\"$as_myself\" |\n    sed '/^X\\(.*[^/]\\)\\/\\/*[^/][^/]*\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)[^/].*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n  srcdir=$ac_confdir\n  if test ! -r \"$srcdir/$ac_unique_file\"; then\n    srcdir=..\n  fi\nelse\n  ac_srcdir_defaulted=no\nfi\nif test ! -r \"$srcdir/$ac_unique_file\"; then\n  test \"$ac_srcdir_defaulted\" = yes && srcdir=\"$ac_confdir or ..\"\n  as_fn_error \"cannot find sources ($ac_unique_file) in $srcdir\"\nfi\nac_msg=\"sources are in $srcdir, but \\`cd $srcdir' does not work\"\nac_abs_confdir=`(\n\tcd \"$srcdir\" && test -r \"./$ac_unique_file\" || as_fn_error \"$ac_msg\"\n\tpwd)`\n# When building in place, set srcdir=.\nif test \"$ac_abs_confdir\" = \"$ac_pwd\"; then\n  srcdir=.\nfi\n# Remove unnecessary trailing slashes from srcdir.\n# Double slashes in file names in object file debugging info\n# mess up M-x gdb in Emacs.\ncase $srcdir in\n*/) srcdir=`expr \"X$srcdir\" : 'X\\(.*[^/]\\)' \\| \"X$srcdir\" : 'X\\(.*\\)'`;;\nesac\nfor ac_var in $ac_precious_vars; do\n  eval ac_env_${ac_var}_set=\\${${ac_var}+set}\n  eval ac_env_${ac_var}_value=\\$${ac_var}\n  eval ac_cv_env_${ac_var}_set=\\${${ac_var}+set}\n  eval ac_cv_env_${ac_var}_value=\\$${ac_var}\ndone\n\n#\n# Report the --help message.\n#\nif test \"$ac_init_help\" = \"long\"; then\n  # Omit some internal or obsolete options to make the list less imposing.\n  # This message is too long to be a string in the A/UX 3.1 sh.\n  cat <<_ACEOF\n\\`configure' configures binwalk 0.4.1 to adapt to many kinds of systems.\n\nUsage: $0 [OPTION]... [VAR=VALUE]...\n\nTo assign environment variables (e.g., CC, CFLAGS...), specify them as\nVAR=VALUE.  See below for descriptions of some of the useful variables.\n\nDefaults for the options are specified in brackets.\n\nConfiguration:\n  -h, --help              display this help and exit\n      --help=short        display options specific to this package\n      --help=recursive    display the short help of all the included packages\n  -V, --version           display version information and exit\n  -q, --quiet, --silent   do not print \\`checking...' messages\n      --cache-file=FILE   cache test results in FILE [disabled]\n  -C, --config-cache      alias for \\`--cache-file=config.cache'\n  -n, --no-create         do not create output files\n      --srcdir=DIR        find the sources in DIR [configure dir or \\`..']\n\nInstallation directories:\n  --prefix=PREFIX         install architecture-independent files in PREFIX\n                          [$ac_default_prefix]\n  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX\n                          [PREFIX]\n\nBy default, \\`make install' will install all the files in\n\\`$ac_default_prefix/bin', \\`$ac_default_prefix/lib' etc.  You can specify\nan installation prefix other than \\`$ac_default_prefix' using \\`--prefix',\nfor instance \\`--prefix=\\$HOME'.\n\nFor better control, use the options below.\n\nFine tuning of the installation directories:\n  --bindir=DIR            user executables [EPREFIX/bin]\n  --sbindir=DIR           system admin executables [EPREFIX/sbin]\n  --libexecdir=DIR        program executables [EPREFIX/libexec]\n  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]\n  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]\n  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]\n  --libdir=DIR            object code libraries [EPREFIX/lib]\n  --includedir=DIR        C header files [PREFIX/include]\n  --oldincludedir=DIR     C header files for non-gcc [/usr/include]\n  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]\n  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]\n  --infodir=DIR           info documentation [DATAROOTDIR/info]\n  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]\n  --mandir=DIR            man documentation [DATAROOTDIR/man]\n  --docdir=DIR            documentation root [DATAROOTDIR/doc/binwalk]\n  --htmldir=DIR           html documentation [DOCDIR]\n  --dvidir=DIR            dvi documentation [DOCDIR]\n  --pdfdir=DIR            pdf documentation [DOCDIR]\n  --psdir=DIR             ps documentation [DOCDIR]\n_ACEOF\n\n  cat <<\\_ACEOF\n_ACEOF\nfi\n\nif test -n \"$ac_init_help\"; then\n  case $ac_init_help in\n     short | recursive ) echo \"Configuration of binwalk 0.4.1:\";;\n   esac\n  cat <<\\_ACEOF\n\nOptional Features:\n  --disable-option-checking  ignore unrecognized --enable/--with options\n  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)\n  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]\n  --enable-static         perform static build\n  --enable-libmagic       build against libmagic\n  --disable-updates       disable update features that rely on libcurl\n\nSome influential environment variables:\n  CC          C compiler command\n  CFLAGS      C compiler flags\n  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a\n              nonstandard directory <lib dir>\n  LIBS        libraries to pass to the linker, e.g. -l<library>\n  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if\n              you have headers in a nonstandard directory <include dir>\n  CPP         C preprocessor\n\nUse these variables to override the choices made by `configure' or to help\nit to find libraries and programs with nonstandard names/locations.\n\nReport bugs to <http://code.google.com/p/binwalk/issues/list>.\n_ACEOF\nac_status=$?\nfi\n\nif test \"$ac_init_help\" = \"recursive\"; then\n  # If there are subdirs, report their specific --help.\n  for ac_dir in : $ac_subdirs_all; do test \"x$ac_dir\" = x: && continue\n    test -d \"$ac_dir\" ||\n      { cd \"$srcdir\" && ac_pwd=`pwd` && srcdir=. && test -d \"$ac_dir\"; } ||\n      continue\n    ac_builddir=.\n\ncase \"$ac_dir\" in\n.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;\n*)\n  ac_dir_suffix=/`$as_echo \"$ac_dir\" | sed 's|^\\.[\\\\/]||'`\n  # A \"..\" for each directory in $ac_dir_suffix.\n  ac_top_builddir_sub=`$as_echo \"$ac_dir_suffix\" | sed 's|/[^\\\\/]*|/..|g;s|/||'`\n  case $ac_top_builddir_sub in\n  \"\") ac_top_builddir_sub=. ac_top_build_prefix= ;;\n  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;\n  esac ;;\nesac\nac_abs_top_builddir=$ac_pwd\nac_abs_builddir=$ac_pwd$ac_dir_suffix\n# for backward compatibility:\nac_top_builddir=$ac_top_build_prefix\n\ncase $srcdir in\n  .)  # We are building in place.\n    ac_srcdir=.\n    ac_top_srcdir=$ac_top_builddir_sub\n    ac_abs_top_srcdir=$ac_pwd ;;\n  [\\\\/]* | ?:[\\\\/]* )  # Absolute name.\n    ac_srcdir=$srcdir$ac_dir_suffix;\n    ac_top_srcdir=$srcdir\n    ac_abs_top_srcdir=$srcdir ;;\n  *) # Relative name.\n    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix\n    ac_top_srcdir=$ac_top_build_prefix$srcdir\n    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;\nesac\nac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix\n\n    cd \"$ac_dir\" || { ac_status=$?; continue; }\n    # Check for guested configure.\n    if test -f \"$ac_srcdir/configure.gnu\"; then\n      echo &&\n      $SHELL \"$ac_srcdir/configure.gnu\" --help=recursive\n    elif test -f \"$ac_srcdir/configure\"; then\n      echo &&\n      $SHELL \"$ac_srcdir/configure\" --help=recursive\n    else\n      $as_echo \"$as_me: WARNING: no configuration information is in $ac_dir\" >&2\n    fi || ac_status=$?\n    cd \"$ac_pwd\" || { ac_status=$?; break; }\n  done\nfi\n\ntest -n \"$ac_init_help\" && exit $ac_status\nif $ac_init_version; then\n  cat <<\\_ACEOF\nbinwalk configure 0.4.1\ngenerated by GNU Autoconf 2.65\n\nCopyright (C) 2009 Free Software Foundation, Inc.\nThis configure script is free software; the Free Software Foundation\ngives unlimited permission to copy, distribute and modify it.\n_ACEOF\n  exit\nfi\n\n## ------------------------ ##\n## Autoconf initialization. ##\n## ------------------------ ##\n\n# ac_fn_c_try_compile LINENO\n# --------------------------\n# Try to compile conftest.$ac_ext, and return whether this succeeded.\nac_fn_c_try_compile ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  rm -f conftest.$ac_objext\n  if { { ac_try=\"$ac_compile\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_compile\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    grep -v '^ *+' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n    mv -f conftest.er1 conftest.err\n  fi\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; } && {\n\t test -z \"$ac_c_werror_flag\" ||\n\t test ! -s conftest.err\n       } && test -s conftest.$ac_objext; then :\n  ac_retval=0\nelse\n  $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n\tac_retval=1\nfi\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n  as_fn_set_status $ac_retval\n\n} # ac_fn_c_try_compile\n\n# ac_fn_c_check_type LINENO TYPE VAR INCLUDES\n# -------------------------------------------\n# Tests whether TYPE exists after having included INCLUDES, setting cache\n# variable VAR accordingly.\nac_fn_c_check_type ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  eval \"$3=no\"\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n$4\nint\nmain ()\n{\nif (sizeof ($2))\n\t return 0;\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n$4\nint\nmain ()\n{\nif (sizeof (($2)))\n\t    return 0;\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n\nelse\n  eval \"$3=yes\"\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n\n} # ac_fn_c_check_type\n\n# ac_fn_c_try_cpp LINENO\n# ----------------------\n# Try to preprocess conftest.$ac_ext, and return whether this succeeded.\nac_fn_c_try_cpp ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  if { { ac_try=\"$ac_cpp conftest.$ac_ext\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_cpp conftest.$ac_ext\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    grep -v '^ *+' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n    mv -f conftest.er1 conftest.err\n  fi\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; } >/dev/null && {\n\t test -z \"$ac_c_preproc_warn_flag$ac_c_werror_flag\" ||\n\t test ! -s conftest.err\n       }; then :\n  ac_retval=0\nelse\n  $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n    ac_retval=1\nfi\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n  as_fn_set_status $ac_retval\n\n} # ac_fn_c_try_cpp\n\n# ac_fn_c_try_run LINENO\n# ----------------------\n# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes\n# that executables *can* be run.\nac_fn_c_try_run ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  if { { ac_try=\"$ac_link\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'\n  { { case \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_try\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; }; then :\n  ac_retval=0\nelse\n  $as_echo \"$as_me: program exited with status $ac_status\" >&5\n       $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n       ac_retval=$ac_status\nfi\n  rm -rf conftest.dSYM conftest_ipa8_conftest.oo\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n  as_fn_set_status $ac_retval\n\n} # ac_fn_c_try_run\n\n# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES\n# -------------------------------------------------------\n# Tests whether HEADER exists and can be compiled using the include files in\n# INCLUDES, setting the cache variable VAR accordingly.\nac_fn_c_check_header_compile ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n$4\n#include <$2>\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  eval \"$3=yes\"\nelse\n  eval \"$3=no\"\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n\n} # ac_fn_c_check_header_compile\n\n# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES\n# -------------------------------------------------------\n# Tests whether HEADER exists, giving a warning if it cannot be compiled using\n# the include files in INCLUDES and setting the cache variable VAR\n# accordingly.\nac_fn_c_check_header_mongrel ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  if { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\nelse\n  # Is the header compilable?\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking $2 usability\" >&5\n$as_echo_n \"checking $2 usability... \" >&6; }\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n$4\n#include <$2>\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_header_compiler=yes\nelse\n  ac_header_compiler=no\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler\" >&5\n$as_echo \"$ac_header_compiler\" >&6; }\n\n# Is the header present?\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking $2 presence\" >&5\n$as_echo_n \"checking $2 presence... \" >&6; }\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <$2>\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n  ac_header_preproc=yes\nelse\n  ac_header_preproc=no\nfi\nrm -f conftest.err conftest.$ac_ext\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc\" >&5\n$as_echo \"$ac_header_preproc\" >&6; }\n\n# So?  What about this header?\ncase $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((\n  yes:no: )\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!\" >&5\n$as_echo \"$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result\" >&5\n$as_echo \"$as_me: WARNING: $2: proceeding with the compiler's result\" >&2;}\n    ;;\n  no:yes:* )\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled\" >&5\n$as_echo \"$as_me: WARNING: $2: present but cannot be compiled\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?\" >&5\n$as_echo \"$as_me: WARNING: $2:     check for missing prerequisite headers?\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation\" >&5\n$as_echo \"$as_me: WARNING: $2: see the Autoconf documentation\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \\\"Present But Cannot Be Compiled\\\"\" >&5\n$as_echo \"$as_me: WARNING: $2:     section \\\"Present But Cannot Be Compiled\\\"\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result\" >&5\n$as_echo \"$as_me: WARNING: $2: proceeding with the compiler's result\" >&2;}\n( cat <<\\_ASBOX\n## ----------------------------------------------------------- ##\n## Report this to http://code.google.com/p/binwalk/issues/list ##\n## ----------------------------------------------------------- ##\n_ASBOX\n     ) | sed \"s/^/$as_me: WARNING:     /\" >&2\n    ;;\nesac\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  eval \"$3=\\$ac_header_compiler\"\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\nfi\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n\n} # ac_fn_c_check_header_mongrel\n\n# ac_fn_c_try_link LINENO\n# -----------------------\n# Try to link conftest.$ac_ext, and return whether this succeeded.\nac_fn_c_try_link ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  rm -f conftest.$ac_objext conftest$ac_exeext\n  if { { ac_try=\"$ac_link\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    grep -v '^ *+' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n    mv -f conftest.er1 conftest.err\n  fi\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; } && {\n\t test -z \"$ac_c_werror_flag\" ||\n\t test ! -s conftest.err\n       } && test -s conftest$ac_exeext && {\n\t test \"$cross_compiling\" = yes ||\n\t $as_test_x conftest$ac_exeext\n       }; then :\n  ac_retval=0\nelse\n  $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n\tac_retval=1\nfi\n  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information\n  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would\n  # interfere with the next link command; also delete a directory that is\n  # left behind by Apple's compiler.  We do this before executing the actions.\n  rm -rf conftest.dSYM conftest_ipa8_conftest.oo\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n  as_fn_set_status $ac_retval\n\n} # ac_fn_c_try_link\n\n# ac_fn_c_check_func LINENO FUNC VAR\n# ----------------------------------\n# Tests whether FUNC exists, setting the cache variable VAR accordingly\nac_fn_c_check_func ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n/* Define $2 to an innocuous variant, in case <limits.h> declares $2.\n   For example, HP-UX 11i <limits.h> declares gettimeofday.  */\n#define $2 innocuous_$2\n\n/* System header to define __stub macros and hopefully few prototypes,\n    which can conflict with char $2 (); below.\n    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since\n    <limits.h> exists even on freestanding compilers.  */\n\n#ifdef __STDC__\n# include <limits.h>\n#else\n# include <assert.h>\n#endif\n\n#undef $2\n\n/* Override any GCC internal prototype to avoid an error.\n   Use char because int might match the return type of a GCC\n   builtin and then its argument prototype would still apply.  */\n#ifdef __cplusplus\nextern \"C\"\n#endif\nchar $2 ();\n/* The GNU C library defines this for functions which it implements\n    to always fail with ENOSYS.  Some functions are actually named\n    something starting with __ and the normal name is an alias.  */\n#if defined __stub_$2 || defined __stub___$2\nchoke me\n#endif\n\nint\nmain ()\n{\nreturn $2 ();\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_link \"$LINENO\"; then :\n  eval \"$3=yes\"\nelse\n  eval \"$3=no\"\nfi\nrm -f core conftest.err conftest.$ac_objext \\\n    conftest$ac_exeext conftest.$ac_ext\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n\n} # ac_fn_c_check_func\ncat >config.log <<_ACEOF\nThis file contains any messages produced by compilers while\nrunning configure, to aid debugging if configure makes a mistake.\n\nIt was created by binwalk $as_me 0.4.1, which was\ngenerated by GNU Autoconf 2.65.  Invocation command line was\n\n  $ $0 $@\n\n_ACEOF\nexec 5>>config.log\n{\ncat <<_ASUNAME\n## --------- ##\n## Platform. ##\n## --------- ##\n\nhostname = `(hostname || uname -n) 2>/dev/null | sed 1q`\nuname -m = `(uname -m) 2>/dev/null || echo unknown`\nuname -r = `(uname -r) 2>/dev/null || echo unknown`\nuname -s = `(uname -s) 2>/dev/null || echo unknown`\nuname -v = `(uname -v) 2>/dev/null || echo unknown`\n\n/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`\n/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`\n\n/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`\n/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`\n/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`\n/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`\n/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`\n/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`\n/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`\n\n_ASUNAME\n\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    $as_echo \"PATH: $as_dir\"\n  done\nIFS=$as_save_IFS\n\n} >&5\n\ncat >&5 <<_ACEOF\n\n\n## ----------- ##\n## Core tests. ##\n## ----------- ##\n\n_ACEOF\n\n\n# Keep a trace of the command line.\n# Strip out --no-create and --no-recursion so they do not pile up.\n# Strip out --silent because we don't want to record it for future runs.\n# Also quote any args containing shell meta-characters.\n# Make two passes to allow for proper duplicate-argument suppression.\nac_configure_args=\nac_configure_args0=\nac_configure_args1=\nac_must_keep_next=false\nfor ac_pass in 1 2\ndo\n  for ac_arg\n  do\n    case $ac_arg in\n    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;\n    -q | -quiet | --quiet | --quie | --qui | --qu | --q \\\n    | -silent | --silent | --silen | --sile | --sil)\n      continue ;;\n    *\\'*)\n      ac_arg=`$as_echo \"$ac_arg\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"` ;;\n    esac\n    case $ac_pass in\n    1) as_fn_append ac_configure_args0 \" '$ac_arg'\" ;;\n    2)\n      as_fn_append ac_configure_args1 \" '$ac_arg'\"\n      if test $ac_must_keep_next = true; then\n\tac_must_keep_next=false # Got value, back to normal.\n      else\n\tcase $ac_arg in\n\t  *=* | --config-cache | -C | -disable-* | --disable-* \\\n\t  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \\\n\t  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \\\n\t  | -with-* | --with-* | -without-* | --without-* | --x)\n\t    case \"$ac_configure_args0 \" in\n\t      \"$ac_configure_args1\"*\" '$ac_arg' \"* ) continue ;;\n\t    esac\n\t    ;;\n\t  -* ) ac_must_keep_next=true ;;\n\tesac\n      fi\n      as_fn_append ac_configure_args \" '$ac_arg'\"\n      ;;\n    esac\n  done\ndone\n{ ac_configure_args0=; unset ac_configure_args0;}\n{ ac_configure_args1=; unset ac_configure_args1;}\n\n# When interrupted or exit'd, cleanup temporary files, and complete\n# config.log.  We remove comments because anyway the quotes in there\n# would cause problems or look ugly.\n# WARNING: Use '\\'' to represent an apostrophe within the trap.\n# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.\ntrap 'exit_status=$?\n  # Save into config.log some information that might help in debugging.\n  {\n    echo\n\n    cat <<\\_ASBOX\n## ---------------- ##\n## Cache variables. ##\n## ---------------- ##\n_ASBOX\n    echo\n    # The following way of writing the cache mishandles newlines in values,\n(\n  for ac_var in `(set) 2>&1 | sed -n '\\''s/^\\([a-zA-Z_][a-zA-Z0-9_]*\\)=.*/\\1/p'\\''`; do\n    eval ac_val=\\$$ac_var\n    case $ac_val in #(\n    *${as_nl}*)\n      case $ac_var in #(\n      *_cv_*) { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline\" >&5\n$as_echo \"$as_me: WARNING: cache variable $ac_var contains a newline\" >&2;} ;;\n      esac\n      case $ac_var in #(\n      _ | IFS | as_nl) ;; #(\n      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(\n      *) { eval $ac_var=; unset $ac_var;} ;;\n      esac ;;\n    esac\n  done\n  (set) 2>&1 |\n    case $as_nl`(ac_space='\\'' '\\''; set) 2>&1` in #(\n    *${as_nl}ac_space=\\ *)\n      sed -n \\\n\t\"s/'\\''/'\\''\\\\\\\\'\\'''\\''/g;\n\t  s/^\\\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\\\)=\\\\(.*\\\\)/\\\\1='\\''\\\\2'\\''/p\"\n      ;; #(\n    *)\n      sed -n \"/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p\"\n      ;;\n    esac |\n    sort\n)\n    echo\n\n    cat <<\\_ASBOX\n## ----------------- ##\n## Output variables. ##\n## ----------------- ##\n_ASBOX\n    echo\n    for ac_var in $ac_subst_vars\n    do\n      eval ac_val=\\$$ac_var\n      case $ac_val in\n      *\\'\\''*) ac_val=`$as_echo \"$ac_val\" | sed \"s/'\\''/'\\''\\\\\\\\\\\\\\\\'\\'''\\''/g\"`;;\n      esac\n      $as_echo \"$ac_var='\\''$ac_val'\\''\"\n    done | sort\n    echo\n\n    if test -n \"$ac_subst_files\"; then\n      cat <<\\_ASBOX\n## ------------------- ##\n## File substitutions. ##\n## ------------------- ##\n_ASBOX\n      echo\n      for ac_var in $ac_subst_files\n      do\n\teval ac_val=\\$$ac_var\n\tcase $ac_val in\n\t*\\'\\''*) ac_val=`$as_echo \"$ac_val\" | sed \"s/'\\''/'\\''\\\\\\\\\\\\\\\\'\\'''\\''/g\"`;;\n\tesac\n\t$as_echo \"$ac_var='\\''$ac_val'\\''\"\n      done | sort\n      echo\n    fi\n\n    if test -s confdefs.h; then\n      cat <<\\_ASBOX\n## ----------- ##\n## confdefs.h. ##\n## ----------- ##\n_ASBOX\n      echo\n      cat confdefs.h\n      echo\n    fi\n    test \"$ac_signal\" != 0 &&\n      $as_echo \"$as_me: caught signal $ac_signal\"\n    $as_echo \"$as_me: exit $exit_status\"\n  } >&5\n  rm -f core *.core core.conftest.* &&\n    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&\n    exit $exit_status\n' 0\nfor ac_signal in 1 2 13 15; do\n  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal\ndone\nac_signal=0\n\n# confdefs.h avoids OS command line length limits that DEFS can exceed.\nrm -f -r conftest* confdefs.h\n\n$as_echo \"/* confdefs.h */\" > confdefs.h\n\n# Predefined preprocessor variables.\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_NAME \"$PACKAGE_NAME\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_VERSION \"$PACKAGE_VERSION\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_STRING \"$PACKAGE_STRING\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_URL \"$PACKAGE_URL\"\n_ACEOF\n\n\n# Let the site file select an alternate cache file if it wants to.\n# Prefer an explicitly selected file to automatically selected ones.\nac_site_file1=NONE\nac_site_file2=NONE\nif test -n \"$CONFIG_SITE\"; then\n  ac_site_file1=$CONFIG_SITE\nelif test \"x$prefix\" != xNONE; then\n  ac_site_file1=$prefix/share/config.site\n  ac_site_file2=$prefix/etc/config.site\nelse\n  ac_site_file1=$ac_default_prefix/share/config.site\n  ac_site_file2=$ac_default_prefix/etc/config.site\nfi\nfor ac_site_file in \"$ac_site_file1\" \"$ac_site_file2\"\ndo\n  test \"x$ac_site_file\" = xNONE && continue\n  if test /dev/null != \"$ac_site_file\" && test -r \"$ac_site_file\"; then\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file\" >&5\n$as_echo \"$as_me: loading site script $ac_site_file\" >&6;}\n    sed 's/^/| /' \"$ac_site_file\" >&5\n    . \"$ac_site_file\"\n  fi\ndone\n\nif test -r \"$cache_file\"; then\n  # Some versions of bash will fail to source /dev/null (special files\n  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.\n  if test /dev/null != \"$cache_file\" && test -f \"$cache_file\"; then\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: loading cache $cache_file\" >&5\n$as_echo \"$as_me: loading cache $cache_file\" >&6;}\n    case $cache_file in\n      [\\\\/]* | ?:[\\\\/]* ) . \"$cache_file\";;\n      *)                      . \"./$cache_file\";;\n    esac\n  fi\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: creating cache $cache_file\" >&5\n$as_echo \"$as_me: creating cache $cache_file\" >&6;}\n  >$cache_file\nfi\n\n# Check that the precious variables saved in the cache have kept the same\n# value.\nac_cache_corrupted=false\nfor ac_var in $ac_precious_vars; do\n  eval ac_old_set=\\$ac_cv_env_${ac_var}_set\n  eval ac_new_set=\\$ac_env_${ac_var}_set\n  eval ac_old_val=\\$ac_cv_env_${ac_var}_value\n  eval ac_new_val=\\$ac_env_${ac_var}_value\n  case $ac_old_set,$ac_new_set in\n    set,)\n      { $as_echo \"$as_me:${as_lineno-$LINENO}: error: \\`$ac_var' was set to \\`$ac_old_val' in the previous run\" >&5\n$as_echo \"$as_me: error: \\`$ac_var' was set to \\`$ac_old_val' in the previous run\" >&2;}\n      ac_cache_corrupted=: ;;\n    ,set)\n      { $as_echo \"$as_me:${as_lineno-$LINENO}: error: \\`$ac_var' was not set in the previous run\" >&5\n$as_echo \"$as_me: error: \\`$ac_var' was not set in the previous run\" >&2;}\n      ac_cache_corrupted=: ;;\n    ,);;\n    *)\n      if test \"x$ac_old_val\" != \"x$ac_new_val\"; then\n\t# differences in whitespace do not lead to failure.\n\tac_old_val_w=`echo x $ac_old_val`\n\tac_new_val_w=`echo x $ac_new_val`\n\tif test \"$ac_old_val_w\" != \"$ac_new_val_w\"; then\n\t  { $as_echo \"$as_me:${as_lineno-$LINENO}: error: \\`$ac_var' has changed since the previous run:\" >&5\n$as_echo \"$as_me: error: \\`$ac_var' has changed since the previous run:\" >&2;}\n\t  ac_cache_corrupted=:\n\telse\n\t  { $as_echo \"$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \\`$ac_var' since the previous run:\" >&5\n$as_echo \"$as_me: warning: ignoring whitespace changes in \\`$ac_var' since the previous run:\" >&2;}\n\t  eval $ac_var=\\$ac_old_val\n\tfi\n\t{ $as_echo \"$as_me:${as_lineno-$LINENO}:   former value:  \\`$ac_old_val'\" >&5\n$as_echo \"$as_me:   former value:  \\`$ac_old_val'\" >&2;}\n\t{ $as_echo \"$as_me:${as_lineno-$LINENO}:   current value: \\`$ac_new_val'\" >&5\n$as_echo \"$as_me:   current value: \\`$ac_new_val'\" >&2;}\n      fi;;\n  esac\n  # Pass precious variables to config.status.\n  if test \"$ac_new_set\" = set; then\n    case $ac_new_val in\n    *\\'*) ac_arg=$ac_var=`$as_echo \"$ac_new_val\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"` ;;\n    *) ac_arg=$ac_var=$ac_new_val ;;\n    esac\n    case \" $ac_configure_args \" in\n      *\" '$ac_arg' \"*) ;; # Avoid dups.  Use of quotes ensures accuracy.\n      *) as_fn_append ac_configure_args \" '$ac_arg'\" ;;\n    esac\n  fi\ndone\nif $ac_cache_corrupted; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build\" >&5\n$as_echo \"$as_me: error: changes in the environment can compromise the build\" >&2;}\n  as_fn_error \"run \\`make distclean' and/or \\`rm $cache_file' and start over\" \"$LINENO\" 5\nfi\n## -------------------- ##\n## Main body of script. ##\n## -------------------- ##\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n\n\n\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\nif test -n \"$ac_tool_prefix\"; then\n  # Extract the first word of \"${ac_tool_prefix}gcc\", so it can be a program name with args.\nset dummy ${ac_tool_prefix}gcc; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$CC\"; then\n  ac_cv_prog_CC=\"$CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_CC=\"${ac_tool_prefix}gcc\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nCC=$ac_cv_prog_CC\nif test -n \"$CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CC\" >&5\n$as_echo \"$CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\nfi\nif test -z \"$ac_cv_prog_CC\"; then\n  ac_ct_CC=$CC\n  # Extract the first word of \"gcc\", so it can be a program name with args.\nset dummy gcc; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_ac_ct_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$ac_ct_CC\"; then\n  ac_cv_prog_ac_ct_CC=\"$ac_ct_CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_ac_ct_CC=\"gcc\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nac_ct_CC=$ac_cv_prog_ac_ct_CC\nif test -n \"$ac_ct_CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC\" >&5\n$as_echo \"$ac_ct_CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n  if test \"x$ac_ct_CC\" = x; then\n    CC=\"\"\n  else\n    case $cross_compiling:$ac_tool_warned in\nyes:)\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet\" >&5\n$as_echo \"$as_me: WARNING: using cross tools not prefixed with host triplet\" >&2;}\nac_tool_warned=yes ;;\nesac\n    CC=$ac_ct_CC\n  fi\nelse\n  CC=\"$ac_cv_prog_CC\"\nfi\n\nif test -z \"$CC\"; then\n          if test -n \"$ac_tool_prefix\"; then\n    # Extract the first word of \"${ac_tool_prefix}cc\", so it can be a program name with args.\nset dummy ${ac_tool_prefix}cc; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$CC\"; then\n  ac_cv_prog_CC=\"$CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_CC=\"${ac_tool_prefix}cc\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nCC=$ac_cv_prog_CC\nif test -n \"$CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CC\" >&5\n$as_echo \"$CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\n  fi\nfi\nif test -z \"$CC\"; then\n  # Extract the first word of \"cc\", so it can be a program name with args.\nset dummy cc; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$CC\"; then\n  ac_cv_prog_CC=\"$CC\" # Let the user override the test.\nelse\n  ac_prog_rejected=no\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    if test \"$as_dir/$ac_word$ac_exec_ext\" = \"/usr/ucb/cc\"; then\n       ac_prog_rejected=yes\n       continue\n     fi\n    ac_cv_prog_CC=\"cc\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nif test $ac_prog_rejected = yes; then\n  # We found a bogon in the path, so make sure we never use it.\n  set dummy $ac_cv_prog_CC\n  shift\n  if test $# != 0; then\n    # We chose a different compiler from the bogus one.\n    # However, it has the same basename, so the bogon will be chosen\n    # first if we set CC to just the basename; use the full file name.\n    shift\n    ac_cv_prog_CC=\"$as_dir/$ac_word${1+' '}$@\"\n  fi\nfi\nfi\nfi\nCC=$ac_cv_prog_CC\nif test -n \"$CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CC\" >&5\n$as_echo \"$CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\nfi\nif test -z \"$CC\"; then\n  if test -n \"$ac_tool_prefix\"; then\n  for ac_prog in cl.exe\n  do\n    # Extract the first word of \"$ac_tool_prefix$ac_prog\", so it can be a program name with args.\nset dummy $ac_tool_prefix$ac_prog; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$CC\"; then\n  ac_cv_prog_CC=\"$CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_CC=\"$ac_tool_prefix$ac_prog\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nCC=$ac_cv_prog_CC\nif test -n \"$CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CC\" >&5\n$as_echo \"$CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\n    test -n \"$CC\" && break\n  done\nfi\nif test -z \"$CC\"; then\n  ac_ct_CC=$CC\n  for ac_prog in cl.exe\ndo\n  # Extract the first word of \"$ac_prog\", so it can be a program name with args.\nset dummy $ac_prog; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_ac_ct_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$ac_ct_CC\"; then\n  ac_cv_prog_ac_ct_CC=\"$ac_ct_CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_ac_ct_CC=\"$ac_prog\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nac_ct_CC=$ac_cv_prog_ac_ct_CC\nif test -n \"$ac_ct_CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC\" >&5\n$as_echo \"$ac_ct_CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\n  test -n \"$ac_ct_CC\" && break\ndone\n\n  if test \"x$ac_ct_CC\" = x; then\n    CC=\"\"\n  else\n    case $cross_compiling:$ac_tool_warned in\nyes:)\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet\" >&5\n$as_echo \"$as_me: WARNING: using cross tools not prefixed with host triplet\" >&2;}\nac_tool_warned=yes ;;\nesac\n    CC=$ac_ct_CC\n  fi\nfi\n\nfi\n\n\ntest -z \"$CC\" && { { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"no acceptable C compiler found in \\$PATH\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\n\n# Provide some information about the compiler.\n$as_echo \"$as_me:${as_lineno-$LINENO}: checking for C compiler version\" >&5\nset X $ac_compile\nac_compiler=$2\nfor ac_option in --version -v -V -qversion; do\n  { { ac_try=\"$ac_compiler $ac_option >&5\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_compiler $ac_option >&5\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    sed '10a\\\n... rest of stderr output deleted ...\n         10q' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n  fi\n  rm -f conftest.er1 conftest.err\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }\ndone\n\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nac_clean_files_save=$ac_clean_files\nac_clean_files=\"$ac_clean_files a.out a.out.dSYM a.exe b.out\"\n# Try to create an executable without -o first, disregard a.out.\n# It will help us diagnose broken compilers, and finding out an intuition\n# of exeext.\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether the C compiler works\" >&5\n$as_echo_n \"checking whether the C compiler works... \" >&6; }\nac_link_default=`$as_echo \"$ac_link\" | sed 's/ -o *conftest[^ ]*//'`\n\n# The possible output files:\nac_files=\"a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*\"\n\nac_rmfiles=\nfor ac_file in $ac_files\ndo\n  case $ac_file in\n    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;\n    * ) ac_rmfiles=\"$ac_rmfiles $ac_file\";;\n  esac\ndone\nrm -f $ac_rmfiles\n\nif { { ac_try=\"$ac_link_default\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link_default\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; then :\n  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.\n# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'\n# in a Makefile.  We should not override ac_cv_exeext if it was cached,\n# so that the user can short-circuit this test for compilers unknown to\n# Autoconf.\nfor ac_file in $ac_files ''\ndo\n  test -f \"$ac_file\" || continue\n  case $ac_file in\n    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )\n\t;;\n    [ab].out )\n\t# We found the default executable, but exeext='' is most\n\t# certainly right.\n\tbreak;;\n    *.* )\n\tif test \"${ac_cv_exeext+set}\" = set && test \"$ac_cv_exeext\" != no;\n\tthen :; else\n\t   ac_cv_exeext=`expr \"$ac_file\" : '[^.]*\\(\\..*\\)'`\n\tfi\n\t# We set ac_cv_exeext here because the later test for it is not\n\t# safe: cross compilers may not add the suffix if given an `-o'\n\t# argument, so we may need to know it at that point already.\n\t# Even if this section looks crufty: it has the advantage of\n\t# actually working.\n\tbreak;;\n    * )\n\tbreak;;\n  esac\ndone\ntest \"$ac_cv_exeext\" = no && ac_cv_exeext=\n\nelse\n  ac_file=''\nfi\nif test -z \"$ac_file\"; then :\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\n$as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n{ { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\n{ as_fn_set_status 77\nas_fn_error \"C compiler cannot create executables\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: yes\" >&5\n$as_echo \"yes\" >&6; }\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name\" >&5\n$as_echo_n \"checking for C compiler default output file name... \" >&6; }\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_file\" >&5\n$as_echo \"$ac_file\" >&6; }\nac_exeext=$ac_cv_exeext\n\nrm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out\nac_clean_files=$ac_clean_files_save\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for suffix of executables\" >&5\n$as_echo_n \"checking for suffix of executables... \" >&6; }\nif { { ac_try=\"$ac_link\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; then :\n  # If both `conftest.exe' and `conftest' are `present' (well, observable)\n# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will\n# work properly (i.e., refer to `conftest.exe'), while it won't with\n# `rm'.\nfor ac_file in conftest.exe conftest conftest.*; do\n  test -f \"$ac_file\" || continue\n  case $ac_file in\n    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;\n    *.* ) ac_cv_exeext=`expr \"$ac_file\" : '[^.]*\\(\\..*\\)'`\n\t  break;;\n    * ) break;;\n  esac\ndone\nelse\n  { { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"cannot compute suffix of executables: cannot compile and link\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\nfi\nrm -f conftest conftest$ac_cv_exeext\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext\" >&5\n$as_echo \"$ac_cv_exeext\" >&6; }\n\nrm -f conftest.$ac_ext\nEXEEXT=$ac_cv_exeext\nac_exeext=$EXEEXT\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <stdio.h>\nint\nmain ()\n{\nFILE *f = fopen (\"conftest.out\", \"w\");\n return ferror (f) || fclose (f) != 0;\n\n  ;\n  return 0;\n}\n_ACEOF\nac_clean_files=\"$ac_clean_files conftest.out\"\n# Check that the compiler produces executables we can run.  If not, either\n# the compiler is broken, or we cross compile.\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling\" >&5\n$as_echo_n \"checking whether we are cross compiling... \" >&6; }\nif test \"$cross_compiling\" != yes; then\n  { { ac_try=\"$ac_link\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }\n  if { ac_try='./conftest$ac_cv_exeext'\n  { { case \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_try\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; }; then\n    cross_compiling=no\n  else\n    if test \"$cross_compiling\" = maybe; then\n\tcross_compiling=yes\n    else\n\t{ { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"cannot run C compiled programs.\nIf you meant to cross compile, use \\`--host'.\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\n    fi\n  fi\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $cross_compiling\" >&5\n$as_echo \"$cross_compiling\" >&6; }\n\nrm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out\nac_clean_files=$ac_clean_files_save\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for suffix of object files\" >&5\n$as_echo_n \"checking for suffix of object files... \" >&6; }\nif test \"${ac_cv_objext+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nrm -f conftest.o conftest.obj\nif { { ac_try=\"$ac_compile\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_compile\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; then :\n  for ac_file in conftest.o conftest.obj conftest.*; do\n  test -f \"$ac_file\" || continue;\n  case $ac_file in\n    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;\n    *) ac_cv_objext=`expr \"$ac_file\" : '.*\\.\\(.*\\)'`\n       break;;\n  esac\ndone\nelse\n  $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n{ { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"cannot compute suffix of object files: cannot compile\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\nfi\nrm -f conftest.$ac_cv_objext conftest.$ac_ext\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext\" >&5\n$as_echo \"$ac_cv_objext\" >&6; }\nOBJEXT=$ac_cv_objext\nac_objext=$OBJEXT\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler\" >&5\n$as_echo_n \"checking whether we are using the GNU C compiler... \" >&6; }\nif test \"${ac_cv_c_compiler_gnu+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n#ifndef __GNUC__\n       choke me\n#endif\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_compiler_gnu=yes\nelse\n  ac_compiler_gnu=no\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nac_cv_c_compiler_gnu=$ac_compiler_gnu\n\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu\" >&5\n$as_echo \"$ac_cv_c_compiler_gnu\" >&6; }\nif test $ac_compiler_gnu = yes; then\n  GCC=yes\nelse\n  GCC=\nfi\nac_test_CFLAGS=${CFLAGS+set}\nac_save_CFLAGS=$CFLAGS\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g\" >&5\n$as_echo_n \"checking whether $CC accepts -g... \" >&6; }\nif test \"${ac_cv_prog_cc_g+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  ac_save_c_werror_flag=$ac_c_werror_flag\n   ac_c_werror_flag=yes\n   ac_cv_prog_cc_g=no\n   CFLAGS=\"-g\"\n   cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_cv_prog_cc_g=yes\nelse\n  CFLAGS=\"\"\n      cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n\nelse\n  ac_c_werror_flag=$ac_save_c_werror_flag\n\t CFLAGS=\"-g\"\n\t cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_cv_prog_cc_g=yes\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\n   ac_c_werror_flag=$ac_save_c_werror_flag\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g\" >&5\n$as_echo \"$ac_cv_prog_cc_g\" >&6; }\nif test \"$ac_test_CFLAGS\" = set; then\n  CFLAGS=$ac_save_CFLAGS\nelif test $ac_cv_prog_cc_g = yes; then\n  if test \"$GCC\" = yes; then\n    CFLAGS=\"-g -O2\"\n  else\n    CFLAGS=\"-g\"\n  fi\nelse\n  if test \"$GCC\" = yes; then\n    CFLAGS=\"-O2\"\n  else\n    CFLAGS=\n  fi\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89\" >&5\n$as_echo_n \"checking for $CC option to accept ISO C89... \" >&6; }\nif test \"${ac_cv_prog_cc_c89+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  ac_cv_prog_cc_c89=no\nac_save_CC=$CC\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <stdarg.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */\nstruct buf { int x; };\nFILE * (*rcsopen) (struct buf *, struct stat *, int);\nstatic char *e (p, i)\n     char **p;\n     int i;\n{\n  return p[i];\n}\nstatic char *f (char * (*g) (char **, int), char **p, ...)\n{\n  char *s;\n  va_list v;\n  va_start (v,p);\n  s = g (p, va_arg (v,int));\n  va_end (v);\n  return s;\n}\n\n/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has\n   function prototypes and stuff, but not '\\xHH' hex character constants.\n   These don't provoke an error unfortunately, instead are silently treated\n   as 'x'.  The following induces an error, until -std is added to get\n   proper ANSI mode.  Curiously '\\x00'!='x' always comes out true, for an\n   array size at least.  It's necessary to write '\\x00'==0 to get something\n   that's true only with -std.  */\nint osf4_cc_array ['\\x00' == 0 ? 1 : -1];\n\n/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters\n   inside strings and character constants.  */\n#define FOO(x) 'x'\nint xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];\n\nint test (int i, double x);\nstruct s1 {int (*f) (int a);};\nstruct s2 {int (*f) (double a);};\nint pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);\nint argc;\nchar **argv;\nint\nmain ()\n{\nreturn f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];\n  ;\n  return 0;\n}\n_ACEOF\nfor ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \\\n\t-Ae \"-Aa -D_HPUX_SOURCE\" \"-Xc -D__EXTENSIONS__\"\ndo\n  CC=\"$ac_save_CC $ac_arg\"\n  if ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_cv_prog_cc_c89=$ac_arg\nfi\nrm -f core conftest.err conftest.$ac_objext\n  test \"x$ac_cv_prog_cc_c89\" != \"xno\" && break\ndone\nrm -f conftest.$ac_ext\nCC=$ac_save_CC\n\nfi\n# AC_CACHE_VAL\ncase \"x$ac_cv_prog_cc_c89\" in\n  x)\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: result: none needed\" >&5\n$as_echo \"none needed\" >&6; } ;;\n  xno)\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: result: unsupported\" >&5\n$as_echo \"unsupported\" >&6; } ;;\n  *)\n    CC=\"$CC $ac_cv_prog_cc_c89\"\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89\" >&5\n$as_echo \"$ac_cv_prog_cc_c89\" >&6; } ;;\nesac\nif test \"x$ac_cv_prog_cc_c89\" != xno; then :\n\nfi\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n\n\nFILE=\"file-5.07\"\nCFLAGS=\"-Wall $CFLAGS\"\nLDFLAGS=\"-lz $LDFLAGS\"\n\n# Check whether --enable-static was given.\nif test \"${enable_static+set}\" = set; then :\n  enableval=$enable_static; STATIC=y\nelse\n  STATIC=n\nfi\n\n# Check whether --enable-libmagic was given.\nif test \"${enable_libmagic+set}\" = set; then :\n  enableval=$enable_libmagic; MAGIC=y\nelse\n  MAGIC=n\nfi\n\n# Check whether --enable-updates was given.\nif test \"${enable_updates+set}\" = set; then :\n  enableval=$enable_updates; CURL=n\nelse\n  CURL=y\nfi\n\n\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor\" >&5\n$as_echo_n \"checking how to run the C preprocessor... \" >&6; }\n# On Suns, sometimes $CPP names a directory.\nif test -n \"$CPP\" && test -d \"$CPP\"; then\n  CPP=\nfi\nif test -z \"$CPP\"; then\n  if test \"${ac_cv_prog_CPP+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n      # Double quotes because CPP needs to be expanded\n    for CPP in \"$CC -E\" \"$CC -E -traditional-cpp\" \"/lib/cpp\"\n    do\n      ac_preproc_ok=false\nfor ac_c_preproc_warn_flag in '' yes\ndo\n  # Use a header file that comes with gcc, so configuring glibc\n  # with a fresh cross-compiler works.\n  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since\n  # <limits.h> exists even on freestanding compilers.\n  # On the NeXT, cc -E runs the code through the compiler's parser,\n  # not just through cpp. \"Syntax error\" is here to catch this case.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#ifdef __STDC__\n# include <limits.h>\n#else\n# include <assert.h>\n#endif\n\t\t     Syntax error\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n\nelse\n  # Broken: fails on valid input.\ncontinue\nfi\nrm -f conftest.err conftest.$ac_ext\n\n  # OK, works on sane cases.  Now check whether nonexistent headers\n  # can be detected and how.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <ac_nonexistent.h>\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n  # Broken: success on invalid input.\ncontinue\nelse\n  # Passes both tests.\nac_preproc_ok=:\nbreak\nfi\nrm -f conftest.err conftest.$ac_ext\n\ndone\n# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.\nrm -f conftest.err conftest.$ac_ext\nif $ac_preproc_ok; then :\n  break\nfi\n\n    done\n    ac_cv_prog_CPP=$CPP\n\nfi\n  CPP=$ac_cv_prog_CPP\nelse\n  ac_cv_prog_CPP=$CPP\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CPP\" >&5\n$as_echo \"$CPP\" >&6; }\nac_preproc_ok=false\nfor ac_c_preproc_warn_flag in '' yes\ndo\n  # Use a header file that comes with gcc, so configuring glibc\n  # with a fresh cross-compiler works.\n  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since\n  # <limits.h> exists even on freestanding compilers.\n  # On the NeXT, cc -E runs the code through the compiler's parser,\n  # not just through cpp. \"Syntax error\" is here to catch this case.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#ifdef __STDC__\n# include <limits.h>\n#else\n# include <assert.h>\n#endif\n\t\t     Syntax error\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n\nelse\n  # Broken: fails on valid input.\ncontinue\nfi\nrm -f conftest.err conftest.$ac_ext\n\n  # OK, works on sane cases.  Now check whether nonexistent headers\n  # can be detected and how.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <ac_nonexistent.h>\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n  # Broken: success on invalid input.\ncontinue\nelse\n  # Passes both tests.\nac_preproc_ok=:\nbreak\nfi\nrm -f conftest.err conftest.$ac_ext\n\ndone\n# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.\nrm -f conftest.err conftest.$ac_ext\nif $ac_preproc_ok; then :\n\nelse\n  { { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"C preprocessor \\\"$CPP\\\" fails sanity check\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\nfi\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e\" >&5\n$as_echo_n \"checking for grep that handles long lines and -e... \" >&6; }\nif test \"${ac_cv_path_GREP+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -z \"$GREP\"; then\n  ac_path_GREP_found=false\n  # Loop through the user's path and test for each of PROGNAME-LIST\n  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_prog in grep ggrep; do\n    for ac_exec_ext in '' $ac_executable_extensions; do\n      ac_path_GREP=\"$as_dir/$ac_prog$ac_exec_ext\"\n      { test -f \"$ac_path_GREP\" && $as_test_x \"$ac_path_GREP\"; } || continue\n# Check for GNU ac_path_GREP and select it if it is found.\n  # Check for GNU $ac_path_GREP\ncase `\"$ac_path_GREP\" --version 2>&1` in\n*GNU*)\n  ac_cv_path_GREP=\"$ac_path_GREP\" ac_path_GREP_found=:;;\n*)\n  ac_count=0\n  $as_echo_n 0123456789 >\"conftest.in\"\n  while :\n  do\n    cat \"conftest.in\" \"conftest.in\" >\"conftest.tmp\"\n    mv \"conftest.tmp\" \"conftest.in\"\n    cp \"conftest.in\" \"conftest.nl\"\n    $as_echo 'GREP' >> \"conftest.nl\"\n    \"$ac_path_GREP\" -e 'GREP$' -e '-(cannot match)-' < \"conftest.nl\" >\"conftest.out\" 2>/dev/null || break\n    diff \"conftest.out\" \"conftest.nl\" >/dev/null 2>&1 || break\n    as_fn_arith $ac_count + 1 && ac_count=$as_val\n    if test $ac_count -gt ${ac_path_GREP_max-0}; then\n      # Best one so far, save it but keep looking for a better one\n      ac_cv_path_GREP=\"$ac_path_GREP\"\n      ac_path_GREP_max=$ac_count\n    fi\n    # 10*(2^10) chars as input seems more than enough\n    test $ac_count -gt 10 && break\n  done\n  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;\nesac\n\n      $ac_path_GREP_found && break 3\n    done\n  done\n  done\nIFS=$as_save_IFS\n  if test -z \"$ac_cv_path_GREP\"; then\n    as_fn_error \"no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin\" \"$LINENO\" 5\n  fi\nelse\n  ac_cv_path_GREP=$GREP\nfi\n\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP\" >&5\n$as_echo \"$ac_cv_path_GREP\" >&6; }\n GREP=\"$ac_cv_path_GREP\"\n\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for egrep\" >&5\n$as_echo_n \"checking for egrep... \" >&6; }\nif test \"${ac_cv_path_EGREP+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1\n   then ac_cv_path_EGREP=\"$GREP -E\"\n   else\n     if test -z \"$EGREP\"; then\n  ac_path_EGREP_found=false\n  # Loop through the user's path and test for each of PROGNAME-LIST\n  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_prog in egrep; do\n    for ac_exec_ext in '' $ac_executable_extensions; do\n      ac_path_EGREP=\"$as_dir/$ac_prog$ac_exec_ext\"\n      { test -f \"$ac_path_EGREP\" && $as_test_x \"$ac_path_EGREP\"; } || continue\n# Check for GNU ac_path_EGREP and select it if it is found.\n  # Check for GNU $ac_path_EGREP\ncase `\"$ac_path_EGREP\" --version 2>&1` in\n*GNU*)\n  ac_cv_path_EGREP=\"$ac_path_EGREP\" ac_path_EGREP_found=:;;\n*)\n  ac_count=0\n  $as_echo_n 0123456789 >\"conftest.in\"\n  while :\n  do\n    cat \"conftest.in\" \"conftest.in\" >\"conftest.tmp\"\n    mv \"conftest.tmp\" \"conftest.in\"\n    cp \"conftest.in\" \"conftest.nl\"\n    $as_echo 'EGREP' >> \"conftest.nl\"\n    \"$ac_path_EGREP\" 'EGREP$' < \"conftest.nl\" >\"conftest.out\" 2>/dev/null || break\n    diff \"conftest.out\" \"conftest.nl\" >/dev/null 2>&1 || break\n    as_fn_arith $ac_count + 1 && ac_count=$as_val\n    if test $ac_count -gt ${ac_path_EGREP_max-0}; then\n      # Best one so far, save it but keep looking for a better one\n      ac_cv_path_EGREP=\"$ac_path_EGREP\"\n      ac_path_EGREP_max=$ac_count\n    fi\n    # 10*(2^10) chars as input seems more than enough\n    test $ac_count -gt 10 && break\n  done\n  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;\nesac\n\n      $ac_path_EGREP_found && break 3\n    done\n  done\n  done\nIFS=$as_save_IFS\n  if test -z \"$ac_cv_path_EGREP\"; then\n    as_fn_error \"no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin\" \"$LINENO\" 5\n  fi\nelse\n  ac_cv_path_EGREP=$EGREP\nfi\n\n   fi\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP\" >&5\n$as_echo \"$ac_cv_path_EGREP\" >&6; }\n EGREP=\"$ac_cv_path_EGREP\"\n\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for ANSI C header files\" >&5\n$as_echo_n \"checking for ANSI C header files... \" >&6; }\nif test \"${ac_cv_header_stdc+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <stdlib.h>\n#include <stdarg.h>\n#include <string.h>\n#include <float.h>\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_cv_header_stdc=yes\nelse\n  ac_cv_header_stdc=no\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\n\nif test $ac_cv_header_stdc = yes; then\n  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <string.h>\n\n_ACEOF\nif (eval \"$ac_cpp conftest.$ac_ext\") 2>&5 |\n  $EGREP \"memchr\" >/dev/null 2>&1; then :\n\nelse\n  ac_cv_header_stdc=no\nfi\nrm -f conftest*\n\nfi\n\nif test $ac_cv_header_stdc = yes; then\n  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <stdlib.h>\n\n_ACEOF\nif (eval \"$ac_cpp conftest.$ac_ext\") 2>&5 |\n  $EGREP \"free\" >/dev/null 2>&1; then :\n\nelse\n  ac_cv_header_stdc=no\nfi\nrm -f conftest*\n\nfi\n\nif test $ac_cv_header_stdc = yes; then\n  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.\n  if test \"$cross_compiling\" = yes; then :\n  :\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <ctype.h>\n#include <stdlib.h>\n#if ((' ' & 0x0FF) == 0x020)\n# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')\n# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))\n#else\n# define ISLOWER(c) \\\n\t\t   (('a' <= (c) && (c) <= 'i') \\\n\t\t     || ('j' <= (c) && (c) <= 'r') \\\n\t\t     || ('s' <= (c) && (c) <= 'z'))\n# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))\n#endif\n\n#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))\nint\nmain ()\n{\n  int i;\n  for (i = 0; i < 256; i++)\n    if (XOR (islower (i), ISLOWER (i))\n\t|| toupper (i) != TOUPPER (i))\n      return 2;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_run \"$LINENO\"; then :\n\nelse\n  ac_cv_header_stdc=no\nfi\nrm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \\\n  conftest.$ac_objext conftest.beam conftest.$ac_ext\nfi\n\nfi\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc\" >&5\n$as_echo \"$ac_cv_header_stdc\" >&6; }\nif test $ac_cv_header_stdc = yes; then\n\n$as_echo \"#define STDC_HEADERS 1\" >>confdefs.h\n\nfi\n\n# On IRIX 5.3, sys/types and inttypes.h are conflicting.\nfor ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \\\n\t\t  inttypes.h stdint.h unistd.h\ndo :\n  as_ac_Header=`$as_echo \"ac_cv_header_$ac_header\" | $as_tr_sh`\nac_fn_c_check_header_compile \"$LINENO\" \"$ac_header\" \"$as_ac_Header\" \"$ac_includes_default\n\"\neval as_val=\\$$as_ac_Header\n   if test \"x$as_val\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define `$as_echo \"HAVE_$ac_header\" | $as_tr_cpp` 1\n_ACEOF\n\nfi\n\ndone\n\n\nac_fn_c_check_type \"$LINENO\" \"size_t\" \"ac_cv_type_size_t\" \"$ac_includes_default\"\nif test \"x$ac_cv_type_size_t\" = x\"\"yes; then :\n\nelse\n\ncat >>confdefs.h <<_ACEOF\n#define size_t unsigned int\n_ACEOF\n\nfi\n\n\nfor ac_header in stdlib.h\ndo :\n  ac_fn_c_check_header_mongrel \"$LINENO\" \"stdlib.h\" \"ac_cv_header_stdlib_h\" \"$ac_includes_default\"\nif test \"x$ac_cv_header_stdlib_h\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define HAVE_STDLIB_H 1\n_ACEOF\n\nfi\n\ndone\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for GNU libc compatible malloc\" >&5\n$as_echo_n \"checking for GNU libc compatible malloc... \" >&6; }\nif test \"${ac_cv_func_malloc_0_nonnull+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test \"$cross_compiling\" = yes; then :\n  ac_cv_func_malloc_0_nonnull=no\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#if defined STDC_HEADERS || defined HAVE_STDLIB_H\n# include <stdlib.h>\n#else\nchar *malloc ();\n#endif\n\nint\nmain ()\n{\nreturn ! malloc (0);\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_run \"$LINENO\"; then :\n  ac_cv_func_malloc_0_nonnull=yes\nelse\n  ac_cv_func_malloc_0_nonnull=no\nfi\nrm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \\\n  conftest.$ac_objext conftest.beam conftest.$ac_ext\nfi\n\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_malloc_0_nonnull\" >&5\n$as_echo \"$ac_cv_func_malloc_0_nonnull\" >&6; }\nif test $ac_cv_func_malloc_0_nonnull = yes; then :\n\n$as_echo \"#define HAVE_MALLOC 1\" >>confdefs.h\n\nelse\n  $as_echo \"#define HAVE_MALLOC 0\" >>confdefs.h\n\n   case \" $LIBOBJS \" in\n  *\" malloc.$ac_objext \"* ) ;;\n  *) LIBOBJS=\"$LIBOBJS malloc.$ac_objext\"\n ;;\nesac\n\n\n$as_echo \"#define malloc rpl_malloc\" >>confdefs.h\n\nfi\n\n\n\nfor ac_header in arpa/inet.h fcntl.h stdlib.h string.h unistd.h\ndo :\n  as_ac_Header=`$as_echo \"ac_cv_header_$ac_header\" | $as_tr_sh`\nac_fn_c_check_header_mongrel \"$LINENO\" \"$ac_header\" \"$as_ac_Header\" \"$ac_includes_default\"\neval as_val=\\$$as_ac_Header\n   if test \"x$as_val\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define `$as_echo \"HAVE_$ac_header\" | $as_tr_cpp` 1\n_ACEOF\n\nelse\n  echo \"error: missing necessary header file\" && exit\nfi\n\ndone\n\n\nfor ac_func in memset strdup strstr strtol\ndo :\n  as_ac_var=`$as_echo \"ac_cv_func_$ac_func\" | $as_tr_sh`\nac_fn_c_check_func \"$LINENO\" \"$ac_func\" \"$as_ac_var\"\neval as_val=\\$$as_ac_var\n   if test \"x$as_val\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define `$as_echo \"HAVE_$ac_func\" | $as_tr_cpp` 1\n_ACEOF\n\nelse\n  as_fn_error \"\\\"Missing necessary function\\\"\" \"$LINENO\" 5\nfi\ndone\n\n\nif test $CURL = y\nthen\n\t{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for curl_easy_init in -lcurl\" >&5\n$as_echo_n \"checking for curl_easy_init in -lcurl... \" >&6; }\nif test \"${ac_cv_lib_curl_curl_easy_init+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  ac_check_lib_save_LIBS=$LIBS\nLIBS=\"-lcurl  $LIBS\"\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\n/* Override any GCC internal prototype to avoid an error.\n   Use char because int might match the return type of a GCC\n   builtin and then its argument prototype would still apply.  */\n#ifdef __cplusplus\nextern \"C\"\n#endif\nchar curl_easy_init ();\nint\nmain ()\n{\nreturn curl_easy_init ();\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_link \"$LINENO\"; then :\n  ac_cv_lib_curl_curl_easy_init=yes\nelse\n  ac_cv_lib_curl_curl_easy_init=no\nfi\nrm -f core conftest.err conftest.$ac_objext \\\n    conftest$ac_exeext conftest.$ac_ext\nLIBS=$ac_check_lib_save_LIBS\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_curl_curl_easy_init\" >&5\n$as_echo \"$ac_cv_lib_curl_curl_easy_init\" >&6; }\nif test \"x$ac_cv_lib_curl_curl_easy_init\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define HAVE_LIBCURL 1\n_ACEOF\n\n  LIBS=\"-lcurl $LIBS\"\n\nelse\n  echo \"error: missing libcurl library\" && exit\nfi\n\n\tfor ac_header in curl/curl.h\ndo :\n  ac_fn_c_check_header_mongrel \"$LINENO\" \"curl/curl.h\" \"ac_cv_header_curl_curl_h\" \"$ac_includes_default\"\nif test \"x$ac_cv_header_curl_curl_h\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define HAVE_CURL_CURL_H 1\n_ACEOF\n\nelse\n  echo \"error: missing curl header files\" && exit\nfi\n\ndone\n\n\n\tLDFLAGS=\"-lcurl $LDFLAGS\"\nelse\n\tCFLAGS=\"-DNOCURL $CFLAGS\"\nfi\n\nif test $MAGIC = n\nthen\n        tar -zxvf $FILE.tar.gz && cd $FILE && ./configure && cd -\n\n        DOFILE=\"file\"\n\tCFLAGS=\"$CFLAGS -I./$FILE/src\"\nelse\n\t{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for magic_buffer in -lmagic\" >&5\n$as_echo_n \"checking for magic_buffer in -lmagic... \" >&6; }\nif test \"${ac_cv_lib_magic_magic_buffer+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  ac_check_lib_save_LIBS=$LIBS\nLIBS=\"-lmagic  $LIBS\"\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\n/* Override any GCC internal prototype to avoid an error.\n   Use char because int might match the return type of a GCC\n   builtin and then its argument prototype would still apply.  */\n#ifdef __cplusplus\nextern \"C\"\n#endif\nchar magic_buffer ();\nint\nmain ()\n{\nreturn magic_buffer ();\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_link \"$LINENO\"; then :\n  ac_cv_lib_magic_magic_buffer=yes\nelse\n  ac_cv_lib_magic_magic_buffer=no\nfi\nrm -f core conftest.err conftest.$ac_objext \\\n    conftest$ac_exeext conftest.$ac_ext\nLIBS=$ac_check_lib_save_LIBS\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_magic_magic_buffer\" >&5\n$as_echo \"$ac_cv_lib_magic_magic_buffer\" >&6; }\nif test \"x$ac_cv_lib_magic_magic_buffer\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define HAVE_LIBMAGIC 1\n_ACEOF\n\n  LIBS=\"-lmagic $LIBS\"\n\nelse\n  echo \"error: missing libmagic library\" && exit\nfi\n\n\tfor ac_header in magic.h\ndo :\n  ac_fn_c_check_header_mongrel \"$LINENO\" \"magic.h\" \"ac_cv_header_magic_h\" \"$ac_includes_default\"\nif test \"x$ac_cv_header_magic_h\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define HAVE_MAGIC_H 1\n_ACEOF\n\nelse\n  echo \"error: missing libmagic header files\" && exit\nfi\n\ndone\n\n\n        DOFILE=\"\"\n        LDFLAGS=\"-lmagic $LDFLAGS\"\nfi\n\nif test $STATIC = y\nthen\n\tCLIBS=$(curl-config --static-libs)\n\tLDFLAGS=\"-static $CLIBS $LDFLAGS\"\nfi\n\ncp confdefs.h config.h\n\nFILE=$FILE\n\nDOFILE=$DOFILE\n\nac_config_files=\"$ac_config_files Makefile\"\n\ncat >confcache <<\\_ACEOF\n# This file is a shell script that caches the results of configure\n# tests run on this system so they can be shared between configure\n# scripts and configure runs, see configure's option --config-cache.\n# It is not useful on other systems.  If it contains results you don't\n# want to keep, you may remove or edit it.\n#\n# config.status only pays attention to the cache file if you give it\n# the --recheck option to rerun configure.\n#\n# `ac_cv_env_foo' variables (set or unset) will be overridden when\n# loading this file, other *unset* `ac_cv_foo' will be assigned the\n# following values.\n\n_ACEOF\n\n# The following way of writing the cache mishandles newlines in values,\n# but we know of no workaround that is simple, portable, and efficient.\n# So, we kill variables containing newlines.\n# Ultrix sh set writes to stderr and can't be redirected directly,\n# and sets the high bit in the cache file unless we assign to the vars.\n(\n  for ac_var in `(set) 2>&1 | sed -n 's/^\\([a-zA-Z_][a-zA-Z0-9_]*\\)=.*/\\1/p'`; do\n    eval ac_val=\\$$ac_var\n    case $ac_val in #(\n    *${as_nl}*)\n      case $ac_var in #(\n      *_cv_*) { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline\" >&5\n$as_echo \"$as_me: WARNING: cache variable $ac_var contains a newline\" >&2;} ;;\n      esac\n      case $ac_var in #(\n      _ | IFS | as_nl) ;; #(\n      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(\n      *) { eval $ac_var=; unset $ac_var;} ;;\n      esac ;;\n    esac\n  done\n\n  (set) 2>&1 |\n    case $as_nl`(ac_space=' '; set) 2>&1` in #(\n    *${as_nl}ac_space=\\ *)\n      # `set' does not quote correctly, so add quotes: double-quote\n      # substitution turns \\\\\\\\ into \\\\, and sed turns \\\\ into \\.\n      sed -n \\\n\t\"s/'/'\\\\\\\\''/g;\n\t  s/^\\\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\\\)=\\\\(.*\\\\)/\\\\1='\\\\2'/p\"\n      ;; #(\n    *)\n      # `set' quotes correctly as required by POSIX, so do not add quotes.\n      sed -n \"/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p\"\n      ;;\n    esac |\n    sort\n) |\n  sed '\n     /^ac_cv_env_/b end\n     t clear\n     :clear\n     s/^\\([^=]*\\)=\\(.*[{}].*\\)$/test \"${\\1+set}\" = set || &/\n     t end\n     s/^\\([^=]*\\)=\\(.*\\)$/\\1=${\\1=\\2}/\n     :end' >>confcache\nif diff \"$cache_file\" confcache >/dev/null 2>&1; then :; else\n  if test -w \"$cache_file\"; then\n    test \"x$cache_file\" != \"x/dev/null\" &&\n      { $as_echo \"$as_me:${as_lineno-$LINENO}: updating cache $cache_file\" >&5\n$as_echo \"$as_me: updating cache $cache_file\" >&6;}\n    cat confcache >$cache_file\n  else\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file\" >&5\n$as_echo \"$as_me: not updating unwritable cache $cache_file\" >&6;}\n  fi\nfi\nrm -f confcache\n\ntest \"x$prefix\" = xNONE && prefix=$ac_default_prefix\n# Let make expand exec_prefix.\ntest \"x$exec_prefix\" = xNONE && exec_prefix='${prefix}'\n\n# Transform confdefs.h into DEFS.\n# Protect against shell expansion while executing Makefile rules.\n# Protect against Makefile macro expansion.\n#\n# If the first sed substitution is executed (which looks for macros that\n# take arguments), then branch to the quote section.  Otherwise,\n# look for a macro that doesn't take arguments.\nac_script='\n:mline\n/\\\\$/{\n N\n s,\\\\\\n,,\n b mline\n}\nt clear\n:clear\ns/^[\t ]*#[\t ]*define[\t ][\t ]*\\([^\t (][^\t (]*([^)]*)\\)[\t ]*\\(.*\\)/-D\\1=\\2/g\nt quote\ns/^[\t ]*#[\t ]*define[\t ][\t ]*\\([^\t ][^\t ]*\\)[\t ]*\\(.*\\)/-D\\1=\\2/g\nt quote\nb any\n:quote\ns/[\t `~#$^&*(){}\\\\|;'\\''\"<>?]/\\\\&/g\ns/\\[/\\\\&/g\ns/\\]/\\\\&/g\ns/\\$/$$/g\nH\n:any\n${\n\tg\n\ts/^\\n//\n\ts/\\n/ /g\n\tp\n}\n'\nDEFS=`sed -n \"$ac_script\" confdefs.h`\n\n\nac_libobjs=\nac_ltlibobjs=\nfor ac_i in : $LIBOBJS; do test \"x$ac_i\" = x: && continue\n  # 1. Remove the extension, and $U if already installed.\n  ac_script='s/\\$U\\././;s/\\.o$//;s/\\.obj$//'\n  ac_i=`$as_echo \"$ac_i\" | sed \"$ac_script\"`\n  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR\n  #    will be set to the directory where LIBOBJS objects are built.\n  as_fn_append ac_libobjs \" \\${LIBOBJDIR}$ac_i\\$U.$ac_objext\"\n  as_fn_append ac_ltlibobjs \" \\${LIBOBJDIR}$ac_i\"'$U.lo'\ndone\nLIBOBJS=$ac_libobjs\n\nLTLIBOBJS=$ac_ltlibobjs\n\n\n\n: ${CONFIG_STATUS=./config.status}\nac_write_fail=0\nac_clean_files_save=$ac_clean_files\nac_clean_files=\"$ac_clean_files $CONFIG_STATUS\"\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS\" >&5\n$as_echo \"$as_me: creating $CONFIG_STATUS\" >&6;}\nas_write_fail=0\ncat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1\n#! $SHELL\n# Generated by $as_me.\n# Run this file to recreate the current configuration.\n# Compiler output produced by configure, useful for debugging\n# configure, is in config.log if it exists.\n\ndebug=false\nac_cs_recheck=false\nac_cs_silent=false\n\nSHELL=\\${CONFIG_SHELL-$SHELL}\nexport SHELL\n_ASEOF\ncat >>$CONFIG_STATUS <<\\_ASEOF || as_write_fail=1\n## -------------------- ##\n## M4sh Initialization. ##\n## -------------------- ##\n\n# Be more Bourne compatible\nDUALCASE=1; export DUALCASE # for MKS sh\nif test -n \"${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :\n  emulate sh\n  NULLCMD=:\n  # Pre-4.2 versions of Zsh do word splitting on ${1+\"$@\"}, which\n  # is contrary to our usage.  Disable this feature.\n  alias -g '${1+\"$@\"}'='\"$@\"'\n  setopt NO_GLOB_SUBST\nelse\n  case `(set -o) 2>/dev/null` in #(\n  *posix*) :\n    set -o posix ;; #(\n  *) :\n     ;;\nesac\nfi\n\n\nas_nl='\n'\nexport as_nl\n# Printing a long string crashes Solaris 7 /usr/bin/printf.\nas_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'\nas_echo=$as_echo$as_echo$as_echo$as_echo$as_echo\nas_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo\n# Prefer a ksh shell builtin over an external printf program on Solaris,\n# but without wasting forks for bash or zsh.\nif test -z \"$BASH_VERSION$ZSH_VERSION\" \\\n    && (test \"X`print -r -- $as_echo`\" = \"X$as_echo\") 2>/dev/null; then\n  as_echo='print -r --'\n  as_echo_n='print -rn --'\nelif (test \"X`printf %s $as_echo`\" = \"X$as_echo\") 2>/dev/null; then\n  as_echo='printf %s\\n'\n  as_echo_n='printf %s'\nelse\n  if test \"X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`\" = \"X-n $as_echo\"; then\n    as_echo_body='eval /usr/ucb/echo -n \"$1$as_nl\"'\n    as_echo_n='/usr/ucb/echo -n'\n  else\n    as_echo_body='eval expr \"X$1\" : \"X\\\\(.*\\\\)\"'\n    as_echo_n_body='eval\n      arg=$1;\n      case $arg in #(\n      *\"$as_nl\"*)\n\texpr \"X$arg\" : \"X\\\\(.*\\\\)$as_nl\";\n\targ=`expr \"X$arg\" : \".*$as_nl\\\\(.*\\\\)\"`;;\n      esac;\n      expr \"X$arg\" : \"X\\\\(.*\\\\)\" | tr -d \"$as_nl\"\n    '\n    export as_echo_n_body\n    as_echo_n='sh -c $as_echo_n_body as_echo'\n  fi\n  export as_echo_body\n  as_echo='sh -c $as_echo_body as_echo'\nfi\n\n# The user is always right.\nif test \"${PATH_SEPARATOR+set}\" != set; then\n  PATH_SEPARATOR=:\n  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {\n    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||\n      PATH_SEPARATOR=';'\n  }\nfi\n\n\n# IFS\n# We need space, tab and new line, in precisely that order.  Quoting is\n# there to prevent editors from complaining about space-tab.\n# (If _AS_PATH_WALK were called with IFS unset, it would disable word\n# splitting by setting IFS to empty value.)\nIFS=\" \"\"\t$as_nl\"\n\n# Find who we are.  Look in the path if we contain no directory separator.\ncase $0 in #((\n  *[\\\\/]* ) as_myself=$0 ;;\n  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    test -r \"$as_dir/$0\" && as_myself=$as_dir/$0 && break\n  done\nIFS=$as_save_IFS\n\n     ;;\nesac\n# We did not find ourselves, most probably we were run as `sh COMMAND'\n# in which case we are not to be found in the path.\nif test \"x$as_myself\" = x; then\n  as_myself=$0\nfi\nif test ! -f \"$as_myself\"; then\n  $as_echo \"$as_myself: error: cannot find myself; rerun with an absolute file name\" >&2\n  exit 1\nfi\n\n# Unset variables that we do not need and which cause bugs (e.g. in\n# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the \"|| exit 1\"\n# suppresses any \"Segmentation fault\" message there.  '((' could\n# trigger a bug in pdksh 5.2.14.\nfor as_var in BASH_ENV ENV MAIL MAILPATH\ndo eval test x\\${$as_var+set} = xset \\\n  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :\ndone\nPS1='$ '\nPS2='> '\nPS4='+ '\n\n# NLS nuisances.\nLC_ALL=C\nexport LC_ALL\nLANGUAGE=C\nexport LANGUAGE\n\n# CDPATH.\n(unset CDPATH) >/dev/null 2>&1 && unset CDPATH\n\n\n# as_fn_error ERROR [LINENO LOG_FD]\n# ---------------------------------\n# Output \"`basename $0`: error: ERROR\" to stderr. If LINENO and LOG_FD are\n# provided, also output the error to LOG_FD, referencing LINENO. Then exit the\n# script with status $?, using 1 if that was 0.\nas_fn_error ()\n{\n  as_status=$?; test $as_status -eq 0 && as_status=1\n  if test \"$3\"; then\n    as_lineno=${as_lineno-\"$2\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n    $as_echo \"$as_me:${as_lineno-$LINENO}: error: $1\" >&$3\n  fi\n  $as_echo \"$as_me: error: $1\" >&2\n  as_fn_exit $as_status\n} # as_fn_error\n\n\n# as_fn_set_status STATUS\n# -----------------------\n# Set $? to STATUS, without forking.\nas_fn_set_status ()\n{\n  return $1\n} # as_fn_set_status\n\n# as_fn_exit STATUS\n# -----------------\n# Exit the shell with STATUS, even in a \"trap 0\" or \"set -e\" context.\nas_fn_exit ()\n{\n  set +e\n  as_fn_set_status $1\n  exit $1\n} # as_fn_exit\n\n# as_fn_unset VAR\n# ---------------\n# Portably unset VAR.\nas_fn_unset ()\n{\n  { eval $1=; unset $1;}\n}\nas_unset=as_fn_unset\n# as_fn_append VAR VALUE\n# ----------------------\n# Append the text in VALUE to the end of the definition contained in VAR. Take\n# advantage of any shell optimizations that allow amortized linear growth over\n# repeated appends, instead of the typical quadratic growth present in naive\n# implementations.\nif (eval \"as_var=1; as_var+=2; test x\\$as_var = x12\") 2>/dev/null; then :\n  eval 'as_fn_append ()\n  {\n    eval $1+=\\$2\n  }'\nelse\n  as_fn_append ()\n  {\n    eval $1=\\$$1\\$2\n  }\nfi # as_fn_append\n\n# as_fn_arith ARG...\n# ------------------\n# Perform arithmetic evaluation on the ARGs, and store the result in the\n# global $as_val. Take advantage of shells that can avoid forks. The arguments\n# must be portable across $(()) and expr.\nif (eval \"test \\$(( 1 + 1 )) = 2\") 2>/dev/null; then :\n  eval 'as_fn_arith ()\n  {\n    as_val=$(( $* ))\n  }'\nelse\n  as_fn_arith ()\n  {\n    as_val=`expr \"$@\" || test $? -eq 1`\n  }\nfi # as_fn_arith\n\n\nif expr a : '\\(a\\)' >/dev/null 2>&1 &&\n   test \"X`expr 00001 : '.*\\(...\\)'`\" = X001; then\n  as_expr=expr\nelse\n  as_expr=false\nfi\n\nif (basename -- /) >/dev/null 2>&1 && test \"X`basename -- / 2>&1`\" = \"X/\"; then\n  as_basename=basename\nelse\n  as_basename=false\nfi\n\nif (as_dir=`dirname -- /` && test \"X$as_dir\" = X/) >/dev/null 2>&1; then\n  as_dirname=dirname\nelse\n  as_dirname=false\nfi\n\nas_me=`$as_basename -- \"$0\" ||\n$as_expr X/\"$0\" : '.*/\\([^/][^/]*\\)/*$' \\| \\\n\t X\"$0\" : 'X\\(//\\)$' \\| \\\n\t X\"$0\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X/\"$0\" |\n    sed '/^.*\\/\\([^/][^/]*\\)\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\/\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\/\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n\n# Avoid depending upon Character Ranges.\nas_cr_letters='abcdefghijklmnopqrstuvwxyz'\nas_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'\nas_cr_Letters=$as_cr_letters$as_cr_LETTERS\nas_cr_digits='0123456789'\nas_cr_alnum=$as_cr_Letters$as_cr_digits\n\nECHO_C= ECHO_N= ECHO_T=\ncase `echo -n x` in #(((((\n-n*)\n  case `echo 'xy\\c'` in\n  *c*) ECHO_T='\t';;\t# ECHO_T is single tab character.\n  xy)  ECHO_C='\\c';;\n  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null\n       ECHO_T='\t';;\n  esac;;\n*)\n  ECHO_N='-n';;\nesac\n\nrm -f conf$$ conf$$.exe conf$$.file\nif test -d conf$$.dir; then\n  rm -f conf$$.dir/conf$$.file\nelse\n  rm -f conf$$.dir\n  mkdir conf$$.dir 2>/dev/null\nfi\nif (echo >conf$$.file) 2>/dev/null; then\n  if ln -s conf$$.file conf$$ 2>/dev/null; then\n    as_ln_s='ln -s'\n    # ... but there are two gotchas:\n    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.\n    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.\n    # In both cases, we have to default to `cp -p'.\n    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||\n      as_ln_s='cp -p'\n  elif ln conf$$.file conf$$ 2>/dev/null; then\n    as_ln_s=ln\n  else\n    as_ln_s='cp -p'\n  fi\nelse\n  as_ln_s='cp -p'\nfi\nrm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file\nrmdir conf$$.dir 2>/dev/null\n\n\n# as_fn_mkdir_p\n# -------------\n# Create \"$as_dir\" as a directory, including parents if necessary.\nas_fn_mkdir_p ()\n{\n\n  case $as_dir in #(\n  -*) as_dir=./$as_dir;;\n  esac\n  test -d \"$as_dir\" || eval $as_mkdir_p || {\n    as_dirs=\n    while :; do\n      case $as_dir in #(\n      *\\'*) as_qdir=`$as_echo \"$as_dir\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"`;; #'(\n      *) as_qdir=$as_dir;;\n      esac\n      as_dirs=\"'$as_qdir' $as_dirs\"\n      as_dir=`$as_dirname -- \"$as_dir\" ||\n$as_expr X\"$as_dir\" : 'X\\(.*[^/]\\)//*[^/][^/]*/*$' \\| \\\n\t X\"$as_dir\" : 'X\\(//\\)[^/]' \\| \\\n\t X\"$as_dir\" : 'X\\(//\\)$' \\| \\\n\t X\"$as_dir\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X\"$as_dir\" |\n    sed '/^X\\(.*[^/]\\)\\/\\/*[^/][^/]*\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)[^/].*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n      test -d \"$as_dir\" && break\n    done\n    test -z \"$as_dirs\" || eval \"mkdir $as_dirs\"\n  } || test -d \"$as_dir\" || as_fn_error \"cannot create directory $as_dir\"\n\n\n} # as_fn_mkdir_p\nif mkdir -p . 2>/dev/null; then\n  as_mkdir_p='mkdir -p \"$as_dir\"'\nelse\n  test -d ./-p && rmdir ./-p\n  as_mkdir_p=false\nfi\n\nif test -x / >/dev/null 2>&1; then\n  as_test_x='test -x'\nelse\n  if ls -dL / >/dev/null 2>&1; then\n    as_ls_L_option=L\n  else\n    as_ls_L_option=\n  fi\n  as_test_x='\n    eval sh -c '\\''\n      if test -d \"$1\"; then\n\ttest -d \"$1/.\";\n      else\n\tcase $1 in #(\n\t-*)set \"./$1\";;\n\tesac;\n\tcase `ls -ld'$as_ls_L_option' \"$1\" 2>/dev/null` in #((\n\t???[sx]*):;;*)false;;esac;fi\n    '\\'' sh\n  '\nfi\nas_executable_p=$as_test_x\n\n# Sed expression to map a string onto a valid CPP name.\nas_tr_cpp=\"eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'\"\n\n# Sed expression to map a string onto a valid variable name.\nas_tr_sh=\"eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'\"\n\n\nexec 6>&1\n## ----------------------------------- ##\n## Main body of $CONFIG_STATUS script. ##\n## ----------------------------------- ##\n_ASEOF\ntest $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n# Save the log message, to keep $0 and so on meaningful, and to\n# report actual input values of CONFIG_FILES etc. instead of their\n# values after options handling.\nac_log=\"\nThis file was extended by binwalk $as_me 0.4.1, which was\ngenerated by GNU Autoconf 2.65.  Invocation command line was\n\n  CONFIG_FILES    = $CONFIG_FILES\n  CONFIG_HEADERS  = $CONFIG_HEADERS\n  CONFIG_LINKS    = $CONFIG_LINKS\n  CONFIG_COMMANDS = $CONFIG_COMMANDS\n  $ $0 $@\n\non `(hostname || uname -n) 2>/dev/null | sed 1q`\n\"\n\n_ACEOF\n\ncase $ac_config_files in *\"\n\"*) set x $ac_config_files; shift; ac_config_files=$*;;\nesac\n\n\n\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\n# Files that config.status was made for.\nconfig_files=\"$ac_config_files\"\n\n_ACEOF\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\nac_cs_usage=\"\\\n\\`$as_me' instantiates files and other configuration actions\nfrom templates according to the current configuration.  Unless the files\nand actions are specified as TAGs, all are instantiated by default.\n\nUsage: $0 [OPTION]... [TAG]...\n\n  -h, --help       print this help, then exit\n  -V, --version    print version number and configuration settings, then exit\n      --config     print configuration, then exit\n  -q, --quiet, --silent\n                   do not print progress messages\n  -d, --debug      don't remove temporary files\n      --recheck    update $as_me by reconfiguring in the same conditions\n      --file=FILE[:TEMPLATE]\n                   instantiate the configuration file FILE\n\nConfiguration files:\n$config_files\n\nReport bugs to <http://code.google.com/p/binwalk/issues/list>.\"\n\n_ACEOF\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\nac_cs_config=\"`$as_echo \"$ac_configure_args\" | sed 's/^ //; s/[\\\\\"\"\\`\\$]/\\\\\\\\&/g'`\"\nac_cs_version=\"\\\\\nbinwalk config.status 0.4.1\nconfigured by $0, generated by GNU Autoconf 2.65,\n  with options \\\\\"\\$ac_cs_config\\\\\"\n\nCopyright (C) 2009 Free Software Foundation, Inc.\nThis config.status script is free software; the Free Software Foundation\ngives unlimited permission to copy, distribute and modify it.\"\n\nac_pwd='$ac_pwd'\nsrcdir='$srcdir'\ntest -n \"\\$AWK\" || AWK=awk\n_ACEOF\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n# The default lists apply if the user does not specify any file.\nac_need_defaults=:\nwhile test $# != 0\ndo\n  case $1 in\n  --*=*)\n    ac_option=`expr \"X$1\" : 'X\\([^=]*\\)='`\n    ac_optarg=`expr \"X$1\" : 'X[^=]*=\\(.*\\)'`\n    ac_shift=:\n    ;;\n  *)\n    ac_option=$1\n    ac_optarg=$2\n    ac_shift=shift\n    ;;\n  esac\n\n  case $ac_option in\n  # Handling of the options.\n  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)\n    ac_cs_recheck=: ;;\n  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )\n    $as_echo \"$ac_cs_version\"; exit ;;\n  --config | --confi | --conf | --con | --co | --c )\n    $as_echo \"$ac_cs_config\"; exit ;;\n  --debug | --debu | --deb | --de | --d | -d )\n    debug=: ;;\n  --file | --fil | --fi | --f )\n    $ac_shift\n    case $ac_optarg in\n    *\\'*) ac_optarg=`$as_echo \"$ac_optarg\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"` ;;\n    esac\n    as_fn_append CONFIG_FILES \" '$ac_optarg'\"\n    ac_need_defaults=false;;\n  --he | --h |  --help | --hel | -h )\n    $as_echo \"$ac_cs_usage\"; exit ;;\n  -q | -quiet | --quiet | --quie | --qui | --qu | --q \\\n  | -silent | --silent | --silen | --sile | --sil | --si | --s)\n    ac_cs_silent=: ;;\n\n  # This is an error.\n  -*) as_fn_error \"unrecognized option: \\`$1'\nTry \\`$0 --help' for more information.\" ;;\n\n  *) as_fn_append ac_config_targets \" $1\"\n     ac_need_defaults=false ;;\n\n  esac\n  shift\ndone\n\nac_configure_extra_args=\n\nif $ac_cs_silent; then\n  exec 6>/dev/null\n  ac_configure_extra_args=\"$ac_configure_extra_args --silent\"\nfi\n\n_ACEOF\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\nif \\$ac_cs_recheck; then\n  set X '$SHELL' '$0' $ac_configure_args \\$ac_configure_extra_args --no-create --no-recursion\n  shift\n  \\$as_echo \"running CONFIG_SHELL=$SHELL \\$*\" >&6\n  CONFIG_SHELL='$SHELL'\n  export CONFIG_SHELL\n  exec \"\\$@\"\nfi\n\n_ACEOF\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\nexec 5>>config.log\n{\n  echo\n  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX\n## Running $as_me. ##\n_ASBOX\n  $as_echo \"$ac_log\"\n} >&5\n\n_ACEOF\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\n_ACEOF\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n\n# Handling of arguments.\nfor ac_config_target in $ac_config_targets\ndo\n  case $ac_config_target in\n    \"Makefile\") CONFIG_FILES=\"$CONFIG_FILES Makefile\" ;;\n\n  *) as_fn_error \"invalid argument: \\`$ac_config_target'\" \"$LINENO\" 5;;\n  esac\ndone\n\n\n# If the user did not use the arguments to specify the items to instantiate,\n# then the envvar interface is used.  Set only those that are not.\n# We use the long form for the default assignment because of an extremely\n# bizarre bug on SunOS 4.1.3.\nif $ac_need_defaults; then\n  test \"${CONFIG_FILES+set}\" = set || CONFIG_FILES=$config_files\nfi\n\n# Have a temporary directory for convenience.  Make it in the build tree\n# simply because there is no reason against having it here, and in addition,\n# creating and moving files from /tmp can sometimes cause problems.\n# Hook for its removal unless debugging.\n# Note that there is a small window in which the directory will not be cleaned:\n# after its creation but before its name has been assigned to `$tmp'.\n$debug ||\n{\n  tmp=\n  trap 'exit_status=$?\n  { test -z \"$tmp\" || test ! -d \"$tmp\" || rm -fr \"$tmp\"; } && exit $exit_status\n' 0\n  trap 'as_fn_exit 1' 1 2 13 15\n}\n# Create a (secure) tmp directory for tmp files.\n\n{\n  tmp=`(umask 077 && mktemp -d \"./confXXXXXX\") 2>/dev/null` &&\n  test -n \"$tmp\" && test -d \"$tmp\"\n}  ||\n{\n  tmp=./conf$$-$RANDOM\n  (umask 077 && mkdir \"$tmp\")\n} || as_fn_error \"cannot create a temporary directory in .\" \"$LINENO\" 5\n\n# Set up the scripts for CONFIG_FILES section.\n# No need to generate them if there are no CONFIG_FILES.\n# This happens for instance with `./config.status config.h'.\nif test -n \"$CONFIG_FILES\"; then\n\n\nac_cr=`echo X | tr X '\\015'`\n# On cygwin, bash can eat \\r inside `` if the user requested igncr.\n# But we know of no other shell where ac_cr would be empty at this\n# point, so we can use a bashism as a fallback.\nif test \"x$ac_cr\" = x; then\n  eval ac_cr=\\$\\'\\\\r\\'\nfi\nac_cs_awk_cr=`$AWK 'BEGIN { print \"a\\rb\" }' </dev/null 2>/dev/null`\nif test \"$ac_cs_awk_cr\" = \"a${ac_cr}b\"; then\n  ac_cs_awk_cr='\\r'\nelse\n  ac_cs_awk_cr=$ac_cr\nfi\n\necho 'BEGIN {' >\"$tmp/subs1.awk\" &&\n_ACEOF\n\n\n{\n  echo \"cat >conf$$subs.awk <<_ACEOF\" &&\n  echo \"$ac_subst_vars\" | sed 's/.*/&!$&$ac_delim/' &&\n  echo \"_ACEOF\"\n} >conf$$subs.sh ||\n  as_fn_error \"could not make $CONFIG_STATUS\" \"$LINENO\" 5\nac_delim_num=`echo \"$ac_subst_vars\" | grep -c '$'`\nac_delim='%!_!# '\nfor ac_last_try in false false false false false :; do\n  . ./conf$$subs.sh ||\n    as_fn_error \"could not make $CONFIG_STATUS\" \"$LINENO\" 5\n\n  ac_delim_n=`sed -n \"s/.*$ac_delim\\$/X/p\" conf$$subs.awk | grep -c X`\n  if test $ac_delim_n = $ac_delim_num; then\n    break\n  elif $ac_last_try; then\n    as_fn_error \"could not make $CONFIG_STATUS\" \"$LINENO\" 5\n  else\n    ac_delim=\"$ac_delim!$ac_delim _$ac_delim!! \"\n  fi\ndone\nrm -f conf$$subs.sh\n\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\ncat >>\"\\$tmp/subs1.awk\" <<\\\\_ACAWK &&\n_ACEOF\nsed -n '\nh\ns/^/S[\"/; s/!.*/\"]=/\np\ng\ns/^[^!]*!//\n:repl\nt repl\ns/'\"$ac_delim\"'$//\nt delim\n:nl\nh\ns/\\(.\\{148\\}\\)..*/\\1/\nt more1\ns/[\"\\\\]/\\\\&/g; s/^/\"/; s/$/\\\\n\"\\\\/\np\nn\nb repl\n:more1\ns/[\"\\\\]/\\\\&/g; s/^/\"/; s/$/\"\\\\/\np\ng\ns/.\\{148\\}//\nt nl\n:delim\nh\ns/\\(.\\{148\\}\\)..*/\\1/\nt more2\ns/[\"\\\\]/\\\\&/g; s/^/\"/; s/$/\"/\np\nb\n:more2\ns/[\"\\\\]/\\\\&/g; s/^/\"/; s/$/\"\\\\/\np\ng\ns/.\\{148\\}//\nt delim\n' <conf$$subs.awk | sed '\n/^[^\"\"]/{\n  N\n  s/\\n//\n}\n' >>$CONFIG_STATUS || ac_write_fail=1\nrm -f conf$$subs.awk\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\n_ACAWK\ncat >>\"\\$tmp/subs1.awk\" <<_ACAWK &&\n  for (key in S) S_is_set[key] = 1\n  FS = \"\u0007\"\n\n}\n{\n  line = $ 0\n  nfields = split(line, field, \"@\")\n  substed = 0\n  len = length(field[1])\n  for (i = 2; i < nfields; i++) {\n    key = field[i]\n    keylen = length(key)\n    if (S_is_set[key]) {\n      value = S[key]\n      line = substr(line, 1, len) \"\" value \"\" substr(line, len + keylen + 3)\n      len += length(value) + length(field[++i])\n      substed = 1\n    } else\n      len += 1 + keylen\n  }\n\n  print line\n}\n\n_ACAWK\n_ACEOF\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\nif sed \"s/$ac_cr//\" < /dev/null > /dev/null 2>&1; then\n  sed \"s/$ac_cr\\$//; s/$ac_cr/$ac_cs_awk_cr/g\"\nelse\n  cat\nfi < \"$tmp/subs1.awk\" > \"$tmp/subs.awk\" \\\n  || as_fn_error \"could not setup config files machinery\" \"$LINENO\" 5\n_ACEOF\n\n# VPATH may cause trouble with some makes, so we remove $(srcdir),\n# ${srcdir} and @srcdir@ from VPATH if srcdir is \".\", strip leading and\n# trailing colons and then remove the whole line if VPATH becomes empty\n# (actually we leave an empty line to preserve line numbers).\nif test \"x$srcdir\" = x.; then\n  ac_vpsub='/^[\t ]*VPATH[\t ]*=/{\ns/:*\\$(srcdir):*/:/\ns/:*\\${srcdir}:*/:/\ns/:*@srcdir@:*/:/\ns/^\\([^=]*=[\t ]*\\):*/\\1/\ns/:*$//\ns/^[^=]*=[\t ]*$//\n}'\nfi\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\nfi # test -n \"$CONFIG_FILES\"\n\n\neval set X \"  :F $CONFIG_FILES      \"\nshift\nfor ac_tag\ndo\n  case $ac_tag in\n  :[FHLC]) ac_mode=$ac_tag; continue;;\n  esac\n  case $ac_mode$ac_tag in\n  :[FHL]*:*);;\n  :L* | :C*:*) as_fn_error \"invalid tag \\`$ac_tag'\" \"$LINENO\" 5;;\n  :[FH]-) ac_tag=-:-;;\n  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;\n  esac\n  ac_save_IFS=$IFS\n  IFS=:\n  set x $ac_tag\n  IFS=$ac_save_IFS\n  shift\n  ac_file=$1\n  shift\n\n  case $ac_mode in\n  :L) ac_source=$1;;\n  :[FH])\n    ac_file_inputs=\n    for ac_f\n    do\n      case $ac_f in\n      -) ac_f=\"$tmp/stdin\";;\n      *) # Look for the file first in the build tree, then in the source tree\n\t # (if the path is not absolute).  The absolute path cannot be DOS-style,\n\t # because $ac_f cannot contain `:'.\n\t test -f \"$ac_f\" ||\n\t   case $ac_f in\n\t   [\\\\/$]*) false;;\n\t   *) test -f \"$srcdir/$ac_f\" && ac_f=\"$srcdir/$ac_f\";;\n\t   esac ||\n\t   as_fn_error \"cannot find input file: \\`$ac_f'\" \"$LINENO\" 5;;\n      esac\n      case $ac_f in *\\'*) ac_f=`$as_echo \"$ac_f\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"`;; esac\n      as_fn_append ac_file_inputs \" '$ac_f'\"\n    done\n\n    # Let's still pretend it is `configure' which instantiates (i.e., don't\n    # use $as_me), people would be surprised to read:\n    #    /* config.h.  Generated by config.status.  */\n    configure_input='Generated from '`\n\t  $as_echo \"$*\" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'\n\t`' by configure.'\n    if test x\"$ac_file\" != x-; then\n      configure_input=\"$ac_file.  $configure_input\"\n      { $as_echo \"$as_me:${as_lineno-$LINENO}: creating $ac_file\" >&5\n$as_echo \"$as_me: creating $ac_file\" >&6;}\n    fi\n    # Neutralize special characters interpreted by sed in replacement strings.\n    case $configure_input in #(\n    *\\&* | *\\|* | *\\\\* )\n       ac_sed_conf_input=`$as_echo \"$configure_input\" |\n       sed 's/[\\\\\\\\&|]/\\\\\\\\&/g'`;; #(\n    *) ac_sed_conf_input=$configure_input;;\n    esac\n\n    case $ac_tag in\n    *:-:* | *:-) cat >\"$tmp/stdin\" \\\n      || as_fn_error \"could not create $ac_file\" \"$LINENO\" 5 ;;\n    esac\n    ;;\n  esac\n\n  ac_dir=`$as_dirname -- \"$ac_file\" ||\n$as_expr X\"$ac_file\" : 'X\\(.*[^/]\\)//*[^/][^/]*/*$' \\| \\\n\t X\"$ac_file\" : 'X\\(//\\)[^/]' \\| \\\n\t X\"$ac_file\" : 'X\\(//\\)$' \\| \\\n\t X\"$ac_file\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X\"$ac_file\" |\n    sed '/^X\\(.*[^/]\\)\\/\\/*[^/][^/]*\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)[^/].*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n  as_dir=\"$ac_dir\"; as_fn_mkdir_p\n  ac_builddir=.\n\ncase \"$ac_dir\" in\n.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;\n*)\n  ac_dir_suffix=/`$as_echo \"$ac_dir\" | sed 's|^\\.[\\\\/]||'`\n  # A \"..\" for each directory in $ac_dir_suffix.\n  ac_top_builddir_sub=`$as_echo \"$ac_dir_suffix\" | sed 's|/[^\\\\/]*|/..|g;s|/||'`\n  case $ac_top_builddir_sub in\n  \"\") ac_top_builddir_sub=. ac_top_build_prefix= ;;\n  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;\n  esac ;;\nesac\nac_abs_top_builddir=$ac_pwd\nac_abs_builddir=$ac_pwd$ac_dir_suffix\n# for backward compatibility:\nac_top_builddir=$ac_top_build_prefix\n\ncase $srcdir in\n  .)  # We are building in place.\n    ac_srcdir=.\n    ac_top_srcdir=$ac_top_builddir_sub\n    ac_abs_top_srcdir=$ac_pwd ;;\n  [\\\\/]* | ?:[\\\\/]* )  # Absolute name.\n    ac_srcdir=$srcdir$ac_dir_suffix;\n    ac_top_srcdir=$srcdir\n    ac_abs_top_srcdir=$srcdir ;;\n  *) # Relative name.\n    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix\n    ac_top_srcdir=$ac_top_build_prefix$srcdir\n    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;\nesac\nac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix\n\n\n  case $ac_mode in\n  :F)\n  #\n  # CONFIG_FILE\n  #\n\n_ACEOF\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n# If the template does not know about datarootdir, expand it.\n# FIXME: This hack should be removed a few years after 2.60.\nac_datarootdir_hack=; ac_datarootdir_seen=\nac_sed_dataroot='\n/datarootdir/ {\n  p\n  q\n}\n/@datadir@/p\n/@docdir@/p\n/@infodir@/p\n/@localedir@/p\n/@mandir@/p'\ncase `eval \"sed -n \\\"\\$ac_sed_dataroot\\\" $ac_file_inputs\"` in\n*datarootdir*) ac_datarootdir_seen=yes;;\n*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting\" >&5\n$as_echo \"$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting\" >&2;}\n_ACEOF\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\n  ac_datarootdir_hack='\n  s&@datadir@&$datadir&g\n  s&@docdir@&$docdir&g\n  s&@infodir@&$infodir&g\n  s&@localedir@&$localedir&g\n  s&@mandir@&$mandir&g\n  s&\\\\\\${datarootdir}&$datarootdir&g' ;;\nesac\n_ACEOF\n\n# Neutralize VPATH when `$srcdir' = `.'.\n# Shell code in configure.ac might set extrasub.\n# FIXME: do we really want to maintain this feature?\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\nac_sed_extra=\"$ac_vpsub\n$extrasub\n_ACEOF\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n:t\n/@[a-zA-Z_][a-zA-Z_0-9]*@/!b\ns|@configure_input@|$ac_sed_conf_input|;t t\ns&@top_builddir@&$ac_top_builddir_sub&;t t\ns&@top_build_prefix@&$ac_top_build_prefix&;t t\ns&@srcdir@&$ac_srcdir&;t t\ns&@abs_srcdir@&$ac_abs_srcdir&;t t\ns&@top_srcdir@&$ac_top_srcdir&;t t\ns&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t\ns&@builddir@&$ac_builddir&;t t\ns&@abs_builddir@&$ac_abs_builddir&;t t\ns&@abs_top_builddir@&$ac_abs_top_builddir&;t t\n$ac_datarootdir_hack\n\"\neval sed \\\"\\$ac_sed_extra\\\" \"$ac_file_inputs\" | $AWK -f \"$tmp/subs.awk\" >$tmp/out \\\n  || as_fn_error \"could not create $ac_file\" \"$LINENO\" 5\n\ntest -z \"$ac_datarootdir_hack$ac_datarootdir_seen\" &&\n  { ac_out=`sed -n '/\\${datarootdir}/p' \"$tmp/out\"`; test -n \"$ac_out\"; } &&\n  { ac_out=`sed -n '/^[\t ]*datarootdir[\t ]*:*=/p' \"$tmp/out\"`; test -z \"$ac_out\"; } &&\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \\`datarootdir'\nwhich seems to be undefined.  Please make sure it is defined.\" >&5\n$as_echo \"$as_me: WARNING: $ac_file contains a reference to the variable \\`datarootdir'\nwhich seems to be undefined.  Please make sure it is defined.\" >&2;}\n\n  rm -f \"$tmp/stdin\"\n  case $ac_file in\n  -) cat \"$tmp/out\" && rm -f \"$tmp/out\";;\n  *) rm -f \"$ac_file\" && mv \"$tmp/out\" \"$ac_file\";;\n  esac \\\n  || as_fn_error \"could not create $ac_file\" \"$LINENO\" 5\n ;;\n\n\n\n  esac\n\ndone # for ac_tag\n\n\nas_fn_exit 0\n_ACEOF\nac_clean_files=$ac_clean_files_save\n\ntest $ac_write_fail = 0 ||\n  as_fn_error \"write failure creating $CONFIG_STATUS\" \"$LINENO\" 5\n\n\n# configure is writing to config.log, and then calls config.status.\n# config.status does its own redirection, appending to config.log.\n# Unfortunately, on DOS this fails, as config.log is still kept open\n# by configure, so config.status won't be able to write to it; its\n# output is simply discarded.  So we exec the FD to /dev/null,\n# effectively closing config.log, so it can be properly (re)opened and\n# appended to by config.status.  When coming back to configure, we\n# need to make the FD available again.\nif test \"$no_create\" != yes; then\n  ac_cs_success=:\n  ac_config_status_args=\n  test \"$silent\" = yes &&\n    ac_config_status_args=\"$ac_config_status_args --quiet\"\n  exec 5>/dev/null\n  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false\n  exec 5>>config.log\n  # Use ||, not &&, to avoid exiting from the if with $? = 1, which\n  # would make configure fail if this is the last instruction.\n  $ac_cs_success || as_fn_exit $?\nfi\nif test -n \"$ac_unrecognized_opts\" && test \"$enable_option_checking\" != no; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts\" >&5\n$as_echo \"$as_me: WARNING: unrecognized options: $ac_unrecognized_opts\" >&2;}\nfi\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/configure.ac",
    "content": "dnl Many thanks to Anthony Basile for the initial configure script and Makefile\n\nAC_PREREQ([2.65])\nAC_INIT([binwalk],[0.4.1],[http://code.google.com/p/binwalk/issues/list])\nAC_CONFIG_SRCDIR([md5.c])\n\nAC_PROG_CC\nAC_LANG(C)\n\nFILE=\"file-5.07\"\nCFLAGS=\"-Wall $CFLAGS\"\nLDFLAGS=\"-lz $LDFLAGS\"\n\nAC_ARG_ENABLE([static],    [  --enable-static         perform static build ], [STATIC=y], [STATIC=n])\nAC_ARG_ENABLE([libmagic],  [  --enable-libmagic       build against libmagic ], [MAGIC=y], [MAGIC=n])\nAC_ARG_ENABLE([updates],   [  --disable-updates       disable update features that rely on libcurl ], [CURL=n], [CURL=y])\n\nAC_TYPE_SIZE_T\n\nAC_FUNC_MALLOC\n\nAC_CHECK_HEADERS([arpa/inet.h fcntl.h stdlib.h string.h unistd.h],[],[echo \"error: missing necessary header file\" && exit])\n\nAC_CHECK_FUNCS([memset strdup strstr strtol],[],AC_MSG_ERROR([\"Missing necessary function\"]))\n\nif test $CURL = y\nthen\n\tAC_CHECK_LIB([curl],[curl_easy_init],[],[echo \"error: missing libcurl library\" && exit],[])\n\tAC_CHECK_HEADERS([curl/curl.h],[],[echo \"error: missing curl header files\" && exit])\n\n\tLDFLAGS=\"-lcurl $LDFLAGS\"\nelse\n\tCFLAGS=\"-DNOCURL $CFLAGS\"\nfi\n\ndnl extract and run file utility configure script\nif test $MAGIC = n\nthen\n        tar -zxvf $FILE.tar.gz && cd $FILE && ./configure && cd -\n\n        DOFILE=\"file\"\n\tCFLAGS=\"$CFLAGS -I./$FILE/src\"\nelse\n\tAC_CHECK_LIB([magic],[magic_buffer],[],[echo \"error: missing libmagic library\" && exit],[])\n\tAC_CHECK_HEADERS([magic.h],[],[echo \"error: missing libmagic header files\" && exit])\n\n        DOFILE=\"\"\n        LDFLAGS=\"-lmagic $LDFLAGS\"\nfi\n\ndnl curl static libs only required if we're doing a static build\nif test $STATIC = y\nthen\n\tCLIBS=$(curl-config --static-libs)\n\tLDFLAGS=\"-static $CLIBS $LDFLAGS\"\nfi\n\ncp confdefs.h config.h\n\nAC_SUBST(FILE, $FILE)\nAC_SUBST(DOFILE, $DOFILE)\nAC_CONFIG_FILES([Makefile])\nAC_OUTPUT\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/filter.c",
    "content": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <ctype.h>\n#include \"filter.h\"\n\n/* Appends a new filter to the filters array */\nvoid add_filter(struct magic_filter *filters[], int *filter_count, enum filter_type_t type, char* filter)\n{\n        if(*filter_count < MAX_FILTERS)\n        {\n                filters[*filter_count] = malloc(sizeof(struct magic_filter));\n                if(filters[*filter_count] != NULL)\n                {\n                        memset(filters[*filter_count], 0, sizeof(struct magic_filter));\n\n                        filters[*filter_count]->type = type;\n                        filters[*filter_count]->filter = strdup(filter);\n\t\t\tuppercase(filters[*filter_count]->filter);\n                        *filter_count = *filter_count+1;\n                }\n                else\n                {\n                        perror(\"Malloc failure\");\n                }\n        }\n\n        return;\n}\n\n/* Check to see if the description matches any of the include / exclude filters */\nenum filter_result_t filter_check(struct magic_filter *filters[], int filter_count, char *description)\n{\n\tint i = 0; \n\tenum filter_result_t found = RESULT_NOT_FOUND;\n\n\t/* If include filters have been specified, then ONLY those descriptions that match the include filters\n\t * should be used. Loop through to see if there are any include filters; if so, make sure this desciption\n\t * matches one of the include filters.\n\t */\n\tfor(i=0; i<filter_count; i++)\n\t{\n\t\tif(filters[i]->type == FILTER_INCLUDE || filters[i]->type == FILTER_ADD)\n\t\t{\n\t\t\t/* If an explicit include filter was specified, then default to RESULT_EXCLUDE unless a match is found */\n\t\t\tif(filters[i]->type == FILTER_INCLUDE)\n\t\t\t{\n\t\t\t\tfound = RESULT_EXCLUDE;\n\t\t\t}\n\n\t\t\tif(string_contains(description, filters[i]->filter))\n\t\t\t{\n\t\t\t\tfound = RESULT_INCLUDE;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t\n\t/* Check to see if description matches any exclude filters */\n\tfor(i=0; i<filter_count; i++)\n\t{\n\t\tif(filters[i]->type == FILTER_EXCLUDE)\n\t\t{\n\t\t\tif(string_contains(description, filters[i]->filter))\n\t\t\t{\n\t\t\t\tfound = RESULT_EXCLUDE;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn found;\n}\n\n/* Performs a case-insensitive string search */\nint string_contains(char *haystack, char *needle)\n{\n\tchar *my_haystack = NULL;\n\tint retval = 0;\n\n\t/* Duplicate the haystack string, as we will be converting it to all uppercase */\n\tmy_haystack = strdup(haystack);\n\n\tif(!my_haystack)\n\t{\n\t\tperror(\"strdup\");\n\t}\n\telse\n\t{\n\t\t/* Convert haystack to all upper case */\n\t\tuppercase(my_haystack);\n\n\t\t/* Search for needle in haystack */\n\t\tif(strstr(my_haystack, needle) != NULL)\n\t\t{\n\t\t\tretval = 1;\n\t\t}\n\t}\n\n\tif(my_haystack) free(my_haystack);\n\treturn retval;\n}\n\n/* Convert a given string to all upper case */\nvoid uppercase(char *string)\n{\n\tint i = 0;\n\n\tfor(i=0; i<strlen(string); i++)\n\t{\n\t\tstring[i] = toupper(string[i]);\n\t}\n\n\treturn;\n}\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/filter.h",
    "content": "#ifndef FILTER_H\n#define FILTER_H\n\n#define MAX_FILTERS 8192\n\nenum filter_type_t\n{\n\tFILTER_EXCLUDE,\n\tFILTER_INCLUDE,\n\tFILTER_ADD\n};\n\nenum filter_result_t\n{\n\tRESULT_NONE,\n\tRESULT_NOT_FOUND,\n\tRESULT_EXCLUDE,\n\tRESULT_INCLUDE\n};\n\nstruct magic_filter\n{\n        enum filter_type_t type;\n        char *filter;\n};\n\nint string_contains(char *haystack, char *needle);\nvoid add_filter(struct magic_filter *filters[], int *filter_count, enum filter_type_t type, char* filter);\nenum filter_result_t filter_check(struct magic_filter *filters[], int filter_count, char *description);\nvoid uppercase(char *string);\n\n#endif\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic/magic.archives",
    "content": "# ----------------------------Archive Formats--------------------------------------\n\n# POSIX tar archives\n257     string          ustar\\000         POSIX tar archive\n!:mime  application/x-tar # encoding: posix\n257     string          ustar\\040\\040\\000 GNU tar archive\n!:mime  application/x-tar # encoding: gnu\n\n# MIPS archive (needs to go before regular portable archives)\n#\n0       string  =!<arch>\\n__________E   MIPS archive\n>20     string  U                       with MIPS Ucode members\n>21     string  L                       with MIPSEL members\n>21     string  B                       with MIPSEB members\n>19     string  L                       and an EL hash table\n>19     string  B                       and an EB hash table\n>22     string  X                       -- out of date\n\n# JAR archiver (.j), this is the successor to ARJ, not Java's JAR (which is essentially ZIP)\n0xe     string  \\x1aJar\\x1b JAR (ARJ Software, Inc.) archive data\n0       string  JARCS JAR (ARJ Software, Inc.) archive data\n\n\n# ARJ archiver (jason@jarthur.Claremont.EDU)\n0       leshort         0xea60          ARJ archive data\n!:mime  application/x-arj\n>5      byte            x               \\b, v%d,\n>8      byte            &0x04           multi-volume,\n>8      byte            &0x10           slash-switched,\n>8      byte            &0x20           backup,\n>34     string          x               original name: %s,\n>7      byte            0               os: MS-DOS \n>7      byte            1               os: PRIMOS\n>7      byte            2               os: Unix\n>7      byte            3               os: Amiga\n>7      byte            4               os: Macintosh\n>7      byte            5               os: OS/2\n>7      byte            6               os: Apple ][ GS\n>7      byte            7               os: Atari ST\n>7      byte            8               os: NeXT\n>7      byte            9               os: VAX/VMS\n>3      byte            >0              %d]\n# [JW] idarc says this is also possible\n2       leshort         0xea60          ARJ archive data\n>5      byte            x               \\b, v%d,\n>8      byte            &0x04           multi-volume,\n>8      byte            &0x10           slash-switched,\n>8      byte            &0x20           backup,\n>34     string          x               original name: %s,\n>7      byte            0               os: MS-DOS\n>7      byte            1               os: PRIMOS\n>7      byte            2               os: Unix\n>7      byte            3               os: Amiga\n>7      byte            4               os: Macintosh\n>7      byte            5               os: OS/2\n>7      byte            6               os: Apple ][ GS\n>7      byte            7               os: Atari ST\n>7      byte            8               os: NeXT\n>7      byte            9               os: VAX/VMS\n>3      byte            >0              %d]\n\n# RAR archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\tRar!\t\tRAR archive data [NSRL|RAR]\n\n# HPACK archiver (Peter Gutmann, pgut1@cs.aukuni.ac.nz)\n0\tstring\t\tHPAK\t\tHPACK archive data [NSRL|HPAK]\n\n# JAM Archive volume format, by Dmitry.Kohmanyuk@UA.net\n0\tstring\t\t\\351,\\001JAM\\\t\tJAM archive, [NSRL|JAM]\n\n# LHARC/LHA archiver (Greg Roelofs, newt@uchicago.edu)\n2\tstring\t\t-lh0-\t\tLHarc 1.x archive data [lh0] [NSRL|LHA1]\n2\tstring\t\t-lh1-\t\tLHarc 1.x archive data [lh1] [NSRL|LHA1]\n2\tstring\t\t-lz4-\t\tLHarc 1.x archive data [lz4] [NSRL|LHA1]\n2\tstring\t\t-lz5-\t\tLHarc 1.x archive data [lz5] [NSRL|LHA1]\n#\t[never seen any but the last; -lh4- reported in comp.compression:]\n2\tstring\t\t-lzs-\t\tLHa 2.x? archive data [lzs] [NSRL|LHA2]\n2\tstring\t\t-lh\\40-\t\tLHa 2.x? archive data [lh ] [NSRL|LHA2]\n2\tstring\t\t-lhd-\t\tLHa 2.x? archive data [lhd] [NSRL|LHA2]\n2\tstring\t\t-lh2-\t\tLHa 2.x? archive data [lh2] [NSRL|LHA2]\n2\tstring\t\t-lh3-\t\tLHa 2.x? archive data [lh3] [NSRL|LHA2]\n2\tstring\t\t-lh4-\t\tLHa (2.x) archive data [lh4] [NSRL|LHA2]\n2\tstring\t\t-lh5-\t\tLHa (2.x) archive data [lh5] [NSRL|LHA2]\n2\tstring\t\t-lh6-\t\tLHa (2.x) archive data [lh6] [NSRL|LHA2]\n2\tstring\t\t-lh7-\t\tLHa (2.x) archive data [lh7] [NSRL|LHA2]\n\n# SQUISH archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\tSQSH\t\tsquished archive data (Acorn RISCOS) [NSRL|SQSH]\n\n# UC2 archiver (Greg Roelofs, newt@uchicago.edu)\n# I can't figure out the self-extracting form of these buggers...\n0\tstring\t\tUC2\\x1a\t\tUC2 archive data [NSRL|UC2]\n\n# Zoo archiver\n20\tlelong\t\t0xfdc4a7dc\tZoo archive data [NSRL|ZOO]\n\n# Shell archives\n# JT, 2004-03-17: The \"#\" in the middle of the line makes it look like the\n# rest of the line is commented out - I guess it's OK? Beware if parsing!\n10\tstring\t\t#\\ This\\ is\\ a\\ shell\\ archive\tshell archive text [NSRL|SH]\n\n#\n# LBR. NB: May conflict with the questionable \n#          \"binary Computer Graphics Metafile\" format.\n#\n0       string  \\0\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\0\\0    LBR archive data [NSRL|LBR]\n#\n# PMA (CP/M derivative of LHA)\n#\n2       string          -pm0-           PMarc archive data [pm0] [NSRL|PMA]\n2       string          -pm1-           PMarc archive data [pm1] [NSRL|PMA]\n2       string          -pm2-           PMarc archive data [pm2] [NSRL|PMA]\n2       string          -pms-           PMarc SFX archive (CP/M, DOS) [NSRL|PMA-SFX]\n5       string          -pc1-           PopCom compressed executable archive (CP/M) [NSRL|PPC-SFX]\n\n# From rafael@icp.inpg.fr (Rafael Laboissiere) \n# The Project Revision Control System (see\n# http://www.XCF.Berkeley.EDU/~jmacd/prcs.html) generates a packaged project\n# file which is recognized by the following entry:\n0\tleshort\t\t0xeb81\tPRCS packaged project archive [NSRL|PRCS]\n\n# GTKtalog catalogs \n# by David Necas (Yeti) <yeti@physics.muni.cz>\n4\tstring\tgtktalog\\ \tGTKtalog catalog data archive, [NSRL|GTK]\n>>14\tbeshort\t0x677a\t\t(gzipped)\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic/magic.bootloaders",
    "content": "\n#---------------------------Bootloaders--------------------------------\n\n# CFE bootloader\n0\tstring\tCFE1CFE1\tCFE boot loader, little endian\n0\tstring\t1EFC1EFC\tCFE boot loader, big endian\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic/magic.compressed",
    "content": "\n#------------------Compression Formats-----------------------------\n\n# bzip2\n0       string          BZh\n>4\tstring\t\t1AY&SY\t\tbzip2 compressed data\n!:mime  application/x-bzip2\n>>3      byte            >47            \\b, block size = %c00k\n\n# lzip  \n0       string          LZIP            lzip compressed data\n!:mime application/x-lzip\n>4      byte            x               \\b, version: %d\n\n# LZO\n0\tstring\t\t\\211LZO\\000\\015\\012\\032\\012\tLZO compressed data\n\n# 7-zip archiver, from Thomas Klausner (wiz@danbala.tuwien.ac.at)\n# http://www.7-zip.org or DOC/7zFormat.txt \n#\n0       string          7z\\274\\257\\047\\034      7-zip archive data,\n>6      byte            x                       version %d\n>7      byte            x                       \\b.%d\n\n# standard unix compress\n0       beshort\t\t0x1f9d          compress'd data\n>2      byte&0x80       >0              block compressed\n>2      byte&0x1f       x               %d bits\n\n# gzip (GNU zip, not to be confused with Info-ZIP or PKWARE zip archiver)\n#   Edited by Chris Chittleborough <cchittleborough@yahoo.com.au>, March 2002\n#       * Original filename is only at offset 10 if \"extra field\" absent\n#       * Produce shorter output - notably, only report compression methods\n#         other than 8 (\"deflate\", the only method defined in RFC 1952).\n0       string          \\037\\213        gzip compressed data\n!:mime  application/x-gzip\n>2      byte            <8              \\b, reserved (invalid) method\n>2      byte            >8              \\b, unknown (invalid) method\n>3      byte            &0x01           \\b, ASCII\n>3      byte            &0x02           \\b, has CRC\n>3      byte            &0x04           \\b, extra field\n>3      byte&0xC        =0x08\n>>10    string          x               \\b, was \"%s\"\n>3      byte            &0x10           \\b, has comment\n>9      byte            =0x00           \\b, from FAT filesystem (MS-DOS, OS/2, NT)\n>9      byte            =0x01           \\b, from Amiga\n>9      byte            =0x02           \\b, from VMS\n>9      byte            =0x03           \\b, from Unix\n>9      byte            =0x04           \\b, from VM/CMS\n>9      byte            =0x05           \\b, from Atari\n>9      byte            =0x06           \\b, from HPFS filesystem (OS/2, NT)\n>9      byte            =0x07           \\b, from MacOS\n>9      byte            =0x08           \\b, from Z-System\n>9      byte            =0x09           \\b, from CP/M\n>9      byte            =0x0A           \\b, from TOPS/20\n>9      byte            =0x0B           \\b, from NTFS filesystem (NT)\n>9      byte            =0x0C           \\b, from QDOS\n>9      byte            =0x0D           \\b, from Acorn RISCOS\n>9\tbyte\t\t>0x0D\t\t\\b, invalid source\n>3      byte            &0x10           \\b, comment\n>3      byte            &0x20           \\b, encrypted\n# Dates before 1992 are invalid, unless of course you're DD-WRT in which\n# case you don't know how to set a date in your gzip files. Brilliant.\n>4\tlelong\t\t=0\t\t\\b, DD-WRT date:\n>4\tlelong\t\t<0\t\t\\b, invalid date:\n>4\tlelong\t\t>0\t\t\n>>4\tlelong\t\t<694224000\t\\b, invalid date:\n>>4\tlelong\t\t=694224000\t\\b, invalid date:\n>>4\tlelong\t\t>694224000\t\\b, last modified:\n>4      ledate          x               %s\n>8      byte            2               \\b, max compression\n>8      byte            4               \\b, max speed\n\n# Zlib signatures\n0\tbeshort\t\t0x789C\t\tzlib compressed data\n0\tbeshort\t\t0x78DA\t\tzlib compressed data\n0\tbeshort\t\t0x7801\t\tzlib compressed data\n\n# Supplementary magic data for the file(1) command to support\n# rzip(1).  The format is described in magic(5).\n#\n# Copyright (C) 2003 by Andrew Tridgell.  You may do whatever you want with\n# this file.\n#\n0       string          RZIP            rzip compressed data\n>4      byte            x               - version %d\n>5      byte            x               \\b.%d\n>6      belong          x               (%d bytes)\n\n# ZIP compression (Greg Roelofs, c/o zip-bugs@wkuvx1.wku.edu)\n0       string          PK\\003\\004      Zip archive data, \n>4      byte            0x00            v0.0\n!:mime  application/zip \n>4      byte            0x09            at least v0.9 to extract\n!:mime  application/zip \n>4      byte            0x0a            at least v1.0 to extract\n!:mime  application/zip \n>4      byte            0x0b            at least v1.1 to extract\n!:mime  application/zip\n>0x161  string          WINZIP          WinZIP self-extracting\n!:mime  application/zip\n>4      byte            0x14\n>>30    ubelong         !0x6d696d65     at least v2.0 to extract\n!:mime  application/zip\n\n# Alternate ZIP string (amc@arwen.cs.berkeley.edu)\n0       string          PK00PK\\003\\004  Zip archive data [NSRL|ZIP]\n\n# Type: LZMA            \n# URL:  http://www.7-zip.org/sdk.html   \n#\n# Added additional parsing to help verify LZMA matches and weed out false positives.\n# Added improved signature checking.\n# Added checks for possibly (probably) invalid matches.\n# From: Craig Heffner\n\n#First LZMA signature\n0       string                  \\x5d\\x00\\x00            LZMA compressed data,\n>0\tleshort\t\t\t>0xE0\t\t\tinvalid\n>0\tbyte\t\t\tx\t\t\tproperties: 0x%.2X,\n>1\tlelong\t\t\t<1\t\t\tinvalid\n>1\tlelong\t\t\tx\t\t\tdictionary size: %d bytes,\n>5\tlequad\t\t\t0\t\t\tinvalid\n>5\tlequad\t\t\t<0\t\t\tinvalid\n>5\tlequad\t\t\t>0x40000000\t\tinvalid\n>5\tlequad\t\t\tx\t\t\tuncompressed size: %lld bytes\n\n#An alternative common LZMA signature\n1\tbelong\t\t\t0x00008000\t\tLZMA compressed data,\n>0\tbyte\t\t\t0\t\t\tinvalid\n>0\tleshort\t\t\t>0xE0\t\t\tinvalid\n>0\tbyte\t\t\tx\t\t\tproperties: 0x%.2X,\n>1      lelong                  <1                      invalid\n>1      lelong                  x                       dictionary size: %d bytes,\n>5\tlequad\t\t\t0\t\t\tinvalid\n>5      lequad                  <0                      invalid\n>5\tlequad\t\t\t>0x40000000\t\tinvalid\n>5      lequad                  x                       uncompressed size: %lld bytes\n\n#Signature for less common LZMA flag/dictionary values. Results in lots of false positives, but usually marked as invalid.\n1\tbeshort\t\t\t0x0000\t\t\tLZMA compressed data,\n>0\tbyte\t\t\t0\t\t\tinvalid\n>0\tbyte\t\t\t>0xE0\t\t\tinvalid\n>0\tbyte\t\t\tx\t\t\tproperties: 0x%.2X,\n>1\tlelong\t\t\t<1\t\t\tinvalid\n>1\tlelong\t\t\tx\t\t\tdictionary size: %d bytes,\n>5\tlequad\t\t\t0\t\t\tinvalid\n>5\tlequad\t\t\t<0\t\t\tinvalid\n>5\tlequad\t\t\t>0x40000000\t\tinvalid\n>5\tlequad\t\t\tx\t\t\tuncompressed size: %lld bytes\n\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic/magic.executables",
    "content": "\n#------------------Standard file formats------------------------------------\n\n# elf:  file(1) magic for ELF executables\n#\n# We have to check the byte order flag to see what byte order all the\n# other stuff in the header is in.\n#\n# What're the correct byte orders for the nCUBE and the Fujitsu VPP500?\n#\n# Created by: unknown\n# Modified by (1): Daniel Quinlan <quinlan@yggdrasil.com>\n# Modified by (2): Peter Tobias <tobias@server.et-inf.fho-emden.de> (core support)\n# Modified by (3): Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de> (fix of core support)\n# Modified by (4): <gerardo.cacciari@gmail.com> (VMS Itanium)\n# Modified by (5): Matthias Urlichs <smurf@debian.org> (Listing of many architectures)\n0       string          \\177ELF         ELF\n>4      byte            0               invalid class\n>4      byte            1               32-bit\n>4      byte            2               64-bit\n>5      byte            0               invalid byte order\n>5      byte            1               LSB\n>>16    leshort         0               no file type,\n!:strength *2\n!:mime  application/octet-stream\n>>16    leshort         1               relocatable,\n!:mime  application/x-object\n>>16    leshort         2               executable,\n!:mime  application/x-executable\n>>16    leshort         3               shared object,\n!:mime  application/x-sharedlib\n>>16    leshort         4               core file\n!:mime  application/x-coredump\n# Core file detection is not reliable.\n#>>>(0x38+0xcc) string  >\\0             of '%s'\n#>>>(0x38+0x10) lelong  >0              (signal %d),\n>>16    leshort         &0xff00         processor-specific,\n>>18    leshort         0               no machine,\n>>18    leshort         1               AT&T WE32100 - invalid byte order,\n>>18    leshort         2               SPARC - invalid byte order,\n>>18    leshort         3               Intel 80386,\n>>18    leshort         4               Motorola\n>>>36   lelong          &0x01000000     68000 - invalid byte order,\n>>>36   lelong          &0x00810000     CPU32 - invalid byte order,\n>>>36   lelong          0               68020 - invalid byte order,\n>>18    leshort         5               Motorola 88000 - invalid byte order,\n>>18    leshort         6               Intel 80486,\n>>18    leshort         7               Intel 80860,\n# The official e_machine number for MIPS is now #8, regardless of endianness.\n# The second number (#10) will be deprecated later. For now, we still\n# say something if #10 is encountered, but only gory details for #8.\n>>18    leshort         8               MIPS,\n>>>36   lelong          &0x20           N32\n>>18    leshort         10              MIPS,\n>>>36   lelong          &0x20           N32\n>>18    leshort         8\n# only for 32-bit\n>>>4    byte            1\n>>>>36  lelong&0xf0000000       0x00000000      MIPS-I\n>>>>36  lelong&0xf0000000       0x10000000      MIPS-II\n>>>>36  lelong&0xf0000000       0x20000000      MIPS-III\n>>>>36  lelong&0xf0000000       0x30000000      MIPS-IV\n>>>>36  lelong&0xf0000000       0x40000000      MIPS-V\n>>>>36  lelong&0xf0000000       0x50000000      MIPS32\n>>>>36  lelong&0xf0000000       0x60000000      MIPS64\n>>>>36  lelong&0xf0000000       0x70000000      MIPS32 rel2\n>>>>36  lelong&0xf0000000       0x80000000      MIPS64 rel2\n# only for 64-bit\n>>>4    byte            2\n>>>>48  lelong&0xf0000000       0x00000000      MIPS-I\n>>>>48  lelong&0xf0000000       0x10000000      MIPS-II\n>>>>48  lelong&0xf0000000       0x20000000      MIPS-III\n>>>>48  lelong&0xf0000000       0x30000000      MIPS-IV\n>>>>48  lelong&0xf0000000       0x40000000      MIPS-V\n>>>>48  lelong&0xf0000000       0x50000000      MIPS32\n>>>>48  lelong&0xf0000000       0x60000000      MIPS64\n>>>>48  lelong&0xf0000000       0x70000000      MIPS32 rel2\n>>>>48  lelong&0xf0000000       0x80000000      MIPS64 rel2\n>>18    leshort         9               Amdahl - invalid byte order,\n>>18    leshort         10              MIPS (deprecated),\n>>18    leshort         11              RS6000 - invalid byte order,\n>>18    leshort         15              PA-RISC - invalid byte order,\n>>>50   leshort         0x0214          2.0\n>>>48   leshort         &0x0008         (LP64),\n>>18    leshort         16              nCUBE,\n>>18    leshort         17              Fujitsu VPP500,\n>>18    leshort         18              SPARC32PLUS - invalid byte order,\n>>18    leshort         20              PowerPC,\n>>18    leshort         22              IBM S/390,\n>>18    leshort         36              NEC V800,\n>>18    leshort         37              Fujitsu FR20,\n>>18    leshort         38              TRW RH-32,\n>>18    leshort         39              Motorola RCE,\n>>18    leshort         40              ARM,\n>>18    leshort         41              Alpha,\n>>18    leshort         0xa390          IBM S/390 (obsolete),\n>>18    leshort         42              Renesas SH,\n>>18    leshort         43              SPARC V9 - invalid byte order,\n>>18    leshort         44              Siemens Tricore Embedded Processor,\n>>18    leshort         45              Argonaut RISC Core, Argonaut Technologies Inc.,\n>>18    leshort         46              Renesas H8/300,\n>>18    leshort         47              Renesas H8/300H,\n>>18    leshort         48              Renesas H8S,\n>>18    leshort         49              Renesas H8/500,\n>>18    leshort         50              IA-64,\n>>18    leshort         51              Stanford MIPS-X,\n>>18    leshort         52              Motorola Coldfire,\n>>18    leshort         53              Motorola M68HC12,\n>>18    leshort         54              Fujitsu MMA,\n>>18    leshort         55              Siemens PCP,\n>>18    leshort         56              Sony nCPU,\n>>18    leshort         57              Denso NDR1,\n>>18    leshort         58              Start*Core,\n>>18    leshort         59              Toyota ME16,\n>>18    leshort         60              ST100,\n>>18    leshort         61              Tinyj emb.,\n>>18    leshort         62              x86-64,\n>>18    leshort         63              Sony DSP,\n>>18    leshort         66              FX66,\n>>18    leshort         67              ST9+ 8/16 bit,\n>>18    leshort         68              ST7 8 bit,\n>>18    leshort         69              MC68HC16,\n>>18    leshort         70              MC68HC11,\n>>18    leshort         71              MC68HC08,\n>>18    leshort         72              MC68HC05,\n>>18    leshort         73              SGI SVx,\n>>18    leshort         74              ST19 8 bit,\n>>18    leshort         75              Digital VAX,\n>>18    leshort         76              Axis cris,\n>>18    leshort         77              Infineon 32-bit embedded,\n>>18    leshort         78              Element 14 64-bit DSP,\n>>18    leshort         79              LSI Logic 16-bit DSP,\n>>18    leshort         80              MMIX,\n>>18    leshort         81              Harvard machine-independent,\n>>18    leshort         82              SiTera Prism,\n>>18    leshort         83              Atmel AVR 8-bit,\n>>18    leshort         84              Fujitsu FR30,\n>>18    leshort         85              Mitsubishi D10V,\n>>18    leshort         86              Mitsubishi D30V,\n>>18    leshort         87              NEC v850,\n>>18    leshort         88              Renesas M32R,\n>>18    leshort         89              Matsushita MN10300,\n>>18    leshort         90              Matsushita MN10200,\n>>18    leshort         91              picoJava,\n>>18    leshort         92              OpenRISC,\n>>18    leshort         93              ARC Cores Tangent-A5,\n>>18    leshort         94              Tensilica Xtensa,\n>>18    leshort         97              NatSemi 32k,\n>>18    leshort         106             Analog Devices Blackfin,\n>>18    leshort         113             Altera Nios II,\n>>18    leshort         0xae            META,\n>>18    leshort         0x3426          OpenRISC (obsolete),\n>>18    leshort         0x8472          OpenRISC (obsolete),\n>>18    leshort         0x9026          Alpha (unofficial),\n>>20    lelong          0               invalid version\n>>20    lelong          1               version 1\n>>36    lelong          1               MathCoPro/FPU/MAU Required\n>5      byte            2               MSB\n>>16    beshort         0               no file type,\n!:mime  application/octet-stream\n>>16    beshort         1               relocatable,\n!:mime  application/x-object\n>>16    beshort         2               executable,\n!:mime  application/x-executable\n>>16    beshort         3               shared object,\n!:mime  application/x-sharedlib\n>>16    beshort         4               core file,\n!:mime  application/x-coredump\n#>>>(0x38+0xcc) string  >\\0             of '%s'\n#>>>(0x38+0x10) belong  >0              (signal %d),\n>>16    beshort         &0xff00         processor-specific,\n>>18    beshort         0               no machine,\n>>18    beshort         1               AT&T WE32100,\n>>18    beshort         2               SPARC,\n>>18    beshort         3               Intel 80386 - invalid byte order,\n>>18    beshort         4               Motorola\n>>>36   belong          &0x01000000     68000,\n>>>36   belong          &0x00810000     CPU32,\n>>>36   belong          0               68020,\n>>18    beshort         5               Motorola 88000,\n>>18    beshort         6               Intel 80486 - invalid byte order,\n>>18    beshort         7               Intel 80860,\n# only for MIPS - see comment in little-endian section above.\n>>18    beshort         8               MIPS,\n>>>36   belong          &0x20           N32\n>>18    beshort         10              MIPS,\n>>>36   belong          &0x20           N32\n>>18    beshort         8\n# only for 32-bit\n>>>4    byte            1\n>>>>36  belong&0xf0000000       0x00000000      MIPS-I\n>>>>36  belong&0xf0000000       0x10000000      MIPS-II\n>>>>36  belong&0xf0000000       0x20000000      MIPS-III\n>>>>36  belong&0xf0000000       0x30000000      MIPS-IV\n>>>>36  belong&0xf0000000       0x40000000      MIPS-V\n>>>>36  belong&0xf0000000       0x50000000      MIPS32\n>>>>36  belong&0xf0000000       0x60000000      MIPS64\n>>>>36  belong&0xf0000000       0x70000000      MIPS32 rel2\n>>>>36  belong&0xf0000000       0x80000000      MIPS64 rel2\n# only for 64-bit\n>>>4    byte            2\n>>>>48  belong&0xf0000000       0x00000000      MIPS-I\n>>>>48  belong&0xf0000000       0x10000000      MIPS-II\n>>>>48  belong&0xf0000000       0x20000000      MIPS-III\n>>>>48  belong&0xf0000000       0x30000000      MIPS-IV\n>>>>48  belong&0xf0000000       0x40000000      MIPS-V\n>>>>48  belong&0xf0000000       0x50000000      MIPS32\n>>>>48  belong&0xf0000000       0x60000000      MIPS64\n>>>>48  belong&0xf0000000       0x70000000      MIPS32 rel2\n>>>>48  belong&0xf0000000       0x80000000      MIPS64 rel2\n>>18    beshort         9               Amdahl,\n>>18    beshort         10              MIPS (deprecated),\n>>18    beshort         11              RS6000,\n>>18    beshort         15              PA-RISC\n>>>50   beshort         0x0214          2.0\n>>>48   beshort         &0x0008         (LP64)\n>>18    beshort         16              nCUBE,\n>>18    beshort         17              Fujitsu VPP500,\n>>18    beshort         18              SPARC32PLUS,\n>>>36   belong&0xffff00 0x000100        V8+ Required,\n>>>36   belong&0xffff00 0x000200        Sun UltraSPARC1 Extensions Required,\n>>>36   belong&0xffff00 0x000400        HaL R1 Extensions Required,\n>>>36   belong&0xffff00 0x000800        Sun UltraSPARC3 Extensions Required,\n>>18    beshort         20              PowerPC or cisco 4500,\n>>18    beshort         21              64-bit PowerPC or cisco 7500,\n>>18    beshort         22              IBM S/390,\n>>18    beshort         23              Cell SPU,\n>>18    beshort         24              cisco SVIP,\n>>18    beshort         25              cisco 7200,\n>>18    beshort         36              NEC V800 or cisco 12000,\n>>18    beshort         37              Fujitsu FR20,\n>>18    beshort         38              TRW RH-32,\n>>18    beshort         39              Motorola RCE,\n>>18    beshort         40              ARM,\n>>18    beshort         41              Alpha,\n>>18    beshort         42              Renesas SH,\n>>18    beshort         43              SPARC V9,\n>>>48   belong&0xffff00 0x000200        Sun UltraSPARC1 Extensions Required,\n>>>48   belong&0xffff00 0x000400        HaL R1 Extensions Required,\n>>>48   belong&0xffff00 0x000800        Sun UltraSPARC3 Extensions Required,\n>>>48   belong&0x3      0               total store ordering,\n>>>48   belong&0x3      1               partial store ordering,\n>>>48   belong&0x3      2               relaxed memory ordering,\n>>18    beshort         44              Siemens Tricore Embedded Processor,\n>>18    beshort         45              Argonaut RISC Core, Argonaut Technologies Inc.,\n>>18    beshort         46              Renesas H8/300,\n>>18    beshort         47              Renesas H8/300H,\n>>18    beshort         48              Renesas H8S,\n>>18    beshort         49              Renesas H8/500,\n>>18    beshort         50              IA-64,\n>>18    beshort         51              Stanford MIPS-X,\n>>18    beshort         52              Motorola Coldfire,\n>>18    beshort         53              Motorola M68HC12,\n>>18    beshort         73              Cray NV1,\n>>18    beshort         75              Digital VAX,\n>>18    beshort         88              Renesas M32R,\n>>18    leshort         92              OpenRISC,\n>>18    leshort         0x3426          OpenRISC (obsolete),\n>>18    leshort         0x8472          OpenRISC (obsolete),\n>>18    beshort         94              Tensilica Xtensa,\n>>18    beshort         97              NatSemi 32k,\n>>18    beshort         0x18ad          AVR32 (unofficial),\n>>18    beshort         0x9026          Alpha (unofficial),\n>>18    beshort         0xa390          IBM S/390 (obsolete),\n>>20    belong          0               invalid version\n>>20    belong          1               version 1\n>>36    belong          1               MathCoPro/FPU/MAU Required\n# Up to now only 0, 1 and 2 are defined; I've seen a file with 0x83, it seemed\n# like proper ELF, but extracting the string had bad results.\n>4      byte            <0x80\n>>8     string          >\\0             (%s)\n>8      string          \\0\n>>7     byte            0               (SYSV)\n>>7     byte            1               (HP-UX)\n>>7     byte            2               (NetBSD)\n>>7     byte            3               (GNU/Linux)\n>>7     byte            4               (GNU/Hurd)\n>>7     byte            5               (86Open)\n>>7     byte            6               (Solaris)\n>>7     byte            7               (Monterey)\n>>7     byte            8               (IRIX)\n>>7     byte            9               (FreeBSD)\n>>7     byte            10              (Tru64)\n>>7     byte            11              (Novell Modesto)\n>>7     byte            12              (OpenBSD)\n>8      string          \\2\n>>7     byte            13              (OpenVMS)\n>>7     byte            97              (ARM)\n>>7     byte            255             (embedded)\n\n\n\n# XXX - according to Microsoft's spec, at an offset of 0x3c in a\n# PE-format executable is the offset in the file of the PE header;\n# unfortunately, that's a little-endian offset, and there's no way\n# to specify an indirect offset with a specified byte order.\n# So, for now, we assume the standard MS-DOS stub, which puts the\n# PE header at 0x80 = 128.\n#\n# Required OS version and subsystem version were 4.0 on some NT 3.51\n# executables built with Visual C++ 4.0, so it's not clear that\n# they're interesting.  The user version was 0.0, but there's\n# probably some linker directive to set it.  The linker version was\n# 3.0, except for one \".exe\" which had it as 4.20 (same damn linker!).\n#\n# many of the compressed formats were extraced from IDARC 1.23 source code\n#\n0       string  MZ\n!:mime  application/x-dosexec\n>0x18  leshort <0x40 MS-DOS executable\n>0 string MZ\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0PE\\0\\0 \\b, PE for MS Windows\n>>&18   leshort&0x2000  >0      (DLL)\n>>&88   leshort         0       (unknown subsystem)\n>>&88   leshort         1       (native)\n>>&88   leshort         2       (GUI)\n>>&88   leshort         3       (console)\n>>&88   leshort         7       (POSIX)\n>>&0    leshort         0x0     unknown processor\n>>&0    leshort         0x14c   Intel 80386\n>>&0    leshort         0x166   MIPS R4000\n>>&0    leshort         0x184   Alpha\n>>&0    leshort         0x268   Motorola 68000\n>>&0    leshort         0x1f0   PowerPC\n>>&0    leshort         0x290   PA-RISC\n>>&18   leshort&0x0100  >0      32-bit\n>>&18   leshort&0x1000  >0      system file\n>>&228  lelong          >0      \\b, Mono/.Net assembly\n>>&0xf4 search/0x140 \\x0\\x40\\x1\\x0\n>>>(&0.l+(4)) string MSCF \\b, WinHKI CAB self-extracting archive\n>30             string  Copyright\\ 1989-1990\\ PKWARE\\ Inc.      Self-extracting PKZIP archive\n!:mime  application/zip\n# Is next line correct? One might expect \"Corp.\" not \"Copr.\" If it is right, add a note to that effect.\n>30             string  PKLITE\\ Copr.   Self-extracting PKZIP archive\n!:mime  application/zip\n\n>0x18  leshort >0x3f\n>>(0x3c.l) string PE\\0\\0 PE\n>>>(0x3c.l+25) byte             1 \\b32 executable\n>>>(0x3c.l+25) byte             2 \\b32+ executable\n# hooray, there's a DOS extender using the PE format, with a valid PE\n# executable inside (which just prints a message and exits if run in win)\n>>>(0x3c.l+92)  leshort         <10\n>>>>(8.s*16) string 32STUB for MS-DOS, 32rtm DOS extender\n>>>>(8.s*16) string !32STUB for MS Windows\n>>>>>(0x3c.l+22)        leshort&0x2000  >0      (DLL)\n>>>>>(0x3c.l+92)        leshort         0       (unknown subsystem)\n>>>>>(0x3c.l+92)        leshort         1       (native)\n>>>>>(0x3c.l+92)        leshort         2       (GUI)\n>>>>>(0x3c.l+92)        leshort         3       (console)\n>>>>>(0x3c.l+92)        leshort         7       (POSIX)\n>>>(0x3c.l+92)  leshort         10      (EFI application)\n>>>(0x3c.l+92)  leshort         11      (EFI boot service driver)\n>>>(0x3c.l+92)  leshort         12      (EFI runtime driver)\n>>>(0x3c.l+92)  leshort         13      (XBOX)\n>>>(0x3c.l+4)   leshort         0x0     unknown processor\n>>>(0x3c.l+4)   leshort         0x14c   Intel 80386\n>>>(0x3c.l+4)   leshort         0x166   MIPS R4000\n>>>(0x3c.l+4)   leshort         0x184   Alpha\n>>>(0x3c.l+4)   leshort         0x268   Motorola 68000\n>>>(0x3c.l+4)   leshort         0x1f0   PowerPC\n>>>(0x3c.l+4)   leshort         0x290   PA-RISC\n>>>(0x3c.l+4)   leshort         0x200   Intel Itanium\n>>>(0x3c.l+22)  leshort&0x0100  >0      32-bit\n>>>(0x3c.l+22)  leshort&0x1000  >0      system file\n>>>(0x3c.l+232) lelong  >0      Mono/.Net assembly\n>>>>(0x3c.l+0xf8)       string          UPX0 \\b, UPX compressed\n>>>>(0x3c.l+0xf8)       search/0x140    PEC2 \\b, PECompact2 compressed\n>>>>(0x3c.l+0xf8)       search/0x140    UPX2\n>>>>>(&0x10.l+(-4))     string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>(0x3c.l+0xf8)       search/0x140    .idata\n>>>>>(&0xe.l+(-4))      string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>>(&0xe.l+(-4))      string          ZZ0 \\b, ZZip self-extracting archive\n>>>>>(&0xe.l+(-4))      string          ZZ1 \\b, ZZip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .rsrc\n>>>>>(&0x0f.l+(-4))     string          a\\\\\\4\\5 \\b, WinHKI self-extracting archive\n>>>>>(&0x0f.l+(-4))     string          Rar! \\b, RAR self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/0x3000   MSCF \\b, InstallShield self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/32       Nullsoft \\b, Nullsoft Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .data\n>>>>>(&0x0f.l)          string          WEXTRACT \\b, MS CAB-Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .petite\\0 \\b, Petite compressed\n>>>>>(0x3c.l+0xf7)      byte            x\n>>>>>>(&0x104.l+(-4))   string          =!sfx! \\b, ACE self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .WISE \\b, WISE installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .dz\\0\\0\\0 \\b, Dzip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .reloc\n>>>>>(&0xe.l+(-4))      search/0x180    PK\\3\\4 \\b, ZIP self-extracting archive (WinZip)\n\n>>>>&(0x3c.l+0xf8)      search/0x100    _winzip_ \\b, ZIP self-extracting archive (WinZip)\n>>>>&(0x3c.l+0xf8)      search/0x100    SharedD \\b, Microsoft Installer self-extracting archive\n>>>>0x30                string          Inno \\b, InnoSetup self-extracting archive\n\n>>(0x3c.l) string !PE\\0\\0 MS-DOS executable\n\n>>(0x3c.l)              string          NE \\b, NE\n>>>(0x3c.l+0x36)        byte            0 (unknown OS)\n>>>(0x3c.l+0x36)        byte            1 for OS/2 1.x\n>>>(0x3c.l+0x36)        byte            2 for MS Windows 3.x\n>>>(0x3c.l+0x36)        byte            3 for MS-DOS\n>>>(0x3c.l+0x36)        byte            >3 (unknown OS)\n>>>(0x3c.l+0x36)        byte            0x81 for MS-DOS, Phar Lap DOS extender\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8002 (DLL)\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8001 (driver)\n>>>&(&0x24.s-1)         string          ARJSFX \\b, ARJ self-extracting archive\n>>>(0x3c.l+0x70)        search/0x80     WinZip(R)\\ Self-Extractor \\b, ZIP self-extracting archive (WinZip)\n\n>>(0x3c.l)              string          LX\\0\\0 \\b, LX\n>>>(0x3c.l+0x0a)        leshort         <1 (unknown OS)\n>>>(0x3c.l+0x0a)        leshort         1 for OS/2\n>>>(0x3c.l+0x0a)        leshort         2 for MS Windows\n>>>(0x3c.l+0x0a)        leshort         3 for DOS\n>>>(0x3c.l+0x0a)        leshort         >3 (unknown OS)\n>>>(0x3c.l+0x10)        lelong&0x28000  =0x8000 (DLL)\n>>>(0x3c.l+0x10)        lelong&0x20000  >0 (device driver)\n>>>(0x3c.l+0x10)        lelong&0x300    0x300 (GUI)\n>>>(0x3c.l+0x10)        lelong&0x28300  <0x300 (console)\n>>>(0x3c.l+0x08)        leshort         1 i80286\n>>>(0x3c.l+0x08)        leshort         2 i80386\n>>>(0x3c.l+0x08)        leshort         3 i80486\n>>>(8.s*16)             string          emx \\b, emx\n>>>>&1                  string          x %s\n>>>&(&0x54.l-3)         string          arjsfx \\b, ARJ self-extracting archive\n\n\n\n#------------------------------------------------------------------------------\n# bFLT: file(1) magic for BFLT uclinux binary files\n#\n# From Philippe De Muyter <phdm@macqel.be>\n# \n# Additional fields added by Craig Heffner\n#\n0       string          bFLT            BFLT executable \n>4      belong          x               version %ld, \n>4      belong          4\n>8\tbelong\t\tx\t\tcode offset: 0x%.8X, \n>12\tbelong\t\tx\t\tdata segment starts at: 0x%.8X, \n>16\tbelong\t\tx\t\tbss segment starts at: 0x%.8X, \n>20\tbelong\t\tx\t\tbss segment ends at: 0x%.8X, \n>24\tbelong\t\tx\t\tstack size: %d bytes, \n>28\tbelong \t\tx\t\trelocation records start at: 0x%.8X, \n>32\tbelong\t\tx\t\tnumber of reolcation records: %d, \n>>36    belong&0x1      0x1             ram\n>>36    belong&0x2      0x2             gotpic\n>>36    belong&0x4      0x4             gzip\n>>36    belong&0x8      0x8             gzdata\n\n\n#-----------------------------------------------------------------\n# MIPS COFF file formats\n#\n0       beshort 0x0160          MIPSEB ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x0162          MIPSEL-BE ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x6001          MIPSEB-LE ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x6201          MIPSEL ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n# MIPS 2 additions\n#\n0       beshort 0x0163          MIPSEB MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x0166          MIPSEL-BE MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x6301          MIPSEB-LE MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x6601          MIPSEL MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n# MIPS 3 additions\n#\n0       beshort 0x0140          MIPSEB MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x0142          MIPSEL-BE MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x4001          MIPSEB-LE MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x4201          MIPSEL MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x180           MIPSEB Ucode\n0       beshort 0x182           MIPSEL-BE Ucode\n\n\n# Windows CE package files\n0       string          MSCE\\0\\0\\0\\0    Microsoft WinCE installer\n>20     lelong          0               \\b, architecture-independent\n>20     lelong          103             \\b, Hitachi SH3\n>20     lelong          104             \\b, Hitachi SH4\n>20     lelong          0xA11           \\b, StrongARM\n>20     lelong          4000            \\b, MIPS R4000\n>20     lelong          10003           \\b, Hitachi SH3\n>20     lelong          10004           \\b, Hitachi SH3E\n>20     lelong          10005           \\b, Hitachi SH4\n>20     lelong          70001           \\b, ARM 7TDMI\n>52     leshort         1               \\b, 1 file\n>52     leshort         >1              \\b, %u files\n>56     leshort         1               \\b, 1 registry entry\n>56     leshort         >1              \\b, %u registry entries\n\n#------------------------------------------------------------------------------\n# Microsoft Xbox executables .xbe (Esa HyytiÃ¤ <ehyytia@cc.hut.fi>)\n0       string          XBEH            XBE, Microsoft Xbox executable\n# probabilistic checks whether signed or not\n>0x0004 ulelong =0x0\n>>&2    ulelong =0x0\n>>>&2   ulelong =0x0  \\b, not signed\n>0x0004 ulelong >0\n>>&2    ulelong >0\n>>>&2   ulelong >0    \\b, signed\n# expect base address of 0x10000\n>0x0104               ulelong =0x10000\n>>(0x0118-0x0FF60)    ulelong&0x80000007  0x80000007 \\b, all regions\n>>(0x0118-0x0FF60)    ulelong&0x80000007  !0x80000007\n>>>(0x0118-0x0FF60)   ulelong >0           (regions:\n>>>>(0x0118-0x0FF60)  ulelong &0x00000001  NA\n>>>>(0x0118-0x0FF60)  ulelong &0x00000002  Japan\n>>>>(0x0118-0x0FF60)  ulelong &0x00000004  Rest_of_World\n>>>>(0x0118-0x0FF60)  ulelong &0x80000000  Manufacturer\n>>>(0x0118-0x0FF60)   ulelong >0           \\b)\n\n#------------------------------------------------------------------------------\n# motorola:  file(1) magic for Motorola 68K and 88K binaries\n#\n# 68K\n#\n0       beshort         0x0208          mc68k COFF\n>18     beshort         ^00000020       object\n>18     beshort         &00000020       executable\n>12     belong          >0              not stripped\n>168    string          .lowmem         Apple toolbox\n>20     beshort         0407            (impure)\n>20     beshort         0410            (pure)\n>20     beshort         0413            (demand paged)\n>20     beshort         0421            (standalone)\n0       beshort         0x0209          mc68k executable (shared)\n>12     belong          >0              not stripped\n0       beshort         0x020A          mc68k executable (shared demand paged)\n>12     belong          >0              not stripped\n\n\n#\n# Motorola/UniSoft 68K Binary Compatibility Standard (BCS)\n#\n0       beshort         0x022A            68K BCS executable\n#\n# 88K\n#\n# Motorola/88Open BCS\n#\n0       beshort         0x022B            88K BCS executable\n\n#------------------------------------------------------------------------------\n# Sony Playstation executables (Adam Sjoegren <asjo@diku.dk>) :\n0       string  PS-X\\ EXE       Sony Playstation executable\n#  Area:\n>113    string  x               (%s)\n\n#------------------------------------------------------------------------------\n# cisco:  file(1) magic for cisco Systems routers\n#\n# Most cisco file-formats are covered by the generic elf code\n#\n# Microcode files are non-ELF, 0x8501 conflicts with NetBSD/alpha.\n0\tbeshort\t\t\t0x8501\t    cisco IOS\n>0      belong&0xffffff00       0x85011400  microcode\n>0      belong&0xffffff00       0x8501cb00  experimental microcode\n>7      string          \t>\\0         for '%s'\n\n\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic/magic.filesystems",
    "content": "#--------------------File Systems---------------------\n\n# Minix filesystems - Juan Cespedes <cespedes@debian.org>\n# Disabled for now until better signatures can be created. Too many false positives.\n#0x410   leshort         0x137f          Minix filesystem\n#>0x402  beshort         !0              \\b, %d zones\n#>0x1e   string          minix           \\b, bootable\n#0x410   leshort         0x138f          Minix filesystem, 30 char names\n#0x410   leshort         0x2468          Minix filesystem, version 2\n#0x410   leshort         0x2478          Minix filesystem, version 2, 30 char names\n\n#0x410   beshort         0x137f          Minix filesystem (big endian)\n#>0x402  beshort         !0              \\b, %d zones\n#>0x1e   string          minix           \\b, bootable\n#0x410   beshort         0x138f          Minix filesystem (big endian), 30 char names\n#0x410   beshort         0x2468          Minix filesystem (big endian), version 2\n#0x410   beshort         0x2478          Minix filesystem (big endian), version 2, 30 char names\n\n# YAFFS\n0\tbelong \t0x03000000\n>4\tbelong \t0x01000000\n>>8\tbeshort\t0xFFFF\t\tYAFFS filesystem\n\n# EFS2 file system - jojo@utulsa.edu\n8       string EFSSuper         EFS2 Qualcomm filesystem super block,\n>0      lelong 0x53000000\tlittle endian,\n>>4     leshort &1              NAND\n>>4     leshort ^1              NOR\n>>4     leshort x               version 0x%x,\n>>24    lelong  x               %d blocks,\n>>16    lelong  x               0x%x pages per block,\n>>20    lelong  x               0x%x bytes per page\n\n8\tstring SSFErepu\t\tEFS2 Qualcomm filesystem super block,\n>0      belong 0x53000000\tbig endian,\n>>4     beshort &1              NAND\n>>4     beshort ^1              NOR\n>>4     beshort x               version 0x%x,\n>>24    belong  x               %d blocks,\n>>16    belong  x               0x%x pages per block,\n>>20    belong  x               0x%x bytes per page\n\n# TROC file system\n0\tstring\tTROC\t\tTROC filesystem,\n>4\tlelong\tx\t\t%d file entries\n\n# PFS file system\n0\tstring\tPFS/\t\tPFS filesystem,\n>4\tstring\tx\t\tversion %s,\n>14\tleshort\tx\t\t%d files\n\n# MPFS file system\n0\tstring\tMPFS\t\tMPFS (Microchip) filesystem,\n>4\tbyte\tx\t\tversion %d.\n>5\tbyte\tx\t\t\\b%d,\n>6\tleshort\tx\t\t%d file entries\n\n# cramfs filesystem - russell@coker.com.au\n0       lelong  0x28cd3d45      CramFS filesystem, little endian\n>4\tlelong\t<0\t\tinvalid\n>4      lelong  x \t\tsize %lu\n>8      lelong  &1 \t\tversion #2\n>8      lelong  &2 \t\tsorted_dirs\n>8      lelong  &4 \t\thole_support\n>32     lelong  x \t\tCRC 0x%x,\n>36     lelong  x \t\tedition %lu,\n>40\tlelong\t<0\t\tinvalid\n>40     lelong  x \t\t%lu blocks,\n>44\tlelong\t<0\t\tinvalid\n>44     lelong  x \t\t%lu files\n\n0       belong  0x28cd3d45      CramFS filesystem, big endian\n>4\tbelong\t<0\t\tinvalid\n>4      belong  x \t\tsize %lu\n>8      belong  &1 \t\tversion #2\n>8      belong  &2 \t\tsorted_dirs\n>8      belong  &4 \t\thole_support\n>32     belong  x \t\tCRC 0x%x,\n>36     belong  x \t\tedition %lu,\n>40\tbelong\t<0\t\tinvalid\n>40     belong  x \t\t%lu blocks,\n>44\tbelong\t<0\t\tinvalid\n>44     belong  x \t\t%lu files\n\n\n\n# JFFS2 file system\n0       leshort 0x1984          JFFS2 filesystem (old) data little endian,\n>4\tlelong\t>1000000\tinvalid\n>4\tlelong\t<0\t\tinvalid\n>4\tlelong\t0\t\tinvalid\n>4\tlelong\tx\t\tJFFS node length: %d\n\n0       beshort 0x1984          JFFS2 filesystem (old) data big endian,\n>4      belong  >1000000        invalid\n>4      belong  <0              invalid\n>4\tbelong\t0\t\tinvalid\n>4      belong  x               JFFS node length: %d\n\n0       leshort 0x1985          JFFS2 filesystem data little endian,\n>4      lelong  >1000000        invalid\n>4      lelong  <0              invalid\n>4\tlelong\t0\t\tinvalid\n>4\tlelong\tx\t\tJFFS node length: %d\n\n0       beshort 0x1985          JFFS2 filesystem data big endian,\n>4      belong  >1000000        invalid\n>4      belong  <0              invalid\n>4\tbelong\t0\t\tinvalid\n>4      belong  x               JFFS node length: %d\n\n\n# Squashfs\n0       string  sqsh    Squashfs filesystem, big endian,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n\n0       string  hsqs    Squashfs filesystem, little endian,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28\tleshort >3\tcompression: \n>>20\tleshort 1\t\\bgzip,\n>>20\tleshort\t2\t\\blzma,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>28\tleshort >3\t\n>>40\tlequad\tx\tsize: %lld bytes,\n>4      lelong  x       %d inodes,\n>28\tleshort >3\n>>12\tlelong\t\tblocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28\tleshort 3\n>>51\tlelong \tx\tblocksize: %d bytes,\n>28\tleshort\t>3\t\n>>12\tlelong\tx\tblocksize: %d bytes,\n>28\tleshort <4\n>>39    ledate  x\tcreated: %s\n>28\tleshort >3\n>>8\tledate x\tcreated: %s\n\n# Squashfs with LZMA compression\n0       string  sqlz    Squashfs filesystem, big endian, lzma compression, \n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort >2\n>>63    bequad x        size: %lld bytes,\n#>>67   belong  x       %d bytes,\n>4      belong  x       %d inodes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort >1\n>>51    belong  x       blocksize: %d bytes,\n>39     bedate  x       created: %s\n\n# Squashfs 3.3 LZMA signature\n0       string  qshs    Squashfs filesystem, big endian, lzma signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort >2\n>>63    bequad x        size: %lld bytes,\n#>>67   belong  x       %d bytes,\n>4      belong  x       %d inodes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort >1\n>>51    belong  x       blocksize: %d bytes,\n>39     bedate  x       created: %s\n\n# Squashfs for DD-WRT\n0       string  tqsh    Squashfs filesystem, big endian, DD-WRT signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort >2\n>>63    bequad x        size: %lld bytes,\n#>>67   belong  x       %d bytes,\n>4      belong  x       %d inodes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort >1\n>>51    belong  x       blocksize: %d bytes,\n>39     bedate  x       created: %s\n\n# Squashfs for DD-WRT\n0       string  hsqt    Squashfs filesystem, little endian, DD-WRT signature,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>28     leshort >2\n>>63    lequad x        size: %lld bytes,\n#>>63   lelong  x       %d bytes,\n>4      lelong  x       %d inodes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort >1\n>>51    lelong  x       blocksize: %d bytes,\n>39     ledate  x       created: %s\n\n# Non-standard Squashfs signature found on some D-Link routers\n0       string  shsq    Squashfs filesystem, little endian, non-standard signature, \n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>28     leshort >2\n>>63    lequad x        size: %lld bytes,\n#>>63   lelong  x       %d bytes,\n>4      lelong  x       %d inodes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort >1\n>>51    lelong  x       blocksize: %d bytes,\n>39     ledate  x       created: %s\n\n# Commented out for now - unlikely to be found in firmware\n# CDROM Filesystems\n# Modified for UDF by gerardo.cacciari@gmail.com\n#32769   string    CD001     #\n#!:mime  application/x-iso9660-image\n#>38913  string   !NSR0      ISO 9660 CD-ROM filesystem data\n#>38913  string    NSR0      UDF filesystem data\n#>>38917 string    1         (version 1.0)\n#>>38917 string    2         (version 1.5)\n#>>38917 string    3         (version 2.0)\n#>>38917 byte     >0x33      (unknown version, ID 0x%X)\n#>>38917 byte     <0x31      (unknown version, ID 0x%X)\n# \"application id\" which appears to be used as a volume label\n#>32808  string    >\\0       '%s'\n#>34816  string    \\000CD001\\001EL\\ TORITO\\ SPECIFICATION    (bootable)\n#37633   string    CD001     ISO 9660 CD-ROM filesystem data (raw 2352 byte sectors)\n#!:mime  application/x-iso9660-image\n#32776   string    CDROM     High Sierra CD-ROM filesystem data\n\n# reiserfs - russell@coker.com.au\n0x10034         string  ReIsErFs        ReiserFS filesystem V3.5\n0x10034         string  ReIsEr2Fs       ReiserFS filesystem V3.6\n0x10034         string  ReIsEr3Fs       ReiserFS filesystem V3.6.19\n>0x1002c        leshort x               block size %d\n>0x10032        leshort &2              (mounted or unclean)\n>0x10000        lelong  x               num blocks %d\n>0x10040        lelong  1               tea hash\n>0x10040        lelong  2               yura hash\n>0x10040        lelong  3               r5 hash\n\n\n# ext2/ext3 filesystems - Andreas Dilger <adilger@dilger.ca>\n# ext4 filesystem - Eric Sandeen <sandeen@sandeen.net>\n# volume label and UUID Russell Coker\n# http://etbe.coker.com.au/2008/07/08/label-vs-uuid-vs-device/\n0x438   leshort         0xEF53          Linux EXT filesystem\n>0x44c  lelong\t\t<0\t\tinvalid\n>0x44c\tlelong\t\t>4\t\tinvalid\n>0x44c  lelong          x               rev %d\n>0x43e  leshort         x               \\b.%d\n# No journal?  ext2\n>0x45c  lelong          ^0x0000004      ext2 filesystem data\n>>0x43a leshort         ^0x0000001      (mounted or unclean)\n# Has a journal?  ext3 or ext4\n>0x45c  lelong          &0x0000004\n#  and small INCOMPAT?\n>>0x460 lelong          <0x0000040\n#   and small RO_COMPAT?\n>>>0x464 lelong         <0x0000008      ext3 filesystem data\n#   else large RO_COMPAT?\n>>>0x464 lelong         >0x0000007      ext4 filesystem data\n#  else large INCOMPAT?\n>>0x460 lelong          >0x000003f      ext4 filesystem data\n>0x468  belong          x               \\b, UUID=%08x\n>0x46c  beshort         x               \\b-%04x\n>0x46e  beshort         x               \\b-%04x\n>0x470  beshort         x               \\b-%04x\n>0x472  belong          x               \\b-%08x\n>0x476  beshort         x               \\b%04x\n>0x478  string          >0              \\b, volume name \"%s\"\n# General flags for any ext* fs\n>0x460  lelong          &0x0000004      (needs journal recovery)\n>0x43a  leshort         &0x0000002      (errors, invalid)\n# INCOMPAT flags\n>0x460  lelong          &0x0000001      (compressed)\n#>0x460 lelong          &0x0000002      (filetype)\n#>0x460 lelong          &0x0000010      (meta bg)\n>0x460  lelong          &0x0000040      (extents)\n>0x460  lelong          &0x0000080      (64bit)\n#>0x460 lelong          &0x0000100      (mmp)\n#>0x460 lelong          &0x0000200      (flex bg)\n# RO_INCOMPAT flags\n#>0x464 lelong          &0x0000001      (sparse super)\n>0x464  lelong          &0x0000002      (large files)\n>0x464  lelong          &0x0000008      (huge files)\n#>0x464 lelong          &0x0000010      (gdt checksum)\n\n\n#romfs filesystems - Juan Cespedes <cespedes@debian.org>\n0       string          -rom1fs-        romfs filesystem, version 1\n>8\tbelong\t>10000000\t\tinvalid\n>8      belong  x                       size: %d bytes,\n>16     string  x                       named %s.\n\n# JFFS - russell@coker.com.au           \n0       lelong  0x34383931      Linux Journalled Flash filesystem, little endian\n0       belong  0x34383931      Linux Journalled Flash filesystem, big endian\n\n# Wind River MemFS file system, found in some VxWorks devices\n0\tstring\towowowowowowowowowowowowowowow\t\tWind River management filesystem,\n>32\tbelong\t0\t\t\t\t\tuncompressed\n>32\tbelong\t1\t\t\t\t\tcompressed,\n>36\tbelong\tx\t\t\t\t\t%d files\n\n\n# FATX \n0\t\tstring\t\tFATX\t\tFATX filesystem data\n\n\n\n\n\n# updated by Joerg Jenderek at Sep 2007\n# only for sector sizes with 512 or more Bytes\n0x1FE\tleshort\t0xAA55\t\t\tstart boot sector\n# to do also for sectors < than 512 Bytes and some other files, GRR\n#30\tsearch/481\t\\x55\\xAA\tstart boot sector / filesystem\n# not for BeOS floppy 1440k, MBRs\n#(11.s-2) uleshort\t0xAA55\t\tstart boot sector / filesystem\n>2\tstring\tOSBS\t\t\t\\b, OS/BS MBR\n# J\\xf6rg Jenderek <joerg dot jenderek at web dot de>\n>0x8C\tstring\tInvalid\\ partition\\ table\t\\b, MS-DOS MBR\n# dr-dos with some upper-, lowercase variants\n>0x9D\tstring\tInvalid\\ partition\\ table$\t\n>>181\tstring\tNo\\ Operating\\ System$\t\t\n>>>201\tstring\tOperating\\ System\\ load\\ error$\t\\b, DR-DOS MBR, Version 7.01 to 7.03\n>0x9D\tstring\tInvalid\\ partition\\ table$\t\n>>181\tstring\tNo\\ operating\\ system$\t\t\n>>>201\tstring\tOperating\\ system\\ load\\ error$\t\\b, DR-DOS MBR, Version 7.01 to 7.03\n>342\tstring\tInvalid\\ partition\\ table$\t\n>>366\tstring\tNo\\ operating\\ system$\t\t\n>>>386\tstring\tOperating\\ system\\ load\\ error$\t\\b, DR-DOS MBR, version 7.01 to 7.03\n>295\tstring\tNEWLDR\\0\t\t\t\t\n>>302\tstring\tBad\\ PT\\ $\t\t\t\t\n>>>310\tstring\tNo\\ OS\\ $\t\t\t\t\n>>>>317\tstring\tOS\\ load\\ err$\t\t\t\t\n>>>>>329\tstring\tMoved\\ or\\ missing\\ IBMBIO.LDR\\n\\r\t\n>>>>>>358\tstring\tPress\\ any\\ key\\ to\\ continue.\\n\\r$\t\n>>>>>>>387\tstring\tCopyright\\ (c)\\ 1984,1998\t\n>>>>>>>>411\tstring\tCaldera\\ Inc.\\0\t\t\\b, DR-DOS MBR (IBMBIO.LDR)\n>0x10F\tstring\tUng\\201ltige\\ Partitionstabelle\t\\b, MS-DOS MBR, german version 4.10.1998, 4.10.2222\n>>0x1B8\tubelong\t>0\t\t\t\t\\b, Serial 0x%-.4x\n>0x8B\tstring\tUng\\201ltige\\ Partitionstabelle\t\\b, MS-DOS MBR, german version 5.00 to 4.00.950\n>271\tstring\tInvalid\\ partition\\ table\\0\t\t\n>>295\tstring\tError\\ loading\\ operating\\ system\\0\t\n>>>326\tstring\tMissing\\ operating\\ system\\0\t\t\\b, mbr\n#\n>139\tstring\tInvalid\\ partition\\ table\\0\t\t\n>>163\tstring\tError\\ loading\\ operating\\ system\\0\t\n>>>194\tstring\tMissing\\ operating\\ system\\0\t\t\\b, Microsoft Windows XP mbr\n# http://www.heise.de/ct/05/09/006/ page 184\n#HKEY_LOCAL_MACHINE\\SYSTEM\\MountedDevices\\DosDevices\\?:=Serial4Bytes+8Bytes\n>>>>0x1B8\tulelong\t>0\t\t\t\t\\b,Serial 0x%-.4x\n>300\tstring\tInvalid\\ partition\\ table\\0\t\n>>324\tstring\tError\\ loading\\ operating\\ system\\0\n>>>355\tstring\tMissing\\ operating\\ system\\0\t\t\\b, Microsoft Windows XP MBR\n#??>>>389\tstring\tInvalid\\ system\\ disk\t\t\n>>>>0x1B8\tulelong\t>0\t\t\t\t\\b, Serial 0x%-.4x\n>300\tstring\tUng\\201ltige\\ Partitionstabelle\n#split string to avoid error: String too long\n>>328\tstring\tFehler\\ beim\\ Laden\\ \t\n>>>346\tstring\tdes\\ Betriebssystems\t\n>>>>366\tstring\tBetriebssystem\\ nicht\\ vorhanden\t\\b, Microsoft Windows XP MBR (german)\n>>>>>0x1B8\tulelong\t>0\t\t\t\t\\b, Serial 0x%-.4x\n#>0x145\tstring\tDefault:\\ F\t\t\t\t\\b, FREE-DOS MBR\n#>0x14B\tstring\tDefault:\\ F\t\t\t\t\\b, FREE-DOS 1.0 MBR\n>0x145\tsearch/7\tDefault:\\ F\t\t\t\\b, FREE-DOS MBR\n#>>313\t\tstring\tF0\\ .\\ .\\ .\t\t\t\n#>>>322\t\tstring\tdisk\\ 1\t\t\t\t\n#>>>>382\tstring\tFAT3\t\t\t\t\n>64\tstring\tno\\ active\\ partition\\ found\t\n>>96\tstring\tread\\ error\\ while\\ reading\\ drive\t\\b, FREE-DOS Beta 0.9 MBR\n# Ranish Partition Manager http://www.ranish.com/part/\n>387\tsearch/4\t\\0\\ Error!\\r\t\t\t\n>>378\tsearch/7\tVirus! \t\t\t\t\n>>>397\tsearch/4\tBooting\\ \t\t\t\n>>>>408\tsearch/4\tHD1/\\0\t \t\t\t\\b, Ranish MBR (\n>>>>>416\tstring\tWriting\\ changes...\t\t\\b2.37\n>>>>>>438\tubyte\t\tx\t\t\t\\b,0x%x dots\n>>>>>>440\tubyte\t\t>0\t\t\t\\b,virus check\n>>>>>>441\tubyte\t\t>0\t\t\t\\b,partition %c\n#2.38,2.42,2.44\n>>>>>416\tstring\t!Writing\\ changes...\t\t\\b\n>>>>>>418\tubyte\t1\t\t\t\t\\bvirus check,\n>>>>>>419\tubyte\tx\t\t\t\t\\b0x%x seconds\n>>>>>>420\tubyte&0x0F\t>0\t\t\t\\b,partition\n>>>>>>>420\tubyte&0x0F\t<5\t\t\t\\b %x\n>>>>>>>420\tubyte&0x0F\t0Xf\t\t\t\\b ask\n>>>>>420\tubyte\t\tx\t\t\t\\b)\n#\n>271\tstring\tOperating\\ system\\ loading \t\t\n>>296\tstring\terror\\r\t\t\t\t\t\\b, SYSLINUX MBR (2.10)\n# http://www.acronis.de/\n>362\tstring\tMBR\\ Error\\ \\0\\r\t\t\t\n>>376\tstring\tress\\ any\\ key\\ to\\ \t\t\t\n>>>392\tstring\tboot\\ from\\ floppy...\\0\t\t\t\\b, Acronis MBR\n# added by Joerg Jenderek\n# http://www.visopsys.org/\n# http://partitionlogic.org.uk/\n>309\tstring\tNo\\ bootable\\ partition\\ found\\r\t\n>>339\tstring\tI/O\\ Error\\ reading\\ boot\\ sector\\r\t\\b, Visopsys MBR\n>349\tstring\tNo\\ bootable\\ partition\\ found\\r\t\n>>379\tstring\tI/O\\ Error\\ reading\\ boot\\ sector\\r\t\\b, simple Visopsys MBR\n# bootloader, bootmanager\n>0x40\tstring\tSBML\t\t\t\t\n# label with 11 characters of FAT 12 bit filesystem\n>>43\tstring\tSMART\\ BTMGR\t\t\t\n>>>430\tstring\tSBMK\\ Bad!\\r\t\t\t\\b, Smart Boot Manager\n# OEM-ID not always \"SBM\"\n#>>>>3\tstrings\tSBM\t\t\t\t\n>>>>6\tstring\t>\\0                             \\b, version %s\n>382\tstring\tXOSLLOADXCF\t\t\t\\b, eXtended Operating System Loader\n>6\tstring\tLILO\t\t\t\t\\b, LInux i386 boot LOader\n>>120\tstring\tLILO\t\t\t\t\\b, version 22.3.4 SuSe\n>>172\tstring\tLILO\t\t\t\t\\b, version 22.5.8 Debian\n# updated by Joerg Jenderek at Oct 2008\n# variables according to grub-0.97/stage1/stage1.S or\n# http://www.gnu.org/software/grub/manual/grub.html#Embedded-data\n# usual values are marked with comments to get only informations of strange GRUB loaders\n>342\t\tsearch/60\t\\0Geom\\0\t\n#>0\t\tulelong\t\tx\t\t%x=0x009048EB ,\t0x2a9048EB  0\n>>0x41\t\tubyte\t\t<2\t\t\n>>>0x3E\t\tubyte\t\t>2\t\t\\b; GRand Unified Bootloader\n# 0x3 for 0.5.95,0.93,0.94,0.96 0x4 for 1.90 \n>>>>0x3E\tubyte\t\tx\t\t\\b, stage1 version 0x%x\n#If it is 0xFF, use a drive passed by BIOS\n>>>>0x40\tubyte\t\t<0xFF\t\t\\b, boot drive 0x%x\n# in most case 0,1,0x2e for GRUB 0.5.95\n>>>>0x41\tubyte\t\t>0\t\t\\b, LBA flag 0x%x\n>>>>0x42\tuleshort\t<0x8000\t\t\\b, stage2 address 0x%x\n#>>>>0x42\tuleshort\t=0x8000\t\t\\b, stage2 address 0x%x (usual)\n>>>>0x42\tuleshort\t>0x8000\t\t\\b, stage2 address 0x%x\n#>>>>0x44\tulelong\t\t=1\t\t\\b, 1st sector stage2 0x%x (default)\n>>>>0x44\tulelong\t\t>1\t\t\\b, 1st sector stage2 0x%x\n>>>>0x48\tuleshort\t<0x800\t\t\\b, stage2 segment 0x%x\n#>>>>0x48\tuleshort\t=0x800\t\t\\b, stage2 segment 0x%x (usual)\n>>>>0x48\tuleshort\t>0x800\t\t\\b, stage2 segment 0x%x\n>>>>402\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>394\tstring\tstage1\t\t\t\\b, GRUB version 0.5.95\n>>>>382\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>376\tstring\tGRUB\\ \\0\t\t\\b, GRUB version 0.93 or 1.94\n>>>>383\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>377\tstring\tGRUB\\ \\0\t\t\\b, GRUB version 0.94\n>>>>385\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>379\tstring\tGRUB\\ \\0\t\t\\b, GRUB version 0.95 or 0.96\n>>>>391\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>385\tstring\tGRUB\\ \\0\t\t\\b, GRUB version 0.97\n#unkown version\n>>>343\t\tstring\tGeom\\0Read\\0\\ Error\\0\t\n>>>>321\t\tstring\tLoading\\ stage1.5\t\\b, GRUB version x.y\n>>>380\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>374\t\tstring\tGRUB\\ \\0\t\t\\b, GRUB version n.m\n# http://syslinux.zytor.com/\n>478\tstring\tBoot\\ failed\\r\t\t\t\n>>495\tstring\tLDLINUX\\ SYS\t\t\t\\b, SYSLINUX bootloader (1.62)\n>480\tstring\tBoot\\ failed\\r\t\t\t\n>>495\tstring\tLDLINUX\\ SYS\t\t\t\\b, SYSLINUX bootloader (2.06 or 2.11)\n>484\tstring\tBoot\\ error\\r\t\t\t\\b, SYSLINUX bootloader (3.11)\n>395\tstring\tchksum\\0\\ ERROR!\\0\t\t\\b, Gujin bootloader\n# http://www.bcdwb.de/bcdw/index_e.htm\n>3\tstring\tBCDL\t\t\t\t\n>>498\tstring\tBCDL\\ \\ \\ \\ BIN\t\t\t\\b, Bootable CD Loader (1.50Z)\n# mbr partion table entries\n# OEM-ID does not contain MicroSoft,NEWLDR,DOS,SYSLINUX,or MTOOLs\n>3\t\t\tstring\t\t!MS\n>>3\t\t\tstring\t\t!SYSLINUX\n>>>3\t\t\tstring\t\t!MTOOL\n>>>>3\t\t\tstring\t\t!NEWLDR\n>>>>>5\t\t\tstring\t\t!DOS\n# not FAT (32 bit)\n>>>>>>82\t\tstring\t\t!FAT32\n#not Linux kernel\n>>>>>>>514\t\tstring\t\t!HdrS\n#not BeOS\n>>>>>>>>422\t\tstring\t\t!Be\\ Boot\\ Loader\n# active flag 0 or 0x80 and type > 0\n>>>>>>>>>446\t\tubyte\t\t<0x81\t\n>>>>>>>>>>446\t\tubyte&0x7F\t0\t\n>>>>>>>>>>>450\t\tubyte\t\t>0\t\\b; partition 1: ID=0x%x\n>>>>>>>>>>>>446\t\tubyte\t\t0x80\t\\b, active\n>>>>>>>>>>>>447\t\tubyte\t\tx\t\\b, starthead %u\n#>>>>>>>>>>>>448\t\tubyte\t\tx\t\\b, start C_S: 0x%x\n#>>>>>>>>>>>>448\t\tubeshort&1023\tx\t\\b, startcylinder? %d\n>>>>>>>>>>>>454\t\tulelong\t\tx\t\\b, startsector %u\n>>>>>>>>>>>>458\t\tulelong\t\tx\t\\b, %u sectors\n#\n>>>>>>>>>462\t\tubyte\t\t<0x81\t\n>>>>>>>>>>462\t\tubyte&0x7F\t0\t\t\n>>>>>>>>>>>466\t\tubyte\t\t>0\t\\b; partition 2: ID=0x%x\n>>>>>>>>>>>>462\t\tubyte\t\t0x80\t\\b, active\n>>>>>>>>>>>>463\t\tubyte\t\tx\t\\b, starthead %u\n#>>>>>>>>>>>>464\t\tubyte\t\tx\t\\b, start C_S: 0x%x\n#>>>>>>>>>>>>464\t\tubeshort&1023\tx\t\\b, startcylinder? %d\n>>>>>>>>>>>>470\t\tulelong\t\tx\t\\b, startsector %u\n>>>>>>>>>>>>474\t\tulelong\t\tx\t\\b, %u sectors\n#\n>>>>>>>>>478\t\tubyte\t\t<0x81\t\t\n>>>>>>>>>>478\t\tubyte&0x7F\t0\t\t\n>>>>>>>>>>>482\t\tubyte\t\t>0\t\\b; partition 3: ID=0x%x\n>>>>>>>>>>>>478\t\tubyte\t\t0x80\t\\b, active\n>>>>>>>>>>>>479\t\tubyte\t\tx\t\\b, starthead %u\n#>>>>>>>>>>>>480\t\tubyte\t\tx\t\\b, start C_S: 0x%x\n#>>>>>>>>>>>>481\t\tubyte\t\tx\t\\b, start C2S: 0x%x\n#>>>>>>>>>>>>480\t\tubeshort&1023\tx\t\\b, startcylinder? %d\n>>>>>>>>>>>>486\t\tulelong\t\tx\t\\b, startsector %u\n>>>>>>>>>>>>490\t\tulelong\t\tx\t\\b, %u sectors\n#\n>>>>>>>>>494\t\tubyte\t\t<0x81\t\n>>>>>>>>>>494\t\tubyte&0x7F\t0\t\t\n>>>>>>>>>>>498\t\tubyte\t\t>0\t\\b; partition 4: ID=0x%x\n>>>>>>>>>>>>494\t\tubyte\t\t0x80\t\\b, active\n>>>>>>>>>>>>495\t\tubyte\t\tx\t\\b, starthead %u\n#>>>>>>>>>>>>496\t\tubyte\t\tx\t\\b, start C_S: 0x%x\n#>>>>>>>>>>>>496\t\tubeshort&1023\tx\t\\b, startcylinder? %d\n>>>>>>>>>>>>502\t\tulelong\t\tx\t\\b, startsector %u\n>>>>>>>>>>>>506\t\tulelong\t\tx\t\\b, %u sectors\n# mbr partion table entries end\n# http://www.acronis.de/\n#FAT label=ACRONIS\\ SZ\n#OEM-ID=BOOTWIZ0\n>442\tstring\tNon-system\\ disk,\\ \t\n>>459\tstring\tpress\\ any\\ key...\\x7\\0\t\t\\b, Acronis Startup Recovery Loader\n# DOS names like F11.SYS are 8 right space padded bytes+3 bytes\n>>>477\t\tubyte&0xDF\t>0\t\t\n>>>>477\t\tstring\t\tx \t\t\\b %-.3s\n>>>>>480\tubyte&0xDF\t>0\t\t\n>>>>>>480\tstring\t\tx \t\t\\b%-.5s\n>>>>485\t\tubyte&0xDF\t>0\t\t\n>>>>>485\tstring\t\tx \t\t\\b.%-.3s\n#\n>185\tstring\tFDBOOT\\ Version\\ \t\t\t\n>>204\tstring\t\\rNo\\ Systemdisk.\\ \t\t\t\n>>>220\tstring\tBooting\\ from\\ harddisk.\\n\\r\t\t\n>>>245\tstring\tCannot\\ load\\ from\\ harddisk.\\n\\r\t\n>>>>273 string\tInsert\\ Systemdisk\\ \t\t\t\n>>>>>291 string and\\ press\\ any\\ key.\\n\\r\t\t\\b, FDBOOT harddisk Bootloader\n>>>>>>200 string\t>\\0                             \\b, version %-3s\n>242\tstring\tBootsector\\ from\\ C.H.\\ Hochst\\204\t\n>>278\tstring\tNo\\ Systemdisk.\\ \t\t\t\n>>>293\tstring\tBooting\\ from\\ harddisk.\\n\\r\t\t\n>>>441\tstring\tCannot\\ load\\ from\\ harddisk.\\n\\r\t\n>>>>469 string\tInsert\\ Systemdisk\\ \t\t\t\n>>>>>487 string and\\ press\\ any\\ key.\\n\\r\t\t\\b, WinImage harddisk Bootloader\n>>>>>>209 string\t>\\0                             \\b, version %-4.4s\n>(1.b+2)\tubyte\t\t0xe\t\t\t\n>>(1.b+3)\tubyte\t\t0x1f\t\t\t\n>>>(1.b+4)\tubyte\t\t0xbe\t\t\t\n>>>>(1.b+5)\tubyte\t\t0x77\t\t\t\n>>>>(1.b+6)\tubyte\t\t0x7c\t\t\t\n>>>>>(1.b+7)\tubyte\t\t0xac\t\t\t\n>>>>>>(1.b+8)\tubyte\t\t0x22\t\t\t\n>>>>>>>(1.b+9)\tubyte\t\t0xc0\t\t\t\n>>>>>>>>(1.b+10)\tubyte\t0x74\t\t\t\n>>>>>>>>>(1.b+11)\tubyte\t0xb\t\t\t\n>>>>>>>>>>(1.b+12)\tubyte\t0x56\t\t\t\n>>>>>>>>>>(1.b+13)\tubyte\t0xb4\t\t\t\\b, mkdosfs boot message display\n>214\tstring\tPlease\\ try\\ to\\ install\\ FreeDOS\\ \t\\b, DOS Emulator boot message display\n#>>244\tstring\tfrom\\ dosemu-freedos-*-bin.tgz\\r\t\n#>>>170\tstring\tSorry,\\ could\\ not\\ load\\ an\\ \t\t\n#>>>>195\tstring\toperating\\ system.\\r\\n\t\t\n#\n>103\tstring\tThis\\ is\\ not\\ a\\ bootable\\ disk.\\ \t\n>>132\tstring\tPlease\\ insert\\ a\\ bootable\\ \t\t\n>>>157\tstring\tfloppy\\ and\\r\\n\t\t\t\t\n>>>>169\tstring\tpress\\ any\\ key\\ to\\ try\\ again...\\r\t\\b, FREE-DOS message display\n#\n>66\tstring\tSolaris\\ Boot\\ Sector    \t\t\n>>99\tstring\tIncomplete\\ MDBoot\\ load.\t\t\n>>>89\tstring\tVersion \t\t\t\t\\b, Sun Solaris Bootloader\n>>>>97\tbyte\tx\t\t\t\t\tversion %c\n#\n>408\tstring\tOS/2\\ !!\\ SYS01475\\r\\0\t\t\t\n>>429\tstring\tOS/2\\ !!\\ SYS02025\\r\\0\t\t\t\n>>>450\tstring\tOS/2\\ !!\\ SYS02027\\r\\0\t\t\t\n>>>469\tstring\tOS2BOOT\\ \\ \\ \\ \t\t\t\t\\b, IBM OS/2 Warp bootloader\n#\n>409\tstring\tOS/2\\ !!\\ SYS01475\\r\\0\t\t\t\n>>430\tstring\tOS/2\\ !!\\ SYS02025\\r\\0\t\t\t\n>>>451\tstring\tOS/2\\ !!\\ SYS02027\\r\\0\t\t\t\n>>>470\tstring\tOS2BOOT\\ \\ \\ \\ \t\t\t\t\\b, IBM OS/2 Warp Bootloader\n>112\t\tstring\tThis\\ disk\\ is\\ not\\ bootable\\r\t\t\t\n>>142\t\tstring\tIf\\ you\\ wish\\ to\\ make\\ it\\ bootable\t\t\n>>>176\t\tstring\trun\\ the\\ DOS\\ program\\ SYS\\  \t\t\t\n>>>200\t\tstring\tafter\\ the\\r\t\t\t\t\t\n>>>>216\t\tstring\tsystem\\ has\\ been\\ loaded\\r\\n\t\t\t\n>>>>>242\tstring\tPlease\\ insert\\ a\\ DOS\\ diskette\\ \t\t\n>>>>>271\tstring\tinto\\r\\n\\ the\\ drive\\ and\\ \t\t\t\n>>>>>>292\tstring\tstrike\\ any\\ key...\\0\t\t\\b, IBM OS/2 Warp message display\n# XP\n>430\tstring\tNTLDR\\ is\\ missing\\xFF\\r\\n\t\t\n>>449\tstring\tDisk\\ error\\xFF\\r\\n\t\t\t\n>>>462\tstring\tPress\\ any\\ key\\ to\\ restart\\r\t\t\\b, Microsoft Windows XP Bootloader\n# DOS names like NTLDR,CMLDR,$LDR$ are 8 right space padded bytes+3 bytes\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n#\n>>>>371\t\tubyte\t\t>0x20\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>376\tubyte&0xDF\t>0\t\t\t\n>>>>>>>376\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>430\tstring\tNTLDR\\ nicht\\ gefunden\\xFF\\r\\n\t\t\n>>453\tstring\tDatentr\\204gerfehler\\xFF\\r\\n\t\t\n>>>473\tstring\tNeustart\\ mit\\ beliebiger\\ Taste\\r\t\\b, Microsoft Windows XP Bootloader (german)\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n# offset variant\n>>>>379\tstring\t\\0\t\t\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n#\n>430\tstring\tNTLDR\\ fehlt\\xFF\\r\\n\t\t\t\n>>444\tstring\tDatentr\\204gerfehler\\xFF\\r\\n\t\t\n>>>464\tstring\tNeustart\\ mit\\ beliebiger\\ Taste\\r\t\\b, Microsoft Windows XP Bootloader (2.german)\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n# variant\n>>>>371\t\tubyte\t\t>0x20\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>376\tubyte&0xDF\t>0\t\t\t\n>>>>>>>376\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>430\tstring\tNTLDR\\ fehlt\\xFF\\r\\n\t\t\t\n>>444\tstring\tMedienfehler\\xFF\\r\\n\t\t\t\n>>>459\tstring\tNeustart:\\ Taste\\ dr\\201cken\\r\t\t\\b, Microsoft Windows XP Bootloader (3.german)\n>>>>371\t\tubyte\t\t>0x20\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>376\tubyte&0xDF\t>0\t\t\t\n>>>>>>>376\tstring\t\tx \t\t\t\\b.%-.3s\n# variant\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n#\n>430\tstring\tDatentr\\204ger\\ entfernen\\xFF\\r\\n\t\n>>454\tstring\tMedienfehler\\xFF\\r\\n\t\t\t\n>>>469\tstring\tNeustart:\\ Taste\\ dr\\201cken\\r\t\t\\b, Microsoft Windows XP Bootloader (4.german)\n>>>>379\t\tstring\t\t\\0\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>376\tubyte&0xDF\t>0\t\t\t\n>>>>>>>376\tstring\t\tx \t\t\t\\b.%-.3s\n# variant\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n#\n\n#>3\tstring\tNTFS\\ \\ \\ \\ \t\t\t\t\n>389\tstring\tFehler\\ beim\\ Lesen\\ \n>>407\tstring\tdes\\ Datentr\\204gers\n>>>426\tstring\tNTLDR\\ fehlt\t\t\t\t\n>>>>440\tstring\tNTLDR\\ ist\\ komprimiert\n>>>>>464 string\tNeustart\\ mit\\ Strg+Alt+Entf\\r\t\t\\b, Microsoft Windows XP Bootloader NTFS (german)\n#>3\tstring\tNTFS\\ \\ \\ \\ \t\t\t\t\n>313\tstring\tA\\ disk\\ read\\ error\\ occurred.\\r\n>>345\tstring\tA\\ kernel\\ file\\ is\\ missing\\ \t\n>>>370\tstring\tfrom\\ the\\ disk.\\r\t\t\n>>>>484\tstring\tNTLDR\\ is\\ compressed\t\t\n>>>>>429 string\tInsert\\ a\\ system\\ diskette\\ \t\n>>>>>>454 string and\\ restart\\r\\nthe\\ system.\\r\t\t\\b, Microsoft Windows XP Bootloader NTFS\n# DOS loader variants different languages,offsets\n>472\tubyte&0xDF\t>0\n>>389\tstring\tInvalid\\ system\\ disk\\xFF\\r\\n\t\t\n>>>411\tstring\tDisk\\ I/O\\ error\t\t\t\n>>>>428\tstring\tReplace\\ the\\ disk,\\ and\\ \t\t\n>>>>>455 string\tpress\\ any\\ key\t\t\t\t\\b, Microsoft Windows 98 Bootloader\n#IO.SYS\n>>>>>>472\tubyte&0xDF\t>0\t\t\t\n>>>>>>>472\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>>>474\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>474\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>>479\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>479 string\t\tx \t\t\t\\b%-.1s\n>>>>>>>480\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>480\tstring\t\tx \t\t\t\\b.%-.3s\n#MSDOS.SYS\n>>>>>>>483\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>>483\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>488\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>488\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>>>491\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>491\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>>390\tstring\tInvalid\\ system\\ disk\\xFF\\r\\n\t\t\n>>>412\tstring\tDisk\\ I/O\\ error\\xFF\\r\\n\t\t\n>>>>429\tstring\tReplace\\ the\\ disk,\\ and\\ \t\t\n>>>>>451 string\tthen\\ press\\ any\\ key\\r\t\t\t\\b, Microsoft Windows 98 Bootloader\n>>388\tstring\tUngueltiges\\ System\\ \\xFF\\r\\n\t\t\n>>>410\tstring\tE/A-Fehler\\ \\ \\ \\ \\xFF\\r\\n\t\t\n>>>>427\tstring\tDatentraeger\\ wechseln\\ und\\ \t\t\n>>>>>453 string\tTaste\\ druecken\\r\t\t\t\\b, Microsoft Windows 95/98/ME Bootloader (german)\n#WINBOOT.SYS only not spaces (0xDF)\n>>>>>>497\tubyte&0xDF\t>0\t\t\t\n>>>>>>>497\tstring\t\tx \t\t\t%-.5s\n>>>>>>>>502\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>502\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>>>504 string\t\tx \t\t\t\\b%-.1s\n>>>>>>505\tubyte&0xDF\t>0\t\t\t\n>>>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n#IO.SYS\n>>>>>>472\tubyte&0xDF\t>0\t\t\tor\n>>>>>>>472\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>>>474\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>474\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>>479\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>479 string\t\tx \t\t\t\\b%-.1s\n>>>>>>>480\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>480\tstring\t\tx \t\t\t\\b.%-.3s\n#MSDOS.SYS\n>>>>>>>483\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>>483\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>488\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>488\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>>>491\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>491\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>>390\tstring\tUngueltiges\\ System\\ \\xFF\\r\\n\t\t\n>>>412\tstring\tE/A-Fehler\\ \\ \\ \\ \\xFF\\r\\n\t\t\n>>>>429\tstring\tDatentraeger\\ wechseln\\ und\\ \t\t\n>>>>>455 string\tTaste\\ druecken\\r\t\t\t\\b, Microsoft Windows 95/98/ME Bootloader (German)\n#WINBOOT.SYS only not spaces (0xDF)\n>>>>>>497\tubyte&0xDF\t>0\t\t\t\n>>>>>>>497\tstring\t\tx \t\t\t%-.7s\n>>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>505\tubyte&0xDF\t>0\t\t\t\n>>>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n#IO.SYS\n>>>>>>472\tubyte&0xDF\t>0\t\t\tor\n>>>>>>>472\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>>>474\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>474\tstring\t\tx \t\t\t\\b%-.6s\n>>>>>>>480\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>480\tstring\t\tx \t\t\t\\b.%-.3s\n#MSDOS.SYS\n>>>>>>>483\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>>483\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>488\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>488\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>>>491\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>491\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>>389\tstring\tUngueltiges\\ System\\ \\xFF\\r\\n\t\t\n>>>411\tstring\tE/A-Fehler\\ \\ \\ \\ \\xFF\\r\\n\t\t\n>>>>428\tstring\tDatentraeger\\ wechseln\\ und\\ \t\t\n>>>>>454 string\tTaste\\ druecken\\r\t\t\t\\b, Microsoft Windows 95/98/ME Bootloader (GERMAN)\n# DOS names like IO.SYS,WINBOOT.SYS,MSDOS.SYS,WINBOOT.INI are 8 right space padded bytes+3 bytes\n>>>>>>472\tstring\t\tx \t\t\t%-.2s\n>>>>>>>474\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>474\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>479\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>479\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>480\tubyte&0xDF\t>0\t\t\t\n>>>>>>>480\tstring\t\tx \t\t\t\\b.%-.3s\n>>>>>>483\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>483\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>488\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>488\tstring\t\tx \t\t\t\\b%-.2s\n>>>>>>>>490\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>490\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>491\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>491\tstring\t\tx \t\t\t\\b.%-.3s\n>479\tubyte&0xDF\t>0\n>>416\tstring\tKein\\ System\\ oder\\ \t\t\t\n>>>433\tstring\tLaufwerksfehler\t\t\t\t\n>>>>450\tstring\tWechseln\\ und\\ Taste\\ dr\\201cken\t\\b, Microsoft DOS Bootloader (german)\n#IO.SYS\n>>>>>479\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>481\tubyte&0xDF\t>0\t\t\t\n>>>>>>>481\tstring\t\tx \t\t\t\\b%-.6s\n>>>>>487\tubyte&0xDF\t>0\t\t\t\n>>>>>>487\tstring\t\tx \t\t\t\\b.%-.3s\n#MSDOS.SYS\n>>>>>>490\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>490\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>495\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>495\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>>498\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>498\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>376\tsearch/41\tNon-System\\ disk\\ or\\ \t\t\n>>395\tsearch/41\tdisk\\ error\\r\t\t\t\n>>>407\tsearch/41\tReplace\\ and\\ \t\t\t\n>>>>419\tsearch/41\tpress\\ \t\t\t\t\\b,\n>>>>419\tsearch/41\tstrike\\ \t\t\t\\b, old\n>>>>426\tsearch/41\tany\\ key\\ when\\ ready\\r\t\tMS or PC-DOS bootloader\n#449\t\t\tDisk\\ Boot\\ failure\\r\t\tMS 3.21\n#466\t\t\tBoot\\ Failure\\r\t\t\tMS 3.30\n>>>>>468 search/18\t\\0\t\t\t\t\n#IO.SYS,IBMBIO.COM\n>>>>>>&0\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>>&-20\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.4s\n>>>>>>>>>&-16\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.2s\n>>>>>>&8\tubyte&0xDF\t>0\t\t\t\\b.\n>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.3s\n#MSDOS.SYS,IBMDOS.COM\n>>>>>>&11\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>&-6\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>>>>&-5\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.2s\n>>>>>>>&7\tubyte&0xDF\t>0\t\t\t\\b.\n>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.3s\n>441\tstring\tCannot\\ load\\ from\\ harddisk.\\n\\r\n>>469\tstring\tInsert\\ Systemdisk\\ \t\t\t\n>>>487\tstring\tand\\ press\\ any\\ key.\\n\\r\t\t\\b, MS (2.11) DOS bootloader\n#>43\tstring\t\\224R-LOADER\\ \\ SYS\t\t\t=label\t\t\t\t\t\n>54\tstring\tSYS\n>>324\tstring\tVASKK\n>>>495\tstring\tNEWLDR\\0\t\t\t\t\\b, DR-DOS Bootloader (LOADER.SYS)\n#\n>98\tstring\tPress\\ a\\ key\\ to\\ retry\\0\\r\t\t\n>>120\tstring\tCannot\\ find\\ file\\ \\0\\r\t\t\n>>>139\tstring\tDisk\\ read\\ error\\0\\r\t\t\t\n>>>>156\tstring\tLoading\\ ...\\0\t\t\t\t\\b, DR-DOS (3.41) Bootloader\n#DRBIOS.SYS\n>>>>>44\t\tubyte&0xDF\t>0\t\t\t\n>>>>>>44\tstring\t\tx\t\t\t\\b %-.6s\n>>>>>>>50\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>50\tstring\t\tx \t\t\t\\b%-.2s\n>>>>>>52\tubyte&0xDF\t>0\t\t\t\n>>>>>>>52\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>70\tstring\tIBMBIO\\ \\ COM\t\t\t\t\n>>472\tstring\tCannot\\ load\\ DOS!\\ \t\t\t\n>>>489\tstring\tAny\\ key\\ to\\ retry\t\t\t\\b, DR-DOS Bootloader\n>>471\tstring\tCannot\\ load\\ DOS\\ \t\t\t\n>>487\tstring\tpress\\ key\\ to\\ retry\t\t\t\\b, Open-DOS Bootloader\n#??\n>444\tstring\tKERNEL\\ \\ SYS\t\t\t\t\t\n>>314\tstring\tBOOT\\ error!\t\t\t\t\\b, FREE-DOS Bootloader\n>499\tstring\tKERNEL\\ \\ SYS\t\t\t\t\n>>305\tstring\tBOOT\\ err!\\0\t\t\t\t\\b, Free-DOS Bootloader\n>449\tstring\tKERNEL\\ \\ SYS\t\t\t\t\n>>319\tstring\tBOOT\\ error!\t\t\t\t\\b, FREE-DOS 0.5 Bootloader\n#\n>449\tstring\tLoading\\ FreeDOS\t\t\t\n>>0x1AF\t\tulelong\t\t>0\t\t\t\\b, FREE-DOS 0.95,1.0 Bootloader\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>331\tstring\tError!.0\t\t\t\t\\b, FREE-DOS 1.0 bootloader\n#\n>125\tstring\tLoading\\ FreeDOS...\\r\t\t\t\n>>311\tstring\tBOOT\\ error!\\r\t\t\t\t\\b, FREE-DOS bootloader\n>>>441\t\tubyte&0xDF\t>0\t\t\t\n>>>>441\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>447\tubyte&0xDF\t>0\t\t\t\n>>>>>>447\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>448\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>448\tstring\t\tx \t\t\t\\b%-.1s\n>>>>449\t\tubyte&0xDF\t>0\t\t\t\n>>>>>449\tstring\t\tx \t\t\t\\b.%-.3s\n>124\tstring\tFreeDOS\\0\t\t\t\t\n>>331\tstring\t\\ err\\0\t\t\t\t\t\\b, FREE-DOS BETa 0.9 Bootloader\n# DOS names like KERNEL.SYS,KERNEL16.SYS,KERNEL32.SYS,METAKERN.SYS are 8 right space padded bytes+3 bytes\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n>>333\tstring\t\\ err\\0\t\t\t\t\t\\b, FREE-DOS BEta 0.9 Bootloader\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n>>334\tstring\t\\ err\\0\t\t\t\t\t\\b, FREE-DOS Beta 0.9 Bootloader\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n>336\tstring\tError!\\ \t\t\t\t\n>>343\tstring\tHit\\ a\\ key\\ to\\ reboot.\t\t\\b, FREE-DOS Beta 0.9sr1 Bootloader\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n# added by Joerg Jenderek\n# http://www.visopsys.org/\n# http://partitionlogic.org.uk/\n# OEM-ID=Visopsys\n>478\t\tulelong\t0\t\t\t\t\t\n>>(1.b+326)\tstring\tI/O\\ Error\\ reading\\ \t\t\t\n>>>(1.b+344)\tstring\tVisopsys\\ loader\\r\t\t\t\n>>>>(1.b+361)\tstring\tPress\\ any\\ key\\ to\\ continue.\\r\t\\b, Visopsys loader\n# http://alexfru.chat.ru/epm.html#bootprog\n>494\tubyte\t>0x4D\t\t\t\t\t\n>>495\tstring\t>E\t\t\t\t\t\n>>>495\tstring\t<S\t\t\t\t\t\n#OEM-ID is not reliable\n>>>>3\tstring\tBootProg\t\t\t\t\n# It just looks for a program file name at the root directory\n# and loads corresponding file with following execution.\n# DOS names like STARTUP.BIN,STARTUPC.COM,STARTUPE.EXE are 8 right space padded bytes+3 bytes\n>>>>499\t\t\tubyte&0xDF\t>0\t\t\\b, COM/EXE Bootloader\n>>>>>499\t\tstring\t\tx \t\t\\b %-.1s\n>>>>>>500\t\tubyte&0xDF\t>0\t\t\n>>>>>>>500\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>501\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>501\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>502\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>502\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>503\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>503\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>504\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>504\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>>>505\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>>>505\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>>>>>506\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>>>>>506\tstring\t\tx \t\t\\b%-.1s\n#name extension\n>>>>>507\t\tubyte&0xDF\t>0\t\t\\b.\n>>>>>>507\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>508\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>508\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>509\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>509\t\tstring\t\tx \t\t\\b%-.1s\n#If the boot sector fails to read any other sector,\n#it prints a very short message (\"RE\") to the screen and hangs the computer.\n#If the boot sector fails to find needed program in the root directory,\n#it also hangs with another message (\"NF\").\n>>>>>492\t\tstring\t\tRENF\t\t\\b, FAT (12 bit)\n>>>>>495\t\tstring\t\tRENF\t\t\\b, FAT (16 bit)\n# http://alexfru.chat.ru/epm.html#bootprog\n>494\tubyte\t>0x4D\t\t\t\t\t\n>>495\tstring\t>E\t\t\t\t\t\n>>>495\tstring\t<S\t\t\t\t\t\n#OEM-ID is not reliable\n>>>>3\tstring\tBootProg\t\t\t\t\n# It just looks for a program file name at the root directory\n# and loads corresponding file with following execution.\n# DOS names like STARTUP.BIN,STARTUPC.COM,STARTUPE.EXE are 8 right space padded bytes+3 bytes\n>>>>499\t\t\tubyte&0xDF\t>0\t\t\\b, COM/EXE Bootloader\n>>>>>499\t\tstring\t\tx \t\t\\b %-.1s\n>>>>>>500\t\tubyte&0xDF\t>0\t\t\n>>>>>>>500\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>501\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>501\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>502\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>502\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>503\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>503\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>504\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>504\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>>>505\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>>>505\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>>>>>506\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>>>>>506\tstring\t\tx \t\t\\b%-.1s\n#name extension\n>>>>>507\t\tubyte&0xDF\t>0\t\t\\b.\n>>>>>>507\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>508\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>508\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>509\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>509\t\tstring\t\tx \t\t\\b%-.1s\n#If the boot sector fails to read any other sector,\n#it prints a very short message (\"RE\") to the screen and hangs the computer.\n#If the boot sector fails to find needed program in the root directory,\n#it also hangs with another message (\"NF\").\n>>>>>492\t\tstring\t\tRENF\t\t\\b, FAT (12 bit)\n>>>>>495\t\tstring\t\tRENF\t\t\\b, FAT (16 bit)\n# x86 bootloader end\n# updated by Joerg Jenderek at Sep 2007\n>3\tubyte\t0\t\t\t\n#no active flag\n>>446\tubyte\t0\t\t\t\n# partition 1 not empty\n>>>450\tubyte\t>0\t\t\t\n# partitions 3,4 empty\n>>>>482\t\tubyte\t0\t\t\t\n>>>>>498\tubyte\t0\t\t\t\n# partition 2 ID=0,5,15\n>>>>>>466\tubyte\t<0x10\t\t\t\n>>>>>>>466\tubyte\t0x05\t\t\t\\b, extended partition table\n>>>>>>>466\tubyte\t0x0F\t\t\t\\b, extended partition table (LBA)\n>>>>>>>466\tubyte\t0x0\t\t\t\\b, extended partition table (last)\t\n# JuMP short     bootcodeoffset NOP assembler instructions will usually be EB xx 90\n# http://mirror.href.com/thestarman/asm/2bytejumps.htmm#FWD\n# older drives may use Near JuMP instruction E9 xx xx\n>0\t\tlelong&0x009000EB\t0x009000EB \n>0\t\tlelong&0x000000E9\t0x000000E9 \n# minimal short forward jump found 03cx??\n# maximal short forward jump is 07fx\n>1\t\tubyte\t\t\t<0xff\t\\b, code offset 0x%x\n# mtools-3.9.8/msdos.h\n# usual values are marked with comments to get only informations of strange FAT systems\n# valid sectorsize must be a power of 2 from 32 to 32768\n>>11\t\tuleshort&0x000f\tx\t\t\n>>>11\t\tuleshort\t<32769\t\t\n>>>>11\t\tuleshort\t>31\t\t\n>>>>>21\t\tubyte&0xf0\t0xF0\t\t\n>>>>>>3\t\tstring\t\t>\\0\t\t\\b, OEM-ID \"%8.8s\"\n#http://mirror.href.com/thestarman/asm/debug/debug2.htm#IHC\n>>>>>>>8\tstring\t\tIHC\t\t\\b cached by Windows 9M\n>>>>>>11\tuleshort\t>512\t\t\\b, Bytes/sector %u\n#>>>>>>11\tuleshort\t=512\t\t\\b, Bytes/sector %u=512 (usual)\n>>>>>>11\tuleshort\t<512\t\t\\b, Bytes/sector %u\n>>>>>>13\tubyte\t\t>1\t\t\\b, sectors/cluster %u\n#>>>>>>13\tubyte\t\t=1\t\t\\b, sectors/cluster %u (usual on Floppies)\n>>>>>>14\tuleshort\t>32\t\t\\b, reserved sectors %u\n#>>>>>>14\tuleshort\t=32\t\t\\b, reserved sectors %u (usual Fat32)\n#>>>>>>14\tuleshort\t>1\t\t\\b, reserved sectors %u\n#>>>>>>14\tuleshort\t=1\t\t\\b, reserved sectors %u (usual FAT12,FAT16)\n>>>>>>14\tuleshort\t<1\t\t\\b, reserved sectors %u\n>>>>>>16\tubyte\t\t>2\t\t\\b, FATs %u\n#>>>>>>16\tubyte\t\t=2\t\t\\b, FATs %u (usual)\n>>>>>>16\tubyte\t\t=1\t\t\\b, FAT  %u\n>>>>>>16\tubyte\t\t>0\n>>>>>>17\tuleshort\t>0\t\t\\b, root entries %u\n#>>>>>>17\tuleshort\t=0\t\t\\b, root entries %u=0 (usual Fat32)\n>>>>>>19\tuleshort\t>0\t\t\\b, sectors %u (volumes <=32 MB) \n#>>>>>>19\tuleshort\t=0\t\t\\b, sectors %u=0 (usual Fat32)\n>>>>>>21\tubyte\t\t>0xF0\t\t\\b, Media descriptor 0x%x\n#>>>>>>21\tubyte\t\t=0xF0\t\t\\b, Media descriptor 0x%x (usual floppy)\n>>>>>>21\tubyte\t\t<0xF0\t\t\\b, Media descriptor 0x%x\n>>>>>>22\tuleshort\t>0\t\t\\b, sectors/FAT %u\n#>>>>>>22\tuleshort\t=0\t\t\\b, sectors/FAT %u=0 (usual Fat32)\n>>>>>>26\tubyte\t\t>2\t\t\\b, heads %u\n#>>>>>>26\tubyte\t\t=2\t\t\\b, heads %u (usual floppy)\n>>>>>>26\tubyte\t\t=1\t\t\\b, heads %u\n#skip for Digital Research DOS (version 3.41) 1440 kB Bootdisk\n>>>>>>38\tubyte\t\t!0x70\t\t\n>>>>>>>28\tulelong\t\t>0\t\t\\b, hidden sectors %u\n#>>>>>>>28\tulelong\t\t=0\t\t\\b, hidden sectors %u (usual floppy)\n>>>>>>>32\tulelong\t\t>0\t\t\\b, sectors %u (volumes > 32 MB) \n#>>>>>>>32\tulelong\t\t=0\t\t\\b, sectors %u (volumes > 32 MB)\n# FAT<32 specific \n>>>>>>82\tstring\t\t!FAT32\n#>>>>>>>36\tubyte\t\t0x80\t\t\\b, physical drive 0x%x=0x80 (usual harddisk)\n#>>>>>>>36\tubyte\t\t0\t\t\\b, physical drive 0x%x=0 (usual floppy)\n>>>>>>>36\tubyte\t\t!0x80\t\t\n>>>>>>>>36\tubyte\t\t!0\t\t\\b, physical drive 0x%x\n>>>>>>>37\tubyte\t\t>0\t\t\\b, reserved 0x%x\n#>>>>>>>37\tubyte\t\t=0\t\t\\b, reserved 0x%x\n>>>>>>>38\tubyte\t\t>0x29\t\t\\b, dos < 4.0 BootSector (0x%x)\n>>>>>>>38\tubyte\t\t<0x29\t\t\\b, dos < 4.0 BootSector (0x%x)\n>>>>>>>38\tubyte\t\t=0x29\n>>>>>>>>39\tulelong\t\tx\t\t\\b, serial number 0x%x\n>>>>>>>>43\tstring\t\t<NO\\ NAME\t\\b, label: \"%11.11s\"\n>>>>>>>>43\tstring\t\t>NO\\ NAME\t\\b, label: \"%11.11s\"\n>>>>>>>>43\tstring\t\t=NO\\ NAME\t\\b, unlabeled\n>>>>>>>54\tstring\t\tFAT\t\t\\b, FAT\n>>>>>>>>54\tstring\t\tFAT12\t\t\\b (12 bit)\n>>>>>>>>54\tstring\t\tFAT16\t\t\\b (16 bit)\n# FAT32 specific\n>>>>>>82\tstring\t\tFAT32\t\t\\b, FAT (32 bit)\n>>>>>>>36\tulelong\t\tx\t\t\\b, sectors/FAT %u\n>>>>>>>40\tuleshort\t>0\t\t\\b, extension flags %u\n#>>>>>>>40\tuleshort\t=0\t\t\\b, extension flags %u\n>>>>>>>42\tuleshort\t>0\t\t\\b, fsVersion %u\n#>>>>>>>42\tuleshort\t=0\t\t\\b, fsVersion %u (usual)\n>>>>>>>44\tulelong\t\t>2\t\t\\b, rootdir cluster %u\n#>>>>>>>44\tulelong\t\t=2\t\t\\b, rootdir cluster %u\n#>>>>>>>44\tulelong\t\t=1\t\t\\b, rootdir cluster %u\n>>>>>>>48\tuleshort\t>1\t\t\\b, infoSector %u\n#>>>>>>>48\tuleshort\t=1\t\t\\b, infoSector %u (usual)\n>>>>>>>48\tuleshort\t<1\t\t\\b, infoSector %u\n>>>>>>>50\tuleshort\t>6\t\t\\b, Backup boot sector %u\n#>>>>>>>50\tuleshort\t=6\t\t\\b, Backup boot sector %u (usual) \n>>>>>>>50\tuleshort\t<6\t\t\\b, Backup boot sector %u\n>>>>>>>54\tulelong\t\t>0\t\t\\b, reserved1 0x%x\n>>>>>>>58\tulelong\t\t>0\t\t\\b, reserved2 0x%x\n>>>>>>>62\tulelong\t\t>0\t\t\\b, reserved3 0x%x\n# same structure as FAT1X \n>>>>>>>64\tubyte\t\t>0x80\t\t\\b, physical drive 0x%x\n#>>>>>>>64\tubyte\t\t=0x80\t\t\\b, physical drive 0x%x=80 (usual harddisk)\n>>>>>>>64\tubyte&0x7F\t>0\t\t\\b, physical drive 0x%x\n#>>>>>>>64\tubyte\t\t=0\t\t\\b, physical drive 0x%x=0 (usual floppy)\n>>>>>>>65\tubyte\t\t>0\t\t\\b, reserved 0x%x\n>>>>>>>66\tubyte\t\t>0x29\t\t\\b, dos < 4.0 BootSector (0x%x)\n>>>>>>>66\tubyte\t\t<0x29\t\t\\b, dos < 4.0 BootSector (0x%x)\n>>>>>>>66\tubyte\t\t=0x29\n>>>>>>>>67\tulelong\t\tx\t\t\\b, serial number 0x%x\n>>>>>>>>71\tstring\t\t<NO\\ NAME\t\\b, label: \"%11.11s\"\n>>>>>>>71\tstring\t\t>NO\\ NAME\t\\b, label: \"%11.11s\"\n>>>>>>>71\tstring\t\t=NO\\ NAME\t\\b, unlabeled\n### FATs end\n>0x200\tlelong\t0x82564557\t\t\\b, BSD disklabel\n\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic/magic.firmware",
    "content": "\n#--------------------------Firmware Formats---------------------------\n\n# uImage file     \n# From: Craig Heffner, U-Boot image.h header definitions file\n0\tbelong\t0x27051956\tuImage header, header size: 64 bytes,\n>4\tbelong\tx\t\theader CRC: 0x%X,\n>8\tbedate\tx\t\tcreated: %s,\n>12\tbelong\tx\t\timage size: %d bytes,\n>16\tbelong\tx\t\tData Address: 0x%X,\n>20\tbelong\tx\t\tEntry Point: 0x%X,\n>24\tbelong\tx\t\tdata CRC: 0x%X,\n#>28\tbyte\tx\t\tOS type: %d,\n>28\tbyte\t0\t\tOS: Invalid OS,\n>28\tbyte\t1\t\tOS: OpenBSD,\n>28\tbyte\t2\t\tOS: NetBSD,\n>28\tbyte\t3\t\tOS: FreeBSD,\n>28\tbyte\t4\t\tOS: 4.4BSD,\n>28\tbyte\t5\t\tOS: Linux,\n>28\tbyte\t6\t\tOS: SVR4,\n>28\tbyte\t7\t\tOS: Esix,\n>28\tbyte\t8\t\tOS: Solaris,\n>28\tbyte\t9\t\tOS: Irix,\n>28\tbyte\t10\t\tOS: SCO,\n>28\tbyte\t11\t\tOS: Dell,\n>28\tbyte\t12\t\tOS: NCR,\n>28\tbyte\t13\t\tOS: LynxOS,\n>28\tbyte\t14\t\tOS: VxWorks,\n>28\tbyte\t15\t\tOS: pSOS,\n>28\tbyte\t16\t\tOS: QNX,\n>28\tbyte\t17\t\tOS: Firmware,\n>28\tbyte\t18\t\tOS: RTEMS,\n>28\tbyte\t19\t\tOS: ARTOS,\n>28\tbyte\t20\t\tOS: Unity OS,\n#>29\tbyte\tx\t\tCPU arch: %d,\n>29\tbyte\t0\t\tCPU: Invalid OS,\n>29\tbyte\t1\t\tCPU: Alpha,\n>29\tbyte\t2\t\tCPU: ARM,\n>29\tbyte\t3\t\tCPU: Intel x86,\n>29\tbyte\t4\t\tCPU: IA64,\n>29\tbyte\t5\t\tCPU: MIPS,\n>29\tbyte\t6\t\tCPU: MIPS 64 bit,\n>29\tbyte\t7\t\tCPU: PowerPC,\n>29\tbyte\t8\t\tCPU: IBM S390,\n>29\tbyte\t9\t\tCPU: SuperH,\n>29\tbyte\t10\t\tCPU: Sparc,\n>29\tbyte\t11\t\tCPU: Sparc 64 bit,\n>29\tbyte\t12\t\tCPU: M68K,\n>29\tbyte\t13\t\tCPU: Nios-32,\n>29\tbyte\t14\t\tCPU: MicroBlaze,\n>29\tbyte\t15\t\tCPU: Nios-II,\n>29\tbyte\t16\t\tCPU: Blackfin,\n>29\tbyte\t17\t\tCPU: AVR,\n>29\tbyte\t18\t\tCPU: STMicroelectronics ST200,\n#>30\tbyte\tx\t\timage type: %d,\n>30\tbyte\t0\t\timage type: Invalid Image,\n>30\tbyte\t1\t\timage type: Standalone Program,\n>30\tbyte\t2\t\timage type: OS Kernel Image,\n>30\tbyte \t3\t\timage type: RAMDisk Image,\n>30\tbyte\t4\t\timage type: Multi-File Image,\n>30\tbyte\t5\t\timage type: Firmware Image,\n>30\tbyte\t6\t\timage type: Script file,\n>30\tbyte\t7\t\timage type: Filesystem Image,\n>30\tbyte\t8\t\timage type: Binary Flat Device Tree Blob\n#>31\tbyte\tx\t\tcompression type: %d,\n>31\tbyte\t0\t\tcompression type: none,\n>31\tbyte\t1\t\tcompression type: gzip,\n>31\tbyte\t2\t\tcompression type: bzip2,\n>31\tbyte\t3\t\tcompression type: lzma,\n>32\tstring\tx\t\timage name: %s\n\n#IMG0 header, found in VxWorks-based Mercury router firmware\n0\tstring\t\tIMG0\t\tIMG0 (VxWorks) header,\n>4\tbelong\t\tx\t\tsize: %d\n\n#Mediatek bootloader signature\n#From xp-dev.com\n0\tstring\t\tBOOTLOADER!\tMediatek bootloader\n\n#CSYS header formats\n0\tstring\t\tCSYS\\x00\tCSYS header, little endian, \n>8\tlelong\t\tx\t\tsize: %d\n\n0\tstring\t\tCSYS\\x80\tCSYS header, big endian,\n>8\tbelong\t\tx\t\tsize: %d\n\n# wrgg firmware image\n0\tstring\t\twrgg02\t\tWRGG firmware header,\n>6\tstring\t\tx\t\tname: %s,\n>48\tstring\t\tx\t\troot device: %s\n\n# trx image file\n0\tstring          HDR0            TRX firmware header, little endian, header size: 28 bytes, \n>4\tlelong\t\tx\t\timage size: %d bytes,\n>8\tlelong\t\tx\t\tCRC32: 0x%X\n>12\tlelong\t\tx\t\tflags/version: 0x%X\n\n0\tstring          0RDH            TRX firmware header, big endian, header size: 28 bytes,\n>4\tbelong\t\tx\t\timage size: %d bytes,\n>8\tbelong\t\tx\t\tCRC32: 0x%X\n>12\tbelong\t\tx\t\tflags/version: 0x%X\n\n\n# Ubicom firmware image\n0\tbelong\t0xFA320080\t\tUbicom firmware header,\n>12\tbelong\tx\t\t\tchecksum: 0x%X,\n>24\tbelong\tx\t\t\timage size: %d\n\n# The ROME bootloader is used by several RealTek-based products.\n# Unfortunately, the magic bytes are specific to each product, so\n# separate signatures must be created for each one.\n\n# Netgear KWGR614 ROME image\n0\tstring\t\tG614\t\tRealtek firmware header (ROME bootloader),\n>4\tbeshort\t\t0xd92f\t\timage type: KFS,\n>4\tbeshort\t\t0xb162\t\timage type: RDIR,\n>4\tbeshort\t\t0xea43\t\timage type: BOOT,\n>4\tbeshort\t\t0x8dc9\t\timage type: RUN,\n>4\tbeshort\t\t0x2a05\t\timage type: CCFG,\n>4\tbeshort\t\t0x6ce8\t\timage type: DCFG,\n>4\tbeshort\t\t0xc371\t\timage type: LOG,\n>6\tbyte\t\tx\t\theader version: %d,\n#month\n>10\tbyte\t\tx\t\tcreated: %d/\n#day\t\n>12\tbyte \t\tx\t\t\\b%d/\n#year\n>8\tbeshort\t\tx\t\t\\b%d,\n>16\tbelong\t\tx\t\timage size: %d bytes,\n>22\tbyte\t\tx\t\tbody checksum: 0x%X,\n>23\tbyte\t\tx\t\theader checksum: 0x%X\n\n# Linksys WRT54GX ROME image\n0\tbelong\t\t0x59a0e842\tRealtek firmware header (ROME bootloader)\n>4      beshort         0xd92f          image type: KFS,\n>4      beshort         0xb162          image type: RDIR,\n>4      beshort         0xea43          image type: BOOT,\n>4      beshort         0x8dc9          image type: RUN,\n>4      beshort         0x2a05          image type: CCFG,\n>4      beshort         0x6ce8          image type: DCFG,\n>4      beshort         0xc371          image type: LOG,\n>6      byte            x               header version: %d,\n#month\n>10     byte            x               created: %d/\n#day    \n>12     byte            x               \\b%d/\n#year\n>8      beshort         x               \\b%d,\n>16     belong          x               image size: %d bytes,\n>22     byte            x               body checksum: 0x%X,\n>23     byte            x               header checksum: 0x%X\n\n# PackImg tag, somtimes used as a delimiter between the kernel and rootfs in firmware images.\n0\tstring\t\t--PaCkImGs--\tPackImg Tag,\n>16\tlelong\t\tx\t\tlittle endian size: %d bytes;\n>16\tbelong\t\tx\t\tbig endian size: %d bytes\n\n\n#------------------------------------------------------------------------------\n# Broadcom header format\n#\n0       string          BCRM            Broadcom header,\n>4      lelong          x               number of sections: %d,\n>>8     lelong          18              first section type: flash\n>>8     lelong          19              first section type: disk\n>>8     lelong          21              first section type: tag\n\n\n# Berkeley Lab Checkpoint Restart (BLCR) checkpoint context files\n# http://ftg.lbl.gov/checkpoint\n0       string  Ck0\\0\\0R\\0\\0\\0  BLCR\n>16     lelong  1       x86\n>16     lelong  3       alpha\n>16     lelong  5       x86-64\n>16     lelong  7       ARM\n>8      lelong  x       context data (little endian, version %d)\n\n0       string  \\0\\0\\0C\\0\\0\\0R  BLCR\n>16     belong  2       SPARC\n>16     belong  4       ppc\n>16     belong  6       ppc64\n>16     belong  7       ARMEB\n>16     belong  8       SPARC64\n>8      belong  x       context data (big endian, version %d)\n\n# Aculab VoIP firmware\n# From: Mark Brown <broonie@sirena.org.uk>\n0       string  VoIP\\ Startup\\ and      Aculab VoIP firmware\n>35     string  x       format %s\n\n#------------------------------------------------------------------------------\n# HP LaserJet 1000 series downloadable firmware file\n0       string  \\xbe\\xefABCDEFGH        HP LaserJet 1000 series downloadable firmware\n\n# From Albert Cahalan <acahalan@gmail.com>\n# really le32 operation,destination,payloadsize (but quite predictable)\n# 01 00 00 00 00 00 00 c0 00 02 00 00\n0       string          \\1\\0\\0\\0\\0\\0\\0\\300\\0\\2\\0\\0      Marvell Libertas firmware\n\n#---------------------------------------------------------------------------\n# The following entries have been tested by Duncan Laurie <duncan@sun.com> (a\n# lead Sun/Cobalt developer) who agrees that they are good and worthy of\n# inclusion.\n\n# Boot ROM images for Sun/Cobalt Linux server appliances\n0       string  Cobalt\\ Networks\\ Inc.\\nFirmware\\ v     Paged COBALT boot rom\n>38     string x        V%.4s\n\n# New format for Sun/Cobalt boot ROMs is annoying, it stores the version code\n# at the very end where file(1) can't get it.\n0       string CRfs     COBALT boot rom data (Flat boot rom or file system)\n\n#\n# Motorola S-Records, from Gerd Truschinski <gt@freebsd.first.gmd.de>\n0   string      S0          Motorola S-Record; binary data in text format\n\n# --------------------------------\n# Microsoft Xbox data file formats\n0       string          XIP0            XIP, Microsoft Xbox data\n0       string          XTF0            XTF, Microsoft Xbox data\n\n#Windows CE\n64\tstring\t\tCECE\t\tWindows CE RTOS\n\n# --------------------------------\n# ZynOS ROM header format\n# From openwrt zynos.h.\n6\tstring\t\tSIG\t\tZynOS header, header size: 48 bytes,\n>0\tbelong\t\tx\t\tload address 0x%X,\n>9\tbyte\t\t<0x7F\t\trom image type:\n>>9\tbyte\t\t<1\t\tinvalid,\n>>9\tbyte\t\t>7\t\tinvalid,\n>>9\tbyte\t\t1\t\tROMIMG,\n>>9\tbyte\t\t2\t\tROMBOOT,\n>>9\tbyte\t\t3\t\tBOOTEXT,\n>>9\tbyte\t\t4\t\tROMBIN,\n>>9\tbyte\t\t5\t\tROMDIR,\n>>9\tbyte\t\t6\t\t6,\n>>9\tbyte\t\t7\t\tROMMAP,\n>9\tbyte\t\t>0x7F\t\tram image type:\n>>9\tbyte\t\t>0x82\t\tinvalid,\n>>9\tbyte\t\t0x80\t\tRAM,\n>>9\tbyte\t\t0x81\t\tRAMCODE,\n>>9\tbyte\t\t0x82\t\tRAMBOOT,\n>10\tbelong\t\t>0x40000000\tinvalid\n>10\tbelong\t\t<0\t\tinvalid\n>10\tbelong\t\t0\t\tinvalid\n>10\tbelong\t\tx\t\tuncompressed size: %d,\n>14\tbelong\t\t>0x40000000\tinvalid\n>14\tbelong\t\t<0\t\tinvalid\n>14\tbelong\t\t0  \t\tinvalid\n>14\tbelong\t\tx\t\tcompressed size: %d,\n>20\tbeshort\t\tx\t\tuncompressed checksum: 0x%X,\n>22\tbeshort\t\tx\t\tcompressed checksum: 0x%X,\n>18\tbyte\t\tx\t\tflags: 0x%X,\n>18\tbyte\t\t&0x40\t\tuncompressed checksum is valid,\n>18\tbyte\t\t&0x80\t\tthe binary is compressed,\n>>18\tbyte\t\t&0x20\t\tcompressed checksum is valid,\n>41\tbelong\t\tx\t\tmemory map table address: 0x%X\n\n# Firmware header used by some VxWorks-based Cisco products\n0\tstring\t\tCI032.00\tCisco VxWorks firmware header,\n>8\tlelong\t\t>1024\t\tinvalid\n>8\tlelong\t\t<0\t\tinvalid\n>8\tlelong\t\tx\t\theader size: %d bytes,\n>32\tlelong\t\t>1024\t\tinvalid\n>32\tlelong\t\t<0\t\tinvalid\n>32\tlelong\t\tx\t\tnumber of files: %d,\n>48\tlelong\t\t<0\t\tinvalid\n>48\tlelong\t\tx\t\timage size: %d,\n>64\tstring\t\tx\t\tfirmware version: %s\n\n# Firmware header used by some TV's\n0\tstring\t\tFNIB\t\tZBOOT firmware header, header size: 32 bytes,\n>8\tlelong\t\tx\t\tload address: 0x%.8X,\n>12\tlelong\t\tx\t\tstart address: 0x%.8X,\n>16\tlelong\t\tx\t\tchecksum: 0x%.8X,\n>20\tlelong\t\tx\t\tversion: 0x%.8X,\n>24\tlelong\t\t<1\t\tinvalid\n>24\tlelong\t\tx\t\timage size: %d bytes\n\n# Firmware header used by several D-Link routers (and probably others)\n0               string  \\x5e\\xa3\\xa4\\x17\n>(7.b+12)       string  \\x5e\\xa3\\xa4\\x17        DLOB firmware header,\n>>12            string  x                       %s,\n>>(7.b+40)      string  x                       %s\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic/magic.kernels",
    "content": "\n#-------------------------Kernels-------------------------------------\n\n# Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>\n# and others such as Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>\n# and Nicolás Lichtmaier <nick@debian.org>\n# All known start with: b8 c0 07 8e d8 b8 00 90 8e c0 b9 00 01 29 f6 29\n514     string          HdrS            Linux kernel\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic.binarch",
    "content": "# MIPS prologue\n# addiu $sp, -XX\n# 27 BD FF XX\n1\tstring\t\\377\\275\\47\tMIPSEL function prologue\n0       string  \\47\\275\\377\tMIPS function prologue\n\n# MIPS epilogue\n# jr $ra\n0\tbelong\t0x03e00008\tMIPS function epilogue\n0\tlelong\t0x03e00008\tMIPSEL function epilogue\n\n# PowerPC epilogue\n# blr\n0\tbelong 0x4E800020\tPowerPC big endian function epilogue\n0\tlelong 0x4E800020\tPowerPC little endian function epilogue\n\n# ARM prologue\n# STMFD SP!, {XX}\n0\tbeshort\t0xE92D\t\tARMEB function prologue\n2\tleshort\t0xE92D\t\tARM function prologue\n\n# ARM epilogue\n# LDMFD SP!, {XX}\n0\tbeshort\t0xE8BD\t\tARMEB function epilogue\n2\tleshort\t0xE8BD\t\tARM function epilogue\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic.bincast",
    "content": "0\tbelong x\tHex:                 0x%.8X\n#0\tstring x\tString:              %s\n0\tlelong x\tLittle Endian Long:  %d\n0\tbelong x\tBig Endian Long:     %d\n0\tleshort x\tLittle Endian Short: %d\n0\tbeshort x\tBig Endian Short:    %d\n0\tledate x\tLittle Endian Date:  %s\n0\tbedate x\tBig Endian Date:     %s\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/magic.binwalk",
    "content": "\n# ----------------------------Archive Formats--------------------------------------\n\n# POSIX tar archives\n257     string          ustar\\000         POSIX tar archive\n!:mime  application/x-tar # encoding: posix\n257     string          ustar\\040\\040\\000 GNU tar archive\n!:mime  application/x-tar # encoding: gnu\n\n# MIPS archive (needs to go before regular portable archives)\n#\n0       string  =!<arch>\\n__________E   MIPS archive\n>20     string  U                       with MIPS Ucode members\n>21     string  L                       with MIPSEL members\n>21     string  B                       with MIPSEB members\n>19     string  L                       and an EL hash table\n>19     string  B                       and an EB hash table\n>22     string  X                       -- out of date\n\n# JAR archiver (.j), this is the successor to ARJ, not Java's JAR (which is essentially ZIP)\n0xe     string  \\x1aJar\\x1b JAR (ARJ Software, Inc.) archive data\n0       string  JARCS JAR (ARJ Software, Inc.) archive data\n\n\n# ARJ archiver (jason@jarthur.Claremont.EDU)\n0       leshort         0xea60          ARJ archive data\n!:mime  application/x-arj\n>5      byte            x               \\b, v%d,\n>8      byte            &0x04           multi-volume,\n>8      byte            &0x10           slash-switched,\n>8      byte            &0x20           backup,\n>34     string          x               original name: %s,\n>7      byte            0               os: MS-DOS \n>7      byte            1               os: PRIMOS\n>7      byte            2               os: Unix\n>7      byte            3               os: Amiga\n>7      byte            4               os: Macintosh\n>7      byte            5               os: OS/2\n>7      byte            6               os: Apple ][ GS\n>7      byte            7               os: Atari ST\n>7      byte            8               os: NeXT\n>7      byte            9               os: VAX/VMS\n>3      byte            >0              %d]\n# [JW] idarc says this is also possible\n2       leshort         0xea60          ARJ archive data\n>5      byte            x               \\b, v%d,\n>8      byte            &0x04           multi-volume,\n>8      byte            &0x10           slash-switched,\n>8      byte            &0x20           backup,\n>34     string          x               original name: %s,\n>7      byte            0               os: MS-DOS\n>7      byte            1               os: PRIMOS\n>7      byte            2               os: Unix\n>7      byte            3               os: Amiga\n>7      byte            4               os: Macintosh\n>7      byte            5               os: OS/2\n>7      byte            6               os: Apple ][ GS\n>7      byte            7               os: Atari ST\n>7      byte            8               os: NeXT\n>7      byte            9               os: VAX/VMS\n>3      byte            >0              %d]\n\n# RAR archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\tRar!\t\tRAR archive data [NSRL|RAR]\n\n# HPACK archiver (Peter Gutmann, pgut1@cs.aukuni.ac.nz)\n0\tstring\t\tHPAK\t\tHPACK archive data [NSRL|HPAK]\n\n# JAM Archive volume format, by Dmitry.Kohmanyuk@UA.net\n0\tstring\t\t\\351,\\001JAM\\\t\tJAM archive, [NSRL|JAM]\n\n# LHARC/LHA archiver (Greg Roelofs, newt@uchicago.edu)\n2\tstring\t\t-lh0-\t\tLHarc 1.x archive data [lh0] [NSRL|LHA1]\n2\tstring\t\t-lh1-\t\tLHarc 1.x archive data [lh1] [NSRL|LHA1]\n2\tstring\t\t-lz4-\t\tLHarc 1.x archive data [lz4] [NSRL|LHA1]\n2\tstring\t\t-lz5-\t\tLHarc 1.x archive data [lz5] [NSRL|LHA1]\n#\t[never seen any but the last; -lh4- reported in comp.compression:]\n2\tstring\t\t-lzs-\t\tLHa 2.x? archive data [lzs] [NSRL|LHA2]\n2\tstring\t\t-lh\\40-\t\tLHa 2.x? archive data [lh ] [NSRL|LHA2]\n2\tstring\t\t-lhd-\t\tLHa 2.x? archive data [lhd] [NSRL|LHA2]\n2\tstring\t\t-lh2-\t\tLHa 2.x? archive data [lh2] [NSRL|LHA2]\n2\tstring\t\t-lh3-\t\tLHa 2.x? archive data [lh3] [NSRL|LHA2]\n2\tstring\t\t-lh4-\t\tLHa (2.x) archive data [lh4] [NSRL|LHA2]\n2\tstring\t\t-lh5-\t\tLHa (2.x) archive data [lh5] [NSRL|LHA2]\n2\tstring\t\t-lh6-\t\tLHa (2.x) archive data [lh6] [NSRL|LHA2]\n2\tstring\t\t-lh7-\t\tLHa (2.x) archive data [lh7] [NSRL|LHA2]\n\n# SQUISH archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\tSQSH\t\tsquished archive data (Acorn RISCOS) [NSRL|SQSH]\n\n# UC2 archiver (Greg Roelofs, newt@uchicago.edu)\n# I can't figure out the self-extracting form of these buggers...\n0\tstring\t\tUC2\\x1a\t\tUC2 archive data [NSRL|UC2]\n\n# Zoo archiver\n20\tlelong\t\t0xfdc4a7dc\tZoo archive data [NSRL|ZOO]\n\n# Shell archives\n# JT, 2004-03-17: The \"#\" in the middle of the line makes it look like the\n# rest of the line is commented out - I guess it's OK? Beware if parsing!\n10\tstring\t\t#\\ This\\ is\\ a\\ shell\\ archive\tshell archive text [NSRL|SH]\n\n#\n# LBR. NB: May conflict with the questionable \n#          \"binary Computer Graphics Metafile\" format.\n#\n0       string  \\0\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\0\\0    LBR archive data [NSRL|LBR]\n#\n# PMA (CP/M derivative of LHA)\n#\n2       string          -pm0-           PMarc archive data [pm0] [NSRL|PMA]\n2       string          -pm1-           PMarc archive data [pm1] [NSRL|PMA]\n2       string          -pm2-           PMarc archive data [pm2] [NSRL|PMA]\n2       string          -pms-           PMarc SFX archive (CP/M, DOS) [NSRL|PMA-SFX]\n5       string          -pc1-           PopCom compressed executable archive (CP/M) [NSRL|PPC-SFX]\n\n# From rafael@icp.inpg.fr (Rafael Laboissiere) \n# The Project Revision Control System (see\n# http://www.XCF.Berkeley.EDU/~jmacd/prcs.html) generates a packaged project\n# file which is recognized by the following entry:\n0\tleshort\t\t0xeb81\tPRCS packaged project archive [NSRL|PRCS]\n\n# GTKtalog catalogs \n# by David Necas (Yeti) <yeti@physics.muni.cz>\n4\tstring\tgtktalog\\ \tGTKtalog catalog data archive, [NSRL|GTK]\n>>14\tbeshort\t0x677a\t\t(gzipped)\n\n\n#---------------------------Bootloaders--------------------------------\n\n# CFE bootloader\n0\tstring\tCFE1CFE1\tCFE boot loader, little endian\n0\tstring\t1EFC1EFC\tCFE boot loader, big endian\n\n\n#------------------Compression Formats-----------------------------\n\n# bzip2\n0       string          BZh\n>4\tstring\t\t1AY&SY\t\tbzip2 compressed data\n!:mime  application/x-bzip2\n>>3      byte            >47            \\b, block size = %c00k\n\n# lzip  \n0       string          LZIP            lzip compressed data\n!:mime application/x-lzip\n>4      byte            x               \\b, version: %d\n\n# LZO\n0\tstring\t\t\\211LZO\\000\\015\\012\\032\\012\tLZO compressed data\n\n# 7-zip archiver, from Thomas Klausner (wiz@danbala.tuwien.ac.at)\n# http://www.7-zip.org or DOC/7zFormat.txt \n#\n0       string          7z\\274\\257\\047\\034      7-zip archive data,\n>6      byte            x                       version %d\n>7      byte            x                       \\b.%d\n\n# standard unix compress\n0       beshort\t\t0x1f9d          compress'd data\n>2      byte&0x80       >0              block compressed\n>2      byte&0x1f       x               %d bits\n\n# gzip (GNU zip, not to be confused with Info-ZIP or PKWARE zip archiver)\n#   Edited by Chris Chittleborough <cchittleborough@yahoo.com.au>, March 2002\n#       * Original filename is only at offset 10 if \"extra field\" absent\n#       * Produce shorter output - notably, only report compression methods\n#         other than 8 (\"deflate\", the only method defined in RFC 1952).\n0       string          \\037\\213        gzip compressed data\n!:mime  application/x-gzip\n>2      byte            <8              \\b, reserved (invalid) method\n>2      byte            >8              \\b, unknown (invalid) method\n>3      byte            &0x01           \\b, ASCII\n>3      byte            &0x02           \\b, has CRC\n>3      byte            &0x04           \\b, extra field\n>3      byte&0xC        =0x08\n>>10    string          x               \\b, was \"%s\"\n>3      byte            &0x10           \\b, has comment\n>9      byte            =0x00           \\b, from FAT filesystem (MS-DOS, OS/2, NT)\n>9      byte            =0x01           \\b, from Amiga\n>9      byte            =0x02           \\b, from VMS\n>9      byte            =0x03           \\b, from Unix\n>9      byte            =0x04           \\b, from VM/CMS\n>9      byte            =0x05           \\b, from Atari\n>9      byte            =0x06           \\b, from HPFS filesystem (OS/2, NT)\n>9      byte            =0x07           \\b, from MacOS\n>9      byte            =0x08           \\b, from Z-System\n>9      byte            =0x09           \\b, from CP/M\n>9      byte            =0x0A           \\b, from TOPS/20\n>9      byte            =0x0B           \\b, from NTFS filesystem (NT)\n>9      byte            =0x0C           \\b, from QDOS\n>9      byte            =0x0D           \\b, from Acorn RISCOS\n>9\tbyte\t\t>0x0D\t\t\\b, invalid source\n>3      byte            &0x10           \\b, comment\n>3      byte            &0x20           \\b, encrypted\n# Dates before 1992 are invalid, unless of course you're DD-WRT in which\n# case you don't know how to set a date in your gzip files. Brilliant.\n>4\tlelong\t\t=0\t\t\\b, DD-WRT date:\n>4\tlelong\t\t<0\t\t\\b, invalid date:\n>4\tlelong\t\t>0\t\t\n>>4\tlelong\t\t<694224000\t\\b, invalid date:\n>>4\tlelong\t\t=694224000\t\\b, invalid date:\n>>4\tlelong\t\t>694224000\t\\b, last modified:\n>4      ledate          x               %s\n>8      byte            2               \\b, max compression\n>8      byte            4               \\b, max speed\n\n# Zlib signatures\n0\tbeshort\t\t0x789C\t\tzlib compressed data\n0\tbeshort\t\t0x78DA\t\tzlib compressed data\n0\tbeshort\t\t0x7801\t\tzlib compressed data\n\n# Supplementary magic data for the file(1) command to support\n# rzip(1).  The format is described in magic(5).\n#\n# Copyright (C) 2003 by Andrew Tridgell.  You may do whatever you want with\n# this file.\n#\n0       string          RZIP            rzip compressed data\n>4      byte            x               - version %d\n>5      byte            x               \\b.%d\n>6      belong          x               (%d bytes)\n\n# ZIP compression (Greg Roelofs, c/o zip-bugs@wkuvx1.wku.edu)\n0       string          PK\\003\\004      Zip archive data, \n>4      byte            0x00            v0.0\n!:mime  application/zip \n>4      byte            0x09            at least v0.9 to extract\n!:mime  application/zip \n>4      byte            0x0a            at least v1.0 to extract\n!:mime  application/zip \n>4      byte            0x0b            at least v1.1 to extract\n!:mime  application/zip\n>0x161  string          WINZIP          WinZIP self-extracting\n!:mime  application/zip\n>4      byte            0x14\n>>30    ubelong         !0x6d696d65     at least v2.0 to extract\n!:mime  application/zip\n\n# Alternate ZIP string (amc@arwen.cs.berkeley.edu)\n0       string          PK00PK\\003\\004  Zip archive data [NSRL|ZIP]\n\n# Type: LZMA            \n# URL:  http://www.7-zip.org/sdk.html   \n#\n# Added additional parsing to help verify LZMA matches and weed out false positives.\n# Added improved signature checking.\n# Added checks for possibly (probably) invalid matches.\n# From: Craig Heffner\n\n#First LZMA signature\n0       string                  \\x5d\\x00\\x00            LZMA compressed data,\n>0\tleshort\t\t\t>0xE0\t\t\tinvalid\n>0\tbyte\t\t\tx\t\t\tproperties: 0x%.2X,\n>1\tlelong\t\t\t<1\t\t\tinvalid\n>1\tlelong\t\t\tx\t\t\tdictionary size: %d bytes,\n>5\tlequad\t\t\t0\t\t\tinvalid\n>5\tlequad\t\t\t<0\t\t\tinvalid\n>5\tlequad\t\t\t>0x40000000\t\tinvalid\n>5\tlequad\t\t\tx\t\t\tuncompressed size: %lld bytes\n\n#An alternative common LZMA signature\n1\tbelong\t\t\t0x00008000\t\tLZMA compressed data,\n>0\tbyte\t\t\t0\t\t\tinvalid\n>0\tleshort\t\t\t>0xE0\t\t\tinvalid\n>0\tbyte\t\t\tx\t\t\tproperties: 0x%.2X,\n>1      lelong                  <1                      invalid\n>1      lelong                  x                       dictionary size: %d bytes,\n>5\tlequad\t\t\t0\t\t\tinvalid\n>5      lequad                  <0                      invalid\n>5\tlequad\t\t\t>0x40000000\t\tinvalid\n>5      lequad                  x                       uncompressed size: %lld bytes\n\n#Signature for less common LZMA flag/dictionary values. Results in lots of false positives, but usually marked as invalid.\n1\tbeshort\t\t\t0x0000\t\t\tLZMA compressed data,\n>0\tbyte\t\t\t0\t\t\tinvalid\n>0\tbyte\t\t\t>0xE0\t\t\tinvalid\n>0\tbyte\t\t\tx\t\t\tproperties: 0x%.2X,\n>1\tlelong\t\t\t<1\t\t\tinvalid\n>1\tlelong\t\t\tx\t\t\tdictionary size: %d bytes,\n>5\tlequad\t\t\t0\t\t\tinvalid\n>5\tlequad\t\t\t<0\t\t\tinvalid\n>5\tlequad\t\t\t>0x40000000\t\tinvalid\n>5\tlequad\t\t\tx\t\t\tuncompressed size: %lld bytes\n\n\n\n#------------------Standard file formats------------------------------------\n\n# elf:  file(1) magic for ELF executables\n#\n# We have to check the byte order flag to see what byte order all the\n# other stuff in the header is in.\n#\n# What're the correct byte orders for the nCUBE and the Fujitsu VPP500?\n#\n# Created by: unknown\n# Modified by (1): Daniel Quinlan <quinlan@yggdrasil.com>\n# Modified by (2): Peter Tobias <tobias@server.et-inf.fho-emden.de> (core support)\n# Modified by (3): Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de> (fix of core support)\n# Modified by (4): <gerardo.cacciari@gmail.com> (VMS Itanium)\n# Modified by (5): Matthias Urlichs <smurf@debian.org> (Listing of many architectures)\n0       string          \\177ELF         ELF\n>4      byte            0               invalid class\n>4      byte            1               32-bit\n>4      byte            2               64-bit\n>5      byte            0               invalid byte order\n>5      byte            1               LSB\n>>16    leshort         0               no file type,\n!:strength *2\n!:mime  application/octet-stream\n>>16    leshort         1               relocatable,\n!:mime  application/x-object\n>>16    leshort         2               executable,\n!:mime  application/x-executable\n>>16    leshort         3               shared object,\n!:mime  application/x-sharedlib\n>>16    leshort         4               core file\n!:mime  application/x-coredump\n# Core file detection is not reliable.\n#>>>(0x38+0xcc) string  >\\0             of '%s'\n#>>>(0x38+0x10) lelong  >0              (signal %d),\n>>16    leshort         &0xff00         processor-specific,\n>>18    leshort         0               no machine,\n>>18    leshort         1               AT&T WE32100 - invalid byte order,\n>>18    leshort         2               SPARC - invalid byte order,\n>>18    leshort         3               Intel 80386,\n>>18    leshort         4               Motorola\n>>>36   lelong          &0x01000000     68000 - invalid byte order,\n>>>36   lelong          &0x00810000     CPU32 - invalid byte order,\n>>>36   lelong          0               68020 - invalid byte order,\n>>18    leshort         5               Motorola 88000 - invalid byte order,\n>>18    leshort         6               Intel 80486,\n>>18    leshort         7               Intel 80860,\n# The official e_machine number for MIPS is now #8, regardless of endianness.\n# The second number (#10) will be deprecated later. For now, we still\n# say something if #10 is encountered, but only gory details for #8.\n>>18    leshort         8               MIPS,\n>>>36   lelong          &0x20           N32\n>>18    leshort         10              MIPS,\n>>>36   lelong          &0x20           N32\n>>18    leshort         8\n# only for 32-bit\n>>>4    byte            1\n>>>>36  lelong&0xf0000000       0x00000000      MIPS-I\n>>>>36  lelong&0xf0000000       0x10000000      MIPS-II\n>>>>36  lelong&0xf0000000       0x20000000      MIPS-III\n>>>>36  lelong&0xf0000000       0x30000000      MIPS-IV\n>>>>36  lelong&0xf0000000       0x40000000      MIPS-V\n>>>>36  lelong&0xf0000000       0x50000000      MIPS32\n>>>>36  lelong&0xf0000000       0x60000000      MIPS64\n>>>>36  lelong&0xf0000000       0x70000000      MIPS32 rel2\n>>>>36  lelong&0xf0000000       0x80000000      MIPS64 rel2\n# only for 64-bit\n>>>4    byte            2\n>>>>48  lelong&0xf0000000       0x00000000      MIPS-I\n>>>>48  lelong&0xf0000000       0x10000000      MIPS-II\n>>>>48  lelong&0xf0000000       0x20000000      MIPS-III\n>>>>48  lelong&0xf0000000       0x30000000      MIPS-IV\n>>>>48  lelong&0xf0000000       0x40000000      MIPS-V\n>>>>48  lelong&0xf0000000       0x50000000      MIPS32\n>>>>48  lelong&0xf0000000       0x60000000      MIPS64\n>>>>48  lelong&0xf0000000       0x70000000      MIPS32 rel2\n>>>>48  lelong&0xf0000000       0x80000000      MIPS64 rel2\n>>18    leshort         9               Amdahl - invalid byte order,\n>>18    leshort         10              MIPS (deprecated),\n>>18    leshort         11              RS6000 - invalid byte order,\n>>18    leshort         15              PA-RISC - invalid byte order,\n>>>50   leshort         0x0214          2.0\n>>>48   leshort         &0x0008         (LP64),\n>>18    leshort         16              nCUBE,\n>>18    leshort         17              Fujitsu VPP500,\n>>18    leshort         18              SPARC32PLUS - invalid byte order,\n>>18    leshort         20              PowerPC,\n>>18    leshort         22              IBM S/390,\n>>18    leshort         36              NEC V800,\n>>18    leshort         37              Fujitsu FR20,\n>>18    leshort         38              TRW RH-32,\n>>18    leshort         39              Motorola RCE,\n>>18    leshort         40              ARM,\n>>18    leshort         41              Alpha,\n>>18    leshort         0xa390          IBM S/390 (obsolete),\n>>18    leshort         42              Renesas SH,\n>>18    leshort         43              SPARC V9 - invalid byte order,\n>>18    leshort         44              Siemens Tricore Embedded Processor,\n>>18    leshort         45              Argonaut RISC Core, Argonaut Technologies Inc.,\n>>18    leshort         46              Renesas H8/300,\n>>18    leshort         47              Renesas H8/300H,\n>>18    leshort         48              Renesas H8S,\n>>18    leshort         49              Renesas H8/500,\n>>18    leshort         50              IA-64,\n>>18    leshort         51              Stanford MIPS-X,\n>>18    leshort         52              Motorola Coldfire,\n>>18    leshort         53              Motorola M68HC12,\n>>18    leshort         54              Fujitsu MMA,\n>>18    leshort         55              Siemens PCP,\n>>18    leshort         56              Sony nCPU,\n>>18    leshort         57              Denso NDR1,\n>>18    leshort         58              Start*Core,\n>>18    leshort         59              Toyota ME16,\n>>18    leshort         60              ST100,\n>>18    leshort         61              Tinyj emb.,\n>>18    leshort         62              x86-64,\n>>18    leshort         63              Sony DSP,\n>>18    leshort         66              FX66,\n>>18    leshort         67              ST9+ 8/16 bit,\n>>18    leshort         68              ST7 8 bit,\n>>18    leshort         69              MC68HC16,\n>>18    leshort         70              MC68HC11,\n>>18    leshort         71              MC68HC08,\n>>18    leshort         72              MC68HC05,\n>>18    leshort         73              SGI SVx,\n>>18    leshort         74              ST19 8 bit,\n>>18    leshort         75              Digital VAX,\n>>18    leshort         76              Axis cris,\n>>18    leshort         77              Infineon 32-bit embedded,\n>>18    leshort         78              Element 14 64-bit DSP,\n>>18    leshort         79              LSI Logic 16-bit DSP,\n>>18    leshort         80              MMIX,\n>>18    leshort         81              Harvard machine-independent,\n>>18    leshort         82              SiTera Prism,\n>>18    leshort         83              Atmel AVR 8-bit,\n>>18    leshort         84              Fujitsu FR30,\n>>18    leshort         85              Mitsubishi D10V,\n>>18    leshort         86              Mitsubishi D30V,\n>>18    leshort         87              NEC v850,\n>>18    leshort         88              Renesas M32R,\n>>18    leshort         89              Matsushita MN10300,\n>>18    leshort         90              Matsushita MN10200,\n>>18    leshort         91              picoJava,\n>>18    leshort         92              OpenRISC,\n>>18    leshort         93              ARC Cores Tangent-A5,\n>>18    leshort         94              Tensilica Xtensa,\n>>18    leshort         97              NatSemi 32k,\n>>18    leshort         106             Analog Devices Blackfin,\n>>18    leshort         113             Altera Nios II,\n>>18    leshort         0xae            META,\n>>18    leshort         0x3426          OpenRISC (obsolete),\n>>18    leshort         0x8472          OpenRISC (obsolete),\n>>18    leshort         0x9026          Alpha (unofficial),\n>>20    lelong          0               invalid version\n>>20    lelong          1               version 1\n>>36    lelong          1               MathCoPro/FPU/MAU Required\n>5      byte            2               MSB\n>>16    beshort         0               no file type,\n!:mime  application/octet-stream\n>>16    beshort         1               relocatable,\n!:mime  application/x-object\n>>16    beshort         2               executable,\n!:mime  application/x-executable\n>>16    beshort         3               shared object,\n!:mime  application/x-sharedlib\n>>16    beshort         4               core file,\n!:mime  application/x-coredump\n#>>>(0x38+0xcc) string  >\\0             of '%s'\n#>>>(0x38+0x10) belong  >0              (signal %d),\n>>16    beshort         &0xff00         processor-specific,\n>>18    beshort         0               no machine,\n>>18    beshort         1               AT&T WE32100,\n>>18    beshort         2               SPARC,\n>>18    beshort         3               Intel 80386 - invalid byte order,\n>>18    beshort         4               Motorola\n>>>36   belong          &0x01000000     68000,\n>>>36   belong          &0x00810000     CPU32,\n>>>36   belong          0               68020,\n>>18    beshort         5               Motorola 88000,\n>>18    beshort         6               Intel 80486 - invalid byte order,\n>>18    beshort         7               Intel 80860,\n# only for MIPS - see comment in little-endian section above.\n>>18    beshort         8               MIPS,\n>>>36   belong          &0x20           N32\n>>18    beshort         10              MIPS,\n>>>36   belong          &0x20           N32\n>>18    beshort         8\n# only for 32-bit\n>>>4    byte            1\n>>>>36  belong&0xf0000000       0x00000000      MIPS-I\n>>>>36  belong&0xf0000000       0x10000000      MIPS-II\n>>>>36  belong&0xf0000000       0x20000000      MIPS-III\n>>>>36  belong&0xf0000000       0x30000000      MIPS-IV\n>>>>36  belong&0xf0000000       0x40000000      MIPS-V\n>>>>36  belong&0xf0000000       0x50000000      MIPS32\n>>>>36  belong&0xf0000000       0x60000000      MIPS64\n>>>>36  belong&0xf0000000       0x70000000      MIPS32 rel2\n>>>>36  belong&0xf0000000       0x80000000      MIPS64 rel2\n# only for 64-bit\n>>>4    byte            2\n>>>>48  belong&0xf0000000       0x00000000      MIPS-I\n>>>>48  belong&0xf0000000       0x10000000      MIPS-II\n>>>>48  belong&0xf0000000       0x20000000      MIPS-III\n>>>>48  belong&0xf0000000       0x30000000      MIPS-IV\n>>>>48  belong&0xf0000000       0x40000000      MIPS-V\n>>>>48  belong&0xf0000000       0x50000000      MIPS32\n>>>>48  belong&0xf0000000       0x60000000      MIPS64\n>>>>48  belong&0xf0000000       0x70000000      MIPS32 rel2\n>>>>48  belong&0xf0000000       0x80000000      MIPS64 rel2\n>>18    beshort         9               Amdahl,\n>>18    beshort         10              MIPS (deprecated),\n>>18    beshort         11              RS6000,\n>>18    beshort         15              PA-RISC\n>>>50   beshort         0x0214          2.0\n>>>48   beshort         &0x0008         (LP64)\n>>18    beshort         16              nCUBE,\n>>18    beshort         17              Fujitsu VPP500,\n>>18    beshort         18              SPARC32PLUS,\n>>>36   belong&0xffff00 0x000100        V8+ Required,\n>>>36   belong&0xffff00 0x000200        Sun UltraSPARC1 Extensions Required,\n>>>36   belong&0xffff00 0x000400        HaL R1 Extensions Required,\n>>>36   belong&0xffff00 0x000800        Sun UltraSPARC3 Extensions Required,\n>>18    beshort         20              PowerPC or cisco 4500,\n>>18    beshort         21              64-bit PowerPC or cisco 7500,\n>>18    beshort         22              IBM S/390,\n>>18    beshort         23              Cell SPU,\n>>18    beshort         24              cisco SVIP,\n>>18    beshort         25              cisco 7200,\n>>18    beshort         36              NEC V800 or cisco 12000,\n>>18    beshort         37              Fujitsu FR20,\n>>18    beshort         38              TRW RH-32,\n>>18    beshort         39              Motorola RCE,\n>>18    beshort         40              ARM,\n>>18    beshort         41              Alpha,\n>>18    beshort         42              Renesas SH,\n>>18    beshort         43              SPARC V9,\n>>>48   belong&0xffff00 0x000200        Sun UltraSPARC1 Extensions Required,\n>>>48   belong&0xffff00 0x000400        HaL R1 Extensions Required,\n>>>48   belong&0xffff00 0x000800        Sun UltraSPARC3 Extensions Required,\n>>>48   belong&0x3      0               total store ordering,\n>>>48   belong&0x3      1               partial store ordering,\n>>>48   belong&0x3      2               relaxed memory ordering,\n>>18    beshort         44              Siemens Tricore Embedded Processor,\n>>18    beshort         45              Argonaut RISC Core, Argonaut Technologies Inc.,\n>>18    beshort         46              Renesas H8/300,\n>>18    beshort         47              Renesas H8/300H,\n>>18    beshort         48              Renesas H8S,\n>>18    beshort         49              Renesas H8/500,\n>>18    beshort         50              IA-64,\n>>18    beshort         51              Stanford MIPS-X,\n>>18    beshort         52              Motorola Coldfire,\n>>18    beshort         53              Motorola M68HC12,\n>>18    beshort         73              Cray NV1,\n>>18    beshort         75              Digital VAX,\n>>18    beshort         88              Renesas M32R,\n>>18    leshort         92              OpenRISC,\n>>18    leshort         0x3426          OpenRISC (obsolete),\n>>18    leshort         0x8472          OpenRISC (obsolete),\n>>18    beshort         94              Tensilica Xtensa,\n>>18    beshort         97              NatSemi 32k,\n>>18    beshort         0x18ad          AVR32 (unofficial),\n>>18    beshort         0x9026          Alpha (unofficial),\n>>18    beshort         0xa390          IBM S/390 (obsolete),\n>>20    belong          0               invalid version\n>>20    belong          1               version 1\n>>36    belong          1               MathCoPro/FPU/MAU Required\n# Up to now only 0, 1 and 2 are defined; I've seen a file with 0x83, it seemed\n# like proper ELF, but extracting the string had bad results.\n>4      byte            <0x80\n>>8     string          >\\0             (%s)\n>8      string          \\0\n>>7     byte            0               (SYSV)\n>>7     byte            1               (HP-UX)\n>>7     byte            2               (NetBSD)\n>>7     byte            3               (GNU/Linux)\n>>7     byte            4               (GNU/Hurd)\n>>7     byte            5               (86Open)\n>>7     byte            6               (Solaris)\n>>7     byte            7               (Monterey)\n>>7     byte            8               (IRIX)\n>>7     byte            9               (FreeBSD)\n>>7     byte            10              (Tru64)\n>>7     byte            11              (Novell Modesto)\n>>7     byte            12              (OpenBSD)\n>8      string          \\2\n>>7     byte            13              (OpenVMS)\n>>7     byte            97              (ARM)\n>>7     byte            255             (embedded)\n\n\n\n# XXX - according to Microsoft's spec, at an offset of 0x3c in a\n# PE-format executable is the offset in the file of the PE header;\n# unfortunately, that's a little-endian offset, and there's no way\n# to specify an indirect offset with a specified byte order.\n# So, for now, we assume the standard MS-DOS stub, which puts the\n# PE header at 0x80 = 128.\n#\n# Required OS version and subsystem version were 4.0 on some NT 3.51\n# executables built with Visual C++ 4.0, so it's not clear that\n# they're interesting.  The user version was 0.0, but there's\n# probably some linker directive to set it.  The linker version was\n# 3.0, except for one \".exe\" which had it as 4.20 (same damn linker!).\n#\n# many of the compressed formats were extraced from IDARC 1.23 source code\n#\n0       string  MZ\n!:mime  application/x-dosexec\n>0x18  leshort <0x40 MS-DOS executable\n>0 string MZ\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0PE\\0\\0 \\b, PE for MS Windows\n>>&18   leshort&0x2000  >0      (DLL)\n>>&88   leshort         0       (unknown subsystem)\n>>&88   leshort         1       (native)\n>>&88   leshort         2       (GUI)\n>>&88   leshort         3       (console)\n>>&88   leshort         7       (POSIX)\n>>&0    leshort         0x0     unknown processor\n>>&0    leshort         0x14c   Intel 80386\n>>&0    leshort         0x166   MIPS R4000\n>>&0    leshort         0x184   Alpha\n>>&0    leshort         0x268   Motorola 68000\n>>&0    leshort         0x1f0   PowerPC\n>>&0    leshort         0x290   PA-RISC\n>>&18   leshort&0x0100  >0      32-bit\n>>&18   leshort&0x1000  >0      system file\n>>&228  lelong          >0      \\b, Mono/.Net assembly\n>>&0xf4 search/0x140 \\x0\\x40\\x1\\x0\n>>>(&0.l+(4)) string MSCF \\b, WinHKI CAB self-extracting archive\n>30             string  Copyright\\ 1989-1990\\ PKWARE\\ Inc.      Self-extracting PKZIP archive\n!:mime  application/zip\n# Is next line correct? One might expect \"Corp.\" not \"Copr.\" If it is right, add a note to that effect.\n>30             string  PKLITE\\ Copr.   Self-extracting PKZIP archive\n!:mime  application/zip\n\n>0x18  leshort >0x3f\n>>(0x3c.l) string PE\\0\\0 PE\n>>>(0x3c.l+25) byte             1 \\b32 executable\n>>>(0x3c.l+25) byte             2 \\b32+ executable\n# hooray, there's a DOS extender using the PE format, with a valid PE\n# executable inside (which just prints a message and exits if run in win)\n>>>(0x3c.l+92)  leshort         <10\n>>>>(8.s*16) string 32STUB for MS-DOS, 32rtm DOS extender\n>>>>(8.s*16) string !32STUB for MS Windows\n>>>>>(0x3c.l+22)        leshort&0x2000  >0      (DLL)\n>>>>>(0x3c.l+92)        leshort         0       (unknown subsystem)\n>>>>>(0x3c.l+92)        leshort         1       (native)\n>>>>>(0x3c.l+92)        leshort         2       (GUI)\n>>>>>(0x3c.l+92)        leshort         3       (console)\n>>>>>(0x3c.l+92)        leshort         7       (POSIX)\n>>>(0x3c.l+92)  leshort         10      (EFI application)\n>>>(0x3c.l+92)  leshort         11      (EFI boot service driver)\n>>>(0x3c.l+92)  leshort         12      (EFI runtime driver)\n>>>(0x3c.l+92)  leshort         13      (XBOX)\n>>>(0x3c.l+4)   leshort         0x0     unknown processor\n>>>(0x3c.l+4)   leshort         0x14c   Intel 80386\n>>>(0x3c.l+4)   leshort         0x166   MIPS R4000\n>>>(0x3c.l+4)   leshort         0x184   Alpha\n>>>(0x3c.l+4)   leshort         0x268   Motorola 68000\n>>>(0x3c.l+4)   leshort         0x1f0   PowerPC\n>>>(0x3c.l+4)   leshort         0x290   PA-RISC\n>>>(0x3c.l+4)   leshort         0x200   Intel Itanium\n>>>(0x3c.l+22)  leshort&0x0100  >0      32-bit\n>>>(0x3c.l+22)  leshort&0x1000  >0      system file\n>>>(0x3c.l+232) lelong  >0      Mono/.Net assembly\n>>>>(0x3c.l+0xf8)       string          UPX0 \\b, UPX compressed\n>>>>(0x3c.l+0xf8)       search/0x140    PEC2 \\b, PECompact2 compressed\n>>>>(0x3c.l+0xf8)       search/0x140    UPX2\n>>>>>(&0x10.l+(-4))     string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>(0x3c.l+0xf8)       search/0x140    .idata\n>>>>>(&0xe.l+(-4))      string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>>(&0xe.l+(-4))      string          ZZ0 \\b, ZZip self-extracting archive\n>>>>>(&0xe.l+(-4))      string          ZZ1 \\b, ZZip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .rsrc\n>>>>>(&0x0f.l+(-4))     string          a\\\\\\4\\5 \\b, WinHKI self-extracting archive\n>>>>>(&0x0f.l+(-4))     string          Rar! \\b, RAR self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/0x3000   MSCF \\b, InstallShield self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/32       Nullsoft \\b, Nullsoft Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .data\n>>>>>(&0x0f.l)          string          WEXTRACT \\b, MS CAB-Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .petite\\0 \\b, Petite compressed\n>>>>>(0x3c.l+0xf7)      byte            x\n>>>>>>(&0x104.l+(-4))   string          =!sfx! \\b, ACE self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .WISE \\b, WISE installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .dz\\0\\0\\0 \\b, Dzip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .reloc\n>>>>>(&0xe.l+(-4))      search/0x180    PK\\3\\4 \\b, ZIP self-extracting archive (WinZip)\n\n>>>>&(0x3c.l+0xf8)      search/0x100    _winzip_ \\b, ZIP self-extracting archive (WinZip)\n>>>>&(0x3c.l+0xf8)      search/0x100    SharedD \\b, Microsoft Installer self-extracting archive\n>>>>0x30                string          Inno \\b, InnoSetup self-extracting archive\n\n>>(0x3c.l) string !PE\\0\\0 MS-DOS executable\n\n>>(0x3c.l)              string          NE \\b, NE\n>>>(0x3c.l+0x36)        byte            0 (unknown OS)\n>>>(0x3c.l+0x36)        byte            1 for OS/2 1.x\n>>>(0x3c.l+0x36)        byte            2 for MS Windows 3.x\n>>>(0x3c.l+0x36)        byte            3 for MS-DOS\n>>>(0x3c.l+0x36)        byte            >3 (unknown OS)\n>>>(0x3c.l+0x36)        byte            0x81 for MS-DOS, Phar Lap DOS extender\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8002 (DLL)\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8001 (driver)\n>>>&(&0x24.s-1)         string          ARJSFX \\b, ARJ self-extracting archive\n>>>(0x3c.l+0x70)        search/0x80     WinZip(R)\\ Self-Extractor \\b, ZIP self-extracting archive (WinZip)\n\n>>(0x3c.l)              string          LX\\0\\0 \\b, LX\n>>>(0x3c.l+0x0a)        leshort         <1 (unknown OS)\n>>>(0x3c.l+0x0a)        leshort         1 for OS/2\n>>>(0x3c.l+0x0a)        leshort         2 for MS Windows\n>>>(0x3c.l+0x0a)        leshort         3 for DOS\n>>>(0x3c.l+0x0a)        leshort         >3 (unknown OS)\n>>>(0x3c.l+0x10)        lelong&0x28000  =0x8000 (DLL)\n>>>(0x3c.l+0x10)        lelong&0x20000  >0 (device driver)\n>>>(0x3c.l+0x10)        lelong&0x300    0x300 (GUI)\n>>>(0x3c.l+0x10)        lelong&0x28300  <0x300 (console)\n>>>(0x3c.l+0x08)        leshort         1 i80286\n>>>(0x3c.l+0x08)        leshort         2 i80386\n>>>(0x3c.l+0x08)        leshort         3 i80486\n>>>(8.s*16)             string          emx \\b, emx\n>>>>&1                  string          x %s\n>>>&(&0x54.l-3)         string          arjsfx \\b, ARJ self-extracting archive\n\n\n\n#------------------------------------------------------------------------------\n# bFLT: file(1) magic for BFLT uclinux binary files\n#\n# From Philippe De Muyter <phdm@macqel.be>\n# \n# Additional fields added by Craig Heffner\n#\n0       string          bFLT            BFLT executable \n>4      belong          x               version %ld, \n>4      belong          4\n>8\tbelong\t\tx\t\tcode offset: 0x%.8X, \n>12\tbelong\t\tx\t\tdata segment starts at: 0x%.8X, \n>16\tbelong\t\tx\t\tbss segment starts at: 0x%.8X, \n>20\tbelong\t\tx\t\tbss segment ends at: 0x%.8X, \n>24\tbelong\t\tx\t\tstack size: %d bytes, \n>28\tbelong \t\tx\t\trelocation records start at: 0x%.8X, \n>32\tbelong\t\tx\t\tnumber of reolcation records: %d, \n>>36    belong&0x1      0x1             ram\n>>36    belong&0x2      0x2             gotpic\n>>36    belong&0x4      0x4             gzip\n>>36    belong&0x8      0x8             gzdata\n\n\n#-----------------------------------------------------------------\n# MIPS COFF file formats\n#\n0       beshort 0x0160          MIPSEB ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x0162          MIPSEL-BE ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x6001          MIPSEB-LE ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x6201          MIPSEL ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n# MIPS 2 additions\n#\n0       beshort 0x0163          MIPSEB MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x0166          MIPSEL-BE MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x6301          MIPSEB-LE MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x6601          MIPSEL MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n# MIPS 3 additions\n#\n0       beshort 0x0140          MIPSEB MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x0142          MIPSEL-BE MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               ^H.%ld\n#\n0       beshort 0x4001          MIPSEB-LE MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x4201          MIPSEL MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               ^H.%ld\n#\n0       beshort 0x180           MIPSEB Ucode\n0       beshort 0x182           MIPSEL-BE Ucode\n\n\n# Windows CE package files\n0       string          MSCE\\0\\0\\0\\0    Microsoft WinCE installer\n>20     lelong          0               \\b, architecture-independent\n>20     lelong          103             \\b, Hitachi SH3\n>20     lelong          104             \\b, Hitachi SH4\n>20     lelong          0xA11           \\b, StrongARM\n>20     lelong          4000            \\b, MIPS R4000\n>20     lelong          10003           \\b, Hitachi SH3\n>20     lelong          10004           \\b, Hitachi SH3E\n>20     lelong          10005           \\b, Hitachi SH4\n>20     lelong          70001           \\b, ARM 7TDMI\n>52     leshort         1               \\b, 1 file\n>52     leshort         >1              \\b, %u files\n>56     leshort         1               \\b, 1 registry entry\n>56     leshort         >1              \\b, %u registry entries\n\n#------------------------------------------------------------------------------\n# Microsoft Xbox executables .xbe (Esa HyytiÃ¤ <ehyytia@cc.hut.fi>)\n0       string          XBEH            XBE, Microsoft Xbox executable\n# probabilistic checks whether signed or not\n>0x0004 ulelong =0x0\n>>&2    ulelong =0x0\n>>>&2   ulelong =0x0  \\b, not signed\n>0x0004 ulelong >0\n>>&2    ulelong >0\n>>>&2   ulelong >0    \\b, signed\n# expect base address of 0x10000\n>0x0104               ulelong =0x10000\n>>(0x0118-0x0FF60)    ulelong&0x80000007  0x80000007 \\b, all regions\n>>(0x0118-0x0FF60)    ulelong&0x80000007  !0x80000007\n>>>(0x0118-0x0FF60)   ulelong >0           (regions:\n>>>>(0x0118-0x0FF60)  ulelong &0x00000001  NA\n>>>>(0x0118-0x0FF60)  ulelong &0x00000002  Japan\n>>>>(0x0118-0x0FF60)  ulelong &0x00000004  Rest_of_World\n>>>>(0x0118-0x0FF60)  ulelong &0x80000000  Manufacturer\n>>>(0x0118-0x0FF60)   ulelong >0           \\b)\n\n#------------------------------------------------------------------------------\n# motorola:  file(1) magic for Motorola 68K and 88K binaries\n#\n# 68K\n#\n0       beshort         0x0208          mc68k COFF\n>18     beshort         ^00000020       object\n>18     beshort         &00000020       executable\n>12     belong          >0              not stripped\n>168    string          .lowmem         Apple toolbox\n>20     beshort         0407            (impure)\n>20     beshort         0410            (pure)\n>20     beshort         0413            (demand paged)\n>20     beshort         0421            (standalone)\n0       beshort         0x0209          mc68k executable (shared)\n>12     belong          >0              not stripped\n0       beshort         0x020A          mc68k executable (shared demand paged)\n>12     belong          >0              not stripped\n\n\n#\n# Motorola/UniSoft 68K Binary Compatibility Standard (BCS)\n#\n0       beshort         0x022A            68K BCS executable\n#\n# 88K\n#\n# Motorola/88Open BCS\n#\n0       beshort         0x022B            88K BCS executable\n\n#------------------------------------------------------------------------------\n# Sony Playstation executables (Adam Sjoegren <asjo@diku.dk>) :\n0       string  PS-X\\ EXE       Sony Playstation executable\n#  Area:\n>113    string  x               (%s)\n\n#------------------------------------------------------------------------------\n# cisco:  file(1) magic for cisco Systems routers\n#\n# Most cisco file-formats are covered by the generic elf code\n#\n# Microcode files are non-ELF, 0x8501 conflicts with NetBSD/alpha.\n0\tbeshort\t\t\t0x8501\t    cisco IOS\n>0      belong&0xffffff00       0x85011400  microcode\n>0      belong&0xffffff00       0x8501cb00  experimental microcode\n>7      string          \t>\\0         for '%s'\n\n\n\n#--------------------File Systems---------------------\n\n# Minix filesystems - Juan Cespedes <cespedes@debian.org>\n# Disabled for now until better signatures can be created. Too many false positives.\n#0x410   leshort         0x137f          Minix filesystem\n#>0x402  beshort         !0              \\b, %d zones\n#>0x1e   string          minix           \\b, bootable\n#0x410   leshort         0x138f          Minix filesystem, 30 char names\n#0x410   leshort         0x2468          Minix filesystem, version 2\n#0x410   leshort         0x2478          Minix filesystem, version 2, 30 char names\n\n#0x410   beshort         0x137f          Minix filesystem (big endian)\n#>0x402  beshort         !0              \\b, %d zones\n#>0x1e   string          minix           \\b, bootable\n#0x410   beshort         0x138f          Minix filesystem (big endian), 30 char names\n#0x410   beshort         0x2468          Minix filesystem (big endian), version 2\n#0x410   beshort         0x2478          Minix filesystem (big endian), version 2, 30 char names\n\n# YAFFS\n0\tbelong \t0x03000000\n>4\tbelong \t0x01000000\n>>8\tbeshort\t0xFFFF\t\tYAFFS filesystem\n\n# EFS2 file system - jojo@utulsa.edu\n8       string EFSSuper         EFS2 Qualcomm filesystem super block,\n>0      lelong 0x53000000\tlittle endian,\n>>4     leshort &1              NAND\n>>4     leshort ^1              NOR\n>>4     leshort x               version 0x%x,\n>>24    lelong  x               %d blocks,\n>>16    lelong  x               0x%x pages per block,\n>>20    lelong  x               0x%x bytes per page\n\n8\tstring SSFErepu\t\tEFS2 Qualcomm filesystem super block,\n>0      belong 0x53000000\tbig endian,\n>>4     beshort &1              NAND\n>>4     beshort ^1              NOR\n>>4     beshort x               version 0x%x,\n>>24    belong  x               %d blocks,\n>>16    belong  x               0x%x pages per block,\n>>20    belong  x               0x%x bytes per page\n\n# TROC file system\n0\tstring\tTROC\t\tTROC filesystem,\n>4\tlelong\tx\t\t%d file entries\n\n# PFS file system\n0\tstring\tPFS/\t\tPFS filesystem,\n>4\tstring\tx\t\tversion %s,\n>14\tleshort\tx\t\t%d files\n\n# MPFS file system\n0\tstring\tMPFS\t\tMPFS (Microchip) filesystem,\n>4\tbyte\tx\t\tversion %d.\n>5\tbyte\tx\t\t\\b%d,\n>6\tleshort\tx\t\t%d file entries\n\n# cramfs filesystem - russell@coker.com.au\n0       lelong  0x28cd3d45      CramFS filesystem, little endian\n>4\tlelong\t<0\t\tinvalid\n>4      lelong  x \t\tsize %lu\n>8      lelong  &1 \t\tversion #2\n>8      lelong  &2 \t\tsorted_dirs\n>8      lelong  &4 \t\thole_support\n>32     lelong  x \t\tCRC 0x%x,\n>36     lelong  x \t\tedition %lu,\n>40\tlelong\t<0\t\tinvalid\n>40     lelong  x \t\t%lu blocks,\n>44\tlelong\t<0\t\tinvalid\n>44     lelong  x \t\t%lu files\n\n0       belong  0x28cd3d45      CramFS filesystem, big endian\n>4\tbelong\t<0\t\tinvalid\n>4      belong  x \t\tsize %lu\n>8      belong  &1 \t\tversion #2\n>8      belong  &2 \t\tsorted_dirs\n>8      belong  &4 \t\thole_support\n>32     belong  x \t\tCRC 0x%x,\n>36     belong  x \t\tedition %lu,\n>40\tbelong\t<0\t\tinvalid\n>40     belong  x \t\t%lu blocks,\n>44\tbelong\t<0\t\tinvalid\n>44     belong  x \t\t%lu files\n\n\n\n# JFFS2 file system\n0       leshort 0x1984          JFFS2 filesystem (old) data little endian,\n>4\tlelong\t>1000000\tinvalid\n>4\tlelong\t<0\t\tinvalid\n>4\tlelong\t0\t\tinvalid\n>4\tlelong\tx\t\tJFFS node length: %d\n\n0       beshort 0x1984          JFFS2 filesystem (old) data big endian,\n>4      belong  >1000000        invalid\n>4      belong  <0              invalid\n>4\tbelong\t0\t\tinvalid\n>4      belong  x               JFFS node length: %d\n\n0       leshort 0x1985          JFFS2 filesystem data little endian,\n>4      lelong  >1000000        invalid\n>4      lelong  <0              invalid\n>4\tlelong\t0\t\tinvalid\n>4\tlelong\tx\t\tJFFS node length: %d\n\n0       beshort 0x1985          JFFS2 filesystem data big endian,\n>4      belong  >1000000        invalid\n>4      belong  <0              invalid\n>4\tbelong\t0\t\tinvalid\n>4      belong  x               JFFS node length: %d\n\n\n# Squashfs\n0       string  sqsh    Squashfs filesystem, big endian,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n\n0       string  hsqs    Squashfs filesystem, little endian,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28\tleshort >3\tcompression: \n>>20\tleshort 1\t\\bgzip,\n>>20\tleshort\t2\t\\blzma,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>28\tleshort >3\t\n>>40\tlequad\tx\tsize: %lld bytes,\n>4      lelong  x       %d inodes,\n>28\tleshort >3\n>>12\tlelong\t\tblocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28\tleshort 3\n>>51\tlelong \tx\tblocksize: %d bytes,\n>28\tleshort\t>3\t\n>>12\tlelong\tx\tblocksize: %d bytes,\n>28\tleshort <4\n>>39    ledate  x\tcreated: %s\n>28\tleshort >3\n>>8\tledate x\tcreated: %s\n\n# Squashfs with LZMA compression\n0       string  sqlz    Squashfs filesystem, big endian, lzma compression, \n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort >2\n>>63    bequad x        size: %lld bytes,\n#>>67   belong  x       %d bytes,\n>4      belong  x       %d inodes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort >1\n>>51    belong  x       blocksize: %d bytes,\n>39     bedate  x       created: %s\n\n# Squashfs 3.3 LZMA signature\n0       string  qshs    Squashfs filesystem, big endian, lzma signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort >2\n>>63    bequad x        size: %lld bytes,\n#>>67   belong  x       %d bytes,\n>4      belong  x       %d inodes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort >1\n>>51    belong  x       blocksize: %d bytes,\n>39     bedate  x       created: %s\n\n# Squashfs for DD-WRT\n0       string  tqsh    Squashfs filesystem, big endian, DD-WRT signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort >2\n>>63    bequad x        size: %lld bytes,\n#>>67   belong  x       %d bytes,\n>4      belong  x       %d inodes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort >1\n>>51    belong  x       blocksize: %d bytes,\n>39     bedate  x       created: %s\n\n# Squashfs for DD-WRT\n0       string  hsqt    Squashfs filesystem, little endian, DD-WRT signature,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>28     leshort >2\n>>63    lequad x        size: %lld bytes,\n#>>63   lelong  x       %d bytes,\n>4      lelong  x       %d inodes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort >1\n>>51    lelong  x       blocksize: %d bytes,\n>39     ledate  x       created: %s\n\n# Non-standard Squashfs signature found on some D-Link routers\n0       string  shsq    Squashfs filesystem, little endian, non-standard signature, \n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>28     leshort >2\n>>63    lequad x        size: %lld bytes,\n#>>63   lelong  x       %d bytes,\n>4      lelong  x       %d inodes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort >1\n>>51    lelong  x       blocksize: %d bytes,\n>39     ledate  x       created: %s\n\n# Commented out for now - unlikely to be found in firmware\n# CDROM Filesystems\n# Modified for UDF by gerardo.cacciari@gmail.com\n#32769   string    CD001     #\n#!:mime  application/x-iso9660-image\n#>38913  string   !NSR0      ISO 9660 CD-ROM filesystem data\n#>38913  string    NSR0      UDF filesystem data\n#>>38917 string    1         (version 1.0)\n#>>38917 string    2         (version 1.5)\n#>>38917 string    3         (version 2.0)\n#>>38917 byte     >0x33      (unknown version, ID 0x%X)\n#>>38917 byte     <0x31      (unknown version, ID 0x%X)\n# \"application id\" which appears to be used as a volume label\n#>32808  string    >\\0       '%s'\n#>34816  string    \\000CD001\\001EL\\ TORITO\\ SPECIFICATION    (bootable)\n#37633   string    CD001     ISO 9660 CD-ROM filesystem data (raw 2352 byte sectors)\n#!:mime  application/x-iso9660-image\n#32776   string    CDROM     High Sierra CD-ROM filesystem data\n\n# reiserfs - russell@coker.com.au\n0x10034         string  ReIsErFs        ReiserFS filesystem V3.5\n0x10034         string  ReIsEr2Fs       ReiserFS filesystem V3.6\n0x10034         string  ReIsEr3Fs       ReiserFS filesystem V3.6.19\n>0x1002c        leshort x               block size %d\n>0x10032        leshort &2              (mounted or unclean)\n>0x10000        lelong  x               num blocks %d\n>0x10040        lelong  1               tea hash\n>0x10040        lelong  2               yura hash\n>0x10040        lelong  3               r5 hash\n\n\n# ext2/ext3 filesystems - Andreas Dilger <adilger@dilger.ca>\n# ext4 filesystem - Eric Sandeen <sandeen@sandeen.net>\n# volume label and UUID Russell Coker\n# http://etbe.coker.com.au/2008/07/08/label-vs-uuid-vs-device/\n0x438   leshort         0xEF53          Linux EXT filesystem\n>0x44c  lelong\t\t<0\t\tinvalid\n>0x44c\tlelong\t\t>4\t\tinvalid\n>0x44c  lelong          x               rev %d\n>0x43e  leshort         x               \\b.%d\n# No journal?  ext2\n>0x45c  lelong          ^0x0000004      ext2 filesystem data\n>>0x43a leshort         ^0x0000001      (mounted or unclean)\n# Has a journal?  ext3 or ext4\n>0x45c  lelong          &0x0000004\n#  and small INCOMPAT?\n>>0x460 lelong          <0x0000040\n#   and small RO_COMPAT?\n>>>0x464 lelong         <0x0000008      ext3 filesystem data\n#   else large RO_COMPAT?\n>>>0x464 lelong         >0x0000007      ext4 filesystem data\n#  else large INCOMPAT?\n>>0x460 lelong          >0x000003f      ext4 filesystem data\n>0x468  belong          x               \\b, UUID=%08x\n>0x46c  beshort         x               \\b-%04x\n>0x46e  beshort         x               \\b-%04x\n>0x470  beshort         x               \\b-%04x\n>0x472  belong          x               \\b-%08x\n>0x476  beshort         x               \\b%04x\n>0x478  string          >0              \\b, volume name \"%s\"\n# General flags for any ext* fs\n>0x460  lelong          &0x0000004      (needs journal recovery)\n>0x43a  leshort         &0x0000002      (errors, invalid)\n# INCOMPAT flags\n>0x460  lelong          &0x0000001      (compressed)\n#>0x460 lelong          &0x0000002      (filetype)\n#>0x460 lelong          &0x0000010      (meta bg)\n>0x460  lelong          &0x0000040      (extents)\n>0x460  lelong          &0x0000080      (64bit)\n#>0x460 lelong          &0x0000100      (mmp)\n#>0x460 lelong          &0x0000200      (flex bg)\n# RO_INCOMPAT flags\n#>0x464 lelong          &0x0000001      (sparse super)\n>0x464  lelong          &0x0000002      (large files)\n>0x464  lelong          &0x0000008      (huge files)\n#>0x464 lelong          &0x0000010      (gdt checksum)\n\n\n#romfs filesystems - Juan Cespedes <cespedes@debian.org>\n0       string          -rom1fs-        romfs filesystem, version 1\n>8\tbelong\t>10000000\t\tinvalid\n>8      belong  x                       size: %d bytes,\n>16     string  x                       named %s.\n\n# JFFS - russell@coker.com.au           \n0       lelong  0x34383931      Linux Journalled Flash filesystem, little endian\n0       belong  0x34383931      Linux Journalled Flash filesystem, big endian\n\n# Wind River MemFS file system, found in some VxWorks devices\n0\tstring\towowowowowowowowowowowowowowow\t\tWind River management filesystem,\n>32\tbelong\t0\t\t\t\t\tuncompressed\n>32\tbelong\t1\t\t\t\t\tcompressed,\n>36\tbelong\tx\t\t\t\t\t%d files\n\n\n# FATX \n0\t\tstring\t\tFATX\t\tFATX filesystem data\n\n\n\n\n\n# updated by Joerg Jenderek at Sep 2007\n# only for sector sizes with 512 or more Bytes\n0x1FE\tleshort\t0xAA55\t\t\tstart boot sector\n# to do also for sectors < than 512 Bytes and some other files, GRR\n#30\tsearch/481\t\\x55\\xAA\tstart boot sector / filesystem\n# not for BeOS floppy 1440k, MBRs\n#(11.s-2) uleshort\t0xAA55\t\tstart boot sector / filesystem\n>2\tstring\tOSBS\t\t\t\\b, OS/BS MBR\n# J\\xf6rg Jenderek <joerg dot jenderek at web dot de>\n>0x8C\tstring\tInvalid\\ partition\\ table\t\\b, MS-DOS MBR\n# dr-dos with some upper-, lowercase variants\n>0x9D\tstring\tInvalid\\ partition\\ table$\t\n>>181\tstring\tNo\\ Operating\\ System$\t\t\n>>>201\tstring\tOperating\\ System\\ load\\ error$\t\\b, DR-DOS MBR, Version 7.01 to 7.03\n>0x9D\tstring\tInvalid\\ partition\\ table$\t\n>>181\tstring\tNo\\ operating\\ system$\t\t\n>>>201\tstring\tOperating\\ system\\ load\\ error$\t\\b, DR-DOS MBR, Version 7.01 to 7.03\n>342\tstring\tInvalid\\ partition\\ table$\t\n>>366\tstring\tNo\\ operating\\ system$\t\t\n>>>386\tstring\tOperating\\ system\\ load\\ error$\t\\b, DR-DOS MBR, version 7.01 to 7.03\n>295\tstring\tNEWLDR\\0\t\t\t\t\n>>302\tstring\tBad\\ PT\\ $\t\t\t\t\n>>>310\tstring\tNo\\ OS\\ $\t\t\t\t\n>>>>317\tstring\tOS\\ load\\ err$\t\t\t\t\n>>>>>329\tstring\tMoved\\ or\\ missing\\ IBMBIO.LDR\\n\\r\t\n>>>>>>358\tstring\tPress\\ any\\ key\\ to\\ continue.\\n\\r$\t\n>>>>>>>387\tstring\tCopyright\\ (c)\\ 1984,1998\t\n>>>>>>>>411\tstring\tCaldera\\ Inc.\\0\t\t\\b, DR-DOS MBR (IBMBIO.LDR)\n>0x10F\tstring\tUng\\201ltige\\ Partitionstabelle\t\\b, MS-DOS MBR, german version 4.10.1998, 4.10.2222\n>>0x1B8\tubelong\t>0\t\t\t\t\\b, Serial 0x%-.4x\n>0x8B\tstring\tUng\\201ltige\\ Partitionstabelle\t\\b, MS-DOS MBR, german version 5.00 to 4.00.950\n>271\tstring\tInvalid\\ partition\\ table\\0\t\t\n>>295\tstring\tError\\ loading\\ operating\\ system\\0\t\n>>>326\tstring\tMissing\\ operating\\ system\\0\t\t\\b, mbr\n#\n>139\tstring\tInvalid\\ partition\\ table\\0\t\t\n>>163\tstring\tError\\ loading\\ operating\\ system\\0\t\n>>>194\tstring\tMissing\\ operating\\ system\\0\t\t\\b, Microsoft Windows XP mbr\n# http://www.heise.de/ct/05/09/006/ page 184\n#HKEY_LOCAL_MACHINE\\SYSTEM\\MountedDevices\\DosDevices\\?:=Serial4Bytes+8Bytes\n>>>>0x1B8\tulelong\t>0\t\t\t\t\\b,Serial 0x%-.4x\n>300\tstring\tInvalid\\ partition\\ table\\0\t\n>>324\tstring\tError\\ loading\\ operating\\ system\\0\n>>>355\tstring\tMissing\\ operating\\ system\\0\t\t\\b, Microsoft Windows XP MBR\n#??>>>389\tstring\tInvalid\\ system\\ disk\t\t\n>>>>0x1B8\tulelong\t>0\t\t\t\t\\b, Serial 0x%-.4x\n>300\tstring\tUng\\201ltige\\ Partitionstabelle\n#split string to avoid error: String too long\n>>328\tstring\tFehler\\ beim\\ Laden\\ \t\n>>>346\tstring\tdes\\ Betriebssystems\t\n>>>>366\tstring\tBetriebssystem\\ nicht\\ vorhanden\t\\b, Microsoft Windows XP MBR (german)\n>>>>>0x1B8\tulelong\t>0\t\t\t\t\\b, Serial 0x%-.4x\n#>0x145\tstring\tDefault:\\ F\t\t\t\t\\b, FREE-DOS MBR\n#>0x14B\tstring\tDefault:\\ F\t\t\t\t\\b, FREE-DOS 1.0 MBR\n>0x145\tsearch/7\tDefault:\\ F\t\t\t\\b, FREE-DOS MBR\n#>>313\t\tstring\tF0\\ .\\ .\\ .\t\t\t\n#>>>322\t\tstring\tdisk\\ 1\t\t\t\t\n#>>>>382\tstring\tFAT3\t\t\t\t\n>64\tstring\tno\\ active\\ partition\\ found\t\n>>96\tstring\tread\\ error\\ while\\ reading\\ drive\t\\b, FREE-DOS Beta 0.9 MBR\n# Ranish Partition Manager http://www.ranish.com/part/\n>387\tsearch/4\t\\0\\ Error!\\r\t\t\t\n>>378\tsearch/7\tVirus! \t\t\t\t\n>>>397\tsearch/4\tBooting\\ \t\t\t\n>>>>408\tsearch/4\tHD1/\\0\t \t\t\t\\b, Ranish MBR (\n>>>>>416\tstring\tWriting\\ changes...\t\t\\b2.37\n>>>>>>438\tubyte\t\tx\t\t\t\\b,0x%x dots\n>>>>>>440\tubyte\t\t>0\t\t\t\\b,virus check\n>>>>>>441\tubyte\t\t>0\t\t\t\\b,partition %c\n#2.38,2.42,2.44\n>>>>>416\tstring\t!Writing\\ changes...\t\t\\b\n>>>>>>418\tubyte\t1\t\t\t\t\\bvirus check,\n>>>>>>419\tubyte\tx\t\t\t\t\\b0x%x seconds\n>>>>>>420\tubyte&0x0F\t>0\t\t\t\\b,partition\n>>>>>>>420\tubyte&0x0F\t<5\t\t\t\\b %x\n>>>>>>>420\tubyte&0x0F\t0Xf\t\t\t\\b ask\n>>>>>420\tubyte\t\tx\t\t\t\\b)\n#\n>271\tstring\tOperating\\ system\\ loading \t\t\n>>296\tstring\terror\\r\t\t\t\t\t\\b, SYSLINUX MBR (2.10)\n# http://www.acronis.de/\n>362\tstring\tMBR\\ Error\\ \\0\\r\t\t\t\n>>376\tstring\tress\\ any\\ key\\ to\\ \t\t\t\n>>>392\tstring\tboot\\ from\\ floppy...\\0\t\t\t\\b, Acronis MBR\n# added by Joerg Jenderek\n# http://www.visopsys.org/\n# http://partitionlogic.org.uk/\n>309\tstring\tNo\\ bootable\\ partition\\ found\\r\t\n>>339\tstring\tI/O\\ Error\\ reading\\ boot\\ sector\\r\t\\b, Visopsys MBR\n>349\tstring\tNo\\ bootable\\ partition\\ found\\r\t\n>>379\tstring\tI/O\\ Error\\ reading\\ boot\\ sector\\r\t\\b, simple Visopsys MBR\n# bootloader, bootmanager\n>0x40\tstring\tSBML\t\t\t\t\n# label with 11 characters of FAT 12 bit filesystem\n>>43\tstring\tSMART\\ BTMGR\t\t\t\n>>>430\tstring\tSBMK\\ Bad!\\r\t\t\t\\b, Smart Boot Manager\n# OEM-ID not always \"SBM\"\n#>>>>3\tstrings\tSBM\t\t\t\t\n>>>>6\tstring\t>\\0                             \\b, version %s\n>382\tstring\tXOSLLOADXCF\t\t\t\\b, eXtended Operating System Loader\n>6\tstring\tLILO\t\t\t\t\\b, LInux i386 boot LOader\n>>120\tstring\tLILO\t\t\t\t\\b, version 22.3.4 SuSe\n>>172\tstring\tLILO\t\t\t\t\\b, version 22.5.8 Debian\n# updated by Joerg Jenderek at Oct 2008\n# variables according to grub-0.97/stage1/stage1.S or\n# http://www.gnu.org/software/grub/manual/grub.html#Embedded-data\n# usual values are marked with comments to get only informations of strange GRUB loaders\n>342\t\tsearch/60\t\\0Geom\\0\t\n#>0\t\tulelong\t\tx\t\t%x=0x009048EB ,\t0x2a9048EB  0\n>>0x41\t\tubyte\t\t<2\t\t\n>>>0x3E\t\tubyte\t\t>2\t\t\\b; GRand Unified Bootloader\n# 0x3 for 0.5.95,0.93,0.94,0.96 0x4 for 1.90 \n>>>>0x3E\tubyte\t\tx\t\t\\b, stage1 version 0x%x\n#If it is 0xFF, use a drive passed by BIOS\n>>>>0x40\tubyte\t\t<0xFF\t\t\\b, boot drive 0x%x\n# in most case 0,1,0x2e for GRUB 0.5.95\n>>>>0x41\tubyte\t\t>0\t\t\\b, LBA flag 0x%x\n>>>>0x42\tuleshort\t<0x8000\t\t\\b, stage2 address 0x%x\n#>>>>0x42\tuleshort\t=0x8000\t\t\\b, stage2 address 0x%x (usual)\n>>>>0x42\tuleshort\t>0x8000\t\t\\b, stage2 address 0x%x\n#>>>>0x44\tulelong\t\t=1\t\t\\b, 1st sector stage2 0x%x (default)\n>>>>0x44\tulelong\t\t>1\t\t\\b, 1st sector stage2 0x%x\n>>>>0x48\tuleshort\t<0x800\t\t\\b, stage2 segment 0x%x\n#>>>>0x48\tuleshort\t=0x800\t\t\\b, stage2 segment 0x%x (usual)\n>>>>0x48\tuleshort\t>0x800\t\t\\b, stage2 segment 0x%x\n>>>>402\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>394\tstring\tstage1\t\t\t\\b, GRUB version 0.5.95\n>>>>382\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>376\tstring\tGRUB\\ \\0\t\t\\b, GRUB version 0.93 or 1.94\n>>>>383\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>377\tstring\tGRUB\\ \\0\t\t\\b, GRUB version 0.94\n>>>>385\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>379\tstring\tGRUB\\ \\0\t\t\\b, GRUB version 0.95 or 0.96\n>>>>391\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>>385\tstring\tGRUB\\ \\0\t\t\\b, GRUB version 0.97\n#unkown version\n>>>343\t\tstring\tGeom\\0Read\\0\\ Error\\0\t\n>>>>321\t\tstring\tLoading\\ stage1.5\t\\b, GRUB version x.y\n>>>380\t\tstring\tGeom\\0Hard\\ Disk\\0Read\\0\\ Error\\0\n>>>>374\t\tstring\tGRUB\\ \\0\t\t\\b, GRUB version n.m\n# http://syslinux.zytor.com/\n>478\tstring\tBoot\\ failed\\r\t\t\t\n>>495\tstring\tLDLINUX\\ SYS\t\t\t\\b, SYSLINUX bootloader (1.62)\n>480\tstring\tBoot\\ failed\\r\t\t\t\n>>495\tstring\tLDLINUX\\ SYS\t\t\t\\b, SYSLINUX bootloader (2.06 or 2.11)\n>484\tstring\tBoot\\ error\\r\t\t\t\\b, SYSLINUX bootloader (3.11)\n>395\tstring\tchksum\\0\\ ERROR!\\0\t\t\\b, Gujin bootloader\n# http://www.bcdwb.de/bcdw/index_e.htm\n>3\tstring\tBCDL\t\t\t\t\n>>498\tstring\tBCDL\\ \\ \\ \\ BIN\t\t\t\\b, Bootable CD Loader (1.50Z)\n# mbr partion table entries\n# OEM-ID does not contain MicroSoft,NEWLDR,DOS,SYSLINUX,or MTOOLs\n>3\t\t\tstring\t\t!MS\n>>3\t\t\tstring\t\t!SYSLINUX\n>>>3\t\t\tstring\t\t!MTOOL\n>>>>3\t\t\tstring\t\t!NEWLDR\n>>>>>5\t\t\tstring\t\t!DOS\n# not FAT (32 bit)\n>>>>>>82\t\tstring\t\t!FAT32\n#not Linux kernel\n>>>>>>>514\t\tstring\t\t!HdrS\n#not BeOS\n>>>>>>>>422\t\tstring\t\t!Be\\ Boot\\ Loader\n# active flag 0 or 0x80 and type > 0\n>>>>>>>>>446\t\tubyte\t\t<0x81\t\n>>>>>>>>>>446\t\tubyte&0x7F\t0\t\n>>>>>>>>>>>450\t\tubyte\t\t>0\t\\b; partition 1: ID=0x%x\n>>>>>>>>>>>>446\t\tubyte\t\t0x80\t\\b, active\n>>>>>>>>>>>>447\t\tubyte\t\tx\t\\b, starthead %u\n#>>>>>>>>>>>>448\t\tubyte\t\tx\t\\b, start C_S: 0x%x\n#>>>>>>>>>>>>448\t\tubeshort&1023\tx\t\\b, startcylinder? %d\n>>>>>>>>>>>>454\t\tulelong\t\tx\t\\b, startsector %u\n>>>>>>>>>>>>458\t\tulelong\t\tx\t\\b, %u sectors\n#\n>>>>>>>>>462\t\tubyte\t\t<0x81\t\n>>>>>>>>>>462\t\tubyte&0x7F\t0\t\t\n>>>>>>>>>>>466\t\tubyte\t\t>0\t\\b; partition 2: ID=0x%x\n>>>>>>>>>>>>462\t\tubyte\t\t0x80\t\\b, active\n>>>>>>>>>>>>463\t\tubyte\t\tx\t\\b, starthead %u\n#>>>>>>>>>>>>464\t\tubyte\t\tx\t\\b, start C_S: 0x%x\n#>>>>>>>>>>>>464\t\tubeshort&1023\tx\t\\b, startcylinder? %d\n>>>>>>>>>>>>470\t\tulelong\t\tx\t\\b, startsector %u\n>>>>>>>>>>>>474\t\tulelong\t\tx\t\\b, %u sectors\n#\n>>>>>>>>>478\t\tubyte\t\t<0x81\t\t\n>>>>>>>>>>478\t\tubyte&0x7F\t0\t\t\n>>>>>>>>>>>482\t\tubyte\t\t>0\t\\b; partition 3: ID=0x%x\n>>>>>>>>>>>>478\t\tubyte\t\t0x80\t\\b, active\n>>>>>>>>>>>>479\t\tubyte\t\tx\t\\b, starthead %u\n#>>>>>>>>>>>>480\t\tubyte\t\tx\t\\b, start C_S: 0x%x\n#>>>>>>>>>>>>481\t\tubyte\t\tx\t\\b, start C2S: 0x%x\n#>>>>>>>>>>>>480\t\tubeshort&1023\tx\t\\b, startcylinder? %d\n>>>>>>>>>>>>486\t\tulelong\t\tx\t\\b, startsector %u\n>>>>>>>>>>>>490\t\tulelong\t\tx\t\\b, %u sectors\n#\n>>>>>>>>>494\t\tubyte\t\t<0x81\t\n>>>>>>>>>>494\t\tubyte&0x7F\t0\t\t\n>>>>>>>>>>>498\t\tubyte\t\t>0\t\\b; partition 4: ID=0x%x\n>>>>>>>>>>>>494\t\tubyte\t\t0x80\t\\b, active\n>>>>>>>>>>>>495\t\tubyte\t\tx\t\\b, starthead %u\n#>>>>>>>>>>>>496\t\tubyte\t\tx\t\\b, start C_S: 0x%x\n#>>>>>>>>>>>>496\t\tubeshort&1023\tx\t\\b, startcylinder? %d\n>>>>>>>>>>>>502\t\tulelong\t\tx\t\\b, startsector %u\n>>>>>>>>>>>>506\t\tulelong\t\tx\t\\b, %u sectors\n# mbr partion table entries end\n# http://www.acronis.de/\n#FAT label=ACRONIS\\ SZ\n#OEM-ID=BOOTWIZ0\n>442\tstring\tNon-system\\ disk,\\ \t\n>>459\tstring\tpress\\ any\\ key...\\x7\\0\t\t\\b, Acronis Startup Recovery Loader\n# DOS names like F11.SYS are 8 right space padded bytes+3 bytes\n>>>477\t\tubyte&0xDF\t>0\t\t\n>>>>477\t\tstring\t\tx \t\t\\b %-.3s\n>>>>>480\tubyte&0xDF\t>0\t\t\n>>>>>>480\tstring\t\tx \t\t\\b%-.5s\n>>>>485\t\tubyte&0xDF\t>0\t\t\n>>>>>485\tstring\t\tx \t\t\\b.%-.3s\n#\n>185\tstring\tFDBOOT\\ Version\\ \t\t\t\n>>204\tstring\t\\rNo\\ Systemdisk.\\ \t\t\t\n>>>220\tstring\tBooting\\ from\\ harddisk.\\n\\r\t\t\n>>>245\tstring\tCannot\\ load\\ from\\ harddisk.\\n\\r\t\n>>>>273 string\tInsert\\ Systemdisk\\ \t\t\t\n>>>>>291 string and\\ press\\ any\\ key.\\n\\r\t\t\\b, FDBOOT harddisk Bootloader\n>>>>>>200 string\t>\\0                             \\b, version %-3s\n>242\tstring\tBootsector\\ from\\ C.H.\\ Hochst\\204\t\n>>278\tstring\tNo\\ Systemdisk.\\ \t\t\t\n>>>293\tstring\tBooting\\ from\\ harddisk.\\n\\r\t\t\n>>>441\tstring\tCannot\\ load\\ from\\ harddisk.\\n\\r\t\n>>>>469 string\tInsert\\ Systemdisk\\ \t\t\t\n>>>>>487 string and\\ press\\ any\\ key.\\n\\r\t\t\\b, WinImage harddisk Bootloader\n>>>>>>209 string\t>\\0                             \\b, version %-4.4s\n>(1.b+2)\tubyte\t\t0xe\t\t\t\n>>(1.b+3)\tubyte\t\t0x1f\t\t\t\n>>>(1.b+4)\tubyte\t\t0xbe\t\t\t\n>>>>(1.b+5)\tubyte\t\t0x77\t\t\t\n>>>>(1.b+6)\tubyte\t\t0x7c\t\t\t\n>>>>>(1.b+7)\tubyte\t\t0xac\t\t\t\n>>>>>>(1.b+8)\tubyte\t\t0x22\t\t\t\n>>>>>>>(1.b+9)\tubyte\t\t0xc0\t\t\t\n>>>>>>>>(1.b+10)\tubyte\t0x74\t\t\t\n>>>>>>>>>(1.b+11)\tubyte\t0xb\t\t\t\n>>>>>>>>>>(1.b+12)\tubyte\t0x56\t\t\t\n>>>>>>>>>>(1.b+13)\tubyte\t0xb4\t\t\t\\b, mkdosfs boot message display\n>214\tstring\tPlease\\ try\\ to\\ install\\ FreeDOS\\ \t\\b, DOS Emulator boot message display\n#>>244\tstring\tfrom\\ dosemu-freedos-*-bin.tgz\\r\t\n#>>>170\tstring\tSorry,\\ could\\ not\\ load\\ an\\ \t\t\n#>>>>195\tstring\toperating\\ system.\\r\\n\t\t\n#\n>103\tstring\tThis\\ is\\ not\\ a\\ bootable\\ disk.\\ \t\n>>132\tstring\tPlease\\ insert\\ a\\ bootable\\ \t\t\n>>>157\tstring\tfloppy\\ and\\r\\n\t\t\t\t\n>>>>169\tstring\tpress\\ any\\ key\\ to\\ try\\ again...\\r\t\\b, FREE-DOS message display\n#\n>66\tstring\tSolaris\\ Boot\\ Sector    \t\t\n>>99\tstring\tIncomplete\\ MDBoot\\ load.\t\t\n>>>89\tstring\tVersion \t\t\t\t\\b, Sun Solaris Bootloader\n>>>>97\tbyte\tx\t\t\t\t\tversion %c\n#\n>408\tstring\tOS/2\\ !!\\ SYS01475\\r\\0\t\t\t\n>>429\tstring\tOS/2\\ !!\\ SYS02025\\r\\0\t\t\t\n>>>450\tstring\tOS/2\\ !!\\ SYS02027\\r\\0\t\t\t\n>>>469\tstring\tOS2BOOT\\ \\ \\ \\ \t\t\t\t\\b, IBM OS/2 Warp bootloader\n#\n>409\tstring\tOS/2\\ !!\\ SYS01475\\r\\0\t\t\t\n>>430\tstring\tOS/2\\ !!\\ SYS02025\\r\\0\t\t\t\n>>>451\tstring\tOS/2\\ !!\\ SYS02027\\r\\0\t\t\t\n>>>470\tstring\tOS2BOOT\\ \\ \\ \\ \t\t\t\t\\b, IBM OS/2 Warp Bootloader\n>112\t\tstring\tThis\\ disk\\ is\\ not\\ bootable\\r\t\t\t\n>>142\t\tstring\tIf\\ you\\ wish\\ to\\ make\\ it\\ bootable\t\t\n>>>176\t\tstring\trun\\ the\\ DOS\\ program\\ SYS\\  \t\t\t\n>>>200\t\tstring\tafter\\ the\\r\t\t\t\t\t\n>>>>216\t\tstring\tsystem\\ has\\ been\\ loaded\\r\\n\t\t\t\n>>>>>242\tstring\tPlease\\ insert\\ a\\ DOS\\ diskette\\ \t\t\n>>>>>271\tstring\tinto\\r\\n\\ the\\ drive\\ and\\ \t\t\t\n>>>>>>292\tstring\tstrike\\ any\\ key...\\0\t\t\\b, IBM OS/2 Warp message display\n# XP\n>430\tstring\tNTLDR\\ is\\ missing\\xFF\\r\\n\t\t\n>>449\tstring\tDisk\\ error\\xFF\\r\\n\t\t\t\n>>>462\tstring\tPress\\ any\\ key\\ to\\ restart\\r\t\t\\b, Microsoft Windows XP Bootloader\n# DOS names like NTLDR,CMLDR,$LDR$ are 8 right space padded bytes+3 bytes\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n#\n>>>>371\t\tubyte\t\t>0x20\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>376\tubyte&0xDF\t>0\t\t\t\n>>>>>>>376\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>430\tstring\tNTLDR\\ nicht\\ gefunden\\xFF\\r\\n\t\t\n>>453\tstring\tDatentr\\204gerfehler\\xFF\\r\\n\t\t\n>>>473\tstring\tNeustart\\ mit\\ beliebiger\\ Taste\\r\t\\b, Microsoft Windows XP Bootloader (german)\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n# offset variant\n>>>>379\tstring\t\\0\t\t\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n#\n>430\tstring\tNTLDR\\ fehlt\\xFF\\r\\n\t\t\t\n>>444\tstring\tDatentr\\204gerfehler\\xFF\\r\\n\t\t\n>>>464\tstring\tNeustart\\ mit\\ beliebiger\\ Taste\\r\t\\b, Microsoft Windows XP Bootloader (2.german)\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n# variant\n>>>>371\t\tubyte\t\t>0x20\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>376\tubyte&0xDF\t>0\t\t\t\n>>>>>>>376\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>430\tstring\tNTLDR\\ fehlt\\xFF\\r\\n\t\t\t\n>>444\tstring\tMedienfehler\\xFF\\r\\n\t\t\t\n>>>459\tstring\tNeustart:\\ Taste\\ dr\\201cken\\r\t\t\\b, Microsoft Windows XP Bootloader (3.german)\n>>>>371\t\tubyte\t\t>0x20\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>376\tubyte&0xDF\t>0\t\t\t\n>>>>>>>376\tstring\t\tx \t\t\t\\b.%-.3s\n# variant\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n#\n>430\tstring\tDatentr\\204ger\\ entfernen\\xFF\\r\\n\t\n>>454\tstring\tMedienfehler\\xFF\\r\\n\t\t\t\n>>>469\tstring\tNeustart:\\ Taste\\ dr\\201cken\\r\t\t\\b, Microsoft Windows XP Bootloader (4.german)\n>>>>379\t\tstring\t\t\\0\t\t\t\n>>>>>368\tubyte&0xDF\t>0\t\t\t\n>>>>>>368\tstring\t\tx \t\t\t%-.5s\n>>>>>>>373\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>373\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>376\tubyte&0xDF\t>0\t\t\t\n>>>>>>>376\tstring\t\tx \t\t\t\\b.%-.3s\n# variant\n>>>>417\t\tubyte&0xDF\t>0\t\t\t\n>>>>>417\tstring\t\tx\t\t\t%-.5s\n>>>>>>422\tubyte&0xDF\t>0\t\t\t\n>>>>>>>422\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>425\tubyte&0xDF\t>0\t\t\t\n>>>>>>425\tstring\t\t>\\ \t\t\t\\b.%-.3s\n#\n\n#>3\tstring\tNTFS\\ \\ \\ \\ \t\t\t\t\n>389\tstring\tFehler\\ beim\\ Lesen\\ \n>>407\tstring\tdes\\ Datentr\\204gers\n>>>426\tstring\tNTLDR\\ fehlt\t\t\t\t\n>>>>440\tstring\tNTLDR\\ ist\\ komprimiert\n>>>>>464 string\tNeustart\\ mit\\ Strg+Alt+Entf\\r\t\t\\b, Microsoft Windows XP Bootloader NTFS (german)\n#>3\tstring\tNTFS\\ \\ \\ \\ \t\t\t\t\n>313\tstring\tA\\ disk\\ read\\ error\\ occurred.\\r\n>>345\tstring\tA\\ kernel\\ file\\ is\\ missing\\ \t\n>>>370\tstring\tfrom\\ the\\ disk.\\r\t\t\n>>>>484\tstring\tNTLDR\\ is\\ compressed\t\t\n>>>>>429 string\tInsert\\ a\\ system\\ diskette\\ \t\n>>>>>>454 string and\\ restart\\r\\nthe\\ system.\\r\t\t\\b, Microsoft Windows XP Bootloader NTFS\n# DOS loader variants different languages,offsets\n>472\tubyte&0xDF\t>0\n>>389\tstring\tInvalid\\ system\\ disk\\xFF\\r\\n\t\t\n>>>411\tstring\tDisk\\ I/O\\ error\t\t\t\n>>>>428\tstring\tReplace\\ the\\ disk,\\ and\\ \t\t\n>>>>>455 string\tpress\\ any\\ key\t\t\t\t\\b, Microsoft Windows 98 Bootloader\n#IO.SYS\n>>>>>>472\tubyte&0xDF\t>0\t\t\t\n>>>>>>>472\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>>>474\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>474\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>>479\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>479 string\t\tx \t\t\t\\b%-.1s\n>>>>>>>480\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>480\tstring\t\tx \t\t\t\\b.%-.3s\n#MSDOS.SYS\n>>>>>>>483\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>>483\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>488\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>488\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>>>491\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>491\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>>390\tstring\tInvalid\\ system\\ disk\\xFF\\r\\n\t\t\n>>>412\tstring\tDisk\\ I/O\\ error\\xFF\\r\\n\t\t\n>>>>429\tstring\tReplace\\ the\\ disk,\\ and\\ \t\t\n>>>>>451 string\tthen\\ press\\ any\\ key\\r\t\t\t\\b, Microsoft Windows 98 Bootloader\n>>388\tstring\tUngueltiges\\ System\\ \\xFF\\r\\n\t\t\n>>>410\tstring\tE/A-Fehler\\ \\ \\ \\ \\xFF\\r\\n\t\t\n>>>>427\tstring\tDatentraeger\\ wechseln\\ und\\ \t\t\n>>>>>453 string\tTaste\\ druecken\\r\t\t\t\\b, Microsoft Windows 95/98/ME Bootloader (german)\n#WINBOOT.SYS only not spaces (0xDF)\n>>>>>>497\tubyte&0xDF\t>0\t\t\t\n>>>>>>>497\tstring\t\tx \t\t\t%-.5s\n>>>>>>>>502\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>502\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>>>504 string\t\tx \t\t\t\\b%-.1s\n>>>>>>505\tubyte&0xDF\t>0\t\t\t\n>>>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n#IO.SYS\n>>>>>>472\tubyte&0xDF\t>0\t\t\tor\n>>>>>>>472\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>>>474\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>474\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>>479\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>479 string\t\tx \t\t\t\\b%-.1s\n>>>>>>>480\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>480\tstring\t\tx \t\t\t\\b.%-.3s\n#MSDOS.SYS\n>>>>>>>483\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>>483\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>488\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>488\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>>>491\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>491\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>>390\tstring\tUngueltiges\\ System\\ \\xFF\\r\\n\t\t\n>>>412\tstring\tE/A-Fehler\\ \\ \\ \\ \\xFF\\r\\n\t\t\n>>>>429\tstring\tDatentraeger\\ wechseln\\ und\\ \t\t\n>>>>>455 string\tTaste\\ druecken\\r\t\t\t\\b, Microsoft Windows 95/98/ME Bootloader (German)\n#WINBOOT.SYS only not spaces (0xDF)\n>>>>>>497\tubyte&0xDF\t>0\t\t\t\n>>>>>>>497\tstring\t\tx \t\t\t%-.7s\n>>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>505\tubyte&0xDF\t>0\t\t\t\n>>>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n#IO.SYS\n>>>>>>472\tubyte&0xDF\t>0\t\t\tor\n>>>>>>>472\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>>>474\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>474\tstring\t\tx \t\t\t\\b%-.6s\n>>>>>>>480\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>480\tstring\t\tx \t\t\t\\b.%-.3s\n#MSDOS.SYS\n>>>>>>>483\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>>483\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>>488\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>488\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>>>491\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>491\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>>389\tstring\tUngueltiges\\ System\\ \\xFF\\r\\n\t\t\n>>>411\tstring\tE/A-Fehler\\ \\ \\ \\ \\xFF\\r\\n\t\t\n>>>>428\tstring\tDatentraeger\\ wechseln\\ und\\ \t\t\n>>>>>454 string\tTaste\\ druecken\\r\t\t\t\\b, Microsoft Windows 95/98/ME Bootloader (GERMAN)\n# DOS names like IO.SYS,WINBOOT.SYS,MSDOS.SYS,WINBOOT.INI are 8 right space padded bytes+3 bytes\n>>>>>>472\tstring\t\tx \t\t\t%-.2s\n>>>>>>>474\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>474\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>479\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>479\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>480\tubyte&0xDF\t>0\t\t\t\n>>>>>>>480\tstring\t\tx \t\t\t\\b.%-.3s\n>>>>>>483\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>483\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>488\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>488\tstring\t\tx \t\t\t\\b%-.2s\n>>>>>>>>490\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>490\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>491\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>491\tstring\t\tx \t\t\t\\b.%-.3s\n>479\tubyte&0xDF\t>0\n>>416\tstring\tKein\\ System\\ oder\\ \t\t\t\n>>>433\tstring\tLaufwerksfehler\t\t\t\t\n>>>>450\tstring\tWechseln\\ und\\ Taste\\ dr\\201cken\t\\b, Microsoft DOS Bootloader (german)\n#IO.SYS\n>>>>>479\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>481\tubyte&0xDF\t>0\t\t\t\n>>>>>>>481\tstring\t\tx \t\t\t\\b%-.6s\n>>>>>487\tubyte&0xDF\t>0\t\t\t\n>>>>>>487\tstring\t\tx \t\t\t\\b.%-.3s\n#MSDOS.SYS\n>>>>>>490\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>490\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>495\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>495\tstring\t\tx \t\t\t\\b%-.3s\n>>>>>>>498\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>498\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>376\tsearch/41\tNon-System\\ disk\\ or\\ \t\t\n>>395\tsearch/41\tdisk\\ error\\r\t\t\t\n>>>407\tsearch/41\tReplace\\ and\\ \t\t\t\n>>>>419\tsearch/41\tpress\\ \t\t\t\t\\b,\n>>>>419\tsearch/41\tstrike\\ \t\t\t\\b, old\n>>>>426\tsearch/41\tany\\ key\\ when\\ ready\\r\t\tMS or PC-DOS bootloader\n#449\t\t\tDisk\\ Boot\\ failure\\r\t\tMS 3.21\n#466\t\t\tBoot\\ Failure\\r\t\t\tMS 3.30\n>>>>>468 search/18\t\\0\t\t\t\t\n#IO.SYS,IBMBIO.COM\n>>>>>>&0\tstring\t\tx \t\t\t\\b %-.2s\n>>>>>>>&-20\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.4s\n>>>>>>>>>&-16\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.2s\n>>>>>>&8\tubyte&0xDF\t>0\t\t\t\\b.\n>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.3s\n#MSDOS.SYS,IBMDOS.COM\n>>>>>>&11\tubyte&0xDF\t>0\t\t\t\\b+\n>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.5s\n>>>>>>>>&-6\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>>>>&-5\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.2s\n>>>>>>>&7\tubyte&0xDF\t>0\t\t\t\\b.\n>>>>>>>>&-1\tstring\t\tx \t\t\t\\b%-.3s\n>441\tstring\tCannot\\ load\\ from\\ harddisk.\\n\\r\n>>469\tstring\tInsert\\ Systemdisk\\ \t\t\t\n>>>487\tstring\tand\\ press\\ any\\ key.\\n\\r\t\t\\b, MS (2.11) DOS bootloader\n#>43\tstring\t\\224R-LOADER\\ \\ SYS\t\t\t=label\t\t\t\t\t\n>54\tstring\tSYS\n>>324\tstring\tVASKK\n>>>495\tstring\tNEWLDR\\0\t\t\t\t\\b, DR-DOS Bootloader (LOADER.SYS)\n#\n>98\tstring\tPress\\ a\\ key\\ to\\ retry\\0\\r\t\t\n>>120\tstring\tCannot\\ find\\ file\\ \\0\\r\t\t\n>>>139\tstring\tDisk\\ read\\ error\\0\\r\t\t\t\n>>>>156\tstring\tLoading\\ ...\\0\t\t\t\t\\b, DR-DOS (3.41) Bootloader\n#DRBIOS.SYS\n>>>>>44\t\tubyte&0xDF\t>0\t\t\t\n>>>>>>44\tstring\t\tx\t\t\t\\b %-.6s\n>>>>>>>50\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>50\tstring\t\tx \t\t\t\\b%-.2s\n>>>>>>52\tubyte&0xDF\t>0\t\t\t\n>>>>>>>52\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>70\tstring\tIBMBIO\\ \\ COM\t\t\t\t\n>>472\tstring\tCannot\\ load\\ DOS!\\ \t\t\t\n>>>489\tstring\tAny\\ key\\ to\\ retry\t\t\t\\b, DR-DOS Bootloader\n>>471\tstring\tCannot\\ load\\ DOS\\ \t\t\t\n>>487\tstring\tpress\\ key\\ to\\ retry\t\t\t\\b, Open-DOS Bootloader\n#??\n>444\tstring\tKERNEL\\ \\ SYS\t\t\t\t\t\n>>314\tstring\tBOOT\\ error!\t\t\t\t\\b, FREE-DOS Bootloader\n>499\tstring\tKERNEL\\ \\ SYS\t\t\t\t\n>>305\tstring\tBOOT\\ err!\\0\t\t\t\t\\b, Free-DOS Bootloader\n>449\tstring\tKERNEL\\ \\ SYS\t\t\t\t\n>>319\tstring\tBOOT\\ error!\t\t\t\t\\b, FREE-DOS 0.5 Bootloader\n#\n>449\tstring\tLoading\\ FreeDOS\t\t\t\n>>0x1AF\t\tulelong\t\t>0\t\t\t\\b, FREE-DOS 0.95,1.0 Bootloader\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n#\n>331\tstring\tError!.0\t\t\t\t\\b, FREE-DOS 1.0 bootloader\n#\n>125\tstring\tLoading\\ FreeDOS...\\r\t\t\t\n>>311\tstring\tBOOT\\ error!\\r\t\t\t\t\\b, FREE-DOS bootloader\n>>>441\t\tubyte&0xDF\t>0\t\t\t\n>>>>441\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>447\tubyte&0xDF\t>0\t\t\t\n>>>>>>447\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>448\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>448\tstring\t\tx \t\t\t\\b%-.1s\n>>>>449\t\tubyte&0xDF\t>0\t\t\t\n>>>>>449\tstring\t\tx \t\t\t\\b.%-.3s\n>124\tstring\tFreeDOS\\0\t\t\t\t\n>>331\tstring\t\\ err\\0\t\t\t\t\t\\b, FREE-DOS BETa 0.9 Bootloader\n# DOS names like KERNEL.SYS,KERNEL16.SYS,KERNEL32.SYS,METAKERN.SYS are 8 right space padded bytes+3 bytes\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n>>333\tstring\t\\ err\\0\t\t\t\t\t\\b, FREE-DOS BEta 0.9 Bootloader\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n>>334\tstring\t\\ err\\0\t\t\t\t\t\\b, FREE-DOS Beta 0.9 Bootloader\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n>336\tstring\tError!\\ \t\t\t\t\n>>343\tstring\tHit\\ a\\ key\\ to\\ reboot.\t\t\\b, FREE-DOS Beta 0.9sr1 Bootloader\n>>>497\t\tubyte&0xDF\t>0\t\t\t\n>>>>497\t\tstring\t\tx \t\t\t\\b %-.6s\n>>>>>503\tubyte&0xDF\t>0\t\t\t\n>>>>>>503\tstring\t\tx \t\t\t\\b%-.1s\n>>>>>>>504\tubyte&0xDF\t>0\t\t\t\n>>>>>>>>504\tstring\t\tx \t\t\t\\b%-.1s\n>>>>505\t\tubyte&0xDF\t>0\t\t\t\n>>>>>505\tstring\t\tx \t\t\t\\b.%-.3s\n# added by Joerg Jenderek\n# http://www.visopsys.org/\n# http://partitionlogic.org.uk/\n# OEM-ID=Visopsys\n>478\t\tulelong\t0\t\t\t\t\t\n>>(1.b+326)\tstring\tI/O\\ Error\\ reading\\ \t\t\t\n>>>(1.b+344)\tstring\tVisopsys\\ loader\\r\t\t\t\n>>>>(1.b+361)\tstring\tPress\\ any\\ key\\ to\\ continue.\\r\t\\b, Visopsys loader\n# http://alexfru.chat.ru/epm.html#bootprog\n>494\tubyte\t>0x4D\t\t\t\t\t\n>>495\tstring\t>E\t\t\t\t\t\n>>>495\tstring\t<S\t\t\t\t\t\n#OEM-ID is not reliable\n>>>>3\tstring\tBootProg\t\t\t\t\n# It just looks for a program file name at the root directory\n# and loads corresponding file with following execution.\n# DOS names like STARTUP.BIN,STARTUPC.COM,STARTUPE.EXE are 8 right space padded bytes+3 bytes\n>>>>499\t\t\tubyte&0xDF\t>0\t\t\\b, COM/EXE Bootloader\n>>>>>499\t\tstring\t\tx \t\t\\b %-.1s\n>>>>>>500\t\tubyte&0xDF\t>0\t\t\n>>>>>>>500\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>501\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>501\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>502\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>502\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>503\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>503\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>504\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>504\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>>>505\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>>>505\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>>>>>506\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>>>>>506\tstring\t\tx \t\t\\b%-.1s\n#name extension\n>>>>>507\t\tubyte&0xDF\t>0\t\t\\b.\n>>>>>>507\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>508\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>508\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>509\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>509\t\tstring\t\tx \t\t\\b%-.1s\n#If the boot sector fails to read any other sector,\n#it prints a very short message (\"RE\") to the screen and hangs the computer.\n#If the boot sector fails to find needed program in the root directory,\n#it also hangs with another message (\"NF\").\n>>>>>492\t\tstring\t\tRENF\t\t\\b, FAT (12 bit)\n>>>>>495\t\tstring\t\tRENF\t\t\\b, FAT (16 bit)\n# http://alexfru.chat.ru/epm.html#bootprog\n>494\tubyte\t>0x4D\t\t\t\t\t\n>>495\tstring\t>E\t\t\t\t\t\n>>>495\tstring\t<S\t\t\t\t\t\n#OEM-ID is not reliable\n>>>>3\tstring\tBootProg\t\t\t\t\n# It just looks for a program file name at the root directory\n# and loads corresponding file with following execution.\n# DOS names like STARTUP.BIN,STARTUPC.COM,STARTUPE.EXE are 8 right space padded bytes+3 bytes\n>>>>499\t\t\tubyte&0xDF\t>0\t\t\\b, COM/EXE Bootloader\n>>>>>499\t\tstring\t\tx \t\t\\b %-.1s\n>>>>>>500\t\tubyte&0xDF\t>0\t\t\n>>>>>>>500\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>501\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>501\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>502\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>502\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>503\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>503\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>504\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>504\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>>>505\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>>>505\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>>>>>>>>>>506\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>>>>>>>>>>506\tstring\t\tx \t\t\\b%-.1s\n#name extension\n>>>>>507\t\tubyte&0xDF\t>0\t\t\\b.\n>>>>>>507\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>508\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>508\t\tstring\t\tx \t\t\\b%-.1s\n>>>>>>>>>509\t\tubyte&0xDF\t>0\t\t\n>>>>>>>>>>509\t\tstring\t\tx \t\t\\b%-.1s\n#If the boot sector fails to read any other sector,\n#it prints a very short message (\"RE\") to the screen and hangs the computer.\n#If the boot sector fails to find needed program in the root directory,\n#it also hangs with another message (\"NF\").\n>>>>>492\t\tstring\t\tRENF\t\t\\b, FAT (12 bit)\n>>>>>495\t\tstring\t\tRENF\t\t\\b, FAT (16 bit)\n# x86 bootloader end\n# updated by Joerg Jenderek at Sep 2007\n>3\tubyte\t0\t\t\t\n#no active flag\n>>446\tubyte\t0\t\t\t\n# partition 1 not empty\n>>>450\tubyte\t>0\t\t\t\n# partitions 3,4 empty\n>>>>482\t\tubyte\t0\t\t\t\n>>>>>498\tubyte\t0\t\t\t\n# partition 2 ID=0,5,15\n>>>>>>466\tubyte\t<0x10\t\t\t\n>>>>>>>466\tubyte\t0x05\t\t\t\\b, extended partition table\n>>>>>>>466\tubyte\t0x0F\t\t\t\\b, extended partition table (LBA)\n>>>>>>>466\tubyte\t0x0\t\t\t\\b, extended partition table (last)\t\n# JuMP short     bootcodeoffset NOP assembler instructions will usually be EB xx 90\n# http://mirror.href.com/thestarman/asm/2bytejumps.htmm#FWD\n# older drives may use Near JuMP instruction E9 xx xx\n>0\t\tlelong&0x009000EB\t0x009000EB \n>0\t\tlelong&0x000000E9\t0x000000E9 \n# minimal short forward jump found 03cx??\n# maximal short forward jump is 07fx\n>1\t\tubyte\t\t\t<0xff\t\\b, code offset 0x%x\n# mtools-3.9.8/msdos.h\n# usual values are marked with comments to get only informations of strange FAT systems\n# valid sectorsize must be a power of 2 from 32 to 32768\n>>11\t\tuleshort&0x000f\tx\t\t\n>>>11\t\tuleshort\t<32769\t\t\n>>>>11\t\tuleshort\t>31\t\t\n>>>>>21\t\tubyte&0xf0\t0xF0\t\t\n>>>>>>3\t\tstring\t\t>\\0\t\t\\b, OEM-ID \"%8.8s\"\n#http://mirror.href.com/thestarman/asm/debug/debug2.htm#IHC\n>>>>>>>8\tstring\t\tIHC\t\t\\b cached by Windows 9M\n>>>>>>11\tuleshort\t>512\t\t\\b, Bytes/sector %u\n#>>>>>>11\tuleshort\t=512\t\t\\b, Bytes/sector %u=512 (usual)\n>>>>>>11\tuleshort\t<512\t\t\\b, Bytes/sector %u\n>>>>>>13\tubyte\t\t>1\t\t\\b, sectors/cluster %u\n#>>>>>>13\tubyte\t\t=1\t\t\\b, sectors/cluster %u (usual on Floppies)\n>>>>>>14\tuleshort\t>32\t\t\\b, reserved sectors %u\n#>>>>>>14\tuleshort\t=32\t\t\\b, reserved sectors %u (usual Fat32)\n#>>>>>>14\tuleshort\t>1\t\t\\b, reserved sectors %u\n#>>>>>>14\tuleshort\t=1\t\t\\b, reserved sectors %u (usual FAT12,FAT16)\n>>>>>>14\tuleshort\t<1\t\t\\b, reserved sectors %u\n>>>>>>16\tubyte\t\t>2\t\t\\b, FATs %u\n#>>>>>>16\tubyte\t\t=2\t\t\\b, FATs %u (usual)\n>>>>>>16\tubyte\t\t=1\t\t\\b, FAT  %u\n>>>>>>16\tubyte\t\t>0\n>>>>>>17\tuleshort\t>0\t\t\\b, root entries %u\n#>>>>>>17\tuleshort\t=0\t\t\\b, root entries %u=0 (usual Fat32)\n>>>>>>19\tuleshort\t>0\t\t\\b, sectors %u (volumes <=32 MB) \n#>>>>>>19\tuleshort\t=0\t\t\\b, sectors %u=0 (usual Fat32)\n>>>>>>21\tubyte\t\t>0xF0\t\t\\b, Media descriptor 0x%x\n#>>>>>>21\tubyte\t\t=0xF0\t\t\\b, Media descriptor 0x%x (usual floppy)\n>>>>>>21\tubyte\t\t<0xF0\t\t\\b, Media descriptor 0x%x\n>>>>>>22\tuleshort\t>0\t\t\\b, sectors/FAT %u\n#>>>>>>22\tuleshort\t=0\t\t\\b, sectors/FAT %u=0 (usual Fat32)\n>>>>>>26\tubyte\t\t>2\t\t\\b, heads %u\n#>>>>>>26\tubyte\t\t=2\t\t\\b, heads %u (usual floppy)\n>>>>>>26\tubyte\t\t=1\t\t\\b, heads %u\n#skip for Digital Research DOS (version 3.41) 1440 kB Bootdisk\n>>>>>>38\tubyte\t\t!0x70\t\t\n>>>>>>>28\tulelong\t\t>0\t\t\\b, hidden sectors %u\n#>>>>>>>28\tulelong\t\t=0\t\t\\b, hidden sectors %u (usual floppy)\n>>>>>>>32\tulelong\t\t>0\t\t\\b, sectors %u (volumes > 32 MB) \n#>>>>>>>32\tulelong\t\t=0\t\t\\b, sectors %u (volumes > 32 MB)\n# FAT<32 specific \n>>>>>>82\tstring\t\t!FAT32\n#>>>>>>>36\tubyte\t\t0x80\t\t\\b, physical drive 0x%x=0x80 (usual harddisk)\n#>>>>>>>36\tubyte\t\t0\t\t\\b, physical drive 0x%x=0 (usual floppy)\n>>>>>>>36\tubyte\t\t!0x80\t\t\n>>>>>>>>36\tubyte\t\t!0\t\t\\b, physical drive 0x%x\n>>>>>>>37\tubyte\t\t>0\t\t\\b, reserved 0x%x\n#>>>>>>>37\tubyte\t\t=0\t\t\\b, reserved 0x%x\n>>>>>>>38\tubyte\t\t>0x29\t\t\\b, dos < 4.0 BootSector (0x%x)\n>>>>>>>38\tubyte\t\t<0x29\t\t\\b, dos < 4.0 BootSector (0x%x)\n>>>>>>>38\tubyte\t\t=0x29\n>>>>>>>>39\tulelong\t\tx\t\t\\b, serial number 0x%x\n>>>>>>>>43\tstring\t\t<NO\\ NAME\t\\b, label: \"%11.11s\"\n>>>>>>>>43\tstring\t\t>NO\\ NAME\t\\b, label: \"%11.11s\"\n>>>>>>>>43\tstring\t\t=NO\\ NAME\t\\b, unlabeled\n>>>>>>>54\tstring\t\tFAT\t\t\\b, FAT\n>>>>>>>>54\tstring\t\tFAT12\t\t\\b (12 bit)\n>>>>>>>>54\tstring\t\tFAT16\t\t\\b (16 bit)\n# FAT32 specific\n>>>>>>82\tstring\t\tFAT32\t\t\\b, FAT (32 bit)\n>>>>>>>36\tulelong\t\tx\t\t\\b, sectors/FAT %u\n>>>>>>>40\tuleshort\t>0\t\t\\b, extension flags %u\n#>>>>>>>40\tuleshort\t=0\t\t\\b, extension flags %u\n>>>>>>>42\tuleshort\t>0\t\t\\b, fsVersion %u\n#>>>>>>>42\tuleshort\t=0\t\t\\b, fsVersion %u (usual)\n>>>>>>>44\tulelong\t\t>2\t\t\\b, rootdir cluster %u\n#>>>>>>>44\tulelong\t\t=2\t\t\\b, rootdir cluster %u\n#>>>>>>>44\tulelong\t\t=1\t\t\\b, rootdir cluster %u\n>>>>>>>48\tuleshort\t>1\t\t\\b, infoSector %u\n#>>>>>>>48\tuleshort\t=1\t\t\\b, infoSector %u (usual)\n>>>>>>>48\tuleshort\t<1\t\t\\b, infoSector %u\n>>>>>>>50\tuleshort\t>6\t\t\\b, Backup boot sector %u\n#>>>>>>>50\tuleshort\t=6\t\t\\b, Backup boot sector %u (usual) \n>>>>>>>50\tuleshort\t<6\t\t\\b, Backup boot sector %u\n>>>>>>>54\tulelong\t\t>0\t\t\\b, reserved1 0x%x\n>>>>>>>58\tulelong\t\t>0\t\t\\b, reserved2 0x%x\n>>>>>>>62\tulelong\t\t>0\t\t\\b, reserved3 0x%x\n# same structure as FAT1X \n>>>>>>>64\tubyte\t\t>0x80\t\t\\b, physical drive 0x%x\n#>>>>>>>64\tubyte\t\t=0x80\t\t\\b, physical drive 0x%x=80 (usual harddisk)\n>>>>>>>64\tubyte&0x7F\t>0\t\t\\b, physical drive 0x%x\n#>>>>>>>64\tubyte\t\t=0\t\t\\b, physical drive 0x%x=0 (usual floppy)\n>>>>>>>65\tubyte\t\t>0\t\t\\b, reserved 0x%x\n>>>>>>>66\tubyte\t\t>0x29\t\t\\b, dos < 4.0 BootSector (0x%x)\n>>>>>>>66\tubyte\t\t<0x29\t\t\\b, dos < 4.0 BootSector (0x%x)\n>>>>>>>66\tubyte\t\t=0x29\n>>>>>>>>67\tulelong\t\tx\t\t\\b, serial number 0x%x\n>>>>>>>>71\tstring\t\t<NO\\ NAME\t\\b, label: \"%11.11s\"\n>>>>>>>71\tstring\t\t>NO\\ NAME\t\\b, label: \"%11.11s\"\n>>>>>>>71\tstring\t\t=NO\\ NAME\t\\b, unlabeled\n### FATs end\n>0x200\tlelong\t0x82564557\t\t\\b, BSD disklabel\n\n\n\n#--------------------------Firmware Formats---------------------------\n\n# uImage file     \n# From: Craig Heffner, U-Boot image.h header definitions file\n0\tbelong\t0x27051956\tuImage header, header size: 64 bytes,\n>4\tbelong\tx\t\theader CRC: 0x%X,\n>8\tbedate\tx\t\tcreated: %s,\n>12\tbelong\tx\t\timage size: %d bytes,\n>16\tbelong\tx\t\tData Address: 0x%X,\n>20\tbelong\tx\t\tEntry Point: 0x%X,\n>24\tbelong\tx\t\tdata CRC: 0x%X,\n#>28\tbyte\tx\t\tOS type: %d,\n>28\tbyte\t0\t\tOS: Invalid OS,\n>28\tbyte\t1\t\tOS: OpenBSD,\n>28\tbyte\t2\t\tOS: NetBSD,\n>28\tbyte\t3\t\tOS: FreeBSD,\n>28\tbyte\t4\t\tOS: 4.4BSD,\n>28\tbyte\t5\t\tOS: Linux,\n>28\tbyte\t6\t\tOS: SVR4,\n>28\tbyte\t7\t\tOS: Esix,\n>28\tbyte\t8\t\tOS: Solaris,\n>28\tbyte\t9\t\tOS: Irix,\n>28\tbyte\t10\t\tOS: SCO,\n>28\tbyte\t11\t\tOS: Dell,\n>28\tbyte\t12\t\tOS: NCR,\n>28\tbyte\t13\t\tOS: LynxOS,\n>28\tbyte\t14\t\tOS: VxWorks,\n>28\tbyte\t15\t\tOS: pSOS,\n>28\tbyte\t16\t\tOS: QNX,\n>28\tbyte\t17\t\tOS: Firmware,\n>28\tbyte\t18\t\tOS: RTEMS,\n>28\tbyte\t19\t\tOS: ARTOS,\n>28\tbyte\t20\t\tOS: Unity OS,\n#>29\tbyte\tx\t\tCPU arch: %d,\n>29\tbyte\t0\t\tCPU: Invalid OS,\n>29\tbyte\t1\t\tCPU: Alpha,\n>29\tbyte\t2\t\tCPU: ARM,\n>29\tbyte\t3\t\tCPU: Intel x86,\n>29\tbyte\t4\t\tCPU: IA64,\n>29\tbyte\t5\t\tCPU: MIPS,\n>29\tbyte\t6\t\tCPU: MIPS 64 bit,\n>29\tbyte\t7\t\tCPU: PowerPC,\n>29\tbyte\t8\t\tCPU: IBM S390,\n>29\tbyte\t9\t\tCPU: SuperH,\n>29\tbyte\t10\t\tCPU: Sparc,\n>29\tbyte\t11\t\tCPU: Sparc 64 bit,\n>29\tbyte\t12\t\tCPU: M68K,\n>29\tbyte\t13\t\tCPU: Nios-32,\n>29\tbyte\t14\t\tCPU: MicroBlaze,\n>29\tbyte\t15\t\tCPU: Nios-II,\n>29\tbyte\t16\t\tCPU: Blackfin,\n>29\tbyte\t17\t\tCPU: AVR,\n>29\tbyte\t18\t\tCPU: STMicroelectronics ST200,\n#>30\tbyte\tx\t\timage type: %d,\n>30\tbyte\t0\t\timage type: Invalid Image,\n>30\tbyte\t1\t\timage type: Standalone Program,\n>30\tbyte\t2\t\timage type: OS Kernel Image,\n>30\tbyte \t3\t\timage type: RAMDisk Image,\n>30\tbyte\t4\t\timage type: Multi-File Image,\n>30\tbyte\t5\t\timage type: Firmware Image,\n>30\tbyte\t6\t\timage type: Script file,\n>30\tbyte\t7\t\timage type: Filesystem Image,\n>30\tbyte\t8\t\timage type: Binary Flat Device Tree Blob\n#>31\tbyte\tx\t\tcompression type: %d,\n>31\tbyte\t0\t\tcompression type: none,\n>31\tbyte\t1\t\tcompression type: gzip,\n>31\tbyte\t2\t\tcompression type: bzip2,\n>31\tbyte\t3\t\tcompression type: lzma,\n>32\tstring\tx\t\timage name: %s\n\n#IMG0 header, found in VxWorks-based Mercury router firmware\n0\tstring\t\tIMG0\t\tIMG0 (VxWorks) header,\n>4\tbelong\t\tx\t\tsize: %d\n\n#Mediatek bootloader signature\n#From xp-dev.com\n0\tstring\t\tBOOTLOADER!\tMediatek bootloader\n\n#CSYS header formats\n0\tstring\t\tCSYS\\x00\tCSYS header, little endian, \n>8\tlelong\t\tx\t\tsize: %d\n\n0\tstring\t\tCSYS\\x80\tCSYS header, big endian,\n>8\tbelong\t\tx\t\tsize: %d\n\n# wrgg firmware image\n0\tstring\t\twrgg02\t\tWRGG firmware header,\n>6\tstring\t\tx\t\tname: %s,\n>48\tstring\t\tx\t\troot device: %s\n\n# trx image file\n0\tstring          HDR0            TRX firmware header, little endian, header size: 28 bytes, \n>4\tlelong\t\tx\t\timage size: %d bytes,\n>8\tlelong\t\tx\t\tCRC32: 0x%X\n>12\tlelong\t\tx\t\tflags/version: 0x%X\n\n0\tstring          0RDH            TRX firmware header, big endian, header size: 28 bytes,\n>4\tbelong\t\tx\t\timage size: %d bytes,\n>8\tbelong\t\tx\t\tCRC32: 0x%X\n>12\tbelong\t\tx\t\tflags/version: 0x%X\n\n\n# Ubicom firmware image\n0\tbelong\t0xFA320080\t\tUbicom firmware header,\n>12\tbelong\tx\t\t\tchecksum: 0x%X,\n>24\tbelong\tx\t\t\timage size: %d\n\n# The ROME bootloader is used by several RealTek-based products.\n# Unfortunately, the magic bytes are specific to each product, so\n# separate signatures must be created for each one.\n\n# Netgear KWGR614 ROME image\n0\tstring\t\tG614\t\tRealtek firmware header (ROME bootloader),\n>4\tbeshort\t\t0xd92f\t\timage type: KFS,\n>4\tbeshort\t\t0xb162\t\timage type: RDIR,\n>4\tbeshort\t\t0xea43\t\timage type: BOOT,\n>4\tbeshort\t\t0x8dc9\t\timage type: RUN,\n>4\tbeshort\t\t0x2a05\t\timage type: CCFG,\n>4\tbeshort\t\t0x6ce8\t\timage type: DCFG,\n>4\tbeshort\t\t0xc371\t\timage type: LOG,\n>6\tbyte\t\tx\t\theader version: %d,\n#month\n>10\tbyte\t\tx\t\tcreated: %d/\n#day\t\n>12\tbyte \t\tx\t\t\\b%d/\n#year\n>8\tbeshort\t\tx\t\t\\b%d,\n>16\tbelong\t\tx\t\timage size: %d bytes,\n>22\tbyte\t\tx\t\tbody checksum: 0x%X,\n>23\tbyte\t\tx\t\theader checksum: 0x%X\n\n# Linksys WRT54GX ROME image\n0\tbelong\t\t0x59a0e842\tRealtek firmware header (ROME bootloader)\n>4      beshort         0xd92f          image type: KFS,\n>4      beshort         0xb162          image type: RDIR,\n>4      beshort         0xea43          image type: BOOT,\n>4      beshort         0x8dc9          image type: RUN,\n>4      beshort         0x2a05          image type: CCFG,\n>4      beshort         0x6ce8          image type: DCFG,\n>4      beshort         0xc371          image type: LOG,\n>6      byte            x               header version: %d,\n#month\n>10     byte            x               created: %d/\n#day    \n>12     byte            x               \\b%d/\n#year\n>8      beshort         x               \\b%d,\n>16     belong          x               image size: %d bytes,\n>22     byte            x               body checksum: 0x%X,\n>23     byte            x               header checksum: 0x%X\n\n# PackImg tag, somtimes used as a delimiter between the kernel and rootfs in firmware images.\n0\tstring\t\t--PaCkImGs--\tPackImg Tag,\n>16\tlelong\t\tx\t\tlittle endian size: %d bytes;\n>16\tbelong\t\tx\t\tbig endian size: %d bytes\n\n\n#------------------------------------------------------------------------------\n# Broadcom header format\n#\n0       string          BCRM            Broadcom header,\n>4      lelong          x               number of sections: %d,\n>>8     lelong          18              first section type: flash\n>>8     lelong          19              first section type: disk\n>>8     lelong          21              first section type: tag\n\n\n# Berkeley Lab Checkpoint Restart (BLCR) checkpoint context files\n# http://ftg.lbl.gov/checkpoint\n0       string  Ck0\\0\\0R\\0\\0\\0  BLCR\n>16     lelong  1       x86\n>16     lelong  3       alpha\n>16     lelong  5       x86-64\n>16     lelong  7       ARM\n>8      lelong  x       context data (little endian, version %d)\n\n0       string  \\0\\0\\0C\\0\\0\\0R  BLCR\n>16     belong  2       SPARC\n>16     belong  4       ppc\n>16     belong  6       ppc64\n>16     belong  7       ARMEB\n>16     belong  8       SPARC64\n>8      belong  x       context data (big endian, version %d)\n\n# Aculab VoIP firmware\n# From: Mark Brown <broonie@sirena.org.uk>\n0       string  VoIP\\ Startup\\ and      Aculab VoIP firmware\n>35     string  x       format %s\n\n#------------------------------------------------------------------------------\n# HP LaserJet 1000 series downloadable firmware file\n0       string  \\xbe\\xefABCDEFGH        HP LaserJet 1000 series downloadable firmware\n\n# From Albert Cahalan <acahalan@gmail.com>\n# really le32 operation,destination,payloadsize (but quite predictable)\n# 01 00 00 00 00 00 00 c0 00 02 00 00\n0       string          \\1\\0\\0\\0\\0\\0\\0\\300\\0\\2\\0\\0      Marvell Libertas firmware\n\n#---------------------------------------------------------------------------\n# The following entries have been tested by Duncan Laurie <duncan@sun.com> (a\n# lead Sun/Cobalt developer) who agrees that they are good and worthy of\n# inclusion.\n\n# Boot ROM images for Sun/Cobalt Linux server appliances\n0       string  Cobalt\\ Networks\\ Inc.\\nFirmware\\ v     Paged COBALT boot rom\n>38     string x        V%.4s\n\n# New format for Sun/Cobalt boot ROMs is annoying, it stores the version code\n# at the very end where file(1) can't get it.\n0       string CRfs     COBALT boot rom data (Flat boot rom or file system)\n\n#\n# Motorola S-Records, from Gerd Truschinski <gt@freebsd.first.gmd.de>\n0   string      S0          Motorola S-Record; binary data in text format\n\n# --------------------------------\n# Microsoft Xbox data file formats\n0       string          XIP0            XIP, Microsoft Xbox data\n0       string          XTF0            XTF, Microsoft Xbox data\n\n#Windows CE\n64\tstring\t\tCECE\t\tWindows CE RTOS\n\n# --------------------------------\n# ZynOS ROM header format\n# From openwrt zynos.h.\n6\tstring\t\tSIG\t\tZynOS header, header size: 48 bytes,\n>0\tbelong\t\tx\t\tload address 0x%X,\n>9\tbyte\t\t<0x7F\t\trom image type:\n>>9\tbyte\t\t<1\t\tinvalid,\n>>9\tbyte\t\t>7\t\tinvalid,\n>>9\tbyte\t\t1\t\tROMIMG,\n>>9\tbyte\t\t2\t\tROMBOOT,\n>>9\tbyte\t\t3\t\tBOOTEXT,\n>>9\tbyte\t\t4\t\tROMBIN,\n>>9\tbyte\t\t5\t\tROMDIR,\n>>9\tbyte\t\t6\t\t6,\n>>9\tbyte\t\t7\t\tROMMAP,\n>9\tbyte\t\t>0x7F\t\tram image type:\n>>9\tbyte\t\t>0x82\t\tinvalid,\n>>9\tbyte\t\t0x80\t\tRAM,\n>>9\tbyte\t\t0x81\t\tRAMCODE,\n>>9\tbyte\t\t0x82\t\tRAMBOOT,\n>10\tbelong\t\t>0x40000000\tinvalid\n>10\tbelong\t\t<0\t\tinvalid\n>10\tbelong\t\t0\t\tinvalid\n>10\tbelong\t\tx\t\tuncompressed size: %d,\n>14\tbelong\t\t>0x40000000\tinvalid\n>14\tbelong\t\t<0\t\tinvalid\n>14\tbelong\t\t0  \t\tinvalid\n>14\tbelong\t\tx\t\tcompressed size: %d,\n>20\tbeshort\t\tx\t\tuncompressed checksum: 0x%X,\n>22\tbeshort\t\tx\t\tcompressed checksum: 0x%X,\n>18\tbyte\t\tx\t\tflags: 0x%X,\n>18\tbyte\t\t&0x40\t\tuncompressed checksum is valid,\n>18\tbyte\t\t&0x80\t\tthe binary is compressed,\n>>18\tbyte\t\t&0x20\t\tcompressed checksum is valid,\n>41\tbelong\t\tx\t\tmemory map table address: 0x%X\n\n# Firmware header used by some VxWorks-based Cisco products\n0\tstring\t\tCI032.00\tCisco VxWorks firmware header,\n>8\tlelong\t\t>1024\t\tinvalid\n>8\tlelong\t\t<0\t\tinvalid\n>8\tlelong\t\tx\t\theader size: %d bytes,\n>32\tlelong\t\t>1024\t\tinvalid\n>32\tlelong\t\t<0\t\tinvalid\n>32\tlelong\t\tx\t\tnumber of files: %d,\n>48\tlelong\t\t<0\t\tinvalid\n>48\tlelong\t\tx\t\timage size: %d,\n>64\tstring\t\tx\t\tfirmware version: %s\n\n# Firmware header used by some TV's\n0\tstring\t\tFNIB\t\tZBOOT firmware header, header size: 32 bytes,\n>8\tlelong\t\tx\t\tload address: 0x%.8X,\n>12\tlelong\t\tx\t\tstart address: 0x%.8X,\n>16\tlelong\t\tx\t\tchecksum: 0x%.8X,\n>20\tlelong\t\tx\t\tversion: 0x%.8X,\n>24\tlelong\t\t<1\t\tinvalid\n>24\tlelong\t\tx\t\timage size: %d bytes\n\n# Firmware header used by several D-Link routers (and probably others)\n0               string  \\x5e\\xa3\\xa4\\x17\n>(7.b+12)       string  \\x5e\\xa3\\xa4\\x17        DLOB firmware header,\n>>12            string  x                       %s,\n>>(7.b+40)      string  x                       %s\n\n#-------------------------Kernels-------------------------------------\n\n# Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>\n# and others such as Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>\n# and Nicolás Lichtmaier <nick@debian.org>\n# All known start with: b8 c0 07 8e d8 b8 00 90 8e c0 b9 00 01 29 f6 29\n514     string          HdrS            Linux kernel\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/md5.c",
    "content": "/* \n * Added md5_string function for ease of use with Binwalk.\n * \n * Original file obtained from: http://cr.yp.to/2004-494/gaim/0.81-src/md5.c\n *\n * Craig Heffner\n */\n\n/*\n  Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.\n\n  This software is provided 'as-is', without any express or implied\n  warranty.  In no event will the authors be held liable for any damages\n  arising from the use of this software.\n\n  Permission is granted to anyone to use this software for any purpose,\n  including commercial applications, and to alter it and redistribute it\n  freely, subject to the following restrictions:\n\n  1. The origin of this software must not be misrepresented; you must not\n     claim that you wrote the original software. If you use this software\n     in a product, an acknowledgment in the product documentation would be\n     appreciated but is not required.\n  2. Altered source versions must be plainly marked as such, and must not be\n     misrepresented as being the original software.\n  3. This notice may not be removed or altered from any source distribution.\n\n  L. Peter Deutsch\n  ghost@aladdin.com\n\n */\n/*\n  Independent implementation of MD5 (RFC 1321).\n\n  This code implements the MD5 Algorithm defined in RFC 1321.\n  It is derived directly from the text of the RFC and not from the\n  reference implementation.\n\n  The original and principal author of md5.c is L. Peter Deutsch\n  <ghost@aladdin.com>.  Other authors are noted in the change history\n  that follows (in reverse chronological order):\n\n  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.\n  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).\n  1999-05-03 lpd Original version.\n */\n\n#include \"md5.h\"\n#include <string.h>\n#include <stdio.h>\t/* Needed for snprintf call in md5_string() */\n\n#ifdef TEST\n/*\n * Compile with -DTEST to create a self-contained executable test program.\n * The test program should print out the same values as given in section\n * A.5 of RFC 1321, reproduced below.\n */\n#include <string.h>\nmain()\n{\n    static const char *const test[7] = {\n\t\"\", /*d41d8cd98f00b204e9800998ecf8427e*/\n\t\"945399884.61923487334tuvga\", /*0cc175b9c0f1b6a831c399e269772661*/\n\t\"abc\", /*900150983cd24fb0d6963f7d28e17f72*/\n\t\"message digest\", /*f96b697d7cb7938d525a2f31aaf161d0*/\n\t\"abcdefghijklmnopqrstuvwxyz\", /*c3fcd3d76192e4007dfb496cca67e13b*/\n\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\",\n\t\t\t\t/*d174ab98d277d9f5a5611c2c9f419d9f*/\n\t\"12345678901234567890123456789012345678901234567890123456789012345678901234567890\" /*57edf4a22be3c955ac49da2e2107b67a*/\n    };\n    int i;\n\n    for (i = 0; i < 7; ++i) {\n\tmd5_state_t state;\n\tmd5_byte_t digest[16];\n\tint di;\n\n\tmd5_init(&state);\n\tmd5_append(&state, (const md5_byte_t *)test[i], strlen(test[i]));\n\tmd5_finish(&state, digest);\n\tprintf(\"MD5 (\\\"%s\\\") = \", test[i]);\n\tfor (di = 0; di < 16; ++di)\n\t    printf(\"%02x\", digest[di]);\n\tprintf(\"  ::  MD5 string: %s\", md5_string((void *) test[i],strlen(test[i])));\n\tprintf(\"\\n\");\n    }\n    return 0;\n}\n#endif /* TEST */\n\n/* Returns the MD5 checksum string of a given file */\nchar *md5_string(void *data, size_t data_size)\n{\n\tint i = 0;\n\tint byte_str_size = 2;\n\tint md5_hash_length = 16;\n\tint str_size = ((md5_hash_length*byte_str_size)+1); /* MD5 is 16 bytes at 2 characters per byte, plus trailing NULL */\n\tchar *md5str = NULL;\n\tmd5_state_t state;\n\tmd5_byte_t digest[md5_hash_length];\n\n\tmd5str = malloc(str_size);\n\tif(!md5str)\n\t{\n\t\tperror(\"malloc\");\n\t}\n\telse\n\t{\n\t\tmemset(md5str,0,str_size);\n\n\t\tmd5_init(&state);\n\t\tmd5_append(&state, (const md5_byte_t *) data, data_size);\n\t\tmd5_finish(&state, digest);\n\n\t\tfor(i = 0; i < md5_hash_length; i++)\n\t\t{\n\t\t\tsnprintf(md5str+(byte_str_size*i),byte_str_size+1,\"%02x\",digest[i]);\n\t\t}\n\t}\n\n\treturn md5str;\n}\n\n/*\n * For reference, here is the program that computed the T values.\n */\n#if 0\n#include <math.h>\nmain()\n{\n    int i;\n    for (i = 1; i <= 64; ++i) {\n\tunsigned long v = (unsigned long)(4294967296.0 * fabs(sin((double)i)));\n\tprintf(\"#define T%d 0x%08lx\\n\", i, v);\n    }\n    return 0;\n}\n#endif\n/*\n * End of T computation program.\n */\n#define T1 0xd76aa478\n#define T2 0xe8c7b756\n#define T3 0x242070db\n#define T4 0xc1bdceee\n#define T5 0xf57c0faf\n#define T6 0x4787c62a\n#define T7 0xa8304613\n#define T8 0xfd469501\n#define T9 0x698098d8\n#define T10 0x8b44f7af\n#define T11 0xffff5bb1\n#define T12 0x895cd7be\n#define T13 0x6b901122\n#define T14 0xfd987193\n#define T15 0xa679438e\n#define T16 0x49b40821\n#define T17 0xf61e2562\n#define T18 0xc040b340\n#define T19 0x265e5a51\n#define T20 0xe9b6c7aa\n#define T21 0xd62f105d\n#define T22 0x02441453\n#define T23 0xd8a1e681\n#define T24 0xe7d3fbc8\n#define T25 0x21e1cde6\n#define T26 0xc33707d6\n#define T27 0xf4d50d87\n#define T28 0x455a14ed\n#define T29 0xa9e3e905\n#define T30 0xfcefa3f8\n#define T31 0x676f02d9\n#define T32 0x8d2a4c8a\n#define T33 0xfffa3942\n#define T34 0x8771f681\n#define T35 0x6d9d6122\n#define T36 0xfde5380c\n#define T37 0xa4beea44\n#define T38 0x4bdecfa9\n#define T39 0xf6bb4b60\n#define T40 0xbebfbc70\n#define T41 0x289b7ec6\n#define T42 0xeaa127fa\n#define T43 0xd4ef3085\n#define T44 0x04881d05\n#define T45 0xd9d4d039\n#define T46 0xe6db99e5\n#define T47 0x1fa27cf8\n#define T48 0xc4ac5665\n#define T49 0xf4292244\n#define T50 0x432aff97\n#define T51 0xab9423a7\n#define T52 0xfc93a039\n#define T53 0x655b59c3\n#define T54 0x8f0ccc92\n#define T55 0xffeff47d\n#define T56 0x85845dd1\n#define T57 0x6fa87e4f\n#define T58 0xfe2ce6e0\n#define T59 0xa3014314\n#define T60 0x4e0811a1\n#define T61 0xf7537e82\n#define T62 0xbd3af235\n#define T63 0x2ad7d2bb\n#define T64 0xeb86d391\n\nstatic void\nmd5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)\n{\n    md5_word_t\n\ta = pms->abcd[0], b = pms->abcd[1],\n\tc = pms->abcd[2], d = pms->abcd[3];\n    md5_word_t t;\n\n#ifndef ARCH_IS_BIG_ENDIAN\n# define ARCH_IS_BIG_ENDIAN 1\t/* slower, default implementation */\n#endif\n#if ARCH_IS_BIG_ENDIAN\n\n    /*\n     * On big-endian machines, we must arrange the bytes in the right\n     * order.  (This also works on machines of unknown byte order.)\n     */\n    md5_word_t X[16];\n    const md5_byte_t *xp = data;\n    int i;\n\n    for (i = 0; i < 16; ++i, xp += 4)\n\tX[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);\n\n#else  /* !ARCH_IS_BIG_ENDIAN */\n\n    /*\n     * On little-endian machines, we can process properly aligned data\n     * without copying it.\n     */\n    md5_word_t xbuf[16];\n    const md5_word_t *X;\n\n    if (!((data - (const md5_byte_t *)0) & 3)) {\n\t/* data are properly aligned */\n\tX = (const md5_word_t *)data;\n    } else {\n\t/* not aligned */\n\tmemcpy(xbuf, data, 64);\n\tX = xbuf;\n    }\n#endif\n\n#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))\n\n    /* Round 1. */\n    /* Let [abcd k s i] denote the operation\n       a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */\n#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))\n#define SET(a, b, c, d, k, s, Ti)\\\n  t = a + F(b,c,d) + X[k] + Ti;\\\n  a = ROTATE_LEFT(t, s) + b\n    /* Do the following 16 operations. */\n    SET(a, b, c, d,  0,  7,  T1);\n    SET(d, a, b, c,  1, 12,  T2);\n    SET(c, d, a, b,  2, 17,  T3);\n    SET(b, c, d, a,  3, 22,  T4);\n    SET(a, b, c, d,  4,  7,  T5);\n    SET(d, a, b, c,  5, 12,  T6);\n    SET(c, d, a, b,  6, 17,  T7);\n    SET(b, c, d, a,  7, 22,  T8);\n    SET(a, b, c, d,  8,  7,  T9);\n    SET(d, a, b, c,  9, 12, T10);\n    SET(c, d, a, b, 10, 17, T11);\n    SET(b, c, d, a, 11, 22, T12);\n    SET(a, b, c, d, 12,  7, T13);\n    SET(d, a, b, c, 13, 12, T14);\n    SET(c, d, a, b, 14, 17, T15);\n    SET(b, c, d, a, 15, 22, T16);\n#undef SET\n\n     /* Round 2. */\n     /* Let [abcd k s i] denote the operation\n          a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */\n#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))\n#define SET(a, b, c, d, k, s, Ti)\\\n  t = a + G(b,c,d) + X[k] + Ti;\\\n  a = ROTATE_LEFT(t, s) + b\n     /* Do the following 16 operations. */\n    SET(a, b, c, d,  1,  5, T17);\n    SET(d, a, b, c,  6,  9, T18);\n    SET(c, d, a, b, 11, 14, T19);\n    SET(b, c, d, a,  0, 20, T20);\n    SET(a, b, c, d,  5,  5, T21);\n    SET(d, a, b, c, 10,  9, T22);\n    SET(c, d, a, b, 15, 14, T23);\n    SET(b, c, d, a,  4, 20, T24);\n    SET(a, b, c, d,  9,  5, T25);\n    SET(d, a, b, c, 14,  9, T26);\n    SET(c, d, a, b,  3, 14, T27);\n    SET(b, c, d, a,  8, 20, T28);\n    SET(a, b, c, d, 13,  5, T29);\n    SET(d, a, b, c,  2,  9, T30);\n    SET(c, d, a, b,  7, 14, T31);\n    SET(b, c, d, a, 12, 20, T32);\n#undef SET\n\n     /* Round 3. */\n     /* Let [abcd k s t] denote the operation\n          a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */\n#define H(x, y, z) ((x) ^ (y) ^ (z))\n#define SET(a, b, c, d, k, s, Ti)\\\n  t = a + H(b,c,d) + X[k] + Ti;\\\n  a = ROTATE_LEFT(t, s) + b\n     /* Do the following 16 operations. */\n    SET(a, b, c, d,  5,  4, T33);\n    SET(d, a, b, c,  8, 11, T34);\n    SET(c, d, a, b, 11, 16, T35);\n    SET(b, c, d, a, 14, 23, T36);\n    SET(a, b, c, d,  1,  4, T37);\n    SET(d, a, b, c,  4, 11, T38);\n    SET(c, d, a, b,  7, 16, T39);\n    SET(b, c, d, a, 10, 23, T40);\n    SET(a, b, c, d, 13,  4, T41);\n    SET(d, a, b, c,  0, 11, T42);\n    SET(c, d, a, b,  3, 16, T43);\n    SET(b, c, d, a,  6, 23, T44);\n    SET(a, b, c, d,  9,  4, T45);\n    SET(d, a, b, c, 12, 11, T46);\n    SET(c, d, a, b, 15, 16, T47);\n    SET(b, c, d, a,  2, 23, T48);\n#undef SET\n\n     /* Round 4. */\n     /* Let [abcd k s t] denote the operation\n          a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */\n#define I(x, y, z) ((y) ^ ((x) | ~(z)))\n#define SET(a, b, c, d, k, s, Ti)\\\n  t = a + I(b,c,d) + X[k] + Ti;\\\n  a = ROTATE_LEFT(t, s) + b\n     /* Do the following 16 operations. */\n    SET(a, b, c, d,  0,  6, T49);\n    SET(d, a, b, c,  7, 10, T50);\n    SET(c, d, a, b, 14, 15, T51);\n    SET(b, c, d, a,  5, 21, T52);\n    SET(a, b, c, d, 12,  6, T53);\n    SET(d, a, b, c,  3, 10, T54);\n    SET(c, d, a, b, 10, 15, T55);\n    SET(b, c, d, a,  1, 21, T56);\n    SET(a, b, c, d,  8,  6, T57);\n    SET(d, a, b, c, 15, 10, T58);\n    SET(c, d, a, b,  6, 15, T59);\n    SET(b, c, d, a, 13, 21, T60);\n    SET(a, b, c, d,  4,  6, T61);\n    SET(d, a, b, c, 11, 10, T62);\n    SET(c, d, a, b,  2, 15, T63);\n    SET(b, c, d, a,  9, 21, T64);\n#undef SET\n\n     /* Then perform the following additions. (That is increment each\n        of the four registers by the value it had before this block\n        was started.) */\n    pms->abcd[0] += a;\n    pms->abcd[1] += b;\n    pms->abcd[2] += c;\n    pms->abcd[3] += d;\n}\n\nvoid\nmd5_init(md5_state_t *pms)\n{\n    pms->count[0] = pms->count[1] = 0;\n    pms->abcd[0] = 0x67452301;\n    pms->abcd[1] = 0xefcdab89;\n    pms->abcd[2] = 0x98badcfe;\n    pms->abcd[3] = 0x10325476;\n}\n\nvoid\nmd5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)\n{\n    const md5_byte_t *p = data;\n    int left = nbytes;\n    int offset = (pms->count[0] >> 3) & 63;\n    md5_word_t nbits = (md5_word_t)(nbytes << 3);\n\n    if (nbytes <= 0)\n\treturn;\n\n    /* Update the message length. */\n    pms->count[1] += nbytes >> 29;\n    pms->count[0] += nbits;\n    if (pms->count[0] < nbits)\n\tpms->count[1]++;\n\n    /* Process an initial partial block. */\n    if (offset) {\n\tint copy = (offset + nbytes > 64 ? 64 - offset : nbytes);\n\n\tmemcpy(pms->buf + offset, p, copy);\n\tif (offset + copy < 64)\n\t    return;\n\tp += copy;\n\tleft -= copy;\n\tmd5_process(pms, pms->buf);\n    }\n\n    /* Process full blocks. */\n    for (; left >= 64; p += 64, left -= 64)\n\tmd5_process(pms, p);\n\n    /* Process a final partial block. */\n    if (left)\n\tmemcpy(pms->buf, p, left);\n}\n\nvoid\nmd5_finish(md5_state_t *pms, md5_byte_t digest[16])\n{\n    static const md5_byte_t pad[64] = {\n\t0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n\t0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n\t0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n\t0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\n    };\n    md5_byte_t data[8];\n    int i;\n\n    /* Save the length before padding. */\n    for (i = 0; i < 8; ++i)\n\tdata[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));\n    /* Pad to 56 bytes mod 64. */\n    md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);\n    /* Append the length. */\n    md5_append(pms, data, 8);\n    for (i = 0; i < 16; ++i)\n\tdigest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));\n}\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/md5.h",
    "content": "/*\n * Added md5_string function prototype for ease of use with Binwalk.\n * \n * Original file obtained from: http://cr.yp.to/2004-494/gaim/0.81-src/md5.h\n *\n * Craig Heffner\n */\n\n/*\n  Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.\n\n  This software is provided 'as-is', without any express or implied\n  warranty.  In no event will the authors be held liable for any damages\n  arising from the use of this software.\n\n  Permission is granted to anyone to use this software for any purpose,\n  including commercial applications, and to alter it and redistribute it\n  freely, subject to the following restrictions:\n\n  1. The origin of this software must not be misrepresented; you must not\n     claim that you wrote the original software. If you use this software\n     in a product, an acknowledgment in the product documentation would be\n     appreciated but is not required.\n  2. Altered source versions must be plainly marked as such, and must not be\n     misrepresented as being the original software.\n  3. This notice may not be removed or altered from any source distribution.\n\n  L. Peter Deutsch\n  ghost@aladdin.com\n\n */\n/*\n  Independent implementation of MD5 (RFC 1321).\n\n  This code implements the MD5 Algorithm defined in RFC 1321.\n  It is derived directly from the text of the RFC and not from the\n  reference implementation.\n\n  The original and principal author of md5.h is L. Peter Deutsch\n  <ghost@aladdin.com>.  Other authors are noted in the change history\n  that follows (in reverse chronological order):\n\n  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.\n  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);\n\tadded conditionalization for C++ compilation from Martin\n\tPurschke <purschke@bnl.gov>.\n  1999-05-03 lpd Original version.\n */\n\n#ifndef md5_INCLUDED\n#  define md5_INCLUDED\n\n/*\n * This code has some adaptations for the Ghostscript environment, but it\n * will compile and run correctly in any environment with 8-bit chars and\n * 32-bit ints.  Specifically, it assumes that if the following are\n * defined, they have the same meaning as in Ghostscript: P1, P2, P3,\n * ARCH_IS_BIG_ENDIAN.\n */\n\n#include <stdlib.h>\n\ntypedef unsigned char md5_byte_t; /* 8-bit byte */\ntypedef unsigned int md5_word_t; /* 32-bit word */\n\n/* Define the state of the MD5 Algorithm. */\ntypedef struct md5_state_s {\n    md5_word_t count[2];\t/* message length in bits, lsw first */\n    md5_word_t abcd[4];\t\t/* digest buffer */\n    md5_byte_t buf[64];\t\t/* accumulate block */\n} md5_state_t;\n\n#ifdef __cplusplus\nextern \"C\" \n{\n#endif\n\n/* Initialize the algorithm. */\n#ifdef P1\nvoid md5_init(P1(md5_state_t *pms));\n#else\nvoid md5_init(md5_state_t *pms);\n#endif\n\n/* Append a string to the message. */\n#ifdef P3\nvoid md5_append(P3(md5_state_t *pms, const md5_byte_t *data, int nbytes));\n#else\nvoid md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);\n#endif\n\n/* Finish the message and return the digest. */\n#ifdef P2\nvoid md5_finish(P2(md5_state_t *pms, md5_byte_t digest[16]));\n#else\nvoid md5_finish(md5_state_t *pms, md5_byte_t digest[16]);\n#endif\n\n/* Returns the MD5 checksum string of a given file */\nchar *md5_string(void *data, size_t data_size);\n\n#ifdef __cplusplus\n}  /* end extern \"C\" */\n#endif\n\n#endif /* md5_INCLUDED */\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/mparse.c",
    "content": "/* Provides minimal magic file parsing capabilities */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <arpa/inet.h>\n#include <unistd.h>\n#include <string.h>\n#include \"mparse.h\"\n\n/* Parse out only the signatures entry from a magic file. 'Row' must point to the beginning of a magic signature line. */\nchar *parse_magic(char *row, int *offset, int *magic_size, int *wildcard, struct magic_filter *filters[], int filter_count, int ignore_short, int fast_filter)\n{\n\tchar *offset_str = NULL, *type = NULL, *magic_str = NULL, *magic_literal = NULL, *magic = NULL, *description = NULL;\n\tlong long_val = 0;\n\tshort short_val = 0;\n\tint literal_size = 0, base = 0;\n\n\t/* Get the offset, type and magic values from the row entry */\n\toffset_str = get_column(row, 0);\n\ttype = get_column(row, 1);\n\tmagic_str = get_column(row, 2);\n\tdescription = get_column(row, 3);\n\n\tif(!offset_str || !type || !magic_str || !description)\n\t{\n\t\tgoto end;\n\t}\n\n\t/* \n\t * If the magic signature is just the magic wildcard character, treat it as a string.\n\t * Likewise, binwalk itself doesn't have support for type masking, so treat masked types\n\t * (such as 'belong&0xF0FFFF00') as strings and just pass them off to libmagic.\n\t */\n\tif((strcmp(magic_str, MAGIC_WILDCARD) == 0) ||\n\t   (strstr(type, AMPERSAND)))\n\t{\n\t\t*wildcard = 1;\n\t\tignore_short = 0;\n\t\tfree(type);\n\t\ttype = strdup(STRING);\n\t}\n\telse\n\t{\n\t\t*wildcard = 0;\n\t}\n\n\t/* \n\t * Two byte signatures result in lots of false positives. If ignore_short is non-zero, then ignore\n\t * all signatures that are of type beshort or leshort, or strings that are two bytes or less in length.\n\t * But only if this signature has not been explicitly marked for inclusion!\n\t */\n\tif(ignore_short && filter_check(filters, filter_count, description) != RESULT_INCLUDE)\n\t{\n\t\tif(strncmp(type, HOST_SHORT, HOST_SHORT_SIZE) == 0 || strncmp(type, LESHORT, LESHORT_SIZE) == 0 || strncmp(type, BESHORT, BESHORT_SIZE) == 0)\n\t\t{\n\t\t\tgoto end;\n\t\t}\n\t\telse if(strncmp(type, STRING, STRING_SIZE) == 0)\n\t\t{\n\t\t\tmagic_literal = string_literal(magic_str, &literal_size);\n\t\t\tif(magic_literal) free(magic_literal);\n\t\t\t\t\n\t\t\tif(literal_size <= SHORT_SIZE)\n\t\t\t{\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\t}\n\n\t/*\n\t * If fast filtering has been enabled and the signature description is not in our include list,\n\t * then completely ignore the signature.\n\t */\n\tif(fast_filter)\n\t{\n\t\tif(description && strlen(description) > 0)\n\t\t{\n\t\t\tif(filter_check(filters, filter_count, description) != RESULT_INCLUDE)\n\t\t\t{\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Offsets can be specified in hex or decimal */\n\tif(strstr(offset_str, \"0x\") == offset_str)\n\t{\t\n\t\t*offset = strtol(offset_str, NULL, 16);\n\t}\n\telse\n\t{\n\t\t*offset = strtol(offset_str, NULL, 10);\n\t}\n\n\t/* Convert the magic value to a string, long or short value */\n\tif(memcmp(type, STRING, STRING_SIZE) == 0)\n\t{\n\t\tmagic = string_literal(magic_str, magic_size);\n\t} else {\n\t\t/* Numeric magic strings can be specified in hex or decimal */\n\t\tif(strstr(magic_str, \"0x\") == magic_str)\n\t\t{\n\t\t\tbase = 16;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbase = 10;\n\t\t}\n\n\t\tif(memcmp(type, LELONG, LELONG_SIZE) == 0 || memcmp(type, HOST_LONG, HOST_LONG_SIZE) == 0)\n\t\t{\n\t\t\tlong_val = strtol(magic_str, NULL, base);\n\t\t\t*magic_size = LONG_SIZE;\n\n\t\t} else if(memcmp(type, LESHORT, LESHORT_SIZE) == 0 || memcmp(type, HOST_SHORT, HOST_SHORT_SIZE) == 0) {\n\n\t\t\tshort_val = (short) strtol(magic_str, NULL, base);\n\t\t\t*magic_size = SHORT_SIZE;\n\n\t\t} else if(memcmp(type, BELONG, BELONG_SIZE) == 0) {\n\n\t\t\tlong_val = strtol(magic_str, NULL, base);\n\t\t\tlong_val = htonl(long_val);\n\t\t\t*magic_size = LONG_SIZE;\n\n\t\t} else if(memcmp(type, BESHORT, BESHORT_SIZE) == 0) {\n\n\t\t\tshort_val = (short) strtol(magic_str, NULL, base);\n\t\t\tshort_val = htons(short_val);\n\t\t\t*magic_size = SHORT_SIZE;\n\t\t}\n\t\t\n\t\tif(*magic_size == SHORT_SIZE)\n\t\t{\n\t\t\tmagic = malloc(SHORT_SIZE);\n\t\t\tif(!magic)\n\t\t\t{\n\t\t\t\t*magic_size = 0;\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t\tmemcpy(magic, (void *) &short_val, SHORT_SIZE);\n\n\t\t} else if(*magic_size == LONG_SIZE) {\n\n\t\t\tmagic = malloc(LONG_SIZE);\n\t\t\tif(!magic)\n\t\t\t{\n\t\t\t\t*magic_size = 0;\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t\tmemcpy(magic, (void *) &long_val, LONG_SIZE);\n\t\t}\n\t}\n\nend:\n\tif(offset_str) free(offset_str);\n\tif(type) free(type);\n\tif(magic_str) free(magic_str);\n\tif(description) free(description);\n\treturn magic;\n}\n\n/* Converts escaped hex or octal bytes to their respective values in the string */\nchar *string_literal(char *string, int *literal_size)\n{\n\tchar *literal = NULL;\n\tchar sbyte[4] = { 0 };\n\tchar byte = 0;\n\tint str_size = 0;\n\tint lsize = 0, i = 0;\n\n\tif(string != NULL && literal_size != NULL)\n\t{\n\t\tstr_size = strlen(string);\n\n\t\t/* The converted string will be as big or smaller than the original string */\n\t\tliteral = malloc(str_size+1);\n\t\tif(!literal)\n\t\t{\n\t\t\tperror(\"malloc\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmemset(literal, 0, str_size+1);\n\n\t\t\t/* Loop through each byte of the original string */\n\t\t\tfor(i=0; i<str_size; i++,lsize++)\n\t\t\t{\n\t\t\t\t/* Always zero out sbyte; it's a place holder for the string value of the escaped digit */\n\t\t\t\tmemset(&sbyte, 0, sizeof(sbyte));\n\t\t\n\t\t\t\t/* Check if we've encountered an escaped character and there are at least two trailing characters */\n\t\t\t\tif(string[i] == '\\\\' && i < str_size-2)\n\t\t\t\t{\n\t\t\t\t\t/* Check to see if we've encountered an escaped escape character */\n\t\t\t\t\tif(string[i+1] == '\\\\')\n\t\t\t\t\t{\n\t\t\t\t\t\t/* Copy the escape character, and increment i by one to ignore the second */\n\t\t\t\t\t\tmemcpy(literal+lsize, string, 1);\n\t\t\t\t\t\ti++;\n\t\n\t\t\t\t\t/* Check to see if we've encountered an esceaped hex value */\n\t\t\t\t\t} \n\t\t\t\t\telse if(string[i+1] == 'x') \n\t\t\t\t\t{\n\t\n\t\t\t\t\t\t/* Get the two bytes after the '\\x' and convert them to an integer */\n\t\t\t\t\t\tmemcpy(&sbyte, string+i+2, 2);\n\t\t\t\t\t\tbyte = (char) strtol((const char*) &sbyte, NULL, 16);\n\t\t\t\t\t\tmemset(literal+lsize, byte, 1);\n\t\t\t\t\t\ti += 3;\n\t\n\t\t\t\t\t/* Else, assume this is an escaped octal value */\n\t\t\t\t\t} \n\t\t\t\t\telse \n\t\t\t\t\t{\n\t\n\t\t\t\t\t\tmemcpy(&sbyte, string+i+1, 3);\n\t\t\t\t\t\tbyte = (char) strtol((const char *) &sbyte, NULL, 8);\n\t\t\t\t\t\tmemset(literal+lsize, byte, 1);\n\t\t\t\t\t\ti += 3;\n\t\t\t\t\t}\n\t\t\t\t} \n\t\t\t\telse \n\t\t\t\t{\n\t\t\t\t\tmemcpy(literal+lsize, string+i, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\n\t\t*literal_size = lsize;\t\n\t}\n\n\treturn literal;\n}\n\n/* Retrieves a column value from a given row */\nchar *get_column(char *row, int colnum)\n{\n\tint row_size = 0;\n\tint i = 0, j = 0, col_size = 0, count = 0;\n\tchar *column = NULL;\n\n\tif(row != NULL)\n\t{\n\t\trow_size = strlen(row);\n\n\t\tfor(i=0; i<row_size; i++)\n\t\t{\n\t\t\t/* If this character is a white space, skip it */\n\t\t\tif(row[i] <= ' ')\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t/* \n\t\t\t * Loop through the string until a column delimiter is found.\n\t\t\t * A column delimiter is any whitespace character.\n\t\t\t */\n\t\t\tfor(j=i; j < row_size; j++)\n\t\t\t{\n\t\t\t\t/* If this character is a white space */\n\t\t\t\tif(row[j] <= ' ')\n\t\t\t\t{\n\t\t\t\t\t/* \n\t\t\t\t\t * The last column in the magic file format contains a description which \n\t\t\t\t\t * likely will contain numerous whitespace characters. Be sure to get the\n\t\t\t\t\t * entire last column by looping until a new line character is found.\n\t\t\t\t\t */\n\t\t\t\t\tif(count == LAST_MAGIC_COLUMN && row[j] != '\\n')\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t/* Else, we have reached the end of this column */\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/* Is this the column that we want? */\n\t\t\tif(count == colnum)\n\t\t\t{\n\t\t\t\t/* Calculate the string length of this column and copy it into a buffer */\n\t\t\t\tcol_size = j - i;\n\t\t\t\tcolumn = malloc(col_size+1);\n\t\t\t\tif(!column)\n\t\t\t\t{\n\t\t\t\t\tperror(\"Malloc failure\");\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tmemset(column,0,col_size+1);\n\t\t\t\tmemcpy(column,row+i,col_size);\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\t/* \n\t\t\t\t * Set i == j to start searching for the next column at the end of this one.\n\t\t\t\t * Increment count to track column count.\n\t\t\t\t */\n\t\t\t\ti = j;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn column;\n}\n\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/mparse.h",
    "content": "#ifndef MPARSE_H\n#define MPARSE_H\n\n#include \"filter.h\"\n\n#define HOST_SHORT\t\t\"short\"\n#define HOST_SHORT_SIZE\t\t5\n#define HOST_LONG\t\t\"long\"\n#define HOST_LONG_SIZE\t\t4\n#define LESHORT \t\t\"leshort\"\n#define LESHORT_SIZE    \t7\n#define LELONG  \t\t\"lelong\"\n#define LELONG_SIZE     \t6\n#define BESHORT \t\t\"beshort\"\n#define BESHORT_SIZE    \t7\n#define BELONG  \t\t\"belong\"\n#define BELONG_SIZE     \t6\n#define STRING  \t\t\"string\"\n#define STRING_SIZE     \t6\n#define LONG_SIZE       \t4\n#define SHORT_SIZE      \t2\n#define LAST_MAGIC_COLUMN\t3\n#define MAGIC_WILDCARD\t\t\"x\"\n#define AMPERSAND\t\t\"&\"\n\nchar *get_column(char *row, int colnum);\nchar *string_literal(char *string, int *literal_size);\nchar *parse_magic(char *row, int *offset, int *magic_size, int *wildcard, struct magic_filter *filters[], int filter_count, int ignore_short, int fast_filter);\n\n#endif\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/update.c",
    "content": "#include <stdio.h>\n\n#ifndef NOCURL\n#include <curl/curl.h>\n#include <curl/easy.h>\n#endif\n\n#include \"update.h\"\n\nsize_t write_data(void *ptr, size_t size, size_t nmemb, FILE *fp)\n{\n\tsize_t written = 0;\n\n\twritten = fwrite(ptr, size, nmemb, fp);\n\n\treturn written;\n}\n\nint update_magic_file(char *url, char *outfile) \n{\n\tint retval = 0;\n\n#ifndef NOCURL\n\tCURL *curl = NULL;\n\tFILE *fp = NULL;\n    \n\tcurl = curl_easy_init();\n\tif(curl) \n\t{\n        \tfp = fopen(outfile,\"wb\");\n\t\tif(fp)\n\t\t{\n        \t\tcurl_easy_setopt(curl, CURLOPT_URL, url);\n        \t\tcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);\n        \t\tcurl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);\n        \t\t\n\t\t\tif(curl_easy_perform(curl) == 0)\n\t\t\t{\n\t\t\t\tretval = 1;\n\t\t\t}\n\n        \t\tfclose(fp);\n\t\t} \n\t\telse \n\t\t{\n\t\t\tperror(outfile);\n\t\t}\n        \n\t\tcurl_easy_cleanup(curl);\n    \t}\n#else\n\tfprintf(stderr, \"Sorry, this feature has been disabled!\\n\");\n#endif\n\n    \treturn retval;\n}\n"
  },
  {
    "path": "src/binwalk-0.4.1/src/update.h",
    "content": "#ifndef UPDATE_H\n#define UPDATE_H\n\n#define BINWALK_UPDATE_URL\t\"http://binwalk.googlecode.com/svn/trunk/src/magic.binwalk\"\n#define BINCAST_UPDATE_URL\t\"http://binwalk.googlecode.com/svn/trunk/src/magic.bincast\"\n#define BINARCH_UPDATE_URL\t\"http://binwalk.googlecode.com/svn/trunk/src/magic.binarch\"\n\nint update_magic_file(char *url, char *outfile);\nsize_t write_data(void *ptr, size_t size, size_t nmemb, FILE *fp);\n\n#endif\n"
  },
  {
    "path": "src/binwalk-1.0/docs/API",
    "content": "DESCRIPTION\n\n\tThe binwalk python module can be used by any python script to programatically perform binwalk scans and \n\tobtain the results of those scans. \n\n\tThe classes, methods and objects in the binwalk modules are documented via pydoc, including examples, \n\tso those interested in using the binwalk module are encouraged to look there. However, several common usage \n\texamples are provided here to help jump-start development efforts.\n\n\nBASIC SCAN\n\n\tThis is the simplest scan, and is equivalent to running binwalk on the command line with no additional arguments.\n\tNote the use of the cleanup() method, which will ensure all temporary files generated by binwalk are cleaned up:\n\n\t\tfrom binwalk import Binwalk\n\n\t\tbinwalk = Binwalk()\n\t\tresults = binwalk.scan('firmware.bin')\n\t\tbinwalk.cleanup()\n\n\tThe scan() method will return a list of tuples, one tuple for each offset in the target file where a matching\n\tsignature was found. The first element of each tuple is the offset into the file at which the match was found. \n\tThe second tuple is a list of dictionaries (depending on the binwalk options, there may be more than one match \n\tfor a given offset); each dictionary describes a matching signature:\n\n\t\tresults = [\n\t\t\t\t(0, [{description : \"LZMA compressed data...\"}]),\n\t\t\t\t(112, [{description : \"gzip compressed data...\"}]),\n\t\t]\n\n\tA callback function may also be specified. The callback function is called as soon as a match is identified. It\n\tis passed two arguments: the offset at which the match was found, and a list of dictionaries as described above:\n\n\t\tfrom binwalk import Binwalk\n\n\t\tdef my_callback(offset, results):\n\t\t\tprint \"Found %d results at offset %d:\" % (len(results), offset)\n\t\t\tfor result in results:\n\t\t\t\tprint \" %s\" % result['description']\n\n\t\tbinwalk = Binwalk(callback=my_callback)\n\t\tbinwalk.scan('firmware.bin')\n\t\tbinwalk.cleanup()\n\n\nADDING FILTERS\n\n\tInclude and exclude filters may be specified which operate identically to the --include, --exclude and --search\n\tbinwalk command line options:\n\n\t\tfrom binwalk import Binwalk\n\t\t\n\t\tbinwalk = Binwalk()\n\t\t\n\t\t# Adds a normally excluded signature to the existing list of signatures (same as --include)\n\t\tbinwalk.filter.include('minix', exclusive=False)\n\n\t\t# Exclusively filters out all signatures except those containing the string 'filesystem' (same as --search)\n\t\tbinwalk.filter.include('filesystem')\n\n\t\t# Excludes all results that contain the string 'jffs2' (same as --exclude)\n\t\tbinwalk.filter.exclude('jffs2')\n\n\t\tbinwalk.scan('firmware')\n\n\nEXTRACTING FILES\n\n\tExtract rules may be specified which operate identically to the --dd and --extract binwalk command line options.\n\t\n\tTo add a custom extract rule, or a list of extract rules (such as with the --dd option):\n\n\t\tfrom binwalk import Binwalk\n\n\t\tbinwalk = Binwalk()\n\n\t\t# Extract results containing the string 'gzip' with a file extension of 'gz' and run the gunzip command\n\t\tbinwalk.extractor.add_rule('gzip:gz:gunzip %e')\n\n\t\t# Extract 'gzip' and 'filesystem' results\n\t\tbinwalk.extractor.add_rule(['gzip:gz', 'filesystem:fs'])\n\n\t\tbinwalk.scan('firmware')\n\n\tTo load the default extraction rules from the extract.conf file (such as with the --extract option):\n\t\n\t\tfrom binwalk import Binwalk\n\t\t\n\t\tbinwalk = Binwalk()\n\t\tbinwalk.extractor.load_defaults()\n\t\tbinwalk.Scan('firmware.bin')\n\n\n\tTo enabled delayed file extraction (such as with the --delay option):\n\n\t\tfrom binwalk import Binwalk\n\t\t\n\t\tbinwalk = Binwalk()\n\t\tbinwalk.extractor.enable_delayed_extract(True)\n\t\tbinwalk.Scan('firmware.bin')\n\n\tTo enable file cleanup after extraction (such as with the --rm option):\n\n\t\tfrom binwalk import Binwalk\n\t\t\n\t\tbinwalk = Binwalk()\n\t\tbinwalk.extractor.cleanup_extracted_files(True)\n\t\tbinwalk.Scan('firmware.bin')\n\n"
  },
  {
    "path": "src/binwalk-1.0/docs/COPYING",
    "content": "The MIT License\n\nCopyright (c) 2010 Craig Heffner\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n"
  },
  {
    "path": "src/binwalk-1.0/docs/README",
    "content": "DESCRIPTION\n\n\tBinwalk is a tool for searching a given binary image for embedded file types. Specifically,\n\tit was designed for identifying files embedded inside of firmware images. Binwalk file signatures\n\tare compatible with the magic signatures used by the Unix file utility.\n\n\tBinwalk includes customized/improved signatures for files that are commonly found in firmware images\n\tsuch as compressed/archived files, firmware headers, Linux kernels, bootloaders, filesystems, etc. \n\n\tBinwalk can scan for executable code by searching for opcodes associated with the function prologues/epiloges \n\tof various architectures.\n\n\tBinwalk can display the value of each file offset in various data types (long, short, date, etc). This is \n\tuseful for identifying unknown firmware header fields such as date and length values.\n\n\tBinwalk can extract embedded files from firmware images and invoke external applications for further analysis,\n\tdecompression or extraction.\n\nINSTALLATION\n\n\tTo install binwalk, run the following command from the src directory:\n\n\t\t# python setup.py install\n\nDEPENDENCIES\n\n\tBinwalk is currently supported on the Linux and Mac OSX platforms.\n\n\tBinwalk depends on the libmagic library (version 5.05 or newer) and its corresponding magic Python module. Debian \n\tusers can install these dependencies via apt-get:\n\n\t\t$ sudo apt-get install libmagic1 python-magic\n\n\tNote that some distributions/platforms may not have libmagic readily available, or may use an older version of \n\tlibmagic that is incompatible with binwalk. In this case, you may download the source code for the file utility at:\n\n\t\tftp://ftp.astron.com/pub/file/\n\n\tFollow the file utility's documentation to build and install both libmagic and the Python magic module.\n\n\nBASIC USAGE\n\n\tThe only required options to binwalk are the file(s) that you want to search:\n\n\t\t$ binwalk firmware1.bin firmware2.bin firmware3.bin\n\n\tBinwalk signatures and system-wide configuration files can be updated to the latest from the SVN\n\ttrunk with the --update option (this likely will need to be run as root):\n\n\t\t# binwalk --update\n\n\tTo see more verbose information about the file being scanned, specify the --verbose option. This option\n\tis automatically enabled if more than one target file is specified on the command line:\n\n\t\t$ binwalk --verbose firmware.bin\n\n\tOutput can be logged to a file with the --file option:\n\n\t\t$ binwalk --file=binwalk.log firmware.bin\n\n\tOutput to stdout can be suppressed with the --quiet option:\n\n\t\t$ binwalk --file=binwalk.log --quiet firmware.bin\n\n\tBy default, scans start at the first byte of the specified file (offset 0) and end at the end of the\n\tspecified file. These settings can be controlled with the --offset and --length options, respectively.\n\tFor example, the following command will scan 128 bytes starting at offset 64:\n\n\t\t$ binwalk --offset=64 --length=128 firmware.bin\n\n\tBy default, binwalk will scan every byte for possible signatures. To scan every 2 bytes, 4 bytes, 8 bytes,\n\tetc, use the --align option:\n\n\t\t$ binwalk --align=4 firmware.bin\n\n\tBy default binwalk will use the signatures from the magic.binwalk file, but you may specify an alternate\n\tsignature file with the --magic option:\n\n\t\t$ binwalk --magic=/usr/share/misc/magic firmware.bin\n\n\tTo search for a sequence of bytes without creating a signature file, use the --raw-bytes option:\n\n\t\t$ binwalk --raw-bytes=\"\\x00\\x01\\x02\\x03\" firmware.bin\n\n\nTYPES OF SCANS\n\n\tBy default binwalk will scan for file signatures inside the specified target file(s), however, other\n\ttypes of scans are also supported.\n\n\tTo scan for known x86/MIPS/ARM/PPC opcodes, use the --opcodes option:\n\n\t\t$ binwalk --opcodes firmware.bin\n\n\tTo cast each offset in the file as various data types (big/little endian shorts/longs, date fields, etc),\n\tuse the --cast option (best used with the --length / --offset options):\n\n\t\t$ binwalk --cast --length=64 firmware.bin\n\n\nCONTROLLING SCAN BEHAVIOR\n\n\tSome signatures - notably those whose magic signatures are less than 3 bytes - are excluded by default\n\tfrom binwalk scans. These can be individually included with the --include option, or globally with --all\n\t(multiple --include options may be specified):\n\n\t\t$ binwalk --include=minix firmware.bin\n\t\t$ binwalk --all firmware.bin\n\n\tBy default results marked as invalid are not displayed. They can be displayed by specifying the --show-invalid\n\toption:\n\n\t\t$ binwalk --show-invalid firmware.bin\n\n\tBy default binwalk will stop scanning for signatures at any given offset once a valid signature has been\n\tfound at that offset. To display all signatures that match at all offsets, use the --keep-going option:\n\n\t\t$ binwalk --keep-going firmware.bin\n\n\nFILTERING SCAN RESULTS\n\n\tIt may at times be desirable to exclude certian signatures from the scan results. This can be done with the\n\t--exclude option (multiple --exclude options may be specified):\n\n\t\t$ binwalk --exclude='lzma compressed data' firmware.bin\n\n\tIt may at times be desirable to only search for a certian signature or group of signatures. This can be \n\tdone with the --search option (multiple --search options may be specified):\n\t\n\t\t$ binwalk --search=filesystem firmware.bin\n\n\tThe --grep option is useful for filtering output that contains multiple results per line, such as occurs \n\twith the --cast option:\n\n\t\t$ binwalk --cast --grep=2012 firmware.bin\n\nEXTRACTING FILES\n\n\tBinwalk can extract matches found inside the target file(s), and optionally execute an external command\n\teach time a file is extracted using the --dd option. At a minimum, a string to search for in the output\n\tdescription and a file extension must be specified. A command to execute may also be specified. These \n\tthree fields are colon delimited.\n\n\tTo extract all matches that contain the text 'gzip compressed data' and save them with a file extension\n\tof 'gz':\n\n\t\t$ binwalk --dd='gzip compressed data:gz' firmware.bin\n\t\n\tTo extract all matches that contain the text 'gzip compressed data', save them with a file extension of\n\t'gz' and execute the 'gunzip' command against the extracted file (note the use of the %e place holder for\n\tthe path to the extracted file):\n\n\t\t$ binwalk --dd='gzip compressed data:gz:gunzip %e' firmware.bin\n\t\n\tThere are some file types that are commonly extracted, and specifying a --dd option for each one is tiresome.\n\tThe -e option will load extract rules from the system/user extract.conf file (see the CONFIGURATION FILES section\n\tbelow):\n\n\t\t$ binwalk -e firmware.bin\n\t\n\tTo specify a different extraction rule file, use --extract:\n\n\t\t$ binwalk --extract=./my_extract.conf firmware.bin\n\t\n\tExtracting files with --dd or --extract can leave a lot of uneccessary files laying around. These can be \n\tautomatically cleaned up with the --rm option. If specified, any extracted file that had a command run against\n\tit will be deleted after the command has finished execution. Additionally, if files created by the executed\n\tcommand are 0 bytes in size, they will also be removed:\n\n\t\t$ binwalk --rm firmware.bin\n\n\tSome file types do not specify their file size in their header, but rather rely on a footer or delimiter to\n\tsignify the end of the file. When extracted these files will by default be copied from the start of the header\n\tto the end of the target file. If there are many of these files, this can take up unecessary disk space. For\n\tthose files which are supported, specifying the --delay option will delay the extraction of these files until\n\tthe end of the file can be found:\n\n\t\t$ binwalk --delay firmware.bin\n\n\t\nDISPLAYING SCAN PROGRESS\n\n\tSome scans can take some time to complete and may not display many results during this time. You can press the \n\tenter key at any time to force binwalk to display its current scan progress:\n\n\t\t$ binwalk -v firmware.bin\n\n\t\tDECIMAL   \tHEX       \tDESCRIPTION\n\t\t------------------------------------------------------------------------------------------\n\t\t<Enter>\n\t\tProgress:  1595 / 12074736  (0.01%)\n\t\t<Enter>\n\t\tProgress:  8015 / 12074736  (0.07%)\n\t\t<Enter>\n\t\tProgress:  12424 / 12074736  (0.10%)\n\n\nSIGNATURE FILES\n\n\tThere are three signature files used by binwalk:\n\n\t\to magic/binwalk - The default signature file.\n\t\to magic/binarch - The signature file used with --opcodes.\n\t\to magic/bincast - The signature file used with --cast.\n\n\tUsers may create their own signatures that will be added to the respective system-wide files when performing a scan.\n\tThis is as easy as editing the following files in the user home directory:\n\n\t\to .binwalk/magic/binwalk\n\t\to .binwalk/magic/binarch\n\t\to .binwalk/magic/bincast\n\n\tAlthough the system-wide signature files can also be altered, the system-wide signature files will be overwritten when\n\tupgrading binwalk, or using the --update option. The user files will not be touched however, and will survive these updates.\n\n\nCONFIGURATION FILES\n\n\tThere is one configuration file used by binwalk only when the --extract option is specified:\n\n\t\to config/extract.conf\n\n\tThis file contains a list of extract rules, identical to the arguments that would be passed to the --dd option.\n\n\tUsers can override and add to this list of extract rules by adding their own rules to the following file in the user home\n\tdirectory:\n\n\t\to .binwalk/config/extract.conf\n\n\tNote that when overriding a system-wide extract rule, the 'type' field in the user extract rule must exactly match the 'type'\n\tfield in the system-wide extract rule.\n\n\tAlthough the system-wide extract.conf file can also be altered, this file will be overwritten when upgrading binwalk or using\n\tthe --update option. The user extract.conf file will not be touched however, and will survive these updates.\n\nMORE INFORMATION\n\n\tFor more detailed and up to date information, visit the binwalk wiki page at:\n\n\t\thttp://code.google.com/p/binwalk/wiki/TableOfContents\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/bin/binwalk-script",
    "content": "#!/usr/bin/env python\n\nimport sys\nimport os.path\nimport binwalk\nfrom threading import Thread\nfrom binwalk.common import str2int\nfrom getopt import GetoptError, getopt as GetOpt\n\ndef display_status(bwalk):\n\twhile True:\n\t\t# Display the current scan progress when the enter key is pressed.\n\t\traw_input()\n\t\tprint \"Progress: %.2f%% (%d / %d)\\n\" % (((float(bwalk.total_scanned) / float(bwalk.scan_length)) * 100), bwalk.total_scanned, bwalk.scan_length)\n\ndef usage(fd):\n\tfd.write(\"\\n\")\n\tfd.write(\"Binwalk v%s\\n\" % binwalk.Config.VERSION)\n\tfd.write(\"Craig Heffner, http://www.devttys0.com\\n\")\n\tfd.write(\"\\n\")\n\tfd.write(\"Usage: %s [OPTIONS] [FILE1] [FILE2] [FILE3] ...\\n\" % os.path.basename(sys.argv[0]))\n\tfd.write(\"\\n\")\n\tfd.write(\"\\t-o, --offset=<int>            Start scan at this file offset\\n\")\n\tfd.write(\"\\t-l, --length=<int>            Number of bytes to scan\\n\")\n\tfd.write(\"\\t-b, --align=<int>             Set byte alignment [default: 1]\\n\")\n\tfd.write(\"\\t-m, --magic=<file>            Specify an alternate magic file to use\\n\")\n\tfd.write(\"\\t-i, --include=<filter>        Include matches that are normally excluded and that have <filter> in their description\\n\")\n\tfd.write(\"\\t-x, --exclude=<filter>        Exclude matches that have <filter> in their description\\n\")\n\tfd.write(\"\\t-y, --search=<filter>         Only search for matches that have <filter> in their description\\n\")\n\tfd.write(\"\\t-g, --grep=<text>             Grep results for the specified text\\n\")\n\tfd.write(\"\\t-R, --raw-bytes=<string>      Search for a sequence of raw bytes instead of using the default magic signatures\\n\")\n\tfd.write(\"\\t-f, --file=<file>             Log results to file\\n\")\n\tfd.write(\"\\t-D, --dd=<type:ext[:cmd]>     Extract entries whose descriptions match <type>, give them file extension <ext>, and execute <cmd>\\n\")\n\tfd.write(\"\\t-e, --extract=[file]          Automatically extract known file types. Load rules from file, if specified.\\n\")\n\tfd.write(\"\\t-r, --rm                      Cleanup extracted files and zero-size files\\n\")\n\tfd.write(\"\\t-d, --delay                   Delay file extraction for files with known footers\\n\")\n\tfd.write(\"\\t-a, --all                     Include all short signatures\\n\")\n\tfd.write(\"\\t-I, --show-invalid            Show results marked as invalid\\n\")\n\tfd.write(\"\\t-A, --opcodes                 Scan for executable code\\n\")\n\tfd.write(\"\\t-C, --cast                    Cast file contents as various data types\\n\")\n\tfd.write(\"\\t-k, --keep-going              Show all matching results at a given offset, not just the first one\\n\")\n\tfd.write(\"\\t-q, --quiet                   Supress output to stdout\\n\")\n\tfd.write(\"\\t-v, --verbose                 Be verbose (specify twice for very verbose)\\n\")\n\tfd.write(\"\\t-u, --update                  Update magic signature files\\n\")\n\tfd.write(\"\\t-h, --help                    Show help output\\n\")\n\tfd.write(\"\\n\")\n\n\tif fd == sys.stderr:\n\t\tsys.exit(1)\n\telse:\n\t\tsys.exit(0)\n\ndef main():\n\tMIN_ARGC = 2\n\talign = 1\n\toffset = 0\n\tlength = 0\n\tquiet = False\n\tpre_filter = True\n\tverbose = 0\n\tlog_file = None\n\tshow_invalid = False\n\tshort_sig = True\n\tcustom_signature = None\n\tdelay_extraction = False\n\textract_rules_file = None\n\textract_from_config = False\n\tcleanup_after_extract = False\n\tmagic_flags = binwalk.magic.MAGIC_NONE\n\toptions = []\n\tmagic_files = []\n\ttarget_files = []\n\tgreps = []\n\tincludes = []\n\texcludes = []\n\tsearches = []\n\textracts = []\n\n\tconfig = binwalk.Config()\n\n\tshort_options = \"aACdhkeqruvPIf:o:l:b:i:x:y:D:m:R:g:\"\n\tlong_options = [\n\t\t\t\"rm\",\n\t\t\t\"all\",\n\t\t\t\"help\", \n\t\t\t\"quiet\", \n\t\t\t\"verbose\",\n\t\t\t\"opcodes\",\n\t\t\t\"cast\",\n\t\t\t\"update\",\n\t\t\t\"keep-going\",\n\t\t\t\"show-invalid\",\n\t\t\t\"profile\",\n\t\t\t\"delay\",\n\t\t\t\"file=\", \n\t\t\t\"offset=\", \n\t\t\t\"length=\", \n\t\t\t\"align=\",\n\t\t\t\"include=\",\n\t\t\t\"exclude=\",\n\t\t\t\"extract=\",\n\t\t\t\"search=\",\n\t\t\t\"dd=\",\n\t\t\t\"grep=\",\n\t\t\t\"magic=\",\n\t\t\t\"raw-bytes=\",\n\t]\n\n\t# Require at least one argument (the target file)\n\tif len(sys.argv) < MIN_ARGC:\n\t\tusage(sys.stderr)\n\n\ttry:\n\t\topts, args = GetOpt(sys.argv[1:], short_options, long_options)\n\texcept GetoptError, e:\n\t\tsys.stderr.write(\"%s\\n\" % str(e))\n\t\tusage(sys.stderr)\n\n\tfor opt, arg in opts:\n\t\tif opt in (\"-h\", \"--help\"):\n\t\t\tusage(sys.stdout)\n\t\telif opt in (\"-d\", \"--delay\"):\n\t\t\tdelay_extraction = True\n\t\telif opt in (\"-f\", \"--file\"):\n\t\t\tlog_file = arg\n\t\telif opt in (\"-q\", \"--quiet\"):\n\t\t\tquiet = True\n\t\telif opt in (\"-v\", \"--verbose\"):\n\t\t\tverbose += 1\n\t\telif opt in (\"-o\", \"--offset\"):\n\t\t\toffset = str2int(arg)\n\t\telif opt in (\"-l\", \"--length\"):\n\t\t\tlength = str2int(arg)\n\t\telif opt in (\"-b\", \"--align\"):\n\t\t\talign = str2int(arg)\n\t\telif opt in (\"-i\", \"--include\"):\n\t\t\tincludes.append(arg)\n\t\telif opt in (\"-y\", \"--search\"):\n\t\t\tsearches.append(arg)\n\t\telif opt in (\"-x\", \"--exclude\"):\n\t\t\texcludes.append(arg)\n\t\telif opt in (\"-D\", \"--dd\"):\n\t\t\textracts.append(arg)\n\t\telif opt in (\"-g\", \"--grep\"):\n\t\t\tgreps.append(arg)\n\t\telif opt in (\"-e\", \"--extract\"):\n\t\t\tif arg:\n\t\t\t\textract_rules_file = arg\n\t\t\telse:\n\t\t\t\textract_from_config = True\n\t\telif opt in (\"-r\", \"--rm\"):\n\t\t\tcleanup_after_extract = True\n\t\telif opt in (\"-m\", \"--magic\"):\n\t\t\tmagic_files.append(arg)\n\t\telif opt in (\"-a\", \"--all\"):\n\t\t\tshort_sig = False\n\t\telif opt in (\"-k\", \"--keep-going\"):\n\t\t\tmagic_flags |= binwalk.magic.MAGIC_CONTINUE\n\t\telif opt in (\"-I\", \"--show-invalid\"):\n\t\t\tshow_invalid = True\n\n\t\telif opt in (\"-A\", \"--opcodes\"):\n\t\t\t# Check every single offset\n\t\t\talign = 1\n\t\t\t# Don't filter out short signatures as some opcode sigs are only 2 bytes\n\t\t\tshort_sig = False\n\t\t\t# Load user file first so its signatures take precedence\n\t\t\tmagic_files.append(config.paths['user'][config.BINARCH_MAGIC_FILE])\n\t\t\tmagic_files.append(config.paths['system'][config.BINARCH_MAGIC_FILE])\n\t\telif opt in (\"-C\", \"--cast\"):\n\t\t\t# Check every single offset\n\t\t\talign = 1\n\t\t\t# Don't stop at the first match (everything matches everything in this scan)\n\t\t\tmagic_flags |= binwalk.magic.MAGIC_CONTINUE\n\t\t\t# Disable all pre filtering; we want to check everything for this scan\n\t\t\tpre_filter = False\n\t\t\t# Don't filter shot signatures, or else some casts won't be displayed\n\t\t\tshort_sig = False\n\t\t\t# Load user file first so its signatures take precedence\n\t\t\tmagic_files.append(config.paths['user'][config.BINCAST_MAGIC_FILE])\n\t\t\tmagic_files.append(config.paths['system'][config.BINCAST_MAGIC_FILE])\n\t\telif opt in (\"-R\", \"--raw-bytes\"):\n\t\t\t# Disable short signature filtering, as the supplied string may be short\n\t\t\tshort_sig = False\n\t\t\tcustom_signature = arg\n\t\telif opt in (\"-u\", \"--update\"):\n\t\t\ttry:\n\t\t\t\tsys.stdout.write(\"Updating signatures...\")\n\t\t\t\tsys.stdout.flush()\n\n\t\t\t\tbinwalk.Update().update()\n\n\t\t\t\tsys.stdout.write(\"done.\\n\")\n\t\t\t\tsys.exit(0)\n\t\t\texcept Exception, e:\n\t\t\t\tif 'Permission denied' in str(e):\n\t\t\t\t\tsys.stderr.write(\"failed (permission denied). Check your user permissions, or run the update as root.\\n\")\n\t\t\t\telse:\n\t\t\t\t\tsys.stderr.write('\\n' + str(e) + '\\n')\n\t\t\t\tsys.exit(1)\n\t\t# The --profile option is handled prior to calling main()\n\t\telif opt not in ('-P', '--profile'):\n\t\t\tusage(sys.stderr)\n\n\t\t# Append the option and argument to the list of processed options\n\t\t# This is used later to determine which argv entries are file names\n\t\toptions.append(opt)\n\t\toptions.append(arg)\n\t\toptions.append(\"%s%s\" % (opt, arg))\n\t\toptions.append(\"%s=%s\" % (opt, arg))\n\n\t# Treat any command line options not processed by getopt as target file paths\n\tfor opt in sys.argv[1:]:\n\t\t#TODO: Do we really want to not process valid files that start with a '-'?\n\t\t#      This is probably OK, and ensures that no options are treated as target files.\n\t\tif opt not in options and not opt.startswith('-'):\n\t\t\ttarget_files.append(opt)\n\n\t# If more than one target file was specified, enable verbose mode; else, there is\n\t# nothing in the output to indicate which scan corresponds to which file.\n\tif len(target_files) > 1:\n\t\tverbose = True\n\n\t# Instantiate the Binwalk class\n\tbwalk = binwalk.Binwalk(flags=magic_flags, verbose=verbose, log=log_file, quiet=quiet)\n\n\t# If a custom signature was specified, create a temporary magic file containing the custom signature\n\t# and ensure that it is the only magic file that will be loaded when Binwalk.scan() is called.\n\tif custom_signature is not None:\n\t\tmagic_files = bwalk.parser.file_from_string(custom_signature)\n\n\t# Set any specified filters\n\tbwalk.filter.include(includes, exclusive=False)\n\tbwalk.filter.exclude(excludes)\n\tbwalk.filter.include(searches)\n\tbwalk.filter.grep(filters=greps)\n\n\t# Add any specified extract rules\n\tbwalk.extractor.add_rule(extracts)\n\n\t# If -e was specified, load the default extract rules\n\tif extract_from_config:\n\t\tbwalk.extractor.load_defaults()\n\n\t# If --extract was specified, load the specified extraction rules file\n\tif extract_rules_file is not None:\n\t\tbwalk.extractor.load_from_file(extract_rules_file)\n\n\t# Set the extractor cleanup value (True to clean up files, False to leave them on disk)\n\tbwalk.extractor.cleanup_extracted_files(cleanup_after_extract)\n\n\t# Enable delayed extraction, which will prevent supported file types from having trailing data when extracted\n\tbwalk.extractor.enable_delayed_extract(delay_extraction)\n\n\t# Load the magic file(s)\n\tbwalk.load_signatures(magic_files=magic_files, pre_filter_signatures=pre_filter, filter_short_signatures=short_sig)\n\t\n\t# Scan each target file\n\tfor target_file in target_files:\n\t\tbwalk.display.header(target_file)\n\n\t\t# Start the display_status function as a daemon thread\n\t\tt = Thread(target=display_status, args=(bwalk,))\n\t\tt.setDaemon(True)\n\t\tt.start()\n\n\t\t# Catch keyboard interrupts so that we can properly clean up after the scan\n\t\ttry:\n\t\t\tbwalk.scan(target_file, \n\t\t\t\toffset=offset, \n\t\t\t\tlength=length, \n\t\t\t\talign=align,\n\t\t\t\tshow_invalid_results=show_invalid, \n\t\t\t\tcallback=bwalk.display.results)\n\t\texcept KeyboardInterrupt:\n\t\t\tpass\n\n\t\tbwalk.display.footer()\n\n\t# Be sure to drink your ovaltine.\n\t# And also to clean up any temporary magic files.\n\tbwalk.cleanup()\n\ntry:\n\t# Special options for profiling the code. For debug use only.\n\tif '--profile' in sys.argv or '-P' in sys.argv:\n\t\timport cProfile\n\t\tcProfile.run('main()')\n\telse:\n\t\tmain()\nexcept KeyboardInterrupt:\n\tpass\n\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/__init__.py",
    "content": "import os\nimport magic\nfrom config import *\nfrom update import *\nfrom filter import *\nfrom parser import *\nfrom smartsig import *\nfrom extractor import *\nfrom prettyprint import *\nfrom common import file_size\n\nclass Binwalk:\n\t'''\n\tPrimary Binwalk class.\n\n\tInteresting class objects:\n\n\t\tself.filter        - An instance of the MagicFilter class.\n\t\tself.extractor     - An instance of the Extractor class.\n\t\tself.parser        - An instance of the MagicParser class.\n\t\tself.display       - An instance of the PrettyPrint class.\n\t\tself.magic_files   - A list of magic file path strings to use whenever the scan() method is invoked.\n\t\tself.scan_length   - The total number of bytes to be scanned.\n\t\tself.total_scanned - The number of bytes that have already been scanned.\n\t'''\n\n\t# Default libmagic flags. Basically disable anything we don't need in the name of speed.\n\tDEFAULT_FLAGS = magic.MAGIC_NO_CHECK_TEXT | magic.MAGIC_NO_CHECK_ENCODING | magic.MAGIC_NO_CHECK_APPTYPE | magic.MAGIC_NO_CHECK_TOKENS\n\n\t# The MAX_SIGNATURE_SIZE limits the amount of data available to a signature.\n\t# While most headers/signatures are far less than this value, some may reference \n\t# pointers in the header structure which may point well beyond the header itself.\n\t# Passing the entire remaining buffer to libmagic is resource intensive and will\n\t# significantly slow the scan; this value represents a reasonable buffer size to\n\t# pass to libmagic which will not drastically affect scan time.\n\tMAX_SIGNATURE_SIZE = 8092\n\n\t# Max number of bytes to process at one time. Everyone should have 50MB of memory, right?\n\tREAD_BLOCK_SIZE = 50 * 1024 * 1024\n\n\t# Minimum verbosity level at which to enable extractor verbosity.\n\tVERY_VERBOSE = 2\n\n\t# Scan every byte by default.\n\tDEFAULT_BYTE_ALIGNMENT = 1\n\n\tdef __init__(self, magic_files=[], flags=magic.MAGIC_NONE, log=None, quiet=False, verbose=0):\n\t\t'''\n\t\tClass constructor.\n\n\t\t@magic_files - A list of magic files to use.\n\t\t@flags       - Flags to pass to magic_open. [TODO: Might this be more appropriate as an argument to load_signaures?]\n\t\t@log         - Output PrettyPrint data to log file as well as to stdout.\n\t\t@quiet       - If set to True, supress PrettyPrint output to stdout.\n\t\t@verbose     - Verbosity level.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.flags = self.DEFAULT_FLAGS | flags\n\t\tself.magic_files = magic_files\n\t\tself.verbose = verbose\n\t\tself.total_scanned = 0\n\t\tself.scan_length = 0\n\t\tself.total_read = 0\n\t\tself.magic = None\n\t\tself.mfile = None\n\n\t\t# Instantiate the config class so we can access file/directory paths\n\t\tself.config = Config()\n\n\t\t# Use the system default magic file if no other was specified\n\t\tif not self.magic_files or self.magic_files is None:\n\t\t\t# Append the user's magic file first so that those signatures take precedence\n\t\t\tself.magic_files = [\n\t\t\t\t\tself.config.paths['user'][self.config.BINWALK_MAGIC_FILE],\n\t\t\t\t\tself.config.paths['system'][self.config.BINWALK_MAGIC_FILE],\n\t\t\t]\n\n\n\t\t# Only set the extractor verbosity if told to be very verbose\n\t\tif self.verbose >= self.VERY_VERBOSE:\n\t\t\textractor_verbose = True\n\t\telse:\n\t\t\textractor_verbose = False\n\n\t\t# Create an instance of the PrettyPrint class, which can be used to print results to screen/file.\n\t\tself.display = PrettyPrint(log=log, quiet=quiet, verbose=verbose, bwalk=self)\n\n\t\t# Create MagicFilter and Extractor class instances. These can be used to:\n\t\t#\n\t\t#\to Create include/exclude filters\n\t\t#\to Specify file extraction rules to be applied during a scan\n\t\t#\n\t\tself.filter = MagicFilter()\n\t\tself.extractor = Extractor(verbose=extractor_verbose)\n\t\t\n\t\t# Create SmartSignature and MagicParser class instances. These are mostly for internal use.\n\t\tself.smart = SmartSignature(self.filter)\n\t\tself.parser = MagicParser(self.filter, self.smart)\n\n\tdef __del__(self):\n\t\t'''\n\t\tClass deconstructor.\n\t\t'''\n\t\tself.cleanup()\n\n\tdef cleanup(self):\n\t\t'''\n\t\tCleanup any temporary files generated by the internal instance of MagicParser.\n\n\t\tReturns None.\n\t\t'''\n\t\ttry:\n\t\t\tself.parser.cleanup()\n\t\texcept:\n\t\t\tpass\n\n\tdef load_signatures(self, magic_files=[], pre_filter_signatures=True, filter_short_signatures=True):\n\t\t'''\n\t\tLoad signatures from magic file(s).\n\t\tCalled automatically by Binwalk.scan() with all defaults, if not already called manually.\n\n\t\t@magic_files\t\t\t- A list of magic files to use (default: self.magic_files).\n\t\t@pre_filter_signatures \t\t- Set to False to disable pre-filtering of signatures before invoking libmagic.\n\t\t@filter_short_signatures\t- Set to True to include signatures with short (<= 2 byte) magic strings.\n\t\n\t\tReturns None.\t\n\t\t'''\n\t\t# Disable pre filtering in the smart signature class instance.\n\t\t# This is also checked by Binwalk.scan() before performing pre-filtering.\n\t\tself.smart.pre_filter = pre_filter_signatures\n\n\t\t# The magic files specified here override any already set\n\t\tif magic_files and magic_files is not None:\n\t\t\tself.magic_files = magic_files\n\n\t\t# Parse the magic file(s) and initialize libmagic\n\t\tself.mfile = self.parser.parse(self.magic_files, filter_short_signatures=filter_short_signatures, pre_filter_signatures=pre_filter_signatures)\n\t\tself.magic = magic.open(self.flags)\n\t\tself.magic.load(self.mfile)\n\n\tdef scan(self, target_file, offset=0, length=0, align=DEFAULT_BYTE_ALIGNMENT, show_invalid_results=False, callback=None):\n\t\t'''\n\t\tPerforms a Binwalk scan on the target file.\n\n\t\t@target_file \t\t\t- File to scan.\n\t\t@offset      \t\t\t- Starting offset at which to start the scan.\n\t\t@length      \t\t\t- Number of bytes to scan.\n\t\t@align       \t\t\t- Look for signatures every align bytes.\n\t\t@show_invalid_results\t\t- Set to True to display invalid results.\n\t\t@callback    \t\t\t- Callback function to be invoked when matches are found.\n\n\t\tThe callback function is passed two arguments: a list of result dictionaries containing the scan results\n\t\t(one result per dict), and the offset at which those results were identified. Example callback function:\n\n\t\t\tdef my_callback(offset, results):\n\t\t\t\tprint \"Found %d results at offset %d:\" % (len(results), offset)\n\t\t\t\tfor result in results:\n\t\t\t\t\tprint \"\\t%s\" % result['description']\n\n\t\t\tbinwalk.Binwalk(callback=my_callback).scan(\"firmware.bin\")\n\n\t\tUpon completion, the scan method returns a sorted list of tuples containing a list of results dictionaries\n\t\tand the offsets at which those results were identified:\n\n\t\t\tscan_items = [\n\t\t\t\t\t(0, [{description : \"LZMA compressed data...\"}]),\n\t\t\t\t\t(112, [{description : \"gzip compressed data...\"}])\n\t\t\t]\n\n\t\tSee SmartSignature.parse for a more detailed description of the results dictionary structure.\n\t\t'''\n\t\tscan_results = {}\n\t\tself.total_read = 0\n\t\tself.total_scanned = 0\n\t\tself.scan_length = length\n\t\tself.filter.show_invalid_results = show_invalid_results\n\n\t\t# Load the default signatures if self.load_signatures has not already been invoked\n\t\tif self.magic is None:\n\t\t\tself.load_signatures()\n\n\t\t# Get a local copy of the signature sets generated by self.parser.build_signature_set.\n\t\t# This is accessed heavily throughout the scan, and there is less overhead for accessing local variables in Python.\n\t\tsignature_set = self.parser.build_signature_set()\n\n\t\t# Need the total size of the target file, even if we aren't scanning the whole thing\n\t\tfsize = file_size(target_file)\n\n\t\t# Open the target file and seek to the specified start offset\n\t\tfd = open(target_file)\n\t\tfd.seek(offset)\n\t\t\n\t\t# If no length was specified, make the length the size of the target file minus the starting offset\n\t\tif self.scan_length == 0:\n\t\t\tself.scan_length = fsize - offset\n\t\t# Sanity check on the byte alignment; default to 1\n\t\tif align <= 0:\n\t\t\talign = 1\n\n\t\t# Main loop, scan through all the data\n\t\twhile True:\n\t\t\ti = 0\n\n\t\t\t# Read in the next block of data from the target file and make sure it's valid\n\t\t\t(data, dlen) = self._read_block(fd)\n\t\t\tif data is None or dlen == 0:\n\t\t\t\tbreak\n\n\t\t\t# The total number of bytes scanned could be bigger than the total number\n\t\t\t# of bytes read from the file under the following circumstances:\n\t\t\t#\n\t\t\t#\to The previous dlen was not a multiple of align\n\t\t\t#\to A previous result specified a jump offset that was beyond the end of the\n\t\t\t#\t  then current data block\n\t\t\t#\n\t\t\t# If this is the case, we need to index into this data block appropriately in order to \n\t\t\t# resume the scan from the appropriate offset, and adjust dlen accordingly.\n\t\t\tbufindex = self.total_scanned - self.total_read\n\t\t\tif bufindex > 0:\n\t\t\t\t# If the total_scanned > total_read, then the total_scanned offset is in a subsequent block.\n\t\t\t\t# Set i to bufindex, which will cause i to be greater than dlen and this block will be skipped.\n\t\t\t\ti = bufindex\n\t\t\telif bufindex < 0:\n\t\t\t\t# If the total_scanned offset is less than total_read, then the total_scanned offset is\n\t\t\t\t# somewhere inside this block. Set i to index into the block appropriately.\n\t\t\t\ti = dlen + bufindex\n\t\t\telse:\n\t\t\t\t# If the total_scanned offset ends at the end of this block, don't scan any of this block\n\t\t\t\ti = dlen\n\n\t\t\t# Scan through each block of data looking for signatures\n\t\t\twhile i < dlen:\n\t\t\t\tsmart = {}\n\t\t\t\tresults = []\n\t\t\t\tresults_offset = -1\n\t\t\t\tpre_filter_ok = False\n\t\t\t\tsmart_jump_done = False\n\n\t\t\t\t# Pre-filter data by checking to see if the parser thinks this might be a valid match.\n\t\t\t\t# This eliminates unnecessary calls into libmagic, which are very expensive.\n\t\t\t\t#\n\t\t\t\t# Ideally, this should be done in the MagicParser class, but function calls are expensive.\n\t\t\t\t# Doing it here greatly decreases the scan time.\n\t\t\t\tif self.smart.pre_filter:\n\t\t\t\t\tfor (sig_offset, sigset) in signature_set:\n                        \t\t\tif data[i+sig_offset:i+sig_offset+self.parser.MATCH_INDEX_SIZE] in sigset:\n                                \t\t\tpre_filter_ok = True\n\t\t\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tpre_filter_ok = True\n\n\t\t\t\tif pre_filter_ok:\n\t\t\t\t\t# Pass the data to libmagic, and split out multiple results into a list\n\t\t\t\t\tfor magic_result in self.parser.split(self.magic.buffer(data[i:i+self.MAX_SIGNATURE_SIZE])):\n\n\t\t\t\t\t\t# Some file names are not NULL byte terminated, but rather their length is\n\t\t\t\t\t\t# specified in a size field. To ensure these are not marked as invalid due to\n\t\t\t\t\t\t# non-printable characters existing in the file name, parse the filename(s) and\n\t\t\t\t\t\t# trim them to the specified filename length, if one was specified.\n\t\t\t\t\t\tmagic_result = self.smart._parse_raw_strings(magic_result)\n\n\t\t\t\t\t\t# Make sure this is a valid result before further processing\n\t\t\t\t\t\tif not self.filter.invalid(magic_result):\n\t\t\t\t\t\t\t# The smart filter parser returns a dictionary of keyword values and the signature description.\n\t\t\t\t\t\t\tsmart = self.smart.parse(magic_result)\n\t\n\t\t\t\t\t\t\t# Validate the jump value and check if the response description should be displayed\n\t\t\t\t\t\t\tif smart['jump'] > -1 and self._should_display(smart['description']):\n\t\t\t\t\t\t\t\t# If multiple results are returned and one of them has smart['jump'] set to a non-zero value,\n\t\t\t\t\t\t\t\t# the calculated results offset will be wrong since i will have been incremented. Only set the\n\t\t\t\t\t\t\t\t# results_offset value when the first match is encountered.\n\t\t\t\t\t\t\t\tif results_offset < 0:\n\t\t\t\t\t\t\t\t\tresults_offset = offset + smart['adjust'] + self.total_scanned\n\n\t\t\t\t\t\t\t\t# Double check to make sure the smart['adjust'] value is sane. \n\t\t\t\t\t\t\t\t# If it makes results_offset negative, then it is not sane.\n\t\t\t\t\t\t\t\tif results_offset >= 0:\n\t\t\t\t\t\t\t\t\t# Extract the result, if it matches one of the extract rules and is not a delayed extract.\n\t\t\t\t\t\t\t\t\tif self.extractor.enabled and not (self.extractor.delayed and smart['delay']):\n\t\t\t\t\t\t\t\t\t\t# If the signature did not specify a size, extract to the end of the file.\n\t\t\t\t\t\t\t\t\t\tif smart['size'] == 0:\n\t\t\t\t\t\t\t\t\t\t\tsmart['size'] = fsize-results_offset\n\n\t\t\t\t\t\t\t\t\t\tsmart['extract'] = self.extractor.extract(\tresults_offset, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsmart['description'], \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttarget_file, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsmart['size'], \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tname=smart['name'])\n\n\t\t\t\t\t\t\t\t\t# This appears to be a valid result, so append it to the results list.\n\t\t\t\t\t\t\t\t\tresults.append(smart)\n\n\t\t\t\t\t\t\t# Jump to the offset specified by jump. Only do this once, so that if multiple results\n\t\t\t\t\t\t\t# are returned each of which specify a jump offset, only the first will be honored.\n\t\t\t\t\t\t\tif smart['jump'] > 0 and not smart_jump_done:\n\t\t\t\t\t\t\t\t# Once a jump offset has been honored, we need to start scanning every byte since the\n\t\t\t\t\t\t\t\t# jump offset may have thrown off the original alignment. In terms of speed this is fine,\n\t\t\t\t\t\t\t\t# since the jump offset usually saves more time anyway. If this is not what the user\n\t\t\t\t\t\t\t\t# wanted/intended, disabling pre filtering will disable jump offset processing completely.\n\t\t\t\t\t\t\t\talign = self.DEFAULT_BYTE_ALIGNMENT\n\t\t\t\t\t\t\t\tsmart_jump_done = True\n\t\t\t\t\t\t\t\ti += (smart['jump'] - align)\n\t\t\t\t\t\t\t\tself.total_scanned += (smart['jump'] - align)\n\n\t\t\t\t# Did we find any valid results?\n\t\t\t\tif results_offset >= 0:\n\t\t\t\t\tscan_results[results_offset] = results\n\t\t\t\t\t\n\t\t\t\t\tif callback is not None:\n\t\t\t\t\t\tcallback(results_offset, results)\n\n\t\t\t\t# Track the number of bytes scanned in this block, and the total number of bytes scanned.\t\n\t\t\t\ti += align\n\t\t\t\tself.total_scanned += align\n\n\t\t# Sort the results before returning them\n\t\tscan_items = scan_results.items()\n\t\tscan_items.sort()\n\n\t\t# Do delayed extraction, if specified.\n\t\tif self.extractor.enabled and self.extractor.delayed:\n\t\t\tscan_items = self.extractor.delayed_extract(scan_items, target_file, fsize)\n\n\t\treturn scan_items\n\n\tdef _should_display(self, data):\n\t\t'''\n\t\tDetermines if a result string should be displayed to the user or not.\n\t\t\n\t\t@data - Display string.\n\n\t\tReturns True if the string should be displayed.\n\t\tReturns False if the string should not be displayed.\n\t\t'''\n\t\treturn (data and data is not None and not self.filter.invalid(data) and self.filter.filter(data) != self.filter.FILTER_EXCLUDE)\n\n\tdef _read_block(self, fd):\n\t\t'''\n\t\tReads in a block of data from the target file.\n\n\t\t@fd - File object for the target file.\n\n\t\tReturns a tuple of (file block data, block data length).\n\t\t'''\n\t\tdlen = 0\n\t\tdata = None\n\t\t# Read in READ_BLOCK_SIZE plus MAX_SIGNATURE_SIZE bytes, but return a max dlen value\n\t\t# of READ_BLOCK_SIZE. This ensures that there is a MAX_SIGNATURE_SIZE buffer at the\n\t\t# end of the returned data in case a signature is found at or near data[dlen].\n\t\trlen = self.READ_BLOCK_SIZE + self.MAX_SIGNATURE_SIZE\n\n\t\tif self.total_read < self.scan_length:\n\t\t\t\n\t\t\tdata = fd.read(rlen)\n\t\t\t\n\t\t\tif data and data is not None:\n\t\t\t\t# Get the actual length of the read in data\n\t\t\t\tdlen = len(data)\n\n\t\t\t\t# If we've read in more data than the scan length, truncate the dlen value\n\t\t\t\tif (self.total_read + dlen) >= self.scan_length:\n\t\t\t\t\tdlen = self.scan_length - self.total_read\n\t\t\t\t# If dlen is the expected rlen size, it should be set to READ_BLOCK_SIZE\n\t\t\t\telif dlen == rlen:\n\t\t\t\t\tdlen = self.READ_BLOCK_SIZE\n\n\t\t\t\t# Increment self.total_read to reflect the amount of data that has been read\n\t\t\t\t# for processing (actual read size is larger of course, due to the MAX_SIGNATURE_SIZE\n\t\t\t\t# buffer of data at the end of each block).\n\t\t\t\tself.total_read += dlen\n\t\t\t\t# Seek to the self.total_read offset so the next read can pick up where this one left off\n\t\t\t\tfd.seek(self.total_read)\n\n\t\treturn (data, dlen)\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/common.py",
    "content": "# Common functions.\nimport os\nimport re\n\ndef file_size(filename):\n\t'''\n\tObtains the size of a given file.\n\n\t@filename - Path to the file.\n\n\tReturns the size of the file.\n\t'''\n\t# Using open/lseek works on both regular files and block devices\n\tfd = os.open(filename, os.O_RDONLY)\n\ttry:\n\t\treturn os.lseek(fd, 0, os.SEEK_END)\n\texcept Exception, e:\n\t\traise Exception(\"file_size failed to obtain the size of '%s': %s\" % (filename, str(e)))\n\tfinally:\n\t\tos.close(fd)\n\ndef str2int(string):\n\t'''\n\tAttempts to convert string to a base 10 integer; if that fails, then base 16.\n\n\t@string - String to convert to an integer.\n\n\tReturns the integer value on success.\n\tThrows an exception if the string cannot be converted into either a base 10 or base 16 integer value.\n\t'''\n\ttry:\n\t\treturn int(string)\n\texcept:\n\t\treturn int(string, 16)\n\ndef strip_quoted_strings(string):\n\t'''\n\tStrips out data in between double quotes.\n\t\n\t@string - String to strip.\n\n\tReturns a sanitized string.\n\t'''\n\t# This regex removes all quoted data from string.\n\t# Note that this removes everything in between the first and last double quote.\n\t# This is intentional, as printed (and quoted) strings from a target file may contain \n\t# double quotes, and this function should ignore those. However, it also means that any \n\t# data between two quoted strings (ex: '\"quote 1\" you won't see me \"quote 2\"') will also be stripped.\n\treturn re.sub(r'\\\"(.*)\\\"', \"\", string)\n\ndef get_quoted_strings(string):\n\t'''\n\tReturns a string comprised of all data in between double quotes.\n\n\t@string - String to get quoted data from.\n\n\tReturns a string of quoted data on success.\n\tReturns a blank string if no quoted data is present.\n\t'''\n\ttry:\n\t\t# This regex grabs all quoted data from string.\n\t\t# Note that this gets everything in between the first and last double quote.\n\t\t# This is intentional, as printed (and quoted) strings from a target file may contain \n\t\t# double quotes, and this function should ignore those. However, it also means that any \n\t\t# data between two quoted strings (ex: '\"quote 1\" non-quoted data \"quote 2\"') will also be included.\n\t\treturn re.findall(r'\\\"(.*)\\\"', string)[0]\n\texcept:\n\t\treturn ''\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/config/extract.conf",
    "content": "#################################################################################################################\n# Default extract rules loaded when --extract is specified.\n# \n# <case-insensitive unique string from binwalk output text>:<desired file extension>:<command to execute>\n#\n# Note that %e is a place holder for the extracted file name.\n#################################################################################################################\n\n# Assumes these utilities are installed in $PATH.\ngzip compressed data:gz:gzip -d -f '%e'\nlzma compressed data:7z:7zr e -y '%e'\nbzip2 compressed data:bz2:bzip2 -d -f '%e'\nzip archive data:zip:jar xf '%e' # jar does a better job of unzipping than unzip does...\nposix tar archive:tar:tar xvf '%e'\n\n# These assume the firmware-mod-kit is installed to /opt/firmware-mod-kit.\n# If not, change the file paths appropriately.\nsquashfs filesystem:squashfs:/opt/firmware-mod-kit/trunk/unsquashfs_all.sh '%e'\njffs2 filesystem:jffs2:/opt/firmware-mod-kit/trunk/src/jffs2/unjffs2 '%e' # requires root\ncpio archive:cpio:/opt/firmware-mod-kit/trunk/uncpio.sh '%e'\n\n# Extract, but don't run anything\next2 filesystem:ext2\nromfs filesystem:romfs\ncramfs filesystem:cramfs\nprivate key:key\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/config.py",
    "content": "import os\n\nclass Config:\n\t'''\n\tBinwalk configuration class, used for accessing user and system file paths.\n\t\n\tAfter instatiating the class, file paths can be accessed via the self.paths dictionary.\n\tSystem file paths are listed under the 'system' key, user file paths under the 'user' key.\n\n\tFor example, to get the path to both the user and system binwalk magic files:\n\n\t\tfrom binwalk import Config\n\n\t\tconf = Config()\n\t\tuser_binwalk_file = conf.paths['user'][conf.BINWALK_MAGIC_FILE]\n\t\tsystem_binwalk_file = conf.paths['system'][conf.BINWALK_MAGIC_FILE]\n\n\tThere is also an instance of this class available via the Binwalk.config object:\n\n\t\timport binwalk\n\n\t\tbw = binwalk.Binwalk()\n\n\t\tuser_binwalk_file = bw.config.paths['user'][conf.BINWALK_MAGIC_FILE]\n\t\tsystem_binwalk_file = bw.config.paths['system'][conf.BINWALK_MAGIC_FILE]\n\n\tValid file names under both the 'user' and 'system' keys are as follows:\n\n\t\to BINWALK_MAGIC_FILE  - Path to the default binwalk magic file.\n\t\to BINCAST_MAGIC_FILE  - Path to the bincast magic file (used when -C is specified with the command line binwalk script)\n\t\to BINARCH_MAGIC_FILE  - Path to the binarch magic file (used when -A is specified with the command line binwalk script)\n\t\to EXTRACT_FILE        - Path to the extract configuration file (used when -e is specified with the command line binwalk script)\n\t'''\n\t# Release version\n\tVERSION = \"1.0\"\n\n\t# Sub directories\n\tBINWALK_USER_DIR = \".binwalk\"\n\tBINWALK_MAGIC_DIR = \"magic\"\n\tBINWALK_CONFIG_DIR = \"config\"\n\n\t# File names\n\tEXTRACT_FILE = \"extract.conf\"\n\tBINWALK_MAGIC_FILE = \"binwalk\"\n\tBINCAST_MAGIC_FILE = \"bincast\"\n\tBINARCH_MAGIC_FILE = \"binarch\"\n\n\tdef __init__(self):\n\t\t'''\n\t\tClass constructor. Enumerates file paths and populates self.paths.\n\t\t'''\n\t\t# Path to the user binwalk directory\n\t\tself.user_dir = self._get_user_dir()\n\t\t# Path to the system wide binwalk directory\n\t\tself.system_dir = self._get_system_dir()\n\n\t\t# Dictionary of all absolute user/system file paths\n\t\tself.paths = {\n\t\t\t'user'\t\t: {},\n\t\t\t'system'\t: {},\n\t\t}\n\n\t\t# Build the paths to all user-specific files\n\t\tself.paths['user'][self.BINWALK_MAGIC_FILE] = self._user_file(self.BINWALK_MAGIC_DIR, self.BINWALK_MAGIC_FILE)\n\t\tself.paths['user'][self.BINCAST_MAGIC_FILE] = self._user_file(self.BINWALK_MAGIC_DIR, self.BINCAST_MAGIC_FILE)\n\t\tself.paths['user'][self.BINARCH_MAGIC_FILE] = self._user_file(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE)\n\t\tself.paths['user'][self.EXTRACT_FILE] = self._user_file(self.BINWALK_CONFIG_DIR, self.EXTRACT_FILE)\n\n\t\t# Build the paths to all system-wide files\n\t\tself.paths['system'][self.BINWALK_MAGIC_FILE] = self._system_file(self.BINWALK_MAGIC_DIR, self.BINWALK_MAGIC_FILE)\n\t\tself.paths['system'][self.BINCAST_MAGIC_FILE] = self._system_file(self.BINWALK_MAGIC_DIR, self.BINCAST_MAGIC_FILE)\n\t\tself.paths['system'][self.BINARCH_MAGIC_FILE] = self._system_file(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE)\n\t\tself.paths['system'][self.EXTRACT_FILE] = self._system_file(self.BINWALK_CONFIG_DIR, self.EXTRACT_FILE)\n\t\n\tdef _get_system_dir(self):\n\t\t'''\n\t\tFind the directory where the binwalk module is installed on the system.\n\t\t'''\n\t\ttry:\n\t\t\troot = __file__\n\t\t\tif os.path.islink(root):\n\t\t\t\troot = os.path.realpath(root)\n\t\t\treturn os.path.dirname(os.path.abspath(root))\n\t\texcept:\n\t\t\treturn ''\n\n\tdef _get_user_dir(self):\n\t\t'''\n\t\tGet the user's home directory.\n\t\t'''\n\t\ttry:\n\t\t\t# This should work in both Windows and Unix environments\n\t\t\treturn os.getenv('USERPROFILE') or os.getenv('HOME')\n\t\texcept:\n\t\t\treturn ''\n\n\tdef _file_path(self, dirname, filename):\n\t\t'''\n\t\tBuilds an absolute path and creates the directory and file if they don't already exist.\n\n\t\t@dirname  - Directory path.\n\t\t@filename - File name.\n\t\t\n\t\tReturns a full path of 'dirname/filename'.\n\t\t'''\n\t\tif not os.path.exists(dirname):\n\t\t\ttry:\n\t\t\t\tos.makedirs(dirname)\n\t\t\texcept:\n\t\t\t\tpass\n\t\t\n\t\tfpath = os.path.join(dirname, filename)\n\n\t\tif not os.path.exists(fpath):\n\t\t\ttry:\n\t\t\t\topen(fpath, \"w\").close()\n\t\t\texcept:\n\t\t\t\tpass\n\n\t\treturn fpath\n\n\tdef _user_file(self, subdir, basename):\n\t\t'''\n\t\tGets the full path to the 'subdir/basename' file in the user binwalk directory.\n\n\t\t@subdir   - Subdirectory inside the user binwalk directory.\n\t\t@basename - File name inside the subdirectory.\n\n\t\tReturns the full path to the 'subdir/basename' file.\n\t\t'''\n\t\treturn self._file_path(os.path.join(self.user_dir, self.BINWALK_USER_DIR, subdir), basename)\n\n\tdef _system_file(self, subdir, basename):\n\t\t'''\n\t\tGets the full path to the 'subdir/basename' file in the system binwalk directory.\n\t\t\n\t\t@subdir   - Subdirectory inside the system binwalk directory.\n\t\t@basename - File name inside the subdirectory.\n\t\t\n\t\tReturns the full path to the 'subdir/basename' file.\n\t\t'''\n\t\treturn self._file_path(os.path.join(self.system_dir, subdir), basename)\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/extractor.py",
    "content": "import os\nimport sys\nimport shlex\nimport tempfile\nimport subprocess\nfrom config import *\nfrom common import file_size\n\nclass Extractor:\n\t'''\n\tExtractor class, responsible for extracting files from the target file and executing external applications, if requested.\n\tAn instance of this class is accessible via the Binwalk.extractor object.\n\n\tExample usage:\n\n\t\timport binwalk\n\t\t\n\t\tbw = binwalk.Binwalk()\n\n\t\t# Create extraction rules for scan results containing the string 'gzip compressed data' and 'filesystem'.\n\t\t# The former will be saved to disk with a file extension of 'gz' and the command 'gunzip <file name on disk>' will be executed (note the %e placeholder).\n\t\t# The latter will be saved to disk with a file extension of 'fs' and no command will be executed.\n\t\t# These rules will take precedence over subsequent rules with the same match string.\n\t\tbw.extractor.add_rule(['gzip compressed data:gz:gunzip %e', 'filesystem:fs'])\n\n\t\t# Load the extraction rules from the default extract.conf file(s).\n\t\tbw.extractor.load_defaults()\n\n\t\t# Run the binwalk scan.\n\t\tbw.scan('firmware.bin')\n\t\t\n\t'''\n\t# Extract rules are delimited with a colon.\n\t# <case insensitive matching string>:<file extension>[:<command to run>]\n\tRULE_DELIM = ':'\n\n\t# Comments in the extract.conf files start with a pound\n\tCOMMENT_DELIM ='#'\n\n\t# Place holder for the extracted file name in the command \n\tFILE_NAME_PLACEHOLDER = '%e'\n\n\tdef __init__(self, verbose=False):\n\t\t'''\n\t\tClass constructor.\n\t\n\t\t@verbose - Set to True to display the output from any executed external applications.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.config = Config()\n\t\tself.enabled = False\n\t\tself.delayed = False\n\t\tself.verbose = verbose\n\t\tself.extract_rules = {}\n\t\tself.remove_after_execute = False\n\n\tdef add_rule(self, rule):\n\t\t'''\n\t\tAdds a set of rules to the extraction rule list.\n\n\t\t@rule - Rule string, or list of rule strings, in the format <case insensitive matching string>:<file extension>[:<command to run>]\n\n\t\tReturns None.\n\t\t'''\n\t\tr = {\n\t\t\t'extension'\t: '',\n\t\t\t'cmd'\t\t: ''\n\t\t}\n\n\t\tif type(rule) != type([]):\n\t\t\trules = [rule]\n\t\telse:\n\t\t\trules = rule\n\n\t\tfor rule in rules:\n\t\t\tr['cmd'] = ''\n\t\t\tr['extension'] = ''\n\n\t\t\ttry:\n\t\t\t\tvalues = self._parse_rule(rule)\n\t\t\t\tmatch = values[0].lower()\n\t\t\t\tr['extension'] = values[1]\n\t\t\t\tr['cmd'] = values[2]\n\t\t\texcept:\n\t\t\t\tpass\n\n\t\t\t# Verify that the match string and file extension were retrieved.\n\t\t\t# Only add the rule if it is a new one (first come, first served).\n\t\t\tif match and r['extension'] and not self.extract_rules.has_key(match):\n\t\t\t\tself.extract_rules[match] = {}\n\t\t\t\tself.extract_rules[match]['cmd'] = r['cmd']\n\t\t\t\tself.extract_rules[match]['extension'] = r['extension']\n\t\t\t\t# Once any rule is added, set self.enabled to True\n\t\t\t\tself.enabled = True\n\n\tdef enable_delayed_extract(self, tf=None):\n\t\t'''\n\t\tEnables / disables the delayed extraction feature.\n\t\tThis feature ensures that certian supported file types will not contain extra data at the end of the\n\t\tfile when they are extracted, but also means that these files will not be extracted until the end of the scan.\n\n\t\t@tf - Set to True to enable, False to disable. \n\n\t\tReturns the current delayed extraction setting.\n\t\t'''\n\t\tif tf is not None:\n\t\t\tself.delayed = tf\n\t\treturn self.delayed\n\n\tdef load_from_file(self, fname):\n\t\t'''\n\t\tLoads extraction rules from the specified file.\n\n\t\t@fname - Path to the extraction rule file.\n\t\t\n\t\tReturns None.\n\t\t'''\n\t\ttry:\n\t\t\t# Process each line from the extract file, ignoring comments\n\t\t\tfor rule in open(fname).readlines():\n\t\t\t\tself.add_rule(rule.split(self.COMMENT_DELIM, 1)[0])\n\t\texcept Exception, e:\n\t\t\traise Exception(\"Extractor.load_from_file failed to load file '%s': %s\" % (fname, str(e)))\n\n\tdef load_defaults(self):\n\t\t'''\n\t\tLoads default extraction rules from the user and system extract.conf files.\n\n\t\tReturns None.\n\t\t'''\n\t\t# Load the user extract file first to ensure its rules take precedence.\n\t\textract_files = [\n\t\t\tself.config.paths['user'][self.config.EXTRACT_FILE],\n\t\t\tself.config.paths['system'][self.config.EXTRACT_FILE],\n\t\t]\n\n\t\tfor extract_file in extract_files:\n\t\t\ttry:\n\t\t\t\tself.load_from_file(extract_file)\n\t\t\texcept Exception, e:\n\t\t\t\tif self.verbose:\n\t\t\t\t\traise Exception(\"Extractor.load_defaults failed to load file '%s': %s\" % (extract_file, str(e)))\n\n\tdef cleanup_extracted_files(self, tf=None):\n\t\t'''\n\t\tSet the action to take after a file is extracted.\n\n\t\t@tf - If set to True, extracted files will be cleaned up after running a command against them.\n\t\t      If set to False, extracted files will not be cleaned up after running a command against them.\n\t\t      If set to None or not specified, the current setting will not be changed.\n\n\t\tReturns the current cleanup status (True/False).\n\t\t'''\n\t\tif tf is not None:\n\t\t\tself.remove_after_execute = tf\n\n\t\treturn self.remove_after_execute\n\t\n\tdef extract(self, offset, description, file_name, size, name=None):\n\t\t'''\n\t\tExtract an embedded file from the target file, if it matches an extract rule.\n\t\tCalled automatically by Binwalk.scan().\n\n\t\t@offset      - Offset inside the target file to begin the extraction.\n\t\t@description - Description of the embedded file to extract, as returned by libmagic.\n\t\t@file_name   - Path to the target file.\n\t\t@size        - Number of bytes to extract.\n\t\t@name        - Name to save the file as.\n\n\t\tReturns the name of the extracted file (blank string if nothing was extracted).\n\t\t'''\n\t\tcleanup_extracted_fname = True\n\n\t\trule = self._match(description)\n\t\tif rule is not None:\n\t\t\tfname = self._dd(file_name, offset, size, rule['extension'], output_file_name=name)\n\t\t\tif rule['cmd']:\n\n\t\t\t\t# Many extraction utilities will extract the file to a new file, just without\n\t\t\t\t# the file extension (i.e., myfile.7z => myfile). If the presumed resulting\n\t\t\t\t# file name already exists before executing the extract command, do not attempt \n\t\t\t\t# to clean it up even if its resulting file size is 0.\n\t\t\t\tif self.remove_after_execute:\n\t\t\t\t\textracted_fname = os.path.splitext(fname)[0]\n\t\t\t\t\tif os.path.exists(extracted_fname):\n\t\t\t\t\t\tcleanup_extracted_fname = False\n\n\t\t\t\t# Execute the specified command against the extracted file\n\t\t\t\tself._execute(rule['cmd'], fname)\n\n\t\t\t\t# Only clean up files if remove_after_execute was specified\t\t\t\t\n\t\t\t\tif self.remove_after_execute:\n\n\t\t\t\t\t# Remove the original file that we extracted\n\t\t\t\t\ttry:\n\t\t\t\t\t\tos.unlink(fname)\n\t\t\t\t\texcept:\n\t\t\t\t\t\tpass\n\n\t\t\t\t\t# If the command worked, assume it removed the file extension from the extracted file\n\n\t\t\t\t\t# If the extracted file name file exists and is empty, remove it\n\t\t\t\t\tif cleanup_extracted_fname and os.path.exists(extracted_fname) and file_size(extracted_fname) == 0:\n\t\t\t\t\t\ttry:\n\t\t\t\t\t\t\tos.unlink(extracted_fname)\n\t\t\t\t\t\texcept:\n\t\t\t\t\t\t\tpass\n\t\telse:\n\t\t\tfname = ''\n\n\t\treturn fname\n\n\tdef delayed_extract(self, results, file_name, size):\n\t\t'''\n\t\tPerforms a delayed extraction (see self.enable_delayed_extract).\n\t\tCalled internally by Binwalk.Scan().\n\n\t\t@results   - A list of dictionaries of all the scan results.\n\t\t@file_name - The path to the scanned file.\n\t\t@size      - The size of the scanned file.\n\n\t\tReturns an updated results list containing the names of the newly extracted files.\n\t\t'''\n\t\tindex = 0\n\t\tinfo_count = 0\n\t\tnresults = results\n\n\t\tfor (offset, infos) in results:\n\t\t\tinfo_count = 0\n\n\t\t\tfor info in infos:\n\t\t\t\tninfos = infos\n\n\t\t\t\tif info['delay']:\n\t\t\t\t\tend_offset = self._entry_offset(index, results, info['delay'])\n\t\t\t\t\tif end_offset == -1:\n\t\t\t\t\t\textract_size = size\n\t\t\t\t\telse:\n\t\t\t\t\t\textract_size = (end_offset - offset)\n\n\t\t\t\t\tninfos[info_count]['extract'] = self.extract(offset, info['description'], file_name, extract_size, info['name'])\n\t\t\t\t\tnresults[index] = (offset, ninfos)\n\n\t\t\t\tinfo_count += 1\n\n\t\t\tindex += 1\n\t\t\n\t\treturn nresults\n\n\tdef _entry_offset(self, index, entries, description):\n\t\t'''\n\t\tGets the offset of the first entry that matches the description.\n\n\t\t@index       - Index into the entries list to begin searching.\n\t\t@entries     - Dictionary of result entries.\n\t\t@description - Case insensitive description.\n\n\t\tReturns the offset, if a matching description is found.\n\t\tReturns -1 if a matching description is not found.\n\t\t'''\n\t\tdescription = description.lower()\n\n\t\tfor (offset, infos) in entries[index:]:\n\t\t\tfor info in infos:\n\t\t\t\tif info['description'].lower().startswith(description):\n\t\t\t\t\treturn offset\n\t\treturn -1\n\n\tdef _match(self, description):\n\t\t'''\n\t\tCheck to see if the provided description string matches an extract rule.\n\t\tCalled internally by self.extract().\n\n\t\t@description - Description string to check.\n\n\t\tReturns the associated rule dictionary if a match is found.\n\t\tReturns None if no match is found.\n\t\t'''\n\t\tdescription = description.lower()\n\n\t\tfor (m, rule) in self.extract_rules.iteritems():\n\t\t\tif m in description:\n\t\t\t\treturn rule\n\t\treturn None\n\n\tdef _parse_rule(self, rule):\n\t\t'''\n\t\tParses an extraction rule.\n\n\t\t@rule - Rule string.\n\n\t\tReturns an array of ['<case insensitive matching string>', '<file extension>', '<command to run>'].\n\t\t'''\n\t\treturn rule.strip().split(self.RULE_DELIM, 2)\n\n\tdef _dd(self, file_name, offset, size, extension, output_file_name=None):\n\t\t'''\n\t\tExtracts a file embedded inside the target file.\n\n\t\t@file_name        - Path to the target file.\n\t\t@offset           - Offset inside the target file where the embedded file begins.\n\t\t@size             - Number of bytes to extract.\n\t\t@extension        - The file exension to assign to the extracted file on disk.\n\t\t@output_file_name - The requested name of the output file.\n\n\t\tReturns the extracted file name.\n\t\t'''\n\t\t# Default extracted file name is <hex offset>.<extension>\n\t\taltname = \"%X.%s\" % (offset, extension)\n\t\t\n\t\tif not output_file_name or output_file_name is None:\n\t\t\tfname = altname\n\t\telse:\n\t\t\tfname = \"%s.%s\" % (output_file_name, extension)\n\t\n\t\t# Sanitize output file name of invalid/dangerous characters (like file paths)\t\n\t\tfname = os.path.basename(fname)\n\n\t\ttry:\n\t\t\t# Open the target file and seek to the offset\n\t\t\tfdin = open(file_name, \"rb\")\n\t\t\tfdin.seek(offset)\n\t\t\t\n\t\t\t# Open the extracted file\n\t\t\ttry:\n\t\t\t\tfdout = open(fname, \"wb\")\n\t\t\texcept:\n\t\t\t\t# Fall back to the alternate name if the requested name fails\n\t\t\t\tfname = altname\n\t\t\t\tfdout = open(fname, \"wb\")\n\n\t\t\t# Read size bytes from target file and write it to the extracted file\n\t\t\tfdout.write(fdin.read(size))\n\n\t\t\t# Cleanup\n\t\t\tfdout.close()\n\t\t\tfdin.close()\n\t\texcept Exception, e:\n\t\t\traise Exception(\"Extractor.dd failed to extract data from '%s' to '%s': %s\" % (file_name, fname, str(e)))\n\t\t\n\t\treturn fname\n\n\tdef _execute(self, cmd, fname):\n\t\t'''\n\t\tExecute a command against the specified file.\n\n\t\t@cmd   - Command to execute.\n\t\t@fname - File to run command against.\n\n\t\tReturns None.\n\t\t'''\n\t\ttmp = None\n\n\t\t# If not in verbose mode, create a temporary file to redirect stdout and stderr to\n\t\tif not self.verbose:\n\t\t\ttmp = tempfile.TemporaryFile()\n\n\t\ttry:\n\t\t\t# Replace all instances of FILE_NAME_PLACEHOLDER in the command with fname\n\t\t\tcmd = cmd.replace(self.FILE_NAME_PLACEHOLDER, fname)\n\n\t\t\t# Execute.\n\t\t\tsubprocess.call(shlex.split(cmd), stdout=tmp, stderr=tmp)\n\t\texcept Exception, e:\n\t\t\tsys.stderr.write(\"WARNING: Extractor.execute failed to run '%s': %s\\n\" % (cmd, str(e)))\n\t\t\n\t\tif tmp is not None:\n\t\t\ttmp.close()\n\n\t\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/filter.py",
    "content": "import common\nfrom smartsig import SmartSignature\n\nclass MagicFilter:\n\t'''\n\tClass to filter libmagic results based on include/exclude rules and false positive detection.\n\tAn instance of this class is available via the Binwalk.filter object.\n\n\tExample code which creates include, exclude, and grep filters before running a Binwalk scan:\n\n\t\timport binwalk\n\n\t\tbw = binwalk.Binwalk()\n\n\t\t# Include all signatures whose descriptions contain the string 'filesystem' in the first line of the signature, even if those signatures are normally excluded.\n\t\t# Note that if exclusive=False was specified, this would merely add these signatures to the default signatures.\n\t\t# Since exclusive=True (the default) has been specified, ONLY those matching signatures will be loaded; all others will be ignored.\n\t\tbw.filter.include('filesystem')\n\n\t\t# Exclude all signatures whose descriptions contain the string 'jffs2', even if those signatures are normally included.\n\t\t# In this case, we are now searching for all filesystem signatures, except JFFS2.\n\t\tbw.filter.exclude('jffs2')\n\n\t\t# Add a grep filter. Unlike the include and exclude filters, it does not affect which results are returned by Binwalk.scan(), but it does affect which results\n\t\t# are printed by Binwalk.display.results(). This is particularly useful for cases like the bincast scan, where multiple lines of results are returned per offset,\n\t\t# but you only want certian ones displayed. In this case, only file systems whose description contain the string '2012' will be displayed.\n\t\tbw.filter.grep(filters=['2012'])\n\n\t\tbw.scan('firmware.bin')\n\t'''\n\n\t# If the result returned by libmagic is \"data\" or contains the text\n\t# 'invalid' or a backslash are known to be invalid/false positives.\n\tDATA_RESULT = \"data\"\n\tINVALID_RESULTS = [\"invalid\", \"\\\\\"]\n\tINVALID_RESULT = \"invalid\"\n\tNON_PRINTABLE_RESULT = \"\\\\\"\n\n\tFILTER_INCLUDE = 0\n\tFILTER_EXCLUDE = 1\n\n\tdef __init__(self, show_invalid_results=False):\n\t\t'''\n\t\tClass constructor.\n\n\t\t@show_invalid_results - Set to True to display results marked as invalid.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.filters = []\n\t\tself.grep_filters = []\n\t\tself.show_invalid_results = show_invalid_results\n\t\tself.exclusive_filter = False\n\t\tself.smart = SmartSignature(self)\n\n\tdef include(self, match, exclusive=True):\n\t\t'''\n\t\tAdds a new filter which explicitly includes results that contain\n\t\tthe specified matching text.\n\n\t\t@match     - Case insensitive text, or list of texts, to match.\n\t\t@exclusive - If True, then results that do not explicitly contain\n\t\t\t     a FILTER_INCLUDE match will be excluded. If False,\n\t\t\t     signatures that contain the FILTER_INCLUDE match will\n\t\t\t     be included in the scan, but will not cause non-matching\n\t\t\t     results to be excluded.\n\t\t\n\t\tReturns None.\n\t\t'''\n\t\tinclude_filter = {\n\t\t\t\t'type'\t\t: self.FILTER_INCLUDE,\n\t\t\t\t'filter'\t: ''\n\t\t}\n\n\t\tif type(match) != type([]):\n\t\t\tmatches = [match]\n\t\telse:\n\t\t\tmatches = match\n\n\t\tfor m in matches:\n\t\t\tif m:\n\t\t\t\tif exclusive and not self.exclusive_filter:\n\t\t\t\t\tself.exclusive_filter = True\n\n\t\t\t\tinclude_filter['filter'] = m.lower()\n\t\t\t\tself.filters.append(include_filter)\n\n\tdef exclude(self, match):\n\t\t'''\n\t\tAdds a new filter which explicitly excludes results that contain\n\t\tthe specified matching text.\n\n\t\t@match - Case insensitive text, or list of texts, to match.\n\t\t\n\t\tReturns None.\n\t\t'''\n\t\texclude_filter = {\n\t\t\t\t'type'\t\t: self.FILTER_EXCLUDE,\n\t\t\t\t'filter'\t: ''\n\t\t}\n\n\t\tif type(match) != type([]):\n\t\t\tmatches = [match]\n\t\telse:\n\t\t\tmatches = match\n\n\t\tfor m in matches:\n\t\t\tif m:\n\t\t\t\texclude_filter['filter'] = m.lower()\n\t\t\t\tself.filters.append(exclude_filter)\n\n\tdef filter(self, data):\n\t\t'''\n\t\tChecks to see if a given string should be excluded from or included in the results.\n\t\tCalled internally by Binwalk.scan().\n\n\t\t@data - String to check.\n\n\t\tReturns FILTER_INCLUDE if the string should be included.\n\t\tReturns FILTER_EXCLUDE if the string should be excluded.\n\t\t'''\n\t\tdata = data.lower()\n\n\t\t# Loop through the filters to see if any of them are a match. \n\t\t# If so, return the registered type for the matching filter (FILTER_INCLUDE | FILTER_EXCLUDE). \n\t\tfor f in self.filters:\n\t\t\tif f['filter'] in data:\n\t\t\t\treturn f['type']\n\n\t\t# If there was not explicit match and exclusive filtering is enabled, return FILTER_EXCLUDE.\n\t\tif self.exclusive_filter:\n\t\t\treturn self.FILTER_EXCLUDE\n\n\t\treturn self.FILTER_INCLUDE\n\n\tdef invalid(self, data):\n\t\t'''\n\t\tChecks if the given string contains invalid data.\n\t\tCalled internally by Binwalk.scan().\n\n\t\t@data - String to validate.\n\n\t\tReturns True if data is invalid, False if valid.\n\t\t'''\n\t\t# A result of 'data' is never ever valid.\n\t\tif data == self.DATA_RESULT:\n\t\t\treturn True\n\n\t\t# If showing invalid results, just return False.\n\t\tif self.show_invalid_results:\n\t\t\treturn False\n\n\t\t# Don't include quoted strings or keyword arguments in this search, as \n\t\t# strings from the target file may legitimately contain the INVALID_RESULT text.\n\t\tif self.INVALID_RESULT in common.strip_quoted_strings(self.smart._strip_tags(data)):\n\t\t\treturn True\n\n\t\t# There should be no non-printable data in any of the data\n\t\tif self.NON_PRINTABLE_RESULT in data:\n\t\t\treturn True\n\n\t\treturn False\n\n\tdef grep(self, data=None, filters=[]):\n\t\t'''\n\t\tAdd or check case-insensitive grep filters against the supplied data string.\n\n\t\t@data    - Data string to check grep filters against. Not required if filters is specified.\n\t\t@filters - Filter, or list of filters, to add to the grep filters list. Not required if data is specified.\n\n\t\tReturns None if data is not specified.\n\t\tIf data is specified, returns True if the data contains a grep filter, or if no grep filters exist.\n\t\tIf data is specified, returns False if the data does not contain any grep filters.\n\t\t'''\n\t\t# Add any specified filters to self.grep_filters\n\t\tif filters:\n\t\t\tif type(filters) != type([]):\n\t\t\t\tgfilters = [filters]\n\t\t\telse:\n\t\t\t\tgfilters = filters\n\n\t\t\tfor gfilter in gfilters:\n\t\t\t\t# Filters are case insensitive\n\t\t\t\tself.grep_filters.append(gfilter.lower())\n\n\t\t# Check the data against all grep filters until one is found\n\t\tif data is not None:\n\t\t\t# If no grep filters have been created, always return True\n\t\t\tif not self.grep_filters:\n\t\t\t\treturn True\n\n\t\t\t# Filters are case insensitive\n\t\t\tdata = data.lower()\n\n\t\t\t# If a filter exists in data, return True\n\t\t\tfor gfilter in self.grep_filters:\n\t\t\t\tif gfilter in data:\n\t\t\t\t\treturn True\n\n\t\t\t# Else, return False\n\t\t\treturn False\n\t\n\t\treturn None\n\n\tdef clear(self):\n\t\t'''\n\t\tClears all include, exclude and grep filters.\n\t\t\n\t\tRetruns None.\n\t\t'''\n\t\tself.filters = []\n\t\tself.grep_filters = []\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/magic/binarch",
    "content": "# MIPS prologue\n# addiu $sp, -XX\n# 27 BD FF XX\n1\tstring\t\\377\\275\\47\tMIPSEL function prologue\n0       string  \\47\\275\\377\tMIPS function prologue\n\n# MIPS epilogue\n# jr $ra\n0\tbelong\t0x03e00008\tMIPS function epilogue\n0\tlelong\t0x03e00008\tMIPSEL function epilogue\n\n# PowerPC epilogue\n# blr\n0\tbelong 0x4E800020\tPowerPC big endian function epilogue\n0\tlelong 0x4E800020\tPowerPC little endian function epilogue\n\n# ARM prologue\n# STMFD SP!, {XX}\n0\tbeshort\t0xE92D\t\tARMEB function prologue\n2\tleshort\t0xE92D\t\tARM function prologue\n\n# ARM epilogue\n# LDMFD SP!, {XX}\n0\tbeshort\t0xE8BD\t\tARMEB function epilogue\n2\tleshort\t0xE8BD\t\tARM function epilogue\n\n# x86 epilogue\n# push ebp\n# move ebp, esp\n0\tstring\t\\x55\\x89\\xE5\tIntel x86 function epilogue\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/magic/bincast",
    "content": "0\tbelong x\tHex:                 0x%.8X\n#0\tstring x\tString:              %s\n0\tlelong x\tLittle Endian Long:  %d\n0\tbelong x\tBig Endian Long:     %d\n0\tleshort x\tLittle Endian Short: %d\n0\tbeshort x\tBig Endian Short:    %d\n0\tledate x\tLittle Endian Date:  %s\n0\tbedate x\tBig Endian Date:     %s\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/magic/binwalk",
    "content": "# ----------------------------Archive Formats--------------------------------------\n\n# POSIX tar archives\n0\tstring\t\tustar\\000\t\tPOSIX tar archive{offset-adjust:-257}\n0\tstring          ustar\\040\\040\\000\tPOSIX tar archive (GNU){offset-adjust:-257}\n\n# JAR archiver (.j), this is the successor to ARJ, not Java's JAR (which is essentially ZIP)\n0       string  \\x1aJar\\x1b JAR (ARJ Software, Inc.) archive data{offset-adjust:-14}\n0       string  JARCS JAR (ARJ Software, Inc.) archive data\n\n\n# ARJ archiver (jason@jarthur.Claremont.EDU)\n0       leshort         0xea60          ARJ archive data\n>5      byte            x               \\b, v%d,\n>8      byte            &0x04           multi-volume,\n>8      byte            &0x10           slash-switched,\n>8      byte            &0x20           backup,\n>34     string          x               original name: \"%s\",\n>7      byte            0               os: MS-DOS \n>7      byte            1               os: PRIMOS\n>7      byte            2               os: Unix\n>7      byte            3               os: Amiga\n>7      byte            4               os: Macintosh\n>7      byte            5               os: OS/2\n>7      byte            6               os: Apple ][ GS\n>7      byte            7               os: Atari ST\n>7      byte            8               os: NeXT\n>7      byte            9               os: VAX/VMS\n>3      byte            >0              %d]\n\n# RAR archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\tRar!\t\tRAR archive data\n\n# HPACK archiver (Peter Gutmann, pgut1@cs.aukuni.ac.nz)\n0\tstring\t\tHPAK\t\tHPACK archive data\n\n# JAM Archive volume format, by Dmitry.Kohmanyuk@UA.net\n0\tstring\t\t\\351,\\001JAM\tJAM archive\n\n# LHARC/LHA archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\t-lzs-\t\tLHa 2.x? archive data [lzs] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh\\40-\t\tLHa 2.x? archive data [lh ] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lhd-\t\tLHa 2.x? archive data [lhd] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh2-\t\tLHa 2.x? archive data [lh2] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh3-\t\tLHa 2.x? archive data [lh3] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh4-\t\tLHa (2.x) archive data [lh4] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh5-\t\tLHa (2.x) archive data [lh5] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh6-\t\tLHa (2.x) archive data [lh6] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh7-\t\tLHa (2.x) archive data [lh7] [NSRL|LHA2]{offset-adjust:-2}\n\n\n# cpio archives\n#\n# The SVR4 \"cpio(4)\" hints that there are additional formats, but they\n# are defined as \"short\"s; I think all the new formats are\n# character-header formats and thus are strings, not numbers.\n#0       string          070707          ASCII cpio archive (pre-SVR4 or odc)\n\n0       string          070701          ASCII cpio archive (SVR4 with no CRC),\n>110\tbyte\t\t0\t\tinvalid\n>110\tstring\t\tx\t\tfile name: \"%s\"\n>54\tstring\t\tx\t\t{jump-to-offset:0x%.8s+112}\n\n0       string          070702          ASCII cpio archive (SVR4 with CRC)\n>110\tbyte\t\t0\t\tinvalid\n>110\tstring\t\tx\t\tfile name: \"%s\"\n>54\tstring\t\tx\t\t{jump-to-offset:0x%.8s+112}\n\n\n# HP Printer Job Language\n# The header found on Win95 HP plot files is the \"Silliest Thing possible\" \n# (TM)\n# Every driver puts the language at some random position, with random case\n# (LANGUAGE and Language)\n# For example the LaserJet 5L driver puts the \"PJL ENTER LANGUAGE\" in line 10\n# From: Uwe Bonnes <bon@elektron.ikp.physik.th-darmstadt.de>\n# \n0       string          \\033%-12345X@PJL        HP Printer Job Language data\n>&0     string          >\\0                     \"%s\"\n>>&0    string          >\\0                     \"%s\"\n>>>&0   string          >\\0                     \"%s\"\n>>>>&0  string          >\\0                     \"%s\"\n\n#------------------------------------------------------------------------------\n#\n# RPM: file(1) magic for Red Hat Packages   Erik Troan (ewt@redhat.com)\n#\n0\tbelong\t\t0xedabeedb\tRPM\n>4\tbyte\t\tx\t\tv%d\n>6\tbeshort\t\t0\t\tbin\n>6\tbeshort\t\t1\t\tsrc\n>8\tbeshort\t\t1\t\ti386\n>8\tbeshort\t\t2\t\tAlpha\n>8\tbeshort\t\t3\t\tSparc\n>8\tbeshort\t\t4\t\tMIPS\n>8\tbeshort\t\t5\t\tPowerPC\n>8\tbeshort\t\t6\t\t68000\n>8\tbeshort\t\t7\tSGI\n>8\tbeshort\t\t8\t\tRS6000\n>8\tbeshort\t\t9\t\tIA64\n>8\tbeshort\t\t10\t\tSparc64\n>8\tbeshort\t\t11\t\tMIPSel\n>8\tbeshort\t\t12\t\tARM\n>10\tstring\t\tx\t\t\"%s\"\n\n\n#---------------------------Bootloaders--------------------------------\n\n# CFE bootloader\n0\tstring\tCFE1CFE1\tCFE boot loader, little endian\n0\tstring\t1EFC1EFC\tCFE boot loader, big endian\n\n\n#------------------Compression Formats-----------------------------\n\n# AFX compressed files (Wolfram Kleff)\n0\tstring\t\t-afx-\t\tAFX compressed file data{offset-adjust:-2}\n\n# bzip2\n0\tstring BZh91AY&SY\tbzip2 compressed data, block size = 900k\n0\tstring BZh81AY&SY\tbzip2 compressed data, block size = 800k\n0\tstring BZh71AY&SY\tbzip2 compressed data, block size = 700k\n0\tstring BZh61AY&SY\tbzip2 compressed data, block size = 600k\n0\tstring BZh51AY&SY\tbzip2 compressed data, block size = 500k\n0\tstring BZh41AY&SY\tbzip2 compressed data, block size = 400k\n0\tstring BZh31AY&SY\tbzip2 compressed data, block size = 300k\n0\tstring BZh21AY&SY\tbzip2 compressed data, block size = 200k\n0\tstring BZh11AY&SY\tbzip2 compressed data, block size = 100k\n\n# lzop from <markus.oberhumer@jk.uni-linz.ac.at>\n0\tstring\t\t\\x89\\x4c\\x5a\\x4f\\x00\\x0d\\x0a\\x1a\\x0a\tlzop compressed data\n>9\tbeshort\t\t<0x0940\n>>9\tbyte&0xf0\t=0x00\t\t- version 0.\n>>9\tbeshort&0x0fff\tx\t\t\\b%03x,\n>>13\tbyte\t\t1\t\tLZO1X-1,\n>>13\tbyte\t\t2\t\tLZO1X-1(15),\n>>13\tbyte\t\t3\t\tLZO1X-999,\n## >>22\tbedate\t\t>0\t\tlast modified: %s,\n>>14\tbyte\t\t=0x00\t\tos: MS-DOS\n>>14\tbyte\t\t=0x01\t\tos: Amiga\n>>14\tbyte\t\t=0x02\t\tos: VMS\n>>14\tbyte\t\t=0x03\t\tos: Unix\n>>14\tbyte\t\t=0x05\t\tos: Atari\n>>14\tbyte\t\t=0x06\t\tos: OS/2\n>>14\tbyte\t\t=0x07\t\tos: MacOS\n>>14\tbyte\t\t=0x0A\t\tos: Tops/20\n>>14\tbyte\t\t=0x0B\t\tos: WinNT\n>>14\tbyte\t\t=0x0E\t\tos: Win32\n>9\tbeshort\t\t>0x0939\n>>9\tbyte&0xf0\t=0x00\t\t- version 0.\n>>9\tbyte&0xf0\t=0x10\t\t- version 1.\n>>9\tbyte&0xf0\t=0x20\t\t- version 2.\n>>9\tbeshort&0x0fff\tx\t\t\\b%03x,\n>>15\tbyte\t\t1\t\tLZO1X-1,\n>>15\tbyte\t\t2\t\tLZO1X-1(15),\n>>15\tbyte\t\t3\t\tLZO1X-999,\n## >>25\tbedate\t\t>0\t\tlast modified: %s,\n>>17\tbyte\t\t=0x00\t\tos: MS-DOS\n>>17\tbyte\t\t=0x01\t\tos: Amiga\n>>17\tbyte\t\t=0x02\t\tos: VMS\n>>17\tbyte\t\t=0x03\t\tos: Unix\n>>17\tbyte\t\t=0x05\t\tos: Atari\n>>17\tbyte\t\t=0x06\t\tos: OS/2\n>>17\tbyte\t\t=0x07\t\tos: MacOS\n>>17\tbyte\t\t=0x0A\t\tos: Tops/20\n>>17\tbyte\t\t=0x0B\t\tos: WinNT\n>>17\tbyte\t\t=0x0E\t\tos: Win32\n\n# lzip  \n0       string          LZIP            lzip compressed data\n>4      byte            x               \\b, version: %d\n\n# LZO\n0\tstring\t\t\\211LZO\\000\\015\\012\\032\\012\tLZO compressed data\n\n# 7-zip archiver, from Thomas Klausner (wiz@danbala.tuwien.ac.at)\n# http://www.7-zip.org or DOC/7zFormat.txt \n#\n0       string          7z\\274\\257\\047\\034      7-zip archive data,\n>6      byte            x                       version %d\n>7      byte            x                       \\b.%d\n\n# standard unix compress\n0       beshort\t\t0x1f9d          compress'd data\n>2      byte&0x80       >0              block compressed\n>2\tbyte&0x1f\t!16\t\tinvalid\n>2      byte&0x1f       x               %d bits\n\n# http://tukaani.org/xz/xz-file-format.txt\n0\tstring\t\t\\xFD\\x37\\x7a\\x58\\x5a\\x00\txz compressed data\n\n# gzip (GNU zip, not to be confused with Info-ZIP or PKWARE zip archiver)\n#   Edited by Chris Chittleborough <cchittleborough@yahoo.com.au>, March 2002\n#       * Original filename is only at offset 10 if \"extra field\" absent\n#       * Produce shorter output - notably, only report compression methods\n#         other than 8 (\"deflate\", the only method defined in RFC 1952).\n0       string          \\037\\213\\x08    gzip compressed data\n>3      byte            &0x01           \\b, ASCII\n>3      byte            &0x02           \\b, has CRC\n>3      byte            &0x04           \\b, extra field\n>3      byte&0xC        =0x08\n>>10\tstring\t\tx\t\t\\b{file-name:%s}\n>>10    string          x               \\b, was \"%s\"\n>3      byte            &0x10           \\b, has comment\n>9      byte            =0x00           \\b, from FAT filesystem (MS-DOS, OS/2, NT)\n>9      byte            =0x01           \\b, from Amiga\n>9      byte            =0x02           \\b, from VMS\n>9      byte            =0x03           \\b, from Unix\n>9      byte            =0x04           \\b, from VM/CMS\n>9      byte            =0x05           \\b, from Atari\n>9      byte            =0x06           \\b, from HPFS filesystem (OS/2, NT)\n>9      byte            =0x07           \\b, from MacOS\n>9      byte            =0x08           \\b, from Z-System\n>9      byte            =0x09           \\b, from CP/M\n>9      byte            =0x0A           \\b, from TOPS/20\n>9      byte            =0x0B           \\b, from NTFS filesystem (NT)\n>9      byte            =0x0C           \\b, from QDOS\n>9      byte            =0x0D           \\b, from Acorn RISCOS\n>9\tbyte\t\t>0x0D\t\t\\b, invalid source\n>9\tbyte\t\t<0\t\t\\b, invalid source\n>3      byte            &0x20           \\b, encrypted (invalid)\n# Dates before 1992 are invalid, unless of course you're DD-WRT in which\n# case you don't know how to set a date in your gzip files. Brilliant.\n>4\tlelong\t\t=0\t\t\\b, NULL date:\n>4\tlelong\t\t<0\t\t\\b, invalid date:\n>4\tlelong\t\t>0\t\t\n>>4\tlelong\t\t<694224000\t\\b, invalid date:\n>>4\tlelong\t\t=694224000\t\\b, invalid date:\n>>4\tlelong\t\t>694224000\t\\b, last modified:\n>4      ledate          x               %s\n>8      byte            2               \\b, max compression\n>8      byte            4               \\b, max speed\n\n# Zlib signatures\n0\tbeshort\t\t0x789C\t\tzlib compressed data\n0\tbeshort\t\t0x78DA\t\tzlib compressed data\n0\tbeshort\t\t0x7801\t\tzlib compressed data\n\n# Supplementary magic data for the file(1) command to support\n# rzip(1).  The format is described in magic(5).\n#\n# Copyright (C) 2003 by Andrew Tridgell.  You may do whatever you want with\n# this file.\n#\n0       string          RZIP            rzip compressed data\n>4      byte            x               - version %d\n>5      byte            x               \\b.%d\n>6      belong          x               (%d bytes)\n\n# ZIP compression (Greg Roelofs, c/o zip-bugs@wkuvx1.wku.edu)\n0       string          PK\\003\\004      Zip archive data,\n>4      byte            0x00            v0.0\n>4      byte            0x09            at least v0.9 to extract,\n>4      byte            0x0a            at least v1.0 to extract,\n>4      byte            0x0b            at least v1.1 to extract,\n>0x161  string          WINZIP          WinZIP self-extracting,\n>4      byte            0x14\n>>30    ubelong         !0x6d696d65     at least v2.0 to extract,\n>18\tlelong\t\t!0\n>>18\tlelong\t\t<0\t\tinvalid\n>>18\tlelong\t\tx\t\tcompressed size: %d,\n>22\tlelong\t\t!0\n>>22\tlelong\t\t<0\t\tinvalid\n>>22\tlelong\t\tx\t\tuncompressed size: %d,{extract-delay:end of zip archive}\n>30\tstring\t\tx\t\t{file-name:{raw-replace}}name: {raw-replace}\n>26\tleshort\t\tx\t\t{raw-string-length:%d}\n>30\tstring\t\tx\t\t{raw-string:%s\n>61\tstring\t\tx\t\t\\b%s\n>92\tstring\t\tx\t\t\\b%s\n>123\tstring\t\tx\t\t\\b%s\n>154\tstring\t\tx\t\t\\b%s}\n\n# ZIP footer\n0\tstring\t\tPK\\x05\\x06\tEnd of Zip archive\n>20\tleshort\t\tx\t\t{offset-adjust:22+%d}\n>20\tleshort\t\t>0\n>>20\tleshort\t\tx\t\t\\b, comment: {raw-replace}\n>>20\tleshort\t\tx\t\t{raw-string-length:%d}\n>>22\tstring\t\tx\t\t{raw-string:%s}\n\n# New LZMA format signature\n0\tstring\t\t\\xFFLZMA\\x00\tLZMA compressed data (new),\n>6\tbyte&0x10\t0\t\tsingle-block stream\n>6\tbyte&0x10\t0x10\t\tmulti-block stream\n\n# See lzma file for LZMA signatures\n# Type: OpenSSL certificates/key files\n# From: Nicolas Collignon <tsointsoin@gmail.com>\n\n0       string  -----BEGIN\\x20CERTIFICATE-----    PEM certificate\n0       string  -----BEGIN\\x20CERTIFICATE\\x20REQ    PEM certificate request\n0       string  -----BEGIN\\x20RSA\\x20PRIVATE        PEM RSA private key\n0       string  -----BEGIN\\x20DSA\\x20PRIVATE        PEM DSA private key\n\n# Type: OpenSSH key files\n# From: Nicolas Collignon <tsointsoin@gmail.com>\n\n0       string  SSH\\x20PRIVATE\\x20KEY\tOpenSSH RSA1 private key,\n>28     string  >\\0\t\t\tversion \"%s\"\n\n0       string  ssh-dss\\x20               OpenSSH DSA public key\n0       string  ssh-rsa\\x20               OpenSSH RSA public key\n\n# Type: Certificates/key files in DER format\n# From: Gert Hulselmans <hulselmansgert@gmail.com>\n0\tstring\t\\x30\\x82\t\tPrivate key in DER format (PKCS#8),\n>4\tstring\t!\\x02\\x01\\x00\t\tinvalid,\n>>2\tbeshort\tx\t\t\theader length: 4, sequence length: %d\n\n0\tstring  \\x30\\x82\t\tCertificate in DER format (x509 v3),\n>4\tstring\t!\\x30\\x82\t\tinvalid,\n>>2\tbeshort\tx\t\t\theader length: 4, sequence length: %d\n\n# GnuPG\n# The format is very similar to pgp\n0\tstring          \\001gpg                 GPG key trust database\n>4\tbyte            x                       version %d\n0       beshort         0x9901                  GPG key public ring\n# This magic is not particularly good, as the keyrings don't have true\n# magic. Nevertheless, it covers many keyrings.\n\n#------------------------------------------------------------------------------\n# Mavroyanopoulos Nikos <nmav@hellug.gr>\n# mcrypt:   file(1) magic for mcrypt 2.2.x;\n0\tstring\t\t\\0m\\3\t\tmcrypt 2.5 encrypted data,\n>4\tbyte\t\t0\t\tinvalid\n>4\tstring\t\t>\\0\t\talgorithm: \"%s\",\n>>&1\tleshort\t\t<1\t\tinvalid\n>>&1\tleshort\t\t>0\t\tkeysize: %d bytes,\n>>>&0\tbyte\t\t0\t\tinvalid\n>>>&0\tstring\t\t>\\0\t\tmode: \"%s\",\n\n0\tstring\t\t\\0m\\2\t\tmcrypt 2.2 encrypted data,\n>3\tbyte\t\t0\t\talgorithm: blowfish-448,\n>3\tbyte\t\t1\t\talgorithm: DES,\n>3\tbyte\t\t2\t\talgorithm: 3DES,\n>3\tbyte\t\t3\t\talgorithm: 3-WAY,\n>3\tbyte\t\t4\t\talgorithm: GOST,\n>3\tbyte\t\t6\t\talgorithm: SAFER-SK64,\n>3\tbyte\t\t7\t\talgorithm: SAFER-SK128,\n>3\tbyte\t\t8\t\talgorithm: CAST-128,\n>3\tbyte\t\t9\t\talgorithm: xTEA,\n>3\tbyte\t\t10\t\talgorithm: TWOFISH-128,\n>3\tbyte\t\t11\t\talgorithm: RC2,\n>3\tbyte\t\t12\t\talgorithm: TWOFISH-192,\n>3\tbyte\t\t13\t\talgorithm: TWOFISH-256,\n>3\tbyte\t\t14\t\talgorithm: blowfish-128,\n>3\tbyte\t\t15\t\talgorithm: blowfish-192,\n>3\tbyte\t\t16\t\talgorithm: blowfish-256,\n>3\tbyte\t\t100\t\talgorithm: RC6,\n>3\tbyte\t\t101\t\talgorithm: IDEA,\n>3\tbyte\t\t<0\t\tinvalid algorithm\n>3\tbyte\t\t>101\t\tinvalid algorithm,\n>3\tbyte\t\t>16\n>>3\tbyte\t\t<100\t\tinvalid algorithm,\n>4\tbyte\t\t0\t\tmode: CBC,\n>4\tbyte\t\t1\t\tmode: ECB,\n>4\tbyte\t\t2\t\tmode: CFB,\n>4\tbyte\t\t3\t\tmode: OFB,\n>4\tbyte\t\t4\t\tmode: nOFB,\n>4\tbyte\t\t<0\t\tinvalid mode,\n>4\tbyte\t\t>4\t\tinvalid mode,\n>5\tbyte\t\t0\t\tkeymode: 8bit\n>5\tbyte\t\t1\t\tkeymode: 4bit\n>5\tbyte\t\t2\t\tkeymode: SHA-1 hash\n>5\tbyte\t\t3\t\tkeymode: MD5 hash\n>5\tbyte\t\t<0\t\tinvalid keymode\n>5\tbyte\t\t>3\t\tinvalid keymode\n\n#------------------------------------------------------------------------------\n# pgp:  file(1) magic for Pretty Good Privacy\n#\n#0       beshort         0x9900                  PGP key public ring\n#0       beshort         0x9501                  PGP key security ring\n#0       beshort         0x9500                  PGP key security ring\n#0\tbeshort\t\t0xa600\t\t\tPGP encrypted data\n0       string          -----BEGIN\\040PGP       PGP armored data\n>15     string          PUBLIC\\040KEY\\040BLOCK- public key block\n>15     string          MESSAGE-                message\n>15     string          SIGNED\\040MESSAGE-      signed message\n>15     string          PGP\\040SIGNATURE-       signature\n\n\n#------------------Standard file formats------------------------------------\n\n#------------------------------------------------------------------------------\n# elf:  file(1) magic for ELF executables\n#\n# We have to check the byte order flag to see what byte order all the\n# other stuff in the header is in.\n#\n# What're the correct byte orders for the nCUBE and the Fujitsu VPP500?\n#\n# updated by Daniel Quinlan (quinlan@yggdrasil.com)\n0\tstring\t\t\\177ELF\t\tELF\n>4\tbyte\t\t0\t\tinvalid class\n>4\tbyte\t\t1\t\t32-bit\n# only for MIPS - in the future, the ABI field of e_flags should be used.\n>>18\tleshort\t\t8\n>>>36\tlelong\t\t&0x20\t\tN32\n>>18\tleshort\t\t10\n>>>36\tlelong\t\t&0x20\t\tN32\n>>18\tbeshort\t\t8\n>>>36\tbelong\t\t&0x20\t\tN32\n>>18\tbeshort\t\t10\n>>>36\tbelong\t\t&0x20\t\tN32\n>4\tbyte\t\t2\t\t64-bit\n>5\tbyte\t\t0\t\tinvalid byte order\n>5\tbyte\t\t1\t\tLSB\n# The official e_machine number for MIPS is now #8, regardless of endianness.\n# The second number (#10) will be deprecated later. For now, we still\n# say something if #10 is encountered, but only gory details for #8.\n>>18    leshort\t\t8\n# only for 32-bit\n>>>4\tbyte\t\t1\n>>>>36  lelong&0xf0000000\t0x00000000\tMIPS-I\n>>>>36  lelong&0xf0000000\t0x10000000\tMIPS-II\n>>>>36  lelong&0xf0000000\t0x20000000\tMIPS-III\n>>>>36  lelong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>36  lelong&0xf0000000\t0x40000000\tMIPS-V\n>>>>36  lelong&0xf0000000\t0x60000000\tMIPS32\n>>>>36  lelong&0xf0000000\t0x70000000\tMIPS64\n>>>>36  lelong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>36  lelong&0xf0000000\t0x90000000\tMIPS64 rel2\n# only for 64-bit\n>>>4\tbyte\t\t2\n>>>>48  lelong&0xf0000000\t0x00000000\tMIPS-I\n>>>>48  lelong&0xf0000000\t0x10000000\tMIPS-II\n>>>>48  lelong&0xf0000000\t0x20000000\tMIPS-III\n>>>>48  lelong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>48  lelong&0xf0000000\t0x40000000\tMIPS-V\n>>>>48  lelong&0xf0000000\t0x60000000\tMIPS32\n>>>>48  lelong&0xf0000000\t0x70000000\tMIPS64 \n>>>>48  lelong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>48  lelong&0xf0000000\t0x90000000\tMIPS64 rel2\n>>16\tleshort\t\t0\t\tno file type,\n>>16\tleshort\t\t1\t\trelocatable,\n>>16\tleshort\t\t2\t\texecutable,\n>>16\tleshort\t\t3\t\tshared object,\n# Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>\n# corrections by Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>\n>>16\tleshort\t\t4\t\tcore file\n# Core file detection is not reliable.\n#>>>(0x38+0xcc) string\t>\\0\t\tof '%s'\n#>>>(0x38+0x10) lelong\t>0\t\t(signal %d),\n>>16\tleshort\t\t&0xff00\t\tprocessor-specific,\n>>18\tleshort\t\t0\t\tno machine,\n>>18\tleshort\t\t1\t\tAT&T WE32100 - invalid byte order,\n>>18\tleshort\t\t2\t\tSPARC - invalid byte order,\n>>18\tleshort\t\t3\t\tIntel 80386,\n>>18\tleshort\t\t4\t\tMotorola\n>>>36\tlelong\t\t&0x01000000\t68000 - invalid byte order,\n>>>36\tlelong\t\t&0x00810000\tCPU32 - invalid byte order,\n>>>36\tlelong\t\t0\t\t68020 - invalid byte order,\n>>18\tleshort\t\t5\t\tMotorola 88000 - invalid byte order,\n>>18\tleshort\t\t6\t\tIntel 80486,\n>>18\tleshort\t\t7\t\tIntel 80860,\n>>18\tleshort\t\t8\t\tMIPS,\n>>18\tleshort\t\t9\t\tAmdahl - invalid byte order,\n>>18\tleshort\t\t10\t\tMIPS (deprecated),\n>>18\tleshort\t\t11\t\tRS6000 - invalid byte order,\n>>18\tleshort\t\t15\t\tPA-RISC - invalid byte order,\n>>>50\tleshort\t\t0x0214\t\t2.0\n>>>48\tleshort\t\t&0x0008\t\t(LP64),\n>>18\tleshort\t\t16\t\tnCUBE,\n>>18\tleshort\t\t17\t\tFujitsu VPP500,\n>>18\tleshort\t\t18\t\tSPARC32PLUS,\n>>18\tleshort\t\t20\t\tPowerPC,\n>>18\tleshort\t\t22\t\tIBM S/390,\n>>18\tleshort\t\t36\t\tNEC V800,\n>>18\tleshort\t\t37\t\tFujitsu FR20,\n>>18\tleshort\t\t38\t\tTRW RH-32,\n>>18\tleshort\t\t39\t\tMotorola RCE,\n>>18\tleshort\t\t40\t\tARM,\n>>18\tleshort\t\t41\t\tAlpha,\n>>18\tleshort\t\t0xa390\t\tIBM S/390 (obsolete),\n>>18\tleshort\t\t42\t\tHitachi SH,\n>>18\tleshort\t\t43\t\tSPARC V9 - invalid byte order,\n>>18\tleshort\t\t44\t\tSiemens Tricore Embedded Processor,\n>>18\tleshort\t\t45\t\tArgonaut RISC Core, Argonaut Technologies Inc.,\n>>18\tleshort\t\t46\t\tHitachi H8/300,\n>>18\tleshort\t\t47\t\tHitachi H8/300H,\n>>18\tleshort\t\t48\t\tHitachi H8S,\n>>18\tleshort\t\t49\t\tHitachi H8/500,\n>>18\tleshort\t\t50\t\tIA-64 (Intel 64 bit architecture)\n>>18\tleshort\t\t51\t\tStanford MIPS-X,\n>>18\tleshort\t\t52\t\tMotorola Coldfire,\n>>18\tleshort\t\t53\t\tMotorola M68HC12,\n>>18\tleshort\t\t62\t\tAMD x86-64,\n>>18\tleshort\t\t75\t\tDigital VAX,\n>>18\tleshort\t\t97\t\tNatSemi 32k,\n>>18\tleshort\t\t0x9026\t\tAlpha (unofficial),\n>>20\tlelong\t\t0\t\tinvalid version\n>>20\tlelong\t\t1\t\tversion 1\n>>36\tlelong\t\t1\t\tMathCoPro/FPU/MAU Required\n>5\tbyte\t\t2\t\tMSB\n# only for MIPS - see comment in little-endian section above.\n>>18    beshort\t\t8\n# only for 32-bit\n>>>4\tbyte\t\t1\n>>>>36  belong&0xf0000000\t0x00000000\tMIPS-I\n>>>>36  belong&0xf0000000\t0x10000000\tMIPS-II\n>>>>36  belong&0xf0000000\t0x20000000\tMIPS-III\n>>>>36  belong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>36  belong&0xf0000000\t0x40000000\tMIPS-V\n>>>>36  belong&0xf0000000\t0x60000000\tMIPS32\n>>>>36  belong&0xf0000000\t0x70000000\tMIPS64\n>>>>36  belong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>36  belong&0xf0000000\t0x90000000\tMIPS64 rel2\n# only for 64-bit\n>>>4\tbyte\t\t2\n>>>>48\tbelong&0xf0000000\t0x00000000\tMIPS-I\n>>>>48\tbelong&0xf0000000\t0x10000000\tMIPS-II\n>>>>48\tbelong&0xf0000000\t0x20000000\tMIPS-III\n>>>>48\tbelong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>48\tbelong&0xf0000000\t0x40000000\tMIPS-V\n>>>>48\tbelong&0xf0000000\t0x60000000\tMIPS32\n>>>>48\tbelong&0xf0000000\t0x70000000\tMIPS64 \n>>>>48\tbelong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>48\tbelong&0xf0000000\t0x90000000\tMIPS64 rel2\n>>16\tbeshort\t\t0\t\tno file type,\n>>16\tbeshort\t\t1\t\trelocatable,\n>>16\tbeshort\t\t2\t\texecutable,\n>>16\tbeshort\t\t3\t\tshared object,\n>>16\tbeshort\t\t4\t\tcore file,\n#>>>(0x38+0xcc) string\t>\\0\t\tof '%s'\n#>>>(0x38+0x10) belong\t>0\t\t(signal %d),\n>>16\tbeshort\t\t&0xff00\t\tprocessor-specific,\n>>18\tbeshort\t\t0\t\tno machine,\n>>18\tbeshort\t\t1\t\tAT&T WE32100,\n>>18\tbeshort\t\t2\t\tSPARC,\n>>18\tbeshort\t\t3\t\tIntel 80386 - invalid byte order,\n>>18\tbeshort\t\t4\t\tMotorola\n>>>36\tbelong\t\t&0x01000000\t68000,\n>>>36\tbelong\t\t&0x00810000\tCPU32,\n>>>36\tbelong\t\t0\t\t68020,\n>>18\tbeshort\t\t5\t\tMotorola 88000,\n>>18\tbeshort\t\t6\t\tIntel 80486 - invalid byte order,\n>>18\tbeshort\t\t7\t\tIntel 80860,\n>>18\tbeshort\t\t8\t\tMIPS,\n>>18\tbeshort\t\t9\t\tAmdahl,\n>>18\tbeshort\t\t10\t\tMIPS (deprecated),\n>>18\tbeshort\t\t11\t\tRS6000,\n>>18\tbeshort\t\t15\t\tPA-RISC\n>>>50\tbeshort\t\t0x0214\t\t2.0\n>>>48\tbeshort\t\t&0x0008\t\t(LP64)\n>>18\tbeshort\t\t16\t\tnCUBE,\n>>18\tbeshort\t\t17\t\tFujitsu VPP500,\n>>18\tbeshort\t\t18\t\tSPARC32PLUS,\n>>>36\tbelong&0xffff00\t&0x000100\tV8+ Required,\n>>>36\tbelong&0xffff00\t&0x000200\tSun UltraSPARC1 Extensions Required,\n>>>36\tbelong&0xffff00\t&0x000400\tHaL R1 Extensions Required,\n>>>36\tbelong&0xffff00\t&0x000800\tSun UltraSPARC3 Extensions Required,\n>>18\tbeshort\t\t20\t\tPowerPC or cisco 4500,\n>>18\tbeshort\t\t21\t\tcisco 7500,\n>>18\tbeshort\t\t22\t\tIBM S/390,\n>>18\tbeshort\t\t24\t\tcisco SVIP,\n>>18\tbeshort\t\t25\t\tcisco 7200,\n>>18\tbeshort\t\t36\t\tNEC V800 or cisco 12000,\n>>18\tbeshort\t\t37\t\tFujitsu FR20,\n>>18\tbeshort\t\t38\t\tTRW RH-32,\n>>18\tbeshort\t\t39\t\tMotorola RCE,\n>>18\tbeshort\t\t40\t\tARM,\n>>18\tbeshort\t\t41\t\tAlpha,\n>>18\tbeshort\t\t42\t\tHitachi SH,\n>>18\tbeshort\t\t43\t\tSPARC V9,\n>>18\tbeshort\t\t44\t\tSiemens Tricore Embedded Processor,\n>>18\tbeshort\t\t45\t\tArgonaut RISC Core, Argonaut Technologies Inc.,\n>>18\tbeshort\t\t46\t\tHitachi H8/300,\n>>18\tbeshort\t\t47\t\tHitachi H8/300H,\n>>18\tbeshort\t\t48\t\tHitachi H8S,\n>>18\tbeshort\t\t49\t\tHitachi H8/500,\n>>18\tbeshort\t\t50\t\tIntel Merced Processor,\n>>18\tbeshort\t\t51\t\tStanford MIPS-X,\n>>18\tbeshort\t\t52\t\tMotorola Coldfire,\n>>18\tbeshort\t\t53\t\tMotorola M68HC12,\n>>18\tbeshort\t\t73\t\tCray NV1,\n>>18\tbeshort\t\t75\t\tDigital VAX,\n>>18\tbeshort\t\t97\t\tNatSemi 32k,\n>>18\tbeshort\t\t0x9026\t\tAlpha (unofficial),\n>>18\tbeshort\t\t0xa390\t\tIBM S/390 (obsolete),\n>>18    beshort         0xde3d          Ubicom32,\n>>20\tbelong\t\t0\t\tinvalid version\n>>20\tbelong\t\t1\t\tversion 1\n>>36\tbelong\t\t1\t\tMathCoPro/FPU/MAU Required\n# Up to now only 0, 1 and 2 are defined; I've seen a file with 0x83, it seemed\n# like proper ELF, but extracting the string had bad results.\n>4      byte            <0x80\n>>8\tstring\t\t>\\0\t\t(\"%s\")\n>8\tstring\t\t\\0\n>>7\tbyte\t\t0\t\t(SYSV)\n>>7\tbyte\t\t1\t\t(HP-UX)\n>>7\tbyte\t\t2\t\t(NetBSD)\n>>7\tbyte\t\t3\t\t(GNU/Linux)\n>>7\tbyte\t\t4\t\t(GNU/Hurd)\n>>7\tbyte\t\t5\t\t(86Open)\n>>7\tbyte\t\t6\t\t(Solaris)\n>>7\tbyte\t\t7\t\t(Monterey)\n>>7\tbyte\t\t8\t\t(IRIX)\n>>7\tbyte\t\t9\t\t(FreeBSD)\n>>7\tbyte\t\t10\t\t(Tru64)\n>>7\tbyte\t\t11\t\t(Novell Modesto)\n>>7\tbyte\t\t12\t\t(OpenBSD)\n>>7\tbyte\t\t97\t\t(ARM)\n>>7\tbyte\t\t255\t\t(embedded)\n\n# XXX - according to Microsoft's spec, at an offset of 0x3c in a\n# PE-format executable is the offset in the file of the PE header;\n# unfortunately, that's a little-endian offset, and there's no way\n# to specify an indirect offset with a specified byte order.\n# So, for now, we assume the standard MS-DOS stub, which puts the\n# PE header at 0x80 = 128.\n#\n# Required OS version and subsystem version were 4.0 on some NT 3.51\n# executables built with Visual C++ 4.0, so it's not clear that\n# they're interesting.  The user version was 0.0, but there's\n# probably some linker directive to set it.  The linker version was\n# 3.0, except for one \".exe\" which had it as 4.20 (same damn linker!).\n#\n# many of the compressed formats were extraced from IDARC 1.23 source code\n#\n0       string  MZ\tMicrosoft\n>0x18  leshort <0x40 MS-DOS executable\n>0 string MZ\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0PE\\0\\0 \\b, PE for MS Windows\n>>&18   leshort&0x2000  >0      (DLL)\n>>&88   leshort         0       (unknown subsystem)\n>>&88   leshort         1       (native)\n>>&88   leshort         2       (GUI)\n>>&88   leshort         3       (console)\n>>&88   leshort         7       (POSIX)\n>>&0    leshort         0x0     unknown processor\n>>&0    leshort         0x14c   Intel 80386\n>>&0    leshort         0x166   MIPS R4000\n>>&0    leshort         0x184   Alpha\n>>&0    leshort         0x268   Motorola 68000\n>>&0    leshort         0x1f0   PowerPC\n>>&0    leshort         0x290   PA-RISC\n>>&18   leshort&0x0100  >0      32-bit\n>>&18   leshort&0x1000  >0      system file\n>>&228  lelong          >0      \\b, Mono/.Net assembly\n>>&0xf4 search/0x140 \\x0\\x40\\x1\\x0\n>>>(&0.l+(4)) string MSCF \\b, WinHKI CAB self-extracting archive\n>30             string  Copyright\\x201989-1990\\x20PKWARE\\x20Inc.      Self-extracting PKZIP archive\n# Is next line correct? One might expect \"Corp.\" not \"Copr.\" If it is right, add a note to that effect.\n>30             string  PKLITE\\x20Copr.   Self-extracting PKZIP archive\n\n>0x18  leshort >0x3f\n>>(0x3c.l) string PE\\0\\0 PE\n>>>(0x3c.l+25) byte             1 \\b32 executable\n>>>(0x3c.l+25) byte             2 \\b32+ executable\n# hooray, there's a DOS extender using the PE format, with a valid PE\n# executable inside (which just prints a message and exits if run in win)\n>>>(0x3c.l+92)  leshort         <10\n>>>>(8.s*16) string 32STUB for MS-DOS, 32rtm DOS extender\n>>>>(8.s*16) string !32STUB for MS Windows\n>>>>>(0x3c.l+22)        leshort&0x2000  >0      (DLL)\n>>>>>(0x3c.l+92)        leshort         0       (unknown subsystem)\n>>>>>(0x3c.l+92)        leshort         1       (native)\n>>>>>(0x3c.l+92)        leshort         2       (GUI)\n>>>>>(0x3c.l+92)        leshort         3       (console)\n>>>>>(0x3c.l+92)        leshort         7       (POSIX)\n>>>(0x3c.l+92)  leshort         10      (EFI application)\n>>>(0x3c.l+92)  leshort         11      (EFI boot service driver)\n>>>(0x3c.l+92)  leshort         12      (EFI runtime driver)\n>>>(0x3c.l+92)  leshort         13      (XBOX)\n>>>(0x3c.l+4)   leshort         0x0     unknown processor\n>>>(0x3c.l+4)   leshort         0x14c   Intel 80386\n>>>(0x3c.l+4)   leshort         0x166   MIPS R4000\n>>>(0x3c.l+4)   leshort         0x184   Alpha\n>>>(0x3c.l+4)   leshort         0x268   Motorola 68000\n>>>(0x3c.l+4)   leshort         0x1f0   PowerPC\n>>>(0x3c.l+4)   leshort         0x290   PA-RISC\n>>>(0x3c.l+4)   leshort         0x200   Intel Itanium\n>>>(0x3c.l+22)  leshort&0x0100  >0      32-bit\n>>>(0x3c.l+22)  leshort&0x1000  >0      system file\n>>>(0x3c.l+232) lelong  >0      Mono/.Net assembly\n>>>>(0x3c.l+0xf8)       string          UPX0 \\b, UPX compressed\n>>>>(0x3c.l+0xf8)       search/0x140    PEC2 \\b, PECompact2 compressed\n>>>>(0x3c.l+0xf8)       search/0x140    UPX2\n>>>>>(&0x10.l+(-4))     string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>(0x3c.l+0xf8)       search/0x140    .idata\n>>>>>(&0xe.l+(-4))      string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>>(&0xe.l+(-4))      string          ZZ0 \\b, ZZip self-extracting archive\n>>>>>(&0xe.l+(-4))      string          ZZ1 \\b, ZZip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .rsrc\n>>>>>(&0x0f.l+(-4))     string          a\\\\\\4\\5 \\b, WinHKI self-extracting archive\n>>>>>(&0x0f.l+(-4))     string          Rar! \\b, RAR self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/0x3000   MSCF \\b, InstallShield self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/32       Nullsoft \\b, Nullsoft Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .data\n>>>>>(&0x0f.l)          string          WEXTRACT \\b, MS CAB-Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .petite\\0 \\b, Petite compressed\n>>>>>(0x3c.l+0xf7)      byte            x\n>>>>>>(&0x104.l+(-4))   string          =!sfx! \\b, ACE self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .WISE \\b, WISE installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .dz\\0\\0\\0 \\b, Dzip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .reloc\n>>>>>(&0xe.l+(-4))      search/0x180    PK\\3\\4 \\b, ZIP self-extracting archive (WinZip)\n\n>>>>&(0x3c.l+0xf8)      search/0x100    _winzip_ \\b, ZIP self-extracting archive (WinZip)\n>>>>&(0x3c.l+0xf8)      search/0x100    SharedD \\b, Microsoft Installer self-extracting archive\n>>>>0x30                string          Inno \\b, InnoSetup self-extracting archive\n\n>>(0x3c.l) string !PE\\0\\0 MS-DOS executable\n\n>>(0x3c.l)              string          NE \\b, NE\n>>>(0x3c.l+0x36)        byte            0 (unknown OS)\n>>>(0x3c.l+0x36)        byte            1 for OS/2 1.x\n>>>(0x3c.l+0x36)        byte            2 for MS Windows 3.x\n>>>(0x3c.l+0x36)        byte            3 for MS-DOS\n>>>(0x3c.l+0x36)        byte            >3 (unknown OS)\n>>>(0x3c.l+0x36)        byte            0x81 for MS-DOS, Phar Lap DOS extender\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8002 (DLL)\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8001 (driver)\n>>>&(&0x24.s-1)         string          ARJSFX \\b, ARJ self-extracting archive\n>>>(0x3c.l+0x70)        search/0x80     WinZip(R)\\x20Self-Extractor \\b, ZIP self-extracting archive (WinZip)\n\n>>(0x3c.l)              string          LX\\0\\0 \\b, LX\n>>>(0x3c.l+0x0a)        leshort         <1 (unknown OS)\n>>>(0x3c.l+0x0a)        leshort         1 for OS/2\n>>>(0x3c.l+0x0a)        leshort         2 for MS Windows\n>>>(0x3c.l+0x0a)        leshort         3 for DOS\n>>>(0x3c.l+0x0a)        leshort         >3 (unknown OS)\n>>>(0x3c.l+0x10)        lelong&0x28000  =0x8000 (DLL)\n>>>(0x3c.l+0x10)        lelong&0x20000  >0 (device driver)\n>>>(0x3c.l+0x10)        lelong&0x300    0x300 (GUI)\n>>>(0x3c.l+0x10)        lelong&0x28300  <0x300 (console)\n>>>(0x3c.l+0x08)        leshort         1 i80286\n>>>(0x3c.l+0x08)        leshort         2 i80386\n>>>(0x3c.l+0x08)        leshort         3 i80486\n>>>(8.s*16)             string          emx \\b, emx\n>>>>&1                  string          x \"%s\"\n>>>&(&0x54.l-3)         string          arjsfx \\b, ARJ self-extracting archive\n\n\n\n#------------------------------------------------------------------------------\n# bFLT: file(1) magic for BFLT uclinux binary files\n#\n# From Philippe De Muyter <phdm@macqel.be>\n# \n# Additional fields added by Craig Heffner\n#\n0       string          bFLT            BFLT executable \n>4      belong          x               version %ld, \n>4      belong          4\n>8\tbelong\t\tx\t\tcode offset: 0x%.8X, \n>12\tbelong\t\tx\t\tdata segment starts at: 0x%.8X, \n>16\tbelong\t\tx\t\tbss segment starts at: 0x%.8X, \n>20\tbelong\t\tx\t\tbss segment ends at: 0x%.8X, \n>24\tbelong\t\tx\t\tstack size: %d bytes, \n>28\tbelong \t\tx\t\trelocation records start at: 0x%.8X, \n>32\tbelong\t\tx\t\tnumber of reolcation records: %d, \n>>36    belong&0x1      0x1             ram\n>>36    belong&0x2      0x2             gotpic\n>>36    belong&0x4      0x4             gzip\n>>36    belong&0x8      0x8             gzdata\n\n\n#-----------------------------------------------------------------\n# MIPS COFF file formats\n#\n0       beshort 0x0160          MIPSEB ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x0162          MIPSEL-BE ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x6001          MIPSEB-LE ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x6201          MIPSEL ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n# MIPS 2 additions\n#\n0       beshort 0x0163          MIPSEB MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x0166          MIPSEL-BE MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x6301          MIPSEB-LE MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x6601          MIPSEL MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n# MIPS 3 additions\n#\n0       beshort 0x0140          MIPSEB MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x0142          MIPSEL-BE MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x4001          MIPSEB-LE MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x4201          MIPSEL MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x180           MIPSEB Ucode\n0       beshort 0x182           MIPSEL-BE Ucode\n\n\n# Windows CE package files\n0       string          MSCE\\0\\0\\0\\0    Microsoft WinCE installer\n>20     lelong          0               \\b, architecture-independent\n>20     lelong          103             \\b, Hitachi SH3\n>20     lelong          104             \\b, Hitachi SH4\n>20     lelong          0xA11           \\b, StrongARM\n>20     lelong          4000            \\b, MIPS R4000\n>20     lelong          10003           \\b, Hitachi SH3\n>20     lelong          10004           \\b, Hitachi SH3E\n>20     lelong          10005           \\b, Hitachi SH4\n>20     lelong          70001           \\b, ARM 7TDMI\n>52     leshort         1               \\b, 1 file\n>52     leshort         >1              \\b, %u files\n>56     leshort         1               \\b, 1 registry entry\n>56     leshort         >1              \\b, %u registry entries\n\n#------------------------------------------------------------------------------\n# Microsoft Xbox executables .xbe (Esa HyytiÃ¤ <ehyytia@cc.hut.fi>)\n0       string          XBEH            XBE, Microsoft Xbox executable\n# probabilistic checks whether signed or not\n>0x0004 ulelong =0x0\n>>&2    ulelong =0x0\n>>>&2   ulelong =0x0  \\b, not signed\n>0x0004 ulelong >0\n>>&2    ulelong >0\n>>>&2   ulelong >0    \\b, signed\n# expect base address of 0x10000\n>0x0104               ulelong =0x10000\n>>(0x0118-0x0FF60)    ulelong&0x80000007  0x80000007 \\b, all regions\n>>(0x0118-0x0FF60)    ulelong&0x80000007  !0x80000007\n>>>(0x0118-0x0FF60)   ulelong >0           (regions:\n>>>>(0x0118-0x0FF60)  ulelong &0x00000001  NA\n>>>>(0x0118-0x0FF60)  ulelong &0x00000002  Japan\n>>>>(0x0118-0x0FF60)  ulelong &0x00000004  Rest_of_World\n>>>>(0x0118-0x0FF60)  ulelong &0x80000000  Manufacturer\n>>>(0x0118-0x0FF60)   ulelong >0           \\b)\n\n#------------------------------------------------------------------------------\n# motorola:  file(1) magic for Motorola 68K and 88K binaries\n#\n# 68K\n#\n0       beshort         0x0208          mc68k COFF\n>18     beshort         ^00000020       object\n>18     beshort         &00000020       executable\n>12     belong          >0              not stripped\n>168    string          .lowmem         Apple toolbox\n>20     beshort         0407            (impure)\n>20     beshort         0410            (pure)\n>20     beshort         0413            (demand paged)\n>20     beshort         0421            (standalone)\n0       beshort         0x0209          mc68k executable (shared)\n>12     belong          >0              not stripped\n0       beshort         0x020A          mc68k executable (shared demand paged)\n>12     belong          >0              not stripped\n\n\n#\n# Motorola/UniSoft 68K Binary Compatibility Standard (BCS)\n#\n0       beshort         0x022A            68K BCS executable\n#\n# 88K\n#\n# Motorola/88Open BCS\n#\n0       beshort         0x022B            88K BCS executable\n\n#------------------------------------------------------------------------------\n# Sony Playstation executables (Adam Sjoegren <asjo@diku.dk>) :\n0       string  PS-X\\x20EXE       Sony Playstation executable\n#  Area:\n>113    string  x               (\"%s\")\n\n#------------------------------------------------------------------------------\n# cisco:  file(1) magic for cisco Systems routers\n#\n# Most cisco file-formats are covered by the generic elf code\n#\n# Microcode files are non-ELF, 0x8501 conflicts with NetBSD/alpha.\n0\tbeshort\t\t\t0x8501\t    cisco IOS\n>0      belong&0xffffff00       0x85011400  microcode\n>0      belong&0xffffff00       0x8501cb00  experimental microcode\n>7      string          \t>\\0         for \"%s\"\n\n# EST flat binary format (which isn't, but anyway)\n# From: Mark Brown <broonie@sirena.org.uk>\n0\tstring\tESTFBINR\tEST flat binary\n\n# These are not the binaries themselves, but string references to them\n# are a strong indication that they exist elsewhere...\n#0\tstring\t/bin/busybox\tBusybox string reference: \"%s\"{one-of-many}\n#0\tstring /bin/sh\t\tShell string reference: \"%s\"{one-of-many}\n\n#--------------------File Systems---------------------\n\n# Minix filesystems - Juan Cespedes <cespedes@debian.org>\n0x410   leshort         0x137f          Minix filesystem\n>0x402  beshort         !0              \\b, %d zones\n>0x1e   string          minix           \\b, bootable\n0x410   leshort         0x138f          Minix filesystem, 30 char names\n0x410   leshort         0x2468          Minix filesystem, version 2\n0x410   leshort         0x2478          Minix filesystem, version 2, 30 char names\n0x410\tleshort\t\t0x4d5a\t\tMinix filesystem, version 3\n0x410\tleshort\t\t0x4d6a\t\tMinix filesystem, version 3, 30 char names\n\n0x410   beshort         0x137f          Minix filesystem (big endian)\n>0x402  beshort         !0              \\b, %d zones\n>0x1e   string          minix           \\b, bootable\n0x410   beshort         0x138f          Minix filesystem (big endian), 30 char names\n0x410   beshort         0x2468          Minix filesystem (big endian), version 2\n0x410   beshort         0x2478          Minix filesystem (big endian), version 2, 30 char names\n0x410\tbeshort\t\t0x4d5a\t\tMinix filesystem (big endian), version 3\n0x410\tbeshort\t\t0x4d6a\t\tMinix filesystem (big endian), version 3, 30 char names\n\n# YAFFS\n0\tstring\t\\x03\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\xFF\\xFF\tYAFFS filesystem\n\n# EFS2 file system - jojo@utulsa.edu\n0      lelong 0x53000000       EFS2 Qualcomm filesystem super block, little endian,\n>8     string !EFSSuper        invalid,\n>4     leshort &1              NAND\n>4     leshort ^1              NOR\n>4     leshort x               version 0x%x,\n>24    lelong  x               %d blocks,\n>16    lelong  x               0x%x pages per block,\n>20    lelong  x               0x%x bytes per page\n\n0      belong 0x53000000       EFS2 Qualcomm filesystem super block, big endian,\n>8     string !SSFErepu\t       invalid,\n>4     beshort &1              NAND\n>4     beshort ^1              NOR\n>4     beshort x               version 0x%x,\n>24    belong  x               %d blocks,\n>16    belong  x               0x%x pages per block,\n>20    belong  x               0x%x bytes per page\n\n# TROC file system\n0\tstring\tTROC\t\tTROC filesystem,\n>4\tlelong\tx\t\t%d file entries\n\n# PFS file system\n0\tstring\tPFS/\t\tPFS filesystem,\n>4\tstring\tx\t\tversion \"%s\",\n>14\tleshort\tx\t\t%d files\n\n# MPFS file system\n0\tstring\tMPFS\t\tMPFS (Microchip) filesystem,\n>4\tbyte\tx\t\tversion %d.\n>5\tbyte\tx\t\t\\b%d,\n>6\tleshort\tx\t\t%d file entries\n\n# cramfs filesystem - russell@coker.com.au\n0       lelong  0x28cd3d45      CramFS filesystem, little endian\n>4\tlelong\t<0\t\tinvalid\n>4      lelong  x \t\tsize %lu\n>8      lelong  &1 \t\tversion #2\n>8      lelong  &2 \t\tsorted_dirs\n>8      lelong  &4 \t\thole_support\n>32     lelong  x \t\tCRC 0x%x,\n>36     lelong  x \t\tedition %lu,\n>40\tlelong\t<0\t\tinvalid\n>40     lelong  x \t\t%lu blocks,\n>44\tlelong\t<0\t\tinvalid\n>44     lelong  x \t\t%lu files\n>4      lelong  x \t\t{jump-to-offset:%lu}\n>4      lelong  x \t\t{file-size:%lu}\n\n0       belong  0x28cd3d45      CramFS filesystem, big endian\n>4\tbelong\t<0\t\tinvalid\n>4      belong  x \t\tsize %lu\n>8      belong  &1 \t\tversion #2\n>8      belong  &2 \t\tsorted_dirs\n>8      belong  &4 \t\thole_support\n>32     belong  x \t\tCRC 0x%x,\n>36     belong  x \t\tedition %lu,\n>40\tbelong\t<0\t\tinvalid\n>40     belong  x \t\t%lu blocks,\n>44\tbelong\t<0\t\tinvalid\n>44     belong  x \t\t%lu files\n>4      belong  x \t\t{jump-to-offset:%lu}\n>4      belong  x \t\t{file-size:%lu}\n\n\n\n# JFFS2 file system\n# If used with binwalk's smart signature feature (on by default, -S to disable)\n# this signature can potentially lead to missing some JFFS2 file systems if there\n# are multiple JFFS2 file systems in a target file and there are no other identified\n# files in between the JFFS2 file systems. This is an unlikely scenario however, and\n# the below signatures are much improved in terms of readability and accuracy in the\n# vast majority of real world scenarios.\n0\t\tleshort 0x1985\tJFFS2 filesystem, little endian{filter-include}\n>2\t\tleshort !0xE001\n>>2\t\tleshort !0xE002\n>>>2\t\tleshort !0x2003\n>>>>2\t\tleshort !0x2004\n>>>>>2\t\tleshort !0x2006\n>>>>>>2\t\tleshort !0xE008\n>>>>>>>2\tleshort !0xE009\t\\b, invalid\n>(4.l)\t\tleshort !0x1985\t\t\n>>(4.l+1)\tleshort !0x1985\t\n>>>(4.l+2)\tleshort !0x1985\t\n>>>>(4.l+3)\tleshort !0x1985\n>>>>>(4.l)      leshort !0xFFFF\n>>>>>>(4.l+1)   leshort !0xFFFF\n>>>>>>>(4.l+2)  leshort !0xFFFF\n>>>>>>>>(4.l+3) leshort !0xFFFF \\b, invalid\n>4\t\tlelong\tx\t{one-of-many}{jump-to-offset:%d}\n\n0       \tbeshort 0x1985\tJFFS2 filesystem, big endian{filter-include}\n>2\t\tbeshort !0xE001\n>>2\t\tbeshort !0xE002\n>>>2\t\tbeshort !0x2003\n>>>>2\t\tbeshort !0x2004\n>>>>>2\t\tbeshort !0x2006\n>>>>>>2\t\tbeshort !0xE008\n>>>>>>>2\tbeshort !0xE009\t\\b, invalid\n>(4.L)\t\tbeshort\t!0x1985\t \n>>(4.L+1)\tbeshort\t!0x1985\t \n>>>(4.L+2)\tbeshort\t!0x1985\n>>>>(4.L+3)\tbeshort\t!0x1985\t\n>>>>>(4.L)\tbeshort !0xFFFF\n>>>>>>(4.L+1)\tbeshort !0xFFFF\n>>>>>>>(4.L+2)\tbeshort !0xFFFF\n>>>>>>>>(4.L+3)\tbeshort !0xFFFF \\b, invalid\n>4\t\tbelong\tx\t{one-of-many}{jump-to-offset:%d}\n\n\n# Squashfs, big endian\n0       string  sqsh    Squashfs filesystem, big endian,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28\tbeshort <3\n>>8\tbelong\tx\t{jump-to-offset:%d}\n>28\tbeshort\t3\t\n>>63\tbequad\tx\t{jump-to-offset:%lld}\n>28\tbeshort\t>3\n>>40\tbequad\tx\t{jump-to-offset:%lld}\n\n# Squashfs, little endian\n0       string  hsqs    Squashfs filesystem, little endian,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>30\tleshort >10\tinvalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28\tleshort >3\tcompression: \n>>20\tleshort 1\t\\bgzip,\n>>20\tleshort\t2\t\\blzma,\n>>20\tleshort 0\t\\binvalid,\n>>20\tleshort >4\t\\binvalid,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>>8     lelong  x       {file-size:%d}\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>>63    lequad x        {file-size:%lld}\n>28\tleshort >3\t\n>>40\tlequad\tx\tsize: %lld bytes,\n>>40\tlequad\tx\t{file-size:%lld}\n>4      lelong  x       %d inodes,\n>28\tleshort >3\n>>12\tlelong\t\tblocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28\tleshort 3\n>>51\tlelong \tx\tblocksize: %d bytes,\n>28\tleshort\t>3\t\n>>12\tlelong\tx\tblocksize: %d bytes,\n>28\tleshort <4\n>>39    ledate  x\tcreated: %s\n>28\tleshort >3\n>>8\tledate x\tcreated: %s\n>28     leshort <3\n>>8     lelong  x       {jump-to-offset:%d}\n>28     leshort 3\n>>63    lequad x        {jump-to-offset:%lld}\n>28     leshort >3\n>>40    lequad  x       {jump-to-offset:%lld}\n\n# Squashfs with LZMA compression\n0       string  sqlz    Squashfs filesystem, big endian, lzma compression, \n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>>8     belong  x       {file-size:%d}\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>>63    bequad x        {file-size:%lld}\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>>40    bequad  x       {file-size:%lld}\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28     beshort <3\n>>8     belong  x       {jump-to-offset:%d}\n>28     beshort 3\n>>63    bequad  x       {jump-to-offset:%lld}\n>28     beshort >3\n>>40    bequad  x       {jump-to-offset:%lld}\n\n# Squashfs 3.3 LZMA signature\n0       string  qshs    Squashfs filesystem, big endian, lzma signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>>8     belong  x       {file-size:%d}\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>>63    bequad x        {file-size:%lld}\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>>40    bequad  x       {file-size:%lld}\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28     beshort <3\n>>8     belong  x       {jump-to-offset:%d}\n>28     beshort 3\n>>63    bequad  x       {jump-to-offset:%lld}\n>28     beshort >3\n>>40    bequad  x       {jump-to-offset:%lld}\n\n# Squashfs for DD-WRT\n0       string  tqsh    Squashfs filesystem, big endian, DD-WRT signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>>8     belong  x       {file-size:%d}\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>>63    bequad x        {file-size:%lld}\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>>40    bequad  x       {file-size:%lld}\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28     beshort <3\n>>8     belong  x       {jump-to-offset:%d}\n>28     beshort 3\n>>63    bequad  x       {jump-to-offset:%lld}\n>28     beshort >3\n>>40    bequad  x       {jump-to-offset:%lld}\n\n# Squashfs for DD-WRT\n0       string  hsqt    Squashfs filesystem, little endian, DD-WRT signature,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>30\tleshort >10\tinvalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort >3      compression:\n>>20    leshort 1       \\bgzip,\n>>20    leshort 2       \\blzma,\n>>20    leshort 0       \\binvalid,\n>>20    leshort >4      \\binvalid,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>>8     lelong  x       {file-size:%d}\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>>63    lequad x        {file-size:%lld}\n>28     leshort >3\n>>40    lequad  x       size: %lld bytes,\n>>40    lequad  x       {file-size:%lld}\n>4      lelong  x       %d inodes,\n>28     leshort >3\n>>12    lelong          blocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort 3\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort >3\n>>12    lelong  x       blocksize: %d bytes,\n>28     leshort <4\n>>39    ledate  x       created: %s\n>28     leshort >3\n>>8     ledate x        created: %s\n>28     leshort <3\n>>8     lelong  x       {jump-to-offset:%d}\n>28     leshort 3\n>>63    lequad x        {jump-to-offset:%lld}\n>28     leshort >3\n>>40    lequad  x       {jump-to-offset:%lld}\n\n# Non-standard Squashfs signature found on some D-Link routers\n0       string  shsq    Squashfs filesystem, little endian, non-standard signature, \n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>30\tleshort >10\tinvalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort >3      compression:\n>>20    leshort 1       \\bgzip,\n>>20    leshort 2       \\blzma,\n>>20    leshort 0       \\binvalid,\n>>20    leshort >4      \\binvalid,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>>8     lelong  x       {file-size:%d}\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>>63    lequad x        {file-size:%lld}\n>28     leshort >3\n>>40    lequad  x       size: %lld bytes,\n>>40    lequad  x       {file-size:%lld}\n>4      lelong  x       %d inodes,\n>28     leshort >3\n>>12    lelong          blocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort 3\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort >3\n>>12    lelong  x       blocksize: %d bytes,\n>28     leshort <4\n>>39    ledate  x       created: %s\n>28     leshort >3\n>>8     ledate x        created: %s\n>28     leshort <3\n>>8     lelong  x       {jump-to-offset:%d}\n>28     leshort 3\n>>63    lequad x        {jump-to-offset:%lld}\n>28     leshort >3\n>>40    lequad  x       {jump-to-offset:%lld}\n\n# ext2/ext3 filesystems - Andreas Dilger <adilger@dilger.ca>\n# ext4 filesystem - Eric Sandeen <sandeen@sandeen.net>\n# volume label and UUID Russell Coker\n# http://etbe.coker.com.au/2008/07/08/label-vs-uuid-vs-device/\n0   leshort         0xEF53      \tLinux EXT filesystem,{filter-include}{offset-adjust:-0x438}\n>2\tleshort\t\t>4\t\tinvalid state\n>2\tleshort\t\t3\t\tinvalid state\n>2\tleshort\t\t<0\t\tinvalid state\n>4\tleshort\t\t>3\t\tinvalid error behavior\n>4\tleshort\t\t<0\t\tinvalid error behavior\n>4\tlelong\t\t>1\t\tinvalid major revision\n>4  lelong\t\t<0\t\tinvalid major revision\n>4  lelong          x               rev %d\n>6  leshort         x               \\b.%d\n# No journal?  ext2\n>36  lelong          ^0x0000004      ext2 filesystem data\n>>2 leshort         ^0x0000001      (mounted or unclean)\n# Has a journal?  ext3 or ext4\n>36  lelong          &0x0000004\n#  and small INCOMPAT?\n>>40 lelong          <0x0000040\n#   and small RO_COMPAT?\n>>>44 lelong         <0x0000008      ext3 filesystem data\n#   else large RO_COMPAT?\n>>>44 lelong         >0x0000007      ext4 filesystem data\n#  else large INCOMPAT?\n>>40 lelong          >0x000003f      ext4 filesystem data\n>48  belong          x               \\b, UUID=%08x\n>52  beshort         x               \\b-%04x\n>54  beshort         x               \\b-%04x\n>56  beshort         x               \\b-%04x\n>58  belong          x               \\b-%08x\n>60  beshort         x               \\b%04x\n>64  string          >0              \\b, volume name \"%s\"\n\n\n#romfs filesystems - Juan Cespedes <cespedes@debian.org>\n0       string\t-rom1fs-\\0\t\tromfs filesystem, version 1\n>8\tbelong\t>10000000\t\tinvalid\n>8      belong  x                       size: %d bytes,\n>16\tstring\tx\t\t\t{file-name:%s}\n>16     string  x                       named \"%s\"\n>8\tbelong\tx\t\t\t{file-size:%d}\n>8\tbelong\tx\t\t\t{jump-to-offset:%d}\n\n# Wind River MemFS file system, found in some VxWorks devices\n0\tstring\towowowowowowowowowowowowowowow\t\tWind River management filesystem,\n>30\tstring\t!ow\t\t\t\t\tinvalid,\n>32\tbelong\t1\t\t\t\t\tcompressed,\n>32\tbelong\t2\t\t\t\t\tplain text,\n>36\tbelong\tx\t\t\t\t\t%d files\n\n\n# netboot image - Juan Cespedes <cespedes@debian.org>\n0\tlelong\t\t\t0x1b031336L\tNetboot image,\n>4\tlelong&0xFFFFFF00\t0\n>>4\tlelong&0x100\t\t0x000\t\tmode 2\n>>4\tlelong&0x100\t\t0x100\t\tmode 3\n>4\tlelong&0xFFFFFF00\t!0\t\tunknown mode (invalid)\n\n#--------------------------Firmware Formats---------------------------\n\n# uImage file     \n# From: Craig Heffner, U-Boot image.h header definitions file\n0\tbelong\t0x27051956\tuImage header, header size: 64 bytes,\n>4\tbelong\tx\t\theader CRC: 0x%X,\n>8\tbedate\tx\t\tcreated: %s,\n>12\tbelong\tx\t\timage size: %d bytes,\n>16\tbelong\tx\t\tData Address: 0x%X,\n>20\tbelong\tx\t\tEntry Point: 0x%X,\n>24\tbelong\tx\t\tdata CRC: 0x%X,\n#>28\tbyte\tx\t\tOS type: %d,\n>28\tbyte\t0\t\tOS: invalid OS,\n>28\tbyte\t1\t\tOS: OpenBSD,\n>28\tbyte\t2\t\tOS: NetBSD,\n>28\tbyte\t3\t\tOS: FreeBSD,\n>28\tbyte\t4\t\tOS: 4.4BSD,\n>28\tbyte\t5\t\tOS: Linux,\n>28\tbyte\t6\t\tOS: SVR4,\n>28\tbyte\t7\t\tOS: Esix,\n>28\tbyte\t8\t\tOS: Solaris,\n>28\tbyte\t9\t\tOS: Irix,\n>28\tbyte\t10\t\tOS: SCO,\n>28\tbyte\t11\t\tOS: Dell,\n>28\tbyte\t12\t\tOS: NCR,\n>28\tbyte\t13\t\tOS: LynxOS,\n>28\tbyte\t14\t\tOS: VxWorks,\n>28\tbyte\t15\t\tOS: pSOS,\n>28\tbyte\t16\t\tOS: QNX,\n>28\tbyte\t17\t\tOS: Firmware,\n>28\tbyte\t18\t\tOS: RTEMS,\n>28\tbyte\t19\t\tOS: ARTOS,\n>28\tbyte\t20\t\tOS: Unity OS,\n#>29\tbyte\tx\t\tCPU arch: %d,\n>29\tbyte\t0\t\tCPU: invalid OS,\n>29\tbyte\t1\t\tCPU: Alpha,\n>29\tbyte\t2\t\tCPU: ARM,\n>29\tbyte\t3\t\tCPU: Intel x86,\n>29\tbyte\t4\t\tCPU: IA64,\n>29\tbyte\t5\t\tCPU: MIPS,\n>29\tbyte\t6\t\tCPU: MIPS 64 bit,\n>29\tbyte\t7\t\tCPU: PowerPC,\n>29\tbyte\t8\t\tCPU: IBM S390,\n>29\tbyte\t9\t\tCPU: SuperH,\n>29\tbyte\t10\t\tCPU: Sparc,\n>29\tbyte\t11\t\tCPU: Sparc 64 bit,\n>29\tbyte\t12\t\tCPU: M68K,\n>29\tbyte\t13\t\tCPU: Nios-32,\n>29\tbyte\t14\t\tCPU: MicroBlaze,\n>29\tbyte\t15\t\tCPU: Nios-II,\n>29\tbyte\t16\t\tCPU: Blackfin,\n>29\tbyte\t17\t\tCPU: AVR,\n>29\tbyte\t18\t\tCPU: STMicroelectronics ST200,\n#>30\tbyte\tx\t\timage type: %d,\n>30\tbyte\t0\t\timage type: invalid Image,\n>30\tbyte\t1\t\timage type: Standalone Program,\n>30\tbyte\t2\t\timage type: OS Kernel Image,\n>30\tbyte \t3\t\timage type: RAMDisk Image,\n>30\tbyte\t4\t\timage type: Multi-File Image,\n>30\tbyte\t5\t\timage type: Firmware Image,\n>30\tbyte\t6\t\timage type: Script file,\n>30\tbyte\t7\t\timage type: Filesystem Image,\n>30\tbyte\t8\t\timage type: Binary Flat Device Tree Blob\n#>31\tbyte\tx\t\tcompression type: %d,\n>31\tbyte\t0\t\tcompression type: none,\n>31\tbyte\t1\t\tcompression type: gzip,\n>31\tbyte\t2\t\tcompression type: bzip2,\n>31\tbyte\t3\t\tcompression type: lzma,\n>32\tstring\tx\t\timage name: \"%s\"\n\n#IMG0 header, found in VxWorks-based Mercury router firmware\n0\tstring\t\tIMG0\t\tIMG0 (VxWorks) header,\n>4\tbelong\t\tx\t\tsize: %d\n\n#Mediatek bootloader signature\n#From xp-dev.com\n0\tstring\t\tBOOTLOADER!\tMediatek bootloader\n\n#CSYS header formats\n0\tstring\t\tCSYS\\x00\tCSYS header, little endian, \n>8\tlelong\t\tx\t\tsize: %d\n\n0\tstring\t\tCSYS\\x80\tCSYS header, big endian,\n>8\tbelong\t\tx\t\tsize: %d\n\n# wrgg firmware image\n0\tstring\t\twrgg02\t\tWRGG firmware header,\n>6\tstring\t\tx\t\tname: \"%s\",\n>48\tstring\t\tx\t\troot device: \"%s\"\n\n# trx image file\n0\tstring          HDR0            TRX firmware header, little endian, header size: 28 bytes, \n>4\tlelong\t\tx\t\timage size: %d bytes,\n>8\tlelong\t\tx\t\tCRC32: 0x%X\n>12\tlelong\t\tx\t\tflags/version: 0x%X\n\n0\tstring          0RDH            TRX firmware header, big endian, header size: 28 bytes,\n>4\tbelong\t\tx\t\timage size: %d bytes,\n>8\tbelong\t\tx\t\tCRC32: 0x%X\n>12\tbelong\t\tx\t\tflags/version: 0x%X\n\n\n# Ubicom firmware image\n0\tbelong\t0xFA320080\t\tUbicom firmware header,\n>12\tbelong\tx\t\t\tchecksum: 0x%X,\n>24\tbelong\tx\t\t\timage size: %d\n\n# The ROME bootloader is used by several RealTek-based products.\n# Unfortunately, the magic bytes are specific to each product, so\n# separate signatures must be created for each one.\n\n# Netgear KWGR614 ROME image\n0\tstring\t\tG614\t\tRealtek firmware header (ROME bootloader),\n>4\tbeshort\t\t0xd92f\t\timage type: KFS,\n>4\tbeshort\t\t0xb162\t\timage type: RDIR,\n>4\tbeshort\t\t0xea43\t\timage type: BOOT,\n>4\tbeshort\t\t0x8dc9\t\timage type: RUN,\n>4\tbeshort\t\t0x2a05\t\timage type: CCFG,\n>4\tbeshort\t\t0x6ce8\t\timage type: DCFG,\n>4\tbeshort\t\t0xc371\t\timage type: LOG,\n>6\tbyte\t\tx\t\theader version: %d,\n#month\n>10\tbyte\t\tx\t\tcreated: %d/\n#day\t\n>12\tbyte \t\tx\t\t\\b%d/\n#year\n>8\tbeshort\t\tx\t\t\\b%d,\n>16\tbelong\t\tx\t\timage size: %d bytes,\n>22\tbyte\t\tx\t\tbody checksum: 0x%X,\n>23\tbyte\t\tx\t\theader checksum: 0x%X\n\n# Linksys WRT54GX ROME image\n0\tbelong\t\t0x59a0e842\tRealtek firmware header (ROME bootloader)\n>4      beshort         0xd92f          image type: KFS,\n>4      beshort         0xb162          image type: RDIR,\n>4      beshort         0xea43          image type: BOOT,\n>4      beshort         0x8dc9          image type: RUN,\n>4      beshort         0x2a05          image type: CCFG,\n>4      beshort         0x6ce8          image type: DCFG,\n>4      beshort         0xc371          image type: LOG,\n>6      byte            x               header version: %d,\n#month\n>10     byte            x               created: %d/\n#day    \n>12     byte            x               \\b%d/\n#year\n>8      beshort         x               \\b%d,\n>16     belong          x               image size: %d bytes,\n>22     byte            x               body checksum: 0x%X,\n>23     byte            x               header checksum: 0x%X\n\n# PackImg tag, somtimes used as a delimiter between the kernel and rootfs in firmware images.\n0\tstring\t\t--PaCkImGs--\tPackImg section delimiter tag,\n>16\tlelong\t\tx\t\tlittle endian size: %d bytes;\n>16\tbelong\t\tx\t\tbig endian size: %d bytes\n\n\n#------------------------------------------------------------------------------\n# Broadcom header format\n#\n0       string          BCRM            Broadcom header,\n>4      lelong          x               number of sections: %d,\n>>8     lelong          18              first section type: flash\n>>8     lelong          19              first section type: disk\n>>8     lelong          21              first section type: tag\n\n\n# Berkeley Lab Checkpoint Restart (BLCR) checkpoint context files\n# http://ftg.lbl.gov/checkpoint\n0       string  Ck0\\0\\0R\\0\\0\\0  BLCR\n>16     lelong  1       x86\n>16     lelong  3       alpha\n>16     lelong  5       x86-64\n>16     lelong  7       ARM\n>8      lelong  x       context data (little endian, version %d)\n\n0       string  \\0\\0\\0C\\0\\0\\0R  BLCR\n>16     belong  2       SPARC\n>16     belong  4       ppc\n>16     belong  6       ppc64\n>16     belong  7       ARMEB\n>16     belong  8       SPARC64\n>8      belong  x       context data (big endian, version %d)\n\n# Aculab VoIP firmware\n# From: Mark Brown <broonie@sirena.org.uk>\n0       string  VoIP\\x20Startup\\x20and      Aculab VoIP firmware\n>35     string  x       format \"%s\"\n\n#------------------------------------------------------------------------------\n# HP LaserJet 1000 series downloadable firmware file\n0       string  \\xbe\\xefABCDEFGH        HP LaserJet 1000 series downloadable firmware\n\n# From Albert Cahalan <acahalan@gmail.com>\n# really le32 operation,destination,payloadsize (but quite predictable)\n# 01 00 00 00 00 00 00 c0 00 02 00 00\n0       string          \\1\\0\\0\\0\\0\\0\\0\\300\\0\\2\\0\\0      Marvell Libertas firmware\n\n#---------------------------------------------------------------------------\n# The following entries have been tested by Duncan Laurie <duncan@sun.com> (a\n# lead Sun/Cobalt developer) who agrees that they are good and worthy of\n# inclusion.\n\n# Boot ROM images for Sun/Cobalt Linux server appliances\n0       string  Cobalt\\x20Networks\\x20Inc.\\nFirmware\\x20v     Paged COBALT boot rom\n>38     string x        V%.4s\n\n# New format for Sun/Cobalt boot ROMs is annoying, it stores the version code\n# at the very end where file(1) can't get it.\n0       string CRfs     COBALT boot rom data (Flat boot rom or file system)\n\n#\n# Motorola S-Records, from Gerd Truschinski <gt@freebsd.first.gmd.de>\n0   string      S0          Motorola S-Record; binary data in text format\n\n# --------------------------------\n# Microsoft Xbox data file formats\n0       string          XIP0            XIP, Microsoft Xbox data\n0       string          XTF0            XTF, Microsoft Xbox data\n\n#Windows CE\n0\tstring\t\tCECE\t\tWindows CE RTOS{offset-adjust:-64}\n\n# --------------------------------\n# ZynOS ROM header format\n# From openwrt zynos.h.\n0\tstring\t\tSIG\t\tZynOS header, header size: 48 bytes,{offset-adjust:-6}\n#>0\tbelong\t\tx\t\tload address 0x%X,\n>3\tbyte\t\t<0x7F\t\trom image type:\n>>3\tbyte\t\t<1\t\tinvalid,\n>>3\tbyte\t\t>7\t\tinvalid,\n>>3\tbyte\t\t1\t\tROMIMG,\n>>3\tbyte\t\t2\t\tROMBOOT,\n>>3\tbyte\t\t3\t\tBOOTEXT,\n>>3\tbyte\t\t4\t\tROMBIN,\n>>3\tbyte\t\t5\t\tROMDIR,\n>>3\tbyte\t\t6\t\t6,\n>>3\tbyte\t\t7\t\tROMMAP,\n>3\tbyte\t\t>0x7F\t\tram image type:\n>>3\tbyte\t\t>0x82\t\tinvalid,\n>>3\tbyte\t\t0x80\t\tRAM,\n>>3\tbyte\t\t0x81\t\tRAMCODE,\n>>3\tbyte\t\t0x82\t\tRAMBOOT,\n>4\tbelong\t\t>0x40000000\tinvalid\n>4\tbelong\t\t<0\t\tinvalid\n>4\tbelong\t\t0\t\tinvalid\n>4\tbelong\t\tx\t\tuncompressed size: %d,\n>8\tbelong\t\t>0x40000000\tinvalid\n>8\tbelong\t\t<0\t\tinvalid\n>8\tbelong\t\t0  \t\tinvalid\n>8\tbelong\t\tx\t\tcompressed size: %d,\n>14\tbeshort\t\tx\t\tuncompressed checksum: 0x%X,\n>16\tbeshort\t\tx\t\tcompressed checksum: 0x%X,\n>12\tbyte\t\tx\t\tflags: 0x%X,\n>12\tbyte\t\t&0x40\t\tuncompressed checksum is valid,\n>12\tbyte\t\t&0x80\t\tthe binary is compressed,\n>>12\tbyte\t\t&0x20\t\tcompressed checksum is valid,\n>35\tbelong\t\tx\t\tmemory map table address: 0x%X\n\n# Firmware header used by some VxWorks-based Cisco products\n0\tstring\t\tCI032.00\tCisco VxWorks firmware header,\n>8\tlelong\t\t>1024\t\tinvalid\n>8\tlelong\t\t<0\t\tinvalid\n>8\tlelong\t\tx\t\theader size: %d bytes,\n>32\tlelong\t\t>1024\t\tinvalid\n>32\tlelong\t\t<0\t\tinvalid\n>32\tlelong\t\tx\t\tnumber of files: %d,\n>48\tlelong\t\t<0\t\tinvalid\n>48\tlelong\t\tx\t\timage size: %d,\n>64\tstring\t\tx\t\tfirmware version: \"%s\"\n\n# Firmware header used by some TV's\n0\tstring\t\tFNIB\t\tZBOOT firmware header, header size: 32 bytes,\n>8\tlelong\t\tx\t\tload address: 0x%.8X,\n>12\tlelong\t\tx\t\tstart address: 0x%.8X,\n>16\tlelong\t\tx\t\tchecksum: 0x%.8X,\n>20\tlelong\t\tx\t\tversion: 0x%.8X,\n>24\tlelong\t\t<1\t\tinvalid\n>24\tlelong\t\tx\t\timage size: %d bytes\n\n# Firmware header used by several D-Link routers (and probably others)\n0               string  \\x5e\\xa3\\xa4\\x17\tDLOB firmware header,\n>(7.b+12)       string  !\\x5e\\xa3\\xa4\\x17       invalid,\n#>>12           string  x                       %s,\n>(7.b+40)       string  x                       boot partition: \"%s\"\n\n# TP-Link firmware header structure; thanks to Jonathan McGowan for reversing and documenting this format\n0\tstring          TP-LINK\\x20Technologies\t\tTP-Link firmware header,{offset-adjust:-4}\n#>-4\tlelong          x               \t\theader version: %d,\n>0x94  \tbeshort         x               \t\tfirmware version: %d.\n>0x96  \tbeshort         x               \t\t\\b%d.\n>0x98  \tbeshort         x               \t\t\\b%d,\n>0x18  \tstring          x               \t\timage version: \"%s\",\n#>0x74  belong          x               \t\timage size: %d bytes,\n>0x3C  \tbelong          x               \t\tproduct ID: 0x%X,\n>0x40  \tbelong          x               \t\tproduct version: %d,\n>0x70  \tbelong          x               \t\tkernel load address: 0x%X,\n>0x74  \tbelong          x               \t\tkernel entry point: 0x%X,\n>0x7C  \tbelong          x               \t\tkernel offset: %d,\n>0x80  \tbelong          x               \t\tkernel length: %d,\n>0x84  \tbelong          x               \t\trootfs offset: %d,\n>0x88  \tbelong          x               \t\trootfs length: %d,\n>0x8C  \tbelong          x               \t\tbootloader offset: %d,\n>0x90  \tbelong          x               \t\tbootloader length: %d\n\n# Tag Image File Format, from Daniel Quinlan (quinlan@yggdrasil.com)\n# The second word of TIFF files is the TIFF version number, 42, which has\n# never changed.  The TIFF specification recommends testing for it.\n0       string          MM\\x00\\x2a      TIFF image data, big-endian\n0       string          II\\x2a\\x00      TIFF image data, little-endian\n\n# PNG [Portable Network Graphics, or \"PNG's Not GIF\"] images\n# (Greg Roelofs, newt@uchicago.edu)\n# (Albert Cahalan, acahalan@cs.uml.edu)\n#\n# 137 P N G \\r \\n ^Z \\n [4-byte length] H E A D [HEAD data] [HEAD crc] ...\n#\n0       string          \\x89PNG\\x0d\\x0a\\x1a\\x0a         PNG image\n>16     belong          x               \\b, %ld x\n>20     belong          x               %ld,\n>24     byte            x               %d-bit\n>25     byte            0               grayscale,\n>25     byte            2               \\b/color RGB,\n>25     byte            3               colormap,\n>25     byte            4               gray+alpha,\n>25     byte            6               \\b/color RGBA,\n#>26    byte            0               deflate/32K,\n>28     byte            0               non-interlaced\n>28     byte            1               interlaced\n\n# GIF\n0       string          GIF8            GIF image data\n>4      string          7a              \\b, version 8\"%s\",\n>4      string          9a              \\b, version 8\"%s\",\n>6      leshort         >0              %hd x\n>8      leshort         >0              %hd\n#>10    byte            &0x80           color mapped,\n#>10    byte&0x07       =0x00           2 colors\n#>10    byte&0x07       =0x01           4 colors\n#>10    byte&0x07       =0x02           8 colors\n#>10    byte&0x07       =0x03           16 colors\n#>10    byte&0x07       =0x04           32 colors\n#>10    byte&0x07       =0x05           64 colors\n#>10    byte&0x07       =0x06           128 colors\n#>10    byte&0x07       =0x07           256 colors\n\n# PC bitmaps (OS/2, Windows BMP files)  (Greg Roelofs, newt@uchicago.edu)\n0       string          BM\n>14     leshort         12              PC bitmap, OS/2 1.x format\n>>18    leshort         x               \\b, %d x\n>>20    leshort         x               %d\n>14     leshort         64              PC bitmap, OS/2 2.x format\n>>18    leshort         x               \\b, %d x\n>>20    leshort         x               %d\n>14     leshort         40              PC bitmap, Windows 3.x format\n>>18    lelong          x               \\b, %d x\n>>22    lelong          x               %d x\n>>28    leshort         x               %d\n>14     leshort         128             PC bitmap, Windows NT/2000 format\n>>18    lelong          x               \\b, %d x\n>>22    lelong          x               %d x\n>>28    leshort         x               %d\n\n#------------------------------------------------------------------------------\n# JPEG images\n# SunOS 5.5.1 had\n#\n#       0       string          \\377\\330\\377\\340        JPEG file\n#       0       string          \\377\\330\\377\\356        JPG file\n#\n# both of which turn into \"JPEG image data\" here.\n#\n0       beshort         0xffd8          JPEG image data\n>6      string          JFIF            \\b, JFIF standard\n# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06\n# in a vain attempt to add image size reporting for JFIF.  Note that these\n# tests are not fool-proof since some perfectly valid JPEGs are currently\n# impossible to specify in magic(4) format.\n# First, a little JFIF version info:\n>>11    byte            x               \\b %d.\n>>12    byte            x               \\b%02d\n# Next, the resolution or aspect ratio of the image:\n#>>13   byte            0               \\b, aspect ratio\n#>>13   byte            1               \\b, resolution (DPI)\n#>>13   byte            2               \\b, resolution (DPCM)\n#>>4    beshort         x               \\b, segment length %d\n# Next, show thumbnail info, if it exists:\n>>18    byte            !0              \\b, thumbnail %dx\n>>>19   byte            x               \\b%d\n\n# EXIF moved down here to avoid reporting a bogus version number,\n# and EXIF version number printing added.\n#   - Patrik R=E5dman <patrik+file-magic@iki.fi>\n>6      string          Exif            \\b, EXIF standard\n# Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD.\n# All possible combinations of entries have to be enumerated, since no looping\n# is possible. And both endians are possible...\n# The combinations included below are from real-world JPEGs.\n# Little-endian\n>>12    string          II\n# IFD 0 Entry #5:\n>>>70   leshort         0x8769\n# EXIF IFD Entry #1:\n>>>>(78.l+14)   leshort 0x9000\n>>>>>(78.l+23)  byte    x               %c\n>>>>>(78.l+24)  byte    x               \\b.%c\n>>>>>(78.l+25)  byte    !0x30           \\b%c\n# IFD 0 Entry #9:\n>>>118  leshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(126.l+38)  leshort 0x9000\n>>>>>(126.l+47) byte    x               %c\n>>>>>(126.l+48) byte    x               \\b.%c\n>>>>>(126.l+49) byte    !0x30           \\b%c\n# IFD 0 Entry #10\n>>>130  leshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(138.l+38)  leshort 0x9000\n>>>>>(138.l+47) byte    x               %c\n>>>>>(138.l+48) byte    x               \\b.%c\n>>>>>(138.l+49) byte    !0x30           \\b%c\n# EXIF IFD Entry #4:\n>>>>(138.l+50)  leshort 0x9000\n>>>>>(138.l+59) byte    x               %c\n>>>>>(138.l+60) byte    x               \\b.%c\n>>>>>(138.l+61) byte    !0x30           \\b%c\n# EXIF IFD Entry #5:\n>>>>(138.l+62)  leshort 0x9000\n>>>>>(138.l+71) byte    x               %c\n>>>>>(138.l+72) byte    x               \\b.%c\n>>>>>(138.l+73) byte    !0x30           \\b%c\n# IFD 0 Entry #11\n>>>142  leshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(150.l+38)  leshort 0x9000\n>>>>>(150.l+47) byte    x               %c\n>>>>>(150.l+48) byte    x               \\b.%c\n>>>>>(150.l+49) byte    !0x30           \\b%c\n# EXIF IFD Entry #4:\n>>>>(150.l+50)  leshort 0x9000\n>>>>>(150.l+59) byte    x               %c\n>>>>>(150.l+60) byte    x               \\b.%c\n>>>>>(150.l+61) byte    !0x30           \\b%c\n# EXIF IFD Entry #5:\n>>>>(150.l+62)  leshort 0x9000\n>>>>>(150.l+71) byte    x               %c\n>>>>>(150.l+72) byte    x               \\b.%c\n>>>>>(150.l+73) byte    !0x30           \\b%c\n# Big-endian\n>>12    string          MM\n# IFD 0 Entry #9:\n>>>118  beshort         0x8769\n# EXIF IFD Entry #1:\n>>>>(126.L+14)  beshort 0x9000\n>>>>>(126.L+23) byte    x               %c\n>>>>>(126.L+24) byte    x               \\b.%c\n>>>>>(126.L+25) byte    !0x30           \\b%c\n# EXIF IFD Entry #3:\n>>>>(126.L+38)  beshort 0x9000\n>>>>>(126.L+47) byte    x               %c\n>>>>>(126.L+48) byte    x               \\b.%c\n>>>>>(126.L+49) byte    !0x30           \\b%c\n# IFD 0 Entry #10\n>>>130  beshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(138.L+38)  beshort 0x9000\n>>>>>(138.L+47) byte    x               %c\n>>>>>(138.L+48) byte    x               \\b.%c\n>>>>>(138.L+49) byte    !0x30           \\b%c\n# EXIF IFD Entry #5:\n>>>>(138.L+62)  beshort 0x9000\n>>>>>(138.L+71) byte    x               %c\n>>>>>(138.L+72) byte    x               \\b.%c\n>>>>>(138.L+73) byte    !0x30           \\b%c\n# IFD 0 Entry #11\n>>>142  beshort         0x8769\n# EXIF IFD Entry #4:\n>>>>(150.L+50)  beshort 0x9000\n>>>>>(150.L+59) byte    x               %c\n>>>>>(150.L+60) byte    x               \\b.%c\n>>>>>(150.L+61) byte    !0x30           \\b%c\n# Here things get sticky.  We can do ONE MORE marker segment with\n# indirect addressing, and that's all.  It would be great if we could\n# do pointer arithemetic like in an assembler language.  Christos?\n# And if there was some sort of looping construct to do searches, plus a few\n# named accumulators, it would be even more effective...\n# At least we can show a comment if no other segments got inserted before:\n>(4.S+5)        byte            0xFE\n>>(4.S+8)       string          >\\0             \\b, comment: \"%s\"\n# FIXME: When we can do non-byte counted strings, we can use that to get\n# the string's count, and fix Debian bug #283760\n#>(4.S+5)       byte            0xFE            \\b, comment\n#>>(4.S+6)      beshort         x               \\b length=%d\n#>>(4.S+8)      string          >\\0             \\b, \"%s\"\n# Or, we can show the encoding type (I've included only the three most common)\n# and image dimensions if we are lucky and the SOFn (image segment) is here:\n>(4.S+5)        byte            0xC0            \\b, baseline\n>>(4.S+6)       byte            x               \\b, precision %d\n>>(4.S+7)       beshort         x               \\b, %dx\n>>(4.S+9)       beshort         x               \\b%d\n>(4.S+5)        byte            0xC1            \\b, extended sequential\n>>(4.S+6)       byte            x               \\b, precision %d\n>>(4.S+7)       beshort         x               \\b, %dx\n>>(4.S+9)       beshort         x               \\b%d\n>(4.S+5)        byte            0xC2            \\b, progressive\n>>(4.S+6)       byte            x               \\b, precision %d\n>>(4.S+7)       beshort         x               \\b, %dx\n>>(4.S+9)       beshort         x               \\b%d\n# I've commented-out quantisation table reporting.  I doubt anyone cares yet.\n#>(4.S+5)       byte            0xDB            \\b, quantisation table\n#>>(4.S+6)      beshort         x               \\b length=%d\n#>14    beshort         x               \\b, %d x\n#>16    beshort         x               \\b %d\n\n\n#-------------------------Kernels-------------------------------------\n\n# Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>\n# and others such as Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>\n# and Nicolás Lichtmaier <nick@debian.org>\n# All known start with: b8 c0 07 8e d8 b8 00 90 8e c0 b9 00 01 29 f6 29\n0\tstring\t\t\\xb8\\xc0\\x07\\x8e\\xd8\\xb8\\x00\\x90\\x8e\\xc0\\xb9\\x00\\x01\\x29\\xf6\\x29\tLinux kernel boot image\n>514\tstring          !HdrS            \t\t\t\t\t\t\t(invalid)\n\n# Finds and prints Linux kernel strings in raw Linux kernels (output like uname -a).\n# Commonly found in decompressed embedded kernel binaries.\n0\tstring\t\tLinux\\ version\\ \tLinux kernel version\n>14\tbyte\t\t0\t\t\tinvalid\n>14\tbyte\t\t!0\n>>14\tstring\t\tx\t\t\t\"%s\n>>45\tstring\t\tx\t\t\t\\b%s\n>>76\tstring\t\tx\t\t\t\\b%s\n>>107\tstring\t\tx\t\t\t\\b%s\"\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5D\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5D\\x00\\x00\tLZMA compressed data, properties: 0x5D,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x01\n# ------------------------------------------------------------------\n0\t\tstring\t\\x01\\x00\\x00\tLZMA compressed data, properties: 0x01,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x02\n# ------------------------------------------------------------------\n0\t\tstring\t\\x02\\x00\\x00\tLZMA compressed data, properties: 0x02,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x03\n# ------------------------------------------------------------------\n0\t\tstring\t\\x03\\x00\\x00\tLZMA compressed data, properties: 0x03,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x04\n# ------------------------------------------------------------------\n0\t\tstring\t\\x04\\x00\\x00\tLZMA compressed data, properties: 0x04,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x09\n# ------------------------------------------------------------------\n0\t\tstring\t\\x09\\x00\\x00\tLZMA compressed data, properties: 0x09,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x0A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x0A\\x00\\x00\tLZMA compressed data, properties: 0x0A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x0B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x0B\\x00\\x00\tLZMA compressed data, properties: 0x0B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x0C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x0C\\x00\\x00\tLZMA compressed data, properties: 0x0C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x12\n# ------------------------------------------------------------------\n0\t\tstring\t\\x12\\x00\\x00\tLZMA compressed data, properties: 0x12,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x13\n# ------------------------------------------------------------------\n0\t\tstring\t\\x13\\x00\\x00\tLZMA compressed data, properties: 0x13,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x14\n# ------------------------------------------------------------------\n0\t\tstring\t\\x14\\x00\\x00\tLZMA compressed data, properties: 0x14,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x1B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x1B\\x00\\x00\tLZMA compressed data, properties: 0x1B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x1C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x1C\\x00\\x00\tLZMA compressed data, properties: 0x1C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x24\n# ------------------------------------------------------------------\n0\t\tstring\t\\x24\\x00\\x00\tLZMA compressed data, properties: 0x24,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x2D\n# ------------------------------------------------------------------\n0\t\tstring\t\\x2D\\x00\\x00\tLZMA compressed data, properties: 0x2D,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x2E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x2E\\x00\\x00\tLZMA compressed data, properties: 0x2E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x2F\n# ------------------------------------------------------------------\n0\t\tstring\t\\x2F\\x00\\x00\tLZMA compressed data, properties: 0x2F,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x30\n# ------------------------------------------------------------------\n0\t\tstring\t\\x30\\x00\\x00\tLZMA compressed data, properties: 0x30,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x31\n# ------------------------------------------------------------------\n0\t\tstring\t\\x31\\x00\\x00\tLZMA compressed data, properties: 0x31,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x36\n# ------------------------------------------------------------------\n0\t\tstring\t\\x36\\x00\\x00\tLZMA compressed data, properties: 0x36,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x37\n# ------------------------------------------------------------------\n0\t\tstring\t\\x37\\x00\\x00\tLZMA compressed data, properties: 0x37,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x38\n# ------------------------------------------------------------------\n0\t\tstring\t\\x38\\x00\\x00\tLZMA compressed data, properties: 0x38,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x39\n# ------------------------------------------------------------------\n0\t\tstring\t\\x39\\x00\\x00\tLZMA compressed data, properties: 0x39,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x3F\n# ------------------------------------------------------------------\n0\t\tstring\t\\x3F\\x00\\x00\tLZMA compressed data, properties: 0x3F,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x40\n# ------------------------------------------------------------------\n0\t\tstring\t\\x40\\x00\\x00\tLZMA compressed data, properties: 0x40,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x41\n# ------------------------------------------------------------------\n0\t\tstring\t\\x41\\x00\\x00\tLZMA compressed data, properties: 0x41,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x48\n# ------------------------------------------------------------------\n0\t\tstring\t\\x48\\x00\\x00\tLZMA compressed data, properties: 0x48,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x49\n# ------------------------------------------------------------------\n0\t\tstring\t\\x49\\x00\\x00\tLZMA compressed data, properties: 0x49,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x51\n# ------------------------------------------------------------------\n0\t\tstring\t\\x51\\x00\\x00\tLZMA compressed data, properties: 0x51,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5A\\x00\\x00\tLZMA compressed data, properties: 0x5A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5B\\x00\\x00\tLZMA compressed data, properties: 0x5B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5C\\x00\\x00\tLZMA compressed data, properties: 0x5C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5E\\x00\\x00\tLZMA compressed data, properties: 0x5E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x63\n# ------------------------------------------------------------------\n0\t\tstring\t\\x63\\x00\\x00\tLZMA compressed data, properties: 0x63,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x64\n# ------------------------------------------------------------------\n0\t\tstring\t\\x64\\x00\\x00\tLZMA compressed data, properties: 0x64,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x65\n# ------------------------------------------------------------------\n0\t\tstring\t\\x65\\x00\\x00\tLZMA compressed data, properties: 0x65,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x66\n# ------------------------------------------------------------------\n0\t\tstring\t\\x66\\x00\\x00\tLZMA compressed data, properties: 0x66,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x6C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x6C\\x00\\x00\tLZMA compressed data, properties: 0x6C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x6D\n# ------------------------------------------------------------------\n0\t\tstring\t\\x6D\\x00\\x00\tLZMA compressed data, properties: 0x6D,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x6E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x6E\\x00\\x00\tLZMA compressed data, properties: 0x6E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x75\n# ------------------------------------------------------------------\n0\t\tstring\t\\x75\\x00\\x00\tLZMA compressed data, properties: 0x75,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x76\n# ------------------------------------------------------------------\n0\t\tstring\t\\x76\\x00\\x00\tLZMA compressed data, properties: 0x76,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x7E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x7E\\x00\\x00\tLZMA compressed data, properties: 0x7E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x87\n# ------------------------------------------------------------------\n0\t\tstring\t\\x87\\x00\\x00\tLZMA compressed data, properties: 0x87,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x88\n# ------------------------------------------------------------------\n0\t\tstring\t\\x88\\x00\\x00\tLZMA compressed data, properties: 0x88,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x89\n# ------------------------------------------------------------------\n0\t\tstring\t\\x89\\x00\\x00\tLZMA compressed data, properties: 0x89,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x8A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x8A\\x00\\x00\tLZMA compressed data, properties: 0x8A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x8B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x8B\\x00\\x00\tLZMA compressed data, properties: 0x8B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x90\n# ------------------------------------------------------------------\n0\t\tstring\t\\x90\\x00\\x00\tLZMA compressed data, properties: 0x90,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x91\n# ------------------------------------------------------------------\n0\t\tstring\t\\x91\\x00\\x00\tLZMA compressed data, properties: 0x91,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x92\n# ------------------------------------------------------------------\n0\t\tstring\t\\x92\\x00\\x00\tLZMA compressed data, properties: 0x92,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x93\n# ------------------------------------------------------------------\n0\t\tstring\t\\x93\\x00\\x00\tLZMA compressed data, properties: 0x93,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x99\n# ------------------------------------------------------------------\n0\t\tstring\t\\x99\\x00\\x00\tLZMA compressed data, properties: 0x99,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x9A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x9A\\x00\\x00\tLZMA compressed data, properties: 0x9A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x9B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x9B\\x00\\x00\tLZMA compressed data, properties: 0x9B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xA2\n# ------------------------------------------------------------------\n0\t\tstring\t\\xA2\\x00\\x00\tLZMA compressed data, properties: 0xA2,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xA3\n# ------------------------------------------------------------------\n0\t\tstring\t\\xA3\\x00\\x00\tLZMA compressed data, properties: 0xA3,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xAB\n# ------------------------------------------------------------------\n0\t\tstring\t\\xAB\\x00\\x00\tLZMA compressed data, properties: 0xAB,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB4\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB4\\x00\\x00\tLZMA compressed data, properties: 0xB4,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB5\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB5\\x00\\x00\tLZMA compressed data, properties: 0xB5,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB6\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB6\\x00\\x00\tLZMA compressed data, properties: 0xB6,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB7\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB7\\x00\\x00\tLZMA compressed data, properties: 0xB7,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB8\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB8\\x00\\x00\tLZMA compressed data, properties: 0xB8,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xBD\n# ------------------------------------------------------------------\n0\t\tstring\t\\xBD\\x00\\x00\tLZMA compressed data, properties: 0xBD,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xBE\n# ------------------------------------------------------------------\n0\t\tstring\t\\xBE\\x00\\x00\tLZMA compressed data, properties: 0xBE,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xBF\n# ------------------------------------------------------------------\n0\t\tstring\t\\xBF\\x00\\x00\tLZMA compressed data, properties: 0xBF,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC0\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC0\\x00\\x00\tLZMA compressed data, properties: 0xC0,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC6\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC6\\x00\\x00\tLZMA compressed data, properties: 0xC6,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC7\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC7\\x00\\x00\tLZMA compressed data, properties: 0xC7,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC8\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC8\\x00\\x00\tLZMA compressed data, properties: 0xC8,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xCF\n# ------------------------------------------------------------------\n0\t\tstring\t\\xCF\\x00\\x00\tLZMA compressed data, properties: 0xCF,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xD0\n# ------------------------------------------------------------------\n0\t\tstring\t\\xD0\\x00\\x00\tLZMA compressed data, properties: 0xD0,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xD8\n# ------------------------------------------------------------------\n0\t\tstring\t\\xD8\\x00\\x00\tLZMA compressed data, properties: 0xD8,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n#------------------------------------------------------------------------------\n# $File: sql,v 1.6 2009/09/19 16:28:12 christos Exp $\n# sql:  file(1) magic for SQL files\n#\n# From: \"Marty Leisner\" <mleisner@eng.mc.xerox.com>\n# Recognize some MySQL files.\n#\n0       beshort                 0xfe01          MySQL table definition file\n>2\tstring\t\t\t<1\t\tinvalid\n>2\tstring\t\t\t>\\11\t\tinvalid\n>2      byte                    x               Version %d\n0       string\t\t        \\xfe\\xfe\\x03    MySQL MISAM index file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\xfe\\xfe\\x07    MySQL MISAM compressed data file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\xfe\\xfe\\x05    MySQL ISAM index file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\xfe\\xfe\\x06    MySQL ISAM compressed data file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\376bin         MySQL replication log\n\n#------------------------------------------------------------------------------\n# iRiver H Series database file \n# From Ken Guest <ken@linux.ie>\n# As observed from iRivNavi.iDB and unencoded firmware\n#\n0   string              iRivDB  iRiver Database file\n>11  string     >\\0     Version \"%s\"\n>39  string             iHP-100 [H Series]\n\n#------------------------------------------------------------------------------\n# SQLite database files\n# Ken Guest <ken@linux.ie>, Ty Sarna, Zack Weinberg\n#\n# Version 1 used GDBM internally; its files cannot be distinguished\n# from other GDBM files.\n#\n# Version 2 used this format:\n0       string  **\\x20This\\x20file\\x20contains\\x20an\\x20SQLite  SQLite 2.x database\n\n# Version 3 of SQLite allows applications to embed their own \"user version\"\n# number in the database.  Detect this and distinguish those files.\n\n0   string  SQLite\\x20format\\x203\n>60 string  _MTN               Monotone source repository\n>60 belong  !0                 SQLite 3.x database, user version %u\n>60 belong  0                  SQLite 3.x database\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/parser.py",
    "content": "import os.path\nimport tempfile\nfrom common import str2int\n\nclass MagicParser:\n\t'''\n\tClass for loading, parsing and creating libmagic-compatible magic files.\n\t\n\tThis class is primarily used internally by the Binwalk class, and a class instance of it is available via the Binwalk.parser object.\n\n\tOne useful method however, is file_from_string(), which will generate a temporary magic file from a given signature string:\n\n\t\timport binwalk\n\n\t\tbw = binwalk.Binwalk()\n\n\t\t# Create a temporary magic file that contains a single entry with a signature of '\\\\x00FOOBAR\\\\xFF', and append the resulting \n\t\t# temporary file name to the list of magic files in the Binwalk class instance.\n\t\tbw.magic_files.append(bw.parser.file_from_string('\\\\x00FOOBAR\\\\xFF', display_name='My custom signature'))\n\n\t\tbw.scan('firmware.bin')\n\t\n\tAll magic files generated by this class will be deleted when the class deconstructor is called.\n\t'''\n\n\tSHORT_SIZE = 2\n\tSHORTS = ['beshort', 'leshort', 'byte']\n\n\tBIG_ENDIAN = 'big'\n\tLITTLE_ENDIAN = 'little'\n\n\tMAGIC_STRING_FORMAT = \"%d\\tstring\\t%s\\t%s\\n\"\n\tDEFAULT_DISPLAY_NAME = \"Raw string signature\"\n\n\tWILDCARD = 'x'\n\n\t# If libmagic returns multiple results, they are delimited with this string.\t\n\tRESULT_SEPERATOR = \"\\\\012- \"\n\n\t# Size of the keys used in the matches set. Limited to 2\n\t# as the key is the magic signature of a given magic file entry.\n\t# Entries can have variable length signatures, but the lowest \n\t# common demonitor is 2, so the first two bytes of the signature\n\t# is used as the key. Does this result in collisions and false\n\t# positives? Yes. But false positives are filtered out by the\n\t# MagicFilter class. The main purpose of MagicParser.match is to\n\t# limit the number of calls to libmagic without itself incurring\n\t# large computational overhead. And for that purpose, this is\n\t# quite effective.\n\tMATCH_INDEX_SIZE = 2\n\n\tdef __init__(self, filter=None, smart=None):\n\t\t'''\n\t\tClass constructor.\n\n\t\t@filter - Instance of the MagicFilter class. May be None if the parse/parse_file methods are not used.\n\t\t@smart  - Instance of the SmartSignature class. May be None if the parse/parse_file methods are not used.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.matches = set([])\n\t\tself.signatures = {}\n\t\tself.sigset = {}\n\t\tself.filter = filter\n\t\tself.smart = smart\n\t\tself.raw_fd = None\n\t\tself.signature_count = 0\n\t\tself.fd = tempfile.NamedTemporaryFile()\n\n\tdef __del__(self):\n\t\t'''\n\t\tClass deconstructor.\n\t\t'''\n\t\tself.cleanup()\n\n\tdef cleanup(self):\n\t\t'''\n\t\tCleans up any tempfiles created by the class instance.\n\n\t\tReturns None.\n\t\t'''\n\t\t# Clean up the tempfiles\n\t\ttry:\n\t\t\tself.fd.close()\n\t\texcept:\n\t\t\tpass\n\t\t\n\t\ttry:\n\t\t\tself.raw_fd.close()\n\t\texcept:\n\t\t\tpass\n\n\tdef file_from_string(self, signature_string, offset=0, display_name=DEFAULT_DISPLAY_NAME):\n\t\t'''\n\t\tGenerates a magic file from a signature string.\n\n\t\t@signature_string - The string signature to search for.\n\t\t@offset           - The offset at which the signature should occur.\n\t\t@display_name     - The text to display when the signature is found.\n\n\t\tReturns the name of the generated temporary magic file.\n\t\t'''\n\t\tself.raw_fd = tempfile.NamedTemporaryFile()\n\t\tself.raw_fd.write(self.MAGIC_STRING_FORMAT % (offset, signature_string, display_name))\n\t\tself.raw_fd.seek(0)\n\t\treturn self.raw_fd.name\n\n\tdef parse(self, file_name, filter_short_signatures=True, pre_filter_signatures=True):\n\t\t'''\n\t\tParses magic file(s) and contatenates them into a single temporary magic file\n\t\twhile simultaneously removing filtered signatures.\n\n\t\t@file_name         \t\t- Magic file, or list of magic files, to parse.\n\t\t@filter_short_signatures\t- Set to False to include entries with short (2 byte) magic signatures.\n\t\t@pre_filter_signatures\t\t- Set to False to disable smart signature keywords.\n\n\t\tReturns the name of the generated temporary magic file, which will be automatically\n\t\tdeleted when the class deconstructor is called.\n\t\t'''\n\t\tif type(file_name) == type([]):\n\t\t\tfiles = file_name\n\t\telse:\n\t\t\tfiles = [file_name]\n\n\t\tfor fname in files:\n\t\t\tif os.path.exists(fname):\n\t\t\t\tself.parse_file(fname, filter_short_signatures, pre_filter_signatures)\n\n\t\tself.fd.seek(0)\n\t\treturn self.fd.name\n\n\tdef parse_file(self, file_name, filter_short_signatures=True, pre_filter_signatures=True):\n\t\t'''\n\t\tParses a magic file and appends valid signatures to the temporary magic file, as allowed\n\t\tby the existing filter rules.\n\n\t\t@file_name\t\t\t- Magic file to parse.\n\t\t@filter_short_signatures\t- Set to False to include entries with short (2 byte) magic signatures.\n\t\t@pre_filter_signatures\t\t- Set to False to disable smart signature keywords.\n\t\t\n\t\tReturns None.\n\t\t'''\n\t\t# Default to not including signature entries until we've\n\t\t# found what looks like a valid entry.\n\t\tinclude = False\n\t\tline_count = 0\n\n\t\ttry:\n\t\t\tfor line in open(file_name).readlines():\n\t\t\t\tline_count += 1\n\n\t\t\t\t# Check if this is the first line of a signature entry\n\t\t\t\tentry = self._parse_line(line)\n\n\t\t\t\tif entry is not None:\n\t\t\t\t\t# Once an entry is identified, default to excluding the entry\n\t\t\t\t\tinclude = False\n\n\t\t\t\t\tif pre_filter_signatures:\n\t\t\t\t\t\t# If the smart signature include keyword is specified for this entry,\n\t\t\t\t\t\t# add an include filter for this signature description.\n\t\t\t\t\t\tif self.smart.include(entry['description']):\n\t\t\t\t\t\t\tself.filter.include(entry['description'], exclusive=False)\n\t\t\t\t\t\t\tinclude = True\n\n\t\t\t\t\t# If we haven't already explicitly included this entry, and we are \n\t\t\t\t\t# filtering out short signatures and this is a short signature, then \n\t\t\t\t\t# add an exclude filter for this signature description\n\t\t\t\t\tif not include and filter_short_signatures and self._is_short(entry):\n\t\t\t\t\t\tself.filter.exclude(entry['description'])\n\n\t\t\t\t\t# If this signature is marked for inclusion, include it.\n\t\t\t\t\tif self.filter.filter(entry['description']) == self.filter.FILTER_INCLUDE:\n\t\t\t\t\t\tinclude = True\n\t\t\t\t\t\n\t\t\t\t\tif include:\n\t\t\t\t\t\tself.signature_count += 1\n\n\t\t\t\t\t\tif not self.signatures.has_key(entry['offset']):\n\t\t\t\t\t\t\tself.signatures[entry['offset']] = []\n\t\t\t\t\t\t\n\t\t\t\t\t\tif entry['condition'][:self.MATCH_INDEX_SIZE] not in self.signatures[entry['offset']]:\n\t\t\t\t\t\t\tself.signatures[entry['offset']].append(entry['condition'][:self.MATCH_INDEX_SIZE])\n\n\t\t\t\t# Keep writing lines of the signature to the temporary magic file until \n\t\t\t\t# we detect a signature that should not be included.\n\t\t\t\tif include:\n\t\t\t\t\tself.fd.write(line)\n\t\texcept Exception, e:\n\t\t\traise Exception(\"Error parsing magic file '%s' on line %d: %s\" % (file_name, line_count, str(e)))\n\n\t\t# Generate a dictionary of offsets with a set of signatures\t\n\t\tfor (offset, siglist) in self.signatures.iteritems():\n\t\t\tself.sigset[offset] = set(siglist)\n\n\tdef _is_short(self, entry):\n\t\t'''\n\t\tDetermines if a signature entry has a short (2 byte) signature or not.\n\n\t\t@entry - Entry dictionary, as returned by self._parse_line().\n\t\t\n\t\tReturns True if the signature is short, False if not short.\n\t\t'''\n\t\tif entry['type'] in self.SHORTS:\n\t\t\treturn True\n\t\telif 'string' in entry['type']:\n\t\t\tif len(entry['condition'].decode('string_escape')) <= self.SHORT_SIZE:\n\t\t\t\treturn True\n\t\treturn False\n\n\tdef _parse_line(self, line):\n\t\t'''\n\t\tParses a signature line into its four parts (offset, type, condition and description),\n\t\tlooking for the first line of a given signature.\n\n\t\t@line - The signature line to parse.\n\n\t\tReturns a dictionary with the respective line parts populated if the line is the first of a signature.\n\t\tReturns a dictionary with all parts set to None if the line is not the first of a signature.\n\t\t'''\n\t\tentry = {\n\t\t\t'offset'\t: '',\n\t\t\t'type'\t\t: '',\n\t\t\t'condition'\t: '',\n\t\t\t'description'\t: '',\n\t\t\t'length'\t: 0\n\t\t}\n\n\t\t# Quick and dirty pre-filter. We are only concerned with the first line of a\n\t\t# signature, which will always start with a number. Make sure the first byte of\n\t\t# the line is a number; if not, don't process.\n\t\tif line[:1] < '0' or line[:1] > '9':\n\t\t\treturn None\n\n\t\ttry:\n\t\t\t# Split the line into white-space separated parts.\n\t\t\t# For this to work properly, replace escaped spaces ('\\ ') with '\\x20'.\n\t\t\t# This means the same thing, but doesn't confuse split().\n\t\t\tline_parts = line.replace('\\\\ ', '\\\\x20').split()\n\t\t\tentry['offset'] = line_parts[0]\n\t\t\tentry['type'] = line_parts[1]\n\t\t\t# The condition line may contain escaped sequences, so be sure to decode it properly.\n\t\t\tentry['condition'] = line_parts[2].decode('string_escape')\n\t\t\tentry['description'] = ' '.join(line_parts[3:])\n\t\texcept Exception, e:\n\t\t\traise Exception(\"%s :: %s\", (str(e), line))\n\n\t\t# We've already verified that the first character in this line is a number, so this *shouldn't*\n\t\t# throw an exception, but let's catch it just in case...\n\t\ttry:\n\t\t\tentry['offset'] = str2int(entry['offset'])\n\t\texcept Exception, e:\n\t\t\traise Exception(\"%s :: %s\", (str(e), line))\n\n\t\t# If this is a string, get the length of the string\n\t\tif 'string' in entry['type']:\n\t\t\tentry['length'] = len(entry['condition'])\n\t\t# Else, we need to jump through a few more hoops...\n\t\telse:\t\n\t\t\t# Default to little endian, unless the type field starts with 'be'. \n\t\t\t# This assumes that we're running on a little endian system...\n\t\t\tif entry['type'].startswith('be'):\n\t\t\t\tendianess = self.BIG_ENDIAN\n\t\t\telse:\n\t\t\t\tendianess = self.LITTLE_ENDIAN\n\t\t\t\n\t\t\t# Try to convert the condition to an integer. This does not allow\n\t\t\t# for more advanced conditions for the first line of a signature, \n\t\t\t# but needing that is rare.\n\t\t\tif entry['condition'] != self.WILDCARD:\n\t\t\t\ttry:\n\t\t\t\t\tintval = str2int(entry['condition'].strip('L'))\n\t\t\t\texcept Exception, e:\n\t\t\t\t\traise Exception(\"Failed to evaluate condition for '%s' type: '%s', condition: '%s', error: %s\" % (entry['description'], entry['type'], entry['condition'], str(e)))\n\t\t\telse:\n\t\t\t\tintval = 0\n\t\t\t\tentry['length'] = 1\n\n\t\t\t# How long is the field type?\n\t\t\tif entry['type'] == 'byte':\n\t\t\t\tentry['length'] = 1\n\t\t\telif 'short' in entry['type']:\n\t\t\t\tentry['length'] = 2\n\t\t\telif 'long' in entry['type']:\n\t\t\t\tentry['length'] = 4\n\t\t\telif 'quad' in entry['type']:\n\t\t\t\tentry['length'] = 8\n\n\t\t\t# Convert the integer value to a string of the appropriate endianess\n\t\t\tentry['condition'] = self._to_string(intval, entry['length'], endianess)\n\n\t\treturn entry\n\n\tdef build_signature_set(self):\n\t\t'''\n\t\tBuilds a list of signature tuples.\n\n\t\tReturns a list of tuples in the format: [(<signature offset>, [set of 2-byte signatures])].\n\t\t'''\n\t\tsignatures = []\n\n\t\tfor (offset, sigset) in self.sigset.iteritems():\n\t\t\tsignatures.append((offset, sigset))\n\n\t\tsignatures.sort()\n\t\treturn signatures\n\n\tdef _to_string(self, value, size, endianess):\n\t\t'''\n\t\tConverts an integer value into a raw string.\n\n\t\t@value     - The integer value to convert.\n\t\t@size      - Size, in bytes, of the integer value.\n\t\t@endianess - One of self.LITTLE_ENDIAN | self.BIG_ENDIAN.\n\n\t\tReturns a raw string containing value.\n\t\t'''\n\t\tdata = \"\"\n\n\t\tfor i in range(0, size):\n\t\t\tdata += chr((value >> (8*i)) & 0xFF)\n\n\t\tif endianess != self.LITTLE_ENDIAN:\n\t\t\tdata = data[::-1]\n\n\t\treturn data\n\n\tdef split(self, data):\n\t\t'''\n\t\tSplits multiple libmagic results in the data string into a list of separate results.\n\n\t\t@data - Data string returned from libmagic.\n\n\t\tReturns a list of result strings.\n\t\t'''\n\t\ttry:\n\t\t\treturn data.split(self.RESULT_SEPERATOR)\n\t\texcept:\n\t\t\treturn []\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/prettyprint.py",
    "content": "import sys\nimport hashlib\nfrom datetime import datetime\n\nclass PrettyPrint:\n        '''\n        Class for printing Binwalk results to screen/log files.\n\t\n\tAn instance of PrettyPrint is available via the Binwalk.display object.\n\tThe PrettyPrint.results() method is of particular interest, as it is suitable for use as a Binwalk.scan() callback function,\n\tand can be used to print Binwalk.scan() results to stdout, a log file, or both.\n\n\tExample usage:\n\n\t\timport binwalk\n\n\t\tbw = binwalk.Binwalk()\n\n\t\tbw.display.header()\n\t\tbw.scan('firmware.bin', callback=bw.display.results)\n\t\tbw.display.footer()\n        '''\n\n        def __init__(self, log=None, quiet=False, bwalk=None, verbose=0):\n                '''\n                Class constructor.\n\t\t\n\t\t@log     - Output log file.\n\t\t@quiet   - If True, results will not be displayed to screen.\n\t\t@bwalk   - The Binwalk class instance.\n\t\t@verbose - If set to True, target file information will be displayed when file_info() is called.\n\n\t\tReturns None.\n\t\t'''\n                self.fp = None\n                self.log =log\n                self.quiet = quiet\n                self.binwalk = bwalk\n                self.verbose = verbose\n\n                if self.log is not None:\n                        self.fp = open(log, \"w\")\n\n        def __del__(self):\n\t\t'''\n\t\tClass deconstructor.\n\t\t'''\n\t\t# Close the log file.\n                try:\n                        self.fp.close()\n                except:\n                        pass\n\n        def _log(self, data):\n\t\t'''\n\t\tLog data to the log file.\n\t\t'''\n                if self.fp is not None:\n                        self.fp.write(data)\n\n        def _pprint(self, data):\n\t\t'''\n\t\tPrint data to stdout and the log file.\n\t\t'''\n                if not self.quiet:\n                        sys.stdout.write(data)\n                self._log(data)\n\n        def _file_md5(self, file_name):\n\t\t'''\n\t\tGenerate an MD5 hash of the specified file.\n\t\t'''\n                md5 = hashlib.md5()\n                \n                with open(file_name, 'rb') as f:\n                        for chunk in iter(lambda: f.read(128*md5.block_size), b''):\n                                md5.update(chunk)\n\n                return md5.hexdigest()\n                        \n        def file_info(self, file_name):\n\t\t'''\n\t\tPrints detailed info about the specified file, including file name, scan time and the file's MD5 sum.\n\t\tCalled internally by self.header if self.verbose is not 0.\n\n\t\t@file_name - The path to the target file.\n\n\t\tReturns None.\n\t\t'''\n                self._pprint(\"\\n\")\n                self._pprint(\"Scan Time:     %s\\n\" % datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n\t\tself._pprint(\"Signatures:    %d\\n\" % self.binwalk.parser.signature_count)\n                self._pprint(\"Target File:   %s\\n\" % file_name)\n                self._pprint(\"MD5 Checksum:  %s\\n\" % self._file_md5(file_name))\n\n        def header(self, file_name=None):\n\t\t'''\n\t\tPrints the Binwalk header, typically used just before starting a scan.\n\n\t\t@file_name - If specified, and if self.verbose > 0, then detailed file info will be included in the header.\n\n\t\tReturns None.\n\t\t'''\n                if self.verbose and file_name is not None:\n                        self.file_info(file_name)\n\n                self._pprint(\"\\nDECIMAL   \\tHEX       \\tDESCRIPTION\\n\")\n                self._pprint(\"-------------------------------------------------------------------------------------------------------\\n\")\n\n        def footer(self):\n\t\t'''\n\t\tPrints the Binwalk footer, typically used just after completing a scan.\n\n\t\tReturns None.\n\t\t'''\n                self._pprint(\"\\n\")\n\n        def results(self, offset, results):\n\t\t'''\n\t\tPrints the results of a scan. Suitable for use as a callback function for Binwalk.scan().\n\n\t\t@offset  - The offset at which the results were found.\n\t\t@results - A list of libmagic result strings.\n\t\t\n\t\tReturns None.\n\t\t'''\n                offset_printed = False\n\n                for info in results:\n\t\t\t# Check for any grep filters before printing\n                        if self.binwalk is not None and self.binwalk.filter.grep(info['description']):\n\t\t\t\t# Only display the offset once per list of results\n                                if not offset_printed:\n                                        self._pprint(\"%-10d\\t0x%-8X\\t%s\\n\" % (offset, offset, info['description']))\n                                        offset_printed = True\n                                else:\n                                        self._pprint(\"%s\\t  %s\\t%s\\n\" % (' '*10, ' '*8, info['description']))\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/smartsig.py",
    "content": "import re\nfrom common import str2int, get_quoted_strings\n\nclass SmartSignature:\n\t'''\n\tClass for parsing smart signature tags in libmagic result strings.\n\n\tThis class is intended for internal use only, but a list of supported 'smart keywords' that may be used \n\tin magic files is available via the SmartSignature.KEYWORDS dictionary:\n\n\t\tfrom binwalk import SmartSignature\n\n\t\tfor (i, keyword) in SmartSignature().KEYWORDS.iteritems():\n\t\t\tprint keyword\n\t'''\n\n\tKEYWORD_DELIM_START = \"{\"\n\tKEYWORD_DELIM_END = \"}\"\n\tKEYWORDS = {\n\t\t'jump'\t\t\t: '%sjump-to-offset:' % KEYWORD_DELIM_START,\n\t\t'filename'\t\t: '%sfile-name:' % KEYWORD_DELIM_START,\n\t\t'filesize'\t\t: '%sfile-size:' % KEYWORD_DELIM_START,\n\t\t'raw-string'\t\t: '%sraw-string:' % KEYWORD_DELIM_START,\t# This one is special and must come last in a signature block\n\t\t'raw-size'\t\t: '%sraw-string-length:' % KEYWORD_DELIM_START,\n\t\t'adjust'\t\t: '%soffset-adjust:' % KEYWORD_DELIM_START,\n\t\t'delay'\t\t\t: '%sextract-delay:' % KEYWORD_DELIM_START,\n\n\t\t'raw-replace'\t\t: '%sraw-replace%s' % (KEYWORD_DELIM_START, KEYWORD_DELIM_END),\n\t\t'one-of-many'\t\t: '%sone-of-many%s' % (KEYWORD_DELIM_START, KEYWORD_DELIM_END),\n\t\t'include'\t\t: '%sfilter-include%s' % (KEYWORD_DELIM_START, KEYWORD_DELIM_END),\n\t\t'exclude'\t\t: '%sfilter-exclude%s' % (KEYWORD_DELIM_START, KEYWORD_DELIM_END),\n\t}\n\n\tdef __init__(self, filter, pre_filter_signatures=True):\n\t\t'''\n\t\tClass constructor.\n\n\t\t@filter                - Instance of the MagicFilter class.\n\t\t@pre_filter_signatures - Set to False to disable the pre-filtering of magic signatures.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.filter = filter\n\t\tself.last_one_of_many = None\n\t\tself.pre_filter_signatures = pre_filter_signatures\n\n\tdef parse(self, data):\n\t\t'''\n\t\tParse a given data string for smart signature keywords. If any are found, interpret them and strip them.\n\n\t\t@data - String to parse, as returned by libmagic.\n\n\t\tReturns a dictionary of parsed values.\n\t\t'''\n\t\tresults = {\n\t\t\t'description'\t: '',\t# The libmagic data string, stripped of all keywords\n\t\t\t'name'\t\t: '',\t# The original name of the file, if known\n\t\t\t'delay'\t\t: '',\t# Extract delay description\n\t\t\t'extract'\t: '',\t# Name of the extracted file, filled in by Binwalk.Scan.\n\t\t\t'jump'\t\t: 0,\t# The relative offset to resume the scan from\n\t\t\t'size'\t\t: 0,\t# The size of the file, if known\n\t\t\t'adjust'\t: 0,\t# The relative offset to add to the reported offset\n\t\t}\n\n\t\t# If pre-filtering is disabled, or the result data is not valid (i.e., potentially malicious), \n\t\t# don't parse anything, just return the raw data as the description.\n\t\tif not self.pre_filter_signatures or not self._is_valid(data):\n\t\t\tresults['description'] = data\n\t\telse:\n\t\t\t# Parse the offset-adjust value. This is used to adjust the reported offset at which \n\t\t\t# a signature was located due to the fact that MagicParser.match expects all signatures\n\t\t\t# to be located at offset 0, which some wil not be.\n\t\t\tresults['adjust'] = self._get_math_arg(data, 'adjust')\n\n\t\t\t# Parse the file-size value. This is used to determine how many bytes should be extracted\n\t\t\t# when extraction is enabled. If not specified, everything to the end of the file will be\n\t\t\t# extracted (see Binwalk.scan).\n\t\t\ttry:\n\t\t\t\tresults['size'] = str2int(self._get_keyword_arg(data, 'filesize'))\n\t\t\texcept:\n\t\t\t\tpass\n\n\t\t\tresults['delay'] = self._get_keyword_arg(data, 'delay')\n\n\t\t\t# Parse the string for the jump-to-offset keyword.\n\t\t\t# This keyword is honored, even if this string result is one of many.\n\t\t\tresults['jump'] = self._get_math_arg(data, 'jump')\n\n\t\t\t# If this is one of many, don't do anything and leave description as a blank string.\n\t\t\t# Else, strip all keyword tags from the string and process additional keywords as necessary.\n\t\t\tif not self._one_of_many(data):\n\t\t\t\tresults['name'] = self._get_keyword_arg(data, 'filename').strip('\"')\n\t\t\t\tresults['description'] = self._strip_tags(data)\n\n\t\treturn results\n\n\tdef _is_valid(self, data):\n\t\t'''\n\t\tValidates that result data does not contain smart keywords in file-supplied strings.\n\n\t\t@data - Data string to validate.\n\n\t\tReturns True if data is OK.\n\t\tReturns False if data is not OK.\n\t\t'''\n\t\t# All strings printed from the target file should be placed in strings, else there is\n\t\t# no way to distinguish between intended keywords and unintended keywords. Get all the\n\t\t# quoted strings.\n\t\tquoted_data = get_quoted_strings(data)\n\n\t\t# Check to see if there was any quoted data, and if so, if it contained the keyword starting delimiter\n\t\tif quoted_data and self.KEYWORD_DELIM_START in quoted_data:\n\t\t\t# If so, check to see if the quoted data contains any of our keywords.\n\t\t\t# If any keywords are found inside of quoted data, consider the keywords invalid.\n\t\t\tfor (name, keyword) in self.KEYWORDS.iteritems():\n\t\t\t\tif keyword in quoted_data:\n\t\t\t\t\treturn False\n\t\treturn True\n\n\tdef _one_of_many(self, data):\n\t\t'''\n\t\tDetermines if a given data string is one result of many.\n\n\t\t@data - String result data.\n\n\t\tReturns True if the string result is one of many.\n\t\tReturns False if the string result is not one of many.\n\t\t'''\n\t\tif not self.filter.invalid(data):\n\t\t\tif self.last_one_of_many is not None and data.startswith(self.last_one_of_many):\n\t\t\t\treturn True\n\t\t\n\t\t\tif self.KEYWORDS['one-of-many'] in data:\n\t\t\t\t# Only match on the data before the first comma, as that is typically unique and static\n\t\t\t\tself.last_one_of_many = data.split(',')[0]\n\t\t\telse:\n\t\t\t\tself.last_one_of_many = None\n\t\t\t\n\t\treturn False\n\n\tdef _get_keyword_arg(self, data, keyword):\n\t\t'''\n\t\tRetrieves the argument for keywords that specify arguments.\n\n\t\t@data    - String result data, as returned by libmagic.\n\t\t@keyword - Keyword index in KEYWORDS.\n\n\t\tReturns the argument string value on success.\n\t\tReturns a blank string on failure.\n\t\t'''\n\t\targ = ''\n\n\t\tif self.KEYWORDS.has_key(keyword) and self.KEYWORDS[keyword] in data:\n\t\t\targ = data.split(self.KEYWORDS[keyword])[1].split(self.KEYWORD_DELIM_END)[0]\n\n\t\treturn arg\n\n\tdef _get_math_arg(self, data, keyword):\n\t\t'''\n\t\tRetrieves the argument for keywords that specifiy mathematical expressions as arguments.\n\n\t\t@data    - String result data, as returned by libmagic.\n\t\t@keyword - Keyword index in KEYWORDS.\n\n\t\tReturns the resulting calculated value.\n\t\t'''\n\t\tvalue = 0\n\n\t\targ = self._get_keyword_arg(data, keyword)\n\t\tif arg:\n\t\t\tfor string_int in arg.split('+'):\n\t\t\t\ttry:\n\t\t\t\t\tvalue += str2int(string_int)\n\t\t\t\texcept:\n\t\t\t\t\tpass\n\n\t\treturn value\t\t\t\n\n\tdef _jump(self, data):\n\t\t'''\n\t\tObtains the jump-to-offset value of a signature, if any.\n\n\t\t@data - String result data.\n\n\t\tReturns the offset to jump to.\n\t\t'''\n\t\toffset = 0\n\n\t\toffset_str = self._get_keyword_arg(data, 'jump')\n\t\tif offset_str:\n\t\t\ttry:\n\t\t\t\toffset = str2int(offset_str)\n\t\t\texcept:\n\t\t\t\tpass\n\n\t\treturn offset\n\n\tdef _parse_raw_strings(self, data):\n\t\t'''\n\t\tProcess strings that aren't NULL byte terminated, but for which we know the string length.\n\t\tThis should be called prior to any other smart parsing functions.\n\n\t\t@data - String to parse.\n\n\t\tReturns a parsed string.\n\t\t'''\n\t\tif self.pre_filter_signatures and self._is_valid(data):\n\t\t\t# Get the raw string  keyword arg\n\t\t\traw_string = self._get_keyword_arg(data, 'raw-string')\n\n\t\t\t# Was a raw string  keyword specified?\n\t\t\tif raw_string:\n\t\t\t\t# Get the raw string length arg\n\t\t\t\traw_size = self._get_keyword_arg(data, 'raw-size')\n\t\n\t\t\t\t# Is the raw string  length arg is a numeric value?\n\t\t\t\tif re.match('^-?[0-9]+$', raw_size):\n\t\t\t\t\t# Replace all instances of raw-replace in data with raw_string[:raw_size]\n\t\t\t\t\t# Also strip out everything after the raw-string keyword, including the keyword itself.\n\t\t\t\t\t# Failure to do so may (will) result in non-printable characters and this string will be \n\t\t\t\t\t# marked as invalid when it shouldn't be.\n\t\t\t\t\tdata = data[:data.find(self.KEYWORDS['raw-string'])].replace(self.KEYWORDS['raw-replace'], '\"' + raw_string[:str2int(raw_size)] + '\"')\n\t\treturn data\n\n\tdef include(self, data):\n\t\t'''\n\t\tDetermines if a result should be included or excluded.\n\n\t\t@data - String result data.\n\n\t\tReturns True if the include smart tag is present.\n\t\tReturns False if the exclude smart tag is present.\n\t\tReturns None if neither smart tags are present.\n\t\t'''\n\t\t# Validate keywords before checking for the include/exclude keywords.\n\t\tif self.pre_filter_signatures and self._is_valid(data):\n\t\t\tif self.KEYWORDS['exclude'] in data:\n\t\t\t\treturn False\n\t\t\telif self.KEYWORDS['include'] in data:\n\t\t\t\treturn True\n\t\treturn None\n\n\tdef _strip_tags(self, data):\n\t\t'''\n\t\tStrips the smart tags from a result string.\n\n\t\t@data - String result data.\n\n\t\tReturns a sanitized string.\n\t\t'''\n\t\tif self.pre_filter_signatures:\n\t\t\tfor (name, keyword) in self.KEYWORDS.iteritems():\n\t\t\t\tstart = data.find(keyword)\n\t\t\t\tif start != -1:\n\t\t\t\t\tend = data[start:].find(self.KEYWORD_DELIM_END)\n\t\t\t\t\tif end != -1:\n\t\t\t\t\t\tdata = data.replace(data[start:start+end+1], \"\")\n\t\treturn data\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/binwalk/update.py",
    "content": "import urllib2\nfrom config import *\n\nclass Update:\n\t'''\n\tClass for updating Binwalk configuration and signatures files from the subversion trunk.\n\n\tExample usage:\n\n\t\tfrom binwalk import Update\n\n\t\tUpdate().update()\n\t'''\n\tBASE_URL = \"http://binwalk.googlecode.com/svn/trunk/src/binwalk/\"\n\tMAGIC_PREFIX = \"magic/\"\n\tCONFIG_PREFIX = \"config/\"\n\n\tdef __init__(self):\n\t\t'''\n\t\tClass constructor.\n\t\t'''\n\t\tself.config = Config()\n\n\tdef update(self):\n\t\t'''\n\t\tUpdates all system wide signatures and config files.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.update_binwalk()\n\t\tself.update_bincast()\n\t\tself.update_binarch()\n\t\tself.update_extract()\n\n\tdef _do_update_from_svn(self, prefix, fname):\n\t\t'''\n\t\tUpdates the specified file to the latest version of that file in SVN.\n\n\t\t@prefix - The URL subdirectory where the file is located.\n\t\t@fname  - The name of the file to update.\n\n\t\tReturns None.\n\t\t'''\n\t\turl = self.BASE_URL + prefix + fname\n\t\t\n\t\ttry:\n\t\t\tdata = urllib2.urlopen(url).read()\n\t\t\topen(self.config.paths['system'][fname], \"wb\").write(data)\n\t\texcept Exception, e:\n\t\t\traise Exception(\"Update._do_update_from_svn failed to update file '%s': %s\" % (url, str(e)))\n\n\tdef update_binwalk(self):\n\t\t'''\n\t\tUpdates the binwalk signature file.\n\n\t\tReturns None.\n\t\t'''\n\t\tself._do_update_from_svn(self.MAGIC_PREFIX, self.config.BINWALK_MAGIC_FILE)\n\t\n\tdef update_bincast(self):\n\t\t'''\n\t\tUpdates the bincast signature file.\n\n\t\tReturns None.\n\t\t'''\n\t\tself._do_update_from_svn(self.MAGIC_PREFIX, self.config.BINCAST_MAGIC_FILE)\n\t\n\tdef update_binarch(self):\n\t\t'''\n\t\tUpdates the binarch signature file.\n\t\n\t\tReturns None.\n\t\t'''\n\t\tself._do_update_from_svn(self.MAGIC_PREFIX, self.config.BINARCH_MAGIC_FILE)\n\n\tdef update_extract(self):\n\t\t'''\n\t\tUpdates the extract.conf file.\n\t\n\t\tReturns None.\n\t\t'''\n\t\tself._do_update_from_svn(self.CONFIG_PREFIX, self.config.EXTRACT_FILE)\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/__init__.py",
    "content": "import os\nimport magic\nfrom config import *\nfrom update import *\nfrom filter import *\nfrom parser import *\nfrom smartsig import *\nfrom extractor import *\nfrom prettyprint import *\nfrom common import file_size\n\nclass Binwalk:\n\t'''\n\tPrimary Binwalk class.\n\n\tInteresting class objects:\n\n\t\tself.filter        - An instance of the MagicFilter class.\n\t\tself.extractor     - An instance of the Extractor class.\n\t\tself.parser        - An instance of the MagicParser class.\n\t\tself.display       - An instance of the PrettyPrint class.\n\t\tself.magic_files   - A list of magic file path strings to use whenever the scan() method is invoked.\n\t\tself.scan_length   - The total number of bytes to be scanned.\n\t\tself.total_scanned - The number of bytes that have already been scanned.\n\t'''\n\n\t# Default libmagic flags. Basically disable anything we don't need in the name of speed.\n\tDEFAULT_FLAGS = magic.MAGIC_NO_CHECK_TEXT | magic.MAGIC_NO_CHECK_ENCODING | magic.MAGIC_NO_CHECK_APPTYPE | magic.MAGIC_NO_CHECK_TOKENS\n\n\t# The MAX_SIGNATURE_SIZE limits the amount of data available to a signature.\n\t# While most headers/signatures are far less than this value, some may reference \n\t# pointers in the header structure which may point well beyond the header itself.\n\t# Passing the entire remaining buffer to libmagic is resource intensive and will\n\t# significantly slow the scan; this value represents a reasonable buffer size to\n\t# pass to libmagic which will not drastically affect scan time.\n\tMAX_SIGNATURE_SIZE = 8092\n\n\t# Max number of bytes to process at one time. Everyone should have 50MB of memory, right?\n\tREAD_BLOCK_SIZE = 50 * 1024 * 1024\n\n\t# Minimum verbosity level at which to enable extractor verbosity.\n\tVERY_VERBOSE = 2\n\n\t# Scan every byte by default.\n\tDEFAULT_BYTE_ALIGNMENT = 1\n\n\tdef __init__(self, magic_files=[], flags=magic.MAGIC_NONE, log=None, quiet=False, verbose=0):\n\t\t'''\n\t\tClass constructor.\n\n\t\t@magic_files - A list of magic files to use.\n\t\t@flags       - Flags to pass to magic_open. [TODO: Might this be more appropriate as an argument to load_signaures?]\n\t\t@log         - Output PrettyPrint data to log file as well as to stdout.\n\t\t@quiet       - If set to True, supress PrettyPrint output to stdout.\n\t\t@verbose     - Verbosity level.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.flags = self.DEFAULT_FLAGS | flags\n\t\tself.magic_files = magic_files\n\t\tself.verbose = verbose\n\t\tself.total_scanned = 0\n\t\tself.scan_length = 0\n\t\tself.total_read = 0\n\t\tself.magic = None\n\t\tself.mfile = None\n\n\t\t# Instantiate the config class so we can access file/directory paths\n\t\tself.config = Config()\n\n\t\t# Use the system default magic file if no other was specified\n\t\tif not self.magic_files or self.magic_files is None:\n\t\t\t# Append the user's magic file first so that those signatures take precedence\n\t\t\tself.magic_files = [\n\t\t\t\t\tself.config.paths['user'][self.config.BINWALK_MAGIC_FILE],\n\t\t\t\t\tself.config.paths['system'][self.config.BINWALK_MAGIC_FILE],\n\t\t\t]\n\n\n\t\t# Only set the extractor verbosity if told to be very verbose\n\t\tif self.verbose >= self.VERY_VERBOSE:\n\t\t\textractor_verbose = True\n\t\telse:\n\t\t\textractor_verbose = False\n\n\t\t# Create an instance of the PrettyPrint class, which can be used to print results to screen/file.\n\t\tself.display = PrettyPrint(log=log, quiet=quiet, verbose=verbose, bwalk=self)\n\n\t\t# Create MagicFilter and Extractor class instances. These can be used to:\n\t\t#\n\t\t#\to Create include/exclude filters\n\t\t#\to Specify file extraction rules to be applied during a scan\n\t\t#\n\t\tself.filter = MagicFilter()\n\t\tself.extractor = Extractor(verbose=extractor_verbose)\n\t\t\n\t\t# Create SmartSignature and MagicParser class instances. These are mostly for internal use.\n\t\tself.smart = SmartSignature(self.filter)\n\t\tself.parser = MagicParser(self.filter, self.smart)\n\n\tdef __del__(self):\n\t\t'''\n\t\tClass deconstructor.\n\t\t'''\n\t\tself.cleanup()\n\n\tdef cleanup(self):\n\t\t'''\n\t\tCleanup any temporary files generated by the internal instance of MagicParser.\n\n\t\tReturns None.\n\t\t'''\n\t\ttry:\n\t\t\tself.parser.cleanup()\n\t\texcept:\n\t\t\tpass\n\n\tdef load_signatures(self, magic_files=[], pre_filter_signatures=True, filter_short_signatures=True):\n\t\t'''\n\t\tLoad signatures from magic file(s).\n\t\tCalled automatically by Binwalk.scan() with all defaults, if not already called manually.\n\n\t\t@magic_files\t\t\t- A list of magic files to use (default: self.magic_files).\n\t\t@pre_filter_signatures \t\t- Set to False to disable pre-filtering of signatures before invoking libmagic.\n\t\t@filter_short_signatures\t- Set to True to include signatures with short (<= 2 byte) magic strings.\n\t\n\t\tReturns None.\t\n\t\t'''\n\t\t# Disable pre filtering in the smart signature class instance.\n\t\t# This is also checked by Binwalk.scan() before performing pre-filtering.\n\t\tself.smart.pre_filter = pre_filter_signatures\n\n\t\t# The magic files specified here override any already set\n\t\tif magic_files and magic_files is not None:\n\t\t\tself.magic_files = magic_files\n\n\t\t# Parse the magic file(s) and initialize libmagic\n\t\tself.mfile = self.parser.parse(self.magic_files, filter_short_signatures=filter_short_signatures, pre_filter_signatures=pre_filter_signatures)\n\t\tself.magic = magic.open(self.flags)\n\t\tself.magic.load(self.mfile)\n\n\tdef scan(self, target_file, offset=0, length=0, align=DEFAULT_BYTE_ALIGNMENT, show_invalid_results=False, callback=None):\n\t\t'''\n\t\tPerforms a Binwalk scan on the target file.\n\n\t\t@target_file \t\t\t- File to scan.\n\t\t@offset      \t\t\t- Starting offset at which to start the scan.\n\t\t@length      \t\t\t- Number of bytes to scan.\n\t\t@align       \t\t\t- Look for signatures every align bytes.\n\t\t@show_invalid_results\t\t- Set to True to display invalid results.\n\t\t@callback    \t\t\t- Callback function to be invoked when matches are found.\n\n\t\tThe callback function is passed two arguments: a list of result dictionaries containing the scan results\n\t\t(one result per dict), and the offset at which those results were identified. Example callback function:\n\n\t\t\tdef my_callback(offset, results):\n\t\t\t\tprint \"Found %d results at offset %d:\" % (len(results), offset)\n\t\t\t\tfor result in results:\n\t\t\t\t\tprint \"\\t%s\" % result['description']\n\n\t\t\tbinwalk.Binwalk(callback=my_callback).scan(\"firmware.bin\")\n\n\t\tUpon completion, the scan method returns a sorted list of tuples containing a list of results dictionaries\n\t\tand the offsets at which those results were identified:\n\n\t\t\tscan_items = [\n\t\t\t\t\t(0, [{description : \"LZMA compressed data...\"}]),\n\t\t\t\t\t(112, [{description : \"gzip compressed data...\"}])\n\t\t\t]\n\n\t\tSee SmartSignature.parse for a more detailed description of the results dictionary structure.\n\t\t'''\n\t\tscan_results = {}\n\t\tself.total_read = 0\n\t\tself.total_scanned = 0\n\t\tself.scan_length = length\n\t\tself.filter.show_invalid_results = show_invalid_results\n\n\t\t# Load the default signatures if self.load_signatures has not already been invoked\n\t\tif self.magic is None:\n\t\t\tself.load_signatures()\n\n\t\t# Get a local copy of the signature sets generated by self.parser.build_signature_set.\n\t\t# This is accessed heavily throughout the scan, and there is less overhead for accessing local variables in Python.\n\t\tsignature_set = self.parser.build_signature_set()\n\n\t\t# Need the total size of the target file, even if we aren't scanning the whole thing\n\t\tfsize = file_size(target_file)\n\n\t\t# Open the target file and seek to the specified start offset\n\t\tfd = open(target_file)\n\t\tfd.seek(offset)\n\t\t\n\t\t# If no length was specified, make the length the size of the target file minus the starting offset\n\t\tif self.scan_length == 0:\n\t\t\tself.scan_length = fsize - offset\n\t\t# Sanity check on the byte alignment; default to 1\n\t\tif align <= 0:\n\t\t\talign = 1\n\n\t\t# Main loop, scan through all the data\n\t\twhile True:\n\t\t\ti = 0\n\n\t\t\t# Read in the next block of data from the target file and make sure it's valid\n\t\t\t(data, dlen) = self._read_block(fd)\n\t\t\tif data is None or dlen == 0:\n\t\t\t\tbreak\n\n\t\t\t# The total number of bytes scanned could be bigger than the total number\n\t\t\t# of bytes read from the file under the following circumstances:\n\t\t\t#\n\t\t\t#\to The previous dlen was not a multiple of align\n\t\t\t#\to A previous result specified a jump offset that was beyond the end of the\n\t\t\t#\t  then current data block\n\t\t\t#\n\t\t\t# If this is the case, we need to index into this data block appropriately in order to \n\t\t\t# resume the scan from the appropriate offset, and adjust dlen accordingly.\n\t\t\tbufindex = self.total_scanned - self.total_read\n\t\t\tif bufindex > 0:\n\t\t\t\t# If the total_scanned > total_read, then the total_scanned offset is in a subsequent block.\n\t\t\t\t# Set i to bufindex, which will cause i to be greater than dlen and this block will be skipped.\n\t\t\t\ti = bufindex\n\t\t\telif bufindex < 0:\n\t\t\t\t# If the total_scanned offset is less than total_read, then the total_scanned offset is\n\t\t\t\t# somewhere inside this block. Set i to index into the block appropriately.\n\t\t\t\ti = dlen + bufindex\n\t\t\telse:\n\t\t\t\t# If the total_scanned offset ends at the end of this block, don't scan any of this block\n\t\t\t\ti = dlen\n\n\t\t\t# Scan through each block of data looking for signatures\n\t\t\twhile i < dlen:\n\t\t\t\tsmart = {}\n\t\t\t\tresults = []\n\t\t\t\tresults_offset = -1\n\t\t\t\tpre_filter_ok = False\n\t\t\t\tsmart_jump_done = False\n\n\t\t\t\t# Pre-filter data by checking to see if the parser thinks this might be a valid match.\n\t\t\t\t# This eliminates unnecessary calls into libmagic, which are very expensive.\n\t\t\t\t#\n\t\t\t\t# Ideally, this should be done in the MagicParser class, but function calls are expensive.\n\t\t\t\t# Doing it here greatly decreases the scan time.\n\t\t\t\tif self.smart.pre_filter:\n\t\t\t\t\tfor (sig_offset, sigset) in signature_set:\n                        \t\t\tif data[i+sig_offset:i+sig_offset+self.parser.MATCH_INDEX_SIZE] in sigset:\n                                \t\t\tpre_filter_ok = True\n\t\t\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tpre_filter_ok = True\n\n\t\t\t\tif pre_filter_ok:\n\t\t\t\t\t# Pass the data to libmagic, and split out multiple results into a list\n\t\t\t\t\tfor magic_result in self.parser.split(self.magic.buffer(data[i:i+self.MAX_SIGNATURE_SIZE])):\n\n\t\t\t\t\t\t# Some file names are not NULL byte terminated, but rather their length is\n\t\t\t\t\t\t# specified in a size field. To ensure these are not marked as invalid due to\n\t\t\t\t\t\t# non-printable characters existing in the file name, parse the filename(s) and\n\t\t\t\t\t\t# trim them to the specified filename length, if one was specified.\n\t\t\t\t\t\tmagic_result = self.smart._parse_raw_strings(magic_result)\n\n\t\t\t\t\t\t# Make sure this is a valid result before further processing\n\t\t\t\t\t\tif not self.filter.invalid(magic_result):\n\t\t\t\t\t\t\t# The smart filter parser returns a dictionary of keyword values and the signature description.\n\t\t\t\t\t\t\tsmart = self.smart.parse(magic_result)\n\t\n\t\t\t\t\t\t\t# Validate the jump value and check if the response description should be displayed\n\t\t\t\t\t\t\tif smart['jump'] > -1 and self._should_display(smart['description']):\n\t\t\t\t\t\t\t\t# If multiple results are returned and one of them has smart['jump'] set to a non-zero value,\n\t\t\t\t\t\t\t\t# the calculated results offset will be wrong since i will have been incremented. Only set the\n\t\t\t\t\t\t\t\t# results_offset value when the first match is encountered.\n\t\t\t\t\t\t\t\tif results_offset < 0:\n\t\t\t\t\t\t\t\t\tresults_offset = offset + smart['adjust'] + self.total_scanned\n\n\t\t\t\t\t\t\t\t# Double check to make sure the smart['adjust'] value is sane. \n\t\t\t\t\t\t\t\t# If it makes results_offset negative, then it is not sane.\n\t\t\t\t\t\t\t\tif results_offset >= 0:\n\t\t\t\t\t\t\t\t\t# Extract the result, if it matches one of the extract rules and is not a delayed extract.\n\t\t\t\t\t\t\t\t\tif self.extractor.enabled and not (self.extractor.delayed and smart['delay']):\n\t\t\t\t\t\t\t\t\t\t# If the signature did not specify a size, extract to the end of the file.\n\t\t\t\t\t\t\t\t\t\tif smart['size'] == 0:\n\t\t\t\t\t\t\t\t\t\t\tsmart['size'] = fsize-results_offset\n\n\t\t\t\t\t\t\t\t\t\tsmart['extract'] = self.extractor.extract(\tresults_offset, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsmart['description'], \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttarget_file, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsmart['size'], \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tname=smart['name'])\n\n\t\t\t\t\t\t\t\t\t# This appears to be a valid result, so append it to the results list.\n\t\t\t\t\t\t\t\t\tresults.append(smart)\n\n\t\t\t\t\t\t\t# Jump to the offset specified by jump. Only do this once, so that if multiple results\n\t\t\t\t\t\t\t# are returned each of which specify a jump offset, only the first will be honored.\n\t\t\t\t\t\t\tif smart['jump'] > 0 and not smart_jump_done:\n\t\t\t\t\t\t\t\t# Once a jump offset has been honored, we need to start scanning every byte since the\n\t\t\t\t\t\t\t\t# jump offset may have thrown off the original alignment. In terms of speed this is fine,\n\t\t\t\t\t\t\t\t# since the jump offset usually saves more time anyway. If this is not what the user\n\t\t\t\t\t\t\t\t# wanted/intended, disabling pre filtering will disable jump offset processing completely.\n\t\t\t\t\t\t\t\talign = self.DEFAULT_BYTE_ALIGNMENT\n\t\t\t\t\t\t\t\tsmart_jump_done = True\n\t\t\t\t\t\t\t\ti += (smart['jump'] - align)\n\t\t\t\t\t\t\t\tself.total_scanned += (smart['jump'] - align)\n\n\t\t\t\t# Did we find any valid results?\n\t\t\t\tif results_offset >= 0:\n\t\t\t\t\tscan_results[results_offset] = results\n\t\t\t\t\t\n\t\t\t\t\tif callback is not None:\n\t\t\t\t\t\tcallback(results_offset, results)\n\n\t\t\t\t# Track the number of bytes scanned in this block, and the total number of bytes scanned.\t\n\t\t\t\ti += align\n\t\t\t\tself.total_scanned += align\n\n\t\t# Sort the results before returning them\n\t\tscan_items = scan_results.items()\n\t\tscan_items.sort()\n\n\t\t# Do delayed extraction, if specified.\n\t\tif self.extractor.enabled and self.extractor.delayed:\n\t\t\tscan_items = self.extractor.delayed_extract(scan_items, target_file, fsize)\n\n\t\treturn scan_items\n\n\tdef _should_display(self, data):\n\t\t'''\n\t\tDetermines if a result string should be displayed to the user or not.\n\t\t\n\t\t@data - Display string.\n\n\t\tReturns True if the string should be displayed.\n\t\tReturns False if the string should not be displayed.\n\t\t'''\n\t\treturn (data and data is not None and not self.filter.invalid(data) and self.filter.filter(data) != self.filter.FILTER_EXCLUDE)\n\n\tdef _read_block(self, fd):\n\t\t'''\n\t\tReads in a block of data from the target file.\n\n\t\t@fd - File object for the target file.\n\n\t\tReturns a tuple of (file block data, block data length).\n\t\t'''\n\t\tdlen = 0\n\t\tdata = None\n\t\t# Read in READ_BLOCK_SIZE plus MAX_SIGNATURE_SIZE bytes, but return a max dlen value\n\t\t# of READ_BLOCK_SIZE. This ensures that there is a MAX_SIGNATURE_SIZE buffer at the\n\t\t# end of the returned data in case a signature is found at or near data[dlen].\n\t\trlen = self.READ_BLOCK_SIZE + self.MAX_SIGNATURE_SIZE\n\n\t\tif self.total_read < self.scan_length:\n\t\t\t\n\t\t\tdata = fd.read(rlen)\n\t\t\t\n\t\t\tif data and data is not None:\n\t\t\t\t# Get the actual length of the read in data\n\t\t\t\tdlen = len(data)\n\n\t\t\t\t# If we've read in more data than the scan length, truncate the dlen value\n\t\t\t\tif (self.total_read + dlen) >= self.scan_length:\n\t\t\t\t\tdlen = self.scan_length - self.total_read\n\t\t\t\t# If dlen is the expected rlen size, it should be set to READ_BLOCK_SIZE\n\t\t\t\telif dlen == rlen:\n\t\t\t\t\tdlen = self.READ_BLOCK_SIZE\n\n\t\t\t\t# Increment self.total_read to reflect the amount of data that has been read\n\t\t\t\t# for processing (actual read size is larger of course, due to the MAX_SIGNATURE_SIZE\n\t\t\t\t# buffer of data at the end of each block).\n\t\t\t\tself.total_read += dlen\n\t\t\t\t# Seek to the self.total_read offset so the next read can pick up where this one left off\n\t\t\t\tfd.seek(self.total_read)\n\n\t\treturn (data, dlen)\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/common.py",
    "content": "# Common functions.\nimport os\nimport re\n\ndef file_size(filename):\n\t'''\n\tObtains the size of a given file.\n\n\t@filename - Path to the file.\n\n\tReturns the size of the file.\n\t'''\n\t# Using open/lseek works on both regular files and block devices\n\tfd = os.open(filename, os.O_RDONLY)\n\ttry:\n\t\treturn os.lseek(fd, 0, os.SEEK_END)\n\texcept Exception, e:\n\t\traise Exception(\"file_size failed to obtain the size of '%s': %s\" % (filename, str(e)))\n\tfinally:\n\t\tos.close(fd)\n\ndef str2int(string):\n\t'''\n\tAttempts to convert string to a base 10 integer; if that fails, then base 16.\n\n\t@string - String to convert to an integer.\n\n\tReturns the integer value on success.\n\tThrows an exception if the string cannot be converted into either a base 10 or base 16 integer value.\n\t'''\n\ttry:\n\t\treturn int(string)\n\texcept:\n\t\treturn int(string, 16)\n\ndef strip_quoted_strings(string):\n\t'''\n\tStrips out data in between double quotes.\n\t\n\t@string - String to strip.\n\n\tReturns a sanitized string.\n\t'''\n\t# This regex removes all quoted data from string.\n\t# Note that this removes everything in between the first and last double quote.\n\t# This is intentional, as printed (and quoted) strings from a target file may contain \n\t# double quotes, and this function should ignore those. However, it also means that any \n\t# data between two quoted strings (ex: '\"quote 1\" you won't see me \"quote 2\"') will also be stripped.\n\treturn re.sub(r'\\\"(.*)\\\"', \"\", string)\n\ndef get_quoted_strings(string):\n\t'''\n\tReturns a string comprised of all data in between double quotes.\n\n\t@string - String to get quoted data from.\n\n\tReturns a string of quoted data on success.\n\tReturns a blank string if no quoted data is present.\n\t'''\n\ttry:\n\t\t# This regex grabs all quoted data from string.\n\t\t# Note that this gets everything in between the first and last double quote.\n\t\t# This is intentional, as printed (and quoted) strings from a target file may contain \n\t\t# double quotes, and this function should ignore those. However, it also means that any \n\t\t# data between two quoted strings (ex: '\"quote 1\" non-quoted data \"quote 2\"') will also be included.\n\t\treturn re.findall(r'\\\"(.*)\\\"', string)[0]\n\texcept:\n\t\treturn ''\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/config/extract.conf",
    "content": "#################################################################################################################\n# Default extract rules loaded when --extract is specified.\n# \n# <case-insensitive unique string from binwalk output text>:<desired file extension>:<command to execute>\n#\n# Note that %e is a place holder for the extracted file name.\n#################################################################################################################\n\n# Assumes these utilities are installed in $PATH.\ngzip compressed data:gz:gzip -d -f '%e'\nlzma compressed data:7z:7zr e -y '%e'\nbzip2 compressed data:bz2:bzip2 -d -f '%e'\nzip archive data:zip:jar xf '%e' # jar does a better job of unzipping than unzip does...\nposix tar archive:tar:tar xvf '%e'\n\n# These assume the firmware-mod-kit is installed to /opt/firmware-mod-kit.\n# If not, change the file paths appropriately.\nsquashfs filesystem:squashfs:/opt/firmware-mod-kit/trunk/unsquashfs_all.sh '%e'\njffs2 filesystem:jffs2:/opt/firmware-mod-kit/trunk/src/jffs2/unjffs2 '%e' # requires root\ncpio archive:cpio:/opt/firmware-mod-kit/trunk/uncpio.sh '%e'\n\n# Extract, but don't run anything\next2 filesystem:ext2\nromfs filesystem:romfs\ncramfs filesystem:cramfs\nprivate key:key\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/config.py",
    "content": "import os\n\nclass Config:\n\t'''\n\tBinwalk configuration class, used for accessing user and system file paths.\n\t\n\tAfter instatiating the class, file paths can be accessed via the self.paths dictionary.\n\tSystem file paths are listed under the 'system' key, user file paths under the 'user' key.\n\n\tFor example, to get the path to both the user and system binwalk magic files:\n\n\t\tfrom binwalk import Config\n\n\t\tconf = Config()\n\t\tuser_binwalk_file = conf.paths['user'][conf.BINWALK_MAGIC_FILE]\n\t\tsystem_binwalk_file = conf.paths['system'][conf.BINWALK_MAGIC_FILE]\n\n\tThere is also an instance of this class available via the Binwalk.config object:\n\n\t\timport binwalk\n\n\t\tbw = binwalk.Binwalk()\n\n\t\tuser_binwalk_file = bw.config.paths['user'][conf.BINWALK_MAGIC_FILE]\n\t\tsystem_binwalk_file = bw.config.paths['system'][conf.BINWALK_MAGIC_FILE]\n\n\tValid file names under both the 'user' and 'system' keys are as follows:\n\n\t\to BINWALK_MAGIC_FILE  - Path to the default binwalk magic file.\n\t\to BINCAST_MAGIC_FILE  - Path to the bincast magic file (used when -C is specified with the command line binwalk script)\n\t\to BINARCH_MAGIC_FILE  - Path to the binarch magic file (used when -A is specified with the command line binwalk script)\n\t\to EXTRACT_FILE        - Path to the extract configuration file (used when -e is specified with the command line binwalk script)\n\t'''\n\t# Release version\n\tVERSION = \"1.0\"\n\n\t# Sub directories\n\tBINWALK_USER_DIR = \".binwalk\"\n\tBINWALK_MAGIC_DIR = \"magic\"\n\tBINWALK_CONFIG_DIR = \"config\"\n\n\t# File names\n\tEXTRACT_FILE = \"extract.conf\"\n\tBINWALK_MAGIC_FILE = \"binwalk\"\n\tBINCAST_MAGIC_FILE = \"bincast\"\n\tBINARCH_MAGIC_FILE = \"binarch\"\n\n\tdef __init__(self):\n\t\t'''\n\t\tClass constructor. Enumerates file paths and populates self.paths.\n\t\t'''\n\t\t# Path to the user binwalk directory\n\t\tself.user_dir = self._get_user_dir()\n\t\t# Path to the system wide binwalk directory\n\t\tself.system_dir = self._get_system_dir()\n\n\t\t# Dictionary of all absolute user/system file paths\n\t\tself.paths = {\n\t\t\t'user'\t\t: {},\n\t\t\t'system'\t: {},\n\t\t}\n\n\t\t# Build the paths to all user-specific files\n\t\tself.paths['user'][self.BINWALK_MAGIC_FILE] = self._user_file(self.BINWALK_MAGIC_DIR, self.BINWALK_MAGIC_FILE)\n\t\tself.paths['user'][self.BINCAST_MAGIC_FILE] = self._user_file(self.BINWALK_MAGIC_DIR, self.BINCAST_MAGIC_FILE)\n\t\tself.paths['user'][self.BINARCH_MAGIC_FILE] = self._user_file(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE)\n\t\tself.paths['user'][self.EXTRACT_FILE] = self._user_file(self.BINWALK_CONFIG_DIR, self.EXTRACT_FILE)\n\n\t\t# Build the paths to all system-wide files\n\t\tself.paths['system'][self.BINWALK_MAGIC_FILE] = self._system_file(self.BINWALK_MAGIC_DIR, self.BINWALK_MAGIC_FILE)\n\t\tself.paths['system'][self.BINCAST_MAGIC_FILE] = self._system_file(self.BINWALK_MAGIC_DIR, self.BINCAST_MAGIC_FILE)\n\t\tself.paths['system'][self.BINARCH_MAGIC_FILE] = self._system_file(self.BINWALK_MAGIC_DIR, self.BINARCH_MAGIC_FILE)\n\t\tself.paths['system'][self.EXTRACT_FILE] = self._system_file(self.BINWALK_CONFIG_DIR, self.EXTRACT_FILE)\n\t\n\tdef _get_system_dir(self):\n\t\t'''\n\t\tFind the directory where the binwalk module is installed on the system.\n\t\t'''\n\t\ttry:\n\t\t\troot = __file__\n\t\t\tif os.path.islink(root):\n\t\t\t\troot = os.path.realpath(root)\n\t\t\treturn os.path.dirname(os.path.abspath(root))\n\t\texcept:\n\t\t\treturn ''\n\n\tdef _get_user_dir(self):\n\t\t'''\n\t\tGet the user's home directory.\n\t\t'''\n\t\ttry:\n\t\t\t# This should work in both Windows and Unix environments\n\t\t\treturn os.getenv('USERPROFILE') or os.getenv('HOME')\n\t\texcept:\n\t\t\treturn ''\n\n\tdef _file_path(self, dirname, filename):\n\t\t'''\n\t\tBuilds an absolute path and creates the directory and file if they don't already exist.\n\n\t\t@dirname  - Directory path.\n\t\t@filename - File name.\n\t\t\n\t\tReturns a full path of 'dirname/filename'.\n\t\t'''\n\t\tif not os.path.exists(dirname):\n\t\t\ttry:\n\t\t\t\tos.makedirs(dirname)\n\t\t\texcept:\n\t\t\t\tpass\n\t\t\n\t\tfpath = os.path.join(dirname, filename)\n\n\t\tif not os.path.exists(fpath):\n\t\t\ttry:\n\t\t\t\topen(fpath, \"w\").close()\n\t\t\texcept:\n\t\t\t\tpass\n\n\t\treturn fpath\n\n\tdef _user_file(self, subdir, basename):\n\t\t'''\n\t\tGets the full path to the 'subdir/basename' file in the user binwalk directory.\n\n\t\t@subdir   - Subdirectory inside the user binwalk directory.\n\t\t@basename - File name inside the subdirectory.\n\n\t\tReturns the full path to the 'subdir/basename' file.\n\t\t'''\n\t\treturn self._file_path(os.path.join(self.user_dir, self.BINWALK_USER_DIR, subdir), basename)\n\n\tdef _system_file(self, subdir, basename):\n\t\t'''\n\t\tGets the full path to the 'subdir/basename' file in the system binwalk directory.\n\t\t\n\t\t@subdir   - Subdirectory inside the system binwalk directory.\n\t\t@basename - File name inside the subdirectory.\n\t\t\n\t\tReturns the full path to the 'subdir/basename' file.\n\t\t'''\n\t\treturn self._file_path(os.path.join(self.system_dir, subdir), basename)\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/extractor.py",
    "content": "import os\nimport sys\nimport shlex\nimport tempfile\nimport subprocess\nfrom config import *\nfrom common import file_size\n\nclass Extractor:\n\t'''\n\tExtractor class, responsible for extracting files from the target file and executing external applications, if requested.\n\tAn instance of this class is accessible via the Binwalk.extractor object.\n\n\tExample usage:\n\n\t\timport binwalk\n\t\t\n\t\tbw = binwalk.Binwalk()\n\n\t\t# Create extraction rules for scan results containing the string 'gzip compressed data' and 'filesystem'.\n\t\t# The former will be saved to disk with a file extension of 'gz' and the command 'gunzip <file name on disk>' will be executed (note the %e placeholder).\n\t\t# The latter will be saved to disk with a file extension of 'fs' and no command will be executed.\n\t\t# These rules will take precedence over subsequent rules with the same match string.\n\t\tbw.extractor.add_rule(['gzip compressed data:gz:gunzip %e', 'filesystem:fs'])\n\n\t\t# Load the extraction rules from the default extract.conf file(s).\n\t\tbw.extractor.load_defaults()\n\n\t\t# Run the binwalk scan.\n\t\tbw.scan('firmware.bin')\n\t\t\n\t'''\n\t# Extract rules are delimited with a colon.\n\t# <case insensitive matching string>:<file extension>[:<command to run>]\n\tRULE_DELIM = ':'\n\n\t# Comments in the extract.conf files start with a pound\n\tCOMMENT_DELIM ='#'\n\n\t# Place holder for the extracted file name in the command \n\tFILE_NAME_PLACEHOLDER = '%e'\n\n\tdef __init__(self, verbose=False):\n\t\t'''\n\t\tClass constructor.\n\t\n\t\t@verbose - Set to True to display the output from any executed external applications.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.config = Config()\n\t\tself.enabled = False\n\t\tself.delayed = False\n\t\tself.verbose = verbose\n\t\tself.extract_rules = {}\n\t\tself.remove_after_execute = False\n\n\tdef add_rule(self, rule):\n\t\t'''\n\t\tAdds a set of rules to the extraction rule list.\n\n\t\t@rule - Rule string, or list of rule strings, in the format <case insensitive matching string>:<file extension>[:<command to run>]\n\n\t\tReturns None.\n\t\t'''\n\t\tr = {\n\t\t\t'extension'\t: '',\n\t\t\t'cmd'\t\t: ''\n\t\t}\n\n\t\tif type(rule) != type([]):\n\t\t\trules = [rule]\n\t\telse:\n\t\t\trules = rule\n\n\t\tfor rule in rules:\n\t\t\tr['cmd'] = ''\n\t\t\tr['extension'] = ''\n\n\t\t\ttry:\n\t\t\t\tvalues = self._parse_rule(rule)\n\t\t\t\tmatch = values[0].lower()\n\t\t\t\tr['extension'] = values[1]\n\t\t\t\tr['cmd'] = values[2]\n\t\t\texcept:\n\t\t\t\tpass\n\n\t\t\t# Verify that the match string and file extension were retrieved.\n\t\t\t# Only add the rule if it is a new one (first come, first served).\n\t\t\tif match and r['extension'] and not self.extract_rules.has_key(match):\n\t\t\t\tself.extract_rules[match] = {}\n\t\t\t\tself.extract_rules[match]['cmd'] = r['cmd']\n\t\t\t\tself.extract_rules[match]['extension'] = r['extension']\n\t\t\t\t# Once any rule is added, set self.enabled to True\n\t\t\t\tself.enabled = True\n\n\tdef enable_delayed_extract(self, tf=None):\n\t\t'''\n\t\tEnables / disables the delayed extraction feature.\n\t\tThis feature ensures that certian supported file types will not contain extra data at the end of the\n\t\tfile when they are extracted, but also means that these files will not be extracted until the end of the scan.\n\n\t\t@tf - Set to True to enable, False to disable. \n\n\t\tReturns the current delayed extraction setting.\n\t\t'''\n\t\tif tf is not None:\n\t\t\tself.delayed = tf\n\t\treturn self.delayed\n\n\tdef load_from_file(self, fname):\n\t\t'''\n\t\tLoads extraction rules from the specified file.\n\n\t\t@fname - Path to the extraction rule file.\n\t\t\n\t\tReturns None.\n\t\t'''\n\t\ttry:\n\t\t\t# Process each line from the extract file, ignoring comments\n\t\t\tfor rule in open(fname).readlines():\n\t\t\t\tself.add_rule(rule.split(self.COMMENT_DELIM, 1)[0])\n\t\texcept Exception, e:\n\t\t\traise Exception(\"Extractor.load_from_file failed to load file '%s': %s\" % (fname, str(e)))\n\n\tdef load_defaults(self):\n\t\t'''\n\t\tLoads default extraction rules from the user and system extract.conf files.\n\n\t\tReturns None.\n\t\t'''\n\t\t# Load the user extract file first to ensure its rules take precedence.\n\t\textract_files = [\n\t\t\tself.config.paths['user'][self.config.EXTRACT_FILE],\n\t\t\tself.config.paths['system'][self.config.EXTRACT_FILE],\n\t\t]\n\n\t\tfor extract_file in extract_files:\n\t\t\ttry:\n\t\t\t\tself.load_from_file(extract_file)\n\t\t\texcept Exception, e:\n\t\t\t\tif self.verbose:\n\t\t\t\t\traise Exception(\"Extractor.load_defaults failed to load file '%s': %s\" % (extract_file, str(e)))\n\n\tdef cleanup_extracted_files(self, tf=None):\n\t\t'''\n\t\tSet the action to take after a file is extracted.\n\n\t\t@tf - If set to True, extracted files will be cleaned up after running a command against them.\n\t\t      If set to False, extracted files will not be cleaned up after running a command against them.\n\t\t      If set to None or not specified, the current setting will not be changed.\n\n\t\tReturns the current cleanup status (True/False).\n\t\t'''\n\t\tif tf is not None:\n\t\t\tself.remove_after_execute = tf\n\n\t\treturn self.remove_after_execute\n\t\n\tdef extract(self, offset, description, file_name, size, name=None):\n\t\t'''\n\t\tExtract an embedded file from the target file, if it matches an extract rule.\n\t\tCalled automatically by Binwalk.scan().\n\n\t\t@offset      - Offset inside the target file to begin the extraction.\n\t\t@description - Description of the embedded file to extract, as returned by libmagic.\n\t\t@file_name   - Path to the target file.\n\t\t@size        - Number of bytes to extract.\n\t\t@name        - Name to save the file as.\n\n\t\tReturns the name of the extracted file (blank string if nothing was extracted).\n\t\t'''\n\t\tcleanup_extracted_fname = True\n\n\t\trule = self._match(description)\n\t\tif rule is not None:\n\t\t\tfname = self._dd(file_name, offset, size, rule['extension'], output_file_name=name)\n\t\t\tif rule['cmd']:\n\n\t\t\t\t# Many extraction utilities will extract the file to a new file, just without\n\t\t\t\t# the file extension (i.e., myfile.7z => myfile). If the presumed resulting\n\t\t\t\t# file name already exists before executing the extract command, do not attempt \n\t\t\t\t# to clean it up even if its resulting file size is 0.\n\t\t\t\tif self.remove_after_execute:\n\t\t\t\t\textracted_fname = os.path.splitext(fname)[0]\n\t\t\t\t\tif os.path.exists(extracted_fname):\n\t\t\t\t\t\tcleanup_extracted_fname = False\n\n\t\t\t\t# Execute the specified command against the extracted file\n\t\t\t\tself._execute(rule['cmd'], fname)\n\n\t\t\t\t# Only clean up files if remove_after_execute was specified\t\t\t\t\n\t\t\t\tif self.remove_after_execute:\n\n\t\t\t\t\t# Remove the original file that we extracted\n\t\t\t\t\ttry:\n\t\t\t\t\t\tos.unlink(fname)\n\t\t\t\t\texcept:\n\t\t\t\t\t\tpass\n\n\t\t\t\t\t# If the command worked, assume it removed the file extension from the extracted file\n\n\t\t\t\t\t# If the extracted file name file exists and is empty, remove it\n\t\t\t\t\tif cleanup_extracted_fname and os.path.exists(extracted_fname) and file_size(extracted_fname) == 0:\n\t\t\t\t\t\ttry:\n\t\t\t\t\t\t\tos.unlink(extracted_fname)\n\t\t\t\t\t\texcept:\n\t\t\t\t\t\t\tpass\n\t\telse:\n\t\t\tfname = ''\n\n\t\treturn fname\n\n\tdef delayed_extract(self, results, file_name, size):\n\t\t'''\n\t\tPerforms a delayed extraction (see self.enable_delayed_extract).\n\t\tCalled internally by Binwalk.Scan().\n\n\t\t@results   - A list of dictionaries of all the scan results.\n\t\t@file_name - The path to the scanned file.\n\t\t@size      - The size of the scanned file.\n\n\t\tReturns an updated results list containing the names of the newly extracted files.\n\t\t'''\n\t\tindex = 0\n\t\tinfo_count = 0\n\t\tnresults = results\n\n\t\tfor (offset, infos) in results:\n\t\t\tinfo_count = 0\n\n\t\t\tfor info in infos:\n\t\t\t\tninfos = infos\n\n\t\t\t\tif info['delay']:\n\t\t\t\t\tend_offset = self._entry_offset(index, results, info['delay'])\n\t\t\t\t\tif end_offset == -1:\n\t\t\t\t\t\textract_size = size\n\t\t\t\t\telse:\n\t\t\t\t\t\textract_size = (end_offset - offset)\n\n\t\t\t\t\tninfos[info_count]['extract'] = self.extract(offset, info['description'], file_name, extract_size, info['name'])\n\t\t\t\t\tnresults[index] = (offset, ninfos)\n\n\t\t\t\tinfo_count += 1\n\n\t\t\tindex += 1\n\t\t\n\t\treturn nresults\n\n\tdef _entry_offset(self, index, entries, description):\n\t\t'''\n\t\tGets the offset of the first entry that matches the description.\n\n\t\t@index       - Index into the entries list to begin searching.\n\t\t@entries     - Dictionary of result entries.\n\t\t@description - Case insensitive description.\n\n\t\tReturns the offset, if a matching description is found.\n\t\tReturns -1 if a matching description is not found.\n\t\t'''\n\t\tdescription = description.lower()\n\n\t\tfor (offset, infos) in entries[index:]:\n\t\t\tfor info in infos:\n\t\t\t\tif info['description'].lower().startswith(description):\n\t\t\t\t\treturn offset\n\t\treturn -1\n\n\tdef _match(self, description):\n\t\t'''\n\t\tCheck to see if the provided description string matches an extract rule.\n\t\tCalled internally by self.extract().\n\n\t\t@description - Description string to check.\n\n\t\tReturns the associated rule dictionary if a match is found.\n\t\tReturns None if no match is found.\n\t\t'''\n\t\tdescription = description.lower()\n\n\t\tfor (m, rule) in self.extract_rules.iteritems():\n\t\t\tif m in description:\n\t\t\t\treturn rule\n\t\treturn None\n\n\tdef _parse_rule(self, rule):\n\t\t'''\n\t\tParses an extraction rule.\n\n\t\t@rule - Rule string.\n\n\t\tReturns an array of ['<case insensitive matching string>', '<file extension>', '<command to run>'].\n\t\t'''\n\t\treturn rule.strip().split(self.RULE_DELIM, 2)\n\n\tdef _dd(self, file_name, offset, size, extension, output_file_name=None):\n\t\t'''\n\t\tExtracts a file embedded inside the target file.\n\n\t\t@file_name        - Path to the target file.\n\t\t@offset           - Offset inside the target file where the embedded file begins.\n\t\t@size             - Number of bytes to extract.\n\t\t@extension        - The file exension to assign to the extracted file on disk.\n\t\t@output_file_name - The requested name of the output file.\n\n\t\tReturns the extracted file name.\n\t\t'''\n\t\t# Default extracted file name is <hex offset>.<extension>\n\t\taltname = \"%X.%s\" % (offset, extension)\n\t\t\n\t\tif not output_file_name or output_file_name is None:\n\t\t\tfname = altname\n\t\telse:\n\t\t\tfname = \"%s.%s\" % (output_file_name, extension)\n\t\n\t\t# Sanitize output file name of invalid/dangerous characters (like file paths)\t\n\t\tfname = os.path.basename(fname)\n\n\t\ttry:\n\t\t\t# Open the target file and seek to the offset\n\t\t\tfdin = open(file_name, \"rb\")\n\t\t\tfdin.seek(offset)\n\t\t\t\n\t\t\t# Open the extracted file\n\t\t\ttry:\n\t\t\t\tfdout = open(fname, \"wb\")\n\t\t\texcept:\n\t\t\t\t# Fall back to the alternate name if the requested name fails\n\t\t\t\tfname = altname\n\t\t\t\tfdout = open(fname, \"wb\")\n\n\t\t\t# Read size bytes from target file and write it to the extracted file\n\t\t\tfdout.write(fdin.read(size))\n\n\t\t\t# Cleanup\n\t\t\tfdout.close()\n\t\t\tfdin.close()\n\t\texcept Exception, e:\n\t\t\traise Exception(\"Extractor.dd failed to extract data from '%s' to '%s': %s\" % (file_name, fname, str(e)))\n\t\t\n\t\treturn fname\n\n\tdef _execute(self, cmd, fname):\n\t\t'''\n\t\tExecute a command against the specified file.\n\n\t\t@cmd   - Command to execute.\n\t\t@fname - File to run command against.\n\n\t\tReturns None.\n\t\t'''\n\t\ttmp = None\n\n\t\t# If not in verbose mode, create a temporary file to redirect stdout and stderr to\n\t\tif not self.verbose:\n\t\t\ttmp = tempfile.TemporaryFile()\n\n\t\ttry:\n\t\t\t# Replace all instances of FILE_NAME_PLACEHOLDER in the command with fname\n\t\t\tcmd = cmd.replace(self.FILE_NAME_PLACEHOLDER, fname)\n\n\t\t\t# Execute.\n\t\t\tsubprocess.call(shlex.split(cmd), stdout=tmp, stderr=tmp)\n\t\texcept Exception, e:\n\t\t\tsys.stderr.write(\"WARNING: Extractor.execute failed to run '%s': %s\\n\" % (cmd, str(e)))\n\t\t\n\t\tif tmp is not None:\n\t\t\ttmp.close()\n\n\t\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/filter.py",
    "content": "import common\nfrom smartsig import SmartSignature\n\nclass MagicFilter:\n\t'''\n\tClass to filter libmagic results based on include/exclude rules and false positive detection.\n\tAn instance of this class is available via the Binwalk.filter object.\n\n\tExample code which creates include, exclude, and grep filters before running a Binwalk scan:\n\n\t\timport binwalk\n\n\t\tbw = binwalk.Binwalk()\n\n\t\t# Include all signatures whose descriptions contain the string 'filesystem' in the first line of the signature, even if those signatures are normally excluded.\n\t\t# Note that if exclusive=False was specified, this would merely add these signatures to the default signatures.\n\t\t# Since exclusive=True (the default) has been specified, ONLY those matching signatures will be loaded; all others will be ignored.\n\t\tbw.filter.include('filesystem')\n\n\t\t# Exclude all signatures whose descriptions contain the string 'jffs2', even if those signatures are normally included.\n\t\t# In this case, we are now searching for all filesystem signatures, except JFFS2.\n\t\tbw.filter.exclude('jffs2')\n\n\t\t# Add a grep filter. Unlike the include and exclude filters, it does not affect which results are returned by Binwalk.scan(), but it does affect which results\n\t\t# are printed by Binwalk.display.results(). This is particularly useful for cases like the bincast scan, where multiple lines of results are returned per offset,\n\t\t# but you only want certian ones displayed. In this case, only file systems whose description contain the string '2012' will be displayed.\n\t\tbw.filter.grep(filters=['2012'])\n\n\t\tbw.scan('firmware.bin')\n\t'''\n\n\t# If the result returned by libmagic is \"data\" or contains the text\n\t# 'invalid' or a backslash are known to be invalid/false positives.\n\tDATA_RESULT = \"data\"\n\tINVALID_RESULTS = [\"invalid\", \"\\\\\"]\n\tINVALID_RESULT = \"invalid\"\n\tNON_PRINTABLE_RESULT = \"\\\\\"\n\n\tFILTER_INCLUDE = 0\n\tFILTER_EXCLUDE = 1\n\n\tdef __init__(self, show_invalid_results=False):\n\t\t'''\n\t\tClass constructor.\n\n\t\t@show_invalid_results - Set to True to display results marked as invalid.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.filters = []\n\t\tself.grep_filters = []\n\t\tself.show_invalid_results = show_invalid_results\n\t\tself.exclusive_filter = False\n\t\tself.smart = SmartSignature(self)\n\n\tdef include(self, match, exclusive=True):\n\t\t'''\n\t\tAdds a new filter which explicitly includes results that contain\n\t\tthe specified matching text.\n\n\t\t@match     - Case insensitive text, or list of texts, to match.\n\t\t@exclusive - If True, then results that do not explicitly contain\n\t\t\t     a FILTER_INCLUDE match will be excluded. If False,\n\t\t\t     signatures that contain the FILTER_INCLUDE match will\n\t\t\t     be included in the scan, but will not cause non-matching\n\t\t\t     results to be excluded.\n\t\t\n\t\tReturns None.\n\t\t'''\n\t\tinclude_filter = {\n\t\t\t\t'type'\t\t: self.FILTER_INCLUDE,\n\t\t\t\t'filter'\t: ''\n\t\t}\n\n\t\tif type(match) != type([]):\n\t\t\tmatches = [match]\n\t\telse:\n\t\t\tmatches = match\n\n\t\tfor m in matches:\n\t\t\tif m:\n\t\t\t\tif exclusive and not self.exclusive_filter:\n\t\t\t\t\tself.exclusive_filter = True\n\n\t\t\t\tinclude_filter['filter'] = m.lower()\n\t\t\t\tself.filters.append(include_filter)\n\n\tdef exclude(self, match):\n\t\t'''\n\t\tAdds a new filter which explicitly excludes results that contain\n\t\tthe specified matching text.\n\n\t\t@match - Case insensitive text, or list of texts, to match.\n\t\t\n\t\tReturns None.\n\t\t'''\n\t\texclude_filter = {\n\t\t\t\t'type'\t\t: self.FILTER_EXCLUDE,\n\t\t\t\t'filter'\t: ''\n\t\t}\n\n\t\tif type(match) != type([]):\n\t\t\tmatches = [match]\n\t\telse:\n\t\t\tmatches = match\n\n\t\tfor m in matches:\n\t\t\tif m:\n\t\t\t\texclude_filter['filter'] = m.lower()\n\t\t\t\tself.filters.append(exclude_filter)\n\n\tdef filter(self, data):\n\t\t'''\n\t\tChecks to see if a given string should be excluded from or included in the results.\n\t\tCalled internally by Binwalk.scan().\n\n\t\t@data - String to check.\n\n\t\tReturns FILTER_INCLUDE if the string should be included.\n\t\tReturns FILTER_EXCLUDE if the string should be excluded.\n\t\t'''\n\t\tdata = data.lower()\n\n\t\t# Loop through the filters to see if any of them are a match. \n\t\t# If so, return the registered type for the matching filter (FILTER_INCLUDE | FILTER_EXCLUDE). \n\t\tfor f in self.filters:\n\t\t\tif f['filter'] in data:\n\t\t\t\treturn f['type']\n\n\t\t# If there was not explicit match and exclusive filtering is enabled, return FILTER_EXCLUDE.\n\t\tif self.exclusive_filter:\n\t\t\treturn self.FILTER_EXCLUDE\n\n\t\treturn self.FILTER_INCLUDE\n\n\tdef invalid(self, data):\n\t\t'''\n\t\tChecks if the given string contains invalid data.\n\t\tCalled internally by Binwalk.scan().\n\n\t\t@data - String to validate.\n\n\t\tReturns True if data is invalid, False if valid.\n\t\t'''\n\t\t# A result of 'data' is never ever valid.\n\t\tif data == self.DATA_RESULT:\n\t\t\treturn True\n\n\t\t# If showing invalid results, just return False.\n\t\tif self.show_invalid_results:\n\t\t\treturn False\n\n\t\t# Don't include quoted strings or keyword arguments in this search, as \n\t\t# strings from the target file may legitimately contain the INVALID_RESULT text.\n\t\tif self.INVALID_RESULT in common.strip_quoted_strings(self.smart._strip_tags(data)):\n\t\t\treturn True\n\n\t\t# There should be no non-printable data in any of the data\n\t\tif self.NON_PRINTABLE_RESULT in data:\n\t\t\treturn True\n\n\t\treturn False\n\n\tdef grep(self, data=None, filters=[]):\n\t\t'''\n\t\tAdd or check case-insensitive grep filters against the supplied data string.\n\n\t\t@data    - Data string to check grep filters against. Not required if filters is specified.\n\t\t@filters - Filter, or list of filters, to add to the grep filters list. Not required if data is specified.\n\n\t\tReturns None if data is not specified.\n\t\tIf data is specified, returns True if the data contains a grep filter, or if no grep filters exist.\n\t\tIf data is specified, returns False if the data does not contain any grep filters.\n\t\t'''\n\t\t# Add any specified filters to self.grep_filters\n\t\tif filters:\n\t\t\tif type(filters) != type([]):\n\t\t\t\tgfilters = [filters]\n\t\t\telse:\n\t\t\t\tgfilters = filters\n\n\t\t\tfor gfilter in gfilters:\n\t\t\t\t# Filters are case insensitive\n\t\t\t\tself.grep_filters.append(gfilter.lower())\n\n\t\t# Check the data against all grep filters until one is found\n\t\tif data is not None:\n\t\t\t# If no grep filters have been created, always return True\n\t\t\tif not self.grep_filters:\n\t\t\t\treturn True\n\n\t\t\t# Filters are case insensitive\n\t\t\tdata = data.lower()\n\n\t\t\t# If a filter exists in data, return True\n\t\t\tfor gfilter in self.grep_filters:\n\t\t\t\tif gfilter in data:\n\t\t\t\t\treturn True\n\n\t\t\t# Else, return False\n\t\t\treturn False\n\t\n\t\treturn None\n\n\tdef clear(self):\n\t\t'''\n\t\tClears all include, exclude and grep filters.\n\t\t\n\t\tRetruns None.\n\t\t'''\n\t\tself.filters = []\n\t\tself.grep_filters = []\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/magic/binarch",
    "content": "# MIPS prologue\n# addiu $sp, -XX\n# 27 BD FF XX\n1\tstring\t\\377\\275\\47\tMIPSEL function prologue\n0       string  \\47\\275\\377\tMIPS function prologue\n\n# MIPS epilogue\n# jr $ra\n0\tbelong\t0x03e00008\tMIPS function epilogue\n0\tlelong\t0x03e00008\tMIPSEL function epilogue\n\n# PowerPC epilogue\n# blr\n0\tbelong 0x4E800020\tPowerPC big endian function epilogue\n0\tlelong 0x4E800020\tPowerPC little endian function epilogue\n\n# ARM prologue\n# STMFD SP!, {XX}\n0\tbeshort\t0xE92D\t\tARMEB function prologue\n2\tleshort\t0xE92D\t\tARM function prologue\n\n# ARM epilogue\n# LDMFD SP!, {XX}\n0\tbeshort\t0xE8BD\t\tARMEB function epilogue\n2\tleshort\t0xE8BD\t\tARM function epilogue\n\n# x86 epilogue\n# push ebp\n# move ebp, esp\n0\tstring\t\\x55\\x89\\xE5\tIntel x86 function epilogue\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/magic/bincast",
    "content": "0\tbelong x\tHex:                 0x%.8X\n#0\tstring x\tString:              %s\n0\tlelong x\tLittle Endian Long:  %d\n0\tbelong x\tBig Endian Long:     %d\n0\tleshort x\tLittle Endian Short: %d\n0\tbeshort x\tBig Endian Short:    %d\n0\tledate x\tLittle Endian Date:  %s\n0\tbedate x\tBig Endian Date:     %s\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/magic/binwalk",
    "content": "# ----------------------------Archive Formats--------------------------------------\n\n# POSIX tar archives\n0\tstring\t\tustar\\000\t\tPOSIX tar archive{offset-adjust:-257}\n0\tstring          ustar\\040\\040\\000\tPOSIX tar archive (GNU){offset-adjust:-257}\n\n# JAR archiver (.j), this is the successor to ARJ, not Java's JAR (which is essentially ZIP)\n0       string  \\x1aJar\\x1b JAR (ARJ Software, Inc.) archive data{offset-adjust:-14}\n0       string  JARCS JAR (ARJ Software, Inc.) archive data\n\n\n# ARJ archiver (jason@jarthur.Claremont.EDU)\n0       leshort         0xea60          ARJ archive data\n>5      byte            x               \\b, v%d,\n>8      byte            &0x04           multi-volume,\n>8      byte            &0x10           slash-switched,\n>8      byte            &0x20           backup,\n>34     string          x               original name: \"%s\",\n>7      byte            0               os: MS-DOS \n>7      byte            1               os: PRIMOS\n>7      byte            2               os: Unix\n>7      byte            3               os: Amiga\n>7      byte            4               os: Macintosh\n>7      byte            5               os: OS/2\n>7      byte            6               os: Apple ][ GS\n>7      byte            7               os: Atari ST\n>7      byte            8               os: NeXT\n>7      byte            9               os: VAX/VMS\n>3      byte            >0              %d]\n\n# RAR archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\tRar!\t\tRAR archive data\n\n# HPACK archiver (Peter Gutmann, pgut1@cs.aukuni.ac.nz)\n0\tstring\t\tHPAK\t\tHPACK archive data\n\n# JAM Archive volume format, by Dmitry.Kohmanyuk@UA.net\n0\tstring\t\t\\351,\\001JAM\tJAM archive\n\n# LHARC/LHA archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\t-lzs-\t\tLHa 2.x? archive data [lzs] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh\\40-\t\tLHa 2.x? archive data [lh ] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lhd-\t\tLHa 2.x? archive data [lhd] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh2-\t\tLHa 2.x? archive data [lh2] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh3-\t\tLHa 2.x? archive data [lh3] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh4-\t\tLHa (2.x) archive data [lh4] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh5-\t\tLHa (2.x) archive data [lh5] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh6-\t\tLHa (2.x) archive data [lh6] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh7-\t\tLHa (2.x) archive data [lh7] [NSRL|LHA2]{offset-adjust:-2}\n\n\n# cpio archives\n#\n# The SVR4 \"cpio(4)\" hints that there are additional formats, but they\n# are defined as \"short\"s; I think all the new formats are\n# character-header formats and thus are strings, not numbers.\n#0       string          070707          ASCII cpio archive (pre-SVR4 or odc)\n\n0       string          070701          ASCII cpio archive (SVR4 with no CRC),\n>110\tbyte\t\t0\t\tinvalid\n>110\tstring\t\tx\t\tfile name: \"%s\"\n>54\tstring\t\tx\t\t{jump-to-offset:0x%.8s+112}\n\n0       string          070702          ASCII cpio archive (SVR4 with CRC)\n>110\tbyte\t\t0\t\tinvalid\n>110\tstring\t\tx\t\tfile name: \"%s\"\n>54\tstring\t\tx\t\t{jump-to-offset:0x%.8s+112}\n\n\n# HP Printer Job Language\n# The header found on Win95 HP plot files is the \"Silliest Thing possible\" \n# (TM)\n# Every driver puts the language at some random position, with random case\n# (LANGUAGE and Language)\n# For example the LaserJet 5L driver puts the \"PJL ENTER LANGUAGE\" in line 10\n# From: Uwe Bonnes <bon@elektron.ikp.physik.th-darmstadt.de>\n# \n0       string          \\033%-12345X@PJL        HP Printer Job Language data\n>&0     string          >\\0                     \"%s\"\n>>&0    string          >\\0                     \"%s\"\n>>>&0   string          >\\0                     \"%s\"\n>>>>&0  string          >\\0                     \"%s\"\n\n#------------------------------------------------------------------------------\n#\n# RPM: file(1) magic for Red Hat Packages   Erik Troan (ewt@redhat.com)\n#\n0\tbelong\t\t0xedabeedb\tRPM\n>4\tbyte\t\tx\t\tv%d\n>6\tbeshort\t\t0\t\tbin\n>6\tbeshort\t\t1\t\tsrc\n>8\tbeshort\t\t1\t\ti386\n>8\tbeshort\t\t2\t\tAlpha\n>8\tbeshort\t\t3\t\tSparc\n>8\tbeshort\t\t4\t\tMIPS\n>8\tbeshort\t\t5\t\tPowerPC\n>8\tbeshort\t\t6\t\t68000\n>8\tbeshort\t\t7\tSGI\n>8\tbeshort\t\t8\t\tRS6000\n>8\tbeshort\t\t9\t\tIA64\n>8\tbeshort\t\t10\t\tSparc64\n>8\tbeshort\t\t11\t\tMIPSel\n>8\tbeshort\t\t12\t\tARM\n>10\tstring\t\tx\t\t\"%s\"\n\n\n#---------------------------Bootloaders--------------------------------\n\n# CFE bootloader\n0\tstring\tCFE1CFE1\tCFE boot loader, little endian\n0\tstring\t1EFC1EFC\tCFE boot loader, big endian\n\n\n#------------------Compression Formats-----------------------------\n\n# AFX compressed files (Wolfram Kleff)\n0\tstring\t\t-afx-\t\tAFX compressed file data{offset-adjust:-2}\n\n# bzip2\n0\tstring BZh91AY&SY\tbzip2 compressed data, block size = 900k\n0\tstring BZh81AY&SY\tbzip2 compressed data, block size = 800k\n0\tstring BZh71AY&SY\tbzip2 compressed data, block size = 700k\n0\tstring BZh61AY&SY\tbzip2 compressed data, block size = 600k\n0\tstring BZh51AY&SY\tbzip2 compressed data, block size = 500k\n0\tstring BZh41AY&SY\tbzip2 compressed data, block size = 400k\n0\tstring BZh31AY&SY\tbzip2 compressed data, block size = 300k\n0\tstring BZh21AY&SY\tbzip2 compressed data, block size = 200k\n0\tstring BZh11AY&SY\tbzip2 compressed data, block size = 100k\n\n# lzop from <markus.oberhumer@jk.uni-linz.ac.at>\n0\tstring\t\t\\x89\\x4c\\x5a\\x4f\\x00\\x0d\\x0a\\x1a\\x0a\tlzop compressed data\n>9\tbeshort\t\t<0x0940\n>>9\tbyte&0xf0\t=0x00\t\t- version 0.\n>>9\tbeshort&0x0fff\tx\t\t\\b%03x,\n>>13\tbyte\t\t1\t\tLZO1X-1,\n>>13\tbyte\t\t2\t\tLZO1X-1(15),\n>>13\tbyte\t\t3\t\tLZO1X-999,\n## >>22\tbedate\t\t>0\t\tlast modified: %s,\n>>14\tbyte\t\t=0x00\t\tos: MS-DOS\n>>14\tbyte\t\t=0x01\t\tos: Amiga\n>>14\tbyte\t\t=0x02\t\tos: VMS\n>>14\tbyte\t\t=0x03\t\tos: Unix\n>>14\tbyte\t\t=0x05\t\tos: Atari\n>>14\tbyte\t\t=0x06\t\tos: OS/2\n>>14\tbyte\t\t=0x07\t\tos: MacOS\n>>14\tbyte\t\t=0x0A\t\tos: Tops/20\n>>14\tbyte\t\t=0x0B\t\tos: WinNT\n>>14\tbyte\t\t=0x0E\t\tos: Win32\n>9\tbeshort\t\t>0x0939\n>>9\tbyte&0xf0\t=0x00\t\t- version 0.\n>>9\tbyte&0xf0\t=0x10\t\t- version 1.\n>>9\tbyte&0xf0\t=0x20\t\t- version 2.\n>>9\tbeshort&0x0fff\tx\t\t\\b%03x,\n>>15\tbyte\t\t1\t\tLZO1X-1,\n>>15\tbyte\t\t2\t\tLZO1X-1(15),\n>>15\tbyte\t\t3\t\tLZO1X-999,\n## >>25\tbedate\t\t>0\t\tlast modified: %s,\n>>17\tbyte\t\t=0x00\t\tos: MS-DOS\n>>17\tbyte\t\t=0x01\t\tos: Amiga\n>>17\tbyte\t\t=0x02\t\tos: VMS\n>>17\tbyte\t\t=0x03\t\tos: Unix\n>>17\tbyte\t\t=0x05\t\tos: Atari\n>>17\tbyte\t\t=0x06\t\tos: OS/2\n>>17\tbyte\t\t=0x07\t\tos: MacOS\n>>17\tbyte\t\t=0x0A\t\tos: Tops/20\n>>17\tbyte\t\t=0x0B\t\tos: WinNT\n>>17\tbyte\t\t=0x0E\t\tos: Win32\n\n# lzip  \n0       string          LZIP            lzip compressed data\n>4      byte            x               \\b, version: %d\n\n# LZO\n0\tstring\t\t\\211LZO\\000\\015\\012\\032\\012\tLZO compressed data\n\n# 7-zip archiver, from Thomas Klausner (wiz@danbala.tuwien.ac.at)\n# http://www.7-zip.org or DOC/7zFormat.txt \n#\n0       string          7z\\274\\257\\047\\034      7-zip archive data,\n>6      byte            x                       version %d\n>7      byte            x                       \\b.%d\n\n# standard unix compress\n0       beshort\t\t0x1f9d          compress'd data\n>2      byte&0x80       >0              block compressed\n>2\tbyte&0x1f\t!16\t\tinvalid\n>2      byte&0x1f       x               %d bits\n\n# http://tukaani.org/xz/xz-file-format.txt\n0\tstring\t\t\\xFD\\x37\\x7a\\x58\\x5a\\x00\txz compressed data\n\n# gzip (GNU zip, not to be confused with Info-ZIP or PKWARE zip archiver)\n#   Edited by Chris Chittleborough <cchittleborough@yahoo.com.au>, March 2002\n#       * Original filename is only at offset 10 if \"extra field\" absent\n#       * Produce shorter output - notably, only report compression methods\n#         other than 8 (\"deflate\", the only method defined in RFC 1952).\n0       string          \\037\\213\\x08    gzip compressed data\n>3      byte            &0x01           \\b, ASCII\n>3      byte            &0x02           \\b, has CRC\n>3      byte            &0x04           \\b, extra field\n>3      byte&0xC        =0x08\n>>10\tstring\t\tx\t\t\\b{file-name:%s}\n>>10    string          x               \\b, was \"%s\"\n>3      byte            &0x10           \\b, has comment\n>9      byte            =0x00           \\b, from FAT filesystem (MS-DOS, OS/2, NT)\n>9      byte            =0x01           \\b, from Amiga\n>9      byte            =0x02           \\b, from VMS\n>9      byte            =0x03           \\b, from Unix\n>9      byte            =0x04           \\b, from VM/CMS\n>9      byte            =0x05           \\b, from Atari\n>9      byte            =0x06           \\b, from HPFS filesystem (OS/2, NT)\n>9      byte            =0x07           \\b, from MacOS\n>9      byte            =0x08           \\b, from Z-System\n>9      byte            =0x09           \\b, from CP/M\n>9      byte            =0x0A           \\b, from TOPS/20\n>9      byte            =0x0B           \\b, from NTFS filesystem (NT)\n>9      byte            =0x0C           \\b, from QDOS\n>9      byte            =0x0D           \\b, from Acorn RISCOS\n>9\tbyte\t\t>0x0D\t\t\\b, invalid source\n>9\tbyte\t\t<0\t\t\\b, invalid source\n>3      byte            &0x20           \\b, encrypted (invalid)\n# Dates before 1992 are invalid, unless of course you're DD-WRT in which\n# case you don't know how to set a date in your gzip files. Brilliant.\n>4\tlelong\t\t=0\t\t\\b, NULL date:\n>4\tlelong\t\t<0\t\t\\b, invalid date:\n>4\tlelong\t\t>0\t\t\n>>4\tlelong\t\t<694224000\t\\b, invalid date:\n>>4\tlelong\t\t=694224000\t\\b, invalid date:\n>>4\tlelong\t\t>694224000\t\\b, last modified:\n>4      ledate          x               %s\n>8      byte            2               \\b, max compression\n>8      byte            4               \\b, max speed\n\n# Zlib signatures\n0\tbeshort\t\t0x789C\t\tzlib compressed data\n0\tbeshort\t\t0x78DA\t\tzlib compressed data\n0\tbeshort\t\t0x7801\t\tzlib compressed data\n\n# Supplementary magic data for the file(1) command to support\n# rzip(1).  The format is described in magic(5).\n#\n# Copyright (C) 2003 by Andrew Tridgell.  You may do whatever you want with\n# this file.\n#\n0       string          RZIP            rzip compressed data\n>4      byte            x               - version %d\n>5      byte            x               \\b.%d\n>6      belong          x               (%d bytes)\n\n# ZIP compression (Greg Roelofs, c/o zip-bugs@wkuvx1.wku.edu)\n0       string          PK\\003\\004      Zip archive data,\n>4      byte            0x00            v0.0\n>4      byte            0x09            at least v0.9 to extract,\n>4      byte            0x0a            at least v1.0 to extract,\n>4      byte            0x0b            at least v1.1 to extract,\n>0x161  string          WINZIP          WinZIP self-extracting,\n>4      byte            0x14\n>>30    ubelong         !0x6d696d65     at least v2.0 to extract,\n>18\tlelong\t\t!0\n>>18\tlelong\t\t<0\t\tinvalid\n>>18\tlelong\t\tx\t\tcompressed size: %d,\n>22\tlelong\t\t!0\n>>22\tlelong\t\t<0\t\tinvalid\n>>22\tlelong\t\tx\t\tuncompressed size: %d,{extract-delay:end of zip archive}\n>30\tstring\t\tx\t\t{file-name:{raw-replace}}name: {raw-replace}\n>26\tleshort\t\tx\t\t{raw-string-length:%d}\n>30\tstring\t\tx\t\t{raw-string:%s\n>61\tstring\t\tx\t\t\\b%s\n>92\tstring\t\tx\t\t\\b%s\n>123\tstring\t\tx\t\t\\b%s\n>154\tstring\t\tx\t\t\\b%s}\n\n# ZIP footer\n0\tstring\t\tPK\\x05\\x06\tEnd of Zip archive\n>20\tleshort\t\tx\t\t{offset-adjust:22+%d}\n>20\tleshort\t\t>0\n>>20\tleshort\t\tx\t\t\\b, comment: {raw-replace}\n>>20\tleshort\t\tx\t\t{raw-string-length:%d}\n>>22\tstring\t\tx\t\t{raw-string:%s}\n\n# New LZMA format signature\n0\tstring\t\t\\xFFLZMA\\x00\tLZMA compressed data (new),\n>6\tbyte&0x10\t0\t\tsingle-block stream\n>6\tbyte&0x10\t0x10\t\tmulti-block stream\n\n# See lzma file for LZMA signatures\n# Type: OpenSSL certificates/key files\n# From: Nicolas Collignon <tsointsoin@gmail.com>\n\n0       string  -----BEGIN\\x20CERTIFICATE-----    PEM certificate\n0       string  -----BEGIN\\x20CERTIFICATE\\x20REQ    PEM certificate request\n0       string  -----BEGIN\\x20RSA\\x20PRIVATE        PEM RSA private key\n0       string  -----BEGIN\\x20DSA\\x20PRIVATE        PEM DSA private key\n\n# Type: OpenSSH key files\n# From: Nicolas Collignon <tsointsoin@gmail.com>\n\n0       string  SSH\\x20PRIVATE\\x20KEY\tOpenSSH RSA1 private key,\n>28     string  >\\0\t\t\tversion \"%s\"\n\n0       string  ssh-dss\\x20               OpenSSH DSA public key\n0       string  ssh-rsa\\x20               OpenSSH RSA public key\n\n# Type: Certificates/key files in DER format\n# From: Gert Hulselmans <hulselmansgert@gmail.com>\n0\tstring\t\\x30\\x82\t\tPrivate key in DER format (PKCS#8),\n>4\tstring\t!\\x02\\x01\\x00\t\tinvalid,\n>>2\tbeshort\tx\t\t\theader length: 4, sequence length: %d\n\n0\tstring  \\x30\\x82\t\tCertificate in DER format (x509 v3),\n>4\tstring\t!\\x30\\x82\t\tinvalid,\n>>2\tbeshort\tx\t\t\theader length: 4, sequence length: %d\n\n# GnuPG\n# The format is very similar to pgp\n0\tstring          \\001gpg                 GPG key trust database\n>4\tbyte            x                       version %d\n0       beshort         0x9901                  GPG key public ring\n# This magic is not particularly good, as the keyrings don't have true\n# magic. Nevertheless, it covers many keyrings.\n\n#------------------------------------------------------------------------------\n# Mavroyanopoulos Nikos <nmav@hellug.gr>\n# mcrypt:   file(1) magic for mcrypt 2.2.x;\n0\tstring\t\t\\0m\\3\t\tmcrypt 2.5 encrypted data,\n>4\tbyte\t\t0\t\tinvalid\n>4\tstring\t\t>\\0\t\talgorithm: \"%s\",\n>>&1\tleshort\t\t<1\t\tinvalid\n>>&1\tleshort\t\t>0\t\tkeysize: %d bytes,\n>>>&0\tbyte\t\t0\t\tinvalid\n>>>&0\tstring\t\t>\\0\t\tmode: \"%s\",\n\n0\tstring\t\t\\0m\\2\t\tmcrypt 2.2 encrypted data,\n>3\tbyte\t\t0\t\talgorithm: blowfish-448,\n>3\tbyte\t\t1\t\talgorithm: DES,\n>3\tbyte\t\t2\t\talgorithm: 3DES,\n>3\tbyte\t\t3\t\talgorithm: 3-WAY,\n>3\tbyte\t\t4\t\talgorithm: GOST,\n>3\tbyte\t\t6\t\talgorithm: SAFER-SK64,\n>3\tbyte\t\t7\t\talgorithm: SAFER-SK128,\n>3\tbyte\t\t8\t\talgorithm: CAST-128,\n>3\tbyte\t\t9\t\talgorithm: xTEA,\n>3\tbyte\t\t10\t\talgorithm: TWOFISH-128,\n>3\tbyte\t\t11\t\talgorithm: RC2,\n>3\tbyte\t\t12\t\talgorithm: TWOFISH-192,\n>3\tbyte\t\t13\t\talgorithm: TWOFISH-256,\n>3\tbyte\t\t14\t\talgorithm: blowfish-128,\n>3\tbyte\t\t15\t\talgorithm: blowfish-192,\n>3\tbyte\t\t16\t\talgorithm: blowfish-256,\n>3\tbyte\t\t100\t\talgorithm: RC6,\n>3\tbyte\t\t101\t\talgorithm: IDEA,\n>3\tbyte\t\t<0\t\tinvalid algorithm\n>3\tbyte\t\t>101\t\tinvalid algorithm,\n>3\tbyte\t\t>16\n>>3\tbyte\t\t<100\t\tinvalid algorithm,\n>4\tbyte\t\t0\t\tmode: CBC,\n>4\tbyte\t\t1\t\tmode: ECB,\n>4\tbyte\t\t2\t\tmode: CFB,\n>4\tbyte\t\t3\t\tmode: OFB,\n>4\tbyte\t\t4\t\tmode: nOFB,\n>4\tbyte\t\t<0\t\tinvalid mode,\n>4\tbyte\t\t>4\t\tinvalid mode,\n>5\tbyte\t\t0\t\tkeymode: 8bit\n>5\tbyte\t\t1\t\tkeymode: 4bit\n>5\tbyte\t\t2\t\tkeymode: SHA-1 hash\n>5\tbyte\t\t3\t\tkeymode: MD5 hash\n>5\tbyte\t\t<0\t\tinvalid keymode\n>5\tbyte\t\t>3\t\tinvalid keymode\n\n#------------------------------------------------------------------------------\n# pgp:  file(1) magic for Pretty Good Privacy\n#\n#0       beshort         0x9900                  PGP key public ring\n#0       beshort         0x9501                  PGP key security ring\n#0       beshort         0x9500                  PGP key security ring\n#0\tbeshort\t\t0xa600\t\t\tPGP encrypted data\n0       string          -----BEGIN\\040PGP       PGP armored data\n>15     string          PUBLIC\\040KEY\\040BLOCK- public key block\n>15     string          MESSAGE-                message\n>15     string          SIGNED\\040MESSAGE-      signed message\n>15     string          PGP\\040SIGNATURE-       signature\n\n\n#------------------Standard file formats------------------------------------\n\n#------------------------------------------------------------------------------\n# elf:  file(1) magic for ELF executables\n#\n# We have to check the byte order flag to see what byte order all the\n# other stuff in the header is in.\n#\n# What're the correct byte orders for the nCUBE and the Fujitsu VPP500?\n#\n# updated by Daniel Quinlan (quinlan@yggdrasil.com)\n0\tstring\t\t\\177ELF\t\tELF\n>4\tbyte\t\t0\t\tinvalid class\n>4\tbyte\t\t1\t\t32-bit\n# only for MIPS - in the future, the ABI field of e_flags should be used.\n>>18\tleshort\t\t8\n>>>36\tlelong\t\t&0x20\t\tN32\n>>18\tleshort\t\t10\n>>>36\tlelong\t\t&0x20\t\tN32\n>>18\tbeshort\t\t8\n>>>36\tbelong\t\t&0x20\t\tN32\n>>18\tbeshort\t\t10\n>>>36\tbelong\t\t&0x20\t\tN32\n>4\tbyte\t\t2\t\t64-bit\n>5\tbyte\t\t0\t\tinvalid byte order\n>5\tbyte\t\t1\t\tLSB\n# The official e_machine number for MIPS is now #8, regardless of endianness.\n# The second number (#10) will be deprecated later. For now, we still\n# say something if #10 is encountered, but only gory details for #8.\n>>18    leshort\t\t8\n# only for 32-bit\n>>>4\tbyte\t\t1\n>>>>36  lelong&0xf0000000\t0x00000000\tMIPS-I\n>>>>36  lelong&0xf0000000\t0x10000000\tMIPS-II\n>>>>36  lelong&0xf0000000\t0x20000000\tMIPS-III\n>>>>36  lelong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>36  lelong&0xf0000000\t0x40000000\tMIPS-V\n>>>>36  lelong&0xf0000000\t0x60000000\tMIPS32\n>>>>36  lelong&0xf0000000\t0x70000000\tMIPS64\n>>>>36  lelong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>36  lelong&0xf0000000\t0x90000000\tMIPS64 rel2\n# only for 64-bit\n>>>4\tbyte\t\t2\n>>>>48  lelong&0xf0000000\t0x00000000\tMIPS-I\n>>>>48  lelong&0xf0000000\t0x10000000\tMIPS-II\n>>>>48  lelong&0xf0000000\t0x20000000\tMIPS-III\n>>>>48  lelong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>48  lelong&0xf0000000\t0x40000000\tMIPS-V\n>>>>48  lelong&0xf0000000\t0x60000000\tMIPS32\n>>>>48  lelong&0xf0000000\t0x70000000\tMIPS64 \n>>>>48  lelong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>48  lelong&0xf0000000\t0x90000000\tMIPS64 rel2\n>>16\tleshort\t\t0\t\tno file type,\n>>16\tleshort\t\t1\t\trelocatable,\n>>16\tleshort\t\t2\t\texecutable,\n>>16\tleshort\t\t3\t\tshared object,\n# Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>\n# corrections by Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>\n>>16\tleshort\t\t4\t\tcore file\n# Core file detection is not reliable.\n#>>>(0x38+0xcc) string\t>\\0\t\tof '%s'\n#>>>(0x38+0x10) lelong\t>0\t\t(signal %d),\n>>16\tleshort\t\t&0xff00\t\tprocessor-specific,\n>>18\tleshort\t\t0\t\tno machine,\n>>18\tleshort\t\t1\t\tAT&T WE32100 - invalid byte order,\n>>18\tleshort\t\t2\t\tSPARC - invalid byte order,\n>>18\tleshort\t\t3\t\tIntel 80386,\n>>18\tleshort\t\t4\t\tMotorola\n>>>36\tlelong\t\t&0x01000000\t68000 - invalid byte order,\n>>>36\tlelong\t\t&0x00810000\tCPU32 - invalid byte order,\n>>>36\tlelong\t\t0\t\t68020 - invalid byte order,\n>>18\tleshort\t\t5\t\tMotorola 88000 - invalid byte order,\n>>18\tleshort\t\t6\t\tIntel 80486,\n>>18\tleshort\t\t7\t\tIntel 80860,\n>>18\tleshort\t\t8\t\tMIPS,\n>>18\tleshort\t\t9\t\tAmdahl - invalid byte order,\n>>18\tleshort\t\t10\t\tMIPS (deprecated),\n>>18\tleshort\t\t11\t\tRS6000 - invalid byte order,\n>>18\tleshort\t\t15\t\tPA-RISC - invalid byte order,\n>>>50\tleshort\t\t0x0214\t\t2.0\n>>>48\tleshort\t\t&0x0008\t\t(LP64),\n>>18\tleshort\t\t16\t\tnCUBE,\n>>18\tleshort\t\t17\t\tFujitsu VPP500,\n>>18\tleshort\t\t18\t\tSPARC32PLUS,\n>>18\tleshort\t\t20\t\tPowerPC,\n>>18\tleshort\t\t22\t\tIBM S/390,\n>>18\tleshort\t\t36\t\tNEC V800,\n>>18\tleshort\t\t37\t\tFujitsu FR20,\n>>18\tleshort\t\t38\t\tTRW RH-32,\n>>18\tleshort\t\t39\t\tMotorola RCE,\n>>18\tleshort\t\t40\t\tARM,\n>>18\tleshort\t\t41\t\tAlpha,\n>>18\tleshort\t\t0xa390\t\tIBM S/390 (obsolete),\n>>18\tleshort\t\t42\t\tHitachi SH,\n>>18\tleshort\t\t43\t\tSPARC V9 - invalid byte order,\n>>18\tleshort\t\t44\t\tSiemens Tricore Embedded Processor,\n>>18\tleshort\t\t45\t\tArgonaut RISC Core, Argonaut Technologies Inc.,\n>>18\tleshort\t\t46\t\tHitachi H8/300,\n>>18\tleshort\t\t47\t\tHitachi H8/300H,\n>>18\tleshort\t\t48\t\tHitachi H8S,\n>>18\tleshort\t\t49\t\tHitachi H8/500,\n>>18\tleshort\t\t50\t\tIA-64 (Intel 64 bit architecture)\n>>18\tleshort\t\t51\t\tStanford MIPS-X,\n>>18\tleshort\t\t52\t\tMotorola Coldfire,\n>>18\tleshort\t\t53\t\tMotorola M68HC12,\n>>18\tleshort\t\t62\t\tAMD x86-64,\n>>18\tleshort\t\t75\t\tDigital VAX,\n>>18\tleshort\t\t97\t\tNatSemi 32k,\n>>18\tleshort\t\t0x9026\t\tAlpha (unofficial),\n>>20\tlelong\t\t0\t\tinvalid version\n>>20\tlelong\t\t1\t\tversion 1\n>>36\tlelong\t\t1\t\tMathCoPro/FPU/MAU Required\n>5\tbyte\t\t2\t\tMSB\n# only for MIPS - see comment in little-endian section above.\n>>18    beshort\t\t8\n# only for 32-bit\n>>>4\tbyte\t\t1\n>>>>36  belong&0xf0000000\t0x00000000\tMIPS-I\n>>>>36  belong&0xf0000000\t0x10000000\tMIPS-II\n>>>>36  belong&0xf0000000\t0x20000000\tMIPS-III\n>>>>36  belong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>36  belong&0xf0000000\t0x40000000\tMIPS-V\n>>>>36  belong&0xf0000000\t0x60000000\tMIPS32\n>>>>36  belong&0xf0000000\t0x70000000\tMIPS64\n>>>>36  belong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>36  belong&0xf0000000\t0x90000000\tMIPS64 rel2\n# only for 64-bit\n>>>4\tbyte\t\t2\n>>>>48\tbelong&0xf0000000\t0x00000000\tMIPS-I\n>>>>48\tbelong&0xf0000000\t0x10000000\tMIPS-II\n>>>>48\tbelong&0xf0000000\t0x20000000\tMIPS-III\n>>>>48\tbelong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>48\tbelong&0xf0000000\t0x40000000\tMIPS-V\n>>>>48\tbelong&0xf0000000\t0x60000000\tMIPS32\n>>>>48\tbelong&0xf0000000\t0x70000000\tMIPS64 \n>>>>48\tbelong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>48\tbelong&0xf0000000\t0x90000000\tMIPS64 rel2\n>>16\tbeshort\t\t0\t\tno file type,\n>>16\tbeshort\t\t1\t\trelocatable,\n>>16\tbeshort\t\t2\t\texecutable,\n>>16\tbeshort\t\t3\t\tshared object,\n>>16\tbeshort\t\t4\t\tcore file,\n#>>>(0x38+0xcc) string\t>\\0\t\tof '%s'\n#>>>(0x38+0x10) belong\t>0\t\t(signal %d),\n>>16\tbeshort\t\t&0xff00\t\tprocessor-specific,\n>>18\tbeshort\t\t0\t\tno machine,\n>>18\tbeshort\t\t1\t\tAT&T WE32100,\n>>18\tbeshort\t\t2\t\tSPARC,\n>>18\tbeshort\t\t3\t\tIntel 80386 - invalid byte order,\n>>18\tbeshort\t\t4\t\tMotorola\n>>>36\tbelong\t\t&0x01000000\t68000,\n>>>36\tbelong\t\t&0x00810000\tCPU32,\n>>>36\tbelong\t\t0\t\t68020,\n>>18\tbeshort\t\t5\t\tMotorola 88000,\n>>18\tbeshort\t\t6\t\tIntel 80486 - invalid byte order,\n>>18\tbeshort\t\t7\t\tIntel 80860,\n>>18\tbeshort\t\t8\t\tMIPS,\n>>18\tbeshort\t\t9\t\tAmdahl,\n>>18\tbeshort\t\t10\t\tMIPS (deprecated),\n>>18\tbeshort\t\t11\t\tRS6000,\n>>18\tbeshort\t\t15\t\tPA-RISC\n>>>50\tbeshort\t\t0x0214\t\t2.0\n>>>48\tbeshort\t\t&0x0008\t\t(LP64)\n>>18\tbeshort\t\t16\t\tnCUBE,\n>>18\tbeshort\t\t17\t\tFujitsu VPP500,\n>>18\tbeshort\t\t18\t\tSPARC32PLUS,\n>>>36\tbelong&0xffff00\t&0x000100\tV8+ Required,\n>>>36\tbelong&0xffff00\t&0x000200\tSun UltraSPARC1 Extensions Required,\n>>>36\tbelong&0xffff00\t&0x000400\tHaL R1 Extensions Required,\n>>>36\tbelong&0xffff00\t&0x000800\tSun UltraSPARC3 Extensions Required,\n>>18\tbeshort\t\t20\t\tPowerPC or cisco 4500,\n>>18\tbeshort\t\t21\t\tcisco 7500,\n>>18\tbeshort\t\t22\t\tIBM S/390,\n>>18\tbeshort\t\t24\t\tcisco SVIP,\n>>18\tbeshort\t\t25\t\tcisco 7200,\n>>18\tbeshort\t\t36\t\tNEC V800 or cisco 12000,\n>>18\tbeshort\t\t37\t\tFujitsu FR20,\n>>18\tbeshort\t\t38\t\tTRW RH-32,\n>>18\tbeshort\t\t39\t\tMotorola RCE,\n>>18\tbeshort\t\t40\t\tARM,\n>>18\tbeshort\t\t41\t\tAlpha,\n>>18\tbeshort\t\t42\t\tHitachi SH,\n>>18\tbeshort\t\t43\t\tSPARC V9,\n>>18\tbeshort\t\t44\t\tSiemens Tricore Embedded Processor,\n>>18\tbeshort\t\t45\t\tArgonaut RISC Core, Argonaut Technologies Inc.,\n>>18\tbeshort\t\t46\t\tHitachi H8/300,\n>>18\tbeshort\t\t47\t\tHitachi H8/300H,\n>>18\tbeshort\t\t48\t\tHitachi H8S,\n>>18\tbeshort\t\t49\t\tHitachi H8/500,\n>>18\tbeshort\t\t50\t\tIntel Merced Processor,\n>>18\tbeshort\t\t51\t\tStanford MIPS-X,\n>>18\tbeshort\t\t52\t\tMotorola Coldfire,\n>>18\tbeshort\t\t53\t\tMotorola M68HC12,\n>>18\tbeshort\t\t73\t\tCray NV1,\n>>18\tbeshort\t\t75\t\tDigital VAX,\n>>18\tbeshort\t\t97\t\tNatSemi 32k,\n>>18\tbeshort\t\t0x9026\t\tAlpha (unofficial),\n>>18\tbeshort\t\t0xa390\t\tIBM S/390 (obsolete),\n>>18    beshort         0xde3d          Ubicom32,\n>>20\tbelong\t\t0\t\tinvalid version\n>>20\tbelong\t\t1\t\tversion 1\n>>36\tbelong\t\t1\t\tMathCoPro/FPU/MAU Required\n# Up to now only 0, 1 and 2 are defined; I've seen a file with 0x83, it seemed\n# like proper ELF, but extracting the string had bad results.\n>4      byte            <0x80\n>>8\tstring\t\t>\\0\t\t(\"%s\")\n>8\tstring\t\t\\0\n>>7\tbyte\t\t0\t\t(SYSV)\n>>7\tbyte\t\t1\t\t(HP-UX)\n>>7\tbyte\t\t2\t\t(NetBSD)\n>>7\tbyte\t\t3\t\t(GNU/Linux)\n>>7\tbyte\t\t4\t\t(GNU/Hurd)\n>>7\tbyte\t\t5\t\t(86Open)\n>>7\tbyte\t\t6\t\t(Solaris)\n>>7\tbyte\t\t7\t\t(Monterey)\n>>7\tbyte\t\t8\t\t(IRIX)\n>>7\tbyte\t\t9\t\t(FreeBSD)\n>>7\tbyte\t\t10\t\t(Tru64)\n>>7\tbyte\t\t11\t\t(Novell Modesto)\n>>7\tbyte\t\t12\t\t(OpenBSD)\n>>7\tbyte\t\t97\t\t(ARM)\n>>7\tbyte\t\t255\t\t(embedded)\n\n# XXX - according to Microsoft's spec, at an offset of 0x3c in a\n# PE-format executable is the offset in the file of the PE header;\n# unfortunately, that's a little-endian offset, and there's no way\n# to specify an indirect offset with a specified byte order.\n# So, for now, we assume the standard MS-DOS stub, which puts the\n# PE header at 0x80 = 128.\n#\n# Required OS version and subsystem version were 4.0 on some NT 3.51\n# executables built with Visual C++ 4.0, so it's not clear that\n# they're interesting.  The user version was 0.0, but there's\n# probably some linker directive to set it.  The linker version was\n# 3.0, except for one \".exe\" which had it as 4.20 (same damn linker!).\n#\n# many of the compressed formats were extraced from IDARC 1.23 source code\n#\n0       string  MZ\tMicrosoft\n>0x18  leshort <0x40 MS-DOS executable\n>0 string MZ\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0PE\\0\\0 \\b, PE for MS Windows\n>>&18   leshort&0x2000  >0      (DLL)\n>>&88   leshort         0       (unknown subsystem)\n>>&88   leshort         1       (native)\n>>&88   leshort         2       (GUI)\n>>&88   leshort         3       (console)\n>>&88   leshort         7       (POSIX)\n>>&0    leshort         0x0     unknown processor\n>>&0    leshort         0x14c   Intel 80386\n>>&0    leshort         0x166   MIPS R4000\n>>&0    leshort         0x184   Alpha\n>>&0    leshort         0x268   Motorola 68000\n>>&0    leshort         0x1f0   PowerPC\n>>&0    leshort         0x290   PA-RISC\n>>&18   leshort&0x0100  >0      32-bit\n>>&18   leshort&0x1000  >0      system file\n>>&228  lelong          >0      \\b, Mono/.Net assembly\n>>&0xf4 search/0x140 \\x0\\x40\\x1\\x0\n>>>(&0.l+(4)) string MSCF \\b, WinHKI CAB self-extracting archive\n>30             string  Copyright\\x201989-1990\\x20PKWARE\\x20Inc.      Self-extracting PKZIP archive\n# Is next line correct? One might expect \"Corp.\" not \"Copr.\" If it is right, add a note to that effect.\n>30             string  PKLITE\\x20Copr.   Self-extracting PKZIP archive\n\n>0x18  leshort >0x3f\n>>(0x3c.l) string PE\\0\\0 PE\n>>>(0x3c.l+25) byte             1 \\b32 executable\n>>>(0x3c.l+25) byte             2 \\b32+ executable\n# hooray, there's a DOS extender using the PE format, with a valid PE\n# executable inside (which just prints a message and exits if run in win)\n>>>(0x3c.l+92)  leshort         <10\n>>>>(8.s*16) string 32STUB for MS-DOS, 32rtm DOS extender\n>>>>(8.s*16) string !32STUB for MS Windows\n>>>>>(0x3c.l+22)        leshort&0x2000  >0      (DLL)\n>>>>>(0x3c.l+92)        leshort         0       (unknown subsystem)\n>>>>>(0x3c.l+92)        leshort         1       (native)\n>>>>>(0x3c.l+92)        leshort         2       (GUI)\n>>>>>(0x3c.l+92)        leshort         3       (console)\n>>>>>(0x3c.l+92)        leshort         7       (POSIX)\n>>>(0x3c.l+92)  leshort         10      (EFI application)\n>>>(0x3c.l+92)  leshort         11      (EFI boot service driver)\n>>>(0x3c.l+92)  leshort         12      (EFI runtime driver)\n>>>(0x3c.l+92)  leshort         13      (XBOX)\n>>>(0x3c.l+4)   leshort         0x0     unknown processor\n>>>(0x3c.l+4)   leshort         0x14c   Intel 80386\n>>>(0x3c.l+4)   leshort         0x166   MIPS R4000\n>>>(0x3c.l+4)   leshort         0x184   Alpha\n>>>(0x3c.l+4)   leshort         0x268   Motorola 68000\n>>>(0x3c.l+4)   leshort         0x1f0   PowerPC\n>>>(0x3c.l+4)   leshort         0x290   PA-RISC\n>>>(0x3c.l+4)   leshort         0x200   Intel Itanium\n>>>(0x3c.l+22)  leshort&0x0100  >0      32-bit\n>>>(0x3c.l+22)  leshort&0x1000  >0      system file\n>>>(0x3c.l+232) lelong  >0      Mono/.Net assembly\n>>>>(0x3c.l+0xf8)       string          UPX0 \\b, UPX compressed\n>>>>(0x3c.l+0xf8)       search/0x140    PEC2 \\b, PECompact2 compressed\n>>>>(0x3c.l+0xf8)       search/0x140    UPX2\n>>>>>(&0x10.l+(-4))     string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>(0x3c.l+0xf8)       search/0x140    .idata\n>>>>>(&0xe.l+(-4))      string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>>(&0xe.l+(-4))      string          ZZ0 \\b, ZZip self-extracting archive\n>>>>>(&0xe.l+(-4))      string          ZZ1 \\b, ZZip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .rsrc\n>>>>>(&0x0f.l+(-4))     string          a\\\\\\4\\5 \\b, WinHKI self-extracting archive\n>>>>>(&0x0f.l+(-4))     string          Rar! \\b, RAR self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/0x3000   MSCF \\b, InstallShield self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/32       Nullsoft \\b, Nullsoft Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .data\n>>>>>(&0x0f.l)          string          WEXTRACT \\b, MS CAB-Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .petite\\0 \\b, Petite compressed\n>>>>>(0x3c.l+0xf7)      byte            x\n>>>>>>(&0x104.l+(-4))   string          =!sfx! \\b, ACE self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .WISE \\b, WISE installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .dz\\0\\0\\0 \\b, Dzip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .reloc\n>>>>>(&0xe.l+(-4))      search/0x180    PK\\3\\4 \\b, ZIP self-extracting archive (WinZip)\n\n>>>>&(0x3c.l+0xf8)      search/0x100    _winzip_ \\b, ZIP self-extracting archive (WinZip)\n>>>>&(0x3c.l+0xf8)      search/0x100    SharedD \\b, Microsoft Installer self-extracting archive\n>>>>0x30                string          Inno \\b, InnoSetup self-extracting archive\n\n>>(0x3c.l) string !PE\\0\\0 MS-DOS executable\n\n>>(0x3c.l)              string          NE \\b, NE\n>>>(0x3c.l+0x36)        byte            0 (unknown OS)\n>>>(0x3c.l+0x36)        byte            1 for OS/2 1.x\n>>>(0x3c.l+0x36)        byte            2 for MS Windows 3.x\n>>>(0x3c.l+0x36)        byte            3 for MS-DOS\n>>>(0x3c.l+0x36)        byte            >3 (unknown OS)\n>>>(0x3c.l+0x36)        byte            0x81 for MS-DOS, Phar Lap DOS extender\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8002 (DLL)\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8001 (driver)\n>>>&(&0x24.s-1)         string          ARJSFX \\b, ARJ self-extracting archive\n>>>(0x3c.l+0x70)        search/0x80     WinZip(R)\\x20Self-Extractor \\b, ZIP self-extracting archive (WinZip)\n\n>>(0x3c.l)              string          LX\\0\\0 \\b, LX\n>>>(0x3c.l+0x0a)        leshort         <1 (unknown OS)\n>>>(0x3c.l+0x0a)        leshort         1 for OS/2\n>>>(0x3c.l+0x0a)        leshort         2 for MS Windows\n>>>(0x3c.l+0x0a)        leshort         3 for DOS\n>>>(0x3c.l+0x0a)        leshort         >3 (unknown OS)\n>>>(0x3c.l+0x10)        lelong&0x28000  =0x8000 (DLL)\n>>>(0x3c.l+0x10)        lelong&0x20000  >0 (device driver)\n>>>(0x3c.l+0x10)        lelong&0x300    0x300 (GUI)\n>>>(0x3c.l+0x10)        lelong&0x28300  <0x300 (console)\n>>>(0x3c.l+0x08)        leshort         1 i80286\n>>>(0x3c.l+0x08)        leshort         2 i80386\n>>>(0x3c.l+0x08)        leshort         3 i80486\n>>>(8.s*16)             string          emx \\b, emx\n>>>>&1                  string          x \"%s\"\n>>>&(&0x54.l-3)         string          arjsfx \\b, ARJ self-extracting archive\n\n\n\n#------------------------------------------------------------------------------\n# bFLT: file(1) magic for BFLT uclinux binary files\n#\n# From Philippe De Muyter <phdm@macqel.be>\n# \n# Additional fields added by Craig Heffner\n#\n0       string          bFLT            BFLT executable \n>4      belong          x               version %ld, \n>4      belong          4\n>8\tbelong\t\tx\t\tcode offset: 0x%.8X, \n>12\tbelong\t\tx\t\tdata segment starts at: 0x%.8X, \n>16\tbelong\t\tx\t\tbss segment starts at: 0x%.8X, \n>20\tbelong\t\tx\t\tbss segment ends at: 0x%.8X, \n>24\tbelong\t\tx\t\tstack size: %d bytes, \n>28\tbelong \t\tx\t\trelocation records start at: 0x%.8X, \n>32\tbelong\t\tx\t\tnumber of reolcation records: %d, \n>>36    belong&0x1      0x1             ram\n>>36    belong&0x2      0x2             gotpic\n>>36    belong&0x4      0x4             gzip\n>>36    belong&0x8      0x8             gzdata\n\n\n#-----------------------------------------------------------------\n# MIPS COFF file formats\n#\n0       beshort 0x0160          MIPSEB ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x0162          MIPSEL-BE ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x6001          MIPSEB-LE ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x6201          MIPSEL ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n# MIPS 2 additions\n#\n0       beshort 0x0163          MIPSEB MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x0166          MIPSEL-BE MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x6301          MIPSEB-LE MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x6601          MIPSEL MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n# MIPS 3 additions\n#\n0       beshort 0x0140          MIPSEB MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x0142          MIPSEL-BE MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x4001          MIPSEB-LE MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x4201          MIPSEL MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x180           MIPSEB Ucode\n0       beshort 0x182           MIPSEL-BE Ucode\n\n\n# Windows CE package files\n0       string          MSCE\\0\\0\\0\\0    Microsoft WinCE installer\n>20     lelong          0               \\b, architecture-independent\n>20     lelong          103             \\b, Hitachi SH3\n>20     lelong          104             \\b, Hitachi SH4\n>20     lelong          0xA11           \\b, StrongARM\n>20     lelong          4000            \\b, MIPS R4000\n>20     lelong          10003           \\b, Hitachi SH3\n>20     lelong          10004           \\b, Hitachi SH3E\n>20     lelong          10005           \\b, Hitachi SH4\n>20     lelong          70001           \\b, ARM 7TDMI\n>52     leshort         1               \\b, 1 file\n>52     leshort         >1              \\b, %u files\n>56     leshort         1               \\b, 1 registry entry\n>56     leshort         >1              \\b, %u registry entries\n\n#------------------------------------------------------------------------------\n# Microsoft Xbox executables .xbe (Esa HyytiÃ¤ <ehyytia@cc.hut.fi>)\n0       string          XBEH            XBE, Microsoft Xbox executable\n# probabilistic checks whether signed or not\n>0x0004 ulelong =0x0\n>>&2    ulelong =0x0\n>>>&2   ulelong =0x0  \\b, not signed\n>0x0004 ulelong >0\n>>&2    ulelong >0\n>>>&2   ulelong >0    \\b, signed\n# expect base address of 0x10000\n>0x0104               ulelong =0x10000\n>>(0x0118-0x0FF60)    ulelong&0x80000007  0x80000007 \\b, all regions\n>>(0x0118-0x0FF60)    ulelong&0x80000007  !0x80000007\n>>>(0x0118-0x0FF60)   ulelong >0           (regions:\n>>>>(0x0118-0x0FF60)  ulelong &0x00000001  NA\n>>>>(0x0118-0x0FF60)  ulelong &0x00000002  Japan\n>>>>(0x0118-0x0FF60)  ulelong &0x00000004  Rest_of_World\n>>>>(0x0118-0x0FF60)  ulelong &0x80000000  Manufacturer\n>>>(0x0118-0x0FF60)   ulelong >0           \\b)\n\n#------------------------------------------------------------------------------\n# motorola:  file(1) magic for Motorola 68K and 88K binaries\n#\n# 68K\n#\n0       beshort         0x0208          mc68k COFF\n>18     beshort         ^00000020       object\n>18     beshort         &00000020       executable\n>12     belong          >0              not stripped\n>168    string          .lowmem         Apple toolbox\n>20     beshort         0407            (impure)\n>20     beshort         0410            (pure)\n>20     beshort         0413            (demand paged)\n>20     beshort         0421            (standalone)\n0       beshort         0x0209          mc68k executable (shared)\n>12     belong          >0              not stripped\n0       beshort         0x020A          mc68k executable (shared demand paged)\n>12     belong          >0              not stripped\n\n\n#\n# Motorola/UniSoft 68K Binary Compatibility Standard (BCS)\n#\n0       beshort         0x022A            68K BCS executable\n#\n# 88K\n#\n# Motorola/88Open BCS\n#\n0       beshort         0x022B            88K BCS executable\n\n#------------------------------------------------------------------------------\n# Sony Playstation executables (Adam Sjoegren <asjo@diku.dk>) :\n0       string  PS-X\\x20EXE       Sony Playstation executable\n#  Area:\n>113    string  x               (\"%s\")\n\n#------------------------------------------------------------------------------\n# cisco:  file(1) magic for cisco Systems routers\n#\n# Most cisco file-formats are covered by the generic elf code\n#\n# Microcode files are non-ELF, 0x8501 conflicts with NetBSD/alpha.\n0\tbeshort\t\t\t0x8501\t    cisco IOS\n>0      belong&0xffffff00       0x85011400  microcode\n>0      belong&0xffffff00       0x8501cb00  experimental microcode\n>7      string          \t>\\0         for \"%s\"\n\n# EST flat binary format (which isn't, but anyway)\n# From: Mark Brown <broonie@sirena.org.uk>\n0\tstring\tESTFBINR\tEST flat binary\n\n# These are not the binaries themselves, but string references to them\n# are a strong indication that they exist elsewhere...\n#0\tstring\t/bin/busybox\tBusybox string reference: \"%s\"{one-of-many}\n#0\tstring /bin/sh\t\tShell string reference: \"%s\"{one-of-many}\n\n#--------------------File Systems---------------------\n\n# Minix filesystems - Juan Cespedes <cespedes@debian.org>\n0x410   leshort         0x137f          Minix filesystem\n>0x402  beshort         !0              \\b, %d zones\n>0x1e   string          minix           \\b, bootable\n0x410   leshort         0x138f          Minix filesystem, 30 char names\n0x410   leshort         0x2468          Minix filesystem, version 2\n0x410   leshort         0x2478          Minix filesystem, version 2, 30 char names\n0x410\tleshort\t\t0x4d5a\t\tMinix filesystem, version 3\n0x410\tleshort\t\t0x4d6a\t\tMinix filesystem, version 3, 30 char names\n\n0x410   beshort         0x137f          Minix filesystem (big endian)\n>0x402  beshort         !0              \\b, %d zones\n>0x1e   string          minix           \\b, bootable\n0x410   beshort         0x138f          Minix filesystem (big endian), 30 char names\n0x410   beshort         0x2468          Minix filesystem (big endian), version 2\n0x410   beshort         0x2478          Minix filesystem (big endian), version 2, 30 char names\n0x410\tbeshort\t\t0x4d5a\t\tMinix filesystem (big endian), version 3\n0x410\tbeshort\t\t0x4d6a\t\tMinix filesystem (big endian), version 3, 30 char names\n\n# YAFFS\n0\tstring\t\\x03\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\xFF\\xFF\tYAFFS filesystem\n\n# EFS2 file system - jojo@utulsa.edu\n0      lelong 0x53000000       EFS2 Qualcomm filesystem super block, little endian,\n>8     string !EFSSuper        invalid,\n>4     leshort &1              NAND\n>4     leshort ^1              NOR\n>4     leshort x               version 0x%x,\n>24    lelong  x               %d blocks,\n>16    lelong  x               0x%x pages per block,\n>20    lelong  x               0x%x bytes per page\n\n0      belong 0x53000000       EFS2 Qualcomm filesystem super block, big endian,\n>8     string !SSFErepu\t       invalid,\n>4     beshort &1              NAND\n>4     beshort ^1              NOR\n>4     beshort x               version 0x%x,\n>24    belong  x               %d blocks,\n>16    belong  x               0x%x pages per block,\n>20    belong  x               0x%x bytes per page\n\n# TROC file system\n0\tstring\tTROC\t\tTROC filesystem,\n>4\tlelong\tx\t\t%d file entries\n\n# PFS file system\n0\tstring\tPFS/\t\tPFS filesystem,\n>4\tstring\tx\t\tversion \"%s\",\n>14\tleshort\tx\t\t%d files\n\n# MPFS file system\n0\tstring\tMPFS\t\tMPFS (Microchip) filesystem,\n>4\tbyte\tx\t\tversion %d.\n>5\tbyte\tx\t\t\\b%d,\n>6\tleshort\tx\t\t%d file entries\n\n# cramfs filesystem - russell@coker.com.au\n0       lelong  0x28cd3d45      CramFS filesystem, little endian\n>4\tlelong\t<0\t\tinvalid\n>4      lelong  x \t\tsize %lu\n>8      lelong  &1 \t\tversion #2\n>8      lelong  &2 \t\tsorted_dirs\n>8      lelong  &4 \t\thole_support\n>32     lelong  x \t\tCRC 0x%x,\n>36     lelong  x \t\tedition %lu,\n>40\tlelong\t<0\t\tinvalid\n>40     lelong  x \t\t%lu blocks,\n>44\tlelong\t<0\t\tinvalid\n>44     lelong  x \t\t%lu files\n>4      lelong  x \t\t{jump-to-offset:%lu}\n>4      lelong  x \t\t{file-size:%lu}\n\n0       belong  0x28cd3d45      CramFS filesystem, big endian\n>4\tbelong\t<0\t\tinvalid\n>4      belong  x \t\tsize %lu\n>8      belong  &1 \t\tversion #2\n>8      belong  &2 \t\tsorted_dirs\n>8      belong  &4 \t\thole_support\n>32     belong  x \t\tCRC 0x%x,\n>36     belong  x \t\tedition %lu,\n>40\tbelong\t<0\t\tinvalid\n>40     belong  x \t\t%lu blocks,\n>44\tbelong\t<0\t\tinvalid\n>44     belong  x \t\t%lu files\n>4      belong  x \t\t{jump-to-offset:%lu}\n>4      belong  x \t\t{file-size:%lu}\n\n\n\n# JFFS2 file system\n# If used with binwalk's smart signature feature (on by default, -S to disable)\n# this signature can potentially lead to missing some JFFS2 file systems if there\n# are multiple JFFS2 file systems in a target file and there are no other identified\n# files in between the JFFS2 file systems. This is an unlikely scenario however, and\n# the below signatures are much improved in terms of readability and accuracy in the\n# vast majority of real world scenarios.\n0\t\tleshort 0x1985\tJFFS2 filesystem, little endian{filter-include}\n>2\t\tleshort !0xE001\n>>2\t\tleshort !0xE002\n>>>2\t\tleshort !0x2003\n>>>>2\t\tleshort !0x2004\n>>>>>2\t\tleshort !0x2006\n>>>>>>2\t\tleshort !0xE008\n>>>>>>>2\tleshort !0xE009\t\\b, invalid\n>(4.l)\t\tleshort !0x1985\t\t\n>>(4.l+1)\tleshort !0x1985\t\n>>>(4.l+2)\tleshort !0x1985\t\n>>>>(4.l+3)\tleshort !0x1985\n>>>>>(4.l)      leshort !0xFFFF\n>>>>>>(4.l+1)   leshort !0xFFFF\n>>>>>>>(4.l+2)  leshort !0xFFFF\n>>>>>>>>(4.l+3) leshort !0xFFFF \\b, invalid\n>4\t\tlelong\tx\t{one-of-many}{jump-to-offset:%d}\n\n0       \tbeshort 0x1985\tJFFS2 filesystem, big endian{filter-include}\n>2\t\tbeshort !0xE001\n>>2\t\tbeshort !0xE002\n>>>2\t\tbeshort !0x2003\n>>>>2\t\tbeshort !0x2004\n>>>>>2\t\tbeshort !0x2006\n>>>>>>2\t\tbeshort !0xE008\n>>>>>>>2\tbeshort !0xE009\t\\b, invalid\n>(4.L)\t\tbeshort\t!0x1985\t \n>>(4.L+1)\tbeshort\t!0x1985\t \n>>>(4.L+2)\tbeshort\t!0x1985\n>>>>(4.L+3)\tbeshort\t!0x1985\t\n>>>>>(4.L)\tbeshort !0xFFFF\n>>>>>>(4.L+1)\tbeshort !0xFFFF\n>>>>>>>(4.L+2)\tbeshort !0xFFFF\n>>>>>>>>(4.L+3)\tbeshort !0xFFFF \\b, invalid\n>4\t\tbelong\tx\t{one-of-many}{jump-to-offset:%d}\n\n\n# Squashfs, big endian\n0       string  sqsh    Squashfs filesystem, big endian,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28\tbeshort <3\n>>8\tbelong\tx\t{jump-to-offset:%d}\n>28\tbeshort\t3\t\n>>63\tbequad\tx\t{jump-to-offset:%lld}\n>28\tbeshort\t>3\n>>40\tbequad\tx\t{jump-to-offset:%lld}\n\n# Squashfs, little endian\n0       string  hsqs    Squashfs filesystem, little endian,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>30\tleshort >10\tinvalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28\tleshort >3\tcompression: \n>>20\tleshort 1\t\\bgzip,\n>>20\tleshort\t2\t\\blzma,\n>>20\tleshort 0\t\\binvalid,\n>>20\tleshort >4\t\\binvalid,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>>8     lelong  x       {file-size:%d}\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>>63    lequad x        {file-size:%lld}\n>28\tleshort >3\t\n>>40\tlequad\tx\tsize: %lld bytes,\n>>40\tlequad\tx\t{file-size:%lld}\n>4      lelong  x       %d inodes,\n>28\tleshort >3\n>>12\tlelong\t\tblocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28\tleshort 3\n>>51\tlelong \tx\tblocksize: %d bytes,\n>28\tleshort\t>3\t\n>>12\tlelong\tx\tblocksize: %d bytes,\n>28\tleshort <4\n>>39    ledate  x\tcreated: %s\n>28\tleshort >3\n>>8\tledate x\tcreated: %s\n>28     leshort <3\n>>8     lelong  x       {jump-to-offset:%d}\n>28     leshort 3\n>>63    lequad x        {jump-to-offset:%lld}\n>28     leshort >3\n>>40    lequad  x       {jump-to-offset:%lld}\n\n# Squashfs with LZMA compression\n0       string  sqlz    Squashfs filesystem, big endian, lzma compression, \n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>>8     belong  x       {file-size:%d}\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>>63    bequad x        {file-size:%lld}\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>>40    bequad  x       {file-size:%lld}\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28     beshort <3\n>>8     belong  x       {jump-to-offset:%d}\n>28     beshort 3\n>>63    bequad  x       {jump-to-offset:%lld}\n>28     beshort >3\n>>40    bequad  x       {jump-to-offset:%lld}\n\n# Squashfs 3.3 LZMA signature\n0       string  qshs    Squashfs filesystem, big endian, lzma signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>>8     belong  x       {file-size:%d}\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>>63    bequad x        {file-size:%lld}\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>>40    bequad  x       {file-size:%lld}\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28     beshort <3\n>>8     belong  x       {jump-to-offset:%d}\n>28     beshort 3\n>>63    bequad  x       {jump-to-offset:%lld}\n>28     beshort >3\n>>40    bequad  x       {jump-to-offset:%lld}\n\n# Squashfs for DD-WRT\n0       string  tqsh    Squashfs filesystem, big endian, DD-WRT signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>>8     belong  x       {file-size:%d}\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>>63    bequad x        {file-size:%lld}\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>>40    bequad  x       {file-size:%lld}\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28     beshort <3\n>>8     belong  x       {jump-to-offset:%d}\n>28     beshort 3\n>>63    bequad  x       {jump-to-offset:%lld}\n>28     beshort >3\n>>40    bequad  x       {jump-to-offset:%lld}\n\n# Squashfs for DD-WRT\n0       string  hsqt    Squashfs filesystem, little endian, DD-WRT signature,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>30\tleshort >10\tinvalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort >3      compression:\n>>20    leshort 1       \\bgzip,\n>>20    leshort 2       \\blzma,\n>>20    leshort 0       \\binvalid,\n>>20    leshort >4      \\binvalid,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>>8     lelong  x       {file-size:%d}\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>>63    lequad x        {file-size:%lld}\n>28     leshort >3\n>>40    lequad  x       size: %lld bytes,\n>>40    lequad  x       {file-size:%lld}\n>4      lelong  x       %d inodes,\n>28     leshort >3\n>>12    lelong          blocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort 3\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort >3\n>>12    lelong  x       blocksize: %d bytes,\n>28     leshort <4\n>>39    ledate  x       created: %s\n>28     leshort >3\n>>8     ledate x        created: %s\n>28     leshort <3\n>>8     lelong  x       {jump-to-offset:%d}\n>28     leshort 3\n>>63    lequad x        {jump-to-offset:%lld}\n>28     leshort >3\n>>40    lequad  x       {jump-to-offset:%lld}\n\n# Non-standard Squashfs signature found on some D-Link routers\n0       string  shsq    Squashfs filesystem, little endian, non-standard signature, \n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>30\tleshort >10\tinvalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort >3      compression:\n>>20    leshort 1       \\bgzip,\n>>20    leshort 2       \\blzma,\n>>20    leshort 0       \\binvalid,\n>>20    leshort >4      \\binvalid,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>>8     lelong  x       {file-size:%d}\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>>63    lequad x        {file-size:%lld}\n>28     leshort >3\n>>40    lequad  x       size: %lld bytes,\n>>40    lequad  x       {file-size:%lld}\n>4      lelong  x       %d inodes,\n>28     leshort >3\n>>12    lelong          blocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort 3\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort >3\n>>12    lelong  x       blocksize: %d bytes,\n>28     leshort <4\n>>39    ledate  x       created: %s\n>28     leshort >3\n>>8     ledate x        created: %s\n>28     leshort <3\n>>8     lelong  x       {jump-to-offset:%d}\n>28     leshort 3\n>>63    lequad x        {jump-to-offset:%lld}\n>28     leshort >3\n>>40    lequad  x       {jump-to-offset:%lld}\n\n# ext2/ext3 filesystems - Andreas Dilger <adilger@dilger.ca>\n# ext4 filesystem - Eric Sandeen <sandeen@sandeen.net>\n# volume label and UUID Russell Coker\n# http://etbe.coker.com.au/2008/07/08/label-vs-uuid-vs-device/\n0   leshort         0xEF53      \tLinux EXT filesystem,{filter-include}{offset-adjust:-0x438}\n>2\tleshort\t\t>4\t\tinvalid state\n>2\tleshort\t\t3\t\tinvalid state\n>2\tleshort\t\t<0\t\tinvalid state\n>4\tleshort\t\t>3\t\tinvalid error behavior\n>4\tleshort\t\t<0\t\tinvalid error behavior\n>4\tlelong\t\t>1\t\tinvalid major revision\n>4  lelong\t\t<0\t\tinvalid major revision\n>4  lelong          x               rev %d\n>6  leshort         x               \\b.%d\n# No journal?  ext2\n>36  lelong          ^0x0000004      ext2 filesystem data\n>>2 leshort         ^0x0000001      (mounted or unclean)\n# Has a journal?  ext3 or ext4\n>36  lelong          &0x0000004\n#  and small INCOMPAT?\n>>40 lelong          <0x0000040\n#   and small RO_COMPAT?\n>>>44 lelong         <0x0000008      ext3 filesystem data\n#   else large RO_COMPAT?\n>>>44 lelong         >0x0000007      ext4 filesystem data\n#  else large INCOMPAT?\n>>40 lelong          >0x000003f      ext4 filesystem data\n>48  belong          x               \\b, UUID=%08x\n>52  beshort         x               \\b-%04x\n>54  beshort         x               \\b-%04x\n>56  beshort         x               \\b-%04x\n>58  belong          x               \\b-%08x\n>60  beshort         x               \\b%04x\n>64  string          >0              \\b, volume name \"%s\"\n\n\n#romfs filesystems - Juan Cespedes <cespedes@debian.org>\n0       string\t-rom1fs-\\0\t\tromfs filesystem, version 1\n>8\tbelong\t>10000000\t\tinvalid\n>8      belong  x                       size: %d bytes,\n>16\tstring\tx\t\t\t{file-name:%s}\n>16     string  x                       named \"%s\"\n>8\tbelong\tx\t\t\t{file-size:%d}\n>8\tbelong\tx\t\t\t{jump-to-offset:%d}\n\n# Wind River MemFS file system, found in some VxWorks devices\n0\tstring\towowowowowowowowowowowowowowow\t\tWind River management filesystem,\n>30\tstring\t!ow\t\t\t\t\tinvalid,\n>32\tbelong\t1\t\t\t\t\tcompressed,\n>32\tbelong\t2\t\t\t\t\tplain text,\n>36\tbelong\tx\t\t\t\t\t%d files\n\n\n# netboot image - Juan Cespedes <cespedes@debian.org>\n0\tlelong\t\t\t0x1b031336L\tNetboot image,\n>4\tlelong&0xFFFFFF00\t0\n>>4\tlelong&0x100\t\t0x000\t\tmode 2\n>>4\tlelong&0x100\t\t0x100\t\tmode 3\n>4\tlelong&0xFFFFFF00\t!0\t\tunknown mode (invalid)\n\n#--------------------------Firmware Formats---------------------------\n\n# uImage file     \n# From: Craig Heffner, U-Boot image.h header definitions file\n0\tbelong\t0x27051956\tuImage header, header size: 64 bytes,\n>4\tbelong\tx\t\theader CRC: 0x%X,\n>8\tbedate\tx\t\tcreated: %s,\n>12\tbelong\tx\t\timage size: %d bytes,\n>16\tbelong\tx\t\tData Address: 0x%X,\n>20\tbelong\tx\t\tEntry Point: 0x%X,\n>24\tbelong\tx\t\tdata CRC: 0x%X,\n#>28\tbyte\tx\t\tOS type: %d,\n>28\tbyte\t0\t\tOS: invalid OS,\n>28\tbyte\t1\t\tOS: OpenBSD,\n>28\tbyte\t2\t\tOS: NetBSD,\n>28\tbyte\t3\t\tOS: FreeBSD,\n>28\tbyte\t4\t\tOS: 4.4BSD,\n>28\tbyte\t5\t\tOS: Linux,\n>28\tbyte\t6\t\tOS: SVR4,\n>28\tbyte\t7\t\tOS: Esix,\n>28\tbyte\t8\t\tOS: Solaris,\n>28\tbyte\t9\t\tOS: Irix,\n>28\tbyte\t10\t\tOS: SCO,\n>28\tbyte\t11\t\tOS: Dell,\n>28\tbyte\t12\t\tOS: NCR,\n>28\tbyte\t13\t\tOS: LynxOS,\n>28\tbyte\t14\t\tOS: VxWorks,\n>28\tbyte\t15\t\tOS: pSOS,\n>28\tbyte\t16\t\tOS: QNX,\n>28\tbyte\t17\t\tOS: Firmware,\n>28\tbyte\t18\t\tOS: RTEMS,\n>28\tbyte\t19\t\tOS: ARTOS,\n>28\tbyte\t20\t\tOS: Unity OS,\n#>29\tbyte\tx\t\tCPU arch: %d,\n>29\tbyte\t0\t\tCPU: invalid OS,\n>29\tbyte\t1\t\tCPU: Alpha,\n>29\tbyte\t2\t\tCPU: ARM,\n>29\tbyte\t3\t\tCPU: Intel x86,\n>29\tbyte\t4\t\tCPU: IA64,\n>29\tbyte\t5\t\tCPU: MIPS,\n>29\tbyte\t6\t\tCPU: MIPS 64 bit,\n>29\tbyte\t7\t\tCPU: PowerPC,\n>29\tbyte\t8\t\tCPU: IBM S390,\n>29\tbyte\t9\t\tCPU: SuperH,\n>29\tbyte\t10\t\tCPU: Sparc,\n>29\tbyte\t11\t\tCPU: Sparc 64 bit,\n>29\tbyte\t12\t\tCPU: M68K,\n>29\tbyte\t13\t\tCPU: Nios-32,\n>29\tbyte\t14\t\tCPU: MicroBlaze,\n>29\tbyte\t15\t\tCPU: Nios-II,\n>29\tbyte\t16\t\tCPU: Blackfin,\n>29\tbyte\t17\t\tCPU: AVR,\n>29\tbyte\t18\t\tCPU: STMicroelectronics ST200,\n#>30\tbyte\tx\t\timage type: %d,\n>30\tbyte\t0\t\timage type: invalid Image,\n>30\tbyte\t1\t\timage type: Standalone Program,\n>30\tbyte\t2\t\timage type: OS Kernel Image,\n>30\tbyte \t3\t\timage type: RAMDisk Image,\n>30\tbyte\t4\t\timage type: Multi-File Image,\n>30\tbyte\t5\t\timage type: Firmware Image,\n>30\tbyte\t6\t\timage type: Script file,\n>30\tbyte\t7\t\timage type: Filesystem Image,\n>30\tbyte\t8\t\timage type: Binary Flat Device Tree Blob\n#>31\tbyte\tx\t\tcompression type: %d,\n>31\tbyte\t0\t\tcompression type: none,\n>31\tbyte\t1\t\tcompression type: gzip,\n>31\tbyte\t2\t\tcompression type: bzip2,\n>31\tbyte\t3\t\tcompression type: lzma,\n>32\tstring\tx\t\timage name: \"%s\"\n\n#IMG0 header, found in VxWorks-based Mercury router firmware\n0\tstring\t\tIMG0\t\tIMG0 (VxWorks) header,\n>4\tbelong\t\tx\t\tsize: %d\n\n#Mediatek bootloader signature\n#From xp-dev.com\n0\tstring\t\tBOOTLOADER!\tMediatek bootloader\n\n#CSYS header formats\n0\tstring\t\tCSYS\\x00\tCSYS header, little endian, \n>8\tlelong\t\tx\t\tsize: %d\n\n0\tstring\t\tCSYS\\x80\tCSYS header, big endian,\n>8\tbelong\t\tx\t\tsize: %d\n\n# wrgg firmware image\n0\tstring\t\twrgg02\t\tWRGG firmware header,\n>6\tstring\t\tx\t\tname: \"%s\",\n>48\tstring\t\tx\t\troot device: \"%s\"\n\n# trx image file\n0\tstring          HDR0            TRX firmware header, little endian, header size: 28 bytes, \n>4\tlelong\t\tx\t\timage size: %d bytes,\n>8\tlelong\t\tx\t\tCRC32: 0x%X\n>12\tlelong\t\tx\t\tflags/version: 0x%X\n\n0\tstring          0RDH            TRX firmware header, big endian, header size: 28 bytes,\n>4\tbelong\t\tx\t\timage size: %d bytes,\n>8\tbelong\t\tx\t\tCRC32: 0x%X\n>12\tbelong\t\tx\t\tflags/version: 0x%X\n\n\n# Ubicom firmware image\n0\tbelong\t0xFA320080\t\tUbicom firmware header,\n>12\tbelong\tx\t\t\tchecksum: 0x%X,\n>24\tbelong\tx\t\t\timage size: %d\n\n# The ROME bootloader is used by several RealTek-based products.\n# Unfortunately, the magic bytes are specific to each product, so\n# separate signatures must be created for each one.\n\n# Netgear KWGR614 ROME image\n0\tstring\t\tG614\t\tRealtek firmware header (ROME bootloader),\n>4\tbeshort\t\t0xd92f\t\timage type: KFS,\n>4\tbeshort\t\t0xb162\t\timage type: RDIR,\n>4\tbeshort\t\t0xea43\t\timage type: BOOT,\n>4\tbeshort\t\t0x8dc9\t\timage type: RUN,\n>4\tbeshort\t\t0x2a05\t\timage type: CCFG,\n>4\tbeshort\t\t0x6ce8\t\timage type: DCFG,\n>4\tbeshort\t\t0xc371\t\timage type: LOG,\n>6\tbyte\t\tx\t\theader version: %d,\n#month\n>10\tbyte\t\tx\t\tcreated: %d/\n#day\t\n>12\tbyte \t\tx\t\t\\b%d/\n#year\n>8\tbeshort\t\tx\t\t\\b%d,\n>16\tbelong\t\tx\t\timage size: %d bytes,\n>22\tbyte\t\tx\t\tbody checksum: 0x%X,\n>23\tbyte\t\tx\t\theader checksum: 0x%X\n\n# Linksys WRT54GX ROME image\n0\tbelong\t\t0x59a0e842\tRealtek firmware header (ROME bootloader)\n>4      beshort         0xd92f          image type: KFS,\n>4      beshort         0xb162          image type: RDIR,\n>4      beshort         0xea43          image type: BOOT,\n>4      beshort         0x8dc9          image type: RUN,\n>4      beshort         0x2a05          image type: CCFG,\n>4      beshort         0x6ce8          image type: DCFG,\n>4      beshort         0xc371          image type: LOG,\n>6      byte            x               header version: %d,\n#month\n>10     byte            x               created: %d/\n#day    \n>12     byte            x               \\b%d/\n#year\n>8      beshort         x               \\b%d,\n>16     belong          x               image size: %d bytes,\n>22     byte            x               body checksum: 0x%X,\n>23     byte            x               header checksum: 0x%X\n\n# PackImg tag, somtimes used as a delimiter between the kernel and rootfs in firmware images.\n0\tstring\t\t--PaCkImGs--\tPackImg section delimiter tag,\n>16\tlelong\t\tx\t\tlittle endian size: %d bytes;\n>16\tbelong\t\tx\t\tbig endian size: %d bytes\n\n\n#------------------------------------------------------------------------------\n# Broadcom header format\n#\n0       string          BCRM            Broadcom header,\n>4      lelong          x               number of sections: %d,\n>>8     lelong          18              first section type: flash\n>>8     lelong          19              first section type: disk\n>>8     lelong          21              first section type: tag\n\n\n# Berkeley Lab Checkpoint Restart (BLCR) checkpoint context files\n# http://ftg.lbl.gov/checkpoint\n0       string  Ck0\\0\\0R\\0\\0\\0  BLCR\n>16     lelong  1       x86\n>16     lelong  3       alpha\n>16     lelong  5       x86-64\n>16     lelong  7       ARM\n>8      lelong  x       context data (little endian, version %d)\n\n0       string  \\0\\0\\0C\\0\\0\\0R  BLCR\n>16     belong  2       SPARC\n>16     belong  4       ppc\n>16     belong  6       ppc64\n>16     belong  7       ARMEB\n>16     belong  8       SPARC64\n>8      belong  x       context data (big endian, version %d)\n\n# Aculab VoIP firmware\n# From: Mark Brown <broonie@sirena.org.uk>\n0       string  VoIP\\x20Startup\\x20and      Aculab VoIP firmware\n>35     string  x       format \"%s\"\n\n#------------------------------------------------------------------------------\n# HP LaserJet 1000 series downloadable firmware file\n0       string  \\xbe\\xefABCDEFGH        HP LaserJet 1000 series downloadable firmware\n\n# From Albert Cahalan <acahalan@gmail.com>\n# really le32 operation,destination,payloadsize (but quite predictable)\n# 01 00 00 00 00 00 00 c0 00 02 00 00\n0       string          \\1\\0\\0\\0\\0\\0\\0\\300\\0\\2\\0\\0      Marvell Libertas firmware\n\n#---------------------------------------------------------------------------\n# The following entries have been tested by Duncan Laurie <duncan@sun.com> (a\n# lead Sun/Cobalt developer) who agrees that they are good and worthy of\n# inclusion.\n\n# Boot ROM images for Sun/Cobalt Linux server appliances\n0       string  Cobalt\\x20Networks\\x20Inc.\\nFirmware\\x20v     Paged COBALT boot rom\n>38     string x        V%.4s\n\n# New format for Sun/Cobalt boot ROMs is annoying, it stores the version code\n# at the very end where file(1) can't get it.\n0       string CRfs     COBALT boot rom data (Flat boot rom or file system)\n\n#\n# Motorola S-Records, from Gerd Truschinski <gt@freebsd.first.gmd.de>\n0   string      S0          Motorola S-Record; binary data in text format\n\n# --------------------------------\n# Microsoft Xbox data file formats\n0       string          XIP0            XIP, Microsoft Xbox data\n0       string          XTF0            XTF, Microsoft Xbox data\n\n#Windows CE\n0\tstring\t\tCECE\t\tWindows CE RTOS{offset-adjust:-64}\n\n# --------------------------------\n# ZynOS ROM header format\n# From openwrt zynos.h.\n0\tstring\t\tSIG\t\tZynOS header, header size: 48 bytes,{offset-adjust:-6}\n#>0\tbelong\t\tx\t\tload address 0x%X,\n>3\tbyte\t\t<0x7F\t\trom image type:\n>>3\tbyte\t\t<1\t\tinvalid,\n>>3\tbyte\t\t>7\t\tinvalid,\n>>3\tbyte\t\t1\t\tROMIMG,\n>>3\tbyte\t\t2\t\tROMBOOT,\n>>3\tbyte\t\t3\t\tBOOTEXT,\n>>3\tbyte\t\t4\t\tROMBIN,\n>>3\tbyte\t\t5\t\tROMDIR,\n>>3\tbyte\t\t6\t\t6,\n>>3\tbyte\t\t7\t\tROMMAP,\n>3\tbyte\t\t>0x7F\t\tram image type:\n>>3\tbyte\t\t>0x82\t\tinvalid,\n>>3\tbyte\t\t0x80\t\tRAM,\n>>3\tbyte\t\t0x81\t\tRAMCODE,\n>>3\tbyte\t\t0x82\t\tRAMBOOT,\n>4\tbelong\t\t>0x40000000\tinvalid\n>4\tbelong\t\t<0\t\tinvalid\n>4\tbelong\t\t0\t\tinvalid\n>4\tbelong\t\tx\t\tuncompressed size: %d,\n>8\tbelong\t\t>0x40000000\tinvalid\n>8\tbelong\t\t<0\t\tinvalid\n>8\tbelong\t\t0  \t\tinvalid\n>8\tbelong\t\tx\t\tcompressed size: %d,\n>14\tbeshort\t\tx\t\tuncompressed checksum: 0x%X,\n>16\tbeshort\t\tx\t\tcompressed checksum: 0x%X,\n>12\tbyte\t\tx\t\tflags: 0x%X,\n>12\tbyte\t\t&0x40\t\tuncompressed checksum is valid,\n>12\tbyte\t\t&0x80\t\tthe binary is compressed,\n>>12\tbyte\t\t&0x20\t\tcompressed checksum is valid,\n>35\tbelong\t\tx\t\tmemory map table address: 0x%X\n\n# Firmware header used by some VxWorks-based Cisco products\n0\tstring\t\tCI032.00\tCisco VxWorks firmware header,\n>8\tlelong\t\t>1024\t\tinvalid\n>8\tlelong\t\t<0\t\tinvalid\n>8\tlelong\t\tx\t\theader size: %d bytes,\n>32\tlelong\t\t>1024\t\tinvalid\n>32\tlelong\t\t<0\t\tinvalid\n>32\tlelong\t\tx\t\tnumber of files: %d,\n>48\tlelong\t\t<0\t\tinvalid\n>48\tlelong\t\tx\t\timage size: %d,\n>64\tstring\t\tx\t\tfirmware version: \"%s\"\n\n# Firmware header used by some TV's\n0\tstring\t\tFNIB\t\tZBOOT firmware header, header size: 32 bytes,\n>8\tlelong\t\tx\t\tload address: 0x%.8X,\n>12\tlelong\t\tx\t\tstart address: 0x%.8X,\n>16\tlelong\t\tx\t\tchecksum: 0x%.8X,\n>20\tlelong\t\tx\t\tversion: 0x%.8X,\n>24\tlelong\t\t<1\t\tinvalid\n>24\tlelong\t\tx\t\timage size: %d bytes\n\n# Firmware header used by several D-Link routers (and probably others)\n0               string  \\x5e\\xa3\\xa4\\x17\tDLOB firmware header,\n>(7.b+12)       string  !\\x5e\\xa3\\xa4\\x17       invalid,\n#>>12           string  x                       %s,\n>(7.b+40)       string  x                       boot partition: \"%s\"\n\n# TP-Link firmware header structure; thanks to Jonathan McGowan for reversing and documenting this format\n0\tstring          TP-LINK\\x20Technologies\t\tTP-Link firmware header,{offset-adjust:-4}\n#>-4\tlelong          x               \t\theader version: %d,\n>0x94  \tbeshort         x               \t\tfirmware version: %d.\n>0x96  \tbeshort         x               \t\t\\b%d.\n>0x98  \tbeshort         x               \t\t\\b%d,\n>0x18  \tstring          x               \t\timage version: \"%s\",\n#>0x74  belong          x               \t\timage size: %d bytes,\n>0x3C  \tbelong          x               \t\tproduct ID: 0x%X,\n>0x40  \tbelong          x               \t\tproduct version: %d,\n>0x70  \tbelong          x               \t\tkernel load address: 0x%X,\n>0x74  \tbelong          x               \t\tkernel entry point: 0x%X,\n>0x7C  \tbelong          x               \t\tkernel offset: %d,\n>0x80  \tbelong          x               \t\tkernel length: %d,\n>0x84  \tbelong          x               \t\trootfs offset: %d,\n>0x88  \tbelong          x               \t\trootfs length: %d,\n>0x8C  \tbelong          x               \t\tbootloader offset: %d,\n>0x90  \tbelong          x               \t\tbootloader length: %d\n\n# Tag Image File Format, from Daniel Quinlan (quinlan@yggdrasil.com)\n# The second word of TIFF files is the TIFF version number, 42, which has\n# never changed.  The TIFF specification recommends testing for it.\n0       string          MM\\x00\\x2a      TIFF image data, big-endian\n0       string          II\\x2a\\x00      TIFF image data, little-endian\n\n# PNG [Portable Network Graphics, or \"PNG's Not GIF\"] images\n# (Greg Roelofs, newt@uchicago.edu)\n# (Albert Cahalan, acahalan@cs.uml.edu)\n#\n# 137 P N G \\r \\n ^Z \\n [4-byte length] H E A D [HEAD data] [HEAD crc] ...\n#\n0       string          \\x89PNG\\x0d\\x0a\\x1a\\x0a         PNG image\n>16     belong          x               \\b, %ld x\n>20     belong          x               %ld,\n>24     byte            x               %d-bit\n>25     byte            0               grayscale,\n>25     byte            2               \\b/color RGB,\n>25     byte            3               colormap,\n>25     byte            4               gray+alpha,\n>25     byte            6               \\b/color RGBA,\n#>26    byte            0               deflate/32K,\n>28     byte            0               non-interlaced\n>28     byte            1               interlaced\n\n# GIF\n0       string          GIF8            GIF image data\n>4      string          7a              \\b, version 8\"%s\",\n>4      string          9a              \\b, version 8\"%s\",\n>6      leshort         >0              %hd x\n>8      leshort         >0              %hd\n#>10    byte            &0x80           color mapped,\n#>10    byte&0x07       =0x00           2 colors\n#>10    byte&0x07       =0x01           4 colors\n#>10    byte&0x07       =0x02           8 colors\n#>10    byte&0x07       =0x03           16 colors\n#>10    byte&0x07       =0x04           32 colors\n#>10    byte&0x07       =0x05           64 colors\n#>10    byte&0x07       =0x06           128 colors\n#>10    byte&0x07       =0x07           256 colors\n\n# PC bitmaps (OS/2, Windows BMP files)  (Greg Roelofs, newt@uchicago.edu)\n0       string          BM\n>14     leshort         12              PC bitmap, OS/2 1.x format\n>>18    leshort         x               \\b, %d x\n>>20    leshort         x               %d\n>14     leshort         64              PC bitmap, OS/2 2.x format\n>>18    leshort         x               \\b, %d x\n>>20    leshort         x               %d\n>14     leshort         40              PC bitmap, Windows 3.x format\n>>18    lelong          x               \\b, %d x\n>>22    lelong          x               %d x\n>>28    leshort         x               %d\n>14     leshort         128             PC bitmap, Windows NT/2000 format\n>>18    lelong          x               \\b, %d x\n>>22    lelong          x               %d x\n>>28    leshort         x               %d\n\n#------------------------------------------------------------------------------\n# JPEG images\n# SunOS 5.5.1 had\n#\n#       0       string          \\377\\330\\377\\340        JPEG file\n#       0       string          \\377\\330\\377\\356        JPG file\n#\n# both of which turn into \"JPEG image data\" here.\n#\n0       beshort         0xffd8          JPEG image data\n>6      string          JFIF            \\b, JFIF standard\n# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06\n# in a vain attempt to add image size reporting for JFIF.  Note that these\n# tests are not fool-proof since some perfectly valid JPEGs are currently\n# impossible to specify in magic(4) format.\n# First, a little JFIF version info:\n>>11    byte            x               \\b %d.\n>>12    byte            x               \\b%02d\n# Next, the resolution or aspect ratio of the image:\n#>>13   byte            0               \\b, aspect ratio\n#>>13   byte            1               \\b, resolution (DPI)\n#>>13   byte            2               \\b, resolution (DPCM)\n#>>4    beshort         x               \\b, segment length %d\n# Next, show thumbnail info, if it exists:\n>>18    byte            !0              \\b, thumbnail %dx\n>>>19   byte            x               \\b%d\n\n# EXIF moved down here to avoid reporting a bogus version number,\n# and EXIF version number printing added.\n#   - Patrik R=E5dman <patrik+file-magic@iki.fi>\n>6      string          Exif            \\b, EXIF standard\n# Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD.\n# All possible combinations of entries have to be enumerated, since no looping\n# is possible. And both endians are possible...\n# The combinations included below are from real-world JPEGs.\n# Little-endian\n>>12    string          II\n# IFD 0 Entry #5:\n>>>70   leshort         0x8769\n# EXIF IFD Entry #1:\n>>>>(78.l+14)   leshort 0x9000\n>>>>>(78.l+23)  byte    x               %c\n>>>>>(78.l+24)  byte    x               \\b.%c\n>>>>>(78.l+25)  byte    !0x30           \\b%c\n# IFD 0 Entry #9:\n>>>118  leshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(126.l+38)  leshort 0x9000\n>>>>>(126.l+47) byte    x               %c\n>>>>>(126.l+48) byte    x               \\b.%c\n>>>>>(126.l+49) byte    !0x30           \\b%c\n# IFD 0 Entry #10\n>>>130  leshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(138.l+38)  leshort 0x9000\n>>>>>(138.l+47) byte    x               %c\n>>>>>(138.l+48) byte    x               \\b.%c\n>>>>>(138.l+49) byte    !0x30           \\b%c\n# EXIF IFD Entry #4:\n>>>>(138.l+50)  leshort 0x9000\n>>>>>(138.l+59) byte    x               %c\n>>>>>(138.l+60) byte    x               \\b.%c\n>>>>>(138.l+61) byte    !0x30           \\b%c\n# EXIF IFD Entry #5:\n>>>>(138.l+62)  leshort 0x9000\n>>>>>(138.l+71) byte    x               %c\n>>>>>(138.l+72) byte    x               \\b.%c\n>>>>>(138.l+73) byte    !0x30           \\b%c\n# IFD 0 Entry #11\n>>>142  leshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(150.l+38)  leshort 0x9000\n>>>>>(150.l+47) byte    x               %c\n>>>>>(150.l+48) byte    x               \\b.%c\n>>>>>(150.l+49) byte    !0x30           \\b%c\n# EXIF IFD Entry #4:\n>>>>(150.l+50)  leshort 0x9000\n>>>>>(150.l+59) byte    x               %c\n>>>>>(150.l+60) byte    x               \\b.%c\n>>>>>(150.l+61) byte    !0x30           \\b%c\n# EXIF IFD Entry #5:\n>>>>(150.l+62)  leshort 0x9000\n>>>>>(150.l+71) byte    x               %c\n>>>>>(150.l+72) byte    x               \\b.%c\n>>>>>(150.l+73) byte    !0x30           \\b%c\n# Big-endian\n>>12    string          MM\n# IFD 0 Entry #9:\n>>>118  beshort         0x8769\n# EXIF IFD Entry #1:\n>>>>(126.L+14)  beshort 0x9000\n>>>>>(126.L+23) byte    x               %c\n>>>>>(126.L+24) byte    x               \\b.%c\n>>>>>(126.L+25) byte    !0x30           \\b%c\n# EXIF IFD Entry #3:\n>>>>(126.L+38)  beshort 0x9000\n>>>>>(126.L+47) byte    x               %c\n>>>>>(126.L+48) byte    x               \\b.%c\n>>>>>(126.L+49) byte    !0x30           \\b%c\n# IFD 0 Entry #10\n>>>130  beshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(138.L+38)  beshort 0x9000\n>>>>>(138.L+47) byte    x               %c\n>>>>>(138.L+48) byte    x               \\b.%c\n>>>>>(138.L+49) byte    !0x30           \\b%c\n# EXIF IFD Entry #5:\n>>>>(138.L+62)  beshort 0x9000\n>>>>>(138.L+71) byte    x               %c\n>>>>>(138.L+72) byte    x               \\b.%c\n>>>>>(138.L+73) byte    !0x30           \\b%c\n# IFD 0 Entry #11\n>>>142  beshort         0x8769\n# EXIF IFD Entry #4:\n>>>>(150.L+50)  beshort 0x9000\n>>>>>(150.L+59) byte    x               %c\n>>>>>(150.L+60) byte    x               \\b.%c\n>>>>>(150.L+61) byte    !0x30           \\b%c\n# Here things get sticky.  We can do ONE MORE marker segment with\n# indirect addressing, and that's all.  It would be great if we could\n# do pointer arithemetic like in an assembler language.  Christos?\n# And if there was some sort of looping construct to do searches, plus a few\n# named accumulators, it would be even more effective...\n# At least we can show a comment if no other segments got inserted before:\n>(4.S+5)        byte            0xFE\n>>(4.S+8)       string          >\\0             \\b, comment: \"%s\"\n# FIXME: When we can do non-byte counted strings, we can use that to get\n# the string's count, and fix Debian bug #283760\n#>(4.S+5)       byte            0xFE            \\b, comment\n#>>(4.S+6)      beshort         x               \\b length=%d\n#>>(4.S+8)      string          >\\0             \\b, \"%s\"\n# Or, we can show the encoding type (I've included only the three most common)\n# and image dimensions if we are lucky and the SOFn (image segment) is here:\n>(4.S+5)        byte            0xC0            \\b, baseline\n>>(4.S+6)       byte            x               \\b, precision %d\n>>(4.S+7)       beshort         x               \\b, %dx\n>>(4.S+9)       beshort         x               \\b%d\n>(4.S+5)        byte            0xC1            \\b, extended sequential\n>>(4.S+6)       byte            x               \\b, precision %d\n>>(4.S+7)       beshort         x               \\b, %dx\n>>(4.S+9)       beshort         x               \\b%d\n>(4.S+5)        byte            0xC2            \\b, progressive\n>>(4.S+6)       byte            x               \\b, precision %d\n>>(4.S+7)       beshort         x               \\b, %dx\n>>(4.S+9)       beshort         x               \\b%d\n# I've commented-out quantisation table reporting.  I doubt anyone cares yet.\n#>(4.S+5)       byte            0xDB            \\b, quantisation table\n#>>(4.S+6)      beshort         x               \\b length=%d\n#>14    beshort         x               \\b, %d x\n#>16    beshort         x               \\b %d\n\n\n#-------------------------Kernels-------------------------------------\n\n# Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>\n# and others such as Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>\n# and Nicolás Lichtmaier <nick@debian.org>\n# All known start with: b8 c0 07 8e d8 b8 00 90 8e c0 b9 00 01 29 f6 29\n0\tstring\t\t\\xb8\\xc0\\x07\\x8e\\xd8\\xb8\\x00\\x90\\x8e\\xc0\\xb9\\x00\\x01\\x29\\xf6\\x29\tLinux kernel boot image\n>514\tstring          !HdrS            \t\t\t\t\t\t\t(invalid)\n\n# Finds and prints Linux kernel strings in raw Linux kernels (output like uname -a).\n# Commonly found in decompressed embedded kernel binaries.\n0\tstring\t\tLinux\\ version\\ \tLinux kernel version\n>14\tbyte\t\t0\t\t\tinvalid\n>14\tbyte\t\t!0\n>>14\tstring\t\tx\t\t\t\"%s\n>>45\tstring\t\tx\t\t\t\\b%s\n>>76\tstring\t\tx\t\t\t\\b%s\n>>107\tstring\t\tx\t\t\t\\b%s\"\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5D\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5D\\x00\\x00\tLZMA compressed data, properties: 0x5D,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x01\n# ------------------------------------------------------------------\n0\t\tstring\t\\x01\\x00\\x00\tLZMA compressed data, properties: 0x01,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x02\n# ------------------------------------------------------------------\n0\t\tstring\t\\x02\\x00\\x00\tLZMA compressed data, properties: 0x02,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x03\n# ------------------------------------------------------------------\n0\t\tstring\t\\x03\\x00\\x00\tLZMA compressed data, properties: 0x03,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x04\n# ------------------------------------------------------------------\n0\t\tstring\t\\x04\\x00\\x00\tLZMA compressed data, properties: 0x04,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x09\n# ------------------------------------------------------------------\n0\t\tstring\t\\x09\\x00\\x00\tLZMA compressed data, properties: 0x09,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x0A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x0A\\x00\\x00\tLZMA compressed data, properties: 0x0A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x0B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x0B\\x00\\x00\tLZMA compressed data, properties: 0x0B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x0C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x0C\\x00\\x00\tLZMA compressed data, properties: 0x0C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x12\n# ------------------------------------------------------------------\n0\t\tstring\t\\x12\\x00\\x00\tLZMA compressed data, properties: 0x12,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x13\n# ------------------------------------------------------------------\n0\t\tstring\t\\x13\\x00\\x00\tLZMA compressed data, properties: 0x13,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x14\n# ------------------------------------------------------------------\n0\t\tstring\t\\x14\\x00\\x00\tLZMA compressed data, properties: 0x14,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x1B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x1B\\x00\\x00\tLZMA compressed data, properties: 0x1B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x1C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x1C\\x00\\x00\tLZMA compressed data, properties: 0x1C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x24\n# ------------------------------------------------------------------\n0\t\tstring\t\\x24\\x00\\x00\tLZMA compressed data, properties: 0x24,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x2D\n# ------------------------------------------------------------------\n0\t\tstring\t\\x2D\\x00\\x00\tLZMA compressed data, properties: 0x2D,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x2E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x2E\\x00\\x00\tLZMA compressed data, properties: 0x2E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x2F\n# ------------------------------------------------------------------\n0\t\tstring\t\\x2F\\x00\\x00\tLZMA compressed data, properties: 0x2F,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x30\n# ------------------------------------------------------------------\n0\t\tstring\t\\x30\\x00\\x00\tLZMA compressed data, properties: 0x30,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x31\n# ------------------------------------------------------------------\n0\t\tstring\t\\x31\\x00\\x00\tLZMA compressed data, properties: 0x31,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x36\n# ------------------------------------------------------------------\n0\t\tstring\t\\x36\\x00\\x00\tLZMA compressed data, properties: 0x36,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x37\n# ------------------------------------------------------------------\n0\t\tstring\t\\x37\\x00\\x00\tLZMA compressed data, properties: 0x37,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x38\n# ------------------------------------------------------------------\n0\t\tstring\t\\x38\\x00\\x00\tLZMA compressed data, properties: 0x38,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x39\n# ------------------------------------------------------------------\n0\t\tstring\t\\x39\\x00\\x00\tLZMA compressed data, properties: 0x39,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x3F\n# ------------------------------------------------------------------\n0\t\tstring\t\\x3F\\x00\\x00\tLZMA compressed data, properties: 0x3F,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x40\n# ------------------------------------------------------------------\n0\t\tstring\t\\x40\\x00\\x00\tLZMA compressed data, properties: 0x40,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x41\n# ------------------------------------------------------------------\n0\t\tstring\t\\x41\\x00\\x00\tLZMA compressed data, properties: 0x41,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x48\n# ------------------------------------------------------------------\n0\t\tstring\t\\x48\\x00\\x00\tLZMA compressed data, properties: 0x48,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x49\n# ------------------------------------------------------------------\n0\t\tstring\t\\x49\\x00\\x00\tLZMA compressed data, properties: 0x49,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x51\n# ------------------------------------------------------------------\n0\t\tstring\t\\x51\\x00\\x00\tLZMA compressed data, properties: 0x51,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5A\\x00\\x00\tLZMA compressed data, properties: 0x5A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5B\\x00\\x00\tLZMA compressed data, properties: 0x5B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5C\\x00\\x00\tLZMA compressed data, properties: 0x5C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5E\\x00\\x00\tLZMA compressed data, properties: 0x5E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x63\n# ------------------------------------------------------------------\n0\t\tstring\t\\x63\\x00\\x00\tLZMA compressed data, properties: 0x63,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x64\n# ------------------------------------------------------------------\n0\t\tstring\t\\x64\\x00\\x00\tLZMA compressed data, properties: 0x64,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x65\n# ------------------------------------------------------------------\n0\t\tstring\t\\x65\\x00\\x00\tLZMA compressed data, properties: 0x65,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x66\n# ------------------------------------------------------------------\n0\t\tstring\t\\x66\\x00\\x00\tLZMA compressed data, properties: 0x66,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x6C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x6C\\x00\\x00\tLZMA compressed data, properties: 0x6C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x6D\n# ------------------------------------------------------------------\n0\t\tstring\t\\x6D\\x00\\x00\tLZMA compressed data, properties: 0x6D,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x6E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x6E\\x00\\x00\tLZMA compressed data, properties: 0x6E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x75\n# ------------------------------------------------------------------\n0\t\tstring\t\\x75\\x00\\x00\tLZMA compressed data, properties: 0x75,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x76\n# ------------------------------------------------------------------\n0\t\tstring\t\\x76\\x00\\x00\tLZMA compressed data, properties: 0x76,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x7E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x7E\\x00\\x00\tLZMA compressed data, properties: 0x7E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x87\n# ------------------------------------------------------------------\n0\t\tstring\t\\x87\\x00\\x00\tLZMA compressed data, properties: 0x87,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x88\n# ------------------------------------------------------------------\n0\t\tstring\t\\x88\\x00\\x00\tLZMA compressed data, properties: 0x88,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x89\n# ------------------------------------------------------------------\n0\t\tstring\t\\x89\\x00\\x00\tLZMA compressed data, properties: 0x89,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x8A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x8A\\x00\\x00\tLZMA compressed data, properties: 0x8A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x8B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x8B\\x00\\x00\tLZMA compressed data, properties: 0x8B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x90\n# ------------------------------------------------------------------\n0\t\tstring\t\\x90\\x00\\x00\tLZMA compressed data, properties: 0x90,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x91\n# ------------------------------------------------------------------\n0\t\tstring\t\\x91\\x00\\x00\tLZMA compressed data, properties: 0x91,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x92\n# ------------------------------------------------------------------\n0\t\tstring\t\\x92\\x00\\x00\tLZMA compressed data, properties: 0x92,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x93\n# ------------------------------------------------------------------\n0\t\tstring\t\\x93\\x00\\x00\tLZMA compressed data, properties: 0x93,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x99\n# ------------------------------------------------------------------\n0\t\tstring\t\\x99\\x00\\x00\tLZMA compressed data, properties: 0x99,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x9A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x9A\\x00\\x00\tLZMA compressed data, properties: 0x9A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x9B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x9B\\x00\\x00\tLZMA compressed data, properties: 0x9B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xA2\n# ------------------------------------------------------------------\n0\t\tstring\t\\xA2\\x00\\x00\tLZMA compressed data, properties: 0xA2,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xA3\n# ------------------------------------------------------------------\n0\t\tstring\t\\xA3\\x00\\x00\tLZMA compressed data, properties: 0xA3,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xAB\n# ------------------------------------------------------------------\n0\t\tstring\t\\xAB\\x00\\x00\tLZMA compressed data, properties: 0xAB,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB4\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB4\\x00\\x00\tLZMA compressed data, properties: 0xB4,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB5\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB5\\x00\\x00\tLZMA compressed data, properties: 0xB5,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB6\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB6\\x00\\x00\tLZMA compressed data, properties: 0xB6,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB7\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB7\\x00\\x00\tLZMA compressed data, properties: 0xB7,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB8\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB8\\x00\\x00\tLZMA compressed data, properties: 0xB8,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xBD\n# ------------------------------------------------------------------\n0\t\tstring\t\\xBD\\x00\\x00\tLZMA compressed data, properties: 0xBD,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xBE\n# ------------------------------------------------------------------\n0\t\tstring\t\\xBE\\x00\\x00\tLZMA compressed data, properties: 0xBE,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xBF\n# ------------------------------------------------------------------\n0\t\tstring\t\\xBF\\x00\\x00\tLZMA compressed data, properties: 0xBF,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC0\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC0\\x00\\x00\tLZMA compressed data, properties: 0xC0,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC6\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC6\\x00\\x00\tLZMA compressed data, properties: 0xC6,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC7\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC7\\x00\\x00\tLZMA compressed data, properties: 0xC7,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC8\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC8\\x00\\x00\tLZMA compressed data, properties: 0xC8,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xCF\n# ------------------------------------------------------------------\n0\t\tstring\t\\xCF\\x00\\x00\tLZMA compressed data, properties: 0xCF,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xD0\n# ------------------------------------------------------------------\n0\t\tstring\t\\xD0\\x00\\x00\tLZMA compressed data, properties: 0xD0,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xD8\n# ------------------------------------------------------------------\n0\t\tstring\t\\xD8\\x00\\x00\tLZMA compressed data, properties: 0xD8,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n#------------------------------------------------------------------------------\n# $File: sql,v 1.6 2009/09/19 16:28:12 christos Exp $\n# sql:  file(1) magic for SQL files\n#\n# From: \"Marty Leisner\" <mleisner@eng.mc.xerox.com>\n# Recognize some MySQL files.\n#\n0       beshort                 0xfe01          MySQL table definition file\n>2\tstring\t\t\t<1\t\tinvalid\n>2\tstring\t\t\t>\\11\t\tinvalid\n>2      byte                    x               Version %d\n0       string\t\t        \\xfe\\xfe\\x03    MySQL MISAM index file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\xfe\\xfe\\x07    MySQL MISAM compressed data file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\xfe\\xfe\\x05    MySQL ISAM index file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\xfe\\xfe\\x06    MySQL ISAM compressed data file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\376bin         MySQL replication log\n\n#------------------------------------------------------------------------------\n# iRiver H Series database file \n# From Ken Guest <ken@linux.ie>\n# As observed from iRivNavi.iDB and unencoded firmware\n#\n0   string              iRivDB  iRiver Database file\n>11  string     >\\0     Version \"%s\"\n>39  string             iHP-100 [H Series]\n\n#------------------------------------------------------------------------------\n# SQLite database files\n# Ken Guest <ken@linux.ie>, Ty Sarna, Zack Weinberg\n#\n# Version 1 used GDBM internally; its files cannot be distinguished\n# from other GDBM files.\n#\n# Version 2 used this format:\n0       string  **\\x20This\\x20file\\x20contains\\x20an\\x20SQLite  SQLite 2.x database\n\n# Version 3 of SQLite allows applications to embed their own \"user version\"\n# number in the database.  Detect this and distinguish those files.\n\n0   string  SQLite\\x20format\\x203\n>60 string  _MTN               Monotone source repository\n>60 belong  !0                 SQLite 3.x database, user version %u\n>60 belong  0                  SQLite 3.x database\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/parser.py",
    "content": "import os.path\nimport tempfile\nfrom common import str2int\n\nclass MagicParser:\n\t'''\n\tClass for loading, parsing and creating libmagic-compatible magic files.\n\t\n\tThis class is primarily used internally by the Binwalk class, and a class instance of it is available via the Binwalk.parser object.\n\n\tOne useful method however, is file_from_string(), which will generate a temporary magic file from a given signature string:\n\n\t\timport binwalk\n\n\t\tbw = binwalk.Binwalk()\n\n\t\t# Create a temporary magic file that contains a single entry with a signature of '\\\\x00FOOBAR\\\\xFF', and append the resulting \n\t\t# temporary file name to the list of magic files in the Binwalk class instance.\n\t\tbw.magic_files.append(bw.parser.file_from_string('\\\\x00FOOBAR\\\\xFF', display_name='My custom signature'))\n\n\t\tbw.scan('firmware.bin')\n\t\n\tAll magic files generated by this class will be deleted when the class deconstructor is called.\n\t'''\n\n\tSHORT_SIZE = 2\n\tSHORTS = ['beshort', 'leshort', 'byte']\n\n\tBIG_ENDIAN = 'big'\n\tLITTLE_ENDIAN = 'little'\n\n\tMAGIC_STRING_FORMAT = \"%d\\tstring\\t%s\\t%s\\n\"\n\tDEFAULT_DISPLAY_NAME = \"Raw string signature\"\n\n\tWILDCARD = 'x'\n\n\t# If libmagic returns multiple results, they are delimited with this string.\t\n\tRESULT_SEPERATOR = \"\\\\012- \"\n\n\t# Size of the keys used in the matches set. Limited to 2\n\t# as the key is the magic signature of a given magic file entry.\n\t# Entries can have variable length signatures, but the lowest \n\t# common demonitor is 2, so the first two bytes of the signature\n\t# is used as the key. Does this result in collisions and false\n\t# positives? Yes. But false positives are filtered out by the\n\t# MagicFilter class. The main purpose of MagicParser.match is to\n\t# limit the number of calls to libmagic without itself incurring\n\t# large computational overhead. And for that purpose, this is\n\t# quite effective.\n\tMATCH_INDEX_SIZE = 2\n\n\tdef __init__(self, filter=None, smart=None):\n\t\t'''\n\t\tClass constructor.\n\n\t\t@filter - Instance of the MagicFilter class. May be None if the parse/parse_file methods are not used.\n\t\t@smart  - Instance of the SmartSignature class. May be None if the parse/parse_file methods are not used.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.matches = set([])\n\t\tself.signatures = {}\n\t\tself.sigset = {}\n\t\tself.filter = filter\n\t\tself.smart = smart\n\t\tself.raw_fd = None\n\t\tself.signature_count = 0\n\t\tself.fd = tempfile.NamedTemporaryFile()\n\n\tdef __del__(self):\n\t\t'''\n\t\tClass deconstructor.\n\t\t'''\n\t\tself.cleanup()\n\n\tdef cleanup(self):\n\t\t'''\n\t\tCleans up any tempfiles created by the class instance.\n\n\t\tReturns None.\n\t\t'''\n\t\t# Clean up the tempfiles\n\t\ttry:\n\t\t\tself.fd.close()\n\t\texcept:\n\t\t\tpass\n\t\t\n\t\ttry:\n\t\t\tself.raw_fd.close()\n\t\texcept:\n\t\t\tpass\n\n\tdef file_from_string(self, signature_string, offset=0, display_name=DEFAULT_DISPLAY_NAME):\n\t\t'''\n\t\tGenerates a magic file from a signature string.\n\n\t\t@signature_string - The string signature to search for.\n\t\t@offset           - The offset at which the signature should occur.\n\t\t@display_name     - The text to display when the signature is found.\n\n\t\tReturns the name of the generated temporary magic file.\n\t\t'''\n\t\tself.raw_fd = tempfile.NamedTemporaryFile()\n\t\tself.raw_fd.write(self.MAGIC_STRING_FORMAT % (offset, signature_string, display_name))\n\t\tself.raw_fd.seek(0)\n\t\treturn self.raw_fd.name\n\n\tdef parse(self, file_name, filter_short_signatures=True, pre_filter_signatures=True):\n\t\t'''\n\t\tParses magic file(s) and contatenates them into a single temporary magic file\n\t\twhile simultaneously removing filtered signatures.\n\n\t\t@file_name         \t\t- Magic file, or list of magic files, to parse.\n\t\t@filter_short_signatures\t- Set to False to include entries with short (2 byte) magic signatures.\n\t\t@pre_filter_signatures\t\t- Set to False to disable smart signature keywords.\n\n\t\tReturns the name of the generated temporary magic file, which will be automatically\n\t\tdeleted when the class deconstructor is called.\n\t\t'''\n\t\tif type(file_name) == type([]):\n\t\t\tfiles = file_name\n\t\telse:\n\t\t\tfiles = [file_name]\n\n\t\tfor fname in files:\n\t\t\tif os.path.exists(fname):\n\t\t\t\tself.parse_file(fname, filter_short_signatures, pre_filter_signatures)\n\n\t\tself.fd.seek(0)\n\t\treturn self.fd.name\n\n\tdef parse_file(self, file_name, filter_short_signatures=True, pre_filter_signatures=True):\n\t\t'''\n\t\tParses a magic file and appends valid signatures to the temporary magic file, as allowed\n\t\tby the existing filter rules.\n\n\t\t@file_name\t\t\t- Magic file to parse.\n\t\t@filter_short_signatures\t- Set to False to include entries with short (2 byte) magic signatures.\n\t\t@pre_filter_signatures\t\t- Set to False to disable smart signature keywords.\n\t\t\n\t\tReturns None.\n\t\t'''\n\t\t# Default to not including signature entries until we've\n\t\t# found what looks like a valid entry.\n\t\tinclude = False\n\t\tline_count = 0\n\n\t\ttry:\n\t\t\tfor line in open(file_name).readlines():\n\t\t\t\tline_count += 1\n\n\t\t\t\t# Check if this is the first line of a signature entry\n\t\t\t\tentry = self._parse_line(line)\n\n\t\t\t\tif entry is not None:\n\t\t\t\t\t# Once an entry is identified, default to excluding the entry\n\t\t\t\t\tinclude = False\n\n\t\t\t\t\tif pre_filter_signatures:\n\t\t\t\t\t\t# If the smart signature include keyword is specified for this entry,\n\t\t\t\t\t\t# add an include filter for this signature description.\n\t\t\t\t\t\tif self.smart.include(entry['description']):\n\t\t\t\t\t\t\tself.filter.include(entry['description'], exclusive=False)\n\t\t\t\t\t\t\tinclude = True\n\n\t\t\t\t\t# If we haven't already explicitly included this entry, and we are \n\t\t\t\t\t# filtering out short signatures and this is a short signature, then \n\t\t\t\t\t# add an exclude filter for this signature description\n\t\t\t\t\tif not include and filter_short_signatures and self._is_short(entry):\n\t\t\t\t\t\tself.filter.exclude(entry['description'])\n\n\t\t\t\t\t# If this signature is marked for inclusion, include it.\n\t\t\t\t\tif self.filter.filter(entry['description']) == self.filter.FILTER_INCLUDE:\n\t\t\t\t\t\tinclude = True\n\t\t\t\t\t\n\t\t\t\t\tif include:\n\t\t\t\t\t\tself.signature_count += 1\n\n\t\t\t\t\t\tif not self.signatures.has_key(entry['offset']):\n\t\t\t\t\t\t\tself.signatures[entry['offset']] = []\n\t\t\t\t\t\t\n\t\t\t\t\t\tif entry['condition'][:self.MATCH_INDEX_SIZE] not in self.signatures[entry['offset']]:\n\t\t\t\t\t\t\tself.signatures[entry['offset']].append(entry['condition'][:self.MATCH_INDEX_SIZE])\n\n\t\t\t\t# Keep writing lines of the signature to the temporary magic file until \n\t\t\t\t# we detect a signature that should not be included.\n\t\t\t\tif include:\n\t\t\t\t\tself.fd.write(line)\n\t\texcept Exception, e:\n\t\t\traise Exception(\"Error parsing magic file '%s' on line %d: %s\" % (file_name, line_count, str(e)))\n\n\t\t# Generate a dictionary of offsets with a set of signatures\t\n\t\tfor (offset, siglist) in self.signatures.iteritems():\n\t\t\tself.sigset[offset] = set(siglist)\n\n\tdef _is_short(self, entry):\n\t\t'''\n\t\tDetermines if a signature entry has a short (2 byte) signature or not.\n\n\t\t@entry - Entry dictionary, as returned by self._parse_line().\n\t\t\n\t\tReturns True if the signature is short, False if not short.\n\t\t'''\n\t\tif entry['type'] in self.SHORTS:\n\t\t\treturn True\n\t\telif 'string' in entry['type']:\n\t\t\tif len(entry['condition'].decode('string_escape')) <= self.SHORT_SIZE:\n\t\t\t\treturn True\n\t\treturn False\n\n\tdef _parse_line(self, line):\n\t\t'''\n\t\tParses a signature line into its four parts (offset, type, condition and description),\n\t\tlooking for the first line of a given signature.\n\n\t\t@line - The signature line to parse.\n\n\t\tReturns a dictionary with the respective line parts populated if the line is the first of a signature.\n\t\tReturns a dictionary with all parts set to None if the line is not the first of a signature.\n\t\t'''\n\t\tentry = {\n\t\t\t'offset'\t: '',\n\t\t\t'type'\t\t: '',\n\t\t\t'condition'\t: '',\n\t\t\t'description'\t: '',\n\t\t\t'length'\t: 0\n\t\t}\n\n\t\t# Quick and dirty pre-filter. We are only concerned with the first line of a\n\t\t# signature, which will always start with a number. Make sure the first byte of\n\t\t# the line is a number; if not, don't process.\n\t\tif line[:1] < '0' or line[:1] > '9':\n\t\t\treturn None\n\n\t\ttry:\n\t\t\t# Split the line into white-space separated parts.\n\t\t\t# For this to work properly, replace escaped spaces ('\\ ') with '\\x20'.\n\t\t\t# This means the same thing, but doesn't confuse split().\n\t\t\tline_parts = line.replace('\\\\ ', '\\\\x20').split()\n\t\t\tentry['offset'] = line_parts[0]\n\t\t\tentry['type'] = line_parts[1]\n\t\t\t# The condition line may contain escaped sequences, so be sure to decode it properly.\n\t\t\tentry['condition'] = line_parts[2].decode('string_escape')\n\t\t\tentry['description'] = ' '.join(line_parts[3:])\n\t\texcept Exception, e:\n\t\t\traise Exception(\"%s :: %s\", (str(e), line))\n\n\t\t# We've already verified that the first character in this line is a number, so this *shouldn't*\n\t\t# throw an exception, but let's catch it just in case...\n\t\ttry:\n\t\t\tentry['offset'] = str2int(entry['offset'])\n\t\texcept Exception, e:\n\t\t\traise Exception(\"%s :: %s\", (str(e), line))\n\n\t\t# If this is a string, get the length of the string\n\t\tif 'string' in entry['type']:\n\t\t\tentry['length'] = len(entry['condition'])\n\t\t# Else, we need to jump through a few more hoops...\n\t\telse:\t\n\t\t\t# Default to little endian, unless the type field starts with 'be'. \n\t\t\t# This assumes that we're running on a little endian system...\n\t\t\tif entry['type'].startswith('be'):\n\t\t\t\tendianess = self.BIG_ENDIAN\n\t\t\telse:\n\t\t\t\tendianess = self.LITTLE_ENDIAN\n\t\t\t\n\t\t\t# Try to convert the condition to an integer. This does not allow\n\t\t\t# for more advanced conditions for the first line of a signature, \n\t\t\t# but needing that is rare.\n\t\t\tif entry['condition'] != self.WILDCARD:\n\t\t\t\ttry:\n\t\t\t\t\tintval = str2int(entry['condition'].strip('L'))\n\t\t\t\texcept Exception, e:\n\t\t\t\t\traise Exception(\"Failed to evaluate condition for '%s' type: '%s', condition: '%s', error: %s\" % (entry['description'], entry['type'], entry['condition'], str(e)))\n\t\t\telse:\n\t\t\t\tintval = 0\n\t\t\t\tentry['length'] = 1\n\n\t\t\t# How long is the field type?\n\t\t\tif entry['type'] == 'byte':\n\t\t\t\tentry['length'] = 1\n\t\t\telif 'short' in entry['type']:\n\t\t\t\tentry['length'] = 2\n\t\t\telif 'long' in entry['type']:\n\t\t\t\tentry['length'] = 4\n\t\t\telif 'quad' in entry['type']:\n\t\t\t\tentry['length'] = 8\n\n\t\t\t# Convert the integer value to a string of the appropriate endianess\n\t\t\tentry['condition'] = self._to_string(intval, entry['length'], endianess)\n\n\t\treturn entry\n\n\tdef build_signature_set(self):\n\t\t'''\n\t\tBuilds a list of signature tuples.\n\n\t\tReturns a list of tuples in the format: [(<signature offset>, [set of 2-byte signatures])].\n\t\t'''\n\t\tsignatures = []\n\n\t\tfor (offset, sigset) in self.sigset.iteritems():\n\t\t\tsignatures.append((offset, sigset))\n\n\t\tsignatures.sort()\n\t\treturn signatures\n\n\tdef _to_string(self, value, size, endianess):\n\t\t'''\n\t\tConverts an integer value into a raw string.\n\n\t\t@value     - The integer value to convert.\n\t\t@size      - Size, in bytes, of the integer value.\n\t\t@endianess - One of self.LITTLE_ENDIAN | self.BIG_ENDIAN.\n\n\t\tReturns a raw string containing value.\n\t\t'''\n\t\tdata = \"\"\n\n\t\tfor i in range(0, size):\n\t\t\tdata += chr((value >> (8*i)) & 0xFF)\n\n\t\tif endianess != self.LITTLE_ENDIAN:\n\t\t\tdata = data[::-1]\n\n\t\treturn data\n\n\tdef split(self, data):\n\t\t'''\n\t\tSplits multiple libmagic results in the data string into a list of separate results.\n\n\t\t@data - Data string returned from libmagic.\n\n\t\tReturns a list of result strings.\n\t\t'''\n\t\ttry:\n\t\t\treturn data.split(self.RESULT_SEPERATOR)\n\t\texcept:\n\t\t\treturn []\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/prettyprint.py",
    "content": "import sys\nimport hashlib\nfrom datetime import datetime\n\nclass PrettyPrint:\n        '''\n        Class for printing Binwalk results to screen/log files.\n\t\n\tAn instance of PrettyPrint is available via the Binwalk.display object.\n\tThe PrettyPrint.results() method is of particular interest, as it is suitable for use as a Binwalk.scan() callback function,\n\tand can be used to print Binwalk.scan() results to stdout, a log file, or both.\n\n\tExample usage:\n\n\t\timport binwalk\n\n\t\tbw = binwalk.Binwalk()\n\n\t\tbw.display.header()\n\t\tbw.scan('firmware.bin', callback=bw.display.results)\n\t\tbw.display.footer()\n        '''\n\n        def __init__(self, log=None, quiet=False, bwalk=None, verbose=0):\n                '''\n                Class constructor.\n\t\t\n\t\t@log     - Output log file.\n\t\t@quiet   - If True, results will not be displayed to screen.\n\t\t@bwalk   - The Binwalk class instance.\n\t\t@verbose - If set to True, target file information will be displayed when file_info() is called.\n\n\t\tReturns None.\n\t\t'''\n                self.fp = None\n                self.log =log\n                self.quiet = quiet\n                self.binwalk = bwalk\n                self.verbose = verbose\n\n                if self.log is not None:\n                        self.fp = open(log, \"w\")\n\n        def __del__(self):\n\t\t'''\n\t\tClass deconstructor.\n\t\t'''\n\t\t# Close the log file.\n                try:\n                        self.fp.close()\n                except:\n                        pass\n\n        def _log(self, data):\n\t\t'''\n\t\tLog data to the log file.\n\t\t'''\n                if self.fp is not None:\n                        self.fp.write(data)\n\n        def _pprint(self, data):\n\t\t'''\n\t\tPrint data to stdout and the log file.\n\t\t'''\n                if not self.quiet:\n                        sys.stdout.write(data)\n                self._log(data)\n\n        def _file_md5(self, file_name):\n\t\t'''\n\t\tGenerate an MD5 hash of the specified file.\n\t\t'''\n                md5 = hashlib.md5()\n                \n                with open(file_name, 'rb') as f:\n                        for chunk in iter(lambda: f.read(128*md5.block_size), b''):\n                                md5.update(chunk)\n\n                return md5.hexdigest()\n                        \n        def file_info(self, file_name):\n\t\t'''\n\t\tPrints detailed info about the specified file, including file name, scan time and the file's MD5 sum.\n\t\tCalled internally by self.header if self.verbose is not 0.\n\n\t\t@file_name - The path to the target file.\n\n\t\tReturns None.\n\t\t'''\n                self._pprint(\"\\n\")\n                self._pprint(\"Scan Time:     %s\\n\" % datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n\t\tself._pprint(\"Signatures:    %d\\n\" % self.binwalk.parser.signature_count)\n                self._pprint(\"Target File:   %s\\n\" % file_name)\n                self._pprint(\"MD5 Checksum:  %s\\n\" % self._file_md5(file_name))\n\n        def header(self, file_name=None):\n\t\t'''\n\t\tPrints the Binwalk header, typically used just before starting a scan.\n\n\t\t@file_name - If specified, and if self.verbose > 0, then detailed file info will be included in the header.\n\n\t\tReturns None.\n\t\t'''\n                if self.verbose and file_name is not None:\n                        self.file_info(file_name)\n\n                self._pprint(\"\\nDECIMAL   \\tHEX       \\tDESCRIPTION\\n\")\n                self._pprint(\"-------------------------------------------------------------------------------------------------------\\n\")\n\n        def footer(self):\n\t\t'''\n\t\tPrints the Binwalk footer, typically used just after completing a scan.\n\n\t\tReturns None.\n\t\t'''\n                self._pprint(\"\\n\")\n\n        def results(self, offset, results):\n\t\t'''\n\t\tPrints the results of a scan. Suitable for use as a callback function for Binwalk.scan().\n\n\t\t@offset  - The offset at which the results were found.\n\t\t@results - A list of libmagic result strings.\n\t\t\n\t\tReturns None.\n\t\t'''\n                offset_printed = False\n\n                for info in results:\n\t\t\t# Check for any grep filters before printing\n                        if self.binwalk is not None and self.binwalk.filter.grep(info['description']):\n\t\t\t\t# Only display the offset once per list of results\n                                if not offset_printed:\n                                        self._pprint(\"%-10d\\t0x%-8X\\t%s\\n\" % (offset, offset, info['description']))\n                                        offset_printed = True\n                                else:\n                                        self._pprint(\"%s\\t  %s\\t%s\\n\" % (' '*10, ' '*8, info['description']))\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/smartsig.py",
    "content": "import re\nfrom common import str2int, get_quoted_strings\n\nclass SmartSignature:\n\t'''\n\tClass for parsing smart signature tags in libmagic result strings.\n\n\tThis class is intended for internal use only, but a list of supported 'smart keywords' that may be used \n\tin magic files is available via the SmartSignature.KEYWORDS dictionary:\n\n\t\tfrom binwalk import SmartSignature\n\n\t\tfor (i, keyword) in SmartSignature().KEYWORDS.iteritems():\n\t\t\tprint keyword\n\t'''\n\n\tKEYWORD_DELIM_START = \"{\"\n\tKEYWORD_DELIM_END = \"}\"\n\tKEYWORDS = {\n\t\t'jump'\t\t\t: '%sjump-to-offset:' % KEYWORD_DELIM_START,\n\t\t'filename'\t\t: '%sfile-name:' % KEYWORD_DELIM_START,\n\t\t'filesize'\t\t: '%sfile-size:' % KEYWORD_DELIM_START,\n\t\t'raw-string'\t\t: '%sraw-string:' % KEYWORD_DELIM_START,\t# This one is special and must come last in a signature block\n\t\t'raw-size'\t\t: '%sraw-string-length:' % KEYWORD_DELIM_START,\n\t\t'adjust'\t\t: '%soffset-adjust:' % KEYWORD_DELIM_START,\n\t\t'delay'\t\t\t: '%sextract-delay:' % KEYWORD_DELIM_START,\n\n\t\t'raw-replace'\t\t: '%sraw-replace%s' % (KEYWORD_DELIM_START, KEYWORD_DELIM_END),\n\t\t'one-of-many'\t\t: '%sone-of-many%s' % (KEYWORD_DELIM_START, KEYWORD_DELIM_END),\n\t\t'include'\t\t: '%sfilter-include%s' % (KEYWORD_DELIM_START, KEYWORD_DELIM_END),\n\t\t'exclude'\t\t: '%sfilter-exclude%s' % (KEYWORD_DELIM_START, KEYWORD_DELIM_END),\n\t}\n\n\tdef __init__(self, filter, pre_filter_signatures=True):\n\t\t'''\n\t\tClass constructor.\n\n\t\t@filter                - Instance of the MagicFilter class.\n\t\t@pre_filter_signatures - Set to False to disable the pre-filtering of magic signatures.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.filter = filter\n\t\tself.last_one_of_many = None\n\t\tself.pre_filter_signatures = pre_filter_signatures\n\n\tdef parse(self, data):\n\t\t'''\n\t\tParse a given data string for smart signature keywords. If any are found, interpret them and strip them.\n\n\t\t@data - String to parse, as returned by libmagic.\n\n\t\tReturns a dictionary of parsed values.\n\t\t'''\n\t\tresults = {\n\t\t\t'description'\t: '',\t# The libmagic data string, stripped of all keywords\n\t\t\t'name'\t\t: '',\t# The original name of the file, if known\n\t\t\t'delay'\t\t: '',\t# Extract delay description\n\t\t\t'extract'\t: '',\t# Name of the extracted file, filled in by Binwalk.Scan.\n\t\t\t'jump'\t\t: 0,\t# The relative offset to resume the scan from\n\t\t\t'size'\t\t: 0,\t# The size of the file, if known\n\t\t\t'adjust'\t: 0,\t# The relative offset to add to the reported offset\n\t\t}\n\n\t\t# If pre-filtering is disabled, or the result data is not valid (i.e., potentially malicious), \n\t\t# don't parse anything, just return the raw data as the description.\n\t\tif not self.pre_filter_signatures or not self._is_valid(data):\n\t\t\tresults['description'] = data\n\t\telse:\n\t\t\t# Parse the offset-adjust value. This is used to adjust the reported offset at which \n\t\t\t# a signature was located due to the fact that MagicParser.match expects all signatures\n\t\t\t# to be located at offset 0, which some wil not be.\n\t\t\tresults['adjust'] = self._get_math_arg(data, 'adjust')\n\n\t\t\t# Parse the file-size value. This is used to determine how many bytes should be extracted\n\t\t\t# when extraction is enabled. If not specified, everything to the end of the file will be\n\t\t\t# extracted (see Binwalk.scan).\n\t\t\ttry:\n\t\t\t\tresults['size'] = str2int(self._get_keyword_arg(data, 'filesize'))\n\t\t\texcept:\n\t\t\t\tpass\n\n\t\t\tresults['delay'] = self._get_keyword_arg(data, 'delay')\n\n\t\t\t# Parse the string for the jump-to-offset keyword.\n\t\t\t# This keyword is honored, even if this string result is one of many.\n\t\t\tresults['jump'] = self._get_math_arg(data, 'jump')\n\n\t\t\t# If this is one of many, don't do anything and leave description as a blank string.\n\t\t\t# Else, strip all keyword tags from the string and process additional keywords as necessary.\n\t\t\tif not self._one_of_many(data):\n\t\t\t\tresults['name'] = self._get_keyword_arg(data, 'filename').strip('\"')\n\t\t\t\tresults['description'] = self._strip_tags(data)\n\n\t\treturn results\n\n\tdef _is_valid(self, data):\n\t\t'''\n\t\tValidates that result data does not contain smart keywords in file-supplied strings.\n\n\t\t@data - Data string to validate.\n\n\t\tReturns True if data is OK.\n\t\tReturns False if data is not OK.\n\t\t'''\n\t\t# All strings printed from the target file should be placed in strings, else there is\n\t\t# no way to distinguish between intended keywords and unintended keywords. Get all the\n\t\t# quoted strings.\n\t\tquoted_data = get_quoted_strings(data)\n\n\t\t# Check to see if there was any quoted data, and if so, if it contained the keyword starting delimiter\n\t\tif quoted_data and self.KEYWORD_DELIM_START in quoted_data:\n\t\t\t# If so, check to see if the quoted data contains any of our keywords.\n\t\t\t# If any keywords are found inside of quoted data, consider the keywords invalid.\n\t\t\tfor (name, keyword) in self.KEYWORDS.iteritems():\n\t\t\t\tif keyword in quoted_data:\n\t\t\t\t\treturn False\n\t\treturn True\n\n\tdef _one_of_many(self, data):\n\t\t'''\n\t\tDetermines if a given data string is one result of many.\n\n\t\t@data - String result data.\n\n\t\tReturns True if the string result is one of many.\n\t\tReturns False if the string result is not one of many.\n\t\t'''\n\t\tif not self.filter.invalid(data):\n\t\t\tif self.last_one_of_many is not None and data.startswith(self.last_one_of_many):\n\t\t\t\treturn True\n\t\t\n\t\t\tif self.KEYWORDS['one-of-many'] in data:\n\t\t\t\t# Only match on the data before the first comma, as that is typically unique and static\n\t\t\t\tself.last_one_of_many = data.split(',')[0]\n\t\t\telse:\n\t\t\t\tself.last_one_of_many = None\n\t\t\t\n\t\treturn False\n\n\tdef _get_keyword_arg(self, data, keyword):\n\t\t'''\n\t\tRetrieves the argument for keywords that specify arguments.\n\n\t\t@data    - String result data, as returned by libmagic.\n\t\t@keyword - Keyword index in KEYWORDS.\n\n\t\tReturns the argument string value on success.\n\t\tReturns a blank string on failure.\n\t\t'''\n\t\targ = ''\n\n\t\tif self.KEYWORDS.has_key(keyword) and self.KEYWORDS[keyword] in data:\n\t\t\targ = data.split(self.KEYWORDS[keyword])[1].split(self.KEYWORD_DELIM_END)[0]\n\n\t\treturn arg\n\n\tdef _get_math_arg(self, data, keyword):\n\t\t'''\n\t\tRetrieves the argument for keywords that specifiy mathematical expressions as arguments.\n\n\t\t@data    - String result data, as returned by libmagic.\n\t\t@keyword - Keyword index in KEYWORDS.\n\n\t\tReturns the resulting calculated value.\n\t\t'''\n\t\tvalue = 0\n\n\t\targ = self._get_keyword_arg(data, keyword)\n\t\tif arg:\n\t\t\tfor string_int in arg.split('+'):\n\t\t\t\ttry:\n\t\t\t\t\tvalue += str2int(string_int)\n\t\t\t\texcept:\n\t\t\t\t\tpass\n\n\t\treturn value\t\t\t\n\n\tdef _jump(self, data):\n\t\t'''\n\t\tObtains the jump-to-offset value of a signature, if any.\n\n\t\t@data - String result data.\n\n\t\tReturns the offset to jump to.\n\t\t'''\n\t\toffset = 0\n\n\t\toffset_str = self._get_keyword_arg(data, 'jump')\n\t\tif offset_str:\n\t\t\ttry:\n\t\t\t\toffset = str2int(offset_str)\n\t\t\texcept:\n\t\t\t\tpass\n\n\t\treturn offset\n\n\tdef _parse_raw_strings(self, data):\n\t\t'''\n\t\tProcess strings that aren't NULL byte terminated, but for which we know the string length.\n\t\tThis should be called prior to any other smart parsing functions.\n\n\t\t@data - String to parse.\n\n\t\tReturns a parsed string.\n\t\t'''\n\t\tif self.pre_filter_signatures and self._is_valid(data):\n\t\t\t# Get the raw string  keyword arg\n\t\t\traw_string = self._get_keyword_arg(data, 'raw-string')\n\n\t\t\t# Was a raw string  keyword specified?\n\t\t\tif raw_string:\n\t\t\t\t# Get the raw string length arg\n\t\t\t\traw_size = self._get_keyword_arg(data, 'raw-size')\n\t\n\t\t\t\t# Is the raw string  length arg is a numeric value?\n\t\t\t\tif re.match('^-?[0-9]+$', raw_size):\n\t\t\t\t\t# Replace all instances of raw-replace in data with raw_string[:raw_size]\n\t\t\t\t\t# Also strip out everything after the raw-string keyword, including the keyword itself.\n\t\t\t\t\t# Failure to do so may (will) result in non-printable characters and this string will be \n\t\t\t\t\t# marked as invalid when it shouldn't be.\n\t\t\t\t\tdata = data[:data.find(self.KEYWORDS['raw-string'])].replace(self.KEYWORDS['raw-replace'], '\"' + raw_string[:str2int(raw_size)] + '\"')\n\t\treturn data\n\n\tdef include(self, data):\n\t\t'''\n\t\tDetermines if a result should be included or excluded.\n\n\t\t@data - String result data.\n\n\t\tReturns True if the include smart tag is present.\n\t\tReturns False if the exclude smart tag is present.\n\t\tReturns None if neither smart tags are present.\n\t\t'''\n\t\t# Validate keywords before checking for the include/exclude keywords.\n\t\tif self.pre_filter_signatures and self._is_valid(data):\n\t\t\tif self.KEYWORDS['exclude'] in data:\n\t\t\t\treturn False\n\t\t\telif self.KEYWORDS['include'] in data:\n\t\t\t\treturn True\n\t\treturn None\n\n\tdef _strip_tags(self, data):\n\t\t'''\n\t\tStrips the smart tags from a result string.\n\n\t\t@data - String result data.\n\n\t\tReturns a sanitized string.\n\t\t'''\n\t\tif self.pre_filter_signatures:\n\t\t\tfor (name, keyword) in self.KEYWORDS.iteritems():\n\t\t\t\tstart = data.find(keyword)\n\t\t\t\tif start != -1:\n\t\t\t\t\tend = data[start:].find(self.KEYWORD_DELIM_END)\n\t\t\t\t\tif end != -1:\n\t\t\t\t\t\tdata = data.replace(data[start:start+end+1], \"\")\n\t\treturn data\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/lib.linux-x86_64-2.7/binwalk/update.py",
    "content": "import urllib2\nfrom config import *\n\nclass Update:\n\t'''\n\tClass for updating Binwalk configuration and signatures files from the subversion trunk.\n\n\tExample usage:\n\n\t\tfrom binwalk import Update\n\n\t\tUpdate().update()\n\t'''\n\tBASE_URL = \"http://binwalk.googlecode.com/svn/trunk/src/binwalk/\"\n\tMAGIC_PREFIX = \"magic/\"\n\tCONFIG_PREFIX = \"config/\"\n\n\tdef __init__(self):\n\t\t'''\n\t\tClass constructor.\n\t\t'''\n\t\tself.config = Config()\n\n\tdef update(self):\n\t\t'''\n\t\tUpdates all system wide signatures and config files.\n\n\t\tReturns None.\n\t\t'''\n\t\tself.update_binwalk()\n\t\tself.update_bincast()\n\t\tself.update_binarch()\n\t\tself.update_extract()\n\n\tdef _do_update_from_svn(self, prefix, fname):\n\t\t'''\n\t\tUpdates the specified file to the latest version of that file in SVN.\n\n\t\t@prefix - The URL subdirectory where the file is located.\n\t\t@fname  - The name of the file to update.\n\n\t\tReturns None.\n\t\t'''\n\t\turl = self.BASE_URL + prefix + fname\n\t\t\n\t\ttry:\n\t\t\tdata = urllib2.urlopen(url).read()\n\t\t\topen(self.config.paths['system'][fname], \"wb\").write(data)\n\t\texcept Exception, e:\n\t\t\traise Exception(\"Update._do_update_from_svn failed to update file '%s': %s\" % (url, str(e)))\n\n\tdef update_binwalk(self):\n\t\t'''\n\t\tUpdates the binwalk signature file.\n\n\t\tReturns None.\n\t\t'''\n\t\tself._do_update_from_svn(self.MAGIC_PREFIX, self.config.BINWALK_MAGIC_FILE)\n\t\n\tdef update_bincast(self):\n\t\t'''\n\t\tUpdates the bincast signature file.\n\n\t\tReturns None.\n\t\t'''\n\t\tself._do_update_from_svn(self.MAGIC_PREFIX, self.config.BINCAST_MAGIC_FILE)\n\t\n\tdef update_binarch(self):\n\t\t'''\n\t\tUpdates the binarch signature file.\n\t\n\t\tReturns None.\n\t\t'''\n\t\tself._do_update_from_svn(self.MAGIC_PREFIX, self.config.BINARCH_MAGIC_FILE)\n\n\tdef update_extract(self):\n\t\t'''\n\t\tUpdates the extract.conf file.\n\t\n\t\tReturns None.\n\t\t'''\n\t\tself._do_update_from_svn(self.CONFIG_PREFIX, self.config.EXTRACT_FILE)\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/build/scripts-2.7/binwalk",
    "content": "#!/usr/bin/python\n\nimport sys\nimport os.path\nimport binwalk\nfrom threading import Thread\nfrom binwalk.common import str2int\nfrom getopt import GetoptError, getopt as GetOpt\n\ndef display_status(bwalk):\n\twhile True:\n\t\t# Display the current scan progress when the enter key is pressed.\n\t\traw_input()\n\t\tprint \"Progress: %.2f%% (%d / %d)\\n\" % (((float(bwalk.total_scanned) / float(bwalk.scan_length)) * 100), bwalk.total_scanned, bwalk.scan_length)\n\ndef usage(fd):\n\tfd.write(\"\\n\")\n\tfd.write(\"Binwalk v%s\\n\" % binwalk.Config.VERSION)\n\tfd.write(\"Craig Heffner, http://www.devttys0.com\\n\")\n\tfd.write(\"\\n\")\n\tfd.write(\"Usage: %s [OPTIONS] [FILE1] [FILE2] [FILE3] ...\\n\" % os.path.basename(sys.argv[0]))\n\tfd.write(\"\\n\")\n\tfd.write(\"\\t-o, --offset=<int>            Start scan at this file offset\\n\")\n\tfd.write(\"\\t-l, --length=<int>            Number of bytes to scan\\n\")\n\tfd.write(\"\\t-b, --align=<int>             Set byte alignment [default: 1]\\n\")\n\tfd.write(\"\\t-m, --magic=<file>            Specify an alternate magic file to use\\n\")\n\tfd.write(\"\\t-i, --include=<filter>        Include matches that are normally excluded and that have <filter> in their description\\n\")\n\tfd.write(\"\\t-x, --exclude=<filter>        Exclude matches that have <filter> in their description\\n\")\n\tfd.write(\"\\t-y, --search=<filter>         Only search for matches that have <filter> in their description\\n\")\n\tfd.write(\"\\t-g, --grep=<text>             Grep results for the specified text\\n\")\n\tfd.write(\"\\t-R, --raw-bytes=<string>      Search for a sequence of raw bytes instead of using the default magic signatures\\n\")\n\tfd.write(\"\\t-f, --file=<file>             Log results to file\\n\")\n\tfd.write(\"\\t-D, --dd=<type:ext[:cmd]>     Extract entries whose descriptions match <type>, give them file extension <ext>, and execute <cmd>\\n\")\n\tfd.write(\"\\t-e, --extract=[file]          Automatically extract known file types. Load rules from file, if specified.\\n\")\n\tfd.write(\"\\t-r, --rm                      Cleanup extracted files and zero-size files\\n\")\n\tfd.write(\"\\t-d, --delay                   Delay file extraction for files with known footers\\n\")\n\tfd.write(\"\\t-a, --all                     Include all short signatures\\n\")\n\tfd.write(\"\\t-I, --show-invalid            Show results marked as invalid\\n\")\n\tfd.write(\"\\t-A, --opcodes                 Scan for executable code\\n\")\n\tfd.write(\"\\t-C, --cast                    Cast file contents as various data types\\n\")\n\tfd.write(\"\\t-k, --keep-going              Show all matching results at a given offset, not just the first one\\n\")\n\tfd.write(\"\\t-q, --quiet                   Supress output to stdout\\n\")\n\tfd.write(\"\\t-v, --verbose                 Be verbose (specify twice for very verbose)\\n\")\n\tfd.write(\"\\t-u, --update                  Update magic signature files\\n\")\n\tfd.write(\"\\t-h, --help                    Show help output\\n\")\n\tfd.write(\"\\n\")\n\n\tif fd == sys.stderr:\n\t\tsys.exit(1)\n\telse:\n\t\tsys.exit(0)\n\ndef main():\n\tMIN_ARGC = 2\n\talign = 1\n\toffset = 0\n\tlength = 0\n\tquiet = False\n\tpre_filter = True\n\tverbose = 0\n\tlog_file = None\n\tshow_invalid = False\n\tshort_sig = True\n\tcustom_signature = None\n\tdelay_extraction = False\n\textract_rules_file = None\n\textract_from_config = False\n\tcleanup_after_extract = False\n\tmagic_flags = binwalk.magic.MAGIC_NONE\n\toptions = []\n\tmagic_files = []\n\ttarget_files = []\n\tgreps = []\n\tincludes = []\n\texcludes = []\n\tsearches = []\n\textracts = []\n\n\tconfig = binwalk.Config()\n\n\tshort_options = \"aACdhkeqruvPIf:o:l:b:i:x:y:D:m:R:g:\"\n\tlong_options = [\n\t\t\t\"rm\",\n\t\t\t\"all\",\n\t\t\t\"help\", \n\t\t\t\"quiet\", \n\t\t\t\"verbose\",\n\t\t\t\"opcodes\",\n\t\t\t\"cast\",\n\t\t\t\"update\",\n\t\t\t\"keep-going\",\n\t\t\t\"show-invalid\",\n\t\t\t\"profile\",\n\t\t\t\"delay\",\n\t\t\t\"file=\", \n\t\t\t\"offset=\", \n\t\t\t\"length=\", \n\t\t\t\"align=\",\n\t\t\t\"include=\",\n\t\t\t\"exclude=\",\n\t\t\t\"extract=\",\n\t\t\t\"search=\",\n\t\t\t\"dd=\",\n\t\t\t\"grep=\",\n\t\t\t\"magic=\",\n\t\t\t\"raw-bytes=\",\n\t]\n\n\t# Require at least one argument (the target file)\n\tif len(sys.argv) < MIN_ARGC:\n\t\tusage(sys.stderr)\n\n\ttry:\n\t\topts, args = GetOpt(sys.argv[1:], short_options, long_options)\n\texcept GetoptError, e:\n\t\tsys.stderr.write(\"%s\\n\" % str(e))\n\t\tusage(sys.stderr)\n\n\tfor opt, arg in opts:\n\t\tif opt in (\"-h\", \"--help\"):\n\t\t\tusage(sys.stdout)\n\t\telif opt in (\"-d\", \"--delay\"):\n\t\t\tdelay_extraction = True\n\t\telif opt in (\"-f\", \"--file\"):\n\t\t\tlog_file = arg\n\t\telif opt in (\"-q\", \"--quiet\"):\n\t\t\tquiet = True\n\t\telif opt in (\"-v\", \"--verbose\"):\n\t\t\tverbose += 1\n\t\telif opt in (\"-o\", \"--offset\"):\n\t\t\toffset = str2int(arg)\n\t\telif opt in (\"-l\", \"--length\"):\n\t\t\tlength = str2int(arg)\n\t\telif opt in (\"-b\", \"--align\"):\n\t\t\talign = str2int(arg)\n\t\telif opt in (\"-i\", \"--include\"):\n\t\t\tincludes.append(arg)\n\t\telif opt in (\"-y\", \"--search\"):\n\t\t\tsearches.append(arg)\n\t\telif opt in (\"-x\", \"--exclude\"):\n\t\t\texcludes.append(arg)\n\t\telif opt in (\"-D\", \"--dd\"):\n\t\t\textracts.append(arg)\n\t\telif opt in (\"-g\", \"--grep\"):\n\t\t\tgreps.append(arg)\n\t\telif opt in (\"-e\", \"--extract\"):\n\t\t\tif arg:\n\t\t\t\textract_rules_file = arg\n\t\t\telse:\n\t\t\t\textract_from_config = True\n\t\telif opt in (\"-r\", \"--rm\"):\n\t\t\tcleanup_after_extract = True\n\t\telif opt in (\"-m\", \"--magic\"):\n\t\t\tmagic_files.append(arg)\n\t\telif opt in (\"-a\", \"--all\"):\n\t\t\tshort_sig = False\n\t\telif opt in (\"-k\", \"--keep-going\"):\n\t\t\tmagic_flags |= binwalk.magic.MAGIC_CONTINUE\n\t\telif opt in (\"-I\", \"--show-invalid\"):\n\t\t\tshow_invalid = True\n\n\t\telif opt in (\"-A\", \"--opcodes\"):\n\t\t\t# Check every single offset\n\t\t\talign = 1\n\t\t\t# Don't filter out short signatures as some opcode sigs are only 2 bytes\n\t\t\tshort_sig = False\n\t\t\t# Load user file first so its signatures take precedence\n\t\t\tmagic_files.append(config.paths['user'][config.BINARCH_MAGIC_FILE])\n\t\t\tmagic_files.append(config.paths['system'][config.BINARCH_MAGIC_FILE])\n\t\telif opt in (\"-C\", \"--cast\"):\n\t\t\t# Check every single offset\n\t\t\talign = 1\n\t\t\t# Don't stop at the first match (everything matches everything in this scan)\n\t\t\tmagic_flags |= binwalk.magic.MAGIC_CONTINUE\n\t\t\t# Disable all pre filtering; we want to check everything for this scan\n\t\t\tpre_filter = False\n\t\t\t# Don't filter shot signatures, or else some casts won't be displayed\n\t\t\tshort_sig = False\n\t\t\t# Load user file first so its signatures take precedence\n\t\t\tmagic_files.append(config.paths['user'][config.BINCAST_MAGIC_FILE])\n\t\t\tmagic_files.append(config.paths['system'][config.BINCAST_MAGIC_FILE])\n\t\telif opt in (\"-R\", \"--raw-bytes\"):\n\t\t\t# Disable short signature filtering, as the supplied string may be short\n\t\t\tshort_sig = False\n\t\t\tcustom_signature = arg\n\t\telif opt in (\"-u\", \"--update\"):\n\t\t\ttry:\n\t\t\t\tsys.stdout.write(\"Updating signatures...\")\n\t\t\t\tsys.stdout.flush()\n\n\t\t\t\tbinwalk.Update().update()\n\n\t\t\t\tsys.stdout.write(\"done.\\n\")\n\t\t\t\tsys.exit(0)\n\t\t\texcept Exception, e:\n\t\t\t\tif 'Permission denied' in str(e):\n\t\t\t\t\tsys.stderr.write(\"failed (permission denied). Check your user permissions, or run the update as root.\\n\")\n\t\t\t\telse:\n\t\t\t\t\tsys.stderr.write('\\n' + str(e) + '\\n')\n\t\t\t\tsys.exit(1)\n\t\t# The --profile option is handled prior to calling main()\n\t\telif opt not in ('-P', '--profile'):\n\t\t\tusage(sys.stderr)\n\n\t\t# Append the option and argument to the list of processed options\n\t\t# This is used later to determine which argv entries are file names\n\t\toptions.append(opt)\n\t\toptions.append(arg)\n\t\toptions.append(\"%s%s\" % (opt, arg))\n\t\toptions.append(\"%s=%s\" % (opt, arg))\n\n\t# Treat any command line options not processed by getopt as target file paths\n\tfor opt in sys.argv[1:]:\n\t\t#TODO: Do we really want to not process valid files that start with a '-'?\n\t\t#      This is probably OK, and ensures that no options are treated as target files.\n\t\tif opt not in options and not opt.startswith('-'):\n\t\t\ttarget_files.append(opt)\n\n\t# If more than one target file was specified, enable verbose mode; else, there is\n\t# nothing in the output to indicate which scan corresponds to which file.\n\tif len(target_files) > 1:\n\t\tverbose = True\n\n\t# Instantiate the Binwalk class\n\tbwalk = binwalk.Binwalk(flags=magic_flags, verbose=verbose, log=log_file, quiet=quiet)\n\n\t# If a custom signature was specified, create a temporary magic file containing the custom signature\n\t# and ensure that it is the only magic file that will be loaded when Binwalk.scan() is called.\n\tif custom_signature is not None:\n\t\tmagic_files = bwalk.parser.file_from_string(custom_signature)\n\n\t# Set any specified filters\n\tbwalk.filter.include(includes, exclusive=False)\n\tbwalk.filter.exclude(excludes)\n\tbwalk.filter.include(searches)\n\tbwalk.filter.grep(filters=greps)\n\n\t# Add any specified extract rules\n\tbwalk.extractor.add_rule(extracts)\n\n\t# If -e was specified, load the default extract rules\n\tif extract_from_config:\n\t\tbwalk.extractor.load_defaults()\n\n\t# If --extract was specified, load the specified extraction rules file\n\tif extract_rules_file is not None:\n\t\tbwalk.extractor.load_from_file(extract_rules_file)\n\n\t# Set the extractor cleanup value (True to clean up files, False to leave them on disk)\n\tbwalk.extractor.cleanup_extracted_files(cleanup_after_extract)\n\n\t# Enable delayed extraction, which will prevent supported file types from having trailing data when extracted\n\tbwalk.extractor.enable_delayed_extract(delay_extraction)\n\n\t# Load the magic file(s)\n\tbwalk.load_signatures(magic_files=magic_files, pre_filter_signatures=pre_filter, filter_short_signatures=short_sig)\n\t\n\t# Scan each target file\n\tfor target_file in target_files:\n\t\tbwalk.display.header(target_file)\n\n\t\t# Start the display_status function as a daemon thread\n\t\tt = Thread(target=display_status, args=(bwalk,))\n\t\tt.setDaemon(True)\n\t\tt.start()\n\n\t\t# Catch keyboard interrupts so that we can properly clean up after the scan\n\t\ttry:\n\t\t\tbwalk.scan(target_file, \n\t\t\t\toffset=offset, \n\t\t\t\tlength=length, \n\t\t\t\talign=align,\n\t\t\t\tshow_invalid_results=show_invalid, \n\t\t\t\tcallback=bwalk.display.results)\n\t\texcept KeyboardInterrupt:\n\t\t\tpass\n\n\t\tbwalk.display.footer()\n\n\t# Be sure to drink your ovaltine.\n\t# And also to clean up any temporary magic files.\n\tbwalk.cleanup()\n\ntry:\n\t# Special options for profiling the code. For debug use only.\n\tif '--profile' in sys.argv or '-P' in sys.argv:\n\t\timport cProfile\n\t\tcProfile.run('main()')\n\telse:\n\t\tmain()\nexcept KeyboardInterrupt:\n\tpass\n\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/archives",
    "content": "# ----------------------------Archive Formats--------------------------------------\n\n# POSIX tar archives\n0\tstring\t\tustar\\000\t\tPOSIX tar archive{offset-adjust:-257}\n0\tstring          ustar\\040\\040\\000\tPOSIX tar archive (GNU){offset-adjust:-257}\n\n# JAR archiver (.j), this is the successor to ARJ, not Java's JAR (which is essentially ZIP)\n0       string  \\x1aJar\\x1b JAR (ARJ Software, Inc.) archive data{offset-adjust:-14}\n0       string  JARCS JAR (ARJ Software, Inc.) archive data\n\n\n# ARJ archiver (jason@jarthur.Claremont.EDU)\n0       leshort         0xea60          ARJ archive data\n>5      byte            x               \\b, v%d,\n>8      byte            &0x04           multi-volume,\n>8      byte            &0x10           slash-switched,\n>8      byte            &0x20           backup,\n>34     string          x               original name: \"%s\",\n>7      byte            0               os: MS-DOS \n>7      byte            1               os: PRIMOS\n>7      byte            2               os: Unix\n>7      byte            3               os: Amiga\n>7      byte            4               os: Macintosh\n>7      byte            5               os: OS/2\n>7      byte            6               os: Apple ][ GS\n>7      byte            7               os: Atari ST\n>7      byte            8               os: NeXT\n>7      byte            9               os: VAX/VMS\n>3      byte            >0              %d]\n\n# RAR archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\tRar!\t\tRAR archive data\n\n# HPACK archiver (Peter Gutmann, pgut1@cs.aukuni.ac.nz)\n0\tstring\t\tHPAK\t\tHPACK archive data\n\n# JAM Archive volume format, by Dmitry.Kohmanyuk@UA.net\n0\tstring\t\t\\351,\\001JAM\tJAM archive\n\n# LHARC/LHA archiver (Greg Roelofs, newt@uchicago.edu)\n0\tstring\t\t-lzs-\t\tLHa 2.x? archive data [lzs] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh\\40-\t\tLHa 2.x? archive data [lh ] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lhd-\t\tLHa 2.x? archive data [lhd] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh2-\t\tLHa 2.x? archive data [lh2] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh3-\t\tLHa 2.x? archive data [lh3] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh4-\t\tLHa (2.x) archive data [lh4] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh5-\t\tLHa (2.x) archive data [lh5] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh6-\t\tLHa (2.x) archive data [lh6] [NSRL|LHA2]{offset-adjust:-2}\n0\tstring\t\t-lh7-\t\tLHa (2.x) archive data [lh7] [NSRL|LHA2]{offset-adjust:-2}\n\n\n# cpio archives\n#\n# The SVR4 \"cpio(4)\" hints that there are additional formats, but they\n# are defined as \"short\"s; I think all the new formats are\n# character-header formats and thus are strings, not numbers.\n#0       string          070707          ASCII cpio archive (pre-SVR4 or odc)\n\n0       string          070701          ASCII cpio archive (SVR4 with no CRC),\n>110\tbyte\t\t0\t\tinvalid\n>110\tstring\t\tx\t\tfile name: \"%s\"\n>54\tstring\t\tx\t\t{jump-to-offset:0x%.8s+112}\n\n0       string          070702          ASCII cpio archive (SVR4 with CRC)\n>110\tbyte\t\t0\t\tinvalid\n>110\tstring\t\tx\t\tfile name: \"%s\"\n>54\tstring\t\tx\t\t{jump-to-offset:0x%.8s+112}\n\n\n# HP Printer Job Language\n# The header found on Win95 HP plot files is the \"Silliest Thing possible\" \n# (TM)\n# Every driver puts the language at some random position, with random case\n# (LANGUAGE and Language)\n# For example the LaserJet 5L driver puts the \"PJL ENTER LANGUAGE\" in line 10\n# From: Uwe Bonnes <bon@elektron.ikp.physik.th-darmstadt.de>\n# \n0       string          \\033%-12345X@PJL        HP Printer Job Language data\n>&0     string          >\\0                     \"%s\"\n>>&0    string          >\\0                     \"%s\"\n>>>&0   string          >\\0                     \"%s\"\n>>>>&0  string          >\\0                     \"%s\"\n\n#------------------------------------------------------------------------------\n#\n# RPM: file(1) magic for Red Hat Packages   Erik Troan (ewt@redhat.com)\n#\n0\tbelong\t\t0xedabeedb\tRPM\n>4\tbyte\t\tx\t\tv%d\n>6\tbeshort\t\t0\t\tbin\n>6\tbeshort\t\t1\t\tsrc\n>8\tbeshort\t\t1\t\ti386\n>8\tbeshort\t\t2\t\tAlpha\n>8\tbeshort\t\t3\t\tSparc\n>8\tbeshort\t\t4\t\tMIPS\n>8\tbeshort\t\t5\t\tPowerPC\n>8\tbeshort\t\t6\t\t68000\n>8\tbeshort\t\t7\tSGI\n>8\tbeshort\t\t8\t\tRS6000\n>8\tbeshort\t\t9\t\tIA64\n>8\tbeshort\t\t10\t\tSparc64\n>8\tbeshort\t\t11\t\tMIPSel\n>8\tbeshort\t\t12\t\tARM\n>10\tstring\t\tx\t\t\"%s\"\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/bootloaders",
    "content": "\n#---------------------------Bootloaders--------------------------------\n\n# CFE bootloader\n0\tstring\tCFE1CFE1\tCFE boot loader, little endian\n0\tstring\t1EFC1EFC\tCFE boot loader, big endian\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/compressed",
    "content": "\n#------------------Compression Formats-----------------------------\n\n# AFX compressed files (Wolfram Kleff)\n0\tstring\t\t-afx-\t\tAFX compressed file data{offset-adjust:-2}\n\n# bzip2\n0\tstring BZh91AY&SY\tbzip2 compressed data, block size = 900k\n0\tstring BZh81AY&SY\tbzip2 compressed data, block size = 800k\n0\tstring BZh71AY&SY\tbzip2 compressed data, block size = 700k\n0\tstring BZh61AY&SY\tbzip2 compressed data, block size = 600k\n0\tstring BZh51AY&SY\tbzip2 compressed data, block size = 500k\n0\tstring BZh41AY&SY\tbzip2 compressed data, block size = 400k\n0\tstring BZh31AY&SY\tbzip2 compressed data, block size = 300k\n0\tstring BZh21AY&SY\tbzip2 compressed data, block size = 200k\n0\tstring BZh11AY&SY\tbzip2 compressed data, block size = 100k\n\n# lzop from <markus.oberhumer@jk.uni-linz.ac.at>\n0\tstring\t\t\\x89\\x4c\\x5a\\x4f\\x00\\x0d\\x0a\\x1a\\x0a\tlzop compressed data\n>9\tbeshort\t\t<0x0940\n>>9\tbyte&0xf0\t=0x00\t\t- version 0.\n>>9\tbeshort&0x0fff\tx\t\t\\b%03x,\n>>13\tbyte\t\t1\t\tLZO1X-1,\n>>13\tbyte\t\t2\t\tLZO1X-1(15),\n>>13\tbyte\t\t3\t\tLZO1X-999,\n## >>22\tbedate\t\t>0\t\tlast modified: %s,\n>>14\tbyte\t\t=0x00\t\tos: MS-DOS\n>>14\tbyte\t\t=0x01\t\tos: Amiga\n>>14\tbyte\t\t=0x02\t\tos: VMS\n>>14\tbyte\t\t=0x03\t\tos: Unix\n>>14\tbyte\t\t=0x05\t\tos: Atari\n>>14\tbyte\t\t=0x06\t\tos: OS/2\n>>14\tbyte\t\t=0x07\t\tos: MacOS\n>>14\tbyte\t\t=0x0A\t\tos: Tops/20\n>>14\tbyte\t\t=0x0B\t\tos: WinNT\n>>14\tbyte\t\t=0x0E\t\tos: Win32\n>9\tbeshort\t\t>0x0939\n>>9\tbyte&0xf0\t=0x00\t\t- version 0.\n>>9\tbyte&0xf0\t=0x10\t\t- version 1.\n>>9\tbyte&0xf0\t=0x20\t\t- version 2.\n>>9\tbeshort&0x0fff\tx\t\t\\b%03x,\n>>15\tbyte\t\t1\t\tLZO1X-1,\n>>15\tbyte\t\t2\t\tLZO1X-1(15),\n>>15\tbyte\t\t3\t\tLZO1X-999,\n## >>25\tbedate\t\t>0\t\tlast modified: %s,\n>>17\tbyte\t\t=0x00\t\tos: MS-DOS\n>>17\tbyte\t\t=0x01\t\tos: Amiga\n>>17\tbyte\t\t=0x02\t\tos: VMS\n>>17\tbyte\t\t=0x03\t\tos: Unix\n>>17\tbyte\t\t=0x05\t\tos: Atari\n>>17\tbyte\t\t=0x06\t\tos: OS/2\n>>17\tbyte\t\t=0x07\t\tos: MacOS\n>>17\tbyte\t\t=0x0A\t\tos: Tops/20\n>>17\tbyte\t\t=0x0B\t\tos: WinNT\n>>17\tbyte\t\t=0x0E\t\tos: Win32\n\n# lzip  \n0       string          LZIP            lzip compressed data\n>4      byte            x               \\b, version: %d\n\n# LZO\n0\tstring\t\t\\211LZO\\000\\015\\012\\032\\012\tLZO compressed data\n\n# 7-zip archiver, from Thomas Klausner (wiz@danbala.tuwien.ac.at)\n# http://www.7-zip.org or DOC/7zFormat.txt \n#\n0       string          7z\\274\\257\\047\\034      7-zip archive data,\n>6      byte            x                       version %d\n>7      byte            x                       \\b.%d\n\n# standard unix compress\n0       beshort\t\t0x1f9d          compress'd data\n>2      byte&0x80       >0              block compressed\n>2\tbyte&0x1f\t!16\t\tinvalid\n>2      byte&0x1f       x               %d bits\n\n# http://tukaani.org/xz/xz-file-format.txt\n0\tstring\t\t\\xFD\\x37\\x7a\\x58\\x5a\\x00\txz compressed data\n\n# gzip (GNU zip, not to be confused with Info-ZIP or PKWARE zip archiver)\n#   Edited by Chris Chittleborough <cchittleborough@yahoo.com.au>, March 2002\n#       * Original filename is only at offset 10 if \"extra field\" absent\n#       * Produce shorter output - notably, only report compression methods\n#         other than 8 (\"deflate\", the only method defined in RFC 1952).\n0       string          \\037\\213\\x08    gzip compressed data\n>3      byte            &0x01           \\b, ASCII\n>3      byte            &0x02           \\b, has CRC\n>3      byte            &0x04           \\b, extra field\n>3      byte&0xC        =0x08\n>>10\tstring\t\tx\t\t\\b{file-name:%s}\n>>10    string          x               \\b, was \"%s\"\n>3      byte            &0x10           \\b, has comment\n>9      byte            =0x00           \\b, from FAT filesystem (MS-DOS, OS/2, NT)\n>9      byte            =0x01           \\b, from Amiga\n>9      byte            =0x02           \\b, from VMS\n>9      byte            =0x03           \\b, from Unix\n>9      byte            =0x04           \\b, from VM/CMS\n>9      byte            =0x05           \\b, from Atari\n>9      byte            =0x06           \\b, from HPFS filesystem (OS/2, NT)\n>9      byte            =0x07           \\b, from MacOS\n>9      byte            =0x08           \\b, from Z-System\n>9      byte            =0x09           \\b, from CP/M\n>9      byte            =0x0A           \\b, from TOPS/20\n>9      byte            =0x0B           \\b, from NTFS filesystem (NT)\n>9      byte            =0x0C           \\b, from QDOS\n>9      byte            =0x0D           \\b, from Acorn RISCOS\n>9\tbyte\t\t>0x0D\t\t\\b, invalid source\n>9\tbyte\t\t<0\t\t\\b, invalid source\n>3      byte            &0x20           \\b, encrypted (invalid)\n# Dates before 1992 are invalid, unless of course you're DD-WRT in which\n# case you don't know how to set a date in your gzip files. Brilliant.\n>4\tlelong\t\t=0\t\t\\b, NULL date:\n>4\tlelong\t\t<0\t\t\\b, invalid date:\n>4\tlelong\t\t>0\t\t\n>>4\tlelong\t\t<694224000\t\\b, invalid date:\n>>4\tlelong\t\t=694224000\t\\b, invalid date:\n>>4\tlelong\t\t>694224000\t\\b, last modified:\n>4      ledate          x               %s\n>8      byte            2               \\b, max compression\n>8      byte            4               \\b, max speed\n\n# Zlib signatures\n0\tbeshort\t\t0x789C\t\tzlib compressed data\n0\tbeshort\t\t0x78DA\t\tzlib compressed data\n0\tbeshort\t\t0x7801\t\tzlib compressed data\n\n# Supplementary magic data for the file(1) command to support\n# rzip(1).  The format is described in magic(5).\n#\n# Copyright (C) 2003 by Andrew Tridgell.  You may do whatever you want with\n# this file.\n#\n0       string          RZIP            rzip compressed data\n>4      byte            x               - version %d\n>5      byte            x               \\b.%d\n>6      belong          x               (%d bytes)\n\n# ZIP compression (Greg Roelofs, c/o zip-bugs@wkuvx1.wku.edu)\n0       string          PK\\003\\004      Zip archive data,\n>4      byte            0x00            v0.0\n>4      byte            0x09            at least v0.9 to extract,\n>4      byte            0x0a            at least v1.0 to extract,\n>4      byte            0x0b            at least v1.1 to extract,\n>0x161  string          WINZIP          WinZIP self-extracting,\n>4      byte            0x14\n>>30    ubelong         !0x6d696d65     at least v2.0 to extract,\n>18\tlelong\t\t!0\n>>18\tlelong\t\t<0\t\tinvalid\n>>18\tlelong\t\tx\t\tcompressed size: %d,\n>22\tlelong\t\t!0\n>>22\tlelong\t\t<0\t\tinvalid\n>>22\tlelong\t\tx\t\tuncompressed size: %d,{extract-delay:end of zip archive}\n>30\tstring\t\tx\t\t{file-name:{raw-replace}}name: {raw-replace}\n>26\tleshort\t\tx\t\t{raw-string-length:%d}\n>30\tstring\t\tx\t\t{raw-string:%s\n>61\tstring\t\tx\t\t\\b%s\n>92\tstring\t\tx\t\t\\b%s\n>123\tstring\t\tx\t\t\\b%s\n>154\tstring\t\tx\t\t\\b%s}\n\n# ZIP footer\n0\tstring\t\tPK\\x05\\x06\tEnd of Zip archive\n>20\tleshort\t\tx\t\t{offset-adjust:22+%d}\n>20\tleshort\t\t>0\n>>20\tleshort\t\tx\t\t\\b, comment: {raw-replace}\n>>20\tleshort\t\tx\t\t{raw-string-length:%d}\n>>22\tstring\t\tx\t\t{raw-string:%s}\n\n# New LZMA format signature\n0\tstring\t\t\\xFFLZMA\\x00\tLZMA compressed data (new),\n>6\tbyte&0x10\t0\t\tsingle-block stream\n>6\tbyte&0x10\t0x10\t\tmulti-block stream\n\n# See lzma file for LZMA signatures\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/crypto",
    "content": "# Type: OpenSSL certificates/key files\n# From: Nicolas Collignon <tsointsoin@gmail.com>\n\n0       string  -----BEGIN\\x20CERTIFICATE-----    PEM certificate\n0       string  -----BEGIN\\x20CERTIFICATE\\x20REQ    PEM certificate request\n0       string  -----BEGIN\\x20RSA\\x20PRIVATE        PEM RSA private key\n0       string  -----BEGIN\\x20DSA\\x20PRIVATE        PEM DSA private key\n\n# Type: OpenSSH key files\n# From: Nicolas Collignon <tsointsoin@gmail.com>\n\n0       string  SSH\\x20PRIVATE\\x20KEY\tOpenSSH RSA1 private key,\n>28     string  >\\0\t\t\tversion \"%s\"\n\n0       string  ssh-dss\\x20               OpenSSH DSA public key\n0       string  ssh-rsa\\x20               OpenSSH RSA public key\n\n# Type: Certificates/key files in DER format\n# From: Gert Hulselmans <hulselmansgert@gmail.com>\n0\tstring\t\\x30\\x82\t\tPrivate key in DER format (PKCS#8),\n>4\tstring\t!\\x02\\x01\\x00\t\tinvalid,\n>>2\tbeshort\tx\t\t\theader length: 4, sequence length: %d\n\n0\tstring  \\x30\\x82\t\tCertificate in DER format (x509 v3),\n>4\tstring\t!\\x30\\x82\t\tinvalid,\n>>2\tbeshort\tx\t\t\theader length: 4, sequence length: %d\n\n# GnuPG\n# The format is very similar to pgp\n0\tstring          \\001gpg                 GPG key trust database\n>4\tbyte            x                       version %d\n0       beshort         0x9901                  GPG key public ring\n# This magic is not particularly good, as the keyrings don't have true\n# magic. Nevertheless, it covers many keyrings.\n\n#------------------------------------------------------------------------------\n# Mavroyanopoulos Nikos <nmav@hellug.gr>\n# mcrypt:   file(1) magic for mcrypt 2.2.x;\n0\tstring\t\t\\0m\\3\t\tmcrypt 2.5 encrypted data,\n>4\tbyte\t\t0\t\tinvalid\n>4\tstring\t\t>\\0\t\talgorithm: \"%s\",\n>>&1\tleshort\t\t<1\t\tinvalid\n>>&1\tleshort\t\t>0\t\tkeysize: %d bytes,\n>>>&0\tbyte\t\t0\t\tinvalid\n>>>&0\tstring\t\t>\\0\t\tmode: \"%s\",\n\n0\tstring\t\t\\0m\\2\t\tmcrypt 2.2 encrypted data,\n>3\tbyte\t\t0\t\talgorithm: blowfish-448,\n>3\tbyte\t\t1\t\talgorithm: DES,\n>3\tbyte\t\t2\t\talgorithm: 3DES,\n>3\tbyte\t\t3\t\talgorithm: 3-WAY,\n>3\tbyte\t\t4\t\talgorithm: GOST,\n>3\tbyte\t\t6\t\talgorithm: SAFER-SK64,\n>3\tbyte\t\t7\t\talgorithm: SAFER-SK128,\n>3\tbyte\t\t8\t\talgorithm: CAST-128,\n>3\tbyte\t\t9\t\talgorithm: xTEA,\n>3\tbyte\t\t10\t\talgorithm: TWOFISH-128,\n>3\tbyte\t\t11\t\talgorithm: RC2,\n>3\tbyte\t\t12\t\talgorithm: TWOFISH-192,\n>3\tbyte\t\t13\t\talgorithm: TWOFISH-256,\n>3\tbyte\t\t14\t\talgorithm: blowfish-128,\n>3\tbyte\t\t15\t\talgorithm: blowfish-192,\n>3\tbyte\t\t16\t\talgorithm: blowfish-256,\n>3\tbyte\t\t100\t\talgorithm: RC6,\n>3\tbyte\t\t101\t\talgorithm: IDEA,\n>3\tbyte\t\t<0\t\tinvalid algorithm\n>3\tbyte\t\t>101\t\tinvalid algorithm,\n>3\tbyte\t\t>16\n>>3\tbyte\t\t<100\t\tinvalid algorithm,\n>4\tbyte\t\t0\t\tmode: CBC,\n>4\tbyte\t\t1\t\tmode: ECB,\n>4\tbyte\t\t2\t\tmode: CFB,\n>4\tbyte\t\t3\t\tmode: OFB,\n>4\tbyte\t\t4\t\tmode: nOFB,\n>4\tbyte\t\t<0\t\tinvalid mode,\n>4\tbyte\t\t>4\t\tinvalid mode,\n>5\tbyte\t\t0\t\tkeymode: 8bit\n>5\tbyte\t\t1\t\tkeymode: 4bit\n>5\tbyte\t\t2\t\tkeymode: SHA-1 hash\n>5\tbyte\t\t3\t\tkeymode: MD5 hash\n>5\tbyte\t\t<0\t\tinvalid keymode\n>5\tbyte\t\t>3\t\tinvalid keymode\n\n#------------------------------------------------------------------------------\n# pgp:  file(1) magic for Pretty Good Privacy\n#\n#0       beshort         0x9900                  PGP key public ring\n#0       beshort         0x9501                  PGP key security ring\n#0       beshort         0x9500                  PGP key security ring\n#0\tbeshort\t\t0xa600\t\t\tPGP encrypted data\n0       string          -----BEGIN\\040PGP       PGP armored data\n>15     string          PUBLIC\\040KEY\\040BLOCK- public key block\n>15     string          MESSAGE-                message\n>15     string          SIGNED\\040MESSAGE-      signed message\n>15     string          PGP\\040SIGNATURE-       signature\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/executables",
    "content": "\n#------------------Standard file formats------------------------------------\n\n#------------------------------------------------------------------------------\n# elf:  file(1) magic for ELF executables\n#\n# We have to check the byte order flag to see what byte order all the\n# other stuff in the header is in.\n#\n# What're the correct byte orders for the nCUBE and the Fujitsu VPP500?\n#\n# updated by Daniel Quinlan (quinlan@yggdrasil.com)\n0\tstring\t\t\\177ELF\t\tELF\n>4\tbyte\t\t0\t\tinvalid class\n>4\tbyte\t\t1\t\t32-bit\n# only for MIPS - in the future, the ABI field of e_flags should be used.\n>>18\tleshort\t\t8\n>>>36\tlelong\t\t&0x20\t\tN32\n>>18\tleshort\t\t10\n>>>36\tlelong\t\t&0x20\t\tN32\n>>18\tbeshort\t\t8\n>>>36\tbelong\t\t&0x20\t\tN32\n>>18\tbeshort\t\t10\n>>>36\tbelong\t\t&0x20\t\tN32\n>4\tbyte\t\t2\t\t64-bit\n>5\tbyte\t\t0\t\tinvalid byte order\n>5\tbyte\t\t1\t\tLSB\n# The official e_machine number for MIPS is now #8, regardless of endianness.\n# The second number (#10) will be deprecated later. For now, we still\n# say something if #10 is encountered, but only gory details for #8.\n>>18    leshort\t\t8\n# only for 32-bit\n>>>4\tbyte\t\t1\n>>>>36  lelong&0xf0000000\t0x00000000\tMIPS-I\n>>>>36  lelong&0xf0000000\t0x10000000\tMIPS-II\n>>>>36  lelong&0xf0000000\t0x20000000\tMIPS-III\n>>>>36  lelong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>36  lelong&0xf0000000\t0x40000000\tMIPS-V\n>>>>36  lelong&0xf0000000\t0x60000000\tMIPS32\n>>>>36  lelong&0xf0000000\t0x70000000\tMIPS64\n>>>>36  lelong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>36  lelong&0xf0000000\t0x90000000\tMIPS64 rel2\n# only for 64-bit\n>>>4\tbyte\t\t2\n>>>>48  lelong&0xf0000000\t0x00000000\tMIPS-I\n>>>>48  lelong&0xf0000000\t0x10000000\tMIPS-II\n>>>>48  lelong&0xf0000000\t0x20000000\tMIPS-III\n>>>>48  lelong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>48  lelong&0xf0000000\t0x40000000\tMIPS-V\n>>>>48  lelong&0xf0000000\t0x60000000\tMIPS32\n>>>>48  lelong&0xf0000000\t0x70000000\tMIPS64 \n>>>>48  lelong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>48  lelong&0xf0000000\t0x90000000\tMIPS64 rel2\n>>16\tleshort\t\t0\t\tno file type,\n>>16\tleshort\t\t1\t\trelocatable,\n>>16\tleshort\t\t2\t\texecutable,\n>>16\tleshort\t\t3\t\tshared object,\n# Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>\n# corrections by Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>\n>>16\tleshort\t\t4\t\tcore file\n# Core file detection is not reliable.\n#>>>(0x38+0xcc) string\t>\\0\t\tof '%s'\n#>>>(0x38+0x10) lelong\t>0\t\t(signal %d),\n>>16\tleshort\t\t&0xff00\t\tprocessor-specific,\n>>18\tleshort\t\t0\t\tno machine,\n>>18\tleshort\t\t1\t\tAT&T WE32100 - invalid byte order,\n>>18\tleshort\t\t2\t\tSPARC - invalid byte order,\n>>18\tleshort\t\t3\t\tIntel 80386,\n>>18\tleshort\t\t4\t\tMotorola\n>>>36\tlelong\t\t&0x01000000\t68000 - invalid byte order,\n>>>36\tlelong\t\t&0x00810000\tCPU32 - invalid byte order,\n>>>36\tlelong\t\t0\t\t68020 - invalid byte order,\n>>18\tleshort\t\t5\t\tMotorola 88000 - invalid byte order,\n>>18\tleshort\t\t6\t\tIntel 80486,\n>>18\tleshort\t\t7\t\tIntel 80860,\n>>18\tleshort\t\t8\t\tMIPS,\n>>18\tleshort\t\t9\t\tAmdahl - invalid byte order,\n>>18\tleshort\t\t10\t\tMIPS (deprecated),\n>>18\tleshort\t\t11\t\tRS6000 - invalid byte order,\n>>18\tleshort\t\t15\t\tPA-RISC - invalid byte order,\n>>>50\tleshort\t\t0x0214\t\t2.0\n>>>48\tleshort\t\t&0x0008\t\t(LP64),\n>>18\tleshort\t\t16\t\tnCUBE,\n>>18\tleshort\t\t17\t\tFujitsu VPP500,\n>>18\tleshort\t\t18\t\tSPARC32PLUS,\n>>18\tleshort\t\t20\t\tPowerPC,\n>>18\tleshort\t\t22\t\tIBM S/390,\n>>18\tleshort\t\t36\t\tNEC V800,\n>>18\tleshort\t\t37\t\tFujitsu FR20,\n>>18\tleshort\t\t38\t\tTRW RH-32,\n>>18\tleshort\t\t39\t\tMotorola RCE,\n>>18\tleshort\t\t40\t\tARM,\n>>18\tleshort\t\t41\t\tAlpha,\n>>18\tleshort\t\t0xa390\t\tIBM S/390 (obsolete),\n>>18\tleshort\t\t42\t\tHitachi SH,\n>>18\tleshort\t\t43\t\tSPARC V9 - invalid byte order,\n>>18\tleshort\t\t44\t\tSiemens Tricore Embedded Processor,\n>>18\tleshort\t\t45\t\tArgonaut RISC Core, Argonaut Technologies Inc.,\n>>18\tleshort\t\t46\t\tHitachi H8/300,\n>>18\tleshort\t\t47\t\tHitachi H8/300H,\n>>18\tleshort\t\t48\t\tHitachi H8S,\n>>18\tleshort\t\t49\t\tHitachi H8/500,\n>>18\tleshort\t\t50\t\tIA-64 (Intel 64 bit architecture)\n>>18\tleshort\t\t51\t\tStanford MIPS-X,\n>>18\tleshort\t\t52\t\tMotorola Coldfire,\n>>18\tleshort\t\t53\t\tMotorola M68HC12,\n>>18\tleshort\t\t62\t\tAMD x86-64,\n>>18\tleshort\t\t75\t\tDigital VAX,\n>>18\tleshort\t\t97\t\tNatSemi 32k,\n>>18\tleshort\t\t0x9026\t\tAlpha (unofficial),\n>>20\tlelong\t\t0\t\tinvalid version\n>>20\tlelong\t\t1\t\tversion 1\n>>36\tlelong\t\t1\t\tMathCoPro/FPU/MAU Required\n>5\tbyte\t\t2\t\tMSB\n# only for MIPS - see comment in little-endian section above.\n>>18    beshort\t\t8\n# only for 32-bit\n>>>4\tbyte\t\t1\n>>>>36  belong&0xf0000000\t0x00000000\tMIPS-I\n>>>>36  belong&0xf0000000\t0x10000000\tMIPS-II\n>>>>36  belong&0xf0000000\t0x20000000\tMIPS-III\n>>>>36  belong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>36  belong&0xf0000000\t0x40000000\tMIPS-V\n>>>>36  belong&0xf0000000\t0x60000000\tMIPS32\n>>>>36  belong&0xf0000000\t0x70000000\tMIPS64\n>>>>36  belong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>36  belong&0xf0000000\t0x90000000\tMIPS64 rel2\n# only for 64-bit\n>>>4\tbyte\t\t2\n>>>>48\tbelong&0xf0000000\t0x00000000\tMIPS-I\n>>>>48\tbelong&0xf0000000\t0x10000000\tMIPS-II\n>>>>48\tbelong&0xf0000000\t0x20000000\tMIPS-III\n>>>>48\tbelong&0xf0000000\t0x30000000\tMIPS-IV\n>>>>48\tbelong&0xf0000000\t0x40000000\tMIPS-V\n>>>>48\tbelong&0xf0000000\t0x60000000\tMIPS32\n>>>>48\tbelong&0xf0000000\t0x70000000\tMIPS64 \n>>>>48\tbelong&0xf0000000\t0x80000000\tMIPS32 rel2\n>>>>48\tbelong&0xf0000000\t0x90000000\tMIPS64 rel2\n>>16\tbeshort\t\t0\t\tno file type,\n>>16\tbeshort\t\t1\t\trelocatable,\n>>16\tbeshort\t\t2\t\texecutable,\n>>16\tbeshort\t\t3\t\tshared object,\n>>16\tbeshort\t\t4\t\tcore file,\n#>>>(0x38+0xcc) string\t>\\0\t\tof '%s'\n#>>>(0x38+0x10) belong\t>0\t\t(signal %d),\n>>16\tbeshort\t\t&0xff00\t\tprocessor-specific,\n>>18\tbeshort\t\t0\t\tno machine,\n>>18\tbeshort\t\t1\t\tAT&T WE32100,\n>>18\tbeshort\t\t2\t\tSPARC,\n>>18\tbeshort\t\t3\t\tIntel 80386 - invalid byte order,\n>>18\tbeshort\t\t4\t\tMotorola\n>>>36\tbelong\t\t&0x01000000\t68000,\n>>>36\tbelong\t\t&0x00810000\tCPU32,\n>>>36\tbelong\t\t0\t\t68020,\n>>18\tbeshort\t\t5\t\tMotorola 88000,\n>>18\tbeshort\t\t6\t\tIntel 80486 - invalid byte order,\n>>18\tbeshort\t\t7\t\tIntel 80860,\n>>18\tbeshort\t\t8\t\tMIPS,\n>>18\tbeshort\t\t9\t\tAmdahl,\n>>18\tbeshort\t\t10\t\tMIPS (deprecated),\n>>18\tbeshort\t\t11\t\tRS6000,\n>>18\tbeshort\t\t15\t\tPA-RISC\n>>>50\tbeshort\t\t0x0214\t\t2.0\n>>>48\tbeshort\t\t&0x0008\t\t(LP64)\n>>18\tbeshort\t\t16\t\tnCUBE,\n>>18\tbeshort\t\t17\t\tFujitsu VPP500,\n>>18\tbeshort\t\t18\t\tSPARC32PLUS,\n>>>36\tbelong&0xffff00\t&0x000100\tV8+ Required,\n>>>36\tbelong&0xffff00\t&0x000200\tSun UltraSPARC1 Extensions Required,\n>>>36\tbelong&0xffff00\t&0x000400\tHaL R1 Extensions Required,\n>>>36\tbelong&0xffff00\t&0x000800\tSun UltraSPARC3 Extensions Required,\n>>18\tbeshort\t\t20\t\tPowerPC or cisco 4500,\n>>18\tbeshort\t\t21\t\tcisco 7500,\n>>18\tbeshort\t\t22\t\tIBM S/390,\n>>18\tbeshort\t\t24\t\tcisco SVIP,\n>>18\tbeshort\t\t25\t\tcisco 7200,\n>>18\tbeshort\t\t36\t\tNEC V800 or cisco 12000,\n>>18\tbeshort\t\t37\t\tFujitsu FR20,\n>>18\tbeshort\t\t38\t\tTRW RH-32,\n>>18\tbeshort\t\t39\t\tMotorola RCE,\n>>18\tbeshort\t\t40\t\tARM,\n>>18\tbeshort\t\t41\t\tAlpha,\n>>18\tbeshort\t\t42\t\tHitachi SH,\n>>18\tbeshort\t\t43\t\tSPARC V9,\n>>18\tbeshort\t\t44\t\tSiemens Tricore Embedded Processor,\n>>18\tbeshort\t\t45\t\tArgonaut RISC Core, Argonaut Technologies Inc.,\n>>18\tbeshort\t\t46\t\tHitachi H8/300,\n>>18\tbeshort\t\t47\t\tHitachi H8/300H,\n>>18\tbeshort\t\t48\t\tHitachi H8S,\n>>18\tbeshort\t\t49\t\tHitachi H8/500,\n>>18\tbeshort\t\t50\t\tIntel Merced Processor,\n>>18\tbeshort\t\t51\t\tStanford MIPS-X,\n>>18\tbeshort\t\t52\t\tMotorola Coldfire,\n>>18\tbeshort\t\t53\t\tMotorola M68HC12,\n>>18\tbeshort\t\t73\t\tCray NV1,\n>>18\tbeshort\t\t75\t\tDigital VAX,\n>>18\tbeshort\t\t97\t\tNatSemi 32k,\n>>18\tbeshort\t\t0x9026\t\tAlpha (unofficial),\n>>18\tbeshort\t\t0xa390\t\tIBM S/390 (obsolete),\n>>18    beshort         0xde3d          Ubicom32,\n>>20\tbelong\t\t0\t\tinvalid version\n>>20\tbelong\t\t1\t\tversion 1\n>>36\tbelong\t\t1\t\tMathCoPro/FPU/MAU Required\n# Up to now only 0, 1 and 2 are defined; I've seen a file with 0x83, it seemed\n# like proper ELF, but extracting the string had bad results.\n>4      byte            <0x80\n>>8\tstring\t\t>\\0\t\t(\"%s\")\n>8\tstring\t\t\\0\n>>7\tbyte\t\t0\t\t(SYSV)\n>>7\tbyte\t\t1\t\t(HP-UX)\n>>7\tbyte\t\t2\t\t(NetBSD)\n>>7\tbyte\t\t3\t\t(GNU/Linux)\n>>7\tbyte\t\t4\t\t(GNU/Hurd)\n>>7\tbyte\t\t5\t\t(86Open)\n>>7\tbyte\t\t6\t\t(Solaris)\n>>7\tbyte\t\t7\t\t(Monterey)\n>>7\tbyte\t\t8\t\t(IRIX)\n>>7\tbyte\t\t9\t\t(FreeBSD)\n>>7\tbyte\t\t10\t\t(Tru64)\n>>7\tbyte\t\t11\t\t(Novell Modesto)\n>>7\tbyte\t\t12\t\t(OpenBSD)\n>>7\tbyte\t\t97\t\t(ARM)\n>>7\tbyte\t\t255\t\t(embedded)\n\n# XXX - according to Microsoft's spec, at an offset of 0x3c in a\n# PE-format executable is the offset in the file of the PE header;\n# unfortunately, that's a little-endian offset, and there's no way\n# to specify an indirect offset with a specified byte order.\n# So, for now, we assume the standard MS-DOS stub, which puts the\n# PE header at 0x80 = 128.\n#\n# Required OS version and subsystem version were 4.0 on some NT 3.51\n# executables built with Visual C++ 4.0, so it's not clear that\n# they're interesting.  The user version was 0.0, but there's\n# probably some linker directive to set it.  The linker version was\n# 3.0, except for one \".exe\" which had it as 4.20 (same damn linker!).\n#\n# many of the compressed formats were extraced from IDARC 1.23 source code\n#\n0       string  MZ\tMicrosoft\n>0x18  leshort <0x40 MS-DOS executable\n>0 string MZ\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0PE\\0\\0 \\b, PE for MS Windows\n>>&18   leshort&0x2000  >0      (DLL)\n>>&88   leshort         0       (unknown subsystem)\n>>&88   leshort         1       (native)\n>>&88   leshort         2       (GUI)\n>>&88   leshort         3       (console)\n>>&88   leshort         7       (POSIX)\n>>&0    leshort         0x0     unknown processor\n>>&0    leshort         0x14c   Intel 80386\n>>&0    leshort         0x166   MIPS R4000\n>>&0    leshort         0x184   Alpha\n>>&0    leshort         0x268   Motorola 68000\n>>&0    leshort         0x1f0   PowerPC\n>>&0    leshort         0x290   PA-RISC\n>>&18   leshort&0x0100  >0      32-bit\n>>&18   leshort&0x1000  >0      system file\n>>&228  lelong          >0      \\b, Mono/.Net assembly\n>>&0xf4 search/0x140 \\x0\\x40\\x1\\x0\n>>>(&0.l+(4)) string MSCF \\b, WinHKI CAB self-extracting archive\n>30             string  Copyright\\x201989-1990\\x20PKWARE\\x20Inc.      Self-extracting PKZIP archive\n# Is next line correct? One might expect \"Corp.\" not \"Copr.\" If it is right, add a note to that effect.\n>30             string  PKLITE\\x20Copr.   Self-extracting PKZIP archive\n\n>0x18  leshort >0x3f\n>>(0x3c.l) string PE\\0\\0 PE\n>>>(0x3c.l+25) byte             1 \\b32 executable\n>>>(0x3c.l+25) byte             2 \\b32+ executable\n# hooray, there's a DOS extender using the PE format, with a valid PE\n# executable inside (which just prints a message and exits if run in win)\n>>>(0x3c.l+92)  leshort         <10\n>>>>(8.s*16) string 32STUB for MS-DOS, 32rtm DOS extender\n>>>>(8.s*16) string !32STUB for MS Windows\n>>>>>(0x3c.l+22)        leshort&0x2000  >0      (DLL)\n>>>>>(0x3c.l+92)        leshort         0       (unknown subsystem)\n>>>>>(0x3c.l+92)        leshort         1       (native)\n>>>>>(0x3c.l+92)        leshort         2       (GUI)\n>>>>>(0x3c.l+92)        leshort         3       (console)\n>>>>>(0x3c.l+92)        leshort         7       (POSIX)\n>>>(0x3c.l+92)  leshort         10      (EFI application)\n>>>(0x3c.l+92)  leshort         11      (EFI boot service driver)\n>>>(0x3c.l+92)  leshort         12      (EFI runtime driver)\n>>>(0x3c.l+92)  leshort         13      (XBOX)\n>>>(0x3c.l+4)   leshort         0x0     unknown processor\n>>>(0x3c.l+4)   leshort         0x14c   Intel 80386\n>>>(0x3c.l+4)   leshort         0x166   MIPS R4000\n>>>(0x3c.l+4)   leshort         0x184   Alpha\n>>>(0x3c.l+4)   leshort         0x268   Motorola 68000\n>>>(0x3c.l+4)   leshort         0x1f0   PowerPC\n>>>(0x3c.l+4)   leshort         0x290   PA-RISC\n>>>(0x3c.l+4)   leshort         0x200   Intel Itanium\n>>>(0x3c.l+22)  leshort&0x0100  >0      32-bit\n>>>(0x3c.l+22)  leshort&0x1000  >0      system file\n>>>(0x3c.l+232) lelong  >0      Mono/.Net assembly\n>>>>(0x3c.l+0xf8)       string          UPX0 \\b, UPX compressed\n>>>>(0x3c.l+0xf8)       search/0x140    PEC2 \\b, PECompact2 compressed\n>>>>(0x3c.l+0xf8)       search/0x140    UPX2\n>>>>>(&0x10.l+(-4))     string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>(0x3c.l+0xf8)       search/0x140    .idata\n>>>>>(&0xe.l+(-4))      string          PK\\3\\4 \\b, ZIP self-extracting archive (Info-Zip)\n>>>>>(&0xe.l+(-4))      string          ZZ0 \\b, ZZip self-extracting archive\n>>>>>(&0xe.l+(-4))      string          ZZ1 \\b, ZZip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .rsrc\n>>>>>(&0x0f.l+(-4))     string          a\\\\\\4\\5 \\b, WinHKI self-extracting archive\n>>>>>(&0x0f.l+(-4))     string          Rar! \\b, RAR self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/0x3000   MSCF \\b, InstallShield self-extracting archive\n>>>>>(&0x0f.l+(-4))     search/32       Nullsoft \\b, Nullsoft Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .data\n>>>>>(&0x0f.l)          string          WEXTRACT \\b, MS CAB-Installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .petite\\0 \\b, Petite compressed\n>>>>>(0x3c.l+0xf7)      byte            x\n>>>>>>(&0x104.l+(-4))   string          =!sfx! \\b, ACE self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .WISE \\b, WISE installer self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .dz\\0\\0\\0 \\b, Dzip self-extracting archive\n>>>>(0x3c.l+0xf8)       search/0x140    .reloc\n>>>>>(&0xe.l+(-4))      search/0x180    PK\\3\\4 \\b, ZIP self-extracting archive (WinZip)\n\n>>>>&(0x3c.l+0xf8)      search/0x100    _winzip_ \\b, ZIP self-extracting archive (WinZip)\n>>>>&(0x3c.l+0xf8)      search/0x100    SharedD \\b, Microsoft Installer self-extracting archive\n>>>>0x30                string          Inno \\b, InnoSetup self-extracting archive\n\n>>(0x3c.l) string !PE\\0\\0 MS-DOS executable\n\n>>(0x3c.l)              string          NE \\b, NE\n>>>(0x3c.l+0x36)        byte            0 (unknown OS)\n>>>(0x3c.l+0x36)        byte            1 for OS/2 1.x\n>>>(0x3c.l+0x36)        byte            2 for MS Windows 3.x\n>>>(0x3c.l+0x36)        byte            3 for MS-DOS\n>>>(0x3c.l+0x36)        byte            >3 (unknown OS)\n>>>(0x3c.l+0x36)        byte            0x81 for MS-DOS, Phar Lap DOS extender\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8002 (DLL)\n>>>(0x3c.l+0x0c)        leshort&0x8003  0x8001 (driver)\n>>>&(&0x24.s-1)         string          ARJSFX \\b, ARJ self-extracting archive\n>>>(0x3c.l+0x70)        search/0x80     WinZip(R)\\x20Self-Extractor \\b, ZIP self-extracting archive (WinZip)\n\n>>(0x3c.l)              string          LX\\0\\0 \\b, LX\n>>>(0x3c.l+0x0a)        leshort         <1 (unknown OS)\n>>>(0x3c.l+0x0a)        leshort         1 for OS/2\n>>>(0x3c.l+0x0a)        leshort         2 for MS Windows\n>>>(0x3c.l+0x0a)        leshort         3 for DOS\n>>>(0x3c.l+0x0a)        leshort         >3 (unknown OS)\n>>>(0x3c.l+0x10)        lelong&0x28000  =0x8000 (DLL)\n>>>(0x3c.l+0x10)        lelong&0x20000  >0 (device driver)\n>>>(0x3c.l+0x10)        lelong&0x300    0x300 (GUI)\n>>>(0x3c.l+0x10)        lelong&0x28300  <0x300 (console)\n>>>(0x3c.l+0x08)        leshort         1 i80286\n>>>(0x3c.l+0x08)        leshort         2 i80386\n>>>(0x3c.l+0x08)        leshort         3 i80486\n>>>(8.s*16)             string          emx \\b, emx\n>>>>&1                  string          x \"%s\"\n>>>&(&0x54.l-3)         string          arjsfx \\b, ARJ self-extracting archive\n\n\n\n#------------------------------------------------------------------------------\n# bFLT: file(1) magic for BFLT uclinux binary files\n#\n# From Philippe De Muyter <phdm@macqel.be>\n# \n# Additional fields added by Craig Heffner\n#\n0       string          bFLT            BFLT executable \n>4      belong          x               version %ld, \n>4      belong          4\n>8\tbelong\t\tx\t\tcode offset: 0x%.8X, \n>12\tbelong\t\tx\t\tdata segment starts at: 0x%.8X, \n>16\tbelong\t\tx\t\tbss segment starts at: 0x%.8X, \n>20\tbelong\t\tx\t\tbss segment ends at: 0x%.8X, \n>24\tbelong\t\tx\t\tstack size: %d bytes, \n>28\tbelong \t\tx\t\trelocation records start at: 0x%.8X, \n>32\tbelong\t\tx\t\tnumber of reolcation records: %d, \n>>36    belong&0x1      0x1             ram\n>>36    belong&0x2      0x2             gotpic\n>>36    belong&0x4      0x4             gzip\n>>36    belong&0x8      0x8             gzdata\n\n\n#-----------------------------------------------------------------\n# MIPS COFF file formats\n#\n0       beshort 0x0160          MIPSEB ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x0162          MIPSEL-BE ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x6001          MIPSEB-LE ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %d\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x6201          MIPSEL ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n# MIPS 2 additions\n#\n0       beshort 0x0163          MIPSEB MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x0166          MIPSEL-BE MIPS-II ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x6301          MIPSEB-LE MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x6601          MIPSEL MIPS-II ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n# MIPS 3 additions\n#\n0       beshort 0x0140          MIPSEB MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x0142          MIPSEL-BE MIPS-III ECOFF executable\n>20     beshort 0407            (impure)\n>20     beshort 0410            (swapped)\n>20     beshort 0413            (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>22     byte    x               - version %ld\n>23     byte    x               \\b.%ld\n#\n0       beshort 0x4001          MIPSEB-LE MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x4201          MIPSEL MIPS-III ECOFF executable\n>20     beshort 03401           (impure)\n>20     beshort 04001           (swapped)\n>20     beshort 05401           (paged)\n>8      belong  >0              not stripped\n>8      belong  0               stripped\n>23     byte    x               - version %ld\n>22     byte    x               \\b.%ld\n#\n0       beshort 0x180           MIPSEB Ucode\n0       beshort 0x182           MIPSEL-BE Ucode\n\n\n# Windows CE package files\n0       string          MSCE\\0\\0\\0\\0    Microsoft WinCE installer\n>20     lelong          0               \\b, architecture-independent\n>20     lelong          103             \\b, Hitachi SH3\n>20     lelong          104             \\b, Hitachi SH4\n>20     lelong          0xA11           \\b, StrongARM\n>20     lelong          4000            \\b, MIPS R4000\n>20     lelong          10003           \\b, Hitachi SH3\n>20     lelong          10004           \\b, Hitachi SH3E\n>20     lelong          10005           \\b, Hitachi SH4\n>20     lelong          70001           \\b, ARM 7TDMI\n>52     leshort         1               \\b, 1 file\n>52     leshort         >1              \\b, %u files\n>56     leshort         1               \\b, 1 registry entry\n>56     leshort         >1              \\b, %u registry entries\n\n#------------------------------------------------------------------------------\n# Microsoft Xbox executables .xbe (Esa HyytiÃ¤ <ehyytia@cc.hut.fi>)\n0       string          XBEH            XBE, Microsoft Xbox executable\n# probabilistic checks whether signed or not\n>0x0004 ulelong =0x0\n>>&2    ulelong =0x0\n>>>&2   ulelong =0x0  \\b, not signed\n>0x0004 ulelong >0\n>>&2    ulelong >0\n>>>&2   ulelong >0    \\b, signed\n# expect base address of 0x10000\n>0x0104               ulelong =0x10000\n>>(0x0118-0x0FF60)    ulelong&0x80000007  0x80000007 \\b, all regions\n>>(0x0118-0x0FF60)    ulelong&0x80000007  !0x80000007\n>>>(0x0118-0x0FF60)   ulelong >0           (regions:\n>>>>(0x0118-0x0FF60)  ulelong &0x00000001  NA\n>>>>(0x0118-0x0FF60)  ulelong &0x00000002  Japan\n>>>>(0x0118-0x0FF60)  ulelong &0x00000004  Rest_of_World\n>>>>(0x0118-0x0FF60)  ulelong &0x80000000  Manufacturer\n>>>(0x0118-0x0FF60)   ulelong >0           \\b)\n\n#------------------------------------------------------------------------------\n# motorola:  file(1) magic for Motorola 68K and 88K binaries\n#\n# 68K\n#\n0       beshort         0x0208          mc68k COFF\n>18     beshort         ^00000020       object\n>18     beshort         &00000020       executable\n>12     belong          >0              not stripped\n>168    string          .lowmem         Apple toolbox\n>20     beshort         0407            (impure)\n>20     beshort         0410            (pure)\n>20     beshort         0413            (demand paged)\n>20     beshort         0421            (standalone)\n0       beshort         0x0209          mc68k executable (shared)\n>12     belong          >0              not stripped\n0       beshort         0x020A          mc68k executable (shared demand paged)\n>12     belong          >0              not stripped\n\n\n#\n# Motorola/UniSoft 68K Binary Compatibility Standard (BCS)\n#\n0       beshort         0x022A            68K BCS executable\n#\n# 88K\n#\n# Motorola/88Open BCS\n#\n0       beshort         0x022B            88K BCS executable\n\n#------------------------------------------------------------------------------\n# Sony Playstation executables (Adam Sjoegren <asjo@diku.dk>) :\n0       string  PS-X\\x20EXE       Sony Playstation executable\n#  Area:\n>113    string  x               (\"%s\")\n\n#------------------------------------------------------------------------------\n# cisco:  file(1) magic for cisco Systems routers\n#\n# Most cisco file-formats are covered by the generic elf code\n#\n# Microcode files are non-ELF, 0x8501 conflicts with NetBSD/alpha.\n0\tbeshort\t\t\t0x8501\t    cisco IOS\n>0      belong&0xffffff00       0x85011400  microcode\n>0      belong&0xffffff00       0x8501cb00  experimental microcode\n>7      string          \t>\\0         for \"%s\"\n\n# EST flat binary format (which isn't, but anyway)\n# From: Mark Brown <broonie@sirena.org.uk>\n0\tstring\tESTFBINR\tEST flat binary\n\n# These are not the binaries themselves, but string references to them\n# are a strong indication that they exist elsewhere...\n#0\tstring\t/bin/busybox\tBusybox string reference: \"%s\"{one-of-many}\n#0\tstring /bin/sh\t\tShell string reference: \"%s\"{one-of-many}\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/filesystems",
    "content": "#--------------------File Systems---------------------\n\n# Minix filesystems - Juan Cespedes <cespedes@debian.org>\n0x410   leshort         0x137f          Minix filesystem\n>0x402  beshort         !0              \\b, %d zones\n>0x1e   string          minix           \\b, bootable\n0x410   leshort         0x138f          Minix filesystem, 30 char names\n0x410   leshort         0x2468          Minix filesystem, version 2\n0x410   leshort         0x2478          Minix filesystem, version 2, 30 char names\n0x410\tleshort\t\t0x4d5a\t\tMinix filesystem, version 3\n0x410\tleshort\t\t0x4d6a\t\tMinix filesystem, version 3, 30 char names\n\n0x410   beshort         0x137f          Minix filesystem (big endian)\n>0x402  beshort         !0              \\b, %d zones\n>0x1e   string          minix           \\b, bootable\n0x410   beshort         0x138f          Minix filesystem (big endian), 30 char names\n0x410   beshort         0x2468          Minix filesystem (big endian), version 2\n0x410   beshort         0x2478          Minix filesystem (big endian), version 2, 30 char names\n0x410\tbeshort\t\t0x4d5a\t\tMinix filesystem (big endian), version 3\n0x410\tbeshort\t\t0x4d6a\t\tMinix filesystem (big endian), version 3, 30 char names\n\n# YAFFS\n0\tstring\t\\x03\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\xFF\\xFF\tYAFFS filesystem\n\n# EFS2 file system - jojo@utulsa.edu\n0      lelong 0x53000000       EFS2 Qualcomm filesystem super block, little endian,\n>8     string !EFSSuper        invalid,\n>4     leshort &1              NAND\n>4     leshort ^1              NOR\n>4     leshort x               version 0x%x,\n>24    lelong  x               %d blocks,\n>16    lelong  x               0x%x pages per block,\n>20    lelong  x               0x%x bytes per page\n\n0      belong 0x53000000       EFS2 Qualcomm filesystem super block, big endian,\n>8     string !SSFErepu\t       invalid,\n>4     beshort &1              NAND\n>4     beshort ^1              NOR\n>4     beshort x               version 0x%x,\n>24    belong  x               %d blocks,\n>16    belong  x               0x%x pages per block,\n>20    belong  x               0x%x bytes per page\n\n# TROC file system\n0\tstring\tTROC\t\tTROC filesystem,\n>4\tlelong\tx\t\t%d file entries\n\n# PFS file system\n0\tstring\tPFS/\t\tPFS filesystem,\n>4\tstring\tx\t\tversion \"%s\",\n>14\tleshort\tx\t\t%d files\n\n# MPFS file system\n0\tstring\tMPFS\t\tMPFS (Microchip) filesystem,\n>4\tbyte\tx\t\tversion %d.\n>5\tbyte\tx\t\t\\b%d,\n>6\tleshort\tx\t\t%d file entries\n\n# cramfs filesystem - russell@coker.com.au\n0       lelong  0x28cd3d45      CramFS filesystem, little endian\n>4\tlelong\t<0\t\tinvalid\n>4      lelong  x \t\tsize %lu\n>8      lelong  &1 \t\tversion #2\n>8      lelong  &2 \t\tsorted_dirs\n>8      lelong  &4 \t\thole_support\n>32     lelong  x \t\tCRC 0x%x,\n>36     lelong  x \t\tedition %lu,\n>40\tlelong\t<0\t\tinvalid\n>40     lelong  x \t\t%lu blocks,\n>44\tlelong\t<0\t\tinvalid\n>44     lelong  x \t\t%lu files\n>4      lelong  x \t\t{jump-to-offset:%lu}\n>4      lelong  x \t\t{file-size:%lu}\n\n0       belong  0x28cd3d45      CramFS filesystem, big endian\n>4\tbelong\t<0\t\tinvalid\n>4      belong  x \t\tsize %lu\n>8      belong  &1 \t\tversion #2\n>8      belong  &2 \t\tsorted_dirs\n>8      belong  &4 \t\thole_support\n>32     belong  x \t\tCRC 0x%x,\n>36     belong  x \t\tedition %lu,\n>40\tbelong\t<0\t\tinvalid\n>40     belong  x \t\t%lu blocks,\n>44\tbelong\t<0\t\tinvalid\n>44     belong  x \t\t%lu files\n>4      belong  x \t\t{jump-to-offset:%lu}\n>4      belong  x \t\t{file-size:%lu}\n\n\n\n# JFFS2 file system\n# If used with binwalk's smart signature feature (on by default, -S to disable)\n# this signature can potentially lead to missing some JFFS2 file systems if there\n# are multiple JFFS2 file systems in a target file and there are no other identified\n# files in between the JFFS2 file systems. This is an unlikely scenario however, and\n# the below signatures are much improved in terms of readability and accuracy in the\n# vast majority of real world scenarios.\n0\t\tleshort 0x1985\tJFFS2 filesystem, little endian{filter-include}\n>2\t\tleshort !0xE001\n>>2\t\tleshort !0xE002\n>>>2\t\tleshort !0x2003\n>>>>2\t\tleshort !0x2004\n>>>>>2\t\tleshort !0x2006\n>>>>>>2\t\tleshort !0xE008\n>>>>>>>2\tleshort !0xE009\t\\b, invalid\n>(4.l)\t\tleshort !0x1985\t\t\n>>(4.l+1)\tleshort !0x1985\t\n>>>(4.l+2)\tleshort !0x1985\t\n>>>>(4.l+3)\tleshort !0x1985\n>>>>>(4.l)      leshort !0xFFFF\n>>>>>>(4.l+1)   leshort !0xFFFF\n>>>>>>>(4.l+2)  leshort !0xFFFF\n>>>>>>>>(4.l+3) leshort !0xFFFF \\b, invalid\n>4\t\tlelong\tx\t{one-of-many}{jump-to-offset:%d}\n\n0       \tbeshort 0x1985\tJFFS2 filesystem, big endian{filter-include}\n>2\t\tbeshort !0xE001\n>>2\t\tbeshort !0xE002\n>>>2\t\tbeshort !0x2003\n>>>>2\t\tbeshort !0x2004\n>>>>>2\t\tbeshort !0x2006\n>>>>>>2\t\tbeshort !0xE008\n>>>>>>>2\tbeshort !0xE009\t\\b, invalid\n>(4.L)\t\tbeshort\t!0x1985\t \n>>(4.L+1)\tbeshort\t!0x1985\t \n>>>(4.L+2)\tbeshort\t!0x1985\n>>>>(4.L+3)\tbeshort\t!0x1985\t\n>>>>>(4.L)\tbeshort !0xFFFF\n>>>>>>(4.L+1)\tbeshort !0xFFFF\n>>>>>>>(4.L+2)\tbeshort !0xFFFF\n>>>>>>>>(4.L+3)\tbeshort !0xFFFF \\b, invalid\n>4\t\tbelong\tx\t{one-of-many}{jump-to-offset:%d}\n\n\n# Squashfs, big endian\n0       string  sqsh    Squashfs filesystem, big endian,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28\tbeshort <3\n>>8\tbelong\tx\t{jump-to-offset:%d}\n>28\tbeshort\t3\t\n>>63\tbequad\tx\t{jump-to-offset:%lld}\n>28\tbeshort\t>3\n>>40\tbequad\tx\t{jump-to-offset:%lld}\n\n# Squashfs, little endian\n0       string  hsqs    Squashfs filesystem, little endian,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>30\tleshort >10\tinvalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28\tleshort >3\tcompression: \n>>20\tleshort 1\t\\bgzip,\n>>20\tleshort\t2\t\\blzma,\n>>20\tleshort 0\t\\binvalid,\n>>20\tleshort >4\t\\binvalid,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>>8     lelong  x       {file-size:%d}\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>>63    lequad x        {file-size:%lld}\n>28\tleshort >3\t\n>>40\tlequad\tx\tsize: %lld bytes,\n>>40\tlequad\tx\t{file-size:%lld}\n>4      lelong  x       %d inodes,\n>28\tleshort >3\n>>12\tlelong\t\tblocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28\tleshort 3\n>>51\tlelong \tx\tblocksize: %d bytes,\n>28\tleshort\t>3\t\n>>12\tlelong\tx\tblocksize: %d bytes,\n>28\tleshort <4\n>>39    ledate  x\tcreated: %s\n>28\tleshort >3\n>>8\tledate x\tcreated: %s\n>28     leshort <3\n>>8     lelong  x       {jump-to-offset:%d}\n>28     leshort 3\n>>63    lequad x        {jump-to-offset:%lld}\n>28     leshort >3\n>>40    lequad  x       {jump-to-offset:%lld}\n\n# Squashfs with LZMA compression\n0       string  sqlz    Squashfs filesystem, big endian, lzma compression, \n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>>8     belong  x       {file-size:%d}\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>>63    bequad x        {file-size:%lld}\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>>40    bequad  x       {file-size:%lld}\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28     beshort <3\n>>8     belong  x       {jump-to-offset:%d}\n>28     beshort 3\n>>63    bequad  x       {jump-to-offset:%lld}\n>28     beshort >3\n>>40    bequad  x       {jump-to-offset:%lld}\n\n# Squashfs 3.3 LZMA signature\n0       string  qshs    Squashfs filesystem, big endian, lzma signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>>8     belong  x       {file-size:%d}\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>>63    bequad x        {file-size:%lld}\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>>40    bequad  x       {file-size:%lld}\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28     beshort <3\n>>8     belong  x       {jump-to-offset:%d}\n>28     beshort 3\n>>63    bequad  x       {jump-to-offset:%lld}\n>28     beshort >3\n>>40    bequad  x       {jump-to-offset:%lld}\n\n# Squashfs for DD-WRT\n0       string  tqsh    Squashfs filesystem, big endian, DD-WRT signature,\n>28     beshort >10     invalid\n>28     beshort <1      invalid\n>30\tbeshort >10\tinvalid\n>28     beshort x       version %d.\n>30     beshort x       \\b%d,\n>28     beshort >3      compression:\n>>20    beshort 1       \\bgzip,\n>>20    beshort 2       \\blzma,\n>>20    beshort 0       \\binvalid,\n>>20    beshort >4      \\binvalid,\n>28     beshort <3\n>>8     belong  x       size: %d bytes,\n>>8     belong  x       {file-size:%d}\n>28     beshort 3\n>>63    bequad x        size: %lld bytes,\n>>63    bequad x        {file-size:%lld}\n>28     beshort >3\n>>40    bequad  x       size: %lld bytes,\n>>40    bequad  x       {file-size:%lld}\n>4      belong  x       %d inodes,\n>28     beshort >3\n>>12    belong          blocksize: %d bytes,\n>28     beshort <2\n>>32    beshort x       blocksize: %d bytes,\n>28     beshort 2\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort 3\n>>51    belong  x       blocksize: %d bytes,\n>28     beshort >3\n>>12    belong  x       blocksize: %d bytes,\n>28     beshort <4\n>>39    bedate  x       created: %s\n>28     beshort >3\n>>8     bedate x        created: %s\n>28     beshort <3\n>>8     belong  x       {jump-to-offset:%d}\n>28     beshort 3\n>>63    bequad  x       {jump-to-offset:%lld}\n>28     beshort >3\n>>40    bequad  x       {jump-to-offset:%lld}\n\n# Squashfs for DD-WRT\n0       string  hsqt    Squashfs filesystem, little endian, DD-WRT signature,\n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>30\tleshort >10\tinvalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort >3      compression:\n>>20    leshort 1       \\bgzip,\n>>20    leshort 2       \\blzma,\n>>20    leshort 0       \\binvalid,\n>>20    leshort >4      \\binvalid,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>>8     lelong  x       {file-size:%d}\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>>63    lequad x        {file-size:%lld}\n>28     leshort >3\n>>40    lequad  x       size: %lld bytes,\n>>40    lequad  x       {file-size:%lld}\n>4      lelong  x       %d inodes,\n>28     leshort >3\n>>12    lelong          blocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort 3\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort >3\n>>12    lelong  x       blocksize: %d bytes,\n>28     leshort <4\n>>39    ledate  x       created: %s\n>28     leshort >3\n>>8     ledate x        created: %s\n>28     leshort <3\n>>8     lelong  x       {jump-to-offset:%d}\n>28     leshort 3\n>>63    lequad x        {jump-to-offset:%lld}\n>28     leshort >3\n>>40    lequad  x       {jump-to-offset:%lld}\n\n# Non-standard Squashfs signature found on some D-Link routers\n0       string  shsq    Squashfs filesystem, little endian, non-standard signature, \n>28     leshort >10     invalid\n>28     leshort <1      invalid\n>30\tleshort >10\tinvalid\n>28     leshort x       version %d.\n>30     leshort x       \\b%d,\n>28     leshort >3      compression:\n>>20    leshort 1       \\bgzip,\n>>20    leshort 2       \\blzma,\n>>20    leshort 0       \\binvalid,\n>>20    leshort >4      \\binvalid,\n>28     leshort <3\n>>8     lelong  x       size: %d bytes,\n>>8     lelong  x       {file-size:%d}\n>28     leshort 3\n>>63    lequad x        size: %lld bytes,\n>>63    lequad x        {file-size:%lld}\n>28     leshort >3\n>>40    lequad  x       size: %lld bytes,\n>>40    lequad  x       {file-size:%lld}\n>4      lelong  x       %d inodes,\n>28     leshort >3\n>>12    lelong          blocksize: %d bytes,\n>28     leshort <2\n>>32    leshort x       blocksize: %d bytes,\n>28     leshort 2\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort 3\n>>51    lelong  x       blocksize: %d bytes,\n>28     leshort >3\n>>12    lelong  x       blocksize: %d bytes,\n>28     leshort <4\n>>39    ledate  x       created: %s\n>28     leshort >3\n>>8     ledate x        created: %s\n>28     leshort <3\n>>8     lelong  x       {jump-to-offset:%d}\n>28     leshort 3\n>>63    lequad x        {jump-to-offset:%lld}\n>28     leshort >3\n>>40    lequad  x       {jump-to-offset:%lld}\n\n# ext2/ext3 filesystems - Andreas Dilger <adilger@dilger.ca>\n# ext4 filesystem - Eric Sandeen <sandeen@sandeen.net>\n# volume label and UUID Russell Coker\n# http://etbe.coker.com.au/2008/07/08/label-vs-uuid-vs-device/\n0   leshort         0xEF53      \tLinux EXT filesystem,{filter-include}{offset-adjust:-0x438}\n>2\tleshort\t\t>4\t\tinvalid state\n>2\tleshort\t\t3\t\tinvalid state\n>2\tleshort\t\t<0\t\tinvalid state\n>4\tleshort\t\t>3\t\tinvalid error behavior\n>4\tleshort\t\t<0\t\tinvalid error behavior\n>4\tlelong\t\t>1\t\tinvalid major revision\n>4  lelong\t\t<0\t\tinvalid major revision\n>4  lelong          x               rev %d\n>6  leshort         x               \\b.%d\n# No journal?  ext2\n>36  lelong          ^0x0000004      ext2 filesystem data\n>>2 leshort         ^0x0000001      (mounted or unclean)\n# Has a journal?  ext3 or ext4\n>36  lelong          &0x0000004\n#  and small INCOMPAT?\n>>40 lelong          <0x0000040\n#   and small RO_COMPAT?\n>>>44 lelong         <0x0000008      ext3 filesystem data\n#   else large RO_COMPAT?\n>>>44 lelong         >0x0000007      ext4 filesystem data\n#  else large INCOMPAT?\n>>40 lelong          >0x000003f      ext4 filesystem data\n>48  belong          x               \\b, UUID=%08x\n>52  beshort         x               \\b-%04x\n>54  beshort         x               \\b-%04x\n>56  beshort         x               \\b-%04x\n>58  belong          x               \\b-%08x\n>60  beshort         x               \\b%04x\n>64  string          >0              \\b, volume name \"%s\"\n\n\n#romfs filesystems - Juan Cespedes <cespedes@debian.org>\n0       string\t-rom1fs-\\0\t\tromfs filesystem, version 1\n>8\tbelong\t>10000000\t\tinvalid\n>8      belong  x                       size: %d bytes,\n>16\tstring\tx\t\t\t{file-name:%s}\n>16     string  x                       named \"%s\"\n>8\tbelong\tx\t\t\t{file-size:%d}\n>8\tbelong\tx\t\t\t{jump-to-offset:%d}\n\n# Wind River MemFS file system, found in some VxWorks devices\n0\tstring\towowowowowowowowowowowowowowow\t\tWind River management filesystem,\n>30\tstring\t!ow\t\t\t\t\tinvalid,\n>32\tbelong\t1\t\t\t\t\tcompressed,\n>32\tbelong\t2\t\t\t\t\tplain text,\n>36\tbelong\tx\t\t\t\t\t%d files\n\n\n# netboot image - Juan Cespedes <cespedes@debian.org>\n0\tlelong\t\t\t0x1b031336L\tNetboot image,\n>4\tlelong&0xFFFFFF00\t0\n>>4\tlelong&0x100\t\t0x000\t\tmode 2\n>>4\tlelong&0x100\t\t0x100\t\tmode 3\n>4\tlelong&0xFFFFFF00\t!0\t\tunknown mode (invalid)\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/firmware",
    "content": "\n#--------------------------Firmware Formats---------------------------\n\n# uImage file     \n# From: Craig Heffner, U-Boot image.h header definitions file\n0\tbelong\t0x27051956\tuImage header, header size: 64 bytes,\n>4\tbelong\tx\t\theader CRC: 0x%X,\n>8\tbedate\tx\t\tcreated: %s,\n>12\tbelong\tx\t\timage size: %d bytes,\n>16\tbelong\tx\t\tData Address: 0x%X,\n>20\tbelong\tx\t\tEntry Point: 0x%X,\n>24\tbelong\tx\t\tdata CRC: 0x%X,\n#>28\tbyte\tx\t\tOS type: %d,\n>28\tbyte\t0\t\tOS: invalid OS,\n>28\tbyte\t1\t\tOS: OpenBSD,\n>28\tbyte\t2\t\tOS: NetBSD,\n>28\tbyte\t3\t\tOS: FreeBSD,\n>28\tbyte\t4\t\tOS: 4.4BSD,\n>28\tbyte\t5\t\tOS: Linux,\n>28\tbyte\t6\t\tOS: SVR4,\n>28\tbyte\t7\t\tOS: Esix,\n>28\tbyte\t8\t\tOS: Solaris,\n>28\tbyte\t9\t\tOS: Irix,\n>28\tbyte\t10\t\tOS: SCO,\n>28\tbyte\t11\t\tOS: Dell,\n>28\tbyte\t12\t\tOS: NCR,\n>28\tbyte\t13\t\tOS: LynxOS,\n>28\tbyte\t14\t\tOS: VxWorks,\n>28\tbyte\t15\t\tOS: pSOS,\n>28\tbyte\t16\t\tOS: QNX,\n>28\tbyte\t17\t\tOS: Firmware,\n>28\tbyte\t18\t\tOS: RTEMS,\n>28\tbyte\t19\t\tOS: ARTOS,\n>28\tbyte\t20\t\tOS: Unity OS,\n#>29\tbyte\tx\t\tCPU arch: %d,\n>29\tbyte\t0\t\tCPU: invalid OS,\n>29\tbyte\t1\t\tCPU: Alpha,\n>29\tbyte\t2\t\tCPU: ARM,\n>29\tbyte\t3\t\tCPU: Intel x86,\n>29\tbyte\t4\t\tCPU: IA64,\n>29\tbyte\t5\t\tCPU: MIPS,\n>29\tbyte\t6\t\tCPU: MIPS 64 bit,\n>29\tbyte\t7\t\tCPU: PowerPC,\n>29\tbyte\t8\t\tCPU: IBM S390,\n>29\tbyte\t9\t\tCPU: SuperH,\n>29\tbyte\t10\t\tCPU: Sparc,\n>29\tbyte\t11\t\tCPU: Sparc 64 bit,\n>29\tbyte\t12\t\tCPU: M68K,\n>29\tbyte\t13\t\tCPU: Nios-32,\n>29\tbyte\t14\t\tCPU: MicroBlaze,\n>29\tbyte\t15\t\tCPU: Nios-II,\n>29\tbyte\t16\t\tCPU: Blackfin,\n>29\tbyte\t17\t\tCPU: AVR,\n>29\tbyte\t18\t\tCPU: STMicroelectronics ST200,\n#>30\tbyte\tx\t\timage type: %d,\n>30\tbyte\t0\t\timage type: invalid Image,\n>30\tbyte\t1\t\timage type: Standalone Program,\n>30\tbyte\t2\t\timage type: OS Kernel Image,\n>30\tbyte \t3\t\timage type: RAMDisk Image,\n>30\tbyte\t4\t\timage type: Multi-File Image,\n>30\tbyte\t5\t\timage type: Firmware Image,\n>30\tbyte\t6\t\timage type: Script file,\n>30\tbyte\t7\t\timage type: Filesystem Image,\n>30\tbyte\t8\t\timage type: Binary Flat Device Tree Blob\n#>31\tbyte\tx\t\tcompression type: %d,\n>31\tbyte\t0\t\tcompression type: none,\n>31\tbyte\t1\t\tcompression type: gzip,\n>31\tbyte\t2\t\tcompression type: bzip2,\n>31\tbyte\t3\t\tcompression type: lzma,\n>32\tstring\tx\t\timage name: \"%s\"\n\n#IMG0 header, found in VxWorks-based Mercury router firmware\n0\tstring\t\tIMG0\t\tIMG0 (VxWorks) header,\n>4\tbelong\t\tx\t\tsize: %d\n\n#Mediatek bootloader signature\n#From xp-dev.com\n0\tstring\t\tBOOTLOADER!\tMediatek bootloader\n\n#CSYS header formats\n0\tstring\t\tCSYS\\x00\tCSYS header, little endian, \n>8\tlelong\t\tx\t\tsize: %d\n\n0\tstring\t\tCSYS\\x80\tCSYS header, big endian,\n>8\tbelong\t\tx\t\tsize: %d\n\n# wrgg firmware image\n0\tstring\t\twrgg02\t\tWRGG firmware header,\n>6\tstring\t\tx\t\tname: \"%s\",\n>48\tstring\t\tx\t\troot device: \"%s\"\n\n# trx image file\n0\tstring          HDR0            TRX firmware header, little endian, header size: 28 bytes, \n>4\tlelong\t\tx\t\timage size: %d bytes,\n>8\tlelong\t\tx\t\tCRC32: 0x%X\n>12\tlelong\t\tx\t\tflags/version: 0x%X\n\n0\tstring          0RDH            TRX firmware header, big endian, header size: 28 bytes,\n>4\tbelong\t\tx\t\timage size: %d bytes,\n>8\tbelong\t\tx\t\tCRC32: 0x%X\n>12\tbelong\t\tx\t\tflags/version: 0x%X\n\n\n# Ubicom firmware image\n0\tbelong\t0xFA320080\t\tUbicom firmware header,\n>12\tbelong\tx\t\t\tchecksum: 0x%X,\n>24\tbelong\tx\t\t\timage size: %d\n\n# The ROME bootloader is used by several RealTek-based products.\n# Unfortunately, the magic bytes are specific to each product, so\n# separate signatures must be created for each one.\n\n# Netgear KWGR614 ROME image\n0\tstring\t\tG614\t\tRealtek firmware header (ROME bootloader),\n>4\tbeshort\t\t0xd92f\t\timage type: KFS,\n>4\tbeshort\t\t0xb162\t\timage type: RDIR,\n>4\tbeshort\t\t0xea43\t\timage type: BOOT,\n>4\tbeshort\t\t0x8dc9\t\timage type: RUN,\n>4\tbeshort\t\t0x2a05\t\timage type: CCFG,\n>4\tbeshort\t\t0x6ce8\t\timage type: DCFG,\n>4\tbeshort\t\t0xc371\t\timage type: LOG,\n>6\tbyte\t\tx\t\theader version: %d,\n#month\n>10\tbyte\t\tx\t\tcreated: %d/\n#day\t\n>12\tbyte \t\tx\t\t\\b%d/\n#year\n>8\tbeshort\t\tx\t\t\\b%d,\n>16\tbelong\t\tx\t\timage size: %d bytes,\n>22\tbyte\t\tx\t\tbody checksum: 0x%X,\n>23\tbyte\t\tx\t\theader checksum: 0x%X\n\n# Linksys WRT54GX ROME image\n0\tbelong\t\t0x59a0e842\tRealtek firmware header (ROME bootloader)\n>4      beshort         0xd92f          image type: KFS,\n>4      beshort         0xb162          image type: RDIR,\n>4      beshort         0xea43          image type: BOOT,\n>4      beshort         0x8dc9          image type: RUN,\n>4      beshort         0x2a05          image type: CCFG,\n>4      beshort         0x6ce8          image type: DCFG,\n>4      beshort         0xc371          image type: LOG,\n>6      byte            x               header version: %d,\n#month\n>10     byte            x               created: %d/\n#day    \n>12     byte            x               \\b%d/\n#year\n>8      beshort         x               \\b%d,\n>16     belong          x               image size: %d bytes,\n>22     byte            x               body checksum: 0x%X,\n>23     byte            x               header checksum: 0x%X\n\n# PackImg tag, somtimes used as a delimiter between the kernel and rootfs in firmware images.\n0\tstring\t\t--PaCkImGs--\tPackImg section delimiter tag,\n>16\tlelong\t\tx\t\tlittle endian size: %d bytes;\n>16\tbelong\t\tx\t\tbig endian size: %d bytes\n\n\n#------------------------------------------------------------------------------\n# Broadcom header format\n#\n0       string          BCRM            Broadcom header,\n>4      lelong          x               number of sections: %d,\n>>8     lelong          18              first section type: flash\n>>8     lelong          19              first section type: disk\n>>8     lelong          21              first section type: tag\n\n\n# Berkeley Lab Checkpoint Restart (BLCR) checkpoint context files\n# http://ftg.lbl.gov/checkpoint\n0       string  Ck0\\0\\0R\\0\\0\\0  BLCR\n>16     lelong  1       x86\n>16     lelong  3       alpha\n>16     lelong  5       x86-64\n>16     lelong  7       ARM\n>8      lelong  x       context data (little endian, version %d)\n\n0       string  \\0\\0\\0C\\0\\0\\0R  BLCR\n>16     belong  2       SPARC\n>16     belong  4       ppc\n>16     belong  6       ppc64\n>16     belong  7       ARMEB\n>16     belong  8       SPARC64\n>8      belong  x       context data (big endian, version %d)\n\n# Aculab VoIP firmware\n# From: Mark Brown <broonie@sirena.org.uk>\n0       string  VoIP\\x20Startup\\x20and      Aculab VoIP firmware\n>35     string  x       format \"%s\"\n\n#------------------------------------------------------------------------------\n# HP LaserJet 1000 series downloadable firmware file\n0       string  \\xbe\\xefABCDEFGH        HP LaserJet 1000 series downloadable firmware\n\n# From Albert Cahalan <acahalan@gmail.com>\n# really le32 operation,destination,payloadsize (but quite predictable)\n# 01 00 00 00 00 00 00 c0 00 02 00 00\n0       string          \\1\\0\\0\\0\\0\\0\\0\\300\\0\\2\\0\\0      Marvell Libertas firmware\n\n#---------------------------------------------------------------------------\n# The following entries have been tested by Duncan Laurie <duncan@sun.com> (a\n# lead Sun/Cobalt developer) who agrees that they are good and worthy of\n# inclusion.\n\n# Boot ROM images for Sun/Cobalt Linux server appliances\n0       string  Cobalt\\x20Networks\\x20Inc.\\nFirmware\\x20v     Paged COBALT boot rom\n>38     string x        V%.4s\n\n# New format for Sun/Cobalt boot ROMs is annoying, it stores the version code\n# at the very end where file(1) can't get it.\n0       string CRfs     COBALT boot rom data (Flat boot rom or file system)\n\n#\n# Motorola S-Records, from Gerd Truschinski <gt@freebsd.first.gmd.de>\n0   string      S0          Motorola S-Record; binary data in text format\n\n# --------------------------------\n# Microsoft Xbox data file formats\n0       string          XIP0            XIP, Microsoft Xbox data\n0       string          XTF0            XTF, Microsoft Xbox data\n\n#Windows CE\n0\tstring\t\tCECE\t\tWindows CE RTOS{offset-adjust:-64}\n\n# --------------------------------\n# ZynOS ROM header format\n# From openwrt zynos.h.\n0\tstring\t\tSIG\t\tZynOS header, header size: 48 bytes,{offset-adjust:-6}\n#>0\tbelong\t\tx\t\tload address 0x%X,\n>3\tbyte\t\t<0x7F\t\trom image type:\n>>3\tbyte\t\t<1\t\tinvalid,\n>>3\tbyte\t\t>7\t\tinvalid,\n>>3\tbyte\t\t1\t\tROMIMG,\n>>3\tbyte\t\t2\t\tROMBOOT,\n>>3\tbyte\t\t3\t\tBOOTEXT,\n>>3\tbyte\t\t4\t\tROMBIN,\n>>3\tbyte\t\t5\t\tROMDIR,\n>>3\tbyte\t\t6\t\t6,\n>>3\tbyte\t\t7\t\tROMMAP,\n>3\tbyte\t\t>0x7F\t\tram image type:\n>>3\tbyte\t\t>0x82\t\tinvalid,\n>>3\tbyte\t\t0x80\t\tRAM,\n>>3\tbyte\t\t0x81\t\tRAMCODE,\n>>3\tbyte\t\t0x82\t\tRAMBOOT,\n>4\tbelong\t\t>0x40000000\tinvalid\n>4\tbelong\t\t<0\t\tinvalid\n>4\tbelong\t\t0\t\tinvalid\n>4\tbelong\t\tx\t\tuncompressed size: %d,\n>8\tbelong\t\t>0x40000000\tinvalid\n>8\tbelong\t\t<0\t\tinvalid\n>8\tbelong\t\t0  \t\tinvalid\n>8\tbelong\t\tx\t\tcompressed size: %d,\n>14\tbeshort\t\tx\t\tuncompressed checksum: 0x%X,\n>16\tbeshort\t\tx\t\tcompressed checksum: 0x%X,\n>12\tbyte\t\tx\t\tflags: 0x%X,\n>12\tbyte\t\t&0x40\t\tuncompressed checksum is valid,\n>12\tbyte\t\t&0x80\t\tthe binary is compressed,\n>>12\tbyte\t\t&0x20\t\tcompressed checksum is valid,\n>35\tbelong\t\tx\t\tmemory map table address: 0x%X\n\n# Firmware header used by some VxWorks-based Cisco products\n0\tstring\t\tCI032.00\tCisco VxWorks firmware header,\n>8\tlelong\t\t>1024\t\tinvalid\n>8\tlelong\t\t<0\t\tinvalid\n>8\tlelong\t\tx\t\theader size: %d bytes,\n>32\tlelong\t\t>1024\t\tinvalid\n>32\tlelong\t\t<0\t\tinvalid\n>32\tlelong\t\tx\t\tnumber of files: %d,\n>48\tlelong\t\t<0\t\tinvalid\n>48\tlelong\t\tx\t\timage size: %d,\n>64\tstring\t\tx\t\tfirmware version: \"%s\"\n\n# Firmware header used by some TV's\n0\tstring\t\tFNIB\t\tZBOOT firmware header, header size: 32 bytes,\n>8\tlelong\t\tx\t\tload address: 0x%.8X,\n>12\tlelong\t\tx\t\tstart address: 0x%.8X,\n>16\tlelong\t\tx\t\tchecksum: 0x%.8X,\n>20\tlelong\t\tx\t\tversion: 0x%.8X,\n>24\tlelong\t\t<1\t\tinvalid\n>24\tlelong\t\tx\t\timage size: %d bytes\n\n# Firmware header used by several D-Link routers (and probably others)\n0               string  \\x5e\\xa3\\xa4\\x17\tDLOB firmware header,\n>(7.b+12)       string  !\\x5e\\xa3\\xa4\\x17       invalid,\n#>>12           string  x                       %s,\n>(7.b+40)       string  x                       boot partition: \"%s\"\n\n# TP-Link firmware header structure; thanks to Jonathan McGowan for reversing and documenting this format\n0\tstring          TP-LINK\\x20Technologies\t\tTP-Link firmware header,{offset-adjust:-4}\n#>-4\tlelong          x               \t\theader version: %d,\n>0x94  \tbeshort         x               \t\tfirmware version: %d.\n>0x96  \tbeshort         x               \t\t\\b%d.\n>0x98  \tbeshort         x               \t\t\\b%d,\n>0x18  \tstring          x               \t\timage version: \"%s\",\n#>0x74  belong          x               \t\timage size: %d bytes,\n>0x3C  \tbelong          x               \t\tproduct ID: 0x%X,\n>0x40  \tbelong          x               \t\tproduct version: %d,\n>0x70  \tbelong          x               \t\tkernel load address: 0x%X,\n>0x74  \tbelong          x               \t\tkernel entry point: 0x%X,\n>0x7C  \tbelong          x               \t\tkernel offset: %d,\n>0x80  \tbelong          x               \t\tkernel length: %d,\n>0x84  \tbelong          x               \t\trootfs offset: %d,\n>0x88  \tbelong          x               \t\trootfs length: %d,\n>0x8C  \tbelong          x               \t\tbootloader offset: %d,\n>0x90  \tbelong          x               \t\tbootloader length: %d\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/images",
    "content": "# Tag Image File Format, from Daniel Quinlan (quinlan@yggdrasil.com)\n# The second word of TIFF files is the TIFF version number, 42, which has\n# never changed.  The TIFF specification recommends testing for it.\n0       string          MM\\x00\\x2a      TIFF image data, big-endian\n0       string          II\\x2a\\x00      TIFF image data, little-endian\n\n# PNG [Portable Network Graphics, or \"PNG's Not GIF\"] images\n# (Greg Roelofs, newt@uchicago.edu)\n# (Albert Cahalan, acahalan@cs.uml.edu)\n#\n# 137 P N G \\r \\n ^Z \\n [4-byte length] H E A D [HEAD data] [HEAD crc] ...\n#\n0       string          \\x89PNG\\x0d\\x0a\\x1a\\x0a         PNG image\n>16     belong          x               \\b, %ld x\n>20     belong          x               %ld,\n>24     byte            x               %d-bit\n>25     byte            0               grayscale,\n>25     byte            2               \\b/color RGB,\n>25     byte            3               colormap,\n>25     byte            4               gray+alpha,\n>25     byte            6               \\b/color RGBA,\n#>26    byte            0               deflate/32K,\n>28     byte            0               non-interlaced\n>28     byte            1               interlaced\n\n# GIF\n0       string          GIF8            GIF image data\n>4      string          7a              \\b, version 8\"%s\",\n>4      string          9a              \\b, version 8\"%s\",\n>6      leshort         >0              %hd x\n>8      leshort         >0              %hd\n#>10    byte            &0x80           color mapped,\n#>10    byte&0x07       =0x00           2 colors\n#>10    byte&0x07       =0x01           4 colors\n#>10    byte&0x07       =0x02           8 colors\n#>10    byte&0x07       =0x03           16 colors\n#>10    byte&0x07       =0x04           32 colors\n#>10    byte&0x07       =0x05           64 colors\n#>10    byte&0x07       =0x06           128 colors\n#>10    byte&0x07       =0x07           256 colors\n\n# PC bitmaps (OS/2, Windows BMP files)  (Greg Roelofs, newt@uchicago.edu)\n0       string          BM\n>14     leshort         12              PC bitmap, OS/2 1.x format\n>>18    leshort         x               \\b, %d x\n>>20    leshort         x               %d\n>14     leshort         64              PC bitmap, OS/2 2.x format\n>>18    leshort         x               \\b, %d x\n>>20    leshort         x               %d\n>14     leshort         40              PC bitmap, Windows 3.x format\n>>18    lelong          x               \\b, %d x\n>>22    lelong          x               %d x\n>>28    leshort         x               %d\n>14     leshort         128             PC bitmap, Windows NT/2000 format\n>>18    lelong          x               \\b, %d x\n>>22    lelong          x               %d x\n>>28    leshort         x               %d\n\n#------------------------------------------------------------------------------\n# JPEG images\n# SunOS 5.5.1 had\n#\n#       0       string          \\377\\330\\377\\340        JPEG file\n#       0       string          \\377\\330\\377\\356        JPG file\n#\n# both of which turn into \"JPEG image data\" here.\n#\n0       beshort         0xffd8          JPEG image data\n>6      string          JFIF            \\b, JFIF standard\n# The following added by Erik Rossen <rossen@freesurf.ch> 1999-09-06\n# in a vain attempt to add image size reporting for JFIF.  Note that these\n# tests are not fool-proof since some perfectly valid JPEGs are currently\n# impossible to specify in magic(4) format.\n# First, a little JFIF version info:\n>>11    byte            x               \\b %d.\n>>12    byte            x               \\b%02d\n# Next, the resolution or aspect ratio of the image:\n#>>13   byte            0               \\b, aspect ratio\n#>>13   byte            1               \\b, resolution (DPI)\n#>>13   byte            2               \\b, resolution (DPCM)\n#>>4    beshort         x               \\b, segment length %d\n# Next, show thumbnail info, if it exists:\n>>18    byte            !0              \\b, thumbnail %dx\n>>>19   byte            x               \\b%d\n\n# EXIF moved down here to avoid reporting a bogus version number,\n# and EXIF version number printing added.\n#   - Patrik R=E5dman <patrik+file-magic@iki.fi>\n>6      string          Exif            \\b, EXIF standard\n# Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD.\n# All possible combinations of entries have to be enumerated, since no looping\n# is possible. And both endians are possible...\n# The combinations included below are from real-world JPEGs.\n# Little-endian\n>>12    string          II\n# IFD 0 Entry #5:\n>>>70   leshort         0x8769\n# EXIF IFD Entry #1:\n>>>>(78.l+14)   leshort 0x9000\n>>>>>(78.l+23)  byte    x               %c\n>>>>>(78.l+24)  byte    x               \\b.%c\n>>>>>(78.l+25)  byte    !0x30           \\b%c\n# IFD 0 Entry #9:\n>>>118  leshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(126.l+38)  leshort 0x9000\n>>>>>(126.l+47) byte    x               %c\n>>>>>(126.l+48) byte    x               \\b.%c\n>>>>>(126.l+49) byte    !0x30           \\b%c\n# IFD 0 Entry #10\n>>>130  leshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(138.l+38)  leshort 0x9000\n>>>>>(138.l+47) byte    x               %c\n>>>>>(138.l+48) byte    x               \\b.%c\n>>>>>(138.l+49) byte    !0x30           \\b%c\n# EXIF IFD Entry #4:\n>>>>(138.l+50)  leshort 0x9000\n>>>>>(138.l+59) byte    x               %c\n>>>>>(138.l+60) byte    x               \\b.%c\n>>>>>(138.l+61) byte    !0x30           \\b%c\n# EXIF IFD Entry #5:\n>>>>(138.l+62)  leshort 0x9000\n>>>>>(138.l+71) byte    x               %c\n>>>>>(138.l+72) byte    x               \\b.%c\n>>>>>(138.l+73) byte    !0x30           \\b%c\n# IFD 0 Entry #11\n>>>142  leshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(150.l+38)  leshort 0x9000\n>>>>>(150.l+47) byte    x               %c\n>>>>>(150.l+48) byte    x               \\b.%c\n>>>>>(150.l+49) byte    !0x30           \\b%c\n# EXIF IFD Entry #4:\n>>>>(150.l+50)  leshort 0x9000\n>>>>>(150.l+59) byte    x               %c\n>>>>>(150.l+60) byte    x               \\b.%c\n>>>>>(150.l+61) byte    !0x30           \\b%c\n# EXIF IFD Entry #5:\n>>>>(150.l+62)  leshort 0x9000\n>>>>>(150.l+71) byte    x               %c\n>>>>>(150.l+72) byte    x               \\b.%c\n>>>>>(150.l+73) byte    !0x30           \\b%c\n# Big-endian\n>>12    string          MM\n# IFD 0 Entry #9:\n>>>118  beshort         0x8769\n# EXIF IFD Entry #1:\n>>>>(126.L+14)  beshort 0x9000\n>>>>>(126.L+23) byte    x               %c\n>>>>>(126.L+24) byte    x               \\b.%c\n>>>>>(126.L+25) byte    !0x30           \\b%c\n# EXIF IFD Entry #3:\n>>>>(126.L+38)  beshort 0x9000\n>>>>>(126.L+47) byte    x               %c\n>>>>>(126.L+48) byte    x               \\b.%c\n>>>>>(126.L+49) byte    !0x30           \\b%c\n# IFD 0 Entry #10\n>>>130  beshort         0x8769\n# EXIF IFD Entry #3:\n>>>>(138.L+38)  beshort 0x9000\n>>>>>(138.L+47) byte    x               %c\n>>>>>(138.L+48) byte    x               \\b.%c\n>>>>>(138.L+49) byte    !0x30           \\b%c\n# EXIF IFD Entry #5:\n>>>>(138.L+62)  beshort 0x9000\n>>>>>(138.L+71) byte    x               %c\n>>>>>(138.L+72) byte    x               \\b.%c\n>>>>>(138.L+73) byte    !0x30           \\b%c\n# IFD 0 Entry #11\n>>>142  beshort         0x8769\n# EXIF IFD Entry #4:\n>>>>(150.L+50)  beshort 0x9000\n>>>>>(150.L+59) byte    x               %c\n>>>>>(150.L+60) byte    x               \\b.%c\n>>>>>(150.L+61) byte    !0x30           \\b%c\n# Here things get sticky.  We can do ONE MORE marker segment with\n# indirect addressing, and that's all.  It would be great if we could\n# do pointer arithemetic like in an assembler language.  Christos?\n# And if there was some sort of looping construct to do searches, plus a few\n# named accumulators, it would be even more effective...\n# At least we can show a comment if no other segments got inserted before:\n>(4.S+5)        byte            0xFE\n>>(4.S+8)       string          >\\0             \\b, comment: \"%s\"\n# FIXME: When we can do non-byte counted strings, we can use that to get\n# the string's count, and fix Debian bug #283760\n#>(4.S+5)       byte            0xFE            \\b, comment\n#>>(4.S+6)      beshort         x               \\b length=%d\n#>>(4.S+8)      string          >\\0             \\b, \"%s\"\n# Or, we can show the encoding type (I've included only the three most common)\n# and image dimensions if we are lucky and the SOFn (image segment) is here:\n>(4.S+5)        byte            0xC0            \\b, baseline\n>>(4.S+6)       byte            x               \\b, precision %d\n>>(4.S+7)       beshort         x               \\b, %dx\n>>(4.S+9)       beshort         x               \\b%d\n>(4.S+5)        byte            0xC1            \\b, extended sequential\n>>(4.S+6)       byte            x               \\b, precision %d\n>>(4.S+7)       beshort         x               \\b, %dx\n>>(4.S+9)       beshort         x               \\b%d\n>(4.S+5)        byte            0xC2            \\b, progressive\n>>(4.S+6)       byte            x               \\b, precision %d\n>>(4.S+7)       beshort         x               \\b, %dx\n>>(4.S+9)       beshort         x               \\b%d\n# I've commented-out quantisation table reporting.  I doubt anyone cares yet.\n#>(4.S+5)       byte            0xDB            \\b, quantisation table\n#>>(4.S+6)      beshort         x               \\b length=%d\n#>14    beshort         x               \\b, %d x\n#>16    beshort         x               \\b %d\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/kernels",
    "content": "\n#-------------------------Kernels-------------------------------------\n\n# Linux kernel boot images, from Albert Cahalan <acahalan@cs.uml.edu>\n# and others such as Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>\n# and Nicolás Lichtmaier <nick@debian.org>\n# All known start with: b8 c0 07 8e d8 b8 00 90 8e c0 b9 00 01 29 f6 29\n0\tstring\t\t\\xb8\\xc0\\x07\\x8e\\xd8\\xb8\\x00\\x90\\x8e\\xc0\\xb9\\x00\\x01\\x29\\xf6\\x29\tLinux kernel boot image\n>514\tstring          !HdrS            \t\t\t\t\t\t\t(invalid)\n\n# Finds and prints Linux kernel strings in raw Linux kernels (output like uname -a).\n# Commonly found in decompressed embedded kernel binaries.\n0\tstring\t\tLinux\\ version\\ \tLinux kernel version\n>14\tbyte\t\t0\t\t\tinvalid\n>14\tbyte\t\t!0\n>>14\tstring\t\tx\t\t\t\"%s\n>>45\tstring\t\tx\t\t\t\\b%s\n>>76\tstring\t\tx\t\t\t\\b%s\n>>107\tstring\t\tx\t\t\t\\b%s\"\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/lzma",
    "content": "\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5D\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5D\\x00\\x00\tLZMA compressed data, properties: 0x5D,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x01\n# ------------------------------------------------------------------\n0\t\tstring\t\\x01\\x00\\x00\tLZMA compressed data, properties: 0x01,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x02\n# ------------------------------------------------------------------\n0\t\tstring\t\\x02\\x00\\x00\tLZMA compressed data, properties: 0x02,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x03\n# ------------------------------------------------------------------\n0\t\tstring\t\\x03\\x00\\x00\tLZMA compressed data, properties: 0x03,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x04\n# ------------------------------------------------------------------\n0\t\tstring\t\\x04\\x00\\x00\tLZMA compressed data, properties: 0x04,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x09\n# ------------------------------------------------------------------\n0\t\tstring\t\\x09\\x00\\x00\tLZMA compressed data, properties: 0x09,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x0A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x0A\\x00\\x00\tLZMA compressed data, properties: 0x0A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x0B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x0B\\x00\\x00\tLZMA compressed data, properties: 0x0B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x0C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x0C\\x00\\x00\tLZMA compressed data, properties: 0x0C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x12\n# ------------------------------------------------------------------\n0\t\tstring\t\\x12\\x00\\x00\tLZMA compressed data, properties: 0x12,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x13\n# ------------------------------------------------------------------\n0\t\tstring\t\\x13\\x00\\x00\tLZMA compressed data, properties: 0x13,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x14\n# ------------------------------------------------------------------\n0\t\tstring\t\\x14\\x00\\x00\tLZMA compressed data, properties: 0x14,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x1B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x1B\\x00\\x00\tLZMA compressed data, properties: 0x1B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x1C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x1C\\x00\\x00\tLZMA compressed data, properties: 0x1C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x24\n# ------------------------------------------------------------------\n0\t\tstring\t\\x24\\x00\\x00\tLZMA compressed data, properties: 0x24,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x2D\n# ------------------------------------------------------------------\n0\t\tstring\t\\x2D\\x00\\x00\tLZMA compressed data, properties: 0x2D,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x2E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x2E\\x00\\x00\tLZMA compressed data, properties: 0x2E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x2F\n# ------------------------------------------------------------------\n0\t\tstring\t\\x2F\\x00\\x00\tLZMA compressed data, properties: 0x2F,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x30\n# ------------------------------------------------------------------\n0\t\tstring\t\\x30\\x00\\x00\tLZMA compressed data, properties: 0x30,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x31\n# ------------------------------------------------------------------\n0\t\tstring\t\\x31\\x00\\x00\tLZMA compressed data, properties: 0x31,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x36\n# ------------------------------------------------------------------\n0\t\tstring\t\\x36\\x00\\x00\tLZMA compressed data, properties: 0x36,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x37\n# ------------------------------------------------------------------\n0\t\tstring\t\\x37\\x00\\x00\tLZMA compressed data, properties: 0x37,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x38\n# ------------------------------------------------------------------\n0\t\tstring\t\\x38\\x00\\x00\tLZMA compressed data, properties: 0x38,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x39\n# ------------------------------------------------------------------\n0\t\tstring\t\\x39\\x00\\x00\tLZMA compressed data, properties: 0x39,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x3F\n# ------------------------------------------------------------------\n0\t\tstring\t\\x3F\\x00\\x00\tLZMA compressed data, properties: 0x3F,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x40\n# ------------------------------------------------------------------\n0\t\tstring\t\\x40\\x00\\x00\tLZMA compressed data, properties: 0x40,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x41\n# ------------------------------------------------------------------\n0\t\tstring\t\\x41\\x00\\x00\tLZMA compressed data, properties: 0x41,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x48\n# ------------------------------------------------------------------\n0\t\tstring\t\\x48\\x00\\x00\tLZMA compressed data, properties: 0x48,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x49\n# ------------------------------------------------------------------\n0\t\tstring\t\\x49\\x00\\x00\tLZMA compressed data, properties: 0x49,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x51\n# ------------------------------------------------------------------\n0\t\tstring\t\\x51\\x00\\x00\tLZMA compressed data, properties: 0x51,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5A\\x00\\x00\tLZMA compressed data, properties: 0x5A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5B\\x00\\x00\tLZMA compressed data, properties: 0x5B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5C\\x00\\x00\tLZMA compressed data, properties: 0x5C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x5E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x5E\\x00\\x00\tLZMA compressed data, properties: 0x5E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x63\n# ------------------------------------------------------------------\n0\t\tstring\t\\x63\\x00\\x00\tLZMA compressed data, properties: 0x63,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x64\n# ------------------------------------------------------------------\n0\t\tstring\t\\x64\\x00\\x00\tLZMA compressed data, properties: 0x64,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x65\n# ------------------------------------------------------------------\n0\t\tstring\t\\x65\\x00\\x00\tLZMA compressed data, properties: 0x65,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x66\n# ------------------------------------------------------------------\n0\t\tstring\t\\x66\\x00\\x00\tLZMA compressed data, properties: 0x66,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x6C\n# ------------------------------------------------------------------\n0\t\tstring\t\\x6C\\x00\\x00\tLZMA compressed data, properties: 0x6C,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x6D\n# ------------------------------------------------------------------\n0\t\tstring\t\\x6D\\x00\\x00\tLZMA compressed data, properties: 0x6D,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x6E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x6E\\x00\\x00\tLZMA compressed data, properties: 0x6E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x75\n# ------------------------------------------------------------------\n0\t\tstring\t\\x75\\x00\\x00\tLZMA compressed data, properties: 0x75,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x76\n# ------------------------------------------------------------------\n0\t\tstring\t\\x76\\x00\\x00\tLZMA compressed data, properties: 0x76,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x7E\n# ------------------------------------------------------------------\n0\t\tstring\t\\x7E\\x00\\x00\tLZMA compressed data, properties: 0x7E,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x87\n# ------------------------------------------------------------------\n0\t\tstring\t\\x87\\x00\\x00\tLZMA compressed data, properties: 0x87,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x88\n# ------------------------------------------------------------------\n0\t\tstring\t\\x88\\x00\\x00\tLZMA compressed data, properties: 0x88,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x89\n# ------------------------------------------------------------------\n0\t\tstring\t\\x89\\x00\\x00\tLZMA compressed data, properties: 0x89,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x8A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x8A\\x00\\x00\tLZMA compressed data, properties: 0x8A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x8B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x8B\\x00\\x00\tLZMA compressed data, properties: 0x8B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x90\n# ------------------------------------------------------------------\n0\t\tstring\t\\x90\\x00\\x00\tLZMA compressed data, properties: 0x90,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x91\n# ------------------------------------------------------------------\n0\t\tstring\t\\x91\\x00\\x00\tLZMA compressed data, properties: 0x91,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x92\n# ------------------------------------------------------------------\n0\t\tstring\t\\x92\\x00\\x00\tLZMA compressed data, properties: 0x92,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x93\n# ------------------------------------------------------------------\n0\t\tstring\t\\x93\\x00\\x00\tLZMA compressed data, properties: 0x93,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x99\n# ------------------------------------------------------------------\n0\t\tstring\t\\x99\\x00\\x00\tLZMA compressed data, properties: 0x99,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x9A\n# ------------------------------------------------------------------\n0\t\tstring\t\\x9A\\x00\\x00\tLZMA compressed data, properties: 0x9A,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0x9B\n# ------------------------------------------------------------------\n0\t\tstring\t\\x9B\\x00\\x00\tLZMA compressed data, properties: 0x9B,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xA2\n# ------------------------------------------------------------------\n0\t\tstring\t\\xA2\\x00\\x00\tLZMA compressed data, properties: 0xA2,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xA3\n# ------------------------------------------------------------------\n0\t\tstring\t\\xA3\\x00\\x00\tLZMA compressed data, properties: 0xA3,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xAB\n# ------------------------------------------------------------------\n0\t\tstring\t\\xAB\\x00\\x00\tLZMA compressed data, properties: 0xAB,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB4\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB4\\x00\\x00\tLZMA compressed data, properties: 0xB4,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB5\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB5\\x00\\x00\tLZMA compressed data, properties: 0xB5,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB6\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB6\\x00\\x00\tLZMA compressed data, properties: 0xB6,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB7\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB7\\x00\\x00\tLZMA compressed data, properties: 0xB7,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xB8\n# ------------------------------------------------------------------\n0\t\tstring\t\\xB8\\x00\\x00\tLZMA compressed data, properties: 0xB8,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xBD\n# ------------------------------------------------------------------\n0\t\tstring\t\\xBD\\x00\\x00\tLZMA compressed data, properties: 0xBD,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xBE\n# ------------------------------------------------------------------\n0\t\tstring\t\\xBE\\x00\\x00\tLZMA compressed data, properties: 0xBE,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xBF\n# ------------------------------------------------------------------\n0\t\tstring\t\\xBF\\x00\\x00\tLZMA compressed data, properties: 0xBF,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC0\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC0\\x00\\x00\tLZMA compressed data, properties: 0xC0,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC6\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC6\\x00\\x00\tLZMA compressed data, properties: 0xC6,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC7\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC7\\x00\\x00\tLZMA compressed data, properties: 0xC7,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xC8\n# ------------------------------------------------------------------\n0\t\tstring\t\\xC8\\x00\\x00\tLZMA compressed data, properties: 0xC8,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xCF\n# ------------------------------------------------------------------\n0\t\tstring\t\\xCF\\x00\\x00\tLZMA compressed data, properties: 0xCF,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xD0\n# ------------------------------------------------------------------\n0\t\tstring\t\\xD0\\x00\\x00\tLZMA compressed data, properties: 0xD0,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n\n# ------------------------------------------------------------------\n# Signature for LZMA compressed data with valid properties byte 0xD8\n# ------------------------------------------------------------------\n0\t\tstring\t\\xD8\\x00\\x00\tLZMA compressed data, properties: 0xD8,\n\n# These are all the valid dictionary sizes supported by LZMA utils.\n>1\t\tlelong\t!65536\t\n>>1\t\tlelong\t!131072\t\n>>>1\t\tlelong\t!262144\t\n>>>>1\t\tlelong\t!524288\t\n>>>>>1\t\tlelong\t!1048576\t\n>>>>>>1\t\tlelong\t!2097152\t\n>>>>>>>1\tlelong\t!4194304\t\n>>>>>>>>1\tlelong\t!8388608\t\n>>>>>>>>>1\tlelong\t!16777216\t\n>>>>>>>>>>1\tlelong\t!33554432\tinvalid\n>1\t\tlelong\tx\t\tdictionary size: %d bytes,\n\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\n>5\t\tlequad\t<1\t\tinvalid\n>5\t\tlequad\t>0x40000000\tinvalid\n\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\n# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\n# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\n>1\t\tlelong\t65536\n>>5\t\tlequad\t65536\t\tinvalid\n>1\t\tlelong\t131072\n>>5\t\tlequad\t131072\t\tinvalid\n>1\t\tlelong\t262144\n>>5\t\tlequad\t262144\t\tinvalid\n>1\t\tlelong\t524288\n>>5\t\tlequad\t524288\t\tinvalid\n>1\t\tlelong\t1048576\n>>5\t\tlequad\t1048576\t\tinvalid\n>1\t\tlelong\t2097152\n>>5\t\tlequad\t2097152\t\tinvalid\n>1\t\tlelong\t4194304\n>>5\t\tlequad\t4194304\t\tinvalid\n>1\t\tlelong\t8388608\n>>5\t\tlequad\t8388608\t\tinvalid\n>1\t\tlelong\t16777216\n>>5\t\tlequad\t16777216\tinvalid\n>1\t\tlelong\t33554432\n>>5\t\tlequad\t33554432\tinvalid\n>5\t\tlequad\tx\t\tuncompressed size: %lld bytes\n\n"
  },
  {
    "path": "src/binwalk-1.0/src/magic/sql",
    "content": "#------------------------------------------------------------------------------\n# $File: sql,v 1.6 2009/09/19 16:28:12 christos Exp $\n# sql:  file(1) magic for SQL files\n#\n# From: \"Marty Leisner\" <mleisner@eng.mc.xerox.com>\n# Recognize some MySQL files.\n#\n0       beshort                 0xfe01          MySQL table definition file\n>2\tstring\t\t\t<1\t\tinvalid\n>2\tstring\t\t\t>\\11\t\tinvalid\n>2      byte                    x               Version %d\n0       string\t\t        \\xfe\\xfe\\x03    MySQL MISAM index file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\xfe\\xfe\\x07    MySQL MISAM compressed data file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\xfe\\xfe\\x05    MySQL ISAM index file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\xfe\\xfe\\x06    MySQL ISAM compressed data file\n>3\tstring\t\t\t<1\t\tinvalid\n>3\tstring\t\t\t>\\11\t\tinvalid\n>3      byte                    x               Version %d\n0       string                  \\376bin         MySQL replication log\n\n#------------------------------------------------------------------------------\n# iRiver H Series database file \n# From Ken Guest <ken@linux.ie>\n# As observed from iRivNavi.iDB and unencoded firmware\n#\n0   string              iRivDB  iRiver Database file\n>11  string     >\\0     Version \"%s\"\n>39  string             iHP-100 [H Series]\n\n#------------------------------------------------------------------------------\n# SQLite database files\n# Ken Guest <ken@linux.ie>, Ty Sarna, Zack Weinberg\n#\n# Version 1 used GDBM internally; its files cannot be distinguished\n# from other GDBM files.\n#\n# Version 2 used this format:\n0       string  **\\x20This\\x20file\\x20contains\\x20an\\x20SQLite  SQLite 2.x database\n\n# Version 3 of SQLite allows applications to embed their own \"user version\"\n# number in the database.  Detect this and distinguish those files.\n\n0   string  SQLite\\x20format\\x203\n>60 string  _MTN               Monotone source repository\n>60 belong  !0                 SQLite 3.x database, user version %u\n>60 belong  0                  SQLite 3.x database\n"
  },
  {
    "path": "src/binwalk-1.0/src/setup.py",
    "content": "#!/usr/bin/env python\nfrom os import listdir, path\nfrom distutils.core import setup\n\n# Generate a new magic file from the files in the magic directory\nprint \"generating binwalk magic file\"\nmagic_files = listdir(\"magic\")\nmagic_files.sort()\nfd = open(\"binwalk/magic/binwalk\", \"wb\")\nfor magic in magic_files:\n\tfpath = path.join(\"magic\", magic)\n\tif path.isfile(fpath):\n\t\tfd.write(open(fpath).read())\nfd.close()\n\n# The data files to install along with the binwalk module\ninstall_data_files = [\"magic/*\", \"config/*\"]\n\n# Install the binwalk module, script and support files\nsetup(\tname = \"binwalk\",\n\tversion = \"1.0\",\n\tdescription = \"Firmware analysis tool\",\n\tauthor = \"Craig Heffner\",\n\turl = \"http://binwalk.googlecode.com\",\n\t\n\tpackages = [\"binwalk\"],\n\tpackage_data = {\"binwalk\" : install_data_files},\n\tscripts = [\"bin/binwalk\"],\n)\n"
  },
  {
    "path": "src/binwalk-1.0/src/support/lzma_gen.py",
    "content": "#!/usr/bin/env python\n# Generates LZMA signatures for each valid LZMA property in the properties list.\n\n\nproperties = [\n\t0x5D,\n\t0x01,\n\t0x02,\n\t0x03,\n\t0x04,\n\t0x09,\n\t0x0A,\n\t0x0B,\n\t0x0C,\n\t0x12,\n\t0x13,\n\t0x14,\n\t0x1B,\n\t0x1C,\n\t0x24,\n\t0x2D,\n\t0x2E,\n\t0x2F,\n\t0x30,\n\t0x31,\n\t0x36,\n\t0x37,\n\t0x38,\n\t0x39,\n\t0x3F,\n\t0x40,\n\t0x41,\n\t0x48,\n\t0x49,\n\t0x51,\n\t0x5A,\n\t0x5B,\n\t0x5C,\n\t0x5E,\n\t0x63,\n\t0x64,\n\t0x65,\n\t0x66,\n\t0x6C,\n\t0x6D,\n\t0x6E,\n\t0x75,\n\t0x76,\n\t0x7E,\n\t0x87,\n\t0x88,\n\t0x89,\n\t0x8A,\n\t0x8B,\n\t0x90,\n\t0x91,\n\t0x92,\n\t0x93,\n\t0x99,\n\t0x9A,\n\t0x9B,\n\t0xA2,\n\t0xA3,\n\t0xAB,\n\t0xB4,\n\t0xB5,\n\t0xB6,\n\t0xB7,\n\t0xB8,\n\t0xBD,\n\t0xBE,\n\t0xBF,\n\t0xC0,\n\t0xC6,\n\t0xC7,\n\t0xC8,\n\t0xCF,\n\t0xD0,\n\t0xD8,\n]\n\ncommon_properties = [0x5D, 0x6D]\n\ndictionary_sizes = [\n\t65536,\n\t131072,\n\t262144,\n\t524288,\n\t1048576,\n\t2097152,\n\t4194304,\n\t8388608,\n\t16777216,\n\t33554432,\n]\n\nfor fbyte in properties:\n#\tif fbyte not in common_properties:\n#\t\tfexclude = '{filter-exclude}'\n#\telse:\n#\t\tfexclude = ''\n\tfexclude = ''\n\n\tsig = '\\n# ------------------------------------------------------------------\\n'\n\tsig += '# Signature for LZMA compressed data with valid properties byte 0x%.2X\\n' % fbyte\n\tsig += '# ------------------------------------------------------------------\\n'\n\tsig += '0\\t\\tstring\\t\\\\x%.2X\\\\x00\\\\x00\\tLZMA compressed data, properties: 0x%.2X,%s\\n' % (fbyte, fbyte, fexclude)\n\n\tsig += '\\n# These are all the valid dictionary sizes supported by LZMA utils.\\n'\n\tfor i in range(0, len(dictionary_sizes)):\n\t\tif i < 6:\n\t\t\tindent = '\\t\\t'\n\t\telse:\n\t\t\tindent = '\\t'\n\n\t\tif i == len(dictionary_sizes)-1:\n\t\t\tinvalid = 'invalid'\n\t\telse:\n\t\t\tinvalid = ''\n\n\t\tsig += '%s1%slelong\\t!%d\\t%s\\n' % ('>'*(i+1), indent, dictionary_sizes[i], invalid)\n\n\tsig += '>1\\t\\tlelong\\tx\\t\\tdictionary size: %d bytes,\\n'\n\t\n\tsig += '\\n# Assume that a valid size will be less than 1GB. This could technically be valid, but is unlikely.\\n'\n\tsig += '>5\\t\\tlequad\\t<1\\t\\tinvalid\\n'\n\tsig += '>5\\t\\tlequad\\t>0x40000000\\tinvalid\\n'\n\n\tsig += '\\n# These are not 100%. The uncompressed size could be exactly the same as the dicionary size, but it is unlikely.\\n'\n\tsig += '# Since most false positives are the result of repeating sequences of bytes (such as executable instructions),\\n'\n\tsig += '# marking matches with the same uncompressed and dictionary sizes as invalid eliminates much of these false positives.\\n'\n\n\tfor dsize in dictionary_sizes:\n\t\tif dsize < 16777216:\n\t\t\tindent = '\\t\\t'\n\t\telse:\n\t\t\tindent = '\\t'\n\n\t\tsig += '>1\\t\\tlelong\\t%d\\n' % dsize\n\t\tsig += '>>5\\t\\tlequad\\t%d%sinvalid\\n' % (dsize, indent)\n\n\tsig += '>5\\t\\tlequad\\tx\\t\\tuncompressed size: %lld bytes\\n'\n\t\n\tprint sig\n"
  },
  {
    "path": "src/configure",
    "content": "#! /bin/sh\n# Guess values for system-dependent variables and create Makefiles.\n# Generated by GNU Autoconf 2.65 for Firmware Mod Kit 0.4.0.\n#\n# Report bugs to <http://firmware-mod-kit.googlecode.com>.\n#\n#\n# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,\n# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,\n# Inc.\n#\n#\n# This configure script is free software; the Free Software Foundation\n# gives unlimited permission to copy, distribute and modify it.\n## -------------------- ##\n## M4sh Initialization. ##\n## -------------------- ##\n\n# Be more Bourne compatible\nDUALCASE=1; export DUALCASE # for MKS sh\nif test -n \"${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :\n  emulate sh\n  NULLCMD=:\n  # Pre-4.2 versions of Zsh do word splitting on ${1+\"$@\"}, which\n  # is contrary to our usage.  Disable this feature.\n  alias -g '${1+\"$@\"}'='\"$@\"'\n  setopt NO_GLOB_SUBST\nelse\n  case `(set -o) 2>/dev/null` in #(\n  *posix*) :\n    set -o posix ;; #(\n  *) :\n     ;;\nesac\nfi\n\n\nas_nl='\n'\nexport as_nl\n# Printing a long string crashes Solaris 7 /usr/bin/printf.\nas_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'\nas_echo=$as_echo$as_echo$as_echo$as_echo$as_echo\nas_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo\n# Prefer a ksh shell builtin over an external printf program on Solaris,\n# but without wasting forks for bash or zsh.\nif test -z \"$BASH_VERSION$ZSH_VERSION\" \\\n    && (test \"X`print -r -- $as_echo`\" = \"X$as_echo\") 2>/dev/null; then\n  as_echo='print -r --'\n  as_echo_n='print -rn --'\nelif (test \"X`printf %s $as_echo`\" = \"X$as_echo\") 2>/dev/null; then\n  as_echo='printf %s\\n'\n  as_echo_n='printf %s'\nelse\n  if test \"X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`\" = \"X-n $as_echo\"; then\n    as_echo_body='eval /usr/ucb/echo -n \"$1$as_nl\"'\n    as_echo_n='/usr/ucb/echo -n'\n  else\n    as_echo_body='eval expr \"X$1\" : \"X\\\\(.*\\\\)\"'\n    as_echo_n_body='eval\n      arg=$1;\n      case $arg in #(\n      *\"$as_nl\"*)\n\texpr \"X$arg\" : \"X\\\\(.*\\\\)$as_nl\";\n\targ=`expr \"X$arg\" : \".*$as_nl\\\\(.*\\\\)\"`;;\n      esac;\n      expr \"X$arg\" : \"X\\\\(.*\\\\)\" | tr -d \"$as_nl\"\n    '\n    export as_echo_n_body\n    as_echo_n='sh -c $as_echo_n_body as_echo'\n  fi\n  export as_echo_body\n  as_echo='sh -c $as_echo_body as_echo'\nfi\n\n# The user is always right.\nif test \"${PATH_SEPARATOR+set}\" != set; then\n  PATH_SEPARATOR=:\n  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {\n    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||\n      PATH_SEPARATOR=';'\n  }\nfi\n\n\n# IFS\n# We need space, tab and new line, in precisely that order.  Quoting is\n# there to prevent editors from complaining about space-tab.\n# (If _AS_PATH_WALK were called with IFS unset, it would disable word\n# splitting by setting IFS to empty value.)\nIFS=\" \"\"\t$as_nl\"\n\n# Find who we are.  Look in the path if we contain no directory separator.\ncase $0 in #((\n  *[\\\\/]* ) as_myself=$0 ;;\n  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    test -r \"$as_dir/$0\" && as_myself=$as_dir/$0 && break\n  done\nIFS=$as_save_IFS\n\n     ;;\nesac\n# We did not find ourselves, most probably we were run as `sh COMMAND'\n# in which case we are not to be found in the path.\nif test \"x$as_myself\" = x; then\n  as_myself=$0\nfi\nif test ! -f \"$as_myself\"; then\n  $as_echo \"$as_myself: error: cannot find myself; rerun with an absolute file name\" >&2\n  exit 1\nfi\n\n# Unset variables that we do not need and which cause bugs (e.g. in\n# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the \"|| exit 1\"\n# suppresses any \"Segmentation fault\" message there.  '((' could\n# trigger a bug in pdksh 5.2.14.\nfor as_var in BASH_ENV ENV MAIL MAILPATH\ndo eval test x\\${$as_var+set} = xset \\\n  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :\ndone\nPS1='$ '\nPS2='> '\nPS4='+ '\n\n# NLS nuisances.\nLC_ALL=C\nexport LC_ALL\nLANGUAGE=C\nexport LANGUAGE\n\n# CDPATH.\n(unset CDPATH) >/dev/null 2>&1 && unset CDPATH\n\nif test \"x$CONFIG_SHELL\" = x; then\n  as_bourne_compatible=\"if test -n \\\"\\${ZSH_VERSION+set}\\\" && (emulate sh) >/dev/null 2>&1; then :\n  emulate sh\n  NULLCMD=:\n  # Pre-4.2 versions of Zsh do word splitting on \\${1+\\\"\\$@\\\"}, which\n  # is contrary to our usage.  Disable this feature.\n  alias -g '\\${1+\\\"\\$@\\\"}'='\\\"\\$@\\\"'\n  setopt NO_GLOB_SUBST\nelse\n  case \\`(set -o) 2>/dev/null\\` in #(\n  *posix*) :\n    set -o posix ;; #(\n  *) :\n     ;;\nesac\nfi\n\"\n  as_required=\"as_fn_return () { (exit \\$1); }\nas_fn_success () { as_fn_return 0; }\nas_fn_failure () { as_fn_return 1; }\nas_fn_ret_success () { return 0; }\nas_fn_ret_failure () { return 1; }\n\nexitcode=0\nas_fn_success || { exitcode=1; echo as_fn_success failed.; }\nas_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }\nas_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }\nas_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }\nif ( set x; as_fn_ret_success y && test x = \\\"\\$1\\\" ); then :\n\nelse\n  exitcode=1; echo positional parameters were not saved.\nfi\ntest x\\$exitcode = x0 || exit 1\"\n  as_suggested=\"  as_lineno_1=\";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested\" as_lineno_1a=\\$LINENO\n  as_lineno_2=\";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested\" as_lineno_2a=\\$LINENO\n  eval 'test \\\"x\\$as_lineno_1'\\$as_run'\\\" != \\\"x\\$as_lineno_2'\\$as_run'\\\" &&\n  test \\\"x\\`expr \\$as_lineno_1'\\$as_run' + 1\\`\\\" = \\\"x\\$as_lineno_2'\\$as_run'\\\"' || exit 1\ntest \\$(( 1 + 1 )) = 2 || exit 1\"\n  if (eval \"$as_required\") 2>/dev/null; then :\n  as_have_required=yes\nelse\n  as_have_required=no\nfi\n  if test x$as_have_required = xyes && (eval \"$as_suggested\") 2>/dev/null; then :\n\nelse\n  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nas_found=false\nfor as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n  as_found=:\n  case $as_dir in #(\n\t /*)\n\t   for as_base in sh bash ksh sh5; do\n\t     # Try only shells that exist, to save several forks.\n\t     as_shell=$as_dir/$as_base\n\t     if { test -f \"$as_shell\" || test -f \"$as_shell.exe\"; } &&\n\t\t    { $as_echo \"$as_bourne_compatible\"\"$as_required\" | as_run=a \"$as_shell\"; } 2>/dev/null; then :\n  CONFIG_SHELL=$as_shell as_have_required=yes\n\t\t   if { $as_echo \"$as_bourne_compatible\"\"$as_suggested\" | as_run=a \"$as_shell\"; } 2>/dev/null; then :\n  break 2\nfi\nfi\n\t   done;;\n       esac\n  as_found=false\ndone\n$as_found || { if { test -f \"$SHELL\" || test -f \"$SHELL.exe\"; } &&\n\t      { $as_echo \"$as_bourne_compatible\"\"$as_required\" | as_run=a \"$SHELL\"; } 2>/dev/null; then :\n  CONFIG_SHELL=$SHELL as_have_required=yes\nfi; }\nIFS=$as_save_IFS\n\n\n      if test \"x$CONFIG_SHELL\" != x; then :\n  # We cannot yet assume a decent shell, so we have to provide a\n\t# neutralization value for shells without unset; and this also\n\t# works around shells that cannot unset nonexistent variables.\n\tBASH_ENV=/dev/null\n\tENV=/dev/null\n\t(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV\n\texport CONFIG_SHELL\n\texec \"$CONFIG_SHELL\" \"$as_myself\" ${1+\"$@\"}\nfi\n\n    if test x$as_have_required = xno; then :\n  $as_echo \"$0: This script requires a shell more modern than all\"\n  $as_echo \"$0: the shells that I found on your system.\"\n  if test x${ZSH_VERSION+set} = xset ; then\n    $as_echo \"$0: In particular, zsh $ZSH_VERSION has bugs and should\"\n    $as_echo \"$0: be upgraded to zsh 4.3.4 or later.\"\n  else\n    $as_echo \"$0: Please tell bug-autoconf@gnu.org and\n$0: http://firmware-mod-kit.googlecode.com about your\n$0: system, including any error possibly output before this\n$0: message. Then install a modern shell, or manually run\n$0: the script under such a shell if you do have one.\"\n  fi\n  exit 1\nfi\nfi\nfi\nSHELL=${CONFIG_SHELL-/bin/sh}\nexport SHELL\n# Unset more variables known to interfere with behavior of common tools.\nCLICOLOR_FORCE= GREP_OPTIONS=\nunset CLICOLOR_FORCE GREP_OPTIONS\n\n## --------------------- ##\n## M4sh Shell Functions. ##\n## --------------------- ##\n# as_fn_unset VAR\n# ---------------\n# Portably unset VAR.\nas_fn_unset ()\n{\n  { eval $1=; unset $1;}\n}\nas_unset=as_fn_unset\n\n# as_fn_set_status STATUS\n# -----------------------\n# Set $? to STATUS, without forking.\nas_fn_set_status ()\n{\n  return $1\n} # as_fn_set_status\n\n# as_fn_exit STATUS\n# -----------------\n# Exit the shell with STATUS, even in a \"trap 0\" or \"set -e\" context.\nas_fn_exit ()\n{\n  set +e\n  as_fn_set_status $1\n  exit $1\n} # as_fn_exit\n\n# as_fn_mkdir_p\n# -------------\n# Create \"$as_dir\" as a directory, including parents if necessary.\nas_fn_mkdir_p ()\n{\n\n  case $as_dir in #(\n  -*) as_dir=./$as_dir;;\n  esac\n  test -d \"$as_dir\" || eval $as_mkdir_p || {\n    as_dirs=\n    while :; do\n      case $as_dir in #(\n      *\\'*) as_qdir=`$as_echo \"$as_dir\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"`;; #'(\n      *) as_qdir=$as_dir;;\n      esac\n      as_dirs=\"'$as_qdir' $as_dirs\"\n      as_dir=`$as_dirname -- \"$as_dir\" ||\n$as_expr X\"$as_dir\" : 'X\\(.*[^/]\\)//*[^/][^/]*/*$' \\| \\\n\t X\"$as_dir\" : 'X\\(//\\)[^/]' \\| \\\n\t X\"$as_dir\" : 'X\\(//\\)$' \\| \\\n\t X\"$as_dir\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X\"$as_dir\" |\n    sed '/^X\\(.*[^/]\\)\\/\\/*[^/][^/]*\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)[^/].*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n      test -d \"$as_dir\" && break\n    done\n    test -z \"$as_dirs\" || eval \"mkdir $as_dirs\"\n  } || test -d \"$as_dir\" || as_fn_error \"cannot create directory $as_dir\"\n\n\n} # as_fn_mkdir_p\n# as_fn_append VAR VALUE\n# ----------------------\n# Append the text in VALUE to the end of the definition contained in VAR. Take\n# advantage of any shell optimizations that allow amortized linear growth over\n# repeated appends, instead of the typical quadratic growth present in naive\n# implementations.\nif (eval \"as_var=1; as_var+=2; test x\\$as_var = x12\") 2>/dev/null; then :\n  eval 'as_fn_append ()\n  {\n    eval $1+=\\$2\n  }'\nelse\n  as_fn_append ()\n  {\n    eval $1=\\$$1\\$2\n  }\nfi # as_fn_append\n\n# as_fn_arith ARG...\n# ------------------\n# Perform arithmetic evaluation on the ARGs, and store the result in the\n# global $as_val. Take advantage of shells that can avoid forks. The arguments\n# must be portable across $(()) and expr.\nif (eval \"test \\$(( 1 + 1 )) = 2\") 2>/dev/null; then :\n  eval 'as_fn_arith ()\n  {\n    as_val=$(( $* ))\n  }'\nelse\n  as_fn_arith ()\n  {\n    as_val=`expr \"$@\" || test $? -eq 1`\n  }\nfi # as_fn_arith\n\n\n# as_fn_error ERROR [LINENO LOG_FD]\n# ---------------------------------\n# Output \"`basename $0`: error: ERROR\" to stderr. If LINENO and LOG_FD are\n# provided, also output the error to LOG_FD, referencing LINENO. Then exit the\n# script with status $?, using 1 if that was 0.\nas_fn_error ()\n{\n  as_status=$?; test $as_status -eq 0 && as_status=1\n  if test \"$3\"; then\n    as_lineno=${as_lineno-\"$2\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n    $as_echo \"$as_me:${as_lineno-$LINENO}: error: $1\" >&$3\n  fi\n  $as_echo \"$as_me: error: $1\" >&2\n  as_fn_exit $as_status\n} # as_fn_error\n\nif expr a : '\\(a\\)' >/dev/null 2>&1 &&\n   test \"X`expr 00001 : '.*\\(...\\)'`\" = X001; then\n  as_expr=expr\nelse\n  as_expr=false\nfi\n\nif (basename -- /) >/dev/null 2>&1 && test \"X`basename -- / 2>&1`\" = \"X/\"; then\n  as_basename=basename\nelse\n  as_basename=false\nfi\n\nif (as_dir=`dirname -- /` && test \"X$as_dir\" = X/) >/dev/null 2>&1; then\n  as_dirname=dirname\nelse\n  as_dirname=false\nfi\n\nas_me=`$as_basename -- \"$0\" ||\n$as_expr X/\"$0\" : '.*/\\([^/][^/]*\\)/*$' \\| \\\n\t X\"$0\" : 'X\\(//\\)$' \\| \\\n\t X\"$0\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X/\"$0\" |\n    sed '/^.*\\/\\([^/][^/]*\\)\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\/\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\/\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n\n# Avoid depending upon Character Ranges.\nas_cr_letters='abcdefghijklmnopqrstuvwxyz'\nas_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'\nas_cr_Letters=$as_cr_letters$as_cr_LETTERS\nas_cr_digits='0123456789'\nas_cr_alnum=$as_cr_Letters$as_cr_digits\n\n\n  as_lineno_1=$LINENO as_lineno_1a=$LINENO\n  as_lineno_2=$LINENO as_lineno_2a=$LINENO\n  eval 'test \"x$as_lineno_1'$as_run'\" != \"x$as_lineno_2'$as_run'\" &&\n  test \"x`expr $as_lineno_1'$as_run' + 1`\" = \"x$as_lineno_2'$as_run'\"' || {\n  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)\n  sed -n '\n    p\n    /[$]LINENO/=\n  ' <$as_myself |\n    sed '\n      s/[$]LINENO.*/&-/\n      t lineno\n      b\n      :lineno\n      N\n      :loop\n      s/[$]LINENO\\([^'$as_cr_alnum'_].*\\n\\)\\(.*\\)/\\2\\1\\2/\n      t loop\n      s/-\\n.*//\n    ' >$as_me.lineno &&\n  chmod +x \"$as_me.lineno\" ||\n    { $as_echo \"$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell\" >&2; as_fn_exit 1; }\n\n  # Don't try to exec as it changes $[0], causing all sort of problems\n  # (the dirname of $[0] is not the place where we might find the\n  # original and so on.  Autoconf is especially sensitive to this).\n  . \"./$as_me.lineno\"\n  # Exit status is that of the last command.\n  exit\n}\n\nECHO_C= ECHO_N= ECHO_T=\ncase `echo -n x` in #(((((\n-n*)\n  case `echo 'xy\\c'` in\n  *c*) ECHO_T='\t';;\t# ECHO_T is single tab character.\n  xy)  ECHO_C='\\c';;\n  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null\n       ECHO_T='\t';;\n  esac;;\n*)\n  ECHO_N='-n';;\nesac\n\nrm -f conf$$ conf$$.exe conf$$.file\nif test -d conf$$.dir; then\n  rm -f conf$$.dir/conf$$.file\nelse\n  rm -f conf$$.dir\n  mkdir conf$$.dir 2>/dev/null\nfi\nif (echo >conf$$.file) 2>/dev/null; then\n  if ln -s conf$$.file conf$$ 2>/dev/null; then\n    as_ln_s='ln -s'\n    # ... but there are two gotchas:\n    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.\n    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.\n    # In both cases, we have to default to `cp -p'.\n    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||\n      as_ln_s='cp -p'\n  elif ln conf$$.file conf$$ 2>/dev/null; then\n    as_ln_s=ln\n  else\n    as_ln_s='cp -p'\n  fi\nelse\n  as_ln_s='cp -p'\nfi\nrm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file\nrmdir conf$$.dir 2>/dev/null\n\nif mkdir -p . 2>/dev/null; then\n  as_mkdir_p='mkdir -p \"$as_dir\"'\nelse\n  test -d ./-p && rmdir ./-p\n  as_mkdir_p=false\nfi\n\nif test -x / >/dev/null 2>&1; then\n  as_test_x='test -x'\nelse\n  if ls -dL / >/dev/null 2>&1; then\n    as_ls_L_option=L\n  else\n    as_ls_L_option=\n  fi\n  as_test_x='\n    eval sh -c '\\''\n      if test -d \"$1\"; then\n\ttest -d \"$1/.\";\n      else\n\tcase $1 in #(\n\t-*)set \"./$1\";;\n\tesac;\n\tcase `ls -ld'$as_ls_L_option' \"$1\" 2>/dev/null` in #((\n\t???[sx]*):;;*)false;;esac;fi\n    '\\'' sh\n  '\nfi\nas_executable_p=$as_test_x\n\n# Sed expression to map a string onto a valid CPP name.\nas_tr_cpp=\"eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'\"\n\n# Sed expression to map a string onto a valid variable name.\nas_tr_sh=\"eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'\"\n\n\ntest -n \"$DJDIR\" || exec 7<&0 </dev/null\nexec 6>&1\n\n# Name of the host.\n# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,\n# so uname gets run too.\nac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`\n\n#\n# Initializations.\n#\nac_default_prefix=/usr/local\nac_clean_files=\nac_config_libobj_dir=.\nLIBOBJS=\ncross_compiling=no\nsubdirs=\nMFLAGS=\nMAKEFLAGS=\n\n# Identity of this package.\nPACKAGE_NAME='Firmware Mod Kit'\nPACKAGE_TARNAME='firmware-mod-kit'\nPACKAGE_VERSION='0.4.0'\nPACKAGE_STRING='Firmware Mod Kit 0.4.0'\nPACKAGE_BUGREPORT='http://firmware-mod-kit.googlecode.com'\nPACKAGE_URL=''\n\n# Factoring default headers for most tests.\nac_includes_default=\"\\\n#include <stdio.h>\n#ifdef HAVE_SYS_TYPES_H\n# include <sys/types.h>\n#endif\n#ifdef HAVE_SYS_STAT_H\n# include <sys/stat.h>\n#endif\n#ifdef STDC_HEADERS\n# include <stdlib.h>\n# include <stddef.h>\n#else\n# ifdef HAVE_STDLIB_H\n#  include <stdlib.h>\n# endif\n#endif\n#ifdef HAVE_STRING_H\n# if !defined STDC_HEADERS && defined HAVE_MEMORY_H\n#  include <memory.h>\n# endif\n# include <string.h>\n#endif\n#ifdef HAVE_STRINGS_H\n# include <strings.h>\n#endif\n#ifdef HAVE_INTTYPES_H\n# include <inttypes.h>\n#endif\n#ifdef HAVE_STDINT_H\n# include <stdint.h>\n#endif\n#ifdef HAVE_UNISTD_H\n# include <unistd.h>\n#endif\"\n\nac_subst_vars='LTLIBOBJS\nLIBOBJS\nEGREP\nGREP\nCPP\nac_ct_CXX\nCXXFLAGS\nCXX\nOBJEXT\nEXEEXT\nac_ct_CC\nCPPFLAGS\nLDFLAGS\nCFLAGS\nCC\ntarget_alias\nhost_alias\nbuild_alias\nLIBS\nECHO_T\nECHO_N\nECHO_C\nDEFS\nmandir\nlocaledir\nlibdir\npsdir\npdfdir\ndvidir\nhtmldir\ninfodir\ndocdir\noldincludedir\nincludedir\nlocalstatedir\nsharedstatedir\nsysconfdir\ndatadir\ndatarootdir\nlibexecdir\nsbindir\nbindir\nprogram_transform_name\nprefix\nexec_prefix\nPACKAGE_URL\nPACKAGE_BUGREPORT\nPACKAGE_STRING\nPACKAGE_VERSION\nPACKAGE_TARNAME\nPACKAGE_NAME\nPATH_SEPARATOR\nSHELL'\nac_subst_files=''\nac_user_opts='\nenable_option_checking\n'\n      ac_precious_vars='build_alias\nhost_alias\ntarget_alias\nCC\nCFLAGS\nLDFLAGS\nLIBS\nCPPFLAGS\nCXX\nCXXFLAGS\nCCC\nCPP'\n\n\n# Initialize some variables set by options.\nac_init_help=\nac_init_version=false\nac_unrecognized_opts=\nac_unrecognized_sep=\n# The variables have the same names as the options, with\n# dashes changed to underlines.\ncache_file=/dev/null\nexec_prefix=NONE\nno_create=\nno_recursion=\nprefix=NONE\nprogram_prefix=NONE\nprogram_suffix=NONE\nprogram_transform_name=s,x,x,\nsilent=\nsite=\nsrcdir=\nverbose=\nx_includes=NONE\nx_libraries=NONE\n\n# Installation directory options.\n# These are left unexpanded so users can \"make install exec_prefix=/foo\"\n# and all the variables that are supposed to be based on exec_prefix\n# by default will actually change.\n# Use braces instead of parens because sh, perl, etc. also accept them.\n# (The list follows the same order as the GNU Coding Standards.)\nbindir='${exec_prefix}/bin'\nsbindir='${exec_prefix}/sbin'\nlibexecdir='${exec_prefix}/libexec'\ndatarootdir='${prefix}/share'\ndatadir='${datarootdir}'\nsysconfdir='${prefix}/etc'\nsharedstatedir='${prefix}/com'\nlocalstatedir='${prefix}/var'\nincludedir='${prefix}/include'\noldincludedir='/usr/include'\ndocdir='${datarootdir}/doc/${PACKAGE_TARNAME}'\ninfodir='${datarootdir}/info'\nhtmldir='${docdir}'\ndvidir='${docdir}'\npdfdir='${docdir}'\npsdir='${docdir}'\nlibdir='${exec_prefix}/lib'\nlocaledir='${datarootdir}/locale'\nmandir='${datarootdir}/man'\n\nac_prev=\nac_dashdash=\nfor ac_option\ndo\n  # If the previous option needs an argument, assign it.\n  if test -n \"$ac_prev\"; then\n    eval $ac_prev=\\$ac_option\n    ac_prev=\n    continue\n  fi\n\n  case $ac_option in\n  *=*)\tac_optarg=`expr \"X$ac_option\" : '[^=]*=\\(.*\\)'` ;;\n  *)\tac_optarg=yes ;;\n  esac\n\n  # Accept the important Cygnus configure options, so we can diagnose typos.\n\n  case $ac_dashdash$ac_option in\n  --)\n    ac_dashdash=yes ;;\n\n  -bindir | --bindir | --bindi | --bind | --bin | --bi)\n    ac_prev=bindir ;;\n  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)\n    bindir=$ac_optarg ;;\n\n  -build | --build | --buil | --bui | --bu)\n    ac_prev=build_alias ;;\n  -build=* | --build=* | --buil=* | --bui=* | --bu=*)\n    build_alias=$ac_optarg ;;\n\n  -cache-file | --cache-file | --cache-fil | --cache-fi \\\n  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)\n    ac_prev=cache_file ;;\n  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \\\n  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)\n    cache_file=$ac_optarg ;;\n\n  --config-cache | -C)\n    cache_file=config.cache ;;\n\n  -datadir | --datadir | --datadi | --datad)\n    ac_prev=datadir ;;\n  -datadir=* | --datadir=* | --datadi=* | --datad=*)\n    datadir=$ac_optarg ;;\n\n  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \\\n  | --dataroo | --dataro | --datar)\n    ac_prev=datarootdir ;;\n  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \\\n  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)\n    datarootdir=$ac_optarg ;;\n\n  -disable-* | --disable-*)\n    ac_useropt=`expr \"x$ac_option\" : 'x-*disable-\\(.*\\)'`\n    # Reject names that are not valid shell variable names.\n    expr \"x$ac_useropt\" : \".*[^-+._$as_cr_alnum]\" >/dev/null &&\n      as_fn_error \"invalid feature name: $ac_useropt\"\n    ac_useropt_orig=$ac_useropt\n    ac_useropt=`$as_echo \"$ac_useropt\" | sed 's/[-+.]/_/g'`\n    case $ac_user_opts in\n      *\"\n\"enable_$ac_useropt\"\n\"*) ;;\n      *) ac_unrecognized_opts=\"$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig\"\n\t ac_unrecognized_sep=', ';;\n    esac\n    eval enable_$ac_useropt=no ;;\n\n  -docdir | --docdir | --docdi | --doc | --do)\n    ac_prev=docdir ;;\n  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)\n    docdir=$ac_optarg ;;\n\n  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)\n    ac_prev=dvidir ;;\n  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)\n    dvidir=$ac_optarg ;;\n\n  -enable-* | --enable-*)\n    ac_useropt=`expr \"x$ac_option\" : 'x-*enable-\\([^=]*\\)'`\n    # Reject names that are not valid shell variable names.\n    expr \"x$ac_useropt\" : \".*[^-+._$as_cr_alnum]\" >/dev/null &&\n      as_fn_error \"invalid feature name: $ac_useropt\"\n    ac_useropt_orig=$ac_useropt\n    ac_useropt=`$as_echo \"$ac_useropt\" | sed 's/[-+.]/_/g'`\n    case $ac_user_opts in\n      *\"\n\"enable_$ac_useropt\"\n\"*) ;;\n      *) ac_unrecognized_opts=\"$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig\"\n\t ac_unrecognized_sep=', ';;\n    esac\n    eval enable_$ac_useropt=\\$ac_optarg ;;\n\n  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \\\n  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \\\n  | --exec | --exe | --ex)\n    ac_prev=exec_prefix ;;\n  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \\\n  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \\\n  | --exec=* | --exe=* | --ex=*)\n    exec_prefix=$ac_optarg ;;\n\n  -gas | --gas | --ga | --g)\n    # Obsolete; use --with-gas.\n    with_gas=yes ;;\n\n  -help | --help | --hel | --he | -h)\n    ac_init_help=long ;;\n  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)\n    ac_init_help=recursive ;;\n  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)\n    ac_init_help=short ;;\n\n  -host | --host | --hos | --ho)\n    ac_prev=host_alias ;;\n  -host=* | --host=* | --hos=* | --ho=*)\n    host_alias=$ac_optarg ;;\n\n  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)\n    ac_prev=htmldir ;;\n  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \\\n  | --ht=*)\n    htmldir=$ac_optarg ;;\n\n  -includedir | --includedir | --includedi | --included | --include \\\n  | --includ | --inclu | --incl | --inc)\n    ac_prev=includedir ;;\n  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \\\n  | --includ=* | --inclu=* | --incl=* | --inc=*)\n    includedir=$ac_optarg ;;\n\n  -infodir | --infodir | --infodi | --infod | --info | --inf)\n    ac_prev=infodir ;;\n  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)\n    infodir=$ac_optarg ;;\n\n  -libdir | --libdir | --libdi | --libd)\n    ac_prev=libdir ;;\n  -libdir=* | --libdir=* | --libdi=* | --libd=*)\n    libdir=$ac_optarg ;;\n\n  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \\\n  | --libexe | --libex | --libe)\n    ac_prev=libexecdir ;;\n  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \\\n  | --libexe=* | --libex=* | --libe=*)\n    libexecdir=$ac_optarg ;;\n\n  -localedir | --localedir | --localedi | --localed | --locale)\n    ac_prev=localedir ;;\n  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)\n    localedir=$ac_optarg ;;\n\n  -localstatedir | --localstatedir | --localstatedi | --localstated \\\n  | --localstate | --localstat | --localsta | --localst | --locals)\n    ac_prev=localstatedir ;;\n  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \\\n  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)\n    localstatedir=$ac_optarg ;;\n\n  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)\n    ac_prev=mandir ;;\n  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)\n    mandir=$ac_optarg ;;\n\n  -nfp | --nfp | --nf)\n    # Obsolete; use --without-fp.\n    with_fp=no ;;\n\n  -no-create | --no-create | --no-creat | --no-crea | --no-cre \\\n  | --no-cr | --no-c | -n)\n    no_create=yes ;;\n\n  -no-recursion | --no-recursion | --no-recursio | --no-recursi \\\n  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)\n    no_recursion=yes ;;\n\n  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \\\n  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \\\n  | --oldin | --oldi | --old | --ol | --o)\n    ac_prev=oldincludedir ;;\n  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \\\n  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \\\n  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)\n    oldincludedir=$ac_optarg ;;\n\n  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)\n    ac_prev=prefix ;;\n  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)\n    prefix=$ac_optarg ;;\n\n  -program-prefix | --program-prefix | --program-prefi | --program-pref \\\n  | --program-pre | --program-pr | --program-p)\n    ac_prev=program_prefix ;;\n  -program-prefix=* | --program-prefix=* | --program-prefi=* \\\n  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)\n    program_prefix=$ac_optarg ;;\n\n  -program-suffix | --program-suffix | --program-suffi | --program-suff \\\n  | --program-suf | --program-su | --program-s)\n    ac_prev=program_suffix ;;\n  -program-suffix=* | --program-suffix=* | --program-suffi=* \\\n  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)\n    program_suffix=$ac_optarg ;;\n\n  -program-transform-name | --program-transform-name \\\n  | --program-transform-nam | --program-transform-na \\\n  | --program-transform-n | --program-transform- \\\n  | --program-transform | --program-transfor \\\n  | --program-transfo | --program-transf \\\n  | --program-trans | --program-tran \\\n  | --progr-tra | --program-tr | --program-t)\n    ac_prev=program_transform_name ;;\n  -program-transform-name=* | --program-transform-name=* \\\n  | --program-transform-nam=* | --program-transform-na=* \\\n  | --program-transform-n=* | --program-transform-=* \\\n  | --program-transform=* | --program-transfor=* \\\n  | --program-transfo=* | --program-transf=* \\\n  | --program-trans=* | --program-tran=* \\\n  | --progr-tra=* | --program-tr=* | --program-t=*)\n    program_transform_name=$ac_optarg ;;\n\n  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)\n    ac_prev=pdfdir ;;\n  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)\n    pdfdir=$ac_optarg ;;\n\n  -psdir | --psdir | --psdi | --psd | --ps)\n    ac_prev=psdir ;;\n  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)\n    psdir=$ac_optarg ;;\n\n  -q | -quiet | --quiet | --quie | --qui | --qu | --q \\\n  | -silent | --silent | --silen | --sile | --sil)\n    silent=yes ;;\n\n  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)\n    ac_prev=sbindir ;;\n  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \\\n  | --sbi=* | --sb=*)\n    sbindir=$ac_optarg ;;\n\n  -sharedstatedir | --sharedstatedir | --sharedstatedi \\\n  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \\\n  | --sharedst | --shareds | --shared | --share | --shar \\\n  | --sha | --sh)\n    ac_prev=sharedstatedir ;;\n  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \\\n  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \\\n  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \\\n  | --sha=* | --sh=*)\n    sharedstatedir=$ac_optarg ;;\n\n  -site | --site | --sit)\n    ac_prev=site ;;\n  -site=* | --site=* | --sit=*)\n    site=$ac_optarg ;;\n\n  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)\n    ac_prev=srcdir ;;\n  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)\n    srcdir=$ac_optarg ;;\n\n  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \\\n  | --syscon | --sysco | --sysc | --sys | --sy)\n    ac_prev=sysconfdir ;;\n  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \\\n  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)\n    sysconfdir=$ac_optarg ;;\n\n  -target | --target | --targe | --targ | --tar | --ta | --t)\n    ac_prev=target_alias ;;\n  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)\n    target_alias=$ac_optarg ;;\n\n  -v | -verbose | --verbose | --verbos | --verbo | --verb)\n    verbose=yes ;;\n\n  -version | --version | --versio | --versi | --vers | -V)\n    ac_init_version=: ;;\n\n  -with-* | --with-*)\n    ac_useropt=`expr \"x$ac_option\" : 'x-*with-\\([^=]*\\)'`\n    # Reject names that are not valid shell variable names.\n    expr \"x$ac_useropt\" : \".*[^-+._$as_cr_alnum]\" >/dev/null &&\n      as_fn_error \"invalid package name: $ac_useropt\"\n    ac_useropt_orig=$ac_useropt\n    ac_useropt=`$as_echo \"$ac_useropt\" | sed 's/[-+.]/_/g'`\n    case $ac_user_opts in\n      *\"\n\"with_$ac_useropt\"\n\"*) ;;\n      *) ac_unrecognized_opts=\"$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig\"\n\t ac_unrecognized_sep=', ';;\n    esac\n    eval with_$ac_useropt=\\$ac_optarg ;;\n\n  -without-* | --without-*)\n    ac_useropt=`expr \"x$ac_option\" : 'x-*without-\\(.*\\)'`\n    # Reject names that are not valid shell variable names.\n    expr \"x$ac_useropt\" : \".*[^-+._$as_cr_alnum]\" >/dev/null &&\n      as_fn_error \"invalid package name: $ac_useropt\"\n    ac_useropt_orig=$ac_useropt\n    ac_useropt=`$as_echo \"$ac_useropt\" | sed 's/[-+.]/_/g'`\n    case $ac_user_opts in\n      *\"\n\"with_$ac_useropt\"\n\"*) ;;\n      *) ac_unrecognized_opts=\"$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig\"\n\t ac_unrecognized_sep=', ';;\n    esac\n    eval with_$ac_useropt=no ;;\n\n  --x)\n    # Obsolete; use --with-x.\n    with_x=yes ;;\n\n  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \\\n  | --x-incl | --x-inc | --x-in | --x-i)\n    ac_prev=x_includes ;;\n  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \\\n  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)\n    x_includes=$ac_optarg ;;\n\n  -x-libraries | --x-libraries | --x-librarie | --x-librari \\\n  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)\n    ac_prev=x_libraries ;;\n  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \\\n  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)\n    x_libraries=$ac_optarg ;;\n\n  -*) as_fn_error \"unrecognized option: \\`$ac_option'\nTry \\`$0 --help' for more information.\"\n    ;;\n\n  *=*)\n    ac_envvar=`expr \"x$ac_option\" : 'x\\([^=]*\\)='`\n    # Reject names that are not valid shell variable names.\n    case $ac_envvar in #(\n      '' | [0-9]* | *[!_$as_cr_alnum]* )\n      as_fn_error \"invalid variable name: \\`$ac_envvar'\" ;;\n    esac\n    eval $ac_envvar=\\$ac_optarg\n    export $ac_envvar ;;\n\n  *)\n    # FIXME: should be removed in autoconf 3.0.\n    $as_echo \"$as_me: WARNING: you should use --build, --host, --target\" >&2\n    expr \"x$ac_option\" : \".*[^-._$as_cr_alnum]\" >/dev/null &&\n      $as_echo \"$as_me: WARNING: invalid host type: $ac_option\" >&2\n    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}\n    ;;\n\n  esac\ndone\n\nif test -n \"$ac_prev\"; then\n  ac_option=--`echo $ac_prev | sed 's/_/-/g'`\n  as_fn_error \"missing argument to $ac_option\"\nfi\n\nif test -n \"$ac_unrecognized_opts\"; then\n  case $enable_option_checking in\n    no) ;;\n    fatal) as_fn_error \"unrecognized options: $ac_unrecognized_opts\" ;;\n    *)     $as_echo \"$as_me: WARNING: unrecognized options: $ac_unrecognized_opts\" >&2 ;;\n  esac\nfi\n\n# Check all directory arguments for consistency.\nfor ac_var in\texec_prefix prefix bindir sbindir libexecdir datarootdir \\\n\t\tdatadir sysconfdir sharedstatedir localstatedir includedir \\\n\t\toldincludedir docdir infodir htmldir dvidir pdfdir psdir \\\n\t\tlibdir localedir mandir\ndo\n  eval ac_val=\\$$ac_var\n  # Remove trailing slashes.\n  case $ac_val in\n    */ )\n      ac_val=`expr \"X$ac_val\" : 'X\\(.*[^/]\\)' \\| \"X$ac_val\" : 'X\\(.*\\)'`\n      eval $ac_var=\\$ac_val;;\n  esac\n  # Be sure to have absolute directory names.\n  case $ac_val in\n    [\\\\/$]* | ?:[\\\\/]* )  continue;;\n    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;\n  esac\n  as_fn_error \"expected an absolute directory name for --$ac_var: $ac_val\"\ndone\n\n# There might be people who depend on the old broken behavior: `$host'\n# used to hold the argument of --host etc.\n# FIXME: To remove some day.\nbuild=$build_alias\nhost=$host_alias\ntarget=$target_alias\n\n# FIXME: To remove some day.\nif test \"x$host_alias\" != x; then\n  if test \"x$build_alias\" = x; then\n    cross_compiling=maybe\n    $as_echo \"$as_me: WARNING: If you wanted to set the --build type, don't use --host.\n    If a cross compiler is detected then cross compile mode will be used.\" >&2\n  elif test \"x$build_alias\" != \"x$host_alias\"; then\n    cross_compiling=yes\n  fi\nfi\n\nac_tool_prefix=\ntest -n \"$host_alias\" && ac_tool_prefix=$host_alias-\n\ntest \"$silent\" = yes && exec 6>/dev/null\n\n\nac_pwd=`pwd` && test -n \"$ac_pwd\" &&\nac_ls_di=`ls -di .` &&\nac_pwd_ls_di=`cd \"$ac_pwd\" && ls -di .` ||\n  as_fn_error \"working directory cannot be determined\"\ntest \"X$ac_ls_di\" = \"X$ac_pwd_ls_di\" ||\n  as_fn_error \"pwd does not report name of working directory\"\n\n\n# Find the source files, if location was not specified.\nif test -z \"$srcdir\"; then\n  ac_srcdir_defaulted=yes\n  # Try the directory containing this script, then the parent directory.\n  ac_confdir=`$as_dirname -- \"$as_myself\" ||\n$as_expr X\"$as_myself\" : 'X\\(.*[^/]\\)//*[^/][^/]*/*$' \\| \\\n\t X\"$as_myself\" : 'X\\(//\\)[^/]' \\| \\\n\t X\"$as_myself\" : 'X\\(//\\)$' \\| \\\n\t X\"$as_myself\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X\"$as_myself\" |\n    sed '/^X\\(.*[^/]\\)\\/\\/*[^/][^/]*\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)[^/].*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n  srcdir=$ac_confdir\n  if test ! -r \"$srcdir/$ac_unique_file\"; then\n    srcdir=..\n  fi\nelse\n  ac_srcdir_defaulted=no\nfi\nif test ! -r \"$srcdir/$ac_unique_file\"; then\n  test \"$ac_srcdir_defaulted\" = yes && srcdir=\"$ac_confdir or ..\"\n  as_fn_error \"cannot find sources ($ac_unique_file) in $srcdir\"\nfi\nac_msg=\"sources are in $srcdir, but \\`cd $srcdir' does not work\"\nac_abs_confdir=`(\n\tcd \"$srcdir\" && test -r \"./$ac_unique_file\" || as_fn_error \"$ac_msg\"\n\tpwd)`\n# When building in place, set srcdir=.\nif test \"$ac_abs_confdir\" = \"$ac_pwd\"; then\n  srcdir=.\nfi\n# Remove unnecessary trailing slashes from srcdir.\n# Double slashes in file names in object file debugging info\n# mess up M-x gdb in Emacs.\ncase $srcdir in\n*/) srcdir=`expr \"X$srcdir\" : 'X\\(.*[^/]\\)' \\| \"X$srcdir\" : 'X\\(.*\\)'`;;\nesac\nfor ac_var in $ac_precious_vars; do\n  eval ac_env_${ac_var}_set=\\${${ac_var}+set}\n  eval ac_env_${ac_var}_value=\\$${ac_var}\n  eval ac_cv_env_${ac_var}_set=\\${${ac_var}+set}\n  eval ac_cv_env_${ac_var}_value=\\$${ac_var}\ndone\n\n#\n# Report the --help message.\n#\nif test \"$ac_init_help\" = \"long\"; then\n  # Omit some internal or obsolete options to make the list less imposing.\n  # This message is too long to be a string in the A/UX 3.1 sh.\n  cat <<_ACEOF\n\\`configure' configures Firmware Mod Kit 0.4.0 to adapt to many kinds of systems.\n\nUsage: $0 [OPTION]... [VAR=VALUE]...\n\nTo assign environment variables (e.g., CC, CFLAGS...), specify them as\nVAR=VALUE.  See below for descriptions of some of the useful variables.\n\nDefaults for the options are specified in brackets.\n\nConfiguration:\n  -h, --help              display this help and exit\n      --help=short        display options specific to this package\n      --help=recursive    display the short help of all the included packages\n  -V, --version           display version information and exit\n  -q, --quiet, --silent   do not print \\`checking...' messages\n      --cache-file=FILE   cache test results in FILE [disabled]\n  -C, --config-cache      alias for \\`--cache-file=config.cache'\n  -n, --no-create         do not create output files\n      --srcdir=DIR        find the sources in DIR [configure dir or \\`..']\n\nInstallation directories:\n  --prefix=PREFIX         install architecture-independent files in PREFIX\n                          [$ac_default_prefix]\n  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX\n                          [PREFIX]\n\nBy default, \\`make install' will install all the files in\n\\`$ac_default_prefix/bin', \\`$ac_default_prefix/lib' etc.  You can specify\nan installation prefix other than \\`$ac_default_prefix' using \\`--prefix',\nfor instance \\`--prefix=\\$HOME'.\n\nFor better control, use the options below.\n\nFine tuning of the installation directories:\n  --bindir=DIR            user executables [EPREFIX/bin]\n  --sbindir=DIR           system admin executables [EPREFIX/sbin]\n  --libexecdir=DIR        program executables [EPREFIX/libexec]\n  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]\n  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]\n  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]\n  --libdir=DIR            object code libraries [EPREFIX/lib]\n  --includedir=DIR        C header files [PREFIX/include]\n  --oldincludedir=DIR     C header files for non-gcc [/usr/include]\n  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]\n  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]\n  --infodir=DIR           info documentation [DATAROOTDIR/info]\n  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]\n  --mandir=DIR            man documentation [DATAROOTDIR/man]\n  --docdir=DIR            documentation root\n                          [DATAROOTDIR/doc/firmware-mod-kit]\n  --htmldir=DIR           html documentation [DOCDIR]\n  --dvidir=DIR            dvi documentation [DOCDIR]\n  --pdfdir=DIR            pdf documentation [DOCDIR]\n  --psdir=DIR             ps documentation [DOCDIR]\n_ACEOF\n\n  cat <<\\_ACEOF\n_ACEOF\nfi\n\nif test -n \"$ac_init_help\"; then\n  case $ac_init_help in\n     short | recursive ) echo \"Configuration of Firmware Mod Kit 0.4.0:\";;\n   esac\n  cat <<\\_ACEOF\n\nSome influential environment variables:\n  CC          C compiler command\n  CFLAGS      C compiler flags\n  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a\n              nonstandard directory <lib dir>\n  LIBS        libraries to pass to the linker, e.g. -l<library>\n  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if\n              you have headers in a nonstandard directory <include dir>\n  CXX         C++ compiler command\n  CXXFLAGS    C++ compiler flags\n  CPP         C preprocessor\n\nUse these variables to override the choices made by `configure' or to help\nit to find libraries and programs with nonstandard names/locations.\n\nReport bugs to <http://firmware-mod-kit.googlecode.com>.\n_ACEOF\nac_status=$?\nfi\n\nif test \"$ac_init_help\" = \"recursive\"; then\n  # If there are subdirs, report their specific --help.\n  for ac_dir in : $ac_subdirs_all; do test \"x$ac_dir\" = x: && continue\n    test -d \"$ac_dir\" ||\n      { cd \"$srcdir\" && ac_pwd=`pwd` && srcdir=. && test -d \"$ac_dir\"; } ||\n      continue\n    ac_builddir=.\n\ncase \"$ac_dir\" in\n.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;\n*)\n  ac_dir_suffix=/`$as_echo \"$ac_dir\" | sed 's|^\\.[\\\\/]||'`\n  # A \"..\" for each directory in $ac_dir_suffix.\n  ac_top_builddir_sub=`$as_echo \"$ac_dir_suffix\" | sed 's|/[^\\\\/]*|/..|g;s|/||'`\n  case $ac_top_builddir_sub in\n  \"\") ac_top_builddir_sub=. ac_top_build_prefix= ;;\n  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;\n  esac ;;\nesac\nac_abs_top_builddir=$ac_pwd\nac_abs_builddir=$ac_pwd$ac_dir_suffix\n# for backward compatibility:\nac_top_builddir=$ac_top_build_prefix\n\ncase $srcdir in\n  .)  # We are building in place.\n    ac_srcdir=.\n    ac_top_srcdir=$ac_top_builddir_sub\n    ac_abs_top_srcdir=$ac_pwd ;;\n  [\\\\/]* | ?:[\\\\/]* )  # Absolute name.\n    ac_srcdir=$srcdir$ac_dir_suffix;\n    ac_top_srcdir=$srcdir\n    ac_abs_top_srcdir=$srcdir ;;\n  *) # Relative name.\n    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix\n    ac_top_srcdir=$ac_top_build_prefix$srcdir\n    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;\nesac\nac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix\n\n    cd \"$ac_dir\" || { ac_status=$?; continue; }\n    # Check for guested configure.\n    if test -f \"$ac_srcdir/configure.gnu\"; then\n      echo &&\n      $SHELL \"$ac_srcdir/configure.gnu\" --help=recursive\n    elif test -f \"$ac_srcdir/configure\"; then\n      echo &&\n      $SHELL \"$ac_srcdir/configure\" --help=recursive\n    else\n      $as_echo \"$as_me: WARNING: no configuration information is in $ac_dir\" >&2\n    fi || ac_status=$?\n    cd \"$ac_pwd\" || { ac_status=$?; break; }\n  done\nfi\n\ntest -n \"$ac_init_help\" && exit $ac_status\nif $ac_init_version; then\n  cat <<\\_ACEOF\nFirmware Mod Kit configure 0.4.0\ngenerated by GNU Autoconf 2.65\n\nCopyright (C) 2009 Free Software Foundation, Inc.\nThis configure script is free software; the Free Software Foundation\ngives unlimited permission to copy, distribute and modify it.\n_ACEOF\n  exit\nfi\n\n## ------------------------ ##\n## Autoconf initialization. ##\n## ------------------------ ##\n\n# ac_fn_c_try_compile LINENO\n# --------------------------\n# Try to compile conftest.$ac_ext, and return whether this succeeded.\nac_fn_c_try_compile ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  rm -f conftest.$ac_objext\n  if { { ac_try=\"$ac_compile\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_compile\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    grep -v '^ *+' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n    mv -f conftest.er1 conftest.err\n  fi\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; } && {\n\t test -z \"$ac_c_werror_flag\" ||\n\t test ! -s conftest.err\n       } && test -s conftest.$ac_objext; then :\n  ac_retval=0\nelse\n  $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n\tac_retval=1\nfi\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n  as_fn_set_status $ac_retval\n\n} # ac_fn_c_try_compile\n\n# ac_fn_cxx_try_compile LINENO\n# ----------------------------\n# Try to compile conftest.$ac_ext, and return whether this succeeded.\nac_fn_cxx_try_compile ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  rm -f conftest.$ac_objext\n  if { { ac_try=\"$ac_compile\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_compile\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    grep -v '^ *+' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n    mv -f conftest.er1 conftest.err\n  fi\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; } && {\n\t test -z \"$ac_cxx_werror_flag\" ||\n\t test ! -s conftest.err\n       } && test -s conftest.$ac_objext; then :\n  ac_retval=0\nelse\n  $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n\tac_retval=1\nfi\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n  as_fn_set_status $ac_retval\n\n} # ac_fn_cxx_try_compile\n\n# ac_fn_c_check_type LINENO TYPE VAR INCLUDES\n# -------------------------------------------\n# Tests whether TYPE exists after having included INCLUDES, setting cache\n# variable VAR accordingly.\nac_fn_c_check_type ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  eval \"$3=no\"\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n$4\nint\nmain ()\n{\nif (sizeof ($2))\n\t return 0;\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n$4\nint\nmain ()\n{\nif (sizeof (($2)))\n\t    return 0;\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n\nelse\n  eval \"$3=yes\"\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n\n} # ac_fn_c_check_type\n\n# ac_fn_c_try_cpp LINENO\n# ----------------------\n# Try to preprocess conftest.$ac_ext, and return whether this succeeded.\nac_fn_c_try_cpp ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  if { { ac_try=\"$ac_cpp conftest.$ac_ext\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_cpp conftest.$ac_ext\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    grep -v '^ *+' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n    mv -f conftest.er1 conftest.err\n  fi\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; } >/dev/null && {\n\t test -z \"$ac_c_preproc_warn_flag$ac_c_werror_flag\" ||\n\t test ! -s conftest.err\n       }; then :\n  ac_retval=0\nelse\n  $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n    ac_retval=1\nfi\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n  as_fn_set_status $ac_retval\n\n} # ac_fn_c_try_cpp\n\n# ac_fn_c_try_run LINENO\n# ----------------------\n# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes\n# that executables *can* be run.\nac_fn_c_try_run ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  if { { ac_try=\"$ac_link\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'\n  { { case \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_try\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; }; then :\n  ac_retval=0\nelse\n  $as_echo \"$as_me: program exited with status $ac_status\" >&5\n       $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n       ac_retval=$ac_status\nfi\n  rm -rf conftest.dSYM conftest_ipa8_conftest.oo\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n  as_fn_set_status $ac_retval\n\n} # ac_fn_c_try_run\n\n# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES\n# -------------------------------------------------------\n# Tests whether HEADER exists and can be compiled using the include files in\n# INCLUDES, setting the cache variable VAR accordingly.\nac_fn_c_check_header_compile ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n$4\n#include <$2>\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  eval \"$3=yes\"\nelse\n  eval \"$3=no\"\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n\n} # ac_fn_c_check_header_compile\n\n# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES\n# -------------------------------------------------------\n# Tests whether HEADER exists, giving a warning if it cannot be compiled using\n# the include files in INCLUDES and setting the cache variable VAR\n# accordingly.\nac_fn_c_check_header_mongrel ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  if { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\nelse\n  # Is the header compilable?\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking $2 usability\" >&5\n$as_echo_n \"checking $2 usability... \" >&6; }\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n$4\n#include <$2>\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_header_compiler=yes\nelse\n  ac_header_compiler=no\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler\" >&5\n$as_echo \"$ac_header_compiler\" >&6; }\n\n# Is the header present?\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking $2 presence\" >&5\n$as_echo_n \"checking $2 presence... \" >&6; }\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <$2>\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n  ac_header_preproc=yes\nelse\n  ac_header_preproc=no\nfi\nrm -f conftest.err conftest.$ac_ext\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc\" >&5\n$as_echo \"$ac_header_preproc\" >&6; }\n\n# So?  What about this header?\ncase $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((\n  yes:no: )\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!\" >&5\n$as_echo \"$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result\" >&5\n$as_echo \"$as_me: WARNING: $2: proceeding with the compiler's result\" >&2;}\n    ;;\n  no:yes:* )\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled\" >&5\n$as_echo \"$as_me: WARNING: $2: present but cannot be compiled\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?\" >&5\n$as_echo \"$as_me: WARNING: $2:     check for missing prerequisite headers?\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation\" >&5\n$as_echo \"$as_me: WARNING: $2: see the Autoconf documentation\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \\\"Present But Cannot Be Compiled\\\"\" >&5\n$as_echo \"$as_me: WARNING: $2:     section \\\"Present But Cannot Be Compiled\\\"\" >&2;}\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result\" >&5\n$as_echo \"$as_me: WARNING: $2: proceeding with the compiler's result\" >&2;}\n( cat <<\\_ASBOX\n## ----------------------------------------------------- ##\n## Report this to http://firmware-mod-kit.googlecode.com ##\n## ----------------------------------------------------- ##\n_ASBOX\n     ) | sed \"s/^/$as_me: WARNING:     /\" >&2\n    ;;\nesac\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  eval \"$3=\\$ac_header_compiler\"\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\nfi\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n\n} # ac_fn_c_check_header_mongrel\n\n# ac_fn_c_try_link LINENO\n# -----------------------\n# Try to link conftest.$ac_ext, and return whether this succeeded.\nac_fn_c_try_link ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  rm -f conftest.$ac_objext conftest$ac_exeext\n  if { { ac_try=\"$ac_link\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    grep -v '^ *+' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n    mv -f conftest.er1 conftest.err\n  fi\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; } && {\n\t test -z \"$ac_c_werror_flag\" ||\n\t test ! -s conftest.err\n       } && test -s conftest$ac_exeext && {\n\t test \"$cross_compiling\" = yes ||\n\t $as_test_x conftest$ac_exeext\n       }; then :\n  ac_retval=0\nelse\n  $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n\tac_retval=1\nfi\n  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information\n  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would\n  # interfere with the next link command; also delete a directory that is\n  # left behind by Apple's compiler.  We do this before executing the actions.\n  rm -rf conftest.dSYM conftest_ipa8_conftest.oo\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n  as_fn_set_status $ac_retval\n\n} # ac_fn_c_try_link\n\n# ac_fn_c_check_func LINENO FUNC VAR\n# ----------------------------------\n# Tests whether FUNC exists, setting the cache variable VAR accordingly\nac_fn_c_check_func ()\n{\n  as_lineno=${as_lineno-\"$1\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $2\" >&5\n$as_echo_n \"checking for $2... \" >&6; }\nif { as_var=$3; eval \"test \\\"\\${$as_var+set}\\\" = set\"; }; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n/* Define $2 to an innocuous variant, in case <limits.h> declares $2.\n   For example, HP-UX 11i <limits.h> declares gettimeofday.  */\n#define $2 innocuous_$2\n\n/* System header to define __stub macros and hopefully few prototypes,\n    which can conflict with char $2 (); below.\n    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since\n    <limits.h> exists even on freestanding compilers.  */\n\n#ifdef __STDC__\n# include <limits.h>\n#else\n# include <assert.h>\n#endif\n\n#undef $2\n\n/* Override any GCC internal prototype to avoid an error.\n   Use char because int might match the return type of a GCC\n   builtin and then its argument prototype would still apply.  */\n#ifdef __cplusplus\nextern \"C\"\n#endif\nchar $2 ();\n/* The GNU C library defines this for functions which it implements\n    to always fail with ENOSYS.  Some functions are actually named\n    something starting with __ and the normal name is an alias.  */\n#if defined __stub_$2 || defined __stub___$2\nchoke me\n#endif\n\nint\nmain ()\n{\nreturn $2 ();\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_link \"$LINENO\"; then :\n  eval \"$3=yes\"\nelse\n  eval \"$3=no\"\nfi\nrm -f core conftest.err conftest.$ac_objext \\\n    conftest$ac_exeext conftest.$ac_ext\nfi\neval ac_res=\\$$3\n\t       { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_res\" >&5\n$as_echo \"$ac_res\" >&6; }\n  eval $as_lineno_stack; test \"x$as_lineno_stack\" = x && { as_lineno=; unset as_lineno;}\n\n} # ac_fn_c_check_func\ncat >config.log <<_ACEOF\nThis file contains any messages produced by compilers while\nrunning configure, to aid debugging if configure makes a mistake.\n\nIt was created by Firmware Mod Kit $as_me 0.4.0, which was\ngenerated by GNU Autoconf 2.65.  Invocation command line was\n\n  $ $0 $@\n\n_ACEOF\nexec 5>>config.log\n{\ncat <<_ASUNAME\n## --------- ##\n## Platform. ##\n## --------- ##\n\nhostname = `(hostname || uname -n) 2>/dev/null | sed 1q`\nuname -m = `(uname -m) 2>/dev/null || echo unknown`\nuname -r = `(uname -r) 2>/dev/null || echo unknown`\nuname -s = `(uname -s) 2>/dev/null || echo unknown`\nuname -v = `(uname -v) 2>/dev/null || echo unknown`\n\n/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`\n/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`\n\n/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`\n/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`\n/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`\n/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`\n/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`\n/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`\n/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`\n\n_ASUNAME\n\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    $as_echo \"PATH: $as_dir\"\n  done\nIFS=$as_save_IFS\n\n} >&5\n\ncat >&5 <<_ACEOF\n\n\n## ----------- ##\n## Core tests. ##\n## ----------- ##\n\n_ACEOF\n\n\n# Keep a trace of the command line.\n# Strip out --no-create and --no-recursion so they do not pile up.\n# Strip out --silent because we don't want to record it for future runs.\n# Also quote any args containing shell meta-characters.\n# Make two passes to allow for proper duplicate-argument suppression.\nac_configure_args=\nac_configure_args0=\nac_configure_args1=\nac_must_keep_next=false\nfor ac_pass in 1 2\ndo\n  for ac_arg\n  do\n    case $ac_arg in\n    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;\n    -q | -quiet | --quiet | --quie | --qui | --qu | --q \\\n    | -silent | --silent | --silen | --sile | --sil)\n      continue ;;\n    *\\'*)\n      ac_arg=`$as_echo \"$ac_arg\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"` ;;\n    esac\n    case $ac_pass in\n    1) as_fn_append ac_configure_args0 \" '$ac_arg'\" ;;\n    2)\n      as_fn_append ac_configure_args1 \" '$ac_arg'\"\n      if test $ac_must_keep_next = true; then\n\tac_must_keep_next=false # Got value, back to normal.\n      else\n\tcase $ac_arg in\n\t  *=* | --config-cache | -C | -disable-* | --disable-* \\\n\t  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \\\n\t  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \\\n\t  | -with-* | --with-* | -without-* | --without-* | --x)\n\t    case \"$ac_configure_args0 \" in\n\t      \"$ac_configure_args1\"*\" '$ac_arg' \"* ) continue ;;\n\t    esac\n\t    ;;\n\t  -* ) ac_must_keep_next=true ;;\n\tesac\n      fi\n      as_fn_append ac_configure_args \" '$ac_arg'\"\n      ;;\n    esac\n  done\ndone\n{ ac_configure_args0=; unset ac_configure_args0;}\n{ ac_configure_args1=; unset ac_configure_args1;}\n\n# When interrupted or exit'd, cleanup temporary files, and complete\n# config.log.  We remove comments because anyway the quotes in there\n# would cause problems or look ugly.\n# WARNING: Use '\\'' to represent an apostrophe within the trap.\n# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.\ntrap 'exit_status=$?\n  # Save into config.log some information that might help in debugging.\n  {\n    echo\n\n    cat <<\\_ASBOX\n## ---------------- ##\n## Cache variables. ##\n## ---------------- ##\n_ASBOX\n    echo\n    # The following way of writing the cache mishandles newlines in values,\n(\n  for ac_var in `(set) 2>&1 | sed -n '\\''s/^\\([a-zA-Z_][a-zA-Z0-9_]*\\)=.*/\\1/p'\\''`; do\n    eval ac_val=\\$$ac_var\n    case $ac_val in #(\n    *${as_nl}*)\n      case $ac_var in #(\n      *_cv_*) { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline\" >&5\n$as_echo \"$as_me: WARNING: cache variable $ac_var contains a newline\" >&2;} ;;\n      esac\n      case $ac_var in #(\n      _ | IFS | as_nl) ;; #(\n      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(\n      *) { eval $ac_var=; unset $ac_var;} ;;\n      esac ;;\n    esac\n  done\n  (set) 2>&1 |\n    case $as_nl`(ac_space='\\'' '\\''; set) 2>&1` in #(\n    *${as_nl}ac_space=\\ *)\n      sed -n \\\n\t\"s/'\\''/'\\''\\\\\\\\'\\'''\\''/g;\n\t  s/^\\\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\\\)=\\\\(.*\\\\)/\\\\1='\\''\\\\2'\\''/p\"\n      ;; #(\n    *)\n      sed -n \"/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p\"\n      ;;\n    esac |\n    sort\n)\n    echo\n\n    cat <<\\_ASBOX\n## ----------------- ##\n## Output variables. ##\n## ----------------- ##\n_ASBOX\n    echo\n    for ac_var in $ac_subst_vars\n    do\n      eval ac_val=\\$$ac_var\n      case $ac_val in\n      *\\'\\''*) ac_val=`$as_echo \"$ac_val\" | sed \"s/'\\''/'\\''\\\\\\\\\\\\\\\\'\\'''\\''/g\"`;;\n      esac\n      $as_echo \"$ac_var='\\''$ac_val'\\''\"\n    done | sort\n    echo\n\n    if test -n \"$ac_subst_files\"; then\n      cat <<\\_ASBOX\n## ------------------- ##\n## File substitutions. ##\n## ------------------- ##\n_ASBOX\n      echo\n      for ac_var in $ac_subst_files\n      do\n\teval ac_val=\\$$ac_var\n\tcase $ac_val in\n\t*\\'\\''*) ac_val=`$as_echo \"$ac_val\" | sed \"s/'\\''/'\\''\\\\\\\\\\\\\\\\'\\'''\\''/g\"`;;\n\tesac\n\t$as_echo \"$ac_var='\\''$ac_val'\\''\"\n      done | sort\n      echo\n    fi\n\n    if test -s confdefs.h; then\n      cat <<\\_ASBOX\n## ----------- ##\n## confdefs.h. ##\n## ----------- ##\n_ASBOX\n      echo\n      cat confdefs.h\n      echo\n    fi\n    test \"$ac_signal\" != 0 &&\n      $as_echo \"$as_me: caught signal $ac_signal\"\n    $as_echo \"$as_me: exit $exit_status\"\n  } >&5\n  rm -f core *.core core.conftest.* &&\n    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&\n    exit $exit_status\n' 0\nfor ac_signal in 1 2 13 15; do\n  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal\ndone\nac_signal=0\n\n# confdefs.h avoids OS command line length limits that DEFS can exceed.\nrm -f -r conftest* confdefs.h\n\n$as_echo \"/* confdefs.h */\" > confdefs.h\n\n# Predefined preprocessor variables.\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_NAME \"$PACKAGE_NAME\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_VERSION \"$PACKAGE_VERSION\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_STRING \"$PACKAGE_STRING\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"\n_ACEOF\n\ncat >>confdefs.h <<_ACEOF\n#define PACKAGE_URL \"$PACKAGE_URL\"\n_ACEOF\n\n\n# Let the site file select an alternate cache file if it wants to.\n# Prefer an explicitly selected file to automatically selected ones.\nac_site_file1=NONE\nac_site_file2=NONE\nif test -n \"$CONFIG_SITE\"; then\n  ac_site_file1=$CONFIG_SITE\nelif test \"x$prefix\" != xNONE; then\n  ac_site_file1=$prefix/share/config.site\n  ac_site_file2=$prefix/etc/config.site\nelse\n  ac_site_file1=$ac_default_prefix/share/config.site\n  ac_site_file2=$ac_default_prefix/etc/config.site\nfi\nfor ac_site_file in \"$ac_site_file1\" \"$ac_site_file2\"\ndo\n  test \"x$ac_site_file\" = xNONE && continue\n  if test /dev/null != \"$ac_site_file\" && test -r \"$ac_site_file\"; then\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file\" >&5\n$as_echo \"$as_me: loading site script $ac_site_file\" >&6;}\n    sed 's/^/| /' \"$ac_site_file\" >&5\n    . \"$ac_site_file\"\n  fi\ndone\n\nif test -r \"$cache_file\"; then\n  # Some versions of bash will fail to source /dev/null (special files\n  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.\n  if test /dev/null != \"$cache_file\" && test -f \"$cache_file\"; then\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: loading cache $cache_file\" >&5\n$as_echo \"$as_me: loading cache $cache_file\" >&6;}\n    case $cache_file in\n      [\\\\/]* | ?:[\\\\/]* ) . \"$cache_file\";;\n      *)                      . \"./$cache_file\";;\n    esac\n  fi\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: creating cache $cache_file\" >&5\n$as_echo \"$as_me: creating cache $cache_file\" >&6;}\n  >$cache_file\nfi\n\n# Check that the precious variables saved in the cache have kept the same\n# value.\nac_cache_corrupted=false\nfor ac_var in $ac_precious_vars; do\n  eval ac_old_set=\\$ac_cv_env_${ac_var}_set\n  eval ac_new_set=\\$ac_env_${ac_var}_set\n  eval ac_old_val=\\$ac_cv_env_${ac_var}_value\n  eval ac_new_val=\\$ac_env_${ac_var}_value\n  case $ac_old_set,$ac_new_set in\n    set,)\n      { $as_echo \"$as_me:${as_lineno-$LINENO}: error: \\`$ac_var' was set to \\`$ac_old_val' in the previous run\" >&5\n$as_echo \"$as_me: error: \\`$ac_var' was set to \\`$ac_old_val' in the previous run\" >&2;}\n      ac_cache_corrupted=: ;;\n    ,set)\n      { $as_echo \"$as_me:${as_lineno-$LINENO}: error: \\`$ac_var' was not set in the previous run\" >&5\n$as_echo \"$as_me: error: \\`$ac_var' was not set in the previous run\" >&2;}\n      ac_cache_corrupted=: ;;\n    ,);;\n    *)\n      if test \"x$ac_old_val\" != \"x$ac_new_val\"; then\n\t# differences in whitespace do not lead to failure.\n\tac_old_val_w=`echo x $ac_old_val`\n\tac_new_val_w=`echo x $ac_new_val`\n\tif test \"$ac_old_val_w\" != \"$ac_new_val_w\"; then\n\t  { $as_echo \"$as_me:${as_lineno-$LINENO}: error: \\`$ac_var' has changed since the previous run:\" >&5\n$as_echo \"$as_me: error: \\`$ac_var' has changed since the previous run:\" >&2;}\n\t  ac_cache_corrupted=:\n\telse\n\t  { $as_echo \"$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \\`$ac_var' since the previous run:\" >&5\n$as_echo \"$as_me: warning: ignoring whitespace changes in \\`$ac_var' since the previous run:\" >&2;}\n\t  eval $ac_var=\\$ac_old_val\n\tfi\n\t{ $as_echo \"$as_me:${as_lineno-$LINENO}:   former value:  \\`$ac_old_val'\" >&5\n$as_echo \"$as_me:   former value:  \\`$ac_old_val'\" >&2;}\n\t{ $as_echo \"$as_me:${as_lineno-$LINENO}:   current value: \\`$ac_new_val'\" >&5\n$as_echo \"$as_me:   current value: \\`$ac_new_val'\" >&2;}\n      fi;;\n  esac\n  # Pass precious variables to config.status.\n  if test \"$ac_new_set\" = set; then\n    case $ac_new_val in\n    *\\'*) ac_arg=$ac_var=`$as_echo \"$ac_new_val\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"` ;;\n    *) ac_arg=$ac_var=$ac_new_val ;;\n    esac\n    case \" $ac_configure_args \" in\n      *\" '$ac_arg' \"*) ;; # Avoid dups.  Use of quotes ensures accuracy.\n      *) as_fn_append ac_configure_args \" '$ac_arg'\" ;;\n    esac\n  fi\ndone\nif $ac_cache_corrupted; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build\" >&5\n$as_echo \"$as_me: error: changes in the environment can compromise the build\" >&2;}\n  as_fn_error \"run \\`make distclean' and/or \\`rm $cache_file' and start over\" \"$LINENO\" 5\nfi\n## -------------------- ##\n## Main body of script. ##\n## -------------------- ##\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n\n\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\nif test -n \"$ac_tool_prefix\"; then\n  # Extract the first word of \"${ac_tool_prefix}gcc\", so it can be a program name with args.\nset dummy ${ac_tool_prefix}gcc; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$CC\"; then\n  ac_cv_prog_CC=\"$CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_CC=\"${ac_tool_prefix}gcc\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nCC=$ac_cv_prog_CC\nif test -n \"$CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CC\" >&5\n$as_echo \"$CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\nfi\nif test -z \"$ac_cv_prog_CC\"; then\n  ac_ct_CC=$CC\n  # Extract the first word of \"gcc\", so it can be a program name with args.\nset dummy gcc; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_ac_ct_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$ac_ct_CC\"; then\n  ac_cv_prog_ac_ct_CC=\"$ac_ct_CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_ac_ct_CC=\"gcc\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nac_ct_CC=$ac_cv_prog_ac_ct_CC\nif test -n \"$ac_ct_CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC\" >&5\n$as_echo \"$ac_ct_CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n  if test \"x$ac_ct_CC\" = x; then\n    CC=\"\"\n  else\n    case $cross_compiling:$ac_tool_warned in\nyes:)\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet\" >&5\n$as_echo \"$as_me: WARNING: using cross tools not prefixed with host triplet\" >&2;}\nac_tool_warned=yes ;;\nesac\n    CC=$ac_ct_CC\n  fi\nelse\n  CC=\"$ac_cv_prog_CC\"\nfi\n\nif test -z \"$CC\"; then\n          if test -n \"$ac_tool_prefix\"; then\n    # Extract the first word of \"${ac_tool_prefix}cc\", so it can be a program name with args.\nset dummy ${ac_tool_prefix}cc; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$CC\"; then\n  ac_cv_prog_CC=\"$CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_CC=\"${ac_tool_prefix}cc\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nCC=$ac_cv_prog_CC\nif test -n \"$CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CC\" >&5\n$as_echo \"$CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\n  fi\nfi\nif test -z \"$CC\"; then\n  # Extract the first word of \"cc\", so it can be a program name with args.\nset dummy cc; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$CC\"; then\n  ac_cv_prog_CC=\"$CC\" # Let the user override the test.\nelse\n  ac_prog_rejected=no\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    if test \"$as_dir/$ac_word$ac_exec_ext\" = \"/usr/ucb/cc\"; then\n       ac_prog_rejected=yes\n       continue\n     fi\n    ac_cv_prog_CC=\"cc\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nif test $ac_prog_rejected = yes; then\n  # We found a bogon in the path, so make sure we never use it.\n  set dummy $ac_cv_prog_CC\n  shift\n  if test $# != 0; then\n    # We chose a different compiler from the bogus one.\n    # However, it has the same basename, so the bogon will be chosen\n    # first if we set CC to just the basename; use the full file name.\n    shift\n    ac_cv_prog_CC=\"$as_dir/$ac_word${1+' '}$@\"\n  fi\nfi\nfi\nfi\nCC=$ac_cv_prog_CC\nif test -n \"$CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CC\" >&5\n$as_echo \"$CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\nfi\nif test -z \"$CC\"; then\n  if test -n \"$ac_tool_prefix\"; then\n  for ac_prog in cl.exe\n  do\n    # Extract the first word of \"$ac_tool_prefix$ac_prog\", so it can be a program name with args.\nset dummy $ac_tool_prefix$ac_prog; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$CC\"; then\n  ac_cv_prog_CC=\"$CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_CC=\"$ac_tool_prefix$ac_prog\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nCC=$ac_cv_prog_CC\nif test -n \"$CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CC\" >&5\n$as_echo \"$CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\n    test -n \"$CC\" && break\n  done\nfi\nif test -z \"$CC\"; then\n  ac_ct_CC=$CC\n  for ac_prog in cl.exe\ndo\n  # Extract the first word of \"$ac_prog\", so it can be a program name with args.\nset dummy $ac_prog; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_ac_ct_CC+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$ac_ct_CC\"; then\n  ac_cv_prog_ac_ct_CC=\"$ac_ct_CC\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_ac_ct_CC=\"$ac_prog\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nac_ct_CC=$ac_cv_prog_ac_ct_CC\nif test -n \"$ac_ct_CC\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC\" >&5\n$as_echo \"$ac_ct_CC\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\n  test -n \"$ac_ct_CC\" && break\ndone\n\n  if test \"x$ac_ct_CC\" = x; then\n    CC=\"\"\n  else\n    case $cross_compiling:$ac_tool_warned in\nyes:)\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet\" >&5\n$as_echo \"$as_me: WARNING: using cross tools not prefixed with host triplet\" >&2;}\nac_tool_warned=yes ;;\nesac\n    CC=$ac_ct_CC\n  fi\nfi\n\nfi\n\n\ntest -z \"$CC\" && { { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"no acceptable C compiler found in \\$PATH\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\n\n# Provide some information about the compiler.\n$as_echo \"$as_me:${as_lineno-$LINENO}: checking for C compiler version\" >&5\nset X $ac_compile\nac_compiler=$2\nfor ac_option in --version -v -V -qversion; do\n  { { ac_try=\"$ac_compiler $ac_option >&5\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_compiler $ac_option >&5\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    sed '10a\\\n... rest of stderr output deleted ...\n         10q' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n  fi\n  rm -f conftest.er1 conftest.err\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }\ndone\n\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nac_clean_files_save=$ac_clean_files\nac_clean_files=\"$ac_clean_files a.out a.out.dSYM a.exe b.out\"\n# Try to create an executable without -o first, disregard a.out.\n# It will help us diagnose broken compilers, and finding out an intuition\n# of exeext.\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether the C compiler works\" >&5\n$as_echo_n \"checking whether the C compiler works... \" >&6; }\nac_link_default=`$as_echo \"$ac_link\" | sed 's/ -o *conftest[^ ]*//'`\n\n# The possible output files:\nac_files=\"a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*\"\n\nac_rmfiles=\nfor ac_file in $ac_files\ndo\n  case $ac_file in\n    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;\n    * ) ac_rmfiles=\"$ac_rmfiles $ac_file\";;\n  esac\ndone\nrm -f $ac_rmfiles\n\nif { { ac_try=\"$ac_link_default\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link_default\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; then :\n  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.\n# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'\n# in a Makefile.  We should not override ac_cv_exeext if it was cached,\n# so that the user can short-circuit this test for compilers unknown to\n# Autoconf.\nfor ac_file in $ac_files ''\ndo\n  test -f \"$ac_file\" || continue\n  case $ac_file in\n    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )\n\t;;\n    [ab].out )\n\t# We found the default executable, but exeext='' is most\n\t# certainly right.\n\tbreak;;\n    *.* )\n\tif test \"${ac_cv_exeext+set}\" = set && test \"$ac_cv_exeext\" != no;\n\tthen :; else\n\t   ac_cv_exeext=`expr \"$ac_file\" : '[^.]*\\(\\..*\\)'`\n\tfi\n\t# We set ac_cv_exeext here because the later test for it is not\n\t# safe: cross compilers may not add the suffix if given an `-o'\n\t# argument, so we may need to know it at that point already.\n\t# Even if this section looks crufty: it has the advantage of\n\t# actually working.\n\tbreak;;\n    * )\n\tbreak;;\n  esac\ndone\ntest \"$ac_cv_exeext\" = no && ac_cv_exeext=\n\nelse\n  ac_file=''\nfi\nif test -z \"$ac_file\"; then :\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\n$as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n{ { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\n{ as_fn_set_status 77\nas_fn_error \"C compiler cannot create executables\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: yes\" >&5\n$as_echo \"yes\" >&6; }\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name\" >&5\n$as_echo_n \"checking for C compiler default output file name... \" >&6; }\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_file\" >&5\n$as_echo \"$ac_file\" >&6; }\nac_exeext=$ac_cv_exeext\n\nrm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out\nac_clean_files=$ac_clean_files_save\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for suffix of executables\" >&5\n$as_echo_n \"checking for suffix of executables... \" >&6; }\nif { { ac_try=\"$ac_link\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; then :\n  # If both `conftest.exe' and `conftest' are `present' (well, observable)\n# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will\n# work properly (i.e., refer to `conftest.exe'), while it won't with\n# `rm'.\nfor ac_file in conftest.exe conftest conftest.*; do\n  test -f \"$ac_file\" || continue\n  case $ac_file in\n    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;\n    *.* ) ac_cv_exeext=`expr \"$ac_file\" : '[^.]*\\(\\..*\\)'`\n\t  break;;\n    * ) break;;\n  esac\ndone\nelse\n  { { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"cannot compute suffix of executables: cannot compile and link\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\nfi\nrm -f conftest conftest$ac_cv_exeext\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext\" >&5\n$as_echo \"$ac_cv_exeext\" >&6; }\n\nrm -f conftest.$ac_ext\nEXEEXT=$ac_cv_exeext\nac_exeext=$EXEEXT\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <stdio.h>\nint\nmain ()\n{\nFILE *f = fopen (\"conftest.out\", \"w\");\n return ferror (f) || fclose (f) != 0;\n\n  ;\n  return 0;\n}\n_ACEOF\nac_clean_files=\"$ac_clean_files conftest.out\"\n# Check that the compiler produces executables we can run.  If not, either\n# the compiler is broken, or we cross compile.\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling\" >&5\n$as_echo_n \"checking whether we are cross compiling... \" >&6; }\nif test \"$cross_compiling\" != yes; then\n  { { ac_try=\"$ac_link\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_link\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }\n  if { ac_try='./conftest$ac_cv_exeext'\n  { { case \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_try\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; }; then\n    cross_compiling=no\n  else\n    if test \"$cross_compiling\" = maybe; then\n\tcross_compiling=yes\n    else\n\t{ { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"cannot run C compiled programs.\nIf you meant to cross compile, use \\`--host'.\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\n    fi\n  fi\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $cross_compiling\" >&5\n$as_echo \"$cross_compiling\" >&6; }\n\nrm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out\nac_clean_files=$ac_clean_files_save\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for suffix of object files\" >&5\n$as_echo_n \"checking for suffix of object files... \" >&6; }\nif test \"${ac_cv_objext+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nrm -f conftest.o conftest.obj\nif { { ac_try=\"$ac_compile\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_compile\") 2>&5\n  ac_status=$?\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }; then :\n  for ac_file in conftest.o conftest.obj conftest.*; do\n  test -f \"$ac_file\" || continue;\n  case $ac_file in\n    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;\n    *) ac_cv_objext=`expr \"$ac_file\" : '.*\\.\\(.*\\)'`\n       break;;\n  esac\ndone\nelse\n  $as_echo \"$as_me: failed program was:\" >&5\nsed 's/^/| /' conftest.$ac_ext >&5\n\n{ { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"cannot compute suffix of object files: cannot compile\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\nfi\nrm -f conftest.$ac_cv_objext conftest.$ac_ext\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext\" >&5\n$as_echo \"$ac_cv_objext\" >&6; }\nOBJEXT=$ac_cv_objext\nac_objext=$OBJEXT\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler\" >&5\n$as_echo_n \"checking whether we are using the GNU C compiler... \" >&6; }\nif test \"${ac_cv_c_compiler_gnu+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n#ifndef __GNUC__\n       choke me\n#endif\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_compiler_gnu=yes\nelse\n  ac_compiler_gnu=no\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nac_cv_c_compiler_gnu=$ac_compiler_gnu\n\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu\" >&5\n$as_echo \"$ac_cv_c_compiler_gnu\" >&6; }\nif test $ac_compiler_gnu = yes; then\n  GCC=yes\nelse\n  GCC=\nfi\nac_test_CFLAGS=${CFLAGS+set}\nac_save_CFLAGS=$CFLAGS\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g\" >&5\n$as_echo_n \"checking whether $CC accepts -g... \" >&6; }\nif test \"${ac_cv_prog_cc_g+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  ac_save_c_werror_flag=$ac_c_werror_flag\n   ac_c_werror_flag=yes\n   ac_cv_prog_cc_g=no\n   CFLAGS=\"-g\"\n   cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_cv_prog_cc_g=yes\nelse\n  CFLAGS=\"\"\n      cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n\nelse\n  ac_c_werror_flag=$ac_save_c_werror_flag\n\t CFLAGS=\"-g\"\n\t cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_cv_prog_cc_g=yes\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\n   ac_c_werror_flag=$ac_save_c_werror_flag\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g\" >&5\n$as_echo \"$ac_cv_prog_cc_g\" >&6; }\nif test \"$ac_test_CFLAGS\" = set; then\n  CFLAGS=$ac_save_CFLAGS\nelif test $ac_cv_prog_cc_g = yes; then\n  if test \"$GCC\" = yes; then\n    CFLAGS=\"-g -O2\"\n  else\n    CFLAGS=\"-g\"\n  fi\nelse\n  if test \"$GCC\" = yes; then\n    CFLAGS=\"-O2\"\n  else\n    CFLAGS=\n  fi\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89\" >&5\n$as_echo_n \"checking for $CC option to accept ISO C89... \" >&6; }\nif test \"${ac_cv_prog_cc_c89+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  ac_cv_prog_cc_c89=no\nac_save_CC=$CC\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <stdarg.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */\nstruct buf { int x; };\nFILE * (*rcsopen) (struct buf *, struct stat *, int);\nstatic char *e (p, i)\n     char **p;\n     int i;\n{\n  return p[i];\n}\nstatic char *f (char * (*g) (char **, int), char **p, ...)\n{\n  char *s;\n  va_list v;\n  va_start (v,p);\n  s = g (p, va_arg (v,int));\n  va_end (v);\n  return s;\n}\n\n/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has\n   function prototypes and stuff, but not '\\xHH' hex character constants.\n   These don't provoke an error unfortunately, instead are silently treated\n   as 'x'.  The following induces an error, until -std is added to get\n   proper ANSI mode.  Curiously '\\x00'!='x' always comes out true, for an\n   array size at least.  It's necessary to write '\\x00'==0 to get something\n   that's true only with -std.  */\nint osf4_cc_array ['\\x00' == 0 ? 1 : -1];\n\n/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters\n   inside strings and character constants.  */\n#define FOO(x) 'x'\nint xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];\n\nint test (int i, double x);\nstruct s1 {int (*f) (int a);};\nstruct s2 {int (*f) (double a);};\nint pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);\nint argc;\nchar **argv;\nint\nmain ()\n{\nreturn f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];\n  ;\n  return 0;\n}\n_ACEOF\nfor ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \\\n\t-Ae \"-Aa -D_HPUX_SOURCE\" \"-Xc -D__EXTENSIONS__\"\ndo\n  CC=\"$ac_save_CC $ac_arg\"\n  if ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_cv_prog_cc_c89=$ac_arg\nfi\nrm -f core conftest.err conftest.$ac_objext\n  test \"x$ac_cv_prog_cc_c89\" != \"xno\" && break\ndone\nrm -f conftest.$ac_ext\nCC=$ac_save_CC\n\nfi\n# AC_CACHE_VAL\ncase \"x$ac_cv_prog_cc_c89\" in\n  x)\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: result: none needed\" >&5\n$as_echo \"none needed\" >&6; } ;;\n  xno)\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: result: unsupported\" >&5\n$as_echo \"unsupported\" >&6; } ;;\n  *)\n    CC=\"$CC $ac_cv_prog_cc_c89\"\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89\" >&5\n$as_echo \"$ac_cv_prog_cc_c89\" >&6; } ;;\nesac\nif test \"x$ac_cv_prog_cc_c89\" != xno; then :\n\nfi\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n\nac_ext=cpp\nac_cpp='$CXXCPP $CPPFLAGS'\nac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_cxx_compiler_gnu\nif test -z \"$CXX\"; then\n  if test -n \"$CCC\"; then\n    CXX=$CCC\n  else\n    if test -n \"$ac_tool_prefix\"; then\n  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC\n  do\n    # Extract the first word of \"$ac_tool_prefix$ac_prog\", so it can be a program name with args.\nset dummy $ac_tool_prefix$ac_prog; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_CXX+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$CXX\"; then\n  ac_cv_prog_CXX=\"$CXX\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_CXX=\"$ac_tool_prefix$ac_prog\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nCXX=$ac_cv_prog_CXX\nif test -n \"$CXX\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CXX\" >&5\n$as_echo \"$CXX\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\n    test -n \"$CXX\" && break\n  done\nfi\nif test -z \"$CXX\"; then\n  ac_ct_CXX=$CXX\n  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC\ndo\n  # Extract the first word of \"$ac_prog\", so it can be a program name with args.\nset dummy $ac_prog; ac_word=$2\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for $ac_word\" >&5\n$as_echo_n \"checking for $ac_word... \" >&6; }\nif test \"${ac_cv_prog_ac_ct_CXX+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -n \"$ac_ct_CXX\"; then\n  ac_cv_prog_ac_ct_CXX=\"$ac_ct_CXX\" # Let the user override the test.\nelse\nas_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_exec_ext in '' $ac_executable_extensions; do\n  if { test -f \"$as_dir/$ac_word$ac_exec_ext\" && $as_test_x \"$as_dir/$ac_word$ac_exec_ext\"; }; then\n    ac_cv_prog_ac_ct_CXX=\"$ac_prog\"\n    $as_echo \"$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext\" >&5\n    break 2\n  fi\ndone\n  done\nIFS=$as_save_IFS\n\nfi\nfi\nac_ct_CXX=$ac_cv_prog_ac_ct_CXX\nif test -n \"$ac_ct_CXX\"; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX\" >&5\n$as_echo \"$ac_ct_CXX\" >&6; }\nelse\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: result: no\" >&5\n$as_echo \"no\" >&6; }\nfi\n\n\n  test -n \"$ac_ct_CXX\" && break\ndone\n\n  if test \"x$ac_ct_CXX\" = x; then\n    CXX=\"g++\"\n  else\n    case $cross_compiling:$ac_tool_warned in\nyes:)\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet\" >&5\n$as_echo \"$as_me: WARNING: using cross tools not prefixed with host triplet\" >&2;}\nac_tool_warned=yes ;;\nesac\n    CXX=$ac_ct_CXX\n  fi\nfi\n\n  fi\nfi\n# Provide some information about the compiler.\n$as_echo \"$as_me:${as_lineno-$LINENO}: checking for C++ compiler version\" >&5\nset X $ac_compile\nac_compiler=$2\nfor ac_option in --version -v -V -qversion; do\n  { { ac_try=\"$ac_compiler $ac_option >&5\"\ncase \"(($ac_try\" in\n  *\\\"* | *\\`* | *\\\\*) ac_try_echo=\\$ac_try;;\n  *) ac_try_echo=$ac_try;;\nesac\neval ac_try_echo=\"\\\"\\$as_me:${as_lineno-$LINENO}: $ac_try_echo\\\"\"\n$as_echo \"$ac_try_echo\"; } >&5\n  (eval \"$ac_compiler $ac_option >&5\") 2>conftest.err\n  ac_status=$?\n  if test -s conftest.err; then\n    sed '10a\\\n... rest of stderr output deleted ...\n         10q' conftest.err >conftest.er1\n    cat conftest.er1 >&5\n  fi\n  rm -f conftest.er1 conftest.err\n  $as_echo \"$as_me:${as_lineno-$LINENO}: \\$? = $ac_status\" >&5\n  test $ac_status = 0; }\ndone\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler\" >&5\n$as_echo_n \"checking whether we are using the GNU C++ compiler... \" >&6; }\nif test \"${ac_cv_cxx_compiler_gnu+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n#ifndef __GNUC__\n       choke me\n#endif\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_cxx_try_compile \"$LINENO\"; then :\n  ac_compiler_gnu=yes\nelse\n  ac_compiler_gnu=no\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nac_cv_cxx_compiler_gnu=$ac_compiler_gnu\n\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu\" >&5\n$as_echo \"$ac_cv_cxx_compiler_gnu\" >&6; }\nif test $ac_compiler_gnu = yes; then\n  GXX=yes\nelse\n  GXX=\nfi\nac_test_CXXFLAGS=${CXXFLAGS+set}\nac_save_CXXFLAGS=$CXXFLAGS\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g\" >&5\n$as_echo_n \"checking whether $CXX accepts -g... \" >&6; }\nif test \"${ac_cv_prog_cxx_g+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  ac_save_cxx_werror_flag=$ac_cxx_werror_flag\n   ac_cxx_werror_flag=yes\n   ac_cv_prog_cxx_g=no\n   CXXFLAGS=\"-g\"\n   cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_cxx_try_compile \"$LINENO\"; then :\n  ac_cv_prog_cxx_g=yes\nelse\n  CXXFLAGS=\"\"\n      cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_cxx_try_compile \"$LINENO\"; then :\n\nelse\n  ac_cxx_werror_flag=$ac_save_cxx_werror_flag\n\t CXXFLAGS=\"-g\"\n\t cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_cxx_try_compile \"$LINENO\"; then :\n  ac_cv_prog_cxx_g=yes\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\n   ac_cxx_werror_flag=$ac_save_cxx_werror_flag\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g\" >&5\n$as_echo \"$ac_cv_prog_cxx_g\" >&6; }\nif test \"$ac_test_CXXFLAGS\" = set; then\n  CXXFLAGS=$ac_save_CXXFLAGS\nelif test $ac_cv_prog_cxx_g = yes; then\n  if test \"$GXX\" = yes; then\n    CXXFLAGS=\"-g -O2\"\n  else\n    CXXFLAGS=\"-g\"\n  fi\nelse\n  if test \"$GXX\" = yes; then\n    CXXFLAGS=\"-O2\"\n  else\n    CXXFLAGS=\n  fi\nfi\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n\n\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor\" >&5\n$as_echo_n \"checking how to run the C preprocessor... \" >&6; }\n# On Suns, sometimes $CPP names a directory.\nif test -n \"$CPP\" && test -d \"$CPP\"; then\n  CPP=\nfi\nif test -z \"$CPP\"; then\n  if test \"${ac_cv_prog_CPP+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n      # Double quotes because CPP needs to be expanded\n    for CPP in \"$CC -E\" \"$CC -E -traditional-cpp\" \"/lib/cpp\"\n    do\n      ac_preproc_ok=false\nfor ac_c_preproc_warn_flag in '' yes\ndo\n  # Use a header file that comes with gcc, so configuring glibc\n  # with a fresh cross-compiler works.\n  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since\n  # <limits.h> exists even on freestanding compilers.\n  # On the NeXT, cc -E runs the code through the compiler's parser,\n  # not just through cpp. \"Syntax error\" is here to catch this case.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#ifdef __STDC__\n# include <limits.h>\n#else\n# include <assert.h>\n#endif\n\t\t     Syntax error\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n\nelse\n  # Broken: fails on valid input.\ncontinue\nfi\nrm -f conftest.err conftest.$ac_ext\n\n  # OK, works on sane cases.  Now check whether nonexistent headers\n  # can be detected and how.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <ac_nonexistent.h>\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n  # Broken: success on invalid input.\ncontinue\nelse\n  # Passes both tests.\nac_preproc_ok=:\nbreak\nfi\nrm -f conftest.err conftest.$ac_ext\n\ndone\n# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.\nrm -f conftest.err conftest.$ac_ext\nif $ac_preproc_ok; then :\n  break\nfi\n\n    done\n    ac_cv_prog_CPP=$CPP\n\nfi\n  CPP=$ac_cv_prog_CPP\nelse\n  ac_cv_prog_CPP=$CPP\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $CPP\" >&5\n$as_echo \"$CPP\" >&6; }\nac_preproc_ok=false\nfor ac_c_preproc_warn_flag in '' yes\ndo\n  # Use a header file that comes with gcc, so configuring glibc\n  # with a fresh cross-compiler works.\n  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since\n  # <limits.h> exists even on freestanding compilers.\n  # On the NeXT, cc -E runs the code through the compiler's parser,\n  # not just through cpp. \"Syntax error\" is here to catch this case.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#ifdef __STDC__\n# include <limits.h>\n#else\n# include <assert.h>\n#endif\n\t\t     Syntax error\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n\nelse\n  # Broken: fails on valid input.\ncontinue\nfi\nrm -f conftest.err conftest.$ac_ext\n\n  # OK, works on sane cases.  Now check whether nonexistent headers\n  # can be detected and how.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <ac_nonexistent.h>\n_ACEOF\nif ac_fn_c_try_cpp \"$LINENO\"; then :\n  # Broken: success on invalid input.\ncontinue\nelse\n  # Passes both tests.\nac_preproc_ok=:\nbreak\nfi\nrm -f conftest.err conftest.$ac_ext\n\ndone\n# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.\nrm -f conftest.err conftest.$ac_ext\nif $ac_preproc_ok; then :\n\nelse\n  { { $as_echo \"$as_me:${as_lineno-$LINENO}: error: in \\`$ac_pwd':\" >&5\n$as_echo \"$as_me: error: in \\`$ac_pwd':\" >&2;}\nas_fn_error \"C preprocessor \\\"$CPP\\\" fails sanity check\nSee \\`config.log' for more details.\" \"$LINENO\" 5; }\nfi\n\nac_ext=c\nac_cpp='$CPP $CPPFLAGS'\nac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'\nac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'\nac_compiler_gnu=$ac_cv_c_compiler_gnu\n\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e\" >&5\n$as_echo_n \"checking for grep that handles long lines and -e... \" >&6; }\nif test \"${ac_cv_path_GREP+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test -z \"$GREP\"; then\n  ac_path_GREP_found=false\n  # Loop through the user's path and test for each of PROGNAME-LIST\n  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_prog in grep ggrep; do\n    for ac_exec_ext in '' $ac_executable_extensions; do\n      ac_path_GREP=\"$as_dir/$ac_prog$ac_exec_ext\"\n      { test -f \"$ac_path_GREP\" && $as_test_x \"$ac_path_GREP\"; } || continue\n# Check for GNU ac_path_GREP and select it if it is found.\n  # Check for GNU $ac_path_GREP\ncase `\"$ac_path_GREP\" --version 2>&1` in\n*GNU*)\n  ac_cv_path_GREP=\"$ac_path_GREP\" ac_path_GREP_found=:;;\n*)\n  ac_count=0\n  $as_echo_n 0123456789 >\"conftest.in\"\n  while :\n  do\n    cat \"conftest.in\" \"conftest.in\" >\"conftest.tmp\"\n    mv \"conftest.tmp\" \"conftest.in\"\n    cp \"conftest.in\" \"conftest.nl\"\n    $as_echo 'GREP' >> \"conftest.nl\"\n    \"$ac_path_GREP\" -e 'GREP$' -e '-(cannot match)-' < \"conftest.nl\" >\"conftest.out\" 2>/dev/null || break\n    diff \"conftest.out\" \"conftest.nl\" >/dev/null 2>&1 || break\n    as_fn_arith $ac_count + 1 && ac_count=$as_val\n    if test $ac_count -gt ${ac_path_GREP_max-0}; then\n      # Best one so far, save it but keep looking for a better one\n      ac_cv_path_GREP=\"$ac_path_GREP\"\n      ac_path_GREP_max=$ac_count\n    fi\n    # 10*(2^10) chars as input seems more than enough\n    test $ac_count -gt 10 && break\n  done\n  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;\nesac\n\n      $ac_path_GREP_found && break 3\n    done\n  done\n  done\nIFS=$as_save_IFS\n  if test -z \"$ac_cv_path_GREP\"; then\n    as_fn_error \"no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin\" \"$LINENO\" 5\n  fi\nelse\n  ac_cv_path_GREP=$GREP\nfi\n\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP\" >&5\n$as_echo \"$ac_cv_path_GREP\" >&6; }\n GREP=\"$ac_cv_path_GREP\"\n\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for egrep\" >&5\n$as_echo_n \"checking for egrep... \" >&6; }\nif test \"${ac_cv_path_EGREP+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1\n   then ac_cv_path_EGREP=\"$GREP -E\"\n   else\n     if test -z \"$EGREP\"; then\n  ac_path_EGREP_found=false\n  # Loop through the user's path and test for each of PROGNAME-LIST\n  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    for ac_prog in egrep; do\n    for ac_exec_ext in '' $ac_executable_extensions; do\n      ac_path_EGREP=\"$as_dir/$ac_prog$ac_exec_ext\"\n      { test -f \"$ac_path_EGREP\" && $as_test_x \"$ac_path_EGREP\"; } || continue\n# Check for GNU ac_path_EGREP and select it if it is found.\n  # Check for GNU $ac_path_EGREP\ncase `\"$ac_path_EGREP\" --version 2>&1` in\n*GNU*)\n  ac_cv_path_EGREP=\"$ac_path_EGREP\" ac_path_EGREP_found=:;;\n*)\n  ac_count=0\n  $as_echo_n 0123456789 >\"conftest.in\"\n  while :\n  do\n    cat \"conftest.in\" \"conftest.in\" >\"conftest.tmp\"\n    mv \"conftest.tmp\" \"conftest.in\"\n    cp \"conftest.in\" \"conftest.nl\"\n    $as_echo 'EGREP' >> \"conftest.nl\"\n    \"$ac_path_EGREP\" 'EGREP$' < \"conftest.nl\" >\"conftest.out\" 2>/dev/null || break\n    diff \"conftest.out\" \"conftest.nl\" >/dev/null 2>&1 || break\n    as_fn_arith $ac_count + 1 && ac_count=$as_val\n    if test $ac_count -gt ${ac_path_EGREP_max-0}; then\n      # Best one so far, save it but keep looking for a better one\n      ac_cv_path_EGREP=\"$ac_path_EGREP\"\n      ac_path_EGREP_max=$ac_count\n    fi\n    # 10*(2^10) chars as input seems more than enough\n    test $ac_count -gt 10 && break\n  done\n  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;\nesac\n\n      $ac_path_EGREP_found && break 3\n    done\n  done\n  done\nIFS=$as_save_IFS\n  if test -z \"$ac_cv_path_EGREP\"; then\n    as_fn_error \"no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin\" \"$LINENO\" 5\n  fi\nelse\n  ac_cv_path_EGREP=$EGREP\nfi\n\n   fi\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP\" >&5\n$as_echo \"$ac_cv_path_EGREP\" >&6; }\n EGREP=\"$ac_cv_path_EGREP\"\n\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for ANSI C header files\" >&5\n$as_echo_n \"checking for ANSI C header files... \" >&6; }\nif test \"${ac_cv_header_stdc+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <stdlib.h>\n#include <stdarg.h>\n#include <string.h>\n#include <float.h>\n\nint\nmain ()\n{\n\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_compile \"$LINENO\"; then :\n  ac_cv_header_stdc=yes\nelse\n  ac_cv_header_stdc=no\nfi\nrm -f core conftest.err conftest.$ac_objext conftest.$ac_ext\n\nif test $ac_cv_header_stdc = yes; then\n  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <string.h>\n\n_ACEOF\nif (eval \"$ac_cpp conftest.$ac_ext\") 2>&5 |\n  $EGREP \"memchr\" >/dev/null 2>&1; then :\n\nelse\n  ac_cv_header_stdc=no\nfi\nrm -f conftest*\n\nfi\n\nif test $ac_cv_header_stdc = yes; then\n  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <stdlib.h>\n\n_ACEOF\nif (eval \"$ac_cpp conftest.$ac_ext\") 2>&5 |\n  $EGREP \"free\" >/dev/null 2>&1; then :\n\nelse\n  ac_cv_header_stdc=no\nfi\nrm -f conftest*\n\nfi\n\nif test $ac_cv_header_stdc = yes; then\n  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.\n  if test \"$cross_compiling\" = yes; then :\n  :\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#include <ctype.h>\n#include <stdlib.h>\n#if ((' ' & 0x0FF) == 0x020)\n# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')\n# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))\n#else\n# define ISLOWER(c) \\\n\t\t   (('a' <= (c) && (c) <= 'i') \\\n\t\t     || ('j' <= (c) && (c) <= 'r') \\\n\t\t     || ('s' <= (c) && (c) <= 'z'))\n# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))\n#endif\n\n#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))\nint\nmain ()\n{\n  int i;\n  for (i = 0; i < 256; i++)\n    if (XOR (islower (i), ISLOWER (i))\n\t|| toupper (i) != TOUPPER (i))\n      return 2;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_run \"$LINENO\"; then :\n\nelse\n  ac_cv_header_stdc=no\nfi\nrm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \\\n  conftest.$ac_objext conftest.beam conftest.$ac_ext\nfi\n\nfi\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc\" >&5\n$as_echo \"$ac_cv_header_stdc\" >&6; }\nif test $ac_cv_header_stdc = yes; then\n\n$as_echo \"#define STDC_HEADERS 1\" >>confdefs.h\n\nfi\n\n# On IRIX 5.3, sys/types and inttypes.h are conflicting.\nfor ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \\\n\t\t  inttypes.h stdint.h unistd.h\ndo :\n  as_ac_Header=`$as_echo \"ac_cv_header_$ac_header\" | $as_tr_sh`\nac_fn_c_check_header_compile \"$LINENO\" \"$ac_header\" \"$as_ac_Header\" \"$ac_includes_default\n\"\neval as_val=\\$$as_ac_Header\n   if test \"x$as_val\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define `$as_echo \"HAVE_$ac_header\" | $as_tr_cpp` 1\n_ACEOF\n\nfi\n\ndone\n\n\nac_fn_c_check_type \"$LINENO\" \"size_t\" \"ac_cv_type_size_t\" \"$ac_includes_default\"\nif test \"x$ac_cv_type_size_t\" = x\"\"yes; then :\n\nelse\n\ncat >>confdefs.h <<_ACEOF\n#define size_t unsigned int\n_ACEOF\n\nfi\n\n\nfor ac_header in stdlib.h\ndo :\n  ac_fn_c_check_header_mongrel \"$LINENO\" \"stdlib.h\" \"ac_cv_header_stdlib_h\" \"$ac_includes_default\"\nif test \"x$ac_cv_header_stdlib_h\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define HAVE_STDLIB_H 1\n_ACEOF\n\nfi\n\ndone\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for GNU libc compatible malloc\" >&5\n$as_echo_n \"checking for GNU libc compatible malloc... \" >&6; }\nif test \"${ac_cv_func_malloc_0_nonnull+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  if test \"$cross_compiling\" = yes; then :\n  ac_cv_func_malloc_0_nonnull=no\nelse\n  cat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n#if defined STDC_HEADERS || defined HAVE_STDLIB_H\n# include <stdlib.h>\n#else\nchar *malloc ();\n#endif\n\nint\nmain ()\n{\nreturn ! malloc (0);\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_run \"$LINENO\"; then :\n  ac_cv_func_malloc_0_nonnull=yes\nelse\n  ac_cv_func_malloc_0_nonnull=no\nfi\nrm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \\\n  conftest.$ac_objext conftest.beam conftest.$ac_ext\nfi\n\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_malloc_0_nonnull\" >&5\n$as_echo \"$ac_cv_func_malloc_0_nonnull\" >&6; }\nif test $ac_cv_func_malloc_0_nonnull = yes; then :\n\n$as_echo \"#define HAVE_MALLOC 1\" >>confdefs.h\n\nelse\n  $as_echo \"#define HAVE_MALLOC 0\" >>confdefs.h\n\n   case \" $LIBOBJS \" in\n  *\" malloc.$ac_objext \"* ) ;;\n  *) LIBOBJS=\"$LIBOBJS malloc.$ac_objext\"\n ;;\nesac\n\n\n$as_echo \"#define malloc rpl_malloc\" >>confdefs.h\n\nfi\n\n\n\nfor ac_header in arpa/inet.h fcntl.h stdlib.h string.h unistd.h\ndo :\n  as_ac_Header=`$as_echo \"ac_cv_header_$ac_header\" | $as_tr_sh`\nac_fn_c_check_header_mongrel \"$LINENO\" \"$ac_header\" \"$as_ac_Header\" \"$ac_includes_default\"\neval as_val=\\$$as_ac_Header\n   if test \"x$as_val\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define `$as_echo \"HAVE_$ac_header\" | $as_tr_cpp` 1\n_ACEOF\n\nelse\n  echo \"error: missing necessary header file(s)\" && exit\nfi\n\ndone\n\nfor ac_func in memset malloc strstr\ndo :\n  as_ac_var=`$as_echo \"ac_cv_func_$ac_func\" | $as_tr_sh`\nac_fn_c_check_func \"$LINENO\" \"$ac_func\" \"$as_ac_var\"\neval as_val=\\$$as_ac_var\n   if test \"x$as_val\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define `$as_echo \"HAVE_$ac_func\" | $as_tr_cpp` 1\n_ACEOF\n\nelse\n  as_fn_error \"\\\"Missing necessary function(s)\\\"\" \"$LINENO\" 5\nfi\ndone\n\n\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: checking for crc32 in -lz\" >&5\n$as_echo_n \"checking for crc32 in -lz... \" >&6; }\nif test \"${ac_cv_lib_z_crc32+set}\" = set; then :\n  $as_echo_n \"(cached) \" >&6\nelse\n  ac_check_lib_save_LIBS=$LIBS\nLIBS=\"-lz  $LIBS\"\ncat confdefs.h - <<_ACEOF >conftest.$ac_ext\n/* end confdefs.h.  */\n\n/* Override any GCC internal prototype to avoid an error.\n   Use char because int might match the return type of a GCC\n   builtin and then its argument prototype would still apply.  */\n#ifdef __cplusplus\nextern \"C\"\n#endif\nchar crc32 ();\nint\nmain ()\n{\nreturn crc32 ();\n  ;\n  return 0;\n}\n_ACEOF\nif ac_fn_c_try_link \"$LINENO\"; then :\n  ac_cv_lib_z_crc32=yes\nelse\n  ac_cv_lib_z_crc32=no\nfi\nrm -f core conftest.err conftest.$ac_objext \\\n    conftest$ac_exeext conftest.$ac_ext\nLIBS=$ac_check_lib_save_LIBS\nfi\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_crc32\" >&5\n$as_echo \"$ac_cv_lib_z_crc32\" >&6; }\nif test \"x$ac_cv_lib_z_crc32\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define HAVE_LIBZ 1\n_ACEOF\n\n  LIBS=\"-lz $LIBS\"\n\nelse\n  echo \"error: missing zlib library\" && exit\nfi\n\nfor ac_header in zlib.h\ndo :\n  ac_fn_c_check_header_mongrel \"$LINENO\" \"zlib.h\" \"ac_cv_header_zlib_h\" \"$ac_includes_default\"\nif test \"x$ac_cv_header_zlib_h\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define HAVE_ZLIB_H 1\n_ACEOF\n\nelse\n  echo \"error: missing zlib header files\" && exit\nfi\n\ndone\n\nfor ac_header in lzma.h\ndo :\n  ac_fn_c_check_header_mongrel \"$LINENO\" \"lzma.h\" \"ac_cv_header_lzma_h\" \"$ac_includes_default\"\nif test \"x$ac_cv_header_lzma_h\" = x\"\"yes; then :\n  cat >>confdefs.h <<_ACEOF\n#define HAVE_LZMA_H 1\n_ACEOF\n\nelse\n  echo \"error: missing liblzma header files\" && exit\nfi\n\ndone\n\n\nac_config_files=\"$ac_config_files Makefile\"\n\ncat >confcache <<\\_ACEOF\n# This file is a shell script that caches the results of configure\n# tests run on this system so they can be shared between configure\n# scripts and configure runs, see configure's option --config-cache.\n# It is not useful on other systems.  If it contains results you don't\n# want to keep, you may remove or edit it.\n#\n# config.status only pays attention to the cache file if you give it\n# the --recheck option to rerun configure.\n#\n# `ac_cv_env_foo' variables (set or unset) will be overridden when\n# loading this file, other *unset* `ac_cv_foo' will be assigned the\n# following values.\n\n_ACEOF\n\n# The following way of writing the cache mishandles newlines in values,\n# but we know of no workaround that is simple, portable, and efficient.\n# So, we kill variables containing newlines.\n# Ultrix sh set writes to stderr and can't be redirected directly,\n# and sets the high bit in the cache file unless we assign to the vars.\n(\n  for ac_var in `(set) 2>&1 | sed -n 's/^\\([a-zA-Z_][a-zA-Z0-9_]*\\)=.*/\\1/p'`; do\n    eval ac_val=\\$$ac_var\n    case $ac_val in #(\n    *${as_nl}*)\n      case $ac_var in #(\n      *_cv_*) { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline\" >&5\n$as_echo \"$as_me: WARNING: cache variable $ac_var contains a newline\" >&2;} ;;\n      esac\n      case $ac_var in #(\n      _ | IFS | as_nl) ;; #(\n      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(\n      *) { eval $ac_var=; unset $ac_var;} ;;\n      esac ;;\n    esac\n  done\n\n  (set) 2>&1 |\n    case $as_nl`(ac_space=' '; set) 2>&1` in #(\n    *${as_nl}ac_space=\\ *)\n      # `set' does not quote correctly, so add quotes: double-quote\n      # substitution turns \\\\\\\\ into \\\\, and sed turns \\\\ into \\.\n      sed -n \\\n\t\"s/'/'\\\\\\\\''/g;\n\t  s/^\\\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\\\)=\\\\(.*\\\\)/\\\\1='\\\\2'/p\"\n      ;; #(\n    *)\n      # `set' quotes correctly as required by POSIX, so do not add quotes.\n      sed -n \"/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p\"\n      ;;\n    esac |\n    sort\n) |\n  sed '\n     /^ac_cv_env_/b end\n     t clear\n     :clear\n     s/^\\([^=]*\\)=\\(.*[{}].*\\)$/test \"${\\1+set}\" = set || &/\n     t end\n     s/^\\([^=]*\\)=\\(.*\\)$/\\1=${\\1=\\2}/\n     :end' >>confcache\nif diff \"$cache_file\" confcache >/dev/null 2>&1; then :; else\n  if test -w \"$cache_file\"; then\n    test \"x$cache_file\" != \"x/dev/null\" &&\n      { $as_echo \"$as_me:${as_lineno-$LINENO}: updating cache $cache_file\" >&5\n$as_echo \"$as_me: updating cache $cache_file\" >&6;}\n    cat confcache >$cache_file\n  else\n    { $as_echo \"$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file\" >&5\n$as_echo \"$as_me: not updating unwritable cache $cache_file\" >&6;}\n  fi\nfi\nrm -f confcache\n\ntest \"x$prefix\" = xNONE && prefix=$ac_default_prefix\n# Let make expand exec_prefix.\ntest \"x$exec_prefix\" = xNONE && exec_prefix='${prefix}'\n\n# Transform confdefs.h into DEFS.\n# Protect against shell expansion while executing Makefile rules.\n# Protect against Makefile macro expansion.\n#\n# If the first sed substitution is executed (which looks for macros that\n# take arguments), then branch to the quote section.  Otherwise,\n# look for a macro that doesn't take arguments.\nac_script='\n:mline\n/\\\\$/{\n N\n s,\\\\\\n,,\n b mline\n}\nt clear\n:clear\ns/^[\t ]*#[\t ]*define[\t ][\t ]*\\([^\t (][^\t (]*([^)]*)\\)[\t ]*\\(.*\\)/-D\\1=\\2/g\nt quote\ns/^[\t ]*#[\t ]*define[\t ][\t ]*\\([^\t ][^\t ]*\\)[\t ]*\\(.*\\)/-D\\1=\\2/g\nt quote\nb any\n:quote\ns/[\t `~#$^&*(){}\\\\|;'\\''\"<>?]/\\\\&/g\ns/\\[/\\\\&/g\ns/\\]/\\\\&/g\ns/\\$/$$/g\nH\n:any\n${\n\tg\n\ts/^\\n//\n\ts/\\n/ /g\n\tp\n}\n'\nDEFS=`sed -n \"$ac_script\" confdefs.h`\n\n\nac_libobjs=\nac_ltlibobjs=\nfor ac_i in : $LIBOBJS; do test \"x$ac_i\" = x: && continue\n  # 1. Remove the extension, and $U if already installed.\n  ac_script='s/\\$U\\././;s/\\.o$//;s/\\.obj$//'\n  ac_i=`$as_echo \"$ac_i\" | sed \"$ac_script\"`\n  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR\n  #    will be set to the directory where LIBOBJS objects are built.\n  as_fn_append ac_libobjs \" \\${LIBOBJDIR}$ac_i\\$U.$ac_objext\"\n  as_fn_append ac_ltlibobjs \" \\${LIBOBJDIR}$ac_i\"'$U.lo'\ndone\nLIBOBJS=$ac_libobjs\n\nLTLIBOBJS=$ac_ltlibobjs\n\n\n\n: ${CONFIG_STATUS=./config.status}\nac_write_fail=0\nac_clean_files_save=$ac_clean_files\nac_clean_files=\"$ac_clean_files $CONFIG_STATUS\"\n{ $as_echo \"$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS\" >&5\n$as_echo \"$as_me: creating $CONFIG_STATUS\" >&6;}\nas_write_fail=0\ncat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1\n#! $SHELL\n# Generated by $as_me.\n# Run this file to recreate the current configuration.\n# Compiler output produced by configure, useful for debugging\n# configure, is in config.log if it exists.\n\ndebug=false\nac_cs_recheck=false\nac_cs_silent=false\n\nSHELL=\\${CONFIG_SHELL-$SHELL}\nexport SHELL\n_ASEOF\ncat >>$CONFIG_STATUS <<\\_ASEOF || as_write_fail=1\n## -------------------- ##\n## M4sh Initialization. ##\n## -------------------- ##\n\n# Be more Bourne compatible\nDUALCASE=1; export DUALCASE # for MKS sh\nif test -n \"${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :\n  emulate sh\n  NULLCMD=:\n  # Pre-4.2 versions of Zsh do word splitting on ${1+\"$@\"}, which\n  # is contrary to our usage.  Disable this feature.\n  alias -g '${1+\"$@\"}'='\"$@\"'\n  setopt NO_GLOB_SUBST\nelse\n  case `(set -o) 2>/dev/null` in #(\n  *posix*) :\n    set -o posix ;; #(\n  *) :\n     ;;\nesac\nfi\n\n\nas_nl='\n'\nexport as_nl\n# Printing a long string crashes Solaris 7 /usr/bin/printf.\nas_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'\nas_echo=$as_echo$as_echo$as_echo$as_echo$as_echo\nas_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo\n# Prefer a ksh shell builtin over an external printf program on Solaris,\n# but without wasting forks for bash or zsh.\nif test -z \"$BASH_VERSION$ZSH_VERSION\" \\\n    && (test \"X`print -r -- $as_echo`\" = \"X$as_echo\") 2>/dev/null; then\n  as_echo='print -r --'\n  as_echo_n='print -rn --'\nelif (test \"X`printf %s $as_echo`\" = \"X$as_echo\") 2>/dev/null; then\n  as_echo='printf %s\\n'\n  as_echo_n='printf %s'\nelse\n  if test \"X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`\" = \"X-n $as_echo\"; then\n    as_echo_body='eval /usr/ucb/echo -n \"$1$as_nl\"'\n    as_echo_n='/usr/ucb/echo -n'\n  else\n    as_echo_body='eval expr \"X$1\" : \"X\\\\(.*\\\\)\"'\n    as_echo_n_body='eval\n      arg=$1;\n      case $arg in #(\n      *\"$as_nl\"*)\n\texpr \"X$arg\" : \"X\\\\(.*\\\\)$as_nl\";\n\targ=`expr \"X$arg\" : \".*$as_nl\\\\(.*\\\\)\"`;;\n      esac;\n      expr \"X$arg\" : \"X\\\\(.*\\\\)\" | tr -d \"$as_nl\"\n    '\n    export as_echo_n_body\n    as_echo_n='sh -c $as_echo_n_body as_echo'\n  fi\n  export as_echo_body\n  as_echo='sh -c $as_echo_body as_echo'\nfi\n\n# The user is always right.\nif test \"${PATH_SEPARATOR+set}\" != set; then\n  PATH_SEPARATOR=:\n  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {\n    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||\n      PATH_SEPARATOR=';'\n  }\nfi\n\n\n# IFS\n# We need space, tab and new line, in precisely that order.  Quoting is\n# there to prevent editors from complaining about space-tab.\n# (If _AS_PATH_WALK were called with IFS unset, it would disable word\n# splitting by setting IFS to empty value.)\nIFS=\" \"\"\t$as_nl\"\n\n# Find who we are.  Look in the path if we contain no directory separator.\ncase $0 in #((\n  *[\\\\/]* ) as_myself=$0 ;;\n  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR\nfor as_dir in $PATH\ndo\n  IFS=$as_save_IFS\n  test -z \"$as_dir\" && as_dir=.\n    test -r \"$as_dir/$0\" && as_myself=$as_dir/$0 && break\n  done\nIFS=$as_save_IFS\n\n     ;;\nesac\n# We did not find ourselves, most probably we were run as `sh COMMAND'\n# in which case we are not to be found in the path.\nif test \"x$as_myself\" = x; then\n  as_myself=$0\nfi\nif test ! -f \"$as_myself\"; then\n  $as_echo \"$as_myself: error: cannot find myself; rerun with an absolute file name\" >&2\n  exit 1\nfi\n\n# Unset variables that we do not need and which cause bugs (e.g. in\n# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the \"|| exit 1\"\n# suppresses any \"Segmentation fault\" message there.  '((' could\n# trigger a bug in pdksh 5.2.14.\nfor as_var in BASH_ENV ENV MAIL MAILPATH\ndo eval test x\\${$as_var+set} = xset \\\n  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :\ndone\nPS1='$ '\nPS2='> '\nPS4='+ '\n\n# NLS nuisances.\nLC_ALL=C\nexport LC_ALL\nLANGUAGE=C\nexport LANGUAGE\n\n# CDPATH.\n(unset CDPATH) >/dev/null 2>&1 && unset CDPATH\n\n\n# as_fn_error ERROR [LINENO LOG_FD]\n# ---------------------------------\n# Output \"`basename $0`: error: ERROR\" to stderr. If LINENO and LOG_FD are\n# provided, also output the error to LOG_FD, referencing LINENO. Then exit the\n# script with status $?, using 1 if that was 0.\nas_fn_error ()\n{\n  as_status=$?; test $as_status -eq 0 && as_status=1\n  if test \"$3\"; then\n    as_lineno=${as_lineno-\"$2\"} as_lineno_stack=as_lineno_stack=$as_lineno_stack\n    $as_echo \"$as_me:${as_lineno-$LINENO}: error: $1\" >&$3\n  fi\n  $as_echo \"$as_me: error: $1\" >&2\n  as_fn_exit $as_status\n} # as_fn_error\n\n\n# as_fn_set_status STATUS\n# -----------------------\n# Set $? to STATUS, without forking.\nas_fn_set_status ()\n{\n  return $1\n} # as_fn_set_status\n\n# as_fn_exit STATUS\n# -----------------\n# Exit the shell with STATUS, even in a \"trap 0\" or \"set -e\" context.\nas_fn_exit ()\n{\n  set +e\n  as_fn_set_status $1\n  exit $1\n} # as_fn_exit\n\n# as_fn_unset VAR\n# ---------------\n# Portably unset VAR.\nas_fn_unset ()\n{\n  { eval $1=; unset $1;}\n}\nas_unset=as_fn_unset\n# as_fn_append VAR VALUE\n# ----------------------\n# Append the text in VALUE to the end of the definition contained in VAR. Take\n# advantage of any shell optimizations that allow amortized linear growth over\n# repeated appends, instead of the typical quadratic growth present in naive\n# implementations.\nif (eval \"as_var=1; as_var+=2; test x\\$as_var = x12\") 2>/dev/null; then :\n  eval 'as_fn_append ()\n  {\n    eval $1+=\\$2\n  }'\nelse\n  as_fn_append ()\n  {\n    eval $1=\\$$1\\$2\n  }\nfi # as_fn_append\n\n# as_fn_arith ARG...\n# ------------------\n# Perform arithmetic evaluation on the ARGs, and store the result in the\n# global $as_val. Take advantage of shells that can avoid forks. The arguments\n# must be portable across $(()) and expr.\nif (eval \"test \\$(( 1 + 1 )) = 2\") 2>/dev/null; then :\n  eval 'as_fn_arith ()\n  {\n    as_val=$(( $* ))\n  }'\nelse\n  as_fn_arith ()\n  {\n    as_val=`expr \"$@\" || test $? -eq 1`\n  }\nfi # as_fn_arith\n\n\nif expr a : '\\(a\\)' >/dev/null 2>&1 &&\n   test \"X`expr 00001 : '.*\\(...\\)'`\" = X001; then\n  as_expr=expr\nelse\n  as_expr=false\nfi\n\nif (basename -- /) >/dev/null 2>&1 && test \"X`basename -- / 2>&1`\" = \"X/\"; then\n  as_basename=basename\nelse\n  as_basename=false\nfi\n\nif (as_dir=`dirname -- /` && test \"X$as_dir\" = X/) >/dev/null 2>&1; then\n  as_dirname=dirname\nelse\n  as_dirname=false\nfi\n\nas_me=`$as_basename -- \"$0\" ||\n$as_expr X/\"$0\" : '.*/\\([^/][^/]*\\)/*$' \\| \\\n\t X\"$0\" : 'X\\(//\\)$' \\| \\\n\t X\"$0\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X/\"$0\" |\n    sed '/^.*\\/\\([^/][^/]*\\)\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\/\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\/\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n\n# Avoid depending upon Character Ranges.\nas_cr_letters='abcdefghijklmnopqrstuvwxyz'\nas_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'\nas_cr_Letters=$as_cr_letters$as_cr_LETTERS\nas_cr_digits='0123456789'\nas_cr_alnum=$as_cr_Letters$as_cr_digits\n\nECHO_C= ECHO_N= ECHO_T=\ncase `echo -n x` in #(((((\n-n*)\n  case `echo 'xy\\c'` in\n  *c*) ECHO_T='\t';;\t# ECHO_T is single tab character.\n  xy)  ECHO_C='\\c';;\n  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null\n       ECHO_T='\t';;\n  esac;;\n*)\n  ECHO_N='-n';;\nesac\n\nrm -f conf$$ conf$$.exe conf$$.file\nif test -d conf$$.dir; then\n  rm -f conf$$.dir/conf$$.file\nelse\n  rm -f conf$$.dir\n  mkdir conf$$.dir 2>/dev/null\nfi\nif (echo >conf$$.file) 2>/dev/null; then\n  if ln -s conf$$.file conf$$ 2>/dev/null; then\n    as_ln_s='ln -s'\n    # ... but there are two gotchas:\n    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.\n    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.\n    # In both cases, we have to default to `cp -p'.\n    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||\n      as_ln_s='cp -p'\n  elif ln conf$$.file conf$$ 2>/dev/null; then\n    as_ln_s=ln\n  else\n    as_ln_s='cp -p'\n  fi\nelse\n  as_ln_s='cp -p'\nfi\nrm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file\nrmdir conf$$.dir 2>/dev/null\n\n\n# as_fn_mkdir_p\n# -------------\n# Create \"$as_dir\" as a directory, including parents if necessary.\nas_fn_mkdir_p ()\n{\n\n  case $as_dir in #(\n  -*) as_dir=./$as_dir;;\n  esac\n  test -d \"$as_dir\" || eval $as_mkdir_p || {\n    as_dirs=\n    while :; do\n      case $as_dir in #(\n      *\\'*) as_qdir=`$as_echo \"$as_dir\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"`;; #'(\n      *) as_qdir=$as_dir;;\n      esac\n      as_dirs=\"'$as_qdir' $as_dirs\"\n      as_dir=`$as_dirname -- \"$as_dir\" ||\n$as_expr X\"$as_dir\" : 'X\\(.*[^/]\\)//*[^/][^/]*/*$' \\| \\\n\t X\"$as_dir\" : 'X\\(//\\)[^/]' \\| \\\n\t X\"$as_dir\" : 'X\\(//\\)$' \\| \\\n\t X\"$as_dir\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X\"$as_dir\" |\n    sed '/^X\\(.*[^/]\\)\\/\\/*[^/][^/]*\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)[^/].*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n      test -d \"$as_dir\" && break\n    done\n    test -z \"$as_dirs\" || eval \"mkdir $as_dirs\"\n  } || test -d \"$as_dir\" || as_fn_error \"cannot create directory $as_dir\"\n\n\n} # as_fn_mkdir_p\nif mkdir -p . 2>/dev/null; then\n  as_mkdir_p='mkdir -p \"$as_dir\"'\nelse\n  test -d ./-p && rmdir ./-p\n  as_mkdir_p=false\nfi\n\nif test -x / >/dev/null 2>&1; then\n  as_test_x='test -x'\nelse\n  if ls -dL / >/dev/null 2>&1; then\n    as_ls_L_option=L\n  else\n    as_ls_L_option=\n  fi\n  as_test_x='\n    eval sh -c '\\''\n      if test -d \"$1\"; then\n\ttest -d \"$1/.\";\n      else\n\tcase $1 in #(\n\t-*)set \"./$1\";;\n\tesac;\n\tcase `ls -ld'$as_ls_L_option' \"$1\" 2>/dev/null` in #((\n\t???[sx]*):;;*)false;;esac;fi\n    '\\'' sh\n  '\nfi\nas_executable_p=$as_test_x\n\n# Sed expression to map a string onto a valid CPP name.\nas_tr_cpp=\"eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'\"\n\n# Sed expression to map a string onto a valid variable name.\nas_tr_sh=\"eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'\"\n\n\nexec 6>&1\n## ----------------------------------- ##\n## Main body of $CONFIG_STATUS script. ##\n## ----------------------------------- ##\n_ASEOF\ntest $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n# Save the log message, to keep $0 and so on meaningful, and to\n# report actual input values of CONFIG_FILES etc. instead of their\n# values after options handling.\nac_log=\"\nThis file was extended by Firmware Mod Kit $as_me 0.4.0, which was\ngenerated by GNU Autoconf 2.65.  Invocation command line was\n\n  CONFIG_FILES    = $CONFIG_FILES\n  CONFIG_HEADERS  = $CONFIG_HEADERS\n  CONFIG_LINKS    = $CONFIG_LINKS\n  CONFIG_COMMANDS = $CONFIG_COMMANDS\n  $ $0 $@\n\non `(hostname || uname -n) 2>/dev/null | sed 1q`\n\"\n\n_ACEOF\n\ncase $ac_config_files in *\"\n\"*) set x $ac_config_files; shift; ac_config_files=$*;;\nesac\n\n\n\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\n# Files that config.status was made for.\nconfig_files=\"$ac_config_files\"\n\n_ACEOF\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\nac_cs_usage=\"\\\n\\`$as_me' instantiates files and other configuration actions\nfrom templates according to the current configuration.  Unless the files\nand actions are specified as TAGs, all are instantiated by default.\n\nUsage: $0 [OPTION]... [TAG]...\n\n  -h, --help       print this help, then exit\n  -V, --version    print version number and configuration settings, then exit\n      --config     print configuration, then exit\n  -q, --quiet, --silent\n                   do not print progress messages\n  -d, --debug      don't remove temporary files\n      --recheck    update $as_me by reconfiguring in the same conditions\n      --file=FILE[:TEMPLATE]\n                   instantiate the configuration file FILE\n\nConfiguration files:\n$config_files\n\nReport bugs to <http://firmware-mod-kit.googlecode.com>.\"\n\n_ACEOF\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\nac_cs_config=\"`$as_echo \"$ac_configure_args\" | sed 's/^ //; s/[\\\\\"\"\\`\\$]/\\\\\\\\&/g'`\"\nac_cs_version=\"\\\\\nFirmware Mod Kit config.status 0.4.0\nconfigured by $0, generated by GNU Autoconf 2.65,\n  with options \\\\\"\\$ac_cs_config\\\\\"\n\nCopyright (C) 2009 Free Software Foundation, Inc.\nThis config.status script is free software; the Free Software Foundation\ngives unlimited permission to copy, distribute and modify it.\"\n\nac_pwd='$ac_pwd'\nsrcdir='$srcdir'\ntest -n \"\\$AWK\" || AWK=awk\n_ACEOF\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n# The default lists apply if the user does not specify any file.\nac_need_defaults=:\nwhile test $# != 0\ndo\n  case $1 in\n  --*=*)\n    ac_option=`expr \"X$1\" : 'X\\([^=]*\\)='`\n    ac_optarg=`expr \"X$1\" : 'X[^=]*=\\(.*\\)'`\n    ac_shift=:\n    ;;\n  *)\n    ac_option=$1\n    ac_optarg=$2\n    ac_shift=shift\n    ;;\n  esac\n\n  case $ac_option in\n  # Handling of the options.\n  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)\n    ac_cs_recheck=: ;;\n  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )\n    $as_echo \"$ac_cs_version\"; exit ;;\n  --config | --confi | --conf | --con | --co | --c )\n    $as_echo \"$ac_cs_config\"; exit ;;\n  --debug | --debu | --deb | --de | --d | -d )\n    debug=: ;;\n  --file | --fil | --fi | --f )\n    $ac_shift\n    case $ac_optarg in\n    *\\'*) ac_optarg=`$as_echo \"$ac_optarg\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"` ;;\n    esac\n    as_fn_append CONFIG_FILES \" '$ac_optarg'\"\n    ac_need_defaults=false;;\n  --he | --h |  --help | --hel | -h )\n    $as_echo \"$ac_cs_usage\"; exit ;;\n  -q | -quiet | --quiet | --quie | --qui | --qu | --q \\\n  | -silent | --silent | --silen | --sile | --sil | --si | --s)\n    ac_cs_silent=: ;;\n\n  # This is an error.\n  -*) as_fn_error \"unrecognized option: \\`$1'\nTry \\`$0 --help' for more information.\" ;;\n\n  *) as_fn_append ac_config_targets \" $1\"\n     ac_need_defaults=false ;;\n\n  esac\n  shift\ndone\n\nac_configure_extra_args=\n\nif $ac_cs_silent; then\n  exec 6>/dev/null\n  ac_configure_extra_args=\"$ac_configure_extra_args --silent\"\nfi\n\n_ACEOF\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\nif \\$ac_cs_recheck; then\n  set X '$SHELL' '$0' $ac_configure_args \\$ac_configure_extra_args --no-create --no-recursion\n  shift\n  \\$as_echo \"running CONFIG_SHELL=$SHELL \\$*\" >&6\n  CONFIG_SHELL='$SHELL'\n  export CONFIG_SHELL\n  exec \"\\$@\"\nfi\n\n_ACEOF\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\nexec 5>>config.log\n{\n  echo\n  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX\n## Running $as_me. ##\n_ASBOX\n  $as_echo \"$ac_log\"\n} >&5\n\n_ACEOF\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\n_ACEOF\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n\n# Handling of arguments.\nfor ac_config_target in $ac_config_targets\ndo\n  case $ac_config_target in\n    \"Makefile\") CONFIG_FILES=\"$CONFIG_FILES Makefile\" ;;\n\n  *) as_fn_error \"invalid argument: \\`$ac_config_target'\" \"$LINENO\" 5;;\n  esac\ndone\n\n\n# If the user did not use the arguments to specify the items to instantiate,\n# then the envvar interface is used.  Set only those that are not.\n# We use the long form for the default assignment because of an extremely\n# bizarre bug on SunOS 4.1.3.\nif $ac_need_defaults; then\n  test \"${CONFIG_FILES+set}\" = set || CONFIG_FILES=$config_files\nfi\n\n# Have a temporary directory for convenience.  Make it in the build tree\n# simply because there is no reason against having it here, and in addition,\n# creating and moving files from /tmp can sometimes cause problems.\n# Hook for its removal unless debugging.\n# Note that there is a small window in which the directory will not be cleaned:\n# after its creation but before its name has been assigned to `$tmp'.\n$debug ||\n{\n  tmp=\n  trap 'exit_status=$?\n  { test -z \"$tmp\" || test ! -d \"$tmp\" || rm -fr \"$tmp\"; } && exit $exit_status\n' 0\n  trap 'as_fn_exit 1' 1 2 13 15\n}\n# Create a (secure) tmp directory for tmp files.\n\n{\n  tmp=`(umask 077 && mktemp -d \"./confXXXXXX\") 2>/dev/null` &&\n  test -n \"$tmp\" && test -d \"$tmp\"\n}  ||\n{\n  tmp=./conf$$-$RANDOM\n  (umask 077 && mkdir \"$tmp\")\n} || as_fn_error \"cannot create a temporary directory in .\" \"$LINENO\" 5\n\n# Set up the scripts for CONFIG_FILES section.\n# No need to generate them if there are no CONFIG_FILES.\n# This happens for instance with `./config.status config.h'.\nif test -n \"$CONFIG_FILES\"; then\n\n\nac_cr=`echo X | tr X '\\015'`\n# On cygwin, bash can eat \\r inside `` if the user requested igncr.\n# But we know of no other shell where ac_cr would be empty at this\n# point, so we can use a bashism as a fallback.\nif test \"x$ac_cr\" = x; then\n  eval ac_cr=\\$\\'\\\\r\\'\nfi\nac_cs_awk_cr=`$AWK 'BEGIN { print \"a\\rb\" }' </dev/null 2>/dev/null`\nif test \"$ac_cs_awk_cr\" = \"a${ac_cr}b\"; then\n  ac_cs_awk_cr='\\r'\nelse\n  ac_cs_awk_cr=$ac_cr\nfi\n\necho 'BEGIN {' >\"$tmp/subs1.awk\" &&\n_ACEOF\n\n\n{\n  echo \"cat >conf$$subs.awk <<_ACEOF\" &&\n  echo \"$ac_subst_vars\" | sed 's/.*/&!$&$ac_delim/' &&\n  echo \"_ACEOF\"\n} >conf$$subs.sh ||\n  as_fn_error \"could not make $CONFIG_STATUS\" \"$LINENO\" 5\nac_delim_num=`echo \"$ac_subst_vars\" | grep -c '$'`\nac_delim='%!_!# '\nfor ac_last_try in false false false false false :; do\n  . ./conf$$subs.sh ||\n    as_fn_error \"could not make $CONFIG_STATUS\" \"$LINENO\" 5\n\n  ac_delim_n=`sed -n \"s/.*$ac_delim\\$/X/p\" conf$$subs.awk | grep -c X`\n  if test $ac_delim_n = $ac_delim_num; then\n    break\n  elif $ac_last_try; then\n    as_fn_error \"could not make $CONFIG_STATUS\" \"$LINENO\" 5\n  else\n    ac_delim=\"$ac_delim!$ac_delim _$ac_delim!! \"\n  fi\ndone\nrm -f conf$$subs.sh\n\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\ncat >>\"\\$tmp/subs1.awk\" <<\\\\_ACAWK &&\n_ACEOF\nsed -n '\nh\ns/^/S[\"/; s/!.*/\"]=/\np\ng\ns/^[^!]*!//\n:repl\nt repl\ns/'\"$ac_delim\"'$//\nt delim\n:nl\nh\ns/\\(.\\{148\\}\\)..*/\\1/\nt more1\ns/[\"\\\\]/\\\\&/g; s/^/\"/; s/$/\\\\n\"\\\\/\np\nn\nb repl\n:more1\ns/[\"\\\\]/\\\\&/g; s/^/\"/; s/$/\"\\\\/\np\ng\ns/.\\{148\\}//\nt nl\n:delim\nh\ns/\\(.\\{148\\}\\)..*/\\1/\nt more2\ns/[\"\\\\]/\\\\&/g; s/^/\"/; s/$/\"/\np\nb\n:more2\ns/[\"\\\\]/\\\\&/g; s/^/\"/; s/$/\"\\\\/\np\ng\ns/.\\{148\\}//\nt delim\n' <conf$$subs.awk | sed '\n/^[^\"\"]/{\n  N\n  s/\\n//\n}\n' >>$CONFIG_STATUS || ac_write_fail=1\nrm -f conf$$subs.awk\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\n_ACAWK\ncat >>\"\\$tmp/subs1.awk\" <<_ACAWK &&\n  for (key in S) S_is_set[key] = 1\n  FS = \"\u0007\"\n\n}\n{\n  line = $ 0\n  nfields = split(line, field, \"@\")\n  substed = 0\n  len = length(field[1])\n  for (i = 2; i < nfields; i++) {\n    key = field[i]\n    keylen = length(key)\n    if (S_is_set[key]) {\n      value = S[key]\n      line = substr(line, 1, len) \"\" value \"\" substr(line, len + keylen + 3)\n      len += length(value) + length(field[++i])\n      substed = 1\n    } else\n      len += 1 + keylen\n  }\n\n  print line\n}\n\n_ACAWK\n_ACEOF\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\nif sed \"s/$ac_cr//\" < /dev/null > /dev/null 2>&1; then\n  sed \"s/$ac_cr\\$//; s/$ac_cr/$ac_cs_awk_cr/g\"\nelse\n  cat\nfi < \"$tmp/subs1.awk\" > \"$tmp/subs.awk\" \\\n  || as_fn_error \"could not setup config files machinery\" \"$LINENO\" 5\n_ACEOF\n\n# VPATH may cause trouble with some makes, so we remove $(srcdir),\n# ${srcdir} and @srcdir@ from VPATH if srcdir is \".\", strip leading and\n# trailing colons and then remove the whole line if VPATH becomes empty\n# (actually we leave an empty line to preserve line numbers).\nif test \"x$srcdir\" = x.; then\n  ac_vpsub='/^[\t ]*VPATH[\t ]*=/{\ns/:*\\$(srcdir):*/:/\ns/:*\\${srcdir}:*/:/\ns/:*@srcdir@:*/:/\ns/^\\([^=]*=[\t ]*\\):*/\\1/\ns/:*$//\ns/^[^=]*=[\t ]*$//\n}'\nfi\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\nfi # test -n \"$CONFIG_FILES\"\n\n\neval set X \"  :F $CONFIG_FILES      \"\nshift\nfor ac_tag\ndo\n  case $ac_tag in\n  :[FHLC]) ac_mode=$ac_tag; continue;;\n  esac\n  case $ac_mode$ac_tag in\n  :[FHL]*:*);;\n  :L* | :C*:*) as_fn_error \"invalid tag \\`$ac_tag'\" \"$LINENO\" 5;;\n  :[FH]-) ac_tag=-:-;;\n  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;\n  esac\n  ac_save_IFS=$IFS\n  IFS=:\n  set x $ac_tag\n  IFS=$ac_save_IFS\n  shift\n  ac_file=$1\n  shift\n\n  case $ac_mode in\n  :L) ac_source=$1;;\n  :[FH])\n    ac_file_inputs=\n    for ac_f\n    do\n      case $ac_f in\n      -) ac_f=\"$tmp/stdin\";;\n      *) # Look for the file first in the build tree, then in the source tree\n\t # (if the path is not absolute).  The absolute path cannot be DOS-style,\n\t # because $ac_f cannot contain `:'.\n\t test -f \"$ac_f\" ||\n\t   case $ac_f in\n\t   [\\\\/$]*) false;;\n\t   *) test -f \"$srcdir/$ac_f\" && ac_f=\"$srcdir/$ac_f\";;\n\t   esac ||\n\t   as_fn_error \"cannot find input file: \\`$ac_f'\" \"$LINENO\" 5;;\n      esac\n      case $ac_f in *\\'*) ac_f=`$as_echo \"$ac_f\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"`;; esac\n      as_fn_append ac_file_inputs \" '$ac_f'\"\n    done\n\n    # Let's still pretend it is `configure' which instantiates (i.e., don't\n    # use $as_me), people would be surprised to read:\n    #    /* config.h.  Generated by config.status.  */\n    configure_input='Generated from '`\n\t  $as_echo \"$*\" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'\n\t`' by configure.'\n    if test x\"$ac_file\" != x-; then\n      configure_input=\"$ac_file.  $configure_input\"\n      { $as_echo \"$as_me:${as_lineno-$LINENO}: creating $ac_file\" >&5\n$as_echo \"$as_me: creating $ac_file\" >&6;}\n    fi\n    # Neutralize special characters interpreted by sed in replacement strings.\n    case $configure_input in #(\n    *\\&* | *\\|* | *\\\\* )\n       ac_sed_conf_input=`$as_echo \"$configure_input\" |\n       sed 's/[\\\\\\\\&|]/\\\\\\\\&/g'`;; #(\n    *) ac_sed_conf_input=$configure_input;;\n    esac\n\n    case $ac_tag in\n    *:-:* | *:-) cat >\"$tmp/stdin\" \\\n      || as_fn_error \"could not create $ac_file\" \"$LINENO\" 5 ;;\n    esac\n    ;;\n  esac\n\n  ac_dir=`$as_dirname -- \"$ac_file\" ||\n$as_expr X\"$ac_file\" : 'X\\(.*[^/]\\)//*[^/][^/]*/*$' \\| \\\n\t X\"$ac_file\" : 'X\\(//\\)[^/]' \\| \\\n\t X\"$ac_file\" : 'X\\(//\\)$' \\| \\\n\t X\"$ac_file\" : 'X\\(/\\)' \\| . 2>/dev/null ||\n$as_echo X\"$ac_file\" |\n    sed '/^X\\(.*[^/]\\)\\/\\/*[^/][^/]*\\/*$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)[^/].*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\/\\)$/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  /^X\\(\\/\\).*/{\n\t    s//\\1/\n\t    q\n\t  }\n\t  s/.*/./; q'`\n  as_dir=\"$ac_dir\"; as_fn_mkdir_p\n  ac_builddir=.\n\ncase \"$ac_dir\" in\n.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;\n*)\n  ac_dir_suffix=/`$as_echo \"$ac_dir\" | sed 's|^\\.[\\\\/]||'`\n  # A \"..\" for each directory in $ac_dir_suffix.\n  ac_top_builddir_sub=`$as_echo \"$ac_dir_suffix\" | sed 's|/[^\\\\/]*|/..|g;s|/||'`\n  case $ac_top_builddir_sub in\n  \"\") ac_top_builddir_sub=. ac_top_build_prefix= ;;\n  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;\n  esac ;;\nesac\nac_abs_top_builddir=$ac_pwd\nac_abs_builddir=$ac_pwd$ac_dir_suffix\n# for backward compatibility:\nac_top_builddir=$ac_top_build_prefix\n\ncase $srcdir in\n  .)  # We are building in place.\n    ac_srcdir=.\n    ac_top_srcdir=$ac_top_builddir_sub\n    ac_abs_top_srcdir=$ac_pwd ;;\n  [\\\\/]* | ?:[\\\\/]* )  # Absolute name.\n    ac_srcdir=$srcdir$ac_dir_suffix;\n    ac_top_srcdir=$srcdir\n    ac_abs_top_srcdir=$srcdir ;;\n  *) # Relative name.\n    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix\n    ac_top_srcdir=$ac_top_build_prefix$srcdir\n    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;\nesac\nac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix\n\n\n  case $ac_mode in\n  :F)\n  #\n  # CONFIG_FILE\n  #\n\n_ACEOF\n\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n# If the template does not know about datarootdir, expand it.\n# FIXME: This hack should be removed a few years after 2.60.\nac_datarootdir_hack=; ac_datarootdir_seen=\nac_sed_dataroot='\n/datarootdir/ {\n  p\n  q\n}\n/@datadir@/p\n/@docdir@/p\n/@infodir@/p\n/@localedir@/p\n/@mandir@/p'\ncase `eval \"sed -n \\\"\\$ac_sed_dataroot\\\" $ac_file_inputs\"` in\n*datarootdir*) ac_datarootdir_seen=yes;;\n*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting\" >&5\n$as_echo \"$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting\" >&2;}\n_ACEOF\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\n  ac_datarootdir_hack='\n  s&@datadir@&$datadir&g\n  s&@docdir@&$docdir&g\n  s&@infodir@&$infodir&g\n  s&@localedir@&$localedir&g\n  s&@mandir@&$mandir&g\n  s&\\\\\\${datarootdir}&$datarootdir&g' ;;\nesac\n_ACEOF\n\n# Neutralize VPATH when `$srcdir' = `.'.\n# Shell code in configure.ac might set extrasub.\n# FIXME: do we really want to maintain this feature?\ncat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1\nac_sed_extra=\"$ac_vpsub\n$extrasub\n_ACEOF\ncat >>$CONFIG_STATUS <<\\_ACEOF || ac_write_fail=1\n:t\n/@[a-zA-Z_][a-zA-Z_0-9]*@/!b\ns|@configure_input@|$ac_sed_conf_input|;t t\ns&@top_builddir@&$ac_top_builddir_sub&;t t\ns&@top_build_prefix@&$ac_top_build_prefix&;t t\ns&@srcdir@&$ac_srcdir&;t t\ns&@abs_srcdir@&$ac_abs_srcdir&;t t\ns&@top_srcdir@&$ac_top_srcdir&;t t\ns&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t\ns&@builddir@&$ac_builddir&;t t\ns&@abs_builddir@&$ac_abs_builddir&;t t\ns&@abs_top_builddir@&$ac_abs_top_builddir&;t t\n$ac_datarootdir_hack\n\"\neval sed \\\"\\$ac_sed_extra\\\" \"$ac_file_inputs\" | $AWK -f \"$tmp/subs.awk\" >$tmp/out \\\n  || as_fn_error \"could not create $ac_file\" \"$LINENO\" 5\n\ntest -z \"$ac_datarootdir_hack$ac_datarootdir_seen\" &&\n  { ac_out=`sed -n '/\\${datarootdir}/p' \"$tmp/out\"`; test -n \"$ac_out\"; } &&\n  { ac_out=`sed -n '/^[\t ]*datarootdir[\t ]*:*=/p' \"$tmp/out\"`; test -z \"$ac_out\"; } &&\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \\`datarootdir'\nwhich seems to be undefined.  Please make sure it is defined.\" >&5\n$as_echo \"$as_me: WARNING: $ac_file contains a reference to the variable \\`datarootdir'\nwhich seems to be undefined.  Please make sure it is defined.\" >&2;}\n\n  rm -f \"$tmp/stdin\"\n  case $ac_file in\n  -) cat \"$tmp/out\" && rm -f \"$tmp/out\";;\n  *) rm -f \"$ac_file\" && mv \"$tmp/out\" \"$ac_file\";;\n  esac \\\n  || as_fn_error \"could not create $ac_file\" \"$LINENO\" 5\n ;;\n\n\n\n  esac\n\ndone # for ac_tag\n\n\nas_fn_exit 0\n_ACEOF\nac_clean_files=$ac_clean_files_save\n\ntest $ac_write_fail = 0 ||\n  as_fn_error \"write failure creating $CONFIG_STATUS\" \"$LINENO\" 5\n\n\n# configure is writing to config.log, and then calls config.status.\n# config.status does its own redirection, appending to config.log.\n# Unfortunately, on DOS this fails, as config.log is still kept open\n# by configure, so config.status won't be able to write to it; its\n# output is simply discarded.  So we exec the FD to /dev/null,\n# effectively closing config.log, so it can be properly (re)opened and\n# appended to by config.status.  When coming back to configure, we\n# need to make the FD available again.\nif test \"$no_create\" != yes; then\n  ac_cs_success=:\n  ac_config_status_args=\n  test \"$silent\" = yes &&\n    ac_config_status_args=\"$ac_config_status_args --quiet\"\n  exec 5>/dev/null\n  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false\n  exec 5>>config.log\n  # Use ||, not &&, to avoid exiting from the if with $? = 1, which\n  # would make configure fail if this is the last instruction.\n  $ac_cs_success || as_fn_exit $?\nfi\nif test -n \"$ac_unrecognized_opts\" && test \"$enable_option_checking\" != no; then\n  { $as_echo \"$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts\" >&5\n$as_echo \"$as_me: WARNING: unrecognized options: $ac_unrecognized_opts\" >&2;}\nfi\n\n"
  },
  {
    "path": "src/configure.ac",
    "content": "AC_PREREQ([2.65])\nAC_INIT([Firmware Mod Kit],[0.4.0],[http://firmware-mod-kit.googlecode.com])\n\nAC_PROG_CC\nAC_PROG_CXX\nAC_LANG(C)\n\nAC_TYPE_SIZE_T\n\nAC_FUNC_MALLOC\n\nAC_CHECK_HEADERS([arpa/inet.h fcntl.h stdlib.h string.h unistd.h],[],[echo \"error: missing necessary header file(s)\" && exit])\nAC_CHECK_FUNCS([memset malloc strstr],[],AC_MSG_ERROR([\"Missing necessary function(s)\"]))\n\nAC_CHECK_LIB([z],[crc32],[],[echo \"error: missing zlib library\" && exit],[])\nAC_CHECK_HEADERS([zlib.h],[],[echo \"error: missing zlib header files\" && exit])\nAC_CHECK_HEADERS([lzma.h],[],[echo \"error: missing liblzma header files\" && exit])\n\nAC_CONFIG_FILES([Makefile])\nAC_OUTPUT\n"
  },
  {
    "path": "src/cramfs-2.x/COPYING",
    "content": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n\t\t    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n\t    How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) year name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "src/cramfs-2.x/GNUmakefile",
    "content": "CC = gcc\nCFLAGS = -W -Wall -O2 -g\nCPPFLAGS = -I.\nLDLIBS = -lz\nPROGS = mkcramfs cramfsck\n\nall: $(PROGS)\n\ndistclean clean:\n\trm -f $(PROGS)\n\n.PHONY: all clean\n"
  },
  {
    "path": "src/cramfs-2.x/NOTES",
    "content": "Notes on Filesystem Layout\n--------------------------\n\nThese notes describe what mkcramfs generates.  Kernel requirements are\na bit looser, e.g. it doesn't care if the <file_data> items are\nswapped around (though it does care that directory entries (inodes) in\na given directory are contiguous, as this is used by readdir).\n\nAll data is currently in host-endian format; neither mkcramfs nor the\nkernel ever do swabbing.  (See section `Block Size' below.)\n\n<filesystem>:\n\t<superblock>\n\t<directory_structure>\n\t<data>\n\n<superblock>: struct cramfs_super (see cramfs_fs.h).\n\n<directory_structure>:\n\tFor each file:\n\t\tstruct cramfs_inode (see cramfs_fs.h).\n\t\tFilename.  Not generally null-terminated, but it is\n\t\t null-padded to a multiple of 4 bytes.\n\nThe order of inode traversal is described as \"width-first\" (not to be\nconfused with breadth-first); i.e. like depth-first but listing all of\na directory's entries before recursing down its subdirectories: the\nsame order as `ls -AUR' (but without the /^\\..*:$/ directory header\nlines); put another way, the same order as `find -type d -exec\nls -AU1 {} \\;'.\n\nBeginning in 2.4.7, directory entries are sorted.  This optimization\nallows cramfs_lookup to return more quickly when a filename does not\nexist, speeds up user-space directory sorts, etc.\n\n<data>:\n\tOne <file_data> for each file that's either a symlink or a\n\t regular file of non-zero st_size.\n\n<file_data>:\n\tnblocks * <block_pointer>\n\t (where nblocks = (st_size - 1) / blksize + 1)\n\tnblocks * <block>\n\tpadding to multiple of 4 bytes\n\nThe i'th <block_pointer> for a file stores the byte offset of the\n*end* of the i'th <block> (i.e. one past the last byte, which is the\nsame as the start of the (i+1)'th <block> if there is one).  The first\n<block> immediately follows the last <block_pointer> for the file.\n<block_pointer>s are each 32 bits long.\n\nThe order of <file_data>'s is a depth-first descent of the directory\ntree, i.e. the same order as `find -size +0 \\( -type f -o -type l \\)\n-print'.\n\n\n<block>: The i'th <block> is the output of zlib's compress function\napplied to the i'th blksize-sized chunk of the input data.\n(For the last <block> of the file, the input may of course be smaller.)\nEach <block> may be a different size.  (See <block_pointer> above.)\n<block>s are merely byte-aligned, not generally u32-aligned.\n\n\nHoles\n-----\n\nThis kernel supports cramfs holes (i.e. [efficient representation of]\nblocks in uncompressed data consisting entirely of NUL bytes), but by\ndefault mkcramfs doesn't test for & create holes, since cramfs in\nkernels up to at least 2.3.39 didn't support holes.  Run mkcramfs\nwith -z if you want it to create files that can have holes in them.\n\n\nTools\n-----\n\nThe cramfs user-space tools, including mkcramfs and cramfsck, are\nlocated at <http://sourceforge.net/projects/cramfs/>.\n\n\nFuture Development\n==================\n\nBlock Size\n----------\n\n(Block size in cramfs refers to the size of input data that is\ncompressed at a time.  It's intended to be somewhere around\nPAGE_CACHE_SIZE for cramfs_readpage's convenience.)\n\nThe superblock ought to indicate the block size that the fs was\nwritten for, since comments in <linux/pagemap.h> indicate that\nPAGE_CACHE_SIZE may grow in future (if I interpret the comment\ncorrectly).\n\nCurrently, mkcramfs #define's PAGE_CACHE_SIZE as 4096 and uses that\nfor blksize, whereas Linux-2.3.39 uses its PAGE_CACHE_SIZE, which in\nturn is defined as PAGE_SIZE (which can be as large as 32KB on arm).\nThis discrepancy is a bug, though it's not clear which should be\nchanged.\n\nOne option is to change mkcramfs to take its PAGE_CACHE_SIZE from\n<asm/page.h>.  Personally I don't like this option, but it does\nrequire the least amount of change: just change `#define\nPAGE_CACHE_SIZE (4096)' to `#include <asm/page.h>'.  The disadvantage\nis that the generated cramfs cannot always be shared between different\nkernels, not even necessarily kernels of the same architecture if\nPAGE_CACHE_SIZE is subject to change between kernel versions\n(currently possible with arm and ia64).\n\nThe remaining options try to make cramfs more sharable.\n\nOne part of that is addressing endianness.  The two options here are\n`always use little-endian' (like ext2fs) or `writer chooses\nendianness; kernel adapts at runtime'.  Little-endian wins because of\ncode simplicity and little CPU overhead even on big-endian machines.\n\nThe cost of swabbing is changing the code to use the le32_to_cpu\netc. macros as used by ext2fs.  We don't need to swab the compressed\ndata, only the superblock, inodes and block pointers.\n\n\nThe other part of making cramfs more sharable is choosing a block\nsize.  The options are:\n\n  1. Always 4096 bytes.\n\n  2. Writer chooses blocksize; kernel adapts but rejects blocksize >\n     PAGE_CACHE_SIZE.\n\n  3. Writer chooses blocksize; kernel adapts even to blocksize >\n     PAGE_CACHE_SIZE.\n\nIt's easy enough to change the kernel to use a smaller value than\nPAGE_CACHE_SIZE: just make cramfs_readpage read multiple blocks.\n\nThe cost of option 1 is that kernels with a larger PAGE_CACHE_SIZE\nvalue don't get as good compression as they can.\n\nThe cost of option 2 relative to option 1 is that the code uses\nvariables instead of #define'd constants.  The gain is that people\nwith kernels having larger PAGE_CACHE_SIZE can make use of that if\nthey don't mind their cramfs being inaccessible to kernels with\nsmaller PAGE_CACHE_SIZE values.\n\nOption 3 is easy to implement if we don't mind being CPU-inefficient:\ne.g. get readpage to decompress to a buffer of size MAX_BLKSIZE (which\nmust be no larger than 32KB) and discard what it doesn't need.\nGetting readpage to read into all the covered pages is harder.\n\nThe main advantage of option 3 over 1, 2, is better compression.  The\ncost is greater complexity.  Probably not worth it, but I hope someone\nwill disagree.  (If it is implemented, then I'll re-use that code in\ne2compr.)\n\n\nAnother cost of 2 and 3 over 1 is making mkcramfs use a different\nblock size, but that just means adding and parsing a -b option.\n\n\nInode Size\n----------\n\nGiven that cramfs will probably be used for CDs etc. as well as just\nsilicon ROMs, it might make sense to expand the inode a little from\nits current 12 bytes.  Inodes other than the root inode are followed\nby filename, so the expansion doesn't even have to be a multiple of 4\nbytes.\n"
  },
  {
    "path": "src/cramfs-2.x/README",
    "content": "\n\tCramfs - cram a filesystem onto a small ROM\n\ncramfs is designed to be simple and small, and to compress things well. \n\nIt uses the zlib routines to compress a file one page at a time, and\nallows random page access.  The meta-data is not compressed, but is\nexpressed in a very terse representation to make it use much less\ndiskspace than traditional filesystems. \n\nYou can't write to a cramfs filesystem (making it compressible and\ncompact also makes it _very_ hard to update on-the-fly), so you have to\ncreate the disk image with the \"mkcramfs\" utility.\n\n\nUsage Notes\n-----------\n\nFile sizes are limited to less than 16MB.\n\nMaximum filesystem size is a little over 256MB.  (The last file on the\nfilesystem is allowed to extend past 256MB.)\n\nOnly the low 8 bits of gid are stored.  The current version of\nmkcramfs simply truncates to 8 bits, which is a potential security\nissue.\n\nHard links are supported, but hard linked files\nwill still have a link count of 1 in the cramfs image.\n\nCramfs directories have no `.' or `..' entries.  Directories (like\nevery other file on cramfs) always have a link count of 1.  (There's\nno need to use -noleaf in `find', btw.)\n\nNo timestamps are stored in a cramfs, so these default to the epoch\n(1970 GMT).  Recently-accessed files may have updated timestamps, but\nthe update lasts only as long as the inode is cached in memory, after\nwhich the timestamp reverts to 1970, i.e. moves backwards in time.\n\nCurrently, cramfs must be written and read with architectures of the\nsame endianness, and can be read only by kernels with PAGE_CACHE_SIZE\n== 4096.  At least the latter of these is a bug, but it hasn't been\ndecided what the best fix is.  For the moment if you have larger pages\nyou can just change the #define in mkcramfs.c, so long as you don't\nmind the filesystem becoming unreadable to future kernels.\n\n\nFor /usr/share/magic\n--------------------\n\n0\tulelong\t0x28cd3d45\tLinux cramfs offset 0\n>4\tulelong\tx\t\tsize %d\n>8\tulelong\tx\t\tflags 0x%x\n>12\tulelong\tx\t\tfuture 0x%x\n>16\tstring\t>\\0\t\tsignature \"%.16s\"\n>32\tulelong\tx\t\tfsid.crc 0x%x\n>36\tulelong\tx\t\tfsid.edition %d\n>40\tulelong\tx\t\tfsid.blocks %d\n>44\tulelong\tx\t\tfsid.files %d\n>48\tstring\t>\\0\t\tname \"%.16s\"\n512\tulelong\t0x28cd3d45\tLinux cramfs offset 512\n>516\tulelong\tx\t\tsize %d\n>520\tulelong\tx\t\tflags 0x%x\n>524\tulelong\tx\t\tfuture 0x%x\n>528\tstring\t>\\0\t\tsignature \"%.16s\"\n>544\tulelong\tx\t\tfsid.crc 0x%x\n>548\tulelong\tx\t\tfsid.edition %d\n>552\tulelong\tx\t\tfsid.blocks %d\n>556\tulelong\tx\t\tfsid.files %d\n>560\tstring\t>\\0\t\tname \"%.16s\"\n\n\nHacker Notes\n------------\n\nSee fs/cramfs/README for filesystem layout and implementation notes.\n"
  },
  {
    "path": "src/cramfs-2.x/cramfsck.c",
    "content": "/*\n * cramfsck - check a cramfs file system\n *\n * Copyright (C) 2000-2002 Transmeta Corporation\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n *\n * 1999/12/03: Linus Torvalds (cramfs tester and unarchive program)\n * 2000/06/03: Daniel Quinlan (CRC and length checking program)\n * 2000/06/04: Daniel Quinlan (merged programs, added options, support\n *                            for special files, preserve permissions and\n *                            ownership, cramfs superblock v2, bogus mode\n *                            test, pathname length test, etc.)\n * 2000/06/06: Daniel Quinlan (support for holes, pretty-printing,\n *                            symlink size test)\n * 2000/07/11: Daniel Quinlan (file length tests, start at offset 0 or 512,\n *                            fsck-compatible exit codes)\n * 2000/07/15: Daniel Quinlan (initial support for block devices)\n * 2002/01/10: Daniel Quinlan (additional checks, test more return codes,\n *                            use read if mmap fails, standardize messages)\n */\n\n/* compile-time options */\n#define INCLUDE_FS_TESTS\t/* include cramfs checking and extraction */\n\n#define _GNU_SOURCE\n#include <sys/types.h>\n#include <stdio.h>\n#include <stdarg.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <sys/mman.h>\n#include <fcntl.h>\n#include <dirent.h>\n#include <stdlib.h>\n#include <errno.h>\n#include <string.h>\n#include <sys/sysmacros.h>\n#include <utime.h>\n#include <sys/ioctl.h>\n#define _LINUX_STRING_H_\n#include <linux/fs.h>\n#include <linux/cramfs_fs.h>\n#include <zlib.h>\n\n/* Exit codes used by fsck-type programs */\n#define FSCK_OK          0\t/* No errors */\n#define FSCK_NONDESTRUCT 1\t/* File system errors corrected */\n#define FSCK_REBOOT      2\t/* System should be rebooted */\n#define FSCK_UNCORRECTED 4\t/* File system errors left uncorrected */\n#define FSCK_ERROR       8\t/* Operational error */\n#define FSCK_USAGE       16\t/* Usage or syntax error */\n#define FSCK_LIBRARY     128\t/* Shared library error */\n\n#define PAD_SIZE 512\n#define PAGE_CACHE_SIZE (4096)\n\nstatic const char *progname = \"cramfsck\";\n\nstatic int fd;\t\t\t/* ROM image file descriptor */\nstatic char *filename;\t\t/* ROM image filename */\nstruct cramfs_super super;\t/* just find the cramfs superblock once */\nstatic int opt_verbose = 0;\t/* 1 = verbose (-v), 2+ = very verbose (-vv) */\n#ifdef INCLUDE_FS_TESTS\nstatic int opt_extract = 0;\t\t/* extract cramfs (-x) */\nstatic char *extract_dir = \"root\";\t/* extraction directory (-x) */\nstatic uid_t euid;\t\t\t/* effective UID */\n\n/* (cramfs_super + start) <= start_dir < end_dir <= start_data <= end_data */\nstatic unsigned long start_dir = ~0UL;\t/* start of first non-root inode */\nstatic unsigned long end_dir = 0;\t/* end of the directory structure */\nstatic unsigned long start_data = ~0UL;\t/* start of the data (256 MB = max) */\nstatic unsigned long end_data = 0;\t/* end of the data */\n\n/* Guarantee access to at least 8kB at a time */\n#define ROMBUFFER_BITS\t13\n#define ROMBUFFERSIZE\t(1 << ROMBUFFER_BITS)\n#define ROMBUFFERMASK\t(ROMBUFFERSIZE-1)\nstatic char read_buffer[ROMBUFFERSIZE * 2];\nstatic unsigned long read_buffer_block = ~0UL;\n\n/* Uncompressing data structures... */\nstatic char outbuffer[PAGE_CACHE_SIZE*2];\nstatic z_stream stream;\n\n/* Prototypes */\nstatic void expand_fs(char *, struct cramfs_inode *);\n#endif /* INCLUDE_FS_TESTS */\n\n/* Input status of 0 to print help and exit without an error. */\nstatic void usage(int status)\n{\n\tFILE *stream = status ? stderr : stdout;\n\n\tfprintf(stream, \"usage: %s [-hv] [-x dir] file\\n\"\n\t\t\" -h         print this help\\n\"\n\t\t\" -x dir     extract into dir\\n\"\n\t\t\" -v         be more verbose\\n\"\n\t\t\" file       file to test\\n\", progname);\n\n\texit(status);\n}\n\nstatic void die(int status, int syserr, const char *fmt, ...)\n{\n\tva_list arg_ptr;\n\tint save = errno;\n\n\tfflush(0);\n\tva_start(arg_ptr, fmt);\n\tfprintf(stderr, \"%s: \", progname);\n\tvfprintf(stderr, fmt, arg_ptr);\n\tif (syserr) {\n\t\tfprintf(stderr, \": %s\", strerror(save));\n\t}\n\tfprintf(stderr, \"\\n\");\n\tva_end(arg_ptr);\n\texit(status);\n}\n\nstatic void test_super(int *start, size_t *length) {\n\tstruct stat st;\n\n\t/* find the physical size of the file or block device */\n\tif (stat(filename, &st) < 0) {\n\t\tdie(FSCK_ERROR, 1, \"stat failed: %s\", filename);\n\t}\n\tfd = open(filename, O_RDONLY);\n\tif (fd < 0) {\n\t\tdie(FSCK_ERROR, 1, \"open failed: %s\", filename);\n\t}\n\tif (S_ISBLK(st.st_mode)) {\n\t\tif (ioctl(fd, BLKGETSIZE, length) < 0) {\n\t\t\tdie(FSCK_ERROR, 1, \"ioctl failed: unable to determine device size: %s\", filename);\n\t\t}\n\t\t*length = *length * 512;\n\t}\n\telse if (S_ISREG(st.st_mode)) {\n\t\t*length = st.st_size;\n\t}\n\telse {\n\t\tdie(FSCK_ERROR, 0, \"not a block device or file: %s\", filename);\n\t}\n\n\tif (*length < sizeof(struct cramfs_super)) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"file length too short\");\n\t}\n\n\t/* find superblock */\n\tif (read(fd, &super, sizeof(super)) != sizeof(super)) {\n\t\tdie(FSCK_ERROR, 1, \"read failed: %s\", filename);\n\t}\n\tif (super.magic == CRAMFS_MAGIC) {\n\t\t*start = 0;\n\t}\n\telse if (*length >= (PAD_SIZE + sizeof(super))) {\n\t\tlseek(fd, PAD_SIZE, SEEK_SET);\n\t\tif (read(fd, &super, sizeof(super)) != sizeof(super)) {\n\t\t\tdie(FSCK_ERROR, 1, \"read failed: %s\", filename);\n\t\t}\n\t\tif (super.magic == CRAMFS_MAGIC) {\n\t\t\t*start = PAD_SIZE;\n\t\t}\n\t}\n\n\t/* superblock tests */\n\tif (super.magic != CRAMFS_MAGIC) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"superblock magic not found\");\n\t}\n\tif (super.flags & ~CRAMFS_SUPPORTED_FLAGS) {\n\t\tdie(FSCK_ERROR, 0, \"unsupported filesystem features\");\n\t}\n\tif (super.size < PAGE_CACHE_SIZE) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"superblock size (%d) too small\", super.size);\n\t}\n\tif (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {\n\t\tif (super.fsid.files == 0) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"zero file count\");\n\t\t}\n\t\tif (*length < super.size) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"file length too short\");\n\t\t}\n\t\telse if (*length > super.size) {\n\t\t\tfprintf(stderr, \"warning: file extends past end of filesystem\\n\");\n\t\t}\n\t}\n\telse {\n\t\tfprintf(stderr, \"warning: old cramfs format\\n\");\n\t}\n}\n\nstatic void test_crc(int start)\n{\n\tvoid *buf;\n\tu32 crc;\n\n\tif (!(super.flags & CRAMFS_FLAG_FSID_VERSION_2)) {\n#ifdef INCLUDE_FS_TESTS\n\t\treturn;\n#else /* not INCLUDE_FS_TESTS */\n\t\tdie(FSCK_USAGE, 0, \"unable to test CRC: old cramfs format\");\n#endif /* not INCLUDE_FS_TESTS */\n\t}\n\n\tcrc = crc32(0L, Z_NULL, 0);\n\n\tbuf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);\n\tif (buf == MAP_FAILED) {\n\t\tbuf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n\t\tif (buf != MAP_FAILED) {\n\t\t\tlseek(fd, 0, SEEK_SET);\n\t\t\tread(fd, buf, super.size);\n\t\t}\n\t}\n\tif (buf != MAP_FAILED) {\n\t\t((struct cramfs_super *) (buf+start))->fsid.crc = crc32(0L, Z_NULL, 0);\n\t\tcrc = crc32(crc, buf+start, super.size-start);\n\t\tmunmap(buf, super.size);\n\t}\n\telse {\n\t\tint retval;\n\t\tsize_t length = 0;\n\n\t\tbuf = malloc(4096);\n\t\tif (!buf) {\n\t\t\tdie(FSCK_ERROR, 1, \"malloc failed\");\n\t\t}\n\t\tlseek(fd, start, SEEK_SET);\n\t\tfor (;;) {\n\t\t\tretval = read(fd, buf, 4096);\n\t\t\tif (retval < 0) {\n\t\t\t\tdie(FSCK_ERROR, 1, \"read failed: %s\", filename);\n\t\t\t}\n\t\t\telse if (retval == 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (length == 0) {\n\t\t\t\t((struct cramfs_super *) buf)->fsid.crc = crc32(0L, Z_NULL, 0);\n\t\t\t}\n\t\t\tlength += retval;\n\t\t\tif (length > (super.size-start)) {\n\t\t\t\tcrc = crc32(crc, buf, retval - (length - (super.size-start)));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcrc = crc32(crc, buf, retval);\n\t\t}\n\t\tfree(buf);\n\t}\n\n\tif (crc != super.fsid.crc) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"crc error\");\n\t}\n}\n\n#ifdef INCLUDE_FS_TESTS\nstatic void print_node(char type, struct cramfs_inode *i, char *name)\n{\n\tchar info[10];\n\n\tif (S_ISCHR(i->mode) || (S_ISBLK(i->mode))) {\n\t\t/* major/minor numbers can be as high as 2^12 or 4096 */\n\t\tsnprintf(info, 10, \"%4d,%4d\", major(i->size), minor(i->size));\n\t}\n\telse {\n\t\t/* size be as high as 2^24 or 16777216 */\n\t\tsnprintf(info, 10, \"%9d\", i->size);\n\t}\n\n\tprintf(\"%c %04o %s %5d:%-3d %s\\n\",\n\t       type, i->mode & ~S_IFMT, info, i->uid, i->gid, name);\n}\n\n/*\n * Create a fake \"blocked\" access\n */\nstatic void *romfs_read(unsigned long offset)\n{\n\tunsigned int block = offset >> ROMBUFFER_BITS;\n\tif (block != read_buffer_block) {\n\t\tread_buffer_block = block;\n\t\tlseek(fd, block << ROMBUFFER_BITS, SEEK_SET);\n\t\tread(fd, read_buffer, ROMBUFFERSIZE * 2);\n\t}\n\treturn read_buffer + (offset & ROMBUFFERMASK);\n}\n\nstatic struct cramfs_inode *cramfs_iget(struct cramfs_inode * i)\n{\n\tstruct cramfs_inode *inode = malloc(sizeof(struct cramfs_inode));\n\n\tif (!inode) {\n\t\tdie(FSCK_ERROR, 1, \"malloc failed\");\n\t}\n\t*inode = *i;\n\treturn inode;\n}\n\nstatic struct cramfs_inode *iget(unsigned int ino)\n{\n\treturn cramfs_iget(romfs_read(ino));\n}\n\nstatic void iput(struct cramfs_inode *inode)\n{\n\tfree(inode);\n}\n\n/*\n * Return the offset of the root directory\n */\nstatic struct cramfs_inode *read_super(void)\n{\n\tunsigned long offset = super.root.offset << 2;\n\n\tif (!S_ISDIR(super.root.mode))\n\t\tdie(FSCK_UNCORRECTED, 0, \"root inode is not directory\");\n\tif (!(super.flags & CRAMFS_FLAG_SHIFTED_ROOT_OFFSET) &&\n\t    ((offset != sizeof(struct cramfs_super)) &&\n\t     (offset != PAD_SIZE + sizeof(struct cramfs_super))))\n\t{\n\t\tdie(FSCK_UNCORRECTED, 0, \"bad root offset (%lu)\", offset);\n\t}\n\treturn cramfs_iget(&super.root);\n}\n\nstatic int uncompress_block(void *src, int len)\n{\n\tint err;\n\n\tstream.next_in = src;\n\tstream.avail_in = len;\n\n\tstream.next_out = (unsigned char *) outbuffer;\n\tstream.avail_out = PAGE_CACHE_SIZE*2;\n\n\tinflateReset(&stream);\n\n\tif (len > PAGE_CACHE_SIZE*2) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"data block too large\");\n\t}\n\terr = inflate(&stream, Z_FINISH);\n\tif (err != Z_STREAM_END) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"decompression error %p(%d): %s\",\n\t\t    zError(err), src, len);\n\t}\n\treturn stream.total_out;\n}\n\nstatic void do_uncompress(char *path, int fd, unsigned long offset, unsigned long size)\n{\n\tunsigned long curr = offset + 4 * ((size + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE);\n\n\tdo {\n\t\tunsigned long out = PAGE_CACHE_SIZE;\n\t\tunsigned long next = *(u32 *) romfs_read(offset);\n\n\t\tif (next > end_data) {\n\t\t\tend_data = next;\n\t\t}\n\n\t\toffset += 4;\n\t\tif (curr == next) {\n\t\t\tif (opt_verbose > 1) {\n\t\t\t\tprintf(\"  hole at %ld (%d)\\n\", curr, PAGE_CACHE_SIZE);\n\t\t\t}\n\t\t\tif (size < PAGE_CACHE_SIZE)\n\t\t\t\tout = size;\n\t\t\tmemset(outbuffer, 0x00, out);\n\t\t}\n\t\telse {\n\t\t\tif (opt_verbose > 1) {\n\t\t\t\tprintf(\"  uncompressing block at %ld to %ld (%ld)\\n\", curr, next, next - curr);\n\t\t\t}\n\t\t\tout = uncompress_block(romfs_read(curr), next - curr);\n\t\t}\n\t\tif (size >= PAGE_CACHE_SIZE) {\n\t\t\tif (out != PAGE_CACHE_SIZE) {\n\t\t\t\tdie(FSCK_UNCORRECTED, 0, \"non-block (%ld) bytes\", out);\n\t\t\t}\n\t\t} else {\n\t\t\tif (out != size) {\n\t\t\t\tdie(FSCK_UNCORRECTED, 0, \"non-size (%ld vs %ld) bytes\", out, size);\n\t\t\t}\n\t\t}\n\t\tsize -= out;\n\t\tif (opt_extract) {\n\t\t\tif (write(fd, outbuffer, out) < 0) {\n\t\t\t\tdie(FSCK_ERROR, 1, \"write failed: %s\", path);\n\t\t\t}\n\t\t}\n\t\tcurr = next;\n\t} while (size);\n}\n\nstatic void change_file_status(char *path, struct cramfs_inode *i)\n{\n\tstruct utimbuf epoch = { 0, 0 };\n\n\tif (euid == 0) {\n\t\tif (lchown(path, i->uid, i->gid) < 0) {\n\t\t\tdie(FSCK_ERROR, 1, \"lchown failed: %s\", path);\n\t\t}\n\t\tif (S_ISLNK(i->mode))\n\t\t\treturn;\n\t\tif ((S_ISUID | S_ISGID) & i->mode) {\n\t\t\tif (chmod(path, i->mode) < 0) {\n\t\t\t\tdie(FSCK_ERROR, 1, \"chown failed: %s\", path);\n\t\t\t}\n\t\t}\n\t}\n\tif (S_ISLNK(i->mode))\n\t\treturn;\n\tif (utime(path, &epoch) < 0) {\n\t\tdie(FSCK_ERROR, 1, \"utime failed: %s\", path);\n\t}\n}\n\nstatic void do_directory(char *path, struct cramfs_inode *i)\n{\n\tint pathlen = strlen(path);\n\tint count = i->size;\n\tunsigned long offset = i->offset << 2;\n\tchar *newpath = malloc(pathlen + 256);\n\n\tif (!newpath) {\n\t\tdie(FSCK_ERROR, 1, \"malloc failed\");\n\t}\n\tif (offset == 0 && count != 0) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"directory inode has zero offset and non-zero size: %s\", path);\n\t}\n\tif (offset != 0 && offset < start_dir) {\n\t\tstart_dir = offset;\n\t}\n\t/* TODO: Do we need to check end_dir for empty case? */\n\tmemcpy(newpath, path, pathlen);\n\tnewpath[pathlen] = '/';\n\tpathlen++;\n\tif (opt_verbose) {\n\t\tprint_node('d', i, path);\n\t}\n\tif (opt_extract) {\n\t\tif (mkdir(path, i->mode) < 0) {\n\t\t\tdie(FSCK_ERROR, 1, \"mkdir failed: %s\", path);\n\t\t}\n\t\tchange_file_status(path, i);\n\t}\n\twhile (count > 0) {\n\t\tstruct cramfs_inode *child = iget(offset);\n\t\tint size;\n\t\tint newlen = child->namelen << 2;\n\n\t\tsize = sizeof(struct cramfs_inode) + newlen;\n\t\tcount -= size;\n\n\t\toffset += sizeof(struct cramfs_inode);\n\n\t\tmemcpy(newpath + pathlen, romfs_read(offset), newlen);\n\t\tnewpath[pathlen + newlen] = 0;\n\t\tif (newlen == 0) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"filename length is zero\");\n\t\t}\n\t\tif ((pathlen + newlen) - strlen(newpath) > 3) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"bad filename length\");\n\t\t}\n\t\texpand_fs(newpath, child);\n\n\t\toffset += newlen;\n\n\t\tif (offset <= start_dir) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"bad inode offset\");\n\t\t}\n\t\tif (offset > end_dir) {\n\t\t\tend_dir = offset;\n\t\t}\n\t\tiput(child); /* free(child) */\n\t}\n\tfree(newpath);\n}\n\nstatic void do_file(char *path, struct cramfs_inode *i)\n{\n\tunsigned long offset = i->offset << 2;\n\tint fd = 0;\n\n\tif (offset == 0 && i->size != 0) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"file inode has zero offset and non-zero size\");\n\t}\n\tif (i->size == 0 && offset != 0) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"file inode has zero size and non-zero offset\");\n\t}\n\tif (offset != 0 && offset < start_data) {\n\t\tstart_data = offset;\n\t}\n\tif (opt_verbose) {\n\t\tprint_node('f', i, path);\n\t}\n\tif (opt_extract) {\n\t\tfd = open(path, O_WRONLY | O_CREAT | O_TRUNC, i->mode);\n\t\tif (fd < 0) {\n\t\t\tdie(FSCK_ERROR, 1, \"open failed: %s\", path);\n\t\t}\n\t}\n\tif (i->size) {\n\t\tdo_uncompress(path, fd, offset, i->size);\n\t}\n\tif (opt_extract) {\n\t\tclose(fd);\n\t\tchange_file_status(path, i);\n\t}\n}\n\nstatic void do_symlink(char *path, struct cramfs_inode *i)\n{\n\tunsigned long offset = i->offset << 2;\n\tunsigned long curr = offset + 4;\n\tunsigned long next = *(u32 *) romfs_read(offset);\n\tunsigned long size;\n\n\tif (offset == 0) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"symbolic link has zero offset\");\n\t}\n\tif (i->size == 0) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"symbolic link has zero size\");\n\t}\n\n\tif (offset < start_data) {\n\t\tstart_data = offset;\n\t}\n\tif (next > end_data) {\n\t\tend_data = next;\n\t}\n\n\tsize = uncompress_block(romfs_read(curr), next - curr);\n\tif (size != i->size) {\n\t\tdie(FSCK_UNCORRECTED, 0, \"size error in symlink: %s\", path);\n\t}\n\toutbuffer[size] = 0;\n\tif (opt_verbose) {\n\t\tchar *str;\n\n\t\tasprintf(&str, \"%s -> %s\", path, outbuffer);\n\t\tprint_node('l', i, str);\n\t\tif (opt_verbose > 1) {\n\t\t\tprintf(\"  uncompressing block at %ld to %ld (%ld)\\n\", curr, next, next - curr);\n\t\t}\n\t\tfree(str);\n\t}\n\tif (opt_extract) {\n\t\tif (symlink(outbuffer, path) < 0) {\n\t\t\tdie(FSCK_ERROR, 1, \"symlink failed: %s\", path);\n\t\t}\n\t\tchange_file_status(path, i);\n\t}\n}\n\nstatic void do_special_inode(char *path, struct cramfs_inode *i)\n{\n\tdev_t devtype = 0;\n\tchar type;\n\n\tif (i->offset) {\t/* no need to shift offset */\n\t\tdie(FSCK_UNCORRECTED, 0, \"special file has non-zero offset: %s\", path);\n\t}\n\tif (S_ISCHR(i->mode)) {\n\t\tdevtype = i->size;\n\t\ttype = 'c';\n\t}\n\telse if (S_ISBLK(i->mode)) {\n\t\tdevtype = i->size;\n\t\ttype = 'b';\n\t}\n\telse if (S_ISFIFO(i->mode)) {\n\t\tif (i->size != 0) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"fifo has non-zero size: %s\", path);\n\t\t}\n\t\ttype = 'p';\n\t}\n\telse if (S_ISSOCK(i->mode)) {\n\t\tif (i->size != 0) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"socket has non-zero size: %s\", path);\n\t\t}\n\t\ttype = 's';\n\t}\n\telse {\n\t\tdie(FSCK_UNCORRECTED, 0, \"bogus mode: %s (%o)\", path, i->mode);\n\t\treturn;\t\t/* not reached */\n\t}\n\n\tif (opt_verbose) {\n\t\tprint_node(type, i, path);\n\t}\n\n\tif (opt_extract) {\n\t\tif (mknod(path, i->mode, devtype) < 0) {\n\t\t\tdie(FSCK_ERROR, 1, \"mknod failed: %s\", path);\n\t\t}\n\t\tchange_file_status(path, i);\n\t}\n}\n\nstatic void expand_fs(char *path, struct cramfs_inode *inode)\n{\n\tif (S_ISDIR(inode->mode)) {\n\t\tdo_directory(path, inode);\n\t}\n\telse if (S_ISREG(inode->mode)) {\n\t\tdo_file(path, inode);\n\t}\n\telse if (S_ISLNK(inode->mode)) {\n\t\tdo_symlink(path, inode);\n\t}\n\telse {\n\t\tdo_special_inode(path, inode);\n\t}\n}\n\nstatic void test_fs(int start)\n{\n\tstruct cramfs_inode *root;\n\n\troot = read_super();\n\tumask(0);\n\teuid = geteuid();\n\tstream.next_in = NULL;\n\tstream.avail_in = 0;\n\tinflateInit(&stream);\n\texpand_fs(extract_dir, root);\n\tinflateEnd(&stream);\n\tif (start_data != ~0UL) {\n\t\tif (start_data < (sizeof(struct cramfs_super) + start)) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"directory data start (%ld) < sizeof(struct cramfs_super) + start (%ld)\", start_data, sizeof(struct cramfs_super) + start);\n\t\t}\n\t\tif (end_dir != start_data) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"directory data end (%ld) != file data start (%ld)\", end_dir, start_data);\n\t\t}\n\t}\n\tif (super.flags & CRAMFS_FLAG_FSID_VERSION_2) {\n\t\tif (end_data > super.size) {\n\t\t\tdie(FSCK_UNCORRECTED, 0, \"invalid file data offset\");\n\t\t}\n\t}\n\tiput(root);\t\t/* free(root) */\n}\n#endif /* INCLUDE_FS_TESTS */\n\nint main(int argc, char **argv)\n{\n\tint c;\t\t\t/* for getopt */\n\tint start = 0;\n\tsize_t length;\n\n\tif (argc)\n\t\tprogname = argv[0];\n\n\t/* command line options */\n\twhile ((c = getopt(argc, argv, \"hx:v\")) != EOF) {\n\t\tswitch (c) {\n\t\tcase 'h':\n\t\t\tusage(FSCK_OK);\n\t\tcase 'x':\n#ifdef INCLUDE_FS_TESTS\n\t\t\topt_extract = 1;\n\t\t\textract_dir = optarg;\n\t\t\tbreak;\n#else /* not INCLUDE_FS_TESTS */\n\t\t\tdie(FSCK_USAGE, 0, \"compiled without -x support\");\n#endif /* not INCLUDE_FS_TESTS */\n\t\tcase 'v':\n\t\t\topt_verbose++;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif ((argc - optind) != 1)\n\t\tusage(FSCK_USAGE);\n\tfilename = argv[optind];\n\n\ttest_super(&start, &length);\n\ttest_crc(start);\n#ifdef INCLUDE_FS_TESTS\n\ttest_fs(start);\n#endif /* INCLUDE_FS_TESTS */\n\n\tif (opt_verbose) {\n\t\tprintf(\"%s: OK\\n\", filename);\n\t}\n\n\texit(FSCK_OK);\n}\n\n/*\n * Local variables:\n * c-file-style: \"linux\"\n * End:\n */\n"
  },
  {
    "path": "src/cramfs-2.x/linux/cramfs_fs.h",
    "content": "#ifndef __CRAMFS_H\n#define __CRAMFS_H\n\n#ifndef __KERNEL__\n\ntypedef unsigned char u8;\ntypedef unsigned short u16;\ntypedef unsigned int u32;\n\n#endif\n\n#define CRAMFS_MAGIC\t\t0x28cd3d45\t/* some random number */\n#define CRAMFS_SIGNATURE\t\"Compressed ROMFS\"\n\n/*\n * Width of various bitfields in struct cramfs_inode.\n * Primarily used to generate warnings in mkcramfs.\n */\n#define CRAMFS_MODE_WIDTH 16\n#define CRAMFS_UID_WIDTH 16\n#define CRAMFS_SIZE_WIDTH 24\n#define CRAMFS_GID_WIDTH 8\n#define CRAMFS_NAMELEN_WIDTH 6\n#define CRAMFS_OFFSET_WIDTH 26\n\n/*\n * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs\n * path length is 63 << 2 = 252.\n */\n#define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)\n\n/*\n * Reasonably terse representation of the inode data.\n */\nstruct cramfs_inode {\n\tu32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH;\n\t/* SIZE for device files is i_rdev */\n\tu32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH;\n\t/* NAMELEN is the length of the file name, divided by 4 and\n           rounded up.  (cramfs doesn't support hard links.) */\n\t/* OFFSET: For symlinks and non-empty regular files, this\n\t   contains the offset (divided by 4) of the file data in\n\t   compressed form (starting with an array of block pointers;\n\t   see README).  For non-empty directories it is the offset\n\t   (divided by 4) of the inode of the first file in that\n\t   directory.  For anything else, offset is zero. */\n\tu32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH;\n};\n\nstruct cramfs_info {\n\tu32 crc;\n\tu32 edition;\n\tu32 blocks;\n\tu32 files;\n};\n\n/*\n * Superblock information at the beginning of the FS.\n */\nstruct cramfs_super {\n\tu32 magic;\t\t\t/* 0x28cd3d45 - random number */\n\tu32 size;\t\t\t/* length in bytes */\n\tu32 flags;\t\t\t/* feature flags */\n\tu32 future;\t\t\t/* reserved for future use */\n\tu8 signature[16];\t\t/* \"Compressed ROMFS\" */\n\tstruct cramfs_info fsid;\t/* unique filesystem info */\n\tu8 name[16];\t\t\t/* user-defined name */\n\tstruct cramfs_inode root;\t/* root inode data */\n};\n\n/*\n * Feature flags\n *\n * 0x00000000 - 0x000000ff: features that work for all past kernels\n * 0x00000100 - 0xffffffff: features that don't work for past kernels\n */\n#define CRAMFS_FLAG_FSID_VERSION_2\t0x00000001\t/* fsid version #2 */\n#define CRAMFS_FLAG_SORTED_DIRS\t\t0x00000002\t/* sorted dirs */\n#define CRAMFS_FLAG_HOLES\t\t0x00000100\t/* support for holes */\n#define CRAMFS_FLAG_WRONG_SIGNATURE\t0x00000200\t/* reserved */\n#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET\t0x00000400\t/* shifted root fs */\n\n/*\n * Valid values in super.flags.  Currently we refuse to mount\n * if (flags & ~CRAMFS_SUPPORTED_FLAGS).  Maybe that should be\n * changed to test super.future instead.\n */\n#define CRAMFS_SUPPORTED_FLAGS\t( 0x000000ff \\\n\t\t\t\t| CRAMFS_FLAG_HOLES \\\n\t\t\t\t| CRAMFS_FLAG_WRONG_SIGNATURE \\\n\t\t\t\t| CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )\n\n/* Uncompression interfaces to the underlying zlib */\nint cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);\nint cramfs_uncompress_init(void);\nint cramfs_uncompress_exit(void);\n\n#endif\n"
  },
  {
    "path": "src/cramfs-2.x/linux/cramfs_fs_sb.h",
    "content": "#ifndef _CRAMFS_FS_SB\n#define _CRAMFS_FS_SB\n\n/*\n * cramfs super-block data in memory\n */\nstruct cramfs_sb_info {\n\t\t\tunsigned long magic;\n\t\t\tunsigned long size;\n\t\t\tunsigned long blocks;\n\t\t\tunsigned long files;\n\t\t\tunsigned long flags;\n};\n\n#endif\n"
  },
  {
    "path": "src/cramfs-2.x/mkcramfs.c",
    "content": "/*\n * mkcramfs - make a cramfs file system\n *\n * Copyright (C) 1999-2002 Transmeta Corporation\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n */\n\n/*\n * If you change the disk format of cramfs, please update fs/cramfs/README.\n */\n\n#include <sys/types.h>\n#include <stdio.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <sys/mman.h>\n#include <fcntl.h>\n#include <dirent.h>\n#include <stdlib.h>\n#include <errno.h>\n#include <string.h>\n#include <stdarg.h>\n#include <linux/cramfs_fs.h>\n#include <zlib.h>\n\n/* Exit codes used by mkfs-type programs */\n#define MKFS_OK          0\t/* No errors */\n#define MKFS_ERROR       8\t/* Operational error */\n#define MKFS_USAGE       16\t/* Usage or syntax error */\n\n/* The kernel only supports PAD_SIZE of 0 and 512. */\n#define PAD_SIZE 512\n\n/* The kernel assumes PAGE_CACHE_SIZE as block size. */\n#define PAGE_CACHE_SIZE (4096)\n\n/*\n * The longest filename component to allow for in the input directory tree.\n * ext2fs (and many others) allow up to 255 bytes.  A couple of filesystems\n * allow longer (e.g. smbfs 1024), but there isn't much use in supporting\n * >255-byte names in the input directory tree given that such names get\n * truncated to CRAMFS_MAXPATHLEN (252 bytes) when written to cramfs.\n *\n * Old versions of mkcramfs generated corrupted filesystems if any input\n * filenames exceeded CRAMFS_MAXPATHLEN (252 bytes), however old\n * versions of cramfsck seem to have been able to detect the corruption.\n */\n#define MAX_INPUT_NAMELEN 255\n\n/*\n * Maximum size fs you can create is roughly 256MB.  (The last file's\n * data must begin within 256MB boundary but can extend beyond that.)\n *\n * Note that if you want it to fit in a ROM then you're limited to what the\n * hardware and kernel can support.\n */\n#define MAXFSLEN ((((1 << CRAMFS_OFFSET_WIDTH) - 1) << 2) /* offset */ \\\n\t\t  + (1 << CRAMFS_SIZE_WIDTH) - 1 /* filesize */ \\\n\t\t  + (1 << CRAMFS_SIZE_WIDTH) * 4 / PAGE_CACHE_SIZE /* block pointers */ )\n\nstatic const char *progname = \"mkcramfs\";\nstatic unsigned int blksize = PAGE_CACHE_SIZE;\nstatic long total_blocks = 0, total_nodes = 1; /* pre-count the root node */\nstatic int image_length = 0;\n\n/*\n * If opt_holes is set, then mkcramfs can create explicit holes in the\n * data, which saves 26 bytes per hole (which is a lot smaller a\n * saving than most most filesystems).\n *\n * Note that kernels up to at least 2.3.39 don't support cramfs holes,\n * which is why this is turned off by default.\n *\n * If opt_verbose is 1, be verbose.  If it is higher, be even more verbose.\n */\nstatic u32 opt_edition = 0;\nstatic int opt_errors = 0;\nstatic int opt_holes = 0;\nstatic int opt_pad = 0;\nstatic int opt_verbose = 0;\nstatic char *opt_image = NULL;\nstatic char *opt_name = NULL;\n\nstatic int warn_dev, warn_gid, warn_namelen, warn_skip, warn_size, warn_uid;\n\n/* In-core version of inode / directory entry. */\nstruct entry {\n\t/* stats */\n\tunsigned char *name;\n\tunsigned int mode, size, uid, gid;\n\n\t/* these are only used for non-empty files */\n\tchar *path;\t\t/* always null except non-empty files */\n\tint fd;\t\t\t/* temporarily open files while mmapped */\n\n\t/* FS data */\n\tvoid *uncompressed;\n\t/* points to other identical file */\n\tstruct entry *same;\n\tunsigned int offset;\t\t/* pointer to compressed data in archive */\n\tunsigned int dir_offset;\t/* Where in the archive is the directory entry? */\n\n\t/* organization */\n\tstruct entry *child; /* null for non-directories and empty directories */\n\tstruct entry *next;\n};\n\n/* Input status of 0 to print help and exit without an error. */\nstatic void usage(int status)\n{\n\tFILE *stream = status ? stderr : stdout;\n\n\tfprintf(stream, \"usage: %s [-h] [-e edition] [-i file] [-n name] dirname outfile\\n\"\n\t\t\" -h         print this help\\n\"\n\t\t\" -E         make all warnings errors (non-zero exit status)\\n\"\n\t\t\" -e edition set edition number (part of fsid)\\n\"\n\t\t\" -i file    insert a file image into the filesystem (requires >= 2.4.0)\\n\"\n\t\t\" -n name    set name of cramfs filesystem\\n\"\n\t\t\" -p         pad by %d bytes for boot code\\n\"\n\t\t\" -s         sort directory entries (old option, ignored)\\n\"\n\t\t\" -v         be more verbose\\n\"\n\t\t\" -z         make explicit holes (requires >= 2.3.39)\\n\"\n\t\t\" dirname    root of the directory tree to be compressed\\n\"\n\t\t\" outfile    output file\\n\", progname, PAD_SIZE);\n\n\texit(status);\n}\n\nstatic void die(int status, int syserr, const char *fmt, ...)\n{\n\tva_list arg_ptr;\n\tint save = errno;\n\n\tfflush(0);\n\tva_start(arg_ptr, fmt);\n\tfprintf(stderr, \"%s: \", progname);\n\tvfprintf(stderr, fmt, arg_ptr);\n\tif (syserr) {\n\t\tfprintf(stderr, \": %s\", strerror(save));\n\t}\n\tfprintf(stderr, \"\\n\");\n\tva_end(arg_ptr);\n\texit(status);\n}\n\nstatic void map_entry(struct entry *entry)\n{\n\tif (entry->path) {\n\t\tentry->fd = open(entry->path, O_RDONLY);\n\t\tif (entry->fd < 0) {\n\t\t\tdie(MKFS_ERROR, 1, \"open failed: %s\", entry->path);\n\t\t}\n\t\tentry->uncompressed = mmap(NULL, entry->size, PROT_READ, MAP_PRIVATE, entry->fd, 0);\n\t\tif (entry->uncompressed == MAP_FAILED) {\n\t\t\tdie(MKFS_ERROR, 1, \"mmap failed: %s\", entry->path);\n\t\t}\n\t}\n}\n\nstatic void unmap_entry(struct entry *entry)\n{\n\tif (entry->path) {\n\t\tif (munmap(entry->uncompressed, entry->size) < 0) {\n\t\t\tdie(MKFS_ERROR, 1, \"munmap failed: %s\", entry->path);\n\t\t}\n\t\tclose(entry->fd);\n\t}\n}\n\nstatic int find_identical_file(struct entry *orig, struct entry *newfile)\n{\n\tif (orig == newfile)\n\t\treturn 1;\n\tif (!orig)\n\t\treturn 0;\n\tif (orig->size == newfile->size && (orig->path || orig->uncompressed))\n\t{\n\t\tmap_entry(orig);\n\t\tmap_entry(newfile);\n\t\tif (!memcmp(orig->uncompressed, newfile->uncompressed, orig->size))\n\t\t{\n\t\t\tnewfile->same = orig;\n\t\t\tunmap_entry(newfile);\n\t\t\tunmap_entry(orig);\n\t\t\treturn 1;\n\t\t}\n\t\tunmap_entry(newfile);\n\t\tunmap_entry(orig);\n\t}\n\treturn (find_identical_file(orig->child, newfile) ||\n\t\tfind_identical_file(orig->next, newfile));\n}\n\nstatic void eliminate_doubles(struct entry *root, struct entry *orig) {\n\tif (orig) {\n\t\tif (orig->size && (orig->path || orig->uncompressed))\n\t\t\tfind_identical_file(root, orig);\n\t\teliminate_doubles(root, orig->child);\n\t\teliminate_doubles(root, orig->next);\n\t}\n}\n\n/*\n * We define our own sorting function instead of using alphasort which\n * uses strcoll and changes ordering based on locale information.\n */\nstatic int cramsort (const void *a, const void *b)\n{\n\treturn strcmp ((*(const struct dirent **) a)->d_name,\n\t\t       (*(const struct dirent **) b)->d_name);\n}\n\nstatic unsigned int parse_directory(struct entry *root_entry, const char *name, struct entry **prev, loff_t *fslen_ub)\n{\n\tstruct dirent **dirlist;\n\tint totalsize = 0, dircount, dirindex;\n\tchar *path, *endpath;\n\tsize_t len = strlen(name);\n\n\t/* Set up the path. */\n\t/* TODO: Reuse the parent's buffer to save memcpy'ing and duplication. */\n\tpath = malloc(len + 1 + MAX_INPUT_NAMELEN + 1);\n\tif (!path) {\n\t\tdie(MKFS_ERROR, 1, \"malloc failed\");\n\t}\n\tmemcpy(path, name, len);\n\tendpath = path + len;\n\t*endpath = '/';\n\tendpath++;\n\n\t/* read in the directory and sort */\n\tdircount = scandir(name, &dirlist, 0, cramsort);\n\n\tif (dircount < 0) {\n\t\tdie(MKFS_ERROR, 1, \"scandir failed: %s\", name);\n\t}\n\n\t/* process directory */\n\tfor (dirindex = 0; dirindex < dircount; dirindex++) {\n\t\tstruct dirent *dirent;\n\t\tstruct entry *entry;\n\t\tstruct stat st;\n\t\tint size;\n\t\tsize_t namelen;\n\n\t\tdirent = dirlist[dirindex];\n\n\t\t/* Ignore \".\" and \"..\" - we won't be adding them to the archive */\n\t\tif (dirent->d_name[0] == '.') {\n\t\t\tif (dirent->d_name[1] == '\\0')\n\t\t\t\tcontinue;\n\t\t\tif (dirent->d_name[1] == '.') {\n\t\t\t\tif (dirent->d_name[2] == '\\0')\n\t\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tnamelen = strlen(dirent->d_name);\n\t\tif (namelen > MAX_INPUT_NAMELEN) {\n\t\t\tdie(MKFS_ERROR, 0,\n\t\t\t\t\"very long (%u bytes) filename found: %s\\n\"\n\t\t\t\t\"please increase MAX_INPUT_NAMELEN in mkcramfs.c and recompile\",\n\t\t\t\tnamelen, dirent->d_name);\n\t\t}\n\t\tmemcpy(endpath, dirent->d_name, namelen + 1);\n\n\t\tif (lstat(path, &st) < 0) {\n\t\t\twarn_skip = 1;\n\t\t\tcontinue;\n\t\t}\n\t\tentry = calloc(1, sizeof(struct entry));\n\t\tif (!entry) {\n\t\t\tdie(MKFS_ERROR, 1, \"calloc failed\");\n\t\t}\n\t\tentry->name = strdup(dirent->d_name);\n\t\tif (!entry->name) {\n\t\t\tdie(MKFS_ERROR, 1, \"strdup failed\");\n\t\t}\n\t\t/* truncate multi-byte UTF-8 filenames on character boundary */\n\t\tif (namelen > CRAMFS_MAXPATHLEN) {\n\t\t\tnamelen = CRAMFS_MAXPATHLEN;\n\t\t\twarn_namelen = 1;\n\t\t\t/* the first lost byte must not be a trail byte */\n\t\t\twhile ((entry->name[namelen] & 0xc0) == 0x80) {\n\t\t\t\tnamelen--;\n\t\t\t\t/* are we reasonably certain it was UTF-8 ? */\n\t\t\t\tif (entry->name[namelen] < 0x80 || !namelen) {\n\t\t\t\t\tdie(MKFS_ERROR, 0, \"cannot truncate filenames not encoded in UTF-8\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tentry->name[namelen] = '\\0';\n\t\t}\n\t\tentry->mode = st.st_mode;\n\t\tentry->size = st.st_size;\n\t\tentry->uid = st.st_uid;\n\t\tif (entry->uid >= 1 << CRAMFS_UID_WIDTH)\n\t\t\twarn_uid = 1;\n\t\tentry->gid = st.st_gid;\n\t\tif (entry->gid >= 1 << CRAMFS_GID_WIDTH)\n\t\t\t/* TODO: We ought to replace with a default\n\t\t\t   gid instead of truncating; otherwise there\n\t\t\t   are security problems.  Maybe mode should\n\t\t\t   be &= ~070.  Same goes for uid once Linux\n\t\t\t   supports >16-bit uids. */\n\t\t\twarn_gid = 1;\n\t\tsize = sizeof(struct cramfs_inode) + ((namelen + 3) & ~3);\n\t\t*fslen_ub += size;\n\t\tif (S_ISDIR(st.st_mode)) {\n\t\t\tentry->size = parse_directory(root_entry, path, &entry->child, fslen_ub);\n\t\t} else if (S_ISREG(st.st_mode)) {\n\t\t\tif (entry->size) {\n\t\t\t\tif (access(path, R_OK) < 0) {\n\t\t\t\t\twarn_skip = 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tentry->path = strdup(path);\n\t\t\t\tif (!entry->path) {\n\t\t\t\t\tdie(MKFS_ERROR, 1, \"strdup failed\");\n\t\t\t\t}\n\t\t\t\tif ((entry->size >= 1 << CRAMFS_SIZE_WIDTH)) {\n\t\t\t\t\twarn_size = 1;\n\t\t\t\t\tentry->size = (1 << CRAMFS_SIZE_WIDTH) - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (S_ISLNK(st.st_mode)) {\n\t\t\tentry->uncompressed = malloc(entry->size);\n\t\t\tif (!entry->uncompressed) {\n\t\t\t\tdie(MKFS_ERROR, 1, \"malloc failed\");\n\t\t\t}\n\t\t\tif (readlink(path, entry->uncompressed, entry->size) < 0) {\n\t\t\t\twarn_skip = 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t} else if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {\n\t\t\t/* maybe we should skip sockets */\n\t\t\tentry->size = 0;\n\t\t} else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {\n\t\t\tentry->size = st.st_rdev;\n\t\t\tif (entry->size & -(1<<CRAMFS_SIZE_WIDTH))\n\t\t\t\twarn_dev = 1;\n\t\t} else {\n\t\t\tdie(MKFS_ERROR, 0, \"bogus file type: %s\", entry->name);\n\t\t}\n\n\t\tif (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {\n\t\t\tint blocks = ((entry->size - 1) / blksize + 1);\n\n\t\t\t/* block pointers & data expansion allowance + data */\n\t\t\tif (entry->size)\n\t\t\t\t*fslen_ub += (4+26)*blocks + entry->size + 3;\n\t\t}\n\n\t\t/* Link it into the list */\n\t\t*prev = entry;\n\t\tprev = &entry->next;\n\t\ttotalsize += size;\n\t}\n\tfree(path);\n\tfree(dirlist);\t\t/* allocated by scandir() with malloc() */\n\treturn totalsize;\n}\n\n/* Returns sizeof(struct cramfs_super), which includes the root inode. */\nstatic unsigned int write_superblock(struct entry *root, char *base, int size)\n{\n\tstruct cramfs_super *super = (struct cramfs_super *) base;\n\tunsigned int offset = sizeof(struct cramfs_super) + image_length;\n\n\toffset += opt_pad;\t/* 0 if no padding */\n\n\tsuper->magic = CRAMFS_MAGIC;\n\tsuper->flags = CRAMFS_FLAG_FSID_VERSION_2 | CRAMFS_FLAG_SORTED_DIRS;\n\tif (opt_holes)\n\t\tsuper->flags |= CRAMFS_FLAG_HOLES;\n\tif (image_length > 0)\n\t\tsuper->flags |= CRAMFS_FLAG_SHIFTED_ROOT_OFFSET;\n\tsuper->size = size;\n\tmemcpy(super->signature, CRAMFS_SIGNATURE, sizeof(super->signature));\n\n\tsuper->fsid.crc = crc32(0L, Z_NULL, 0);\n\tsuper->fsid.edition = opt_edition;\n\tsuper->fsid.blocks = total_blocks;\n\tsuper->fsid.files = total_nodes;\n\n\tmemset(super->name, 0x00, sizeof(super->name));\n\tif (opt_name)\n\t\tstrncpy(super->name, opt_name, sizeof(super->name));\n\telse\n\t\tstrncpy(super->name, \"Compressed\", sizeof(super->name));\n\n\tsuper->root.mode = root->mode;\n\tsuper->root.uid = root->uid;\n\tsuper->root.gid = root->gid;\n\tsuper->root.size = root->size;\n\tsuper->root.offset = offset >> 2;\n\n\treturn offset;\n}\n\nstatic void set_data_offset(struct entry *entry, char *base, unsigned long offset)\n{\n\tstruct cramfs_inode *inode = (struct cramfs_inode *) (base + entry->dir_offset);\n\n\tif ((offset & 3) != 0) {\n\t\tdie(MKFS_ERROR, 0, \"illegal offset of %lu bytes\", offset);\n\t}\n\tif (offset >= (1 << (2 + CRAMFS_OFFSET_WIDTH))) {\n\t\tdie(MKFS_ERROR, 0, \"filesystem too big\");\n\t}\n\tinode->offset = (offset >> 2);\n}\n\n/*\n * TODO: Does this work for chars >= 0x80?  Most filesystems use UTF-8\n * encoding for filenames, whereas the console is a single-byte\n * character set like iso-latin-1.\n */\nstatic void print_node(struct entry *e)\n{\n\tchar info[10];\n\tchar type = '?';\n\n\tif (S_ISREG(e->mode)) type = 'f';\n\telse if (S_ISDIR(e->mode)) type = 'd';\n\telse if (S_ISLNK(e->mode)) type = 'l';\n\telse if (S_ISCHR(e->mode)) type = 'c';\n\telse if (S_ISBLK(e->mode)) type = 'b';\n\telse if (S_ISFIFO(e->mode)) type = 'p';\n\telse if (S_ISSOCK(e->mode)) type = 's';\n\n\tif (S_ISCHR(e->mode) || (S_ISBLK(e->mode))) {\n\t\t/* major/minor numbers can be as high as 2^12 or 4096 */\n\t\tsnprintf(info, 10, \"%4d,%4d\", major(e->size), minor(e->size));\n\t}\n\telse {\n\t\t/* size be as high as 2^24 or 16777216 */\n\t\tsnprintf(info, 10, \"%9d\", e->size);\n\t}\n\n\tprintf(\"%c %04o %s %5d:%-3d %s\\n\",\n\t       type, e->mode & ~S_IFMT, info, e->uid, e->gid, e->name);\n}\n\n/*\n * We do a width-first printout of the directory\n * entries, using a stack to remember the directories\n * we've seen.\n */\nstatic unsigned int write_directory_structure(struct entry *entry, char *base, unsigned int offset)\n{\n\tint stack_entries = 0;\n\tint stack_size = 64;\n\tstruct entry **entry_stack;\n\n\tentry_stack = malloc(stack_size * sizeof(struct entry *));\n\tif (!entry_stack) {\n\t\tdie(MKFS_ERROR, 1, \"malloc failed\");\n\t}\n\n\tif (opt_verbose) {\n\t\tprintf(\"root:\\n\");\n\t}\n\n\tfor (;;) {\n\t\tint dir_start = stack_entries;\n\t\twhile (entry) {\n\t\t\tstruct cramfs_inode *inode = (struct cramfs_inode *) (base + offset);\n\t\t\tsize_t len = strlen(entry->name);\n\n\t\t\tentry->dir_offset = offset;\n\n\t\t\tinode->mode = entry->mode;\n\t\t\tinode->uid = entry->uid;\n\t\t\tinode->gid = entry->gid;\n\t\t\tinode->size = entry->size;\n\t\t\tinode->offset = 0;\n\t\t\t/* Non-empty directories, regfiles and symlinks will\n\t\t\t   write over inode->offset later. */\n\n\t\t\toffset += sizeof(struct cramfs_inode);\n\t\t\ttotal_nodes++;\t/* another node */\n\t\t\tmemcpy(base + offset, entry->name, len);\n\t\t\t/* Pad up the name to a 4-byte boundary */\n\t\t\twhile (len & 3) {\n\t\t\t\t*(base + offset + len) = '\\0';\n\t\t\t\tlen++;\n\t\t\t}\n\t\t\tinode->namelen = len >> 2;\n\t\t\toffset += len;\n\n\t\t\tif (opt_verbose)\n\t\t\t\tprint_node(entry);\n\n\t\t\tif (entry->child) {\n\t\t\t\tif (stack_entries >= stack_size) {\n\t\t\t\t\tstack_size *= 2;\n\t\t\t\t\tentry_stack = realloc(entry_stack, stack_size * sizeof(struct entry *));\n\t\t\t\t\tif (!entry_stack) {\n\t\t\t\t\t\tdie(MKFS_ERROR, 1, \"realloc failed\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tentry_stack[stack_entries] = entry;\n\t\t\t\tstack_entries++;\n\t\t\t}\n\t\t\tentry = entry->next;\n\t\t}\n\n\t\t/*\n\t\t * Reverse the order the stack entries pushed during\n\t\t * this directory, for a small optimization of disk\n\t\t * access in the created fs.  This change makes things\n\t\t * `ls -UR' order.\n\t\t */\n\t\t{\n\t\t\tstruct entry **lo = entry_stack + dir_start;\n\t\t\tstruct entry **hi = entry_stack + stack_entries;\n\t\t\tstruct entry *tmp;\n\n\t\t\twhile (lo < --hi) {\n\t\t\t\ttmp = *lo;\n\t\t\t\t*lo++ = *hi;\n\t\t\t\t*hi = tmp;\n\t\t\t}\n\t\t}\n\n\t\t/* Pop a subdirectory entry from the stack, and recurse. */\n\t\tif (!stack_entries)\n\t\t\tbreak;\n\t\tstack_entries--;\n\t\tentry = entry_stack[stack_entries];\n\n\t\tset_data_offset(entry, base, offset);\n\t\tif (opt_verbose) {\n\t\t\tprintf(\"%s:\\n\", entry->name);\n\t\t}\n\t\tentry = entry->child;\n\t}\n\tfree(entry_stack);\n\treturn offset;\n}\n\nstatic int is_zero(char const *begin, unsigned len)\n{\n\t/* Returns non-zero iff the first LEN bytes from BEGIN are all NULs. */\n\treturn (len-- == 0 ||\n\t\t(begin[0] == '\\0' &&\n\t\t (len-- == 0 ||\n\t\t  (begin[1] == '\\0' &&\n\t\t   (len-- == 0 ||\n\t\t    (begin[2] == '\\0' &&\n\t\t     (len-- == 0 ||\n\t\t      (begin[3] == '\\0' &&\n\t\t       memcmp(begin, begin + 4, len) == 0))))))));\n}\n\n/*\n * One 4-byte pointer per block and then the actual blocked\n * output. The first block does not need an offset pointer,\n * as it will start immediately after the pointer block;\n * so the i'th pointer points to the end of the i'th block\n * (i.e. the start of the (i+1)'th block or past EOF).\n *\n * Note that size > 0, as a zero-sized file wouldn't ever\n * have gotten here in the first place.\n */\nstatic unsigned int do_compress(char *base, unsigned int offset, char const *name, char *uncompressed, unsigned int size)\n{\n\tunsigned long original_size = size;\n\tunsigned long original_offset = offset;\n\tunsigned long new_size;\n\tunsigned long blocks = (size - 1) / blksize + 1;\n\tunsigned long curr = offset + 4 * blocks;\n\tint change;\n\n\ttotal_blocks += blocks;\n\n\tdo {\n\t\tunsigned long len = 2 * blksize;\n\t\tunsigned int input = size;\n\t\tint err;\n\n\t\tif (input > blksize)\n\t\t\tinput = blksize;\n\t\tsize -= input;\n\t\tif (!(opt_holes && is_zero (uncompressed, input))) {\n\t\t\terr = compress2(base + curr, &len, uncompressed, input, Z_BEST_COMPRESSION);\n\t\t\tif (err != Z_OK) {\n\t\t\t\tdie(MKFS_ERROR, 0, \"compression error: %s\", zError(err));\n\t\t\t}\n\t\t\tcurr += len;\n\t\t}\n\t\tuncompressed += input;\n\n\t\tif (len > blksize*2) {\n\t\t\t/* (I don't think this can happen with zlib.) */\n\t\t\tdie(MKFS_ERROR, 0, \"AIEEE: block \\\"compressed\\\" to > 2*blocklength (%ld)\", len);\n\t\t}\n\n\t\t*(u32 *) (base + offset) = curr;\n\t\toffset += 4;\n\t} while (size);\n\n\tcurr = (curr + 3) & ~3;\n\tnew_size = curr - original_offset;\n\t/* TODO: Arguably, original_size in these 2 lines should be\n\t   st_blocks * 512.  But if you say that then perhaps\n\t   administrative data should also be included in both. */\n\tchange = new_size - original_size;\n\tif (opt_verbose > 1) {\n\t\tprintf(\"%6.2f%% (%+d bytes)\\t%s\\n\",\n\t\t       (change * 100) / (double) original_size, change, name);\n\t}\n\n\treturn curr;\n}\n\n\n/*\n * Traverse the entry tree, writing data for every item that has\n * non-null entry->path (i.e. every non-empty regfile) and non-null\n * entry->uncompressed (i.e. every symlink).\n */\nstatic unsigned int write_data(struct entry *entry, char *base, unsigned int offset)\n{\n\tdo {\n\t\tif (entry->path || entry->uncompressed) {\n\t\t\tif (entry->same) {\n\t\t\t\tset_data_offset(entry, base, entry->same->offset);\n\t\t\t\tentry->offset = entry->same->offset;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tset_data_offset(entry, base, offset);\n\t\t\t\tentry->offset = offset;\n\t\t\t\tmap_entry(entry);\n\t\t\t\toffset = do_compress(base, offset, entry->name, entry->uncompressed, entry->size);\n\t\t\t\tunmap_entry(entry);\n\t\t\t}\n\t\t}\n\t\telse if (entry->child)\n\t\t\toffset = write_data(entry->child, base, offset);\n\t\tentry=entry->next;\n\t} while (entry);\n\treturn offset;\n}\n\nstatic unsigned int write_file(char *file, char *base, unsigned int offset)\n{\n\tint fd;\n\tchar *buf;\n\n\tfd = open(file, O_RDONLY);\n\tif (fd < 0) {\n\t\tdie(MKFS_ERROR, 1, \"open failed: %s\", file);\n\t}\n\tbuf = mmap(NULL, image_length, PROT_READ, MAP_PRIVATE, fd, 0);\n\tif (buf == MAP_FAILED) {\n\t\tdie(MKFS_ERROR, 1, \"mmap failed\");\n\t}\n\tmemcpy(base + offset, buf, image_length);\n\tmunmap(buf, image_length);\n\tclose (fd);\n\t/* Pad up the image_length to a 4-byte boundary */\n\twhile (image_length & 3) {\n\t\t*(base + offset + image_length) = '\\0';\n\t\timage_length++;\n\t}\n\treturn (offset + image_length);\n}\n\nint main(int argc, char **argv)\n{\n\tstruct stat st;\t\t/* used twice... */\n\tstruct entry *root_entry;\n\tchar *rom_image;\n\tssize_t offset, written;\n\tint fd;\n\t/* initial guess (upper-bound) of required filesystem size */\n\tloff_t fslen_ub = sizeof(struct cramfs_super);\n\tchar const *dirname, *outfile;\n\tu32 crc;\n\tint c;\t\t\t/* for getopt */\n\tchar *ep;\t\t/* for strtoul */\n\n\ttotal_blocks = 0;\n\n\tif (argc)\n\t\tprogname = argv[0];\n\n\t/* command line options */\n\twhile ((c = getopt(argc, argv, \"hEe:i:n:psvz\")) != EOF) {\n\t\tswitch (c) {\n\t\tcase 'h':\n\t\t\tusage(MKFS_OK);\n\t\tcase 'E':\n\t\t\topt_errors = 1;\n\t\t\tbreak;\n\t\tcase 'e':\n\t\t\terrno = 0;\n\t\t\topt_edition = strtoul(optarg, &ep, 10);\n\t\t\tif (errno || optarg[0] == '\\0' || *ep != '\\0')\n\t\t\t\tusage(MKFS_USAGE);\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\topt_image = optarg;\n\t\t\tif (lstat(opt_image, &st) < 0) {\n\t\t\t\tdie(MKFS_ERROR, 1, \"lstat failed: %s\", opt_image);\n\t\t\t}\n\t\t\timage_length = st.st_size; /* may be padded later */\n\t\t\tfslen_ub += (image_length + 3); /* 3 is for padding */\n\t\t\tbreak;\n\t\tcase 'n':\n\t\t\topt_name = optarg;\n\t\t\tbreak;\n\t\tcase 'p':\n\t\t\topt_pad = PAD_SIZE;\n\t\t\tfslen_ub += PAD_SIZE;\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\t/* old option, ignored */\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\topt_verbose++;\n\t\t\tbreak;\n\t\tcase 'z':\n\t\t\topt_holes = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif ((argc - optind) != 2)\n\t\tusage(MKFS_USAGE);\n\tdirname = argv[optind];\n\toutfile = argv[optind + 1];\n\n\tif (stat(dirname, &st) < 0) {\n\t\tdie(MKFS_USAGE, 1, \"stat failed: %s\", dirname);\n\t}\n\tfd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0666);\n\tif (fd < 0) {\n\t\tdie(MKFS_USAGE, 1, \"open failed: %s\", outfile);\n\t}\n\n\troot_entry = calloc(1, sizeof(struct entry));\n\tif (!root_entry) {\n\t\tdie(MKFS_ERROR, 1, \"calloc failed\");\n\t}\n\troot_entry->mode = st.st_mode;\n\troot_entry->uid = st.st_uid;\n\troot_entry->gid = st.st_gid;\n\n\troot_entry->size = parse_directory(root_entry, dirname, &root_entry->child, &fslen_ub);\n\n\t/* always allocate a multiple of blksize bytes because that's\n\t   what we're going to write later on */\n\tfslen_ub = ((fslen_ub - 1) | (blksize - 1)) + 1;\n\n\tif (fslen_ub > MAXFSLEN) {\n\t\tfprintf(stderr,\n\t\t\t\"warning: estimate of required size (upper bound) is %LdMB, but maximum image size is %uMB, we might die prematurely\\n\",\n\t\t\tfslen_ub >> 20,\n\t\t\tMAXFSLEN >> 20);\n\t\tfslen_ub = MAXFSLEN;\n\t}\n\n\t/* find duplicate files. TODO: uses the most inefficient algorithm\n\t   possible. */\n\teliminate_doubles(root_entry, root_entry);\n\n\t/* TODO: Why do we use a private/anonymous mapping here\n\t   followed by a write below, instead of just a shared mapping\n\t   and a couple of ftruncate calls?  Is it just to save us\n\t   having to deal with removing the file afterwards?  If we\n\t   really need this huge anonymous mapping, we ought to mmap\n\t   in smaller chunks, so that the user doesn't need nn MB of\n\t   RAM free.  If the reason is to be able to write to\n\t   un-mmappable block devices, then we could try shared mmap\n\t   and revert to anonymous mmap if the shared mmap fails. */\n\trom_image = mmap(NULL, fslen_ub?fslen_ub:1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n\n\tif (rom_image == MAP_FAILED) {\n\t\tdie(MKFS_ERROR, 1, \"mmap failed\");\n\t}\n\n\t/* Skip the first opt_pad bytes for boot loader code */\n\toffset = opt_pad;\n\tmemset(rom_image, 0x00, opt_pad);\n\n\t/* Skip the superblock and come back to write it later. */\n\toffset += sizeof(struct cramfs_super);\n\n\t/* Insert a file image. */\n\tif (opt_image) {\n\t\tprintf(\"Including: %s\\n\", opt_image);\n\t\toffset = write_file(opt_image, rom_image, offset);\n\t}\n\n\toffset = write_directory_structure(root_entry->child, rom_image, offset);\n\tprintf(\"Directory data: %d bytes\\n\", offset);\n\n\toffset = write_data(root_entry, rom_image, offset);\n\n\t/* We always write a multiple of blksize bytes, so that\n\t   losetup works. */\n\toffset = ((offset - 1) | (blksize - 1)) + 1;\n\tprintf(\"Everything: %d kilobytes\\n\", offset >> 10);\n\n\t/* Write the superblock now that we can fill in all of the fields. */\n\twrite_superblock(root_entry, rom_image+opt_pad, offset);\n\tprintf(\"Super block: %d bytes\\n\", sizeof(struct cramfs_super));\n\n\t/* Put the checksum in. */\n\tcrc = crc32(0L, Z_NULL, 0);\n\tcrc = crc32(crc, (rom_image+opt_pad), (offset-opt_pad));\n\t((struct cramfs_super *) (rom_image+opt_pad))->fsid.crc = crc;\n\tprintf(\"CRC: %x\\n\", crc);\n\n\t/* Check to make sure we allocated enough space. */\n\tif (fslen_ub < offset) {\n\t\tdie(MKFS_ERROR, 0, \"not enough space allocated for ROM image (%Ld allocated, %d used)\", fslen_ub, offset);\n\t}\n\n\twritten = write(fd, rom_image, offset);\n\tif (written < 0) {\n\t\tdie(MKFS_ERROR, 1, \"write failed\");\n\t}\n\tif (offset != written) {\n\t\tdie(MKFS_ERROR, 0, \"ROM image write failed (wrote %d of %d bytes)\", written, offset);\n\t}\n\n\t/* (These warnings used to come at the start, but they scroll off the\n\t   screen too quickly.) */\n\tif (warn_namelen)\n\t\tfprintf(stderr, /* bytes, not chars: think UTF-8. */\n\t\t\t\"warning: filenames truncated to %d bytes (possibly less if multi-byte UTF-8)\\n\",\n\t\t\tCRAMFS_MAXPATHLEN);\n\tif (warn_skip)\n\t\tfprintf(stderr, \"warning: files were skipped due to errors\\n\");\n\tif (warn_size)\n\t\tfprintf(stderr,\n\t\t\t\"warning: file sizes truncated to %luMB (minus 1 byte)\\n\",\n\t\t\t1L << (CRAMFS_SIZE_WIDTH - 20));\n\tif (warn_uid) /* (not possible with current Linux versions) */\n\t\tfprintf(stderr,\n\t\t\t\"warning: uids truncated to %u bits (this may be a security concern)\\n\",\n\t\t\tCRAMFS_UID_WIDTH);\n\tif (warn_gid)\n\t\tfprintf(stderr,\n\t\t\t\"warning: gids truncated to %u bits (this may be a security concern)\\n\",\n\t\t\tCRAMFS_GID_WIDTH);\n\tif (warn_dev)\n\t\tfprintf(stderr,\n\t\t\t\"WARNING: device numbers truncated to %u bits (this almost certainly means\\n\"\n\t\t\t\"that some device files will be wrong)\\n\",\n\t\t\tCRAMFS_OFFSET_WIDTH);\n\tif (opt_errors &&\n\t    (warn_namelen||warn_skip||warn_size||warn_uid||warn_gid||warn_dev))\n\t\texit(MKFS_ERROR);\n\n\texit(MKFS_OK);\n}\n\n/*\n * Local variables:\n * c-file-style: \"linux\"\n * End:\n */\n"
  },
  {
    "path": "src/cramfsswap/COPYING",
    "content": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n\t\t    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n\t    How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) year  name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "src/cramfsswap/Makefile",
    "content": "#!/usr/bin/make -f\n\nall: cramfsswap strip\ndebian: cramfsswap\n\ncramfsswap: cramfsswap.c\n\tgcc -Wall -g -O -o cramfsswap cramfsswap.c -lz\n\nstrip:\n\tstrip cramfsswap\n\ninstall: cramfsswap\n\tinstall cramfsswap $(DESTDIR)/usr/bin\n\t\nclean:\t\n\trm -f cramfsswap\n"
  },
  {
    "path": "src/cramfsswap/README",
    "content": "\n  cramfsswap - swap endianess of a cram filesystem (cramfs)\n  version 1.1\n\n\n  cramfs is a highly compressed and size optimized linux filesystem which is\n  mainly used for embedded applications. the problem with cramfs is that it\n  is endianess sensitive, meaning you can't mount a cramfs for a big endian\n  target on a little endian machine and vice versa. this is often especially \n  a problem in the development phase.\n\n  cramfsswap solves that problem by allowing you to swap to endianess of a\n  cramfs filesystem.\n\n\n  changelog:\n\n  v1.0  2004-12-01  first release\n  v1.1  2005-01-04  added correct recalculation of crc, thanks to joerg\n                    dorchain <joerg at dorchain.net>\n"
  },
  {
    "path": "src/cramfsswap/cramfsswap.1",
    "content": ".TH cramfsswap 1 \"4 Jan 2005\" Linux \"User Manuals\"\n.SH NAME\ncramfsswap \\- swap endianess of a cram filesystem (cramfs)\n.SH SYNOPSIS\n.B cramfsswap <infile> <outfile>\n.SH DESCRIPTION\ncramfs is a highly compressed and size optimized linux filesystem which is\nmainly used for embedded applications. the problem with cramfs is that it\nis endianess sensitive, meaning you can't mount a cramfs for a big endian\ntarget on a little endian machine and vice versa. this is often especially \na problem in the development phase.\n\ncramfsswap solves that problem by allowing you to swap to endianess of a\ncramfs filesystem.\n.SH AUTHOR\nMichael Holzt <kju@debian.org>\n.SH VERSION\n20050104\n"
  },
  {
    "path": "src/cramfsswap/cramfsswap.c",
    "content": "/*\n    cramfsswap - swaps endian of a cramfs file\n\n    last modified on 2006-11-08 by kju\n\n    Copyright (c) 2004-2006 by Michael Holzt, kju -at- fqdn.org\n    To be distributed under the terms of the GPL2 license.\n    \n*/\n\n#include <stdio.h>\n#include <inttypes.h>\n#include <sys/stat.h>\n#include <linux/cramfs_fs.h>\n#include <byteswap.h>\n#include <zlib.h> /* for crc32 */\n#include <sys/mman.h>\n#include <fcntl.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define BUFFERSIZE\t16384\n#define MAXFILES\t4096\n#define BLKSIZE\t\t4096\t/* Should this be a command line option? */\n\n\nint main(int argc, char *argv[])\n{\n  uint32_t\t\tsuperblock_in[16], superblock_out[16], \n                        flags, blockpointer_in, blockpointer_out,\n                        blockpointer_last, crc, *mapping;\n  uint16_t\t\tendiantest;\n  uint8_t\t        inode_in[12], inode_out[12];\n  struct cramfs_inode\tinode;\n  unsigned int\t\tfilecnt, file, filepos, remaining, nblocks,\n                        copybytes, readbytes, x;\n  unsigned int \t\t*fileoffset, *filesize;\n  unsigned char\t\tbuffer[BUFFERSIZE], is_hostorder, host_is_le, file_is_le;\n  int\t\t\tinfile, outfile;\n  int\t\t\tsize;\n\n  \n  if ( argc != 3 )\n  {\n    fprintf(stderr, \"Usage: %s <in> <out>\\n\", argv[0]);\n    exit(1);\n  }\n                                    \n  if ( (infile=open(argv[1],O_RDONLY)) < 0 )\n  {\n    perror(\"while trying to open binary input file\");\n    exit(1);\n  }\n  if ( (outfile=open(argv[2], O_RDWR|O_TRUNC|O_CREAT, 0644)) < 0 )\n  {\n    perror(\"while trying to open image output file\");\n    exit(1);\n  }\n\n  if ( read(infile, &superblock_in, sizeof(superblock_in)) != sizeof(superblock_in) )\n  {\n    perror(\"while trying to read superblock\");\n    exit(1);\n  }\n\n  /* Detect endianness of host */\n  endiantest = 1;\n  if ( ((uint8_t *)&endiantest)[0] == 1 )\n    host_is_le = 1;\n  else\n    host_is_le = 0;\n\n  /* Detect endianness of file */\n  if ( superblock_in[0] == CRAMFS_MAGIC )\n  {\n    is_hostorder = 1;\n    file_is_le = host_is_le;\n  }\n  else if ( superblock_in[0] == bswap_32(CRAMFS_MAGIC) )\n  {\n    is_hostorder = 0;\n    file_is_le = !(host_is_le);\n  }\n  else\n  {\n    fprintf(stderr, \"cramfs magic not detected\\n\");\n    exit(1);\n  }\n\n  if ( file_is_le )\n    printf(\"Filesystem is little endian, will be converted to big endian.\\n\");\n  else\n    printf(\"Filesystem is big endian, will be converted to little endian.\\n\");\n\n  /* Swap Superblock */\n  superblock_out[ 0] = bswap_32(superblock_in[ 0]);\t/* Magic */\n  superblock_out[ 1] = bswap_32(superblock_in[ 1]);\t/* Size */\n  superblock_out[ 2] = bswap_32(superblock_in[ 2]);\t/* Flags */\n  superblock_out[ 3] = bswap_32(superblock_in[ 3]);\t/* Future Use */\n  superblock_out[ 4] =          superblock_in[ 4] ;     /* Sig 1/4 */\n  superblock_out[ 5] =          superblock_in[ 5] ;     /* Sig 2/4 */\n  superblock_out[ 6] =          superblock_in[ 6] ;     /* Sig 3/4 */\n  superblock_out[ 7] =          superblock_in[ 7] ;     /* Sig 4/4 */\n  superblock_out[ 8] = bswap_32(superblock_in[ 8]);\t/* fsid crc */\n  superblock_out[ 9] = bswap_32(superblock_in[ 9]);\t/* fsid edition */\n  superblock_out[10] = bswap_32(superblock_in[10]);\t/* fsid blocks */\n  superblock_out[11] = bswap_32(superblock_in[11]);\t/* fsid files */\n  superblock_out[12] =          superblock_in[12] ;     /* Name 1/4 */\n  superblock_out[13] =          superblock_in[13] ;     /* Name 2/4 */\n  superblock_out[14] =          superblock_in[14] ;     /* Name 3/4 */\n  superblock_out[15] =          superblock_in[15] ;     /* Name 4/4 */\n  write(outfile, &superblock_out, sizeof(superblock_out));\n\n\n  /* Check Flags */\n  if ( is_hostorder)\n    flags = superblock_in[2];\n  else\n    flags = superblock_out[2];\n\n  /* I'm not sure about the changes between v1 and v2. So for now\n     don't support v1. */\n  if ( (flags & 0x1) == 0 )\n  {\n    fprintf(stderr,\"Error: Not cramfs version 2!\\n\");\n    exit(1);\n  }\n\n  /* This should be done later */\n  if ( flags & 0x100 )\n  {\n    fprintf(stderr,\"Error: Filesystem contains holes (not supported yet)\\n\");\n    exit(1);\n  }\n  \n  /* Do we really need this? */  \n  if ( flags & 0x400 )\n  {\n    fprintf(stderr,\"Error: Filesystem has shifted root fs flag (not supported)\\n\");\n    exit(1);\n  }\n\n  /* Something else? */  \n  if ( flags & 0xFFFFFFFC )\n  {\n    fprintf(stderr,\"Error: Filesystem has unknown/unsupported flag set!\\n\");\n    exit(1);\n  }\n\n  /* Get Filecounter (which is number of file entries plus 1 (for the root inode) */\n  if ( is_hostorder )\n    filecnt = superblock_in[11];\n  else\n    filecnt = superblock_out[11];\n  printf(\"Filesystem contains %d files.\\n\", filecnt-1);\n\n  fileoffset = (unsigned int*)malloc( filecnt * sizeof( *fileoffset ));\n  if( fileoffset == NULL ){\n      perror(\"fileoffset malloc error\");\n      exit(1);\n  }\n\n  filesize = (unsigned int*)malloc( filecnt * sizeof( *filesize ));\n  if( filesize == NULL ){\n      free( fileoffset ); fileoffset = NULL;\n      perror(\"filesize malloc error\");\n      exit(1);\n  }\n\n  /* Set filepos (in words) */\n  filepos = 16;\n\n  /* Initialise the counter for the \"real\" (stored) files */\n  remaining = 0;\n\n  /* Read directory entries (first one is the root inode) */\n  for ( file=0; file<filecnt; file++ )\n  {\n    /* Read and swap file inode */\n    if ( read(infile, &inode_in, sizeof(inode_in)) != sizeof(inode_in) )\n    {\n      perror(\"while trying to read directory entry\");\n      exit(1);\n    }\n\n    /* Swap the inode. */\n\n    inode_out[0] = inode_in[1]; /* 16 bit: mode */\n    inode_out[1] = inode_in[0];\n\n    inode_out[2] = inode_in[3]; /* 16 bit: uid */\n    inode_out[3] = inode_in[2]; \n    \n    inode_out[4] = inode_in[6]; /* 24 bit: size */\n    inode_out[5] = inode_in[5];\n    inode_out[6] = inode_in[4];\n    \n    inode_out[7] = inode_in[7]; /* 8 bit: gid width */\n\n    /* Stop the madness! Outlaw C bitfields! They are unportable and nasty!\n       See yourself what a mess this is: */\n    \n    if ( file_is_le )\n    {\n      inode_out[ 8] = ( (inode_in[ 8]&0x3F) << 2 ) | \n                      ( (inode_in[11]&0xC0) >> 6 );\n                     \n      inode_out[ 9] = ( (inode_in[11]&0x3F) << 2 ) |\n                      ( (inode_in[10]&0xC0) >> 6 );\n\n      inode_out[10] = ( (inode_in[10]&0x3F) << 2 ) |\n                      ( (inode_in[ 9]&0xC0) >> 6 );\n\n      inode_out[11] = ( (inode_in[ 9]&0x3F) << 2 ) |\n                      ( (inode_in[ 8]&0xC0) >> 6 );\n    } else\n    {\n      inode_out[ 8] = ( (inode_in[ 8]&0xFD) >> 2 ) | \n                      ( (inode_in[11]&0x03) << 6 );\n                     \n      inode_out[ 9] = ( (inode_in[11]&0xFD) >> 2 ) | \n                      ( (inode_in[10]&0x03) << 6 );\n                     \n      inode_out[10] = ( (inode_in[10]&0xFD) >> 2 ) | \n                      ( (inode_in[ 9]&0x03) << 6 );\n                     \n      inode_out[11] = ( (inode_in[ 9]&0xFD) >> 2 ) | \n                      ( (inode_in[ 8]&0x03) << 6 );\n    }\n    \n    if ( is_hostorder )\n    {\n      /* copy the input for our use */\n      memcpy(&inode, &inode_in, sizeof(inode_in));\n    } else\n    {\n      /* copy the output for our use */\n      memcpy(&inode, &inode_out, sizeof(inode_in));\n    }\n\n    /* write the converted inode */\n    write(outfile, &inode_out, sizeof(inode_out));\n\n    /* Copy filename */\n    if ( read(infile, &buffer, inode.namelen<<2) != inode.namelen<<2 )\n    {\n      perror(\"while trying to read filename\");\n      exit(1);\n    }\n    write(outfile, &buffer, inode.namelen<<2);\n\n    /* Store the file size and file offset */\n    filesize  [file] = inode.size;\n    fileoffset[file] = inode.offset;\n\n    /* filepos is increased by namelen words + 3 words for the inode */\n    filepos += inode.namelen + 3;\n\n    /* Has this entry a data chunk? */\n    if ( ( S_ISREG(inode.mode) || S_ISLNK(inode.mode) ) && inode.size > 0 )\n    {\n      remaining++;\n    }\n    \n  }\n\n  \n  /* Now process the individual files data. Because cramfs will share the compressed\n     data for two identical input files, we do this by starting at the begin of the\n     data, identifiying the accompanying file, process the file data, and move to\n     the next until no file is left                                                */\n  while ( remaining )\n  {\n    /* Find the file */\n    for ( file=1; fileoffset[file]!=filepos&&file<filecnt; file++ );\n    if ( fileoffset[file]!=filepos ) \n    {\n      /* Not found */\n      fprintf(stderr, \"Did not find the file which starts at word %x, aborting...\\n\", filepos);\n      exit(1);\n    }\n\n    /* Reduce file counter for each file which starts here (as said, can be more\n       than one if the cramfs had identical input files) */\n    for ( x=1; x<filecnt; x++ )\n      if ( fileoffset[x] == filepos )\n        remaining--;\n\n    /* Number of blocks of this file */\n    nblocks = (filesize[file]-1)/BLKSIZE + 1;\n\n    /* Swap the blockpointer */\n    for ( x=0; x<nblocks; x++ )\n    {\n      if ( read(infile, &blockpointer_in, 4) != 4 )\n      {\n        perror(\"while trying to read blockpointer\");\n        exit(1);\n      }\n\n      blockpointer_out = bswap_32(blockpointer_in);\n      write(outfile, &blockpointer_out, 4);\n\n      filepos++;\n    }\n    \n    /* Last blockpointer points to the byte after the end \n       of the file */\n    if ( is_hostorder )\n      blockpointer_last = blockpointer_in;\n    else\n      blockpointer_last = blockpointer_out;\n\n    /* Align to a word boundary */\n    blockpointer_last += (4-(blockpointer_last%4))%4;\n\n    /* Copy the file data */\n    copybytes = blockpointer_last-(filepos<<2);\n    while (copybytes>0)\n    {\n      readbytes = (copybytes>BUFFERSIZE) ? BUFFERSIZE : copybytes;\n      \n      if ( read(infile, &buffer, readbytes) != readbytes )\n      {\n        perror(\"while trying to read file data\");\n        exit(1);\n      }\n      write(outfile, &buffer, readbytes);\n      \n      copybytes -= readbytes;\n    }\n\n    /* Set new filepos */\n    filepos = (blockpointer_last)>>2;\n  }  \n\n  /* Copy the remaining data (padding) */\n  do\n  {\n    readbytes = read(infile, &buffer, BUFFERSIZE);\n    write(outfile, &buffer, readbytes);\n  } while ( readbytes>0 );\n\n  /* recalculate the crc */\n  size = lseek(outfile, 0, SEEK_CUR); /* should not fail */\n  mapping = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, outfile, 0);\n  if (mapping != MAP_FAILED) {\n    crc = crc32(0L, Z_NULL, 0);\n    mapping[8] = is_hostorder?bswap_32(crc):crc;\n    crc = crc32(crc, (unsigned char *)mapping, size);\n    printf(\"CRC: 0x%08x\\n\", crc);\n    mapping[8] = is_hostorder?bswap_32(crc):crc;\n    munmap(mapping, size);\n  }\n  else {\n    perror(\"mapping failed\");\n  }\n  \n  /* Done! */\n  close(infile);\n  close(outfile);\n\n  exit(0);                                                                \n}\n\n"
  },
  {
    "path": "src/cramfsswap/debian/changelog",
    "content": "cramfsswap (1.4.1) unstable; urgency=low\n\n  * Changed build rules: Do not strip in makefile when building for debian,\n    instead will be stripped by dh_strip invocation in debian/rules thus\n    honoring nostrip option correctly (closes: Bug#436671).\n\n -- Michael Holzt <debian-cramfsswap@michael.holzt.de>  Sun, 14 Oct 2007 23:38:41 +0200\n\ncramfsswap (1.4) unstable; urgency=low\n\n  * cramfsswap can now handle cramfs filesystems with more than 4095 files\n    thanks to a patch by Nobuhiro Iwamatsu (closes: Bug#440060).\n\n -- Michael Holzt <debian-cramfsswap@michael.holzt.de>  Sun, 14 Oct 2007 22:03:07 +0200\n\ncramfsswap (1.3.1) unstable; urgency=low\n\n  * Corrected beginning of source (GPL-Notice, last modified)\n\n -- Michael Holzt <debian-cramfsswap@michael.holzt.de>  Wed,  8 Nov 2006 16:36:19 +0100\n\ncramfsswap (1.3) unstable; urgency=low\n\n  * Corrected swapping on big endian architecture (closes: Bug#345723).\n  * Skipped version 1.2 due to incorrectly handled NMU. :-(\n  * Clarified license information. Only GPL2 does apply, no GPL3!\n\n -- Michael Holzt <debian-cramfsswap@michael.holzt.de>  Wed,  8 Nov 2006 14:10:27 +0100\n\ncramfsswap (1.2) unstable; urgency=low\n\n  * NMU\n  * Patch from Andreas Jochens to fix FTBFS on unstable due to missing u32\n    declaration. Closes: #392166\n\n -- Joey Hess <joeyh@debian.org>  Tue, 17 Oct 2006 15:50:08 -0400\n\ncramfsswap (1.1) unstable; urgency=low\n\n  * Initial Release.\n\n -- Michael Holzt <kju@debian.org>  Tue,  4 Jan 2005 12:26:00 +0100\n"
  },
  {
    "path": "src/cramfsswap/debian/compat",
    "content": "4\n"
  },
  {
    "path": "src/cramfsswap/debian/control",
    "content": "Source: cramfsswap\nSection: utils\nPriority: extra\nMaintainer: Michael Holzt <debian-cramfsswap@michael.holzt.de>\nBuild-Depends: debhelper (>= 4.1.16), zlib1g-dev\nStandards-Version: 3.7.2\n\nPackage: cramfsswap\nArchitecture: any\nDepends: ${shlibs:Depends}\nDescription: swap endianess of a cram filesystem (cramfs)\n cramfs is a highly compressed and size optimized linux filesystem which is\n mainly used for embedded applications. the problem with cramfs is that it\n is endianess sensitive, meaning you can't mount a cramfs for a big endian\n target on a little endian machine and vice versa. this is often especially \n a problem in the development phase.\n .\n cramfsswap solves that problem by allowing you to swap to endianess of a\n cramfs filesystem.\n"
  },
  {
    "path": "src/cramfsswap/debian/copyright",
    "content": "This package was debianized by Michael Holzt <kju@debian.org> on\nTue,  4 Jan 2005 12:26:00 +0100.\n\nThis is a native debian package, debian maintainer and upstream author are\nthe same person. The source can be downloaded from \nhttp://kju.de/projekte/cramfsswap/ (sorry, German only)\n\nLicense:\n\ncramfsswap is released under the GNU GPL license as free, open source\nsoftware. Hopefully it will seem useful to someone. NO WARRANTY. GPL2\nonly! On Debian GNU/Linux systems, the complete text of the GNU General\nPublic License can be found in '/usr/share/common-licenses/GPL'.\n"
  },
  {
    "path": "src/cramfsswap/debian/dirs",
    "content": "usr/bin\nusr/sbin\n"
  },
  {
    "path": "src/cramfsswap/debian/docs",
    "content": "README\n"
  },
  {
    "path": "src/cramfsswap/debian/rules",
    "content": "#!/usr/bin/make -f\n#\n# debian/rules for cramfsswap\n#\n# modelled after the debhelper example\n#\n\n# Uncomment this to turn on verbose mode.\n#export DH_VERBOSE=1\n\nbuild: build-stamp\nbuild-stamp: \n\tdh_testdir\n\t$(MAKE) debian\n\ttouch build-stamp\n\nclean:\n\tdh_testdir\n\tdh_testroot\n\trm -f build-stamp configure-stamp\n\t-$(MAKE) clean\n\tdh_clean \n\ninstall: build\n\tdh_testdir\n\tdh_testroot\n\tdh_clean -k \n\tdh_installdirs\n\t$(MAKE) install DESTDIR=$(CURDIR)/debian/cramfsswap\n\n# Build architecture-independent files here.\nbinary-indep: build install\n# We have nothing to do by default.\n\n# Build architecture-dependent files here.\nbinary-arch: build install\n\tdh_testdir\n\tdh_testroot\n\tdh_installchangelogs \n\tdh_installdocs\n\tdh_installman cramfsswap.1\n\tdh_link\n\tdh_strip\n\tdh_compress\n\tdh_fixperms\n\tdh_installdeb\n\tdh_shlibdeps\n\tdh_gencontrol\n\tdh_md5sums\n\tdh_builddeb\n\nbinary: binary-indep binary-arch\n.PHONY: build clean binary-indep binary-arch binary install\n"
  },
  {
    "path": "src/crcalc/Makefile",
    "content": "CC=gcc\nCFLAGS=-Wall\nTARGET=crcalc\n\n$(TARGET): patch.o\n\t$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET).c *.o -o $(TARGET)\n\npatch.o: crc.o md5.o\n\t$(CC) $(CFLAGS) $(LDFLAGS) patch.c -c\n\ncrc.o:\n\t$(CC) $(CFLAGS) $(LDFLAGS) crc.c -c\n\nmd5.o:\n\t$(CC) $(CFLAGS) $(LDFLAGS) md5.c -c\n\nclean:\n\trm -f *.o $(TARGET)\n"
  },
  {
    "path": "src/crcalc/README",
    "content": "DESCRIPTION\n\t\n\tCRCalc re-calculates and updates the CRC fields of uImage, TRX, and DLOB firmware headers.\n\n\tCRCalc can update multiple headers inside a firmware image if you provide it with a list\n\tof offsets for each header inside the firmware image. The list file can be a binwalk log\n\tor just a list of decimal offsets (one offset per line).\n\n\tIf no binwalk log or list file is provided, CRCalc assumes that there is only one header\n\tat the very beginning of the target firmware image.\n\nUSAGE\n\t\n\tBasic usage:\n\t\n\t\t$ crcalc firmware.img\n\n\tUsage with a binwalk log / offset list file:\n\n\t\t$ crcalc firmware.img binwalk.log\n"
  },
  {
    "path": "src/crcalc/crc.c",
    "content": "#include \"crc.h\"\n\n/**********************************************************************/\n/* The following was grabbed and tweaked from the old snippets collection\n * of public domain C code. */\n\n/**********************************************************************\\\n|* Demonstration program to compute the 32-bit CRC used as the frame  *|\n|* check sequence in ADCCP (ANSI X3.66, also known as FIPS PUB 71     *|\n|* and FED-STD-1003, the U.S. versions of CCITT's X.25 link-level     *|\n|* protocol).  The 32-bit FCS was added via the Federal Register,     *|\n|* 1 June 1982, p.23798.  I presume but don't know for certain that   *|\n|* this polynomial is or will be included in CCITT V.41, which        *|\n|* defines the 16-bit CRC (often called CRC-CCITT) polynomial.  FIPS  *|\n|* PUB 78 says that the 32-bit FCS reduces otherwise undetected       *|\n|* errors by a factor of 10^-5 over 16-bit FCS.                       *|\n\\**********************************************************************/\n\n/* Copyright (C) 1986 Gary S. Brown.  You may use this program, or\n   code or tables extracted from it, as desired without restriction.*/\n\n/* First, the polynomial itself and its table of feedback terms.  The  */\n/* polynomial is                                                       */\n/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */\n/* Note that we take it \"backwards\" and put the highest-order term in  */\n/* the lowest-order bit.  The X^32 term is \"implied\"; the LSB is the   */\n/* X^31 term, etc.  The X^0 term (usually shown as \"+1\") results in    */\n/* the MSB being 1.                                                    */\n\n/* Note that the usual hardware shift register implementation, which   */\n/* is what we're using (we're merely optimizing it by doing eight-bit  */\n/* chunks at a time) shifts bits into the lowest-order term.  In our   */\n/* implementation, that means shifting towards the right.  Why do we   */\n/* do it this way?  Because the calculated CRC must be transmitted in  */\n/* order from highest-order term to lowest-order term.  UARTs transmit */\n/* characters in order from LSB to MSB.  By storing the CRC this way,  */\n/* we hand it to the UART in the order low-byte to high-byte; the UART */\n/* sends each low-bit to hight-bit; and the result is transmission bit */\n/* by bit from highest- to lowest-order term without requiring any bit */\n/* shuffling on our part.  Reception works similarly.                  */\n\n/* The feedback terms table consists of 256, 32-bit entries.  Notes:   */\n/*                                                                     */\n/*  1. The table can be generated at runtime if desired; code to do so */\n/*     is shown later.  It might not be obvious, but the feedback      */\n/*     terms simply represent the results of eight shift/xor opera-    */\n/*     tions for all combinations of data and CRC register values.     */\n/*                                                                     */\n/*  2. The CRC accumulation logic is the same for all CRC polynomials, */\n/*     be they sixteen or thirty-two bits wide.  You simply choose the */\n/*     appropriate table.  Alternatively, because the table can be     */\n/*     generated at runtime, you can start by generating the table for */\n/*     the polynomial in question and use exactly the same \"updcrc\",   */\n/*     if your application needn't simultaneously handle two CRC       */\n/*     polynomials.  (Note, however, that XMODEM is strange.)          */\n/*                                                                     */\n/*  3. For 16-bit CRCs, the table entries need be only 16 bits wide;   */\n/*     of course, 32-bit entries work OK if the high 16 bits are zero. */\n/*                                                                     */\n/*  4. The values must be right-shifted by eight bits by the \"updcrc\"  */\n/*     logic; the shift must be unsigned (bring in zeroes).  On some   */\n/*     hardware you could probably optimize the shift in assembler by  */\n/*     using byte-swap instructions.                                   */\n\nstatic const uint32_t crc_32_tab[] = { /* CRC polynomial 0xedb88320 */\n0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,\n0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,\n0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,\n0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,\n0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,\n0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,\n0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,\n0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,\n0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,\n0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,\n0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,\n0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,\n0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,\n0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,\n0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,\n0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,\n0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\n0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d\n};\n\n#define UPDC32(octet,crc) (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8))\n\nuint32_t crc32(char *buf, size_t len)\n{\n      uint32_t crc;\n\n      crc = 0xFFFFFFFF;\n\n      for ( ; len; --len, ++buf)\n      {\n            crc = UPDC32(*buf, crc);\n      }\n\n      return crc;\n}\n"
  },
  {
    "path": "src/crcalc/crc.h",
    "content": "#ifndef _CRC_H_\n#define _CRC_H_\n\n#include <stdlib.h>\n#include <stdint.h>\n\nuint32_t crc32(char *buf, size_t len);\n\n#endif\n"
  },
  {
    "path": "src/crcalc/crcalc.c",
    "content": "/*\n * Utility for calculating and patching checksums in various files.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include \"crcalc.h\"\n#include \"patch.h\"\n\nint main(int argc, char *argv[])\n{\n\tint retval = EXIT_FAILURE, ok = 0, fail = 1, n = 0, i = 0, offset = 0;\n\tint offsets[MAX_HEAD_SIZE] = { 0 };\n\tchar *buf = NULL, *ptr = NULL, *fname = NULL, *log = NULL;\n\tsize_t size = 0, nsize = 0;\n\n\t/* Check usage */\n\tif(argc < 2 || argv[1][0] == '-')\n\t{\n\t\tfprintf(stderr, USAGE, argv[0]);\n\t\tgoto end;\n\t}\n\telse\n\t{\n\t\tfname = argv[1];\n\t\n\t\tif(argc == 3)\n\t\t{\n\t\t\tlog = argv[2];\n\t\t}\n\t}\n\n\t/* Read in target file */\n\tbuf = file_read(fname, &size);\n\n\tif(buf && size > MIN_FILE_SIZE)\n\t{\n\t\t/* Parse in the log file, if any */\n\t\tn = parse_log(log, offsets);\n\n\t\tfprintf(stderr, \"Processing %d header(s) from %s...\\n\", n, fname);\n\n\t\t/* Loop through each offset in the integer array */\n\t\tfor(i=0; i<n; i++)\n\t\t{\n\t\t\tok = 0;\n\t\t\toffset = offsets[i];\n\t\t\tnsize = size - offset;\n\t\t\tptr = (buf + offset);\n\n\t\t\tfprintf(stderr, \"Processing header at offset %d...\", offset);\n\n\t\t\t/* Identify and patch the header at each offset */\n\t\t\tswitch(identify_header(ptr))\n\t\t\t{\n\t\t\t\tcase TRX:\n\t\t\t\t\tok = patch_trx(ptr, nsize);\n\t\t\t\t\tbreak;\n\t\t\t\tcase UIMAGE:\n\t\t\t\t\tok = patch_uimage(ptr, nsize);\n\t\t\t\t\tbreak;\n\t\t\t\tcase DLOB:\n\t\t\t\t\tok = patch_dlob(ptr, nsize);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tfprintf(stderr, \"sorry, this file type is not supported.\\n\");\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(ok)\n\t\t\t{\n\t\t\t\tfail = 0;\n\t\t\t\tfprintf(stderr, \"checksum(s) updated OK.\\n\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfprintf(stderr, \"checksum update(s) failed!\\n\");\n\t\t\t}\n\t\t}\n\t}\n\n\tif(!fail)\n\t{\n\t\tif(!file_write(fname, buf, size))\n\t\t{\n\t\t\tfprintf(stderr, \"Failed to save data to file '%s'\\n\", fname);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfprintf(stderr, \"CRC(s) updated successfully.\\n\");\n\t\t\tretval = EXIT_SUCCESS;\n\t\t}\n\t}\n\telse\n\t{\n\t\tfprintf(stderr, \"CRC update failed.\\n\");\n\t}\n\nend:\n\tif(buf) free(buf);\n\treturn retval;\n}\n\n/* Parse binwalk-style log file for offsets to headers in the target firmware image */\nint parse_log(char *file, int offsets[MAX_HEAD_SIZE])\n{\n\tFILE *fp = NULL;\n\tchar line[MAX_LINE_SIZE] = { 0 };\n\tint n = 0;\n\n\tif(file == NULL)\n\t{\n\t\toffsets[0] = 0;\n\t\tn = 1;\n\t}\n\telse\n\t{\n\t\tfp = fopen(file, \"r\");\n\t\tif(fp)\n\t\t{\n\t\t\t/* Read each line one at a time from the log file */\n\t\t\twhile((fgets((char *) &line, MAX_LINE_SIZE, fp) != NULL) && (n < MAX_HEAD_SIZE))\n\t\t\t{\n\t\t\t\t/* \n\t\t\t\t * If the line has the string 'header', or it is a short, non-white space line, \n\t\t\t\t * use the offset in this line. This allows us to parse a file with just a list of\n\t\t\t\t * header offsets, as well as standard binwalk logs.\n\t\t\t\t */\n\t\t\t\tif((((strlen((char *) &line) < MAX_STR_SIZE) && !is_whitespace((char *) &line))) ||\n\t\t\t\t   (strstr((char *) &line, HEADER_ID_STR)))\n\t\t\t\t{\n\t\t\t\t\toffsets[n] = atoi((char *) &line);\n\t\t\t\t\tn++;\n\t\t\t\t}\n\n\t\t\t\tmemset((char *) &line, 0, MAX_LINE_SIZE);\n\t\t\t}\n\n\t\t\tfclose(fp);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tperror(file);\n\t\t}\n\t}\n\n\treturn n;\n}\n\n/* Determine if a string is all white space or not */\nint is_whitespace(char *string)\n{\n\tint i = 0, retval = 1;\n\n\tfor(i=0; i<strlen(string); i++)\n\t{\n\t\tif(string[i] >= MIN_NON_WHITE)\n\t\t{\n\t\t\tretval = 0;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Reads in and returns the contents and size of a given file */\nchar *file_read(char *file, size_t *fsize)\n{\n        int fd = 0;\n        struct stat _fstat = { 0 };\n        char *buffer = NULL;\n\n        if(stat(file, &_fstat) == -1)\n        {\n                perror(file);\n                goto end;\n        }\n\n        if(_fstat.st_size == 0)\n        {\n                fprintf(stderr, \"%s: zero size file\\n\", file);\n                goto end;\n        }\n\n        fd = open(file,O_RDONLY);\n        if(!fd)\n        {\n                perror(file);\n                goto end;\n        }\n\n        buffer = malloc(_fstat.st_size);\n        if(!buffer)\n        {\n                perror(\"malloc\");\n\t\tgoto end;\n        }\n        memset(buffer, 0 ,_fstat.st_size);\n\n        if(read(fd, buffer, _fstat.st_size) != _fstat.st_size)\n        {\n                perror(file);\n                if(buffer) free(buffer);\n                buffer = NULL;\n        }\n        else\n        {\n                *fsize = _fstat.st_size;\n        }\n\nend:\n        if(fd) close(fd);\n        return buffer;\n}\n\n/* Write size bytes from buf to file fname */\nint file_write(char *fname, char *buf, size_t size)\n{\n\tFILE *fp = NULL;\n\tint retval = 0;\n\n\tfp = fopen(fname, \"w\");\n\tif(fp)\n\t{\n\t\tif(fwrite(buf, 1, size, fp) == size)\n\t\t{\n\t\t\tretval = 1;\n\t\t}\n\t\t\n\t\tfclose(fp);\n\t}\n\telse\n\t{\n\t\tperror(\"fopen\");\n\t}\n\n\treturn retval;\n}\n\n/* Identifies the header type used in the supplied file */\nenum header_type identify_header(char *buf)\n{\n\tenum header_type retval = UNKNOWN;\n\tuint32_t *sig = NULL;\n\n\tsig = (uint32_t *) buf;\n\n\tswitch(*sig)\n\t{\n\t\tcase TRX_MAGIC:\n\t\t\tretval = TRX;\n\t\t\tbreak;\n\t\tcase UIMAGE_MAGIC:\n\t\t\tretval = UIMAGE;\n\t\t\tbreak;\n\t\tcase DLOB_MAGIC:\n\t\t\tretval = DLOB;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\n\treturn retval;\n}\n\n"
  },
  {
    "path": "src/crcalc/crcalc.h",
    "content": "#ifndef _CRCALC_H_\n#define _CRCALC_H_\n\n#include <stdint.h>\n\n#define MIN_FILE_SIZE 4\n#define MAX_LINE_SIZE 8096\n#define MAX_HEAD_SIZE 512\n#define HEADER_ID_STR \"header\"\n#define MIN_NON_WHITE '!'\n#define MAX_STR_SIZE  10\n#define MIN_STR_SIZE  1\n\n#define USAGE \"\\n\\\ncrcalc v0.2 - (c) 2011, Craig Heffner\\n\\\nRe-calculates firmware header checksusms for TRX and uImage firmware headers.\\n\\\n\\n\\\nUsage: %s <firmware image> [binwalk log file]\\n\\\n\\n\\\nIf no binwalk log file is specified, the header is assumed to be at the beginning of the firmware image.\\n\\\n\\n\"\n\nenum header_type\n{\n\tUNKNOWN,\n\tTRX,\n\tUIMAGE,\n\tDLOB,\n};\n\nint parse_log(char *file, int offsets[MAX_HEAD_SIZE]);\nint is_whitespace(char *string);\nchar *file_read(char *file, size_t *fsize);\nint file_write(char *fname, char *buf, size_t size);\nenum header_type identify_header(char *buf);\n\n#endif\n"
  },
  {
    "path": "src/crcalc/md5.c",
    "content": "/* \n * Added md5_string function for ease of use with Binwalk.\n * \n * Original file obtained from: http://cr.yp.to/2004-494/gaim/0.81-src/md5.c\n *\n * Craig Heffner\n */\n\n/*\n  Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.\n\n  This software is provided 'as-is', without any express or implied\n  warranty.  In no event will the authors be held liable for any damages\n  arising from the use of this software.\n\n  Permission is granted to anyone to use this software for any purpose,\n  including commercial applications, and to alter it and redistribute it\n  freely, subject to the following restrictions:\n\n  1. The origin of this software must not be misrepresented; you must not\n     claim that you wrote the original software. If you use this software\n     in a product, an acknowledgment in the product documentation would be\n     appreciated but is not required.\n  2. Altered source versions must be plainly marked as such, and must not be\n     misrepresented as being the original software.\n  3. This notice may not be removed or altered from any source distribution.\n\n  L. Peter Deutsch\n  ghost@aladdin.com\n\n */\n/*\n  Independent implementation of MD5 (RFC 1321).\n\n  This code implements the MD5 Algorithm defined in RFC 1321.\n  It is derived directly from the text of the RFC and not from the\n  reference implementation.\n\n  The original and principal author of md5.c is L. Peter Deutsch\n  <ghost@aladdin.com>.  Other authors are noted in the change history\n  that follows (in reverse chronological order):\n\n  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.\n  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).\n  1999-05-03 lpd Original version.\n */\n\n#include \"md5.h\"\n#include <string.h>\n#include <stdio.h>\t/* Needed for snprintf call in md5_string() */\n\n#ifdef TEST\n/*\n * Compile with -DTEST to create a self-contained executable test program.\n * The test program should print out the same values as given in section\n * A.5 of RFC 1321, reproduced below.\n */\n#include <string.h>\nmain()\n{\n    static const char *const test[7] = {\n\t\"\", /*d41d8cd98f00b204e9800998ecf8427e*/\n\t\"945399884.61923487334tuvga\", /*0cc175b9c0f1b6a831c399e269772661*/\n\t\"abc\", /*900150983cd24fb0d6963f7d28e17f72*/\n\t\"message digest\", /*f96b697d7cb7938d525a2f31aaf161d0*/\n\t\"abcdefghijklmnopqrstuvwxyz\", /*c3fcd3d76192e4007dfb496cca67e13b*/\n\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\",\n\t\t\t\t/*d174ab98d277d9f5a5611c2c9f419d9f*/\n\t\"12345678901234567890123456789012345678901234567890123456789012345678901234567890\" /*57edf4a22be3c955ac49da2e2107b67a*/\n    };\n    int i;\n\n    for (i = 0; i < 7; ++i) {\n\tmd5_state_t state;\n\tmd5_byte_t digest[16];\n\tint di;\n\n\tmd5_init(&state);\n\tmd5_append(&state, (const md5_byte_t *)test[i], strlen(test[i]));\n\tmd5_finish(&state, digest);\n\tprintf(\"MD5 (\\\"%s\\\") = \", test[i]);\n\tfor (di = 0; di < 16; ++di)\n\t    printf(\"%02x\", digest[di]);\n\tprintf(\"  ::  MD5 string: %s\", md5_string((void *) test[i],strlen(test[i])));\n\tprintf(\"\\n\");\n    }\n    return 0;\n}\n#endif /* TEST */\n\n/* Returns the MD5 checksum string of a given file */\nchar *md5_string(void *data, size_t data_size)\n{\n\tint i = 0;\n\tint byte_str_size = 2;\n\tint md5_hash_length = 16;\n\tint str_size = ((md5_hash_length*byte_str_size)+1); /* MD5 is 16 bytes at 2 characters per byte, plus trailing NULL */\n\tchar *md5str = NULL;\n\tmd5_state_t state;\n\tmd5_byte_t digest[md5_hash_length];\n\n\tmd5str = malloc(str_size);\n\tif(!md5str)\n\t{\n\t\tperror(\"malloc\");\n\t}\n\telse\n\t{\n\t\tmemset(md5str,0,str_size);\n\n\t\tmd5_init(&state);\n\t\tmd5_append(&state, (const md5_byte_t *) data, data_size);\n\t\tmd5_finish(&state, digest);\n\n\t\tfor(i = 0; i < md5_hash_length; i++)\n\t\t{\n\t\t\tsnprintf(md5str+(byte_str_size*i),byte_str_size+1,\"%02x\",digest[i]);\n\t\t}\n\t}\n\n\treturn md5str;\n}\n\n/*\n * For reference, here is the program that computed the T values.\n */\n#if 0\n#include <math.h>\nmain()\n{\n    int i;\n    for (i = 1; i <= 64; ++i) {\n\tunsigned long v = (unsigned long)(4294967296.0 * fabs(sin((double)i)));\n\tprintf(\"#define T%d 0x%08lx\\n\", i, v);\n    }\n    return 0;\n}\n#endif\n/*\n * End of T computation program.\n */\n#define T1 0xd76aa478\n#define T2 0xe8c7b756\n#define T3 0x242070db\n#define T4 0xc1bdceee\n#define T5 0xf57c0faf\n#define T6 0x4787c62a\n#define T7 0xa8304613\n#define T8 0xfd469501\n#define T9 0x698098d8\n#define T10 0x8b44f7af\n#define T11 0xffff5bb1\n#define T12 0x895cd7be\n#define T13 0x6b901122\n#define T14 0xfd987193\n#define T15 0xa679438e\n#define T16 0x49b40821\n#define T17 0xf61e2562\n#define T18 0xc040b340\n#define T19 0x265e5a51\n#define T20 0xe9b6c7aa\n#define T21 0xd62f105d\n#define T22 0x02441453\n#define T23 0xd8a1e681\n#define T24 0xe7d3fbc8\n#define T25 0x21e1cde6\n#define T26 0xc33707d6\n#define T27 0xf4d50d87\n#define T28 0x455a14ed\n#define T29 0xa9e3e905\n#define T30 0xfcefa3f8\n#define T31 0x676f02d9\n#define T32 0x8d2a4c8a\n#define T33 0xfffa3942\n#define T34 0x8771f681\n#define T35 0x6d9d6122\n#define T36 0xfde5380c\n#define T37 0xa4beea44\n#define T38 0x4bdecfa9\n#define T39 0xf6bb4b60\n#define T40 0xbebfbc70\n#define T41 0x289b7ec6\n#define T42 0xeaa127fa\n#define T43 0xd4ef3085\n#define T44 0x04881d05\n#define T45 0xd9d4d039\n#define T46 0xe6db99e5\n#define T47 0x1fa27cf8\n#define T48 0xc4ac5665\n#define T49 0xf4292244\n#define T50 0x432aff97\n#define T51 0xab9423a7\n#define T52 0xfc93a039\n#define T53 0x655b59c3\n#define T54 0x8f0ccc92\n#define T55 0xffeff47d\n#define T56 0x85845dd1\n#define T57 0x6fa87e4f\n#define T58 0xfe2ce6e0\n#define T59 0xa3014314\n#define T60 0x4e0811a1\n#define T61 0xf7537e82\n#define T62 0xbd3af235\n#define T63 0x2ad7d2bb\n#define T64 0xeb86d391\n\nstatic void\nmd5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)\n{\n    md5_word_t\n\ta = pms->abcd[0], b = pms->abcd[1],\n\tc = pms->abcd[2], d = pms->abcd[3];\n    md5_word_t t;\n\n#ifndef ARCH_IS_BIG_ENDIAN\n# define ARCH_IS_BIG_ENDIAN 1\t/* slower, default implementation */\n#endif\n#if ARCH_IS_BIG_ENDIAN\n\n    /*\n     * On big-endian machines, we must arrange the bytes in the right\n     * order.  (This also works on machines of unknown byte order.)\n     */\n    md5_word_t X[16];\n    const md5_byte_t *xp = data;\n    int i;\n\n    for (i = 0; i < 16; ++i, xp += 4)\n\tX[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);\n\n#else  /* !ARCH_IS_BIG_ENDIAN */\n\n    /*\n     * On little-endian machines, we can process properly aligned data\n     * without copying it.\n     */\n    md5_word_t xbuf[16];\n    const md5_word_t *X;\n\n    if (!((data - (const md5_byte_t *)0) & 3)) {\n\t/* data are properly aligned */\n\tX = (const md5_word_t *)data;\n    } else {\n\t/* not aligned */\n\tmemcpy(xbuf, data, 64);\n\tX = xbuf;\n    }\n#endif\n\n#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))\n\n    /* Round 1. */\n    /* Let [abcd k s i] denote the operation\n       a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */\n#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))\n#define SET(a, b, c, d, k, s, Ti)\\\n  t = a + F(b,c,d) + X[k] + Ti;\\\n  a = ROTATE_LEFT(t, s) + b\n    /* Do the following 16 operations. */\n    SET(a, b, c, d,  0,  7,  T1);\n    SET(d, a, b, c,  1, 12,  T2);\n    SET(c, d, a, b,  2, 17,  T3);\n    SET(b, c, d, a,  3, 22,  T4);\n    SET(a, b, c, d,  4,  7,  T5);\n    SET(d, a, b, c,  5, 12,  T6);\n    SET(c, d, a, b,  6, 17,  T7);\n    SET(b, c, d, a,  7, 22,  T8);\n    SET(a, b, c, d,  8,  7,  T9);\n    SET(d, a, b, c,  9, 12, T10);\n    SET(c, d, a, b, 10, 17, T11);\n    SET(b, c, d, a, 11, 22, T12);\n    SET(a, b, c, d, 12,  7, T13);\n    SET(d, a, b, c, 13, 12, T14);\n    SET(c, d, a, b, 14, 17, T15);\n    SET(b, c, d, a, 15, 22, T16);\n#undef SET\n\n     /* Round 2. */\n     /* Let [abcd k s i] denote the operation\n          a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */\n#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))\n#define SET(a, b, c, d, k, s, Ti)\\\n  t = a + G(b,c,d) + X[k] + Ti;\\\n  a = ROTATE_LEFT(t, s) + b\n     /* Do the following 16 operations. */\n    SET(a, b, c, d,  1,  5, T17);\n    SET(d, a, b, c,  6,  9, T18);\n    SET(c, d, a, b, 11, 14, T19);\n    SET(b, c, d, a,  0, 20, T20);\n    SET(a, b, c, d,  5,  5, T21);\n    SET(d, a, b, c, 10,  9, T22);\n    SET(c, d, a, b, 15, 14, T23);\n    SET(b, c, d, a,  4, 20, T24);\n    SET(a, b, c, d,  9,  5, T25);\n    SET(d, a, b, c, 14,  9, T26);\n    SET(c, d, a, b,  3, 14, T27);\n    SET(b, c, d, a,  8, 20, T28);\n    SET(a, b, c, d, 13,  5, T29);\n    SET(d, a, b, c,  2,  9, T30);\n    SET(c, d, a, b,  7, 14, T31);\n    SET(b, c, d, a, 12, 20, T32);\n#undef SET\n\n     /* Round 3. */\n     /* Let [abcd k s t] denote the operation\n          a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */\n#define H(x, y, z) ((x) ^ (y) ^ (z))\n#define SET(a, b, c, d, k, s, Ti)\\\n  t = a + H(b,c,d) + X[k] + Ti;\\\n  a = ROTATE_LEFT(t, s) + b\n     /* Do the following 16 operations. */\n    SET(a, b, c, d,  5,  4, T33);\n    SET(d, a, b, c,  8, 11, T34);\n    SET(c, d, a, b, 11, 16, T35);\n    SET(b, c, d, a, 14, 23, T36);\n    SET(a, b, c, d,  1,  4, T37);\n    SET(d, a, b, c,  4, 11, T38);\n    SET(c, d, a, b,  7, 16, T39);\n    SET(b, c, d, a, 10, 23, T40);\n    SET(a, b, c, d, 13,  4, T41);\n    SET(d, a, b, c,  0, 11, T42);\n    SET(c, d, a, b,  3, 16, T43);\n    SET(b, c, d, a,  6, 23, T44);\n    SET(a, b, c, d,  9,  4, T45);\n    SET(d, a, b, c, 12, 11, T46);\n    SET(c, d, a, b, 15, 16, T47);\n    SET(b, c, d, a,  2, 23, T48);\n#undef SET\n\n     /* Round 4. */\n     /* Let [abcd k s t] denote the operation\n          a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */\n#define I(x, y, z) ((y) ^ ((x) | ~(z)))\n#define SET(a, b, c, d, k, s, Ti)\\\n  t = a + I(b,c,d) + X[k] + Ti;\\\n  a = ROTATE_LEFT(t, s) + b\n     /* Do the following 16 operations. */\n    SET(a, b, c, d,  0,  6, T49);\n    SET(d, a, b, c,  7, 10, T50);\n    SET(c, d, a, b, 14, 15, T51);\n    SET(b, c, d, a,  5, 21, T52);\n    SET(a, b, c, d, 12,  6, T53);\n    SET(d, a, b, c,  3, 10, T54);\n    SET(c, d, a, b, 10, 15, T55);\n    SET(b, c, d, a,  1, 21, T56);\n    SET(a, b, c, d,  8,  6, T57);\n    SET(d, a, b, c, 15, 10, T58);\n    SET(c, d, a, b,  6, 15, T59);\n    SET(b, c, d, a, 13, 21, T60);\n    SET(a, b, c, d,  4,  6, T61);\n    SET(d, a, b, c, 11, 10, T62);\n    SET(c, d, a, b,  2, 15, T63);\n    SET(b, c, d, a,  9, 21, T64);\n#undef SET\n\n     /* Then perform the following additions. (That is increment each\n        of the four registers by the value it had before this block\n        was started.) */\n    pms->abcd[0] += a;\n    pms->abcd[1] += b;\n    pms->abcd[2] += c;\n    pms->abcd[3] += d;\n}\n\nvoid\nmd5_init(md5_state_t *pms)\n{\n    pms->count[0] = pms->count[1] = 0;\n    pms->abcd[0] = 0x67452301;\n    pms->abcd[1] = 0xefcdab89;\n    pms->abcd[2] = 0x98badcfe;\n    pms->abcd[3] = 0x10325476;\n}\n\nvoid\nmd5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)\n{\n    const md5_byte_t *p = data;\n    int left = nbytes;\n    int offset = (pms->count[0] >> 3) & 63;\n    md5_word_t nbits = (md5_word_t)(nbytes << 3);\n\n    if (nbytes <= 0)\n\treturn;\n\n    /* Update the message length. */\n    pms->count[1] += nbytes >> 29;\n    pms->count[0] += nbits;\n    if (pms->count[0] < nbits)\n\tpms->count[1]++;\n\n    /* Process an initial partial block. */\n    if (offset) {\n\tint copy = (offset + nbytes > 64 ? 64 - offset : nbytes);\n\n\tmemcpy(pms->buf + offset, p, copy);\n\tif (offset + copy < 64)\n\t    return;\n\tp += copy;\n\tleft -= copy;\n\tmd5_process(pms, pms->buf);\n    }\n\n    /* Process full blocks. */\n    for (; left >= 64; p += 64, left -= 64)\n\tmd5_process(pms, p);\n\n    /* Process a final partial block. */\n    if (left)\n\tmemcpy(pms->buf, p, left);\n}\n\nvoid\nmd5_finish(md5_state_t *pms, md5_byte_t digest[16])\n{\n    static const md5_byte_t pad[64] = {\n\t0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n\t0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n\t0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n\t0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\n    };\n    md5_byte_t data[8];\n    int i;\n\n    /* Save the length before padding. */\n    for (i = 0; i < 8; ++i)\n\tdata[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));\n    /* Pad to 56 bytes mod 64. */\n    md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);\n    /* Append the length. */\n    md5_append(pms, data, 8);\n    for (i = 0; i < 16; ++i)\n\tdigest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));\n}\n"
  },
  {
    "path": "src/crcalc/md5.h",
    "content": "/*\n * Added md5_string function prototype for ease of use with Binwalk.\n * \n * Original file obtained from: http://cr.yp.to/2004-494/gaim/0.81-src/md5.h\n *\n * Craig Heffner\n */\n\n/*\n  Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.\n\n  This software is provided 'as-is', without any express or implied\n  warranty.  In no event will the authors be held liable for any damages\n  arising from the use of this software.\n\n  Permission is granted to anyone to use this software for any purpose,\n  including commercial applications, and to alter it and redistribute it\n  freely, subject to the following restrictions:\n\n  1. The origin of this software must not be misrepresented; you must not\n     claim that you wrote the original software. If you use this software\n     in a product, an acknowledgment in the product documentation would be\n     appreciated but is not required.\n  2. Altered source versions must be plainly marked as such, and must not be\n     misrepresented as being the original software.\n  3. This notice may not be removed or altered from any source distribution.\n\n  L. Peter Deutsch\n  ghost@aladdin.com\n\n */\n/*\n  Independent implementation of MD5 (RFC 1321).\n\n  This code implements the MD5 Algorithm defined in RFC 1321.\n  It is derived directly from the text of the RFC and not from the\n  reference implementation.\n\n  The original and principal author of md5.h is L. Peter Deutsch\n  <ghost@aladdin.com>.  Other authors are noted in the change history\n  that follows (in reverse chronological order):\n\n  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.\n  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);\n\tadded conditionalization for C++ compilation from Martin\n\tPurschke <purschke@bnl.gov>.\n  1999-05-03 lpd Original version.\n */\n\n#ifndef md5_INCLUDED\n#  define md5_INCLUDED\n\n/*\n * This code has some adaptations for the Ghostscript environment, but it\n * will compile and run correctly in any environment with 8-bit chars and\n * 32-bit ints.  Specifically, it assumes that if the following are\n * defined, they have the same meaning as in Ghostscript: P1, P2, P3,\n * ARCH_IS_BIG_ENDIAN.\n */\n\n#include <stdlib.h>\n\ntypedef unsigned char md5_byte_t; /* 8-bit byte */\ntypedef unsigned int md5_word_t; /* 32-bit word */\n\n/* Define the state of the MD5 Algorithm. */\ntypedef struct md5_state_s {\n    md5_word_t count[2];\t/* message length in bits, lsw first */\n    md5_word_t abcd[4];\t\t/* digest buffer */\n    md5_byte_t buf[64];\t\t/* accumulate block */\n} md5_state_t;\n\n#ifdef __cplusplus\nextern \"C\" \n{\n#endif\n\n/* Initialize the algorithm. */\n#ifdef P1\nvoid md5_init(P1(md5_state_t *pms));\n#else\nvoid md5_init(md5_state_t *pms);\n#endif\n\n/* Append a string to the message. */\n#ifdef P3\nvoid md5_append(P3(md5_state_t *pms, const md5_byte_t *data, int nbytes));\n#else\nvoid md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);\n#endif\n\n/* Finish the message and return the digest. */\n#ifdef P2\nvoid md5_finish(P2(md5_state_t *pms, md5_byte_t digest[16]));\n#else\nvoid md5_finish(md5_state_t *pms, md5_byte_t digest[16]);\n#endif\n\n/* Returns the MD5 checksum string of a given file */\nchar *md5_string(void *data, size_t data_size);\n\n#ifdef __cplusplus\n}  /* end extern \"C\" */\n#endif\n\n#endif /* md5_INCLUDED */\n"
  },
  {
    "path": "src/crcalc/patch.c",
    "content": "#include <string.h>\n#include <arpa/inet.h>\n#include \"patch.h\"\n#include \"crc.h\"\n#include \"md5.h\"\n\n/* Update the CRC for a TRX file */\nint patch_trx(char *buf, size_t size)\n{\n        int retval = 0;\n        struct trx_header *header = NULL;\n\n        header = (struct trx_header *) buf;\n        header->crc32 = 0;\n\n\t/* Sanity check on the header length field */\n\tif(header->len <= size)\n\t{\n        \t/* Checksum is calculated over the image, plus the header offsets (12 bytes into the TRX header) */\n        \theader->crc32 = crc32(buf+12, (header->len-12));\n\n        \tif(header->crc32 != 0)\n        \t{\n        \t        retval = 1;\n        \t}\n\t}\n\n        return retval;\n}\n\n/* Update both CRCs for uImage files */\nint patch_uimage(char *buf, size_t size)\n{\n        int retval = 0;\n\tuint32_t hlen = 0;\n        struct uimage_header *header = NULL;\n\n        header = (struct uimage_header *) buf;\n\thlen = ntohl(header->ih_size);\n\n\tif(hlen <= size)\n\t{\n        \theader->ih_hcrc = 0;\n        \theader->ih_dcrc = 0;\n\n        \theader->ih_dcrc = crc32(buf+sizeof(struct uimage_header), hlen) ^ 0xFFFFFFFFL;\n        \theader->ih_dcrc = htonl(header->ih_dcrc);\n\n        \theader->ih_hcrc = crc32(buf, sizeof(struct uimage_header)) ^ 0xFFFFFFFFL;\n        \theader->ih_hcrc = htonl(header->ih_hcrc);\n\n        \tif(header->ih_dcrc != 0 && header->ih_hcrc != 0)\n        \t{\n        \t        retval = 1;\n        \t}\n\t}\n\n        return retval;\n}\n\n/* Update the MD5 checksum in the DLOB header */\nint patch_dlob(char *buf, size_t size)\n{\n\tmd5_state_t state;\n        md5_byte_t digest[16];\n\tint i = 0, retval = 0;\n\tuint32_t cksum_header_offset = 0, data_size = 0, data_offset = 0;\n\tstruct dlob_header *sig_header = NULL, *cksum_header = NULL;\n\n\tsig_header = (struct dlob_header *) buf;\n\tcksum_header_offset = sizeof(struct dlob_header) + ntohl(sig_header->header_size) + ntohl(sig_header->data_size);\n\t\n\tif(cksum_header_offset < size)\n\t{\n\t\tcksum_header = (struct dlob_header *) (buf + cksum_header_offset);\n\t\tdata_size = ntohl(cksum_header->data_size);\n\t\tdata_offset = cksum_header_offset + sizeof(struct dlob_header) + ntohl(cksum_header->header_size) + DLOB_TYPE_STRING_LENGTH;\n\n\t\tif(data_size < size && (data_size + data_offset) <= size)\n\t\t{\n\t\t\tmd5_init(&state);\n\t\t\tmd5_append(&state, (const md5_byte_t *) (buf + data_offset), data_size);\n\t\t\tmd5_finish(&state, digest);\n\n\t\t\tfor(i=0; i<16; i++)\n\t\t\t{\n\t\t\t\tbuf[cksum_header_offset+sizeof(struct dlob_header)+i] = digest[i];\n\t\t\t}\n\t\t\n\t\t\tretval = 1;\n\t\t}\n\t}\n\t\t\n\treturn retval;\n}\n"
  },
  {
    "path": "src/crcalc/patch.h",
    "content": "#ifndef _PATCH_H_\n#define _PATCH_H_\n\n#include <stdint.h>\n\n#define TRX_MAGIC 0x30524448\nstruct trx_header {\n        uint32_t magic;         /* \"HDR0\" */\n        uint32_t len;           /* Length of file including header */\n        uint32_t crc32;         /* 32-bit CRC from flag_version to end of file */\n        uint32_t flag_version;  /* 0:15 flags, 16:31 version */\n        uint32_t offsets[3];    /* Offsets of partitions from start of header */\n};\n\n/* Magic bytes are compared in *little* endian */\n#define UIMAGE_MAGIC 0x56190527\nstruct uimage_header {\n      uint32_t    ih_magic;             /* Image Header Magic Number  */\n      uint32_t    ih_hcrc;              /* Image Header CRC Checksum  */\n      uint32_t    ih_time;              /* Image Creation Timestamp   */\n      uint32_t    ih_size;              /* Image Data Size            */\n      uint32_t    ih_load;              /* Data      Load  Address    */\n      uint32_t    ih_ep;                /* Entry Point Address        */\n      uint32_t    ih_dcrc;              /* Image Data CRC Checksum    */\n      uint8_t     ih_os;                /* Operating System           */\n      uint8_t     ih_arch;              /* CPU architecture           */\n      uint8_t     ih_type;              /* Image Type                 */\n      uint8_t     ih_comp;              /* Compression Type           */\n      uint8_t     ih_name[32];          /* Image Name                 */\n};\n\n#define DLOB_MAGIC 0x17A4A35E\n#define DLOB_TYPE_STRING_LENGTH 16\nstruct dlob_header {\n\tuint32_t sig_magic;\t\t/* DLOB_MAGIC */\n\tuint32_t header_size;\t\t/* Size of the signature header */\n\tuint32_t data_size;\t\t/* Flags or an ID value maybe? */\n};\n\nint patch_trx(char *buf, size_t size);\nint patch_uimage(char *buf, size_t size);\nint patch_dlob(char *buf, size_t size);\n\n#endif\n"
  },
  {
    "path": "src/firmware-tools/Makefile",
    "content": "CC=gcc\nCFLAGS=-g -Wall\nTARGET=buffalo-enc\n\n$(TARGET): buffalo-enc.o\n\t$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET).c *.o -o $(TARGET)\n\nbuffalo-enc.o:\n\t$(CC) $(CFLAGS) $(LDFLAGS) buffalo-lib.c -c\n\nclean:\n\trm -f buffalo-enc.o buffalo-lib.o $(TARGET)\n\ndistclean: clean\n"
  },
  {
    "path": "src/firmware-tools/add_header.c",
    "content": "/*\n * add_header.c - partially based on OpenWrt's motorola-bin.c\n *\n * Copyright (C) 2008 Imre Kaloz  <kaloz@openwrt.org>\n *                    Gabor Juhos <juhosg@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License,\n * version 2 as published by the Free Software Foundation.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n */\n\n/*\n * The add_header utility used by various vendors preprends the buf\n * image with a header containing a CRC32 value which is generated for the\n * model id + reserved space for CRC32 + buf, then replaces the reserved\n * area with the actual CRC32. This replacement tool mimics this behavior.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stddef.h>\n#include <unistd.h>\n#include <errno.h>\n#include <fcntl.h>\n#include <sys/mman.h>\n#include <string.h>\n#include <netinet/in.h>\n#include <inttypes.h>\n\n#define BPB 8 /* bits/byte */\n\nstatic uint32_t crc32[1<<BPB];\n\nstatic void init_crc32()\n{\n\tconst uint32_t poly = ntohl(0x2083b8ed);\n\tint n;\n\n\tfor (n = 0; n < 1<<BPB; n++) {\n\t\tuint32_t crc = n;\n\t\tint bit;\n\n\t\tfor (bit = 0; bit < BPB; bit++)\n\t\t\tcrc = (crc & 1) ? (poly ^ (crc >> 1)) : (crc >> 1);\n\t\tcrc32[n] = crc;\n\t}\n}\n\nstatic uint32_t crc32buf(unsigned char *buf, size_t len)\n{\n\tuint32_t crc = 0xFFFFFFFF;\n\n\tfor (; len; len--, buf++)\n\t\tcrc = crc32[(uint8_t)crc ^ *buf] ^ (crc >> BPB);\n\treturn ~crc;\n}\n\nstruct header {\n\tunsigned char model[16];\n\tuint32_t crc;\n};\n\nstatic void usage(const char *) __attribute__ (( __noreturn__ ));\n\nstatic void usage(const char *mess)\n{\n\tfprintf(stderr, \"Error: %s\\n\", mess);\n\tfprintf(stderr, \"Usage: add_header model_id input_file output_file\\n\");\n\tfprintf(stderr, \"\\n\");\n\texit(1);\n}\n\nint main(int argc, char **argv)\n{\n\toff_t len;\t\t\t// of original buf\n\toff_t buflen;\t\t\t// of the output file\n\tint fd;\n\tvoid *input_file;\t\t// pointer to the input file (mmmapped)\n\tstruct header header;\n\tunsigned char *buf;\t// pointer to prefix + copy of original buf\n\n\t// verify parameters\n\n\tif (argc != 4)\n\t\tusage(\"wrong number of arguments\");\n\n\t// mmap input_file\n\tif ((fd = open(argv[2], O_RDONLY))  < 0\n\t|| (len = lseek(fd, 0, SEEK_END)) < 0\n\t|| (input_file = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0)) == (void *) (-1)\n\t|| close(fd) < 0)\n\t{\n\t\tfprintf(stderr, \"Error loading file %s: %s\\n\", argv[2], strerror(errno));\n\t\texit(1);\n\t}\n\n\tbuflen = len + sizeof(header);\n\n\tinit_crc32();\n\n\t// copy model name into header\n\tstrncpy(header.model, argv[1], sizeof(header.model));\n\theader.crc = 0;\n\n\t// create a firmware image in memory and copy the input_file to it\n\tbuf = malloc(buflen);\n\tmemcpy(buf, &header, sizeof(header));\n\tmemcpy(&buf[sizeof(header)], input_file, len);\n\n\t// CRC of temporary header + buf\n\theader.crc = htonl(crc32buf(buf, buflen));\n\n\tmemcpy(buf, &header, sizeof(header));\n\n\t// write the buf\n\tif ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0\n\t|| write(fd, buf, buflen) != buflen\n\t|| close(fd) < 0)\n\t{\n\t\tfprintf(stderr, \"Error storing file %s: %s\\n\", argv[3], strerror(errno));\n\t\texit(2);\n \t}\n\n\tfree(buf);\n\n\tmunmap(input_file,len);\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/addpattern.c",
    "content": "/*\n * Copyright (C) 2004  Manuel Novoa III  <mjn3@codepoet.org>\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n */\n\n/* July 29, 2004\n *\n * This is a hacked replacement for the 'addpattern' utility used to\n * create wrt54g .bin firmware files.  It isn't pretty, but it does\n * the job for me.\n *\n * Extensions:\n *  -v allows setting the version string on the command line.\n *  -{0|1} sets the (currently ignored) hw_ver flag in the header\n *      to 0 or 1 respectively.\n */\n\n/* January 12, 2005\n *\n * Modified by rodent at rodent dot za dot net\n * Support added for the new WRT54G v2.2 and WRT54GS v1.1 \"flags\"\n * Without the flags set to 0x7, the above units will refuse to flash.\n *\n * Extensions:\n *  -{0|1|2} sets {0|1} sets hw_ver flag to 0/1. {2} sets hw_ver to 1\n *     and adds the new hardware \"flags\" for the v2.2/v1.1 units\n*/\n\n/* January 1, 2007\n *\n * Modified by juan.i.gonzalez at subdown dot net\n * Support added for the AG241v2  and similar\n *\n * Extensions:\n *  -r #.# adds revision hardware flags. AG241v2 and similar.\n *\n * AG241V2 firmware sets the hw_ver to 0x44.\n *\n * Example: -r 2.0\n *\n * Convert 2.0 to 20 to be an integer, and add 0x30 to skip special ASCII\n * #define HW_Version ((HW_REV * 10) + 0x30)  -> from cyutils.h\n*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n#include <unistd.h>\n#include <sys/stat.h>\n\n/**********************************************************************/\n\n#define CODE_ID\t\t\"U2ND\"\t\t/* from code_pattern.h */\n#define CODE_PATTERN   \"W54S\"\t/* from code_pattern.h */\n#define PBOT_PATTERN   \"PBOT\"\n\n#define CYBERTAN_VERSION\t\"v3.37.2\" /* from cyutils.h */\n\n/* WRT54G v2.2 and WRT54GS v1.1 \"flags\" (from 3.37.32 firmware cyutils.h) */\n#define SUPPORT_4712_CHIP      0x0001\n#define SUPPORT_INTEL_FLASH    0x0002\n#define SUPPORT_5325E_SWITCH   0x0004\n/* (from 3.00.24 firmware cyutils.h) */\n#define SUPPORT_4704_CHIP      0x0008\n#define SUPPORT_5352E_CHIP     0x0010\n\nstruct code_header {\t\t\t/* from cyutils.h */\n\tchar magic[4];\n\tchar res1[4];\t\t\t\t/* for extra magic */\n\tchar fwdate[3];\n\tchar fwvern[3];\n\tchar id[4];\t\t\t\t\t/* U2ND */\n\tchar hw_ver;    \t\t\t/* 0: for 4702, 1: for 4712 -- new in 2.04.3 */\n\n\tunsigned char  sn;\t\t// Serial Number\n\tunsigned char  flags[2];\t/* SUPPORT_ flags new for 3.37.2 (WRT54G v2.2 and WRT54GS v1.1) */\n\tunsigned char  stable[2];\t// The image is stable (for dual image)\n\tunsigned char  try1[2];\t\t// Try to boot image first time (for dual image)\n\tunsigned char  try2[2];\t\t// Try to boot image second time (for dual image)\n\tunsigned char  try3[2];\t\t// Try to boot image third time (for dual_image)\n\tunsigned char  res3[2];\n} ;\n\nstruct board_info {\n\tchar\t*id;\n\tchar\t*pattern;\n\tchar\thw_ver;\n\tchar\tsn;\n\tchar\tflags[2];\n};\n\nstruct board_info boards[] = {\n\t{\n\t\t.id\t\t= \"WRT160NL\",\n\t\t.pattern\t= \"NL16\",\n\t\t.hw_ver\t\t= 0x00,\n\t\t.sn\t\t= 0x0f,\n\t\t.flags\t\t= {0x3f, 0x00},\n\t}, {\n\t\t/* Terminating entry */\n\t\t.id\t= NULL,\n\t}\n};\n\n/**********************************************************************/\n\nvoid usage(void) __attribute__ (( __noreturn__ ));\n\nvoid usage(void)\n{\n\tfprintf(stderr, \"Usage: addpattern [-i trxfile] [-o binfile] [-B board_id] [-p pattern] [-s serial] [-g] [-b] [-v v#.#.#] [-r #.#] [-{0|1|2|4|5}] -h\\n\");\n\texit(EXIT_FAILURE);\n}\n\nstruct board_info *find_board(char *id)\n{\n\tstruct board_info *board;\n\n\tfor (board = boards; board->id != NULL; board++)\n\t\tif (strcasecmp(id, board->id) == 0)\n\t\t\treturn board;\n\n\treturn NULL;\n}\n\nint main(int argc, char **argv)\n{\n\tchar buf[1024];\t/* keep this at 1k or adjust garbage calc below */\n\tstruct code_header *hdr;\n\tFILE *in = stdin;\n\tFILE *out = stdout;\n\tchar *ifn = NULL;\n\tchar *ofn = NULL;\n\tchar *pattern = CODE_PATTERN;\n\tchar *pbotpat = PBOT_PATTERN;\n\tchar *version = CYBERTAN_VERSION;\n\tchar *board_id = NULL;\n\tstruct board_info *board = NULL;\n\tint gflag = 0;\n\tint pbotflag = 0;\n\tint c;\n\tint v0, v1, v2;\n\tsize_t off, n;\n\ttime_t t;\n\tstruct tm *ptm;\n\n\tfprintf(stderr, \"mjn3's addpattern replacement - v0.81\\n\");\n\n\thdr = (struct code_header *) buf;\n\tmemset(hdr, 0, sizeof(struct code_header));\n\n\twhile ((c = getopt(argc, argv, \"i:o:p:s:gbv:01245hr:B:\")) != -1) {\n\t\tswitch (c) {\n\t\t\tcase 'i':\n\t\t\t\tifn = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'o':\n\t\t\t\tofn = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'p':\n\t\t\t\tpattern = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\thdr->sn = (unsigned char) atoi (optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'g':\n\t\t\t\tgflag = 1;\n\t\t\t\tbreak;\n\t\t\tcase 'b':\n\t\t\t\tpbotflag = 1;\n\t\t\t\tbreak;\n\t\t\tcase 'v':\t\t\t/* extension to allow setting version */\n\t\t\t\tversion = optarg;\n\t\t\t\tbreak;\n\t\t\tcase '0':\n\t\t\t\thdr->hw_ver = 0;\n\t\t\t\tbreak;\n\t\t\tcase '1':\n\t\t\t\thdr->hw_ver = 1;\n\t\t\t\tbreak;\n\t\t\tcase '2': \t\t\t/* new 54G v2.2 and 54GS v1.1 flags */\n\t\t\t\thdr->hw_ver = 1;\n\t\t\t\thdr->flags[0] |= SUPPORT_4712_CHIP;\n\t\t\t\thdr->flags[0] |= SUPPORT_INTEL_FLASH;\n\t\t\t\thdr->flags[0] |= SUPPORT_5325E_SWITCH;\n\t\t\t\tbreak;\n\t\t\tcase '4':\n\t\t\t\t/* V4 firmware sets the flags to 0x1f */\n\t\t\t\thdr->hw_ver = 0;\n\t\t\t\thdr->flags[0] = 0x1f;\n\t\t\t\tbreak;\n\t\t\tcase '5':\n\t\t\t\t/* V5 is appended to trxV2 image */\n\t\t\t\thdr->stable[0] = 0x73; // force image to be stable\n\t\t\t\thdr->stable[1] = 0x00;\n\t\t\t\thdr->try1[0]   = 0x74; // force try1 to be set\n\t\t\t\thdr->try1[1]   = 0x00;\n\t\t\t\thdr->try2[0]   = hdr->try2[1]   = 0xFF;\n\t\t\t\thdr->try3[0]   = hdr->try3[1]   = 0xFF;\n\t\t\t\tbreak;\n                        case 'r':\n                                hdr->hw_ver = (char)(atof(optarg)*10)+0x30;\n                                break;\n                        case 'B':\n                                board_id = optarg;\n                                break;\n\n                        case 'h':\n\t\t\tdefault:\n\t\t\t\tusage();\n\t\t}\n\t}\n\n    \tif (optind != argc || optind == 1) {\n\t\tfprintf(stderr, \"illegal arg \\\"%s\\\"\\n\", argv[optind]);\n\t\tusage();\n\t}\n\n\tif (board_id) {\n\t\tboard = find_board(board_id);\n\t\tif (board == NULL) {\n\t\t\tfprintf(stderr, \"unknown board \\\"%s\\\"\\n\", board_id);\n\t\t\tusage();\n\t\t}\n\t\tpattern = board->pattern;\n\t\thdr->hw_ver = board->hw_ver;\n\t\thdr->sn = board->sn;\n\t\thdr->flags[0] = board->flags[0];\n\t\thdr->flags[1] = board->flags[1];\n\t}\n\n\tif (strlen(pattern) != 4) {\n\t\tfprintf(stderr, \"illegal pattern \\\"%s\\\": length != 4\\n\", pattern);\n\t\tusage();\n\t}\n\n\tif (ifn && !(in = fopen(ifn, \"r\"))) {\n\t\tfprintf(stderr, \"can not open \\\"%s\\\" for reading\\n\", ifn);\n\t\tusage();\n\t}\n\n\tif (ofn && !(out = fopen(ofn, \"w\"))) {\n\t\tfprintf(stderr, \"can not open \\\"%s\\\" for writing\\n\", ofn);\n\t\tusage();\n\t}\n\n\tif (time(&t) == (time_t)(-1)) {\n\t\tfprintf(stderr, \"time call failed\\n\");\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tptm = localtime(&t);\n\n\tif (3 != sscanf(version, \"v%d.%d.%d\", &v0, &v1, &v2)) {\n\t\tfprintf(stderr, \"bad version string \\\"%s\\\"\\n\", version);\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tmemcpy(&hdr->magic, pattern, 4);\n\tif (pbotflag)\n\t\tmemcpy(&hdr->res1, pbotpat, 4);\n\thdr->fwdate[0] = ptm->tm_year % 100;\n\thdr->fwdate[1] = ptm->tm_mon + 1;\n\thdr->fwdate[2] = ptm->tm_mday;\n\thdr->fwvern[0] = v0;\n\thdr->fwvern[1] = v1;\n\thdr->fwvern[2] = v2;\n\tmemcpy(&hdr->id, CODE_ID, strlen(CODE_ID));\n\n\toff = sizeof(struct code_header);\n\n\tfprintf(stderr, \"writing firmware v%d.%d.%d on %d/%d/%d (y/m/d)\\n\",\n\t\t\tv0, v1, v2,\n\t\t\thdr->fwdate[0], hdr->fwdate[1], hdr->fwdate[2]);\n\n\n\twhile ((n = fread(buf + off, 1, sizeof(buf)-off, in) + off) > 0) {\n\t\toff = 0;\n\t\tif (n < sizeof(buf)) {\n\t\t\tif (ferror(in)) {\n\t\t\tFREAD_ERROR:\n\t\t\t\tfprintf(stderr, \"fread error\\n\");\n\t\t\t\treturn EXIT_FAILURE;\n\t\t\t}\n\t\t\tif (gflag) {\n\t\t\t\tgflag = sizeof(buf) - n;\n\t\t\t\tmemset(buf + n, 0xff, gflag);\n\t\t\t\tfprintf(stderr, \"adding %d bytes of garbage\\n\", gflag);\n\t\t\t\tn = sizeof(buf);\n\t\t\t}\n\t\t}\n\t\tif (!fwrite(buf, n, 1, out)) {\n\t\tFWRITE_ERROR:\n\t\t\tfprintf(stderr, \"fwrite error\\n\");\n\t\t\treturn EXIT_FAILURE;\n\t\t}\n\t}\n\n\tif (ferror(in)) {\n\t\tgoto FREAD_ERROR;\n\t}\n\n\tif (fflush(out)) {\n\t\tgoto FWRITE_ERROR;\n\t}\n\n\tfclose(in);\n\tfclose(out);\n\n\treturn EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/firmware-tools/airlink.c",
    "content": "/*\n * Thanks to Vassily Galinsky for this tool\n*****************************************************************************\nAIRLINK AR525W firmware image structure\n  -8:-5  Extended (httpd) header checksum  -       sum2\n  -4:-1  Extended (httpd) header magic     -       \"ARRN\" - 0x4e525241\n   0: 3  Standard (tftpd) header magic     -       \"GMTK\" - 0x4b544d47\n   4: 7  Standard (tftpd) header checksum  -       sum1\n   8: b  0\n   c: f  Size of compressed linux kernel\n  10:13  Size of firmware image file with standard header\n  14:17  Product code                      -       0x5\n  18:1b  Bootloader checksum               -       sum0\n  1c:1f  0\n  20:    Compressed linux kernel\n  -      Squashfs or jffs2 file system - kernel dependent - either 32 bytes or sector aligned \n*****************************************************************************/\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <sys/mman.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <netinet/in.h>\n\ntypedef unsigned char uchar;\n\nuint32_t crctab[257] = {\n\t0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,\n\t0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,\n\t0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n\t0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,\n\t0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,\n\t0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n\t0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,\n\t0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,\n\t0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n\t0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,\n\t0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,\n\t0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n\t0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,\n\t0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,\n\t0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n\t0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,\n\t0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,\n\t0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n\t0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,\n\t0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,\n\t0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n\t0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,\n\t0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,\n\t0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n\t0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,\n\t0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,\n\t0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n\t0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,\n\t0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,\n\t0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n\t0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,\n\t0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,\n\t0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n\t0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,\n\t0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,\n\t0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n\t0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,\n\t0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,\n\t0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n\t0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,\n\t0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,\n\t0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n\t0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,\n\t0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,\n\t0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n\t0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,\n\t0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,\n\t0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n\t0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,\n\t0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,\n\t0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n\t0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,\n\t0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,\n\t0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n\t0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,\n\t0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,\n\t0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n\t0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,\n\t0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,\n\t0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n\t0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,\n\t0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,\n\t0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n\t0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,\n\t0\n};\n\nuint32_t header[] = {\n\t0x00000000, 0x4e525241,\n\t0x4b544d47, 0x00000000, 0x00000000, 0x000afd4a,\n\t0x00000000, 0x00000005, 0x00000000, 0x00000000\n};\n\nstatic int JFFS2 = 0;\n\nint generate_image(char *kname, char *fsname, char *fname, int EHDR)\n{\n\tint i;\n\tuint32_t lenk, lens;\n\tuchar *bk, *bs;\n\tint fkd, ffd, fsd;\n\tfkd = open(kname, O_RDONLY);\n\tffd = creat(fname, 0644);\n\tif ((fkd < 0) || (ffd < 0))\n\t\treturn -1;\n\tif (fsname) {\n\t\tfsd = open(fsname, O_RDONLY);\n\t\tif (fsd < 0)\n\t\t\treturn -1;\n\t}\n\tlenk = lseek(fkd, 0, SEEK_END);\n\theader[5] = lenk;\n\tbk = (uchar *) mmap(NULL, lenk, PROT_READ, MAP_SHARED, fkd, 0);\n\tif (bk == MAP_FAILED)\n\t\treturn -1;\n\tif (fsname) {\n\t\tlens = lseek(fsd, 0, SEEK_END);\n\t\tbs = (uchar *) mmap(NULL, lens, PROT_READ, MAP_SHARED, fsd,\n\t\t\t\t    0);\n\t\tif (bs == MAP_FAILED)\n\t\t\treturn -1;\n\t}\n\tif (EHDR)\n\t\twrite(ffd, header, 0x28);\n\telse\n\t\twrite(ffd, header + 2, 0x20);\n\twrite(ffd, bk, lenk);\n\tlenk += 0x20;\n\tif (!JFFS2) JFFS2 = 0x20;\n\tprintf(\"Padding header+kernel - 0x%x +  0x%x = 0x%x\\n\",\n\t       lenk, ((lenk - 1 + JFFS2) / JFFS2) * JFFS2 - lenk,\n\t       ((lenk - 1 + JFFS2) / JFFS2) * JFFS2);\n\tfor (i = 0; i < ((lenk - 1 + JFFS2) / JFFS2) * JFFS2 - lenk; i++)\n\t\twrite(ffd, header, 1);\n\tif (fsname) {\n\t\twrite(ffd, bs, lens);\n\t\tclose(fsd);\n\t}\n\tclose(ffd);\n\tclose(fkd);\n\treturn 0;\n}\n\nuint32_t crc32(uchar * buf, uint32_t len)\n{\n\tregister int i;\n\tuint32_t sum;\n\tregister uint32_t s0;\n\ts0 = ~0;\n\tfor (i = 0; i < len; i++) {\n\t\ts0 = (s0 >> 8) ^ crctab[(uchar) (s0 & 0xFF) ^ buf[i]];\n\t}\n\tsum = ~s0;\n\treturn sum;\n}\n\nvoid usage(char *prog)\n{\n\tprintf(\"Usage: %s [-b 0/1] image_filename \\n\", prog);\n\tprintf(\"       update checksums for firmware file\\n\");\n\tprintf\n\t    (\"Usage: %s [-b 0/1] [-j erasesize_in_kibytes] [-e] kernel filesystem image_filename \\n\",\n\t     prog);\n\tprintf(\"       generate firmware file and update checksums\\n\");\n\tprintf(\"--------------------------------------------------\\n\");\n\tprintf(\"       -e - generate header for web upload\\n\");\n\tprintf(\"       -b 0/1 - clear/update bootloader checksum\\n\");\n\tprintf(\"       -j erasesize_in_kibytes - generate header for jffs2 filesystem\\n\");\n}\n\nint main(int argc, char **argv)\n{\n\tuchar b[0x400];\n\tchar EHDR = 0;\n\tchar BHDR = 0;\n\tint c, fd;\n\textern char *optarg;\n\textern int optind, optopt;\n\n\twhile ((c = getopt(argc, argv, \"b:ej:\")) != -1) {\n\t\tswitch (c) {\n\t\tcase 'b':\n\t\t\tif (optarg[0] == '1')\n\t\t\t\tBHDR = 1;\n\t\t\tbreak;\n\t\tcase 'e':\n\t\t\tEHDR = 1;\n\t\t\tbreak;\n\t\tcase 'j':\n\t\t\tsscanf(optarg, \"%i\", &JFFS2);\n\t\t\tJFFS2 *= 1024;\n\t\t\tbreak;\n\t\tcase '?':\n\t\t\tfprintf(stderr, \"\\nError: unknown arg %c\\n\\n\\n\",\n\t\t\t\toptopt);\n\t\t\tusage(argv[0]);\n\t\t\texit(-1);\n\t\t}\n\t}\n\tif (((argc - optind) < 1) && ((argc - optind) > 3)) {\n\t\tusage(argv[0]);\n\t\texit(-1);\n\t}\n\tif ((argc - optind) == 3)\n\t\tif (generate_image\n\t\t    (argv[optind], argv[optind + 1], argv[optind + 2],\n\t\t     EHDR)) {\n\t\t\tfprintf(stderr,\n\t\t\t\t\"\\nError generating image file %s\\n\\n\\n\",\n\t\t\t\targv[argc - 1]);\n\t\t\tusage(argv[0]);\n\t\t\texit(-1);\n\t\t}\n\tif ((argc - optind) == 2)\n\t\tif (generate_image\n\t\t    (argv[optind], NULL, argv[optind + 1], EHDR)) {\n\t\t\tfprintf(stderr,\n\t\t\t\t\"\\nError generating image file %s\\n\\n\\n\",\n\t\t\t\targv[argc - 1]);\n\t\t\tusage(argv[0]);\n\t\t\texit(-1);\n\t\t}\n\n\tfd = open(argv[argc - 1], O_RDWR);\n\tif (fd < 0) {\n\t\tfprintf(stderr, \"\\nImage file not found %s\\n\\n\\n\",\n\t\t\targv[argc - 1]);\n\t\tusage(argv[0]);\n\t\texit(-1);\n\t}\n\tlong i, len = lseek(fd, 0, SEEK_END);\n\tlseek(fd, 0, SEEK_SET);\n\tuchar *buf = malloc(len);\n\tread(fd, buf, len);\n\tuint32_t sum, l0;\n\tuint32_t MagicS = 0x474d544b;\n\tuint32_t MagicE = 0x4152524e;\n\tif (ntohl(*((uint32_t *) buf)) == MagicS) {\n\t\tfprintf(stderr,\n\t\t\t\"Image without extra 8 bytes - Standard header\\n\");\n\t\tbuf[0x10] = len & 0xff;\n\t\tbuf[0x11] = (len >> 8) & 0xff;\n\t\tbuf[0x12] = (len >> 16) & 0xff;\n\t\tbuf[0x13] = (len >> 24) & 0xff;\n\t\tlseek(fd, 0x10, SEEK_SET);\n\t\twrite(fd, buf + 0x10, 0x4);\n\t\tEHDR = 0;\n\t} else if ((ntohl(*((uint32_t *) (buf + 0x8))) == MagicS)\n\t\t   && ((ntohl(*((uint32_t *) (buf + 0x4))) == MagicE))) {\n\t\tfprintf(stderr,\n\t\t\t\"Image with extra 8 bytes - Extended header\\n\");\n\t\t*((uint32_t *) (buf + 0x18)) = len - 8;\n\t\tbuf[0x18] = (len - 8) & 0xff;\n\t\tbuf[0x19] = ((len - 8) >> 8) & 0xff;\n\t\tbuf[0x1a] = ((len - 8) >> 16) & 0xff;\n\t\tbuf[0x1b] = ((len - 8) >> 24) & 0xff;\n\t\tlseek(fd, 0x18, SEEK_SET);\n\t\twrite(fd, buf + 0x18, 0x4);\n\t\tbuf += 8;\n\t\tEHDR = 1;\n\t} else if (len == buf[0x10] | ((uint32_t)buf[0x11] << 8) | ((uint32_t)buf[0x12] << 16) | ((uint32_t)buf[0x13] << 24)) {\n\t\tfprintf(stderr,\n\t\t\t\"Image without extra 8 bytes - Standard header\\n\");\n\t\tEHDR = 0;\n\t} else if (len == (buf[0x18] | ((uint32_t)buf[0x19] << 8) | ((uint32_t)buf[0x1a] << 16) | ((uint32_t)buf[0x1b] << 24)) + 8) {\n\t\tfprintf(stderr,\n\t\t\t\"Image with extra 8 bytes - Extended header\\n\");\n\t\tbuf += 8;\n\t\tEHDR = 1;\n\t} else {\n\t\tfprintf(stderr, \"ERROR: Wrong image size\\n\");\n\t\texit(-1);\n\t}\n\tl0 = buf[0x10] | ((uint32_t)buf[0x11] << 8) | ((uint32_t)buf[0x12] << 16) | ((uint32_t)buf[0x13] << 24);\n\tif (!BHDR)\n\t\t*((uint32_t *) & buf[0x18]) = 0;\n\tunsigned long sum0 = buf[0x18] | ((uint32_t)buf[0x19] << 8) | ((uint32_t)buf[0x1a] << 16) | ((uint32_t)buf[0x1b] << 24);\n\tunsigned long sum1 = buf[0x4] | ((uint32_t)buf[0x5] << 8) | ((uint32_t)buf[0x6] << 16) | ((uint32_t)buf[0x7] << 24);\n\t*((uint32_t *) & buf[0x4]) = 0x0L;\n\tmemcpy(b, buf, 0x100);\n\tmemcpy(b + 0x100, buf + ((l0 >> 1) - ((l0 & 0x6) >> 1)), 0x100);\n\tmemcpy(b + 0x200, buf + (l0 - 0x200), 0x200);\n\t*((uint32_t *) & b[0x18]) = 0x0L;\n\n\tsum = crc32(b, 0x400);\n\tprintf(\"CRC32 sum0 - (%x, %x, %x)\\n\", sum, sum0, 0x400);\n\tif (EHDR)\n\t\tlseek(fd, 0x20, SEEK_SET);\n\telse\n\t\tlseek(fd, 0x18, SEEK_SET);\n\tbuf[0x18] = (BHDR ? sum : sum0) & 0xff;\n\tbuf[0x19] = ((BHDR ? sum : sum0) >> 8) & 0xff;\n\tbuf[0x1a] = ((BHDR ? sum : sum0) >> 16) & 0xff;\n\tbuf[0x1b] = ((BHDR ? sum : sum0) >> 24) & 0xff;\n\twrite(fd, &buf[0x18], 0x4);\n\n\tsum = crc32(buf, l0);\n\tprintf(\"CRC32 sum1 - (%x, %x, %x)\\n\", sum, sum1, l0);\n\tif (EHDR)\n\t\tlseek(fd, 0xC, SEEK_SET);\n\telse\n\t\tlseek(fd, 0x4, SEEK_SET);\n\tbuf[0x4] = sum & 0xff;\n\tbuf[0x5] = (sum >> 8) & 0xff;\n\tbuf[0x6] = (sum >> 16) & 0xff;\n\tbuf[0x7] = (sum >> 24) & 0xff;\n\twrite(fd, &buf[0x4], 0x4);\n\tif (EHDR) {\n\t\tunsigned long sum2 = buf[-0x8] | ((uint32_t)buf[-0x7] << 8) | ((uint32_t)buf[-0x6] << 16) | ((uint32_t)buf[-0x5] << 24);\n\t\t*((uint32_t *) & buf[-0x8]) = 0L;\n\t\tsum = crc32(buf - 0x4, len - 0x4);\n\t\tprintf(\"CRC32 sum2 - (%x, %x, %x)\\n\", sum, sum2,\n\t\t       len - 0x4);\n\t\tlseek(fd, 0, SEEK_SET);\n\t\t*((uint32_t *) & buf[-0x8]) = htonl(sum);\n\t\twrite(fd, &buf[-0x8], 0x4);\n\t\tbuf -= 8;\n\t}\n\tclose(fd);\n\tfree(buf);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/bcm_tag.h",
    "content": "#ifndef __BCM63XX_TAG_H\n#define __BCM63XX_TAG_H\n\n#define TAGVER_LEN 4                   /* Length of Tag Version */\n#define TAGLAYOUT_LEN 4                /* Length of FlashLayoutVer */\n#define SIG1_LEN 20\t\t       /* Company Signature 1 Length */\n#define SIG2_LEN 14                    /* Company Signature 2 Lenght */\n#define BOARDID_LEN 16\t\t       /* Length of BoardId */\n#define ENDIANFLAG_LEN 2               /* Endian Flag Length */\n#define CHIPID_LEN 6\t\t       /* Chip Id Length */\n#define IMAGE_LEN 10                   /* Length of Length Field */\n#define ADDRESS_LEN 12                 /* Length of Address field */\n#define DUALFLAG_LEN 2\t\t       /* Dual Image flag Length */\n#define INACTIVEFLAG_LEN 2\t       /* Inactie Flag Length */\n#define RSASIG_LEN 20   \t       /* Length of RSA Signature in tag */\n#define TAGINFO1_LEN 30                /* Length of vendor information field1 in tag */\n#define FLASHLAYOUTVER_LEN 4\t       /* Length of Flash Layout Version String tag */\n#define TAGINFO2_LEN 16                /* Length of vendor information field2 in tag */\n#define CRC_LEN 4                      /* Length of CRC in bytes */\n#define ALTTAGINFO_LEN 54              /* Alternate length for vendor information; Pirelli */\n\n#define NUM_PIRELLI 2\n#define IMAGETAG_CRC_START\t\t0xFFFFFFFF\n\n#define PIRELLI_BOARDS { \\\n  \"AGPF-S0\", \\\n  \"DWV-S0\", \\\n}\n\n/*\n * The broadcom firmware assumes the rootfs starts the image,\n * therefore uses the rootfs start (flashImageAddress)\n * to determine where to flash the image.  Since we have the kernel first\n * we have to give it the kernel address, but the crc uses the length\n * associated with this address (rootLength), which is added to the kernel\n * length (kernelLength) to determine the length of image to flash and thus\n * needs to be rootfs + deadcode (jffs2 EOF marker)\n*/\n\nstruct bcm_tag {\n\tchar tagVersion[TAGVER_LEN];           // 0-3: Version of the image tag\n\tchar sig_1[SIG1_LEN];                  // 4-23: Company Line 1\n\tchar sig_2[SIG2_LEN];                  // 24-37: Company Line 2\n\tchar chipid[CHIPID_LEN];               // 38-43: Chip this image is for\n\tchar boardid[BOARDID_LEN];             // 44-59: Board name\n\tchar big_endian[ENDIANFLAG_LEN];       // 60-61: Map endianness -- 1 BE 0 LE\n\tchar totalLength[IMAGE_LEN];           // 62-71: Total length of image\n\tchar cfeAddress[ADDRESS_LEN];          // 72-83: Address in memory of CFE\n\tchar cfeLength[IMAGE_LEN];             // 84-93: Size of CFE\n\tchar flashImageStart[ADDRESS_LEN];     // 94-105: Address in memory of image start (kernel for OpenWRT, rootfs for stock firmware)\n\tchar flashRootLength[IMAGE_LEN];            // 106-115: Size of rootfs for flashing\n\tchar kernelAddress[ADDRESS_LEN];       // 116-127: Address in memory of kernel\n\tchar kernelLength[IMAGE_LEN];          // 128-137: Size of kernel\n\tchar dualImage[DUALFLAG_LEN];          // 138-139: Unused at present\n\tchar inactiveFlag[INACTIVEFLAG_LEN];   // 140-141: Unused at present\n        char rsa_signature[RSASIG_LEN];        // 142-161: RSA Signature (unused at present; some vendors may use this)\n\tchar information1[TAGINFO1_LEN];       // 162-191: Compilation and related information (not generated/used by OpenWRT)\n        char flashLayoutVer[FLASHLAYOUTVER_LEN];// 192-195: Version flash layout\n        char fskernelCRC[CRC_LEN];             // 196-199: kernel+rootfs CRC32\n\tchar information2[TAGINFO2_LEN];       // 200-215: Unused at present except Alice Gate where is is information\n\tchar imageCRC[CRC_LEN];                // 216-219: CRC32 of image less imagetag (kernel for Alice Gate)\n        char rootfsCRC[CRC_LEN];               // 220-223: CRC32 of rootfs partition\n        char kernelCRC[CRC_LEN];               // 224-227: CRC32 of kernel partition\n        char imageSequence[4];\t\t       // 228-231: Image sequence number\n        char rootLength[4];                    // 232-235: steal from reserved1 to keep the real root length so we can use in the flash map even after we have change the rootLength to 0 to satisfy devices that check CRC on every boot\n        char headerCRC[CRC_LEN];               // 236-239: CRC32 of header excluding tagVersion\n        char reserved2[16];                    // 240-255: Unused at present\n};\n\n#endif /* __BCM63XX_TAG_H */\n"
  },
  {
    "path": "src/firmware-tools/buffalo-enc.c",
    "content": "/*\n * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License version 2 as published\n * by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n\n#include \"buffalo-lib.h\"\n\n#define ERR(fmt, args...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## args ); \\\n} while (0)\n\nstatic char *progname;\nstatic char *ifname;\nstatic char *ofname;\nstatic char *crypt_key = \"Buffalo\";\nstatic char *magic = \"start\";\nstatic int longstate;\nstatic unsigned char seed = 'O';\n\nstatic char *product;\nstatic char *version;\nstatic int do_decrypt;\n\nvoid usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -d              decrypt instead of encrypt\\n\"\n\"  -i <file>       read input from the file <file>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -l              use longstate {en,de}cryption method\\n\"\n\"  -k <key>        use <key> for encryption (default: Buffalo)\\n\"\n\"  -m <magic>      set magic to <magic>\\n\"\n\"  -p <product>    set product name to <product>\\n\"\n\"  -v <version>    set version to <version>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nstatic int decrypt_file(void)\n{\n\tstruct enc_param ep;\n\tssize_t src_len;\n\tunsigned char *buf = NULL;\n\tint err;\n\tint ret = -1;\n\n\tsrc_len = get_file_size(ifname);\n\tif (src_len < 0) {\n\t\tERR(\"unable to get size of '%s'\", ifname);\n\t\tgoto out;\n\t}\n\n\tbuf = malloc(src_len);\n\tif (buf == NULL) {\n\t\tERR(\"no memory for the buffer\");\n\t\tgoto out;\n\t}\n\n\terr = read_file_to_buf(ifname, buf, src_len);\n\tif (err) {\n\t\tERR(\"unable to read from file '%s'\", ifname);\n\t\tgoto out;\n\t}\n\n\tmemset(&ep, '\\0', sizeof(ep));\n\tep.key = (unsigned char *) crypt_key;\n\n\terr = decrypt_buf(&ep, buf, src_len);\n\tif (err) {\n\t\tERR(\"unable to decrypt '%s'\", ifname);\n\t\tgoto out;\n\t}\n\n\tprintf(\"Magic\\t\\t: '%s'\\n\", ep.magic);\n\tprintf(\"Seed\\t\\t: 0x%02x\\n\", ep.seed);\n\tprintf(\"Product\\t\\t: '%s'\\n\", ep.product);\n\tprintf(\"Version\\t\\t: '%s'\\n\", ep.version);\n\tprintf(\"Data len\\t: %u\\n\", ep.datalen);\n\tprintf(\"Checksum\\t: 0x%08x\\n\", ep.csum);\n\n\terr = write_buf_to_file(ofname, buf, ep.datalen);\n\tif (err) {\n\t\tERR(\"unable to write to file '%s'\", ofname);\n\t\tgoto out;\n\t}\n\n\tret = 0;\n\nout:\n\tfree(buf);\n\treturn ret;\n}\n\nstatic int encrypt_file(void)\n{\n\tstruct enc_param ep;\n\tssize_t src_len;\n\tunsigned char *buf;\n\tuint32_t hdrlen;\n\tssize_t totlen = 0;\n\tint err;\n\tint ret = -1;\n\n\tsrc_len = get_file_size(ifname);\n\tif (src_len < 0) {\n\t\tERR(\"unable to get size of '%s'\", ifname);\n\t\tgoto out;\n\t}\n\n\ttotlen = enc_compute_buf_len(product, version, src_len);\n\thdrlen = enc_compute_header_len(product, version);\n\n\tbuf = malloc(totlen);\n\tif (buf == NULL) {\n\t\tERR(\"no memory for the buffer\");\n\t\tgoto out;\n\t}\n\n\terr = read_file_to_buf(ifname, &buf[hdrlen], src_len);\n\tif (err) {\n\t\tERR(\"unable to read from file '%s'\", ofname);\n\t\tgoto free_buf;\n\t}\n\n\tmemset(&ep, '\\0', sizeof(ep));\n\tep.key = (unsigned char *) crypt_key;\n\tep.seed = seed;\n\tep.longstate = longstate;\n\tep.csum = buffalo_csum(src_len, &buf[hdrlen], src_len);\n\tep.datalen = src_len;\n\tstrcpy((char *) ep.magic, magic);\n\tstrcpy((char *) ep.product, product);\n\tstrcpy((char *) ep.version, version);\n\n\terr = encrypt_buf(&ep, buf, &buf[hdrlen]);\n\tif (err) {\n\t\tERR(\"invalid input file\");\n\t\tgoto free_buf;\n\t}\n\n\terr = write_buf_to_file(ofname, buf, totlen);\n\tif (err) {\n\t\tERR(\"unable to write to file '%s'\", ofname);\n\t\tgoto free_buf;\n\t}\n\n\tret = 0;\n\nfree_buf:\n \tfree(buf);\nout:\n \treturn ret;\n}\n\nstatic int check_params(void)\n{\n\tint ret = -1;\n\n\tif (ifname == NULL) {\n\t\tERR(\"no input file specified\");\n\t\tgoto out;\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\tgoto out;\n\t}\n\n\tif (crypt_key == NULL) {\n\t\tERR(\"no key specified\");\n\t\tgoto out;\n\t} else if (strlen(crypt_key) > BCRYPT_MAX_KEYLEN) {\n\t\tERR(\"key '%s' is too long\", crypt_key);\n\t\tgoto out;\n\t}\n\n\tif (strlen(magic) != (ENC_MAGIC_LEN - 1)) {\n\t\tERR(\"length of magic must be %d\", ENC_MAGIC_LEN - 1);\n\t\tgoto out;\n\t}\n\n\tif (!do_decrypt) {\n\t\tif (product == NULL) {\n\t\t\tERR(\"no product specified\");\n\t\t\tgoto out;\n\t\t}\n\n\t\tif (version == NULL) {\n\t\t\tERR(\"no version specified\");\n\t\t\tgoto out;\n\t\t}\n\n\t\tif (strlen(product) > (ENC_PRODUCT_LEN - 1)) {\n\t\t\tERR(\"product name '%s' is too long\", product);\n\t\t\tgoto out;\n\t\t}\n\n\t\tif (strlen(version) > (ENC_VERSION_LEN - 1)) {\n\t\t\tERR(\"version '%s' is too long\", version);\n\t\t\tgoto out;\n\t\t}\n\t}\n\n\tret = 0;\n\nout:\n\treturn ret;\n}\n\nint main(int argc, char *argv[])\n{\n\tint res = EXIT_FAILURE;\n\tint err;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"adi:m:o:hp:v:k:r:s:\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'd':\n\t\t\tdo_decrypt = 1;\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tifname = optarg;\n\t\t\tbreak;\n\t\tcase 'l':\n\t\t\tlongstate = 1;\n\t\t\tbreak;\n\t\tcase 'm':\n\t\t\tmagic = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'p':\n\t\t\tproduct = optarg;\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tversion = optarg;\n\t\t\tbreak;\n\t\tcase 'k':\n\t\t\tcrypt_key = optarg;\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\tseed = strtoul(optarg, NULL, 16);\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\terr = check_params();\n\tif (err)\n\t\tgoto out;\n\n\tif (do_decrypt)\n\t\terr = decrypt_file();\n\telse\n\t\terr = encrypt_file();\n\n\tif (err)\n\t\tgoto out;\n\n\tres = EXIT_SUCCESS;\n\nout:\n\treturn res;\n}\n"
  },
  {
    "path": "src/firmware-tools/buffalo-lib.c",
    "content": "/*\n * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License version 2 as published\n * by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <unistd.h>\n#include <sys/stat.h>\n\n#include \"buffalo-lib.h\"\n\nstatic uint32_t crc32_table[256] =\n{\n\t0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,\n\t0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,\n\t0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,\n\t0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,\n\t0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,\n\t0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,\n\t0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011,\n\t0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,\n\t0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,\n\t0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,\n\t0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,\n\t0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,\n\t0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49,\n\t0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,\n\t0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,\n\t0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,\n\t0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,\n\t0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,\n\t0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,\n\t0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,\n\t0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,\n\t0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,\n\t0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,\n\t0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,\n\t0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e,\n\t0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,\n\t0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,\n\t0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,\n\t0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,\n\t0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,\n\t0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686,\n\t0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,\n\t0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,\n\t0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,\n\t0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,\n\t0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,\n\t0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47,\n\t0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,\n\t0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,\n\t0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,\n\t0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,\n\t0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,\n\t0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f,\n\t0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,\n\t0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,\n\t0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,\n\t0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,\n\t0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,\n\t0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,\n\t0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,\n\t0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,\n\t0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,\n\t0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,\n\t0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,\n\t0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088,\n\t0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,\n\t0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,\n\t0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,\n\t0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,\n\t0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,\n\t0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0,\n\t0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,\n\t0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,\n\t0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4\n};\n\nint bcrypt_init(struct bcrypt_ctx *ctx, void *key, int keylen,\n\t\tunsigned long state_len)\n{\n\tunsigned char *state;\n\tunsigned char *p = key;\n\tunsigned long i, j;\n\tunsigned long k = 0;\n\n\tstate = malloc(state_len);\n\tif (state == NULL)\n\t\treturn -1;\n\n\tctx->i = 0;\n\tctx->j = 0;\n\tctx->state = state;\n\tctx->state_len = state_len;\n\n\tfor (i = 0; i < state_len; i++)\n\t\tstate[i] = i;\n\n\tfor(i = 0, j = 0; i < state_len; i++, j = (j + 1) % keylen) {\n\t\tunsigned char t;\n\n\t\tt = state[i];\n\t\tk = (k + p[j] + t) % state_len;\n\t\tstate[i] = state[k];\n\t\tstate[k] = t;\n\t}\n\n\treturn 0;\n}\n\nint bcrypt_process(struct bcrypt_ctx *ctx, unsigned char *src,\n\t\t   unsigned char *dst, unsigned long len)\n{\n\tunsigned char *state = ctx->state;\n\tunsigned long state_len = ctx->state_len;\n\tunsigned char i, j;\n\tunsigned long k;\n\n\ti = ctx->i;\n\tj = ctx->j;\n\n\tfor (k = 0; k < len; k++) {\n\t\tunsigned char t;\n\n\t\ti = (i + 1) % state_len;\n\t\tj = (j + state[i]) % state_len;\n\t\tt = state[j];\n\t\tstate[j] = state[i];\n\t\tstate[i] = t;\n\n\t\tdst[k] = src[k] ^ state[(state[i] + state[j]) % state_len];\n\t}\n\n\tctx->i = i;\n\tctx->j = j;\n\n\treturn len;\n}\n\nvoid bcrypt_finish(struct bcrypt_ctx *ctx)\n{\n\tif (ctx->state)\n\t\tfree(ctx->state);\n}\n\nint bcrypt_buf(unsigned char seed, unsigned char *key, unsigned char *src,\n\t       unsigned char *dst, unsigned long len, int longstate)\n{\n\tunsigned char bckey[BCRYPT_MAX_KEYLEN + 1];\n\tunsigned int keylen;\n\tstruct bcrypt_ctx ctx;\n\tint ret;\n\n\t/* setup decryption key */\n\tkeylen = strlen((char *) key);\n\tbckey[0] = seed;\n\tmemcpy(&bckey[1], key, keylen);\n\n\tkeylen++;\n\n\tret = bcrypt_init(&ctx, bckey, keylen,\n\t\t\t  (longstate) ? len : BCRYPT_DEFAULT_STATE_LEN);\n\tif (ret)\n\t\treturn ret;\n\n\tbcrypt_process(&ctx, src, dst, len);\n\tbcrypt_finish(&ctx);\n\n\treturn 0;\n}\n\nuint32_t buffalo_csum(uint32_t csum, void *buf, unsigned long len)\n{\n\tchar *p = buf;\n\n\twhile (len--) {\n\t\tint i;\n\n\t\tcsum ^= *p++;\n\t\tfor (i = 0; i < 8; i++)\n\t\t\tcsum = (csum >> 1) ^ ((csum & 1) ? 0xedb88320ul : 0);\n\t}\n\n\treturn csum;\n}\n\nuint32_t buffalo_crc(void *buf, unsigned long len)\n{\n\tunsigned char *p = buf;\n\tunsigned long t = len;\n\tuint32_t crc = 0;\n\n\twhile (len--)\n\t\tcrc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *p++) & 0xFF];\n\n\twhile (t) {\n\t\tcrc = (crc << 8) ^ crc32_table[((crc >> 24) ^ t) & 0xFF];\n\t\tt >>= 8;\n\t}\n\n\treturn ~crc;\n}\n\nunsigned long enc_compute_header_len(char *product, char *version)\n{\n\treturn ENC_MAGIC_LEN + 1 + strlen(product) + 1 +\n\t       strlen(version) + 1 + 3 * sizeof(uint32_t);\n}\n\nunsigned long enc_compute_buf_len(char *product, char *version,\n\t\t\t\t  unsigned long datalen)\n{\n\tunsigned long ret;\n\n\tret = enc_compute_header_len(product, version);\n\tret += datalen + sizeof(uint32_t);\n\tret += (4 - ret % 4);\n\n\treturn ret;\n}\n\nstatic void put_be32(void *data, uint32_t val)\n{\n\tunsigned char *p = data;\n\n\tp[0] = (val >> 24) & 0xff;\n\tp[1] = (val >> 16) & 0xff;\n\tp[2] = (val >> 8) & 0xff;\n\tp[3] = val & 0xff;\n}\n\nstatic uint32_t get_be32(void *data)\n{\n\tunsigned char *p = data;\n\n\treturn (((uint32_t)p[0]) << 24) |\n\t       (((uint32_t)p[1]) << 16) |\n\t       (((uint32_t)p[2]) << 8) |\n\t       ((uint32_t)p[3]);\n}\n\nstatic int check_magic(void *magic)\n{\n\tif (!memcmp(\"start\", magic, ENC_MAGIC_LEN));\n\t\treturn 0;\n\n\tif (!memcmp(\"asar1\", magic, ENC_MAGIC_LEN));\n\t\treturn 0;\n\n\treturn -1;\n}\n\nint encrypt_buf(struct enc_param *ep, unsigned char *hdr,\n\t\tunsigned char *data)\n{\n\tunsigned char *p;\n\tuint32_t len;\n\tint err;\n\tint ret = -1;\n\tunsigned char s;\n\n\tp = (unsigned char *) hdr;\n\n\t/* setup magic */\n\tlen = strlen((char *) ep->magic) + 1;\n\tmemcpy(p, ep->magic, len);\n\tp += len;\n\n\t/* setup seed */\n\t*p++ = ep->seed;\n\n\t/* put product len */\n\tlen = strlen((char *) ep->product) + 1;\n\tput_be32(p, len);\n\tp += sizeof(uint32_t);\n\n\t/* copy and crypt product name */\n\tmemcpy(p, ep->product, len);\n\terr = bcrypt_buf(ep->seed, ep->key, p, p, len, ep->longstate);\n\tif (err)\n\t\tgoto out;\n\ts = *p;\n\tp += len;\n\n\t/* put version length */\n\tlen = strlen((char *) ep->version) + 1;\n\tput_be32(p, len);\n\tp += sizeof(uint32_t);\n\n\t/* copy and crypt version */\n\tmemcpy(p, ep->version, len);\n\terr = bcrypt_buf(s, ep->key, p, p, len, ep->longstate);\n\tif (err)\n\t\tgoto out;\n\ts = *p;\n\tp += len;\n\n\t/* put data length */\n\tput_be32(p, ep->datalen);\n\n\t/* encrypt data */\n\terr = bcrypt_buf(s, ep->key, data, data, ep->datalen, ep->longstate);\n\tif (err)\n\t\tgoto out;\n\n\t/* put checksum */\n\tput_be32(&data[ep->datalen], ep->csum);\n\n\tret = 0;\n\nout:\n\treturn ret;\n}\n\nint decrypt_buf(struct enc_param *ep, unsigned char *data,\n\t\tunsigned long datalen)\n{\n\tunsigned char *p;\n\tuint32_t prod_len;\n\tuint32_t ver_len;\n\tuint32_t len;\n\tuint32_t csum;\n\tssize_t remain;\n\tint err;\n\tint ret = -1;\n\n#define CHECKLEN(_l) do {\t\t\\\n\tlen = (_l);\t\t\t\\\n\tif (remain < len) {\t\t\\\n\t\tgoto out;\t\t\\\n\t}\t\t\t\t\\\n} while (0)\n\n#define INCP() do {\t\t\t\\\n\tp += len;\t\t\t\\\n\tremain -= len;\t\t\t\\\n} while (0)\n\n\tremain = datalen;\n\tp = data;\n\n\tCHECKLEN(ENC_MAGIC_LEN);\n\terr = check_magic(p);\n\tif (err)\n\t\tgoto out;\n\tmemcpy(ep->magic, p, ENC_MAGIC_LEN);\n\tINCP();\n\n\tCHECKLEN(1);\n\tep->seed = *p;\n\tINCP();\n\n\tCHECKLEN(sizeof(uint32_t));\n\tprod_len = get_be32(p);\n\tif (prod_len > ENC_PRODUCT_LEN)\n\t\tgoto out;\n\tINCP();\n\n\tCHECKLEN(prod_len);\n\tmemcpy(ep->product, p, prod_len);\n\tINCP();\n\n\tCHECKLEN(sizeof(uint32_t));\n\tver_len = get_be32(p);\n\tif (ver_len > ENC_VERSION_LEN)\n\t\tgoto out;\n\tINCP();\n\n\tCHECKLEN(ver_len);\n\tmemcpy(ep->version, p, ver_len);\n\tINCP();\n\n\tCHECKLEN(sizeof(uint32_t));\n\tep->datalen = get_be32(p);\n\tINCP();\n\n\t/* decrypt data */\n\tCHECKLEN(ep->datalen);\n\terr = bcrypt_buf(ep->version[0], ep->key, p, data, ep->datalen,\n\t\t\t ep->longstate);\n\tif (err)\n\t\tgoto out;\n\tINCP();\n\n\tCHECKLEN(sizeof(uint32_t));\n\tep->csum = get_be32(p);\n\tINCP();\n\n\tcsum = buffalo_csum(ep->datalen, data, ep->datalen);\n\tif (csum != ep->csum)\n\t\tgoto out;\n\n\t/* decrypt product name */\n\terr = bcrypt_buf(ep->product[0], ep->key, ep->version, ep->version,\n\t\t\t ver_len, ep->longstate);\n\tif (err)\n\t\tgoto out;\n\n\t/* decrypt version */\n\terr = bcrypt_buf(ep->seed, ep->key, ep->product, ep->product, prod_len,\n\t\t\t ep->longstate);\n\tif (err)\n\t\tgoto out;\n\n\tret = 0;\nout:\n\treturn ret;\n\n#undef CHECKLEN\n#undef INCP\n}\n\nssize_t get_file_size(char *name)\n{\n\tstruct stat st;\n\tint err;\n\n\terr = stat(name, &st);\n\tif (err)\n\t\treturn -1;\n\n\treturn st.st_size;\n}\n\nint read_file_to_buf(char *name, void *buf, ssize_t buflen)\n{\n\tFILE *f;\n\tsize_t done;\n\tint ret = -1;\n\n\tf = fopen(name, \"r\");\n\tif (f == NULL)\n\t\tgoto out;\n\n\terrno = 0;\n\tdone = fread(buf, buflen, 1, f);\n\tif (done != 1)\n\t\tgoto close;\n\n\tret = 0;\n\nclose:\n\tfclose(f);\nout:\n\treturn ret;\n}\n\nint write_buf_to_file(char *name, void *buf, ssize_t buflen)\n{\n\tFILE *f;\n\tsize_t done;\n\tint ret = -1;\n\n\tf = fopen(name, \"w\");\n\tif (f == NULL)\n\t\tgoto out;\n\n\terrno = 0;\n\tdone = fwrite(buf, buflen, 1, f);\n\tif (done != 1)\n\t\tgoto close;\n\n\tret = 0;\n\nclose:\n\tfflush(f);\n\tfclose(f);\n\tif (ret)\n\t\tunlink(name);\nout:\n\treturn ret;\n}\n"
  },
  {
    "path": "src/firmware-tools/buffalo-lib.h",
    "content": "/*\n *  Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#ifndef _BUFFALO_LIB_H\n#define _BUFFALO_LIB_H\n\n#include <stdint.h>\n\n#define ARRAY_SIZE(_a)\t(sizeof((_a)) / sizeof((_a)[0]))\n#define BIT(_x)\t\t(1UL << (_x))\n\n#define TAG_BRAND_LEN\t\t32\n#define TAG_PRODUCT_LEN\t\t32\n#define TAG_VERSION_LEN\t\t8\n#define TAG_REGION_LEN\t\t2\n#define TAG_LANGUAGE_LEN\t8\n#define TAG_PLATFORM_LEN\t8\n#define TAG_HWVER_LEN\t\t4\n#define TAG_HWVER_VAL_LEN\t4\n\nstruct buffalo_tag {\n\tunsigned char\tproduct[TAG_PRODUCT_LEN];\n\tunsigned char\tbrand[TAG_BRAND_LEN];\n\tunsigned char\tver_major[TAG_VERSION_LEN];\n\tunsigned char\tver_minor[TAG_VERSION_LEN];\n\tunsigned char\tregion_code[2];\n\tuint32_t\tregion_mask;\n\tunsigned char\tunknown0[2];\n\tunsigned char\tlanguage[TAG_LANGUAGE_LEN];\n\tunsigned char\tplatform[TAG_PLATFORM_LEN];\n\tunsigned char\thwv[TAG_HWVER_LEN];\n\tunsigned char\thwv_val[TAG_HWVER_VAL_LEN];\n\tuint8_t\t\tunknown1[24];\n\n\tuint32_t\tlen;\n\tuint32_t\tcrc;\n\tuint32_t\tbase1;\n\tuint32_t\tbase2;\n\tuint32_t\tdata_len;\n\tuint8_t\t\tflag;\n\tuint8_t\t\tunknown2[3];\n} __attribute ((packed));\n\nstruct buffalo_tag2 {\n\tunsigned char\tproduct[TAG_PRODUCT_LEN];\n\tunsigned char\tbrand[TAG_BRAND_LEN];\n\tunsigned char\tver_major[TAG_VERSION_LEN];\n\tunsigned char\tver_minor[TAG_VERSION_LEN];\n\tunsigned char\tregion_code[2];\n\tuint32_t\tregion_mask;\n\tunsigned char\tunknown0[2];\n\tunsigned char\tlanguage[TAG_LANGUAGE_LEN];\n\tunsigned char\tplatform[TAG_PLATFORM_LEN];\n\tunsigned char\thwv[TAG_HWVER_LEN];\n\tunsigned char\thwv_val[TAG_HWVER_VAL_LEN];\n\tuint8_t\t\tunknown1[24];\n\n\tuint32_t\ttotal_len;\n\tuint32_t\tcrc;\n\tuint32_t\tlen1;\n\tuint32_t\tlen2;\n\tuint8_t\t\tflag;\n\tuint8_t\t\tunknown2[3];\n} __attribute ((packed));\n\n#define ENC_PRODUCT_LEN\t\t32\n#define ENC_VERSION_LEN\t\t8\n#define ENC_MAGIC_LEN\t\t6\n\nunsigned long enc_compute_header_len(char *product, char *version);\nunsigned long enc_compute_buf_len(char *product, char *version,\n\t\t\t\t  unsigned long datalen);\n\nstruct enc_param {\n\tunsigned char *key;\n\tunsigned char magic[ENC_MAGIC_LEN];\n\tunsigned char product[ENC_PRODUCT_LEN];\n\tunsigned char version[ENC_VERSION_LEN];\n\tunsigned char seed;\n\tint longstate;\n\tunsigned datalen;\n\tuint32_t csum;\n};\n\nint encrypt_buf(struct enc_param *ep, unsigned char *hdr,\n\t        unsigned char *data);\nint decrypt_buf(struct enc_param *ep, unsigned char *data,\n\t\tunsigned long datalen);\n\n#define BCRYPT_DEFAULT_STATE_LEN\t256\n#define BCRYPT_MAX_KEYLEN\t\t254\n\nstruct bcrypt_ctx {\n\tunsigned long i;\n\tunsigned long j;\n\tunsigned char *state;\n\tunsigned long state_len;\n};\n\nint bcrypt_init(struct bcrypt_ctx *ctx, void *key, int keylen,\n\t\tunsigned long state_len);\nint bcrypt_process(struct bcrypt_ctx *ctx, unsigned char *src,\n\t\t   unsigned char *dst, unsigned long len);\nvoid bcrypt_finish(struct bcrypt_ctx *ctx);\nint bcrypt_buf(unsigned char seed, unsigned char *key, unsigned char *src,\n\t       unsigned char *dst, unsigned long len, int longstate);\n\nuint32_t buffalo_csum(uint32_t csum, void *buf, unsigned long len);\nuint32_t buffalo_crc(void *buf, unsigned long len);\n\nssize_t get_file_size(char *name);\nint read_file_to_buf(char *name, void *buf, ssize_t buflen);\nint write_buf_to_file(char *name, void *buf, ssize_t buflen);\n\n#endif /* _BUFFALO_LIB_H */\n"
  },
  {
    "path": "src/firmware-tools/buffalo-tag.c",
    "content": "/*\n *  Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <netinet/in.h>\n\n#include \"buffalo-lib.h\"\n\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\nstatic char *region_table[] = {\n\t\"JP\", \"US\", \"EU\", \"AP\", \"TW\", \"KR\"\n};\n\n#define MAX_INPUT_FILES\t2\n\nstatic char *progname;\nstatic char *ifname[MAX_INPUT_FILES];\nstatic ssize_t fsize[MAX_INPUT_FILES];\nstatic int num_files;\nstatic char *ofname;\nstatic char *product;\nstatic char *brand;\nstatic char *language;\nstatic char *hwver;\nstatic char *platform;\nstatic int flag;\nstatic char *major;\nstatic char *minor = \"1.01\";\nstatic int skipcrc;\nstatic uint32_t base1;\nstatic uint32_t base2;\nstatic char *region_code;\nstatic uint32_t region_mask;\nstatic int num_regions;\n\nvoid usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -a <platform>   set platform to <platform>\\n\"\n\"  -b <brand>      set brand to <brand>\\n\"\n\"  -c <base1>\\n\"\n\"  -d <base2>\\n\"\n\"  -f <flag>       set flag to <flag>\\n\"\n\"  -i <file>       read input from the file <file>\\n\"\n\"  -l <language>   set language to <language>\\n\"\n\"  -m <version>    set minor version to <version>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -p <product>    set product to <product>\\n\"\n\"  -r <region>     set image region to <region>\\n\"\n\"\t\t   valid regions: JP, US, EU, AP, TW, KR, M_\\n\"\n\"  -s              skip CRC calculation\\n\"\n\"  -v <version>    set major version to <version>\\n\"\n\"  -w <version>    set harwdware version to <version>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nstatic int check_params(void)\n{\n\n#define CHECKSTR(_var, _name, _len)\tdo {\t\t\\\n\tif ((_var) == NULL) {\t\t\t\t\\\n\t\tERR(\"no %s specified\", (_name));\t\\\n\t\treturn -1;\t\t\t\t\\\n\t}\t\t\t\t\t\t\\\n\tif ((_len) > 0 &&\t\t\t\t\\\n\t    strlen((_var)) > ((_len) - 1)) {\t\t\\\n\t\tERR(\"%s is too long\", (_name));\t\t\\\n\t\treturn -1;\t\t\t\t\\\n\t}\t\t\t\t\t\t\\\n} while (0)\n\n\tif (num_files == 0)\n\t\tERR(\"no input files specified\");\n\n\tCHECKSTR(ofname, \"output file\", 0);\n\tCHECKSTR(brand, \"brand\", TAG_BRAND_LEN);\n\tCHECKSTR(product, \"product\", TAG_PRODUCT_LEN);\n\tCHECKSTR(platform, \"platform\", TAG_PLATFORM_LEN);\n\tCHECKSTR(major, \"major version\", TAG_VERSION_LEN);\n\tCHECKSTR(minor, \"minor version\", TAG_VERSION_LEN);\n\tCHECKSTR(language, \"language\", TAG_LANGUAGE_LEN);\n\n\tif (hwver)\n\t\tCHECKSTR(hwver, \"hardware version\", 2);\n\n\tif (num_regions == 0) {\n\t\tERR(\"no region code specified\");\n\t\treturn -1;\n\t}\n\n\treturn 0;\n\n#undef CHECKSTR\n}\n\nstatic int process_region(char *reg)\n{\n\tint i;\n\n\tif (strlen(reg) != 2) {\n\t\tERR(\"invalid region code '%s'\", reg);\n\t\treturn -1;\n\t}\n\n\tif (strcmp(reg, \"M_\") == 0) {\n\t\tregion_code = reg;\n\t\tregion_mask |= ~0;\n\t\tnum_regions = 32;\n\t\treturn 0;\n\t}\n\n\tfor (i = 0; i < ARRAY_SIZE(region_table); i++)\n\t\tif (strcmp(reg, region_table[i]) == 0) {\n\t\t\tregion_code = reg;\n\t\t\tregion_mask |= 1 << i;\n\t\t\tnum_regions++;\n\t\t\treturn 0;\n\t\t}\n\n\tERR(\"unknown region code '%s'\", reg);\n\treturn -1;\n}\n\nstatic int process_ifname(char *name)\n{\n\tif (num_files >= ARRAY_SIZE(ifname)) {\n\t\tERR(\"too many input files specified\");\n\t\treturn -1;\n\t}\n\n\tifname[num_files++] = name;\n\treturn 0;\n}\n\nstatic void fixup_tag(unsigned char *buf, ssize_t buflen)\n{\n\tstruct buffalo_tag *tag = (struct buffalo_tag *) buf;\n\n\tmemset(tag, '\\0', sizeof(*tag));\n\n\tmemcpy(tag->brand, brand, strlen(brand));\n\tmemcpy(tag->product, product, strlen(product));\n\tmemcpy(tag->platform, platform, strlen(platform));\n\tmemcpy(tag->ver_major, major, strlen(major));\n\tmemcpy(tag->ver_minor, minor, strlen(minor));\n\tmemcpy(tag->language, language, strlen(language));\n\n\tif (num_regions > 1) {\n\t\ttag->region_code[0] = 'M';\n\t\ttag->region_code[1] = '_';\n\t\ttag->region_mask = htonl(region_mask);\n\t} else {\n\t\tmemcpy(tag->region_code, region_code, 2);\n\t}\n\n\ttag->len = htonl(buflen);\n\ttag->data_len = htonl(fsize[0]);\n\ttag->base1 = htonl(base1);\n\ttag->base2 = htonl(base2);\n\ttag->flag = flag;\n\n\tif (hwver) {\n\t\tmemcpy(tag->hwv, \"hwv\", 3);\n\t\tmemcpy(tag->hwv_val, hwver, strlen(hwver));\n\t}\n\n\tif (!skipcrc)\n\t\ttag->crc = htonl(buffalo_crc(buf, buflen));\n}\n\nstatic void fixup_tag2(unsigned char *buf, ssize_t buflen)\n{\n\tstruct buffalo_tag2 *tag = (struct buffalo_tag2 *) buf;\n\n\tmemset(tag, '\\0', sizeof(*tag));\n\n\tmemcpy(tag->brand, brand, strlen(brand));\n\tmemcpy(tag->product, product, strlen(product));\n\tmemcpy(tag->platform, platform, strlen(platform));\n\tmemcpy(tag->ver_major, major, strlen(major));\n\tmemcpy(tag->ver_minor, minor, strlen(minor));\n\tmemcpy(tag->language, language, strlen(language));\n\n\tif (num_regions > 1) {\n\t\ttag->region_code[0] = 'M';\n\t\ttag->region_code[1] = '_';\n\t\ttag->region_mask = htonl(region_mask);\n\t} else {\n\t\tmemcpy(tag->region_code, region_code, 2);\n\t}\n\n\ttag->total_len = htonl(buflen);\n\ttag->len1 = htonl(fsize[0]);\n\ttag->len2 = htonl(fsize[1]);\n\ttag->flag = flag;\n\n\tif (hwver) {\n\t\tmemcpy(tag->hwv, \"hwv\", 3);\n\t\tmemcpy(tag->hwv_val, hwver, strlen(hwver));\n\t}\n\n\tif (!skipcrc)\n\t\ttag->crc = htonl(buffalo_crc(buf, buflen));\n}\n\nstatic int tag_file(void)\n{\n\tunsigned char *buf;\n\tssize_t offset;\n\tssize_t hdrlen;\n\tssize_t buflen;\n\tint err;\n\tint ret = -1;\n\tint i;\n\n\tif (num_files == 1)\n\t\thdrlen = sizeof(struct buffalo_tag);\n\telse\n\t\thdrlen = sizeof(struct buffalo_tag2);\n\n\tbuflen = hdrlen;\n\n\tfor (i = 0; i < num_files; i++) {\n\t\tfsize[i] = get_file_size(ifname[i]);\n\t\tif (fsize[i] < 0) {\n\t\t\tERR(\"unable to get size of '%s'\", ifname[i]);\n\t\t\tgoto out;\n\t\t}\n\t\tbuflen += fsize[i];\n\t}\n\n\tbuf = malloc(buflen);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto out;\n\t}\n\n\toffset = hdrlen;\n\tfor (i = 0; i < num_files; i++) {\n\t\terr = read_file_to_buf(ifname[i], buf + offset, fsize[i]);\n\t\tif (err) {\n\t\t\tERR(\"unable to read from file '%s'\", ifname[i]);\n\t\t\tgoto free_buf;\n\t\t}\n\n\t\toffset += fsize[i];\n\t}\n\n\tif (num_files == 1)\n\t\tfixup_tag(buf, buflen);\n\telse\n\t\tfixup_tag2(buf, buflen);\n\n\terr = write_buf_to_file(ofname, buf, buflen);\n\tif (err) {\n\t\tERR(\"unable to write to file '%s'\", ofname);\n\t\tgoto free_buf;\n\t}\n\n\tret = 0;\n\nfree_buf:\n\tfree(buf);\nout:\n\treturn ret;\n}\n\nint main(int argc, char *argv[])\n{\n\tint res = EXIT_FAILURE;\n\tint err;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"a:b:c:d:f:hi:l:m:o:p:r:sv:w:\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'a':\n\t\t\tplatform = optarg;\n\t\t\tbreak;\n\t\tcase 'b':\n\t\t\tbrand = optarg;\n\t\t\tbreak;\n\t\tcase 'c':\n\t\t\tbase1 = strtoul(optarg, NULL, 16);\n\t\t\tbreak;\n\t\tcase 'd':\n\t\t\tbase2 = strtoul(optarg, NULL, 16);\n\t\t\tbreak;\n\t\tcase 'f':\n\t\t\tflag = strtoul(optarg, NULL, 2);\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\terr = process_ifname(optarg);\n\t\t\tif (err)\n\t\t\t\tgoto out;\n\t\t\tbreak;\n\t\tcase 'l':\n\t\t\tlanguage = optarg;\n\t\t\tbreak;\n\t\tcase 'm':\n\t\t\tminor = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'p':\n\t\t\tproduct = optarg;\n\t\t\tbreak;\n\t\tcase 'r':\n\t\t\terr = process_region(optarg);\n\t\t\tif (err)\n\t\t\t\tgoto out;\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\tskipcrc = 1;\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tmajor = optarg;\n\t\t\tbreak;\n\t\tcase 'w':\n\t\t\thwver = optarg;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\terr = check_params();\n\tif (err)\n\t\tgoto out;\n\n\terr = tag_file();\n\tif (err)\n\t\tgoto out;\n\n\tres = EXIT_SUCCESS;\n\nout:\n\treturn res;\n}\n"
  },
  {
    "path": "src/firmware-tools/buffalo-tftp.c",
    "content": "/*\n * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License version 2 as published\n * by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n\n#include \"buffalo-lib.h\"\n\n#define ERR(fmt, args...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## args ); \\\n} while (0)\n\nstatic char *progname;\nstatic char *ifname;\nstatic char *ofname;\nstatic int do_decrypt;\n\nvoid usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -d              decrypt instead of encrypt\\n\"\n\"  -i <file>       read input from the file <file>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nstatic const unsigned char *crypt_key1 = (unsigned char *)\n\t\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\nstatic const unsigned char *crypt_key2 = (unsigned char *)\n\t\"XYZ0123hijklmnopqABCDEFGHrstuvabcdefgwxyzIJKLMSTUVW456789NOPQR\";\n\nstatic void crypt_header(unsigned char *buf, ssize_t len,\n\t\t\t const unsigned char *key1, const unsigned char *key2)\n{\n\tssize_t i;\n\n\tfor (i = 0; i < len; i++) {\n\t\tunsigned int j;\n\n\t\tfor (j = 0; key1[j]; j++)\n\t\t\tif (buf[i] == key1[j]) {\n\t\t\t\tbuf[i] = key2[j];\n\t\t\t\tbreak;\n\t\t\t}\n\t}\n}\n\nstatic int crypt_file(void)\n{\n\tunsigned char *buf = NULL;\n\tssize_t src_len;\n\tssize_t crypt_len;\n\tint err;\n\tint ret = -1;\n\n\tsrc_len = get_file_size(ifname);\n\tif (src_len < 0) {\n\t\tERR(\"unable to get size of '%s'\", ifname);\n\t\tgoto out;\n\t}\n\n\tbuf = malloc(src_len);\n\tif (buf == NULL) {\n\t\tERR(\"no memory for the buffer\");\n\t\tgoto out;\n\t}\n\n\terr = read_file_to_buf(ifname, buf, src_len);\n\tif (err) {\n\t\tERR(\"unable to read from file '%s'\", ifname);\n\t\tgoto out;\n\t}\n\n\tcrypt_len = (src_len > 512) ? 512 : src_len;\n\tif (do_decrypt)\n\t\tcrypt_header(buf, 512, crypt_key2, crypt_key1);\n\telse\n\t\tcrypt_header(buf, 512, crypt_key1, crypt_key2);\n\n\terr = write_buf_to_file(ofname, buf, src_len);\n\tif (err) {\n\t\tERR(\"unable to write to file '%s'\", ofname);\n\t\tgoto out;\n\t}\n\n\tret = 0;\n\nout:\n\tfree(buf);\n\treturn ret;\n}\n\nstatic int check_params(void)\n{\n\tint ret = -1;\n\n\tif (ifname == NULL) {\n\t\tERR(\"no input file specified\");\n\t\tgoto out;\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\tgoto out;\n\t}\n\n\tret = 0;\n\nout:\n\treturn ret;\n}\n\nint main(int argc, char *argv[])\n{\n\tint res = EXIT_FAILURE;\n\tint err;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"di:o:h\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'd':\n\t\t\tdo_decrypt = 1;\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tifname = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\terr = check_params();\n\tif (err)\n\t\tgoto out;\n\n\terr = crypt_file();\n\tif (err)\n\t\tgoto out;\n\n\tres = EXIT_SUCCESS;\n\nout:\n\treturn res;\n}\n"
  },
  {
    "path": "src/firmware-tools/csysimg.h",
    "content": "/*\n *\n *  Copyright (C) 2007,2009 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program was based on the code found in various Linux\n *  source tarballs released by Edimax for it's devices.\n *  Original author: David Hsu <davidhsu@realtek.com.tw>\n *\n *  This program is free software; you can redistribute it and/or\n *  modify it under the terms of the GNU General Public License\n *  as published by the Free Software Foundation; either version 2\n *  of the License, or (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program; if not, write to the\n *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n *  Boston, MA  02110-1301, USA.\n */\n\n#define SIG_LEN\t\t4\n\n#define ADM_CODE_ADDR\t0x80500000\n#define ADM_WEBP_ADDR\t0x10000\n#define ADM_WEBP_SIZE\t0x10000\n#define ADM_BOOT_SIZE\t0x8000\n#define ADM_CONF_SIZE\t0x8000\n#define ADM_BOOT_SIG\t\"\\x00\\x60\\x1A\\x40\"\n\n\n/*\n * Generic signatures\n */\n#define SIG_CSYS\t\"CSYS\"\n#define SIG_CONF\t\"HS\\x00\\x00\"\n#define SIG_BOOT_RTL\t\"\\x00\\x00\\x40\\x21\"\n\n/*\n * Web page signatures\n */\n#define SIG_BR6104K\t\"WB4K\"\n#define SIG_BR6104KP\t\"WBKP\"\n#define SIG_BR6104Wg\t\"WBGW\"\n#define SIG_BR6104IPC\t\"WBIP\"\n#define SIG_BR6114WG\tSIG_BR6104IPC\n#define SIG_BR6524K\t\"2-K-\"\n#define SIG_BR6524KP\t\"2-KP\"\t/* FIXME: valid? */\n#define SIG_BR6524WG\t\"2-WG\"\t/* FIXME: valid? */\n#define SIG_BR6524WP\t\"2-WP\"\t/* FIXME: valid? */\n#define SIG_BR6541K\t\"4--K\"\n#define SIG_BR6541KP\t\"4-KP\"\t/* FIXME: valid? */\n#define SIG_BR6541WP\t\"4-WP\"\t/* FIXME: valid? */\n#define SIG_C54BSR4\tSIG_BR6104IPC\n#define SIG_EW7207APg\t\"EWAS\"\n#define SIG_PS1205UWg\t\"4000\"\n#define SIG_PS3205U\t\"5010\"\n#define SIG_PS3205UWg\t\"5011\"\n#define SIG_RALINK\t\"RNRA\"\n#define SIG_5GXI\t\"5GXI\"\t/* fake signature */\n\n#define SIG_H2BR4\tSIG_BR6524K\n#define SIG_H2WR54G\tSIG_BR6524WG\n\n#define SIG_XRT401D\tSIG_BR6104K\n#define SIG_XRT402D\tSIG_BR6524K\n\n/*\n * CSYS image file header\n */\nstruct csys_header {\n\tunsigned char sig[SIG_LEN];\n\tuint32_t addr;\n\tuint32_t size;\n};\n"
  },
  {
    "path": "src/firmware-tools/cyg_crc.h",
    "content": "//==========================================================================\n//\n//      crc.h\n//\n//      Interface for the CRC algorithms.\n//\n//==========================================================================\n//####ECOSGPLCOPYRIGHTBEGIN####\n// -------------------------------------------\n// This file is part of eCos, the Embedded Configurable Operating System.\n// Copyright (C) 2002 Andrew Lunn\n//\n// eCos is free software; you can redistribute it and/or modify it under\n// the terms of the GNU General Public License as published by the Free\n// Software Foundation; either version 2 or (at your option) any later version.\n//\n// eCos is distributed in the hope that it will be useful, but WITHOUT ANY\n// WARRANTY; without even the implied warranty of MERCHANTABILITY or\n// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n// for more details.\n//\n// You should have received a copy of the GNU General Public License along\n// with eCos; if not, write to the Free Software Foundation, Inc.,\n// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.\n//\n// As a special exception, if other files instantiate templates or use macros\n// or inline functions from this file, or you compile this file and link it\n// with other works to produce a work based on this file, this file does not\n// by itself cause the resulting work to be covered by the GNU General Public\n// License. However the source code for this file must still be made available\n// in accordance with section (3) of the GNU General Public License.\n//\n// This exception does not invalidate any other reasons why a work based on\n// this file might be covered by the GNU General Public License.\n//\n// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.\n// at http://sources.redhat.com/ecos/ecos-license/\n// -------------------------------------------\n//####ECOSGPLCOPYRIGHTEND####\n//==========================================================================\n//#####DESCRIPTIONBEGIN####\n//\n// Author(s):    Andrew Lunn\n// Contributors: Andrew Lunn\n// Date:         2002-08-06\n// Purpose:\n// Description:\n//\n// This code is part of eCos (tm).\n//\n//####DESCRIPTIONEND####\n//\n//==========================================================================\n\n#ifndef _SERVICES_CRC_CRC_H_\n#define _SERVICES_CRC_CRC_H_\n\n#if 0\n#include <cyg/infra/cyg_type.h>\n#else\n#include <stdint.h>\ntypedef uint32_t cyg_uint32;\ntypedef uint16_t cyg_uint16;\n#endif\n\n#ifndef __externC\n# ifdef __cplusplus\n#  define __externC extern \"C\"\n# else\n#  define __externC extern\n# endif\n#endif\n\n// Compute a CRC, using the POSIX 1003 definition\n\n__externC cyg_uint32\ncyg_posix_crc32(unsigned char *s, int len);\n\n// Gary S. Brown's 32 bit CRC\n\n__externC cyg_uint32\ncyg_crc32(unsigned char *s, int len);\n\n// Gary S. Brown's 32 bit CRC, but accumulate the result from a\n// previous CRC calculation\n\n__externC cyg_uint32\ncyg_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len);\n\n// Ethernet FCS Algorithm\n\n__externC cyg_uint32\ncyg_ether_crc32(unsigned char *s, int len);\n\n// Ethernet FCS algorithm, but accumulate the result from a previous\n// CRC calculation.\n\n__externC cyg_uint32\ncyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len);\n\n// 16 bit CRC with polynomial x^16+x^12+x^5+1\n\n__externC cyg_uint16\ncyg_crc16(unsigned char *s, int len);\n\n#endif // _SERVICES_CRC_CRC_H_\n\n\n\n"
  },
  {
    "path": "src/firmware-tools/cyg_crc16.c",
    "content": "//==========================================================================\n//\n//      crc16.c\n//\n//      16 bit CRC with polynomial x^16+x^12+x^5+1\n//\n//==========================================================================\n//####ECOSGPLCOPYRIGHTBEGIN####\n// -------------------------------------------\n// This file is part of eCos, the Embedded Configurable Operating System.\n// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n// Copyright (C) 2002 Gary Thomas\n//\n// eCos is free software; you can redistribute it and/or modify it under\n// the terms of the GNU General Public License as published by the Free\n// Software Foundation; either version 2 or (at your option) any later version.\n//\n// eCos is distributed in the hope that it will be useful, but WITHOUT ANY\n// WARRANTY; without even the implied warranty of MERCHANTABILITY or\n// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n// for more details.\n//\n// You should have received a copy of the GNU General Public License along\n// with eCos; if not, write to the Free Software Foundation, Inc.,\n// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.\n//\n// As a special exception, if other files instantiate templates or use macros\n// or inline functions from this file, or you compile this file and link it\n// with other works to produce a work based on this file, this file does not\n// by itself cause the resulting work to be covered by the GNU General Public\n// License. However the source code for this file must still be made available\n// in accordance with section (3) of the GNU General Public License.\n//\n// This exception does not invalidate any other reasons why a work based on\n// this file might be covered by the GNU General Public License.\n//\n// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.\n// at http://sources.redhat.com/ecos/ecos-license/\n// -------------------------------------------\n//####ECOSGPLCOPYRIGHTEND####\n//==========================================================================\n//#####DESCRIPTIONBEGIN####\n//\n// Author(s):    gthomas\n// Contributors: gthomas,asl\n// Date:         2001-01-31\n// Purpose:      \n// Description:  \n//              \n// This code is part of eCos (tm).\n//\n//####DESCRIPTIONEND####\n//\n//==========================================================================\n\n#if 0\n#include <cyg/crc/crc.h>\n#else\n#include \"cyg_crc.h\"\n#endif\n\n// Table of CRC constants - implements x^16+x^12+x^5+1\nstatic const cyg_uint16 crc16_tab[] = {\n    0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, \n    0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, \n    0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, \n    0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, \n    0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, \n    0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, \n    0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, \n    0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, \n    0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, \n    0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, \n    0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, \n    0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, \n    0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, \n    0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, \n    0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, \n    0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, \n    0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, \n    0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, \n    0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, \n    0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, \n    0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, \n    0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, \n    0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, \n    0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, \n    0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, \n    0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, \n    0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, \n    0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, \n    0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, \n    0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, \n    0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, \n    0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, \n};\n\ncyg_uint16\ncyg_crc16(unsigned char *buf, int len)\n{\n    int i;\n    cyg_uint16 cksum;\n\n    cksum = 0;\n    for (i = 0;  i < len;  i++) {\n        cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xFF] ^ (cksum << 8);\n    }\n    return cksum;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/cyg_crc32.c",
    "content": "//==========================================================================\n//\n//      crc32.c\n//\n//      Gary S. Brown's 32 bit CRC\n//\n//==========================================================================\n//####ECOSGPLCOPYRIGHTBEGIN####\n// -------------------------------------------\n// This file is part of eCos, the Embedded Configurable Operating System.\n// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n// Copyright (C) 2002 Gary Thomas\n//\n// eCos is free software; you can redistribute it and/or modify it under\n// the terms of the GNU General Public License as published by the Free\n// Software Foundation; either version 2 or (at your option) any later version.\n//\n// eCos is distributed in the hope that it will be useful, but WITHOUT ANY\n// WARRANTY; without even the implied warranty of MERCHANTABILITY or\n// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n// for more details.\n//\n// You should have received a copy of the GNU General Public License along\n// with eCos; if not, write to the Free Software Foundation, Inc.,\n// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.\n//\n// As a special exception, if other files instantiate templates or use macros\n// or inline functions from this file, or you compile this file and link it\n// with other works to produce a work based on this file, this file does not\n// by itself cause the resulting work to be covered by the GNU General Public\n// License. However the source code for this file must still be made available\n// in accordance with section (3) of the GNU General Public License.\n//\n// This exception does not invalidate any other reasons why a work based on\n// this file might be covered by the GNU General Public License.\n//\n// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.\n// at http://sources.redhat.com/ecos/ecos-license/\n// -------------------------------------------\n//####ECOSGPLCOPYRIGHTEND####\n//==========================================================================\n//#####DESCRIPTIONBEGIN####\n//\n// Author(s):    gthomas\n// Contributors: gthomas,asl\n// Date:         2001-01-31\n// Purpose:      \n// Description:  \n//              \n// This code is part of eCos (tm).\n//\n//####DESCRIPTIONEND####\n//\n//==========================================================================\n\n#if 0\n#include <cyg/crc/crc.h>\n#else\n#include \"cyg_crc.h\"\n#endif\n\n  /* ====================================================================== */\n  /*  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or       */\n  /*  code or tables extracted from it, as desired without restriction.     */\n  /*                                                                        */\n  /*  First, the polynomial itself and its table of feedback terms.  The    */\n  /*  polynomial is                                                         */\n  /*  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0   */\n  /*                                                                        */\n  /* ====================================================================== */\n\nstatic const cyg_uint32 crc32_tab[] = {\n      0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,\n      0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,\n      0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,\n      0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,\n      0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,\n      0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,\n      0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,\n      0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,\n      0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,\n      0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,\n      0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,\n      0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,\n      0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,\n      0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,\n      0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,\n      0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,\n      0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,\n      0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,\n      0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,\n      0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,\n      0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,\n      0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,\n      0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,\n      0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,\n      0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,\n      0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,\n      0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,\n      0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,\n      0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,\n      0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,\n      0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,\n      0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,\n      0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,\n      0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,\n      0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,\n      0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,\n      0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,\n      0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,\n      0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,\n      0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,\n      0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,\n      0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,\n      0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,\n      0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,\n      0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,\n      0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,\n      0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,\n      0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,\n      0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,\n      0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,\n      0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,\n      0x2d02ef8dL\n   };\n\n/* This is the standard Gary S. Brown's 32 bit CRC algorithm, but\n   accumulate the CRC into the result of a previous CRC. */\ncyg_uint32 \ncyg_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)\n{\n  int i;\n\n  for (i = 0;  i < len;  i++) {\n    crc32val = crc32_tab[(crc32val ^ s[i]) & 0xff] ^ (crc32val >> 8);\n  }\n  return crc32val;\n}\n\n/* This is the standard Gary S. Brown's 32 bit CRC algorithm */\ncyg_uint32\ncyg_crc32(unsigned char *s, int len)\n{\n  return (cyg_crc32_accumulate(0,s,len));\n}\n\n/* Return a 32-bit CRC of the contents of the buffer accumulating the\n   result from a previous CRC calculation. This uses the Ethernet FCS\n   algorithm.*/\ncyg_uint32\ncyg_ether_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)\n{\n  int i;\n\n  if (s == 0) return 0L;\n  \n  crc32val = crc32val ^ 0xffffffff;\n  for (i = 0;  i < len;  i++) {\n      crc32val = crc32_tab[(crc32val ^ s[i]) & 0xff] ^ (crc32val >> 8);\n  }\n  return crc32val ^ 0xffffffff;\n}\n\n/* Return a 32-bit CRC of the contents of the buffer, using the\n   Ethernet FCS algorithm. */\ncyg_uint32\ncyg_ether_crc32(unsigned char *s, int len)\n{\n  return cyg_ether_crc32_accumulate(0,s,len);\n}\n\n\n"
  },
  {
    "path": "src/firmware-tools/dgfirmware.c",
    "content": "#include <stdlib.h>\n#include <stdio.h>\n\n\n#define IMG_SIZE     0x3e0000\n\n#define KERNEL_START 0x020000\n#define KERNEL_SIZE  0x0b0000\n\n#define ROOTFS_START 0x0d0000\n#define ROOTFS_SIZE  0x30ffb2\n\nchar* app_name;\n\n\n\n\nvoid print_usage(void)\n{\n  fprintf(stderr, \"usage: dgfirmware [<opts>] <img>\\n\");\n  fprintf(stderr, \"  <img>               firmware image filename\\n\");\n  fprintf(stderr, \"  <opts>  -h          print this message\\n\");\n  fprintf(stderr, \"          -f          fix the checksum\\n\");\n  fprintf(stderr, \"          -x  <file>  extract the rootfs file to <file>\\n\");\n  fprintf(stderr, \"          -xk <file>  extract the kernel to <file>\\n\");\n  fprintf(stderr, \"          -m  <file>  merge in rootfs fil\\e from <file>\\n\");\n  fprintf(stderr, \"          -k  <file>  merge in kernel from <file>\\n\");\n  fprintf(stderr, \"          -w  <file>  write back the modified firmware\\n\");\n}\n\n\nunsigned char* read_img(const char *fname)\n{\n  FILE *fp;\n  int size;\n  unsigned char *img;\n\n  fp = fopen(fname, \"rb\");\n  if (fp == NULL) {\n    perror(app_name);\n    exit(-1);\n  }\n\n  fseek(fp, 0, SEEK_END);\n  size = ftell(fp);\n  \n  if (size != IMG_SIZE) {\n    fprintf(stderr, \"%s: image file has wrong size\\n\", app_name);\n    fclose(fp);\n    exit(-1);\n  }\n\n  rewind(fp);\n\n  img = malloc(IMG_SIZE);\n  if (img == NULL) {\n    perror(app_name);\n    fclose(fp);\n    exit(-1);\n  }\n\n  if (fread(img, 1, IMG_SIZE, fp) != IMG_SIZE) {\n    fprintf(stderr, \"%s: can't read image file\\n\", app_name);\n    fclose(fp);\n    exit(-1);\n  }\n\n  fclose(fp);\n  return img;\n}\n\n\nvoid write_img(unsigned char* img, const char *fname)\n{\n  FILE *fp;\n\n  fp = fopen(fname, \"wb\");\n  if (fp == NULL) {\n    perror(app_name);\n    exit(-1);\n  }\n\n  if (fwrite(img, 1, IMG_SIZE, fp) != IMG_SIZE) {\n    fprintf(stderr, \"%s: can't write image file\\n\", app_name);\n    fclose(fp);\n    exit(-1);\n  }\n}\n\n\nvoid write_rootfs(unsigned char* img, const char *fname)\n{\n  FILE *fp;\n\n  fp = fopen(fname, \"wb\");\n  if (fp == NULL) {\n    perror(app_name);\n    exit(-1);\n  }\n  \n  if (fwrite(img+ROOTFS_START, 1, ROOTFS_SIZE, fp) != ROOTFS_SIZE) {\n    fprintf(stderr, \"%s: can't write image file\\n\", app_name);\n    fclose(fp);\n    exit(-1);\n  }\n}\n\n\nvoid write_kernel(unsigned char* img, const char *fname)\n{\n  FILE *fp;\n\n  fp = fopen(fname, \"wb\");\n  if (fp == NULL) {\n    perror(app_name);\n    exit(-1);\n  }\n  \n  if (fwrite(img+KERNEL_START, 1, KERNEL_SIZE, fp) != KERNEL_SIZE) {\n    fprintf(stderr, \"%s: can't write kernel file\\n\", app_name);\n    fclose(fp);\n    exit(-1);\n  }\n}\n\n\nunsigned char* read_rootfs(unsigned char* img, const char *fname)\n{\n  FILE *fp;\n  int size;\n  int i;\n\n  for (i=ROOTFS_START; i<ROOTFS_START+ROOTFS_SIZE; i++)\n    img[i] = 0xff;\n\n  fp = fopen(fname, \"rb\");\n  if (fp == NULL) {\n    perror(app_name);\n    exit(-1);\n  }\n\n  fseek(fp, 0, SEEK_END);\n  size = ftell(fp);\n  \n  if (size > ROOTFS_SIZE) {\n    fprintf(stderr, \"%s: rootfs image file is too big\\n\", app_name);\n    fclose(fp);\n    exit(-1);\n  }\n\n  rewind(fp);\n\n  if (fread(img+ROOTFS_START, 1, size, fp) != size) {\n    fprintf(stderr, \"%s: can't read rootfs image file\\n\", app_name);\n    fclose(fp);\n    exit(-1);\n  }\n\n  fclose(fp);\n  return img;\n}\n\n\nunsigned char* read_kernel(unsigned char* img, const char *fname)\n{\n  FILE *fp;\n  int size;\n  int i;\n\n  for (i=KERNEL_START; i<KERNEL_START+KERNEL_SIZE; i++)\n    img[i] = 0xff;\n\n  fp = fopen(fname, \"rb\");\n  if (fp == NULL) {\n    perror(app_name);\n    exit(-1);\n  }\n\n  fseek(fp, 0, SEEK_END);\n  size = ftell(fp);\n  \n  if (size > KERNEL_SIZE) {\n    fprintf(stderr, \"%s: kernel binary file is too big\\n\", app_name);\n    fclose(fp);\n    exit(-1);\n  }\n\n  rewind(fp);\n\n  if (fread(img+KERNEL_START, 1, size, fp) != size) {\n    fprintf(stderr, \"%s: can't read kernel file\\n\", app_name);\n    fclose(fp);\n    exit(-1);\n  }\n\n  fclose(fp);\n  return img;\n}\n\n\nint get_checksum(unsigned char* img)\n{\n  short unsigned s;\n\n  s = img[0x3dfffc] + (img[0x3dfffd]<<8);\n\n  return s;\n}\n\n\nvoid set_checksum(unsigned char*img, unsigned short sum)\n{\n  img[0x3dfffc] = sum & 0xff;\n  img[0x3dfffd] = (sum>>8) & 0xff;\n}\n\n\nint compute_checksum(unsigned char* img)\n{\n  int i;\n  short s=0;\n\n  for (i=0; i<0x3dfffc; i++)\n    s += img[i];\n\n  return s;\n}\n\n\nint main(int argc, char* argv[])\n{\n  char *img_fname     = NULL;\n  char *rootfs_fname  = NULL;\n  char *kernel_fname  = NULL;\n  char *new_img_fname = NULL;\n\n  int do_fix_checksum = 0;\n  int do_write        = 0;\n  int do_write_rootfs = 0;\n  int do_read_rootfs  = 0;\n  int do_write_kernel = 0;\n  int do_read_kernel  = 0;\n\n  int i;\n  unsigned char *img;\n  unsigned short img_checksum;\n  unsigned short real_checksum;\n\n  app_name = argv[0];\n\n  for (i=1; i<argc; i++) {\n    if (!strcmp(argv[i], \"-h\")) {\n      print_usage();\n      return 0;\n    }\n    else if (!strcmp(argv[i], \"-f\")) {\n      do_fix_checksum = 1;\n    }\n    else if (!strcmp(argv[i], \"-x\")) {\n      if (i+1 >= argc) {\n\tfprintf(stderr, \"%s: missing argument\\n\", app_name);\n\treturn -1;\n      }\n      do_write_rootfs = 1;\n      rootfs_fname = argv[i+1];\n      i++;\n    }\n    else if (!strcmp(argv[i], \"-xk\")) {\n      if (i+1 >= argc) {\n\tfprintf(stderr, \"%s: missing argument\\n\", app_name);\n\treturn -1;\n      }\n      do_write_kernel = 1;\n      kernel_fname = argv[i+1];\n      i++;\n    }\n    else if (!strcmp(argv[i], \"-m\")) {\n      if (i+1 >= argc) {\n\tfprintf(stderr, \"%s: missing argument\\n\", app_name);\n\treturn -1;\n      }\n      do_read_rootfs = 1;\n      rootfs_fname = argv[i+1];\n      i++;\n    }\n    else if (!strcmp(argv[i], \"-k\")) {\n      if (i+1 >= argc) {\n\tfprintf(stderr, \"%s: missing argument\\n\", app_name);\n\treturn -1;\n      }\n      do_read_kernel = 1;\n      kernel_fname = argv[i+1];\n      i++;\n    }\n    else if (!strcmp(argv[i], \"-w\")) {\n      if (i+1 >= argc) {\n\tfprintf(stderr, \"%s: missing argument\\n\", app_name);\n\treturn -1;\n      }\n      do_write = 1;\n      new_img_fname = argv[i+1];\n      i++;\n    }\n    else if (img_fname != 0) {\n      fprintf(stderr, \"%s: too many arguments\\n\", app_name);\n      return -1;\n    }\n    else {\n      img_fname = argv[i];\n    }\n  }\n\n  if (img_fname == NULL) {\n    fprintf(stderr, \"%s: missing argument\\n\", app_name);\n    return -1;\n  }\n\n  if ((do_read_rootfs && do_write_rootfs) ||\n      (do_read_kernel && do_write_kernel)) {\n    fprintf(stderr, \"%s: conflictuous options\\n\", app_name);\n    return -1;\n  }\n\n  printf (\"** Read firmware file\\n\");\n  img = read_img(img_fname);\n\n  printf (\"Firmware product: %s\\n\", img+0x3dffbd);\n  printf (\"Firmware version: 1.%02d.%02d\\n\", (img[0x3dffeb] & 0x7f), img[0x3dffec]);\n\n  if (do_write_rootfs) {\n    printf (\"** Write rootfs file\\n\");\n    write_rootfs(img, rootfs_fname);\n  }\n\n  if (do_write_kernel) {\n    printf (\"** Write kernel file\\n\");\n    write_kernel(img, kernel_fname);\n  }\n\n  if (do_read_rootfs) {\n    printf (\"** Read rootfs file\\n\");\n    read_rootfs(img, rootfs_fname);\n    do_fix_checksum = 1;\n  }\n\n  if (do_read_kernel) {\n    printf (\"** Read kernel file\\n\");\n    read_kernel(img, kernel_fname);\n    do_fix_checksum = 1;\n  }\n\n  img_checksum = get_checksum(img);\n  real_checksum = compute_checksum(img);\n  \n  printf (\"image checksum = %04x\\n\", img_checksum);\n  printf (\"real checksum  = %04x\\n\", real_checksum);\n\n  if (do_fix_checksum) {\n    if (img_checksum != real_checksum) {\n      printf (\"** Bad Checksum, fix it\\n\");\n      set_checksum(img, real_checksum);\n    }\n    else {\n      printf (\"** Checksum is correct, good\\n\");\n    }\n  }\n\n  if (do_write) {\n    printf (\"** Write image file\\n\");\n    write_img(img, new_img_fname);\n  }\n\n  free(img);\n  return 0;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/encode_crc.c",
    "content": "/* **************************************************************************\n\n   This program creates a CRC checksum and encodes the file that is named\n   in the command line.\n   \n   Compile with:  gcc encode_crc.c -Wall -o encode_crc\n\n   Author:     Michael Margraf  (michael.margraf@freecom.com)\n   Copyright:  Freecom Technology GmbH, Berlin, 2004\n               www.freecom.com\n\n  This program is free software; you can redistribute it and/or modify\n  it under the terms of the GNU General Public License as published by\n  the Free Software Foundation; either version 2 of the License, or\n  (at your option) any later version.\n\n  This program is distributed in the hope that it will be useful,\n  but WITHOUT ANY WARRANTY; without even the implied warranty of\n  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n  General Public License for more details.\n\n  You should have received a copy of the GNU General Public License\n  along with this program; if not, write to the Free Software\n  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n\n ************************************************************************* */\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <sys/stat.h>\n\n// *******************************************************************\n// CCITT polynom G(x)=x^16+x^12+x^5+1\n#define POLYNOM  0x1021\n\n// CRC algorithm with MSB first\nint make_crc16(int crc, char new)\n{\n  int i;\n  crc = crc ^ (((int)new) << 8);\n  \n  for(i=0; i<8; i++) {  // work on 8 bits in \"new\"\n    crc <<= 1;          // MSBs first\n    if(crc & 0x10000)  crc ^= POLYNOM;\n  }\n  return crc & 0xFFFF;\n}\n\n// *******************************************************************\n// Reads the file \"filename\" into memory and returns pointer to the buffer.\nstatic char *readfile(char *filename, int *size)\n{\n\tFILE\t\t*fp;\n\tchar\t\t*buffer;\n\tstruct stat\tinfo;\n\t\n\tif (stat(filename,&info)!=0)\n\t\treturn NULL;\n\n\tif ((fp=fopen(filename,\"r\"))==NULL)\n\t\treturn NULL;\n\n\tbuffer=NULL;\n\tfor (;;)\n\t{\n\t\tif ((buffer=(char *)malloc(info.st_size+1))==NULL)\n\t\t\tbreak;\n\n\t\tif (fread(buffer,1,info.st_size,fp)!=info.st_size)\n\t\t{\n\t\t\tfree(buffer);\n\t\t\tbuffer=NULL;\n\t\t\tbreak;\n\t\t}\n\n\t\tbuffer[info.st_size]='\\0';\n\t\tif(size) *size = info.st_size;\n\n\t\tbreak;\n\t}\n\n\t(void)fclose(fp);\n\n\treturn buffer;\n}\n\n\n// *******************************************************************\nint main(int argc, char** argv)\n{\n  if(argc < 3) {\n    printf(\"ERROR: Argument missing!\\n\\n\");\n    return 1;\n  }\n\n  int count;  // size of file in bytes\n  char *p, *master = readfile(argv[1], &count);\n  if(!master) {\n    printf(\"ERROR: File not found!\\n\");\n    return 1;\n  }\n\n  int crc = 0xFFFF, z;\n\n  p = master;\n  for(z=0; z<count; z++)\n    crc = make_crc16(crc, *(p++));  // calculate CRC\n  short crc16 = (short)crc;\n\n\t/*\n  if(argc > 2) {   // with flag for device recognition ?\n    p = argv[2];\n    for(z=strlen(p); z>0; z--) {\n      crc ^= (int)(*p);\n      *(p++) = (char)crc;  // encode device flag\n    }\n  }\n\t*/\n\n  p = master;\n  for(z=0; z<count; z++) {\n    crc ^= (int)(*p);\n    *(p++) = (char)crc;  // encode file\n  }\n\n\n  // write encoded file...\n  FILE *fp = fopen(argv[2], \"w\");\n  if(!fp) {\n    printf(\"ERROR: File not writeable!\\n\");\n    return 1;\n  }\n\n  if(argc > 3) {  // add flag for device recognition ?\n    fwrite(argv[3], strlen(argv[3]), sizeof(char), fp);\n  }\n  else {\n    // Device is an FSG, so byte swap (IXP4xx is big endian)\n    crc16 = ((crc16 >> 8) & 0xFF) | ((crc16 << 8) & 0xFF00);\n  }\n\n  fwrite(&crc16, 1, sizeof(short), fp);     // first write CRC\n\n  fwrite(master, count, sizeof(char), fp);  // write content\n  fclose(fp);\n\n  free(master);\n  return 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/fix-u-media-header.c",
    "content": "/*\n *  Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\n#include \"cyg_crc.h\"\n\n#include <arpa/inet.h>\n#include <netinet/in.h>\n\n#define IH_MAGIC\t0x27051956\t/* Image Magic Number\t\t*/\n#define IH_NMLEN\t32\t\t/* Image Name Length\t\t*/\n\n#define UM_MAGIC\t0x55525F46\n#define UM_HEADER_LEN\t12\n\n/*\n * all data in network byte order (aka natural aka bigendian)\n */\nstruct u_media_header {\n\tuint32_t\tih_magic;\t/* Image Header Magic Number\t*/\n\tuint32_t\tih_hcrc;\t/* Image Header CRC Checksum\t*/\n\tuint32_t\tih_time;\t/* Image Creation Timestamp\t*/\n\tuint32_t\tih_size;\t/* Image Data Size\t\t*/\n\tuint32_t\tih_load;\t/* Data\t Load  Address\t\t*/\n\tuint32_t\tih_ep;\t\t/* Entry Point Address\t\t*/\n\tuint32_t\tih_dcrc;\t/* Image Data CRC Checksum\t*/\n\tuint8_t\t\tih_os;\t\t/* Operating System\t\t*/\n\tuint8_t\t\tih_arch;\t/* CPU architecture\t\t*/\n\tuint8_t\t\tih_type;\t/* Image Type\t\t\t*/\n\tuint8_t\t\tih_comp;\t/* Compression Type\t\t*/\n\tuint8_t\t\tih_name[IH_NMLEN - UM_HEADER_LEN]; /* Image Name\t\t*/\n\n\tuint32_t\tih_UMedia_magic;\t/* U-Media magic number\t*/\n\tuint32_t\tih_UMedia_boardID;\t/* U-Media board ID\t*/\n\tuint8_t\t\tih_UMedia_imageType;\t/* U-Media image type */\n\tuint8_t\t\tih_UMedia_LoadDefault;\t/* U-Media load to factory default setting */\n\tuint8_t\t\tih_UMedia_temp1;\t/* U-Media didn't use this tag */\n\tuint8_t\t\tih_UMedia_temp2;\t/* U-Media didn't use this tag */\n} __attribute__ ((packed));\n\nstruct if_info {\n\tchar\t\t*file_name;\t/* name of the file */\n\tuint32_t\tfile_size;\t/* length of the file */\n};\n\nstatic char *progname;\nstatic char *ofname;\nstatic struct if_info if_info;\nstatic int factory_defaults;\nstatic uint32_t board_id;\nstatic uint8_t image_type;\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \" (%s)\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\n#define DBG(fmt, ...) do { \\\n\tfprintf(stderr, \"[%s] \" fmt \"\\n\", progname, ## __VA_ARGS__ ); \\\n} while (0)\n\nstatic void usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -B <board_id>   set board ID to <board_id>\\n\"\n\"  -i <file>       read input from the file <file>\\n\"\n\"  -F              load factory defaults\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -T <type>       set image type to <type>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nstatic int str2u32(char *arg, uint32_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err)) {\n\t\treturn -1;\n\t}\n\n\t*val = t;\n\treturn 0;\n}\n\nstatic int str2u8(char *arg, uint8_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err)) {\n\t\treturn -1;\n\t}\n\n\tif (t > 255)\n\t\treturn -1;\n\n\t*val = t;\n\treturn 0;\n}\n\nstatic int get_file_stat(struct if_info *fdata)\n{\n\tstruct stat st;\n\tint res;\n\n\tif (fdata->file_name == NULL)\n\t\treturn 0;\n\n\tres = stat(fdata->file_name, &st);\n\tif (res){\n\t\tERRS(\"stat failed on %s\", fdata->file_name);\n\t\treturn res;\n\t}\n\n\tfdata->file_size = st.st_size;\n\treturn 0;\n}\n\nstatic int read_to_buf(struct if_info *fdata, char *buf)\n{\n\tFILE *f;\n\tint ret = EXIT_FAILURE;\n\n\tf = fopen(fdata->file_name, \"r\");\n\tif (f == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for reading\", fdata->file_name);\n\t\tgoto out;\n\t}\n\n\terrno = 0;\n\tfread(buf, fdata->file_size, 1, f);\n\tif (errno != 0) {\n\t\tERRS(\"unable to read from file \\\"%s\\\"\", fdata->file_name);\n\t\tgoto out_close;\n\t}\n\n\tret = EXIT_SUCCESS;\n\nout_close:\n\tfclose(f);\nout:\n\treturn ret;\n}\n\nstatic int check_options(void)\n{\n\tint ret;\n\n\tif (ofname == NULL) {\n\t\tERR(\"no %s specified\", \"output file\");\n\t\treturn -1;\n\t}\n\n\tif (if_info.file_name == NULL) {\n\t\tERR(\"no %s specified\", \"input file\");\n\t\treturn -1;\n\t}\n\n\tret = get_file_stat(&if_info);\n\tif (ret)\n\t\treturn ret;\n\n\treturn 0;\n}\n\nstatic int write_fw(char *data, int len)\n{\n\tFILE *f;\n\tint ret = EXIT_FAILURE;\n\n\tf = fopen(ofname, \"w\");\n\tif (f == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto out;\n\t}\n\n\terrno = 0;\n\tfwrite(data, len, 1, f);\n\tif (errno) {\n\t\tERRS(\"unable to write output file\");\n\t\tgoto out_flush;\n\t}\n\n\tret = EXIT_SUCCESS;\n\nout_flush:\n\tfflush(f);\n\tfclose(f);\n\tif (ret != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\nout:\n\treturn ret;\n}\n\nstatic int fix_header(void)\n{\n\tint buflen;\n\tchar *buf;\n\tuint32_t crc, crc_orig;\n\tstruct u_media_header *hdr;\n\tint ret = EXIT_FAILURE;\n\n\tbuflen = if_info.file_size;\n\tif (buflen < sizeof(*hdr)) {\n\t\tERR(\"invalid input file\\n\");\n\t\treturn ret;\n\t}\n\n\tbuf = malloc(buflen);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto out;\n\t}\n\n\tret = read_to_buf(&if_info, buf);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\thdr = (struct u_media_header *) buf;\n\tif (ntohl(hdr->ih_magic) != IH_MAGIC) {\n\t\tERR(\"invalid input file, bad magic\\n\");\n\t\tgoto out_free_buf;\n\t}\n\n\t/* verify header CRC */\n\tcrc_orig = ntohl(hdr->ih_hcrc);\n\thdr->ih_hcrc = 0;\n\tcrc = cyg_ether_crc32((unsigned char *)hdr, sizeof(*hdr));\n\tif (crc != crc_orig) {\n\t\tERR(\"invalid input file, bad header CRC\\n\");\n\t\tgoto out_free_buf;\n\t}\n\n\thdr->ih_name[IH_NMLEN - UM_HEADER_LEN - 1] = '\\0';\n\n\t/* set U-Media specific fields */\n\thdr->ih_UMedia_magic = htonl(UM_MAGIC);\n\thdr->ih_UMedia_boardID = htonl(board_id);\n\thdr->ih_UMedia_imageType = image_type;\n\thdr->ih_UMedia_LoadDefault = (factory_defaults) ? 1 : 0;\n\n\t/* update header CRC */\n\tcrc = cyg_ether_crc32((unsigned char *)hdr, sizeof(*hdr));\n\thdr->ih_hcrc = htonl(crc);\n\n\tret = write_fw(buf, buflen);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\tDBG(\"U-Media header fixed in \\\"%s\\\"\", ofname);\n\n\tret = EXIT_SUCCESS;\n\nout_free_buf:\n\tfree(buf);\nout:\n\treturn ret;\n}\n\nint main(int argc, char *argv[])\n{\n\tint ret = EXIT_FAILURE;\n\n\tprogname = basename(argv[0]);\n\n\twhile (1) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"B:Fi:o:T:h\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'B':\n\t\t\tif (str2u32(optarg, &board_id)) {\n\t\t\t\tERR(\"%s is invalid '%s'\",\n\t\t\t\t    \"board ID\", optarg);\n\t\t\t\tgoto out;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'T':\n\t\t\tif (str2u8(optarg, &image_type)) {\n\t\t\t\tERR(\"%s is invalid '%s'\",\n\t\t\t\t    \"image type\", optarg);\n\t\t\t\tgoto out;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'F':\n\t\t\tfactory_defaults = 1;\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tif_info.file_name = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tret = check_options();\n\tif (ret)\n\t\tgoto out;\n\n\tret = fix_header();\n\nout:\n\treturn ret;\n}\n"
  },
  {
    "path": "src/firmware-tools/fw.h",
    "content": "/*\n *  * Copyright (C) 2007 Ubiquiti Networks, Inc.\n *   *\n *    * This program is free software; you can redistribute it and/or\n *     * modify it under the terms of the GNU General Public License as\n *      * published by the Free Software Foundation; either version 2 of the\n *       * License, or (at your option) any later version.\n *        *\n *         * This program is distributed in the hope that it will be useful, but\n *          * WITHOUT ANY WARRANTY; without even the implied warranty of\n *           * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n *            * General Public License for more details.\n *             *\n *              * You should have received a copy of the GNU General Public License\n *               * along with this program; if not, write to the Free Software\n *                * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n *                 */\n\n#ifndef FW_INCLUDED\n#define FW_INCLUDED\n\n#include <sys/types.h>\n\n#define MAGIC_HEADER\t\"OPEN\"\n#define MAGIC_PART\t\"PART\"\n#define MAGIC_END\t\"END.\"\n\n#define MAGIC_LENGTH\t4\n\ntypedef struct header {\n\tchar magic[MAGIC_LENGTH];\n\tchar version[256];\n\tu_int32_t crc;\n\tu_int32_t pad;\n} __attribute__ ((packed)) header_t;\n\ntypedef struct part {\n\tchar magic[MAGIC_LENGTH];\n\tchar name[16];\n\tchar pad[12];\n\tu_int32_t memaddr;\n\tu_int32_t index;\n\tu_int32_t baseaddr;\n\tu_int32_t entryaddr;\n\tu_int32_t data_size;\n\tu_int32_t part_size;\n} __attribute__ ((packed)) part_t;\n\ntypedef struct part_crc {\n\tu_int32_t crc;\n\tu_int32_t pad;\n} __attribute__ ((packed)) part_crc_t;\n\ntypedef struct signature {\n\tchar magic[MAGIC_LENGTH];\n\tu_int32_t crc;\n\tu_int32_t pad;\n} __attribute__ ((packed)) signature_t;\n\n#define VERSION \"1.2\"\n\n#define INFO(...) fprintf(stdout, __VA_ARGS__)\n#define ERROR(...) fprintf(stderr, \"ERROR: \"__VA_ARGS__)\n#define WARN(...) fprintf(stderr, \"WARN: \"__VA_ARGS__)\n#define DEBUG(...) do {\\\n        if (debug) \\\n                fprintf(stdout, \"DEBUG: \"__VA_ARGS__); \\\n} while (0);\n\n#endif\n"
  },
  {
    "path": "src/firmware-tools/imagetag.c",
    "content": "/*\n * This file is subject to the terms and conditions of the GNU General Public\n * License.  See the file \"COPYING\" in the main directory of this archive\n * for more details.\n *\n * Copyright (C) 2008 Axel Gembe <ago@bastart.eu.org>\n * Copyright (C) 2009-2010 Daniel Dickinson <openwrt@cshore.neomailbox.net>\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdint.h>\n#include <time.h>\n#include <unistd.h>\n#include <sys/stat.h>\n#include <netinet/in.h>\n\n#include \"bcm_tag.h\"\n#include \"imagetag_cmdline.h\"\n\n#define DEADCODE\t\t\t0xDEADC0DE\n\n/* Kernel header */\nstruct kernelhdr {\n\tuint32_t\t\tloadaddr;\t/* Kernel load address */\n\tuint32_t\t\tentry;\t\t/* Kernel entry point address */\n\tuint32_t\t\tlzmalen;\t/* Compressed length of the LZMA data that follows */\n};\n\nstatic char pirellitab[NUM_PIRELLI][BOARDID_LEN] = PIRELLI_BOARDS;\n\nstatic uint32_t crc32tab[256] = {\n\t0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,\n\t0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,\n\t0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,\n\t0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,\n\t0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,\n\t0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,\n\t0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,\n\t0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,\n\t0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,\n\t0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,\n\t0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,\n\t0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,\n\t0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,\n\t0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,\n\t0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,\n\t0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,\n\t0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,\n\t0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,\n\t0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,\n\t0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,\n\t0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,\n\t0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,\n\t0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,\n\t0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,\n\t0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,\n\t0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,\n\t0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,\n\t0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,\n\t0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,\n\t0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,\n\t0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,\n\t0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D\n};\n\nvoid int2tag(char *tag, uint32_t value) {\n  uint32_t network = htonl(value);\n  memcpy(tag, (char *)(&network), 4);\n}\n\nuint32_t crc32(uint32_t crc, uint8_t *data, size_t len)\n{\n\twhile (len--)\n\t\tcrc = (crc >> 8) ^ crc32tab[(crc ^ *data++) & 0xFF];\n\n\treturn crc;\n}\n\nuint32_t compute_crc32(uint32_t crc, FILE *binfile, size_t compute_start, size_t compute_len)\n{\n\tuint8_t readbuf[1024];\n\tsize_t read;\n\n\tfseek(binfile, compute_start, SEEK_SET);\n\n\t/* read block of 1024 bytes */\n\twhile (binfile && !feof(binfile) && !ferror(binfile) && (compute_len >= sizeof(readbuf))) {\n\t\tread = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), binfile);\n\t\tcrc = crc32(crc, readbuf, read);\n\t\tcompute_len = compute_len - read;\n\t}\n\n\t/* Less than 1024 bytes remains, read compute_len bytes */\n\tif (binfile && !feof(binfile) && !ferror(binfile) && (compute_len > 0)) {\n\t\tread = fread(readbuf, sizeof(uint8_t), compute_len, binfile);\n\t\tcrc = crc32(crc, readbuf, read);\n\t}\n\n\treturn crc;\n}\n\nsize_t getlen(FILE *fp)\n{\n\tsize_t retval, curpos;\n\n\tif (!fp)\n\t\treturn 0;\n\n\tcurpos = ftell(fp);\n\tfseek(fp, 0, SEEK_END);\n\tretval = ftell(fp);\n\tfseek(fp, curpos, SEEK_SET);\n\n\treturn retval;\n}\n\nint tagfile(const char *kernel, const char *rootfs, const char *bin, \\\n\t\t\tconst struct gengetopt_args_info *args, \\\n\t\t\tuint32_t flash_start, uint32_t image_offset, \\\n\t\t\tuint32_t block_size, uint32_t load_address, uint32_t entry)\n{\n\tstruct bcm_tag tag;\n\tstruct kernelhdr khdr;\n\tFILE *kernelfile = NULL, *rootfsfile = NULL, *binfile = NULL, *cfefile = NULL;\n\tsize_t cfeoff, cfelen, kerneloff, kernellen, rootfsoff, rootfslen, \\\n\t  read, imagelen, rootfsoffpadlen = 0, kernelfslen, kerneloffpadlen = 0, oldrootfslen;\n\tuint8_t readbuf[1024];\n\tuint32_t imagecrc = IMAGETAG_CRC_START;\n\tuint32_t kernelcrc = IMAGETAG_CRC_START;\n\tuint32_t rootfscrc = IMAGETAG_CRC_START;\n\tuint32_t kernelfscrc = IMAGETAG_CRC_START;\n\tuint32_t fwaddr = 0;\n\tuint8_t crc_val;\n\tconst uint32_t deadcode = htonl(DEADCODE);\n\tint i;\n\tint is_pirelli = 0;\n\n\n\tmemset(&tag, 0, sizeof(struct bcm_tag));\n\n\tif (!kernel || !rootfs) {\n\t\tfprintf(stderr, \"imagetag can't create an image without both kernel and rootfs\\n\");\n\t}\n\n\tif (kernel && !(kernelfile = fopen(kernel, \"rb\"))) {\n\t\tfprintf(stderr, \"Unable to open kernel \\\"%s\\\"\\n\", kernel);\n\t\treturn 1;\n\t}\n\n\tif (rootfs && !(rootfsfile = fopen(rootfs, \"rb\"))) {\n\t\tfprintf(stderr, \"Unable to open rootfs \\\"%s\\\"\\n\", rootfs);\n\t\treturn 1;\n\t}\n\n\tif (!bin || !(binfile = fopen(bin, \"wb+\"))) {\n\t\tfprintf(stderr, \"Unable to open output file \\\"%s\\\"\\n\", bin);\n\t\treturn 1;\n\t}\n\n\tif ((args->cfe_given) && (args->cfe_arg)) {\n\t  if (!(cfefile = fopen(args->cfe_arg, \"rb\"))) {\n\t\tfprintf(stderr, \"Unable to open CFE file \\\"%s\\\"\\n\", args->cfe_arg);\n\t  }\n\t}\n\n\tfwaddr = flash_start + image_offset;\n\tif (cfefile) {\n\t  cfeoff = flash_start;\t\t  \n\t  cfelen = getlen(cfefile);\n\t  /* Seek to the start of the file after tag */\n\t  fseek(binfile, sizeof(tag), SEEK_SET);\n\t  \n\t  /* Write the cfe */\n\t  while (cfefile && !feof(cfefile) && !ferror(cfefile)) {\n\t\tread = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), cfefile);\n\t\tfwrite(readbuf, sizeof(uint8_t), read, binfile);\n\t  }\n\n\t} else {\n\t  cfeoff = 0;\n\t  cfelen = 0;\n\t}\n\n\tif (!args->root_first_flag) {\n\t  /* Build the kernel address and length (doesn't need to be aligned, read only) */\n\t  kerneloff = fwaddr + sizeof(tag);\n\t  \n\t  kernellen = getlen(kernelfile);\n\t  \n\t  if (!args->kernel_file_has_header_flag) {\n\t\t/* Build the kernel header */\n\t\tkhdr.loadaddr\t= htonl(load_address);\n\t\tkhdr.entry\t= htonl(entry);\n\t\tkhdr.lzmalen\t= htonl(kernellen);\n\t\t\n\t\t/* Increase the kernel size by the header size */\n\t\tkernellen += sizeof(khdr);\t  \n\t  }\n\t  \n\t  /* Build the rootfs address and length (start and end do need to be aligned on flash erase block boundaries */\n\t  rootfsoff = kerneloff + kernellen;\n\t  rootfsoff = (rootfsoff % block_size) > 0 ? (((rootfsoff / block_size) + 1) * block_size) : rootfsoff;\n\t  rootfslen = getlen(rootfsfile);\n\t  rootfslen = ( (rootfslen % block_size) > 0 ? (((rootfslen / block_size) + 1) * block_size) : rootfslen );\n\t  imagelen = rootfsoff + rootfslen - kerneloff + sizeof(deadcode);\n\t  rootfsoffpadlen = rootfsoff - (kerneloff + kernellen);\n\t  \n\t  /* Seek to the start of the kernel */\n\t  fseek(binfile, kerneloff - fwaddr + cfelen, SEEK_SET);\n\t  \n\t  /* Write the kernel header */\n\t  fwrite(&khdr, sizeof(khdr), 1, binfile);\n\t  \n\t  /* Write the kernel */\n\t  while (kernelfile && !feof(kernelfile) && !ferror(kernelfile)) {\n\t\tread = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), kernelfile);\n\t\tfwrite(readbuf, sizeof(uint8_t), read, binfile);\n\t  }\n\n\t  /* Write the RootFS */\n\t  fseek(binfile, rootfsoff - fwaddr + cfelen, SEEK_SET);\n\t  while (rootfsfile && !feof(rootfsfile) && !ferror(rootfsfile)) {\n\t\tread = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), rootfsfile);\n\t\tfwrite(readbuf, sizeof(uint8_t), read, binfile);\n\t  }\n\n\t  /* Align image to specified erase block size and append deadc0de */\n\t  printf(\"Data alignment to %dk with 'deadc0de' appended\\n\", block_size/1024);\n\t  fseek(binfile, rootfsoff + rootfslen - fwaddr + cfelen, SEEK_SET);\n\t  fwrite(&deadcode, sizeof(uint32_t), 1, binfile);\n\n\t  oldrootfslen = rootfslen;\n\t  if (args->pad_given) {\n\t\tuint32_t allfs = 0xffffffff;\n\t\tuint32_t pad_size = args->pad_arg * 1024 * 1024;\n\n\t\tprintf(\"Padding image to %d bytes ...\\n\", pad_size);\n\t\twhile (imagelen < pad_size) {\n\t\t\tfwrite(&allfs, sizeof(uint32_t), 1, binfile);\n\t\t\timagelen += 4;\n\t\t\trootfslen += 4;\n\t\t}\n\t  }\n\n\t  /* Flush the binfile buffer so that when we read from file, it contains\n\t   * everything in the buffer\n\t   */\n\t  fflush(binfile);\n\n\t  /* Compute the crc32 of the entire image (deadC0de included) */\n\t  imagecrc = compute_crc32(imagecrc, binfile, kerneloff - fwaddr + cfelen, imagelen);\n\t  /* Compute the crc32 of the kernel and padding between kernel and rootfs) */\n\t  kernelcrc = compute_crc32(kernelcrc, binfile, kerneloff - fwaddr + cfelen, kernellen + rootfsoffpadlen);\n\t  /* Compute the crc32 of the kernel and padding between kernel and rootfs) */\n\t  kernelfscrc = compute_crc32(kernelfscrc, binfile, kerneloff - fwaddr + cfelen, kernellen + rootfsoffpadlen + rootfslen + sizeof(deadcode));\n\t  /* Compute the crc32 of the flashImageStart to rootLength.\n\t   * The broadcom firmware assumes the rootfs starts the image,\n\t   * therefore uses the rootfs start to determine where to flash\n\t   * the image.  Since we have the kernel first we have to give\n\t   * it the kernel address, but the crc uses the length\n\t   * associated with this address, which is added to the kernel\n\t   * length to determine the length of image to flash and thus\n\t   * needs to be rootfs + deadcode\n\t   */\n\t  rootfscrc = compute_crc32(rootfscrc, binfile, kerneloff - fwaddr + cfelen, rootfslen + sizeof(deadcode));\n\n\t} else {\n\t  /* Build the kernel address and length (doesn't need to be aligned, read only) */\n\t  rootfsoff = fwaddr + sizeof(tag);\n\t  oldrootfslen = getlen(rootfsfile);\n\t  rootfslen = oldrootfslen;\n\t  rootfslen = ( (rootfslen % block_size) > 0 ? (((rootfslen / block_size) + 1) * block_size) : rootfslen );\n\t  kerneloffpadlen = rootfslen - oldrootfslen;\n\t  oldrootfslen = rootfslen;\n\n\t  kerneloff = rootfsoff + rootfslen;\n\t  kernellen = getlen(kernelfile);\n\n\t  imagelen = cfelen + rootfslen + kernellen;\n\t  \n\t  /* Seek to the start of the kernel */\n\t  fseek(binfile, kerneloff - fwaddr + cfelen, SEEK_SET);\n\t  \n\t  if (!args->kernel_file_has_header_flag) {\n\t\t/* Build the kernel header */\n\t\tkhdr.loadaddr\t= htonl(load_address);\n\t\tkhdr.entry\t= htonl(entry);\n\t\tkhdr.lzmalen\t= htonl(kernellen);\n\t\t\n\t\t/* Write the kernel header */\n\t\tfwrite(&khdr, sizeof(khdr), 1, binfile);\n\t  \n\t\t/* Increase the kernel size by the header size */\n\t\tkernellen += sizeof(khdr);\t  \n\t  }\n\t  \n\t  /* Write the kernel */\n\t  while (kernelfile && !feof(kernelfile) && !ferror(kernelfile)) {\n\t\tread = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), kernelfile);\n\t\tfwrite(readbuf, sizeof(uint8_t), read, binfile);\n\t  }\n\n\t  /* Write the RootFS */\n\t  fseek(binfile, rootfsoff - fwaddr + cfelen, SEEK_SET);\n\t  while (rootfsfile && !feof(rootfsfile) && !ferror(rootfsfile)) {\n\t\tread = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), rootfsfile);\n\t\tfwrite(readbuf, sizeof(uint8_t), read, binfile);\n\t  }\n\n\t  /* Flush the binfile buffer so that when we read from file, it contains\n\t   * everything in the buffer\n\t   */\n\t  fflush(binfile);\n\n\t  /* Compute the crc32 of the entire image (deadC0de included) */\n\t  imagecrc = compute_crc32(imagecrc, binfile, sizeof(tag), imagelen);\n\t  /* Compute the crc32 of the kernel and padding between kernel and rootfs) */\n\t  kernelcrc = compute_crc32(kernelcrc, binfile, kerneloff - fwaddr + cfelen, kernellen + rootfsoffpadlen);\n\t  kernelfscrc = compute_crc32(kernelfscrc, binfile, rootfsoff - fwaddr + cfelen, kernellen + rootfslen);\n\t  rootfscrc = compute_crc32(rootfscrc, binfile, rootfsoff - fwaddr + cfelen, rootfslen);\n\t}\n\n\t/* Close the files */\n\tif (cfefile) {\n\t  fclose(cfefile);\n\t}\n\tfclose(kernelfile);\n\tfclose(rootfsfile);\n\n\t/* Build the tag */\n\tstrncpy(tag.tagVersion, args->tag_version_arg, sizeof(tag.tagVersion) - 1);\n\tstrncpy(tag.sig_1, args->signature_arg, sizeof(tag.sig_1) - 1);\n\tstrncpy(tag.sig_2, args->signature2_arg, sizeof(tag.sig_2) - 1);\n\tstrncpy(tag.chipid, args->chipid_arg, sizeof(tag.chipid) - 1);\n\tstrncpy(tag.boardid, args->boardid_arg, sizeof(tag.boardid) - 1);\n\tstrcpy(tag.big_endian, \"1\");\n\tsprintf(tag.totalLength, \"%lu\", imagelen);\n\n\tif (args->cfe_given) {\n\t  sprintf(tag.cfeAddress, \"%lu\", flash_start);\n\t  sprintf(tag.cfeLength, \"%lu\", cfelen);\n\t} else {\n\t  /* We don't include CFE */\n\t  strcpy(tag.cfeAddress, \"0\");\n\t  strcpy(tag.cfeLength, \"0\");\n\t}\n\n\tsprintf(tag.kernelAddress, \"%lu\", kerneloff);\n\tsprintf(tag.kernelLength, \"%lu\", kernellen + rootfsoffpadlen);\n\n\tif (args->root_first_flag) {\n\t  sprintf(tag.flashImageStart, \"%lu\", rootfsoff);\n\t  sprintf(tag.flashRootLength, \"%lu\", rootfslen);\t  \n\t} else {\n\t  sprintf(tag.flashImageStart, \"%lu\", kerneloff);\n\t  sprintf(tag.flashRootLength, \"%lu\", rootfslen + sizeof(deadcode));\n\t}\n\tint2tag(tag.rootLength, oldrootfslen + sizeof(deadcode));\n\n\tif (args->rsa_signature_given) {\n\t    strncpy(tag.rsa_signature, args->rsa_signature_arg, RSASIG_LEN);\n\t}\n\n\tif (args->layoutver_given) {\n\t    strncpy(tag.flashLayoutVer, args->layoutver_arg, TAGLAYOUT_LEN);\n\t}\n\n\tif (args->info1_given) {\n\t  strncpy(tag.information1, args->info1_arg, TAGINFO1_LEN);\n\t}\n\n\tif (args->info2_given) {\n\t  strncpy(tag.information2, args->info2_arg, TAGINFO2_LEN);\n\t}\n\n\tif (args->reserved2_given) {\n\t  strncpy(tag.reserved2, args->reserved2_arg, 16);\n\t}\n\n\tif (args->altinfo_given) {\n\t  strncpy(&tag.information1[0], args->altinfo_arg, ALTTAGINFO_LEN);\n\t}\n\n\tif (args->second_image_flag_given) {\n\t  if (strncmp(args->second_image_flag_arg, \"2\", DUALFLAG_LEN) != 0) {\t\t\n\t\tstrncpy(tag.dualImage, args->second_image_flag_arg, DUALFLAG_LEN);\n\t  }\n\t}\n\n\tif (args->inactive_given) {\n\t  if (strncmp(args->inactive_arg, \"2\", INACTIVEFLAG_LEN) != 0) {\t\t\n\t\tstrncpy(tag.inactiveFlag, args->second_image_flag_arg, INACTIVEFLAG_LEN);\n\t  }\n\t}\n\n\tfor (i = 0; i < NUM_PIRELLI; i++) {\n\t\tif (strncmp(args->boardid_arg, pirellitab[i], BOARDID_LEN) == 0) {\n\t\t\tis_pirelli = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif ( !is_pirelli ) {\n\t  int2tag(tag.imageCRC, kernelfscrc);\n\t} else {\n\t  int2tag(tag.imageCRC, kernelcrc);\n\t}\n\n\tint2tag(&(tag.rootfsCRC[0]), rootfscrc);\n\tint2tag(tag.kernelCRC, kernelcrc);\n\tint2tag(tag.fskernelCRC, kernelfscrc);\n\tint2tag(tag.headerCRC, crc32(IMAGETAG_CRC_START, (uint8_t*)&tag, sizeof(tag) - 20));\n\n\tfseek(binfile, 0L, SEEK_SET);\n\tfwrite(&tag, sizeof(uint8_t), sizeof(tag), binfile);\n\n    fflush(binfile);\n\tfclose(binfile);\n\n\treturn 0;\n}\n\nint main(int argc, char **argv)\n{\n    int c, i;\n\tchar *kernel, *rootfs, *bin;\n\tuint32_t flash_start, image_offset, block_size, load_address, entry;\n\tflash_start = image_offset = block_size = load_address = entry = 0;\n\tstruct gengetopt_args_info parsed_args;\n\n\tkernel = rootfs = bin = NULL;\n\n\tif (cmdline_parser(argc, argv, &parsed_args)) {\n\t  exit(1);\n\t}\n\n\tprintf(\"Broadcom 63xx image tagger - v2.0.0\\n\");\n\tprintf(\"Copyright (C) 2008 Axel Gembe\\n\");\n\tprintf(\"Copyright (C) 2009-2010 Daniel Dickinson\\n\");\n\tprintf(\"Licensed under the terms of the Gnu General Public License\\n\");\n\n\tkernel = parsed_args.kernel_arg;\n\trootfs = parsed_args.rootfs_arg;\n\tbin = parsed_args.output_arg;\n\tif (strlen(parsed_args.tag_version_arg) >= TAGVER_LEN) {\n\t  fprintf(stderr, \"Error: Tag Version (tag_version,v) too long.\\n\");\n\t  exit(1);\n\t}\n\tif (strlen(parsed_args.boardid_arg) >= BOARDID_LEN) {\n\t  fprintf(stderr, \"Error: Board ID (boardid,b) too long.\\n\");\n\t  exit(1);\n\t}\n\tif (strlen(parsed_args.chipid_arg) >= CHIPID_LEN) {\n\t  fprintf(stderr, \"Error: Chip ID (chipid,c) too long.\\n\");\n\t  exit(1);\n\t}\n\tif (strlen(parsed_args.signature_arg) >= SIG1_LEN) {\n\t  fprintf(stderr, \"Error: Magic string (signature,a) too long.\\n\");\n\t  exit(1);\n\t}\n\tif (strlen(parsed_args.signature2_arg) >= SIG2_LEN) {\n\t  fprintf(stderr, \"Error: Second magic string (signature2,m) too long.\\n\");\n\t  exit(1);\n\t}\n\tif (parsed_args.layoutver_given) {\n\t  if (strlen(parsed_args.layoutver_arg) > FLASHLAYOUTVER_LEN) {\n\t\tfprintf(stderr, \"Error: Flash layout version (layoutver,y) too long.\\n\");\n\t\texit(1);\n\t  }\n\t}\n\tif (parsed_args.rsa_signature_given) {\n\t  if (strlen(parsed_args.rsa_signature_arg) > RSASIG_LEN) {\n\t\tfprintf(stderr, \"Error: RSA Signature (rsa_signature,r) too long.\\n\");\n\t\texit(1);\n\t  }\n\t}\n\n\tif (parsed_args.info1_given) {\n\t  if (strlen(parsed_args.info1_arg) >= TAGINFO1_LEN) {\n\t\tfprintf(stderr, \"Error: Vendor Information 1 (info1) too long.\\n\");\n\t\texit(1);\n\t  }\n\t}\n\n\tif (parsed_args.info2_given) {\n\t  if (strlen(parsed_args.info2_arg) >= TAGINFO2_LEN) {\n\t\tfprintf(stderr, \"Error: Vendor Information 2 (info2) too long.\\n\");\n\t\texit(1);\n\t  }\n\t}\n\n\tif (parsed_args.altinfo_given) {\n\t  if (strlen(parsed_args.altinfo_arg) >= ALTTAGINFO_LEN) {\n\t\tfprintf(stderr, \"Error: Vendor Information 1 (info1) too long.\\n\");\n\t\texit(1);\n\t  }\n\t}\n\n\tif (parsed_args.pad_given) {\n\t  if (parsed_args.pad_arg < 0) {\n\t\tfprintf(stderr, \"Error: pad size must be positive.\\r\");\n\t\texit(1);\n\t  }\n\t}\n\n\tflash_start = strtoul(parsed_args.flash_start_arg, NULL, 16);\n\timage_offset = strtoul(parsed_args.image_offset_arg, NULL, 16);\n\tblock_size = strtoul(parsed_args.block_size_arg, NULL, 16);\n\n\tif (!parsed_args.kernel_file_has_header_flag) {\n\t  load_address = strtoul(parsed_args.load_addr_arg, NULL, 16);\n\t  entry = strtoul(parsed_args.entry_arg, NULL, 16);\n\t  if (load_address == 0) {\n\t\tfprintf(stderr, \"Error: Invalid value for load address\\n\");\n\t  }\n\t  if (entry == 0) {\n\t\tfprintf(stderr, \"Error: Invalid value for entry\\n\");\n\t  }\n\t}\n\t\n\treturn tagfile(kernel, rootfs, bin, &parsed_args, flash_start, image_offset, block_size, load_address, entry);\n}\n"
  },
  {
    "path": "src/firmware-tools/imagetag.ggo",
    "content": "# Command line option parsing generator file for imagetag\n# Supplied-To: gengetopt\n#\n# Copyright 2010 Daniel Dickinson <openwrt@cshore.neomailbox.net>\n#\n# This file is subject to the terms and conditions of the GNU General Public\n# License.  See the file \"COPYING\" in the main directory of this archive\n# for more details.\n#\n\npackage \"imagetag\"\nversion \"2.0.0\"\npurpose \"Generate image with CFE imagetag for Broadcom 63xx routers.\"\ndescription \"Copyright (C) 2008 Axel Gembe\nCopyright (C) 2009-2010 Daniel Dickinson\nLicensed unter the terms of the Gnu General Public License.\n\nGiven a root filesystem, a linux kernel, and an optional CFE, generates an image with an imagetag for a Broadcom 63xx-based router.  Additional parameters to be specified depend on the specfic brand and model of router.\"\nargs \"--file-name=imagetag_cmdline\"\n\noption \"kernel\" i \"File with LZMA compressed kernel to include in the image.\" string typestr=\"filename\"  required\noption \"rootfs\" f \"File with RootFS to include in the image.\" string typestr=\"filename\" required\noption \"output\" o \"Name of output file.\" string typestr=\"filename\" required\noption \"cfe\" - \"File with CFE to include in the image.\" string typestr=\"filename\" optional\noption \"boardid\" b \"Board ID to set in the image (must match what router expects, e.g. \\\"96345GW2\\\").\" string required\noption \"chipid\" c \"Chip ID to set in the image (must match the actual hardware, e.g. \\\"6345\\\").\" string required\noption \"flash-start\" s \"Flash start address.\" string typestr=\"address\" optional default=\"0xBFC00000\"\noption \"image-offset\" n \"Offset from start address for the first byte after the CFE (in memory).\" string typestr=\"offset\" default=\"0x10000\" optional\noption \"tag-version\" v \"Version number for imagetag format.\" string default=\"6\" optional\noption \"signature\" a \"Magic string (signature), for boards that need it.\" string default=\"Broadcom Corporatio\" optional\noption \"signature2\" m \"Second magic string (signature2).\" string default=\"ver. 2.0\" optional\noption \"block-size\" k \"Flash erase block size.\" string optional default=\"0x10000\"\noption \"load-addr\" l \"Kernel load address.\" string typestr=\"address\" required\noption \"entry\" e \"Address where the kernel entry point will be for booting.\" string typestr=\"address\" required\noption \"layoutver\" y \"Flash layout version (version 2.2x of the Broadcom code requires this).\" string optional\noption \"info1\" 1 \"String for first vendor information section.\" string optional\noption \"altinfo\" - \"String for vendor information section (alternate/pirelli).\" string optional\noption \"info2\" 2 \"String for second vendor information section.\" string optional\noption \"root-first\" - \"Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory).\" flag off\noption \"rsa-signature\" r \"String for RSA Signature section.\" string optional\noption \"second-image-flag\" - \"Dual Image Flag (2=not-specified).\" values=\"0\", \"1\", \"2\" default=\"2\" typestr=\"flag-value\" optional\noption \"inactive\" - \"Inactive Flag (2=not-specified).\" values=\"0\", \"1\", \"2\" default=\"2\" typestr=\"flag-value\" optional\noption \"reserved2\" - \"String for second reserved section.\" string optional\noption \"kernel-file-has-header\" - \"Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed\" flag off\noption \"pad\" p \"Pad the image to this size if smaller (in MiB)\" int typestr=\"size (in MiB)\" optional\n"
  },
  {
    "path": "src/firmware-tools/imagetag_cmdline.c",
    "content": "/*\n  File autogenerated by gengetopt version 2.22.4\n  generated with the following command:\n  gengetopt --file-name=imagetag_cmdline --file-name=imagetag_cmdline\n\n  The developers of gengetopt consider the fixed text that goes in all\n  gengetopt output files to be in the public domain:\n  we make no copyright claims on it.\n*/\n\n/* If we use autoconf.  */\n#ifdef HAVE_CONFIG_H\n#include \"config.h\"\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#ifndef FIX_UNUSED\n#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */\n#endif\n\n#include <getopt.h>\n\n#include \"imagetag_cmdline.h\"\n\nconst char *gengetopt_args_info_purpose = \"Generate image with CFE imagetag for Broadcom 63xx routers.\";\n\nconst char *gengetopt_args_info_usage = \"Usage: imagetag [OPTIONS]...\";\n\nconst char *gengetopt_args_info_description = \"Copyright (C) 2008 Axel Gembe\\nCopyright (C) 2009-2010 Daniel Dickinson\\nLicensed unter the terms of the Gnu General Public License.\\n\\nGiven a root filesystem, a linux kernel, and an optional CFE, generates an \\nimage with an imagetag for a Broadcom 63xx-based router.  Additional parameters \\nto be specified depend on the specfic brand and model of router.\";\n\nconst char *gengetopt_args_info_help[] = {\n  \"  -h, --help                    Print help and exit\",\n  \"  -V, --version                 Print version and exit\",\n  \"  -i, --kernel=filename         File with LZMA compressed kernel to include in \\n                                  the image.\",\n  \"  -f, --rootfs=filename         File with RootFS to include in the image.\",\n  \"  -o, --output=filename         Name of output file.\",\n  \"      --cfe=filename            File with CFE to include in the image.\",\n  \"  -b, --boardid=STRING          Board ID to set in the image (must match what \\n                                  router expects, e.g. \\\"96345GW2\\\").\",\n  \"  -c, --chipid=STRING           Chip ID to set in the image (must match the \\n                                  actual hardware, e.g. \\\"6345\\\").\",\n  \"  -s, --flash-start=address     Flash start address.  (default=`0xBFC00000')\",\n  \"  -n, --image-offset=offset     Offset from start address for the first byte \\n                                  after the CFE (in memory).  \\n                                  (default=`0x10000')\",\n  \"  -v, --tag-version=STRING      Version number for imagetag format.  \\n                                  (default=`6')\",\n  \"  -a, --signature=STRING        Magic string (signature), for boards that need \\n                                  it.  (default=`Broadcom Corporatio')\",\n  \"  -m, --signature2=STRING       Second magic string (signature2).  \\n                                  (default=`ver. 2.0')\",\n  \"  -k, --block-size=STRING       Flash erase block size.  (default=`0x10000')\",\n  \"  -l, --load-addr=address       Kernel load address.\",\n  \"  -e, --entry=address           Address where the kernel entry point will be \\n                                  for booting.\",\n  \"  -y, --layoutver=STRING        Flash layout version (version 2.2x of the \\n                                  Broadcom code requires this).\",\n  \"  -1, --info1=STRING            String for first vendor information section.\",\n  \"      --altinfo=STRING          String for vendor information section \\n                                  (alternate/pirelli).\",\n  \"  -2, --info2=STRING            String for second vendor information section.\",\n  \"      --root-first              Put the rootfs before the kernel (only for \\n                                  stock images, e.g. captured from the router's \\n                                  flash memory).  (default=off)\",\n  \"  -r, --rsa-signature=STRING    String for RSA Signature section.\",\n  \"      --second-image-flag=flag-value\\n                                Dual Image Flag (2=not-specified).  (possible \\n                                  values=\\\"0\\\", \\\"1\\\", \\\"2\\\" default=`2')\",\n  \"      --inactive=flag-value     Inactive Flag (2=not-specified).  (possible \\n                                  values=\\\"0\\\", \\\"1\\\", \\\"2\\\" default=`2')\",\n  \"      --reserved2=STRING        String for second reserved section.\",\n  \"      --kernel-file-has-header  Indicates that the kernel file includes the \\n                                  kernel header with correct load address and \\n                                  entry point, so no changes are needed  \\n                                  (default=off)\",\n  \"  -p, --pad=size (in MiB)       Pad the image to this size if smaller (in MiB)\",\n    0\n};\n\ntypedef enum {ARG_NO\n  , ARG_FLAG\n  , ARG_STRING\n  , ARG_INT\n} cmdline_parser_arg_type;\n\nstatic\nvoid clear_given (struct gengetopt_args_info *args_info);\nstatic\nvoid clear_args (struct gengetopt_args_info *args_info);\n\nstatic int\ncmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,\n                        struct cmdline_parser_params *params, const char *additional_error);\n\nstatic int\ncmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);\n\nconst char *cmdline_parser_second_image_flag_values[] = {\"0\", \"1\", \"2\", 0}; /*< Possible values for second-image-flag. */\nconst char *cmdline_parser_inactive_values[] = {\"0\", \"1\", \"2\", 0}; /*< Possible values for inactive. */\n\nstatic char *\ngengetopt_strdup (const char *s);\n\nstatic\nvoid clear_given (struct gengetopt_args_info *args_info)\n{\n  args_info->help_given = 0 ;\n  args_info->version_given = 0 ;\n  args_info->kernel_given = 0 ;\n  args_info->rootfs_given = 0 ;\n  args_info->output_given = 0 ;\n  args_info->cfe_given = 0 ;\n  args_info->boardid_given = 0 ;\n  args_info->chipid_given = 0 ;\n  args_info->flash_start_given = 0 ;\n  args_info->image_offset_given = 0 ;\n  args_info->tag_version_given = 0 ;\n  args_info->signature_given = 0 ;\n  args_info->signature2_given = 0 ;\n  args_info->block_size_given = 0 ;\n  args_info->load_addr_given = 0 ;\n  args_info->entry_given = 0 ;\n  args_info->layoutver_given = 0 ;\n  args_info->info1_given = 0 ;\n  args_info->altinfo_given = 0 ;\n  args_info->info2_given = 0 ;\n  args_info->root_first_given = 0 ;\n  args_info->rsa_signature_given = 0 ;\n  args_info->second_image_flag_given = 0 ;\n  args_info->inactive_given = 0 ;\n  args_info->reserved2_given = 0 ;\n  args_info->kernel_file_has_header_given = 0 ;\n  args_info->pad_given = 0 ;\n}\n\nstatic\nvoid clear_args (struct gengetopt_args_info *args_info)\n{\n  FIX_UNUSED (args_info);\n  args_info->kernel_arg = NULL;\n  args_info->kernel_orig = NULL;\n  args_info->rootfs_arg = NULL;\n  args_info->rootfs_orig = NULL;\n  args_info->output_arg = NULL;\n  args_info->output_orig = NULL;\n  args_info->cfe_arg = NULL;\n  args_info->cfe_orig = NULL;\n  args_info->boardid_arg = NULL;\n  args_info->boardid_orig = NULL;\n  args_info->chipid_arg = NULL;\n  args_info->chipid_orig = NULL;\n  args_info->flash_start_arg = gengetopt_strdup (\"0xBFC00000\");\n  args_info->flash_start_orig = NULL;\n  args_info->image_offset_arg = gengetopt_strdup (\"0x10000\");\n  args_info->image_offset_orig = NULL;\n  args_info->tag_version_arg = gengetopt_strdup (\"6\");\n  args_info->tag_version_orig = NULL;\n  args_info->signature_arg = gengetopt_strdup (\"Broadcom Corporatio\");\n  args_info->signature_orig = NULL;\n  args_info->signature2_arg = gengetopt_strdup (\"ver. 2.0\");\n  args_info->signature2_orig = NULL;\n  args_info->block_size_arg = gengetopt_strdup (\"0x10000\");\n  args_info->block_size_orig = NULL;\n  args_info->load_addr_arg = NULL;\n  args_info->load_addr_orig = NULL;\n  args_info->entry_arg = NULL;\n  args_info->entry_orig = NULL;\n  args_info->layoutver_arg = NULL;\n  args_info->layoutver_orig = NULL;\n  args_info->info1_arg = NULL;\n  args_info->info1_orig = NULL;\n  args_info->altinfo_arg = NULL;\n  args_info->altinfo_orig = NULL;\n  args_info->info2_arg = NULL;\n  args_info->info2_orig = NULL;\n  args_info->root_first_flag = 0;\n  args_info->rsa_signature_arg = NULL;\n  args_info->rsa_signature_orig = NULL;\n  args_info->second_image_flag_arg = gengetopt_strdup (\"2\");\n  args_info->second_image_flag_orig = NULL;\n  args_info->inactive_arg = gengetopt_strdup (\"2\");\n  args_info->inactive_orig = NULL;\n  args_info->reserved2_arg = NULL;\n  args_info->reserved2_orig = NULL;\n  args_info->kernel_file_has_header_flag = 0;\n  args_info->pad_orig = NULL;\n  \n}\n\nstatic\nvoid init_args_info(struct gengetopt_args_info *args_info)\n{\n\n\n  args_info->help_help = gengetopt_args_info_help[0] ;\n  args_info->version_help = gengetopt_args_info_help[1] ;\n  args_info->kernel_help = gengetopt_args_info_help[2] ;\n  args_info->rootfs_help = gengetopt_args_info_help[3] ;\n  args_info->output_help = gengetopt_args_info_help[4] ;\n  args_info->cfe_help = gengetopt_args_info_help[5] ;\n  args_info->boardid_help = gengetopt_args_info_help[6] ;\n  args_info->chipid_help = gengetopt_args_info_help[7] ;\n  args_info->flash_start_help = gengetopt_args_info_help[8] ;\n  args_info->image_offset_help = gengetopt_args_info_help[9] ;\n  args_info->tag_version_help = gengetopt_args_info_help[10] ;\n  args_info->signature_help = gengetopt_args_info_help[11] ;\n  args_info->signature2_help = gengetopt_args_info_help[12] ;\n  args_info->block_size_help = gengetopt_args_info_help[13] ;\n  args_info->load_addr_help = gengetopt_args_info_help[14] ;\n  args_info->entry_help = gengetopt_args_info_help[15] ;\n  args_info->layoutver_help = gengetopt_args_info_help[16] ;\n  args_info->info1_help = gengetopt_args_info_help[17] ;\n  args_info->altinfo_help = gengetopt_args_info_help[18] ;\n  args_info->info2_help = gengetopt_args_info_help[19] ;\n  args_info->root_first_help = gengetopt_args_info_help[20] ;\n  args_info->rsa_signature_help = gengetopt_args_info_help[21] ;\n  args_info->second_image_flag_help = gengetopt_args_info_help[22] ;\n  args_info->inactive_help = gengetopt_args_info_help[23] ;\n  args_info->reserved2_help = gengetopt_args_info_help[24] ;\n  args_info->kernel_file_has_header_help = gengetopt_args_info_help[25] ;\n  args_info->pad_help = gengetopt_args_info_help[26] ;\n  \n}\n\nvoid\ncmdline_parser_print_version (void)\n{\n  printf (\"%s %s\\n\",\n     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),\n     CMDLINE_PARSER_VERSION);\n}\n\nstatic void print_help_common(void) {\n  cmdline_parser_print_version ();\n\n  if (strlen(gengetopt_args_info_purpose) > 0)\n    printf(\"\\n%s\\n\", gengetopt_args_info_purpose);\n\n  if (strlen(gengetopt_args_info_usage) > 0)\n    printf(\"\\n%s\\n\", gengetopt_args_info_usage);\n\n  printf(\"\\n\");\n\n  if (strlen(gengetopt_args_info_description) > 0)\n    printf(\"%s\\n\\n\", gengetopt_args_info_description);\n}\n\nvoid\ncmdline_parser_print_help (void)\n{\n  int i = 0;\n  print_help_common();\n  while (gengetopt_args_info_help[i])\n    printf(\"%s\\n\", gengetopt_args_info_help[i++]);\n}\n\nvoid\ncmdline_parser_init (struct gengetopt_args_info *args_info)\n{\n  clear_given (args_info);\n  clear_args (args_info);\n  init_args_info (args_info);\n}\n\nvoid\ncmdline_parser_params_init(struct cmdline_parser_params *params)\n{\n  if (params)\n    { \n      params->override = 0;\n      params->initialize = 1;\n      params->check_required = 1;\n      params->check_ambiguity = 0;\n      params->print_errors = 1;\n    }\n}\n\nstruct cmdline_parser_params *\ncmdline_parser_params_create(void)\n{\n  struct cmdline_parser_params *params = \n    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));\n  cmdline_parser_params_init(params);  \n  return params;\n}\n\nstatic void\nfree_string_field (char **s)\n{\n  if (*s)\n    {\n      free (*s);\n      *s = 0;\n    }\n}\n\n\nstatic void\ncmdline_parser_release (struct gengetopt_args_info *args_info)\n{\n\n  free_string_field (&(args_info->kernel_arg));\n  free_string_field (&(args_info->kernel_orig));\n  free_string_field (&(args_info->rootfs_arg));\n  free_string_field (&(args_info->rootfs_orig));\n  free_string_field (&(args_info->output_arg));\n  free_string_field (&(args_info->output_orig));\n  free_string_field (&(args_info->cfe_arg));\n  free_string_field (&(args_info->cfe_orig));\n  free_string_field (&(args_info->boardid_arg));\n  free_string_field (&(args_info->boardid_orig));\n  free_string_field (&(args_info->chipid_arg));\n  free_string_field (&(args_info->chipid_orig));\n  free_string_field (&(args_info->flash_start_arg));\n  free_string_field (&(args_info->flash_start_orig));\n  free_string_field (&(args_info->image_offset_arg));\n  free_string_field (&(args_info->image_offset_orig));\n  free_string_field (&(args_info->tag_version_arg));\n  free_string_field (&(args_info->tag_version_orig));\n  free_string_field (&(args_info->signature_arg));\n  free_string_field (&(args_info->signature_orig));\n  free_string_field (&(args_info->signature2_arg));\n  free_string_field (&(args_info->signature2_orig));\n  free_string_field (&(args_info->block_size_arg));\n  free_string_field (&(args_info->block_size_orig));\n  free_string_field (&(args_info->load_addr_arg));\n  free_string_field (&(args_info->load_addr_orig));\n  free_string_field (&(args_info->entry_arg));\n  free_string_field (&(args_info->entry_orig));\n  free_string_field (&(args_info->layoutver_arg));\n  free_string_field (&(args_info->layoutver_orig));\n  free_string_field (&(args_info->info1_arg));\n  free_string_field (&(args_info->info1_orig));\n  free_string_field (&(args_info->altinfo_arg));\n  free_string_field (&(args_info->altinfo_orig));\n  free_string_field (&(args_info->info2_arg));\n  free_string_field (&(args_info->info2_orig));\n  free_string_field (&(args_info->rsa_signature_arg));\n  free_string_field (&(args_info->rsa_signature_orig));\n  free_string_field (&(args_info->second_image_flag_arg));\n  free_string_field (&(args_info->second_image_flag_orig));\n  free_string_field (&(args_info->inactive_arg));\n  free_string_field (&(args_info->inactive_orig));\n  free_string_field (&(args_info->reserved2_arg));\n  free_string_field (&(args_info->reserved2_orig));\n  free_string_field (&(args_info->pad_orig));\n  \n  \n\n  clear_given (args_info);\n}\n\n/**\n * @param val the value to check\n * @param values the possible values\n * @return the index of the matched value:\n * -1 if no value matched,\n * -2 if more than one value has matched\n */\nstatic int\ncheck_possible_values(const char *val, const char *values[])\n{\n  int i, found, last;\n  size_t len;\n\n  if (!val)   /* otherwise strlen() crashes below */\n    return -1; /* -1 means no argument for the option */\n\n  found = last = 0;\n\n  for (i = 0, len = strlen(val); values[i]; ++i)\n    {\n      if (strncmp(val, values[i], len) == 0)\n        {\n          ++found;\n          last = i;\n          if (strlen(values[i]) == len)\n            return i; /* exact macth no need to check more */\n        }\n    }\n\n  if (found == 1) /* one match: OK */\n    return last;\n\n  return (found ? -2 : -1); /* return many values or none matched */\n}\n\n\nstatic void\nwrite_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])\n{\n  int found = -1;\n  if (arg) {\n    if (values) {\n      found = check_possible_values(arg, values);      \n    }\n    if (found >= 0)\n      fprintf(outfile, \"%s=\\\"%s\\\" # %s\\n\", opt, arg, values[found]);\n    else\n      fprintf(outfile, \"%s=\\\"%s\\\"\\n\", opt, arg);\n  } else {\n    fprintf(outfile, \"%s\\n\", opt);\n  }\n}\n\n\nint\ncmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)\n{\n  int i = 0;\n\n  if (!outfile)\n    {\n      fprintf (stderr, \"%s: cannot dump options to stream\\n\", CMDLINE_PARSER_PACKAGE);\n      return EXIT_FAILURE;\n    }\n\n  if (args_info->help_given)\n    write_into_file(outfile, \"help\", 0, 0 );\n  if (args_info->version_given)\n    write_into_file(outfile, \"version\", 0, 0 );\n  if (args_info->kernel_given)\n    write_into_file(outfile, \"kernel\", args_info->kernel_orig, 0);\n  if (args_info->rootfs_given)\n    write_into_file(outfile, \"rootfs\", args_info->rootfs_orig, 0);\n  if (args_info->output_given)\n    write_into_file(outfile, \"output\", args_info->output_orig, 0);\n  if (args_info->cfe_given)\n    write_into_file(outfile, \"cfe\", args_info->cfe_orig, 0);\n  if (args_info->boardid_given)\n    write_into_file(outfile, \"boardid\", args_info->boardid_orig, 0);\n  if (args_info->chipid_given)\n    write_into_file(outfile, \"chipid\", args_info->chipid_orig, 0);\n  if (args_info->flash_start_given)\n    write_into_file(outfile, \"flash-start\", args_info->flash_start_orig, 0);\n  if (args_info->image_offset_given)\n    write_into_file(outfile, \"image-offset\", args_info->image_offset_orig, 0);\n  if (args_info->tag_version_given)\n    write_into_file(outfile, \"tag-version\", args_info->tag_version_orig, 0);\n  if (args_info->signature_given)\n    write_into_file(outfile, \"signature\", args_info->signature_orig, 0);\n  if (args_info->signature2_given)\n    write_into_file(outfile, \"signature2\", args_info->signature2_orig, 0);\n  if (args_info->block_size_given)\n    write_into_file(outfile, \"block-size\", args_info->block_size_orig, 0);\n  if (args_info->load_addr_given)\n    write_into_file(outfile, \"load-addr\", args_info->load_addr_orig, 0);\n  if (args_info->entry_given)\n    write_into_file(outfile, \"entry\", args_info->entry_orig, 0);\n  if (args_info->layoutver_given)\n    write_into_file(outfile, \"layoutver\", args_info->layoutver_orig, 0);\n  if (args_info->info1_given)\n    write_into_file(outfile, \"info1\", args_info->info1_orig, 0);\n  if (args_info->altinfo_given)\n    write_into_file(outfile, \"altinfo\", args_info->altinfo_orig, 0);\n  if (args_info->info2_given)\n    write_into_file(outfile, \"info2\", args_info->info2_orig, 0);\n  if (args_info->root_first_given)\n    write_into_file(outfile, \"root-first\", 0, 0 );\n  if (args_info->rsa_signature_given)\n    write_into_file(outfile, \"rsa-signature\", args_info->rsa_signature_orig, 0);\n  if (args_info->second_image_flag_given)\n    write_into_file(outfile, \"second-image-flag\", args_info->second_image_flag_orig, cmdline_parser_second_image_flag_values);\n  if (args_info->inactive_given)\n    write_into_file(outfile, \"inactive\", args_info->inactive_orig, cmdline_parser_inactive_values);\n  if (args_info->reserved2_given)\n    write_into_file(outfile, \"reserved2\", args_info->reserved2_orig, 0);\n  if (args_info->kernel_file_has_header_given)\n    write_into_file(outfile, \"kernel-file-has-header\", 0, 0 );\n  if (args_info->pad_given)\n    write_into_file(outfile, \"pad\", args_info->pad_orig, 0);\n  \n\n  i = EXIT_SUCCESS;\n  return i;\n}\n\nint\ncmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)\n{\n  FILE *outfile;\n  int i = 0;\n\n  outfile = fopen(filename, \"w\");\n\n  if (!outfile)\n    {\n      fprintf (stderr, \"%s: cannot open file for writing: %s\\n\", CMDLINE_PARSER_PACKAGE, filename);\n      return EXIT_FAILURE;\n    }\n\n  i = cmdline_parser_dump(outfile, args_info);\n  fclose (outfile);\n\n  return i;\n}\n\nvoid\ncmdline_parser_free (struct gengetopt_args_info *args_info)\n{\n  cmdline_parser_release (args_info);\n}\n\n/** @brief replacement of strdup, which is not standard */\nchar *\ngengetopt_strdup (const char *s)\n{\n  char *result = 0;\n  if (!s)\n    return result;\n\n  result = (char*)malloc(strlen(s) + 1);\n  if (result == (char*)0)\n    return (char*)0;\n  strcpy(result, s);\n  return result;\n}\n\nint\ncmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)\n{\n  return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);\n}\n\nint\ncmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,\n                   struct cmdline_parser_params *params)\n{\n  int result;\n  result = cmdline_parser_internal (argc, argv, args_info, params, 0);\n\n  if (result == EXIT_FAILURE)\n    {\n      cmdline_parser_free (args_info);\n      exit (EXIT_FAILURE);\n    }\n  \n  return result;\n}\n\nint\ncmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)\n{\n  int result;\n  struct cmdline_parser_params params;\n  \n  params.override = override;\n  params.initialize = initialize;\n  params.check_required = check_required;\n  params.check_ambiguity = 0;\n  params.print_errors = 1;\n\n  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);\n\n  if (result == EXIT_FAILURE)\n    {\n      cmdline_parser_free (args_info);\n      exit (EXIT_FAILURE);\n    }\n  \n  return result;\n}\n\nint\ncmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)\n{\n  int result = EXIT_SUCCESS;\n\n  if (cmdline_parser_required2(args_info, prog_name, 0) > 0)\n    result = EXIT_FAILURE;\n\n  if (result == EXIT_FAILURE)\n    {\n      cmdline_parser_free (args_info);\n      exit (EXIT_FAILURE);\n    }\n  \n  return result;\n}\n\nint\ncmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)\n{\n  int error = 0;\n  FIX_UNUSED (additional_error);\n\n  /* checks for required options */\n  if (! args_info->kernel_given)\n    {\n      fprintf (stderr, \"%s: '--kernel' ('-i') option required%s\\n\", prog_name, (additional_error ? additional_error : \"\"));\n      error = 1;\n    }\n  \n  if (! args_info->rootfs_given)\n    {\n      fprintf (stderr, \"%s: '--rootfs' ('-f') option required%s\\n\", prog_name, (additional_error ? additional_error : \"\"));\n      error = 1;\n    }\n  \n  if (! args_info->output_given)\n    {\n      fprintf (stderr, \"%s: '--output' ('-o') option required%s\\n\", prog_name, (additional_error ? additional_error : \"\"));\n      error = 1;\n    }\n  \n  if (! args_info->boardid_given)\n    {\n      fprintf (stderr, \"%s: '--boardid' ('-b') option required%s\\n\", prog_name, (additional_error ? additional_error : \"\"));\n      error = 1;\n    }\n  \n  if (! args_info->chipid_given)\n    {\n      fprintf (stderr, \"%s: '--chipid' ('-c') option required%s\\n\", prog_name, (additional_error ? additional_error : \"\"));\n      error = 1;\n    }\n  \n  if (! args_info->load_addr_given)\n    {\n      fprintf (stderr, \"%s: '--load-addr' ('-l') option required%s\\n\", prog_name, (additional_error ? additional_error : \"\"));\n      error = 1;\n    }\n  \n  if (! args_info->entry_given)\n    {\n      fprintf (stderr, \"%s: '--entry' ('-e') option required%s\\n\", prog_name, (additional_error ? additional_error : \"\"));\n      error = 1;\n    }\n  \n  \n  /* checks for dependences among options */\n\n  return error;\n}\n\n\nstatic char *package_name = 0;\n\n/**\n * @brief updates an option\n * @param field the generic pointer to the field to update\n * @param orig_field the pointer to the orig field\n * @param field_given the pointer to the number of occurrence of this option\n * @param prev_given the pointer to the number of occurrence already seen\n * @param value the argument for this option (if null no arg was specified)\n * @param possible_values the possible values for this option (if specified)\n * @param default_value the default value (in case the option only accepts fixed values)\n * @param arg_type the type of this option\n * @param check_ambiguity @see cmdline_parser_params.check_ambiguity\n * @param override @see cmdline_parser_params.override\n * @param no_free whether to free a possible previous value\n * @param multiple_option whether this is a multiple option\n * @param long_opt the corresponding long option\n * @param short_opt the corresponding short option (or '-' if none)\n * @param additional_error possible further error specification\n */\nstatic\nint update_arg(void *field, char **orig_field,\n               unsigned int *field_given, unsigned int *prev_given, \n               char *value, const char *possible_values[],\n               const char *default_value,\n               cmdline_parser_arg_type arg_type,\n               int check_ambiguity, int override,\n               int no_free, int multiple_option,\n               const char *long_opt, char short_opt,\n               const char *additional_error)\n{\n  char *stop_char = 0;\n  const char *val = value;\n  int found;\n  char **string_field;\n  FIX_UNUSED (field);\n\n  stop_char = 0;\n  found = 0;\n\n  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))\n    {\n      if (short_opt != '-')\n        fprintf (stderr, \"%s: `--%s' (`-%c') option given more than once%s\\n\", \n               package_name, long_opt, short_opt,\n               (additional_error ? additional_error : \"\"));\n      else\n        fprintf (stderr, \"%s: `--%s' option given more than once%s\\n\", \n               package_name, long_opt,\n               (additional_error ? additional_error : \"\"));\n      return 1; /* failure */\n    }\n\n  if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0)\n    {\n      if (short_opt != '-')\n        fprintf (stderr, \"%s: %s argument, \\\"%s\\\", for option `--%s' (`-%c')%s\\n\", \n          package_name, (found == -2) ? \"ambiguous\" : \"invalid\", value, long_opt, short_opt,\n          (additional_error ? additional_error : \"\"));\n      else\n        fprintf (stderr, \"%s: %s argument, \\\"%s\\\", for option `--%s'%s\\n\", \n          package_name, (found == -2) ? \"ambiguous\" : \"invalid\", value, long_opt,\n          (additional_error ? additional_error : \"\"));\n      return 1; /* failure */\n    }\n    \n  if (field_given && *field_given && ! override)\n    return 0;\n  if (prev_given)\n    (*prev_given)++;\n  if (field_given)\n    (*field_given)++;\n  if (possible_values)\n    val = possible_values[found];\n\n  switch(arg_type) {\n  case ARG_FLAG:\n    *((int *)field) = !*((int *)field);\n    break;\n  case ARG_INT:\n    if (val) *((int *)field) = strtol (val, &stop_char, 0);\n    break;\n  case ARG_STRING:\n    if (val) {\n      string_field = (char **)field;\n      if (!no_free && *string_field)\n        free (*string_field); /* free previous string */\n      *string_field = gengetopt_strdup (val);\n    }\n    break;\n  default:\n    break;\n  };\n\n  /* check numeric conversion */\n  switch(arg_type) {\n  case ARG_INT:\n    if (val && !(stop_char && *stop_char == '\\0')) {\n      fprintf(stderr, \"%s: invalid numeric value: %s\\n\", package_name, val);\n      return 1; /* failure */\n    }\n    break;\n  default:\n    ;\n  };\n\n  /* store the original value */\n  switch(arg_type) {\n  case ARG_NO:\n  case ARG_FLAG:\n    break;\n  default:\n    if (value && orig_field) {\n      if (no_free) {\n        *orig_field = value;\n      } else {\n        if (*orig_field)\n          free (*orig_field); /* free previous string */\n        *orig_field = gengetopt_strdup (value);\n      }\n    }\n  };\n\n  return 0; /* OK */\n}\n\n\nint\ncmdline_parser_internal (\n  int argc, char **argv, struct gengetopt_args_info *args_info,\n                        struct cmdline_parser_params *params, const char *additional_error)\n{\n  int c;\t/* Character of the parsed option.  */\n\n  int error = 0;\n  struct gengetopt_args_info local_args_info;\n  \n  int override;\n  int initialize;\n  int check_required;\n  int check_ambiguity;\n  \n  package_name = argv[0];\n  \n  override = params->override;\n  initialize = params->initialize;\n  check_required = params->check_required;\n  check_ambiguity = params->check_ambiguity;\n\n  if (initialize)\n    cmdline_parser_init (args_info);\n\n  cmdline_parser_init (&local_args_info);\n\n  optarg = 0;\n  optind = 0;\n  opterr = params->print_errors;\n  optopt = '?';\n\n  while (1)\n    {\n      int option_index = 0;\n\n      static struct option long_options[] = {\n        { \"help\",\t0, NULL, 'h' },\n        { \"version\",\t0, NULL, 'V' },\n        { \"kernel\",\t1, NULL, 'i' },\n        { \"rootfs\",\t1, NULL, 'f' },\n        { \"output\",\t1, NULL, 'o' },\n        { \"cfe\",\t1, NULL, 0 },\n        { \"boardid\",\t1, NULL, 'b' },\n        { \"chipid\",\t1, NULL, 'c' },\n        { \"flash-start\",\t1, NULL, 's' },\n        { \"image-offset\",\t1, NULL, 'n' },\n        { \"tag-version\",\t1, NULL, 'v' },\n        { \"signature\",\t1, NULL, 'a' },\n        { \"signature2\",\t1, NULL, 'm' },\n        { \"block-size\",\t1, NULL, 'k' },\n        { \"load-addr\",\t1, NULL, 'l' },\n        { \"entry\",\t1, NULL, 'e' },\n        { \"layoutver\",\t1, NULL, 'y' },\n        { \"info1\",\t1, NULL, '1' },\n        { \"altinfo\",\t1, NULL, 0 },\n        { \"info2\",\t1, NULL, '2' },\n        { \"root-first\",\t0, NULL, 0 },\n        { \"rsa-signature\",\t1, NULL, 'r' },\n        { \"second-image-flag\",\t1, NULL, 0 },\n        { \"inactive\",\t1, NULL, 0 },\n        { \"reserved2\",\t1, NULL, 0 },\n        { \"kernel-file-has-header\",\t0, NULL, 0 },\n        { \"pad\",\t1, NULL, 'p' },\n        { 0,  0, 0, 0 }\n      };\n\n      c = getopt_long (argc, argv, \"hVi:f:o:b:c:s:n:v:a:m:k:l:e:y:1:2:r:p:\", long_options, &option_index);\n\n      if (c == -1) break;\t/* Exit from `while (1)' loop.  */\n\n      switch (c)\n        {\n        case 'h':\t/* Print help and exit.  */\n          cmdline_parser_print_help ();\n          cmdline_parser_free (&local_args_info);\n          exit (EXIT_SUCCESS);\n\n        case 'V':\t/* Print version and exit.  */\n          cmdline_parser_print_version ();\n          cmdline_parser_free (&local_args_info);\n          exit (EXIT_SUCCESS);\n\n        case 'i':\t/* File with LZMA compressed kernel to include in the image..  */\n        \n        \n          if (update_arg( (void *)&(args_info->kernel_arg), \n               &(args_info->kernel_orig), &(args_info->kernel_given),\n              &(local_args_info.kernel_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"kernel\", 'i',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'f':\t/* File with RootFS to include in the image..  */\n        \n        \n          if (update_arg( (void *)&(args_info->rootfs_arg), \n               &(args_info->rootfs_orig), &(args_info->rootfs_given),\n              &(local_args_info.rootfs_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"rootfs\", 'f',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'o':\t/* Name of output file..  */\n        \n        \n          if (update_arg( (void *)&(args_info->output_arg), \n               &(args_info->output_orig), &(args_info->output_given),\n              &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"output\", 'o',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'b':\t/* Board ID to set in the image (must match what router expects, e.g. \\\"96345GW2\\\")..  */\n        \n        \n          if (update_arg( (void *)&(args_info->boardid_arg), \n               &(args_info->boardid_orig), &(args_info->boardid_given),\n              &(local_args_info.boardid_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"boardid\", 'b',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'c':\t/* Chip ID to set in the image (must match the actual hardware, e.g. \\\"6345\\\")..  */\n        \n        \n          if (update_arg( (void *)&(args_info->chipid_arg), \n               &(args_info->chipid_orig), &(args_info->chipid_given),\n              &(local_args_info.chipid_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"chipid\", 'c',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 's':\t/* Flash start address..  */\n        \n        \n          if (update_arg( (void *)&(args_info->flash_start_arg), \n               &(args_info->flash_start_orig), &(args_info->flash_start_given),\n              &(local_args_info.flash_start_given), optarg, 0, \"0xBFC00000\", ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"flash-start\", 's',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'n':\t/* Offset from start address for the first byte after the CFE (in memory)..  */\n        \n        \n          if (update_arg( (void *)&(args_info->image_offset_arg), \n               &(args_info->image_offset_orig), &(args_info->image_offset_given),\n              &(local_args_info.image_offset_given), optarg, 0, \"0x10000\", ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"image-offset\", 'n',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'v':\t/* Version number for imagetag format..  */\n        \n        \n          if (update_arg( (void *)&(args_info->tag_version_arg), \n               &(args_info->tag_version_orig), &(args_info->tag_version_given),\n              &(local_args_info.tag_version_given), optarg, 0, \"6\", ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"tag-version\", 'v',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'a':\t/* Magic string (signature), for boards that need it..  */\n        \n        \n          if (update_arg( (void *)&(args_info->signature_arg), \n               &(args_info->signature_orig), &(args_info->signature_given),\n              &(local_args_info.signature_given), optarg, 0, \"Broadcom Corporatio\", ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"signature\", 'a',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'm':\t/* Second magic string (signature2)..  */\n        \n        \n          if (update_arg( (void *)&(args_info->signature2_arg), \n               &(args_info->signature2_orig), &(args_info->signature2_given),\n              &(local_args_info.signature2_given), optarg, 0, \"ver. 2.0\", ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"signature2\", 'm',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'k':\t/* Flash erase block size..  */\n        \n        \n          if (update_arg( (void *)&(args_info->block_size_arg), \n               &(args_info->block_size_orig), &(args_info->block_size_given),\n              &(local_args_info.block_size_given), optarg, 0, \"0x10000\", ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"block-size\", 'k',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'l':\t/* Kernel load address..  */\n        \n        \n          if (update_arg( (void *)&(args_info->load_addr_arg), \n               &(args_info->load_addr_orig), &(args_info->load_addr_given),\n              &(local_args_info.load_addr_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"load-addr\", 'l',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'e':\t/* Address where the kernel entry point will be for booting..  */\n        \n        \n          if (update_arg( (void *)&(args_info->entry_arg), \n               &(args_info->entry_orig), &(args_info->entry_given),\n              &(local_args_info.entry_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"entry\", 'e',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'y':\t/* Flash layout version (version 2.2x of the Broadcom code requires this)..  */\n        \n        \n          if (update_arg( (void *)&(args_info->layoutver_arg), \n               &(args_info->layoutver_orig), &(args_info->layoutver_given),\n              &(local_args_info.layoutver_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"layoutver\", 'y',\n              additional_error))\n            goto failure;\n        \n          break;\n        case '1':\t/* String for first vendor information section..  */\n        \n        \n          if (update_arg( (void *)&(args_info->info1_arg), \n               &(args_info->info1_orig), &(args_info->info1_given),\n              &(local_args_info.info1_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"info1\", '1',\n              additional_error))\n            goto failure;\n        \n          break;\n        case '2':\t/* String for second vendor information section..  */\n        \n        \n          if (update_arg( (void *)&(args_info->info2_arg), \n               &(args_info->info2_orig), &(args_info->info2_given),\n              &(local_args_info.info2_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"info2\", '2',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'r':\t/* String for RSA Signature section..  */\n        \n        \n          if (update_arg( (void *)&(args_info->rsa_signature_arg), \n               &(args_info->rsa_signature_orig), &(args_info->rsa_signature_given),\n              &(local_args_info.rsa_signature_given), optarg, 0, 0, ARG_STRING,\n              check_ambiguity, override, 0, 0,\n              \"rsa-signature\", 'r',\n              additional_error))\n            goto failure;\n        \n          break;\n        case 'p':\t/* Pad the image to this size if smaller (in MiB).  */\n        \n        \n          if (update_arg( (void *)&(args_info->pad_arg), \n               &(args_info->pad_orig), &(args_info->pad_given),\n              &(local_args_info.pad_given), optarg, 0, 0, ARG_INT,\n              check_ambiguity, override, 0, 0,\n              \"pad\", 'p',\n              additional_error))\n            goto failure;\n        \n          break;\n\n        case 0:\t/* Long option with no short option */\n          /* File with CFE to include in the image..  */\n          if (strcmp (long_options[option_index].name, \"cfe\") == 0)\n          {\n          \n          \n            if (update_arg( (void *)&(args_info->cfe_arg), \n                 &(args_info->cfe_orig), &(args_info->cfe_given),\n                &(local_args_info.cfe_given), optarg, 0, 0, ARG_STRING,\n                check_ambiguity, override, 0, 0,\n                \"cfe\", '-',\n                additional_error))\n              goto failure;\n          \n          }\n          /* String for vendor information section (alternate/pirelli)..  */\n          else if (strcmp (long_options[option_index].name, \"altinfo\") == 0)\n          {\n          \n          \n            if (update_arg( (void *)&(args_info->altinfo_arg), \n                 &(args_info->altinfo_orig), &(args_info->altinfo_given),\n                &(local_args_info.altinfo_given), optarg, 0, 0, ARG_STRING,\n                check_ambiguity, override, 0, 0,\n                \"altinfo\", '-',\n                additional_error))\n              goto failure;\n          \n          }\n          /* Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory)..  */\n          else if (strcmp (long_options[option_index].name, \"root-first\") == 0)\n          {\n          \n          \n            if (update_arg((void *)&(args_info->root_first_flag), 0, &(args_info->root_first_given),\n                &(local_args_info.root_first_given), optarg, 0, 0, ARG_FLAG,\n                check_ambiguity, override, 1, 0, \"root-first\", '-',\n                additional_error))\n              goto failure;\n          \n          }\n          /* Dual Image Flag (2=not-specified)..  */\n          else if (strcmp (long_options[option_index].name, \"second-image-flag\") == 0)\n          {\n          \n          \n            if (update_arg( (void *)&(args_info->second_image_flag_arg), \n                 &(args_info->second_image_flag_orig), &(args_info->second_image_flag_given),\n                &(local_args_info.second_image_flag_given), optarg, cmdline_parser_second_image_flag_values, \"2\", ARG_STRING,\n                check_ambiguity, override, 0, 0,\n                \"second-image-flag\", '-',\n                additional_error))\n              goto failure;\n          \n          }\n          /* Inactive Flag (2=not-specified)..  */\n          else if (strcmp (long_options[option_index].name, \"inactive\") == 0)\n          {\n          \n          \n            if (update_arg( (void *)&(args_info->inactive_arg), \n                 &(args_info->inactive_orig), &(args_info->inactive_given),\n                &(local_args_info.inactive_given), optarg, cmdline_parser_inactive_values, \"2\", ARG_STRING,\n                check_ambiguity, override, 0, 0,\n                \"inactive\", '-',\n                additional_error))\n              goto failure;\n          \n          }\n          /* String for second reserved section..  */\n          else if (strcmp (long_options[option_index].name, \"reserved2\") == 0)\n          {\n          \n          \n            if (update_arg( (void *)&(args_info->reserved2_arg), \n                 &(args_info->reserved2_orig), &(args_info->reserved2_given),\n                &(local_args_info.reserved2_given), optarg, 0, 0, ARG_STRING,\n                check_ambiguity, override, 0, 0,\n                \"reserved2\", '-',\n                additional_error))\n              goto failure;\n          \n          }\n          /* Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed.  */\n          else if (strcmp (long_options[option_index].name, \"kernel-file-has-header\") == 0)\n          {\n          \n          \n            if (update_arg((void *)&(args_info->kernel_file_has_header_flag), 0, &(args_info->kernel_file_has_header_given),\n                &(local_args_info.kernel_file_has_header_given), optarg, 0, 0, ARG_FLAG,\n                check_ambiguity, override, 1, 0, \"kernel-file-has-header\", '-',\n                additional_error))\n              goto failure;\n          \n          }\n          \n          break;\n        case '?':\t/* Invalid option.  */\n          /* `getopt_long' already printed an error message.  */\n          goto failure;\n\n        default:\t/* bug: option not considered.  */\n          fprintf (stderr, \"%s: option unknown: %c%s\\n\", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : \"\"));\n          abort ();\n        } /* switch */\n    } /* while */\n\n\n\n  if (check_required)\n    {\n      error += cmdline_parser_required2 (args_info, argv[0], additional_error);\n    }\n\n  cmdline_parser_release (&local_args_info);\n\n  if ( error )\n    return (EXIT_FAILURE);\n\n  return 0;\n\nfailure:\n  \n  cmdline_parser_release (&local_args_info);\n  return (EXIT_FAILURE);\n}\n"
  },
  {
    "path": "src/firmware-tools/imagetag_cmdline.h",
    "content": "/** @file imagetag_cmdline.h\n *  @brief The header file for the command line option parser\n *  generated by GNU Gengetopt version 2.22.4\n *  http://www.gnu.org/software/gengetopt.\n *  DO NOT modify this file, since it can be overwritten\n *  @author GNU Gengetopt by Lorenzo Bettini */\n\n#ifndef IMAGETAG_CMDLINE_H\n#define IMAGETAG_CMDLINE_H\n\n/* If we use autoconf.  */\n#ifdef HAVE_CONFIG_H\n#include \"config.h\"\n#endif\n\n#include <stdio.h> /* for FILE */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif /* __cplusplus */\n\n#ifndef CMDLINE_PARSER_PACKAGE\n/** @brief the program name (used for printing errors) */\n#define CMDLINE_PARSER_PACKAGE \"imagetag\"\n#endif\n\n#ifndef CMDLINE_PARSER_PACKAGE_NAME\n/** @brief the complete program name (used for help and version) */\n#define CMDLINE_PARSER_PACKAGE_NAME \"imagetag\"\n#endif\n\n#ifndef CMDLINE_PARSER_VERSION\n/** @brief the program version */\n#define CMDLINE_PARSER_VERSION \"2.0.0\"\n#endif\n\n/** @brief Where the command line options are stored */\nstruct gengetopt_args_info\n{\n  const char *help_help; /**< @brief Print help and exit help description.  */\n  const char *version_help; /**< @brief Print version and exit help description.  */\n  char * kernel_arg;\t/**< @brief File with LZMA compressed kernel to include in the image..  */\n  char * kernel_orig;\t/**< @brief File with LZMA compressed kernel to include in the image. original value given at command line.  */\n  const char *kernel_help; /**< @brief File with LZMA compressed kernel to include in the image. help description.  */\n  char * rootfs_arg;\t/**< @brief File with RootFS to include in the image..  */\n  char * rootfs_orig;\t/**< @brief File with RootFS to include in the image. original value given at command line.  */\n  const char *rootfs_help; /**< @brief File with RootFS to include in the image. help description.  */\n  char * output_arg;\t/**< @brief Name of output file..  */\n  char * output_orig;\t/**< @brief Name of output file. original value given at command line.  */\n  const char *output_help; /**< @brief Name of output file. help description.  */\n  char * cfe_arg;\t/**< @brief File with CFE to include in the image..  */\n  char * cfe_orig;\t/**< @brief File with CFE to include in the image. original value given at command line.  */\n  const char *cfe_help; /**< @brief File with CFE to include in the image. help description.  */\n  char * boardid_arg;\t/**< @brief Board ID to set in the image (must match what router expects, e.g. \\\"96345GW2\\\")..  */\n  char * boardid_orig;\t/**< @brief Board ID to set in the image (must match what router expects, e.g. \\\"96345GW2\\\"). original value given at command line.  */\n  const char *boardid_help; /**< @brief Board ID to set in the image (must match what router expects, e.g. \\\"96345GW2\\\"). help description.  */\n  char * chipid_arg;\t/**< @brief Chip ID to set in the image (must match the actual hardware, e.g. \\\"6345\\\")..  */\n  char * chipid_orig;\t/**< @brief Chip ID to set in the image (must match the actual hardware, e.g. \\\"6345\\\"). original value given at command line.  */\n  const char *chipid_help; /**< @brief Chip ID to set in the image (must match the actual hardware, e.g. \\\"6345\\\"). help description.  */\n  char * flash_start_arg;\t/**< @brief Flash start address. (default='0xBFC00000').  */\n  char * flash_start_orig;\t/**< @brief Flash start address. original value given at command line.  */\n  const char *flash_start_help; /**< @brief Flash start address. help description.  */\n  char * image_offset_arg;\t/**< @brief Offset from start address for the first byte after the CFE (in memory). (default='0x10000').  */\n  char * image_offset_orig;\t/**< @brief Offset from start address for the first byte after the CFE (in memory). original value given at command line.  */\n  const char *image_offset_help; /**< @brief Offset from start address for the first byte after the CFE (in memory). help description.  */\n  char * tag_version_arg;\t/**< @brief Version number for imagetag format. (default='6').  */\n  char * tag_version_orig;\t/**< @brief Version number for imagetag format. original value given at command line.  */\n  const char *tag_version_help; /**< @brief Version number for imagetag format. help description.  */\n  char * signature_arg;\t/**< @brief Magic string (signature), for boards that need it. (default='Broadcom Corporatio').  */\n  char * signature_orig;\t/**< @brief Magic string (signature), for boards that need it. original value given at command line.  */\n  const char *signature_help; /**< @brief Magic string (signature), for boards that need it. help description.  */\n  char * signature2_arg;\t/**< @brief Second magic string (signature2). (default='ver. 2.0').  */\n  char * signature2_orig;\t/**< @brief Second magic string (signature2). original value given at command line.  */\n  const char *signature2_help; /**< @brief Second magic string (signature2). help description.  */\n  char * block_size_arg;\t/**< @brief Flash erase block size. (default='0x10000').  */\n  char * block_size_orig;\t/**< @brief Flash erase block size. original value given at command line.  */\n  const char *block_size_help; /**< @brief Flash erase block size. help description.  */\n  char * load_addr_arg;\t/**< @brief Kernel load address..  */\n  char * load_addr_orig;\t/**< @brief Kernel load address. original value given at command line.  */\n  const char *load_addr_help; /**< @brief Kernel load address. help description.  */\n  char * entry_arg;\t/**< @brief Address where the kernel entry point will be for booting..  */\n  char * entry_orig;\t/**< @brief Address where the kernel entry point will be for booting. original value given at command line.  */\n  const char *entry_help; /**< @brief Address where the kernel entry point will be for booting. help description.  */\n  char * layoutver_arg;\t/**< @brief Flash layout version (version 2.2x of the Broadcom code requires this)..  */\n  char * layoutver_orig;\t/**< @brief Flash layout version (version 2.2x of the Broadcom code requires this). original value given at command line.  */\n  const char *layoutver_help; /**< @brief Flash layout version (version 2.2x of the Broadcom code requires this). help description.  */\n  char * info1_arg;\t/**< @brief String for first vendor information section..  */\n  char * info1_orig;\t/**< @brief String for first vendor information section. original value given at command line.  */\n  const char *info1_help; /**< @brief String for first vendor information section. help description.  */\n  char * altinfo_arg;\t/**< @brief String for vendor information section (alternate/pirelli)..  */\n  char * altinfo_orig;\t/**< @brief String for vendor information section (alternate/pirelli). original value given at command line.  */\n  const char *altinfo_help; /**< @brief String for vendor information section (alternate/pirelli). help description.  */\n  char * info2_arg;\t/**< @brief String for second vendor information section..  */\n  char * info2_orig;\t/**< @brief String for second vendor information section. original value given at command line.  */\n  const char *info2_help; /**< @brief String for second vendor information section. help description.  */\n  int root_first_flag;\t/**< @brief Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory). (default=off).  */\n  const char *root_first_help; /**< @brief Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory). help description.  */\n  char * rsa_signature_arg;\t/**< @brief String for RSA Signature section..  */\n  char * rsa_signature_orig;\t/**< @brief String for RSA Signature section. original value given at command line.  */\n  const char *rsa_signature_help; /**< @brief String for RSA Signature section. help description.  */\n  char * second_image_flag_arg;\t/**< @brief Dual Image Flag (2=not-specified). (default='2').  */\n  char * second_image_flag_orig;\t/**< @brief Dual Image Flag (2=not-specified). original value given at command line.  */\n  const char *second_image_flag_help; /**< @brief Dual Image Flag (2=not-specified). help description.  */\n  char * inactive_arg;\t/**< @brief Inactive Flag (2=not-specified). (default='2').  */\n  char * inactive_orig;\t/**< @brief Inactive Flag (2=not-specified). original value given at command line.  */\n  const char *inactive_help; /**< @brief Inactive Flag (2=not-specified). help description.  */\n  char * reserved2_arg;\t/**< @brief String for second reserved section..  */\n  char * reserved2_orig;\t/**< @brief String for second reserved section. original value given at command line.  */\n  const char *reserved2_help; /**< @brief String for second reserved section. help description.  */\n  int kernel_file_has_header_flag;\t/**< @brief Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed (default=off).  */\n  const char *kernel_file_has_header_help; /**< @brief Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed help description.  */\n  int pad_arg;\t/**< @brief Pad the image to this size if smaller (in MiB).  */\n  char * pad_orig;\t/**< @brief Pad the image to this size if smaller (in MiB) original value given at command line.  */\n  const char *pad_help; /**< @brief Pad the image to this size if smaller (in MiB) help description.  */\n  \n  unsigned int help_given ;\t/**< @brief Whether help was given.  */\n  unsigned int version_given ;\t/**< @brief Whether version was given.  */\n  unsigned int kernel_given ;\t/**< @brief Whether kernel was given.  */\n  unsigned int rootfs_given ;\t/**< @brief Whether rootfs was given.  */\n  unsigned int output_given ;\t/**< @brief Whether output was given.  */\n  unsigned int cfe_given ;\t/**< @brief Whether cfe was given.  */\n  unsigned int boardid_given ;\t/**< @brief Whether boardid was given.  */\n  unsigned int chipid_given ;\t/**< @brief Whether chipid was given.  */\n  unsigned int flash_start_given ;\t/**< @brief Whether flash-start was given.  */\n  unsigned int image_offset_given ;\t/**< @brief Whether image-offset was given.  */\n  unsigned int tag_version_given ;\t/**< @brief Whether tag-version was given.  */\n  unsigned int signature_given ;\t/**< @brief Whether signature was given.  */\n  unsigned int signature2_given ;\t/**< @brief Whether signature2 was given.  */\n  unsigned int block_size_given ;\t/**< @brief Whether block-size was given.  */\n  unsigned int load_addr_given ;\t/**< @brief Whether load-addr was given.  */\n  unsigned int entry_given ;\t/**< @brief Whether entry was given.  */\n  unsigned int layoutver_given ;\t/**< @brief Whether layoutver was given.  */\n  unsigned int info1_given ;\t/**< @brief Whether info1 was given.  */\n  unsigned int altinfo_given ;\t/**< @brief Whether altinfo was given.  */\n  unsigned int info2_given ;\t/**< @brief Whether info2 was given.  */\n  unsigned int root_first_given ;\t/**< @brief Whether root-first was given.  */\n  unsigned int rsa_signature_given ;\t/**< @brief Whether rsa-signature was given.  */\n  unsigned int second_image_flag_given ;\t/**< @brief Whether second-image-flag was given.  */\n  unsigned int inactive_given ;\t/**< @brief Whether inactive was given.  */\n  unsigned int reserved2_given ;\t/**< @brief Whether reserved2 was given.  */\n  unsigned int kernel_file_has_header_given ;\t/**< @brief Whether kernel-file-has-header was given.  */\n  unsigned int pad_given ;\t/**< @brief Whether pad was given.  */\n\n} ;\n\n/** @brief The additional parameters to pass to parser functions */\nstruct cmdline_parser_params\n{\n  int override; /**< @brief whether to override possibly already present options (default 0) */\n  int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */\n  int check_required; /**< @brief whether to check that all required options were provided (default 1) */\n  int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */\n  int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */\n} ;\n\n/** @brief the purpose string of the program */\nextern const char *gengetopt_args_info_purpose;\n/** @brief the usage string of the program */\nextern const char *gengetopt_args_info_usage;\n/** @brief all the lines making the help output */\nextern const char *gengetopt_args_info_help[];\n\n/**\n * The command line parser\n * @param argc the number of command line options\n * @param argv the command line options\n * @param args_info the structure where option information will be stored\n * @return 0 if everything went fine, NON 0 if an error took place\n */\nint cmdline_parser (int argc, char **argv,\n  struct gengetopt_args_info *args_info);\n\n/**\n * The command line parser (version with additional parameters - deprecated)\n * @param argc the number of command line options\n * @param argv the command line options\n * @param args_info the structure where option information will be stored\n * @param override whether to override possibly already present options\n * @param initialize whether to initialize the option structure my_args_info\n * @param check_required whether to check that all required options were provided\n * @return 0 if everything went fine, NON 0 if an error took place\n * @deprecated use cmdline_parser_ext() instead\n */\nint cmdline_parser2 (int argc, char **argv,\n  struct gengetopt_args_info *args_info,\n  int override, int initialize, int check_required);\n\n/**\n * The command line parser (version with additional parameters)\n * @param argc the number of command line options\n * @param argv the command line options\n * @param args_info the structure where option information will be stored\n * @param params additional parameters for the parser\n * @return 0 if everything went fine, NON 0 if an error took place\n */\nint cmdline_parser_ext (int argc, char **argv,\n  struct gengetopt_args_info *args_info,\n  struct cmdline_parser_params *params);\n\n/**\n * Save the contents of the option struct into an already open FILE stream.\n * @param outfile the stream where to dump options\n * @param args_info the option struct to dump\n * @return 0 if everything went fine, NON 0 if an error took place\n */\nint cmdline_parser_dump(FILE *outfile,\n  struct gengetopt_args_info *args_info);\n\n/**\n * Save the contents of the option struct into a (text) file.\n * This file can be read by the config file parser (if generated by gengetopt)\n * @param filename the file where to save\n * @param args_info the option struct to save\n * @return 0 if everything went fine, NON 0 if an error took place\n */\nint cmdline_parser_file_save(const char *filename,\n  struct gengetopt_args_info *args_info);\n\n/**\n * Print the help\n */\nvoid cmdline_parser_print_help(void);\n/**\n * Print the version\n */\nvoid cmdline_parser_print_version(void);\n\n/**\n * Initializes all the fields a cmdline_parser_params structure \n * to their default values\n * @param params the structure to initialize\n */\nvoid cmdline_parser_params_init(struct cmdline_parser_params *params);\n\n/**\n * Allocates dynamically a cmdline_parser_params structure and initializes\n * all its fields to their default values\n * @return the created and initialized cmdline_parser_params structure\n */\nstruct cmdline_parser_params *cmdline_parser_params_create(void);\n\n/**\n * Initializes the passed gengetopt_args_info structure's fields\n * (also set default values for options that have a default)\n * @param args_info the structure to initialize\n */\nvoid cmdline_parser_init (struct gengetopt_args_info *args_info);\n/**\n * Deallocates the string fields of the gengetopt_args_info structure\n * (but does not deallocate the structure itself)\n * @param args_info the structure to deallocate\n */\nvoid cmdline_parser_free (struct gengetopt_args_info *args_info);\n\n/**\n * Checks that all the required options were specified\n * @param args_info the structure to check\n * @param prog_name the name of the program that will be used to print\n *   possible errors\n * @return\n */\nint cmdline_parser_required (struct gengetopt_args_info *args_info,\n  const char *prog_name);\n\nextern const char *cmdline_parser_second_image_flag_values[];  /**< @brief Possible values for second-image-flag. */\nextern const char *cmdline_parser_inactive_values[];  /**< @brief Possible values for inactive. */\n\n\n#ifdef __cplusplus\n}\n#endif /* __cplusplus */\n#endif /* IMAGETAG_CMDLINE_H */\n"
  },
  {
    "path": "src/firmware-tools/lzma2eva.c",
    "content": "/*\n    lzma2eva - convert lzma-compressed file to AVM EVA bootloader format\n    Copyright (C) 2007  Enrik Berkhan <Enrik.Berkhan@inka.de>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA\n*/\n\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <zlib.h> /* crc32 */\n\n#define checksum_add32(csum, data) \\\n  csum += ((uint8_t *)&data)[0]; \\\n  csum += ((uint8_t *)&data)[1]; \\\n  csum += ((uint8_t *)&data)[2]; \\\n  csum += ((uint8_t *)&data)[3];\n\nvoid\nusage(void)\n{\n  fprintf(stderr, \"usage: lzma2eva <loadadddr> <entry> <lzmafile> <evafile>\\n\");\n  exit(1);\n}\n\nvoid\npexit(const char *msg)\n{\n  perror(msg);\n  exit(1);\n}\n\nint\nmain(int argc, char *argv[])\n{\n\n  const char *infile, *outfile;\n  FILE *in, *out;\n  static const uint8_t buf[4096];\n  size_t elems;\n\n  uint8_t properties;\n  uint32_t dictsize;\n  uint64_t datasize;\n\n  uint32_t magic = 0xfeed1281L;\n  uint32_t reclength = 0;\n  fpos_t reclengthpos;\n  uint32_t loadaddress = 0;\n  uint32_t type = 0x075a0201L; /* might be 7Z 2.1? */\n  uint32_t checksum = 0;\n\n  uint32_t compsize = 0;\n  fpos_t compsizepos;\n  uint32_t datasize32 = 0;\n  uint32_t datacrc32 = crc32(0, 0, 0);\n\n  uint32_t zero = 0;\n  uint32_t entry = 0;\n\n  if (argc != 5)\n    usage();\n\n  /* \"parse\" command line */\n  loadaddress = strtoul(argv[1], 0, 0);\n  entry = strtoul(argv[2], 0, 0);\n  infile = argv[3];\n  outfile = argv[4];\n\n  in = fopen(infile, \"rb\");\n  if (!in)\n    pexit(\"fopen\");\n  out = fopen(outfile, \"w+b\");\n  if (!out)\n    pexit(\"fopen\");\n\n  /* read LZMA header */\n  if (1 != fread(&properties, sizeof properties, 1, in))\n    pexit(\"fread\");\n  if (1 != fread(&dictsize, sizeof dictsize, 1, in))\n    pexit(\"fread\");\n  if (1 != fread(&datasize, sizeof datasize, 1, in))\n    pexit(\"fread\");\n\n  /* write EVA header */\n  if (1 != fwrite(&magic, sizeof magic, 1, out))\n    pexit(\"fwrite\");\n  if (fgetpos(out, &reclengthpos))\n    pexit(\"fgetpos\");\n  if (1 != fwrite(&reclength, sizeof reclength, 1, out))\n    pexit(\"fwrite\");\n  if (1 != fwrite(&loadaddress, sizeof loadaddress, 1, out))\n    pexit(\"fwrite\");\n  if (1 != fwrite(&type, sizeof type, 1, out))\n    pexit(\"fwrite\");\n\n  /* write EVA LZMA header */\n  if (fgetpos(out, &compsizepos))\n    pexit(\"fgetpos\");\n  if (1 != fwrite(&compsize, sizeof compsize, 1, out))\n    pexit(\"fwrite\");\n  /* XXX check length */\n  datasize32 = (uint32_t)datasize;\n  if (1 != fwrite(&datasize32, sizeof datasize32, 1, out))\n    pexit(\"fwrite\");\n  if (1 != fwrite(&datacrc32, sizeof datacrc32, 1, out))\n    pexit(\"fwrite\");\n\n  /* write modified LZMA header */\n  if (1 != fwrite(&properties, sizeof properties, 1, out))\n    pexit(\"fwrite\");\n  if (1 != fwrite(&dictsize, sizeof dictsize, 1, out))\n    pexit(\"fwrite\");\n  if (1 != fwrite(&zero, 3, 1, out))\n    pexit(\"fwrite\");\n\n  /* copy compressed data, calculate crc32 */\n  while (0 < (elems = fread(&buf, sizeof buf[0], sizeof buf, in))) {\n    compsize += elems;\n    if (elems != fwrite(&buf, sizeof buf[0], elems, out))\n      pexit(\"fwrite\");\n    datacrc32 = crc32(datacrc32, buf, elems);\n  }\n  if (ferror(in))\n    pexit(\"fread\");\n  fclose(in);\n\n  /* re-write record length */\n  reclength = compsize + 24;\n  if (fsetpos(out, &reclengthpos))\n    pexit(\"fsetpos\");\n  if (1 != fwrite(&reclength, sizeof reclength, 1, out))\n    pexit(\"fwrite\");\n\n  /* re-write EVA LZMA header including size and data crc */\n  if (fsetpos(out, &compsizepos))\n    pexit(\"fsetpos\");\n  if (1 != fwrite(&compsize, sizeof compsize, 1, out))\n    pexit(\"fwrite\");\n  if (1 != fwrite(&datasize32, sizeof datasize32, 1, out))\n    pexit(\"fwrite\");\n  if (1 != fwrite(&datacrc32, sizeof datacrc32, 1, out))\n    pexit(\"fwrite\");\n\n  /* calculate record checksum */\n  checksum += reclength;\n  checksum += loadaddress;\n  checksum_add32(checksum, type);\n  checksum_add32(checksum, compsize);\n  checksum_add32(checksum, datasize32);\n  checksum_add32(checksum, datacrc32);\n  if (fseek(out, 0, SEEK_CUR))\n    pexit(\"fseek\");\n  while (0 < (elems = fread(&buf, sizeof buf[0], sizeof buf, out))) {\n    size_t i;\n    for (i = 0; i < elems; ++i)\n      checksum += buf[i];\n  }\n  if (ferror(out))\n    pexit(\"fread\");\n  if (fseek(out, 0, SEEK_CUR))\n    pexit(\"fseek\");\n\n  checksum = ~checksum + 1;\n  if (1 != fwrite(&checksum, sizeof checksum, 1, out))\n    pexit(\"fwrite\");\n\n  /* write entry record */\n  if (1 != fwrite(&zero, sizeof zero, 1, out))\n    pexit(\"fwrite\");\n  if (1 != fwrite(&entry, sizeof entry, 1, out))\n    pexit(\"fwrite\");\n\n  if (fclose(out))\n    pexit(\"fclose\");\n\n  return 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/makeamitbin.c",
    "content": "/*\n *  makeamitbin - create firmware binaries for MGB100\n *\n *  Copyright (C) 2007 Volker Weiss     <dev@tintuc.de>\n *                     Christian Welzel <dev@welzel-online.ch>\n *\n *  This program is free software; you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation; either version 2 of the License, or\n *  (at your option) any later version.\n * \n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n * \n *  You should have received a copy of the GNU General Public License\n *  along with this program; if not, write to the Free Software\n *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n *\n */\n\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n\n/* defaults: Level One WAP-0007 */\nstatic char *ascii1 = \"DDC_RUS001\";\nstatic char *ascii2 = \"Queen\";\n\nstatic struct hdrinfo {\n  char *name;\n\tunsigned long unknown; /* can probably be any number, maybe version number */\n\tint topalign;\n\tunsigned int addr;\n\tunsigned int size;\n} hdrinfo[] = {\n\t{ \"bios\", 0xc76be111, 1, 0x3fa000, 0x006000 },        /* BIOS */\n\t{ \"recovery\", 0xc76be222, 0, 0x3f0000, 0x004000 },    /* Recovery Loader */\n\t{ \"linux\", 0xc76bee9d, 0, 0x000000, 0x100000 },       /* Linux */\n\t{ \"ramdisk\", 0xc76bee9d, 0, 0x100000, 0x280000 },     /* ramdisk */\n\t{ \"amitconfig\", 0xc76bee8b, 0, 0x380000, 0x060000 },  /* AMIT config */\n\t{ \"redboot\", 0x00000000, 1, 0x3d0000, 0x030000 },     /* Redboot 128kB image */\n\t{ \"redbootlow\", 0, 0, 0x3e0000, 0x18000 },            /* Redboot 1. part */\n\t{ \"redboothigh\", 0, 0, 0x3fa000, 0x6000 },            /* Redboot 2. part */\n\t{ \"linux3g\", 0xcb5f06b5, 0, 0x000000, 0x100000 },       /* Linux */\n\t{ \"ramdisk3g\", 0xcb5f06b5, 0, 0x100000, 0x280000 },     /* ramdisk */\n\t{ NULL }\n};\n\n/*\nCHD2WLANU_R400b7\n\n11e1 6bc7\n22e2 6bc7\n5dc3 47c8\n5cc3 47c8\n21c3 47c8\n*/\n\n/*\n20060106_DDC_WAP-0007_R400b4\n\n11e1 6bc7\n22e2 6bc7\n9dee 6bc7\n9dee 6bc7\n8bee 6bc7\n*/\n\n/*\nWMU-6000FS_R400b6\n\n11e1 6bc7\n22e2 6bc7\n6d2d 0fc8\n6c2d 0fc8\n542d 0fc8\n*/\n\n/*\nWAP-0007(R4.00b8)_2006-10-02\n\n9979 5fc8\n22e2 6bc7\nc46e cec8\nc36e cec8\na76e cec8\n*/\n\n\n\n#define HDRSIZE              80\n\n#define COPY_SHORT(d, o, v)  d[o+0] = (unsigned char)((v) & 0xff); \\\n                             d[o+1] = (unsigned char)(((v) >> 8) & 0xff)\n#define COPY_LONG(d, o, v)   d[o+0] = (unsigned char)((v) & 0xff); \\\n                             d[o+1] = (unsigned char)(((v) >> 8) & 0xff); \\\n\t\t\t\t\t\t\t\t\t\t\t\t\t   d[o+2] = (unsigned char)(((v) >> 16) & 0xff); \\\n\t\t\t\t\t\t\t\t\t\t\t\t\t   d[o+3] = (unsigned char)(((v) >> 24) & 0xff)\n#define READ_SHORT(d, o)     ((unsigned short)(d[o+0]) + \\\n                             (((unsigned short)(d[o+1])) << 8))\n\n/*\n00..0d ASCII product ID\n0e..0f checksum of payload\n10..1b ASCII Queen\n1c..1f AMIT BIOS: 11e1 6bc7, Recovery Tool: 22e2 6bc7\n       Linux: 5dc3 47c8, ramdisk: 5cc3 47c8\n\t\t\t AMIT FS: 21c3 47c8    VERSION NUMBER??????\n20..23 offset in flash aligned to segment boundary\n24..27 length in flash aligned to segment boundary\n28..2b offset in flash (payload)\n2c..2f length (payload)\n30..3f always 0\n40..47 always 4248 0101 5000 0001 (last maybe .....0501)\n48..4b same as 20..23\n4c..4d always 0b00\n4e..4f inverted checksum of header\n*/\n\nunsigned short checksum(unsigned char *data, long size)\n{\n\tlong n;\n\tunsigned short d, cs = 0;\n\tfor (n = 0; n < size; n += 2)\n\t{\n\t\td = READ_SHORT(data, n);\n\t\tcs += d;\n\t\tif (cs < d)\n\t\t\tcs++;\n\t}\n\tif (size & 1)\n\t{\n\t\td = data[n];\n\t\tcs += d;\n\t\tif (cs < d)\n\t\t\tcs++;\n\t}\n\treturn cs;\n}\n\nvoid showhdr(unsigned char *hdr)\n{\n\tint i, j;\n\tfor (j = 0; j < 5; j++)\n\t{\n\t\tfor (i = 0; i < 16; i++)\n\t\t{\n\t\t\tprintf(\"%02x \", (unsigned int)(hdr[j * 16 + i]));\n\t\t}\n\t\tprintf(\"   \");\n\t\tfor (i = 0; i < 16; i++)\n\t\t{\n\t\t\tunsigned char d = hdr[j * 16 + i];\n\t\t\tprintf(\"%c\", (d >= ' ' && d < 127) ? d : '.');\n\t\t}\n\t\tprintf(\"\\n\");\n\t}\n}\n\nvoid makehdr(unsigned char *hdr, struct hdrinfo *info,\n             unsigned char *data, long size, int last)\n{\n\tunsigned int offset = info->addr + 0x10;\n\tmemset(hdr, 0, HDRSIZE);\n\tif (info->topalign)\n\t\toffset = info->addr + info->size - size;\t/* top align */\n\tstrncpy((char *)hdr + 0x00, ascii1, 14);\n\tstrncpy((char *)hdr + 0x10, ascii2, 12);\n\tCOPY_LONG(hdr, 0x1c, info->unknown);\n\tCOPY_LONG(hdr, 0x20, info->addr);\n\tCOPY_LONG(hdr, 0x24, info->size);\n\tCOPY_LONG(hdr, 0x28, offset);\n\tCOPY_LONG(hdr, 0x2c, size);\n\tCOPY_LONG(hdr, 0x40, 0x01014842);\n\tCOPY_LONG(hdr, 0x44, last ? 0x01050050 : 0x01000050);\n\tCOPY_LONG(hdr, 0x48, info->addr);\n\tCOPY_SHORT(hdr, 0x4c, info->unknown == 0xcb5f06b5 ? 0x0016 : 0x000b);\n\tCOPY_SHORT(hdr, 0x0e, checksum(data, size));\n\tCOPY_SHORT(hdr, 0x4e, ~checksum(hdr, HDRSIZE));\n}\n\nunsigned char *read_file(const char *name, long *size)\n{\n\tFILE *f;\n\tunsigned char *data = NULL;\n\t*size = 0;\n\tf = fopen(name, \"r\");\n\tif (f != NULL)\n\t{\n\t\tif (fseek(f, 0, SEEK_END) == 0)\n\t\t{\n\t    *size = ftell(f);\n\t\t\tif (*size != -1)\n\t\t\t{\n\t\t\t\tif (fseek(f, 0, SEEK_SET) == 0)\n\t\t\t\t{\n\t\t\t\t\tdata = (unsigned char *)malloc(*size);\n\t\t\t\t\tif (data != NULL)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (fread(data, sizeof(char), *size, f) != *size)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfree(data);\n\t\t\t\t\t\t\tdata = NULL;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfclose(f);\n\t}\n\treturn data;\n}\n\nstruct hdrinfo *find_hdrinfo(const char *name)\n{\n\tint n;\n\tfor (n = 0; hdrinfo[n].name != NULL; n++)\n\t{\n\t\tif (strcmp(name, hdrinfo[n].name) == 0)\n\t\t\treturn &hdrinfo[n];\n\t}\n\treturn NULL;\n}\n\nvoid oferror(FILE *f)\n{\n\tprintf(\"file error\\n\");\n\texit(2);\n}\n\nvoid showhelp(void)\n{\n\tprintf(\"Syntax: makeamitbin [options]\\n\");\n\tprintf(\"Options:\\n\");\n\tprintf(\"  -1 ID1\\tFirmware identifier 1, e.g. 'DDC_RUS001' for manufacturer LevelOne\\n\");\n\tprintf(\"  -2 ID2\\tFirmware identifier 2, 'Queen' in all known cases\\n\");\n\tprintf(\"  -o FILE\\tOutput file\\n\");\n\tprintf(\"  -ids\\t\\tShow a list of known firmware identifiers.\\n\");\n\texit(1);\n}\n\nvoid show_fwids(void)\n{\n\tprintf(\"List of known firmware identifiers:\\n\");\n\tprintf(\"Manufacturer\\t\\tProduct\\t\\tIdentifier\\n\");\n\tprintf(\"=====================================================\\n\");\n\tprintf(\"Conceptronic\\t\\tCHD2WLANU\\tLLM_RUS001\\n\");\n\tprintf(\"Pearl\\t\\t\\tPE6643\\t\\tQueen\\n\");\n\tprintf(\"Micronica\\t\\tMGB100\\t\\tQueen\\n\");\n\tprintf(\"LevelOne\\t\\tWAP-0007\\tDDC_RUS001\\n\");\n\tprintf(\"SMC\\t\\t\\tWAPS-G\\t\\tSMC_RUS001\\n\");\n\tprintf(\"OvisLink (AirLive)\\tWMU-6\\t\\tOVS_RUS001\\n\");\n\tprintf(\"SafeCom SWSAPUR-5\\tFMW\\t\\tSafeco_RPS001\\n\");\n\texit(1);\n}\n\nint main(int argc, char *argv[])\n{\n\tunsigned char hdr[HDRSIZE];\n\tunsigned char *data;\n\tFILE *of;\n\tchar *outfile = NULL;\n\tchar *type;\n\tstruct hdrinfo *info;\n\tlong size;\n\tint last = 0;\n\tint n;\n\tfor (n = 1; n < argc; n++)\n\t{\n\t\tif (strcmp(argv[n], \"-1\") == 0)\n\t\t\tascii1 = argv[n+1];\n\t\tif (strcmp(argv[n], \"-2\") == 0)\n\t\t\tascii2 = argv[n+1];\n\t\tif (strcmp(argv[n], \"-o\") == 0)\n\t\t\toutfile = argv[n+1];\n\t\tif (strcmp(argv[n], \"-ids\") == 0)\n\t\t\tshow_fwids();\n\t}\n\tif (ascii1 == NULL || ascii2 == NULL || outfile == NULL)\n\t\tshowhelp();\n\tof = fopen(outfile, \"w\");\n\tif (of == NULL)\n\t\toferror(of);\n\tfor (n = 1; n < argc; n++)\n\t{\n\t\tif (strncmp(argv[n], \"-\", 1) != 0)\n\t\t{\n\t\t\ttype = argv[n++];\n\t\t\tif (n >= argc)\n\t\t\t\tshowhelp();\n\t\t\tlast = ((n + 1) >= argc);\t\t/* dirty, options first! */\n\t\t\tinfo = find_hdrinfo(type);\n\t\t\tif (info == NULL)\n\t\t\t\tshowhelp();\n\t\t\tdata = read_file(argv[n], &size);\n\t\t\tif (data == NULL)\n\t\t\t\tshowhelp();\n\t\t\tmakehdr(hdr, info, data, size, last);\n\t\t\t/* showhdr(hdr); */\n\t\t\tif (fwrite(hdr, HDRSIZE, 1, of) != 1)\n\t\t\t\toferror(of);\n\t\t\tif (fwrite(data, size, 1, of) != 1)\n\t\t\t\toferror(of);\n\t\t\tfree(data);\n\t\t}\n\t\telse\n\t\t\tn++;\n\t}\n\tif (fclose(of) != 0)\n\t\toferror(NULL);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/md5.c",
    "content": "\n\n/*\n ***********************************************************************\n ** md5.c -- the source code for MD5 routines                         **\n ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **\n ** Created: 2/17/90 RLR                                              **\n ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **\n ***********************************************************************\n */\n\n/*\n ***********************************************************************\n ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **\n **                                                                   **\n ** License to copy and use this software is granted provided that    **\n ** it is identified as the \"RSA Data Security, Inc. MD5 Message-     **\n ** Digest Algorithm\" in all material mentioning or referencing this  **\n ** software or this function.                                        **\n **                                                                   **\n ** License is also granted to make and use derivative works          **\n ** provided that such works are identified as \"derived from the RSA  **\n ** Data Security, Inc. MD5 Message-Digest Algorithm\" in all          **\n ** material mentioning or referencing the derived work.              **\n **                                                                   **\n ** RSA Data Security, Inc. makes no representations concerning       **\n ** either the merchantability of this software or the suitability    **\n ** of this software for any particular purpose.  It is provided \"as  **\n ** is\" without express or implied warranty of any kind.              **\n **                                                                   **\n ** These notices must be retained in any copies of any part of this  **\n ** documentation and/or software.                                    **\n ***********************************************************************\n */\n\n#include <string.h>\n#include \"md5.h\"\n\n/*\n ***********************************************************************\n **  Message-digest routines:                                         **\n **  To form the message digest for a message M                       **\n **    (1) Initialize a context buffer mdContext using MD5_Init       **\n **    (2) Call MD5_Update on mdContext and M                         **\n **    (3) Call MD5_Final on mdContext                                **\n **  The message digest is now in mdContext->digest[0...15]           **\n ***********************************************************************\n */\n\n/* forward declaration */\nstatic void Transform ();\n\nstatic unsigned char PADDING[64] = {\n  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n};\n\n/* F, G, H and I are basic MD5 functions */\n#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))\n#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))\n#define H(x, y, z) ((x) ^ (y) ^ (z))\n#define I(x, y, z) ((y) ^ ((x) | (~z)))\n\n/* ROTATE_LEFT rotates x left n bits */\n#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))\n\n/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */\n/* Rotation is separate from addition to prevent recomputation */\n#define FF(a, b, c, d, x, s, ac) \\\n  {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n#define GG(a, b, c, d, x, s, ac) \\\n  {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n#define HH(a, b, c, d, x, s, ac) \\\n  {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n#define II(a, b, c, d, x, s, ac) \\\n  {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n\n#ifdef __STDC__\n#define UL(x)\tx##U\n#else\n#define UL(x)\tx\n#endif\n\n/* The routine MD5_Init initializes the message-digest context\n   mdContext. All fields are set to zero.\n */\nvoid MD5_Init (mdContext)\nMD5_CTX *mdContext;\n{\n  mdContext->i[0] = mdContext->i[1] = (UINT4)0;\n\n  /* Load magic initialization constants.\n   */\n  mdContext->buf[0] = (UINT4)0x67452301;\n  mdContext->buf[1] = (UINT4)0xefcdab89;\n  mdContext->buf[2] = (UINT4)0x98badcfe;\n  mdContext->buf[3] = (UINT4)0x10325476;\n}\n\n/* The routine MD5Update updates the message-digest context to\n   account for the presence of each of the characters inBuf[0..inLen-1]\n   in the message whose digest is being computed.\n */\nvoid MD5_Update (mdContext, inBuf, inLen)\nMD5_CTX *mdContext;\nunsigned char *inBuf;\nunsigned int inLen;\n{\n  UINT4 in[16];\n  int mdi;\n  unsigned int i, ii;\n\n  /* compute number of bytes mod 64 */\n  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);\n\n  /* update number of bits */\n  if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])\n    mdContext->i[1]++;\n  mdContext->i[0] += ((UINT4)inLen << 3);\n  mdContext->i[1] += ((UINT4)inLen >> 29);\n\n  while (inLen--) {\n    /* add new character to buffer, increment mdi */\n    mdContext->in[mdi++] = *inBuf++;\n\n    /* transform if necessary */\n    if (mdi == 0x40) {\n      for (i = 0, ii = 0; i < 16; i++, ii += 4)\n        in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |\n                (((UINT4)mdContext->in[ii+2]) << 16) |\n                (((UINT4)mdContext->in[ii+1]) << 8) |\n                ((UINT4)mdContext->in[ii]);\n      Transform (mdContext->buf, in);\n      mdi = 0;\n    }\n  }\n}\n\n/* The routine MD5Final terminates the message-digest computation and\n   ends with the desired message digest in mdContext->digest[0...15].\n */\nvoid MD5_Final (hash, mdContext)\nunsigned char hash[];\nMD5_CTX *mdContext;\n{\n  UINT4 in[16];\n  int mdi;\n  unsigned int i, ii;\n  unsigned int padLen;\n\n  /* save number of bits */\n  in[14] = mdContext->i[0];\n  in[15] = mdContext->i[1];\n\n  /* compute number of bytes mod 64 */\n  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);\n\n  /* pad out to 56 mod 64 */\n  padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);\n  MD5_Update (mdContext, PADDING, padLen);\n\n  /* append length in bits and transform */\n  for (i = 0, ii = 0; i < 14; i++, ii += 4)\n    in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |\n            (((UINT4)mdContext->in[ii+2]) << 16) |\n            (((UINT4)mdContext->in[ii+1]) << 8) |\n            ((UINT4)mdContext->in[ii]);\n  Transform (mdContext->buf, in);\n\n  /* store buffer in digest */\n  for (i = 0, ii = 0; i < 4; i++, ii += 4) {\n    mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);\n    mdContext->digest[ii+1] =\n      (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);\n    mdContext->digest[ii+2] =\n      (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);\n    mdContext->digest[ii+3] =\n      (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);\n  }\n  memcpy(hash, mdContext->digest, 16);\n}\n\n/* Basic MD5 step. Transforms buf based on in.\n */\nstatic void Transform (buf, in)\nUINT4 *buf;\nUINT4 *in;\n{\n  UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];\n\n  /* Round 1 */\n#define S11 7\n#define S12 12\n#define S13 17\n#define S14 22\n  FF ( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */\n  FF ( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */\n  FF ( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */\n  FF ( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */\n  FF ( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */\n  FF ( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */\n  FF ( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */\n  FF ( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */\n  FF ( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */\n  FF ( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */\n  FF ( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */\n  FF ( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */\n  FF ( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */\n  FF ( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */\n  FF ( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */\n  FF ( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */\n\n  /* Round 2 */\n#define S21 5\n#define S22 9\n#define S23 14\n#define S24 20\n  GG ( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */\n  GG ( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */\n  GG ( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */\n  GG ( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */\n  GG ( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */\n  GG ( d, a, b, c, in[10], S22, UL(  38016083)); /* 22 */\n  GG ( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */\n  GG ( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */\n  GG ( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */\n  GG ( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */\n  GG ( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */\n  GG ( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */\n  GG ( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */\n  GG ( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */\n  GG ( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */\n  GG ( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */\n\n  /* Round 3 */\n#define S31 4\n#define S32 11\n#define S33 16\n#define S34 23\n  HH ( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */\n  HH ( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */\n  HH ( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */\n  HH ( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */\n  HH ( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */\n  HH ( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */\n  HH ( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */\n  HH ( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */\n  HH ( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */\n  HH ( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */\n  HH ( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */\n  HH ( b, c, d, a, in[ 6], S34, UL(  76029189)); /* 44 */\n  HH ( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */\n  HH ( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */\n  HH ( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */\n  HH ( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */\n\n  /* Round 4 */\n#define S41 6\n#define S42 10\n#define S43 15\n#define S44 21\n  II ( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */\n  II ( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */\n  II ( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */\n  II ( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */\n  II ( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */\n  II ( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */\n  II ( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */\n  II ( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */\n  II ( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */\n  II ( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */\n  II ( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */\n  II ( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */\n  II ( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */\n  II ( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */\n  II ( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */\n  II ( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */\n\n  buf[0] += a;\n  buf[1] += b;\n  buf[2] += c;\n  buf[3] += d;\n}\n\n/*\n ***********************************************************************\n ** End of md5.c                                                      **\n ******************************** (cut) ********************************\n */\n"
  },
  {
    "path": "src/firmware-tools/md5.h",
    "content": "/*\n ***********************************************************************\n ** md5.h -- header file for implementation of MD5                    **\n ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **\n ** Created: 2/17/90 RLR                                              **\n ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version               **\n ** Revised (for MD5): RLR 4/27/91                                    **\n **   -- G modified to have y&~z instead of y&z                       **\n **   -- FF, GG, HH modified to add in last register done             **\n **   -- Access pattern: round 2 works mod 5, round 3 works mod 3     **\n **   -- distinct additive constant for each step                     **\n **   -- round 4 added, working mod 7                                 **\n ***********************************************************************\n */\n\n/*\n ***********************************************************************\n ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **\n **                                                                   **\n ** License to copy and use this software is granted provided that    **\n ** it is identified as the \"RSA Data Security, Inc. MD5 Message-     **\n ** Digest Algorithm\" in all material mentioning or referencing this  **\n ** software or this function.                                        **\n **                                                                   **\n ** License is also granted to make and use derivative works          **\n ** provided that such works are identified as \"derived from the RSA  **\n ** Data Security, Inc. MD5 Message-Digest Algorithm\" in all          **\n ** material mentioning or referencing the derived work.              **\n **                                                                   **\n ** RSA Data Security, Inc. makes no representations concerning       **\n ** either the merchantability of this software or the suitability    **\n ** of this software for any particular purpose.  It is provided \"as  **\n ** is\" without express or implied warranty of any kind.              **\n **                                                                   **\n ** These notices must be retained in any copies of any part of this  **\n ** documentation and/or software.                                    **\n ***********************************************************************\n */\n\n#ifndef __MD5_INCLUDE__\n\n/* typedef a 32-bit type */\n#ifdef _LP64\ntypedef unsigned int UINT4;\ntypedef int          INT4;\n#else\ntypedef unsigned long UINT4;\ntypedef long          INT4;\n#endif\n#define _UINT4_T\n\n/* Data structure for MD5 (Message-Digest) computation */\ntypedef struct {\n  UINT4 i[2];                   /* number of _bits_ handled mod 2^64 */\n  UINT4 buf[4];                                    /* scratch buffer */\n  unsigned char in[64];                              /* input buffer */\n  unsigned char digest[16];     /* actual digest after MD5Final call */\n} MD5_CTX;\n\nvoid MD5_Init ();\nvoid MD5_Update ();\nvoid MD5_Final ();\n\n#define __MD5_INCLUDE__\n#endif /* __MD5_INCLUDE__ */\n"
  },
  {
    "path": "src/firmware-tools/mkbrncmdline.c",
    "content": "/*\n * mkbrncmdline.c - partially based on OpenWrt's wndr3700.c\n *\n * Copyright (C) 2011 Tobias Diedrich <ranma+openwrt@tdiedrich.de>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License,\n * version 2 as published by the Free Software Foundation.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stddef.h>\n#include <unistd.h>\n#include <errno.h>\n#include <fcntl.h>\n#include <sys/mman.h>\n#include <string.h>\n#include <netinet/in.h>\n#include <inttypes.h>\n\nstatic void usage(const char *) __attribute__ (( __noreturn__ ));\n\nstatic void usage(const char *mess)\n{\n\tfprintf(stderr, \"Error: %s\\n\", mess);\n\tfprintf(stderr, \"Usage: mkbrncmdline -i input_file -o output_file [-a loadaddress] arg1 [argx ...]\\n\");\n\tfprintf(stderr, \"\\n\");\n\texit(1);\n}\n\nstatic char *input_file = NULL;\nstatic char *output_file = NULL;\nstatic unsigned loadaddr = 0x80002000;\n\nstatic void parseopts(int *argc, char ***argv)\n{\n\tchar *endptr;\n\tint res;\n\n\twhile ((res = getopt(*argc, *argv, \"a:i:o:\")) != -1) {\n\t\tswitch (res) {\n\t\tdefault:\n\t\t\tusage(\"Unknown option\");\n\t\t\tbreak;\n\t\tcase 'a':\n\t\t\tloadaddr = strtoul(optarg, &endptr, 0);\n\t\t\tif (endptr == optarg || *endptr != 0)\n\t\t\t\tusage(\"loadaddress must be a decimal or hexadecimal 32-bit value\");\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tinput_file = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\toutput_file = optarg;\n\t\t\tbreak;\n\t\t}\n\t}\n\t*argc -= optind;\n\t*argv += optind;\n}\n\nstatic void emitload(int outfd, int reg, unsigned value)\n{\n\tchar buf[8] = {\n\t\t0x3c, 0x04 + reg,\n\t\tvalue >> 24, value >> 16,\n\t\t0x34, 0x84 + reg + (reg << 5),\n\t\tvalue >> 8, value,\n\t};\n\tif (write(outfd, buf, sizeof(buf)) != sizeof(buf)) {\n\t\tfprintf(stderr, \"write: %s\\n\", strerror(errno));\n\t\texit(1);\n\t}\n}\n\nint main(int argc, char **argv)\n{\n\tint outfd;\n\tint i;\n\tint fd;\n\tsize_t len, skip, buf_len;\n\tunsigned cmdline_addr;\n\tunsigned s_ofs;\n\tchar *buf;\n\n\tparseopts(&argc, &argv);\n\n\tif (argc < 1)\n\t\tusage(\"must specify at least one kernel cmdline argument\");\n\n\tif (input_file == NULL || output_file == NULL)\n\t\tusage(\"must specify input and output file\");\n\n\tif ((outfd = open(output_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1)\n\t{\n\t\tfprintf(stderr, \"Error opening '%s' for writing: %s\\n\", output_file, strerror(errno));\n\t\texit(1);\n\t}\n\n\t// mmap input_file\n\tif ((fd = open(input_file, O_RDONLY))  < 0\n\t|| (len = lseek(fd, 0, SEEK_END)) < 0\n\t|| (input_file = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0)) == (void *) (-1)\n\t|| close(fd) < 0)\n\t{\n\t\tfprintf(stderr, \"Error mapping file '%s': %s\\n\", input_file, strerror(errno));\n\t\texit(1);\n\t}\n\n\tcmdline_addr = loadaddr + len;\n\n\t// Kernel args are passed in registers a0,a1,a2 and a3\n\temitload(outfd, 0, 0);              /* a0 = 0 */\n\temitload(outfd, 1, 0);              /* a1 = 0 */\n\temitload(outfd, 2, cmdline_addr);   /* a2 = &cmdline */\n\temitload(outfd, 3, 0);              /* a3 = 0 */\n\tskip = lseek(outfd, 0, SEEK_END);\n\n\t// write the kernel\n\tif (write(outfd, input_file + skip, len - skip) != len -skip) {\n\t\tfprintf(stderr, \"write: %s\\n\", strerror(errno));\n\t\texit(1);\n\t}\n\n\t// write cmdline structure\n\tbuf_len = (argc + 1) * 4;\n\tfor (i=0; i<argc; i++) {\n\t\tbuf_len += strlen(argv[i]) + 1;\n\t}\n\tbuf = malloc(buf_len + 16);\n\tif (!buf) {\n\t\tfprintf(stderr, \"Could not allocate memory for cmdline buffer\\n\");\n\t\texit(1);\n\t}\n\tmemset(buf, 0, buf_len);\n\n\ts_ofs = 4 * (argc + 1);\n\tfor (i=0; i<argc; i++) {\n\t\tunsigned s_ptr = cmdline_addr + s_ofs;\n\t\tbuf[i * 4 + 0] = s_ptr >> 24;\n\t\tbuf[i * 4 + 1] = s_ptr >> 16;\n\t\tbuf[i * 4 + 2] = s_ptr >>  8;\n\t\tbuf[i * 4 + 3] = s_ptr >>  0;\n\t\tmemcpy(&buf[s_ofs], argv[i], strlen(argv[i]));\n\t\ts_ofs += strlen(argv[i]) + 1;\n\t}\n\tif (write(outfd, buf, buf_len) != buf_len) {\n\t\tfprintf(stderr, \"write: %s\\n\", strerror(errno));\n\t\texit(1);\n\t}\n\n\n\tmunmap(input_file, len);\n\tclose(outfd);\n\tfree(buf);\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkbrnimg.c",
    "content": "/*\n * mkbrnimg.c - partially based on OpenWrt's wndr3700.c\n *\n * Copyright (C) 2011 Tobias Diedrich <ranma+openwrt@tdiedrich.de>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License,\n * version 2 as published by the Free Software Foundation.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stddef.h>\n#include <unistd.h>\n#include <errno.h>\n#include <fcntl.h>\n#include <sys/mman.h>\n#include <string.h>\n#include <netinet/in.h>\n#include <inttypes.h>\n\n#define BPB 8 /* bits/byte */\n\nstatic uint32_t crc32[1<<BPB];\n\nstatic void init_crc32()\n{\n\tconst uint32_t poly = ntohl(0x2083b8ed);\n\tint n;\n\n\tfor (n = 0; n < 1<<BPB; n++) {\n\t\tuint32_t crc = n;\n\t\tint bit;\n\n\t\tfor (bit = 0; bit < BPB; bit++)\n\t\t\tcrc = (crc & 1) ? (poly ^ (crc >> 1)) : (crc >> 1);\n\t\tcrc32[n] = crc;\n\t}\n}\n\nstatic uint32_t crc32buf(unsigned char *buf, size_t len)\n{\n\tuint32_t crc = 0xFFFFFFFF;\n\n\tfor (; len; len--, buf++)\n\t\tcrc = crc32[(uint8_t)crc ^ *buf] ^ (crc >> BPB);\n\treturn ~crc;\n}\n\nstatic void usage(const char *) __attribute__ (( __noreturn__ ));\n\nstatic void usage(const char *mess)\n{\n\tfprintf(stderr, \"Error: %s\\n\", mess);\n\tfprintf(stderr, \"Usage: mkbrnimg [-o output_file] [-m magic] [-s signature] kernel_file [additional files]\\n\");\n\tfprintf(stderr, \"\\n\");\n\texit(1);\n}\n\nstatic char *output_file = \"default-brnImage\";\nstatic uint32_t magic = 0x12345678;\nstatic char *signature = \"BRNDTW502\";\n\nstatic void parseopts(int *argc, char ***argv)\n{\n\tchar *endptr;\n\tint res;\n\n\twhile ((res = getopt(*argc, *argv, \"o:m:s:\")) != -1) {\n\t\tswitch (res) {\n\t\tdefault:\n\t\t\tusage(\"Unknown option\");\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\toutput_file = optarg;\n\t\t\tbreak;\n\t\tcase 'm':\n\t\t\tmagic = strtoul(optarg, &endptr, 0);\n\t\t\tif (endptr == optarg || *endptr != 0)\n\t\t\t\tusage(\"magic must be a decimal or hexadecimal 32-bit value\");\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\tsignature = optarg;\n\t\t\tbreak;\n\t\t}\n\t}\n\t*argc -= optind;\n\t*argv += optind;\n}\n\nstatic void appendfile(int outfd, char *path, int kernel) {\n\tint fd;\n\tsize_t len, padded_len;\n\tchar *input_file;\n\tuint32_t crc;\n\tchar padding[0x400];\n\tchar footer[12];\n\n\tmemset(padding, 0xff, sizeof(padding));\n\n\t// mmap input_file\n\tif ((fd = open(path, O_RDONLY))  < 0\n\t|| (len = lseek(fd, 0, SEEK_END)) < 0\n\t|| (input_file = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0)) == (void *) (-1)\n\t|| close(fd) < 0)\n\t{\n\t\tfprintf(stderr, \"Error mapping file '%s': %s\\n\", path, strerror(errno));\n\t\texit(1);\n\t}\n\n\t// kernel should be lzma compressed image, not uImage\n\tif (kernel &&\n\t    (input_file[0] != (char)0x5d ||\n\t     input_file[1] != (char)0x00 ||\n\t     input_file[2] != (char)0x00 ||\n\t     input_file[3] != (char)0x80)) {\n\t\tfprintf(stderr, \"lzma signature not found on kernel image.\\n\");\n\t\texit(1);\n\t}\n\n\tinit_crc32();\n\tcrc = crc32buf(input_file, len);\n\tfprintf(stderr, \"crc32 for '%s' is %08x.\\n\", path, crc);\n\n\t// write the file\n\twrite(outfd, input_file, len);\n\n\t// write padding\n\tpadded_len = ((len + sizeof(footer) + sizeof(padding) - 1) & ~(sizeof(padding) - 1)) - sizeof(footer);\n\tfprintf(stderr, \"len=%08x padded_len=%08x\\n\", len, padded_len);\n\twrite(outfd, padding, padded_len - len);\n\n\t// write footer\n\tfooter[0]  = (len   >>  0) & 0xff;\n\tfooter[1]  = (len   >>  8) & 0xff;\n\tfooter[2]  = (len   >> 16) & 0xff;\n\tfooter[3]  = (len   >> 24) & 0xff;\n\tfooter[4]  = (magic >>  0) & 0xff;\n\tfooter[5]  = (magic >>  8) & 0xff;\n\tfooter[6]  = (magic >> 16) & 0xff;\n\tfooter[7]  = (magic >> 24) & 0xff;\n\tfooter[8]  = (crc   >>  0) & 0xff;\n\tfooter[9]  = (crc   >>  8) & 0xff;\n\tfooter[10] = (crc   >> 16) & 0xff;\n\tfooter[11] = (crc   >> 24) & 0xff;\n\twrite(outfd, footer, sizeof(footer));\n\n\tmunmap(input_file, len);\n}\n\nint main(int argc, char **argv)\n{\n\tint outfd;\n\tint i;\n\n\tparseopts(&argc, &argv);\n\n\tif (argc < 1)\n\t\tusage(\"wrong number of arguments\");\n\n\tif ((outfd = open(output_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1)\n\t{\n\t\tfprintf(stderr, \"Error opening '%s' for writing: %s\\n\", output_file, strerror(errno));\n\t\texit(1);\n\t}\n\n\tfor (i=0; i<argc; i++) {\n\t\tappendfile(outfd, argv[i], i == 0);\n\t}\n\twrite(outfd, signature, strlen(signature)+1);\n\tclose(outfd);\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkcameofw.c",
    "content": "/*\n * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License version 2 as published\n * by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\n#include <arpa/inet.h>\n#include <netinet/in.h>\n\n#define MAX_MODEL_LEN\t\t20\n#define MAX_SIGNATURE_LEN\t30\n#define MAX_REGION_LEN\t\t4\n#define MAX_VERSION_LEN\t\t12\n\n#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))\n\nstruct file_info {\n\tchar\t\t*file_name;\t/* name of the file */\n\tuint32_t\tfile_size;\t/* length of the file */\n\tuint32_t\twrite_size;\n};\n\nstruct img_header {\n\tuint32_t\tchecksum;\n\tuint32_t\timage_size;\n\tuint32_t\tkernel_size;\n\tchar\t\tmodel[MAX_MODEL_LEN];\n\tchar\t\tsignature[MAX_SIGNATURE_LEN];\n\tchar\t\tregion[MAX_REGION_LEN];\n\tchar\t\tversion[MAX_VERSION_LEN];\n\tunsigned char\theader_len;\n\tunsigned char\tis_tgz;\n\tunsigned char\tpad[4];\n} __attribute__ ((packed));\n\n/*\n * Globals\n */\nstatic char *ofname;\nstatic char *progname;\n\nstatic char *model;\nstatic char *signature;\nstatic char *region = \"DEF\";\nstatic char *version;\nstatic struct file_info kernel_info;\nstatic struct file_info rootfs_info;\nstatic uint32_t kernel_size;\nstatic uint32_t image_size;\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \" (%s)\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\n#define DBG(fmt, ...) do { \\\n\tfprintf(stderr, \"[%s] \" fmt \"\\n\", progname, ## __VA_ARGS__ ); \\\n} while (0)\n\nstatic void usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -k <file>       read kernel image from the file <file>\\n\"\n\"  -M <model>      set model to <model>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -r <file>       read rootfs image from the file <file>\\n\"\n\"  -S <signature>  set image signature to <signature>\\n\"\n\"  -R <region>     set image region to <region>\\n\"\n\"  -V <version>    set image version to <version>\\n\"\n\"  -I <size>       set image size to <size>\\n\"\n\"  -K <size>       set kernel size to <size>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nint\nstr2u32(char *arg, uint32_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err)) {\n\t\treturn -1;\n\t}\n\n\t*val = t;\n\treturn 0;\n}\n\nstatic int get_file_stat(struct file_info *fdata)\n{\n\tstruct stat st;\n\tint res;\n\n\tif (fdata->file_name == NULL)\n\t\treturn 0;\n\n\tres = stat(fdata->file_name, &st);\n\tif (res){\n\t\tERRS(\"stat failed on %s\", fdata->file_name);\n\t\treturn res;\n\t}\n\n\tfdata->file_size = st.st_size;\n\tfdata->write_size = fdata->file_size;\n\treturn 0;\n}\n\nstatic int read_to_buf(struct file_info *fdata, char *buf)\n{\n\tFILE *f;\n\tint ret = EXIT_FAILURE;\n\n\tf = fopen(fdata->file_name, \"r\");\n\tif (f == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for reading\", fdata->file_name);\n\t\tgoto out;\n\t}\n\n\terrno = 0;\n\tfread(buf, fdata->file_size, 1, f);\n\tif (errno != 0) {\n\t\tERRS(\"unable to read from file \\\"%s\\\"\", fdata->file_name);\n\t\tgoto out_close;\n\t}\n\n\tret = EXIT_SUCCESS;\n\nout_close:\n\tfclose(f);\nout:\n\treturn ret;\n}\n\nstatic int check_options(void)\n{\n\tint ret;\n\n#define CHKSTR(_name, _msg)\t\t\t\t\\\n\tdo {\t\t\t\t\t\t\\\n\t\tif (_name == NULL) {\t\t\t\\\n\t\t\tERR(\"no %s specified\", _msg);\t\\\n\t\t\treturn -1;\t\t\t\\\n\t\t}\t\t\t\t\t\\\n\t} while (0)\n\n#define CHKSTRLEN(_name, _msg)\t\t\t\t\t\\\n\tdo {\t\t\t\t\t\t\t\\\n\t\tint field_len;\t\t\t\t\t\\\n\t\tCHKSTR(_name, _msg);\t\t\t\t\\\n\t\tfield_len = FIELD_SIZEOF(struct img_header, _name) - 1; \\\n\t\tif (strlen(_name) > field_len) { \t\t\\\n\t\t\tERR(\"%s is too long, max length is %d\",\t\\\n\t\t\t    _msg, field_len);\t\t\t\\\n\t\t\treturn -1;\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\\\n\t} while (0)\n\n\tCHKSTRLEN(model, \"model\");\n\tCHKSTRLEN(signature, \"signature\");\n\tCHKSTRLEN(region, \"region\");\n\tCHKSTRLEN(version, \"version\");\n\tCHKSTR(ofname, \"output file\");\n\tCHKSTR(kernel_info.file_name, \"kernel image\");\n\tCHKSTR(rootfs_info.file_name, \"rootfs image\");\n\n\tret = get_file_stat(&kernel_info);\n\tif (ret)\n\t\treturn ret;\n\n\tret = get_file_stat(&rootfs_info);\n\tif (ret)\n\t\treturn ret;\n\n\tif (kernel_size) {\n\t\t/* override kernel size */\n\t\tkernel_info.write_size = kernel_size;\n\t}\n\n\tif (image_size) {\n\t\tif (image_size < kernel_info.write_size)\n\t\t\tkernel_info.write_size = image_size;\n\n\t\t/* override rootfs size */\n\t\trootfs_info.write_size = image_size - kernel_info.write_size;\n\t}\n\n\tif (kernel_info.file_size > kernel_info.write_size) {\n\t\tERR(\"kernel image is too big\");\n\t\treturn -1;\n\t}\n\n\tif (rootfs_info.file_size > rootfs_info.write_size) {\n\t\tERR(\"rootfs image is too big\");\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\nstatic int write_fw(char *data, int len)\n{\n\tFILE *f;\n\tint ret = EXIT_FAILURE;\n\n\tf = fopen(ofname, \"w\");\n\tif (f == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto out;\n\t}\n\n\terrno = 0;\n\tfwrite(data, len, 1, f);\n\tif (errno) {\n\t\tERRS(\"unable to write output file\");\n\t\tgoto out_flush;\n\t}\n\n\tDBG(\"firmware file \\\"%s\\\" completed\", ofname);\n\n\tret = EXIT_SUCCESS;\n\nout_flush:\n\tfflush(f);\n\tfclose(f);\n\tif (ret != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\nout:\n\treturn ret;\n}\n\nstatic uint32_t get_csum(unsigned char *p, uint32_t len)\n{\n\tuint32_t csum = 0;\n\n\twhile (len--)\n\t\tcsum += *p++;\n\n\treturn csum;\n}\n\nstatic int build_fw(void)\n{\n\tint buflen;\n\tchar *buf;\n\tchar *p;\n\tuint32_t csum;\n\tstruct img_header *hdr;\n\tint ret = EXIT_FAILURE;\n\n\tbuflen = sizeof(struct img_header) +\n\t\t kernel_info.write_size + rootfs_info.write_size;\n\n\tbuf = malloc(buflen);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto out;\n\t}\n\n\tmemset(buf, 0, buflen);\n\n\tp = buf + sizeof(struct img_header);\n\n\t/* read kernel data */\n\tret = read_to_buf(&kernel_info, p);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\tp += kernel_info.write_size;\n\n\t/* read rootfs data */\n\tret = read_to_buf(&rootfs_info, p);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\tcsum = get_csum((unsigned char *)(buf + sizeof(struct img_header)),\n\t\t\tbuflen - sizeof(struct img_header));\n\n\t/* fill firmware header */\n\thdr = (struct img_header *) buf;\n\n\thdr->checksum = htonl(csum);\n\thdr->image_size = htonl(buflen - sizeof(struct img_header));\n\thdr->kernel_size = htonl(kernel_info.write_size);\n\thdr->header_len = sizeof(struct img_header);\n\tstrncpy(hdr->model, model, sizeof(hdr->model));\n\tstrncpy(hdr->signature, signature, sizeof(hdr->signature));\n\tstrncpy(hdr->version, version, sizeof(hdr->version));\n\tstrncpy(hdr->region, region, sizeof(hdr->region));\n\n\tret = write_fw(buf, buflen);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\tret = EXIT_SUCCESS;\n\nout_free_buf:\n\tfree(buf);\nout:\n\treturn ret;\n}\n\nint main(int argc, char *argv[])\n{\n\tint ret = EXIT_FAILURE;\n\n\tprogname = basename(argv[0]);\n\n\twhile (1) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"M:S:V:R:k:K:I:r:o:h\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'M':\n\t\t\tmodel = optarg;\n\t\t\tbreak;\n\t\tcase 'S':\n\t\t\tsignature = optarg;\n\t\t\tbreak;\n\t\tcase 'V':\n\t\t\tversion = optarg;\n\t\t\tbreak;\n\t\tcase 'R':\n\t\t\tregion = optarg;\n\t\t\tbreak;\n\t\tcase 'k':\n\t\t\tkernel_info.file_name = optarg;\n\t\t\tbreak;\n\t\tcase 'K':\n\t\t\tif (str2u32(optarg, &kernel_size)) {\n\t\t\t\tERR(\"%s is invalid '%s'\",\n\t\t\t\t    \"kernel size\", optarg);\n\t\t\t\tgoto out;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'I':\n\t\t\tif (str2u32(optarg, &image_size)) {\n\t\t\t\tERR(\"%s is invalid '%s'\",\n\t\t\t\t    \"image size\", optarg);\n\t\t\t\tgoto out;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'r':\n\t\t\trootfs_info.file_name = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tret = check_options();\n\tif (ret)\n\t\tgoto out;\n\n\tret = build_fw();\n\nout:\n\treturn ret;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/mkcasfw.c",
    "content": "/*\n *\n *  Copyright (C) 2007 OpenWrt.org\n *  Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n#include <endian.h>     /* for __BYTE_ORDER */\n#if defined(__CYGWIN__)\n#  include <byteswap.h>\n#endif\n\n#if (__BYTE_ORDER == __LITTLE_ENDIAN)\n#  define HOST_TO_LE16(x)\t(x)\n#  define HOST_TO_LE32(x)\t(x)\n#  define LE16_TO_HOST(x)\t(x)\n#  define LE32_TO_HOST(x)\t(x)\n#else\n#  define HOST_TO_LE16(x)\tbswap_16(x)\n#  define HOST_TO_LE32(x)\tbswap_32(x)\n#  define LE16_TO_HOST(x)\tbswap_16(x)\n#  define LE32_TO_HOST(x)\tbswap_32(x)\n#endif\n\n#define MAX_NUM_BLOCKS\t2\n#define MAX_ARG_COUNT\t32\n#define MAX_ARG_LEN\t1024\n#define FILE_BUF_LEN\t(16*1024)\n#define DEFAULT_PADC\t0xFF\n\n#define DEFAULT_BLOCK_ALIGN\t0x10000U\n\n#define CSUM_TYPE_NONE\t0\n#define CSUM_TYPE_8\t1\n#define CSUM_TYPE_16\t2\n#define CSUM_TYPE_32\t3\n\nstruct csum_state{\n\tint\tsize;\n\tuint32_t val;\n\tuint32_t tmp;\n\tint\todd;\n};\n\nstruct image_desc {\n\tint\t\tneed_file;\n\tchar\t\t*file_name;\t/* name of the file */\n\tuint32_t\tfile_size;\t/* length of the file */\n\n\tuint32_t\tcsum;\n\tuint32_t\tout_size;\n\tuint8_t\t\tpadc;\n};\n\nstruct fwhdr_nfs {\n\tuint32_t\ttype;\n\tuint32_t\tkernel_offs;\n\tuint32_t\tkernel_size;\n\tuint32_t\tfs_offs;\n\tuint32_t\tfs_size;\n\tuint32_t\tkernel_csum;\n\tuint32_t\tfs_csum;\n\tuint32_t\tid;\n} __attribute__ ((packed));\n\nstruct fwhdr_cas {\n\tuint32_t\ttype;\n\tuint32_t\tkernel_offs;\n\tuint32_t\tkernel_size;\n\tuint32_t\tid;\n\tuint32_t\tkernel_csum;\n\tuint32_t\tmagic1;\n\tuint32_t\tmagic2;\n\tuint32_t\tmagic3;\n} __attribute__ ((packed));\n\nunion file_hdr {\n\tstruct fwhdr_cas cas;\n\tstruct fwhdr_nfs nfs;\n};\n\nstruct board_info {\n\tchar\t\t*model;\n\tchar\t\t*name;\n\tint\t\theader_type;\n\tuint32_t\tid;\n\tuint32_t\tmax_kernel_size;\n\tuint32_t\tmax_fs_size;\n};\n\n#define HEADER_TYPE_NFS\t\t0\n#define HEADER_TYPE_CAS\t\t1\n\n#define KERNEL_SIZE_CAS\t\t(61*64*1024)\n#define KERNEL_SIZE_NFS\t\t(52*64*1024)\n#define FS_SIZE_NFS\t\t(9*64*1024)\n\n#define CAS_MAGIC1\t0x5241AA55\n#define CAS_MAGIC2\t0x524F4741\n#define CAS_MAGIC3\t0xD3F22D4E\n\n/* Cellvision/SparkLAN products */\n#define MODEL_CAS_630\t\t0x01000000\n#define MODEL_CAS_630W\t\t0x01000000\n#define MODEL_CAS_670\t\t0x01000000\n#define MODEL_CAS_670W\t\t0x01000000\n#define MODEL_NFS_101U\t\t0x01000000\n#define MODEL_NFS_101WU\t\t0x01000003\n#define MODEL_NFS_202U\t\t0x01000001\n#define MODEL_NFS_202WU\t\t0x01000002\n\n/* Corega products */\n#define MODEL_CG_NSADP\t\t0x01000020 /* NFS-101U */\n#define MODEL_CG_NSADPCR\t0x01000021 /* NFS-202U */\n\n/* D-Link products */\n#define MODEL_DCS_950\t\t0x01010102 /* CAS-630 */\n#define MODEL_DCS_950G\t\t0x01020102 /* CAS-630W */\n#define MODEL_DNS_120\t\t0x01000030 /* NFS-101U */\n#define MODEL_DNS_G120\t\t0x01000032 /* NFS-101WU */\n\n/* Digitus products */\n#define MODEL_DN_16021\t\tMODEL_CAS_630\n#define MODEL_DN_16022\t\tMODEL_CAS_630W\n#define MODEL_DN_16030\t\tMODEL_CAS_670\n#define MODEL_DN_16031\t\tMODEL_CAS_670W\n#define MODEL_DN_7013\t\tMODEL_NFS_101U\n\n/* Lobos products */\n#define MODEL_LB_SS01TXU\t0x00000000\n\n/* Neu-Fusion products */\n\n/* Ovislink products */\n#define MODEL_MU_5000FS\t\t0x01000040 /* NFS-101U */\n#define MODEL_WL_5420CAM\t0x020B0101 /* CAS-630W? */\n#define MODEL_WL_5460CAM\t0x020B0001 /* CAS-670W */\n\n/* Repotec products */\n\n/* Sitecom products */\n#define MODEL_LN_350\t\t/* unknown */\n#define MODEL_LN_403\t\t0x01020402\n#define MODEL_WL_401\t\t0x01010402\n\n/* Surecom products */\n#define MODEL_EP_4001_MM\t0x01030A02 /* CAS-630 */\n#define MODEL_EP_4002_MM\t0x01020A02 /* CAS-630W */\n#define MODEL_EP_4011_MM\t0x01010A02 /* CAS-670 */\n#define MODEL_EP_4012_MM\t0x01000A02 /* CAS-670W */\n#define MODEL_EP_9812_U\t\t/* unknown */\n\n/* Trendnet products */\n#define MODEL_TN_U100\t\t0x01000081 /* NFS-101U */\n#define MODEL_TN_U200\t\t0x01000082 /* NFS-202U */\n\n/*\n * Globals\n */\nchar *progname;\nchar *ofname;\nint verblevel;\nint keep_invalid_images;\nint invalid_causes_error = 1;\nunion file_hdr header;\n\nstruct image_desc kernel_image;\nstruct image_desc fs_image;\n\nstruct board_info *board = NULL;\n\n#define BOARD(m, n, i, ks, fs, h) {\t\t\\\n\t\t.model = (m),\t\t\t\\\n\t\t.name = (n),\t\t\t\\\n\t\t.id = (i),\t\t\t\\\n\t\t.max_kernel_size = (ks), \t\\\n\t\t.max_fs_size = (fs), \t\t\\\n\t\t.header_type = (h)\t\t\\\n\t}\n\n#define BOARD_CAS(m,n,i) \\\n\t\tBOARD(m, n, i, KERNEL_SIZE_CAS, 0, HEADER_TYPE_CAS)\n#define BOARD_NFS(m,n,i) \\\n\t\tBOARD(m, n, i, KERNEL_SIZE_NFS, FS_SIZE_NFS, HEADER_TYPE_NFS)\n\nstatic struct board_info boards[] = {\n\t/* Cellvision/Sparklan products */\n\tBOARD_CAS(\"CAS-630\", \"Cellvision CAS-630\", MODEL_CAS_630),\n\tBOARD_CAS(\"CAS-630W\", \"Cellvision CAS-630W\", MODEL_CAS_630W),\n\tBOARD_CAS(\"CAS-670\", \"Cellvision CAS-670\", MODEL_CAS_670),\n\tBOARD_CAS(\"CAS-670W\", \"Cellvision CAS-670W\", MODEL_CAS_670W),\n\tBOARD_NFS(\"NFS-101U\", \"Cellvision NFS-101U\", MODEL_NFS_101U),\n\tBOARD_NFS(\"NFS-101WU\", \"Cellvision NFS-101WU\", MODEL_NFS_101WU),\n\tBOARD_NFS(\"NFS-202U\", \"Cellvision NFS-202U\", MODEL_NFS_202U),\n\tBOARD_NFS(\"NFS-202WU\", \"Cellvision NFS-202WU\", MODEL_NFS_202WU),\n\n\t/* Corega products */\n\tBOARD_NFS(\"CG-NSADP\", \"Corega CG-NSADP\", MODEL_CG_NSADP),\n\tBOARD_NFS(\"CG-NSADPCR\", \"Corega CG-NSADPCR\", MODEL_CG_NSADPCR),\n\n\t/* D-Link products */\n\tBOARD_CAS(\"DCS-950\", \"D-Link DCS-950\", MODEL_DCS_950),\n\tBOARD_CAS(\"DCS-950G\", \"D-Link DCS-950G\", MODEL_DCS_950G),\n\tBOARD_NFS(\"DNS-120\", \"D-Link DNS-120\", MODEL_DNS_120),\n\tBOARD_NFS(\"DNS-G120\", \"D-Link DNS-G120\", MODEL_DNS_G120),\n\n\t/* Digitus products */\n\tBOARD_NFS(\"DN-7013\", \"Digitus DN-7013\", MODEL_DN_7013),\n\n\t/* Lobos products */\n\tBOARD_NFS(\"LB-SS01TXU\", \"Lobos LB-SS01TXU\", MODEL_LB_SS01TXU),\n\n\t/* Ovislink products */\n\tBOARD_NFS(\"MU-5000FS\", \"Ovislink MU-5000FS\", MODEL_MU_5000FS),\n\tBOARD_CAS(\"WL-5420CAM\", \"Ovislink WL-5420 CAM\", MODEL_WL_5420CAM),\n\tBOARD_CAS(\"WL-5460CAM\", \"Ovislink WL-5460 CAM\", MODEL_WL_5460CAM),\n\n\t/* Sitecom products */\n\tBOARD_CAS(\"LN-403\", \"Sitecom LN-403\", MODEL_LN_403),\n\tBOARD_CAS(\"WL-401\", \"Sitecom WL-401\", MODEL_WL_401),\n\n\t/* Surecom products */\n\tBOARD_CAS(\"EP-4001-MM\", \"Surecom EP-4001-MM\", MODEL_EP_4001_MM),\n\tBOARD_CAS(\"EP-4002-MM\", \"Surecom EP-4002-MM\", MODEL_EP_4002_MM),\n\tBOARD_CAS(\"EP-4011-MM\", \"Surecom EP-4011-MM\", MODEL_EP_4011_MM),\n\tBOARD_CAS(\"EP-4012-MM\", \"Surecom EP-4012-MM\", MODEL_EP_4012_MM),\n\n\t/* TrendNET products */\n\tBOARD_NFS(\"TN-U100\", \"TrendNET TN-U100\", MODEL_TN_U100),\n\tBOARD_NFS(\"TN-U200\", \"TrendNET TN-U200\", MODEL_TN_U200),\n\n\t{.model = NULL}\n};\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\n#define WARN(fmt, ...) do { \\\n\tfprintf(stderr, \"[%s] *** warning: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define DBG(lev, fmt, ...) do { \\\n\tif (verblevel < lev) \\\n\t\tbreak;\\\n\tfprintf(stderr, \"[%s] \" fmt \"\\n\", progname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERR_FATAL\t\t-1\n#define ERR_INVALID_IMAGE\t-2\n\nvoid\nusage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct board_info *board;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...] <file>\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -B <board>      create image for the board specified with <board>.\\n\"\n\"                  valid <board> values:\\n\"\n\t);\n\tfor (board = boards; board->model != NULL; board++){\n\t\tfprintf(stream,\n\"                  %-12s: %s\\n\",\n\t\t board->model, board->name);\n\t};\n\tfprintf(stream,\n\"  -d              don't throw error on invalid images\\n\"\n\"  -k              keep invalid images\\n\"\n\"  -K <file>       add kernel to the image\\n\"\n\"  -C <file>       add custom filesystem to the image\\n\"\n\"  -h              show this screen\\n\"\n\"Parameters:\\n\"\n\"  <file>          write output to the file <file>\\n\"\n\t);\n\n\texit(status);\n}\n\nstatic inline uint32_t align(uint32_t base, uint32_t alignment)\n{\n\tuint32_t ret;\n\n\tif (alignment) {\n\t\tret = (base + alignment - 1);\n\t\tret &= ~(alignment-1);\n\t} else {\n\t\tret = base;\n\t}\n\n\treturn ret;\n}\n\n/*\n * argument parsing\n */\nint\nstr2u32(char *arg, uint32_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err)) {\n\t\treturn -1;\n\t}\n\n\t*val = t;\n\treturn 0;\n}\n\n\nint\nstr2u16(char *arg, uint16_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err) || (t >= 0x10000)) {\n\t\treturn -1;\n\t}\n\n\t*val = t & 0xFFFF;\n\treturn 0;\n}\n\nint\nstr2u8(char *arg, uint8_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err) || (t >= 0x100)) {\n\t\treturn -1;\n\t}\n\n\t*val = t & 0xFF;\n\treturn 0;\n}\n\nint\nparse_arg(char *arg, char *buf, char *argv[])\n{\n\tint res = 0;\n\tsize_t argl;\n\tchar *tok;\n\tchar **ap = &buf;\n\tint i;\n\n\tmemset(argv, 0, MAX_ARG_COUNT * sizeof(void *));\n\n\tif ((arg == NULL)) {\n\t\t/* no arguments */\n\t\treturn 0;\n\t}\n\n\targl = strlen(arg);\n\tif (argl == 0) {\n\t\t/* no arguments */\n\t\treturn 0;\n\t}\n\n\tif (argl >= MAX_ARG_LEN) {\n\t\t/* argument is too long */\n\t\targl = MAX_ARG_LEN-1;\n\t}\n\n\tmemcpy(buf, arg, argl);\n\tbuf[argl] = '\\0';\n\n\tfor (i = 0; i < MAX_ARG_COUNT; i++) {\n\t\ttok = strsep(ap, \":\");\n\t\tif (tok == NULL) {\n\t\t\tbreak;\n\t\t}\n#if 0\n\t\telse if (tok[0] == '\\0') {\n\t\t\tbreak;\n\t\t}\n#endif\n\t\targv[i] = tok;\n\t\tres++;\n\t}\n\n\treturn res;\n}\n\n\nint\nrequired_arg(char c, char *arg)\n{\n\tif (arg == NULL || *arg != '-')\n\t\treturn 0;\n\n\tERR(\"option -%c requires an argument\\n\", c);\n\treturn ERR_FATAL;\n}\n\n\nint\nis_empty_arg(char *arg)\n{\n\tint ret = 1;\n\tif (arg != NULL) {\n\t\tif (*arg) ret = 0;\n\t};\n\treturn ret;\n}\n\n\nvoid\ncsum8_update(uint8_t *p, uint32_t len, struct csum_state *css)\n{\n\tfor ( ; len > 0; len --) {\n\t\tcss->val += *p++;\n\t}\n}\n\n\nuint16_t\ncsum8_get(struct csum_state *css)\n{\n\tuint8_t t;\n\n\tt = css->val;\n\treturn ~t + 1;\n}\n\n\nvoid\ncsum16_update(uint8_t *p, uint32_t len, struct csum_state *css)\n{\n\tuint16_t t;\n\n\tif (css->odd) {\n\t\tt = css->tmp + (p[0]<<8);\n\t\tcss->val += LE16_TO_HOST(t);\n\t\tcss->odd = 0;\n\t\tlen--;\n\t\tp++;\n\t}\n\n\tfor ( ; len > 1; len -= 2, p +=2 ) {\n\t\tt = p[0] + (p[1] << 8);\n\t\tcss->val += LE16_TO_HOST(t);\n\t}\n\n\tif (len == 1) {\n\t\tcss->tmp = p[0];\n\t\tcss->odd = 1;\n\t}\n}\n\n\nuint16_t\ncsum16_get(struct csum_state *css)\n{\n\tchar pad = 0;\n\n\tcsum16_update(&pad, 1, css);\n\treturn ~css->val + 1;\n}\n\nvoid\ncsum32_update(uint8_t *p, uint32_t len, struct csum_state *css)\n{\n\tuint32_t t;\n\n\tfor ( ; len > 3; len -= 4, p += 4 ) {\n\t\tt = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);\n\t\tcss->val ^= t;\n\t}\n}\n\nuint32_t\ncsum32_get(struct csum_state *css)\n{\n\treturn css->val;\n}\n\n\nvoid\ncsum_init(struct csum_state *css, int size)\n{\n\tcss->val = 0;\n\tcss->tmp = 0;\n\tcss->odd = 0;\n\tcss->size = size;\n}\n\nvoid\ncsum_update(uint8_t *p, uint32_t len, struct csum_state *css)\n{\n\tswitch (css->size) {\n\tcase CSUM_TYPE_8:\n\t\tcsum8_update(p,len,css);\n\t\tbreak;\n\tcase CSUM_TYPE_16:\n\t\tcsum16_update(p,len,css);\n\t\tbreak;\n\tcase CSUM_TYPE_32:\n\t\tcsum32_update(p,len,css);\n\t\tbreak;\n\t}\n}\n\n\nuint32_t\ncsum_get(struct csum_state *css)\n{\n\tuint32_t ret;\n\n\tswitch (css->size) {\n\tcase CSUM_TYPE_8:\n\t\tret = csum8_get(css);\n\t\tbreak;\n\tcase CSUM_TYPE_16:\n\t\tret = csum16_get(css);\n\t\tbreak;\n\tcase CSUM_TYPE_32:\n\t\tret = csum32_get(css);\n\t}\n\n\treturn ret;\n}\n\n\n/*\n * routines to write data to the output file\n */\nint\nwrite_out_data(FILE *outfile, uint8_t *data, size_t len,\n\t\tstruct csum_state *css)\n{\n\terrno = 0;\n\n\tfwrite(data, len, 1, outfile);\n\tif (errno) {\n\t\tERRS(\"unable to write output file\");\n\t\treturn ERR_FATAL;\n\t}\n\n\tif (css) {\n\t\tcsum_update(data, len, css);\n\t}\n\n\treturn 0;\n}\n\n\nint\nwrite_out_padding(FILE *outfile, size_t len, uint8_t padc,\n\t\t struct csum_state *css)\n{\n\tuint8_t buf[512];\n\tsize_t buflen = sizeof(buf);\n\tint err;\n\n\tmemset(buf, padc, buflen);\n\twhile (len > 0) {\n\t\tif (len < buflen)\n\t\t\tbuflen = len;\n\n\t\terr = write_out_data(outfile, buf, buflen, css);\n\t\tif (err)\n\t\t\treturn err;\n\n\t\tlen -= buflen;\n\t}\n\n\treturn 0;\n}\n\n\nint\nimage_stat_file(struct image_desc *desc)\n{\n\tstruct stat st;\n\tint err;\n\n\tif (desc->file_name == NULL)\n\t\treturn 0;\n\n\terr = stat(desc->file_name, &st);\n\tif (err){\n\t\tERRS(\"stat failed on %s\", desc->file_name);\n\t\treturn ERR_FATAL;\n\t}\n\n\tif (st.st_size > desc->out_size) {\n\t\tWARN(\"file %s is too big, will be truncated to %d bytes\\n\",\n\t\t\tdesc->file_name, desc->out_size);\n\t\tdesc->file_size = desc->out_size;\n\t\treturn ERR_INVALID_IMAGE;\n\t}\n\n\n\tdesc->file_size = st.st_size;\n\tdesc->out_size = align(desc->file_size,1);\n\treturn 0;\n}\n\n\nint\nimage_writeout_file(FILE *outfile, struct image_desc *desc,\n\t\t\tstruct csum_state *css)\n{\n\tchar buf[FILE_BUF_LEN];\n\tsize_t buflen = sizeof(buf);\n\tFILE *f;\n\tsize_t len;\n\tint res;\n\n\tif (desc->file_name == NULL)\n\t\treturn 0;\n\n\tif (desc->file_size == 0)\n\t\treturn 0;\n\n\terrno = 0;\n\tf = fopen(desc->file_name,\"r\");\n\tif (errno) {\n\t\tERRS(\"unable to open file: %s\", desc->file_name);\n\t\treturn ERR_FATAL;\n\t}\n\n\tlen = desc->file_size;\n\twhile (len > 0) {\n\t\tif (len < buflen)\n\t\t\tbuflen = len;\n\n\t\t/* read data from source file */\n\t\terrno = 0;\n\t\tfread(buf, buflen, 1, f);\n\t\tif (errno != 0) {\n\t\t\tERRS(\"unable to read from file: %s\", desc->file_name);\n\t\t\tres = ERR_FATAL;\n\t\t\tbreak;\n\t\t}\n\n\t\tres = write_out_data(outfile, buf, buflen, css);\n\t\tif (res)\n\t\t\tbreak;\n\n\t\tlen -= buflen;\n\t}\n\n\tfclose(f);\n\treturn res;\n}\n\n\nint\nimage_writeout(FILE *outfile, struct image_desc *desc)\n{\n\tint res;\n\tstruct csum_state css;\n\tsize_t padlen;\n\n\tres = 0;\n\n\tif (!desc->file_size)\n\t\treturn 0;\n\n\tDBG(2, \"writing image, file=%s, file_size=%d\\n\",\n\t\tdesc->file_name, desc->file_size);\n\n\tcsum_init(&css, CSUM_TYPE_32);\n\n\tres = image_writeout_file(outfile, desc, &css);\n\tif (res)\n\t\treturn res;\n\n\t/* write padding data if neccesary */\n\tpadlen = desc->out_size - desc->file_size;\n\tDBG(1,\"padding desc, length=%d\", padlen);\n\tres = write_out_padding(outfile, padlen, desc->padc, &css);\n\n\tdesc->csum = csum_get(&css);\n\n\treturn res;\n}\n\n\nint\nwrite_out_header(FILE *outfile)\n{\n\tunion file_hdr tmp;\n\tint res;\n\n\terrno = 0;\n\tif (fseek(outfile, 0, SEEK_SET) != 0) {\n\t\tERRS(\"fseek failed on output file\");\n\t\treturn ERR_FATAL;\n\t}\n\n\tswitch (board->header_type) {\n\tcase HEADER_TYPE_CAS:\n\t\ttmp.cas.type = HOST_TO_LE32(header.cas.type);\n\t\ttmp.cas.id = HOST_TO_LE32(header.cas.id);\n\t\ttmp.cas.kernel_offs = HOST_TO_LE32(sizeof(tmp.cas));\n\t\ttmp.cas.kernel_size = HOST_TO_LE32(kernel_image.out_size);\n\t\ttmp.cas.kernel_csum = HOST_TO_LE32(kernel_image.csum);\n\t\ttmp.cas.magic1 = HOST_TO_LE32(CAS_MAGIC1);\n\t\ttmp.cas.magic2 = HOST_TO_LE32(CAS_MAGIC2);\n\t\ttmp.cas.magic3 = HOST_TO_LE32(CAS_MAGIC3);\n\t\tres = write_out_data(outfile, (uint8_t *)&tmp.cas,\n\t\t\t\t\tsizeof(tmp.cas), NULL);\n\t\tbreak;\n\tcase HEADER_TYPE_NFS:\n\t\ttmp.nfs.type = HOST_TO_LE32(header.nfs.type);\n\t\ttmp.nfs.id = HOST_TO_LE32(header.nfs.id);\n\t\ttmp.nfs.kernel_offs = HOST_TO_LE32(sizeof(tmp.nfs));\n\t\ttmp.nfs.kernel_size = HOST_TO_LE32(kernel_image.out_size);\n\t\ttmp.nfs.kernel_csum = HOST_TO_LE32(kernel_image.csum);\n\t\ttmp.nfs.fs_offs = HOST_TO_LE32(sizeof(tmp.nfs)\n\t\t\t\t\t+ kernel_image.out_size);\n\t\ttmp.nfs.fs_size = HOST_TO_LE32(fs_image.out_size);\n\t\ttmp.nfs.fs_csum = HOST_TO_LE32(fs_image.csum);\n\t\tres = write_out_data(outfile, (uint8_t *)&tmp.nfs,\n\t\t\t\t\tsizeof(tmp.nfs), NULL);\n\t\tbreak;\n\t}\n\n\treturn res;\n}\n\nint\nwrite_out_images(FILE *outfile)\n{\n\tstruct image_desc *desc;\n\tint i, res;\n\n\tres = image_writeout(outfile, &kernel_image);\n\tif (res)\n\t\treturn res;\n\n\tres = image_writeout(outfile, &fs_image);\n\tif (res)\n\t\treturn res;\n\n\treturn 0;\n}\n\n\nstruct board_info *\nfind_board(char *model)\n{\n\tstruct board_info *ret;\n\tstruct board_info *board;\n\n\tret = NULL;\n\tfor (board = boards; board->model != NULL; board++){\n\t\tif (strcasecmp(model, board->model) == 0) {\n\t\t\tret = board;\n\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn ret;\n}\n\n\nint\nparse_opt_board(char ch, char *arg)\n{\n\n\tDBG(1,\"parsing board option: -%c %s\", ch, arg);\n\n\tif (board != NULL) {\n\t\tERR(\"only one board option allowed\");\n\t\treturn ERR_FATAL;\n\t}\n\n\tif (required_arg(ch, arg))\n\t\treturn ERR_FATAL;\n\n\tboard = find_board(arg);\n\tif (board == NULL){\n\t\tERR(\"invalid/unknown board specified: %s\", arg);\n\t\treturn ERR_FATAL;\n\t}\n\n\tswitch (board->header_type) {\n\tcase HEADER_TYPE_CAS:\n\t\theader.cas.type = HEADER_TYPE_CAS;\n\t\theader.cas.id = board->id;\n\t\tbreak;\n\tcase HEADER_TYPE_NFS:\n\t\theader.nfs.type = HEADER_TYPE_NFS;\n\t\theader.nfs.id = board->id;\n\t\tbreak;\n\tdefault:\n\t\tERR(\"internal error, unknown header type\\n\");\n\t\treturn ERR_FATAL;\n\t}\n\n\treturn 0;\n}\n\n\nint\nparse_opt_image(char ch, char *arg)\n{\n\tchar buf[MAX_ARG_LEN];\n\tchar *argv[MAX_ARG_COUNT];\n\tint argc;\n\tchar *p;\n\tstruct image_desc *desc = NULL;\n\tint i;\n\n\tswitch (ch) {\n\tcase 'K':\n\t\tif (kernel_image.file_name) {\n\t\t\tWARN(\"only one kernel option allowed\");\n\t\t\tbreak;\n\t\t}\n\t\tdesc = &kernel_image;\n\t\tbreak;\n\tcase 'F':\n\t\tif (fs_image.file_name) {\n\t\t\tWARN(\"only one fs option allowed\");\n\t\t\tbreak;\n\t\t}\n\t\tdesc = &fs_image;\n\t\tbreak;\n\t}\n\n\tif (!desc)\n\t\treturn ERR_FATAL;\n\n\targc = parse_arg(arg, buf, argv);\n\n\ti = 0;\n\tp = argv[i++];\n\tif (!is_empty_arg(p)) {\n\t\tdesc->file_name = strdup(p);\n\t\tif (desc->file_name == NULL) {\n\t\t\tERR(\"not enough memory\");\n\t\t\treturn ERR_FATAL;\n\t\t}\n\t} else {\n\t\tERR(\"no file specified for option %c\", ch);\n\t\treturn ERR_FATAL;\n\t}\n\n\treturn 0;\n}\n\n\nint\nprocess_images(void)\n{\n\tstruct image_desc *desc;\n\tuint32_t offs = 0;\n\tint i;\n\tint res;\n\n\tkernel_image.out_size = board->max_kernel_size;\n\tkernel_image.padc = DEFAULT_PADC;\n\tres = image_stat_file(&kernel_image);\n\tif (res)\n\t\treturn res;\n\n\tif (!fs_image.file_name)\n\t\treturn 0;\n\n\tfs_image.out_size = board->max_fs_size;\n\tfs_image.padc = DEFAULT_PADC;\n\tres = image_stat_file(&fs_image);\n\tif (res)\n\t\treturn res;\n\n\treturn 0;\n}\n\n\nint\nmain(int argc, char *argv[])\n{\n\tint optinvalid = 0;   /* flag for invalid option */\n\tint c;\n\tint res = ERR_FATAL;\n\n\tFILE *outfile;\n\n\tprogname=basename(argv[0]);\n\n\topterr = 0;  /* could not print standard getopt error messages */\n\twhile ( 1 ) {\n\t\toptinvalid = 0;\n\n\t\tc = getopt(argc, argv, \"B:C:dhK:r:vw:x:\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'B':\n\t\t\toptinvalid = parse_opt_board(c,optarg);\n\t\t\tbreak;\n\t\tcase 'd':\n\t\t\tinvalid_causes_error = 0;\n\t\t\tbreak;\n\t\tcase 'C':\n\t\tcase 'K':\n\t\t\toptinvalid = parse_opt_image(c,optarg);\n\t\t\tbreak;\n\t\tcase 'k':\n\t\t\tkeep_invalid_images = 1;\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tverblevel++;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\toptinvalid = 1;\n\t\t\tbreak;\n\t\t}\n\t\tif (optinvalid != 0 ){\n\t\t\tERR(\"invalid option: -%c\", optopt);\n\t\t\tgoto out;\n\t\t}\n\t}\n\n\tif (board == NULL) {\n\t\tERR(\"no board specified\");\n\t\tgoto out;\n\t}\n\n\tif (optind == argc) {\n\t\tERR(\"no output file specified\");\n\t\tgoto out;\n\t}\n\n\tofname = argv[optind++];\n\n\tif (optind < argc) {\n\t\tERR(\"invalid option: %s\", argv[optind]);\n\t\tgoto out;\n\t}\n\n\tres = process_images();\n\tif (res == ERR_FATAL)\n\t\tgoto out;\n\n\tif (res == ERR_INVALID_IMAGE) {\n\t\tif (invalid_causes_error)\n\t\t\tres = ERR_FATAL;\n\n\t\tif (keep_invalid_images == 0) {\n\t\t\tWARN(\"generation of invalid images disabled\", ofname);\n\t\t\tgoto out;\n\t\t}\n\n\t\tWARN(\"generating invalid image\", ofname);\n\t}\n\n\toutfile = fopen(ofname, \"w\");\n\tif (outfile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tres = ERR_FATAL;\n\t\tgoto out;\n\t}\n\n\tif (write_out_header(outfile) != 0) {\n\t\tres = ERR_FATAL;\n\t\tgoto out_flush;\n\t}\n\n\tif (write_out_images(outfile) != 0) {\n\t\tres = ERR_FATAL;\n\t\tgoto out_flush;\n\t}\n\n\tif (write_out_header(outfile) != 0) {\n\t\tres = ERR_FATAL;\n\t\tgoto out_flush;\n\t}\n\n\tDBG(1,\"Image file %s completed.\", ofname);\n\nout_flush:\n\tfflush(outfile);\n\tfclose(outfile);\n\tif (res == ERR_FATAL) {\n\t\tunlink(ofname);\n\t}\nout:\n\tif (res == ERR_FATAL)\n\t\treturn EXIT_FAILURE;\n\n\treturn EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkchkimg.c",
    "content": "/*\n * \tMake CHK Image\n *\n * \tThis utility creates Netgear .chk files.\n *\n * \tCopyright (C) 2008 Dave C. Reeve <Dave.Reeve@dreeve.org>\n *\n *\tThis program is free software; you can redistribute it and/or modify\n *\tit under the terms of the GNU General Public License as published by\n *\tthe Free Software Foundation; either version 2 of the License, or\n *\t(at your option) any later version.\n *\n *\tThis program is distributed in the hope that it will be useful,\n *\tbut WITHOUT ANY WARRANTY; without even the implied warranty of\n *\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *\tGNU General Public License for more details.\n *\t\n *\tYou should have received a copy of the GNU General Public License along\n *\twith this program; if not, write to the Free Software Foundation, Inc.,\n *\t51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n */\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdarg.h>\n#include <errno.h>\n#include <arpa/inet.h>\n#include <unistd.h>\n\n#define BUF_LEN (2048)\n\n#define MAX_BOARD_ID_LEN (64)\n\nstruct chk_header {\n\tuint32_t magic;\n\tuint32_t header_len;\n\tuint8_t  reserved[8];\n\tuint32_t kernel_chksum;\n\tuint32_t rootfs_chksum;\n\tuint32_t kernel_len;\n\tuint32_t rootfs_len;\n\tuint32_t image_chksum;\n\tuint32_t header_chksum;\n\t/* char board_id[] - upto MAX_BOARD_ID_LEN */\n};\n\nstatic void __attribute__ ((format (printf, 2, 3)))\nfatal_error (int maybe_errno, const char * format, ...)\n{\n\tva_list ap;\n\n\tfprintf (stderr, \"mkchkimg: \");\n\tva_start (ap, format);\n\tvfprintf (stderr, format, ap);\n\tva_end (ap);\n\n\tif (maybe_errno) {\n\t\tfprintf (stderr, \": %s\\n\", strerror (maybe_errno));\n\t} else {\n\t\tfprintf (stderr, \"\\n\");\n\t}\n\n\texit (EXIT_FAILURE);\n}\n\nstatic void __attribute__ ((format (printf, 1, 2)))\nmessage (const char * format, ...)\n{\n\tva_list ap;\n\n\tfprintf (stderr, \"mkchkimg: \");\n\tva_start (ap, format);\n\tvfprintf (stderr, format, ap);\n\tva_end (ap);\n\tfprintf (stderr, \"\\n\");\n}\n\nstruct ngr_checksum {\n\tuint32_t c0;\n\tuint32_t c1;\n};\n\nstatic inline void\nnetgear_checksum_init (struct ngr_checksum * c)\n{\n\tc->c0 = c->c1 = 0;\n}\n\nstatic inline void\nnetgear_checksum_add (struct ngr_checksum * c, unsigned char * buf, size_t len)\n{\n\tsize_t i;\n\n\tfor (i=0; i<len; i++) {\n\t\tc->c0 += buf[i] & 0xff;\n\t\tc->c1 += c->c0;\n\t}\n}\n\nstatic inline unsigned long\nnetgear_checksum_fini (struct ngr_checksum * c)\n{\n\tuint32_t b, checksum;\n\n\tb = (c->c0 & 65535) + ((c->c0 >> 16) & 65535);\n\tc->c0 = ((b >> 16) + b) & 65535;\n\tb = (c->c1 & 65535) + ((c->c1 >> 16) & 65535);\n\tc->c1 = ((b >> 16) + b) & 65535;\n\tchecksum = ((c->c1 << 16) | c->c0);\n\treturn checksum;\n}\n\nstatic void\nprint_help (void)\n{\n\tfprintf (stderr, \"Usage: mkchkimg -o output -k kernel [-f filesys] [-b board_id] [-r region]\\n\");\n}\n\nint\nmain (int argc, char * argv[])\n{\n\tint opt;\n\tchar * ptr;\n\tsize_t len;\n\tsize_t header_len;\n\tstruct chk_header * hdr;\n\tstruct ngr_checksum chk_part, chk_whole;\n\tchar buf[BUF_LEN];\n\tchar * output_file, * kern_file, * fs_file;\n\tFILE * out_fp, * kern_fp, * fs_fp;\n\tchar * board_id;\n\tunsigned long region;\n\n\t/* Default values */\n\tboard_id = \"U12H072T00_NETGEAR\";\n\tregion = 1;\t/* 1=WW, 2=NA */\n\toutput_file = NULL;\n\tkern_file = NULL;\n\tfs_file = NULL;\n\tfs_fp = NULL;\n\n\twhile ((opt = getopt (argc, argv, \":b:r:k:f:o:h\")) != -1) {\n\t\tswitch (opt) {\n\t\t    case 'b':\n\t\t    \t/* Board Identity */\n\t\t\tif (strlen (optarg) > MAX_BOARD_ID_LEN) {\n\t\t\t\tfatal_error (0, \"Board lenght exceeds %d\", \n\t\t\t\t\tMAX_BOARD_ID_LEN);\n\t\t\t}\n\t\t\tboard_id = optarg;\n\t\t\tbreak;\n\n\t\t    case 'r':\n\t\t    \t/* Region */\n\t\t\terrno = 0;\n\t\t\tregion = strtoul (optarg, &ptr, 0);\n\t\t\tif (errno || ptr==optarg || *ptr!='\\0') {\n\t\t\t\tfatal_error (0, \"Cannot parse region %s\", optarg);\n\t\t\t}\n\t\t\tif (region > 0xff) {\n\t\t\t\tfatal_error (0, \"Region cannot exceed 0xff\");\n\t\t\t}\n\t\t\tbreak;\n\n\t\t    case 'k':\n\t\t    \t/* Kernel */\n\t\t\tkern_file = optarg;\n\t\t\tbreak;\n\n\t\t    case 'f':\n\t\t    \t/* Filing System */\n\t\t\tfs_file = optarg;\n\t\t\tbreak;\n\n\t\t    case 'o':\n\t\t    \t/* Output file */\n\t\t\toutput_file = optarg;\n\t\t\tbreak;\n\n\t\t    case 'h':\n\t\t    \tprint_help ();\n\t\t\treturn EXIT_SUCCESS;\n\n\t\t    case ':':\n\t\t    \tprint_help ();\n\t\t    \tfatal_error (0, \"Option -%c missing argument\", optopt);\n\t\t\tbreak;\n\n\t\t    case '?':\n\t\t    \tprint_help ();\n\t\t    \tfatal_error (0, \"Unknown argument -%c\", optopt);\n\t\t\tbreak;\n\t\t    \n\t\t    default:\n\t\t    \tbreak;\n\t\t}\n\t}\n\n\t/* Check we have all the options expected */\n\tif (!kern_file) {\n\t\tprint_help ();\n\t\tfatal_error (0, \"Kernel file expected\");\n\t}\n\tif (!output_file) {\n\t\tprint_help ();\n\t\tfatal_error (0, \"Output file required\");\n\t}\n\tmessage (\"Netgear CHK writer - v0.1\");\n\n\t/* Open the input file */\n\tkern_fp = fopen (kern_file, \"r\");\n\tif (!kern_fp) {\n\t\tfatal_error (errno, \"Cannot open %s\", kern_file);\n\t}\n\n\t/* Open the fs file, if specified */\n\tif (fs_file) {\n\t\tfs_fp = fopen (fs_file, \"r\");\n\t\tif (!fs_fp) {\n\t\t\tfatal_error (errno, \"Cannot open %s\", fs_file);\n\t\t}\n\t}\n\n\t/* Open the output file */\n\tout_fp = fopen (output_file, \"w+\");\n\tif (!out_fp) {\n\t\tfatal_error (errno, \"Cannot open %s\", output_file);\n\t}\n\n\t/* Write zeros when the chk header will be */\n\tbuf[0] = '\\0';\n\theader_len = sizeof (struct chk_header) + strlen (board_id);\n\tif (fwrite (buf, 1, header_len, out_fp) != header_len) {\n\t\tfatal_error (errno, \"Cannot write header\");\n\t}\n\n\t/* Allocate storage for header, we fill in as we go */\n\thdr = malloc (sizeof (struct chk_header));\n\tif (!hdr) {\n\t\tfatal_error (0, \"malloc failed\");\n\t}\n\tbzero (hdr, sizeof (struct chk_header));\n\n\t/* Fill in known values */\n\thdr->magic = htonl (0x2a23245e);\n\thdr->header_len = htonl(header_len);\n\thdr->reserved[0] = (unsigned char)(region & 0xff);\n\thdr->reserved[1] = 1;\t\t/* Major */\n\thdr->reserved[2] = 1;\t\t/* Minor */\n\thdr->reserved[3] = 99;\t\t/* Build */\n\thdr->reserved[4] = 0;\t\t/* Unknown t1 ? was 1 */\n\thdr->reserved[5] = 0;\t\t/* Unknonw t2 ? was 0 */\n\thdr->reserved[6] = 0;\t\t/* Unknonw t3 ? was 1 */\n\thdr->reserved[7] = 0;\t\t/* Unused ? */\n\tmessage (\"       Board Id: %s\", board_id);\n\tmessage (\"         Region: %s\", region == 1 ? \"World Wide (WW)\" \n\t\t\t: (region == 2 ? \"North America (NA)\" : \"Unknown\"));\n\n\t/* Copy the trx file, calculating the checksum as we go */\n\tnetgear_checksum_init (&chk_part);\n\tnetgear_checksum_init (&chk_whole);\n\twhile (!feof (kern_fp)) {\n\t\tlen = fread (buf, 1, BUF_LEN, kern_fp);\n\t\tif (len < 1) {\n\t\t\tbreak;\n\t\t}\n\t\tif (fwrite (buf, len, 1, out_fp) != 1) {\n\t\t\tfatal_error (errno, \"Write error\");\n\t\t}\n\t\thdr->kernel_len += len;\n\t\tnetgear_checksum_add (&chk_part, (unsigned char *)buf, len);\n\t\tnetgear_checksum_add (&chk_whole, (unsigned char *)buf, len);\n\t}\n\thdr->kernel_chksum = netgear_checksum_fini (&chk_part);\n\tmessage (\"     Kernel Len: %u\", hdr->kernel_len);\n\tmessage (\"Kernel Checksum: 0x%08x\", hdr->kernel_chksum);\n\thdr->kernel_len = htonl (hdr->kernel_len);\n\thdr->kernel_chksum = htonl (hdr->kernel_chksum);\n\n\t/* Now copy the root fs, calculating the checksum as we go */\n\tif (fs_fp) {\n\t\tnetgear_checksum_init (&chk_part);\n\t\twhile (!feof (fs_fp)) {\n\t\t\tlen = fread (buf, 1, BUF_LEN, fs_fp);\n\t\t\tif (len < 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (fwrite (buf, len, 1, out_fp) != 1) {\n\t\t\t\tfatal_error (errno, \"Write error\");\n\t\t\t}\n\t\t\thdr->rootfs_len += len;\n\t\t\tnetgear_checksum_add (&chk_part, (unsigned char *)buf, len);\n\t\t\tnetgear_checksum_add (&chk_whole, (unsigned char *)buf, len);\n\t\t}\n\t\thdr->rootfs_chksum = (netgear_checksum_fini (&chk_part));\n\t\tmessage (\"     Rootfs Len: %u\", hdr->rootfs_len);\n\t\tmessage (\"Rootfs Checksum: 0x%08x\", hdr->rootfs_chksum);\n\t\thdr->rootfs_len = htonl (hdr->rootfs_len);\n\t\thdr->rootfs_chksum = htonl (hdr->rootfs_chksum);\n\t}\n\n\t/* Calcautate the image checksum */\n\thdr->image_chksum = netgear_checksum_fini (&chk_whole);\n\tmessage (\" Image Checksum: 0x%08x\", hdr->image_chksum);\n\thdr->image_chksum = htonl (hdr->image_chksum);\n\n\t/* Calculate the header checksum */\n\tnetgear_checksum_init (&chk_part);\n\tnetgear_checksum_add (&chk_part, (unsigned char *)hdr, \n\t\t\t\tsizeof (struct chk_header));\n\tnetgear_checksum_add (&chk_part, (unsigned char *)board_id,\n\t\t\t\tstrlen (board_id));\n\thdr->header_chksum = htonl (netgear_checksum_fini (&chk_part));\n\n\t/* Finally rewind the output and write headers */\n\trewind (out_fp);\n\tif (fwrite (hdr, sizeof (struct chk_header), 1, out_fp) != 1) {\n\t\tfatal_error (errno, \"Cannot write header\");\n\t}\n\tif (fwrite (board_id, strlen (board_id), 1, out_fp) != 1) {\n\t\tfatal_error (errno, \"Cannot write board id\");\n\t}\n\n\t/* Success */\n\treturn EXIT_SUCCESS;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/mkcsysimg.c",
    "content": "/*\n *\n *  Copyright (C) 2007-2009 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program was based on the code found in various Linux\n *  source tarballs released by Edimax for it's devices.\n *  Original author: David Hsu <davidhsu@realtek.com.tw>\n *\n *  This program is free software; you can redistribute it and/or\n *  modify it under the terms of the GNU General Public License\n *  as published by the Free Software Foundation; either version 2\n *  of the License, or (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program; if not, write to the\n *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n *  Boston, MA  02110-1301, USA.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n#include <endian.h>     /* for __BYTE_ORDER */\n#if defined(__CYGWIN__)\n#  include <byteswap.h>\n#endif\n\n#include \"csysimg.h\"\n\n#if (__BYTE_ORDER == __LITTLE_ENDIAN)\n#  define HOST_TO_LE16(x)\t(x)\n#  define HOST_TO_LE32(x)\t(x)\n#  define LE16_TO_HOST(x)\t(x)\n#  define LE32_TO_HOST(x)\t(x)\n#else\n#  define HOST_TO_LE16(x)\tbswap_16(x)\n#  define HOST_TO_LE32(x)\tbswap_32(x)\n#  define LE16_TO_HOST(x)\tbswap_16(x)\n#  define LE32_TO_HOST(x)\tbswap_32(x)\n#endif\n\n#define MAX_NUM_BLOCKS\t8\n#define MAX_ARG_COUNT\t32\n#define MAX_ARG_LEN\t1024\n#define FILE_BUF_LEN\t(16*1024)\n#define CSYS_PADC\t0xFF\n\n#define BLOCK_TYPE_BOOT\t0\n#define BLOCK_TYPE_CONF\t1\n#define BLOCK_TYPE_WEBP\t2\n#define BLOCK_TYPE_CODE\t3\n#define BLOCK_TYPE_XTRA\t4\n\n#define DEFAULT_BLOCK_ALIGN\t0x10000U\n\n#define CSUM_SIZE_NONE\t0\n#define CSUM_SIZE_8\t1\n#define CSUM_SIZE_16\t2\n\n\nstruct csum_state{\n\tint\tsize;\n\tuint16_t val;\n\tuint16_t tmp;\n\tint\todd;\n};\n\n\nstruct csys_block {\n\tint\t\ttype;\t/* type of the block */\n\n\tint\t\tneed_file;\n\tchar\t\t*file_name;\t/* name of the file */\n\tuint32_t\tfile_size;\t/* length of the file */\n\n\tunsigned char\tsig[SIG_LEN];\n\tuint32_t\taddr;\n\tint\t\taddr_set;\n\tuint32_t\talign;\n\tint\t\talign_set;\n\tuint8_t\t\tpadc;\n\n\tuint32_t\tsize;\n\tuint32_t\tsize_hdr;\n\tuint32_t\tsize_csum;\n\tuint32_t\tsize_avail;\n\n\tstruct csum_state *css;\n};\n\n\nstruct board_info {\n\tchar *model;\n\tchar *name;\n\tuint32_t flash_size;\n\n\tchar sig_boot[SIG_LEN];\n\tchar sig_conf[SIG_LEN];\n\tchar sig_webp[SIG_LEN];\n\n\tuint32_t boot_size;\n\tuint32_t conf_size;\n\tuint32_t webp_size;\n\tuint32_t webp_size_max;\n\tuint32_t code_size;\n\n\tuint32_t addr_code;\n\tuint32_t addr_webp;\n};\n\n#define BOARD(m, n, f, sigb, sigw, bs, cs, ws, ac, aw) {\\\n\t.model = m, .name = n, .flash_size = f<<20, \\\n\t.sig_boot = sigb, .sig_conf = SIG_CONF, .sig_webp = sigw, \\\n\t.boot_size = bs, .conf_size = cs, \\\n\t.webp_size = ws, .webp_size_max = 3*0x10000, \\\n\t.addr_code = ac, .addr_webp = aw \\\n\t}\n\n#define BOARD_ADM(m,n,f, sigw) BOARD(m,n,f, ADM_BOOT_SIG, sigw, \\\n\tADM_BOOT_SIZE, ADM_CONF_SIZE, ADM_WEBP_SIZE, \\\n\tADM_CODE_ADDR, ADM_WEBP_ADDR)\n\n\n/*\n * Globals\n */\nchar *progname;\nchar *ofname = NULL;\nint verblevel = 0;\nint invalid_causes_error = 1;\nint keep_invalid_images = 0;\n\nstruct board_info *board = NULL;\n\nstruct csys_block *boot_block = NULL;\nstruct csys_block *conf_block = NULL;\nstruct csys_block *webp_block = NULL;\nstruct csys_block *code_block = NULL;\n\nstruct csys_block blocks[MAX_NUM_BLOCKS];\nint num_blocks = 0;\n\nstatic struct board_info boards[] = {\n\t/* The original Edimax products */\n\tBOARD_ADM(\"BR-6104K\", \"Edimax BR-6104K\", 2, SIG_BR6104K),\n\tBOARD_ADM(\"BR-6104KP\", \"Edimax BR-6104KP\", 2, SIG_BR6104KP),\n\tBOARD_ADM(\"BR-6104Wg\", \"Edimax BR-6104Wg\", 2, SIG_BR6104Wg),\n\tBOARD_ADM(\"BR-6114WG\", \"Edimax BR-6114WG\", 2, SIG_BR6114WG),\n\tBOARD_ADM(\"BR-6524K\", \"Edimax BR-6524K\", 2, SIG_BR6524K),\n\tBOARD_ADM(\"BR-6524KP\", \"Edimax BR-6524KP\", 2, SIG_BR6524KP),\n\tBOARD_ADM(\"BR-6524WG\", \"Edimax BR-6524WG\", 4, SIG_BR6524WG),\n\tBOARD_ADM(\"BR-6524WP\", \"Edimax BR-6524WP\", 4, SIG_BR6524WP),\n\tBOARD_ADM(\"BR-6541K\", \"Edimax BR-6541K\", 2, SIG_BR6541K),\n\tBOARD_ADM(\"BR-6541KP\", \"Edimax BR-6541K\", 2, SIG_BR6541KP),\n\tBOARD_ADM(\"BR-6541WP\", \"Edimax BR-6541WP\", 4, SIG_BR6541WP),\n\tBOARD_ADM(\"EW-7207APg\", \"Edimax EW-7207APg\", 2, SIG_EW7207APg),\n\tBOARD_ADM(\"PS-1205UWg\", \"Edimax PS-1205UWg\", 2, SIG_PS1205UWg),\n\tBOARD_ADM(\"PS-3205U\", \"Edimax PS-3205U\", 2, SIG_PS3205U),\n\tBOARD_ADM(\"PS-3205UWg\", \"Edimax PS-3205UWg\", 2, SIG_PS3205UWg),\n\n\t/* Hawking products */\n\tBOARD_ADM(\"H2BR4\", \"Hawking H2BR4\", 2, SIG_H2BR4),\n\tBOARD_ADM(\"H2WR54G\", \"Hawking H2WR54G\", 4, SIG_H2WR54G),\n\n\t/* Planet products */\n\tBOARD_ADM(\"XRT-401D\", \"Planet XRT-401D\", 2, SIG_XRT401D),\n\tBOARD_ADM(\"XRT-402D\", \"Planet XRT-402D\", 2, SIG_XRT402D),\n\n\t/* Conceptronic products */\n\tBOARD_ADM(\"C54BSR4\", \"Conceptronic C54BSR4\", 2, SIG_C54BSR4),\n\n\t/* OSBRiDGE products */\n\tBOARD_ADM(\"5GXi\", \"OSBDRiDGE 5GXi\", 2, SIG_5GXI),\n\n\t{.model = NULL}\n};\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", progname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", progname, ## __VA_ARGS__ \\\n\t\t, strerror(save)); \\\n} while (0)\n\n#define WARN(fmt, ...) do { \\\n\tfprintf(stderr, \"[%s] *** warning: \" fmt \"\\n\", progname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define DBG(lev, fmt, ...) do { \\\n\tif (verblevel < lev) \\\n\t\tbreak;\\\n\tfprintf(stderr, \"[%s] \" fmt \"\\n\", progname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERR_FATAL\t\t-1\n#define ERR_INVALID_IMAGE\t-2\n\nvoid\nusage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct board_info *board;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...] <file>\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -B <board>      create image for the board specified with <board>.\\n\"\n\"                  valid <board> values:\\n\"\n\t);\n\tfor (board = boards; board->model != NULL; board++){\n\t\tfprintf(stream,\n\"                  %-12s: %s\\n\",\n\t\t board->model, board->name);\n\t};\n\tfprintf(stream,\n\"  -d              don't throw error on invalid images\\n\"\n\"  -k              keep invalid images\\n\"\n\"  -b <file>[:<align>[:<padc>]]\\n\"\n\"                  add boot code to the image\\n\"\n\"  -c <file>[:<align>[:<padc>]]\\n\"\n\"                  add configuration settings to the image\\n\"\n\"  -r <file>:[<addr>][:<align>[:<padc>]]\\n\"\n\"                  add runtime code to the image\\n\"\n\"  -w [<file>:[<addr>][:<align>[:<padc>]]]\\n\"\n\"                  add webpages to the image\\n\"\n\"  -x <file>[:<align>[:<padc>]]\\n\"\n\"                  add extra data at the end of the image\\n\"\n\"  -h              show this screen\\n\"\n\"Parameters:\\n\"\n\"  <file>          write output to the file <file>\\n\"\n\t);\n\n\texit(status);\n}\n\nstatic inline uint32_t align(uint32_t base, uint32_t alignment)\n{\n\tuint32_t ret;\n\n\tif (alignment) {\n\t\tret = (base + alignment - 1);\n\t\tret &= ~(alignment-1);\n\t} else {\n\t\tret = base;\n\t}\n\n\treturn ret;\n}\n\n/*\n * argument parsing\n */\nint\nstr2u32(char *arg, uint32_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err)) {\n\t\treturn -1;\n\t}\n\n\t*val = t;\n\treturn 0;\n}\n\n\nint\nstr2u16(char *arg, uint16_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err) || (t >= 0x10000)) {\n\t\treturn -1;\n\t}\n\n\t*val = t & 0xFFFF;\n\treturn 0;\n}\n\nint\nstr2u8(char *arg, uint8_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err) || (t >= 0x100)) {\n\t\treturn -1;\n\t}\n\n\t*val = t & 0xFF;\n\treturn 0;\n}\n\nint\nstr2sig(char *arg, uint32_t *sig)\n{\n\tif (strlen(arg) != 4)\n\t\treturn -1;\n\n\t*sig = arg[0] | (arg[1] << 8) | (arg[2] << 16) | (arg[3] << 24);\n\n\treturn 0;\n}\n\n\nint\nparse_arg(char *arg, char *buf, char *argv[])\n{\n\tint res = 0;\n\tsize_t argl;\n\tchar *tok;\n\tchar **ap = &buf;\n\tint i;\n\n\tmemset(argv, 0, MAX_ARG_COUNT * sizeof(void *));\n\n\tif ((arg == NULL)) {\n\t\t/* no arguments */\n\t\treturn 0;\n\t}\n\n\targl = strlen(arg);\n\tif (argl == 0) {\n\t\t/* no arguments */\n\t\treturn 0;\n\t}\n\n\tif (argl >= MAX_ARG_LEN) {\n\t\t/* argument is too long */\n\t\targl = MAX_ARG_LEN-1;\n\t}\n\n\tmemcpy(buf, arg, argl);\n\tbuf[argl] = '\\0';\n\n\tfor (i = 0; i < MAX_ARG_COUNT; i++) {\n\t\ttok = strsep(ap, \":\");\n\t\tif (tok == NULL) {\n\t\t\tbreak;\n\t\t}\n#if 0\n\t\telse if (tok[0] == '\\0') {\n\t\t\tbreak;\n\t\t}\n#endif\n\t\targv[i] = tok;\n\t\tres++;\n\t}\n\n\treturn res;\n}\n\n\nint\nrequired_arg(char c, char *arg)\n{\n\tif (arg == NULL || *arg != '-')\n\t\treturn 0;\n\n\tERR(\"option -%c requires an argument\\n\", c);\n\treturn ERR_FATAL;\n}\n\n\nint\nis_empty_arg(char *arg)\n{\n\tint ret = 1;\n\tif (arg != NULL) {\n\t\tif (*arg) ret = 0;\n\t};\n\treturn ret;\n}\n\n\nvoid\ncsum8_update(uint8_t *p, uint32_t len, struct csum_state *css)\n{\n\tfor ( ; len > 0; len --) {\n\t\tcss->val += *p++;\n\t}\n}\n\n\nuint16_t\ncsum8_get(struct csum_state *css)\n{\n\tuint8_t t;\n\n\tt = css->val;\n\treturn ~t + 1;\n}\n\n\nvoid\ncsum16_update(uint8_t *p, uint32_t len, struct csum_state *css)\n{\n\tuint16_t t;\n\n\tif (css->odd) {\n\t\tt = css->tmp + (p[0]<<8);\n\t\tcss->val += LE16_TO_HOST(t);\n\t\tcss->odd = 0;\n\t\tlen--;\n\t\tp++;\n\t}\n\n\tfor ( ; len > 1; len -= 2, p +=2 ) {\n\t\tt = p[0] + (p[1] << 8);\n\t\tcss->val += LE16_TO_HOST(t);\n\t}\n\n\tif (len == 1) {\n\t\tcss->tmp = p[0];\n\t\tcss->odd = 1;\n\t}\n}\n\n\nuint16_t\ncsum16_get(struct csum_state *css)\n{\n\tchar pad = 0;\n\n\tcsum16_update(&pad, 1, css);\n\treturn ~css->val + 1;\n}\n\n\nvoid\ncsum_init(struct csum_state *css, int size)\n{\n\tcss->val = 0;\n\tcss->tmp = 0;\n\tcss->odd = 0;\n\tcss->size = size;\n}\n\n\nvoid\ncsum_update(uint8_t *p, uint32_t len, struct csum_state *css)\n{\n\tswitch (css->size) {\n\tcase CSUM_SIZE_8:\n\t\tcsum8_update(p,len,css);\n\t\tbreak;\n\tcase CSUM_SIZE_16:\n\t\tcsum16_update(p,len,css);\n\t\tbreak;\n\t}\n}\n\n\nuint16_t\ncsum_get(struct csum_state *css)\n{\n\tuint16_t ret;\n\n\tswitch (css->size) {\n\tcase CSUM_SIZE_8:\n\t\tret = csum8_get(css);\n\t\tbreak;\n\tcase CSUM_SIZE_16:\n\t\tret = csum16_get(css);\n\t\tbreak;\n\t}\n\n\treturn ret;\n}\n\n\n/*\n * routines to write data to the output file\n */\nint\nwrite_out_data(FILE *outfile, uint8_t *data, size_t len,\n\t\tstruct csum_state *css)\n{\n\terrno = 0;\n\n\tfwrite(data, len, 1, outfile);\n\tif (errno) {\n\t\tERRS(\"unable to write output file\");\n\t\treturn ERR_FATAL;\n\t}\n\n\tif (css) {\n\t\tcsum_update(data, len, css);\n\t}\n\n\treturn 0;\n}\n\n\nint\nwrite_out_padding(FILE *outfile, size_t len, uint8_t padc,\n\t\t struct csum_state *css)\n{\n\tuint8_t buf[512];\n\tsize_t buflen = sizeof(buf);\n\tint err;\n\n\tmemset(buf, padc, buflen);\n\twhile (len > 0) {\n\t\tif (len < buflen)\n\t\t\tbuflen = len;\n\n\t\terr = write_out_data(outfile, buf, buflen, css);\n\t\tif (err)\n\t\t\treturn err;\n\n\t\tlen -= buflen;\n\t}\n\n\treturn 0;\n}\n\n\nint\nblock_stat_file(struct csys_block *block)\n{\n\tstruct stat st;\n\tint err;\n\n\tif (block->file_name == NULL)\n\t\treturn 0;\n\n\terr = stat(block->file_name, &st);\n\tif (err){\n\t\tERRS(\"stat failed on %s\", block->file_name);\n\t\treturn ERR_FATAL;\n\t}\n\n\tblock->file_size = st.st_size;\n\treturn 0;\n}\n\n\nint\nblock_writeout_hdr(FILE *outfile, struct csys_block *block)\n{\n\tstruct csys_header hdr;\n\tint res;\n\n\tif (block->size_hdr == 0)\n\t\treturn 0;\n\n\t/* setup header fields */\n\tmemcpy(hdr.sig, block->sig, 4);\n\thdr.addr = HOST_TO_LE32(block->addr);\n\thdr.size = HOST_TO_LE32(block->size - block->size_hdr - block->size_csum);\n\n\tDBG(1,\"writing header for block\");\n\tres = write_out_data(outfile, (uint8_t *)&hdr, sizeof(hdr),NULL);\n\treturn res;\n\n}\n\n\nint\nblock_writeout_file(FILE *outfile, struct csys_block *block)\n{\n\tchar buf[FILE_BUF_LEN];\n\tsize_t buflen = sizeof(buf);\n\tFILE *f;\n\tsize_t len;\n\tint res;\n\n\tif (block->file_name == NULL)\n\t\treturn 0;\n\n\tif (block->file_size == 0)\n\t\treturn 0;\n\n\terrno = 0;\n\tf = fopen(block->file_name,\"r\");\n\tif (errno) {\n\t\tERRS(\"unable to open file: %s\", block->file_name);\n\t\treturn ERR_FATAL;\n\t}\n\n\tlen = block->file_size;\n\twhile (len > 0) {\n\t\tif (len < buflen)\n\t\t\tbuflen = len;\n\n\t\t/* read data from source file */\n\t\terrno = 0;\n\t\tfread(buf, buflen, 1, f);\n\t\tif (errno != 0) {\n\t\t\tERRS(\"unable to read from file: %s\", block->file_name);\n\t\t\tres = ERR_FATAL;\n\t\t\tbreak;\n\t\t}\n\n\t\tres = write_out_data(outfile, buf, buflen, block->css);\n\t\tif (res)\n\t\t\tbreak;\n\n\t\tlen -= buflen;\n\t}\n\n\tfclose(f);\n\treturn res;\n}\n\n\nint\nblock_writeout_data(FILE *outfile, struct csys_block *block)\n{\n\tint res;\n\tsize_t padlen;\n\n\tres = block_writeout_file(outfile, block);\n\tif (res)\n\t\treturn res;\n\n\t/* write padding data if neccesary */\n\tpadlen = block->size_avail - block->file_size;\n\tDBG(1,\"padding block, length=%d\", padlen);\n\tres = write_out_padding(outfile, padlen, block->padc, block->css);\n\n\treturn res;\n}\n\n\nint\nblock_writeout_csum(FILE *outfile, struct csys_block *block)\n{\n\tuint16_t csum;\n\tint res;\n\n\tif (block->size_csum == 0)\n\t\treturn 0;\n\n\tDBG(1,\"writing checksum for block\");\n\tcsum = HOST_TO_LE16(csum_get(block->css));\n\tres = write_out_data(outfile, (uint8_t *)&csum, block->size_csum, NULL);\n\n\treturn res;\n}\n\n\nint\nblock_writeout(FILE *outfile, struct csys_block *block)\n{\n\tint res;\n\tstruct csum_state css;\n\n\tres = 0;\n\n\tif (block == NULL)\n\t\treturn res;\n\n\tblock->css = NULL;\n\n\tDBG(2, \"writing block, file=%s, file_size=%d, space=%d\",\n\t\tblock->file_name, block->file_size, block->size_avail);\n\tres = block_writeout_hdr(outfile, block);\n\tif (res)\n\t\treturn res;\n\n\tif (block->size_csum != 0) {\n\t\tblock->css = &css;\n\t\tcsum_init(&css, block->size_csum);\n\t}\n\n\tres = block_writeout_data(outfile, block);\n\tif (res)\n\t\treturn res;\n\n\tres = block_writeout_csum(outfile, block);\n\tif (res)\n\t\treturn res;\n\n\treturn res;\n}\n\n\nint\nwrite_out_blocks(FILE *outfile)\n{\n\tstruct csys_block *block;\n\tint i, res;\n\n\tres = block_writeout(outfile, boot_block);\n\tif (res)\n\t\treturn res;\n\n\tres = block_writeout(outfile, conf_block);\n\tif (res)\n\t\treturn res;\n\n\tres = block_writeout(outfile, webp_block);\n\tif (res)\n\t\treturn res;\n\n\tres = block_writeout(outfile, code_block);\n\tif (res)\n\t\treturn res;\n\n\tres = 0;\n\tfor (i=0; i < num_blocks; i++) {\n\t\tblock = &blocks[i];\n\n\t\tif (block->type != BLOCK_TYPE_XTRA)\n\t\t\tcontinue;\n\n\t\tres = block_writeout(outfile, block);\n\t\tif (res)\n\t\t\tbreak;\n\t}\n\n\treturn res;\n}\n\n\nstruct board_info *\nfind_board(char *model)\n{\n\tstruct board_info *ret;\n\tstruct board_info *board;\n\n\tret = NULL;\n\tfor (board = boards; board->model != NULL; board++){\n\t\tif (strcasecmp(model, board->model) == 0) {\n\t\t\tret = board;\n\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn ret;\n}\n\n\nint\nparse_opt_board(char ch, char *arg)\n{\n\n\tDBG(1,\"parsing board option: -%c %s\", ch, arg);\n\n\tif (board != NULL) {\n\t\tERR(\"only one board option allowed\");\n\t\treturn ERR_FATAL;\n\t}\n\n\tif (required_arg(ch, arg))\n\t\treturn ERR_FATAL;\n\n\tboard = find_board(arg);\n\tif (board == NULL){\n\t\tERR(\"invalid/unknown board specified: %s\", arg);\n\t\treturn ERR_FATAL;\n\t}\n\n\treturn 0;\n}\n\n\nint\nparse_opt_block(char ch, char *arg)\n{\n\tchar buf[MAX_ARG_LEN];\n\tchar *argv[MAX_ARG_COUNT];\n\tint argc;\n\tchar *p;\n\tstruct csys_block *block;\n\tint i;\n\n\tif ( num_blocks > MAX_NUM_BLOCKS ) {\n\t\tERR(\"too many blocks specified\");\n\t\treturn ERR_FATAL;\n\t}\n\n\tblock = &blocks[num_blocks];\n\n\t/* setup default field values */\n\tblock->need_file = 1;\n\tblock->padc = 0xFF;\n\n\tswitch (ch) {\n\tcase 'b':\n\t\tif (boot_block) {\n\t\t\tWARN(\"only one boot block allowed\");\n\t\t\tbreak;\n\t\t}\n\t\tblock->type = BLOCK_TYPE_BOOT;\n\t\tboot_block = block;\n\t\tbreak;\n\tcase 'c':\n\t\tif (conf_block) {\n\t\t\tWARN(\"only one config block allowed\");\n\t\t\tbreak;\n\t\t}\n\t\tblock->type = BLOCK_TYPE_CONF;\n\t\tconf_block = block;\n\t\tbreak;\n\tcase 'w':\n\t\tif (webp_block) {\n\t\t\tWARN(\"only one web block allowed\");\n\t\t\tbreak;\n\t\t}\n\t\tblock->type = BLOCK_TYPE_WEBP;\n\t\tblock->size_hdr = sizeof(struct csys_header);\n\t\tblock->size_csum = CSUM_SIZE_8;\n\t\tblock->need_file = 0;\n\t\twebp_block = block;\n\t\tbreak;\n\tcase 'r':\n\t\tif (code_block) {\n\t\t\tWARN(\"only one runtime block allowed\");\n\t\t\tbreak;\n\t\t}\n\t\tblock->type = BLOCK_TYPE_CODE;\n\t\tblock->size_hdr = sizeof(struct csys_header);\n\t\tblock->size_csum = CSUM_SIZE_16;\n\t\tcode_block = block;\n\t\tbreak;\n\tcase 'x':\n\t\tblock->type = BLOCK_TYPE_XTRA;\n\t\tbreak;\n\tdefault:\n\t\tERR(\"unknown block type \\\"%c\\\"\", ch);\n\t\treturn ERR_FATAL;\n\t}\n\n\targc = parse_arg(arg, buf, argv);\n\n\ti = 0;\n\tp = argv[i++];\n\tif (!is_empty_arg(p)) {\n\t\tblock->file_name = strdup(p);\n\t\tif (block->file_name == NULL) {\n\t\t\tERR(\"not enough memory\");\n\t\t\treturn ERR_FATAL;\n\t\t}\n\t} else if (block->need_file){\n\t\tERR(\"no file specified in %s\", arg);\n\t\treturn ERR_FATAL;\n\t}\n\n\tif (block->size_hdr) {\n\t\tp = argv[i++];\n\t\tif (!is_empty_arg(p)) {\n\t\t\tif (str2u32(p, &block->addr) != 0) {\n\t\t\t\tERR(\"invalid start address in %s\", arg);\n\t\t\t\treturn ERR_FATAL;\n\t\t\t}\n\t\t\tblock->addr_set = 1;\n\t\t}\n\t}\n\n\tp = argv[i++];\n\tif (!is_empty_arg(p)) {\n\t\tif (str2u32(p, &block->align) != 0) {\n\t\t\tERR(\"invalid alignment value in %s\", arg);\n\t\t\treturn ERR_FATAL;\n\t\t}\n\t\tblock->align_set = 1;\n\t}\n\n\tp = argv[i++];\n\tif (!is_empty_arg(p) && (str2u8(p, &block->padc) != 0)) {\n\t\tERR(\"invalid paddig character in %s\", arg);\n\t\treturn ERR_FATAL;\n\t}\n\n\tnum_blocks++;\n\n\treturn 0;\n}\n\n\nint\nprocess_blocks(void)\n{\n\tstruct csys_block *block;\n\tuint32_t offs = 0;\n\tint i;\n\tint res;\n\n\tres = 0;\n\t/* collecting stats */\n\tfor (i = 0; i < num_blocks; i++) {\n\t\tblock = &blocks[i];\n\t\tres = block_stat_file(block);\n\t\tif (res)\n\t\t\treturn res;\n\t}\n\n\t/* bootloader */\n\tblock = boot_block;\n\tif (block) {\n\t\tblock->size = board->boot_size;\n\t\tif (block->file_size > board->boot_size) {\n\t\t\tWARN(\"boot block is too big\");\n\t\t\tres = ERR_INVALID_IMAGE;\n\t\t}\n\t}\n\toffs += board->boot_size;\n\n\t/* configuration data */\n\tblock = conf_block;\n\tif (block) {\n\t\tblock->size = board->conf_size;\n\t\tif (block->file_size > board->conf_size) {\n\t\t\tWARN(\"config block is too big\");\n\t\t\tres = ERR_INVALID_IMAGE;\n\t\t}\n\t}\n\toffs += board->conf_size;\n\n\t/* webpages */\n\tblock = webp_block;\n\tif (block) {\n\n\t\tmemcpy(block->sig, board->sig_webp, 4);\n\n\t\tif (block->addr_set == 0)\n\t\t\tblock->addr = board->addr_webp;\n\n\t\tif (block->align_set == 0)\n\t\t\tblock->align = DEFAULT_BLOCK_ALIGN;\n\n\t\tblock->size = align(offs + block->file_size + block->size_hdr +\n\t\t\t\tblock->size_csum, block->align) - offs;\n\n\t\tif (block->size > board->webp_size_max) {\n\t\t\tWARN(\"webpages block is too big\");\n\t\t\tres = ERR_INVALID_IMAGE;\n\t\t}\n\n\t\tDBG(2,\"webpages start at %08x, size=%08x\", offs,\n\t\t\t\tblock->size);\n\n\t\toffs += block->size;\n\t\tif (offs > board->flash_size) {\n\t\t\tWARN(\"webp block is too big\");\n\t\t\tres = ERR_INVALID_IMAGE;\n\t\t}\n\t}\n\n\t/* runtime code */\n\tblock = code_block;\n\tif (block) {\n\t\tmemcpy(code_block->sig, SIG_CSYS, 4);\n\n\t\tif (block->addr_set == 0)\n\t\t\tblock->addr = board->addr_code;\n\n\t\tif (block->align_set == 0)\n\t\t\tblock->align = DEFAULT_BLOCK_ALIGN;\n\n\t\tblock->size = align(offs + block->file_size +\n\t\t\t\tblock->size_hdr + block->size_csum,\n\t\t\t\tblock->align) - offs;\n\n\t\tDBG(2,\"code block start at %08x, size=%08x\", offs,\n\t\t\t\tblock->size);\n\n\t\toffs += block->size;\n\t\tif (offs > board->flash_size) {\n\t\t\tWARN(\"code block is too big\");\n\t\t\tres = ERR_INVALID_IMAGE;\n\t\t}\n\t}\n\n\tfor (i = 0; i < num_blocks; i++) {\n\t\tblock = &blocks[i];\n\n\t\tif (block->type != BLOCK_TYPE_XTRA)\n\t\t\tcontinue;\n\n\t\tif (block->align_set == 0)\n\t\t\tblock->align = DEFAULT_BLOCK_ALIGN;\n\n\t\tblock->size = align(offs + block->file_size,\n\t\t\t\tblock->align) - offs;\n\n\t\tDBG(2,\"file %s start at %08x, size=%08x, align=%08x\",\n\t\t\tblock->file_name, offs, block->size, block->align);\n\n\t\toffs += block->size;\n\t\tif (offs > board->flash_size) {\n\t\t\tWARN(\"file %s is too big, size=%d, avail=%d\",\n\t\t\t\tblock->file_name, block->file_size,\n\t\t\t\tboard->flash_size - offs);\n\t\t\tres = ERR_INVALID_IMAGE;\n\t\t}\n\t}\n\n\tfor (i = 0; i < num_blocks; i++) {\n\t\tblock = &blocks[i];\n\n\t\tblock->size_avail = block->size - block->size_hdr -\n\t\t\tblock->size_csum;\n\n\t\tif (block->size_avail < block->file_size) {\n\t\t\tWARN(\"file %s is too big, size=%d, avail=%d\",\n\t\t\t\tblock->file_name, block->file_size,\n\t\t\t\tblock->size_avail);\n\t\t\tres = ERR_INVALID_IMAGE;\n\t\t}\n\t}\n\n\treturn res;\n}\n\n\nint\nmain(int argc, char *argv[])\n{\n\tint optinvalid = 0;   /* flag for invalid option */\n\tint c;\n\tint res = ERR_FATAL;\n\n\tFILE *outfile;\n\n\tprogname=basename(argv[0]);\n\n\topterr = 0;  /* could not print standard getopt error messages */\n\twhile ( 1 ) {\n\t\toptinvalid = 0;\n\n\t\tc = getopt(argc, argv, \"b:B:c:dhkr:vw:x:\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'b':\n\t\tcase 'c':\n\t\tcase 'r':\n\t\tcase 'x':\n\t\t\toptinvalid = parse_opt_block(c,optarg);\n\t\t\tbreak;\n\t\tcase 'w':\n\t\t\tif (optarg != NULL && *optarg == '-') {\n\t\t\t\t/* rollback */\n\t\t\t\toptind--;\n\t\t\t\toptarg = NULL;\n\t\t\t}\n\t\t\toptinvalid = parse_opt_block(c,optarg);\n\t\t\tbreak;\n\t\tcase 'd':\n\t\t\tinvalid_causes_error = 0;\n\t\t\tbreak;\n\t\tcase 'k':\n\t\t\tkeep_invalid_images = 1;\n\t\t\tbreak;\n\t\tcase 'B':\n\t\t\toptinvalid = parse_opt_board(c,optarg);\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tverblevel++;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\toptinvalid = 1;\n\t\t\tbreak;\n\t\t}\n\t\tif (optinvalid != 0 ){\n\t\t\tERR(\"invalid option: -%c\", optopt);\n\t\t\tgoto out;\n\t\t}\n\t}\n\n\tif (board == NULL) {\n\t\tERR(\"no board specified\");\n\t\tgoto out;\n\t}\n\n\tif (optind == argc) {\n\t\tERR(\"no output file specified\");\n\t\tgoto out;\n\t}\n\n\tofname = argv[optind++];\n\n\tif (optind < argc) {\n\t\tERR(\"invalid option: %s\", argv[optind]);\n\t\tgoto out;\n\t}\n\n\tres = process_blocks();\n\tif (res == ERR_FATAL)\n\t\tgoto out;\n\n\tif (res == ERR_INVALID_IMAGE) {\n\t\tif (invalid_causes_error)\n\t\t\tres = ERR_FATAL;\n\n\t\tif (keep_invalid_images == 0) {\n\t\t\tWARN(\"generation of invalid images disabled\", ofname);\n\t\t\tgoto out;\n\t\t}\n\n\t\tWARN(\"generating invalid image\", ofname);\n\t}\n\n\toutfile = fopen(ofname, \"w\");\n\tif (outfile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tres = ERR_FATAL;\n\t\tgoto out;\n\t}\n\n\tif (write_out_blocks(outfile) != 0) {\n\t\tres = ERR_FATAL;\n\t\tgoto out_flush;\n\t}\n\n\tDBG(1,\"Image file %s completed.\", ofname);\n\nout_flush:\n\tfflush(outfile);\n\tfclose(outfile);\n\tif (res == ERR_FATAL) {\n\t\tunlink(ofname);\n\t}\nout:\n\tif (res == ERR_FATAL)\n\t\treturn EXIT_FAILURE;\n\n\treturn EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkdapimg.c",
    "content": "#include <stdio.h>\n#include <stdint.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <libgen.h>\n#include <stdarg.h>\n#include <getopt.h>\n#include <string.h>\n#include <errno.h>\n\n#include <netinet/in.h>\t// htonl\n\n// Usage: mkdapimg [-p] [-m <model>] -s <sig> -i <input> -o <output>\n//\n// e.g.: mkdapimg -s RT3052-AP-DAP1350-3 -i sysupgarde.bin -o factory.bin\n//\n// If the model string <model> is not given, we will assume that\n// the leading characters upto the first \"-\" is the model.\n//\n// The \"-p\" (patch) option is used to patch the exisiting image with the\n// specified model and signature.\n// The \"-x\" (fix) option will recalculate the payload size and checksum\n// during the patch mode operation.\n\n// The img_hdr_struct was taken from the D-Link SDK:\n// DAP-1350_A1_FW1.11NA_GPL/GPL_Source_Code/Uboot/DAP-1350/httpd/header.h\n\n#define MAX_MODEL_NAME_LEN\t20\n#define MAX_SIG_LEN\t\t30\n\nstruct img_hdr_struct {\n\tuint32_t checksum;\n\tchar model[MAX_MODEL_NAME_LEN];\n\tchar sig[MAX_SIG_LEN];\n\tuint8_t\tpartition;       \n\tuint8_t hdr_len;\n\tuint8_t rsv1;\n\tuint8_t rsv2;    \n\tuint32_t flash_byte_cnt;  \n} imghdr ;\n\nchar *progname;\n\nvoid\nperrexit(int code, char *msg)\n{\n\tfprintf(stderr, \"%s: %s: %s\\n\", progname, msg, strerror(errno));\n\texit(code);\n}\n\nvoid\nusage()\n{\n\tfprintf(stderr, \"usage: %s [-p] [-m model] -s signature -i input -o output\\n\", progname);\n\texit(1);\n}\n\nint\nmain(int ac, char *av[])\n{\n\tchar model[MAX_MODEL_NAME_LEN+1];\n\tchar signature[MAX_SIG_LEN+1];\n\tint patchmode = 0;\n\tint fixmode = 0;\n\n\tFILE *ifile, *ofile;\n\tint c;\n\tuint32_t cksum;\n\tuint32_t bcnt;\n\n\tprogname = basename(av[0]);\n\tmemset(model, 0, sizeof(model));\n\tmemset(signature, 0, sizeof(signature));\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(ac, av, \"pxm:s:i:o:\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'p':\n\t\t\tpatchmode = 1;\n\t\t\tbreak;\n\t\tcase 'x':\n\t\t\tfixmode = 1;\n\t\t\tbreak;\n\t\tcase 'm':\n\t\t\tif (strlen(optarg) > MAX_MODEL_NAME_LEN) {\n\t\t\t\tfprintf(stderr, \"%s: model name exceeds %d chars\\n\",\n\t\t\t\t\tprogname, MAX_MODEL_NAME_LEN);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tstrcpy(model, optarg);\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\tif (strlen(optarg) > MAX_SIG_LEN) {\n\t\t\t\tfprintf(stderr, \"%s: signature exceeds %d chars\\n\",\n\t\t\t\t\tprogname, MAX_SIG_LEN);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tstrcpy(signature, optarg);\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tif ((ifile = fopen(optarg, \"r\")) == NULL)\n\t\t\t\tperrexit(1, optarg);\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tif ((ofile = fopen(optarg, \"w\")) == NULL)\n\t\t\t\tperrexit(1, optarg);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage();\n\t\t}\n\t}\n\n\tif (signature[0] == 0 || ifile == NULL || ofile == NULL) {\n\t\tusage();\n\t}\n\n\tif (model[0] == 0) {\n\t\tchar *p = strchr(signature, '-');\n\t\tif (p == NULL) {\n\t\t\tfprintf(stderr, \"%s: model name unknown\\n\", progname);\n\t\t\texit(1);\n\t\t}\n\t\tif (p - signature > MAX_MODEL_NAME_LEN) {\n\t\t\t*p = 0;\n\t\t\tfprintf(stderr, \"%s: auto model name failed, string %s too long\\n\", progname, signature);\n\t\t\texit(1);\n\t\t}\n\t\tstrncpy(model, signature, p - signature);\n\t}\n\n\tif (patchmode) {\n\t\tif (fread(&imghdr, sizeof(imghdr), 1, ifile) < 0)\n\t\t\tperrexit(2, \"fread on input\");\n\t}\n\n\tfor (bcnt = 0, cksum = 0 ; (c = fgetc(ifile)) != EOF ; bcnt++)\n\t\tcksum += c & 0xff;\n\n\tif (fseek(ifile, patchmode ? sizeof(imghdr) : 0, SEEK_SET) < 0)\n\t\tperrexit(2, \"fseek on input\");\n\n\tif (patchmode == 0) {\n\t\t// Fill in the header\n\t\tmemset(&imghdr, 0, sizeof(imghdr));\n\t\timghdr.checksum = htonl(cksum);\n\t\timghdr.partition = 0 ; // don't care?\n\t\timghdr.hdr_len = sizeof(imghdr);\n\t\timghdr.flash_byte_cnt = htonl(bcnt);\n\t} else {\n\t\tif (ntohl(imghdr.checksum) != cksum) {\n\t\t\tfprintf(stderr, \"%s: patch mode, checksum mismatch\\n\",\n\t\t\t\tprogname);\n\t\t\tif (fixmode) {\n\t\t\t\tfprintf(stderr, \"%s: fixing\\n\", progname);\n\t\t\t\timghdr.checksum = htonl(cksum);\n\t\t\t} else\n\t\t\t\texit(3);\n\t\t} else if (ntohl(imghdr.flash_byte_cnt) != bcnt) {\n\t\t\tfprintf(stderr, \"%s: patch mode, size mismatch\\n\",\n\t\t\t\tprogname);\n\t\t\tif (fixmode) {\n\t\t\t\tfprintf(stderr, \"%s: fixing\\n\", progname);\n\t\t\t\timghdr.flash_byte_cnt = htonl(bcnt);\n\t\t\t} else\n\t\t\t\texit(3);\n\t\t}\n\t}\n\n\tstrncpy(imghdr.model, model, MAX_MODEL_NAME_LEN);\n\tstrncpy(imghdr.sig, signature, MAX_SIG_LEN);\n\n\tif (fwrite(&imghdr, sizeof(imghdr), 1, ofile) < 0)\n\t\tperrexit(2, \"fwrite header on output\");\n\n\twhile ((c = fgetc(ifile)) != EOF) {\n\t\tif (fputc(c, ofile) == EOF)\n\t\t\tperrexit(2, \"fputc on output\");\n\t}\n\n\tif (ferror(ifile))\n\t\tperrexit(2, \"fgetc on input\");\n\n\n\tfclose(ofile);\n\tfclose(ifile);\n}\n"
  },
  {
    "path": "src/firmware-tools/mkdir615h1.c",
    "content": "/*\n *\n *  Copyright (C) 2012 OpenWrt.org\n *  Copyright (C) 2012 Mikko Hissa <mikko.hissa@uta.fi>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdarg.h>\n#include <libgen.h>\n#include <errno.h>\n#include <arpa/inet.h>\n#include <unistd.h>\n#include \"md5.h\"\n\n#define HDR_LEN \t\t0x60\n#define BUF_SIZE \t\t0x200\n#define VERSION_SIZE\t\t0x10\n#define MD5_SIZE\t\t0x10\n#define PAD_SIZE\t\t0x20\n#define DEFAULT_MAGIC \t\t305419896\n#define DEFAULT_VERSION\t\t\"123\"\n#define DEFAULT_VENDOR_ID\t536\n#define DEFAULT_HEAD_VALUE\t0x0\n#define DEFAULT_BLOCK_SIZE \t65535\n#define DEFAULT_PRODUCT_ID\t48\n#define DEFAULT_FIRMWARE_TYPE\t0x03\n\ntypedef struct {\n\tuint32_t head;\n\tuint32_t vendor_id;\n\tuint32_t product_id;\n\tuint8_t version[VERSION_SIZE];\n\tuint32_t firmware_type;\n\tuint32_t filesize;\n\tuint32_t zero;\n\tuint8_t md5sum[MD5_SIZE];\n\tuint8_t pad[PAD_SIZE];\n\tuint32_t chksum;\n\tuint32_t magic;\n} img_header;\n\ntypedef struct {\n\tuint8_t id;\n\tchar * name;\n} firmware_type;\n\ntypedef enum {\n\tNONE, ENCODE, DECODE\n} op_mode;\n\nstatic firmware_type FIRMWARE_TYPES[] = {\n\t\t{ 0x01, \"bootloader\" },\n\t\t{ 0x02,\t\"kernel\" },\n\t\t{ 0x03, \"kernelapp\" },\n\t\t{ 0x04, \"apps\" },\n\t\t{ 0x05,\t\"littleapps\" },\n\t\t{ 0x06, \"sounds\" },\n\t\t{ 0x07, \"userconfig\" },\n\t\t{ 0x0a,\t\"factoryapps\" },\n\t\t{ 0x0b, \"odmapps\" },\n\t\t{ 0x0c, \"langpack\" }\n};\n\nstatic long get_file_size(const char *filename)\n{\n\tFILE *fp_file;\n\tlong result;\n\n\tfp_file = fopen(filename, \"r\");\n\tif (!fp_file)\n\t\treturn -1;\n\tfseek(fp_file, 0, SEEK_END);\n\tresult = ftell(fp_file);\n\tfclose(fp_file);\n\treturn result;\n}\n\nstatic int header_checksum(void *data, int len)\n{\n\tint i;\n\tint sum;\n\n\tsum = 0;\n\tif (data != NULL && len >= 0) {\n\t\tfor (i = 0; i < len; ++i)\n\t\t\tsum += *(unsigned char *) (data + i);\n\t\treturn sum;\n\t}\n\n\treturn -1;\n}\n\nstatic int md5_file(const char *filename, uint8_t *dst)\n{\n\tFILE *fp_src;\n\tMD5_CTX ctx;\n\tchar buf[BUF_SIZE];\n\tsize_t bytes_read;\n\n\tMD5_Init(&ctx);\n\n\tfp_src = fopen(filename, \"r+b\");\n\tif (!fp_src) {\n\t\treturn -1;\n\t}\n\twhile (!feof(fp_src)) {\n\t\tbytes_read = fread(&buf, 1, BUF_SIZE, fp_src);\n\t\tMD5_Update(&ctx, &buf, bytes_read);\n\t}\n\tfclose(fp_src);\n\n\tMD5_Final(dst, &ctx);\n\n\treturn 0;\n}\n\nstatic int encode_image(const char *input_file_name,\n\t\tconst char *output_file_name, img_header *header, int block_size)\n{\n\tchar buf[BUF_SIZE];\n\tsize_t bytes_read;\n\tsize_t pad_len = 0;\n\tsize_t bytes_avail;\n\n\tFILE *fp_input;\n\tFILE *fp_output;\n\n\tint i;\n\tlong magic;\n\n\tfp_input = fopen(input_file_name, \"r+b\");\n\tif (!fp_input) {\n\t\tfprintf(stderr, \"Cannot open %s !!\\n\", input_file_name);\n\t\treturn -1;\n\t}\n\n\tfp_output = fopen(output_file_name, \"w+b\");\n\tif (!fp_output) {\n\t\tfprintf(stderr, \"Cannot open %s !!\\n\", output_file_name);\n\t\tfclose(fp_input);\n\t\treturn -1;\n\t}\n\n\theader->filesize = get_file_size(input_file_name);\n\tif (!header->filesize) {\n\t\tfprintf(stderr, \"File %s open/size error!\\n\", input_file_name);\n\t\tfclose(fp_input);\n\t\tfclose(fp_output);\n\t\treturn -1;\n\t}\n\t/*\n\t * Zero padding\n\t */\n\tif (block_size > 0) {\n\t\tpad_len = block_size - (header->filesize % block_size);\n\t}\n\n\tif (md5_file(input_file_name, (uint8_t *) &header->md5sum) < 0) {\n\t\tfprintf(stderr, \"Md5 failed on file %s\\n\", input_file_name);\n\t\tfclose(fp_input);\n\t\tfclose(fp_output);\n\t\treturn -1;\n\t}\n\theader->zero = 0;\n\theader->chksum = header_checksum(header, HDR_LEN);\n\theader->head = htonl(header->head);\n\theader->vendor_id = htonl(header->vendor_id);\n\theader->product_id = htonl(header->product_id);\n\theader->firmware_type = htonl(header->firmware_type);\n\theader->filesize = htonl(header->filesize);\n\theader->chksum = htonl(header->chksum);\n\tmagic = header->magic;\n\theader->magic = htonl(header->magic);\n\n\tfwrite(header, HDR_LEN, 1, fp_output);\n\n\twhile (!feof(fp_input) || pad_len > 0) {\n\n\t\tif (!feof(fp_input))\n\t\t\tbytes_read = fread(&buf, 1, BUF_SIZE, fp_input);\n\t\telse\n\t\t\tbytes_read = 0;\n\n\t\t/*\n\t\t * No more bytes read, start padding\n\t\t */\n\t\tif (bytes_read < BUF_SIZE && pad_len > 0) {\n\t\t\tbytes_avail = BUF_SIZE - bytes_read;\n\t\t\tmemset( &buf[bytes_read], 0, bytes_avail);\n\t\t\tbytes_read += bytes_avail < pad_len ? bytes_avail : pad_len;\n\t\t\tpad_len -= bytes_avail < pad_len ? bytes_avail : pad_len;\n\t\t}\n\n\t\tfor (i = 0; i < bytes_read; i++)\n\t\t\tbuf[i] ^= magic >> ((((i >> 60) + i) & 7) - (i >> 60));\n\t\tfwrite(&buf, bytes_read, 1, fp_output);\n\t}\n\n\tfclose(fp_input);\n\tfclose(fp_output);\n\treturn 1;\n}\n\nint decode_image(const char *input_file_name, const char *output_file_name)\n{\n\timg_header header;\n\tchar buf[512];\n\n\tFILE *fp_input;\n\tFILE *fp_output;\n\tunsigned int i;\n\n\tsize_t bytes_read;\n\tsize_t bytes_written;\n\n\tfp_input = fopen(input_file_name, \"r+b\");\n\tif (!fp_input) {\n\t\tfprintf(stderr, \"Cannot open %s !!\\n\", input_file_name);\n\t\tfclose(fp_input);\n\t\treturn -1;\n\t}\n\n\tfp_output = fopen(output_file_name, \"w+b\");\n\tif (!fp_output) {\n\t\tfprintf(stderr, \"Cannot open %s !!\\n\", output_file_name);\n\t\tfclose(fp_output);\n\t\treturn -1;\n\t}\n\n\tif (fread(&header, 1, HDR_LEN, fp_input) != HDR_LEN) {\n\t\tfprintf(stderr, \"Incorrect header size!!\");\n\t\tfclose(fp_input);\n\t\tfclose(fp_output);\n\t\treturn -1;\n\t}\n\n\theader.head = ntohl(header.head);\n\theader.vendor_id = ntohl(header.vendor_id);\n\theader.product_id = ntohl(header.product_id);\n\theader.firmware_type = ntohl(header.firmware_type);\n\theader.filesize = ntohl(header.filesize);\n\theader.chksum = ntohl(header.chksum);\n\theader.magic = ntohl(header.magic);\n\n\tbytes_written = 0;\n\twhile (!feof(fp_input)) {\n\n\t\tbytes_read = fread(&buf, 1, BUF_SIZE, fp_input);\n\t\tfor (i = 0; i < bytes_read; i++)\n\t\t\tbuf[i] ^= header.magic >> ((((i >> 60) + i) & 7) - (i >> 60));\n\n\t\t/*\n\t\t * Handle padded source file\n\t\t */\n\t\tif (bytes_written + bytes_read > header.filesize) {\n\t\t\tbytes_read = header.filesize - bytes_written;\n\t\t\tif (bytes_read > 0)\n\t\t\t\tfwrite(&buf, bytes_read, 1, fp_output);\n\t\t\tbreak;\n\t\t}\n\n\t\tfwrite(&buf, bytes_read, 1, fp_output);\n\t\tbytes_written += bytes_read;\n\t}\n\n\tfclose(fp_input);\n\tfclose(fp_output);\n\n\treturn 1;\n}\n\nstatic void usage(const char *progname, int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tint i;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream, \"\\n\"\n\t\t\t\"Options:\\n\"\n\t\t\t\"  -e <file>\t\tencode image file <file>\\n\"\n\t\t\t\"  -d <file>\t\tdecode image file <file>\\n\"\n\t\t\t\"  -o <file>\t\twrite output to the file <file>\\n\"\n\t\t\t\"  -t <type>\t\tset image type to <type>, defaults to 3\\n\"\n\t\t\t\"\t\t\tvalid image <type> values:\\n\");\n\tfor (i = 0; i < sizeof(FIRMWARE_TYPES) / sizeof(firmware_type); i++) {\n\t\tfprintf(stream, \"\t\t\t%-5i= %s\\n\", FIRMWARE_TYPES[i].id,\n\t\t\t\tFIRMWARE_TYPES[i].name);\n\t}\n\tfprintf(stream, \"  -v <version>\t\tset image version to <version>\\n\"\n\t\t\t\"  -r <vendor>\t\tset image vendor id to <vendor>\\n\"\n\t\t\t\"  -p <product>\t\tset image product id to <product>\\n\"\n\t\t\t\"  -m <magic>\t\tset encoding magic <magic>\\n\"\n\t\t\t\"  -z\t\t\tenable image padding to <blocksize>\\n\"\n\t\t\t\"  -b <blocksize>\tset image <blocksize>, defaults to 65535\\n\"\n\t\t\t\"  -h\t\t\tshow this screen\\n\");\n\texit(status);\n}\n\nint main(int argc, char *argv[])\n{\n\tint opt;\n\tchar *input_file, *output_file, *progname = NULL;\n\top_mode mode = NONE;\n\tint tmp, i, pad = 0;\n\tint block_size;\n\timg_header header;\n\n\tblock_size = DEFAULT_BLOCK_SIZE;\n\tprogname = basename(argv[0]);\n\n\tmemset(&header, 0, sizeof( img_header ));\n\theader.magic = DEFAULT_MAGIC;\n\theader.head = DEFAULT_HEAD_VALUE;\n\theader.vendor_id = DEFAULT_VENDOR_ID;\n\theader.product_id = DEFAULT_PRODUCT_ID;\n\theader.firmware_type = DEFAULT_FIRMWARE_TYPE;\n\tstrncpy( (char*)&header.version, DEFAULT_VERSION, VERSION_SIZE - 1);\n\n\twhile ((opt = getopt(argc, argv, \":o:e:d:t:v:r:p:m:b:h?z\")) != -1) {\n\t\tswitch (opt) {\n\t\tcase 'e':\n\t\t\tinput_file = optarg;\n\t\t\tmode = ENCODE;\n\t\t\tbreak;\n\t\tcase 'd':\n\t\t\tinput_file = optarg;\n\t\t\tmode = DECODE;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\toutput_file = optarg;\n\t\t\tbreak;\n\t\tcase 't':\n\t\t\ttmp = strtol(optarg, 0, 10);\n\t\t\tfor (i = 0; i < sizeof(FIRMWARE_TYPES) / sizeof(firmware_type);\n\t\t\t\t\ti++) {\n\t\t\t\tif (FIRMWARE_TYPES[i].id == tmp) {\n\t\t\t\t\theader.firmware_type = FIRMWARE_TYPES[i].id;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (header.firmware_type == 0) {\n\t\t\t\tfprintf(stderr, \"Invalid firmware <type>!\\n\");\n\t\t\t\tusage(progname, EXIT_FAILURE);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tstrncpy( (char*)&header.version, optarg,\n\t\t\t\t\tVERSION_SIZE - 1);\n\t\t\tbreak;\n\t\tcase 'r':\n\t\t\theader.vendor_id = strtol(optarg, 0, 10);\n\t\t\tbreak;\n\t\tcase 'p':\n\t\t\theader.product_id = strtol(optarg, 0, 10);\n\t\t\tbreak;\n\t\tcase 'm':\n\t\t\theader.magic = strtoul(optarg, 0, 16);\n\t\t\tbreak;\n\t\tcase 'z':\n\t\t\tpad = 1;\n\t\t\tbreak;\n\t\tcase 'b':\n\t\t\tblock_size = strtol(optarg, 0, 10);\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(progname, EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tcase ':':\n\t\t\tfprintf(stderr, \"Option -%c requires an operand\\n\", optopt);\n\t\t\tusage(progname, EXIT_FAILURE);\n\t\t\tbreak;\n\t\tcase '?':\n\t\t\tfprintf(stderr, \"Unrecognized option: -%c\\n\", optopt);\n\t\t\tusage(progname, EXIT_FAILURE);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(progname, EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (input_file == NULL || output_file == NULL ) {\n\t\tfprintf(stderr, \"Input and output files must be defined\\n\");\n\t\tusage(progname, EXIT_FAILURE);\n\t}\n\n\tswitch (mode) {\n\tcase NONE:\n\t\tusage(progname, EXIT_FAILURE);\n\t\tbreak;\n\tcase ENCODE:\n\t\tif (encode_image(input_file, output_file, &header, pad ? block_size : 0)\n\t\t\t\t< 0)\n\t\t\treturn EXIT_FAILURE;\n\t\tbreak;\n\tcase DECODE:\n\t\tif (decode_image(input_file, output_file) < 0)\n\t\t\treturn EXIT_FAILURE;\n\t\tbreak;\n\t}\n\n\treturn EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkdniimg.c",
    "content": "/*\n *  Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\n#define DNI_HDR_LEN\t128\n\n/*\n * Globals\n */\nstatic char *ifname;\nstatic char *progname;\nstatic char *ofname;\nstatic char *version = \"1.00.00\";\nstatic char *region = \"\";\nstatic char *hd_id;\n\nstatic char *board_id;\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\nvoid usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct board_info *board;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -B <board>      create image for the board specified with <board>\\n\"\n\"  -i <file>       read input from the file <file>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -v <version>    set image version to <version>\\n\"\n\"  -r <region>     set image region to <region>\\n\"\n\"  -H <hd_id>      set image hardware id to <hd_id>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nint main(int argc, char *argv[])\n{\n\tint res = EXIT_FAILURE;\n\tint buflen;\n\tint err;\n\tstruct stat st;\n\tchar *buf;\n\tint pos, rem, i;\n\tuint8_t csum;\n\n\tFILE *outfile, *infile;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"B:i:o:v:r:H:h\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'B':\n\t\t\tboard_id = optarg;\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tifname = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tversion = optarg;\n\t\t\tbreak;\n\t\tcase 'r':\n\t\t\tregion = optarg;\n\t\t\tbreak;\n\t\tcase 'H':\n\t\t\thd_id = optarg;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (board_id == NULL) {\n\t\tERR(\"no board specified\");\n\t\tgoto err;\n\t}\n\n\tif (ifname == NULL) {\n\t\tERR(\"no input file specified\");\n\t\tgoto err;\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\tgoto err;\n\t}\n\n\terr = stat(ifname, &st);\n\tif (err){\n\t\tERRS(\"stat failed on %s\", ifname);\n\t\tgoto err;\n\t}\n\n\tbuflen = st.st_size + DNI_HDR_LEN + 1;\n\tbuf = malloc(buflen);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto err;\n\t}\n\n\tmemset(buf, 0, DNI_HDR_LEN);\n\tpos = snprintf(buf, DNI_HDR_LEN, \"device:%s\\nversion:V%s\\nregion:%s\\n\",\n\t\t       board_id, version, region);\n\trem = DNI_HDR_LEN - pos;\n\tif (pos >= 0 && rem > 1 && hd_id) {\n\t\tsnprintf(buf + pos, rem, \"hd_id:%s\\n\", hd_id);\n\t}\n\n\tinfile = fopen(ifname, \"r\");\n\tif (infile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for reading\", ifname);\n\t\tgoto err_free;\n\t}\n\n\terrno = 0;\n\tfread(buf +  DNI_HDR_LEN, st.st_size, 1, infile);\n\tif (errno != 0) {\n\t\tERRS(\"unable to read from file %s\", ifname);\n\t\tgoto err_close_in;\n\t}\n\n\tcsum = 0;\n\tfor (i = 0; i < (st.st_size + DNI_HDR_LEN); i++)\n\t\tcsum += buf[i];\n\n\tcsum = 0xff - csum;\n\tbuf[st.st_size + DNI_HDR_LEN] = csum;\n\n\toutfile = fopen(ofname, \"w\");\n\tif (outfile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto err_close_in;\n\t}\n\n\terrno = 0;\n\tfwrite(buf, buflen, 1, outfile);\n\tif (errno) {\n\t\tERRS(\"unable to write to file %s\", ofname);\n\t\tgoto err_close_out;\n\t}\n\n\tres = EXIT_SUCCESS;\n\n out_flush:\n\tfflush(outfile);\n\n err_close_out:\n\tfclose(outfile);\n\tif (res != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\n\n err_close_in:\n\tfclose(infile);\n\n err_free:\n\tfree(buf);\n\n err:\n\treturn res;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkedimaximg.c",
    "content": "/*\n * Copyright (C) 2011 Vasilis Tsiligiannis <b_tsiligiannis@silverton.gr>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License as\n * published by the Free Software Foundation; either version 2 of the\n * License, or (at your option) any later version.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <libgen.h>\n#include <getopt.h>\n#include <errno.h>\n#include <sys/stat.h>\n#include <endian.h>\t/* for __BYTE_ORDER */\n\n#if (__BYTE_ORDER == __LITTLE_ENDIAN)\n#  define HOST_TO_LE16(x)\t(x)\n#  define HOST_TO_LE32(x)\t(x)\n#else\n#  define HOST_TO_LE16(x)\tbswap_16(x)\n#  define HOST_TO_LE32(x)\tbswap_32(x)\n#endif\n\nstruct header\n{\n    unsigned char sign[4];\n    unsigned int start;\n    unsigned int flash;\n    unsigned char model[4];\n    unsigned int size;\n} __attribute__ ((packed));\n\nstruct finfo\n{\n    char *name;\n    off_t size;\n};\n\nstruct buf\n{\n    char *start;\n    size_t size;\n};\n\nstatic char *progname;\n\nstatic void usage(int status)\n{\n    FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\n    fprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n    fprintf(stream,\n\t    \"\\n\"\n\t    \"Options:\\n\"\n\t    \"  -s <sig>        set image signature to <sig>\\n\"\n\t    \"  -m <model>      set model to <model>\\n\"\n\t    \"  -i <file>       read input from file <file>\\n\"\n\t    \"  -o <file>       write output to file <file>\\n\"\n\t    \"  -f <flash>      set flash address to <flash>\\n\"\n\t    \"  -S <start>      set start address to <start>\\n\");\n\n    exit(status);\n}\n\nstatic int strtou32(char *arg, unsigned int *val)\n{\n    char *endptr = NULL;\n\n    errno = 0;\n    *val = strtoul(arg, &endptr, 0);\n    if (errno || (endptr == arg) || (*endptr && (endptr != NULL))) {\n\treturn EXIT_SUCCESS;\n    }\n\n    return EXIT_FAILURE;\n}\n\nstatic unsigned short fwcsum (struct buf *buf) {\n    int i;\n    unsigned short ret = 0;\n\n    for (i = 0; i < buf->size / 2; i++)\n\tret -= ((unsigned short *) buf->start)[i];\n    \n    return ret;\n}\n\nstatic int fwread(struct finfo *finfo, struct buf *buf)\n{\n    FILE *f;\n    \n    f = fopen(finfo->name, \"r\");\n    if (!f) {\n\tfprintf(stderr, \"could not open \\\"%s\\\" for reading\\n\", finfo->name);\n\tusage(EXIT_FAILURE);\n    }\n\n    buf->size = fread(buf->start, 1, finfo->size, f);\n    if (buf->size != finfo->size) {\n\tfprintf(stderr, \"unable to read from file \\\"%s\\\"\\n\", finfo->name);\n\tusage(EXIT_FAILURE);\n    }\n\n    fclose(f);\n\n    return EXIT_SUCCESS;\n}\n\nstatic int fwwrite(struct finfo *finfo, struct buf *buf)\n{\n    FILE *f;\n\n    f = fopen(finfo->name, \"w\");\n    if (!f) {\n\tfprintf(stderr, \"could not open \\\"%s\\\" for writing\\n\", finfo->name);\n\tusage(EXIT_FAILURE);\n    }\n\n    buf->size = fwrite(buf->start, 1, finfo->size, f);\n    if (buf->size != finfo->size) {\n\tfprintf(stderr, \"unable to write to file \\\"%s\\\"\\n\", finfo->name);\n\tusage(EXIT_FAILURE);\n    }\n\n    fclose(f);\n\n    return EXIT_SUCCESS;\n}\t\n  \nint main(int argc, char **argv)\n{\n    struct stat st;\n    struct header header;\n    struct buf ibuf, obuf;\n    struct finfo ifinfo, ofinfo;\n    unsigned short csum;\n    int c;\n\n    ifinfo.name = ofinfo.name = NULL;\n    header.flash = header.size = header.start = 0;\n    progname = basename(argv[0]);\n\n    while((c = getopt(argc, argv, \"i:o:m:s:f:S:h\")) != -1) {\n\tswitch (c) {\n\tcase 'i':\n\t    ifinfo.name = optarg;\n\t    break;\n\tcase 'o':\n\t    ofinfo.name = optarg;\n\t    break;\n\tcase 'm':\n\t    if (strlen(optarg) != 4) {\n\t\tfprintf(stderr, \"model must be 4 characters long\\n\");\n\t\tusage(EXIT_FAILURE);\n\t    }\n\t    memcpy(header.model, optarg, 4);\n\t    break;\n\tcase 's':\n\t    if (strlen(optarg) != 4) {\n\t\tfprintf(stderr, \"signature must be 4 characters long\\n\");\n\t\tusage(EXIT_FAILURE);\n\t    }\n\t    memcpy(header.sign, optarg, 4);\n\t    break;\n\tcase 'h':\n\t    usage(EXIT_SUCCESS);\n\t    break;\n\tcase 'f':\n\t    if (!strtou32(optarg, &header.flash)) {\n\t\tfprintf(stderr, \"invalid flash address specified\\n\");\n\t\tusage(EXIT_FAILURE);\n\t    }\n\t    break;\n\tcase 'S':\n\t    if (!strtou32(optarg, &header.start)) {\n\t\tfprintf(stderr, \"invalid start address specified\\n\");\n\t\tusage(EXIT_FAILURE);\n\t    }\n\t    break;\n\tdefault:\n\t    usage(EXIT_FAILURE);\n\t    break;\n\t}\n    }\n\n    if (ifinfo.name == NULL) {\n\tfprintf(stderr, \"no input file specified\\n\");\n\tusage(EXIT_FAILURE);\n    }\n\n    if (ofinfo.name == NULL) {\n\tfprintf(stderr, \"no output file specified\\n\");\n\tusage(EXIT_FAILURE);\n    }\n\n    if (stat(ifinfo.name, &st)) {\n\tfprintf(stderr, \"stat failed on %s\\n\", ifinfo.name);\n\tusage(EXIT_FAILURE);\n    }\n\n    if (header.sign == NULL) {\n\tfprintf(stderr, \"no signature specified\\n\");\n\tusage(EXIT_FAILURE);\n    }\n\n    if (header.model == NULL) {\n\tfprintf(stderr, \"no model specified\\n\");\n\tusage(EXIT_FAILURE);\n    }\n\n    if (!header.flash) {\n\tfprintf(stderr, \"no flash address specified\\n\");\n\tusage(EXIT_FAILURE);\n    }\n\n    if (!header.start) {\n\tfprintf(stderr, \"no start address specified\\n\");\n\tusage(EXIT_FAILURE);\n    }\n\n    ifinfo.size = st.st_size;\n\n    obuf.size = ifinfo.size + sizeof(struct header) + sizeof(unsigned short);\n    if (obuf.size % sizeof(unsigned short))\n\tobuf.size++;\n\n    obuf.start = malloc(obuf.size);\n    if (!obuf.start) {\n\tfprintf(stderr, \"no memory for buffer\\n\");\n\tusage(EXIT_FAILURE);\n    }\n    memset(obuf.start, 0, obuf.size);\n\n    ibuf.size = ifinfo.size;\n    ibuf.start = obuf.start + sizeof(struct header);\n    \n    if (fwread(&ifinfo, &ibuf))\n\tusage(EXIT_FAILURE);\n\n    header.flash = HOST_TO_LE32(header.flash);\n    header.size = HOST_TO_LE32(obuf.size - sizeof(struct header));\n    header.start = HOST_TO_LE32(header.start);\n    memcpy (obuf.start, &header, sizeof(struct header));\n\n    csum = HOST_TO_LE16(fwcsum(&ibuf));\n    memcpy(obuf.start + obuf.size - sizeof(unsigned short),\n\t   &csum, sizeof(unsigned short));\n\n    ofinfo.size = obuf.size;\n\n    if (fwwrite(&ofinfo, &obuf))\n\tusage(EXIT_FAILURE);\n\n    return EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkfwimage.c",
    "content": "/*\n * Copyright (C) 2007 Ubiquiti Networks, Inc.\n * Copyright (C) 2008 Lukas Kuna <ValXdater@seznam.cz>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License as\n * published by the Free Software Foundation; either version 2 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful, but\n * WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n */\n\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <unistd.h>\n#include <string.h>\n#include <errno.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <netinet/in.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <limits.h>\n#include \"fw.h\"\n\ntypedef struct fw_layout_data {\n\tchar\t\tname[PATH_MAX];\n\tu_int32_t\tkern_start;\n\tu_int32_t\tkern_entry;\n\tu_int32_t\tfirmware_max_length;\n} fw_layout_t;\n\nfw_layout_t fw_layout_data[] = {\n\t{\n\t\t.name\t\t=\t\"XS2\",\n\t\t.kern_start\t=\t0xbfc30000,\n\t\t.kern_entry\t=\t0x80041000,\n\t\t.firmware_max_length=\t0x00390000,\n\t},\n\t{\n\t\t.name\t\t=\t\"XS5\",\n\t\t.kern_start\t=\t0xbe030000,\n\t\t.kern_entry\t=\t0x80041000,\n\t\t.firmware_max_length=\t0x00390000,\n\t},\n\t{\n\t\t.name\t\t=\t\"RS\",\n\t\t.kern_start\t=\t0xbf030000,\n\t\t.kern_entry\t=\t0x80060000,\n\t\t.firmware_max_length=\t0x00B00000,\n\t},\n\t{\n\t\t.name\t\t=\t\"RSPRO\",\n\t\t.kern_start\t=\t0xbf030000,\n\t\t.kern_entry\t=\t0x80060000,\n\t\t.firmware_max_length=\t0x00B00000,\n\t},\n\t{\n\t\t.name\t\t=\t\"LS-SR71\",\n\t\t.kern_start\t=\t0xbf030000,\n\t\t.kern_entry\t=\t0x80060000,\n\t\t.firmware_max_length=\t0x00640000,\n\t},\n\t{\n\t\t.name\t\t=\t\"XS2-8\",\n\t\t.kern_start\t=\t0xa8030000,\n\t\t.kern_entry\t=\t0x80041000,\n\t\t.firmware_max_length=\t0x006C0000,\n\t},\n\t{\n\t\t.name\t\t=\t\"XM\",\n\t\t.kern_start\t=\t0x9f050000,\n\t\t.kern_entry\t=\t0x80002000,\n\t\t.firmware_max_length=\t0x006A0000,\n\t},\n\t{\t.name\t\t=\t\"\",\n\t},\n};\n\ntypedef struct part_data {\n\tchar \tpartition_name[64];\n\tint  \tpartition_index;\n\tu_int32_t\tpartition_baseaddr;\n\tu_int32_t\tpartition_startaddr;\n\tu_int32_t\tpartition_memaddr;\n\tu_int32_t\tpartition_entryaddr;\n\tu_int32_t  partition_length;\n\n\tchar\tfilename[PATH_MAX];\n\tstruct stat stats;\n} part_data_t;\n\n#define MAX_SECTIONS\t8\n#define DEFAULT_OUTPUT_FILE \t\"firmware-image.bin\"\n#define DEFAULT_VERSION\t\t\"UNKNOWN\"\n\n#define OPTIONS \"B:hv:m:o:r:k:\"\n\nstatic int debug = 0;\n\ntypedef struct image_info {\n\tchar magic[16];\n\tchar version[256];\n\tchar outputfile[PATH_MAX];\n\tu_int32_t\tpart_count;\n\tpart_data_t parts[MAX_SECTIONS];\n} image_info_t;\n\nstatic void write_header(void* mem, const char *magic, const char* version)\n{\n\theader_t* header = mem;\n\tmemset(header, 0, sizeof(header_t));\n\n\tmemcpy(header->magic, magic, MAGIC_LENGTH);\n\tstrncpy(header->version, version, sizeof(header->version));\n\theader->crc = htonl(crc32(0L, (unsigned char *)header,\n\t\t\t\tsizeof(header_t) - 2 * sizeof(u_int32_t)));\n\theader->pad = 0L;\n}\n\n\nstatic void write_signature(void* mem, u_int32_t sig_offset)\n{\n\t/* write signature */\n\tsignature_t* sign = (signature_t*)(mem + sig_offset);\n\tmemset(sign, 0, sizeof(signature_t));\n\n\tmemcpy(sign->magic, MAGIC_END, MAGIC_LENGTH);\n\tsign->crc = htonl(crc32(0L,(unsigned char *)mem, sig_offset));\n\tsign->pad = 0L;\n}\n\nstatic int write_part(void* mem, part_data_t* d)\n{\n\tchar* addr;\n\tint fd;\n\tpart_t* p = mem;\n\tpart_crc_t* crc = mem + sizeof(part_t) + d->stats.st_size;\n\n\tfd = open(d->filename, O_RDONLY);\n\tif (fd < 0)\n\t{\n\t\tERROR(\"Failed opening file '%s'\\n\", d->filename);\n\t\treturn -1;\n\t}\n\n\tif ((addr=(char*)mmap(0, d->stats.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED)\n\t{\n\t\tERROR(\"Failed mmaping memory for file '%s'\\n\", d->filename);\n\t\tclose(fd);\n\t\treturn -2;\n\t}\n\n\tmemcpy(mem + sizeof(part_t), addr, d->stats.st_size);\n\tmunmap(addr, d->stats.st_size);\n\n\tmemset(p->name, 0, sizeof(p->name));\n\tstrncpy(p->magic, MAGIC_PART, MAGIC_LENGTH);\n\tstrncpy(p->name, d->partition_name, sizeof(p->name));\n\tp->index = htonl(d->partition_index);\n\tp->data_size = htonl(d->stats.st_size);\n\tp->part_size = htonl(d->partition_length);\n\tp->baseaddr = htonl(d->partition_baseaddr);\n\tp->memaddr = htonl(d->partition_memaddr);\n\tp->entryaddr = htonl(d->partition_entryaddr);\n\n\tcrc->crc = htonl(crc32(0L, mem, d->stats.st_size + sizeof(part_t)));\n\tcrc->pad = 0L;\n\n\treturn 0;\n}\n\nstatic void usage(const char* progname)\n{\n\tINFO(\"Version %s\\n\"\n             \"Usage: %s [options]\\n\"\n\t     \"\\t-v <version string>\\t - firmware version information, default: %s\\n\"\n\t     \"\\t-o <output file>\\t - firmware output file, default: %s\\n\"\n\t     \"\\t-m <magic>\\t - firmware magic, default: %s\\n\"\n\t     \"\\t-k <kernel file>\\t\\t - kernel file\\n\"\n\t     \"\\t-r <rootfs file>\\t\\t - rootfs file\\n\"\n\t     \"\\t-B <board name>\\t\\t - choose firmware layout for specified board (XS2, XS5, RS, XM)\\n\"\n\t     \"\\t-h\\t\\t\\t - this help\\n\", VERSION,\n\t     progname, DEFAULT_VERSION, DEFAULT_OUTPUT_FILE, MAGIC_HEADER);\n}\n\nstatic void print_image_info(const image_info_t* im)\n{\n\tint i = 0;\n\tINFO(\"Firmware version: '%s'\\n\"\n\t     \"Output file: '%s'\\n\"\n\t     \"Part count: %u\\n\",\n\t     im->version, im->outputfile,\n\t     im->part_count);\n\n\tfor (i = 0; i < im->part_count; ++i)\n\t{\n\t\tconst part_data_t* d = &im->parts[i];\n\t\tINFO(\" %10s: %8ld bytes (free: %8ld)\\n\",\n\t\t     d->partition_name,\n\t\t     d->stats.st_size,\n\t\t     d->partition_length - d->stats.st_size);\n\t}\n}\n\n\n\nstatic u_int32_t filelength(const char* file)\n{\n\tFILE *p;\n\tint ret = -1;\n\n\tif ( (p = fopen(file, \"rb\") ) == NULL) return (-1);\n\n\tfseek(p, 0, SEEK_END);\n\tret = ftell(p);\n\n\tfclose (p);\n\n\treturn (ret);\n}\n\nstatic int create_image_layout(const char* kernelfile, const char* rootfsfile, char* board_name, image_info_t* im)\n{\n\tpart_data_t* kernel = &im->parts[0];\n\tpart_data_t* rootfs = &im->parts[1];\n\n\tfw_layout_t* p;\n\n\tp = &fw_layout_data[0];\n\twhile ((strlen(p->name) != 0) && (strncmp(p->name, board_name, sizeof(board_name)) != 0))\n\t\tp++;\n\tif (p->name == NULL) {\n\t\tprintf(\"BUG! Unable to find default fw layout!\\n\");\n\t\texit(-1);\n\t}\n\n\tprintf(\"board = %s\\n\", p->name);\n\tstrcpy(kernel->partition_name, \"kernel\");\n\tkernel->partition_index = 1;\n\tkernel->partition_baseaddr = p->kern_start;\n\tif ( (kernel->partition_length = filelength(kernelfile)) < 0) return (-1);\n\tkernel->partition_memaddr = p->kern_entry;\n\tkernel->partition_entryaddr = p->kern_entry;\n\tstrncpy(kernel->filename, kernelfile, sizeof(kernel->filename));\n\n\tif (filelength(rootfsfile) + kernel->partition_length > p->firmware_max_length)\n\t\treturn (-2);\n\n\tstrcpy(rootfs->partition_name, \"rootfs\");\n\trootfs->partition_index = 2;\n\trootfs->partition_baseaddr = kernel->partition_baseaddr + kernel->partition_length;\n\trootfs->partition_length = p->firmware_max_length - kernel->partition_length;\n\trootfs->partition_memaddr = 0x00000000;\n\trootfs->partition_entryaddr = 0x00000000;\n\tstrncpy(rootfs->filename, rootfsfile, sizeof(rootfs->filename));\n\nprintf(\"kernel: %d 0x%08x\\n\", kernel->partition_length, kernel->partition_baseaddr);\nprintf(\"root: %d 0x%08x\\n\", rootfs->partition_length, rootfs->partition_baseaddr);\n\tim->part_count = 2;\n\n\treturn 0;\n}\n\n/**\n * Checks the availability and validity of all image components.\n * Fills in stats member of the part_data structure.\n */\nstatic int validate_image_layout(image_info_t* im)\n{\n\tint i;\n\n\tif (im->part_count == 0 || im->part_count > MAX_SECTIONS)\n\t{\n\t\tERROR(\"Invalid part count '%d'\\n\", im->part_count);\n\t\treturn -1;\n\t}\n\n\tfor (i = 0; i < im->part_count; ++i)\n\t{\n\t\tpart_data_t* d = &im->parts[i];\n\t\tint len = strlen(d->partition_name);\n\t\tif (len == 0 || len > 16)\n\t\t{\n\t\t\tERROR(\"Invalid partition name '%s' of the part %d\\n\",\n\t\t\t\t\td->partition_name, i);\n\t\t\treturn -1;\n\t\t}\n\t\tif (stat(d->filename, &d->stats) < 0)\n\t\t{\n\t\t\tERROR(\"Couldn't stat file '%s' from part '%s'\\n\",\n\t\t\t\t       \td->filename, d->partition_name);\n\t\t\treturn -2;\n\t\t}\n\t\tif (d->stats.st_size == 0)\n\t\t{\n\t\t\tERROR(\"File '%s' from part '%s' is empty!\\n\",\n\t\t\t\t       \td->filename, d->partition_name);\n\t\t\treturn -3;\n\t\t}\n\t\tif (d->stats.st_size > d->partition_length) {\n\t\t\tERROR(\"File '%s' too big (%d) - max size: 0x%08X (exceeds %lu bytes)\\n\",\n\t\t\t\t       \td->filename, i, d->partition_length,\n\t\t\t\t\td->stats.st_size - d->partition_length);\n\t\t\treturn -4;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\nstatic int build_image(image_info_t* im)\n{\n\tchar* mem;\n\tchar* ptr;\n\tu_int32_t mem_size;\n\tFILE* f;\n\tint i;\n\n\t// build in-memory buffer\n\tmem_size = sizeof(header_t) + sizeof(signature_t);\n\tfor (i = 0; i < im->part_count; ++i)\n\t{\n\t\tpart_data_t* d = &im->parts[i];\n\t\tmem_size += sizeof(part_t) + d->stats.st_size + sizeof(part_crc_t);\n\t}\n\n\tmem = (char*)calloc(mem_size, 1);\n\tif (mem == NULL)\n\t{\n\t\tERROR(\"Cannot allocate memory chunk of size '%u'\\n\", mem_size);\n\t\treturn -1;\n\t}\n\n\t// write header\n\twrite_header(mem, im->magic, im->version);\n\tptr = mem + sizeof(header_t);\n\t// write all parts\n\tfor (i = 0; i < im->part_count; ++i)\n\t{\n\t\tpart_data_t* d = &im->parts[i];\n\t\tint rc;\n\t\tif ((rc = write_part(ptr, d)) != 0)\n\t\t{\n\t\t\tERROR(\"ERROR: failed writing part %u '%s'\\n\", i, d->partition_name);\n\t\t}\n\t\tptr += sizeof(part_t) + d->stats.st_size + sizeof(part_crc_t);\n\t}\n\t// write signature\n\twrite_signature(mem, mem_size - sizeof(signature_t));\n\n\t// write in-memory buffer into file\n\tif ((f = fopen(im->outputfile, \"w\")) == NULL)\n\t{\n\t\tERROR(\"Can not create output file: '%s'\\n\", im->outputfile);\n\t\treturn -10;\n\t}\n\n\tif (fwrite(mem, mem_size, 1, f) != 1)\n\t{\n\t\tERROR(\"Could not write %d bytes into file: '%s'\\n\",\n\t\t\t\tmem_size, im->outputfile);\n\t\treturn -11;\n\t}\n\n\tfree(mem);\n\tfclose(f);\n\treturn 0;\n}\n\n\nint main(int argc, char* argv[])\n{\n\tchar kernelfile[PATH_MAX];\n\tchar rootfsfile[PATH_MAX];\n\tchar board_name[PATH_MAX];\n\tint o, rc;\n\timage_info_t im;\n\n\tmemset(&im, 0, sizeof(im));\n\tmemset(kernelfile, 0, sizeof(kernelfile));\n\tmemset(rootfsfile, 0, sizeof(rootfsfile));\n\tmemset(board_name, 0, sizeof(board_name));\n\n\tstrcpy(im.outputfile, DEFAULT_OUTPUT_FILE);\n\tstrcpy(im.version, DEFAULT_VERSION);\n\tstrncpy(im.magic, MAGIC_HEADER, sizeof(im.magic));\n\n\twhile ((o = getopt(argc, argv, OPTIONS)) != -1)\n\t{\n\t\tswitch (o) {\n\t\tcase 'v':\n\t\t\tif (optarg)\n\t\t\t\tstrncpy(im.version, optarg, sizeof(im.version));\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tif (optarg)\n\t\t\t\tstrncpy(im.outputfile, optarg, sizeof(im.outputfile));\n\t\t\tbreak;\n\t\tcase 'm':\n\t\t\tif (optarg)\n\t\t\t\tstrncpy(im.magic, optarg, sizeof(im.magic));\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(argv[0]);\n\t\t\treturn -1;\n\t\tcase 'k':\n\t\t\tif (optarg)\n\t\t\t\tstrncpy(kernelfile, optarg, sizeof(kernelfile));\n\t\t\tbreak;\n\t\tcase 'r':\n\t\t\tif (optarg)\n\t\t\t\tstrncpy(rootfsfile, optarg, sizeof(rootfsfile));\n\t\t\tbreak;\n\t\tcase 'B':\n\t\t\tif (optarg)\n\t\t\t\tstrncpy(board_name, optarg, sizeof(board_name));\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (strlen(board_name) == 0)\n\t\tstrcpy(board_name, \"XS2\"); /* default to XS2 */\n\n\tif (strlen(kernelfile) == 0)\n\t{\n\t\tERROR(\"Kernel file is not specified, cannot continue\\n\");\n\t\tusage(argv[0]);\n\t\treturn -2;\n\t}\n\n\tif (strlen(rootfsfile) == 0)\n\t{\n\t\tERROR(\"Root FS file is not specified, cannot continue\\n\");\n\t\tusage(argv[0]);\n\t\treturn -2;\n\t}\n\n\tif ((rc = create_image_layout(kernelfile, rootfsfile, board_name, &im)) != 0)\n\t{\n\t\tERROR(\"Failed creating firmware layout description - error code: %d\\n\", rc);\n\t\treturn -3;\n\t}\n\n\tif ((rc = validate_image_layout(&im)) != 0)\n\t{\n\t\tERROR(\"Failed validating firmware layout - error code: %d\\n\", rc);\n\t\treturn -4;\n\t}\n\n\tprint_image_info(&im);\n\n\tif ((rc = build_image(&im)) != 0)\n\t{\n\t\tERROR(\"Failed building image file '%s' - error code: %d\\n\", im.outputfile, rc);\n\t\treturn -5;\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkfwimage2.c",
    "content": "/*\n * Copyright (C) 2007 Ubiquiti Networks, Inc.\n * Copyright (C) 2008 Lukas Kuna <ValXdater@seznam.cz>\n * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License as\n * published by the Free Software Foundation; either version 2 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful, but\n * WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n */\n\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <unistd.h>\n#include <string.h>\n#include <errno.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <netinet/in.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <limits.h>\n#include \"fw.h\"\n\n#undef VERSION\n#define VERSION \"1.2-OpenWrt.1\"\n\n#define MAX_SECTIONS\t\t8\n#define DEFAULT_OUTPUT_FILE \t\"firmware-image.bin\"\n#define DEFAULT_VERSION\t\t\"UNKNOWN\"\n#define DEFAULT_FLASH_BASE\t(0xbfc00000)\n\n#define FIRMWARE_MAX_LENGTH\t(0x390000)\n\ntypedef struct part_data {\n\tchar \t\tpartition_name[64];\n\tint  \t\tpartition_index;\n\tu_int32_t\tpartition_baseaddr;\n\tu_int32_t\tpartition_offset;\n\tu_int32_t\tpartition_memaddr;\n\tu_int32_t\tpartition_entryaddr;\n\tu_int32_t\tpartition_length;\n\n\tchar\t\tfilename[PATH_MAX];\n\tstruct stat\tstats;\n} part_data_t;\n\ntypedef struct image_info {\n\tchar\t\tversion[256];\n\tchar\t\toutputfile[PATH_MAX];\n\tchar\t\tmagic[MAGIC_LENGTH];\n\tu_int32_t\tflash_baseaddr;\n\tu_int32_t\tpart_count;\n\tpart_data_t\tparts[MAX_SECTIONS];\n} image_info_t;\n\nstatic image_info_t im;\nstatic int debug = 0;\nstatic int zero_part_baseaddr = 0;\n\nstatic void write_header(void* mem, const char* version)\n{\n\theader_t* header = mem;\n\tmemset(header, 0, sizeof(header_t));\n\n\tmemcpy(header->magic, im.magic, MAGIC_LENGTH);\n\tstrncpy(header->version, version, sizeof(header->version));\n\theader->crc = htonl(crc32(0L, (unsigned char *)header,\n\t\t\t\tsizeof(header_t) - 2 * sizeof(u_int32_t)));\n\theader->pad = 0L;\n}\n\nstatic void write_signature(void* mem, u_int32_t sig_offset)\n{\n\t/* write signature */\n\tsignature_t* sign = (signature_t*)(mem + sig_offset);\n\tmemset(sign, 0, sizeof(signature_t));\n\n\tmemcpy(sign->magic, MAGIC_END, MAGIC_LENGTH);\n\tsign->crc = htonl(crc32(0L,(unsigned char *)mem, sig_offset));\n\tsign->pad = 0L;\n}\n\nstatic int write_part(void* mem, part_data_t* d)\n{\n\tchar* addr;\n\tint fd;\n\tpart_t* p = mem;\n\tpart_crc_t* crc = mem + sizeof(part_t) + d->stats.st_size;\n\n\tfd = open(d->filename, O_RDONLY);\n\tif (fd < 0) {\n\t\tERROR(\"Failed opening file '%s'\\n\", d->filename);\n\t\treturn -1;\n\t}\n\n\tif ((addr=(char*)mmap(0, d->stats.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {\n\t\tERROR(\"Failed mmaping memory for file '%s'\\n\", d->filename);\n\t\tclose(fd);\n\t\treturn -2;\n\t}\n\n\tmemcpy(mem + sizeof(part_t), addr, d->stats.st_size);\n\tmunmap(addr, d->stats.st_size);\n\n\tmemset(p->name, 0, sizeof(p->name));\n\tstrncpy(p->magic, MAGIC_PART, MAGIC_LENGTH);\n\tstrncpy(p->name, d->partition_name, sizeof(p->name));\n\tp->index = htonl(d->partition_index);\n\tp->data_size = htonl(d->stats.st_size);\n\tp->part_size = htonl(d->partition_length);\n\tp->baseaddr = htonl(d->partition_baseaddr);\n\tp->memaddr = htonl(d->partition_memaddr);\n\tp->entryaddr = htonl(d->partition_entryaddr);\n\n\tcrc->crc = htonl(crc32(0L, mem, d->stats.st_size + sizeof(part_t)));\n\tcrc->pad = 0L;\n\n\treturn 0;\n}\n\nstatic void usage(const char* progname)\n{\n\tINFO(\"Version %s\\n\"\n             \"Usage: %s [options]\\n\"\n\t     \"\\t-v <version string>\\t - firmware version information, default: %s\\n\"\n\t     \"\\t-m <magic>\\t\\t - firmware magic, default: %s\\n\"\n\t     \"\\t-f <flash base>\\t\\t - flash base address, default: 0x%08x\\n\"\n\t     \"\\t-o <output file>\\t - firmware output file, default: %s\\n\"\n\t     \"\\t-p <name>:<offset>:<len>:<memaddr>:<entry>:<file>\\n \"\n\t     \"\\t\\t\\t\\t - create a partition from <file>\\n\"\n\t     \"\\t-z\\t\\t\\t - set partition offsets to zero\\n\"\n\t     \"\\t-h\\t\\t\\t - this help\\n\",\n\t     VERSION, progname, DEFAULT_VERSION, MAGIC_HEADER,\n\t     DEFAULT_FLASH_BASE, DEFAULT_OUTPUT_FILE);\n}\n\nstatic void print_image_info(void)\n{\n\tint i;\n\n\tINFO(\"Firmware version : '%s'\\n\"\n\t     \"Output file      : '%s'\\n\"\n\t     \"Part count       : %u\\n\",\n\t     im.version, im.outputfile, im.part_count);\n\n\tfor (i = 0; i < im.part_count; ++i) {\n\t\tconst part_data_t* d = &im.parts[i];\n\t\tINFO(\"  %10s: %08x %08x %08x %08x %8ld bytes (free: %8ld)\\n\",\n\t\t     d->partition_name,\n\t\t     d->partition_baseaddr,\n\t\t     d->partition_length,\n\t\t     d->partition_entryaddr,\n\t\t     d->partition_memaddr,\n\t\t     d->stats.st_size,\n\t\t     d->partition_length - d->stats.st_size);\n\t}\n}\n\nstatic int filelength(const char* file)\n{\n\tFILE *p;\n\tint ret = -1;\n\n\tif ( (p = fopen(file, \"rb\") ) == NULL) return (-1);\n\n\tfseek(p, 0, SEEK_END);\n\tret = ftell(p);\n\n\tfclose (p);\n\n\treturn (ret);\n}\n\nint str2u32(char *arg, u_int32_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno = 0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err == arg) || ((err != NULL) && *err)) {\n\t\treturn -1;\n\t}\n\n\t*val = t;\n\treturn 0;\n}\n\nstatic int image_layout_add_partition(const char *part_desc)\n{\n\tpart_data_t *d;\n\tchar memaddr[16];\n\tchar entryaddr[16];\n\tchar offset[16];\n\tchar length[16];\n\tint t;\n\n\tif (im.part_count >= MAX_SECTIONS) {\n\t\tERROR(\"Too many partitions specified\\n\");\n\t\treturn (-1);\n\t}\n\n\td = &im.parts[im.part_count];\n\tt = sscanf(part_desc, \"%15[a-zA-Z]:%15[0-9a-fA-Fx]:%15[0-9a-fA-Fx]:%15[0-9a-fA-Fx]:%15[0-9a-fA-Fx]:%256s\",\n\t\t\td->partition_name,\n\t\t\toffset,\n\t\t\tlength,\n\t\t\tmemaddr,\n\t\t\tentryaddr,\n\t\t\td->filename);\n\n\tif (t != 6) {\n\t\tERROR(\"Bad partition parameter %d, '%s'\\n\", t, part_desc);\n\t\treturn (-1);\n\t}\n\n\tif (strlen(d->partition_name) == 0) {\n\t\tERROR(\"No partition name specified in '%s'\\n\", part_desc);\n\t\treturn (-1);\n\t}\n\n\tif (str2u32(offset, &d->partition_offset)) {\n\t\tERROR(\"Bad offset value '%s'\\n\", offset);\n\t\treturn (-1);\n\t}\n\n\tif (str2u32(length, &d->partition_length)) {\n\t\tERROR(\"Bad length value '%s'\\n\", length);\n\t\treturn (-1);\n\t}\n\n\tif (d->partition_length == 0) {\n\t\tint flen;\n\t\tflen = filelength(d->filename);\n\t\tif (flen < 0) {\n\t\t\tERROR(\"Unable to determine size of '%s'\\n\",\n\t\t\t\t\td->filename);\n\t\t\treturn (-1);\n\t\t}\n\t\td->partition_length = flen;\n\t}\n\n\tif (str2u32(memaddr, &d->partition_memaddr)) {\n\t\tERROR(\"Bad memaddr vaule '%s'\\n\", memaddr);\n\t\treturn (-1);\n\t}\n\n\tif (str2u32(entryaddr, &d->partition_entryaddr)) {\n\t\tERROR(\"Bad entry address value '%s'\\n\", entryaddr);\n\t\treturn (-1);\n\t}\n\n\tim.part_count++;\n\td->partition_index = im.part_count;\n\n\treturn 0;\n}\n\nstatic int image_layout_verify(void)\n{\n\tu_int32_t offset;\n\tint i;\n\n\tif (im.part_count == 0) {\n\t\tERROR(\"No partitions specified\\n\");\n\t\treturn -1;\n\t}\n\n\toffset = im.parts[0].partition_offset;\n\tfor (i = 0; i < im.part_count; i++)\n\t{\n\t\tpart_data_t* d = &im.parts[i];\n\n\t\tif (stat(d->filename, &d->stats) < 0) {\n\t\t\tERROR(\"Couldn't stat file '%s' from part '%s'\\n\",\n\t\t\t\t\td->filename, d->partition_name);\n\t\t\treturn -2;\n\t\t}\n\n\t\tif (d->stats.st_size == 0) {\n\t\t\tERROR(\"File '%s' from part '%s' is empty!\\n\",\n\t\t\t\t\td->filename, d->partition_name);\n\t\t\treturn -3;\n\t\t}\n\n\t\tif (d->stats.st_size > d->partition_length) {\n\t\t\tERROR(\"File '%s' too big (%d) - max size: 0x%08X (exceeds %lu bytes)\\n\",\n\t\t\t\td->filename, i, d->partition_length,\n\t\t\t\td->stats.st_size - d->partition_length);\n\t\t\treturn -4;\n\t\t}\n\n\t\tif (d->partition_offset < offset)\n\t\t\td->partition_offset = offset;\n\n\t\tif (zero_part_baseaddr) {\n\t\t\td->partition_baseaddr = 0;\n\t\t} else {\n\t\t\td->partition_baseaddr =\n\t\t\t\tim.flash_baseaddr + d->partition_offset;\n\t\t}\n\t\toffset += d->partition_length;\n\t}\n\n\treturn 0;\n}\n\nstatic int build_image(void)\n{\n\tchar* mem;\n\tchar* ptr;\n\tu_int32_t mem_size;\n\tFILE* f;\n\tint i;\n\n\t/* build in-memory buffer */\n\tmem_size = sizeof(header_t) + sizeof(signature_t);\n\tfor (i = 0; i < im.part_count; ++i) {\n\t\tpart_data_t* d = &im.parts[i];\n\t\tmem_size += sizeof(part_t) + d->stats.st_size + sizeof(part_crc_t);\n\t}\n\n\tmem = (char*)calloc(mem_size, 1);\n\tif (mem == NULL) {\n\t\tERROR(\"Cannot allocate memory chunk of size '%u'\\n\", mem_size);\n\t\treturn -1;\n\t}\n\n\t/* write header */\n\twrite_header(mem, im.version);\n\tptr = mem + sizeof(header_t);\n\n\t/* write all parts */\n\tfor (i = 0; i < im.part_count; ++i) {\n\t\tpart_data_t* d = &im.parts[i];\n\t\tint rc;\n\t\tif ((rc = write_part(ptr, d)) != 0) {\n\t\t\tERROR(\"ERROR: failed writing part %u '%s'\\n\", i, d->partition_name);\n\t\t\treturn -1;\n\t\t}\n\t\tptr += sizeof(part_t) + d->stats.st_size + sizeof(part_crc_t);\n\t}\n\n\n\t/* write signature */\n\twrite_signature(mem, mem_size - sizeof(signature_t));\n\n\t/* write in-memory buffer into file */\n\tif ((f = fopen(im.outputfile, \"w\")) == NULL) {\n\t\tERROR(\"Can not create output file: '%s'\\n\", im.outputfile);\n\t\treturn -10;\n\t}\n\n\tif (fwrite(mem, mem_size, 1, f) != 1) {\n\t\tERROR(\"Could not write %d bytes into file: '%s'\\n\",\n\t\t\t\tmem_size, im.outputfile);\n\t\treturn -11;\n\t}\n\n\tfree(mem);\n\tfclose(f);\n\treturn 0;\n}\n\nint main(int argc, char* argv[])\n{\n\tint o, rc;\n\n\tmemset(&im, 0, sizeof(im));\n\n\tstrcpy(im.outputfile, DEFAULT_OUTPUT_FILE);\n\tstrcpy(im.version, DEFAULT_VERSION);\n\tmemcpy(im.magic, MAGIC_HEADER, MAGIC_LENGTH);\n\tim.flash_baseaddr = DEFAULT_FLASH_BASE;\n\n\twhile ((o = getopt(argc, argv, \"f:hm:o:p:v:z\")) != -1)\n\t{\n\t\tswitch (o) {\n\t\tcase 'f':\n\t\t\tif (optarg)\n\t\t\t\tif (str2u32(optarg, &im.flash_baseaddr)) {\n\t\t\t\t\tERROR(\"Invalid flash start address %s\\n\", optarg);\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(argv[0]);\n\t\t\treturn -1;\n\t\tcase 'm':\n\t\t\tif (optarg) {\n\t\t\t\tif (strlen(optarg) != MAGIC_LENGTH) {\n\t\t\t\t\tERROR(\"Invalid magic %s\\n\", optarg);\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\n\t\t\t\tmemcpy(im.magic, optarg, MAGIC_LENGTH);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tif (optarg)\n\t\t\t\tstrncpy(im.outputfile, optarg, sizeof(im.outputfile));\n\t\t\tbreak;\n\t\tcase 'p':\n\t\t\tif (optarg) {\n\t\t\t\tif (image_layout_add_partition(optarg))\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tif (optarg)\n\t\t\t\tstrncpy(im.version, optarg, sizeof(im.version));\n\t\t\tbreak;\n\t\tcase 'z':\n\t\t\tzero_part_baseaddr = 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\trc = image_layout_verify();\n\tif (rc)\t{\n\t\tERROR(\"Failed validating firmware layout - error code: %d\\n\",\n\t\t\t\trc);\n\t\treturn -4;\n\t}\n\n\tprint_image_info();\n\n\trc = build_image();\n\tif (rc)\t{\n\t\tERROR(\"Failed building image file '%s' - error code: %d\\n\",\n\t\t\t\tim.outputfile, rc);\n\t\treturn -5;\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkmylofw.c",
    "content": "/*\n *  Copyright (C) 2006-2008 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or\n *  modify it under the terms of the GNU General Public License\n *  as published by the Free Software Foundation; either version 2\n *  of the License, or (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program; if not, write to the\n *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n *  Boston, MA  02110-1301, USA.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n#include <endian.h>     /* for __BYTE_ORDER */\n\n#if defined(__CYGWIN__)\n#  include <byteswap.h>\n#endif\n\n#if (__BYTE_ORDER == __LITTLE_ENDIAN)\n#  define HOST_TO_LE16(x)\t(x)\n#  define HOST_TO_LE32(x)\t(x)\n#else\n#  define HOST_TO_LE16(x)\tbswap_16(x)\n#  define HOST_TO_LE32(x)\tbswap_32(x)\n#endif\n\n#include \"myloader.h\"\n\n#define MAX_FW_BLOCKS  \t32\n#define MAX_ARG_COUNT   32\n#define MAX_ARG_LEN     1024\n#define FILE_BUF_LEN    (16*1024)\n#define PART_NAME_LEN\t32\n\nstruct fw_block {\n\tuint32_t\taddr;\n\tuint32_t\tblocklen; /* length of the block */\n\tuint32_t\tflags;\n\n\tchar\t\t*name;  /* name of the file */\n\tuint32_t\tsize;  \t/* length of the file */\n\tuint32_t\tcrc;    /* crc value of the file */\n};\n\nstruct fw_part {\n\tstruct mylo_partition\tmylo;\n\tchar\t\t\tname[PART_NAME_LEN];\n};\n\n#define BLOCK_FLAG_HAVEHDR    0x0001\n\nstruct cpx_board {\n\tchar\t\t*model; /* model number*/\n\tchar\t\t*name;\t/* model name*/\n\tchar\t\t*desc;  /* description */\n\tuint16_t        vid;    /* vendor id */\n\tuint16_t        did;    /* device id */\n\tuint16_t        svid;   /* sub vendor id */\n\tuint16_t        sdid;   /* sub device id */\n\tuint32_t        flash_size;     /* size of flash */\n\tuint32_t\tpart_offset;\t/* offset of the partition_table */\n\tuint32_t\tpart_size;\t/* size of the partition_table */\n};\n\n#define BOARD(_vid, _did, _svid, _sdid, _flash, _mod, _name, _desc, _po, _ps) {\t\t\\\n\t.model = _mod, .name = _name, .desc = _desc,   \t\t\t\\\n\t.vid = _vid, .did = _did, .svid = _svid, .sdid = _sdid,         \\\n\t.flash_size = (_flash << 20),\t\t\t\t\t\\\n\t.part_offset = _po, .part_size = _ps }\n\n#define CPX_BOARD(_did, _flash, _mod, _name, _desc, _po, _ps) \\\n\tBOARD(VENID_COMPEX, _did, VENID_COMPEX, _did, _flash, _mod, _name, _desc, _po, _ps)\n\n#define CPX_BOARD_ADM(_did, _flash, _mod, _name, _desc) \\\n\tCPX_BOARD(_did, _flash, _mod, _name, _desc, 0x10000, 0x10000)\n\n#define CPX_BOARD_AR71XX(_did, _flash, _mod, _name, _desc) \\\n\tCPX_BOARD(_did, _flash, _mod, _name, _desc, 0x20000, 0x8000)\n\n#define CPX_BOARD_AR23XX(_did, _flash, _mod, _name, _desc) \\\n\tCPX_BOARD(_did, _flash, _mod, _name, _desc, 0x10000, 0x10000)\n\n#define ALIGN(x,y)\t((x)+((y)-1)) & ~((y)-1)\n\nchar\t*progname;\nchar\t*ofname = NULL;\n\nuint32_t flash_size = 0;\nint\tfw_num_partitions = 0;\nint\tfw_num_blocks = 0;\nint\tverblevel = 0;\n\nstruct mylo_fw_header fw_header;\nstruct fw_part fw_parts[MYLO_MAX_PARTITIONS];\nstruct fw_block fw_blocks[MAX_FW_BLOCKS];\nstruct cpx_board *board;\n\nstruct cpx_board boards[] = {\n\tCPX_BOARD_ADM(DEVID_COMPEX_NP18A, 4,\n\t\t\"NP18A\", \"Compex NetPassage 18A\",\n\t\t\"Dualband Wireless A+G Internet Gateway\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_NP26G8M, 2,\n\t\t\"NP26G8M\", \"Compex NetPassage 26G (8M)\",\n\t\t\"Wireless-G Broadband Multimedia Gateway\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_NP26G16M, 4,\n\t\t\"NP26G16M\", \"Compex NetPassage 26G (16M)\",\n\t\t\"Wireless-G Broadband Multimedia Gateway\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_NP27G, 4,\n\t\t\"NP27G\", \"Compex NetPassage 27G\",\n\t\t\"Wireless-G 54Mbps eXtended Range Router\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_NP28G, 4,\n\t\t\"NP28G\", \"Compex NetPassage 28G\",\n\t\t\"Wireless 108Mbps Super-G XR Multimedia Router with 4 USB Ports\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_NP28GHS, 4,\n\t\t\"NP28GHS\", \"Compex NetPassage 28G (HotSpot)\",\n\t\t\"HotSpot Solution\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_WP18, 4,\n\t\t\"WP18\", \"Compex NetPassage WP18\",\n\t\t\"Wireless-G 54Mbps A+G Dualband Access Point\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_WP54G, 4,\n\t\t\"WP54G\", \"Compex WP54G\",\n\t\t\"Wireless-G 54Mbps XR Access Point\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_WP54Gv1C, 2,\n\t\t\"WP54Gv1C\", \"Compex WP54G rev.1C\",\n\t\t\"Wireless-G 54Mbps XR Access Point\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_WP54AG, 4,\n\t\t\"WP54AG\", \"Compex WP54AG\",\n\t\t\"Wireless-AG 54Mbps XR Access Point\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_WPP54G, 4,\n\t\t\"WPP54G\", \"Compex WPP54G\",\n\t\t\"Outdoor Access Point\"),\n\tCPX_BOARD_ADM(DEVID_COMPEX_WPP54AG, 4,\n\t\t\"WPP54AG\", \"Compex WPP54AG\",\n\t\t\"Outdoor Access Point\"),\n\n\tCPX_BOARD_AR71XX(DEVID_COMPEX_WP543, 2,\n\t\t\"WP543\", \"Compex WP543\",\n\t\t\"BareBoard\"),\n\tCPX_BOARD_AR71XX(DEVID_COMPEX_WPE72, 8,\n\t\t\"WPE72\", \"Compex WPE72\",\n\t\t\"BareBoard\"),\n\n\tCPX_BOARD_AR23XX(DEVID_COMPEX_NP25G, 4,\n\t\t\"NP25G\", \"Compex NetPassage 25G\",\n\t\t\"Wireless 54Mbps XR Router\"),\n\tCPX_BOARD_AR23XX(DEVID_COMPEX_WPE53G, 4,\n\t\t\"WPE53G\", \"Compex NetPassage 25G\",\n\t\t\"Wireless 54Mbps XR Access Point\"),\n\t{.model = NULL}\n};\n\nvoid\nerrmsgv(int syserr, const char *fmt, va_list arg_ptr)\n{\n\tint save = errno;\n\n\tfflush(0);\n\tfprintf(stderr, \"[%s] Error: \", progname);\n\tvfprintf(stderr, fmt, arg_ptr);\n\tif (syserr != 0) {\n\t\tfprintf(stderr, \": %s\", strerror(save));\n\t}\n\tfprintf(stderr, \"\\n\");\n}\n\nvoid\nerrmsg(int syserr, const char *fmt, ...)\n{\n\tva_list arg_ptr;\n\tva_start(arg_ptr, fmt);\n\terrmsgv(syserr, fmt, arg_ptr);\n\tva_end(arg_ptr);\n}\n\nvoid\ndbgmsg(int level, const char *fmt, ...)\n{\n\tva_list arg_ptr;\n\tif (verblevel >= level) {\n\t\tfflush(0);\n\t\tva_start(arg_ptr, fmt);\n\t\tvfprintf(stderr, fmt, arg_ptr);\n\t\tfprintf(stderr, \"\\n\");\n\t\tva_end(arg_ptr);\n\t}\n}\n\n\nvoid\nusage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct cpx_board *board;\n\n\tfprintf(stream, \"Usage: %s [OPTION...] <file>\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"  <file>          write output to the <file>\\n\"\n\"\\n\"\n\"Options:\\n\"\n\"  -B <board>      create firmware for the board specified with <board>.\\n\"\n\"                  This option set vendor id, device id, subvendor id,\\n\"\n\"                  subdevice id, and flash size options to the right value.\\n\"\n\"                  valid <board> values:\\n\");\n\tfor (board = boards; board->model != NULL; board++){\n\t\tfprintf(stream,\n\"                      %-12s: %s\\n\",\n\t\t board->model, board->name);\n\t};\n\tfprintf(stream,\n\"  -i <vid>:<did>[:<svid>[:<sdid>]]\\n\"\n\"                  create firmware for board with vendor id <vid>, device\\n\"\n\"                  id <did>, subvendor id <svid> and subdevice id <sdid>.\\n\"\n\"  -r <rev>        set board revision to <rev>.\\n\"\n\"  -s <size>       set flash size to <size>\\n\"\n\"  -b <addr>:<len>[:[<flags>]:<file>]\\n\"\n\"                  define block at <addr> with length of <len>.\\n\"\n\"                  valid <flag> values:\\n\"\n\"                      h : add crc header before the file data.\\n\"\n\"  -p <addr>:<len>[:<flags>[:<param>[:<name>[:<file>]]]]\\n\"\n\"                  add partition at <addr>, with size of <len> to the\\n\"\n\"                  partition table, set partition name to <name>, partition \\n\"\n\"                  flags to <flags> and partition parameter to <param>.\\n\"\n\"                  If the <file> is specified content of the file will be \\n\"\n\"                  added to the firmware image.\\n\"\n\"                  valid <flag> values:\\n\"\n\"                      a:  this is the active partition. The bootloader loads\\n\"\n\"                          the firmware from this partition.\\n\"\n\"                      h:  the partition data have a header.\\n\"\n\"                      l:  the partition data uses LZMA compression.\\n\"\n\"                      p:  the bootloader loads data from this partition to\\n\"\n\"                          the RAM before decompress it.\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\n/*\n * Code to compute the CRC-32 table. Borrowed from\n * gzip-1.0.3/makecrc.c.\n */\n\nstatic uint32_t crc_32_tab[256];\n\nvoid\ninit_crc_table(void)\n{\n\t/* Not copyrighted 1990 Mark Adler\t*/\n\n\tuint32_t c;      /* crc shift register */\n\tuint32_t e;      /* polynomial exclusive-or pattern */\n\tint i;           /* counter for all possible eight bit values */\n\tint k;           /* byte being shifted into crc apparatus */\n\n\t/* terms of polynomial defining this crc (except x^32): */\n\tstatic const int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};\n\n\t/* Make exclusive-or pattern from polynomial */\n\te = 0;\n\tfor (i = 0; i < sizeof(p)/sizeof(int); i++)\n\t\te |= 1L << (31 - p[i]);\n\n\tcrc_32_tab[0] = 0;\n\n\tfor (i = 1; i < 256; i++) {\n\t\tc = 0;\n\t\tfor (k = i | 256; k != 1; k >>= 1) {\n\t\t\tc = c & 1 ? (c >> 1) ^ e : c >> 1;\n\t\t\tif (k & 1)\n\t\t\t\tc ^= e;\n\t\t}\n\t\tcrc_32_tab[i] = c;\n\t}\n}\n\n\nvoid\nupdate_crc(uint8_t *p, uint32_t len, uint32_t *crc)\n{\n\tuint32_t t;\n\n\tt = *crc ^ 0xFFFFFFFFUL;\n\twhile (len--) {\n\t\tt = crc_32_tab[(t ^ *p++) & 0xff] ^ (t >> 8);\n\t}\n\t*crc = t ^ 0xFFFFFFFFUL;\n}\n\n\nuint32_t\nget_crc(uint8_t *p, uint32_t len)\n{\n\tuint32_t crc;\n\n\tcrc = 0;\n\tupdate_crc(p ,len , &crc);\n\treturn crc;\n}\n\n\nint\nstr2u32(char *arg, uint32_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err)) {\n\t\treturn -1;\n\t}\n\n\t*val = t;\n\treturn 0;\n}\n\n\nint\nstr2u16(char *arg, uint16_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err) || (t >= 0x10000)) {\n\t\treturn -1;\n\t}\n\n\t*val = t & 0xFFFF;\n\treturn 0;\n}\n\n\nstruct cpx_board *\nfind_board(char *model){\n\tstruct cpx_board *board;\n\tstruct cpx_board *tmp;\n\n\tboard = NULL;\n\tfor (tmp = boards; tmp->model != NULL; tmp++){\n\t\tif (strcasecmp(model, tmp->model) == 0) {\n\t\t\tboard = tmp;\n\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn board;\n}\n\n\nint\nget_file_crc(struct fw_block *ff)\n{\n\tFILE *f;\n\tuint8_t buf[FILE_BUF_LEN];\n\tuint32_t readlen = sizeof(buf);\n\tint res = -1;\n\tsize_t len;\n\n\tif ((ff->flags & BLOCK_FLAG_HAVEHDR) == 0) {\n\t\tres = 0;\n\t\tgoto out;\n\t}\n\n\terrno = 0;\n\tf = fopen(ff->name,\"r\");\n\tif (errno) {\n\t\terrmsg(1,\"unable to open file %s\", ff->name);\n\t\tgoto out;\n\t}\n\n\tff->crc = 0;\n\tlen = ff->size;\n\twhile (len > 0) {\n\t\tif (len < readlen)\n\t\t\treadlen = len;\n\n\t\terrno = 0;\n\t\tfread(buf, readlen, 1, f);\n\t\tif (errno) {\n\t\t\terrmsg(1,\"unable to read from file %s\",\tff->name);\n\t\t\tgoto out_close;\n\t\t}\n\n\t\tupdate_crc(buf, readlen, &ff->crc);\n\t\tlen -= readlen;\n\t}\n\n\tres = 0;\n\nout_close:\n\tfclose(f);\nout:\n\treturn res;\n}\n\n\nint\nprocess_files(void)\n{\n\tstruct fw_block *b;\n\tstruct stat st;\n\tint i;\n\n\tfor (i = 0; i < fw_num_blocks; i++) {\n\t\tb = &fw_blocks[i];\n\t\tif ((b->addr + b->blocklen) > flash_size) {\n\t\t\terrmsg(0, \"block at 0x%08X is too big\", b->addr);\n\t\t\treturn -1;\n\t\t}\n\t\tif (b->name == NULL)\n\t\t\tcontinue;\n\n\t\tif (stat(b->name, &st) < 0) {\n\t\t\terrmsg(0, \"stat failed on %s\",b->name);\n\t\t\treturn -1;\n\t\t}\n\t\tif (b->blocklen == 0) {\n\t\t\tb->blocklen = flash_size - b->addr;\n\t\t}\n\t\tif (st.st_size > b->blocklen) {\n\t\t\terrmsg(0,\"file %s is too big\",b->name);\n\t\t\treturn -1;\n\t\t}\n\n\t\tb->size = st.st_size;\n\t}\n\n\treturn 0;\n}\n\n\nint\nprocess_partitions(void)\n{\n\tstruct mylo_partition *part;\n\tint i;\n\n\tfor (i = 0; i < fw_num_partitions; i++) {\n\t\tpart = &fw_parts[i].mylo;\n\n\t\tif (part->addr > flash_size) {\n\t\t\terrmsg(0, \"invalid partition at 0x%08X\", part->addr);\n\t\t\treturn -1;\n\t\t}\n\n\t\tif ((part->addr + part->size) > flash_size) {\n\t\t\terrmsg(0, \"partition at 0x%08X is too big\", part->addr);\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\n/*\n * routines to write data to the output file\n */\nint\nwrite_out_data(FILE *outfile, uint8_t *data, size_t len, uint32_t *crc)\n{\n\terrno = 0;\n\n\tfwrite(data, len, 1, outfile);\n\tif (errno) {\n\t\terrmsg(1,\"unable to write output file\");\n\t\treturn -1;\n\t}\n\n\tif (crc) {\n\t\tupdate_crc(data, len, crc);\n\t}\n\n\treturn 0;\n}\n\n\nint\nwrite_out_desc(FILE *outfile, struct mylo_fw_blockdesc *desc, uint32_t *crc)\n{\n\treturn write_out_data(outfile, (uint8_t *)desc,\n\t\tsizeof(*desc), crc);\n}\n\n\nint\nwrite_out_padding(FILE *outfile, size_t len, uint8_t padc, uint32_t *crc)\n{\n\tuint8_t buff[512];\n\tsize_t  buflen = sizeof(buff);\n\n\tmemset(buff, padc, buflen);\n\n\twhile (len > 0) {\n\t\tif (len < buflen)\n\t\t\tbuflen = len;\n\n\t\tif (write_out_data(outfile, buff, buflen, crc))\n\t\t\treturn -1;\n\n\t\tlen -= buflen;\n\t}\n\n\treturn 0;\n}\n\n\nint\nwrite_out_file(FILE *outfile, struct fw_block *block, uint32_t *crc)\n{\n\tchar buff[FILE_BUF_LEN];\n\tsize_t  buflen = sizeof(buff);\n\tFILE *f;\n\tsize_t len;\n\n\terrno = 0;\n\n\tif (block->name == NULL) {\n\t\treturn 0;\n\t}\n\n\tif ((block->flags & BLOCK_FLAG_HAVEHDR) != 0) {\n\t\tstruct mylo_partition_header ph;\n\n\t\tif (get_file_crc(block) != 0)\n\t\t        return -1;\n\n\t\tph.crc = HOST_TO_LE32(block->crc);\n\t\tph.len = HOST_TO_LE32(block->size);\n\n\t\tif (write_out_data(outfile, (uint8_t *)&ph, sizeof(ph), crc) != 0)\n\t\t\treturn -1;\n\t}\n\n\tf = fopen(block->name,\"r\");\n\tif (errno) {\n\t\terrmsg(1,\"unable to open file: %s\", block->name);\n\t\treturn -1;\n\t}\n\n\tlen = block->size;\n\twhile (len > 0) {\n\t\tif (len < buflen)\n\t\t\tbuflen = len;\n\n\t\t/* read data from source file */\n\t\terrno = 0;\n\t\tfread(buff, buflen, 1, f);\n\t\tif (errno != 0) {\n\t\t\terrmsg(1,\"unable to read from file: %s\",block->name);\n\t\t\treturn -1;\n\t\t}\n\n\t\tif (write_out_data(outfile, buff, buflen, crc) != 0)\n\t\t\treturn -1;\n\n\t\tlen -= buflen;\n\t}\n\n\tfclose(f);\n\n\t/* align next block on a 4 byte boundary */\n\tlen = ALIGN(len,4) - block->size;\n\tif (write_out_padding(outfile, len, 0xFF, crc))\n\t\treturn -1;\n\n\tdbgmsg(1,\"file %s written out\", block->name);\n\treturn 0;\n}\n\n\nint\nwrite_out_header(FILE *outfile, uint32_t *crc)\n{\n\tstruct mylo_fw_header hdr;\n\n\tmemset(&hdr, 0, sizeof(hdr));\n\n\thdr.magic = HOST_TO_LE32(MYLO_MAGIC_FIRMWARE);\n\thdr.crc = HOST_TO_LE32(fw_header.crc);\n\thdr.vid = HOST_TO_LE16(fw_header.vid);\n\thdr.did = HOST_TO_LE16(fw_header.did);\n\thdr.svid = HOST_TO_LE16(fw_header.svid);\n\thdr.sdid = HOST_TO_LE16(fw_header.sdid);\n\thdr.rev = HOST_TO_LE32(fw_header.rev);\n\thdr.fwhi = HOST_TO_LE32(fw_header.fwhi);\n\thdr.fwlo = HOST_TO_LE32(fw_header.fwlo);\n\thdr.flags = HOST_TO_LE32(fw_header.flags);\n\n\tif (fseek(outfile, 0, SEEK_SET) != 0) {\n\t\terrmsg(1,\"fseek failed on output file\");\n\t\treturn -1;\n\t}\n\n\treturn write_out_data(outfile, (uint8_t *)&hdr, sizeof(hdr), crc);\n}\n\n\nint\nwrite_out_partitions(FILE *outfile, uint32_t *crc)\n{\n\tstruct mylo_partition_table p;\n\tchar part_names[MYLO_MAX_PARTITIONS][PART_NAME_LEN];\n\tint ret;\n\tint i;\n\n\tif (fw_num_partitions == 0)\n\t\treturn 0;\n\n\tmemset(&p, 0, sizeof(p));\n\tmemset(part_names, 0, sizeof(part_names));\n\n\tp.magic = HOST_TO_LE32(MYLO_MAGIC_PARTITIONS);\n\tfor (i = 0; i < fw_num_partitions; i++) {\n\t\tstruct mylo_partition *mp;\n\t\tstruct fw_part *fp;\n\n\t\tmp = &p.partitions[i];\n\t\tfp = &fw_parts[i];\n\t\tmp->flags = HOST_TO_LE16(fp->mylo.flags);\n\t\tmp->type = HOST_TO_LE16(PARTITION_TYPE_USED);\n\t\tmp->addr = HOST_TO_LE32(fp->mylo.addr);\n\t\tmp->size = HOST_TO_LE32(fp->mylo.size);\n\t\tmp->param = HOST_TO_LE32(fp->mylo.param);\n\n\t\tmemcpy(part_names[i], fp->name, PART_NAME_LEN);\n\t}\n\n\tret = write_out_data(outfile, (uint8_t *)&p, sizeof(p), crc);\n\tif (ret)\n\t\treturn ret;\n\n\tret = write_out_data(outfile, (uint8_t *)part_names, sizeof(part_names),\n\t\t\t\tcrc);\n\treturn ret;\n}\n\n\nint\nwrite_out_blocks(FILE *outfile, uint32_t *crc)\n{\n\tstruct mylo_fw_blockdesc desc;\n\tstruct fw_block *b;\n\tuint32_t dlen;\n\tint i;\n\n\t/*\n\t * if at least one partition specified, write out block descriptor\n\t * for the partition table\n\t */\n\tif (fw_num_partitions > 0) {\n\t\tdesc.type = HOST_TO_LE32(FW_DESC_TYPE_USED);\n\t\tdesc.addr = HOST_TO_LE32(board->part_offset);\n\t\tdesc.dlen = HOST_TO_LE32(sizeof(struct mylo_partition_table) +\n\t\t\t\t\t(MYLO_MAX_PARTITIONS * PART_NAME_LEN));\n\t\tdesc.blen = HOST_TO_LE32(board->part_size);\n\n\t\tif (write_out_desc(outfile, &desc, crc) != 0)\n\t\t        return -1;\n\t}\n\n\t/*\n\t * write out block descriptors for each files\n\t */\n\tfor (i = 0; i < fw_num_blocks; i++) {\n\t\tb = &fw_blocks[i];\n\n\t\t/* detect block size */\n\t\tdlen = b->size;\n\t\tif ((b->flags & BLOCK_FLAG_HAVEHDR) != 0) {\n\t\t\tdlen += sizeof(struct mylo_partition_header);\n\t\t}\n\n\t\t/* round up to 4 bytes */\n\t\tdlen = ALIGN(dlen, 4);\n\n\t\t/* setup the descriptor */\n\t\tdesc.type = HOST_TO_LE32(FW_DESC_TYPE_USED);\n\t\tdesc.addr = HOST_TO_LE32(b->addr);\n\t\tdesc.dlen = HOST_TO_LE32(dlen);\n\t\tdesc.blen = HOST_TO_LE32(b->blocklen);\n\n\t\tif (write_out_desc(outfile, &desc, crc) != 0)\n\t\t\treturn -1;\n\t}\n\n\t/*\n\t * write out the null block descriptor\n\t */\n\tmemset(&desc, 0, sizeof(desc));\n\tif (write_out_desc(outfile, &desc, crc) != 0)\n\t\treturn -1;\n\n\tif (write_out_partitions(outfile, crc) != 0)\n\t\treturn -1;\n\n\t/*\n\t * write out data for each blocks\n\t */\n\tfor (i = 0; i < fw_num_blocks; i++) {\n\t\tb = &fw_blocks[i];\n\t\tif (write_out_file(outfile, b, crc) != 0)\n\t\t        return -1;\n\t}\n\n\treturn 0;\n}\n\n\n/*\n * argument parsing\n */\nint\nparse_arg(char *arg, char *buf, char *argv[])\n{\n\tint res = 0;\n\tsize_t argl;\n\tchar *tok;\n\tchar **ap = &buf;\n\tint i;\n\n\tif ((arg == NULL)) {\n\t\t/* invalid argument string */\n\t\treturn -1;\n\t}\n\n\targl = strlen(arg);\n\tif (argl == 0) {\n\t\t/* no arguments */\n\t\treturn res;\n\t}\n\n\tif (argl >= MAX_ARG_LEN) {\n\t\t/* argument is too long */\n\t\targl = MAX_ARG_LEN-1;\n\t}\n\n\tmemset(argv, 0, MAX_ARG_COUNT * sizeof(void *));\n\tmemcpy(buf, arg, argl);\n\tbuf[argl] = '\\0';\n\n\tfor (i = 0; i < MAX_ARG_COUNT; i++) {\n\t\ttok = strsep(ap, \":\");\n\t\tif (tok == NULL) {\n\t\t\tbreak;\n\t\t}\n#if 0\n\t\telse if (tok[0] == '\\0') {\n\t\t\tbreak;\n\t\t}\n#endif\n\t\targv[i] = tok;\n\t\tres++;\n\t}\n\n\treturn res;\n}\n\n\nint\nrequired_arg(char c, char *arg)\n{\n\tif ((optarg != NULL) && (*arg == '-')){\n\t\terrmsg(0,\"option %c requires an argument\\n\", c);\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\n\nint\nis_empty_arg(char *arg)\n{\n\tint ret = 1;\n\tif (arg != NULL) {\n\t\tif (*arg) ret = 0;\n\t};\n\treturn ret;\n}\n\n\nint\nparse_opt_flags(char ch, char *arg)\n{\n\tif (required_arg(ch, arg)) {\n\t\tgoto err_out;\n\t}\n\n\tif (str2u32(arg, &fw_header.flags) != 0) {\n\t\terrmsg(0,\"invalid firmware flags: %s\", arg);\n\t\tgoto err_out;\n\t}\n\n\tdbgmsg(1, \"firmware flags set to %X bytes\", fw_header.flags);\n\n\treturn 0;\n\nerr_out:\n\treturn -1;\n}\n\n\nint\nparse_opt_size(char ch, char *arg)\n{\n\tif (required_arg(ch, arg)) {\n\t\tgoto err_out;\n\t}\n\n\tif (str2u32(arg, &flash_size) != 0) {\n\t\terrmsg(0,\"invalid flash size: %s\", arg);\n\t\tgoto err_out;\n\t}\n\n\tdbgmsg(1, \"flash size set to %d bytes\", flash_size);\n\n\treturn 0;\n\nerr_out:\n\treturn -1;\n}\n\n\nint\nparse_opt_id(char ch, char *arg)\n{\n\tchar buf[MAX_ARG_LEN];\n\tchar *argv[MAX_ARG_COUNT];\n\tint argc;\n\tchar *p;\n\n\tif (required_arg(ch, arg)) {\n\t\tgoto err_out;\n\t}\n\n\targc = parse_arg(arg, buf, argv);\n\n\t/* processing vendor ID*/\n\tp = argv[0];\n\tif (is_empty_arg(p)) {\n\t\terrmsg(0,\"vendor id is missing from -%c %s\",ch, arg);\n\t\tgoto err_out;\n\t} else if (str2u16(p, &fw_header.vid) != 0) {\n\t\terrmsg(0,\"invalid vendor id: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\tdbgmsg(1, \"vendor id is set to 0x%04X\", fw_header.vid);\n\n\t/* processing device ID*/\n\tp = argv[1];\n\tif (is_empty_arg(p)) {\n\t\terrmsg(0,\"device id is missing from -%c %s\",ch, arg);\n\t\tgoto err_out;\n\t} else if (str2u16(p, &fw_header.did) != 0) {\n\t\terrmsg(0,\"invalid device id: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\tdbgmsg(1, \"device id is set to 0x%04X\", fw_header.did);\n\n\t/* processing sub vendor ID*/\n\tp = argv[2];\n\tif (is_empty_arg(p)) {\n\t\tfw_header.svid = fw_header.vid;\n\t} else if (str2u16(p, &fw_header.svid) != 0) {\n\t\terrmsg(0,\"invalid sub vendor id: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\tdbgmsg(1, \"sub vendor id is set to 0x%04X\", fw_header.svid);\n\n\t/* processing device ID*/\n\tp = argv[3];\n\tif (is_empty_arg(p)) {\n\t\tfw_header.sdid = fw_header.did;\n\t} else if (str2u16(p, &fw_header.sdid) != 0) {\n\t\terrmsg(0,\"invalid sub device id: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\tdbgmsg(1, \"sub device id is set to 0x%04X\", fw_header.sdid);\n\n\t/* processing revision */\n\tp = argv[4];\n\tif (is_empty_arg(p)) {\n\t\tfw_header.rev = 0;\n\t} else if (str2u32(arg, &fw_header.rev) != 0) {\n\t\terrmsg(0,\"invalid revision number: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\tdbgmsg(1, \"board revision is set to 0x%08X\", fw_header.rev);\n\n\treturn 0;\n\nerr_out:\n\treturn -1;\n}\n\n\nint\nparse_opt_block(char ch, char *arg)\n{\n\tchar buf[MAX_ARG_LEN];\n\tchar *argv[MAX_ARG_COUNT];\n\tint argc;\n\tstruct fw_block *b;\n\tchar *p;\n\n\tif (required_arg(ch, arg)) {\n\t\tgoto err_out;\n\t}\n\n\tif (fw_num_blocks >= MAX_FW_BLOCKS) {\n\t\terrmsg(0,\"too many blocks specified\");\n\t\tgoto err_out;\n\t}\n\n\targc = parse_arg(arg, buf, argv);\n\tdbgmsg(1,\"processing block option %s, count %d\", arg, argc);\n\n\tb = &fw_blocks[fw_num_blocks++];\n\n\t/* processing block address */\n\tp = argv[0];\n\tif (is_empty_arg(p)) {\n\t\terrmsg(0,\"no block address specified in %s\", arg);\n\t\tgoto err_out;\n\t} else if (str2u32(p, &b->addr) != 0) {\n\t\terrmsg(0,\"invalid block address: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\t/* processing block length */\n\tp = argv[1];\n\tif (is_empty_arg(p)) {\n\t\terrmsg(0,\"no block length specified in %s\", arg);\n\t\tgoto err_out;\n\t} else if (str2u32(p, &b->blocklen) != 0) {\n\t\terrmsg(0,\"invalid block length: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\tif (argc < 3) {\n\t\tdbgmsg(1,\"empty block %s\", arg);\n\t\tgoto success;\n\t}\n\n\t/* processing flags */\n\tp = argv[2];\n\tif (is_empty_arg(p) == 0) {\n\t\tfor ( ; *p != '\\0'; p++) {\n\t\t\tswitch (*p) {\n\t\t\tcase 'h':\n\t\t\t\tb->flags |= BLOCK_FLAG_HAVEHDR;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\terrmsg(0, \"invalid block flag \\\"%c\\\"\", *p);\n\t\t\t\tgoto err_out;\n\t\t\t}\n\t\t}\n\t}\n\n\t/* processing file name */\n\tp = argv[3];\n\tif (is_empty_arg(p)) {\n\t\terrmsg(0,\"file name missing in %s\", arg);\n\t\tgoto err_out;\n\t}\n\n\tb->name = strdup(p);\n\tif (b->name == NULL) {\n\t\terrmsg(0,\"not enough memory\");\n\t\tgoto err_out;\n\t}\n\nsuccess:\n\n\treturn 0;\n\nerr_out:\n\treturn -1;\n}\n\n\nint\nparse_opt_partition(char ch, char *arg)\n{\n\tchar buf[MAX_ARG_LEN];\n\tchar *argv[MAX_ARG_COUNT];\n\tint argc;\n\tchar *p;\n\tstruct mylo_partition *part;\n\tstruct fw_part *fp;\n\n\tif (required_arg(ch, arg)) {\n\t\tgoto err_out;\n\t}\n\n\tif (fw_num_partitions >= MYLO_MAX_PARTITIONS) {\n\t\terrmsg(0, \"too many partitions specified\");\n\t\tgoto err_out;\n\t}\n\n\tfp = &fw_parts[fw_num_partitions++];\n\tpart = &fp->mylo;\n\n\targc = parse_arg(arg, buf, argv);\n\n\t/* processing partition address */\n\tp = argv[0];\n\tif (is_empty_arg(p)) {\n\t\terrmsg(0,\"partition address missing in -%c %s\",ch, arg);\n\t\tgoto err_out;\n\t} else if (str2u32(p, &part->addr) != 0) {\n\t\terrmsg(0,\"invalid partition address: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\t/* processing partition size */\n\tp = argv[1];\n\tif (is_empty_arg(p)) {\n\t\terrmsg(0,\"partition size missing in -%c %s\",ch, arg);\n\t\tgoto err_out;\n\t} else if (str2u32(p, &part->size) != 0) {\n\t\terrmsg(0,\"invalid partition size: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\t/* processing partition flags */\n\tp = argv[2];\n\tif (is_empty_arg(p) == 0) {\n\t\tfor ( ; *p != '\\0'; p++) {\n\t\t\tswitch (*p) {\n\t\t\tcase 'a':\n\t\t\t\tpart->flags |= PARTITION_FLAG_ACTIVE;\n\t\t\t\tbreak;\n\t\t\tcase 'p':\n\t\t\t\tpart->flags |= PARTITION_FLAG_PRELOAD;\n\t\t\t\tbreak;\n\t\t\tcase 'l':\n\t\t\t\tpart->flags |= PARTITION_FLAG_LZMA;\n\t\t\t\tbreak;\n\t\t\tcase 'h':\n\t\t\t\tpart->flags |= PARTITION_FLAG_HAVEHDR;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\terrmsg(0, \"invalid partition flag \\\"%c\\\"\", *p);\n\t\t\t\tgoto err_out;\n\t\t\t}\n\t\t}\n\t}\n\n\t/* processing partition parameter */\n\tp = argv[3];\n\tif (is_empty_arg(p)) {\n\t\t/* set default partition parameter */\n\t\tpart->param = 0;\n\t} else if (str2u32(p, &part->param) != 0) {\n\t\terrmsg(0,\"invalid partition parameter: %s\", p);\n\t\tgoto err_out;\n\t}\n\n\tp = argv[4];\n\tif (is_empty_arg(p)) {\n\t\t/* set default partition parameter */\n\t\tfp->name[0] = '\\0';\n\t} else {\n\t\tstrncpy(fp->name, p, PART_NAME_LEN);\n\t}\n\n#if 1\n\tif (part->size == 0) {\n\t\tpart->size = flash_size - part->addr;\n\t}\n\n\t/* processing file parameter */\n\tp = argv[5];\n\tif (is_empty_arg(p) == 0) {\n\t\tstruct fw_block *b;\n\n\t\tif (fw_num_blocks == MAX_FW_BLOCKS) {\n\t\t\terrmsg(0,\"too many blocks specified\", p);\n\t\t\tgoto err_out;\n\t\t}\n\t\tb = &fw_blocks[fw_num_blocks++];\n\t\tb->name = strdup(p);\n\t\tb->addr = part->addr;\n\t\tb->blocklen = part->size;\n\t\tif (part->flags & PARTITION_FLAG_HAVEHDR) {\n\t\t\tb->flags |= BLOCK_FLAG_HAVEHDR;\n\t\t}\n\t}\n#endif\n\n\treturn 0;\n\nerr_out:\n\treturn -1;\n}\n\n\nint\nparse_opt_board(char ch, char *arg)\n{\n\tif (required_arg(ch, arg)) {\n\t\tgoto err_out;\n\t}\n\n\tboard = find_board(arg);\n\tif (board == NULL){\n\t\terrmsg(0,\"invalid/unknown board specified: %s\", arg);\n\t\tgoto err_out;\n\t}\n\n\tfw_header.vid = board->vid;\n\tfw_header.did = board->did;\n\tfw_header.svid = board->svid;\n\tfw_header.sdid = board->sdid;\n\n\tflash_size = board->flash_size;\n\n\treturn 0;\n\nerr_out:\n\treturn -1;\n}\n\n\nint\nparse_opt_rev(char ch, char *arg)\n{\n\tif (required_arg(ch, arg)) {\n\t\treturn -1;\n\t}\n\n\tif (str2u32(arg, &fw_header.rev) != 0) {\n\t\terrmsg(0,\"invalid revision number: %s\", arg);\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\n\n/*\n * main\n */\nint\nmain(int argc, char *argv[])\n{\n\tint optinvalid = 0;   /* flag for invalid option */\n\tint c;\n\tint res = EXIT_FAILURE;\n\n\tFILE  *outfile;\n\tuint32_t crc;\n\n\tprogname=basename(argv[0]);\n\n\tmemset(&fw_header, 0, sizeof(fw_header));\n\n\t/* init header defaults */\n\tfw_header.vid = VENID_COMPEX;\n\tfw_header.did = DEVID_COMPEX_WP54G;\n\tfw_header.svid = VENID_COMPEX;\n\tfw_header.sdid = DEVID_COMPEX_WP54G;\n\tfw_header.fwhi = 0x20000;\n\tfw_header.fwlo = 0x20000;\n\tfw_header.flags = 0;\n\n\topterr = 0;  /* could not print standard getopt error messages */\n\twhile ((c = getopt(argc, argv, \"b:B:f:hi:p:r:s:v\")) != -1) {\n\t\toptinvalid = 0;\n\t\tswitch (c) {\n\t\tcase 'b':\n\t\t\toptinvalid = parse_opt_block(c,optarg);\n\t\t\tbreak;\n\t\tcase 'B':\n\t\t\toptinvalid = parse_opt_board(c,optarg);\n\t\t\tbreak;\n\t\tcase 'f':\n\t\t\toptinvalid = parse_opt_flags(c,optarg);\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\toptinvalid = parse_opt_id(c,optarg);\n\t\t\tbreak;\n\t\tcase 'p':\n\t\t\toptinvalid = parse_opt_partition(c,optarg);\n\t\t\tbreak;\n\t\tcase 'r':\n\t\t\toptinvalid = parse_opt_rev(c,optarg);\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\toptinvalid = parse_opt_size(c,optarg);\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tverblevel++;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\toptinvalid = 1;\n\t\t\tbreak;\n\t\t}\n\t\tif (optinvalid != 0 ){\n\t\t\terrmsg(0, \"invalid option: -%c\", optopt);\n\t\t\tgoto out;\n\t\t}\n\t}\n\n\tif (optind == argc) {\n\t\terrmsg(0, \"no output file specified\");\n\t\tgoto out;\n\t}\n\n\tofname = argv[optind++];\n\n\tif (optind < argc) {\n\t\terrmsg(0, \"invalid option: %s\", argv[optind]);\n\t\tgoto out;\n\t}\n\n\tif (!board) {\n\t\terrmsg(0, \"no board specified\");\n\t\tgoto out;\n\t}\n\n\tif (flash_size == 0) {\n\t\terrmsg(0, \"no flash size specified\");\n\t\tgoto out;\n\t}\n\n\tif (process_files() != 0) {\n\t\tgoto out;\n\t}\n\n\tif (process_partitions() != 0) {\n\t\tgoto out;\n\t}\n\n\toutfile = fopen(ofname, \"w\");\n\tif (outfile == NULL) {\n\t\terrmsg(1, \"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto out;\n\t}\n\n\tcrc = 0;\n\tinit_crc_table();\n\n\tif (write_out_header(outfile, &crc) != 0)\n\t\tgoto out_flush;\n\n\tif (write_out_blocks(outfile, &crc) != 0)\n\t\tgoto out_flush;\n\n\tfw_header.crc = crc;\n\tif (write_out_header(outfile, NULL) != 0)\n\t\tgoto out_flush;\n\n\tdbgmsg(1,\"Firmware file %s completed.\", ofname);\n\n\tres = EXIT_SUCCESS;\n\nout_flush:\n\tfflush(outfile);\n\tfclose(outfile);\n\tif (res != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\nout:\n\treturn res;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkplanexfw.c",
    "content": "/*\n *  Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\n#include \"sha1.h\"\n\n#if (__BYTE_ORDER == __BIG_ENDIAN)\n#  define HOST_TO_BE32(x)\t(x)\n#  define BE32_TO_HOST(x)\t(x)\n#else\n#  define HOST_TO_BE32(x)\tbswap_32(x)\n#  define BE32_TO_HOST(x)\tbswap_32(x)\n#endif\n\n\nstruct planex_hdr {\n\tuint8_t\t\tsha1sum[20];\n\tchar\t\tversion[8];\n\tuint8_t\t\tunk1[2];\n\tuint32_t\tdatalen;\n} __attribute__ ((packed));\n\nstruct board_info {\n\tchar\t\t*id;\n\tuint32_t\tseed;\n\tuint8_t\t\tunk[2];\n\tuint32_t\tdatalen;\n};\n\n/*\n * Globals\n */\nstatic char *ifname;\nstatic char *progname;\nstatic char *ofname;\nstatic char *version = \"1.00.00\";\n\nstatic char *board_id;\nstatic struct board_info *board;\n\nstatic struct board_info boards[] = {\n\t{\n\t\t.id\t\t= \"MZK-W04NU\",\n\t\t.seed\t\t= 2,\n\t\t.unk\t\t= {0x04, 0x08},\n\t\t.datalen\t= 0x770000,\n\t}, {\n\t\t.id\t\t= \"MZK-W300NH\",\n\t\t.seed\t\t= 4,\n\t\t.unk\t\t= {0x00, 0x00},\n\t\t.datalen\t= 0x770000,\n\t}, {\n\t\t/* terminating entry */\n\t}\n};\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\nstatic struct board_info *find_board(char *id)\n{\n\tstruct board_info *ret;\n\tstruct board_info *board;\n\n\tret = NULL;\n\tfor (board = boards; board->id != NULL; board++){\n\t\tif (strcasecmp(id, board->id) == 0) {\n\t\t\tret = board;\n\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn ret;\n}\n\nvoid usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct board_info *board;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -B <board>      create image for the board specified with <board>\\n\"\n\"  -i <file>       read input from the file <file>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -v <version>    set image version to <version>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nint main(int argc, char *argv[])\n{\n\tint res = EXIT_FAILURE;\n\tint buflen;\n\tint err;\n\tstruct stat st;\n\tchar *buf;\n\tstruct planex_hdr *hdr;\n\tsha1_context ctx;\n\tuint32_t seed;\n\n\tFILE *outfile, *infile;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"B:i:o:v:h\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'B':\n\t\t\tboard_id = optarg;\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tifname = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tversion = optarg;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (board_id == NULL) {\n\t\tERR(\"no board specified\");\n\t\tgoto err;\n\t}\n\n\tboard = find_board(board_id);\n\tif (board == NULL) {\n\t\tERR(\"unknown board '%s'\", board_id);\n\t\tgoto err;\n\t};\n\n\tif (ifname == NULL) {\n\t\tERR(\"no input file specified\");\n\t\tgoto err;\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\tgoto err;\n\t}\n\n\terr = stat(ifname, &st);\n\tif (err){\n\t\tERRS(\"stat failed on %s\", ifname);\n\t\tgoto err;\n\t}\n\n\tif (st.st_size > board->datalen) {\n\t\tERR(\"file '%s' is too big - max size: 0x%08X (exceeds %lu bytes)\\n\",\n\t\t    ifname, board->datalen, st.st_size - board->datalen);\n\t\tgoto err;\n\t}\n\n\tbuflen = board->datalen + 0x10000;\n\tbuf = malloc(buflen);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto err;\n\t}\n\n\tmemset(buf, 0xff, buflen);\n\thdr = (struct planex_hdr *)buf;\n\n\thdr->datalen = HOST_TO_BE32(board->datalen);\n\thdr->unk1[0] = board->unk[0];\n\thdr->unk1[1] = board->unk[1];\n\n\tsnprintf(hdr->version, sizeof(hdr->version), \"%s\", version);\n\n\tinfile = fopen(ifname, \"r\");\n\tif (infile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for reading\", ifname);\n\t\tgoto err_free;\n\t}\n\n\terrno = 0;\n\tfread(buf +  sizeof(*hdr), st.st_size, 1, infile);\n\tif (errno != 0) {\n\t\tERRS(\"unable to read from file %s\", ifname);\n\t\tgoto err_close_in;\n\t}\n\n\tseed = HOST_TO_BE32(board->seed);\n\tsha1_starts(&ctx);\n\tsha1_update(&ctx, (uchar *) &seed, sizeof(seed));\n\tsha1_update(&ctx, buf + sizeof(*hdr), board->datalen);\n\tsha1_finish(&ctx, hdr->sha1sum);\n\n\toutfile = fopen(ofname, \"w\");\n\tif (outfile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto err_close_in;\n\t}\n\n\terrno = 0;\n\tfwrite(buf, buflen, 1, outfile);\n\tif (errno) {\n\t\tERRS(\"unable to write to file %s\", ofname);\n\t\tgoto err_close_out;\n\t}\n\n\tres = EXIT_SUCCESS;\n\n out_flush:\n\tfflush(outfile);\n\n err_close_out:\n\tfclose(outfile);\n\tif (res != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\n\n err_close_in:\n\tfclose(infile);\n\n err_free:\n\tfree(buf);\n\n err:\n\treturn res;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/mktitanimg.c",
    "content": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <libgen.h>\n#include \"mktitanimg.h\"\n\n\nstruct checksumrecord\n{\n\t\tunsigned int magic;\n        unsigned int    chksum;     /* The checksum for the complete header.\n Excepting the\n                                           checksum block */\n};\n/***************************************************************************\n * void print_help(void)\n ***************************************************************************/\nvoid print_help(void)\n{\n\tstatic char* help_page[]=\n\t{\n\t\t\"mknspimg version 1.0, Texas Instruments, 2004\",\n\t\t\"Syntax:\",\n\t\t\"        mknspimg -o outfile -i image1 image2 -a align1 align2 [-v] [-b] [-p prod_id] [-r rel_id] [-s rel_name] [-f flags]\",\n\t\t\"Example:\",\n\t\t\"        mknspimg -o nsp_image.bin -i kernel.bin files.img -a 0 4096\",\n\t\t\"This generates 'nsp_image.bin' from two input files aligning first to 0 and second to 4096 bytes.\"\n\t};\n\n\tint num_lines = sizeof(help_page)/sizeof(char*);\n\tint i;\n\tfor(i=0; i < num_lines; i++) {\n\t\tprintf(\"%s\\n\", help_page[i]);\n\t}\n}\n\n/***************************************************************************\n * void mknspimg_print_hdr(NSP_IMG_HDR* p_img_hdr)\n ***************************************************************************/\nvoid mknspimg_print_hdr(struct nsp_img_hdr *hdr)\n{\n\tstruct nsp_img_hdr_chksum\t*chksum;\n\tstruct nsp_img_hdr_section_info\t*sect_info;\n\tstruct nsp_img_hdr_sections\t*section;\n\tint i;\n\n\tprintf(\"****************** NSP Image Summary ******************\\n\");\n\tprintf(\"Magic:             0x%x\\n\",\t\thdr->head.magic);\n\tprintf(\"Image Header Size: 0x%x bytes\\n\",\thdr->head.hdr_size);\n\tprintf(\"Total Image Size:  %d bytes\\n\",\t\thdr->head.image_size);\n\tprintf(\"Product ID:        0x%x\\n\",\t\thdr->head.prod_id);\n\tprintf(\"Release ID:        0x%x\\n\",\t\thdr->head.rel_id);\n\tprintf(\"Version ID:        0x%x\\n\",\t\thdr->head.version);\n\n\tprintf(\"Offset Info:       0x%x\\n\",\t\thdr->head.info_offset);\n\tprintf(\"Offset Sect info:  0x%x\\n\",\t\thdr->head.sect_info_offset);\n\tprintf(\"Offset Sections:   0x%x\\n\",\t\thdr->sect_info.sections_offset);\n\n\tchksum=(struct nsp_img_hdr_chksum *)(hdr+hdr->head.chksum_offset);\n\tprintf(\"Header Checksum:   0x%x\\n\",\t\tchksum->hdr_chksum);\n\n\tprintf(\"+++ Section Information +++\\n\");\n\tprintf(\"# of sections:     %u\\n\", hdr->sect_info.num_sects);\n\tsection=&(hdr->sections);\n\tfor(i = 0; i < hdr->sect_info.num_sects; i++, section++) {\n\t\tprintf(\"+++++ Section %d +++++\\n\", i);\n\t\tprintf(\"Total size:  %u bytes\\n\",\tsection->total_size);\n\t\tprintf(\"Raw Size:    %u bytes\\n\",\tsection->raw_size);\n\t\tprintf(\"Offset:      0x%x\\n\",\t\tsection->offset);\n\t\tprintf(\"Type:        0x%x\\n\",\t\tsection->type);\n\t\tprintf(\"Name:        %s\\n\",\t\tsection->name);\n\t}\n\tprintf(\"*******************************************************\\n\");\n}\n\nCMDLINE_CFG\tcmd_line_cfg =\n{\n\t{\n\t\t/*\tMIN\tMAX\tFLAGS\t\t\t\t\tOPTION\t*/\n\t\t{\t2,\t2,\t(CMDLINE_OPTFLAG_ALLOW | CMDLINE_OPTFLAG_MANDAT) },\t/* '-a' align1 align2 */\n\t\t{\t0,\t0,\tCMDLINE_OPTFLAG_ALLOW },\t\t/* '-b' bootstrap */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-c' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-d' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-e' */\n\t\t{\t1,\t1,\tCMDLINE_OPTFLAG_ALLOW },\t\t/* '-f' flags */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-g' */\n\t\t{\t1,\t1,\tCMDLINE_OPTFLAG_ALLOW },\t\t/* '-h' */\n\t\t{\t2,\t2,\t(CMDLINE_OPTFLAG_ALLOW | CMDLINE_OPTFLAG_MANDAT) },\t/* '-i arg1 arg2 ' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-j' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-k' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-l' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-m' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-n' */\n\t\t{\t1,\t1,\t(CMDLINE_OPTFLAG_ALLOW | CMDLINE_OPTFLAG_MANDAT) },\t/* '-o arg' */\n\t\t{\t1,\t1,\tCMDLINE_OPTFLAG_ALLOW },\t\t/* '-p' PROD_ID */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-q' */\n\t\t{\t1,\t1,\tCMDLINE_OPTFLAG_ALLOW },\t\t/* '-r' REL_ID */\n\t\t{\t1,\t1,\tCMDLINE_OPTFLAG_ALLOW },\t\t/* '-s' \"Release XXX.XXX\" */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-t' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-u' */\n\t\t{\t0,\t0,\tCMDLINE_OPTFLAG_ALLOW },\t\t/* '-v' control VERBOSE/NON-VERBOSE mode */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-w' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-x' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* '-y' */\n\t\t{\t0,\t0,\t!CMDLINE_OPTFLAG_ALLOW }\t\t/* '-z' */\n\t},\n\t{\t0,\t\t0,\t!CMDLINE_OPTFLAG_ALLOW },\t\t/* global arguments */\n};\n\n/***************************************************************************\n * int nsp_img_write(void* image, char* file, int padding)\n * Write out the image.\n ***************************************************************************/\nint main(int argc, char* argv[], char* env[])\n{\n\tFILE*\tnsp_image\t= NULL;\n\tint header_version=1;\n\tint\tcmdline_err;\n\tchar*\tcmdline_error_msg;\n\n\tchar*\tfilen_kernel;\n\tchar*\tfilen_files;\n\tchar*\tfilen_out;\n\n\tint\ti,count;\t\t\t/* loop variables */\n\tint\tnum_sects = 2;\t\t\t/* We require exactly two image with -i option\n\t\t\t\t\t\t\t   (see CMDLINE_CFG structure above) */\n\tint\tdesc_count=0;\n\tint\ttotal = 0;\n\n\tint\theader_size=0;\n\tstruct nsp_img_hdr_head\t\t*img_hdr_head;\t/* Start of image header */\n\tstruct nsp_img_hdr_info *img_hdr_info;\n\tstruct nsp_img_hdr_section_info *img_hdr_section_info ;\n\tstruct nsp_img_hdr_sections\t*img_hdr_sections, *section;\t/* Section pointers */\n\t\n\n\t/* Configure the command line. */\n\tcmdline_configure(&cmd_line_cfg);\n\n\t/* Read and parse the command line. */\n\tcmdline_err = cmdline_read(argc, argv);\n\n\t/* Check for parsing errors. */\n\tif(cmdline_err != 0) {\n\t\t/* Get the parse error message */\n\t\tcmdline_error_msg = cmdline_error(cmdline_err);\n\n\t\t/* Print it out */\n\t\tprintf(\"%s\\n\", cmdline_error_msg);\n\n\t\t/* Print our help too */\n\t\tprint_help();\n\t\treturn -1;\n\t}\n\tif(cmdline_getopt_count('h') > 0)\n\t{\n\t\theader_version=atoi(argv[cmdline_getarg(cmdline_getarg_list('h'),0)]);\n\t}\n\t/* Set up arguments */\n\tfilen_kernel\t= argv[cmdline_getarg(cmdline_getarg_list('i'),0)];\n\tfilen_files\t= argv[cmdline_getarg(cmdline_getarg_list('i'),1)];\n\tfilen_out\t= argv[cmdline_getarg(cmdline_getarg_list('o'),0)];\n\t/* Command line arguments have been parsed. Start doing our work. */\n\n\t/* Caculate the header size, and allocate the memory, and assign the sub pointers */\n\theader_size =\tsizeof(struct nsp_img_hdr_head) +\t\t/* This has a single section\n\t\t\t\t\t\t\t\t   desc block already */\n\t\t\t\t(header_version==1?0:4) + \n\t\t\t\tsizeof(struct nsp_img_hdr_info) + \n\t\t\t\tsizeof(struct nsp_img_hdr_section_info) + \n\t\t\tsizeof(struct nsp_img_hdr_sections) * num_sects ;\n\n\timg_hdr_head = (struct nsp_img_hdr_head *)malloc(header_size);\n\tmemset(img_hdr_head, 0x0, header_size);\n\timg_hdr_info = (struct nsp_img_hdr_info*)((char *)img_hdr_head + sizeof(struct nsp_img_hdr_head) + (header_version==1?0:4));\n\timg_hdr_section_info = (struct nsp_img_hdr_section_info*)((char *)img_hdr_info + sizeof(struct nsp_img_hdr_info));\n\timg_hdr_sections = (struct nsp_img_hdr_sections*)((char *)img_hdr_section_info + sizeof(struct nsp_img_hdr_section_info));\n\tsection = img_hdr_sections;\n\tmemset(img_hdr_head, 0xff, (void*)img_hdr_info - (void*)img_hdr_head);\n\t\n\timg_hdr_head->hdr_version = header_version;\n\timg_hdr_head->hdr_size = header_size;\n\timg_hdr_head->info_offset = (void*)img_hdr_info - (void*)img_hdr_head;\n\timg_hdr_head->sect_info_offset = (void*)img_hdr_section_info - (void*)img_hdr_head;\n\t\n\timg_hdr_section_info->num_sects = num_sects;\n\timg_hdr_section_info->sect_size = sizeof(struct nsp_img_hdr_sections);\n\timg_hdr_section_info->sections_offset = (void*)img_hdr_sections - (void*)img_hdr_head;\n\t\n/*\tchksum = (struct nsp_img_hdr_chksum *)\n\t\t\t((unsigned int)image_hdr + header_size - sizeof(struct nsp_img_hdr_chksum));*/\n\n\t/* Open the out file */\n\tnsp_image = fopen(filen_out,\"wb+\");\n\tif(nsp_image==NULL) {\n\t\tprintf(\"ERROR: can't open %s for writing.\\n\", filen_out);\n\t\treturn -1;\n\t}\n\n\t/* Skip image header. We'll come back to it after we've written out the images. */\t\n\tfseek(nsp_image,header_size,SEEK_SET);\n\ttotal = ftell(nsp_image);\n\ttotal = header_size;\n\tprintf(\"total=%x\\n\",total);\n\t{\n\t\tint align;\n\t\tint\tpadding;\n\t\tchar * buf;\n\t\talign = (header_version==1?0x10000:0x4000);\n\t\tif(align==0) {\n\t\t\t/* The user indicated no padding */\n\t\t\tpadding = 0;\n\t\t} else {\n\t\t\t/* Calculate number padding bytes */\n\t\t\tif((total %align) ==0)\n\t\t\t\tpadding=0;\n\t\t\telse\n\t\t\t\tpadding = align - (total % align);\n\t\t}\n\t\tif(padding>0)\n\t\t{\n\t\t\tbuf=malloc(padding);\n\t\t\tmemset(buf, 0xff, padding);\n\t\t\tif(fwrite((void*)buf,1,padding,nsp_image)!=padding) {\n\t\t\t\tprintf(\"ERROR: can't write to %s.\\n\", filen_out);\n\t\t\t\tfree(buf);\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tfree(buf);\n\t\t\t\n\t\t}\n\t\ttotal+=padding;\n\t\t\n\n\t}\n\t/* Write out all specified images (with -i option) */\n\tfor(i=0; i < num_sects; i++) {\n\t\tchar*\tfile_name;\t\t/* input file name */\n\t\tFILE*\tfilep;\t\t\t/* input file pointer */\n\t\tint\tpadding;\t\t/* number of padding bytes to prepend */\n\t\tint\talign;\t\t\t/* align factor from command line */\n\t\tint\tresult;\t\t\t/* intermediate result */\n\t\tchar * buf;\n\n\t\t/* Open the specified image for reading */\n\t\tfile_name\t= argv[cmdline_getarg(cmdline_getarg_list('i'),i)];\n\t\tfilep\t\t= fopen(file_name, \"rb\");\n\t\tif(filep==NULL) {\n\t\t\tprintf(\"ERROR: can't open file %s for reading.\\n\", file_name);\n\t\t\treturn -1;\n\t\t}\n\t\tsection->flags = ~0x00;\n\t\t/* Determine file size */\n\t\tfseek(filep,0,SEEK_END);\n\t\tsection->raw_size=ftell(filep);\n\t\tfseek(filep,0,SEEK_SET);\n\t\tcs_calc_sum(filep,(unsigned long *)&section->chksum,0);\n\t\tfseek(filep,0,SEEK_SET);\n\n\t\t/* Retrieve the alignment constant */\n\t\t/* Set image offset from the beginning of the out file */\n\t\tsection->offset=total;// + padding;\n\n\t\t//total += padding;\n\n\t\t/* Copy the image file into nsp_image */\n\t\tcount = section->raw_size;\n\t\tbuf=malloc(count);\n\t\tresult=fread(buf, 1, count, filep);\n\t\tfwrite(buf, 1, result, nsp_image);\n\t\tfree(buf);\n\t\t\n\t\t/* HACK: This is a hack to get the names and types to the files.\n\t\t\tTODO: Fix this to be a real method */\n\t\tif(i==0){\n\t\t\tsection->type=NSP_IMG_SECTION_TYPE_KERNEL;\n\t\t\tstrncpy(section->name, \"kernel\", 16);\n\t\t} else if(i==1){\n\t\t\tsection->type=NSP_IMG_SECTION_TYPE_FILESYSTEM_ROOT;\n\t\t\tstrncpy(section->name, \"root\", 16);\n\t\t}\n\n\t\t/* Account for the total */\n\t\talign\t=  strtoul(argv[cmdline_getarg(cmdline_getarg_list('a'),i)],NULL,0);\n\t\tif(i==0){\n\t\t\tif(align==0 || (((section->raw_size+ section->offset)%align)==0))\n\t\t\t\tpadding=0;\n\t\t\telse\n\t\t\t\tpadding = align - ((section->raw_size+ section->offset) % align);\n\n\t\t\t\tsection->total_size=section->raw_size + padding;\n\t\t}\n\t\telse{\n\t\t\t#define EXTRA_BLOCK 0x10000\n\t\t\tunsigned int squash_padding;\n\t\t\tsquash_padding = EXTRA_BLOCK - section->raw_size % EXTRA_BLOCK;\n\t\t\tbuf=malloc(EXTRA_BLOCK + 4);\n\t\t\tmemset(buf, 0, squash_padding);\n\t\t\tfwrite(buf, 1, squash_padding, nsp_image);\n\t\t\tmemset(buf, 0, EXTRA_BLOCK + 4);\n\t\t\t*((unsigned int *)buf)=0xdec0adde;\n\t\t\t*((unsigned int *)(buf+EXTRA_BLOCK))=0xdec0adde;\n\t\t\tfwrite(buf, 1, EXTRA_BLOCK+4, nsp_image);\n\t\t\tfree(buf);\n\t\t\t\n\t\t\tif(align==0 || (((section->raw_size + (EXTRA_BLOCK + 4 + squash_padding)) %align)==0))\n\t\t\t\tpadding=0;\n\t\t\telse\n\t\t\t\tpadding = align - ((section->raw_size + (EXTRA_BLOCK + 4 + squash_padding)) % align);\n\t\t\tsection->total_size=section->raw_size + (EXTRA_BLOCK + 4 + squash_padding) + padding;\n\t\t}\n\t\tif(padding>0){\n\t\t\tbuf=malloc(padding);\n\t\t\tmemset(buf, 0xff, padding);\n\t\t\tfwrite(buf, 1, padding, nsp_image);\n\t\t\tfree(buf);\n\t\t}\n\t\tprintf(\"*****padding is %d\\ttotal_size=%d\\traw_size=%d\\n\",padding, section->total_size, section->raw_size);\n\n\t\t//total += section->raw_size;\n\t\ttotal = section->total_size + section->offset;\n\t\tprintf(\"total=0x%x\\n\",total);\n\t\t/* Close the input file */\n\t\tfclose(filep);\n\n\t\t/* Move the section pointer to the next slot */\n\t\tsection++;\n\t}\n\n\t/* Take care of the NSP image header fields */\n\n\t/* head fields */\n\timg_hdr_head->magic\t\t= NSP_IMG_MAGIC_NUMBER;\n\timg_hdr_head->boot_offset\t= img_hdr_sections->offset;\n\timg_hdr_head->flags\t\t= ~0x00;\t\t\t/* Set to all 1's */\n\n\tif(cmdline_getopt_count('b'))\n\t\timg_hdr_head->flags\t&= ~(NSP_IMG_FLAG_FAILBACK_5 | NSP_IMG_FLAG_FAILBACK_1);\n\n\tif(cmdline_getopt_count('f'))\n\t\timg_hdr_head->flags\t= strtoul(argv[cmdline_getarg(cmdline_getarg_list('f'),0)], 0, 16);\n\n#if 0\n\timg_hdr_head->hdr_version\t= 2;\n\timg_hdr_head->hdr_size\t= header_size;\n#endif\n\n\tif(cmdline_getopt_count('p'))\n\t\timg_hdr_head->prod_id\t\t= strtoul(argv[cmdline_getarg(cmdline_getarg_list('p'),0)], 0, 16);\n\telse\n\t\timg_hdr_head->prod_id\t\t= 0x4C575943;\n\n\tif(cmdline_getopt_count('r'))\n\t\timg_hdr_head->rel_id\t\t= strtoul(argv[cmdline_getarg(cmdline_getarg_list('r'),0)], 0, 0);\n\telse\n\t\timg_hdr_head->rel_id\t\t= 0x10203040;\n\n\tif(cmdline_getopt_count('s'))\n\t\timg_hdr_head->version\t\t= strtoul(argv[cmdline_getarg(cmdline_getarg_list('s'),0)], 0, 0);\n\telse\n\t\timg_hdr_head->version\t\t= 0x0b040000;\n\timg_hdr_head->image_size\t= total;\n#if 0\n\timg_hdr_head->info_offset\t= (unsigned int)(&(image_hdr->info)) -\n\t\t\t\t\t\t(unsigned int)image_hdr;\n\timg_hdr_head->sect_info_offset= (unsigned int)(&(image_hdr->sect_info)) -\n\t\t\t\t\t\t(unsigned int)image_hdr;\n#endif\n//\timage_hdr->head.chksum_offset\t= (unsigned int)chksum - (unsigned int)image_hdr;\n\timg_hdr_head->chksum_offset = 0xffffffff;\n//\timage_hdr->head.pad1 = 0xffffffff;\n\t/* info fields */\n\t/* TODO: Fix. Do nothing yet */\n//\tstrncpy(nsp_img_hdr.id.prod_info,NSP_PRODINFO_STRING,sizeof(NSP_PRODINFO_STRING));\n\tstrcpy(img_hdr_info->image_filename, (const char *)basename(filen_out));\n\t/* section fields */\n#if 0\n\timg_hdr_section_info->num_sects=\t\tnum_sects;\n\timg_hdr_section_info->sect_size=\t\tsizeof(struct nsp_img_hdr_sections);\n\timg_hdr_section_info->sections_offset=\t(unsigned int)(&(image_hdr->sections)) -\n\t\t\t\t\t\t(unsigned int)image_hdr;\n#endif\n\n\t/* Calculate checksum(s) */\n#if 0\n\tchksum->hdr_chksum = cs_calc_buf_sum((char*)image_hdr,\n\t\t\theader_size - sizeof(struct nsp_img_hdr_chksum));\n#endif\n\t/* Write out the NSP header. */\n\tfseek(nsp_image,0,SEEK_SET);\n\tcount = fwrite((void*)img_hdr_head, header_size, 1, nsp_image);\n\tif(count!=1) {\n\t\tprintf(\"ERROR: can't write to %s.\\n\", filen_out);\n\t\treturn -1;\n\t}\n\n\t/* Check if -v option was specified (no arg needed) */\n\tif(cmdline_getopt_count('v') > 0)\n\t{\n\t\tstruct nsp_img_hdr_head\thead;\n\t\tstruct nsp_img_hdr\t*hdr;\n\n\t\t/* Rewind the file back to the beginning */\n\t\tfseek(nsp_image,0,SEEK_SET);\n\n\t\t/* Read header from the file */\n\t\tfread((void*)&head, sizeof(struct nsp_img_hdr_head),\n\t\t\t\t1, nsp_image);\n\n\t\t/* Get memory to store the complete header */\n\t\thdr = (struct nsp_img_hdr *)malloc(head.hdr_size);\n\n\t\t/* Read header from the file */\n\t\tfseek(nsp_image,0,SEEK_SET);\n\t\tfread((void*)hdr, head.hdr_size, 1, nsp_image);\n\n\t\t/* Print it out */\n\t\tmknspimg_print_hdr(hdr);\n\t\tprintf(\"Generated total %d bytes\\n\",total);\n\t\tfree(hdr);\n\t}\n\n\tfree(img_hdr_head);\n\n      {\n\t  struct checksumrecord cr;\n      cr.magic=CKSUM_MAGIC_NUMBER;\n      cs_calc_sum(nsp_image, (unsigned long *)&cr.chksum, 0);\n      fseek(nsp_image,0, SEEK_END);\n      fwrite(&cr, 1, sizeof(cr), nsp_image);\n\t  }\n\t  {\n\t\tFILE * non_web;\n\t\tchar fname[256];\n\t\tchar * img_buf;\n\t\tunsigned int len;\n\t\tstrcpy(fname, filen_out);\n\t\tstrcat(fname, \".non_web\");\n\t\tnon_web = fopen(fname,\"wb+\");\n\t\tfseek(nsp_image, 0, SEEK_END);\n\t\tlen = ftell(nsp_image);\n\t\timg_buf=malloc(len);\n\t\tfseek(nsp_image, 0, SEEK_SET);\n\t\tfread(img_buf, 1, len, nsp_image);\n\t\timg_buf[0xb] = 0x17;\n\t\tfwrite(img_buf, 1, len-sizeof(struct checksumrecord), non_web);\n\t\tfclose(non_web);\n\t\tfree(img_buf);\n\t  }\n\t  /* Close NSP image file */\n\tfclose(nsp_image);\n\n\t/* return result */\n\treturn(0);\n}\n\n#ifdef DMALLOC\n#include <dmalloc.h>\n#endif /* DMALLOC */\n\n#define BUFLEN (1 << 16)\n\nstatic unsigned long crctab[256] =\n{\n\t0x0,\n\t0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B,\n\t0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6,\n\t0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD,\n\t0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, 0x5F15ADAC,\n\t0x5BD4B01B, 0x569796C2, 0x52568B75, 0x6A1936C8, 0x6ED82B7F,\n\t0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3, 0x709F7B7A,\n\t0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039,\n\t0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58,\n\t0xBAEA46EF, 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033,\n\t0xA4AD16EA, 0xA06C0B5D, 0xD4326D90, 0xD0F37027, 0xDDB056FE,\n\t0xD9714B49, 0xC7361B4C, 0xC3F706FB, 0xCEB42022, 0xCA753D95,\n\t0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1, 0xE13EF6F4,\n\t0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0,\n\t0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5,\n\t0x2AC12072, 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16,\n\t0x018AEB13, 0x054BF6A4, 0x0808D07D, 0x0CC9CDCA, 0x7897AB07,\n\t0x7C56B6B0, 0x71159069, 0x75D48DDE, 0x6B93DDDB, 0x6F52C06C,\n\t0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08, 0x571D7DD1,\n\t0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA,\n\t0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B,\n\t0xBB60ADFC, 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698,\n\t0x832F1041, 0x87EE0DF6, 0x99A95DF3, 0x9D684044, 0x902B669D,\n\t0x94EA7B2A, 0xE0B41DE7, 0xE4750050, 0xE9362689, 0xEDF73B3E,\n\t0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2, 0xC6BCF05F,\n\t0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34,\n\t0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80,\n\t0x644FC637, 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB,\n\t0x4F040D56, 0x4BC510E1, 0x46863638, 0x42472B8F, 0x5C007B8A,\n\t0x58C1663D, 0x558240E4, 0x51435D53, 0x251D3B9E, 0x21DC2629,\n\t0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5, 0x3F9B762C,\n\t0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF,\n\t0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E,\n\t0xF5EE4BB9, 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65,\n\t0xEBA91BBC, 0xEF68060B, 0xD727BBB6, 0xD3E6A601, 0xDEA580D8,\n\t0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD, 0xCDA1F604, 0xC960EBB3,\n\t0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7, 0xAE3AFBA2,\n\t0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71,\n\t0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74,\n\t0x857130C3, 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640,\n\t0x4E8EE645, 0x4A4FFBF2, 0x470CDD2B, 0x43CDC09C, 0x7B827D21,\n\t0x7F436096, 0x7200464F, 0x76C15BF8, 0x68860BFD, 0x6C47164A,\n\t0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E, 0x18197087,\n\t0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC,\n\t0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D,\n\t0x2056CD3A, 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE,\n\t0xCC2B1D17, 0xC8EA00A0, 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB,\n\t0xDBEE767C, 0xE3A1CBC1, 0xE760D676, 0xEA23F0AF, 0xEEE2ED18,\n\t0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4, 0x89B8FD09,\n\t0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662,\n\t0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF,\n\t0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4\n};\n\nint cs_is_tagged(FILE *fp)\n{\n\tchar buf[8];\n\n\tfseek(fp, -8, SEEK_END);\n\tfread(buf, 8, 1, fp);\n\tif(*(unsigned long*)buf == CKSUM_MAGIC_NUMBER)\n\t\treturn 1;\n\treturn 0;\n}\n\nunsigned long cs_read_sum(FILE *fp)\n{\n\tchar buf[8];\n\n\tfseek(fp, -8, SEEK_END);\n\tfread(buf, 8, 1, fp);\n\treturn *((unsigned long*)&buf[4]);\n}\n\nint cs_calc_sum(FILE *fp, unsigned long *res, int tagged)\n{\n\tunsigned char buf[BUFLEN];\n\tunsigned long crc = 0;\n\tuintmax_t length = 0;\n\tsize_t bytes_read;\n\n\tfseek(fp, 0, SEEK_SET);\n\n\twhile((bytes_read = fread(buf, 1, BUFLEN, fp)) > 0)\n\t{\n\t\tunsigned char *cp = buf;\n\n\t\tif(length + bytes_read < length)\n\t\t\treturn 0;\n\n\t\tif(bytes_read != BUFLEN && tagged)\n\t\t\tbytes_read -= 8;\n\n\t\tlength += bytes_read;\n\t\twhile(bytes_read--)\n\t\t\tcrc =(crc << 8) ^ crctab[((crc >> 24) ^ *cp++) & 0xFF];\n\t}\n\n\tif(ferror(fp))\n\t\treturn 0;\n\n\tfor(; length; length >>= 8)\n\t\tcrc =(crc << 8) ^ crctab[((crc >> 24) ^ length) & 0xFF];\n\n\tcrc = ~crc & 0xFFFFFFFF;\n\n\t*res = crc;\n\n\treturn 1;\n}\n\nunsigned long cs_calc_buf_sum(char *buf, int size)\n{\n\tunsigned long crc = 0;\n\tchar *cp = buf;\n\tunsigned long length = size;\n\n\twhile(size--)\n\t\tcrc =(crc << 8) ^ crctab[((crc >> 24) ^ *cp++) & 0xFF];\n\n\tfor(; length; length >>= 8)\n\t\tcrc =(crc << 8) ^ crctab[((crc >> 24) ^ length) & 0xFF];\n\n\tcrc = ~crc & 0xFFFFFFFF;\n\n\treturn crc;\n}\n\nunsigned long cs_calc_buf_sum_ds(char *buf, int buf_size, char *sign, int sign_len)\n{\n\tunsigned long crc = 0;\n\tchar *cp = buf;\n\tunsigned long length = buf_size+sign_len;\n\n\twhile(buf_size--)\n\t\tcrc =(crc << 8) ^ crctab[((crc >> 24) ^ *cp++) & 0xFF];\n\n\tcp = sign;\n\twhile(sign_len--)\n\t\tcrc =(crc << 8) ^ crctab[((crc >> 24) ^ *cp++) & 0xFF];\n\n\n\tfor(; length; length >>= 8)\n\t\tcrc =(crc << 8) ^ crctab[((crc >> 24) ^ length) & 0xFF];\n\n\tcrc = ~crc & 0xFFFFFFFF;\n\n\treturn crc;\n}\n\nint cs_set_sum(FILE *fp, unsigned long sum, int tagged)\n{\n\tunsigned long magic = CKSUM_MAGIC_NUMBER;\n\n\tif(tagged)\n\t\tfseek(fp, -8, SEEK_END);\n\telse\n\t\tfseek(fp, 0, SEEK_END);\n\n\tif(fwrite(&magic, 1, 4, fp) < 4)\n\t\treturn 0;\n\tif(fwrite(&sum, 1, 4, fp) < 4)\n\t\treturn 0;\n\n\treturn 1;\n}\n\nvoid cs_get_sum(FILE *fp, unsigned long *sum)\n{\n\tunsigned long magic = 0;\n\n\tfseek(fp, -8, SEEK_END);\n\n\tfread(&magic, 4, 1, fp);\n\tfread(sum, 4, 1, fp);\n}\n\nint cs_validate_file(char *filename)\n{\n\tFILE *pFile = NULL;\n\tunsigned long sum = 0, res = 0;\n\n\tif((pFile = fopen(filename, \"r\")) == NULL)\n\t\treturn 0;\n\n\tif(!cs_is_tagged(pFile))\n\t{\n\t\tfclose(pFile);\n\t\treturn 0;\n\t}\n\tif(!cs_calc_sum(pFile, &sum, 1))\n\t{\n\t\tfclose(pFile);\n\t\treturn 0;\n\t}\n\tcs_get_sum(pFile, &res);\n\tfclose(pFile);\n\n\tif(sum != res)\n\t\treturn 0;\n\treturn 1;\n}\n\n/* ********* Library internal data ********* */\n#define\tCMDLINE_TRUE\t\t\t1\n#define\tCMDLINE_FALSE\t\t\t0\n\ntypedef\tenum CMDLINE_ERR\n{\n\tCMDLINE_ERR_OK\t\t= 0,\t/* No Error (OK) */\n\tCMDLINE_ERR_ERROR\t= -1,\t/* Unspecified error */\n\tCMDLINE_ERR_INVKEY\t= -3,\t/* Invalid option key */\n\tCMDLINE_ERR_MANYARG\t= -4,\t/* Too many arguments */\n\tCMDLINE_ERR_FEWARG\t= -5,\t/* Too few arguments */\n\tCMDLINE_ERR_ILLOPT\t= -6,\t/* Option not allowed (illegal option) */\n\tCMDLINE_ERR_NOMEM\t= -7,\t/* No memory */\n\tCMDLINE_ERR_OPTMIS\t= -8\t/* A mandatory option is missing */\n} CMDLINE_ERR;\n\n/* Argument list */\ntypedef\tstruct CMDLINE_ARG\n{\n\tint\t\t\t\tindex;\t\t/* Index of the argument in the command line */\n\tstruct CMDLINE_ARG*\tp_next;\t/* Next node in the linked list */\n} CMDLINE_ARG;\n\n/* Master control block for an option */\ntypedef struct CMDLINE_ARGS\n{\n\tint\t\t\t\targc;\t\t/* Total count of arguments found */\n\tint\t\t\t\toptc;\t\t/* Total count of options found */\n\tCMDLINE_ARG*\tlist;\t\t/* Argument list */\n} CMDLINE_ARGS;\n\n/* Master control block for all found arguments */\ntypedef\tstruct CMDLINE_DATA\n{\n\tCMDLINE_ARGS\topt_args[26];\t/* Array of MCBs for each option ('a' through 'z') */\n\tCMDLINE_ARGS\tglb_args;\t\t/* Global arguments */\n\tint\t\t\t\tparsed;\t\t\t/* Internal flag to prevent client calls if library is not initialized */\n} CMDLINE_DATA;\n\n/* ********* Local Data ********* */\nstatic CMDLINE_CFG cmdline_cfg;\nstatic CMDLINE_DATA cmdline_data;\n\nchar*\tcmdline_errmsg = \"CMDLINE ERROR\";\n\n/* ***************************************************************\n* Print all found command line options and their arguments\n****************************************************************** */\nvoid* cmdline_getarg_list(char opt)\n{\n\tint index = (opt - 'a');\n\n\t/* Check the validity of the index */\n\tif((index < 0) || (index > 25))\n\t{\n\t\t/* ERROR: Wrong option */\n\t\treturn NULL;\n\t}\n\n\t/* Return a pointer to the ARGS control structure */\n\treturn((void*)(&cmdline_data.opt_args[index]));\n}\n\n/* ***************************************************************\n* Print all found command line options and their arguments\n****************************************************************** */\nint cmdline_getarg_count(void* list)\n{\n\tCMDLINE_ARGS*\tp_args = (CMDLINE_ARGS*)list;\n\n\t/* Return number of arguments for this option */\n\treturn(p_args->argc);\n}\n\n/* ***************************************************************\n* Print all found command line options and their arguments\n****************************************************************** */\nint cmdline_getopt_count(char opt)\n{\n\tint\t\t\t\tindex;\n\n\t/* Calculate index value */\n\tindex = opt - 'a';\n\tif(index < 0 || index > 25) return -1;\n\n\t/* Return number of arguments for this option */\n\treturn(cmdline_data.opt_args[index].optc);\n}\n\n/* ***************************************************************\n* Print all found command line options and their arguments\n****************************************************************** */\nint cmdline_getarg(void* list, int num)\n{\n\tint i;\n\tCMDLINE_ARGS*\tp_args = (CMDLINE_ARGS*)list;\n\tCMDLINE_ARG*\tp_arg;\n\n\t/* Search the 'num' argument in the list for this option */\n\tfor(i=0,p_arg=p_args->list; (p_arg!=NULL) && (i<p_args->argc); i++, p_arg=p_arg->p_next)\n\t{\n\t\t/* if num matches i, we found it */\n\t\tif(i==num) return(p_arg->index);\n\t}\n\t/* We did not find the specified argument or the list was empty */\n\treturn -1;\n}\n\n/* ***************************************************************\n* Print all found command line options and their arguments\n****************************************************************** */\nint cmdline_configure(CMDLINE_CFG* p_cfg)\n{\n\t/* reset global data */\n\tmemset(&cmdline_cfg,0,sizeof(cmdline_cfg));\n\tmemset(&cmdline_data,0,sizeof(cmdline_data));\n\n\t/* Copy the user's config structure */\n\tcmdline_cfg = *p_cfg;\n\treturn 0;\n}\n\n/* ***************************************************************\n* Print all found command line options and their arguments\n****************************************************************** */\nchar* cmdline_error(int err)\n{\n\t/* TODO: implement a table of error messages */\n\treturn(cmdline_errmsg);\n}\n\n/* ***************************************************************\n* Print all found command line options and their arguments\n****************************************************************** */\nstatic void cmdline_print_args(CMDLINE_ARGS* p_arglist, char* argv[])\n{\n\tCMDLINE_ARG*\tp_arg;\n\n\tprintf(\"   Number of times option was specified: %d\\n\", p_arglist->optc);\n\tprintf(\"   Number of Arguments:                  %d\\n\", p_arglist->argc);\n\n\tif(p_arglist->argc > 0)\n\t{\n\t\tprintf(\"   Argument List: \");\n\n\t\tfor(p_arg=p_arglist->list; p_arg != NULL; p_arg=p_arg->p_next)\n\t\t\tprintf(\"%s \", argv[p_arg->index]);\n\t}\n\n\tprintf(\"\\n\");\n}\n\n/* ***************************************************************\n* Print all found command line options and their arguments\n****************************************************************** */\nvoid cmdline_print(char* argv[])\n{\n\tint i;\n\n\t/* Check if the command line was parsed */\n\tif(cmdline_data.parsed != CMDLINE_TRUE)\n\t{\n\t\tprintf(\"The command line has not been parsed yet.\\n\");\n\t\treturn;\n\t}\n\n\t/* Print out option arguments */\n\tfor( i = 0; i < 26; i++ )\n\t{\n\t\t/* Check if the option was specified */\n\t\tif(cmdline_data.opt_args[i].optc !=0 )\n\t\t{\n\t\t\t/* Print out option name and arguments */\n\t\t\tprintf(\"Option: -%c\\n\", (char)('a'+i));\n\t\t\tcmdline_print_args(&(cmdline_data.opt_args[i]), argv);\n\t\t}\n\t}\n\n\t/* Print out global arguments */\n\tprintf(\"Global arguments:\\n\");\n\tcmdline_print_args(&(cmdline_data.glb_args), argv);\n}\n\n/* ***************************************************************\n* Print configuration\n****************************************************************** */\nvoid cmdline_print_cfg(void)\n{\n\n}\n\nstatic void cmdline_argadd(CMDLINE_ARGS* p_arglist, CMDLINE_ARG* p_arg)\n{\n\tCMDLINE_ARG*\tp_list;\n\tCMDLINE_ARG*\tp_prev=NULL;\n\n\t/* See if we had anything in the list */\n\tif(p_arglist->argc == 0)\n\t{\n\t\t/* Link the argument in */\n\t\tp_arglist->list = p_arg;\n\t}\n\telse\n\t{\n\t\t/* Find the tail of the list */\n\t\tfor(p_list=p_arglist->list; p_list != NULL; p_list=p_list->p_next)\n\t\t\tp_prev = p_list;\n\n\t\t/* Link the argument in */\n\t\tp_prev->p_next=p_arg;\n\t}\n\n\t/* Keep track of arg number */\n\tp_arglist->argc++;\n}\n\n/* ***************************************************************\n* cmdline_read()\n* Read and parse command line arguments\n****************************************************************** */\nint cmdline_read(int argc, char* argv[])\n{\n\tint i, option=0;\n\n\t/* Process every command line argument in argv[] array */\n\tfor( i = 1; i < argc; i++ )\n\t{\n\t\t/* Does the argument start with a dash? */\n\t\tif( *argv[i] == '-' )\n\t\t{\n\t\t\t/* The argument must be two characters: a dash, and a letter */\n\t\t\tif( strlen(argv[i]) != 2 )\n\t\t\t{\n\t\t\t\t/* ERROR: option syntax (needs to be a dash and one letter) */\n\t\t\t\treturn(CMDLINE_ERR_ERROR);\n\t\t\t}\n\n\t\t\t/* Check validity of the option key ('a' through 'z') */\n\t\t\tif( ((*(argv[i] + 1)) < 'a') || ((*(argv[i] + 1)) > 'z') )\n\t\t\t{\n\t\t\t\t/* ERROR: option sysntax (invalid option key) */\n\t\t\t\treturn(CMDLINE_ERR_INVKEY);\n\t\t\t}\n\n\t\t\t/* Calculate the option index */\n\t\t\toption = (*(argv[i] + 1)) - 'a';\n\t\t\tif((option < 0) || (option > 25)) return(CMDLINE_ERR_INVKEY);\n\n\t\t\t/* Check to see if the option is allowed */\n\t\t\tif( cmdline_cfg.opts[option].flags & CMDLINE_OPTFLAG_ALLOW )\n\t\t\t{\n\t\t\t\t/* Option allowed. */\n\t\t\t\tcmdline_data.opt_args[option].optc++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* ERROR: Option is not allowed */\n\t\t\t\treturn(CMDLINE_ERR_ILLOPT);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* Read the arguments for the option */\n\t\t\tCMDLINE_ARG*\tp_arg;\n\n\t\t\t/* Allocate space for the argument node */\n\t\t\tp_arg = (CMDLINE_ARG*)calloc(1,sizeof(CMDLINE_ARG));\n\t\t\tif( p_arg== NULL )\n\t\t\t{\n\t\t\t\t/* ERROR: Can't allocate memory for the argument index */\n\t\t\t\treturn(CMDLINE_ERR_NOMEM);\n\t\t\t}\n\n\t\t\t/* Initialize the argument */\n\t\t\tp_arg->index\t= i;\n\t\t\tp_arg->p_next\t= NULL;\n\n\t\t\t/* Check if we can add to the list of arguments for this option */\n\t\t\tif( (option < 0)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* Do we have to add to the global list? */\n\t\t\t\t|| (cmdline_data.opt_args[option].argc == cmdline_cfg.opts[option].max)\t\t/* Did we reach MAX arguments? */\n\t\t\t\t)\n\t\t\t{\n\t\t\t\t/* This option does not require arguments. Keep the argument in the global list. */\n\t\t\t\tcmdline_argadd(&(cmdline_data.glb_args), p_arg);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* See if the current count has reached max for this option */\n\t\t\t\tif( cmdline_data.opt_args[option].argc == cmdline_cfg.opts[option].max )\n\t\t\t\t{\n\t\t\t\t\t/* ERROR: too many arguments for an option */\n\t\t\t\t\treturn(CMDLINE_ERR_MANYARG);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Link the argument to the arg list of the option */\n\t\t\t\t\tcmdline_argadd(&(cmdline_data.opt_args[option]), p_arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* ****** We read the complete command line. See if what we collected matches the configuration ******* */\n\n\t/* Check every collected option against its configuration */\n\tfor( i=0; i < 26; i++ )\n\t{\n\t\t/* Check if this option was allowed */\n\t\tif(cmdline_cfg.opts[i].flags & CMDLINE_OPTFLAG_ALLOW)\n\t\t{\n\t\t\t/* See if it was mandatory */\n\t\t\tif(cmdline_cfg.opts[i].flags & CMDLINE_OPTFLAG_MANDAT)\n\t\t\t{\n\t\t\t\t/* Check if we really collected this option on the command line. */\n\t\t\t\tif(cmdline_data.opt_args[i].optc == 0)\n\t\t\t\t{\n\t\t\t\t\t/* ERROR: a missing mandatory option */\n\t\t\t\t\treturn(CMDLINE_ERR_OPTMIS);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Option was there. Check how many args we got for it. */\n\t\t\t\t\tif(cmdline_data.opt_args[i].argc < cmdline_cfg.opts[i].min)\n\t\t\t\t\t{\n\t\t\t\t\t\t/* ERROR: too few arguments for an option */\n\t\t\t\t\t\treturn(CMDLINE_ERR_FEWARG);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t/* This mandatory option was proper. */\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\t/* This is non-mandatory option: */\n\t\t\t{\n\t\t\t\t/* Check if the option was specified on the command line */\n\t\t\t\tif(cmdline_data.opt_args[i].optc == 0)\n\t\t\t\t{\n\t\t\t\t\t/* option wasn't specified, go to the next */\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Option was there. Check how many args we collected for it. */\n\t\t\t\t\tif(cmdline_data.opt_args[i].argc < cmdline_cfg.opts[i].min)\n\t\t\t\t\t{\n\t\t\t\t\t\t/* ERROR: too few arguments for a non-mandatory option */\n\t\t\t\t\t\treturn(CMDLINE_ERR_FEWARG);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t/* This non-mandatory option was proper. */\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\t/* Option was not allowed. */\n\t\t{\n\t\t\t/* We should not get here as the non-allowed options should have been\n\t\t\ttrapped eariler. */\n\t\t}\n\t}\n\n\t/* Command line was proper as far as the number of options and their arguments */\n\tcmdline_data.parsed = CMDLINE_TRUE;\n\treturn(CMDLINE_ERR_OK);\n}\n"
  },
  {
    "path": "src/firmware-tools/mktitanimg.h",
    "content": "#ifndef __MKTITANIMG_H\n#define __MKTITANIMG_H\n\n#ifndef CFGMGR_CKSUM_H\n#define CFGMGR_CKSUM_H\n\n#define CKSUM_MAGIC_NUMBER 0xC453DE23\n\n#include <inttypes.h>\n#include <stdio.h>\n#include <errno.h>\n\nint cs_is_tagged(FILE*);\nunsigned long cs_read_sum(FILE*);\nint cs_calc_sum(FILE*, unsigned long*, int);\nint cs_set_sum(FILE*, unsigned long, int);\nvoid cs_get_sum(FILE*, unsigned long*);\nunsigned long cs_calc_buf_sum(char*, int);\nint cs_validate_file(char*);\n\n#endif\n#ifndef ___CMDLINE_H___\n#define\t___CMDLINE_H___\n\n/* ********* Library Configuration ********* */\ntypedef\tstruct CMDLINE_OPT\n{\n\tint\tmin;\t\t\t\t\t/* Minimum number of arguments this option takes */\n\tint\tmax;\t\t\t\t\t/* Maximum number of arguments this option takes */\n\tint\tflags;\t\t\t\t\t/* Controlling flags (whether to accept or not, etc) */\n} CMDLINE_OPT;\n\ntypedef\tstruct CMDLINE_CFG\n{\n\tCMDLINE_OPT\topts[26];\t\t/* Options 'a' through 'z' */\n\tCMDLINE_OPT\tglobal;\t\t\t/* Global option (outside 'a'..'z') */\n} CMDLINE_CFG;\n/* ******************************************** */\n\n#define\tCMDLINE_OPTFLAG_ALLOW\t0x1\t\t\t/* The option is allowed */\n#define\tCMDLINE_OPTFLAG_MANDAT\t0x2\t\t\t/* The option is mandatory */\n\nextern\tvoid\tcmdline_print(char* argv[]);\n\nextern\tint\t\tcmdline_configure(CMDLINE_CFG* p_cfg);\nextern\tint\t\tcmdline_read(int argc, char* argv[]);\n\nextern\tvoid*\tcmdline_getarg_list(char opt);\nextern\tint\t\tcmdline_getarg_count(void* list);\nextern\tint\t\tcmdline_getopt_count(char opt);\nextern\tint\t\tcmdline_getarg(void* list, int num);\n\nextern\tchar*\tcmdline_error(int err);\n#endif\n\n\n#ifndef _NSPIMGHDR_H_\n#define _NSPIMGHDR_H_\n\n/* This file describes the header format for the single image. The image is broken\n   up into several pieces. The image contains this header plus 1 or more sections.\n   Each section contains a binary block that could be a kernel, filesystem, etc. The\n   only garentee for this is that the very first section MUST be executable. Meaning\n   that the bootloader will be able to take the address of the header start, add the\n   header size, and execute that binary block. The header has its own checksum. It\n   starts hdr_size-4 bytes from the start of the header.\n */\n\nstruct nsp_img_hdr_head\n{\n\tunsigned int\tmagic;\t\t/* Magic number to identify this image header */\n\tunsigned int\tboot_offset;\t/* Offset from start of header to kernel code. */\n\tunsigned int\tflags;\t\t/* Image flags. */\n\tunsigned int\thdr_version;\t/* Version of this header. */\n\tunsigned int\thdr_size;\t/* The complete size of all portions of the header */\n\tunsigned int\tprod_id;\t/* This product id */\n\tunsigned int\trel_id;\t\t/* Which release this is */\n\tunsigned int\tversion;\t/* name-MMM.nnn.ooo-rxx => 0xMMnnooxx. See comment\n\t\t\t\t\t   below */\n\tunsigned int\timage_size;\t/* Image size (including header) */\n\tunsigned int\tinfo_offset;\t/* Offset from start of header to info block */\n\tunsigned int\tsect_info_offset;\t/* Offset from start of header to section desc */\n\tunsigned int\tchksum_offset;\t/* Offset from start of header to chksum block */\n//\tunsigned int    pad1;\n};\n\n/* The patch id is a machine readable value that takes the normal patch level, and encodes\n   the correct numbers inside of it. The format of the patches are name-MM.NN.oo-rxx.bin.\n   Convert MM, NN, oo, and xx into hex, and encode them as 0xMMNNooxx. Thus:\n   att-1.2.18-r14.bin => 0x0102120e */\n\n/* The following are the flag bits for the above flags variable */\n/* List of NSP status flags: */\n#define NSP_IMG_FLAG_FAILBACK_MASK\t0xF8000000\n\n/* NSP Image status flag: Flag indicates individual sections image */\n#define NSP_IMG_FLAG_INDIVIDUAL\t\t0x00000001\n\n/* NSP Image status flag 1: Image contains a bootable image when this bit is 0 */\n#define NSP_IMG_FLAG_FAILBACK_1\t\t0x08000000\n\n/* NSP Image status flag 2: Image contains a non-bootable image when this bit is 0 */\n#define NSP_IMG_FLAG_FAILBACK_2\t\t0x10000000\n\n/* NSP Image status flag 3: PSPBoot has tried the image when this bit is 0 */\n#define NSP_IMG_FLAG_FAILBACK_3\t\t0x20000000\n\n/* NSP Image status flag 4: Image is now secondary image when this bit is 0 */\n#define NSP_IMG_FLAG_FAILBACK_4\t\t0x40000000\n\n/* NSP Image status flag 5: Image contains a valid image when this bit is 0 */\n#define NSP_IMG_FLAG_FAILBACK_5\t\t0x80000000\n\n/* NSP Single image magic number */\n#define NSP_IMG_MAGIC_NUMBER\t\t0x4D544443\n\n\nstruct nsp_img_hdr_info\n{\n\tchar\trelease_name[64];\t/* Name of release */\n\tchar\timage_filename[64];\t/* name-mm.nn.oo-rxx.bin format */\n};\n\nstruct nsp_img_hdr_section_info\n{\n\tunsigned int\tnum_sects;\t/* Number of section (and section desc blocks) in this\n\t\t\t\t\t   image */\n\tunsigned int\tsect_size;\t/* Size of a SINGLE section_desc block */\n\tunsigned int\tsections_offset;\t/* Offset to from start of header to the start of\n\t\t\t\t\t\t   the section blocks */\n};\n\n/* There will be one of more of the following stuctures in the image header. Each\n   section will have one of these blocks. */\nstruct nsp_img_hdr_sections\n{\n\tunsigned int\toffset;\t\t/* Offset of section from start of NSP_IMG_HDR_HEAD */\n\tunsigned int\ttotal_size;\t/* Size of section (including pad size.) */\n\tunsigned int\traw_size;\t/* Size of section only */\n\tunsigned int\tflags;\t\t/* Section flags */\n\tunsigned int\tchksum;\t\t/* Section checksum */\n\tunsigned int\ttype;\t\t/* Section type. What kind of info does this section\n\t\t\t\t\t   describe */\n\tchar\t\tname[16];\t/* Reference name for this section. */\n};\n#define NSP_IMG_SECTION_TYPE_KERNEL\t\t(0x01)\n#define NSP_IMG_SECTION_TYPE_FILESYSTEM_ROOT\t(0x02)\n#define NSP_IMG_SECTION_TYPE_FILESYSTEM\t\t(0x03)\n\nstruct nsp_img_hdr\n{\n\tstruct nsp_img_hdr_head\t\thead;\t/* Head portion */\n\tstruct nsp_img_hdr_info\t\tinfo;\t/* Info */\n\tstruct nsp_img_hdr_section_info\tsect_info;\t/* Section block */\n\tstruct nsp_img_hdr_sections\tsections;\t/* 1 or more section_description blocks. More\n\t\t\t\t\t\t   section_desc blocks will be appended here\n\t\t\t\t\t\t   for each additional section needed */\n};\n\nstruct nsp_img_hdr_chksum\n{\n\tunsigned int\thdr_chksum;\t/* The checksum for the complete header. Excepting the\n\t\t\t\t\t   checksum block */\n};\n\nstruct nsp_img_hdr_sections *nsp_img_hdr_get_section_ptr_by_name(struct nsp_img_hdr *hdr, char *name);\nunsigned int nsp_img_hdr_get_section_offset_by_name(struct nsp_img_hdr *hdr, char *name);\nunsigned int nsp_img_hdr_get_section_size_by_name(struct nsp_img_hdr *hdr, char *name);\n\n#endif\n#endif /* __MKTITANIMG_H */\n"
  },
  {
    "path": "src/firmware-tools/mktplinkfw.c",
    "content": "/*\n * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>\n *\n * This tool was based on:\n *   TP-Link WR941 V2 firmware checksum fixing tool.\n *   Copyright (C) 2008,2009 Wang Jian <lark@linux.net.cn>\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License version 2 as published\n * by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\n#include <arpa/inet.h>\n#include <netinet/in.h>\n\n#include \"md5.h\"\n\n#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })\n\n#define HEADER_VERSION_V1\t0x01000000\n#define HWID_TL_MR3020_V1\t0x30200001\n#define HWID_TL_MR3220_V1\t0x32200001\n#define HWID_TL_MR3420_V1\t0x34200001\n#define HWID_TL_WA701N_V1\t0x07010001\n#define HWID_TL_WA7510N_V1\t0x75100001\n#define HWID_TL_WA901ND_V1\t0x09010001\n#define HWID_TL_WA901ND_V2\t0x09010002\n#define HWID_TL_WR703N_V1\t0x07030101\n#define HWID_TL_WR741ND_V1\t0x07410001\n#define HWID_TL_WR741ND_V4\t0x07410004\n#define HWID_TL_WR740N_V1\t0x07400001\n#define HWID_TL_WR740N_V3\t0x07400003\n#define HWID_TL_WR743ND_V1\t0x07430001\n#define HWID_TL_WR841N_V1_5\t0x08410002\n#define HWID_TL_WR841ND_V3\t0x08410003\n#define HWID_TL_WR841ND_V5\t0x08410005\n#define HWID_TL_WR841ND_V7\t0x08410007\n#define HWID_TL_WR941ND_V2\t0x09410002\n#define HWID_TL_WR941ND_V4\t0x09410004\n#define HWID_TL_WR1043ND_V1\t0x10430001\n#define HWID_TL_WR1041N_V2\t0x10410002\n#define HWID_TL_WR2543N_V1\t0x25430001\n\n#define MD5SUM_LEN\t16\n\nstruct file_info {\n\tchar\t\t*file_name;\t/* name of the file */\n\tuint32_t\tfile_size;\t/* length of the file */\n};\n\nstruct fw_header {\n\tuint32_t\tversion;\t/* header version */\n\tchar\t\tvendor_name[24];\n\tchar\t\tfw_version[36];\n\tuint32_t\thw_id;\t\t/* hardware id */\n\tuint32_t\thw_rev;\t\t/* hardware revision */\n\tuint32_t\tunk1;\n\tuint8_t\t\tmd5sum1[MD5SUM_LEN];\n\tuint32_t\tunk2;\n\tuint8_t\t\tmd5sum2[MD5SUM_LEN];\n\tuint32_t\tunk3;\n\tuint32_t\tkernel_la;\t/* kernel load address */\n\tuint32_t\tkernel_ep;\t/* kernel entry point */\n\tuint32_t\tfw_length;\t/* total length of the firmware */\n\tuint32_t\tkernel_ofs;\t/* kernel data offset */\n\tuint32_t\tkernel_len;\t/* kernel data length */\n\tuint32_t\trootfs_ofs;\t/* rootfs data offset */\n\tuint32_t\trootfs_len;\t/* rootfs data length */\n\tuint32_t\tboot_ofs;\t/* bootloader data offset */\n\tuint32_t\tboot_len;\t/* bootloader data length */\n\tuint16_t\tver_hi;\n\tuint16_t\tver_mid;\n\tuint16_t\tver_lo;\n\tuint8_t\t\tpad[354];\n} __attribute__ ((packed));\n\nstruct flash_layout {\n\tchar\t\t*id;\n\tuint32_t\tfw_max_len;\n\tuint32_t\tkernel_la;\n\tuint32_t\tkernel_ep;\n\tuint32_t\trootfs_ofs;\n};\n\nstruct board_info {\n\tchar\t\t*id;\n\tuint32_t\thw_id;\n\tuint32_t\thw_rev;\n\tchar\t\t*layout_id;\n};\n\n/*\n * Globals\n */\nstatic char *ofname;\nstatic char *progname;\nstatic char *vendor = \"TP-LINK Technologies\";\nstatic char *version = \"ver. 1.0\";\nstatic char *fw_ver = \"0.0.0\";\n\nstatic char *board_id;\nstatic struct board_info *board;\nstatic char *layout_id;\nstatic struct flash_layout *layout;\nstatic char *opt_hw_id;\nstatic uint32_t hw_id;\nstatic char *opt_hw_rev;\nstatic uint32_t hw_rev;\nstatic int fw_ver_lo;\nstatic int fw_ver_mid;\nstatic int fw_ver_hi;\nstatic struct file_info kernel_info;\nstatic uint32_t kernel_la = 0;\nstatic uint32_t kernel_ep = 0;\nstatic uint32_t kernel_len = 0;\nstatic struct file_info rootfs_info;\nstatic uint32_t rootfs_ofs = 0;\nstatic uint32_t rootfs_align;\nstatic struct file_info boot_info;\nstatic int combined;\nstatic int strip_padding;\nstatic int add_jffs2_eof;\nstatic unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};\n\nstatic struct file_info inspect_info;\nstatic int extract = 0;\n\nchar md5salt_normal[MD5SUM_LEN] = {\n\t0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,\n\t0xdd, 0xf9, 0xe7, 0xf4, 0x0e, 0xae, 0x47, 0x38,\n};\n\nchar md5salt_boot[MD5SUM_LEN] = {\n\t0x8c, 0xef, 0x33, 0x5b, 0xd5, 0xc5, 0xce, 0xfa,\n\t0xa7, 0x9c, 0x28, 0xda, 0xb2, 0xe9, 0x0f, 0x42,\n};\n\nstatic struct flash_layout layouts[] = {\n\t{\n\t\t.id\t\t= \"4M\",\n\t\t.fw_max_len\t= 0x3c0000,\n\t\t.kernel_la\t= 0x80060000,\n\t\t.kernel_ep\t= 0x80060000,\n\t\t.rootfs_ofs\t= 0x140000,\n\t}, {\n\t\t.id\t\t= \"4Mlzma\",\n\t\t.fw_max_len\t= 0x3c0000,\n\t\t.kernel_la\t= 0x80060000,\n\t\t.kernel_ep\t= 0x80060000,\n\t\t.rootfs_ofs\t= 0x100000,\n\t}, {\n\t\t.id\t\t= \"8M\",\n\t\t.fw_max_len\t= 0x7c0000,\n\t\t.kernel_la\t= 0x80060000,\n\t\t.kernel_ep\t= 0x80060000,\n\t\t.rootfs_ofs\t= 0x140000,\n\t}, {\n\t\t.id\t\t= \"8Mlzma\",\n\t\t.fw_max_len\t= 0x7c0000,\n\t\t.kernel_la\t= 0x80060000,\n\t\t.kernel_ep\t= 0x80060000,\n\t\t.rootfs_ofs\t= 0x100000,\n\t}, {\n\t\t/* terminating entry */\n\t}\n};\n\nstatic struct board_info boards[] = {\n\t{\n\t\t.id\t\t= \"TL-MR3020v1\",\n\t\t.hw_id\t\t= HWID_TL_MR3020_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4Mlzma\",\n\t}, {\n\t\t.id\t\t= \"TL-MR3220v1\",\n\t\t.hw_id\t\t= HWID_TL_MR3220_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-MR3420v1\",\n\t\t.hw_id\t\t= HWID_TL_MR3420_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WA701Nv1\",\n\t\t.hw_id\t\t= HWID_TL_WA701N_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WA7510N\",\n\t\t.hw_id\t\t= HWID_TL_WA7510N_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WA901NDv1\",\n\t\t.hw_id\t\t= HWID_TL_WA901ND_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id             = \"TL-WA901NDv2\",\n\t\t.hw_id          = HWID_TL_WA901ND_V2,\n\t\t.hw_rev         = 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR741NDv1\",\n\t\t.hw_id\t\t= HWID_TL_WR741ND_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR741NDv4\",\n\t\t.hw_id\t\t= HWID_TL_WR741ND_V4,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4Mlzma\",\n\t}, {\n\t\t.id\t\t= \"TL-WR740Nv1\",\n\t\t.hw_id\t\t= HWID_TL_WR740N_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR740Nv3\",\n\t\t.hw_id\t\t= HWID_TL_WR740N_V3,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR743NDv1\",\n\t\t.hw_id\t\t= HWID_TL_WR743ND_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR841Nv1.5\",\n\t\t.hw_id\t\t= HWID_TL_WR841N_V1_5,\n\t\t.hw_rev\t\t= 2,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR841NDv3\",\n\t\t.hw_id\t\t= HWID_TL_WR841ND_V3,\n\t\t.hw_rev\t\t= 3,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR841NDv5\",\n\t\t.hw_id\t\t= HWID_TL_WR841ND_V5,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR841NDv7\",\n\t\t.hw_id\t\t= HWID_TL_WR841ND_V7,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR941NDv2\",\n\t\t.hw_id\t\t= HWID_TL_WR941ND_V2,\n\t\t.hw_rev\t\t= 2,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR941NDv4\",\n\t\t.hw_id\t\t= HWID_TL_WR941ND_V4,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR1041Nv2\",\n\t\t.hw_id\t\t= HWID_TL_WR1041N_V2,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4Mlzma\",\n\t}, {\n\t\t.id\t\t= \"TL-WR1043NDv1\",\n\t\t.hw_id\t\t= HWID_TL_WR1043ND_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"8M\",\n\t}, {\n\t\t.id\t\t= \"TL-WR2543Nv1\",\n\t\t.hw_id\t\t= HWID_TL_WR2543N_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"8Mlzma\",\n\t}, {\n\t\t.id\t\t= \"TL-WR703Nv1\",\n\t\t.hw_id\t\t= HWID_TL_WR703N_V1,\n\t\t.hw_rev\t\t= 1,\n\t\t.layout_id\t= \"4Mlzma\",\n\t}, {\n\t\t/* terminating entry */\n\t}\n};\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\n#define DBG(fmt, ...) do { \\\n\tfprintf(stderr, \"[%s] \" fmt \"\\n\", progname, ## __VA_ARGS__ ); \\\n} while (0)\n\nstatic struct board_info *find_board(char *id)\n{\n\tstruct board_info *ret;\n\tstruct board_info *board;\n\n\tret = NULL;\n\tfor (board = boards; board->id != NULL; board++){\n\t\tif (strcasecmp(id, board->id) == 0) {\n\t\t\tret = board;\n\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn ret;\n}\n\nstatic struct board_info *find_board_by_hwid(uint32_t hw_id)\n{\n\tstruct board_info *board;\n\n\tfor (board = boards; board->id != NULL; board++) {\n\t\tif (hw_id == board->hw_id)\n\t\t\treturn board;\n\t};\n\n\treturn NULL;\n}\n\nstatic struct flash_layout *find_layout(char *id)\n{\n\tstruct flash_layout *ret;\n\tstruct flash_layout *l;\n\n\tret = NULL;\n\tfor (l = layouts; l->id != NULL; l++){\n\t\tif (strcasecmp(id, l->id) == 0) {\n\t\t\tret = l;\n\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn ret;\n}\n\nstatic void usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct board_info *board;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -B <board>      create image for the board specified with <board>\\n\"\n\"  -c              use combined kernel image\\n\"\n\"  -E <ep>         overwrite kernel entry point with <ep> (hexval prefixed with 0x)\\n\"\n\"  -L <la>         overwrite kernel load address with <la> (hexval prefixed with 0x)\\n\"\n\"  -H <hwid>       use hardware id specified with <hwid>\\n\"\n\"  -F <id>         use flash layout specified with <id>\\n\"\n\"  -k <file>       read kernel image from the file <file>\\n\"\n\"  -r <file>       read rootfs image from the file <file>\\n\"\n\"  -a <align>      align the rootfs start on an <align> bytes boundary\\n\"\n\"  -R <offset>     overwrite rootfs offset with <offset> (hexval prefixed with 0x)\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -s              strip padding from the end of the image\\n\"\n\"  -j              add jffs2 end-of-filesystem markers\\n\"\n\"  -N <vendor>     set image vendor to <vendor>\\n\"\n\"  -V <version>    set image version to <version>\\n\"\n\"  -v <version>    set firmware version to <version>\\n\"\n\"  -i <file>       inspect given firmware file <file>\\n\"\n\"  -x              extract kernel and rootfs while inspecting (requires -i)\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nstatic int get_md5(char *data, int size, char *md5)\n{\n\tMD5_CTX ctx;\n\n\tMD5_Init(&ctx);\n\tMD5_Update(&ctx, data, size);\n\tMD5_Final(md5, &ctx);\n}\n\nstatic int get_file_stat(struct file_info *fdata)\n{\n\tstruct stat st;\n\tint res;\n\n\tif (fdata->file_name == NULL)\n\t\treturn 0;\n\n\tres = stat(fdata->file_name, &st);\n\tif (res){\n\t\tERRS(\"stat failed on %s\", fdata->file_name);\n\t\treturn res;\n\t}\n\n\tfdata->file_size = st.st_size;\n\treturn 0;\n}\n\nstatic int read_to_buf(struct file_info *fdata, char *buf)\n{\n\tFILE *f;\n\tint ret = EXIT_FAILURE;\n\n\tf = fopen(fdata->file_name, \"r\");\n\tif (f == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for reading\", fdata->file_name);\n\t\tgoto out;\n\t}\n\n\terrno = 0;\n\tfread(buf, fdata->file_size, 1, f);\n\tif (errno != 0) {\n\t\tERRS(\"unable to read from file \\\"%s\\\"\", fdata->file_name);\n\t\tgoto out_close;\n\t}\n\n\tret = EXIT_SUCCESS;\n\n out_close:\n\tfclose(f);\n out:\n\treturn ret;\n}\n\nstatic int check_options(void)\n{\n\tint ret;\n\n\tif (inspect_info.file_name) {\n\t\tret = get_file_stat(&inspect_info);\n\t\tif (ret)\n\t\t\treturn ret;\n\n\t\treturn 0;\n\t} else if (extract) {\n\t\tERR(\"no firmware for inspection specified\");\n\t\treturn -1;\n\t}\n\n\tif (board_id == NULL && opt_hw_id == NULL) {\n\t\tERR(\"either board or hardware id must be specified\");\n\t\treturn -1;\n\t}\n\n\tif (board_id) {\n\t\tboard = find_board(board_id);\n\t\tif (board == NULL) {\n\t\t\tERR(\"unknown/unsupported board id \\\"%s\\\"\", board_id);\n\t\t\treturn -1;\n\t\t}\n\t\tif (layout_id == NULL)\n\t\t\tlayout_id = board->layout_id;\n\n\t\thw_id = board->hw_id;\n\t\thw_rev = board->hw_rev;\n\t} else {\n\t\tif (layout_id == NULL) {\n\t\t\tERR(\"flash layout is not specified\");\n\t\t\treturn -1;\n\t\t}\n\t\thw_id = strtoul(opt_hw_id, NULL, 0);\n\n\t\tif (opt_hw_rev)\n\t\t\thw_rev = strtoul(opt_hw_rev, NULL, 0);\n\t\telse\n\t\t\thw_rev = 1;\n\t}\n\n\tlayout = find_layout(layout_id);\n\tif (layout == NULL) {\n\t\tERR(\"unknown flash layout \\\"%s\\\"\", layout_id);\n\t\treturn -1;\n\t}\n\n\tif (!kernel_la)\n\t\tkernel_la = layout->kernel_la;\n\tif (!kernel_ep)\n\t\tkernel_ep = layout->kernel_ep;\n\tif (!rootfs_ofs)\n\t\trootfs_ofs = layout->rootfs_ofs;\n\n\tif (kernel_info.file_name == NULL) {\n\t\tERR(\"no kernel image specified\");\n\t\treturn -1;\n\t}\n\n\tret = get_file_stat(&kernel_info);\n\tif (ret)\n\t\treturn ret;\n\n\tkernel_len = kernel_info.file_size;\n\n\tif (combined) {\n\t\tif (kernel_info.file_size >\n\t\t    layout->fw_max_len - sizeof(struct fw_header)) {\n\t\t\tERR(\"kernel image is too big\");\n\t\t\treturn -1;\n\t\t}\n\t} else {\n\t\tif (rootfs_info.file_name == NULL) {\n\t\t\tERR(\"no rootfs image specified\");\n\t\t\treturn -1;\n\t\t}\n\n\t\tret = get_file_stat(&rootfs_info);\n\t\tif (ret)\n\t\t\treturn ret;\n\n\t\tif (rootfs_align) {\n\t\t\tkernel_len += sizeof(struct fw_header);\n\t\t\tkernel_len = ALIGN(kernel_len, rootfs_align);\n\t\t\tkernel_len -= sizeof(struct fw_header);\n\n\t\t\tDBG(\"kernel length aligned to %u\", kernel_len);\n\n\t\t\tif (kernel_len + rootfs_info.file_size >\n\t\t\t    layout->fw_max_len - sizeof(struct fw_header)) {\n\t\t\t\tERR(\"images are too big\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t} else {\n\t\t\tif (kernel_info.file_size >\n\t\t\t    rootfs_ofs - sizeof(struct fw_header)) {\n\t\t\t\tERR(\"kernel image is too big\");\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t\tif (rootfs_info.file_size >\n\t\t\t    (layout->fw_max_len - rootfs_ofs)) {\n\t\t\t\tERR(\"rootfs image is too big\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\treturn -1;\n\t}\n\n\tret = sscanf(fw_ver, \"%d.%d.%d\", &fw_ver_hi, &fw_ver_mid, &fw_ver_lo);\n\tif (ret != 3) {\n\t\tERR(\"invalid firmware version '%s'\", fw_ver);\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\nstatic void fill_header(char *buf, int len)\n{\n\tstruct fw_header *hdr = (struct fw_header *)buf;\n\n\tmemset(hdr, 0, sizeof(struct fw_header));\n\n\thdr->version = htonl(HEADER_VERSION_V1);\n\tstrncpy(hdr->vendor_name, vendor, sizeof(hdr->vendor_name));\n\tstrncpy(hdr->fw_version, version, sizeof(hdr->fw_version));\n\thdr->hw_id = htonl(hw_id);\n\thdr->hw_rev = htonl(hw_rev);\n\n\tif (boot_info.file_size == 0)\n\t\tmemcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1));\n\telse\n\t\tmemcpy(hdr->md5sum1, md5salt_boot, sizeof(hdr->md5sum1));\n\n\thdr->kernel_la = htonl(kernel_la);\n\thdr->kernel_ep = htonl(kernel_ep);\n\thdr->fw_length = htonl(layout->fw_max_len);\n\thdr->kernel_ofs = htonl(sizeof(struct fw_header));\n\thdr->kernel_len = htonl(kernel_len);\n\tif (!combined) {\n\t\thdr->rootfs_ofs = htonl(rootfs_ofs);\n\t\thdr->rootfs_len = htonl(rootfs_info.file_size);\n\t}\n\n\thdr->ver_hi = htons(fw_ver_hi);\n\thdr->ver_mid = htons(fw_ver_mid);\n\thdr->ver_lo = htons(fw_ver_lo);\n\n\tget_md5(buf, len, hdr->md5sum1);\n}\n\nstatic int pad_jffs2(char *buf, int currlen)\n{\n\tint len;\n\tuint32_t pad_mask;\n\n\tlen = currlen;\n\tpad_mask = (64 * 1024);\n\twhile ((len < layout->fw_max_len) && (pad_mask != 0)) {\n\t\tuint32_t mask;\n\t\tint i;\n\n\t\tfor (i = 10; i < 32; i++) {\n\t\t\tmask = 1 << i;\n\t\t\tif (pad_mask & mask)\n\t\t\t\tbreak;\n\t\t}\n\n\t\tlen = ALIGN(len, mask);\n\n\t\tfor (i = 10; i < 32; i++) {\n\t\t\tmask = 1 << i;\n\t\t\tif ((len & (mask - 1)) == 0)\n\t\t\t\tpad_mask &= ~mask;\n\t\t}\n\n\t\tfor (i = 0; i < sizeof(jffs2_eof_mark); i++)\n\t\t\tbuf[len + i] = jffs2_eof_mark[i];\n\n\t\tlen += sizeof(jffs2_eof_mark);\n\t}\n\n\treturn len;\n}\n\nstatic int write_fw(char *data, int len)\n{\n\tFILE *f;\n\tint ret = EXIT_FAILURE;\n\n\tf = fopen(ofname, \"w\");\n\tif (f == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto out;\n\t}\n\n\terrno = 0;\n\tfwrite(data, len, 1, f);\n\tif (errno) {\n\t\tERRS(\"unable to write output file\");\n\t\tgoto out_flush;\n\t}\n\n\tDBG(\"firmware file \\\"%s\\\" completed\", ofname);\n\n\tret = EXIT_SUCCESS;\n\n out_flush:\n\tfflush(f);\n\tfclose(f);\n\tif (ret != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\n out:\n\treturn ret;\n}\n\nstatic int build_fw(void)\n{\n\tint buflen;\n\tchar *buf;\n\tchar *p;\n\tint ret = EXIT_FAILURE;\n\tint writelen = 0;\n\n\tbuflen = layout->fw_max_len;\n\n\tbuf = malloc(buflen);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto out;\n\t}\n\n\tmemset(buf, 0xff, buflen);\n\tp = buf + sizeof(struct fw_header);\n\tret = read_to_buf(&kernel_info, p);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\twritelen = sizeof(struct fw_header) + kernel_len;\n\n\tif (!combined) {\n\t\tif (rootfs_align)\n\t\t\tp = buf + writelen;\n\t\telse\n\t\t\tp = buf + rootfs_ofs;\n\n\t\tret = read_to_buf(&rootfs_info, p);\n\t\tif (ret)\n\t\t\tgoto out_free_buf;\n\n\t\tif (rootfs_align)\n\t\t\twritelen += rootfs_info.file_size;\n\t\telse\n\t\t\twritelen = rootfs_ofs + rootfs_info.file_size;\n\n\t\tif (add_jffs2_eof)\n\t\t\twritelen = pad_jffs2(buf, writelen);\n\t}\n\n\tif (!strip_padding)\n\t\twritelen = buflen;\n\n\tfill_header(buf, writelen);\n\tret = write_fw(buf, writelen);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\tret = EXIT_SUCCESS;\n\n out_free_buf:\n\tfree(buf);\n out:\n\treturn ret;\n}\n\n/* Helper functions to inspect_fw() representing different output formats */\nstatic inline void inspect_fw_pstr(char *label, char *str)\n{\n\tprintf(\"%-23s: %s\\n\", label, str);\n}\n\nstatic inline void inspect_fw_phex(char *label, uint32_t val)\n{\n\tprintf(\"%-23s: 0x%08x\\n\", label, val);\n}\n\nstatic inline void inspect_fw_phexpost(char *label,\n                                       uint32_t val, char *post)\n{\n\tprintf(\"%-23s: 0x%08x (%s)\\n\", label, val, post);\n}\n\nstatic inline void inspect_fw_phexdef(char *label,\n                                      uint32_t val, uint32_t defval)\n{\n\tprintf(\"%-23s: 0x%08x                  \", label, val);\n\n\tif (val == defval)\n\t\tprintf(\"(== OpenWrt default)\\n\");\n\telse\n\t\tprintf(\"(OpenWrt default: 0x%08x)\\n\", defval);\n}\n\nstatic inline void inspect_fw_phexexp(char *label,\n                                      uint32_t val, uint32_t expval)\n{\n\tprintf(\"%-23s: 0x%08x \", label, val);\n\n\tif (val == expval)\n\t\tprintf(\"(ok)\\n\");\n\telse\n\t\tprintf(\"(expected: 0x%08x)\\n\", expval);\n}\n\nstatic inline void inspect_fw_phexdec(char *label, uint32_t val)\n{\n\tprintf(\"%-23s: 0x%08x / %8u bytes\\n\", label, val, val);\n}\n\nstatic inline void inspect_fw_phexdecdef(char *label,\n                                         uint32_t val, uint32_t defval)\n{\n\tprintf(\"%-23s: 0x%08x / %8u bytes \", label, val, val);\n\n\tif (val == defval)\n\t\tprintf(\"(== OpenWrt default)\\n\");\n\telse\n\t\tprintf(\"(OpenWrt default: 0x%08x)\\n\", defval);\n}\n\nstatic inline void inspect_fw_pmd5sum(char *label, uint8_t *val, char *text)\n{\n\tint i;\n\n\tprintf(\"%-23s:\", label);\n\tfor (i=0; i<MD5SUM_LEN; i++)\n\t\tprintf(\" %02x\", val[i]);\n\tprintf(\" %s\\n\", text);\n}\n\nstatic int inspect_fw(void)\n{\n\tchar *buf;\n\tstruct fw_header *hdr;\n\tuint8_t md5sum[MD5SUM_LEN];\n\tstruct board_info *board;\n\tint ret = EXIT_FAILURE;\n\n\tbuf = malloc(inspect_info.file_size);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer!\\n\");\n\t\tgoto out;\n\t}\n\n\tret = read_to_buf(&inspect_info, buf);\n\tif (ret)\n\t\tgoto out_free_buf;\n\thdr = (struct fw_header *)buf;\n\n\tinspect_fw_pstr(\"File name\", inspect_info.file_name);\n\tinspect_fw_phexdec(\"File size\", inspect_info.file_size);\n\n\tif (ntohl(hdr->version) != HEADER_VERSION_V1) {\n\t\tERR(\"file does not seem to have V1 header!\\n\");\n\t\tgoto out_free_buf;\n\t}\n\n\tinspect_fw_phexdec(\"Version 1 Header size\", sizeof(struct fw_header));\n\n\tif (ntohl(hdr->unk1) != 0)\n\t\tinspect_fw_phexdec(\"Unknown value 1\", hdr->unk1);\n\n\tmemcpy(md5sum, hdr->md5sum1, sizeof(md5sum));\n\tif (ntohl(hdr->boot_len) == 0)\n\t\tmemcpy(hdr->md5sum1, md5salt_normal, sizeof(md5sum));\n\telse\n\t\tmemcpy(hdr->md5sum1, md5salt_boot, sizeof(md5sum));\n\tget_md5(buf, inspect_info.file_size, hdr->md5sum1);\n\n\tif (memcmp(md5sum, hdr->md5sum1, sizeof(md5sum))) {\n\t\tinspect_fw_pmd5sum(\"Header MD5Sum1\", md5sum, \"(*ERROR*)\");\n\t\tinspect_fw_pmd5sum(\"          --> expected\", hdr->md5sum1, \"\");\n\t} else {\n\t\tinspect_fw_pmd5sum(\"Header MD5Sum1\", md5sum, \"(ok)\");\n\t}\n\tif (ntohl(hdr->unk2) != 0)\n\t\tinspect_fw_phexdec(\"Unknown value 2\", hdr->unk2);\n\tinspect_fw_pmd5sum(\"Header MD5Sum2\", hdr->md5sum2,\n\t                   \"(purpose yet unknown, unchecked here)\");\n\tif (ntohl(hdr->unk3) != 0)\n\t\tinspect_fw_phexdec(\"Unknown value 3\", hdr->unk3);\n\n\tprintf(\"\\n\");\n\n\tinspect_fw_pstr(\"Vendor name\", hdr->vendor_name);\n\tinspect_fw_pstr(\"Firmware version\", hdr->fw_version);\n\tboard = find_board_by_hwid(ntohl(hdr->hw_id));\n\tif (board) {\n\t\tlayout = find_layout(board->layout_id);\n\t\tinspect_fw_phexpost(\"Hardware ID\",\n\t\t                    ntohl(hdr->hw_id), board->id);\n\t\tinspect_fw_phexexp(\"Hardware Revision\",\n\t\t                   ntohl(hdr->hw_rev), board->hw_rev);\n\t} else {\n\t\tinspect_fw_phexpost(\"Hardware ID\",\n\t\t                    ntohl(hdr->hw_id), \"unknown\");\n\t\tinspect_fw_phex(\"Hardware Revision\",\n\t\t                ntohl(hdr->hw_rev));\n\t}\n\n\tprintf(\"\\n\");\n\n\tinspect_fw_phexdec(\"Kernel data offset\",\n\t                   ntohl(hdr->kernel_ofs));\n\tinspect_fw_phexdec(\"Kernel data length\",\n\t                   ntohl(hdr->kernel_len));\n\tif (board) {\n\t\tinspect_fw_phexdef(\"Kernel load address\",\n\t\t                   ntohl(hdr->kernel_la),\n\t\t                   layout ? layout->kernel_la : 0xffffffff);\n\t\tinspect_fw_phexdef(\"Kernel entry point\",\n\t\t                   ntohl(hdr->kernel_ep),\n\t\t                   layout ? layout->kernel_ep : 0xffffffff);\n\t\tinspect_fw_phexdecdef(\"Rootfs data offset\",\n\t\t                      ntohl(hdr->rootfs_ofs),\n\t\t                      layout ? layout->rootfs_ofs : 0xffffffff);\n\t} else {\n\t\tinspect_fw_phex(\"Kernel load address\",\n\t\t                ntohl(hdr->kernel_la));\n\t\tinspect_fw_phex(\"Kernel entry point\",\n\t\t                ntohl(hdr->kernel_ep));\n\t\tinspect_fw_phexdec(\"Rootfs data offset\",\n\t\t                   ntohl(hdr->rootfs_ofs));\n\t}\n\tinspect_fw_phexdec(\"Rootfs data length\",\n\t                   ntohl(hdr->rootfs_len));\n\tinspect_fw_phexdec(\"Boot loader data offset\",\n\t                   ntohl(hdr->boot_ofs));\n\tinspect_fw_phexdec(\"Boot loader data length\",\n\t                   ntohl(hdr->boot_len));\n\tinspect_fw_phexdec(\"Total firmware length\",\n\t                   ntohl(hdr->fw_length));\n\n\tif (extract) {\n\t\tFILE *fp;\n\t\tchar *filename;\n\n\t\tprintf(\"\\n\");\n\n\t\tfilename = malloc(strlen(inspect_info.file_name) + 8);\n\t\tsprintf(filename, \"%s-kernel\", inspect_info.file_name);\n\t\tprintf(\"Extracting kernel to \\\"%s\\\"...\\n\", filename);\n\t\tfp = fopen(filename, \"w\");\n\t\tif (fp)\t{\n\t\t\tif (!fwrite(buf + ntohl(hdr->kernel_ofs),\n\t\t\t            ntohl(hdr->kernel_len), 1, fp)) {\n\t\t\t\tERR(\"error in fwrite(): %s\", strerror(errno));\n\t\t\t}\n\t\t\tfclose(fp);\n\t\t} else {\n\t\t\tERR(\"error in fopen(): %s\", strerror(errno));\n\t\t}\n\t\tfree(filename);\n\n\t\tfilename = malloc(strlen(inspect_info.file_name) + 8);\n\t\tsprintf(filename, \"%s-rootfs\", inspect_info.file_name);\n\t\tprintf(\"Extracting rootfs to \\\"%s\\\"...\\n\", filename);\n\t\tfp = fopen(filename, \"w\");\n\t\tif (fp)\t{\n\t\t\tif (!fwrite(buf + ntohl(hdr->rootfs_ofs),\n\t\t\t            ntohl(hdr->rootfs_len), 1, fp)) {\n\t\t\t\tERR(\"error in fwrite(): %s\", strerror(errno));\n\t\t\t}\n\t\t\tfclose(fp);\n\t\t} else {\n\t\t\tERR(\"error in fopen(): %s\", strerror(errno));\n\t\t}\n\t\tfree(filename);\n\t}\n\n out_free_buf:\n\tfree(buf);\n out:\n\treturn ret;\n}\n\nint main(int argc, char *argv[])\n{\n\tint ret = EXIT_FAILURE;\n\tint err;\n\n\tFILE *outfile;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xhsjv:\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'a':\n\t\t\tsscanf(optarg, \"0x%x\", &rootfs_align);\n\t\t\tbreak;\n\t\tcase 'B':\n\t\t\tboard_id = optarg;\n\t\t\tbreak;\n\t\tcase 'H':\n\t\t\topt_hw_id = optarg;\n\t\t\tbreak;\n\t\tcase 'E':\n\t\t\tsscanf(optarg, \"0x%x\", &kernel_ep);\n\t\t\tbreak;\n\t\tcase 'F':\n\t\t\tlayout_id = optarg;\n\t\t\tbreak;\n\t\tcase 'W':\n\t\t\topt_hw_rev = optarg;\n\t\t\tbreak;\n\t\tcase 'L':\n\t\t\tsscanf(optarg, \"0x%x\", &kernel_la);\n\t\t\tbreak;\n\t\tcase 'V':\n\t\t\tversion = optarg;\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tfw_ver = optarg;\n\t\t\tbreak;\n\t\tcase 'N':\n\t\t\tvendor = optarg;\n\t\t\tbreak;\n\t\tcase 'c':\n\t\t\tcombined++;\n\t\t\tbreak;\n\t\tcase 'k':\n\t\t\tkernel_info.file_name = optarg;\n\t\t\tbreak;\n\t\tcase 'r':\n\t\t\trootfs_info.file_name = optarg;\n\t\t\tbreak;\n\t\tcase 'R':\n\t\t\tsscanf(optarg, \"0x%x\", &rootfs_ofs);\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\tstrip_padding = 1;\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tinspect_info.file_name = optarg;\n\t\t\tbreak;\n\t\tcase 'j':\n\t\t\tadd_jffs2_eof = 1;\n\t\t\tbreak;\n\t\tcase 'x':\n\t\t\textract = 1;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tret = check_options();\n\tif (ret)\n\t\tgoto out;\n\n\tif (!inspect_info.file_name)\n\t\tret = build_fw();\n\telse\n\t\tret = inspect_fw();\n\n out:\n\treturn ret;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/mkwrgimg.c",
    "content": "/*\n *  Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>\n#include <libgen.h>\n#include <getopt.h>\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\n#include \"md5.h\"\n\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \", %s\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\n#define WRG_MAGIC\t0x20040220\n\nstruct wrg_header {\n\tchar\t\tsignature[32];\n\tuint32_t\tmagic1;\n\tuint32_t\tmagic2;\n\tuint32_t\tsize;\n\tuint32_t\toffset;\n\tchar\t\tdevname[32];\n\tchar\t\tdigest[16];\n} __attribute__ ((packed));\n\nstatic char *progname;\nstatic char *ifname;\nstatic char *ofname;\nstatic char *signature;\nstatic char *dev_name;\nstatic uint32_t offset;\nstatic int big_endian;\n\nvoid usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -b              create image in big endian format\\n\"\n\"  -i <file>       read input from the file <file>\\n\"\n\"  -d <name>       set device name to <name>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -O <offset>     set offset to <offset>\\n\"\n\"  -s <sig>        set image signature to <sig>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nstatic void put_u32(void *data, uint32_t val)\n{\n\tunsigned char *p = data;\n\n\tif (big_endian) {\n\t\tp[0] = (val >> 24) & 0xff;\n\t\tp[1] = (val >> 16) & 0xff;\n\t\tp[2] = (val >> 8) & 0xff;\n\t\tp[3] = val & 0xff;\n\t} else {\n\t\tp[3] = (val >> 24) & 0xff;\n\t\tp[2] = (val >> 16) & 0xff;\n\t\tp[1] = (val >> 8) & 0xff;\n\t\tp[0] = val & 0xff;\n\t}\n}\n\nstatic void get_digest(struct wrg_header *header, char *data, int size)\n{\n\tMD5_CTX ctx;\n\n\tMD5_Init(&ctx);\n\n\tMD5_Update(&ctx, (char *)&header->offset, sizeof(header->offset));\n\tMD5_Update(&ctx, (char *)&header->devname, sizeof(header->devname));\n\tMD5_Update(&ctx, data, size);\n\n\tMD5_Final(header->digest, &ctx);\n}\n\nint main(int argc, char *argv[])\n{\n\tstruct wrg_header *header;\n\tchar *buf;\n\tstruct stat st;\n\tint buflen;\n\tint err;\n\tint res = EXIT_FAILURE;\n\n\tFILE *outfile, *infile;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"bd:i:o:s:O:h\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'b':\n\t\t\tbig_endian = 1;\n\t\t\tbreak;\n\t\tcase 'd':\n\t\t\tdev_name = optarg;\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tifname = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\tsignature = optarg;\n\t\t\tbreak;\n\t\tcase 'O':\n\t\t\toffset = strtoul(optarg, NULL, 0);\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (signature == NULL) {\n\t\tERR(\"no signature specified\");\n\t\tgoto err;\n\t}\n\n\tif (ifname == NULL) {\n\t\tERR(\"no input file specified\");\n\t\tgoto err;\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\tgoto err;\n\t}\n\n\tif (dev_name == NULL) {\n\t\tERR(\"no device name specified\");\n\t\tgoto err;\n\t}\n\n\terr = stat(ifname, &st);\n\tif (err){\n\t\tERRS(\"stat failed on %s\", ifname);\n\t\tgoto err;\n\t}\n\n\tbuflen = st.st_size + sizeof(struct wrg_header);\n\tbuf = malloc(buflen);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto err;\n\t}\n\n\tinfile = fopen(ifname, \"r\");\n\tif (infile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for reading\", ifname);\n\t\tgoto err_free;\n\t}\n\n\terrno = 0;\n\tfread(buf + sizeof(struct wrg_header), st.st_size, 1, infile);\n\tif (errno != 0) {\n\t\tERRS(\"unable to read from file %s\", ifname);\n\t\tgoto close_in;\n\t}\n\n\theader = (struct wrg_header *) buf;\n\tmemset(header, '\\0', sizeof(struct wrg_header));\n\n\tstrncpy(header->signature, signature, sizeof(header->signature));\n\tstrncpy(header->devname, dev_name, sizeof(header->signature));\n\tput_u32(&header->magic1, WRG_MAGIC);\n\tput_u32(&header->magic2, WRG_MAGIC);\n\tput_u32(&header->size, st.st_size);\n\tput_u32(&header->offset, offset);\n\n\tget_digest(header, buf + sizeof(struct wrg_header), st.st_size);\n\n\toutfile = fopen(ofname, \"w\");\n\tif (outfile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto close_in;\n\t}\n\n\terrno = 0;\n\tfwrite(buf, buflen, 1, outfile);\n\tif (errno) {\n\t\tERRS(\"unable to write to file %s\", ofname);\n\t\tgoto close_out;\n\t}\n\n\tfflush(outfile);\n\n\tres = EXIT_SUCCESS;\n\nclose_out:\n\tfclose(outfile);\n\tif (res != EXIT_SUCCESS)\n\t\tunlink(ofname);\nclose_in:\n\tfclose(infile);\nerr_free:\n\tfree(buf);\nerr:\n\treturn res;\n}\n"
  },
  {
    "path": "src/firmware-tools/mkzcfw.c",
    "content": "/*\n * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License version 2 as published\n * by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\n#include \"cyg_crc.h\"\n\n#if (__BYTE_ORDER == __BIG_ENDIAN)\n#  define HOST_TO_BE32(x)\t(x)\n#  define BE32_TO_HOST(x)\t(x)\n#  define HOST_TO_LE32(x)\tbswap_32(x)\n#  define LE32_TO_HOST(x)\tbswap_32(x)\n#else\n#  define HOST_TO_BE32(x)\tbswap_32(x)\n#  define BE32_TO_HOST(x)\tbswap_32(x)\n#  define HOST_TO_LE32(x)\t(x)\n#  define LE32_TO_HOST(x)\t(x)\n#endif\n\n#define MAGIC_FIRMWARE\t0x6d726966\t/* 'firm' */\n#define MAGIC_KERNEL\t0x676d694b\t/* 'Kimg' */\n#define MAGIC_ROOTFS\t0x676d6952\t/* 'Rimg' */\n\nstruct file_info {\n\tchar\t\t*file_name;\t/* name of the file */\n\tuint32_t\tfile_size;\t/* length of the file */\n};\n\nstruct fw_header {\n\tuint32_t\tmagic;\n\tuint32_t\tlength;\n\tuint32_t\tunk1;\n\tuint32_t\tunk2;\n} __attribute__ ((packed));\n\nstruct fw_tail {\n\tuint32_t\thw_id;\n\tuint32_t\tcrc;\n} __attribute__ ((packed));\n\nstruct board_info {\n\tchar\t\t*id;\n\tuint32_t\thw_id;\n\tuint32_t\tkernel_len;\n\tuint32_t\trootfs_len;\n};\n\n/*\n * Globals\n */\nstatic char *ofname;\nstatic char *progname;\n\nstatic char *board_id;\nstatic struct board_info *board;\nstatic struct file_info kernel_info;\nstatic struct file_info rootfs_info;\n\n\nstatic struct board_info boards[] = {\n\t{\n\t\t.id\t\t= \"ZCN-1523H-2-8\",\n\t\t.hw_id\t\t= 0x66661523,\n\t\t.kernel_len\t= 0x170000,\n\t\t.rootfs_len\t= 0x610000,\n\t}, {\n\t\t.id\t\t= \"ZCN-1523H-5-16\",\n\t\t.hw_id\t\t= 0x6615235A,\n\t\t.kernel_len\t= 0x170000,\n\t\t.rootfs_len\t= 0x610000,\n\t}, {\n\t\t/* terminating entry */\n\t}\n};\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\n#define DBG(fmt, ...) do { \\\n\tfprintf(stderr, \"[%s] \" fmt \"\\n\", progname, ## __VA_ARGS__ ); \\\n} while (0)\n\nstatic struct board_info *find_board(char *id)\n{\n\tstruct board_info *ret;\n\tstruct board_info *board;\n\n\tret = NULL;\n\tfor (board = boards; board->id != NULL; board++){\n\t\tif (strcasecmp(id, board->id) == 0) {\n\t\t\tret = board;\n\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn ret;\n}\n\nstatic void usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct board_info *board;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -B <board>      create image for the board specified with <board>\\n\"\n\"  -k <file>       read kernel image from the file <file>\\n\"\n\"  -r <file>       read rootfs image from the file <file>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nstatic int get_file_stat(struct file_info *fdata)\n{\n\tstruct stat st;\n\tint res;\n\n\tif (fdata->file_name == NULL)\n\t\treturn 0;\n\n\tres = stat(fdata->file_name, &st);\n\tif (res){\n\t\tERRS(\"stat failed on %s\", fdata->file_name);\n\t\treturn res;\n\t}\n\n\tfdata->file_size = st.st_size;\n\treturn 0;\n}\n\nstatic int read_to_buf(struct file_info *fdata, char *buf)\n{\n\tFILE *f;\n\tint ret = EXIT_FAILURE;\n\n\tf = fopen(fdata->file_name, \"r\");\n\tif (f == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for reading\", fdata->file_name);\n\t\tgoto out;\n\t}\n\n\terrno = 0;\n\tfread(buf, fdata->file_size, 1, f);\n\tif (errno != 0) {\n\t\tERRS(\"unable to read from file \\\"%s\\\"\", fdata->file_name);\n\t\tgoto out_close;\n\t}\n\n\tret = EXIT_SUCCESS;\n\n out_close:\n\tfclose(f);\n out:\n\treturn ret;\n}\n\nstatic int check_options(void)\n{\n\tint ret;\n\n\tif (board_id == NULL) {\n\t\tERR(\"no board specified\");\n\t\treturn -1;\n\t}\n\n\tboard = find_board(board_id);\n\tif (board == NULL) {\n\t\tERR(\"unknown/unsupported board id \\\"%s\\\"\", board_id);\n\t\treturn -1;\n\t}\n\n\tif (kernel_info.file_name == NULL) {\n\t\tERR(\"no kernel image specified\");\n\t\treturn -1;\n\t}\n\n\tret = get_file_stat(&kernel_info);\n\tif (ret)\n\t\treturn ret;\n\n\tif (kernel_info.file_size > board->kernel_len) {\n\t\tERR(\"kernel image is too big\");\n\t\treturn -1;\n\t}\n\n\tif (rootfs_info.file_name == NULL) {\n\t\tERR(\"no rootfs image specified\");\n\t\treturn -1;\n\t}\n\n\tret = get_file_stat(&rootfs_info);\n\tif (ret)\n\t\treturn ret;\n\n\tif (rootfs_info.file_size > board->rootfs_len) {\n\t\tERR(\"rootfs image is too big\");\n\t\treturn -1;\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\nstatic int write_fw(char *data, int len)\n{\n\tFILE *f;\n\tint ret = EXIT_FAILURE;\n\n\tf = fopen(ofname, \"w\");\n\tif (f == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto out;\n\t}\n\n\terrno = 0;\n\tfwrite(data, len, 1, f);\n\tif (errno) {\n\t\tERRS(\"unable to write output file\");\n\t\tgoto out_flush;\n\t}\n\n\tDBG(\"firmware file \\\"%s\\\" completed\", ofname);\n\n\tret = EXIT_SUCCESS;\n\n out_flush:\n\tfflush(f);\n\tfclose(f);\n\tif (ret != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\n out:\n\treturn ret;\n}\n\nstatic int build_fw(void)\n{\n\tint buflen;\n\tchar *buf;\n\tchar *p;\n\tint ret = EXIT_FAILURE;\n\tint writelen = 0;\n\tuint32_t crc;\n\tstruct fw_header *hdr;\n\tstruct fw_tail *tail;\n\n\tbuflen = 3 * sizeof(struct fw_header) +\n\t\t kernel_info.file_size + rootfs_info.file_size +\n\t\t 3 * sizeof(struct fw_tail);\n\n\tbuf = malloc(buflen);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto out;\n\t}\n\n\tp = buf;\n\tmemset(p, 0, buflen);\n\n\t/* fill firmware header */\n\thdr = (struct fw_header *) p;\n\thdr->magic = HOST_TO_LE32(MAGIC_FIRMWARE);\n\thdr->length = HOST_TO_LE32(buflen - sizeof(struct fw_header));\n\tp += sizeof(struct fw_header);\n\n\t/* fill kernel block header */\n\thdr = (struct fw_header *) p;\n\thdr->magic = HOST_TO_LE32(MAGIC_KERNEL);\n\thdr->length = HOST_TO_LE32(kernel_info.file_size +\n\t\t\t\t   sizeof(struct fw_tail));\n\tp += sizeof(struct fw_header);\n\n\t/* read kernel data */\n\tret = read_to_buf(&kernel_info, p);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\t/* fill firmware tail */\n\ttail = (struct fw_tail *) (p + kernel_info.file_size);\n\ttail->hw_id = HOST_TO_BE32(board->hw_id);\n\ttail->crc = HOST_TO_BE32(cyg_crc32(p, kernel_info.file_size +\n\t\t\t\t \t   sizeof(struct fw_tail) - 4));\n\n\tp += kernel_info.file_size + sizeof(struct fw_tail);\n\n\t/* fill rootfs block header */\n\thdr = (struct fw_header *) p;\n\thdr->magic = HOST_TO_LE32(MAGIC_ROOTFS);\n\thdr->length = HOST_TO_LE32(rootfs_info.file_size +\n\t\t\t\t   sizeof(struct fw_tail));\n\tp += sizeof(struct fw_header);\n\n\t/* read rootfs data */\n\tret = read_to_buf(&rootfs_info, p);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\t/* fill firmware tail */\n\ttail = (struct fw_tail *) (p + rootfs_info.file_size);\n\ttail->hw_id = HOST_TO_BE32(board->hw_id);\n\ttail->crc = HOST_TO_BE32(cyg_crc32(p, rootfs_info.file_size +\n\t\t\t\t \t   sizeof(struct fw_tail) - 4));\n\n\tp += rootfs_info.file_size + sizeof(struct fw_tail);\n\n\t/* fill firmware tail */\n\ttail = (struct fw_tail *) p;\n\ttail->hw_id = HOST_TO_BE32(board->hw_id);\n\ttail->crc = HOST_TO_BE32(cyg_crc32(buf + sizeof(struct fw_header),\n\t\t\t\t buflen - sizeof(struct fw_header) - 4));\n\n\tret = write_fw(buf, buflen);\n\tif (ret)\n\t\tgoto out_free_buf;\n\n\tret = EXIT_SUCCESS;\n\n out_free_buf:\n\tfree(buf);\n out:\n\treturn ret;\n}\n\nint main(int argc, char *argv[])\n{\n\tint ret = EXIT_FAILURE;\n\tint err;\n\n\tFILE *outfile;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"B:k:r:o:h\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'B':\n\t\t\tboard_id = optarg;\n\t\t\tbreak;\n\t\tcase 'k':\n\t\t\tkernel_info.file_name = optarg;\n\t\t\tbreak;\n\t\tcase 'r':\n\t\t\trootfs_info.file_name = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tret = check_options();\n\tif (ret)\n\t\tgoto out;\n\n\tret = build_fw();\n\n out:\n\treturn ret;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/mkzynfw.c",
    "content": "/*\n *\n *  Copyright (C) 2007-2008 OpenWrt.org\n *  Copyright (C) 2007-2008 Gabor Juhos <juhosg at openwrt.org>\n *\n *  This code was based on the information of the ZyXEL's firmware\n *  image format written by Kolja Waschk, can be found at:\n *  http://www.ixo.de/info/zyxel_uclinux\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>\t/* for unlink() */\n#include <libgen.h>\n#include <getopt.h>\t/* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n#include <endian.h>\t/* for __BYTE_ORDER */\n#if defined(__CYGWIN__)\n#  include <byteswap.h>\n#endif\n\n#include \"zynos.h\"\n\n#if (__BYTE_ORDER == __LITTLE_ENDIAN)\n#  define HOST_TO_LE16(x)\t(x)\n#  define HOST_TO_LE32(x)\t(x)\n#  define LE16_TO_HOST(x)\t(x)\n#  define LE32_TO_HOST(x)\t(x)\n#  define HOST_TO_BE16(x)\tbswap_16(x)\n#  define HOST_TO_BE32(x)\tbswap_32(x)\n#  define BE16_TO_HOST(x)\tbswap_16(x)\n#  define BE32_TO_HOST(x)\tbswap_32(x)\n#else\n#  define HOST_TO_BE16(x)\t(x)\n#  define HOST_TO_BE32(x)\t(x)\n#  define BE16_TO_HOST(x)\t(x)\n#  define BE32_TO_HOST(x)\t(x)\n#  define HOST_TO_LE16(x)\tbswap_16(x)\n#  define HOST_TO_LE32(x)\tbswap_32(x)\n#  define LE16_TO_HOST(x)\tbswap_16(x)\n#  define LE32_TO_HOST(x)\tbswap_32(x)\n#endif\n\n#define ALIGN(x,y)\t(((x)+((y)-1)) & ~((y)-1))\n\n#define MAX_NUM_BLOCKS\t8\n#define MAX_ARG_COUNT\t32\n#define MAX_ARG_LEN\t1024\n#define FILE_BUF_LEN\t(16*1024)\n\n\nstruct csum_state{\n\tint\t\todd;\n\tuint32_t\tsum;\n\tuint32_t\ttmp;\n};\n\nstruct fw_block {\n\tuint32_t\talign;\t\t/* alignment of this block */\n\tchar\t\t*file_name;\t/* name of the file */\n\tuint32_t\tfile_size;\t/* length of the file */\n\tchar\t\t*mmap_name;\t/* name in the MMAP table */\n\tint\t\ttype;\t\t/* block type */\n\tuint32_t\tpadlen;\n\tuint8_t\t\tpadc;\n};\n\n#define BLOCK_TYPE_BOOTEXT\t0\n#define BLOCK_TYPE_RAW\t\t1\n\nstruct fw_mmap {\n\tuint32_t\taddr;\n\tuint32_t\tsize;\n\tuint32_t\tuser_addr;\n\tuint32_t\tuser_size;\n};\n#define MMAP_DATA_SIZE\t1024\n#define MMAP_ALIGN\t16\n\nstruct board_info {\n\tchar *name;\t\t/* model name */\n\tchar *desc;\t\t/* description */\n\tuint16_t vendor;\t/* vendor id */\n\tuint16_t model;\t\t/* model id */\n\tuint32_t flash_base;\t/* flash base address */\n\tuint32_t flash_size;\t/* board flash size */\n\tuint32_t code_start;\t/* code start address */\n\tuint32_t romio_offs;\t/* offset of the firmware within the flash */\n\tuint32_t bootext_size;\t/* maximum size of bootext block */\n};\n\n/*\n * Globals\n */\nchar *progname;\nchar *ofname = NULL;\nint verblevel = 0;\n\nstruct board_info *board = NULL;\n\nstruct fw_block blocks[MAX_NUM_BLOCKS];\nstruct fw_block *bootext_block = NULL;\nint num_blocks = 0;\n\n#define ADM5120_FLASH_BASE\t0xBFC00000\n#define ADM5120_CODE_START\t0x80008000\n\n/* TODO: check values for AR7 */\n#define AR7_FLASH_BASE\t\t0xB0000000\n#define AR7_CODE_START\t\t0x94008000\n\n#define ATHEROS_FLASH_BASE\t0xBFC00000\n#define ATHEROS_CODE_START\t0x80e00000\n\n#define AR71XX_FLASH_BASE\t0xBFC00000\n#define AR71XX_CODE_START\t0x81E00000\n\n#define BOARD(n, d, v, m, fb, fs, cs, fo) {\t\t\\\n\t.name = (n), .desc=(d),\t\t\t\t\\\n\t.vendor = (v), .model = (m),\t\t\t\\\n\t.flash_base = (fb), .flash_size = (fs)<<20,\t\\\n\t.code_start = (cs), .romio_offs = (fo),\t\t\\\n\t.bootext_size = BOOTEXT_DEF_SIZE\t\t\\\n\t}\n\n#define ADMBOARD1(n, d, m, fs) BOARD(n, d, ZYNOS_VENDOR_ID_ZYXEL, m, \\\n\tADM5120_FLASH_BASE, fs, ADM5120_CODE_START, 0x8000)\n\n#define ADMBOARD2(n, d, m, fs) BOARD(n, d, ZYNOS_VENDOR_ID_ZYXEL, m, \\\n\tADM5120_FLASH_BASE, fs, ADM5120_CODE_START, 0x10000)\n\n#define AR7BOARD1(n, d, m, fs) BOARD(n, d, ZYNOS_VENDOR_ID_ZYXEL, m, \\\n\tAR7_FLASH_BASE, fs, AR7_CODE_START, 0x8000)\n\n#define ATHEROSBOARD1(n, d, m, fs) BOARD(n, d, ZYNOS_VENDOR_ID_ZYXEL, m, \\\n\tATHEROS_FLASH_BASE, fs, ATHEROS_CODE_START, 0x30000)\n\n#define AR71XXBOARD1(n, d, m, fs) {\t\t\\\n\t.name = (n), .desc=(d),\t\t\t\t\\\n\t.vendor = (ZYNOS_VENDOR_ID_ZYXEL), .model = (m),\t\t\t\\\n\t.flash_base = (AR71XX_FLASH_BASE), .flash_size = (fs)<<20,\t\\\n\t.code_start = (AR71XX_CODE_START), .romio_offs = (0x40000),\t\t\\\n\t.bootext_size = 0x30000\t\t\\\n\t}\n\n\nstatic struct board_info boards[] = {\n\t/*\n\t * Infineon/ADMtek ADM5120 based boards\n\t */\n\tADMBOARD2(\"ES-2024A\",\t\"ZyXEL ES-2024A\", ZYNOS_MODEL_ES_2024A, 4),\n\tADMBOARD2(\"ES-2024PWR\",\t\"ZyXEL ES-2024PWR\", ZYNOS_MODEL_ES_2024PWR, 4),\n\tADMBOARD2(\"ES-2108\",\t\"ZyXEL ES-2108\", ZYNOS_MODEL_ES_2108, 4),\n\tADMBOARD2(\"ES-2108-F\",\t\"ZyXEL ES-2108-F\", ZYNOS_MODEL_ES_2108_F, 4),\n\tADMBOARD2(\"ES-2108-G\",\t\"ZyXEL ES-2108-G\", ZYNOS_MODEL_ES_2108_G, 4),\n\tADMBOARD2(\"ES-2108-LC\",\t\"ZyXEL ES-2108-LC\", ZYNOS_MODEL_ES_2108_LC, 4),\n\tADMBOARD2(\"ES-2108PWR\",\t\"ZyXEL ES-2108PWR\", ZYNOS_MODEL_ES_2108PWR, 4),\n\tADMBOARD1(\"HS-100\",\t\"ZyXEL HomeSafe 100\", ZYNOS_MODEL_HS_100, 2),\n\tADMBOARD1(\"HS-100W\",\t\"ZyXEL HomeSafe 100W\", ZYNOS_MODEL_HS_100W, 2),\n\tADMBOARD1(\"P-334\",\t\"ZyXEL Prestige 334\", ZYNOS_MODEL_P_334, 2),\n\tADMBOARD1(\"P-334U\",\t\"ZyXEL Prestige 334U\", ZYNOS_MODEL_P_334U, 4),\n\tADMBOARD1(\"P-334W\",\t\"ZyXEL Prestige 334W\", ZYNOS_MODEL_P_334W, 2),\n\tADMBOARD1(\"P-334WH\",\t\"ZyXEL Prestige 334WH\", ZYNOS_MODEL_P_334WH, 4),\n\tADMBOARD1(\"P-334WHD\",\t\"ZyXEL Prestige 334WHD\", ZYNOS_MODEL_P_334WHD, 4),\n\tADMBOARD1(\"P-334WT\",\t\"ZyXEL Prestige 334WT\", ZYNOS_MODEL_P_334WT, 4),\n\tADMBOARD1(\"P-335\",\t\"ZyXEL Prestige 335\", ZYNOS_MODEL_P_335, 4),\n\tADMBOARD1(\"P-335Plus\",\t\"ZyXEL Prestige 335Plus\", ZYNOS_MODEL_P_335PLUS, 4),\n\tADMBOARD1(\"P-335U\",\t\"ZyXEL Prestige 335U\", ZYNOS_MODEL_P_335U, 4),\n\tADMBOARD1(\"P-335WT\",\t\"ZyXEL Prestige 335WT\", ZYNOS_MODEL_P_335WT, 4),\n\n\t{\n\t\t.name\t\t= \"P-2602HW-D1A\",\n\t\t.desc\t\t= \"ZyXEL P-2602HW-D1A\",\n\t\t.vendor\t\t= ZYNOS_VENDOR_ID_ZYXEL,\n\t\t.model\t\t= ZYNOS_MODEL_P_2602HW_D1A,\n\t\t.flash_base\t= AR7_FLASH_BASE,\n\t\t.flash_size\t= 4*1024*1024,\n\t\t.code_start\t= 0x94008000,\n\t\t.romio_offs\t= 0x20000,\n\t\t.bootext_size\t= BOOTEXT_DEF_SIZE,\n\t},\n\n#if 0\n\t/*\n\t * Texas Instruments AR7 based boards\n\t */\n\tAR7BOARD1(\"P-660H-61\",  \"ZyXEL P-660H-61\", ZYNOS_MODEL_P_660H_61, 2),\n\tAR7BOARD1(\"P-660H-63\",  \"ZyXEL P-660H-63\", ZYNOS_MODEL_P_660H_63, 2),\n\tAR7BOARD1(\"P-660H-D1\",  \"ZyXEL P-660H-D1\", ZYNOS_MODEL_P_660H_D1, 2),\n\tAR7BOARD1(\"P-660H-D3\",  \"ZyXEL P-660H-D3\", ZYNOS_MODEL_P_660H_D3, 2),\n\tAR7BOARD1(\"P-660HW-61\", \"ZyXEL P-660HW-61\", ZYNOS_MODEL_P_660HW_61, 2),\n\tAR7BOARD1(\"P-660HW-63\", \"ZyXEL P-660HW-63\", ZYNOS_MODEL_P_660HW_63, 2),\n\tAR7BOARD1(\"P-660HW-67\", \"ZyXEL P-660HW-67\", ZYNOS_MODEL_P_660HW_67, 2),\n\tAR7BOARD1(\"P-660HW-D1\", \"ZyXEL P-660HW-D1\", ZYNOS_MODEL_P_660HW_D1, 2),\n\tAR7BOARD1(\"P-660HW-D3\", \"ZyXEL P-660HW-D3\", ZYNOS_MODEL_P_660HW_D3, 2),\n\tAR7BOARD1(\"P-660R-61\",  \"ZyXEL P-660R-61\", ZYNOS_MODEL_P_660R_61, 2),\n\tAR7BOARD1(\"P-660R-61C\", \"ZyXEL P-660R-61C\", ZYNOS_MODEL_P_660R_61C, 2),\n\tAR7BOARD1(\"P-660R-63\",  \"ZyXEL P-660R-63\", ZYNOS_MODEL_P_660R_63, 2),\n\tAR7BOARD1(\"P-660R-63C\", \"ZyXEL P-660R-63C\", ZYNOS_MODEL_P_660R_63C, 2),\n\tAR7BOARD1(\"P-660R-67\",  \"ZyXEL P-660R-67\", ZYNOS_MODEL_P_660R_67, 2),\n\tAR7BOARD1(\"P-660R-D1\",  \"ZyXEL P-660R-D1\", ZYNOS_MODEL_P_660R_D1, 2),\n\tAR7BOARD1(\"P-660R-D3\",  \"ZyXEL P-660R-D3\", ZYNOS_MODEL_P_660R_D3, 2),\n#endif\n\t{\n\t\t.name\t\t= \"O2SURF\",\n\t\t.desc\t\t= \"O2 DSL Surf & Phone\",\n\t\t.vendor\t\t= ZYNOS_VENDOR_ID_O2,\n\t\t.model\t\t= ZYNOS_MODEL_O2SURF,\n\t\t.flash_base\t= AR7_FLASH_BASE,\n\t\t.flash_size\t= 8*1024*1024,\n\t\t.code_start\t= 0x94014000,\n\t\t.romio_offs\t= 0x40000,\n\t\t.bootext_size\t= BOOTEXT_DEF_SIZE,\n\t},\n\n\t/*\n:x\n\t */\n\tATHEROSBOARD1(\"NBG-318S\", \"ZyXEL NBG-318S\", ZYNOS_MODEL_NBG_318S, 4),\n\n\t/*\n\t * Atheros ar71xx based boards\n\t */\n\tAR71XXBOARD1(\"NBG-460N\", \"ZyXEL NBG-460N\", ZYNOS_MODEL_NBG_460N, 4),\n\n\t{.name = NULL}\n};\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \", %s\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\n#define WARN(fmt, ...) do { \\\n\tfprintf(stderr, \"[%s] *** warning: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define DBG(lev, fmt, ...) do { \\\n\tif (verblevel < lev) \\\n\t\tbreak;\\\n\tfprintf(stderr, \"[%s] \" fmt \"\\n\", progname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERR_FATAL\t\t-1\n#define ERR_INVALID_IMAGE\t-2\n\n/*\n * Helper routines\n */\nvoid\nusage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct board_info *board;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -B <board>      create image for the board specified with <board>.\\n\"\n\"                  valid <board> values:\\n\"\n\t);\n\tfor (board = boards; board->name != NULL; board++){\n\t\tfprintf(stream,\n\"                    %-12s= %s\\n\",\n\t\t board->name, board->desc);\n\t};\n\tfprintf(stream,\n\"  -b <file>[:<align>]\\n\"\n\"                  add boot extension block to the image\\n\"\n\"  -r <file>[:<align>]\\n\"\n\"                  add raw block to the image\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\n\n/*\n * argument parsing\n */\nint\nstr2u32(char *arg, uint32_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err)) {\n\t\treturn -1;\n\t}\n\n\t*val = t;\n\treturn 0;\n}\n\n\nint\nstr2u16(char *arg, uint16_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err) || (t >= 0x10000)) {\n\t\treturn -1;\n\t}\n\n\t*val = t & 0xFFFF;\n\treturn 0;\n}\n\nint\nstr2u8(char *arg, uint8_t *val)\n{\n\tchar *err = NULL;\n\tuint32_t t;\n\n\terrno=0;\n\tt = strtoul(arg, &err, 0);\n\tif (errno || (err==arg) || ((err != NULL) && *err) || (t >= 0x100)) {\n\t\treturn -1;\n\t}\n\n\t*val = t & 0xFF;\n\treturn 0;\n}\n\nint\nstr2sig(char *arg, uint32_t *sig)\n{\n\tif (strlen(arg) != 4)\n\t\treturn -1;\n\n\t*sig = arg[0] | (arg[1] << 8) | (arg[2] << 16) | (arg[3] << 24);\n\n\treturn 0;\n}\n\n\nint\nparse_arg(char *arg, char *buf, char *argv[])\n{\n\tint res = 0;\n\tsize_t argl;\n\tchar *tok;\n\tchar **ap = &buf;\n\tint i;\n\n\tmemset(argv, 0, MAX_ARG_COUNT * sizeof(void *));\n\n\tif ((arg == NULL)) {\n\t\t/* no arguments */\n\t\treturn 0;\n\t}\n\n\targl = strlen(arg);\n\tif (argl == 0) {\n\t\t/* no arguments */\n\t\treturn 0;\n\t}\n\n\tif (argl >= MAX_ARG_LEN) {\n\t\t/* argument is too long */\n\t\targl = MAX_ARG_LEN-1;\n\t}\n\n\tmemcpy(buf, arg, argl);\n\tbuf[argl] = '\\0';\n\n\tfor (i = 0; i < MAX_ARG_COUNT; i++) {\n\t\ttok = strsep(ap, \":\");\n\t\tif (tok == NULL) {\n\t\t\tbreak;\n\t\t}\n#if 0\n\t\telse if (tok[0] == '\\0') {\n\t\t\tbreak;\n\t\t}\n#endif\n\t\targv[i] = tok;\n\t\tres++;\n\t}\n\n\treturn res;\n}\n\n\nint\nrequired_arg(char c, char *arg)\n{\n\tif (arg == NULL || *arg != '-')\n\t\treturn 0;\n\n\tERR(\"option -%c requires an argument\\n\", c);\n\treturn -1;\n}\n\n\nint\nis_empty_arg(char *arg)\n{\n\tint ret = 1;\n\tif (arg != NULL) {\n\t\tif (*arg) ret = 0;\n\t};\n\treturn ret;\n}\n\n\nvoid\ncsum_init(struct csum_state *css)\n{\n\tcss->odd = 0;\n\tcss->sum = 0;\n\tcss->tmp = 0;\n}\n\n\nvoid\ncsum_update(uint8_t *p, uint32_t len, struct csum_state *css)\n{\n\tif (len == 0)\n\t\treturn;\n\n\tif (css->odd) {\n\t\tcss->sum += (css->tmp << 8) + p[0];\n\t\tif (css->sum > 0xFFFF) {\n\t\t\tcss->sum += 1;\n\t\t\tcss->sum &= 0xFFFF;\n\t\t}\n\t\tcss->odd = 0;\n\t\tlen--;\n\t\tp++;\n\t}\n\n\tfor ( ; len > 1; len -= 2, p +=2 ) {\n\t\tcss->sum  += (p[0] << 8) + p[1];\n\t\tif (css->sum > 0xFFFF) {\n\t\t\tcss->sum += 1;\n\t\t\tcss->sum &= 0xFFFF;\n\t\t}\n\t}\n\n\tif (len == 1){\n\t\tcss->tmp = p[0];\n\t\tcss->odd = 1;\n\t}\n}\n\n\nuint16_t\ncsum_get(struct csum_state *css)\n{\n\tchar pad = 0;\n\n\tcsum_update(&pad, 1, css);\n\treturn css->sum;\n}\n\nuint16_t\ncsum_buf(uint8_t *p, uint32_t len)\n{\n\tstruct csum_state css;\n\n\tcsum_init(&css);\n\tcsum_update(p, len, &css);\n\treturn csum_get(&css);\n\n}\n\n/*\n * routines to write data to the output file\n */\nint\nwrite_out_data(FILE *outfile, uint8_t *data, size_t len,\n\t\tstruct csum_state *css)\n{\n\terrno = 0;\n\n\tfwrite(data, len, 1, outfile);\n\tif (errno) {\n\t\tERR(\"unable to write output file\");\n\t\treturn -1;\n\t}\n\n\tif (css) {\n\t\tcsum_update(data, len, css);\n\t}\n\n\treturn 0;\n}\n\n\nint\nwrite_out_padding(FILE *outfile, size_t len, uint8_t padc,\n\t\t struct csum_state *css)\n{\n\tuint8_t buf[512];\n\tsize_t buflen = sizeof(buf);\n\n\tmemset(buf, padc, buflen);\n\twhile (len > 0) {\n\t\tif (len < buflen)\n\t\t\tbuflen = len;\n\n\t\tif (write_out_data(outfile, buf, buflen, css))\n\t\t\treturn -1;\n\n\t\tlen -= buflen;\n\t}\n\n\treturn 0;\n}\n\n\nint\nwrite_out_data_align(FILE *outfile, uint8_t *data, size_t len, size_t align,\n\t\tstruct csum_state *css)\n{\n\tsize_t padlen;\n\tint res;\n\n\tres = write_out_data(outfile, data, len, css);\n\tif (res)\n\t\treturn res;\n\n\tpadlen = ALIGN(len,align) - len;\n\tres = write_out_padding(outfile, padlen, 0xFF, css);\n\n\treturn res;\n}\n\n\nint\nwrite_out_header(FILE *outfile, struct zyn_rombin_hdr *hdr)\n{\n\tstruct zyn_rombin_hdr t;\n\n\terrno = 0;\n\tif (fseek(outfile, 0, SEEK_SET) != 0) {\n\t\tERRS(\"fseek failed on output file\");\n\t\treturn -1;\n\t}\n\n\t/* setup temporary header fields */\n\tmemset(&t, 0, sizeof(t));\n\tt.addr = HOST_TO_BE32(hdr->addr);\n\tmemcpy(&t.sig, ROMBIN_SIGNATURE, ROMBIN_SIG_LEN);\n\tt.type = hdr->type;\n\tt.flags = hdr->flags;\n\tt.osize = HOST_TO_BE32(hdr->osize);\n\tt.csize = HOST_TO_BE32(hdr->csize);\n\tt.ocsum = HOST_TO_BE16(hdr->ocsum);\n\tt.ccsum = HOST_TO_BE16(hdr->ccsum);\n\tt.mmap_addr = HOST_TO_BE32(hdr->mmap_addr);\n\n\tDBG(2, \"hdr.addr      = 0x%08x\", hdr->addr);\n\tDBG(2, \"hdr.type      = 0x%02x\", hdr->type);\n\tDBG(2, \"hdr.osize     = 0x%08x\", hdr->osize);\n\tDBG(2, \"hdr.csize     = 0x%08x\", hdr->csize);\n\tDBG(2, \"hdr.flags     = 0x%02x\", hdr->flags);\n\tDBG(2, \"hdr.ocsum     = 0x%04x\", hdr->ocsum);\n\tDBG(2, \"hdr.ccsum     = 0x%04x\", hdr->ccsum);\n\tDBG(2, \"hdr.mmap_addr = 0x%08x\", hdr->mmap_addr);\n\n\treturn write_out_data(outfile, (uint8_t *)&t, sizeof(t), NULL);\n}\n\n\nint\nwrite_out_mmap(FILE *outfile, struct fw_mmap *mmap, struct csum_state *css)\n{\n\tstruct zyn_mmt_hdr *mh;\n\tuint8_t buf[MMAP_DATA_SIZE];\n\tuint32_t user_size;\n\tchar *data;\n\tint res;\n\n\tmemset(buf, 0, sizeof(buf));\n\n\tmh = (struct zyn_mmt_hdr *)buf;\n\n\t/* TODO: needs to recreate the memory map too? */\n\tmh->count=0;\n\n\t/* Build user data section */\n\tdata = buf+sizeof(*mh);\n\tdata += sprintf(data, \"Vendor 1 %d\", board->vendor);\n\t*data++ = '\\0';\n\tdata += sprintf(data, \"Model 1 %d\", BE16_TO_HOST(board->model));\n\t*data++ = '\\0';\n\t/* TODO: make hardware version configurable? */\n\tdata += sprintf(data, \"HwVerRange 2 %d %d\", 0, 0);\n\t*data++ = '\\0';\n\n\tuser_size = (uint8_t *)data - buf;\n\tmh->user_start= HOST_TO_BE32(mmap->addr+sizeof(*mh));\n\tmh->user_end= HOST_TO_BE32(mmap->addr+user_size);\n\tmh->csum = HOST_TO_BE16(csum_buf(buf+sizeof(*mh), user_size));\n\n\tres = write_out_data(outfile, buf, sizeof(buf), css);\n\n\treturn res;\n}\n\n\nint\nblock_stat_file(struct fw_block *block)\n{\n\tstruct stat st;\n\tint res;\n\n\tif (block->file_name == NULL)\n\t\treturn 0;\n\n\tres = stat(block->file_name, &st);\n\tif (res){\n\t\tERRS(\"stat failed on %s\", block->file_name);\n\t\treturn res;\n\t}\n\n\tblock->file_size = st.st_size;\n\treturn 0;\n}\n\n\nint\nread_magic(uint16_t *magic)\n{\n\tFILE *f;\n\tint res;\n\n\terrno = 0;\n\tf = fopen(bootext_block->file_name,\"r\");\n\tif (errno) {\n\t\tERRS(\"unable to open file: %s\", bootext_block->file_name);\n\t\treturn -1;\n\t}\n\n\terrno = 0;\n\tfread(magic, 2, 1, f);\n\tif (errno != 0) {\n\t\tERRS(\"unable to read from file: %s\", bootext_block->file_name);\n\t\tres = -1;\n\t\tgoto err;\n\t}\n\n\tres = 0;\n\nerr:\n\tfclose(f);\n\treturn res;\n}\n\n\nint\nwrite_out_file(FILE *outfile, char *name, size_t len, struct csum_state *css)\n{\n\tchar buf[FILE_BUF_LEN];\n\tsize_t buflen = sizeof(buf);\n\tFILE *f;\n\tint res;\n\n\tDBG(2, \"writing out file, name=%s, len=%d\",\n\t\tname, len);\n\n\terrno = 0;\n\tf = fopen(name,\"r\");\n\tif (errno) {\n\t\tERRS(\"unable to open file: %s\", name);\n\t\treturn -1;\n\t}\n\n\twhile (len > 0) {\n\t\tif (len < buflen)\n\t\t\tbuflen = len;\n\n\t\t/* read data from source file */\n\t\terrno = 0;\n\t\tfread(buf, buflen, 1, f);\n\t\tif (errno != 0) {\n\t\t\tERRS(\"unable to read from file: %s\",name);\n\t\t\tres = -1;\n\t\t\tbreak;\n\t\t}\n\n\t\tres = write_out_data(outfile, buf, buflen, css);\n\t\tif (res)\n\t\t\tbreak;\n\n\t\tlen -= buflen;\n\t}\n\n\tfclose(f);\n\treturn res;\n}\n\n\nint\nwrite_out_block(FILE *outfile, struct fw_block *block, struct csum_state *css)\n{\n\tint res;\n\n\tif (block == NULL)\n\t\treturn 0;\n\n\tif (block->file_name == NULL)\n\t\treturn 0;\n\n\tif (block->file_size == 0)\n\t\treturn 0;\n\n\tres = write_out_file(outfile, block->file_name,\n\t\t\tblock->file_size, css);\n\treturn res;\n}\n\n\nint\nwrite_out_image(FILE *outfile)\n{\n\tstruct fw_block *block;\n\tstruct fw_mmap mmap;\n\tstruct zyn_rombin_hdr hdr;\n\tstruct csum_state css;\n\tint i, res;\n\tuint32_t offset;\n\tuint32_t padlen;\n\tuint16_t csum;\n\tuint16_t t;\n\n\t/* setup header fields */\n\tmemset(&hdr, 0, sizeof(hdr));\n\thdr.addr = board->code_start;\n\thdr.type = OBJECT_TYPE_BOOTEXT;\n\thdr.flags = ROMBIN_FLAG_OCSUM;\n\n\toffset = board->romio_offs;\n\n\tres = write_out_header(outfile, &hdr);\n\tif (res)\n\t\treturn res;\n\n\toffset += sizeof(hdr);\n\n\tcsum_init(&css);\n\tres = write_out_block(outfile, bootext_block, &css);\n\tif (res)\n\t\treturn res;\n\n\toffset += bootext_block->file_size;\n\tif (offset > (board->romio_offs + board->bootext_size)) {\n\t\tERR(\"bootext file '%s' is too big\", bootext_block->file_name);\n\t\treturn -1;\n\t}\n\n\tpadlen = ALIGN(offset, MMAP_ALIGN) - offset;\n\tres = write_out_padding(outfile, padlen, 0xFF, &css);\n\tif (res)\n\t\treturn res;\n\n\toffset += padlen;\n\n\tmmap.addr = board->flash_base + offset;\n\tres = write_out_mmap(outfile, &mmap, &css);\n\tif (res)\n\t\treturn res;\n\n\toffset += MMAP_DATA_SIZE;\n\n\tif ((offset - board->romio_offs) < board->bootext_size) {\n\t\tpadlen = board->romio_offs + board->bootext_size - offset;\n\t\tres = write_out_padding(outfile, padlen, 0xFF, &css);\n\t\tif (res)\n\t\t\treturn res;\n\t\toffset += padlen;\n\n\t\tDBG(2, \"bootext end at %08x\", offset);\n\t}\n\n\tfor (i = 0; i < num_blocks; i++) {\n\t\tblock = &blocks[i];\n\n\t\tif (block->type == BLOCK_TYPE_BOOTEXT)\n\t\t\tcontinue;\n\n\t\tpadlen = ALIGN(offset, block->align) - offset;\n\t\tres = write_out_padding(outfile, padlen, 0xFF, &css);\n\t\tif (res)\n\t\t\treturn res;\n\t\toffset += padlen;\n\n\t\tres = write_out_block(outfile, block, &css);\n\t\tif (res)\n\t\t\treturn res;\n\t\toffset += block->file_size;\n\t}\n\n\tpadlen = ALIGN(offset, 4) - offset;\n\tres = write_out_padding(outfile, padlen, 0xFF, &css);\n\tif (res)\n\t\treturn res;\n\toffset += padlen;\n\n\tcsum = csum_get(&css);\n\thdr.mmap_addr = mmap.addr;\n\thdr.osize = 2;\n\n\tres = read_magic(&hdr.ocsum);\n\tif (res)\n\t\treturn res;\n\thdr.ocsum = BE16_TO_HOST(hdr.ocsum);\n\n\tif (csum <= hdr.ocsum)\n\t\tt = hdr.ocsum - csum;\n\telse\n\t\tt = hdr.ocsum - csum - 1;\n\n\tDBG(2, \"ocsum=%04x, csum=%04x, fix=%04x\", hdr.ocsum, csum, t);\n\n\tt = HOST_TO_BE16(t);\n\tres = write_out_data(outfile, (uint8_t *)&t, 2, NULL);\n\tif (res)\n\t\treturn res;\n\n\n\tres = write_out_header(outfile, &hdr);\n\n\treturn res;\n}\n\n\nstruct board_info *\nfind_board(char *name)\n{\n\tstruct board_info *ret;\n\tstruct board_info *board;\n\n\tret = NULL;\n\tfor (board = boards; board->name != NULL; board++){\n\t\tif (strcasecmp(name, board->name) == 0) {\n\t\t\tret = board;\n\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn ret;\n}\n\n\nint\nparse_opt_board(char ch, char *arg)\n{\n\n\tDBG(1,\"parsing board option: -%c %s\", ch, arg);\n\n\tif (board != NULL) {\n\t\tERR(\"only one board option allowed\");\n\t\treturn -1;\n\t}\n\n\tif (required_arg(ch, arg))\n\t\treturn -1;\n\n\tboard = find_board(arg);\n\tif (board == NULL){\n\t\tERR(\"invalid/unknown board specified: %s\", arg);\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\n\nint\nparse_opt_ofname(char ch, char *arg)\n{\n\n\tif (ofname != NULL) {\n\t\tERR(\"only one output file allowed\");\n\t\treturn -1;\n\t}\n\n\tif (required_arg(ch, arg))\n\t\treturn -1;\n\n\tofname = arg;\n\n\treturn 0;\n}\n\n\nint\nparse_opt_block(char ch, char *arg)\n{\n\tchar buf[MAX_ARG_LEN];\n\tchar *argv[MAX_ARG_COUNT];\n\tint argc;\n\tchar *p;\n\tstruct fw_block *block;\n\tint i;\n\n\tif ( num_blocks >= MAX_NUM_BLOCKS ) {\n\t\tERR(\"too many blocks specified\");\n\t\treturn -1;\n\t}\n\n\tblock = &blocks[num_blocks++];\n\n\t/* setup default field values */\n\tblock->padc = 0xFF;\n\n\tswitch(ch) {\n\tcase 'b':\n\t\tif (bootext_block) {\n\t\t\tERR(\"only one boot extension block allowed\");\n\t\t\tbreak;\n\t\t}\n\t\tblock->type = BLOCK_TYPE_BOOTEXT;\n\t\tbootext_block = block;\n\t\tbreak;\n\tcase 'r':\n\t\tblock->type = BLOCK_TYPE_RAW;\n\t\tbreak;\n\t}\n\n\targc = parse_arg(arg, buf, argv);\n\n\ti = 0;\n\tp = argv[i++];\n\tif (is_empty_arg(p)) {\n\t\tERR(\"no file specified in %s\", arg);\n\t\treturn -1;\n\t} else {\n\t\tblock->file_name = strdup(p);\n\t\tif (block->file_name == NULL) {\n\t\t\tERR(\"not enough memory\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tif (block->type == BLOCK_TYPE_BOOTEXT)\n\t\treturn 0;\n\n\tp = argv[i++];\n\tif (!is_empty_arg(p)) {\n\t\tif (str2u32(p, &block->align) != 0) {\n\t\t\tERR(\"invalid block align in %s\", arg);\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nint\ncalc_block_offsets(int type, uint32_t *offset)\n{\n\tstruct fw_block *block;\n\tuint32_t next_offs;\n\tuint32_t avail;\n\tint i, res;\n\n\tDBG(1,\"calculating block offsets, starting with %lu\",\n\t\t*offset);\n\n\tres = 0;\n\tfor (i = 0; i < num_blocks; i++) {\n\t\tblock = &blocks[i];\n\n\t\tif (block->type != type)\n\t\t\tcontinue;\n\n\t\tnext_offs = ALIGN(*offset, block->align);\n\t\tavail = board->flash_size - next_offs;\n\t\tif (block->file_size > avail) {\n\t\t\tERR(\"file %s is too big, offset = %u, size=%u,\"\n\t\t\t\t\" avail = %u, align = %u\", block->file_name,\n\t\t\t\t(unsigned)next_offs,\n\t\t\t\t(unsigned)block->file_size,\n\t\t\t\t(unsigned)avail,\n\t\t\t\t(unsigned)block->align);\n\t\t\tres = -1;\n\t\t\tbreak;\n\t\t}\n\n\t\tblock->padlen = next_offs - *offset;\n\t\t*offset += block->file_size;\n\t}\n\n\treturn res;\n}\n\nint\nprocess_blocks(void)\n{\n\tstruct fw_block *block;\n\tuint32_t offset;\n\tint i;\n\tint res;\n\n\t/* collecting file stats */\n\tfor (i = 0; i < num_blocks; i++) {\n\t\tblock = &blocks[i];\n\t\tres = block_stat_file(block);\n\t\tif (res)\n\t\t\treturn res;\n\t}\n\n\toffset = board->romio_offs + bootext_block->file_size;\n\tres = calc_block_offsets(BLOCK_TYPE_RAW, &offset);\n\n\treturn res;\n}\n\n\nint\nmain(int argc, char *argv[])\n{\n\tint optinvalid = 0;   /* flag for invalid option */\n\tint c;\n\tint res = EXIT_FAILURE;\n\n\tFILE *outfile;\n\n\tprogname=basename(argv[0]);\n\n\topterr = 0;  /* could not print standard getopt error messages */\n\twhile ( 1 ) {\n\t\toptinvalid = 0;\n\n\t\tc = getopt(argc, argv, \"b:B:ho:r:v\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'b':\n\t\tcase 'r':\n\t\t\toptinvalid = parse_opt_block(c,optarg);\n\t\t\tbreak;\n\t\tcase 'B':\n\t\t\toptinvalid = parse_opt_board(c,optarg);\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\toptinvalid = parse_opt_ofname(c,optarg);\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tverblevel++;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\toptinvalid = 1;\n\t\t\tbreak;\n\t\t}\n\t\tif (optinvalid != 0 ) {\n\t\t\tERR(\"invalid option: -%c\", optopt);\n\t\t\tgoto out;\n\t\t}\n\t}\n\n\tif (board == NULL) {\n\t\tERR(\"no board specified\");\n\t\tgoto out;\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\tgoto out;\n\t}\n\n\tif (optind < argc) {\n\t\tERR(\"invalid option: %s\", argv[optind]);\n\t\tgoto out;\n\t}\n\n\tif (process_blocks() != 0) {\n\t\tgoto out;\n\t}\n\n\toutfile = fopen(ofname, \"w\");\n\tif (outfile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto out;\n\t}\n\n\tif (write_out_image(outfile) != 0)\n\t\tgoto out_flush;\n\n\tDBG(1,\"Image file %s completed.\", ofname);\n\n\tres = EXIT_SUCCESS;\n\nout_flush:\n\tfflush(outfile);\n\tfclose(outfile);\n\tif (res != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\nout:\n\treturn res;\n}\n"
  },
  {
    "path": "src/firmware-tools/motorola-bin.c",
    "content": "/*\n * motorola-bin.c\n *\n * Copyright (C) 2005-2006 Mike Baker,\n *                         Imre Kaloz <kaloz@openwrt.org>\n *                         D. Hugh Redelmeier\n *                         OpenWrt.org\n *\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2\n * of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n *\n */\n\n/*\n * Motorola's firmware flashing code requires an extra header.\n * The header is eight bytes (see struct motorola below).\n * This program will take a firmware file and create a new one\n * with this header:\n *\tmotorola-bin --wr850g WR850G_V403.stripped.trx WR850G_V403.trx\n *\n * Note: Motorola's firmware is distributed with this header.\n * If you need to flash Motorola firmware on a router running OpenWRT,\n * you will to remove this header.  Use the --strip flag:\n *\tmotorola-bin --strip WR850G_V403.trx WR850G_V403.stripped.trx\n */\n\n/*\n * February 1, 2006\n *\n * Add support for for creating WA840G and WE800G images\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stddef.h>\n#include <unistd.h>\n#include <errno.h>\n#include <fcntl.h>\n#include <sys/mman.h>\n#include <string.h>\n#include <netinet/in.h>\n#include <inttypes.h>\n\n#define BPB 8 /* bits/byte */\n\nstatic uint32_t crc32[1<<BPB];\n\nstatic void init_crc32()\n{\n\tconst uint32_t poly = ntohl(0x2083b8ed);\n\tint n;\n\n\tfor (n = 0; n < 1<<BPB; n++) {\n\t\tuint32_t crc = n;\n\t\tint bit;\n\n\t\tfor (bit = 0; bit < BPB; bit++)\n\t\t\tcrc = (crc & 1) ? (poly ^ (crc >> 1)) : (crc >> 1);\n\t\tcrc32[n] = crc;\n\t}\n}\n\nstatic uint32_t crc32buf(unsigned char *buf, size_t len)\n{\n\tuint32_t crc = 0xFFFFFFFF;\n\n\tfor (; len; len--, buf++)\n\t\tcrc = crc32[(uint8_t)crc ^ *buf] ^ (crc >> BPB);\n\treturn crc;\n}\n\nstruct motorola {\n\tuint32_t crc;\t// crc32 of the remainder\n\tuint32_t flags;\t// unknown, 105770*\n};\n\nstatic const struct model {\n\tchar digit;\t/* a digit signifying model (historical) */\n\tconst char *name;\n\tuint32_t flags;\n} models[] = {\n\t{ '1', \"WR850G\", 0x10577050LU },\n\t{ '2', \"WA840G\", 0x10577040LU },\n\t{ '3', \"WE800G\", 0x10577000LU },\n\t{ '\\0', NULL, 0 }\n};\n\nstatic void usage(const char *) __attribute__ (( __noreturn__ ));\n\nstatic void usage(const char *mess)\n{\n\tconst struct model *m;\n\n\tfprintf(stderr, \"Error: %s\\n\", mess);\n\tfprintf(stderr, \"Usage: motorola-bin -device|--strip infile outfile\\n\");\n\tfprintf(stderr, \"Known devices: \");\n\n\tfor (m = models; m->digit != '\\0'; m++)\n\t\tfprintf(stderr, \" %c - %s\", m->digit, m->name);\n\n\tfprintf(stderr, \"\\n\");\n\texit(1);\n}\n\nint main(int argc, char **argv)\n{\n\toff_t len;\t// of original firmware\n\tint fd;\n\tvoid *trx;\t// pointer to original firmware (mmmapped)\n\tstruct motorola *firmware;\t// pionter to prefix + copy of original firmware\n\tuint32_t flags;\n\n\t// verify parameters\n\n\tif (argc != 4)\n\t\tusage(\"wrong number of arguments\");\n\n\t// mmap trx file\n\tif ((fd = open(argv[2], O_RDONLY))  < 0\n\t|| (len = lseek(fd, 0, SEEK_END)) < 0\n\t|| (trx = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0)) == (void *) (-1)\n\t|| close(fd) < 0)\n\t{\n\t\tfprintf(stderr, \"Error loading file %s: %s\\n\", argv[2], strerror(errno));\n\t\texit(1);\n\t}\n\n\tinit_crc32();\n\n\tif (strcmp(argv[1], \"--strip\") == 0)\n\t{\n\t\tconst char *ugh = NULL;\n\n\t\tif (len < sizeof(struct motorola)) {\n\t\t\tugh = \"input file too short\";\n\t\t} else {\n\t\t\tconst struct model *m;\n\n\t\t\tfirmware = trx;\n\t\t\tif (htonl(crc32buf(trx + offsetof(struct motorola, flags), len - offsetof(struct motorola, flags))) != firmware->crc)\n\t\t\t\tugh = \"Invalid CRC\";\n\t\t\tfor (m = models; ; m++) {\n\t\t\t\tif (m->digit == '\\0') {\n\t\t\t\t\tif (ugh == NULL)\n\t\t\t\t\t\tugh = \"unrecognized flags field\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (firmware->flags == htonl(m->flags)) {\n\t\t\t\t\tfprintf(stderr, \"Firmware for Motorola %s\\n\", m->name);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (ugh != NULL) {\n\t\t\tfprintf(stderr, \"%s\\n\", ugh);\n\t\t\texit(3);\n\t\t} else {\n\t\t\t// all is well, write the file without the prefix\n\t\t\tif ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0\n\t\t\t|| write(fd, trx + sizeof(struct motorola), len - sizeof(struct motorola)) !=  len - sizeof(struct motorola)\n\t\t\t|| close(fd) < 0)\n\t\t\t{\n\t\t\t\tfprintf(stderr, \"Error storing file %s: %s\\n\", argv[3], strerror(errno));\n\t\t\t\texit(2);\n\t\t\t}\n\t\t}\n\t\t\n\t} else {\n\t\t// setup the firmware flags magic number\n\t\tconst struct model *m;\n\t\tconst char *df = argv[1];\n\n\t\tif (*df != '-')\n\t\t\tusage(\"first argument must start with -\");\n\t\tif (*++df == '-')\n\t\t\t++df;\t/* allow but don't require second - */\n\n\t\tfor (m = models; ; m++) {\n\t\t\tif (m->digit == '\\0')\n\t\t\t\tusage(\"unrecognized device specified\");\n\t\t\tif ((df[0] == m->digit && df[1] == '\\0') || strcasecmp(df, m->name) == 0) {\n\t\t\t\tflags = m->flags;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\n\t\t// create a firmware image in memory\n\t\t// and copy the trx to it\n\t\tfirmware = malloc(sizeof(struct motorola) + len);\n\t\tmemcpy(&firmware[1], trx, len);\n\n\t\t// setup the motorola headers\n\t\tfirmware->flags = htonl(flags);\n\n\t\t// CRC of flags + firmware\n\t\tfirmware->crc = htonl(crc32buf((unsigned char *)&firmware->flags, sizeof(firmware->flags) + len));\n\n\t\t// write the firmware\n\t\tif ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0\n\t\t|| write(fd, firmware, sizeof(struct motorola) + len) != sizeof(struct motorola) + len\n\t\t|| close(fd) < 0)\n\t\t{\n\t\t\tfprintf(stderr, \"Error storing file %s: %s\\n\", argv[3], strerror(errno));\n\t\t\texit(2);\n\t\t}\n\n\t\tfree(firmware);\n\t}\n\n\tmunmap(trx,len);\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/myloader.h",
    "content": "/*\n *  Copyright (C) 2006-2008 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute  it and/or modify it\n *  under  the terms of  the GNU General  Public License as published by the\n *  Free Software Foundation;  either version 2 of the  License, or (at your\n *  option) any later version.\n *\n */\n\n#ifndef _MYLOADER_H_\n#define _MYLOADER_H_\n\n/*\n * Firmware file format:\n *\n *\t<header>\n *\t[<block descriptor 0>]\n *\t...\n *\t[<block descriptor n>]\n *\t<null block descriptor>\n *\t[<block data 0>]\n *\t...\n *\t[<block data n>]\n *\n *\n */\n\n/* Myloader specific magic numbers */\n#define MYLO_MAGIC_FIRMWARE\t0x4C594D00\n#define MYLO_MAGIC_20021103\t0x20021103\n#define MYLO_MAGIC_20021107\t0x20021107\n\n#define MYLO_MAGIC_SYS_PARAMS\tMYLO_MAGIC_20021107\n#define MYLO_MAGIC_PARTITIONS\tMYLO_MAGIC_20021103\n#define MYLO_MAGIC_BOARD_PARAMS\tMYLO_MAGIC_20021103\n\n/*\n * Addresses of the data structures provided by MyLoader\n */\n#define MYLO_MIPS_SYS_PARAMS\t0x80000800\t/* System Parameters */\n#define MYLO_MIPS_BOARD_PARAMS\t0x80000A00\t/* Board Parameters */\n#define MYLO_MIPS_PARTITIONS\t0x80000C00\t/* Partition Table */\n#define MYLO_MIPS_BOOT_PARAMS\t0x80000E00\t/* Boot Parameters */\n\n/* Vendor ID's (seems to be same as the PCI vendor ID's) */\n#define VENID_COMPEX\t\t0x11F6\n\n/* Devices based on the ADM5120 */\n#define DEVID_COMPEX_NP27G\t0x0078\n#define DEVID_COMPEX_NP28G\t0x044C\n#define DEVID_COMPEX_NP28GHS\t0x044E\n#define DEVID_COMPEX_WP54Gv1C\t0x0514\n#define DEVID_COMPEX_WP54G\t0x0515\n#define DEVID_COMPEX_WP54AG\t0x0546\n#define DEVID_COMPEX_WPP54AG\t0x0550\n#define DEVID_COMPEX_WPP54G\t0x0555\n\n/* Devices based on the Atheros AR2317 */\n#define DEVID_COMPEX_NP25G\t0x05e6\n#define DEVID_COMPEX_WPE53G\t0x05dc\n\n/* Devices based on the Atheros AR71xx */\n#define DEVID_COMPEX_WP543\t0x0640\n#define DEVID_COMPEX_WPE72\t0x0672\n\n/* Devices based on the IXP422 */\n#define DEVID_COMPEX_WP18\t0x047E\n#define DEVID_COMPEX_NP18A\t0x0489\n\n/* Other devices */\n#define DEVID_COMPEX_NP26G8M\t0x03E8\n#define DEVID_COMPEX_NP26G16M\t0x03E9\n\nstruct mylo_fw_header {\n\tuint32_t\tmagic;\t/* must be MYLO_MAGIC_FIRMWARE */\n\tuint32_t\tcrc;\t/* CRC of the whole firmware */\n\tuint32_t\tres0;\t/* unknown/unused */\n\tuint32_t\tres1;\t/* unknown/unused */\n\tuint16_t\tvid;\t/* vendor ID */\n\tuint16_t\tdid;\t/* device ID */\n\tuint16_t\tsvid;\t/* sub vendor ID */\n\tuint16_t\tsdid;\t/* sub device ID */\n\tuint32_t\trev;\t/* device revision */\n\tuint32_t\tfwhi;\t/* FIXME: firmware version high? */\n\tuint32_t\tfwlo;\t/* FIXME: firmware version low? */\n\tuint32_t\tflags;\t/* firmware flags */\n};\n\n#define FW_FLAG_BOARD_PARAMS_WP\t0x01 /* board parameters are write protected */\n#define FW_FLAG_BOOT_SECTOR_WE\t0x02 /* enable of write boot sectors (below 64K) */\n\nstruct mylo_fw_blockdesc {\n\tuint32_t\ttype;\t/* block type */\n\tuint32_t\taddr;\t/* relative address to flash start */\n\tuint32_t\tdlen;\t/* size of block data in bytes */\n\tuint32_t\tblen;\t/* total size of block in bytes */\n};\n\n#define FW_DESC_TYPE_UNUSED\t0\n#define FW_DESC_TYPE_USED\t1\n\nstruct mylo_partition {\n\tuint16_t\tflags;\t/* partition flags */\n\tuint16_t\ttype;\t/* type of the partition */\n\tuint32_t\taddr;\t/* relative address of the partition from the\n\t\t\t\t   flash start */\n\tuint32_t\tsize;\t/* size of the partition in bytes */\n\tuint32_t\tparam;\t/* if this is the active partition, the\n\t\t\t\t   MyLoader load code to this address */\n};\n\n#define PARTITION_FLAG_ACTIVE\t0x8000 /* this is the active partition,\n\t\t\t\t\t* MyLoader loads firmware from here */\n#define PARTITION_FLAG_ISRAM\t0x2000 /* FIXME: this is a RAM partition? */\n#define PARTIIION_FLAG_RAMLOAD\t0x1000 /* FIXME: load this partition into the RAM? */\n#define PARTITION_FLAG_PRELOAD\t0x0800 /* the partition data preloaded to RAM\n\t\t\t\t\t* before decompression */\n#define PARTITION_FLAG_LZMA\t0x0100 /* the partition data compressed with LZMA */\n#define PARTITION_FLAG_HAVEHDR  0x0002 /* the partition data have a header */\n\n#define PARTITION_TYPE_FREE\t0\n#define PARTITION_TYPE_USED\t1\n\n#define MYLO_MAX_PARTITIONS\t8\t/* maximum number of partitions in the\n\t\t\t\t\t   partition table */\n\nstruct mylo_partition_table {\n\tuint32_t\tmagic;\t/* must be MYLO_MAGIC_PARTITIONS */\n\tuint32_t\tres0;\t/* unknown/unused */\n\tuint32_t\tres1;\t/* unknown/unused */\n\tuint32_t \tres2;\t/* unknown/unused */\n\tstruct mylo_partition partitions[MYLO_MAX_PARTITIONS];\n};\n\nstruct mylo_partition_header {\n\tuint32_t\tlen;\t/* length of the partition data */\n\tuint32_t\tcrc;\t/* CRC value of the partition data */\n};\n\nstruct mylo_system_params {\n\tuint32_t\tmagic;\t/* must be MYLO_MAGIC_SYS_PARAMS */\n\tuint32_t\tres0;\n\tuint32_t\tres1;\n\tuint32_t\tmylo_ver;\n\tuint16_t\tvid;\t/* Vendor ID */\n\tuint16_t\tdid;\t/* Device ID */\n\tuint16_t\tsvid;\t/* Sub Vendor ID */\n\tuint16_t\tsdid;\t/* Sub Device ID */\n\tuint32_t\trev;\t/* device revision */\n\tuint32_t\tfwhi;\n\tuint32_t\tfwlo;\n\tuint32_t\ttftp_addr;\n\tuint32_t\tprog_start;\n\tuint32_t\tflash_size;\t/* Size of boot FLASH in bytes */\n\tuint32_t\tdram_size;\t/* Size of onboard RAM in bytes */\n};\n\n\nstruct mylo_eth_addr {\n\tuint8_t\tmac[6];\n\tuint8_t\tcsum[2];\n};\n\n#define MYLO_ETHADDR_COUNT\t8\t/* maximum number of ethernet address\n\t\t\t\t\t   in the board parameters */\n\nstruct mylo_board_params {\n\tuint32_t\tmagic;\t/* must be MYLO_MAGIC_BOARD_PARAMS */\n\tuint32_t\tres0;\n\tuint32_t\tres1;\n\tuint32_t\tres2;\n\tstruct mylo_eth_addr addr[MYLO_ETHADDR_COUNT];\n};\n\n#endif /* _MYLOADER_H_*/\n"
  },
  {
    "path": "src/firmware-tools/nand_ecc.c",
    "content": "/*\n * calculate ecc code for nand flash\n *\n * Copyright (C) 2008 yajin <yajin@vm-kernel.org>\n * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License as\n * published by the Free Software Foundation; either version 2 or\n * (at your option) version 3 of the License.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston,\n * MA 02111-1307 USA\n */\n\n\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <fcntl.h>\n#include <stdio.h>\n\n#define DEF_NAND_PAGE_SIZE   2048\n#define DEF_NAND_OOB_SIZE     64\n#define DEF_NAND_ECC_OFFSET   0x28\n\nstatic int page_size = DEF_NAND_PAGE_SIZE;\nstatic int oob_size = DEF_NAND_OOB_SIZE;\nstatic int ecc_offset = DEF_NAND_ECC_OFFSET;\n\n/*\n * Pre-calculated 256-way 1 byte column parity\n */\nstatic const uint8_t nand_ecc_precalc_table[] = {\n\t0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00,\n\t0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65,\n\t0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66,\n\t0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03,\n\t0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69,\n\t0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c,\n\t0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f,\n\t0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a,\n\t0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a,\n\t0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f,\n\t0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c,\n\t0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69,\n\t0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03,\n\t0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66,\n\t0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65,\n\t0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00\n};\n\n/**\n * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256-byte block\n * @dat:\traw data\n * @ecc_code:\tbuffer for ECC\n */\nint nand_calculate_ecc(const uint8_t *dat,\n\t\t       uint8_t *ecc_code)\n{\n\tuint8_t idx, reg1, reg2, reg3, tmp1, tmp2;\n\tint i;\n\n\t/* Initialize variables */\n\treg1 = reg2 = reg3 = 0;\n\n\t/* Build up column parity */\n\tfor(i = 0; i < 256; i++) {\n\t\t/* Get CP0 - CP5 from table */\n\t\tidx = nand_ecc_precalc_table[*dat++];\n\t\treg1 ^= (idx & 0x3f);\n\n\t\t/* All bit XOR = 1 ? */\n\t\tif (idx & 0x40) {\n\t\t\treg3 ^= (uint8_t) i;\n\t\t\treg2 ^= ~((uint8_t) i);\n\t\t}\n\t}\n\n\t/* Create non-inverted ECC code from line parity */\n\ttmp1  = (reg3 & 0x80) >> 0; /* B7 -> B7 */\n\ttmp1 |= (reg2 & 0x80) >> 1; /* B7 -> B6 */\n\ttmp1 |= (reg3 & 0x40) >> 1; /* B6 -> B5 */\n\ttmp1 |= (reg2 & 0x40) >> 2; /* B6 -> B4 */\n\ttmp1 |= (reg3 & 0x20) >> 2; /* B5 -> B3 */\n\ttmp1 |= (reg2 & 0x20) >> 3; /* B5 -> B2 */\n\ttmp1 |= (reg3 & 0x10) >> 3; /* B4 -> B1 */\n\ttmp1 |= (reg2 & 0x10) >> 4; /* B4 -> B0 */\n\n\ttmp2  = (reg3 & 0x08) << 4; /* B3 -> B7 */\n\ttmp2 |= (reg2 & 0x08) << 3; /* B3 -> B6 */\n\ttmp2 |= (reg3 & 0x04) << 3; /* B2 -> B5 */\n\ttmp2 |= (reg2 & 0x04) << 2; /* B2 -> B4 */\n\ttmp2 |= (reg3 & 0x02) << 2; /* B1 -> B3 */\n\ttmp2 |= (reg2 & 0x02) << 1; /* B1 -> B2 */\n\ttmp2 |= (reg3 & 0x01) << 1; /* B0 -> B1 */\n\ttmp2 |= (reg2 & 0x01) << 0; /* B7 -> B0 */\n\n\t/* Calculate final ECC code */\n#ifdef CONFIG_MTD_NAND_ECC_SMC\n\tecc_code[0] = ~tmp2;\n\tecc_code[1] = ~tmp1;\n#else\n\tecc_code[0] = ~tmp1;\n\tecc_code[1] = ~tmp2;\n#endif\n\tecc_code[2] = ((~reg1) << 2) | 0x03;\n\n\treturn 0;\n}\n\n/*\n *  usage: bb-nandflash-ecc    start_address  size\n */\nvoid usage(const char *prog)\n{\n\tfprintf(stderr, \"Usage: %s [options] <input> <output>\\n\"\n\t\t\"Options:\\n\"\n\t\t\"    -p <pagesize>      NAND page size (default: %d)\\n\"\n\t\t\"    -o <oobsize>       NAND OOB size (default: %d)\\n\"\n\t\t\"    -e <offset>        NAND ECC offset (default: %d)\\n\"\n\t\t\"\\n\", prog, DEF_NAND_PAGE_SIZE, DEF_NAND_OOB_SIZE,\n\t\tDEF_NAND_ECC_OFFSET);\n\texit(1);\n}\n\n/*start_address/size does not include oob\n  */\nint main(int argc, char **argv)\n{\n\tuint8_t *page_data = NULL;\n\tuint8_t *ecc_data;\n\tint infd = -1, outfd = -1;\n\tint ret = 1;\n\tssize_t bytes;\n\tint ch;\n\n\twhile ((ch = getopt(argc, argv, \"e:o:p:\")) != -1) {\n\t\tswitch(ch) {\n\t\tcase 'p':\n\t\t\tpage_size = strtoul(optarg, NULL, 0);\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\toob_size = strtoul(optarg, NULL, 0);\n\t\t\tbreak;\n\t\tcase 'e':\n\t\t\tecc_offset = strtoul(optarg, NULL, 0);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(argv[0]);\n\t\t}\n\t}\n\targc -= optind;\n\tif (argc < 2)\n\t\tusage(argv[0]);\n\n\targv += optind;\n\n\tinfd = open(argv[0], O_RDONLY, 0);\n\tif (infd < 0) {\n\t\tperror(\"open input file\");\n\t\tgoto out;\n\t}\n\n\toutfd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0644);\n\tif (outfd < 0) {\n\t\tperror(\"open output file\");\n\t\tgoto out;\n\t}\n\n\tpage_data = malloc(page_size + oob_size);\n\n\twhile ((bytes = read(infd, page_data, page_size)) == page_size) {\n\t\tint j;\n\n\t\tecc_data = page_data + page_size + ecc_offset;\n\t\tfor (j = 0; j < page_size / 256; j++)\n\t\t{\n\t\t\tnand_calculate_ecc(page_data + j * 256, ecc_data);\n\t\t\tecc_data += 3;\n\t\t}\n\t\twrite(outfd, page_data, page_size + oob_size);\n\t}\n\n\tret = 0;\nout:\n\tif (infd >= 0)\n\t\tclose(infd);\n\tif (outfd >= 0)\n\t\tclose(outfd);\n\tif (page_data)\n\t\tfree(page_data);\n\treturn ret;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/osbridge-crc.c",
    "content": "/*\n *  Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\n#if (__BYTE_ORDER == __LITTLE_ENDIAN)\n#  define HOST_TO_LE16(x)\t(x)\n#  define HOST_TO_LE32(x)\t(x)\n#  define LE16_TO_HOST(x)\t(x)\n#  define LE32_TO_HOST(x)\t(x)\n#else\n#  define HOST_TO_LE16(x)\tbswap_16(x)\n#  define HOST_TO_LE32(x)\tbswap_32(x)\n#  define LE16_TO_HOST(x)\tbswap_16(x)\n#  define LE32_TO_HOST(x)\tbswap_32(x)\n#endif\n\nuint32_t crc32buf(char *buf, size_t len);\n\n/*\n * Globals\n */\nstatic char *ifname;\nstatic char *progname;\nstatic char *ofname;\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\nvoid usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct board_info *board;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -i <file>       read input from the file <file>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\nint main(int argc, char *argv[])\n{\n\tint res = EXIT_FAILURE;\n\tint buflen;\n\tint err;\n\tstruct stat st;\n\tchar *buf;\n\tuint32_t *hdr;\n\tuint32_t crc;\n\n\tFILE *outfile, *infile;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"i:o:h\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'i':\n\t\t\tifname = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (ifname == NULL) {\n\t\tERR(\"no input file specified\");\n\t\tgoto err;\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\tgoto err;\n\t}\n\n\terr = stat(ifname, &st);\n\tif (err){\n\t\tERRS(\"stat failed on %s\", ifname);\n\t\tgoto err;\n\t}\n\n\tbuflen = st.st_size;\n\tbuf = malloc(buflen);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto err;\n\t}\n\n\tinfile = fopen(ifname, \"r\");\n\tif (infile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for reading\", ifname);\n\t\tgoto err_free;\n\t}\n\n\terrno = 0;\n\tfread(buf, buflen, 1, infile);\n\tif (errno != 0) {\n\t\tERRS(\"unable to read from file %s\", ifname);\n\t\tgoto err_close_in;\n\t}\n\n\tcrc = crc32buf(buf, buflen);\n\thdr = (uint32_t *)buf;\n\t*hdr = HOST_TO_LE32(crc);\n\n\toutfile = fopen(ofname, \"w\");\n\tif (outfile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto err_close_in;\n\t}\n\n\terrno = 0;\n\tfwrite(buf, buflen, 1, outfile);\n\tif (errno) {\n\t\tERRS(\"unable to write to file %s\", ofname);\n\t\tgoto err_close_out;\n\t}\n\n\tres = EXIT_SUCCESS;\n\n out_flush:\n\tfflush(outfile);\n\n err_close_out:\n\tfclose(outfile);\n\tif (res != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\n\n err_close_in:\n\tfclose(infile);\n\n err_free:\n\tfree(buf);\n\n err:\n\treturn res;\n}\n\n/**********************************************************************/\n/* The following was grabbed and tweaked from the old snippets collection\n * of public domain C code. */\n\n/**********************************************************************\\\n|* Demonstration program to compute the 32-bit CRC used as the frame  *|\n|* check sequence in ADCCP (ANSI X3.66, also known as FIPS PUB 71     *|\n|* and FED-STD-1003, the U.S. versions of CCITT's X.25 link-level     *|\n|* protocol).  The 32-bit FCS was added via the Federal Register,     *|\n|* 1 June 1982, p.23798.  I presume but don't know for certain that   *|\n|* this polynomial is or will be included in CCITT V.41, which        *|\n|* defines the 16-bit CRC (often called CRC-CCITT) polynomial.  FIPS  *|\n|* PUB 78 says that the 32-bit FCS reduces otherwise undetected       *|\n|* errors by a factor of 10^-5 over 16-bit FCS.                       *|\n\\**********************************************************************/\n\n/* Copyright (C) 1986 Gary S. Brown.  You may use this program, or\n   code or tables extracted from it, as desired without restriction.*/\n\n/* First, the polynomial itself and its table of feedback terms.  The  */\n/* polynomial is                                                       */\n/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */\n/* Note that we take it \"backwards\" and put the highest-order term in  */\n/* the lowest-order bit.  The X^32 term is \"implied\"; the LSB is the   */\n/* X^31 term, etc.  The X^0 term (usually shown as \"+1\") results in    */\n/* the MSB being 1.                                                    */\n\n/* Note that the usual hardware shift register implementation, which   */\n/* is what we're using (we're merely optimizing it by doing eight-bit  */\n/* chunks at a time) shifts bits into the lowest-order term.  In our   */\n/* implementation, that means shifting towards the right.  Why do we   */\n/* do it this way?  Because the calculated CRC must be transmitted in  */\n/* order from highest-order term to lowest-order term.  UARTs transmit */\n/* characters in order from LSB to MSB.  By storing the CRC this way,  */\n/* we hand it to the UART in the order low-byte to high-byte; the UART */\n/* sends each low-bit to hight-bit; and the result is transmission bit */\n/* by bit from highest- to lowest-order term without requiring any bit */\n/* shuffling on our part.  Reception works similarly.                  */\n\n/* The feedback terms table consists of 256, 32-bit entries.  Notes:   */\n/*                                                                     */\n/*  1. The table can be generated at runtime if desired; code to do so */\n/*     is shown later.  It might not be obvious, but the feedback      */\n/*     terms simply represent the results of eight shift/xor opera-    */\n/*     tions for all combinations of data and CRC register values.     */\n/*                                                                     */\n/*  2. The CRC accumulation logic is the same for all CRC polynomials, */\n/*     be they sixteen or thirty-two bits wide.  You simply choose the */\n/*     appropriate table.  Alternatively, because the table can be     */\n/*     generated at runtime, you can start by generating the table for */\n/*     the polynomial in question and use exactly the same \"updcrc\",   */\n/*     if your application needn't simultaneously handle two CRC       */\n/*     polynomials.  (Note, however, that XMODEM is strange.)          */\n/*                                                                     */\n/*  3. For 16-bit CRCs, the table entries need be only 16 bits wide;   */\n/*     of course, 32-bit entries work OK if the high 16 bits are zero. */\n/*                                                                     */\n/*  4. The values must be right-shifted by eight bits by the \"updcrc\"  */\n/*     logic; the shift must be unsigned (bring in zeroes).  On some   */\n/*     hardware you could probably optimize the shift in assembler by  */\n/*     using byte-swap instructions.                                   */\n\nstatic const uint32_t crc_32_tab[] = { /* CRC polynomial 0xedb88320 */\n0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,\n0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,\n0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,\n0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,\n0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,\n0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,\n0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,\n0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,\n0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,\n0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,\n0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,\n0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,\n0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,\n0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,\n0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,\n0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,\n0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\n0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d\n};\n\n#define UPDC32(octet,crc) (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8))\n\nuint32_t crc32buf(char *buf, size_t len)\n{\n      uint32_t crc;\n\n      crc = 0xFFFFFFFF;\n\n      for ( ; len; --len, ++buf)\n      {\n            crc = UPDC32(*buf, crc);\n      }\n\n      return crc ^ 0xFFFFFFFF;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/pc1crypt.c",
    "content": "/*\n *  Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n *  This code was based on:\n *\tPC1 Cipher Algorithm ( Pukall Cipher 1 )\n *\tBy Alexander PUKALL 1991\n *\tfree code no restriction to use\n *\tplease include the name of the Author in the final software\n *\tthe Key is 128 bits\n *\thttp://membres.lycos.fr/pc1/\n *\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     /* for unlink() */\n#include <libgen.h>\n#include <getopt.h>     /* for getopt() */\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\nstruct pc1_ctx {\n\tunsigned short\tax;\n\tunsigned short\tbx;\n\tunsigned short\tcx;\n\tunsigned short\tdx;\n\tunsigned short\tsi;\n\tunsigned short\ttmp;\n\tunsigned short\tx1a2;\n\tunsigned short\tx1a0[8];\n\tunsigned short\tres;\n\tunsigned short\ti;\n\tunsigned short\tinter;\n\tunsigned short\tcfc;\n\tunsigned short\tcfd;\n\tunsigned short\tcompte;\n\tunsigned char\tcle[17];\n\tshort\t\tc;\n};\n\nstatic void pc1_finish(struct pc1_ctx *pc1)\n{\n\t/* erase all variables */\n\tmemset(pc1, 0, sizeof(struct pc1_ctx));\n}\n\nstatic void pc1_code(struct pc1_ctx *pc1)\n{\n\tpc1->dx = pc1->x1a2 + pc1->i;\n\tpc1->ax = pc1->x1a0[pc1->i];\n\tpc1->cx = 0x015a;\n\tpc1->bx = 0x4e35;\n\n\tpc1->tmp = pc1->ax;\n\tpc1->ax = pc1->si;\n\tpc1->si = pc1->tmp;\n\n\tpc1->tmp = pc1->ax;\n\tpc1->ax = pc1->dx;\n\tpc1->dx = pc1->tmp;\n\n\tif (pc1->ax != 0) {\n\t\tpc1->ax = pc1->ax * pc1->bx;\n\t}\n\n\tpc1->tmp = pc1->ax;\n\tpc1->ax = pc1->cx;\n\tpc1->cx = pc1->tmp;\n\n\tif (pc1->ax != 0) {\n\t\tpc1->ax = pc1->ax * pc1->si;\n\t\tpc1->cx = pc1->ax + pc1->cx;\n\t}\n\n\tpc1->tmp = pc1->ax;\n\tpc1->ax = pc1->si;\n\tpc1->si = pc1->tmp;\n\tpc1->ax = pc1->ax * pc1->bx;\n\tpc1->dx = pc1->cx + pc1->dx;\n\n\tpc1->ax = pc1->ax + 1;\n\n\tpc1->x1a2 = pc1->dx;\n\tpc1->x1a0[pc1->i] = pc1->ax;\n\n\tpc1->res = pc1->ax ^ pc1->dx;\n\tpc1->i = pc1->i + 1;\n}\n\nstatic void pc1_assemble(struct pc1_ctx *pc1)\n{\n\tpc1->x1a0[0] = (pc1->cle[0] * 256) + pc1->cle[1];\n\n\tpc1_code(pc1);\n\tpc1->inter = pc1->res;\n\n\tpc1->x1a0[1] = pc1->x1a0[0] ^ ((pc1->cle[2]*256) + pc1->cle[3]);\n\tpc1_code(pc1);\n\tpc1->inter = pc1->inter ^ pc1->res;\n\n\tpc1->x1a0[2] = pc1->x1a0[1] ^ ((pc1->cle[4]*256) + pc1->cle[5]);\n\tpc1_code(pc1);\n\tpc1->inter = pc1->inter ^ pc1->res;\n\n\tpc1->x1a0[3] = pc1->x1a0[2] ^ ((pc1->cle[6]*256) + pc1->cle[7]);\n\tpc1_code(pc1);\n\tpc1->inter = pc1->inter ^ pc1->res;\n\n\tpc1->x1a0[4] = pc1->x1a0[3] ^ ((pc1->cle[8]*256) + pc1->cle[9]);\n\tpc1_code(pc1);\n\tpc1->inter = pc1->inter ^ pc1->res;\n\n\tpc1->x1a0[5] = pc1->x1a0[4] ^ ((pc1->cle[10]*256) + pc1->cle[11]);\n\tpc1_code(pc1);\n\tpc1->inter = pc1->inter ^ pc1->res;\n\n\tpc1->x1a0[6] = pc1->x1a0[5] ^ ((pc1->cle[12]*256) + pc1->cle[13]);\n\tpc1_code(pc1);\n\tpc1->inter = pc1->inter ^ pc1->res;\n\n\tpc1->x1a0[7] = pc1->x1a0[6] ^ ((pc1->cle[14]*256) + pc1->cle[15]);\n\tpc1_code(pc1);\n\tpc1->inter = pc1->inter ^ pc1->res;\n\n\tpc1->i = 0;\n}\n\nstatic unsigned char pc1_decrypt(struct pc1_ctx *pc1, short c)\n{\n\tpc1_assemble(pc1);\n\tpc1->cfc = pc1->inter >> 8;\n\tpc1->cfd = pc1->inter & 255; /* cfc^cfd = random byte */\n\n\tc = c ^ (pc1->cfc ^ pc1->cfd);\n\tfor (pc1->compte = 0; pc1->compte <= 15; pc1->compte++) {\n\t\t/* we mix the plaintext byte with the key */\n\t\tpc1->cle[pc1->compte] = pc1->cle[pc1->compte] ^ c;\n\t}\n\n\treturn c;\n}\n\nstatic unsigned char pc1_encrypt(struct pc1_ctx *pc1, short c)\n{\n\tpc1_assemble(pc1);\n\tpc1->cfc = pc1->inter >> 8;\n\tpc1->cfd = pc1->inter & 255; /* cfc^cfd = random byte */\n\n\tfor (pc1->compte = 0; pc1->compte <= 15; pc1->compte++) {\n\t\t/* we mix the plaintext byte with the key */\n\t\tpc1->cle[pc1->compte] = pc1->cle[pc1->compte] ^ c;\n\t}\n\tc = c ^ (pc1->cfc ^ pc1->cfd);\n\n\treturn c;\n}\n\nstatic void pc1_init(struct pc1_ctx *pc1)\n{\n\tmemset(pc1, 0, sizeof(struct pc1_ctx));\n\n\t/* ('Remsaalps!123456') is the key used, you can change it */\n\tstrcpy(pc1->cle, \"Remsaalps!123456\");\n}\n\nstatic void pc1_decrypt_buf(struct pc1_ctx *pc1, unsigned char *buf,\n\t\t\t    unsigned len)\n{\n\tunsigned i;\n\n\tfor (i = 0; i < len; i++)\n\t\tbuf[i] = pc1_decrypt(pc1, buf[i]);\n}\n\nstatic void pc1_encrypt_buf(struct pc1_ctx *pc1, unsigned char *buf,\n\t\t\t    unsigned len)\n{\n\tunsigned i;\n\n\tfor (i = 0; i < len; i++)\n\t\tbuf[i] = pc1_encrypt(pc1, buf[i]);\n}\n\n/*\n * Globals\n */\nstatic char *ifname;\nstatic char *progname;\nstatic char *ofname;\nstatic int decrypt;\n\n/*\n * Message macros\n */\n#define ERR(fmt, ...) do { \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__ ); \\\n} while (0)\n\n#define ERRS(fmt, ...) do { \\\n\tint save = errno; \\\n\tfflush(0); \\\n\tfprintf(stderr, \"[%s] *** error: \" fmt \"\\n\", \\\n\t\t\tprogname, ## __VA_ARGS__, strerror(save)); \\\n} while (0)\n\nvoid usage(int status)\n{\n\tFILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;\n\tstruct board_info *board;\n\n\tfprintf(stream, \"Usage: %s [OPTIONS...]\\n\", progname);\n\tfprintf(stream,\n\"\\n\"\n\"Options:\\n\"\n\"  -d              decrypt instead of encrypt\"\n\"  -i <file>       read input from the file <file>\\n\"\n\"  -o <file>       write output to the file <file>\\n\"\n\"  -h              show this screen\\n\"\n\t);\n\n\texit(status);\n}\n\n#define BUFSIZE\t\t(64 * 1024)\n\nint main(int argc, char *argv[])\n{\n\tstruct pc1_ctx pc1;\n\tint res = EXIT_FAILURE;\n\tint err;\n\tstruct stat st;\n\tchar *buf;\n\tunsigned total;\n\n\tFILE *outfile, *infile;\n\n\tprogname = basename(argv[0]);\n\n\twhile ( 1 ) {\n\t\tint c;\n\n\t\tc = getopt(argc, argv, \"di:o:h\");\n\t\tif (c == -1)\n\t\t\tbreak;\n\n\t\tswitch (c) {\n\t\tcase 'd':\n\t\t\tdecrypt = 1;\n\t\t\tbreak;\n\t\tcase 'i':\n\t\t\tifname = optarg;\n\t\t\tbreak;\n\t\tcase 'o':\n\t\t\tofname = optarg;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\tusage(EXIT_SUCCESS);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage(EXIT_FAILURE);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (ifname == NULL) {\n\t\tERR(\"no input file specified\");\n\t\tgoto err;\n\t}\n\n\tif (ofname == NULL) {\n\t\tERR(\"no output file specified\");\n\t\tgoto err;\n\t}\n\n\terr = stat(ifname, &st);\n\tif (err){\n\t\tERRS(\"stat failed on %s\", ifname);\n\t\tgoto err;\n\t}\n\n\ttotal = st.st_size;\n\tbuf = malloc(BUFSIZE);\n\tif (!buf) {\n\t\tERR(\"no memory for buffer\\n\");\n\t\tgoto err;\n\t}\n\n\tinfile = fopen(ifname, \"r\");\n\tif (infile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for reading\", ifname);\n\t\tgoto err_free;\n\t}\n\n\toutfile = fopen(ofname, \"w\");\n\tif (outfile == NULL) {\n\t\tERRS(\"could not open \\\"%s\\\" for writing\", ofname);\n\t\tgoto err_close_in;\n\t}\n\n\tpc1_init(&pc1);\n\twhile (total > 0) {\n\t\tunsigned datalen;\n\n\t\tif (total > BUFSIZE)\n\t\t\tdatalen = BUFSIZE;\n\t\telse\n\t\t\tdatalen = total;\n\n\t\terrno = 0;\n\t\tfread(buf, datalen, 1, infile);\n\t\tif (errno != 0) {\n\t\t\tERRS(\"unable to read from file %s\", ifname);\n\t\t\tgoto err_close_out;\n\t\t}\n\n\t\tif (decrypt)\n\t\t\tpc1_decrypt_buf(&pc1, buf, datalen);\n\t\telse\n\t\t\tpc1_encrypt_buf(&pc1, buf, datalen);\n\n\t\terrno = 0;\n\t\tfwrite(buf, datalen, 1, outfile);\n\t\tif (errno) {\n\t\t\tERRS(\"unable to write to file %s\", ofname);\n\t\t\tgoto err_close_out;\n\t\t}\n\n\t\ttotal -= datalen;\n\t}\n\tpc1_finish(&pc1);\n\n\tres = EXIT_SUCCESS;\n\n out_flush:\n\tfflush(outfile);\n\n err_close_out:\n\tfclose(outfile);\n\tif (res != EXIT_SUCCESS) {\n\t\tunlink(ofname);\n\t}\n\n err_close_in:\n\tfclose(infile);\n\n err_free:\n\tfree(buf);\n\n err:\n\treturn res;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/ptgen.c",
    "content": "/* \n * ptgen - partition table generator\n * Copyright (C) 2006 by Felix Fietkau <nbd@openwrt.org>\n *\n * uses parts of afdisk\n * Copyright (C) 2002 by David Roetzel <david@roetzel.de>\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\n */\n\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <string.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include <ctype.h>\n#include <fcntl.h>\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define cpu_to_le16(x) bswap_16(x)\n#elif __BYTE_ORDER == __LITTLE_ENDIAN\n#define cpu_to_le16(x) (x)\n#else\n#error unknown endianness!\n#endif\n\n/* Partition table entry */\nstruct pte { \n\tunsigned char active;\n\tunsigned char chs_start[3];\n\tunsigned char type;\n\tunsigned char chs_end[3];\n\tunsigned int start;\n\tunsigned int length;\n};\n\nstruct partinfo {\n\tunsigned long size;\n\tint type;\n};\n\nint verbose = 0;\nint active = 1;\nint heads = -1;\nint sectors = -1;\nint kb_align = 0;\nstruct partinfo parts[4];\nchar *filename = NULL;\n\n\n/* \n * parse the size argument, which is either\n * a simple number (K assumed) or\n * K, M or G\n *\n * returns the size in KByte\n */\nstatic long to_kbytes(const char *string) {\n\tint exp = 0;\n\tlong result;\n\tchar *end;\n\n\tresult = strtoul(string, &end, 0);\n\tswitch (tolower(*end)) {\n\t\t\tcase 'k' :\n\t\t\tcase '\\0' : exp = 0; break;\n\t\t\tcase 'm' : exp = 1; break;\n\t\t\tcase 'g' : exp = 2; break;\n\t\t\tdefault: return 0;\n\t}\n\n\tif (*end)\n\t\tend++;\n\n\tif (*end) {\n\t\tfprintf(stderr, \"garbage after end of number\\n\");\n\t\treturn 0;\n\t}\n\n\t/* result: number + 1024^(exp) */\n\treturn result * ((2 << ((10 * exp) - 1)) ?: 1);\n}\n\n/* convert the sector number into a CHS value for the partition table */\nstatic void to_chs(long sect, unsigned char chs[3]) {\n\tint c,h,s;\n\t\n\ts = (sect % sectors) + 1;\n\tsect = sect / sectors;\n\th = sect % heads;\n\tsect = sect / heads;\n\tc = sect;\n\n\tchs[0] = h;\n\tchs[1] = s | ((c >> 2) & 0xC0);\n\tchs[2] = c & 0xFF;\n\n\treturn;\n}\n\n/* round the sector number up to the next cylinder */\nstatic inline unsigned long round_to_cyl(long sect) {\n\tint cyl_size = heads * sectors;\n\n\treturn sect + cyl_size - (sect % cyl_size); \n}\n\n/* round the sector number up to the kb_align boundary */\nstatic inline unsigned long round_to_kb(long sect) {\n        return ((sect - 1) / kb_align + 1) * kb_align;\n}\n\n/* check the partition sizes and write the partition table */\nstatic int gen_ptable(int nr)\n{\n\tstruct pte pte[4];\n\tunsigned long sect = 0; \n\tint i, fd, ret = -1, start, len;\n\n\tmemset(pte, 0, sizeof(struct pte) * 4);\n\tfor (i = 0; i < nr; i++) {\n\t\tif (!parts[i].size) {\n\t\t\tfprintf(stderr, \"Invalid size in partition %d!\\n\", i);\n\t\t\treturn -1;\n\t\t}\n\t\tpte[i].active = ((i + 1) == active) ? 0x80 : 0;\n\t\tpte[i].type = parts[i].type;\n\t\tstart = sect + sectors;\n\t\tif (kb_align != 0)\n\t\t\tstart = round_to_kb(start);\n\t\tpte[i].start = cpu_to_le16(start);\n\t\tsect = start + parts[i].size * 2;\n\t\tif (kb_align == 0)\n\t\t\tsect = round_to_cyl(sect);\n\t\tpte[i].length = cpu_to_le16(len = sect - start);\n\t\tto_chs(start, pte[i].chs_start);\n\t\tto_chs(start + len - 1, pte[i].chs_end);\n\t\tif (verbose)\n\t\t\tfprintf(stderr, \"Partition %d: start=%ld, end=%ld, size=%ld\\n\", i, (long) start * 512, ((long) start + (long) len) * 512, (long) len * 512);\n\t\tprintf(\"%ld\\n\", ((long) start * 512));\n\t\tprintf(\"%ld\\n\", ((long) len * 512));\n\t}\n\n\tif ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {\n\t\tfprintf(stderr, \"Can't open output file '%s'\\n\",filename);\n\t\treturn -1;\n\t}\n\n\tlseek(fd, 446, SEEK_SET);\n\tif (write(fd, pte, sizeof(struct pte) * 4) != sizeof(struct pte) * 4) {\n\t\tfprintf(stderr, \"write failed.\\n\");\n\t\tgoto fail;\n\t}\n\tlseek(fd, 510, SEEK_SET);\n\tif (write(fd, \"\\x55\\xaa\", 2) != 2) {\n\t\tfprintf(stderr, \"write failed.\\n\");\n\t\tgoto fail;\n\t}\n\t\n\tret = 0;\nfail:\n\tclose(fd);\n\treturn ret;\n}\n\nstatic void usage(char *prog)\n{\n\tfprintf(stderr,\t\"Usage: %s [-v] -h <heads> -s <sectors> -o <outputfile> [-a 0..4] [-l <align kB>] [[-t <type>] -p <size>...] \\n\", prog);\n\texit(1);\n}\n\nint main (int argc, char **argv)\n{\n\tchar type = 0x83;\n\tint ch;\n\tint part = 0;\n\n\twhile ((ch = getopt(argc, argv, \"h:s:p:a:t:o:vl:\")) != -1) {\n\t\tswitch (ch) {\n\t\tcase 'o':\n\t\t\tfilename = optarg;\n\t\t\tbreak;\n\t\tcase 'v':\n\t\t\tverbose++;\n\t\t\tbreak;\n\t\tcase 'h':\n\t\t\theads = (int) strtoul(optarg, NULL, 0);\n\t\t\tbreak;\n\t\tcase 's':\n\t\t\tsectors = (int) strtoul(optarg, NULL, 0);\n\t\t\tbreak;\n\t\tcase 'p':\n\t\t\tif (part > 3) {\n\t\t\t\tfprintf(stderr, \"Too many partitions\\n\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tparts[part].size = to_kbytes(optarg);\n\t\t\tparts[part++].type = type;\n\t\t\tbreak;\n\t\tcase 't':\n\t\t\ttype = (char) strtoul(optarg, NULL, 16);\n\t\t\tbreak;\n\t\tcase 'a':\n\t\t\tactive = (int) strtoul(optarg, NULL, 0);\n\t\t\tif ((active < 0) || (active > 4))\n\t\t\t\tactive = 0;\n\t\t\tbreak;\n\t\tcase 'l':\n\t\t\tkb_align = (int) strtoul(optarg, NULL, 0) * 2;\n\t\t\tbreak;\n\t\tcase '?':\n\t\tdefault:\n\t\t\tusage(argv[0]);\n\t\t}\n\t}\n\targc -= optind;\n\tif (argc || (heads <= 0) || (sectors <= 0) || !filename) \n\t\tusage(argv[0]);\n\t\n\treturn gen_ptable(part);\n}\n"
  },
  {
    "path": "src/firmware-tools/readme.txt",
    "content": "This is a collection of firmware packaging and obfuscation utilities.\n"
  },
  {
    "path": "src/firmware-tools/seama.c",
    "content": "/* vi: set sw=4 ts=4: */\n/*\n *\tCopyright (C) 2008, Alpha Networks, Inc.\n *\tCreated by David Hsieh <david_hsieh@alphanetworks.com>\n *\tAll right reserved.\n *\n *\t(SEA)ttle i(MA)ge is the image which used in project seattle.\n *\n *\tRedistribution and use in source and binary forms, with or\n *\twithout modification, are permitted provided that the following\n *\tconditions are met:\n *\n *\t1.\tRedistributions of source code must retain the above\n *\t\tcopyright notice, this list of conditions and the following\n *\t\tdisclaimer.\n *\n *\t2.\tRedistributions in binary form must reproduce the above\n *\t\tcopyright notice, this list of conditions and the following\n *\t\tdisclaimer in the documentation and/or other materials\n *\t\tprovided with the distribution.\n *\n *\t3.\tThe name of the author may not be used to endorse or promote\n *\t\tproducts derived from this software without specific prior\n *\t\twritten permission.\n *\n *\tTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY\n *\tEXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\n *\tTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n *\tPARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR\n *\tBE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n *\tEXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\n *\tTO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n *\tDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n *\tON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n *\tLIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n *\tIN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\n *\tTHE POSSIBILITY OF SUCH DAMAGE.\n *\n */\n\n#include <stdio.h>\n#include <stdint.h>\n#include <stdlib.h>\n#include <stdarg.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <string.h>\n#include <arpa/inet.h>\n\n#include \"md5.h\"\n#include \"seama.h\"\n\n#define PROGNAME\t\t\t\"seama\"\n#define VERSION\t\t\t\t\"0.20\"\n#define MAX_SEAMA_META_SIZE\t1024\n#define MAX_META\t\t\t128\n#define MAX_IMAGE\t\t\t128\n\nextern int optind;\nextern char * optarg;\n\nstatic int\t\to_verbose = 0;\t\t/* verbose mode. */\nstatic char *\to_dump = NULL;\t\t/* Seama file to dump. */\nstatic char *\to_seal = NULL;\t\t/* Seal the input images when file name exist. */\nstatic char *\to_extract = NULL;\t/* Extract the seama file. */\nstatic char *\to_images[MAX_IMAGE];/* The image files to pack or seal */\nstatic int\t\to_isize = 0;\t\t/* number of images */\nstatic char *\to_meta[MAX_META];\t/* meta data array */\nstatic int\t\to_msize = 0;\t\t/* size of meta array */\n\nstatic void verbose(const char * format, ...)\n{\n\tva_list marker;\n\tif (o_verbose)\n\t{\n\t\tva_start(marker, format);\n\t\tvfprintf(stdout, format, marker);\n\t\tva_end(marker);\n\t}\n}\n\nstatic void cleanup_exit(int exit_code)\n{\n\tverbose(\"%s: exit with code %d\\n\", PROGNAME, exit_code);\n\texit(exit_code);\n}\n\nstatic void show_usage(int exit_code)\n{\n\tprintf(\tPROGNAME \" version \" VERSION \"\\n\"\n\t\t\t\"usage: \" PROGNAME \" [OPTIONS]\\n\"\n\t\t\t\"  -h                 show this help message.\\n\"\n\t\t\t\"  -v                 verbose mode.\\n\"\n\t\t\t\"  -m {META data}     META data.\\n\"\n\t\t\t\"  -d {file}          dump the info of the seama file.\\n\"\n\t\t\t\"  -i {input file}    image file name.\\n\"\n\t\t\t\"  -s {file}          Seal the images to the seama file.\\n\"\n\t\t\t\"  -x {seama file}    Extract the seama file.\\n\"\n\t\t\t\"\\n\"\n\t\t\t\"  SEAMA can pack the input file (with -i) into a seama file.\\n\"\n\t\t\t\"  ex: seama -i target.file\\n\"\n\t\t\t\"  SEAMA can also seal multiple seama files into a single seama file.\\n\"\n\t\t\t\"  ex: seama -s final.file -i taget1.seama -i target2.seama\\n\"\n\t\t\t\"  To extract the raw image from SEAMA, you need to specify the meta.\\n\"\n\t\t\t\"  The first image match the specified meta will be extract to\\n\"\n\t\t\t\"  the output file which was specified with '-x'.\\n\"\n\t\t\t\"  ex: seama -x output -i seama.image -m file=sealpac\\n\"\n\t\t\t);\n\tcleanup_exit(exit_code);\n}\n\nstatic int parse_args(int argc, char * argv[])\n{\n\tint opt;\n\n\twhile ((opt = getopt(argc, argv, \"hvd:s:i:m:x:\")) > 0)\n\t{\n\t\tswitch (opt)\n\t\t{\n\t\tdefault:\tshow_usage(-1); break;\n\t\tcase 'h':\tshow_usage(0); break;\n\t\tcase 'v':\to_verbose++; break;\n\t\tcase 'd':\to_dump = optarg; break;\n\t\tcase 's':\to_seal = optarg; break;\n\t\tcase 'x':\to_extract = optarg; break;\n\t\tcase 'i':\n\t\t\tif (o_isize < MAX_IMAGE) o_images[o_isize++] = optarg;\n\t\t\telse printf(\"Exceed the maximum acceptable image files.!\\n\");\n\t\t\tbreak;\n\t\tcase 'm':\n\t\t\tif (o_msize < MAX_META) o_meta[o_msize++] = optarg;\n\t\t\telse printf(\"Exceed the maximum acceptable META data.!\\n\");\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn 0;\n}\n\n/*******************************************************************/\n\nstatic size_t calculate_digest(FILE * fh, size_t size, uint8_t * digest)\n{\n\tMD5_CTX ctx;\n\tsize_t bytes_left, bytes_read, i;\n\tuint8_t buf[MAX_SEAMA_META_SIZE];\n\n\tbytes_left = size ? size : sizeof(buf);\n\tbytes_read = 0;\n\n\tMD5_Init(&ctx);\n\twhile (!feof(fh) && !ferror(fh) && bytes_left > 0)\n\t{\n\t\ti = bytes_left < sizeof(buf) ? bytes_left : sizeof(buf);\n\t\ti = fread(buf, sizeof(char), i, fh);\n\t\tif (i > 0)\n\t\t{\n\t\t\tMD5_Update(&ctx, buf, i);\n\t\t\tbytes_read += i;\n\t\t}\n\t\tif (size) bytes_left -= i;\n\t}\n\tMD5_Final(digest, &ctx);\n\treturn bytes_read;\n}\n\n#define READ_BUFF_SIZE 8*1024\nstatic size_t copy_file(FILE * to, FILE * from)\n{\n\tsize_t i, fsize = 0;\n\tuint8_t buf[READ_BUFF_SIZE];\n\n\twhile (!feof(from) && !ferror(from))\n\t{\n\t\ti = fread(buf, sizeof(uint8_t), READ_BUFF_SIZE, from);\n\t\tif (i > 0)\n\t\t{\n\t\t\tfsize += i;\n\t\t\tfwrite(buf, sizeof(uint8_t), i, to);\n\t\t}\n\t}\n\treturn fsize;\n}\n\nstatic int verify_seama(const char * fname, int msg)\n{\n\tFILE * fh = NULL;\n\tstruct stat st;\n\tseamahdr_t shdr;\n\tuint8_t checksum[16];\n\tuint8_t digest[16];\n\tuint8_t buf[MAX_SEAMA_META_SIZE];\n\tsize_t msize, isize, i;\n\tint ret = -1;\n\n#define ERRBREAK(fmt, args...) { if (msg) printf(fmt, ##args); break; }\n\n\tdo\n\t{\n\t\tif (stat(fname, &st) < 0)\t\t\t\tERRBREAK(\"Unable to get the info of '%s'\\n\",fname);\n\t\tif ((fh = fopen(fname, \"r+\"))==NULL)\tERRBREAK(\"Unable to open '%s' for reading!\\n\",fname);\n\n\t\t/* Dump SEAMA header */\n\t\tif (msg) printf(\"FILE - %s (%d bytes)\\n\", fname, (int)st.st_size);\n\n\t\t/* SEAMA */\n\t\twhile (!feof(fh) && !ferror(fh))\n\t\t{\n\t\t\t/* read header */\n\t\t\tif (fread(&shdr, sizeof(shdr), 1, fh) != 1) break;\n\n\t\t\t/* Check the magic number */\n\t\t\tif (shdr.magic != htonl(SEAMA_MAGIC)) ERRBREAK(\"Invalid SEAMA magic. Probably no more SEAMA!\\n\");\n\n\t\t\t/* Get the size */\n\t\t\tisize = ntohl(shdr.size);\n\t\t\tmsize = ntohs(shdr.metasize);\n\n\t\t\t/* The checksum exist only if size is greater than zero. */\n\t\t\tif (isize > 0)\n\t\t\t{\n\t\t\t\tif (fread(checksum, sizeof(checksum), 1, fh) != 1)\n\t\t\t\t\tERRBREAK(\"Error reading checksum !\\n\");\n\t\t\t}\n\n\t\t\t/* Check the META size. */\n\t\t\tif (msize > sizeof(buf)) ERRBREAK(\"META data in SEAMA header is too large!\\n\");\n\n\t\t\t/* Read META data. */\n\t\t\tif (fread(buf, sizeof(char), msize, fh) != msize)\n\t\t\t\tERRBREAK(\"Unable to read SEAMA META data!\\n\");\n\n\t\t\t/* dump header */\n\t\t\tif (msg)\n\t\t\t{\n\t\t\t\tprintf(\"SEAMA ==========================================\\n\");\n\t\t\t\tprintf(\"  magic      : %08x\\n\", ntohl(shdr.magic));\n\t\t\t\tprintf(\"  meta size  : %d bytes\\n\", msize);\n\t\t\t\tfor (i=0; i<msize; i+=(strlen((const char *)&buf[i])+1))\n\t\t\t\t\tprintf(\"  meta data  : %s\\n\", &buf[i]);\n\t\t\t\tprintf(\"  image size : %d bytes\\n\", isize);\n\t\t\t}\n\n\t\t\t/* verify checksum */\n\t\t\tif (isize > 0)\n\t\t\t{\n\t\t\t\tif (msg)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"  checksum   : \");\n\t\t\t\t\tfor (i=0; i<16; i++) printf(\"%02X\", checksum[i]);\n\t\t\t\t\tprintf(\"\\n\");\n\t\t\t\t}\n\n\t\t\t\t/* Calculate the checksum */\n\t\t\t\tcalculate_digest(fh, isize, digest);\n\t\t\t\tif (msg)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"  digest     : \");\n\t\t\t\t\tfor (i=0; i<16; i++) printf(\"%02X\", digest[i]);\n\t\t\t\t\tprintf(\"\\n\");\n\t\t\t\t}\n\n\t\t\t\tif (memcmp(checksum, digest, 16)!=0) ERRBREAK(\"!!ERROR!! checksum error !!\\n\");\n\t\t\t\tret = 0;\n\t\t\t}\n\t\t}\n\t\tif (msg) printf(\"================================================\\n\");\n\t} while (0);\n\tif (fh) fclose(fh);\n\treturn ret;\n}\n\nstatic size_t write_seama_header(FILE * fh, char * meta[], size_t msize, size_t size)\n{\n\tseamahdr_t shdr;\n\tsize_t i;\n\tuint16_t metasize = 0;\n\n\t/* Calculate the META size */\n\tfor (i=0; i<msize; i++) metasize += (strlen(meta[i]) + 1);\n\t//+++ let meta data end on 4 alignment by siyou. 2010/3/1 03:58pm\n\tmetasize = ((metasize+3)/4)*4;\n\tverbose(\"SEAMA META : %d bytes\\n\", metasize);\n\n\t/* Fill up the header, all the data endian should be network byte order. */\n\tshdr.magic\t\t= htonl(SEAMA_MAGIC);\n\tshdr.reserved\t= 0;\n\tshdr.metasize\t= htons(metasize);\n\tshdr.size\t\t= htonl(size);\n\n\t/* Write the header */\n\treturn fwrite(&shdr, sizeof(seamahdr_t), 1, fh);\n}\n\nstatic size_t write_checksum(FILE * fh, uint8_t * checksum)\n{\n\treturn fwrite(checksum, sizeof(uint8_t), 16, fh);\n}\n\nstatic size_t write_meta_data(FILE * fh, char * meta[], size_t size)\n{\n\tsize_t i,j;\n\tsize_t ret = 0;\n\n\tfor (i=0; i<size; i++)\n\t{\n\t\tverbose(\"SEAMA META data : %s\\n\", meta[i]);\n\t\tj = fwrite(meta[i], sizeof(char), strlen(meta[i])+1, fh);\n\t\tif (j != strlen(meta[i])+1) return 0;\n\t\tret += j;\n\t}\n\t//+++ let meta data end on 4 alignment by siyou. 2010/3/1 03:58pm\n\tj = ((ret+3)/4)*4;\n\tfor ( ; ret < j; ret++)\n\t\tfwrite(\"\", sizeof(char), 1, fh);\n\n\treturn ret;\n}\n\n/*******************************************************************/\n\nstatic void dump_seama(const char * fname)\n{\n\tverify_seama(fname, 1);\n}\n\nstatic void seal_files(const char * file)\n{\n\tFILE * fh;\n\tFILE * ifh;\n\tsize_t i;\n\n\t/* Each image should be seama. */\n\tfor (i = 0; i < o_isize; i++)\n\t{\n\t\tif (verify_seama(o_images[i], 0) < 0)\n\t\t{\n\t\t\tprintf(\"'%s' is not a seama file !\\n\",o_images[i]);\n\t\t\treturn;\n\t\t}\n\t}\n\n\t/* Open file for write */\n\tfh = fopen(file, \"w+\");\n\tif (fh)\n\t{\n\t\t/* Write the header. */\n\t\twrite_seama_header(fh, o_meta, o_msize, 0);\n\t\twrite_meta_data(fh, o_meta, o_msize);\n\n\t\t/* Write image files */\n\t\tfor (i=0; i<o_isize; i++)\n\t\t{\n\t\t\tifh = fopen(o_images[i], \"r+\");\n\t\t\tif (ifh)\n\t\t\t{\n\t\t\t\tcopy_file(fh, ifh);\n\t\t\t\tfclose(ifh);\n\t\t\t}\n\t\t}\n\n\t\tfclose(fh);\n\t}\n}\n\nstatic void pack_files(void)\n{\n\tFILE * fh;\n\tFILE * ifh;\n\tsize_t i, fsize;\n\tchar filename[512];\n\tuint8_t digest[16];\n\n\tfor (i=0; i<o_isize; i++)\n\t{\n\t\t/* Open the input file. */\n\t\tifh = fopen(o_images[i], \"r+\");\n\t\tif (ifh)\n\t\t{\n\t\t\tfsize = calculate_digest(ifh, 0, digest);\n\t\t\tverbose(\"file size (%s) : %d\\n\", o_images[i], fsize);\n\t\t\trewind(ifh);\n\n\t\t\t/* Open the output file. */\n\t\t\tsprintf(filename, \"%s.seama\", o_images[i]);\n\t\t\tfh = fopen(filename, \"w+\");\n\t\t\tif (fh)\n\t\t\t{\n\t\t\t\twrite_seama_header(fh, o_meta, o_msize, fsize);\n\t\t\t\twrite_checksum(fh, digest);\n\t\t\t\twrite_meta_data(fh, o_meta, o_msize);\n\t\t\t\tcopy_file(fh, ifh);\n\t\t\t\tfclose(fh);\n\t\t\t}\n\t\t\tfclose(ifh);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintf(\"Unable to open image file '%s'\\n\",o_images[i]);\n\t\t}\n\t}\n}\n\n/**************************************************************************/\n\nstatic int match_meta(const char * meta, size_t size)\n{\n\tsize_t i, j;\n\tint match;\n\n\tfor (i = 0; i < o_msize; i++)\n\t{\n\t\tfor (match = 0, j = 0; j < size; j += (strlen(&meta[j])+1))\n\t\t\tif (strcmp(&meta[j], o_meta[i])==0) { match++; break; }\n\t\tif (!match) return 0;\n\t}\n\treturn 1;\n}\n\n\nstatic void extract_file(const char * output)\n{\n\tFILE * ifh = NULL;\n\tFILE * ofh = NULL;\n\tsize_t msize, isize, i, m;\n\tseamahdr_t shdr;\n\tuint8_t buf[MAX_SEAMA_META_SIZE];\n\tint done = 0;\n\n\t/* We need meta for searching the target image. */\n\tif (o_msize == 0)\n\t{\n\t\tprintf(\"SEAMA: need meta for searching image.\\n\");\n\t\treturn;\n\t}\n\n\t/* Walk through each input file */\n\tfor (i = 0; i < o_isize; i++)\n\t{\n\t\t/* verify the input file */\n\t\tif (verify_seama(o_images[i], 0) < 0)\n\t\t{\n\t\t\tprintf(\"SEAMA: '%s' is not a seama file !\\n\", o_images[i]);\n\t\t\tcontinue;\n\t\t}\n\t\t/* open the input file */\n\t\tifh  = fopen(o_images[i], \"r\");\n\t\tif (!ifh) continue;\n\t\t/* read file */\n\t\twhile (!feof(ifh) && !ferror(ifh))\n\t\t{\n\t\t\t/* read header */\n\t\t\tfread(&shdr, sizeof(shdr), 1, ifh);\n\t\t\tif (shdr.magic != htonl(SEAMA_MAGIC)) break;\n\t\t\t/* Get the size */\n\t\t\tisize = ntohl(shdr.size);\n\t\t\tmsize = ntohs(shdr.metasize);\n\t\t\tif (isize == 0)\n\t\t\t{\n\t\t\t\twhile (msize > 0)\n\t\t\t\t{\n\t\t\t\t\tm = fread(buf, sizeof(char), (msize < MAX_SEAMA_META_SIZE) ? msize : MAX_SEAMA_META_SIZE, ifh);\n\t\t\t\t\tif (m <= 0) break;\n\t\t\t\t\tmsize -= m;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t/* read checksum */\n\t\t\tfread(buf, sizeof(char), 16, ifh);\n\t\t\tif (msize > 0)\n\t\t\t{\n\t\t\t\t/* read META */\n\t\t\t\tfread(buf, sizeof(char), msize, ifh);\n\t\t\t\tif (match_meta((const char *)buf, msize))\n\t\t\t\t{\n\t\t\t\t\tprintf(\"SEAMA: found image @ '%s', image size: %d\\n\", o_images[i], isize);\n\t\t\t\t\t/* open output file */\n\t\t\t\t\tofh = fopen(output, \"w\");\n\t\t\t\t\tif (!ofh) printf(\"SEAMA: unable to open '%s' for writting.\\n\",output);\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\twhile (isize > 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tm = fread(buf, sizeof(char), (isize < MAX_SEAMA_META_SIZE) ? isize : MAX_SEAMA_META_SIZE, ifh);\n\t\t\t\t\t\t\tif (m <= 0) break;\n\t\t\t\t\t\t\tfwrite(buf, sizeof(char), m, ofh);\n\t\t\t\t\t\t\tisize -= m;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfclose(ofh);\n\t\t\t\t\t}\n\t\t\t\t\tdone++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (isize > 0)\n\t\t\t{\n\t\t\t\tm = fread(buf, sizeof(char), (isize < MAX_SEAMA_META_SIZE) ? isize : MAX_SEAMA_META_SIZE, ifh);\n\t\t\t\tif (m <= 0) break;\n\t\t\t\tisize -= m;\n\t\t\t}\n\t\t}\n\t\t/* close the file. */\n\t\tfclose(ifh);\n\t\tif (done) break;\n\t}\n\treturn;\n}\n\n/*******************************************************************/\n#ifdef RGBIN_BOX\nint seama_main(int argc, char * argv[], char * env[])\n#else\nint main(int argc, char * argv[], char * env[])\n#endif\n{\n\tverbose(\"SEAMA version \" VERSION \"\\n\");\n\n\t/* parse the arguments */\n\tif (parse_args(argc, argv) < 0) show_usage(9);\n\n\t/* Do the works */\n\tif\t\t(o_dump)\tdump_seama(o_dump);\n\telse if (o_seal)\tseal_files(o_seal);\n\telse if\t(o_extract)\textract_file(o_extract);\n\telse\t\t\t\tpack_files();\n\n\tcleanup_exit(0);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/seama.h",
    "content": "/* vi: set sw=4 ts=4: */\n/*\n *\t(SEA)ttle i(MA)ge is the image which used in project seattle.\n *\n *\tCreated by David Hsieh <david_hsieh@alphanetworks.com>\n *\tCopyright (C) 2008-2009 Alpha Networks, Inc.\n *\n *\tThis file is free software; you can redistribute it and/or\n *\tmodify it under the terms of the GNU Lesser General Public\n *\tLicense as published by the Free Software Foundation; either'\n *\tversion 2.1 of the License, or (at your option) any later version.\n *\n *\tThe GNU C Library is distributed in the hope that it will be useful,'\n *\tbut WITHOUT ANY WARRANTY; without even the implied warranty of\n *\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n *\tLesser General Public License for more details.\n *\n *\tYou should have received a copy of the GNU Lesser General Public\n *\tLicense along with the GNU C Library; if not, write to the Free\n *\tSoftware Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\n *\t02111-1307 USA.\n */\n\n#ifndef __SEAMA_HEADER_FILE__\n#define __SEAMA_HEADER_FILE__\n\n#include <stdint.h>\n\n#define SEAMA_MAGIC\t\t0x5EA3A417\n\n/*\n *\tSEAMA looks like the following map.\n *\tAll the data of the header should be in network byte order.\n *\n *  +-------------+-------------+------------\n *\t| SEAMA magic               |     ^\n *  +-------------+-------------+     |\n *\t| reserved    | meta size   |     |\n *  +-------------+-------------+   header\n *\t| image size (0 bytes)      |     |\n *  +-------------+-------------+     |\n *\t~ Meta data                 ~     v\n *  +-------------+-------------+------------\n *\t| SEAMA magic               |   ^     ^\n *  +-------------+-------------+   |     |\n *\t| reserved    | meta size   |   |     |\n *  +-------------+-------------+   |     |\n *\t| image size                |   |     |\n *  +-------------+-------------+ header  |\n *\t|                           |   |     |\n *\t| 16 bytes of MD5 digest    |   |     |\n *\t|                           |   |     |\n *\t|                           |   |     |\n *  +-------------+-------------+   |     |\n *\t~ Meta data                 ~   v     |\n *  +-------------+-------------+-------  |\n *\t|                           |         |\n *\t| Image of the 1st entity   |         |\n *\t~                           ~ 1st entity\n *\t|                           |         |\n *\t|                           |         v\n *  +-------------+-------------+-------------\n *\t| SEAMA magic               |   ^     ^\n *  +-------------+-------------+   |     |\n *\t| reserved    | meta size   |   |     |\n *  +-------------+-------------+   |     |\n *\t| image size                |   |     |\n *  +-------------+-------------+ header  |\n *\t|                           |   |     |\n *\t| 16 bytes of MD5 digest    |   |     |\n *\t|                           |   |     |\n *\t|                           |   |     |\n *  +-------------+-------------+   |     |\n *\t~ Meta data                 ~   v     |\n *  +-------------+-------------+-------  |\n *\t|                           |         |\n *\t| Image of the 2nd entity   |         |\n *\t~                           ~ 2nd entity\n *\t|                           |         |\n *\t|                           |         v\n *  +-------------+-------------+-------------\n */\n\n\n/*\n *\tSEAMA header\n *\n *\t|<-------- 32 bits -------->|\n *  +-------------+-------------+\n *\t| SEAMA magic               |\n *  +-------------+-------------+\n *\t| reserved    | meta size   |\n *  +-------------+-------------+\n *\t| image size                |\n *  +-------------+-------------+\n */\n/* seama header */\ntypedef struct seama_hdr\tseamahdr_t;\nstruct seama_hdr\n{\n\tuint32_t\tmagic;\t\t\t/* should always be SEAMA_MAGIC. */\n\tuint16_t\treserved;\t\t/* reserved for  */\n\tuint16_t\tmetasize;\t\t/* size of the META data */\n\tuint32_t\tsize;\t\t\t/* size of the image */\n} __attribute__ ((packed));\n\n\n#endif\n"
  },
  {
    "path": "src/firmware-tools/sha1.c",
    "content": "/*\n *  FIPS-180-1 compliant SHA-1 implementation\n *\n *  Copyright (C) 2003-2006  Christophe Devine\n *\n *  This library is free software; you can redistribute it and/or\n *  modify it under the terms of the GNU Lesser General Public\n *  License, version 2.1 as published by the Free Software Foundation.\n *\n *  This library is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n *  Lesser General Public License for more details.\n *\n *  You should have received a copy of the GNU Lesser General Public\n *  License along with this library; if not, write to the Free Software\n *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n *  MA  02110-1301  USA\n */\n/*\n *  The SHA-1 standard was published by NIST in 1993.\n *\n *  http://www.itl.nist.gov/fipspubs/fip180-1.htm\n */\n\n#ifndef _CRT_SECURE_NO_DEPRECATE\n#define _CRT_SECURE_NO_DEPRECATE 1\n#endif\n\n#include <string.h>\n#include <stdio.h>\n\n#include \"sha1.h\"\n\n/* \n * 32-bit integer manipulation macros (big endian)\n */\n#ifndef GET_UINT32_BE\n#define GET_UINT32_BE(n,b,i)                    \\\n{                                               \\\n    (n) = ( (ulong) (b)[(i)    ] << 24 )        \\\n        | ( (ulong) (b)[(i) + 1] << 16 )        \\\n        | ( (ulong) (b)[(i) + 2] <<  8 )        \\\n        | ( (ulong) (b)[(i) + 3]       );       \\\n}\n#endif\n#ifndef PUT_UINT32_BE\n#define PUT_UINT32_BE(n,b,i)                    \\\n{                                               \\\n    (b)[(i)    ] = (uchar) ( (n) >> 24 );       \\\n    (b)[(i) + 1] = (uchar) ( (n) >> 16 );       \\\n    (b)[(i) + 2] = (uchar) ( (n) >>  8 );       \\\n    (b)[(i) + 3] = (uchar) ( (n)       );       \\\n}\n#endif\n\n/*\n * Core SHA-1 functions\n */\nvoid sha1_starts( sha1_context *ctx )\n{\n    ctx->total[0] = 0;\n    ctx->total[1] = 0;\n\n    ctx->state[0] = 0x67452301;\n    ctx->state[1] = 0xEFCDAB89;\n    ctx->state[2] = 0x98BADCFE;\n    ctx->state[3] = 0x10325476;\n    ctx->state[4] = 0xC3D2E1F0;\n}\n\nvoid sha1_process( sha1_context *ctx, uchar data[64] )\n{\n    ulong temp, W[16], A, B, C, D, E;\n\n    GET_UINT32_BE( W[0],  data,  0 );\n    GET_UINT32_BE( W[1],  data,  4 );\n    GET_UINT32_BE( W[2],  data,  8 );\n    GET_UINT32_BE( W[3],  data, 12 );\n    GET_UINT32_BE( W[4],  data, 16 );\n    GET_UINT32_BE( W[5],  data, 20 );\n    GET_UINT32_BE( W[6],  data, 24 );\n    GET_UINT32_BE( W[7],  data, 28 );\n    GET_UINT32_BE( W[8],  data, 32 );\n    GET_UINT32_BE( W[9],  data, 36 );\n    GET_UINT32_BE( W[10], data, 40 );\n    GET_UINT32_BE( W[11], data, 44 );\n    GET_UINT32_BE( W[12], data, 48 );\n    GET_UINT32_BE( W[13], data, 52 );\n    GET_UINT32_BE( W[14], data, 56 );\n    GET_UINT32_BE( W[15], data, 60 );\n\n#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))\n\n#define R(t)                                            \\\n(                                                       \\\n    temp = W[(t -  3) & 0x0F] ^ W[(t - 8) & 0x0F] ^     \\\n           W[(t - 14) & 0x0F] ^ W[ t      & 0x0F],      \\\n    ( W[t & 0x0F] = S(temp,1) )                         \\\n)\n\n#define P(a,b,c,d,e,x)                                  \\\n{                                                       \\\n    e += S(a,5) + F(b,c,d) + K + x; b = S(b,30);        \\\n}\n\n    A = ctx->state[0];\n    B = ctx->state[1];\n    C = ctx->state[2];\n    D = ctx->state[3];\n    E = ctx->state[4];\n\n#define F(x,y,z) (z ^ (x & (y ^ z)))\n#define K 0x5A827999\n\n    P( A, B, C, D, E, W[0]  );\n    P( E, A, B, C, D, W[1]  );\n    P( D, E, A, B, C, W[2]  );\n    P( C, D, E, A, B, W[3]  );\n    P( B, C, D, E, A, W[4]  );\n    P( A, B, C, D, E, W[5]  );\n    P( E, A, B, C, D, W[6]  );\n    P( D, E, A, B, C, W[7]  );\n    P( C, D, E, A, B, W[8]  );\n    P( B, C, D, E, A, W[9]  );\n    P( A, B, C, D, E, W[10] );\n    P( E, A, B, C, D, W[11] );\n    P( D, E, A, B, C, W[12] );\n    P( C, D, E, A, B, W[13] );\n    P( B, C, D, E, A, W[14] );\n    P( A, B, C, D, E, W[15] );\n    P( E, A, B, C, D, R(16) );\n    P( D, E, A, B, C, R(17) );\n    P( C, D, E, A, B, R(18) );\n    P( B, C, D, E, A, R(19) );\n\n#undef K\n#undef F\n\n#define F(x,y,z) (x ^ y ^ z)\n#define K 0x6ED9EBA1\n\n    P( A, B, C, D, E, R(20) );\n    P( E, A, B, C, D, R(21) );\n    P( D, E, A, B, C, R(22) );\n    P( C, D, E, A, B, R(23) );\n    P( B, C, D, E, A, R(24) );\n    P( A, B, C, D, E, R(25) );\n    P( E, A, B, C, D, R(26) );\n    P( D, E, A, B, C, R(27) );\n    P( C, D, E, A, B, R(28) );\n    P( B, C, D, E, A, R(29) );\n    P( A, B, C, D, E, R(30) );\n    P( E, A, B, C, D, R(31) );\n    P( D, E, A, B, C, R(32) );\n    P( C, D, E, A, B, R(33) );\n    P( B, C, D, E, A, R(34) );\n    P( A, B, C, D, E, R(35) );\n    P( E, A, B, C, D, R(36) );\n    P( D, E, A, B, C, R(37) );\n    P( C, D, E, A, B, R(38) );\n    P( B, C, D, E, A, R(39) );\n\n#undef K\n#undef F\n\n#define F(x,y,z) ((x & y) | (z & (x | y)))\n#define K 0x8F1BBCDC\n\n    P( A, B, C, D, E, R(40) );\n    P( E, A, B, C, D, R(41) );\n    P( D, E, A, B, C, R(42) );\n    P( C, D, E, A, B, R(43) );\n    P( B, C, D, E, A, R(44) );\n    P( A, B, C, D, E, R(45) );\n    P( E, A, B, C, D, R(46) );\n    P( D, E, A, B, C, R(47) );\n    P( C, D, E, A, B, R(48) );\n    P( B, C, D, E, A, R(49) );\n    P( A, B, C, D, E, R(50) );\n    P( E, A, B, C, D, R(51) );\n    P( D, E, A, B, C, R(52) );\n    P( C, D, E, A, B, R(53) );\n    P( B, C, D, E, A, R(54) );\n    P( A, B, C, D, E, R(55) );\n    P( E, A, B, C, D, R(56) );\n    P( D, E, A, B, C, R(57) );\n    P( C, D, E, A, B, R(58) );\n    P( B, C, D, E, A, R(59) );\n\n#undef K\n#undef F\n\n#define F(x,y,z) (x ^ y ^ z)\n#define K 0xCA62C1D6\n\n    P( A, B, C, D, E, R(60) );\n    P( E, A, B, C, D, R(61) );\n    P( D, E, A, B, C, R(62) );\n    P( C, D, E, A, B, R(63) );\n    P( B, C, D, E, A, R(64) );\n    P( A, B, C, D, E, R(65) );\n    P( E, A, B, C, D, R(66) );\n    P( D, E, A, B, C, R(67) );\n    P( C, D, E, A, B, R(68) );\n    P( B, C, D, E, A, R(69) );\n    P( A, B, C, D, E, R(70) );\n    P( E, A, B, C, D, R(71) );\n    P( D, E, A, B, C, R(72) );\n    P( C, D, E, A, B, R(73) );\n    P( B, C, D, E, A, R(74) );\n    P( A, B, C, D, E, R(75) );\n    P( E, A, B, C, D, R(76) );\n    P( D, E, A, B, C, R(77) );\n    P( C, D, E, A, B, R(78) );\n    P( B, C, D, E, A, R(79) );\n\n#undef K\n#undef F\n\n    ctx->state[0] += A;\n    ctx->state[1] += B;\n    ctx->state[2] += C;\n    ctx->state[3] += D;\n    ctx->state[4] += E;\n}\n\nvoid sha1_update( sha1_context *ctx, uchar *input, uint length )\n{\n    ulong left, fill;\n\n    if( ! length ) return;\n\n    left = ctx->total[0] & 0x3F;\n    fill = 64 - left;\n\n    ctx->total[0] += length;\n    ctx->total[0] &= 0xFFFFFFFF;\n\n    if( ctx->total[0] < length )\n        ctx->total[1]++;\n\n    if( left && length >= fill )\n    {\n        memcpy( (void *) (ctx->buffer + left),\n                (void *) input, fill );\n        sha1_process( ctx, ctx->buffer );\n        length -= fill;\n        input  += fill;\n        left = 0;\n    }\n\n    while( length >= 64 )\n    {\n        sha1_process( ctx, input );\n        length -= 64;\n        input  += 64;\n    }\n\n    if( length )\n    {\n        memcpy( (void *) (ctx->buffer + left),\n                (void *) input, length );\n    }\n}\n\nstatic uchar sha1_padding[64] =\n{\n 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\n};\n\nvoid sha1_finish( sha1_context *ctx, uchar digest[20] )\n{\n    ulong last, padn;\n    ulong high, low;\n    uchar msglen[8];\n\n    high = ( ctx->total[0] >> 29 )\n         | ( ctx->total[1] <<  3 );\n    low  = ( ctx->total[0] <<  3 );\n\n    PUT_UINT32_BE( high, msglen, 0 );\n    PUT_UINT32_BE( low,  msglen, 4 );\n\n    last = ctx->total[0] & 0x3F;\n    padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );\n\n    sha1_update( ctx, sha1_padding, padn );\n    sha1_update( ctx, msglen, 8 );\n\n    PUT_UINT32_BE( ctx->state[0], digest,  0 );\n    PUT_UINT32_BE( ctx->state[1], digest,  4 );\n    PUT_UINT32_BE( ctx->state[2], digest,  8 );\n    PUT_UINT32_BE( ctx->state[3], digest, 12 );\n    PUT_UINT32_BE( ctx->state[4], digest, 16 );\n}\n\n/*\n * Output SHA-1(file contents), returns 0 if successful.\n */\nint sha1_file( char *filename, uchar digest[20] )\n{\n    FILE *f;\n    size_t n;\n    sha1_context ctx;\n    uchar buf[1024];\n\n    if( ( f = fopen( filename, \"rb\" ) ) == NULL )\n        return( 1 );\n\n    sha1_starts( &ctx );\n\n    while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )\n        sha1_update( &ctx, buf, (uint) n );\n\n    sha1_finish( &ctx, digest );\n\n    fclose( f );\n    return( 0 );\n}\n\n/*\n * Output SHA-1(buf)\n */\nvoid sha1_csum( uchar *buf, uint buflen, uchar digest[20] )\n{\n    sha1_context ctx;\n\n    sha1_starts( &ctx );\n    sha1_update( &ctx, buf, buflen );\n    sha1_finish( &ctx, digest );\n}\n\n/*\n * Output HMAC-SHA-1(key,buf)\n */\nvoid sha1_hmac( uchar *key, uint keylen, uchar *buf, uint buflen,\n                uchar digest[20] )\n{\n    uint i;\n    sha1_context ctx;\n    uchar k_ipad[64];\n    uchar k_opad[64];\n    uchar tmpbuf[20];\n\n    memset( k_ipad, 0x36, 64 );\n    memset( k_opad, 0x5C, 64 );\n\n    for( i = 0; i < keylen; i++ )\n    {\n        if( i >= 64 ) break;\n\n        k_ipad[i] ^= key[i];\n        k_opad[i] ^= key[i];\n    }\n\n    sha1_starts( &ctx );\n    sha1_update( &ctx, k_ipad, 64 );\n    sha1_update( &ctx, buf, buflen );\n    sha1_finish( &ctx, tmpbuf );\n\n    sha1_starts( &ctx );\n    sha1_update( &ctx, k_opad, 64 );\n    sha1_update( &ctx, tmpbuf, 20 );\n    sha1_finish( &ctx, digest );\n\n    memset( k_ipad, 0, 64 );\n    memset( k_opad, 0, 64 );\n    memset( tmpbuf, 0, 20 );\n    memset( &ctx, 0, sizeof( sha1_context ) );\n}\n\n#ifdef SELF_TEST\n/* \n * FIPS-180-1 test vectors\n */\nstatic char *sha1_test_str[3] = \n{\n    \"abc\",\n    \"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\",\n    NULL\n};\n\nstatic uchar sha1_test_sum[3][20] =\n{\n    { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,\n      0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },\n    { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,\n      0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },\n    { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,\n      0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }\n};\n\n/*\n * Checkup routine\n */\nint sha1_self_test( void )\n{\n    int i, j;\n    uchar buf[1000];\n    uchar sha1sum[20];\n    sha1_context ctx;\n\n    for( i = 0; i < 3; i++ )\n    {\n        printf( \"  SHA-1 test #%d: \", i + 1 );\n\n        sha1_starts( &ctx );\n\n        if( i < 2 )\n            sha1_update( &ctx, (uchar *) sha1_test_str[i],\n                         strlen( sha1_test_str[i] ) );\n        else\n        {\n            memset( buf, 'a', 1000 );\n            for( j = 0; j < 1000; j++ )\n                sha1_update( &ctx, (uchar *) buf, 1000 );\n        }\n\n        sha1_finish( &ctx, sha1sum );\n\n        if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 )\n        {\n            printf( \"failed\\n\" );\n            return( 1 );\n        }\n\n        printf( \"passed\\n\" );\n    }\n\n    printf( \"\\n\" );\n    return( 0 );\n}\n#else\nint sha1_self_test( void )\n{\n    printf( \"SHA-1 self-test not available\\n\\n\" );\n    return( 1 );\n}\n#endif\n"
  },
  {
    "path": "src/firmware-tools/sha1.h",
    "content": "#ifndef _SHA1_H\n#define _SHA1_H\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#ifndef _STD_TYPES\n#define _STD_TYPES\n\n#define uchar   unsigned char\n#define uint    unsigned int\n#define ulong   unsigned long int\n\n#endif\n\ntypedef struct\n{\n    ulong total[2];\n    ulong state[5];\n    uchar buffer[64];\n}\nsha1_context;\n\n/*\n * Core SHA-1 functions\n */\nvoid sha1_starts( sha1_context *ctx );\nvoid sha1_update( sha1_context *ctx, uchar *input, uint length );\nvoid sha1_finish( sha1_context *ctx, uchar digest[20] );\n\n/*\n * Output SHA-1(file contents), returns 0 if successful.\n */\nint sha1_file( char *filename, uchar digest[20] );\n\n/*\n * Output SHA-1(buf)\n */\nvoid sha1_csum( uchar *buf, uint buflen, uchar digest[20] );\n\n/*\n * Output HMAC-SHA-1(key,buf)\n */\nvoid sha1_hmac( uchar *key, uint keylen, uchar *buf, uint buflen,\n                uchar digest[20] );\n\n/*\n * Checkup routine\n */\nint sha1_self_test( void );\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* sha1.h */\n"
  },
  {
    "path": "src/firmware-tools/spw303v.c",
    "content": "/*\n * spw303v.c - partially based on OpenWrt's imagetag.c and addpattern.c\n *\n * Copyright (C) 2011  Jonas Gorski <jonas.gorski@gmail.com>\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdint.h>\n#include <time.h>\n#include <unistd.h>\n#include <sys/stat.h>\n\n#define IMAGE_LEN 10                   /* Length of Length Field */\n#define ADDRESS_LEN 12                 /* Length of Address field */\n#define TAGID_LEN  6                   /* Length of tag ID */\n#define TAGINFO_LEN 20                 /* Length of vendor information field in tag */\n#define TAGVER_LEN 4                   /* Length of Tag Version */\n#define TAGLAYOUT_LEN 4                /* Length of FlashLayoutVer */\n\n\nstruct spw303v_tag\n{\n    unsigned char tagVersion[4];       // tag version.  Will be 2 here.\n    unsigned char signiture_1[20];         \t\t // text line for company info\n    unsigned char signiture_2[14];        \t\t// additional info (can be version number)\n    unsigned char chipId[6];\t\t\t \t\t// chip id\n    unsigned char boardId[16];        \t\t \t// board id\n    unsigned char bigEndian[2];           \t\t// if = 1 - big, = 0 - little endia of the host\n    unsigned char totalImageLen[IMAGE_LEN];      // the sum of all the following length\n    unsigned char cfeAddress[ADDRESS_LEN];       // if non zero, cfe starting address\n    unsigned char cfeLen[IMAGE_LEN];             // if non zero, cfe size in clear ASCII text.\n    unsigned char rootfsAddress[ADDRESS_LEN];    // if non zero, filesystem starting address\n    unsigned char rootfsLen[IMAGE_LEN];          // if non zero, filesystem size in clear ASCII text.\n    unsigned char kernelAddress[ADDRESS_LEN];    // if non zero, kernel starting address\n    unsigned char kernelLen[IMAGE_LEN];          // if non zero, kernel size in clear ASCII text.\n\n\tunsigned char certf1Address[ADDRESS_LEN];\n\tunsigned char certf1Len[6];\n\tunsigned char certf2Address[ADDRESS_LEN];\n\tunsigned char certf2Len[6];\n\tunsigned char certf3Address[ADDRESS_LEN];\n\tunsigned char certf3Len[6];\n\tunsigned char httpsFileSize[4];\n\tunsigned char tr64FileSize[4];\n\tunsigned char tr69FileSize[4];\n\tunsigned char filesmap[4];\n\n    unsigned char imageSequence[4];     \t\t\t// incrments everytime an image is flashed\n    unsigned char reserved[4];\t\t\t\t\t    // reserved for later use\n    unsigned char imageCRC[4];                      // 216-219: CRC32 of images\n    unsigned char reserved2[16];                    // 220-235: Unused at present\n    unsigned char headerCRC[4];                     // 236-239: CRC32 of header excluding tagVersion\n    unsigned char reserved3[16];                    // 240-255: Unused at present\n};\n\nstatic uint32_t crc32tab[256] = {\n\t0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,\n\t0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,\n\t0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,\n\t0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,\n\t0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,\n\t0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,\n\t0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,\n\t0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,\n\t0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,\n\t0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,\n\t0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,\n\t0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,\n\t0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,\n\t0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,\n\t0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,\n\t0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,\n\t0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,\n\t0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,\n\t0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,\n\t0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,\n\t0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,\n\t0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,\n\t0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,\n\t0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,\n\t0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,\n\t0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,\n\t0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,\n\t0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,\n\t0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,\n\t0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,\n\t0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,\n\t0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D\n};\n#define IMAGETAG_CRC_START\t\t\t0xFFFFFFFF\n\n#define IMAGETAG_MAGIC1_TCOM\t\t\"AAAAAAAA Corporatio\"\n\nstatic char fake_data[] = {\n        0x18, 0x21, 0x21, 0x18, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21 ,0x18,\n        0x21, 0x24, 0x21, 0x1b, 0x18, 0x18, 0x24, 0x24, 0x18, 0x21, 0x21, 0x21,\n        0x21, 0x21, 0x21, 0x21, 0x1b, 0x18, 0x18, 0x24, 0x24, 0x21, 0x21, 0x21,\n        0x21, 0x21, 0x21, 0x21, 0x18, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x18,\n        0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x18, 0x21, 0x21,\n        0x21, 0x21, 0x21, 0x21,\n};\n\n\nuint32_t crc32(uint32_t crc, uint8_t *data, size_t len)\n{\n\twhile (len--)\n\t\tcrc = (crc >> 8) ^ crc32tab[(crc ^ *data++) & 0xFF];\n\n\treturn crc;\n}\n\nvoid fix_header(void *buf)\n{\n\tstruct spw303v_tag *tag = buf;\n\tuint32_t crc;\n\t/* Replace signature with custom t-com one */\n\tmemset(tag->signiture_1, 0, 20);\n\tmemcpy(tag->signiture_1, IMAGETAG_MAGIC1_TCOM, strlen(IMAGETAG_MAGIC1_TCOM));\n\n\t/* Clear cert fields to remove information_* data */\n\tmemset(tag->certf1Address, 0, 74);\n\n\t/* replace image crc with modified one */\n\tcrc = ntohl(*((uint32_t *)&tag->imageCRC));\n\n\tcrc = htonl(crc32(crc, fake_data, 64));\n\n\tmemcpy(tag->imageCRC, &crc, 4);\n\n\t/* Update tag crc */\n\tcrc = htonl(crc32(IMAGETAG_CRC_START, buf, 236));\n\tmemcpy(tag->headerCRC, &crc, 4);\n}\n\n\n\nvoid usage(void) __attribute__ (( __noreturn__ ));\n\nvoid usage(void)\n{\n\tfprintf(stderr, \"Usage: spw303v [-i <inputfile>] [-o <outputfile>]\\n\");\n\texit(EXIT_FAILURE);\n}\n\n\nint main(int argc, char **argv)\n{\n\tchar buf[1024];\t/* keep this at 1k or adjust garbage calc below */\n\tFILE *in = stdin;\n\tFILE *out = stdout;\n\tchar *ifn = NULL;\n\tchar *ofn = NULL;\n\tint c;\n\tint v0, v1, v2;\n\tsize_t n;\n\tint first_block = 1;\n\n\tuint32_t image_crc = IMAGETAG_CRC_START;\n\n\twhile ((c = getopt(argc, argv, \"i:o:h\")) != -1) {\n\t\tswitch (c) {\n\t\t\tcase 'i':\n\t\t\t\tifn = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'o':\n\t\t\t\tofn = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'h':\n\t\t\tdefault:\n\t\t\t\tusage();\n\t\t}\n\t}\n\n\tif (optind != argc || optind == 1) {\n\t\tfprintf(stderr, \"illegal arg \\\"%s\\\"\\n\", argv[optind]);\n\t\tusage();\n\t}\n\n\tif (ifn && !(in = fopen(ifn, \"r\"))) {\n\t\tfprintf(stderr, \"can not open \\\"%s\\\" for reading\\n\", ifn);\n\t\tusage();\n\t}\n\n\tif (ofn && !(out = fopen(ofn, \"w\"))) {\n\t\tfprintf(stderr, \"can not open \\\"%s\\\" for writing\\n\", ofn);\n\t\tusage();\n\t}\n\n\n\n\twhile ((n = fread(buf, 1, sizeof(buf), in)) > 0) {\n\t\tif (n < sizeof(buf)) {\n\t\t\tif (ferror(in)) {\n\t\t\tFREAD_ERROR:\n\t\t\t\tfprintf(stderr, \"fread error\\n\");\n\t\t\t\treturn EXIT_FAILURE;\n\t\t\t}\n\t\t}\n\n\t\tif (first_block && n >= 256) {\n\t\t\tfix_header(buf);\n\t\t\tfirst_block = 0;\n\t\t}\n\n\t\timage_crc = crc32(image_crc, buf, n);\n\n\t\tif (!fwrite(buf, n, 1, out)) {\n\t\tFWRITE_ERROR:\n\t\t\tfprintf(stderr, \"fwrite error\\n\");\n\t\t\treturn EXIT_FAILURE;\n\t\t}\n\t}\n\n\tif (ferror(in)) {\n\t\tgoto FREAD_ERROR;\n\t}\n\n\tif (fflush(out)) {\n\t\tgoto FWRITE_ERROR;\n\t}\n\n\tfclose(in);\n\tfclose(out);\n\n\treturn EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/firmware-tools/srec2bin.c",
    "content": "#include <stdio.h>\n#include <ctype.h>\n#include <string.h>\n\n//Rev 0.1 Original\n// 8 Jan 2001  MJH  Added code to write data to Binary file\n//                  note: outputfile is name.bin, where name is first part\n//                  of input file.  ie tmp.rec -> tmp.bin\n//\n//   srec2bin <input SREC file> <Output Binary File> <If Present, Big Endian>\n//\n//   TAG   \n//        bit32u TAG_BIG     = 0xDEADBE42;\n//        bit32u TAG_LITTLE  = 0xFEEDFA42;\n//\n//  File Structure\n//\n//  TAG    :   32 Bits\n//  [DATA RECORDS]\n//\n//  Data Records Structure\n//\n//  LENGTH  :  32 Bits    <- Length of DATA, excludes ADDRESS and CHECKSUM\n//  ADDRESS :  32 Bits\n//  DATA    :  8 Bits * LENGTH\n//  CHECKSUM:  32 Bits    <-  0 - (Sum of Length --> End of Data)\n//\n//  Note : If Length == 0, Address will be Program Start\n//\n//\n//  \n//\n//\n\n#define MajRevNum 0\n#define MinRevNum 2\n\n\n#define EndianSwitch(x) ((x >> 24) | (x << 24) | ((x << 8) & (0x00FF0000)) | ((x >> 8) & (0x0000FF00)) )\n\ntypedef unsigned char bit8u;\ntypedef unsigned int bit32u;\ntypedef int bit32;\n\n#define FALSE 0\n#define TRUE (!FALSE)\n\n\nbit32u CheckSum;\nint RecStart;\nint debug;\nint verbose;\n\nFILE *OpenOutputFile( char *Name );\nFILE *fOut;\nbit32u RecLength=0;\n\nbit32u AddressCurrent;\n\nbit32u gh(char *cp,int nibs);\n\nint BigEndian;\n\nint inputline;\n\n// char buf[16*1024];\n\nchar buffer[2048];\nchar *cur_ptr;\nint cur_line=0;\nint cur_len=0;\n\nint s1s2s3_total=0;\n\nbit32u PBVal;\nint    PBValid;\nbit32u PBAdr;\n\n\nvoid dumpfTell(char *s, bit32u Value)\n{\n    int Length;\n    Length = (int) RecLength;\n    if (debug)\n          printf(\"[%s  ] ftell()[0x%08lX] Length[0x%4X] Length[%4d] Value[0x%08x]\\n\",\n                s, ftell(fOut), Length, Length, Value);\n}\n\nvoid DispHex(bit32u Hex)\n{\n//    printf(\"%X\", Hex);\n}\n\nvoid WaitDisplay(void)\n{\n   static int Count=0;\n   static int Index=0;\n   char iline[]={\"-\\\\|/\"};\n\n   Count++;\n   if ((Count % 32)==0)\n   {\n     if (verbose)\n        printf(\"%c%c\",iline[Index++],8);\n     Index &= 3;\n   }\n}\n\n\nvoid binOut32 ( bit32u Data )\n{\n// On UNIX machine all 32bit writes need ENDIAN switched\n//    Data = EndianSwitch(Data);\n//    fwrite( &Data, sizeof(bit32u), 1, fOut);\n\n   char sdat[4];\n   int i;\n\n   for(i=0;i<4;i++)\n    sdat[i]=(char)(Data>>(i*8));\n   fwrite( sdat, 1, 4, fOut);\n   dumpfTell(\"Out32\" , Data);\n}\n\n// Only update RecLength on Byte Writes\n// All 32 bit writes will be for Length etc\n\nvoid binOut8 ( bit8u Data )\n{\n    int n;\n    dumpfTell(\"B4Data\" , (bit32u) (Data & 0xFF) );\n    n = fwrite( &Data, sizeof(bit8u), 1, fOut);\n    if (n != 1)\n        printf(\"Error in writing %X for Address 0x%8X\\n\", Data, AddressCurrent);\n    RecLength += 1;\n}\n\n//  Currently ONLY used for outputting Program Start\n\nvoid binRecStart(bit32u Address)\n{\n    RecLength      = 0;\n    CheckSum       = Address;\n    RecStart       = TRUE;\n\n    if (debug)\n          printf(\"[RecStart] CheckSum[0x%08X] Length[%4d] Address[0x%08X]\\n\",\n                CheckSum, RecLength, Address);\n\n\n    dumpfTell(\"RecLength\", RecLength);\n    binOut32( RecLength );\n    dumpfTell(\"Address\", Address);\n    binOut32( Address );\n}\n\nvoid binRecEnd(void)\n{\n    long RecEnd;\n\n    if (!RecStart)   //  if no record started, do not end it\n    {\n        return;\n    }\n\n    RecStart = FALSE;\n\n\n    RecEnd = ftell(fOut);         // Save Current position\n\n    if (debug)\n          printf(\"[RecEnd  ] CheckSum[0x%08X] Length[%4d] Length[0x%X] RecEnd[0x%08lX]\\n\",\n                CheckSum, RecLength, RecLength, RecEnd);\n\n    fseek( fOut, -((long) RecLength), SEEK_CUR);  // move back Start Of Data\n\n    dumpfTell(\"Data   \", -1);\n\n    fseek( fOut, -4, SEEK_CUR);  // move back Start Of Address\n\n    dumpfTell(\"Address   \", -1);\n\n    fseek( fOut, -4, SEEK_CUR);  // move back Start Of Length\n\n    dumpfTell(\"Length   \", -1);\n\n    binOut32( RecLength );\n\n    fseek( fOut, RecEnd, SEEK_SET);  // move to end of Record\n\n    CheckSum += RecLength;\n\n    CheckSum =  ~CheckSum + 1;  // Two's complement\n\n    binOut32( CheckSum );\n\n    if (verbose)\n        printf(\"[Created Record of %d Bytes with CheckSum [0x%8X]\\n\", RecLength, CheckSum);\n}\n\nvoid binRecOutProgramStart(bit32u Address)\n{\n    if (Address != (AddressCurrent+1))\n    {\n        binRecEnd();\n        binRecStart(Address);\n    }\n    AddressCurrent = Address;\n}\nvoid binRecOutByte(bit32u Address, bit8u Data)\n{\n    //  If Address is one after Current Address, output Byte\n    //  If not, close out last record, update Length, write checksum\n    //  Then Start New Record, updating Current Address\n\n    if (Address != (AddressCurrent+1))\n    {\n        binRecEnd();\n        binRecStart(Address);\n    }\n    AddressCurrent = Address;\n    CheckSum += Data;\n    binOut8( Data );\n}\n\n//=============================================================================\n//       SUPPORT FUNCTIONS\n//=============================================================================\nint readline(FILE *fil,char *buf,int len)\n{\n    int rlen;\n    \n    rlen=0;\n    if (len==0)  return(0);\n    while(1)\n    {\n      if (cur_len==0)\n      {\n        cur_len=fread(buffer, 1, sizeof(buffer), fil);\n        if (cur_len==0)\n        {\n          if (rlen)\n          {\n            *buf=0;\n            return(rlen);\n          }\n          return(-1);\n        }\n        cur_ptr=buffer;\n      }\n      if (cur_len)\n      {\n        if (*cur_ptr=='\\n')\n        {\n          *buf=0;\n          cur_ptr++;\n          cur_len--;\n          return(rlen);\n        }\n         else\n         {\n           if ((len>1)&&(*cur_ptr!='\\r'))\n           {\n             *buf++=*cur_ptr++;\n             len--;\n           }\n           else\n             cur_ptr++;\n\n           rlen++;\n           cur_len--;\n         }\n      }\n      else\n      {\n        *buf=0;\n        cur_ptr++;\n        cur_len--;\n        return(rlen);\n      }\n    }\n}\n\n\nint SRLerrorout(char *c1,char *c2)\n{\n  printf(\"\\nERROR: %s - '%s'.\",c1,c2);\n  return(FALSE);\n}\n\n\nint checksum(char *cp,int count)\n{\n  char *scp;\n  int cksum;\n  int dum;\n\n  scp=cp;\n  while(*scp)\n  {\n    if (!isxdigit(*scp++))\n      return(SRLerrorout(\"Invalid hex digits\",cp));\n  }\n  scp=cp;\n\n  cksum=count;\n\n  while(count)\n  {\n    cksum += gh(scp,2);\n    if (count == 2)\n        dum = ~cksum;\n    scp += 2;\n    count--;\n  }\n  cksum&=0x0ff; \n  //  printf(\"\\nCk:%02x\",cksum);\n  return(cksum==0x0ff);\n}\n\nbit32u gh(char *cp,int nibs)\n{\n  int i;\n  bit32u j;\n\n  j=0;\n\n  for(i=0;i<nibs;i++)\n  {\n    j<<=4;\n    if ((*cp>='a')&&(*cp<='z')) *cp &= 0x5f;\n    if ((*cp>='0')&&(*cp<='9')) \n      j += (*cp-0x30);\n     else\n      if ((*cp>='A')&&(*cp<='F'))\n        j += (*cp-0x37);\n       else\n        SRLerrorout(\"Bad Hex char\", cp);\n    cp++;\n  }\n  return(j);\n}\n\n\n//=============================================================================\n//       PROCESS SREC LINE\n//=============================================================================\n\nint srecLine(char *pSrecLine)\n{\n    char *scp,ch;\n    int  itmp,count,dat;\n    bit32u adr;\n    static bit32u RecordCounter=0;\n\n    cur_line++;\n    scp=pSrecLine;\n  \n    if (*pSrecLine!='S')\n      return(SRLerrorout(\"Not an Srecord file\",scp));\n    pSrecLine++;\n    if (strlen(pSrecLine)<4)\n      return(SRLerrorout(\"Srecord too short\",scp));\n  \n    ch=*pSrecLine++;\n  \n    count=gh(pSrecLine,2);\n  \n    pSrecLine += 2;\n  \n  //  if(debug)\n  //        printf(\"count %d, strlen(pSrecLine) = %d, pSrecLine =[%s]\\n\", count, strlen(pSrecLine), pSrecLine);\n     RecordCounter++;\n     DispHex(RecordCounter);\n  \n    if ((count*2) != strlen(pSrecLine)) return(SRLerrorout(\"Count field larger than record\",scp));\n  \n    if (!checksum(pSrecLine, count)) return(SRLerrorout(\"Bad Checksum\",scp));\n  \n    switch(ch)\n    {\n        case '0': if (count<3) return(SRLerrorout(\"Invalid Srecord count field\",scp));\n                  itmp=gh(pSrecLine,4); pSrecLine+=4; count-=2;\n                  if (itmp) return(SRLerrorout(\"Srecord 1 address not zero\",scp));\n        break;\n        case '1': if (count<3) return(SRLerrorout(\"Invalid Srecord count field\",scp));\n                  return(SRLerrorout(\"Srecord Not valid for MIPS\",scp));\n        break;\n        case '2': if (count<4) return(SRLerrorout(\"Invalid Srecord count field\",scp));\n                  return(SRLerrorout(\"Srecord Not valid for MIPS\",scp));\n        break;\n        case '3': if (count<5) return(SRLerrorout(\"Invalid Srecord count field\",scp));\n                  adr=gh(pSrecLine,8); pSrecLine+=8; count-=4;\n                  count--;\n                  while(count)\n                  {\n                    dat=gh(pSrecLine,2); pSrecLine+=2; count--;\n                    binRecOutByte(adr, (char) (dat & 0xFF));\n                    adr++;\n                  }\n                  s1s2s3_total++;\n        break;\n        case '4': return(SRLerrorout(\"Invalid Srecord type\",scp));\n        break;\n        case '5': if (count<3) return(SRLerrorout(\"Invalid Srecord count field\",scp));\n                  itmp=gh(pSrecLine,4); pSrecLine+=4; count-=2;\n                  if (itmp|=s1s2s3_total) return(SRLerrorout(\"Incorrect number of S3 Record processed\",scp));\n        break;\n        case '6': return(SRLerrorout(\"Invalid Srecord type\",scp));\n        break;\n        case '7': // PROGRAM START\n                  if (count<5) return(SRLerrorout(\"Invalid Srecord count field\",scp));\n                  adr=gh(pSrecLine,8); pSrecLine+=8; count-=4;\n                  if (count!=1) return(SRLerrorout(\"Invalid Srecord count field\",scp));\n                  binRecOutProgramStart(adr);\n        break;\n        case '8': if (count<4) return(SRLerrorout(\"Invalid Srecord count field\",scp));\n                  return(SRLerrorout(\"Srecord Not valid for MIPS\",scp));\n        break;\n        case '9': if (count<3) return(SRLerrorout(\"Invalid Srecord count field\",scp));\n                  return(SRLerrorout(\"Srecord Not valid for MIPS\",scp));\n        break;\n        default:\n        break;\n    }\n    return(TRUE);\n}\n \n\n//=============================================================================\n//       MAIN LOGIC, READS IN LINE AND OUTPUTS BINARY\n//=============================================================================\n\nint srec2bin(int argc,char *argv[],int verbose)\n{\n    int i,rlen,sts;\n    FILE *fp;\n    char ac;\n    char buff[256];\n    bit32u TAG_BIG     = 0xDEADBE42;\n    bit32u TAG_LITTLE  = 0xFEEDFA42;\n\n    bit32u Tag;\n\n  \n    if(argc < 3)\n    {\n      printf(\"\\nError: <srec2bin <srec input file> <bin output file>\\n\\n\");\n      return(0);\n    }\n  \n    if (argc > 3) BigEndian=TRUE; else BigEndian=FALSE;\n\n    if (BigEndian)\n        Tag = TAG_BIG;\n    else\n        Tag = TAG_LITTLE;\n\n    if (verbose)\n       printf(\"\\nEndian: %s, Tag is 0x%8X\\n\",(BigEndian)?\"BIG\":\"LITTLE\", Tag);\n\n    fp = fopen(argv[1],\"rt\");\n\n    if (fp==NULL)\n    {\n      printf(\"\\nError: Opening input file, %s.\", argv[1]);\n      return(0);\n    }\n  \n    fOut = fopen( argv[2], \"wb\");\n    \n    if (fOut==NULL)\n    {\n      printf(\"\\nError: Opening Output file, %s.\", argv[2]);\n      if(fp) fclose(fp);\n      return(0);\n    }\n \n    RecStart = FALSE;\n\n    AddressCurrent = 0xFFFFFFFFL;\n\n    // Setup Tag \n  \n    dumpfTell(\"Tag\", Tag);\n\n    binOut32(Tag);\n\n  \n    inputline=0;\n    sts=TRUE;\n\n    rlen = readline(fp,buff,sizeof buff);\n\n    while( (sts) && (rlen != -1))\n    {\n        if (strlen(buff))\n        {\n            sts &= srecLine(buff);\n            WaitDisplay();\n        }\n       rlen = readline(fp,buff,sizeof buff);\n    }\n\n  \n  //  printf(\"PC: 0x%08X, Length 0x%08X, Tag 0x%08X\\n\", ProgramStart, RecLength, TAG_LITTLE);\n  \n    binRecEnd();\n\n    if(fp) fclose(fp);\n    if(fOut) fclose(fOut);\n\n    return(1);\n}\n\nmain(int argc, char *argv[])\n{\n    debug = TRUE;\n    debug = FALSE;\n    verbose = FALSE;\n    srec2bin(argc,argv,verbose);\n    return 0;\n}\n\n"
  },
  {
    "path": "src/firmware-tools/trx.c",
    "content": "/*\n * Copyright (C) 2004  Manuel Novoa III  <mjn3@codepoet.org>\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n */\n\n/* July 29, 2004\n *\n * This is a hacked replacement for the 'trx' utility used to create\n * wrt54g .trx firmware files.  It isn't pretty, but it does the job\n * for me.\n *\n * As an extension, you can specify a larger maximum length for the\n * .trx file using '-m'.  It will be rounded up to be a multiple of 4K.\n * NOTE: This space will be malloc()'d.\n *\n * August 16, 2004\n *\n * Sigh... Make it endian-neutral.\n *\n * TODO: Support '-b' option to specify offsets for each file.\n *\n * February 19, 2005 - mbm\n *\n * Add -a (align offset) and -b (absolute offset)\n *\n * March 24, 2010 - markus\n *\n * extend trx header struct for new version\n * assume v1 for as default\n * Add option -2 to allow v2 header\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stddef.h>\n#include <stdint.h>\n#include <string.h>\n#include <errno.h>\n#include <unistd.h>\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define STORE32_LE(X)\t\tbswap_32(X)\n#define LOAD32_LE(X)\t\tbswap_32(X)\n#elif __BYTE_ORDER == __LITTLE_ENDIAN\n#define STORE32_LE(X)\t\t(X)\n#define LOAD32_LE(X)\t\t(X)\n#else\n#error unkown endianness!\n#endif\n\nuint32_t crc32buf(char *buf, size_t len);\n\n/**********************************************************************/\n/* from trxhdr.h */\n\n#define TRX_MAGIC\t0x30524448\t/* \"HDR0\" */\n#define TRX_MAX_LEN\t0x720000\n#define TRX_NO_HEADER\t1\t\t/* Do not write TRX header */\t\n\nstruct trx_header {\n\tuint32_t magic;\t\t\t/* \"HDR0\" */\n\tuint32_t len;\t\t\t/* Length of file including header */\n\tuint32_t crc32;\t\t\t/* 32-bit CRC from flag_version to end of file */\n\tuint32_t flag_version;\t/* 0:15 flags, 16:31 version */\n\tuint32_t offsets[4];\t/* Offsets of partitions from start of header */\n};\n\n/**********************************************************************/\n\nvoid usage(void) __attribute__ (( __noreturn__ ));\n\nvoid usage(void)\n{\n\tfprintf(stderr, \"Usage:\\n\");\n\tfprintf(stderr, \" trx [-2] [-o outfile] [-m maxlen] [-a align] [-b absolute offset] [-x relative offset]\\n\");\n\tfprintf(stderr, \"     [-f file] [-f file [-f file [-f file (v2 only)]]]\\n\");\n\texit(EXIT_FAILURE);\n}\n\nint main(int argc, char **argv)\n{\n\tFILE *out = stdout;\n\tFILE *in;\n\tchar *ofn = NULL;\n\tchar *buf;\n\tchar *e;\n\tint c, i, append = 0;\n\tsize_t n;\n\tssize_t n2;\n\tuint32_t cur_len, fsmark=0;\n\tunsigned long maxlen = TRX_MAX_LEN;\n\tstruct trx_header *p;\n\tchar trx_version = 1;\n\tunsigned char binheader[32];\n\n\tfprintf(stderr, \"mjn3's trx replacement - v0.81.1\\n\");\n\n\tif (!(buf = malloc(maxlen))) {\n\t\tfprintf(stderr, \"malloc failed\\n\");\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tp = (struct trx_header *) buf;\n\n\tp->magic = STORE32_LE(TRX_MAGIC);\n\tcur_len = sizeof(struct trx_header) - 4; /* assume v1 header */\n\n\tin = NULL;\n\ti = 0;\n\n\twhile ((c = getopt(argc, argv, \"-:2o:m:a:x:b:f:A:F:\")) != -1) {\n\t\tswitch (c) {\n\t\t\tcase '2':\n\t\t\t\t/* take care that nothing was written to buf so far */\n\t\t\t\tif (cur_len != sizeof(struct trx_header) - 4) {\n\t\t\t\t\tfprintf(stderr, \"-2 has to be used before any other argument!\\n\");\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttrx_version = 2;\n\t\t\t\t\tcur_len += 4;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'F':\n\t\t\t\tfsmark = cur_len;\n\t\t\tcase 'A':\n\t\t\t\tappend = 1;\n\t\t\t\t/* fall through */\n\t\t\tcase 'f':\n\t\t\tcase 1:\n\t\t\t\tif (!append)\n\t\t\t\t\tp->offsets[i++] = STORE32_LE(cur_len);\n\n\t\t\t\tif (!(in = fopen(optarg, \"r\"))) {\n\t\t\t\t\tfprintf(stderr, \"can not open \\\"%s\\\" for reading\\n\", optarg);\n\t\t\t\t\tusage();\n\t\t\t\t}\n\t\t\t\tn = fread(buf + cur_len, 1, maxlen - cur_len, in);\n\t\t\t\tif (!feof(in)) {\n\t\t\t\t\tfprintf(stderr, \"fread failure or file \\\"%s\\\" too large\\n\",optarg);\n\t\t\t\t\tfclose(in);\n\t\t\t\t\treturn EXIT_FAILURE;\n\t\t\t\t}\n\t\t\t\tfclose(in);\n#undef  ROUND\n#define ROUND 4\n\t\t\t\tif (n & (ROUND-1)) {\n\t\t\t\t\tmemset(buf + cur_len + n, 0, ROUND - (n & (ROUND-1)));\n\t\t\t\t\tn += ROUND - (n & (ROUND-1));\n\t\t\t\t}\n\t\t\t\tcur_len += n;\n\t\t\t\tappend = 0;\n\n\t\t\t\tbreak;\n\t\t\tcase 'o':\n\t\t\t\tofn = optarg;\n\t\t\t\tif (ofn && !(out = fopen(ofn, \"w\"))) {\n\t\t\t\t\tfprintf(stderr, \"can not open \\\"%s\\\" for writing\\n\", ofn);\n\t\t\t\t\tusage();\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\tcase 'm':\n\t\t\t\terrno = 0;\n\t\t\t\tmaxlen = strtoul(optarg, &e, 0);\n\t\t\t\tif (errno || (e == optarg) || *e) {\n\t\t\t\t\tfprintf(stderr, \"illegal numeric string\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\n#undef  ROUND\n#define ROUND 0x1000\n\t\t\t\tif (maxlen & (ROUND-1)) {\n\t\t\t\t\tmaxlen += (ROUND - (maxlen & (ROUND-1)));\n\t\t\t\t}\n\t\t\t\tif (maxlen < ROUND) {\n\t\t\t\t\tfprintf(stderr, \"maxlen too small (or wrapped)\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\n\t\t\t\tif (maxlen > TRX_MAX_LEN) {\n\t\t\t\t\tfprintf(stderr, \"WARNING: maxlen exceeds default maximum!  Beware of overwriting nvram!\\n\");\n\t\t\t\t}\n\t\t\t\tif (!(buf = realloc(buf,maxlen))) {\n\t\t\t\t\tfprintf(stderr, \"realloc failed\");\n\t\t\t\t\treturn EXIT_FAILURE;\n\t\t\t\t}\n\t\t\t\tp = (struct trx_header *) buf;\n\t\t\t\tbreak;\n\t\t\tcase 'a':\n\t\t\t\terrno = 0;\n\t\t\t\tn = strtoul(optarg, &e, 0);\n\t\t\t\tif (errno || (e == optarg) || *e) {\n\t\t\t\t\tfprintf(stderr, \"illegal numeric string\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\n\t\t\t\tif (cur_len & (n-1)) {\n\t\t\t\t\tn = n - (cur_len & (n-1));\n\t\t\t\t\tmemset(buf + cur_len, 0, n);\n\t\t\t\t\tcur_len += n;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'b':\n\t\t\t\terrno = 0;\n\t\t\t\tn = strtoul(optarg, &e, 0);\n\t\t\t\tif (errno || (e == optarg) || *e) {\n\t\t\t\t\tfprintf(stderr, \"illegal numeric string\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\n\t\t\t\tif (n < cur_len) {\n\t\t\t\t\tfprintf(stderr, \"WARNING: current length exceeds -b %d offset\\n\",(int) n);\n\t\t\t\t} else {\n\t\t\t\t\tmemset(buf + cur_len, 0, n - cur_len);\n\t\t\t\t\tcur_len = n;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'x':\n\t\t\t\terrno = 0;\n\t\t\t\tn2 = strtol(optarg, &e, 0);\n\t\t\t\tif (errno || (e == optarg) || *e) {\n\t\t\t\t\tfprintf(stderr, \"illegal numeric string\\n\");\n\t\t\t\t\tusage();\n\t\t\t\t}\n\t\t\t\tif (n2 < 0) {\n\t\t\t\t\tif (-n2 > cur_len) {\n\t\t\t\t\t\tfprintf(stderr, \"WARNING: current length smaller then -x %d offset\\n\",(int) n2);\n\t\t\t\t\t\tcur_len = 0;\n\t\t\t\t\t} else\n\t\t\t\t\t\tcur_len += n2;\n\t\t\t\t} else {\n\t\t\t\t\tmemset(buf + cur_len, 0, n2);\n\t\t\t\t\tcur_len += n2;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tusage();\n\t\t}\n\t}\n\tp->flag_version = STORE32_LE((trx_version << 16));\n\n\tif (!in) {\n\t\tfprintf(stderr, \"we require atleast one filename\\n\");\n\t\tusage();\n\t}\n\n#undef  ROUND\n#define ROUND 0x1000\n\tn = cur_len & (ROUND-1);\n\tif (n) {\n\t\tmemset(buf + cur_len, 0, ROUND - n);\n\t\tcur_len += ROUND - n;\n\t}\n\n\t/* for TRXv2 set bin-header Flags to 0xFF for CRC calculation like CFE does */ \n\tif (trx_version == 2) {\n\t\tif(cur_len - LOAD32_LE(p->offsets[3]) < sizeof(binheader)) {\n\t\t\tfprintf(stderr, \"TRXv2 binheader too small!\\n\");\n\t\t\treturn EXIT_FAILURE;\n\t\t}\n\t\tmemcpy(binheader, buf + LOAD32_LE(p->offsets[3]), sizeof(binheader)); /* save header */\n\t\tmemset(buf + LOAD32_LE(p->offsets[3]) + 22, 0xFF, 8); /* set stable and try1-3 to 0xFF */\n\t}\n\n\tp->crc32 = crc32buf((char *) &p->flag_version,\n\t\t\t\t\t\t(fsmark)?fsmark:cur_len - offsetof(struct trx_header, flag_version));\n\tp->crc32 = STORE32_LE(p->crc32);\n\n\tp->len = STORE32_LE((fsmark) ? fsmark : cur_len);\n\tp->len = STORE32_LE(p->len);\n\n\t/* restore TRXv2 bin-header */\n\tif (trx_version == 2) {\n\t\tmemcpy(buf + LOAD32_LE(p->offsets[3]), binheader, sizeof(binheader));\n\t}\n\n\tif (!fwrite(buf, cur_len, 1, out) || fflush(out)) {\n\t\tfprintf(stderr, \"fwrite failed\\n\");\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tfclose(out);\n\t\n\treturn EXIT_SUCCESS;\n}\n\n/**********************************************************************/\n/* The following was grabbed and tweaked from the old snippets collection\n * of public domain C code. */\n\n/**********************************************************************\\\n|* Demonstration program to compute the 32-bit CRC used as the frame  *|\n|* check sequence in ADCCP (ANSI X3.66, also known as FIPS PUB 71     *|\n|* and FED-STD-1003, the U.S. versions of CCITT's X.25 link-level     *|\n|* protocol).  The 32-bit FCS was added via the Federal Register,     *|\n|* 1 June 1982, p.23798.  I presume but don't know for certain that   *|\n|* this polynomial is or will be included in CCITT V.41, which        *|\n|* defines the 16-bit CRC (often called CRC-CCITT) polynomial.  FIPS  *|\n|* PUB 78 says that the 32-bit FCS reduces otherwise undetected       *|\n|* errors by a factor of 10^-5 over 16-bit FCS.                       *|\n\\**********************************************************************/\n\n/* Copyright (C) 1986 Gary S. Brown.  You may use this program, or\n   code or tables extracted from it, as desired without restriction.*/\n\n/* First, the polynomial itself and its table of feedback terms.  The  */\n/* polynomial is                                                       */\n/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */\n/* Note that we take it \"backwards\" and put the highest-order term in  */\n/* the lowest-order bit.  The X^32 term is \"implied\"; the LSB is the   */\n/* X^31 term, etc.  The X^0 term (usually shown as \"+1\") results in    */\n/* the MSB being 1.                                                    */\n\n/* Note that the usual hardware shift register implementation, which   */\n/* is what we're using (we're merely optimizing it by doing eight-bit  */\n/* chunks at a time) shifts bits into the lowest-order term.  In our   */\n/* implementation, that means shifting towards the right.  Why do we   */\n/* do it this way?  Because the calculated CRC must be transmitted in  */\n/* order from highest-order term to lowest-order term.  UARTs transmit */\n/* characters in order from LSB to MSB.  By storing the CRC this way,  */\n/* we hand it to the UART in the order low-byte to high-byte; the UART */\n/* sends each low-bit to hight-bit; and the result is transmission bit */\n/* by bit from highest- to lowest-order term without requiring any bit */\n/* shuffling on our part.  Reception works similarly.                  */\n\n/* The feedback terms table consists of 256, 32-bit entries.  Notes:   */\n/*                                                                     */\n/*  1. The table can be generated at runtime if desired; code to do so */\n/*     is shown later.  It might not be obvious, but the feedback      */\n/*     terms simply represent the results of eight shift/xor opera-    */\n/*     tions for all combinations of data and CRC register values.     */\n/*                                                                     */\n/*  2. The CRC accumulation logic is the same for all CRC polynomials, */\n/*     be they sixteen or thirty-two bits wide.  You simply choose the */\n/*     appropriate table.  Alternatively, because the table can be     */\n/*     generated at runtime, you can start by generating the table for */\n/*     the polynomial in question and use exactly the same \"updcrc\",   */\n/*     if your application needn't simultaneously handle two CRC       */\n/*     polynomials.  (Note, however, that XMODEM is strange.)          */\n/*                                                                     */\n/*  3. For 16-bit CRCs, the table entries need be only 16 bits wide;   */\n/*     of course, 32-bit entries work OK if the high 16 bits are zero. */\n/*                                                                     */\n/*  4. The values must be right-shifted by eight bits by the \"updcrc\"  */\n/*     logic; the shift must be unsigned (bring in zeroes).  On some   */\n/*     hardware you could probably optimize the shift in assembler by  */\n/*     using byte-swap instructions.                                   */\n\nstatic const uint32_t crc_32_tab[] = { /* CRC polynomial 0xedb88320 */\n0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,\n0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,\n0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,\n0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,\n0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,\n0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,\n0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,\n0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,\n0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,\n0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,\n0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,\n0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,\n0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,\n0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,\n0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,\n0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,\n0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\n0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d\n};\n\n#define UPDC32(octet,crc) (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8))\n\nuint32_t crc32buf(char *buf, size_t len)\n{\n      uint32_t crc;\n\n      crc = 0xFFFFFFFF;\n\n      for ( ; len; --len, ++buf)\n      {\n            crc = UPDC32(*buf, crc);\n      }\n\n      return crc;\n}\n"
  },
  {
    "path": "src/firmware-tools/trx2edips.c",
    "content": "#include <stdio.h>\n#include <stdlib.h>\n#include <stddef.h>\n#include <stdint.h>\n#include <string.h>\n#include <errno.h>\n#include <unistd.h>\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define STORE32_LE(X)\t\tbswap_32(X)\n#define LOAD32_LE(X)\t\tbswap_32(X)\n#elif __BYTE_ORDER == __LITTLE_ENDIAN\n#define STORE32_LE(X)\t\t(X)\n#define LOAD32_LE(X)\t\t(X)\n#else\n#error unkown endianness!\n#endif\n\n/**********************************************************************/\n/* from trxhdr.h */\n\n#define TRX_MAGIC\t0x30524448\t/* \"HDR0\" */\n#define TRX_VERSION\t1\n#define TRX_MAX_LEN\t0x5A0000\n#define TRX_NO_HEADER\t1\t\t/* Do not write TRX header */\n\nstruct trx_header {\n\tuint32_t magic;\t\t\t/* \"HDR0\" */\n\tuint32_t len;\t\t\t/* Length of file including header */\n\tuint32_t crc32;\t\t\t/* 32-bit CRC from flag_version to end of file */\n\tuint32_t flag_version;\t/* 0:15 flags, 16:31 version */\n\tuint32_t offsets[3];\t/* Offsets of partitions from start of header */\n};\n\n\nstruct edimax_header {\n\tuint32_t sign;\t\t\t/* signature for header */\n\tuint32_t length;\t\t/* start address but doesn't seems to be used... */\n\tuint32_t start_addr;\t\t/* length of data, not used too ...*/\n};\n\n\n#define EDIMAX_PS16\t0x36315350\t/* \"PS16\" */\n#define EDIMAX_HDR_LEN \t0xc\n\n\n/**********************************************************************/\nstatic const uint32_t crc_32_tab[] = { /* CRC polynomial 0xedb88320 */\n0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,\n0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,\n0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,\n0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,\n0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,\n0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,\n0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,\n0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,\n0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,\n0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,\n0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,\n0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,\n0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,\n0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,\n0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,\n0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,\n0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\n0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d\n};\n\n#define UPDC32(octet, crc) (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8))\n\nuint32_t crc32buf(char *buf, size_t len)\n{\n\tuint32_t crc;\n\n\tcrc = 0xFFFFFFFF;\n\n\tfor (; len; --len, ++buf)\n\t\tcrc = UPDC32(*buf, crc);\n\n\treturn crc;\n}\n\n\nint main(int argc, char *argv[])\n{\n\tFILE *fpIn = NULL;\n\tFILE *fpOut = NULL;\n\tstruct edimax_header eh;\n\tsize_t res;\n\tint length;\n\n\tchar *buf;\n\tstruct trx_header *p;\n\n\tif (argc != 3) {\n\t\tprintf(\"Usage: %s <input file> <output file>\\n\", argv[0]);\n\t\treturn -1;\n\t}\n\n\tfpIn = fopen(argv[1], \"rb\");\n\tif (fpIn == NULL) {\n\t\tfprintf(stderr, \"Unable to open %s\\n\", argv[1]);\n\t\treturn EXIT_FAILURE;\n\t}\n\t/* compute the length of the file */\n\tfseek(fpIn, 0, SEEK_END);\n\tlength = ftell(fpIn);\n\t/* alloc enough memory to store the file */\n\tbuf = (char *)malloc(length);\n\tif (!buf) {\n\t\tfprintf(stderr, \"malloc of buffers failed\\n\");\n\t\treturn EXIT_FAILURE;\n\t}\n\t\n\trewind(fpIn);\n\t/* read the whole file*/\n\tres = fread(buf, 1, length, fpIn);\n\n\tp = (struct trx_header *)buf;\n\tif (LOAD32_LE(p->magic) != TRX_MAGIC) {\n\t\tfprintf(stderr, \"Not a trx file...%x\\n\", LOAD32_LE(p->magic));\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tfclose(fpIn);\n\n\tfpOut = fopen(argv[2], \"wb+\");\n\tif (fpOut == NULL) {\n\t\tfprintf(stderr, \"Unable to open %s\\n\", argv[2]);\n\t\treturn EXIT_FAILURE;\n\t}\n\t/* make the 3 partition beeing 12 bytes closer from the header */\n\tmemcpy(buf + LOAD32_LE(p->offsets[2]) - EDIMAX_HDR_LEN, buf + LOAD32_LE(p->offsets[2]), length - LOAD32_LE(p->offsets[2]));\n\t/* recompute the crc32 check */\n\tp->crc32 = STORE32_LE(crc32buf((char *) &p->flag_version, length - offsetof(struct trx_header, flag_version)));\n\n\teh.sign = STORE32_LE(EDIMAX_PS16);\n\teh.length = STORE32_LE(length);\n\teh.start_addr = STORE32_LE(0x80500000);\n\n\t/* write the modified file */\n\tfwrite(&eh, sizeof(struct edimax_header), 1, fpOut);\n\tfwrite(buf, sizeof(char), length, fpOut);\n\tfclose(fpOut);\n}\n\n"
  },
  {
    "path": "src/firmware-tools/trx2usr.c",
    "content": "/*\n * trx2usr - Convert a TRX firmware image to a U.S. Robotics firmware\n *           image by prepending a 28-byte header.\n *\n * This program was modeled after the usr-hdr.c program from the GPL'ed\n * firmware for the U.S. Robotics Wireless MAXg Router (USR5461). The\n * output file of this program can be uploaded via the web interface\n * of the original U.S. Robotics firmware. Note that this program only\n * works on a little-endian host platform.\n *\n * Copyright (C) 2006 Dick Streefland\n *\n * This is free software, licensed under the terms of the GNU General\n * Public License as published by the Free Software Foundation.\n */\n\n#include <stdio.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n\n#define\tTRX_MAGIC\t\t\"HDR0\"\n\n#define\tUSR_MAGIC\t\t0x30525355\t// \"USR0\"\n#define\tEPI_VERSION\t\t0x06235d03\n#define\tCOMPAT_ID\t\t1\t\t// USR5461\n#define\tHARDWARE_REV\t\t1\n\n#define\tCRC32_INIT\t\t0xffffffff\n#define\tCHUNK\t\t\t(64*1024)\n\ntypedef\tunsigned char\t\tuint8;\ntypedef\tunsigned short\t\tuint16;\ntypedef\tunsigned int\t\tuint32;\n\nstruct\tusr_header\n{\n\tuint32\tmagic;\t\t\t// \"USR0\" \n\tuint32\tlen;\t\t\t// file length without this header \n\tuint32\tcrc32;\t\t\t// CRC32 of the file without header \n\tuint32\tversion;\t\t// EPI_VERSION\n\tuint16\tcompatibility_id;\t// COMPAT_ID\n\tuint16\thardware_revision;\t// HARDWARE_REV\n\tuint32\treserved[2];\n};\n\t\nstatic\tconst\tuint32\t\tcrc_32_tab [] =\t// CRC polynomial 0xedb88320\n{\n\t0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,\n\t0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n\t0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,\n\t0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n\t0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n\t0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n\t0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,\n\t0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n\t0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,\n\t0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n\t0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,\n\t0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n\t0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,\n\t0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n\t0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n\t0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n\t0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,\n\t0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n\t0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,\n\t0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n\t0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,\n\t0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n\t0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,\n\t0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n\t0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n\t0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n\t0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,\n\t0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n\t0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,\n\t0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n\t0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,\n\t0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n\t0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,\n\t0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n\t0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n\t0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n\t0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,\n\t0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n\t0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,\n\t0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n\t0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,\n\t0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n\t0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,\n};\n\nstatic\tchar\tbuf[CHUNK];\n\nstatic\tuint32\tcrc32(uint32 crc, uint8* p, size_t n)\n{\n\twhile (n--)\n\t{\n\t\tcrc = crc_32_tab[(crc ^ *p++) & 0xff] ^ (crc >> 8);\n\t}\n\treturn crc;\n}\n\nstatic\tint\ttrx2usr(FILE* trx, FILE* usr)\n{\n\tstruct usr_header\thdr;\n\tsize_t\t\t\tn;\n\n\thdr.magic\t\t= USR_MAGIC;\n\thdr.len\t\t\t= 0;\n\thdr.crc32\t\t= CRC32_INIT;\n\thdr.version\t\t= EPI_VERSION;\n\thdr.compatibility_id\t= COMPAT_ID;\n\thdr.hardware_revision\t= HARDWARE_REV;\n\thdr.reserved[0]\t\t= 0;\n\thdr.reserved[1]\t\t= 0;\n\tfwrite(& hdr, sizeof(hdr), 1, usr);\n\twhile ((n = fread(buf, 1, CHUNK, trx)))\n\t{\n\t\tif (hdr.len == 0 && strncmp(buf, TRX_MAGIC, strlen(TRX_MAGIC)) != 0)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tfwrite(& buf, 1, n, usr);\n\t\thdr.len += n;\n\t\thdr.crc32 = crc32( hdr.crc32, (uint8 *) & buf, n);\n\t}\n\tfseek(usr, 0L, SEEK_SET);\n\tfwrite(& hdr, sizeof(hdr), 1, usr);\n\tif (n != 0)\n\t{\n\t\tfprintf(stderr, \"Input is not a TRX file\\n\");\n\t\treturn 1;\n\t}\n\tif (hdr.len == 0)\n\t{\n\t\tfprintf(stderr, \"Empty input\\n\");\n\t\treturn 1;\n\t}\n\tif (ferror(trx))\n\t{\n\t\tfprintf(stderr, \"Read error\\n\");\n\t\treturn 1;\n\t}\n\tif (ferror(usr))\n\t{\n\t\tfprintf(stderr, \"Write error\\n\");\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\nextern\tint\tmain(int argc, char *argv[])\n{\n\tFILE*\tin;\n\tFILE*\tout;\n\tint\tret;\n\n\tif (argc != 3)\n\t{\n\t\tfprintf(stderr, \"Usage: trx2usr <trx input> <usr output>\\n\");\n\t\texit(2);\n\t}\n\tin  = fopen(argv[1], \"rb\");\n\tif (!in)\n\t{\n\t\tfprintf(stderr, \"Cannot open \\\"%s\\\": %s\\n\", argv[1], strerror(errno));\n\t\texit(1);\n\t}\n\tout = fopen(argv[2], \"wb\");\n\tif (!out)\n\t{\n\t\tfprintf(stderr, \"Cannot create \\\"%s\\\": %s\\n\", argv[2], strerror(errno));\n\t\texit(1);\n\t}\n\tret = trx2usr(in, out);\n\tfclose(in);\n\tfclose(out);\n\tif (ret)\n\t{\n\t\tunlink(argv[2]);\n\t}\n\treturn ret;\n}\n"
  },
  {
    "path": "src/firmware-tools/wndr3700.c",
    "content": "/*\n * wndr3700.c - partially based on OpenWrt's add_header.c\n *\n * Copyright (C) 2009 Anael Orlinski  <naouel@naouel.org>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License,\n * version 2 as published by the Free Software Foundation.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n */\n\n/*\n * The add_header utility used by various vendors preprends the buf\n * image with a header containing a CRC32 value which is generated for the\n * model id + reserved space for CRC32 + buf, then replaces the reserved\n * area with the actual CRC32. This replacement tool mimics this behavior.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stddef.h>\n#include <unistd.h>\n#include <errno.h>\n#include <fcntl.h>\n#include <sys/mman.h>\n#include <string.h>\n#include <netinet/in.h>\n#include <inttypes.h>\n\n#define BPB 8 /* bits/byte */\n\n#define WNDR3700_MAGIC_LEN\t4\n\nstatic uint32_t crc32[1<<BPB];\nstatic char *magic = \"3700\";\n\nstatic void init_crc32()\n{\n\tconst uint32_t poly = ntohl(0x2083b8ed);\n\tint n;\n\n\tfor (n = 0; n < 1<<BPB; n++) {\n\t\tuint32_t crc = n;\n\t\tint bit;\n\n\t\tfor (bit = 0; bit < BPB; bit++)\n\t\t\tcrc = (crc & 1) ? (poly ^ (crc >> 1)) : (crc >> 1);\n\t\tcrc32[n] = crc;\n\t}\n}\n\nstatic uint32_t crc32buf(unsigned char *buf, size_t len)\n{\n\tuint32_t crc = 0xFFFFFFFF;\n\n\tfor (; len; len--, buf++)\n\t\tcrc = crc32[(uint8_t)crc ^ *buf] ^ (crc >> BPB);\n\treturn ~crc;\n}\n\nstruct header {\n    unsigned char magic[WNDR3700_MAGIC_LEN];\n    uint32_t crc;\n    unsigned char stuff[56];\n};\n\nstatic void usage(const char *) __attribute__ (( __noreturn__ ));\n\nstatic void usage(const char *mess)\n{\n\tfprintf(stderr, \"Error: %s\\n\", mess);\n\tfprintf(stderr, \"Usage: wndr3700 input_file output_file [magic]\\n\");\n\tfprintf(stderr, \"\\n\");\n\texit(1);\n}\n\nint main(int argc, char **argv)\n{\n\toff_t len;\t\t\t// of original buf\n\toff_t buflen;\t\t\t// of the output file\n\tint fd;\n\tvoid *input_file;\t\t// pointer to the input file (mmmapped)\n\tstruct header header;\n\tunsigned char *buf;\t// pointer to prefix + copy of original buf\n\n\t// verify parameters\n\n\tif (argc < 3)\n\t\tusage(\"wrong number of arguments\");\n\n\tif (argc > 3)\n\t\tmagic = argv[3];\n\n\tif (strlen(magic) != WNDR3700_MAGIC_LEN) {\n\t\tfprintf(stderr, \"Invalid magic: '%s'\\n\", magic);\n\t\texit(1);\n\t}\n\n\t// mmap input_file\n\tif ((fd = open(argv[1], O_RDONLY))  < 0\n\t|| (len = lseek(fd, 0, SEEK_END)) < 0\n\t|| (input_file = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0)) == (void *) (-1)\n\t|| close(fd) < 0)\n\t{\n\t\tfprintf(stderr, \"Error loading file %s: %s\\n\", argv[1], strerror(errno));\n\t\texit(1);\n\t}\n\n\tbuflen = len;\n\n\tinit_crc32();\n\n        // preload header\n        memcpy(&header, input_file, sizeof(header));\n\n\tmemcpy(header.magic, magic, WNDR3700_MAGIC_LEN);\n\theader.crc = 0;\n\n\t// create a firmware image in memory and copy the input_file to it\n\tbuf = malloc(buflen);\n\tmemcpy(buf, input_file, len);\n\n\t// CRC of temporary header\n\theader.crc = htonl(crc32buf((unsigned char*)&header, sizeof(header)));\n\n\tmemcpy(buf, &header, sizeof(header));\n\n\t// write the buf\n\tif ((fd = open(argv[2], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0\n\t|| write(fd, buf, buflen) != buflen\n\t|| close(fd) < 0)\n\t{\n\t\tfprintf(stderr, \"Error storing file %s: %s\\n\", argv[2], strerror(errno));\n\t\texit(2);\n \t}\n\n\tfree(buf);\n\n\tmunmap(input_file,len);\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/wrt400n.c",
    "content": "/*\n * WRT400n - Firmware Generation Creator\n *\n * Creates a firmware image for the Linksys WRT400n router,\n * that can be uploaded via the firmware upload page,\n * from a kernel image file and root fs file\n *\n *\tAuthor: Sandeep Mistry\n */\n#include <fcntl.h>\n#include <stdio.h>\n#include <stdint.h>\n#include <string.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n\n#include \"cyg_crc.h\"\n\n// https://dev.openwrt.org/browser/trunk/target/linux/rdc-2.6/files/drivers/mtd/maps/rdc3210.c\nstatic uint32_t crctab[257] =\n{\n\t0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,\n\t0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,\n\t0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,\n\t0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,\n\t0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,\n\t0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n\t0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,\n\t0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,\n\t0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,\n\t0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,\n\t0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,\n\t0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n\t0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,\n\t0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,\n\t0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n\t0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,\n\t0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,\n\t0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n\t0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,\n\t0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,\n\t0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,\n\t0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,\n\t0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,\n\t0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n\t0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,\n\t0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,\n\t0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,\n\t0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,\n\t0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,\n\t0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n\t0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,\n\t0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,\n\t0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,\n\t0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,\n\t0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,\n\t0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n\t0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,\n\t0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,\n\t0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,\n\t0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,\n\t0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,\n\t0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n\t0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,\n\t0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,\n\t0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n\t0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,\n\t0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,\n\t0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n\t0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,\n\t0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,\n\t0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,\n\t0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,\n\t0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,\n\t0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n\t0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,\n\t0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,\n\t0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,\n\t0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,\n\t0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,\n\t0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n\t0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,\n\t0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,\n\t0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,\n\t0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,\n\t0\n};\n\nstatic uint32_t crc32(uint8_t* buf, uint32_t len)\n{\n\tregister int i;\n\tuint32_t sum;\n\tregister uint32_t s0;\n\ts0 = ~0;\n\tfor (i = 0; i < len; i++)\n\t{\n\t\ts0 = (s0 >> 8) ^ crctab[(uint8_t) (s0 & 0xFF) ^ buf[i]];\n\t}\n\tsum = ~s0;\n\treturn sum;\n}\n\n#define HEADERSIZE\t60\n#define MAGIC\t\t\"GMTKRT400N\"\n\n// global variables\nuint8_t kernelbuf[0x100000];\t// kernel - lzma - uImage\nuint8_t rootfsbuf[0x2FFFC4];\t// root - squashfs\n\nuint8_t buf[0x400000];\t\t// buffer for image\n\n\n// Header format:\n//\n//\t\tGPL Tarball: http://downloads.linksysbycisco.com/downloads/WRT400N_1.0.01.19_US.tar,0.gz\n//\t\tFile: WRT400N_1.0.01.19_US/FW_WRT400N_1.0.01.19_US_20081229/GTK/user/include/fw_upgrade.h\n//\n//\n//\t\tStruct:\n//\t\t\ttypedef struct\n//\t\t\t{\n//\t\t\t\tUINT32\t\tchecksum;\t\t/* CRC32 */\n//\t\t\t\tUINT8\t\t\tmagic[11];\t\t/* The value of GTIMG_MAGIC */\n//\t\t\t\tUINT32\t\tkernel_length;\t\t/* The length of the kernel image */\n//\t\t\t\t//UINT32\t\tkernel_entry_point;\t/* Kernel's entry point for RedBoot's information */\n//\t\t\t\tUINT32\t\tkernel_upgrade_flag;\t/* Set to 1 if we need to upgrade the kernel parition of the Flash */\n//\t\t\t\tUINT32\t\trootfs_length;\t\t/* The length of the rootfs image */\n//\t\t\t\t//UINT32\t\trootfs_entry_point;\t/* Not in use */\n//\t\t\t\tUINT32\t\trootfs_upgrade_flag;\t/* Set to 1 if we need to upgrade the rootfs parition of the Flash */\n//\n//\t\t\t\t// Add 3 items by Vic Yu, 2006-05/10\n//\t\t\t\tUINT32\t\tkernel_checksum;\n//\t\t\t\tUINT32\t\trootfs_checksum;\n//\t\t\t\tUINT32\t\tfw_totalsize;\n//\t\t\t\tUINT32\t\treserved[4];\n//\t\t\t}imghdr_t , *pLinuxFWHeader_T;\n//\n//\n//\t\tDescription\n//\t\t\t- checksum: \t\t\tCRC32 of kernel and root fs, back to back\n//\t\t\t- magic:\t\t\t\tGMTKRT400N\n//\t\t\t- kernel_length:\t\tkernel length in bytes\n//\t\t\t- kernel_upgrade_flag:\tshould we upgrade the kernel - set to 1\n//\t\t\t- rootfs_length:\t\troot fs length in byte\n//\t\t\t- rootfs_upgrade_flag:\tshould we upgrade the root fs - set to 1\n//\t\t\t- kernel_checksum: \t\tGary S. Brown's 32 bit CRC algorithm for kernel, with remaining bits\n//\t\t\t\t\t\t\t\t\tset to 0xFF upto 0x100000 bytes (total length)\n//\t\t\t- rootfs_checksum:\t\tGary S. Brown's 32 bit CRC algorithm for root fs, with remaining bits\n//\t\t\t\t\t\t\t\t\tset to 0xFF upto 0x2FFFC4 bytes\t(total length)\n//\t\t\t- fw_totalsize:\t\t\ttotal firmware image file length (header length + kernel length + root fs length)\n//\t\t\t- reserved[4]:\t\t\treserved ??? - set to all 0xFF\n\n\n\nint main(int argc, char *argv[])\n{\n\t// file descriptors ...\n\tint \t\tkernelfd\t\t= -1;\n\tint \t\trootfsfd\t\t\t= -1;\n\tint\t\t\toutfd\t\t\t= -1;\n\n\tchar*\t\tkernelfilename\t= NULL;\n\tchar*\t\trootfsfilename\t= NULL;\n\tchar*\t\toutputfilename\t= NULL;\n\n\t// file sizes\n\tuint32_t \tkernelsize \t\t= 0;\n\tuint32_t \trootfssize \t\t= 0;\n\tuint32_t \ttotalsize \t\t= 0;\n\n\t// header flags\n\tuint32_t \tkernelflag \t\t= 0;\n\tuint32_t \trootfsflag \t\t= 0;\n\n\t// checksums\n\tuint32_t \tkernelchecksum \t= 0;\n\tuint32_t \trootfschecksum \t= 0;\n\tuint32_t\tcrc\t\t\t\t= 0;\n\n\tif(argc != 4)\n\t{\n\t\tprintf(\"Usage:\\n\\t%s <kernel file> <rootfs file> <output file>\\n\", argv[0]);\n\t\treturn 1;\n\t}\n\n\tkernelfilename = argv[1];\n\trootfsfilename = argv[2];\n\toutputfilename = argv[3];\n\n\t// Fill the kernel, rootfs, main buffer\n\tmemset(kernelbuf, 0xFF, sizeof(kernelbuf));\n\tmemset(rootfsbuf, 0xFF, sizeof(rootfsbuf));\n\tmemset(buf, 0xFF, sizeof(buf));\n\n\t// open the kernel ..\n\tkernelfd = open(kernelfilename, O_RDONLY);\n\n\tif(kernelfd == -1)\n\t{\n\t\tprintf(\"Error: opening '%s'\\n\", kernelfilename);\n\t\tgoto done;\n\t}\n\n\t// read in the kernel ...\n\tkernelsize = read(kernelfd, kernelbuf, sizeof(kernelbuf));\n\n\tif(kernelsize == -1)\n\t{\n\t\tprintf(\"Error: reading '%s'\\n\", kernelfilename);\n\t\tgoto done;\n\t}\n\n\t// calculate the kernel checksum ...\n\tkernelchecksum = cyg_crc32_accumulate(0, kernelbuf, sizeof(kernelbuf));\n\n\t// print out stats\n\tprintf(\"%s: size %d (0x%x), crc32 = 0x%x\\n\", kernelfilename, kernelsize, kernelsize, kernelchecksum);\n\n\n\t// open the root fs ..\n\trootfsfd = open(rootfsfilename, O_RDONLY);\n\n\tif(rootfsfd == -1)\n\t{\n\t\tprintf(\"Error: opening '%s'\\n\", rootfsfilename);\n\t\tgoto done;\n\t}\n\n\t// read in the root fs ..\n\trootfssize = read(rootfsfd, rootfsbuf, sizeof(rootfsbuf));\n\n\tif(rootfssize == -1)\n\t{\n\t\tprintf(\"Error: reading '%s'\\n\", rootfsfilename);\n\t\tgoto done;\n\t}\n\n\t// calculate the root fs checksum ...\n\trootfschecksum = cyg_crc32_accumulate(0, rootfsbuf, sizeof(rootfsbuf));\n\n\t// print out stats\n\tprintf(\"%s: size %d (0x%x), crc32 = 0x%x\\n\", rootfsfilename, rootfssize, rootfssize, rootfschecksum);\n\n\n\t// now for the header ...\n\n\ttotalsize = HEADERSIZE;\n\n\t// copy over kernel\n\tmemcpy(buf + totalsize, kernelbuf, kernelsize);\n\ttotalsize += kernelsize;\n\n\t// copy over root fs\n\tmemcpy(buf + totalsize, rootfsbuf, rootfssize);\n\ttotalsize += rootfssize;\n\n\t// calculate crc\n\tcrc = crc32(buf + HEADERSIZE, totalsize - HEADERSIZE);\n\n\t// print some stats out\n\tprintf(\"crc = 0x%x, total size = %d (0x%x)\\n\", crc, totalsize, totalsize);\n\n\t// copy crc into header\n\tcrc = htonl(crc);\n\tmemcpy(buf, &crc, sizeof(crc));\n\n\t// copy over magic\n\tstrcpy((char *)buf + 4, MAGIC);\n\n\t// copy over kernel size\n\tkernelsize = htonl(kernelsize);\n\tmemcpy(buf + 16, &kernelsize, sizeof(kernelsize));\n\n\t// copy over kernal flag\n\tkernelflag = htonl(0x1);\n\tmemcpy(buf + 20, &kernelflag, sizeof(kernelflag));\n\n\t// copy over root fs size\n\trootfssize = htonl(rootfssize);\n\tmemcpy(buf + 24, &rootfssize, sizeof(rootfssize));\n\n\t// copy over root fs flag\n\trootfsflag = htonl(0x1);\n\tmemcpy(buf + 28, &rootfsflag, sizeof(rootfsflag));\n\n\t// copy over kernel check sum\n\tkernelchecksum = htonl(kernelchecksum);\n\tmemcpy(buf + 32, &kernelchecksum, sizeof(kernelchecksum));\n\n\t// copy over root fs checksum\n\trootfschecksum = htonl(rootfschecksum);\n\tmemcpy(buf + 36, &rootfschecksum, sizeof(rootfschecksum));\n\n\t// copy over total size\n\ttotalsize = htonl(totalsize);\n\tmemcpy(buf + 40, &totalsize, sizeof(totalsize));\n\n\t// undo the htonl (for write)\n\ttotalsize = htonl(totalsize);\n\n\n\t// write out the file from the buffer\n\toutfd = open(outputfilename, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);\n\n\tif(outfd == -1)\n\t{\n\t\tprintf(\"ERROR: opening '%s' for write\\n\", outputfilename);\n\t}\n\n\twrite(outfd, buf, totalsize);\n\ndone:\n\t// close open fd's\n\n\tif(kernelfd != -1)\n\t{\n\t\tclose(kernelfd);\n\t\tkernelfd = -1;\n\t}\n\n\tif(rootfsfd != -1)\n\t{\n\t\tclose(rootfsfd);\n\t\trootfsfd = -1;\n\t}\n\n\tif(outfd != -1)\n\t{\n\t\tclose(outfd);\n\t\toutfd = -1;\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/firmware-tools/xorimage.c",
    "content": "/*\n * xorimage.c - partially based on OpenWrt's addpattern.c\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n */\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdint.h>\n#include <time.h>\n#include <unistd.h>\n#include <sys/stat.h>\n\nstatic char default_pattern[] = \"12345678\";\n\n\nint xor_data(uint8_t *data, size_t len, const uint8_t *pattern, int p_len, int p_off)\n{\n\tint offset = p_off;\n\twhile (len--) {\n\t\t*data ^= pattern[offset];\n\t\tdata++;\n\t\toffset = (offset + 1) % p_len;\n\t}\n\treturn offset;\n}\n\n\nvoid usage(void) __attribute__ (( __noreturn__ ));\n\nvoid usage(void)\n{\n\tfprintf(stderr, \"Usage: xorimage [-i infile] [-o outfile] [-p <pattern>]\\n\");\n\texit(EXIT_FAILURE);\n}\n\n\nint main(int argc, char **argv)\n{\n\tchar buf[1024];\t/* keep this at 1k or adjust garbage calc below */\n\tFILE *in = stdin;\n\tFILE *out = stdout;\n\tchar *ifn = NULL;\n\tchar *ofn = NULL;\n\tconst char *pattern = default_pattern;\n\tint c;\n\tint v0, v1, v2;\n\tsize_t n;\n\tint p_len, p_off = 0;\n\n\twhile ((c = getopt(argc, argv, \"i:o:p:h\")) != -1) {\n\t\tswitch (c) {\n\t\t\tcase 'i':\n\t\t\t\tifn = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'o':\n\t\t\t\tofn = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'p':\n\t\t\t\tpattern = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'h':\n\t\t\tdefault:\n\t\t\t\tusage();\n\t\t}\n\t}\n\n\tif (optind != argc || optind == 1) {\n\t\tfprintf(stderr, \"illegal arg \\\"%s\\\"\\n\", argv[optind]);\n\t\tusage();\n\t}\n\n\tif (ifn && !(in = fopen(ifn, \"r\"))) {\n\t\tfprintf(stderr, \"can not open \\\"%s\\\" for reading\\n\", ifn);\n\t\tusage();\n\t}\n\n\tif (ofn && !(out = fopen(ofn, \"w\"))) {\n\t\tfprintf(stderr, \"can not open \\\"%s\\\" for writing\\n\", ofn);\n\t\tusage();\n\t}\n\n\tp_len = strlen(pattern);\n\n\tif (p_len == 0) {\n\t\tfprintf(stderr, \"pattern cannot be empty\\n\");\n\t\tusage();\n\t}\n\n\n\twhile ((n = fread(buf, 1, sizeof(buf), in)) > 0) {\n\t\tif (n < sizeof(buf)) {\n\t\t\tif (ferror(in)) {\n\t\t\tFREAD_ERROR:\n\t\t\t\tfprintf(stderr, \"fread error\\n\");\n\t\t\t\treturn EXIT_FAILURE;\n\t\t\t}\n\t\t}\n\n\t\tp_off = xor_data(buf, n, pattern, p_len, p_off);\n\n\t\tif (!fwrite(buf, n, 1, out)) {\n\t\tFWRITE_ERROR:\n\t\t\tfprintf(stderr, \"fwrite error\\n\");\n\t\t\treturn EXIT_FAILURE;\n\t\t}\n\t}\n\n\tif (ferror(in)) {\n\t\tgoto FREAD_ERROR;\n\t}\n\n\tif (fflush(out)) {\n\t\tgoto FWRITE_ERROR;\n\t}\n\n\tfclose(in);\n\tfclose(out);\n\n\treturn EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/firmware-tools/zynos.h",
    "content": "/*\n *\n *  Copyright (C) 2007-2008 OpenWrt.org\n *  Copyright (C) 2007-2008 Gabor Juhos <juhosg at openwrt.org>\n *\n *  This code was based on the information of the ZyXEL's firmware\n *  image format written by Kolja Waschk, can be found at:\n *  http://www.ixo.de/info/zyxel_uclinux\n *\n *  This program is free software; you can redistribute it and/or modify it\n *  under the terms of the GNU General Public License version 2 as published\n *  by the Free Software Foundation.\n *\n */\n\n#ifndef _ZYNOS_H\n#define _ZYNOS_H\n\n#define BOOTBASE_NAME_LEN\t32\n#define BOOTBASE_MAC_LEN\t6\n#define BOOTBASE_FEAT_LEN\t22\n\n#define BOOTEXT_DEF_SIZE\t0x18000\n\nstruct zyn_bootbase_info {\n\tchar\t\tvendor[BOOTBASE_NAME_LEN]; /* Vendor name */\n\tchar\t\tmodel[BOOTBASE_NAME_LEN]; /* Model name */\n\tuint32_t\tbootext_addr;\t/* absolute address of the Boot Extension */\n\tuint16_t\tres0;\t\t/* reserved/unknown */\n\tuint8_t\t\tsys_type;\t/* system type */\n\tuint8_t\t\tres1;\t\t/* reserved/unknown */\n\tuint16_t\tmodel_id;\t/* model id */\n\tuint8_t\t\tfeat_other[BOOTBASE_FEAT_LEN]; /* other feature bits */\n\tuint8_t\t\tfeat_main;\t/* main feature bits */\n\tuint8_t\t\tres2;\t\t/* reserved/unknown */\n\tuint8_t\t\tmac[BOOTBASE_MAC_LEN]; /* mac address */\n\tuint8_t\t\tcountry;\t/* default country code */\n\tuint8_t\t\tdbgflag;\t/* debug flag */\n} __attribute__((packed));\n\n#define ROMBIN_SIG_LEN\t3\n#define ROMBIN_VER_LEN\t15\n\nstruct zyn_rombin_hdr {\n\tuint32_t\taddr;\t\t/* load address of the object */\n\tuint16_t\tres0;\t\t/* unknown/unused */\n\tchar\t\tsig[ROMBIN_SIG_LEN];\t/* magic, must be \"SIG\" */\n\tuint8_t\t\ttype;\t\t/* type of the object */\n\tuint32_t\tosize;\t\t/* size of the uncompressed data */\n\tuint32_t\tcsize;\t\t/* size of the compressed data */\n\tuint8_t\t\tflags;\t\t/* various flags */\n\tuint8_t\t\tres1;\t\t/* unknown/unused */\n\tuint16_t\tocsum;\t\t/* csum of the uncompressed data */\n\tuint16_t\tccsum;\t\t/* csum of the compressed data */\n\tchar\t\tver[ROMBIN_VER_LEN];\n\tuint32_t\tmmap_addr;\t/* address of the Memory Map Table*/\n\tuint32_t\tres2;\t\t/* unknown/unused*/\n\tuint8_t\t\tres3;\t\t/* unknown/unused*/\n} __attribute__((packed));\n\n#define ROMBIN_SIGNATURE\t\"SIG\"\n\n/* Rombin flag bits */\n#define ROMBIN_FLAG_01\t\t0x01\n#define ROMBIN_FLAG_02\t\t0x02\n#define ROMBIN_FLAG_04\t\t0x04\n#define ROMBIN_FLAG_08\t\t0x08\n#define ROMBIN_FLAG_10\t\t0x10\n#define ROMBIN_FLAG_CCSUM\t0x20\t/* compressed checksum is valid */\n#define ROMBIN_FLAG_OCSUM\t0x40\t/* original checksum is valid */\n#define ROMBIN_FLAG_COMPRESSED\t0x80\t/* the binary is compressed */\n\n/* Object types */\n#define OBJECT_TYPE_ROMIMG\t0x01\n#define OBJECT_TYPE_ROMBOOT\t0x02\n#define OBJECT_TYPE_BOOTEXT\t0x03\n#define OBJECT_TYPE_ROMBIN\t0x04\n#define OBJECT_TYPE_ROMDIR\t0x05\n#define OBJECT_TYPE_6\t\t0x06\n#define OBJECT_TYPE_ROMMAP\t0x07\n#define OBJECT_TYPE_RAM\t\t0x80\n#define OBJECT_TYPE_RAMCODE\t0x81\n#define OBJECT_TYPE_RAMBOOT\t0x82\n\n/*\n * Memory Map Table header\n */\nstruct zyn_mmt_hdr {\n\tuint16_t\tcount;\n\tuint32_t\tuser_start;\n\tuint32_t\tuser_end;\n\tuint16_t\tcsum;\n\tuint8_t\t\tres[12];\n} __attribute__((packed));\n\n#define OBJECT_NAME_LEN\t\t8\n\nstruct zyn_mmt_item {\n\tuint8_t\t\ttype;\t/* type of the object */\n\tuint8_t\t\tname[OBJECT_NAME_LEN]; /* name of the object */\n\tuint8_t\t\tres0;\t/* unused/unknown */\n\tuint32_t\taddr;\n\tuint32_t\tsize;\t/* size of the object */\n\tuint8_t\t\tres1[3]; /* unused/unknown */\n\tuint8_t\t\ttype2;\n} __attribute__((packed));\n\n/*\n * Vendor IDs\n */\n#define ZYNOS_VENDOR_ID_ZYXEL\t0\n#define ZYNOS_VENDOR_ID_NETGEAR\t1\n#define ZYNOS_VENDOR_ID_DLINK\t2\n#define ZYNOS_VENDOR_ID_03\t3\n#define ZYNOS_VENDOR_ID_LUCENT\t4\n#define ZYNOS_VENDOR_ID_O2\t10\n\n/*\n * Model IDs (in big-endian format)\n */\n#define MID(x)\t(((x) & 0xFF) << 8) | (((x) & 0xFF00) >> 8)\n\n/*\n * Infineon/ADMtek ADM5120 based models\n */\n#define ZYNOS_MODEL_ES_2024A\t\tMID(  221)\n#define ZYNOS_MODEL_ES_2024PWR\t\tMID( 4097)\n#define ZYNOS_MODEL_ES_2108\t\tMID(61952)\n#define ZYNOS_MODEL_ES_2108_F\t\tMID(44801)\n#define ZYNOS_MODEL_ES_2108_G\t\tMID(62208)\n#define ZYNOS_MODEL_ES_2108_LC\t\tMID(64512)\n#define ZYNOS_MODEL_ES_2108PWR\t\tMID(62464)\n#define ZYNOS_MODEL_HS_100\t\tMID(61855)\n#define ZYNOS_MODEL_HS_100W\t\tZYNOS_MODEL_HS_100\n#define ZYNOS_MODEL_P_334\t\tMID(62879)\n#define ZYNOS_MODEL_P_334U\t\tMID(56735)\n#define ZYNOS_MODEL_P_334W\t\tMID(62367)\n#define ZYNOS_MODEL_P_334WH\t\tMID(57344)\n#define ZYNOS_MODEL_P_334WHD\t\tMID(57600)\n#define ZYNOS_MODEL_P_334WT\t\tMID(61343)\n#define ZYNOS_MODEL_P_335\t\tMID(60831)\n#define ZYNOS_MODEL_P_335PLUS\t\tMID( 9472)\n#define ZYNOS_MODEL_P_335U\t\tMID(56479)\n#define ZYNOS_MODEL_P_335WT\t\tZYNOS_MODEL_P_335\n\n/*\n * Texas Instruments AR7 based models\n */\n#define ZYNOS_MODEL_P_2602H_61C\t\tMID( 3229)\n#define ZYNOS_MODEL_P_2602H_63C\t\tMID( 3485)\n#define ZYNOS_MODEL_P_2602H_D1A\t\t/* n.a. */\n#define ZYNOS_MODEL_P_2602H_D3A\t\t/* n.a. */\n#define ZYNOS_MODEL_P_2602HW_61C\t/* n.a. */\n#define ZYNOS_MODEL_P_2602HW_63\t\t/* n.a. */\n#define ZYNOS_MODEL_P_2602HW_63C\tZYNOS_MODEL_P_2602H_63C\n#define ZYNOS_MODEL_P_2602HW_D1A\tMID( 6301)\n#define ZYNOS_MODEL_P_2602HW_D3A\t/* n.a. */\n#define ZYNOS_MODEL_P_2602HWL_61\tMID( 1181)\n#define ZYNOS_MODEL_P_2602HWL_61C\tZYNOS_MODEL_P_2602H_61C\n#define ZYNOS_MODEL_P_2602HWL_63C\tZYNOS_MODEL_P_2602H_63C\n#define ZYNOS_MODEL_P_2602HWL_D1A\tZYNOS_MODEL_P_2602HW_D1A\n#define ZYNOS_MODEL_P_2602HWL_D3A\tMID( 7581)\n#define ZYNOS_MODEL_P_2602HWN_D7A\tMID(30464)\n#define ZYNOS_MODEL_P_2602HWNLI_D7A\tMID( 6813)\n\n#define ZYNOS_MODEL_P_2602R_61\t\tMID( 2205)\n#define ZYNOS_MODEL_P_2602R_63\t\tMID( 3997)\n#define ZYNOS_MODEL_P_2602R_D1A\t\t/* n.a. */\n#define ZYNOS_MODEL_P_2602R_D3A\t\t/* n.a. */\n#define ZYNOS_MODEL_P_2602RL_D1A\tMID( 6045)\n#define ZYNOS_MODEL_P_2602RL_D3A\tMID( 7069)\n\n#define ZYNOS_MODEL_P_660H_61\t\tMID(19346)\n#define ZYNOS_MODEL_P_660H_63\t\tMID(22162)\n#define ZYNOS_MODEL_P_660H_67\t\t/* n.a. */\n#define ZYNOS_MODEL_P_660H_D1\t\tMID( 7066)\n#define ZYNOS_MODEL_P_660H_D3\t\tMID(13210)\n\n#define ZYNOS_MODEL_P_660HW_61\t\tZYNOS_MODEL_P_660H_61\n#define ZYNOS_MODEL_P_660HW_63\t\tZYNOS_MODEL_P_660H_63\n#define ZYNOS_MODEL_P_660HW_67\t\tZYNOS_MODEL_P_660HW_63\n#define ZYNOS_MODEL_P_660HW_D1\t\tMID( 9114)\n#define ZYNOS_MODEL_P_660HW_D3\t\tMID(12698)\n\n#define ZYNOS_MODEL_P_660R_61\t\tMID(20882)\n#define ZYNOS_MODEL_P_660R_61C\t\tMID( 1178)\n#define ZYNOS_MODEL_P_660R_63\t\tMID(21138)\n#define ZYNOS_MODEL_P_660R_63C\t\tMID(  922)\n#define ZYNOS_MODEL_P_660R_67\t\tZYNOS_MODEL_P_660R_63\n#define ZYNOS_MODEL_P_660R_67C\t\t/* n.a. */\n#define ZYNOS_MODEL_P_660R_D1\t\tMID( 7322)\n#define ZYNOS_MODEL_P_660R_D3\t\tMID(10138)\n\n#define ZYNOS_MODEL_P_661H_61\t\tMID(19346)\n#define ZYNOS_MODEL_P_661H_63\t\tMID( 1946)\n#define ZYNOS_MODEL_P_661H_D1\t\tMID(10650)\n#define ZYNOS_MODEL_P_661H_D3\t\tMID(12442)\n\n#define ZYNOS_MODEL_P_661HW_61\t\tZYNOS_MODEL_P_661H_61\n#define ZYNOS_MODEL_P_661HW_63\t\tZYNOS_MODEL_P_661H_63\n#define ZYNOS_MODEL_P_661HW_D1\t\tMID(10906)\n#define ZYNOS_MODEL_P_661HW_D3\t\tMID(14746)\n\n#define ZYNOS_MODEL_P_662H_61\t\tMID(22418)\n#define ZYNOS_MODEL_P_662H_63\t\t/* n.a. */\n#define ZYNOS_MODEL_P_662H_67\t\t/* n.a. */\n#define ZYNOS_MODEL_P_662H_D1\t\t/* n.a. */\n#define ZYNOS_MODEL_P_662H_D3\t\t/* n.a. */\n\n#define ZYNOS_MODEL_P_662HW_61\t\t/* n.a. */\n#define ZYNOS_MODEL_P_662HW_63\t\tMID(22674)\n#define ZYNOS_MODEL_P_662HW_67\t\t/* n.a. */\n#define ZYNOS_MODEL_P_662HW_D1\t\tMID(10394)\n#define ZYNOS_MODEL_P_662HW_D3\t\tMID(12954)\n\n/* OEM boards */\n#define ZYNOS_MODEL_O2SURF\t\tZYNOS_MODEL_P_2602HWN_D7A\n\n/* Atheros AR2318 based boards */\n#define ZYNOS_MODEL_NBG_318S\t\tMID(59392)\n\n/* Atheros AR71xx based boards */\n#define ZYNOS_MODEL_NBG_460N\t\tMID(61441)\n\n#endif /* _ZYNOS_H */\n"
  },
  {
    "path": "src/jffs2/unjffs2",
    "content": "#!/bin/bash\n# Script to mount a JFFS2 image and copy the file system's files to a destination directory.\n#\n# Craig Heffner\n# 27 August 2011\n\nIMG=\"$1\"\nDST=\"$2\"\nBLOCK=\"/dev/mtdblock1\"\n\nif [ \"$IMG\" == \"\" ] || [ \"$IMG\" == \"-h\" ]\nthen\n\techo \"Usage: $0 <jffs2 image> [mount directory]\"\n\texit 1\nfi\n\n# Need to extract file systems as ROOT\n#if [ \"$UID\" != \"0\" ]\n#then\n#        SUDO=\"sudo\"\n#else\n#        SUDO=\"\"\n#fi\n\nif [ \"$DST\" == \"\" ]\nthen\n\tDST=\"jffs2-root\"\nfi\n\nif [ -e \"$DST\" ]\nthen\n\techo \"ERROR: $DST already exists! Quitting...\"\n\texit 1\nfi\n\nif [ \"$(file $IMG | grep little)\" == \"\" ]\nthen\n\techo \"Converting image to little endian...\"\n\tjffs2dump -b -e $IMG.le $IMG\n\tIMG=$IMG.le\nfi\n\n#Make sure required modules are loaded\n$SUDO modprobe mtdblock\n$SUDO modprobe mtdchar\n$SUDO modprobe mtd\n$SUDO rmmod mtdram\n$SUDO modprobe mtdram total_size=$((64*1024))\n\n#Create destination and temporary mount directories\n$SUDO mkdir -p $DST && $SUDO mkdir -p $DST\n\nif [ $? == 0 ]\nthen\n\tif [ ! -e $BLOCK ]\n\tthen\n\t\t$SUDO mknod $BLOCK b 31 0\n\tfi\n\n\t#Copy JFSS2 image to MTD block\n\t$SUDO dd if=\"$IMG\" of=$BLOCK && $SUDO mount -t jffs2 $BLOCK $DST\n\n\tif [ $? == 0 ]\n\tthen\n\t\techo \"JFFS2 image mounted to $DST\"\n\t\texit 0\n\telse\n\t\techo \"ERROR: Failed to mount $IMG to $BLOCK\"\n\t\t$SUDO rm -rf \"$DST\"\n\tfi\nelse\n\techo \"ERROR: Directory creation failed\"\n\t$SUDO rm -rf \"$DST\"\nfi\n\nexit 1\n"
  },
  {
    "path": "src/lzma/.built",
    "content": ""
  },
  {
    "path": "src/lzma/.unpacked",
    "content": ""
  },
  {
    "path": "src/lzma/7zC.txt",
    "content": "7z ANSI-C Decoder 4.23\r\n----------------------\r\n\r\n7z ANSI-C Decoder 4.23 Copyright (C) 1999-2005 Igor Pavlov\r\n\r\n7z ANSI-C provides 7z/LZMA decoding.\r\n7z ANSI-C version is simplified version ported from C++ code.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nRead lzma.txt for information about license.\r\n\r\n\r\nFiles\r\n---------------------\r\n\r\n7zAlloc.*    - Allocate and Free\r\n7zBuffer.*   - Buffer structure\r\n7zCrc.*      - CRC32 code\r\n7zDecode.*   - Low level memory->memory decoding\r\n7zExtract.*  - High level stream->memory decoding\r\n7zHeader.*   - .7z format constants\r\n7zIn.*       - .7z archive opening\r\n7zItem.*     - .7z structures\r\n7zMain.c     - Test application\r\n7zMethodID.* - MethodID structure\r\n7zTypes.h    - Base types and constants\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nYou must download 7-Zip program from www.7-zip.org.\r\n\r\nYou can create .7z archive with 7z.exe or 7za.exe:\r\n\r\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255\r\n\r\nIf you have big number of files in archive, and you need fast extracting, \r\nyou can use partly-solid archives:\r\n  \r\n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\r\n\r\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r\n512KB for extracting one file from such archive.\r\n\r\n\r\nLimitations of current version of 7z ANSI-C Decoder\r\n---------------------------------------------------\r\n\r\n - It reads only \"FileName\", \"Size\", and \"CRC\" information for each file in archive.\r\n - It supports only LZMA and Copy (no compression) methods.\r\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r\n \r\nThese limitations will be fixed in future versions.\r\n\r\n\r\nUsing 7z ANSI-C Decoder Test application:\r\n-----------------------------------------\r\n\r\nUsage: 7zDec <command> <archive_name>\r\n\r\n<Command>:\r\n  e: Extract files from archive\r\n  l: List contents of archive\r\n  t: Test integrity of archive\r\n\r\nExample: \r\n\r\n  7zDec l archive.7z\r\n\r\nlists contents of archive.7z\r\n\r\n  7zDec e archive.7z\r\n\r\nextracts files from archive.7z to current folder.\r\n\r\n\r\nHow to use .7z Decoder\r\n----------------------\r\n\r\n.7z Decoder can be compiled in one of two modes:\r\n\r\n1) Default mode. In that mode 7z Decoder will read full compressed \r\n   block to RAM before decompressing.\r\n  \r\n2) Mode with defined _LZMA_IN_CB. In that mode 7z Decoder can read\r\n   compressed block by parts. And you can specify desired buffer size. \r\n   So memory requirements can be reduced. But decompressing speed will \r\n   be 5-10% lower and code size is slightly larger.\r\n\r\n   \r\nMemory allocation\r\n~~~~~~~~~~~~~~~~~\r\n\r\n7z Decoder uses two memory pools:\r\n1) Temporary pool\r\n2) Main pool\r\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\r\n\r\nSteps for using 7z decoder\r\n--------------------------\r\n\r\nUse code at 7zMain.c as example.\r\n\r\n1) Declare variables:\r\n  inStream                     /* implements ISzInStream interface */\r\n  CArchiveDatabaseEx db;       /* 7z archive database structure */\r\n  ISzAlloc allocImp;           /* memory functions for main pool */\r\n  ISzAlloc allocTempImp;       /* memory functions for temporary pool */\r\n\r\n2) call InitCrcTable(); function to initialize CRC structures.\r\n\r\n3) call SzArDbExInit(&db); function to initialize db structures.\r\n\r\n4) call SzArchiveOpen(inStream, &db, &allocMain, &allocTemp) to open archive\r\n\r\nThis function opens archive \"inStream\" and reads headers to \"db\".\r\nAll items in \"db\" will be allocated with \"allocMain\" functions.\r\nSzArchiveOpen function allocates and frees temporary structures by \"allocTemp\" functions.\r\n\r\n5) List items or Extract items\r\n\r\n  Listing code:\r\n  ~~~~~~~~~~~~~\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n\r\n  Extracting code:\r\n  ~~~~~~~~~~~~~~~~\r\n\r\n  SZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n  If you need to decompress more than one file, you can send these values from previous call:\r\n    blockIndex, \r\n    outBuffer, \r\n    outBufferSize,\r\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \r\n  it will increase decompression speed.\r\n\r\n  After decompressing you must free \"outBuffer\":\r\n  allocImp.Free(outBuffer);\r\n\r\n6) call SzArDbExFree(&db, allocImp.Free) to free allocated items in \"db\".\r\n\r\n\r\n\r\n\r\nMemory requirements for .7z decoding \r\n------------------------------------\r\n\r\nMemory usage for Archive opening:\r\n  - Temporary pool:\r\n     - Memory for compressed .7z headers (if _LZMA_IN_CB is not defined)\r\n     - Memory for uncompressed .7z headers\r\n     - some other temporary blocks\r\n  - Main pool:\r\n     - Memory for database: \r\n       Estimated size of one file structures in solid archive:\r\n         - Size (4 or 8 Bytes)\r\n         - CRC32 (4 bytes)\r\n         - Some file information (4 bytes)\r\n         - File Name (variable length) + pointer + allocation structures\r\n\r\nMemory usage for archive Decompressing:\r\n  - Temporary pool:\r\n     - Memory for compressed solid block (if _LZMA_IN_CB is not defined)\r\n     - Memory for LZMA decompressing structures\r\n  - Main pool:\r\n     - Memory for decompressed solid block\r\n  \r\n\r\nIf _LZMA_IN_CB is defined, 7z Decoder will not allocate memory for \r\ncompressed blocks. Instead of this, you must allocate buffer with desired \r\nsize before calling 7z Decoder. Use 7zMain.c as example.\r\n\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\n7z Decoder functions can return one of the following codes:\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_CRC_ERROR (3)\r\n\r\n#define SZE_NOTIMPL (4)\r\n#define SZE_FAIL (5)\r\n\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB       - Use special callback mode for input stream to reduce memory requirements\r\n\r\n_SZ_FILE_SIZE_64  - define it if you need support for files larger than 4 GB\r\n_SZ_NO_INT_64     - define it if your compiler doesn't support long long int\r\n\r\n_LZMA_PROB32      - it can increase LZMA decompressing speed on some 32-bit CPUs.\r\n\r\n_SZ_ONE_DIRECTORY - define it if you want to locate all source files to one directory\r\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/lzma/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\r\n-----------------------------------\r\n\r\nThis file contains description of 7z archive format. \r\n7z archive can contain files compressed with any method.\r\nSee \"Methods.txt\" for description for defined compressing methods.\r\n\r\n\r\nFormat structure Overview\r\n-------------------------\r\n\r\nSome fields can be optional.\r\n\r\nArchive structure\r\n~~~~~~~~~~~~~~~~~  \r\nSignatureHeader\r\n[PackedStreams]\r\n[PackedStreamsForHeaders]\r\n[\r\n  Header \r\n  or \r\n  {\r\n    Packed Header\r\n    HeaderInfo\r\n  }\r\n]\r\n\r\n\r\n\r\nHeader structure\r\n~~~~~~~~~~~~~~~~  \r\n{\r\n  ArchiveProperties\r\n  AdditionalStreams\r\n  {\r\n    PackInfo\r\n    {\r\n      PackPos\r\n      NumPackStreams\r\n      Sizes[NumPackStreams]\r\n      CRCs[NumPackStreams]\r\n    }\r\n    CodersInfo\r\n    {\r\n      NumFolders\r\n      Folders[NumFolders]\r\n      {\r\n        NumCoders\r\n        CodersInfo[NumCoders]\r\n        {\r\n          ID\r\n          NumInStreams;\r\n          NumOutStreams;\r\n          PropertiesSize\r\n          Properties[PropertiesSize]\r\n        }\r\n        NumBindPairs\r\n        BindPairsInfo[NumBindPairs]\r\n        {\r\n          InIndex;\r\n          OutIndex;\r\n        }\r\n        PackedIndices\r\n      }\r\n      UnPackSize[Folders][Folders.NumOutstreams]\r\n      CRCs[NumFolders]\r\n    }\r\n    SubStreamsInfo\r\n    {\r\n      NumUnPackStreamsInFolders[NumFolders];\r\n      UnPackSizes[]\r\n      CRCs[]\r\n    }\r\n  }\r\n  MainStreamsInfo\r\n  {\r\n    (Same as in AdditionalStreams)\r\n  }\r\n  FilesInfo\r\n  {\r\n    NumFiles\r\n    Properties[]\r\n    {\r\n      ID\r\n      Size\r\n      Data\r\n    }\r\n  }\r\n}\r\n\r\nHeaderInfo structure\r\n~~~~~~~~~~~~~~~~~~~~\r\n{\r\n  (Same as in AdditionalStreams)\r\n}\r\n\r\n\r\n\r\nNotes about Notation and encoding\r\n---------------------------------\r\n\r\n7z uses little endian encoding.\r\n\r\n7z archive format has optional headers that are marked as\r\n[]\r\nHeader\r\n[]\r\n\r\nREAL_UINT64 means real UINT64.\r\n\r\nUINT64 means real UINT64 encoded with the following scheme:\r\n\r\n  Size of encoding sequence depends from first byte:\r\n  First_Byte  Extra_Bytes        Value\r\n  (binary)   \r\n  0xxxxxxx               : ( xxxxxxx           )\r\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r\n  ...\r\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r\n  11111110    BYTE y[7]  :                         y\r\n  11111111    BYTE y[8]  :                         y\r\n\r\n\r\n\r\nProperty IDs\r\n------------\r\n\r\n0x00 = kEnd,\r\n\r\n0x01 = kHeader,\r\n\r\n0x02 = kArchiveProperties,\r\n    \r\n0x03 = kAdditionalStreamsInfo,\r\n0x04 = kMainStreamsInfo,\r\n0x05 = kFilesInfo,\r\n    \r\n0x06 = kPackInfo,\r\n0x07 = kUnPackInfo,\r\n0x08 = kSubStreamsInfo,\r\n\r\n0x09 = kSize,\r\n0x0A = kCRC,\r\n\r\n0x0B = kFolder,\r\n\r\n0x0C = kCodersUnPackSize,\r\n0x0D = kNumUnPackStream,\r\n\r\n0x0E = kEmptyStream,\r\n0x0F = kEmptyFile,\r\n0x10 = kAnti,\r\n\r\n0x11 = kName,\r\n0x12 = kCreationTime,\r\n0x13 = kLastAccessTime,\r\n0x14 = kLastWriteTime,\r\n0x15 = kWinAttributes,\r\n0x16 = kComment,\r\n\r\n0x17 = kEncodedHeader,\r\n\r\n\r\n7z format headers\r\n-----------------\r\n\r\nSignatureHeader\r\n~~~~~~~~~~~~~~~\r\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n\r\n  ArchiveVersion\r\n  {\r\n    BYTE Major;   // now = 0\r\n    BYTE Minor;   // now = 2\r\n  };\r\n\r\n  UINT32 StartHeaderCRC;\r\n\r\n  StartHeader\r\n  {\r\n    REAL_UINT64 NextHeaderOffset\r\n    REAL_UINT64 NextHeaderSize\r\n    UINT32 NextHeaderCRC\r\n  }\r\n\r\n\r\n...........................\r\n\r\n\r\nArchiveProperties\r\n~~~~~~~~~~~~~~~~~\r\nBYTE NID::kArchiveProperties (0x02)\r\nwhile(true)\r\n{\r\n  BYTE PropertyType;\r\n  if (aType == 0)\r\n    break;\r\n  UINT64 PropertySize;\r\n  BYTE PropertyData[PropertySize];\r\n}\r\n\r\n\r\nDigests (NumStreams)\r\n~~~~~~~~~~~~~~~~~~~~~\r\n  BYTE AllAreDefined\r\n  if (AllAreDefined == 0)\r\n  {\r\n    for(NumStreams)\r\n      BIT Defined\r\n  }\r\n  UINT32 CRCs[NumDefined]\r\n\r\n\r\nPackInfo\r\n~~~~~~~~~~~~\r\n  BYTE NID::kPackInfo  (0x06)\r\n  UINT64 PackPos\r\n  UINT64 NumPackStreams\r\n\r\n  []\r\n  BYTE NID::kSize    (0x09)\r\n  UINT64 PackSizes[NumPackStreams]\r\n  []\r\n\r\n  []\r\n  BYTE NID::kCRC      (0x0A)\r\n  PackStreamDigests[NumPackStreams]\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFolder\r\n~~~~~~\r\n  UINT64 NumCoders;\r\n  for (NumCoders)\r\n  {\r\n    BYTE \r\n    {\r\n      0:3 DecompressionMethod.IDSize\r\n      4:\r\n        0 - IsSimple\r\n        1 - Is not simple\r\n      5:\r\n        0 - No Attributes\r\n        1 - There Are Attributes\r\n      7:\r\n        0 - Last Method in Alternative_Method_List\r\n        1 - There are more alternative methods\r\n    } \r\n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\r\n    if (!IsSimple)\r\n    {\r\n      UINT64 NumInStreams;\r\n      UINT64 NumOutStreams;\r\n    }\r\n    if (DecompressionMethod[0] != 0)\r\n    {\r\n      UINT64 PropertiesSize\r\n      BYTE Properties[PropertiesSize]\r\n    }\r\n  }\r\n    \r\n  NumBindPairs = NumOutStreamsTotal - 1;\r\n\r\n  for (NumBindPairs)\r\n  {\r\n    UINT64 InIndex;\r\n    UINT64 OutIndex;\r\n  }\r\n\r\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r\n  if (NumPackedStreams > 1)\r\n    for(NumPackedStreams)\r\n    {\r\n      UINT64 Index;\r\n    };\r\n\r\n\r\n\r\n\r\nCoders Info\r\n~~~~~~~~~~~\r\n\r\n  BYTE NID::kUnPackInfo  (0x07)\r\n\r\n\r\n  BYTE NID::kFolder  (0x0B)\r\n  UINT64 NumFolders\r\n  BYTE External\r\n  switch(External)\r\n  {\r\n    case 0:\r\n      Folders[NumFolders]\r\n    case 1:\r\n      UINT64 DataStreamIndex\r\n  }\r\n\r\n\r\n  BYTE ID::kCodersUnPackSize  (0x0C)\r\n  for(Folders)\r\n    for(Folder.NumOutStreams)\r\n     UINT64 UnPackSize;\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC   (0x0A)\r\n  UnPackDigests[NumFolders]\r\n  []\r\n\r\n  \r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\n\r\nSubStreams Info\r\n~~~~~~~~~~~~~~\r\n  BYTE NID::kSubStreamsInfo; (0x08)\r\n\r\n  []\r\n  BYTE NID::kNumUnPackStream; (0x0D)\r\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kSize  (0x09)\r\n  UINT64 UnPackSizes[]\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC  (0x0A)\r\n  Digests[Number of streams with unknown CRC]\r\n  []\r\n\r\n  \r\n  BYTE NID::kEnd\r\n\r\n\r\nStreams Info\r\n~~~~~~~~~~~~\r\n\r\n  []\r\n  PackInfo\r\n  []\r\n\r\n\r\n  []\r\n  CodersInfo\r\n  []\r\n\r\n\r\n  []\r\n  SubStreamsInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFilesInfo\r\n~~~~~~~~~\r\n  BYTE NID::kFilesInfo;  (0x05)\r\n  UINT64 NumFiles\r\n\r\n  while(true)\r\n  {\r\n    BYTE PropertyType;\r\n    if (aType == 0)\r\n      break;\r\n\r\n    UINT64 Size;\r\n\r\n    switch(PropertyType)\r\n    {\r\n      kEmptyStream:   (0x0E)\r\n        for(NumFiles)\r\n          BIT IsEmptyStream\r\n\r\n      kEmptyFile:     (0x0F)\r\n        for(EmptyStreams)\r\n          BIT IsEmptyFile\r\n\r\n      kAnti:          (0x10)\r\n        for(EmptyStreams)\r\n          BIT IsAntiFile\r\n      \r\n      case kCreationTime:   (0x12)\r\n      case kLastAccessTime: (0x13)\r\n      case kLastWriteTime:  (0x14)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT TimeDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Items)\r\n          UINT32 Time\r\n        []\r\n      \r\n      kNames:     (0x11)\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Files)\r\n        {\r\n          wchar_t Names[NameSize];\r\n          wchar_t 0;\r\n        }\r\n        []\r\n\r\n      kAttributes:  (0x15)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT AttributesAreDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Attributes)\r\n          UINT32 Attributes\r\n        []\r\n    }\r\n  }\r\n\r\n\r\nHeader\r\n~~~~~~\r\n  BYTE NID::kHeader (0x01)\r\n\r\n  []\r\n  ArchiveProperties\r\n  []\r\n\r\n  []\r\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  BYTE NID::kMainStreamsInfo;    (0x04)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  FilesInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nHeaderInfo\r\n~~~~~~~~~~\r\n  []\r\n  BYTE NID::kEncodedHeader; (0x17)\r\n  StreamsInfo for Encoded Header\r\n  []\r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zAlloc.c",
    "content": "/* 7zAlloc.c */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n#endif\r\n\r\nvoid *SzAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zAlloc.h",
    "content": "/* 7zAlloc.h */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\nvoid *SzAlloc(size_t size);\r\nvoid SzFree(void *address);\r\n\r\nvoid *SzAllocTemp(size_t size);\r\nvoid SzFreeTemp(void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zBuffer.c",
    "content": "/* 7zBuffer.c */\r\n\r\n#include \"7zBuffer.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer)\r\n{\r\n  buffer->Capacity = 0;\r\n  buffer->Items = 0;\r\n}\r\n\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))\r\n{\r\n  buffer->Capacity = newCapacity;\r\n  if (newCapacity == 0)\r\n  {\r\n    buffer->Items = 0;\r\n    return 1;\r\n  }\r\n  buffer->Items = (Byte *)allocFunc(newCapacity);\r\n  return (buffer->Items != 0);\r\n}\r\n\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(buffer->Items);\r\n  buffer->Items = 0;\r\n  buffer->Capacity = 0;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zBuffer.h",
    "content": "/* 7zBuffer.h */\r\n\r\n#ifndef __7Z_BUFFER_H\r\n#define __7Z_BUFFER_H\r\n\r\n#include <stddef.h>\r\n#include \"7zTypes.h\"\r\n\r\ntypedef struct _CSzByteBuffer\r\n{    \r\n\tsize_t Capacity;\r\n  Byte *Items;\r\n}CSzByteBuffer;\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer);\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zCrc.c",
    "content": "/* 7zCrc.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid InitCrcTable()\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      if (r & 1) \r\n        r = (r >> 1) ^ kCrcPoly;\r\n      else     \r\n        r >>= 1;\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nvoid CrcInit(UInt32 *crc) { *crc = 0xFFFFFFFF; }\r\nUInt32 CrcGetDigest(UInt32 *crc) { return *crc ^ 0xFFFFFFFF; } \r\n\r\nvoid CrcUpdateByte(UInt32 *crc, Byte b)\r\n{\r\n  *crc = g_CrcTable[((Byte)(*crc)) ^ b] ^ (*crc >> 8);\r\n}\r\n\r\nvoid CrcUpdateUInt16(UInt32 *crc, UInt16 v)\r\n{\r\n  CrcUpdateByte(crc, (Byte)v);\r\n  CrcUpdateByte(crc, (Byte)(v >> 8));\r\n}\r\n\r\nvoid CrcUpdateUInt32(UInt32 *crc, UInt32 v)\r\n{\r\n  int i;\r\n  for (i = 0; i < 4; i++)\r\n    CrcUpdateByte(crc, (Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CrcUpdateUInt64(UInt32 *crc, UInt64 v)\r\n{\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    CrcUpdateByte(crc, (Byte)(v));\r\n    v >>= 8;\r\n  }\r\n}\r\n\r\nvoid CrcUpdate(UInt32 *crc, const void *data, size_t size)\r\n{\r\n  UInt32 v = *crc;\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = g_CrcTable[((Byte)(v)) ^ *p] ^ (v >> 8);\r\n  *crc = v;\r\n}\r\n\r\nUInt32 CrcCalculateDigest(const void *data, size_t size)\r\n{\r\n  UInt32 crc;\r\n  CrcInit(&crc);\r\n  CrcUpdate(&crc, data, size);\r\n  return CrcGetDigest(&crc);\r\n}\r\n\r\nint CrcVerifyDigest(UInt32 digest, const void *data, size_t size)\r\n{\r\n  return (CrcCalculateDigest(data, size) == digest);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zCrc.h",
    "content": "/* 7zCrc.h */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"7zTypes.h\"\r\n\r\nextern UInt32 g_CrcTable[256];\r\nvoid InitCrcTable();\r\n\r\nvoid CrcInit(UInt32 *crc);\r\nUInt32 CrcGetDigest(UInt32 *crc);\r\nvoid CrcUpdateByte(UInt32 *crc, Byte v);\r\nvoid CrcUpdateUInt16(UInt32 *crc, UInt16 v);\r\nvoid CrcUpdateUInt32(UInt32 *crc, UInt32 v);\r\nvoid CrcUpdateUInt64(UInt32 *crc, UInt64 v);\r\nvoid CrcUpdate(UInt32 *crc, const void *data, size_t size);\r\n \r\nUInt32 CrcCalculateDigest(const void *data, size_t size);\r\nint CrcVerifyDigest(UInt32 digest, const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zDecode.c",
    "content": "/* 7zDecode.c */\r\n\r\n#include \"7zDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#else\r\n#include \"../../Compress/LZMA_C/LzmaDecode.h\"\r\n#endif\r\n\r\nCMethodID k_Copy = { { 0x0 }, 1 };\r\nCMethodID k_LZMA = { { 0x3, 0x1, 0x1 }, 3 };\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\ntypedef struct _CLzmaInCallbackImp\r\n{\r\n  ILzmaInCallback InCallback;\r\n  ISzInStream *InStream;\r\n  size_t Size;\r\n} CLzmaInCallbackImp;\r\n\r\nint LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object;\r\n  size_t processedSize;\r\n  SZ_RESULT res;\r\n  *size = 0;\r\n  res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, cb->Size, &processedSize);\r\n  *size = (SizeT)processedSize;\r\n  if (processedSize > cb->Size)\r\n    return (int)SZE_FAIL;\r\n  cb->Size -= processedSize;\r\n  if (res == SZ_OK)\r\n    return 0;\r\n  return (int)res;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, \r\n    size_t *outSizeProcessed, ISzAlloc *allocMain)\r\n{\r\n  UInt32 si;\r\n  size_t inSize = 0;\r\n  CCoderInfo *coder;\r\n  if (folder->NumPackStreams != 1)\r\n    return SZE_NOTIMPL;\r\n  if (folder->NumCoders != 1)\r\n    return SZE_NOTIMPL;\r\n  coder = folder->Coders;\r\n  *outSizeProcessed = 0;\r\n\r\n  for (si = 0; si < folder->NumPackStreams; si++)\r\n    inSize += (size_t)packSizes[si];\r\n\r\n  if (AreMethodsEqual(&coder->MethodID, &k_Copy))\r\n  {\r\n    size_t i;\r\n    if (inSize != outSize)\r\n      return SZE_DATA_ERROR;\r\n    #ifdef _LZMA_IN_CB\r\n    for (i = 0; i < inSize;)\r\n    {\r\n      size_t j;\r\n      Byte *inBuffer;\r\n      size_t bufferSize;\r\n      RINOK(inStream->Read((void *)inStream,  (void **)&inBuffer, inSize - i, &bufferSize));\r\n      if (bufferSize == 0)\r\n        return SZE_DATA_ERROR;\r\n      if (bufferSize > inSize - i)\r\n        return SZE_FAIL;\r\n      *outSizeProcessed += bufferSize;\r\n      for (j = 0; j < bufferSize && i < inSize; j++, i++)\r\n        outBuffer[i] = inBuffer[j];\r\n    }\r\n    #else\r\n    for (i = 0; i < inSize; i++)\r\n      outBuffer[i] = inBuffer[i];\r\n    *outSizeProcessed = inSize;\r\n    #endif\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (AreMethodsEqual(&coder->MethodID, &k_LZMA))\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    CLzmaInCallbackImp lzmaCallback;\r\n    #else\r\n    SizeT inProcessed;\r\n    #endif\r\n\r\n    CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n    int result;\r\n    SizeT outSizeProcessedLoc;\r\n\r\n    #ifdef _LZMA_IN_CB\r\n    lzmaCallback.Size = inSize;\r\n    lzmaCallback.InStream = inStream;\r\n    lzmaCallback.InCallback.Read = LzmaReadImp;\r\n    #endif\r\n\r\n    if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, \r\n        coder->Properties.Capacity) != LZMA_RESULT_OK)\r\n      return SZE_FAIL;\r\n\r\n    state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n    if (state.Probs == 0)\r\n      return SZE_OUTOFMEMORY;\r\n\r\n    #ifdef _LZMA_OUT_READ\r\n    if (state.Properties.DictionarySize == 0)\r\n      state.Dictionary = 0;\r\n    else\r\n    {\r\n      state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize);\r\n      if (state.Dictionary == 0)\r\n      {\r\n        allocMain->Free(state.Probs);\r\n        return SZE_OUTOFMEMORY;\r\n      }\r\n    }\r\n    LzmaDecoderInit(&state);\r\n    #endif\r\n\r\n    result = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &lzmaCallback.InCallback,\r\n        #else\r\n        inBuffer, (SizeT)inSize, &inProcessed,\r\n        #endif\r\n        outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n    *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n    allocMain->Free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    allocMain->Free(state.Dictionary);\r\n    #endif\r\n    if (result == LZMA_RESULT_DATA_ERROR)\r\n      return SZE_DATA_ERROR;\r\n    if (result != LZMA_RESULT_OK)\r\n      return SZE_FAIL;\r\n    return SZ_OK;\r\n  }\r\n  return SZE_NOTIMPL;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zDecode.h",
    "content": "/* 7zDecode.h */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n#ifdef _LZMA_IN_CB\r\n#include \"7zIn.h\"\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *stream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, \r\n    size_t *outSizeProcessed, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zExtract.c",
    "content": "/* 7zExtract.c */\r\n\r\n#include \"7zExtract.h\"\r\n#include \"7zDecode.h\"\r\n#include \"7zCrc.h\"\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer, \r\n    size_t *outBufferSize,\r\n    size_t *offset, \r\n    size_t *outSizeProcessed, \r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];\r\n  SZ_RESULT res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    allocMain->Free(*outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CFolder *folder = db->Database.Folders + folderIndex;\r\n    CFileSize unPackSize = SzFolderGetUnPackSize(folder);\r\n    #ifndef _LZMA_IN_CB\r\n    CFileSize packSize = SzArDbGetFolderFullPackSize(db, folderIndex);\r\n    Byte *inBuffer = 0;\r\n    size_t processedSize;\r\n    #endif\r\n    *blockIndex = folderIndex;\r\n    allocMain->Free(*outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(inStream->Seek(inStream, SzArDbGetFolderStreamPos(db, folderIndex, 0)));\r\n    \r\n    #ifndef _LZMA_IN_CB\r\n    if (packSize != 0)\r\n    {\r\n      inBuffer = (Byte *)allocTemp->Alloc((size_t)packSize);\r\n      if (inBuffer == 0)\r\n        return SZE_OUTOFMEMORY;\r\n    }\r\n    res = inStream->Read(inStream, inBuffer, (size_t)packSize, &processedSize);\r\n    if (res == SZ_OK && processedSize != (size_t)packSize)\r\n      res = SZE_FAIL;\r\n    #endif\r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = (size_t)unPackSize;\r\n      if (unPackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)allocMain->Alloc((size_t)unPackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZE_OUTOFMEMORY;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        size_t outRealSize;\r\n        res = SzDecode(db->Database.PackSizes + \r\n          db->FolderStartPackStreamIndex[folderIndex], folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream,\r\n          #else\r\n          inBuffer, \r\n          #endif\r\n          *outBuffer, (size_t)unPackSize, &outRealSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (outRealSize == (size_t)unPackSize)\r\n          {\r\n            if (folder->UnPackCRCDefined)\r\n            {\r\n              if (!CrcVerifyDigest(folder->UnPackCRC, *outBuffer, (size_t)unPackSize))\r\n                res = SZE_FAIL;\r\n            }\r\n          }\r\n          else\r\n            res = SZE_FAIL;\r\n        }\r\n      }\r\n    }\r\n    #ifndef _LZMA_IN_CB\r\n    allocTemp->Free(inBuffer);\r\n    #endif\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i; \r\n    CFileItem *fileItem = db->Database.Files + fileIndex;\r\n    *offset = 0;\r\n    for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)db->Database.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZE_FAIL;\r\n    {\r\n      if (fileItem->IsFileCRCDefined)\r\n      {\r\n        if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer + *offset, *outSizeProcessed))\r\n          res = SZE_FAIL;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zExtract.h",
    "content": "/* 7zExtract.h */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive. \r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send \r\n    these values from previous call:\r\n      *blockIndex, \r\n      *outBuffer, \r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid, \r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables \r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zHeader.c",
    "content": "/*  7zHeader.c */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zHeader.h",
    "content": "/* 7zHeader.h */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"7zTypes.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnPackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnPackSize,\r\n  k7zIdNumUnPackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCreationTime,\r\n  k7zIdLastAccessTime,\r\n  k7zIdLastWriteTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zIn.c",
    "content": "/* 7zIn.c */\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zCrc.h\"\r\n#include \"7zDecode.h\"\r\n\r\n#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db)\r\n{\r\n  SzArchiveDatabaseInit(&db->Database);\r\n  db->FolderStartPackStreamIndex = 0;\r\n  db->PackStreamStartPositions = 0;\r\n  db->FolderStartFileIndex = 0;\r\n  db->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(db->FolderStartPackStreamIndex);\r\n  freeFunc(db->PackStreamStartPositions);\r\n  freeFunc(db->FolderStartFileIndex);\r\n  freeFunc(db->FileIndexToFolderIndexMap);\r\n  SzArchiveDatabaseFree(&db->Database, freeFunc);\r\n  SzArDbExInit(db);\r\n}\r\n\r\n/*\r\nCFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nCFileSize GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n\r\nSZ_RESULT MySzInAlloc(void **p, size_t size, void * (*allocFunc)(size_t size))\r\n{\r\n  if (size == 0)\r\n    *p = 0;\r\n  else\r\n  {\r\n    *p = allocFunc(size);\r\n    RINOM(*p);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 startPos = 0;\r\n  CFileSize startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  RINOK(MySzInAlloc((void **)&db->FolderStartPackStreamIndex, db->Database.NumFolders * sizeof(UInt32), allocFunc));\r\n  for(i = 0; i < db->Database.NumFolders; i++)\r\n  {\r\n    db->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += db->Database.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  RINOK(MySzInAlloc((void **)&db->PackStreamStartPositions, db->Database.NumPackStreams * sizeof(CFileSize), allocFunc));\r\n\r\n  for(i = 0; i < db->Database.NumPackStreams; i++)\r\n  {\r\n    db->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += db->Database.PackSizes[i];\r\n  }\r\n\r\n  RINOK(MySzInAlloc((void **)&db->FolderStartFileIndex, db->Database.NumFolders * sizeof(UInt32), allocFunc));\r\n  RINOK(MySzInAlloc((void **)&db->FileIndexToFolderIndexMap, db->Database.NumFiles * sizeof(UInt32), allocFunc));\r\n\r\n  for (i = 0; i < db->Database.NumFiles; i++)\r\n  {\r\n    CFileItem *file = db->Database.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      db->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      while(1)\r\n      {\r\n        if (folderIndex >= db->Database.NumFolders)\r\n          return SZE_ARCHIVE_ERROR;\r\n        db->FolderStartFileIndex[folderIndex] = i;\r\n        if (db->Database.Folders[folderIndex].NumUnPackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    db->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return db->ArchiveInfo.DataStartPosition + \r\n    db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nCFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex)\r\n{\r\n  UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n  CFolder *folder = db->Database.Folders + folderIndex;\r\n  CFileSize size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n    size += db->Database.PackSizes[packStreamIndex + i];\r\n  return size;\r\n}\r\n\r\n\r\n/*\r\nSZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case k7zIdLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case k7zIdLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nSZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  while (size > 0)\r\n  {\r\n    Byte *inBuffer;\r\n    size_t processedSize;\r\n    RINOK(inStream->Read(inStream, (void **)&inBuffer, size, &processedSize));\r\n    if (processedSize == 0 || processedSize > size)\r\n      return SZE_FAIL;\r\n    size -= processedSize;\r\n    do\r\n    {\r\n      *data++ = *inBuffer++;\r\n    }\r\n    while (--processedSize != 0);\r\n  }\r\n  #else\r\n  size_t processedSize;\r\n  RINOK(inStream->Read(inStream, data, size, &processedSize));\r\n  if (processedSize != size)\r\n    return SZE_FAIL;\r\n  #endif\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data)\r\n{\r\n  return SafeReadDirect(inStream, data, 1);\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nint TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nSZ_RESULT SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  *value = (CFileSize)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZE_NOTIMPL;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZE_NOTIMPL;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadID(CSzData *sd, UInt64 *value) \r\n{ \r\n  return SzReadNumber(sd, value); \r\n}\r\n\r\nSZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nSZ_RESULT SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZE_ARCHIVE_ERROR;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  RINOK(MySzInAlloc((void **)v, numItems * sizeof(Byte), allocFunc));\r\n  for(i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, allocFunc);\r\n  RINOK(MySzInAlloc((void **)v, numItems * sizeof(Byte), allocFunc));\r\n  for(i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHashDigests(\r\n    CSzData *sd, \r\n    size_t numItems,\r\n    Byte **digestsDefined, \r\n    UInt32 **digests, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc));\r\n  RINOK(MySzInAlloc((void **)digests, numItems * sizeof(UInt32), allocFunc));\r\n  for(i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadPackInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    CFileSize **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadSize(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  RINOK(MySzInAlloc((void **)packSizes, (size_t)*numPackStreams * sizeof(CFileSize), allocFunc));\r\n\r\n  for(i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadSize(sd, (*packSizes) + i));\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc)); \r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    RINOK(MySzInAlloc((void **)packCRCsDefined, (size_t)*numPackStreams * sizeof(Byte), allocFunc));\r\n    RINOK(MySzInAlloc((void **)packCRCs, (size_t)*numPackStreams * sizeof(UInt32), allocFunc));\r\n    for(i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR;\r\n}\r\n\r\nSZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 numCoders;\r\n  UInt32 numBindPairs;\r\n  UInt32 numPackedStreams;\r\n  UInt32 i;\r\n  UInt32 numInStreams = 0;\r\n  UInt32 numOutStreams = 0;\r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  folder->NumCoders = numCoders;\r\n\r\n  RINOK(MySzInAlloc((void **)&folder->Coders, (size_t)numCoders * sizeof(CCoderInfo), allocFunc));\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfoInit(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      coder->MethodID.IDSize = (Byte)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, coder->MethodID.ID, coder->MethodID.IDSize));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc))\r\n          return SZE_OUTOFMEMORY;\r\n        RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += (UInt32)coder->NumInStreams;\r\n    numOutStreams += (UInt32)coder->NumOutStreams;\r\n  }\r\n\r\n  numBindPairs = numOutStreams - 1;\r\n  folder->NumBindPairs = numBindPairs;\r\n\r\n\r\n  RINOK(MySzInAlloc((void **)&folder->BindPairs, (size_t)numBindPairs * sizeof(CBindPair), allocFunc));\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bindPair = folder->BindPairs + i;;\r\n    RINOK(SzReadNumber32(sd, &bindPair->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bindPair->OutIndex)); \r\n  }\r\n\r\n  numPackedStreams = numInStreams - (UInt32)numBindPairs;\r\n\r\n  folder->NumPackStreams = numPackedStreams;\r\n  RINOK(MySzInAlloc((void **)&folder->PackStreams, (size_t)numPackedStreams * sizeof(UInt32), allocFunc));\r\n\r\n  if (numPackedStreams == 1)\r\n  {\r\n    UInt32 j;\r\n    UInt32 pi = 0;\r\n    for (j = 0; j < numInStreams; j++)\r\n      if (SzFolderFindBindPairForInStream(folder, j) < 0)\r\n      {\r\n        folder->PackStreams[pi++] = j;\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUnPackInfo(\r\n    CSzData *sd, \r\n    UInt32 *numFolders,\r\n    CFolder **folders,  /* for allocFunc */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n\r\n    RINOK(MySzInAlloc((void **)folders, (size_t)*numFolders * sizeof(CFolder), allocFunc));\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n      SzFolderInit((*folders) + i);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));\r\n\r\n  for(i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolderGetNumOutStreams(folder);\r\n\r\n    RINOK(MySzInAlloc((void **)&folder->UnPackSizes, (size_t)numOutStreams * sizeof(CFileSize), allocFunc));\r\n\r\n    for(j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadSize(sd, folder->UnPackSizes + j));\r\n    }\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SZ_RESULT res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc); \r\n      if (res == SZ_OK)\r\n      {\r\n        for(i = 0; i < *numFolders; i++)\r\n        {\r\n          CFolder *folder = (*folders) + i;\r\n          folder->UnPackCRCDefined = crcsDefined[i];\r\n          folder->UnPackCRC = crcs[i];\r\n        }\r\n      }\r\n      allocTemp->Free(crcs);\r\n      allocTemp->Free(crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadSubStreamsInfo(\r\n    CSzData *sd, \r\n    UInt32 numFolders,\r\n    CFolder *folders,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n    folders[i].NumUnPackStreams = 1;\r\n  *numUnPackStreams = numFolders;\r\n\r\n  while(1)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnPackStream)\r\n    {\r\n      *numUnPackStreams = 0;\r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnPackStreams = numStreams;\r\n        *numUnPackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnPackStreams == 0)\r\n  {\r\n    *unPackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize));\r\n    RINOM(*unPackSizes);\r\n    *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    CFileSize sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      CFileSize size;\r\n      RINOK(SzReadSize(sd, &size));\r\n      (*unPackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for(i = 0; i < *numUnPackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  while(1)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0; \r\n      UInt32 *digests2 = 0;\r\n      SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnPackStreams;\r\n          if (numSubstreams == 1 && folder->UnPackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnPackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      allocTemp->Free(digestsDefined2);\r\n      allocTemp->Free(digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nSZ_RESULT SzReadStreamsInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    CArchiveDatabase *db,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZE_FAIL;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams, \r\n            &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc));\r\n        break;\r\n      }\r\n      case k7zIdUnPackInfo:\r\n      {\r\n        RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders, \r\n            numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZE_FAIL;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nSZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CFileItem *file = files + i;\r\n    while(pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZE_ARCHIVE_ERROR;\r\n        if (pos + 2 > sd->Size)\r\n          return SZE_ARCHIVE_ERROR;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZE_ARCHIVE_ERROR;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    RINOK(MySzInAlloc((void **)&file->Name, (size_t)len * sizeof(char), allocFunc));\r\n\r\n    len = 0;\r\n    while(2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while(numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHeader2(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db,   /* allocMain */\r\n    CFileSize **unPackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnPackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &db->ArchiveInfo.DataStartPosition,\r\n        &db->Database, \r\n        &numUnPackStreams,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests, allocMain->Alloc, allocTemp));\r\n    db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZE_ARCHIVE_ERROR;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  db->Database.NumFiles = numFiles;\r\n\r\n  RINOK(MySzInAlloc((void **)&files, (size_t)numFiles * sizeof(CFileItem), allocMain->Alloc));\r\n\r\n  db->Database.Files = files;\r\n  for(i = 0; i < numFiles; i++)\r\n    SzFileInit(files + i);\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc));\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for(i = 0; i < numFiles; i++)\r\n    {\r\n      CFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if(file->HasStream)\r\n      {\r\n        file->IsDirectory = 0;\r\n        file->Size = (*unPackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->IsFileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDirectory = 1;\r\n        else\r\n          file->IsDirectory = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->IsFileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArDbExFill(db, allocMain->Alloc);\r\n}\r\n\r\nSZ_RESULT SzReadHeader(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db, \r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  SZ_RESULT res = SzReadHeader2(sd, db, \r\n      &unPackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector,\r\n      allocMain, allocTemp);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  allocTemp->Free(emptyStreamVector);\r\n  allocTemp->Free(emptyFileVector);\r\n  return res;\r\n} \r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams2(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    CArchiveDatabase *db,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    #ifndef _LZMA_IN_CB\r\n    Byte **inBuffer,\r\n    #endif\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnPackStreams = 0;\r\n  CFileSize dataStartPos;\r\n  CFolder *folder;\r\n  #ifndef _LZMA_IN_CB\r\n  CFileSize packSize = 0;\r\n  UInt32 i = 0;\r\n  #endif\r\n  CFileSize unPackSize;\r\n  size_t outRealSize;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, db,\r\n      &numUnPackStreams,  unPackSizes, digestsDefined, digests, \r\n      allocTemp->Alloc, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (db->NumFolders != 1)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  folder = db->Folders;\r\n  unPackSize = SzFolderGetUnPackSize(folder);\r\n  \r\n  RINOK(inStream->Seek(inStream, dataStartPos));\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  for (i = 0; i < db->NumPackStreams; i++)\r\n    packSize += db->PackSizes[i];\r\n\r\n  RINOK(MySzInAlloc((void **)inBuffer, (size_t)packSize, allocTemp->Alloc));\r\n\r\n  RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize));\r\n  #endif\r\n\r\n  if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  res = SzDecode(db->PackSizes, folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream,\r\n          #else\r\n          *inBuffer, \r\n          #endif\r\n          outBuffer->Items, (size_t)unPackSize,\r\n          &outRealSize, allocTemp);\r\n  RINOK(res)\r\n  if (outRealSize != (UInt32)unPackSize)\r\n    return SZE_FAIL;\r\n  if (folder->UnPackCRCDefined)\r\n    if (!CrcVerifyDigest(folder->UnPackCRC, outBuffer->Items, (size_t)unPackSize))\r\n      return SZE_FAIL;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CArchiveDatabase db;\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  #ifndef _LZMA_IN_CB\r\n  Byte *inBuffer = 0;\r\n  #endif\r\n  SZ_RESULT res;\r\n  SzArchiveDatabaseInit(&db);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset, \r\n    &db, &unPackSizes, &digestsDefined, &digests, \r\n    #ifndef _LZMA_IN_CB\r\n    &inBuffer,\r\n    #endif\r\n    allocTemp);\r\n  SzArchiveDatabaseFree(&db, allocTemp->Free);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  #ifndef _LZMA_IN_CB\r\n  allocTemp->Free(inBuffer);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen2(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte signature[k7zSignatureSize];\r\n  Byte version;\r\n  UInt32 crcFromArchive;\r\n  UInt64 nextHeaderOffset;\r\n  UInt64 nextHeaderSize;\r\n  UInt32 nextHeaderCRC;\r\n  UInt32 crc;\r\n  CFileSize pos = 0;\r\n  CSzByteBuffer buffer;\r\n  CSzData sd;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize));\r\n\r\n  if (!TestSignatureCandidate(signature))\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  /*\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n  */\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n  if (version != k7zMajorVersion)\r\n    return SZE_ARCHIVE_ERROR;\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n\r\n  RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive));\r\n\r\n  CrcInit(&crc);\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset));\r\n  CrcUpdateUInt64(&crc, nextHeaderOffset);\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize));\r\n  CrcUpdateUInt64(&crc, nextHeaderSize);\r\n  RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC));\r\n  CrcUpdateUInt32(&crc, nextHeaderCRC);\r\n\r\n  pos = k7zStartHeaderSize;\r\n  db->ArchiveInfo.StartPositionAfterHeader = pos;\r\n  \r\n  if (CrcGetDigest(&crc) != crcFromArchive)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  if (nextHeaderSize == 0)\r\n    return SZ_OK;\r\n\r\n  RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset)));\r\n\r\n  if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize);\r\n  if (res == SZ_OK)\r\n  {\r\n    if (CrcVerifyDigest(nextHeaderCRC, buffer.Items, (UInt32)nextHeaderSize))\r\n    {\r\n      while (1)\r\n      {\r\n        UInt64 type;\r\n        sd.Data = buffer.Items;\r\n        sd.Size = buffer.Capacity;\r\n        res = SzReadID(&sd, &type);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (type == k7zIdHeader)\r\n        {\r\n          res = SzReadHeader(&sd, db, allocMain, allocTemp);\r\n          break;\r\n        }\r\n        if (type != k7zIdEncodedHeader)\r\n        {\r\n          res = SZE_ARCHIVE_ERROR;\r\n          break;\r\n        }\r\n        {\r\n          CSzByteBuffer outBuffer;\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, \r\n              db->ArchiveInfo.StartPositionAfterHeader, \r\n              allocTemp);\r\n          if (res != SZ_OK)\r\n          {\r\n            SzByteBufferFree(&outBuffer, allocTemp->Free);\r\n            break;\r\n          }\r\n          SzByteBufferFree(&buffer, allocTemp->Free);\r\n          buffer.Items = outBuffer.Items;\r\n          buffer.Capacity = outBuffer.Capacity;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  SzByteBufferFree(&buffer, allocTemp->Free);\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArDbExFree(db, allocMain->Free);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zIn.h",
    "content": "/* 7zIn.h */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n \r\ntypedef struct _CInArchiveInfo\r\n{\r\n  CFileSize StartPositionAfterHeader; \r\n  CFileSize DataStartPosition;\r\n}CInArchiveInfo;\r\n\r\ntypedef struct _CArchiveDatabaseEx\r\n{\r\n  CArchiveDatabase Database;\r\n  CInArchiveInfo ArchiveInfo;\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  CFileSize *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n}CArchiveDatabaseEx;\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db);\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);\r\nCFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex);\r\n\r\ntypedef struct _ISzInStream\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  SZ_RESULT (*Read)(\r\n      void *object,           /* pointer to ISzInStream itself */\r\n      void **buffer,          /* out: pointer to buffer with data */\r\n      size_t maxRequiredSize, /* max required size to read */\r\n      size_t *processedSize); /* real processed size. \r\n                                 processedSize can be less than maxRequiredSize.\r\n                                 If processedSize == 0, then there are no more \r\n                                 bytes in stream. */\r\n  #else\r\n  SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);\r\n  #endif\r\n  SZ_RESULT (*Seek)(void *object, CFileSize pos);\r\n} ISzInStream;\r\n\r\n \r\nint SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zItem.c",
    "content": "/* 7zItem.c */\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder)\r\n{\r\n  SzByteBufferInit(&coder->Properties);\r\n}\r\n\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))\r\n{\r\n  SzByteBufferFree(&coder->Properties, freeFunc);\r\n  SzCoderInfoInit(coder);\r\n}\r\n\r\nvoid SzFolderInit(CFolder *folder)\r\n{\r\n  folder->NumCoders = 0;\r\n  folder->Coders = 0;\r\n  folder->NumBindPairs = 0;\r\n  folder->BindPairs = 0;\r\n  folder->NumPackStreams = 0;\r\n  folder->PackStreams = 0;\r\n  folder->UnPackSizes = 0;\r\n  folder->UnPackCRCDefined = 0;\r\n  folder->UnPackCRC = 0;\r\n  folder->NumUnPackStreams = 0;\r\n}\r\n\r\nvoid SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    SzCoderInfoFree(&folder->Coders[i], freeFunc);\r\n  freeFunc(folder->Coders);\r\n  freeFunc(folder->BindPairs);\r\n  freeFunc(folder->PackStreams);\r\n  freeFunc(folder->UnPackSizes);\r\n  SzFolderInit(folder);\r\n}\r\n\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    result += folder->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder)\r\n{ \r\n  int i = (int)SzFolderGetNumOutStreams(folder);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolderFindBindPairForOutStream(folder, i) < 0)\r\n      return folder->UnPackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\n/*\r\nint FindPackStreamArrayIndex(int inStreamIndex) const\r\n{\r\n  for(int i = 0; i < PackStreams.Size(); i++)\r\n  if (PackStreams[i] == inStreamIndex)\r\n    return i;\r\n  return -1;\r\n}\r\n*/\r\n\r\nvoid SzFileInit(CFileItem *fileItem)\r\n{\r\n  fileItem->IsFileCRCDefined = 0;\r\n  fileItem->HasStream = 1;\r\n  fileItem->IsDirectory = 0;\r\n  fileItem->IsAnti = 0;\r\n  fileItem->Name = 0;\r\n}\r\n\r\nvoid SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))\r\n{\r\n  freeFunc(fileItem->Name);\r\n  SzFileInit(fileItem);\r\n}\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db)\r\n{\r\n  db->NumPackStreams = 0;\r\n  db->PackSizes = 0;\r\n  db->PackCRCsDefined = 0;\r\n  db->PackCRCs = 0;\r\n  db->NumFolders = 0;\r\n  db->Folders = 0;\r\n  db->NumFiles = 0;\r\n  db->Files = 0;\r\n}\r\n\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < db->NumFolders; i++)\r\n    SzFolderFree(&db->Folders[i], freeFunc);\r\n  for (i = 0; i < db->NumFiles; i++)\r\n    SzFileFree(&db->Files[i], freeFunc);\r\n  freeFunc(db->PackSizes);\r\n  freeFunc(db->PackCRCsDefined);\r\n  freeFunc(db->PackCRCs);\r\n  freeFunc(db->Folders);\r\n  freeFunc(db->Files);\r\n  SzArchiveDatabaseInit(db);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zItem.h",
    "content": "/* 7zItem.h */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"7zMethodID.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zBuffer.h\"\r\n\r\ntypedef struct _CCoderInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  CMethodID MethodID;\r\n  CSzByteBuffer Properties;\r\n}CCoderInfo;\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder);\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));\r\n\r\ntypedef struct _CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n}CBindPair;\r\n\r\ntypedef struct _CFolder\r\n{\r\n  UInt32 NumCoders;\r\n  CCoderInfo *Coders;\r\n  UInt32 NumBindPairs;\r\n  CBindPair *BindPairs;\r\n  UInt32 NumPackStreams; \r\n  UInt32 *PackStreams;\r\n  CFileSize *UnPackSizes;\r\n  int UnPackCRCDefined;\r\n  UInt32 UnPackCRC;\r\n\r\n  UInt32 NumUnPackStreams;\r\n}CFolder;\r\n\r\nvoid SzFolderInit(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\n\r\n/* #define CArchiveFileTime UInt64 */\r\n\r\ntypedef struct _CFileItem\r\n{\r\n  /*\r\n  CArchiveFileTime LastWriteTime;\r\n  CFileSize StartPos;\r\n  UInt32 Attributes; \r\n  */\r\n  CFileSize Size;\r\n  UInt32 FileCRC;\r\n  char *Name;\r\n\r\n  Byte IsFileCRCDefined;\r\n  Byte HasStream;\r\n  Byte IsDirectory;\r\n  Byte IsAnti;\r\n  /*\r\n  int AreAttributesDefined;\r\n  int IsLastWriteTimeDefined;\r\n  int IsStartPosDefined;\r\n  */\r\n}CFileItem;\r\n\r\nvoid SzFileInit(CFileItem *fileItem);\r\n\r\ntypedef struct _CArchiveDatabase\r\n{\r\n  UInt32 NumPackStreams;\r\n  CFileSize *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  UInt32 NumFolders;\r\n  CFolder *Folders;\r\n  UInt32 NumFiles;\r\n  CFileItem *Files;\r\n}CArchiveDatabase;\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db);\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));\r\n\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zMain.c",
    "content": "/* \r\n7zMain.c\r\nTest application for 7z Decoder\r\nLZMA SDK 4.26 Copyright (c) 1999-2005 Igor Pavlov (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"7zCrc.h\"\r\n#include \"7zIn.h\"\r\n#include \"7zExtract.h\"\r\n\r\ntypedef struct _CFileInStream\r\n{\r\n  ISzInStream InStream;\r\n  FILE *File;\r\n} CFileInStream;\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define kBufferSize (1 << 12)\r\nByte g_Buffer[kBufferSize];\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc;\r\n  if (maxRequiredSize > kBufferSize)\r\n    maxRequiredSize = kBufferSize;\r\n  processedSizeLoc = fread(g_Buffer, 1, maxRequiredSize, s->File);\r\n  *buffer = g_Buffer;\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#else\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc = fread(buffer, 1, size, s->File);\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzFileSeekImp(void *object, CFileSize pos)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  int res = fseek(s->File, (long)pos, SEEK_SET);\r\n  if (res == 0)\r\n    return SZ_OK;\r\n  return SZE_FAIL;\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CArchiveDatabaseEx db;\r\n  SZ_RESULT res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder 4.30  Copyright (c) 1999-2005 Igor Pavlov  2005-11-20\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.File = fopen(args[2], \"rb\");\r\n  if (archiveStream.File == 0)\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.InStream.Read = SzFileReadImp;\r\n  archiveStream.InStream.Seek = SzFileSeekImp;\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  InitCrcTable();\r\n  SzArDbExInit(&db);\r\n  res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0;\r\n    int testCommand = 0;\r\n    int extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0)\r\n      listCommand = 1;\r\n    if (strcmp(command, \"t\") == 0)\r\n      testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0)\r\n      extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      // if you need cache, use these 3 variables.\r\n      // if you use external function, you can make these variable as static.\r\n      UInt32 blockIndex = 0xFFFFFFFF; // it can have any value before first call (if outBuffer = 0) \r\n      Byte *outBuffer = 0; // it must be 0 before first call for each new archive. \r\n      size_t outBufferSize = 0;  // it can have any value before first call (if outBuffer = 0) \r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CFileItem *f = db.Database.Files + i;\r\n        if (f->IsDirectory)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ? \r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDirectory)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzExtract(&archiveStream.InStream, &db, i, \r\n            &blockIndex, &outBuffer, &outBufferSize, \r\n            &offset, &outSizeProcessed, \r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          FILE *outputHandle;\r\n          UInt32 processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          outputHandle = fopen(fileName, \"wb+\");\r\n          if (outputHandle == 0)\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          processedSize = fwrite(outBuffer + offset, 1, outSizeProcessed, outputHandle);\r\n          if (processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          if (fclose(outputHandle))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      allocImp.Free(outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZE_FAIL;\r\n    }\r\n  }\r\n  SzArDbExFree(&db, allocImp.Free);\r\n\r\n  fclose(archiveStream.File);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == SZE_OUTOFMEMORY)\r\n    PrintError(\"can not allocate memory\");\r\n  else     \r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zMethodID.c",
    "content": "/* 7zMethodID.c */\r\n\r\n#include \"7zMethodID.h\"\r\n\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2)\r\n{\r\n  int i;\r\n  if (a1->IDSize != a2->IDSize)\r\n    return 0;\r\n  for (i = 0; i < a1->IDSize; i++)\r\n    if (a1->ID[i] != a2->ID[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zMethodID.h",
    "content": "/* 7zMethodID.h */\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"7zTypes.h\"\r\n\r\n#define kMethodIDSize 15\r\n  \r\ntypedef struct _CMethodID\r\n{\r\n  Byte ID[kMethodIDSize];\r\n  Byte IDSize;\r\n} CMethodID;\r\n\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7zTypes.h",
    "content": "/* 7zTypes.h */\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\n#ifndef UInt32\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\n#define UInt32 unsigned long\r\n#else\r\n#define UInt32 unsigned int\r\n#endif\r\n#endif\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#ifndef UInt16\r\n#define UInt16 unsigned short\r\n#endif\r\n\r\n/* #define _SZ_NO_INT_64 */\r\n/* define it your compiler doesn't support long long int */\r\n\r\n#ifdef _SZ_NO_INT_64\r\n#define UInt64 unsigned long\r\n#else\r\n#ifdef _MSC_VER\r\n#define UInt64 unsigned __int64\r\n#else\r\n#define UInt64 unsigned long long int\r\n#endif\r\n#endif\r\n\r\n\r\n/* #define _SZ_FILE_SIZE_64 */\r\n/* Use _SZ_FILE_SIZE_64 if you need support for files larger than 4 GB*/\r\n\r\n#ifndef CFileSize\r\n#ifdef _SZ_FILE_SIZE_64\r\n#define CFileSize UInt64\r\n#else\r\n#define CFileSize UInt32\r\n#endif\r\n#endif\r\n\r\n#define SZ_RESULT int\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_CRC_ERROR (3)\r\n\r\n#define SZE_NOTIMPL (4)\r\n#define SZE_FAIL (5)\r\n\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7z_C.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z_C\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z_C - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\" CFG=\"7z_C - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z_C - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z_C - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z_C - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /W4 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z_C - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z_C - Win32 Release\"\r\n# Name \"7z_C - Win32 Debug\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_C\\LzmaDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_C\\LzmaDecode.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zTypes.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/7z_C.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z_C\"=.\\7z_C.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/makefile",
    "content": "PROG = 7zDec.exe\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zBuffer.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n  $O\\7zMethodID.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $O\\LzmaDecode.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/LZMA_C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Archive/7z_C/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o \r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuffer.o: 7zBuffer.c\r\n\t$(CXX) $(CFLAGS) 7zBuffer.c\r\n\r\n7zCrc.o: 7zCrc.c\r\n\t$(CXX) $(CFLAGS) 7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\n7zMethodID.o: 7zMethodID.c\r\n\t$(CXX) $(CFLAGS) 7zMethodID.c\r\n\r\nLzmaDecode.o: ../../Compress/LZMA_C/LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/LZMA_C/LzmaDecode.c\r\n\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  // return result ? S_OK: E_FAIL;\r\n  #ifdef _WIN32\r\n  return result ? S_OK: (::GetLastError());\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), \r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef _WIN32\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nbool COutFileStream::Create(LPCTSTR fileName, bool createAlways)\r\n{\r\n  return File.Create(fileName, createAlways);\r\n}\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool COutFileStream::Create(LPCWSTR fileName, bool createAlways)\r\n{\r\n  return File.Create(fileName, createAlways);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef _WIN32\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15); \r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), \r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef _WIN32\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef _WIN32\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n  #endif\r\n  \r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\n#include \"../../Common/Alloc.h\"\r\n\r\nCInBuffer::CInBuffer(): \r\n  _buffer(0), \r\n  _bufferLimit(0), \r\n  _bufferBase(0), \r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nclass CInBufferException\r\n{\r\npublic:\r\n  HRESULT ErrorCode;\r\n  CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      if(!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)\r\n  {\r\n    for(processedSize = 0; processedSize < size; processedSize++)\r\n      if (!ReadByte(((Byte *)data)[processedSize]))\r\n        return;\r\n  }\r\n  bool ReadBytes(void *data, UInt32 size)\r\n  {\r\n    UInt32 processedSize;\r\n    ReadBytes(data, size, processedSize);\r\n    return (processedSize == size);\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\n#include \"../../Common/Alloc.h\"\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{ \r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos) \r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode != S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = FlushPart();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException\r\n{\r\n  HRESULT ErrorCode;\r\n  COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\n  void FlushWithCheck();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/lzma/C/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Read(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (Byte *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Write(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      break;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/ARM.cpp",
    "content": "// ARM.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARM.h\"\r\n\r\n#include \"BranchARM.c\"\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/ARM.h",
    "content": "// ARM.h\r\n\r\n#ifndef __ARM_H\r\n#define __ARM_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM, 0x05, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/ARMThumb.cpp",
    "content": "// ARMThumb.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARMThumb.h\"\r\n\r\n#include \"BranchARMThumb.c\"\r\n\r\nUInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/ARMThumb.h",
    "content": "// ARMThumb.h\r\n\r\n#ifndef __ARMTHUMB_H\r\n#define __ARMTHUMB_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARMThumb, 0x07, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchARM.c",
    "content": "// BranchARM.c\r\n\r\n#include \"BranchARM.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 src = (data[i + 2] << 16) | (data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + 8 + src;\r\n      else\r\n        dest = src - (nowPos + i + 8);\r\n      dest >>= 2;\r\n      data[i + 2] = (dest >> 16);\r\n      data[i + 1] = (dest >> 8);\r\n      data[i + 0] = dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchARM.h",
    "content": "// BranchARM.h\r\n\r\n#ifndef __BRANCH_ARM_H\r\n#define __BRANCH_ARM_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchARMThumb.c",
    "content": "// BranchARMThumb.c\r\n\r\n#include \"BranchARMThumb.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 && \r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 src = \r\n        ((data[i + 1] & 0x7) << 19) |\r\n        (data[i + 0] << 11) |\r\n        ((data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + 4 + src;\r\n      else\r\n        dest = src - (nowPos + i + 4);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = 0xF0 | ((dest >> 19) & 0x7);\r\n      data[i + 0] = (dest >> 11);\r\n      data[i + 3] = 0xF8 | ((dest >> 8) & 0x7);\r\n      data[i + 2] = (dest);\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchARMThumb.h",
    "content": "// BranchARMThumb.h\r\n\r\n#ifndef __BRANCH_ARM_THUMB_H\r\n#define __BRANCH_ARM_THUMB_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __BRANCH_CODER_H\r\n#define __BRANCH_CODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/Types.h\"\r\n#include \"Common/Alloc.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClass2b(Name, id, subId, encodingId)  \\\r\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\r\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00); \r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchIA64.c",
    "content": "// BranchIA64.c\r\n\r\n#include \"BranchIA64.h\"\r\n\r\nconst Byte kBranchTable[32] = \r\n{ \r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0 \r\n};\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 16 <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    for (int slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      UInt32 bytePos = (bitPos >> 3);\r\n      UInt32 bitRes = bitPos & 0x7;\r\n      // UInt64 instruction = *(UInt64 *)(data + i + bytePos);\r\n      UInt64 instruction = 0;\r\n      int j;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);\r\n\r\n      UInt64 instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 \r\n        &&  ((instNorm >> 9) & 0x7) == 0 \r\n        // &&  (instNorm & 0x3F)== 0 \r\n        )\r\n      {\r\n        UInt32 src = UInt32((instNorm >> 13) & 0xFFFFF);\r\n        src |= ((instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        UInt32 dest;\r\n        if (encoding)\r\n          dest = nowPos + i + src;\r\n        else\r\n          dest = src - (nowPos + i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~(UInt64(0x8FFFFF) << 13);\r\n        instNorm |= (UInt64(dest & 0xFFFFF) << 13);\r\n        instNorm |= (UInt64(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        // *(UInt64 *)(data + i + bytePos) = instruction;\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = Byte(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchIA64.h",
    "content": "// BranchIA64.h\r\n\r\n#ifndef __BRANCH_IA64_H\r\n#define __BRANCH_IA64_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchPPC.c",
    "content": "// BranchPPC.c\r\n\r\n#include \"BranchPPC.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    // PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link)\r\n    if ((data[i] >> 2) == 0x12 && \r\n    (\r\n      (data[i + 3] & 3) == 1 \r\n      // || (data[i+3] & 3) == 3\r\n      )\r\n    )\r\n    {\r\n      UInt32 src = ((data[i + 0] & 3) << 24) |\r\n        (data[i + 1] << 16) |\r\n        (data[i + 2] << 8) |\r\n        (data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      data[i + 0] = 0x48 | ((dest >> 24) &  0x3);\r\n      data[i + 1] = (dest >> 16);\r\n      data[i + 2] = (dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchPPC.h",
    "content": "// BranchPPC.h\r\n\r\n#ifndef __BRANCH_PPC_H\r\n#define __BRANCH_PPC_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchSPARC.c",
    "content": "// BranchSPARC.c\r\n\r\n#include \"BranchSPARC.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || \r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      \r\n      src <<= 2;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchSPARC.h",
    "content": "// BranchSPARC.h\r\n\r\n#ifndef __BRANCH_SPARC_H\r\n#define __BRANCH_SPARC_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 SPARC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchX86.c",
    "content": "/* BranchX86.c */\r\n\r\n#include \"BranchX86.h\"\r\n\r\n/*\r\nstatic int inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n*/\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst int kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\n/*\r\nvoid x86_Convert_Init(UInt32 *prevMask, UInt32 *prevPos)\r\n{\r\n  *prevMask = 0;\r\n  *prevPos = (UInt32)(-5);\r\n}\r\n*/\r\n\r\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \r\n    UInt32 *prevMask, UInt32 *prevPos, int encoding)\r\n{\r\n  UInt32 bufferPos = 0;\r\n  UInt32 limit;\r\n\r\n  if (endPos < 5)\r\n    return 0;\r\n  \r\n  if (nowPos - *prevPos > 5)\r\n    *prevPos = nowPos - 5;\r\n  \r\n  limit = endPos - 5;\r\n  while(bufferPos <= limit)\r\n  {\r\n    Byte b = buffer[bufferPos];\r\n    UInt32 offset;\r\n    if (b != 0xE8 && b != 0xE9)\r\n    {\r\n      bufferPos++;\r\n      continue;\r\n    }\r\n    offset = (nowPos + bufferPos - *prevPos);\r\n    *prevPos = (nowPos + bufferPos);\r\n    if (offset > 5)\r\n      *prevMask = 0;\r\n    else\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < offset; i++)\r\n      {\r\n        *prevMask &= 0x77;\r\n        *prevMask <<= 1;\r\n      }\r\n    }\r\n    b = buffer[bufferPos + 4];\r\n    if (Test86MSByte(b) && kMaskToAllowedStatus[(*prevMask >> 1) & 0x7] && \r\n      (*prevMask >> 1) < 0x10)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)(b) << 24) |\r\n        ((UInt32)(buffer[bufferPos + 3]) << 16) |\r\n        ((UInt32)(buffer[bufferPos + 2]) << 8) |\r\n        (buffer[bufferPos + 1]);\r\n      \r\n      UInt32 dest;\r\n      while(1)\r\n      {\r\n        UInt32 index;\r\n        if (encoding)\r\n          dest = (nowPos + bufferPos + 5) + src;\r\n        else\r\n          dest = src - (nowPos + bufferPos + 5);\r\n        if (*prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[*prevMask >> 1];\r\n        b = (Byte)(dest >> (24 - index * 8));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index * 8)) - 1);\r\n      }\r\n      buffer[bufferPos + 4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      buffer[bufferPos + 3] = (Byte)(dest >> 16);\r\n      buffer[bufferPos + 2] = (Byte)(dest >> 8);\r\n      buffer[bufferPos + 1] = (Byte)dest;\r\n      bufferPos += 5;\r\n      *prevMask = 0;\r\n    }\r\n    else\r\n    {\r\n      bufferPos++;\r\n      *prevMask |= 1;\r\n      if (Test86MSByte(b))\r\n        *prevMask |= 0x10;\r\n    }\r\n  }\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/BranchX86.h",
    "content": "/* BranchX86.h */\r\n\r\n#ifndef __BRANCHX86_H\r\n#define __BRANCHX86_H\r\n\r\n#ifndef UInt32\r\n#define UInt32 unsigned int\r\n#endif\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#define x86_Convert_Init(prevMask, prevPos) { prevMask = 0; prevPos = (UInt32)(-5); }\r\n\r\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \r\n    UInt32 *prevMask, UInt32 *prevPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/IA64.cpp",
    "content": "// IA64.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"IA64.h\"\r\n\r\n#include \"BranchIA64.c\"\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/IA64.h",
    "content": "// IA64.h\r\n\r\n#ifndef __IA64_H\r\n#define __IA64_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_IA64, 0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/PPC.cpp",
    "content": "// PPC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"PPC.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"BranchPPC.c\"\r\n\r\nUInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/PPC.h",
    "content": "// PPC.h\r\n\r\n#ifndef __PPC_H\r\n#define __PPC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_PPC_B, 0x02, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/SPARC.cpp",
    "content": "// SPARC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"SPARC.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"BranchSPARC.c\"\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/SPARC.h",
    "content": "// SPARC.h\r\n\r\n#ifndef __SPARC_H\r\n#define __SPARC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_SPARC, 0x08, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/x86.cpp",
    "content": "// x86.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"BranchX86.c\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/x86.h",
    "content": "// x86.h\r\n\r\n#ifndef __X86_H\r\n#define __X86_H\r\n\r\n#include \"BranchCoder.h\"\r\n#include \"BranchX86.h\"\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  UInt32 _prevPos;\r\n  void x86Init() { x86_Convert_Init(_prevMask, _prevPos); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 , \r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/x86_2.cpp",
    "content": "// x86_2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86_2.h\"\r\n\r\n#include \"../../../Common/Alloc.h\"\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\ninline bool IsJcc(Byte b0, Byte b1)\r\n{\r\n  return (b0 == 0x0F && (b1 & 0xF0) == 0x80);\r\n}\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CBCJ2_x86_Encoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCBCJ2_x86_Encoder::~CBCJ2_x86_Encoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CBCJ2_x86_Encoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256; i++)\r\n    _statusE8Encoder[i].Init();\r\n  _statusE9Encoder.Init();\r\n  _statusJccEncoder.Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  while(true)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    while(true)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it \r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\r\n        else if (IsJcc(prevByte, b))\r\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src = \r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;          \r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;          \r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      if (convert)\r\n      {\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 1);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 1);\r\n        else \r\n          _statusJccEncoder.Encode(&_rangeEncoder, 1);\r\n\r\n        bufferPos += 5;\r\n        if (b == 0xE8)\r\n        {\r\n          _callStream.WriteByte((Byte)(dest >> 24));\r\n          _callStream.WriteByte((Byte)(dest >> 16));\r\n          _callStream.WriteByte((Byte)(dest >> 8));\r\n          _callStream.WriteByte((Byte)(dest));\r\n        }\r\n        else \r\n        {\r\n          _jumpStream.WriteByte((Byte)(dest >> 24));\r\n          _jumpStream.WriteByte((Byte)(dest >> 16));\r\n          _jumpStream.WriteByte((Byte)(dest >> 8));\r\n          _jumpStream.WriteByte((Byte)(dest));\r\n        }\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\r\n        else\r\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256; i++)\r\n    _statusE8Decoder[i].Init();\r\n  _statusE9Decoder.Init();\r\n  _statusJccDecoder.Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  while(true)\r\n  {\r\n    if (processedBytes > (1 << 20) && progress != NULL)\r\n    {\r\n      UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    processedBytes++;\r\n    Byte b;\r\n    if (!_mainInStream.ReadByte(b))\r\n      return Flush();\r\n    _outStream.WriteByte(b);\r\n    if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\r\n    {\r\n      prevByte = b;\r\n      continue;\r\n    }\r\n    bool status;\r\n    if (b == 0xE8)\r\n      status = (_statusE8Decoder[prevByte].Decode(&_rangeDecoder) == 1);\r\n    else if (b == 0xE9)\r\n      status = (_statusE9Decoder.Decode(&_rangeDecoder) == 1);\r\n    else\r\n      status = (_statusJccDecoder.Decode(&_rangeDecoder) == 1);\r\n    if (status)\r\n    {\r\n      UInt32 src;\r\n      if (b == 0xE8)\r\n      {\r\n        Byte b0;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src = ((UInt32)b0) << 24;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 16;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 8;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      else\r\n      {\r\n        Byte b0;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src = ((UInt32)b0) << 24;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 16;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 8;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CBCJ2_x86_Decoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/Branch/x86_2.h",
    "content": "// x86_2.h\r\n\r\n#ifndef __BRANCH_X86_2_H\r\n#define __BRANCH_X86_2_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../RangeCoder/RangeCoderBit.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n// {23170F69-40C1-278B-0303-010100000100}\r\n#define MyClass2_a(Name, id, subId, encodingId)  \\\r\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\r\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00);\r\n\r\n#define MyClass_a(Name, id, subId)  \\\r\nMyClass2_a(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClass2_a(Name ## _Decoder, id, subId, 0x00) \r\n\r\nMyClass_a(BCJ2_x86, 0x01, 0x1B)\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CBCJ2_x86_Encoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CBCJ2_x86_Encoder(): _buffer(0) {};\r\n  ~CBCJ2_x86_Encoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE8Encoder[256];\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE9Encoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusJccEncoder;\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CBCJ2_x86_Encoder *_coder;\r\n  public:\r\n    CCoderReleaser(CBCJ2_x86_Encoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n\r\nclass CBCJ2_x86_Decoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{ \r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE8Decoder[256];\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE9Decoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusJccDecoder;\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CBCJ2_x86_Decoder *_coder;\r\n  public:\r\n    CCoderReleaser(CBCJ2_x86_Decoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/BinTree/BinTree.h",
    "content": "// BinTree.h\r\n\r\n#include \"../LZInWindow.h\"\r\n#include \"../IMatchFinder.h\"\r\n \r\nnamespace BT_NAMESPACE {\r\n\r\ntypedef UInt32 CIndex;\r\nconst UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\r\n\r\nclass CMatchFinderBinTree: \r\n  public IMatchFinder,\r\n  public IMatchFinderSetCallback,\r\n  public CLZInWindow,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 _cyclicBufferPos;\r\n  UInt32 _cyclicBufferSize; // it must be historySize + 1\r\n  UInt32 _matchMaxLen;\r\n  CIndex *_hash;\r\n  UInt32 _cutValue;\r\n\r\n  CMyComPtr<IMatchFinderCallback> m_Callback;\r\n\r\n  void Normalize();\r\n  void FreeThisClassMemory();\r\n  void FreeMemory();\r\n\r\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\r\n\r\n  STDMETHOD(Init)(ISequentialInStream *inStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(MovePos)();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\r\n  STDMETHOD_(void, DummyLongestMatch)();\r\n\r\n  // IMatchFinderSetCallback\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\r\n\r\n  virtual void BeforeMoveBlock();\r\n  virtual void AfterMoveBlock();\r\n\r\npublic:\r\n  CMatchFinderBinTree();\r\n  virtual ~CMatchFinderBinTree();\r\n  void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/BinTree/BinTree2.h",
    "content": "// BinTree2.h\r\n\r\n#ifndef __BINTREE2_H\r\n#define __BINTREE2_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT2\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/BinTree/BinTree3.h",
    "content": "// BinTree3.h\r\n\r\n#ifndef __BINTREE3_H\r\n#define __BINTREE3_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT3\r\n\r\n#define HASH_ARRAY_2\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/BinTree/BinTree3Z.h",
    "content": "// BinTree3Z.h\r\n\r\n#ifndef __BINTREE3Z_H\r\n#define __BINTREE3Z_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT3Z\r\n\r\n#define HASH_ZIP\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ZIP\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/BinTree/BinTree4.h",
    "content": "// BinTree4.h\r\n\r\n#ifndef __BINTREE4_H\r\n#define __BINTREE4_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT4\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/BinTree/BinTree4b.h",
    "content": "// BinTree4b.h\r\n\r\n#ifndef __BINTREE4B_H\r\n#define __BINTREE4B_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT4B\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n#define HASH_BIG\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n#undef HASH_BIG\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/BinTree/BinTreeMain.h",
    "content": "// BinTreeMain.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/CRC.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\nnamespace BT_NAMESPACE {\r\n\r\n#ifdef HASH_ARRAY_2\r\n  static const UInt32 kHash2Size = 1 << 10;\r\n  #ifdef HASH_ARRAY_3\r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 4;\r\n    static const UInt32 kHash3Size = 1 << 18;\r\n    #ifdef HASH_BIG\r\n    static const UInt32 kHashSize = 1 << 23;\r\n    #else\r\n    static const UInt32 kHashSize = 1 << 20;\r\n    #endif\r\n  #else\r\n    static const UInt32 kNumHashDirectBytes = 3;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n  #endif\r\n#else\r\n  #ifdef HASH_ZIP \r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << 16;\r\n  #else\r\n    #define THERE_ARE_DIRECT_HASH_BYTES\r\n    static const UInt32 kNumHashDirectBytes = 2;\r\n    static const UInt32 kNumHashBytes = 2;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n  #endif\r\n#endif\r\n\r\nstatic const UInt32 kHashSizeSum = kHashSize\r\n    #ifdef HASH_ARRAY_2\r\n    + kHash2Size\r\n    #ifdef HASH_ARRAY_3\r\n    + kHash3Size\r\n    #endif\r\n    #endif\r\n    ;\r\n\r\n#ifdef HASH_ARRAY_2\r\nstatic const UInt32 kHash2Offset = kHashSize;\r\n#ifdef HASH_ARRAY_3\r\nstatic const UInt32 kHash3Offset = kHashSize + kHash2Size;\r\n#endif\r\n#endif\r\n\r\nCMatchFinderBinTree::CMatchFinderBinTree():\r\n  _hash(0),\r\n  _cutValue(0xFF)\r\n{\r\n}\r\n\r\nvoid CMatchFinderBinTree::FreeThisClassMemory()\r\n{\r\n  BigFree(_hash);\r\n  _hash = 0;\r\n}\r\n\r\nvoid CMatchFinderBinTree::FreeMemory()\r\n{\r\n  FreeThisClassMemory();\r\n  CLZInWindow::Free();\r\n}\r\n\r\nCMatchFinderBinTree::~CMatchFinderBinTree()\r\n{ \r\n  FreeMemory();\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderBinTree::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  UInt32 sizeReserv = (historySize + keepAddBufferBefore + \r\n      matchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n  if (CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, sizeReserv))\r\n  {\r\n    if (historySize + 256 > kMaxValForNormalize)\r\n    {\r\n      FreeMemory();\r\n      return E_INVALIDARG;\r\n    }\r\n    _matchMaxLen = matchMaxLen;\r\n    UInt32 newCyclicBufferSize = historySize + 1;\r\n    if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)\r\n      return S_OK;\r\n    FreeThisClassMemory();\r\n    _cyclicBufferSize = newCyclicBufferSize; // don't change it\r\n    _hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize * 2) * sizeof(CIndex));\r\n    if (_hash != 0)\r\n      return S_OK;\r\n  }\r\n  FreeMemory();\r\n  return E_OUTOFMEMORY;\r\n}\r\n\r\nstatic const UInt32 kEmptyHashValue = 0;\r\n\r\nSTDMETHODIMP CMatchFinderBinTree::Init(ISequentialInStream *stream)\r\n{\r\n  RINOK(CLZInWindow::Init(stream));\r\n  for(UInt32 i = 0; i < kHashSizeSum; i++)\r\n    _hash[i] = kEmptyHashValue;\r\n  _cyclicBufferPos = 0;\r\n  ReduceOffsets(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderBinTree::ReleaseStream()\r\n{ \r\n  // ReleaseStream(); \r\n}\r\n\r\n#ifdef HASH_ARRAY_2\r\n#ifdef HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)\r\n{\r\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\r\n  hash2Value = temp & (kHash2Size - 1);\r\n  hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);\r\n  return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) & \r\n      (kHashSize - 1);\r\n}\r\n#else // no HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)\r\n{\r\n  hash2Value = (CCRC::Table[pointer[0]] ^ pointer[1]) & (kHash2Size - 1);\r\n  return ((UInt32(pointer[0]) << 16)) | ((UInt32(pointer[1]) << 8)) | pointer[2];\r\n}\r\n#endif // HASH_ARRAY_3\r\n#else // no HASH_ARRAY_2\r\n#ifdef HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return ((UInt32(pointer[0]) << 8) ^ \r\n      CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\r\n}\r\n#else // no HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return pointer[0] ^ (UInt32(pointer[1]) << 8);\r\n}\r\n#endif // HASH_ZIP\r\n#endif // HASH_ARRAY_2\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetLongestMatch(UInt32 *distances)\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kNumHashBytes)\r\n      return 0; \r\n  }\r\n\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  Byte *cur = _buffer + _pos;\r\n\r\n  UInt32 maxLen = 0;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[hashValue];\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n  #endif\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  distances[2] = 0xFFFFFFFF;\r\n  if(curMatch2 > matchMinPos)\r\n    if (_buffer[curMatch2] == cur[0])\r\n    {\r\n      distances[2] = _pos - curMatch2 - 1;\r\n      maxLen = 2;\r\n    }\r\n\r\n  #ifdef HASH_ARRAY_3\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  distances[3] = 0xFFFFFFFF;\r\n  if(curMatch3 > matchMinPos)\r\n    if (_buffer[curMatch3] == cur[0])\r\n    {\r\n      distances[3] = _pos - curMatch3 - 1;\r\n      maxLen = 3;\r\n    }\r\n  #endif\r\n  #endif\r\n\r\n  _hash[hashValue] = _pos;\r\n\r\n  CIndex *son = _hash + kHashSizeSum;\r\n  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r\n\r\n  distances[kNumHashBytes] = 0xFFFFFFFF;\r\n\r\n  #ifdef THERE_ARE_DIRECT_HASH_BYTES\r\n  if (lenLimit == kNumHashDirectBytes)\r\n  {\r\n    if(curMatch > matchMinPos)\r\n      while (maxLen < kNumHashDirectBytes)\r\n        distances[++maxLen] = _pos - curMatch - 1;\r\n    // We don't need tree in this case\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 len0, len1;\r\n    len0 = len1 = kNumHashDirectBytes;\r\n    UInt32 count = _cutValue;\r\n    while(true)\r\n    {\r\n      if(curMatch <= matchMinPos || count-- == 0)\r\n      {\r\n        *ptr0 = kEmptyHashValue;\r\n        *ptr1 = kEmptyHashValue;\r\n        break;\r\n      }\r\n      Byte *pb = _buffer + curMatch;\r\n      UInt32 len = MyMin(len0, len1);\r\n      do\r\n      {\r\n        if (pb[len] != cur[len])\r\n          break;\r\n      }\r\n      while(++len != lenLimit);\r\n      \r\n      UInt32 delta = _pos - curMatch;\r\n      while (maxLen < len)\r\n        distances[++maxLen] = delta - 1;\r\n      \r\n      UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n          (_cyclicBufferPos - delta):\r\n          (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n      CIndex *pair = son + (cyclicPos << 1);\r\n      \r\n      if (len != lenLimit)\r\n      {\r\n        if (pb[len] < cur[len])\r\n        {\r\n          *ptr1 = curMatch;\r\n          ptr1 = pair + 1;\r\n          curMatch = *ptr1;\r\n          len1 = len;\r\n        }\r\n        else\r\n        {\r\n          *ptr0 = curMatch;\r\n          ptr0 = pair;\r\n          curMatch = *ptr0;\r\n          len0 = len;\r\n        }\r\n      }\r\n      else\r\n      {\r\n        *ptr1 = pair[0];\r\n        *ptr0 = pair[1];\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  #ifdef HASH_ARRAY_2\r\n  #ifdef HASH_ARRAY_3\r\n  if (distances[4] < distances[3])\r\n    distances[3] = distances[4];\r\n  #endif\r\n  if (distances[3] < distances[2])\r\n    distances[2] = distances[3];\r\n  #endif\r\n  return maxLen;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderBinTree::DummyLongestMatch()\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kNumHashBytes)\r\n      return; \r\n  }\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  Byte *cur = _buffer + _pos;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[hashValue];\r\n  _hash[hashValue] = _pos;\r\n\r\n  CIndex *son = _hash + kHashSizeSum;\r\n  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r\n\r\n  #ifdef THERE_ARE_DIRECT_HASH_BYTES\r\n  if (lenLimit != kNumHashDirectBytes)\r\n  #endif\r\n  {\r\n    UInt32 len0, len1;\r\n    len0 = len1 = kNumHashDirectBytes;\r\n    UInt32 count = _cutValue;\r\n    while(true)\r\n    {\r\n      if(curMatch <= matchMinPos || count-- == 0)\r\n        break;\r\n      Byte *pb = _buffer + curMatch;\r\n      UInt32 len = MyMin(len0, len1);\r\n      do\r\n      {\r\n        if (pb[len] != cur[len])\r\n          break;\r\n      }\r\n      while(++len != lenLimit);\r\n      \r\n      UInt32 delta = _pos - curMatch;\r\n      UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n        (_cyclicBufferPos - delta):\r\n      (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n      CIndex *pair = son + (cyclicPos << 1);\r\n      \r\n      if (len != lenLimit)\r\n      {\r\n        if (pb[len] < cur[len])\r\n        {\r\n          *ptr1 = curMatch;\r\n          ptr1 = pair + 1;\r\n          curMatch = *ptr1;\r\n          len1 = len;\r\n        }\r\n        else \r\n        {\r\n          *ptr0 = curMatch;\r\n          ptr0 = pair;\r\n          curMatch = *ptr0;\r\n          len0 = len;\r\n        }\r\n      }\r\n      else\r\n      {\r\n        *ptr1 = pair[0];\r\n        *ptr0 = pair[1];\r\n        return;\r\n      }\r\n    }\r\n  }\r\n  *ptr0 = kEmptyHashValue;\r\n  *ptr1 = kEmptyHashValue;\r\n}\r\n\r\nvoid CMatchFinderBinTree::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _cyclicBufferSize;\r\n  CIndex *items = _hash;\r\n  UInt32 numItems = (kHashSizeSum + _cyclicBufferSize * 2);\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n  ReduceOffsets(subValue);\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderBinTree::MovePos()\r\n{\r\n  if (++_cyclicBufferPos == _cyclicBufferSize)\r\n    _cyclicBufferPos = 0;\r\n  RINOK(CLZInWindow::MovePos());\r\n  if (_pos == kMaxValForNormalize)\r\n    Normalize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(Byte) CMatchFinderBinTree::GetIndexByte(Int32 index)\r\n  { return CLZInWindow::GetIndexByte(index); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetMatchLen(Int32 index, \r\n    UInt32 back, UInt32 limit)\r\n  { return CLZInWindow::GetMatchLen(index, back, limit); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetNumAvailableBytes()\r\n  { return CLZInWindow::GetNumAvailableBytes(); }\r\n\r\nSTDMETHODIMP_(const Byte *) CMatchFinderBinTree::GetPointerToCurrentPos()\r\n  { return CLZInWindow::GetPointerToCurrentPos(); }\r\n\r\n// IMatchFinderSetCallback\r\nSTDMETHODIMP CMatchFinderBinTree::SetCallback(IMatchFinderCallback *callback)\r\n{\r\n  m_Callback = callback;\r\n  return S_OK;\r\n}\r\n\r\nvoid CMatchFinderBinTree::BeforeMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->BeforeChangingBufferPos();\r\n  CLZInWindow::BeforeMoveBlock();\r\n}\r\n\r\nvoid CMatchFinderBinTree::AfterMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->AfterChangingBufferPos();\r\n  CLZInWindow::AfterMoveBlock();\r\n}\r\n \r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/HashChain/HC.h",
    "content": "// HC.h\r\n\r\n#include \"../LZInWindow.h\"\r\n#include \"../IMatchFinder.h\"\r\n \r\nnamespace HC_NAMESPACE {\r\n\r\ntypedef UInt32 CIndex;\r\nconst UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\r\n\r\nclass CMatchFinderHC: \r\n  public IMatchFinder,\r\n  public IMatchFinderSetCallback,\r\n  public CLZInWindow,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 _cyclicBufferPos;\r\n  UInt32 _cyclicBufferSize; // it must be historySize + 1\r\n  UInt32 _matchMaxLen;\r\n  CIndex *_hash;\r\n  UInt32 _cutValue;\r\n\r\n  CMyComPtr<IMatchFinderCallback> m_Callback;\r\n\r\n  void Normalize();\r\n  void FreeThisClassMemory();\r\n  void FreeMemory();\r\n\r\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\r\n\r\n  STDMETHOD(Init)(ISequentialInStream *inStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(MovePos)();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\r\n  STDMETHOD_(void, DummyLongestMatch)();\r\n\r\n  // IMatchFinderSetCallback\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\r\n\r\n  virtual void BeforeMoveBlock();\r\n  virtual void AfterMoveBlock();\r\n\r\npublic:\r\n  CMatchFinderHC();\r\n  virtual ~CMatchFinderHC();\r\n  void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/HashChain/HC2.h",
    "content": "// HC2.h\r\n\r\n#ifndef __HC2_H\r\n#define __HC2_H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC2\r\n\r\n#include \"HCMF.h\"\r\n#include \"HCMFMain.h\"\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/HashChain/HC3.h",
    "content": "// HC3.h\r\n\r\n#ifndef __HC3_H\r\n#define __HC3_H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC3\r\n\r\n#define HASH_ARRAY_2\r\n\r\n#include \"HC.h\"\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/HashChain/HC4.h",
    "content": "// HC4.h\r\n\r\n#ifndef __HC4_H\r\n#define __HC4_H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC4\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n\r\n#include \"HC.h\"\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/HashChain/HC4b.h",
    "content": "// HC4b.h\r\n\r\n#ifndef __HC4B__H\r\n#define __HC4B__H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC4b\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n#define HASH_BIG\r\n\r\n#include \"HC.h\"\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n#undef HASH_BIG\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/HashChain/HCMain.h",
    "content": "// HC.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/CRC.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\nnamespace HC_NAMESPACE {\r\n\r\n#ifdef HASH_ARRAY_2\r\n  static const UInt32 kHash2Size = 1 << 10;\r\n  #ifdef HASH_ARRAY_3\r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 4;\r\n    static const UInt32 kHash3Size = 1 << 18;\r\n    #ifdef HASH_BIG\r\n    static const UInt32 kHashSize = 1 << 23;\r\n    #else\r\n    static const UInt32 kHashSize = 1 << 20;\r\n    #endif\r\n  #else\r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << (16);\r\n  #endif\r\n#else\r\n  #ifdef HASH_ZIP \r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << 16;\r\n  #else\r\n    #define THERE_ARE_DIRECT_HASH_BYTES\r\n    static const UInt32 kNumHashDirectBytes = 2;\r\n    static const UInt32 kNumHashBytes = 2;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n  #endif\r\n#endif\r\n\r\nstatic const UInt32 kHashSizeSum = kHashSize\r\n    #ifdef HASH_ARRAY_2\r\n    + kHash2Size\r\n    #ifdef HASH_ARRAY_3\r\n    + kHash3Size\r\n    #endif\r\n    #endif\r\n    ;\r\n\r\n#ifdef HASH_ARRAY_2\r\nstatic const UInt32 kHash2Offset = kHashSize;\r\n#ifdef HASH_ARRAY_3\r\nstatic const UInt32 kHash3Offset = kHashSize + kHash2Size;\r\n#endif\r\n#endif\r\n\r\nCMatchFinderHC::CMatchFinderHC():\r\n  _hash(0),\r\n  _cutValue(16)\r\n{\r\n}\r\n\r\nvoid CMatchFinderHC::FreeThisClassMemory()\r\n{\r\n  BigFree(_hash);\r\n  _hash = 0;\r\n}\r\n\r\nvoid CMatchFinderHC::FreeMemory()\r\n{\r\n  FreeThisClassMemory();\r\n  CLZInWindow::Free();\r\n}\r\n\r\nCMatchFinderHC::~CMatchFinderHC()\r\n{ \r\n  FreeMemory();\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderHC::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  UInt32 sizeReserv = (historySize + keepAddBufferBefore + \r\n      matchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n  if (CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, sizeReserv))\r\n  {\r\n    if (historySize + 256 > kMaxValForNormalize)\r\n    {\r\n      FreeMemory();\r\n      return E_INVALIDARG;\r\n    }\r\n    _matchMaxLen = matchMaxLen;\r\n    UInt32 newCyclicBufferSize = historySize + 1;\r\n    if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)\r\n      return S_OK;\r\n    FreeThisClassMemory();\r\n    _cyclicBufferSize = newCyclicBufferSize; // don't change it\r\n    _hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize) * sizeof(CIndex));\r\n    if (_hash != 0)\r\n      return S_OK;\r\n  }\r\n  FreeMemory();\r\n  return E_OUTOFMEMORY;\r\n}\r\n\r\nstatic const UInt32 kEmptyHashValue = 0;\r\n\r\nSTDMETHODIMP CMatchFinderHC::Init(ISequentialInStream *stream)\r\n{\r\n  RINOK(CLZInWindow::Init(stream));\r\n  for(UInt32 i = 0; i < kHashSizeSum; i++)\r\n    _hash[i] = kEmptyHashValue;\r\n  _cyclicBufferPos = 0;\r\n  ReduceOffsets(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderHC::ReleaseStream()\r\n{ \r\n  // ReleaseStream(); \r\n}\r\n\r\n#ifdef HASH_ARRAY_2\r\n#ifdef HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)\r\n{\r\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\r\n  hash2Value = temp & (kHash2Size - 1);\r\n  hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);\r\n  return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) & \r\n      (kHashSize - 1);\r\n}\r\n#else // no HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)\r\n{\r\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\r\n  hash2Value = temp & (kHash2Size - 1);\r\n  return (temp ^ (UInt32(pointer[2]) << 8)) & (kHashSize - 1);;\r\n}\r\n#endif // HASH_ARRAY_3\r\n#else // no HASH_ARRAY_2\r\n#ifdef HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return ((UInt32(pointer[0]) << 8) ^ \r\n      CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\r\n}\r\n#else // no HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return pointer[0] ^ (UInt32(pointer[1]) << 8);\r\n}\r\n#endif // HASH_ZIP\r\n#endif // HASH_ARRAY_2\r\n\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetLongestMatch(UInt32 *distances)\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kNumHashBytes)\r\n      return 0; \r\n  }\r\n\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  Byte *cur = _buffer + _pos;\r\n  \r\n  UInt32 maxLen = 0;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n  #ifdef HASH_ARRAY_2\r\n\r\n  UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  distances[2] = 0xFFFFFFFF;\r\n  if(curMatch2 > matchMinPos)\r\n    if (_buffer[curMatch2] == cur[0])\r\n    {\r\n      distances[2] = _pos - curMatch2 - 1;\r\n      maxLen = 2;\r\n    }\r\n\r\n  #ifdef HASH_ARRAY_3\r\n  \r\n  UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  distances[3] = 0xFFFFFFFF;\r\n  if(curMatch3 > matchMinPos)\r\n    if (_buffer[curMatch3] == cur[0])\r\n    {\r\n      distances[3] = _pos - curMatch3 - 1;\r\n      maxLen = 3;\r\n    }\r\n  \r\n  #endif\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[hashValue];\r\n  _hash[hashValue] = _pos;\r\n  CIndex *chain = _hash + kHashSizeSum;\r\n  chain[_cyclicBufferPos] = curMatch;\r\n  distances[kNumHashBytes] = 0xFFFFFFFF;\r\n  #ifdef THERE_ARE_DIRECT_HASH_BYTES\r\n  if (lenLimit == kNumHashDirectBytes)\r\n  {\r\n    if(curMatch > matchMinPos)\r\n      while (maxLen < kNumHashDirectBytes)\r\n        distances[++maxLen] = _pos - curMatch - 1;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 count = _cutValue;\r\n    do\r\n    {\r\n      if(curMatch <= matchMinPos)\r\n        break;\r\n      Byte *pby1 = _buffer + curMatch;\r\n      UInt32 currentLen = kNumHashDirectBytes;\r\n      do \r\n      {\r\n        if (pby1[currentLen] != cur[currentLen])\r\n          break;\r\n      }\r\n      while(++currentLen != lenLimit);\r\n      \r\n      UInt32 delta = _pos - curMatch;\r\n      while (maxLen < currentLen)\r\n        distances[++maxLen] = delta - 1;\r\n      if(currentLen == lenLimit)\r\n        break;\r\n      \r\n      UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n        (_cyclicBufferPos - delta):\r\n      (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n      \r\n      curMatch = chain[cyclicPos];\r\n    }\r\n    while(--count != 0);\r\n  }\r\n  #ifdef HASH_ARRAY_2\r\n  #ifdef HASH_ARRAY_3\r\n  if (distances[4] < distances[3])\r\n    distances[3] = distances[4];\r\n  #endif\r\n  if (distances[3] < distances[2])\r\n    distances[2] = distances[3];\r\n  #endif\r\n  return maxLen;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderHC::DummyLongestMatch()\r\n{\r\n  if (_streamPos - _pos < kNumHashBytes)\r\n    return; \r\n  \r\n  Byte *cur = _buffer + _pos;\r\n  \r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  _hash[kHashSizeSum + _cyclicBufferPos] = _hash[hashValue];\r\n  _hash[hashValue] = _pos;\r\n}\r\n\r\nvoid CMatchFinderHC::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _cyclicBufferSize;\r\n  CIndex *items = _hash;\r\n  UInt32 numItems = kHashSizeSum + _cyclicBufferSize;\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n  ReduceOffsets(subValue);\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderHC::MovePos()\r\n{\r\n  if (++_cyclicBufferPos == _cyclicBufferSize)\r\n    _cyclicBufferPos = 0;\r\n  RINOK(CLZInWindow::MovePos());\r\n  if (_pos == kMaxValForNormalize)\r\n    Normalize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(Byte) CMatchFinderHC::GetIndexByte(Int32 index)\r\n  { return CLZInWindow::GetIndexByte(index); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetMatchLen(Int32 index, \r\n    UInt32 back, UInt32 limit)\r\n  { return CLZInWindow::GetMatchLen(index, back, limit); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetNumAvailableBytes()\r\n  { return CLZInWindow::GetNumAvailableBytes(); }\r\n\r\nSTDMETHODIMP_(const Byte *) CMatchFinderHC::GetPointerToCurrentPos()\r\n  { return CLZInWindow::GetPointerToCurrentPos(); }\r\n\r\n// IMatchFinderSetCallback\r\nSTDMETHODIMP CMatchFinderHC::SetCallback(IMatchFinderCallback *callback)\r\n{\r\n  m_Callback = callback;\r\n  return S_OK;\r\n}\r\n\r\nvoid CMatchFinderHC::BeforeMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->BeforeChangingBufferPos();\r\n  CLZInWindow::BeforeMoveBlock();\r\n}\r\n\r\nvoid CMatchFinderHC::AfterMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->AfterChangingBufferPos();\r\n  CLZInWindow::AfterMoveBlock();\r\n}\r\n \r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/IMatchFinder.h",
    "content": "// MatchFinders/IMatchFinder.h\r\n\r\n#ifndef __IMATCHFINDER_H\r\n#define __IMATCHFINDER_H\r\n\r\n// {23170F69-40C1-278A-0000-000200010000}\r\nDEFINE_GUID(IID_IInWindowStream, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200010000\")\r\nIInWindowStream: public IUnknown\r\n{\r\n  STDMETHOD(Init)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD_(void, ReleaseStream)() PURE;\r\n  STDMETHOD(MovePos)() PURE;\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;\r\n};\r\n \r\n// {23170F69-40C1-278A-0000-000200020000}\r\nDEFINE_GUID(IID_IMatchFinder, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020000\")\r\nIMatchFinder: public IInWindowStream\r\n{\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances) PURE;\r\n  STDMETHOD_(void, DummyLongestMatch)() PURE;\r\n};\r\n\r\n// {23170F69-40C1-278A-0000-000200020100}\r\nDEFINE_GUID(IID_IMatchFinderCallback, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020100\")\r\nIMatchFinderCallback: public IUnknown\r\n{\r\n  STDMETHOD(BeforeChangingBufferPos)() PURE;\r\n  STDMETHOD(AfterChangingBufferPos)() PURE;\r\n};\r\n\r\n// {23170F69-40C1-278A-0000-000200020200}\r\nDEFINE_GUID(IID_IMatchFinderSetCallback, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020200\")\r\nIMatchFinderSetCallback: public IUnknown\r\n{\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback) PURE;\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000200030000}\r\nDEFINE_GUID(IID_IInitMatchFinder, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200030000\")\r\nIMatchFinderInit: public IUnknown\r\n{\r\n  STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/LZInWindow.cpp",
    "content": "// LZInWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZInWindow.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n\r\nvoid CLZInWindow::Free()\r\n{\r\n  ::BigFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nbool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n{\r\n  _keepSizeBefore = keepSizeBefore;\r\n  _keepSizeAfter = keepSizeAfter;\r\n  _keepSizeReserv = keepSizeReserv;\r\n  UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n  if (_bufferBase == 0 || _blockSize != blockSize)\r\n  {\r\n    Free();\r\n    _blockSize = blockSize;\r\n    if (_blockSize != 0)\r\n      _bufferBase = (Byte *)::BigAlloc(_blockSize);\r\n  }\r\n  _pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;\r\n  if (_blockSize == 0)\r\n    return true;\r\n  return (_bufferBase != 0);\r\n}\r\n\r\n\r\nHRESULT CLZInWindow::Init(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n  _buffer = _bufferBase;\r\n  _pos = 0;\r\n  _streamPos = 0;\r\n  _streamEndWasReached = false;\r\n  return ReadBlock();\r\n}\r\n\r\n/*\r\nvoid CLZInWindow::ReleaseStream()\r\n{\r\n  _stream.Release();\r\n}\r\n*/\r\n\r\n///////////////////////////////////////////\r\n// ReadBlock\r\n\r\n// In State:\r\n//   (_buffer + _streamPos) <= (_bufferBase + _blockSize)\r\n// Out State:\r\n//   _posLimit <= _blockSize - _keepSizeAfter;\r\n//   if(_streamEndWasReached == false):\r\n//     _streamPos >= _pos + _keepSizeAfter\r\n//     _posLimit = _streamPos - _keepSizeAfter;\r\n//   else\r\n//          \r\n  \r\nHRESULT CLZInWindow::ReadBlock()\r\n{\r\n  if(_streamEndWasReached)\r\n    return S_OK;\r\n  while(true)\r\n  {\r\n    UInt32 size = UInt32(_bufferBase - _buffer) + _blockSize - _streamPos;\r\n    if(size == 0)\r\n      return S_OK;\r\n    UInt32 numReadBytes;\r\n    RINOK(_stream->Read(_buffer + _streamPos, size, &numReadBytes));\r\n    if(numReadBytes == 0)\r\n    {\r\n      _posLimit = _streamPos;\r\n      const Byte *pointerToPostion = _buffer + _posLimit;\r\n      if(pointerToPostion > _pointerToLastSafePosition)\r\n        _posLimit = (UInt32)(_pointerToLastSafePosition - _buffer);\r\n      _streamEndWasReached = true;\r\n      return S_OK;\r\n    }\r\n    _streamPos += numReadBytes;\r\n    if(_streamPos >= _pos + _keepSizeAfter)\r\n    {\r\n      _posLimit = _streamPos - _keepSizeAfter;\r\n      return S_OK;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CLZInWindow::MoveBlock()\r\n{\r\n  BeforeMoveBlock();\r\n  UInt32 offset = UInt32(_buffer - _bufferBase) + _pos - _keepSizeBefore;\r\n  UInt32 numBytes = UInt32(_buffer - _bufferBase) + _streamPos -  offset;\r\n  memmove(_bufferBase, _bufferBase + offset, numBytes);\r\n  _buffer -= offset;\r\n  AfterMoveBlock();\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/LZInWindow.h",
    "content": "// LZInWindow.h\r\n\r\n#ifndef __LZ_IN_WINDOW_H\r\n#define __LZ_IN_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n\r\nclass CLZInWindow\r\n{\r\n  Byte *_bufferBase; // pointer to buffer with data\r\n  ISequentialInStream *_stream;\r\n  UInt32 _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n  bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n  const Byte *_pointerToLastSafePosition;\r\nprotected:\r\n  Byte  *_buffer;   // Pointer to virtual Buffer begin\r\n  UInt32 _blockSize;  // Size of Allocated memory block\r\n  UInt32 _pos;             // offset (from _buffer) of curent byte\r\n  UInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n  UInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n  UInt32 _keepSizeReserv;  // how many BYTEs must be kept as reserv\r\n  UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\r\n  virtual void BeforeMoveBlock() {};\r\n  virtual void AfterMoveBlock() {};\r\n  void MoveBlock();\r\n  virtual HRESULT ReadBlock();\r\n  void Free();\r\npublic:\r\n  CLZInWindow(): _bufferBase(0) {}\r\n  virtual ~CLZInWindow() { Free(); }\r\n\r\n  bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, \r\n      UInt32 keepSizeReserv = (1<<17));\r\n\r\n  HRESULT Init(ISequentialInStream *stream);\r\n  // void ReleaseStream();\r\n\r\n  Byte *GetBuffer() const { return _buffer; }\r\n\r\n  const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }\r\n\r\n  HRESULT MovePos()\r\n  {\r\n    _pos++;\r\n    if (_pos > _posLimit)\r\n    {\r\n      const Byte *pointerToPostion = _buffer + _pos;\r\n      if(pointerToPostion > _pointerToLastSafePosition)\r\n        MoveBlock();\r\n      return ReadBlock();\r\n    }\r\n    else\r\n      return S_OK;\r\n  }\r\n  Byte GetIndexByte(Int32 index)const\r\n    {  return _buffer[(size_t)_pos + index]; }\r\n\r\n  // index + limit have not to exceed _keepSizeAfter;\r\n  UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const\r\n  {  \r\n    if(_streamEndWasReached)\r\n      if ((_pos + index) + limit > _streamPos)\r\n        limit = _streamPos - (_pos + index);\r\n    distance++;\r\n    Byte *pby = _buffer + (size_t)_pos + index;\r\n    UInt32 i;\r\n    for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);\r\n    return i;\r\n  }\r\n\r\n  UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }\r\n\r\n  void ReduceOffsets(Int32 subValue)\r\n  {\r\n    _buffer += subValue;\r\n    _posLimit -= subValue;\r\n    _pos -= subValue;\r\n    _streamPos -= subValue;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/LZOutWindow.cpp",
    "content": "// LZOutWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"LZOutWindow.h\"\r\n\r\nvoid CLZOutWindow::Init(bool solid)\r\n{\r\n  if(!solid)\r\n    COutBuffer::Init();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/LZOutWindow.h",
    "content": "// LZOutWindow.h\r\n\r\n#ifndef __LZ_OUT_WINDOW_H\r\n#define __LZ_OUT_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\n/*\r\n#ifndef _NO_EXCEPTIONS\r\nclass CLZOutWindowException\r\n{\r\npublic:\r\n  HRESULT ErrorCode;\r\n  CLZOutWindowException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n*/\r\ntypedef COutBufferException CLZOutWindowException;\r\n\r\nclass CLZOutWindow: public COutBuffer\r\n{\r\npublic:\r\n  void Init(bool solid = false);\r\n  \r\n  // distance >= 0, len > 0, \r\n  bool CopyBlock(UInt32 distance, UInt32 len)\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n    {\r\n      if (!_overDict)\r\n        return false;\r\n      pos += _bufferSize;\r\n    }\r\n    do\r\n    {\r\n      if (pos == _bufferSize)\r\n        pos = 0;\r\n      _buffer[_pos++] = _buffer[pos++];\r\n      if (_pos == _limitPos)\r\n        FlushWithCheck();  \r\n    }\r\n    while(--len != 0);\r\n    return true;\r\n  }\r\n  \r\n  void PutByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if (_pos == _limitPos)\r\n      FlushWithCheck();  \r\n  }\r\n  \r\n  Byte GetByte(UInt32 distance) const\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n      pos += _bufferSize;\r\n    return _buffer[pos]; \r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/Patricia/Pat.h",
    "content": "// Pat.h\r\n\r\n// #ifndef __PATRICIA__H\r\n// #define __PATRICIA__H\r\n\r\n#include \"../../../../Common/MyCom.h\"\r\n#include \"../../../../Common/Types.h\"\r\n#include \"../LZInWindow.h\"\r\n\r\nnamespace PAT_NAMESPACE {\r\n\r\nstruct CNode;\r\n\r\ntypedef CNode *CNodePointer;\r\n\r\n// #define __AUTO_REMOVE\r\n\r\n// #define __NODE_4_BITS\r\n// #define __NODE_3_BITS\r\n// #define __NODE_2_BITS\r\n// #define __NODE_2_BITS_PADDING\r\n\r\n// #define __HASH_3\r\n\r\n\r\ntypedef UInt32 CIndex;\r\n\r\n#ifdef __NODE_4_BITS\r\n  typedef UInt32 CIndex2;\r\n  typedef UInt32 CSameBitsType;\r\n#else\r\n#ifdef __NODE_3_BITS\r\n  typedef UInt32 CIndex2;\r\n  typedef UInt32 CSameBitsType;\r\n#else\r\n\r\n  typedef UInt32 CIndex;\r\n  typedef UInt32 CSameBitsType;\r\n\r\n  typedef CIndex CIndex2;\r\n#endif\r\n#endif\r\n\r\nconst UInt32 kNumBitsInIndex = sizeof(CIndex) * 8;\r\nconst UInt32 kMatchStartValue = UInt32(1) << (kNumBitsInIndex - 1);\r\n// don't change kMatchStartValue definition, since it is used in \r\n// PatMain.h: \r\n\r\ntypedef CIndex CMatchPointer;\r\n\r\nconst UInt32 kDescendantEmptyValue = kMatchStartValue - 1;\r\n\r\nunion CDescendant \r\n{\r\n  CIndex NodePointer;\r\n  CMatchPointer MatchPointer;\r\n  bool IsEmpty() const { return NodePointer == kDescendantEmptyValue; }\r\n  bool IsNode() const { return NodePointer < kDescendantEmptyValue; }\r\n  bool IsMatch() const { return NodePointer > kDescendantEmptyValue; }\r\n  void MakeEmpty() { NodePointer = kDescendantEmptyValue; }\r\n};\r\n\r\n#undef MY_BYTE_SIZE\r\n\r\n#ifdef __NODE_4_BITS\r\n  #define MY_BYTE_SIZE 8\r\n  const UInt32 kNumSubBits = 4;\r\n#else\r\n#ifdef __NODE_3_BITS\r\n  #define MY_BYTE_SIZE 9\r\n  const UInt32 kNumSubBits = 3;\r\n#else\r\n  #define MY_BYTE_SIZE 8\r\n  #ifdef __NODE_2_BITS\r\n    const UInt32 kNumSubBits = 2;\r\n  #else\r\n    const UInt32 kNumSubBits = 1;\r\n  #endif\r\n#endif\r\n#endif\r\n\r\nconst UInt32 kNumSubNodes = 1 << kNumSubBits;\r\nconst UInt32 kSubNodesMask = kNumSubNodes - 1;\r\n\r\nstruct CNode\r\n{\r\n  CIndex2 LastMatch;\r\n  CSameBitsType NumSameBits;\r\n  union\r\n  {\r\n    CDescendant  Descendants[kNumSubNodes];\r\n    UInt32 NextFreeNode;\r\n  };\r\n  #ifdef __NODE_2_BITS\r\n  #ifdef __NODE_2_BITS_PADDING\r\n  UInt32 Padding[2];\r\n  #endif\r\n  #endif\r\n};\r\n\r\n#undef kIDNumBitsByte\r\n#undef kIDNumBitsString\r\n\r\n#ifdef __NODE_4_BITS\r\n  #define kIDNumBitsByte 0x30\r\n  #define kIDNumBitsString TEXT(\"4\")\r\n#else\r\n#ifdef __NODE_3_BITS\r\n  #define kIDNumBitsByte 0x20\r\n  #define kIDNumBitsString TEXT(\"3\")\r\n#else\r\n#ifdef __NODE_2_BITS\r\n  #define kIDNumBitsByte 0x10\r\n  #define kIDNumBitsString TEXT(\"2\")\r\n#else\r\n  #define kIDNumBitsByte 0x00\r\n  #define kIDNumBitsString TEXT(\"1\")\r\n#endif\r\n#endif\r\n#endif\r\n\r\n#undef kIDManualRemoveByte\r\n#undef kIDManualRemoveString\r\n\r\n#ifdef __AUTO_REMOVE\r\n  #define kIDManualRemoveByte 0x00\r\n  #define kIDManualRemoveString TEXT(\"\")\r\n#else\r\n  #define kIDManualRemoveByte 0x08\r\n  #define kIDManualRemoveString TEXT(\"R\")\r\n#endif\r\n\r\n#undef kIDHash3Byte\r\n#undef kIDHash3String\r\n\r\n#ifdef __HASH_3\r\n  #define kIDHash3Byte 0x04\r\n  #define kIDHash3String TEXT(\"H\")\r\n#else\r\n  #define kIDHash3Byte 0x00\r\n  #define kIDHash3String TEXT(\"\")\r\n#endif\r\n\r\n#undef kIDUse3BytesByte\r\n#undef kIDUse3BytesString\r\n\r\n#define kIDUse3BytesByte 0x00\r\n#define kIDUse3BytesString TEXT(\"\")\r\n\r\n#undef kIDPaddingByte\r\n#undef kIDPaddingString\r\n\r\n#ifdef __NODE_2_BITS_PADDING\r\n  #define kIDPaddingByte 0x01\r\n  #define kIDPaddingString TEXT(\"P\")\r\n#else\r\n  #define kIDPaddingByte 0x00\r\n  #define kIDPaddingString TEXT(\"\")\r\n#endif\r\n\r\n\r\n// #undef kIDString\r\n// #define kIDString TEXT(\"Compress.MatchFinderPat\") kIDNumBitsString kIDManualRemoveString kIDUse3BytesString kIDPaddingString kIDHash3String\r\n\r\n// {23170F69-40C1-278C-01XX-0000000000}\r\n\r\nDEFINE_GUID(PAT_CLSID, \r\n0x23170F69, 0x40C1, 0x278C, 0x01, \r\nkIDNumBitsByte | \r\nkIDManualRemoveByte | kIDHash3Byte | kIDUse3BytesByte | kIDPaddingByte, \r\n0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\n// III(PAT_NAMESPACE)\r\n\r\nclass CPatricia: \r\n  public IMatchFinder,\r\n  public IMatchFinderSetCallback,\r\n  public CMyUnknownImp,\r\n  CLZInWindow\r\n{ \r\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\r\n\r\n  STDMETHOD(Init)(ISequentialInStream *aStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(MovePos)();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD(Create)(UInt32 historySize, \r\n      UInt32 keepAddBufferBefore, UInt32 matchMaxLen, \r\n      UInt32 keepAddBufferAfter);\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\r\n  STDMETHOD_(void, DummyLongestMatch)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n\r\n  void FreeMemory();\r\npublic:\r\n  CPatricia();\r\n  ~CPatricia();\r\n\r\n  UInt32 _sizeHistory;\r\n  UInt32 _matchMaxLen;\r\n\r\n  CDescendant *m_HashDescendants;\r\n  #ifdef __HASH_3\r\n  CDescendant *m_Hash2Descendants;\r\n  #endif\r\n\r\n  CNode *m_Nodes;\r\n\r\n  UInt32 m_FreeNode;\r\n  UInt32 m_FreeNodeMax;\r\n\r\n  #ifdef __AUTO_REMOVE\r\n  UInt32 m_NumUsedNodes;\r\n  UInt32 m_NumNodes;\r\n  #else\r\n  bool  m_SpecialRemoveMode;\r\n  #endif\r\n\r\n  bool  m_SpecialMode;\r\n  UInt32 m_NumNotChangedCycles;\r\n  UInt32 *m_TmpBacks;\r\n\r\n  CMyComPtr<IMatchFinderCallback> m_Callback;\r\n\r\n  virtual void BeforeMoveBlock();\r\n  virtual void AfterMoveBlock();\r\n\r\n  // IMatchFinderSetCallback\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\r\n\r\n  void ChangeLastMatch(UInt32 hashValue);\r\n  \r\n  #ifdef __AUTO_REMOVE\r\n  void TestRemoveDescendant(CDescendant &descendant, UInt32 limitPos);\r\n  void TestRemoveNodes();\r\n  void RemoveNode(UInt32 index);\r\n  void TestRemoveAndNormalizeDescendant(CDescendant &descendant, \r\n      UInt32 limitPos, UInt32 subValue);\r\n  void TestRemoveNodesAndNormalize();\r\n  #else\r\n  void NormalizeDescendant(CDescendant &descendant, UInt32 subValue);\r\n  void Normalize();\r\n  void RemoveMatch();\r\n  #endif\r\nprivate:\r\n  void AddInternalNode(CNodePointer aNode, CIndex *aNodePointerPointer, \r\n      Byte aByte, Byte aByteXOR, UInt32 aNumSameBits, UInt32 aPos)\r\n  {\r\n    while((aByteXOR & kSubNodesMask) == 0)\r\n    {\r\n      aByteXOR >>= kNumSubBits;\r\n      aByte >>= kNumSubBits;\r\n      aNumSameBits -= kNumSubBits;\r\n    }\r\n    // Insert New Node\r\n    CNodePointer aNewNode = &m_Nodes[m_FreeNode];\r\n    UInt32 aNodeIndex = *aNodePointerPointer;\r\n    *aNodePointerPointer = m_FreeNode;\r\n    m_FreeNode = aNewNode->NextFreeNode;\r\n    #ifdef __AUTO_REMOVE\r\n    m_NumUsedNodes++;\r\n    #endif\r\n    if (m_FreeNode > m_FreeNodeMax)\r\n    {\r\n      m_FreeNodeMax = m_FreeNode;\r\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\r\n    }\r\n\r\n    UInt32 aBitsNew = aByte & kSubNodesMask;\r\n    UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;\r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n      aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;\r\n    aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;\r\n    aNewNode->Descendants[aBitsOld].NodePointer = aNodeIndex;\r\n    aNewNode->NumSameBits = CSameBitsType(aNode->NumSameBits - aNumSameBits);\r\n    aNewNode->LastMatch = aPos;\r\n    \r\n    aNode->NumSameBits = CSameBitsType(aNumSameBits - kNumSubBits);\r\n  }\r\n\r\n  void AddLeafNode(CNodePointer aNode, Byte aByte, Byte aByteXOR, \r\n      UInt32 aNumSameBits, UInt32 aPos, UInt32 aDescendantIndex)\r\n  {\r\n    for(;(aByteXOR & kSubNodesMask) == 0; aNumSameBits += kNumSubBits)\r\n    {\r\n      aByte >>= kNumSubBits;\r\n      aByteXOR >>= kNumSubBits;\r\n    }\r\n    UInt32 aNewNodeIndex = m_FreeNode;\r\n    CNodePointer aNewNode = &m_Nodes[m_FreeNode];\r\n    m_FreeNode = aNewNode->NextFreeNode;\r\n    #ifdef __AUTO_REMOVE\r\n    m_NumUsedNodes++;\r\n    #endif\r\n    if (m_FreeNode > m_FreeNodeMax)\r\n    {\r\n      m_FreeNodeMax = m_FreeNode;\r\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\r\n    }\r\n\r\n    UInt32 aBitsNew = (aByte & kSubNodesMask);\r\n    UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;\r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n      aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;\r\n    aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;\r\n    aNewNode->Descendants[aBitsOld].MatchPointer = \r\n      aNode->Descendants[aDescendantIndex].MatchPointer;\r\n    aNewNode->NumSameBits = CSameBitsType(aNumSameBits);\r\n    aNewNode->LastMatch = aPos;\r\n    aNode->Descendants[aDescendantIndex].NodePointer = aNewNodeIndex;\r\n  }\r\n};\r\n\r\n}\r\n\r\n// #endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/Patricia/Pat2.h",
    "content": "// Pat2.h\r\n\r\n#ifndef __PAT2__H\r\n#define __PAT2__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat2\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat2\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_2_BITS\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef  __NODE_2_BITS\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/Patricia/Pat2H.h",
    "content": "// Pat2H.h\r\n\r\n#ifndef __PAT2H__H\r\n#define __PAT2H__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat2H\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat2H\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_2_BITS\r\n#define __HASH_3\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef __NODE_2_BITS\r\n#undef __HASH_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/Patricia/Pat2R.h",
    "content": "// Pat2R.h\r\n\r\n#ifndef __PAT2R__H\r\n#define __PAT2R__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat2R\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat2R\r\n\r\n#define __NODE_2_BITS\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef  __NODE_2_BITS\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/Patricia/Pat3H.h",
    "content": "// Pat3H.h\r\n\r\n#ifndef __PAT3H__H\r\n#define __PAT3H__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat3H\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat3H\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_3_BITS\r\n#define __HASH_3\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef __NODE_3_BITS\r\n#undef __HASH_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/Patricia/Pat4H.h",
    "content": "// Pat4H.h\r\n\r\n#ifndef __PAT4H__H\r\n#define __PAT4H__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat4H\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat4H\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_4_BITS\r\n#define __HASH_3\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef __NODE_4_BITS\r\n#undef __HASH_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/Patricia/PatMain.h",
    "content": "// PatMain.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\nnamespace PAT_NAMESPACE {\r\n\r\nSTDMETHODIMP CPatricia::SetCallback(IMatchFinderCallback *callback)\r\n{\r\n  m_Callback = callback;\r\n  return S_OK;\r\n}\r\n\r\nvoid CPatricia::BeforeMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->BeforeChangingBufferPos();\r\n  CLZInWindow::BeforeMoveBlock();\r\n}\r\n\r\nvoid CPatricia::AfterMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->AfterChangingBufferPos();\r\n  CLZInWindow::AfterMoveBlock();\r\n}\r\n\r\nconst UInt32 kMatchStartValue2 = 2;\r\nconst UInt32 kDescendantEmptyValue2 = kMatchStartValue2 - 1;\r\nconst UInt32 kDescendantsNotInitilized2 = kDescendantEmptyValue2 - 1;\r\n\r\n#ifdef __HASH_3\r\n\r\nstatic const UInt32 kNumHashBytes = 3;\r\nstatic const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n\r\nstatic const UInt32 kNumHash2Bytes = 2;\r\nstatic const UInt32 kHash2Size = 1 << (8 * kNumHash2Bytes);\r\nstatic const UInt32 kPrevHashSize = kNumHash2Bytes;\r\n\r\n#else\r\n\r\nstatic const UInt32 kNumHashBytes = 2;\r\nstatic const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\nstatic const UInt32 kPrevHashSize = 0;\r\n\r\n#endif\r\n\r\n\r\nCPatricia::CPatricia():\r\n  m_HashDescendants(0),\r\n  #ifdef __HASH_3\r\n  m_Hash2Descendants(0),\r\n  #endif\r\n  m_Nodes(0),\r\n  m_TmpBacks(0)\r\n{\r\n}\r\n\r\nCPatricia::~CPatricia()\r\n{\r\n  FreeMemory();\r\n}\r\n\r\nvoid CPatricia::FreeMemory()\r\n{\r\n  MyFree(m_TmpBacks);\r\n  m_TmpBacks = 0;\r\n\r\n  ::BigFree(m_Nodes);\r\n  m_Nodes = 0;\r\n\r\n  ::BigFree(m_HashDescendants);\r\n  m_HashDescendants = 0;\r\n\r\n  #ifdef __HASH_3\r\n\r\n  ::BigFree(m_Hash2Descendants);\r\n  m_Hash2Descendants = 0;\r\n\r\n  CLZInWindow::Free();\r\n\r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP CPatricia::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  FreeMemory();\r\n  int kNumBitsInNumSameBits = sizeof(CSameBitsType) * 8;\r\n  if (kNumBitsInNumSameBits < 32 && ((matchMaxLen * MY_BYTE_SIZE) > ((UInt32)1 << kNumBitsInNumSameBits)))\r\n    return E_INVALIDARG;\r\n\r\n  const UInt32 kAlignMask = (1 << 16) - 1;\r\n  UInt32 windowReservSize = historySize;\r\n  windowReservSize += kAlignMask;\r\n  windowReservSize &= ~(kAlignMask);\r\n\r\n  const UInt32 kMinReservSize = (1 << 19);\r\n  if (windowReservSize < kMinReservSize)\r\n    windowReservSize = kMinReservSize;\r\n  windowReservSize += 256;\r\n\r\n  if (!CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, windowReservSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _sizeHistory = historySize;\r\n  _matchMaxLen = matchMaxLen;\r\n  m_HashDescendants = (CDescendant *)BigAlloc(kHashSize * sizeof(CDescendant));\r\n  if (m_HashDescendants == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n\r\n  #ifdef __HASH_3\r\n  m_Hash2Descendants = (CDescendant *)BigAlloc(kHash2Size  * sizeof(CDescendant));\r\n  if (m_Hash2Descendants == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n  #endif\r\n  \r\n  #ifdef __AUTO_REMOVE\r\n  \r\n  #ifdef __HASH_3\r\n  m_NumNodes = historySize + _sizeHistory * 4 / 8 + (1 << 19);\r\n  #else\r\n  m_NumNodes = historySize + _sizeHistory * 4 / 8 + (1 << 10);\r\n  #endif\r\n  \r\n  #else\r\n  \r\n  UInt32 m_NumNodes = historySize;\r\n  \r\n  #endif\r\n  \r\n  const UInt32 kMaxNumNodes = UInt32(1) << (sizeof(CIndex) * 8 - 1);\r\n  if (m_NumNodes + 32 > kMaxNumNodes)\r\n    return E_INVALIDARG;\r\n  \r\n  // m_Nodes = (CNode *)::BigAlloc((m_NumNodes + 2) * sizeof(CNode));\r\n  m_Nodes = (CNode *)::BigAlloc((m_NumNodes + 12) * sizeof(CNode));\r\n  if (m_Nodes == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n  \r\n  m_TmpBacks = (UInt32 *)MyAlloc((_matchMaxLen + 1) * sizeof(UInt32));\r\n  if (m_TmpBacks == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CPatricia::Init(ISequentialInStream *aStream)\r\n{\r\n  RINOK(CLZInWindow::Init(aStream));\r\n\r\n  // memset(m_HashDescendants, 0xFF, kHashSize * sizeof(m_HashDescendants[0]));\r\n\r\n  #ifdef __HASH_3\r\n  for (UInt32 i = 0; i < kHash2Size; i++)\r\n    m_Hash2Descendants[i].MatchPointer = kDescendantsNotInitilized2;\r\n  #else\r\n  for (UInt32 i = 0; i < kHashSize; i++)\r\n    m_HashDescendants[i].MakeEmpty();\r\n  #endif\r\n\r\n  m_Nodes[0].NextFreeNode = 1;\r\n  m_FreeNode = 0;\r\n  m_FreeNodeMax = 0;\r\n  #ifdef __AUTO_REMOVE\r\n  m_NumUsedNodes = 0;\r\n  #else\r\n  m_SpecialRemoveMode = false;\r\n  #endif\r\n  m_SpecialMode = false;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CPatricia::ReleaseStream()\r\n{\r\n  // CLZInWindow::ReleaseStream();\r\n}\r\n\r\n// pos = _pos + kNumHashBytes\r\n// fullCurrentLimit = currentLimit + kNumHashBytes\r\n// fullMatchLen = matchLen + kNumHashBytes\r\n\r\nvoid CPatricia::ChangeLastMatch(UInt32 hashValue)\r\n{\r\n  UInt32 pos = _pos + kNumHashBytes - 1;\r\n  UInt32 descendantIndex;\r\n  const Byte *currentBytePointer = _buffer + pos;\r\n  UInt32 numLoadedBits = 0;\r\n  Byte curByte = 0;  // = 0 to disable warning of GCC\r\n  CNodePointer node = &m_Nodes[m_HashDescendants[hashValue].NodePointer];\r\n\r\n  while(true)\r\n  {\r\n    UInt32 numSameBits = node->NumSameBits;\r\n    if(numSameBits > 0)\r\n    {\r\n      if (numLoadedBits < numSameBits)\r\n      {\r\n        numSameBits -= numLoadedBits;\r\n        currentBytePointer += (numSameBits / MY_BYTE_SIZE);\r\n        numSameBits %= MY_BYTE_SIZE;\r\n        curByte = *currentBytePointer++;\r\n        numLoadedBits = MY_BYTE_SIZE; \r\n      }\r\n      curByte >>= numSameBits;\r\n      numLoadedBits -= numSameBits;\r\n    }\r\n    if(numLoadedBits == 0)\r\n    {\r\n      curByte = *currentBytePointer++;\r\n      numLoadedBits = MY_BYTE_SIZE; \r\n    }\r\n    descendantIndex = (curByte & kSubNodesMask);\r\n    node->LastMatch = pos;\r\n    numLoadedBits -= kNumSubBits;\r\n    curByte >>= kNumSubBits;\r\n    if(node->Descendants[descendantIndex].IsNode())\r\n      node = &m_Nodes[node->Descendants[descendantIndex].NodePointer];\r\n    else\r\n      break;\r\n  }\r\n  node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n}\r\n\r\nUInt32 CPatricia::GetLongestMatch(UInt32 *distances)\r\n{\r\n  UInt32 fullCurrentLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    fullCurrentLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    fullCurrentLimit = _streamPos - _pos;\r\n    if(fullCurrentLimit < kNumHashBytes)\r\n      return 0; \r\n  }\r\n  UInt32 pos = _pos + kNumHashBytes;\r\n\r\n  #ifdef __HASH_3\r\n  UInt32 hash2Value = ((UInt32(_buffer[_pos])) << 8) | _buffer[_pos + 1];\r\n  UInt32 hashValue = (hash2Value << 8) | _buffer[_pos + 2];\r\n  CDescendant &hash2Descendant = m_Hash2Descendants[hash2Value];\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  if(hash2Descendant.MatchPointer <= kDescendantEmptyValue2)\r\n  {\r\n    if(hash2Descendant.MatchPointer == kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hashValue & 0xFFFF00;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n        m_HashDescendants[base + i].MakeEmpty();\r\n    }\r\n    hash2Descendant.MatchPointer = pos + kMatchStartValue2;\r\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n    return 0;\r\n  }\r\n\r\n  distances[kNumHash2Bytes] = pos - (hash2Descendant.MatchPointer - kMatchStartValue2) - 1;\r\n  hash2Descendant.MatchPointer = pos + kMatchStartValue2;\r\n  #ifdef __AUTO_REMOVE\r\n  if (distances[kNumHash2Bytes] >= _sizeHistory)\r\n  {\r\n    if (hashDescendant.IsNode())\r\n      RemoveNode(hashDescendant.NodePointer);\r\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n    return 0;\r\n  }\r\n  #endif\r\n  if (fullCurrentLimit == kNumHash2Bytes)\r\n    return kNumHash2Bytes;\r\n\r\n  #else\r\n  UInt32 hashValue = UInt32(GetIndexByte(1))  | (UInt32(GetIndexByte(0)) << 8);\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  #endif\r\n\r\n\r\n  if(m_SpecialMode)\r\n  {\r\n    if(hashDescendant.IsMatch())\r\n      m_NumNotChangedCycles = 0;\r\n    if(m_NumNotChangedCycles >= _sizeHistory - 1)\r\n    {\r\n      ChangeLastMatch(hashValue);\r\n      m_NumNotChangedCycles = 0;\r\n    }\r\n    if(GetIndexByte(fullCurrentLimit - 1) == GetIndexByte(fullCurrentLimit - 2)) \r\n    {\r\n      if(hashDescendant.IsMatch())\r\n        hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n      else\r\n        m_NumNotChangedCycles++;\r\n      for(UInt32 i = kNumHashBytes; i <= fullCurrentLimit; i++)\r\n        distances[i] = 0;\r\n      return fullCurrentLimit;\r\n    }\r\n    else if(m_NumNotChangedCycles > 0)\r\n      ChangeLastMatch(hashValue);\r\n    m_SpecialMode = false;\r\n  }\r\n\r\n  if(hashDescendant.IsEmpty())\r\n  {\r\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n    return kPrevHashSize;\r\n  }\r\n\r\n  UInt32 currentLimit = fullCurrentLimit - kNumHashBytes;\r\n\r\n  if(hashDescendant.IsMatch())\r\n  {\r\n    CMatchPointer matchPointer = hashDescendant.MatchPointer;\r\n    UInt32 backReal = pos - (matchPointer - kMatchStartValue);\r\n    UInt32 back = backReal - 1;\r\n    #ifdef __AUTO_REMOVE\r\n    if (back >= _sizeHistory)\r\n    {\r\n      hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n      return kPrevHashSize;\r\n    }\r\n    #endif\r\n\r\n    UInt32 matchLen;\r\n    distances += kNumHashBytes;\r\n    Byte *buffer = _buffer + pos;\r\n    for(matchLen = 0; true; matchLen++)\r\n    {\r\n      *distances++ = back;\r\n      if (matchLen == currentLimit)\r\n      {\r\n        hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n        return kNumHashBytes + matchLen;\r\n      }\r\n      if (buffer[matchLen] != buffer[(size_t)matchLen - backReal])\r\n        break;\r\n    }\r\n     \r\n    // UInt32 matchLen = GetMatchLen(kNumHashBytes, back, currentLimit);\r\n    \r\n    UInt32 fullMatchLen = matchLen + kNumHashBytes; \r\n    hashDescendant.NodePointer = m_FreeNode;\r\n    CNodePointer node = &m_Nodes[m_FreeNode];\r\n    m_FreeNode = node->NextFreeNode;\r\n    #ifdef __AUTO_REMOVE\r\n    m_NumUsedNodes++;\r\n    #endif\r\n    if (m_FreeNode > m_FreeNodeMax)\r\n    {\r\n      m_FreeNodeMax = m_FreeNode;\r\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\r\n    }\r\n      \r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n      node->Descendants[i].NodePointer = kDescendantEmptyValue;\r\n    node->LastMatch = pos;\r\n      \r\n    Byte byteNew = GetIndexByte(fullMatchLen);\r\n    Byte byteOld = GetIndexByte(fullMatchLen - backReal);\r\n    Byte bitsNew, bitsOld;\r\n    UInt32 numSameBits = matchLen * MY_BYTE_SIZE;\r\n    while (true)\r\n    {\r\n      bitsNew = (byteNew & kSubNodesMask);\r\n      bitsOld = (byteOld & kSubNodesMask);\r\n      if(bitsNew != bitsOld) \r\n        break;\r\n      byteNew >>= kNumSubBits;\r\n      byteOld >>= kNumSubBits;\r\n      numSameBits += kNumSubBits;\r\n    }\r\n    node->NumSameBits = CSameBitsType(numSameBits);\r\n    node->Descendants[bitsNew].MatchPointer = pos + kMatchStartValue;\r\n    node->Descendants[bitsOld].MatchPointer = matchPointer;\r\n    return fullMatchLen;\r\n  }\r\n  const Byte *baseCurrentBytePointer = _buffer + pos;\r\n  const Byte *currentBytePointer = baseCurrentBytePointer;\r\n  UInt32 numLoadedBits = 0;\r\n  Byte curByte = 0;\r\n  CIndex *nodePointerPointer = &hashDescendant.NodePointer;\r\n  CNodePointer node = &m_Nodes[*nodePointerPointer];\r\n  distances += kNumHashBytes;\r\n  const Byte *bytePointerLimit = baseCurrentBytePointer + currentLimit;\r\n  const Byte *currentAddingOffset = _buffer;\r\n\r\n  #ifdef __AUTO_REMOVE\r\n  UInt32 lowPos;\r\n  if (pos > _sizeHistory)\r\n    lowPos = pos - _sizeHistory;\r\n  else\r\n    lowPos = 0;\r\n  #endif\r\n\r\n  while(true)\r\n  {\r\n    #ifdef __AUTO_REMOVE\r\n    if (node->LastMatch < lowPos)\r\n    {\r\n      RemoveNode(*nodePointerPointer);\r\n      *nodePointerPointer = pos + kMatchStartValue;\r\n      if (currentBytePointer == baseCurrentBytePointer)\r\n        return kPrevHashSize;\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n    #endif\r\n    if(numLoadedBits == 0)\r\n    {\r\n      *distances++ = pos - node->LastMatch - 1;\r\n      if(currentBytePointer >= bytePointerLimit)\r\n      {\r\n        for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n          node->Descendants[i].MatchPointer = pos + kMatchStartValue;\r\n        node->LastMatch = pos;\r\n        node->NumSameBits = 0;\r\n        return fullCurrentLimit;\r\n      }\r\n      curByte = (*currentBytePointer++);\r\n      currentAddingOffset++;\r\n      numLoadedBits = MY_BYTE_SIZE; \r\n    }\r\n    UInt32 numSameBits = node->NumSameBits;\r\n    if(numSameBits > 0)\r\n    {\r\n      Byte byteXOR = ((*(currentAddingOffset + node->LastMatch -1)) >> \r\n          (MY_BYTE_SIZE - numLoadedBits)) ^ curByte;\r\n      while(numLoadedBits <= numSameBits)\r\n      {\r\n        if(byteXOR != 0)\r\n        {\r\n          AddInternalNode(node, nodePointerPointer, curByte, byteXOR,\r\n              numSameBits, pos);\r\n          return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n        }\r\n        *distances++ = pos - node->LastMatch - 1;\r\n        numSameBits -= numLoadedBits;\r\n        if(currentBytePointer >= bytePointerLimit)\r\n        {\r\n          for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n            node->Descendants[i].MatchPointer = pos + kMatchStartValue;\r\n          node->LastMatch = pos;\r\n          node->NumSameBits = CSameBitsType(node->NumSameBits - numSameBits);\r\n          return fullCurrentLimit;\r\n        }\r\n        numLoadedBits = MY_BYTE_SIZE; \r\n        curByte = (*currentBytePointer++);\r\n        byteXOR = curByte ^ (*(currentAddingOffset + node->LastMatch));\r\n        currentAddingOffset++;\r\n      }\r\n      if((byteXOR & ((1 << numSameBits) - 1)) != 0)\r\n      {\r\n        AddInternalNode(node, nodePointerPointer, curByte, byteXOR,\r\n            numSameBits, pos);\r\n        return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n      }\r\n      curByte >>= numSameBits;\r\n      numLoadedBits -= numSameBits;\r\n    }\r\n    UInt32 descendantIndex = (curByte & kSubNodesMask);\r\n    numLoadedBits -= kNumSubBits;\r\n    nodePointerPointer = &node->Descendants[descendantIndex].NodePointer;\r\n    UInt32 nextNodeIndex = *nodePointerPointer;\r\n    node->LastMatch = pos;\r\n    if (nextNodeIndex < kDescendantEmptyValue)\r\n    {\r\n      curByte >>= kNumSubBits;\r\n      node = &m_Nodes[nextNodeIndex];\r\n    }\r\n    else if (nextNodeIndex == kDescendantEmptyValue)\r\n    {\r\n      node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n    else \r\n      break;\r\n  }\r\n \r\n  UInt32 descendantIndex = (curByte & kSubNodesMask);\r\n  curByte >>= kNumSubBits;\r\n  CMatchPointer matchPointer = node->Descendants[descendantIndex].MatchPointer;\r\n  CMatchPointer realMatchPointer;\r\n  realMatchPointer = matchPointer - kMatchStartValue;\r\n\r\n  #ifdef __AUTO_REMOVE\r\n  if (realMatchPointer < lowPos)\r\n  {\r\n    node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n    return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n  }\r\n  #endif\r\n\r\n  Byte byteXOR;\r\n  UInt32 numSameBits = 0;\r\n  if(numLoadedBits != 0)\r\n  {\r\n    Byte matchByte = *(currentAddingOffset + realMatchPointer -1);  \r\n    matchByte >>= (MY_BYTE_SIZE - numLoadedBits);\r\n    byteXOR = matchByte ^ curByte;\r\n    if(byteXOR != 0)\r\n    {\r\n      AddLeafNode(node, curByte, byteXOR, numSameBits, pos, descendantIndex);\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n    numSameBits += numLoadedBits;\r\n  }\r\n\r\n  const Byte *matchBytePointer = _buffer + realMatchPointer + \r\n      (currentBytePointer - baseCurrentBytePointer);\r\n  for(; currentBytePointer < bytePointerLimit; numSameBits += MY_BYTE_SIZE)\r\n  {\r\n    curByte = (*currentBytePointer++);\r\n    *distances++ = pos - realMatchPointer - 1;\r\n    byteXOR = curByte ^ (*matchBytePointer++);\r\n    if(byteXOR != 0)\r\n    {\r\n      AddLeafNode(node, curByte, byteXOR, numSameBits, pos, descendantIndex);\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n  }\r\n  *distances = pos - realMatchPointer - 1;\r\n  node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n\r\n  if(*distances == 0)\r\n  {\r\n    m_SpecialMode = true;\r\n    m_NumNotChangedCycles = 0;\r\n  }\r\n  return fullCurrentLimit;\r\n}\r\n\r\nSTDMETHODIMP_(void) CPatricia::DummyLongestMatch()\r\n{\r\n  GetLongestMatch(m_TmpBacks);\r\n}\r\n\r\n\r\n// ------------------------------------\r\n// Remove Match\r\n\r\ntypedef Byte CRemoveDataWord;\r\n\r\nstatic const int kSizeRemoveDataWordInBits = MY_BYTE_SIZE * sizeof(CRemoveDataWord);\r\n\r\n#ifndef __AUTO_REMOVE\r\n\r\nvoid CPatricia::RemoveMatch()\r\n{\r\n  if(m_SpecialRemoveMode)\r\n  {\r\n    if(GetIndexByte(_matchMaxLen - 1 - _sizeHistory) ==\r\n        GetIndexByte(_matchMaxLen - _sizeHistory))\r\n      return;\r\n    m_SpecialRemoveMode = false;\r\n  }\r\n  UInt32 pos = _pos + kNumHashBytes - _sizeHistory;\r\n\r\n  #ifdef __HASH_3\r\n  const Byte *pp = _buffer + _pos - _sizeHistory;\r\n  UInt32 hash2Value = ((UInt32(pp[0])) << 8) | pp[1];\r\n  UInt32 hashValue = (hash2Value << 8) | pp[2];\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  CDescendant &hash2Descendant = m_Hash2Descendants[hash2Value];\r\n  if (hash2Descendant >= kMatchStartValue2)\r\n    if(hash2Descendant.MatchPointer == pos + kMatchStartValue2)\r\n      hash2Descendant.MatchPointer = kDescendantEmptyValue2;\r\n  #else\r\n  UInt32 hashValue = UInt32(GetIndexByte(1 - _sizeHistory))  | \r\n      (UInt32(GetIndexByte(0 - _sizeHistory)) << 8);\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  #endif\r\n    \r\n  if(hashDescendant.IsEmpty())\r\n    return;\r\n  if(hashDescendant.IsMatch())\r\n  {\r\n    if(hashDescendant.MatchPointer == pos + kMatchStartValue)\r\n      hashDescendant.MakeEmpty();\r\n    return;\r\n  }\r\n  \r\n  UInt32 descendantIndex;\r\n  const CRemoveDataWord *currentPointer = (const CRemoveDataWord *)(_buffer + pos);\r\n  UInt32 numLoadedBits = 0;\r\n  CRemoveDataWord curWord = 0; // = 0 to disable GCC warning\r\n\r\n  CIndex *nodePointerPointer = &hashDescendant.NodePointer;\r\n\r\n  CNodePointer node = &m_Nodes[hashDescendant.NodePointer];\r\n  \r\n  while(true)\r\n  {\r\n    if(numLoadedBits == 0)\r\n    {\r\n      curWord = *currentPointer++;\r\n      numLoadedBits = kSizeRemoveDataWordInBits; \r\n    }\r\n    UInt32 numSameBits = node->NumSameBits;\r\n    if(numSameBits > 0)\r\n    {\r\n      if (numLoadedBits <= numSameBits)\r\n      {\r\n        numSameBits -= numLoadedBits;\r\n        currentPointer += (numSameBits / kSizeRemoveDataWordInBits);\r\n        numSameBits %= kSizeRemoveDataWordInBits;\r\n        curWord = *currentPointer++;\r\n        numLoadedBits = kSizeRemoveDataWordInBits; \r\n      }\r\n      curWord >>= numSameBits;\r\n      numLoadedBits -= numSameBits;\r\n    }\r\n    descendantIndex = (curWord & kSubNodesMask);\r\n    numLoadedBits -= kNumSubBits;\r\n    curWord >>= kNumSubBits;\r\n    UInt32 nextNodeIndex = node->Descendants[descendantIndex].NodePointer;\r\n    if (nextNodeIndex < kDescendantEmptyValue)\r\n    {\r\n      nodePointerPointer = &node->Descendants[descendantIndex].NodePointer;\r\n      node = &m_Nodes[nextNodeIndex];\r\n    }\r\n    else\r\n      break;\r\n  }\r\n  if (node->Descendants[descendantIndex].MatchPointer != pos + kMatchStartValue)\r\n  {\r\n    const Byte *currentBytePointer = _buffer + _pos - _sizeHistory;\r\n    const Byte *currentBytePointerLimit = currentBytePointer + _matchMaxLen;\r\n    for(;currentBytePointer < currentBytePointerLimit; currentBytePointer++)\r\n      if(*currentBytePointer != *(currentBytePointer+1))\r\n        return;\r\n    m_SpecialRemoveMode = true;\r\n    return;\r\n  }\r\n\r\n  UInt32 numNodes = 0, numMatches = 0;\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    UInt32 nodeIndex = node->Descendants[i].NodePointer;\r\n    if (nodeIndex < kDescendantEmptyValue)\r\n      numNodes++;\r\n    else if (nodeIndex > kDescendantEmptyValue)\r\n      numMatches++;\r\n  }\r\n  numMatches -= 1;\r\n  if (numNodes + numMatches > 1)\r\n  {\r\n    node->Descendants[descendantIndex].MakeEmpty();\r\n    return;\r\n  }\r\n  if(numNodes == 1)\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < kNumSubNodes; i++)\r\n      if (node->Descendants[i].IsNode())\r\n        break;\r\n    UInt32 nextNodeIndex = node->Descendants[i].NodePointer;\r\n    CNodePointer nextNode = &m_Nodes[nextNodeIndex];\r\n    nextNode->NumSameBits += node->NumSameBits + kNumSubBits;\r\n    *node = *nextNode;\r\n\r\n    nextNode->NextFreeNode = m_FreeNode;\r\n    m_FreeNode = nextNodeIndex;\r\n    return;\r\n  }\r\n  UInt32 matchPointer = 0; // = 0 to disable GCC warning\r\n  for (i = 0; i < kNumSubNodes; i++)\r\n    if (node->Descendants[i].IsMatch() && i != descendantIndex)\r\n    {\r\n      matchPointer = node->Descendants[i].MatchPointer;\r\n      break;\r\n    }\r\n  node->NextFreeNode = m_FreeNode;\r\n  m_FreeNode = *nodePointerPointer;\r\n  *nodePointerPointer = matchPointer;\r\n}\r\n#endif\r\n\r\n\r\n// Commented code is more correct, but it gives warning \r\n// on GCC: (1 << 32)\r\n// So we use kMatchStartValue twice:\r\n// kMatchStartValue = UInt32(1) << (kNumBitsInIndex - 1);\r\n// must be defined in Pat.h\r\n/*\r\nconst UInt32 kNormalizeStartPos = (UInt32(1) << (kNumBitsInIndex)) - \r\n    kMatchStartValue - kNumHashBytes - 1;\r\n*/\r\nconst UInt32 kNormalizeStartPos = kMatchStartValue - kNumHashBytes - 1;\r\n\r\nSTDMETHODIMP CPatricia::MovePos()\r\n{\r\n  #ifndef __AUTO_REMOVE\r\n  if(_pos >= _sizeHistory)\r\n    RemoveMatch();\r\n  #endif\r\n  RINOK(CLZInWindow::MovePos());\r\n  #ifdef __AUTO_REMOVE\r\n  if (m_NumUsedNodes >= m_NumNodes)\r\n    TestRemoveNodes();\r\n  #endif\r\n  if (_pos >= kNormalizeStartPos)\r\n  {\r\n    #ifdef __AUTO_REMOVE\r\n    TestRemoveNodesAndNormalize();\r\n    #else\r\n    Normalize();\r\n    #endif\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifndef __AUTO_REMOVE\r\n\r\nvoid CPatricia::NormalizeDescendant(CDescendant &descendant, UInt32 subValue)\r\n{\r\n  if (descendant.IsEmpty())\r\n    return;\r\n  if (descendant.IsMatch())\r\n    descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n  else\r\n  {\r\n    CNode &node = m_Nodes[descendant.NodePointer];\r\n    node.LastMatch = node.LastMatch - subValue;\r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n       NormalizeDescendant(node.Descendants[i], subValue);\r\n  }\r\n}\r\n\r\nvoid CPatricia::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _sizeHistory;\r\n  CLZInWindow::ReduceOffsets(subValue);\r\n  \r\n  #ifdef __HASH_3\r\n\r\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\r\n  {\r\n    CDescendant &descendant = m_Hash2Descendants[hash];\r\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hash << 8;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n        NormalizeDescendant(m_HashDescendants[base + i], subValue);\r\n    }\r\n    if (descendant.MatchPointer < kMatchStartValue2)\r\n      continue;\r\n    descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n  }\r\n  \r\n  #else\r\n  \r\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\r\n    NormalizeDescendant(m_HashDescendants[hash], subValue);\r\n  \r\n  #endif\r\n\r\n}\r\n\r\n#else\r\n\r\nvoid CPatricia::TestRemoveDescendant(CDescendant &descendant, UInt32 limitPos)\r\n{\r\n  CNode &node = m_Nodes[descendant.NodePointer];\r\n  UInt32 numChilds = 0;\r\n  UInt32 childIndex = 0; // = 0 to disable GCC warning\r\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    CDescendant &descendant2 = node.Descendants[i];\r\n    if (descendant2.IsEmpty())\r\n      continue;\r\n    if (descendant2.IsMatch())\r\n    {\r\n      if (descendant2.MatchPointer < limitPos)\r\n        descendant2.MakeEmpty();\r\n      else\r\n      {\r\n        numChilds++;\r\n        childIndex = i;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      TestRemoveDescendant(descendant2, limitPos);\r\n      if (!descendant2.IsEmpty())\r\n      {\r\n        numChilds++;\r\n        childIndex = i;\r\n      }\r\n    }\r\n  }\r\n  if (numChilds > 1)\r\n    return;\r\n\r\n  CIndex nodePointerTemp = descendant.NodePointer;\r\n  if (numChilds == 1)\r\n  {\r\n    const CDescendant &descendant2 = node.Descendants[childIndex];\r\n    if (descendant2.IsNode())\r\n      m_Nodes[descendant2.NodePointer].NumSameBits += node.NumSameBits + kNumSubBits;\r\n    descendant = descendant2;\r\n  }\r\n  else\r\n    descendant.MakeEmpty();\r\n  node.NextFreeNode = m_FreeNode;\r\n  m_FreeNode = nodePointerTemp;\r\n  m_NumUsedNodes--;\r\n}\r\n\r\nvoid CPatricia::RemoveNode(UInt32 index)\r\n{\r\n  CNode &node = m_Nodes[index];\r\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    CDescendant &descendant2 = node.Descendants[i];\r\n    if (descendant2.IsNode())\r\n      RemoveNode(descendant2.NodePointer);\r\n  }\r\n  node.NextFreeNode = m_FreeNode;\r\n  m_FreeNode = index;\r\n  m_NumUsedNodes--;\r\n}\r\n\r\nvoid CPatricia::TestRemoveNodes()\r\n{\r\n  UInt32 limitPos = kMatchStartValue + _pos - _sizeHistory + kNumHashBytes;\r\n  \r\n  #ifdef __HASH_3\r\n  \r\n  UInt32 limitPos2 = kMatchStartValue2 + _pos - _sizeHistory + kNumHashBytes;\r\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\r\n  {\r\n    CDescendant &descendant = m_Hash2Descendants[hash];\r\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hash << 8;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n      {\r\n        CDescendant &descendant = m_HashDescendants[base + i];\r\n        if (descendant.IsEmpty())\r\n          continue;\r\n        if (descendant.IsMatch())\r\n        {\r\n          if (descendant.MatchPointer < limitPos)\r\n            descendant.MakeEmpty();\r\n        }\r\n        else\r\n          TestRemoveDescendant(descendant, limitPos);\r\n      }\r\n    }\r\n    if (descendant.MatchPointer < kMatchStartValue2)\r\n      continue;\r\n    if (descendant.MatchPointer < limitPos2)\r\n      descendant.MatchPointer = kDescendantEmptyValue2;\r\n  }\r\n  \r\n  #else\r\n  \r\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\r\n  {\r\n    CDescendant &descendant = m_HashDescendants[hash];\r\n    if (descendant.IsEmpty())\r\n      continue;\r\n    if (descendant.IsMatch())\r\n    {\r\n      if (descendant.MatchPointer < limitPos)\r\n        descendant.MakeEmpty();\r\n    }\r\n    else\r\n      TestRemoveDescendant(descendant, limitPos);\r\n  }\r\n  \r\n  #endif\r\n}\r\n\r\nvoid CPatricia::TestRemoveAndNormalizeDescendant(CDescendant &descendant, \r\n    UInt32 limitPos, UInt32 subValue)\r\n{\r\n  if (descendant.IsEmpty())\r\n    return;\r\n  if (descendant.IsMatch())\r\n  {\r\n    if (descendant.MatchPointer < limitPos)\r\n      descendant.MakeEmpty();\r\n    else\r\n      descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n    return;\r\n  }\r\n  CNode &node = m_Nodes[descendant.NodePointer];\r\n  UInt32 numChilds = 0;\r\n  UInt32 childIndex = 0; // = 0 to disable GCC warning\r\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    CDescendant &descendant2 = node.Descendants[i];\r\n    TestRemoveAndNormalizeDescendant(descendant2, limitPos, subValue);\r\n    if (!descendant2.IsEmpty())\r\n    {\r\n      numChilds++;\r\n      childIndex = i;\r\n    }\r\n  }\r\n  if (numChilds > 1)\r\n  {\r\n    node.LastMatch = node.LastMatch - subValue;\r\n    return;\r\n  }\r\n\r\n  CIndex nodePointerTemp = descendant.NodePointer;\r\n  if (numChilds == 1)\r\n  {\r\n    const CDescendant &descendant2 = node.Descendants[childIndex];\r\n    if (descendant2.IsNode())\r\n      m_Nodes[descendant2.NodePointer].NumSameBits += node.NumSameBits + kNumSubBits;\r\n    descendant = descendant2;\r\n  }\r\n  else\r\n    descendant.MakeEmpty();\r\n  node.NextFreeNode = m_FreeNode;\r\n  m_FreeNode = nodePointerTemp;\r\n  m_NumUsedNodes--;\r\n}\r\n\r\nvoid CPatricia::TestRemoveNodesAndNormalize()\r\n{\r\n  UInt32 subValue = _pos - _sizeHistory;\r\n  UInt32 limitPos = kMatchStartValue + _pos - _sizeHistory + kNumHashBytes;\r\n  CLZInWindow::ReduceOffsets(subValue);\r\n\r\n  #ifdef __HASH_3\r\n  \r\n  UInt32 limitPos2 = kMatchStartValue2 + _pos - _sizeHistory + kNumHashBytes;\r\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\r\n  {\r\n    CDescendant &descendant = m_Hash2Descendants[hash];\r\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hash << 8;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n        TestRemoveAndNormalizeDescendant(m_HashDescendants[base + i], limitPos, subValue);\r\n    }\r\n    if (descendant.MatchPointer < kMatchStartValue2)\r\n      continue;\r\n    if (descendant.MatchPointer < limitPos2)\r\n      descendant.MatchPointer = kDescendantEmptyValue2;\r\n    else\r\n      descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n  }\r\n  \r\n  #else\r\n\r\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\r\n    TestRemoveAndNormalizeDescendant(m_HashDescendants[hash], limitPos, subValue);\r\n\r\n  #endif\r\n}\r\n\r\n#endif\r\n\r\nSTDMETHODIMP_(Byte) CPatricia::GetIndexByte(Int32 index)\r\n{\r\n  return CLZInWindow::GetIndexByte(index);\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CPatricia::GetMatchLen(Int32 index, UInt32 back, UInt32 limit)\r\n{\r\n  return CLZInWindow::GetMatchLen(index, back, limit);\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CPatricia::GetNumAvailableBytes()\r\n{\r\n  return CLZInWindow::GetNumAvailableBytes();\r\n}\r\n\r\nSTDMETHODIMP_(const Byte *) CPatricia::GetPointerToCurrentPos()\r\n{\r\n  return CLZInWindow::GetPointerToCurrentPos();\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZ/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA/LZMA.h",
    "content": "// LZMA.h\r\n\r\n#ifndef __LZMA_H\r\n#define __LZMA_H\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst UInt32 kNumRepDistances = 4;\r\n\r\nconst int kNumStates = 12;\r\n\r\nconst Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nconst Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nconst Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nconst Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\nclass CState\r\n{\r\npublic:\r\n  Byte Index;\r\n  void Init() { Index = 0; }\r\n  void UpdateChar() { Index = kLiteralNextStates[Index]; }\r\n  void UpdateMatch() { Index = kMatchNextStates[Index]; }\r\n  void UpdateRep() { Index = kRepNextStates[Index]; }\r\n  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }\r\n  bool IsCharState() const { return Index < 7; }\r\n};\r\n\r\nconst int kNumPosSlotBits = 6; \r\nconst int kDicLogSizeMin = 0; \r\nconst int kDicLogSizeMax = 32; \r\nconst int kDistTableSizeMax = kDicLogSizeMax * 2; \r\n\r\nconst UInt32 kNumLenToPosStates = 4;\r\n\r\ninline UInt32 GetLenToPosState(UInt32 len)\r\n{\r\n  len -= 2;\r\n  if (len < kNumLenToPosStates)\r\n    return len;\r\n  return kNumLenToPosStates - 1;\r\n}\r\n\r\nnamespace NLength {\r\n\r\nconst int kNumPosStatesBitsMax = 4;\r\nconst UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\r\nconst int kNumPosStatesBitsEncodingMax = 4;\r\nconst UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\nconst int kNumLowBits = 3;\r\nconst int kNumMidBits = 3;\r\nconst int kNumHighBits = 8;\r\nconst UInt32 kNumLowSymbols = 1 << kNumLowBits;\r\nconst UInt32 kNumMidSymbols = 1 << kNumMidBits;\r\nconst UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\r\n\r\n}\r\n\r\nconst UInt32 kMatchMinLen = 2;\r\nconst UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\r\n\r\nconst int kNumAlignBits = 4;\r\nconst UInt32 kAlignTableSize = 1 << kNumAlignBits;\r\nconst UInt32 kAlignMask = (kAlignTableSize - 1);\r\n\r\nconst UInt32 kStartPosModelIndex = 4;\r\nconst UInt32 kEndPosModelIndex = 14;\r\nconst UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\nconst UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\r\nconst int kNumLitPosStatesBitsEncodingMax = 4;\r\nconst int kNumLitContextBitsMax = 8;\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA/LZMADecoder.cpp",
    "content": "// LZMADecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\n#include \"../../../Common/Defs.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kLenIdFinished = -1;\r\nconst int kLenIdNeedInit = -2;\r\n\r\nvoid CDecoder::Init()\r\n{\r\n  { \r\n    for(int i = 0; i < kNumStates; i++)\r\n    {\r\n      for (UInt32 j = 0; j <= _posStateMask; j++)\r\n      {\r\n        _isMatch[i][j].Init();\r\n        _isRep0Long[i][j].Init();\r\n      }\r\n      _isRep[i].Init();\r\n      _isRepG0[i].Init();\r\n      _isRepG1[i].Init();\r\n      _isRepG2[i].Init();\r\n    }\r\n  }\r\n  { \r\n    for (UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n    _posSlotDecoder[i].Init();\r\n  }\r\n  { \r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posDecoders[i].Init();\r\n  }\r\n  _posAlignDecoder.Init();\r\n  _lenDecoder.Init(_posStateMask + 1);\r\n  _repMatchLenDecoder.Init(_posStateMask + 1);\r\n  _literalDecoder.Init();\r\n\r\n  _state.Init();\r\n  _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0;\r\n}\r\n\r\nHRESULT CDecoder::CodeSpec(UInt32 curSize)\r\n{\r\n  if (_outSizeDefined)\r\n  {\r\n    const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize();\r\n    if (curSize > rem)\r\n      curSize = (UInt32)rem;\r\n  }\r\n\r\n  if (_remainLen == kLenIdFinished)\r\n    return S_OK;\r\n  if (_remainLen == kLenIdNeedInit)\r\n  {\r\n    _rangeDecoder.Init();\r\n    Init();\r\n    _remainLen = 0;\r\n  }\r\n  if (curSize == 0)\r\n    return S_OK;\r\n\r\n  UInt32 rep0 = _reps[0];\r\n  UInt32 rep1 = _reps[1];\r\n  UInt32 rep2 = _reps[2];\r\n  UInt32 rep3 = _reps[3];\r\n  CState state = _state;\r\n  Byte previousByte;\r\n\r\n  while(_remainLen > 0 && curSize > 0)\r\n  {\r\n    previousByte = _outWindowStream.GetByte(rep0);\r\n    _outWindowStream.PutByte(previousByte);\r\n    _remainLen--;\r\n    curSize--;\r\n  }\r\n  UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n  if (nowPos64 == 0)\r\n    previousByte = 0;\r\n  else\r\n    previousByte = _outWindowStream.GetByte(0);\r\n\r\n  while(curSize > 0)\r\n  {\r\n    {\r\n      #ifdef _NO_EXCEPTIONS\r\n      if (_rangeDecoder.Stream.ErrorCode != S_OK)\r\n        return _rangeDecoder.Stream.ErrorCode;\r\n      #endif\r\n      if (_rangeDecoder.Stream.WasFinished())\r\n        return S_FALSE;\r\n      UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n      if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n      {\r\n        if(!state.IsCharState())\r\n          previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte, _outWindowStream.GetByte(rep0));\r\n        else\r\n          previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte);\r\n        _outWindowStream.PutByte(previousByte);\r\n        state.UpdateChar();\r\n        curSize--;\r\n        nowPos64++;\r\n      }\r\n      else             \r\n      {\r\n        UInt32 len;\r\n        if(_isRep[state.Index].Decode(&_rangeDecoder) == 1)\r\n        {\r\n          len = 0;\r\n          if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0)\r\n          {\r\n            if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n            {\r\n              state.UpdateShortRep();\r\n              len = 1;\r\n            }\r\n          }\r\n          else\r\n          {\r\n            UInt32 distance;\r\n            if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0)\r\n              distance = rep1;\r\n            else \r\n            {\r\n              if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0)\r\n                distance = rep2;\r\n              else\r\n              {\r\n                distance = rep3;\r\n                rep3 = rep2;\r\n              }\r\n              rep2 = rep1;\r\n            }\r\n            rep1 = rep0;\r\n            rep0 = distance;\r\n          }\r\n          if (len == 0)\r\n          {\r\n            len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;\r\n            state.UpdateRep();\r\n          }\r\n        }\r\n        else\r\n        {\r\n          rep3 = rep2;\r\n          rep2 = rep1;\r\n          rep1 = rep0;\r\n          len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);\r\n          state.UpdateMatch();\r\n          UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);\r\n          if (posSlot >= kStartPosModelIndex)\r\n          {\r\n            UInt32 numDirectBits = (posSlot >> 1) - 1;\r\n            rep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\r\n            if (posSlot < kEndPosModelIndex)\r\n              rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders + \r\n                  rep0 - posSlot - 1, &_rangeDecoder, numDirectBits);\r\n            else\r\n            {\r\n              rep0 += (_rangeDecoder.DecodeDirectBits(\r\n                  numDirectBits - kNumAlignBits) << kNumAlignBits);\r\n              rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder);\r\n              if (rep0 == 0xFFFFFFFF)\r\n              {\r\n                _remainLen = kLenIdFinished;\r\n                return S_OK;\r\n              }\r\n            }\r\n          }\r\n          else\r\n            rep0 = posSlot;\r\n        }\r\n        UInt32 locLen = len;\r\n        if (len > curSize)\r\n          locLen = (UInt32)curSize;\r\n        if (!_outWindowStream.CopyBlock(rep0, locLen))\r\n          return S_FALSE;\r\n        previousByte = _outWindowStream.GetByte(0);\r\n        curSize -= locLen;\r\n        nowPos64 += locLen;\r\n        len -= locLen;\r\n        if (len != 0)\r\n        {\r\n          _remainLen = (Int32)len;\r\n          break;\r\n        }\r\n\r\n        #ifdef _NO_EXCEPTIONS\r\n        if (_outWindowStream.ErrorCode != S_OK)\r\n          return _outWindowStream.ErrorCode;\r\n        #endif\r\n      }\r\n    }\r\n  }\r\n  if (_rangeDecoder.Stream.WasFinished())\r\n    return S_FALSE;\r\n  _reps[0] = rep0;\r\n  _reps[1] = rep1;\r\n  _reps[2] = rep2;\r\n  _reps[3] = rep3;\r\n  _state = state;\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 *, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  SetInStream(inStream);\r\n  _outWindowStream.SetStream(outStream);\r\n  SetOutStreamSize(outSize);\r\n  CDecoderFlusher flusher(this);\r\n\r\n  while (true)\r\n  {\r\n    UInt32 curSize = 1 << 18;\r\n    RINOK(CodeSpec(curSize));\r\n    if (_remainLen == kLenIdFinished)\r\n      break;\r\n    if (progress != NULL)\r\n    {\r\n      UInt64 inSize = _rangeDecoder.GetProcessedSize();\r\n      UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(&inSize, &nowPos64));\r\n    }\r\n    if (_outSizeDefined)\r\n      if (_outWindowStream.GetProcessedSize() >= _outSize)\r\n        break;\r\n  } \r\n  flusher.NeedFlush = false;\r\n  return Flush();\r\n}\r\n\r\n\r\n#ifdef _NO_EXCEPTIONS\r\n\r\n#define LZMA_TRY_BEGIN\r\n#define LZMA_TRY_END\r\n\r\n#else\r\n\r\n#define LZMA_TRY_BEGIN try { \r\n#define LZMA_TRY_END } \\\r\n  catch(const CInBufferException &e)  { return e.ErrorCode; } \\\r\n  catch(const CLZOutWindowException &e)  { return e.ErrorCode; } \\\r\n  catch(...) { return S_FALSE; }\r\n\r\n#endif\r\n\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  LZMA_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size)\r\n{\r\n  if (size < 5)\r\n    return E_INVALIDARG;\r\n  int lc = properties[0] % 9;\r\n  Byte remainder = (Byte)(properties[0] / 9);\r\n  int lp = remainder % 5;\r\n  int pb = remainder / 5;\r\n  UInt32 dictionarySize = 0;\r\n  for (int i = 0; i < 4; i++)\r\n    dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n  return SetDecoderPropertiesRaw(lc, lp, pb, dictionarySize);\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderPropertiesRaw(int lc, int lp, int pb, UInt32 dictionarySize)\r\n{\r\n  if (pb > NLength::kNumPosStatesBitsMax)\r\n    return E_INVALIDARG;\r\n  _posStateMask = (1 << pb) - 1;\r\n  if (!_outWindowStream.Create(dictionarySize))\r\n    return E_OUTOFMEMORY;\r\n  if (!_literalDecoder.Create(lp, lc))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = _rangeDecoder.GetProcessedSize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _rangeDecoder.SetStream(inStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::ReleaseInStream()\r\n{\r\n  _rangeDecoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  if (_outSizeDefined = (outSize != NULL))\r\n    _outSize = *outSize;\r\n  _remainLen = kLenIdNeedInit;\r\n  _outWindowStream.Init();\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _ST_MODE\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  const UInt64 startPos = _outWindowStream.GetProcessedSize();\r\n  _outWindowStream.SetMemStream((Byte *)data);\r\n  RINOK(CodeSpec(size));\r\n  if (processedSize)\r\n    *processedSize = (UInt32)(_outWindowStream.GetProcessedSize() - startPos);\r\n  return Flush();\r\n  LZMA_TRY_END\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA/LZMADecoder.h",
    "content": "// LZMA/Decoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/LZOutWindow.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;\r\n\r\nclass CLiteralDecoder2\r\n{\r\n  CMyBitDecoder _decoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _decoders[i].Init();\r\n  }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n      RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, Byte matchByte)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      UInt32 matchBit = (matchByte >> 7) & 1;\r\n      matchByte <<= 1;\r\n      // UInt32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);\r\n      // symbol = (symbol << 1) | bit;\r\n      UInt32 bit;\r\n      RC_GETBIT2(kNumMoveBits, _decoders[0x100 + (matchBit << 8) + symbol].Prob, symbol, \r\n          bit = 0, bit = 1)\r\n      if (matchBit != bit)\r\n      {\r\n        while (symbol < 0x100)\r\n        {\r\n          // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n          RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n        }\r\n        break;\r\n      }\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n};\r\n\r\nclass CLiteralDecoder\r\n{\r\n  CLiteralDecoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralDecoder(): _coders(0) {}\r\n  ~CLiteralDecoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte, Byte matchByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CDecoder\r\n{\r\n  CMyBitDecoder _choice;\r\n  CMyBitDecoder _choice2;\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder; \r\npublic:\r\n  void Init(UInt32 numPosStates)\r\n  {\r\n    _choice.Init();\r\n    _choice2.Init();\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n    {\r\n      _lowCoder[posState].Init();\r\n      _midCoder[posState].Init();\r\n    }\r\n    _highCoder.Init();\r\n  }\r\n  UInt32 Decode(NRangeCoder::CDecoder *rangeDecoder, UInt32 posState)\r\n  {\r\n    if(_choice.Decode(rangeDecoder) == 0)\r\n      return _lowCoder[posState].Decode(rangeDecoder);\r\n    if(_choice2.Decode(rangeDecoder) == 0)\r\n      return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);\r\n    return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CDecoder: \r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CLZOutWindow _outWindowStream;\r\n  NRangeCoder::CDecoder _rangeDecoder;\r\n\r\n  CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax];\r\n  CMyBitDecoder _isRep[kNumStates];\r\n  CMyBitDecoder _isRepG0[kNumStates];\r\n  CMyBitDecoder _isRepG1[kNumStates];\r\n  CMyBitDecoder _isRepG2[kNumStates];\r\n  CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax];\r\n\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];\r\n\r\n  CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;\r\n  \r\n  NLength::CDecoder _lenDecoder;\r\n  NLength::CDecoder _repMatchLenDecoder;\r\n\r\n  CLiteralDecoder _literalDecoder;\r\n\r\n  UInt32 _posStateMask;\r\n\r\n  ///////////////////\r\n  // State\r\n  UInt32 _reps[4];\r\n  CState _state;\r\n  Int32 _remainLen; // -1 means end of stream. // -2 means need Init\r\n  UInt64 _outSize;\r\n  bool _outSizeDefined;\r\n\r\n  void Init();\r\n  HRESULT CodeSpec(UInt32 size);\r\npublic:\r\n\r\n  #ifdef _ST_MODE\r\n  MY_UNKNOWN_IMP4(\r\n      ICompressSetDecoderProperties2, \r\n      ICompressSetInStream, \r\n      ICompressSetOutStreamSize, \r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP1(\r\n      ICompressSetDecoderProperties2)\r\n  #endif\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _outWindowStream.ReleaseStream();\r\n    ReleaseInStream();\r\n  }\r\n\r\n  class CDecoderFlusher\r\n  {\r\n    CDecoder *_decoder;\r\n  public:\r\n    bool NeedFlush;\r\n    CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}\r\n    ~CDecoderFlusher() \r\n    { \r\n      if (NeedFlush)\r\n        _decoder->Flush();\r\n      _decoder->ReleaseStreams(); \r\n    }\r\n  };\r\n\r\n  HRESULT Flush() {  return _outWindowStream.Flush(); }  \r\n\r\n  STDMETHOD(CodeReal)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  \r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n  STDMETHOD(SetDecoderPropertiesRaw)(int lc, int lp, int pb, UInt32 dictionarySize);\r\n\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifdef _ST_MODE\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  CDecoder(): _outSizeDefined(false) {}\r\n  virtual ~CDecoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA/LZMAEncoder.cpp",
    "content": "// LZMA/Encoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/Defs.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"LZMAEncoder.h\"\r\n\r\n// for minimal compressing code size define these:\r\n// #define COMPRESS_MF_BT\r\n// #define COMPRESS_MF_BT4\r\n\r\n#if !defined(COMPRESS_MF_BT) && !defined(COMPRESS_MF_PAT) && !defined(COMPRESS_MF_HC)\r\n#define COMPRESS_MF_BT\r\n#define COMPRESS_MF_PAT\r\n#define COMPRESS_MF_HC\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_BT\r\n#if !defined(COMPRESS_MF_BT2) && !defined(COMPRESS_MF_BT3) && !defined(COMPRESS_MF_BT4) && !defined(COMPRESS_MF_BT4B)\r\n#define COMPRESS_MF_BT2\r\n#define COMPRESS_MF_BT3\r\n#define COMPRESS_MF_BT4\r\n#define COMPRESS_MF_BT4B\r\n#endif\r\n#ifdef COMPRESS_MF_BT2\r\n#include \"../LZ/BinTree/BinTree2.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT3\r\n#include \"../LZ/BinTree/BinTree3.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT4\r\n#include \"../LZ/BinTree/BinTree4.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT4B\r\n#include \"../LZ/BinTree/BinTree4b.h\"\r\n#endif\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_PAT\r\n#include \"../LZ/Patricia/Pat2.h\"\r\n#include \"../LZ/Patricia/Pat2H.h\"\r\n#include \"../LZ/Patricia/Pat3H.h\"\r\n#include \"../LZ/Patricia/Pat4H.h\"\r\n#include \"../LZ/Patricia/Pat2R.h\"\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_HC\r\n#include \"../LZ/HashChain/HC3.h\"\r\n#include \"../LZ/HashChain/HC4.h\"\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../LZ/MT/MT.h\"\r\n#endif\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kDefaultDictionaryLogSize = 20;\r\nconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\nenum \r\n{\r\n  kBT2,\r\n  kBT3,\r\n  kBT4,\r\n  kBT4B,\r\n  kPat2,\r\n  kPat2H,\r\n  kPat3H,\r\n  kPat4H,\r\n  kPat2R,\r\n  kHC3,\r\n  kHC4\r\n};\r\n\r\nstatic const wchar_t *kMatchFinderIDs[] = \r\n{\r\n  L\"BT2\",\r\n  L\"BT3\",\r\n  L\"BT4\",\r\n  L\"BT4B\",\r\n  L\"PAT2\",\r\n  L\"PAT2H\",\r\n  L\"PAT3H\",\r\n  L\"PAT4H\",\r\n  L\"PAT2R\",\r\n  L\"HC3\",\r\n  L\"HC4\"\r\n};\r\n\r\nByte g_FastPos[1024];\r\n\r\nclass CFastPosInit\r\n{\r\npublic:\r\n  CFastPosInit() { Init(); }\r\n  void Init()\r\n  {\r\n    const Byte kFastSlots = 20;\r\n    int c = 2;\r\n    g_FastPos[0] = 0;\r\n    g_FastPos[1] = 1;\r\n\r\n    for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n    {\r\n      UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n      for (UInt32 j = 0; j < k; j++, c++)\r\n        g_FastPos[c] = slotFast;\r\n    }\r\n  }\r\n} g_FastPosInit;\r\n\r\n\r\nvoid CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    _encoders[context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nvoid CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, \r\n    Byte matchByte, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    UInt32 matchBit = (matchByte >> i) & 1;\r\n    _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n    if (matchBit != bit)\r\n    {\r\n      while(i != 0)\r\n      {\r\n        i--;\r\n        UInt32 bit = (symbol >> i) & 1;\r\n        _encoders[context].Encode(rangeEncoder, bit);\r\n        context = (context << 1) | bit;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nUInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  if (matchMode)\r\n  {\r\n    do \r\n    {\r\n      i--;\r\n      UInt32 matchBit = (matchByte >> i) & 1;\r\n      UInt32 bit = (symbol >> i) & 1;\r\n      price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit);\r\n      context = (context << 1) | bit;\r\n      if (matchBit != bit)\r\n        break;\r\n    }\r\n    while (i != 0);\r\n  }\r\n  while(i != 0)\r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    price += _encoders[context].GetPrice(bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  return price;\r\n};\r\n\r\n\r\nnamespace NLength {\r\n\r\nvoid CEncoder::Init(UInt32 numPosStates)\r\n{\r\n  _choice.Init();\r\n  _choice2.Init();\r\n  for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n  {\r\n    _lowCoder[posState].Init();\r\n    _midCoder[posState].Init();\r\n  }\r\n  _highCoder.Init();\r\n}\r\n\r\nvoid CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n  {\r\n    _choice.Encode(rangeEncoder, 0);\r\n    _lowCoder[posState].Encode(rangeEncoder, symbol);\r\n  }\r\n  else\r\n  {\r\n    _choice.Encode(rangeEncoder, 1);\r\n    if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n    {\r\n      _choice2.Encode(rangeEncoder, 0);\r\n      _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      _choice2.Encode(rangeEncoder, 1);\r\n      _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 CEncoder::GetPrice(UInt32 symbol, UInt32 posState) const\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n    return _choice.GetPrice0() + _lowCoder[posState].GetPrice(symbol);\r\n  UInt32 price = _choice.GetPrice1();\r\n  if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n  {\r\n    price += _choice2.GetPrice0();\r\n    price += _midCoder[posState].GetPrice(symbol - kNumLowSymbols);\r\n  }\r\n  else\r\n  {\r\n    price += _choice2.GetPrice1();\r\n    price += _highCoder.GetPrice(symbol - kNumLowSymbols - kNumMidSymbols);\r\n  }\r\n  return price;\r\n}\r\n\r\n}\r\nCEncoder::CEncoder():\r\n  _numFastBytes(kNumFastBytesDefault),\r\n  _distTableSize(kDefaultDictionaryLogSize * 2),\r\n  _posStateBits(2),\r\n  _posStateMask(4 - 1),\r\n  _numLiteralPosStateBits(0),\r\n  _numLiteralContextBits(3),\r\n  _dictionarySize(1 << kDefaultDictionaryLogSize),\r\n  _dictionarySizePrev(UInt32(-1)),\r\n  _numFastBytesPrev(UInt32(-1)),\r\n  _matchFinderIndex(kBT4),\r\n   #ifdef COMPRESS_MF_MT\r\n  _multiThread(false),\r\n   #endif\r\n  _writeEndMark(false)\r\n{\r\n  _maxMode = false;\r\n  _fastMode = false;\r\n}\r\n\r\nHRESULT CEncoder::Create()\r\n{\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_matchFinder)\r\n  {\r\n    switch(_matchFinderIndex)\r\n    {\r\n      #ifdef COMPRESS_MF_BT\r\n      #ifdef COMPRESS_MF_BT2\r\n      case kBT2:\r\n        _matchFinder = new NBT2::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT3\r\n      case kBT3:\r\n        _matchFinder = new NBT3::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT4\r\n      case kBT4:\r\n        _matchFinder = new NBT4::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT4B\r\n      case kBT4B:\r\n        _matchFinder = new NBT4B::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #endif\r\n      \r\n      #ifdef COMPRESS_MF_PAT\r\n      case kPat2:\r\n        _matchFinder = new NPat2::CPatricia;\r\n        break;\r\n      case kPat2H:\r\n        _matchFinder = new NPat2H::CPatricia;\r\n        break;\r\n      case kPat3H:\r\n        _matchFinder = new NPat3H::CPatricia;\r\n        break;\r\n      case kPat4H:\r\n        _matchFinder = new NPat4H::CPatricia;\r\n        break;\r\n      case kPat2R:\r\n        _matchFinder = new NPat2R::CPatricia;\r\n        break;\r\n      #endif\r\n\r\n      #ifdef COMPRESS_MF_HC\r\n      case kHC3:\r\n        _matchFinder = new NHC3::CMatchFinderHC;\r\n        break;\r\n      case kHC4:\r\n        _matchFinder = new NHC4::CMatchFinderHC;\r\n        break;\r\n      #endif\r\n    }\r\n    if (_matchFinder == 0)\r\n      return E_OUTOFMEMORY;\r\n\r\n    #ifdef COMPRESS_MF_MT\r\n    if (_multiThread && !(_fastMode && (_matchFinderIndex == kHC3 || _matchFinderIndex == kHC4)))\r\n    {\r\n      CMatchFinderMT *mfSpec = new CMatchFinderMT;\r\n      if (mfSpec == 0)\r\n        return E_OUTOFMEMORY;\r\n      CMyComPtr<IMatchFinder> mf = mfSpec;\r\n      RINOK(mfSpec->SetMatchFinder(_matchFinder));\r\n      _matchFinder.Release();\r\n      _matchFinder = mf;\r\n    }\r\n    #endif\r\n  }\r\n  \r\n  if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))\r\n    return E_OUTOFMEMORY;\r\n\r\n  if (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n    return S_OK;\r\n  RINOK(_matchFinder->Create(_dictionarySize, kNumOpts, _numFastBytes, \r\n      kMatchMaxLen * 2 + 1 - _numFastBytes));\r\n  _dictionarySizePrev = _dictionarySize;\r\n  _numFastBytesPrev = _numFastBytes;\r\n  return S_OK;\r\n}\r\n\r\nstatic bool AreStringsEqual(const wchar_t *base, const wchar_t *testString)\r\n{\r\n  while (true)\r\n  {\r\n    wchar_t c = *testString;\r\n    if (c >= 'a' && c <= 'z')\r\n      c -= 0x20;\r\n    if (*base != c)\r\n      return false;\r\n    if (c == 0)\r\n      return true;\r\n    base++;\r\n    testString++;\r\n  }\r\n}\r\n\r\nstatic int FindMatchFinder(const wchar_t *s)\r\n{\r\n  for (int m = 0; m < (int)(sizeof(kMatchFinderIDs) / sizeof(kMatchFinderIDs[0])); m++)\r\n    if (AreStringsEqual(kMatchFinderIDs[m], s))\r\n      return m;\r\n  return -1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, \r\n    const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  for (UInt32 i = 0; i < numProperties; i++)\r\n  {\r\n    const PROPVARIANT &prop = properties[i];\r\n    switch(propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 numFastBytes = prop.ulVal;\r\n        if(numFastBytes < 5 || numFastBytes > kMatchMaxLen)\r\n          return E_INVALIDARG;\r\n        _numFastBytes = numFastBytes;\r\n        break;\r\n      }\r\n      case NCoderPropID::kAlgorithm:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 maximize = prop.ulVal;\r\n        _fastMode = (maximize == 0); \r\n        _maxMode = (maximize >= 2);\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinder:\r\n      {\r\n        if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        int matchFinderIndexPrev = _matchFinderIndex;\r\n        int m = FindMatchFinder(prop.bstrVal);\r\n        if (m < 0)\r\n          return E_INVALIDARG;\r\n        _matchFinderIndex = m;\r\n        if (_matchFinder && matchFinderIndexPrev != _matchFinderIndex)\r\n        {\r\n          _dictionarySizePrev = UInt32(-1);\r\n          _matchFinder.Release();\r\n        }\r\n        break;\r\n      }\r\n      #ifdef COMPRESS_MF_MT\r\n      case NCoderPropID::kMultiThread:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        bool newMultiThread = (prop.boolVal == VARIANT_TRUE);\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          _dictionarySizePrev = UInt32(-1);\r\n          _matchFinder.Release();\r\n        }\r\n        _multiThread = newMultiThread;\r\n        break;\r\n      }\r\n      #endif\r\n      case NCoderPropID::kDictionarySize:\r\n      {\r\n        const int kDicLogSizeMaxCompress = 28;\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 dictionarySize = prop.ulVal;\r\n        if (dictionarySize < UInt32(1 << kDicLogSizeMin) ||\r\n            dictionarySize > UInt32(1 << kDicLogSizeMaxCompress))\r\n          return E_INVALIDARG;\r\n        _dictionarySize = dictionarySize;\r\n        UInt32 dicLogSize;\r\n        for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n          if (dictionarySize <= (UInt32(1) << dicLogSize))\r\n            break;\r\n        _distTableSize = dicLogSize * 2;\r\n        break;\r\n      }\r\n      case NCoderPropID::kPosStateBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _posStateBits = value;\r\n        _posStateMask = (1 << _posStateBits) - 1;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitPosBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralPosStateBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitContextBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitContextBitsMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralContextBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kEndMarker:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE);\r\n        break;\r\n      }\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{ \r\n  const UInt32 kPropSize = 5;\r\n  Byte properties[kPropSize];\r\n  properties[0] = (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits;\r\n  for (int i = 0; i < 4; i++)\r\n    properties[1 + i] = Byte(_dictionarySize >> (8 * i));\r\n  return WriteStream(outStream, properties, kPropSize, NULL);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _rangeEncoder.SetStream(outStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _rangeEncoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Init()\r\n{\r\n  CBaseState::Init();\r\n\r\n  // RINOK(_matchFinder->Init(inStream));\r\n  _rangeEncoder.Init();\r\n\r\n  for(int i = 0; i < kNumStates; i++)\r\n  {\r\n    for (UInt32 j = 0; j <= _posStateMask; j++)\r\n    {\r\n      _isMatch[i][j].Init();\r\n      _isRep0Long[i][j].Init();\r\n    }\r\n    _isRep[i].Init();\r\n    _isRepG0[i].Init();\r\n    _isRepG1[i].Init();\r\n    _isRepG2[i].Init();\r\n  }\r\n\r\n  _literalEncoder.Init();\r\n\r\n  // _repMatchLenEncoder.Init();\r\n  \r\n  {\r\n    for(UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n      _posSlotEncoder[i].Init();\r\n  }\r\n  {\r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posEncoders[i].Init();\r\n  }\r\n\r\n  _lenEncoder.Init(1 << _posStateBits);\r\n  _repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n  _posAlignEncoder.Init();\r\n\r\n  _longestMatchWasFound = false;\r\n  _optimumEndIndex = 0;\r\n  _optimumCurrentIndex = 0;\r\n  _additionalOffset = 0;\r\n\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::MovePos(UInt32 num)\r\n{\r\n  for (;num != 0; num--)\r\n  {\r\n    _matchFinder->DummyLongestMatch();\r\n    RINOK(_matchFinder->MovePos());\r\n    _additionalOffset++;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nUInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)\r\n{\r\n  _optimumEndIndex = cur;\r\n  UInt32 posMem = _optimum[cur].PosPrev;\r\n  UInt32 backMem = _optimum[cur].BackPrev;\r\n  do\r\n  {\r\n    if (_optimum[cur].Prev1IsChar)\r\n    {\r\n      _optimum[posMem].MakeAsChar();\r\n      _optimum[posMem].PosPrev = posMem - 1;\r\n      if (_optimum[cur].Prev2)\r\n      {\r\n        _optimum[posMem - 1].Prev1IsChar = false;\r\n        _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n        _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n      }\r\n    }\r\n    UInt32 posPrev = posMem;\r\n    UInt32 backCur = backMem;\r\n\r\n    backMem = _optimum[posPrev].BackPrev;\r\n    posMem = _optimum[posPrev].PosPrev;\r\n\r\n    _optimum[posPrev].BackPrev = backCur;\r\n    _optimum[posPrev].PosPrev = cur;\r\n    cur = posPrev;\r\n  }\r\n  while(cur != 0);\r\n  backRes = _optimum[0].BackPrev;\r\n  _optimumCurrentIndex  = _optimum[0].PosPrev;\r\n  return _optimumCurrentIndex; \r\n}\r\n\r\n/*\r\ninline UInt32 GetMatchLen(const Byte *data, UInt32 back, UInt32 limit)\r\n{  \r\n  back++;\r\n  for(UInt32 i = 0; i < limit && data[i] == data[i - back]; i++);\r\n  return i;\r\n}\r\n*/\r\n\r\n\r\n/*\r\nOut:\r\n  (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal\r\n*/\r\n\r\nHRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\r\n{\r\n  if(_optimumEndIndex != _optimumCurrentIndex)\r\n  {\r\n    const COptimal &optimum = _optimum[_optimumCurrentIndex];\r\n    lenRes = optimum.PosPrev - _optimumCurrentIndex;\r\n    backRes = optimum.BackPrev;\r\n    _optimumCurrentIndex = optimum.PosPrev;\r\n    return S_OK;\r\n  }\r\n  _optimumCurrentIndex = 0;\r\n  _optimumEndIndex = 0; // test it;\r\n  \r\n  UInt32 lenMain;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    RINOK(ReadMatchDistances(lenMain));\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n\r\n  UInt32 reps[kNumRepDistances];\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  UInt32 i;\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    reps[i] = _repDistances[i];\r\n    repLens[i] = _matchFinder->GetMatchLen(0 - 1, reps[i], kMatchMaxLen);\r\n    if (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    return MovePos(lenRes - 1);\r\n  }\r\n\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = _matchDistances[_numFastBytes] + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 1);\r\n  }\r\n  Byte currentByte = _matchFinder->GetIndexByte(0 - 1);\r\n\r\n  _optimum[0].State = _state;\r\n\r\n  Byte matchByte;\r\n  \r\n  matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n  UInt32 posState = (position & _posStateMask);\r\n\r\n  _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() + \r\n      _literalEncoder.GetPrice(position, _previousByte, !_state.IsCharState(), matchByte, currentByte);\r\n  _optimum[1].MakeAsChar();\r\n\r\n  _optimum[1].PosPrev = 0;\r\n\r\n  for (i = 0; i < kNumRepDistances; i++)\r\n    _optimum[0].Backs[i] = reps[i];\r\n\r\n  UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1();\r\n  UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n  if(matchByte == currentByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n    if(shortRepPrice < _optimum[1].Price)\r\n    {\r\n      _optimum[1].Price = shortRepPrice;\r\n      _optimum[1].MakeAsShortRep();\r\n    }\r\n  }\r\n  if(lenMain < 2)\r\n  {\r\n    backRes = _optimum[1].BackPrev;\r\n    lenRes = 1;\r\n    return S_OK;\r\n  }\r\n\r\n  \r\n  UInt32 normalMatchPrice = matchPrice + \r\n      _isRep[_state.Index].GetPrice0();\r\n\r\n  if (lenMain <= repLens[repMaxIndex])\r\n    lenMain = 0;\r\n\r\n  UInt32 len;\r\n  for(len = 2; len <= lenMain; len++)\r\n  {\r\n    _optimum[len].PosPrev = 0;\r\n    _optimum[len].BackPrev = _matchDistances[len] + kNumRepDistances;\r\n    _optimum[len].Price = normalMatchPrice + \r\n        GetPosLenPrice(_matchDistances[len], len, posState);\r\n    _optimum[len].Prev1IsChar = false;\r\n  }\r\n\r\n  if (lenMain < repLens[repMaxIndex])\r\n    lenMain = repLens[repMaxIndex];\r\n\r\n  for (; len <= lenMain; len++)\r\n    _optimum[len].Price = kIfinityPrice;\r\n\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    for(UInt32 lenTest = 2; lenTest <= repLen; lenTest++)\r\n    {\r\n      UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\r\n      COptimal &optimum = _optimum[lenTest];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = i;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n    }\r\n  }\r\n\r\n  UInt32 cur = 0;\r\n  UInt32 lenEnd = lenMain;\r\n\r\n  while(true)\r\n  {\r\n    cur++;\r\n    if(cur == lenEnd)\r\n    {\r\n      lenRes = Backward(backRes, cur);\r\n      return S_OK;\r\n    }\r\n    position++;\r\n    COptimal &curOptimum = _optimum[cur];\r\n    UInt32 posPrev = curOptimum.PosPrev;\r\n    CState state;\r\n    if (curOptimum.Prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOptimum.Prev2)\r\n      {\r\n        state = _optimum[curOptimum.PosPrev2].State;\r\n        if (curOptimum.BackPrev2 < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      else\r\n        state = _optimum[posPrev].State;\r\n      state.UpdateChar();\r\n    }\r\n    else\r\n      state = _optimum[posPrev].State;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (curOptimum.IsShortRep())\r\n        state.UpdateShortRep();\r\n      else\r\n        state.UpdateChar();\r\n      /*\r\n      if (curOptimum.Prev1IsChar)\r\n        for(int i = 0; i < kNumRepDistances; i++)\r\n          reps[i] = _optimum[posPrev].Backs[i];\r\n      */\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      if (curOptimum.Prev1IsChar && curOptimum.Prev2)\r\n      {\r\n        posPrev = curOptimum.PosPrev2;\r\n        pos = curOptimum.BackPrev2;\r\n        state.UpdateRep();\r\n      }\r\n      else\r\n      {\r\n        pos = curOptimum.BackPrev;\r\n        if (pos < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      const COptimal &prevOptimum = _optimum[posPrev];\r\n      if (pos < kNumRepDistances)\r\n      {\r\n        reps[0] = prevOptimum.Backs[pos];\r\n    \t\tUInt32 i;\r\n        for(i = 1; i <= pos; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n        for(; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i];\r\n      }\r\n      else\r\n      {\r\n        reps[0] = (pos - kNumRepDistances);\r\n        for(UInt32 i = 1; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n      }\r\n    }\r\n    curOptimum.State = state;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n      curOptimum.Backs[i] = reps[i];\r\n    UInt32 newLen;\r\n    RINOK(ReadMatchDistances(newLen));\r\n    if(newLen >= _numFastBytes)\r\n    {\r\n      _longestMatchLength = newLen;\r\n      _longestMatchWasFound = true;\r\n      lenRes = Backward(backRes, cur);\r\n      return S_OK;\r\n    }\r\n    UInt32 curPrice = curOptimum.Price; \r\n    // Byte currentByte  = _matchFinder->GetIndexByte(0 - 1);\r\n    // Byte matchByte = _matchFinder->GetIndexByte(0 - reps[0] - 1 - 1);\r\n    const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;\r\n    Byte currentByte = *data;\r\n    Byte matchByte = data[(size_t)0 - reps[0] - 1];\r\n\r\n    UInt32 posState = (position & _posStateMask);\r\n\r\n    UInt32 curAnd1Price = curPrice +\r\n        _isMatch[state.Index][posState].GetPrice0() +\r\n        _literalEncoder.GetPrice(position, data[(size_t)0 - 1], !state.IsCharState(), matchByte, currentByte);\r\n\r\n    COptimal &nextOptimum = _optimum[cur + 1];\r\n\r\n    bool nextIsChar = false;\r\n    if (curAnd1Price < nextOptimum.Price) \r\n    {\r\n      nextOptimum.Price = curAnd1Price;\r\n      nextOptimum.PosPrev = cur;\r\n      nextOptimum.MakeAsChar();\r\n      nextIsChar = true;\r\n    }\r\n\r\n    UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();\r\n    UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n    \r\n    if(matchByte == currentByte &&\r\n        !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n      if(shortRepPrice <= nextOptimum.Price)\r\n      {\r\n        nextOptimum.Price = shortRepPrice;\r\n        nextOptimum.PosPrev = cur;\r\n        nextOptimum.MakeAsShortRep();\r\n        // nextIsChar = false;\r\n      }\r\n    }\r\n    /*\r\n    if(newLen == 2 && _matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n      continue;\r\n    */\r\n\r\n    UInt32 numAvailableBytesFull = _matchFinder->GetNumAvailableBytes() + 1;\r\n    numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n    UInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n    if (numAvailableBytes < 2)\r\n      continue;\r\n    if (numAvailableBytes > _numFastBytes)\r\n      numAvailableBytes = _numFastBytes;\r\n    if (numAvailableBytes >= 3 && !nextIsChar)\r\n    {\r\n      // try Literal + rep0\r\n      UInt32 backOffset = reps[0] + 1;\r\n      UInt32 temp;\r\n      for (temp = 1; temp < numAvailableBytes; temp++)\r\n        if (data[temp] != data[(size_t)temp - backOffset])\r\n          break;\r\n      UInt32 lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        CState state2 = state;\r\n        state2.UpdateChar();\r\n        UInt32 posStateNext = (position + 1) & _posStateMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price + \r\n            _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n            _isRep[state2.Index].GetPrice1();\r\n        // for (; lenTest2 >= 2; lenTest2--)\r\n        {\r\n          while(lenEnd < cur + 1 + lenTest2)\r\n            _optimum[++lenEnd].Price = kIfinityPrice;\r\n          UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n              0, lenTest2, state2, posStateNext);\r\n          COptimal &optimum = _optimum[cur + 1 + lenTest2];\r\n          if (curAndLenPrice < optimum.Price) \r\n          {\r\n            optimum.Price = curAndLenPrice;\r\n            optimum.PosPrev = cur + 1;\r\n            optimum.BackPrev = 0;\r\n            optimum.Prev1IsChar = true;\r\n            optimum.Prev2 = false;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)\r\n    {\r\n      // UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n      UInt32 backOffset = reps[repIndex] + 1;\r\n      if (data[0] != data[(size_t)0 - backOffset] ||\r\n          data[1] != data[(size_t)1 - backOffset])\r\n        continue;\r\n      UInt32 lenTest;\r\n      for (lenTest = 2; lenTest < numAvailableBytes; lenTest++)\r\n        if (data[lenTest] != data[(size_t)lenTest - backOffset])\r\n          break;\r\n      UInt32 lenTestTemp = lenTest;\r\n      do\r\n      {\r\n        while(lenEnd < cur + lenTest)\r\n          _optimum[++lenEnd].Price = kIfinityPrice;\r\n        UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = repIndex;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n      }\r\n      while(--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n\r\n        if (_maxMode)\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit; lenTest2++)\r\n            if (data[lenTest2] != data[(size_t)lenTest2 - backOffset])\r\n              break;\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateRep();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = \r\n                repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1], \r\n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice1();\r\n            UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = lenTest + 1 + lenTest2;\r\n              while(lenEnd < cur + offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[cur + offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    \r\n    //    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n    if (newLen > numAvailableBytes)\r\n      newLen = numAvailableBytes;\r\n    if (newLen >= 2)\r\n    {\r\n      if (newLen == 2 && _matchDistances[2] >= 0x80)\r\n        continue;\r\n      UInt32 normalMatchPrice = matchPrice + \r\n        _isRep[state.Index].GetPrice0();\r\n      while(lenEnd < cur + newLen)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n      for(UInt32 lenTest = newLen; lenTest >= 2; lenTest--)\r\n      {\r\n        UInt32 curBack = _matchDistances[lenTest];\r\n        UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = curBack + kNumRepDistances;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n\r\n        if (_maxMode && (lenTest == newLen || curBack != _matchDistances[lenTest + 1]))\r\n        {\r\n          // Try Match + Literal + Rep0\r\n          UInt32 backOffset = curBack + 1;\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit; lenTest2++)\r\n            if (data[lenTest2] != data[(size_t)lenTest2 - backOffset])\r\n              break;\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateMatch();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1], \r\n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice1();\r\n            UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = lenTest + 1 + lenTest2;\r\n              while(lenEnd < cur + offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[cur + offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = curBack + kNumRepDistances;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n{\r\n  const int kDif = 7;\r\n  return (smallDist < (UInt32(1) << (32-kDif)) && bigDist >= (smallDist << kDif));\r\n}\r\n\r\n\r\nHRESULT CEncoder::ReadMatchDistances(UInt32 &lenRes)\r\n{\r\n  lenRes = _matchFinder->GetLongestMatch(_matchDistances);\r\n  if (lenRes == _numFastBytes)\r\n    lenRes += _matchFinder->GetMatchLen(lenRes, _matchDistances[lenRes], \r\n        kMatchMaxLen - lenRes);\r\n  _additionalOffset++;\r\n  return _matchFinder->MovePos();\r\n}\r\n\r\nHRESULT CEncoder::GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\r\n{\r\n  UInt32 lenMain;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    RINOK(ReadMatchDistances(lenMain));\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    _longestMatchWasFound = false;\r\n  }\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    repLens[i] = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);\r\n    if (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    return MovePos(lenRes - 1);\r\n  }\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = _matchDistances[_numFastBytes] + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 1);\r\n  }\r\n  while (lenMain > 2)\r\n  {\r\n    if (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\r\n      break;\r\n    lenMain--;\r\n  }\r\n  if (lenMain == 2 && _matchDistances[2] >= 0x80)\r\n    lenMain = 1;\r\n\r\n  UInt32 backMain = _matchDistances[lenMain];\r\n  if (repLens[repMaxIndex] >= 2)\r\n  {\r\n    if (repLens[repMaxIndex] + 1 >= lenMain || \r\n        repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1<<12)))\r\n    {\r\n      backRes = repMaxIndex;\r\n      lenRes = repLens[repMaxIndex];\r\n      return MovePos(lenRes - 1);\r\n    }\r\n  }\r\n  \r\n\r\n  if (lenMain >= 2)\r\n  {\r\n    RINOK(ReadMatchDistances(_longestMatchLength));\r\n    if (_longestMatchLength >= 2 &&\r\n      (\r\n        (_longestMatchLength >= lenMain && _matchDistances[lenMain] < backMain) || \r\n        _longestMatchLength == lenMain + 1 && \r\n          !ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\r\n        _longestMatchLength > lenMain + 1 ||\r\n        _longestMatchLength + 1 >= lenMain && lenMain >= 3 &&\r\n          ChangePair(_matchDistances[lenMain - 1], backMain)\r\n      )\r\n      )\r\n    {\r\n      _longestMatchWasFound = true;\r\n      backRes = UInt32(-1);\r\n      lenRes = 1;\r\n      return S_OK;\r\n    }\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n    {\r\n      UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);\r\n      if (repLen >= 2 && repLen + 1 >= lenMain)\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        lenRes = 1;\r\n        return S_OK;\r\n      }\r\n    }\r\n    backRes = backMain + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 2);\r\n  }\r\n  backRes = UInt32(-1);\r\n  lenRes = 1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::InitMatchFinder(IMatchFinder *matchFinder)\r\n{\r\n  _matchFinder = matchFinder;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Flush(UInt32 nowPos)\r\n{\r\n  ReleaseMFStream();\r\n  WriteEndMarker(nowPos & _posStateMask);\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nvoid CEncoder::WriteEndMarker(UInt32 posState)\r\n{\r\n  // This function for writing End Mark for stream version of LZMA. \r\n  // In current version this feature is not used.\r\n  if (!_writeEndMark)\r\n    return;\r\n\r\n  _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n  _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n  _state.UpdateMatch();\r\n  UInt32 len = kMatchMinLen; // kMatchMaxLen;\r\n  _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\r\n  UInt32 posSlot = (1 << kNumPosSlotBits)  - 1;\r\n  UInt32 lenToPosState = GetLenToPosState(len);\r\n  _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n  UInt32 footerBits = 30;\r\n  UInt32 posReduced = (UInt32(1) << footerBits) - 1;\r\n  _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n  _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n}\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  _needReleaseMFStream = false;\r\n  CCoderReleaser coderReleaser(this);\r\n  RINOK(SetStreams(inStream, outStream, inSize, outSize));\r\n  while(true)\r\n  {\r\n    UInt64 processedInSize;\r\n    UInt64 processedOutSize;\r\n    Int32 finished;\r\n    RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished));\r\n    if (finished != 0)\r\n      return S_OK;\r\n    if (progress != 0)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize));\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CEncoder::SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  _inStream = inStream;\r\n  _finished = false;\r\n  RINOK(Create());\r\n  RINOK(SetOutStream(outStream));\r\n  RINOK(Init());\r\n  \r\n  // CCoderReleaser releaser(this);\r\n\r\n  /*\r\n  if (_matchFinder->GetNumAvailableBytes() == 0)\r\n    return Flush();\r\n  */\r\n\r\n  if (!_fastMode)\r\n  {\r\n    FillPosSlotPrices();\r\n    FillDistancesPrices();\r\n    FillAlignPrices();\r\n  }\r\n\r\n  _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _lenEncoder.UpdateTables(1 << _posStateBits);\r\n  _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n  lastPosSlotFillingPos = 0;\r\n  nowPos64 = 0;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)\r\n{\r\n  if (_inStream != 0)\r\n  {\r\n    RINOK(_matchFinder->Init(_inStream));\r\n    _needReleaseMFStream = true;\r\n    _inStream = 0;\r\n  }\r\n\r\n\r\n  *finished = 1;\r\n  if (_finished)\r\n    return S_OK;\r\n  _finished = true;\r\n\r\n\r\n  UInt64 progressPosValuePrev = nowPos64;\r\n  if (nowPos64 == 0)\r\n  {\r\n    if (_matchFinder->GetNumAvailableBytes() == 0)\r\n      return Flush(UInt32(nowPos64));\r\n    UInt32 len; // it's not used\r\n    RINOK(ReadMatchDistances(len));\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n    _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n    _state.UpdateChar();\r\n    Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\r\n    _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte);\r\n    _previousByte = curByte;\r\n    _additionalOffset--;\r\n    nowPos64++;\r\n  }\r\n  if (_matchFinder->GetNumAvailableBytes() == 0)\r\n    return Flush(UInt32(nowPos64));\r\n  while(true)\r\n  {\r\n    #ifdef _NO_EXCEPTIONS\r\n    if (_rangeEncoder.Stream.ErrorCode != S_OK)\r\n      return _rangeEncoder.Stream.ErrorCode;\r\n    #endif\r\n    UInt32 pos;\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n\r\n    UInt32 len;\r\n    HRESULT result;\r\n    if (_fastMode)\r\n      result = GetOptimumFast(UInt32(nowPos64), pos, len);\r\n    else\r\n      result = GetOptimum(UInt32(nowPos64), pos, len);\r\n    RINOK(result);\r\n\r\n    if(len == 1 && pos == 0xFFFFFFFF)\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n      Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\r\n      CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte);\r\n      if(!_state.IsCharState())\r\n      {\r\n        Byte matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - _additionalOffset);\r\n        subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);\r\n      }\r\n      else\r\n        subCoder->Encode(&_rangeEncoder, curByte);\r\n      _state.UpdateChar();\r\n      _previousByte = curByte;\r\n    }\r\n    else\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n      if(pos < kNumRepDistances)\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 1);\r\n        if(pos == 0)\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 0);\r\n          if(len == 1)\r\n            _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n          else\r\n            _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n        }\r\n        else\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 1);\r\n          if (pos == 1)\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 0);\r\n          else\r\n          {\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 1);\r\n            _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);\r\n          }\r\n        }\r\n        if (len == 1)\r\n          _state.UpdateShortRep();\r\n        else\r\n        {\r\n          _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\r\n          _state.UpdateRep();\r\n        }\r\n\r\n\r\n        UInt32 distance = _repDistances[pos];\r\n        if (pos != 0)\r\n        {\r\n          for(UInt32 i = pos; i >= 1; i--)\r\n            _repDistances[i] = _repDistances[i - 1];\r\n          _repDistances[0] = distance;\r\n        }\r\n      }\r\n      else\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n        _state.UpdateMatch();\r\n        _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\r\n        pos -= kNumRepDistances;\r\n        UInt32 posSlot = GetPosSlot(pos);\r\n        UInt32 lenToPosState = GetLenToPosState(len);\r\n        _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1, \r\n                &_rangeEncoder, footerBits, posReduced);\r\n          else\r\n          {\r\n            _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n            if (!_fastMode)\r\n              if (--_alignPriceCount == 0)\r\n                FillAlignPrices();\r\n          }\r\n        }\r\n        UInt32 distance = pos;\r\n        for(UInt32 i = kNumRepDistances - 1; i >= 1; i--)\r\n          _repDistances[i] = _repDistances[i - 1];\r\n        _repDistances[0] = distance;\r\n      }\r\n      _previousByte = _matchFinder->GetIndexByte(len - 1 - _additionalOffset);\r\n    }\r\n    _additionalOffset -= len;\r\n    nowPos64 += len;\r\n    if (!_fastMode)\r\n      if (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\r\n      {\r\n        FillPosSlotPrices();\r\n        FillDistancesPrices();\r\n        lastPosSlotFillingPos = nowPos64;\r\n      }\r\n    if (_additionalOffset == 0)\r\n    {\r\n      *inSize = nowPos64;\r\n      *outSize = _rangeEncoder.GetProcessedSize();\r\n      if (_matchFinder->GetNumAvailableBytes() == 0)\r\n        return Flush(UInt32(nowPos64));\r\n      if (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n      {\r\n        _finished = false;\r\n        *finished = 0;\r\n        return S_OK;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try \r\n  { \r\n  #endif\r\n    return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  #ifndef _NO_EXCEPTIONS\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return E_FAIL; }\r\n  #endif\r\n}\r\n  \r\nvoid CEncoder::FillPosSlotPrices()\r\n{\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n\t  UInt32 posSlot;\r\n    for (posSlot = 0; posSlot < kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\r\n      _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\r\n    for (; posSlot < _distTableSize; posSlot++)\r\n      _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) + \r\n      ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);\r\n  }\r\n}\r\n\r\nvoid CEncoder::FillDistancesPrices()\r\n{\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n\t  UInt32 i;\r\n    for (i = 0; i < kStartPosModelIndex; i++)\r\n      _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][i];\r\n    for (; i < kNumFullDistances; i++)\r\n    { \r\n      UInt32 posSlot = GetPosSlot(i);\r\n      UInt32 footerBits = ((posSlot >> 1) - 1);\r\n      UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n\r\n      _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][posSlot] +\r\n          NRangeCoder::ReverseBitTreeGetPrice(_posEncoders + \r\n              base - posSlot - 1, footerBits, i - base);\r\n            \r\n    }\r\n  }\r\n}\r\n\r\nvoid CEncoder::FillAlignPrices()\r\n{\r\n  for (UInt32 i = 0; i < kAlignTableSize; i++)\r\n    _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n  _alignPriceCount = kAlignTableSize;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA/LZMAEncoder.h",
    "content": "// LZMA/Encoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/IMatchFinder.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;\r\n\r\nclass CBaseState\r\n{\r\nprotected:\r\n  CState _state;\r\n  Byte _previousByte;\r\n  UInt32 _repDistances[kNumRepDistances];\r\n  void Init()\r\n  {\r\n    _state.Init();\r\n    _previousByte = 0;\r\n    for(UInt32 i = 0 ; i < kNumRepDistances; i++)\r\n      _repDistances[i] = 0;\r\n  }\r\n};\r\n\r\nstruct COptimal\r\n{\r\n  CState State;\r\n\r\n  bool Prev1IsChar;\r\n  bool Prev2;\r\n\r\n  UInt32 PosPrev2;\r\n  UInt32 BackPrev2;     \r\n\r\n  UInt32 Price;    \r\n  UInt32 PosPrev;         // posNext;\r\n  UInt32 BackPrev;     \r\n  UInt32 Backs[kNumRepDistances];\r\n  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }\r\n  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n  bool IsShortRep() { return (BackPrev == 0); }\r\n};\r\n\r\n\r\nextern Byte g_FastPos[1024];\r\ninline UInt32 GetPosSlot(UInt32 pos)\r\n{\r\n  if (pos < (1 << 10))\r\n    return g_FastPos[pos];\r\n  if (pos < (1 << 19))\r\n    return g_FastPos[pos >> 9] + 18;\r\n  return g_FastPos[pos >> 18] + 36;\r\n}\r\n\r\ninline UInt32 GetPosSlot2(UInt32 pos)\r\n{\r\n  if (pos < (1 << 16))\r\n    return g_FastPos[pos >> 6] + 12;\r\n  if (pos < (1 << 25))\r\n    return g_FastPos[pos >> 15] + 30;\r\n  return g_FastPos[pos >> 24] + 48;\r\n}\r\n\r\nconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\nconst UInt32 kNumOpts = 1 << 12;\r\n\r\n\r\nclass CLiteralEncoder2\r\n{\r\n  CMyBitEncoder _encoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _encoders[i].Init();\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);\r\n  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;\r\n};\r\n\r\nclass CLiteralEncoder\r\n{\r\n  CLiteralEncoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralEncoder(): _coders(0) {}\r\n  ~CLiteralEncoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)\r\n    { return &_coders[GetState(pos, prevByte)]; }\r\n  /*\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte, \r\n      Byte symbol)\r\n    { _coders[GetState(pos, prevByte)].Encode(rangeEncoder, symbol); }\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte, \r\n      Byte matchByte, Byte symbol)\r\n    { _coders[GetState(pos, prevByte)].Encode(rangeEncoder,\r\n      matchByte, symbol); }\r\n  */\r\n  UInt32 GetPrice(UInt32 pos, Byte prevByte, bool matchMode, Byte matchByte, Byte symbol) const\r\n    { return _coders[GetState(pos, prevByte)].GetPrice(matchMode, matchByte, symbol); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CEncoder\r\n{\r\n  CMyBitEncoder _choice;\r\n  CMyBitEncoder  _choice2;\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits>  _highCoder;\r\npublic:\r\n  void Init(UInt32 numPosStates);\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const;\r\n};\r\n\r\nconst UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\r\n\r\nclass CPriceTableEncoder: public CEncoder\r\n{\r\n  UInt32 _prices[kNumSymbolsTotal][kNumPosStatesEncodingMax];\r\n  UInt32 _tableSize;\r\n  UInt32 _counters[kNumPosStatesEncodingMax];\r\npublic:\r\n  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const\r\n    { return _prices[symbol][posState]; }\r\n  void UpdateTable(UInt32 posState)\r\n  {\r\n    for (UInt32 len = 0; len < _tableSize; len++)\r\n      _prices[len][posState] = CEncoder::GetPrice(len, posState);\r\n    _counters[posState] = _tableSize;\r\n  }\r\n  void UpdateTables(UInt32 numPosStates)\r\n  {\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n      UpdateTable(posState);\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n  {\r\n    CEncoder::Encode(rangeEncoder, symbol, posState);\r\n    if (--_counters[posState] == 0)\r\n      UpdateTable(posState);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CEncoder : \r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CBaseState,\r\n  public CMyUnknownImp\r\n{\r\n  COptimal _optimum[kNumOpts];\r\n  CMyComPtr<IMatchFinder> _matchFinder; // test it\r\n  NRangeCoder::CEncoder _rangeEncoder;\r\n\r\n  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n  CMyBitEncoder _isRep[kNumStates];\r\n  CMyBitEncoder _isRepG0[kNumStates];\r\n  CMyBitEncoder _isRepG1[kNumStates];\r\n  CMyBitEncoder _isRepG2[kNumStates];\r\n  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];\r\n\r\n  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;\r\n  \r\n  NLength::CPriceTableEncoder _lenEncoder;\r\n  NLength::CPriceTableEncoder _repMatchLenEncoder;\r\n\r\n  CLiteralEncoder _literalEncoder;\r\n\r\n  UInt32 _matchDistances[kMatchMaxLen + 1];\r\n\r\n  bool _fastMode;\r\n  bool _maxMode;\r\n  UInt32 _numFastBytes;\r\n  UInt32 _longestMatchLength;    \r\n\r\n  UInt32 _additionalOffset;\r\n\r\n  UInt32 _optimumEndIndex;\r\n  UInt32 _optimumCurrentIndex;\r\n\r\n  bool _longestMatchWasFound;\r\n\r\n  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  \r\n  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n\r\n  UInt32 _alignPrices[kAlignTableSize];\r\n  UInt32 _alignPriceCount;\r\n\r\n  UInt32 _distTableSize;\r\n\r\n  UInt32 _posStateBits;\r\n  UInt32 _posStateMask;\r\n  UInt32 _numLiteralPosStateBits;\r\n  UInt32 _numLiteralContextBits;\r\n\r\n  UInt32 _dictionarySize;\r\n\r\n  UInt32 _dictionarySizePrev;\r\n  UInt32 _numFastBytesPrev;\r\n\r\n  UInt64 lastPosSlotFillingPos;\r\n  UInt64 nowPos64;\r\n  bool _finished;\r\n  ISequentialInStream *_inStream;\r\n\r\n  int _matchFinderIndex;\r\n  #ifdef COMPRESS_MF_MT\r\n  bool _multiThread;\r\n  #endif\r\n\r\n  bool _writeEndMark;\r\n\r\n  bool _needReleaseMFStream;\r\n  \r\n  HRESULT ReadMatchDistances(UInt32 &len);\r\n\r\n  HRESULT MovePos(UInt32 num);\r\n  UInt32 GetRepLen1Price(CState state, UInt32 posState) const\r\n  {\r\n    return _isRepG0[state.Index].GetPrice0() +\r\n        _isRep0Long[state.Index][posState].GetPrice0();\r\n  }\r\n  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const\r\n  {\r\n    UInt32 price = _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n    if(repIndex == 0)\r\n    {\r\n      price += _isRepG0[state.Index].GetPrice0();\r\n      price += _isRep0Long[state.Index][posState].GetPrice1();\r\n    }\r\n    else\r\n    {\r\n      price += _isRepG0[state.Index].GetPrice1();\r\n      if (repIndex == 1)\r\n        price += _isRepG1[state.Index].GetPrice0();\r\n      else\r\n      {\r\n        price += _isRepG1[state.Index].GetPrice1();\r\n        price += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n      }\r\n    }\r\n    return price;\r\n  }\r\n  /*\r\n  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const\r\n  {\r\n    if (pos >= kNumFullDistances)\r\n      return kIfinityPrice;\r\n    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);\r\n  }\r\n  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n  */\r\n  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    if (len == 2 && pos >= 0x80)\r\n      return kIfinityPrice;\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n\r\n  UInt32 Backward(UInt32 &backRes, UInt32 cur);\r\n  HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r\n  HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r\n\r\n  void FillPosSlotPrices();\r\n  void FillDistancesPrices();\r\n  void FillAlignPrices();\r\n    \r\n  void ReleaseMFStream()\r\n  {\r\n    if (_matchFinder && _needReleaseMFStream)\r\n    {\r\n      _matchFinder->ReleaseStream();\r\n      _needReleaseMFStream = false;\r\n    }\r\n  }\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    ReleaseMFStream();\r\n    ReleaseOutStream();\r\n  }\r\n\r\n  HRESULT Flush(UInt32 nowPos);\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()\r\n    {\r\n      _coder->ReleaseStreams();\r\n    }\r\n  };\r\n  friend class CCoderReleaser;\r\n\r\n  void WriteEndMarker(UInt32 posState);\r\n\r\npublic:\r\n  CEncoder();\r\n  void SetWriteEndMarkerMode(bool writeEndMarker)\r\n    { _writeEndMark= writeEndMarker; }\r\n\r\n  HRESULT Create();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  HRESULT Init();\r\n  \r\n  // ICompressCoder interface\r\n  HRESULT SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize);\r\n  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);\r\n\r\n  HRESULT CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressCoder interface\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // IInitMatchFinder interface\r\n  STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder);\r\n\r\n  // ICompressSetCoderProperties2\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  \r\n  // ICompressWriteCoderProperties\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"Pat\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2R.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat3H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat4H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\PatMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"BT\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3Z.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3ZMain.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree4b.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTreeMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"HC\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC3.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC4b.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HCMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\IMatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA_C\\LzmaDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA_C\\LzmaDecode.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"LzmaRamDecode.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kMode,\r\n  kDictionary,\r\n  kFastBytes,\r\n  kLitContext,\r\n  kLitPos,\r\n  kPosBits,\r\n  kMatchFinder,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kSimple, false }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\"\r\n    \"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, bt4b, pat2r, pat2,\\n\"\r\n    \"              pat2h, pat3h, pat4h, hc3, hc4], default: bt4\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[], \r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA 4.32 Copyright (c) 1999-2005 Igor Pavlov  2005-12-09\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  if (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }   \r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++]; \r\n\r\n  bool dictionaryIsDefined = false;\r\n  UInt32 dictionary = 1 << 21;\r\n  if(parser[NKey::kDictionary].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dictionary = 1 << dicLog;\r\n    dictionaryIsDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 10;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchmark(stderr, numIterations, dictionary, \r\n        mf.CompareNoCase(L\"BT4\") == 0);\r\n  }\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++]; \r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\", \r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++]; \r\n    COutFileStream *outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\", \r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    UInt32 inSize = (UInt32)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize); \r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)\r\n      throw \"Can not read\";\r\n    if ((UInt32)inSize != processedSize)\r\n      throw \"Read size error\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSizeProcessed;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictionaryIsDefined)\r\n        dictionary = 1 << 23;\r\n      int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, \r\n          dictionary, SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      size_t outSize;\r\n      if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)\r\n        throw \"data error\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLZMA::CEncoder *encoderSpec = \r\n      new NCompress::NLZMA::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictionaryIsDefined)\r\n      dictionary = 1 << 23;\r\n\r\n    UInt32 posStateBits = 2;\r\n    UInt32 litContextBits = 3; // for normal files\r\n    // UInt32 litContextBits = 0; // for 32-bit data\r\n    UInt32 litPosBits = 0;\r\n    // UInt32 litPosBits = 2; // for 32-bit data\r\n    UInt32 algorithm = 2;\r\n    UInt32 numFastBytes = 128;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    if(parser[NKey::kMode].ThereIs)\r\n      if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))\r\n        IncorrectCommand();\r\n\r\n    if(parser[NKey::kFastBytes].ThereIs)\r\n      if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitContext].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitPos].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kPosBits].ThereIs)\r\n      if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))\r\n        IncorrectCommand();\r\n\r\n    PROPID propIDs[] = \r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker\r\n    };\r\n    const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n    /*\r\n    NWindows::NCOM::CPropVariant properties[kNumProps];\r\n    properties[0] = UInt32(dictionary);\r\n    properties[1] = UInt32(posStateBits);\r\n    properties[2] = UInt32(litContextBits);\r\n   \r\n    properties[3] = UInt32(litPosBits);\r\n    properties[4] = UInt32(algorithm);\r\n    properties[5] = UInt32(numFastBytes);\r\n    properties[6] = mf;\r\n    properties[7] = eos;\r\n    */\r\n    PROPVARIANT properties[kNumProps];\r\n    for (int p = 0; p < 6; p++)\r\n      properties[p].vt = VT_UI4;\r\n    properties[0].ulVal = UInt32(dictionary);\r\n    properties[1].ulVal = UInt32(posStateBits);\r\n    properties[2].ulVal = UInt32(litContextBits);\r\n    properties[3].ulVal = UInt32(litPosBits);\r\n    properties[4].ulVal = UInt32(algorithm);\r\n    properties[5].ulVal = UInt32(numFastBytes);\r\n    \r\n    properties[6].vt = VT_BSTR;\r\n    properties[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    properties[7].vt = VT_BOOL;\r\n    properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }   \r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }   \r\n  }\r\n  else\r\n  {\r\n    NCompress::NLZMA::CDecoder *decoderSpec = \r\n        new NCompress::NLZMA::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte properties[kPropertiesSize];\r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, properties, kPropertiesSize, &processedSize) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (processedSize != kPropertiesSize)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b;\r\n      if (inStream->Read(&b, 1, &processedSize) != S_OK)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      if (processedSize != 1)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      fileSize |= ((UInt64)b) << (8 * i);\r\n    }\r\n    if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }   \r\n  }\r\n  return 0;\r\n}\r\n\r\nint main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s) \r\n  { \r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1; \r\n  }\r\n  catch(...) \r\n  { \r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1; \r\n  }\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#include <time.h>\r\n#endif\r\n\r\n#include \"../../../Common/CRC.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\nstatic const UInt32 kAdditionalSize = \r\n#ifdef _WIN32_WCE\r\n(1 << 20);\r\n#else\r\n(6 << 20);\r\n#endif\r\n\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 10;\r\n\r\nclass CRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd() \r\n  {\r\n    return \r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBitRandomGenerator\r\n{\r\n  CRandomGenerator RG;\r\n  UInt32 Value;\r\n  int NumBits;\r\npublic:\r\n  void Init()\r\n  {\r\n    Value = 0;\r\n    NumBits = 0;\r\n  }\r\n  UInt32 GetRnd(int numBits) \r\n  {\r\n    if (NumBits > numBits)\r\n    {\r\n      UInt32 result = Value & ((1 << numBits) - 1);\r\n      Value >>= numBits;\r\n      NumBits -= numBits;\r\n      return result;\r\n    }\r\n    numBits -= NumBits;\r\n    UInt32 result = (Value << numBits);\r\n    Value = RG.GetRnd();\r\n    result |= Value & ((1 << numBits) - 1);\r\n    Value >>= numBits;\r\n    NumBits = 32 - numBits;\r\n    return result;\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator\r\n{\r\n  CBitRandomGenerator RG;\r\n  UInt32 Pos;\r\npublic:\r\n  UInt32 BufferSize;\r\n  Byte *Buffer;\r\n  CBenchRandomGenerator(): Buffer(0) {} \r\n  ~CBenchRandomGenerator() { delete []Buffer; }\r\n  void Init() { RG.Init(); }\r\n  void Set(UInt32 bufferSize) \r\n  {\r\n    delete []Buffer;\r\n    Buffer = 0;\r\n    Buffer = new Byte[bufferSize];\r\n    Pos = 0;\r\n    BufferSize = bufferSize;\r\n  }\r\n  UInt32 GetRndBit() { return RG.GetRnd(1); }\r\n  /*\r\n  UInt32 GetLogRand(int maxLen)\r\n  {\r\n    UInt32 len = GetRnd() % (maxLen + 1);\r\n    return GetRnd() & ((1 << len) - 1);\r\n  }\r\n  */\r\n  UInt32 GetLogRandBits(int numBits)\r\n  {\r\n    UInt32 len = RG.GetRnd(numBits);\r\n    return RG.GetRnd(len);\r\n  }\r\n  UInt32 GetOffset()\r\n  {\r\n    if (GetRndBit() == 0)\r\n      return GetLogRandBits(4);\r\n    return (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n  }\r\n  UInt32 GetLen()\r\n  {\r\n    if (GetRndBit() == 0)\r\n      return RG.GetRnd(2);\r\n    if (GetRndBit() == 0)\r\n      return 4 + RG.GetRnd(3);\r\n    return 12 + RG.GetRnd(4);\r\n  }\r\n  void Generate()\r\n  {\r\n    while(Pos < BufferSize)\r\n    {\r\n      if (GetRndBit() == 0 || Pos < 1)\r\n        Buffer[Pos++] = Byte(RG.GetRnd(8));\r\n      else\r\n      {\r\n        UInt32 offset = GetOffset();\r\n        while (offset >= Pos)\r\n          offset >>= 1;\r\n        offset += 1;\r\n        UInt32 len = 2 + GetLen();\r\n        for (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n          Buffer[Pos] = Buffer[Pos - offset];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nclass CBenchmarkInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  UInt32 Pos;\r\n  UInt32 Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, UInt32 size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 remain = Size - Pos;\r\n  if (size > remain)\r\n    size = remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 BufferSize;\r\n  FILE *_f;\r\npublic:\r\n  UInt32 Pos;\r\n  Byte *Buffer;\r\n  CBenchmarkOutStream(): _f(0), Buffer(0) {} \r\n  virtual ~CBenchmarkOutStream() { delete []Buffer; }\r\n  void Init(FILE *f, UInt32 bufferSize) \r\n  {\r\n    delete []Buffer;\r\n    Buffer = 0;\r\n    Buffer = new Byte[bufferSize];\r\n    Pos = 0;\r\n    BufferSize = bufferSize;\r\n    _f = f;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < BufferSize; i++)\r\n    Buffer[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    fprintf(_f, \"\\nERROR: Buffer is full\\n\");\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CCRC CRC;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { CRC.Init(); }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  CRC.Update(data, size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef _WIN32\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  return GetTickCount();\r\n  #else\r\n  return clock();\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef _WIN32\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  return 1000;\r\n  #else\r\n  return CLOCKS_PER_SEC;\r\n  #endif \r\n}\r\n\r\nstruct CProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 ApprovedStart;\r\n  UInt64 InSize;\r\n  UInt64 Time;\r\n  void Init()\r\n  {\r\n    InSize = 0;\r\n    Time = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nSTDMETHODIMP CProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  if (*inSize >= ApprovedStart && InSize == 0)\r\n  {\r\n    Time = ::GetTimeCount();\r\n    InSize = *inSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n{\r\n  UInt64 freq = GetFreq();\r\n  UInt64 elTime = elapsedTime;\r\n  while(freq > 1000000)\r\n  {\r\n    freq >>= 1;\r\n    elTime >>= 1;\r\n  }\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic UInt64 GetCompressRating(UInt32 dictionarySize, bool isBT4,\r\n    UInt64 elapsedTime, UInt64 size)\r\n{\r\n  UInt64 numCommandsForOne;\r\n  if (isBT4)\r\n  {\r\n    UInt64 t = GetLogSize(dictionarySize) - (19 << kSubBits);\r\n    numCommandsForOne = 2000 + ((t * t * 68) >> (2 * kSubBits));\r\n  }\r\n  else\r\n  {\r\n    UInt64 t = GetLogSize(dictionarySize) - (15 << kSubBits);\r\n    numCommandsForOne = 1500 + ((t * t * 41) >> (2 * kSubBits));\r\n  }\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime);\r\n}\r\n\r\nstatic UInt64 GetDecompressRating(UInt64 elapsedTime, \r\n    UInt64 outSize, UInt64 inSize)\r\n{\r\n  UInt64 numCommands = inSize * 250 + outSize * 21;\r\n  return MyMultDiv64(numCommands, elapsedTime);\r\n}\r\n\r\n/*\r\nstatic UInt64 GetTotalRating(\r\n    UInt32 dictionarySize, \r\n    bool isBT4,\r\n    UInt64 elapsedTimeEn, UInt64 sizeEn,\r\n    UInt64 elapsedTimeDe, \r\n    UInt64 inSizeDe, UInt64 outSizeDe)\r\n{\r\n  return (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) + \r\n    GetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n}\r\n*/\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  fprintf(f, \"%5d MIPS\", (unsigned int)(rating / 1000000));\r\n}\r\n\r\nstatic void PrintResults(\r\n    FILE *f, \r\n    UInt32 dictionarySize,\r\n    bool isBT4,\r\n    UInt64 elapsedTime, \r\n    UInt64 size, \r\n    bool decompressMode, UInt64 secondSize)\r\n{\r\n  UInt64 speed = MyMultDiv64(size, elapsedTime);\r\n  fprintf(f, \"%6d KB/s  \", (unsigned int)(speed / 1024));\r\n  UInt64 rating;\r\n  if (decompressMode)\r\n    rating = GetDecompressRating(elapsedTime, size, secondSize);\r\n  else\r\n    rating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\r\n  PrintRating(f, rating);\r\n}\r\n\r\nstatic void ThrowError(FILE *f, HRESULT result, const char *s)\r\n{\r\n  fprintf(f, \"\\nError: \");\r\n  if (result == E_ABORT)\r\n    fprintf(f, \"User break\");\r\n  if (result == E_OUTOFMEMORY)\r\n    fprintf(f, \"Can not allocate memory\");\r\n  else\r\n    fprintf(f, s);\r\n  fprintf(f, \"\\n\");\r\n}\r\n\r\nconst wchar_t *bt2 = L\"BT2\";\r\nconst wchar_t *bt4 = L\"BT4\";\r\n\r\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize, bool isBT4)\r\n{\r\n  if (numIterations == 0)\r\n    return 0;\r\n  if (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\r\n  {\r\n    fprintf(f, \"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\\n\");\r\n    return 1;\r\n  }\r\n  fprintf(f, \"\\n       Compressing                Decompressing\\n\\n\");\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;\r\n  CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n\r\n  CBenchmarkOutStream *propStreamSpec = new CBenchmarkOutStream;\r\n  CMyComPtr<ISequentialOutStream> propStream = propStreamSpec;\r\n  propStreamSpec->Init(f, kMaxLzmaPropSize);\r\n  \r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kMatchFinder  \r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = UInt32(dictionarySize);\r\n\r\n  properties[1].vt = VT_BSTR;\r\n  properties[1].bstrVal = isBT4 ? (BSTR)bt4: (BSTR)bt2;\r\n\r\n  const UInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n  {\r\n    fprintf(f, \"\\nError: Incorrect command\\n\");\r\n    return 1;\r\n  }\r\n  encoderSpec->WriteCoderProperties(propStream);\r\n\r\n  CBenchRandomGenerator rg;\r\n  rg.Init();\r\n  rg.Set(kBufferSize);\r\n  rg.Generate();\r\n  CCRC crc;\r\n  crc.Update(rg.Buffer, rg.BufferSize);\r\n\r\n  CProgressInfo *progressInfoSpec = new CProgressInfo;\r\n  CMyComPtr<ICompressProgressInfo> progressInfo = progressInfoSpec;\r\n\r\n  progressInfoSpec->ApprovedStart = dictionarySize;\r\n\r\n  UInt64 totalBenchSize = 0;\r\n  UInt64 totalEncodeTime = 0;\r\n  UInt64 totalDecodeTime = 0;\r\n  UInt64 totalCompressedSize = 0;\r\n\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    progressInfoSpec->Init();\r\n    CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n    inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n    CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n    CBenchmarkOutStream *outStreamSpec = new CBenchmarkOutStream;\r\n    outStreamSpec->Init(f, kCompressedBufferSize);\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, progressInfo);\r\n    UInt64 encodeTime = ::GetTimeCount() - progressInfoSpec->Time;\r\n    UInt32 compressedSize = outStreamSpec->Pos;\r\n    if(result != S_OK)\r\n    {\r\n      ThrowError(f, result, \"Encoder Error\");\r\n      return 1;\r\n    }\r\n    if (progressInfoSpec->InSize == 0)\r\n    {\r\n      fprintf(f, \"\\nError: Internal ERROR 1282\\n\");\r\n      return 1;\r\n    }\r\n  \r\n    ///////////////////////\r\n    // Decompressing\r\n  \r\n    CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n    CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n    UInt64 decodeTime;\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n      crcOutStreamSpec->Init();\r\n      \r\n      if (decoderSpec->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos) != S_OK)\r\n      {\r\n        fprintf(f, \"\\nError: Set Decoder Properties Error\\n\");\r\n        return 1;\r\n      }\r\n      UInt64 outSize = kBufferSize;\r\n      UInt64 startTime = ::GetTimeCount();\r\n      result = decoder->Code(inStream, crcOutStream, 0, &outSize, 0);\r\n      decodeTime = ::GetTimeCount() - startTime;\r\n      if(result != S_OK)\r\n      {\r\n        ThrowError(f, result, \"Decode Error\");\r\n        return 1;\r\n      }\r\n      if (crcOutStreamSpec->CRC.GetDigest() != crc.GetDigest())\r\n      {\r\n        fprintf(f, \"\\nError: CRC Error\\n\");\r\n        return 1;\r\n      }\r\n    }\r\n    UInt64 benchSize = kBufferSize - progressInfoSpec->InSize;\r\n    PrintResults(f, dictionarySize, isBT4, encodeTime, benchSize, false, 0);\r\n    fprintf(f, \"     \");\r\n    PrintResults(f, dictionarySize, isBT4, decodeTime, kBufferSize, true, compressedSize);\r\n    fprintf(f, \"\\n\");\r\n\r\n    totalBenchSize += benchSize;\r\n    totalEncodeTime += encodeTime;\r\n    totalDecodeTime += decodeTime;\r\n    totalCompressedSize += compressedSize;\r\n  }\r\n  fprintf(f, \"---------------------------------------------------\\n\");\r\n  PrintResults(f, dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\r\n  fprintf(f, \"     \");\r\n  PrintResults(f, dictionarySize, isBT4, totalDecodeTime, \r\n      kBufferSize * numIterations, true, totalCompressedSize);\r\n  fprintf(f, \"    Average\\n\");\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LzmaBench_h\r\n#define __LzmaBench_h\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize, bool isBT4);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/LzmaRam.cpp",
    "content": "// LzmaRam.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../Branch/BranchX86.h\"\r\n}\r\n\r\nclass CInStreamRam: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Size;\r\n  size_t Pos;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 remain = Size - Pos;\r\n  if (size > remain)\r\n    size = remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass COutStreamRam: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  size_t Size;\r\npublic:\r\n  Byte *Data;\r\n  size_t Pos;\r\n  bool Overflow;\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n    Overflow = false;\r\n  }\r\n  void SetPos(size_t pos)\r\n  {\r\n    Overflow = false;\r\n    Pos = pos;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  HRESULT WriteByte(Byte b)\r\n  {\r\n    if (Pos >= Size)\r\n    {\r\n      Overflow = true;\r\n      return E_FAIL;\r\n    }\r\n    Data[Pos++] = b;\r\n    return S_OK;\r\n  }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < Size; i++)\r\n    Data[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    Overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\n#define SZE_FAIL (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_OUT_OVERFLOW (3)\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try { \r\n  #endif\r\n\r\n  *outSizeProcessed = 0;\r\n  const size_t kIdSize = 1;\r\n  const size_t kLzmaPropsSize = 5;\r\n  const size_t kMinDestSize = kIdSize + kLzmaPropsSize + 8;\r\n  if (outSize < kMinDestSize)\r\n    return SZE_OUT_OVERFLOW;\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kAlgorithm,\r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kNumFastBytes,\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[1].vt = VT_UI4;\r\n  properties[2].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)2;\r\n  properties[1].ulVal = (UInt32)dictionarySize;\r\n  properties[2].ulVal = (UInt32)64;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n    return 1;\r\n  \r\n  COutStreamRam *outStreamSpec = new COutStreamRam;\r\n  if (outStreamSpec == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n  CInStreamRam *inStreamSpec = new CInStreamRam;\r\n  if (inStreamSpec == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\r\n  outStreamSpec->Init(outBuffer, outSize);\r\n  if (outStreamSpec->WriteByte(0) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n\r\n  if (encoderSpec->WriteCoderProperties(outStream) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n  if (outStreamSpec->Pos != kIdSize + kLzmaPropsSize)\r\n    return 1;\r\n  \r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    UInt64 t = (UInt64)(inSize);\r\n    if (outStreamSpec->WriteByte((Byte)((t) >> (8 * i))) != S_OK)\r\n      return SZE_OUT_OVERFLOW;\r\n  }\r\n\r\n  Byte *filteredStream = 0;\r\n\r\n  bool useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (inSize != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(inSize);\r\n      if (filteredStream == 0)\r\n        return SZE_OUTOFMEMORY;\r\n      memmove(filteredStream, inBuffer, inSize);\r\n    }\r\n    UInt32 _prevMask;\r\n    UInt32 _prevPos;\r\n    x86_Convert_Init(_prevMask, _prevPos);\r\n    x86_Convert(filteredStream, (UInt32)inSize, 0, &_prevMask, &_prevPos, 1);\r\n  }\r\n  \r\n  UInt32 minSize = 0;\r\n  int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n  bool bestIsFiltered = false;\r\n  int mainResult = 0;\r\n  size_t startPos = outStreamSpec->Pos;\r\n  for (i = 0; i < numPasses; i++)\r\n  {\r\n    if (numPasses > 1 && i == numPasses - 1 && !bestIsFiltered)\r\n      break;\r\n    outStreamSpec->SetPos(startPos);\r\n    bool curModeIsFiltered = false;\r\n    if (useFilter && i == 0)\r\n      curModeIsFiltered = true;\r\n    if (numPasses > 1 && i == numPasses - 1)\r\n      curModeIsFiltered = true;\r\n\r\n    inStreamSpec->Init(curModeIsFiltered ? filteredStream : inBuffer, inSize);\r\n    \r\n    HRESULT lzmaResult = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    \r\n    mainResult = 0;\r\n    if (lzmaResult == E_OUTOFMEMORY)\r\n    {\r\n      mainResult = SZE_OUTOFMEMORY;\r\n      break;\r\n    } \r\n    if (i == 0 || outStreamSpec->Pos <= minSize)\r\n    {\r\n      minSize = outStreamSpec->Pos;\r\n      bestIsFiltered = curModeIsFiltered;\r\n    }\r\n    if (outStreamSpec->Overflow)\r\n      mainResult = SZE_OUT_OVERFLOW;\r\n    else if (lzmaResult != S_OK)\r\n    {\r\n      mainResult = SZE_FAIL;\r\n      break;\r\n    } \r\n  }\r\n  *outSizeProcessed = outStreamSpec->Pos;\r\n  if (bestIsFiltered)\r\n    outBuffer[0] = 1;\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n  \r\n  #ifndef _NO_EXCEPTIONS\r\n  } catch(...) { return SZE_OUTOFMEMORY; }\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/LzmaRam.h",
    "content": "// LzmaRam.h\r\n\r\n#ifndef __LzmaRam_h\r\n#define __LzmaRam_h\r\n\r\n#include <stdlib.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\n/*\r\nLzmaRamEncode: BCJ + LZMA RAM->RAM compressing.\r\nIt uses .lzma format, but it writes one additional byte to .lzma file:\r\n  0: - no filter\r\n  1: - x86(BCJ) filter.\r\n\r\nTo provide best compression ratio dictionarySize mustbe >= inSize\r\n\r\nLzmaRamEncode allocates Data with MyAlloc/BigAlloc functions.\r\nRAM Requirements:\r\n  RamSize = dictionarySize * 9.5 + 6MB + FilterBlockSize \r\n    FilterBlockSize = 0, if useFilter == false\r\n    FilterBlockSize = inSize, if useFilter == true\r\n\r\n  Return code:\r\n    0 - OK\r\n    1 - Unspecified Error\r\n    2 - Memory allocating error\r\n    3 - Output buffer OVERFLOW\r\n\r\nIf you use SZ_FILTER_AUTO mode, then encoder will use 2 or 3 passes:\r\n  2 passes when FILTER_NO provides better compression.\r\n  3 passes when FILTER_YES provides better compression.\r\n*/\r\n\r\nenum ESzFilterMode \r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.c",
    "content": "/* LzmaRamDecode.c */\r\n\r\n#include \"LzmaRamDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#include \"BranchX86.h\"\r\n#else\r\n#include \"../LZMA_C/LzmaDecode.h\"\r\n#include \"../Branch/BranchX86.h\"\r\n#endif\r\n\r\n#define LZMA_PROPS_SIZE 14\r\n#define LZMA_SIZE_OFFSET 6\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize, \r\n    size_t *outSize)\r\n{\r\n  unsigned int i;\r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  *outSize = 0;\r\n  for(i = 0; i < sizeof(size_t); i++)\r\n    *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);\r\n  for(; i < 8; i++)\r\n    if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)\r\n      return 1;\r\n  return 0;\r\n}\r\n\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *))\r\n{\r\n  CLzmaDecoderState state;  /* it's about 24 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  SizeT inProcessed;\r\n  int useFilter;\r\n  \r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  useFilter = inBuffer[0];\r\n\r\n  *outSizeProcessed = 0;\r\n  if (useFilter > 1)\r\n    return 1;\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return 1;\r\n  state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  result = LzmaDecode(&state,\r\n    inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed,\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  freeFunc(state.Probs);\r\n  if (result != LZMA_RESULT_OK)\r\n    return 1;\r\n  *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 _prevMask;\r\n    UInt32 _prevPos;\r\n    x86_Convert_Init(_prevMask, _prevPos);\r\n    x86_Convert(outBuffer, (UInt32)outSizeProcessedLoc, 0, &_prevMask, &_prevPos, 0);\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.h",
    "content": "/* LzmaRamDecode.h */\r\n\r\n#ifndef __LzmaRamDecode_h\r\n#define __LzmaRamDecode_h\r\n\r\n#include <stdlib.h>\r\n\r\n/*\r\nLzmaRamGetUncompressedSize:\r\n  In: \r\n    inBuffer - input data\r\n    inSize   - input data size\r\n  Out: \r\n    outSize  - uncompressed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers\r\n*/\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    size_t *outSize);\r\n\r\n\r\n/*\r\nLzmaRamDecompress:\r\n  In: \r\n    inBuffer  - input data\r\n    inSize    - input data size\r\n    outBuffer - output data\r\n    outSize   - output size\r\n    allocFunc - alloc function (can be malloc)\r\n    freeFunc  - free function (can be free)\r\n  Out: \r\n    outSizeProcessed - processed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers / data stream\r\n    2 - Memory allocating error\r\n\r\nMemory requirements depend from properties of LZMA stream.\r\nWith default lzma settings it's about 16 KB.\r\n*/\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nCFLAGS = $(CFLAGS) -I ../../../\r\nLIBS = $(LIBS) oleaut32.lib user32.lib\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaRam.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\String.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\Vector.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZInWindow.obj \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\n\r\nOBJS = \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $O\\LzmaRamDecode.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\LzmaRamDecode.obj: LzmaRamDecode.c\r\n\t$(COMPL_O1)\r\n$O\\LzmaDecode.obj: ../LZMA_C/LzmaDecode.c\r\n\t$(COMPL_O2)\r\n$O\\BranchX86.obj: ../Branch/BranchX86.c\r\n\t$(COMPL_O2)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c -I ../../../\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaRam.o \\\r\n  LzmaRamDecode.o \\\r\n  LzmaDecode.o \\\r\n  BranchX86.o \\\r\n  LZMADecoder.o \\\r\n  LZMAEncoder.o \\\r\n  LZInWindow.o \\\r\n  LZOutWindow.o \\\r\n  RangeCoderBit.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  Alloc.o \\\r\n  C_FileIO.o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  String.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  Vector.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaRam.o: LzmaRam.cpp\r\n\t$(CXX) $(CFLAGS) LzmaRam.cpp\r\n\r\nLzmaRamDecode.o: LzmaRamDecode.c\r\n\t$(CXX_C) $(CFLAGS) LzmaRamDecode.c\r\n\r\nLzmaDecode.o: ../LZMA_C/LzmaDecode.c\r\n\t$(CXX_C) $(CFLAGS) ../LZMA_C/LzmaDecode.c\r\n\r\nBranchX86.o: ../Branch/BranchX86.c\r\n\t$(CXX_C) $(CFLAGS) ../Branch/BranchX86.c\r\n\r\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\r\n\r\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\r\n\r\nLZInWindow.o: ../LZ/LZInWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp\r\n\r\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\r\n\r\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\r\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\nAlloc.o: ../../../Common/Alloc.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/Alloc.cpp\r\n\r\nC_FileIO.o: ../../../Common/C_FileIO.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nString.o: ../../../Common/String.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/String.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nVector.o: ../../../Common/Vector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/Vector.cpp\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_C/LzmaDecode.c",
    "content": "/*\r\n  LzmaDecode.c\r\n  LZMA Decoder (optimized for Speed version)\r\n  \r\n  LZMA SDK 4.22 Copyright (c) 1999-2005 Igor Pavlov (2005-06-10)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) \\\r\n  { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \\\r\n  BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}\r\n\r\n#define RC_INIT Buffer = BufferLim = 0; RC_INIT2\r\n\r\n#else\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#endif\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  const Byte *Buffer = vs->Buffer;\r\n  const Byte *BufferLim = vs->BufferLim;\r\n  #else\r\n  const Byte *Buffer = inStream;\r\n  const Byte *BufferLim = inStream + inSize;\r\n  #endif\r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      #ifdef _LZMA_IN_CB\r\n      RC_INIT;\r\n      #else\r\n      RC_INIT(inStream, inSize);\r\n      #endif\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  RC_INIT;\r\n  #else\r\n  RC_INIT(inStream, inSize);\r\n  #endif\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (Byte)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n            UpdateBit0(prob);\r\n            \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            \r\n            state = state < kNumLitStates ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = Buffer;\r\n  vs->BufferLim = BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_C/LzmaDecode.h",
    "content": "/* \r\n  LzmaDecode.h\r\n  LZMA Decoder interface\r\n\r\n  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMADECODE_H\r\n#define __LZMADECODE_H\r\n\r\n/* #define _LZMA_IN_CB */\r\n/* Use callback for input data */\r\n\r\n/* #define _LZMA_OUT_READ */\r\n/* Use read function for output data */\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_LOC_OPT */\r\n/* Enable local speed optimizations inside code */\r\n\r\n/* #define _LZMA_SYSTEM_SIZE_T */\r\n/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/\r\n\r\n#ifndef UInt32\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\n#define UInt32 unsigned long\r\n#else\r\n#define UInt32 unsigned int\r\n#endif\r\n#endif\r\n\r\n#ifndef SizeT\r\n#ifdef _LZMA_SYSTEM_SIZE_T\r\n#include <stddef.h>\r\n#define SizeT size_t\r\n#else\r\n#define SizeT UInt32\r\n#endif\r\n#endif\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb unsigned short\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#ifdef _LZMA_IN_CB\r\ntypedef struct _ILzmaInCallback\r\n{\r\n  int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);\r\n} ILzmaInCallback;\r\n#endif\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  #ifdef _LZMA_OUT_READ\r\n  UInt32 DictionarySize;\r\n  #endif\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  const unsigned char *Buffer;\r\n  const unsigned char *BufferLim;\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  unsigned char *Dictionary;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;\r\n  unsigned char TempDictionary[4];\r\n  #endif\r\n} CLzmaDecoderState;\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }\r\n#endif\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *inCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_C/LzmaDecodeSize.c",
    "content": "/*\r\n  LzmaDecodeSize.c\r\n  LZMA Decoder (optimized for Size version)\r\n  \r\n  LZMA SDK 4.27 Copyright (c) 1999-2005 Igor Pavlov (2005-08-07)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\ntypedef struct _CRangeDecoder\r\n{\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  #ifdef _LZMA_IN_CB\r\n  ILzmaInCallback *InCallback;\r\n  int Result;\r\n  #endif\r\n  int ExtraBytes;\r\n} CRangeDecoder;\r\n\r\nByte RangeDecoderReadByte(CRangeDecoder *rd)\r\n{\r\n  if (rd->Buffer == rd->BufferLim)\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    SizeT size;\r\n    rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);\r\n    rd->BufferLim = rd->Buffer + size;\r\n    if (size == 0)\r\n    #endif\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n  }\r\n  return (*rd->Buffer++);\r\n}\r\n\r\n/* #define ReadByte (*rd->Buffer++) */\r\n#define ReadByte (RangeDecoderReadByte(rd))\r\n\r\nvoid RangeDecoderInit(CRangeDecoder *rd\r\n  #ifndef _LZMA_IN_CB\r\n    , const Byte *stream, SizeT bufferSize\r\n  #endif\r\n    )\r\n{\r\n  int i;\r\n  #ifdef _LZMA_IN_CB\r\n  rd->Buffer = rd->BufferLim = 0;\r\n  #else\r\n  rd->Buffer = stream;\r\n  rd->BufferLim = stream + bufferSize;\r\n  #endif\r\n  rd->ExtraBytes = 0;\r\n  rd->Code = 0;\r\n  rd->Range = (0xFFFFFFFF);\r\n  for(i = 0; i < 5; i++)\r\n    rd->Code = (rd->Code << 8) | ReadByte;\r\n}\r\n\r\n#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;        \r\n#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;\r\n#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }\r\n\r\nUInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)\r\n{\r\n  RC_INIT_VAR\r\n  UInt32 result = 0;\r\n  int i;\r\n  for (i = numTotalBits; i != 0; i--)\r\n  {\r\n    /* UInt32 t; */\r\n    range >>= 1;\r\n\r\n    result <<= 1;\r\n    if (code >= range)\r\n    {\r\n      code -= range;\r\n      result |= 1;\r\n    }\r\n    /*\r\n    t = (code - range) >> 31;\r\n    t &= 1;\r\n    code -= range & (t - 1);\r\n    result = (result + result) | (1 - t);\r\n    */\r\n    RC_NORMALIZE\r\n  }\r\n  RC_FLUSH_VAR\r\n  return result;\r\n}\r\n\r\nint RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)\r\n{\r\n  UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;\r\n  if (rd->Code < bound)\r\n  {\r\n    rd->Range = bound;\r\n    *prob += (kBitModelTotal - *prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 0;\r\n  }\r\n  else\r\n  {\r\n    rd->Range -= bound;\r\n    rd->Code -= bound;\r\n    *prob -= (*prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 1;\r\n  }\r\n}\r\n\r\n#define RC_GET_BIT2(prob, mi, A0, A1) \\\r\n  UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \\\r\n  if (code < bound) \\\r\n    { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \\\r\n  else \\\r\n    { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)               \r\n\r\nint RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = numLevels; i != 0; i--)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT(prob, mi)\r\n    #else\r\n    mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return mi - (1 << numLevels);\r\n}\r\n\r\nint RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  int symbol = 0;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = 0; i < numLevels; i++)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))\r\n    #else\r\n    int bit = RangeDecoderBitDecode(probs + mi, rd);\r\n    mi = mi + mi + bit;\r\n    symbol |= (bit << i);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + symbol;\r\n    RC_GET_BIT(prob, symbol)\r\n    #else\r\n    symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n    #endif\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    int bit;\r\n    int matchBit = (matchByte >> 7) & 1;\r\n    matchByte <<= 1;\r\n    #ifdef _LZMA_LOC_OPT\r\n    {\r\n      CProb *prob = probs + 0x100 + (matchBit << 8) + symbol;\r\n      RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)\r\n    }\r\n    #else\r\n    bit = RangeDecoderBitDecode(probs + 0x100 + (matchBit << 8) + symbol, rd);\r\n    symbol = (symbol << 1) | bit;\r\n    #endif\r\n    if (matchBit != bit)\r\n    {\r\n      while (symbol < 0x100)\r\n      {\r\n        #ifdef _LZMA_LOC_OPT\r\n        CProb *prob = probs + symbol;\r\n        RC_GET_BIT(prob, symbol)\r\n        #else\r\n        symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n        #endif\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\nint LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)\r\n{\r\n  if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)\r\n    return RangeDecoderBitTreeDecode(p + LenLow +\r\n        (posState << kLenNumLowBits), kLenNumLowBits, rd);\r\n  if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)\r\n    return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +\r\n        (posState << kLenNumMidBits), kLenNumMidBits, rd);\r\n  return kLenNumLowSymbols + kLenNumMidSymbols + \r\n      RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);\r\n}\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  CRangeDecoder rd;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  rd.Range = vs->Range;\r\n  rd.Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  rd.Buffer = vs->Buffer;\r\n  rd.BufferLim = vs->BufferLim;\r\n  #else\r\n  rd.Buffer = inStream;\r\n  rd.BufferLim = inStream + inSize;\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RangeDecoderInit(&rd\r\n          #ifndef _LZMA_IN_CB\r\n          , inStream, inSize\r\n          #endif\r\n          );\r\n      #ifdef _LZMA_IN_CB\r\n      if (rd.Result != LZMA_RESULT_OK)\r\n        return rd.Result;\r\n      #endif\r\n      if (rd.ExtraBytes != 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  rd.Result = LZMA_RESULT_OK;\r\n  #endif\r\n  rd.ExtraBytes = 0;\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  #endif\r\n  RangeDecoderInit(&rd\r\n      #ifndef _LZMA_IN_CB\r\n      , inStream, inSize\r\n      #endif\r\n      );\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  if (rd.Result != LZMA_RESULT_OK)\r\n    return rd.Result;\r\n  #endif\r\n  if (rd.ExtraBytes != 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n    #ifdef _LZMA_IN_CB\r\n    if (rd.Result != LZMA_RESULT_OK)\r\n      return rd.Result;\r\n    #endif\r\n    if (rd.ExtraBytes != 0)\r\n      return LZMA_RESULT_DATA_ERROR;\r\n    if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n    {\r\n      CProb *probs = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        Byte matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);\r\n      }\r\n      else\r\n        previousByte = LzmaLiteralDecode(probs, &rd);\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)\r\n      {\r\n        if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)\r\n        {\r\n          if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n      \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n\r\n            state = state < 7 ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n            continue;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)\r\n            distance = rep1;\r\n          else \r\n          {\r\n            if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)\r\n              distance = rep2;\r\n            else\r\n            {\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        len = LzmaLenDecode(p + RepLenCoder, &rd, posState);\r\n        state = state < 7 ? 8 : 11;\r\n      }\r\n      else\r\n      {\r\n        int posSlot;\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < 7 ? 7 : 10;\r\n        len = LzmaLenDecode(p + LenCoder, &rd, posState);\r\n        posSlot = RangeDecoderBitTreeDecode(p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits), kNumPosSlotBits, &rd);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 += RangeDecoderReverseBitTreeDecode(\r\n                p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);\r\n          }\r\n          else\r\n          {\r\n            rep0 += RangeDecoderDecodeDirectBits(&rd, \r\n                numDirectBits - kNumAlignBits) << kNumAlignBits;\r\n            rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = rd.Range;\r\n  vs->Code = rd.Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = rd.Buffer;\r\n  vs->BufferLim = rd.BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(rd.Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_C/LzmaStateDecode.c",
    "content": "/*\r\n  LzmaStateDecode.c\r\n  LZMA Decoder (State version)\r\n  \r\n  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\n/* kRequiredInBufferSize = number of required input bytes for worst case: \r\n   longest match with longest distance.\r\n   kLzmaInBufferSize must be larger than kRequiredInBufferSize \r\n   23 bits = 2 (match select) + 10 (len) + 6 (distance) + 4(align) + 1 (RC_NORMALIZE)\r\n*/\r\n\r\n#define kRequiredInBufferSize ((23 * (kNumBitModelTotalBits - kNumMoveBits + 1) + 26 + 9) / 8)\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n    return LZMA_RESULT_OK;\r\n  }\r\n}\r\n\r\nint LzmaDecode(\r\n    CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding)\r\n{\r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n\r\n  unsigned char *Buffer = vs->Buffer;\r\n  int BufferSize = vs->BufferSize; /* don't change it to unsigned int */\r\n  CProb *p = vs->Probs;\r\n\r\n  int state = vs->State;\r\n  unsigned char previousByte;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  SizeT nowPos = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  unsigned char *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  unsigned char tempDictionary[4];\r\n\r\n  (*inSizeProcessed) = 0;\r\n  (*outSizeProcessed) = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n    {\r\n      Buffer[BufferSize++] = *inStream++;\r\n      (*inSizeProcessed)++;\r\n      inSize--;\r\n    }\r\n    if (BufferSize < 5)\r\n    {\r\n      vs->BufferSize = BufferSize;\r\n      return finishDecoding ? LZMA_RESULT_DATA_ERROR : LZMA_RESULT_OK;\r\n    }\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RC_INIT;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  while(1)\r\n  {\r\n    int bufferPos = (int)(Buffer - vs->Buffer);\r\n    if (BufferSize - bufferPos < kRequiredInBufferSize)\r\n    {\r\n      int i;\r\n      BufferSize -= bufferPos;\r\n      if (BufferSize < 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n      for (i = 0; i < BufferSize; i++)\r\n        vs->Buffer[i] = Buffer[i];\r\n      Buffer = vs->Buffer;\r\n      while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n      {\r\n        Buffer[BufferSize++] = *inStream++;\r\n        (*inSizeProcessed)++;\r\n        inSize--;\r\n      }\r\n      if (BufferSize < kRequiredInBufferSize && !finishDecoding)\r\n        break;\r\n    }\r\n    if (nowPos >= outSize)\r\n      break;\r\n    {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)((nowPos + globalPos) & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        ((((nowPos + globalPos)& literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (unsigned char)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            UInt32 pos;\r\n            UpdateBit0(prob);\r\n            if (distanceLimit == 0)\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            outStream[nowPos++] = previousByte;\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      if (rep0 > distanceLimit) \r\n        return LZMA_RESULT_DATA_ERROR;\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n\r\n      do\r\n      {\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  BufferSize -= (int)(Buffer - vs->Buffer);\r\n  if (BufferSize < 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    int i;\r\n    for (i = 0; i < BufferSize; i++)\r\n      vs->Buffer[i] = Buffer[i];\r\n  }\r\n  vs->BufferSize = BufferSize;\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = (UInt32)(globalPos + nowPos);\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n\r\n  (*outSizeProcessed) = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_C/LzmaStateDecode.h",
    "content": "/* \r\n  LzmaStateDecode.h\r\n  LZMA Decoder interface (State version)\r\n\r\n  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMASTATEDECODE_H\r\n#define __LZMASTATEDECODE_H\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_SYSTEM_SIZE_T */\r\n/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/\r\n\r\n\r\n#ifndef UInt32\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\n#define UInt32 unsigned long\r\n#else\r\n#define UInt32 unsigned int\r\n#endif\r\n#endif\r\n\r\n#ifndef SizeT\r\n#ifdef _LZMA_SYSTEM_SIZE_T\r\n#include <stddef.h>\r\n#define SizeT size_t\r\n#else\r\n#define SizeT UInt32\r\n#endif\r\n#endif\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb unsigned short\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  UInt32 DictionarySize;\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))\r\n\r\n#define kLzmaInBufferSize 64   /* don't change it. it must be larger than kRequiredInBufferSize */\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n  unsigned char *Dictionary;\r\n\r\n  unsigned char Buffer[kLzmaInBufferSize];\r\n  int BufferSize;\r\n\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;  /* -2: decoder needs internal initialization\r\n                     -1: stream was finished, \r\n                      0: ok\r\n                    > 0: need to write RemainLen bytes as match Reps[0],\r\n                  */\r\n  unsigned char TempDictionary[4];  /* it's required when DictionarySize = 0 */\r\n} CLzmaDecoderState;\r\n\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }\r\n\r\n/* LzmaDecode: decoding from input stream to output stream.\r\n  If finishDecoding != 0, then there are no more bytes in input stream\r\n  after inStream[inSize - 1]. */\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize,  SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_C/LzmaStateTest.c",
    "content": "/* \r\nLzmaStateTest.c\r\nTest application for LZMA Decoder (State version)\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\n#define kInBufferSize (1 << 15)\r\n#define kOutBufferSize (1 << 15)\r\n\r\nunsigned char g_InBuffer[kInBufferSize];\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n  { return fread(data, 1, size, file); }\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size); }\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0; \r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  int i;\r\n  int res = 0;\r\n  CLzmaDecoderState state;  /* it's about 140 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n  SizeT inAvail = 0;\r\n  unsigned char *inBuffer = 0;\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n  \r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    unsigned char b;\r\n    if (!MyReadFileAndCheck(inFile, &b, 1))\r\n      return PrintError(rs, kCantReadMessage);\r\n    if (b != 0xFF)\r\n      waitEOS = 0;\r\n    if (i < 4)\r\n      outSize += (UInt32)(b) << (i * 8);\r\n    else\r\n      outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  \r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      free(state.Probs);\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    }\r\n  }\r\n  \r\n  /* Decompress */\r\n  \r\n  LzmaDecoderInit(&state);\r\n  \r\n  do\r\n  {\r\n    SizeT inProcessed, outProcessed;\r\n    int finishDecoding;\r\n    UInt32 outAvail = kOutBufferSize;\r\n    if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n      outAvail = outSize;\r\n    if (inAvail == 0)\r\n    {\r\n      inAvail = (SizeT)MyReadFile(inFile, g_InBuffer, kInBufferSize);\r\n      inBuffer = g_InBuffer;\r\n    }\r\n    finishDecoding = (inAvail == 0);\r\n    res = LzmaDecode(&state,\r\n        inBuffer, inAvail, &inProcessed,\r\n        g_OutBuffer, outAvail, &outProcessed,\r\n        finishDecoding);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n      break;\r\n    }\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n    \r\n    if (outFile != 0)  \r\n      if (fwrite(g_OutBuffer, 1, outProcessed, outFile) != outProcessed)\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n        break;\r\n      }\r\n      \r\n    if (outSize < outProcessed)\r\n      outSizeHigh--;\r\n    outSize -= (UInt32)outProcessed;\r\n    outSize &= 0xFFFFFFFF;\r\n\r\n    if (outProcessed == 0 && finishDecoding)\r\n    {\r\n      if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n        res = 1;\r\n      break;\r\n    }\r\n  }\r\n  while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n\r\n  free(state.Dictionary);\r\n  free(state.Probs);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-02\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_C/LzmaTest.c",
    "content": "/* \r\nLzmaTest.c\r\nTest application for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-05)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fread(data, 1, size, file); \r\n}\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size);} \r\n\r\nsize_t MyWriteFile(FILE *file, const void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fwrite(data, 1, size, file); \r\n}\r\n\r\nint MyWriteFileAndCheck(FILE *file, const void *data, size_t size)\r\n  { return (MyWriteFile(file, data, size) == size); }\r\n\r\n#ifdef _LZMA_IN_CB\r\n#define kInBufferSize (1 << 15)\r\ntypedef struct _CBuffer\r\n{\r\n  ILzmaInCallback InCallback;\r\n  FILE *File;\r\n  unsigned char Buffer[kInBufferSize];\r\n} CBuffer;\r\n\r\nint LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CBuffer *b = (CBuffer *)object;\r\n  *buffer = b->Buffer;\r\n  *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);\r\n  return LZMA_RESULT_OK;\r\n}\r\nCBuffer g_InBuffer;\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define kOutBufferSize (1 << 15)\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n#endif\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0;\r\n  #ifndef _LZMA_OUT_READ\r\n  SizeT outSizeFull;\r\n  unsigned char *outStream;\r\n  #endif\r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  SizeT compressedSize;\r\n  unsigned char *inStream;\r\n  #endif\r\n\r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n  int res;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.File = inFile;\r\n  #endif\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  {\r\n    long length;\r\n    fseek(inFile, 0, SEEK_END);\r\n    length = ftell(inFile);\r\n    fseek(inFile, 0, SEEK_SET);\r\n    if ((long)(SizeT)length != length)\r\n      return PrintError(rs, \"Too big compressed stream\");\r\n    compressedSize = (SizeT)(length - (LZMA_PROPERTIES_SIZE + 8));\r\n  }\r\n  #endif\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n\r\n  {\r\n    int i;\r\n    for (i = 0; i < 8; i++)\r\n    {\r\n      unsigned char b;\r\n      if (!MyReadFileAndCheck(inFile, &b, 1))\r\n        return PrintError(rs, kCantReadMessage);\r\n      if (b != 0xFF)\r\n        waitEOS = 0;\r\n      if (i < 4)\r\n        outSize += (UInt32)(b) << (i * 8);\r\n      else\r\n        outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n    }\r\n    \r\n    #ifndef _LZMA_OUT_READ\r\n    if (waitEOS)\r\n      return PrintError(rs, \"Stream with EOS marker is not supported\");\r\n    outSizeFull = (SizeT)outSize;\r\n    if (sizeof(SizeT) >= 8)\r\n      outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);\r\n    else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)\r\n      return PrintError(rs, \"Too big uncompressed stream\");\r\n    #endif\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n  #else\r\n  if (outSizeFull == 0)\r\n    outStream = 0;\r\n  else\r\n    outStream = (unsigned char *)malloc(outSizeFull);\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  if (compressedSize == 0)\r\n    inStream = 0;\r\n  else\r\n    inStream = (unsigned char *)malloc(compressedSize);\r\n  #endif\r\n\r\n  if (state.Probs == 0 \r\n    #ifdef _LZMA_OUT_READ\r\n    || (state.Dictionary == 0 && state.Properties.DictionarySize != 0)\r\n    #else\r\n    || (outStream == 0 && outSizeFull != 0)\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    || (inStream == 0 && compressedSize != 0)\r\n    #endif\r\n    )\r\n  {\r\n    free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    free(state.Dictionary);\r\n    #else\r\n    free(outStream);\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    free(inStream);\r\n    #endif\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  }\r\n\r\n  /* Decompress */\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  #else\r\n  if (!MyReadFileAndCheck(inFile, inStream, compressedSize))\r\n    return PrintError(rs, kCantReadMessage);\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inAvail = compressedSize;\r\n    const unsigned char *inBuffer = inStream;\r\n    #endif\r\n    LzmaDecoderInit(&state);\r\n    do\r\n    {\r\n      #ifndef _LZMA_IN_CB\r\n      SizeT inProcessed;\r\n      #endif\r\n      SizeT outProcessed;\r\n      SizeT outAvail = kOutBufferSize;\r\n      if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n        outAvail = (SizeT)outSize;\r\n      res = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &g_InBuffer.InCallback,\r\n        #else\r\n        inBuffer, inAvail, &inProcessed,\r\n        #endif\r\n        g_OutBuffer, outAvail, &outProcessed);\r\n      if (res != 0)\r\n      {\r\n        sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n        res = 1;\r\n        break;\r\n      }\r\n      #ifndef _LZMA_IN_CB\r\n      inAvail -= inProcessed;\r\n      inBuffer += inProcessed;\r\n      #endif\r\n      \r\n      if (outFile != 0)  \r\n        if (!MyWriteFileAndCheck(outFile, g_OutBuffer, (size_t)outProcessed))\r\n        {\r\n          PrintError(rs, kCantWriteMessage);\r\n          res = 1;\r\n          break;\r\n        }\r\n        \r\n      if (outSize < outProcessed)\r\n        outSizeHigh--;\r\n      outSize -= (UInt32)outProcessed;\r\n      outSize &= 0xFFFFFFFF;\r\n        \r\n      if (outProcessed == 0)\r\n      {\r\n        if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n          res = 1;\r\n        break;\r\n      }\r\n    }\r\n    while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n  }\r\n\r\n  #else\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inProcessed;\r\n    #endif\r\n    SizeT outProcessed;\r\n    res = LzmaDecode(&state,\r\n      #ifdef _LZMA_IN_CB\r\n      &g_InBuffer.InCallback,\r\n      #else\r\n      inStream, compressedSize, &inProcessed,\r\n      #endif\r\n      outStream, outSizeFull, &outProcessed);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n    }\r\n    else if (outFile != 0)\r\n    {\r\n      if (!MyWriteFileAndCheck(outFile, outStream, (size_t)outProcessed))\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  free(state.Dictionary);\r\n  #else\r\n  free(outStream);\r\n  #endif\r\n  #ifndef _LZMA_IN_CB\r\n  free(inStream);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-05\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_C/makefile",
    "content": "PROG = lzmaDec.exe\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nOBJS = \\\r\n  $O\\LzmaTest.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$O\\LzmaTest.obj: $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/LZMA_C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_C/makefile.gcc",
    "content": "PROG = lzmadec\r\nCXX = gcc \r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall -pedantic -D _LZMA_PROB32 \r\n\r\nOBJS = LzmaTest.o LzmaDecode.o \r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\nLzmaTest.o: LzmaTest.c\r\n\t$(CXX) $(CFLAGS) LzmaTest.c\r\n\r\nLzmaDecode.o: LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) LzmaDecode.c\r\n\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Lib/ZLib.cpp",
    "content": "/*\r\n * lzma zlib simplified wrapper\r\n *\r\n * Copyright (c) 2005-2006 Oleg I. Vdovikin <oleg@cs.msu.su>\r\n *\r\n * This library is free software; you can redistribute \r\n * it and/or modify it under the terms of the GNU Lesser \r\n * General Public License as published by the Free Software \r\n * Foundation; either version 2.1 of the License, or \r\n * (at your option) any later version.\r\n *\r\n * This library is distributed in the hope that it will be \r\n * useful, but WITHOUT ANY WARRANTY; without even the implied \r\n * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r\n * PURPOSE. See the GNU Lesser General Public License \r\n * for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General \r\n * Public License along with this library; if not, write to \r\n * the Free Software Foundation, Inc., 59 Temple Place, \r\n * Suite 330, Boston, MA 02111-1307 USA \r\n */\r\n\r\n/*\r\n * default values for encoder/decoder used by wrapper\r\n */\r\n\r\n#include <zlib.h>\r\n\r\n#define ZLIB_LC 3\r\n#define ZLIB_LP 0\r\n#define ZLIB_PB 2\r\n\r\n#ifdef WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#endif\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#define STG_E_SEEKERROR                  ((HRESULT)0x80030019L)\r\n#define STG_E_MEDIUMFULL                 ((HRESULT)0x80030070L)\r\n\r\nclass CInMemoryStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CInMemoryStream(const Bytef *data, UInt64 size) : \r\n\t  m_data(data), m_size(size), m_offset(0) {}\r\n\r\n  virtual ~CInMemoryStream() {}\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\t  if (size > m_size - m_offset) \r\n\t\t  size = m_size - m_offset;\r\n\r\n\t  if (size) {\r\n\t\t  memcpy(data, m_data + m_offset, size);\r\n\t  }\r\n\r\n\t  m_offset += size;\r\n\r\n\t  if (processedSize) \r\n\t\t  *processedSize = size;\r\n\r\n\t  return S_OK;\r\n  }\r\n\r\n  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\treturn Read(data, size, processedSize);\r\n  }\r\n\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n  {\r\n\t  UInt64 _offset;\r\n\r\n\t  if (seekOrigin == STREAM_SEEK_SET) _offset = offset;\r\n\t  else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset; \r\n\t  else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;\r\n\t  else return STG_E_INVALIDFUNCTION;\r\n\r\n\t  if (_offset < 0 || _offset > m_size)\r\n\t\t  return STG_E_SEEKERROR;\r\n\r\n\t  m_offset = _offset;\r\n\r\n\t  if (newPosition)\r\n\t\t  *newPosition = m_offset;\r\n\r\n\t  return S_OK;\r\n  }\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size)\r\n  {\r\n\t  *size = m_size;\r\n\t  return S_OK;\r\n  }\r\nprotected:\r\n\tconst Bytef *m_data;\r\n\tUInt64 m_size;\r\n\tUInt64 m_offset;\r\n};\r\n\r\nclass COutMemoryStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  COutMemoryStream(Bytef *data, UInt64 maxsize) : \r\n\t  m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}\r\n  virtual ~COutMemoryStream() {}\r\n  \r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\t  if (size > m_maxsize - m_offset) \r\n\t\t  size = m_maxsize - m_offset;\r\n\r\n\t  if (size) {\r\n\t\t  memcpy(m_data + m_offset, data, size);\r\n\t  }\r\n\r\n\t  m_offset += size;\r\n\r\n\t  if (m_offset > m_size)\r\n\t\tm_size = m_offset;\r\n\r\n\t  if (processedSize) \r\n\t\t  *processedSize = size;\r\n\r\n\t  return S_OK;\r\n  }\r\n  \r\n  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\t  return Write(data, size, processedSize);\r\n  }\r\n\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n  {\r\n\t  UInt64 _offset;\r\n\r\n\t  if (seekOrigin == STREAM_SEEK_SET) _offset = offset;\r\n\t  else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset; \r\n\t  else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;\r\n\t  else return STG_E_INVALIDFUNCTION;\r\n\r\n\t  if (_offset < 0 || _offset > m_maxsize)\r\n\t\t  return STG_E_SEEKERROR;\r\n\r\n\t  m_offset = _offset;\r\n\r\n\t  if (newPosition)\r\n\t\t  *newPosition = m_offset;\r\n\r\n\t  return S_OK;\r\n  }\r\n  \r\n  STDMETHOD(SetSize)(Int64 newSize)\r\n  {\r\n\t  if ((UInt64)newSize > m_maxsize) \r\n\t\t  return STG_E_MEDIUMFULL;\r\n\r\n\t  return S_OK;\r\n  }\r\nprotected:\r\n\tBytef *m_data;\r\n\tUInt64 m_size;\r\n\tUInt64 m_maxsize;\r\n\tUInt64 m_offset;\r\n};\r\n\r\nZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,\r\n                                  const Bytef *source, uLong sourceLen,\r\n                                  int level))\r\n{\r\n\tCInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);\r\n\tCMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\t\r\n\tCOutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);\r\n\tCMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n\t\r\n\tNCompress::NLZMA::CEncoder *encoderSpec = \r\n\t\tnew NCompress::NLZMA::CEncoder;\r\n\tCMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\t\r\n\tPROPID propIDs[] = \r\n\t{\r\n\t\tNCoderPropID::kDictionarySize,\r\n\t\tNCoderPropID::kPosStateBits,\r\n\t\tNCoderPropID::kLitContextBits,\r\n\t\tNCoderPropID::kLitPosBits,\r\n\t\tNCoderPropID::kAlgorithm,\r\n\t\tNCoderPropID::kNumFastBytes,\r\n\t\tNCoderPropID::kMatchFinder,\r\n\t\tNCoderPropID::kEndMarker\r\n\t};\r\n\tconst int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\t\r\n\tPROPVARIANT properties[kNumProps];\r\n\tfor (int p = 0; p < 6; p++)\r\n\t\tproperties[p].vt = VT_UI4;\r\n\tproperties[0].ulVal = UInt32(1 << (level + 14));\r\n\tproperties[1].ulVal = UInt32(ZLIB_PB);\r\n\tproperties[2].ulVal = UInt32(ZLIB_LC); // for normal files\r\n\tproperties[3].ulVal = UInt32(ZLIB_LP); // for normal files\r\n\tproperties[4].ulVal = UInt32(2);\r\n\tproperties[5].ulVal = UInt32(128);\r\n\t\r\n\tproperties[6].vt = VT_BSTR;\r\n\tproperties[6].bstrVal = (BSTR)(const wchar_t *)L\"BT4\";\r\n\t\r\n\tproperties[7].vt = VT_BOOL;\r\n\tproperties[7].boolVal = VARIANT_TRUE;\r\n\t\r\n\tif (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n\t\treturn Z_MEM_ERROR; // should not happen\r\n\t\r\n\tHRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n\tif (result == E_OUTOFMEMORY)\r\n\t{\r\n\t\treturn Z_MEM_ERROR;\r\n\t}   \r\n\telse if (result != S_OK)\r\n\t{\r\n\t\treturn Z_BUF_ERROR;\t// should not happen\r\n\t}   \r\n\t\r\n\tUInt64 fileSize;\r\n\toutStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);\r\n\t*destLen = fileSize;\r\n\t\r\n\treturn Z_OK;\r\n}\r\n\r\nZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,\r\n                                   const Bytef *source, uLong sourceLen))\r\n{\r\n\t/* CJH: 7zip ID implemented by some LZMA implementations */\r\n\tif(strncmp((char *) source, \"7zip\", 4) == 0)\r\n\t{\r\n\t\tsource += 4;\r\n\t\tsourceLen -= 4;\r\n\t}\r\n\r\n\tCInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);\r\n\tCMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\t\r\n\tCOutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);\r\n\tCMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n\t\r\n\tNCompress::NLZMA::CDecoder *decoderSpec = \r\n\t\tnew NCompress::NLZMA::CDecoder;\r\n\tCMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n\t\r\n\tif (decoderSpec->SetDecoderPropertiesRaw(ZLIB_LC, \r\n\t\tZLIB_LP, ZLIB_PB, (1 << 23)) != S_OK) return Z_DATA_ERROR;\r\n\t\r\n\tUInt64 fileSize = *destLen;\r\n\t\r\n\tif (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n\t{\r\n\t\treturn Z_DATA_ERROR;\r\n\t}\r\n\t\r\n\toutStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);\r\n\t*destLen = fileSize;\r\n\t\r\n\treturn Z_OK;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/LZMA_Lib/makefile",
    "content": "PROG = liblzma.a\nCXX = g++ -O3 -Wall\nAR = ar\nRM = rm -f\nCFLAGS = -c  -I ../../../\n\nOBJS = \\\n  ZLib.o \\\n  LZMADecoder.o \\\n  LZMAEncoder.o \\\n  LZInWindow.o \\\n  LZOutWindow.o \\\n  RangeCoderBit.o \\\n  InBuffer.o \\\n  OutBuffer.o \\\n  FileStreams.o \\\n  Alloc.o \\\n  C_FileIO.o \\\n  CommandLineParser.o \\\n  CRC.o \\\n  StreamUtils.o \\\n  String.o \\\n  StringConvert.o \\\n  StringToInt.o \\\n  Vector.o \\\n\n\nall: $(PROG)\n\n$(PROG): $(OBJS)\n\t$(AR) r $(PROG) $(OBJS)\n\nZLib.o: ZLib.cpp\n\t$(CXX) $(CFLAGS) ZLib.cpp\n\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\n\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\n\nLZInWindow.o: ../LZ/LZInWindow.cpp\n\t$(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp\n\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\n\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\n\nInBuffer.o: ../../Common/InBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\n\nOutBuffer.o: ../../Common/OutBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\n\nStreamUtils.o: ../../Common/StreamUtils.cpp\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\n\nFileStreams.o: ../../Common/FileStreams.cpp\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\n\nAlloc.o: ../../../Common/Alloc.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/Alloc.cpp\n\nC_FileIO.o: ../../../Common/C_FileIO.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp\n\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\n\nCRC.o: ../../../Common/CRC.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\n\nMyWindows.o: ../../../Common/MyWindows.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\n\nString.o: ../../../Common/String.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/String.cpp\n\nStringConvert.o: ../../../Common/StringConvert.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\n\nStringToInt.o: ../../../Common/StringToInt.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\n\nVector.o: ../../../Common/Vector.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/Vector.cpp\n\nclean:\n\t-$(RM) $(PROG) $(OBJS)\n\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/RangeCoder/RangeCoder.h",
    "content": "// Compress/RangeCoder/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_H\r\n#define __COMPRESS_RANGECODER_H\r\n\r\n#include \"../../Common/InBuffer.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1; \r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) \r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);                      \r\n    } \r\n    _cacheSize++;                               \r\n    Low = (UInt32)Low << 8;                           \r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numTotalBits)\r\n  {\r\n    for (int i = numTotalBits - 1; i >= 0; i--)\r\n    {\r\n      Range >>= 1;\r\n      if (((value >> i) & 1) == 1)\r\n        Low += Range;\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;        \r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8; \r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/RangeCoder/RangeCoderBit.cpp",
    "content": "// Compress/RangeCoder/RangeCoderBit.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nUInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\nstatic CPriceTables g_PriceTables;\r\n\r\nCPriceTables::CPriceTables() { Init(); }\r\n\r\nvoid CPriceTables::Init()\r\n{\r\n  const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n  for(int i = kNumBits - 1; i >= 0; i--)\r\n  {\r\n    UInt32 start = 1 << (kNumBits - i - 1);\r\n    UInt32 end = 1 << (kNumBits - i);\r\n    for (UInt32 j = start; j < end; j++)\r\n      ProbPrices[j] = (i << kNumBitPriceShiftBits) + \r\n          (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n  }\r\n\r\n  /*\r\n  // simplest: bad solution\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = kBitPrice;\r\n  */\r\n  \r\n  /*\r\n  const double kDummyMultMid = (1.0 / kBitPrice) / 2;\r\n  const double kDummyMultMid = 0;\r\n  // float solution\r\n  double ln2 = log(double(2));\r\n  double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);\r\n  */\r\n  \r\n  /*\r\n  // experimental, slow, solution:\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n  {\r\n    const int kCyclesBits = 5;\r\n    const UInt32 kCycles = (1 << kCyclesBits);\r\n\r\n    UInt32 range = UInt32(-1);\r\n    UInt32 bitCount = 0;\r\n    for (UInt32 j = 0; j < kCycles; j++)\r\n    {\r\n      range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n      range *= i;\r\n      while(range < (1 << 31))\r\n      {\r\n        range <<= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    bitCount <<= kNumBitPriceShiftBits;\r\n    range -= (1 << 31);\r\n    for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)\r\n    {\r\n      range <<= 1;\r\n      if (range > (1 << 31))\r\n      {\r\n        bitCount += (1 << k);\r\n        range -= (1 << 31);\r\n      }\r\n    }\r\n    ProbPrices[i] = (bitCount \r\n      // + (1 << (kCyclesBits - 1))\r\n      ) >> kCyclesBits;\r\n  }\r\n  */\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/RangeCoder/RangeCoderBit.h",
    "content": "// Compress/RangeCoder/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_H\r\n#define __COMPRESS_RANGECODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 2;\r\n\r\nconst int kNumBitPriceShiftBits = 6;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nclass CPriceTables\r\n{\r\npublic:\r\n  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  static void Init();\r\n  CPriceTables();\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return CPriceTables::ProbPrices[\r\n      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/RangeCoder/RangeCoderBitTree.h",
    "content": "// Compress/RangeCoder/RangeCoderBitTree.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_TREE_H\r\n#define __COMPRESS_RANGECODER_BIT_TREE_H\r\n\r\n#include \"RangeCoderBit.h\"\r\n#include \"RangeCoderOpt.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeEncoder\r\n{\r\n  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  void Encode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int bitIndex = NumBitLevels; bitIndex != 0 ;)\r\n    {\r\n      bitIndex--;\r\n      UInt32 bit = (symbol >> bitIndex) & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n  };\r\n  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int i = 0; i < NumBitLevels; i++)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n      symbol >>= 1;\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    symbol |= (1 << NumBitLevels);\r\n    UInt32 price = 0;\r\n    while (symbol != 1)\r\n    {\r\n      price += Models[symbol >> 1].GetPrice(symbol & 1);\r\n      symbol >>= 1;\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 ReverseGetPrice(UInt32 symbol) const\r\n  {\r\n    UInt32 price = 0;\r\n    UInt32 modelIndex = 1;\r\n    for (int i = NumBitLevels; i != 0; i--)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      symbol >>= 1;\r\n      price += Models[modelIndex].GetPrice(bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n    return price;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeDecoder\r\n{\r\n  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  UInt32 Decode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n    {\r\n      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);\r\n      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)\r\n    }\r\n    RC_FLUSH_VAR\r\n    return modelIndex - (1 << NumBitLevels);\r\n  };\r\n  UInt32 ReverseDecode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    UInt32 symbol = 0;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n    {\r\n      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n      // modelIndex <<= 1;\r\n      // modelIndex += bit;\r\n      // symbol |= (bit << bitIndex);\r\n      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n    }\r\n    RC_FLUSH_VAR\r\n    return symbol;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nvoid ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models, \r\n    CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  for (int i = 0; i < NumBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    Models[modelIndex].Encode(rangeEncoder, bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models, \r\n    UInt32 NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 modelIndex = 1;\r\n  for (int i = NumBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += Models[modelIndex].GetPrice(bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models, \r\n    CDecoder *rangeDecoder, int NumBitLevels)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  UInt32 symbol = 0;\r\n  RC_INIT_VAR\r\n  for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n  {\r\n    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n    // modelIndex <<= 1;\r\n    // modelIndex += bit;\r\n    // symbol |= (bit << bitIndex);\r\n    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n  }\r\n  RC_FLUSH_VAR\r\n  return symbol;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/RangeCoder/RangeCoderOpt.h",
    "content": "// Compress/RangeCoder/RangeCoderOpt.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_OPT_H\r\n#define __COMPRESS_RANGECODER_OPT_H\r\n\r\n#define RC_INIT_VAR \\\r\n  UInt32 range = rangeDecoder->Range; \\\r\n  UInt32 code = rangeDecoder->Code;        \r\n\r\n#define RC_FLUSH_VAR \\\r\n  rangeDecoder->Range = range; \\\r\n  rangeDecoder->Code = code;\r\n\r\n#define RC_NORMALIZE \\\r\n  if (range < NCompress::NRangeCoder::kTopValue) \\\r\n    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }\r\n\r\n#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \\\r\n  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \\\r\n  if (code < bound) \\\r\n  { A0; range = bound; \\\r\n    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \\\r\n    mi <<= 1; } \\\r\n  else \\\r\n  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \\\r\n    mi = (mi + mi) + 1; }} \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/Compress/RangeCoder/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n// \"23170F69-40C1-278A-0000-000400xx0000\"\r\n#define CODER_INTERFACE(i, x) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \\\r\nstruct i: public IUnknown\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, \r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kNumPasses = 0x460, \r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block \r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n// \"23170F69-40C1-278A-0000-000300xx0000\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, b, x) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \\\r\nstruct i: public b\r\n\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream, \r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/Alloc.cpp",
    "content": "// Common/Alloc.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount++);\r\n  #endif\r\n  return ::malloc(size);\r\n}\r\n\r\nvoid MyFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d\", --g_allocCount);\r\n  #endif\r\n  \r\n  ::free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  ::VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\nstatic SIZE_T g_LargePageSize = \r\n    #ifdef _WIN64\r\n    (1 << 21);\r\n    #else\r\n    (1 << 22);\r\n    #endif\r\n\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n\r\nbool SetLargePageSize()\r\n{\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return false;\r\n  SIZE_T size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return false;\r\n  g_LargePageSize = size;\r\n  return true;\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  if (size >= (1 << 18))\r\n  {\r\n    void *res = ::VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), \r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  ::VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/Alloc.h",
    "content": "// Common/Alloc.h\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size) throw();\r\nvoid MyFree(void *address) throw();\r\n\r\n#ifdef _WIN32\r\n\r\nbool SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size) throw();\r\nvoid MidFree(void *address) throw();\r\nvoid *BigAlloc(size_t size) throw();\r\nvoid BigFree(void *address) throw();\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CRC.h\"\r\n\r\nstatic const UInt32 kCRCPoly = 0xEDB88320;\r\n\r\nUInt32 CCRC::Table[256];\r\n\r\nvoid CCRC::InitTable()\r\n{\r\n  for (UInt32 i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    for (int j = 0; j < 8; j++)\r\n      if (r & 1) \r\n        r = (r >> 1) ^ kCRCPoly;\r\n      else     \r\n        r >>= 1;\r\n    CCRC::Table[i] = r;\r\n  }\r\n}\r\n\r\nclass CCRCTableInit\r\n{\r\npublic:\r\n  CCRCTableInit() { CCRC::InitTable(); }\r\n} g_CRCTableInit;\r\n\r\nvoid CCRC::UpdateByte(Byte b)\r\n{\r\n  _value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);\r\n}\r\n\r\nvoid CCRC::UpdateUInt16(UInt16 v)\r\n{\r\n  UpdateByte(Byte(v));\r\n  UpdateByte(Byte(v >> 8));\r\n}\r\n\r\nvoid CCRC::UpdateUInt32(UInt32 v)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n    UpdateByte((Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CCRC::UpdateUInt64(UInt64 v)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n    UpdateByte((Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CCRC::Update(const void *data, size_t size)\r\n{\r\n  UInt32 v = _value;\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);\r\n  _value = v;\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/Common/CRC.h",
    "content": "// Common/CRC.h\r\n\r\n#ifndef __COMMON_CRC_H\r\n#define __COMMON_CRC_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nclass CCRC\r\n{\r\n  UInt32 _value;\r\npublic:\r\n\tstatic UInt32 Table[256];\r\n\tstatic void InitTable();\r\n\r\n  CCRC():  _value(0xFFFFFFFF){};\r\n  void Init() { _value = 0xFFFFFFFF; }\r\n  void UpdateByte(Byte v);\r\n  void UpdateUInt16(UInt16 v);\r\n  void UpdateUInt32(UInt32 v);\r\n  void UpdateUInt64(UInt64 v);\r\n  void Update(const void *data, size_t size);\r\n  UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } \r\n  static UInt32 CalculateDigest(const void *data, size_t size)\r\n  {\r\n    CCRC crc;\r\n    crc.Update(data, size);\r\n    return crc.GetDigest();\r\n  }\r\n  static bool VerifyDigest(UInt32 digest, const void *data, size_t size)\r\n  {\r\n    return (CalculateDigest(data, size) == digest);\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/lzma/C/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else \r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  while (true)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      return;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{ \r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */); \r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms, \r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0) \r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while(pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len) \r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString: \r\n      case NSwitchType::kUnLimitedPostString: \r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for(int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString)\r\n{\r\n  for(int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if(commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\nbool ParseSubCharsCommand(int numForms, const CCommandSubCharsSet *forms, \r\n    const UString &commandString, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numUsedChars = 0;\r\n  for(int i = 0; i < numForms; i++)\r\n  {\r\n    const CCommandSubCharsSet &set = forms[i];\r\n    int currentIndex = -1;\r\n    int len = MyStringLen(set.Chars);\r\n    for(int j = 0; j < len; j++)\r\n    {\r\n      wchar_t c = set.Chars[j];\r\n      int newIndex = commandString.Find(c);\r\n      if (newIndex >= 0)\r\n      {\r\n        if (currentIndex >= 0)\r\n          return false;\r\n        if (commandString.Find(c, newIndex + 1) >= 0)\r\n          return false;\r\n        currentIndex = j;\r\n        numUsedChars++;\r\n      }\r\n    }\r\n    if(currentIndex == -1 && !set.EmptyAllowed)\r\n      return false;\r\n    indices.Add(currentIndex);\r\n  }\r\n  return (numUsedChars == commandString.Length());\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"Common/String.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  { \r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms); \r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms, \r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString);\r\n\r\nstruct CCommandSubCharsSet\r\n{\r\n  wchar_t *Chars;\r\n  bool EmptyAllowed;\r\n};\r\n\r\n// Returns: indices of finded chars; -1 if there is no match\r\nbool ParseSubCharsCommand(int numForms, const CCommandSubCharsSet *forms, \r\n    const UString &commandString, CIntVector &indices);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p) \r\n  { \r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p) \r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR() { m_str = NULL; }\r\n  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR pSrc)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(pSrc);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const \r\n  { \r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memmove(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  void Attach(BSTR src) {  m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) { \r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline bool operator==(REFGUID g1, REFGUID g2)\r\n{ \r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return false;\r\n  return true;\r\n}\r\ninline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct \r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else \r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#else\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall \r\n#else\r\n#define STDMETHODCALLTYPE \r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct \r\n\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\t\r\n  VT_EMPTY\t= 0,\r\n\tVT_NULL\t= 1,\r\n\tVT_I2\t= 2,\r\n\tVT_I4\t= 3,\r\n\tVT_R4\t= 4,\r\n\tVT_R8\t= 5,\r\n\tVT_CY\t= 6,\r\n\tVT_DATE\t= 7,\r\n\tVT_BSTR\t= 8,\r\n\tVT_DISPATCH\t= 9,\r\n\tVT_ERROR\t= 10,\r\n\tVT_BOOL\t= 11,\r\n\tVT_VARIANT\t= 12,\r\n\tVT_UNKNOWN\t= 13,\r\n\tVT_DECIMAL\t= 14,\r\n\tVT_I1\t= 16,\r\n\tVT_UI1\t= 17,\r\n\tVT_UI2\t= 18,\r\n\tVT_UI4\t= 19,\r\n\tVT_I8\t= 20,\r\n\tVT_UI8\t= 21,\r\n\tVT_INT\t= 22,\r\n\tVT_UINT\t= 23,\r\n\tVT_VOID\t= 24,\r\n\tVT_HRESULT\t= 25,\r\n\tVT_FILETIME\t= 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union \r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\t\r\n  STREAM_SEEK_SET\t= 0,\r\n  STREAM_SEEK_CUR\t= 1,\r\n  STREAM_SEEK_END\t= 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\nvoid * \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/lzma/C/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw();\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/lzma/C/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/lzma/C/Common/String.cpp",
    "content": "// Common/String.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"StringConvert.h\"\r\n#else\r\n#include <ctype.h>\r\n#endif\r\n\r\n#include \"Common/String.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{ \r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1), \r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), \r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{ \r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/String.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"Vector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\nstatic const char *kTrimDefaultCharSet  = \" \\n\\t\";\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{ \r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{ \r\n  T *destStart = dest;\r\n  while((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)CharUpperA((LPSTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)CharUpperW((LPWSTR)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)CharLowerA((LPSTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)CharLowerW((LPWSTR)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char  *s2);\r\n#endif\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex, \r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n\tint _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if(realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if(newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if(_capacity > 0)\r\n    {\r\n      for (int i = 0; i < (_length + 1); i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n      _chars = newBuffer;\r\n    }\r\n    else\r\n    {\r\n      _chars = newBuffer;\r\n      _chars[0] = 0;\r\n    }\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize) \r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0)\r\n    { SetCapacity(16 - 1); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;} \r\n\r\n  // The minimum size of the character buffer in characters. \r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if(minBufLength >= _capacity)\r\n      SetCapacity(minBufLength + 1);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if(newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length; \r\n    return *this;\r\n  }  \r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if(&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    while (true)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    while (true)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for(int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    for(int i = 0; i < (int)(sizeof(kTrimDefaultCharSet) /\r\n      sizeof(kTrimDefaultCharSet[0])); i++)\r\n      charSet += (T)kTrimDefaultCharSet[i];\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for(int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0) \r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0) \r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()), \r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 2;\r\n    int numChars = WideCharToMultiByte(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(numRequiredBytes), \r\n      numRequiredBytes + 1, NULL, NULL);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/lzma/C/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"Common/String.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT codePage)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/lzma/C/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\ntypedef unsigned char Byte;\r\ntypedef short Int16;\r\ntypedef unsigned short UInt16;\r\ntypedef int Int32;\r\ntypedef unsigned int UInt32;\r\n#ifdef _MSC_VER\r\ntypedef __int64 Int64;\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef long long int Int64;\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Common/Vector.cpp",
    "content": "// Common/Vector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"Vector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector()\r\n  { delete []((unsigned char *)_items); }\r\nvoid CBaseRecordVector::Clear() \r\n  { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() \r\n  { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index)\r\n  { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if(_size != _capacity)\r\n    return;\r\n  int delta;\r\n  if (_capacity > 64)\r\n    delta = _capacity / 2;\r\n  else if (_capacity > 8)\r\n    delta = 8;\r\n  else\r\n    delta = 4;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  if(newCapacity <= _capacity)\r\n    return;\r\n  /*\r\n  #ifndef _DEBUG\r\n  static const unsigned int kMaxVectorSize = 0xF0000000;\r\n  if(newCapacity < _size || \r\n      ((unsigned int )newCapacity * (unsigned int )_itemSize) > kMaxVectorSize) \r\n    throw 1052354;\r\n  #endif\r\n  */\r\n  unsigned char *p = new unsigned char[newCapacity * _itemSize];\r\n  int numRecordsToMove = _capacity;\r\n  memmove(p, _items, _itemSize * numRecordsToMove);\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize, \r\n    ((unsigned char  *)_items) + srcIndex * _itemSize, \r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/lzma/C/Common/Vector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n\tint _capacity;\r\n  int _size;\r\n\tvoid *_items;\r\n  size_t _itemSize;\r\n\r\n\tvoid ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; } \r\npublic:\r\n  CBaseRecordVector(size_t itemSize):\r\n      _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n\tvirtual ~CBaseRecordVector();\r\n  int Size() const { return _size; }\r\n\tbool IsEmpty() const { return (_size == 0); }\r\n\tvoid Reserve(int newCapacity);\r\n\tvirtual void Delete(int index, int num = 1);\r\n\tvoid Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector():CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v):\r\n    CBaseRecordVector(sizeof(T)) { *this = v;}\r\n\tCRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n\tint Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n\tvoid Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n\tT& operator[](int index) { return ((T *)_items)[index]; }\r\n\tconst T& Front() const { return operator[](0); }\r\n  T& Front()   { return operator[](0); }\r\n\tconst T& Back() const { return operator[](_size - 1); }\r\n  T& Back()   { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  void Sort(int left, int right)\r\n  { \r\n    if (right - left < 2)\r\n      return;\r\n    Swap(left, (left + right) / 2);\r\n    int last = left;\r\n    for (int i = left; i < right; i++)\r\n      if (operator[](i) < operator[](left))\r\n        Swap(++last, i);\r\n    Swap(left, last);\r\n    Sort(left, last);\r\n    Sort(last + 1, right);\r\n  }\r\n  void Sort() { Sort(0, Size());  }\r\n  void Sort(int left, int right, int (*compare)(const T*, const T*, void *), void *param)\r\n  { \r\n    if (right - left < 2)\r\n      return;\r\n    Swap(left, (left + right) / 2);\r\n    int last = left;\r\n    for (int i = left; i < right; i++)\r\n      if (compare(&operator[](i), &operator[](left), param) < 0)\r\n        Swap(++last, i);\r\n    Swap(left, last);\r\n    Sort(left, last, compare, param);\r\n    Sort(last + 1, right, compare, param);\r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param) \r\n  {  \r\n    Sort(0, Size(), compare, param);  \r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector(){};\r\n  ~CObjectVector() { Clear(); }\r\n  CObjectVector(const CObjectVector &objectVector)\r\n    { *this = objectVector; }\r\n\tCObjectVector& operator=(const CObjectVector &objectVector)\r\n  {\r\n    Clear();\r\n    return (*this += objectVector);\r\n  }\r\n\tCObjectVector& operator+=(const CObjectVector &objectVector)\r\n  {\r\n    int size = objectVector.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(objectVector[i]);\r\n    return *this;\r\n  }\r\n\tconst T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n\tT& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n\tT& Front() { return operator[](0); }\r\n\tconst T& Front() const { return operator[](0); }\r\n\tT& Back() { return operator[](_size - 1); }\r\n\tconst T& Back() const { return operator[](_size - 1); }\r\n\tint Add(const T& item)\r\n    { return CPointerVector::Add(new T(item)); }\r\n\tvoid Insert(int index, const T& item)\r\n    { CPointerVector::Insert(index, new T(item)); }\r\n\tvirtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for(int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for(int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n      return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param) \r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void *param)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/lzma/C/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  Close();\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE) NULL);\r\n  return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    Close();\r\n    _handle = ::CreateFileW(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE) NULL);\r\n    return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));\r\n  }\r\n  return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP), \r\n    desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(!_fileIsOpen)\r\n    return true;\r\n  bool result = BOOLToBool(::CloseHandle(_handle));\r\n  _fileIsOpen = !result;\r\n  return result;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if(sizeLow == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR) \r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if(!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CreationTime = winFileInfo.ftCreationTime;\r\n  fileInfo.LastAccessTime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.LastWriteTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes; \r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 24);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, creationTime, lastAccessTime, lastWriteTime)); }\r\n\r\nbool COutFile::SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {  return SetTime(NULL, NULL, lastWriteTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if(!Seek(length, newPosition))\r\n    return false;\r\n  if(newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/lzma/C/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{ \r\n  DWORD    Attributes; \r\n  FILETIME CreationTime; \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime; \r\n  DWORD    VolumeSerialNumber; \r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks; \r\n  UInt64   FileIndex; \r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  bool _fileIsOpen;\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _fileIsOpen(false){};\r\n  virtual ~CFileBase();\r\n\r\n  virtual bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition); \r\n  bool SeekToBegin(); \r\n  bool SeekToEnd(UInt64 &newPosition); \r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/lzma/C/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/lzma/CPL.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n<HTML><HEAD><TITLE>Common Public License - v 1.0</TITLE>\r\n<META http-equiv=Content-Type content=\"text/html; charset=ISO-8859-1\">\r\n<BODY vLink=#800000 bgColor=#ffffff>\r\n<P align=center><B>Common Public License - v 1.0</B> \r\n<P><B></B><FONT size=3></FONT>\r\n<P><FONT size=3></FONT><FONT size=2>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER \r\nTHE TERMS OF THIS COMMON PUBLIC LICENSE (\"AGREEMENT\"). ANY USE, REPRODUCTION OR \r\nDISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS \r\nAGREEMENT.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2><B>1. DEFINITIONS</B></FONT> \r\n<P><FONT size=2>\"Contribution\" means:</FONT> \r\n<UL><FONT size=2>a) in the case of the initial Contributor, the initial code \r\n  and documentation distributed under this Agreement, and<BR clear=left>b) in \r\n  the case of each subsequent Contributor:</FONT></UL>\r\n<UL><FONT size=2>i) changes to the Program, and</FONT></UL>\r\n<UL><FONT size=2>ii) additions to the Program;</FONT></UL>\r\n<UL><FONT size=2>where such changes and/or additions to the Program originate \r\n  from and are distributed by that particular Contributor. </FONT><FONT size=2>A \r\n  Contribution 'originates' from a Contributor if it was added to the Program by \r\n  such Contributor itself or anyone acting on such Contributor's behalf. \r\n  </FONT><FONT size=2>Contributions do not include additions to the Program \r\n  which: (i) are separate modules of software distributed in conjunction with \r\n  the Program under their own license agreement, and (ii) are not derivative \r\n  works of the Program. </FONT></UL>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>\"Contributor\" means any person or entity that distributes the \r\nProgram.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2>\"Licensed Patents \" mean patent claims licensable by a \r\nContributor which are necessarily infringed by the use or sale of its \r\nContribution alone or when combined with the Program. </FONT>\r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2>\"Program\" means the Contributions \r\ndistributed in accordance with this Agreement.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>\"Recipient\" means anyone who receives the Program under this \r\nAgreement, including all Contributors.</FONT> \r\n<P><FONT size=2><B></B></FONT>\r\n<P><FONT size=2><B>2. GRANT OF RIGHTS</B></FONT> \r\n<UL><FONT size=2></FONT><FONT size=2>a) </FONT><FONT size=2>Subject to the \r\n  terms of this Agreement, each Contributor hereby grants</FONT><FONT size=2> \r\n  Recipient a non-exclusive, worldwide, royalty-free copyright license \r\n  to</FONT><FONT color=#ff0000 size=2> </FONT><FONT size=2>reproduce, prepare \r\n  derivative works of, publicly display, publicly perform, distribute and \r\n  sublicense the Contribution of such Contributor, if any, and such derivative \r\n  works, in source code and object code form.</FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2></FONT><FONT size=2>b) Subject to the terms of this \r\n  Agreement, each Contributor hereby grants </FONT><FONT size=2>Recipient a \r\n  non-exclusive, worldwide,</FONT><FONT color=#008000 size=2> </FONT><FONT \r\n  size=2>royalty-free patent license under Licensed Patents to make, use, sell, \r\n  offer to sell, import and otherwise transfer the Contribution of such \r\n  Contributor, if any, in source code and object code form. This patent license \r\n  shall apply to the combination of the Contribution and the Program if, at the \r\n  time the Contribution is added by the Contributor, such addition of the \r\n  Contribution causes such combination to be covered by the Licensed Patents. \r\n  The patent license shall not apply to any other combinations which include the \r\n  Contribution. No hardware per se is licensed hereunder. </FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2>c) Recipient understands that although each Contributor \r\n  grants the licenses to its Contributions set forth herein, no assurances are \r\n  provided by any Contributor that the Program does not infringe the patent or \r\n  other intellectual property rights of any other entity. Each Contributor \r\n  disclaims any liability to Recipient for claims brought by any other entity \r\n  based on infringement of intellectual property rights or otherwise. As a \r\n  condition to exercising the rights and licenses granted hereunder, each \r\n  Recipient hereby assumes sole responsibility to secure any other intellectual \r\n  property rights needed, if any. For example, if a third party patent license \r\n  is required to allow Recipient to distribute the Program, it is Recipient's \r\n  responsibility to acquire that license before distributing the \r\nProgram.</FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2>d) Each Contributor represents that to its knowledge it has \r\n  sufficient copyright rights in its Contribution, if any, to grant the \r\n  copyright license set forth in this Agreement. </FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<P><FONT size=2><B>3. REQUIREMENTS</B></FONT> \r\n<P><FONT size=2><B></B>A Contributor may choose to distribute the Program in \r\nobject code form under its own license agreement, provided that:</FONT> \r\n<UL><FONT size=2>a) it complies with the terms and conditions of this \r\n  Agreement; and</FONT></UL>\r\n<UL><FONT size=2>b) its license agreement:</FONT></UL>\r\n<UL><FONT size=2>i) effectively disclaims</FONT><FONT size=2> on behalf of all \r\n  Contributors all warranties and conditions, express and implied, including \r\n  warranties or conditions of title and non-infringement, and implied warranties \r\n  or conditions of merchantability and fitness for a particular purpose; \r\n</FONT></UL>\r\n<UL><FONT size=2>ii) effectively excludes on behalf of all Contributors all \r\n  liability for damages, including direct, indirect, special, incidental and \r\n  consequential damages, such as lost profits; </FONT></UL>\r\n<UL><FONT size=2>iii)</FONT><FONT size=2> states that any provisions which \r\n  differ from this Agreement are offered by that Contributor alone and not by \r\n  any other party; and</FONT></UL>\r\n<UL><FONT size=2>iv) states that source code for the Program is available from \r\n  such Contributor, and informs licensees how to obtain it in a reasonable \r\n  manner on or through a medium customarily used for software \r\n  exchange.</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 \r\n  size=2></FONT></UL>\r\n<UL><FONT color=#ff0000 size=2></FONT><FONT size=2></FONT></UL>\r\n<P><FONT size=2>When the Program is made available in source code form:</FONT> \r\n<UL><FONT size=2>a) it must be made available under this Agreement; and \r\n</FONT></UL>\r\n<UL><FONT size=2>b) a copy of this Agreement must be included with each copy \r\n  of the Program. </FONT></UL>\r\n<P><FONT size=2></FONT><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT>\r\n<P><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT><FONT size=2>Contributors \r\nmay not remove or alter any copyright notices contained within the Program. \r\n</FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>Each Contributor must identify itself as the originator of its \r\nContribution, if any, in a manner that reasonably allows subsequent Recipients \r\nto identify the originator of the Contribution. </FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2><B>4. COMMERCIAL DISTRIBUTION</B></FONT> \r\n<P><FONT size=2>Commercial distributors of software may accept certain \r\nresponsibilities with respect to end users, business partners and the like. \r\nWhile this license is intended to facilitate the commercial use of the Program, \r\nthe Contributor who includes the Program in a commercial product offering should \r\ndo so in a manner which does not create potential liability for other \r\nContributors. Therefore, if a Contributor includes the Program in a commercial \r\nproduct offering, such Contributor (\"Commercial Contributor\") hereby agrees to \r\ndefend and indemnify every other Contributor (\"Indemnified Contributor\") against \r\nany losses, damages and costs (collectively \"Losses\") arising from claims, \r\nlawsuits and other legal actions brought by a third party against the \r\nIndemnified Contributor to the extent caused by the acts or omissions of such \r\nCommercial Contributor in connection with its distribution of the Program in a \r\ncommercial product offering. The obligations in this section do not apply to any \r\nclaims or Losses relating to any actual or alleged intellectual property \r\ninfringement. In order to qualify, an Indemnified Contributor must: a) promptly \r\nnotify the Commercial Contributor in writing of such claim, and b) allow the \r\nCommercial Contributor to control, and cooperate with the Commercial Contributor \r\nin, the defense and any related settlement negotiations. The Indemnified \r\nContributor may participate in any such claim at its own expense.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>For example, a Contributor might include the Program in a \r\ncommercial product offering, Product X. That Contributor is then a Commercial \r\nContributor. If that Commercial Contributor then makes performance claims, or \r\noffers warranties related to Product X, those performance claims and warranties \r\nare such Commercial Contributor's responsibility alone. Under this section, the \r\nCommercial Contributor would have to defend claims against the other \r\nContributors related to those performance claims and warranties, and if a court \r\nrequires any other Contributor to pay any damages as a result, the Commercial \r\nContributor must pay those damages.</FONT> \r\n<P><FONT size=2></FONT><FONT color=#0000ff size=2></FONT>\r\n<P><FONT color=#0000ff size=2></FONT><FONT size=2><B>5. NO WARRANTY</B></FONT> \r\n<P><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS \r\nPROVIDED ON AN \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r\nEITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR \r\nCONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A \r\nPARTICULAR PURPOSE. Each Recipient is</FONT><FONT size=2> solely responsible for \r\ndetermining the appropriateness of using and distributing </FONT><FONT \r\nsize=2>the Program</FONT><FONT size=2> and assumes all risks associated with its \r\nexercise of rights under this Agreement</FONT><FONT size=2>, including but not \r\nlimited to the risks and costs of program errors, compliance with applicable \r\nlaws, damage to or loss of data, </FONT><FONT size=2>programs or equipment, and \r\nunavailability or interruption of operations</FONT><FONT size=2>. </FONT><FONT \r\nsize=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2><B>6. DISCLAIMER OF LIABILITY</B></FONT> \r\n<P><FONT size=2></FONT><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS \r\nAGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR \r\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r\n</FONT><FONT size=2>(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT \r\nsize=2> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, \r\nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \r\nOUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS \r\nGRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2><B>7. GENERAL</B></FONT> \r\n<P><FONT size=2></FONT><FONT size=2>If any provision of this Agreement is \r\ninvalid or unenforceable under applicable law, it shall not affect the validity \r\nor enforceability of the remainder of the terms of this Agreement, and without \r\nfurther action by the parties hereto, such provision shall be reformed to the \r\nminimum extent necessary to make such provision valid and enforceable.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>If Recipient institutes patent litigation against a Contributor \r\nwith respect to a patent applicable to software (including a cross-claim or \r\ncounterclaim in a lawsuit), then any patent licenses granted by that Contributor \r\nto such Recipient under this Agreement shall terminate as of the date such \r\nlitigation is filed. In addition, if Recipient institutes patent litigation \r\nagainst any entity (including a cross-claim or counterclaim in a lawsuit) \r\nalleging that the Program itself (excluding combinations of the Program with \r\nother software or hardware) infringes such Recipient's patent(s), then such \r\nRecipient's rights granted under Section 2(b) shall terminate as of the date \r\nsuch litigation is filed. </FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>All Recipient's rights under this Agreement shall terminate if \r\nit fails to comply with any of the material terms or conditions of this \r\nAgreement and does not cure such failure in a reasonable period of time after \r\nbecoming aware of such noncompliance. If all Recipient's rights under this \r\nAgreement terminate, Recipient agrees to cease use and distribution of the \r\nProgram as soon as reasonably practicable. However, Recipient's obligations \r\nunder this Agreement and any licenses granted by Recipient relating to the \r\nProgram shall continue and survive. </FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2>Everyone is permitted to copy and distribute \r\ncopies of this Agreement, but in order to avoid inconsistency the Agreement is \r\ncopyrighted and may only be modified in the following manner. The Agreement \r\nSteward reserves the right to </FONT><FONT size=2>publish new versions \r\n(including revisions) of this Agreement from time to </FONT><FONT size=2>time. \r\nNo one other than the Agreement Steward has the right to modify this Agreement. \r\nIBM is the initial Agreement Steward. IBM may assign the responsibility to serve \r\nas the Agreement Steward to a suitable separate entity. </FONT><FONT size=2>Each \r\nnew version of the Agreement will be given a distinguishing version number. The \r\nProgram (including Contributions) may always be distributed subject to the \r\nversion of the Agreement under which it was received. In addition, after a new \r\nversion of the Agreement is published, Contributor may elect to distribute the \r\nProgram (including its Contributions) under the new </FONT><FONT size=2>version. \r\n</FONT><FONT size=2>Except as expressly stated in Sections 2(a) and 2(b) above, \r\nRecipient receives no rights or licenses to the intellectual property of any \r\nContributor under this Agreement, whether expressly, </FONT><FONT size=2>by \r\nimplication, estoppel or otherwise</FONT><FONT size=2>.</FONT><FONT size=2> All \r\nrights in the Program not expressly granted under this Agreement are \r\nreserved.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>This Agreement is governed by the laws of the State of New York \r\nand the intellectual property laws of the United States of America. No party to \r\nthis Agreement will bring a legal action under this Agreement more than one year \r\nafter the cause of action arose. Each party waives its rights to a jury trial in \r\nany resulting litigation.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT></P></BODY></HTML>\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid Init(System.IO.Stream inStream);\r\n\t\tvoid ReleaseStream();\r\n\t\tvoid MovePos();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetLongestMatch(UInt32[] distances);\r\n\t\tvoid DummyLongestMatch();\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize;\r\n\t\tUInt32 _historySize;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\t// UInt32 []_dummy;\r\n\t\tUInt32[] _son;\r\n\r\n\t\tUInt32[] _hash;\r\n\t\tUInt32[] _hash2;\r\n\t\tUInt32[] _hash3;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\t\tbool HASH_BIG = false;\r\n\r\n\t\tconst UInt32 kHash3Size = 1 << 18;\r\n\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kBT4Hash2Size = 1 << 10;\r\n\t\tconst UInt32 kBT4Hash4Size = 1 << 20;\r\n\t\tconst UInt32 kBT4bHash4Size = 1 << 23;\r\n\t\tconst UInt32 kBT2NumHashDirectBytes = 2;\r\n\t\tconst UInt32 kBT4NumHashDirectBytes = 0;\r\n\r\n\t\tUInt32 kHash2Size = kBT4Hash2Size;\r\n\t\tUInt32 kNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\t\tUInt32 kNumHashBytes = 4;\r\n\t\tUInt32 kHashSize = kBT4Hash4Size;\r\n\r\n\t\tpublic void SetType(int numHashBytes, bool big)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = numHashBytes > 2;\r\n\t\t\tHASH_BIG = big;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkHash2Size = kBT4Hash2Size;\r\n\t\t\t\tkNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\t\t\t\tkNumHashBytes = 4;\r\n\t\t\t\tkHashSize = HASH_BIG ? kBT4bHash4Size : kBT4Hash4Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = kBT2NumHashDirectBytes;\r\n\t\t\t\tkNumHashBytes = 2;\r\n\t\t\t\tkHashSize = kBT2HashSize;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\r\n\t\tUInt32 Hash(UInt32 offset, out UInt32 hash2Value, out UInt32 hash3Value)\r\n\t\t{\r\n\t\t\tUInt32 temp = CRC.Table[_bufferBase[offset]] ^ _bufferBase[offset + 1];\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((UInt32)(_bufferBase[offset + 2]) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\treturn (temp ^ (CRC.Table[_bufferBase[offset + 3]] << 5)) & (kHashSize - 1);\r\n\t\t}\r\n\r\n\t\tUInt32 Hash(UInt32 offset)\r\n\t\t{\r\n\t\t\treturn _bufferBase[offset] ^ ((UInt32)(_bufferBase[offset + 1]) << 8);\r\n\t\t}\r\n\r\n\t\tpublic new void Init(System.IO.Stream inStream)\r\n\t\t{\r\n\t\t\tbase.Init(inStream);\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < kHashSize; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tfor (i = 0; i < kHash2Size; i++)\r\n\t\t\t\t\t_hash2[i] = kEmptyHashValue;\r\n\t\t\t\tfor (i = 0; i < kHash3Size; i++)\r\n\t\t\t\t\t_hash3[i] = kEmptyHashValue;\r\n\t\t\t}\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\t_cyclicBufferPos++;\r\n\t\t\tif (_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\t// _dummy = new UInt32[matchMaxLen + 1];\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\t_son = null;\r\n\t\t\t_hash = null;\r\n\t\t\t_hash2 = null;\r\n\t\t\t_hash3 = null;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\tif (_blockSize + 256 > kMaxValForNormalize)\r\n\t\t\t\tthrow new Exception();\r\n\r\n\t\t\t_historySize = historySize;\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\t_cyclicBufferSize = historySize + 1;\r\n\t\t\t_son = new UInt32[_cyclicBufferSize * 2];\r\n\r\n\t\t\t_hash = new UInt32[kHashSize];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\t_hash2 = new UInt32[kHash2Size];\r\n\t\t\t\t_hash3 = new UInt32[kHash3Size];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetLongestMatch(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\tUInt32 matchHashLenMax = 0;\r\n\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t\thashValue = Hash(cur, out hash2Value, out hash3Value);\r\n\t\t\telse\r\n\t\t\t\thashValue = Hash(cur);\r\n\r\n\t\t\tUInt32 curMatch = _hash[hashValue];\r\n\t\t\tUInt32 curMatch2 = 0, curMatch3 = 0;\r\n\t\t\tUInt32 len2Distance = 0;\r\n\t\t\tUInt32 len3Distance = 0;\r\n\t\t\tbool matchLen2Exist = false;\r\n\t\t\tbool matchLen3Exist = false;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\t\tif (curMatch2 >= matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen2Distance = _pos - curMatch2 - 1;\r\n\t\t\t\t\t\tmatchHashLenMax = 2;\r\n\t\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t\t\t\tif (curMatch3 >= matchMinPos)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tlen3Distance = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\t\tmatchHashLenMax = 3;\r\n\t\t\t\t\t\t\tmatchLen3Exist = true;\r\n\t\t\t\t\t\t\tif (matchLen2Exist)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (len3Distance < len2Distance)\r\n\t\t\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[hashValue] = _pos;\r\n\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t{\r\n\t\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t}\r\n\t\t\t\treturn matchHashLenMax;\r\n\t\t\t}\r\n\t\t\tUInt32 ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptrRight = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 maxLen, minLeft, minRight;\r\n\t\t\tmaxLen = minLeft = minRight = kNumHashDirectBytes;\r\n\r\n\t\t\tdistances[maxLen] = _pos - curMatch - 1;\r\n\r\n\t\t\tfor (UInt32 count = _cutValue; count > 0; count--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 currentLen = Math.Min(minLeft, minRight);\r\n\t\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\twhile (currentLen > maxLen)\r\n\t\t\t\t\tdistances[++maxLen] = delta - 1;\r\n\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tif (currentLen != lenLimit)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] < _bufferBase[cur + currentLen])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\r\n\t\t\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (matchLen2Exist && len2Distance < distances[2])\r\n\t\t\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\t\t\tif (matchLen3Exist && len3Distance < distances[3])\r\n\t\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\treturn maxLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t\t_son[ptrRight] = kEmptyHashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tif (matchLen2Exist)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (maxLen < 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\t\tmaxLen = 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (len2Distance < distances[2])\r\n\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tif (matchLen3Exist)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (maxLen < 3)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t\t\tmaxLen = 3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (len3Distance < distances[3])\r\n\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn maxLen;\r\n\t\t}\r\n\r\n\t\tpublic void DummyLongestMatch()\r\n\t\t{\r\n\t\t\t// GetLongestMatch(_dummy);\r\n\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t\thashValue = Hash(cur, out hash2Value, out hash3Value);\r\n\t\t\telse\r\n\t\t\t\thashValue = Hash(cur);\r\n\r\n\t\t\tUInt32 curMatch = _hash[hashValue];\r\n\t\t\tUInt32 curMatch2 = 0, curMatch3 = 0;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t\t}\r\n\t\t\t_hash[hashValue] = _pos;\r\n\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t{\r\n\t\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tUInt32 ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptrRight = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 minLeft, minRight;\r\n\t\t\tminLeft = minRight = kNumHashDirectBytes;\r\n\r\n\t\t\tfor (UInt32 count = _cutValue; count > 0; count--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 currentLen = Math.Min(minLeft, minRight);\r\n\t\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tif (currentLen != lenLimit)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] < _bufferBase[cur + currentLen])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t\t_son[ptrRight] = kEmptyHashValue;\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 startItem = _pos - _historySize;\r\n\t\t\tUInt32 subValue = startItem - 1;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\r\n\t\t\tNormalizeLinks(_hash, kHashSize, subValue);\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tNormalizeLinks(_hash2, kHash2Size, subValue);\r\n\t\t\t\tNormalizeLinks(_hash3, kHash3Size, subValue);\r\n\t\t\t}\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize;  // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos;             // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\t\tUInt32 _keepSizeReserv;  // how many BYTEs must be kept as reserv\r\n\t\tpublic UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic virtual void BeforeMoveBlock() { }\r\n\t\tpublic virtual void AfterMoveBlock() { }\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tBeforeMoveBlock();\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t\tAfterMoveBlock();\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\t_keepSizeReserv = keepSizeReserv;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t_stream = stream;\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++) ;\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream) { Init(stream, false); }\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t  public bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\tpublic const int kDicLogSizeMax = 28;\r\n\t\tpublic const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get  { return 0; }}\r\n\t\tpublic override long Position  \r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t\tBT4B\r\n\t\t};\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t\t\"BT4B\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1024];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 20;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 10))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 19))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 9] + 18);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 18] + 36);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 16))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 25))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 15] + 30);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 24] + 48);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 20;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax]; // kNumLowBits\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax]; // kNumMidBits\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tUInt32 price = 0;\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _choice.GetPrice0();\r\n\t\t\t\t\tprice += _lowCoder[posState].GetPrice(symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\tprice += _choice.GetPrice1();\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprice += _choice2.GetPrice0();\r\n\t\t\t\t\t\tprice += _midCoder[posState].GetPrice(symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprice += _choice2.GetPrice1();\r\n\t\t\t\t\t\tprice += _highCoder.GetPrice(symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic new UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[(symbol << Base.kNumPosStatesBitsEncodingMax) + posState];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 len = 0; len < _tableSize; len++)\r\n\t\t\t\t\t_prices[(len << Base.kNumPosStatesBitsEncodingMax) + posState] = base.GetPrice(len, posState);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;         // posNext;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\t// public UInt32 []Backs = new UInt32[Base.kNumRepDistances];\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\r\n\t\tLZ.IMatchFinder _matchFinder = null; // test it\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen + 1];\r\n\t\tbool _fastMode = false;\r\n\t\tbool _maxMode = false;\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[Base.kDistTableSizeMax << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 lastPosSlotFillingPos;\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\r\n\t\tSystem.IO.Stream _inStream;\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark;\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\t// _rangeEncoder.Create(1 << 20);\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tbool big = false;\r\n\t\t\t\tswitch (_matchFinderType)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase EMatchFinderType.BT2:\r\n\t\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase EMatchFinderType.BT4:\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase EMatchFinderType.BT4B:\r\n\t\t\t\t\t\tbig = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tbt.SetType(numHashBytes, big);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes,\r\n\t\t\t\tBase.kMatchMaxLen * 2 + 1 - _numFastBytes);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes)\r\n\t\t{\r\n\t\t\tlenRes = _matchFinder.GetLongestMatch(_matchDistances);\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes, _matchDistances[lenRes],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t_additionalOffset++;\r\n\t\t\t_matchFinder.MovePos();\r\n\t\t}\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tfor (; num > 0; num--)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.DummyLongestMatch();\r\n\t\t\t\t_matchFinder.MovePos();\r\n\t\t\t\t_additionalOffset++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice += _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tif (len == 2 && pos >= 0x80)\r\n\t\t\t\treturn kIfinityPrice;\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(pos << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(GetPosSlot2(pos) << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_optimumEndIndex = 0; // test it;\r\n\r\n\t\t\tUInt32 lenMain;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tUInt32 backMain = (lenMain < _numFastBytes) ? _matchDistances[lenMain] :\r\n\t\t\t\t\t_matchDistances[_numFastBytes];\r\n\t\t\t\tbackRes = backMain + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tByte matchByte;\r\n\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (lenMain < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\r\n\t\t\tif (lenMain <= repLens[repMaxIndex])\r\n\t\t\t\tlenMain = 0;\r\n\r\n\t\t\tUInt32 len;\r\n\t\t\tfor (len = 2; len <= lenMain; len++)\r\n\t\t\t{\r\n\t\t\t\t_optimum[len].PosPrev = 0;\r\n\t\t\t\t_optimum[len].BackPrev = _matchDistances[len] + Base.kNumRepDistances;\r\n\t\t\t\t_optimum[len].Price = normalMatchPrice +\r\n\t\t\t\t\tGetPosLenPrice(_matchDistances[len], len, posState);\r\n\t\t\t\t_optimum[len].Prev1IsChar = false;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain < repLens[repMaxIndex])\r\n\t\t\t\tlenMain = repLens[repMaxIndex];\r\n\r\n\t\t\tfor (; len <= lenMain; len++)\r\n\t\t\t\t_optimum[len].Price = kIfinityPrice;\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tfor (UInt32 lenTest = 2; lenTest <= repLen; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\t\t\tUInt32 lenEnd = lenMain;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\t// nextIsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t/*\r\n\t\t\t\tif(newLen == 2 && _matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t*/\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tUInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (numAvailableBytes >= 3 && !nextIsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 backOffset = reps[0] + 1;\r\n\t\t\t\t\tUInt32 temp;\r\n\t\t\t\t\tfor (temp = 1; temp < numAvailableBytes; temp++)\r\n\t\t\t\t\t\t// if (data[temp] != data[(size_t)temp - backOffset])\r\n\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)temp - 1) != _matchFinder.GetIndexByte((Int32)temp - (Int32)backOffset - 1))\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tUInt32 lenTest2 = temp - 1;\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t// for (; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + 1 + lenTest2)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + 1 + lenTest2];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\t// UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n\t\t\t\t\tUInt32 backOffset = reps[repIndex] + 1;\r\n\t\t\t\t\tif (_matchFinder.GetIndexByte(-1) != \r\n\t\t\t\t\t\t  _matchFinder.GetIndexByte((Int32)(-1 - (Int32)backOffset)) ||\r\n\t\t\t\t\t\t\t_matchFinder.GetIndexByte(0) != \r\n\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)(0 - (Int32)backOffset)))\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTest;\r\n\t\t\t\t\tfor (lenTest = 2; lenTest < numAvailableBytes; lenTest++)\r\n\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)lenTest - 1) != \r\n\t\t\t\t\t\t    _matchFinder.GetIndexByte((Int32)lenTest - 1 - (Int32)backOffset))\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t  do\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (_maxMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 lenTest2 = lenTest + 1;\r\n\t\t\t\t\t\tUInt32 limit = Math.Min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)((Int32)lenTest2 - 1)) !=\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest2 - 1 - (Int32)backOffset)))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)backOffset)), \r\n\t\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t            \r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t//    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tif (newLen >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (newLen == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tnormalMatchPrice = matchPrice +\r\n\t\t\t\t\t\t_isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = newLen; lenTest >= 2; lenTest--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[lenTest];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (_maxMode && (lenTest == newLen || curBack != _matchDistances[lenTest + 1]))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 backOffset = curBack + 1;\r\n\t\t\t\t\t\t\tUInt32 lenTest2 = lenTest + 1;\r\n\t\t\t\t\t\t\tUInt32 limit = Math.Min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)lenTest2 - 1) != _matchFinder.GetIndexByte((Int32)lenTest2 - (Int32)backOffset - 1))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t// data[(size_t)lenTest - 1], \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t// data[(size_t)lenTest - backOffset], data[lenTest]\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)backOffset - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1)\r\n\t\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tUInt32 GetOptimumFast(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tUInt32 lenMain;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[_numFastBytes] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\twhile (lenMain > 2)\r\n\t\t\t{\r\n\t\t\t\tif (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tlenMain--;\r\n\t\t\t}\r\n\t\t\tif (lenMain == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\t\tlenMain = 1;\r\n\r\n\t\t\tUInt32 backMain = _matchDistances[lenMain];\r\n\t\t\tif (repLens[repMaxIndex] >= 2)\r\n\t\t\t{\r\n\t\t\t\tif (repLens[repMaxIndex] + 1 >= lenMain ||\r\n\t\t\t\t\trepLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 12)))\r\n\t\t\t\t{\r\n\t\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\t\treturn lenRes;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= 2)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out _longestMatchLength);\r\n\t\t\t\tif (_longestMatchLength >= 2 &&\r\n\t\t\t\t\t(\r\n\t\t\t\t\t(_longestMatchLength >= lenMain &&\r\n\t\t\t\t\t_matchDistances[lenMain] < backMain) ||\r\n\t\t\t\t\t_longestMatchLength == lenMain + 1 &&\r\n\t\t\t\t\t!ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\r\n\t\t\t\t\t_longestMatchLength > lenMain + 1 ||\r\n\t\t\t\t\t_longestMatchLength + 1 >= lenMain && lenMain >= 3 &&\r\n\t\t\t\t\tChangePair(_matchDistances[lenMain - 1], backMain)\r\n\t\t\t\t\t)\r\n\t\t\t\t\t)\r\n\t\t\t\t{\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n\t\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 repLen = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\t\t\tif (repLen >= 2 && repLen + 1 >= lenMain)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\t\t\treturn 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbackRes = backMain + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 2);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tvoid InitMatchFinder(LZ.IMatchFinder matchFinder)\r\n\t\t{\r\n\t\t\t_matchFinder = matchFinder;\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen; // kMatchMaxLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Init(_inStream);\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len; // it's not used\r\n\t\t\t\tReadMatchDistances(out len);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\r\n\t\t\t\tUInt32 len;\r\n\t\t\t\tif (_fastMode)\r\n\t\t\t\t\tlen = GetOptimumFast((UInt32)nowPos64, out pos);\r\n\t\t\t\telse\r\n\t\t\t\t\tlen = GetOptimum((UInt32)nowPos64, out pos);\r\n\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\r\n\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\tif (!_fastMode)\r\n\t\t\t\t\t\t\t\t\tif (--_alignPriceCount == 0)\r\n\t\t\t\t\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (!_fastMode)\r\n\t\t\t\t\tif (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFillPosSlotPrices();\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\t\tlastPosSlotFillingPos = nowPos64;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// CCoderReleaser releaser(this);\r\n\r\n\t\t\t/*\r\n\t\t\tif (_matchFinder->GetNumAvailableBytes() == 0)\r\n\t\t\t\treturn Flush();\r\n\t\t\t*/\r\n\r\n\t\t\tif (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillPosSlotPrices();\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tlastPosSlotFillingPos = 0;\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 28;\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\r\n\t\tvoid FillPosSlotPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tfor (posSlot = 0; posSlot < Base.kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\r\n\t\t\t\tfor (; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) +\r\n\t\t\t\t\t\t((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\r\n\t\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = Base.kAlignTableSize;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t\"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4, bt4b], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.32 Copyright (c) 1999-2005 Igor Pavlov  2005-12-09\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[12];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary, mf == \"bt4\");\r\n\t\t\t}\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tFileStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.40607</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\t\t\tpublic void Init() { RG.Init(); }\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\t/*\r\n\t\t\tUInt32 GetLogRand(int maxLen)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = GetRnd() % (maxLen + 1);\r\n\t\t\t\treturn GetRnd() & ((1 << len) - 1);\r\n\t\t\t}\r\n\t\t\t*/\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn RG.GetRnd(2);\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn 4 + RG.GetRnd(3);\r\n\t\t\t\treturn 12 + RG.GetRnd(4);\r\n\t\t\t}\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)(RG.GetRnd(8));\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 offset = GetOffset();\r\n\t\t\t\t\t\twhile (offset >= Pos)\r\n\t\t\t\t\t\t\toffset >>= 1;\r\n\t\t\t\t\t\toffset += 1;\r\n\t\t\t\t\t\tUInt32 len = 2 + GetLen();\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - offset];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, bool isBT4,\r\n\t\t\tUInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 numCommandsForOne;\r\n\t\t\tif (isBT4)\r\n\t\t\t{\r\n\t\t\t\tUInt64 t = GetLogSize(dictionarySize) - (19 << kSubBits);\r\n\t\t\t\tnumCommandsForOne = 2000 + ((t * t * 68) >> (2 * kSubBits));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tUInt64 t = GetLogSize(dictionarySize) - (15 << kSubBits);\r\n\t\t\t\tnumCommandsForOne = 1500 + ((t * t * 41) >> (2 * kSubBits));\r\n\t\t\t}\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime,\r\n\t\t\tUInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 250 + outSize * 21;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tbool isBT4,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tbool isBT4,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tconst string bt2 = \"BT2\";\r\n\t\tconst string bt4 = \"BT4\";\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize, bool isBT4)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\tCoderPropID.MatchFinder  \r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t\tisBT4 ? bt4: bt2\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Init();\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, isBT4, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, isBT4, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, isBT4, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "package SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\t\t\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize;\r\n\tint _historySize;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\t\r\n\tint[] _hash;\r\n\tint[] _hash2;\r\n\tint[] _hash3;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\tboolean HASH_BIG = false;\r\n\t\r\n\tstatic final int kHash3Size = 1 << 18;\r\n\t\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kBT4Hash2Size = 1 << 10;\r\n\tstatic final int kBT4Hash4Size = 1 << 20;\r\n\tstatic final int kBT4bHash4Size = 1 << 23;\r\n\tstatic final int kBT2NumHashDirectBytes = 2;\r\n\tstatic final int kBT4NumHashDirectBytes = 0;\r\n\t\r\n\tint kHash2Size = kBT4Hash2Size;\r\n\tint kNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\tint kNumHashBytes = 4;\r\n\tint kHashSize = kBT4Hash4Size;\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void SetType(int numHashBytes, boolean big)\r\n\t{\r\n\t\tHASH_ARRAY = numHashBytes > 2;\r\n\t\tHASH_BIG = big;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkHash2Size = kBT4Hash2Size;\r\n\t\t\tkNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\t\t\tkNumHashBytes = 4;\r\n\t\t\tkHashSize = (HASH_BIG ? kBT4bHash4Size : kBT4Hash4Size);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = kBT2NumHashDirectBytes;\r\n\t\t\tkNumHashBytes = 2;\r\n\t\t\tkHashSize = kBT2HashSize;\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic final int kEmptyHashValue = 0;\r\n\t\r\n\tstatic final int kMaxValForNormalize = ((int)1 << 30) - 1;\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < kHashSize; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tfor (i = 0; i < kHash2Size; i++)\r\n\t\t\t\t_hash2[i] = kEmptyHashValue;\r\n\t\t\tfor (i = 0; i < kHash3Size; i++)\r\n\t\t\t\t_hash3[i] = kEmptyHashValue;\r\n\t\t}\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\t_son = null;\r\n\t\t_hash = null;\r\n\t\t_hash2 = null;\r\n\t\t_hash3 = null;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\tif (_blockSize + 256 > kMaxValForNormalize)\r\n\t\t\treturn false;\r\n\t\t\r\n\t\t_historySize = historySize;\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\t\t\r\n\t\t_cyclicBufferSize = historySize + 1;\r\n\t\t_son = new int[_cyclicBufferSize * 2];\r\n\t\t\r\n\t\t_hash = new int[kHashSize];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\t_hash2 = new int[kHash2Size];\r\n\t\t\t_hash3 = new int[kHash3Size];\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic int GetLongestMatch(int[] distances)\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\treturn 0;\r\n\t\t}\r\n\t\t\r\n\t\tint matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\t\t\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\t\r\n\t\tint matchHashLenMax = 0;\r\n\t\t\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & (kHashSize - 1);\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8)) & (kHashSize - 1);\r\n\t\t\r\n\t\tint curMatch = _hash[hashValue];\r\n\t\tint curMatch2 = 0, curMatch3 = 0;\r\n\t\tint len2Distance = 0;\r\n\t\tint len3Distance = 0;\r\n\t\tboolean matchLen2Exist = false;\r\n\t\tboolean matchLen3Exist = false;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\tif (curMatch2 >= matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tlen2Distance = _pos - curMatch2 - 1;\r\n\t\t\t\t\tmatchHashLenMax = 2;\r\n\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t{\r\n\t\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t\t\tif (curMatch3 >= matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen3Distance = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tmatchHashLenMax = 3;\r\n\t\t\t\t\t\tmatchLen3Exist = true;\r\n\t\t\t\t\t\tif (matchLen2Exist)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (len3Distance < len2Distance)\r\n\t\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t_hash[hashValue] = _pos;\r\n\t\t\r\n\t\tif (curMatch < matchMinPos)\r\n\t\t{\r\n\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\t\t\t\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t}\r\n\t\t\treturn matchHashLenMax;\r\n\t\t}\r\n\t\tint ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptrRight = (_cyclicBufferPos << 1);\r\n\t\t\r\n\t\tint maxLen, minLeft, minRight;\r\n\t\tmaxLen = minLeft = minRight = kNumHashDirectBytes;\r\n\t\t\r\n\t\tdistances[maxLen] = _pos - curMatch - 1;\r\n\t\t\r\n\t\tfor (int count = _cutValue; count != 0; count--)\r\n\t\t{\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint currentLen = Math.min(minLeft, minRight);\r\n\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\tbreak;\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\twhile (currentLen > maxLen)\r\n\t\t\t\tdistances[++maxLen] = delta - 1;\r\n\t\t\t\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\t\t\t\r\n\t\t\tif (currentLen != lenLimit)\r\n\t\t\t{\r\n\t\t\t\tif ((_bufferBase[pby1 + currentLen] & 0xFF) < (_bufferBase[cur + currentLen] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (matchLen2Exist && len2Distance < distances[2])\r\n\t\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\t\tif (matchLen3Exist && len3Distance < distances[3])\r\n\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn maxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t_son[ptrRight] = kEmptyHashValue;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tif (matchLen2Exist)\r\n\t\t\t{\r\n\t\t\t\tif (maxLen < 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\tmaxLen = 2;\r\n\t\t\t\t}\r\n\t\t\t\telse if (len2Distance < distances[2])\r\n\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t}\r\n\t\t\t{\r\n\t\t\t\tif (matchLen3Exist)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (maxLen < 3)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t\tmaxLen = 3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (len3Distance < distances[3])\r\n\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn maxLen;\r\n\t}\r\n\t\r\n\tpublic void DummyLongestMatch()\r\n\t{\r\n\t\t// GetLongestMatch(_dummy);\r\n\t\t\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tint matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\t\t\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\t\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & (kHashSize - 1);\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8)) & (kHashSize - 1);\r\n\t\t\r\n\t\tint curMatch = _hash[hashValue];\r\n\t\tint curMatch2 = 0, curMatch3 = 0;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t}\r\n\t\t_hash[hashValue] = _pos;\r\n\t\t\r\n\t\tif (curMatch < matchMinPos)\r\n\t\t{\r\n\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tint ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptrRight = (_cyclicBufferPos << 1);\r\n\t\t\r\n\t\tint minLeft, minRight;\r\n\t\tminLeft = minRight = kNumHashDirectBytes;\r\n\t\t\r\n\t\tfor (int count = _cutValue; count != 0; count--)\r\n\t\t{\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint currentLen = Math.min(minLeft, minRight);\r\n\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\tbreak;\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\t\t\t\r\n\t\t\tif (currentLen != lenLimit)\r\n\t\t\t{\r\n\t\t\t\tif ((_bufferBase[pby1 + currentLen] & 0xFF) < (_bufferBase[cur + currentLen] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t_son[ptrRight] = kEmptyHashValue;\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint startItem = _pos - _historySize;\r\n\t\tint subValue = startItem - 1;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\r\n\t\tNormalizeLinks(_hash, kHashSize, subValue);\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tNormalizeLinks(_hash2, kHash2Size, subValue);\r\n\t\t\tNormalizeLinks(_hash3, kHash3Size, subValue);\r\n\t\t}\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue)\r\n\t{ _cutValue = cutValue; }\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindows\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tint _keepSizeReserv;  // how many BYTEs must be kept as reserv\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free()\r\n\t{ _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t_keepSizeReserv = keepSizeReserv;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream)\r\n\t{ _stream = stream; \t}\r\n\r\n\tpublic void ReleaseStream()\r\n\t{ _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\r\n\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\r\n\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\tpublic static final int kDicLogSizeMax = 28;\r\n\tpublic static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\tpublic static final int EMatchFinderTypeBT4B = 2;\r\n\t\r\n\t\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\t\r\n\tstatic byte[] g_FastPos = new byte[1024];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 20;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 10))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 19))\r\n\t\t\treturn g_FastPos[pos >> 9] + 18;\r\n\t\treturn g_FastPos[pos >> 18] + 36;\r\n\t}\r\n\t\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 16))\r\n\t\t\treturn g_FastPos[pos >> 6] + 12;\r\n\t\tif (pos < (1 << 25))\r\n\t\t\treturn g_FastPos[pos >> 15] + 30;\r\n\t\treturn g_FastPos[pos >> 24] + 48;\r\n\t}\r\n\t\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\t\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\t\r\n\tstatic final int kDefaultDictionaryLogSize = 20;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\t\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\t\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\t\t\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\tint price = 0;\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\t\tprice += _lowCoder[posState].GetPrice(symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\t\t\tprice += _midCoder[posState].GetPrice(symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\t\t\tprice += _highCoder.GetPrice(symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\t};\r\n\t\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\t\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\t\t\r\n\t\tpublic void SetTableSize(int tableSize)\r\n\t\t{ _tableSize = tableSize; }\r\n\t\t\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[(symbol << Base.kNumPosStatesBitsEncodingMax) + posState];\r\n\t\t}\r\n\t\t\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tfor (int len = 0; len < _tableSize; len++)\r\n\t\t\t\t_prices[(len << Base.kNumPosStatesBitsEncodingMax) + posState] = super.GetPrice(len, posState);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\t\t\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\t\t\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\t\t\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;         // posNext;\r\n\t\tpublic int BackPrev;\r\n\t\t\r\n\t\t// public UInt32 []Backs = new UInt32[Base.kNumRepDistances];\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\t\t\r\n\t\tpublic void MakeAsChar()\r\n\t\t{ BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep()\r\n\t\t{ BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep()\r\n\t\t{ return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null; // test it\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\t\r\n\tshort[] _isMatch = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\t\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\t\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\t\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen + 1];\r\n\tboolean _fastMode = false;\r\n\tboolean _maxMode = true;\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _additionalOffset;\r\n\t\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\t\r\n\tboolean _longestMatchWasFound;\r\n\t\r\n\tint [] _posSlotPrices = new int [Base.kDistTableSizeMax << Base.kNumLenToPosStatesBits];\r\n\tint [] _distancesPrices = new int [Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\tint [] _alignPrices = new int [Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\t\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\t\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\t\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\t\r\n\tlong lastPosSlotFillingPos;\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\t\r\n\tjava.io.InputStream _inStream;\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\tboolean _needReleaseMFStream = false;\r\n\t\r\n\tvoid Create()\r\n\t{\r\n\t\t// _rangeEncoder.Create(1 << 20);\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tboolean big = false;\r\n\t\t\tswitch (_matchFinderType)\r\n\t\t\t{\r\n\t\t\t\tcase EMatchFinderTypeBT2:\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase EMatchFinderTypeBT4:\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase EMatchFinderTypeBT4B:\r\n\t\t\t\t\tbig = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tbt.SetType(numHashBytes, big);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\t\t\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes,\r\n\t\t\t\tBase.kMatchMaxLen * 2 + 1 - _numFastBytes);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\t\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\t\t\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\t\t\r\n\t\t_posAlignEncoder.Init();\r\n\t\t\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\t\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = _matchFinder.GetLongestMatch(_matchDistances);\r\n\t\tif (lenRes == _numFastBytes)\r\n\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes, _matchDistances[lenRes],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t_additionalOffset++;\r\n\t\t_matchFinder.MovePos();\r\n\t\treturn lenRes;\r\n\t}\r\n\t\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tfor (; num > 0; num--)\r\n\t\t{\r\n\t\t\t_matchFinder.DummyLongestMatch();\r\n\t\t\t_matchFinder.MovePos();\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\t\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tif (len == 2 && pos >= 0x80)\r\n\t\t\treturn kIfinityPrice;\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(pos << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(GetPosSlot2(pos) << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\t\r\n\tint Backward(int[] backRes, int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\t\t\t\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\t\t\t\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes[0] = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\t\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\t\r\n\tint GetOptimum(int position, int []backRes) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes[0] = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_optimumEndIndex = 0; // test it;\r\n\t\t\r\n\t\tint lenMain;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\t\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes[0] = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tint backMain = (lenMain < _numFastBytes) ? _matchDistances[lenMain] :\r\n\t\t\t\t_matchDistances[_numFastBytes];\r\n\t\t\tbackRes[0] = backMain + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\r\n\t\t_optimum[0].State = _state;\r\n\t\t\r\n\t\tbyte matchByte;\r\n\t\t\r\n\t\tmatchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\t\t\r\n\t\tint posState = (position & _posStateMask);\r\n\t\t\r\n\t\t_optimum[1].Price =\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\t\t\r\n\t\t_optimum[1].PosPrev = 0;\r\n\t\t\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\t\t\r\n\t\t\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\t\t\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (lenMain < 2)\r\n\t\t{\r\n\t\t\tbackRes[0] = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\t\t\r\n\t\tif (lenMain <= repLens[repMaxIndex])\r\n\t\t\tlenMain = 0;\r\n\t\t\r\n\t\tint len;\r\n\t\tfor (len = 2; len <= lenMain; len++)\r\n\t\t{\r\n\t\t\t_optimum[len].PosPrev = 0;\r\n\t\t\t_optimum[len].BackPrev = _matchDistances[len] + Base.kNumRepDistances;\r\n\t\t\t_optimum[len].Price = normalMatchPrice +\r\n\t\t\t\t\tGetPosLenPrice(_matchDistances[len], len, posState);\r\n\t\t\t_optimum[len].Prev1IsChar = false;\r\n\t\t}\r\n\t\t\r\n\t\tif (lenMain < repLens[repMaxIndex])\r\n\t\t\tlenMain = repLens[repMaxIndex];\r\n\t\t\r\n\t\tfor (; len <= lenMain; len++)\r\n\t\t\t_optimum[len].Price = kIfinityPrice;\r\n\t\t\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tfor (int lenTest = 2; lenTest <= repLen; lenTest++)\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\r\n\t\t\t\tOptimal optimum = _optimum[lenTest];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tint cur = 0;\r\n\t\tint lenEnd = lenMain;\r\n\t\t\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t{\r\n\t\t\t\treturn Backward(backRes, cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(backRes, cur);\r\n\t\t\t}\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\t\t\t\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\t\t\t\r\n\t\t\tposState = (position & _posStateMask);\r\n\t\t\t\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\t\t\t\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\t\t\t\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\t\t\t\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t// nextIsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tint numAvailableBytes = numAvailableBytesFull;\r\n\t\t\t\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (numAvailableBytes >= 3 && !nextIsChar)\r\n\t\t\t{\r\n\t\t\t\tint backOffset = reps[0] + 1;\r\n\t\t\t\tint temp;\r\n\t\t\t\tfor (temp = 1; temp < numAvailableBytes; temp++)\r\n\t\t\t\t\t// if (data[temp] != data[(size_t)temp - backOffset])\r\n\t\t\t\t\tif (_matchFinder.GetIndexByte(temp - 1) != _matchFinder.GetIndexByte(temp - backOffset - 1))\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tint lenTest2 = temp - 1;\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t// for (; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + 1 + lenTest2)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + 1 + lenTest2];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\t// int repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n\t\t\t\tint backOffset = reps[repIndex] + 1;\r\n\t\t\t\tif (_matchFinder.GetIndexByte(-1) !=\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(-1 - backOffset) ||\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(0) !=\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(0 - backOffset))\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTest;\r\n\t\t\t\tfor (lenTest = 2; lenTest < numAvailableBytes; lenTest++)\r\n\t\t\t\t\tif (_matchFinder.GetIndexByte(lenTest - 1) !=\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - backOffset))\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\t\t\t\t\r\n\t\t\t\tif (_maxMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tint lenTest2 = lenTest + 1;\r\n\t\t\t\t\tint limit = Math.min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\tif (_matchFinder.GetIndexByte(lenTest2 - 1) !=\r\n\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest2 - 1 - backOffset))\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - backOffset),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t//    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\tif (newLen >= 2)\r\n\t\t\t{\r\n\t\t\t\tif (newLen == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\r\n\t\t\t\tfor (int lenTest = newLen; lenTest >= 2; lenTest--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[lenTest];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (_maxMode && (lenTest == newLen || curBack != _matchDistances[lenTest + 1]))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint backOffset = curBack + 1;\r\n\t\t\t\t\t\tint lenTest2 = lenTest + 1;\r\n\t\t\t\t\t\tint limit = Math.min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\t\tif (_matchFinder.GetIndexByte(lenTest2 - 1) != _matchFinder.GetIndexByte(lenTest2 - backOffset - 1))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - backOffset - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1)\r\n\t\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\t\r\n\tint GetOptimumFast(int position, int[] backRes) throws IOException\r\n\t{\r\n\t\tint lenMain;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tint repMaxIndex = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes[0] = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes[0] = _matchDistances[_numFastBytes] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\t\twhile (lenMain > 2)\r\n\t\t{\r\n\t\t\tif (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\r\n\t\t\t\tbreak;\r\n\t\t\tlenMain--;\r\n\t\t}\r\n\t\tif (lenMain == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\tlenMain = 1;\r\n\t\t\r\n\t\tint backMain = _matchDistances[lenMain];\r\n\t\tif (repLens[repMaxIndex] >= 2)\r\n\t\t{\r\n\t\t\tif (repLens[repMaxIndex] + 1 >= lenMain ||\r\n\t\t\t\t\trepLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 12)))\r\n\t\t\t{\r\n\t\t\t\tbackRes[0] = repMaxIndex;\r\n\t\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif (lenMain >= 2)\r\n\t\t{\r\n\t\t\t_longestMatchLength = ReadMatchDistances();\r\n\t\t\tif (_longestMatchLength >= 2 &&\r\n\t\t\t\t\t(\r\n\t\t\t\t\t(_longestMatchLength >= lenMain &&\r\n\t\t\t\t\t_matchDistances[lenMain] < backMain) ||\r\n\t\t\t\t\t_longestMatchLength == lenMain + 1 &&\r\n\t\t\t\t\t!ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\r\n\t\t\t\t\t_longestMatchLength > lenMain + 1 ||\r\n\t\t\t\t\t_longestMatchLength + 1 >= lenMain && lenMain >= 3 &&\r\n\t\t\t\t\tChangePair(_matchDistances[lenMain - 1], backMain)\r\n\t\t\t\t\t)\r\n\t\t\t\t\t)\r\n\t\t\t{\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\tbackRes[0] = -1;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tint repLen = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLen >= 2 && repLen + 1 >= lenMain)\r\n\t\t\t\t{\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\tbackRes[0] = -1;\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbackRes[0] = backMain + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 2);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\t\tbackRes[0] = -1;\r\n\t\treturn 1;\r\n\t}\r\n\t\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\t\t\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen; // kMatchMaxLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\t\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\t\r\n\tint[] posTemp = new int[1];\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\t\t\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\t\t\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\t\t\r\n\t\t\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\t\r\n\t\t\tint len;\r\n\t\t\tif (_fastMode)\r\n\t\t\t\tlen = GetOptimumFast((int)nowPos64, posTemp);\r\n\t\t\telse\r\n\t\t\t\tlen = GetOptimum((int)nowPos64, posTemp);\r\n\t\t\t\r\n\t\t\tint pos = posTemp[0];\r\n\t\t\t\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\t\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\tif (!_fastMode)\r\n\t\t\t\t\t\t\t\tif (--_alignPriceCount == 0)\r\n\t\t\t\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (!_fastMode)\r\n\t\t\t\tif (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\r\n\t\t\t\t{\r\n\t\t\t\tFillPosSlotPrices();\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tlastPosSlotFillingPos = nowPos64;\r\n\t\t\t\t}\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\t\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\t\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tif (!_fastMode)\r\n\t\t{\r\n\t\t\tFillPosSlotPrices();\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\t\t\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t\r\n\t\tlastPosSlotFillingPos = 0;\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\t\r\n\tlong[] processedInSize = new long[1];\r\n\tlong[] processedOutSize = new long[1];\r\n\tboolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\t\r\n\tvoid FillPosSlotPrices()\r\n\t{\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tfor (posSlot = 0; posSlot < Base.kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\r\n\t\t\tfor (; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) +\r\n\t\t\t\t\t\t((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = ((posSlot >> 1) - 1);\r\n\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\r\n\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\t\tBitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = Base.kAlignTableSize;\r\n\t}\r\n\t\r\n\t\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\tif (algorithm < 0 || algorithm > 2)\r\n\t\t\treturn false;\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = Base.kDicLogSizeMax;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++);\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SeNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n\t\r\n\t\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t\"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4, bt4b], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.32 Copyright (c) 1999-2005 Igor Pavlov  2005-12-09\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary, params.MatchFinder >= 1);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SeNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator()\r\n\t\t{ Init(); }\r\n\t\tpublic void Init()\r\n\t\t{ A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\t\tpublic CBenchRandomGenerator()\r\n\t\t{ }\r\n\t\tpublic void Init()\r\n\t\t{ RG.Init(); }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit()\r\n\t\t{ return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn RG.GetRnd(2);\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn 4 + RG.GetRnd(3);\r\n\t\t\treturn 12 + RG.GetRnd(4);\r\n\t\t}\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint offset = GetOffset();\r\n\t\t\t\t\twhile (offset >= Pos)\r\n\t\t\t\t\t\toffset >>>= 1;\r\n\t\t\t\t\toffset += 1;\r\n\t\t\t\t\tint len = 2 + GetLen();\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - offset];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, boolean isBT4, long elapsedTime, long size)\r\n\t{\r\n\t\tlong numCommandsForOne;\r\n\t\tif (isBT4)\r\n\t\t{\r\n\t\t\tlong t = GetLogSize(dictionarySize) - (19 << kSubBits);\r\n\t\t\tnumCommandsForOne = 2000 + ((t * t * 68) >>> (2 * kSubBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong t = GetLogSize(dictionarySize) - (15 << kSubBits);\r\n\t\t\tnumCommandsForOne = 1500 + ((t * t * 41) >>> (2 * kSubBits));\r\n\t\t}\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime,\r\n\t\t\tlong outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 250 + outSize * 21;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tboolean isBT4,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tboolean isBT4,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tString bt2 = \"BT2\";\r\n\tString bt4 = \"BT4\";\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize, boolean isBT4) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\tif (!encoder.SetMatchFinder(isBT4 ?\r\n\t\t\tSevenZip.Compression.LZMA.Encoder.EMatchFinderTypeBT4:\r\n\t\t\tSevenZip.Compression.LZMA.Encoder.EMatchFinderTypeBT2))\r\n\t\t\tthrow new Exception(\"Incorrect MatchFinder\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Init();\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, isBT4, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, isBT4, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, isBT4, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/lzma/LGPL.txt",
    "content": "      GNU LESSER GENERAL PUBLIC LICENSE\r\n           Version 2.1, February 1999\r\n\r\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\r\n     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n Everyone is permitted to copy and distribute verbatim copies\r\n of this license document, but changing it is not allowed.\r\n\r\n[This is the first released version of the Lesser GPL.  It also counts\r\n as the successor of the GNU Library Public License, version 2, hence\r\n the version number 2.1.]\r\n\r\n          Preamble\r\n\r\n  The licenses for most software are designed to take away your\r\nfreedom to share and change it.  By contrast, the GNU General Public\r\nLicenses are intended to guarantee your freedom to share and change\r\nfree software--to make sure the software is free for all its users.\r\n\r\n  This license, the Lesser General Public License, applies to some\r\nspecially designated software packages--typically libraries--of the\r\nFree Software Foundation and other authors who decide to use it.  You\r\ncan use it too, but we suggest you first think carefully about whether\r\nthis license or the ordinary General Public License is the better\r\nstrategy to use in any particular case, based on the explanations below.\r\n\r\n  When we speak of free software, we are referring to freedom of use,\r\nnot price.  Our General Public Licenses are designed to make sure that\r\nyou have the freedom to distribute copies of free software (and charge\r\nfor this service if you wish); that you receive source code or can get\r\nit if you want it; that you can change the software and use pieces of\r\nit in new free programs; and that you are informed that you can do\r\nthese things.\r\n\r\n  To protect your rights, we need to make restrictions that forbid\r\ndistributors to deny you these rights or to ask you to surrender these\r\nrights.  These restrictions translate to certain responsibilities for\r\nyou if you distribute copies of the library or if you modify it.\r\n\r\n  For example, if you distribute copies of the library, whether gratis\r\nor for a fee, you must give the recipients all the rights that we gave\r\nyou.  You must make sure that they, too, receive or can get the source\r\ncode.  If you link other code with the library, you must provide\r\ncomplete object files to the recipients, so that they can relink them\r\nwith the library after making changes to the library and recompiling\r\nit.  And you must show them these terms so they know their rights.\r\n\r\n  We protect your rights with a two-step method: (1) we copyright the\r\nlibrary, and (2) we offer you this license, which gives you legal\r\npermission to copy, distribute and/or modify the library.\r\n\r\n  To protect each distributor, we want to make it very clear that\r\nthere is no warranty for the free library.  Also, if the library is\r\nmodified by someone else and passed on, the recipients should know\r\nthat what they have is not the original version, so that the original\r\nauthor's reputation will not be affected by problems that might be\r\nintroduced by others.\r\n\f\r\n  Finally, software patents pose a constant threat to the existence of\r\nany free program.  We wish to make sure that a company cannot\r\neffectively restrict the users of a free program by obtaining a\r\nrestrictive license from a patent holder.  Therefore, we insist that\r\nany patent license obtained for a version of the library must be\r\nconsistent with the full freedom of use specified in this license.\r\n\r\n  Most GNU software, including some libraries, is covered by the\r\nordinary GNU General Public License.  This license, the GNU Lesser\r\nGeneral Public License, applies to certain designated libraries, and\r\nis quite different from the ordinary General Public License.  We use\r\nthis license for certain libraries in order to permit linking those\r\nlibraries into non-free programs.\r\n\r\n  When a program is linked with a library, whether statically or using\r\na shared library, the combination of the two is legally speaking a\r\ncombined work, a derivative of the original library.  The ordinary\r\nGeneral Public License therefore permits such linking only if the\r\nentire combination fits its criteria of freedom.  The Lesser General\r\nPublic License permits more lax criteria for linking other code with\r\nthe library.\r\n\r\n  We call this license the \"Lesser\" General Public License because it\r\ndoes Less to protect the user's freedom than the ordinary General\r\nPublic License.  It also provides other free software developers Less\r\nof an advantage over competing non-free programs.  These disadvantages\r\nare the reason we use the ordinary General Public License for many\r\nlibraries.  However, the Lesser license provides advantages in certain\r\nspecial circumstances.\r\n\r\n  For example, on rare occasions, there may be a special need to\r\nencourage the widest possible use of a certain library, so that it becomes\r\na de-facto standard.  To achieve this, non-free programs must be\r\nallowed to use the library.  A more frequent case is that a free\r\nlibrary does the same job as widely used non-free libraries.  In this\r\ncase, there is little to gain by limiting the free library to free\r\nsoftware only, so we use the Lesser General Public License.\r\n\r\n  In other cases, permission to use a particular library in non-free\r\nprograms enables a greater number of people to use a large body of\r\nfree software.  For example, permission to use the GNU C Library in\r\nnon-free programs enables many more people to use the whole GNU\r\noperating system, as well as its variant, the GNU/Linux operating\r\nsystem.\r\n\r\n  Although the Lesser General Public License is Less protective of the\r\nusers' freedom, it does ensure that the user of a program that is\r\nlinked with the Library has the freedom and the wherewithal to run\r\nthat program using a modified version of the Library.\r\n\r\n  The precise terms and conditions for copying, distribution and\r\nmodification follow.  Pay close attention to the difference between a\r\n\"work based on the library\" and a \"work that uses the library\".  The\r\nformer contains code derived from the library, whereas the latter must\r\nbe combined with the library in order to run.\r\n\f\r\n      GNU LESSER GENERAL PUBLIC LICENSE\r\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\r\n\r\n  0. This License Agreement applies to any software library or other\r\nprogram which contains a notice placed by the copyright holder or\r\nother authorized party saying it may be distributed under the terms of\r\nthis Lesser General Public License (also called \"this License\").\r\nEach licensee is addressed as \"you\".\r\n\r\n  A \"library\" means a collection of software functions and/or data\r\nprepared so as to be conveniently linked with application programs\r\n(which use some of those functions and data) to form executables.\r\n\r\n  The \"Library\", below, refers to any such software library or work\r\nwhich has been distributed under these terms.  A \"work based on the\r\nLibrary\" means either the Library or any derivative work under\r\ncopyright law: that is to say, a work containing the Library or a\r\nportion of it, either verbatim or with modifications and/or translated\r\nstraightforwardly into another language.  (Hereinafter, translation is\r\nincluded without limitation in the term \"modification\".)\r\n\r\n  \"Source code\" for a work means the preferred form of the work for\r\nmaking modifications to it.  For a library, complete source code means\r\nall the source code for all modules it contains, plus any associated\r\ninterface definition files, plus the scripts used to control compilation\r\nand installation of the library.\r\n\r\n  Activities other than copying, distribution and modification are not\r\ncovered by this License; they are outside its scope.  The act of\r\nrunning a program using the Library is not restricted, and output from\r\nsuch a program is covered only if its contents constitute a work based\r\non the Library (independent of the use of the Library in a tool for\r\nwriting it).  Whether that is true depends on what the Library does\r\nand what the program that uses the Library does.\r\n  \r\n  1. You may copy and distribute verbatim copies of the Library's\r\ncomplete source code as you receive it, in any medium, provided that\r\nyou conspicuously and appropriately publish on each copy an\r\nappropriate copyright notice and disclaimer of warranty; keep intact\r\nall the notices that refer to this License and to the absence of any\r\nwarranty; and distribute a copy of this License along with the\r\nLibrary.\r\n\r\n  You may charge a fee for the physical act of transferring a copy,\r\nand you may at your option offer warranty protection in exchange for a\r\nfee.\r\n\f\r\n  2. You may modify your copy or copies of the Library or any portion\r\nof it, thus forming a work based on the Library, and copy and\r\ndistribute such modifications or work under the terms of Section 1\r\nabove, provided that you also meet all of these conditions:\r\n\r\n    a) The modified work must itself be a software library.\r\n\r\n    b) You must cause the files modified to carry prominent notices\r\n    stating that you changed the files and the date of any change.\r\n\r\n    c) You must cause the whole of the work to be licensed at no\r\n    charge to all third parties under the terms of this License.\r\n\r\n    d) If a facility in the modified Library refers to a function or a\r\n    table of data to be supplied by an application program that uses\r\n    the facility, other than as an argument passed when the facility\r\n    is invoked, then you must make a good faith effort to ensure that,\r\n    in the event an application does not supply such function or\r\n    table, the facility still operates, and performs whatever part of\r\n    its purpose remains meaningful.\r\n\r\n    (For example, a function in a library to compute square roots has\r\n    a purpose that is entirely well-defined independent of the\r\n    application.  Therefore, Subsection 2d requires that any\r\n    application-supplied function or table used by this function must\r\n    be optional: if the application does not supply it, the square\r\n    root function must still compute square roots.)\r\n\r\nThese requirements apply to the modified work as a whole.  If\r\nidentifiable sections of that work are not derived from the Library,\r\nand can be reasonably considered independent and separate works in\r\nthemselves, then this License, and its terms, do not apply to those\r\nsections when you distribute them as separate works.  But when you\r\ndistribute the same sections as part of a whole which is a work based\r\non the Library, the distribution of the whole must be on the terms of\r\nthis License, whose permissions for other licensees extend to the\r\nentire whole, and thus to each and every part regardless of who wrote\r\nit.\r\n\r\nThus, it is not the intent of this section to claim rights or contest\r\nyour rights to work written entirely by you; rather, the intent is to\r\nexercise the right to control the distribution of derivative or\r\ncollective works based on the Library.\r\n\r\nIn addition, mere aggregation of another work not based on the Library\r\nwith the Library (or with a work based on the Library) on a volume of\r\na storage or distribution medium does not bring the other work under\r\nthe scope of this License.\r\n\r\n  3. You may opt to apply the terms of the ordinary GNU General Public\r\nLicense instead of this License to a given copy of the Library.  To do\r\nthis, you must alter all the notices that refer to this License, so\r\nthat they refer to the ordinary GNU General Public License, version 2,\r\ninstead of to this License.  (If a newer version than version 2 of the\r\nordinary GNU General Public License has appeared, then you can specify\r\nthat version instead if you wish.)  Do not make any other change in\r\nthese notices.\r\n\f\r\n  Once this change is made in a given copy, it is irreversible for\r\nthat copy, so the ordinary GNU General Public License applies to all\r\nsubsequent copies and derivative works made from that copy.\r\n\r\n  This option is useful when you wish to copy part of the code of\r\nthe Library into a program that is not a library.\r\n\r\n  4. You may copy and distribute the Library (or a portion or\r\nderivative of it, under Section 2) in object code or executable form\r\nunder the terms of Sections 1 and 2 above provided that you accompany\r\nit with the complete corresponding machine-readable source code, which\r\nmust be distributed under the terms of Sections 1 and 2 above on a\r\nmedium customarily used for software interchange.\r\n\r\n  If distribution of object code is made by offering access to copy\r\nfrom a designated place, then offering equivalent access to copy the\r\nsource code from the same place satisfies the requirement to\r\ndistribute the source code, even though third parties are not\r\ncompelled to copy the source along with the object code.\r\n\r\n  5. A program that contains no derivative of any portion of the\r\nLibrary, but is designed to work with the Library by being compiled or\r\nlinked with it, is called a \"work that uses the Library\".  Such a\r\nwork, in isolation, is not a derivative work of the Library, and\r\ntherefore falls outside the scope of this License.\r\n\r\n  However, linking a \"work that uses the Library\" with the Library\r\ncreates an executable that is a derivative of the Library (because it\r\ncontains portions of the Library), rather than a \"work that uses the\r\nlibrary\".  The executable is therefore covered by this License.\r\nSection 6 states terms for distribution of such executables.\r\n\r\n  When a \"work that uses the Library\" uses material from a header file\r\nthat is part of the Library, the object code for the work may be a\r\nderivative work of the Library even though the source code is not.\r\nWhether this is true is especially significant if the work can be\r\nlinked without the Library, or if the work is itself a library.  The\r\nthreshold for this to be true is not precisely defined by law.\r\n\r\n  If such an object file uses only numerical parameters, data\r\nstructure layouts and accessors, and small macros and small inline\r\nfunctions (ten lines or less in length), then the use of the object\r\nfile is unrestricted, regardless of whether it is legally a derivative\r\nwork.  (Executables containing this object code plus portions of the\r\nLibrary will still fall under Section 6.)\r\n\r\n  Otherwise, if the work is a derivative of the Library, you may\r\ndistribute the object code for the work under the terms of Section 6.\r\nAny executables containing that work also fall under Section 6,\r\nwhether or not they are linked directly with the Library itself.\r\n\f\r\n  6. As an exception to the Sections above, you may also combine or\r\nlink a \"work that uses the Library\" with the Library to produce a\r\nwork containing portions of the Library, and distribute that work\r\nunder terms of your choice, provided that the terms permit\r\nmodification of the work for the customer's own use and reverse\r\nengineering for debugging such modifications.\r\n\r\n  You must give prominent notice with each copy of the work that the\r\nLibrary is used in it and that the Library and its use are covered by\r\nthis License.  You must supply a copy of this License.  If the work\r\nduring execution displays copyright notices, you must include the\r\ncopyright notice for the Library among them, as well as a reference\r\ndirecting the user to the copy of this License.  Also, you must do one\r\nof these things:\r\n\r\n    a) Accompany the work with the complete corresponding\r\n    machine-readable source code for the Library including whatever\r\n    changes were used in the work (which must be distributed under\r\n    Sections 1 and 2 above); and, if the work is an executable linked\r\n    with the Library, with the complete machine-readable \"work that\r\n    uses the Library\", as object code and/or source code, so that the\r\n    user can modify the Library and then relink to produce a modified\r\n    executable containing the modified Library.  (It is understood\r\n    that the user who changes the contents of definitions files in the\r\n    Library will not necessarily be able to recompile the application\r\n    to use the modified definitions.)\r\n\r\n    b) Use a suitable shared library mechanism for linking with the\r\n    Library.  A suitable mechanism is one that (1) uses at run time a\r\n    copy of the library already present on the user's computer system,\r\n    rather than copying library functions into the executable, and (2)\r\n    will operate properly with a modified version of the library, if\r\n    the user installs one, as long as the modified version is\r\n    interface-compatible with the version that the work was made with.\r\n\r\n    c) Accompany the work with a written offer, valid for at\r\n    least three years, to give the same user the materials\r\n    specified in Subsection 6a, above, for a charge no more\r\n    than the cost of performing this distribution.\r\n\r\n    d) If distribution of the work is made by offering access to copy\r\n    from a designated place, offer equivalent access to copy the above\r\n    specified materials from the same place.\r\n\r\n    e) Verify that the user has already received a copy of these\r\n    materials or that you have already sent this user a copy.\r\n\r\n  For an executable, the required form of the \"work that uses the\r\nLibrary\" must include any data and utility programs needed for\r\nreproducing the executable from it.  However, as a special exception,\r\nthe materials to be distributed need not include anything that is\r\nnormally distributed (in either source or binary form) with the major\r\ncomponents (compiler, kernel, and so on) of the operating system on\r\nwhich the executable runs, unless that component itself accompanies\r\nthe executable.\r\n\r\n  It may happen that this requirement contradicts the license\r\nrestrictions of other proprietary libraries that do not normally\r\naccompany the operating system.  Such a contradiction means you cannot\r\nuse both them and the Library together in an executable that you\r\ndistribute.\r\n\f\r\n  7. You may place library facilities that are a work based on the\r\nLibrary side-by-side in a single library together with other library\r\nfacilities not covered by this License, and distribute such a combined\r\nlibrary, provided that the separate distribution of the work based on\r\nthe Library and of the other library facilities is otherwise\r\npermitted, and provided that you do these two things:\r\n\r\n    a) Accompany the combined library with a copy of the same work\r\n    based on the Library, uncombined with any other library\r\n    facilities.  This must be distributed under the terms of the\r\n    Sections above.\r\n\r\n    b) Give prominent notice with the combined library of the fact\r\n    that part of it is a work based on the Library, and explaining\r\n    where to find the accompanying uncombined form of the same work.\r\n\r\n  8. You may not copy, modify, sublicense, link with, or distribute\r\nthe Library except as expressly provided under this License.  Any\r\nattempt otherwise to copy, modify, sublicense, link with, or\r\ndistribute the Library is void, and will automatically terminate your\r\nrights under this License.  However, parties who have received copies,\r\nor rights, from you under this License will not have their licenses\r\nterminated so long as such parties remain in full compliance.\r\n\r\n  9. You are not required to accept this License, since you have not\r\nsigned it.  However, nothing else grants you permission to modify or\r\ndistribute the Library or its derivative works.  These actions are\r\nprohibited by law if you do not accept this License.  Therefore, by\r\nmodifying or distributing the Library (or any work based on the\r\nLibrary), you indicate your acceptance of this License to do so, and\r\nall its terms and conditions for copying, distributing or modifying\r\nthe Library or works based on it.\r\n\r\n  10. Each time you redistribute the Library (or any work based on the\r\nLibrary), the recipient automatically receives a license from the\r\noriginal licensor to copy, distribute, link with or modify the Library\r\nsubject to these terms and conditions.  You may not impose any further\r\nrestrictions on the recipients' exercise of the rights granted herein.\r\nYou are not responsible for enforcing compliance by third parties with\r\nthis License.\r\n\f\r\n  11. If, as a consequence of a court judgment or allegation of patent\r\ninfringement or for any other reason (not limited to patent issues),\r\nconditions are imposed on you (whether by court order, agreement or\r\notherwise) that contradict the conditions of this License, they do not\r\nexcuse you from the conditions of this License.  If you cannot\r\ndistribute so as to satisfy simultaneously your obligations under this\r\nLicense and any other pertinent obligations, then as a consequence you\r\nmay not distribute the Library at all.  For example, if a patent\r\nlicense would not permit royalty-free redistribution of the Library by\r\nall those who receive copies directly or indirectly through you, then\r\nthe only way you could satisfy both it and this License would be to\r\nrefrain entirely from distribution of the Library.\r\n\r\nIf any portion of this section is held invalid or unenforceable under any\r\nparticular circumstance, the balance of the section is intended to apply,\r\nand the section as a whole is intended to apply in other circumstances.\r\n\r\nIt is not the purpose of this section to induce you to infringe any\r\npatents or other property right claims or to contest validity of any\r\nsuch claims; this section has the sole purpose of protecting the\r\nintegrity of the free software distribution system which is\r\nimplemented by public license practices.  Many people have made\r\ngenerous contributions to the wide range of software distributed\r\nthrough that system in reliance on consistent application of that\r\nsystem; it is up to the author/donor to decide if he or she is willing\r\nto distribute software through any other system and a licensee cannot\r\nimpose that choice.\r\n\r\nThis section is intended to make thoroughly clear what is believed to\r\nbe a consequence of the rest of this License.\r\n\r\n  12. If the distribution and/or use of the Library is restricted in\r\ncertain countries either by patents or by copyrighted interfaces, the\r\noriginal copyright holder who places the Library under this License may add\r\nan explicit geographical distribution limitation excluding those countries,\r\nso that distribution is permitted only in or among countries not thus\r\nexcluded.  In such case, this License incorporates the limitation as if\r\nwritten in the body of this License.\r\n\r\n  13. The Free Software Foundation may publish revised and/or new\r\nversions of the Lesser General Public License from time to time.\r\nSuch new versions will be similar in spirit to the present version,\r\nbut may differ in detail to address new problems or concerns.\r\n\r\nEach version is given a distinguishing version number.  If the Library\r\nspecifies a version number of this License which applies to it and\r\n\"any later version\", you have the option of following the terms and\r\nconditions either of that version or of any later version published by\r\nthe Free Software Foundation.  If the Library does not specify a\r\nlicense version number, you may choose any version ever published by\r\nthe Free Software Foundation.\r\n\f\r\n  14. If you wish to incorporate parts of the Library into other free\r\nprograms whose distribution conditions are incompatible with these,\r\nwrite to the author to ask for permission.  For software which is\r\ncopyrighted by the Free Software Foundation, write to the Free\r\nSoftware Foundation; we sometimes make exceptions for this.  Our\r\ndecision will be guided by the two goals of preserving the free status\r\nof all derivatives of our free software and of promoting the sharing\r\nand reuse of software generally.\r\n\r\n          NO WARRANTY\r\n\r\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\r\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\r\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\r\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\r\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\r\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\r\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\r\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\r\n\r\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\r\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\r\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\r\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\r\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\r\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\r\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\r\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\r\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\r\nDAMAGES.\r\n\r\n         END OF TERMS AND CONDITIONS\r\n\f\r\n           How to Apply These Terms to Your New Libraries\r\n\r\n  If you develop a new library, and you want it to be of the greatest\r\npossible use to the public, we recommend making it free software that\r\neveryone can redistribute and change.  You can do so by permitting\r\nredistribution under these terms (or, alternatively, under the terms of the\r\nordinary General Public License).\r\n\r\n  To apply these terms, attach the following notices to the library.  It is\r\nsafest to attach them to the start of each source file to most effectively\r\nconvey the exclusion of warranty; and each file should have at least the\r\n\"copyright\" line and a pointer to where the full notice is found.\r\n\r\n    <one line to give the library's name and a brief idea of what it does.>\r\n    Copyright (C) <year>  <name of author>\r\n\r\n    This library is free software; you can redistribute it and/or\r\n    modify it under the terms of the GNU Lesser General Public\r\n    License as published by the Free Software Foundation; either\r\n    version 2.1 of the License, or (at your option) any later version.\r\n\r\n    This library is distributed in the hope that it will be useful,\r\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r\n    Lesser General Public License for more details.\r\n\r\n    You should have received a copy of the GNU Lesser General Public\r\n    License along with this library; if not, write to the Free Software\r\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nAlso add information on how to contact you by electronic and paper mail.\r\n\r\nYou should also get your employer (if you work as a programmer) or your\r\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\r\nnecessary.  Here is a sample; alter the names:\r\n\r\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\r\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\r\n\r\n  <signature of Ty Coon>, 1 April 1990\r\n  Ty Coon, President of Vice\r\n\r\nThat's all there is to it!\r\n\r\n\r\n"
  },
  {
    "path": "src/lzma/Methods.txt",
    "content": "Compression method IDs (4.27)\r\n-----------------------------\r\n\r\nEach compression method in 7z has unique binary value (ID).\r\nThe length of ID in bytes is arbitrary but it can not exceed 15 bytes.\r\n\r\nList of defined IDs\r\n-------------------\r\n      \r\n00 - Copy\r\n01 - Reserved\r\n02 - Common\r\n   03 Swap\r\n      - 2 Swap2\r\n      - 4 Swap4\r\n   04 Delta (subject to change)\r\n\r\n03 - 7z\r\n   01 - LZMA\r\n      01 - Version\r\n  \r\n   03 - Branch\r\n      01 - x86\r\n         03  - BCJ\r\n         1B  - BCJ2\r\n      02 - PPC\r\n         05 - BC_PPC_B (Big Endian)\r\n      03 - Alpha\r\n         01 - BC_Alpha\r\n      04 - IA64\r\n         01 - BC_IA64\r\n      05 - ARM\r\n         01 - BC_ARM\r\n      06 - M68\r\n         05 - BC_M68_B (Big Endian)\r\n      07 - ARM Thumb\r\n         01 - BC_ARMThumb\r\n      08 - SPARC\r\n         05 - BC_SPARC\r\n\r\n   04 - PPMD\r\n      01 - Version\r\n\r\n04 - Misc\r\n   00 - Reserved\r\n   01 - Zip\r\n      00 - Copy (not used). Use {00} instead\r\n      01 - Shrink\r\n      06 - Implode\r\n      08 - Deflate\r\n      09 - Deflate64\r\n      12 - BZip2 (not used). Use {04 02 02} instead\r\n   02 - BZip\r\n      02 - BZip2\r\n   03 - Rar\r\n      01 - Rar15\r\n      02 - Rar20\r\n      03 - Rar29\r\n   04 - Arj\r\n      01 - Arj (1,2,3)\r\n      02 - Arj 4\r\n   05 - Z\r\n   06 - Lzh\r\n   07 - Reserved for 7z\r\n   08 - Cab\r\n\r\n\r\n06 - Crypto \r\n   00 - \r\n   01 - AES\r\n      0x - AES-128\r\n      4x - AES-192\r\n      8x - AES-256\r\n\r\n      x0 - ECB\r\n      x1 - CBC\r\n      x2 - CFB\r\n      x3 - OFB\r\n\r\n   07 - Reserved\r\n   0F - Reserved\r\n\r\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\r\n\r\n   F1 - Misc Ciphers (Combine)\r\n      01 - Zip\r\n         01 - Main Zip crypto algo\r\n      03 - RAR\r\n         02 - \r\n         03 - Rar29 AES-128 + (modified SHA-1)\r\n      07 - 7z\r\n         01 - AES-256 + SHA-256\r\n\r\n07 - Hash (subject to change)\r\n   00 - \r\n   01 - CRC\r\n   02 - SHA-1\r\n   03 - SHA-256\r\n   04 - SHA-384\r\n   05 - SHA-512\r\n\r\n   F0 - Misc Hash\r\n\r\n   F1 - Misc\r\n      03 - RAR\r\n         03 - Rar29 Password Hashing (modified SHA1)\r\n      07 - 7z \r\n         01 - SHA-256 Password Hashing\r\n    \r\n   \r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/lzma/history.txt",
    "content": "HISTORY of the LZMA SDK\r\n-----------------------\r\n\r\n  Version 4.32                2005-12-09\r\n  --------------------------------------\r\n    - Java version of LZMA SDK was included\r\n\r\n\r\n  Version 4.30                2005-11-20\r\n  --------------------------------------\r\n    - Compression ratio was improved in -a2 mode\r\n    - Speed optimizations for compressing in -a2 mode\r\n    - -fb switch now supports values up to 273\r\n    - Bug in 7z_C (7zIn.c) was fixed:\r\n      It used Alloc/Free functions from different memory pools.\r\n      So if program used two memory pools, it worked incorrectly.\r\n    - 7z_C: .7z format supporting was improved\r\n    - LZMA# SDK (C#.NET version) was included\r\n\r\n\r\n  Version 4.27 (Updated)      2005-09-21\r\n  --------------------------------------\r\n   - Some GUIDs/interfaces in C++ were changed.\r\n     IStream.h:\r\n       ISequentialInStream::Read now works as old ReadPart\r\n       ISequentialOutStream::Write now works as old WritePart\r\n\r\n  \r\n  Version 4.27                2005-08-07\r\n  --------------------------------------\r\n    - Bug in LzmaDecodeSize.c was fixed:\r\n       if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r\n       decompressing worked incorrectly.\r\n\r\n\r\n  Version 4.26                2005-08-05\r\n  --------------------------------------\r\n    - Fixes in 7z_C code and LzmaTest.c:\r\n      previous versions could work incorrectly,\r\n      if malloc(0) returns 0\r\n\r\n\r\n  Version 4.23                2005-06-29\r\n  --------------------------------------\r\n    - Small fixes in C++ code\r\n\r\n\r\n  Version 4.22                2005-06-10\r\n  --------------------------------------\r\n    - Small fixes\r\n\r\n\r\n  Version 4.21                2005-06-08\r\n  --------------------------------------\r\n    - Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r\n    - New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r\n        - LzmaStateDecode.h\r\n        - LzmaStateDecode.c\r\n        - LzmaStateTest.c\r\n    - ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r\n\r\n  \r\n  Version 4.17                2005-04-18\r\n  --------------------------------------\r\n    - New example for RAM->RAM compressing/decompressing: \r\n      LZMA + BCJ (filter for x86 code):\r\n        - LzmaRam.h\r\n        - LzmaRam.cpp\r\n        - LzmaRamDecode.h\r\n        - LzmaRamDecode.c\r\n        - -f86 switch for lzma.exe\r\n\r\n  \r\n  Version 4.16                2005-03-29\r\n  --------------------------------------\r\n    - Bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r\n       If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r\n       decoder could access memory outside of allocated range.\r\n    - Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r\n      Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r\n      LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r\n    - Small speed optimization in LZMA C++ code\r\n    - filter for SPARC's code was added\r\n    - Simplified version of .7z ANSI-C Decoder was included\r\n\r\n\r\n  Version 4.06                2004-09-05\r\n  --------------------------------------\r\n    - Bug in v4.05 was fixed:\r\n        LZMA-Encoder didn't release output stream in some cases.\r\n\r\n\r\n  Version 4.05                2004-08-25\r\n  --------------------------------------\r\n    - Source code of filters for x86, IA-64, ARM, ARM-Thumb \r\n      and PowerPC code was included to SDK\r\n    - Some internal minor changes\r\n\r\n\r\n  Version 4.04                2004-07-28\r\n  --------------------------------------\r\n    - More compatibility with some C++ compilers\r\n\r\n\r\n  Version 4.03                2004-06-18\r\n  --------------------------------------\r\n    - \"Benchmark\" command was added. It measures compressing \r\n      and decompressing speed and shows rating values. \r\n      Also it checks hardware errors.\r\n\r\n\r\n  Version 4.02                2004-06-10\r\n  --------------------------------------\r\n    - C++ LZMA Encoder/Decoder code now is more portable\r\n      and it can be compiled by GCC on Linux.\r\n\r\n\r\n  Version 4.01                2004-02-15\r\n  --------------------------------------\r\n    - Some detection of data corruption was enabled.\r\n        LzmaDecode.c / RangeDecoderReadByte\r\n        .....\r\n        {\r\n          rd->ExtraBytes = 1;\r\n          return 0xFF;\r\n        }\r\n\r\n\r\n  Version 4.00                2004-02-13\r\n  --------------------------------------\r\n    - Original version of LZMA SDK\r\n\r\n\r\n\r\nHISTORY of the LZMA\r\n-------------------\r\n  2001-2004:  Improvements to LZMA compressing/decompressing code, \r\n              keeping compatibility with original LZMA format\r\n  1996-2001:  Development of LZMA compression format\r\n\r\n  Some milestones:\r\n\r\n  2001-08-30: LZMA compression was added to 7-Zip\r\n  1999-01-02: First version of 7-Zip was released\r\n  \r\n\r\nEnd of document\r\n"
  },
  {
    "path": "src/lzma/lzma.txt",
    "content": "LZMA SDK 4.32\r\n-------------\r\n\r\nLZMA SDK 4.32  Copyright (C) 1999-2005 Igor Pavlov\r\n\r\nLZMA SDK provides the documentation, samples, header files, libraries, \r\nand tools you need to develop applications that use LZMA compression.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\nLZMA is an improved version of famous LZ77 compression algorithm. \r\nIt was improved in way of maximum increasing of compression ratio,\r\nkeeping high decompression speed and low memory requirements for \r\ndecompressing.\r\n\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nLZMA SDK is available under any of the following licenses:\r\n\r\n1) GNU Lesser General Public License (GNU LGPL)\r\n2) Common Public License (CPL)\r\n3) Simplified license for unmodified code (read SPECIAL EXCEPTION) \r\n4) Proprietary license \r\n\r\nIt means that you can select one of these four options and follow rules of that license.\r\n\r\n\r\n1,2) GNU LGPL and CPL licenses are pretty similar and both these\r\nlicenses are classified as \r\n - \"Free software licenses\" at http://www.gnu.org/ \r\n - \"OSI-approved\" at http://www.opensource.org/\r\n\r\n\r\n3) SPECIAL EXCEPTION\r\n\r\nIgor Pavlov, as the author of this code, expressly permits you \r\nto statically or dynamically link your code (or bind by name) \r\nto the files from LZMA SDK without subjecting your linked \r\ncode to the terms of the CPL or GNU LGPL. \r\nAny modifications or additions to files from LZMA SDK, however, \r\nare subject to the GNU LGPL or CPL terms.\r\n\r\nSPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code, \r\nwhile you keep LZMA SDK code unmodified.\r\n\r\n\r\nSPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use this code under the same terms and conditions contained in the License \r\nAgreement you have for any previous version of LZMA SDK developed by Igor Pavlov.\r\n\r\nSPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version \r\nof LZMA SDK as update for previous versions.\r\n\r\n\r\nSPECIAL EXCEPTION #3: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use code of examples (LzmaTest.c, LzmaStateTest.c, LzmaAlone.cpp, \r\nLzmaAlone.cs, LzmaAlone.java) as public domain code. \r\n\r\n\r\n4) Proprietary license\r\n\r\nLZMA SDK also can be available under a proprietary license which \r\ncan include:\r\n\r\n1) Right to modify code without subjecting modified code to the \r\nterms of the CPL or GNU LGPL\r\n2) Technical support for code\r\n\r\nTo request such proprietary license or any additional consultations,\r\nsend email message from that page:\r\nhttp://www.7-zip.org/support.html\r\n\r\n\r\nYou should have received a copy of the GNU Lesser General Public\r\nLicense along with this library; if not, write to the Free Software\r\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nYou should have received a copy of the Common Public License\r\nalong with this library.\r\n\r\n\r\nLZMA SDK Contents\r\n-----------------\r\n\r\nLZMA SDK includes:\r\n\r\n  - C++ source code of LZMA compressing and decompressing\r\n  - ANSI-C compatible source code for LZMA decompressing\r\n  - C# source code for LZMA compressing and decompressing\r\n  - Java source code for LZMA compressing and decompressing\r\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\r\n\r\nANSI-C LZMA decompression code was ported from original C++ sources to C.\r\nAlso it was simplified and optimized for code size. \r\nBut it is fully compatible with LZMA from 7-Zip.\r\n\r\n\r\nUNIX/Linux version \r\n------------------\r\nTo compile C++ version of file->file LZMA, go to directory\r\nC/7zip/Compress/LZMA_Alone \r\nand type \"make\" or \"make clean all\" to recompile all.\r\n\r\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\r\nTo compile with static libraries, change string in makefile\r\nLIB = -lm\r\nto string  \r\nLIB = -lm -static\r\n\r\n\r\nFiles\r\n---------------------\r\nC        - C / CPP source code\r\nCS       - C# source code\r\nJava     - Java source code\r\nlzma.txt - LZMA SDK description (this file)\r\n7zFormat.txt - 7z Format description\r\n7zC.txt  - 7z ANSI-C Decoder description (this file)\r\nmethods.txt  - Compression method IDs for .7z\r\nLGPL.txt - GNU Lesser General Public License\r\nCPL.html - Common Public License\r\nlzma.exe - Compiled file->file LZMA encoder/decoder for Windows\r\nhistory.txt - history of the LZMA SDK\r\n\r\n\r\nSource code structure\r\n---------------------\r\n\r\nC  - C / CPP files\r\n  Common  - common files for C++ projects\r\n  Windows - common files for Windows related code\r\n  7zip    - files related to 7-Zip Project\r\n    Common   - common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n        BinTree    - Binary Tree Match Finder for LZ algorithm\r\n        HashChain  - Hash Chain Match Finder for LZ algorithm\r\n        Patricia   - Patricia Match Finder for LZ algorithm\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n      LZMA         - LZMA compression/decompression on C++\r\n      LZMA_Alone   - file->file LZMA compression/decompression\r\n      LZMA_C       - ANSI-C compatible LZMA decompressor\r\n        LzmaDecode.h  - interface for LZMA decoding on ANSI-C\r\n        LzmaDecode.c      - LZMA decoding on ANSI-C (new fastest version)\r\n        LzmaDecodeSize.c  - LZMA decoding on ANSI-C (old size-optimized version)\r\n        LzmaTest.c        - test application that decodes LZMA encoded file\r\n        LzmaStateDecode.h - interface for LZMA decoding (State version)\r\n        LzmaStateDecode.c - LZMA decoding on ANSI-C (State version)\r\n        LzmaStateTest.c   - test application (State version)\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n    Archive - files related to archiving\r\n      7z_C     - 7z ANSI-C Decoder\r\n\r\nCS - C# files\r\n  7zip\r\n    Common   - some common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      LzmaAlone    - file->file LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nJava  - Java files\r\n  SevenZip\r\n    Compression    - files related to compression/decompression\r\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nC/C++ source code of LZMA SDK is part of 7-Zip project.\r\n\r\nYou can find ANSI-C LZMA decompressing code at folder \r\n  C/7zip/Compress/LZMA_C\r\n7-Zip doesn't use that ANSI-C LZMA code and that code was developed \r\nspecially for this SDK. And files from LZMA_C do not need files from \r\nother directories of SDK for compiling.\r\n\r\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r\n\r\n  http://sourceforge.net/projects/sevenzip/\r\n\r\n\r\nLZMA Decompression features\r\n---------------------------\r\n  - Variable dictionary size (up to 256 MB)\r\n  - Estimated compressing speed: about 500 KB/s on 1 GHz CPU\r\n  - Estimated decompressing speed: \r\n      - 8-12 MB/s on 1 GHz Intel Pentium 3 or AMD Athlon\r\n      - 500-1000 KB/s on 100 MHz ARM, MIPS, PowerPC or other simple RISC\r\n  - Small memory requirements for decompressing (8-32 KB + DictionarySize)\r\n  - Small code size for decompressing: 2-8 KB (depending from \r\n    speed optimizations) \r\n\r\nLZMA decoder uses only integer operations and can be \r\nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r\n\r\nSome critical operations that affect to speed of LZMA decompression:\r\n  1) 32*16 bit integer multiply\r\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\r\n  3) 32-bit shift and arithmetic operations\r\n\r\nSpeed of LZMA decompressing mostly depends from CPU speed.\r\nMemory speed has no big meaning. But if your CPU has small data cache, \r\noverall weight of memory speed will slightly increase.\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nUsing LZMA encoder/decoder executable\r\n--------------------------------------\r\n\r\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\r\n\r\n  e: encode file\r\n\r\n  d: decode file\r\n\r\n  b: Benchmark. There are two tests: compressing and decompressing \r\n     with LZMA method. Benchmark shows rating in MIPS (million \r\n     instructions per second). Rating value is calculated from \r\n     measured speed and it is normalized with AMD Athlon XP CPU\r\n     results. Also Benchmark checks possible hardware errors (RAM \r\n     errors in most cases). Benchmark uses these settings:\r\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d. Also you \r\n     can change number of iterations. Example for 30 iterations:\r\n\tLZMA b 30\r\n     Default number of iterations is 10.\r\n\r\n<Switches>\r\n  \r\n\r\n  -a{N}:  set compression mode 0 = fast, 1 = normal, 2 = max\r\n          default: 2 (max)\r\n\r\n  d{N}:   Sets Dictionary size - [0, 28], default: 23 (8MB)\r\n          The maximum value for dictionary size is 256 MB = 2^28 bytes.\r\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \r\n          For decompressing file compressed by LZMA method with dictionary \r\n          size D = 2^N you need about D bytes of memory (RAM).\r\n\r\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\r\n          Usually big number gives a little bit better compression ratio \r\n          and slower compression process.\r\n\r\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\r\n          Sometimes lc=4 gives gain for big files.\r\n\r\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r\n          lp switch is intended for periodical data when period is \r\n          equal 2^N. For example, for 32-bit (4 bytes) \r\n          periodical data you can use lp=2. Often it's better to set lc0, \r\n          if you change lp switch.\r\n\r\n  -pb{N}: set number of pos bits - [0, 4], default: 2\r\n          pb switch is intended for periodical data \r\n          when period is equal 2^N.\r\n\r\n  -mf{MF_ID}: set Match Finder. Default: bt4. \r\n              Compression ratio for all bt* and pat* almost the same.\r\n              Algorithms from hc* group doesn't provide good compression \r\n              ratio, but they often works pretty fast in combination with \r\n              fast mode (-a0). Methods from bt* group require less memory \r\n              than methods from pat* group. Usually bt4 works faster than \r\n              any pat*, but for some types of files pat* can work faster. \r\n\r\n              Memory requirements depend from dictionary size \r\n              (parameter \"d\" in table below). \r\n\r\n               MF_ID     Memory                   Description\r\n\r\n                bt2    d*9.5 +  1MB  Binary Tree with 2 bytes hashing.\r\n                bt3    d*9.5 + 65MB  Binary Tree with 2-3(full) bytes hashing.\r\n                bt4    d*9.5 +  6MB  Binary Tree with 2-3-4 bytes hashing.\r\n                bt4b   d*9.5 + 34MB  Binary Tree with 2-3-4(big) bytes hashing.\r\n                pat2r  d*26  +  1MB  Patricia Tree with 2-bits nodes, removing.\r\n                pat2   d*38  +  1MB  Patricia Tree with 2-bits nodes.\r\n                pat2h  d*38  + 77MB  Patricia Tree with 2-bits nodes, 2-3 bytes hashing.\r\n                pat3h  d*62  + 85MB  Patricia Tree with 3-bits nodes, 2-3 bytes hashing.\r\n                pat4h  d*110 +101MB  Patricia Tree with 4-bits nodes, 2-3 bytes hashing.\r\n                hc3    d*5.5 +  1MB  Hash Chain with 2-3 bytes hashing.\r\n                hc4    d*5.5 +  6MB  Hash Chain with 2-3-4 bytes hashing.\r\n\r\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \r\n          eos marker, since LZMA decoder knows uncompressed size \r\n          stored in .lzma file header.\r\n\r\n  -si:    Read data from stdin (it will write End Of Stream marker).\r\n  -so:    Write data to stdout\r\n\r\n\r\nExamples:\r\n\r\n1) LZMA e file.bin file.lzma -d16 -lc0 \r\n\r\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r\nand 0 literal context bits. -lc0 allows to reduce memory requirements \r\nfor decompression.\r\n\r\n\r\n2) LZMA e file.bin file.lzma -lc0 -lp2\r\n\r\ncompresses file.bin to file.lzma with settings suitable \r\nfor 32-bit periodical data (for example, ARM or MIPS code).\r\n\r\n3) LZMA d file.lzma file.bin\r\n\r\ndecompresses file.lzma to file.bin.\r\n\r\n\r\nCompression ratio hints\r\n-----------------------\r\n\r\nRecommendations\r\n---------------\r\n\r\nTo increase compression ratio for LZMA compressing it's desirable \r\nto have aligned data (if it's possible) and also it's desirable to locate\r\ndata in such order, where code is grouped in one place and data is \r\ngrouped in other place (it's better than such mixing: code, data, code,\r\ndata, ...).\r\n\r\n\r\nUsing Filters\r\n-------------\r\nYou can increase compression ratio for some data types, using\r\nspecial filters before compressing. For example, it's possible to \r\nincrease compression ratio on 5-10% for code for those CPU ISAs: \r\nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r\n\r\nYou can find C/C++ source code of such filters in folder \"7zip/Compress/Branch\"\r\n\r\nYou can check compression ratio gain of these filters with such \r\n7-Zip commands (example for ARM code):\r\nNo filter:\r\n  7z a a1.7z a.bin -m0=lzma\r\n\r\nWith filter for little-endian ARM code:\r\n  7z a a2.7z a.bin -m0=bc_arm -m1=lzma        \r\n\r\nWith filter for big-endian ARM code (using additional Swap4 filter):\r\n  7z a a3.7z a.bin -m0=swap4 -m1=bc_arm -m2=lzma\r\n\r\nIt works in such manner:\r\nCompressing    = Filter_encoding + LZMA_encoding\r\nDecompressing  = LZMA_decoding + Filter_decoding\r\n\r\nCompressing and decompressing speed of such filters is very high,\r\nso it will not increase decompressing time too much.\r\nMoreover, it reduces decompression time for LZMA_decoding, \r\nsince compression ratio with filtering is higher.\r\n\r\nThese filters convert CALL (calling procedure) instructions \r\nfrom relative offsets to absolute addresses, so such data becomes more \r\ncompressible. Source code of these CALL filters is pretty simple\r\n(about 20 lines of C++), so you can convert it from C++ version yourself.\r\n\r\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r\n\r\n\r\nLZMA compressed file format\r\n---------------------------\r\nOffset Size Description\r\n  0     1   Special LZMA properties for compressed data\r\n  1     4   Dictionary size (little endian)\r\n  5     8   Uncompressed size (little endian). -1 means unknown size\r\n 13         Compressed data\r\n\r\n\r\nANSI-C LZMA Decoder\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nTo compile ANSI-C LZMA Decoder you can use one of the following files sets:\r\n1) LzmaDecode.h + LzmaDecode.c + LzmaTest.c  (fastest version)\r\n2) LzmaDecode.h + LzmaDecodeSize.c + LzmaTest.c  (old size-optimized version)\r\n3) LzmaStateDecode.h + LzmaStateDecode.c + LzmaStateTest.c  (zlib-like interface)\r\n\r\n\r\nMemory requirements for LZMA decoding\r\n-------------------------------------\r\n\r\nLZMA decoder doesn't allocate memory itself, so you must \r\nallocate memory and send it to LZMA.\r\n\r\nStack usage of LZMA decoding function for local variables is not \r\nlarger than 200 bytes.\r\n\r\nHow To decompress data\r\n----------------------\r\n\r\nLZMA Decoder (ANSI-C version) now supports 5 interfaces:\r\n1) Single-call Decompressing\r\n2) Single-call Decompressing with input stream callback\r\n3) Multi-call Decompressing with output buffer\r\n4) Multi-call Decompressing with input callback and output buffer\r\n5) Multi-call State Decompressing (zlib-like interface)\r\n\r\nVariant-5 is similar to Variant-4, but Variant-5 doesn't use callback functions.\r\n\r\nDecompressing steps\r\n-------------------\r\n\r\n1) read LZMA properties (5 bytes):\r\n   unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n2) read uncompressed size (8 bytes, little-endian)\r\n\r\n3) Decode properties:\r\n\r\n  CLzmaDecoderState state;  /* it's 24-140 bytes structure, if int is 32-bit */\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n\r\n4) Allocate memory block for internal Structures:\r\n\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n\r\n  LZMA decoder uses array of CProb variables as internal structure.\r\n  By default, CProb is unsigned_short. But you can define _LZMA_PROB32 to make \r\n  it unsigned_int. It can increase speed on some 32-bit CPUs, but memory \r\n  usage will be doubled in that case.\r\n\r\n\r\n5) Main Decompressing\r\n\r\nYou must use one of the following interfaces:\r\n\r\n5.1 Single-call Decompressing\r\n-----------------------------\r\nWhen to use: RAM->RAM decompressing\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: no defines\r\nMemory Requirements:\r\n  - Input buffer: compressed size\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  int res = LzmaDecode(&state, \r\n      inStream, compressedSize, &inProcessed,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.2 Single-call Decompressing with input stream callback\r\n--------------------------------------------------------\r\nWhen to use: File->RAM or Flash->RAM decompressing.\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB\r\nMemory Requirements:\r\n  - Buffer for input stream: any size (for example, 16 KB)\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  typedef struct _CBuffer\r\n  {\r\n    ILzmaInCallback InCallback;\r\n    FILE *File;\r\n    unsigned char Buffer[kInBufferSize];\r\n  } CBuffer;\r\n\r\n  int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n  {\r\n    CBuffer *bo = (CBuffer *)object;\r\n    *buffer = bo->Buffer;\r\n    *size = MyReadFile(bo->File, bo->Buffer, kInBufferSize);\r\n    return LZMA_RESULT_OK;\r\n  }\r\n\r\n  CBuffer g_InBuffer;\r\n\r\n  g_InBuffer.File = inFile;\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  int res = LzmaDecode(&state, \r\n      &g_InBuffer.InCallback,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.3 Multi-call decompressing with output buffer\r\n-----------------------------------------------\r\nWhen to use: RAM->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Input buffer: compressed size\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details.\r\n\r\n\r\n5.4 Multi-call decompressing with input callback and output buffer\r\n------------------------------------------------------------------\r\nWhen to use: File->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB, _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      &bo.InCallback,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details:\r\n\r\n\r\n5.5 Multi-call State Decompressing (zlib-like interface)\r\n------------------------------------------------------------------\r\nWhen to use: file->file decompressing \r\nCompile files: LzmaStateDecode.h, LzmaStateDecode.c\r\nCompile defines:\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    res = LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed,\r\n      finishDecoding);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaStateTest.c for more details:\r\n\r\n\r\n6) Free all allocated blocks\r\n\r\n\r\nNote\r\n----\r\nLzmaDecodeSize.c is size-optimized version of LzmaDecode.c.\r\nBut compiled code of LzmaDecodeSize.c can be larger than \r\ncompiled code of LzmaDecode.c. So it's better to use \r\nLzmaDecode.c in most cases.\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\nLZMA decoder can return one of the following codes:\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\nIf you use callback function for input data and you return some \r\nerror code, LZMA Decoder also returns that code.\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB    - Use callback for input data\r\n\r\n_LZMA_OUT_READ - Use read function for output data\r\n\r\n_LZMA_LOC_OPT  - Enable local speed optimizations inside code.\r\n                 _LZMA_LOC_OPT is only for LzmaDecodeSize.c (size-optimized version).\r\n                 _LZMA_LOC_OPT doesn't affect LzmaDecode.c (speed-optimized version)\r\n                 and LzmaStateDecode.c\r\n\r\n_LZMA_PROB32   - It can increase speed on some 32-bit CPUs, \r\n                 but memory usage will be doubled in that case\r\n\r\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler\r\n                         and long is 32-bit.\r\n\r\n_LZMA_SYSTEM_SIZE_T  - Define it if you want to use system's size_t.\r\n                       You can use it to enable 64-bit sizes supporting\r\n\r\n\r\n\r\nC++ LZMA Encoder/Decoder \r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nC++ LZMA code use COM-like interfaces. So if you want to use it, \r\nyou can study basics of COM/OLE.\r\n\r\nBy default, LZMA Encoder contains all Match Finders.\r\nBut for compressing it's enough to have just one of them.\r\nSo for reducing size of compressing code you can define:\r\n  #define COMPRESS_MF_BT\r\n  #define COMPRESS_MF_BT4\r\nand it will use only bt4 match finder.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/motorola-bin.c",
    "content": "/*\n * motorola-bin.c\n *\n * Copyright (C) 2005-2006 Mike Baker,\n *                         Imre Kaloz <kaloz@openwrt.org>\n *                         OpenWrt.org\n *\n * $Id: motorola-bin.c 3155 2006-02-05 23:59:37Z kaloz $\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2\n * of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n *\n */\n\n/*\n * February 1, 2006\n *\n * Add support for for creating WA840G and WE800G images\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include <sys/mman.h>\n#include <string.h>\n#include <netinet/in.h>\n\nunsigned long *crc32;\n\nvoid init_crc32()\n{\n    unsigned long crc;\n    unsigned long poly = ntohl(0x2083b8ed);\n    int n, bit;\n    if ((crc32 = (unsigned long *) malloc(256 * sizeof(unsigned long))) == (void *)-1) {\n       perror(\"malloc\");\n       exit(1);\n    }\n    for (n = 0; n < 256; n++) {\n        crc = (unsigned long) n;\n        for (bit = 0; bit < 8; bit++)\n            crc = (crc & 1) ? (poly ^ (crc >> 1)) : (crc >> 1);\n        crc32[n] = crc;\n    }\n}\n\nunsigned int crc32buf(char *buf, size_t len)\n{\n    unsigned int crc = 0xFFFFFFFF;\n    for (; len; len--, buf++)\n        crc = crc32[(crc ^ *buf) & 0xff] ^ (crc >> 8);\n    return crc;\n}\n\nstruct motorola {\n\tunsigned int crc;\t// crc32 of the remainder\n\tunsigned int flags;\t// unknown, 105770*\n\tchar *trx;\t\t// standard trx\n};\n\nvoid usage(void) __attribute__ (( __noreturn__ ));\n\nvoid usage(void)\n{\n\tprintf(\"Usage: motorola-bin [-device] [trxfile] [binfile]\\n\\n\");\n\tprintf(\"Known devices: 1 - WR850G | 2 - WA840G | 3 - WE800G\\n\");\n\texit(1);\n}\n\nint main(int argc, char **argv)\n{\n\tunsigned int len;\n\tint fd;\n\tint c;\n\tvoid *trx;\n\tstruct motorola *firmware;\n\n\t// verify parameters\n\n\tif (argc!=4)\n\t{\n\tusage();\n\t}\n\n\t// mmap trx file\n\tif (((fd = open(argv[2], O_RDONLY))  < 0)\n\t|| ((len = lseek(fd, 0, SEEK_END)) < 0)\n\t|| ((trx = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0)) == (void *) (-1))\n\t|| (close(fd) < 0)) {\n\t\tperror(\"open/malloc\");\n\t\texit(1);\n\t}\n\t\n\t// create a firmware image in memory\n\t// and copy the trx to it\n\tfirmware = malloc(len+8);\n\tmemcpy(&firmware->trx,trx,len);\n\tmunmap(trx,len);\n\n\t// setup the motorola headers\n\tinit_crc32();\n\n\t// setup the firmware magic\n\n\twhile ((c = getopt(argc, argv, \"123\")) !=-1) {\n\t\tswitch (c) {\n\t\t\tcase '1':\n\t\t\t\tfirmware->flags = ntohl(0x10577050); // Motorola WR850G\n\t\t\t\tbreak;\n\t\t\tcase '2':\n\t\t\t\tfirmware->flags = ntohl(0x10577040); // Motorola WA840G\n\t\t\t\tbreak;\n\t\t\tcase '3':\n\t\t\t\tfirmware->flags = ntohl(0x10577000); // Motorola WE800G\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tusage();\n\t\t}\n\t}\n\n\tfirmware->crc   = htonl(crc32buf((char *)&firmware->flags,len+4));\n\n\t// write the firmware\n\tif (((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0)\n\t|| (write(fd,firmware,len+8) != len+8)\n\t|| (close(fd) < 0)) {\n\t\tperror(\"write\");\n\t\texit(-1);\n\t}\n\n\tfree(firmware);\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/Makefile",
    "content": "all:\n\tmake -C ./squashfs-3.0-e2100\n\tmake -C ./squashfs-3.2-r2\n\tmake -C ./squashfs-3.2-r2-lzma\n\tmake -C ./squashfs-3.2-r2-hg612-lzma\n\tmake -C ./squashfs-3.2-r2-wnr1000\n\tmake -C ./squashfs-3.2-r2-rtn12\n\tmake -C ./squashfs-3.3\n\tmake -C ./squashfs-3.3-lzma\n\tmake -C ./squashfs-3.3-grml-lzma\n\tmake -C ./squashfs-3.4-cisco\n\tmake -C ./squashfs-3.4-nb4\n\tmake -C ./squashfs-4.0-lzma\n\tmake -C ./squashfs-4.0-realtek\n\tmake -C ./squashfs-2.0-nb4\n\tmake -C ./squashfs-4.2\n\tmake -C ./squashfs-4.2-official\n\nclean:\n\tmake -C ./squashfs-3.0-e2100 clean\n\tmake -C ./squashfs-3.2-r2 clean\n\tmake -C ./squashfs-3.2-r2-lzma clean\n\tmake -C ./squashfs-3.2-r2-hg612-lzma clean\n\tmake -C ./squashfs-3.2-r2-wnr1000 clean\n\tmake -C ./squashfs-3.2-r2-rtn12 clean\n\tmake -C ./squashfs-3.3 clean\n\tmake -C ./squashfs-3.3-lzma clean\n\tmake -C ./squashfs-3.3-grml-lzma clean\n\tmake -C ./squashfs-3.4-cisco clean\n\tmake -C ./squashfs-3.4-nb4 clean\n\tmake -C ./squashfs-4.0-lzma clean\n\tmake -C ./squashfs-4.0-realtek clean\n\tmake -C ./squashfs-2.0-nb4 clean\n\tmake -C ./squashfs-4.2 clean\n\tmake -C ./squashfs-4.2-official clean\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/Makefile",
    "content": "all:\n\tmake -C nb4-mksquashfs\n\tmake -C nb4-unsquashfs\n\tcp nb4-mksquashfs/mksquashfs .\n\tcp nb4-unsquashfs/unsquashfs .\n\nclean:\n\tmake -C nb4-mksquashfs clean\n\tmake -C nb4-unsquashfs clean\n\trm -rf mksquashfs unsquashfs\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/Makefile",
    "content": "LZMADIR = ./lzma/compress\nINCLUDEDIR = -I. -I$(LZMADIR)\nLZMAOBJS = \\\n\t7zapi.o \\\n        7zlzma.o \\\n        AriBitCoder.o \\\n        IInOutStreams.o \\\n        LenCoder.o \\\n        LiteralCoder.o \\\n        LZMA.o \\\n        LZMAEncoder.o \\\n        OutByte.o \\\n        WindowIn.o\n\nCC = gcc\nSTRIP = strip\n\n#CFLAGS\t\t= $(DEFS) $(WARNINGS) -O2 -D__MACOSX__ -DGNU $(INCLUDEDIR)\nCFLAGS\t\t= $(DEFS) $(WARNINGS) -O2 -DGNU $(INCLUDEDIR)\n\nvpath %.cpp $(LZMADIR)\n\nmksquashfs:  squashfs/*.c squashfs/*.h $(LZMAOBJS) \n\t@if [ ! -e /usr/include/zlib.h ]; then \\\n          echo *****You need to install zlib-devel package to build mksquashfs! ; \\\n          echo *****You may find it in your Linux distribution CDs. ; \\\n\t  exit ;\\\n        fi\n\tgcc $(CFLAGS) -Isquashfs -c squashfs/*.c\n\tgcc $(CFLAGS) -c getline.c\n\tgcc $(CFLAGS) -c getdelim.c\n\tg++  -o mksquashfs mksquashfs.o read_fs.o sort.o getline.o getdelim.o $(LZMAOBJS) -lz\n#\tln mksquashfs nb4-mksquashfs\n\n$(LZMAOBJS): %.o: %.cpp\n\tg++ -c $(CFLAGS) $^ -o $@\n\nclean:\n\trm -f mksquashfs nb4-mksquashfs\n\trm -fr *.o core\n\trm -fr $(LZMADIR)/*.o \n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/getdelim.c",
    "content": "/* getdelim.c --- Implementation of replacement getdelim function.\n   Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005 Free\n   Software Foundation, Inc.\n\n   This program is free software; you can redistribute it and/or\n   modify it under the terms of the GNU General Public License as\n   published by the Free Software Foundation; either version 2, or (at\n   your option) any later version.\n\n   This program is distributed in the hope that it will be useful, but\n   WITHOUT ANY WARRANTY; without even the implied warranty of\n   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n   General Public License for more details.\n\n   You should have received a copy of the GNU General Public License\n   along with this program; if not, write to the Free Software\n   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n   02110-1301, USA.  */\n\n/* Ported from glibc by Simon Josefsson. */\n\n#ifdef HAVE_CONFIG_H\n# include <config.h>\n#endif\n\n#include <stdlib.h>\n#include <errno.h>\n\n#include \"getdelim.h\"\n\n#if !HAVE_FLOCKFILE\n# undef flockfile\n# define flockfile(x) ((void) 0)\n#endif\n#if !HAVE_FUNLOCKFILE\n# undef funlockfile\n# define funlockfile(x) ((void) 0)\n#endif\n\n/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and\n   NUL-terminate it).  *LINEPTR is a pointer returned from malloc (or\n   NULL), pointing to *N characters of space.  It is realloc'ed as\n   necessary.  Returns the number of characters read (not including\n   the null terminator), or -1 on error or EOF.  */\n\nssize_t\ngetdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)\n{\n  int result = 0;\n  ssize_t cur_len = 0;\n  ssize_t len;\n\n  if (lineptr == NULL || n == NULL || fp == NULL)\n    {\n      errno = EINVAL;\n      return -1;\n    }\n\n  flockfile (fp);\n\n  if (*lineptr == NULL || *n == 0)\n    {\n      *n = 120;\n      *lineptr = (char *) malloc (*n);\n      if (*lineptr == NULL)\n\t{\n\t  result = -1;\n\t  goto unlock_return;\n\t}\n    }\n\n  for (;;)\n    {\n      char *t;\n      int i;\n\n      i = getc (fp);\n      if (i == EOF)\n      {\n\tresult = -1;\n\tbreak;\n      }\n\n      /* Make enough space for len+1 (for final NUL) bytes.  */\n      if (cur_len + 1 >= *n)\n\t{\n\t  size_t needed = 2 * (cur_len + 1) + 1;   /* Be generous. */\n\t  char *new_lineptr;\n\n\t  if (needed < cur_len)\n\t    {\n\t      result = -1;\n\t      goto unlock_return;\n\t    }\n\n\t  new_lineptr = (char *) realloc (*lineptr, needed);\n\t  if (new_lineptr == NULL)\n\t    {\n\t      result = -1;\n\t      goto unlock_return;\n\t    }\n\n\t  *lineptr = new_lineptr;\n\t  *n = needed;\n\t}\n\n      (*lineptr)[cur_len] = i;\n      cur_len++;\n\n      if (i == delimiter)\n\tbreak;\n    }\n  (*lineptr)[cur_len] = '\\0';\n  result = cur_len ? cur_len : result;\n\n unlock_return:\n  funlockfile (fp);\n  return result;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/getdelim.h",
    "content": "/* getdelim.h --- Prototype for replacement getdelim function.\n   Copyright (C) 2005 Free Software Foundation, Inc.\n\n   This program is free software; you can redistribute it and/or\n   modify it under the terms of the GNU General Public License as\n   published by the Free Software Foundation; either version 2, or (at\n   your option) any later version.\n\n   This program is distributed in the hope that it will be useful, but\n   WITHOUT ANY WARRANTY; without even the implied warranty of\n   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n   General Public License for more details.\n\n   You should have received a copy of the GNU General Public License\n   along with this program; if not, write to the Free Software\n   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n   02110-1301, USA.  */\n\n/* Written by Simon Josefsson. */\n\n/* Get size_t, FILE, ssize_t.  And getdelim, if available.  */\n# include <stddef.h>\n# include <stdio.h>\n# include <sys/types.h>\n\n#if !HAVE_DECL_GETDELIM\nssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream);\n#endif /* !HAVE_GETDELIM */\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/getline.c",
    "content": "/* getline.c --- Implementation of replacement getline function.\n   Copyright (C) 2005 Free Software Foundation, Inc.\n\n   This program is free software; you can redistribute it and/or\n   modify it under the terms of the GNU General Public License as\n   published by the Free Software Foundation; either version 2, or (at\n   your option) any later version.\n\n   This program is distributed in the hope that it will be useful, but\n   WITHOUT ANY WARRANTY; without even the implied warranty of\n   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n   General Public License for more details.\n\n   You should have received a copy of the GNU General Public License\n   along with this program; if not, write to the Free Software\n   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n   02110-1301, USA.  */\n\n/* Written by Simon Josefsson. */\n\n#ifdef HAVE_CONFIG_H\n# include <config.h>\n#endif\n\n#include \"getdelim.h\"\n#include \"getline.h\"\n\nssize_t\ngetline (char **lineptr, size_t *n, FILE *stream)\n{\n  return getdelim (lineptr, n, '\\n', stream);\n}\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/getline.h",
    "content": "/* getline.h --- Prototype for replacement getline function.\n   Copyright (C) 2005 Free Software Foundation, Inc.\n\n   This program is free software; you can redistribute it and/or\n   modify it under the terms of the GNU General Public License as\n   published by the Free Software Foundation; either version 2, or (at\n   your option) any later version.\n\n   This program is distributed in the hope that it will be useful, but\n   WITHOUT ANY WARRANTY; without even the implied warranty of\n   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n   General Public License for more details.\n\n   You should have received a copy of the GNU General Public License\n   along with this program; if not, write to the Free Software\n   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n   02110-1301, USA.  */\n\n/* Written by Simon Josefsson. */\n\n/* Get size_t, FILE, ssize_t.  And getline, if available.  */\n# include <stddef.h>\n# include <stdio.h>\n# include <sys/types.h>\n\n#if !HAVE_DECL_GETLINE\nssize_t getline (char **lineptr, size_t *n, FILE *stream);\n#endif /* !HAVE_GETLINE */\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/7z.h",
    "content": "#ifndef __7Z_H\n#define __7Z_H\n\nbool compress_deflate_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned& out_size, unsigned num_passes, unsigned num_fast_bytes) throw ();\nbool decompress_deflate_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned out_size) throw ();\nbool compress_rfc1950_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned& out_size, unsigned num_passes, unsigned num_fast_bytes) throw ();\n\nbool compress_lzma_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned& out_size, unsigned algo, unsigned dictionary_size, unsigned num_fast_bytes) throw ();\nbool decompress_lzma_7z(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned out_size) throw ();\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/7zapi.cpp",
    "content": "#include \"7z.h\"\n/********************** APIs Definitions ************************************/\n\nextern \"C\" {\n\nint compress_lzma_7zapi(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned *out_size, unsigned algo, unsigned dictionary_size, unsigned num_fast_bytes);\n\n}\n\nint compress_lzma_7zapi(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned *out_size, unsigned algo, unsigned dictionary_size, unsigned num_fast_bytes)\n{\n\tbool ret;\n\t//unsigned outsize = *out_size;\n\n\tret = compress_lzma_7z(in_data, in_size, out_data, *out_size, algo, dictionary_size, num_fast_bytes);\n\n\treturn (int)ret;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/7zapi.h",
    "content": "#ifndef __7ZAPI_H__\n#define __7ZAPI_H__\n\n#if defined(__cplusplus)\nextern \"C\" {\n#endif\n\nextern int compress_lzma_7zapi(const unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned *out_size, unsigned algo, unsigned dictionary_size, unsigned num_fast_bytes);\n\n\n#if defined(__cplusplus)\n}\n#endif\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/7zlzma.cpp",
    "content": "#include \"7z.h\"\n\n#include \"LZMAEncoder.h\"\n#include \"LZMADecoder.h\"\n\nbool compress_lzma_7z(const unsigned char* in_data, \n                      unsigned in_size, \n                      unsigned char* out_data, \n                      unsigned& out_size, \n                      unsigned algo, \n                      unsigned dictionary_size, \n                      unsigned num_fast_bytes) throw () {\n\ttry {\n\t\tNCompress::NLZMA::CEncoder cc;\n\n\t\t// reduce the dictionary size if the file is small\n\t\twhile (dictionary_size > 8 && dictionary_size / 2 >= out_size)\n\t\t\tdictionary_size /= 2;\n\n\t\tif (cc.SetDictionarySize(dictionary_size) != S_OK)\n\t\t\treturn false;\n\n\t\tif (cc.SetEncoderNumFastBytes(num_fast_bytes) != S_OK)\n\t\t\treturn false;\n\n\t\tif (cc.SetEncoderAlgorithm(algo) != S_OK)\n\t\t\treturn false;\n\n\t\tISequentialInStream in(reinterpret_cast<const char*>(in_data), in_size);\n\t\tISequentialOutStream out(reinterpret_cast<char*>(out_data), out_size);\n\n\t\tUINT64 in_size_l = in_size;\n\n\t\tif (cc.WriteCoderProperties(&out) != S_OK)\n\t\t\treturn false;\n\n\t\tif (cc.Code(&in, &out, &in_size_l) != S_OK)\n\t\t\treturn false;\n\n\t\tout_size = out.size_get();\n\n\t\tif (out.overflow_get())\n\t\t\treturn false;\n\n\t\treturn true;\n\t} catch (...) {\n\t\treturn false;\n\t}\n}\n#if 0\nbool decompress_lzma_7z(const unsigned char* in_data, \n                        unsigned in_size, \n                        unsigned char* out_data, \n                        unsigned out_size) throw () {\n\ttry {\n\t\tNCompress::NLZMA::CDecoder cc;\n\n\t\tISequentialInStream in(reinterpret_cast<const char*>(in_data), in_size);\n\t\tISequentialOutStream out(reinterpret_cast<char*>(out_data), out_size);\n\n\t\tUINT64 in_size_l = in_size;\n\t\tUINT64 out_size_l = out_size;\n\n\t\tif (cc.ReadCoderProperties(&in) != S_OK)\n\t\t\treturn false;\n\n\t\tif (cc.Code(&in, &out, &in_size_l, &out_size_l) != S_OK)\n\t\t\treturn false;\n\n\t\tif (out.size_get() != out_size || out.overflow_get())\n\t\t\treturn false;\n\n\t\treturn true;\n\t} catch (...) {\n\t\treturn false;\n\t}\n}\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/AriBitCoder.cpp",
    "content": "#include \"AriBitCoder.h\"\n#include \"AriPrice.h\"\n\n#include <cmath>\n\nnamespace NCompression {\nnamespace NArithmetic {\n\nstatic const double kDummyMultMid = (1.0 / kBitPrice) / 2;\n\nCPriceTables::CPriceTables()\n{\n  double aLn2 = log(2);\n  double aLnAll = log(kBitModelTotal >> kNumMoveReducingBits);\n  for(UINT32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\n    m_StatePrices[i] = UINT32((fabs(aLnAll - log(i)) / aLn2 + kDummyMultMid) * kBitPrice);\n}\n\nCPriceTables g_PriceTables;\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/AriBitCoder.h",
    "content": "#ifndef __COMPRESSION_BITCODER_H\n#define __COMPRESSION_BITCODER_H\n\n#include \"RangeCoder.h\"\n\nnamespace NCompression {\nnamespace NArithmetic {\n\nconst int kNumBitModelTotalBits  = 11;\nconst UINT32 kBitModelTotal = (1 << kNumBitModelTotalBits);\n\nconst int kNumMoveReducingBits = 2;\n\n\nclass CPriceTables\n{\npublic:\n  UINT32 m_StatePrices[kBitModelTotal >> kNumMoveReducingBits];\n  CPriceTables();\n};\n\nextern CPriceTables g_PriceTables;\n\n\n/////////////////////////////\n// CBitModel\n\ntemplate <int aNumMoveBits>\nclass CBitModel\n{\npublic:\n  UINT32 m_Probability;\n  void UpdateModel(UINT32 aSymbol)\n  {\n    /*\n    m_Probability -= (m_Probability + ((aSymbol - 1) & ((1 << aNumMoveBits) - 1))) >> aNumMoveBits;\n    m_Probability += (1 - aSymbol) << (kNumBitModelTotalBits - aNumMoveBits);\n    */\n    if (aSymbol == 0)\n      m_Probability += (kBitModelTotal - m_Probability) >> aNumMoveBits;\n    else\n      m_Probability -= (m_Probability) >> aNumMoveBits;\n  }\npublic:\n  void Init() { m_Probability = kBitModelTotal / 2; }\n};\n\ntemplate <int aNumMoveBits>\nclass CBitEncoder: public CBitModel<aNumMoveBits>\n{\npublic:\n  void Encode(CRangeEncoder *aRangeEncoder, UINT32 aSymbol)\n  {\n    aRangeEncoder->EncodeBit(this->m_Probability, kNumBitModelTotalBits, aSymbol);\n    this->UpdateModel(aSymbol);\n  }\n  UINT32 GetPrice(UINT32 aSymbol) const\n  {\n    return g_PriceTables.m_StatePrices[\n      (((this->m_Probability - aSymbol) ^ ((-(int)aSymbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\n  }\n};\n\n\ntemplate <int aNumMoveBits>\nclass CBitDecoder: public CBitModel<aNumMoveBits>\n{\npublic:\n  UINT32 Decode(CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aNewBound = (aRangeDecoder->m_Range >> kNumBitModelTotalBits) * this->m_Probability;\n    if (aRangeDecoder->m_Code < aNewBound)\n    {\n      aRangeDecoder->m_Range = aNewBound;\n      this->m_Probability += (kBitModelTotal - this->m_Probability) >> aNumMoveBits;\n      if (aRangeDecoder->m_Range < kTopValue)\n      {\n        aRangeDecoder->m_Code = (aRangeDecoder->m_Code << 8) | aRangeDecoder->m_Stream.ReadByte();\n        aRangeDecoder->m_Range <<= 8;\n      }\n      return 0;\n    }\n    else\n    {\n      aRangeDecoder->m_Range -= aNewBound;\n      aRangeDecoder->m_Code -= aNewBound;\n      this->m_Probability -= (this->m_Probability) >> aNumMoveBits;\n      if (aRangeDecoder->m_Range < kTopValue)\n      {\n        aRangeDecoder->m_Code = (aRangeDecoder->m_Code << 8) | aRangeDecoder->m_Stream.ReadByte();\n        aRangeDecoder->m_Range <<= 8;\n      }\n      return 1;\n    }\n  }\n};\n\n}}\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/AriConst.h",
    "content": "#ifndef __ARICONST_H\n#define __ARICONST_H\n\n#include \"AriBitCoder.h\"\n\ntypedef NCompression::NArithmetic::CRangeEncoder CMyRangeEncoder;\ntypedef NCompression::NArithmetic::CRangeDecoder CMyRangeDecoder;\n\ntemplate <int aNumMoveBits> class CMyBitEncoder: \n    public NCompression::NArithmetic::CBitEncoder<aNumMoveBits> {};\ntemplate <int aNumMoveBits> class CMyBitDecoder: \n    public NCompression::NArithmetic::CBitDecoder<aNumMoveBits> {};\n\n#endif\n\n\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/AriPrice.h",
    "content": "#ifndef __COMPRESSION_ARIPRICE_H\n#define __COMPRESSION_ARIPRICE_H\n\nnamespace NCompression {\nnamespace NArithmetic {\n\nconst UINT32 kNumBitPriceShiftBits = 6;\nconst UINT32 kBitPrice = 1 << kNumBitPriceShiftBits;\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree.h",
    "content": "#include \"Portable.h\"\n#include \"WindowIn.h\"\n\nnamespace BT_NAMESPACE {\n\ntypedef UINT32 CIndex;\nconst UINT32 kMaxValForNormalize = (UINT32(1) << 31) - 1;\n\nstruct CPair\n{\n  CIndex Left;\n  CIndex Right;\n};\n\nclass CInTree: public NStream::NWindow::CIn\n{\n  UINT32 m_HistorySize;\n  UINT32 m_MatchMaxLen;\n\n  CIndex *m_Hash;\n  \n  #ifdef HASH_ARRAY_2\n  CIndex *m_Hash2;\n  #ifdef HASH_ARRAY_3\n  CIndex *m_Hash3;\n  #endif\n  #endif\n  \n  CPair *m_Son;\n  CPair *m_Base;\n\n  UINT32 m_CutValue;\n\n  void NormalizeLinks(CIndex *anArray, UINT32 aNumItems, UINT32 aSubValue);\n  void Normalize();\n  void FreeMemory();\n\nprotected:\n  virtual void AfterMoveBlock();\npublic:\n  CInTree();\n  ~CInTree();\n  HRESULT Create(UINT32 aSizeHistory, UINT32 aKeepAddBufferBefore, UINT32 aMatchMaxLen, \n      UINT32 aKeepAddBufferAfter, UINT32 _dwSizeReserv = (1<<17));\n\tHRESULT Init(ISequentialInStream *aStream);\n  void SetCutValue(UINT32 aCutValue) { m_CutValue = aCutValue; }\n  UINT32 GetLongestMatch(UINT32 *aDistances);\n  void DummyLongestMatch();\n  HRESULT MovePos()\n  {\n    RETURN_IF_NOT_S_OK(CIn::MovePos());\n    if (m_Pos == kMaxValForNormalize)\n      Normalize();\n    return S_OK;\n  }\n  void ReduceOffsets(UINT32 aSubValue)\n  {\n    CIn::ReduceOffsets(aSubValue);\n    m_Son += aSubValue;\n  }\n};\n\n}\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree2.h",
    "content": "#ifndef __BINTREE2__H\n#define __BINTREE2__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT2\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT2\n\n#include \"BinTreeMF.h\"\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree2Main.h",
    "content": "#ifndef __BINTREE2MAIN__H\n#define __BINTREE2MAIN__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT2\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT2\n\n#include \"BinTreeMFMain.h\"\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree3.h",
    "content": "#ifndef __BINTREE3__H\n#define __BINTREE3__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT3\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT3\n\n#define HASH_ARRAY_2\n\n#include \"BinTreeMF.h\"\n\n#undef HASH_ARRAY_2\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree3Main.h",
    "content": "#ifndef __BINTREE3MAIN__H\n#define __BINTREE3MAIN__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT3\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT3\n\n#define HASH_ARRAY_2\n\n#include \"BinTreeMFMain.h\"\n\n#undef HASH_ARRAY_2\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree3Z.h",
    "content": "#ifndef __BINTREE3Z__H\n#define __BINTREE3Z__H\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT3Z\n\n#define HASH_ZIP\n\n#include \"BinTree.h\"\n\n#undef HASH_ZIP\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree3ZMain.h",
    "content": "#ifndef __BINTREE3ZMAIN__H\n#define __BINTREE3ZMAIN__H\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT3Z\n\n#define HASH_ZIP\n\n#include \"BinTreeMain.h\"\n\n#undef HASH_ZIP\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree4.h",
    "content": "#ifndef __BINTREE4__H\n#define __BINTREE4__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT4\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT4\n\n#define HASH_ARRAY_2\n#define HASH_ARRAY_3\n\n#include \"BinTreeMF.h\"\n\n#undef HASH_ARRAY_2\n#undef HASH_ARRAY_3\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree4Main.h",
    "content": "#ifndef __BINTREEMAIN4__H\n#define __BINTREEMAIN4__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT4\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT4\n\n#define HASH_ARRAY_2\n#define HASH_ARRAY_3\n\n#include \"BinTreeMFMain.h\"\n\n#undef HASH_ARRAY_2\n#undef HASH_ARRAY_3\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree4b.h",
    "content": "#ifndef __BINTREE4B__H\n#define __BINTREE4B__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT4b\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT4b\n\n#define HASH_ARRAY_2\n#define HASH_ARRAY_3\n#define HASH_BIG\n\n#include \"BinTreeMF.h\"\n\n#undef HASH_ARRAY_2\n#undef HASH_ARRAY_3\n#undef HASH_BIG\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTree4bMain.h",
    "content": "#ifndef __BINTREE4BMAIN__H\n#define __BINTREE4BMAIN__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT4b\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT4b\n\n#define HASH_ARRAY_2\n#define HASH_ARRAY_3\n#define HASH_BIG\n\n#include \"BinTreeMFMain.h\"\n\n#undef HASH_ARRAY_2\n#undef HASH_ARRAY_3\n#undef HASH_BIG\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTreeMF.h",
    "content": "// #ifndef __BINTREEMF_H\n// #define __BINTREEMF_H\n\n#include \"BinTree.h\"\n\nnamespace BT_NAMESPACE {\n\nclass CMatchFinderBinTree : public CInTree\n{\npublic:\n  HRESULT Create(UINT32 aSizeHistory,\n      UINT32 aKeepAddBufferBefore, UINT32 aMatchMaxLen, \n      UINT32 aKeepAddBufferAfter);\n};\n \n}\n\n// #endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTreeMFMain.h",
    "content": "#include \"BinTreeMain.h\"\n\nnamespace BT_NAMESPACE {\n\nHRESULT CMatchFinderBinTree::Create(UINT32 aSizeHistory,\n      UINT32 aKeepAddBufferBefore, UINT32 aMatchMaxLen, \n      UINT32 aKeepAddBufferAfter)\n{ \n  const UINT32 kAlignMask = (1 << 16) - 1;\n  UINT32 aWindowReservSize = aSizeHistory / 2;\n  aWindowReservSize += kAlignMask;\n  aWindowReservSize &= ~(kAlignMask);\n\n  const int kMinDictSize = (1 << 19);\n  if (aWindowReservSize < kMinDictSize)\n    aWindowReservSize = kMinDictSize;\n  aWindowReservSize += 256;\n\n  try \n  {\n    return CInTree::Create(aSizeHistory, aKeepAddBufferBefore, aMatchMaxLen,\n      aKeepAddBufferAfter, aWindowReservSize); \n  }\n  catch(...)\n  {\n    return E_OUTOFMEMORY;\n  }\n}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BinTreeMain.h",
    "content": "#include \"CRC.h\"\n\nnamespace BT_NAMESPACE {\n\n#ifdef HASH_ARRAY_2\n  static const UINT32 kHash2Size = 1 << 10;\n  #ifdef HASH_ARRAY_3\n    static const UINT32 kNumHashDirectBytes = 0;\n    static const UINT32 kNumHashBytes = 4;\n    static const UINT32 kHash3Size = 1 << 18;\n    #ifdef HASH_BIG\n    static const UINT32 kHashSize = 1 << 23;\n    #else\n    static const UINT32 kHashSize = 1 << 20;\n    #endif\n  #else\n    static const UINT32 kNumHashDirectBytes = 3;\n    static const UINT32 kNumHashBytes = 3;\n    static const UINT32 kHashSize = 1 << (8 * kNumHashBytes);\n  #endif\n#else\n  #ifdef HASH_ZIP \n    static const UINT32 kNumHashDirectBytes = 0;\n    static const UINT32 kNumHashBytes = 3;\n    static const UINT32 kHashSize = 1 << 16;\n  #else\n    static const UINT32 kNumHashDirectBytes = 2;\n    static const UINT32 kNumHashBytes = 2;\n    static const UINT32 kHashSize = 1 << (8 * kNumHashBytes);\n  #endif\n#endif\n\nCInTree::CInTree():\n  #ifdef HASH_ARRAY_2\n  m_Hash2(0),\n  #ifdef HASH_ARRAY_3\n  m_Hash3(0),\n  #endif\n  #endif\n  m_Hash(0),\n  m_Base(0),\n  m_CutValue(0xFF)\n{\n}\n\nvoid CInTree::FreeMemory()\n{\n  if (m_Base != 0)\n\tdelete [] m_Base;\n  if (m_Hash != 0)\n\tdelete [] m_Hash;\n  m_Base = 0;\n  m_Hash = 0;\n  CIn::Free();\n}\n\nCInTree::~CInTree()\n{ \n  FreeMemory();\n}\n\nHRESULT CInTree::Create(UINT32 aSizeHistory, UINT32 aKeepAddBufferBefore, \n    UINT32 aMatchMaxLen, UINT32 aKeepAddBufferAfter, UINT32 aSizeReserv)\n{\n  FreeMemory();\n    CIn::Create(aSizeHistory + aKeepAddBufferBefore, \n      aMatchMaxLen + aKeepAddBufferAfter, aSizeReserv);\n    \n    if (m_BlockSize + 256 > kMaxValForNormalize)\n      return E_INVALIDARG;\n    \n    m_HistorySize = aSizeHistory;\n    m_MatchMaxLen = aMatchMaxLen;\n    \n    \n    UINT32 aSize = kHashSize;\n    #ifdef HASH_ARRAY_2\n    aSize += kHash2Size;\n    #ifdef HASH_ARRAY_3\n    aSize += kHash3Size;\n    #endif\n    #endif\n    \n    m_Base = new CPair[m_BlockSize + 1];\n    if (m_Base == 0)\n\treturn E_OUTOFMEMORY;\n    m_Hash = new CIndex[aSize + 1];\n    if (m_Hash == 0)\n\treturn E_OUTOFMEMORY;\n    \n    #ifdef HASH_ARRAY_2\n    m_Hash2 = &m_Hash[kHashSize]; \n    #ifdef HASH_ARRAY_3\n    m_Hash3 = &m_Hash2[kHash2Size]; \n    #endif\n    #endif\n    return S_OK;\n}\n\nstatic const UINT32 kEmptyHashValue = 0;\n\nHRESULT CInTree::Init(ISequentialInStream *aStream)\n{\n  RETURN_IF_NOT_S_OK(CIn::Init(aStream));\n  unsigned i;\n  for(i = 0; i < kHashSize; i++)\n    m_Hash[i] = kEmptyHashValue;\n\n  #ifdef HASH_ARRAY_2\n  for(i = 0; i < kHash2Size; i++)\n    m_Hash2[i] = kEmptyHashValue;\n  #ifdef HASH_ARRAY_3\n  for(i = 0; i < kHash3Size; i++)\n    m_Hash3[i] = kEmptyHashValue;\n  #endif\n  #endif\n\n  m_Son = m_Base;\n\n  ReduceOffsets(0 - 1);\n  return S_OK;\n}\n\n\n#ifdef HASH_ARRAY_2\n#ifdef HASH_ARRAY_3\ninline UINT32 Hash(const BYTE *aPointer, UINT32 &aHash2Value, UINT32 &aHash3Value)\n{\n  UINT32 aTemp = CCRC::m_Table[aPointer[0]] ^ aPointer[1];\n  aHash2Value = aTemp & (kHash2Size - 1);\n  aHash3Value = (aTemp ^ (UINT32(aPointer[2]) << 8)) & (kHash3Size - 1);\n  return (aTemp ^ (UINT32(aPointer[2]) << 8) ^ (CCRC::m_Table[aPointer[3]] << 5)) & \n      (kHashSize - 1);\n}\n#else // no HASH_ARRAY_3\ninline UINT32 Hash(const BYTE *aPointer, UINT32 &aHash2Value)\n{\n  aHash2Value = (CCRC::m_Table[aPointer[0]] ^ aPointer[1]) & (kHash2Size - 1);\n  return (*((const UINT32 *)aPointer)) & 0xFFFFFF;\n}\n#endif // HASH_ARRAY_3\n#else // no HASH_ARRAY_2\n#ifdef HASH_ZIP \ninline UINT32 Hash(const BYTE *aPointer)\n{\n  return ((UINT32(aPointer[0]) << 8) ^ \n      CCRC::m_Table[aPointer[1]] ^ aPointer[2]) & (kHashSize - 1);\n}\n#else // no HASH_ZIP \ninline UINT32 Hash(const BYTE *aPointer)\n{\n  return aPointer[0] ^ (UINT32(aPointer[1]) << 8);\n}\n#endif // HASH_ZIP\n#endif // HASH_ARRAY_2\n\nUINT32 CInTree::GetLongestMatch(UINT32 *aDistances)\n{\n  UINT32 aCurrentLimit;\n  if (m_Pos + m_MatchMaxLen <= m_StreamPos)\n    aCurrentLimit = m_MatchMaxLen;\n  else\n  {\n    aCurrentLimit = m_StreamPos - m_Pos;\n    if(aCurrentLimit < kNumHashBytes)\n      return 0; \n  }\n\n  UINT32 aMatchMinPos = (m_Pos > m_HistorySize) ? (m_Pos - m_HistorySize) : 1;\n  BYTE *aCur = m_Buffer + m_Pos;\n  \n  UINT32 aMatchHashLenMax = 0;\n\n  #ifdef HASH_ARRAY_2\n  UINT32 aHash2Value;\n  #ifdef HASH_ARRAY_3\n  UINT32 aHash3Value;\n  UINT32 aHashValue = Hash(aCur, aHash2Value, aHash3Value);\n  #else\n  UINT32 aHashValue = Hash(aCur, aHash2Value);\n  #endif\n  #else\n  UINT32 aHashValue = Hash(aCur);\n  #endif\n\n  UINT32 aCurMatch = m_Hash[aHashValue];\n  #ifdef HASH_ARRAY_2\n  UINT32 aCurMatch2 = m_Hash2[aHash2Value];\n  #ifdef HASH_ARRAY_3\n  UINT32 aCurMatch3 = m_Hash3[aHash3Value];\n  #endif\n  m_Hash2[aHash2Value] = m_Pos;\n  bool aMatchLen2Exist = false;\n  UINT32 aLen2Distance = 0;\n  if(aCurMatch2 >= aMatchMinPos)\n  {\n    if (m_Buffer[aCurMatch2] == aCur[0])\n    {\n      aLen2Distance = m_Pos - aCurMatch2 - 1;\n      aMatchHashLenMax = 2;\n      aMatchLen2Exist = true;\n    }\n  }\n\n  #ifdef HASH_ARRAY_3\n  m_Hash3[aHash3Value] = m_Pos;\n  UINT32 aMatchLen3Exist = false;\n  UINT32 aLen3Distance = 0;\n  if(aCurMatch3 >= aMatchMinPos)\n  {\n    if (m_Buffer[aCurMatch3] == aCur[0])\n    {\n      aLen3Distance = m_Pos - aCurMatch3 - 1;\n      aMatchHashLenMax = 3;\n      aMatchLen3Exist = true;\n      if (aMatchLen2Exist)\n      {\n        if (aLen3Distance < aLen2Distance)\n          aLen2Distance = aLen3Distance;\n      }\n      else\n      {\n        aLen2Distance = aLen3Distance;\n        aMatchLen2Exist = true;\n      }\n    }\n  }\n  #endif\n  #endif\n\n  m_Hash[aHashValue] = m_Pos;\n  if(aCurMatch < aMatchMinPos)\n  {\n    m_Son[m_Pos].Left = kEmptyHashValue; \n    m_Son[m_Pos].Right = kEmptyHashValue; \n\n    #ifdef HASH_ARRAY_2\n    aDistances[2] = aLen2Distance;\n    #ifdef HASH_ARRAY_3\n    aDistances[3] = aLen3Distance;\n    #endif\n    #endif\n\n    return aMatchHashLenMax;\n  }\n  CIndex *aPtrLeft = &m_Son[m_Pos].Right;\n  CIndex *aPtrRight = &m_Son[m_Pos].Left;\n\n  UINT32 aMax, aMinSameLeft, aMinSameRight, aMinSame;\n  aMax = aMinSameLeft = aMinSameRight = aMinSame = kNumHashDirectBytes;\n\n  #ifdef HASH_ARRAY_2\n  #ifndef HASH_ARRAY_3\n    if (aMatchLen2Exist)\n      aDistances[2] = aLen2Distance;\n    else\n      if (kNumHashDirectBytes >= 2)\n        aDistances[2] = m_Pos - aCurMatch - 1;\n  #endif\n  #endif\n\n  aDistances[aMax] = m_Pos - aCurMatch - 1;\n  \n  for(UINT32 aCount = m_CutValue; aCount > 0; aCount--)\n  {\n    BYTE *pby1 = m_Buffer + aCurMatch;\n    // CIndex aLeft = m_Son[aCurMatch].Left; // it's prefetch\n    UINT32 aCurrentLen;\n    for(aCurrentLen = aMinSame; aCurrentLen < aCurrentLimit; aCurrentLen++/*, dwComps++*/)\n      if (pby1[aCurrentLen] != aCur[aCurrentLen])\n        break;\n    while (aCurrentLen > aMax)\n      aDistances[++aMax] = m_Pos - aCurMatch - 1;\n    if (aCurrentLen != aCurrentLimit)\n    {\n      if (pby1[aCurrentLen] < aCur[aCurrentLen])\n      {\n        *aPtrRight = aCurMatch;\n        aPtrRight = &m_Son[aCurMatch].Right;\n        aCurMatch = m_Son[aCurMatch].Right;\n        if(aCurrentLen > aMinSameLeft)\n        {\n          aMinSameLeft = aCurrentLen;\n          aMinSame = MyMin(aMinSameLeft, aMinSameRight);\n        }\n      }\n      else\n      {\n        *aPtrLeft = aCurMatch;\n        aPtrLeft = &m_Son[aCurMatch].Left;\n        // aCurMatch = aLeft;\n        aCurMatch = m_Son[aCurMatch].Left;\n        if(aCurrentLen > aMinSameRight)\n        {\n          aMinSameRight = aCurrentLen;\n          aMinSame = MyMin(aMinSameLeft, aMinSameRight);\n        }\n      }\n    }\n    else\n    {\n      if(aCurrentLen < m_MatchMaxLen)\n      {\n        *aPtrLeft = aCurMatch;\n        aPtrLeft = &m_Son[aCurMatch].Left;\n        aCurMatch = m_Son[aCurMatch].Left;\n        if(aCurrentLen > aMinSameRight)\n        {\n          aMinSameRight = aCurrentLen;\n          aMinSame = MyMin(aMinSameLeft, aMinSameRight);\n        }\n      }\n      else\n      {\n        *aPtrLeft = m_Son[aCurMatch].Right;\n        *aPtrRight = m_Son[aCurMatch].Left;\n\n        #ifdef HASH_ARRAY_2\n        if (aMatchLen2Exist && aLen2Distance < aDistances[2])\n          aDistances[2] = aLen2Distance;\n        #ifdef HASH_ARRAY_3\n        if (aMatchLen3Exist && aLen3Distance < aDistances[3])\n          aDistances[3] = aLen3Distance;\n        #endif\n        #endif\n\n        return aMax;\n      }\n    }\n    if(aCurMatch < aMatchMinPos)\n      break;\n  }\n  *aPtrLeft = kEmptyHashValue;\n  *aPtrRight = kEmptyHashValue;\n  #ifdef HASH_ARRAY_2\n  if (aMatchLen2Exist)\n  {\n    if (aMax < 2)\n    {\n      aDistances[2] = aLen2Distance;\n      aMax = 2;\n    }\n    else if (aLen2Distance < aDistances[2])\n      aDistances[2] = aLen2Distance;\n  }\n  #ifdef HASH_ARRAY_3\n  if (aMatchLen3Exist)\n  {\n    if (aMax < 3)\n    {\n      aDistances[3] = aLen3Distance;\n      aMax = 3;\n    }\n    else if (aLen3Distance < aDistances[3])\n      aDistances[3] = aLen3Distance;\n  }\n  #endif\n  #endif\n  return aMax;\n}\n\nvoid CInTree::DummyLongestMatch()\n{\n  UINT32 aCurrentLimit;\n  if (m_Pos + m_MatchMaxLen <= m_StreamPos)\n    aCurrentLimit = m_MatchMaxLen;\n  else\n  {\n    aCurrentLimit = m_StreamPos - m_Pos;\n    if(aCurrentLimit < kNumHashBytes)\n      return; \n  }\n  UINT32 aMatchMinPos = (m_Pos > m_HistorySize) ? (m_Pos - m_HistorySize) : 1;\n  BYTE *aCur = m_Buffer + m_Pos;\n  \n  #ifdef HASH_ARRAY_2\n  UINT32 aHash2Value;\n  #ifdef HASH_ARRAY_3\n  UINT32 aHash3Value;\n  UINT32 aHashValue = Hash(aCur, aHash2Value, aHash3Value);\n  m_Hash3[aHash3Value] = m_Pos;\n  #else\n  UINT32 aHashValue = Hash(aCur, aHash2Value);\n  #endif\n  m_Hash2[aHash2Value] = m_Pos;\n  #else\n  UINT32 aHashValue = Hash(aCur);\n  #endif\n\n  UINT32 aCurMatch = m_Hash[aHashValue];\n  m_Hash[aHashValue] = m_Pos;\n  if(aCurMatch < aMatchMinPos)\n  {\n    m_Son[m_Pos].Left = kEmptyHashValue; \n    m_Son[m_Pos].Right = kEmptyHashValue; \n    return;\n  }\n  CIndex *aPtrLeft = &m_Son[m_Pos].Right;\n  CIndex *aPtrRight = &m_Son[m_Pos].Left;\n\n  UINT32 aMax, aMinSameLeft, aMinSameRight, aMinSame;\n  aMax = aMinSameLeft = aMinSameRight = aMinSame = kNumHashDirectBytes;\n  for(UINT32 aCount = m_CutValue; aCount > 0; aCount--)\n  {\n    BYTE *pby1 = m_Buffer + aCurMatch;\n    // CIndex aLeft = m_Son[aCurMatch].Left; // it's prefetch\n    UINT32 aCurrentLen;\n    for(aCurrentLen = aMinSame; aCurrentLen < aCurrentLimit; aCurrentLen++/*, dwComps++*/)\n      if (pby1[aCurrentLen] != aCur[aCurrentLen])\n        break;\n    if (aCurrentLen != aCurrentLimit)\n    {\n      if (pby1[aCurrentLen] < aCur[aCurrentLen])\n      {\n        *aPtrRight = aCurMatch;\n        aPtrRight = &m_Son[aCurMatch].Right;\n        aCurMatch = m_Son[aCurMatch].Right;\n        if(aCurrentLen > aMinSameLeft)\n        {\n          aMinSameLeft = aCurrentLen;\n          aMinSame = MyMin(aMinSameLeft, aMinSameRight);\n        }\n      }\n      else \n      {\n        *aPtrLeft = aCurMatch;\n        aPtrLeft = &m_Son[aCurMatch].Left;\n        aCurMatch = m_Son[aCurMatch].Left;\n        // aCurMatch = aLeft;\n        if(aCurrentLen > aMinSameRight)\n        {\n          aMinSameRight = aCurrentLen;\n          aMinSame = MyMin(aMinSameLeft, aMinSameRight);\n        }\n      }\n    }\n    else\n    {\n      if(aCurrentLen < m_MatchMaxLen)\n      {\n        *aPtrLeft = aCurMatch;\n        aPtrLeft = &m_Son[aCurMatch].Left;\n        aCurMatch = m_Son[aCurMatch].Left;\n        if(aCurrentLen > aMinSameRight)\n        {\n          aMinSameRight = aCurrentLen;\n          aMinSame = MyMin(aMinSameLeft, aMinSameRight);\n        }\n      }\n      else\n      {\n        *aPtrLeft = m_Son[aCurMatch].Right;\n        *aPtrRight = m_Son[aCurMatch].Left;\n        return;\n      }\n    }\n    if(aCurMatch < aMatchMinPos)\n      break;\n  }\n  *aPtrLeft = kEmptyHashValue;\n  *aPtrRight = kEmptyHashValue;\n}\n\nvoid CInTree::AfterMoveBlock()\n{\n  UINT32 aNumBytesToMove = m_HistorySize * sizeof(CPair);\n  UINT32 aSpecOffset = ((m_Son + m_Pos) - m_Base) - m_HistorySize;\n  memmove(m_Base, m_Base + aSpecOffset, aNumBytesToMove);\n  m_Son -= aSpecOffset;\n}\n\nvoid CInTree::NormalizeLinks(CIndex *anArray, UINT32 aNumItems, UINT32 aSubValue)\n{\n  for (UINT32 i = 0; i < aNumItems; i++)\n  {\n    UINT32 aValue = anArray[i];\n    if (aValue <= aSubValue)\n      aValue = kEmptyHashValue;\n    else\n      aValue -= aSubValue;\n    anArray[i] = aValue;\n  }\n}\n\nvoid CInTree::Normalize()\n{\n  UINT32 aStartItem = m_Pos - m_HistorySize;\n  UINT32 aSubValue = aStartItem - 1;\n  NormalizeLinks((CIndex *)(m_Son + aStartItem), m_HistorySize * 2, aSubValue);\n  NormalizeLinks(m_Hash, kHashSize, aSubValue);\n\n  #ifdef HASH_ARRAY_2\n  NormalizeLinks(m_Hash2, kHash2Size, aSubValue);\n  #ifdef HASH_ARRAY_3\n  NormalizeLinks(m_Hash3, kHash3Size, aSubValue);\n  #endif\n  #endif\n\n  ReduceOffsets(aSubValue);\n}\n \n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/BitTreeCoder.h",
    "content": "#ifndef __BITTREECODER_H\n#define __BITTREECODER_H\n\n#include \"AriBitCoder.h\"\n#include \"RCDefs.h\"\n\n//////////////////////////\n// CBitTreeEncoder\n\ntemplate <int aNumMoveBits, UINT32 m_NumBitLevels>\nclass CBitTreeEncoder\n{\n  CMyBitEncoder<aNumMoveBits> m_Models[1 << m_NumBitLevels];\npublic:\n  void Init()\n  {\n    for(UINT32 i = 1; i < (1 << m_NumBitLevels); i++)\n      m_Models[i].Init();\n  }\n  void Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol)\n  {\n    UINT32 aModelIndex = 1;\n    for (UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0 ;)\n    {\n      aBitIndex--;\n      UINT32 aBit = (aSymbol >> aBitIndex ) & 1;\n      m_Models[aModelIndex].Encode(aRangeEncoder, aBit);\n      aModelIndex = (aModelIndex << 1) | aBit;\n    }\n  };\n  UINT32 GetPrice(UINT32 aSymbol) const\n  {\n    UINT32 aPrice = 0;\n    UINT32 aModelIndex = 1;\n    for (UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0 ;)\n    {\n      aBitIndex--;\n      UINT32 aBit = (aSymbol >> aBitIndex ) & 1;\n      aPrice += m_Models[aModelIndex].GetPrice(aBit);\n      aModelIndex = (aModelIndex << 1) + aBit;\n    }\n    return aPrice;\n  }\n};\n\n//////////////////////////\n// CBitTreeDecoder\n\ntemplate <int aNumMoveBits, UINT32 m_NumBitLevels>\nclass CBitTreeDecoder\n{\n  CMyBitDecoder<aNumMoveBits> m_Models[1 << m_NumBitLevels];\npublic:\n  void Init()\n  {\n    for(UINT32 i = 1; i < (1 << m_NumBitLevels); i++)\n      m_Models[i].Init();\n  }\n  UINT32 Decode(CMyRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    RC_INIT_VAR\n    for(UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0; aBitIndex--)\n    {\n      // aModelIndex = (aModelIndex << 1) + m_Models[aModelIndex].Decode(aRangeDecoder);\n      RC_GETBIT(aNumMoveBits, m_Models[aModelIndex].m_Probability, aModelIndex)\n    }\n    RC_FLUSH_VAR\n    return aModelIndex - (1 << m_NumBitLevels);\n  };\n};\n\n\n\n////////////////////////////////\n// CReverseBitTreeEncoder\n\ntemplate <int aNumMoveBits>\nclass CReverseBitTreeEncoder2\n{\n  CMyBitEncoder<aNumMoveBits> *m_Models;\n  UINT32 m_NumBitLevels;\npublic:\n  CReverseBitTreeEncoder2(): m_Models(0) { }\n  ~CReverseBitTreeEncoder2() { delete []m_Models; }\n  bool Create(UINT32 aNumBitLevels)\n  {\n    m_NumBitLevels = aNumBitLevels;\n    m_Models = new CMyBitEncoder<aNumMoveBits>[1 << aNumBitLevels];\n    return (m_Models != 0);\n  }\n  void Init()\n  {\n    UINT32 aNumModels = 1 << m_NumBitLevels;\n    for(UINT32 i = 1; i < aNumModels; i++)\n      m_Models[i].Init();\n  }\n  void Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol)\n  {\n    UINT32 aModelIndex = 1;\n    for (UINT32 i = 0; i < m_NumBitLevels; i++)\n    {\n      UINT32 aBit = aSymbol & 1;\n      m_Models[aModelIndex].Encode(aRangeEncoder, aBit);\n      aModelIndex = (aModelIndex << 1) | aBit;\n      aSymbol >>= 1;\n    }\n  }\n  UINT32 GetPrice(UINT32 aSymbol) const\n  {\n    UINT32 aPrice = 0;\n    UINT32 aModelIndex = 1;\n    for (UINT32 i = m_NumBitLevels; i > 0; i--)\n    {\n      UINT32 aBit = aSymbol & 1;\n      aSymbol >>= 1;\n      aPrice += m_Models[aModelIndex].GetPrice(aBit);\n      aModelIndex = (aModelIndex << 1) | aBit;\n    }\n    return aPrice;\n  }\n};\n\n/*\ntemplate <int aNumMoveBits, int aNumBitLevels>\nclass CReverseBitTreeEncoder: public CReverseBitTreeEncoder2<aNumMoveBits>\n{\npublic:\n  CReverseBitTreeEncoder() \n    { Create(aNumBitLevels); }\n};\n*/\n////////////////////////////////\n// CReverseBitTreeDecoder\n\ntemplate <int aNumMoveBits>\nclass CReverseBitTreeDecoder2\n{\n  CMyBitDecoder<aNumMoveBits> *m_Models;\n  UINT32 m_NumBitLevels;\npublic:\n  CReverseBitTreeDecoder2(): m_Models(0) { }\n  ~CReverseBitTreeDecoder2() { delete []m_Models; }\n  bool Create(UINT32 aNumBitLevels)\n  {\n    m_NumBitLevels = aNumBitLevels;\n    m_Models = new CMyBitDecoder<aNumMoveBits>[1 << aNumBitLevels];\n    return (m_Models != 0);\n  }\n  void Init()\n  {\n    UINT32 aNumModels = 1 << m_NumBitLevels;\n    for(UINT32 i = 1; i < aNumModels; i++)\n      m_Models[i].Init();\n  }\n  UINT32 Decode(CMyRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    UINT32 aSymbol = 0;\n    RC_INIT_VAR\n    for(UINT32 aBitIndex = 0; aBitIndex < m_NumBitLevels; aBitIndex++)\n    {\n      // UINT32 aBit = m_Models[aModelIndex].Decode(aRangeDecoder);\n      // aModelIndex <<= 1;\n      // aModelIndex += aBit;\n      // aSymbol |= (aBit << aBitIndex);\n      RC_GETBIT2(aNumMoveBits, m_Models[aModelIndex].m_Probability, aModelIndex, ; , aSymbol |= (1 << aBitIndex))\n    }\n    RC_FLUSH_VAR\n    return aSymbol;\n  };\n};\n////////////////////////////\n// CReverseBitTreeDecoder2\n\ntemplate <int aNumMoveBits, UINT32 m_NumBitLevels>\nclass CReverseBitTreeDecoder\n{\n  CMyBitDecoder<aNumMoveBits> m_Models[1 << m_NumBitLevels];\npublic:\n  void Init()\n  {\n    for(UINT32 i = 1; i < (1 << m_NumBitLevels); i++)\n      m_Models[i].Init();\n  }\n  UINT32 Decode(CMyRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    UINT32 aSymbol = 0;\n    RC_INIT_VAR\n    for(UINT32 aBitIndex = 0; aBitIndex < m_NumBitLevels; aBitIndex++)\n    {\n      // UINT32 aBit = m_Models[aModelIndex].Decode(aRangeDecoder);\n      // aModelIndex <<= 1;\n      // aModelIndex += aBit;\n      // aSymbol |= (aBit << aBitIndex);\n      RC_GETBIT2(aNumMoveBits, m_Models[aModelIndex].m_Probability, aModelIndex, ; , aSymbol |= (1 << aBitIndex))\n    }\n    RC_FLUSH_VAR\n    return aSymbol;\n  }\n};\n\n/*\n//////////////////////////\n// CBitTreeEncoder2\n\ntemplate <int aNumMoveBits>\nclass CBitTreeEncoder2\n{\n  NCompression::NArithmetic::CBitEncoder<aNumMoveBits> *m_Models;\n  UINT32 m_NumBitLevels;\npublic:\n  bool Create(UINT32 aNumBitLevels)\n  { \n    m_NumBitLevels = aNumBitLevels;\n    m_Models = new NCompression::NArithmetic::CBitEncoder<aNumMoveBits>[1 << aNumBitLevels];\n    return (m_Models != 0);\n  }\n  void Init()\n  {\n    UINT32 aNumModels = 1 << m_NumBitLevels;\n    for(UINT32 i = 1; i < aNumModels; i++)\n      m_Models[i].Init();\n  }\n  void Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol)\n  {\n    UINT32 aModelIndex = 1;\n    for (UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0 ;)\n    {\n      aBitIndex--;\n      UINT32 aBit = (aSymbol >> aBitIndex ) & 1;\n      m_Models[aModelIndex].Encode(aRangeEncoder, aBit);\n      aModelIndex = (aModelIndex << 1) | aBit;\n    }\n  }\n  UINT32 GetPrice(UINT32 aSymbol) const\n  {\n    UINT32 aPrice = 0;\n    UINT32 aModelIndex = 1;\n    for (UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0 ;)\n    {\n      aBitIndex--;\n      UINT32 aBit = (aSymbol >> aBitIndex ) & 1;\n      aPrice += m_Models[aModelIndex].GetPrice(aBit);\n      aModelIndex = (aModelIndex << 1) + aBit;\n    }\n    return aPrice;\n  }\n};\n\n\n//////////////////////////\n// CBitTreeDecoder2\n\ntemplate <int aNumMoveBits>\nclass CBitTreeDecoder2\n{\n  NCompression::NArithmetic::CBitDecoder<aNumMoveBits> *m_Models;\n  UINT32 m_NumBitLevels;\npublic:\n  bool Create(UINT32 aNumBitLevels)\n  { \n    m_NumBitLevels = aNumBitLevels;\n    m_Models = new NCompression::NArithmetic::CBitDecoder<aNumMoveBits>[1 << aNumBitLevels];\n    return (m_Models != 0);\n  }\n  void Init()\n  {\n    UINT32 aNumModels = 1 << m_NumBitLevels;\n    for(UINT32 i = 1; i < aNumModels; i++)\n      m_Models[i].Init();\n  }\n  UINT32 Decode(CMyRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    RC_INIT_VAR\n    for(UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0; aBitIndex--)\n    {\n      // aModelIndex = (aModelIndex << 1) + m_Models[aModelIndex].Decode(aRangeDecoder);\n      RC_GETBIT(aNumMoveBits, m_Models[aModelIndex].m_Probability, aModelIndex)\n    }\n    RC_FLUSH_VAR\n    return aModelIndex - (1 << m_NumBitLevels);\n  }\n};\n*/\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/CRC.h",
    "content": "#ifndef __COMMON_CRC_H\n#define __COMMON_CRC_H\n\n#include \"Portable.h\"\n\nclass CCRC\n{\n  UINT32 m_Value;\npublic:\n\tstatic UINT32 m_Table[256];\n  CCRC():  m_Value(0xFFFFFFFF){};\n  void Init() { m_Value = 0xFFFFFFFF; }\n  void Update(const void *aData, UINT32 aSize);\n  UINT32 GetDigest() const { return m_Value ^ 0xFFFFFFFF; } \n  static UINT32 CalculateDigest(const void *aData, UINT32 aSize)\n  {\n    CCRC aCRC;\n    aCRC.Update(aData, aSize);\n    return aCRC.GetDigest();\n  }\n  static bool VerifyDigest(UINT32 aDigest, const void *aData, UINT32 aSize)\n  {\n    return (CalculateDigest(aData, aSize) == aDigest);\n  }\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/Const.h",
    "content": "#ifndef __DEFLATE_CONST_H\n#define __DEFLATE_CONST_H\n\nnamespace NDeflate {\n\nconst UINT32 kDistTableSize = 30;\nconst UINT32 kHistorySize = 0x8000;\nconst UINT32 kNumLenCombinations = 256;\n\nconst UINT32 kNumHuffmanBits = 15;\n\nconst UINT32 kLenTableSize = 29;\n\nconst UINT32 kStaticDistTableSize = 32;\nconst UINT32 kStaticLenTableSize = 31;\n\nconst UINT32 kReadTableNumber = 0x100;\nconst UINT32 kMatchNumber = kReadTableNumber + 1;\n\nconst UINT32 kMainTableSize = kMatchNumber + kLenTableSize; //298;\nconst UINT32 kStaticMainTableSize = kMatchNumber + kStaticLenTableSize; //298;\n\nconst UINT32 kDistTableStart = kMainTableSize;\n\nconst UINT32 kHeapTablesSizesSum = kMainTableSize + kDistTableSize;\n\nconst UINT32 kLevelTableSize = 19;\n\nconst UINT32 kMaxTableSize = kHeapTablesSizesSum; // test it\nconst UINT32 kStaticMaxTableSize = kStaticMainTableSize + kStaticDistTableSize;\n\nconst UINT32 kTableDirectLevels = 16;\nconst UINT32 kTableLevelRepNumber = kTableDirectLevels;\nconst UINT32 kTableLevel0Number = kTableLevelRepNumber + 1;\nconst UINT32 kTableLevel0Number2 = kTableLevel0Number + 1;\n\nconst UINT32 kLevelMask = 0xF;\n\nconst BYTE kLenStart[kLenTableSize]      = {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224, 255};\nconst BYTE kLenDirectBits[kLenTableSize] = {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,  4,  5,  5,  5,  5, 0};\n\n\nconst UINT32 kDistStart[kDistTableSize]     = {0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576};\nconst BYTE kDistDirectBits[kDistTableSize] = {0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5,  6,  6,  7,  7,  8,  8,   9,   9,  10,  10,  11,  11,  12,   12,   13,   13};\n\nconst BYTE kLevelDirectBits[kLevelTableSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};\n\nconst BYTE kCodeLengthAlphabetOrder[kLevelTableSize] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};\n\nconst UINT32 kMatchMinLen = 3; \nconst UINT32 kMatchMaxLen = kNumLenCombinations + kMatchMinLen - 1; // 255 + 2; test it\n\nconst int kFinalBlockFieldSize = 1;\n\nnamespace NFinalBlockField\n{\nenum\n{\n  kNotFinalBlock = 0,\n  kFinalBlock = 1\n};\n}\n\nconst int kBlockTypeFieldSize = 2;\n\nnamespace NBlockType\n{\n  enum\n  {\n    kStored = 0,\n    kFixedHuffman = 1,\n    kDynamicHuffman = 2,\n    kReserved = 3\n  };\n}\n\nconst UINT32 kDeflateNumberOfLengthCodesFieldSize  = 5;\nconst UINT32 kDeflateNumberOfDistanceCodesFieldSize  = 5;\nconst UINT32 kDeflateNumberOfLevelCodesFieldSize  = 4;\n\nconst UINT32 kDeflateNumberOfLitLenCodesMin = 257;\n\nconst UINT32 kDeflateNumberOfDistanceCodesMin = 1;\nconst UINT32 kDeflateNumberOfLevelCodesMin = 4;\n\nconst UINT32 kDeflateLevelCodeFieldSize  = 3;\n\nconst UINT32 kDeflateStoredBlockLengthFieldSizeSize = 16;\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/IInOutStreams.cpp",
    "content": "#include \"Portable.h\"\n#include \"IInOutStreams.h\"\n\nHRESULT ISequentialInStream::Read(void *aData, UINT32 aSize, UINT32* aProcessedSize) {\n\tif (aSize > size)\n\t\taSize = size;\n\t*aProcessedSize = aSize;\n\tmemcpy(aData, data, aSize);\n\tsize -= aSize;\n\tdata += aSize;\n\treturn S_OK;\n}\n\nHRESULT ISequentialOutStream::Write(const void *aData, UINT32 aSize, UINT32* aProcessedSize) {\n\tif (aSize > size) {\n\t\toverflow = true;\n\t\taSize = size;\n\t}\n\t*aProcessedSize = aSize;\n\tmemcpy(data, aData, aSize);\n\tsize -= aSize;\n\tdata += aSize;\n\ttotal += aSize;\n\treturn S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/IInOutStreams.h",
    "content": "#ifndef __IINOUTSTREAMS_H\n#define __IINOUTSTREAMS_H\n\n#include \"Portable.h\"\n\nclass ISequentialInStream\n{\n\tconst char* data;\n\tunsigned size;\npublic:\n\tISequentialInStream(const char* Adata, unsigned Asize) : data(Adata), size(Asize) { }\n\n\tHRESULT Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize);\n};\n\nclass ISequentialOutStream\n{\n\tchar* data;\n\tunsigned size;\n\tbool overflow;\n\tunsigned total;\npublic:\n\tISequentialOutStream(char* Adata, unsigned Asize) : data(Adata), size(Asize), overflow(false), total(0) { }\n\n\tbool overflow_get() const { return overflow; }\n\tunsigned size_get() const { return total; }\n\n\tHRESULT Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/InByte.cpp",
    "content": "#include \"InByte.h\"\n\nnamespace NStream{\n\nCInByte::CInByte(UINT32 aBufferSize):\n  m_BufferSize(aBufferSize),\n  m_BufferBase(0)\n{\n  m_BufferBase = new BYTE[m_BufferSize];\n}\n\nCInByte::~CInByte()\n{\n  delete []m_BufferBase;\n}\n\nvoid CInByte::Init(ISequentialInStream *aStream)\n{\n  m_Stream = aStream;\n  m_ProcessedSize = 0;\n  m_Buffer = m_BufferBase;\n  m_BufferLimit = m_Buffer;\n  m_StreamWasExhausted = false;\n}\n\nbool CInByte::ReadBlock()\n{\n  if (m_StreamWasExhausted)\n    return false;\n  m_ProcessedSize += (m_Buffer - m_BufferBase);\n  UINT32 aNumProcessedBytes;\n  HRESULT aResult = m_Stream->Read(m_BufferBase, m_BufferSize, &aNumProcessedBytes);\n  if (aResult != S_OK)\n    throw aResult;\n  m_Buffer = m_BufferBase;\n  m_BufferLimit = m_Buffer + aNumProcessedBytes;\n  m_StreamWasExhausted = (aNumProcessedBytes == 0);\n  return (!m_StreamWasExhausted);\n}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/InByte.h",
    "content": "#ifndef __STREAM_INBYTE_H\n#define __STREAM_INBYTE_H\n\n#include \"IInOutStreams.h\"\n\nnamespace NStream {\n\nclass CInByte\n{\n  UINT64 m_ProcessedSize;\n  BYTE *m_BufferBase;\n  UINT32 m_BufferSize;\n  BYTE *m_Buffer;\n  BYTE *m_BufferLimit;\n  ISequentialInStream* m_Stream;\n  bool m_StreamWasExhausted;\n\n  bool ReadBlock();\n\npublic:\n  CInByte(UINT32 aBufferSize = 0x100000);\n  ~CInByte();\n  \n  void Init(ISequentialInStream *aStream);\n\n  bool ReadByte(BYTE &aByte)\n    {\n      if(m_Buffer >= m_BufferLimit)\n        if(!ReadBlock())\n          return false;\n      aByte = *m_Buffer++;\n      return true;\n    }\n  BYTE ReadByte()\n    {\n      if(m_Buffer >= m_BufferLimit)\n        if(!ReadBlock())\n          return 0x0;\n      return *m_Buffer++;\n    }\n  void ReadBytes(void *aData, UINT32 aSize, UINT32 &aProcessedSize)\n    {\n      for(aProcessedSize = 0; aProcessedSize < aSize; aProcessedSize++)\n        if (!ReadByte(((BYTE *)aData)[aProcessedSize]))\n          return;\n    }\n  bool ReadBytes(void *aData, UINT32 aSize)\n    {\n      UINT32 aProcessedSize;\n      ReadBytes(aData, aSize, aProcessedSize);\n      return (aProcessedSize == aSize);\n    }\n  UINT64 GetProcessedSize() const { return m_ProcessedSize + (m_Buffer - m_BufferBase); }\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LZMA.cpp",
    "content": "#include \"LZMA.h\"\n\nnamespace NCompress {\nnamespace NLZMA {\n\nUINT32 kDistStart[kDistTableSizeMax];\n\nstatic class CConstInit\n{\npublic:\n  CConstInit()\n  {\n    UINT32 aStartValue = 0;\n    int i;\n    for (i = 0; i < kDistTableSizeMax; i++)\n    {\n      kDistStart[i] = aStartValue;\n      aStartValue += (1 << kDistDirectBits[i]);\n    }\n  }\n} g_ConstInit;\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LZMA.h",
    "content": "#include \"LenCoder.h\"\n\n#ifndef __LZMA_H\n#define __LZMA_H\n\nnamespace NCompress {\nnamespace NLZMA {\n\nconst UINT32 kNumRepDistances = 4;\n\nconst BYTE kNumStates = 12;\n\nconst BYTE kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\nconst BYTE kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\nconst BYTE kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\nconst BYTE kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\n\nclass CState\n{\npublic:\n  BYTE m_Index;\n  void Init()\n    { m_Index = 0; }\n  void UpdateChar()\n    { m_Index = kLiteralNextStates[m_Index]; }\n  void UpdateMatch()\n    { m_Index = kMatchNextStates[m_Index]; }\n  void UpdateRep()\n    { m_Index = kRepNextStates[m_Index]; }\n  void UpdateShortRep()\n    { m_Index = kShortRepNextStates[m_Index]; }\n};\n\nclass CBaseCoder\n{\nprotected:\n  CState m_State;\n  BYTE m_PreviousByte;\n  bool m_PeviousIsMatch;\n  UINT32 m_RepDistances[kNumRepDistances];\n  void Init()\n  {\n    m_State.Init();\n    m_PreviousByte = 0;\n    m_PeviousIsMatch = false;\n    for(int i = 0 ; i < kNumRepDistances; i++)\n      m_RepDistances[i] = 0;\n  }\n};\n\nconst int kNumPosSlotBits = 6; \nconst int kDicLogSizeMax = 28; \nconst int kDistTableSizeMax = kDicLogSizeMax * 2; \n\nextern UINT32 kDistStart[kDistTableSizeMax];\nconst BYTE kDistDirectBits[kDistTableSizeMax] = \n{\n  0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,\n  10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, \n  20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26 \n};\n\nconst UINT32 kNumLenToPosStates = 4;\ninline UINT32 GetLenToPosState(UINT32 aLen)\n{\n  aLen -= 2;\n  if (aLen < kNumLenToPosStates)\n    return aLen;\n  return kNumLenToPosStates - 1;\n}\n\nconst int kMatchMinLen = 2;\n\nconst int kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\n\nconst int kNumAlignBits = 4;\nconst int kAlignTableSize = 1 << kNumAlignBits;\nconst UINT32 kAlignMask = (kAlignTableSize - 1);\n\nconst int kStartPosModelIndex = 4;\nconst int kEndPosModelIndex = 14;\nconst int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\n\nconst int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\n\n\nconst int kMainChoiceLiteralIndex = 0;\nconst int kMainChoiceMatchIndex = 1;\n\nconst int kMatchChoiceDistanceIndex= 0;\nconst int kMatchChoiceRepetitionIndex = 1;\n\nconst int kNumMoveBitsForMainChoice = 5;\nconst int kNumMoveBitsForPosCoders = 5;\n\nconst int kNumMoveBitsForAlignCoders = 5;\n\nconst int kNumMoveBitsForPosSlotCoder = 5;\n\nconst int kNumLitPosStatesBitsEncodingMax = 4;\nconst int kNumLitContextBitsMax = 8;\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LZMADecoder.cpp",
    "content": "#include \"Portable.h\"\n#include \"LZMADecoder.h\"\n\n#define RETURN_E_OUTOFMEMORY_IF_FALSE(x) { if (!(x)) return E_OUTOFMEMORY; }\n\nnamespace NCompress {\nnamespace NLZMA {\n\nHRESULT CDecoder::SetDictionarySize(UINT32 aDictionarySize)\n{\n  if (aDictionarySize > (1 << kDicLogSizeMax))\n    return E_INVALIDARG;\n  \n  UINT32 aWindowReservSize = MyMax(aDictionarySize, UINT32(1 << 21));\n\n  if (m_DictionarySize != aDictionarySize)\n  {\n    m_OutWindowStream.Create(aDictionarySize, kMatchMaxLen, aWindowReservSize);\n    m_DictionarySize = aDictionarySize;\n  }\n  return S_OK;\n}\n\nHRESULT CDecoder::SetLiteralProperties(\n    UINT32 aLiteralPosStateBits, UINT32 aLiteralContextBits)\n{\n  if (aLiteralPosStateBits > 8)\n    return E_INVALIDARG;\n  if (aLiteralContextBits > 8)\n    return E_INVALIDARG;\n  m_LiteralDecoder.Create(aLiteralPosStateBits, aLiteralContextBits);\n  return S_OK;\n}\n\nHRESULT CDecoder::SetPosBitsProperties(UINT32 aNumPosStateBits)\n{\n  if (aNumPosStateBits > NLength::kNumPosStatesBitsMax)\n    return E_INVALIDARG;\n  UINT32 aNumPosStates = 1 << aNumPosStateBits;\n  m_LenDecoder.Create(aNumPosStates);\n  m_RepMatchLenDecoder.Create(aNumPosStates);\n  m_PosStateMask = aNumPosStates - 1;\n  return S_OK;\n}\n\nCDecoder::CDecoder():\n  m_DictionarySize((UINT32)-1)\n{\n  Create();\n}\n\nHRESULT CDecoder::Create()\n{\n  for(int i = 0; i < kNumPosModels; i++)\n  {\n    RETURN_E_OUTOFMEMORY_IF_FALSE(\n        m_PosDecoders[i].Create(kDistDirectBits[kStartPosModelIndex + i]));\n  }\n  return S_OK;\n}\n\n\nHRESULT CDecoder::Init(ISequentialInStream *anInStream,\n    ISequentialOutStream *anOutStream)\n{\n  m_RangeDecoder.Init(anInStream);\n\n  m_OutWindowStream.Init(anOutStream);\n\n  int i;\n  for(i = 0; i < kNumStates; i++)\n  {\n    for (UINT32 j = 0; j <= m_PosStateMask; j++)\n    {\n      m_MainChoiceDecoders[i][j].Init();\n      m_MatchRepShortChoiceDecoders[i][j].Init();\n    }\n    m_MatchChoiceDecoders[i].Init();\n    m_MatchRepChoiceDecoders[i].Init();\n    m_MatchRep1ChoiceDecoders[i].Init();\n    m_MatchRep2ChoiceDecoders[i].Init();\n  }\n  \n  m_LiteralDecoder.Init();\n   \n  // m_RepMatchLenDecoder.Init();\n\n  for (i = 0; i < kNumLenToPosStates; i++)\n    m_PosSlotDecoder[i].Init();\n\n  for(i = 0; i < kNumPosModels; i++)\n    m_PosDecoders[i].Init();\n  \n  m_LenDecoder.Init();\n  m_RepMatchLenDecoder.Init();\n\n  m_PosAlignDecoder.Init();\n  return S_OK;\n\n}\n\nHRESULT CDecoder::CodeReal(ISequentialInStream *anInStream,\n    ISequentialOutStream *anOutStream, \n    const UINT64 *anInSize, const UINT64 *anOutSize)\n{\n  if (anOutSize == NULL)\n    return E_INVALIDARG;\n\n  Init(anInStream, anOutStream);\n\n  CState aState;\n  aState.Init();\n  bool aPeviousIsMatch = false;\n  BYTE aPreviousByte = 0;\n  UINT32 aRepDistances[kNumRepDistances];\n  for(int i = 0 ; i < kNumRepDistances; i++)\n    aRepDistances[i] = 0;\n\n  UINT64 aNowPos64 = 0;\n  UINT64 aSize = *anOutSize;\n  while(aNowPos64 < aSize)\n  {\n    UINT64 aNext = MyMin(aNowPos64 + (1 << 18), aSize);\n    while(aNowPos64 < aNext)\n    {\n      UINT32 aPosState = UINT32(aNowPos64) & m_PosStateMask;\n      if (m_MainChoiceDecoders[aState.m_Index][aPosState].Decode(&m_RangeDecoder) == kMainChoiceLiteralIndex)\n      {\n        // aCounts[0]++;\n        aState.UpdateChar();\n        if(aPeviousIsMatch)\n        {\n          BYTE aMatchByte = m_OutWindowStream.GetOneByte(0 - aRepDistances[0] - 1);\n          aPreviousByte = m_LiteralDecoder.DecodeWithMatchByte(&m_RangeDecoder, \n              UINT32(aNowPos64), aPreviousByte, aMatchByte);\n          aPeviousIsMatch = false;\n        }\n        else\n          aPreviousByte = m_LiteralDecoder.DecodeNormal(&m_RangeDecoder, \n              UINT32(aNowPos64), aPreviousByte);\n        m_OutWindowStream.PutOneByte(aPreviousByte);\n        aNowPos64++;\n      }\n      else             \n      {\n        aPeviousIsMatch = true;\n        UINT32 aDistance, aLen;\n        if(m_MatchChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == \n            kMatchChoiceRepetitionIndex)\n        {\n          if(m_MatchRepChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == 0)\n          {\n            if(m_MatchRepShortChoiceDecoders[aState.m_Index][aPosState].Decode(&m_RangeDecoder) == 0)\n            {\n              aState.UpdateShortRep();\n              aPreviousByte = m_OutWindowStream.GetOneByte(0 - aRepDistances[0] - 1);\n              m_OutWindowStream.PutOneByte(aPreviousByte);\n              aNowPos64++;\n              // aCounts[3 + 4]++;\n              continue;\n            }\n            // aCounts[3 + 0]++;\n            aDistance = aRepDistances[0];\n          }\n          else\n          {\n            if(m_MatchRep1ChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == 0)\n            {\n              aDistance = aRepDistances[1];\n              aRepDistances[1] = aRepDistances[0];\n              // aCounts[3 + 1]++;\n            }\n            else \n            {\n              if (m_MatchRep2ChoiceDecoders[aState.m_Index].Decode(&m_RangeDecoder) == 0)\n              {\n                // aCounts[3 + 2]++;\n                aDistance = aRepDistances[2];\n              }\n              else\n              {\n                // aCounts[3 + 3]++;\n                aDistance = aRepDistances[3];\n                aRepDistances[3] = aRepDistances[2];\n              }\n              aRepDistances[2] = aRepDistances[1];\n              aRepDistances[1] = aRepDistances[0];\n            }\n            aRepDistances[0] = aDistance;\n          }\n          aLen = m_RepMatchLenDecoder.Decode(&m_RangeDecoder, aPosState) + kMatchMinLen;\n          // aCounts[aLen]++;\n          aState.UpdateRep();\n        }\n        else\n        {\n          aLen = kMatchMinLen + m_LenDecoder.Decode(&m_RangeDecoder, aPosState);\n          aState.UpdateMatch();\n          UINT32 aPosSlot = m_PosSlotDecoder[GetLenToPosState(aLen)].Decode(&m_RangeDecoder);\n          // aCounts[aPosSlot]++;\n          if (aPosSlot >= kStartPosModelIndex)\n          {\n            aDistance = kDistStart[aPosSlot];\n            if (aPosSlot < kEndPosModelIndex)\n              aDistance += m_PosDecoders[aPosSlot - kStartPosModelIndex].Decode(&m_RangeDecoder);\n            else\n            {\n              aDistance += (m_RangeDecoder.DecodeDirectBits(kDistDirectBits[aPosSlot] - \n                  kNumAlignBits) << kNumAlignBits);\n              aDistance += m_PosAlignDecoder.Decode(&m_RangeDecoder);\n            }\n          }\n          else\n            aDistance = aPosSlot;\n\n          \n          aRepDistances[3] = aRepDistances[2];\n          aRepDistances[2] = aRepDistances[1];\n          aRepDistances[1] = aRepDistances[0];\n          \n          aRepDistances[0] = aDistance;\n          // UpdateStat(aLen, aPosSlot);\n        }\n        if (aDistance >= aNowPos64)\n          throw E_INVALIDDATA;\n        m_OutWindowStream.CopyBackBlock(aDistance, aLen);\n        aNowPos64 += aLen;\n        aPreviousByte = m_OutWindowStream.GetOneByte(0 - 1);\n      }\n    }\n  }\n  return Flush();\n}\n\nHRESULT CDecoder::Code(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *anInSize, const UINT64 *anOutSize)\n{\n  try {\n     return CodeReal(anInStream, anOutStream, anInSize, anOutSize);\n  } catch (HRESULT& e) {\n     return e;\n  } catch (...) {\n     return E_FAIL;\n  }\n}\n\nHRESULT CDecoder::ReadCoderProperties(ISequentialInStream *anInStream)\n{\n  UINT32 aNumPosStateBits;\n  UINT32 aLiteralPosStateBits;\n  UINT32 aLiteralContextBits;\n  UINT32 aDictionarySize;\n\n   UINT32 aProcessesedSize;\n\n  BYTE aByte;\n  RETURN_IF_NOT_S_OK(anInStream->Read(&aByte, sizeof(aByte), &aProcessesedSize));\n  if (aProcessesedSize != sizeof(aByte))\n    return E_INVALIDARG;\n\n  aLiteralContextBits = aByte % 9;\n  BYTE aRemainder = aByte / 9;\n  aLiteralPosStateBits = aRemainder % 5;\n  aNumPosStateBits = aRemainder / 5;\n\n  RETURN_IF_NOT_S_OK(anInStream->Read(&aDictionarySize, sizeof(aDictionarySize), &aProcessesedSize));\n  if (aProcessesedSize != sizeof(aDictionarySize))\n    return E_INVALIDARG;\n\n  RETURN_IF_NOT_S_OK(SetDictionarySize(aDictionarySize));\n  RETURN_IF_NOT_S_OK(SetLiteralProperties(aLiteralPosStateBits, aLiteralContextBits));\n  RETURN_IF_NOT_S_OK(SetPosBitsProperties(aNumPosStateBits));\n\n  return S_OK;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LZMADecoder.h",
    "content": "#ifndef __LZARITHMETIC_DECODER_H\n#define __LZARITHMETIC_DECODER_H\n\n#include \"WindowOut.h\"\n#include \"LZMA.h\"\n#include \"LenCoder.h\"\n#include \"LiteralCoder.h\"\n\nnamespace NCompress {\nnamespace NLZMA {\n\ntypedef CMyBitDecoder<kNumMoveBitsForMainChoice> CMyBitDecoder2;\n\nclass CDecoder\n{\n  NStream::NWindow::COut m_OutWindowStream;\n  CMyRangeDecoder m_RangeDecoder;\n\n  CMyBitDecoder2 m_MainChoiceDecoders[kNumStates][NLength::kNumPosStatesMax];\n  CMyBitDecoder2 m_MatchChoiceDecoders[kNumStates];\n  CMyBitDecoder2 m_MatchRepChoiceDecoders[kNumStates];\n  CMyBitDecoder2 m_MatchRep1ChoiceDecoders[kNumStates];\n  CMyBitDecoder2 m_MatchRep2ChoiceDecoders[kNumStates];\n  CMyBitDecoder2 m_MatchRepShortChoiceDecoders[kNumStates][NLength::kNumPosStatesMax];\n\n  CBitTreeDecoder<kNumMoveBitsForPosSlotCoder, kNumPosSlotBits> m_PosSlotDecoder[kNumLenToPosStates];\n\n  CReverseBitTreeDecoder2<kNumMoveBitsForPosCoders> m_PosDecoders[kNumPosModels];\n  CReverseBitTreeDecoder<kNumMoveBitsForAlignCoders, kNumAlignBits> m_PosAlignDecoder;\n  // CBitTreeDecoder2<kNumMoveBitsForPosCoders> m_PosDecoders[kNumPosModels];\n  // CBitTreeDecoder<kNumMoveBitsForAlignCoders, kNumAlignBits> m_PosAlignDecoder;\n  \n  NLength::CDecoder m_LenDecoder;\n  NLength::CDecoder m_RepMatchLenDecoder;\n\n  NLiteral::CDecoder m_LiteralDecoder;\n\n  UINT32 m_DictionarySize;\n  \n  UINT32 m_PosStateMask;\n\n  HRESULT Create();\n\n  HRESULT Init(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream);\n\n  HRESULT Flush() {  return m_OutWindowStream.Flush(); }\n\n  HRESULT CodeReal(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *anInSize, const UINT64 *anOutSize);\n\npublic:\n\n  CDecoder();\n  \n  HRESULT Code(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *anInSize, const UINT64 *anOutSize);\n  HRESULT ReadCoderProperties(ISequentialInStream *anInStream);\n\n  HRESULT SetDictionarySize(UINT32 aDictionarySize);\n  HRESULT SetLiteralProperties(UINT32 aLiteralPosStateBits, UINT32 aLiteralContextBits);\n  HRESULT SetPosBitsProperties(UINT32 aNumPosStateBits);\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LZMAEncoder.cpp",
    "content": "#include \"Portable.h\"\n#include \"LZMAEncoder.h\"\n\n#include \"BinTree2Main.h\"\n\nusing namespace NCompression;\nusing namespace NArithmetic;\n\n#define RETURN_E_OUTOFMEMORY_IF_FALSE(x) { if (!(x)) return E_OUTOFMEMORY; }\n\nnamespace NCompress {\nnamespace NLZMA {\n\nBYTE g_FastPos[1024];\n\nclass CFastPosInit\n{\npublic:\n  CFastPosInit()\n  {\n    int c = 0;\n    const int kFastSlots = 20;\n    c = 0;\n    for (BYTE aSlotFast = 0; aSlotFast < kFastSlots; aSlotFast++)\n    {\n      UINT32 k = (1 << kDistDirectBits[aSlotFast]);\n      for (UINT32 j = 0; j < k; j++, c++)\n        g_FastPos[c] = aSlotFast;\n    }\n  }\n} g_FastPosInit;\n\nconst int kDefaultDictionaryLogSize = 20;\nconst int kNumFastBytesDefault = 0x20;\n\nCEncoder::CEncoder():\n  m_DictionarySize(1 << kDefaultDictionaryLogSize),\n  m_DictionarySizePrev(UINT32(-1)),\n  m_NumFastBytes(kNumFastBytesDefault),\n  m_NumFastBytesPrev(UINT32(-1)),\n  m_DistTableSize(kDefaultDictionaryLogSize * 2),\n  m_PosStateBits(2),\n  m_PosStateMask(4 - 1),\n  m_LiteralPosStateBits(0),\n  m_LiteralContextBits(3)\n{\n  m_MaxMode = false;\n  m_FastMode = false;\n  m_PosAlignEncoder.Create(kNumAlignBits);\n  for(int i = 0; i < kNumPosModels; i++)\n    m_PosEncoders[i].Create(kDistDirectBits[kStartPosModelIndex + i]);\n}\n\nHRESULT CEncoder::Create()\n{\n  if (m_DictionarySize == m_DictionarySizePrev && m_NumFastBytesPrev == m_NumFastBytes)\n    return S_OK;\n  RETURN_IF_NOT_S_OK(m_MatchFinder.Create(m_DictionarySize, kNumOpts, m_NumFastBytes, \n      kMatchMaxLen - m_NumFastBytes));\n  m_DictionarySizePrev = m_DictionarySize;\n  m_NumFastBytesPrev = m_NumFastBytes;\n  m_LiteralEncoder.Create(m_LiteralPosStateBits, m_LiteralContextBits);\n  m_LenEncoder.Create(1 << m_PosStateBits);\n  m_RepMatchLenEncoder.Create(1 << m_PosStateBits);\n  return S_OK;\n}\n\nHRESULT CEncoder::SetEncoderAlgorithm(UINT32 A) {\n  UINT32 aMaximize = A;\n  if (aMaximize > 2)\n    return E_INVALIDARG;\n\n  m_FastMode = (aMaximize == 0);\n  m_MaxMode = (aMaximize >= 2);\n\n  return S_OK;\n}\n\nHRESULT CEncoder::SetEncoderNumFastBytes(UINT32 A) {\n  UINT32 aNumFastBytes = A;\n  if(aNumFastBytes < 2 || aNumFastBytes > kMatchMaxLen)\n    return E_INVALIDARG;\n\n  m_NumFastBytes = aNumFastBytes;\n\n  return S_OK;\n}\n\nHRESULT CEncoder::SetDictionarySize(UINT32 aDictionarySize)\n{\n  if (aDictionarySize > UINT32(1 << kDicLogSizeMax))\n    return E_INVALIDARG;\n  m_DictionarySize = aDictionarySize;\n  UINT32 aDicLogSize;\n  for(aDicLogSize = 0; aDicLogSize < kDicLogSizeMax; aDicLogSize++)\n    if (aDictionarySize <= (UINT32(1) << aDicLogSize))\n      break;\n  m_DistTableSize = aDicLogSize * 2;\n  return S_OK;\n}\n\nHRESULT CEncoder::SetLiteralProperties(UINT32 aLiteralPosStateBits, UINT32 aLiteralContextBits)\n{\n  if (aLiteralPosStateBits > kNumLitPosStatesBitsEncodingMax)\n    return E_INVALIDARG;\n  if (aLiteralContextBits > kNumLitContextBitsMax)\n    return E_INVALIDARG;\n  m_LiteralPosStateBits = aLiteralPosStateBits;\n  m_LiteralContextBits = aLiteralContextBits;\n  return S_OK;\n}\n\nHRESULT CEncoder::SetPosBitsProperties(UINT32 aNumPosStateBits)\n{\n  if (aNumPosStateBits > NLength::kNumPosStatesBitsEncodingMax)\n    return E_INVALIDARG;\n  m_PosStateBits = aNumPosStateBits;\n  m_PosStateMask = (1 << m_PosStateBits) - 1;\n  return S_OK;\n}\n\n\nHRESULT CEncoder::WriteCoderProperties(ISequentialOutStream *anOutStream)\n{ \n  BYTE aByte = (m_PosStateBits * 5 + m_LiteralPosStateBits) * 9 + m_LiteralContextBits;\n  UINT32 aProcessedSize;\n  HRESULT aResult = anOutStream->Write(&aByte, sizeof(aByte), &aProcessedSize);\n  if (aResult != S_OK)\n     return aResult;\n  if (aProcessedSize != sizeof(aByte))\n     return E_FAIL;\n  aResult = anOutStream->Write(&m_DictionarySize, sizeof(m_DictionarySize), &aProcessedSize);\n    if (aResult != S_OK)\n     return aResult;\n  if (aProcessedSize != sizeof(m_DictionarySize))\n     return E_FAIL;\n  return S_OK;\n}\n\nHRESULT CEncoder::Init(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream)\n{\n  CBaseCoder::Init();\n\n  RETURN_IF_NOT_S_OK(m_MatchFinder.Init(anInStream));\n  m_RangeEncoder.Init(anOutStream);\n\n  int i;\n  for(i = 0; i < kNumStates; i++)\n  {\n    for (UINT32 j = 0; j <= m_PosStateMask; j++)\n    {\n      m_MainChoiceEncoders[i][j].Init();\n      m_MatchRepShortChoiceEncoders[i][j].Init();\n    }\n    m_MatchChoiceEncoders[i].Init();\n    m_MatchRepChoiceEncoders[i].Init();\n    m_MatchRep1ChoiceEncoders[i].Init();\n    m_MatchRep2ChoiceEncoders[i].Init();\n  }\n\n  m_LiteralEncoder.Init();\n\n  // m_RepMatchLenEncoder.Init();\n  \n  for(i = 0; i < kNumLenToPosStates; i++)\n    m_PosSlotEncoder[i].Init();\n\n  for(i = 0; i < kNumPosModels; i++)\n    m_PosEncoders[i].Init();\n\n  m_LenEncoder.Init();\n  m_RepMatchLenEncoder.Init();\n\n  m_PosAlignEncoder.Init();\n\n  m_LongestMatchWasFound = false;\n  m_OptimumEndIndex = 0;\n  m_OptimumCurrentIndex = 0;\n  m_AdditionalOffset = 0;\n\n  return S_OK;\n}\n\nvoid CEncoder::MovePos(UINT32 aNum)\n{\n  for (;aNum > 0; aNum--)\n  {\n    m_MatchFinder.DummyLongestMatch();\n    HRESULT aResult = m_MatchFinder.MovePos();\n    if (aResult != S_OK)\n      throw aResult;\n    m_AdditionalOffset++;\n  }\n}\n\nUINT32 CEncoder::Backward(UINT32 &aBackRes, UINT32 aCur)\n{\n  m_OptimumEndIndex = aCur;\n  UINT32 aPosMem = m_Optimum[aCur].PosPrev;\n  UINT32 aBackMem = m_Optimum[aCur].BackPrev;\n  do\n  {\n    if (m_Optimum[aCur].Prev1IsChar)\n    {\n      m_Optimum[aPosMem].MakeAsChar();\n      m_Optimum[aPosMem].PosPrev = aPosMem - 1;\n      if (m_Optimum[aCur].Prev2)\n      {\n        m_Optimum[aPosMem - 1].Prev1IsChar = false;\n        m_Optimum[aPosMem - 1].PosPrev = m_Optimum[aCur].PosPrev2;\n        m_Optimum[aPosMem - 1].BackPrev = m_Optimum[aCur].BackPrev2;\n      }\n    }\n    UINT32 aPosPrev = aPosMem;\n    UINT32 aBackCur = aBackMem;\n\n    aBackMem = m_Optimum[aPosPrev].BackPrev;\n    aPosMem = m_Optimum[aPosPrev].PosPrev;\n\n    m_Optimum[aPosPrev].BackPrev = aBackCur;\n    m_Optimum[aPosPrev].PosPrev = aCur;\n    aCur = aPosPrev;\n  }\n  while(aCur > 0);\n  aBackRes = m_Optimum[0].BackPrev;\n  m_OptimumCurrentIndex  = m_Optimum[0].PosPrev;\n  return m_OptimumCurrentIndex; \n}\n\n/*\ninline UINT32 GetMatchLen(const BYTE *aData, UINT32 aBack, UINT32 aLimit)\n{  \n  aBack++;\n  for(UINT32 i = 0; i < aLimit && aData[i] == aData[i - aBack]; i++);\n  return i;\n}\n*/\n\nUINT32 CEncoder::GetOptimum(UINT32 &aBackRes, UINT32 aPosition)\n{\n  if(m_OptimumEndIndex != m_OptimumCurrentIndex)\n  {\n    UINT32 aLen = m_Optimum[m_OptimumCurrentIndex].PosPrev - m_OptimumCurrentIndex;\n    aBackRes = m_Optimum[m_OptimumCurrentIndex].BackPrev;\n    m_OptimumCurrentIndex = m_Optimum[m_OptimumCurrentIndex].PosPrev;\n    return aLen;\n  }\n  m_OptimumCurrentIndex = 0;\n  m_OptimumEndIndex = 0; // test it;\n  \n  UINT32 aLenMain;\n  if (!m_LongestMatchWasFound)\n    aLenMain = ReadMatchDistances();\n  else\n  {\n    aLenMain = m_LongestMatchLength;\n    m_LongestMatchWasFound = false;\n  }\n\n\n  UINT32 aReps[kNumRepDistances];\n  UINT32 aRepLens[kNumRepDistances];\n  UINT32 RepMaxIndex = 0;\n  int i;\n  for(i = 0; i < kNumRepDistances; i++)\n  {\n    aReps[i] = m_RepDistances[i];\n    aRepLens[i] = m_MatchFinder.GetMatchLen(0 - 1, aReps[i], kMatchMaxLen);\n    if (i == 0 || aRepLens[i] > aRepLens[RepMaxIndex])\n      RepMaxIndex = i;\n  }\n  if(aRepLens[RepMaxIndex] > m_NumFastBytes)\n  {\n    aBackRes = RepMaxIndex;\n    MovePos(aRepLens[RepMaxIndex] - 1);\n    return aRepLens[RepMaxIndex];\n  }\n\n  if(aLenMain > m_NumFastBytes)\n  {\n    UINT32 aBackMain = (aLenMain < m_NumFastBytes) ? m_MatchDistances[aLenMain] :\n        m_MatchDistances[m_NumFastBytes];\n    aBackRes = aBackMain + kNumRepDistances; \n    MovePos(aLenMain - 1);\n    return aLenMain;\n  }\n  BYTE aCurrentByte = m_MatchFinder.GetIndexByte(0 - 1);\n\n  m_Optimum[0].State = m_State;\n\n  BYTE aMatchByte;\n  \n  aMatchByte = m_MatchFinder.GetIndexByte(0 - m_RepDistances[0] - 1 - 1);\n\n  UINT32 aPosState = (aPosition & m_PosStateMask);\n\n  m_Optimum[1].Price = m_MainChoiceEncoders[m_State.m_Index][aPosState].GetPrice(kMainChoiceLiteralIndex) + \n      m_LiteralEncoder.GetPrice(aPosition, m_PreviousByte, m_PeviousIsMatch, aMatchByte, aCurrentByte);\n  m_Optimum[1].MakeAsChar();\n\n  m_Optimum[1].PosPrev = 0;\n\n  for (i = 0; i < kNumRepDistances; i++)\n    m_Optimum[0].Backs[i] = aReps[i];\n\n  UINT32 aMatchPrice = m_MainChoiceEncoders[m_State.m_Index][aPosState].GetPrice(kMainChoiceMatchIndex);\n  UINT32 aRepMatchPrice = aMatchPrice + \n      m_MatchChoiceEncoders[m_State.m_Index].GetPrice(kMatchChoiceRepetitionIndex);\n\n  if(aMatchByte == aCurrentByte)\n  {\n    UINT32 aShortRepPrice = aRepMatchPrice + GetRepLen1Price(m_State, aPosState);\n    if(aShortRepPrice < m_Optimum[1].Price)\n    {\n      m_Optimum[1].Price = aShortRepPrice;\n      m_Optimum[1].MakeAsShortRep();\n    }\n  }\n  if(aLenMain < 2)\n  {\n    aBackRes = m_Optimum[1].BackPrev;\n    return 1;\n  }\n\n  \n  UINT32 aNormalMatchPrice = aMatchPrice + \n      m_MatchChoiceEncoders[m_State.m_Index].GetPrice(kMatchChoiceDistanceIndex);\n\n  if (aLenMain <= aRepLens[RepMaxIndex])\n    aLenMain = 0;\n\n  UINT32 aLen;\n  for(aLen = 2; aLen <= aLenMain; aLen++)\n  {\n    m_Optimum[aLen].PosPrev = 0;\n    m_Optimum[aLen].BackPrev = m_MatchDistances[aLen] + kNumRepDistances;\n    m_Optimum[aLen].Price = aNormalMatchPrice + \n        GetPosLenPrice(m_MatchDistances[aLen], aLen, aPosState);\n    m_Optimum[aLen].Prev1IsChar = false;\n  }\n\n  if (aLenMain < aRepLens[RepMaxIndex])\n    aLenMain = aRepLens[RepMaxIndex];\n\n  for (; aLen <= aLenMain; aLen++)\n    m_Optimum[aLen].Price = kIfinityPrice;\n\n  for(i = 0; i < kNumRepDistances; i++)\n  {\n    unsigned aRepLen = aRepLens[i];\n    for(UINT32 aLenTest = 2; aLenTest <= aRepLen; aLenTest++)\n    {\n      UINT32 aCurAndLenPrice = aRepMatchPrice + GetRepPrice(i, aLenTest, m_State, aPosState);\n      COptimal &anOptimum = m_Optimum[aLenTest];\n      if (aCurAndLenPrice < anOptimum.Price) \n      {\n        anOptimum.Price = aCurAndLenPrice;\n        anOptimum.PosPrev = 0;\n        anOptimum.BackPrev = i;\n        anOptimum.Prev1IsChar = false;\n      }\n    }\n  }\n\n  UINT32 aCur = 0;\n  UINT32 aLenEnd = aLenMain;\n\n  while(true)\n  {\n    aCur++;\n    if(aCur == aLenEnd)  \n      return Backward(aBackRes, aCur);\n    aPosition++;\n    UINT32 aPosPrev = m_Optimum[aCur].PosPrev;\n    CState aState;\n    if (m_Optimum[aCur].Prev1IsChar)\n    {\n      aPosPrev--;\n      if (m_Optimum[aCur].Prev2)\n      {\n        aState = m_Optimum[m_Optimum[aCur].PosPrev2].State;\n        if (m_Optimum[aCur].BackPrev2 < kNumRepDistances)\n          aState.UpdateRep();\n        else\n          aState.UpdateMatch();\n      }\n      else\n        aState = m_Optimum[aPosPrev].State;\n      aState.UpdateChar();\n    }\n    else\n      aState = m_Optimum[aPosPrev].State;\n    bool aPrevWasMatch;\n    if (aPosPrev == aCur - 1)\n    {\n      if (m_Optimum[aCur].IsShortRep())\n      {\n        aPrevWasMatch = true;\n        aState.UpdateShortRep();\n      }\n      else\n      {\n        aPrevWasMatch = false;\n        aState.UpdateChar();\n      }\n      /*\n      if (m_Optimum[aCur].Prev1IsChar)\n        for(int i = 0; i < kNumRepDistances; i++)\n          aReps[i] = m_Optimum[aPosPrev].Backs[i];\n      */\n    }\n    else\n    {\n      aPrevWasMatch = true;\n      UINT32 aPos;\n      if (m_Optimum[aCur].Prev1IsChar && m_Optimum[aCur].Prev2)\n      {\n        aPosPrev = m_Optimum[aCur].PosPrev2;\n        aPos = m_Optimum[aCur].BackPrev2;\n        aState.UpdateRep();\n      }\n      else\n      {\n        aPos = m_Optimum[aCur].BackPrev;\n        if (aPos < kNumRepDistances)\n          aState.UpdateRep();\n        else\n          aState.UpdateMatch();\n      }\n      if (aPos < kNumRepDistances)\n      {\n        aReps[0] = m_Optimum[aPosPrev].Backs[aPos];\n    \t\tUINT32 i;\n        for(i = 1; i <= aPos; i++)\n          aReps[i] = m_Optimum[aPosPrev].Backs[i - 1];\n        for(; i < kNumRepDistances; i++)\n          aReps[i] = m_Optimum[aPosPrev].Backs[i];\n      }\n      else\n      {\n        aReps[0] = (aPos - kNumRepDistances);\n        for(UINT32 i = 1; i < kNumRepDistances; i++)\n          aReps[i] = m_Optimum[aPosPrev].Backs[i - 1];\n      }\n    }\n    m_Optimum[aCur].State = aState;\n    for(UINT32 i = 0; i < kNumRepDistances; i++)\n      m_Optimum[aCur].Backs[i] = aReps[i];\n    UINT32 aNewLen = ReadMatchDistances();\n    if(aNewLen > m_NumFastBytes)\n    {\n      m_LongestMatchLength = aNewLen;\n      m_LongestMatchWasFound = true;\n      return Backward(aBackRes, aCur);\n    }\n    UINT32 aCurPrice = m_Optimum[aCur].Price; \n    // BYTE aCurrentByte  = m_MatchFinder.GetIndexByte(0 - 1);\n    // BYTE aMatchByte = m_MatchFinder.GetIndexByte(0 - aReps[0] - 1 - 1);\n    const BYTE *aData = m_MatchFinder.GetPointerToCurrentPos() - 1;\n    BYTE aCurrentByte = *aData;\n    BYTE aMatchByte = aData[0 - aReps[0] - 1];\n\n    UINT32 aPosState = (aPosition & m_PosStateMask);\n\n    UINT32 aCurAnd1Price = aCurPrice +\n        m_MainChoiceEncoders[aState.m_Index][aPosState].GetPrice(kMainChoiceLiteralIndex) +\n        m_LiteralEncoder.GetPrice(aPosition, aData[-1], aPrevWasMatch, aMatchByte, aCurrentByte);\n\n    COptimal &aNextOptimum = m_Optimum[aCur + 1];\n\n    bool aNextIsChar = false;\n    if (aCurAnd1Price < aNextOptimum.Price) \n    {\n      aNextOptimum.Price = aCurAnd1Price;\n      aNextOptimum.PosPrev = aCur;\n      aNextOptimum.MakeAsChar();\n      aNextIsChar = true;\n    }\n\n    UINT32 aMatchPrice = aCurPrice + m_MainChoiceEncoders[aState.m_Index][aPosState].GetPrice(kMainChoiceMatchIndex);\n    UINT32 aRepMatchPrice = aMatchPrice + m_MatchChoiceEncoders[aState.m_Index].GetPrice(kMatchChoiceRepetitionIndex);\n    \n    if(aMatchByte == aCurrentByte &&\n        !(aNextOptimum.PosPrev < aCur && aNextOptimum.BackPrev == 0))\n    {\n      UINT32 aShortRepPrice = aRepMatchPrice + GetRepLen1Price(aState, aPosState);\n      if(aShortRepPrice <= aNextOptimum.Price)\n      {\n        aNextOptimum.Price = aShortRepPrice;\n        aNextOptimum.PosPrev = aCur;\n        aNextOptimum.MakeAsShortRep();\n        // aNextIsChar = false;\n      }\n    }\n    /*\n    if(aNewLen == 2 && m_MatchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\n      continue;\n    */\n\n    UINT32 aNumAvailableBytes = m_MatchFinder.GetNumAvailableBytes() + 1;\n    aNumAvailableBytes = MyMin(kNumOpts - 1 - aCur, aNumAvailableBytes);\n\n    if (aNumAvailableBytes < 2)\n      continue;\n    if (aNumAvailableBytes > m_NumFastBytes)\n      aNumAvailableBytes = m_NumFastBytes;\n    if (aNumAvailableBytes >= 3 && !aNextIsChar)\n    {\n      UINT32 aBackOffset = aReps[0] + 1;\n      UINT32 aTemp;\n      for (aTemp = 1; aTemp < aNumAvailableBytes; aTemp++)\n        if (aData[aTemp] != aData[aTemp - aBackOffset])\n          break;\n      UINT32 aLenTest2 = aTemp - 1;\n      if (aLenTest2 >= 2)\n      {\n        CState aState2 = aState;\n        aState2.UpdateChar();\n        UINT32 aPosStateNext = (aPosition + 1) & m_PosStateMask;\n        UINT32 aNextRepMatchPrice = aCurAnd1Price + \n            m_MainChoiceEncoders[aState2.m_Index][aPosStateNext].GetPrice(kMainChoiceMatchIndex) +\n            m_MatchChoiceEncoders[aState2.m_Index].GetPrice(kMatchChoiceRepetitionIndex);\n        // for (; aLenTest2 >= 2; aLenTest2--)\n        {\n          while(aLenEnd < aCur + 1 + aLenTest2)\n            m_Optimum[++aLenEnd].Price = kIfinityPrice;\n          UINT32 aCurAndLenPrice = aNextRepMatchPrice + GetRepPrice(\n              0, aLenTest2, aState2, aPosStateNext);\n          COptimal &anOptimum = m_Optimum[aCur + 1 + aLenTest2];\n          if (aCurAndLenPrice < anOptimum.Price) \n          {\n            anOptimum.Price = aCurAndLenPrice;\n            anOptimum.PosPrev = aCur + 1;\n            anOptimum.BackPrev = 0;\n            anOptimum.Prev1IsChar = true;\n            anOptimum.Prev2 = false;\n          }\n        }\n      }\n    }\n    for(UINT32 aRepIndex = 0; aRepIndex < kNumRepDistances; aRepIndex++)\n    {\n      // UINT32 aRepLen = m_MatchFinder.GetMatchLen(0 - 1, aReps[aRepIndex], aNewLen); // test it;\n      UINT32 aBackOffset = aReps[aRepIndex] + 1;\n      UINT32 aLenTest;\n      for (aLenTest = 0; aLenTest < aNumAvailableBytes; aLenTest++)\n        if (aData[aLenTest] != aData[aLenTest - aBackOffset])\n          break;\n      for(; aLenTest >= 2; aLenTest--)\n      {\n        while(aLenEnd < aCur + aLenTest)\n          m_Optimum[++aLenEnd].Price = kIfinityPrice;\n        UINT32 aCurAndLenPrice = aRepMatchPrice + GetRepPrice(aRepIndex, aLenTest, aState, aPosState);\n        COptimal &anOptimum = m_Optimum[aCur + aLenTest];\n        if (aCurAndLenPrice < anOptimum.Price) \n        {\n          anOptimum.Price = aCurAndLenPrice;\n          anOptimum.PosPrev = aCur;\n          anOptimum.BackPrev = aRepIndex;\n          anOptimum.Prev1IsChar = false;\n        }\n\n        /*\n        if (m_MaxMode)\n        {\n          UINT32 aTemp;\n          for (aTemp = aLenTest + 1; aTemp < aNumAvailableBytes; aTemp++)\n            if (aData[aTemp] != aData[aTemp - aBackOffset])\n              break;\n          UINT32 aLenTest2 = aTemp - (aLenTest + 1);\n          if (aLenTest2 >= 2)\n          {\n            CState aState2 = aState;\n            aState2.UpdateRep();\n            UINT32 aPosStateNext = (aPosition + aLenTest) & m_PosStateMask;\n            UINT32 aCurAndLenCharPrice = aCurAndLenPrice + \n                m_MainChoiceEncoders[aState2.m_Index][aPosStateNext].GetPrice(kMainChoiceLiteralIndex) +\n                m_LiteralEncoder.GetPrice(aPosition + aLenTest, aData[aLenTest - 1], \n                true, aData[aLenTest - aBackOffset], aData[aLenTest]);\n            aState2.UpdateChar();\n            aPosStateNext = (aPosition + aLenTest + 1) & m_PosStateMask;\n            UINT32 aNextMatchPrice = aCurAndLenCharPrice + m_MainChoiceEncoders[aState2.m_Index][aPosStateNext].GetPrice(kMainChoiceMatchIndex);\n            UINT32 aNextRepMatchPrice = aNextMatchPrice + m_MatchChoiceEncoders[aState2.m_Index].GetPrice(kMatchChoiceRepetitionIndex);\n            \n            // for(; aLenTest2 >= 2; aLenTest2--)\n            {\n              UINT32 anOffset = aLenTest + 1 + aLenTest2;\n              while(aLenEnd < aCur + anOffset)\n                m_Optimum[++aLenEnd].Price = kIfinityPrice;\n              UINT32 aCurAndLenPrice = aNextRepMatchPrice + GetRepPrice(\n                  0, aLenTest2, aState2, aPosStateNext);\n              COptimal &anOptimum = m_Optimum[aCur + anOffset];\n              if (aCurAndLenPrice < anOptimum.Price) \n              {\n                anOptimum.Price = aCurAndLenPrice;\n                anOptimum.PosPrev = aCur + aLenTest + 1;\n                anOptimum.BackPrev = 0;\n                anOptimum.Prev1IsChar = true;\n                anOptimum.Prev2 = true;\n                anOptimum.PosPrev2 = aCur;\n                anOptimum.BackPrev2 = aRepIndex;\n              }\n            }\n          }\n        }\n        */\n      }\n    }\n    \n    //    for(UINT32 aLenTest = 2; aLenTest <= aNewLen; aLenTest++)\n    if (aNewLen > aNumAvailableBytes)\n      aNewLen = aNumAvailableBytes;\n    if (aNewLen >= 2)\n    {\n      if (aNewLen == 2 && m_MatchDistances[2] >= 0x80)\n        continue;\n      UINT32 aNormalMatchPrice = aMatchPrice + \n        m_MatchChoiceEncoders[aState.m_Index].GetPrice(kMatchChoiceDistanceIndex);\n      while(aLenEnd < aCur + aNewLen)\n        m_Optimum[++aLenEnd].Price = kIfinityPrice;\n\n      for(UINT32 aLenTest = aNewLen; aLenTest >= 2; aLenTest--)\n      {\n        UINT32 aCurBack = m_MatchDistances[aLenTest];\n        UINT32 aCurAndLenPrice = aNormalMatchPrice + GetPosLenPrice(aCurBack, aLenTest, aPosState);\n        COptimal &anOptimum = m_Optimum[aCur + aLenTest];\n        if (aCurAndLenPrice < anOptimum.Price) \n        {\n          anOptimum.Price = aCurAndLenPrice;\n          anOptimum.PosPrev = aCur;\n          anOptimum.BackPrev = aCurBack + kNumRepDistances;\n          anOptimum.Prev1IsChar = false;\n        }\n\n        if (m_MaxMode)\n        {\n          UINT32 aBackOffset = aCurBack + 1;\n          UINT32 aTemp;\n          for (aTemp = aLenTest + 1; aTemp < aNumAvailableBytes; aTemp++)\n            if (aData[aTemp] != aData[aTemp - aBackOffset])\n              break;\n          UINT32 aLenTest2 = aTemp - (aLenTest + 1);\n          if (aLenTest2 >= 2)\n          {\n            CState aState2 = aState;\n            aState2.UpdateMatch();\n            UINT32 aPosStateNext = (aPosition + aLenTest) & m_PosStateMask;\n            UINT32 aCurAndLenCharPrice = aCurAndLenPrice + \n                m_MainChoiceEncoders[aState2.m_Index][aPosStateNext].GetPrice(kMainChoiceLiteralIndex) +\n                m_LiteralEncoder.GetPrice(aPosition + aLenTest, aData[aLenTest - 1], \n                true, aData[aLenTest - aBackOffset], aData[aLenTest]);\n            aState2.UpdateChar();\n            aPosStateNext = (aPosition + aLenTest + 1) & m_PosStateMask;\n            UINT32 aNextMatchPrice = aCurAndLenCharPrice + m_MainChoiceEncoders[aState2.m_Index][aPosStateNext].GetPrice(kMainChoiceMatchIndex);\n            UINT32 aNextRepMatchPrice = aNextMatchPrice + m_MatchChoiceEncoders[aState2.m_Index].GetPrice(kMatchChoiceRepetitionIndex);\n            \n            // for(; aLenTest2 >= 2; aLenTest2--)\n            {\n              UINT32 anOffset = aLenTest + 1 + aLenTest2;\n              while(aLenEnd < aCur + anOffset)\n                m_Optimum[++aLenEnd].Price = kIfinityPrice;\n              UINT32 aCurAndLenPrice = aNextRepMatchPrice + GetRepPrice(\n                  0, aLenTest2, aState2, aPosStateNext);\n              COptimal &anOptimum = m_Optimum[aCur + anOffset];\n              if (aCurAndLenPrice < anOptimum.Price) \n              {\n                anOptimum.Price = aCurAndLenPrice;\n                anOptimum.PosPrev = aCur + aLenTest + 1;\n                anOptimum.BackPrev = 0;\n                anOptimum.Prev1IsChar = true;\n                anOptimum.Prev2 = true;\n                anOptimum.PosPrev2 = aCur;\n                anOptimum.BackPrev2 = aCurBack + kNumRepDistances;\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}\n\nstatic bool inline ChangePair(UINT32 aSmall, UINT32 aBig)\n{\n  const int kDif = 7;\n  return (aSmall < (UINT32(1) << (32-kDif)) && aBig >= (aSmall << kDif));\n}\n\n\nUINT32 CEncoder::GetOptimumFast(UINT32 &aBackRes, UINT32 aPosition)\n{\n  UINT32 aLenMain;\n  if (!m_LongestMatchWasFound)\n    aLenMain = ReadMatchDistances();\n  else\n  {\n    aLenMain = m_LongestMatchLength;\n    m_LongestMatchWasFound = false;\n  }\n  UINT32 aRepLens[kNumRepDistances];\n  UINT32 RepMaxIndex = 0;\n  for(int i = 0; i < kNumRepDistances; i++)\n  {\n    aRepLens[i] = m_MatchFinder.GetMatchLen(0 - 1, m_RepDistances[i], kMatchMaxLen);\n    if (i == 0 || aRepLens[i] > aRepLens[RepMaxIndex])\n      RepMaxIndex = i;\n  }\n  if(aRepLens[RepMaxIndex] >= m_NumFastBytes)\n  {\n    aBackRes = RepMaxIndex;\n    MovePos(aRepLens[RepMaxIndex] - 1);\n    return aRepLens[RepMaxIndex];\n  }\n  if(aLenMain >= m_NumFastBytes)\n  {\n    aBackRes = m_MatchDistances[m_NumFastBytes] + kNumRepDistances; \n    MovePos(aLenMain - 1);\n    return aLenMain;\n  }\n  while (aLenMain > 2)\n  {\n    if (!ChangePair(m_MatchDistances[aLenMain - 1], \n        m_MatchDistances[aLenMain]))\n      break;\n    aLenMain--;\n  }\n  if (aLenMain == 2 && m_MatchDistances[2] >= 0x80)\n    aLenMain = 1;\n\n  UINT32 aBackMain = m_MatchDistances[aLenMain];\n  if (aRepLens[RepMaxIndex] >= 2)\n  {\n    if (aRepLens[RepMaxIndex] + 1 >= aLenMain || \n        aRepLens[RepMaxIndex] + 2 >= aLenMain && (aBackMain > (1<<12)))\n    {\n      aBackRes = RepMaxIndex;\n      MovePos(aRepLens[RepMaxIndex] - 1);\n      return aRepLens[RepMaxIndex];\n    }\n  }\n  \n\n  if (aLenMain >= 2)\n  {\n    m_LongestMatchLength = ReadMatchDistances();\n    if (m_LongestMatchLength >= 2 &&\n      (\n        (m_LongestMatchLength >= aLenMain && \n          m_MatchDistances[aLenMain] < aBackMain) || \n        m_LongestMatchLength == aLenMain + 1 && \n          !ChangePair(aBackMain, m_MatchDistances[m_LongestMatchLength]) ||\n        m_LongestMatchLength > aLenMain + 1 ||\n        m_LongestMatchLength + 1 >= aLenMain && \n          ChangePair(m_MatchDistances[aLenMain - 1], aBackMain)\n      )\n      )\n    {\n      m_LongestMatchWasFound = true;\n      aBackRes = UINT32(-1);\n      return 1;\n    }\n    for(int i = 0; i < kNumRepDistances; i++)\n    {\n      UINT32 aRepLen = m_MatchFinder.GetMatchLen(0 - 1, m_RepDistances[i], kMatchMaxLen);\n      if (aRepLen >= 2 && aRepLen + 1 >= aLenMain)\n      {\n        m_LongestMatchWasFound = true;\n        aBackRes = UINT32(-1);\n        return 1;\n      }\n    }\n    aBackRes = aBackMain + kNumRepDistances; \n    MovePos(aLenMain - 2);\n    return aLenMain;\n  }\n  aBackRes = UINT32(-1);\n  return 1;\n}\n\nHRESULT CEncoder::Flush()\n{\n  m_RangeEncoder.FlushData();\n  return m_RangeEncoder.FlushStream();\n}\n\nHRESULT CEncoder::CodeReal(ISequentialInStream *anInStream,\n      ISequentialOutStream *anOutStream, \n      const UINT64 *anInSize)\n{\n  RETURN_IF_NOT_S_OK(Create());\n  Init(anInStream, anOutStream);\n\n  if (m_MatchFinder.GetNumAvailableBytes() == 0)\n    return Flush();\n\n  if (!m_FastMode)\n  {\n    FillPosSlotPrices();\n    FillDistancesPrices();\n    FillAlignPrices();\n  }\n\n  m_LenEncoder.SetTableSize(m_NumFastBytes);\n  m_LenEncoder.UpdateTables();\n  m_RepMatchLenEncoder.SetTableSize(m_NumFastBytes);\n  m_RepMatchLenEncoder.UpdateTables();\n\n  UINT64 aLastPosSlotFillingPos = 0;\n\n  UINT64 aNowPos64 = 0;\n  ReadMatchDistances();\n  UINT32 aPosState = UINT32(aNowPos64) & m_PosStateMask;\n  m_MainChoiceEncoders[m_State.m_Index][aPosState].Encode(&m_RangeEncoder, kMainChoiceLiteralIndex);\n  m_State.UpdateChar();\n  BYTE aByte = m_MatchFinder.GetIndexByte(0 - m_AdditionalOffset);\n  m_LiteralEncoder.Encode(&m_RangeEncoder, UINT32(aNowPos64), m_PreviousByte, false, 0, aByte);\n  m_PreviousByte = aByte;\n  m_AdditionalOffset--;\n  aNowPos64++;\n  if (m_MatchFinder.GetNumAvailableBytes() == 0)\n    return Flush();\n  while(true)\n  {\n    UINT32 aPos;\n    UINT32 aPosState = UINT32(aNowPos64) & m_PosStateMask;\n\n    UINT32 aLen;\n    if (m_FastMode)\n      aLen = GetOptimumFast(aPos, UINT32(aNowPos64));\n    else\n      aLen = GetOptimum(aPos, UINT32(aNowPos64));\n\n    if(aLen == 1 && aPos == (-1))\n    {\n      m_MainChoiceEncoders[m_State.m_Index][aPosState].Encode(&m_RangeEncoder, kMainChoiceLiteralIndex);\n      m_State.UpdateChar();\n      BYTE aMatchByte;\n      if(m_PeviousIsMatch)\n        aMatchByte = m_MatchFinder.GetIndexByte(0 - m_RepDistances[0] - 1 - m_AdditionalOffset);\n      BYTE aByte = m_MatchFinder.GetIndexByte(0 - m_AdditionalOffset);\n      m_LiteralEncoder.Encode(&m_RangeEncoder, UINT32(aNowPos64), m_PreviousByte, m_PeviousIsMatch, aMatchByte, aByte);\n      m_PreviousByte = aByte;\n      m_PeviousIsMatch = false;\n    }\n    else\n    {\n      m_PeviousIsMatch = true;\n      m_MainChoiceEncoders[m_State.m_Index][aPosState].Encode(&m_RangeEncoder, kMainChoiceMatchIndex);\n      if(aPos < kNumRepDistances)\n      {\n        m_MatchChoiceEncoders[m_State.m_Index].Encode(&m_RangeEncoder, kMatchChoiceRepetitionIndex);\n        if(aPos == 0)\n        {\n          m_MatchRepChoiceEncoders[m_State.m_Index].Encode(&m_RangeEncoder, 0);\n          if(aLen == 1)\n            m_MatchRepShortChoiceEncoders[m_State.m_Index][aPosState].Encode(&m_RangeEncoder, 0);\n          else\n            m_MatchRepShortChoiceEncoders[m_State.m_Index][aPosState].Encode(&m_RangeEncoder, 1);\n        }\n        else\n        {\n          m_MatchRepChoiceEncoders[m_State.m_Index].Encode(&m_RangeEncoder, 1);\n          if (aPos == 1)\n            m_MatchRep1ChoiceEncoders[m_State.m_Index].Encode(&m_RangeEncoder, 0);\n          else\n          {\n            m_MatchRep1ChoiceEncoders[m_State.m_Index].Encode(&m_RangeEncoder, 1);\n            m_MatchRep2ChoiceEncoders[m_State.m_Index].Encode(&m_RangeEncoder, aPos - 2);\n          }\n        }\n        if (aLen == 1)\n          m_State.UpdateShortRep();\n        else\n        {\n          m_RepMatchLenEncoder.Encode(&m_RangeEncoder, aLen - kMatchMinLen, aPosState);\n          m_State.UpdateRep();\n        }\n\n\n        UINT32 aDistance = m_RepDistances[aPos];\n        if (aPos != 0)\n        {\n          for(UINT32 i = aPos; i >= 1; i--)\n            m_RepDistances[i] = m_RepDistances[i - 1];\n          m_RepDistances[0] = aDistance;\n        }\n      }\n      else\n      {\n        m_MatchChoiceEncoders[m_State.m_Index].Encode(&m_RangeEncoder, kMatchChoiceDistanceIndex);\n        m_State.UpdateMatch();\n        m_LenEncoder.Encode(&m_RangeEncoder, aLen - kMatchMinLen, aPosState);\n        aPos -= kNumRepDistances;\n        UINT32 aPosSlot = GetPosSlot(aPos);\n        UINT32 aLenToPosState = GetLenToPosState(aLen);\n        m_PosSlotEncoder[aLenToPosState].Encode(&m_RangeEncoder, aPosSlot);\n        \n        UINT32 aFooterBits = kDistDirectBits[aPosSlot];\n        UINT32 aPosReduced = aPos - kDistStart[aPosSlot];\n        if (aPosSlot >= kStartPosModelIndex)\n        {\n          if (aPosSlot < kEndPosModelIndex)\n            m_PosEncoders[aPosSlot - kStartPosModelIndex].Encode(&m_RangeEncoder, aPosReduced);\n          else\n          {\n            m_RangeEncoder.EncodeDirectBits(aPosReduced >> kNumAlignBits, aFooterBits - kNumAlignBits);\n            m_PosAlignEncoder.Encode(&m_RangeEncoder, aPosReduced & kAlignMask);\n            if (!m_FastMode)\n              if (--m_AlignPriceCount == 0)\n                FillAlignPrices();\n          }\n        }\n        UINT32 aDistance = aPos;\n        for(UINT32 i = kNumRepDistances - 1; i >= 1; i--)\n          m_RepDistances[i] = m_RepDistances[i - 1];\n        m_RepDistances[0] = aDistance;\n      }\n      m_PreviousByte = m_MatchFinder.GetIndexByte(aLen - 1 - m_AdditionalOffset);\n    }\n    m_AdditionalOffset -= aLen;\n    aNowPos64 += aLen;\n    if (!m_FastMode)\n      if (aNowPos64 - aLastPosSlotFillingPos >= (1 << 9))\n      {\n        FillPosSlotPrices();\n        FillDistancesPrices();\n        aLastPosSlotFillingPos = aNowPos64;\n      }\n    if (m_AdditionalOffset == 0 && m_MatchFinder.GetNumAvailableBytes() == 0)\n      return Flush();\n  }\n}\n\nHRESULT CEncoder::Code(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *anInSize)\n{\n  try {\n    return CodeReal(anInStream, anOutStream, anInSize);\n  } catch (HRESULT& e) {\n    return e;\n  } catch (...) {\n    return E_FAIL;\n  }\n}\n  \nvoid CEncoder::FillPosSlotPrices()\n{\n  for (int aLenToPosState = 0; aLenToPosState < kNumLenToPosStates; aLenToPosState++)\n  {\n    UINT32 aPosSlot;\n    for (aPosSlot = 0; aPosSlot < kEndPosModelIndex && aPosSlot < m_DistTableSize; aPosSlot++)\n      m_PosSlotPrices[aLenToPosState][aPosSlot] = m_PosSlotEncoder[aLenToPosState].GetPrice(aPosSlot);\n    for (; aPosSlot < m_DistTableSize; aPosSlot++)\n      m_PosSlotPrices[aLenToPosState][aPosSlot] = m_PosSlotEncoder[aLenToPosState].GetPrice(aPosSlot) + \n          ((kDistDirectBits[aPosSlot] - kNumAlignBits) << kNumBitPriceShiftBits);\n  }\n}\n\nvoid CEncoder::FillDistancesPrices()\n{\n  for (int aLenToPosState = 0; aLenToPosState < kNumLenToPosStates; aLenToPosState++)\n  {\n    UINT32 i;\n    for (i = 0; i < kStartPosModelIndex; i++)\n      m_DistancesPrices[aLenToPosState][i] = m_PosSlotPrices[aLenToPosState][i];\n    for (; i < kNumFullDistances; i++)\n    { \n      UINT32 aPosSlot = GetPosSlot(i);\n      m_DistancesPrices[aLenToPosState][i] = m_PosSlotPrices[aLenToPosState][aPosSlot] +\n          m_PosEncoders[aPosSlot - kStartPosModelIndex].GetPrice(i - kDistStart[aPosSlot]);\n    }\n  }\n}\n\nvoid CEncoder::FillAlignPrices()\n{\n  for (int i = 0; i < kAlignTableSize; i++)\n    m_AlignPrices[i] = m_PosAlignEncoder.GetPrice(i);\n  m_AlignPriceCount = kAlignTableSize;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LZMAEncoder.h",
    "content": "#ifndef __LZARITHMETIC_ENCODER_H\n#define __LZARITHMETIC_ENCODER_H\n\n#include \"Portable.h\"\n#include \"AriPrice.h\"\n#include \"LZMA.h\"\n#include \"LenCoder.h\"\n#include \"LiteralCoder.h\"\n#include \"AriConst.h\"\n\n// NOTE Here is choosen the MatchFinder\n#include \"BinTree2.h\"\n#define MATCH_FINDER NBT2::CMatchFinderBinTree\n\nnamespace NCompress {\nnamespace NLZMA {\n\nstruct COptimal\n{\n  CState State;\n\n  bool Prev1IsChar;\n  bool Prev2;\n\n  UINT32 PosPrev2;\n  UINT32 BackPrev2;     \n\n  UINT32 Price;    \n  UINT32 PosPrev;         // posNext;\n  UINT32 BackPrev;     \n  UINT32 Backs[kNumRepDistances];\n  void MakeAsChar() { BackPrev = UINT32(-1); Prev1IsChar = false; }\n  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\n  bool IsShortRep() { return (BackPrev == 0); }\n};\n\n\nextern BYTE g_FastPos[1024];\ninline UINT32 GetPosSlot(UINT32 aPos)\n{\n  if (aPos < (1 << 10))\n    return g_FastPos[aPos];\n  if (aPos < (1 << 19))\n    return g_FastPos[aPos >> 9] + 18;\n  return g_FastPos[aPos >> 18] + 36;\n}\n\ninline UINT32 GetPosSlot2(UINT32 aPos)\n{\n  if (aPos < (1 << 16))\n    return g_FastPos[aPos >> 6] + 12;\n  if (aPos < (1 << 25))\n    return g_FastPos[aPos >> 15] + 30;\n  return g_FastPos[aPos >> 24] + 48;\n}\n\nconst int kIfinityPrice = 0xFFFFFFF;\n\ntypedef CMyBitEncoder<kNumMoveBitsForMainChoice> CMyBitEncoder2;\n\nconst int kNumOpts = 1 << 12;\n\nclass CEncoder : public CBaseCoder\n{\n  COptimal m_Optimum[kNumOpts];\npublic:\n  MATCH_FINDER m_MatchFinder;\n  CMyRangeEncoder m_RangeEncoder;\nprivate:\n\n  CMyBitEncoder2 m_MainChoiceEncoders[kNumStates][NLength::kNumPosStatesEncodingMax];\n  CMyBitEncoder2 m_MatchChoiceEncoders[kNumStates];\n  CMyBitEncoder2 m_MatchRepChoiceEncoders[kNumStates];\n  CMyBitEncoder2 m_MatchRep1ChoiceEncoders[kNumStates];\n  CMyBitEncoder2 m_MatchRep2ChoiceEncoders[kNumStates];\n  CMyBitEncoder2 m_MatchRepShortChoiceEncoders[kNumStates][NLength::kNumPosStatesEncodingMax];\n\n  CBitTreeEncoder<kNumMoveBitsForPosSlotCoder, kNumPosSlotBits> m_PosSlotEncoder[kNumLenToPosStates];\n\n  CReverseBitTreeEncoder2<kNumMoveBitsForPosCoders> m_PosEncoders[kNumPosModels];\n  CReverseBitTreeEncoder2<kNumMoveBitsForAlignCoders> m_PosAlignEncoder;\n  // CBitTreeEncoder2<kNumMoveBitsForPosCoders> m_PosEncoders[kNumPosModels];\n  // CBitTreeEncoder2<kNumMoveBitsForAlignCoders> m_PosAlignEncoder;\n  \n  NLength::CPriceTableEncoder m_LenEncoder;\n  NLength::CPriceTableEncoder m_RepMatchLenEncoder;\n\n  NLiteral::CEncoder m_LiteralEncoder;\n\n  UINT32 m_MatchDistances[kMatchMaxLen + 1];\n\n  bool m_FastMode;\n  bool m_MaxMode;\n  UINT32 m_NumFastBytes;\n  UINT32 m_LongestMatchLength;    \n\n  UINT32 m_AdditionalOffset;\n\n  UINT32 m_OptimumEndIndex;\n  UINT32 m_OptimumCurrentIndex;\n\n  bool m_LongestMatchWasFound;\n\n  UINT32 m_PosSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\n  \n  UINT32 m_DistancesPrices[kNumLenToPosStates][kNumFullDistances];\n\n  UINT32 m_AlignPrices[kAlignTableSize];\n  UINT32 m_AlignPriceCount;\n\n  UINT32 m_DistTableSize;\n\n  UINT32 m_PosStateBits;\n  UINT32 m_PosStateMask;\n  UINT32 m_LiteralPosStateBits;\n  UINT32 m_LiteralContextBits;\n\n  UINT32 m_DictionarySize;\n\n\n  UINT32 m_DictionarySizePrev;\n  UINT32 m_NumFastBytesPrev;\n\n  \n  UINT32 ReadMatchDistances()\n  {\n    UINT32 aLen = m_MatchFinder.GetLongestMatch(m_MatchDistances);\n    if (aLen == m_NumFastBytes)\n      aLen += m_MatchFinder.GetMatchLen(aLen, m_MatchDistances[aLen], \n          kMatchMaxLen - aLen);\n    m_AdditionalOffset++;\n    HRESULT aResult = m_MatchFinder.MovePos();\n    if (aResult != S_OK)\n      throw aResult;\n    return aLen;\n  }\n\n  void MovePos(UINT32 aNum);\n  UINT32 GetRepLen1Price(CState aState, UINT32 aPosState) const\n  {\n    return m_MatchRepChoiceEncoders[aState.m_Index].GetPrice(0) +\n        m_MatchRepShortChoiceEncoders[aState.m_Index][aPosState].GetPrice(0);\n  }\n  UINT32 GetRepPrice(UINT32 aRepIndex, UINT32 aLen, CState aState, UINT32 aPosState) const\n  {\n    UINT32 aPrice = m_RepMatchLenEncoder.GetPrice(aLen - kMatchMinLen, aPosState);\n    if(aRepIndex == 0)\n    {\n      aPrice += m_MatchRepChoiceEncoders[aState.m_Index].GetPrice(0);\n      aPrice += m_MatchRepShortChoiceEncoders[aState.m_Index][aPosState].GetPrice(1);\n    }\n    else\n    {\n      aPrice += m_MatchRepChoiceEncoders[aState.m_Index].GetPrice(1);\n      if (aRepIndex == 1)\n        aPrice += m_MatchRep1ChoiceEncoders[aState.m_Index].GetPrice(0);\n      else\n      {\n        aPrice += m_MatchRep1ChoiceEncoders[aState.m_Index].GetPrice(1);\n        aPrice += m_MatchRep2ChoiceEncoders[aState.m_Index].GetPrice(aRepIndex - 2);\n      }\n    }\n    return aPrice;\n  }\n  /*\n  UINT32 GetPosLen2Price(UINT32 aPos, UINT32 aPosState) const\n  {\n    if (aPos >= kNumFullDistances)\n      return kIfinityPrice;\n    return m_DistancesPrices[0][aPos] + m_LenEncoder.GetPrice(0, aPosState);\n  }\n  UINT32 GetPosLen3Price(UINT32 aPos, UINT32 aLen, UINT32 aPosState) const\n  {\n    UINT32 aPrice;\n    UINT32 aLenToPosState = GetLenToPosState(aLen);\n    if (aPos < kNumFullDistances)\n      aPrice = m_DistancesPrices[aLenToPosState][aPos];\n    else\n      aPrice = m_PosSlotPrices[aLenToPosState][GetPosSlot2(aPos)] + \n          m_AlignPrices[aPos & kAlignMask];\n    return aPrice + m_LenEncoder.GetPrice(aLen - kMatchMinLen, aPosState);\n  }\n  */\n  UINT32 GetPosLenPrice(UINT32 aPos, UINT32 aLen, UINT32 aPosState) const\n  {\n    if (aLen == 2 && aPos >= 0x80)\n      return kIfinityPrice;\n    UINT32 aPrice;\n    UINT32 aLenToPosState = GetLenToPosState(aLen);\n    if (aPos < kNumFullDistances)\n      aPrice = m_DistancesPrices[aLenToPosState][aPos];\n    else\n      aPrice = m_PosSlotPrices[aLenToPosState][GetPosSlot2(aPos)] + \n          m_AlignPrices[aPos & kAlignMask];\n    return aPrice + m_LenEncoder.GetPrice(aLen - kMatchMinLen, aPosState);\n  }\n\n  UINT32 Backward(UINT32 &aBackRes, UINT32 aCur);\n  UINT32 GetOptimum(UINT32 &aBackRes, UINT32 aPosition);\n  UINT32 GetOptimumFast(UINT32 &aBackRes, UINT32 aPosition);\n\n  void FillPosSlotPrices();\n  void FillDistancesPrices();\n  void FillAlignPrices();\n    \n  HRESULT Flush();\n\n  HRESULT Create();\n\n  HRESULT CodeReal(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *anInSize);\n\n  HRESULT Init(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream);\n\npublic:\n  CEncoder();\n\n  HRESULT SetEncoderAlgorithm(UINT32 A);\n  HRESULT SetEncoderNumFastBytes(UINT32 A);\n  HRESULT SetDictionarySize(UINT32 aDictionarySize);\n  HRESULT SetLiteralProperties(UINT32 aLiteralPosStateBits, UINT32 aLiteralContextBits);\n  HRESULT SetPosBitsProperties(UINT32 aNumPosStateBits);\n  HRESULT Code(ISequentialInStream *anInStream, ISequentialOutStream *anOutStream, const UINT64 *anInSize);\n  HRESULT WriteCoderProperties(ISequentialOutStream *anOutStream);\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LenCoder.cpp",
    "content": "#include \"LenCoder.h\"\n\nusing namespace NCompression;\nusing namespace NArithmetic;\n\nnamespace NLength {\n\nvoid CEncoder::Init()\n{\n  m_Choice.Init();\n  for (UINT32 aPosState = 0; aPosState < m_NumPosStates; aPosState++)\n  {\n    m_LowCoder[aPosState].Init();\n    m_MidCoder[aPosState].Init();\n  }\n  m_Choice2.Init();\n  m_HighCoder.Init();\n}\n\nvoid CEncoder::Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol, UINT32 aPosState)\n{\n  if(aSymbol < kNumLowSymbols)\n  {\n    m_Choice.Encode(aRangeEncoder, 0);\n    m_LowCoder[aPosState].Encode(aRangeEncoder, aSymbol);\n  }\n  else\n  {\n    aSymbol -= kNumLowSymbols;\n    m_Choice.Encode(aRangeEncoder, 1);\n    if(aSymbol < kNumMidSymbols)\n    {\n      m_Choice2.Encode(aRangeEncoder, 0);\n      m_MidCoder[aPosState].Encode(aRangeEncoder, aSymbol);\n    }\n    else\n    {\n      aSymbol -= kNumMidSymbols;\n      m_Choice2.Encode(aRangeEncoder, 1);\n      m_HighCoder.Encode(aRangeEncoder, aSymbol);\n    }\n  }\n}\n\nUINT32 CEncoder::GetPrice(UINT32 aSymbol, UINT32 aPosState) const\n{\n  UINT32 aPrice = 0;\n  if(aSymbol < kNumLowSymbols)\n  {\n    aPrice += m_Choice.GetPrice(0);\n    aPrice += m_LowCoder[aPosState].GetPrice(aSymbol);\n  }\n  else\n  {\n    aSymbol -= kNumLowSymbols;\n    aPrice += m_Choice.GetPrice(1);\n    if(aSymbol < kNumMidSymbols)\n    {\n      aPrice += m_Choice2.GetPrice(0);\n      aPrice += m_MidCoder[aPosState].GetPrice(aSymbol);\n    }\n    else\n    {\n      aSymbol -= kNumMidSymbols;\n      aPrice += m_Choice2.GetPrice(1);\n      aPrice += m_HighCoder.GetPrice(aSymbol);\n    }\n  }\n  return aPrice;\n}\n\n}\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LenCoder.h",
    "content": "#ifndef __LENCODER_H\n#define __LENCODER_H\n\n#include \"BitTreeCoder.h\"\n\nnamespace NLength {\n\nconst int kNumPosStatesBitsMax = 4;\nconst int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\n\n\nconst int kNumPosStatesBitsEncodingMax = 4;\nconst int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\n\n\nconst int kNumMoveBits = 5;\n\nconst int kNumLenBits = 3;\nconst int kNumLowSymbols = 1 << kNumLenBits;\nconst int kNumMidBits = 3;\nconst int kNumMidSymbols = 1 << kNumMidBits;\n\nconst int kNumHighBits = 8;\n\nconst int kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\n\nclass CEncoder\n{\n  CMyBitEncoder<kNumMoveBits> m_Choice;\n  CBitTreeEncoder<kNumMoveBits, kNumLenBits>  m_LowCoder[kNumPosStatesEncodingMax];\n  CMyBitEncoder<kNumMoveBits>  m_Choice2;\n  CBitTreeEncoder<kNumMoveBits, kNumMidBits>  m_MidCoder[kNumPosStatesEncodingMax];\n  CBitTreeEncoder<kNumMoveBits, kNumHighBits>  m_HighCoder;\nprotected:\n  UINT32 m_NumPosStates;\npublic:\n  void Create(UINT32 aNumPosStates)\n    { m_NumPosStates = aNumPosStates; }\n  void Init();\n  void Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol, UINT32 aPosState);\n\n  UINT32 GetPrice(UINT32 aSymbol, UINT32 aPosState) const;\n};\n\nconst int kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\n\nclass CPriceTableEncoder: public CEncoder\n{\n  UINT32 m_Prices[kNumSymbolsTotal][kNumPosStatesEncodingMax];\n  UINT32 m_TableSize;\n  UINT32 m_Counters[kNumPosStatesEncodingMax];\npublic:\n  void SetTableSize(UINT32 aTableSize)\n    { m_TableSize = aTableSize;  }\n  UINT32 GetPrice(UINT32 aSymbol, UINT32 aPosState) const\n    { return m_Prices[aSymbol][aPosState]; }\n  void UpdateTable(UINT32 aPosState)\n  {\n    for (UINT32 aLen = 0; aLen < m_TableSize; aLen++)\n      m_Prices[aLen][aPosState] = CEncoder::GetPrice(aLen , aPosState);\n    m_Counters[aPosState] = m_TableSize;\n  }\n  void UpdateTables()\n  {\n    for (UINT32 aPosState = 0; aPosState < m_NumPosStates; aPosState++)\n      UpdateTable(aPosState);\n  }\n  void Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol, UINT32 aPosState)\n  {\n    CEncoder::Encode(aRangeEncoder, aSymbol, aPosState);\n    if (--m_Counters[aPosState] == 0)\n      UpdateTable(aPosState);\n  }\n};\n\n\nclass CDecoder\n{\n  CMyBitDecoder<kNumMoveBits> m_Choice;\n  CBitTreeDecoder<kNumMoveBits, kNumLenBits>  m_LowCoder[kNumPosStatesMax];\n  CMyBitDecoder<kNumMoveBits> m_Choice2;\n  CBitTreeDecoder<kNumMoveBits, kNumMidBits>  m_MidCoder[kNumPosStatesMax];\n  CBitTreeDecoder<kNumMoveBits, kNumHighBits> m_HighCoder; \n  UINT32 m_NumPosStates;\npublic:\n  void Create(UINT32 aNumPosStates)\n    { m_NumPosStates = aNumPosStates; }\n  void Init()\n  {\n    m_Choice.Init();\n    for (UINT32 aPosState = 0; aPosState < m_NumPosStates; aPosState++)\n    {\n      m_LowCoder[aPosState].Init();\n      m_MidCoder[aPosState].Init();\n    }\n    m_Choice2.Init();\n    m_HighCoder.Init();\n  }\n  UINT32 Decode(CMyRangeDecoder *aRangeDecoder, UINT32 aPosState)\n  {\n    if(m_Choice.Decode(aRangeDecoder) == 0)\n      return m_LowCoder[aPosState].Decode(aRangeDecoder);\n    else\n    {\n      UINT32 aSymbol = kNumLowSymbols;\n      if(m_Choice2.Decode(aRangeDecoder) == 0)\n        aSymbol += m_MidCoder[aPosState].Decode(aRangeDecoder);\n      else\n      {\n        aSymbol += kNumMidSymbols;\n        aSymbol += m_HighCoder.Decode(aRangeDecoder);\n      }\n      return aSymbol;\n    }\n  }\n\n};\n\n}\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LiteralCoder.cpp",
    "content": "#include \"LiteralCoder.h\"\n\nusing namespace NCompression;\nusing namespace NArithmetic;\n\nnamespace NLiteral {\n\nvoid CEncoder2::Init()\n{\n  for (int i = 0; i < 3; i++)\n    for (int j = 1; j < (1 << 8); j++)\n      m_Encoders[i][j].Init();\n}\n\nvoid CEncoder2::Encode(CMyRangeEncoder *aRangeEncoder, \n    bool aMatchMode, BYTE aMatchByte, BYTE aSymbol)\n{\n  UINT32 aContext = 1;\n  bool aSame = true;\n  for (int i = 7; i >= 0; i--)\n  {\n    UINT32 aBit = (aSymbol >> i) & 1;\n    unsigned aState;\n    if (aMatchMode && aSame)\n    {\n      UINT32 aMatchBit = (aMatchByte >> i) & 1;\n      aState = 1 + aMatchBit;\n      aSame = (aMatchBit == aBit);\n    }\n    else\n      aState = 0;\n    m_Encoders[aState][aContext].Encode(aRangeEncoder, aBit);\n    aContext = (aContext << 1) | aBit;\n  }\n}\n\nUINT32 CEncoder2::GetPrice(bool aMatchMode, BYTE aMatchByte, BYTE aSymbol) const\n{\n  UINT32 aPrice = 0;\n  UINT32 aContext = 1;\n  int i = 7;\n  if (aMatchMode)\n  {\n    for (; i >= 0; i--)\n    {\n      UINT32 aMatchBit = (aMatchByte >> i) & 1;\n      UINT32 aBit = (aSymbol >> i) & 1;\n      aPrice += m_Encoders[1 + aMatchBit][aContext].GetPrice(aBit);\n      aContext = (aContext << 1) | aBit;\n      if (aMatchBit != aBit)\n      {\n        i--;\n        break;\n      }\n    }\n  }\n  for (; i >= 0; i--)\n  {\n    UINT32 aBit = (aSymbol >> i) & 1;\n    aPrice += m_Encoders[0][aContext].GetPrice(aBit);\n    aContext = (aContext << 1) | aBit;\n  }\n  return aPrice;\n};\n\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/LiteralCoder.h",
    "content": "#ifndef __LITERALCODER_H\n#define __LITERALCODER_H\n\n#include \"AriBitCoder.h\"\n#include \"RCDefs.h\"\n\nnamespace NLiteral {\n\nconst int kNumMoveBits = 5;\n\nclass CEncoder2\n{\n  CMyBitEncoder<kNumMoveBits> m_Encoders[3][1 << 8];\npublic:\n  void Init();\n  void Encode(CMyRangeEncoder *aRangeEncoder, bool aMatchMode, BYTE aMatchByte, BYTE aSymbol);\n  UINT32 GetPrice(bool aMatchMode, BYTE aMatchByte, BYTE aSymbol) const;\n};\n\nclass CDecoder2\n{\n  CMyBitDecoder<kNumMoveBits> m_Decoders[3][1 << 8];\npublic:\n  void Init()\n  {\n    for (int i = 0; i < 3; i++)\n      for (int j = 1; j < (1 << 8); j++)\n        m_Decoders[i][j].Init();\n  }\n\n  BYTE DecodeNormal(CMyRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aSymbol = 1;\n    RC_INIT_VAR\n    do\n    {\n      // aSymbol = (aSymbol << 1) | m_Decoders[0][aSymbol].Decode(aRangeDecoder);\n      RC_GETBIT(kNumMoveBits, m_Decoders[0][aSymbol].m_Probability, aSymbol)\n    }\n    while (aSymbol < 0x100);\n    RC_FLUSH_VAR\n    return aSymbol;\n  }\n\n  BYTE DecodeWithMatchByte(CMyRangeDecoder *aRangeDecoder, BYTE aMatchByte)\n  {\n    UINT32 aSymbol = 1;\n    RC_INIT_VAR\n    do\n    {\n      UINT32 aMatchBit = (aMatchByte >> 7) & 1;\n      aMatchByte <<= 1;\n      // UINT32 aBit = m_Decoders[1 + aMatchBit][aSymbol].Decode(aRangeDecoder);\n      // aSymbol = (aSymbol << 1) | aBit;\n      UINT32 aBit;\n      RC_GETBIT2(kNumMoveBits, m_Decoders[1 + aMatchBit][aSymbol].m_Probability, aSymbol, \n          aBit = 0, aBit = 1)\n      if (aMatchBit != aBit)\n      {\n        while (aSymbol < 0x100)\n        {\n          // aSymbol = (aSymbol << 1) | m_Decoders[0][aSymbol].Decode(aRangeDecoder);\n          RC_GETBIT(kNumMoveBits, m_Decoders[0][aSymbol].m_Probability, aSymbol)\n        }\n        break;\n      }\n    }\n    while (aSymbol < 0x100);\n    RC_FLUSH_VAR\n    return aSymbol;\n  }\n};\n\n/*\nconst UINT32 kNumPrevByteBits = 1;\nconst UINT32 kNumPrevByteStates =  (1 << kNumPrevByteBits);\n\ninline UINT32 GetLiteralState(BYTE aPrevByte)\n  { return (aPrevByte >> (8 - kNumPrevByteBits)); }\n*/\n\nclass CEncoder\n{\n  CEncoder2 *m_Coders;\n  UINT32 m_NumPrevBits;\n  UINT32 m_NumPosBits;\n  UINT32 m_PosMask;\npublic:\n  CEncoder(): m_Coders(0) {}\n  ~CEncoder()  { Free(); }\n  void Free()\n  { \n    delete []m_Coders;\n    m_Coders = 0;\n  }\n  void Create(UINT32 aNumPosBits, UINT32 aNumPrevBits)\n  {\n    Free();\n    m_NumPosBits = aNumPosBits;\n    m_PosMask = (1 << aNumPosBits) - 1;\n    m_NumPrevBits = aNumPrevBits;\n    UINT32 aNumStates = 1 << (m_NumPrevBits + m_NumPosBits);\n    m_Coders = new CEncoder2[aNumStates];\n  }\n  void Init()\n  {\n    UINT32 aNumStates = 1 << (m_NumPrevBits + m_NumPosBits);\n    for (UINT32 i = 0; i < aNumStates; i++)\n      m_Coders[i].Init();\n  }\n  UINT32 GetState(UINT32 aPos, BYTE aPrevByte) const\n    { return ((aPos & m_PosMask) << m_NumPrevBits) + (aPrevByte >> (8 - m_NumPrevBits)); }\n  void Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aPos, BYTE aPrevByte, \n      bool aMatchMode, BYTE aMatchByte, BYTE aSymbol)\n    { m_Coders[GetState(aPos, aPrevByte)].Encode(aRangeEncoder, aMatchMode, \n          aMatchByte, aSymbol); }\n  UINT32 GetPrice(UINT32 aPos, BYTE aPrevByte, bool aMatchMode, BYTE aMatchByte, BYTE aSymbol) const\n    { return m_Coders[GetState(aPos, aPrevByte)].GetPrice(aMatchMode, aMatchByte, aSymbol); }\n};\n\nclass CDecoder\n{\n  CDecoder2 *m_Coders;\n  UINT32 m_NumPrevBits;\n  UINT32 m_NumPosBits;\n  UINT32 m_PosMask;\npublic:\n  CDecoder(): m_Coders(0) {}\n  ~CDecoder()  { Free(); }\n  void Free()\n  { \n    delete []m_Coders;\n    m_Coders = 0;\n  }\n  void Create(UINT32 aNumPosBits, UINT32 aNumPrevBits)\n  {\n    Free();\n    m_NumPosBits = aNumPosBits;\n    m_PosMask = (1 << aNumPosBits) - 1;\n    m_NumPrevBits = aNumPrevBits;\n    UINT32 aNumStates = 1 << (m_NumPrevBits + m_NumPosBits);\n    m_Coders = new CDecoder2[aNumStates];\n  }\n  void Init()\n  {\n    UINT32 aNumStates = 1 << (m_NumPrevBits + m_NumPosBits);\n    for (UINT32 i = 0; i < aNumStates; i++)\n      m_Coders[i].Init();\n  }\n  UINT32 GetState(UINT32 aPos, BYTE aPrevByte) const\n    { return ((aPos & m_PosMask) << m_NumPrevBits) + (aPrevByte >> (8 - m_NumPrevBits)); }\n  BYTE DecodeNormal(CMyRangeDecoder *aRangeDecoder, UINT32 aPos, BYTE aPrevByte)\n    { return m_Coders[GetState(aPos, aPrevByte)].DecodeNormal(aRangeDecoder); }\n  BYTE DecodeWithMatchByte(CMyRangeDecoder *aRangeDecoder, UINT32 aPos, BYTE aPrevByte, BYTE aMatchByte)\n    { return m_Coders[GetState(aPos, aPrevByte)].DecodeWithMatchByte(aRangeDecoder, aMatchByte); }\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/OutByte.cpp",
    "content": "#include \"OutByte.h\"\n\nnamespace NStream {\n\nCOutByte::COutByte(UINT32 aBufferSize):\n  m_BufferSize(aBufferSize)\n{\n  m_Buffer = new BYTE[m_BufferSize];\n}\n\nCOutByte::~COutByte()\n{\n  delete []m_Buffer;\n}\n\nvoid COutByte::Init(ISequentialOutStream *aStream)\n{\n  m_Stream = aStream;\n  m_ProcessedSize = 0;\n  m_Pos = 0;\n}\n\nHRESULT COutByte::Flush()\n{\n  if (m_Pos == 0)\n    return S_OK;\n  UINT32 aProcessedSize;\n  HRESULT aResult = m_Stream->Write(m_Buffer, m_Pos, &aProcessedSize);\n  if (aResult != S_OK)\n    return aResult;\n  if (m_Pos != aProcessedSize)\n    return E_FAIL;\n  m_ProcessedSize += aProcessedSize;\n  m_Pos = 0;\n  return S_OK;\n}\n\nvoid COutByte::WriteBlock()\n{\n  HRESULT aResult = Flush();\n  if (aResult != S_OK)\n    throw aResult;\n}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/OutByte.h",
    "content": "#ifndef __STREAM_OUTBYTE_H\n#define __STREAM_OUTBYTE_H\n\n#include \"Portable.h\"\n#include \"IInOutStreams.h\"\n\nnamespace NStream {\n\nclass COutByte\n{\n  BYTE *m_Buffer;\n  UINT32 m_Pos;\n  UINT32 m_BufferSize;\n  ISequentialOutStream* m_Stream;\n  UINT64 m_ProcessedSize;\n\n  void WriteBlock();\npublic:\n  COutByte(UINT32 aBufferSize = (1 << 20));\n  ~COutByte();\n\n  void Init(ISequentialOutStream *aStream);\n  HRESULT Flush();\n\n  void WriteByte(BYTE aByte)\n  {\n    m_Buffer[m_Pos++] = aByte;\n    if(m_Pos >= m_BufferSize)\n      WriteBlock();\n  }\n  void WriteBytes(const void *aBytes, UINT32 aSize)\n  {\n    for (UINT32 i = 0; i < aSize; i++)\n      WriteByte(((const BYTE *)aBytes)[i]);\n  }\n\n  UINT64 GetProcessedSize() const { return m_ProcessedSize + m_Pos; }\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/Portable.h",
    "content": "#ifndef __PORTABLE_H\n#define __PORTABLE_H\n\n#include <string.h>\n\ntypedef signed char INT8;\ntypedef unsigned char UINT8;\ntypedef short INT16;\ntypedef unsigned short UINT16;\ntypedef long INT32;\ntypedef unsigned long UINT32;\n#if GNU\ntypedef long long INT64;\ntypedef unsigned long long UINT64;\n#else\ntypedef __int64 INT64;\ntypedef unsigned __int64 UINT64;\n#endif\n\ntypedef UINT8 BYTE;\ntypedef UINT16 WORD;\ntypedef UINT32 DWORD;\n\ntypedef unsigned UINT_PTR;\n\ntypedef int BOOL;\n#define FALSE 0\n#define TRUE 1\n\n#define HRESULT int\n#define S_OK 0\n#define E_INVALIDARG -1\n#define E_OUTOFMEMORY -2\n#define E_FAIL -3\n#define E_INTERNAL_ERROR -4\n#define E_INVALIDDATA -5\n\ntemplate <class T> inline T MyMin(T a, T b) {\n\treturn a < b ? a : b;\n}\n\ntemplate <class T> inline T MyMax(T a, T b) {\n\treturn a > b ? a : b;\n}\n\n#define RETURN_IF_NOT_S_OK(x) { HRESULT __aResult_ = (x); if(__aResult_ != S_OK) return __aResult_; }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/RCDefs.h",
    "content": "#ifndef __RCDEFS_H\n#define __RCDEFS_H\n\n#include \"AriBitCoder.h\"\n#include \"AriConst.h\"\n\n#define RC_INIT_VAR                            \\\n  UINT32 aRange = aRangeDecoder->m_Range;      \\\n  UINT32 aCode = aRangeDecoder->m_Code;        \n\n#define RC_FLUSH_VAR                          \\\n  aRangeDecoder->m_Range = aRange;            \\\n  aRangeDecoder->m_Code = aCode;\n\n#define RC_NORMALIZE                                    \\\n    if (aRange < NCompression::NArithmetic::kTopValue)               \\\n    {                                                              \\\n      aCode = (aCode << 8) | aRangeDecoder->m_Stream.ReadByte();   \\\n      aRange <<= 8; }\n\n#define RC_GETBIT2(aNumMoveBits, aProb, aModelIndex, Action0, Action1)                        \\\n    {UINT32 aNewBound = (aRange >> NCompression::NArithmetic::kNumBitModelTotalBits) * aProb; \\\n    if (aCode < aNewBound)                               \\\n    {                                                             \\\n      Action0;                                                    \\\n      aRange = aNewBound;                                         \\\n      aProb += (NCompression::NArithmetic::kBitModelTotal - aProb) >> aNumMoveBits;          \\\n      aModelIndex <<= 1;                                          \\\n    }                                                             \\\n    else                                                          \\\n    {                                                             \\\n      Action1;                                                    \\\n      aRange -= aNewBound;                                        \\\n      aCode -= aNewBound;                                          \\\n      aProb -= (aProb) >> aNumMoveBits;                           \\\n      aModelIndex = (aModelIndex << 1) + 1;                       \\\n    }}                                                             \\\n    RC_NORMALIZE\n\n#define RC_GETBIT(aNumMoveBits, aProb, aModelIndex) RC_GETBIT2(aNumMoveBits, aProb, aModelIndex, ; , ;)               \n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/RangeCoder.h",
    "content": "#ifndef __COMPRESSION_RANGECODER_H\n#define __COMPRESSION_RANGECODER_H\n\n#include \"InByte.h\"\n#include \"OutByte.h\"\n\nnamespace NCompression {\nnamespace NArithmetic {\n\nconst UINT32 kNumTopBits = 24;\nconst UINT32 kTopValue = (1 << kNumTopBits);\n\nclass CRangeEncoder\n{\n  NStream::COutByte m_Stream;\n  UINT64 m_Low;\n  UINT32 m_Range;\n  UINT32 m_FFNum;\n  BYTE m_Cache;\n\npublic:\n  void Init(ISequentialOutStream *aStream)\n  {\n    m_Stream.Init(aStream);\n    m_Low = 0;\n    m_Range = UINT32(-1);\n    m_FFNum = 0;\n    m_Cache = 0;\n  }\n\n  void FlushData()\n  {\n    // m_Low += 1; \n    for(int i = 0; i < 5; i++)\n      ShiftLow();\n  }\n\n  HRESULT FlushStream()\n    { return m_Stream.Flush();  }\n\n  void Encode(UINT32 aStart, UINT32 aSize, UINT32 aTotal)\n  {\n    m_Low += aStart * (m_Range /= aTotal);\n    m_Range *= aSize;\n    while (m_Range < kTopValue)\n    {\n      m_Range <<= 8;\n      ShiftLow();\n    }\n  }\n\n  /*\n  void EncodeDirectBitsDiv(UINT32 aValue, UINT32 aNumTotalBits)\n  {\n    m_Low += aValue * (m_Range >>= aNumTotalBits);\n    Normalize();\n  }\n  \n  void EncodeDirectBitsDiv2(UINT32 aValue, UINT32 aNumTotalBits)\n  {\n    if (aNumTotalBits <= kNumBottomBits)\n      EncodeDirectBitsDiv(aValue, aNumTotalBits);\n    else\n    {\n      EncodeDirectBitsDiv(aValue >> kNumBottomBits, (aNumTotalBits - kNumBottomBits));\n      EncodeDirectBitsDiv(aValue & ((1 << kBottomValueBits) - 1), kNumBottomBits);\n    }\n  }\n  */\n  void ShiftLow()\n  {\n    if (m_Low < (UINT32)0xFF000000 || UINT32(m_Low >> 32) == 1) \n    {\n      m_Stream.WriteByte(m_Cache + BYTE(m_Low >> 32));            \n      for (;m_FFNum != 0; m_FFNum--) \n        m_Stream.WriteByte(0xFF + BYTE(m_Low >> 32));\n      m_Cache = BYTE(UINT32(m_Low) >> 24);                      \n    } \n    else \n      m_FFNum++;                               \n    m_Low = UINT32(m_Low) << 8;                           \n  }\n  \n  void EncodeDirectBits(UINT32 aValue, UINT32 aNumTotalBits)\n  {\n    for (int i = aNumTotalBits - 1; i >= 0; i--)\n    {\n      m_Range >>= 1;\n      if (((aValue >> i) & 1) == 1)\n        m_Low += m_Range;\n      if (m_Range < kTopValue)\n      {\n        m_Range <<= 8;\n        ShiftLow();\n      }\n    }\n  }\n\n  void EncodeBit(UINT32 aSize0, UINT32 aNumTotalBits, UINT32 aSymbol)\n  {\n    UINT32 aNewBound = (m_Range >> aNumTotalBits) * aSize0;\n    if (aSymbol == 0)\n      m_Range = aNewBound;\n    else\n    {\n      m_Low += aNewBound;\n      m_Range -= aNewBound;\n    }\n    while (m_Range < kTopValue)\n    {\n      m_Range <<= 8;\n      ShiftLow();\n    }\n  }\n\n  UINT64 GetProcessedSize() {  return m_Stream.GetProcessedSize() + m_FFNum; }\n};\n\nclass CRangeDecoder\n{\npublic:\n  NStream::CInByte m_Stream;\n  UINT32 m_Range;\n  UINT32 m_Code;\n  UINT32 m_Word;\n  void Normalize()\n  {\n    while (m_Range < kTopValue)\n    {\n      m_Code = (m_Code << 8) | m_Stream.ReadByte();\n      m_Range <<= 8;\n    }\n  }\n  \n  void Init(ISequentialInStream *aStream)\n  {\n    m_Stream.Init(aStream);\n    m_Code = 0;\n    m_Range = UINT32(-1);\n    for(int i = 0; i < 5; i++)\n      m_Code = (m_Code << 8) | m_Stream.ReadByte();\n  }\n\n  UINT32 GetThreshold(UINT32 aTotal)\n  {\n    return (m_Code) / ( m_Range /= aTotal);\n  }\n\n  void Decode(UINT32 aStart, UINT32 aSize, UINT32 aTotal)\n  {\n    m_Code -= aStart * m_Range;\n    m_Range *= aSize;\n    Normalize();\n  }\n\n  /*\n  UINT32 DecodeDirectBitsDiv(UINT32 aNumTotalBits)\n  {\n    m_Range >>= aNumTotalBits;\n    UINT32 aThreshold = m_Code / m_Range;\n    m_Code -= aThreshold * m_Range;\n    \n    Normalize();\n    return aThreshold;\n  }\n\n  UINT32 DecodeDirectBitsDiv2(UINT32 aNumTotalBits)\n  {\n    if (aNumTotalBits <= kNumBottomBits)\n      return DecodeDirectBitsDiv(aNumTotalBits);\n    UINT32 aResult = DecodeDirectBitsDiv(aNumTotalBits - kNumBottomBits) << kNumBottomBits;\n    return (aResult | DecodeDirectBitsDiv(kNumBottomBits));\n  }\n  */\n\n  UINT32 DecodeDirectBits(UINT32 aNumTotalBits)\n  {\n    UINT32 aRange = m_Range;\n    UINT32 aCode = m_Code;        \n    UINT32 aResult = 0;\n    for (UINT32 i = aNumTotalBits; i > 0; i--)\n    {\n      aRange >>= 1;\n      /*\n      aResult <<= 1;\n      if (aCode >= aRange)\n      {\n        aCode -= aRange;\n        aResult |= 1;\n      }\n      */\n      UINT32 t = (aCode - aRange) >> 31;\n      aCode -= aRange & (t - 1);\n      // aRange = aRangeTmp + ((aRange & 1) & (1 - t));\n      aResult = (aResult << 1) | (1 - t);\n\n      if (aRange < kTopValue)\n      {\n        aCode = (aCode << 8) | m_Stream.ReadByte();\n        aRange <<= 8; \n      }\n    }\n    m_Range = aRange;\n    m_Code = aCode;\n    return aResult;\n  }\n\n  UINT32 DecodeBit(UINT32 aSize0, UINT32 aNumTotalBits)\n  {\n    UINT32 aNewBound = (m_Range >> aNumTotalBits) * aSize0;\n    UINT32 aSymbol;\n    if (m_Code < aNewBound)\n    {\n      aSymbol = 0;\n      m_Range = aNewBound;\n    }\n    else\n    {\n      aSymbol = 1;\n      m_Code -= aNewBound;\n      m_Range -= aNewBound;\n    }\n    Normalize();\n    return aSymbol;\n  }\n\n  UINT64 GetProcessedSize() {return m_Stream.GetProcessedSize(); }\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/StdAfx.cpp",
    "content": "// stdafx.cpp : source file that includes just the standard includes\n//\tProgramStore.pch will be the pre-compiled header\n//\tstdafx.obj will contain the pre-compiled type information\n\n#include \"StdAfx.h\"\n\n// TODO: reference any additional headers you need in STDAFX.H\n// and not in this file\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/StdAfx.h",
    "content": "// stdafx.h : include file for standard system include files,\n//  or project specific include files that are used frequently, but\n//      are changed infrequently\n//\n\n#if !defined(AFX_STDAFX_H__FF26AFB2_1227_11D4_A62F_00C04F69DA2B__INCLUDED_)\n#define AFX_STDAFX_H__FF26AFB2_1227_11D4_A62F_00C04F69DA2B__INCLUDED_\n\n#if _MSC_VER > 1000\n#pragma once\n#endif // _MSC_VER > 1000\n\n#define WIN32_LEAN_AND_MEAN\t\t// Exclude rarely-used stuff from Windows headers\n\n#include <stdio.h>\n\n// TODO: reference additional headers your program requires here\n\n//{{AFX_INSERT_LOCATION}}\n// Microsoft Visual C++ will insert additional declarations immediately before the previous line.\n\n#endif // !defined(AFX_STDAFX_H__FF26AFB2_1227_11D4_A62F_00C04F69DA2B__INCLUDED_)\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/WindowIn.cpp",
    "content": "#include \"Portable.h\"\n#include \"WindowIn.h\"\n\nnamespace NStream {\nnamespace NWindow {\n\nCIn::CIn():\n  m_BufferBase(0)\n{}\n\nvoid CIn::Free()\n{\n  delete []m_BufferBase;\n  m_BufferBase = 0;\n}\n\nvoid CIn::Create(UINT32 aKeepSizeBefore, UINT32 aKeepSizeAfter, UINT32 aKeepSizeReserv)\n{\n  m_KeepSizeBefore = aKeepSizeBefore;\n  m_KeepSizeAfter = aKeepSizeAfter;\n  m_KeepSizeReserv = aKeepSizeReserv;\n  m_BlockSize = aKeepSizeBefore + aKeepSizeAfter + aKeepSizeReserv;\n  Free();\n  m_BufferBase = new BYTE[m_BlockSize];\n  m_PointerToLastSafePosition = m_BufferBase + m_BlockSize - aKeepSizeAfter;\n}\n\nCIn::~CIn()\n{\n  Free();\n}\n\nHRESULT CIn::Init(ISequentialInStream *aStream)\n{\n  m_Stream = aStream;\n  m_Buffer = m_BufferBase;\n  m_Pos = 0;\n  m_StreamPos = 0;\n  m_StreamEndWasReached = false;\n  return ReadBlock();\n}\n\n///////////////////////////////////////////\n// ReadBlock\n\n// In State:\n//   (m_Buffer + m_StreamPos) <= (m_BufferBase + m_BlockSize)\n// Out State:\n//   m_PosLimit <= m_BlockSize - m_KeepSizeAfter;\n//   if(m_StreamEndWasReached == false):\n//     m_StreamPos >= m_Pos + m_KeepSizeAfter\n//     m_PosLimit = m_StreamPos - m_KeepSizeAfter;\n//   else\n//          \n  \nHRESULT CIn::ReadBlock()\n{\n  if(m_StreamEndWasReached)\n    return S_OK;\n  while(true)\n  {\n    UINT32 aSize = (m_BufferBase + m_BlockSize) - (m_Buffer + m_StreamPos);\n    if(aSize == 0)\n      return S_OK;\n    UINT32 aNumReadBytes;\n    RETURN_IF_NOT_S_OK(m_Stream->Read(m_Buffer + m_StreamPos,\n        aSize, &aNumReadBytes));\n    if(aNumReadBytes == 0)\n    {\n      m_PosLimit = m_StreamPos;\n      const BYTE *aPointerToPostion = m_Buffer + m_PosLimit;\n      if(aPointerToPostion > m_PointerToLastSafePosition)\n        m_PosLimit = m_PointerToLastSafePosition - m_Buffer;\n      m_StreamEndWasReached = true;\n      return S_OK;\n    }\n    m_StreamPos += aNumReadBytes;\n    if(m_StreamPos >= m_Pos + m_KeepSizeAfter)\n    {\n      m_PosLimit = m_StreamPos - m_KeepSizeAfter;\n      return S_OK;\n    }\n  }\n}\n\nvoid CIn::MoveBlock()\n{\n  BeforeMoveBlock();\n  UINT32 anOffset = (m_Buffer + m_Pos - m_KeepSizeBefore) - m_BufferBase;\n  UINT32 aNumBytes = (m_Buffer + m_StreamPos) -  (m_BufferBase + anOffset);\n  memmove(m_BufferBase, m_BufferBase + anOffset, aNumBytes);\n  m_Buffer -= anOffset;\n  AfterMoveBlock();\n}\n\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/WindowIn.h",
    "content": "#ifndef __STREAM_WINDOWIN_H\n#define __STREAM_WINDOWIN_H\n\n#include \"IInOutStreams.h\"\n\nnamespace NStream {\nnamespace NWindow {\n\nclass CIn\n{\n  BYTE  *m_BufferBase; // pointer to buffer with data\n  ISequentialInStream* m_Stream;\n  UINT32 m_PosLimit;  // offset (from m_Buffer) of first byte when new block reading must be done\n  bool m_StreamEndWasReached; // if (true) then m_StreamPos shows real end of stream\n\n  const BYTE *m_PointerToLastSafePosition;\n\nprotected:\n  BYTE  *m_Buffer;   // Pointer to virtual Buffer begin\n  UINT32 m_BlockSize;  // Size of Allocated memory block\n  UINT32 m_Pos;             // offset (from m_Buffer) of curent byte\n  UINT32 m_KeepSizeBefore;  // how many BYTEs must be kept in buffer before m_Pos\n  UINT32 m_KeepSizeAfter;   // how many BYTEs must be kept buffer after m_Pos\n  UINT32 m_KeepSizeReserv;  // how many BYTEs must be kept as reserv\n  UINT32 m_StreamPos;   // offset (from m_Buffer) of first not read byte from Stream\n\n  virtual void BeforeMoveBlock() {};\n  virtual void AfterMoveBlock() {};\n  void MoveBlock();\n  virtual HRESULT ReadBlock();\n  void Free();\npublic:\n  CIn();\n  void Create(UINT32 aKeepSizeBefore, UINT32 aKeepSizeAfter, \n      UINT32 aKeepSizeReserv = (1<<17));\n  virtual ~CIn();\n\n  HRESULT Init(ISequentialInStream *aStream);\n\n  BYTE *GetBuffer() const { return m_Buffer; }\n\n  const BYTE *GetPointerToCurrentPos() const { return m_Buffer + m_Pos; }\n\n  HRESULT MovePos()\n  {\n    m_Pos++;\n    if (m_Pos > m_PosLimit)\n    {\n      const BYTE *aPointerToPostion = m_Buffer + m_Pos;\n      if(aPointerToPostion > m_PointerToLastSafePosition)\n        MoveBlock();\n      return ReadBlock();\n    }\n    else\n      return S_OK;\n  }\n  // BYTE GetCurrentByte()const;\n  BYTE GetIndexByte(UINT32 anIndex)const\n    {  return m_Buffer[m_Pos + anIndex]; }\n\n  // UINT32 GetCurPos()const { return m_Pos;};\n  // BYTE *GetBufferBeg()const { return m_Buffer;};\n\n  // aIndex + aLimit have not to exceed m_KeepSizeAfter;\n  UINT32 GetMatchLen(UINT32 aIndex, UINT32 aBack, UINT32 aLimit) const\n  {  \n    if(m_StreamEndWasReached)\n      if ((m_Pos + aIndex) + aLimit > m_StreamPos)\n        aLimit = m_StreamPos - (m_Pos + aIndex);\n      aBack++;\n      BYTE *pby = m_Buffer + m_Pos + aIndex;\n      UINT32 i;\n      for(i = 0; i < aLimit && pby[i] == pby[i - aBack]; i++);\n      return i;\n  }\n\n  UINT32 GetNumAvailableBytes() const { return m_StreamPos - m_Pos; }\n\n  void ReduceOffsets(UINT32 aSubValue)\n  {\n    m_Buffer += aSubValue;\n    m_PosLimit -= aSubValue;\n    m_Pos -= aSubValue;\n    m_StreamPos -= aSubValue;\n  }\n\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/WindowOut.cpp",
    "content": "#include \"WindowOut.h\"\n\nnamespace NStream {\nnamespace NWindow {\n\nvoid COut::Create(UINT32 aKeepSizeBefore, UINT32 aKeepSizeAfter, UINT32 aKeepSizeReserv)\n{\n  m_Pos = 0;\n  m_PosLimit = aKeepSizeReserv + aKeepSizeBefore;\n  m_KeepSizeBefore = aKeepSizeBefore;\n  m_KeepSizeAfter = aKeepSizeAfter;\n  m_KeepSizeReserv = aKeepSizeReserv;\n  m_StreamPos = 0;\n  m_MoveFrom = m_KeepSizeReserv;\n  m_WindowSize = aKeepSizeBefore;\n  UINT32 aBlockSize = m_KeepSizeBefore + m_KeepSizeAfter + m_KeepSizeReserv;\n  delete []m_Buffer;\n  m_Buffer = new BYTE[aBlockSize];\n}\n\nCOut::~COut()\n{\n  delete []m_Buffer;\n}\n\nvoid COut::SetWindowSize(UINT32 aWindowSize)\n{\n  m_WindowSize = aWindowSize;\n  m_MoveFrom = m_KeepSizeReserv + m_KeepSizeBefore - aWindowSize;\n}\n\nvoid COut::Init(ISequentialOutStream *aStream, bool aSolid)\n{\n  m_Stream = aStream;\n\n  if(aSolid)\n    m_StreamPos = m_Pos;\n  else\n  {\n    m_Pos = 0;\n    m_PosLimit = m_KeepSizeReserv + m_KeepSizeBefore;\n    m_StreamPos = 0;\n  }\n}\n\nHRESULT COut::Flush()\n{\n  UINT32 aSize = m_Pos - m_StreamPos;\n  if(aSize == 0)\n    return S_OK;\n  UINT32 aProcessedSize;\n  HRESULT aResult = m_Stream->Write(m_Buffer + m_StreamPos, aSize, &aProcessedSize);\n  if (aResult != S_OK)\n    return aResult;\n  if (aSize != aProcessedSize)\n    return E_FAIL;\n  m_StreamPos = m_Pos;\n  return S_OK;\n}\n\nvoid COut::MoveBlockBackward()\n{\n  HRESULT aResult = Flush();\n  if (aResult != S_OK)\n    throw aResult;\n  memmove(m_Buffer, m_Buffer + m_MoveFrom, m_WindowSize + m_KeepSizeAfter);\n  m_Pos -= m_MoveFrom;\n  m_StreamPos -= m_MoveFrom;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/WindowOut.h",
    "content": "#ifndef __STREAM_WINDOWOUT_H\n#define __STREAM_WINDOWOUT_H\n\n#include \"IInOutStreams.h\"\n\nnamespace NStream {\nnamespace NWindow {\n\n// m_KeepSizeBefore: how mach BYTEs must be in buffer before m_Pos;\n// m_KeepSizeAfter: how mach BYTEs must be in buffer after m_Pos;\n// m_KeepSizeReserv: how mach BYTEs must be in buffer for Moving Reserv; \n//                    must be >= aKeepSizeAfter; // test it\n\nclass COut\n{\n  BYTE  *m_Buffer;\n  UINT32 m_Pos;\n  UINT32 m_PosLimit;\n  UINT32 m_KeepSizeBefore;\n  UINT32 m_KeepSizeAfter;\n  UINT32 m_KeepSizeReserv;\n  UINT32 m_StreamPos;\n\n  UINT32 m_WindowSize;\n  UINT32 m_MoveFrom;\n\n  ISequentialOutStream *m_Stream;\n\n  virtual void MoveBlockBackward();\npublic:\n  COut(): m_Buffer(0), m_Stream(0) {}\n  virtual ~COut();\n  void Create(UINT32 aKeepSizeBefore,\n      UINT32 aKeepSizeAfter, UINT32 aKeepSizeReserv = (1<<17));\n  void SetWindowSize(UINT32 aWindowSize);\n\n  void Init(ISequentialOutStream *aStream, bool aSolid = false);\n  HRESULT Flush();\n  \n  UINT32 GetCurPos() const { return m_Pos; }\n  const BYTE *GetPointerToCurrentPos() const { return m_Buffer + m_Pos;};\n\n  void CopyBackBlock(UINT32 aDistance, UINT32 aLen)\n  {\n    if (m_Pos >= m_PosLimit)\n      MoveBlockBackward();  \n    BYTE *p = m_Buffer + m_Pos;\n    aDistance++;\n    for(UINT32 i = 0; i < aLen; i++)\n      p[i] = p[i - aDistance];\n    m_Pos += aLen;\n  }\n\n  void PutOneByte(BYTE aByte)\n  {\n    if (m_Pos >= m_PosLimit)\n      MoveBlockBackward();  \n    m_Buffer[m_Pos++] = aByte;\n  }\n\n  BYTE GetOneByte(UINT32 anIndex) const\n  {\n    return m_Buffer[m_Pos + anIndex];\n  }\n\n  BYTE *GetBuffer() const { return m_Buffer; }\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/compress/lzDecomp.cpp",
    "content": "#include \"stdio.h\"\n#include \"LZMADecoder.h\"\n\n//static LzmaDecoder cc;\nISequentialInStream  in_stream;\nISequentialOutStream out_stream;\nint decompress_lzma_7z( unsigned char* in_data, \n                        unsigned in_size, \n                        unsigned char* out_data, \n                        unsigned out_size) {\n//\t\tLzmaDecoder cc;\n        int RC;\n\t\tUINT64 in_size_l  = in_size;\n\t\tUINT64 out_size_l = out_size;\n\n\n        InStreamInit(in_data, in_size);\n\n\t\tOutStreamInit((char *)out_data, out_size);\n\n        LzmaDecoderConstructor(&cc);\n\n        if ((RC = LzmaDecoderReadCoderProperties(&cc)) != S_OK)\n        {\n\t\t\treturn RC;\n        }\n\n\t\tif (LzmaDecoderCode(&cc, &in_size_l, &out_size_l) != S_OK)\n        {\n\t\t\treturn -2;\n        }\n\n\t\tif (out_stream.size != out_size)\n        {\n\t\t\treturn -3;\n        }\n\n        if ( out_stream.overflow )\n        {\n            return -4;\n        }\n\nprintf( \"\\nDecompressed size: %d\\n\", out_stream.total );\n\t\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/7z.h",
    "content": "#ifndef __7Z_H\n#define __7Z_H\n\n#if defined __cplusplus\nextern \"C\"\n{\n#endif\n\nint decompress_lzma_7z(unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned out_size);\n\n#if defined __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/7zlzma.c",
    "content": "#include \"7z.h\"\n\n#ifdef _HOST_TOOL\n#include \"stdio.h\"\n#endif\n\n#include \"LZMADecoder.h\"\n\n\nstatic LzmaDecoder   cc;\nISequentialInStream  in_stream;\nISequentialOutStream out_stream;\nint decompress_lzma_7z( unsigned char* in_data, \n                        unsigned in_size, \n                        unsigned char* out_data, \n                        unsigned out_size) {\n//\t\tLzmaDecoder cc;\n        int RC;\n\tUINT64 in_size_l  = in_size;\n\tUINT64 out_size_l = out_size;\n\n\n        InStreamInit(in_data, in_size);\n\n\tOutStreamInit((char *)out_data, out_size);\n\n        LzmaDecoderConstructor(&cc);\n\n        if ((RC = LzmaDecoderReadCoderProperties(&cc)) != S_OK)\n        {\n\t\treturn RC;\n        }\n\n\tif (LzmaDecoderCode(&cc, &in_size_l, &out_size_l) != S_OK)\n        {\n\t\treturn -2;\n        }\n\n\tif (out_stream.size != out_size)\n        {\n\t\treturn -3;\n        }\n\n        if ( out_stream.overflow )\n        {\n            return -4;\n        }\n\n\treturn 0;\n}\n\n//BRCM modification\n#ifdef __KERNEL__\nEXPORT_SYMBOL(decompress_lzma_7z);\n#endif\n\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/AriBitCoder.h",
    "content": "#ifndef __COMPRESSION_BITCODER_H\n#define __COMPRESSION_BITCODER_H\n\n#include \"RangeCoder.h\"\n\n#define kNumBitModelTotalBits  11\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\n\n#define kNumMoveReducingBits 2\n\n\ntypedef UINT32 CBitDecoder;\n\nINLINE  void BitDecoderInit(CBitDecoder *bitDecoder)\n  { \n    *bitDecoder = kBitModelTotal / 2; \n  }\n\n#if 0\nUINT32 BitDecode(ISequentialInStream *in_stream, CBitDecoder *bitDecoder, CRangeDecoder *aRangeDecoder);\n#else\nINLINE  UINT32 BitDecode(ISequentialInStream *in_stream, CBitDecoder *bitDecoder, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aNewBound = (aRangeDecoder->m_Range >> kNumBitModelTotalBits) * (*bitDecoder);\n    if (aRangeDecoder->m_Code < aNewBound)\n    {\n      aRangeDecoder->m_Range = aNewBound;\n      *bitDecoder += (kBitModelTotal - *bitDecoder) >> kNumMoveBits;\n      if (aRangeDecoder->m_Range < kTopValue)\n      {\n        aRangeDecoder->m_Code = (aRangeDecoder->m_Code << 8) | InStreamReadByte(in_stream);\n        aRangeDecoder->m_Range <<= 8;\n      }\n      return 0;\n    }\n    else\n    {\n      aRangeDecoder->m_Range -= aNewBound;\n      aRangeDecoder->m_Code -= aNewBound;\n      *bitDecoder -= (*bitDecoder) >> kNumMoveBits;\n      if (aRangeDecoder->m_Range < kTopValue)\n      {\n        aRangeDecoder->m_Code = (aRangeDecoder->m_Code << 8) | InStreamReadByte(in_stream);\n        aRangeDecoder->m_Range <<= 8;\n      }\n      return 1;\n    }\n  }\n#endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/BitTreeCoder.h",
    "content": "#ifndef __BITTREECODER_H\n#define __BITTREECODER_H\n\n#include \"AriBitCoder.h\"\n#include \"RCDefs.h\"\n\n//BRCM modification start\n// Duplication of malloc/free redirection macros from the two header files\n// namely, BitTreeCoder.h and LiteralCoder.h, were moved to a single\n// implementation in RCDefs.h that is included by both the above header files.\n//BRCM modification end\n\n//////////////////////////\n// CBitTreeDecoder\n\ntypedef struct CBitTreeDecoder\n{\n  UINT32       m_NumBitLevels;\n  CBitDecoder *m_Models;\n} CBitTreeDecoder;\n\n//  ~CBitTreeDecoder() { free(m_Models); }\nINLINE void BitTreeDecoderInit(CBitTreeDecoder *bitTreeDecoder, UINT32 aNumBitLevels)\n  {\n    int i;\n    bitTreeDecoder->m_NumBitLevels = aNumBitLevels;\n    bitTreeDecoder->m_Models       = (CBitDecoder *)malloc( sizeof(CBitDecoder) * (1 << bitTreeDecoder->m_NumBitLevels));\n    //BRCM modification\n    //printf(\"malloc in BitTreeDecoderInit=%d\\n\",sizeof(CBitDecoder) * (1 << bitTreeDecoder->m_NumBitLevels));\n    if (!bitTreeDecoder->m_Models) {\n\t    printf(\"Error in allocating memory for bitTreeDecoder!\\n\");\n\t    return;\n    }\t    \n    for(i = 1; i < (1 << aNumBitLevels); i++)\n      BitDecoderInit(&bitTreeDecoder->m_Models[i]);\n  }\nINLINE UINT32 BitTreeDecode(ISequentialInStream *in_stream, CBitTreeDecoder *bitTreeDecoder, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;\n    UINT32 aBitIndex;\n    for(aBitIndex = bitTreeDecoder->m_NumBitLevels; aBitIndex > 0; aBitIndex--)\n    {\n      RC_GETBIT(kNumMoveBits, bitTreeDecoder->m_Models[aModelIndex], aModelIndex)\n    }\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aModelIndex - (1 << bitTreeDecoder->m_NumBitLevels);\n  }\n\n\n////////////////////////////////\n// CReverseBitTreeDecoder2\n\ntypedef struct CReverseBitTreeDecoder2\n{\n  UINT32       m_NumBitLevels;\n  CBitDecoder *m_Models;\n} CReverseBitTreeDecoder2;\n\n//  CReverseBitTreeDecoder2(): m_Models(0) { }\n//  ~CReverseBitTreeDecoder2() { free(m_Models); }\nINLINE BOOL ReverseBitTreeDecoder2Create(CReverseBitTreeDecoder2 *reverseBitTreeDecoder2, UINT32 aNumBitLevels)\n  {\n    reverseBitTreeDecoder2->m_NumBitLevels = aNumBitLevels;\n    reverseBitTreeDecoder2->m_Models       = (CBitDecoder *)malloc( sizeof(CBitDecoder) * (1 << reverseBitTreeDecoder2->m_NumBitLevels));\n    //printf(\"malloc in ReverseBitTreeDecoder2Create=%d\\n\",sizeof(CBitDecoder) * (1 << reverseBitTreeDecoder2->m_NumBitLevels));\n    if (!reverseBitTreeDecoder2->m_Models) {\n\t    printf(\"Error in allocating memory for reverseBitTreeDecoder2!\\n\");\n\t    return 0;\n    }\t    \n    return (reverseBitTreeDecoder2->m_Models != 0);\n  }\nINLINE void ReverseBitTreeDecoder2Init(CReverseBitTreeDecoder2 *reverseBitTreeDecoder2)\n  {\n    UINT32 aNumModels = 1 << reverseBitTreeDecoder2->m_NumBitLevels;\n    UINT32 i;\n    for(i = 1; i < aNumModels; i++)\n      BitDecoderInit(&reverseBitTreeDecoder2->m_Models[i]);\n  }\nINLINE UINT32 ReverseBitTreeDecoder2Decode(ISequentialInStream *in_stream, CReverseBitTreeDecoder2 *reverseBitTreeDecoder2, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    UINT32 aSymbol = 0;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;\n    UINT32 aBitIndex;\n    for(aBitIndex = 0; aBitIndex < reverseBitTreeDecoder2->m_NumBitLevels; aBitIndex++)\n    {\n      RC_GETBIT2(kNumMoveBits, reverseBitTreeDecoder2->m_Models[aModelIndex], aModelIndex, ; , aSymbol |= (1 << aBitIndex))\n    }\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aSymbol;\n  }\n\n\n////////////////////////////\n// CReverseBitTreeDecoder\n\ntypedef struct CReverseBitTreeDecoder\n{\n  UINT32        m_NumBitLevels;\n  CBitDecoder  *m_Models;\n} CReverseBitTreeDecoder;\n\n//    CReverseBitTreeDecoder(): m_Models(0) { }\n//    ~CReverseBitTreeDecoder() { free(m_Models); }\nINLINE void ReverseBitTreeDecoderInit(CReverseBitTreeDecoder *reverseBitTreeDecoder, UINT32 aNumBitLevels)\n  {\n    int i;\n    reverseBitTreeDecoder->m_NumBitLevels = aNumBitLevels;\n    reverseBitTreeDecoder->m_Models       = (CBitDecoder *)malloc( sizeof(CBitDecoder) * (1 << reverseBitTreeDecoder->m_NumBitLevels));\n    //printf(\"malloc in ReverseBitTreeDecoderInit=%d\\n\",sizeof(CBitDecoder) * (1 << reverseBitTreeDecoder->m_NumBitLevels));\n    if (!reverseBitTreeDecoder->m_Models) {\n\t    printf(\"Error in allocating memory for reverseBitTreeDecoder!\\n\");\n\t    return;\n    }\t    \n    for(i = 1; i < (1 << reverseBitTreeDecoder->m_NumBitLevels); i++)\n      BitDecoderInit(&reverseBitTreeDecoder->m_Models[i]);\n  }\n\nINLINE UINT32 ReverseBitTreeDecoderDecode(ISequentialInStream *in_stream, CReverseBitTreeDecoder *reverseBitTreeDecoder, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    UINT32 aSymbol = 0;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;\n    UINT32 aBitIndex;\n    for(aBitIndex = 0; aBitIndex < reverseBitTreeDecoder->m_NumBitLevels; aBitIndex++)\n    {\n      RC_GETBIT2(kNumMoveBits, reverseBitTreeDecoder->m_Models[aModelIndex], aModelIndex, ; , aSymbol |= (1 << aBitIndex))\n    }\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aSymbol;\n  }\n\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/IInOutStreams.c",
    "content": "#include \"IInOutStreams.h\"\n// BRCM modification \nstatic void *lib_memcpy(void *dest,const void *src,size_t cnt);\nstatic void *lib_memcpy(void *dest,const void *src,size_t cnt)\n{\n    unsigned char *d;\n    const unsigned char *s;\n\n    d = (unsigned char *) dest;\n    s = (const unsigned char *) src;\n\n    while (cnt) {\n\t*d++ = *s++;\n\tcnt--;\n\t}\n\n    return dest;\n}\n\nHRESULT InStreamRead(void *aData, UINT32 aSize, UINT32* aProcessedSize) {\n    \tif (aSize > in_stream.remainingBytes)\n    \t\taSize = in_stream.remainingBytes;\n    \t*aProcessedSize = aSize;\n    \tlib_memcpy(aData, in_stream.data, aSize); // brcm modification\n    \tin_stream.remainingBytes -= aSize;\n    \tin_stream.data += aSize;\n    \treturn S_OK;\n    }\n\n#if 0\nBYTE InStreamReadByte()\n    {\n        if (in_stream.remainingBytes == 0)\n            return 0x0;\n        in_stream.remainingBytes--;\n        return (BYTE) *in_stream.data++;\n    }\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/IInOutStreams.h",
    "content": "#ifndef __IINOUTSTREAMS_H\n#define __IINOUTSTREAMS_H\n\n#include \"Portable.h\"\n\ntypedef struct ISequentialInStream\n{\n\tunsigned char* data;\n\tunsigned       remainingBytes;\n} ISequentialInStream;\n\nextern ISequentialInStream in_stream;\n\nINLINE void InStreamInit(unsigned char * Adata, unsigned Asize)\n    {\n        in_stream.data           = Adata;\n        in_stream.remainingBytes = Asize;\n    }\n\nHRESULT InStreamRead(void *aData, UINT32 aSize, UINT32* aProcessedSize);\n\n#if 0\nBYTE InStreamReadByte();\n#else\nINLINE BYTE InStreamReadByte(ISequentialInStream *in_stream)\n    {\n        if (in_stream->remainingBytes == 0)\n            return 0x0;\n        in_stream->remainingBytes--;\n        return (BYTE) *in_stream->data++;\n    }\n#endif\n\n\n\ntypedef struct ISequentialOutStream\n{\n\tchar*       data;\n\tunsigned    size;\n\tBOOL        overflow;\n\tunsigned    total;\n} ISequentialOutStream;\n\nextern ISequentialOutStream out_stream;\n\n#define OutStreamInit(Adata, Asize) \\\n{ \\\n    out_stream.data = Adata; \\\n    out_stream.size = Asize; \\\n    out_stream.overflow = FALSE; \\\n    out_stream.total = 0; \\\n}\n\n#define OutStreamSizeSet(newsize) \\\n    { \\\n        out_stream.total = newsize; \\\n        if (out_stream.total > out_stream.size) \\\n            out_stream.overflow = TRUE; \\\n    }\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/LZMA.h",
    "content": "#include \"LenCoder.h\"\n\n#ifndef __LZMA_H\n#define __LZMA_H\n\n\n#define kNumRepDistances 4\n\n#define kNumStates 12\n\nstatic const BYTE kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\nstatic const BYTE kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\nstatic const BYTE kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\nstatic const BYTE kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\n\ntypedef BYTE CState;\n\nINLINE void CStateInit(CState *m_Index)\n    { *m_Index = 0; }\nINLINE void CStateUpdateChar(CState *m_Index)\n    { *m_Index = kLiteralNextStates[*m_Index]; }\nINLINE void CStateUpdateMatch(CState *m_Index)\n    { *m_Index = kMatchNextStates[*m_Index]; }\nINLINE void CStateUpdateRep(CState *m_Index)\n    { *m_Index = kRepNextStates[*m_Index]; }\nINLINE void CStateUpdateShortRep(CState *m_Index)\n    { *m_Index = kShortRepNextStates[*m_Index]; }\n\n\n#define kNumPosSlotBits 6\n#define kDicLogSizeMax 28\n#define kDistTableSizeMax 56\n\n//extern UINT32 kDistStart[kDistTableSizeMax];\nstatic const BYTE kDistDirectBits[kDistTableSizeMax] = \n{\n  0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,\n  10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, \n  20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26 \n};\n\n#define kNumLenToPosStates 4\nINLINE UINT32 GetLenToPosState(UINT32 aLen)\n{\n  aLen -= 2;\n  if (aLen < kNumLenToPosStates)\n    return aLen;\n  return kNumLenToPosStates - 1;\n}\n\n#define kMatchMinLen 2\n\n#define kMatchMaxLen (kMatchMinLen + kNumSymbolsTotal - 1)\n\n#define kNumAlignBits 4\n#define kAlignTableSize 16\n#define kAlignMask 15\n\n#define kStartPosModelIndex 4\n#define kEndPosModelIndex 14\n#define kNumPosModels 10\n\n#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\n\n\n#define kMainChoiceLiteralIndex 0\n#define kMainChoiceMatchIndex 1\n\n#define kMatchChoiceDistanceIndex0\n#define kMatchChoiceRepetitionIndex 1\n\n#define kNumMoveBitsForMainChoice 5\n#define kNumMoveBitsForPosCoders 5\n\n#define kNumMoveBitsForAlignCoders 5\n\n#define kNumMoveBitsForPosSlotCoder 5\n\n#define kNumLitPosStatesBitsEncodingMax 4\n#define kNumLitContextBitsMax 8\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/LZMADecoder.c",
    "content": "#include \"Portable.h\"\n#ifdef _HOST_TOOL\n#include \"stdio.h\"\n#endif\n#include \"LZMADecoder.h\"\n\n\n//#define RETURN_E_OUTOFMEMORY_IF_FALSE(x) { if (!(x)) return E_OUTOFMEMORY; }\n\n\nstatic UINT32    kDistStart[kDistTableSizeMax];\nstruct WindowOut out_window;\n\n/*\n * BRCM modification: free all the allocated buffer by malloc\n *\n */\nstatic void LzmaDecoderFreeBuffer(LzmaDecoder  *lzmaDecoder)\n{\n  int i,aPosState;\n  \n  //printf(\"free lzmaDecoder->m_LiteralDecoder\\n\");\n  free((&lzmaDecoder->m_LiteralDecoder)->m_Coders);\n\n  for (i = 0; i < kNumLenToPosStates; i++) {\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free((&lzmaDecoder->m_PosSlotDecoder[i])->m_Models);\n  }\n  // from LenDecoderInit(&lzmaDecoder->m_LenDecoder;\n  for (aPosState = 0; aPosState < (&lzmaDecoder->m_LenDecoder)->m_NumPosStates; aPosState++) {\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free( (&(&lzmaDecoder->m_LenDecoder)->m_LowCoder[aPosState])->m_Models );\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free( (&(&lzmaDecoder->m_LenDecoder)->m_MidCoder[aPosState])->m_Models );\n   }\n  //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n  free( (&(&lzmaDecoder->m_LenDecoder)->m_HighCoder)->m_Models );\n\n\n  // from LenDecoderInit(&lzmaDecoder->m_RepMatchLenDecoder);\n  for (aPosState = 0; aPosState < (&lzmaDecoder->m_RepMatchLenDecoder)->m_NumPosStates; aPosState++) {\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free( (&(&lzmaDecoder->m_RepMatchLenDecoder)->m_LowCoder[aPosState])->m_Models );\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free( (&(&lzmaDecoder->m_RepMatchLenDecoder)->m_MidCoder[aPosState])->m_Models );\n  }\n  //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n  free( (&(&lzmaDecoder->m_RepMatchLenDecoder)->m_HighCoder)->m_Models );\n\n    \n  //printf(\"free lzmaDecoder->m_PosAlignDecoder\\n\");\n  free((&lzmaDecoder->m_PosAlignDecoder)->m_Models);\n\n  for(i = 0; i < kNumPosModels; i++) {\n      //printf(\"free lzmaDecoder->m_PosDecoders\\n\");\n      free((&lzmaDecoder->m_PosDecoders[i])->m_Models);\n  }\n  \n}\n\nHRESULT LzmaDecoderSetDictionarySize(\n    LzmaDecoder  *lzmaDecoder, \n    UINT32        aDictionarySize)\n{\n  if (aDictionarySize > (1 << kDicLogSizeMax))\n    return E_INVALIDARG;\n  \n//  UINT32 aWindowReservSize = MyMax(aDictionarySize, UINT32(1 << 21));\n\n  if (lzmaDecoder->m_DictionarySize != aDictionarySize)\n  {\n    lzmaDecoder->m_DictionarySize = aDictionarySize;\n  }\n  return S_OK;\n}\n\nHRESULT LzmaDecoderSetLiteralProperties( \n    LzmaDecoder  *lzmaDecoder,\n    UINT32        aLiteralPosStateBits, \n    UINT32        aLiteralContextBits)\n{\n  if (aLiteralPosStateBits > 8)\n    return E_INVALIDARG;\n  if (aLiteralContextBits > 8)\n    return E_INVALIDARG;\n  LitDecoderCreate(&lzmaDecoder->m_LiteralDecoder, aLiteralPosStateBits, aLiteralContextBits);\n  return S_OK;\n}\n\nHRESULT LzmaDecoderSetPosBitsProperties(\n    LzmaDecoder *lzmaDecoder, \n    UINT32       aNumPosStateBits)\n{\n  UINT32 aNumPosStates;\n  if (aNumPosStateBits > (UINT32) kNumPosStatesBitsMax)\n    return E_INVALIDARG;\n  aNumPosStates = 1 << aNumPosStateBits;\n  LenDecoderCreate(&lzmaDecoder->m_LenDecoder, aNumPosStates);\n  LenDecoderCreate(&lzmaDecoder->m_RepMatchLenDecoder, aNumPosStates);\n  lzmaDecoder->m_PosStateMask = aNumPosStates - 1;\n  return S_OK;\n}\n\n\nvoid LzmaDecoderConstructor(LzmaDecoder *lzmaDecoder)\n{\n  lzmaDecoder->m_DictionarySize = ((UINT32)-1);\n  LzmaDecoderCreate(lzmaDecoder);\n}\n\nHRESULT LzmaDecoderCreate(LzmaDecoder *lzmaDecoder)\n{\n  int i;\n  for(i = 0; i < kNumPosModels; i++)\n  {\n    if (!(ReverseBitTreeDecoder2Create(&lzmaDecoder->m_PosDecoders[i],kDistDirectBits[kStartPosModelIndex + i])))\n        return E_OUTOFMEMORY;;\n  }\n  return S_OK;\n}\n\n\nHRESULT LzmaDecoderInit(LzmaDecoder *lzmaDecoder)\n{\n  int    i;\n  UINT32 j;\n\n  RangeDecoderInit(&in_stream, &lzmaDecoder->m_RangeDecoder);\n\n  OutWindowInit();\n\n  for(i = 0; i < kNumStates; i++)\n  {\n    for (j = 0; j <= lzmaDecoder->m_PosStateMask; j++)\n    {\n      BitDecoderInit(&lzmaDecoder->m_MainChoiceDecoders[i][j]);\n      BitDecoderInit(&lzmaDecoder->m_MatchRepShortChoiceDecoders[i][j]);\n    }\n    BitDecoderInit(&lzmaDecoder->m_MatchChoiceDecoders[i]);\n    BitDecoderInit(&lzmaDecoder->m_MatchRepChoiceDecoders[i]);\n    BitDecoderInit(&lzmaDecoder->m_MatchRep1ChoiceDecoders[i]);\n    BitDecoderInit(&lzmaDecoder->m_MatchRep2ChoiceDecoders[i]);\n  }\n  \n  LitDecoderInit(&lzmaDecoder->m_LiteralDecoder);\n   \n  for (i = 0; i < (int) kNumLenToPosStates; i++)\n    BitTreeDecoderInit(&lzmaDecoder->m_PosSlotDecoder[i],kNumPosSlotBits);\n\n  for(i = 0; i < kNumPosModels; i++)\n    ReverseBitTreeDecoder2Init(&lzmaDecoder->m_PosDecoders[i]);\n  \n  LenDecoderInit(&lzmaDecoder->m_LenDecoder);\n  LenDecoderInit(&lzmaDecoder->m_RepMatchLenDecoder);\n\n  ReverseBitTreeDecoderInit(&lzmaDecoder->m_PosAlignDecoder, kNumAlignBits);\n  return S_OK;\n\n}\n\nHRESULT LzmaDecoderCodeReal( \n    LzmaDecoder     *lzmaDecoder, \n    UINT64          *anInSize, \n    UINT64          *anOutSize)\n{\n  BOOL                  aPeviousIsMatch         = FALSE;\n  BYTE                  aPreviousByte           = 0;\n  UINT32                aRepDistances[kNumRepDistances];\n  int                   i;\n  UINT64                aNowPos64               = 0;\n  UINT64                aSize                   = *anOutSize;\n  ISequentialInStream   my_in_stream;\n//  WindowOut             out_window;\n  CState                aState;\n\n  CStateInit(&aState);\n\n  if (anOutSize == NULL)\n  {\n      printf(\"CodeReal: invalid argument %x\\n\", (UINT32) anOutSize );\n      return E_INVALIDARG;\n  }\n\n\n  LzmaDecoderInit(lzmaDecoder);\n\n  my_in_stream.data           = in_stream.data;\n  my_in_stream.remainingBytes = in_stream.remainingBytes;\n\n  for(i = 0 ; i < (int) kNumRepDistances; i++)\n    aRepDistances[i] = 0;\n\n  //while(aNowPos64 < aSize)\n  while(my_in_stream.remainingBytes > 0)\n  {\n    UINT64 aNext = MyMin(aNowPos64 + (1 << 18), aSize);\n    while(aNowPos64 < aNext)\n    {\n      UINT32 aPosState = (UINT32)(aNowPos64) & lzmaDecoder->m_PosStateMask;\n      if (BitDecode(&my_in_stream, \n                    &lzmaDecoder->m_MainChoiceDecoders[aState][aPosState], \n                    &lzmaDecoder->m_RangeDecoder) == (UINT32) kMainChoiceLiteralIndex)\n      {\n        CStateUpdateChar(&aState);\n        if(aPeviousIsMatch)\n        {\n          BYTE aMatchByte = OutWindowGetOneByte(0 - aRepDistances[0] - 1);\n          aPreviousByte = LitDecodeWithMatchByte(&my_in_stream, \n                                                 &lzmaDecoder->m_LiteralDecoder, \n                                                 &lzmaDecoder->m_RangeDecoder, \n                                                 (UINT32)(aNowPos64), \n                                                 aPreviousByte, \n                                                 aMatchByte);\n          aPeviousIsMatch = FALSE;\n        }\n        else\n          aPreviousByte = LitDecodeNormal(&my_in_stream, \n                                          &lzmaDecoder->m_LiteralDecoder, \n                                          &lzmaDecoder->m_RangeDecoder, \n                                         (UINT32)(aNowPos64), \n                                          aPreviousByte);\n        OutWindowPutOneByte(aPreviousByte);\n        aNowPos64++;\n      }\n      else             \n      {\n        UINT32 aDistance, aLen;\n        aPeviousIsMatch = TRUE;\n        if(BitDecode(&my_in_stream, \n                     &lzmaDecoder->m_MatchChoiceDecoders[aState], \n                     &lzmaDecoder->m_RangeDecoder) == (UINT32) kMatchChoiceRepetitionIndex)\n        {\n          if(BitDecode(&my_in_stream, \n                       &lzmaDecoder->m_MatchRepChoiceDecoders[aState], \n                       &lzmaDecoder->m_RangeDecoder) == 0)\n          {\n            if(BitDecode(&my_in_stream, \n                         &lzmaDecoder->m_MatchRepShortChoiceDecoders[aState][aPosState], \n                         &lzmaDecoder->m_RangeDecoder) == 0)\n            {\n              CStateUpdateShortRep(&aState);\n              aPreviousByte = OutWindowGetOneByte(0 - aRepDistances[0] - 1);\n              OutWindowPutOneByte(aPreviousByte);\n              aNowPos64++;\n              continue;\n            }\n            aDistance = aRepDistances[0];\n          }\n          else\n          {\n            if(BitDecode(&my_in_stream, \n                         &lzmaDecoder->m_MatchRep1ChoiceDecoders[aState], \n                         &lzmaDecoder->m_RangeDecoder) == 0)\n            {\n              aDistance = aRepDistances[1];\n              aRepDistances[1] = aRepDistances[0];\n            }\n            else \n            {\n              if (BitDecode(&my_in_stream, \n                            &lzmaDecoder->m_MatchRep2ChoiceDecoders[aState], \n                            &lzmaDecoder->m_RangeDecoder) == 0)\n              {\n                aDistance = aRepDistances[2];\n              }\n              else\n              {\n                aDistance = aRepDistances[3];\n                aRepDistances[3] = aRepDistances[2];\n              }\n              aRepDistances[2] = aRepDistances[1];\n              aRepDistances[1] = aRepDistances[0];\n            }\n            aRepDistances[0] = aDistance;\n          }\n          aLen = LenDecode(&my_in_stream, \n                           &lzmaDecoder->m_RepMatchLenDecoder, \n                           &lzmaDecoder->m_RangeDecoder, \n                           aPosState) + kMatchMinLen;\n          CStateUpdateRep(&aState);\n        }\n        else\n        {\n          UINT32 aPosSlot;\n          aLen = kMatchMinLen + LenDecode(&my_in_stream, \n                                          &lzmaDecoder->m_LenDecoder, \n                                          &lzmaDecoder->m_RangeDecoder, \n                                          aPosState);\n          CStateUpdateMatch(&aState);\n          aPosSlot = BitTreeDecode(&my_in_stream, \n                                   &lzmaDecoder->m_PosSlotDecoder[GetLenToPosState(aLen)],\n                                   &lzmaDecoder->m_RangeDecoder);\n          if (aPosSlot >= (UINT32) kStartPosModelIndex)\n          {\n            aDistance = kDistStart[aPosSlot];\n            if (aPosSlot < (UINT32) kEndPosModelIndex)\n              aDistance += ReverseBitTreeDecoder2Decode(&my_in_stream, \n                                                        &lzmaDecoder->m_PosDecoders[aPosSlot - kStartPosModelIndex],\n                                                        &lzmaDecoder->m_RangeDecoder);\n            else\n            {\n              aDistance += (RangeDecodeDirectBits(&my_in_stream, \n                                                  &lzmaDecoder->m_RangeDecoder, \n                                                  kDistDirectBits[aPosSlot] - kNumAlignBits) << kNumAlignBits);\n              aDistance += ReverseBitTreeDecoderDecode(&my_in_stream, \n                                                       &lzmaDecoder->m_PosAlignDecoder, \n                                                       &lzmaDecoder->m_RangeDecoder);\n            }\n          }\n          else\n            aDistance = aPosSlot;\n\n          \n          aRepDistances[3] = aRepDistances[2];\n          aRepDistances[2] = aRepDistances[1];\n          aRepDistances[1] = aRepDistances[0];\n          \n          aRepDistances[0] = aDistance;\n        }\n        if (aDistance >= aNowPos64)\n        {\n            printf(\"CodeReal: invalid data\\n\" );\n            return E_INVALIDDATA;\n        }\n        OutWindowCopyBackBlock(aDistance, aLen);\n        aNowPos64 += aLen;\n        aPreviousByte = OutWindowGetOneByte(0 - 1);\n      }\n    }\n  }\n  \n  //BRCM modification\n  LzmaDecoderFreeBuffer(lzmaDecoder);\n  \n  OutWindowFlush();\n  return S_OK;\n}\n\nHRESULT LzmaDecoderCode(\n    LzmaDecoder *lzmaDecoder,\n    UINT64 *anInSize, \n    UINT64 *anOutSize)\n{\n\n    UINT32 aStartValue = 0;\n    int i;\n    \n    for (i = 0; i < kDistTableSizeMax; i++)\n    {\n        kDistStart[i] = aStartValue;\n        aStartValue += (1 << kDistDirectBits[i]);\n    }\n    return LzmaDecoderCodeReal( \n        lzmaDecoder, \n        anInSize, \n        anOutSize);\n}\n\nHRESULT LzmaDecoderReadCoderProperties(LzmaDecoder *lzmaDecoder)\n{\n  UINT32 aNumPosStateBits;\n  UINT32 aLiteralPosStateBits;\n  UINT32 aLiteralContextBits;\n  UINT32 aDictionarySize;\n  BYTE   aRemainder;\n  UINT32 aProcessesedSize;\n\n  BYTE aByte;\n  RETURN_IF_NOT_S_OK(InStreamRead(&aByte, \n                                  sizeof(aByte), \n                                  &aProcessesedSize));\n\n  if (aProcessesedSize != sizeof(aByte))\n    return E_INVALIDARG;\n\n  aLiteralContextBits   = aByte % 9;\n  aRemainder            = aByte / 9;\n  aLiteralPosStateBits  = aRemainder % 5;\n  aNumPosStateBits      = aRemainder / 5;\n\n  RETURN_IF_NOT_S_OK(InStreamRead(&aDictionarySize, \n                                  sizeof(aDictionarySize), \n                                  &aProcessesedSize));\n\n  if (aProcessesedSize != sizeof(aDictionarySize))\n    return E_INVALIDARG;\n\n  RETURN_IF_NOT_S_OK( LzmaDecoderSetDictionarySize(lzmaDecoder, \n                                                   aDictionarySize) );\n  RETURN_IF_NOT_S_OK( LzmaDecoderSetLiteralProperties(lzmaDecoder, \n                                                      aLiteralPosStateBits, \n                                                      aLiteralContextBits) );\n  RETURN_IF_NOT_S_OK( LzmaDecoderSetPosBitsProperties(lzmaDecoder, \n                                                      aNumPosStateBits) );\n\n  return S_OK;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/LZMADecoder.h",
    "content": "#ifndef __LZARITHMETIC_DECODER_H\n#define __LZARITHMETIC_DECODER_H\n\n#include \"WindowOut.h\"\n#include \"LZMA.h\"\n#include \"LenCoder.h\"\n#include \"LiteralCoder.h\"\n\n\ntypedef struct LzmaDecoder\n{\n  CRangeDecoder m_RangeDecoder;\n\n  CBitDecoder m_MainChoiceDecoders[kNumStates][kNumPosStatesMax];\n  CBitDecoder m_MatchChoiceDecoders[kNumStates];\n  CBitDecoder m_MatchRepChoiceDecoders[kNumStates];\n  CBitDecoder m_MatchRep1ChoiceDecoders[kNumStates];\n  CBitDecoder m_MatchRep2ChoiceDecoders[kNumStates];\n  CBitDecoder m_MatchRepShortChoiceDecoders[kNumStates][kNumPosStatesMax];\n\n  CBitTreeDecoder               m_PosSlotDecoder[kNumLenToPosStates];\n\n  CReverseBitTreeDecoder2       m_PosDecoders[kNumPosModels];\n  CReverseBitTreeDecoder        m_PosAlignDecoder;\n  \n  LenDecoder m_LenDecoder;\n  LenDecoder m_RepMatchLenDecoder;\n\n  LitDecoder m_LiteralDecoder;\n\n  UINT32 m_DictionarySize;\n  \n  UINT32 m_PosStateMask;\n} LzmaDecoder;\n\n  HRESULT LzmaDecoderCreate(LzmaDecoder *lzmaDecoder);\n\n  HRESULT LzmaDecoderInit(LzmaDecoder *lzmaDecoder);\n\n//static inline  HRESULT LzmaDecoderFlush() { return OutWindowFlush(); }\n\n  HRESULT LzmaDecoderCodeReal( \n      LzmaDecoder           *lzmaDecoder, \n//      ISequentialInStream   *in_stream, \n      UINT64                *anInSize, \n//      WindowOut             *out_window,\n      UINT64                *anOutSize);\n\n\n  void LzmaDecoderConstructor( LzmaDecoder *lzmaDecoder );\n  \n  HRESULT LzmaDecoderCode( LzmaDecoder *lzmaDecoder, UINT64 *anInSize, UINT64 *anOutSize);\n  HRESULT LzmaDecoderReadCoderProperties(LzmaDecoder *lzmaDecoder );\n\n  HRESULT LzmaDecoderSetDictionarySize(LzmaDecoder *lzmaDecoder, UINT32 aDictionarySize);\n  HRESULT LzmaDecoderSetLiteralProperties(LzmaDecoder *lzmaDecoder, UINT32 aLiteralPosStateBits, UINT32 aLiteralContextBits);\n  HRESULT LzmaDecoderSetPosBitsProperties(LzmaDecoder *lzmaDecoder, UINT32 aNumPosStateBits);\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/LenCoder.h",
    "content": "#ifndef __LENCODER_H\n#define __LENCODER_H\n\n#include \"BitTreeCoder.h\"\n\n\n#define kNumPosStatesBitsMax 4\n#define kNumPosStatesMax 16\n\n\n#define kNumPosStatesBitsEncodingMax 4\n#define kNumPosStatesEncodingMax 16\n\n\n//#define kNumMoveBits 5\n\n#define kNumLenBits 3\n#define kNumLowSymbols (1 << kNumLenBits)\n\n#define kNumMidBits 3\n#define kNumMidSymbols (1 << kNumMidBits)\n\n#define kNumHighBits 8\n\n#define kNumSymbolsTotal (kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits))\n\ntypedef struct LenDecoder\n{\n  CBitDecoder       m_Choice;\n  CBitDecoder       m_Choice2;\n  CBitTreeDecoder   m_LowCoder[kNumPosStatesMax];\n  CBitTreeDecoder   m_MidCoder[kNumPosStatesMax];\n  CBitTreeDecoder   m_HighCoder; \n  UINT32            m_NumPosStates;\n} LenDecoder;\n\nINLINE void LenDecoderCreate(LenDecoder *lenCoder, UINT32 aNumPosStates)\n  { \n    lenCoder->m_NumPosStates = aNumPosStates; \n  }\n\nINLINE void LenDecoderInit(LenDecoder *lenCoder)\n  {\n    UINT32 aPosState;\n    BitDecoderInit(&lenCoder->m_Choice);\n    for (aPosState = 0; aPosState < lenCoder->m_NumPosStates; aPosState++)\n    {\n      BitTreeDecoderInit(&lenCoder->m_LowCoder[aPosState],kNumLenBits);\n      BitTreeDecoderInit(&lenCoder->m_MidCoder[aPosState],kNumMidBits);\n    }\n    BitTreeDecoderInit(&lenCoder->m_HighCoder,kNumHighBits);\n    BitDecoderInit(&lenCoder->m_Choice2);\n  }\n\nINLINE UINT32 LenDecode(ISequentialInStream *in_stream, LenDecoder *lenCoder, CRangeDecoder *aRangeDecoder, UINT32 aPosState)\n  {\n    if(BitDecode(in_stream, &lenCoder->m_Choice, aRangeDecoder) == 0)\n      return BitTreeDecode(in_stream, &lenCoder->m_LowCoder[aPosState],aRangeDecoder);\n    else\n    {\n      UINT32 aSymbol = kNumLowSymbols;\n      if(BitDecode(in_stream, &lenCoder->m_Choice2, aRangeDecoder) == 0)\n        aSymbol += BitTreeDecode(in_stream, &lenCoder->m_MidCoder[aPosState],aRangeDecoder);\n      else\n      {\n        aSymbol += kNumMidSymbols;\n        aSymbol += BitTreeDecode(in_stream, &lenCoder->m_HighCoder,aRangeDecoder);\n      }\n      return aSymbol;\n    }\n  }\n\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/LiteralCoder.h",
    "content": "#ifndef __LITERALCODER_H\n#define __LITERALCODER_H\n\n#include \"AriBitCoder.h\"\n#include \"RCDefs.h\"\n\n//BRCM modification start\n// Duplication of malloc/free redirection macros from the two header files\n// namely, BitTreeCoder.h and LiteralCoder.h, were moved to a single\n// implementation in RCDefs.h that is included by both the above header files.\n//BRCM modification end\n\n//#define kNumMoveBits 5\n\ntypedef struct LitDecoder2\n{\n  CBitDecoder m_Decoders[3][1 << 8];\n} LitDecoder2;\n\n\nINLINE void LitDecoder2Init(LitDecoder2 *litDecoder2)\n  {\n    int i, j;\n    for (i = 0; i < 3; i++)\n      for (j = 1; j < (1 << 8); j++)\n        BitDecoderInit(&litDecoder2->m_Decoders[i][j]);\n  }\n\nINLINE BYTE LitDecoder2DecodeNormal(ISequentialInStream *in_stream, LitDecoder2 *litDecoder2, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aSymbol = 1;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;        \n    do\n    {\n      RC_GETBIT(kNumMoveBits, litDecoder2->m_Decoders[0][aSymbol], aSymbol)\n    }\n    while (aSymbol < 0x100);\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aSymbol;\n  }\n\nINLINE BYTE LitDecoder2DecodeWithMatchByte(ISequentialInStream *in_stream, LitDecoder2 *litDecoder2, CRangeDecoder *aRangeDecoder, BYTE aMatchByte)\n  {\n    UINT32 aSymbol = 1;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;        \n    do\n    {\n      UINT32 aBit;\n      UINT32 aMatchBit = (aMatchByte >> 7) & 1;\n      aMatchByte <<= 1;\n      RC_GETBIT2(kNumMoveBits, litDecoder2->m_Decoders[1 + aMatchBit][aSymbol], aSymbol, \n          aBit = 0, aBit = 1)\n      if (aMatchBit != aBit)\n      {\n        while (aSymbol < 0x100)\n        {\n          RC_GETBIT(kNumMoveBits, litDecoder2->m_Decoders[0][aSymbol], aSymbol)\n        }\n        break;\n      }\n    }\n    while (aSymbol < 0x100);\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aSymbol;\n  }\n\n\ntypedef struct LitDecoder\n{\n  LitDecoder2 *m_Coders;\n  UINT32 m_NumPrevBits;\n  UINT32 m_NumPosBits;\n  UINT32 m_PosMask;\n} LitDecoder;\n\n\n//  LitDecoder(): m_Coders(0) {}\n//  ~LitDecoder()  { Free(); }\n\n/*\nINLINE void LitDecoderFree(LitDecoder *litDecoder)\n  { \n    free( (char *) litDecoder->m_Coders );\n    litDecoder->m_Coders = 0;\n  }\n*/\n\nINLINE void LitDecoderCreate(LitDecoder *litDecoder, UINT32 aNumPosBits, UINT32 aNumPrevBits)\n  {\n//    LitDecoderFree(litDecoder);\n    UINT32 aNumStates;\n    litDecoder->m_NumPosBits = aNumPosBits;\n    litDecoder->m_PosMask = (1 << aNumPosBits) - 1;\n    litDecoder->m_NumPrevBits = aNumPrevBits;\n    aNumStates = 1 << (aNumPrevBits + aNumPosBits);\n    litDecoder->m_Coders = (LitDecoder2*) malloc( sizeof( LitDecoder2 ) * aNumStates );\n    //printf(\"malloc in LitDecoderCreate=%d\\n\",sizeof( LitDecoder2 ) * aNumStates);\n    if (litDecoder->m_Coders == 0)\n        printf( \"Error allocating memory for LitDecoder m_Coders!\\n\" );\n  }\n\nINLINE void LitDecoderInit(LitDecoder *litDecoder)\n  {\n    UINT32 i;\n    UINT32 aNumStates = 1 << (litDecoder->m_NumPrevBits + litDecoder->m_NumPosBits);\n    for (i = 0; i < aNumStates; i++)\n      LitDecoder2Init(&litDecoder->m_Coders[i]);\n  }\n\nINLINE UINT32 LitDecoderGetState(LitDecoder *litDecoder, UINT32 aPos, BYTE aPrevByte)\n  { \n    return ((aPos & litDecoder->m_PosMask) << litDecoder->m_NumPrevBits) + (aPrevByte >> (8 - litDecoder->m_NumPrevBits)); \n  }\n\nINLINE BYTE LitDecodeNormal(ISequentialInStream *in_stream, LitDecoder *litDecoder, CRangeDecoder *aRangeDecoder, UINT32 aPos, BYTE aPrevByte)\n  { \n    return LitDecoder2DecodeNormal(in_stream, &litDecoder->m_Coders[LitDecoderGetState(litDecoder, aPos, aPrevByte)], aRangeDecoder); \n  }\n\nINLINE BYTE LitDecodeWithMatchByte(ISequentialInStream *in_stream, LitDecoder *litDecoder, CRangeDecoder *aRangeDecoder, UINT32 aPos, BYTE aPrevByte, BYTE aMatchByte)\n  { \n      return LitDecoder2DecodeWithMatchByte(in_stream, &litDecoder->m_Coders[LitDecoderGetState(litDecoder, aPos, aPrevByte)], aRangeDecoder, aMatchByte); \n  }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/Makefile",
    "content": "\nBSPOBJS +=               \\\n\t 7zlzma.o \\\n\t LZMADecoder.o \\\n\t IInOutStreams.o \\\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/Portable.h",
    "content": "#ifndef __PORTABLE_H\n#define __PORTABLE_H\n\n//BRCM modification\n#ifdef _HOST_TOOL\n#include <string.h>\n#endif\n\n#ifdef _CFE_\n#include <string.h>\n#endif\n\n#ifdef __KERNEL__\n#include <linux/string.h>\n#endif\n\n//bcm\n//#ifdef __GNUC__   \n//#include <types/vxTypesOld.h>\n//#define INLINE static inline\n//#else\ntypedef char INT8;\ntypedef unsigned char UINT8;\ntypedef short INT16;\ntypedef unsigned short UINT16;\ntypedef int INT32;\ntypedef unsigned int UINT32;\ntypedef int BOOL;\n#define INLINE static inline\n//#define INLINE static __inline__\n//#endif\ntypedef long long INT64;           // %%%% Changed from \"long long\"\ntypedef unsigned long long UINT64; // %%%% Changed from \"long long\"\n\ntypedef UINT8 BYTE;\ntypedef UINT16 WORD;\ntypedef UINT32 DWORD;\n\ntypedef unsigned UINT_PTR;\n#define FALSE 0\n#define TRUE 1\n\n#define HRESULT int\n#define S_OK 0\n#define E_INVALIDARG -1\n#define E_OUTOFMEMORY -2\n#define E_FAIL -3\n#define E_INTERNAL_ERROR -4\n#define E_INVALIDDATA -5\n\n#define MyMin( a, b ) ( a < b ? a : b )\n\n#define MyMax( a, b ) ( a > b ? a : b )\n\n#define kNumMoveBits 5\n\n#define RETURN_IF_NOT_S_OK(x) { HRESULT __aResult_ = (x); if(__aResult_ != S_OK) return __aResult_; }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/RCDefs.h",
    "content": "#ifndef __RCDEFS_H\n#define __RCDEFS_H\n\n#include \"AriBitCoder.h\"\n\n/* BRCM modification start */\n#ifdef _HOST_TOOL\n#include \"stdio.h\"\n#include \"stdlib.h\"\n#include \"malloc.h\"\n#endif\n\n#ifdef _CFE_\n#include \"lib_malloc.h\"\n#include \"lib_printf.h\"\n#define malloc(x) KMALLOC(x, 0)\n#define free(x)   KFREE(x)\n#endif\n\n#ifdef __KERNEL__\n#include <linux/kernel.h>\n#include <linux/vmalloc.h>\n#include <linux/slab.h>\n#define printf printk\n\n/*\n * BRCM Note:\n *\n * Typically the LitDecoder2 object m_Coders is very large e.g. 24576 bytes,\n * and kmalloc can fail if there is no contiguous space. All other dynamic\n * memory allocations in lzma's usage are very small. If vmalloc is used\n * we would use up (2*4K + 32 + 32) bytes per invocation. When memory is\n * in short supply, e.g. during an upload we typically require over 158Kbytes\n * when 28K would have sufficed if kmalloc was used for smaller sizes.\n *\n */\nINLINE void * lzma_malloc(unsigned long sz)\n{\n    if ( sz > 1024 )\n    {\n        // printf(\"lzma_malloc -> vmalloc( %lu )\\n\", sz );\n        return (void*) vmalloc(sz);\n    }\n    else\n    {\n        // printf(\"lzma_malloc -> kmalloc( %lu )\\n\", sz );\n        return kmalloc(sz, GFP_KERNEL);\n    }\n}\n\nINLINE void lzma_free(void * blk_p)\n{\n        /* if kseg0 kernel cached memory | kseg1 kernel uncached memory */\n    if (  ((unsigned int)blk_p <  (unsigned int) 0xC0000000)\n       && ((unsigned int)blk_p >= (unsigned int) 0x80000000))\n    {\n        // printf(\"lzma_free -> kfree( 0x%08x )\\n\", (int) blk_p);\n        kfree(blk_p);\n    }\n    else        /* kseg2 vmalloc | kuseg malloc */\n    {\n        // printf(\"lzma_free -> vfree( 0x%08x )\\n\", (int) blk_p);\n        vfree(blk_p);\n    }\n}\n\n#define malloc(x) lzma_malloc(x)\n#define free(x)   lzma_free(x)\n#endif\n/* BRCM modification end */\n\n\n/*\n#define RC_INIT_VAR                            \\\n  UINT32 aRange = aRangeDecoder->m_Range;      \\\n  UINT32 aCode = aRangeDecoder->m_Code;        \n\n#define RC_FLUSH_VAR                          \\\n  aRangeDecoder->m_Range = aRange;            \\\n  aRangeDecoder->m_Code = aCode;\n*/\n\n\n#if 1\n#define RC_GETBIT2(aNumMoveBits, aProb, aModelIndex, Action0, Action1)                        \\\n    {UINT32 aNewBound = (aRange >> kNumBitModelTotalBits) * aProb; \\\n    if (aCode < aNewBound)                               \\\n    {                                                             \\\n      Action0;                                                    \\\n      aRange = aNewBound;                                         \\\n      aProb += (kBitModelTotal - aProb) >> aNumMoveBits;          \\\n      aModelIndex <<= 1;                                          \\\n    }                                                             \\\n    else                                                          \\\n    {                                                             \\\n      Action1;                                                    \\\n      aRange -= aNewBound;                                        \\\n      aCode -= aNewBound;                                          \\\n      aProb -= (aProb) >> aNumMoveBits;                           \\\n      aModelIndex = (aModelIndex << 1) + 1;                       \\\n    }}                                                             \\\n    if (aRange < kTopValue)               \\\n    {                                                              \\\n      aCode = (aCode << 8) | InStreamReadByte(in_stream);   \\\n      aRange <<= 8; }\n\n#define RC_GETBIT(aNumMoveBits, aProb, aModelIndex) RC_GETBIT2(aNumMoveBits, aProb, aModelIndex, ; , ;)               \n#endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/RangeCoder.h",
    "content": "#ifndef __COMPRESSION_RANGECODER_H\n#define __COMPRESSION_RANGECODER_H\n\n#include \"IInOutStreams.h\"\n\n#define kNumTopBits 24\n#define kTopValue (1 << kNumTopBits)\n\ntypedef struct CRangeDecoder\n{\n  UINT32  m_Range;\n  UINT32  m_Code;\n} CRangeDecoder;\n\n\n\nINLINE void RangeDecoderInit(\n    ISequentialInStream *in_stream, \n    CRangeDecoder *rangeDecoder)\n  {\n    int i;\n    rangeDecoder->m_Code = 0;\n    rangeDecoder->m_Range = (UINT32)(-1);\n    for(i = 0; i < 5; i++)\n      rangeDecoder->m_Code = (rangeDecoder->m_Code << 8) | InStreamReadByte(in_stream);\n  }\n\nINLINE UINT32 RangeDecodeDirectBits(\n    ISequentialInStream *in_stream, \n    CRangeDecoder *rangeDecoder, \n    UINT32 aNumTotalBits)\n  {\n    UINT32 aRange = rangeDecoder->m_Range;\n    UINT32 aCode = rangeDecoder->m_Code;        \n    UINT32 aResult = 0;\n    UINT32 i;\n    for (i = aNumTotalBits; i > 0; i--)\n    {\n      UINT32 t;\n      aRange >>= 1;\n      t = (aCode - aRange) >> 31;\n      aCode -= aRange & (t - 1);\n      aResult = (aResult << 1) | (1 - t);\n\n      if (aRange < kTopValue)\n      {\n        aCode = (aCode << 8) | InStreamReadByte(in_stream);\n        aRange <<= 8; \n      }\n    }\n    rangeDecoder->m_Range = aRange;\n    rangeDecoder->m_Code = aCode;\n    return aResult;\n  }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/WindowOut.h",
    "content": "#ifndef __STREAM_WINDOWOUT_H\n#define __STREAM_WINDOWOUT_H\n\n#include \"IInOutStreams.h\"\n\ntypedef struct WindowOut\n{\n  BYTE  *Buffer;\n  UINT32 Pos;\n} WindowOut;\n\nextern WindowOut out_window;\n\n#define OutWindowInit() \\\n  { \\\n    out_window.Buffer = (BYTE *) out_stream.data; \\\n    out_window.Pos = 0; \\\n  }\n\n#define OutWindowFlush() \\\n  { \\\n    OutStreamSizeSet( out_window.Pos ); \\\n  } \n\n// BRCM modification \nINLINE void OutWindowCopyBackBlock(UINT32 aDistance, UINT32 aLen)\n  {\n    BYTE   *p = out_window.Buffer + out_window.Pos;\n    UINT32  i;\n    aDistance++;\n    for(i = 0; i < aLen; i++)\n      p[i] = p[i - aDistance];\n    out_window.Pos += aLen;\n  }\n\n\n#define OutWindowPutOneByte(aByte) \\\n  { \\\n    out_window.Buffer[out_window.Pos++] = aByte; \\\n  } \n\n#define OutWindowGetOneByte(anIndex) \\\n     (out_window.Buffer[out_window.Pos + anIndex])\n\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/lzma/decompress/vxTypesOld.h",
    "content": "/* vxTypesOld.h - old VxWorks type definition header */\n\n/* Copyright 1984-1997 Wind River Systems, Inc. */\n\n/*\nmodification history\n--------------------\n02c,15aug97,cym  added simnt support.\n02d,26mar97,cdp  added Thumb (ARM7TDMI_T) support.\n02c,28nov96,cdp  added ARM support.\n02b,28sep95,ms\t removed \"static __inline__\" (SPR #4500)\n02b,12jul95,ism  added simsolaris support\n02a,19mar95,dvs  removed tron references.\n01z,01sep94,ism  fixed comment as per SPR# 1512.\n01y,02dec93,pme  added Am29K family support.\n01x,12jun93,rrr  vxsim.\n02a,26may94,yao  added PPC support.\n01w,09jun93,hdn  added support for I80X86\n01v,12feb93,srh  added C++ versions of FUNCPTR, et al.\n01u,13nov92,dnw  added definition of VOID (SPR #1781)\n01t,02oct92,srh  replaced conditional around volatile, const, and signed so\n                 they won't be elided when __STDC__ is defined.\n                 added __cplusplus to __STDC__ condition.\n01s,22sep92,rrr  added support for c++\n01r,08sep92,smb  made some additions for the MIPS.\n01q,07sep92,smb  added __STDC__ and modes to maintain compatibility with 5.0\n01p,07jul92,rrr  moved STACK_GROW and ENDIAN to vxArch.h\n01o,03jul92,smb  changed name from vxTypes.h.\n01n,26may92,rrr  the tree shuffle\n01m,25nov91,llk  included sys/types.h.\n01l,04oct91,rrr  passed through the ansification filter\n\t\t  -fixed #else and #endif\n\t\t  -removed TINY and UTINY\n\t\t  -changed VOID to void\n\t\t  -changed ASMLANGUAGE to _ASMLANGUAGE\n\t\t  -changed copyright notice\n01k,01oct91,jpb  fixed MIPS conditional for undefined CPU_FAMILY.\n01j,20sep91,wmd  conditionalized out defines for const, unsigned and volatile\n\t\t for the MIPS architecture.\n01i,02aug91,ajm  added support for MIPS_R3k.\n01h,15may91,gae  added define for \"signed\" when not available for pre-ANSI.\n01g,29apr91,hdn  added defines and macros for TRON architecture.\n01f,28apr91,del  added defines of __volatile__ and __const__ if !_STDC_\n\t\t && _GNUC__\n01f,24mar91,del  added INSTR * define for I960.\n01e,28jan91,kdl  added DBLFUNCPTR and FLTFUNCPTR.\n01d,25oct90,dnw  changed void to void except when linting.\n01c,05oct90,shl  added copyright notice.\n                 made #endif ANSI style.\n01b,10aug90,dnw  added VOIDFUNCPTR\n01a,29may90,del  written.\n*/\n\n/*\nDESCRIPTION\nThis header file contains a mixture of stuff.\n1) the old style typedefs (ie. POSIX now says they must end with _t).\n   These will be phased out gradually.\n2) a mechanism for getting rid of const warning which are produced by the\n   GNU C compiler. Hopefully, this will be removed in the future.\n3) macros that are so longer needed for vxWorks source code but maybe needed\n   by some customer applications and are therefore provided for backward\n   compatability.\n4) system III typedefs (used by netinet) which do not fit in anywhere else.\n\n*/\n\n#ifndef __INCvxTypesOldh\n#define __INCvxTypesOldh\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"sys/types.h\"\n\n/* vxWorks types */\n\ntypedef\tchar\t\tINT8;\ntypedef\tshort\t\tINT16;\ntypedef\tint\t\tINT32;\n\ntypedef\tunsigned char\tUINT8;\ntypedef\tunsigned short\tUINT16;\ntypedef\tunsigned int\tUINT32;\n\ntypedef\tunsigned char\tUCHAR;\ntypedef unsigned short\tUSHORT;\ntypedef\tunsigned int\tUINT;\ntypedef unsigned long\tULONG;\n\ntypedef\tint\t\tBOOL;\ntypedef\tint\t\tSTATUS;\ntypedef int \t\tARGINT;\n\ntypedef void\t\tVOID;\n\n#ifdef __cplusplus\ntypedef int \t\t(*FUNCPTR) (...);     /* ptr to function returning int */\ntypedef void \t\t(*VOIDFUNCPTR) (...); /* ptr to function returning void */\ntypedef double \t\t(*DBLFUNCPTR) (...);  /* ptr to function returning double*/\ntypedef float \t\t(*FLTFUNCPTR) (...);  /* ptr to function returning float */\n#else\ntypedef int \t\t(*FUNCPTR) ();\t   /* ptr to function returning int */\ntypedef void \t\t(*VOIDFUNCPTR) (); /* ptr to function returning void */\ntypedef double \t\t(*DBLFUNCPTR) ();  /* ptr to function returning double*/\ntypedef float \t\t(*FLTFUNCPTR) ();  /* ptr to function returning float */\n#endif\t\t\t/* _cplusplus */\n\n\n/* This structure and the following definitions are needed to get rid\n   of const warning produced by the GNU C compiler.\n */\n\n#if defined(__STDC__) || defined(__cplusplus)\ntypedef union\n    {\n    long pm_int;\n    void *pm_v;\n    const void *pm_cv;\n    char *pm_c;\n    unsigned char *pm_uc;\n\n    signed char *pm_sc;\n    const char *pm_cc;\n    const unsigned char *pm_cuc;\n    const signed char *pm_csc;\n    short *pm_s;\n    ushort_t *pm_us;\n    const short *pm_cs;\n    const ushort_t *pm_cus;\n    int *pm_i;\n    uint_t *pm_ui;\n    const int *pm_ci;\n    const uint_t *pm_cui;\n    long *pm_l;\n    ulong_t *pm_ul;\n    const long *pm_cl;\n    const ulong_t *pm_cul;\n\n    int8_t *pm_i8;\n    uint8_t *pm_ui8;\n    const int8_t *pm_ci8;\n    const uint8_t *pm_cui8;\n    int16_t *pm_i16;\n    uint16_t *pm_ui16;\n    const int16_t *pm_ci16;\n    const uint16_t *pm_cui16;\n    int32_t *pm_i32;\n    uint32_t *pm_ui32;\n    const int32_t *pm_ci32;\n    const uint32_t *pm_cui32;\n#if _ARCH_MOVE_SIZE > 4\n    int64_t *pm_i64;\n    const int64_t *pm_ci64;\n#if _ARCH_MOVE_SIZE > 8\n    int128_t *pm_i128;\n    const int128_t *pm_ci128;\n#endif\n#endif\n    } pointer_mix_t;\n\n#define CHAR_FROM_CONST(x)\t(char *)(x)\n#define VOID_FROM_CONST(x)\t(void *)(x)\n\n#endif /* __STDC__ */\n\n#define STACK_DIR\t\t_ARCH_STACK_DIR\n#define ALIGN_MEMORY\t\t_ARCH_ALIGN_MEMORY\n#define ALIGN_STACK\t\t_ARCH_ALIGN_STACK\n#define ALIGN_REGS\t\t_ARCH_ALIGN_REGS\n\n#define\tNBBY\t8\t\t/* number of bits in a byte */\n\n/* modes - must match O_RDONLY/O_WRONLY/O_RDWR in ioLib.h! */\n\n#define READ            0\n#define WRITE           1\n#define UPDATE          2\n\n/* Select uses bit masks of file descriptors in longs.\n * These macros manipulate such bit fields (the filesystem macros use chars).\n * FD_SETSIZE may be defined by the user, but the default here\n * should be >= maxFiles parameter in iosInit call found in usrConfig.c.\n * If this define is changed, recompile the source, or else select() will\n * not work.\n */\n\n#ifndef\tFD_SETSIZE\n#define\tFD_SETSIZE\t256\n#endif\t/* FD_SETSIZE */\n\ntypedef long\tfd_mask;\n#define NFDBITS\t(sizeof(fd_mask) * NBBY)\t/* bits per mask */\n#ifndef howmany\n#define\thowmany(x, y)\t((unsigned int)(((x)+((y)-1)))/(unsigned int)(y))\n#endif\t/* howmany */\n\ntypedef\tstruct fd_set\n    {\n    fd_mask\tfds_bits[howmany(FD_SETSIZE, NFDBITS)];\n    } fd_set;\n\n#define\tFD_SET(n, p)\t((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))\n#define\tFD_CLR(n, p)\t((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))\n#define\tFD_ISSET(n, p)\t((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))\n#define FD_ZERO(p)\tbzero((char *)(p), sizeof(*(p)))\n\n\n/* system III  typedefs (used by netinet) */\n\ntypedef\tunsigned char\tu_char;\ntypedef\tunsigned short\tu_short;\ntypedef\tunsigned int\tu_int;\ntypedef\tunsigned long\tu_long;\ntypedef\tunsigned short\tushort;\n\n\n/* historical definitions - now obsolete */\n\ntypedef char\t\tTBOOL;\t\t/* obsolete */\n\n\n/* architecture dependent typedefs */\n\n#ifdef\tCPU_FAMILY\n\n#if\tCPU_FAMILY==MC680X0 \ntypedef unsigned short INSTR;\t\t/* word-aligned instructions */\n#endif\t/* CPU_FAMILY==MC680X0 */\n\n#if\tCPU_FAMILY==SPARC || CPU_FAMILY==MIPS || CPU_FAMILY==SIMSPARCSUNOS || CPU_FAMILY==SIMHPPA || CPU_FAMILY==SIMSPARCSOLARIS\ntypedef unsigned long INSTR;\t\t/* 32 bit word-aligned instructions */\n#endif\t/* CPU_FAMILY==SPARC || CPU_FAMILY==MIPS || CPU_FAMILY==SIMSPARCSUNOS || CPU_FAMILY==SIMHPPA || CPU_FAMILY==SIMSPARCSOLARIS */\n\n#if\tCPU_FAMILY==I960\ntypedef\tunsigned long INSTR;\t\t/* 32 bit word-aligned instructions */\n#endif\t/* CPU_FAMILY==I960 */\n\n#if\tCPU_FAMILY==I80X86 || CPU_FAMILY==SIMNT\ntypedef\tunsigned char INSTR;\t\t/* char instructions */\n#endif\t/* CPU_FAMILY==I80X86 || CPU_FAMILY==SIMNT */\n\n#if\tCPU_FAMILY==AM29XXX\ntypedef\tunsigned long INSTR;\t\t/* 32 bit word-aligned instructions */\n#endif\t/* CPU_FAMILY==AM29XXX */\n\n#if     (CPU_FAMILY==PPC)\ntypedef unsigned long INSTR;            /* 32 bit word-aligned instructions */\n#endif  /* (CPU_FAMILY==PPC) */\n\n#if     CPU_FAMILY==ARM\n#if\tCPU==ARM7TDMI_T\ntypedef unsigned short INSTR;           /* 16 bit instructions */\n#else\ntypedef unsigned long INSTR;            /* 32 bit word-aligned instructions */\n#endif\n#endif  /* CPU_FAMILY==ARM */\n\n#endif\t/* CPU_FAMILY */\n\n/* ANSI type qualifiers */\n\n#if !defined(__STDC__) && !defined(__cplusplus)\n\n#ifdef  __GNUC__\n#define\tvolatile\t__volatile__\n#define\tconst\t\t__const__\n#define\tsigned\t\t__signed__\n#else\n#if     !(defined(CPU_FAMILY) && CPU_FAMILY==MIPS)\n#define\tvolatile\n#define\tconst\n#define\tsigned\n#endif\t/* !(defined(CPU_FAMILY) && CPU_FAMILY==MIPS) */\n#endif\t/* __GNUC__ */\n\n#endif\t/* !defined(__STDC__) && !defined(__cplusplus) */\n\n#if     CPU_FAMILY==MIPS\n#define CHAR_FROM_CONST(x)\t(char *)(x)\n#define VOID_FROM_CONST(x)\t(void *)(x)\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* __INCvxTypesOldh */\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/squashfs/Makefile",
    "content": "INCLUDEDIR = .\n\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\n\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\t$(CC) mksquashfs.o read_fs.o sort.o -lz -o $@\n\nmksquashfs.o: mksquashfs.c mksquashfs.h\n\nread_fs.o: read_fs.c read_fs.h\n\nsort.o: sort.c\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/squashfs/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define TRUE 1\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#ifdef __MACOSX__\n  #define __BYTE_ORDER BYTE_ORDER\n  #define __BIG_ENDIAN BIG_ENDIAN\n  #define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n  #include <endian.h>\n#endif\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/mman.h>\n\n#include \"mksquashfs.h\"\n#include <squashfs_fs.h>\n/* BRCM begin */\n#include <stdarg.h>\n#include \"7zapi.h\"\n/* BRCM end */\n\n/* Exit codes used by mkfs-type programs */\n#define MKFS_OK          0\t/* No errors */\n#define MKFS_ERROR       8\t/* Operational error */\n#define MKFS_USAGE       16\t/* Usage or syntax error */\n\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tprintf(\"mksquashfs: \"s, ## args)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { if(!silent) printf(\"mksquashfs: \"s, ## args); } while(0)\n#define ERROR(s, args...)\t\tdo { fprintf(stderr, s, ## args); } while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { if(restore)\\\n\t\t\t\t\trestorefs();\\\n\t\t\t\t\texit(1); } while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0)\n\n/* the GNU C library has a wonderful scanf(\"%as\", string) which will\n allocate the string with the right size, good to avoid buffer overruns. \n the following macros use it if available or use a hacky workaround...\n */\n\n#ifdef __GNUC__\n#define SCANF_PREFIX \"a\"\n#define SCANF_STRING(s) (&s)\n#define GETCWD_SIZE 0\n#else\n#define SCANF_PREFIX \"511\"\n#define SCANF_STRING(s) (s = xmalloc(512))\n#define GETCWD_SIZE -1\ninline int snprintf(char *str, size_t n, const char *fmt, ...)\n{\n\tint ret;\n\tva_list ap;\n\n\tva_start(ap, fmt);\n\tret = vsprintf(str, fmt, ap);\n\tva_end(ap);\n\treturn ret;\n}\n#endif \n\nstatic FILE *devtable = NULL;\n\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint total_compressed = 0, total_uncompressed = 0;\n\nint fd;\n\n/* superblock attributes */\nint noI = 0, noD = 0, check_data = 0, block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\n\n/* write position within data section */\nunsigned int bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* in memory directory header */\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tsquashfs_dir_header\t*entry_count_p;\n};\n\nstruct file_info *dupl[65536], *frag_dups[65536];\nint dup_files = 0;\n\nint swap, silent = TRUE;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nstatic char *fragment_data;\nstatic int fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n\n\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\nchar dev_path[1024];\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n};\n\n/* in memory file info */\nstruct file_info {\n\tunsigned int\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned int\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tunsigned short\t\tfragment_checksum;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\nunsigned int sbytes, sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_bytes, stotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sdup_files;\nint sfragments;\nint restore = 0;\n\n/*flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\nlong long global_uid = -1, global_gid = -1;\n\n/* structure to used to pass in a pointer or an integer\n * to duplicate buffer read helper functions.\n */\nstruct duplicate_buffer_handle {\n\tunsigned char\t*ptr;\n\tunsigned int\tstart;\n};\n\nstruct old_root_entry_info *old_root_entry;\nvoid add_old_root_entry(char *name, squashfs_inode inode, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern int read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **inode_table, int *inode_bytes,\n\t\tchar **data_cache, int *cache_bytes, int *cache_size, char **directory_table, int *directory_bytes,\n\t\tchar **directory_data_cache, int *directory_cache_bytes, int *directory_cache_size,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\t\tsquashfs_uid *uids, unsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tunsigned int *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int), squashfs_fragment_entry **fragment_table);\nsquashfs_inode get_sorted_inode(struct stat *buf);\nint read_sort_file(char *filename, int source, char *source_path[]);\nvoid sort_files_and_write(int source, char *source_path[]);\nstruct file_info *duplicate(unsigned char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, int bytes, unsigned int **block_list, int *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes);\n\n#define FALSE 0\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n/* BRCM begin */\n#define LZMA\t0\n#define GZIP\t1\nint compress_algorithm = LZMA; \n/* BRCM end */\n\nstatic void verror_msg(const char *s, va_list p)\n{\n\tfflush(stdout);\n\tfprintf(stderr, \"mkcramfs: \");\n\tvfprintf(stderr, s, p);                         \n}\n\nstatic void vperror_msg(const char *s, va_list p)\n{\n\tint err = errno;\n\n\tif (s == 0)\n\t\ts = \"\";\n\tverror_msg(s, p);\n\tif (*s)\n\t\ts = \": \";\n\tfprintf(stderr, \"%s%s\\n\", s, strerror(err));\n}\n\nstatic void perror_msg(const char *s, ...)\n{\n\tva_list p;\n\n\tva_start(p, s);\n\tvperror_msg(s, p);\n\tva_end(p);\n}\n\nstatic void error_msg_and_die(const char *s, ...)\n{\n\tva_list p;\n\n\tva_start(p, s);\n\tverror_msg(s, p);\n\tva_end(p);\n\tputc('\\n', stderr);\n\texit(MKFS_ERROR);\n}\n\nstatic void perror_msg_and_die(const char *s, ...)\n{\n\tva_list p;\n\n\tva_start(p, s);\n\tvperror_msg(s, p);\n\tva_end(p);\n\texit(MKFS_ERROR);\n}\n\nstatic FILE *xfopen(const char *path, const char *mode)\n{\n\tFILE *fp;\n\n\tif ((fp = fopen(path, mode)) == NULL)\n\t\tperror_msg_and_die(\"%s\", path);\n\treturn fp;\n}\n\nvoid restorefs()\n{\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(interrupted == 1)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t\tinterrupted ++;\n\t}\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\n\t/* BRCM begin */\n\tif (compress_algorithm == GZIP) {\n\t\tc_byte = block_size << 1;\n\t\tif(!uncompressed && (res = compress2(d, &c_byte, s, size, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\t\t\t\n\t}\n\n\tif (compress_algorithm == LZMA) {\n\t\tunsigned lzma_algo;\n\t\tunsigned lzma_dictsize;\n\t\tunsigned lzma_fastbytes;\n\t\tint opt_compression_level = 1;\n\n\t\tc_byte = block_size << 3;\n\t\tswitch (opt_compression_level) {\n\t\tcase 1 :\n\t\t\tlzma_algo = 1;\n\t\t\tlzma_dictsize = 1 << 20;\n\t\t\tlzma_fastbytes = 64;\n\t\t\tbreak;\n\t\tcase 2 :\n\t\t\tlzma_algo = 2;\n\t\t\tlzma_dictsize = 1 << 22;\n\t\t\tlzma_fastbytes = 128;\n\t\t\tbreak;\n\t\tcase 3 :\n\t\t\tlzma_algo = 2;\n\t\t\tlzma_dictsize = 1 << 24;\n\t\t\tlzma_fastbytes = 255;\n\t\t\tbreak;\n\t\tdefault :\n\t\t\tBAD_ERROR(\"Invalid LZMA compression level. Must be 1,2,3.\");\n\t\t\treturn 0;\n\t\t}\n\t\tif(!uncompressed && !(res = compress_lzma_7zapi((const unsigned char*)s, \n\t\t\t\t\t\t\t\t(unsigned)size, \n\t\t\t\t\t\t\t\t(unsigned char*)d,\n\t\t\t\t\t\t\t\t(unsigned *)&c_byte,\n\t\t\t\t\t\t\t\tlzma_algo, lzma_dictsize, lzma_fastbytes))) {\n\t\t\t/* this should NEVER happen */\n\t\t\tBAD_ERROR(\"Internal error - LZMA compression failed.\\n\");\n\t\t\treturn 0;\n\t\t}\n\t\t//printf(\"LZMA: block_size=%d, in_size=%d, out_size=%d\\n\", block_size, size, c_byte);\n\t}\n\t/* BRCM end */\n\t\n\tif(uncompressed || c_byte >= size) {\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy((void *) (inode_table + inode_bytes), (void *) &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, unsigned int byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nvoid write_bytes(int fd, unsigned int byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(off + bytes > ((long long)1<<32) - 1 )\n\t\tBAD_ERROR(\"Filesystem greater than maximum size 2^32 - 1\\n\");\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nunsigned int write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tunsigned int start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy((void *) (inode_table + inode_bytes), (void *) &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tunsigned int start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy((void *) (directory_table + directory_bytes), (void *) &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nsquashfs_inode create_inode(char *filename, int type, int byte_size,\nsquashfs_block start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct stat* devtable_inode_info)\n{\n\tsquashfs_inode i_no;\n\tstruct stat buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\n\tif(filename[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t} else \n   /* We set st_mode different than 0 for all files in the device table list.\n   ** That is how we \"recognize\" that the file is from the device table list.\n   ** For files not in the table list st_mode is initially set to 0 and \n   ** then reinitialized using lstat */\n   if ( devtable_inode_info != NULL && devtable_inode_info->st_mode != 0 ) {\n      buf.st_mode = devtable_inode_info->st_mode;\n      buf.st_rdev = devtable_inode_info->st_rdev;\n      buf.st_uid = devtable_inode_info->st_uid;\n      buf.st_gid = devtable_inode_info->st_gid;\n      buf.st_mtime = time(NULL);;\n\t} else if(lstat(filename, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\tperror(buffer);\n\t\treturn SQUASHFS_INVALID;\n\t}\n\n\tbase->mode = SQUASHFS_MODE(buf.st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf.st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf.st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf.st_gid : global_gid);\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n/* CONFIG_MIPS_BRCM Begin Broadcom changed code. */\n/* GCC4.0 does not like two assigns and a cast in one line.  Split them up. */\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n/* CONFIG_MIPS_BRCM end Broadcom changed code. */\n\n\t\treg->mtime = buf.st_mtime;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy((void *) inodep, (void *) reg, sizeof(*reg));\n\t\t\tmemcpy((void *) inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %x, blocks %d, fragment %d, offset %d, size %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->mtime = buf.st_mtime;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tif(!swap)\n\t\t\tmemcpy((void *) inode, (void *) dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %x, offset %x\\n\", byte_size,\n\t\t\tstart_block, offset);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->rdev = (unsigned short) ((major(buf.st_rdev) << 8) |\n\t\t\t(minor(buf.st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy((void *) inode, (void *) dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x\\n\", dev->rdev);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn SQUASHFS_INVALID;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn SQUASHFS_INVALID;\n\t\t}\n\n/* CONFIG_MIPS_BRCM Begin Broadcom changed code. */\n/* GCC4.0 does not like two assigns and a cast in one line.  Split them up. */\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n/* CONFIG_MIPS_BRCM end Broadcom changed code. */\n\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy((void *) inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d\\n\",\t byte);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tif(!swap)\n\t\t\tmemcpy((void *) inode, (void *) ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\");\n\t} else\n\t\treturn SQUASHFS_INVALID;\n\n\ti_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%Lx, type %d, uid %d, guid %d\\n\", i_no, type, base->uid, base->guid);\n\n\treturn i_no;\n}\n\n\nvoid init_dir(struct directory *dir)\n{\n\tif((dir->buff = (char *)malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n}\n\n\nvoid add_dir(squashfs_inode inode, char *name, int type, struct directory *dir)\n{\n\tchar *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + 6 >= dir->buff + dir->size) {\n\t\tif((buff = (char *) realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (squashfs_dir_header *) (((unsigned char *) dir->entry_count_p) -\n\t\t\t\tdir->buff + buff);\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy((void *) dir->entry_count_p, (void *) &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), dir->entry_count_p);\n\t\t}\n\n\t\tdir->entry_count_p = (squashfs_dir_header *) dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tif(!swap)\n\t\tmemcpy((void *) idirp, (void *) &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nsquashfs_inode write_dir(char *filename, struct directory *dir)\n{\n\tsquashfs_inode inode;\n\tunsigned int dir_size;\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(directory_cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy((void *) directory_table + directory_bytes, (void *) &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdir_size = dir->p - dir->buff;\n\tdata_space = (directory_cache_size - directory_cache_bytes);\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tif(!swap)\n\t\t\tmemcpy((void *) dir->entry_count_p, (void *) &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\n\tinode = create_inode(filename, SQUASHFS_DIR_TYPE, dir_size, directory_bytes, directory_cache_bytes, NULL, NULL, NULL);\n\n\tdirectory_cache_bytes += dir_size;\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%Lx\\n\", inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn inode;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment)\n{\n\tif(fragment->index == fragments || fragment->index == SQUASHFS_INVALID_BLK)\n\t\treturn fragment_data + fragment->offset;\n\telse {\n\t\tsquashfs_fragment_entry *disk_fragment = &fragment_table[fragment->index];\n\t\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size), res;\n\t\tlong bytes = block_size;\n\n\t\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\t\tchar cbuffer[block_size];\n\n\t\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\n\t\t\tif((res = uncompress(buffer, &bytes, (const char *) cbuffer, size)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\t\telse\n\t\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t}\n\t\t} else\n\t\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\t\treturn buffer + fragment->offset;\n\t}\n}\n\n\t\nvoid write_fragment()\n{\n\tint compressed_size;\n\tunsigned char buffer[block_size << 1];\n\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tif(fragments % FRAG_SIZE == 0)\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\tfragment_table[fragments].size = mangle(buffer, fragment_data, fragment_size, block_size, noF, 1);\n\tfragment_table[fragments].start_block = bytes;\n\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(fragment_table[fragments].size);\n\twrite_bytes(fd, bytes, compressed_size, buffer);\n\tbytes += compressed_size;\n\ttotal_uncompressed += fragment_size;\n\ttotal_compressed += compressed_size;\n\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\",fragments, fragment_size, compressed_size);\n\tfragments ++;\n\tfragment_size = 0;\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_BLK, 0, 0};\nstruct fragment *get_and_fill_fragment(char *buff, int size)\n{\n\tstruct fragment *ffrg;\n\n\tif(size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = size;\n\tmemcpy(fragment_data + fragment_size, buff, size);\n\tfragment_size += size;\n\n\treturn ffrg;\n}\n\n\nunsigned int write_fragment_table()\n{\n\tunsigned int start_bytes, frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments),\n\t\tmeta_blocks = SQUASHFS_FRAGMENT_INDEXES(fragments);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2], buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tunsigned short c_byte;\n\tint i, compressed_size;\n\tsquashfs_fragment_index list[meta_blocks];\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d, meta_blocks %d\\n\", fragments, frag_bytes, meta_blocks);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %x, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy((void *) p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = i == meta_blocks - 1 ? frag_bytes % SQUASHFS_METADATA_SIZE : SQUASHFS_METADATA_SIZE;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, noF, 0);\n\t\tif(!swap)\n\t\t\tmemcpy((void *) cbuffer, (void *) &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tsquashfs_fragment_index slist[meta_blocks];\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\treturn start_bytes;\n}\n\n\nunsigned char *read_from_buffer(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tunsigned char *v = handle->ptr;\n\thandle->ptr += avail_bytes;\t\n\treturn v;\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nunsigned char *read_from_file(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tread_bytes(fd, handle->start, avail_bytes, read_from_file_buffer);\n\thandle->start += avail_bytes;\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(unsigned char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *handle, int l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes = 0;\n\tunsigned char *b;\n\tstruct duplicate_buffer_handle position = *handle;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tb = get_next_file_block(&position, bytes);\n\t\twhile(bytes--) {\n\t\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\t\tchksum += *b++;\n\t\t}\n\t}\n\n\treturn chksum;\n}\n\n\nstatic unsigned int cached_frag = -1;\nvoid add_file(int start, int file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tstruct file_info *dupl_ptr;\n\tchar *datap;\n\tstruct duplicate_buffer_handle handle;\n\t\n\tif(!duplicate_checking)\n\t\treturn;\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\tif(cached_frag == fragment)\n\t\tdatap = fragment_data + offset;\n\telse\n\t\tdatap = get_fragment(fragment_data, frg);\n\thandle.start = start;\n\tif((dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &frg, datap, bytes)) != NULL)\n\t\tdupl_ptr->fragment = frg;\n\tcached_frag = fragment;\n}\n\n\nstruct file_info *duplicate(unsigned char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, int bytes, unsigned int **block_list, int *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes)\n{\n\tunsigned short checksum = get_checksum(get_next_file_block, file_start, bytes);\n\tstruct duplicate_buffer_handle handle = { frag_data, 0 };\n\tunsigned short fragment_checksum = get_checksum(read_from_buffer, &handle, frag_bytes);\n\tstruct file_info *dupl_ptr = bytes ? dupl[checksum] : frag_dups[fragment_checksum];\n\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size && fragment_checksum == dupl_ptr->fragment_checksum) {\n\t\t\tunsigned char buffer1[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tunsigned int dup_bytes = dupl_ptr->bytes, dup_start = dupl_ptr->start;\n\t\t\tstruct duplicate_buffer_handle position = *file_start;\n\t\t\tunsigned char *buffer;\n\t\t\twhile(dup_bytes) {\n\t\t\t\tint avail_bytes = dup_bytes > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : dup_bytes;\n\n\t\t\t\tbuffer = get_next_file_block(&position, avail_bytes);\n\t\t\t\tread_bytes(fd, dup_start, avail_bytes, buffer1);\n\t\t\t\tif(memcmp(buffer, buffer1, avail_bytes) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_bytes -= avail_bytes;\n\t\t\t\tdup_start += avail_bytes;\n\t\t\t}\n\t\t\tif(dup_bytes == 0) {\n\t\t\t\tchar frag_buffer1[block_size];\n\t\t\t\tchar *fragment_buffer1 = get_fragment(frag_buffer1, dupl_ptr->fragment);\n\t\t\t\tif(frag_bytes == 0 || memcmp(frag_data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%x, size %d, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->start = *start;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tif((dupl_ptr->block_list = (unsigned int *) malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\t}\n\t\n\tmemcpy(dupl_ptr->block_list, *block_list, blocks * sizeof(unsigned int));\n\tdup_files ++;\n\tif(bytes) {\n\t\tdupl_ptr->next = dupl[checksum];\n\t\tdupl[checksum] = dupl_ptr;\n\t} else {\n\t\tdupl_ptr->next = frag_dups[fragment_checksum];\n\t\tfrag_dups[fragment_checksum] = dupl_ptr;\n\t}\n\n\treturn dupl_ptr;\n}\n\n\n#define MINALLOCBYTES (1024 * 1024)\nsquashfs_inode write_file(char *filename, long long size, int *duplicate_file)\n{\n\tunsigned int frag_bytes, file, start, file_bytes = 0, block = 0;\n\tunsigned int c_byte;\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\tunsigned int blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int block_list[blocks], *block_listp = block_list;\n\tchar buff[block_size], *c_buffer;\n\tint allocated_blocks = blocks, i, bbytes, whole_file = 1;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tstruct duplicate_buffer_handle handle;\n\n\tif(!no_fragments && (read_size < block_size || always_use_fragments)) {\n\t\tallocated_blocks = blocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %Ld bytes\\n\", filename, SQUASHFS_MAX_FILE_SIZE);\n\n\ttotal_bytes += read_size;\n\tif((file = open(filename, O_RDONLY)) == -1) {\n\t\tperror(\"Error in opening file, skipping...\");\n\t\treturn SQUASHFS_INVALID;\n\t}\n\n\tdo {\n\t\tif((c_buffer = (char *) malloc((allocated_blocks + 1) << block_log)) == NULL) {\n\t\t\tTRACE(\"Out of memory allocating write_file buffer, allocated_blocks %d, blocks %d\\n\", allocated_blocks, blocks);\n\t\t\twhole_file = 0;\n\t\t\tif((allocated_blocks << (block_log - 1)) < MINALLOCBYTES)\n\t\t\t\tBAD_ERROR(\"Out of memory allocating write_file buffer, could not allocate %d blocks (%d Kbytes)\\n\", allocated_blocks, allocated_blocks << (block_log - 10));\n\t\t\tallocated_blocks >>= 1;\n\t\t}\n\t} while(!c_buffer);\n\n\tfor(start = bytes; block < blocks; file_bytes += bbytes) {\n\t\tfor(i = 0, bbytes = 0; (i < allocated_blocks) && (block < blocks); i++) {\n\t\t\tint available_bytes = read_size - (block * block_size) > block_size ? block_size : read_size - (block * block_size);\n\t\t\tif(read(file, buff, available_bytes) == -1)\n\t\t\t\tgoto read_err;\n\t\t\tc_byte = mangle(c_buffer + bbytes, buff, available_bytes, block_size, noD, 1);\n\t\t\tblock_list[block ++] = c_byte;\n\t\t\tbbytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\t}\n\t\tif(!whole_file) {\n\t\t\twrite_bytes(fd, bytes, bbytes, c_buffer);\n\t\t\tbytes += bbytes;\n\t\t}\n\t}\n\n\tif(frag_bytes != 0)\n\t\tif(read(file, buff, frag_bytes) == -1)\n\t\t\tgoto read_err;\n\n\tclose(file);\n\tif(whole_file) {\n\t\thandle.ptr = c_buffer;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_buffer, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t\twrite_bytes(fd, bytes, file_bytes, c_buffer);\n\t\tbytes += file_bytes;\n\t} else {\n\t\thandle.start = start;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\tbytes = start;\n\t\t\tif(!block_device)\n\t\t\t\tftruncate(fd, bytes);\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t}\n\n\tfragment = get_and_fill_fragment(buff, frag_bytes);\n\tif(duplicate_checking)\n\t\tdupl_ptr->fragment = fragment;\n\n\t*duplicate_file = FALSE;\n\nwr_inode:\n\tfree(c_buffer);\n\tfile_count ++;\n\treturn create_inode(filename, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tfree(c_buffer);\n\treturn SQUASHFS_INVALID;\n}\n\n\nstruct linuxdir {\n\tDIR\t*linuxdir;\n\tchar\tpathname[8192];\n};\n\n\nvoid *linux_opendir(char *pathname, struct directory *dir)\n{\n\tstruct linuxdir *linuxdir;\n\tif((linuxdir = malloc(sizeof(struct linuxdir))) == NULL)\n\t\treturn NULL;\n\tif((linuxdir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(linuxdir);\n\t\treturn NULL;\n\t}\n\tstrcpy(linuxdir->pathname, pathname);\n\treturn (void *) linuxdir;\n}\n\n\nint linux_readdir(void *l, char *filename, char *dir_name, struct stat* devtable_inode_info)\n{\n\tstruct dirent *d_name;\n\tstruct linuxdir *linuxdir = (struct linuxdir *)l;\n\n\tdevtable_inode_info->st_mode = 0;\n\n\tdo {\n\t\tif((d_name = readdir(linuxdir->linuxdir)) == NULL)\n\t\t{\n\t\t\tif ( strncmp(linuxdir->pathname, dev_path, sizeof(linuxdir->pathname)) == 0 )\n\t\t\t{\n\t\t\t   if ( devtable_readdir(l, filename, dir_name, devtable_inode_info ) )\n\t\t\t   {\n\t\t\t      return( TRUE );\n\t\t\t   }\n\t\t\t}\n\t\t\treturn FALSE;\n\t\t}\n\t} while(strcmp(d_name->d_name, \".\") == 0 || strcmp(d_name->d_name, \"..\") == 0);\n\tstrcat(strcat(strcpy(filename, linuxdir->pathname), \"/\"), d_name->d_name);\n\tstrcpy(dir_name, d_name->d_name);\n\treturn TRUE;\n}\n\n\nvoid linux_closedir(void *linuxdir)\n{\n\tclosedir(((struct linuxdir *)linuxdir)->linuxdir);\n\tfree(linuxdir);\n}\n\n\nstatic int interpret_table_entry(char *line, char* filename, char* dirname, struct stat* devtable_inode_info)\n{\n\tchar type, *name = NULL;\n\tchar* full;\n\tunsigned long mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;\n\tunsigned long start = 0, increment = 1, count = 0;\n\n\tif (sscanf (line, \"%\" SCANF_PREFIX \"s %c %lo %lu %lu %lu %lu %lu %lu %lu\",\n\t\t SCANF_STRING(name), &type, &mode, &uid, &gid, &major, &minor,\n\t\t &start, &increment, &count) < 0) \n\t{\n\t\treturn 1;\n\t}\n\n\tif (!strcmp(name, \"/\")) {\n\t\terror_msg_and_die(\"Device table entries require absolute paths\");\n\t}\n\n\tstrcpy( filename, source_path[0] );\n\tstrcat( filename, name );\n\n   full = strdup( name );\n\tstrcpy( dirname, (char*)basename(full) );\n   free(full);\n\n\tswitch (type) {\n\tcase 'd':\n\t\tmode |= S_IFDIR;\n\t\tbreak;\n\tcase 'f':\n\t\tmode |= S_IFREG;\n\t\tbreak;\n\tcase 'p':\n\t\tmode |= S_IFIFO;\n\t\tbreak;\n\tcase 'c':\n\tcase 'b':\n\t\tmode |= (type == 'c') ? S_IFCHR : S_IFBLK;\n\t\tif (count > 0) {\n\t\t\tchar *buf;\n\t\t\tunsigned long i;\n\t\t\tdev_t rdev;\n\n\t\t\tfor (i = start; i < count; i++) {\n\t\t\t\tasprintf(&buf, \"%s%lu\", name, i);\n\t\t\t\trdev = makedev(major, minor + (i * increment - start));\n\t\t\t\tfree(buf);\n\t\t\t\tdevtable_inode_info->st_rdev = rdev;\n\t\t\t}\n\t\t} else {\n\t\t\tdev_t rdev = makedev(major, minor);\n\t\t\tdevtable_inode_info->st_rdev = rdev;\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\terror_msg_and_die(\"Unsupported file type\");\n\t}\n\tfree(name);\n\n\tdevtable_inode_info->st_mode = mode;\n\n\treturn 0;\n}\n\nint devtable_readdir(void *l, char *filename, char *dir_name, struct stat* devtable_inode_info)\n{\n\tchar *line;\n\tint status = FALSE;\n\tint commentLine = FALSE;\n\tsize_t length = 0;\n\n\tstrcpy(filename, \"\");\n\tstrcpy(dir_name, \"\");\n\n\t/* Looks ok so far.  The general plan now is to read in one\n\t * line at a time, check for leading comment delimiters ('#'),\n\t * then try and parse the line as a device table.  If we fail\n\t * to parse things, try and help the poor fool to fix their\n\t * device table with a useful error msg... */\n\tline = NULL;\n\tdo\n\t{\n\t\tif (getline(&line, &length, devtable) != -1) {\n\t\t\tstatus = TRUE;\n\t\t\t/* First trim off any whitespace */\n\t\t\tint len = strlen(line);\n\n\t\t\t/* trim trailing whitespace */\n\t\t\twhile (len > 0 && isspace(line[len - 1]))\n\t\t\t\tline[--len] = '\\0';\n\t\t\t/* trim leading whitespace */\n\t\t\tmemmove(line, &line[strspn(line, \" \\n\\r\\t\\v\")], len);\n\n\t\t\t/* How long are we after trimming? */\n\t\t\tlen = strlen(line);\n\n\t\t\t/* If this is NOT a comment line, try to interpret it */\n\t\t\tif (len && *line != '#') {\n\t\t\t\tcommentLine = FALSE;\n\t\t\tif (interpret_table_entry(line, filename, dir_name, devtable_inode_info))\n\t\t\t\t\tstatus = FALSE;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcommentLine = TRUE;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfree(line);\n\t\t\tline = NULL;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfree(line);\n\t\t}\n\t} while (commentLine == TRUE);\n\n\n\treturn status;\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nchar encomp_pathname[8192];\nint encomp_entry = 0;\n\nvoid *encomp_opendir(char *pathname, struct directory *dir)\n{\n\tint i;\n\n\tfor(i = 0; i < old_root_entries; i++)\n\t\tadd_dir(old_root_entry[i].inode, old_root_entry[i].name, old_root_entry[i].type, dir);\n\n\treturn (void *)source_path;\n}\n\n\nint encomp_readdir(void *l, char *filename, char *dir_name, struct stat* devtable_inode_info)\n{\n\tchar *basename;\n\tint n, pass = 1;\n\n\tdevtable_inode_info->st_mode = 0;\n\n\twhile(encomp_entry < source) {\n\t\tif((basename = getbase(source_path[encomp_entry])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[encomp_entry]);\n\t\t\tencomp_entry++;\n\t\t\tcontinue;\n\t\t}\n        \tstrcpy(filename, source_path[encomp_entry]);\n\t\tstrcpy(dir_name, basename);\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < old_root_entries && strcmp(old_root_entry[n].name, dir_name) != 0; n++);\n\t\t\tif(n == old_root_entries) {\n\t\t\t\tadd_old_root_entry(dir_name, 0, 0);\n\t\t\t\tencomp_entry++;\n\t\t\t\treturn TRUE;\n\t\t\t}\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t}\n\treturn FALSE;\n}\n\n\nvoid encomp_closedir(void *linuxdir)\n{\n}\n\n\nvoid *single_opendir(char *pathname, struct directory *dir)\n{\n\tencomp_opendir(pathname, dir);\n\treturn linux_opendir(pathname, dir);\n}\n\n\nint single_readdir(void *l, char *filename, char *dir_name, struct stat* devtable_inode_info)\n{\n\tint i, pass = 1;\n\tchar name[SQUASHFS_NAME_LEN + 1];\n\n\tdevtable_inode_info->st_mode = 0;\n\n\tif(linux_readdir(l, filename, dir_name, devtable_inode_info) == FALSE)\n\t\treturn FALSE;\n\n\tstrcpy(name, dir_name);\n\tfor(;;) {\n\t\tfor(i = 0; i < old_root_entries && strcmp(old_root_entry[i].name, dir_name) != 0; i++);\n\t\tif(i == old_root_entries) {\n\t\t\tadd_old_root_entry(dir_name, 0, 0);\n\t\t\treturn TRUE;\n\t\t}\n\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\tsprintf(dir_name, \"%s_%d\", name, pass++);\n\t\tERROR(\"%s\\n\", dir_name);\n\t}\n}\n\n\nsquashfs_inode dir_scan(char *pathname, void* (_opendir)(char *, struct directory *), int (_readdir)(void *, char *, char *, struct stat*),\n\t\tvoid (_closedir)(void *))\n{\n\tvoid *linuxdir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\tint squashfs_type;\n\tsquashfs_inode inode = SQUASHFS_INVALID;\n\tstruct directory dir;\n\n\tstruct stat devtable_inode_info;\n\tunsigned long mode;\n\tdevtable_inode_info.st_mode = 0;\n\t\n\tinit_dir(&dir);\n\tif((linuxdir = _opendir(pathname, &dir)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\t\n\twhile(_readdir(linuxdir, filename, dir_name, &devtable_inode_info) != FALSE) {\n\n\t\tmode = devtable_inode_info.st_mode;\n\n\t\tif ( devtable_inode_info.st_mode == 0 ) {\n\t\t\tif(lstat(filename, &buf) == -1) {\n\t\t\t\tchar buffer[8192];\n\t\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmode = buf.st_mode;\n\t\t}\n\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tswitch(mode & S_IFMT) {\n\t\t\tcase S_IFREG: {\n\t\t\t\tint duplicate_file;\n\n\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\tif(!sorted) {\n\t\t\t\t\tinode = write_file(filename, buf.st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %Ld bytes, %s\\n\", filename, buf.st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t} else\n\t\t\t\t\tinode = get_sorted_inode(&buf);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase S_IFDIR:\n\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\tinode = dir_scan(filename, linux_opendir, linux_readdir, linux_closedir);\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFLNK:\n\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\tinode = create_inode(filename, squashfs_type, 0, 0, 0, NULL, NULL, &devtable_inode_info);\n\t\t\t\tINFO(\"symbolic link %s inode 0x%Lx\\n\", dir_name, inode);\n\t\t\t\tsym_count ++;\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFCHR:\n\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\tinode = create_inode(filename, squashfs_type, 0, 0, 0, NULL, NULL, &devtable_inode_info);\n\t\t\t\tINFO(\"character device %s inode 0x%Lx\\n\", dir_name, inode);\n\t\t\t\tdev_count ++;\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFBLK:\n\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\tinode = create_inode(filename, squashfs_type, 0, 0, 0, NULL, NULL, &devtable_inode_info);\n\t\t\t\tINFO(\"block device %s inode 0x%Lx\\n\", dir_name, inode);\n\t\t\t\tdev_count ++;\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFIFO:\n\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\tinode = create_inode(filename, squashfs_type, 0, 0, 0, NULL, NULL, &devtable_inode_info);\n\t\t\t\tINFO(\"fifo %s inode 0x%Lx\\n\", dir_name, inode);\n\t\t\t\tfifo_count ++;\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFSOCK:\n\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\tinode = create_inode(filename, squashfs_type, 0, 0, 0, NULL, NULL, &devtable_inode_info);\n\t\t\t\tINFO(\"unix domain socket %s inode 0x%Lx\\n\", dir_name, inode);\n\t\t\t\tsock_count ++;\n\t\t\t\tbreak;\n\n\t\t\t default:\n\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, mode);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\tif(inode != SQUASHFS_INVALID)\n\t\t\tadd_dir(inode, dir_name, squashfs_type, &dir);\n\t}\n\n\t_closedir(linuxdir);\n\tinode = write_dir(pathname, &dir);\n\tINFO(\"directory %s inode 0x%Lx\\n\", pathname, inode);\n\nerror:\n\tfree(dir.buff);\n\n\treturn inode;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 9; i <= 16; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 2.0\\n\");\\\n\tprintf(\"copyright (C) 2004 Phillip Lougher (plougher@users.sourceforge.net)\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, delete = FALSE, keep_as_directory = FALSE, orig_be;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 512 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-D\") == 0) {\n\t\t\tTRACE(\"-D passed as parameter\\n\");\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -D missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tTRACE(\"devTable filename = %s\\n\", argv[i]);\n\t\t\tdevtable = xfopen(argv[i], \"r\");\n\t\t\tif (fstat(fileno(devtable), &buf) < 0)\n\t\t\t\tperror_msg_and_die(argv[i]);\n\t\t\tif (buf.st_size < 10)\n\t\t\t\tERROR(\"%s: not a proper device table file\\n\", argv[0]);\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\t\t/* BRCM begin */\t\n\t\telse if(strcmp(argv[i], \"-gzip\") == 0)\n\t\t\tcompress_algorithm = GZIP;\n\t\t\n\t\telse if(strcmp(argv[i], \"-lzma\") == 0)\n\t\t\tcompress_algorithm = LZMA;\n\t\t/* BRCM end */\n\t\t\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude dirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"\\t-info\\t\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"\\t-sort sort file\\t\\t\\tsort files according to priorities in sort file.  One file or dir\\n\");\n\t\t        ERROR(\"\\t\\t\\t\\t\\twith priority per line.  Priority -32768 to 32767, default priority 0\\n\");\n\t\t\tERROR(\"\\t-b block size\\t\\t\\tsize of blocks in \");\n\t\t\tERROR(\"filesystem, default %d\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"\\t-noappend\\t\\t\\tDo not append to existing filesystem on dest, write a new filesystem\\n\");\n\t\t        ERROR(\"\\t\\t\\t\\t\\tThis is the default action if dest does not exist, or if no filesystem is on it\\n\");\n\t\t\tERROR(\"\\t-keep-as-directory\\t\\tIf one source directory is specified, create a root directory\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\t\\tcontaining that directory, rather than the contents of the directory\\n\");\n\t\t\tERROR(\"\\t-root-becomes name\\t\\tWhen appending source files/directories, make the original\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\t\\troot become a subdirectory in the new root called name, rather\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\t\\tthan adding the new source items to the original root\\n\");\n\t\t\tERROR(\"\\t-noI -noInodeCompression\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"\\t-noD -noDataCompression\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"\\t-noF -noFragmentCompression\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"\\t-no-duplicates\\t\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"\\t-no-fragments\\t\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"\\t-always-use-fragments\\t\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"\\t-nopad\\t\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"\\t-check_data\\t\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"\\t-le\\t\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"\\t-be\\t\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\t/* BRCM begin */\n\t\t\tERROR(\"\\t-gzip\\t\\t\\t\\tuse gzip compression\\n\");\n\t\t\tERROR(\"\\t-lzma\\t\\t\\t\\tuse lzma compression(default)\\n\");\t\t\t\n\t\t\t/* BRCM end */\n\t\t\tERROR(\"\\t-ef exclude file\\t\\tfile is a list of exclude dirs/files - one per line\\n\");\n\t\t\tERROR(\"\\t-all-root\\t\\t\\toverride file uid/gid and make all file uid/gids owned by root\\n\");\n\t\t\tERROR(\"\\t-root-owned\\t\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"\\t-force-uid uid\\t\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"\\t-force-gid gid\\t\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"\\t-version\\t\\t\\tprint version, licence and copyright message\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t\tif(!delete) {\n\t\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\t\tif(S_ISREG(buf.st_mode)) { /* reopen truncating file */\n\t\t\t\t\tclose(fd);\n\t\t\t                if((fd = open(argv[source + 1], O_TRUNC  | O_RDWR)) == -1) {\n\t\t\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\t\t\texit(1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdelete = TRUE;\n\t\t\t}\n\n\t\t}\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\texit(1);\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tif((fragment_data = (char *) malloc(block_size)) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating fragment_data\");\n\n\tif(delete) {\n\t\tprintf(\"Creating %s filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\t\n\t\tfragments = SQUASHFS_INVALID_BLK;\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &inode_bytes, &data_cache,\n\t\t\t\t&cache_bytes, &cache_size, &directory_table, &directory_bytes,\n\t\t\t\t&directory_data_cache, &directory_cache_bytes, &directory_cache_size,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count, (squashfs_uid *) uids, &uid_count,\n\t\t\t\t(squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, add_old_root_entry, &fragment_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\texit(1);\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s squashfs filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, noD, noF, -check_data, no-duplicates, no-fragments and always-use-fragments options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tinode_size = inode_bytes;\n\t\tdirectory_size = directory_bytes;\n\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tinode_count = file_count + dir_count + sym_count + dev_count;\n\t\tsdata_cache = (char *)malloc(scache_bytes = cache_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = directory_cache_size);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache, sdirectory_cache_bytes);\n\t\tsinode_bytes = inode_bytes;\n\t\tsdirectory_bytes = directory_bytes;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(stat(source_path[0], &buf) == -1) {\n\t\tperror(\"Cannot stat source directory\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsnprintf(dev_path, sizeof(dev_path), \"%s/dev\", source_path[0]);\n\n\tif(sorted)\n\t\tsort_files_and_write(source, source_path);\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(buf.st_mode))\n\t\tsBlk.root_inode = dir_scan(source_path[0], linux_opendir, linux_readdir, linux_closedir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(buf.st_mode))\n\t\tsBlk.root_inode = dir_scan(source_path[0], single_opendir, single_readdir, linux_closedir);\n\telse\n\t\tsBlk.root_inode = dir_scan(\"\", encomp_opendir, encomp_readdir, encomp_closedir);\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\n\tTRACE(\"sBlk->inode_table_start 0x%x\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%x\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%x\\n\", sBlk.fragment_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tunsigned char temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s filesystem, data block size %d, %s data, %s metadata, %s fragments\\n\", be ?\n\t\t\"Big endian\" : \"Little endian\", block_size, noI ? \"uncompressed\" : \"compressed\", noD ?\n\t\"uncompressed\" : \"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\n\tif(fd) close(fd);\n\tif(devtable) fclose(devtable);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/squashfs/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/squashfs/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, unsigned int, int, char *);\nextern int add_file(int, int, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#ifdef __MACOSX__\n  #define __BYTE_ORDER BYTE_ORDER\n  #define __BIG_ENDIAN BIG_ENDIAN\n  #define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n  #include <endian.h>\n#endif\n#include \"read_fs.h\"\n#include <squashfs_fs.h>\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tprintf(\"mksquashfs: \"s, ## args)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tfprintf(stderr, s, ## args)\n\nint swap;\n\nint read_block(int fd, int start, int *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tunsigned char buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tlong bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tif((res = uncompress(block, &bytes, (const char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, int start, int end, int root_inode_start, squashfs_super_block *sBlk,\n\t\tsquashfs_dir_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *uncompressed_file, unsigned int *uncompressed_directory, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%x, end 0x%x, root_inode_start 0x%x\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%x containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%x\\n\", start);\n\t\tif((bytes += read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\tbytes -= sizeof(squashfs_dir_inode_header);\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy((void *)&sinode, (void *)(*inode_table + bytes), sizeof(*dir_inode));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir_inode, &sinode);\n\t} else\n\t\tmemcpy((void *)dir_inode, (void *)(*inode_table + bytes), sizeof(*dir_inode));\n\tdirectory_start_block = dir_inode->start_block;\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy((void *)&sinode, (void *)cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy((void *)&inode, (void *)cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_BLK ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_BLK ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tint file_bytes = 0, i, start = inode.start_block;\n\t\t\t\tunsigned int block_list[blocks];\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %d, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy((void *)sblock_list, (void *)cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy((void *)block_list, (void *)cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy((void *)&sinodep, (void *)cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy((void *)&inodep, (void *)cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy((void *)&sinode, (void *)cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy((void *)&dir_inode, (void *)cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tfree(*inode_table);\n\t\t\t\treturn FALSE;\n\t\t}\n\t}\n\t\n\treturn files;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major == 1)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS 1.x filesystem.  Appending\\nto SQUASHFS 1.x filesystems is not supported.  Please convert it to a SQUASHFS 2.0 filesystem...n\", source);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d), I support (%d: <= %d)\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid SQUASHFS superblock on %s.\\n\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not\" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFilesystem size %d bytes\\n\", sBlk->bytes_used);\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %x\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %x\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %x\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %x\\n\", sBlk->fragment_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, int start, int offset, int size, squashfs_super_block *sBlk,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint bytes = 0, dir_count;\n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%x, bytes read so far %d\\n\", start, bytes);\n\t\tif((bytes += read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy((void *)&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy((void *)&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy((void *)&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy((void *)dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy((void *)dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%x\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%x, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table, int *inode_bytes,\n\t\tchar **data_cache, int *cache_bytes, int *cache_size,\n\t\tchar **cdirectory_table, int *directory_bytes,\n\t\tchar **directory_data_cache, int *directory_cache_bytes, int *directory_cache_size,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\t\tsquashfs_uid *uids, unsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tunsigned int *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int), squashfs_fragment_entry **fragment_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tunsigned int start = sBlk->inode_table_start, end = sBlk->directory_table_start,\n\t\troot_inode_start = start + SQUASHFS_INODE_BLK(sBlk->root_inode),\n\t\troot_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_directory_offset;\n\tsquashfs_dir_inode_header inode;\n\tunsigned int files, root_inode_block;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd,  sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, sBlk, &inode, &inode_table, &root_inode_block,\n\t\t\tuncompressed_file, uncompressed_directory, file_count, sym_count, dev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, sBlk->directory_table_start + inode.start_block,\n\t\t\t\t\t\tinode.offset, inode.file_size, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\tif((*cinode_table = (char *) malloc(root_inode_start - start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t       \tread_bytes(fd, start, root_inode_start - start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(inode.start_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\tread_bytes(fd, sBlk->directory_table_start, inode.start_block, *cdirectory_table);\n\n\t\t*inode_bytes =  root_inode_start - start;\n\t\t*directory_bytes = inode.start_block;\n\n\t\troot_inode_offset += sizeof(inode);\n\t\troot_directory_offset = inode.offset + inode.file_size;\n\t\t(*dir_count) ++;\n\n\t\tif(((*data_cache = (char *) malloc(root_inode_offset)) == NULL) || \n\t\t\t\t((*directory_data_cache = (char *) malloc(root_directory_offset)) == NULL)) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode/directory caches\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset);\n\t\tmemcpy(*directory_data_cache, directory_table, root_directory_offset);\n\t\t*cache_size = root_inode_offset;\n\t\t*directory_cache_size = root_directory_offset;\n\n\t\tif(root_name) {\n\t\t\tpush_directory_entry(root_name, sBlk->root_inode, SQUASHFS_DIR_TYPE);\n\t\t\t*cache_bytes = root_inode_offset;\n\t\t\t*directory_cache_bytes = root_directory_offset;\n\t\t} else {\n\t\t\t*cache_bytes = root_inode_offset - sizeof(inode);\n\t\t\t*directory_cache_bytes = inode.offset;\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/squashfs/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/squashfs/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tprintf(\"mksquashfs: \"s, ## args)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tif(!silent) printf(\"mksquashfs: \"s, ## args)\n#define ERROR(s, args...)\t\tfprintf(stderr, s, ## args)\n#define EXIT_MKSQUASHFS()\t\texit(1)\n#define BAD_ERROR(s, args...)\t\t{\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t}\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry {\n\tchar *filename;\n\tlong long size;\n\tino_t st_ino;\n\tdev_t st_dev;\n\tstruct priority_entry *next;\n};\n\nstruct priority_entry *priority_list[65536];\n\nstruct sorted_inode_entry {\n\tsquashfs_inode inode;\n\tino_t\tst_ino;\n\tdev_t\tst_dev;\n\tstruct sorted_inode_entry *next;\n};\n\nstruct sorted_inode_entry *sorted_inode_list[65536];\n\nextern int silent;\nextern int excluded(char *filename, struct stat *buf);\nextern squashfs_inode write_file(char *filename, long long size, int *c_size);\n\n\nint add_to_sorted_inode_list(squashfs_inode inode, dev_t st_dev, ino_t st_ino)\n{\n\tint hash = st_ino & 0xffff;\n\tstruct sorted_inode_entry *new_sorted_inode_entry;\n\n\tif((new_sorted_inode_entry = malloc(sizeof(struct sorted_inode_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating sorted inode entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_sorted_inode_entry->inode = inode;\n\tnew_sorted_inode_entry->st_ino = st_ino;\n\tnew_sorted_inode_entry->st_dev = st_dev;\n\tnew_sorted_inode_entry->next = sorted_inode_list[hash];\n\tsorted_inode_list[hash] = new_sorted_inode_entry;\n\n\treturn TRUE;\n}\n\n\t\nsquashfs_inode get_sorted_inode(struct stat *buf)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sorted_inode_entry *sorted_inode_entry;\n\n\tfor(sorted_inode_entry = sorted_inode_list[hash]; sorted_inode_entry; sorted_inode_entry = sorted_inode_entry->next)\n\t\tif(buf->st_ino == sorted_inode_entry->st_ino && buf->st_dev == sorted_inode_entry->st_dev)\n\t\t\tbreak;\n\n\tif(sorted_inode_entry)\n\t\treturn sorted_inode_entry->inode;\n\telse\n\t\treturn (squashfs_inode) 0;\n}\n\n\nint add_priority_list(char *filename, struct stat *buf, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->filename = strdup(filename);\n\tnew_priority_entry->size = buf->st_size;\n\tnew_priority_entry->st_dev = buf->st_dev;\n\tnew_priority_entry->st_ino = buf->st_ino;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat sort_list dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %Lx, st_ino %Lx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat sort_list dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t}\n\treturn TRUE;\n}\n\n\nvoid generate_file_priorities(char *pathname, int priority, struct stat *buf)\n{\n\tchar filename[8192];\n\tDIR *linuxdir;\n\tstruct dirent *d_name;\n\t\n\tpriority = get_priority(pathname, buf, priority);\n\n\tif((linuxdir = opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\treturn;\n\t}\n\t\n\twhile((d_name = readdir(linuxdir)) != NULL) {\n\t\tif(strcmp(d_name->d_name, \".\") == 0 || strcmp(d_name->d_name, \"..\") == 0)\n\t\t\tcontinue;\n\t\tstrcat(strcat(strcpy(filename, pathname), \"/\"), d_name->d_name);\n\n\t\tif(lstat(filename, buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(excluded(filename, buf))\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(filename, buf, get_priority(filename, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(filename, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tclosedir(linuxdir);\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(int source, char *source_path[])\n{\n\tstruct stat buf;\n\tint i, c_size;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\n\tfor(i = 0; i < source; i++) {\n\t\tif(lstat(source_path[i], &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", source_path[i]);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(excluded(source_path[i], &buf))\n\t\t\tcontinue;\n\n\t\tswitch(buf.st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(source_path[i], &buf, get_priority(source_path[i], &buf, 0));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(source_path[i], 0, &buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor(i = 0; i < 65536; i++)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->filename);\n\t\t\tinode = write_file(entry->filename, entry->size, &c_size);\n\t\t\tINFO(\"file %s, size %d bytes, inode 0x%Lx\\n\", entry->filename, c_size, inode);\n\t\t\tINFO(\"\\t%.2f%% of uncompressed file size (%Ld bytes)\\n\", ((float) c_size / entry->size) * 100.0, entry->size);\n\t\t\tadd_to_sorted_inode_list(inode, entry->st_dev, entry->st_ino);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/squashfs/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#define SQUASHFS_MAJOR\t\t\t2\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#if defined(BUILD_SQUASH_HIGH)\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n\n#elif  defined(BUILD_SQUASH_NORMAL)\n#define SQUASHFS_FILE_SIZE\t\t32768\n#define SQUASHFS_FILE_LOG\t\t15\n#define SQUASHFS_FILE_MAX_SIZE\t\t32768\n\n#elif defined(BUILD_SQUASH_LOW)\n#define SQUASHFS_FILE_SIZE\t\t8192\n#define SQUASHFS_FILE_LOG\t\t13\n#define SQUASHFS_FILE_MAX_SIZE\t\t8192\n\n#else\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n#endif\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) 0xffffffff)\n#define SQUASHFS_USED_BLK\t\t((long long) 0xfffffffe)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, SQUASHFS_NOI)\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, SQUASHFS_NOD)\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, SQUASHFS_NOF)\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, SQUASHFS_CHECK)\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, duplicate_checking)\t(noi | (nod << 1) | (check_data << 2) | (nof << 3) | (no_frag << 4) | (always_frag << 5) | (duplicate_checking << 6))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t\t\t\t(B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \\\n\t\t\t\t\t(B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an uncompressed\n * offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode)(((squashfs_inode) (A) << 16)\\\n\t\t\t\t\t+ (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + ((b) >> 2) + 1))\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\ntypedef unsigned int\t\t\tsquashfs_fragment_index;\n#define SQUASHFS_FRAGMENT_BYTES(A)\t(A * sizeof(squashfs_fragment_entry))\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))\n#define SQUASHFS_CACHED_FRAGMENTS\t3\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t32\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/*\n * definitions for structures on disk\n */\n\ntypedef unsigned int\t\tsquashfs_block;\ntypedef long long\t\tsquashfs_inode;\n\ntypedef unsigned int\t\tsquashfs_uid;\n\ntypedef struct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used;\n\tunsigned int\t\tuid_start;\n\tunsigned int\t\tguid_start;\n\tunsigned int\t\tinode_table_start;\n\tunsigned int\t\tdirectory_table_start;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode\t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start;\n} __attribute__ ((packed)) squashfs_super_block;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed)) squashfs_base_inode_header;\n\ntypedef squashfs_base_inode_header squashfs_ipc_inode_header;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed)) squashfs_dev_inode_header;\n\t\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed)) squashfs_symlink_inode_header;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tsquashfs_block\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:SQUASHFS_MAX_FILE_SIZE_LOG;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed)) squashfs_reg_inode_header;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed)) squashfs_dir_inode_header;\n\ntypedef union {\n\tsquashfs_base_inode_header\tbase;\n\tsquashfs_dev_inode_header\tdev;\n\tsquashfs_symlink_inode_header\tsymlink;\n\tsquashfs_reg_inode_header\treg;\n\tsquashfs_dir_inode_header\tdir;\n\tsquashfs_ipc_inode_header\tipc;\n} squashfs_inode_header;\n\t\ntypedef struct {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed)) squashfs_dir_entry;\n\ntypedef struct {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed)) squashfs_dir_header;\n\n\ntypedef struct {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed)) squashfs_fragment_entry;\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n#ifdef SQUASHFS_1_0_COMPATIBILITY\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed)) squashfs_base_inode_header_1;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed)) squashfs_ipc_inode_header_1;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed)) squashfs_dev_inode_header_1;\n\t\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed)) squashfs_symlink_inode_header_1;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tsquashfs_block\t\tstart_block;\n\tunsigned int\t\tfile_size:SQUASHFS_MAX_FILE_SIZE_LOG;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed)) squashfs_reg_inode_header_1;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed)) squashfs_dir_inode_header_1;\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n#endif\n\n#ifdef __KERNEL__\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#include <asm/byteorder.h>\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/squashfs/squashfs_fs_i.h",
    "content": "#ifndef SQUASHFS_FS_I\n#define SQUASHFS_FS_I\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs_i.h\n */\n\ntypedef struct squashfs_inode_info {\n\tunsigned int\tstart_block;\n\tunsigned int\tblock_list_start;\n\tunsigned int\toffset;\n\tunsigned int\tfragment_start_block;\n\tunsigned int\tfragment_size;\n\tunsigned int\tfragment_offset;\n\tstruct inode\tvfs_inode;\n\t} squashfs_inode_info;\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-mksquashfs/squashfs/squashfs_fs_sb.h",
    "content": "#ifndef SQUASHFS_FS_SB\n#define SQUASHFS_FS_SB\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs_sb.h\n */\n\n#include <linux/squashfs_fs.h>\n\ntypedef struct {\n\tunsigned int\tblock;\n\tint\t\tlength;\n\tunsigned int\tnext_index;\n\tchar\t\t*data;\n\t} squashfs_cache;\n\nstruct squashfs_fragment_cache {\n\tunsigned int\tblock;\n\tint\t\tlength;\n\tunsigned int\tlocked;\n\tchar\t\t*data;\n\t};\n\ntypedef struct squashfs_sb_info {\n\tsquashfs_super_block\tsBlk;\n\tint\t\t\tdevblksize;\n\tint\t\t\tdevblksize_log2;\n\tint\t\t\tswap;\n\tsquashfs_cache\t\t*block_cache;\n\tstruct squashfs_fragment_cache\t*fragment;\n\tint\t\t\tnext_cache;\n\tint\t\t\tnext_fragment;\n\tsquashfs_uid\t\t*uid;\n\tsquashfs_uid\t\t*guid;\n\tsquashfs_fragment_index\t\t*fragment_index;\n\tunsigned int\t\tread_size;\n\tchar\t\t\t*read_data;\n\tchar\t\t\t*read_page;\n\tstruct semaphore\tread_page_mutex;\n\tstruct semaphore\tblock_cache_mutex;\n\tstruct semaphore\tfragment_mutex;\n\twait_queue_head_t\twaitq;\n\twait_queue_head_t\tfragment_wait_queue;\n\tstruct inode\t\t*(*iget)(struct super_block *s, squashfs_inode inode);\n\tunsigned int\t\t(*read_blocklist)(struct inode *inode, int index, int readahead_blks,\n\t\t\t\t\tchar *block_list, char **block_p, unsigned int *bsize);\n\t} squashfs_sb_info;\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/Makefile",
    "content": "CC=gcc\n\nCFLAGS := -I. -Ibrcm-lzma -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\n\nall: unsquashfs\n\nunsquashfs: nb4-unsquash.o\n\tcd brcm-lzma; make\n\tgcc nb4-unsquash.o brcm-lzma/7zlzma.o brcm-lzma/IInOutStreams.o brcm-lzma/LZMADecoder.o -lpthread -lm -o $@\n\nnb4-unsquash.o: nb4-unsquash.c squashfs_fs.h read_fs.h global.h\n\nclean:\n\tcd brcm-lzma; make clean\n\trm -f nb4-unsquash.o unsquashfs\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/README",
    "content": "Cette application nb4-unsquash est juste l'adaption de la suite inflate-lzma prsente dans le rpertoire kernel/linux/fs/inflate-lzma de la distribution Broadcom  la procdure unsquashfs.c de la suite squashfs3.3\r\nhttp://sourceforge.net/project/showfiles.php?group_id=63835\r\n\r\nUn simple Make devrait construire l'utilitaire nb4-unsquash\r\n\r\nPour l'utiliser\r\n./nb4-unsquash\r\nSYNTAX: ./unsqlzma [options] filesystem [directories or files to extract]\r\n  -v[ersion]  print version, licence and copyright information\r\n  -i[nfo]    print files as they are unsquashed\r\n  -li[nfo]  print files as they are unsquashed with file\r\n        attributes (like ls -l output)\r\n  -l[s]     list filesystem, but don't unsquash\r\n  -ll[s]     list filesystem with file attributes (like\r\n        ls -l output), but don't unsquash\r\n  -d[est] <pathname> unsquash to <pathname>, default \"squashfs-root\"\r\n  -f[orce]  if file already exists then overwrite\r\n  -s[tat]    display filesystem superblock information\r\n  -e[f] <extract file>  list of directories or files to extract.\r\n        One per line\r\n  -r[egex]  treat extract names as POSIX regular expressions\r\n        rather than use the default shell wildcard\r\n        expansion (globbing)\r\n\r\n\r\npour lister les fichiers du fichier xx.sqsh\r\n./nb4-unsquash -ll xx.sqsh\r\n\r\npour extraire les fichiers du fichier xx.sqsh dans le rpertoire yy\r\n./nb4-unsquash -d yy xx.sqsh\r\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/7z.h",
    "content": "#ifndef __7Z_H\n#define __7Z_H\n\n#if defined __cplusplus\nextern \"C\"\n{\n#endif\n\nint decompress_lzma_7z(unsigned char* in_data, unsigned in_size, unsigned char* out_data, unsigned out_size);\n\n#if defined __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/7zlzma.c",
    "content": "#include \"7z.h\"\n\n#include \"stdio.h\"\n#include \"string.h\"\n#include \"stdlib.h\"\n\n#include \"LZMADecoder.h\"\n\n\nstatic LzmaDecoder   cc;\nISequentialInStream  in_stream;\nISequentialOutStream out_stream;\nint decompress_lzma_7z( unsigned char* in_data, \n                        unsigned in_size, \n                        unsigned char* out_data, \n                        unsigned out_size) {\n//\t\tLzmaDecoder cc;\n        int RC;\n\tUINT64 in_size_l  = in_size;\n\tUINT64 out_size_l = out_size;\n\n\n        InStreamInit(in_data, in_size);\n\n\tOutStreamInit((char *)out_data, out_size);\n\n        LzmaDecoderConstructor(&cc);\n\n        if ((RC = LzmaDecoderReadCoderProperties(&cc)) != S_OK)\n        {\n\t\treturn RC;\n        }\n\n\tif (LzmaDecoderCode(&cc, &in_size_l, &out_size_l) != S_OK)\n        {\n\t\treturn -2;\n        }\n\n\tif (out_stream.size != out_size)\n        {\n\t\treturn -3;\n        }\n\n        if ( out_stream.overflow )\n        {\n            return -4;\n        }\n\n\treturn 0;\n}\n\n//BRCM modification\n#ifdef __KERNEL__\nEXPORT_SYMBOL(decompress_lzma_7z);\n#endif\n\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/AriBitCoder.h",
    "content": "#ifndef __COMPRESSION_BITCODER_H\n#define __COMPRESSION_BITCODER_H\n\n#include \"RangeCoder.h\"\n\n#define kNumBitModelTotalBits  11\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\n\n#define kNumMoveReducingBits 2\n\n\ntypedef UINT32 CBitDecoder;\n\nINLINE  void BitDecoderInit(CBitDecoder *bitDecoder)\n  { \n    *bitDecoder = kBitModelTotal / 2; \n  }\n\n#if 0\nUINT32 BitDecode(ISequentialInStream *in_stream, CBitDecoder *bitDecoder, CRangeDecoder *aRangeDecoder);\n#else\nINLINE  UINT32 BitDecode(ISequentialInStream *in_stream, CBitDecoder *bitDecoder, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aNewBound = (aRangeDecoder->m_Range >> kNumBitModelTotalBits) * (*bitDecoder);\n    if (aRangeDecoder->m_Code < aNewBound)\n    {\n      aRangeDecoder->m_Range = aNewBound;\n      *bitDecoder += (kBitModelTotal - *bitDecoder) >> kNumMoveBits;\n      if (aRangeDecoder->m_Range < kTopValue)\n      {\n        aRangeDecoder->m_Code = (aRangeDecoder->m_Code << 8) | InStreamReadByte(in_stream);\n        aRangeDecoder->m_Range <<= 8;\n      }\n      return 0;\n    }\n    else\n    {\n      aRangeDecoder->m_Range -= aNewBound;\n      aRangeDecoder->m_Code -= aNewBound;\n      *bitDecoder -= (*bitDecoder) >> kNumMoveBits;\n      if (aRangeDecoder->m_Range < kTopValue)\n      {\n        aRangeDecoder->m_Code = (aRangeDecoder->m_Code << 8) | InStreamReadByte(in_stream);\n        aRangeDecoder->m_Range <<= 8;\n      }\n      return 1;\n    }\n  }\n#endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/BitTreeCoder.h",
    "content": "#ifndef __BITTREECODER_H\n#define __BITTREECODER_H\n\n#include \"AriBitCoder.h\"\n#include \"RCDefs.h\"\n\n//BRCM modification start\n#ifdef _HOST_TOOL\n#include \"stdio.h\"\n#include \"stdlib.h\"\n#include \"malloc.h\" \n#endif\n\n#ifdef _CFE_\n#include \"lib_malloc.h\"\n#include \"lib_printf.h\"\n#define malloc(x) KMALLOC(x, 0)\n#endif\n\n#ifdef __KERNEL__\n#include <linux/kernel.h>\n#include <linux/vmalloc.h>\n#include <linux/slab.h>\n#define printf printk\n//#define malloc(x) kmalloc(x,GFP_KERNEL)\n#define malloc(x) vmalloc(x)\n#define free(x) vfree(x)\n#endif\n//BRCM modification end\n\n//////////////////////////\n// CBitTreeDecoder\n\ntypedef struct CBitTreeDecoder\n{\n  UINT32       m_NumBitLevels;\n  CBitDecoder *m_Models;\n} CBitTreeDecoder;\n\n//  ~CBitTreeDecoder() { free(m_Models); }\nINLINE void BitTreeDecoderInit(CBitTreeDecoder *bitTreeDecoder, UINT32 aNumBitLevels)\n  {\n    int i;\n    bitTreeDecoder->m_NumBitLevels = aNumBitLevels;\n    bitTreeDecoder->m_Models       = (CBitDecoder *)malloc( sizeof(CBitDecoder) * (1 << bitTreeDecoder->m_NumBitLevels));\n    //BRCM modification\n    //printf(\"malloc in BitTreeDecoderInit=%d\\n\",sizeof(CBitDecoder) * (1 << bitTreeDecoder->m_NumBitLevels));\n    if (!bitTreeDecoder->m_Models) {\n\t    printf(\"Error in allocating memory for bitTreeDecoder!\\n\");\n\t    return;\n    }\t    \n    for(i = 1; i < (1 << aNumBitLevels); i++)\n      BitDecoderInit(&bitTreeDecoder->m_Models[i]);\n  }\nINLINE UINT32 BitTreeDecode(ISequentialInStream *in_stream, CBitTreeDecoder *bitTreeDecoder, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;\n    UINT32 aBitIndex;\n    for(aBitIndex = bitTreeDecoder->m_NumBitLevels; aBitIndex > 0; aBitIndex--)\n    {\n      RC_GETBIT(kNumMoveBits, bitTreeDecoder->m_Models[aModelIndex], aModelIndex)\n    }\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aModelIndex - (1 << bitTreeDecoder->m_NumBitLevels);\n  }\n\n\n////////////////////////////////\n// CReverseBitTreeDecoder2\n\ntypedef struct CReverseBitTreeDecoder2\n{\n  UINT32       m_NumBitLevels;\n  CBitDecoder *m_Models;\n} CReverseBitTreeDecoder2;\n\n//  CReverseBitTreeDecoder2(): m_Models(0) { }\n//  ~CReverseBitTreeDecoder2() { free(m_Models); }\nINLINE BOOL ReverseBitTreeDecoder2Create(CReverseBitTreeDecoder2 *reverseBitTreeDecoder2, UINT32 aNumBitLevels)\n  {\n    reverseBitTreeDecoder2->m_NumBitLevels = aNumBitLevels;\n    reverseBitTreeDecoder2->m_Models       = (CBitDecoder *)malloc( sizeof(CBitDecoder) * (1 << reverseBitTreeDecoder2->m_NumBitLevels));\n    //printf(\"malloc in ReverseBitTreeDecoder2Create=%d\\n\",sizeof(CBitDecoder) * (1 << reverseBitTreeDecoder2->m_NumBitLevels));\n    if (!reverseBitTreeDecoder2->m_Models) {\n\t    printf(\"Error in allocating memory for reverseBitTreeDecoder2!\\n\");\n\t    return 0;\n    }\t    \n    return (reverseBitTreeDecoder2->m_Models != 0);\n  }\nINLINE void ReverseBitTreeDecoder2Init(CReverseBitTreeDecoder2 *reverseBitTreeDecoder2)\n  {\n    UINT32 aNumModels = 1 << reverseBitTreeDecoder2->m_NumBitLevels;\n    UINT32 i;\n    for(i = 1; i < aNumModels; i++)\n      BitDecoderInit(&reverseBitTreeDecoder2->m_Models[i]);\n  }\nINLINE UINT32 ReverseBitTreeDecoder2Decode(ISequentialInStream *in_stream, CReverseBitTreeDecoder2 *reverseBitTreeDecoder2, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    UINT32 aSymbol = 0;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;\n    UINT32 aBitIndex;\n    for(aBitIndex = 0; aBitIndex < reverseBitTreeDecoder2->m_NumBitLevels; aBitIndex++)\n    {\n      RC_GETBIT2(kNumMoveBits, reverseBitTreeDecoder2->m_Models[aModelIndex], aModelIndex, ; , aSymbol |= (1 << aBitIndex))\n    }\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aSymbol;\n  }\n\n\n////////////////////////////\n// CReverseBitTreeDecoder\n\ntypedef struct CReverseBitTreeDecoder\n{\n  UINT32        m_NumBitLevels;\n  CBitDecoder  *m_Models;\n} CReverseBitTreeDecoder;\n\n//    CReverseBitTreeDecoder(): m_Models(0) { }\n//    ~CReverseBitTreeDecoder() { free(m_Models); }\nINLINE void ReverseBitTreeDecoderInit(CReverseBitTreeDecoder *reverseBitTreeDecoder, UINT32 aNumBitLevels)\n  {\n    int i;\n    reverseBitTreeDecoder->m_NumBitLevels = aNumBitLevels;\n    reverseBitTreeDecoder->m_Models       = (CBitDecoder *)malloc( sizeof(CBitDecoder) * (1 << reverseBitTreeDecoder->m_NumBitLevels));\n    //printf(\"malloc in ReverseBitTreeDecoderInit=%d\\n\",sizeof(CBitDecoder) * (1 << reverseBitTreeDecoder->m_NumBitLevels));\n    if (!reverseBitTreeDecoder->m_Models) {\n\t    printf(\"Error in allocating memory for reverseBitTreeDecoder!\\n\");\n\t    return;\n    }\t    \n    for(i = 1; i < (1 << reverseBitTreeDecoder->m_NumBitLevels); i++)\n      BitDecoderInit(&reverseBitTreeDecoder->m_Models[i]);\n  }\n\nINLINE UINT32 ReverseBitTreeDecoderDecode(ISequentialInStream *in_stream, CReverseBitTreeDecoder *reverseBitTreeDecoder, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aModelIndex = 1;\n    UINT32 aSymbol = 0;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;\n    UINT32 aBitIndex;\n    for(aBitIndex = 0; aBitIndex < reverseBitTreeDecoder->m_NumBitLevels; aBitIndex++)\n    {\n      RC_GETBIT2(kNumMoveBits, reverseBitTreeDecoder->m_Models[aModelIndex], aModelIndex, ; , aSymbol |= (1 << aBitIndex))\n    }\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aSymbol;\n  }\n\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/IInOutStreams.c",
    "content": "#include \"stdlib.h\"\n#include \"IInOutStreams.h\"\n// BRCM modification \nstatic void *lib_memcpy(void *dest,const void *src,size_t cnt);\nstatic void *lib_memcpy(void *dest,const void *src,size_t cnt)\n{\n    unsigned char *d;\n    const unsigned char *s;\n\n    d = (unsigned char *) dest;\n    s = (const unsigned char *) src;\n\n    while (cnt) {\n\t*d++ = *s++;\n\tcnt--;\n\t}\n\n    return dest;\n}\n\nHRESULT InStreamRead(void *aData, UINT32 aSize, UINT32* aProcessedSize) {\n    \tif (aSize > in_stream.remainingBytes)\n    \t\taSize = in_stream.remainingBytes;\n    \t*aProcessedSize = aSize;\n    \tlib_memcpy(aData, in_stream.data, aSize); // brcm modification\n    \tin_stream.remainingBytes -= aSize;\n    \tin_stream.data += aSize;\n    \treturn S_OK;\n    }\n\n#if 0\nBYTE InStreamReadByte()\n    {\n        if (in_stream.remainingBytes == 0)\n            return 0x0;\n        in_stream.remainingBytes--;\n        return (BYTE) *in_stream.data++;\n    }\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/IInOutStreams.h",
    "content": "#ifndef __IINOUTSTREAMS_H\n#define __IINOUTSTREAMS_H\n\n#include \"Portable.h\"\n\ntypedef struct ISequentialInStream\n{\n\tunsigned char* data;\n\tunsigned       remainingBytes;\n} ISequentialInStream;\n\nextern ISequentialInStream in_stream;\n\nINLINE void InStreamInit(unsigned char * Adata, unsigned Asize)\n    {\n        in_stream.data           = Adata;\n        in_stream.remainingBytes = Asize;\n    }\n\nHRESULT InStreamRead(void *aData, UINT32 aSize, UINT32* aProcessedSize);\n\n#if 0\nBYTE InStreamReadByte();\n#else\nINLINE BYTE InStreamReadByte(ISequentialInStream *in_stream)\n    {\n        if (in_stream->remainingBytes == 0)\n            return 0x0;\n        in_stream->remainingBytes--;\n        return (BYTE) *in_stream->data++;\n    }\n#endif\n\n\n\ntypedef struct ISequentialOutStream\n{\n\tchar*       data;\n\tunsigned    size;\n\tBOOL        overflow;\n\tunsigned    total;\n} ISequentialOutStream;\n\nextern ISequentialOutStream out_stream;\n\n#define OutStreamInit(Adata, Asize) \\\n{ \\\n    out_stream.data = Adata; \\\n    out_stream.size = Asize; \\\n    out_stream.overflow = FALSE; \\\n    out_stream.total = 0; \\\n}\n\n#define OutStreamSizeSet(newsize) \\\n    { \\\n        out_stream.total = newsize; \\\n        if (out_stream.total > out_stream.size) \\\n            out_stream.overflow = TRUE; \\\n    }\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/LZMA.h",
    "content": "#include \"LenCoder.h\"\n\n#ifndef __LZMA_H\n#define __LZMA_H\n\n\n#define kNumRepDistances 4\n\n#define kNumStates 12\n\nstatic const BYTE kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\nstatic const BYTE kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\nstatic const BYTE kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\nstatic const BYTE kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\n\ntypedef BYTE CState;\n\nINLINE void CStateInit(CState *m_Index)\n    { *m_Index = 0; }\nINLINE void CStateUpdateChar(CState *m_Index)\n    { *m_Index = kLiteralNextStates[*m_Index]; }\nINLINE void CStateUpdateMatch(CState *m_Index)\n    { *m_Index = kMatchNextStates[*m_Index]; }\nINLINE void CStateUpdateRep(CState *m_Index)\n    { *m_Index = kRepNextStates[*m_Index]; }\nINLINE void CStateUpdateShortRep(CState *m_Index)\n    { *m_Index = kShortRepNextStates[*m_Index]; }\n\n\n#define kNumPosSlotBits 6\n#define kDicLogSizeMax 28\n#define kDistTableSizeMax 56\n\n//extern UINT32 kDistStart[kDistTableSizeMax];\nstatic const BYTE kDistDirectBits[kDistTableSizeMax] = \n{\n  0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,\n  10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, \n  20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26 \n};\n\n#define kNumLenToPosStates 4\nINLINE UINT32 GetLenToPosState(UINT32 aLen)\n{\n  aLen -= 2;\n  if (aLen < kNumLenToPosStates)\n    return aLen;\n  return kNumLenToPosStates - 1;\n}\n\n#define kMatchMinLen 2\n\n#define kMatchMaxLen (kMatchMinLen + kNumSymbolsTotal - 1)\n\n#define kNumAlignBits 4\n#define kAlignTableSize 16\n#define kAlignMask 15\n\n#define kStartPosModelIndex 4\n#define kEndPosModelIndex 14\n#define kNumPosModels 10\n\n#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\n\n\n#define kMainChoiceLiteralIndex 0\n#define kMainChoiceMatchIndex 1\n\n#define kMatchChoiceDistanceIndex0\n#define kMatchChoiceRepetitionIndex 1\n\n#define kNumMoveBitsForMainChoice 5\n#define kNumMoveBitsForPosCoders 5\n\n#define kNumMoveBitsForAlignCoders 5\n\n#define kNumMoveBitsForPosSlotCoder 5\n\n#define kNumLitPosStatesBitsEncodingMax 4\n#define kNumLitContextBitsMax 8\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/LZMADecoder.c",
    "content": "#include \"Portable.h\"\n#include \"stdio.h\"\n#include \"stdlib.h\"\n#include \"LZMADecoder.h\"\n\n\n//#define RETURN_E_OUTOFMEMORY_IF_FALSE(x) { if (!(x)) return E_OUTOFMEMORY; }\n\n\nstatic UINT32    kDistStart[kDistTableSizeMax];\nstruct WindowOut out_window;\n\n/*\n * BRCM modification: free all the allocated buffer by malloc\n *\n */\nstatic void LzmaDecoderFreeBuffer(LzmaDecoder  *lzmaDecoder)\n{\n  int i,aPosState;\n  \n  //printf(\"free lzmaDecoder->m_LiteralDecoder\\n\");\n  free((&lzmaDecoder->m_LiteralDecoder)->m_Coders);\n\n  for (i = 0; i < kNumLenToPosStates; i++) {\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free((&lzmaDecoder->m_PosSlotDecoder[i])->m_Models);\n  }\n  // from LenDecoderInit(&lzmaDecoder->m_LenDecoder;\n  for (aPosState = 0; aPosState < (&lzmaDecoder->m_LenDecoder)->m_NumPosStates; aPosState++) {\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free( (&(&lzmaDecoder->m_LenDecoder)->m_LowCoder[aPosState])->m_Models );\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free( (&(&lzmaDecoder->m_LenDecoder)->m_MidCoder[aPosState])->m_Models );\n   }\n  //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n  free( (&(&lzmaDecoder->m_LenDecoder)->m_HighCoder)->m_Models );\n\n\n  // from LenDecoderInit(&lzmaDecoder->m_RepMatchLenDecoder);\n  for (aPosState = 0; aPosState < (&lzmaDecoder->m_RepMatchLenDecoder)->m_NumPosStates; aPosState++) {\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free( (&(&lzmaDecoder->m_RepMatchLenDecoder)->m_LowCoder[aPosState])->m_Models );\n      //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n      free( (&(&lzmaDecoder->m_RepMatchLenDecoder)->m_MidCoder[aPosState])->m_Models );\n  }\n  //printf(\"free lzmaDecoder->m_PosSlotDecoder\\n\");\n  free( (&(&lzmaDecoder->m_RepMatchLenDecoder)->m_HighCoder)->m_Models );\n\n    \n  //printf(\"free lzmaDecoder->m_PosAlignDecoder\\n\");\n  free((&lzmaDecoder->m_PosAlignDecoder)->m_Models);\n\n  for(i = 0; i < kNumPosModels; i++) {\n      //printf(\"free lzmaDecoder->m_PosDecoders\\n\");\n      free((&lzmaDecoder->m_PosDecoders[i])->m_Models);\n  }\n  \n}\n\nHRESULT LzmaDecoderSetDictionarySize(\n    LzmaDecoder  *lzmaDecoder, \n    UINT32        aDictionarySize)\n{\n  if (aDictionarySize > (1 << kDicLogSizeMax))\n    return E_INVALIDARG;\n  \n//  UINT32 aWindowReservSize = MyMax(aDictionarySize, UINT32(1 << 21));\n\n  if (lzmaDecoder->m_DictionarySize != aDictionarySize)\n  {\n    lzmaDecoder->m_DictionarySize = aDictionarySize;\n  }\n  return S_OK;\n}\n\nHRESULT LzmaDecoderSetLiteralProperties( \n    LzmaDecoder  *lzmaDecoder,\n    UINT32        aLiteralPosStateBits, \n    UINT32        aLiteralContextBits)\n{\n  if (aLiteralPosStateBits > 8)\n    return E_INVALIDARG;\n  if (aLiteralContextBits > 8)\n    return E_INVALIDARG;\n  LitDecoderCreate(&lzmaDecoder->m_LiteralDecoder, aLiteralPosStateBits, aLiteralContextBits);\n  return S_OK;\n}\n\nHRESULT LzmaDecoderSetPosBitsProperties(\n    LzmaDecoder *lzmaDecoder, \n    UINT32       aNumPosStateBits)\n{\n  UINT32 aNumPosStates;\n  if (aNumPosStateBits > (UINT32) kNumPosStatesBitsMax)\n    return E_INVALIDARG;\n  aNumPosStates = 1 << aNumPosStateBits;\n  LenDecoderCreate(&lzmaDecoder->m_LenDecoder, aNumPosStates);\n  LenDecoderCreate(&lzmaDecoder->m_RepMatchLenDecoder, aNumPosStates);\n  lzmaDecoder->m_PosStateMask = aNumPosStates - 1;\n  return S_OK;\n}\n\n\nvoid LzmaDecoderConstructor(LzmaDecoder *lzmaDecoder)\n{\n  lzmaDecoder->m_DictionarySize = ((UINT32)-1);\n  LzmaDecoderCreate(lzmaDecoder);\n}\n\nHRESULT LzmaDecoderCreate(LzmaDecoder *lzmaDecoder)\n{\n  int i;\n  for(i = 0; i < kNumPosModels; i++)\n  {\n    if (!(ReverseBitTreeDecoder2Create(&lzmaDecoder->m_PosDecoders[i],kDistDirectBits[kStartPosModelIndex + i])))\n        return E_OUTOFMEMORY;;\n  }\n  return S_OK;\n}\n\n\nHRESULT LzmaDecoderInit(LzmaDecoder *lzmaDecoder)\n{\n  int    i;\n  UINT32 j;\n\n  RangeDecoderInit(&in_stream, &lzmaDecoder->m_RangeDecoder);\n\n  OutWindowInit();\n\n  for(i = 0; i < kNumStates; i++)\n  {\n    for (j = 0; j <= lzmaDecoder->m_PosStateMask; j++)\n    {\n      BitDecoderInit(&lzmaDecoder->m_MainChoiceDecoders[i][j]);\n      BitDecoderInit(&lzmaDecoder->m_MatchRepShortChoiceDecoders[i][j]);\n    }\n    BitDecoderInit(&lzmaDecoder->m_MatchChoiceDecoders[i]);\n    BitDecoderInit(&lzmaDecoder->m_MatchRepChoiceDecoders[i]);\n    BitDecoderInit(&lzmaDecoder->m_MatchRep1ChoiceDecoders[i]);\n    BitDecoderInit(&lzmaDecoder->m_MatchRep2ChoiceDecoders[i]);\n  }\n  \n  LitDecoderInit(&lzmaDecoder->m_LiteralDecoder);\n   \n  for (i = 0; i < (int) kNumLenToPosStates; i++)\n    BitTreeDecoderInit(&lzmaDecoder->m_PosSlotDecoder[i],kNumPosSlotBits);\n\n  for(i = 0; i < kNumPosModels; i++)\n    ReverseBitTreeDecoder2Init(&lzmaDecoder->m_PosDecoders[i]);\n  \n  LenDecoderInit(&lzmaDecoder->m_LenDecoder);\n  LenDecoderInit(&lzmaDecoder->m_RepMatchLenDecoder);\n\n  ReverseBitTreeDecoderInit(&lzmaDecoder->m_PosAlignDecoder, kNumAlignBits);\n  return S_OK;\n\n}\n\nHRESULT LzmaDecoderCodeReal( \n    LzmaDecoder     *lzmaDecoder, \n    UINT64          *anInSize, \n    UINT64          *anOutSize)\n{\n  BOOL                  aPeviousIsMatch         = FALSE;\n  BYTE                  aPreviousByte           = 0;\n  UINT32                aRepDistances[kNumRepDistances];\n  int                   i;\n  UINT64                aNowPos64               = 0;\n  UINT64                aSize                   = *anOutSize;\n  ISequentialInStream   my_in_stream;\n//  WindowOut             out_window;\n  CState                aState;\n\n  CStateInit(&aState);\n\n  if (anOutSize == NULL)\n  {\n      printf(\"CodeReal: invalid argument %x\\n\", (UINT32) anOutSize );\n      return E_INVALIDARG;\n  }\n\n\n  LzmaDecoderInit(lzmaDecoder);\n\n  my_in_stream.data           = in_stream.data;\n  my_in_stream.remainingBytes = in_stream.remainingBytes;\n\n  for(i = 0 ; i < (int) kNumRepDistances; i++)\n    aRepDistances[i] = 0;\n\n  //while(aNowPos64 < aSize)\n  while(my_in_stream.remainingBytes > 0)\n  {\n    UINT64 aNext = MyMin(aNowPos64 + (1 << 18), aSize);\n    while(aNowPos64 < aNext)\n    {\n      UINT32 aPosState = (UINT32)(aNowPos64) & lzmaDecoder->m_PosStateMask;\n      if (BitDecode(&my_in_stream, \n                    &lzmaDecoder->m_MainChoiceDecoders[aState][aPosState], \n                    &lzmaDecoder->m_RangeDecoder) == (UINT32) kMainChoiceLiteralIndex)\n      {\n        CStateUpdateChar(&aState);\n        if(aPeviousIsMatch)\n        {\n          BYTE aMatchByte = OutWindowGetOneByte(0 - aRepDistances[0] - 1);\n          aPreviousByte = LitDecodeWithMatchByte(&my_in_stream, \n                                                 &lzmaDecoder->m_LiteralDecoder, \n                                                 &lzmaDecoder->m_RangeDecoder, \n                                                 (UINT32)(aNowPos64), \n                                                 aPreviousByte, \n                                                 aMatchByte);\n          aPeviousIsMatch = FALSE;\n        }\n        else\n          aPreviousByte = LitDecodeNormal(&my_in_stream, \n                                          &lzmaDecoder->m_LiteralDecoder, \n                                          &lzmaDecoder->m_RangeDecoder, \n                                         (UINT32)(aNowPos64), \n                                          aPreviousByte);\n        OutWindowPutOneByte(aPreviousByte);\n        aNowPos64++;\n      }\n      else             \n      {\n        UINT32 aDistance, aLen;\n        aPeviousIsMatch = TRUE;\n        if(BitDecode(&my_in_stream, \n                     &lzmaDecoder->m_MatchChoiceDecoders[aState], \n                     &lzmaDecoder->m_RangeDecoder) == (UINT32) kMatchChoiceRepetitionIndex)\n        {\n          if(BitDecode(&my_in_stream, \n                       &lzmaDecoder->m_MatchRepChoiceDecoders[aState], \n                       &lzmaDecoder->m_RangeDecoder) == 0)\n          {\n            if(BitDecode(&my_in_stream, \n                         &lzmaDecoder->m_MatchRepShortChoiceDecoders[aState][aPosState], \n                         &lzmaDecoder->m_RangeDecoder) == 0)\n            {\n              CStateUpdateShortRep(&aState);\n              aPreviousByte = OutWindowGetOneByte(0 - aRepDistances[0] - 1);\n              OutWindowPutOneByte(aPreviousByte);\n              aNowPos64++;\n              continue;\n            }\n            aDistance = aRepDistances[0];\n          }\n          else\n          {\n            if(BitDecode(&my_in_stream, \n                         &lzmaDecoder->m_MatchRep1ChoiceDecoders[aState], \n                         &lzmaDecoder->m_RangeDecoder) == 0)\n            {\n              aDistance = aRepDistances[1];\n              aRepDistances[1] = aRepDistances[0];\n            }\n            else \n            {\n              if (BitDecode(&my_in_stream, \n                            &lzmaDecoder->m_MatchRep2ChoiceDecoders[aState], \n                            &lzmaDecoder->m_RangeDecoder) == 0)\n              {\n                aDistance = aRepDistances[2];\n              }\n              else\n              {\n                aDistance = aRepDistances[3];\n                aRepDistances[3] = aRepDistances[2];\n              }\n              aRepDistances[2] = aRepDistances[1];\n              aRepDistances[1] = aRepDistances[0];\n            }\n            aRepDistances[0] = aDistance;\n          }\n          aLen = LenDecode(&my_in_stream, \n                           &lzmaDecoder->m_RepMatchLenDecoder, \n                           &lzmaDecoder->m_RangeDecoder, \n                           aPosState) + kMatchMinLen;\n          CStateUpdateRep(&aState);\n        }\n        else\n        {\n          UINT32 aPosSlot;\n          aLen = kMatchMinLen + LenDecode(&my_in_stream, \n                                          &lzmaDecoder->m_LenDecoder, \n                                          &lzmaDecoder->m_RangeDecoder, \n                                          aPosState);\n          CStateUpdateMatch(&aState);\n          aPosSlot = BitTreeDecode(&my_in_stream, \n                                   &lzmaDecoder->m_PosSlotDecoder[GetLenToPosState(aLen)],\n                                   &lzmaDecoder->m_RangeDecoder);\n          if (aPosSlot >= (UINT32) kStartPosModelIndex)\n          {\n            aDistance = kDistStart[aPosSlot];\n            if (aPosSlot < (UINT32) kEndPosModelIndex)\n              aDistance += ReverseBitTreeDecoder2Decode(&my_in_stream, \n                                                        &lzmaDecoder->m_PosDecoders[aPosSlot - kStartPosModelIndex],\n                                                        &lzmaDecoder->m_RangeDecoder);\n            else\n            {\n              aDistance += (RangeDecodeDirectBits(&my_in_stream, \n                                                  &lzmaDecoder->m_RangeDecoder, \n                                                  kDistDirectBits[aPosSlot] - kNumAlignBits) << kNumAlignBits);\n              aDistance += ReverseBitTreeDecoderDecode(&my_in_stream, \n                                                       &lzmaDecoder->m_PosAlignDecoder, \n                                                       &lzmaDecoder->m_RangeDecoder);\n            }\n          }\n          else\n            aDistance = aPosSlot;\n\n          \n          aRepDistances[3] = aRepDistances[2];\n          aRepDistances[2] = aRepDistances[1];\n          aRepDistances[1] = aRepDistances[0];\n          \n          aRepDistances[0] = aDistance;\n        }\n        if (aDistance >= aNowPos64)\n        {\n            printf(\"CodeReal: invalid data\\n\" );\n            return E_INVALIDDATA;\n        }\n        OutWindowCopyBackBlock(aDistance, aLen);\n        aNowPos64 += aLen;\n        aPreviousByte = OutWindowGetOneByte(0 - 1);\n      }\n    }\n  }\n  \n  //BRCM modification\n  LzmaDecoderFreeBuffer(lzmaDecoder);\n  \n  OutWindowFlush();\n  return S_OK;\n}\n\nHRESULT LzmaDecoderCode(\n    LzmaDecoder *lzmaDecoder,\n    UINT64 *anInSize, \n    UINT64 *anOutSize)\n{\n\n    UINT32 aStartValue = 0;\n    int i;\n    \n    for (i = 0; i < kDistTableSizeMax; i++)\n    {\n        kDistStart[i] = aStartValue;\n        aStartValue += (1 << kDistDirectBits[i]);\n    }\n    return LzmaDecoderCodeReal( \n        lzmaDecoder, \n        anInSize, \n        anOutSize);\n}\n\nHRESULT LzmaDecoderReadCoderProperties(LzmaDecoder *lzmaDecoder)\n{\n  UINT32 aNumPosStateBits;\n  UINT32 aLiteralPosStateBits;\n  UINT32 aLiteralContextBits;\n  UINT32 aDictionarySize;\n  BYTE   aRemainder;\n  UINT32 aProcessesedSize;\n\n  BYTE aByte;\n  RETURN_IF_NOT_S_OK(InStreamRead(&aByte, \n                                  sizeof(aByte), \n                                  &aProcessesedSize));\n\n  if (aProcessesedSize != sizeof(aByte))\n    return E_INVALIDARG;\n\n  aLiteralContextBits   = aByte % 9;\n  aRemainder            = aByte / 9;\n  aLiteralPosStateBits  = aRemainder % 5;\n  aNumPosStateBits      = aRemainder / 5;\n\n  RETURN_IF_NOT_S_OK(InStreamRead(&aDictionarySize, \n                                  sizeof(aDictionarySize), \n                                  &aProcessesedSize));\n\n  if (aProcessesedSize != sizeof(aDictionarySize))\n    return E_INVALIDARG;\n\n  RETURN_IF_NOT_S_OK( LzmaDecoderSetDictionarySize(lzmaDecoder, \n                                                   aDictionarySize) );\n  RETURN_IF_NOT_S_OK( LzmaDecoderSetLiteralProperties(lzmaDecoder, \n                                                      aLiteralPosStateBits, \n                                                      aLiteralContextBits) );\n  RETURN_IF_NOT_S_OK( LzmaDecoderSetPosBitsProperties(lzmaDecoder, \n                                                      aNumPosStateBits) );\n\n  return S_OK;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/LZMADecoder.h",
    "content": "#ifndef __LZARITHMETIC_DECODER_H\n#define __LZARITHMETIC_DECODER_H\n\n#include \"WindowOut.h\"\n#include \"LZMA.h\"\n#include \"LenCoder.h\"\n#include \"LiteralCoder.h\"\n\n\ntypedef struct LzmaDecoder\n{\n  CRangeDecoder m_RangeDecoder;\n\n  CBitDecoder m_MainChoiceDecoders[kNumStates][kNumPosStatesMax];\n  CBitDecoder m_MatchChoiceDecoders[kNumStates];\n  CBitDecoder m_MatchRepChoiceDecoders[kNumStates];\n  CBitDecoder m_MatchRep1ChoiceDecoders[kNumStates];\n  CBitDecoder m_MatchRep2ChoiceDecoders[kNumStates];\n  CBitDecoder m_MatchRepShortChoiceDecoders[kNumStates][kNumPosStatesMax];\n\n  CBitTreeDecoder               m_PosSlotDecoder[kNumLenToPosStates];\n\n  CReverseBitTreeDecoder2       m_PosDecoders[kNumPosModels];\n  CReverseBitTreeDecoder        m_PosAlignDecoder;\n  \n  LenDecoder m_LenDecoder;\n  LenDecoder m_RepMatchLenDecoder;\n\n  LitDecoder m_LiteralDecoder;\n\n  UINT32 m_DictionarySize;\n  \n  UINT32 m_PosStateMask;\n} LzmaDecoder;\n\n  HRESULT LzmaDecoderCreate(LzmaDecoder *lzmaDecoder);\n\n  HRESULT LzmaDecoderInit(LzmaDecoder *lzmaDecoder);\n\n//static inline  HRESULT LzmaDecoderFlush() { return OutWindowFlush(); }\n\n  HRESULT LzmaDecoderCodeReal( \n      LzmaDecoder           *lzmaDecoder, \n//      ISequentialInStream   *in_stream, \n      UINT64                *anInSize, \n//      WindowOut             *out_window,\n      UINT64                *anOutSize);\n\n\n  void LzmaDecoderConstructor( LzmaDecoder *lzmaDecoder );\n  \n  HRESULT LzmaDecoderCode( LzmaDecoder *lzmaDecoder, UINT64 *anInSize, UINT64 *anOutSize);\n  HRESULT LzmaDecoderReadCoderProperties(LzmaDecoder *lzmaDecoder );\n\n  HRESULT LzmaDecoderSetDictionarySize(LzmaDecoder *lzmaDecoder, UINT32 aDictionarySize);\n  HRESULT LzmaDecoderSetLiteralProperties(LzmaDecoder *lzmaDecoder, UINT32 aLiteralPosStateBits, UINT32 aLiteralContextBits);\n  HRESULT LzmaDecoderSetPosBitsProperties(LzmaDecoder *lzmaDecoder, UINT32 aNumPosStateBits);\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/LenCoder.h",
    "content": "#ifndef __LENCODER_H\n#define __LENCODER_H\n\n#include \"BitTreeCoder.h\"\n\n\n#define kNumPosStatesBitsMax 4\n#define kNumPosStatesMax 16\n\n\n#define kNumPosStatesBitsEncodingMax 4\n#define kNumPosStatesEncodingMax 16\n\n\n//#define kNumMoveBits 5\n\n#define kNumLenBits 3\n#define kNumLowSymbols (1 << kNumLenBits)\n\n#define kNumMidBits 3\n#define kNumMidSymbols (1 << kNumMidBits)\n\n#define kNumHighBits 8\n\n#define kNumSymbolsTotal (kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits))\n\ntypedef struct LenDecoder\n{\n  CBitDecoder       m_Choice;\n  CBitDecoder       m_Choice2;\n  CBitTreeDecoder   m_LowCoder[kNumPosStatesMax];\n  CBitTreeDecoder   m_MidCoder[kNumPosStatesMax];\n  CBitTreeDecoder   m_HighCoder; \n  UINT32            m_NumPosStates;\n} LenDecoder;\n\nINLINE void LenDecoderCreate(LenDecoder *lenCoder, UINT32 aNumPosStates)\n  { \n    lenCoder->m_NumPosStates = aNumPosStates; \n  }\n\nINLINE void LenDecoderInit(LenDecoder *lenCoder)\n  {\n    UINT32 aPosState;\n    BitDecoderInit(&lenCoder->m_Choice);\n    for (aPosState = 0; aPosState < lenCoder->m_NumPosStates; aPosState++)\n    {\n      BitTreeDecoderInit(&lenCoder->m_LowCoder[aPosState],kNumLenBits);\n      BitTreeDecoderInit(&lenCoder->m_MidCoder[aPosState],kNumMidBits);\n    }\n    BitTreeDecoderInit(&lenCoder->m_HighCoder,kNumHighBits);\n    BitDecoderInit(&lenCoder->m_Choice2);\n  }\n\nINLINE UINT32 LenDecode(ISequentialInStream *in_stream, LenDecoder *lenCoder, CRangeDecoder *aRangeDecoder, UINT32 aPosState)\n  {\n    if(BitDecode(in_stream, &lenCoder->m_Choice, aRangeDecoder) == 0)\n      return BitTreeDecode(in_stream, &lenCoder->m_LowCoder[aPosState],aRangeDecoder);\n    else\n    {\n      UINT32 aSymbol = kNumLowSymbols;\n      if(BitDecode(in_stream, &lenCoder->m_Choice2, aRangeDecoder) == 0)\n        aSymbol += BitTreeDecode(in_stream, &lenCoder->m_MidCoder[aPosState],aRangeDecoder);\n      else\n      {\n        aSymbol += kNumMidSymbols;\n        aSymbol += BitTreeDecode(in_stream, &lenCoder->m_HighCoder,aRangeDecoder);\n      }\n      return aSymbol;\n    }\n  }\n\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/LiteralCoder.h",
    "content": "#ifndef __LITERALCODER_H\n#define __LITERALCODER_H\n\n#include \"AriBitCoder.h\"\n#include \"RCDefs.h\"\n\n//BRCM modification start\n#ifdef _HOST_TOOL\n#include \"stdio.h\"\n#include \"malloc.h\" \n#endif\n\n#ifdef _CFE_\n#include \"lib_malloc.h\"\n#include \"lib_printf.h\"\n#define malloc(x) KMALLOC(x, 0)\n#define free(x) KFREE(x)\n#endif\n\n#ifdef __KERNEL__\n#include <linux/kernel.h>\n#include <linux/slab.h>\n#define printf  printk\n//#define malloc(x)  kmalloc(x,GFP_KERNEL)\n#define malloc(x)  vmalloc(x)\n#define free(x) vfree(x)\n#endif\n//BRCM modification end\n\n//#define kNumMoveBits 5\n\ntypedef struct LitDecoder2\n{\n  CBitDecoder m_Decoders[3][1 << 8];\n} LitDecoder2;\n\n\nINLINE void LitDecoder2Init(LitDecoder2 *litDecoder2)\n  {\n    int i, j;\n    for (i = 0; i < 3; i++)\n      for (j = 1; j < (1 << 8); j++)\n        BitDecoderInit(&litDecoder2->m_Decoders[i][j]);\n  }\n\nINLINE BYTE LitDecoder2DecodeNormal(ISequentialInStream *in_stream, LitDecoder2 *litDecoder2, CRangeDecoder *aRangeDecoder)\n  {\n    UINT32 aSymbol = 1;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;        \n    do\n    {\n      RC_GETBIT(kNumMoveBits, litDecoder2->m_Decoders[0][aSymbol], aSymbol)\n    }\n    while (aSymbol < 0x100);\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aSymbol;\n  }\n\nINLINE BYTE LitDecoder2DecodeWithMatchByte(ISequentialInStream *in_stream, LitDecoder2 *litDecoder2, CRangeDecoder *aRangeDecoder, BYTE aMatchByte)\n  {\n    UINT32 aSymbol = 1;\n    UINT32 aRange = aRangeDecoder->m_Range;\n    UINT32 aCode = aRangeDecoder->m_Code;        \n    do\n    {\n      UINT32 aBit;\n      UINT32 aMatchBit = (aMatchByte >> 7) & 1;\n      aMatchByte <<= 1;\n      RC_GETBIT2(kNumMoveBits, litDecoder2->m_Decoders[1 + aMatchBit][aSymbol], aSymbol, \n          aBit = 0, aBit = 1)\n      if (aMatchBit != aBit)\n      {\n        while (aSymbol < 0x100)\n        {\n          RC_GETBIT(kNumMoveBits, litDecoder2->m_Decoders[0][aSymbol], aSymbol)\n        }\n        break;\n      }\n    }\n    while (aSymbol < 0x100);\n    aRangeDecoder->m_Range = aRange;\n    aRangeDecoder->m_Code = aCode;\n    return aSymbol;\n  }\n\n\ntypedef struct LitDecoder\n{\n  LitDecoder2 *m_Coders;\n  UINT32 m_NumPrevBits;\n  UINT32 m_NumPosBits;\n  UINT32 m_PosMask;\n} LitDecoder;\n\n\n//  LitDecoder(): m_Coders(0) {}\n//  ~LitDecoder()  { Free(); }\n\n/*\nINLINE void LitDecoderFree(LitDecoder *litDecoder)\n  { \n    free( (char *) litDecoder->m_Coders );\n    litDecoder->m_Coders = 0;\n  }\n*/\n\nINLINE void LitDecoderCreate(LitDecoder *litDecoder, UINT32 aNumPosBits, UINT32 aNumPrevBits)\n  {\n//    LitDecoderFree(litDecoder);\n    UINT32 aNumStates;\n    litDecoder->m_NumPosBits = aNumPosBits;\n    litDecoder->m_PosMask = (1 << aNumPosBits) - 1;\n    litDecoder->m_NumPrevBits = aNumPrevBits;\n    aNumStates = 1 << (aNumPrevBits + aNumPosBits);\n    litDecoder->m_Coders = (LitDecoder2*) malloc( sizeof( LitDecoder2 ) * aNumStates );\n    //printf(\"malloc in LitDecoderCreate=%d\\n\",sizeof( LitDecoder2 ) * aNumStates);\n    if (litDecoder->m_Coders == 0)\n        printf( \"Error allocating memory for LitDecoder m_Coders!\\n\" );\n  }\n\nINLINE void LitDecoderInit(LitDecoder *litDecoder)\n  {\n    UINT32 i;\n    UINT32 aNumStates = 1 << (litDecoder->m_NumPrevBits + litDecoder->m_NumPosBits);\n    for (i = 0; i < aNumStates; i++)\n      LitDecoder2Init(&litDecoder->m_Coders[i]);\n  }\n\nINLINE UINT32 LitDecoderGetState(LitDecoder *litDecoder, UINT32 aPos, BYTE aPrevByte)\n  { \n    return ((aPos & litDecoder->m_PosMask) << litDecoder->m_NumPrevBits) + (aPrevByte >> (8 - litDecoder->m_NumPrevBits)); \n  }\n\nINLINE BYTE LitDecodeNormal(ISequentialInStream *in_stream, LitDecoder *litDecoder, CRangeDecoder *aRangeDecoder, UINT32 aPos, BYTE aPrevByte)\n  { \n    return LitDecoder2DecodeNormal(in_stream, &litDecoder->m_Coders[LitDecoderGetState(litDecoder, aPos, aPrevByte)], aRangeDecoder); \n  }\n\nINLINE BYTE LitDecodeWithMatchByte(ISequentialInStream *in_stream, LitDecoder *litDecoder, CRangeDecoder *aRangeDecoder, UINT32 aPos, BYTE aPrevByte, BYTE aMatchByte)\n  { \n      return LitDecoder2DecodeWithMatchByte(in_stream, &litDecoder->m_Coders[LitDecoderGetState(litDecoder, aPos, aPrevByte)], aRangeDecoder, aMatchByte); \n  }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/Makefile",
    "content": "INCLUDEDIR = .\n\nCC=gcc\n\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\n\nall:7zlzma.o  IInOutStreams.o  LZMADecoder.o\n\nclean :\n\trm -f *.o\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/Portable.h",
    "content": "#ifndef __PORTABLE_H\n#define __PORTABLE_H\n\n//BRCM modification\n#ifdef _HOST_TOOL\n#include <string.h>\n#endif\n\n#ifdef _CFE_\n#include <string.h>\n#endif\n\n#ifdef __KERNEL__\n#include <linux/string.h>\n#endif\n\n//bcm\n//#ifdef __GNUC__   \n//#include <types/vxTypesOld.h>\n//#define INLINE static inline\n//#else\ntypedef char INT8;\ntypedef unsigned char UINT8;\ntypedef short INT16;\ntypedef unsigned short UINT16;\ntypedef int INT32;\ntypedef unsigned int UINT32;\ntypedef int BOOL;\n#define INLINE static inline\n//#define INLINE static __inline__\n//#endif\ntypedef long long INT64;           // %%%% Changed from \"long long\"\ntypedef unsigned long long UINT64; // %%%% Changed from \"long long\"\n\ntypedef UINT8 BYTE;\ntypedef UINT16 WORD;\ntypedef UINT32 DWORD;\n\ntypedef unsigned UINT_PTR;\n#define FALSE 0\n#define TRUE 1\n\n#define HRESULT int\n#define S_OK 0\n#define E_INVALIDARG -1\n#define E_OUTOFMEMORY -2\n#define E_FAIL -3\n#define E_INTERNAL_ERROR -4\n#define E_INVALIDDATA -5\n\n#define MyMin( a, b ) ( a < b ? a : b )\n\n#define MyMax( a, b ) ( a > b ? a : b )\n\n#define kNumMoveBits 5\n\n#define RETURN_IF_NOT_S_OK(x) { HRESULT __aResult_ = (x); if(__aResult_ != S_OK) return __aResult_; }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/RCDefs.h",
    "content": "#ifndef __RCDEFS_H\n#define __RCDEFS_H\n\n#include \"AriBitCoder.h\"\n\n/*\n#define RC_INIT_VAR                            \\\n  UINT32 aRange = aRangeDecoder->m_Range;      \\\n  UINT32 aCode = aRangeDecoder->m_Code;        \n\n#define RC_FLUSH_VAR                          \\\n  aRangeDecoder->m_Range = aRange;            \\\n  aRangeDecoder->m_Code = aCode;\n*/\n\n\n#if 1\n#define RC_GETBIT2(aNumMoveBits, aProb, aModelIndex, Action0, Action1)                        \\\n    {UINT32 aNewBound = (aRange >> kNumBitModelTotalBits) * aProb; \\\n    if (aCode < aNewBound)                               \\\n    {                                                             \\\n      Action0;                                                    \\\n      aRange = aNewBound;                                         \\\n      aProb += (kBitModelTotal - aProb) >> aNumMoveBits;          \\\n      aModelIndex <<= 1;                                          \\\n    }                                                             \\\n    else                                                          \\\n    {                                                             \\\n      Action1;                                                    \\\n      aRange -= aNewBound;                                        \\\n      aCode -= aNewBound;                                          \\\n      aProb -= (aProb) >> aNumMoveBits;                           \\\n      aModelIndex = (aModelIndex << 1) + 1;                       \\\n    }}                                                             \\\n    if (aRange < kTopValue)               \\\n    {                                                              \\\n      aCode = (aCode << 8) | InStreamReadByte(in_stream);   \\\n      aRange <<= 8; }\n\n#define RC_GETBIT(aNumMoveBits, aProb, aModelIndex) RC_GETBIT2(aNumMoveBits, aProb, aModelIndex, ; , ;)               \n#endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/RangeCoder.h",
    "content": "#ifndef __COMPRESSION_RANGECODER_H\n#define __COMPRESSION_RANGECODER_H\n\n#include \"IInOutStreams.h\"\n\n#define kNumTopBits 24\n#define kTopValue (1 << kNumTopBits)\n\ntypedef struct CRangeDecoder\n{\n  UINT32  m_Range;\n  UINT32  m_Code;\n} CRangeDecoder;\n\n\n\nINLINE void RangeDecoderInit(\n    ISequentialInStream *in_stream, \n    CRangeDecoder *rangeDecoder)\n  {\n    int i;\n    rangeDecoder->m_Code = 0;\n    rangeDecoder->m_Range = (UINT32)(-1);\n    for(i = 0; i < 5; i++)\n      rangeDecoder->m_Code = (rangeDecoder->m_Code << 8) | InStreamReadByte(in_stream);\n  }\n\nINLINE UINT32 RangeDecodeDirectBits(\n    ISequentialInStream *in_stream, \n    CRangeDecoder *rangeDecoder, \n    UINT32 aNumTotalBits)\n  {\n    UINT32 aRange = rangeDecoder->m_Range;\n    UINT32 aCode = rangeDecoder->m_Code;        \n    UINT32 aResult = 0;\n    UINT32 i;\n    for (i = aNumTotalBits; i > 0; i--)\n    {\n      UINT32 t;\n      aRange >>= 1;\n      t = (aCode - aRange) >> 31;\n      aCode -= aRange & (t - 1);\n      aResult = (aResult << 1) | (1 - t);\n\n      if (aRange < kTopValue)\n      {\n        aCode = (aCode << 8) | InStreamReadByte(in_stream);\n        aRange <<= 8; \n      }\n    }\n    rangeDecoder->m_Range = aRange;\n    rangeDecoder->m_Code = aCode;\n    return aResult;\n  }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/WindowOut.h",
    "content": "#ifndef __STREAM_WINDOWOUT_H\n#define __STREAM_WINDOWOUT_H\n\n#include \"IInOutStreams.h\"\n\ntypedef struct WindowOut\n{\n  BYTE  *Buffer;\n  UINT32 Pos;\n} WindowOut;\n\nextern WindowOut out_window;\n\n#define OutWindowInit() \\\n  { \\\n    out_window.Buffer = (BYTE *) out_stream.data; \\\n    out_window.Pos = 0; \\\n  }\n\n#define OutWindowFlush() \\\n  { \\\n    OutStreamSizeSet( out_window.Pos ); \\\n  } \n\n// BRCM modification \nINLINE void OutWindowCopyBackBlock(UINT32 aDistance, UINT32 aLen)\n  {\n    BYTE   *p = out_window.Buffer + out_window.Pos;\n    UINT32  i;\n    aDistance++;\n    for(i = 0; i < aLen; i++)\n      p[i] = p[i - aDistance];\n    out_window.Pos += aLen;\n  }\n\n\n#define OutWindowPutOneByte(aByte) \\\n  { \\\n    out_window.Buffer[out_window.Pos++] = aByte; \\\n  } \n\n#define OutWindowGetOneByte(anIndex) \\\n     (out_window.Buffer[out_window.Pos + anIndex])\n\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/brcm-lzma/vxTypesOld.h",
    "content": "/* vxTypesOld.h - old VxWorks type definition header */\n\n/* Copyright 1984-1997 Wind River Systems, Inc. */\n\n/*\nmodification history\n--------------------\n02c,15aug97,cym  added simnt support.\n02d,26mar97,cdp  added Thumb (ARM7TDMI_T) support.\n02c,28nov96,cdp  added ARM support.\n02b,28sep95,ms\t removed \"static __inline__\" (SPR #4500)\n02b,12jul95,ism  added simsolaris support\n02a,19mar95,dvs  removed tron references.\n01z,01sep94,ism  fixed comment as per SPR# 1512.\n01y,02dec93,pme  added Am29K family support.\n01x,12jun93,rrr  vxsim.\n02a,26may94,yao  added PPC support.\n01w,09jun93,hdn  added support for I80X86\n01v,12feb93,srh  added C++ versions of FUNCPTR, et al.\n01u,13nov92,dnw  added definition of VOID (SPR #1781)\n01t,02oct92,srh  replaced conditional around volatile, const, and signed so\n                 they won't be elided when __STDC__ is defined.\n                 added __cplusplus to __STDC__ condition.\n01s,22sep92,rrr  added support for c++\n01r,08sep92,smb  made some additions for the MIPS.\n01q,07sep92,smb  added __STDC__ and modes to maintain compatibility with 5.0\n01p,07jul92,rrr  moved STACK_GROW and ENDIAN to vxArch.h\n01o,03jul92,smb  changed name from vxTypes.h.\n01n,26may92,rrr  the tree shuffle\n01m,25nov91,llk  included sys/types.h.\n01l,04oct91,rrr  passed through the ansification filter\n\t\t  -fixed #else and #endif\n\t\t  -removed TINY and UTINY\n\t\t  -changed VOID to void\n\t\t  -changed ASMLANGUAGE to _ASMLANGUAGE\n\t\t  -changed copyright notice\n01k,01oct91,jpb  fixed MIPS conditional for undefined CPU_FAMILY.\n01j,20sep91,wmd  conditionalized out defines for const, unsigned and volatile\n\t\t for the MIPS architecture.\n01i,02aug91,ajm  added support for MIPS_R3k.\n01h,15may91,gae  added define for \"signed\" when not available for pre-ANSI.\n01g,29apr91,hdn  added defines and macros for TRON architecture.\n01f,28apr91,del  added defines of __volatile__ and __const__ if !_STDC_\n\t\t && _GNUC__\n01f,24mar91,del  added INSTR * define for I960.\n01e,28jan91,kdl  added DBLFUNCPTR and FLTFUNCPTR.\n01d,25oct90,dnw  changed void to void except when linting.\n01c,05oct90,shl  added copyright notice.\n                 made #endif ANSI style.\n01b,10aug90,dnw  added VOIDFUNCPTR\n01a,29may90,del  written.\n*/\n\n/*\nDESCRIPTION\nThis header file contains a mixture of stuff.\n1) the old style typedefs (ie. POSIX now says they must end with _t).\n   These will be phased out gradually.\n2) a mechanism for getting rid of const warning which are produced by the\n   GNU C compiler. Hopefully, this will be removed in the future.\n3) macros that are so longer needed for vxWorks source code but maybe needed\n   by some customer applications and are therefore provided for backward\n   compatability.\n4) system III typedefs (used by netinet) which do not fit in anywhere else.\n\n*/\n\n#ifndef __INCvxTypesOldh\n#define __INCvxTypesOldh\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include \"sys/types.h\"\n\n/* vxWorks types */\n\ntypedef\tchar\t\tINT8;\ntypedef\tshort\t\tINT16;\ntypedef\tint\t\tINT32;\n\ntypedef\tunsigned char\tUINT8;\ntypedef\tunsigned short\tUINT16;\ntypedef\tunsigned int\tUINT32;\n\ntypedef\tunsigned char\tUCHAR;\ntypedef unsigned short\tUSHORT;\ntypedef\tunsigned int\tUINT;\ntypedef unsigned long\tULONG;\n\ntypedef\tint\t\tBOOL;\ntypedef\tint\t\tSTATUS;\ntypedef int \t\tARGINT;\n\ntypedef void\t\tVOID;\n\n#ifdef __cplusplus\ntypedef int \t\t(*FUNCPTR) (...);     /* ptr to function returning int */\ntypedef void \t\t(*VOIDFUNCPTR) (...); /* ptr to function returning void */\ntypedef double \t\t(*DBLFUNCPTR) (...);  /* ptr to function returning double*/\ntypedef float \t\t(*FLTFUNCPTR) (...);  /* ptr to function returning float */\n#else\ntypedef int \t\t(*FUNCPTR) ();\t   /* ptr to function returning int */\ntypedef void \t\t(*VOIDFUNCPTR) (); /* ptr to function returning void */\ntypedef double \t\t(*DBLFUNCPTR) ();  /* ptr to function returning double*/\ntypedef float \t\t(*FLTFUNCPTR) ();  /* ptr to function returning float */\n#endif\t\t\t/* _cplusplus */\n\n\n/* This structure and the following definitions are needed to get rid\n   of const warning produced by the GNU C compiler.\n */\n\n#if defined(__STDC__) || defined(__cplusplus)\ntypedef union\n    {\n    long pm_int;\n    void *pm_v;\n    const void *pm_cv;\n    char *pm_c;\n    unsigned char *pm_uc;\n\n    signed char *pm_sc;\n    const char *pm_cc;\n    const unsigned char *pm_cuc;\n    const signed char *pm_csc;\n    short *pm_s;\n    ushort_t *pm_us;\n    const short *pm_cs;\n    const ushort_t *pm_cus;\n    int *pm_i;\n    uint_t *pm_ui;\n    const int *pm_ci;\n    const uint_t *pm_cui;\n    long *pm_l;\n    ulong_t *pm_ul;\n    const long *pm_cl;\n    const ulong_t *pm_cul;\n\n    int8_t *pm_i8;\n    uint8_t *pm_ui8;\n    const int8_t *pm_ci8;\n    const uint8_t *pm_cui8;\n    int16_t *pm_i16;\n    uint16_t *pm_ui16;\n    const int16_t *pm_ci16;\n    const uint16_t *pm_cui16;\n    int32_t *pm_i32;\n    uint32_t *pm_ui32;\n    const int32_t *pm_ci32;\n    const uint32_t *pm_cui32;\n#if _ARCH_MOVE_SIZE > 4\n    int64_t *pm_i64;\n    const int64_t *pm_ci64;\n#if _ARCH_MOVE_SIZE > 8\n    int128_t *pm_i128;\n    const int128_t *pm_ci128;\n#endif\n#endif\n    } pointer_mix_t;\n\n#define CHAR_FROM_CONST(x)\t(char *)(x)\n#define VOID_FROM_CONST(x)\t(void *)(x)\n\n#endif /* __STDC__ */\n\n#define STACK_DIR\t\t_ARCH_STACK_DIR\n#define ALIGN_MEMORY\t\t_ARCH_ALIGN_MEMORY\n#define ALIGN_STACK\t\t_ARCH_ALIGN_STACK\n#define ALIGN_REGS\t\t_ARCH_ALIGN_REGS\n\n#define\tNBBY\t8\t\t/* number of bits in a byte */\n\n/* modes - must match O_RDONLY/O_WRONLY/O_RDWR in ioLib.h! */\n\n#define READ            0\n#define WRITE           1\n#define UPDATE          2\n\n/* Select uses bit masks of file descriptors in longs.\n * These macros manipulate such bit fields (the filesystem macros use chars).\n * FD_SETSIZE may be defined by the user, but the default here\n * should be >= maxFiles parameter in iosInit call found in usrConfig.c.\n * If this define is changed, recompile the source, or else select() will\n * not work.\n */\n\n#ifndef\tFD_SETSIZE\n#define\tFD_SETSIZE\t256\n#endif\t/* FD_SETSIZE */\n\ntypedef long\tfd_mask;\n#define NFDBITS\t(sizeof(fd_mask) * NBBY)\t/* bits per mask */\n#ifndef howmany\n#define\thowmany(x, y)\t((unsigned int)(((x)+((y)-1)))/(unsigned int)(y))\n#endif\t/* howmany */\n\ntypedef\tstruct fd_set\n    {\n    fd_mask\tfds_bits[howmany(FD_SETSIZE, NFDBITS)];\n    } fd_set;\n\n#define\tFD_SET(n, p)\t((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))\n#define\tFD_CLR(n, p)\t((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))\n#define\tFD_ISSET(n, p)\t((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))\n#define FD_ZERO(p)\tbzero((char *)(p), sizeof(*(p)))\n\n\n/* system III  typedefs (used by netinet) */\n\ntypedef\tunsigned char\tu_char;\ntypedef\tunsigned short\tu_short;\ntypedef\tunsigned int\tu_int;\ntypedef\tunsigned long\tu_long;\ntypedef\tunsigned short\tushort;\n\n\n/* historical definitions - now obsolete */\n\ntypedef char\t\tTBOOL;\t\t/* obsolete */\n\n\n/* architecture dependent typedefs */\n\n#ifdef\tCPU_FAMILY\n\n#if\tCPU_FAMILY==MC680X0 \ntypedef unsigned short INSTR;\t\t/* word-aligned instructions */\n#endif\t/* CPU_FAMILY==MC680X0 */\n\n#if\tCPU_FAMILY==SPARC || CPU_FAMILY==MIPS || CPU_FAMILY==SIMSPARCSUNOS || CPU_FAMILY==SIMHPPA || CPU_FAMILY==SIMSPARCSOLARIS\ntypedef unsigned long INSTR;\t\t/* 32 bit word-aligned instructions */\n#endif\t/* CPU_FAMILY==SPARC || CPU_FAMILY==MIPS || CPU_FAMILY==SIMSPARCSUNOS || CPU_FAMILY==SIMHPPA || CPU_FAMILY==SIMSPARCSOLARIS */\n\n#if\tCPU_FAMILY==I960\ntypedef\tunsigned long INSTR;\t\t/* 32 bit word-aligned instructions */\n#endif\t/* CPU_FAMILY==I960 */\n\n#if\tCPU_FAMILY==I80X86 || CPU_FAMILY==SIMNT\ntypedef\tunsigned char INSTR;\t\t/* char instructions */\n#endif\t/* CPU_FAMILY==I80X86 || CPU_FAMILY==SIMNT */\n\n#if\tCPU_FAMILY==AM29XXX\ntypedef\tunsigned long INSTR;\t\t/* 32 bit word-aligned instructions */\n#endif\t/* CPU_FAMILY==AM29XXX */\n\n#if     (CPU_FAMILY==PPC)\ntypedef unsigned long INSTR;            /* 32 bit word-aligned instructions */\n#endif  /* (CPU_FAMILY==PPC) */\n\n#if     CPU_FAMILY==ARM\n#if\tCPU==ARM7TDMI_T\ntypedef unsigned short INSTR;           /* 16 bit instructions */\n#else\ntypedef unsigned long INSTR;            /* 32 bit word-aligned instructions */\n#endif\n#endif  /* CPU_FAMILY==ARM */\n\n#endif\t/* CPU_FAMILY */\n\n/* ANSI type qualifiers */\n\n#if !defined(__STDC__) && !defined(__cplusplus)\n\n#ifdef  __GNUC__\n#define\tvolatile\t__volatile__\n#define\tconst\t\t__const__\n#define\tsigned\t\t__signed__\n#else\n#if     !(defined(CPU_FAMILY) && CPU_FAMILY==MIPS)\n#define\tvolatile\n#define\tconst\n#define\tsigned\n#endif\t/* !(defined(CPU_FAMILY) && CPU_FAMILY==MIPS) */\n#endif\t/* __GNUC__ */\n\n#endif\t/* !defined(__STDC__) && !defined(__cplusplus) */\n\n#if     CPU_FAMILY==MIPS\n#define CHAR_FROM_CONST(x)\t(char *)(x)\n#define VOID_FROM_CONST(x)\t(void *)(x)\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* __INCvxTypesOldh */\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\ntypedef union squashfs_inode_header_1 squashfs_inode_header_1;\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/nb4-unsquash.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n *  Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_1_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#define Z_OK            0\n#define Z_MEM_ERROR    (-4)\n#define Z_BUF_ERROR    (-5)\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <sys/mman.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#if defined(__GNUC__) && !defined(__MACOSX__)\n  #include <endian.h>\n#else\n  #define __BYTE_ORDER BYTE_ORDER\n  #define __BIG_ENDIAN BIG_ENDIAN\n  #define __LITTLE_ENDIAN LITTLE_ENDIAN\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"7z.h\"\n\n#if defined(__CYGWIN__) || defined(__MACOSX__)\n  #define FNM_EXTMATCH (1 << 5)\n#endif\n\n#ifdef __CYGWIN__\n  #define SYSTEM_UID 18\n#else\n  #define SYSTEM_UID 0\n#endif\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(char *pathname, unsigned int block_start, unsigned int offset);\n\tchar *(*read_fragment)(unsigned int fragment);\n\tvoid (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, unsigned char *block_ptr, int blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar symlink[65536];\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n};\n\t\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE, use_regex = FALSE;\nchar **created_inode;\nint root_process;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0} };\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\tif((user = getpwuid(inode->uid)) == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tif((group = getgrgid(inode->gid)) == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0, inode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \", (int) inode->data >> 8, (int) inode->data & 0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n                res = decompress_lzma_7z((unsigned char *) buffer, c_byte, (unsigned char *) block, bytes);\n\n\t\tif(res != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n                res = decompress_lzma_7z((unsigned char *) data, c_byte,\n                (unsigned char *) block, bytes);\n\t\tif(res != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid read_block_list(unsigned int *block_list, unsigned char *block_ptr, int blocks)\n{\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nvoid read_block_list_1(unsigned int *block_list, unsigned char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) | (SQUASHFS_COMPRESSED(block_size) ? 0 : SQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time, unsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\tERROR(\"chown(%s, %d, %d)\\n\", pathname, uid, guid);\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_1()\n{\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nchar *read_fragment_2(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data;\nlong long hole;\n\nint write_block(int file_fd, char *buffer, int size)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(lseek_broken == FALSE && lseek(file_fd, off, SEEK_CUR) == -1) {\n\t\t\t/* failed to seek beyond end of file */\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t\tlseek_broken = TRUE;\n\t\t}\n\t\tif(lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size : hole;\n\t\t\t\tif(write(file_fd, zero_data, avail_bytes) < avail_bytes)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t\thole = 0;\n\t}\n\n\tif(write(file_fd, buffer, size) < size)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\t\nint write_file(long long file_size, char *pathname, unsigned int fragment, unsigned int frag_bytes,\nunsigned int offset, unsigned int blocks, long long start, char *block_ptr,\nunsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\tint file_end = file_size / block_size;\n\n\tTRACE(\"write_file: regular file, blocks %d, file_size %d\\n\", blocks,file_size);\n\n\thole = 0;\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\ts_ops.read_block_list(block_list, block_ptr, blocks);\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif(block_list[i] == 0) { /* sparse file */\n\t\t\thole += i == file_end ? file_size & (block_size - 1) : block_size;\n\t\t\tcontinue;\n\t\t}\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\t\tif(i < blocks-1)\n\t\t bytes=65536;\n                else\n\t\t bytes=file_size - (blocks-1)*65536 - frag_bytes;\n\n                TRACE(\"decompress %d bytes into %d bytes\\n\", SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]),bytes);\n\n\t\tif(write_block(file_fd, file_data, bytes) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = s_ops.read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write_block(file_fd, fragment_data + offset, frag_bytes) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tif(hole) {\n\t\t/* corner case for hole extending to end of file */\n\t\thole --;\n\t\tif(write_block(file_fd, \"\\0\", 1) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write sparse data block\\n\");\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\tfree(block_list);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\n\nstatic struct inode *read_inode(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i->data, pathname, i->fragment, i->frag_bytes,\n\t\t\t\t\ti->offset, i->blocks, i->start, i->block_ptr, i->mode)) {\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", i->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\tmakedev((i->data >> 8) & 0xff, i->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", i->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_2 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[header.base.uid];\n    i.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_2!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_1 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode, sizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[(header.base.inode_type - 1) / SQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) % SQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n    i.gid = header.base.guid == 15 ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_1), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_1!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(char *pathname, unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tstruct inode *i;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + i->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(pathname, i);\n\n\tbytes += i->offset;\n\tsize = i->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = i->mode;\n\tdir->uid = i->uid;\n\tdir->guid = i->gid;\n\tdir->mtime = i->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(char *pathname, unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tstruct inode *i;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + i->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(pathname, i);\n\n\tbytes += i->offset;\n\tsize = i->data + bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = i->mode;\n\tdir->uid = i->uid;\n\tdir->guid = i->gid;\n\tdir->mtime = i->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\tif(error = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB)) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing extract which subsumes the extract currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific extracts, delete as they're subsumed by this extract\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/* match on a leaf component, any subdirectories will\n\t\t\t\t * implicitly match, therefore return an empty new search set */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/* no matching names found, delete empty search set, and return\n        * FALSE */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches),\n     * return new search set and return TRUE */\n\treturn TRUE;\n\nempty_set:\n   /* found matching leaf exclude, return empty search set and return TRUE */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, struct pathnames *paths)\n{\n\tstruct dir *dir = s_ops.squashfs_opendir(parent_name, start_block, offset);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly)\n\t\t\t\tcreate_inode(pathname, i);\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str : \"failed to get time\\n\");\n\tprintf(\"Filesystem is %sexportable via NFS\\n\", SQUASHFS_EXPORTABLE(sBlk.flags) ? \"\" : \"not \");\n\n\tprintf(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tif(sBlk.s_major > 1 && !SQUASHFS_NO_FRAGMENTS(sBlk.flags))\n\t\tprintf(\"Fragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Check data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not \");\n\tif(sBlk.s_major > 1) {\n\t\tprintf(\"Fragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not \" : \"\");\n\t\tprintf(\"Always_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not \");\n\t} else\n\t\tprintf(\"Fragments are not supported by the filesystem\\n\");\n\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tprintf(\"Block size %d\\n\", sBlk.block_size);\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.fragments);\n\tprintf(\"Number of inodes %d\\n\", sBlk.inodes);\n\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tif(sBlk.s_major > 1)\n\t\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n}\n\n\nint read_super(char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk.s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk.s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 1 || sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s_major == 1) {\n\t\t\tsBlk.block_size = sBlk.block_size_1;\n\t\t\tsBlk.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t} else {\n\t\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t}\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor <= 1) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.read_block_list = read_block_list;\n\t\ts_ops.read_inode = read_inode;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tif((fd = fopen(filename, \"rb\")) == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename, strerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.5 (2007/10/31)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tchar **target_name = NULL;\n\tint n, targets = 0;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\t\n\tif(root_process = (geteuid() == SYSTEM_UID))\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 || strcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 || strcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 || strcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 || strcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 || strcmp(argv[i], \"-r\") == 0)\n\t\t\tuse_regex = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are unsquashed with file\\n\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file attributes (like\\n\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX regular expressions\\n\\t\\t\\t\\trather than use the default shell wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tblock_size = sBlk.block_size;\n\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids();\n\n\ts_ops.read_fragment_table();\n\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-2.0-nb4/nb4-unsquashfs/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t1\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/Makefile",
    "content": "INCLUDEDIR = .\nLZMAPATH = ./lzma/C/7zip/Compress/LZMA_Lib\n\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2 \n\nall: mksquashfs mksquashfs-lzma unsquashfs unsquashfs-lzma\nCC=gcc\nCXX=g++\n\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\t$(CC) mksquashfs.o read_fs.o sort.o -lz -o $@\n\nmksquashfs-lzma: mksquashfs.o read_fs.o sort.o\n\tmake -C $(LZMAPATH)\n\t$(CXX) mksquashfs.o read_fs.o sort.o -L$(LZMAPATH) -llzma -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nunsquashfs: unsquashfs.o\n\t$(CC) unsquashfs.o -lz -o $@\n\nunsquashfs-lzma: unsquashfs.o\n\tmake -C $(LZMAPATH)\n\t$(CXX) -O3 unsquashfs.o -L$(LZMAPATH) -llzma -o $@\n\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h\n\ninstall: mksquashfs-lzma\n\tcp mksquashfs-lzma /opt/buildroot-gdb/bin/mksquashfs_lzma-3.0\n\nclean:\n\t$(MAKE) -C lzma/C/7zip/Compress/LZMA_Lib clean\n\trm -f *.o mksquashfs mksquashfs-lzma unsquashfs unsquashfs-lzma\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\n\ntypedef union squashfs_inode_header squashfs_inode_header;\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/.built",
    "content": ""
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/.unpacked",
    "content": ""
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/7zC.txt",
    "content": "7z ANSI-C Decoder 4.23\r\n----------------------\r\n\r\n7z ANSI-C Decoder 4.23 Copyright (C) 1999-2005 Igor Pavlov\r\n\r\n7z ANSI-C provides 7z/LZMA decoding.\r\n7z ANSI-C version is simplified version ported from C++ code.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nRead lzma.txt for information about license.\r\n\r\n\r\nFiles\r\n---------------------\r\n\r\n7zAlloc.*    - Allocate and Free\r\n7zBuffer.*   - Buffer structure\r\n7zCrc.*      - CRC32 code\r\n7zDecode.*   - Low level memory->memory decoding\r\n7zExtract.*  - High level stream->memory decoding\r\n7zHeader.*   - .7z format constants\r\n7zIn.*       - .7z archive opening\r\n7zItem.*     - .7z structures\r\n7zMain.c     - Test application\r\n7zMethodID.* - MethodID structure\r\n7zTypes.h    - Base types and constants\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nYou must download 7-Zip program from www.7-zip.org.\r\n\r\nYou can create .7z archive with 7z.exe or 7za.exe:\r\n\r\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255\r\n\r\nIf you have big number of files in archive, and you need fast extracting, \r\nyou can use partly-solid archives:\r\n  \r\n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\r\n\r\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r\n512KB for extracting one file from such archive.\r\n\r\n\r\nLimitations of current version of 7z ANSI-C Decoder\r\n---------------------------------------------------\r\n\r\n - It reads only \"FileName\", \"Size\", and \"CRC\" information for each file in archive.\r\n - It supports only LZMA and Copy (no compression) methods.\r\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r\n \r\nThese limitations will be fixed in future versions.\r\n\r\n\r\nUsing 7z ANSI-C Decoder Test application:\r\n-----------------------------------------\r\n\r\nUsage: 7zDec <command> <archive_name>\r\n\r\n<Command>:\r\n  e: Extract files from archive\r\n  l: List contents of archive\r\n  t: Test integrity of archive\r\n\r\nExample: \r\n\r\n  7zDec l archive.7z\r\n\r\nlists contents of archive.7z\r\n\r\n  7zDec e archive.7z\r\n\r\nextracts files from archive.7z to current folder.\r\n\r\n\r\nHow to use .7z Decoder\r\n----------------------\r\n\r\n.7z Decoder can be compiled in one of two modes:\r\n\r\n1) Default mode. In that mode 7z Decoder will read full compressed \r\n   block to RAM before decompressing.\r\n  \r\n2) Mode with defined _LZMA_IN_CB. In that mode 7z Decoder can read\r\n   compressed block by parts. And you can specify desired buffer size. \r\n   So memory requirements can be reduced. But decompressing speed will \r\n   be 5-10% lower and code size is slightly larger.\r\n\r\n   \r\nMemory allocation\r\n~~~~~~~~~~~~~~~~~\r\n\r\n7z Decoder uses two memory pools:\r\n1) Temporary pool\r\n2) Main pool\r\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\r\n\r\nSteps for using 7z decoder\r\n--------------------------\r\n\r\nUse code at 7zMain.c as example.\r\n\r\n1) Declare variables:\r\n  inStream                     /* implements ISzInStream interface */\r\n  CArchiveDatabaseEx db;       /* 7z archive database structure */\r\n  ISzAlloc allocImp;           /* memory functions for main pool */\r\n  ISzAlloc allocTempImp;       /* memory functions for temporary pool */\r\n\r\n2) call InitCrcTable(); function to initialize CRC structures.\r\n\r\n3) call SzArDbExInit(&db); function to initialize db structures.\r\n\r\n4) call SzArchiveOpen(inStream, &db, &allocMain, &allocTemp) to open archive\r\n\r\nThis function opens archive \"inStream\" and reads headers to \"db\".\r\nAll items in \"db\" will be allocated with \"allocMain\" functions.\r\nSzArchiveOpen function allocates and frees temporary structures by \"allocTemp\" functions.\r\n\r\n5) List items or Extract items\r\n\r\n  Listing code:\r\n  ~~~~~~~~~~~~~\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n\r\n  Extracting code:\r\n  ~~~~~~~~~~~~~~~~\r\n\r\n  SZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n  If you need to decompress more than one file, you can send these values from previous call:\r\n    blockIndex, \r\n    outBuffer, \r\n    outBufferSize,\r\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \r\n  it will increase decompression speed.\r\n\r\n  After decompressing you must free \"outBuffer\":\r\n  allocImp.Free(outBuffer);\r\n\r\n6) call SzArDbExFree(&db, allocImp.Free) to free allocated items in \"db\".\r\n\r\n\r\n\r\n\r\nMemory requirements for .7z decoding \r\n------------------------------------\r\n\r\nMemory usage for Archive opening:\r\n  - Temporary pool:\r\n     - Memory for compressed .7z headers (if _LZMA_IN_CB is not defined)\r\n     - Memory for uncompressed .7z headers\r\n     - some other temporary blocks\r\n  - Main pool:\r\n     - Memory for database: \r\n       Estimated size of one file structures in solid archive:\r\n         - Size (4 or 8 Bytes)\r\n         - CRC32 (4 bytes)\r\n         - Some file information (4 bytes)\r\n         - File Name (variable length) + pointer + allocation structures\r\n\r\nMemory usage for archive Decompressing:\r\n  - Temporary pool:\r\n     - Memory for compressed solid block (if _LZMA_IN_CB is not defined)\r\n     - Memory for LZMA decompressing structures\r\n  - Main pool:\r\n     - Memory for decompressed solid block\r\n  \r\n\r\nIf _LZMA_IN_CB is defined, 7z Decoder will not allocate memory for \r\ncompressed blocks. Instead of this, you must allocate buffer with desired \r\nsize before calling 7z Decoder. Use 7zMain.c as example.\r\n\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\n7z Decoder functions can return one of the following codes:\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_CRC_ERROR (3)\r\n\r\n#define SZE_NOTIMPL (4)\r\n#define SZE_FAIL (5)\r\n\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB       - Use special callback mode for input stream to reduce memory requirements\r\n\r\n_SZ_FILE_SIZE_64  - define it if you need support for files larger than 4 GB\r\n_SZ_NO_INT_64     - define it if your compiler doesn't support long long int\r\n\r\n_LZMA_PROB32      - it can increase LZMA decompressing speed on some 32-bit CPUs.\r\n\r\n_SZ_ONE_DIRECTORY - define it if you want to locate all source files to one directory\r\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\r\n-----------------------------------\r\n\r\nThis file contains description of 7z archive format. \r\n7z archive can contain files compressed with any method.\r\nSee \"Methods.txt\" for description for defined compressing methods.\r\n\r\n\r\nFormat structure Overview\r\n-------------------------\r\n\r\nSome fields can be optional.\r\n\r\nArchive structure\r\n~~~~~~~~~~~~~~~~~  \r\nSignatureHeader\r\n[PackedStreams]\r\n[PackedStreamsForHeaders]\r\n[\r\n  Header \r\n  or \r\n  {\r\n    Packed Header\r\n    HeaderInfo\r\n  }\r\n]\r\n\r\n\r\n\r\nHeader structure\r\n~~~~~~~~~~~~~~~~  \r\n{\r\n  ArchiveProperties\r\n  AdditionalStreams\r\n  {\r\n    PackInfo\r\n    {\r\n      PackPos\r\n      NumPackStreams\r\n      Sizes[NumPackStreams]\r\n      CRCs[NumPackStreams]\r\n    }\r\n    CodersInfo\r\n    {\r\n      NumFolders\r\n      Folders[NumFolders]\r\n      {\r\n        NumCoders\r\n        CodersInfo[NumCoders]\r\n        {\r\n          ID\r\n          NumInStreams;\r\n          NumOutStreams;\r\n          PropertiesSize\r\n          Properties[PropertiesSize]\r\n        }\r\n        NumBindPairs\r\n        BindPairsInfo[NumBindPairs]\r\n        {\r\n          InIndex;\r\n          OutIndex;\r\n        }\r\n        PackedIndices\r\n      }\r\n      UnPackSize[Folders][Folders.NumOutstreams]\r\n      CRCs[NumFolders]\r\n    }\r\n    SubStreamsInfo\r\n    {\r\n      NumUnPackStreamsInFolders[NumFolders];\r\n      UnPackSizes[]\r\n      CRCs[]\r\n    }\r\n  }\r\n  MainStreamsInfo\r\n  {\r\n    (Same as in AdditionalStreams)\r\n  }\r\n  FilesInfo\r\n  {\r\n    NumFiles\r\n    Properties[]\r\n    {\r\n      ID\r\n      Size\r\n      Data\r\n    }\r\n  }\r\n}\r\n\r\nHeaderInfo structure\r\n~~~~~~~~~~~~~~~~~~~~\r\n{\r\n  (Same as in AdditionalStreams)\r\n}\r\n\r\n\r\n\r\nNotes about Notation and encoding\r\n---------------------------------\r\n\r\n7z uses little endian encoding.\r\n\r\n7z archive format has optional headers that are marked as\r\n[]\r\nHeader\r\n[]\r\n\r\nREAL_UINT64 means real UINT64.\r\n\r\nUINT64 means real UINT64 encoded with the following scheme:\r\n\r\n  Size of encoding sequence depends from first byte:\r\n  First_Byte  Extra_Bytes        Value\r\n  (binary)   \r\n  0xxxxxxx               : ( xxxxxxx           )\r\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r\n  ...\r\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r\n  11111110    BYTE y[7]  :                         y\r\n  11111111    BYTE y[8]  :                         y\r\n\r\n\r\n\r\nProperty IDs\r\n------------\r\n\r\n0x00 = kEnd,\r\n\r\n0x01 = kHeader,\r\n\r\n0x02 = kArchiveProperties,\r\n    \r\n0x03 = kAdditionalStreamsInfo,\r\n0x04 = kMainStreamsInfo,\r\n0x05 = kFilesInfo,\r\n    \r\n0x06 = kPackInfo,\r\n0x07 = kUnPackInfo,\r\n0x08 = kSubStreamsInfo,\r\n\r\n0x09 = kSize,\r\n0x0A = kCRC,\r\n\r\n0x0B = kFolder,\r\n\r\n0x0C = kCodersUnPackSize,\r\n0x0D = kNumUnPackStream,\r\n\r\n0x0E = kEmptyStream,\r\n0x0F = kEmptyFile,\r\n0x10 = kAnti,\r\n\r\n0x11 = kName,\r\n0x12 = kCreationTime,\r\n0x13 = kLastAccessTime,\r\n0x14 = kLastWriteTime,\r\n0x15 = kWinAttributes,\r\n0x16 = kComment,\r\n\r\n0x17 = kEncodedHeader,\r\n\r\n\r\n7z format headers\r\n-----------------\r\n\r\nSignatureHeader\r\n~~~~~~~~~~~~~~~\r\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n\r\n  ArchiveVersion\r\n  {\r\n    BYTE Major;   // now = 0\r\n    BYTE Minor;   // now = 2\r\n  };\r\n\r\n  UINT32 StartHeaderCRC;\r\n\r\n  StartHeader\r\n  {\r\n    REAL_UINT64 NextHeaderOffset\r\n    REAL_UINT64 NextHeaderSize\r\n    UINT32 NextHeaderCRC\r\n  }\r\n\r\n\r\n...........................\r\n\r\n\r\nArchiveProperties\r\n~~~~~~~~~~~~~~~~~\r\nBYTE NID::kArchiveProperties (0x02)\r\nwhile(true)\r\n{\r\n  BYTE PropertyType;\r\n  if (aType == 0)\r\n    break;\r\n  UINT64 PropertySize;\r\n  BYTE PropertyData[PropertySize];\r\n}\r\n\r\n\r\nDigests (NumStreams)\r\n~~~~~~~~~~~~~~~~~~~~~\r\n  BYTE AllAreDefined\r\n  if (AllAreDefined == 0)\r\n  {\r\n    for(NumStreams)\r\n      BIT Defined\r\n  }\r\n  UINT32 CRCs[NumDefined]\r\n\r\n\r\nPackInfo\r\n~~~~~~~~~~~~\r\n  BYTE NID::kPackInfo  (0x06)\r\n  UINT64 PackPos\r\n  UINT64 NumPackStreams\r\n\r\n  []\r\n  BYTE NID::kSize    (0x09)\r\n  UINT64 PackSizes[NumPackStreams]\r\n  []\r\n\r\n  []\r\n  BYTE NID::kCRC      (0x0A)\r\n  PackStreamDigests[NumPackStreams]\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFolder\r\n~~~~~~\r\n  UINT64 NumCoders;\r\n  for (NumCoders)\r\n  {\r\n    BYTE \r\n    {\r\n      0:3 DecompressionMethod.IDSize\r\n      4:\r\n        0 - IsSimple\r\n        1 - Is not simple\r\n      5:\r\n        0 - No Attributes\r\n        1 - There Are Attributes\r\n      7:\r\n        0 - Last Method in Alternative_Method_List\r\n        1 - There are more alternative methods\r\n    } \r\n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\r\n    if (!IsSimple)\r\n    {\r\n      UINT64 NumInStreams;\r\n      UINT64 NumOutStreams;\r\n    }\r\n    if (DecompressionMethod[0] != 0)\r\n    {\r\n      UINT64 PropertiesSize\r\n      BYTE Properties[PropertiesSize]\r\n    }\r\n  }\r\n    \r\n  NumBindPairs = NumOutStreamsTotal - 1;\r\n\r\n  for (NumBindPairs)\r\n  {\r\n    UINT64 InIndex;\r\n    UINT64 OutIndex;\r\n  }\r\n\r\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r\n  if (NumPackedStreams > 1)\r\n    for(NumPackedStreams)\r\n    {\r\n      UINT64 Index;\r\n    };\r\n\r\n\r\n\r\n\r\nCoders Info\r\n~~~~~~~~~~~\r\n\r\n  BYTE NID::kUnPackInfo  (0x07)\r\n\r\n\r\n  BYTE NID::kFolder  (0x0B)\r\n  UINT64 NumFolders\r\n  BYTE External\r\n  switch(External)\r\n  {\r\n    case 0:\r\n      Folders[NumFolders]\r\n    case 1:\r\n      UINT64 DataStreamIndex\r\n  }\r\n\r\n\r\n  BYTE ID::kCodersUnPackSize  (0x0C)\r\n  for(Folders)\r\n    for(Folder.NumOutStreams)\r\n     UINT64 UnPackSize;\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC   (0x0A)\r\n  UnPackDigests[NumFolders]\r\n  []\r\n\r\n  \r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\n\r\nSubStreams Info\r\n~~~~~~~~~~~~~~\r\n  BYTE NID::kSubStreamsInfo; (0x08)\r\n\r\n  []\r\n  BYTE NID::kNumUnPackStream; (0x0D)\r\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kSize  (0x09)\r\n  UINT64 UnPackSizes[]\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC  (0x0A)\r\n  Digests[Number of streams with unknown CRC]\r\n  []\r\n\r\n  \r\n  BYTE NID::kEnd\r\n\r\n\r\nStreams Info\r\n~~~~~~~~~~~~\r\n\r\n  []\r\n  PackInfo\r\n  []\r\n\r\n\r\n  []\r\n  CodersInfo\r\n  []\r\n\r\n\r\n  []\r\n  SubStreamsInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFilesInfo\r\n~~~~~~~~~\r\n  BYTE NID::kFilesInfo;  (0x05)\r\n  UINT64 NumFiles\r\n\r\n  while(true)\r\n  {\r\n    BYTE PropertyType;\r\n    if (aType == 0)\r\n      break;\r\n\r\n    UINT64 Size;\r\n\r\n    switch(PropertyType)\r\n    {\r\n      kEmptyStream:   (0x0E)\r\n        for(NumFiles)\r\n          BIT IsEmptyStream\r\n\r\n      kEmptyFile:     (0x0F)\r\n        for(EmptyStreams)\r\n          BIT IsEmptyFile\r\n\r\n      kAnti:          (0x10)\r\n        for(EmptyStreams)\r\n          BIT IsAntiFile\r\n      \r\n      case kCreationTime:   (0x12)\r\n      case kLastAccessTime: (0x13)\r\n      case kLastWriteTime:  (0x14)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT TimeDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Items)\r\n          UINT32 Time\r\n        []\r\n      \r\n      kNames:     (0x11)\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Files)\r\n        {\r\n          wchar_t Names[NameSize];\r\n          wchar_t 0;\r\n        }\r\n        []\r\n\r\n      kAttributes:  (0x15)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT AttributesAreDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Attributes)\r\n          UINT32 Attributes\r\n        []\r\n    }\r\n  }\r\n\r\n\r\nHeader\r\n~~~~~~\r\n  BYTE NID::kHeader (0x01)\r\n\r\n  []\r\n  ArchiveProperties\r\n  []\r\n\r\n  []\r\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  BYTE NID::kMainStreamsInfo;    (0x04)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  FilesInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nHeaderInfo\r\n~~~~~~~~~~\r\n  []\r\n  BYTE NID::kEncodedHeader; (0x17)\r\n  StreamsInfo for Encoded Header\r\n  []\r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zAlloc.c",
    "content": "/* 7zAlloc.c */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n#endif\r\n\r\nvoid *SzAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zAlloc.h",
    "content": "/* 7zAlloc.h */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\nvoid *SzAlloc(size_t size);\r\nvoid SzFree(void *address);\r\n\r\nvoid *SzAllocTemp(size_t size);\r\nvoid SzFreeTemp(void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zBuffer.c",
    "content": "/* 7zBuffer.c */\r\n\r\n#include \"7zBuffer.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer)\r\n{\r\n  buffer->Capacity = 0;\r\n  buffer->Items = 0;\r\n}\r\n\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))\r\n{\r\n  buffer->Capacity = newCapacity;\r\n  if (newCapacity == 0)\r\n  {\r\n    buffer->Items = 0;\r\n    return 1;\r\n  }\r\n  buffer->Items = (Byte *)allocFunc(newCapacity);\r\n  return (buffer->Items != 0);\r\n}\r\n\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(buffer->Items);\r\n  buffer->Items = 0;\r\n  buffer->Capacity = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zBuffer.h",
    "content": "/* 7zBuffer.h */\r\n\r\n#ifndef __7Z_BUFFER_H\r\n#define __7Z_BUFFER_H\r\n\r\n#include <stddef.h>\r\n#include \"7zTypes.h\"\r\n\r\ntypedef struct _CSzByteBuffer\r\n{    \r\n\tsize_t Capacity;\r\n  Byte *Items;\r\n}CSzByteBuffer;\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer);\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zCrc.c",
    "content": "/* 7zCrc.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid InitCrcTable()\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      if (r & 1) \r\n        r = (r >> 1) ^ kCrcPoly;\r\n      else     \r\n        r >>= 1;\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nvoid CrcInit(UInt32 *crc) { *crc = 0xFFFFFFFF; }\r\nUInt32 CrcGetDigest(UInt32 *crc) { return *crc ^ 0xFFFFFFFF; } \r\n\r\nvoid CrcUpdateByte(UInt32 *crc, Byte b)\r\n{\r\n  *crc = g_CrcTable[((Byte)(*crc)) ^ b] ^ (*crc >> 8);\r\n}\r\n\r\nvoid CrcUpdateUInt16(UInt32 *crc, UInt16 v)\r\n{\r\n  CrcUpdateByte(crc, (Byte)v);\r\n  CrcUpdateByte(crc, (Byte)(v >> 8));\r\n}\r\n\r\nvoid CrcUpdateUInt32(UInt32 *crc, UInt32 v)\r\n{\r\n  int i;\r\n  for (i = 0; i < 4; i++)\r\n    CrcUpdateByte(crc, (Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CrcUpdateUInt64(UInt32 *crc, UInt64 v)\r\n{\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    CrcUpdateByte(crc, (Byte)(v));\r\n    v >>= 8;\r\n  }\r\n}\r\n\r\nvoid CrcUpdate(UInt32 *crc, const void *data, size_t size)\r\n{\r\n  UInt32 v = *crc;\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = g_CrcTable[((Byte)(v)) ^ *p] ^ (v >> 8);\r\n  *crc = v;\r\n}\r\n\r\nUInt32 CrcCalculateDigest(const void *data, size_t size)\r\n{\r\n  UInt32 crc;\r\n  CrcInit(&crc);\r\n  CrcUpdate(&crc, data, size);\r\n  return CrcGetDigest(&crc);\r\n}\r\n\r\nint CrcVerifyDigest(UInt32 digest, const void *data, size_t size)\r\n{\r\n  return (CrcCalculateDigest(data, size) == digest);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zCrc.h",
    "content": "/* 7zCrc.h */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"7zTypes.h\"\r\n\r\nextern UInt32 g_CrcTable[256];\r\nvoid InitCrcTable();\r\n\r\nvoid CrcInit(UInt32 *crc);\r\nUInt32 CrcGetDigest(UInt32 *crc);\r\nvoid CrcUpdateByte(UInt32 *crc, Byte v);\r\nvoid CrcUpdateUInt16(UInt32 *crc, UInt16 v);\r\nvoid CrcUpdateUInt32(UInt32 *crc, UInt32 v);\r\nvoid CrcUpdateUInt64(UInt32 *crc, UInt64 v);\r\nvoid CrcUpdate(UInt32 *crc, const void *data, size_t size);\r\n \r\nUInt32 CrcCalculateDigest(const void *data, size_t size);\r\nint CrcVerifyDigest(UInt32 digest, const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zDecode.c",
    "content": "/* 7zDecode.c */\r\n\r\n#include \"7zDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#else\r\n#include \"../../Compress/LZMA_C/LzmaDecode.h\"\r\n#endif\r\n\r\nCMethodID k_Copy = { { 0x0 }, 1 };\r\nCMethodID k_LZMA = { { 0x3, 0x1, 0x1 }, 3 };\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\ntypedef struct _CLzmaInCallbackImp\r\n{\r\n  ILzmaInCallback InCallback;\r\n  ISzInStream *InStream;\r\n  size_t Size;\r\n} CLzmaInCallbackImp;\r\n\r\nint LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object;\r\n  size_t processedSize;\r\n  SZ_RESULT res;\r\n  *size = 0;\r\n  res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, cb->Size, &processedSize);\r\n  *size = (SizeT)processedSize;\r\n  if (processedSize > cb->Size)\r\n    return (int)SZE_FAIL;\r\n  cb->Size -= processedSize;\r\n  if (res == SZ_OK)\r\n    return 0;\r\n  return (int)res;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, \r\n    size_t *outSizeProcessed, ISzAlloc *allocMain)\r\n{\r\n  UInt32 si;\r\n  size_t inSize = 0;\r\n  CCoderInfo *coder;\r\n  if (folder->NumPackStreams != 1)\r\n    return SZE_NOTIMPL;\r\n  if (folder->NumCoders != 1)\r\n    return SZE_NOTIMPL;\r\n  coder = folder->Coders;\r\n  *outSizeProcessed = 0;\r\n\r\n  for (si = 0; si < folder->NumPackStreams; si++)\r\n    inSize += (size_t)packSizes[si];\r\n\r\n  if (AreMethodsEqual(&coder->MethodID, &k_Copy))\r\n  {\r\n    size_t i;\r\n    if (inSize != outSize)\r\n      return SZE_DATA_ERROR;\r\n    #ifdef _LZMA_IN_CB\r\n    for (i = 0; i < inSize;)\r\n    {\r\n      size_t j;\r\n      Byte *inBuffer;\r\n      size_t bufferSize;\r\n      RINOK(inStream->Read((void *)inStream,  (void **)&inBuffer, inSize - i, &bufferSize));\r\n      if (bufferSize == 0)\r\n        return SZE_DATA_ERROR;\r\n      if (bufferSize > inSize - i)\r\n        return SZE_FAIL;\r\n      *outSizeProcessed += bufferSize;\r\n      for (j = 0; j < bufferSize && i < inSize; j++, i++)\r\n        outBuffer[i] = inBuffer[j];\r\n    }\r\n    #else\r\n    for (i = 0; i < inSize; i++)\r\n      outBuffer[i] = inBuffer[i];\r\n    *outSizeProcessed = inSize;\r\n    #endif\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (AreMethodsEqual(&coder->MethodID, &k_LZMA))\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    CLzmaInCallbackImp lzmaCallback;\r\n    #else\r\n    SizeT inProcessed;\r\n    #endif\r\n\r\n    CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n    int result;\r\n    SizeT outSizeProcessedLoc;\r\n\r\n    #ifdef _LZMA_IN_CB\r\n    lzmaCallback.Size = inSize;\r\n    lzmaCallback.InStream = inStream;\r\n    lzmaCallback.InCallback.Read = LzmaReadImp;\r\n    #endif\r\n\r\n    if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, \r\n        coder->Properties.Capacity) != LZMA_RESULT_OK)\r\n      return SZE_FAIL;\r\n\r\n    state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n    if (state.Probs == 0)\r\n      return SZE_OUTOFMEMORY;\r\n\r\n    #ifdef _LZMA_OUT_READ\r\n    if (state.Properties.DictionarySize == 0)\r\n      state.Dictionary = 0;\r\n    else\r\n    {\r\n      state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize);\r\n      if (state.Dictionary == 0)\r\n      {\r\n        allocMain->Free(state.Probs);\r\n        return SZE_OUTOFMEMORY;\r\n      }\r\n    }\r\n    LzmaDecoderInit(&state);\r\n    #endif\r\n\r\n    result = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &lzmaCallback.InCallback,\r\n        #else\r\n        inBuffer, (SizeT)inSize, &inProcessed,\r\n        #endif\r\n        outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n    *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n    allocMain->Free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    allocMain->Free(state.Dictionary);\r\n    #endif\r\n    if (result == LZMA_RESULT_DATA_ERROR)\r\n      return SZE_DATA_ERROR;\r\n    if (result != LZMA_RESULT_OK)\r\n      return SZE_FAIL;\r\n    return SZ_OK;\r\n  }\r\n  return SZE_NOTIMPL;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zDecode.h",
    "content": "/* 7zDecode.h */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n#ifdef _LZMA_IN_CB\r\n#include \"7zIn.h\"\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *stream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, \r\n    size_t *outSizeProcessed, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zExtract.c",
    "content": "/* 7zExtract.c */\r\n\r\n#include \"7zExtract.h\"\r\n#include \"7zDecode.h\"\r\n#include \"7zCrc.h\"\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer, \r\n    size_t *outBufferSize,\r\n    size_t *offset, \r\n    size_t *outSizeProcessed, \r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];\r\n  SZ_RESULT res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    allocMain->Free(*outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CFolder *folder = db->Database.Folders + folderIndex;\r\n    CFileSize unPackSize = SzFolderGetUnPackSize(folder);\r\n    #ifndef _LZMA_IN_CB\r\n    CFileSize packSize = SzArDbGetFolderFullPackSize(db, folderIndex);\r\n    Byte *inBuffer = 0;\r\n    size_t processedSize;\r\n    #endif\r\n    *blockIndex = folderIndex;\r\n    allocMain->Free(*outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(inStream->Seek(inStream, SzArDbGetFolderStreamPos(db, folderIndex, 0)));\r\n    \r\n    #ifndef _LZMA_IN_CB\r\n    if (packSize != 0)\r\n    {\r\n      inBuffer = (Byte *)allocTemp->Alloc((size_t)packSize);\r\n      if (inBuffer == 0)\r\n        return SZE_OUTOFMEMORY;\r\n    }\r\n    res = inStream->Read(inStream, inBuffer, (size_t)packSize, &processedSize);\r\n    if (res == SZ_OK && processedSize != (size_t)packSize)\r\n      res = SZE_FAIL;\r\n    #endif\r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = (size_t)unPackSize;\r\n      if (unPackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)allocMain->Alloc((size_t)unPackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZE_OUTOFMEMORY;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        size_t outRealSize;\r\n        res = SzDecode(db->Database.PackSizes + \r\n          db->FolderStartPackStreamIndex[folderIndex], folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream,\r\n          #else\r\n          inBuffer, \r\n          #endif\r\n          *outBuffer, (size_t)unPackSize, &outRealSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (outRealSize == (size_t)unPackSize)\r\n          {\r\n            if (folder->UnPackCRCDefined)\r\n            {\r\n              if (!CrcVerifyDigest(folder->UnPackCRC, *outBuffer, (size_t)unPackSize))\r\n                res = SZE_FAIL;\r\n            }\r\n          }\r\n          else\r\n            res = SZE_FAIL;\r\n        }\r\n      }\r\n    }\r\n    #ifndef _LZMA_IN_CB\r\n    allocTemp->Free(inBuffer);\r\n    #endif\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i; \r\n    CFileItem *fileItem = db->Database.Files + fileIndex;\r\n    *offset = 0;\r\n    for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)db->Database.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZE_FAIL;\r\n    {\r\n      if (fileItem->IsFileCRCDefined)\r\n      {\r\n        if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer + *offset, *outSizeProcessed))\r\n          res = SZE_FAIL;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zExtract.h",
    "content": "/* 7zExtract.h */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive. \r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send \r\n    these values from previous call:\r\n      *blockIndex, \r\n      *outBuffer, \r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid, \r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables \r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zHeader.c",
    "content": "/*  7zHeader.c */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zHeader.h",
    "content": "/* 7zHeader.h */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"7zTypes.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnPackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnPackSize,\r\n  k7zIdNumUnPackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCreationTime,\r\n  k7zIdLastAccessTime,\r\n  k7zIdLastWriteTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zIn.c",
    "content": "/* 7zIn.c */\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zCrc.h\"\r\n#include \"7zDecode.h\"\r\n\r\n#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db)\r\n{\r\n  SzArchiveDatabaseInit(&db->Database);\r\n  db->FolderStartPackStreamIndex = 0;\r\n  db->PackStreamStartPositions = 0;\r\n  db->FolderStartFileIndex = 0;\r\n  db->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(db->FolderStartPackStreamIndex);\r\n  freeFunc(db->PackStreamStartPositions);\r\n  freeFunc(db->FolderStartFileIndex);\r\n  freeFunc(db->FileIndexToFolderIndexMap);\r\n  SzArchiveDatabaseFree(&db->Database, freeFunc);\r\n  SzArDbExInit(db);\r\n}\r\n\r\n/*\r\nCFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nCFileSize GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n\r\nSZ_RESULT MySzInAlloc(void **p, size_t size, void * (*allocFunc)(size_t size))\r\n{\r\n  if (size == 0)\r\n    *p = 0;\r\n  else\r\n  {\r\n    *p = allocFunc(size);\r\n    RINOM(*p);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 startPos = 0;\r\n  CFileSize startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  RINOK(MySzInAlloc((void **)&db->FolderStartPackStreamIndex, db->Database.NumFolders * sizeof(UInt32), allocFunc));\r\n  for(i = 0; i < db->Database.NumFolders; i++)\r\n  {\r\n    db->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += db->Database.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  RINOK(MySzInAlloc((void **)&db->PackStreamStartPositions, db->Database.NumPackStreams * sizeof(CFileSize), allocFunc));\r\n\r\n  for(i = 0; i < db->Database.NumPackStreams; i++)\r\n  {\r\n    db->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += db->Database.PackSizes[i];\r\n  }\r\n\r\n  RINOK(MySzInAlloc((void **)&db->FolderStartFileIndex, db->Database.NumFolders * sizeof(UInt32), allocFunc));\r\n  RINOK(MySzInAlloc((void **)&db->FileIndexToFolderIndexMap, db->Database.NumFiles * sizeof(UInt32), allocFunc));\r\n\r\n  for (i = 0; i < db->Database.NumFiles; i++)\r\n  {\r\n    CFileItem *file = db->Database.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      db->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      while(1)\r\n      {\r\n        if (folderIndex >= db->Database.NumFolders)\r\n          return SZE_ARCHIVE_ERROR;\r\n        db->FolderStartFileIndex[folderIndex] = i;\r\n        if (db->Database.Folders[folderIndex].NumUnPackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    db->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return db->ArchiveInfo.DataStartPosition + \r\n    db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nCFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex)\r\n{\r\n  UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n  CFolder *folder = db->Database.Folders + folderIndex;\r\n  CFileSize size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n    size += db->Database.PackSizes[packStreamIndex + i];\r\n  return size;\r\n}\r\n\r\n\r\n/*\r\nSZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case k7zIdLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case k7zIdLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nSZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  while (size > 0)\r\n  {\r\n    Byte *inBuffer;\r\n    size_t processedSize;\r\n    RINOK(inStream->Read(inStream, (void **)&inBuffer, size, &processedSize));\r\n    if (processedSize == 0 || processedSize > size)\r\n      return SZE_FAIL;\r\n    size -= processedSize;\r\n    do\r\n    {\r\n      *data++ = *inBuffer++;\r\n    }\r\n    while (--processedSize != 0);\r\n  }\r\n  #else\r\n  size_t processedSize;\r\n  RINOK(inStream->Read(inStream, data, size, &processedSize));\r\n  if (processedSize != size)\r\n    return SZE_FAIL;\r\n  #endif\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data)\r\n{\r\n  return SafeReadDirect(inStream, data, 1);\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nint TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nSZ_RESULT SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  *value = (CFileSize)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZE_NOTIMPL;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZE_NOTIMPL;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadID(CSzData *sd, UInt64 *value) \r\n{ \r\n  return SzReadNumber(sd, value); \r\n}\r\n\r\nSZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nSZ_RESULT SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZE_ARCHIVE_ERROR;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  RINOK(MySzInAlloc((void **)v, numItems * sizeof(Byte), allocFunc));\r\n  for(i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, allocFunc);\r\n  RINOK(MySzInAlloc((void **)v, numItems * sizeof(Byte), allocFunc));\r\n  for(i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHashDigests(\r\n    CSzData *sd, \r\n    size_t numItems,\r\n    Byte **digestsDefined, \r\n    UInt32 **digests, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc));\r\n  RINOK(MySzInAlloc((void **)digests, numItems * sizeof(UInt32), allocFunc));\r\n  for(i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadPackInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    CFileSize **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadSize(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  RINOK(MySzInAlloc((void **)packSizes, (size_t)*numPackStreams * sizeof(CFileSize), allocFunc));\r\n\r\n  for(i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadSize(sd, (*packSizes) + i));\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc)); \r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    RINOK(MySzInAlloc((void **)packCRCsDefined, (size_t)*numPackStreams * sizeof(Byte), allocFunc));\r\n    RINOK(MySzInAlloc((void **)packCRCs, (size_t)*numPackStreams * sizeof(UInt32), allocFunc));\r\n    for(i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR;\r\n}\r\n\r\nSZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 numCoders;\r\n  UInt32 numBindPairs;\r\n  UInt32 numPackedStreams;\r\n  UInt32 i;\r\n  UInt32 numInStreams = 0;\r\n  UInt32 numOutStreams = 0;\r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  folder->NumCoders = numCoders;\r\n\r\n  RINOK(MySzInAlloc((void **)&folder->Coders, (size_t)numCoders * sizeof(CCoderInfo), allocFunc));\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfoInit(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      coder->MethodID.IDSize = (Byte)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, coder->MethodID.ID, coder->MethodID.IDSize));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc))\r\n          return SZE_OUTOFMEMORY;\r\n        RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += (UInt32)coder->NumInStreams;\r\n    numOutStreams += (UInt32)coder->NumOutStreams;\r\n  }\r\n\r\n  numBindPairs = numOutStreams - 1;\r\n  folder->NumBindPairs = numBindPairs;\r\n\r\n\r\n  RINOK(MySzInAlloc((void **)&folder->BindPairs, (size_t)numBindPairs * sizeof(CBindPair), allocFunc));\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bindPair = folder->BindPairs + i;;\r\n    RINOK(SzReadNumber32(sd, &bindPair->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bindPair->OutIndex)); \r\n  }\r\n\r\n  numPackedStreams = numInStreams - (UInt32)numBindPairs;\r\n\r\n  folder->NumPackStreams = numPackedStreams;\r\n  RINOK(MySzInAlloc((void **)&folder->PackStreams, (size_t)numPackedStreams * sizeof(UInt32), allocFunc));\r\n\r\n  if (numPackedStreams == 1)\r\n  {\r\n    UInt32 j;\r\n    UInt32 pi = 0;\r\n    for (j = 0; j < numInStreams; j++)\r\n      if (SzFolderFindBindPairForInStream(folder, j) < 0)\r\n      {\r\n        folder->PackStreams[pi++] = j;\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUnPackInfo(\r\n    CSzData *sd, \r\n    UInt32 *numFolders,\r\n    CFolder **folders,  /* for allocFunc */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n\r\n    RINOK(MySzInAlloc((void **)folders, (size_t)*numFolders * sizeof(CFolder), allocFunc));\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n      SzFolderInit((*folders) + i);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));\r\n\r\n  for(i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolderGetNumOutStreams(folder);\r\n\r\n    RINOK(MySzInAlloc((void **)&folder->UnPackSizes, (size_t)numOutStreams * sizeof(CFileSize), allocFunc));\r\n\r\n    for(j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadSize(sd, folder->UnPackSizes + j));\r\n    }\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SZ_RESULT res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc); \r\n      if (res == SZ_OK)\r\n      {\r\n        for(i = 0; i < *numFolders; i++)\r\n        {\r\n          CFolder *folder = (*folders) + i;\r\n          folder->UnPackCRCDefined = crcsDefined[i];\r\n          folder->UnPackCRC = crcs[i];\r\n        }\r\n      }\r\n      allocTemp->Free(crcs);\r\n      allocTemp->Free(crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadSubStreamsInfo(\r\n    CSzData *sd, \r\n    UInt32 numFolders,\r\n    CFolder *folders,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n    folders[i].NumUnPackStreams = 1;\r\n  *numUnPackStreams = numFolders;\r\n\r\n  while(1)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnPackStream)\r\n    {\r\n      *numUnPackStreams = 0;\r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnPackStreams = numStreams;\r\n        *numUnPackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnPackStreams == 0)\r\n  {\r\n    *unPackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize));\r\n    RINOM(*unPackSizes);\r\n    *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    CFileSize sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      CFileSize size;\r\n      RINOK(SzReadSize(sd, &size));\r\n      (*unPackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for(i = 0; i < *numUnPackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  while(1)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0; \r\n      UInt32 *digests2 = 0;\r\n      SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnPackStreams;\r\n          if (numSubstreams == 1 && folder->UnPackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnPackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      allocTemp->Free(digestsDefined2);\r\n      allocTemp->Free(digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nSZ_RESULT SzReadStreamsInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    CArchiveDatabase *db,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZE_FAIL;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams, \r\n            &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc));\r\n        break;\r\n      }\r\n      case k7zIdUnPackInfo:\r\n      {\r\n        RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders, \r\n            numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZE_FAIL;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nSZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CFileItem *file = files + i;\r\n    while(pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZE_ARCHIVE_ERROR;\r\n        if (pos + 2 > sd->Size)\r\n          return SZE_ARCHIVE_ERROR;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZE_ARCHIVE_ERROR;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    RINOK(MySzInAlloc((void **)&file->Name, (size_t)len * sizeof(char), allocFunc));\r\n\r\n    len = 0;\r\n    while(2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while(numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHeader2(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db,   /* allocMain */\r\n    CFileSize **unPackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnPackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &db->ArchiveInfo.DataStartPosition,\r\n        &db->Database, \r\n        &numUnPackStreams,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests, allocMain->Alloc, allocTemp));\r\n    db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZE_ARCHIVE_ERROR;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  db->Database.NumFiles = numFiles;\r\n\r\n  RINOK(MySzInAlloc((void **)&files, (size_t)numFiles * sizeof(CFileItem), allocMain->Alloc));\r\n\r\n  db->Database.Files = files;\r\n  for(i = 0; i < numFiles; i++)\r\n    SzFileInit(files + i);\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc));\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for(i = 0; i < numFiles; i++)\r\n    {\r\n      CFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if(file->HasStream)\r\n      {\r\n        file->IsDirectory = 0;\r\n        file->Size = (*unPackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->IsFileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDirectory = 1;\r\n        else\r\n          file->IsDirectory = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->IsFileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArDbExFill(db, allocMain->Alloc);\r\n}\r\n\r\nSZ_RESULT SzReadHeader(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db, \r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  SZ_RESULT res = SzReadHeader2(sd, db, \r\n      &unPackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector,\r\n      allocMain, allocTemp);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  allocTemp->Free(emptyStreamVector);\r\n  allocTemp->Free(emptyFileVector);\r\n  return res;\r\n} \r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams2(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    CArchiveDatabase *db,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    #ifndef _LZMA_IN_CB\r\n    Byte **inBuffer,\r\n    #endif\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnPackStreams = 0;\r\n  CFileSize dataStartPos;\r\n  CFolder *folder;\r\n  #ifndef _LZMA_IN_CB\r\n  CFileSize packSize = 0;\r\n  UInt32 i = 0;\r\n  #endif\r\n  CFileSize unPackSize;\r\n  size_t outRealSize;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, db,\r\n      &numUnPackStreams,  unPackSizes, digestsDefined, digests, \r\n      allocTemp->Alloc, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (db->NumFolders != 1)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  folder = db->Folders;\r\n  unPackSize = SzFolderGetUnPackSize(folder);\r\n  \r\n  RINOK(inStream->Seek(inStream, dataStartPos));\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  for (i = 0; i < db->NumPackStreams; i++)\r\n    packSize += db->PackSizes[i];\r\n\r\n  RINOK(MySzInAlloc((void **)inBuffer, (size_t)packSize, allocTemp->Alloc));\r\n\r\n  RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize));\r\n  #endif\r\n\r\n  if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  res = SzDecode(db->PackSizes, folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream,\r\n          #else\r\n          *inBuffer, \r\n          #endif\r\n          outBuffer->Items, (size_t)unPackSize,\r\n          &outRealSize, allocTemp);\r\n  RINOK(res)\r\n  if (outRealSize != (UInt32)unPackSize)\r\n    return SZE_FAIL;\r\n  if (folder->UnPackCRCDefined)\r\n    if (!CrcVerifyDigest(folder->UnPackCRC, outBuffer->Items, (size_t)unPackSize))\r\n      return SZE_FAIL;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CArchiveDatabase db;\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  #ifndef _LZMA_IN_CB\r\n  Byte *inBuffer = 0;\r\n  #endif\r\n  SZ_RESULT res;\r\n  SzArchiveDatabaseInit(&db);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset, \r\n    &db, &unPackSizes, &digestsDefined, &digests, \r\n    #ifndef _LZMA_IN_CB\r\n    &inBuffer,\r\n    #endif\r\n    allocTemp);\r\n  SzArchiveDatabaseFree(&db, allocTemp->Free);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  #ifndef _LZMA_IN_CB\r\n  allocTemp->Free(inBuffer);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen2(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte signature[k7zSignatureSize];\r\n  Byte version;\r\n  UInt32 crcFromArchive;\r\n  UInt64 nextHeaderOffset;\r\n  UInt64 nextHeaderSize;\r\n  UInt32 nextHeaderCRC;\r\n  UInt32 crc;\r\n  CFileSize pos = 0;\r\n  CSzByteBuffer buffer;\r\n  CSzData sd;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize));\r\n\r\n  if (!TestSignatureCandidate(signature))\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  /*\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n  */\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n  if (version != k7zMajorVersion)\r\n    return SZE_ARCHIVE_ERROR;\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n\r\n  RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive));\r\n\r\n  CrcInit(&crc);\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset));\r\n  CrcUpdateUInt64(&crc, nextHeaderOffset);\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize));\r\n  CrcUpdateUInt64(&crc, nextHeaderSize);\r\n  RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC));\r\n  CrcUpdateUInt32(&crc, nextHeaderCRC);\r\n\r\n  pos = k7zStartHeaderSize;\r\n  db->ArchiveInfo.StartPositionAfterHeader = pos;\r\n  \r\n  if (CrcGetDigest(&crc) != crcFromArchive)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  if (nextHeaderSize == 0)\r\n    return SZ_OK;\r\n\r\n  RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset)));\r\n\r\n  if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize);\r\n  if (res == SZ_OK)\r\n  {\r\n    if (CrcVerifyDigest(nextHeaderCRC, buffer.Items, (UInt32)nextHeaderSize))\r\n    {\r\n      while (1)\r\n      {\r\n        UInt64 type;\r\n        sd.Data = buffer.Items;\r\n        sd.Size = buffer.Capacity;\r\n        res = SzReadID(&sd, &type);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (type == k7zIdHeader)\r\n        {\r\n          res = SzReadHeader(&sd, db, allocMain, allocTemp);\r\n          break;\r\n        }\r\n        if (type != k7zIdEncodedHeader)\r\n        {\r\n          res = SZE_ARCHIVE_ERROR;\r\n          break;\r\n        }\r\n        {\r\n          CSzByteBuffer outBuffer;\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, \r\n              db->ArchiveInfo.StartPositionAfterHeader, \r\n              allocTemp);\r\n          if (res != SZ_OK)\r\n          {\r\n            SzByteBufferFree(&outBuffer, allocTemp->Free);\r\n            break;\r\n          }\r\n          SzByteBufferFree(&buffer, allocTemp->Free);\r\n          buffer.Items = outBuffer.Items;\r\n          buffer.Capacity = outBuffer.Capacity;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  SzByteBufferFree(&buffer, allocTemp->Free);\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArDbExFree(db, allocMain->Free);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zIn.h",
    "content": "/* 7zIn.h */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n \r\ntypedef struct _CInArchiveInfo\r\n{\r\n  CFileSize StartPositionAfterHeader; \r\n  CFileSize DataStartPosition;\r\n}CInArchiveInfo;\r\n\r\ntypedef struct _CArchiveDatabaseEx\r\n{\r\n  CArchiveDatabase Database;\r\n  CInArchiveInfo ArchiveInfo;\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  CFileSize *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n}CArchiveDatabaseEx;\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db);\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);\r\nCFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex);\r\n\r\ntypedef struct _ISzInStream\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  SZ_RESULT (*Read)(\r\n      void *object,           /* pointer to ISzInStream itself */\r\n      void **buffer,          /* out: pointer to buffer with data */\r\n      size_t maxRequiredSize, /* max required size to read */\r\n      size_t *processedSize); /* real processed size. \r\n                                 processedSize can be less than maxRequiredSize.\r\n                                 If processedSize == 0, then there are no more \r\n                                 bytes in stream. */\r\n  #else\r\n  SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);\r\n  #endif\r\n  SZ_RESULT (*Seek)(void *object, CFileSize pos);\r\n} ISzInStream;\r\n\r\n \r\nint SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zItem.c",
    "content": "/* 7zItem.c */\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder)\r\n{\r\n  SzByteBufferInit(&coder->Properties);\r\n}\r\n\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))\r\n{\r\n  SzByteBufferFree(&coder->Properties, freeFunc);\r\n  SzCoderInfoInit(coder);\r\n}\r\n\r\nvoid SzFolderInit(CFolder *folder)\r\n{\r\n  folder->NumCoders = 0;\r\n  folder->Coders = 0;\r\n  folder->NumBindPairs = 0;\r\n  folder->BindPairs = 0;\r\n  folder->NumPackStreams = 0;\r\n  folder->PackStreams = 0;\r\n  folder->UnPackSizes = 0;\r\n  folder->UnPackCRCDefined = 0;\r\n  folder->UnPackCRC = 0;\r\n  folder->NumUnPackStreams = 0;\r\n}\r\n\r\nvoid SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    SzCoderInfoFree(&folder->Coders[i], freeFunc);\r\n  freeFunc(folder->Coders);\r\n  freeFunc(folder->BindPairs);\r\n  freeFunc(folder->PackStreams);\r\n  freeFunc(folder->UnPackSizes);\r\n  SzFolderInit(folder);\r\n}\r\n\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    result += folder->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder)\r\n{ \r\n  int i = (int)SzFolderGetNumOutStreams(folder);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolderFindBindPairForOutStream(folder, i) < 0)\r\n      return folder->UnPackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\n/*\r\nint FindPackStreamArrayIndex(int inStreamIndex) const\r\n{\r\n  for(int i = 0; i < PackStreams.Size(); i++)\r\n  if (PackStreams[i] == inStreamIndex)\r\n    return i;\r\n  return -1;\r\n}\r\n*/\r\n\r\nvoid SzFileInit(CFileItem *fileItem)\r\n{\r\n  fileItem->IsFileCRCDefined = 0;\r\n  fileItem->HasStream = 1;\r\n  fileItem->IsDirectory = 0;\r\n  fileItem->IsAnti = 0;\r\n  fileItem->Name = 0;\r\n}\r\n\r\nvoid SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))\r\n{\r\n  freeFunc(fileItem->Name);\r\n  SzFileInit(fileItem);\r\n}\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db)\r\n{\r\n  db->NumPackStreams = 0;\r\n  db->PackSizes = 0;\r\n  db->PackCRCsDefined = 0;\r\n  db->PackCRCs = 0;\r\n  db->NumFolders = 0;\r\n  db->Folders = 0;\r\n  db->NumFiles = 0;\r\n  db->Files = 0;\r\n}\r\n\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < db->NumFolders; i++)\r\n    SzFolderFree(&db->Folders[i], freeFunc);\r\n  for (i = 0; i < db->NumFiles; i++)\r\n    SzFileFree(&db->Files[i], freeFunc);\r\n  freeFunc(db->PackSizes);\r\n  freeFunc(db->PackCRCsDefined);\r\n  freeFunc(db->PackCRCs);\r\n  freeFunc(db->Folders);\r\n  freeFunc(db->Files);\r\n  SzArchiveDatabaseInit(db);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zItem.h",
    "content": "/* 7zItem.h */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"7zMethodID.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zBuffer.h\"\r\n\r\ntypedef struct _CCoderInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  CMethodID MethodID;\r\n  CSzByteBuffer Properties;\r\n}CCoderInfo;\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder);\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));\r\n\r\ntypedef struct _CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n}CBindPair;\r\n\r\ntypedef struct _CFolder\r\n{\r\n  UInt32 NumCoders;\r\n  CCoderInfo *Coders;\r\n  UInt32 NumBindPairs;\r\n  CBindPair *BindPairs;\r\n  UInt32 NumPackStreams; \r\n  UInt32 *PackStreams;\r\n  CFileSize *UnPackSizes;\r\n  int UnPackCRCDefined;\r\n  UInt32 UnPackCRC;\r\n\r\n  UInt32 NumUnPackStreams;\r\n}CFolder;\r\n\r\nvoid SzFolderInit(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\n\r\n/* #define CArchiveFileTime UInt64 */\r\n\r\ntypedef struct _CFileItem\r\n{\r\n  /*\r\n  CArchiveFileTime LastWriteTime;\r\n  CFileSize StartPos;\r\n  UInt32 Attributes; \r\n  */\r\n  CFileSize Size;\r\n  UInt32 FileCRC;\r\n  char *Name;\r\n\r\n  Byte IsFileCRCDefined;\r\n  Byte HasStream;\r\n  Byte IsDirectory;\r\n  Byte IsAnti;\r\n  /*\r\n  int AreAttributesDefined;\r\n  int IsLastWriteTimeDefined;\r\n  int IsStartPosDefined;\r\n  */\r\n}CFileItem;\r\n\r\nvoid SzFileInit(CFileItem *fileItem);\r\n\r\ntypedef struct _CArchiveDatabase\r\n{\r\n  UInt32 NumPackStreams;\r\n  CFileSize *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  UInt32 NumFolders;\r\n  CFolder *Folders;\r\n  UInt32 NumFiles;\r\n  CFileItem *Files;\r\n}CArchiveDatabase;\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db);\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));\r\n\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zMain.c",
    "content": "/* \r\n7zMain.c\r\nTest application for 7z Decoder\r\nLZMA SDK 4.26 Copyright (c) 1999-2005 Igor Pavlov (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"7zCrc.h\"\r\n#include \"7zIn.h\"\r\n#include \"7zExtract.h\"\r\n\r\ntypedef struct _CFileInStream\r\n{\r\n  ISzInStream InStream;\r\n  FILE *File;\r\n} CFileInStream;\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define kBufferSize (1 << 12)\r\nByte g_Buffer[kBufferSize];\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc;\r\n  if (maxRequiredSize > kBufferSize)\r\n    maxRequiredSize = kBufferSize;\r\n  processedSizeLoc = fread(g_Buffer, 1, maxRequiredSize, s->File);\r\n  *buffer = g_Buffer;\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#else\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc = fread(buffer, 1, size, s->File);\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzFileSeekImp(void *object, CFileSize pos)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  int res = fseek(s->File, (long)pos, SEEK_SET);\r\n  if (res == 0)\r\n    return SZ_OK;\r\n  return SZE_FAIL;\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CArchiveDatabaseEx db;\r\n  SZ_RESULT res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder 4.30  Copyright (c) 1999-2005 Igor Pavlov  2005-11-20\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.File = fopen(args[2], \"rb\");\r\n  if (archiveStream.File == 0)\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.InStream.Read = SzFileReadImp;\r\n  archiveStream.InStream.Seek = SzFileSeekImp;\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  InitCrcTable();\r\n  SzArDbExInit(&db);\r\n  res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0;\r\n    int testCommand = 0;\r\n    int extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0)\r\n      listCommand = 1;\r\n    if (strcmp(command, \"t\") == 0)\r\n      testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0)\r\n      extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      // if you need cache, use these 3 variables.\r\n      // if you use external function, you can make these variable as static.\r\n      UInt32 blockIndex = 0xFFFFFFFF; // it can have any value before first call (if outBuffer = 0) \r\n      Byte *outBuffer = 0; // it must be 0 before first call for each new archive. \r\n      size_t outBufferSize = 0;  // it can have any value before first call (if outBuffer = 0) \r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CFileItem *f = db.Database.Files + i;\r\n        if (f->IsDirectory)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ? \r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDirectory)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzExtract(&archiveStream.InStream, &db, i, \r\n            &blockIndex, &outBuffer, &outBufferSize, \r\n            &offset, &outSizeProcessed, \r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          FILE *outputHandle;\r\n          UInt32 processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          outputHandle = fopen(fileName, \"wb+\");\r\n          if (outputHandle == 0)\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          processedSize = fwrite(outBuffer + offset, 1, outSizeProcessed, outputHandle);\r\n          if (processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          if (fclose(outputHandle))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      allocImp.Free(outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZE_FAIL;\r\n    }\r\n  }\r\n  SzArDbExFree(&db, allocImp.Free);\r\n\r\n  fclose(archiveStream.File);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == SZE_OUTOFMEMORY)\r\n    PrintError(\"can not allocate memory\");\r\n  else     \r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zMethodID.c",
    "content": "/* 7zMethodID.c */\r\n\r\n#include \"7zMethodID.h\"\r\n\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2)\r\n{\r\n  int i;\r\n  if (a1->IDSize != a2->IDSize)\r\n    return 0;\r\n  for (i = 0; i < a1->IDSize; i++)\r\n    if (a1->ID[i] != a2->ID[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zMethodID.h",
    "content": "/* 7zMethodID.h */\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"7zTypes.h\"\r\n\r\n#define kMethodIDSize 15\r\n  \r\ntypedef struct _CMethodID\r\n{\r\n  Byte ID[kMethodIDSize];\r\n  Byte IDSize;\r\n} CMethodID;\r\n\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7zTypes.h",
    "content": "/* 7zTypes.h */\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\n#ifndef UInt32\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\n#define UInt32 unsigned long\r\n#else\r\n#define UInt32 unsigned int\r\n#endif\r\n#endif\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#ifndef UInt16\r\n#define UInt16 unsigned short\r\n#endif\r\n\r\n/* #define _SZ_NO_INT_64 */\r\n/* define it your compiler doesn't support long long int */\r\n\r\n#ifdef _SZ_NO_INT_64\r\n#define UInt64 unsigned long\r\n#else\r\n#ifdef _MSC_VER\r\n#define UInt64 unsigned __int64\r\n#else\r\n#define UInt64 unsigned long long int\r\n#endif\r\n#endif\r\n\r\n\r\n/* #define _SZ_FILE_SIZE_64 */\r\n/* Use _SZ_FILE_SIZE_64 if you need support for files larger than 4 GB*/\r\n\r\n#ifndef CFileSize\r\n#ifdef _SZ_FILE_SIZE_64\r\n#define CFileSize UInt64\r\n#else\r\n#define CFileSize UInt32\r\n#endif\r\n#endif\r\n\r\n#define SZ_RESULT int\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_CRC_ERROR (3)\r\n\r\n#define SZE_NOTIMPL (4)\r\n#define SZE_FAIL (5)\r\n\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7z_C.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z_C\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z_C - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\" CFG=\"7z_C - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z_C - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z_C - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z_C - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /W4 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z_C - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z_C - Win32 Release\"\r\n# Name \"7z_C - Win32 Debug\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_C\\LzmaDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_C\\LzmaDecode.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zTypes.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/7z_C.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z_C\"=.\\7z_C.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/makefile",
    "content": "PROG = 7zDec.exe\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zBuffer.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n  $O\\7zMethodID.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $O\\LzmaDecode.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/LZMA_C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Archive/7z_C/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o \r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuffer.o: 7zBuffer.c\r\n\t$(CXX) $(CFLAGS) 7zBuffer.c\r\n\r\n7zCrc.o: 7zCrc.c\r\n\t$(CXX) $(CFLAGS) 7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\n7zMethodID.o: 7zMethodID.c\r\n\t$(CXX) $(CFLAGS) 7zMethodID.c\r\n\r\nLzmaDecode.o: ../../Compress/LZMA_C/LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/LZMA_C/LzmaDecode.c\r\n\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  // return result ? S_OK: E_FAIL;\r\n  #ifdef _WIN32\r\n  return result ? S_OK: (::GetLastError());\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), \r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef _WIN32\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nbool COutFileStream::Create(LPCTSTR fileName, bool createAlways)\r\n{\r\n  return File.Create(fileName, createAlways);\r\n}\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool COutFileStream::Create(LPCWSTR fileName, bool createAlways)\r\n{\r\n  return File.Create(fileName, createAlways);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef _WIN32\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15); \r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), \r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef _WIN32\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef _WIN32\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n  #endif\r\n  \r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\n#include \"../../Common/Alloc.h\"\r\n\r\nCInBuffer::CInBuffer(): \r\n  _buffer(0), \r\n  _bufferLimit(0), \r\n  _bufferBase(0), \r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nclass CInBufferException\r\n{\r\npublic:\r\n  HRESULT ErrorCode;\r\n  CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      if(!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)\r\n  {\r\n    for(processedSize = 0; processedSize < size; processedSize++)\r\n      if (!ReadByte(((Byte *)data)[processedSize]))\r\n        return;\r\n  }\r\n  bool ReadBytes(void *data, UInt32 size)\r\n  {\r\n    UInt32 processedSize;\r\n    ReadBytes(data, size, processedSize);\r\n    return (processedSize == size);\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\n#include \"../../Common/Alloc.h\"\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{ \r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos) \r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode != S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = FlushPart();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException\r\n{\r\n  HRESULT ErrorCode;\r\n  COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\n  void FlushWithCheck();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Read(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (Byte *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Write(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      break;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/ARM.cpp",
    "content": "// ARM.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARM.h\"\r\n\r\n#include \"BranchARM.c\"\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/ARM.h",
    "content": "// ARM.h\r\n\r\n#ifndef __ARM_H\r\n#define __ARM_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM, 0x05, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/ARMThumb.cpp",
    "content": "// ARMThumb.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARMThumb.h\"\r\n\r\n#include \"BranchARMThumb.c\"\r\n\r\nUInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/ARMThumb.h",
    "content": "// ARMThumb.h\r\n\r\n#ifndef __ARMTHUMB_H\r\n#define __ARMTHUMB_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARMThumb, 0x07, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchARM.c",
    "content": "// BranchARM.c\r\n\r\n#include \"BranchARM.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 src = (data[i + 2] << 16) | (data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + 8 + src;\r\n      else\r\n        dest = src - (nowPos + i + 8);\r\n      dest >>= 2;\r\n      data[i + 2] = (dest >> 16);\r\n      data[i + 1] = (dest >> 8);\r\n      data[i + 0] = dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchARM.h",
    "content": "// BranchARM.h\r\n\r\n#ifndef __BRANCH_ARM_H\r\n#define __BRANCH_ARM_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchARMThumb.c",
    "content": "// BranchARMThumb.c\r\n\r\n#include \"BranchARMThumb.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 && \r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 src = \r\n        ((data[i + 1] & 0x7) << 19) |\r\n        (data[i + 0] << 11) |\r\n        ((data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + 4 + src;\r\n      else\r\n        dest = src - (nowPos + i + 4);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = 0xF0 | ((dest >> 19) & 0x7);\r\n      data[i + 0] = (dest >> 11);\r\n      data[i + 3] = 0xF8 | ((dest >> 8) & 0x7);\r\n      data[i + 2] = (dest);\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchARMThumb.h",
    "content": "// BranchARMThumb.h\r\n\r\n#ifndef __BRANCH_ARM_THUMB_H\r\n#define __BRANCH_ARM_THUMB_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __BRANCH_CODER_H\r\n#define __BRANCH_CODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/Types.h\"\r\n#include \"Common/Alloc.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClass2b(Name, id, subId, encodingId)  \\\r\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\r\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00); \r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchIA64.c",
    "content": "// BranchIA64.c\r\n\r\n#include \"BranchIA64.h\"\r\n\r\nconst Byte kBranchTable[32] = \r\n{ \r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0 \r\n};\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 16 <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    for (int slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      UInt32 bytePos = (bitPos >> 3);\r\n      UInt32 bitRes = bitPos & 0x7;\r\n      // UInt64 instruction = *(UInt64 *)(data + i + bytePos);\r\n      UInt64 instruction = 0;\r\n      int j;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);\r\n\r\n      UInt64 instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 \r\n        &&  ((instNorm >> 9) & 0x7) == 0 \r\n        // &&  (instNorm & 0x3F)== 0 \r\n        )\r\n      {\r\n        UInt32 src = UInt32((instNorm >> 13) & 0xFFFFF);\r\n        src |= ((instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        UInt32 dest;\r\n        if (encoding)\r\n          dest = nowPos + i + src;\r\n        else\r\n          dest = src - (nowPos + i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~(UInt64(0x8FFFFF) << 13);\r\n        instNorm |= (UInt64(dest & 0xFFFFF) << 13);\r\n        instNorm |= (UInt64(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        // *(UInt64 *)(data + i + bytePos) = instruction;\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = Byte(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchIA64.h",
    "content": "// BranchIA64.h\r\n\r\n#ifndef __BRANCH_IA64_H\r\n#define __BRANCH_IA64_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchPPC.c",
    "content": "// BranchPPC.c\r\n\r\n#include \"BranchPPC.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    // PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link)\r\n    if ((data[i] >> 2) == 0x12 && \r\n    (\r\n      (data[i + 3] & 3) == 1 \r\n      // || (data[i+3] & 3) == 3\r\n      )\r\n    )\r\n    {\r\n      UInt32 src = ((data[i + 0] & 3) << 24) |\r\n        (data[i + 1] << 16) |\r\n        (data[i + 2] << 8) |\r\n        (data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      data[i + 0] = 0x48 | ((dest >> 24) &  0x3);\r\n      data[i + 1] = (dest >> 16);\r\n      data[i + 2] = (dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchPPC.h",
    "content": "// BranchPPC.h\r\n\r\n#ifndef __BRANCH_PPC_H\r\n#define __BRANCH_PPC_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchSPARC.c",
    "content": "// BranchSPARC.c\r\n\r\n#include \"BranchSPARC.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || \r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      \r\n      src <<= 2;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchSPARC.h",
    "content": "// BranchSPARC.h\r\n\r\n#ifndef __BRANCH_SPARC_H\r\n#define __BRANCH_SPARC_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 SPARC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchX86.c",
    "content": "/* BranchX86.c */\r\n\r\n#include \"BranchX86.h\"\r\n\r\n/*\r\nstatic int inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n*/\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst int kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\n/*\r\nvoid x86_Convert_Init(UInt32 *prevMask, UInt32 *prevPos)\r\n{\r\n  *prevMask = 0;\r\n  *prevPos = (UInt32)(-5);\r\n}\r\n*/\r\n\r\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \r\n    UInt32 *prevMask, UInt32 *prevPos, int encoding)\r\n{\r\n  UInt32 bufferPos = 0;\r\n  UInt32 limit;\r\n\r\n  if (endPos < 5)\r\n    return 0;\r\n  \r\n  if (nowPos - *prevPos > 5)\r\n    *prevPos = nowPos - 5;\r\n  \r\n  limit = endPos - 5;\r\n  while(bufferPos <= limit)\r\n  {\r\n    Byte b = buffer[bufferPos];\r\n    UInt32 offset;\r\n    if (b != 0xE8 && b != 0xE9)\r\n    {\r\n      bufferPos++;\r\n      continue;\r\n    }\r\n    offset = (nowPos + bufferPos - *prevPos);\r\n    *prevPos = (nowPos + bufferPos);\r\n    if (offset > 5)\r\n      *prevMask = 0;\r\n    else\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < offset; i++)\r\n      {\r\n        *prevMask &= 0x77;\r\n        *prevMask <<= 1;\r\n      }\r\n    }\r\n    b = buffer[bufferPos + 4];\r\n    if (Test86MSByte(b) && kMaskToAllowedStatus[(*prevMask >> 1) & 0x7] && \r\n      (*prevMask >> 1) < 0x10)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)(b) << 24) |\r\n        ((UInt32)(buffer[bufferPos + 3]) << 16) |\r\n        ((UInt32)(buffer[bufferPos + 2]) << 8) |\r\n        (buffer[bufferPos + 1]);\r\n      \r\n      UInt32 dest;\r\n      while(1)\r\n      {\r\n        UInt32 index;\r\n        if (encoding)\r\n          dest = (nowPos + bufferPos + 5) + src;\r\n        else\r\n          dest = src - (nowPos + bufferPos + 5);\r\n        if (*prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[*prevMask >> 1];\r\n        b = (Byte)(dest >> (24 - index * 8));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index * 8)) - 1);\r\n      }\r\n      buffer[bufferPos + 4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      buffer[bufferPos + 3] = (Byte)(dest >> 16);\r\n      buffer[bufferPos + 2] = (Byte)(dest >> 8);\r\n      buffer[bufferPos + 1] = (Byte)dest;\r\n      bufferPos += 5;\r\n      *prevMask = 0;\r\n    }\r\n    else\r\n    {\r\n      bufferPos++;\r\n      *prevMask |= 1;\r\n      if (Test86MSByte(b))\r\n        *prevMask |= 0x10;\r\n    }\r\n  }\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/BranchX86.h",
    "content": "/* BranchX86.h */\r\n\r\n#ifndef __BRANCHX86_H\r\n#define __BRANCHX86_H\r\n\r\n#ifndef UInt32\r\n#define UInt32 unsigned int\r\n#endif\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#define x86_Convert_Init(prevMask, prevPos) { prevMask = 0; prevPos = (UInt32)(-5); }\r\n\r\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \r\n    UInt32 *prevMask, UInt32 *prevPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/IA64.cpp",
    "content": "// IA64.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"IA64.h\"\r\n\r\n#include \"BranchIA64.c\"\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/IA64.h",
    "content": "// IA64.h\r\n\r\n#ifndef __IA64_H\r\n#define __IA64_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_IA64, 0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/PPC.cpp",
    "content": "// PPC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"PPC.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"BranchPPC.c\"\r\n\r\nUInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/PPC.h",
    "content": "// PPC.h\r\n\r\n#ifndef __PPC_H\r\n#define __PPC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_PPC_B, 0x02, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/SPARC.cpp",
    "content": "// SPARC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"SPARC.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"BranchSPARC.c\"\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/SPARC.h",
    "content": "// SPARC.h\r\n\r\n#ifndef __SPARC_H\r\n#define __SPARC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_SPARC, 0x08, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/x86.cpp",
    "content": "// x86.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"BranchX86.c\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/x86.h",
    "content": "// x86.h\r\n\r\n#ifndef __X86_H\r\n#define __X86_H\r\n\r\n#include \"BranchCoder.h\"\r\n#include \"BranchX86.h\"\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  UInt32 _prevPos;\r\n  void x86Init() { x86_Convert_Init(_prevMask, _prevPos); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 , \r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/x86_2.cpp",
    "content": "// x86_2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86_2.h\"\r\n\r\n#include \"../../../Common/Alloc.h\"\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\ninline bool IsJcc(Byte b0, Byte b1)\r\n{\r\n  return (b0 == 0x0F && (b1 & 0xF0) == 0x80);\r\n}\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CBCJ2_x86_Encoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCBCJ2_x86_Encoder::~CBCJ2_x86_Encoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CBCJ2_x86_Encoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256; i++)\r\n    _statusE8Encoder[i].Init();\r\n  _statusE9Encoder.Init();\r\n  _statusJccEncoder.Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  while(true)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    while(true)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it \r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\r\n        else if (IsJcc(prevByte, b))\r\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src = \r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;          \r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;          \r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      if (convert)\r\n      {\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 1);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 1);\r\n        else \r\n          _statusJccEncoder.Encode(&_rangeEncoder, 1);\r\n\r\n        bufferPos += 5;\r\n        if (b == 0xE8)\r\n        {\r\n          _callStream.WriteByte((Byte)(dest >> 24));\r\n          _callStream.WriteByte((Byte)(dest >> 16));\r\n          _callStream.WriteByte((Byte)(dest >> 8));\r\n          _callStream.WriteByte((Byte)(dest));\r\n        }\r\n        else \r\n        {\r\n          _jumpStream.WriteByte((Byte)(dest >> 24));\r\n          _jumpStream.WriteByte((Byte)(dest >> 16));\r\n          _jumpStream.WriteByte((Byte)(dest >> 8));\r\n          _jumpStream.WriteByte((Byte)(dest));\r\n        }\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\r\n        else\r\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256; i++)\r\n    _statusE8Decoder[i].Init();\r\n  _statusE9Decoder.Init();\r\n  _statusJccDecoder.Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  while(true)\r\n  {\r\n    if (processedBytes > (1 << 20) && progress != NULL)\r\n    {\r\n      UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    processedBytes++;\r\n    Byte b;\r\n    if (!_mainInStream.ReadByte(b))\r\n      return Flush();\r\n    _outStream.WriteByte(b);\r\n    if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\r\n    {\r\n      prevByte = b;\r\n      continue;\r\n    }\r\n    bool status;\r\n    if (b == 0xE8)\r\n      status = (_statusE8Decoder[prevByte].Decode(&_rangeDecoder) == 1);\r\n    else if (b == 0xE9)\r\n      status = (_statusE9Decoder.Decode(&_rangeDecoder) == 1);\r\n    else\r\n      status = (_statusJccDecoder.Decode(&_rangeDecoder) == 1);\r\n    if (status)\r\n    {\r\n      UInt32 src;\r\n      if (b == 0xE8)\r\n      {\r\n        Byte b0;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src = ((UInt32)b0) << 24;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 16;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 8;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      else\r\n      {\r\n        Byte b0;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src = ((UInt32)b0) << 24;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 16;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 8;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CBCJ2_x86_Decoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/Branch/x86_2.h",
    "content": "// x86_2.h\r\n\r\n#ifndef __BRANCH_X86_2_H\r\n#define __BRANCH_X86_2_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../RangeCoder/RangeCoderBit.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n// {23170F69-40C1-278B-0303-010100000100}\r\n#define MyClass2_a(Name, id, subId, encodingId)  \\\r\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\r\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00);\r\n\r\n#define MyClass_a(Name, id, subId)  \\\r\nMyClass2_a(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClass2_a(Name ## _Decoder, id, subId, 0x00) \r\n\r\nMyClass_a(BCJ2_x86, 0x01, 0x1B)\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CBCJ2_x86_Encoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CBCJ2_x86_Encoder(): _buffer(0) {};\r\n  ~CBCJ2_x86_Encoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE8Encoder[256];\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE9Encoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusJccEncoder;\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CBCJ2_x86_Encoder *_coder;\r\n  public:\r\n    CCoderReleaser(CBCJ2_x86_Encoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n\r\nclass CBCJ2_x86_Decoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{ \r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE8Decoder[256];\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE9Decoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusJccDecoder;\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CBCJ2_x86_Decoder *_coder;\r\n  public:\r\n    CCoderReleaser(CBCJ2_x86_Decoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/BinTree/BinTree.h",
    "content": "// BinTree.h\r\n\r\n#include \"../LZInWindow.h\"\r\n#include \"../IMatchFinder.h\"\r\n \r\nnamespace BT_NAMESPACE {\r\n\r\ntypedef UInt32 CIndex;\r\nconst UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\r\n\r\nclass CMatchFinderBinTree: \r\n  public IMatchFinder,\r\n  public IMatchFinderSetCallback,\r\n  public CLZInWindow,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 _cyclicBufferPos;\r\n  UInt32 _cyclicBufferSize; // it must be historySize + 1\r\n  UInt32 _matchMaxLen;\r\n  CIndex *_hash;\r\n  UInt32 _cutValue;\r\n\r\n  CMyComPtr<IMatchFinderCallback> m_Callback;\r\n\r\n  void Normalize();\r\n  void FreeThisClassMemory();\r\n  void FreeMemory();\r\n\r\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\r\n\r\n  STDMETHOD(Init)(ISequentialInStream *inStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(MovePos)();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\r\n  STDMETHOD_(void, DummyLongestMatch)();\r\n\r\n  // IMatchFinderSetCallback\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\r\n\r\n  virtual void BeforeMoveBlock();\r\n  virtual void AfterMoveBlock();\r\n\r\npublic:\r\n  CMatchFinderBinTree();\r\n  virtual ~CMatchFinderBinTree();\r\n  void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/BinTree/BinTree2.h",
    "content": "// BinTree2.h\r\n\r\n#ifndef __BINTREE2_H\r\n#define __BINTREE2_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT2\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/BinTree/BinTree3.h",
    "content": "// BinTree3.h\r\n\r\n#ifndef __BINTREE3_H\r\n#define __BINTREE3_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT3\r\n\r\n#define HASH_ARRAY_2\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/BinTree/BinTree3Z.h",
    "content": "// BinTree3Z.h\r\n\r\n#ifndef __BINTREE3Z_H\r\n#define __BINTREE3Z_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT3Z\r\n\r\n#define HASH_ZIP\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ZIP\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/BinTree/BinTree4.h",
    "content": "// BinTree4.h\r\n\r\n#ifndef __BINTREE4_H\r\n#define __BINTREE4_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT4\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/BinTree/BinTree4b.h",
    "content": "// BinTree4b.h\r\n\r\n#ifndef __BINTREE4B_H\r\n#define __BINTREE4B_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT4B\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n#define HASH_BIG\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n#undef HASH_BIG\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/BinTree/BinTreeMain.h",
    "content": "// BinTreeMain.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/CRC.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\nnamespace BT_NAMESPACE {\r\n\r\n#ifdef HASH_ARRAY_2\r\n  static const UInt32 kHash2Size = 1 << 10;\r\n  #ifdef HASH_ARRAY_3\r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 4;\r\n    static const UInt32 kHash3Size = 1 << 18;\r\n    #ifdef HASH_BIG\r\n    static const UInt32 kHashSize = 1 << 23;\r\n    #else\r\n    static const UInt32 kHashSize = 1 << 20;\r\n    #endif\r\n  #else\r\n    static const UInt32 kNumHashDirectBytes = 3;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n  #endif\r\n#else\r\n  #ifdef HASH_ZIP \r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << 16;\r\n  #else\r\n    #define THERE_ARE_DIRECT_HASH_BYTES\r\n    static const UInt32 kNumHashDirectBytes = 2;\r\n    static const UInt32 kNumHashBytes = 2;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n  #endif\r\n#endif\r\n\r\nstatic const UInt32 kHashSizeSum = kHashSize\r\n    #ifdef HASH_ARRAY_2\r\n    + kHash2Size\r\n    #ifdef HASH_ARRAY_3\r\n    + kHash3Size\r\n    #endif\r\n    #endif\r\n    ;\r\n\r\n#ifdef HASH_ARRAY_2\r\nstatic const UInt32 kHash2Offset = kHashSize;\r\n#ifdef HASH_ARRAY_3\r\nstatic const UInt32 kHash3Offset = kHashSize + kHash2Size;\r\n#endif\r\n#endif\r\n\r\nCMatchFinderBinTree::CMatchFinderBinTree():\r\n  _hash(0),\r\n  _cutValue(0xFF)\r\n{\r\n}\r\n\r\nvoid CMatchFinderBinTree::FreeThisClassMemory()\r\n{\r\n  BigFree(_hash);\r\n  _hash = 0;\r\n}\r\n\r\nvoid CMatchFinderBinTree::FreeMemory()\r\n{\r\n  FreeThisClassMemory();\r\n  CLZInWindow::Free();\r\n}\r\n\r\nCMatchFinderBinTree::~CMatchFinderBinTree()\r\n{ \r\n  FreeMemory();\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderBinTree::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  UInt32 sizeReserv = (historySize + keepAddBufferBefore + \r\n      matchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n  if (CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, sizeReserv))\r\n  {\r\n    if (historySize + 256 > kMaxValForNormalize)\r\n    {\r\n      FreeMemory();\r\n      return E_INVALIDARG;\r\n    }\r\n    _matchMaxLen = matchMaxLen;\r\n    UInt32 newCyclicBufferSize = historySize + 1;\r\n    if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)\r\n      return S_OK;\r\n    FreeThisClassMemory();\r\n    _cyclicBufferSize = newCyclicBufferSize; // don't change it\r\n    _hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize * 2) * sizeof(CIndex));\r\n    if (_hash != 0)\r\n      return S_OK;\r\n  }\r\n  FreeMemory();\r\n  return E_OUTOFMEMORY;\r\n}\r\n\r\nstatic const UInt32 kEmptyHashValue = 0;\r\n\r\nSTDMETHODIMP CMatchFinderBinTree::Init(ISequentialInStream *stream)\r\n{\r\n  RINOK(CLZInWindow::Init(stream));\r\n  for(UInt32 i = 0; i < kHashSizeSum; i++)\r\n    _hash[i] = kEmptyHashValue;\r\n  _cyclicBufferPos = 0;\r\n  ReduceOffsets(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderBinTree::ReleaseStream()\r\n{ \r\n  // ReleaseStream(); \r\n}\r\n\r\n#ifdef HASH_ARRAY_2\r\n#ifdef HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)\r\n{\r\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\r\n  hash2Value = temp & (kHash2Size - 1);\r\n  hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);\r\n  return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) & \r\n      (kHashSize - 1);\r\n}\r\n#else // no HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)\r\n{\r\n  hash2Value = (CCRC::Table[pointer[0]] ^ pointer[1]) & (kHash2Size - 1);\r\n  return ((UInt32(pointer[0]) << 16)) | ((UInt32(pointer[1]) << 8)) | pointer[2];\r\n}\r\n#endif // HASH_ARRAY_3\r\n#else // no HASH_ARRAY_2\r\n#ifdef HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return ((UInt32(pointer[0]) << 8) ^ \r\n      CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\r\n}\r\n#else // no HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return pointer[0] ^ (UInt32(pointer[1]) << 8);\r\n}\r\n#endif // HASH_ZIP\r\n#endif // HASH_ARRAY_2\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetLongestMatch(UInt32 *distances)\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kNumHashBytes)\r\n      return 0; \r\n  }\r\n\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  Byte *cur = _buffer + _pos;\r\n\r\n  UInt32 maxLen = 0;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[hashValue];\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n  #endif\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  distances[2] = 0xFFFFFFFF;\r\n  if(curMatch2 > matchMinPos)\r\n    if (_buffer[curMatch2] == cur[0])\r\n    {\r\n      distances[2] = _pos - curMatch2 - 1;\r\n      maxLen = 2;\r\n    }\r\n\r\n  #ifdef HASH_ARRAY_3\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  distances[3] = 0xFFFFFFFF;\r\n  if(curMatch3 > matchMinPos)\r\n    if (_buffer[curMatch3] == cur[0])\r\n    {\r\n      distances[3] = _pos - curMatch3 - 1;\r\n      maxLen = 3;\r\n    }\r\n  #endif\r\n  #endif\r\n\r\n  _hash[hashValue] = _pos;\r\n\r\n  CIndex *son = _hash + kHashSizeSum;\r\n  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r\n\r\n  distances[kNumHashBytes] = 0xFFFFFFFF;\r\n\r\n  #ifdef THERE_ARE_DIRECT_HASH_BYTES\r\n  if (lenLimit == kNumHashDirectBytes)\r\n  {\r\n    if(curMatch > matchMinPos)\r\n      while (maxLen < kNumHashDirectBytes)\r\n        distances[++maxLen] = _pos - curMatch - 1;\r\n    // We don't need tree in this case\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 len0, len1;\r\n    len0 = len1 = kNumHashDirectBytes;\r\n    UInt32 count = _cutValue;\r\n    while(true)\r\n    {\r\n      if(curMatch <= matchMinPos || count-- == 0)\r\n      {\r\n        *ptr0 = kEmptyHashValue;\r\n        *ptr1 = kEmptyHashValue;\r\n        break;\r\n      }\r\n      Byte *pb = _buffer + curMatch;\r\n      UInt32 len = MyMin(len0, len1);\r\n      do\r\n      {\r\n        if (pb[len] != cur[len])\r\n          break;\r\n      }\r\n      while(++len != lenLimit);\r\n      \r\n      UInt32 delta = _pos - curMatch;\r\n      while (maxLen < len)\r\n        distances[++maxLen] = delta - 1;\r\n      \r\n      UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n          (_cyclicBufferPos - delta):\r\n          (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n      CIndex *pair = son + (cyclicPos << 1);\r\n      \r\n      if (len != lenLimit)\r\n      {\r\n        if (pb[len] < cur[len])\r\n        {\r\n          *ptr1 = curMatch;\r\n          ptr1 = pair + 1;\r\n          curMatch = *ptr1;\r\n          len1 = len;\r\n        }\r\n        else\r\n        {\r\n          *ptr0 = curMatch;\r\n          ptr0 = pair;\r\n          curMatch = *ptr0;\r\n          len0 = len;\r\n        }\r\n      }\r\n      else\r\n      {\r\n        *ptr1 = pair[0];\r\n        *ptr0 = pair[1];\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  #ifdef HASH_ARRAY_2\r\n  #ifdef HASH_ARRAY_3\r\n  if (distances[4] < distances[3])\r\n    distances[3] = distances[4];\r\n  #endif\r\n  if (distances[3] < distances[2])\r\n    distances[2] = distances[3];\r\n  #endif\r\n  return maxLen;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderBinTree::DummyLongestMatch()\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kNumHashBytes)\r\n      return; \r\n  }\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  Byte *cur = _buffer + _pos;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[hashValue];\r\n  _hash[hashValue] = _pos;\r\n\r\n  CIndex *son = _hash + kHashSizeSum;\r\n  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r\n\r\n  #ifdef THERE_ARE_DIRECT_HASH_BYTES\r\n  if (lenLimit != kNumHashDirectBytes)\r\n  #endif\r\n  {\r\n    UInt32 len0, len1;\r\n    len0 = len1 = kNumHashDirectBytes;\r\n    UInt32 count = _cutValue;\r\n    while(true)\r\n    {\r\n      if(curMatch <= matchMinPos || count-- == 0)\r\n        break;\r\n      Byte *pb = _buffer + curMatch;\r\n      UInt32 len = MyMin(len0, len1);\r\n      do\r\n      {\r\n        if (pb[len] != cur[len])\r\n          break;\r\n      }\r\n      while(++len != lenLimit);\r\n      \r\n      UInt32 delta = _pos - curMatch;\r\n      UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n        (_cyclicBufferPos - delta):\r\n      (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n      CIndex *pair = son + (cyclicPos << 1);\r\n      \r\n      if (len != lenLimit)\r\n      {\r\n        if (pb[len] < cur[len])\r\n        {\r\n          *ptr1 = curMatch;\r\n          ptr1 = pair + 1;\r\n          curMatch = *ptr1;\r\n          len1 = len;\r\n        }\r\n        else \r\n        {\r\n          *ptr0 = curMatch;\r\n          ptr0 = pair;\r\n          curMatch = *ptr0;\r\n          len0 = len;\r\n        }\r\n      }\r\n      else\r\n      {\r\n        *ptr1 = pair[0];\r\n        *ptr0 = pair[1];\r\n        return;\r\n      }\r\n    }\r\n  }\r\n  *ptr0 = kEmptyHashValue;\r\n  *ptr1 = kEmptyHashValue;\r\n}\r\n\r\nvoid CMatchFinderBinTree::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _cyclicBufferSize;\r\n  CIndex *items = _hash;\r\n  UInt32 numItems = (kHashSizeSum + _cyclicBufferSize * 2);\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n  ReduceOffsets(subValue);\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderBinTree::MovePos()\r\n{\r\n  if (++_cyclicBufferPos == _cyclicBufferSize)\r\n    _cyclicBufferPos = 0;\r\n  RINOK(CLZInWindow::MovePos());\r\n  if (_pos == kMaxValForNormalize)\r\n    Normalize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(Byte) CMatchFinderBinTree::GetIndexByte(Int32 index)\r\n  { return CLZInWindow::GetIndexByte(index); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetMatchLen(Int32 index, \r\n    UInt32 back, UInt32 limit)\r\n  { return CLZInWindow::GetMatchLen(index, back, limit); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetNumAvailableBytes()\r\n  { return CLZInWindow::GetNumAvailableBytes(); }\r\n\r\nSTDMETHODIMP_(const Byte *) CMatchFinderBinTree::GetPointerToCurrentPos()\r\n  { return CLZInWindow::GetPointerToCurrentPos(); }\r\n\r\n// IMatchFinderSetCallback\r\nSTDMETHODIMP CMatchFinderBinTree::SetCallback(IMatchFinderCallback *callback)\r\n{\r\n  m_Callback = callback;\r\n  return S_OK;\r\n}\r\n\r\nvoid CMatchFinderBinTree::BeforeMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->BeforeChangingBufferPos();\r\n  CLZInWindow::BeforeMoveBlock();\r\n}\r\n\r\nvoid CMatchFinderBinTree::AfterMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->AfterChangingBufferPos();\r\n  CLZInWindow::AfterMoveBlock();\r\n}\r\n \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/HashChain/HC.h",
    "content": "// HC.h\r\n\r\n#include \"../LZInWindow.h\"\r\n#include \"../IMatchFinder.h\"\r\n \r\nnamespace HC_NAMESPACE {\r\n\r\ntypedef UInt32 CIndex;\r\nconst UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\r\n\r\nclass CMatchFinderHC: \r\n  public IMatchFinder,\r\n  public IMatchFinderSetCallback,\r\n  public CLZInWindow,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 _cyclicBufferPos;\r\n  UInt32 _cyclicBufferSize; // it must be historySize + 1\r\n  UInt32 _matchMaxLen;\r\n  CIndex *_hash;\r\n  UInt32 _cutValue;\r\n\r\n  CMyComPtr<IMatchFinderCallback> m_Callback;\r\n\r\n  void Normalize();\r\n  void FreeThisClassMemory();\r\n  void FreeMemory();\r\n\r\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\r\n\r\n  STDMETHOD(Init)(ISequentialInStream *inStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(MovePos)();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\r\n  STDMETHOD_(void, DummyLongestMatch)();\r\n\r\n  // IMatchFinderSetCallback\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\r\n\r\n  virtual void BeforeMoveBlock();\r\n  virtual void AfterMoveBlock();\r\n\r\npublic:\r\n  CMatchFinderHC();\r\n  virtual ~CMatchFinderHC();\r\n  void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/HashChain/HC2.h",
    "content": "// HC2.h\r\n\r\n#ifndef __HC2_H\r\n#define __HC2_H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC2\r\n\r\n#include \"HCMF.h\"\r\n#include \"HCMFMain.h\"\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/HashChain/HC3.h",
    "content": "// HC3.h\r\n\r\n#ifndef __HC3_H\r\n#define __HC3_H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC3\r\n\r\n#define HASH_ARRAY_2\r\n\r\n#include \"HC.h\"\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/HashChain/HC4.h",
    "content": "// HC4.h\r\n\r\n#ifndef __HC4_H\r\n#define __HC4_H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC4\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n\r\n#include \"HC.h\"\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/HashChain/HC4b.h",
    "content": "// HC4b.h\r\n\r\n#ifndef __HC4B__H\r\n#define __HC4B__H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC4b\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n#define HASH_BIG\r\n\r\n#include \"HC.h\"\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n#undef HASH_BIG\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/HashChain/HCMain.h",
    "content": "// HC.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/CRC.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\nnamespace HC_NAMESPACE {\r\n\r\n#ifdef HASH_ARRAY_2\r\n  static const UInt32 kHash2Size = 1 << 10;\r\n  #ifdef HASH_ARRAY_3\r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 4;\r\n    static const UInt32 kHash3Size = 1 << 18;\r\n    #ifdef HASH_BIG\r\n    static const UInt32 kHashSize = 1 << 23;\r\n    #else\r\n    static const UInt32 kHashSize = 1 << 20;\r\n    #endif\r\n  #else\r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << (16);\r\n  #endif\r\n#else\r\n  #ifdef HASH_ZIP \r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << 16;\r\n  #else\r\n    #define THERE_ARE_DIRECT_HASH_BYTES\r\n    static const UInt32 kNumHashDirectBytes = 2;\r\n    static const UInt32 kNumHashBytes = 2;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n  #endif\r\n#endif\r\n\r\nstatic const UInt32 kHashSizeSum = kHashSize\r\n    #ifdef HASH_ARRAY_2\r\n    + kHash2Size\r\n    #ifdef HASH_ARRAY_3\r\n    + kHash3Size\r\n    #endif\r\n    #endif\r\n    ;\r\n\r\n#ifdef HASH_ARRAY_2\r\nstatic const UInt32 kHash2Offset = kHashSize;\r\n#ifdef HASH_ARRAY_3\r\nstatic const UInt32 kHash3Offset = kHashSize + kHash2Size;\r\n#endif\r\n#endif\r\n\r\nCMatchFinderHC::CMatchFinderHC():\r\n  _hash(0),\r\n  _cutValue(16)\r\n{\r\n}\r\n\r\nvoid CMatchFinderHC::FreeThisClassMemory()\r\n{\r\n  BigFree(_hash);\r\n  _hash = 0;\r\n}\r\n\r\nvoid CMatchFinderHC::FreeMemory()\r\n{\r\n  FreeThisClassMemory();\r\n  CLZInWindow::Free();\r\n}\r\n\r\nCMatchFinderHC::~CMatchFinderHC()\r\n{ \r\n  FreeMemory();\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderHC::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  UInt32 sizeReserv = (historySize + keepAddBufferBefore + \r\n      matchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n  if (CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, sizeReserv))\r\n  {\r\n    if (historySize + 256 > kMaxValForNormalize)\r\n    {\r\n      FreeMemory();\r\n      return E_INVALIDARG;\r\n    }\r\n    _matchMaxLen = matchMaxLen;\r\n    UInt32 newCyclicBufferSize = historySize + 1;\r\n    if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)\r\n      return S_OK;\r\n    FreeThisClassMemory();\r\n    _cyclicBufferSize = newCyclicBufferSize; // don't change it\r\n    _hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize) * sizeof(CIndex));\r\n    if (_hash != 0)\r\n      return S_OK;\r\n  }\r\n  FreeMemory();\r\n  return E_OUTOFMEMORY;\r\n}\r\n\r\nstatic const UInt32 kEmptyHashValue = 0;\r\n\r\nSTDMETHODIMP CMatchFinderHC::Init(ISequentialInStream *stream)\r\n{\r\n  RINOK(CLZInWindow::Init(stream));\r\n  for(UInt32 i = 0; i < kHashSizeSum; i++)\r\n    _hash[i] = kEmptyHashValue;\r\n  _cyclicBufferPos = 0;\r\n  ReduceOffsets(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderHC::ReleaseStream()\r\n{ \r\n  // ReleaseStream(); \r\n}\r\n\r\n#ifdef HASH_ARRAY_2\r\n#ifdef HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)\r\n{\r\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\r\n  hash2Value = temp & (kHash2Size - 1);\r\n  hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);\r\n  return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) & \r\n      (kHashSize - 1);\r\n}\r\n#else // no HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)\r\n{\r\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\r\n  hash2Value = temp & (kHash2Size - 1);\r\n  return (temp ^ (UInt32(pointer[2]) << 8)) & (kHashSize - 1);;\r\n}\r\n#endif // HASH_ARRAY_3\r\n#else // no HASH_ARRAY_2\r\n#ifdef HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return ((UInt32(pointer[0]) << 8) ^ \r\n      CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\r\n}\r\n#else // no HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return pointer[0] ^ (UInt32(pointer[1]) << 8);\r\n}\r\n#endif // HASH_ZIP\r\n#endif // HASH_ARRAY_2\r\n\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetLongestMatch(UInt32 *distances)\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kNumHashBytes)\r\n      return 0; \r\n  }\r\n\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  Byte *cur = _buffer + _pos;\r\n  \r\n  UInt32 maxLen = 0;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n  #ifdef HASH_ARRAY_2\r\n\r\n  UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  distances[2] = 0xFFFFFFFF;\r\n  if(curMatch2 > matchMinPos)\r\n    if (_buffer[curMatch2] == cur[0])\r\n    {\r\n      distances[2] = _pos - curMatch2 - 1;\r\n      maxLen = 2;\r\n    }\r\n\r\n  #ifdef HASH_ARRAY_3\r\n  \r\n  UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  distances[3] = 0xFFFFFFFF;\r\n  if(curMatch3 > matchMinPos)\r\n    if (_buffer[curMatch3] == cur[0])\r\n    {\r\n      distances[3] = _pos - curMatch3 - 1;\r\n      maxLen = 3;\r\n    }\r\n  \r\n  #endif\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[hashValue];\r\n  _hash[hashValue] = _pos;\r\n  CIndex *chain = _hash + kHashSizeSum;\r\n  chain[_cyclicBufferPos] = curMatch;\r\n  distances[kNumHashBytes] = 0xFFFFFFFF;\r\n  #ifdef THERE_ARE_DIRECT_HASH_BYTES\r\n  if (lenLimit == kNumHashDirectBytes)\r\n  {\r\n    if(curMatch > matchMinPos)\r\n      while (maxLen < kNumHashDirectBytes)\r\n        distances[++maxLen] = _pos - curMatch - 1;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 count = _cutValue;\r\n    do\r\n    {\r\n      if(curMatch <= matchMinPos)\r\n        break;\r\n      Byte *pby1 = _buffer + curMatch;\r\n      UInt32 currentLen = kNumHashDirectBytes;\r\n      do \r\n      {\r\n        if (pby1[currentLen] != cur[currentLen])\r\n          break;\r\n      }\r\n      while(++currentLen != lenLimit);\r\n      \r\n      UInt32 delta = _pos - curMatch;\r\n      while (maxLen < currentLen)\r\n        distances[++maxLen] = delta - 1;\r\n      if(currentLen == lenLimit)\r\n        break;\r\n      \r\n      UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n        (_cyclicBufferPos - delta):\r\n      (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n      \r\n      curMatch = chain[cyclicPos];\r\n    }\r\n    while(--count != 0);\r\n  }\r\n  #ifdef HASH_ARRAY_2\r\n  #ifdef HASH_ARRAY_3\r\n  if (distances[4] < distances[3])\r\n    distances[3] = distances[4];\r\n  #endif\r\n  if (distances[3] < distances[2])\r\n    distances[2] = distances[3];\r\n  #endif\r\n  return maxLen;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderHC::DummyLongestMatch()\r\n{\r\n  if (_streamPos - _pos < kNumHashBytes)\r\n    return; \r\n  \r\n  Byte *cur = _buffer + _pos;\r\n  \r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  _hash[kHashSizeSum + _cyclicBufferPos] = _hash[hashValue];\r\n  _hash[hashValue] = _pos;\r\n}\r\n\r\nvoid CMatchFinderHC::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _cyclicBufferSize;\r\n  CIndex *items = _hash;\r\n  UInt32 numItems = kHashSizeSum + _cyclicBufferSize;\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n  ReduceOffsets(subValue);\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderHC::MovePos()\r\n{\r\n  if (++_cyclicBufferPos == _cyclicBufferSize)\r\n    _cyclicBufferPos = 0;\r\n  RINOK(CLZInWindow::MovePos());\r\n  if (_pos == kMaxValForNormalize)\r\n    Normalize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(Byte) CMatchFinderHC::GetIndexByte(Int32 index)\r\n  { return CLZInWindow::GetIndexByte(index); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetMatchLen(Int32 index, \r\n    UInt32 back, UInt32 limit)\r\n  { return CLZInWindow::GetMatchLen(index, back, limit); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetNumAvailableBytes()\r\n  { return CLZInWindow::GetNumAvailableBytes(); }\r\n\r\nSTDMETHODIMP_(const Byte *) CMatchFinderHC::GetPointerToCurrentPos()\r\n  { return CLZInWindow::GetPointerToCurrentPos(); }\r\n\r\n// IMatchFinderSetCallback\r\nSTDMETHODIMP CMatchFinderHC::SetCallback(IMatchFinderCallback *callback)\r\n{\r\n  m_Callback = callback;\r\n  return S_OK;\r\n}\r\n\r\nvoid CMatchFinderHC::BeforeMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->BeforeChangingBufferPos();\r\n  CLZInWindow::BeforeMoveBlock();\r\n}\r\n\r\nvoid CMatchFinderHC::AfterMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->AfterChangingBufferPos();\r\n  CLZInWindow::AfterMoveBlock();\r\n}\r\n \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/IMatchFinder.h",
    "content": "// MatchFinders/IMatchFinder.h\r\n\r\n#ifndef __IMATCHFINDER_H\r\n#define __IMATCHFINDER_H\r\n\r\n// {23170F69-40C1-278A-0000-000200010000}\r\nDEFINE_GUID(IID_IInWindowStream, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200010000\")\r\nIInWindowStream: public IUnknown\r\n{\r\n  STDMETHOD(Init)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD_(void, ReleaseStream)() PURE;\r\n  STDMETHOD(MovePos)() PURE;\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;\r\n};\r\n \r\n// {23170F69-40C1-278A-0000-000200020000}\r\nDEFINE_GUID(IID_IMatchFinder, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020000\")\r\nIMatchFinder: public IInWindowStream\r\n{\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances) PURE;\r\n  STDMETHOD_(void, DummyLongestMatch)() PURE;\r\n};\r\n\r\n// {23170F69-40C1-278A-0000-000200020100}\r\nDEFINE_GUID(IID_IMatchFinderCallback, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020100\")\r\nIMatchFinderCallback: public IUnknown\r\n{\r\n  STDMETHOD(BeforeChangingBufferPos)() PURE;\r\n  STDMETHOD(AfterChangingBufferPos)() PURE;\r\n};\r\n\r\n// {23170F69-40C1-278A-0000-000200020200}\r\nDEFINE_GUID(IID_IMatchFinderSetCallback, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020200\")\r\nIMatchFinderSetCallback: public IUnknown\r\n{\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback) PURE;\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000200030000}\r\nDEFINE_GUID(IID_IInitMatchFinder, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200030000\")\r\nIMatchFinderInit: public IUnknown\r\n{\r\n  STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/LZInWindow.cpp",
    "content": "// LZInWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZInWindow.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n\r\nvoid CLZInWindow::Free()\r\n{\r\n  ::BigFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nbool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n{\r\n  _keepSizeBefore = keepSizeBefore;\r\n  _keepSizeAfter = keepSizeAfter;\r\n  _keepSizeReserv = keepSizeReserv;\r\n  UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n  if (_bufferBase == 0 || _blockSize != blockSize)\r\n  {\r\n    Free();\r\n    _blockSize = blockSize;\r\n    if (_blockSize != 0)\r\n      _bufferBase = (Byte *)::BigAlloc(_blockSize);\r\n  }\r\n  _pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;\r\n  if (_blockSize == 0)\r\n    return true;\r\n  return (_bufferBase != 0);\r\n}\r\n\r\n\r\nHRESULT CLZInWindow::Init(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n  _buffer = _bufferBase;\r\n  _pos = 0;\r\n  _streamPos = 0;\r\n  _streamEndWasReached = false;\r\n  return ReadBlock();\r\n}\r\n\r\n/*\r\nvoid CLZInWindow::ReleaseStream()\r\n{\r\n  _stream.Release();\r\n}\r\n*/\r\n\r\n///////////////////////////////////////////\r\n// ReadBlock\r\n\r\n// In State:\r\n//   (_buffer + _streamPos) <= (_bufferBase + _blockSize)\r\n// Out State:\r\n//   _posLimit <= _blockSize - _keepSizeAfter;\r\n//   if(_streamEndWasReached == false):\r\n//     _streamPos >= _pos + _keepSizeAfter\r\n//     _posLimit = _streamPos - _keepSizeAfter;\r\n//   else\r\n//          \r\n  \r\nHRESULT CLZInWindow::ReadBlock()\r\n{\r\n  if(_streamEndWasReached)\r\n    return S_OK;\r\n  while(true)\r\n  {\r\n    UInt32 size = UInt32(_bufferBase - _buffer) + _blockSize - _streamPos;\r\n    if(size == 0)\r\n      return S_OK;\r\n    UInt32 numReadBytes;\r\n    RINOK(_stream->Read(_buffer + _streamPos, size, &numReadBytes));\r\n    if(numReadBytes == 0)\r\n    {\r\n      _posLimit = _streamPos;\r\n      const Byte *pointerToPostion = _buffer + _posLimit;\r\n      if(pointerToPostion > _pointerToLastSafePosition)\r\n        _posLimit = (UInt32)(_pointerToLastSafePosition - _buffer);\r\n      _streamEndWasReached = true;\r\n      return S_OK;\r\n    }\r\n    _streamPos += numReadBytes;\r\n    if(_streamPos >= _pos + _keepSizeAfter)\r\n    {\r\n      _posLimit = _streamPos - _keepSizeAfter;\r\n      return S_OK;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CLZInWindow::MoveBlock()\r\n{\r\n  BeforeMoveBlock();\r\n  UInt32 offset = UInt32(_buffer - _bufferBase) + _pos - _keepSizeBefore;\r\n  UInt32 numBytes = UInt32(_buffer - _bufferBase) + _streamPos -  offset;\r\n  memmove(_bufferBase, _bufferBase + offset, numBytes);\r\n  _buffer -= offset;\r\n  AfterMoveBlock();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/LZInWindow.h",
    "content": "// LZInWindow.h\r\n\r\n#ifndef __LZ_IN_WINDOW_H\r\n#define __LZ_IN_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n\r\nclass CLZInWindow\r\n{\r\n  Byte *_bufferBase; // pointer to buffer with data\r\n  ISequentialInStream *_stream;\r\n  UInt32 _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n  bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n  const Byte *_pointerToLastSafePosition;\r\nprotected:\r\n  Byte  *_buffer;   // Pointer to virtual Buffer begin\r\n  UInt32 _blockSize;  // Size of Allocated memory block\r\n  UInt32 _pos;             // offset (from _buffer) of curent byte\r\n  UInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n  UInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n  UInt32 _keepSizeReserv;  // how many BYTEs must be kept as reserv\r\n  UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\r\n  virtual void BeforeMoveBlock() {};\r\n  virtual void AfterMoveBlock() {};\r\n  void MoveBlock();\r\n  virtual HRESULT ReadBlock();\r\n  void Free();\r\npublic:\r\n  CLZInWindow(): _bufferBase(0) {}\r\n  virtual ~CLZInWindow() { Free(); }\r\n\r\n  bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, \r\n      UInt32 keepSizeReserv = (1<<17));\r\n\r\n  HRESULT Init(ISequentialInStream *stream);\r\n  // void ReleaseStream();\r\n\r\n  Byte *GetBuffer() const { return _buffer; }\r\n\r\n  const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }\r\n\r\n  HRESULT MovePos()\r\n  {\r\n    _pos++;\r\n    if (_pos > _posLimit)\r\n    {\r\n      const Byte *pointerToPostion = _buffer + _pos;\r\n      if(pointerToPostion > _pointerToLastSafePosition)\r\n        MoveBlock();\r\n      return ReadBlock();\r\n    }\r\n    else\r\n      return S_OK;\r\n  }\r\n  Byte GetIndexByte(Int32 index)const\r\n    {  return _buffer[(size_t)_pos + index]; }\r\n\r\n  // index + limit have not to exceed _keepSizeAfter;\r\n  UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const\r\n  {  \r\n    if(_streamEndWasReached)\r\n      if ((_pos + index) + limit > _streamPos)\r\n        limit = _streamPos - (_pos + index);\r\n    distance++;\r\n    Byte *pby = _buffer + (size_t)_pos + index;\r\n    UInt32 i;\r\n    for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);\r\n    return i;\r\n  }\r\n\r\n  UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }\r\n\r\n  void ReduceOffsets(Int32 subValue)\r\n  {\r\n    _buffer += subValue;\r\n    _posLimit -= subValue;\r\n    _pos -= subValue;\r\n    _streamPos -= subValue;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/LZOutWindow.cpp",
    "content": "// LZOutWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"LZOutWindow.h\"\r\n\r\nvoid CLZOutWindow::Init(bool solid)\r\n{\r\n  if(!solid)\r\n    COutBuffer::Init();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/LZOutWindow.h",
    "content": "// LZOutWindow.h\r\n\r\n#ifndef __LZ_OUT_WINDOW_H\r\n#define __LZ_OUT_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\n/*\r\n#ifndef _NO_EXCEPTIONS\r\nclass CLZOutWindowException\r\n{\r\npublic:\r\n  HRESULT ErrorCode;\r\n  CLZOutWindowException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n*/\r\ntypedef COutBufferException CLZOutWindowException;\r\n\r\nclass CLZOutWindow: public COutBuffer\r\n{\r\npublic:\r\n  void Init(bool solid = false);\r\n  \r\n  // distance >= 0, len > 0, \r\n  bool CopyBlock(UInt32 distance, UInt32 len)\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n    {\r\n      if (!_overDict)\r\n        return false;\r\n      pos += _bufferSize;\r\n    }\r\n    do\r\n    {\r\n      if (pos == _bufferSize)\r\n        pos = 0;\r\n      _buffer[_pos++] = _buffer[pos++];\r\n      if (_pos == _limitPos)\r\n        FlushWithCheck();  \r\n    }\r\n    while(--len != 0);\r\n    return true;\r\n  }\r\n  \r\n  void PutByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if (_pos == _limitPos)\r\n      FlushWithCheck();  \r\n  }\r\n  \r\n  Byte GetByte(UInt32 distance) const\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n      pos += _bufferSize;\r\n    return _buffer[pos]; \r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/Patricia/Pat.h",
    "content": "// Pat.h\r\n\r\n// #ifndef __PATRICIA__H\r\n// #define __PATRICIA__H\r\n\r\n#include \"../../../../Common/MyCom.h\"\r\n#include \"../../../../Common/Types.h\"\r\n#include \"../LZInWindow.h\"\r\n\r\nnamespace PAT_NAMESPACE {\r\n\r\nstruct CNode;\r\n\r\ntypedef CNode *CNodePointer;\r\n\r\n// #define __AUTO_REMOVE\r\n\r\n// #define __NODE_4_BITS\r\n// #define __NODE_3_BITS\r\n// #define __NODE_2_BITS\r\n// #define __NODE_2_BITS_PADDING\r\n\r\n// #define __HASH_3\r\n\r\n\r\ntypedef UInt32 CIndex;\r\n\r\n#ifdef __NODE_4_BITS\r\n  typedef UInt32 CIndex2;\r\n  typedef UInt32 CSameBitsType;\r\n#else\r\n#ifdef __NODE_3_BITS\r\n  typedef UInt32 CIndex2;\r\n  typedef UInt32 CSameBitsType;\r\n#else\r\n\r\n  typedef UInt32 CIndex;\r\n  typedef UInt32 CSameBitsType;\r\n\r\n  typedef CIndex CIndex2;\r\n#endif\r\n#endif\r\n\r\nconst UInt32 kNumBitsInIndex = sizeof(CIndex) * 8;\r\nconst UInt32 kMatchStartValue = UInt32(1) << (kNumBitsInIndex - 1);\r\n// don't change kMatchStartValue definition, since it is used in \r\n// PatMain.h: \r\n\r\ntypedef CIndex CMatchPointer;\r\n\r\nconst UInt32 kDescendantEmptyValue = kMatchStartValue - 1;\r\n\r\nunion CDescendant \r\n{\r\n  CIndex NodePointer;\r\n  CMatchPointer MatchPointer;\r\n  bool IsEmpty() const { return NodePointer == kDescendantEmptyValue; }\r\n  bool IsNode() const { return NodePointer < kDescendantEmptyValue; }\r\n  bool IsMatch() const { return NodePointer > kDescendantEmptyValue; }\r\n  void MakeEmpty() { NodePointer = kDescendantEmptyValue; }\r\n};\r\n\r\n#undef MY_BYTE_SIZE\r\n\r\n#ifdef __NODE_4_BITS\r\n  #define MY_BYTE_SIZE 8\r\n  const UInt32 kNumSubBits = 4;\r\n#else\r\n#ifdef __NODE_3_BITS\r\n  #define MY_BYTE_SIZE 9\r\n  const UInt32 kNumSubBits = 3;\r\n#else\r\n  #define MY_BYTE_SIZE 8\r\n  #ifdef __NODE_2_BITS\r\n    const UInt32 kNumSubBits = 2;\r\n  #else\r\n    const UInt32 kNumSubBits = 1;\r\n  #endif\r\n#endif\r\n#endif\r\n\r\nconst UInt32 kNumSubNodes = 1 << kNumSubBits;\r\nconst UInt32 kSubNodesMask = kNumSubNodes - 1;\r\n\r\nstruct CNode\r\n{\r\n  CIndex2 LastMatch;\r\n  CSameBitsType NumSameBits;\r\n  union\r\n  {\r\n    CDescendant  Descendants[kNumSubNodes];\r\n    UInt32 NextFreeNode;\r\n  };\r\n  #ifdef __NODE_2_BITS\r\n  #ifdef __NODE_2_BITS_PADDING\r\n  UInt32 Padding[2];\r\n  #endif\r\n  #endif\r\n};\r\n\r\n#undef kIDNumBitsByte\r\n#undef kIDNumBitsString\r\n\r\n#ifdef __NODE_4_BITS\r\n  #define kIDNumBitsByte 0x30\r\n  #define kIDNumBitsString TEXT(\"4\")\r\n#else\r\n#ifdef __NODE_3_BITS\r\n  #define kIDNumBitsByte 0x20\r\n  #define kIDNumBitsString TEXT(\"3\")\r\n#else\r\n#ifdef __NODE_2_BITS\r\n  #define kIDNumBitsByte 0x10\r\n  #define kIDNumBitsString TEXT(\"2\")\r\n#else\r\n  #define kIDNumBitsByte 0x00\r\n  #define kIDNumBitsString TEXT(\"1\")\r\n#endif\r\n#endif\r\n#endif\r\n\r\n#undef kIDManualRemoveByte\r\n#undef kIDManualRemoveString\r\n\r\n#ifdef __AUTO_REMOVE\r\n  #define kIDManualRemoveByte 0x00\r\n  #define kIDManualRemoveString TEXT(\"\")\r\n#else\r\n  #define kIDManualRemoveByte 0x08\r\n  #define kIDManualRemoveString TEXT(\"R\")\r\n#endif\r\n\r\n#undef kIDHash3Byte\r\n#undef kIDHash3String\r\n\r\n#ifdef __HASH_3\r\n  #define kIDHash3Byte 0x04\r\n  #define kIDHash3String TEXT(\"H\")\r\n#else\r\n  #define kIDHash3Byte 0x00\r\n  #define kIDHash3String TEXT(\"\")\r\n#endif\r\n\r\n#undef kIDUse3BytesByte\r\n#undef kIDUse3BytesString\r\n\r\n#define kIDUse3BytesByte 0x00\r\n#define kIDUse3BytesString TEXT(\"\")\r\n\r\n#undef kIDPaddingByte\r\n#undef kIDPaddingString\r\n\r\n#ifdef __NODE_2_BITS_PADDING\r\n  #define kIDPaddingByte 0x01\r\n  #define kIDPaddingString TEXT(\"P\")\r\n#else\r\n  #define kIDPaddingByte 0x00\r\n  #define kIDPaddingString TEXT(\"\")\r\n#endif\r\n\r\n\r\n// #undef kIDString\r\n// #define kIDString TEXT(\"Compress.MatchFinderPat\") kIDNumBitsString kIDManualRemoveString kIDUse3BytesString kIDPaddingString kIDHash3String\r\n\r\n// {23170F69-40C1-278C-01XX-0000000000}\r\n\r\nDEFINE_GUID(PAT_CLSID, \r\n0x23170F69, 0x40C1, 0x278C, 0x01, \r\nkIDNumBitsByte | \r\nkIDManualRemoveByte | kIDHash3Byte | kIDUse3BytesByte | kIDPaddingByte, \r\n0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\n// III(PAT_NAMESPACE)\r\n\r\nclass CPatricia: \r\n  public IMatchFinder,\r\n  public IMatchFinderSetCallback,\r\n  public CMyUnknownImp,\r\n  CLZInWindow\r\n{ \r\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\r\n\r\n  STDMETHOD(Init)(ISequentialInStream *aStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(MovePos)();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD(Create)(UInt32 historySize, \r\n      UInt32 keepAddBufferBefore, UInt32 matchMaxLen, \r\n      UInt32 keepAddBufferAfter);\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\r\n  STDMETHOD_(void, DummyLongestMatch)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n\r\n  void FreeMemory();\r\npublic:\r\n  CPatricia();\r\n  ~CPatricia();\r\n\r\n  UInt32 _sizeHistory;\r\n  UInt32 _matchMaxLen;\r\n\r\n  CDescendant *m_HashDescendants;\r\n  #ifdef __HASH_3\r\n  CDescendant *m_Hash2Descendants;\r\n  #endif\r\n\r\n  CNode *m_Nodes;\r\n\r\n  UInt32 m_FreeNode;\r\n  UInt32 m_FreeNodeMax;\r\n\r\n  #ifdef __AUTO_REMOVE\r\n  UInt32 m_NumUsedNodes;\r\n  UInt32 m_NumNodes;\r\n  #else\r\n  bool  m_SpecialRemoveMode;\r\n  #endif\r\n\r\n  bool  m_SpecialMode;\r\n  UInt32 m_NumNotChangedCycles;\r\n  UInt32 *m_TmpBacks;\r\n\r\n  CMyComPtr<IMatchFinderCallback> m_Callback;\r\n\r\n  virtual void BeforeMoveBlock();\r\n  virtual void AfterMoveBlock();\r\n\r\n  // IMatchFinderSetCallback\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\r\n\r\n  void ChangeLastMatch(UInt32 hashValue);\r\n  \r\n  #ifdef __AUTO_REMOVE\r\n  void TestRemoveDescendant(CDescendant &descendant, UInt32 limitPos);\r\n  void TestRemoveNodes();\r\n  void RemoveNode(UInt32 index);\r\n  void TestRemoveAndNormalizeDescendant(CDescendant &descendant, \r\n      UInt32 limitPos, UInt32 subValue);\r\n  void TestRemoveNodesAndNormalize();\r\n  #else\r\n  void NormalizeDescendant(CDescendant &descendant, UInt32 subValue);\r\n  void Normalize();\r\n  void RemoveMatch();\r\n  #endif\r\nprivate:\r\n  void AddInternalNode(CNodePointer aNode, CIndex *aNodePointerPointer, \r\n      Byte aByte, Byte aByteXOR, UInt32 aNumSameBits, UInt32 aPos)\r\n  {\r\n    while((aByteXOR & kSubNodesMask) == 0)\r\n    {\r\n      aByteXOR >>= kNumSubBits;\r\n      aByte >>= kNumSubBits;\r\n      aNumSameBits -= kNumSubBits;\r\n    }\r\n    // Insert New Node\r\n    CNodePointer aNewNode = &m_Nodes[m_FreeNode];\r\n    UInt32 aNodeIndex = *aNodePointerPointer;\r\n    *aNodePointerPointer = m_FreeNode;\r\n    m_FreeNode = aNewNode->NextFreeNode;\r\n    #ifdef __AUTO_REMOVE\r\n    m_NumUsedNodes++;\r\n    #endif\r\n    if (m_FreeNode > m_FreeNodeMax)\r\n    {\r\n      m_FreeNodeMax = m_FreeNode;\r\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\r\n    }\r\n\r\n    UInt32 aBitsNew = aByte & kSubNodesMask;\r\n    UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;\r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n      aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;\r\n    aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;\r\n    aNewNode->Descendants[aBitsOld].NodePointer = aNodeIndex;\r\n    aNewNode->NumSameBits = CSameBitsType(aNode->NumSameBits - aNumSameBits);\r\n    aNewNode->LastMatch = aPos;\r\n    \r\n    aNode->NumSameBits = CSameBitsType(aNumSameBits - kNumSubBits);\r\n  }\r\n\r\n  void AddLeafNode(CNodePointer aNode, Byte aByte, Byte aByteXOR, \r\n      UInt32 aNumSameBits, UInt32 aPos, UInt32 aDescendantIndex)\r\n  {\r\n    for(;(aByteXOR & kSubNodesMask) == 0; aNumSameBits += kNumSubBits)\r\n    {\r\n      aByte >>= kNumSubBits;\r\n      aByteXOR >>= kNumSubBits;\r\n    }\r\n    UInt32 aNewNodeIndex = m_FreeNode;\r\n    CNodePointer aNewNode = &m_Nodes[m_FreeNode];\r\n    m_FreeNode = aNewNode->NextFreeNode;\r\n    #ifdef __AUTO_REMOVE\r\n    m_NumUsedNodes++;\r\n    #endif\r\n    if (m_FreeNode > m_FreeNodeMax)\r\n    {\r\n      m_FreeNodeMax = m_FreeNode;\r\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\r\n    }\r\n\r\n    UInt32 aBitsNew = (aByte & kSubNodesMask);\r\n    UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;\r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n      aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;\r\n    aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;\r\n    aNewNode->Descendants[aBitsOld].MatchPointer = \r\n      aNode->Descendants[aDescendantIndex].MatchPointer;\r\n    aNewNode->NumSameBits = CSameBitsType(aNumSameBits);\r\n    aNewNode->LastMatch = aPos;\r\n    aNode->Descendants[aDescendantIndex].NodePointer = aNewNodeIndex;\r\n  }\r\n};\r\n\r\n}\r\n\r\n// #endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/Patricia/Pat2.h",
    "content": "// Pat2.h\r\n\r\n#ifndef __PAT2__H\r\n#define __PAT2__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat2\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat2\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_2_BITS\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef  __NODE_2_BITS\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/Patricia/Pat2H.h",
    "content": "// Pat2H.h\r\n\r\n#ifndef __PAT2H__H\r\n#define __PAT2H__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat2H\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat2H\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_2_BITS\r\n#define __HASH_3\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef __NODE_2_BITS\r\n#undef __HASH_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/Patricia/Pat2R.h",
    "content": "// Pat2R.h\r\n\r\n#ifndef __PAT2R__H\r\n#define __PAT2R__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat2R\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat2R\r\n\r\n#define __NODE_2_BITS\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef  __NODE_2_BITS\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/Patricia/Pat3H.h",
    "content": "// Pat3H.h\r\n\r\n#ifndef __PAT3H__H\r\n#define __PAT3H__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat3H\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat3H\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_3_BITS\r\n#define __HASH_3\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef __NODE_3_BITS\r\n#undef __HASH_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/Patricia/Pat4H.h",
    "content": "// Pat4H.h\r\n\r\n#ifndef __PAT4H__H\r\n#define __PAT4H__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat4H\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat4H\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_4_BITS\r\n#define __HASH_3\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef __NODE_4_BITS\r\n#undef __HASH_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/Patricia/PatMain.h",
    "content": "// PatMain.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\nnamespace PAT_NAMESPACE {\r\n\r\nSTDMETHODIMP CPatricia::SetCallback(IMatchFinderCallback *callback)\r\n{\r\n  m_Callback = callback;\r\n  return S_OK;\r\n}\r\n\r\nvoid CPatricia::BeforeMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->BeforeChangingBufferPos();\r\n  CLZInWindow::BeforeMoveBlock();\r\n}\r\n\r\nvoid CPatricia::AfterMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->AfterChangingBufferPos();\r\n  CLZInWindow::AfterMoveBlock();\r\n}\r\n\r\nconst UInt32 kMatchStartValue2 = 2;\r\nconst UInt32 kDescendantEmptyValue2 = kMatchStartValue2 - 1;\r\nconst UInt32 kDescendantsNotInitilized2 = kDescendantEmptyValue2 - 1;\r\n\r\n#ifdef __HASH_3\r\n\r\nstatic const UInt32 kNumHashBytes = 3;\r\nstatic const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n\r\nstatic const UInt32 kNumHash2Bytes = 2;\r\nstatic const UInt32 kHash2Size = 1 << (8 * kNumHash2Bytes);\r\nstatic const UInt32 kPrevHashSize = kNumHash2Bytes;\r\n\r\n#else\r\n\r\nstatic const UInt32 kNumHashBytes = 2;\r\nstatic const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\nstatic const UInt32 kPrevHashSize = 0;\r\n\r\n#endif\r\n\r\n\r\nCPatricia::CPatricia():\r\n  m_HashDescendants(0),\r\n  #ifdef __HASH_3\r\n  m_Hash2Descendants(0),\r\n  #endif\r\n  m_Nodes(0),\r\n  m_TmpBacks(0)\r\n{\r\n}\r\n\r\nCPatricia::~CPatricia()\r\n{\r\n  FreeMemory();\r\n}\r\n\r\nvoid CPatricia::FreeMemory()\r\n{\r\n  MyFree(m_TmpBacks);\r\n  m_TmpBacks = 0;\r\n\r\n  ::BigFree(m_Nodes);\r\n  m_Nodes = 0;\r\n\r\n  ::BigFree(m_HashDescendants);\r\n  m_HashDescendants = 0;\r\n\r\n  #ifdef __HASH_3\r\n\r\n  ::BigFree(m_Hash2Descendants);\r\n  m_Hash2Descendants = 0;\r\n\r\n  CLZInWindow::Free();\r\n\r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP CPatricia::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  FreeMemory();\r\n  int kNumBitsInNumSameBits = sizeof(CSameBitsType) * 8;\r\n  if (kNumBitsInNumSameBits < 32 && ((matchMaxLen * MY_BYTE_SIZE) > ((UInt32)1 << kNumBitsInNumSameBits)))\r\n    return E_INVALIDARG;\r\n\r\n  const UInt32 kAlignMask = (1 << 16) - 1;\r\n  UInt32 windowReservSize = historySize;\r\n  windowReservSize += kAlignMask;\r\n  windowReservSize &= ~(kAlignMask);\r\n\r\n  const UInt32 kMinReservSize = (1 << 19);\r\n  if (windowReservSize < kMinReservSize)\r\n    windowReservSize = kMinReservSize;\r\n  windowReservSize += 256;\r\n\r\n  if (!CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, windowReservSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _sizeHistory = historySize;\r\n  _matchMaxLen = matchMaxLen;\r\n  m_HashDescendants = (CDescendant *)BigAlloc(kHashSize * sizeof(CDescendant));\r\n  if (m_HashDescendants == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n\r\n  #ifdef __HASH_3\r\n  m_Hash2Descendants = (CDescendant *)BigAlloc(kHash2Size  * sizeof(CDescendant));\r\n  if (m_Hash2Descendants == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n  #endif\r\n  \r\n  #ifdef __AUTO_REMOVE\r\n  \r\n  #ifdef __HASH_3\r\n  m_NumNodes = historySize + _sizeHistory * 4 / 8 + (1 << 19);\r\n  #else\r\n  m_NumNodes = historySize + _sizeHistory * 4 / 8 + (1 << 10);\r\n  #endif\r\n  \r\n  #else\r\n  \r\n  UInt32 m_NumNodes = historySize;\r\n  \r\n  #endif\r\n  \r\n  const UInt32 kMaxNumNodes = UInt32(1) << (sizeof(CIndex) * 8 - 1);\r\n  if (m_NumNodes + 32 > kMaxNumNodes)\r\n    return E_INVALIDARG;\r\n  \r\n  // m_Nodes = (CNode *)::BigAlloc((m_NumNodes + 2) * sizeof(CNode));\r\n  m_Nodes = (CNode *)::BigAlloc((m_NumNodes + 12) * sizeof(CNode));\r\n  if (m_Nodes == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n  \r\n  m_TmpBacks = (UInt32 *)MyAlloc((_matchMaxLen + 1) * sizeof(UInt32));\r\n  if (m_TmpBacks == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CPatricia::Init(ISequentialInStream *aStream)\r\n{\r\n  RINOK(CLZInWindow::Init(aStream));\r\n\r\n  // memset(m_HashDescendants, 0xFF, kHashSize * sizeof(m_HashDescendants[0]));\r\n\r\n  #ifdef __HASH_3\r\n  for (UInt32 i = 0; i < kHash2Size; i++)\r\n    m_Hash2Descendants[i].MatchPointer = kDescendantsNotInitilized2;\r\n  #else\r\n  for (UInt32 i = 0; i < kHashSize; i++)\r\n    m_HashDescendants[i].MakeEmpty();\r\n  #endif\r\n\r\n  m_Nodes[0].NextFreeNode = 1;\r\n  m_FreeNode = 0;\r\n  m_FreeNodeMax = 0;\r\n  #ifdef __AUTO_REMOVE\r\n  m_NumUsedNodes = 0;\r\n  #else\r\n  m_SpecialRemoveMode = false;\r\n  #endif\r\n  m_SpecialMode = false;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CPatricia::ReleaseStream()\r\n{\r\n  // CLZInWindow::ReleaseStream();\r\n}\r\n\r\n// pos = _pos + kNumHashBytes\r\n// fullCurrentLimit = currentLimit + kNumHashBytes\r\n// fullMatchLen = matchLen + kNumHashBytes\r\n\r\nvoid CPatricia::ChangeLastMatch(UInt32 hashValue)\r\n{\r\n  UInt32 pos = _pos + kNumHashBytes - 1;\r\n  UInt32 descendantIndex;\r\n  const Byte *currentBytePointer = _buffer + pos;\r\n  UInt32 numLoadedBits = 0;\r\n  Byte curByte = 0;  // = 0 to disable warning of GCC\r\n  CNodePointer node = &m_Nodes[m_HashDescendants[hashValue].NodePointer];\r\n\r\n  while(true)\r\n  {\r\n    UInt32 numSameBits = node->NumSameBits;\r\n    if(numSameBits > 0)\r\n    {\r\n      if (numLoadedBits < numSameBits)\r\n      {\r\n        numSameBits -= numLoadedBits;\r\n        currentBytePointer += (numSameBits / MY_BYTE_SIZE);\r\n        numSameBits %= MY_BYTE_SIZE;\r\n        curByte = *currentBytePointer++;\r\n        numLoadedBits = MY_BYTE_SIZE; \r\n      }\r\n      curByte >>= numSameBits;\r\n      numLoadedBits -= numSameBits;\r\n    }\r\n    if(numLoadedBits == 0)\r\n    {\r\n      curByte = *currentBytePointer++;\r\n      numLoadedBits = MY_BYTE_SIZE; \r\n    }\r\n    descendantIndex = (curByte & kSubNodesMask);\r\n    node->LastMatch = pos;\r\n    numLoadedBits -= kNumSubBits;\r\n    curByte >>= kNumSubBits;\r\n    if(node->Descendants[descendantIndex].IsNode())\r\n      node = &m_Nodes[node->Descendants[descendantIndex].NodePointer];\r\n    else\r\n      break;\r\n  }\r\n  node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n}\r\n\r\nUInt32 CPatricia::GetLongestMatch(UInt32 *distances)\r\n{\r\n  UInt32 fullCurrentLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    fullCurrentLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    fullCurrentLimit = _streamPos - _pos;\r\n    if(fullCurrentLimit < kNumHashBytes)\r\n      return 0; \r\n  }\r\n  UInt32 pos = _pos + kNumHashBytes;\r\n\r\n  #ifdef __HASH_3\r\n  UInt32 hash2Value = ((UInt32(_buffer[_pos])) << 8) | _buffer[_pos + 1];\r\n  UInt32 hashValue = (hash2Value << 8) | _buffer[_pos + 2];\r\n  CDescendant &hash2Descendant = m_Hash2Descendants[hash2Value];\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  if(hash2Descendant.MatchPointer <= kDescendantEmptyValue2)\r\n  {\r\n    if(hash2Descendant.MatchPointer == kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hashValue & 0xFFFF00;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n        m_HashDescendants[base + i].MakeEmpty();\r\n    }\r\n    hash2Descendant.MatchPointer = pos + kMatchStartValue2;\r\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n    return 0;\r\n  }\r\n\r\n  distances[kNumHash2Bytes] = pos - (hash2Descendant.MatchPointer - kMatchStartValue2) - 1;\r\n  hash2Descendant.MatchPointer = pos + kMatchStartValue2;\r\n  #ifdef __AUTO_REMOVE\r\n  if (distances[kNumHash2Bytes] >= _sizeHistory)\r\n  {\r\n    if (hashDescendant.IsNode())\r\n      RemoveNode(hashDescendant.NodePointer);\r\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n    return 0;\r\n  }\r\n  #endif\r\n  if (fullCurrentLimit == kNumHash2Bytes)\r\n    return kNumHash2Bytes;\r\n\r\n  #else\r\n  UInt32 hashValue = UInt32(GetIndexByte(1))  | (UInt32(GetIndexByte(0)) << 8);\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  #endif\r\n\r\n\r\n  if(m_SpecialMode)\r\n  {\r\n    if(hashDescendant.IsMatch())\r\n      m_NumNotChangedCycles = 0;\r\n    if(m_NumNotChangedCycles >= _sizeHistory - 1)\r\n    {\r\n      ChangeLastMatch(hashValue);\r\n      m_NumNotChangedCycles = 0;\r\n    }\r\n    if(GetIndexByte(fullCurrentLimit - 1) == GetIndexByte(fullCurrentLimit - 2)) \r\n    {\r\n      if(hashDescendant.IsMatch())\r\n        hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n      else\r\n        m_NumNotChangedCycles++;\r\n      for(UInt32 i = kNumHashBytes; i <= fullCurrentLimit; i++)\r\n        distances[i] = 0;\r\n      return fullCurrentLimit;\r\n    }\r\n    else if(m_NumNotChangedCycles > 0)\r\n      ChangeLastMatch(hashValue);\r\n    m_SpecialMode = false;\r\n  }\r\n\r\n  if(hashDescendant.IsEmpty())\r\n  {\r\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n    return kPrevHashSize;\r\n  }\r\n\r\n  UInt32 currentLimit = fullCurrentLimit - kNumHashBytes;\r\n\r\n  if(hashDescendant.IsMatch())\r\n  {\r\n    CMatchPointer matchPointer = hashDescendant.MatchPointer;\r\n    UInt32 backReal = pos - (matchPointer - kMatchStartValue);\r\n    UInt32 back = backReal - 1;\r\n    #ifdef __AUTO_REMOVE\r\n    if (back >= _sizeHistory)\r\n    {\r\n      hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n      return kPrevHashSize;\r\n    }\r\n    #endif\r\n\r\n    UInt32 matchLen;\r\n    distances += kNumHashBytes;\r\n    Byte *buffer = _buffer + pos;\r\n    for(matchLen = 0; true; matchLen++)\r\n    {\r\n      *distances++ = back;\r\n      if (matchLen == currentLimit)\r\n      {\r\n        hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n        return kNumHashBytes + matchLen;\r\n      }\r\n      if (buffer[matchLen] != buffer[(size_t)matchLen - backReal])\r\n        break;\r\n    }\r\n     \r\n    // UInt32 matchLen = GetMatchLen(kNumHashBytes, back, currentLimit);\r\n    \r\n    UInt32 fullMatchLen = matchLen + kNumHashBytes; \r\n    hashDescendant.NodePointer = m_FreeNode;\r\n    CNodePointer node = &m_Nodes[m_FreeNode];\r\n    m_FreeNode = node->NextFreeNode;\r\n    #ifdef __AUTO_REMOVE\r\n    m_NumUsedNodes++;\r\n    #endif\r\n    if (m_FreeNode > m_FreeNodeMax)\r\n    {\r\n      m_FreeNodeMax = m_FreeNode;\r\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\r\n    }\r\n      \r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n      node->Descendants[i].NodePointer = kDescendantEmptyValue;\r\n    node->LastMatch = pos;\r\n      \r\n    Byte byteNew = GetIndexByte(fullMatchLen);\r\n    Byte byteOld = GetIndexByte(fullMatchLen - backReal);\r\n    Byte bitsNew, bitsOld;\r\n    UInt32 numSameBits = matchLen * MY_BYTE_SIZE;\r\n    while (true)\r\n    {\r\n      bitsNew = (byteNew & kSubNodesMask);\r\n      bitsOld = (byteOld & kSubNodesMask);\r\n      if(bitsNew != bitsOld) \r\n        break;\r\n      byteNew >>= kNumSubBits;\r\n      byteOld >>= kNumSubBits;\r\n      numSameBits += kNumSubBits;\r\n    }\r\n    node->NumSameBits = CSameBitsType(numSameBits);\r\n    node->Descendants[bitsNew].MatchPointer = pos + kMatchStartValue;\r\n    node->Descendants[bitsOld].MatchPointer = matchPointer;\r\n    return fullMatchLen;\r\n  }\r\n  const Byte *baseCurrentBytePointer = _buffer + pos;\r\n  const Byte *currentBytePointer = baseCurrentBytePointer;\r\n  UInt32 numLoadedBits = 0;\r\n  Byte curByte = 0;\r\n  CIndex *nodePointerPointer = &hashDescendant.NodePointer;\r\n  CNodePointer node = &m_Nodes[*nodePointerPointer];\r\n  distances += kNumHashBytes;\r\n  const Byte *bytePointerLimit = baseCurrentBytePointer + currentLimit;\r\n  const Byte *currentAddingOffset = _buffer;\r\n\r\n  #ifdef __AUTO_REMOVE\r\n  UInt32 lowPos;\r\n  if (pos > _sizeHistory)\r\n    lowPos = pos - _sizeHistory;\r\n  else\r\n    lowPos = 0;\r\n  #endif\r\n\r\n  while(true)\r\n  {\r\n    #ifdef __AUTO_REMOVE\r\n    if (node->LastMatch < lowPos)\r\n    {\r\n      RemoveNode(*nodePointerPointer);\r\n      *nodePointerPointer = pos + kMatchStartValue;\r\n      if (currentBytePointer == baseCurrentBytePointer)\r\n        return kPrevHashSize;\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n    #endif\r\n    if(numLoadedBits == 0)\r\n    {\r\n      *distances++ = pos - node->LastMatch - 1;\r\n      if(currentBytePointer >= bytePointerLimit)\r\n      {\r\n        for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n          node->Descendants[i].MatchPointer = pos + kMatchStartValue;\r\n        node->LastMatch = pos;\r\n        node->NumSameBits = 0;\r\n        return fullCurrentLimit;\r\n      }\r\n      curByte = (*currentBytePointer++);\r\n      currentAddingOffset++;\r\n      numLoadedBits = MY_BYTE_SIZE; \r\n    }\r\n    UInt32 numSameBits = node->NumSameBits;\r\n    if(numSameBits > 0)\r\n    {\r\n      Byte byteXOR = ((*(currentAddingOffset + node->LastMatch -1)) >> \r\n          (MY_BYTE_SIZE - numLoadedBits)) ^ curByte;\r\n      while(numLoadedBits <= numSameBits)\r\n      {\r\n        if(byteXOR != 0)\r\n        {\r\n          AddInternalNode(node, nodePointerPointer, curByte, byteXOR,\r\n              numSameBits, pos);\r\n          return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n        }\r\n        *distances++ = pos - node->LastMatch - 1;\r\n        numSameBits -= numLoadedBits;\r\n        if(currentBytePointer >= bytePointerLimit)\r\n        {\r\n          for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n            node->Descendants[i].MatchPointer = pos + kMatchStartValue;\r\n          node->LastMatch = pos;\r\n          node->NumSameBits = CSameBitsType(node->NumSameBits - numSameBits);\r\n          return fullCurrentLimit;\r\n        }\r\n        numLoadedBits = MY_BYTE_SIZE; \r\n        curByte = (*currentBytePointer++);\r\n        byteXOR = curByte ^ (*(currentAddingOffset + node->LastMatch));\r\n        currentAddingOffset++;\r\n      }\r\n      if((byteXOR & ((1 << numSameBits) - 1)) != 0)\r\n      {\r\n        AddInternalNode(node, nodePointerPointer, curByte, byteXOR,\r\n            numSameBits, pos);\r\n        return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n      }\r\n      curByte >>= numSameBits;\r\n      numLoadedBits -= numSameBits;\r\n    }\r\n    UInt32 descendantIndex = (curByte & kSubNodesMask);\r\n    numLoadedBits -= kNumSubBits;\r\n    nodePointerPointer = &node->Descendants[descendantIndex].NodePointer;\r\n    UInt32 nextNodeIndex = *nodePointerPointer;\r\n    node->LastMatch = pos;\r\n    if (nextNodeIndex < kDescendantEmptyValue)\r\n    {\r\n      curByte >>= kNumSubBits;\r\n      node = &m_Nodes[nextNodeIndex];\r\n    }\r\n    else if (nextNodeIndex == kDescendantEmptyValue)\r\n    {\r\n      node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n    else \r\n      break;\r\n  }\r\n \r\n  UInt32 descendantIndex = (curByte & kSubNodesMask);\r\n  curByte >>= kNumSubBits;\r\n  CMatchPointer matchPointer = node->Descendants[descendantIndex].MatchPointer;\r\n  CMatchPointer realMatchPointer;\r\n  realMatchPointer = matchPointer - kMatchStartValue;\r\n\r\n  #ifdef __AUTO_REMOVE\r\n  if (realMatchPointer < lowPos)\r\n  {\r\n    node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n    return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n  }\r\n  #endif\r\n\r\n  Byte byteXOR;\r\n  UInt32 numSameBits = 0;\r\n  if(numLoadedBits != 0)\r\n  {\r\n    Byte matchByte = *(currentAddingOffset + realMatchPointer -1);  \r\n    matchByte >>= (MY_BYTE_SIZE - numLoadedBits);\r\n    byteXOR = matchByte ^ curByte;\r\n    if(byteXOR != 0)\r\n    {\r\n      AddLeafNode(node, curByte, byteXOR, numSameBits, pos, descendantIndex);\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n    numSameBits += numLoadedBits;\r\n  }\r\n\r\n  const Byte *matchBytePointer = _buffer + realMatchPointer + \r\n      (currentBytePointer - baseCurrentBytePointer);\r\n  for(; currentBytePointer < bytePointerLimit; numSameBits += MY_BYTE_SIZE)\r\n  {\r\n    curByte = (*currentBytePointer++);\r\n    *distances++ = pos - realMatchPointer - 1;\r\n    byteXOR = curByte ^ (*matchBytePointer++);\r\n    if(byteXOR != 0)\r\n    {\r\n      AddLeafNode(node, curByte, byteXOR, numSameBits, pos, descendantIndex);\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n  }\r\n  *distances = pos - realMatchPointer - 1;\r\n  node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n\r\n  if(*distances == 0)\r\n  {\r\n    m_SpecialMode = true;\r\n    m_NumNotChangedCycles = 0;\r\n  }\r\n  return fullCurrentLimit;\r\n}\r\n\r\nSTDMETHODIMP_(void) CPatricia::DummyLongestMatch()\r\n{\r\n  GetLongestMatch(m_TmpBacks);\r\n}\r\n\r\n\r\n// ------------------------------------\r\n// Remove Match\r\n\r\ntypedef Byte CRemoveDataWord;\r\n\r\nstatic const int kSizeRemoveDataWordInBits = MY_BYTE_SIZE * sizeof(CRemoveDataWord);\r\n\r\n#ifndef __AUTO_REMOVE\r\n\r\nvoid CPatricia::RemoveMatch()\r\n{\r\n  if(m_SpecialRemoveMode)\r\n  {\r\n    if(GetIndexByte(_matchMaxLen - 1 - _sizeHistory) ==\r\n        GetIndexByte(_matchMaxLen - _sizeHistory))\r\n      return;\r\n    m_SpecialRemoveMode = false;\r\n  }\r\n  UInt32 pos = _pos + kNumHashBytes - _sizeHistory;\r\n\r\n  #ifdef __HASH_3\r\n  const Byte *pp = _buffer + _pos - _sizeHistory;\r\n  UInt32 hash2Value = ((UInt32(pp[0])) << 8) | pp[1];\r\n  UInt32 hashValue = (hash2Value << 8) | pp[2];\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  CDescendant &hash2Descendant = m_Hash2Descendants[hash2Value];\r\n  if (hash2Descendant >= kMatchStartValue2)\r\n    if(hash2Descendant.MatchPointer == pos + kMatchStartValue2)\r\n      hash2Descendant.MatchPointer = kDescendantEmptyValue2;\r\n  #else\r\n  UInt32 hashValue = UInt32(GetIndexByte(1 - _sizeHistory))  | \r\n      (UInt32(GetIndexByte(0 - _sizeHistory)) << 8);\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  #endif\r\n    \r\n  if(hashDescendant.IsEmpty())\r\n    return;\r\n  if(hashDescendant.IsMatch())\r\n  {\r\n    if(hashDescendant.MatchPointer == pos + kMatchStartValue)\r\n      hashDescendant.MakeEmpty();\r\n    return;\r\n  }\r\n  \r\n  UInt32 descendantIndex;\r\n  const CRemoveDataWord *currentPointer = (const CRemoveDataWord *)(_buffer + pos);\r\n  UInt32 numLoadedBits = 0;\r\n  CRemoveDataWord curWord = 0; // = 0 to disable GCC warning\r\n\r\n  CIndex *nodePointerPointer = &hashDescendant.NodePointer;\r\n\r\n  CNodePointer node = &m_Nodes[hashDescendant.NodePointer];\r\n  \r\n  while(true)\r\n  {\r\n    if(numLoadedBits == 0)\r\n    {\r\n      curWord = *currentPointer++;\r\n      numLoadedBits = kSizeRemoveDataWordInBits; \r\n    }\r\n    UInt32 numSameBits = node->NumSameBits;\r\n    if(numSameBits > 0)\r\n    {\r\n      if (numLoadedBits <= numSameBits)\r\n      {\r\n        numSameBits -= numLoadedBits;\r\n        currentPointer += (numSameBits / kSizeRemoveDataWordInBits);\r\n        numSameBits %= kSizeRemoveDataWordInBits;\r\n        curWord = *currentPointer++;\r\n        numLoadedBits = kSizeRemoveDataWordInBits; \r\n      }\r\n      curWord >>= numSameBits;\r\n      numLoadedBits -= numSameBits;\r\n    }\r\n    descendantIndex = (curWord & kSubNodesMask);\r\n    numLoadedBits -= kNumSubBits;\r\n    curWord >>= kNumSubBits;\r\n    UInt32 nextNodeIndex = node->Descendants[descendantIndex].NodePointer;\r\n    if (nextNodeIndex < kDescendantEmptyValue)\r\n    {\r\n      nodePointerPointer = &node->Descendants[descendantIndex].NodePointer;\r\n      node = &m_Nodes[nextNodeIndex];\r\n    }\r\n    else\r\n      break;\r\n  }\r\n  if (node->Descendants[descendantIndex].MatchPointer != pos + kMatchStartValue)\r\n  {\r\n    const Byte *currentBytePointer = _buffer + _pos - _sizeHistory;\r\n    const Byte *currentBytePointerLimit = currentBytePointer + _matchMaxLen;\r\n    for(;currentBytePointer < currentBytePointerLimit; currentBytePointer++)\r\n      if(*currentBytePointer != *(currentBytePointer+1))\r\n        return;\r\n    m_SpecialRemoveMode = true;\r\n    return;\r\n  }\r\n\r\n  UInt32 numNodes = 0, numMatches = 0;\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    UInt32 nodeIndex = node->Descendants[i].NodePointer;\r\n    if (nodeIndex < kDescendantEmptyValue)\r\n      numNodes++;\r\n    else if (nodeIndex > kDescendantEmptyValue)\r\n      numMatches++;\r\n  }\r\n  numMatches -= 1;\r\n  if (numNodes + numMatches > 1)\r\n  {\r\n    node->Descendants[descendantIndex].MakeEmpty();\r\n    return;\r\n  }\r\n  if(numNodes == 1)\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < kNumSubNodes; i++)\r\n      if (node->Descendants[i].IsNode())\r\n        break;\r\n    UInt32 nextNodeIndex = node->Descendants[i].NodePointer;\r\n    CNodePointer nextNode = &m_Nodes[nextNodeIndex];\r\n    nextNode->NumSameBits += node->NumSameBits + kNumSubBits;\r\n    *node = *nextNode;\r\n\r\n    nextNode->NextFreeNode = m_FreeNode;\r\n    m_FreeNode = nextNodeIndex;\r\n    return;\r\n  }\r\n  UInt32 matchPointer = 0; // = 0 to disable GCC warning\r\n  for (i = 0; i < kNumSubNodes; i++)\r\n    if (node->Descendants[i].IsMatch() && i != descendantIndex)\r\n    {\r\n      matchPointer = node->Descendants[i].MatchPointer;\r\n      break;\r\n    }\r\n  node->NextFreeNode = m_FreeNode;\r\n  m_FreeNode = *nodePointerPointer;\r\n  *nodePointerPointer = matchPointer;\r\n}\r\n#endif\r\n\r\n\r\n// Commented code is more correct, but it gives warning \r\n// on GCC: (1 << 32)\r\n// So we use kMatchStartValue twice:\r\n// kMatchStartValue = UInt32(1) << (kNumBitsInIndex - 1);\r\n// must be defined in Pat.h\r\n/*\r\nconst UInt32 kNormalizeStartPos = (UInt32(1) << (kNumBitsInIndex)) - \r\n    kMatchStartValue - kNumHashBytes - 1;\r\n*/\r\nconst UInt32 kNormalizeStartPos = kMatchStartValue - kNumHashBytes - 1;\r\n\r\nSTDMETHODIMP CPatricia::MovePos()\r\n{\r\n  #ifndef __AUTO_REMOVE\r\n  if(_pos >= _sizeHistory)\r\n    RemoveMatch();\r\n  #endif\r\n  RINOK(CLZInWindow::MovePos());\r\n  #ifdef __AUTO_REMOVE\r\n  if (m_NumUsedNodes >= m_NumNodes)\r\n    TestRemoveNodes();\r\n  #endif\r\n  if (_pos >= kNormalizeStartPos)\r\n  {\r\n    #ifdef __AUTO_REMOVE\r\n    TestRemoveNodesAndNormalize();\r\n    #else\r\n    Normalize();\r\n    #endif\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifndef __AUTO_REMOVE\r\n\r\nvoid CPatricia::NormalizeDescendant(CDescendant &descendant, UInt32 subValue)\r\n{\r\n  if (descendant.IsEmpty())\r\n    return;\r\n  if (descendant.IsMatch())\r\n    descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n  else\r\n  {\r\n    CNode &node = m_Nodes[descendant.NodePointer];\r\n    node.LastMatch = node.LastMatch - subValue;\r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n       NormalizeDescendant(node.Descendants[i], subValue);\r\n  }\r\n}\r\n\r\nvoid CPatricia::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _sizeHistory;\r\n  CLZInWindow::ReduceOffsets(subValue);\r\n  \r\n  #ifdef __HASH_3\r\n\r\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\r\n  {\r\n    CDescendant &descendant = m_Hash2Descendants[hash];\r\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hash << 8;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n        NormalizeDescendant(m_HashDescendants[base + i], subValue);\r\n    }\r\n    if (descendant.MatchPointer < kMatchStartValue2)\r\n      continue;\r\n    descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n  }\r\n  \r\n  #else\r\n  \r\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\r\n    NormalizeDescendant(m_HashDescendants[hash], subValue);\r\n  \r\n  #endif\r\n\r\n}\r\n\r\n#else\r\n\r\nvoid CPatricia::TestRemoveDescendant(CDescendant &descendant, UInt32 limitPos)\r\n{\r\n  CNode &node = m_Nodes[descendant.NodePointer];\r\n  UInt32 numChilds = 0;\r\n  UInt32 childIndex = 0; // = 0 to disable GCC warning\r\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    CDescendant &descendant2 = node.Descendants[i];\r\n    if (descendant2.IsEmpty())\r\n      continue;\r\n    if (descendant2.IsMatch())\r\n    {\r\n      if (descendant2.MatchPointer < limitPos)\r\n        descendant2.MakeEmpty();\r\n      else\r\n      {\r\n        numChilds++;\r\n        childIndex = i;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      TestRemoveDescendant(descendant2, limitPos);\r\n      if (!descendant2.IsEmpty())\r\n      {\r\n        numChilds++;\r\n        childIndex = i;\r\n      }\r\n    }\r\n  }\r\n  if (numChilds > 1)\r\n    return;\r\n\r\n  CIndex nodePointerTemp = descendant.NodePointer;\r\n  if (numChilds == 1)\r\n  {\r\n    const CDescendant &descendant2 = node.Descendants[childIndex];\r\n    if (descendant2.IsNode())\r\n      m_Nodes[descendant2.NodePointer].NumSameBits += node.NumSameBits + kNumSubBits;\r\n    descendant = descendant2;\r\n  }\r\n  else\r\n    descendant.MakeEmpty();\r\n  node.NextFreeNode = m_FreeNode;\r\n  m_FreeNode = nodePointerTemp;\r\n  m_NumUsedNodes--;\r\n}\r\n\r\nvoid CPatricia::RemoveNode(UInt32 index)\r\n{\r\n  CNode &node = m_Nodes[index];\r\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    CDescendant &descendant2 = node.Descendants[i];\r\n    if (descendant2.IsNode())\r\n      RemoveNode(descendant2.NodePointer);\r\n  }\r\n  node.NextFreeNode = m_FreeNode;\r\n  m_FreeNode = index;\r\n  m_NumUsedNodes--;\r\n}\r\n\r\nvoid CPatricia::TestRemoveNodes()\r\n{\r\n  UInt32 limitPos = kMatchStartValue + _pos - _sizeHistory + kNumHashBytes;\r\n  \r\n  #ifdef __HASH_3\r\n  \r\n  UInt32 limitPos2 = kMatchStartValue2 + _pos - _sizeHistory + kNumHashBytes;\r\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\r\n  {\r\n    CDescendant &descendant = m_Hash2Descendants[hash];\r\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hash << 8;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n      {\r\n        CDescendant &descendant = m_HashDescendants[base + i];\r\n        if (descendant.IsEmpty())\r\n          continue;\r\n        if (descendant.IsMatch())\r\n        {\r\n          if (descendant.MatchPointer < limitPos)\r\n            descendant.MakeEmpty();\r\n        }\r\n        else\r\n          TestRemoveDescendant(descendant, limitPos);\r\n      }\r\n    }\r\n    if (descendant.MatchPointer < kMatchStartValue2)\r\n      continue;\r\n    if (descendant.MatchPointer < limitPos2)\r\n      descendant.MatchPointer = kDescendantEmptyValue2;\r\n  }\r\n  \r\n  #else\r\n  \r\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\r\n  {\r\n    CDescendant &descendant = m_HashDescendants[hash];\r\n    if (descendant.IsEmpty())\r\n      continue;\r\n    if (descendant.IsMatch())\r\n    {\r\n      if (descendant.MatchPointer < limitPos)\r\n        descendant.MakeEmpty();\r\n    }\r\n    else\r\n      TestRemoveDescendant(descendant, limitPos);\r\n  }\r\n  \r\n  #endif\r\n}\r\n\r\nvoid CPatricia::TestRemoveAndNormalizeDescendant(CDescendant &descendant, \r\n    UInt32 limitPos, UInt32 subValue)\r\n{\r\n  if (descendant.IsEmpty())\r\n    return;\r\n  if (descendant.IsMatch())\r\n  {\r\n    if (descendant.MatchPointer < limitPos)\r\n      descendant.MakeEmpty();\r\n    else\r\n      descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n    return;\r\n  }\r\n  CNode &node = m_Nodes[descendant.NodePointer];\r\n  UInt32 numChilds = 0;\r\n  UInt32 childIndex = 0; // = 0 to disable GCC warning\r\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    CDescendant &descendant2 = node.Descendants[i];\r\n    TestRemoveAndNormalizeDescendant(descendant2, limitPos, subValue);\r\n    if (!descendant2.IsEmpty())\r\n    {\r\n      numChilds++;\r\n      childIndex = i;\r\n    }\r\n  }\r\n  if (numChilds > 1)\r\n  {\r\n    node.LastMatch = node.LastMatch - subValue;\r\n    return;\r\n  }\r\n\r\n  CIndex nodePointerTemp = descendant.NodePointer;\r\n  if (numChilds == 1)\r\n  {\r\n    const CDescendant &descendant2 = node.Descendants[childIndex];\r\n    if (descendant2.IsNode())\r\n      m_Nodes[descendant2.NodePointer].NumSameBits += node.NumSameBits + kNumSubBits;\r\n    descendant = descendant2;\r\n  }\r\n  else\r\n    descendant.MakeEmpty();\r\n  node.NextFreeNode = m_FreeNode;\r\n  m_FreeNode = nodePointerTemp;\r\n  m_NumUsedNodes--;\r\n}\r\n\r\nvoid CPatricia::TestRemoveNodesAndNormalize()\r\n{\r\n  UInt32 subValue = _pos - _sizeHistory;\r\n  UInt32 limitPos = kMatchStartValue + _pos - _sizeHistory + kNumHashBytes;\r\n  CLZInWindow::ReduceOffsets(subValue);\r\n\r\n  #ifdef __HASH_3\r\n  \r\n  UInt32 limitPos2 = kMatchStartValue2 + _pos - _sizeHistory + kNumHashBytes;\r\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\r\n  {\r\n    CDescendant &descendant = m_Hash2Descendants[hash];\r\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hash << 8;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n        TestRemoveAndNormalizeDescendant(m_HashDescendants[base + i], limitPos, subValue);\r\n    }\r\n    if (descendant.MatchPointer < kMatchStartValue2)\r\n      continue;\r\n    if (descendant.MatchPointer < limitPos2)\r\n      descendant.MatchPointer = kDescendantEmptyValue2;\r\n    else\r\n      descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n  }\r\n  \r\n  #else\r\n\r\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\r\n    TestRemoveAndNormalizeDescendant(m_HashDescendants[hash], limitPos, subValue);\r\n\r\n  #endif\r\n}\r\n\r\n#endif\r\n\r\nSTDMETHODIMP_(Byte) CPatricia::GetIndexByte(Int32 index)\r\n{\r\n  return CLZInWindow::GetIndexByte(index);\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CPatricia::GetMatchLen(Int32 index, UInt32 back, UInt32 limit)\r\n{\r\n  return CLZInWindow::GetMatchLen(index, back, limit);\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CPatricia::GetNumAvailableBytes()\r\n{\r\n  return CLZInWindow::GetNumAvailableBytes();\r\n}\r\n\r\nSTDMETHODIMP_(const Byte *) CPatricia::GetPointerToCurrentPos()\r\n{\r\n  return CLZInWindow::GetPointerToCurrentPos();\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZ/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA/LZMA.h",
    "content": "// LZMA.h\r\n\r\n#ifndef __LZMA_H\r\n#define __LZMA_H\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst UInt32 kNumRepDistances = 4;\r\n\r\nconst int kNumStates = 12;\r\n\r\nconst Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nconst Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nconst Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nconst Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\nclass CState\r\n{\r\npublic:\r\n  Byte Index;\r\n  void Init() { Index = 0; }\r\n  void UpdateChar() { Index = kLiteralNextStates[Index]; }\r\n  void UpdateMatch() { Index = kMatchNextStates[Index]; }\r\n  void UpdateRep() { Index = kRepNextStates[Index]; }\r\n  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }\r\n  bool IsCharState() const { return Index < 7; }\r\n};\r\n\r\nconst int kNumPosSlotBits = 6; \r\nconst int kDicLogSizeMin = 0; \r\nconst int kDicLogSizeMax = 32; \r\nconst int kDistTableSizeMax = kDicLogSizeMax * 2; \r\n\r\nconst UInt32 kNumLenToPosStates = 4;\r\n\r\ninline UInt32 GetLenToPosState(UInt32 len)\r\n{\r\n  len -= 2;\r\n  if (len < kNumLenToPosStates)\r\n    return len;\r\n  return kNumLenToPosStates - 1;\r\n}\r\n\r\nnamespace NLength {\r\n\r\nconst int kNumPosStatesBitsMax = 4;\r\nconst UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\r\nconst int kNumPosStatesBitsEncodingMax = 4;\r\nconst UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\nconst int kNumLowBits = 3;\r\nconst int kNumMidBits = 3;\r\nconst int kNumHighBits = 8;\r\nconst UInt32 kNumLowSymbols = 1 << kNumLowBits;\r\nconst UInt32 kNumMidSymbols = 1 << kNumMidBits;\r\nconst UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\r\n\r\n}\r\n\r\nconst UInt32 kMatchMinLen = 2;\r\nconst UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\r\n\r\nconst int kNumAlignBits = 4;\r\nconst UInt32 kAlignTableSize = 1 << kNumAlignBits;\r\nconst UInt32 kAlignMask = (kAlignTableSize - 1);\r\n\r\nconst UInt32 kStartPosModelIndex = 4;\r\nconst UInt32 kEndPosModelIndex = 14;\r\nconst UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\nconst UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\r\nconst int kNumLitPosStatesBitsEncodingMax = 4;\r\nconst int kNumLitContextBitsMax = 8;\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA/LZMADecoder.cpp",
    "content": "// LZMADecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\n#include \"../../../Common/Defs.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kLenIdFinished = -1;\r\nconst int kLenIdNeedInit = -2;\r\n\r\nvoid CDecoder::Init()\r\n{\r\n  { \r\n    for(int i = 0; i < kNumStates; i++)\r\n    {\r\n      for (UInt32 j = 0; j <= _posStateMask; j++)\r\n      {\r\n        _isMatch[i][j].Init();\r\n        _isRep0Long[i][j].Init();\r\n      }\r\n      _isRep[i].Init();\r\n      _isRepG0[i].Init();\r\n      _isRepG1[i].Init();\r\n      _isRepG2[i].Init();\r\n    }\r\n  }\r\n  { \r\n    for (UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n    _posSlotDecoder[i].Init();\r\n  }\r\n  { \r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posDecoders[i].Init();\r\n  }\r\n  _posAlignDecoder.Init();\r\n  _lenDecoder.Init(_posStateMask + 1);\r\n  _repMatchLenDecoder.Init(_posStateMask + 1);\r\n  _literalDecoder.Init();\r\n\r\n  _state.Init();\r\n  _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0;\r\n}\r\n\r\nHRESULT CDecoder::CodeSpec(UInt32 curSize)\r\n{\r\n  if (_outSizeDefined)\r\n  {\r\n    const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize();\r\n    if (curSize > rem)\r\n      curSize = (UInt32)rem;\r\n  }\r\n\r\n  if (_remainLen == kLenIdFinished)\r\n    return S_OK;\r\n  if (_remainLen == kLenIdNeedInit)\r\n  {\r\n    _rangeDecoder.Init();\r\n    Init();\r\n    _remainLen = 0;\r\n  }\r\n  if (curSize == 0)\r\n    return S_OK;\r\n\r\n  UInt32 rep0 = _reps[0];\r\n  UInt32 rep1 = _reps[1];\r\n  UInt32 rep2 = _reps[2];\r\n  UInt32 rep3 = _reps[3];\r\n  CState state = _state;\r\n  Byte previousByte;\r\n\r\n  while(_remainLen > 0 && curSize > 0)\r\n  {\r\n    previousByte = _outWindowStream.GetByte(rep0);\r\n    _outWindowStream.PutByte(previousByte);\r\n    _remainLen--;\r\n    curSize--;\r\n  }\r\n  UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n  if (nowPos64 == 0)\r\n    previousByte = 0;\r\n  else\r\n    previousByte = _outWindowStream.GetByte(0);\r\n\r\n  while(curSize > 0)\r\n  {\r\n    {\r\n      #ifdef _NO_EXCEPTIONS\r\n      if (_rangeDecoder.Stream.ErrorCode != S_OK)\r\n        return _rangeDecoder.Stream.ErrorCode;\r\n      #endif\r\n      if (_rangeDecoder.Stream.WasFinished())\r\n        return S_FALSE;\r\n      UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n      if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n      {\r\n        if(!state.IsCharState())\r\n          previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte, _outWindowStream.GetByte(rep0));\r\n        else\r\n          previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte);\r\n        _outWindowStream.PutByte(previousByte);\r\n        state.UpdateChar();\r\n        curSize--;\r\n        nowPos64++;\r\n      }\r\n      else             \r\n      {\r\n        UInt32 len;\r\n        if(_isRep[state.Index].Decode(&_rangeDecoder) == 1)\r\n        {\r\n          len = 0;\r\n          if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0)\r\n          {\r\n            if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n            {\r\n              state.UpdateShortRep();\r\n              len = 1;\r\n            }\r\n          }\r\n          else\r\n          {\r\n            UInt32 distance;\r\n            if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0)\r\n              distance = rep1;\r\n            else \r\n            {\r\n              if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0)\r\n                distance = rep2;\r\n              else\r\n              {\r\n                distance = rep3;\r\n                rep3 = rep2;\r\n              }\r\n              rep2 = rep1;\r\n            }\r\n            rep1 = rep0;\r\n            rep0 = distance;\r\n          }\r\n          if (len == 0)\r\n          {\r\n            len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;\r\n            state.UpdateRep();\r\n          }\r\n        }\r\n        else\r\n        {\r\n          rep3 = rep2;\r\n          rep2 = rep1;\r\n          rep1 = rep0;\r\n          len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);\r\n          state.UpdateMatch();\r\n          UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);\r\n          if (posSlot >= kStartPosModelIndex)\r\n          {\r\n            UInt32 numDirectBits = (posSlot >> 1) - 1;\r\n            rep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\r\n            if (posSlot < kEndPosModelIndex)\r\n              rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders + \r\n                  rep0 - posSlot - 1, &_rangeDecoder, numDirectBits);\r\n            else\r\n            {\r\n              rep0 += (_rangeDecoder.DecodeDirectBits(\r\n                  numDirectBits - kNumAlignBits) << kNumAlignBits);\r\n              rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder);\r\n              if (rep0 == 0xFFFFFFFF)\r\n              {\r\n                _remainLen = kLenIdFinished;\r\n                return S_OK;\r\n              }\r\n            }\r\n          }\r\n          else\r\n            rep0 = posSlot;\r\n        }\r\n        UInt32 locLen = len;\r\n        if (len > curSize)\r\n          locLen = (UInt32)curSize;\r\n        if (!_outWindowStream.CopyBlock(rep0, locLen))\r\n          return S_FALSE;\r\n        previousByte = _outWindowStream.GetByte(0);\r\n        curSize -= locLen;\r\n        nowPos64 += locLen;\r\n        len -= locLen;\r\n        if (len != 0)\r\n        {\r\n          _remainLen = (Int32)len;\r\n          break;\r\n        }\r\n\r\n        #ifdef _NO_EXCEPTIONS\r\n        if (_outWindowStream.ErrorCode != S_OK)\r\n          return _outWindowStream.ErrorCode;\r\n        #endif\r\n      }\r\n    }\r\n  }\r\n  if (_rangeDecoder.Stream.WasFinished())\r\n    return S_FALSE;\r\n  _reps[0] = rep0;\r\n  _reps[1] = rep1;\r\n  _reps[2] = rep2;\r\n  _reps[3] = rep3;\r\n  _state = state;\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 *, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  SetInStream(inStream);\r\n  _outWindowStream.SetStream(outStream);\r\n  SetOutStreamSize(outSize);\r\n  CDecoderFlusher flusher(this);\r\n\r\n  while (true)\r\n  {\r\n    UInt32 curSize = 1 << 18;\r\n    RINOK(CodeSpec(curSize));\r\n    if (_remainLen == kLenIdFinished)\r\n      break;\r\n    if (progress != NULL)\r\n    {\r\n      UInt64 inSize = _rangeDecoder.GetProcessedSize();\r\n      UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(&inSize, &nowPos64));\r\n    }\r\n    if (_outSizeDefined)\r\n      if (_outWindowStream.GetProcessedSize() >= _outSize)\r\n        break;\r\n  } \r\n  flusher.NeedFlush = false;\r\n  return Flush();\r\n}\r\n\r\n\r\n#ifdef _NO_EXCEPTIONS\r\n\r\n#define LZMA_TRY_BEGIN\r\n#define LZMA_TRY_END\r\n\r\n#else\r\n\r\n#define LZMA_TRY_BEGIN try { \r\n#define LZMA_TRY_END } \\\r\n  catch(const CInBufferException &e)  { return e.ErrorCode; } \\\r\n  catch(const CLZOutWindowException &e)  { return e.ErrorCode; } \\\r\n  catch(...) { return S_FALSE; }\r\n\r\n#endif\r\n\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  LZMA_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size)\r\n{\r\n  if (size < 5)\r\n    return E_INVALIDARG;\r\n  int lc = properties[0] % 9;\r\n  Byte remainder = (Byte)(properties[0] / 9);\r\n  int lp = remainder % 5;\r\n  int pb = remainder / 5;\r\n  UInt32 dictionarySize = 0;\r\n  for (int i = 0; i < 4; i++)\r\n    dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n  return SetDecoderPropertiesRaw(lc, lp, pb, dictionarySize);\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderPropertiesRaw(int lc, int lp, int pb, UInt32 dictionarySize)\r\n{\r\n  if (pb > NLength::kNumPosStatesBitsMax)\r\n    return E_INVALIDARG;\r\n  _posStateMask = (1 << pb) - 1;\r\n  if (!_outWindowStream.Create(dictionarySize))\r\n    return E_OUTOFMEMORY;\r\n  if (!_literalDecoder.Create(lp, lc))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = _rangeDecoder.GetProcessedSize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _rangeDecoder.SetStream(inStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::ReleaseInStream()\r\n{\r\n  _rangeDecoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  if (_outSizeDefined = (outSize != NULL))\r\n    _outSize = *outSize;\r\n  _remainLen = kLenIdNeedInit;\r\n  _outWindowStream.Init();\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _ST_MODE\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  const UInt64 startPos = _outWindowStream.GetProcessedSize();\r\n  _outWindowStream.SetMemStream((Byte *)data);\r\n  RINOK(CodeSpec(size));\r\n  if (processedSize)\r\n    *processedSize = (UInt32)(_outWindowStream.GetProcessedSize() - startPos);\r\n  return Flush();\r\n  LZMA_TRY_END\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA/LZMADecoder.h",
    "content": "// LZMA/Decoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/LZOutWindow.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;\r\n\r\nclass CLiteralDecoder2\r\n{\r\n  CMyBitDecoder _decoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _decoders[i].Init();\r\n  }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n      RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, Byte matchByte)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      UInt32 matchBit = (matchByte >> 7) & 1;\r\n      matchByte <<= 1;\r\n      // UInt32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);\r\n      // symbol = (symbol << 1) | bit;\r\n      UInt32 bit;\r\n      RC_GETBIT2(kNumMoveBits, _decoders[0x100 + (matchBit << 8) + symbol].Prob, symbol, \r\n          bit = 0, bit = 1)\r\n      if (matchBit != bit)\r\n      {\r\n        while (symbol < 0x100)\r\n        {\r\n          // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n          RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n        }\r\n        break;\r\n      }\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n};\r\n\r\nclass CLiteralDecoder\r\n{\r\n  CLiteralDecoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralDecoder(): _coders(0) {}\r\n  ~CLiteralDecoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte, Byte matchByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CDecoder\r\n{\r\n  CMyBitDecoder _choice;\r\n  CMyBitDecoder _choice2;\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder; \r\npublic:\r\n  void Init(UInt32 numPosStates)\r\n  {\r\n    _choice.Init();\r\n    _choice2.Init();\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n    {\r\n      _lowCoder[posState].Init();\r\n      _midCoder[posState].Init();\r\n    }\r\n    _highCoder.Init();\r\n  }\r\n  UInt32 Decode(NRangeCoder::CDecoder *rangeDecoder, UInt32 posState)\r\n  {\r\n    if(_choice.Decode(rangeDecoder) == 0)\r\n      return _lowCoder[posState].Decode(rangeDecoder);\r\n    if(_choice2.Decode(rangeDecoder) == 0)\r\n      return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);\r\n    return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CDecoder: \r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CLZOutWindow _outWindowStream;\r\n  NRangeCoder::CDecoder _rangeDecoder;\r\n\r\n  CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax];\r\n  CMyBitDecoder _isRep[kNumStates];\r\n  CMyBitDecoder _isRepG0[kNumStates];\r\n  CMyBitDecoder _isRepG1[kNumStates];\r\n  CMyBitDecoder _isRepG2[kNumStates];\r\n  CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax];\r\n\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];\r\n\r\n  CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;\r\n  \r\n  NLength::CDecoder _lenDecoder;\r\n  NLength::CDecoder _repMatchLenDecoder;\r\n\r\n  CLiteralDecoder _literalDecoder;\r\n\r\n  UInt32 _posStateMask;\r\n\r\n  ///////////////////\r\n  // State\r\n  UInt32 _reps[4];\r\n  CState _state;\r\n  Int32 _remainLen; // -1 means end of stream. // -2 means need Init\r\n  UInt64 _outSize;\r\n  bool _outSizeDefined;\r\n\r\n  void Init();\r\n  HRESULT CodeSpec(UInt32 size);\r\npublic:\r\n\r\n  #ifdef _ST_MODE\r\n  MY_UNKNOWN_IMP4(\r\n      ICompressSetDecoderProperties2, \r\n      ICompressSetInStream, \r\n      ICompressSetOutStreamSize, \r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP1(\r\n      ICompressSetDecoderProperties2)\r\n  #endif\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _outWindowStream.ReleaseStream();\r\n    ReleaseInStream();\r\n  }\r\n\r\n  class CDecoderFlusher\r\n  {\r\n    CDecoder *_decoder;\r\n  public:\r\n    bool NeedFlush;\r\n    CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}\r\n    ~CDecoderFlusher() \r\n    { \r\n      if (NeedFlush)\r\n        _decoder->Flush();\r\n      _decoder->ReleaseStreams(); \r\n    }\r\n  };\r\n\r\n  HRESULT Flush() {  return _outWindowStream.Flush(); }  \r\n\r\n  STDMETHOD(CodeReal)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  \r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n  STDMETHOD(SetDecoderPropertiesRaw)(int lc, int lp, int pb, UInt32 dictionarySize);\r\n\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifdef _ST_MODE\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  CDecoder(): _outSizeDefined(false) {}\r\n  virtual ~CDecoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA/LZMAEncoder.cpp",
    "content": "// LZMA/Encoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/Defs.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"LZMAEncoder.h\"\r\n\r\n// for minimal compressing code size define these:\r\n// #define COMPRESS_MF_BT\r\n// #define COMPRESS_MF_BT4\r\n\r\n#if !defined(COMPRESS_MF_BT) && !defined(COMPRESS_MF_PAT) && !defined(COMPRESS_MF_HC)\r\n#define COMPRESS_MF_BT\r\n#define COMPRESS_MF_PAT\r\n#define COMPRESS_MF_HC\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_BT\r\n#if !defined(COMPRESS_MF_BT2) && !defined(COMPRESS_MF_BT3) && !defined(COMPRESS_MF_BT4) && !defined(COMPRESS_MF_BT4B)\r\n#define COMPRESS_MF_BT2\r\n#define COMPRESS_MF_BT3\r\n#define COMPRESS_MF_BT4\r\n#define COMPRESS_MF_BT4B\r\n#endif\r\n#ifdef COMPRESS_MF_BT2\r\n#include \"../LZ/BinTree/BinTree2.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT3\r\n#include \"../LZ/BinTree/BinTree3.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT4\r\n#include \"../LZ/BinTree/BinTree4.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT4B\r\n#include \"../LZ/BinTree/BinTree4b.h\"\r\n#endif\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_PAT\r\n#include \"../LZ/Patricia/Pat2.h\"\r\n#include \"../LZ/Patricia/Pat2H.h\"\r\n#include \"../LZ/Patricia/Pat3H.h\"\r\n#include \"../LZ/Patricia/Pat4H.h\"\r\n#include \"../LZ/Patricia/Pat2R.h\"\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_HC\r\n#include \"../LZ/HashChain/HC3.h\"\r\n#include \"../LZ/HashChain/HC4.h\"\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../LZ/MT/MT.h\"\r\n#endif\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kDefaultDictionaryLogSize = 20;\r\nconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\nenum \r\n{\r\n  kBT2,\r\n  kBT3,\r\n  kBT4,\r\n  kBT4B,\r\n  kPat2,\r\n  kPat2H,\r\n  kPat3H,\r\n  kPat4H,\r\n  kPat2R,\r\n  kHC3,\r\n  kHC4\r\n};\r\n\r\nstatic const wchar_t *kMatchFinderIDs[] = \r\n{\r\n  L\"BT2\",\r\n  L\"BT3\",\r\n  L\"BT4\",\r\n  L\"BT4B\",\r\n  L\"PAT2\",\r\n  L\"PAT2H\",\r\n  L\"PAT3H\",\r\n  L\"PAT4H\",\r\n  L\"PAT2R\",\r\n  L\"HC3\",\r\n  L\"HC4\"\r\n};\r\n\r\nByte g_FastPos[1024];\r\n\r\nclass CFastPosInit\r\n{\r\npublic:\r\n  CFastPosInit() { Init(); }\r\n  void Init()\r\n  {\r\n    const Byte kFastSlots = 20;\r\n    int c = 2;\r\n    g_FastPos[0] = 0;\r\n    g_FastPos[1] = 1;\r\n\r\n    for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n    {\r\n      UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n      for (UInt32 j = 0; j < k; j++, c++)\r\n        g_FastPos[c] = slotFast;\r\n    }\r\n  }\r\n} g_FastPosInit;\r\n\r\n\r\nvoid CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    _encoders[context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nvoid CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, \r\n    Byte matchByte, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    UInt32 matchBit = (matchByte >> i) & 1;\r\n    _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n    if (matchBit != bit)\r\n    {\r\n      while(i != 0)\r\n      {\r\n        i--;\r\n        UInt32 bit = (symbol >> i) & 1;\r\n        _encoders[context].Encode(rangeEncoder, bit);\r\n        context = (context << 1) | bit;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nUInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  if (matchMode)\r\n  {\r\n    do \r\n    {\r\n      i--;\r\n      UInt32 matchBit = (matchByte >> i) & 1;\r\n      UInt32 bit = (symbol >> i) & 1;\r\n      price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit);\r\n      context = (context << 1) | bit;\r\n      if (matchBit != bit)\r\n        break;\r\n    }\r\n    while (i != 0);\r\n  }\r\n  while(i != 0)\r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    price += _encoders[context].GetPrice(bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  return price;\r\n};\r\n\r\n\r\nnamespace NLength {\r\n\r\nvoid CEncoder::Init(UInt32 numPosStates)\r\n{\r\n  _choice.Init();\r\n  _choice2.Init();\r\n  for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n  {\r\n    _lowCoder[posState].Init();\r\n    _midCoder[posState].Init();\r\n  }\r\n  _highCoder.Init();\r\n}\r\n\r\nvoid CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n  {\r\n    _choice.Encode(rangeEncoder, 0);\r\n    _lowCoder[posState].Encode(rangeEncoder, symbol);\r\n  }\r\n  else\r\n  {\r\n    _choice.Encode(rangeEncoder, 1);\r\n    if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n    {\r\n      _choice2.Encode(rangeEncoder, 0);\r\n      _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      _choice2.Encode(rangeEncoder, 1);\r\n      _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 CEncoder::GetPrice(UInt32 symbol, UInt32 posState) const\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n    return _choice.GetPrice0() + _lowCoder[posState].GetPrice(symbol);\r\n  UInt32 price = _choice.GetPrice1();\r\n  if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n  {\r\n    price += _choice2.GetPrice0();\r\n    price += _midCoder[posState].GetPrice(symbol - kNumLowSymbols);\r\n  }\r\n  else\r\n  {\r\n    price += _choice2.GetPrice1();\r\n    price += _highCoder.GetPrice(symbol - kNumLowSymbols - kNumMidSymbols);\r\n  }\r\n  return price;\r\n}\r\n\r\n}\r\nCEncoder::CEncoder():\r\n  _numFastBytes(kNumFastBytesDefault),\r\n  _distTableSize(kDefaultDictionaryLogSize * 2),\r\n  _posStateBits(2),\r\n  _posStateMask(4 - 1),\r\n  _numLiteralPosStateBits(0),\r\n  _numLiteralContextBits(3),\r\n  _dictionarySize(1 << kDefaultDictionaryLogSize),\r\n  _dictionarySizePrev(UInt32(-1)),\r\n  _numFastBytesPrev(UInt32(-1)),\r\n  _matchFinderIndex(kBT4),\r\n   #ifdef COMPRESS_MF_MT\r\n  _multiThread(false),\r\n   #endif\r\n  _writeEndMark(false)\r\n{\r\n  _maxMode = false;\r\n  _fastMode = false;\r\n}\r\n\r\nHRESULT CEncoder::Create()\r\n{\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_matchFinder)\r\n  {\r\n    switch(_matchFinderIndex)\r\n    {\r\n      #ifdef COMPRESS_MF_BT\r\n      #ifdef COMPRESS_MF_BT2\r\n      case kBT2:\r\n        _matchFinder = new NBT2::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT3\r\n      case kBT3:\r\n        _matchFinder = new NBT3::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT4\r\n      case kBT4:\r\n        _matchFinder = new NBT4::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT4B\r\n      case kBT4B:\r\n        _matchFinder = new NBT4B::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #endif\r\n      \r\n      #ifdef COMPRESS_MF_PAT\r\n      case kPat2:\r\n        _matchFinder = new NPat2::CPatricia;\r\n        break;\r\n      case kPat2H:\r\n        _matchFinder = new NPat2H::CPatricia;\r\n        break;\r\n      case kPat3H:\r\n        _matchFinder = new NPat3H::CPatricia;\r\n        break;\r\n      case kPat4H:\r\n        _matchFinder = new NPat4H::CPatricia;\r\n        break;\r\n      case kPat2R:\r\n        _matchFinder = new NPat2R::CPatricia;\r\n        break;\r\n      #endif\r\n\r\n      #ifdef COMPRESS_MF_HC\r\n      case kHC3:\r\n        _matchFinder = new NHC3::CMatchFinderHC;\r\n        break;\r\n      case kHC4:\r\n        _matchFinder = new NHC4::CMatchFinderHC;\r\n        break;\r\n      #endif\r\n    }\r\n    if (_matchFinder == 0)\r\n      return E_OUTOFMEMORY;\r\n\r\n    #ifdef COMPRESS_MF_MT\r\n    if (_multiThread && !(_fastMode && (_matchFinderIndex == kHC3 || _matchFinderIndex == kHC4)))\r\n    {\r\n      CMatchFinderMT *mfSpec = new CMatchFinderMT;\r\n      if (mfSpec == 0)\r\n        return E_OUTOFMEMORY;\r\n      CMyComPtr<IMatchFinder> mf = mfSpec;\r\n      RINOK(mfSpec->SetMatchFinder(_matchFinder));\r\n      _matchFinder.Release();\r\n      _matchFinder = mf;\r\n    }\r\n    #endif\r\n  }\r\n  \r\n  if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))\r\n    return E_OUTOFMEMORY;\r\n\r\n  if (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n    return S_OK;\r\n  RINOK(_matchFinder->Create(_dictionarySize, kNumOpts, _numFastBytes, \r\n      kMatchMaxLen * 2 + 1 - _numFastBytes));\r\n  _dictionarySizePrev = _dictionarySize;\r\n  _numFastBytesPrev = _numFastBytes;\r\n  return S_OK;\r\n}\r\n\r\nstatic bool AreStringsEqual(const wchar_t *base, const wchar_t *testString)\r\n{\r\n  while (true)\r\n  {\r\n    wchar_t c = *testString;\r\n    if (c >= 'a' && c <= 'z')\r\n      c -= 0x20;\r\n    if (*base != c)\r\n      return false;\r\n    if (c == 0)\r\n      return true;\r\n    base++;\r\n    testString++;\r\n  }\r\n}\r\n\r\nstatic int FindMatchFinder(const wchar_t *s)\r\n{\r\n  for (int m = 0; m < (int)(sizeof(kMatchFinderIDs) / sizeof(kMatchFinderIDs[0])); m++)\r\n    if (AreStringsEqual(kMatchFinderIDs[m], s))\r\n      return m;\r\n  return -1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, \r\n    const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  for (UInt32 i = 0; i < numProperties; i++)\r\n  {\r\n    const PROPVARIANT &prop = properties[i];\r\n    switch(propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 numFastBytes = prop.ulVal;\r\n        if(numFastBytes < 5 || numFastBytes > kMatchMaxLen)\r\n          return E_INVALIDARG;\r\n        _numFastBytes = numFastBytes;\r\n        break;\r\n      }\r\n      case NCoderPropID::kAlgorithm:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 maximize = prop.ulVal;\r\n        _fastMode = (maximize == 0); \r\n        _maxMode = (maximize >= 2);\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinder:\r\n      {\r\n        if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        int matchFinderIndexPrev = _matchFinderIndex;\r\n        int m = FindMatchFinder(prop.bstrVal);\r\n        if (m < 0)\r\n          return E_INVALIDARG;\r\n        _matchFinderIndex = m;\r\n        if (_matchFinder && matchFinderIndexPrev != _matchFinderIndex)\r\n        {\r\n          _dictionarySizePrev = UInt32(-1);\r\n          _matchFinder.Release();\r\n        }\r\n        break;\r\n      }\r\n      #ifdef COMPRESS_MF_MT\r\n      case NCoderPropID::kMultiThread:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        bool newMultiThread = (prop.boolVal == VARIANT_TRUE);\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          _dictionarySizePrev = UInt32(-1);\r\n          _matchFinder.Release();\r\n        }\r\n        _multiThread = newMultiThread;\r\n        break;\r\n      }\r\n      #endif\r\n      case NCoderPropID::kDictionarySize:\r\n      {\r\n        const int kDicLogSizeMaxCompress = 28;\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 dictionarySize = prop.ulVal;\r\n        if (dictionarySize < UInt32(1 << kDicLogSizeMin) ||\r\n            dictionarySize > UInt32(1 << kDicLogSizeMaxCompress))\r\n          return E_INVALIDARG;\r\n        _dictionarySize = dictionarySize;\r\n        UInt32 dicLogSize;\r\n        for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n          if (dictionarySize <= (UInt32(1) << dicLogSize))\r\n            break;\r\n        _distTableSize = dicLogSize * 2;\r\n        break;\r\n      }\r\n      case NCoderPropID::kPosStateBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _posStateBits = value;\r\n        _posStateMask = (1 << _posStateBits) - 1;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitPosBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralPosStateBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitContextBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitContextBitsMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralContextBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kEndMarker:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE);\r\n        break;\r\n      }\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{ \r\n  const UInt32 kPropSize = 5;\r\n  Byte properties[kPropSize];\r\n  properties[0] = (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits;\r\n  for (int i = 0; i < 4; i++)\r\n    properties[1 + i] = Byte(_dictionarySize >> (8 * i));\r\n  return WriteStream(outStream, properties, kPropSize, NULL);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _rangeEncoder.SetStream(outStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _rangeEncoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Init()\r\n{\r\n  CBaseState::Init();\r\n\r\n  // RINOK(_matchFinder->Init(inStream));\r\n  _rangeEncoder.Init();\r\n\r\n  for(int i = 0; i < kNumStates; i++)\r\n  {\r\n    for (UInt32 j = 0; j <= _posStateMask; j++)\r\n    {\r\n      _isMatch[i][j].Init();\r\n      _isRep0Long[i][j].Init();\r\n    }\r\n    _isRep[i].Init();\r\n    _isRepG0[i].Init();\r\n    _isRepG1[i].Init();\r\n    _isRepG2[i].Init();\r\n  }\r\n\r\n  _literalEncoder.Init();\r\n\r\n  // _repMatchLenEncoder.Init();\r\n  \r\n  {\r\n    for(UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n      _posSlotEncoder[i].Init();\r\n  }\r\n  {\r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posEncoders[i].Init();\r\n  }\r\n\r\n  _lenEncoder.Init(1 << _posStateBits);\r\n  _repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n  _posAlignEncoder.Init();\r\n\r\n  _longestMatchWasFound = false;\r\n  _optimumEndIndex = 0;\r\n  _optimumCurrentIndex = 0;\r\n  _additionalOffset = 0;\r\n\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::MovePos(UInt32 num)\r\n{\r\n  for (;num != 0; num--)\r\n  {\r\n    _matchFinder->DummyLongestMatch();\r\n    RINOK(_matchFinder->MovePos());\r\n    _additionalOffset++;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nUInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)\r\n{\r\n  _optimumEndIndex = cur;\r\n  UInt32 posMem = _optimum[cur].PosPrev;\r\n  UInt32 backMem = _optimum[cur].BackPrev;\r\n  do\r\n  {\r\n    if (_optimum[cur].Prev1IsChar)\r\n    {\r\n      _optimum[posMem].MakeAsChar();\r\n      _optimum[posMem].PosPrev = posMem - 1;\r\n      if (_optimum[cur].Prev2)\r\n      {\r\n        _optimum[posMem - 1].Prev1IsChar = false;\r\n        _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n        _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n      }\r\n    }\r\n    UInt32 posPrev = posMem;\r\n    UInt32 backCur = backMem;\r\n\r\n    backMem = _optimum[posPrev].BackPrev;\r\n    posMem = _optimum[posPrev].PosPrev;\r\n\r\n    _optimum[posPrev].BackPrev = backCur;\r\n    _optimum[posPrev].PosPrev = cur;\r\n    cur = posPrev;\r\n  }\r\n  while(cur != 0);\r\n  backRes = _optimum[0].BackPrev;\r\n  _optimumCurrentIndex  = _optimum[0].PosPrev;\r\n  return _optimumCurrentIndex; \r\n}\r\n\r\n/*\r\ninline UInt32 GetMatchLen(const Byte *data, UInt32 back, UInt32 limit)\r\n{  \r\n  back++;\r\n  for(UInt32 i = 0; i < limit && data[i] == data[i - back]; i++);\r\n  return i;\r\n}\r\n*/\r\n\r\n\r\n/*\r\nOut:\r\n  (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal\r\n*/\r\n\r\nHRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\r\n{\r\n  if(_optimumEndIndex != _optimumCurrentIndex)\r\n  {\r\n    const COptimal &optimum = _optimum[_optimumCurrentIndex];\r\n    lenRes = optimum.PosPrev - _optimumCurrentIndex;\r\n    backRes = optimum.BackPrev;\r\n    _optimumCurrentIndex = optimum.PosPrev;\r\n    return S_OK;\r\n  }\r\n  _optimumCurrentIndex = 0;\r\n  _optimumEndIndex = 0; // test it;\r\n  \r\n  UInt32 lenMain;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    RINOK(ReadMatchDistances(lenMain));\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n\r\n  UInt32 reps[kNumRepDistances];\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  UInt32 i;\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    reps[i] = _repDistances[i];\r\n    repLens[i] = _matchFinder->GetMatchLen(0 - 1, reps[i], kMatchMaxLen);\r\n    if (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    return MovePos(lenRes - 1);\r\n  }\r\n\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = _matchDistances[_numFastBytes] + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 1);\r\n  }\r\n  Byte currentByte = _matchFinder->GetIndexByte(0 - 1);\r\n\r\n  _optimum[0].State = _state;\r\n\r\n  Byte matchByte;\r\n  \r\n  matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n  UInt32 posState = (position & _posStateMask);\r\n\r\n  _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() + \r\n      _literalEncoder.GetPrice(position, _previousByte, !_state.IsCharState(), matchByte, currentByte);\r\n  _optimum[1].MakeAsChar();\r\n\r\n  _optimum[1].PosPrev = 0;\r\n\r\n  for (i = 0; i < kNumRepDistances; i++)\r\n    _optimum[0].Backs[i] = reps[i];\r\n\r\n  UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1();\r\n  UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n  if(matchByte == currentByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n    if(shortRepPrice < _optimum[1].Price)\r\n    {\r\n      _optimum[1].Price = shortRepPrice;\r\n      _optimum[1].MakeAsShortRep();\r\n    }\r\n  }\r\n  if(lenMain < 2)\r\n  {\r\n    backRes = _optimum[1].BackPrev;\r\n    lenRes = 1;\r\n    return S_OK;\r\n  }\r\n\r\n  \r\n  UInt32 normalMatchPrice = matchPrice + \r\n      _isRep[_state.Index].GetPrice0();\r\n\r\n  if (lenMain <= repLens[repMaxIndex])\r\n    lenMain = 0;\r\n\r\n  UInt32 len;\r\n  for(len = 2; len <= lenMain; len++)\r\n  {\r\n    _optimum[len].PosPrev = 0;\r\n    _optimum[len].BackPrev = _matchDistances[len] + kNumRepDistances;\r\n    _optimum[len].Price = normalMatchPrice + \r\n        GetPosLenPrice(_matchDistances[len], len, posState);\r\n    _optimum[len].Prev1IsChar = false;\r\n  }\r\n\r\n  if (lenMain < repLens[repMaxIndex])\r\n    lenMain = repLens[repMaxIndex];\r\n\r\n  for (; len <= lenMain; len++)\r\n    _optimum[len].Price = kIfinityPrice;\r\n\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    for(UInt32 lenTest = 2; lenTest <= repLen; lenTest++)\r\n    {\r\n      UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\r\n      COptimal &optimum = _optimum[lenTest];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = i;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n    }\r\n  }\r\n\r\n  UInt32 cur = 0;\r\n  UInt32 lenEnd = lenMain;\r\n\r\n  while(true)\r\n  {\r\n    cur++;\r\n    if(cur == lenEnd)\r\n    {\r\n      lenRes = Backward(backRes, cur);\r\n      return S_OK;\r\n    }\r\n    position++;\r\n    COptimal &curOptimum = _optimum[cur];\r\n    UInt32 posPrev = curOptimum.PosPrev;\r\n    CState state;\r\n    if (curOptimum.Prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOptimum.Prev2)\r\n      {\r\n        state = _optimum[curOptimum.PosPrev2].State;\r\n        if (curOptimum.BackPrev2 < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      else\r\n        state = _optimum[posPrev].State;\r\n      state.UpdateChar();\r\n    }\r\n    else\r\n      state = _optimum[posPrev].State;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (curOptimum.IsShortRep())\r\n        state.UpdateShortRep();\r\n      else\r\n        state.UpdateChar();\r\n      /*\r\n      if (curOptimum.Prev1IsChar)\r\n        for(int i = 0; i < kNumRepDistances; i++)\r\n          reps[i] = _optimum[posPrev].Backs[i];\r\n      */\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      if (curOptimum.Prev1IsChar && curOptimum.Prev2)\r\n      {\r\n        posPrev = curOptimum.PosPrev2;\r\n        pos = curOptimum.BackPrev2;\r\n        state.UpdateRep();\r\n      }\r\n      else\r\n      {\r\n        pos = curOptimum.BackPrev;\r\n        if (pos < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      const COptimal &prevOptimum = _optimum[posPrev];\r\n      if (pos < kNumRepDistances)\r\n      {\r\n        reps[0] = prevOptimum.Backs[pos];\r\n    \t\tUInt32 i;\r\n        for(i = 1; i <= pos; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n        for(; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i];\r\n      }\r\n      else\r\n      {\r\n        reps[0] = (pos - kNumRepDistances);\r\n        for(UInt32 i = 1; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n      }\r\n    }\r\n    curOptimum.State = state;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n      curOptimum.Backs[i] = reps[i];\r\n    UInt32 newLen;\r\n    RINOK(ReadMatchDistances(newLen));\r\n    if(newLen >= _numFastBytes)\r\n    {\r\n      _longestMatchLength = newLen;\r\n      _longestMatchWasFound = true;\r\n      lenRes = Backward(backRes, cur);\r\n      return S_OK;\r\n    }\r\n    UInt32 curPrice = curOptimum.Price; \r\n    // Byte currentByte  = _matchFinder->GetIndexByte(0 - 1);\r\n    // Byte matchByte = _matchFinder->GetIndexByte(0 - reps[0] - 1 - 1);\r\n    const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;\r\n    Byte currentByte = *data;\r\n    Byte matchByte = data[(size_t)0 - reps[0] - 1];\r\n\r\n    UInt32 posState = (position & _posStateMask);\r\n\r\n    UInt32 curAnd1Price = curPrice +\r\n        _isMatch[state.Index][posState].GetPrice0() +\r\n        _literalEncoder.GetPrice(position, data[(size_t)0 - 1], !state.IsCharState(), matchByte, currentByte);\r\n\r\n    COptimal &nextOptimum = _optimum[cur + 1];\r\n\r\n    bool nextIsChar = false;\r\n    if (curAnd1Price < nextOptimum.Price) \r\n    {\r\n      nextOptimum.Price = curAnd1Price;\r\n      nextOptimum.PosPrev = cur;\r\n      nextOptimum.MakeAsChar();\r\n      nextIsChar = true;\r\n    }\r\n\r\n    UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();\r\n    UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n    \r\n    if(matchByte == currentByte &&\r\n        !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n      if(shortRepPrice <= nextOptimum.Price)\r\n      {\r\n        nextOptimum.Price = shortRepPrice;\r\n        nextOptimum.PosPrev = cur;\r\n        nextOptimum.MakeAsShortRep();\r\n        // nextIsChar = false;\r\n      }\r\n    }\r\n    /*\r\n    if(newLen == 2 && _matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n      continue;\r\n    */\r\n\r\n    UInt32 numAvailableBytesFull = _matchFinder->GetNumAvailableBytes() + 1;\r\n    numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n    UInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n    if (numAvailableBytes < 2)\r\n      continue;\r\n    if (numAvailableBytes > _numFastBytes)\r\n      numAvailableBytes = _numFastBytes;\r\n    if (numAvailableBytes >= 3 && !nextIsChar)\r\n    {\r\n      // try Literal + rep0\r\n      UInt32 backOffset = reps[0] + 1;\r\n      UInt32 temp;\r\n      for (temp = 1; temp < numAvailableBytes; temp++)\r\n        if (data[temp] != data[(size_t)temp - backOffset])\r\n          break;\r\n      UInt32 lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        CState state2 = state;\r\n        state2.UpdateChar();\r\n        UInt32 posStateNext = (position + 1) & _posStateMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price + \r\n            _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n            _isRep[state2.Index].GetPrice1();\r\n        // for (; lenTest2 >= 2; lenTest2--)\r\n        {\r\n          while(lenEnd < cur + 1 + lenTest2)\r\n            _optimum[++lenEnd].Price = kIfinityPrice;\r\n          UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n              0, lenTest2, state2, posStateNext);\r\n          COptimal &optimum = _optimum[cur + 1 + lenTest2];\r\n          if (curAndLenPrice < optimum.Price) \r\n          {\r\n            optimum.Price = curAndLenPrice;\r\n            optimum.PosPrev = cur + 1;\r\n            optimum.BackPrev = 0;\r\n            optimum.Prev1IsChar = true;\r\n            optimum.Prev2 = false;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)\r\n    {\r\n      // UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n      UInt32 backOffset = reps[repIndex] + 1;\r\n      if (data[0] != data[(size_t)0 - backOffset] ||\r\n          data[1] != data[(size_t)1 - backOffset])\r\n        continue;\r\n      UInt32 lenTest;\r\n      for (lenTest = 2; lenTest < numAvailableBytes; lenTest++)\r\n        if (data[lenTest] != data[(size_t)lenTest - backOffset])\r\n          break;\r\n      UInt32 lenTestTemp = lenTest;\r\n      do\r\n      {\r\n        while(lenEnd < cur + lenTest)\r\n          _optimum[++lenEnd].Price = kIfinityPrice;\r\n        UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = repIndex;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n      }\r\n      while(--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n\r\n        if (_maxMode)\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit; lenTest2++)\r\n            if (data[lenTest2] != data[(size_t)lenTest2 - backOffset])\r\n              break;\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateRep();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = \r\n                repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1], \r\n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice1();\r\n            UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = lenTest + 1 + lenTest2;\r\n              while(lenEnd < cur + offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[cur + offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    \r\n    //    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n    if (newLen > numAvailableBytes)\r\n      newLen = numAvailableBytes;\r\n    if (newLen >= 2)\r\n    {\r\n      if (newLen == 2 && _matchDistances[2] >= 0x80)\r\n        continue;\r\n      UInt32 normalMatchPrice = matchPrice + \r\n        _isRep[state.Index].GetPrice0();\r\n      while(lenEnd < cur + newLen)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n      for(UInt32 lenTest = newLen; lenTest >= 2; lenTest--)\r\n      {\r\n        UInt32 curBack = _matchDistances[lenTest];\r\n        UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = curBack + kNumRepDistances;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n\r\n        if (_maxMode && (lenTest == newLen || curBack != _matchDistances[lenTest + 1]))\r\n        {\r\n          // Try Match + Literal + Rep0\r\n          UInt32 backOffset = curBack + 1;\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit; lenTest2++)\r\n            if (data[lenTest2] != data[(size_t)lenTest2 - backOffset])\r\n              break;\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateMatch();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1], \r\n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice1();\r\n            UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = lenTest + 1 + lenTest2;\r\n              while(lenEnd < cur + offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[cur + offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = curBack + kNumRepDistances;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n{\r\n  const int kDif = 7;\r\n  return (smallDist < (UInt32(1) << (32-kDif)) && bigDist >= (smallDist << kDif));\r\n}\r\n\r\n\r\nHRESULT CEncoder::ReadMatchDistances(UInt32 &lenRes)\r\n{\r\n  lenRes = _matchFinder->GetLongestMatch(_matchDistances);\r\n  if (lenRes == _numFastBytes)\r\n    lenRes += _matchFinder->GetMatchLen(lenRes, _matchDistances[lenRes], \r\n        kMatchMaxLen - lenRes);\r\n  _additionalOffset++;\r\n  return _matchFinder->MovePos();\r\n}\r\n\r\nHRESULT CEncoder::GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\r\n{\r\n  UInt32 lenMain;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    RINOK(ReadMatchDistances(lenMain));\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    _longestMatchWasFound = false;\r\n  }\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    repLens[i] = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);\r\n    if (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    return MovePos(lenRes - 1);\r\n  }\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = _matchDistances[_numFastBytes] + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 1);\r\n  }\r\n  while (lenMain > 2)\r\n  {\r\n    if (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\r\n      break;\r\n    lenMain--;\r\n  }\r\n  if (lenMain == 2 && _matchDistances[2] >= 0x80)\r\n    lenMain = 1;\r\n\r\n  UInt32 backMain = _matchDistances[lenMain];\r\n  if (repLens[repMaxIndex] >= 2)\r\n  {\r\n    if (repLens[repMaxIndex] + 1 >= lenMain || \r\n        repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1<<12)))\r\n    {\r\n      backRes = repMaxIndex;\r\n      lenRes = repLens[repMaxIndex];\r\n      return MovePos(lenRes - 1);\r\n    }\r\n  }\r\n  \r\n\r\n  if (lenMain >= 2)\r\n  {\r\n    RINOK(ReadMatchDistances(_longestMatchLength));\r\n    if (_longestMatchLength >= 2 &&\r\n      (\r\n        (_longestMatchLength >= lenMain && _matchDistances[lenMain] < backMain) || \r\n        _longestMatchLength == lenMain + 1 && \r\n          !ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\r\n        _longestMatchLength > lenMain + 1 ||\r\n        _longestMatchLength + 1 >= lenMain && lenMain >= 3 &&\r\n          ChangePair(_matchDistances[lenMain - 1], backMain)\r\n      )\r\n      )\r\n    {\r\n      _longestMatchWasFound = true;\r\n      backRes = UInt32(-1);\r\n      lenRes = 1;\r\n      return S_OK;\r\n    }\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n    {\r\n      UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);\r\n      if (repLen >= 2 && repLen + 1 >= lenMain)\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        lenRes = 1;\r\n        return S_OK;\r\n      }\r\n    }\r\n    backRes = backMain + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 2);\r\n  }\r\n  backRes = UInt32(-1);\r\n  lenRes = 1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::InitMatchFinder(IMatchFinder *matchFinder)\r\n{\r\n  _matchFinder = matchFinder;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Flush(UInt32 nowPos)\r\n{\r\n  ReleaseMFStream();\r\n  WriteEndMarker(nowPos & _posStateMask);\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nvoid CEncoder::WriteEndMarker(UInt32 posState)\r\n{\r\n  // This function for writing End Mark for stream version of LZMA. \r\n  // In current version this feature is not used.\r\n  if (!_writeEndMark)\r\n    return;\r\n\r\n  _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n  _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n  _state.UpdateMatch();\r\n  UInt32 len = kMatchMinLen; // kMatchMaxLen;\r\n  _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\r\n  UInt32 posSlot = (1 << kNumPosSlotBits)  - 1;\r\n  UInt32 lenToPosState = GetLenToPosState(len);\r\n  _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n  UInt32 footerBits = 30;\r\n  UInt32 posReduced = (UInt32(1) << footerBits) - 1;\r\n  _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n  _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n}\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  _needReleaseMFStream = false;\r\n  CCoderReleaser coderReleaser(this);\r\n  RINOK(SetStreams(inStream, outStream, inSize, outSize));\r\n  while(true)\r\n  {\r\n    UInt64 processedInSize;\r\n    UInt64 processedOutSize;\r\n    Int32 finished;\r\n    RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished));\r\n    if (finished != 0)\r\n      return S_OK;\r\n    if (progress != 0)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize));\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CEncoder::SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  _inStream = inStream;\r\n  _finished = false;\r\n  RINOK(Create());\r\n  RINOK(SetOutStream(outStream));\r\n  RINOK(Init());\r\n  \r\n  // CCoderReleaser releaser(this);\r\n\r\n  /*\r\n  if (_matchFinder->GetNumAvailableBytes() == 0)\r\n    return Flush();\r\n  */\r\n\r\n  if (!_fastMode)\r\n  {\r\n    FillPosSlotPrices();\r\n    FillDistancesPrices();\r\n    FillAlignPrices();\r\n  }\r\n\r\n  _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _lenEncoder.UpdateTables(1 << _posStateBits);\r\n  _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n  lastPosSlotFillingPos = 0;\r\n  nowPos64 = 0;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)\r\n{\r\n  if (_inStream != 0)\r\n  {\r\n    RINOK(_matchFinder->Init(_inStream));\r\n    _needReleaseMFStream = true;\r\n    _inStream = 0;\r\n  }\r\n\r\n\r\n  *finished = 1;\r\n  if (_finished)\r\n    return S_OK;\r\n  _finished = true;\r\n\r\n\r\n  UInt64 progressPosValuePrev = nowPos64;\r\n  if (nowPos64 == 0)\r\n  {\r\n    if (_matchFinder->GetNumAvailableBytes() == 0)\r\n      return Flush(UInt32(nowPos64));\r\n    UInt32 len; // it's not used\r\n    RINOK(ReadMatchDistances(len));\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n    _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n    _state.UpdateChar();\r\n    Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\r\n    _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte);\r\n    _previousByte = curByte;\r\n    _additionalOffset--;\r\n    nowPos64++;\r\n  }\r\n  if (_matchFinder->GetNumAvailableBytes() == 0)\r\n    return Flush(UInt32(nowPos64));\r\n  while(true)\r\n  {\r\n    #ifdef _NO_EXCEPTIONS\r\n    if (_rangeEncoder.Stream.ErrorCode != S_OK)\r\n      return _rangeEncoder.Stream.ErrorCode;\r\n    #endif\r\n    UInt32 pos;\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n\r\n    UInt32 len;\r\n    HRESULT result;\r\n    if (_fastMode)\r\n      result = GetOptimumFast(UInt32(nowPos64), pos, len);\r\n    else\r\n      result = GetOptimum(UInt32(nowPos64), pos, len);\r\n    RINOK(result);\r\n\r\n    if(len == 1 && pos == 0xFFFFFFFF)\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n      Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\r\n      CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte);\r\n      if(!_state.IsCharState())\r\n      {\r\n        Byte matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - _additionalOffset);\r\n        subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);\r\n      }\r\n      else\r\n        subCoder->Encode(&_rangeEncoder, curByte);\r\n      _state.UpdateChar();\r\n      _previousByte = curByte;\r\n    }\r\n    else\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n      if(pos < kNumRepDistances)\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 1);\r\n        if(pos == 0)\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 0);\r\n          if(len == 1)\r\n            _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n          else\r\n            _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n        }\r\n        else\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 1);\r\n          if (pos == 1)\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 0);\r\n          else\r\n          {\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 1);\r\n            _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);\r\n          }\r\n        }\r\n        if (len == 1)\r\n          _state.UpdateShortRep();\r\n        else\r\n        {\r\n          _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\r\n          _state.UpdateRep();\r\n        }\r\n\r\n\r\n        UInt32 distance = _repDistances[pos];\r\n        if (pos != 0)\r\n        {\r\n          for(UInt32 i = pos; i >= 1; i--)\r\n            _repDistances[i] = _repDistances[i - 1];\r\n          _repDistances[0] = distance;\r\n        }\r\n      }\r\n      else\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n        _state.UpdateMatch();\r\n        _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\r\n        pos -= kNumRepDistances;\r\n        UInt32 posSlot = GetPosSlot(pos);\r\n        UInt32 lenToPosState = GetLenToPosState(len);\r\n        _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1, \r\n                &_rangeEncoder, footerBits, posReduced);\r\n          else\r\n          {\r\n            _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n            if (!_fastMode)\r\n              if (--_alignPriceCount == 0)\r\n                FillAlignPrices();\r\n          }\r\n        }\r\n        UInt32 distance = pos;\r\n        for(UInt32 i = kNumRepDistances - 1; i >= 1; i--)\r\n          _repDistances[i] = _repDistances[i - 1];\r\n        _repDistances[0] = distance;\r\n      }\r\n      _previousByte = _matchFinder->GetIndexByte(len - 1 - _additionalOffset);\r\n    }\r\n    _additionalOffset -= len;\r\n    nowPos64 += len;\r\n    if (!_fastMode)\r\n      if (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\r\n      {\r\n        FillPosSlotPrices();\r\n        FillDistancesPrices();\r\n        lastPosSlotFillingPos = nowPos64;\r\n      }\r\n    if (_additionalOffset == 0)\r\n    {\r\n      *inSize = nowPos64;\r\n      *outSize = _rangeEncoder.GetProcessedSize();\r\n      if (_matchFinder->GetNumAvailableBytes() == 0)\r\n        return Flush(UInt32(nowPos64));\r\n      if (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n      {\r\n        _finished = false;\r\n        *finished = 0;\r\n        return S_OK;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try \r\n  { \r\n  #endif\r\n    return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  #ifndef _NO_EXCEPTIONS\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return E_FAIL; }\r\n  #endif\r\n}\r\n  \r\nvoid CEncoder::FillPosSlotPrices()\r\n{\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n\t  UInt32 posSlot;\r\n    for (posSlot = 0; posSlot < kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\r\n      _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\r\n    for (; posSlot < _distTableSize; posSlot++)\r\n      _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) + \r\n      ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);\r\n  }\r\n}\r\n\r\nvoid CEncoder::FillDistancesPrices()\r\n{\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n\t  UInt32 i;\r\n    for (i = 0; i < kStartPosModelIndex; i++)\r\n      _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][i];\r\n    for (; i < kNumFullDistances; i++)\r\n    { \r\n      UInt32 posSlot = GetPosSlot(i);\r\n      UInt32 footerBits = ((posSlot >> 1) - 1);\r\n      UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n\r\n      _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][posSlot] +\r\n          NRangeCoder::ReverseBitTreeGetPrice(_posEncoders + \r\n              base - posSlot - 1, footerBits, i - base);\r\n            \r\n    }\r\n  }\r\n}\r\n\r\nvoid CEncoder::FillAlignPrices()\r\n{\r\n  for (UInt32 i = 0; i < kAlignTableSize; i++)\r\n    _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n  _alignPriceCount = kAlignTableSize;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA/LZMAEncoder.h",
    "content": "// LZMA/Encoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/IMatchFinder.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;\r\n\r\nclass CBaseState\r\n{\r\nprotected:\r\n  CState _state;\r\n  Byte _previousByte;\r\n  UInt32 _repDistances[kNumRepDistances];\r\n  void Init()\r\n  {\r\n    _state.Init();\r\n    _previousByte = 0;\r\n    for(UInt32 i = 0 ; i < kNumRepDistances; i++)\r\n      _repDistances[i] = 0;\r\n  }\r\n};\r\n\r\nstruct COptimal\r\n{\r\n  CState State;\r\n\r\n  bool Prev1IsChar;\r\n  bool Prev2;\r\n\r\n  UInt32 PosPrev2;\r\n  UInt32 BackPrev2;     \r\n\r\n  UInt32 Price;    \r\n  UInt32 PosPrev;         // posNext;\r\n  UInt32 BackPrev;     \r\n  UInt32 Backs[kNumRepDistances];\r\n  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }\r\n  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n  bool IsShortRep() { return (BackPrev == 0); }\r\n};\r\n\r\n\r\nextern Byte g_FastPos[1024];\r\ninline UInt32 GetPosSlot(UInt32 pos)\r\n{\r\n  if (pos < (1 << 10))\r\n    return g_FastPos[pos];\r\n  if (pos < (1 << 19))\r\n    return g_FastPos[pos >> 9] + 18;\r\n  return g_FastPos[pos >> 18] + 36;\r\n}\r\n\r\ninline UInt32 GetPosSlot2(UInt32 pos)\r\n{\r\n  if (pos < (1 << 16))\r\n    return g_FastPos[pos >> 6] + 12;\r\n  if (pos < (1 << 25))\r\n    return g_FastPos[pos >> 15] + 30;\r\n  return g_FastPos[pos >> 24] + 48;\r\n}\r\n\r\nconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\nconst UInt32 kNumOpts = 1 << 12;\r\n\r\n\r\nclass CLiteralEncoder2\r\n{\r\n  CMyBitEncoder _encoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _encoders[i].Init();\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);\r\n  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;\r\n};\r\n\r\nclass CLiteralEncoder\r\n{\r\n  CLiteralEncoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralEncoder(): _coders(0) {}\r\n  ~CLiteralEncoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)\r\n    { return &_coders[GetState(pos, prevByte)]; }\r\n  /*\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte, \r\n      Byte symbol)\r\n    { _coders[GetState(pos, prevByte)].Encode(rangeEncoder, symbol); }\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte, \r\n      Byte matchByte, Byte symbol)\r\n    { _coders[GetState(pos, prevByte)].Encode(rangeEncoder,\r\n      matchByte, symbol); }\r\n  */\r\n  UInt32 GetPrice(UInt32 pos, Byte prevByte, bool matchMode, Byte matchByte, Byte symbol) const\r\n    { return _coders[GetState(pos, prevByte)].GetPrice(matchMode, matchByte, symbol); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CEncoder\r\n{\r\n  CMyBitEncoder _choice;\r\n  CMyBitEncoder  _choice2;\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits>  _highCoder;\r\npublic:\r\n  void Init(UInt32 numPosStates);\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const;\r\n};\r\n\r\nconst UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\r\n\r\nclass CPriceTableEncoder: public CEncoder\r\n{\r\n  UInt32 _prices[kNumSymbolsTotal][kNumPosStatesEncodingMax];\r\n  UInt32 _tableSize;\r\n  UInt32 _counters[kNumPosStatesEncodingMax];\r\npublic:\r\n  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const\r\n    { return _prices[symbol][posState]; }\r\n  void UpdateTable(UInt32 posState)\r\n  {\r\n    for (UInt32 len = 0; len < _tableSize; len++)\r\n      _prices[len][posState] = CEncoder::GetPrice(len, posState);\r\n    _counters[posState] = _tableSize;\r\n  }\r\n  void UpdateTables(UInt32 numPosStates)\r\n  {\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n      UpdateTable(posState);\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n  {\r\n    CEncoder::Encode(rangeEncoder, symbol, posState);\r\n    if (--_counters[posState] == 0)\r\n      UpdateTable(posState);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CEncoder : \r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CBaseState,\r\n  public CMyUnknownImp\r\n{\r\n  COptimal _optimum[kNumOpts];\r\n  CMyComPtr<IMatchFinder> _matchFinder; // test it\r\n  NRangeCoder::CEncoder _rangeEncoder;\r\n\r\n  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n  CMyBitEncoder _isRep[kNumStates];\r\n  CMyBitEncoder _isRepG0[kNumStates];\r\n  CMyBitEncoder _isRepG1[kNumStates];\r\n  CMyBitEncoder _isRepG2[kNumStates];\r\n  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];\r\n\r\n  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;\r\n  \r\n  NLength::CPriceTableEncoder _lenEncoder;\r\n  NLength::CPriceTableEncoder _repMatchLenEncoder;\r\n\r\n  CLiteralEncoder _literalEncoder;\r\n\r\n  UInt32 _matchDistances[kMatchMaxLen + 1];\r\n\r\n  bool _fastMode;\r\n  bool _maxMode;\r\n  UInt32 _numFastBytes;\r\n  UInt32 _longestMatchLength;    \r\n\r\n  UInt32 _additionalOffset;\r\n\r\n  UInt32 _optimumEndIndex;\r\n  UInt32 _optimumCurrentIndex;\r\n\r\n  bool _longestMatchWasFound;\r\n\r\n  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  \r\n  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n\r\n  UInt32 _alignPrices[kAlignTableSize];\r\n  UInt32 _alignPriceCount;\r\n\r\n  UInt32 _distTableSize;\r\n\r\n  UInt32 _posStateBits;\r\n  UInt32 _posStateMask;\r\n  UInt32 _numLiteralPosStateBits;\r\n  UInt32 _numLiteralContextBits;\r\n\r\n  UInt32 _dictionarySize;\r\n\r\n  UInt32 _dictionarySizePrev;\r\n  UInt32 _numFastBytesPrev;\r\n\r\n  UInt64 lastPosSlotFillingPos;\r\n  UInt64 nowPos64;\r\n  bool _finished;\r\n  ISequentialInStream *_inStream;\r\n\r\n  int _matchFinderIndex;\r\n  #ifdef COMPRESS_MF_MT\r\n  bool _multiThread;\r\n  #endif\r\n\r\n  bool _writeEndMark;\r\n\r\n  bool _needReleaseMFStream;\r\n  \r\n  HRESULT ReadMatchDistances(UInt32 &len);\r\n\r\n  HRESULT MovePos(UInt32 num);\r\n  UInt32 GetRepLen1Price(CState state, UInt32 posState) const\r\n  {\r\n    return _isRepG0[state.Index].GetPrice0() +\r\n        _isRep0Long[state.Index][posState].GetPrice0();\r\n  }\r\n  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const\r\n  {\r\n    UInt32 price = _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n    if(repIndex == 0)\r\n    {\r\n      price += _isRepG0[state.Index].GetPrice0();\r\n      price += _isRep0Long[state.Index][posState].GetPrice1();\r\n    }\r\n    else\r\n    {\r\n      price += _isRepG0[state.Index].GetPrice1();\r\n      if (repIndex == 1)\r\n        price += _isRepG1[state.Index].GetPrice0();\r\n      else\r\n      {\r\n        price += _isRepG1[state.Index].GetPrice1();\r\n        price += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n      }\r\n    }\r\n    return price;\r\n  }\r\n  /*\r\n  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const\r\n  {\r\n    if (pos >= kNumFullDistances)\r\n      return kIfinityPrice;\r\n    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);\r\n  }\r\n  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n  */\r\n  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    if (len == 2 && pos >= 0x80)\r\n      return kIfinityPrice;\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n\r\n  UInt32 Backward(UInt32 &backRes, UInt32 cur);\r\n  HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r\n  HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r\n\r\n  void FillPosSlotPrices();\r\n  void FillDistancesPrices();\r\n  void FillAlignPrices();\r\n    \r\n  void ReleaseMFStream()\r\n  {\r\n    if (_matchFinder && _needReleaseMFStream)\r\n    {\r\n      _matchFinder->ReleaseStream();\r\n      _needReleaseMFStream = false;\r\n    }\r\n  }\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    ReleaseMFStream();\r\n    ReleaseOutStream();\r\n  }\r\n\r\n  HRESULT Flush(UInt32 nowPos);\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()\r\n    {\r\n      _coder->ReleaseStreams();\r\n    }\r\n  };\r\n  friend class CCoderReleaser;\r\n\r\n  void WriteEndMarker(UInt32 posState);\r\n\r\npublic:\r\n  CEncoder();\r\n  void SetWriteEndMarkerMode(bool writeEndMarker)\r\n    { _writeEndMark= writeEndMarker; }\r\n\r\n  HRESULT Create();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  HRESULT Init();\r\n  \r\n  // ICompressCoder interface\r\n  HRESULT SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize);\r\n  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);\r\n\r\n  HRESULT CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressCoder interface\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // IInitMatchFinder interface\r\n  STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder);\r\n\r\n  // ICompressSetCoderProperties2\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  \r\n  // ICompressWriteCoderProperties\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"Pat\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2R.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat3H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat4H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\PatMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"BT\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3Z.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3ZMain.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree4b.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTreeMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"HC\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC3.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC4b.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HCMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\IMatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA_C\\LzmaDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA_C\\LzmaDecode.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"LzmaRamDecode.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kMode,\r\n  kDictionary,\r\n  kFastBytes,\r\n  kLitContext,\r\n  kLitPos,\r\n  kPosBits,\r\n  kMatchFinder,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kSimple, false }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\"\r\n    \"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, bt4b, pat2r, pat2,\\n\"\r\n    \"              pat2h, pat3h, pat4h, hc3, hc4], default: bt4\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[], \r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA 4.32 Copyright (c) 1999-2005 Igor Pavlov  2005-12-09\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  if (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }   \r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++]; \r\n\r\n  bool dictionaryIsDefined = false;\r\n  UInt32 dictionary = 1 << 21;\r\n  if(parser[NKey::kDictionary].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dictionary = 1 << dicLog;\r\n    dictionaryIsDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 10;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchmark(stderr, numIterations, dictionary, \r\n        mf.CompareNoCase(L\"BT4\") == 0);\r\n  }\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++]; \r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\", \r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++]; \r\n    COutFileStream *outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\", \r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    UInt32 inSize = (UInt32)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize); \r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)\r\n      throw \"Can not read\";\r\n    if ((UInt32)inSize != processedSize)\r\n      throw \"Read size error\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSizeProcessed;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictionaryIsDefined)\r\n        dictionary = 1 << 23;\r\n      int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, \r\n          dictionary, SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      size_t outSize;\r\n      if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)\r\n        throw \"data error\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLZMA::CEncoder *encoderSpec = \r\n      new NCompress::NLZMA::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictionaryIsDefined)\r\n      dictionary = 1 << 23;\r\n\r\n    UInt32 posStateBits = 2;\r\n    UInt32 litContextBits = 3; // for normal files\r\n    // UInt32 litContextBits = 0; // for 32-bit data\r\n    UInt32 litPosBits = 0;\r\n    // UInt32 litPosBits = 2; // for 32-bit data\r\n    UInt32 algorithm = 2;\r\n    UInt32 numFastBytes = 128;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    if(parser[NKey::kMode].ThereIs)\r\n      if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))\r\n        IncorrectCommand();\r\n\r\n    if(parser[NKey::kFastBytes].ThereIs)\r\n      if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitContext].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitPos].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kPosBits].ThereIs)\r\n      if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))\r\n        IncorrectCommand();\r\n\r\n    PROPID propIDs[] = \r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker\r\n    };\r\n    const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n    /*\r\n    NWindows::NCOM::CPropVariant properties[kNumProps];\r\n    properties[0] = UInt32(dictionary);\r\n    properties[1] = UInt32(posStateBits);\r\n    properties[2] = UInt32(litContextBits);\r\n   \r\n    properties[3] = UInt32(litPosBits);\r\n    properties[4] = UInt32(algorithm);\r\n    properties[5] = UInt32(numFastBytes);\r\n    properties[6] = mf;\r\n    properties[7] = eos;\r\n    */\r\n    PROPVARIANT properties[kNumProps];\r\n    for (int p = 0; p < 6; p++)\r\n      properties[p].vt = VT_UI4;\r\n    properties[0].ulVal = UInt32(dictionary);\r\n    properties[1].ulVal = UInt32(posStateBits);\r\n    properties[2].ulVal = UInt32(litContextBits);\r\n    properties[3].ulVal = UInt32(litPosBits);\r\n    properties[4].ulVal = UInt32(algorithm);\r\n    properties[5].ulVal = UInt32(numFastBytes);\r\n    \r\n    properties[6].vt = VT_BSTR;\r\n    properties[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    properties[7].vt = VT_BOOL;\r\n    properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }   \r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }   \r\n  }\r\n  else\r\n  {\r\n    NCompress::NLZMA::CDecoder *decoderSpec = \r\n        new NCompress::NLZMA::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte properties[kPropertiesSize];\r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, properties, kPropertiesSize, &processedSize) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (processedSize != kPropertiesSize)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b;\r\n      if (inStream->Read(&b, 1, &processedSize) != S_OK)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      if (processedSize != 1)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      fileSize |= ((UInt64)b) << (8 * i);\r\n    }\r\n    if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }   \r\n  }\r\n  return 0;\r\n}\r\n\r\nint main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s) \r\n  { \r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1; \r\n  }\r\n  catch(...) \r\n  { \r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1; \r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#include <time.h>\r\n#endif\r\n\r\n#include \"../../../Common/CRC.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\nstatic const UInt32 kAdditionalSize = \r\n#ifdef _WIN32_WCE\r\n(1 << 20);\r\n#else\r\n(6 << 20);\r\n#endif\r\n\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 10;\r\n\r\nclass CRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd() \r\n  {\r\n    return \r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBitRandomGenerator\r\n{\r\n  CRandomGenerator RG;\r\n  UInt32 Value;\r\n  int NumBits;\r\npublic:\r\n  void Init()\r\n  {\r\n    Value = 0;\r\n    NumBits = 0;\r\n  }\r\n  UInt32 GetRnd(int numBits) \r\n  {\r\n    if (NumBits > numBits)\r\n    {\r\n      UInt32 result = Value & ((1 << numBits) - 1);\r\n      Value >>= numBits;\r\n      NumBits -= numBits;\r\n      return result;\r\n    }\r\n    numBits -= NumBits;\r\n    UInt32 result = (Value << numBits);\r\n    Value = RG.GetRnd();\r\n    result |= Value & ((1 << numBits) - 1);\r\n    Value >>= numBits;\r\n    NumBits = 32 - numBits;\r\n    return result;\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator\r\n{\r\n  CBitRandomGenerator RG;\r\n  UInt32 Pos;\r\npublic:\r\n  UInt32 BufferSize;\r\n  Byte *Buffer;\r\n  CBenchRandomGenerator(): Buffer(0) {} \r\n  ~CBenchRandomGenerator() { delete []Buffer; }\r\n  void Init() { RG.Init(); }\r\n  void Set(UInt32 bufferSize) \r\n  {\r\n    delete []Buffer;\r\n    Buffer = 0;\r\n    Buffer = new Byte[bufferSize];\r\n    Pos = 0;\r\n    BufferSize = bufferSize;\r\n  }\r\n  UInt32 GetRndBit() { return RG.GetRnd(1); }\r\n  /*\r\n  UInt32 GetLogRand(int maxLen)\r\n  {\r\n    UInt32 len = GetRnd() % (maxLen + 1);\r\n    return GetRnd() & ((1 << len) - 1);\r\n  }\r\n  */\r\n  UInt32 GetLogRandBits(int numBits)\r\n  {\r\n    UInt32 len = RG.GetRnd(numBits);\r\n    return RG.GetRnd(len);\r\n  }\r\n  UInt32 GetOffset()\r\n  {\r\n    if (GetRndBit() == 0)\r\n      return GetLogRandBits(4);\r\n    return (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n  }\r\n  UInt32 GetLen()\r\n  {\r\n    if (GetRndBit() == 0)\r\n      return RG.GetRnd(2);\r\n    if (GetRndBit() == 0)\r\n      return 4 + RG.GetRnd(3);\r\n    return 12 + RG.GetRnd(4);\r\n  }\r\n  void Generate()\r\n  {\r\n    while(Pos < BufferSize)\r\n    {\r\n      if (GetRndBit() == 0 || Pos < 1)\r\n        Buffer[Pos++] = Byte(RG.GetRnd(8));\r\n      else\r\n      {\r\n        UInt32 offset = GetOffset();\r\n        while (offset >= Pos)\r\n          offset >>= 1;\r\n        offset += 1;\r\n        UInt32 len = 2 + GetLen();\r\n        for (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n          Buffer[Pos] = Buffer[Pos - offset];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nclass CBenchmarkInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  UInt32 Pos;\r\n  UInt32 Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, UInt32 size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 remain = Size - Pos;\r\n  if (size > remain)\r\n    size = remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 BufferSize;\r\n  FILE *_f;\r\npublic:\r\n  UInt32 Pos;\r\n  Byte *Buffer;\r\n  CBenchmarkOutStream(): _f(0), Buffer(0) {} \r\n  virtual ~CBenchmarkOutStream() { delete []Buffer; }\r\n  void Init(FILE *f, UInt32 bufferSize) \r\n  {\r\n    delete []Buffer;\r\n    Buffer = 0;\r\n    Buffer = new Byte[bufferSize];\r\n    Pos = 0;\r\n    BufferSize = bufferSize;\r\n    _f = f;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < BufferSize; i++)\r\n    Buffer[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    fprintf(_f, \"\\nERROR: Buffer is full\\n\");\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CCRC CRC;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { CRC.Init(); }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  CRC.Update(data, size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef _WIN32\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  return GetTickCount();\r\n  #else\r\n  return clock();\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef _WIN32\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  return 1000;\r\n  #else\r\n  return CLOCKS_PER_SEC;\r\n  #endif \r\n}\r\n\r\nstruct CProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 ApprovedStart;\r\n  UInt64 InSize;\r\n  UInt64 Time;\r\n  void Init()\r\n  {\r\n    InSize = 0;\r\n    Time = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nSTDMETHODIMP CProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  if (*inSize >= ApprovedStart && InSize == 0)\r\n  {\r\n    Time = ::GetTimeCount();\r\n    InSize = *inSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n{\r\n  UInt64 freq = GetFreq();\r\n  UInt64 elTime = elapsedTime;\r\n  while(freq > 1000000)\r\n  {\r\n    freq >>= 1;\r\n    elTime >>= 1;\r\n  }\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic UInt64 GetCompressRating(UInt32 dictionarySize, bool isBT4,\r\n    UInt64 elapsedTime, UInt64 size)\r\n{\r\n  UInt64 numCommandsForOne;\r\n  if (isBT4)\r\n  {\r\n    UInt64 t = GetLogSize(dictionarySize) - (19 << kSubBits);\r\n    numCommandsForOne = 2000 + ((t * t * 68) >> (2 * kSubBits));\r\n  }\r\n  else\r\n  {\r\n    UInt64 t = GetLogSize(dictionarySize) - (15 << kSubBits);\r\n    numCommandsForOne = 1500 + ((t * t * 41) >> (2 * kSubBits));\r\n  }\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime);\r\n}\r\n\r\nstatic UInt64 GetDecompressRating(UInt64 elapsedTime, \r\n    UInt64 outSize, UInt64 inSize)\r\n{\r\n  UInt64 numCommands = inSize * 250 + outSize * 21;\r\n  return MyMultDiv64(numCommands, elapsedTime);\r\n}\r\n\r\n/*\r\nstatic UInt64 GetTotalRating(\r\n    UInt32 dictionarySize, \r\n    bool isBT4,\r\n    UInt64 elapsedTimeEn, UInt64 sizeEn,\r\n    UInt64 elapsedTimeDe, \r\n    UInt64 inSizeDe, UInt64 outSizeDe)\r\n{\r\n  return (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) + \r\n    GetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n}\r\n*/\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  fprintf(f, \"%5d MIPS\", (unsigned int)(rating / 1000000));\r\n}\r\n\r\nstatic void PrintResults(\r\n    FILE *f, \r\n    UInt32 dictionarySize,\r\n    bool isBT4,\r\n    UInt64 elapsedTime, \r\n    UInt64 size, \r\n    bool decompressMode, UInt64 secondSize)\r\n{\r\n  UInt64 speed = MyMultDiv64(size, elapsedTime);\r\n  fprintf(f, \"%6d KB/s  \", (unsigned int)(speed / 1024));\r\n  UInt64 rating;\r\n  if (decompressMode)\r\n    rating = GetDecompressRating(elapsedTime, size, secondSize);\r\n  else\r\n    rating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\r\n  PrintRating(f, rating);\r\n}\r\n\r\nstatic void ThrowError(FILE *f, HRESULT result, const char *s)\r\n{\r\n  fprintf(f, \"\\nError: \");\r\n  if (result == E_ABORT)\r\n    fprintf(f, \"User break\");\r\n  if (result == E_OUTOFMEMORY)\r\n    fprintf(f, \"Can not allocate memory\");\r\n  else\r\n    fprintf(f, s);\r\n  fprintf(f, \"\\n\");\r\n}\r\n\r\nconst wchar_t *bt2 = L\"BT2\";\r\nconst wchar_t *bt4 = L\"BT4\";\r\n\r\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize, bool isBT4)\r\n{\r\n  if (numIterations == 0)\r\n    return 0;\r\n  if (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\r\n  {\r\n    fprintf(f, \"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\\n\");\r\n    return 1;\r\n  }\r\n  fprintf(f, \"\\n       Compressing                Decompressing\\n\\n\");\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;\r\n  CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n\r\n  CBenchmarkOutStream *propStreamSpec = new CBenchmarkOutStream;\r\n  CMyComPtr<ISequentialOutStream> propStream = propStreamSpec;\r\n  propStreamSpec->Init(f, kMaxLzmaPropSize);\r\n  \r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kMatchFinder  \r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = UInt32(dictionarySize);\r\n\r\n  properties[1].vt = VT_BSTR;\r\n  properties[1].bstrVal = isBT4 ? (BSTR)bt4: (BSTR)bt2;\r\n\r\n  const UInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n  {\r\n    fprintf(f, \"\\nError: Incorrect command\\n\");\r\n    return 1;\r\n  }\r\n  encoderSpec->WriteCoderProperties(propStream);\r\n\r\n  CBenchRandomGenerator rg;\r\n  rg.Init();\r\n  rg.Set(kBufferSize);\r\n  rg.Generate();\r\n  CCRC crc;\r\n  crc.Update(rg.Buffer, rg.BufferSize);\r\n\r\n  CProgressInfo *progressInfoSpec = new CProgressInfo;\r\n  CMyComPtr<ICompressProgressInfo> progressInfo = progressInfoSpec;\r\n\r\n  progressInfoSpec->ApprovedStart = dictionarySize;\r\n\r\n  UInt64 totalBenchSize = 0;\r\n  UInt64 totalEncodeTime = 0;\r\n  UInt64 totalDecodeTime = 0;\r\n  UInt64 totalCompressedSize = 0;\r\n\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    progressInfoSpec->Init();\r\n    CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n    inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n    CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n    CBenchmarkOutStream *outStreamSpec = new CBenchmarkOutStream;\r\n    outStreamSpec->Init(f, kCompressedBufferSize);\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, progressInfo);\r\n    UInt64 encodeTime = ::GetTimeCount() - progressInfoSpec->Time;\r\n    UInt32 compressedSize = outStreamSpec->Pos;\r\n    if(result != S_OK)\r\n    {\r\n      ThrowError(f, result, \"Encoder Error\");\r\n      return 1;\r\n    }\r\n    if (progressInfoSpec->InSize == 0)\r\n    {\r\n      fprintf(f, \"\\nError: Internal ERROR 1282\\n\");\r\n      return 1;\r\n    }\r\n  \r\n    ///////////////////////\r\n    // Decompressing\r\n  \r\n    CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n    CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n    UInt64 decodeTime;\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n      crcOutStreamSpec->Init();\r\n      \r\n      if (decoderSpec->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos) != S_OK)\r\n      {\r\n        fprintf(f, \"\\nError: Set Decoder Properties Error\\n\");\r\n        return 1;\r\n      }\r\n      UInt64 outSize = kBufferSize;\r\n      UInt64 startTime = ::GetTimeCount();\r\n      result = decoder->Code(inStream, crcOutStream, 0, &outSize, 0);\r\n      decodeTime = ::GetTimeCount() - startTime;\r\n      if(result != S_OK)\r\n      {\r\n        ThrowError(f, result, \"Decode Error\");\r\n        return 1;\r\n      }\r\n      if (crcOutStreamSpec->CRC.GetDigest() != crc.GetDigest())\r\n      {\r\n        fprintf(f, \"\\nError: CRC Error\\n\");\r\n        return 1;\r\n      }\r\n    }\r\n    UInt64 benchSize = kBufferSize - progressInfoSpec->InSize;\r\n    PrintResults(f, dictionarySize, isBT4, encodeTime, benchSize, false, 0);\r\n    fprintf(f, \"     \");\r\n    PrintResults(f, dictionarySize, isBT4, decodeTime, kBufferSize, true, compressedSize);\r\n    fprintf(f, \"\\n\");\r\n\r\n    totalBenchSize += benchSize;\r\n    totalEncodeTime += encodeTime;\r\n    totalDecodeTime += decodeTime;\r\n    totalCompressedSize += compressedSize;\r\n  }\r\n  fprintf(f, \"---------------------------------------------------\\n\");\r\n  PrintResults(f, dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\r\n  fprintf(f, \"     \");\r\n  PrintResults(f, dictionarySize, isBT4, totalDecodeTime, \r\n      kBufferSize * numIterations, true, totalCompressedSize);\r\n  fprintf(f, \"    Average\\n\");\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LzmaBench_h\r\n#define __LzmaBench_h\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize, bool isBT4);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/LzmaRam.cpp",
    "content": "// LzmaRam.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../Branch/BranchX86.h\"\r\n}\r\n\r\nclass CInStreamRam: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Size;\r\n  size_t Pos;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 remain = Size - Pos;\r\n  if (size > remain)\r\n    size = remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass COutStreamRam: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  size_t Size;\r\npublic:\r\n  Byte *Data;\r\n  size_t Pos;\r\n  bool Overflow;\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n    Overflow = false;\r\n  }\r\n  void SetPos(size_t pos)\r\n  {\r\n    Overflow = false;\r\n    Pos = pos;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  HRESULT WriteByte(Byte b)\r\n  {\r\n    if (Pos >= Size)\r\n    {\r\n      Overflow = true;\r\n      return E_FAIL;\r\n    }\r\n    Data[Pos++] = b;\r\n    return S_OK;\r\n  }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < Size; i++)\r\n    Data[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    Overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\n#define SZE_FAIL (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_OUT_OVERFLOW (3)\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try { \r\n  #endif\r\n\r\n  *outSizeProcessed = 0;\r\n  const size_t kIdSize = 1;\r\n  const size_t kLzmaPropsSize = 5;\r\n  const size_t kMinDestSize = kIdSize + kLzmaPropsSize + 8;\r\n  if (outSize < kMinDestSize)\r\n    return SZE_OUT_OVERFLOW;\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kAlgorithm,\r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kNumFastBytes,\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[1].vt = VT_UI4;\r\n  properties[2].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)2;\r\n  properties[1].ulVal = (UInt32)dictionarySize;\r\n  properties[2].ulVal = (UInt32)64;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n    return 1;\r\n  \r\n  COutStreamRam *outStreamSpec = new COutStreamRam;\r\n  if (outStreamSpec == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n  CInStreamRam *inStreamSpec = new CInStreamRam;\r\n  if (inStreamSpec == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\r\n  outStreamSpec->Init(outBuffer, outSize);\r\n  if (outStreamSpec->WriteByte(0) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n\r\n  if (encoderSpec->WriteCoderProperties(outStream) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n  if (outStreamSpec->Pos != kIdSize + kLzmaPropsSize)\r\n    return 1;\r\n  \r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    UInt64 t = (UInt64)(inSize);\r\n    if (outStreamSpec->WriteByte((Byte)((t) >> (8 * i))) != S_OK)\r\n      return SZE_OUT_OVERFLOW;\r\n  }\r\n\r\n  Byte *filteredStream = 0;\r\n\r\n  bool useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (inSize != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(inSize);\r\n      if (filteredStream == 0)\r\n        return SZE_OUTOFMEMORY;\r\n      memmove(filteredStream, inBuffer, inSize);\r\n    }\r\n    UInt32 _prevMask;\r\n    UInt32 _prevPos;\r\n    x86_Convert_Init(_prevMask, _prevPos);\r\n    x86_Convert(filteredStream, (UInt32)inSize, 0, &_prevMask, &_prevPos, 1);\r\n  }\r\n  \r\n  UInt32 minSize = 0;\r\n  int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n  bool bestIsFiltered = false;\r\n  int mainResult = 0;\r\n  size_t startPos = outStreamSpec->Pos;\r\n  for (i = 0; i < numPasses; i++)\r\n  {\r\n    if (numPasses > 1 && i == numPasses - 1 && !bestIsFiltered)\r\n      break;\r\n    outStreamSpec->SetPos(startPos);\r\n    bool curModeIsFiltered = false;\r\n    if (useFilter && i == 0)\r\n      curModeIsFiltered = true;\r\n    if (numPasses > 1 && i == numPasses - 1)\r\n      curModeIsFiltered = true;\r\n\r\n    inStreamSpec->Init(curModeIsFiltered ? filteredStream : inBuffer, inSize);\r\n    \r\n    HRESULT lzmaResult = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    \r\n    mainResult = 0;\r\n    if (lzmaResult == E_OUTOFMEMORY)\r\n    {\r\n      mainResult = SZE_OUTOFMEMORY;\r\n      break;\r\n    } \r\n    if (i == 0 || outStreamSpec->Pos <= minSize)\r\n    {\r\n      minSize = outStreamSpec->Pos;\r\n      bestIsFiltered = curModeIsFiltered;\r\n    }\r\n    if (outStreamSpec->Overflow)\r\n      mainResult = SZE_OUT_OVERFLOW;\r\n    else if (lzmaResult != S_OK)\r\n    {\r\n      mainResult = SZE_FAIL;\r\n      break;\r\n    } \r\n  }\r\n  *outSizeProcessed = outStreamSpec->Pos;\r\n  if (bestIsFiltered)\r\n    outBuffer[0] = 1;\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n  \r\n  #ifndef _NO_EXCEPTIONS\r\n  } catch(...) { return SZE_OUTOFMEMORY; }\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/LzmaRam.h",
    "content": "// LzmaRam.h\r\n\r\n#ifndef __LzmaRam_h\r\n#define __LzmaRam_h\r\n\r\n#include <stdlib.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\n/*\r\nLzmaRamEncode: BCJ + LZMA RAM->RAM compressing.\r\nIt uses .lzma format, but it writes one additional byte to .lzma file:\r\n  0: - no filter\r\n  1: - x86(BCJ) filter.\r\n\r\nTo provide best compression ratio dictionarySize mustbe >= inSize\r\n\r\nLzmaRamEncode allocates Data with MyAlloc/BigAlloc functions.\r\nRAM Requirements:\r\n  RamSize = dictionarySize * 9.5 + 6MB + FilterBlockSize \r\n    FilterBlockSize = 0, if useFilter == false\r\n    FilterBlockSize = inSize, if useFilter == true\r\n\r\n  Return code:\r\n    0 - OK\r\n    1 - Unspecified Error\r\n    2 - Memory allocating error\r\n    3 - Output buffer OVERFLOW\r\n\r\nIf you use SZ_FILTER_AUTO mode, then encoder will use 2 or 3 passes:\r\n  2 passes when FILTER_NO provides better compression.\r\n  3 passes when FILTER_YES provides better compression.\r\n*/\r\n\r\nenum ESzFilterMode \r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.c",
    "content": "/* LzmaRamDecode.c */\r\n\r\n#include \"LzmaRamDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#include \"BranchX86.h\"\r\n#else\r\n#include \"../LZMA_C/LzmaDecode.h\"\r\n#include \"../Branch/BranchX86.h\"\r\n#endif\r\n\r\n#define LZMA_PROPS_SIZE 14\r\n#define LZMA_SIZE_OFFSET 6\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize, \r\n    size_t *outSize)\r\n{\r\n  unsigned int i;\r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  *outSize = 0;\r\n  for(i = 0; i < sizeof(size_t); i++)\r\n    *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);\r\n  for(; i < 8; i++)\r\n    if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)\r\n      return 1;\r\n  return 0;\r\n}\r\n\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *))\r\n{\r\n  CLzmaDecoderState state;  /* it's about 24 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  SizeT inProcessed;\r\n  int useFilter;\r\n  \r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  useFilter = inBuffer[0];\r\n\r\n  *outSizeProcessed = 0;\r\n  if (useFilter > 1)\r\n    return 1;\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return 1;\r\n  state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  result = LzmaDecode(&state,\r\n    inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed,\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  freeFunc(state.Probs);\r\n  if (result != LZMA_RESULT_OK)\r\n    return 1;\r\n  *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 _prevMask;\r\n    UInt32 _prevPos;\r\n    x86_Convert_Init(_prevMask, _prevPos);\r\n    x86_Convert(outBuffer, (UInt32)outSizeProcessedLoc, 0, &_prevMask, &_prevPos, 0);\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.h",
    "content": "/* LzmaRamDecode.h */\r\n\r\n#ifndef __LzmaRamDecode_h\r\n#define __LzmaRamDecode_h\r\n\r\n#include <stdlib.h>\r\n\r\n/*\r\nLzmaRamGetUncompressedSize:\r\n  In: \r\n    inBuffer - input data\r\n    inSize   - input data size\r\n  Out: \r\n    outSize  - uncompressed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers\r\n*/\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    size_t *outSize);\r\n\r\n\r\n/*\r\nLzmaRamDecompress:\r\n  In: \r\n    inBuffer  - input data\r\n    inSize    - input data size\r\n    outBuffer - output data\r\n    outSize   - output size\r\n    allocFunc - alloc function (can be malloc)\r\n    freeFunc  - free function (can be free)\r\n  Out: \r\n    outSizeProcessed - processed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers / data stream\r\n    2 - Memory allocating error\r\n\r\nMemory requirements depend from properties of LZMA stream.\r\nWith default lzma settings it's about 16 KB.\r\n*/\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nCFLAGS = $(CFLAGS) -I ../../../\r\nLIBS = $(LIBS) oleaut32.lib user32.lib\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaRam.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\String.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\Vector.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZInWindow.obj \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\n\r\nOBJS = \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $O\\LzmaRamDecode.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\LzmaRamDecode.obj: LzmaRamDecode.c\r\n\t$(COMPL_O1)\r\n$O\\LzmaDecode.obj: ../LZMA_C/LzmaDecode.c\r\n\t$(COMPL_O2)\r\n$O\\BranchX86.obj: ../Branch/BranchX86.c\r\n\t$(COMPL_O2)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c -I ../../../\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaRam.o \\\r\n  LzmaRamDecode.o \\\r\n  LzmaDecode.o \\\r\n  BranchX86.o \\\r\n  LZMADecoder.o \\\r\n  LZMAEncoder.o \\\r\n  LZInWindow.o \\\r\n  LZOutWindow.o \\\r\n  RangeCoderBit.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  Alloc.o \\\r\n  C_FileIO.o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  String.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  Vector.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaRam.o: LzmaRam.cpp\r\n\t$(CXX) $(CFLAGS) LzmaRam.cpp\r\n\r\nLzmaRamDecode.o: LzmaRamDecode.c\r\n\t$(CXX_C) $(CFLAGS) LzmaRamDecode.c\r\n\r\nLzmaDecode.o: ../LZMA_C/LzmaDecode.c\r\n\t$(CXX_C) $(CFLAGS) ../LZMA_C/LzmaDecode.c\r\n\r\nBranchX86.o: ../Branch/BranchX86.c\r\n\t$(CXX_C) $(CFLAGS) ../Branch/BranchX86.c\r\n\r\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\r\n\r\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\r\n\r\nLZInWindow.o: ../LZ/LZInWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp\r\n\r\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\r\n\r\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\r\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\nAlloc.o: ../../../Common/Alloc.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/Alloc.cpp\r\n\r\nC_FileIO.o: ../../../Common/C_FileIO.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nString.o: ../../../Common/String.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/String.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nVector.o: ../../../Common/Vector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/Vector.cpp\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_C/LzmaDecode.c",
    "content": "/*\r\n  LzmaDecode.c\r\n  LZMA Decoder (optimized for Speed version)\r\n  \r\n  LZMA SDK 4.22 Copyright (c) 1999-2005 Igor Pavlov (2005-06-10)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) \\\r\n  { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \\\r\n  BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}\r\n\r\n#define RC_INIT Buffer = BufferLim = 0; RC_INIT2\r\n\r\n#else\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#endif\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  const Byte *Buffer = vs->Buffer;\r\n  const Byte *BufferLim = vs->BufferLim;\r\n  #else\r\n  const Byte *Buffer = inStream;\r\n  const Byte *BufferLim = inStream + inSize;\r\n  #endif\r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      #ifdef _LZMA_IN_CB\r\n      RC_INIT;\r\n      #else\r\n      RC_INIT(inStream, inSize);\r\n      #endif\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  RC_INIT;\r\n  #else\r\n  RC_INIT(inStream, inSize);\r\n  #endif\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (Byte)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n            UpdateBit0(prob);\r\n            \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            \r\n            state = state < kNumLitStates ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = Buffer;\r\n  vs->BufferLim = BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_C/LzmaDecode.h",
    "content": "/* \r\n  LzmaDecode.h\r\n  LZMA Decoder interface\r\n\r\n  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMADECODE_H\r\n#define __LZMADECODE_H\r\n\r\n/* #define _LZMA_IN_CB */\r\n/* Use callback for input data */\r\n\r\n/* #define _LZMA_OUT_READ */\r\n/* Use read function for output data */\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_LOC_OPT */\r\n/* Enable local speed optimizations inside code */\r\n\r\n/* #define _LZMA_SYSTEM_SIZE_T */\r\n/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/\r\n\r\n#ifndef UInt32\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\n#define UInt32 unsigned long\r\n#else\r\n#define UInt32 unsigned int\r\n#endif\r\n#endif\r\n\r\n#ifndef SizeT\r\n#ifdef _LZMA_SYSTEM_SIZE_T\r\n#include <stddef.h>\r\n#define SizeT size_t\r\n#else\r\n#define SizeT UInt32\r\n#endif\r\n#endif\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb unsigned short\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#ifdef _LZMA_IN_CB\r\ntypedef struct _ILzmaInCallback\r\n{\r\n  int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);\r\n} ILzmaInCallback;\r\n#endif\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  #ifdef _LZMA_OUT_READ\r\n  UInt32 DictionarySize;\r\n  #endif\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  const unsigned char *Buffer;\r\n  const unsigned char *BufferLim;\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  unsigned char *Dictionary;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;\r\n  unsigned char TempDictionary[4];\r\n  #endif\r\n} CLzmaDecoderState;\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }\r\n#endif\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *inCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_C/LzmaDecodeSize.c",
    "content": "/*\r\n  LzmaDecodeSize.c\r\n  LZMA Decoder (optimized for Size version)\r\n  \r\n  LZMA SDK 4.27 Copyright (c) 1999-2005 Igor Pavlov (2005-08-07)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\ntypedef struct _CRangeDecoder\r\n{\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  #ifdef _LZMA_IN_CB\r\n  ILzmaInCallback *InCallback;\r\n  int Result;\r\n  #endif\r\n  int ExtraBytes;\r\n} CRangeDecoder;\r\n\r\nByte RangeDecoderReadByte(CRangeDecoder *rd)\r\n{\r\n  if (rd->Buffer == rd->BufferLim)\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    SizeT size;\r\n    rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);\r\n    rd->BufferLim = rd->Buffer + size;\r\n    if (size == 0)\r\n    #endif\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n  }\r\n  return (*rd->Buffer++);\r\n}\r\n\r\n/* #define ReadByte (*rd->Buffer++) */\r\n#define ReadByte (RangeDecoderReadByte(rd))\r\n\r\nvoid RangeDecoderInit(CRangeDecoder *rd\r\n  #ifndef _LZMA_IN_CB\r\n    , const Byte *stream, SizeT bufferSize\r\n  #endif\r\n    )\r\n{\r\n  int i;\r\n  #ifdef _LZMA_IN_CB\r\n  rd->Buffer = rd->BufferLim = 0;\r\n  #else\r\n  rd->Buffer = stream;\r\n  rd->BufferLim = stream + bufferSize;\r\n  #endif\r\n  rd->ExtraBytes = 0;\r\n  rd->Code = 0;\r\n  rd->Range = (0xFFFFFFFF);\r\n  for(i = 0; i < 5; i++)\r\n    rd->Code = (rd->Code << 8) | ReadByte;\r\n}\r\n\r\n#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;        \r\n#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;\r\n#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }\r\n\r\nUInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)\r\n{\r\n  RC_INIT_VAR\r\n  UInt32 result = 0;\r\n  int i;\r\n  for (i = numTotalBits; i != 0; i--)\r\n  {\r\n    /* UInt32 t; */\r\n    range >>= 1;\r\n\r\n    result <<= 1;\r\n    if (code >= range)\r\n    {\r\n      code -= range;\r\n      result |= 1;\r\n    }\r\n    /*\r\n    t = (code - range) >> 31;\r\n    t &= 1;\r\n    code -= range & (t - 1);\r\n    result = (result + result) | (1 - t);\r\n    */\r\n    RC_NORMALIZE\r\n  }\r\n  RC_FLUSH_VAR\r\n  return result;\r\n}\r\n\r\nint RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)\r\n{\r\n  UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;\r\n  if (rd->Code < bound)\r\n  {\r\n    rd->Range = bound;\r\n    *prob += (kBitModelTotal - *prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 0;\r\n  }\r\n  else\r\n  {\r\n    rd->Range -= bound;\r\n    rd->Code -= bound;\r\n    *prob -= (*prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 1;\r\n  }\r\n}\r\n\r\n#define RC_GET_BIT2(prob, mi, A0, A1) \\\r\n  UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \\\r\n  if (code < bound) \\\r\n    { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \\\r\n  else \\\r\n    { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)               \r\n\r\nint RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = numLevels; i != 0; i--)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT(prob, mi)\r\n    #else\r\n    mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return mi - (1 << numLevels);\r\n}\r\n\r\nint RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  int symbol = 0;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = 0; i < numLevels; i++)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))\r\n    #else\r\n    int bit = RangeDecoderBitDecode(probs + mi, rd);\r\n    mi = mi + mi + bit;\r\n    symbol |= (bit << i);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + symbol;\r\n    RC_GET_BIT(prob, symbol)\r\n    #else\r\n    symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n    #endif\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    int bit;\r\n    int matchBit = (matchByte >> 7) & 1;\r\n    matchByte <<= 1;\r\n    #ifdef _LZMA_LOC_OPT\r\n    {\r\n      CProb *prob = probs + 0x100 + (matchBit << 8) + symbol;\r\n      RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)\r\n    }\r\n    #else\r\n    bit = RangeDecoderBitDecode(probs + 0x100 + (matchBit << 8) + symbol, rd);\r\n    symbol = (symbol << 1) | bit;\r\n    #endif\r\n    if (matchBit != bit)\r\n    {\r\n      while (symbol < 0x100)\r\n      {\r\n        #ifdef _LZMA_LOC_OPT\r\n        CProb *prob = probs + symbol;\r\n        RC_GET_BIT(prob, symbol)\r\n        #else\r\n        symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n        #endif\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\nint LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)\r\n{\r\n  if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)\r\n    return RangeDecoderBitTreeDecode(p + LenLow +\r\n        (posState << kLenNumLowBits), kLenNumLowBits, rd);\r\n  if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)\r\n    return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +\r\n        (posState << kLenNumMidBits), kLenNumMidBits, rd);\r\n  return kLenNumLowSymbols + kLenNumMidSymbols + \r\n      RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);\r\n}\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  CRangeDecoder rd;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  rd.Range = vs->Range;\r\n  rd.Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  rd.Buffer = vs->Buffer;\r\n  rd.BufferLim = vs->BufferLim;\r\n  #else\r\n  rd.Buffer = inStream;\r\n  rd.BufferLim = inStream + inSize;\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RangeDecoderInit(&rd\r\n          #ifndef _LZMA_IN_CB\r\n          , inStream, inSize\r\n          #endif\r\n          );\r\n      #ifdef _LZMA_IN_CB\r\n      if (rd.Result != LZMA_RESULT_OK)\r\n        return rd.Result;\r\n      #endif\r\n      if (rd.ExtraBytes != 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  rd.Result = LZMA_RESULT_OK;\r\n  #endif\r\n  rd.ExtraBytes = 0;\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  #endif\r\n  RangeDecoderInit(&rd\r\n      #ifndef _LZMA_IN_CB\r\n      , inStream, inSize\r\n      #endif\r\n      );\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  if (rd.Result != LZMA_RESULT_OK)\r\n    return rd.Result;\r\n  #endif\r\n  if (rd.ExtraBytes != 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n    #ifdef _LZMA_IN_CB\r\n    if (rd.Result != LZMA_RESULT_OK)\r\n      return rd.Result;\r\n    #endif\r\n    if (rd.ExtraBytes != 0)\r\n      return LZMA_RESULT_DATA_ERROR;\r\n    if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n    {\r\n      CProb *probs = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        Byte matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);\r\n      }\r\n      else\r\n        previousByte = LzmaLiteralDecode(probs, &rd);\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)\r\n      {\r\n        if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)\r\n        {\r\n          if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n      \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n\r\n            state = state < 7 ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n            continue;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)\r\n            distance = rep1;\r\n          else \r\n          {\r\n            if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)\r\n              distance = rep2;\r\n            else\r\n            {\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        len = LzmaLenDecode(p + RepLenCoder, &rd, posState);\r\n        state = state < 7 ? 8 : 11;\r\n      }\r\n      else\r\n      {\r\n        int posSlot;\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < 7 ? 7 : 10;\r\n        len = LzmaLenDecode(p + LenCoder, &rd, posState);\r\n        posSlot = RangeDecoderBitTreeDecode(p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits), kNumPosSlotBits, &rd);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 += RangeDecoderReverseBitTreeDecode(\r\n                p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);\r\n          }\r\n          else\r\n          {\r\n            rep0 += RangeDecoderDecodeDirectBits(&rd, \r\n                numDirectBits - kNumAlignBits) << kNumAlignBits;\r\n            rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = rd.Range;\r\n  vs->Code = rd.Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = rd.Buffer;\r\n  vs->BufferLim = rd.BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(rd.Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_C/LzmaStateDecode.c",
    "content": "/*\r\n  LzmaStateDecode.c\r\n  LZMA Decoder (State version)\r\n  \r\n  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\n/* kRequiredInBufferSize = number of required input bytes for worst case: \r\n   longest match with longest distance.\r\n   kLzmaInBufferSize must be larger than kRequiredInBufferSize \r\n   23 bits = 2 (match select) + 10 (len) + 6 (distance) + 4(align) + 1 (RC_NORMALIZE)\r\n*/\r\n\r\n#define kRequiredInBufferSize ((23 * (kNumBitModelTotalBits - kNumMoveBits + 1) + 26 + 9) / 8)\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n    return LZMA_RESULT_OK;\r\n  }\r\n}\r\n\r\nint LzmaDecode(\r\n    CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding)\r\n{\r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n\r\n  unsigned char *Buffer = vs->Buffer;\r\n  int BufferSize = vs->BufferSize; /* don't change it to unsigned int */\r\n  CProb *p = vs->Probs;\r\n\r\n  int state = vs->State;\r\n  unsigned char previousByte;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  SizeT nowPos = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  unsigned char *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  unsigned char tempDictionary[4];\r\n\r\n  (*inSizeProcessed) = 0;\r\n  (*outSizeProcessed) = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n    {\r\n      Buffer[BufferSize++] = *inStream++;\r\n      (*inSizeProcessed)++;\r\n      inSize--;\r\n    }\r\n    if (BufferSize < 5)\r\n    {\r\n      vs->BufferSize = BufferSize;\r\n      return finishDecoding ? LZMA_RESULT_DATA_ERROR : LZMA_RESULT_OK;\r\n    }\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RC_INIT;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  while(1)\r\n  {\r\n    int bufferPos = (int)(Buffer - vs->Buffer);\r\n    if (BufferSize - bufferPos < kRequiredInBufferSize)\r\n    {\r\n      int i;\r\n      BufferSize -= bufferPos;\r\n      if (BufferSize < 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n      for (i = 0; i < BufferSize; i++)\r\n        vs->Buffer[i] = Buffer[i];\r\n      Buffer = vs->Buffer;\r\n      while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n      {\r\n        Buffer[BufferSize++] = *inStream++;\r\n        (*inSizeProcessed)++;\r\n        inSize--;\r\n      }\r\n      if (BufferSize < kRequiredInBufferSize && !finishDecoding)\r\n        break;\r\n    }\r\n    if (nowPos >= outSize)\r\n      break;\r\n    {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)((nowPos + globalPos) & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        ((((nowPos + globalPos)& literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (unsigned char)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            UInt32 pos;\r\n            UpdateBit0(prob);\r\n            if (distanceLimit == 0)\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            outStream[nowPos++] = previousByte;\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      if (rep0 > distanceLimit) \r\n        return LZMA_RESULT_DATA_ERROR;\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n\r\n      do\r\n      {\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  BufferSize -= (int)(Buffer - vs->Buffer);\r\n  if (BufferSize < 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    int i;\r\n    for (i = 0; i < BufferSize; i++)\r\n      vs->Buffer[i] = Buffer[i];\r\n  }\r\n  vs->BufferSize = BufferSize;\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = (UInt32)(globalPos + nowPos);\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n\r\n  (*outSizeProcessed) = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_C/LzmaStateDecode.h",
    "content": "/* \r\n  LzmaStateDecode.h\r\n  LZMA Decoder interface (State version)\r\n\r\n  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMASTATEDECODE_H\r\n#define __LZMASTATEDECODE_H\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_SYSTEM_SIZE_T */\r\n/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/\r\n\r\n\r\n#ifndef UInt32\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\n#define UInt32 unsigned long\r\n#else\r\n#define UInt32 unsigned int\r\n#endif\r\n#endif\r\n\r\n#ifndef SizeT\r\n#ifdef _LZMA_SYSTEM_SIZE_T\r\n#include <stddef.h>\r\n#define SizeT size_t\r\n#else\r\n#define SizeT UInt32\r\n#endif\r\n#endif\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb unsigned short\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  UInt32 DictionarySize;\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))\r\n\r\n#define kLzmaInBufferSize 64   /* don't change it. it must be larger than kRequiredInBufferSize */\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n  unsigned char *Dictionary;\r\n\r\n  unsigned char Buffer[kLzmaInBufferSize];\r\n  int BufferSize;\r\n\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;  /* -2: decoder needs internal initialization\r\n                     -1: stream was finished, \r\n                      0: ok\r\n                    > 0: need to write RemainLen bytes as match Reps[0],\r\n                  */\r\n  unsigned char TempDictionary[4];  /* it's required when DictionarySize = 0 */\r\n} CLzmaDecoderState;\r\n\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }\r\n\r\n/* LzmaDecode: decoding from input stream to output stream.\r\n  If finishDecoding != 0, then there are no more bytes in input stream\r\n  after inStream[inSize - 1]. */\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize,  SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_C/LzmaStateTest.c",
    "content": "/* \r\nLzmaStateTest.c\r\nTest application for LZMA Decoder (State version)\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\n#define kInBufferSize (1 << 15)\r\n#define kOutBufferSize (1 << 15)\r\n\r\nunsigned char g_InBuffer[kInBufferSize];\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n  { return fread(data, 1, size, file); }\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size); }\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0; \r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  int i;\r\n  int res = 0;\r\n  CLzmaDecoderState state;  /* it's about 140 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n  SizeT inAvail = 0;\r\n  unsigned char *inBuffer = 0;\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n  \r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    unsigned char b;\r\n    if (!MyReadFileAndCheck(inFile, &b, 1))\r\n      return PrintError(rs, kCantReadMessage);\r\n    if (b != 0xFF)\r\n      waitEOS = 0;\r\n    if (i < 4)\r\n      outSize += (UInt32)(b) << (i * 8);\r\n    else\r\n      outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  \r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      free(state.Probs);\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    }\r\n  }\r\n  \r\n  /* Decompress */\r\n  \r\n  LzmaDecoderInit(&state);\r\n  \r\n  do\r\n  {\r\n    SizeT inProcessed, outProcessed;\r\n    int finishDecoding;\r\n    UInt32 outAvail = kOutBufferSize;\r\n    if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n      outAvail = outSize;\r\n    if (inAvail == 0)\r\n    {\r\n      inAvail = (SizeT)MyReadFile(inFile, g_InBuffer, kInBufferSize);\r\n      inBuffer = g_InBuffer;\r\n    }\r\n    finishDecoding = (inAvail == 0);\r\n    res = LzmaDecode(&state,\r\n        inBuffer, inAvail, &inProcessed,\r\n        g_OutBuffer, outAvail, &outProcessed,\r\n        finishDecoding);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n      break;\r\n    }\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n    \r\n    if (outFile != 0)  \r\n      if (fwrite(g_OutBuffer, 1, outProcessed, outFile) != outProcessed)\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n        break;\r\n      }\r\n      \r\n    if (outSize < outProcessed)\r\n      outSizeHigh--;\r\n    outSize -= (UInt32)outProcessed;\r\n    outSize &= 0xFFFFFFFF;\r\n\r\n    if (outProcessed == 0 && finishDecoding)\r\n    {\r\n      if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n        res = 1;\r\n      break;\r\n    }\r\n  }\r\n  while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n\r\n  free(state.Dictionary);\r\n  free(state.Probs);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-02\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_C/LzmaTest.c",
    "content": "/* \r\nLzmaTest.c\r\nTest application for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-05)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fread(data, 1, size, file); \r\n}\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size);} \r\n\r\nsize_t MyWriteFile(FILE *file, const void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fwrite(data, 1, size, file); \r\n}\r\n\r\nint MyWriteFileAndCheck(FILE *file, const void *data, size_t size)\r\n  { return (MyWriteFile(file, data, size) == size); }\r\n\r\n#ifdef _LZMA_IN_CB\r\n#define kInBufferSize (1 << 15)\r\ntypedef struct _CBuffer\r\n{\r\n  ILzmaInCallback InCallback;\r\n  FILE *File;\r\n  unsigned char Buffer[kInBufferSize];\r\n} CBuffer;\r\n\r\nint LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CBuffer *b = (CBuffer *)object;\r\n  *buffer = b->Buffer;\r\n  *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);\r\n  return LZMA_RESULT_OK;\r\n}\r\nCBuffer g_InBuffer;\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define kOutBufferSize (1 << 15)\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n#endif\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0;\r\n  #ifndef _LZMA_OUT_READ\r\n  SizeT outSizeFull;\r\n  unsigned char *outStream;\r\n  #endif\r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  SizeT compressedSize;\r\n  unsigned char *inStream;\r\n  #endif\r\n\r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n  int res;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.File = inFile;\r\n  #endif\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  {\r\n    long length;\r\n    fseek(inFile, 0, SEEK_END);\r\n    length = ftell(inFile);\r\n    fseek(inFile, 0, SEEK_SET);\r\n    if ((long)(SizeT)length != length)\r\n      return PrintError(rs, \"Too big compressed stream\");\r\n    compressedSize = (SizeT)(length - (LZMA_PROPERTIES_SIZE + 8));\r\n  }\r\n  #endif\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n\r\n  {\r\n    int i;\r\n    for (i = 0; i < 8; i++)\r\n    {\r\n      unsigned char b;\r\n      if (!MyReadFileAndCheck(inFile, &b, 1))\r\n        return PrintError(rs, kCantReadMessage);\r\n      if (b != 0xFF)\r\n        waitEOS = 0;\r\n      if (i < 4)\r\n        outSize += (UInt32)(b) << (i * 8);\r\n      else\r\n        outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n    }\r\n    \r\n    #ifndef _LZMA_OUT_READ\r\n    if (waitEOS)\r\n      return PrintError(rs, \"Stream with EOS marker is not supported\");\r\n    outSizeFull = (SizeT)outSize;\r\n    if (sizeof(SizeT) >= 8)\r\n      outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);\r\n    else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)\r\n      return PrintError(rs, \"Too big uncompressed stream\");\r\n    #endif\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n  #else\r\n  if (outSizeFull == 0)\r\n    outStream = 0;\r\n  else\r\n    outStream = (unsigned char *)malloc(outSizeFull);\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  if (compressedSize == 0)\r\n    inStream = 0;\r\n  else\r\n    inStream = (unsigned char *)malloc(compressedSize);\r\n  #endif\r\n\r\n  if (state.Probs == 0 \r\n    #ifdef _LZMA_OUT_READ\r\n    || (state.Dictionary == 0 && state.Properties.DictionarySize != 0)\r\n    #else\r\n    || (outStream == 0 && outSizeFull != 0)\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    || (inStream == 0 && compressedSize != 0)\r\n    #endif\r\n    )\r\n  {\r\n    free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    free(state.Dictionary);\r\n    #else\r\n    free(outStream);\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    free(inStream);\r\n    #endif\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  }\r\n\r\n  /* Decompress */\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  #else\r\n  if (!MyReadFileAndCheck(inFile, inStream, compressedSize))\r\n    return PrintError(rs, kCantReadMessage);\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inAvail = compressedSize;\r\n    const unsigned char *inBuffer = inStream;\r\n    #endif\r\n    LzmaDecoderInit(&state);\r\n    do\r\n    {\r\n      #ifndef _LZMA_IN_CB\r\n      SizeT inProcessed;\r\n      #endif\r\n      SizeT outProcessed;\r\n      SizeT outAvail = kOutBufferSize;\r\n      if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n        outAvail = (SizeT)outSize;\r\n      res = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &g_InBuffer.InCallback,\r\n        #else\r\n        inBuffer, inAvail, &inProcessed,\r\n        #endif\r\n        g_OutBuffer, outAvail, &outProcessed);\r\n      if (res != 0)\r\n      {\r\n        sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n        res = 1;\r\n        break;\r\n      }\r\n      #ifndef _LZMA_IN_CB\r\n      inAvail -= inProcessed;\r\n      inBuffer += inProcessed;\r\n      #endif\r\n      \r\n      if (outFile != 0)  \r\n        if (!MyWriteFileAndCheck(outFile, g_OutBuffer, (size_t)outProcessed))\r\n        {\r\n          PrintError(rs, kCantWriteMessage);\r\n          res = 1;\r\n          break;\r\n        }\r\n        \r\n      if (outSize < outProcessed)\r\n        outSizeHigh--;\r\n      outSize -= (UInt32)outProcessed;\r\n      outSize &= 0xFFFFFFFF;\r\n        \r\n      if (outProcessed == 0)\r\n      {\r\n        if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n          res = 1;\r\n        break;\r\n      }\r\n    }\r\n    while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n  }\r\n\r\n  #else\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inProcessed;\r\n    #endif\r\n    SizeT outProcessed;\r\n    res = LzmaDecode(&state,\r\n      #ifdef _LZMA_IN_CB\r\n      &g_InBuffer.InCallback,\r\n      #else\r\n      inStream, compressedSize, &inProcessed,\r\n      #endif\r\n      outStream, outSizeFull, &outProcessed);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n    }\r\n    else if (outFile != 0)\r\n    {\r\n      if (!MyWriteFileAndCheck(outFile, outStream, (size_t)outProcessed))\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  free(state.Dictionary);\r\n  #else\r\n  free(outStream);\r\n  #endif\r\n  #ifndef _LZMA_IN_CB\r\n  free(inStream);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-05\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_C/makefile",
    "content": "PROG = lzmaDec.exe\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nOBJS = \\\r\n  $O\\LzmaTest.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$O\\LzmaTest.obj: $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/LZMA_C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_C/makefile.gcc",
    "content": "PROG = lzmadec\r\nCXX = gcc \r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall -pedantic -D _LZMA_PROB32 \r\n\r\nOBJS = LzmaTest.o LzmaDecode.o \r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\nLzmaTest.o: LzmaTest.c\r\n\t$(CXX) $(CFLAGS) LzmaTest.c\r\n\r\nLzmaDecode.o: LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) LzmaDecode.c\r\n\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Lib/ZLib.cpp",
    "content": "/*\r\n * lzma zlib simplified wrapper\r\n *\r\n * Copyright (c) 2005-2006 Oleg I. Vdovikin <oleg@cs.msu.su>\r\n *\r\n * This library is free software; you can redistribute \r\n * it and/or modify it under the terms of the GNU Lesser \r\n * General Public License as published by the Free Software \r\n * Foundation; either version 2.1 of the License, or \r\n * (at your option) any later version.\r\n *\r\n * This library is distributed in the hope that it will be \r\n * useful, but WITHOUT ANY WARRANTY; without even the implied \r\n * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r\n * PURPOSE. See the GNU Lesser General Public License \r\n * for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General \r\n * Public License along with this library; if not, write to \r\n * the Free Software Foundation, Inc., 59 Temple Place, \r\n * Suite 330, Boston, MA 02111-1307 USA \r\n */\r\n\r\n/*\r\n * default values for encoder/decoder used by wrapper\r\n */\r\n\r\n#include <zlib.h>\r\n\r\n#define ZLIB_LC 0\r\n#define ZLIB_LP 0\r\n#define ZLIB_PB 2\r\n\r\n#ifdef WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#endif\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#define STG_E_SEEKERROR                  ((HRESULT)0x80030019L)\r\n#define STG_E_MEDIUMFULL                 ((HRESULT)0x80030070L)\r\n\r\nclass CInMemoryStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CInMemoryStream(const Bytef *data, UInt64 size) : \r\n\t  m_data(data), m_size(size), m_offset(0) {}\r\n\r\n  virtual ~CInMemoryStream() {}\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\t  if (size > m_size - m_offset) \r\n\t\t  size = m_size - m_offset;\r\n\r\n\t  if (size) {\r\n\t\t  memcpy(data, m_data + m_offset, size);\r\n\t  }\r\n\r\n\t  m_offset += size;\r\n\r\n\t  if (processedSize) \r\n\t\t  *processedSize = size;\r\n\r\n\t  return S_OK;\r\n  }\r\n\r\n  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\treturn Read(data, size, processedSize);\r\n  }\r\n\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n  {\r\n\t  UInt64 _offset;\r\n\r\n\t  if (seekOrigin == STREAM_SEEK_SET) _offset = offset;\r\n\t  else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset; \r\n\t  else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;\r\n\t  else return STG_E_INVALIDFUNCTION;\r\n\r\n\t  if (_offset < 0 || _offset > m_size)\r\n\t\t  return STG_E_SEEKERROR;\r\n\r\n\t  m_offset = _offset;\r\n\r\n\t  if (newPosition)\r\n\t\t  *newPosition = m_offset;\r\n\r\n\t  return S_OK;\r\n  }\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size)\r\n  {\r\n\t  *size = m_size;\r\n\t  return S_OK;\r\n  }\r\nprotected:\r\n\tconst Bytef *m_data;\r\n\tUInt64 m_size;\r\n\tUInt64 m_offset;\r\n};\r\n\r\nclass COutMemoryStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  COutMemoryStream(Bytef *data, UInt64 maxsize) : \r\n\t  m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}\r\n  virtual ~COutMemoryStream() {}\r\n  \r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\t  if (size > m_maxsize - m_offset) \r\n\t\t  size = m_maxsize - m_offset;\r\n\r\n\t  if (size) {\r\n\t\t  memcpy(m_data + m_offset, data, size);\r\n\t  }\r\n\r\n\t  m_offset += size;\r\n\r\n\t  if (m_offset > m_size)\r\n\t\tm_size = m_offset;\r\n\r\n\t  if (processedSize) \r\n\t\t  *processedSize = size;\r\n\r\n\t  return S_OK;\r\n  }\r\n  \r\n  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\t  return Write(data, size, processedSize);\r\n  }\r\n\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n  {\r\n\t  UInt64 _offset;\r\n\r\n\t  if (seekOrigin == STREAM_SEEK_SET) _offset = offset;\r\n\t  else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset; \r\n\t  else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;\r\n\t  else return STG_E_INVALIDFUNCTION;\r\n\r\n\t  if (_offset < 0 || _offset > m_maxsize)\r\n\t\t  return STG_E_SEEKERROR;\r\n\r\n\t  m_offset = _offset;\r\n\r\n\t  if (newPosition)\r\n\t\t  *newPosition = m_offset;\r\n\r\n\t  return S_OK;\r\n  }\r\n  \r\n  STDMETHOD(SetSize)(Int64 newSize)\r\n  {\r\n\t  if ((UInt64)newSize > m_maxsize) \r\n\t\t  return STG_E_MEDIUMFULL;\r\n\r\n\t  return S_OK;\r\n  }\r\nprotected:\r\n\tBytef *m_data;\r\n\tUInt64 m_size;\r\n\tUInt64 m_maxsize;\r\n\tUInt64 m_offset;\r\n};\r\n\r\nZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,\r\n                                  const Bytef *source, uLong sourceLen,\r\n                                  int level))\r\n{\r\n\tCInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);\r\n\tCMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\t\r\n\tCOutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);\r\n\tCMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n\t\r\n\tNCompress::NLZMA::CEncoder *encoderSpec = \r\n\t\tnew NCompress::NLZMA::CEncoder;\r\n\tCMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\t\r\n\tPROPID propIDs[] = \r\n\t{\r\n\t\tNCoderPropID::kDictionarySize,\r\n\t\tNCoderPropID::kPosStateBits,\r\n\t\tNCoderPropID::kLitContextBits,\r\n\t\tNCoderPropID::kLitPosBits,\r\n\t\tNCoderPropID::kAlgorithm,\r\n\t\tNCoderPropID::kNumFastBytes,\r\n\t\tNCoderPropID::kMatchFinder,\r\n\t\tNCoderPropID::kEndMarker\r\n\t};\r\n\tconst int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\t\r\n\tPROPVARIANT properties[kNumProps];\r\n\tfor (int p = 0; p < 6; p++)\r\n\t\tproperties[p].vt = VT_UI4;\r\n\tproperties[0].ulVal = UInt32(1 << (level + 14));\r\n\tproperties[1].ulVal = UInt32(ZLIB_PB);\r\n\tproperties[2].ulVal = UInt32(ZLIB_LC); // for normal files\r\n\tproperties[3].ulVal = UInt32(ZLIB_LP); // for normal files\r\n\tproperties[4].ulVal = UInt32(2);\r\n\tproperties[5].ulVal = UInt32(128);\r\n\t\r\n\tproperties[6].vt = VT_BSTR;\r\n\tproperties[6].bstrVal = (BSTR)(const wchar_t *)L\"BT4\";\r\n\t\r\n\tproperties[7].vt = VT_BOOL;\r\n\tproperties[7].boolVal = VARIANT_TRUE;\r\n\t\r\n\tif (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n\t\treturn Z_MEM_ERROR; // should not happen\r\n\t\r\n\tHRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n\tif (result == E_OUTOFMEMORY)\r\n\t{\r\n\t\treturn Z_MEM_ERROR;\r\n\t}   \r\n\telse if (result != S_OK)\r\n\t{\r\n\t\treturn Z_BUF_ERROR;\t// should not happen\r\n\t}   \r\n\t\r\n\tUInt64 fileSize;\r\n\toutStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);\r\n\t*destLen = fileSize;\r\n\t\r\n\treturn Z_OK;\r\n}\r\n\r\nZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,\r\n                                   const Bytef *source, uLong sourceLen))\r\n{\r\n\tCInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);\r\n\tCMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\t\r\n\tCOutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);\r\n\tCMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n\t\r\n\tNCompress::NLZMA::CDecoder *decoderSpec = \r\n\t\tnew NCompress::NLZMA::CDecoder;\r\n\tCMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n\t\r\n\tif (decoderSpec->SetDecoderPropertiesRaw(ZLIB_LC, \r\n\t\tZLIB_LP, ZLIB_PB, (1 << 23)) != S_OK) return Z_DATA_ERROR;\r\n\t\r\n\tUInt64 fileSize = *destLen;\r\n\t\r\n\tif (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n\t{\r\n\t\treturn Z_DATA_ERROR;\r\n\t}\r\n\t\r\n\toutStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);\r\n\t*destLen = fileSize;\r\n\t\r\n\treturn Z_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/LZMA_Lib/makefile",
    "content": "PROG = liblzma.a\nCXX = g++ -O3 -Wall\nAR = ar\nRM = rm -f\nCFLAGS = -c  -I ../../../\n\nOBJS = \\\n  ZLib.o \\\n  LZMADecoder.o \\\n  LZMAEncoder.o \\\n  LZInWindow.o \\\n  LZOutWindow.o \\\n  RangeCoderBit.o \\\n  InBuffer.o \\\n  OutBuffer.o \\\n  FileStreams.o \\\n  Alloc.o \\\n  C_FileIO.o \\\n  CommandLineParser.o \\\n  CRC.o \\\n  StreamUtils.o \\\n  String.o \\\n  StringConvert.o \\\n  StringToInt.o \\\n  Vector.o \\\n\n\nall: $(PROG)\n\n$(PROG): $(OBJS)\n\t$(AR) r $(PROG) $(OBJS)\n\nZLib.o: ZLib.cpp\n\t$(CXX) $(CFLAGS) ZLib.cpp\n\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\n\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\n\nLZInWindow.o: ../LZ/LZInWindow.cpp\n\t$(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp\n\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\n\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\n\nInBuffer.o: ../../Common/InBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\n\nOutBuffer.o: ../../Common/OutBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\n\nStreamUtils.o: ../../Common/StreamUtils.cpp\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\n\nFileStreams.o: ../../Common/FileStreams.cpp\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\n\nAlloc.o: ../../../Common/Alloc.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/Alloc.cpp\n\nC_FileIO.o: ../../../Common/C_FileIO.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp\n\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\n\nCRC.o: ../../../Common/CRC.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\n\nMyWindows.o: ../../../Common/MyWindows.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\n\nString.o: ../../../Common/String.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/String.cpp\n\nStringConvert.o: ../../../Common/StringConvert.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\n\nStringToInt.o: ../../../Common/StringToInt.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\n\nVector.o: ../../../Common/Vector.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/Vector.cpp\n\nclean:\n\t-$(RM) $(PROG) $(OBJS)\n\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/RangeCoder/RangeCoder.h",
    "content": "// Compress/RangeCoder/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_H\r\n#define __COMPRESS_RANGECODER_H\r\n\r\n#include \"../../Common/InBuffer.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1; \r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) \r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);                      \r\n    } \r\n    _cacheSize++;                               \r\n    Low = (UInt32)Low << 8;                           \r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numTotalBits)\r\n  {\r\n    for (int i = numTotalBits - 1; i >= 0; i--)\r\n    {\r\n      Range >>= 1;\r\n      if (((value >> i) & 1) == 1)\r\n        Low += Range;\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;        \r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8; \r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/RangeCoder/RangeCoderBit.cpp",
    "content": "// Compress/RangeCoder/RangeCoderBit.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nUInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\nstatic CPriceTables g_PriceTables;\r\n\r\nCPriceTables::CPriceTables() { Init(); }\r\n\r\nvoid CPriceTables::Init()\r\n{\r\n  const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n  for(int i = kNumBits - 1; i >= 0; i--)\r\n  {\r\n    UInt32 start = 1 << (kNumBits - i - 1);\r\n    UInt32 end = 1 << (kNumBits - i);\r\n    for (UInt32 j = start; j < end; j++)\r\n      ProbPrices[j] = (i << kNumBitPriceShiftBits) + \r\n          (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n  }\r\n\r\n  /*\r\n  // simplest: bad solution\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = kBitPrice;\r\n  */\r\n  \r\n  /*\r\n  const double kDummyMultMid = (1.0 / kBitPrice) / 2;\r\n  const double kDummyMultMid = 0;\r\n  // float solution\r\n  double ln2 = log(double(2));\r\n  double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);\r\n  */\r\n  \r\n  /*\r\n  // experimental, slow, solution:\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n  {\r\n    const int kCyclesBits = 5;\r\n    const UInt32 kCycles = (1 << kCyclesBits);\r\n\r\n    UInt32 range = UInt32(-1);\r\n    UInt32 bitCount = 0;\r\n    for (UInt32 j = 0; j < kCycles; j++)\r\n    {\r\n      range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n      range *= i;\r\n      while(range < (1 << 31))\r\n      {\r\n        range <<= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    bitCount <<= kNumBitPriceShiftBits;\r\n    range -= (1 << 31);\r\n    for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)\r\n    {\r\n      range <<= 1;\r\n      if (range > (1 << 31))\r\n      {\r\n        bitCount += (1 << k);\r\n        range -= (1 << 31);\r\n      }\r\n    }\r\n    ProbPrices[i] = (bitCount \r\n      // + (1 << (kCyclesBits - 1))\r\n      ) >> kCyclesBits;\r\n  }\r\n  */\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/RangeCoder/RangeCoderBit.h",
    "content": "// Compress/RangeCoder/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_H\r\n#define __COMPRESS_RANGECODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 2;\r\n\r\nconst int kNumBitPriceShiftBits = 6;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nclass CPriceTables\r\n{\r\npublic:\r\n  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  static void Init();\r\n  CPriceTables();\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return CPriceTables::ProbPrices[\r\n      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/RangeCoder/RangeCoderBitTree.h",
    "content": "// Compress/RangeCoder/RangeCoderBitTree.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_TREE_H\r\n#define __COMPRESS_RANGECODER_BIT_TREE_H\r\n\r\n#include \"RangeCoderBit.h\"\r\n#include \"RangeCoderOpt.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeEncoder\r\n{\r\n  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  void Encode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int bitIndex = NumBitLevels; bitIndex != 0 ;)\r\n    {\r\n      bitIndex--;\r\n      UInt32 bit = (symbol >> bitIndex) & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n  };\r\n  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int i = 0; i < NumBitLevels; i++)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n      symbol >>= 1;\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    symbol |= (1 << NumBitLevels);\r\n    UInt32 price = 0;\r\n    while (symbol != 1)\r\n    {\r\n      price += Models[symbol >> 1].GetPrice(symbol & 1);\r\n      symbol >>= 1;\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 ReverseGetPrice(UInt32 symbol) const\r\n  {\r\n    UInt32 price = 0;\r\n    UInt32 modelIndex = 1;\r\n    for (int i = NumBitLevels; i != 0; i--)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      symbol >>= 1;\r\n      price += Models[modelIndex].GetPrice(bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n    return price;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeDecoder\r\n{\r\n  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  UInt32 Decode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n    {\r\n      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);\r\n      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)\r\n    }\r\n    RC_FLUSH_VAR\r\n    return modelIndex - (1 << NumBitLevels);\r\n  };\r\n  UInt32 ReverseDecode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    UInt32 symbol = 0;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n    {\r\n      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n      // modelIndex <<= 1;\r\n      // modelIndex += bit;\r\n      // symbol |= (bit << bitIndex);\r\n      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n    }\r\n    RC_FLUSH_VAR\r\n    return symbol;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nvoid ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models, \r\n    CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  for (int i = 0; i < NumBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    Models[modelIndex].Encode(rangeEncoder, bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models, \r\n    UInt32 NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 modelIndex = 1;\r\n  for (int i = NumBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += Models[modelIndex].GetPrice(bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models, \r\n    CDecoder *rangeDecoder, int NumBitLevels)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  UInt32 symbol = 0;\r\n  RC_INIT_VAR\r\n  for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n  {\r\n    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n    // modelIndex <<= 1;\r\n    // modelIndex += bit;\r\n    // symbol |= (bit << bitIndex);\r\n    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n  }\r\n  RC_FLUSH_VAR\r\n  return symbol;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/RangeCoder/RangeCoderOpt.h",
    "content": "// Compress/RangeCoder/RangeCoderOpt.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_OPT_H\r\n#define __COMPRESS_RANGECODER_OPT_H\r\n\r\n#define RC_INIT_VAR \\\r\n  UInt32 range = rangeDecoder->Range; \\\r\n  UInt32 code = rangeDecoder->Code;        \r\n\r\n#define RC_FLUSH_VAR \\\r\n  rangeDecoder->Range = range; \\\r\n  rangeDecoder->Code = code;\r\n\r\n#define RC_NORMALIZE \\\r\n  if (range < NCompress::NRangeCoder::kTopValue) \\\r\n    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }\r\n\r\n#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \\\r\n  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \\\r\n  if (code < bound) \\\r\n  { A0; range = bound; \\\r\n    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \\\r\n    mi <<= 1; } \\\r\n  else \\\r\n  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \\\r\n    mi = (mi + mi) + 1; }} \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/Compress/RangeCoder/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n// \"23170F69-40C1-278A-0000-000400xx0000\"\r\n#define CODER_INTERFACE(i, x) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \\\r\nstruct i: public IUnknown\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, \r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kNumPasses = 0x460, \r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block \r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n// \"23170F69-40C1-278A-0000-000300xx0000\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, b, x) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \\\r\nstruct i: public b\r\n\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream, \r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/Alloc.cpp",
    "content": "// Common/Alloc.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount++);\r\n  #endif\r\n  return ::malloc(size);\r\n}\r\n\r\nvoid MyFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d\", --g_allocCount);\r\n  #endif\r\n  \r\n  ::free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  ::VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\nstatic SIZE_T g_LargePageSize = \r\n    #ifdef _WIN64\r\n    (1 << 21);\r\n    #else\r\n    (1 << 22);\r\n    #endif\r\n\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n\r\nbool SetLargePageSize()\r\n{\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return false;\r\n  SIZE_T size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return false;\r\n  g_LargePageSize = size;\r\n  return true;\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  if (size >= (1 << 18))\r\n  {\r\n    void *res = ::VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), \r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  ::VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/Alloc.h",
    "content": "// Common/Alloc.h\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size) throw();\r\nvoid MyFree(void *address) throw();\r\n\r\n#ifdef _WIN32\r\n\r\nbool SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size) throw();\r\nvoid MidFree(void *address) throw();\r\nvoid *BigAlloc(size_t size) throw();\r\nvoid BigFree(void *address) throw();\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CRC.h\"\r\n\r\nstatic const UInt32 kCRCPoly = 0xEDB88320;\r\n\r\nUInt32 CCRC::Table[256];\r\n\r\nvoid CCRC::InitTable()\r\n{\r\n  for (UInt32 i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    for (int j = 0; j < 8; j++)\r\n      if (r & 1) \r\n        r = (r >> 1) ^ kCRCPoly;\r\n      else     \r\n        r >>= 1;\r\n    CCRC::Table[i] = r;\r\n  }\r\n}\r\n\r\nclass CCRCTableInit\r\n{\r\npublic:\r\n  CCRCTableInit() { CCRC::InitTable(); }\r\n} g_CRCTableInit;\r\n\r\nvoid CCRC::UpdateByte(Byte b)\r\n{\r\n  _value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);\r\n}\r\n\r\nvoid CCRC::UpdateUInt16(UInt16 v)\r\n{\r\n  UpdateByte(Byte(v));\r\n  UpdateByte(Byte(v >> 8));\r\n}\r\n\r\nvoid CCRC::UpdateUInt32(UInt32 v)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n    UpdateByte((Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CCRC::UpdateUInt64(UInt64 v)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n    UpdateByte((Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CCRC::Update(const void *data, size_t size)\r\n{\r\n  UInt32 v = _value;\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);\r\n  _value = v;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/CRC.h",
    "content": "// Common/CRC.h\r\n\r\n#ifndef __COMMON_CRC_H\r\n#define __COMMON_CRC_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nclass CCRC\r\n{\r\n  UInt32 _value;\r\npublic:\r\n\tstatic UInt32 Table[256];\r\n\tstatic void InitTable();\r\n\r\n  CCRC():  _value(0xFFFFFFFF){};\r\n  void Init() { _value = 0xFFFFFFFF; }\r\n  void UpdateByte(Byte v);\r\n  void UpdateUInt16(UInt16 v);\r\n  void UpdateUInt32(UInt32 v);\r\n  void UpdateUInt64(UInt64 v);\r\n  void Update(const void *data, size_t size);\r\n  UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } \r\n  static UInt32 CalculateDigest(const void *data, size_t size)\r\n  {\r\n    CCRC crc;\r\n    crc.Update(data, size);\r\n    return crc.GetDigest();\r\n  }\r\n  static bool VerifyDigest(UInt32 digest, const void *data, size_t size)\r\n  {\r\n    return (CalculateDigest(data, size) == digest);\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else \r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  while (true)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      return;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{ \r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */); \r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms, \r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0) \r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while(pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len) \r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString: \r\n      case NSwitchType::kUnLimitedPostString: \r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for(int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString)\r\n{\r\n  for(int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if(commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\nbool ParseSubCharsCommand(int numForms, const CCommandSubCharsSet *forms, \r\n    const UString &commandString, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numUsedChars = 0;\r\n  for(int i = 0; i < numForms; i++)\r\n  {\r\n    const CCommandSubCharsSet &set = forms[i];\r\n    int currentIndex = -1;\r\n    int len = MyStringLen(set.Chars);\r\n    for(int j = 0; j < len; j++)\r\n    {\r\n      wchar_t c = set.Chars[j];\r\n      int newIndex = commandString.Find(c);\r\n      if (newIndex >= 0)\r\n      {\r\n        if (currentIndex >= 0)\r\n          return false;\r\n        if (commandString.Find(c, newIndex + 1) >= 0)\r\n          return false;\r\n        currentIndex = j;\r\n        numUsedChars++;\r\n      }\r\n    }\r\n    if(currentIndex == -1 && !set.EmptyAllowed)\r\n      return false;\r\n    indices.Add(currentIndex);\r\n  }\r\n  return (numUsedChars == commandString.Length());\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"Common/String.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  { \r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms); \r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms, \r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString);\r\n\r\nstruct CCommandSubCharsSet\r\n{\r\n  wchar_t *Chars;\r\n  bool EmptyAllowed;\r\n};\r\n\r\n// Returns: indices of finded chars; -1 if there is no match\r\nbool ParseSubCharsCommand(int numForms, const CCommandSubCharsSet *forms, \r\n    const UString &commandString, CIntVector &indices);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p) \r\n  { \r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p) \r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR() { m_str = NULL; }\r\n  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR pSrc)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(pSrc);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const \r\n  { \r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memmove(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  void Attach(BSTR src) {  m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) { \r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline bool operator==(REFGUID g1, REFGUID g2)\r\n{ \r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return false;\r\n  return true;\r\n}\r\ninline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct \r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else \r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#else\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall \r\n#else\r\n#define STDMETHODCALLTYPE \r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct \r\n\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\t\r\n  VT_EMPTY\t= 0,\r\n\tVT_NULL\t= 1,\r\n\tVT_I2\t= 2,\r\n\tVT_I4\t= 3,\r\n\tVT_R4\t= 4,\r\n\tVT_R8\t= 5,\r\n\tVT_CY\t= 6,\r\n\tVT_DATE\t= 7,\r\n\tVT_BSTR\t= 8,\r\n\tVT_DISPATCH\t= 9,\r\n\tVT_ERROR\t= 10,\r\n\tVT_BOOL\t= 11,\r\n\tVT_VARIANT\t= 12,\r\n\tVT_UNKNOWN\t= 13,\r\n\tVT_DECIMAL\t= 14,\r\n\tVT_I1\t= 16,\r\n\tVT_UI1\t= 17,\r\n\tVT_UI2\t= 18,\r\n\tVT_UI4\t= 19,\r\n\tVT_I8\t= 20,\r\n\tVT_UI8\t= 21,\r\n\tVT_INT\t= 22,\r\n\tVT_UINT\t= 23,\r\n\tVT_VOID\t= 24,\r\n\tVT_HRESULT\t= 25,\r\n\tVT_FILETIME\t= 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union \r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\t\r\n  STREAM_SEEK_SET\t= 0,\r\n  STREAM_SEEK_CUR\t= 1,\r\n  STREAM_SEEK_END\t= 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\nvoid * \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw();\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/String.cpp",
    "content": "// Common/String.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"StringConvert.h\"\r\n#else\r\n#include <ctype.h>\r\n#endif\r\n\r\n#include \"Common/String.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{ \r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1), \r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), \r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{ \r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/String.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"Vector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\nstatic const char *kTrimDefaultCharSet  = \" \\n\\t\";\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{ \r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{ \r\n  T *destStart = dest;\r\n  while((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)CharUpperA((LPSTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)CharUpperW((LPWSTR)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)CharLowerA((LPSTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)CharLowerW((LPWSTR)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char  *s2);\r\n#endif\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex, \r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n\tint _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if(realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if(newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if(_capacity > 0)\r\n    {\r\n      for (int i = 0; i < (_length + 1); i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n      _chars = newBuffer;\r\n    }\r\n    else\r\n    {\r\n      _chars = newBuffer;\r\n      _chars[0] = 0;\r\n    }\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize) \r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0)\r\n    { SetCapacity(16 - 1); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;} \r\n\r\n  // The minimum size of the character buffer in characters. \r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if(minBufLength >= _capacity)\r\n      SetCapacity(minBufLength + 1);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if(newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length; \r\n    return *this;\r\n  }  \r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if(&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    while (true)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    while (true)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for(int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    for(int i = 0; i < (int)(sizeof(kTrimDefaultCharSet) /\r\n      sizeof(kTrimDefaultCharSet[0])); i++)\r\n      charSet += (T)kTrimDefaultCharSet[i];\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for(int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0) \r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0) \r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()), \r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 2;\r\n    int numChars = WideCharToMultiByte(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(numRequiredBytes), \r\n      numRequiredBytes + 1, NULL, NULL);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"Common/String.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT codePage)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\ntypedef unsigned char Byte;\r\ntypedef short Int16;\r\ntypedef unsigned short UInt16;\r\ntypedef int Int32;\r\ntypedef unsigned int UInt32;\r\n#ifdef _MSC_VER\r\ntypedef __int64 Int64;\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef long long int Int64;\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/Vector.cpp",
    "content": "// Common/Vector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"Vector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector()\r\n  { delete []((unsigned char *)_items); }\r\nvoid CBaseRecordVector::Clear() \r\n  { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() \r\n  { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index)\r\n  { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if(_size != _capacity)\r\n    return;\r\n  int delta;\r\n  if (_capacity > 64)\r\n    delta = _capacity / 2;\r\n  else if (_capacity > 8)\r\n    delta = 8;\r\n  else\r\n    delta = 4;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  if(newCapacity <= _capacity)\r\n    return;\r\n  /*\r\n  #ifndef _DEBUG\r\n  static const unsigned int kMaxVectorSize = 0xF0000000;\r\n  if(newCapacity < _size || \r\n      ((unsigned int )newCapacity * (unsigned int )_itemSize) > kMaxVectorSize) \r\n    throw 1052354;\r\n  #endif\r\n  */\r\n  unsigned char *p = new unsigned char[newCapacity * _itemSize];\r\n  int numRecordsToMove = _capacity;\r\n  memmove(p, _items, _itemSize * numRecordsToMove);\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize, \r\n    ((unsigned char  *)_items) + srcIndex * _itemSize, \r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Common/Vector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n\tint _capacity;\r\n  int _size;\r\n\tvoid *_items;\r\n  size_t _itemSize;\r\n\r\n\tvoid ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; } \r\npublic:\r\n  CBaseRecordVector(size_t itemSize):\r\n      _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n\tvirtual ~CBaseRecordVector();\r\n  int Size() const { return _size; }\r\n\tbool IsEmpty() const { return (_size == 0); }\r\n\tvoid Reserve(int newCapacity);\r\n\tvirtual void Delete(int index, int num = 1);\r\n\tvoid Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector():CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v):\r\n    CBaseRecordVector(sizeof(T)) { *this = v;}\r\n\tCRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n\tint Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n\tvoid Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n\tT& operator[](int index) { return ((T *)_items)[index]; }\r\n\tconst T& Front() const { return operator[](0); }\r\n  T& Front()   { return operator[](0); }\r\n\tconst T& Back() const { return operator[](_size - 1); }\r\n  T& Back()   { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  void Sort(int left, int right)\r\n  { \r\n    if (right - left < 2)\r\n      return;\r\n    Swap(left, (left + right) / 2);\r\n    int last = left;\r\n    for (int i = left; i < right; i++)\r\n      if (operator[](i) < operator[](left))\r\n        Swap(++last, i);\r\n    Swap(left, last);\r\n    Sort(left, last);\r\n    Sort(last + 1, right);\r\n  }\r\n  void Sort() { Sort(0, Size());  }\r\n  void Sort(int left, int right, int (*compare)(const T*, const T*, void *), void *param)\r\n  { \r\n    if (right - left < 2)\r\n      return;\r\n    Swap(left, (left + right) / 2);\r\n    int last = left;\r\n    for (int i = left; i < right; i++)\r\n      if (compare(&operator[](i), &operator[](left), param) < 0)\r\n        Swap(++last, i);\r\n    Swap(left, last);\r\n    Sort(left, last, compare, param);\r\n    Sort(last + 1, right, compare, param);\r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param) \r\n  {  \r\n    Sort(0, Size(), compare, param);  \r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector(){};\r\n  ~CObjectVector() { Clear(); }\r\n  CObjectVector(const CObjectVector &objectVector)\r\n    { *this = objectVector; }\r\n\tCObjectVector& operator=(const CObjectVector &objectVector)\r\n  {\r\n    Clear();\r\n    return (*this += objectVector);\r\n  }\r\n\tCObjectVector& operator+=(const CObjectVector &objectVector)\r\n  {\r\n    int size = objectVector.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(objectVector[i]);\r\n    return *this;\r\n  }\r\n\tconst T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n\tT& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n\tT& Front() { return operator[](0); }\r\n\tconst T& Front() const { return operator[](0); }\r\n\tT& Back() { return operator[](_size - 1); }\r\n\tconst T& Back() const { return operator[](_size - 1); }\r\n\tint Add(const T& item)\r\n    { return CPointerVector::Add(new T(item)); }\r\n\tvoid Insert(int index, const T& item)\r\n    { CPointerVector::Insert(index, new T(item)); }\r\n\tvirtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for(int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for(int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n      return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param) \r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void *param)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  Close();\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE) NULL);\r\n  return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    Close();\r\n    _handle = ::CreateFileW(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE) NULL);\r\n    return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));\r\n  }\r\n  return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP), \r\n    desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(!_fileIsOpen)\r\n    return true;\r\n  bool result = BOOLToBool(::CloseHandle(_handle));\r\n  _fileIsOpen = !result;\r\n  return result;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if(sizeLow == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR) \r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if(!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CreationTime = winFileInfo.ftCreationTime;\r\n  fileInfo.LastAccessTime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.LastWriteTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes; \r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 24);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, creationTime, lastAccessTime, lastWriteTime)); }\r\n\r\nbool COutFile::SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {  return SetTime(NULL, NULL, lastWriteTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if(!Seek(length, newPosition))\r\n    return false;\r\n  if(newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{ \r\n  DWORD    Attributes; \r\n  FILETIME CreationTime; \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime; \r\n  DWORD    VolumeSerialNumber; \r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks; \r\n  UInt64   FileIndex; \r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  bool _fileIsOpen;\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _fileIsOpen(false){};\r\n  virtual ~CFileBase();\r\n\r\n  virtual bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition); \r\n  bool SeekToBegin(); \r\n  bool SeekToEnd(UInt64 &newPosition); \r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/C/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CPL.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n<HTML><HEAD><TITLE>Common Public License - v 1.0</TITLE>\r\n<META http-equiv=Content-Type content=\"text/html; charset=ISO-8859-1\">\r\n<BODY vLink=#800000 bgColor=#ffffff>\r\n<P align=center><B>Common Public License - v 1.0</B> \r\n<P><B></B><FONT size=3></FONT>\r\n<P><FONT size=3></FONT><FONT size=2>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER \r\nTHE TERMS OF THIS COMMON PUBLIC LICENSE (\"AGREEMENT\"). ANY USE, REPRODUCTION OR \r\nDISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS \r\nAGREEMENT.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2><B>1. DEFINITIONS</B></FONT> \r\n<P><FONT size=2>\"Contribution\" means:</FONT> \r\n<UL><FONT size=2>a) in the case of the initial Contributor, the initial code \r\n  and documentation distributed under this Agreement, and<BR clear=left>b) in \r\n  the case of each subsequent Contributor:</FONT></UL>\r\n<UL><FONT size=2>i) changes to the Program, and</FONT></UL>\r\n<UL><FONT size=2>ii) additions to the Program;</FONT></UL>\r\n<UL><FONT size=2>where such changes and/or additions to the Program originate \r\n  from and are distributed by that particular Contributor. </FONT><FONT size=2>A \r\n  Contribution 'originates' from a Contributor if it was added to the Program by \r\n  such Contributor itself or anyone acting on such Contributor's behalf. \r\n  </FONT><FONT size=2>Contributions do not include additions to the Program \r\n  which: (i) are separate modules of software distributed in conjunction with \r\n  the Program under their own license agreement, and (ii) are not derivative \r\n  works of the Program. </FONT></UL>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>\"Contributor\" means any person or entity that distributes the \r\nProgram.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2>\"Licensed Patents \" mean patent claims licensable by a \r\nContributor which are necessarily infringed by the use or sale of its \r\nContribution alone or when combined with the Program. </FONT>\r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2>\"Program\" means the Contributions \r\ndistributed in accordance with this Agreement.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>\"Recipient\" means anyone who receives the Program under this \r\nAgreement, including all Contributors.</FONT> \r\n<P><FONT size=2><B></B></FONT>\r\n<P><FONT size=2><B>2. GRANT OF RIGHTS</B></FONT> \r\n<UL><FONT size=2></FONT><FONT size=2>a) </FONT><FONT size=2>Subject to the \r\n  terms of this Agreement, each Contributor hereby grants</FONT><FONT size=2> \r\n  Recipient a non-exclusive, worldwide, royalty-free copyright license \r\n  to</FONT><FONT color=#ff0000 size=2> </FONT><FONT size=2>reproduce, prepare \r\n  derivative works of, publicly display, publicly perform, distribute and \r\n  sublicense the Contribution of such Contributor, if any, and such derivative \r\n  works, in source code and object code form.</FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2></FONT><FONT size=2>b) Subject to the terms of this \r\n  Agreement, each Contributor hereby grants </FONT><FONT size=2>Recipient a \r\n  non-exclusive, worldwide,</FONT><FONT color=#008000 size=2> </FONT><FONT \r\n  size=2>royalty-free patent license under Licensed Patents to make, use, sell, \r\n  offer to sell, import and otherwise transfer the Contribution of such \r\n  Contributor, if any, in source code and object code form. This patent license \r\n  shall apply to the combination of the Contribution and the Program if, at the \r\n  time the Contribution is added by the Contributor, such addition of the \r\n  Contribution causes such combination to be covered by the Licensed Patents. \r\n  The patent license shall not apply to any other combinations which include the \r\n  Contribution. No hardware per se is licensed hereunder. </FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2>c) Recipient understands that although each Contributor \r\n  grants the licenses to its Contributions set forth herein, no assurances are \r\n  provided by any Contributor that the Program does not infringe the patent or \r\n  other intellectual property rights of any other entity. Each Contributor \r\n  disclaims any liability to Recipient for claims brought by any other entity \r\n  based on infringement of intellectual property rights or otherwise. As a \r\n  condition to exercising the rights and licenses granted hereunder, each \r\n  Recipient hereby assumes sole responsibility to secure any other intellectual \r\n  property rights needed, if any. For example, if a third party patent license \r\n  is required to allow Recipient to distribute the Program, it is Recipient's \r\n  responsibility to acquire that license before distributing the \r\nProgram.</FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2>d) Each Contributor represents that to its knowledge it has \r\n  sufficient copyright rights in its Contribution, if any, to grant the \r\n  copyright license set forth in this Agreement. </FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<P><FONT size=2><B>3. REQUIREMENTS</B></FONT> \r\n<P><FONT size=2><B></B>A Contributor may choose to distribute the Program in \r\nobject code form under its own license agreement, provided that:</FONT> \r\n<UL><FONT size=2>a) it complies with the terms and conditions of this \r\n  Agreement; and</FONT></UL>\r\n<UL><FONT size=2>b) its license agreement:</FONT></UL>\r\n<UL><FONT size=2>i) effectively disclaims</FONT><FONT size=2> on behalf of all \r\n  Contributors all warranties and conditions, express and implied, including \r\n  warranties or conditions of title and non-infringement, and implied warranties \r\n  or conditions of merchantability and fitness for a particular purpose; \r\n</FONT></UL>\r\n<UL><FONT size=2>ii) effectively excludes on behalf of all Contributors all \r\n  liability for damages, including direct, indirect, special, incidental and \r\n  consequential damages, such as lost profits; </FONT></UL>\r\n<UL><FONT size=2>iii)</FONT><FONT size=2> states that any provisions which \r\n  differ from this Agreement are offered by that Contributor alone and not by \r\n  any other party; and</FONT></UL>\r\n<UL><FONT size=2>iv) states that source code for the Program is available from \r\n  such Contributor, and informs licensees how to obtain it in a reasonable \r\n  manner on or through a medium customarily used for software \r\n  exchange.</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 \r\n  size=2></FONT></UL>\r\n<UL><FONT color=#ff0000 size=2></FONT><FONT size=2></FONT></UL>\r\n<P><FONT size=2>When the Program is made available in source code form:</FONT> \r\n<UL><FONT size=2>a) it must be made available under this Agreement; and \r\n</FONT></UL>\r\n<UL><FONT size=2>b) a copy of this Agreement must be included with each copy \r\n  of the Program. </FONT></UL>\r\n<P><FONT size=2></FONT><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT>\r\n<P><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT><FONT size=2>Contributors \r\nmay not remove or alter any copyright notices contained within the Program. \r\n</FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>Each Contributor must identify itself as the originator of its \r\nContribution, if any, in a manner that reasonably allows subsequent Recipients \r\nto identify the originator of the Contribution. </FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2><B>4. COMMERCIAL DISTRIBUTION</B></FONT> \r\n<P><FONT size=2>Commercial distributors of software may accept certain \r\nresponsibilities with respect to end users, business partners and the like. \r\nWhile this license is intended to facilitate the commercial use of the Program, \r\nthe Contributor who includes the Program in a commercial product offering should \r\ndo so in a manner which does not create potential liability for other \r\nContributors. Therefore, if a Contributor includes the Program in a commercial \r\nproduct offering, such Contributor (\"Commercial Contributor\") hereby agrees to \r\ndefend and indemnify every other Contributor (\"Indemnified Contributor\") against \r\nany losses, damages and costs (collectively \"Losses\") arising from claims, \r\nlawsuits and other legal actions brought by a third party against the \r\nIndemnified Contributor to the extent caused by the acts or omissions of such \r\nCommercial Contributor in connection with its distribution of the Program in a \r\ncommercial product offering. The obligations in this section do not apply to any \r\nclaims or Losses relating to any actual or alleged intellectual property \r\ninfringement. In order to qualify, an Indemnified Contributor must: a) promptly \r\nnotify the Commercial Contributor in writing of such claim, and b) allow the \r\nCommercial Contributor to control, and cooperate with the Commercial Contributor \r\nin, the defense and any related settlement negotiations. The Indemnified \r\nContributor may participate in any such claim at its own expense.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>For example, a Contributor might include the Program in a \r\ncommercial product offering, Product X. That Contributor is then a Commercial \r\nContributor. If that Commercial Contributor then makes performance claims, or \r\noffers warranties related to Product X, those performance claims and warranties \r\nare such Commercial Contributor's responsibility alone. Under this section, the \r\nCommercial Contributor would have to defend claims against the other \r\nContributors related to those performance claims and warranties, and if a court \r\nrequires any other Contributor to pay any damages as a result, the Commercial \r\nContributor must pay those damages.</FONT> \r\n<P><FONT size=2></FONT><FONT color=#0000ff size=2></FONT>\r\n<P><FONT color=#0000ff size=2></FONT><FONT size=2><B>5. NO WARRANTY</B></FONT> \r\n<P><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS \r\nPROVIDED ON AN \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r\nEITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR \r\nCONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A \r\nPARTICULAR PURPOSE. Each Recipient is</FONT><FONT size=2> solely responsible for \r\ndetermining the appropriateness of using and distributing </FONT><FONT \r\nsize=2>the Program</FONT><FONT size=2> and assumes all risks associated with its \r\nexercise of rights under this Agreement</FONT><FONT size=2>, including but not \r\nlimited to the risks and costs of program errors, compliance with applicable \r\nlaws, damage to or loss of data, </FONT><FONT size=2>programs or equipment, and \r\nunavailability or interruption of operations</FONT><FONT size=2>. </FONT><FONT \r\nsize=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2><B>6. DISCLAIMER OF LIABILITY</B></FONT> \r\n<P><FONT size=2></FONT><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS \r\nAGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR \r\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r\n</FONT><FONT size=2>(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT \r\nsize=2> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, \r\nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \r\nOUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS \r\nGRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2><B>7. GENERAL</B></FONT> \r\n<P><FONT size=2></FONT><FONT size=2>If any provision of this Agreement is \r\ninvalid or unenforceable under applicable law, it shall not affect the validity \r\nor enforceability of the remainder of the terms of this Agreement, and without \r\nfurther action by the parties hereto, such provision shall be reformed to the \r\nminimum extent necessary to make such provision valid and enforceable.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>If Recipient institutes patent litigation against a Contributor \r\nwith respect to a patent applicable to software (including a cross-claim or \r\ncounterclaim in a lawsuit), then any patent licenses granted by that Contributor \r\nto such Recipient under this Agreement shall terminate as of the date such \r\nlitigation is filed. In addition, if Recipient institutes patent litigation \r\nagainst any entity (including a cross-claim or counterclaim in a lawsuit) \r\nalleging that the Program itself (excluding combinations of the Program with \r\nother software or hardware) infringes such Recipient's patent(s), then such \r\nRecipient's rights granted under Section 2(b) shall terminate as of the date \r\nsuch litigation is filed. </FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>All Recipient's rights under this Agreement shall terminate if \r\nit fails to comply with any of the material terms or conditions of this \r\nAgreement and does not cure such failure in a reasonable period of time after \r\nbecoming aware of such noncompliance. If all Recipient's rights under this \r\nAgreement terminate, Recipient agrees to cease use and distribution of the \r\nProgram as soon as reasonably practicable. However, Recipient's obligations \r\nunder this Agreement and any licenses granted by Recipient relating to the \r\nProgram shall continue and survive. </FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2>Everyone is permitted to copy and distribute \r\ncopies of this Agreement, but in order to avoid inconsistency the Agreement is \r\ncopyrighted and may only be modified in the following manner. The Agreement \r\nSteward reserves the right to </FONT><FONT size=2>publish new versions \r\n(including revisions) of this Agreement from time to </FONT><FONT size=2>time. \r\nNo one other than the Agreement Steward has the right to modify this Agreement. \r\nIBM is the initial Agreement Steward. IBM may assign the responsibility to serve \r\nas the Agreement Steward to a suitable separate entity. </FONT><FONT size=2>Each \r\nnew version of the Agreement will be given a distinguishing version number. The \r\nProgram (including Contributions) may always be distributed subject to the \r\nversion of the Agreement under which it was received. In addition, after a new \r\nversion of the Agreement is published, Contributor may elect to distribute the \r\nProgram (including its Contributions) under the new </FONT><FONT size=2>version. \r\n</FONT><FONT size=2>Except as expressly stated in Sections 2(a) and 2(b) above, \r\nRecipient receives no rights or licenses to the intellectual property of any \r\nContributor under this Agreement, whether expressly, </FONT><FONT size=2>by \r\nimplication, estoppel or otherwise</FONT><FONT size=2>.</FONT><FONT size=2> All \r\nrights in the Program not expressly granted under this Agreement are \r\nreserved.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>This Agreement is governed by the laws of the State of New York \r\nand the intellectual property laws of the United States of America. No party to \r\nthis Agreement will bring a legal action under this Agreement more than one year \r\nafter the cause of action arose. Each party waives its rights to a jury trial in \r\nany resulting litigation.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT></P></BODY></HTML>\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid Init(System.IO.Stream inStream);\r\n\t\tvoid ReleaseStream();\r\n\t\tvoid MovePos();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetLongestMatch(UInt32[] distances);\r\n\t\tvoid DummyLongestMatch();\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize;\r\n\t\tUInt32 _historySize;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\t// UInt32 []_dummy;\r\n\t\tUInt32[] _son;\r\n\r\n\t\tUInt32[] _hash;\r\n\t\tUInt32[] _hash2;\r\n\t\tUInt32[] _hash3;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\t\tbool HASH_BIG = false;\r\n\r\n\t\tconst UInt32 kHash3Size = 1 << 18;\r\n\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kBT4Hash2Size = 1 << 10;\r\n\t\tconst UInt32 kBT4Hash4Size = 1 << 20;\r\n\t\tconst UInt32 kBT4bHash4Size = 1 << 23;\r\n\t\tconst UInt32 kBT2NumHashDirectBytes = 2;\r\n\t\tconst UInt32 kBT4NumHashDirectBytes = 0;\r\n\r\n\t\tUInt32 kHash2Size = kBT4Hash2Size;\r\n\t\tUInt32 kNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\t\tUInt32 kNumHashBytes = 4;\r\n\t\tUInt32 kHashSize = kBT4Hash4Size;\r\n\r\n\t\tpublic void SetType(int numHashBytes, bool big)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = numHashBytes > 2;\r\n\t\t\tHASH_BIG = big;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkHash2Size = kBT4Hash2Size;\r\n\t\t\t\tkNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\t\t\t\tkNumHashBytes = 4;\r\n\t\t\t\tkHashSize = HASH_BIG ? kBT4bHash4Size : kBT4Hash4Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = kBT2NumHashDirectBytes;\r\n\t\t\t\tkNumHashBytes = 2;\r\n\t\t\t\tkHashSize = kBT2HashSize;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\r\n\t\tUInt32 Hash(UInt32 offset, out UInt32 hash2Value, out UInt32 hash3Value)\r\n\t\t{\r\n\t\t\tUInt32 temp = CRC.Table[_bufferBase[offset]] ^ _bufferBase[offset + 1];\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((UInt32)(_bufferBase[offset + 2]) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\treturn (temp ^ (CRC.Table[_bufferBase[offset + 3]] << 5)) & (kHashSize - 1);\r\n\t\t}\r\n\r\n\t\tUInt32 Hash(UInt32 offset)\r\n\t\t{\r\n\t\t\treturn _bufferBase[offset] ^ ((UInt32)(_bufferBase[offset + 1]) << 8);\r\n\t\t}\r\n\r\n\t\tpublic new void Init(System.IO.Stream inStream)\r\n\t\t{\r\n\t\t\tbase.Init(inStream);\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < kHashSize; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tfor (i = 0; i < kHash2Size; i++)\r\n\t\t\t\t\t_hash2[i] = kEmptyHashValue;\r\n\t\t\t\tfor (i = 0; i < kHash3Size; i++)\r\n\t\t\t\t\t_hash3[i] = kEmptyHashValue;\r\n\t\t\t}\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\t_cyclicBufferPos++;\r\n\t\t\tif (_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\t// _dummy = new UInt32[matchMaxLen + 1];\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\t_son = null;\r\n\t\t\t_hash = null;\r\n\t\t\t_hash2 = null;\r\n\t\t\t_hash3 = null;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\tif (_blockSize + 256 > kMaxValForNormalize)\r\n\t\t\t\tthrow new Exception();\r\n\r\n\t\t\t_historySize = historySize;\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\t_cyclicBufferSize = historySize + 1;\r\n\t\t\t_son = new UInt32[_cyclicBufferSize * 2];\r\n\r\n\t\t\t_hash = new UInt32[kHashSize];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\t_hash2 = new UInt32[kHash2Size];\r\n\t\t\t\t_hash3 = new UInt32[kHash3Size];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetLongestMatch(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\tUInt32 matchHashLenMax = 0;\r\n\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t\thashValue = Hash(cur, out hash2Value, out hash3Value);\r\n\t\t\telse\r\n\t\t\t\thashValue = Hash(cur);\r\n\r\n\t\t\tUInt32 curMatch = _hash[hashValue];\r\n\t\t\tUInt32 curMatch2 = 0, curMatch3 = 0;\r\n\t\t\tUInt32 len2Distance = 0;\r\n\t\t\tUInt32 len3Distance = 0;\r\n\t\t\tbool matchLen2Exist = false;\r\n\t\t\tbool matchLen3Exist = false;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\t\tif (curMatch2 >= matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen2Distance = _pos - curMatch2 - 1;\r\n\t\t\t\t\t\tmatchHashLenMax = 2;\r\n\t\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t\t\t\tif (curMatch3 >= matchMinPos)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tlen3Distance = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\t\tmatchHashLenMax = 3;\r\n\t\t\t\t\t\t\tmatchLen3Exist = true;\r\n\t\t\t\t\t\t\tif (matchLen2Exist)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (len3Distance < len2Distance)\r\n\t\t\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[hashValue] = _pos;\r\n\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t{\r\n\t\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t}\r\n\t\t\t\treturn matchHashLenMax;\r\n\t\t\t}\r\n\t\t\tUInt32 ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptrRight = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 maxLen, minLeft, minRight;\r\n\t\t\tmaxLen = minLeft = minRight = kNumHashDirectBytes;\r\n\r\n\t\t\tdistances[maxLen] = _pos - curMatch - 1;\r\n\r\n\t\t\tfor (UInt32 count = _cutValue; count > 0; count--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 currentLen = Math.Min(minLeft, minRight);\r\n\t\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\twhile (currentLen > maxLen)\r\n\t\t\t\t\tdistances[++maxLen] = delta - 1;\r\n\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tif (currentLen != lenLimit)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] < _bufferBase[cur + currentLen])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\r\n\t\t\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (matchLen2Exist && len2Distance < distances[2])\r\n\t\t\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\t\t\tif (matchLen3Exist && len3Distance < distances[3])\r\n\t\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\treturn maxLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t\t_son[ptrRight] = kEmptyHashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tif (matchLen2Exist)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (maxLen < 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\t\tmaxLen = 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (len2Distance < distances[2])\r\n\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tif (matchLen3Exist)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (maxLen < 3)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t\t\tmaxLen = 3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (len3Distance < distances[3])\r\n\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn maxLen;\r\n\t\t}\r\n\r\n\t\tpublic void DummyLongestMatch()\r\n\t\t{\r\n\t\t\t// GetLongestMatch(_dummy);\r\n\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t\thashValue = Hash(cur, out hash2Value, out hash3Value);\r\n\t\t\telse\r\n\t\t\t\thashValue = Hash(cur);\r\n\r\n\t\t\tUInt32 curMatch = _hash[hashValue];\r\n\t\t\tUInt32 curMatch2 = 0, curMatch3 = 0;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t\t}\r\n\t\t\t_hash[hashValue] = _pos;\r\n\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t{\r\n\t\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tUInt32 ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptrRight = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 minLeft, minRight;\r\n\t\t\tminLeft = minRight = kNumHashDirectBytes;\r\n\r\n\t\t\tfor (UInt32 count = _cutValue; count > 0; count--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 currentLen = Math.Min(minLeft, minRight);\r\n\t\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tif (currentLen != lenLimit)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] < _bufferBase[cur + currentLen])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t\t_son[ptrRight] = kEmptyHashValue;\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 startItem = _pos - _historySize;\r\n\t\t\tUInt32 subValue = startItem - 1;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\r\n\t\t\tNormalizeLinks(_hash, kHashSize, subValue);\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tNormalizeLinks(_hash2, kHash2Size, subValue);\r\n\t\t\t\tNormalizeLinks(_hash3, kHash3Size, subValue);\r\n\t\t\t}\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize;  // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos;             // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\t\tUInt32 _keepSizeReserv;  // how many BYTEs must be kept as reserv\r\n\t\tpublic UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic virtual void BeforeMoveBlock() { }\r\n\t\tpublic virtual void AfterMoveBlock() { }\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tBeforeMoveBlock();\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t\tAfterMoveBlock();\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\t_keepSizeReserv = keepSizeReserv;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t_stream = stream;\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++) ;\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream) { Init(stream, false); }\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t  public bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\tpublic const int kDicLogSizeMax = 28;\r\n\t\tpublic const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get  { return 0; }}\r\n\t\tpublic override long Position  \r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t\tBT4B\r\n\t\t};\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t\t\"BT4B\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1024];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 20;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 10))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 19))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 9] + 18);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 18] + 36);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 16))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 25))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 15] + 30);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 24] + 48);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 20;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax]; // kNumLowBits\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax]; // kNumMidBits\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tUInt32 price = 0;\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _choice.GetPrice0();\r\n\t\t\t\t\tprice += _lowCoder[posState].GetPrice(symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\tprice += _choice.GetPrice1();\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprice += _choice2.GetPrice0();\r\n\t\t\t\t\t\tprice += _midCoder[posState].GetPrice(symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprice += _choice2.GetPrice1();\r\n\t\t\t\t\t\tprice += _highCoder.GetPrice(symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic new UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[(symbol << Base.kNumPosStatesBitsEncodingMax) + posState];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 len = 0; len < _tableSize; len++)\r\n\t\t\t\t\t_prices[(len << Base.kNumPosStatesBitsEncodingMax) + posState] = base.GetPrice(len, posState);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;         // posNext;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\t// public UInt32 []Backs = new UInt32[Base.kNumRepDistances];\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\r\n\t\tLZ.IMatchFinder _matchFinder = null; // test it\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen + 1];\r\n\t\tbool _fastMode = false;\r\n\t\tbool _maxMode = false;\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[Base.kDistTableSizeMax << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 lastPosSlotFillingPos;\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\r\n\t\tSystem.IO.Stream _inStream;\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark;\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\t// _rangeEncoder.Create(1 << 20);\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tbool big = false;\r\n\t\t\t\tswitch (_matchFinderType)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase EMatchFinderType.BT2:\r\n\t\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase EMatchFinderType.BT4:\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase EMatchFinderType.BT4B:\r\n\t\t\t\t\t\tbig = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tbt.SetType(numHashBytes, big);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes,\r\n\t\t\t\tBase.kMatchMaxLen * 2 + 1 - _numFastBytes);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes)\r\n\t\t{\r\n\t\t\tlenRes = _matchFinder.GetLongestMatch(_matchDistances);\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes, _matchDistances[lenRes],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t_additionalOffset++;\r\n\t\t\t_matchFinder.MovePos();\r\n\t\t}\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tfor (; num > 0; num--)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.DummyLongestMatch();\r\n\t\t\t\t_matchFinder.MovePos();\r\n\t\t\t\t_additionalOffset++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice += _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tif (len == 2 && pos >= 0x80)\r\n\t\t\t\treturn kIfinityPrice;\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(pos << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(GetPosSlot2(pos) << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_optimumEndIndex = 0; // test it;\r\n\r\n\t\t\tUInt32 lenMain;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tUInt32 backMain = (lenMain < _numFastBytes) ? _matchDistances[lenMain] :\r\n\t\t\t\t\t_matchDistances[_numFastBytes];\r\n\t\t\t\tbackRes = backMain + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tByte matchByte;\r\n\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (lenMain < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\r\n\t\t\tif (lenMain <= repLens[repMaxIndex])\r\n\t\t\t\tlenMain = 0;\r\n\r\n\t\t\tUInt32 len;\r\n\t\t\tfor (len = 2; len <= lenMain; len++)\r\n\t\t\t{\r\n\t\t\t\t_optimum[len].PosPrev = 0;\r\n\t\t\t\t_optimum[len].BackPrev = _matchDistances[len] + Base.kNumRepDistances;\r\n\t\t\t\t_optimum[len].Price = normalMatchPrice +\r\n\t\t\t\t\tGetPosLenPrice(_matchDistances[len], len, posState);\r\n\t\t\t\t_optimum[len].Prev1IsChar = false;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain < repLens[repMaxIndex])\r\n\t\t\t\tlenMain = repLens[repMaxIndex];\r\n\r\n\t\t\tfor (; len <= lenMain; len++)\r\n\t\t\t\t_optimum[len].Price = kIfinityPrice;\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tfor (UInt32 lenTest = 2; lenTest <= repLen; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\t\t\tUInt32 lenEnd = lenMain;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\t// nextIsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t/*\r\n\t\t\t\tif(newLen == 2 && _matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t*/\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tUInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (numAvailableBytes >= 3 && !nextIsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 backOffset = reps[0] + 1;\r\n\t\t\t\t\tUInt32 temp;\r\n\t\t\t\t\tfor (temp = 1; temp < numAvailableBytes; temp++)\r\n\t\t\t\t\t\t// if (data[temp] != data[(size_t)temp - backOffset])\r\n\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)temp - 1) != _matchFinder.GetIndexByte((Int32)temp - (Int32)backOffset - 1))\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tUInt32 lenTest2 = temp - 1;\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t// for (; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + 1 + lenTest2)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + 1 + lenTest2];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\t// UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n\t\t\t\t\tUInt32 backOffset = reps[repIndex] + 1;\r\n\t\t\t\t\tif (_matchFinder.GetIndexByte(-1) != \r\n\t\t\t\t\t\t  _matchFinder.GetIndexByte((Int32)(-1 - (Int32)backOffset)) ||\r\n\t\t\t\t\t\t\t_matchFinder.GetIndexByte(0) != \r\n\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)(0 - (Int32)backOffset)))\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTest;\r\n\t\t\t\t\tfor (lenTest = 2; lenTest < numAvailableBytes; lenTest++)\r\n\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)lenTest - 1) != \r\n\t\t\t\t\t\t    _matchFinder.GetIndexByte((Int32)lenTest - 1 - (Int32)backOffset))\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t  do\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (_maxMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 lenTest2 = lenTest + 1;\r\n\t\t\t\t\t\tUInt32 limit = Math.Min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)((Int32)lenTest2 - 1)) !=\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest2 - 1 - (Int32)backOffset)))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)backOffset)), \r\n\t\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t            \r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t//    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tif (newLen >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (newLen == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tnormalMatchPrice = matchPrice +\r\n\t\t\t\t\t\t_isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = newLen; lenTest >= 2; lenTest--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[lenTest];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (_maxMode && (lenTest == newLen || curBack != _matchDistances[lenTest + 1]))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 backOffset = curBack + 1;\r\n\t\t\t\t\t\t\tUInt32 lenTest2 = lenTest + 1;\r\n\t\t\t\t\t\t\tUInt32 limit = Math.Min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)lenTest2 - 1) != _matchFinder.GetIndexByte((Int32)lenTest2 - (Int32)backOffset - 1))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t// data[(size_t)lenTest - 1], \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t// data[(size_t)lenTest - backOffset], data[lenTest]\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)backOffset - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1)\r\n\t\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tUInt32 GetOptimumFast(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tUInt32 lenMain;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[_numFastBytes] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\twhile (lenMain > 2)\r\n\t\t\t{\r\n\t\t\t\tif (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tlenMain--;\r\n\t\t\t}\r\n\t\t\tif (lenMain == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\t\tlenMain = 1;\r\n\r\n\t\t\tUInt32 backMain = _matchDistances[lenMain];\r\n\t\t\tif (repLens[repMaxIndex] >= 2)\r\n\t\t\t{\r\n\t\t\t\tif (repLens[repMaxIndex] + 1 >= lenMain ||\r\n\t\t\t\t\trepLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 12)))\r\n\t\t\t\t{\r\n\t\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\t\treturn lenRes;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= 2)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out _longestMatchLength);\r\n\t\t\t\tif (_longestMatchLength >= 2 &&\r\n\t\t\t\t\t(\r\n\t\t\t\t\t(_longestMatchLength >= lenMain &&\r\n\t\t\t\t\t_matchDistances[lenMain] < backMain) ||\r\n\t\t\t\t\t_longestMatchLength == lenMain + 1 &&\r\n\t\t\t\t\t!ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\r\n\t\t\t\t\t_longestMatchLength > lenMain + 1 ||\r\n\t\t\t\t\t_longestMatchLength + 1 >= lenMain && lenMain >= 3 &&\r\n\t\t\t\t\tChangePair(_matchDistances[lenMain - 1], backMain)\r\n\t\t\t\t\t)\r\n\t\t\t\t\t)\r\n\t\t\t\t{\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n\t\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 repLen = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\t\t\tif (repLen >= 2 && repLen + 1 >= lenMain)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\t\t\treturn 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbackRes = backMain + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 2);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tvoid InitMatchFinder(LZ.IMatchFinder matchFinder)\r\n\t\t{\r\n\t\t\t_matchFinder = matchFinder;\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen; // kMatchMaxLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Init(_inStream);\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len; // it's not used\r\n\t\t\t\tReadMatchDistances(out len);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\r\n\t\t\t\tUInt32 len;\r\n\t\t\t\tif (_fastMode)\r\n\t\t\t\t\tlen = GetOptimumFast((UInt32)nowPos64, out pos);\r\n\t\t\t\telse\r\n\t\t\t\t\tlen = GetOptimum((UInt32)nowPos64, out pos);\r\n\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\r\n\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\tif (!_fastMode)\r\n\t\t\t\t\t\t\t\t\tif (--_alignPriceCount == 0)\r\n\t\t\t\t\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (!_fastMode)\r\n\t\t\t\t\tif (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFillPosSlotPrices();\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\t\tlastPosSlotFillingPos = nowPos64;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// CCoderReleaser releaser(this);\r\n\r\n\t\t\t/*\r\n\t\t\tif (_matchFinder->GetNumAvailableBytes() == 0)\r\n\t\t\t\treturn Flush();\r\n\t\t\t*/\r\n\r\n\t\t\tif (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillPosSlotPrices();\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tlastPosSlotFillingPos = 0;\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 28;\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\r\n\t\tvoid FillPosSlotPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tfor (posSlot = 0; posSlot < Base.kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\r\n\t\t\t\tfor (; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) +\r\n\t\t\t\t\t\t((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\r\n\t\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = Base.kAlignTableSize;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t\"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4, bt4b], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.32 Copyright (c) 1999-2005 Igor Pavlov  2005-12-09\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[12];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary, mf == \"bt4\");\r\n\t\t\t}\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tFileStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.40607</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\t\t\tpublic void Init() { RG.Init(); }\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\t/*\r\n\t\t\tUInt32 GetLogRand(int maxLen)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = GetRnd() % (maxLen + 1);\r\n\t\t\t\treturn GetRnd() & ((1 << len) - 1);\r\n\t\t\t}\r\n\t\t\t*/\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn RG.GetRnd(2);\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn 4 + RG.GetRnd(3);\r\n\t\t\t\treturn 12 + RG.GetRnd(4);\r\n\t\t\t}\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)(RG.GetRnd(8));\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 offset = GetOffset();\r\n\t\t\t\t\t\twhile (offset >= Pos)\r\n\t\t\t\t\t\t\toffset >>= 1;\r\n\t\t\t\t\t\toffset += 1;\r\n\t\t\t\t\t\tUInt32 len = 2 + GetLen();\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - offset];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, bool isBT4,\r\n\t\t\tUInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 numCommandsForOne;\r\n\t\t\tif (isBT4)\r\n\t\t\t{\r\n\t\t\t\tUInt64 t = GetLogSize(dictionarySize) - (19 << kSubBits);\r\n\t\t\t\tnumCommandsForOne = 2000 + ((t * t * 68) >> (2 * kSubBits));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tUInt64 t = GetLogSize(dictionarySize) - (15 << kSubBits);\r\n\t\t\t\tnumCommandsForOne = 1500 + ((t * t * 41) >> (2 * kSubBits));\r\n\t\t\t}\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime,\r\n\t\t\tUInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 250 + outSize * 21;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tbool isBT4,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tbool isBT4,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tconst string bt2 = \"BT2\";\r\n\t\tconst string bt4 = \"BT4\";\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize, bool isBT4)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\tCoderPropID.MatchFinder  \r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t\tisBT4 ? bt4: bt2\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Init();\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, isBT4, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, isBT4, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, isBT4, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "package SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\t\t\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize;\r\n\tint _historySize;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\t\r\n\tint[] _hash;\r\n\tint[] _hash2;\r\n\tint[] _hash3;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\tboolean HASH_BIG = false;\r\n\t\r\n\tstatic final int kHash3Size = 1 << 18;\r\n\t\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kBT4Hash2Size = 1 << 10;\r\n\tstatic final int kBT4Hash4Size = 1 << 20;\r\n\tstatic final int kBT4bHash4Size = 1 << 23;\r\n\tstatic final int kBT2NumHashDirectBytes = 2;\r\n\tstatic final int kBT4NumHashDirectBytes = 0;\r\n\t\r\n\tint kHash2Size = kBT4Hash2Size;\r\n\tint kNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\tint kNumHashBytes = 4;\r\n\tint kHashSize = kBT4Hash4Size;\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void SetType(int numHashBytes, boolean big)\r\n\t{\r\n\t\tHASH_ARRAY = numHashBytes > 2;\r\n\t\tHASH_BIG = big;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkHash2Size = kBT4Hash2Size;\r\n\t\t\tkNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\t\t\tkNumHashBytes = 4;\r\n\t\t\tkHashSize = (HASH_BIG ? kBT4bHash4Size : kBT4Hash4Size);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = kBT2NumHashDirectBytes;\r\n\t\t\tkNumHashBytes = 2;\r\n\t\t\tkHashSize = kBT2HashSize;\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic final int kEmptyHashValue = 0;\r\n\t\r\n\tstatic final int kMaxValForNormalize = ((int)1 << 30) - 1;\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < kHashSize; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tfor (i = 0; i < kHash2Size; i++)\r\n\t\t\t\t_hash2[i] = kEmptyHashValue;\r\n\t\t\tfor (i = 0; i < kHash3Size; i++)\r\n\t\t\t\t_hash3[i] = kEmptyHashValue;\r\n\t\t}\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\t_son = null;\r\n\t\t_hash = null;\r\n\t\t_hash2 = null;\r\n\t\t_hash3 = null;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\tif (_blockSize + 256 > kMaxValForNormalize)\r\n\t\t\treturn false;\r\n\t\t\r\n\t\t_historySize = historySize;\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\t\t\r\n\t\t_cyclicBufferSize = historySize + 1;\r\n\t\t_son = new int[_cyclicBufferSize * 2];\r\n\t\t\r\n\t\t_hash = new int[kHashSize];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\t_hash2 = new int[kHash2Size];\r\n\t\t\t_hash3 = new int[kHash3Size];\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic int GetLongestMatch(int[] distances)\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\treturn 0;\r\n\t\t}\r\n\t\t\r\n\t\tint matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\t\t\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\t\r\n\t\tint matchHashLenMax = 0;\r\n\t\t\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & (kHashSize - 1);\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8)) & (kHashSize - 1);\r\n\t\t\r\n\t\tint curMatch = _hash[hashValue];\r\n\t\tint curMatch2 = 0, curMatch3 = 0;\r\n\t\tint len2Distance = 0;\r\n\t\tint len3Distance = 0;\r\n\t\tboolean matchLen2Exist = false;\r\n\t\tboolean matchLen3Exist = false;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\tif (curMatch2 >= matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tlen2Distance = _pos - curMatch2 - 1;\r\n\t\t\t\t\tmatchHashLenMax = 2;\r\n\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t{\r\n\t\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t\t\tif (curMatch3 >= matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen3Distance = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tmatchHashLenMax = 3;\r\n\t\t\t\t\t\tmatchLen3Exist = true;\r\n\t\t\t\t\t\tif (matchLen2Exist)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (len3Distance < len2Distance)\r\n\t\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t_hash[hashValue] = _pos;\r\n\t\t\r\n\t\tif (curMatch < matchMinPos)\r\n\t\t{\r\n\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\t\t\t\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t}\r\n\t\t\treturn matchHashLenMax;\r\n\t\t}\r\n\t\tint ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptrRight = (_cyclicBufferPos << 1);\r\n\t\t\r\n\t\tint maxLen, minLeft, minRight;\r\n\t\tmaxLen = minLeft = minRight = kNumHashDirectBytes;\r\n\t\t\r\n\t\tdistances[maxLen] = _pos - curMatch - 1;\r\n\t\t\r\n\t\tfor (int count = _cutValue; count != 0; count--)\r\n\t\t{\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint currentLen = Math.min(minLeft, minRight);\r\n\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\tbreak;\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\twhile (currentLen > maxLen)\r\n\t\t\t\tdistances[++maxLen] = delta - 1;\r\n\t\t\t\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\t\t\t\r\n\t\t\tif (currentLen != lenLimit)\r\n\t\t\t{\r\n\t\t\t\tif ((_bufferBase[pby1 + currentLen] & 0xFF) < (_bufferBase[cur + currentLen] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (matchLen2Exist && len2Distance < distances[2])\r\n\t\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\t\tif (matchLen3Exist && len3Distance < distances[3])\r\n\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn maxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t_son[ptrRight] = kEmptyHashValue;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tif (matchLen2Exist)\r\n\t\t\t{\r\n\t\t\t\tif (maxLen < 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\tmaxLen = 2;\r\n\t\t\t\t}\r\n\t\t\t\telse if (len2Distance < distances[2])\r\n\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t}\r\n\t\t\t{\r\n\t\t\t\tif (matchLen3Exist)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (maxLen < 3)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t\tmaxLen = 3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (len3Distance < distances[3])\r\n\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn maxLen;\r\n\t}\r\n\t\r\n\tpublic void DummyLongestMatch()\r\n\t{\r\n\t\t// GetLongestMatch(_dummy);\r\n\t\t\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tint matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\t\t\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\t\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & (kHashSize - 1);\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8)) & (kHashSize - 1);\r\n\t\t\r\n\t\tint curMatch = _hash[hashValue];\r\n\t\tint curMatch2 = 0, curMatch3 = 0;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t}\r\n\t\t_hash[hashValue] = _pos;\r\n\t\t\r\n\t\tif (curMatch < matchMinPos)\r\n\t\t{\r\n\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tint ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptrRight = (_cyclicBufferPos << 1);\r\n\t\t\r\n\t\tint minLeft, minRight;\r\n\t\tminLeft = minRight = kNumHashDirectBytes;\r\n\t\t\r\n\t\tfor (int count = _cutValue; count != 0; count--)\r\n\t\t{\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint currentLen = Math.min(minLeft, minRight);\r\n\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\tbreak;\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\t\t\t\r\n\t\t\tif (currentLen != lenLimit)\r\n\t\t\t{\r\n\t\t\t\tif ((_bufferBase[pby1 + currentLen] & 0xFF) < (_bufferBase[cur + currentLen] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t_son[ptrRight] = kEmptyHashValue;\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint startItem = _pos - _historySize;\r\n\t\tint subValue = startItem - 1;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\r\n\t\tNormalizeLinks(_hash, kHashSize, subValue);\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tNormalizeLinks(_hash2, kHash2Size, subValue);\r\n\t\t\tNormalizeLinks(_hash3, kHash3Size, subValue);\r\n\t\t}\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue)\r\n\t{ _cutValue = cutValue; }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindows\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tint _keepSizeReserv;  // how many BYTEs must be kept as reserv\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free()\r\n\t{ _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t_keepSizeReserv = keepSizeReserv;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream)\r\n\t{ _stream = stream; \t}\r\n\r\n\tpublic void ReleaseStream()\r\n\t{ _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\r\n\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\r\n\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\tpublic static final int kDicLogSizeMax = 28;\r\n\tpublic static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\tpublic static final int EMatchFinderTypeBT4B = 2;\r\n\t\r\n\t\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\t\r\n\tstatic byte[] g_FastPos = new byte[1024];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 20;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 10))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 19))\r\n\t\t\treturn g_FastPos[pos >> 9] + 18;\r\n\t\treturn g_FastPos[pos >> 18] + 36;\r\n\t}\r\n\t\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 16))\r\n\t\t\treturn g_FastPos[pos >> 6] + 12;\r\n\t\tif (pos < (1 << 25))\r\n\t\t\treturn g_FastPos[pos >> 15] + 30;\r\n\t\treturn g_FastPos[pos >> 24] + 48;\r\n\t}\r\n\t\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\t\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\t\r\n\tstatic final int kDefaultDictionaryLogSize = 20;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\t\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\t\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\t\t\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\tint price = 0;\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\t\tprice += _lowCoder[posState].GetPrice(symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\t\t\tprice += _midCoder[posState].GetPrice(symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\t\t\tprice += _highCoder.GetPrice(symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\t};\r\n\t\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\t\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\t\t\r\n\t\tpublic void SetTableSize(int tableSize)\r\n\t\t{ _tableSize = tableSize; }\r\n\t\t\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[(symbol << Base.kNumPosStatesBitsEncodingMax) + posState];\r\n\t\t}\r\n\t\t\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tfor (int len = 0; len < _tableSize; len++)\r\n\t\t\t\t_prices[(len << Base.kNumPosStatesBitsEncodingMax) + posState] = super.GetPrice(len, posState);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\t\t\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\t\t\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\t\t\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;         // posNext;\r\n\t\tpublic int BackPrev;\r\n\t\t\r\n\t\t// public UInt32 []Backs = new UInt32[Base.kNumRepDistances];\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\t\t\r\n\t\tpublic void MakeAsChar()\r\n\t\t{ BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep()\r\n\t\t{ BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep()\r\n\t\t{ return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null; // test it\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\t\r\n\tshort[] _isMatch = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\t\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\t\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\t\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen + 1];\r\n\tboolean _fastMode = false;\r\n\tboolean _maxMode = true;\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _additionalOffset;\r\n\t\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\t\r\n\tboolean _longestMatchWasFound;\r\n\t\r\n\tint [] _posSlotPrices = new int [Base.kDistTableSizeMax << Base.kNumLenToPosStatesBits];\r\n\tint [] _distancesPrices = new int [Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\tint [] _alignPrices = new int [Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\t\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\t\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\t\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\t\r\n\tlong lastPosSlotFillingPos;\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\t\r\n\tjava.io.InputStream _inStream;\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\tboolean _needReleaseMFStream = false;\r\n\t\r\n\tvoid Create()\r\n\t{\r\n\t\t// _rangeEncoder.Create(1 << 20);\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tboolean big = false;\r\n\t\t\tswitch (_matchFinderType)\r\n\t\t\t{\r\n\t\t\t\tcase EMatchFinderTypeBT2:\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase EMatchFinderTypeBT4:\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase EMatchFinderTypeBT4B:\r\n\t\t\t\t\tbig = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tbt.SetType(numHashBytes, big);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\t\t\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes,\r\n\t\t\t\tBase.kMatchMaxLen * 2 + 1 - _numFastBytes);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\t\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\t\t\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\t\t\r\n\t\t_posAlignEncoder.Init();\r\n\t\t\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\t\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = _matchFinder.GetLongestMatch(_matchDistances);\r\n\t\tif (lenRes == _numFastBytes)\r\n\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes, _matchDistances[lenRes],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t_additionalOffset++;\r\n\t\t_matchFinder.MovePos();\r\n\t\treturn lenRes;\r\n\t}\r\n\t\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tfor (; num > 0; num--)\r\n\t\t{\r\n\t\t\t_matchFinder.DummyLongestMatch();\r\n\t\t\t_matchFinder.MovePos();\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\t\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tif (len == 2 && pos >= 0x80)\r\n\t\t\treturn kIfinityPrice;\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(pos << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(GetPosSlot2(pos) << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\t\r\n\tint Backward(int[] backRes, int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\t\t\t\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\t\t\t\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes[0] = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\t\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\t\r\n\tint GetOptimum(int position, int []backRes) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes[0] = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_optimumEndIndex = 0; // test it;\r\n\t\t\r\n\t\tint lenMain;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\t\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes[0] = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tint backMain = (lenMain < _numFastBytes) ? _matchDistances[lenMain] :\r\n\t\t\t\t_matchDistances[_numFastBytes];\r\n\t\t\tbackRes[0] = backMain + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\r\n\t\t_optimum[0].State = _state;\r\n\t\t\r\n\t\tbyte matchByte;\r\n\t\t\r\n\t\tmatchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\t\t\r\n\t\tint posState = (position & _posStateMask);\r\n\t\t\r\n\t\t_optimum[1].Price =\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\t\t\r\n\t\t_optimum[1].PosPrev = 0;\r\n\t\t\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\t\t\r\n\t\t\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\t\t\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (lenMain < 2)\r\n\t\t{\r\n\t\t\tbackRes[0] = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\t\t\r\n\t\tif (lenMain <= repLens[repMaxIndex])\r\n\t\t\tlenMain = 0;\r\n\t\t\r\n\t\tint len;\r\n\t\tfor (len = 2; len <= lenMain; len++)\r\n\t\t{\r\n\t\t\t_optimum[len].PosPrev = 0;\r\n\t\t\t_optimum[len].BackPrev = _matchDistances[len] + Base.kNumRepDistances;\r\n\t\t\t_optimum[len].Price = normalMatchPrice +\r\n\t\t\t\t\tGetPosLenPrice(_matchDistances[len], len, posState);\r\n\t\t\t_optimum[len].Prev1IsChar = false;\r\n\t\t}\r\n\t\t\r\n\t\tif (lenMain < repLens[repMaxIndex])\r\n\t\t\tlenMain = repLens[repMaxIndex];\r\n\t\t\r\n\t\tfor (; len <= lenMain; len++)\r\n\t\t\t_optimum[len].Price = kIfinityPrice;\r\n\t\t\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tfor (int lenTest = 2; lenTest <= repLen; lenTest++)\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\r\n\t\t\t\tOptimal optimum = _optimum[lenTest];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tint cur = 0;\r\n\t\tint lenEnd = lenMain;\r\n\t\t\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t{\r\n\t\t\t\treturn Backward(backRes, cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(backRes, cur);\r\n\t\t\t}\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\t\t\t\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\t\t\t\r\n\t\t\tposState = (position & _posStateMask);\r\n\t\t\t\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\t\t\t\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\t\t\t\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\t\t\t\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t// nextIsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tint numAvailableBytes = numAvailableBytesFull;\r\n\t\t\t\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (numAvailableBytes >= 3 && !nextIsChar)\r\n\t\t\t{\r\n\t\t\t\tint backOffset = reps[0] + 1;\r\n\t\t\t\tint temp;\r\n\t\t\t\tfor (temp = 1; temp < numAvailableBytes; temp++)\r\n\t\t\t\t\t// if (data[temp] != data[(size_t)temp - backOffset])\r\n\t\t\t\t\tif (_matchFinder.GetIndexByte(temp - 1) != _matchFinder.GetIndexByte(temp - backOffset - 1))\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tint lenTest2 = temp - 1;\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t// for (; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + 1 + lenTest2)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + 1 + lenTest2];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\t// int repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n\t\t\t\tint backOffset = reps[repIndex] + 1;\r\n\t\t\t\tif (_matchFinder.GetIndexByte(-1) !=\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(-1 - backOffset) ||\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(0) !=\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(0 - backOffset))\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTest;\r\n\t\t\t\tfor (lenTest = 2; lenTest < numAvailableBytes; lenTest++)\r\n\t\t\t\t\tif (_matchFinder.GetIndexByte(lenTest - 1) !=\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - backOffset))\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\t\t\t\t\r\n\t\t\t\tif (_maxMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tint lenTest2 = lenTest + 1;\r\n\t\t\t\t\tint limit = Math.min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\tif (_matchFinder.GetIndexByte(lenTest2 - 1) !=\r\n\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest2 - 1 - backOffset))\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - backOffset),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t//    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\tif (newLen >= 2)\r\n\t\t\t{\r\n\t\t\t\tif (newLen == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\r\n\t\t\t\tfor (int lenTest = newLen; lenTest >= 2; lenTest--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[lenTest];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (_maxMode && (lenTest == newLen || curBack != _matchDistances[lenTest + 1]))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint backOffset = curBack + 1;\r\n\t\t\t\t\t\tint lenTest2 = lenTest + 1;\r\n\t\t\t\t\t\tint limit = Math.min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\t\tif (_matchFinder.GetIndexByte(lenTest2 - 1) != _matchFinder.GetIndexByte(lenTest2 - backOffset - 1))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - backOffset - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1)\r\n\t\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\t\r\n\tint GetOptimumFast(int position, int[] backRes) throws IOException\r\n\t{\r\n\t\tint lenMain;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tint repMaxIndex = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes[0] = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes[0] = _matchDistances[_numFastBytes] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\t\twhile (lenMain > 2)\r\n\t\t{\r\n\t\t\tif (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\r\n\t\t\t\tbreak;\r\n\t\t\tlenMain--;\r\n\t\t}\r\n\t\tif (lenMain == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\tlenMain = 1;\r\n\t\t\r\n\t\tint backMain = _matchDistances[lenMain];\r\n\t\tif (repLens[repMaxIndex] >= 2)\r\n\t\t{\r\n\t\t\tif (repLens[repMaxIndex] + 1 >= lenMain ||\r\n\t\t\t\t\trepLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 12)))\r\n\t\t\t{\r\n\t\t\t\tbackRes[0] = repMaxIndex;\r\n\t\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif (lenMain >= 2)\r\n\t\t{\r\n\t\t\t_longestMatchLength = ReadMatchDistances();\r\n\t\t\tif (_longestMatchLength >= 2 &&\r\n\t\t\t\t\t(\r\n\t\t\t\t\t(_longestMatchLength >= lenMain &&\r\n\t\t\t\t\t_matchDistances[lenMain] < backMain) ||\r\n\t\t\t\t\t_longestMatchLength == lenMain + 1 &&\r\n\t\t\t\t\t!ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\r\n\t\t\t\t\t_longestMatchLength > lenMain + 1 ||\r\n\t\t\t\t\t_longestMatchLength + 1 >= lenMain && lenMain >= 3 &&\r\n\t\t\t\t\tChangePair(_matchDistances[lenMain - 1], backMain)\r\n\t\t\t\t\t)\r\n\t\t\t\t\t)\r\n\t\t\t{\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\tbackRes[0] = -1;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tint repLen = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLen >= 2 && repLen + 1 >= lenMain)\r\n\t\t\t\t{\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\tbackRes[0] = -1;\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbackRes[0] = backMain + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 2);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\t\tbackRes[0] = -1;\r\n\t\treturn 1;\r\n\t}\r\n\t\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\t\t\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen; // kMatchMaxLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\t\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\t\r\n\tint[] posTemp = new int[1];\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\t\t\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\t\t\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\t\t\r\n\t\t\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\t\r\n\t\t\tint len;\r\n\t\t\tif (_fastMode)\r\n\t\t\t\tlen = GetOptimumFast((int)nowPos64, posTemp);\r\n\t\t\telse\r\n\t\t\t\tlen = GetOptimum((int)nowPos64, posTemp);\r\n\t\t\t\r\n\t\t\tint pos = posTemp[0];\r\n\t\t\t\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\t\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\tif (!_fastMode)\r\n\t\t\t\t\t\t\t\tif (--_alignPriceCount == 0)\r\n\t\t\t\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (!_fastMode)\r\n\t\t\t\tif (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\r\n\t\t\t\t{\r\n\t\t\t\tFillPosSlotPrices();\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tlastPosSlotFillingPos = nowPos64;\r\n\t\t\t\t}\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\t\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\t\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tif (!_fastMode)\r\n\t\t{\r\n\t\t\tFillPosSlotPrices();\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\t\t\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t\r\n\t\tlastPosSlotFillingPos = 0;\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\t\r\n\tlong[] processedInSize = new long[1];\r\n\tlong[] processedOutSize = new long[1];\r\n\tboolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\t\r\n\tvoid FillPosSlotPrices()\r\n\t{\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tfor (posSlot = 0; posSlot < Base.kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\r\n\t\t\tfor (; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) +\r\n\t\t\t\t\t\t((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = ((posSlot >> 1) - 1);\r\n\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\r\n\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\t\tBitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = Base.kAlignTableSize;\r\n\t}\r\n\t\r\n\t\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\tif (algorithm < 0 || algorithm > 2)\r\n\t\t\treturn false;\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = Base.kDicLogSizeMax;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++);\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SeNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n\t\r\n\t\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t\"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4, bt4b], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.32 Copyright (c) 1999-2005 Igor Pavlov  2005-12-09\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary, params.MatchFinder >= 1);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SeNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator()\r\n\t\t{ Init(); }\r\n\t\tpublic void Init()\r\n\t\t{ A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\t\tpublic CBenchRandomGenerator()\r\n\t\t{ }\r\n\t\tpublic void Init()\r\n\t\t{ RG.Init(); }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit()\r\n\t\t{ return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn RG.GetRnd(2);\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn 4 + RG.GetRnd(3);\r\n\t\t\treturn 12 + RG.GetRnd(4);\r\n\t\t}\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint offset = GetOffset();\r\n\t\t\t\t\twhile (offset >= Pos)\r\n\t\t\t\t\t\toffset >>>= 1;\r\n\t\t\t\t\toffset += 1;\r\n\t\t\t\t\tint len = 2 + GetLen();\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - offset];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, boolean isBT4, long elapsedTime, long size)\r\n\t{\r\n\t\tlong numCommandsForOne;\r\n\t\tif (isBT4)\r\n\t\t{\r\n\t\t\tlong t = GetLogSize(dictionarySize) - (19 << kSubBits);\r\n\t\t\tnumCommandsForOne = 2000 + ((t * t * 68) >>> (2 * kSubBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong t = GetLogSize(dictionarySize) - (15 << kSubBits);\r\n\t\t\tnumCommandsForOne = 1500 + ((t * t * 41) >>> (2 * kSubBits));\r\n\t\t}\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime,\r\n\t\t\tlong outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 250 + outSize * 21;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tboolean isBT4,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tboolean isBT4,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tString bt2 = \"BT2\";\r\n\tString bt4 = \"BT4\";\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize, boolean isBT4) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\tif (!encoder.SetMatchFinder(isBT4 ?\r\n\t\t\tSevenZip.Compression.LZMA.Encoder.EMatchFinderTypeBT4:\r\n\t\t\tSevenZip.Compression.LZMA.Encoder.EMatchFinderTypeBT2))\r\n\t\t\tthrow new Exception(\"Incorrect MatchFinder\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Init();\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, isBT4, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, isBT4, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, isBT4, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/LGPL.txt",
    "content": "      GNU LESSER GENERAL PUBLIC LICENSE\r\n           Version 2.1, February 1999\r\n\r\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\r\n     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n Everyone is permitted to copy and distribute verbatim copies\r\n of this license document, but changing it is not allowed.\r\n\r\n[This is the first released version of the Lesser GPL.  It also counts\r\n as the successor of the GNU Library Public License, version 2, hence\r\n the version number 2.1.]\r\n\r\n          Preamble\r\n\r\n  The licenses for most software are designed to take away your\r\nfreedom to share and change it.  By contrast, the GNU General Public\r\nLicenses are intended to guarantee your freedom to share and change\r\nfree software--to make sure the software is free for all its users.\r\n\r\n  This license, the Lesser General Public License, applies to some\r\nspecially designated software packages--typically libraries--of the\r\nFree Software Foundation and other authors who decide to use it.  You\r\ncan use it too, but we suggest you first think carefully about whether\r\nthis license or the ordinary General Public License is the better\r\nstrategy to use in any particular case, based on the explanations below.\r\n\r\n  When we speak of free software, we are referring to freedom of use,\r\nnot price.  Our General Public Licenses are designed to make sure that\r\nyou have the freedom to distribute copies of free software (and charge\r\nfor this service if you wish); that you receive source code or can get\r\nit if you want it; that you can change the software and use pieces of\r\nit in new free programs; and that you are informed that you can do\r\nthese things.\r\n\r\n  To protect your rights, we need to make restrictions that forbid\r\ndistributors to deny you these rights or to ask you to surrender these\r\nrights.  These restrictions translate to certain responsibilities for\r\nyou if you distribute copies of the library or if you modify it.\r\n\r\n  For example, if you distribute copies of the library, whether gratis\r\nor for a fee, you must give the recipients all the rights that we gave\r\nyou.  You must make sure that they, too, receive or can get the source\r\ncode.  If you link other code with the library, you must provide\r\ncomplete object files to the recipients, so that they can relink them\r\nwith the library after making changes to the library and recompiling\r\nit.  And you must show them these terms so they know their rights.\r\n\r\n  We protect your rights with a two-step method: (1) we copyright the\r\nlibrary, and (2) we offer you this license, which gives you legal\r\npermission to copy, distribute and/or modify the library.\r\n\r\n  To protect each distributor, we want to make it very clear that\r\nthere is no warranty for the free library.  Also, if the library is\r\nmodified by someone else and passed on, the recipients should know\r\nthat what they have is not the original version, so that the original\r\nauthor's reputation will not be affected by problems that might be\r\nintroduced by others.\r\n\f\r\n  Finally, software patents pose a constant threat to the existence of\r\nany free program.  We wish to make sure that a company cannot\r\neffectively restrict the users of a free program by obtaining a\r\nrestrictive license from a patent holder.  Therefore, we insist that\r\nany patent license obtained for a version of the library must be\r\nconsistent with the full freedom of use specified in this license.\r\n\r\n  Most GNU software, including some libraries, is covered by the\r\nordinary GNU General Public License.  This license, the GNU Lesser\r\nGeneral Public License, applies to certain designated libraries, and\r\nis quite different from the ordinary General Public License.  We use\r\nthis license for certain libraries in order to permit linking those\r\nlibraries into non-free programs.\r\n\r\n  When a program is linked with a library, whether statically or using\r\na shared library, the combination of the two is legally speaking a\r\ncombined work, a derivative of the original library.  The ordinary\r\nGeneral Public License therefore permits such linking only if the\r\nentire combination fits its criteria of freedom.  The Lesser General\r\nPublic License permits more lax criteria for linking other code with\r\nthe library.\r\n\r\n  We call this license the \"Lesser\" General Public License because it\r\ndoes Less to protect the user's freedom than the ordinary General\r\nPublic License.  It also provides other free software developers Less\r\nof an advantage over competing non-free programs.  These disadvantages\r\nare the reason we use the ordinary General Public License for many\r\nlibraries.  However, the Lesser license provides advantages in certain\r\nspecial circumstances.\r\n\r\n  For example, on rare occasions, there may be a special need to\r\nencourage the widest possible use of a certain library, so that it becomes\r\na de-facto standard.  To achieve this, non-free programs must be\r\nallowed to use the library.  A more frequent case is that a free\r\nlibrary does the same job as widely used non-free libraries.  In this\r\ncase, there is little to gain by limiting the free library to free\r\nsoftware only, so we use the Lesser General Public License.\r\n\r\n  In other cases, permission to use a particular library in non-free\r\nprograms enables a greater number of people to use a large body of\r\nfree software.  For example, permission to use the GNU C Library in\r\nnon-free programs enables many more people to use the whole GNU\r\noperating system, as well as its variant, the GNU/Linux operating\r\nsystem.\r\n\r\n  Although the Lesser General Public License is Less protective of the\r\nusers' freedom, it does ensure that the user of a program that is\r\nlinked with the Library has the freedom and the wherewithal to run\r\nthat program using a modified version of the Library.\r\n\r\n  The precise terms and conditions for copying, distribution and\r\nmodification follow.  Pay close attention to the difference between a\r\n\"work based on the library\" and a \"work that uses the library\".  The\r\nformer contains code derived from the library, whereas the latter must\r\nbe combined with the library in order to run.\r\n\f\r\n      GNU LESSER GENERAL PUBLIC LICENSE\r\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\r\n\r\n  0. This License Agreement applies to any software library or other\r\nprogram which contains a notice placed by the copyright holder or\r\nother authorized party saying it may be distributed under the terms of\r\nthis Lesser General Public License (also called \"this License\").\r\nEach licensee is addressed as \"you\".\r\n\r\n  A \"library\" means a collection of software functions and/or data\r\nprepared so as to be conveniently linked with application programs\r\n(which use some of those functions and data) to form executables.\r\n\r\n  The \"Library\", below, refers to any such software library or work\r\nwhich has been distributed under these terms.  A \"work based on the\r\nLibrary\" means either the Library or any derivative work under\r\ncopyright law: that is to say, a work containing the Library or a\r\nportion of it, either verbatim or with modifications and/or translated\r\nstraightforwardly into another language.  (Hereinafter, translation is\r\nincluded without limitation in the term \"modification\".)\r\n\r\n  \"Source code\" for a work means the preferred form of the work for\r\nmaking modifications to it.  For a library, complete source code means\r\nall the source code for all modules it contains, plus any associated\r\ninterface definition files, plus the scripts used to control compilation\r\nand installation of the library.\r\n\r\n  Activities other than copying, distribution and modification are not\r\ncovered by this License; they are outside its scope.  The act of\r\nrunning a program using the Library is not restricted, and output from\r\nsuch a program is covered only if its contents constitute a work based\r\non the Library (independent of the use of the Library in a tool for\r\nwriting it).  Whether that is true depends on what the Library does\r\nand what the program that uses the Library does.\r\n  \r\n  1. You may copy and distribute verbatim copies of the Library's\r\ncomplete source code as you receive it, in any medium, provided that\r\nyou conspicuously and appropriately publish on each copy an\r\nappropriate copyright notice and disclaimer of warranty; keep intact\r\nall the notices that refer to this License and to the absence of any\r\nwarranty; and distribute a copy of this License along with the\r\nLibrary.\r\n\r\n  You may charge a fee for the physical act of transferring a copy,\r\nand you may at your option offer warranty protection in exchange for a\r\nfee.\r\n\f\r\n  2. You may modify your copy or copies of the Library or any portion\r\nof it, thus forming a work based on the Library, and copy and\r\ndistribute such modifications or work under the terms of Section 1\r\nabove, provided that you also meet all of these conditions:\r\n\r\n    a) The modified work must itself be a software library.\r\n\r\n    b) You must cause the files modified to carry prominent notices\r\n    stating that you changed the files and the date of any change.\r\n\r\n    c) You must cause the whole of the work to be licensed at no\r\n    charge to all third parties under the terms of this License.\r\n\r\n    d) If a facility in the modified Library refers to a function or a\r\n    table of data to be supplied by an application program that uses\r\n    the facility, other than as an argument passed when the facility\r\n    is invoked, then you must make a good faith effort to ensure that,\r\n    in the event an application does not supply such function or\r\n    table, the facility still operates, and performs whatever part of\r\n    its purpose remains meaningful.\r\n\r\n    (For example, a function in a library to compute square roots has\r\n    a purpose that is entirely well-defined independent of the\r\n    application.  Therefore, Subsection 2d requires that any\r\n    application-supplied function or table used by this function must\r\n    be optional: if the application does not supply it, the square\r\n    root function must still compute square roots.)\r\n\r\nThese requirements apply to the modified work as a whole.  If\r\nidentifiable sections of that work are not derived from the Library,\r\nand can be reasonably considered independent and separate works in\r\nthemselves, then this License, and its terms, do not apply to those\r\nsections when you distribute them as separate works.  But when you\r\ndistribute the same sections as part of a whole which is a work based\r\non the Library, the distribution of the whole must be on the terms of\r\nthis License, whose permissions for other licensees extend to the\r\nentire whole, and thus to each and every part regardless of who wrote\r\nit.\r\n\r\nThus, it is not the intent of this section to claim rights or contest\r\nyour rights to work written entirely by you; rather, the intent is to\r\nexercise the right to control the distribution of derivative or\r\ncollective works based on the Library.\r\n\r\nIn addition, mere aggregation of another work not based on the Library\r\nwith the Library (or with a work based on the Library) on a volume of\r\na storage or distribution medium does not bring the other work under\r\nthe scope of this License.\r\n\r\n  3. You may opt to apply the terms of the ordinary GNU General Public\r\nLicense instead of this License to a given copy of the Library.  To do\r\nthis, you must alter all the notices that refer to this License, so\r\nthat they refer to the ordinary GNU General Public License, version 2,\r\ninstead of to this License.  (If a newer version than version 2 of the\r\nordinary GNU General Public License has appeared, then you can specify\r\nthat version instead if you wish.)  Do not make any other change in\r\nthese notices.\r\n\f\r\n  Once this change is made in a given copy, it is irreversible for\r\nthat copy, so the ordinary GNU General Public License applies to all\r\nsubsequent copies and derivative works made from that copy.\r\n\r\n  This option is useful when you wish to copy part of the code of\r\nthe Library into a program that is not a library.\r\n\r\n  4. You may copy and distribute the Library (or a portion or\r\nderivative of it, under Section 2) in object code or executable form\r\nunder the terms of Sections 1 and 2 above provided that you accompany\r\nit with the complete corresponding machine-readable source code, which\r\nmust be distributed under the terms of Sections 1 and 2 above on a\r\nmedium customarily used for software interchange.\r\n\r\n  If distribution of object code is made by offering access to copy\r\nfrom a designated place, then offering equivalent access to copy the\r\nsource code from the same place satisfies the requirement to\r\ndistribute the source code, even though third parties are not\r\ncompelled to copy the source along with the object code.\r\n\r\n  5. A program that contains no derivative of any portion of the\r\nLibrary, but is designed to work with the Library by being compiled or\r\nlinked with it, is called a \"work that uses the Library\".  Such a\r\nwork, in isolation, is not a derivative work of the Library, and\r\ntherefore falls outside the scope of this License.\r\n\r\n  However, linking a \"work that uses the Library\" with the Library\r\ncreates an executable that is a derivative of the Library (because it\r\ncontains portions of the Library), rather than a \"work that uses the\r\nlibrary\".  The executable is therefore covered by this License.\r\nSection 6 states terms for distribution of such executables.\r\n\r\n  When a \"work that uses the Library\" uses material from a header file\r\nthat is part of the Library, the object code for the work may be a\r\nderivative work of the Library even though the source code is not.\r\nWhether this is true is especially significant if the work can be\r\nlinked without the Library, or if the work is itself a library.  The\r\nthreshold for this to be true is not precisely defined by law.\r\n\r\n  If such an object file uses only numerical parameters, data\r\nstructure layouts and accessors, and small macros and small inline\r\nfunctions (ten lines or less in length), then the use of the object\r\nfile is unrestricted, regardless of whether it is legally a derivative\r\nwork.  (Executables containing this object code plus portions of the\r\nLibrary will still fall under Section 6.)\r\n\r\n  Otherwise, if the work is a derivative of the Library, you may\r\ndistribute the object code for the work under the terms of Section 6.\r\nAny executables containing that work also fall under Section 6,\r\nwhether or not they are linked directly with the Library itself.\r\n\f\r\n  6. As an exception to the Sections above, you may also combine or\r\nlink a \"work that uses the Library\" with the Library to produce a\r\nwork containing portions of the Library, and distribute that work\r\nunder terms of your choice, provided that the terms permit\r\nmodification of the work for the customer's own use and reverse\r\nengineering for debugging such modifications.\r\n\r\n  You must give prominent notice with each copy of the work that the\r\nLibrary is used in it and that the Library and its use are covered by\r\nthis License.  You must supply a copy of this License.  If the work\r\nduring execution displays copyright notices, you must include the\r\ncopyright notice for the Library among them, as well as a reference\r\ndirecting the user to the copy of this License.  Also, you must do one\r\nof these things:\r\n\r\n    a) Accompany the work with the complete corresponding\r\n    machine-readable source code for the Library including whatever\r\n    changes were used in the work (which must be distributed under\r\n    Sections 1 and 2 above); and, if the work is an executable linked\r\n    with the Library, with the complete machine-readable \"work that\r\n    uses the Library\", as object code and/or source code, so that the\r\n    user can modify the Library and then relink to produce a modified\r\n    executable containing the modified Library.  (It is understood\r\n    that the user who changes the contents of definitions files in the\r\n    Library will not necessarily be able to recompile the application\r\n    to use the modified definitions.)\r\n\r\n    b) Use a suitable shared library mechanism for linking with the\r\n    Library.  A suitable mechanism is one that (1) uses at run time a\r\n    copy of the library already present on the user's computer system,\r\n    rather than copying library functions into the executable, and (2)\r\n    will operate properly with a modified version of the library, if\r\n    the user installs one, as long as the modified version is\r\n    interface-compatible with the version that the work was made with.\r\n\r\n    c) Accompany the work with a written offer, valid for at\r\n    least three years, to give the same user the materials\r\n    specified in Subsection 6a, above, for a charge no more\r\n    than the cost of performing this distribution.\r\n\r\n    d) If distribution of the work is made by offering access to copy\r\n    from a designated place, offer equivalent access to copy the above\r\n    specified materials from the same place.\r\n\r\n    e) Verify that the user has already received a copy of these\r\n    materials or that you have already sent this user a copy.\r\n\r\n  For an executable, the required form of the \"work that uses the\r\nLibrary\" must include any data and utility programs needed for\r\nreproducing the executable from it.  However, as a special exception,\r\nthe materials to be distributed need not include anything that is\r\nnormally distributed (in either source or binary form) with the major\r\ncomponents (compiler, kernel, and so on) of the operating system on\r\nwhich the executable runs, unless that component itself accompanies\r\nthe executable.\r\n\r\n  It may happen that this requirement contradicts the license\r\nrestrictions of other proprietary libraries that do not normally\r\naccompany the operating system.  Such a contradiction means you cannot\r\nuse both them and the Library together in an executable that you\r\ndistribute.\r\n\f\r\n  7. You may place library facilities that are a work based on the\r\nLibrary side-by-side in a single library together with other library\r\nfacilities not covered by this License, and distribute such a combined\r\nlibrary, provided that the separate distribution of the work based on\r\nthe Library and of the other library facilities is otherwise\r\npermitted, and provided that you do these two things:\r\n\r\n    a) Accompany the combined library with a copy of the same work\r\n    based on the Library, uncombined with any other library\r\n    facilities.  This must be distributed under the terms of the\r\n    Sections above.\r\n\r\n    b) Give prominent notice with the combined library of the fact\r\n    that part of it is a work based on the Library, and explaining\r\n    where to find the accompanying uncombined form of the same work.\r\n\r\n  8. You may not copy, modify, sublicense, link with, or distribute\r\nthe Library except as expressly provided under this License.  Any\r\nattempt otherwise to copy, modify, sublicense, link with, or\r\ndistribute the Library is void, and will automatically terminate your\r\nrights under this License.  However, parties who have received copies,\r\nor rights, from you under this License will not have their licenses\r\nterminated so long as such parties remain in full compliance.\r\n\r\n  9. You are not required to accept this License, since you have not\r\nsigned it.  However, nothing else grants you permission to modify or\r\ndistribute the Library or its derivative works.  These actions are\r\nprohibited by law if you do not accept this License.  Therefore, by\r\nmodifying or distributing the Library (or any work based on the\r\nLibrary), you indicate your acceptance of this License to do so, and\r\nall its terms and conditions for copying, distributing or modifying\r\nthe Library or works based on it.\r\n\r\n  10. Each time you redistribute the Library (or any work based on the\r\nLibrary), the recipient automatically receives a license from the\r\noriginal licensor to copy, distribute, link with or modify the Library\r\nsubject to these terms and conditions.  You may not impose any further\r\nrestrictions on the recipients' exercise of the rights granted herein.\r\nYou are not responsible for enforcing compliance by third parties with\r\nthis License.\r\n\f\r\n  11. If, as a consequence of a court judgment or allegation of patent\r\ninfringement or for any other reason (not limited to patent issues),\r\nconditions are imposed on you (whether by court order, agreement or\r\notherwise) that contradict the conditions of this License, they do not\r\nexcuse you from the conditions of this License.  If you cannot\r\ndistribute so as to satisfy simultaneously your obligations under this\r\nLicense and any other pertinent obligations, then as a consequence you\r\nmay not distribute the Library at all.  For example, if a patent\r\nlicense would not permit royalty-free redistribution of the Library by\r\nall those who receive copies directly or indirectly through you, then\r\nthe only way you could satisfy both it and this License would be to\r\nrefrain entirely from distribution of the Library.\r\n\r\nIf any portion of this section is held invalid or unenforceable under any\r\nparticular circumstance, the balance of the section is intended to apply,\r\nand the section as a whole is intended to apply in other circumstances.\r\n\r\nIt is not the purpose of this section to induce you to infringe any\r\npatents or other property right claims or to contest validity of any\r\nsuch claims; this section has the sole purpose of protecting the\r\nintegrity of the free software distribution system which is\r\nimplemented by public license practices.  Many people have made\r\ngenerous contributions to the wide range of software distributed\r\nthrough that system in reliance on consistent application of that\r\nsystem; it is up to the author/donor to decide if he or she is willing\r\nto distribute software through any other system and a licensee cannot\r\nimpose that choice.\r\n\r\nThis section is intended to make thoroughly clear what is believed to\r\nbe a consequence of the rest of this License.\r\n\r\n  12. If the distribution and/or use of the Library is restricted in\r\ncertain countries either by patents or by copyrighted interfaces, the\r\noriginal copyright holder who places the Library under this License may add\r\nan explicit geographical distribution limitation excluding those countries,\r\nso that distribution is permitted only in or among countries not thus\r\nexcluded.  In such case, this License incorporates the limitation as if\r\nwritten in the body of this License.\r\n\r\n  13. The Free Software Foundation may publish revised and/or new\r\nversions of the Lesser General Public License from time to time.\r\nSuch new versions will be similar in spirit to the present version,\r\nbut may differ in detail to address new problems or concerns.\r\n\r\nEach version is given a distinguishing version number.  If the Library\r\nspecifies a version number of this License which applies to it and\r\n\"any later version\", you have the option of following the terms and\r\nconditions either of that version or of any later version published by\r\nthe Free Software Foundation.  If the Library does not specify a\r\nlicense version number, you may choose any version ever published by\r\nthe Free Software Foundation.\r\n\f\r\n  14. If you wish to incorporate parts of the Library into other free\r\nprograms whose distribution conditions are incompatible with these,\r\nwrite to the author to ask for permission.  For software which is\r\ncopyrighted by the Free Software Foundation, write to the Free\r\nSoftware Foundation; we sometimes make exceptions for this.  Our\r\ndecision will be guided by the two goals of preserving the free status\r\nof all derivatives of our free software and of promoting the sharing\r\nand reuse of software generally.\r\n\r\n          NO WARRANTY\r\n\r\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\r\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\r\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\r\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\r\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\r\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\r\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\r\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\r\n\r\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\r\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\r\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\r\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\r\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\r\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\r\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\r\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\r\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\r\nDAMAGES.\r\n\r\n         END OF TERMS AND CONDITIONS\r\n\f\r\n           How to Apply These Terms to Your New Libraries\r\n\r\n  If you develop a new library, and you want it to be of the greatest\r\npossible use to the public, we recommend making it free software that\r\neveryone can redistribute and change.  You can do so by permitting\r\nredistribution under these terms (or, alternatively, under the terms of the\r\nordinary General Public License).\r\n\r\n  To apply these terms, attach the following notices to the library.  It is\r\nsafest to attach them to the start of each source file to most effectively\r\nconvey the exclusion of warranty; and each file should have at least the\r\n\"copyright\" line and a pointer to where the full notice is found.\r\n\r\n    <one line to give the library's name and a brief idea of what it does.>\r\n    Copyright (C) <year>  <name of author>\r\n\r\n    This library is free software; you can redistribute it and/or\r\n    modify it under the terms of the GNU Lesser General Public\r\n    License as published by the Free Software Foundation; either\r\n    version 2.1 of the License, or (at your option) any later version.\r\n\r\n    This library is distributed in the hope that it will be useful,\r\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r\n    Lesser General Public License for more details.\r\n\r\n    You should have received a copy of the GNU Lesser General Public\r\n    License along with this library; if not, write to the Free Software\r\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nAlso add information on how to contact you by electronic and paper mail.\r\n\r\nYou should also get your employer (if you work as a programmer) or your\r\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\r\nnecessary.  Here is a sample; alter the names:\r\n\r\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\r\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\r\n\r\n  <signature of Ty Coon>, 1 April 1990\r\n  Ty Coon, President of Vice\r\n\r\nThat's all there is to it!\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/Methods.txt",
    "content": "Compression method IDs (4.27)\r\n-----------------------------\r\n\r\nEach compression method in 7z has unique binary value (ID).\r\nThe length of ID in bytes is arbitrary but it can not exceed 15 bytes.\r\n\r\nList of defined IDs\r\n-------------------\r\n      \r\n00 - Copy\r\n01 - Reserved\r\n02 - Common\r\n   03 Swap\r\n      - 2 Swap2\r\n      - 4 Swap4\r\n   04 Delta (subject to change)\r\n\r\n03 - 7z\r\n   01 - LZMA\r\n      01 - Version\r\n  \r\n   03 - Branch\r\n      01 - x86\r\n         03  - BCJ\r\n         1B  - BCJ2\r\n      02 - PPC\r\n         05 - BC_PPC_B (Big Endian)\r\n      03 - Alpha\r\n         01 - BC_Alpha\r\n      04 - IA64\r\n         01 - BC_IA64\r\n      05 - ARM\r\n         01 - BC_ARM\r\n      06 - M68\r\n         05 - BC_M68_B (Big Endian)\r\n      07 - ARM Thumb\r\n         01 - BC_ARMThumb\r\n      08 - SPARC\r\n         05 - BC_SPARC\r\n\r\n   04 - PPMD\r\n      01 - Version\r\n\r\n04 - Misc\r\n   00 - Reserved\r\n   01 - Zip\r\n      00 - Copy (not used). Use {00} instead\r\n      01 - Shrink\r\n      06 - Implode\r\n      08 - Deflate\r\n      09 - Deflate64\r\n      12 - BZip2 (not used). Use {04 02 02} instead\r\n   02 - BZip\r\n      02 - BZip2\r\n   03 - Rar\r\n      01 - Rar15\r\n      02 - Rar20\r\n      03 - Rar29\r\n   04 - Arj\r\n      01 - Arj (1,2,3)\r\n      02 - Arj 4\r\n   05 - Z\r\n   06 - Lzh\r\n   07 - Reserved for 7z\r\n   08 - Cab\r\n\r\n\r\n06 - Crypto \r\n   00 - \r\n   01 - AES\r\n      0x - AES-128\r\n      4x - AES-192\r\n      8x - AES-256\r\n\r\n      x0 - ECB\r\n      x1 - CBC\r\n      x2 - CFB\r\n      x3 - OFB\r\n\r\n   07 - Reserved\r\n   0F - Reserved\r\n\r\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\r\n\r\n   F1 - Misc Ciphers (Combine)\r\n      01 - Zip\r\n         01 - Main Zip crypto algo\r\n      03 - RAR\r\n         02 - \r\n         03 - Rar29 AES-128 + (modified SHA-1)\r\n      07 - 7z\r\n         01 - AES-256 + SHA-256\r\n\r\n07 - Hash (subject to change)\r\n   00 - \r\n   01 - CRC\r\n   02 - SHA-1\r\n   03 - SHA-256\r\n   04 - SHA-384\r\n   05 - SHA-512\r\n\r\n   F0 - Misc Hash\r\n\r\n   F1 - Misc\r\n      03 - RAR\r\n         03 - Rar29 Password Hashing (modified SHA1)\r\n      07 - 7z \r\n         01 - SHA-256 Password Hashing\r\n    \r\n   \r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/history.txt",
    "content": "HISTORY of the LZMA SDK\r\n-----------------------\r\n\r\n  Version 4.32                2005-12-09\r\n  --------------------------------------\r\n    - Java version of LZMA SDK was included\r\n\r\n\r\n  Version 4.30                2005-11-20\r\n  --------------------------------------\r\n    - Compression ratio was improved in -a2 mode\r\n    - Speed optimizations for compressing in -a2 mode\r\n    - -fb switch now supports values up to 273\r\n    - Bug in 7z_C (7zIn.c) was fixed:\r\n      It used Alloc/Free functions from different memory pools.\r\n      So if program used two memory pools, it worked incorrectly.\r\n    - 7z_C: .7z format supporting was improved\r\n    - LZMA# SDK (C#.NET version) was included\r\n\r\n\r\n  Version 4.27 (Updated)      2005-09-21\r\n  --------------------------------------\r\n   - Some GUIDs/interfaces in C++ were changed.\r\n     IStream.h:\r\n       ISequentialInStream::Read now works as old ReadPart\r\n       ISequentialOutStream::Write now works as old WritePart\r\n\r\n  \r\n  Version 4.27                2005-08-07\r\n  --------------------------------------\r\n    - Bug in LzmaDecodeSize.c was fixed:\r\n       if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r\n       decompressing worked incorrectly.\r\n\r\n\r\n  Version 4.26                2005-08-05\r\n  --------------------------------------\r\n    - Fixes in 7z_C code and LzmaTest.c:\r\n      previous versions could work incorrectly,\r\n      if malloc(0) returns 0\r\n\r\n\r\n  Version 4.23                2005-06-29\r\n  --------------------------------------\r\n    - Small fixes in C++ code\r\n\r\n\r\n  Version 4.22                2005-06-10\r\n  --------------------------------------\r\n    - Small fixes\r\n\r\n\r\n  Version 4.21                2005-06-08\r\n  --------------------------------------\r\n    - Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r\n    - New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r\n        - LzmaStateDecode.h\r\n        - LzmaStateDecode.c\r\n        - LzmaStateTest.c\r\n    - ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r\n\r\n  \r\n  Version 4.17                2005-04-18\r\n  --------------------------------------\r\n    - New example for RAM->RAM compressing/decompressing: \r\n      LZMA + BCJ (filter for x86 code):\r\n        - LzmaRam.h\r\n        - LzmaRam.cpp\r\n        - LzmaRamDecode.h\r\n        - LzmaRamDecode.c\r\n        - -f86 switch for lzma.exe\r\n\r\n  \r\n  Version 4.16                2005-03-29\r\n  --------------------------------------\r\n    - Bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r\n       If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r\n       decoder could access memory outside of allocated range.\r\n    - Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r\n      Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r\n      LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r\n    - Small speed optimization in LZMA C++ code\r\n    - filter for SPARC's code was added\r\n    - Simplified version of .7z ANSI-C Decoder was included\r\n\r\n\r\n  Version 4.06                2004-09-05\r\n  --------------------------------------\r\n    - Bug in v4.05 was fixed:\r\n        LZMA-Encoder didn't release output stream in some cases.\r\n\r\n\r\n  Version 4.05                2004-08-25\r\n  --------------------------------------\r\n    - Source code of filters for x86, IA-64, ARM, ARM-Thumb \r\n      and PowerPC code was included to SDK\r\n    - Some internal minor changes\r\n\r\n\r\n  Version 4.04                2004-07-28\r\n  --------------------------------------\r\n    - More compatibility with some C++ compilers\r\n\r\n\r\n  Version 4.03                2004-06-18\r\n  --------------------------------------\r\n    - \"Benchmark\" command was added. It measures compressing \r\n      and decompressing speed and shows rating values. \r\n      Also it checks hardware errors.\r\n\r\n\r\n  Version 4.02                2004-06-10\r\n  --------------------------------------\r\n    - C++ LZMA Encoder/Decoder code now is more portable\r\n      and it can be compiled by GCC on Linux.\r\n\r\n\r\n  Version 4.01                2004-02-15\r\n  --------------------------------------\r\n    - Some detection of data corruption was enabled.\r\n        LzmaDecode.c / RangeDecoderReadByte\r\n        .....\r\n        {\r\n          rd->ExtraBytes = 1;\r\n          return 0xFF;\r\n        }\r\n\r\n\r\n  Version 4.00                2004-02-13\r\n  --------------------------------------\r\n    - Original version of LZMA SDK\r\n\r\n\r\n\r\nHISTORY of the LZMA\r\n-------------------\r\n  2001-2004:  Improvements to LZMA compressing/decompressing code, \r\n              keeping compatibility with original LZMA format\r\n  1996-2001:  Development of LZMA compression format\r\n\r\n  Some milestones:\r\n\r\n  2001-08-30: LZMA compression was added to 7-Zip\r\n  1999-01-02: First version of 7-Zip was released\r\n  \r\n\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/lzma/lzma.txt",
    "content": "LZMA SDK 4.32\r\n-------------\r\n\r\nLZMA SDK 4.32  Copyright (C) 1999-2005 Igor Pavlov\r\n\r\nLZMA SDK provides the documentation, samples, header files, libraries, \r\nand tools you need to develop applications that use LZMA compression.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\nLZMA is an improved version of famous LZ77 compression algorithm. \r\nIt was improved in way of maximum increasing of compression ratio,\r\nkeeping high decompression speed and low memory requirements for \r\ndecompressing.\r\n\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nLZMA SDK is available under any of the following licenses:\r\n\r\n1) GNU Lesser General Public License (GNU LGPL)\r\n2) Common Public License (CPL)\r\n3) Simplified license for unmodified code (read SPECIAL EXCEPTION) \r\n4) Proprietary license \r\n\r\nIt means that you can select one of these four options and follow rules of that license.\r\n\r\n\r\n1,2) GNU LGPL and CPL licenses are pretty similar and both these\r\nlicenses are classified as \r\n - \"Free software licenses\" at http://www.gnu.org/ \r\n - \"OSI-approved\" at http://www.opensource.org/\r\n\r\n\r\n3) SPECIAL EXCEPTION\r\n\r\nIgor Pavlov, as the author of this code, expressly permits you \r\nto statically or dynamically link your code (or bind by name) \r\nto the files from LZMA SDK without subjecting your linked \r\ncode to the terms of the CPL or GNU LGPL. \r\nAny modifications or additions to files from LZMA SDK, however, \r\nare subject to the GNU LGPL or CPL terms.\r\n\r\nSPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code, \r\nwhile you keep LZMA SDK code unmodified.\r\n\r\n\r\nSPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use this code under the same terms and conditions contained in the License \r\nAgreement you have for any previous version of LZMA SDK developed by Igor Pavlov.\r\n\r\nSPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version \r\nof LZMA SDK as update for previous versions.\r\n\r\n\r\nSPECIAL EXCEPTION #3: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use code of examples (LzmaTest.c, LzmaStateTest.c, LzmaAlone.cpp, \r\nLzmaAlone.cs, LzmaAlone.java) as public domain code. \r\n\r\n\r\n4) Proprietary license\r\n\r\nLZMA SDK also can be available under a proprietary license which \r\ncan include:\r\n\r\n1) Right to modify code without subjecting modified code to the \r\nterms of the CPL or GNU LGPL\r\n2) Technical support for code\r\n\r\nTo request such proprietary license or any additional consultations,\r\nsend email message from that page:\r\nhttp://www.7-zip.org/support.html\r\n\r\n\r\nYou should have received a copy of the GNU Lesser General Public\r\nLicense along with this library; if not, write to the Free Software\r\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nYou should have received a copy of the Common Public License\r\nalong with this library.\r\n\r\n\r\nLZMA SDK Contents\r\n-----------------\r\n\r\nLZMA SDK includes:\r\n\r\n  - C++ source code of LZMA compressing and decompressing\r\n  - ANSI-C compatible source code for LZMA decompressing\r\n  - C# source code for LZMA compressing and decompressing\r\n  - Java source code for LZMA compressing and decompressing\r\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\r\n\r\nANSI-C LZMA decompression code was ported from original C++ sources to C.\r\nAlso it was simplified and optimized for code size. \r\nBut it is fully compatible with LZMA from 7-Zip.\r\n\r\n\r\nUNIX/Linux version \r\n------------------\r\nTo compile C++ version of file->file LZMA, go to directory\r\nC/7zip/Compress/LZMA_Alone \r\nand type \"make\" or \"make clean all\" to recompile all.\r\n\r\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\r\nTo compile with static libraries, change string in makefile\r\nLIB = -lm\r\nto string  \r\nLIB = -lm -static\r\n\r\n\r\nFiles\r\n---------------------\r\nC        - C / CPP source code\r\nCS       - C# source code\r\nJava     - Java source code\r\nlzma.txt - LZMA SDK description (this file)\r\n7zFormat.txt - 7z Format description\r\n7zC.txt  - 7z ANSI-C Decoder description (this file)\r\nmethods.txt  - Compression method IDs for .7z\r\nLGPL.txt - GNU Lesser General Public License\r\nCPL.html - Common Public License\r\nlzma.exe - Compiled file->file LZMA encoder/decoder for Windows\r\nhistory.txt - history of the LZMA SDK\r\n\r\n\r\nSource code structure\r\n---------------------\r\n\r\nC  - C / CPP files\r\n  Common  - common files for C++ projects\r\n  Windows - common files for Windows related code\r\n  7zip    - files related to 7-Zip Project\r\n    Common   - common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n        BinTree    - Binary Tree Match Finder for LZ algorithm\r\n        HashChain  - Hash Chain Match Finder for LZ algorithm\r\n        Patricia   - Patricia Match Finder for LZ algorithm\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n      LZMA         - LZMA compression/decompression on C++\r\n      LZMA_Alone   - file->file LZMA compression/decompression\r\n      LZMA_C       - ANSI-C compatible LZMA decompressor\r\n        LzmaDecode.h  - interface for LZMA decoding on ANSI-C\r\n        LzmaDecode.c      - LZMA decoding on ANSI-C (new fastest version)\r\n        LzmaDecodeSize.c  - LZMA decoding on ANSI-C (old size-optimized version)\r\n        LzmaTest.c        - test application that decodes LZMA encoded file\r\n        LzmaStateDecode.h - interface for LZMA decoding (State version)\r\n        LzmaStateDecode.c - LZMA decoding on ANSI-C (State version)\r\n        LzmaStateTest.c   - test application (State version)\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n    Archive - files related to archiving\r\n      7z_C     - 7z ANSI-C Decoder\r\n\r\nCS - C# files\r\n  7zip\r\n    Common   - some common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      LzmaAlone    - file->file LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nJava  - Java files\r\n  SevenZip\r\n    Compression    - files related to compression/decompression\r\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nC/C++ source code of LZMA SDK is part of 7-Zip project.\r\n\r\nYou can find ANSI-C LZMA decompressing code at folder \r\n  C/7zip/Compress/LZMA_C\r\n7-Zip doesn't use that ANSI-C LZMA code and that code was developed \r\nspecially for this SDK. And files from LZMA_C do not need files from \r\nother directories of SDK for compiling.\r\n\r\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r\n\r\n  http://sourceforge.net/projects/sevenzip/\r\n\r\n\r\nLZMA Decompression features\r\n---------------------------\r\n  - Variable dictionary size (up to 256 MB)\r\n  - Estimated compressing speed: about 500 KB/s on 1 GHz CPU\r\n  - Estimated decompressing speed: \r\n      - 8-12 MB/s on 1 GHz Intel Pentium 3 or AMD Athlon\r\n      - 500-1000 KB/s on 100 MHz ARM, MIPS, PowerPC or other simple RISC\r\n  - Small memory requirements for decompressing (8-32 KB + DictionarySize)\r\n  - Small code size for decompressing: 2-8 KB (depending from \r\n    speed optimizations) \r\n\r\nLZMA decoder uses only integer operations and can be \r\nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r\n\r\nSome critical operations that affect to speed of LZMA decompression:\r\n  1) 32*16 bit integer multiply\r\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\r\n  3) 32-bit shift and arithmetic operations\r\n\r\nSpeed of LZMA decompressing mostly depends from CPU speed.\r\nMemory speed has no big meaning. But if your CPU has small data cache, \r\noverall weight of memory speed will slightly increase.\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nUsing LZMA encoder/decoder executable\r\n--------------------------------------\r\n\r\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\r\n\r\n  e: encode file\r\n\r\n  d: decode file\r\n\r\n  b: Benchmark. There are two tests: compressing and decompressing \r\n     with LZMA method. Benchmark shows rating in MIPS (million \r\n     instructions per second). Rating value is calculated from \r\n     measured speed and it is normalized with AMD Athlon XP CPU\r\n     results. Also Benchmark checks possible hardware errors (RAM \r\n     errors in most cases). Benchmark uses these settings:\r\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d. Also you \r\n     can change number of iterations. Example for 30 iterations:\r\n\tLZMA b 30\r\n     Default number of iterations is 10.\r\n\r\n<Switches>\r\n  \r\n\r\n  -a{N}:  set compression mode 0 = fast, 1 = normal, 2 = max\r\n          default: 2 (max)\r\n\r\n  d{N}:   Sets Dictionary size - [0, 28], default: 23 (8MB)\r\n          The maximum value for dictionary size is 256 MB = 2^28 bytes.\r\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \r\n          For decompressing file compressed by LZMA method with dictionary \r\n          size D = 2^N you need about D bytes of memory (RAM).\r\n\r\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\r\n          Usually big number gives a little bit better compression ratio \r\n          and slower compression process.\r\n\r\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\r\n          Sometimes lc=4 gives gain for big files.\r\n\r\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r\n          lp switch is intended for periodical data when period is \r\n          equal 2^N. For example, for 32-bit (4 bytes) \r\n          periodical data you can use lp=2. Often it's better to set lc0, \r\n          if you change lp switch.\r\n\r\n  -pb{N}: set number of pos bits - [0, 4], default: 2\r\n          pb switch is intended for periodical data \r\n          when period is equal 2^N.\r\n\r\n  -mf{MF_ID}: set Match Finder. Default: bt4. \r\n              Compression ratio for all bt* and pat* almost the same.\r\n              Algorithms from hc* group doesn't provide good compression \r\n              ratio, but they often works pretty fast in combination with \r\n              fast mode (-a0). Methods from bt* group require less memory \r\n              than methods from pat* group. Usually bt4 works faster than \r\n              any pat*, but for some types of files pat* can work faster. \r\n\r\n              Memory requirements depend from dictionary size \r\n              (parameter \"d\" in table below). \r\n\r\n               MF_ID     Memory                   Description\r\n\r\n                bt2    d*9.5 +  1MB  Binary Tree with 2 bytes hashing.\r\n                bt3    d*9.5 + 65MB  Binary Tree with 2-3(full) bytes hashing.\r\n                bt4    d*9.5 +  6MB  Binary Tree with 2-3-4 bytes hashing.\r\n                bt4b   d*9.5 + 34MB  Binary Tree with 2-3-4(big) bytes hashing.\r\n                pat2r  d*26  +  1MB  Patricia Tree with 2-bits nodes, removing.\r\n                pat2   d*38  +  1MB  Patricia Tree with 2-bits nodes.\r\n                pat2h  d*38  + 77MB  Patricia Tree with 2-bits nodes, 2-3 bytes hashing.\r\n                pat3h  d*62  + 85MB  Patricia Tree with 3-bits nodes, 2-3 bytes hashing.\r\n                pat4h  d*110 +101MB  Patricia Tree with 4-bits nodes, 2-3 bytes hashing.\r\n                hc3    d*5.5 +  1MB  Hash Chain with 2-3 bytes hashing.\r\n                hc4    d*5.5 +  6MB  Hash Chain with 2-3-4 bytes hashing.\r\n\r\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \r\n          eos marker, since LZMA decoder knows uncompressed size \r\n          stored in .lzma file header.\r\n\r\n  -si:    Read data from stdin (it will write End Of Stream marker).\r\n  -so:    Write data to stdout\r\n\r\n\r\nExamples:\r\n\r\n1) LZMA e file.bin file.lzma -d16 -lc0 \r\n\r\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r\nand 0 literal context bits. -lc0 allows to reduce memory requirements \r\nfor decompression.\r\n\r\n\r\n2) LZMA e file.bin file.lzma -lc0 -lp2\r\n\r\ncompresses file.bin to file.lzma with settings suitable \r\nfor 32-bit periodical data (for example, ARM or MIPS code).\r\n\r\n3) LZMA d file.lzma file.bin\r\n\r\ndecompresses file.lzma to file.bin.\r\n\r\n\r\nCompression ratio hints\r\n-----------------------\r\n\r\nRecommendations\r\n---------------\r\n\r\nTo increase compression ratio for LZMA compressing it's desirable \r\nto have aligned data (if it's possible) and also it's desirable to locate\r\ndata in such order, where code is grouped in one place and data is \r\ngrouped in other place (it's better than such mixing: code, data, code,\r\ndata, ...).\r\n\r\n\r\nUsing Filters\r\n-------------\r\nYou can increase compression ratio for some data types, using\r\nspecial filters before compressing. For example, it's possible to \r\nincrease compression ratio on 5-10% for code for those CPU ISAs: \r\nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r\n\r\nYou can find C/C++ source code of such filters in folder \"7zip/Compress/Branch\"\r\n\r\nYou can check compression ratio gain of these filters with such \r\n7-Zip commands (example for ARM code):\r\nNo filter:\r\n  7z a a1.7z a.bin -m0=lzma\r\n\r\nWith filter for little-endian ARM code:\r\n  7z a a2.7z a.bin -m0=bc_arm -m1=lzma        \r\n\r\nWith filter for big-endian ARM code (using additional Swap4 filter):\r\n  7z a a3.7z a.bin -m0=swap4 -m1=bc_arm -m2=lzma\r\n\r\nIt works in such manner:\r\nCompressing    = Filter_encoding + LZMA_encoding\r\nDecompressing  = LZMA_decoding + Filter_decoding\r\n\r\nCompressing and decompressing speed of such filters is very high,\r\nso it will not increase decompressing time too much.\r\nMoreover, it reduces decompression time for LZMA_decoding, \r\nsince compression ratio with filtering is higher.\r\n\r\nThese filters convert CALL (calling procedure) instructions \r\nfrom relative offsets to absolute addresses, so such data becomes more \r\ncompressible. Source code of these CALL filters is pretty simple\r\n(about 20 lines of C++), so you can convert it from C++ version yourself.\r\n\r\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r\n\r\n\r\nLZMA compressed file format\r\n---------------------------\r\nOffset Size Description\r\n  0     1   Special LZMA properties for compressed data\r\n  1     4   Dictionary size (little endian)\r\n  5     8   Uncompressed size (little endian). -1 means unknown size\r\n 13         Compressed data\r\n\r\n\r\nANSI-C LZMA Decoder\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nTo compile ANSI-C LZMA Decoder you can use one of the following files sets:\r\n1) LzmaDecode.h + LzmaDecode.c + LzmaTest.c  (fastest version)\r\n2) LzmaDecode.h + LzmaDecodeSize.c + LzmaTest.c  (old size-optimized version)\r\n3) LzmaStateDecode.h + LzmaStateDecode.c + LzmaStateTest.c  (zlib-like interface)\r\n\r\n\r\nMemory requirements for LZMA decoding\r\n-------------------------------------\r\n\r\nLZMA decoder doesn't allocate memory itself, so you must \r\nallocate memory and send it to LZMA.\r\n\r\nStack usage of LZMA decoding function for local variables is not \r\nlarger than 200 bytes.\r\n\r\nHow To decompress data\r\n----------------------\r\n\r\nLZMA Decoder (ANSI-C version) now supports 5 interfaces:\r\n1) Single-call Decompressing\r\n2) Single-call Decompressing with input stream callback\r\n3) Multi-call Decompressing with output buffer\r\n4) Multi-call Decompressing with input callback and output buffer\r\n5) Multi-call State Decompressing (zlib-like interface)\r\n\r\nVariant-5 is similar to Variant-4, but Variant-5 doesn't use callback functions.\r\n\r\nDecompressing steps\r\n-------------------\r\n\r\n1) read LZMA properties (5 bytes):\r\n   unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n2) read uncompressed size (8 bytes, little-endian)\r\n\r\n3) Decode properties:\r\n\r\n  CLzmaDecoderState state;  /* it's 24-140 bytes structure, if int is 32-bit */\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n\r\n4) Allocate memory block for internal Structures:\r\n\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n\r\n  LZMA decoder uses array of CProb variables as internal structure.\r\n  By default, CProb is unsigned_short. But you can define _LZMA_PROB32 to make \r\n  it unsigned_int. It can increase speed on some 32-bit CPUs, but memory \r\n  usage will be doubled in that case.\r\n\r\n\r\n5) Main Decompressing\r\n\r\nYou must use one of the following interfaces:\r\n\r\n5.1 Single-call Decompressing\r\n-----------------------------\r\nWhen to use: RAM->RAM decompressing\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: no defines\r\nMemory Requirements:\r\n  - Input buffer: compressed size\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  int res = LzmaDecode(&state, \r\n      inStream, compressedSize, &inProcessed,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.2 Single-call Decompressing with input stream callback\r\n--------------------------------------------------------\r\nWhen to use: File->RAM or Flash->RAM decompressing.\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB\r\nMemory Requirements:\r\n  - Buffer for input stream: any size (for example, 16 KB)\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  typedef struct _CBuffer\r\n  {\r\n    ILzmaInCallback InCallback;\r\n    FILE *File;\r\n    unsigned char Buffer[kInBufferSize];\r\n  } CBuffer;\r\n\r\n  int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n  {\r\n    CBuffer *bo = (CBuffer *)object;\r\n    *buffer = bo->Buffer;\r\n    *size = MyReadFile(bo->File, bo->Buffer, kInBufferSize);\r\n    return LZMA_RESULT_OK;\r\n  }\r\n\r\n  CBuffer g_InBuffer;\r\n\r\n  g_InBuffer.File = inFile;\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  int res = LzmaDecode(&state, \r\n      &g_InBuffer.InCallback,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.3 Multi-call decompressing with output buffer\r\n-----------------------------------------------\r\nWhen to use: RAM->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Input buffer: compressed size\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details.\r\n\r\n\r\n5.4 Multi-call decompressing with input callback and output buffer\r\n------------------------------------------------------------------\r\nWhen to use: File->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB, _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      &bo.InCallback,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details:\r\n\r\n\r\n5.5 Multi-call State Decompressing (zlib-like interface)\r\n------------------------------------------------------------------\r\nWhen to use: file->file decompressing \r\nCompile files: LzmaStateDecode.h, LzmaStateDecode.c\r\nCompile defines:\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    res = LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed,\r\n      finishDecoding);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaStateTest.c for more details:\r\n\r\n\r\n6) Free all allocated blocks\r\n\r\n\r\nNote\r\n----\r\nLzmaDecodeSize.c is size-optimized version of LzmaDecode.c.\r\nBut compiled code of LzmaDecodeSize.c can be larger than \r\ncompiled code of LzmaDecode.c. So it's better to use \r\nLzmaDecode.c in most cases.\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\nLZMA decoder can return one of the following codes:\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\nIf you use callback function for input data and you return some \r\nerror code, LZMA Decoder also returns that code.\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB    - Use callback for input data\r\n\r\n_LZMA_OUT_READ - Use read function for output data\r\n\r\n_LZMA_LOC_OPT  - Enable local speed optimizations inside code.\r\n                 _LZMA_LOC_OPT is only for LzmaDecodeSize.c (size-optimized version).\r\n                 _LZMA_LOC_OPT doesn't affect LzmaDecode.c (speed-optimized version)\r\n                 and LzmaStateDecode.c\r\n\r\n_LZMA_PROB32   - It can increase speed on some 32-bit CPUs, \r\n                 but memory usage will be doubled in that case\r\n\r\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler\r\n                         and long is 32-bit.\r\n\r\n_LZMA_SYSTEM_SIZE_T  - Define it if you want to use system's size_t.\r\n                       You can use it to enable 64-bit sizes supporting\r\n\r\n\r\n\r\nC++ LZMA Encoder/Decoder \r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nC++ LZMA code use COM-like interfaces. So if you want to use it, \r\nyou can study basics of COM/OLE.\r\n\r\nBy default, LZMA Encoder contains all Match Finders.\r\nBut for compressing it's enough to have just one of them.\r\nSo for reducing size of compressing code you can define:\r\n  #define COMPRESS_MF_BT\r\n  #define COMPRESS_MF_BT4\r\nand it will use only bt4 match finder.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536], *frag_dups[65536];\nint dup_files = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nchar fragment_data[SQUASHFS_FILE_SIZE];\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\n\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tunsigned short\t\tfragment_checksum;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* structure to used to pass in a pointer or an integer\n * to duplicate buffer read helper functions.\n */\nstruct duplicate_buffer_handle {\n\tchar\t*ptr;\n\tlong long\tstart;\n};\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table);\nint get_sorted_inode(squashfs_inode *inode, struct stat *buf);\nint read_sort_file(char *filename, int source, char *source_path[]);\nvoid sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, long long bytes, unsigned int **block_list, long long *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes);\nstruct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\nvoid restorefs()\n{\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(interrupted == 1)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t\tinterrupted ++;\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte = block_size << 1;\n\tunsigned int res;\n\n\tif(!uncompressed && (res = compress2((unsigned char *) d, &c_byte, (unsigned char *) s, size, 9)) != Z_OK) {\n\t\tif(res == Z_MEM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\telse if(res == Z_BUF_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, not enough room in output buffer\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\treturn 0;\n\t}\n\n\tif(uncompressed || c_byte >= size) {\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\treturn FALSE;\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nint write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir) {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir) == FALSE)\n\t\t\treturn FALSE;\n\t} else {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL) == FALSE)\n\t\t\treturn FALSE;\n\t}\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn TRUE;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment = &fragment_table[fragment->index];\n\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\n\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid write_fragment()\n{\n\tint compressed_size;\n\tchar buffer[block_size << 1];\n\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tif(fragments % FRAG_SIZE == 0)\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\tfragment_table[fragments].size = mangle(buffer, fragment_data, fragment_size, block_size, noF, 1);\n\tfragment_table[fragments].start_block = bytes;\n\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(fragment_table[fragments].size);\n\twrite_bytes(fd, bytes, compressed_size, buffer);\n\tbytes += compressed_size;\n\ttotal_uncompressed += fragment_size;\n\ttotal_compressed += compressed_size;\n\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\",fragments, fragment_size, compressed_size);\n\tfragments ++;\n\tfragment_size = 0;\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(char *buff, int size)\n{\n\tstruct fragment *ffrg;\n\n\tif(size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = size;\n\tmemcpy(fragment_data + fragment_size, buff, size);\n\tfragment_size += size;\n\n\treturn ffrg;\n}\n\n\nlong long write_fragment_table()\n{\n\tlong long start_bytes;\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments),\n\t\tmeta_blocks = SQUASHFS_FRAGMENT_INDEXES(fragments);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2], buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tunsigned short c_byte;\n\tint i, compressed_size;\n\tsquashfs_fragment_index list[meta_blocks];\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d, meta_blocks %d\\n\", fragments, frag_bytes, meta_blocks);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = i == meta_blocks - 1 ? frag_bytes % SQUASHFS_METADATA_SIZE : SQUASHFS_METADATA_SIZE;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, noF, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tsquashfs_fragment_index slist[meta_blocks];\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\treturn start_bytes;\n}\n\n\nchar *read_from_buffer(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tchar *v = handle->ptr;\n\thandle->ptr += avail_bytes;\t\n\treturn v;\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_file(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tread_bytes(fd, handle->start, avail_bytes, read_from_file_buffer);\n\thandle->start += avail_bytes;\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *handle, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes = 0;\n\tunsigned char *b;\n\tstruct duplicate_buffer_handle position = *handle;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tb = (unsigned char *) get_next_file_block(&position, bytes);\n\t\twhile(bytes--) {\n\t\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\t\tchksum += *b++;\n\t\t}\n\t}\n\n\treturn chksum;\n}\n\n\nint cached_frag = -1;\nvoid add_file(long long start, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tstruct file_info *dupl_ptr;\n\tchar *datap;\n\tstruct duplicate_buffer_handle handle;\n\tunsigned int *block_list = block_listp;\n\n\tif(!duplicate_checking)\n\t\treturn;\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\tif(fragment == cached_frag || fragment == SQUASHFS_INVALID_FRAG)\n\t\tdatap = fragment_data + offset;\n\telse\n\t\tdatap = get_fragment(fragment_data, frg);\n\thandle.start = start;\n\tif((dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &frg, datap, bytes)) != NULL)\n\t\tdupl_ptr->fragment = frg;\n\telse\n\t\tfree(block_list);\n\tcached_frag = fragment;\n}\n\n\nchar cached_fragment[SQUASHFS_FILE_SIZE];\nint cached_frag1 = -1;\n\nstruct file_info *duplicate(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, long long bytes, unsigned int **block_list, long long *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes)\n{\n\tunsigned short checksum = get_checksum(get_next_file_block, file_start, bytes);\n\tstruct duplicate_buffer_handle handle = { frag_data, 0 };\n\tunsigned short fragment_checksum = get_checksum(read_from_buffer, &handle, frag_bytes);\n\tstruct file_info *dupl_ptr = bytes ? dupl[checksum] : frag_dups[fragment_checksum];\n\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size && fragment_checksum == dupl_ptr->fragment_checksum) {\n\t\t\tchar buffer1[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tlong long dup_bytes = dupl_ptr->bytes;\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tstruct duplicate_buffer_handle position = *file_start;\n\t\t\tchar *buffer;\n\t\t\twhile(dup_bytes) {\n\t\t\t\tint avail_bytes = dup_bytes > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : dup_bytes;\n\n\t\t\t\tbuffer = get_next_file_block(&position, avail_bytes);\n\t\t\t\tread_bytes(fd, dup_start, avail_bytes, buffer1);\n\t\t\t\tif(memcmp(buffer, buffer1, avail_bytes) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_bytes -= avail_bytes;\n\t\t\t\tdup_start += avail_bytes;\n\t\t\t}\n\t\t\tif(dup_bytes == 0) {\n\t\t\t\tchar *fragment_buffer1;\n\t\t\t\t\n\t\t\t\tif(dupl_ptr->fragment->index == fragments || dupl_ptr->fragment->index == SQUASHFS_INVALID_FRAG)\n\t\t\t\t\tfragment_buffer1 = fragment_data + dupl_ptr->fragment->offset;\n\t\t\t\telse if(dupl_ptr->fragment->index == cached_frag1)\n\t\t\t\t\tfragment_buffer1 = cached_fragment + dupl_ptr->fragment->offset;\n\t\t\t\telse {\n\t\t\t\t\tfragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment);\n\t\t\t\t\tcached_frag1 = dupl_ptr->fragment->index;\n\t\t\t\t}\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(frag_data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->start = *start;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->block_list = *block_list;\n\n\tdup_files ++;\n\tif(bytes) {\n\t\tdupl_ptr->next = dupl[checksum];\n\t\tdupl[checksum] = dupl_ptr;\n\t} else {\n\t\tdupl_ptr->next = frag_dups[fragment_checksum];\n\t\tfrag_dups[fragment_checksum] = dupl_ptr;\n\t}\n\n\treturn dupl_ptr;\n}\n\n\n#define MINALLOCBYTES (1024 * 1024)\nint write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)\n{\n\tint block = 0, i, file, whole_file = 1, status;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes = 0, start;\n\tchar buff[block_size], *c_buffer = NULL, *filename = dir_ent->pathname;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr = NULL;\n\tstruct duplicate_buffer_handle handle;\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\tint blocks = (read_size + block_size - 1) >> block_log, allocated_blocks = blocks;\n\tunsigned int *block_list, *block_listp;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif(!no_fragments && (read_size < block_size || always_use_fragments)) {\n\t\tallocated_blocks = blocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %lld bytes\\n\", filename, SQUASHFS_MAX_FILE_SIZE);\n\n\ttotal_bytes += read_size;\n\tif((file = open(filename, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\tlong long bytes = (((long long) allocated_blocks) + 1) << block_log;\n\t\tif(bytes != ((size_t) bytes) || (c_buffer = (char *) malloc(bytes)) == NULL) {\n\t\t\tTRACE(\"Out of memory allocating write_file buffer, allocated_blocks %ld, blocks %d\\n\", allocated_blocks, blocks);\n\t\t\twhole_file = 0;\n\t\t\tif(bytes < MINALLOCBYTES)\n\t\t\t\tBAD_ERROR(\"Out of memory allocating write_file buffer, could not allocate %ld blocks (%d Kbytes)\\n\", allocated_blocks, allocated_blocks << (block_log - 10));\n\t\t\tallocated_blocks >>= 1;\n\t\t}\n\t} while(!c_buffer);\n\n\tfor(start = bytes; block < blocks; file_bytes += bbytes) {\n\t\tfor(i = 0, bbytes = 0; (i < allocated_blocks) && (block < blocks); i++) {\n\t\t\tint available_bytes = read_size - (block * block_size) > block_size ? block_size : read_size - (block * block_size);\n\t\t\tif(read(file, buff, available_bytes) == -1)\n\t\t\t\tgoto read_err;\n\t\t\tc_byte = mangle(c_buffer + bbytes, buff, available_bytes, block_size, noD, 1);\n\t\t\tblock_list[block ++] = c_byte;\n\t\t\tbbytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\t}\n\t\tif(!whole_file) {\n\t\t\twrite_bytes(fd, bytes, bbytes, c_buffer);\n\t\t\tbytes += bbytes;\n\t\t}\n\t}\n\n\tif(frag_bytes != 0)\n\t\tif(read(file, buff, frag_bytes) == -1)\n\t\t\tgoto read_err;\n\n\tclose(file);\n\tif(whole_file) {\n\t\thandle.ptr = c_buffer;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_buffer, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t\twrite_bytes(fd, bytes, file_bytes, c_buffer);\n\t\tbytes += file_bytes;\n\t} else {\n\t\thandle.start = start;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\tbytes = start;\n\t\t\tif(!block_device)\n\t\t\t\tftruncate(fd, bytes);\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t}\n\n\tfragment = get_and_fill_fragment(buff, frag_bytes);\n\tif(duplicate_checking)\n\t\tdupl_ptr->fragment = fragment;\n\n\t*duplicate_file = FALSE;\n\nwr_inode:\n\tfree(c_buffer);\n\tfile_count ++;\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\tif(duplicate_checking == FALSE || *duplicate_file == TRUE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tfree(c_buffer);\n\tfree(block_list);\n\treturn FALSE;\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir_info = dir_scan1(pathname, _readdir);\n\tstruct dir_ent *dir_ent;\n\tstruct inode_info *inode_info;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif((inode_info = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->inode = inode_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tinode_info->nlink = 1;\n\tinode_info->inode_number = root_inode_number ? root_inode_number : dir_inode_no++;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tinode_info->buf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO;\n\t\tinode_info->buf.st_uid = getuid();\n\t\tinode_info->buf.st_gid = getgid();\n\t\tinode_info->buf.st_mtime = time(NULL);\n\t} else if(lstat(pathname, &inode_info->buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\n\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint result = FALSE;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\tresult = write_file(inode, dir_ent, buf->st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tresult = dir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n\t\t\t\t}\n\t\t\tif(result)\n\t\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcaseSQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult = TRUE;\n\t\t}\n\t\t\n\n\t\tif(result)\n\t\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\tresult = write_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n\n\treturn result;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 16; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.0 (2006/03/15)\\n\");\\\n\tprintf(\"copyright (C) 2006 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t} else  {\n\t\tsignal(SIGTERM, sighandler2);\n\t\tsignal(SIGINT, sighandler2);\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\t\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -2.0 options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = inode_dir_offset + inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\n\tTRACE(\"sBlk->inode_table_start 0x%x\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%x\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%x\\n\", sBlk.fragment_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tsBlk.unused = SQUASHFS_INVALID_BLK;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s filesystem, data block size %d, %s data, %s metadata, %s fragments\\n\", be ?\n\t\t\"Big endian\" : \"Little endian\", block_size, noD ? \"uncompressed\" : \"compressed\", noI ?\n\t\"uncompressed\" : \"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\tclose(fd);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i, start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i, start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3.0 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is %d.%d, I support 3.0\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid SQUASHFS superblock on %s.\\n\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not\" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block; \n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern squashfs_inode write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tgenerate_file_priorities(dir, 0, &dir->dir_ent->inode->buf);\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\tif(write_file(&inode, entry->dir, entry->dir->inode->buf.st_size,\n\t\t\t\t\t\t\t&duplicate_file)) {\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tstruct inode_info\t*next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t(A * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n#define SQUASHFS_CACHED_FRAGMENTS\t3\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tunused;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tunused;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->unused, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.0-e2100/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n *  Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0, dev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE;\nchar **created_inode;\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry; hash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes, (const unsigned char *) data, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end, squashfs_super_block *sBlk)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, unsigned int mode, unsigned int uid, unsigned int guid,\nunsigned int mtime, unsigned int set_mode)\n{\n\tstruct utimbuf times = { (time_t) mtime, (time_t) mtime };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(set_mode && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(geteuid() == 0) {\n\t\tuid_t uid_value = (uid_t) uid_table[uid];\n\t\tuid_t guid_value = guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[guid];\n\n\t\tif(chown(pathname, uid_value, guid_value) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids(squashfs_super_block *sBlk)\n{\n\tif((uid_table = malloc((sBlk->no_uids + sBlk->no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk->no_uids;\n\n\tif(read_bytes(sBlk->uid_start, (sBlk->no_uids + sBlk->no_guids) * sizeof(unsigned int), (char *) uid_table) ==\n\t\t\tFALSE)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table(squashfs_super_block *sBlk)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL, ((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint write_file(char *pathname, unsigned int fragment, unsigned int frag_bytes, unsigned int offset,\nunsigned int blocks, long long start, char *block_ptr, unsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY, (mode_t) mode)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write(file_fd, file_data, bytes) < bytes) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write(file_fd, fragment_data + offset, frag_bytes) < frag_bytes) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\t\t\n\nint create_inode(char *pathname, unsigned int start_block, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tlong long start = sBlk->inode_table_start + start_block;\n\tsquashfs_inode_header header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tif(created_inode[header.base.inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(link(created_inode[header.base.inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size\n\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>\n\t\t\t\tsBlk->block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,\n\t\t\t\t\tblock_ptr + sizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size\n\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>\n\t\t\t\tsBlk->block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,\n\t\t\t\t\tblock_ptr + sizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(geteuid() == 0) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(geteuid() == 0) {\n\t\t\t\tif(mknod(pathname, inodep->inode_type == SQUASHFS_CHRDEV_TYPE ? S_IFCHR : S_IFBLK,\n\t\t\t\t\t\t\tmakedev((inodep->rdev >> 8) & 0xff, inodep->rdev & 0xff))\n\t\t\t\t\t\t\t== -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\theader.base.mtime, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[header.base.inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end, squashfs_super_block *sBlk)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table = realloc(directory_table, size += SQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes, sBlk)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_openddir(unsigned int block_start, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start = sBlk->inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk->directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block, unsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tstruct dir *dir = squashfs_openddir(start_block, offset, sBlk);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(lsonly || info)\n\t\t\tprintf(\"%s\\n\", pathname);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, sBlk);\n\t\telse\n\t\t\tif(!lsonly)\n\t\t\t\tcreate_inode(pathname, start_block, offset, sBlk);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, TRUE);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nint read_super(squashfs_super_block *sBlk, char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d)\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tERROR(\"I only support Squashfs 3.0 filesystems!  Later releases will support older Squashfs filesystems\\n\");\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tTRACE(\"Found a valid %s endian SQUASHFS superblock on %s.\\n\", swap ? \"little\" : \"big\", source);\n#else\n\tTRACE(\"Found a valid %s endian SQUASHFS superblock on %s.\\n\", swap ? \"big\" : \"little\", source);\n#endif\n\n\tTRACE(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not\" : \"\");\n\tTRACE(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tTRACE(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tTRACE(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tTRACE(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tTRACE(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tTRACE(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start 0x%llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.0 (2006/03/15)\\n\");\\\n\tprintf(\"copyright (C) 2006 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tsquashfs_super_block sBlk;\n\tchar *dest = \"squashfs-root\";\n\tint i, version = FALSE;\n\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0) {\n\t\t\tif(++i == argc)\n\t\t\t\tgoto options;\n\t\t\tdest = argv[i];\n\t\t}\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [-ls | -dest] filesystem\\n\", argv[0]);\n\t\t\tERROR(\"\\t-version\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-info\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-ls\\t\\t\\tlist filesystem only\\n\");\n\t\t\tERROR(\"\\t-dest <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(&sBlk, argv[i]) == FALSE)\n\t\texit(1);\n\n\tblock_size = sBlk.block_size;\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids(&sBlk);\n\tread_fragment_table(&sBlk);\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start, &sBlk);\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start, &sBlk);\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), &sBlk);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/Makefile",
    "content": "CC := gcc\nCXX := g++\nINCLUDEDIR = .\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\nLZMAPATH = ../../lzma/C/7zip/Compress/LZMA_Lib\n\nall: mksquashfs unsquashfs # mksquashfs-lzma unsquashfs-lzma\n\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\t$(CC) mksquashfs.o read_fs.o sort.o -lpthread -lz -lm -o $@\n\n#mksquashfs-lzma: mksquashfs.o read_fs.o sort.o\n#\tmake -C $(LZMAPATH)\n#\t$(CXX) -O3 mksquashfs.o read_fs.o sort.o -L$(LZMAPATH) -lpthread -lm -llzma -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nunsquashfs-lzma: unsquashfs.o\n\tmake -C $(LZMAPATH)\n\t$(CXX) -O3 unsquashfs.o -L$(LZMAPATH) -llzma -o $@\n\nunsquashfs: unsquashfs.o\n\t$(CC) unsquashfs.o -lz -o $@\n\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h\n\nclean:\n\trm -f *.o\n\trm -f mksquashfs\n\trm -f unsquashfs\n\trm -f mksquashfs-lzma\n\trm -f unsquashfs-lzma\n\trm -f mksquashfs.exe\n\trm -f unsquashfs.exe\n\trm -f mksquashfs-lzma.exe\n\trm -f unsquashfs-lzma.exe\n\tmake -C $(LZMAPATH) clean\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* data allocator status struct.  Allocators are used to keep\n  track of memory buffers passed between different threads */\nstruct allocator {\n\tint\t\tmax_buffers;\n\tint\t\tcount;\n\tint\t\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t\twait;\n};\n\n/* struct describing a memory buffer passed between threads */\nstruct file_buffer {\n\tstruct allocator\t*allocator;\n\tvoid\t\t\t(*release)(int);\n\tint\t\t\trelease_data;\n\tlong long\t\tblock;\n\tint\t\t\tsize;\n\tint\t\t\tc_byte;\n\tunsigned int\t\tblock_order;\n\tint\t\t\tfragment;\n\tint\t\t\terror;\n\tstruct file_buffer\t*next;\n\tchar\t\t\tdata[0];\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n/* describes the list of blocks in a file which is a possible\n   duplicate.  For each block, it indicates whether the block is\n   in memory or on disk */\nstruct buffer_list {\n\tlong long start;\n\tint size;\n\tstruct file_buffer *read_buffer;\n};\n\nstruct allocator *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\nextern struct priority_entry *priority_list[65536];\n\n\nstruct allocator *alloc_init(int buffer_size, int max_buffers)\n{\n\tstruct allocator *allocator = malloc(sizeof(struct allocator));\n\n\tif(allocator == NULL)\n\t\treturn NULL;\n\n\tallocator->max_buffers = max_buffers;\n\tallocator->buffer_size = buffer_size;\n\tallocator->count = 0;\n\tpthread_mutex_init(&allocator->mutex, NULL);\n\tpthread_cond_init(&allocator->wait, NULL);\n\n\treturn allocator;\n}\n\n\nstruct file_buffer *alloc_get(struct allocator *allocator)\n{\n\tstruct file_buffer *file_buffer;\n\t\n\tpthread_mutex_lock(&allocator->mutex);\n\n\twhile(allocator->count == allocator->max_buffers)\n\t\tpthread_cond_wait(&allocator->wait, &allocator->mutex);\n\n\tif((file_buffer = malloc(sizeof(struct file_buffer) + allocator->buffer_size)) == NULL)\n\t\tgoto failed;\n\n\tfile_buffer->release = NULL;\n\tfile_buffer->allocator = allocator;\n\tallocator->count ++;\n\nfailed:\n\tpthread_mutex_unlock(&allocator->mutex);\n\treturn file_buffer;\n}\n\n\nstruct file_buffer *alloc_get_2(struct allocator *allocator, void (*release)(int), int release_data)\n{\n\tstruct file_buffer *file_buffer = alloc_get(allocator);\n\n\tif(file_buffer) {\n\t\tfile_buffer->release = release;\n\t\tfile_buffer->release_data = release_data;\n\t}\n\treturn file_buffer;\n}\n\n\nvoid alloc_free(struct file_buffer *file_buffer)\n{\n\tstruct allocator *allocator;\n\n\tif(file_buffer == NULL)\n\t\treturn;\n\n\tallocator = file_buffer->allocator;\n\n\tif(file_buffer->release)\n\t\tfile_buffer->release(file_buffer->release_data);\n\n\tpthread_mutex_lock(&allocator->mutex);\n\tfree(file_buffer);\n\tif(allocator->count == 0)\n\t\tERROR(\"alloc_free: freeing buffer for empty allocator!\\n\");\n\telse\n\t\tallocator->count --;\n\tpthread_cond_signal(&allocator->wait);\n\tpthread_mutex_unlock(&allocator->mutex);\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\n\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t}\n\n\tstream->next_in = (unsigned char *) s;\n\tstream->avail_in = size;\n\tstream->next_out = (unsigned char *) d;\n\tstream->avail_out = block_size;\n\n\tres = deflate(stream, Z_FINISH);\n\tif(res != Z_STREAM_END && res != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\telse if(res == Z_BUF_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t}\n\n\tc_byte = stream->total_out;\n\n\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\treturn FALSE;\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nint write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir) {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir) == FALSE)\n\t\t\treturn FALSE;\n\t} else {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL) == FALSE)\n\t\t\treturn FALSE;\n\t}\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn TRUE;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment, int *cached_fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\n\tif(fragment->index == *cached_fragment || fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn buffer + fragment->offset;\n\n\tif(fragment_data && fragment->index == fragments)\n\t\treturn fragment_data->data + fragment->offset;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragment_table[fragment->index].pending)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\n\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\t*cached_fragment = fragment->index;\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid ensure_fragments_flushed()\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragments_outstanding)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].pending = TRUE;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\nvoid frag_release(int block)\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragment_table[block].pending = FALSE;\n\tpthread_cond_signal(&fragment_waiting);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = alloc_get(fragment_buffer);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint avail_bytes, compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tlong long slist[meta_blocks];\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_buffer(struct buffer_list *buffer_list, unsigned int blocks)\n{\n\tunsigned short chksum = 0;\n\tint block;\n\n\tfor(block = 0; block < blocks; block ++) {\n\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\tif(b->read_buffer)\n\t\t\tchksum = get_checksum(b->read_buffer->data, b->read_buffer->size, chksum);\n\t\telse\n\t\t\tchksum = get_checksum(read_from_disk(b->start, b->size), b->size, chksum);\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\nint cached_frag = -1;\nchar fragdata[SQUASHFS_FILE_MAX_SIZE];\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tchar *datap;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\nchar cached_fragment[SQUASHFS_FILE_SIZE];\nint cached_frag1 = -1;\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), file_size);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tchar buffer2[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tchar *buffer;\n\t\t\tint block;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_buffer(buffer_list, blocks);\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), frag_bytes);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\t\t\tif(b->read_buffer)\n\t\t\t\t\tbuffer = b->read_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tbuffer = read_from_disk(b->start, b->size);\n\n\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\n\t\t\t\tif(memcmp(buffer, buffer2, b->size) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_start += b->size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tchar *fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1);\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tint count;\n\tint blocks = (buf->st_size + block_size - 1) >> block_log;\n\tint frag_block = !no_fragments && (always_use_fragments ||\n\t\t(buf->st_size < block_size)) ? buf->st_size >> block_log : -1;\n\tint file;\n\tstatic int block_order = 0;\n\tstruct file_buffer *file_buffer;\n\n\tif(buf->st_size == 0 || dir_ent->inode->read)\n\t\treturn;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tfor(count = 0; count < blocks; count ++) {\n\t\tfile_buffer = alloc_get(reader_buffer);\n\n\t\tif((file_buffer->size = read(file, file_buffer->data, block_size)) == -1) {\n\t\t\tclose(file);\n\t\t\tgoto read_err2;\n\t\t}\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->block_order = block_order ++;\n\t\tfile_buffer->error = FALSE;\n\t\tif(file_buffer->fragment = count == frag_block)\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\telse\n\t\t\tqueue_put(from_reader, file_buffer);\n\t}\n\n\tclose(file);\n\tdir_ent->inode->read = TRUE;\n\n\treturn;\n\nread_err:\n\tfile_buffer = alloc_get(reader_buffer);\nread_err2:\n\tfile_buffer->block_order = block_order ++;\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tperror(\"Lseek on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n\t\t\tperror(\"Write on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer = alloc_get(writer_buffer);\n\n\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\n\t\twrite_buffer->block = file_buffer->block;\n\t\twrite_buffer->block_order = file_buffer->block_order;\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\n\t\twrite_buffer->fragment = FALSE;\n\t\twrite_buffer->error = FALSE;\n\t\talloc_free(file_buffer);\n\t\tqueue_put(from_deflate, write_buffer);\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer = alloc_get_2(writer_buffer, frag_release, file_buffer->block);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\twrite_buffer->size = compressed_size;\n\t\twrite_buffer->block = bytes;\n\t\tqueue_put(to_writer, write_buffer);\n\t\tbytes += compressed_size;\n\t\ttotal_uncompressed += file_buffer->size;\n\t\ttotal_compressed += compressed_size;\n\t\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\n\t\tfragments_outstanding --;\n\t\tpthread_cond_signal(&fragment_waiting);\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->block_order);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int block_order = 0;\n\tint hash = BLOCK_HASH(block_order);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->block_order == block_order)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->block_order == block_order)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tblock_order ++;\n\n\treturn file_buffer;\n}\n\n\nint progress_bar(long long current, long long max, int columns)\n{\n\tint max_digits = ceil(log10(max));\n\tint used = max_digits * 2 + 10;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(!progress || columns - used < 0)\n\t\treturn;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\nint write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n}\n\n\nint write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\n{\n\tint file;\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\talloc_free(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\tstruct file_buffer *file_buffer = get_file_buffer(from_deflate);\n\n\tif(file_buffer->error) {\n\t\talloc_free(file_buffer);\n\t\treturn FALSE;\n\t}\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum))\n\t\treturn write_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\talloc_free(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size)\n{\n\tint block, status;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list;\n\tstruct file_buffer *read_buffer;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\t\tqueue_put(to_writer, read_buffer);\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t} else\n\t\tread_buffer = NULL;\n\n\tfragment = get_and_fill_fragment(read_buffer);\n\talloc_free(read_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, int *duplicate_file)\n{\n\tint block, status, thresh;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer *read_buffer;\n\tstruct file_data *file_data;\n\tstruct buffer_list *buffer_list;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tthresh = blocks > (writer_buffer_size - processors) ? blocks - (writer_buffer_size - processors): 0;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\n\t\tif(block < thresh) {\n\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\tqueue_put(to_writer, read_buffer);\n\t\t} else\n\t\t\tbuffer_list[block].read_buffer = read_buffer;\n\t\tbuffer_list[block].start = read_buffer->block;\n\t\tbuffer_list[block].size = read_buffer->size;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t} else\n\t\tread_buffer = NULL;\n\n\tqueue_put(to_writer, NULL);\n\tif(queue_get(from_writer) != 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\n\t\tfragment = get_and_fill_fragment(read_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\talloc_free(buffer_list[block].read_buffer);\n\t\tbytes = buffer_list[0].start;\n\t\tif(thresh && !block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\n\talloc_free(read_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block && thresh) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\talloc_free(buffer_list[blocks].read_buffer);\n\tfree(buffer_list);\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)\n{\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %lld bytes\\n\", dir_ent->pathname, SQUASHFS_MAX_FILE_SIZE);\n\n\tif(read_size == 0)\n\t\treturn write_file_empty(inode, dir_ent, duplicate_file);\n\n\tif(!no_fragments && (read_size < block_size))\n\t\treturn write_file_frag(inode, dir_ent, read_size, duplicate_file);\n\n\tif(pre_duplicate(read_size))\n\t\treturn write_file_blocks_dup(inode, dir_ent, read_size, duplicate_file);\n\n\t*duplicate_file = FALSE;\n\treturn write_file_blocks(inode, dir_ent, read_size);\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFREG)\n\t\t\testimated_uncompressed += (buf.st_size + block_size - 1) >> block_log;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\n\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint result = FALSE;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\tresult = write_file(inode, dir_ent, buf->st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tresult = dir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n\t\t\t\t}\n\t\t\tif(result)\n\t\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult = TRUE;\n\t\t}\n\t\t\n\n\t\tif(result)\n\t\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\tresult = write_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n\n\treturn result;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 16; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(processors * 2);\n\treader_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, reader_buffer_size);\n\twriter_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, writer_buffer_size);\n\tfragment_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, processors * 2);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\n\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\n}\n\n\t\t\t\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.2-r2 (2007/01/15)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct winsize winsize;\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t} else  {\n\t\tsignal(SIGTERM, sighandler2);\n\t\tsignal(SIGINT, sighandler2);\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tinitialise_threads();\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t\t\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = inode_dir_offset + inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(progress) {\n\t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\t\tcolumns = 80;\n\t\t} else\n\t\t\tcolumns = winsize.ws_col;\n\t\tsignal(SIGWINCH, sigwinch_handler);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tensure_fragments_flushed();\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\tclose(fd);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3.0 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is %d.%d, I support 3.0\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %xllx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block; \n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tlong long sindex[indexes];\n\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_inode_t sinode;\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\n\t\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern squashfs_inode write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\tif(write_file(&inode, entry->dir, entry->dir->inode->buf.st_size,\n\t\t\t\t\t\t\t&duplicate_file)) {\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n *  Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir\t*(*squashfs_opendir)(unsigned int block_start, unsigned int offset);\n\tchar \t\t*(*read_fragment)(unsigned int fragment);\n\tvoid\t\t(*read_fragment_table)();\n\tint\t\t(*create_inode)(char *pathname, unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE, force = FALSE;\nchar **created_inode;\nint root_process;\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes,\n\t\t(const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes,\n\t\t(const unsigned char *) data, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, unsigned int mode, unsigned int uid,\nunsigned int guid, unsigned int mtime, unsigned int set_mode)\n{\n\tstruct utimbuf times = { (time_t) mtime, (time_t) mtime };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tuid_t uid_value = (uid_t) uid_table[uid];\n\t\tuid_t guid_value = guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[guid];\n\n\t\tif(chown(pathname, uid_value, guid_value) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nchar *read_fragment_2(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint write_file(char *pathname, unsigned int fragment, unsigned int frag_bytes,\nunsigned int offset, unsigned int blocks, long long start, char *block_ptr,\nunsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write(file_fd, file_data, bytes) < bytes) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = s_ops.read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write(file_fd, fragment_data + offset, frag_bytes) < frag_bytes) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\t\t\n\nint create_inode(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tif(created_inode[header.base.inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[header.base.inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\theader.base.mtime, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[header.base.inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nint create_inode_2(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header_2 header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, sBlk.mkfs_time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\tsBlk.mkfs_time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header_2 header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nint matches(char *targname, char *name)\n{\n\tif(*targname == '\\0' || strcmp(targname, name) == 0)\n\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, char *target)\n{\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tchar targname[1024];\n\n\ttarget = get_component(target, targname);\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(targname, name))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(lsonly || info)\n\t\t\tprintf(\"%s\\n\", pathname);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, target);\n\t\telse\n\t\t\tif(!lsonly)\n\t\t\t\ts_ops.create_inode(pathname, start_block, offset);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nint read_super(char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk.s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk.s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\n\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\ts_ops.read_fragment = read_fragment_2;\n\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\ts_ops.create_inode = create_inode_2;\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor == 0) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.create_inode = create_inode;\n\t} else {\n\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d)\\n\",\n\t\t\t\tsource, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"I support Squashfs 2.x and 3.0 filesystems!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\n\tTRACE(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not\" : \"\");\n\tTRACE(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tTRACE(\"\\tBlock size %d\\n\", sBlk.block_size);\n\tTRACE(\"\\tNumber of fragments %d\\n\", sBlk.fragments);\n\tTRACE(\"\\tNumber of inodes %d\\n\", sBlk.inodes);\n\tTRACE(\"\\tNumber of uids %d\\n\", sBlk.no_uids);\n\tTRACE(\"\\tNumber of gids %d\\n\", sBlk.no_guids);\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.3 (2007/01/02)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, version = FALSE;\n\tchar *target = \"\";\n\n\tif(root_process = geteuid() == 0)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc)\n\t\t\t\tgoto options;\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directory or file to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem only\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tif((i + 1) < argc)\n\t\ttarget = argv[i + 1];\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tblock_size = sBlk.block_size;\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids();\n\ts_ops.read_fragment_table();\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), target);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/Makefile",
    "content": "\n# Copyright (C) 2006, 2007 Junjiro Okajima\n# Copyright (C) 2006, 2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described ones in lzma and squashfs.\n\n# $Id: Makefile,v 1.2 2007-11-22 06:13:08 steven Exp $\n\n# paths\nSqlzma = ${CURDIR}\nLzmaVer = lzma443\nLzma = ${Sqlzma}/${LzmaVer}\nSqVer = squashfs3.2-r2\nSquashfs = ${Sqlzma}/${SqVer}\n\nLzmaC = ${Lzma}/C/7zip/Compress/LZMA_C\nLzmaAlone = ${Lzma}/C/7zip/Compress/LZMA_Alone\nSqTools = ${Squashfs}/squashfs-tools\n\n# enable it if you want to add -g option when compiling\nUseDebugFlags =\n# disable it if you don't want to compile squashfs kernel module here\nBuildSquashfs = 1\n\nexport\n\nall:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\t@cp squashfs3.2-r2/squashfs-tools/mksquashfs .\n\t@cp squashfs3.2-r2/squashfs-tools/unsquashfs .\n\nclean:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\t${RM} *~ mksquashfs unsquashfs\n\n# install: all\n#\tcp squashfs3.2-r2/squashfs-tools/mksquashfs /opt/buildroot-gdb/bin/mksquashfs_lzma-3.2\n\n########################################\n\n\n\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/7zC.txt",
    "content": "7z ANSI-C Decoder 4.43\r\n----------------------\r\n\r\n7z ANSI-C Decoder 4.43 Copyright (C) 1999-2006 Igor Pavlov\r\n\r\n7z ANSI-C provides 7z/LZMA decoding.\r\n7z ANSI-C version is simplified version ported from C++ code.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nRead lzma.txt for information about license.\r\n\r\n\r\nFiles\r\n---------------------\r\n\r\n7zAlloc.*    - Allocate and Free\r\n7zBuffer.*   - Buffer structure\r\n7zCrc.*      - CRC32 code\r\n7zDecode.*   - Low level memory->memory decoding\r\n7zExtract.*  - High level stream->memory decoding\r\n7zHeader.*   - .7z format constants\r\n7zIn.*       - .7z archive opening\r\n7zItem.*     - .7z structures\r\n7zMain.c     - Test application\r\n7zMethodID.* - MethodID structure\r\n7zTypes.h    - Base types and constants\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nYou must download 7-Zip program from www.7-zip.org.\r\n\r\nYou can create .7z archive with 7z.exe or 7za.exe:\r\n\r\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255 -mf=off\r\n\r\nIf you have big number of files in archive, and you need fast extracting, \r\nyou can use partly-solid archives:\r\n  \r\n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K -mf=off\r\n\r\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r\n512KB for extracting one file from such archive.\r\n\r\n\r\nLimitations of current version of 7z ANSI-C Decoder\r\n---------------------------------------------------\r\n\r\n - It reads only \"FileName\", \"Size\", and \"CRC\" information for each file in archive.\r\n - It supports only LZMA and Copy (no compression) methods.\r\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r\n \r\nThese limitations will be fixed in future versions.\r\n\r\n\r\nUsing 7z ANSI-C Decoder Test application:\r\n-----------------------------------------\r\n\r\nUsage: 7zDec <command> <archive_name>\r\n\r\n<Command>:\r\n  e: Extract files from archive\r\n  l: List contents of archive\r\n  t: Test integrity of archive\r\n\r\nExample: \r\n\r\n  7zDec l archive.7z\r\n\r\nlists contents of archive.7z\r\n\r\n  7zDec e archive.7z\r\n\r\nextracts files from archive.7z to current folder.\r\n\r\n\r\nHow to use .7z Decoder\r\n----------------------\r\n\r\n.7z Decoder can be compiled in one of two modes:\r\n\r\n1) Default mode. In that mode 7z Decoder will read full compressed \r\n   block to RAM before decompressing.\r\n  \r\n2) Mode with defined _LZMA_IN_CB. In that mode 7z Decoder can read\r\n   compressed block by parts. And you can specify desired buffer size. \r\n   So memory requirements can be reduced. But decompressing speed will \r\n   be 5-10% lower and code size is slightly larger.\r\n\r\n   \r\nMemory allocation\r\n~~~~~~~~~~~~~~~~~\r\n\r\n7z Decoder uses two memory pools:\r\n1) Temporary pool\r\n2) Main pool\r\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\r\n\r\nSteps for using 7z decoder\r\n--------------------------\r\n\r\nUse code at 7zMain.c as example.\r\n\r\n1) Declare variables:\r\n  inStream                     /* implements ISzInStream interface */\r\n  CArchiveDatabaseEx db;       /* 7z archive database structure */\r\n  ISzAlloc allocImp;           /* memory functions for main pool */\r\n  ISzAlloc allocTempImp;       /* memory functions for temporary pool */\r\n\r\n2) call InitCrcTable(); function to initialize CRC structures.\r\n\r\n3) call SzArDbExInit(&db); function to initialize db structures.\r\n\r\n4) call SzArchiveOpen(inStream, &db, &allocMain, &allocTemp) to open archive\r\n\r\nThis function opens archive \"inStream\" and reads headers to \"db\".\r\nAll items in \"db\" will be allocated with \"allocMain\" functions.\r\nSzArchiveOpen function allocates and frees temporary structures by \"allocTemp\" functions.\r\n\r\n5) List items or Extract items\r\n\r\n  Listing code:\r\n  ~~~~~~~~~~~~~\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n\r\n  Extracting code:\r\n  ~~~~~~~~~~~~~~~~\r\n\r\n  SZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n  If you need to decompress more than one file, you can send these values from previous call:\r\n    blockIndex, \r\n    outBuffer, \r\n    outBufferSize,\r\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \r\n  it will increase decompression speed.\r\n\r\n  After decompressing you must free \"outBuffer\":\r\n  allocImp.Free(outBuffer);\r\n\r\n6) call SzArDbExFree(&db, allocImp.Free) to free allocated items in \"db\".\r\n\r\n\r\n\r\n\r\nMemory requirements for .7z decoding \r\n------------------------------------\r\n\r\nMemory usage for Archive opening:\r\n  - Temporary pool:\r\n     - Memory for compressed .7z headers (if _LZMA_IN_CB is not defined)\r\n     - Memory for uncompressed .7z headers\r\n     - some other temporary blocks\r\n  - Main pool:\r\n     - Memory for database: \r\n       Estimated size of one file structures in solid archive:\r\n         - Size (4 or 8 Bytes)\r\n         - CRC32 (4 bytes)\r\n         - Some file information (4 bytes)\r\n         - File Name (variable length) + pointer + allocation structures\r\n\r\nMemory usage for archive Decompressing:\r\n  - Temporary pool:\r\n     - Memory for compressed solid block (if _LZMA_IN_CB is not defined)\r\n     - Memory for LZMA decompressing structures\r\n  - Main pool:\r\n     - Memory for decompressed solid block\r\n  \r\n\r\nIf _LZMA_IN_CB is defined, 7z Decoder will not allocate memory for \r\ncompressed blocks. Instead of this, you must allocate buffer with desired \r\nsize before calling 7z Decoder. Use 7zMain.c as example.\r\n\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\n7z Decoder functions can return one of the following codes:\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_CRC_ERROR (3)\r\n\r\n#define SZE_NOTIMPL (4)\r\n#define SZE_FAIL (5)\r\n\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB       - Use special callback mode for input stream to reduce memory requirements\r\n\r\n_SZ_FILE_SIZE_64  - define it if you need support for files larger than 4 GB\r\n_SZ_NO_INT_64     - define it if your compiler doesn't support long long int\r\n\r\n_LZMA_PROB32      - it can increase LZMA decompressing speed on some 32-bit CPUs.\r\n\r\n_SZ_ONE_DIRECTORY - define it if you want to locate all source files to one directory\r\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\r\n-----------------------------------\r\n\r\nThis file contains description of 7z archive format. \r\n7z archive can contain files compressed with any method.\r\nSee \"Methods.txt\" for description for defined compressing methods.\r\n\r\n\r\nFormat structure Overview\r\n-------------------------\r\n\r\nSome fields can be optional.\r\n\r\nArchive structure\r\n~~~~~~~~~~~~~~~~~  \r\nSignatureHeader\r\n[PackedStreams]\r\n[PackedStreamsForHeaders]\r\n[\r\n  Header \r\n  or \r\n  {\r\n    Packed Header\r\n    HeaderInfo\r\n  }\r\n]\r\n\r\n\r\n\r\nHeader structure\r\n~~~~~~~~~~~~~~~~  \r\n{\r\n  ArchiveProperties\r\n  AdditionalStreams\r\n  {\r\n    PackInfo\r\n    {\r\n      PackPos\r\n      NumPackStreams\r\n      Sizes[NumPackStreams]\r\n      CRCs[NumPackStreams]\r\n    }\r\n    CodersInfo\r\n    {\r\n      NumFolders\r\n      Folders[NumFolders]\r\n      {\r\n        NumCoders\r\n        CodersInfo[NumCoders]\r\n        {\r\n          ID\r\n          NumInStreams;\r\n          NumOutStreams;\r\n          PropertiesSize\r\n          Properties[PropertiesSize]\r\n        }\r\n        NumBindPairs\r\n        BindPairsInfo[NumBindPairs]\r\n        {\r\n          InIndex;\r\n          OutIndex;\r\n        }\r\n        PackedIndices\r\n      }\r\n      UnPackSize[Folders][Folders.NumOutstreams]\r\n      CRCs[NumFolders]\r\n    }\r\n    SubStreamsInfo\r\n    {\r\n      NumUnPackStreamsInFolders[NumFolders];\r\n      UnPackSizes[]\r\n      CRCs[]\r\n    }\r\n  }\r\n  MainStreamsInfo\r\n  {\r\n    (Same as in AdditionalStreams)\r\n  }\r\n  FilesInfo\r\n  {\r\n    NumFiles\r\n    Properties[]\r\n    {\r\n      ID\r\n      Size\r\n      Data\r\n    }\r\n  }\r\n}\r\n\r\nHeaderInfo structure\r\n~~~~~~~~~~~~~~~~~~~~\r\n{\r\n  (Same as in AdditionalStreams)\r\n}\r\n\r\n\r\n\r\nNotes about Notation and encoding\r\n---------------------------------\r\n\r\n7z uses little endian encoding.\r\n\r\n7z archive format has optional headers that are marked as\r\n[]\r\nHeader\r\n[]\r\n\r\nREAL_UINT64 means real UINT64.\r\n\r\nUINT64 means real UINT64 encoded with the following scheme:\r\n\r\n  Size of encoding sequence depends from first byte:\r\n  First_Byte  Extra_Bytes        Value\r\n  (binary)   \r\n  0xxxxxxx               : ( xxxxxxx           )\r\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r\n  ...\r\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r\n  11111110    BYTE y[7]  :                         y\r\n  11111111    BYTE y[8]  :                         y\r\n\r\n\r\n\r\nProperty IDs\r\n------------\r\n\r\n0x00 = kEnd,\r\n\r\n0x01 = kHeader,\r\n\r\n0x02 = kArchiveProperties,\r\n    \r\n0x03 = kAdditionalStreamsInfo,\r\n0x04 = kMainStreamsInfo,\r\n0x05 = kFilesInfo,\r\n    \r\n0x06 = kPackInfo,\r\n0x07 = kUnPackInfo,\r\n0x08 = kSubStreamsInfo,\r\n\r\n0x09 = kSize,\r\n0x0A = kCRC,\r\n\r\n0x0B = kFolder,\r\n\r\n0x0C = kCodersUnPackSize,\r\n0x0D = kNumUnPackStream,\r\n\r\n0x0E = kEmptyStream,\r\n0x0F = kEmptyFile,\r\n0x10 = kAnti,\r\n\r\n0x11 = kName,\r\n0x12 = kCreationTime,\r\n0x13 = kLastAccessTime,\r\n0x14 = kLastWriteTime,\r\n0x15 = kWinAttributes,\r\n0x16 = kComment,\r\n\r\n0x17 = kEncodedHeader,\r\n\r\n\r\n7z format headers\r\n-----------------\r\n\r\nSignatureHeader\r\n~~~~~~~~~~~~~~~\r\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n\r\n  ArchiveVersion\r\n  {\r\n    BYTE Major;   // now = 0\r\n    BYTE Minor;   // now = 2\r\n  };\r\n\r\n  UINT32 StartHeaderCRC;\r\n\r\n  StartHeader\r\n  {\r\n    REAL_UINT64 NextHeaderOffset\r\n    REAL_UINT64 NextHeaderSize\r\n    UINT32 NextHeaderCRC\r\n  }\r\n\r\n\r\n...........................\r\n\r\n\r\nArchiveProperties\r\n~~~~~~~~~~~~~~~~~\r\nBYTE NID::kArchiveProperties (0x02)\r\nwhile(true)\r\n{\r\n  BYTE PropertyType;\r\n  if (aType == 0)\r\n    break;\r\n  UINT64 PropertySize;\r\n  BYTE PropertyData[PropertySize];\r\n}\r\n\r\n\r\nDigests (NumStreams)\r\n~~~~~~~~~~~~~~~~~~~~~\r\n  BYTE AllAreDefined\r\n  if (AllAreDefined == 0)\r\n  {\r\n    for(NumStreams)\r\n      BIT Defined\r\n  }\r\n  UINT32 CRCs[NumDefined]\r\n\r\n\r\nPackInfo\r\n~~~~~~~~~~~~\r\n  BYTE NID::kPackInfo  (0x06)\r\n  UINT64 PackPos\r\n  UINT64 NumPackStreams\r\n\r\n  []\r\n  BYTE NID::kSize    (0x09)\r\n  UINT64 PackSizes[NumPackStreams]\r\n  []\r\n\r\n  []\r\n  BYTE NID::kCRC      (0x0A)\r\n  PackStreamDigests[NumPackStreams]\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFolder\r\n~~~~~~\r\n  UINT64 NumCoders;\r\n  for (NumCoders)\r\n  {\r\n    BYTE \r\n    {\r\n      0:3 DecompressionMethod.IDSize\r\n      4:\r\n        0 - IsSimple\r\n        1 - Is not simple\r\n      5:\r\n        0 - No Attributes\r\n        1 - There Are Attributes\r\n      7:\r\n        0 - Last Method in Alternative_Method_List\r\n        1 - There are more alternative methods\r\n    } \r\n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\r\n    if (!IsSimple)\r\n    {\r\n      UINT64 NumInStreams;\r\n      UINT64 NumOutStreams;\r\n    }\r\n    if (DecompressionMethod[0] != 0)\r\n    {\r\n      UINT64 PropertiesSize\r\n      BYTE Properties[PropertiesSize]\r\n    }\r\n  }\r\n    \r\n  NumBindPairs = NumOutStreamsTotal - 1;\r\n\r\n  for (NumBindPairs)\r\n  {\r\n    UINT64 InIndex;\r\n    UINT64 OutIndex;\r\n  }\r\n\r\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r\n  if (NumPackedStreams > 1)\r\n    for(NumPackedStreams)\r\n    {\r\n      UINT64 Index;\r\n    };\r\n\r\n\r\n\r\n\r\nCoders Info\r\n~~~~~~~~~~~\r\n\r\n  BYTE NID::kUnPackInfo  (0x07)\r\n\r\n\r\n  BYTE NID::kFolder  (0x0B)\r\n  UINT64 NumFolders\r\n  BYTE External\r\n  switch(External)\r\n  {\r\n    case 0:\r\n      Folders[NumFolders]\r\n    case 1:\r\n      UINT64 DataStreamIndex\r\n  }\r\n\r\n\r\n  BYTE ID::kCodersUnPackSize  (0x0C)\r\n  for(Folders)\r\n    for(Folder.NumOutStreams)\r\n     UINT64 UnPackSize;\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC   (0x0A)\r\n  UnPackDigests[NumFolders]\r\n  []\r\n\r\n  \r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\n\r\nSubStreams Info\r\n~~~~~~~~~~~~~~\r\n  BYTE NID::kSubStreamsInfo; (0x08)\r\n\r\n  []\r\n  BYTE NID::kNumUnPackStream; (0x0D)\r\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kSize  (0x09)\r\n  UINT64 UnPackSizes[]\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC  (0x0A)\r\n  Digests[Number of streams with unknown CRC]\r\n  []\r\n\r\n  \r\n  BYTE NID::kEnd\r\n\r\n\r\nStreams Info\r\n~~~~~~~~~~~~\r\n\r\n  []\r\n  PackInfo\r\n  []\r\n\r\n\r\n  []\r\n  CodersInfo\r\n  []\r\n\r\n\r\n  []\r\n  SubStreamsInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFilesInfo\r\n~~~~~~~~~\r\n  BYTE NID::kFilesInfo;  (0x05)\r\n  UINT64 NumFiles\r\n\r\n  while(true)\r\n  {\r\n    BYTE PropertyType;\r\n    if (aType == 0)\r\n      break;\r\n\r\n    UINT64 Size;\r\n\r\n    switch(PropertyType)\r\n    {\r\n      kEmptyStream:   (0x0E)\r\n        for(NumFiles)\r\n          BIT IsEmptyStream\r\n\r\n      kEmptyFile:     (0x0F)\r\n        for(EmptyStreams)\r\n          BIT IsEmptyFile\r\n\r\n      kAnti:          (0x10)\r\n        for(EmptyStreams)\r\n          BIT IsAntiFile\r\n      \r\n      case kCreationTime:   (0x12)\r\n      case kLastAccessTime: (0x13)\r\n      case kLastWriteTime:  (0x14)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT TimeDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Items)\r\n          UINT32 Time\r\n        []\r\n      \r\n      kNames:     (0x11)\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Files)\r\n        {\r\n          wchar_t Names[NameSize];\r\n          wchar_t 0;\r\n        }\r\n        []\r\n\r\n      kAttributes:  (0x15)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT AttributesAreDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Attributes)\r\n          UINT32 Attributes\r\n        []\r\n    }\r\n  }\r\n\r\n\r\nHeader\r\n~~~~~~\r\n  BYTE NID::kHeader (0x01)\r\n\r\n  []\r\n  ArchiveProperties\r\n  []\r\n\r\n  []\r\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  BYTE NID::kMainStreamsInfo;    (0x04)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  FilesInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nHeaderInfo\r\n~~~~~~~~~~\r\n  []\r\n  BYTE NID::kEncodedHeader; (0x17)\r\n  StreamsInfo for Encoded Header\r\n  []\r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zAlloc.c",
    "content": "/* 7zAlloc.c */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n#endif\r\n\r\nvoid *SzAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zAlloc.h",
    "content": "/* 7zAlloc.h */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\nvoid *SzAlloc(size_t size);\r\nvoid SzFree(void *address);\r\n\r\nvoid *SzAllocTemp(size_t size);\r\nvoid SzFreeTemp(void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zBuffer.c",
    "content": "/* 7zBuffer.c */\r\n\r\n#include \"7zBuffer.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer)\r\n{\r\n  buffer->Capacity = 0;\r\n  buffer->Items = 0;\r\n}\r\n\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))\r\n{\r\n  buffer->Capacity = newCapacity;\r\n  if (newCapacity == 0)\r\n  {\r\n    buffer->Items = 0;\r\n    return 1;\r\n  }\r\n  buffer->Items = (Byte *)allocFunc(newCapacity);\r\n  return (buffer->Items != 0);\r\n}\r\n\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(buffer->Items);\r\n  buffer->Items = 0;\r\n  buffer->Capacity = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zBuffer.h",
    "content": "/* 7zBuffer.h */\r\n\r\n#ifndef __7Z_BUFFER_H\r\n#define __7Z_BUFFER_H\r\n\r\n#include <stddef.h>\r\n#include \"7zTypes.h\"\r\n\r\ntypedef struct _CSzByteBuffer\r\n{    \r\n\tsize_t Capacity;\r\n  Byte *Items;\r\n}CSzByteBuffer;\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer);\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zCrc.c",
    "content": "/* 7zCrc.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid InitCrcTable()\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      if (r & 1) \r\n        r = (r >> 1) ^ kCrcPoly;\r\n      else     \r\n        r >>= 1;\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nvoid CrcInit(UInt32 *crc) { *crc = 0xFFFFFFFF; }\r\nUInt32 CrcGetDigest(UInt32 *crc) { return *crc ^ 0xFFFFFFFF; } \r\n\r\nvoid CrcUpdateByte(UInt32 *crc, Byte b)\r\n{\r\n  *crc = g_CrcTable[((Byte)(*crc)) ^ b] ^ (*crc >> 8);\r\n}\r\n\r\nvoid CrcUpdateUInt16(UInt32 *crc, UInt16 v)\r\n{\r\n  CrcUpdateByte(crc, (Byte)v);\r\n  CrcUpdateByte(crc, (Byte)(v >> 8));\r\n}\r\n\r\nvoid CrcUpdateUInt32(UInt32 *crc, UInt32 v)\r\n{\r\n  int i;\r\n  for (i = 0; i < 4; i++)\r\n    CrcUpdateByte(crc, (Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CrcUpdateUInt64(UInt32 *crc, UInt64 v)\r\n{\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    CrcUpdateByte(crc, (Byte)(v));\r\n    v >>= 8;\r\n  }\r\n}\r\n\r\nvoid CrcUpdate(UInt32 *crc, const void *data, size_t size)\r\n{\r\n  UInt32 v = *crc;\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = g_CrcTable[((Byte)(v)) ^ *p] ^ (v >> 8);\r\n  *crc = v;\r\n}\r\n\r\nUInt32 CrcCalculateDigest(const void *data, size_t size)\r\n{\r\n  UInt32 crc;\r\n  CrcInit(&crc);\r\n  CrcUpdate(&crc, data, size);\r\n  return CrcGetDigest(&crc);\r\n}\r\n\r\nint CrcVerifyDigest(UInt32 digest, const void *data, size_t size)\r\n{\r\n  return (CrcCalculateDigest(data, size) == digest);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zCrc.h",
    "content": "/* 7zCrc.h */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"7zTypes.h\"\r\n\r\nextern UInt32 g_CrcTable[256];\r\nvoid InitCrcTable();\r\n\r\nvoid CrcInit(UInt32 *crc);\r\nUInt32 CrcGetDigest(UInt32 *crc);\r\nvoid CrcUpdateByte(UInt32 *crc, Byte v);\r\nvoid CrcUpdateUInt16(UInt32 *crc, UInt16 v);\r\nvoid CrcUpdateUInt32(UInt32 *crc, UInt32 v);\r\nvoid CrcUpdateUInt64(UInt32 *crc, UInt64 v);\r\nvoid CrcUpdate(UInt32 *crc, const void *data, size_t size);\r\n \r\nUInt32 CrcCalculateDigest(const void *data, size_t size);\r\nint CrcVerifyDigest(UInt32 digest, const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zDecode.c",
    "content": "/* 7zDecode.c */\r\n\r\n#include \"7zDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#else\r\n#include \"../../Compress/LZMA_C/LzmaDecode.h\"\r\n#endif\r\n\r\nCMethodID k_Copy = { { 0x0 }, 1 };\r\nCMethodID k_LZMA = { { 0x3, 0x1, 0x1 }, 3 };\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\ntypedef struct _CLzmaInCallbackImp\r\n{\r\n  ILzmaInCallback InCallback;\r\n  ISzInStream *InStream;\r\n  size_t Size;\r\n} CLzmaInCallbackImp;\r\n\r\nint LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object;\r\n  size_t processedSize;\r\n  SZ_RESULT res;\r\n  *size = 0;\r\n  res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, cb->Size, &processedSize);\r\n  *size = (SizeT)processedSize;\r\n  if (processedSize > cb->Size)\r\n    return (int)SZE_FAIL;\r\n  cb->Size -= processedSize;\r\n  if (res == SZ_OK)\r\n    return 0;\r\n  return (int)res;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, \r\n    size_t *outSizeProcessed, ISzAlloc *allocMain)\r\n{\r\n  UInt32 si;\r\n  size_t inSize = 0;\r\n  CCoderInfo *coder;\r\n  if (folder->NumPackStreams != 1)\r\n    return SZE_NOTIMPL;\r\n  if (folder->NumCoders != 1)\r\n    return SZE_NOTIMPL;\r\n  coder = folder->Coders;\r\n  *outSizeProcessed = 0;\r\n\r\n  for (si = 0; si < folder->NumPackStreams; si++)\r\n    inSize += (size_t)packSizes[si];\r\n\r\n  if (AreMethodsEqual(&coder->MethodID, &k_Copy))\r\n  {\r\n    size_t i;\r\n    if (inSize != outSize)\r\n      return SZE_DATA_ERROR;\r\n    #ifdef _LZMA_IN_CB\r\n    for (i = 0; i < inSize;)\r\n    {\r\n      size_t j;\r\n      Byte *inBuffer;\r\n      size_t bufferSize;\r\n      RINOK(inStream->Read((void *)inStream,  (void **)&inBuffer, inSize - i, &bufferSize));\r\n      if (bufferSize == 0)\r\n        return SZE_DATA_ERROR;\r\n      if (bufferSize > inSize - i)\r\n        return SZE_FAIL;\r\n      *outSizeProcessed += bufferSize;\r\n      for (j = 0; j < bufferSize && i < inSize; j++, i++)\r\n        outBuffer[i] = inBuffer[j];\r\n    }\r\n    #else\r\n    for (i = 0; i < inSize; i++)\r\n      outBuffer[i] = inBuffer[i];\r\n    *outSizeProcessed = inSize;\r\n    #endif\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (AreMethodsEqual(&coder->MethodID, &k_LZMA))\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    CLzmaInCallbackImp lzmaCallback;\r\n    #else\r\n    SizeT inProcessed;\r\n    #endif\r\n\r\n    CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n    int result;\r\n    SizeT outSizeProcessedLoc;\r\n\r\n    #ifdef _LZMA_IN_CB\r\n    lzmaCallback.Size = inSize;\r\n    lzmaCallback.InStream = inStream;\r\n    lzmaCallback.InCallback.Read = LzmaReadImp;\r\n    #endif\r\n\r\n    if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, \r\n        coder->Properties.Capacity) != LZMA_RESULT_OK)\r\n      return SZE_FAIL;\r\n\r\n    state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n    if (state.Probs == 0)\r\n      return SZE_OUTOFMEMORY;\r\n\r\n    #ifdef _LZMA_OUT_READ\r\n    if (state.Properties.DictionarySize == 0)\r\n      state.Dictionary = 0;\r\n    else\r\n    {\r\n      state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize);\r\n      if (state.Dictionary == 0)\r\n      {\r\n        allocMain->Free(state.Probs);\r\n        return SZE_OUTOFMEMORY;\r\n      }\r\n    }\r\n    LzmaDecoderInit(&state);\r\n    #endif\r\n\r\n    result = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &lzmaCallback.InCallback,\r\n        #else\r\n        inBuffer, (SizeT)inSize, &inProcessed,\r\n        #endif\r\n        outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n    *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n    allocMain->Free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    allocMain->Free(state.Dictionary);\r\n    #endif\r\n    if (result == LZMA_RESULT_DATA_ERROR)\r\n      return SZE_DATA_ERROR;\r\n    if (result != LZMA_RESULT_OK)\r\n      return SZE_FAIL;\r\n    return SZ_OK;\r\n  }\r\n  return SZE_NOTIMPL;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zDecode.h",
    "content": "/* 7zDecode.h */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n#ifdef _LZMA_IN_CB\r\n#include \"7zIn.h\"\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *stream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, \r\n    size_t *outSizeProcessed, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zExtract.c",
    "content": "/* 7zExtract.c */\r\n\r\n#include \"7zExtract.h\"\r\n#include \"7zDecode.h\"\r\n#include \"7zCrc.h\"\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer, \r\n    size_t *outBufferSize,\r\n    size_t *offset, \r\n    size_t *outSizeProcessed, \r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];\r\n  SZ_RESULT res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    allocMain->Free(*outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CFolder *folder = db->Database.Folders + folderIndex;\r\n    CFileSize unPackSize = SzFolderGetUnPackSize(folder);\r\n    #ifndef _LZMA_IN_CB\r\n    CFileSize packSize = SzArDbGetFolderFullPackSize(db, folderIndex);\r\n    Byte *inBuffer = 0;\r\n    size_t processedSize;\r\n    #endif\r\n    *blockIndex = folderIndex;\r\n    allocMain->Free(*outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(inStream->Seek(inStream, SzArDbGetFolderStreamPos(db, folderIndex, 0)));\r\n    \r\n    #ifndef _LZMA_IN_CB\r\n    if (packSize != 0)\r\n    {\r\n      inBuffer = (Byte *)allocTemp->Alloc((size_t)packSize);\r\n      if (inBuffer == 0)\r\n        return SZE_OUTOFMEMORY;\r\n    }\r\n    res = inStream->Read(inStream, inBuffer, (size_t)packSize, &processedSize);\r\n    if (res == SZ_OK && processedSize != (size_t)packSize)\r\n      res = SZE_FAIL;\r\n    #endif\r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = (size_t)unPackSize;\r\n      if (unPackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)allocMain->Alloc((size_t)unPackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZE_OUTOFMEMORY;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        size_t outRealSize;\r\n        res = SzDecode(db->Database.PackSizes + \r\n          db->FolderStartPackStreamIndex[folderIndex], folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream,\r\n          #else\r\n          inBuffer, \r\n          #endif\r\n          *outBuffer, (size_t)unPackSize, &outRealSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (outRealSize == (size_t)unPackSize)\r\n          {\r\n            if (folder->UnPackCRCDefined)\r\n            {\r\n              if (!CrcVerifyDigest(folder->UnPackCRC, *outBuffer, (size_t)unPackSize))\r\n                res = SZE_FAIL;\r\n            }\r\n          }\r\n          else\r\n            res = SZE_FAIL;\r\n        }\r\n      }\r\n    }\r\n    #ifndef _LZMA_IN_CB\r\n    allocTemp->Free(inBuffer);\r\n    #endif\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i; \r\n    CFileItem *fileItem = db->Database.Files + fileIndex;\r\n    *offset = 0;\r\n    for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)db->Database.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZE_FAIL;\r\n    {\r\n      if (fileItem->IsFileCRCDefined)\r\n      {\r\n        if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer + *offset, *outSizeProcessed))\r\n          res = SZE_FAIL;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zExtract.h",
    "content": "/* 7zExtract.h */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive. \r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send \r\n    these values from previous call:\r\n      *blockIndex, \r\n      *outBuffer, \r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid, \r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables \r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zHeader.c",
    "content": "/*  7zHeader.c */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zHeader.h",
    "content": "/* 7zHeader.h */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"7zTypes.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnPackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnPackSize,\r\n  k7zIdNumUnPackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCreationTime,\r\n  k7zIdLastAccessTime,\r\n  k7zIdLastWriteTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zIn.c",
    "content": "/* 7zIn.c */\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zCrc.h\"\r\n#include \"7zDecode.h\"\r\n\r\n#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db)\r\n{\r\n  SzArchiveDatabaseInit(&db->Database);\r\n  db->FolderStartPackStreamIndex = 0;\r\n  db->PackStreamStartPositions = 0;\r\n  db->FolderStartFileIndex = 0;\r\n  db->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(db->FolderStartPackStreamIndex);\r\n  freeFunc(db->PackStreamStartPositions);\r\n  freeFunc(db->FolderStartFileIndex);\r\n  freeFunc(db->FileIndexToFolderIndexMap);\r\n  SzArchiveDatabaseFree(&db->Database, freeFunc);\r\n  SzArDbExInit(db);\r\n}\r\n\r\n/*\r\nCFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nCFileSize GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n#define MY_ALLOC(T, p, size, allocFunc) { if ((size) == 0) p = 0; else \\\r\n  if ((p = (T *)allocFunc((size) * sizeof(T))) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nSZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 startPos = 0;\r\n  CFileSize startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  MY_ALLOC(UInt32, db->FolderStartPackStreamIndex, db->Database.NumFolders, allocFunc);\r\n  for(i = 0; i < db->Database.NumFolders; i++)\r\n  {\r\n    db->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += db->Database.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  MY_ALLOC(CFileSize, db->PackStreamStartPositions, db->Database.NumPackStreams, allocFunc);\r\n\r\n  for(i = 0; i < db->Database.NumPackStreams; i++)\r\n  {\r\n    db->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += db->Database.PackSizes[i];\r\n  }\r\n\r\n  MY_ALLOC(UInt32, db->FolderStartFileIndex, db->Database.NumFolders, allocFunc);\r\n  MY_ALLOC(UInt32, db->FileIndexToFolderIndexMap, db->Database.NumFiles, allocFunc);\r\n\r\n  for (i = 0; i < db->Database.NumFiles; i++)\r\n  {\r\n    CFileItem *file = db->Database.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      db->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      while(1)\r\n      {\r\n        if (folderIndex >= db->Database.NumFolders)\r\n          return SZE_ARCHIVE_ERROR;\r\n        db->FolderStartFileIndex[folderIndex] = i;\r\n        if (db->Database.Folders[folderIndex].NumUnPackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    db->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return db->ArchiveInfo.DataStartPosition + \r\n    db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nCFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex)\r\n{\r\n  UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n  CFolder *folder = db->Database.Folders + folderIndex;\r\n  CFileSize size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n    size += db->Database.PackSizes[packStreamIndex + i];\r\n  return size;\r\n}\r\n\r\n\r\n/*\r\nSZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case k7zIdLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case k7zIdLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nSZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  while (size > 0)\r\n  {\r\n    Byte *inBuffer;\r\n    size_t processedSize;\r\n    RINOK(inStream->Read(inStream, (void **)&inBuffer, size, &processedSize));\r\n    if (processedSize == 0 || processedSize > size)\r\n      return SZE_FAIL;\r\n    size -= processedSize;\r\n    do\r\n    {\r\n      *data++ = *inBuffer++;\r\n    }\r\n    while (--processedSize != 0);\r\n  }\r\n  #else\r\n  size_t processedSize;\r\n  RINOK(inStream->Read(inStream, data, size, &processedSize));\r\n  if (processedSize != size)\r\n    return SZE_FAIL;\r\n  #endif\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data)\r\n{\r\n  return SafeReadDirect(inStream, data, 1);\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nint TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nSZ_RESULT SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  *value = (CFileSize)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZE_NOTIMPL;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZE_NOTIMPL;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadID(CSzData *sd, UInt64 *value) \r\n{ \r\n  return SzReadNumber(sd, value); \r\n}\r\n\r\nSZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nSZ_RESULT SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZE_ARCHIVE_ERROR;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  MY_ALLOC(Byte, *v, numItems, allocFunc);\r\n  for(i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, allocFunc);\r\n  MY_ALLOC(Byte, *v, numItems, allocFunc);\r\n  for(i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHashDigests(\r\n    CSzData *sd, \r\n    size_t numItems,\r\n    Byte **digestsDefined, \r\n    UInt32 **digests, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc));\r\n  MY_ALLOC(UInt32, *digests, numItems, allocFunc);\r\n  for(i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadPackInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    CFileSize **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadSize(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, allocFunc);\r\n\r\n  for(i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadSize(sd, (*packSizes) + i));\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc)); \r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, allocFunc);\r\n    MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, allocFunc);\r\n    for(i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR;\r\n}\r\n\r\nSZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 numCoders;\r\n  UInt32 numBindPairs;\r\n  UInt32 numPackedStreams;\r\n  UInt32 i;\r\n  UInt32 numInStreams = 0;\r\n  UInt32 numOutStreams = 0;\r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  folder->NumCoders = numCoders;\r\n\r\n  MY_ALLOC(CCoderInfo, folder->Coders, (size_t)numCoders, allocFunc);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfoInit(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      coder->MethodID.IDSize = (Byte)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, coder->MethodID.ID, coder->MethodID.IDSize));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc))\r\n          return SZE_OUTOFMEMORY;\r\n        RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += (UInt32)coder->NumInStreams;\r\n    numOutStreams += (UInt32)coder->NumOutStreams;\r\n  }\r\n\r\n  numBindPairs = numOutStreams - 1;\r\n  folder->NumBindPairs = numBindPairs;\r\n\r\n\r\n  MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, allocFunc);\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bindPair = folder->BindPairs + i;;\r\n    RINOK(SzReadNumber32(sd, &bindPair->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bindPair->OutIndex)); \r\n  }\r\n\r\n  numPackedStreams = numInStreams - (UInt32)numBindPairs;\r\n\r\n  folder->NumPackStreams = numPackedStreams;\r\n  MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, allocFunc);\r\n\r\n  if (numPackedStreams == 1)\r\n  {\r\n    UInt32 j;\r\n    UInt32 pi = 0;\r\n    for (j = 0; j < numInStreams; j++)\r\n      if (SzFolderFindBindPairForInStream(folder, j) < 0)\r\n      {\r\n        folder->PackStreams[pi++] = j;\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUnPackInfo(\r\n    CSzData *sd, \r\n    UInt32 *numFolders,\r\n    CFolder **folders,  /* for allocFunc */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n    MY_ALLOC(CFolder, *folders, (size_t)*numFolders, allocFunc);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n      SzFolderInit((*folders) + i);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));\r\n\r\n  for(i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolderGetNumOutStreams(folder);\r\n\r\n    MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, allocFunc);\r\n\r\n    for(j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadSize(sd, folder->UnPackSizes + j));\r\n    }\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SZ_RESULT res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc); \r\n      if (res == SZ_OK)\r\n      {\r\n        for(i = 0; i < *numFolders; i++)\r\n        {\r\n          CFolder *folder = (*folders) + i;\r\n          folder->UnPackCRCDefined = crcsDefined[i];\r\n          folder->UnPackCRC = crcs[i];\r\n        }\r\n      }\r\n      allocTemp->Free(crcs);\r\n      allocTemp->Free(crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadSubStreamsInfo(\r\n    CSzData *sd, \r\n    UInt32 numFolders,\r\n    CFolder *folders,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n    folders[i].NumUnPackStreams = 1;\r\n  *numUnPackStreams = numFolders;\r\n\r\n  while(1)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnPackStream)\r\n    {\r\n      *numUnPackStreams = 0;\r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnPackStreams = numStreams;\r\n        *numUnPackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnPackStreams == 0)\r\n  {\r\n    *unPackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize));\r\n    RINOM(*unPackSizes);\r\n    *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    CFileSize sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      CFileSize size;\r\n      RINOK(SzReadSize(sd, &size));\r\n      (*unPackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for(i = 0; i < *numUnPackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  while(1)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0; \r\n      UInt32 *digests2 = 0;\r\n      SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnPackStreams;\r\n          if (numSubstreams == 1 && folder->UnPackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnPackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      allocTemp->Free(digestsDefined2);\r\n      allocTemp->Free(digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nSZ_RESULT SzReadStreamsInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    CArchiveDatabase *db,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZE_FAIL;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams, \r\n            &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc));\r\n        break;\r\n      }\r\n      case k7zIdUnPackInfo:\r\n      {\r\n        RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders, \r\n            numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZE_FAIL;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nSZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CFileItem *file = files + i;\r\n    while(pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZE_ARCHIVE_ERROR;\r\n        if (pos + 2 > sd->Size)\r\n          return SZE_ARCHIVE_ERROR;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZE_ARCHIVE_ERROR;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    MY_ALLOC(char, file->Name, (size_t)len, allocFunc);\r\n\r\n    len = 0;\r\n    while(2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while(numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHeader2(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db,   /* allocMain */\r\n    CFileSize **unPackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnPackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &db->ArchiveInfo.DataStartPosition,\r\n        &db->Database, \r\n        &numUnPackStreams,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests, allocMain->Alloc, allocTemp));\r\n    db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZE_ARCHIVE_ERROR;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  db->Database.NumFiles = numFiles;\r\n\r\n  MY_ALLOC(CFileItem, files, (size_t)numFiles, allocMain->Alloc);\r\n\r\n  db->Database.Files = files;\r\n  for(i = 0; i < numFiles; i++)\r\n    SzFileInit(files + i);\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc));\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for(i = 0; i < numFiles; i++)\r\n    {\r\n      CFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if(file->HasStream)\r\n      {\r\n        file->IsDirectory = 0;\r\n        file->Size = (*unPackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->IsFileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDirectory = 1;\r\n        else\r\n          file->IsDirectory = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->IsFileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArDbExFill(db, allocMain->Alloc);\r\n}\r\n\r\nSZ_RESULT SzReadHeader(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db, \r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  SZ_RESULT res = SzReadHeader2(sd, db, \r\n      &unPackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector,\r\n      allocMain, allocTemp);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  allocTemp->Free(emptyStreamVector);\r\n  allocTemp->Free(emptyFileVector);\r\n  return res;\r\n} \r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams2(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    CArchiveDatabase *db,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    #ifndef _LZMA_IN_CB\r\n    Byte **inBuffer,\r\n    #endif\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnPackStreams = 0;\r\n  CFileSize dataStartPos;\r\n  CFolder *folder;\r\n  #ifndef _LZMA_IN_CB\r\n  CFileSize packSize = 0;\r\n  UInt32 i = 0;\r\n  #endif\r\n  CFileSize unPackSize;\r\n  size_t outRealSize;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, db,\r\n      &numUnPackStreams,  unPackSizes, digestsDefined, digests, \r\n      allocTemp->Alloc, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (db->NumFolders != 1)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  folder = db->Folders;\r\n  unPackSize = SzFolderGetUnPackSize(folder);\r\n  \r\n  RINOK(inStream->Seek(inStream, dataStartPos));\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  for (i = 0; i < db->NumPackStreams; i++)\r\n    packSize += db->PackSizes[i];\r\n\r\n  MY_ALLOC(Byte, *inBuffer, (size_t)packSize, allocTemp->Alloc);\r\n\r\n  RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize));\r\n  #endif\r\n\r\n  if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  res = SzDecode(db->PackSizes, folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream,\r\n          #else\r\n          *inBuffer, \r\n          #endif\r\n          outBuffer->Items, (size_t)unPackSize,\r\n          &outRealSize, allocTemp);\r\n  RINOK(res)\r\n  if (outRealSize != (UInt32)unPackSize)\r\n    return SZE_FAIL;\r\n  if (folder->UnPackCRCDefined)\r\n    if (!CrcVerifyDigest(folder->UnPackCRC, outBuffer->Items, (size_t)unPackSize))\r\n      return SZE_FAIL;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CArchiveDatabase db;\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  #ifndef _LZMA_IN_CB\r\n  Byte *inBuffer = 0;\r\n  #endif\r\n  SZ_RESULT res;\r\n  SzArchiveDatabaseInit(&db);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset, \r\n    &db, &unPackSizes, &digestsDefined, &digests, \r\n    #ifndef _LZMA_IN_CB\r\n    &inBuffer,\r\n    #endif\r\n    allocTemp);\r\n  SzArchiveDatabaseFree(&db, allocTemp->Free);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  #ifndef _LZMA_IN_CB\r\n  allocTemp->Free(inBuffer);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen2(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte signature[k7zSignatureSize];\r\n  Byte version;\r\n  UInt32 crcFromArchive;\r\n  UInt64 nextHeaderOffset;\r\n  UInt64 nextHeaderSize;\r\n  UInt32 nextHeaderCRC;\r\n  UInt32 crc;\r\n  CFileSize pos = 0;\r\n  CSzByteBuffer buffer;\r\n  CSzData sd;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize));\r\n\r\n  if (!TestSignatureCandidate(signature))\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  /*\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n  */\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n  if (version != k7zMajorVersion)\r\n    return SZE_ARCHIVE_ERROR;\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n\r\n  RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive));\r\n\r\n  CrcInit(&crc);\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset));\r\n  CrcUpdateUInt64(&crc, nextHeaderOffset);\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize));\r\n  CrcUpdateUInt64(&crc, nextHeaderSize);\r\n  RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC));\r\n  CrcUpdateUInt32(&crc, nextHeaderCRC);\r\n\r\n  pos = k7zStartHeaderSize;\r\n  db->ArchiveInfo.StartPositionAfterHeader = pos;\r\n  \r\n  if (CrcGetDigest(&crc) != crcFromArchive)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  if (nextHeaderSize == 0)\r\n    return SZ_OK;\r\n\r\n  RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset)));\r\n\r\n  if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize);\r\n  if (res == SZ_OK)\r\n  {\r\n    if (CrcVerifyDigest(nextHeaderCRC, buffer.Items, (UInt32)nextHeaderSize))\r\n    {\r\n      while (1)\r\n      {\r\n        UInt64 type;\r\n        sd.Data = buffer.Items;\r\n        sd.Size = buffer.Capacity;\r\n        res = SzReadID(&sd, &type);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (type == k7zIdHeader)\r\n        {\r\n          res = SzReadHeader(&sd, db, allocMain, allocTemp);\r\n          break;\r\n        }\r\n        if (type != k7zIdEncodedHeader)\r\n        {\r\n          res = SZE_ARCHIVE_ERROR;\r\n          break;\r\n        }\r\n        {\r\n          CSzByteBuffer outBuffer;\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, \r\n              db->ArchiveInfo.StartPositionAfterHeader, \r\n              allocTemp);\r\n          if (res != SZ_OK)\r\n          {\r\n            SzByteBufferFree(&outBuffer, allocTemp->Free);\r\n            break;\r\n          }\r\n          SzByteBufferFree(&buffer, allocTemp->Free);\r\n          buffer.Items = outBuffer.Items;\r\n          buffer.Capacity = outBuffer.Capacity;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  SzByteBufferFree(&buffer, allocTemp->Free);\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArDbExFree(db, allocMain->Free);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zIn.h",
    "content": "/* 7zIn.h */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n \r\ntypedef struct _CInArchiveInfo\r\n{\r\n  CFileSize StartPositionAfterHeader; \r\n  CFileSize DataStartPosition;\r\n}CInArchiveInfo;\r\n\r\ntypedef struct _CArchiveDatabaseEx\r\n{\r\n  CArchiveDatabase Database;\r\n  CInArchiveInfo ArchiveInfo;\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  CFileSize *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n}CArchiveDatabaseEx;\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db);\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);\r\nCFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex);\r\n\r\ntypedef struct _ISzInStream\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  SZ_RESULT (*Read)(\r\n      void *object,           /* pointer to ISzInStream itself */\r\n      void **buffer,          /* out: pointer to buffer with data */\r\n      size_t maxRequiredSize, /* max required size to read */\r\n      size_t *processedSize); /* real processed size. \r\n                                 processedSize can be less than maxRequiredSize.\r\n                                 If processedSize == 0, then there are no more \r\n                                 bytes in stream. */\r\n  #else\r\n  SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);\r\n  #endif\r\n  SZ_RESULT (*Seek)(void *object, CFileSize pos);\r\n} ISzInStream;\r\n\r\n \r\nint SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zItem.c",
    "content": "/* 7zItem.c */\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder)\r\n{\r\n  SzByteBufferInit(&coder->Properties);\r\n}\r\n\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))\r\n{\r\n  SzByteBufferFree(&coder->Properties, freeFunc);\r\n  SzCoderInfoInit(coder);\r\n}\r\n\r\nvoid SzFolderInit(CFolder *folder)\r\n{\r\n  folder->NumCoders = 0;\r\n  folder->Coders = 0;\r\n  folder->NumBindPairs = 0;\r\n  folder->BindPairs = 0;\r\n  folder->NumPackStreams = 0;\r\n  folder->PackStreams = 0;\r\n  folder->UnPackSizes = 0;\r\n  folder->UnPackCRCDefined = 0;\r\n  folder->UnPackCRC = 0;\r\n  folder->NumUnPackStreams = 0;\r\n}\r\n\r\nvoid SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    SzCoderInfoFree(&folder->Coders[i], freeFunc);\r\n  freeFunc(folder->Coders);\r\n  freeFunc(folder->BindPairs);\r\n  freeFunc(folder->PackStreams);\r\n  freeFunc(folder->UnPackSizes);\r\n  SzFolderInit(folder);\r\n}\r\n\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    result += folder->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder)\r\n{ \r\n  int i = (int)SzFolderGetNumOutStreams(folder);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolderFindBindPairForOutStream(folder, i) < 0)\r\n      return folder->UnPackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\n/*\r\nint FindPackStreamArrayIndex(int inStreamIndex) const\r\n{\r\n  for(int i = 0; i < PackStreams.Size(); i++)\r\n  if (PackStreams[i] == inStreamIndex)\r\n    return i;\r\n  return -1;\r\n}\r\n*/\r\n\r\nvoid SzFileInit(CFileItem *fileItem)\r\n{\r\n  fileItem->IsFileCRCDefined = 0;\r\n  fileItem->HasStream = 1;\r\n  fileItem->IsDirectory = 0;\r\n  fileItem->IsAnti = 0;\r\n  fileItem->Name = 0;\r\n}\r\n\r\nvoid SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))\r\n{\r\n  freeFunc(fileItem->Name);\r\n  SzFileInit(fileItem);\r\n}\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db)\r\n{\r\n  db->NumPackStreams = 0;\r\n  db->PackSizes = 0;\r\n  db->PackCRCsDefined = 0;\r\n  db->PackCRCs = 0;\r\n  db->NumFolders = 0;\r\n  db->Folders = 0;\r\n  db->NumFiles = 0;\r\n  db->Files = 0;\r\n}\r\n\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < db->NumFolders; i++)\r\n    SzFolderFree(&db->Folders[i], freeFunc);\r\n  for (i = 0; i < db->NumFiles; i++)\r\n    SzFileFree(&db->Files[i], freeFunc);\r\n  freeFunc(db->PackSizes);\r\n  freeFunc(db->PackCRCsDefined);\r\n  freeFunc(db->PackCRCs);\r\n  freeFunc(db->Folders);\r\n  freeFunc(db->Files);\r\n  SzArchiveDatabaseInit(db);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zItem.h",
    "content": "/* 7zItem.h */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"7zMethodID.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zBuffer.h\"\r\n\r\ntypedef struct _CCoderInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  CMethodID MethodID;\r\n  CSzByteBuffer Properties;\r\n}CCoderInfo;\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder);\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));\r\n\r\ntypedef struct _CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n}CBindPair;\r\n\r\ntypedef struct _CFolder\r\n{\r\n  UInt32 NumCoders;\r\n  CCoderInfo *Coders;\r\n  UInt32 NumBindPairs;\r\n  CBindPair *BindPairs;\r\n  UInt32 NumPackStreams; \r\n  UInt32 *PackStreams;\r\n  CFileSize *UnPackSizes;\r\n  int UnPackCRCDefined;\r\n  UInt32 UnPackCRC;\r\n\r\n  UInt32 NumUnPackStreams;\r\n}CFolder;\r\n\r\nvoid SzFolderInit(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\n\r\n/* #define CArchiveFileTime UInt64 */\r\n\r\ntypedef struct _CFileItem\r\n{\r\n  /*\r\n  CArchiveFileTime LastWriteTime;\r\n  CFileSize StartPos;\r\n  UInt32 Attributes; \r\n  */\r\n  CFileSize Size;\r\n  UInt32 FileCRC;\r\n  char *Name;\r\n\r\n  Byte IsFileCRCDefined;\r\n  Byte HasStream;\r\n  Byte IsDirectory;\r\n  Byte IsAnti;\r\n  /*\r\n  int AreAttributesDefined;\r\n  int IsLastWriteTimeDefined;\r\n  int IsStartPosDefined;\r\n  */\r\n}CFileItem;\r\n\r\nvoid SzFileInit(CFileItem *fileItem);\r\n\r\ntypedef struct _CArchiveDatabase\r\n{\r\n  UInt32 NumPackStreams;\r\n  CFileSize *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  UInt32 NumFolders;\r\n  CFolder *Folders;\r\n  UInt32 NumFiles;\r\n  CFileItem *Files;\r\n}CArchiveDatabase;\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db);\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));\r\n\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zMain.c",
    "content": "/* \r\n7zMain.c\r\nTest application for 7z Decoder\r\nLZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-06-04)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"7zCrc.h\"\r\n#include \"7zIn.h\"\r\n#include \"7zExtract.h\"\r\n\r\ntypedef struct _CFileInStream\r\n{\r\n  ISzInStream InStream;\r\n  FILE *File;\r\n} CFileInStream;\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define kBufferSize (1 << 12)\r\nByte g_Buffer[kBufferSize];\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc;\r\n  if (maxRequiredSize > kBufferSize)\r\n    maxRequiredSize = kBufferSize;\r\n  processedSizeLoc = fread(g_Buffer, 1, maxRequiredSize, s->File);\r\n  *buffer = g_Buffer;\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#else\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc = fread(buffer, 1, size, s->File);\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzFileSeekImp(void *object, CFileSize pos)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  int res = fseek(s->File, (long)pos, SEEK_SET);\r\n  if (res == 0)\r\n    return SZ_OK;\r\n  return SZE_FAIL;\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CArchiveDatabaseEx db;\r\n  SZ_RESULT res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder 4.43  Copyright (c) 1999-2006 Igor Pavlov  2006-06-04\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.File = fopen(args[2], \"rb\");\r\n  if (archiveStream.File == 0)\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.InStream.Read = SzFileReadImp;\r\n  archiveStream.InStream.Seek = SzFileSeekImp;\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  InitCrcTable();\r\n  SzArDbExInit(&db);\r\n  res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0;\r\n    int testCommand = 0;\r\n    int extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0)\r\n      listCommand = 1;\r\n    if (strcmp(command, \"t\") == 0)\r\n      testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0)\r\n      extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      /*\r\n      if you need cache, use these 3 variables.\r\n      if you use external function, you can make these variable as static.\r\n      */\r\n      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r\n      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r\n      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CFileItem *f = db.Database.Files + i;\r\n        if (f->IsDirectory)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ? \r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDirectory)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzExtract(&archiveStream.InStream, &db, i, \r\n            &blockIndex, &outBuffer, &outBufferSize, \r\n            &offset, &outSizeProcessed, \r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          FILE *outputHandle;\r\n          UInt32 processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          outputHandle = fopen(fileName, \"wb+\");\r\n          if (outputHandle == 0)\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          processedSize = fwrite(outBuffer + offset, 1, outSizeProcessed, outputHandle);\r\n          if (processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          if (fclose(outputHandle))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      allocImp.Free(outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZE_FAIL;\r\n    }\r\n  }\r\n  SzArDbExFree(&db, allocImp.Free);\r\n\r\n  fclose(archiveStream.File);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == SZE_OUTOFMEMORY)\r\n    PrintError(\"can not allocate memory\");\r\n  else     \r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zMethodID.c",
    "content": "/* 7zMethodID.c */\r\n\r\n#include \"7zMethodID.h\"\r\n\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2)\r\n{\r\n  int i;\r\n  if (a1->IDSize != a2->IDSize)\r\n    return 0;\r\n  for (i = 0; i < a1->IDSize; i++)\r\n    if (a1->ID[i] != a2->ID[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zMethodID.h",
    "content": "/* 7zMethodID.h */\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"7zTypes.h\"\r\n\r\n#define kMethodIDSize 15\r\n  \r\ntypedef struct _CMethodID\r\n{\r\n  Byte ID[kMethodIDSize];\r\n  Byte IDSize;\r\n} CMethodID;\r\n\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7zTypes.h",
    "content": "/* 7zTypes.h */\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif \r\n\r\n/* #define _SZ_NO_INT_64 */\r\n/* define it your compiler doesn't support long long int */\r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\n#ifdef _SZ_NO_INT_64\r\ntypedef unsigned long UInt64;\r\n#else\r\n#ifdef _MSC_VER\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n#endif\r\n#endif\r\n\r\n\r\n/* #define _SZ_FILE_SIZE_64 */\r\n/* Use _SZ_FILE_SIZE_64 if you need support for files larger than 4 GB*/\r\n\r\n#ifndef CFileSize\r\n#ifdef _SZ_FILE_SIZE_64\r\ntypedef UInt64 CFileSize; \r\n#else\r\ntypedef UInt32 CFileSize; \r\n#endif\r\n#endif\r\n\r\n#define SZ_RESULT int\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_CRC_ERROR (3)\r\n\r\n#define SZE_NOTIMPL (4)\r\n#define SZE_FAIL (5)\r\n\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7z_C.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z_C\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z_C - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\" CFG=\"7z_C - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z_C - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z_C - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z_C - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /W4 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z_C - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z_C - Win32 Release\"\r\n# Name \"7z_C - Win32 Debug\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_C\\LzmaDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_C\\LzmaDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_C\\LzmaTypes.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zTypes.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/7z_C.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z_C\"=.\\7z_C.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/makefile",
    "content": "PROG = 7zDec.exe\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zBuffer.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n  $O\\7zMethodID.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $O\\LzmaDecode.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/LZMA_C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Archive/7z_C/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o \r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuffer.o: 7zBuffer.c\r\n\t$(CXX) $(CFLAGS) 7zBuffer.c\r\n\r\n7zCrc.o: 7zCrc.c\r\n\t$(CXX) $(CFLAGS) 7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\n7zMethodID.o: 7zMethodID.c\r\n\t$(CXX) $(CFLAGS) 7zMethodID.c\r\n\r\nLzmaDecode.o: ../../Compress/LZMA_C/LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/LZMA_C/LzmaDecode.c\r\n\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  // return result ? S_OK: E_FAIL;\r\n  #ifdef _WIN32\r\n  return result ? S_OK: (::GetLastError());\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), \r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef _WIN32\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nbool COutFileStream::Create(LPCTSTR fileName, bool createAlways)\r\n{\r\n  return File.Create(fileName, createAlways);\r\n}\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool COutFileStream::Create(LPCWSTR fileName, bool createAlways)\r\n{\r\n  return File.Create(fileName, createAlways);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef _WIN32\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15); \r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), \r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef _WIN32\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef _WIN32\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n  #endif\r\n  \r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\n#include \"../../Common/Alloc.h\"\r\n\r\nCInBuffer::CInBuffer(): \r\n  _buffer(0), \r\n  _bufferLimit(0), \r\n  _bufferBase(0), \r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nclass CInBufferException\r\n{\r\npublic:\r\n  HRESULT ErrorCode;\r\n  CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      if(!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)\r\n  {\r\n    for(processedSize = 0; processedSize < size; processedSize++)\r\n      if (!ReadByte(((Byte *)data)[processedSize]))\r\n        return;\r\n  }\r\n  bool ReadBytes(void *data, UInt32 size)\r\n  {\r\n    UInt32 processedSize;\r\n    ReadBytes(data, size, processedSize);\r\n    return (processedSize == size);\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\n#include \"../../Common/Alloc.h\"\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{ \r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos) \r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode == S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = FlushPart();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException\r\n{\r\n  HRESULT ErrorCode;\r\n  COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\n  void FlushWithCheck();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Read(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (Byte *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Write(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      break;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/ARM.cpp",
    "content": "// ARM.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARM.h\"\r\n\r\n#include \"BranchARM.c\"\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/ARM.h",
    "content": "// ARM.h\r\n\r\n#ifndef __ARM_H\r\n#define __ARM_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM, 0x05, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/ARMThumb.cpp",
    "content": "// ARMThumb.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARMThumb.h\"\r\n\r\n#include \"BranchARMThumb.c\"\r\n\r\nUInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/ARMThumb.h",
    "content": "// ARMThumb.h\r\n\r\n#ifndef __ARMTHUMB_H\r\n#define __ARMTHUMB_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARMThumb, 0x07, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchARM.c",
    "content": "/* BranchARM.c */\r\n\r\n#include \"BranchARM.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 src = (data[i + 2] << 16) | (data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + 8 + src;\r\n      else\r\n        dest = src - (nowPos + i + 8);\r\n      dest >>= 2;\r\n      data[i + 2] = (dest >> 16);\r\n      data[i + 1] = (dest >> 8);\r\n      data[i + 0] = dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchARM.h",
    "content": "// BranchARM.h\r\n\r\n#ifndef __BRANCH_ARM_H\r\n#define __BRANCH_ARM_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchARMThumb.c",
    "content": "/* BranchARMThumb.c */\r\n\r\n#include \"BranchARMThumb.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 && \r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 src = \r\n        ((data[i + 1] & 0x7) << 19) |\r\n        (data[i + 0] << 11) |\r\n        ((data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + 4 + src;\r\n      else\r\n        dest = src - (nowPos + i + 4);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = 0xF0 | ((dest >> 19) & 0x7);\r\n      data[i + 0] = (dest >> 11);\r\n      data[i + 3] = 0xF8 | ((dest >> 8) & 0x7);\r\n      data[i + 2] = (dest);\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchARMThumb.h",
    "content": "// BranchARMThumb.h\r\n\r\n#ifndef __BRANCH_ARM_THUMB_H\r\n#define __BRANCH_ARM_THUMB_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __BRANCH_CODER_H\r\n#define __BRANCH_CODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/Types.h\"\r\n#include \"Common/Alloc.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClass2b(Name, id, subId, encodingId)  \\\r\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\r\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00); \r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchIA64.c",
    "content": "/* BranchIA64.c */\r\n\r\n#include \"BranchIA64.h\"\r\n\r\nconst Byte kBranchTable[32] = \r\n{ \r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0 \r\n};\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 16 <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    for (int slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      UInt32 bytePos = (bitPos >> 3);\r\n      UInt32 bitRes = bitPos & 0x7;\r\n      UInt64 instruction = 0;\r\n      int j;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);\r\n\r\n      UInt64 instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 \r\n        &&  ((instNorm >> 9) & 0x7) == 0 \r\n        /* &&  (instNorm & 0x3F)== 0 */\r\n        )\r\n      {\r\n        UInt32 src = UInt32((instNorm >> 13) & 0xFFFFF);\r\n        src |= ((instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        UInt32 dest;\r\n        if (encoding)\r\n          dest = nowPos + i + src;\r\n        else\r\n          dest = src - (nowPos + i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~(UInt64(0x8FFFFF) << 13);\r\n        instNorm |= (UInt64(dest & 0xFFFFF) << 13);\r\n        instNorm |= (UInt64(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = Byte(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchIA64.h",
    "content": "// BranchIA64.h\r\n\r\n#ifndef __BRANCH_IA64_H\r\n#define __BRANCH_IA64_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchPPC.c",
    "content": "/* BranchPPC.c */\r\n\r\n#include \"BranchPPC.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    /* PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) */\r\n    if ((data[i] >> 2) == 0x12 && \r\n    (\r\n      (data[i + 3] & 3) == 1 \r\n      /* || (data[i+3] & 3) == 3 */\r\n      )\r\n    )\r\n    {\r\n      UInt32 src = ((data[i + 0] & 3) << 24) |\r\n        (data[i + 1] << 16) |\r\n        (data[i + 2] << 8) |\r\n        (data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      data[i + 0] = 0x48 | ((dest >> 24) &  0x3);\r\n      data[i + 1] = (dest >> 16);\r\n      data[i + 2] = (dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchPPC.h",
    "content": "// BranchPPC.h\r\n\r\n#ifndef __BRANCH_PPC_H\r\n#define __BRANCH_PPC_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchSPARC.c",
    "content": "/* BranchSPARC.c */\r\n\r\n#include \"BranchSPARC.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || \r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      \r\n      src <<= 2;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchSPARC.h",
    "content": "// BranchSPARC.h\r\n\r\n#ifndef __BRANCH_SPARC_H\r\n#define __BRANCH_SPARC_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 SPARC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchTypes.h",
    "content": "/* BranchTypes.h */\r\n\r\n#ifndef __BRANCHTYPES_H\r\n#define __BRANCHTYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchX86.c",
    "content": "/* BranchX86.c */\r\n\r\n#include \"BranchX86.h\"\r\n\r\n/*\r\nstatic int inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n*/\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst int kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\n/*\r\nvoid x86_Convert_Init(UInt32 *prevMask, UInt32 *prevPos)\r\n{\r\n  *prevMask = 0;\r\n  *prevPos = (UInt32)(-5);\r\n}\r\n*/\r\n\r\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \r\n    UInt32 *prevMask, UInt32 *prevPos, int encoding)\r\n{\r\n  UInt32 bufferPos = 0;\r\n  UInt32 limit;\r\n\r\n  if (endPos < 5)\r\n    return 0;\r\n  \r\n  if (nowPos - *prevPos > 5)\r\n    *prevPos = nowPos - 5;\r\n  \r\n  limit = endPos - 5;\r\n  while(bufferPos <= limit)\r\n  {\r\n    Byte b = buffer[bufferPos];\r\n    UInt32 offset;\r\n    if (b != 0xE8 && b != 0xE9)\r\n    {\r\n      bufferPos++;\r\n      continue;\r\n    }\r\n    offset = (nowPos + bufferPos - *prevPos);\r\n    *prevPos = (nowPos + bufferPos);\r\n    if (offset > 5)\r\n      *prevMask = 0;\r\n    else\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < offset; i++)\r\n      {\r\n        *prevMask &= 0x77;\r\n        *prevMask <<= 1;\r\n      }\r\n    }\r\n    b = buffer[bufferPos + 4];\r\n    if (Test86MSByte(b) && kMaskToAllowedStatus[(*prevMask >> 1) & 0x7] && \r\n      (*prevMask >> 1) < 0x10)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)(b) << 24) |\r\n        ((UInt32)(buffer[bufferPos + 3]) << 16) |\r\n        ((UInt32)(buffer[bufferPos + 2]) << 8) |\r\n        (buffer[bufferPos + 1]);\r\n      \r\n      UInt32 dest;\r\n      while(1)\r\n      {\r\n        UInt32 index;\r\n        if (encoding)\r\n          dest = (nowPos + bufferPos + 5) + src;\r\n        else\r\n          dest = src - (nowPos + bufferPos + 5);\r\n        if (*prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[*prevMask >> 1];\r\n        b = (Byte)(dest >> (24 - index * 8));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index * 8)) - 1);\r\n      }\r\n      buffer[bufferPos + 4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      buffer[bufferPos + 3] = (Byte)(dest >> 16);\r\n      buffer[bufferPos + 2] = (Byte)(dest >> 8);\r\n      buffer[bufferPos + 1] = (Byte)dest;\r\n      bufferPos += 5;\r\n      *prevMask = 0;\r\n    }\r\n    else\r\n    {\r\n      bufferPos++;\r\n      *prevMask |= 1;\r\n      if (Test86MSByte(b))\r\n        *prevMask |= 0x10;\r\n    }\r\n  }\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/BranchX86.h",
    "content": "/* BranchX86.h */\r\n\r\n#ifndef __BRANCHX86_H\r\n#define __BRANCHX86_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\n#define x86_Convert_Init(prevMask, prevPos) { prevMask = 0; prevPos = (UInt32)(-5); }\r\n\r\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \r\n    UInt32 *prevMask, UInt32 *prevPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/IA64.cpp",
    "content": "// IA64.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"IA64.h\"\r\n\r\n#include \"BranchIA64.c\"\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/IA64.h",
    "content": "// IA64.h\r\n\r\n#ifndef __IA64_H\r\n#define __IA64_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_IA64, 0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/PPC.cpp",
    "content": "// PPC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"PPC.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"BranchPPC.c\"\r\n\r\nUInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/PPC.h",
    "content": "// PPC.h\r\n\r\n#ifndef __PPC_H\r\n#define __PPC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_PPC_B, 0x02, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/SPARC.cpp",
    "content": "// SPARC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"SPARC.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"BranchSPARC.c\"\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/SPARC.h",
    "content": "// SPARC.h\r\n\r\n#ifndef __SPARC_H\r\n#define __SPARC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_SPARC, 0x08, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/x86.cpp",
    "content": "// x86.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"BranchX86.c\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/x86.h",
    "content": "// x86.h\r\n\r\n#ifndef __X86_H\r\n#define __X86_H\r\n\r\n#include \"BranchCoder.h\"\r\n#include \"BranchX86.h\"\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  UInt32 _prevPos;\r\n  void x86Init() { x86_Convert_Init(_prevMask, _prevPos); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 , \r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/x86_2.cpp",
    "content": "// x86_2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86_2.h\"\r\n\r\n#include \"../../../Common/Alloc.h\"\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\ninline bool IsJcc(Byte b0, Byte b1)\r\n{\r\n  return (b0 == 0x0F && (b1 & 0xF0) == 0x80);\r\n}\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CBCJ2_x86_Encoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCBCJ2_x86_Encoder::~CBCJ2_x86_Encoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CBCJ2_x86_Encoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256; i++)\r\n    _statusE8Encoder[i].Init();\r\n  _statusE9Encoder.Init();\r\n  _statusJccEncoder.Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  while(true)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    while(true)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it \r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\r\n        else if (IsJcc(prevByte, b))\r\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src = \r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;          \r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;          \r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      if (convert)\r\n      {\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 1);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 1);\r\n        else \r\n          _statusJccEncoder.Encode(&_rangeEncoder, 1);\r\n\r\n        bufferPos += 5;\r\n        if (b == 0xE8)\r\n        {\r\n          _callStream.WriteByte((Byte)(dest >> 24));\r\n          _callStream.WriteByte((Byte)(dest >> 16));\r\n          _callStream.WriteByte((Byte)(dest >> 8));\r\n          _callStream.WriteByte((Byte)(dest));\r\n        }\r\n        else \r\n        {\r\n          _jumpStream.WriteByte((Byte)(dest >> 24));\r\n          _jumpStream.WriteByte((Byte)(dest >> 16));\r\n          _jumpStream.WriteByte((Byte)(dest >> 8));\r\n          _jumpStream.WriteByte((Byte)(dest));\r\n        }\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\r\n        else\r\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256; i++)\r\n    _statusE8Decoder[i].Init();\r\n  _statusE9Decoder.Init();\r\n  _statusJccDecoder.Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  while(true)\r\n  {\r\n    if (processedBytes > (1 << 20) && progress != NULL)\r\n    {\r\n      UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    processedBytes++;\r\n    Byte b;\r\n    if (!_mainInStream.ReadByte(b))\r\n      return Flush();\r\n    _outStream.WriteByte(b);\r\n    if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\r\n    {\r\n      prevByte = b;\r\n      continue;\r\n    }\r\n    bool status;\r\n    if (b == 0xE8)\r\n      status = (_statusE8Decoder[prevByte].Decode(&_rangeDecoder) == 1);\r\n    else if (b == 0xE9)\r\n      status = (_statusE9Decoder.Decode(&_rangeDecoder) == 1);\r\n    else\r\n      status = (_statusJccDecoder.Decode(&_rangeDecoder) == 1);\r\n    if (status)\r\n    {\r\n      UInt32 src;\r\n      if (b == 0xE8)\r\n      {\r\n        Byte b0;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src = ((UInt32)b0) << 24;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 16;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 8;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      else\r\n      {\r\n        Byte b0;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src = ((UInt32)b0) << 24;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 16;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 8;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CBCJ2_x86_Decoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/Branch/x86_2.h",
    "content": "// x86_2.h\r\n\r\n#ifndef __BRANCH_X86_2_H\r\n#define __BRANCH_X86_2_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../RangeCoder/RangeCoderBit.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n// {23170F69-40C1-278B-0303-010100000100}\r\n#define MyClass2_a(Name, id, subId, encodingId)  \\\r\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\r\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00);\r\n\r\n#define MyClass_a(Name, id, subId)  \\\r\nMyClass2_a(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClass2_a(Name ## _Decoder, id, subId, 0x00) \r\n\r\nMyClass_a(BCJ2_x86, 0x01, 0x1B)\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CBCJ2_x86_Encoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CBCJ2_x86_Encoder(): _buffer(0) {};\r\n  ~CBCJ2_x86_Encoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE8Encoder[256];\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE9Encoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusJccEncoder;\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CBCJ2_x86_Encoder *_coder;\r\n  public:\r\n    CCoderReleaser(CBCJ2_x86_Encoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n\r\nclass CBCJ2_x86_Decoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{ \r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE8Decoder[256];\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE9Decoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusJccDecoder;\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CBCJ2_x86_Decoder *_coder;\r\n  public:\r\n    CCoderReleaser(CBCJ2_x86_Decoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/BinTree/BinTree.h",
    "content": "// BinTree.h\r\n\r\n#include \"../LZInWindow.h\"\r\n#include \"../IMatchFinder.h\"\r\n \r\nnamespace BT_NAMESPACE {\r\n\r\ntypedef UInt32 CIndex;\r\nconst UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\r\n\r\nclass CMatchFinder: \r\n  public IMatchFinder,\r\n  public CLZInWindow,\r\n  public CMyUnknownImp,\r\n  public IMatchFinderSetNumPasses\r\n{\r\n  UInt32 _cyclicBufferPos;\r\n  UInt32 _cyclicBufferSize; // it must be historySize + 1\r\n  UInt32 _matchMaxLen;\r\n  CIndex *_hash;\r\n  CIndex *_son;\r\n  UInt32 _hashMask;\r\n  UInt32 _cutValue;\r\n  UInt32 _hashSizeSum;\r\n\r\n  void Normalize();\r\n  void FreeThisClassMemory();\r\n  void FreeMemory();\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetStream)(ISequentialInStream *inStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(Init)();\r\n  HRESULT MovePos();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n  STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes);\r\n  STDMETHOD_(void, ChangeBufferPos)();\r\n\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n  STDMETHOD(GetMatches)(UInt32 *distances);\r\n  STDMETHOD(Skip)(UInt32 num);\r\n\r\npublic:\r\n  CMatchFinder();\r\n  virtual ~CMatchFinder();\r\n  virtual void SetNumPasses(UInt32 numPasses) { _cutValue = numPasses; }\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/BinTree/BinTree2.h",
    "content": "// BinTree2.h\r\n\r\n#ifndef __BINTREE2_H\r\n#define __BINTREE2_H\r\n\r\n#define BT_NAMESPACE NBT2\r\n\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef BT_NAMESPACE\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/BinTree/BinTree3.h",
    "content": "// BinTree3.h\r\n\r\n#ifndef __BINTREE3_H\r\n#define __BINTREE3_H\r\n\r\n#define BT_NAMESPACE NBT3\r\n\r\n#define HASH_ARRAY_2\r\n\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n\r\n#undef BT_NAMESPACE\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/BinTree/BinTree3Z.h",
    "content": "// BinTree3Z.h\r\n\r\n#ifndef __BINTREE3Z_H\r\n#define __BINTREE3Z_H\r\n\r\n#define BT_NAMESPACE NBT3Z\r\n\r\n#define HASH_ZIP\r\n\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ZIP\r\n\r\n#undef BT_NAMESPACE\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/BinTree/BinTree4.h",
    "content": "// BinTree4.h\r\n\r\n#ifndef __BINTREE4_H\r\n#define __BINTREE4_H\r\n\r\n#define BT_NAMESPACE NBT4\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n\r\n#undef BT_NAMESPACE\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/BinTree/BinTreeMain.h",
    "content": "// BinTreeMain.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/CRC.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\n#include \"BinTree.h\"\r\n\r\n// #include <xmmintrin.h>\r\n// It's for prefetch\r\n// But prefetch doesn't give big gain in K8.\r\n\r\nnamespace BT_NAMESPACE {\r\n\r\n#ifdef HASH_ARRAY_2\r\n  static const UInt32 kHash2Size = 1 << 10;\r\n  #define kNumHashDirectBytes 0\r\n  #ifdef HASH_ARRAY_3\r\n    static const UInt32 kNumHashBytes = 4;\r\n    static const UInt32 kHash3Size = 1 << 16;\r\n  #else\r\n    static const UInt32 kNumHashBytes = 3;\r\n  #endif\r\n  static const UInt32 kHashSize = 0;\r\n  static const UInt32 kMinMatchCheck = kNumHashBytes;\r\n  static const UInt32 kStartMaxLen = 1;\r\n#else\r\n  #ifdef HASH_ZIP \r\n    #define kNumHashDirectBytes 0\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << 16;\r\n    static const UInt32 kMinMatchCheck = kNumHashBytes;\r\n    static const UInt32 kStartMaxLen = 1;\r\n  #else\r\n    #define kNumHashDirectBytes 2\r\n    static const UInt32 kNumHashBytes = 2;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n    static const UInt32 kMinMatchCheck = kNumHashBytes + 1;\r\n    static const UInt32 kStartMaxLen = 1;\r\n  #endif\r\n#endif\r\n\r\n#ifdef HASH_ARRAY_2\r\n#ifdef HASH_ARRAY_3\r\nstatic const UInt32 kHash3Offset = kHash2Size;\r\n#endif\r\n#endif\r\n\r\nstatic const UInt32 kFixHashSize = 0\r\n    #ifdef HASH_ARRAY_2\r\n    + kHash2Size\r\n    #ifdef HASH_ARRAY_3\r\n    + kHash3Size\r\n    #endif\r\n    #endif\r\n    ;\r\n\r\nCMatchFinder::CMatchFinder():\r\n  _hash(0)\r\n{\r\n}\r\n\r\nvoid CMatchFinder::FreeThisClassMemory()\r\n{\r\n  BigFree(_hash);\r\n  _hash = 0;\r\n}\r\n\r\nvoid CMatchFinder::FreeMemory()\r\n{\r\n  FreeThisClassMemory();\r\n  CLZInWindow::Free();\r\n}\r\n\r\nCMatchFinder::~CMatchFinder()\r\n{ \r\n  FreeMemory();\r\n}\r\n\r\nSTDMETHODIMP CMatchFinder::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  if (historySize > kMaxValForNormalize - 256)\r\n  {\r\n    FreeMemory();\r\n    return E_INVALIDARG;\r\n  }\r\n  _cutValue = \r\n  #ifdef _HASH_CHAIN\r\n    8 + (matchMaxLen >> 2);\r\n  #else\r\n    16 + (matchMaxLen >> 1);\r\n  #endif\r\n  UInt32 sizeReserv = (historySize + keepAddBufferBefore + \r\n      matchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n  if (CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, sizeReserv))\r\n  {\r\n    _matchMaxLen = matchMaxLen;\r\n    UInt32 newCyclicBufferSize = historySize + 1;\r\n    if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)\r\n      return S_OK;\r\n    FreeThisClassMemory();\r\n    _cyclicBufferSize = newCyclicBufferSize; // don't change it\r\n\r\n    UInt32 hs = kHashSize;\r\n\r\n    #ifdef HASH_ARRAY_2\r\n    hs = historySize - 1;\r\n    hs |= (hs >> 1);\r\n    hs |= (hs >> 2);\r\n    hs |= (hs >> 4);\r\n    hs |= (hs >> 8);\r\n    hs >>= 1;\r\n    hs |= 0xFFFF;\r\n    if (hs > (1 << 24))\r\n    {\r\n      #ifdef HASH_ARRAY_3\r\n      hs >>= 1;\r\n      #else\r\n      hs = (1 << 24) - 1;\r\n      #endif\r\n    }\r\n    _hashMask = hs;\r\n    hs++;\r\n    #endif\r\n    _hashSizeSum = hs + kFixHashSize;\r\n    UInt32 numItems = _hashSizeSum + _cyclicBufferSize\r\n    #ifndef _HASH_CHAIN\r\n     * 2\r\n    #endif\r\n    ;\r\n    size_t sizeInBytes = (size_t)numItems * sizeof(CIndex);\r\n    if (sizeInBytes / sizeof(CIndex) != numItems)\r\n      return E_OUTOFMEMORY;\r\n    _hash = (CIndex *)BigAlloc(sizeInBytes);\r\n    _son = _hash + _hashSizeSum;\r\n    if (_hash != 0)\r\n      return S_OK;\r\n  }\r\n  FreeMemory();\r\n  return E_OUTOFMEMORY;\r\n}\r\n\r\nstatic const UInt32 kEmptyHashValue = 0;\r\n\r\nSTDMETHODIMP CMatchFinder::SetStream(ISequentialInStream *stream)\r\n{\r\n  CLZInWindow::SetStream(stream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CMatchFinder::Init()\r\n{\r\n  RINOK(CLZInWindow::Init());\r\n  for(UInt32 i = 0; i < _hashSizeSum; i++)\r\n    _hash[i] = kEmptyHashValue;\r\n  _cyclicBufferPos = 0;\r\n  ReduceOffsets(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinder::ReleaseStream()\r\n{ \r\n  // ReleaseStream(); \r\n}\r\n\r\n#ifdef HASH_ARRAY_2\r\n#ifdef HASH_ARRAY_3\r\n\r\n#define HASH_CALC { \\\r\n  UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ (UInt32(cur[2]) << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ (UInt32(cur[2]) << 8) ^ (CCRC::Table[cur[3]] << 5)) & _hashMask; }\r\n  \r\n#else // no HASH_ARRAY_3\r\n#define HASH_CALC { \\\r\n  UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ (UInt32(cur[2]) << 8)) & _hashMask; }\r\n#endif // HASH_ARRAY_3\r\n#else // no HASH_ARRAY_2\r\n#ifdef HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return ((UInt32(pointer[0]) << 8) ^ CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\r\n}\r\n#else // no HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return pointer[0] ^ (UInt32(pointer[1]) << 8);\r\n}\r\n#endif // HASH_ZIP\r\n#endif // HASH_ARRAY_2\r\n\r\nSTDMETHODIMP CMatchFinder::GetMatches(UInt32 *distances)\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kMinMatchCheck)\r\n    {\r\n      distances[0] = 0;\r\n      return MovePos(); \r\n    }\r\n  }\r\n\r\n  int offset = 1;\r\n\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  const Byte *cur = _buffer + _pos;\r\n\r\n  UInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  #endif\r\n  UInt32 hashValue;\r\n  HASH_CALC;\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 curMatch2 = _hash[hash2Value];\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n  #endif\r\n  _hash[hash2Value] = _pos;\r\n  if(curMatch2 > matchMinPos)\r\n    if (_buffer[curMatch2] == cur[0])\r\n    {\r\n      distances[offset++] = maxLen = 2;\r\n      distances[offset++] = _pos - curMatch2 - 1;\r\n    }\r\n\r\n  #ifdef HASH_ARRAY_3\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  if(curMatch3 > matchMinPos)\r\n    if (_buffer[curMatch3] == cur[0])\r\n    {\r\n      if (curMatch3 == curMatch2)\r\n        offset -= 2;\r\n      distances[offset++] = maxLen = 3;\r\n      distances[offset++] = _pos - curMatch3 - 1;\r\n      curMatch2 = curMatch3;\r\n    }\r\n  #endif\r\n  if (offset != 1 && curMatch2 == curMatch)\r\n  {\r\n    offset -= 2;\r\n    maxLen = kStartMaxLen;\r\n  }\r\n  #endif\r\n\r\n  _hash[kFixHashSize + hashValue] = _pos;\r\n\r\n  CIndex *son = _son;\r\n\r\n  #ifdef _HASH_CHAIN\r\n  son[_cyclicBufferPos] = curMatch;\r\n  #else\r\n  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r\n\r\n  UInt32 len0, len1;\r\n  len0 = len1 = kNumHashDirectBytes;\r\n  #endif\r\n\r\n  #if kNumHashDirectBytes != 0\r\n  if(curMatch > matchMinPos)\r\n  {\r\n    if (_buffer[curMatch + kNumHashDirectBytes] != cur[kNumHashDirectBytes])\r\n    {\r\n      distances[offset++] = maxLen = kNumHashDirectBytes;\r\n      distances[offset++] = _pos - curMatch - 1;\r\n    }\r\n  }\r\n  #endif\r\n  UInt32 count = _cutValue;\r\n  while(true)\r\n  {\r\n    if(curMatch <= matchMinPos || count-- == 0)\r\n    {\r\n      #ifndef _HASH_CHAIN\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      #endif\r\n      break;\r\n    }\r\n    UInt32 delta = _pos - curMatch;\r\n    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n        (_cyclicBufferPos - delta):\r\n        (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n    CIndex *pair = son + \r\n    #ifdef _HASH_CHAIN\r\n      cyclicPos;\r\n    #else\r\n      (cyclicPos << 1);\r\n    #endif\r\n    \r\n    // _mm_prefetch((const char *)pair, _MM_HINT_T0);\r\n    \r\n    const Byte *pb = _buffer + curMatch;\r\n    UInt32 len = \r\n    #ifdef _HASH_CHAIN\r\n    kNumHashDirectBytes;\r\n    if (pb[maxLen] == cur[maxLen])\r\n    #else\r\n    MyMin(len0, len1);\r\n    #endif\r\n    if (pb[len] == cur[len])\r\n    {\r\n      while(++len != lenLimit)\r\n        if (pb[len] != cur[len])\r\n          break;\r\n      if (maxLen < len)\r\n      {\r\n        distances[offset++] = maxLen = len;\r\n        distances[offset++] = delta - 1;\r\n        if (len == lenLimit)\r\n        {\r\n          #ifndef _HASH_CHAIN\r\n          *ptr1 = pair[0];\r\n          *ptr0 = pair[1];\r\n          #endif\r\n          break;\r\n        }\r\n      }\r\n    }\r\n    #ifdef _HASH_CHAIN\r\n    curMatch = *pair;\r\n    #else\r\n    if (pb[len] < cur[len])\r\n    {\r\n      *ptr1 = curMatch;\r\n      ptr1 = pair + 1;\r\n      curMatch = *ptr1;\r\n      len1 = len;\r\n    }\r\n    else\r\n    {\r\n      *ptr0 = curMatch;\r\n      ptr0 = pair;\r\n      curMatch = *ptr0;\r\n      len0 = len;\r\n    }\r\n    #endif\r\n  }\r\n  distances[0] = offset - 1;\r\n  if (++_cyclicBufferPos == _cyclicBufferSize)\r\n    _cyclicBufferPos = 0;\r\n  RINOK(CLZInWindow::MovePos());\r\n  if (_pos == kMaxValForNormalize)\r\n    Normalize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CMatchFinder::Skip(UInt32 num)\r\n{\r\n  do\r\n  {\r\n  #ifdef _HASH_CHAIN\r\n  if (_streamPos - _pos < kNumHashBytes)\r\n  {\r\n    RINOK(MovePos()); \r\n    continue;\r\n  }\r\n  #else\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kMinMatchCheck)\r\n    {\r\n      RINOK(MovePos());\r\n      continue;\r\n    }\r\n  }\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  #endif\r\n  const Byte *cur = _buffer + _pos;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue;\r\n  HASH_CALC;\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  #else\r\n  UInt32 hashValue;\r\n  HASH_CALC;\r\n  #endif\r\n  _hash[hash2Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n  _hash[kFixHashSize + hashValue] = _pos;\r\n\r\n  #ifdef _HASH_CHAIN\r\n  _son[_cyclicBufferPos] = curMatch;\r\n  #else\r\n  CIndex *son = _son;\r\n  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r\n\r\n  UInt32 len0, len1;\r\n  len0 = len1 = kNumHashDirectBytes;\r\n  UInt32 count = _cutValue;\r\n  while(true)\r\n  {\r\n    if(curMatch <= matchMinPos || count-- == 0)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      break;\r\n    }\r\n    \r\n    UInt32 delta = _pos - curMatch;\r\n    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n      (_cyclicBufferPos - delta):\r\n      (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n    CIndex *pair = son + (cyclicPos << 1);\r\n    \r\n    // _mm_prefetch((const char *)pair, _MM_HINT_T0);\r\n    \r\n    const Byte *pb = _buffer + curMatch;\r\n    UInt32 len = MyMin(len0, len1);\r\n    \r\n    if (pb[len] == cur[len])\r\n    {\r\n      while(++len != lenLimit)\r\n        if (pb[len] != cur[len])\r\n          break;\r\n      if (len == lenLimit)\r\n      {\r\n        *ptr1 = pair[0];\r\n        *ptr0 = pair[1];\r\n        break;\r\n      }\r\n    }\r\n    if (pb[len] < cur[len])\r\n    {\r\n      *ptr1 = curMatch;\r\n      ptr1 = pair + 1;\r\n      curMatch = *ptr1;\r\n      len1 = len;\r\n    }\r\n    else\r\n    {\r\n      *ptr0 = curMatch;\r\n      ptr0 = pair;\r\n      curMatch = *ptr0;\r\n      len0 = len;\r\n    }\r\n  }\r\n  #endif\r\n  if (++_cyclicBufferPos == _cyclicBufferSize)\r\n    _cyclicBufferPos = 0;\r\n  RINOK(CLZInWindow::MovePos());\r\n  if (_pos == kMaxValForNormalize)\r\n    Normalize();\r\n  }\r\n  while(--num != 0);\r\n  return S_OK;\r\n}\r\n\r\nvoid CMatchFinder::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _cyclicBufferSize;\r\n  CIndex *items = _hash;\r\n  UInt32 numItems = (_hashSizeSum + _cyclicBufferSize \r\n    #ifndef _HASH_CHAIN\r\n     * 2\r\n    #endif\r\n    );\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n  ReduceOffsets(subValue);\r\n}\r\n\r\nHRESULT CMatchFinder::MovePos()\r\n{\r\n  if (++_cyclicBufferPos == _cyclicBufferSize)\r\n    _cyclicBufferPos = 0;\r\n  RINOK(CLZInWindow::MovePos());\r\n  if (_pos == kMaxValForNormalize)\r\n    Normalize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(Byte) CMatchFinder::GetIndexByte(Int32 index)\r\n  { return CLZInWindow::GetIndexByte(index); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinder::GetMatchLen(Int32 index, \r\n    UInt32 back, UInt32 limit)\r\n  { return CLZInWindow::GetMatchLen(index, back, limit); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinder::GetNumAvailableBytes()\r\n  { return CLZInWindow::GetNumAvailableBytes(); }\r\n\r\nSTDMETHODIMP_(const Byte *) CMatchFinder::GetPointerToCurrentPos()\r\n  { return CLZInWindow::GetPointerToCurrentPos(); }\r\n\r\nSTDMETHODIMP_(Int32) CMatchFinder::NeedChangeBufferPos(UInt32 numCheckBytes)\r\n  { return CLZInWindow::NeedMove(numCheckBytes) ? 1: 0; }\r\n\r\nSTDMETHODIMP_(void) CMatchFinder::ChangeBufferPos()\r\n  { CLZInWindow::MoveBlock();}\r\n\r\n#undef HASH_CALC\r\n#undef kNumHashDirectBytes\r\n \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/HashChain/HC2.h",
    "content": "// HC2.h\r\n\r\n#ifndef __HC2_H\r\n#define __HC2_H\r\n\r\n#define BT_NAMESPACE NHC2\r\n\r\n#include \"HCMain.h\"\r\n\r\n#undef BT_NAMESPACE\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/HashChain/HC3.h",
    "content": "// HC3.h\r\n\r\n#ifndef __HC3_H\r\n#define __HC3_H\r\n\r\n#define BT_NAMESPACE NHC3\r\n\r\n#define HASH_ARRAY_2\r\n\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef BT_NAMESPACE\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/HashChain/HC4.h",
    "content": "// HC4.h\r\n\r\n#ifndef __HC4_H\r\n#define __HC4_H\r\n\r\n#define BT_NAMESPACE NHC4\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n\r\n#undef BT_NAMESPACE\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/HashChain/HCMain.h",
    "content": "// HCMain.h\r\n\r\n#define _HASH_CHAIN\r\n#include \"../BinTree/BinTreeMain.h\"\r\n#undef _HASH_CHAIN\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/IMatchFinder.h",
    "content": "// MatchFinders/IMatchFinder.h\r\n\r\n#ifndef __IMATCHFINDER_H\r\n#define __IMATCHFINDER_H\r\n\r\nstruct IInWindowStream: public IUnknown\r\n{\r\n  STDMETHOD(SetStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD_(void, ReleaseStream)() PURE;\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;\r\n  STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes) PURE;\r\n  STDMETHOD_(void, ChangeBufferPos)() PURE;\r\n};\r\n \r\nstruct IMatchFinder: public IInWindowStream\r\n{\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;\r\n  STDMETHOD(GetMatches)(UInt32 *distances) PURE;\r\n  STDMETHOD(Skip)(UInt32 num) PURE;\r\n};\r\n\r\nstruct IMatchFinderSetNumPasses\r\n{\r\n  virtual void SetNumPasses(UInt32 numPasses) PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/LZInWindow.cpp",
    "content": "// LZInWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZInWindow.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n\r\nvoid CLZInWindow::Free()\r\n{\r\n  ::BigFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nbool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n{\r\n  _keepSizeBefore = keepSizeBefore;\r\n  _keepSizeAfter = keepSizeAfter;\r\n  UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n  if (_bufferBase == 0 || _blockSize != blockSize)\r\n  {\r\n    Free();\r\n    _blockSize = blockSize;\r\n    if (_blockSize != 0)\r\n      _bufferBase = (Byte *)::BigAlloc(_blockSize);\r\n  }\r\n  _pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;\r\n  if (_blockSize == 0)\r\n    return true;\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CLZInWindow::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nHRESULT CLZInWindow::Init()\r\n{\r\n  _buffer = _bufferBase;\r\n  _pos = 0;\r\n  _streamPos = 0;\r\n  _streamEndWasReached = false;\r\n  return ReadBlock();\r\n}\r\n\r\n/*\r\nvoid CLZInWindow::ReleaseStream()\r\n{\r\n  _stream.Release();\r\n}\r\n*/\r\n\r\n///////////////////////////////////////////\r\n// ReadBlock\r\n\r\n// In State:\r\n//   (_buffer + _streamPos) <= (_bufferBase + _blockSize)\r\n// Out State:\r\n//   _posLimit <= _blockSize - _keepSizeAfter;\r\n//   if(_streamEndWasReached == false):\r\n//     _streamPos >= _pos + _keepSizeAfter\r\n//     _posLimit = _streamPos - _keepSizeAfter;\r\n//   else\r\n//          \r\n  \r\nHRESULT CLZInWindow::ReadBlock()\r\n{\r\n  if(_streamEndWasReached)\r\n    return S_OK;\r\n  while(true)\r\n  {\r\n    UInt32 size = (UInt32)(_bufferBase - _buffer) + _blockSize - _streamPos;\r\n    if(size == 0)\r\n      return S_OK;\r\n    UInt32 numReadBytes;\r\n    RINOK(_stream->Read(_buffer + _streamPos, size, &numReadBytes));\r\n    if(numReadBytes == 0)\r\n    {\r\n      _posLimit = _streamPos;\r\n      const Byte *pointerToPostion = _buffer + _posLimit;\r\n      if(pointerToPostion > _pointerToLastSafePosition)\r\n        _posLimit = (UInt32)(_pointerToLastSafePosition - _buffer);\r\n      _streamEndWasReached = true;\r\n      return S_OK;\r\n    }\r\n    _streamPos += numReadBytes;\r\n    if(_streamPos >= _pos + _keepSizeAfter)\r\n    {\r\n      _posLimit = _streamPos - _keepSizeAfter;\r\n      return S_OK;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CLZInWindow::MoveBlock()\r\n{\r\n  UInt32 offset = (UInt32)(_buffer - _bufferBase) + _pos - _keepSizeBefore;\r\n  // we need one additional byte, since MovePos moves on 1 byte.\r\n  if (offset > 0)\r\n    offset--; \r\n  UInt32 numBytes = (UInt32)(_buffer - _bufferBase) + _streamPos -  offset;\r\n  memmove(_bufferBase, _bufferBase + offset, numBytes);\r\n  _buffer -= offset;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/LZInWindow.h",
    "content": "// LZInWindow.h\r\n\r\n#ifndef __LZ_IN_WINDOW_H\r\n#define __LZ_IN_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n\r\nclass CLZInWindow\r\n{\r\n  Byte *_bufferBase; // pointer to buffer with data\r\n  ISequentialInStream *_stream;\r\n  UInt32 _posLimit;  // offset (from _buffer) when new block reading must be done\r\n  bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n  const Byte *_pointerToLastSafePosition;\r\nprotected:\r\n  Byte  *_buffer;   // Pointer to virtual Buffer begin\r\n  UInt32 _blockSize;  // Size of Allocated memory block\r\n  UInt32 _pos;             // offset (from _buffer) of curent byte\r\n  UInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n  UInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n  UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\r\n  void MoveBlock();\r\n  HRESULT ReadBlock();\r\n  void Free();\r\npublic:\r\n  CLZInWindow(): _bufferBase(0) {}\r\n  virtual ~CLZInWindow() { Free(); }\r\n\r\n  // keepSizeBefore + keepSizeAfter + keepSizeReserv < 4G)\r\n  bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv = (1<<17));\r\n\r\n  void SetStream(ISequentialInStream *stream);\r\n  HRESULT Init();\r\n  // void ReleaseStream();\r\n\r\n  Byte *GetBuffer() const { return _buffer; }\r\n\r\n  const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }\r\n\r\n  HRESULT MovePos()\r\n  {\r\n    _pos++;\r\n    if (_pos > _posLimit)\r\n    {\r\n      const Byte *pointerToPostion = _buffer + _pos;\r\n      if(pointerToPostion > _pointerToLastSafePosition)\r\n        MoveBlock();\r\n      return ReadBlock();\r\n    }\r\n    else\r\n      return S_OK;\r\n  }\r\n  Byte GetIndexByte(Int32 index) const  {  return _buffer[(size_t)_pos + index]; }\r\n\r\n  // index + limit have not to exceed _keepSizeAfter;\r\n  // -2G <= index < 2G\r\n  UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const\r\n  {  \r\n    if(_streamEndWasReached)\r\n      if ((_pos + index) + limit > _streamPos)\r\n        limit = _streamPos - (_pos + index);\r\n    distance++;\r\n    const Byte *pby = _buffer + (size_t)_pos + index;\r\n    UInt32 i;\r\n    for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);\r\n    return i;\r\n  }\r\n\r\n  UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }\r\n\r\n  void ReduceOffsets(Int32 subValue)\r\n  {\r\n    _buffer += subValue;\r\n    _posLimit -= subValue;\r\n    _pos -= subValue;\r\n    _streamPos -= subValue;\r\n  }\r\n\r\n  bool NeedMove(UInt32 numCheckBytes)\r\n  {\r\n    UInt32 reserv = _pointerToLastSafePosition - (_buffer + _pos);\r\n    return (reserv <= numCheckBytes);\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/LZOutWindow.cpp",
    "content": "// LZOutWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"LZOutWindow.h\"\r\n\r\nvoid CLZOutWindow::Init(bool solid)\r\n{\r\n  if(!solid)\r\n    COutBuffer::Init();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/LZOutWindow.h",
    "content": "// LZOutWindow.h\r\n\r\n#ifndef __LZ_OUT_WINDOW_H\r\n#define __LZ_OUT_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\ntypedef COutBufferException CLZOutWindowException;\r\n#endif\r\n\r\nclass CLZOutWindow: public COutBuffer\r\n{\r\npublic:\r\n  void Init(bool solid = false);\r\n  \r\n  // distance >= 0, len > 0, \r\n  bool CopyBlock(UInt32 distance, UInt32 len)\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (distance >= _pos)\r\n    {\r\n      if (!_overDict || distance >= _bufferSize)\r\n        return false;\r\n      pos += _bufferSize;\r\n    }\r\n    do\r\n    {\r\n      if (pos == _bufferSize)\r\n        pos = 0;\r\n      _buffer[_pos++] = _buffer[pos++];\r\n      if (_pos == _limitPos)\r\n        FlushWithCheck();  \r\n    }\r\n    while(--len != 0);\r\n    return true;\r\n  }\r\n  \r\n  void PutByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if (_pos == _limitPos)\r\n      FlushWithCheck();  \r\n  }\r\n  \r\n  Byte GetByte(UInt32 distance) const\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n      pos += _bufferSize;\r\n    return _buffer[pos]; \r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZ/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA/LZMA.h",
    "content": "// LZMA.h\r\n\r\n#ifndef __LZMA_H\r\n#define __LZMA_H\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst UInt32 kNumRepDistances = 4;\r\n\r\nconst int kNumStates = 12;\r\n\r\nconst Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nconst Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nconst Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nconst Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\nclass CState\r\n{\r\npublic:\r\n  Byte Index;\r\n  void Init() { Index = 0; }\r\n  void UpdateChar() { Index = kLiteralNextStates[Index]; }\r\n  void UpdateMatch() { Index = kMatchNextStates[Index]; }\r\n  void UpdateRep() { Index = kRepNextStates[Index]; }\r\n  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }\r\n  bool IsCharState() const { return Index < 7; }\r\n};\r\n\r\nconst int kNumPosSlotBits = 6; \r\nconst int kDicLogSizeMin = 0; \r\nconst int kDicLogSizeMax = 32; \r\nconst int kDistTableSizeMax = kDicLogSizeMax * 2; \r\n\r\nconst UInt32 kNumLenToPosStates = 4;\r\n\r\ninline UInt32 GetLenToPosState(UInt32 len)\r\n{\r\n  len -= 2;\r\n  if (len < kNumLenToPosStates)\r\n    return len;\r\n  return kNumLenToPosStates - 1;\r\n}\r\n\r\nnamespace NLength {\r\n\r\nconst int kNumPosStatesBitsMax = 4;\r\nconst UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\r\nconst int kNumPosStatesBitsEncodingMax = 4;\r\nconst UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\nconst int kNumLowBits = 3;\r\nconst int kNumMidBits = 3;\r\nconst int kNumHighBits = 8;\r\nconst UInt32 kNumLowSymbols = 1 << kNumLowBits;\r\nconst UInt32 kNumMidSymbols = 1 << kNumMidBits;\r\nconst UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\r\n\r\n}\r\n\r\nconst UInt32 kMatchMinLen = 2;\r\nconst UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\r\n\r\nconst int kNumAlignBits = 4;\r\nconst UInt32 kAlignTableSize = 1 << kNumAlignBits;\r\nconst UInt32 kAlignMask = (kAlignTableSize - 1);\r\n\r\nconst UInt32 kStartPosModelIndex = 4;\r\nconst UInt32 kEndPosModelIndex = 14;\r\nconst UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\nconst UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\r\nconst int kNumLitPosStatesBitsEncodingMax = 4;\r\nconst int kNumLitContextBitsMax = 8;\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA/LZMADecoder.cpp",
    "content": "// LZMADecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\n#include \"../../../Common/Defs.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kLenIdFinished = -1;\r\nconst int kLenIdNeedInit = -2;\r\n\r\nvoid CDecoder::Init()\r\n{\r\n  { \r\n    for(int i = 0; i < kNumStates; i++)\r\n    {\r\n      for (UInt32 j = 0; j <= _posStateMask; j++)\r\n      {\r\n        _isMatch[i][j].Init();\r\n        _isRep0Long[i][j].Init();\r\n      }\r\n      _isRep[i].Init();\r\n      _isRepG0[i].Init();\r\n      _isRepG1[i].Init();\r\n      _isRepG2[i].Init();\r\n    }\r\n  }\r\n  { \r\n    for (UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n    _posSlotDecoder[i].Init();\r\n  }\r\n  { \r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posDecoders[i].Init();\r\n  }\r\n  _posAlignDecoder.Init();\r\n  _lenDecoder.Init(_posStateMask + 1);\r\n  _repMatchLenDecoder.Init(_posStateMask + 1);\r\n  _literalDecoder.Init();\r\n\r\n  _state.Init();\r\n  _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0;\r\n}\r\n\r\nHRESULT CDecoder::CodeSpec(UInt32 curSize)\r\n{\r\n  if (_outSizeDefined)\r\n  {\r\n    const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize();\r\n    if (curSize > rem)\r\n      curSize = (UInt32)rem;\r\n  }\r\n\r\n  if (_remainLen == kLenIdFinished)\r\n    return S_OK;\r\n  if (_remainLen == kLenIdNeedInit)\r\n  {\r\n    _rangeDecoder.Init();\r\n    Init();\r\n    _remainLen = 0;\r\n  }\r\n  if (curSize == 0)\r\n    return S_OK;\r\n\r\n  UInt32 rep0 = _reps[0];\r\n  UInt32 rep1 = _reps[1];\r\n  UInt32 rep2 = _reps[2];\r\n  UInt32 rep3 = _reps[3];\r\n  CState state = _state;\r\n  Byte previousByte;\r\n\r\n  while(_remainLen > 0 && curSize > 0)\r\n  {\r\n    previousByte = _outWindowStream.GetByte(rep0);\r\n    _outWindowStream.PutByte(previousByte);\r\n    _remainLen--;\r\n    curSize--;\r\n  }\r\n  UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n  if (nowPos64 == 0)\r\n    previousByte = 0;\r\n  else\r\n    previousByte = _outWindowStream.GetByte(0);\r\n\r\n  while(curSize > 0)\r\n  {\r\n    {\r\n      #ifdef _NO_EXCEPTIONS\r\n      if (_rangeDecoder.Stream.ErrorCode != S_OK)\r\n        return _rangeDecoder.Stream.ErrorCode;\r\n      #endif\r\n      if (_rangeDecoder.Stream.WasFinished())\r\n        return S_FALSE;\r\n      UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n      if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n      {\r\n        if(!state.IsCharState())\r\n          previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte, _outWindowStream.GetByte(rep0));\r\n        else\r\n          previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte);\r\n        _outWindowStream.PutByte(previousByte);\r\n        state.UpdateChar();\r\n        curSize--;\r\n        nowPos64++;\r\n      }\r\n      else             \r\n      {\r\n        UInt32 len;\r\n        if(_isRep[state.Index].Decode(&_rangeDecoder) == 1)\r\n        {\r\n          len = 0;\r\n          if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0)\r\n          {\r\n            if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n            {\r\n              state.UpdateShortRep();\r\n              len = 1;\r\n            }\r\n          }\r\n          else\r\n          {\r\n            UInt32 distance;\r\n            if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0)\r\n              distance = rep1;\r\n            else \r\n            {\r\n              if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0)\r\n                distance = rep2;\r\n              else\r\n              {\r\n                distance = rep3;\r\n                rep3 = rep2;\r\n              }\r\n              rep2 = rep1;\r\n            }\r\n            rep1 = rep0;\r\n            rep0 = distance;\r\n          }\r\n          if (len == 0)\r\n          {\r\n            len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;\r\n            state.UpdateRep();\r\n          }\r\n        }\r\n        else\r\n        {\r\n          rep3 = rep2;\r\n          rep2 = rep1;\r\n          rep1 = rep0;\r\n          len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);\r\n          state.UpdateMatch();\r\n          UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);\r\n          if (posSlot >= kStartPosModelIndex)\r\n          {\r\n            UInt32 numDirectBits = (posSlot >> 1) - 1;\r\n            rep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\r\n            if (posSlot < kEndPosModelIndex)\r\n              rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders + \r\n                  rep0 - posSlot - 1, &_rangeDecoder, numDirectBits);\r\n            else\r\n            {\r\n              rep0 += (_rangeDecoder.DecodeDirectBits(\r\n                  numDirectBits - kNumAlignBits) << kNumAlignBits);\r\n              rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder);\r\n              if (rep0 == 0xFFFFFFFF)\r\n              {\r\n                _remainLen = kLenIdFinished;\r\n                return S_OK;\r\n              }\r\n            }\r\n          }\r\n          else\r\n            rep0 = posSlot;\r\n        }\r\n        UInt32 locLen = len;\r\n        if (len > curSize)\r\n          locLen = (UInt32)curSize;\r\n        if (!_outWindowStream.CopyBlock(rep0, locLen))\r\n          return S_FALSE;\r\n        previousByte = _outWindowStream.GetByte(0);\r\n        curSize -= locLen;\r\n        nowPos64 += locLen;\r\n        len -= locLen;\r\n        if (len != 0)\r\n        {\r\n          _remainLen = (Int32)len;\r\n          break;\r\n        }\r\n\r\n        #ifdef _NO_EXCEPTIONS\r\n        if (_outWindowStream.ErrorCode != S_OK)\r\n          return _outWindowStream.ErrorCode;\r\n        #endif\r\n      }\r\n    }\r\n  }\r\n  if (_rangeDecoder.Stream.WasFinished())\r\n    return S_FALSE;\r\n  _reps[0] = rep0;\r\n  _reps[1] = rep1;\r\n  _reps[2] = rep2;\r\n  _reps[3] = rep3;\r\n  _state = state;\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 *, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  SetInStream(inStream);\r\n  _outWindowStream.SetStream(outStream);\r\n  SetOutStreamSize(outSize);\r\n  CDecoderFlusher flusher(this);\r\n\r\n  while (true)\r\n  {\r\n    UInt32 curSize = 1 << 18;\r\n    RINOK(CodeSpec(curSize));\r\n    if (_remainLen == kLenIdFinished)\r\n      break;\r\n    if (progress != NULL)\r\n    {\r\n      UInt64 inSize = _rangeDecoder.GetProcessedSize();\r\n      UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(&inSize, &nowPos64));\r\n    }\r\n    if (_outSizeDefined)\r\n      if (_outWindowStream.GetProcessedSize() >= _outSize)\r\n        break;\r\n  } \r\n  flusher.NeedFlush = false;\r\n  return Flush();\r\n}\r\n\r\n\r\n#ifdef _NO_EXCEPTIONS\r\n\r\n#define LZMA_TRY_BEGIN\r\n#define LZMA_TRY_END\r\n\r\n#else\r\n\r\n#define LZMA_TRY_BEGIN try { \r\n#define LZMA_TRY_END } \\\r\n  catch(const CInBufferException &e)  { return e.ErrorCode; } \\\r\n  catch(const CLZOutWindowException &e)  { return e.ErrorCode; } \\\r\n  catch(...) { return S_FALSE; }\r\n\r\n#endif\r\n\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  LZMA_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size)\r\n{\r\n  if (size < 5)\r\n    return E_INVALIDARG;\r\n  int lc = properties[0] % 9;\r\n  Byte remainder = (Byte)(properties[0] / 9);\r\n  int lp = remainder % 5;\r\n  int pb = remainder / 5;\r\n  if (pb > NLength::kNumPosStatesBitsMax)\r\n    return E_INVALIDARG;\r\n  _posStateMask = (1 << pb) - 1;\r\n  UInt32 dictionarySize = 0;\r\n  for (int i = 0; i < 4; i++)\r\n    dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n  if (!_outWindowStream.Create(dictionarySize))\r\n    return E_OUTOFMEMORY;\r\n  if (!_literalDecoder.Create(lp, lc))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = _rangeDecoder.GetProcessedSize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _rangeDecoder.SetStream(inStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::ReleaseInStream()\r\n{\r\n  _rangeDecoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  if (_outSizeDefined = (outSize != NULL))\r\n    _outSize = *outSize;\r\n  _remainLen = kLenIdNeedInit;\r\n  _outWindowStream.Init();\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _ST_MODE\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  const UInt64 startPos = _outWindowStream.GetProcessedSize();\r\n  _outWindowStream.SetMemStream((Byte *)data);\r\n  RINOK(CodeSpec(size));\r\n  if (processedSize)\r\n    *processedSize = (UInt32)(_outWindowStream.GetProcessedSize() - startPos);\r\n  return Flush();\r\n  LZMA_TRY_END\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA/LZMADecoder.h",
    "content": "// LZMA/Decoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/LZOutWindow.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;\r\n\r\nclass CLiteralDecoder2\r\n{\r\n  CMyBitDecoder _decoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _decoders[i].Init();\r\n  }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n      RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, Byte matchByte)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      UInt32 matchBit = (matchByte >> 7) & 1;\r\n      matchByte <<= 1;\r\n      // UInt32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);\r\n      // symbol = (symbol << 1) | bit;\r\n      UInt32 bit;\r\n      RC_GETBIT2(kNumMoveBits, _decoders[0x100 + (matchBit << 8) + symbol].Prob, symbol, \r\n          bit = 0, bit = 1)\r\n      if (matchBit != bit)\r\n      {\r\n        while (symbol < 0x100)\r\n        {\r\n          // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n          RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n        }\r\n        break;\r\n      }\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n};\r\n\r\nclass CLiteralDecoder\r\n{\r\n  CLiteralDecoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralDecoder(): _coders(0) {}\r\n  ~CLiteralDecoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte, Byte matchByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CDecoder\r\n{\r\n  CMyBitDecoder _choice;\r\n  CMyBitDecoder _choice2;\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder; \r\npublic:\r\n  void Init(UInt32 numPosStates)\r\n  {\r\n    _choice.Init();\r\n    _choice2.Init();\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n    {\r\n      _lowCoder[posState].Init();\r\n      _midCoder[posState].Init();\r\n    }\r\n    _highCoder.Init();\r\n  }\r\n  UInt32 Decode(NRangeCoder::CDecoder *rangeDecoder, UInt32 posState)\r\n  {\r\n    if(_choice.Decode(rangeDecoder) == 0)\r\n      return _lowCoder[posState].Decode(rangeDecoder);\r\n    if(_choice2.Decode(rangeDecoder) == 0)\r\n      return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);\r\n    return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CDecoder: \r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  public ICompressGetInStreamProcessedSize,\r\n  #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CLZOutWindow _outWindowStream;\r\n  NRangeCoder::CDecoder _rangeDecoder;\r\n\r\n  CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax];\r\n  CMyBitDecoder _isRep[kNumStates];\r\n  CMyBitDecoder _isRepG0[kNumStates];\r\n  CMyBitDecoder _isRepG1[kNumStates];\r\n  CMyBitDecoder _isRepG2[kNumStates];\r\n  CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax];\r\n\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];\r\n\r\n  CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;\r\n  \r\n  NLength::CDecoder _lenDecoder;\r\n  NLength::CDecoder _repMatchLenDecoder;\r\n\r\n  CLiteralDecoder _literalDecoder;\r\n\r\n  UInt32 _posStateMask;\r\n\r\n  ///////////////////\r\n  // State\r\n  UInt32 _reps[4];\r\n  CState _state;\r\n  Int32 _remainLen; // -1 means end of stream. // -2 means need Init\r\n  UInt64 _outSize;\r\n  bool _outSizeDefined;\r\n\r\n  void Init();\r\n  HRESULT CodeSpec(UInt32 size);\r\npublic:\r\n\r\n  #ifdef _ST_MODE\r\n  MY_UNKNOWN_IMP5(\r\n      ICompressSetDecoderProperties2, \r\n      ICompressGetInStreamProcessedSize,\r\n      ICompressSetInStream, \r\n      ICompressSetOutStreamSize, \r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize)\r\n  #endif\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _outWindowStream.ReleaseStream();\r\n    ReleaseInStream();\r\n  }\r\n\r\n  class CDecoderFlusher\r\n  {\r\n    CDecoder *_decoder;\r\n  public:\r\n    bool NeedFlush;\r\n    CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}\r\n    ~CDecoderFlusher() \r\n    { \r\n      if (NeedFlush)\r\n        _decoder->Flush();\r\n      _decoder->ReleaseStreams(); \r\n    }\r\n  };\r\n\r\n  HRESULT Flush() {  return _outWindowStream.Flush(); }  \r\n\r\n  STDMETHOD(CodeReal)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  \r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifdef _ST_MODE\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  CDecoder(): _outSizeDefined(false) {}\r\n  virtual ~CDecoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA/LZMAEncoder.cpp",
    "content": "// LZMA/Encoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/Defs.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"LZMAEncoder.h\"\r\n\r\n// for minimal compressing code size define these:\r\n// #define COMPRESS_MF_BT\r\n// #define COMPRESS_MF_BT4\r\n\r\n#if !defined(COMPRESS_MF_BT) && !defined(COMPRESS_MF_HC)\r\n#define COMPRESS_MF_BT\r\n#define COMPRESS_MF_HC\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_BT\r\n#if !defined(COMPRESS_MF_BT2) && !defined(COMPRESS_MF_BT3) && !defined(COMPRESS_MF_BT4)\r\n#define COMPRESS_MF_BT2\r\n#define COMPRESS_MF_BT3\r\n#define COMPRESS_MF_BT4\r\n#endif\r\n#ifdef COMPRESS_MF_BT2\r\n#include \"../LZ/BinTree/BinTree2.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT3\r\n#include \"../LZ/BinTree/BinTree3.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT4\r\n#include \"../LZ/BinTree/BinTree4.h\"\r\n#endif\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_HC\r\n#include \"../LZ/HashChain/HC4.h\"\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../LZ/MT/MT.h\"\r\n#endif\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kDefaultDictionaryLogSize = 22;\r\nconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\nenum \r\n{\r\n  kBT2,\r\n  kBT3,\r\n  kBT4,\r\n  kHC4\r\n};\r\n\r\nstatic const wchar_t *kMatchFinderIDs[] = \r\n{\r\n  L\"BT2\",\r\n  L\"BT3\",\r\n  L\"BT4\",\r\n  L\"HC4\"\r\n};\r\n\r\nByte g_FastPos[1 << 11];\r\n\r\nclass CFastPosInit\r\n{\r\npublic:\r\n  CFastPosInit() { Init(); }\r\n  void Init()\r\n  {\r\n    const Byte kFastSlots = 22;\r\n    int c = 2;\r\n    g_FastPos[0] = 0;\r\n    g_FastPos[1] = 1;\r\n\r\n    for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n    {\r\n      UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n      for (UInt32 j = 0; j < k; j++, c++)\r\n        g_FastPos[c] = slotFast;\r\n    }\r\n  }\r\n} g_FastPosInit;\r\n\r\n\r\nvoid CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    _encoders[context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nvoid CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, \r\n    Byte matchByte, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    UInt32 matchBit = (matchByte >> i) & 1;\r\n    _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n    if (matchBit != bit)\r\n    {\r\n      while(i != 0)\r\n      {\r\n        i--;\r\n        UInt32 bit = (symbol >> i) & 1;\r\n        _encoders[context].Encode(rangeEncoder, bit);\r\n        context = (context << 1) | bit;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nUInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  if (matchMode)\r\n  {\r\n    do \r\n    {\r\n      i--;\r\n      UInt32 matchBit = (matchByte >> i) & 1;\r\n      UInt32 bit = (symbol >> i) & 1;\r\n      price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit);\r\n      context = (context << 1) | bit;\r\n      if (matchBit != bit)\r\n        break;\r\n    }\r\n    while (i != 0);\r\n  }\r\n  while(i != 0)\r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    price += _encoders[context].GetPrice(bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  return price;\r\n};\r\n\r\n\r\nnamespace NLength {\r\n\r\nvoid CEncoder::Init(UInt32 numPosStates)\r\n{\r\n  _choice.Init();\r\n  _choice2.Init();\r\n  for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n  {\r\n    _lowCoder[posState].Init();\r\n    _midCoder[posState].Init();\r\n  }\r\n  _highCoder.Init();\r\n}\r\n\r\nvoid CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n  {\r\n    _choice.Encode(rangeEncoder, 0);\r\n    _lowCoder[posState].Encode(rangeEncoder, symbol);\r\n  }\r\n  else\r\n  {\r\n    _choice.Encode(rangeEncoder, 1);\r\n    if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n    {\r\n      _choice2.Encode(rangeEncoder, 0);\r\n      _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      _choice2.Encode(rangeEncoder, 1);\r\n      _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CEncoder::SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const\r\n{\r\n  UInt32 a0 = _choice.GetPrice0();\r\n  UInt32 a1 = _choice.GetPrice1();\r\n  UInt32 b0 = a1 + _choice2.GetPrice0();\r\n  UInt32 b1 = a1 + _choice2.GetPrice1();\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + _lowCoder[posState].GetPrice(i);\r\n  }\r\n  for (; i < kNumLowSymbols + kNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + _midCoder[posState].GetPrice(i - kNumLowSymbols);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + _highCoder.GetPrice(i - kNumLowSymbols - kNumMidSymbols);\r\n}\r\n\r\n}\r\nCEncoder::CEncoder():\r\n  _numFastBytes(kNumFastBytesDefault),\r\n  _distTableSize(kDefaultDictionaryLogSize * 2),\r\n  _posStateBits(2),\r\n  _posStateMask(4 - 1),\r\n  _numLiteralPosStateBits(0),\r\n  _numLiteralContextBits(3),\r\n  _dictionarySize(1 << kDefaultDictionaryLogSize),\r\n  _dictionarySizePrev(UInt32(-1)),\r\n  _numFastBytesPrev(UInt32(-1)),\r\n  _matchFinderCycles(0),\r\n  _matchFinderIndex(kBT4),\r\n   #ifdef COMPRESS_MF_MT\r\n  _multiThread(false),\r\n   #endif\r\n  _writeEndMark(false),\r\n  setMfPasses(0)\r\n{\r\n  // _maxMode = false;\r\n  _fastMode = false;\r\n}\r\n\r\nHRESULT CEncoder::Create()\r\n{\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_matchFinder)\r\n  {\r\n    switch(_matchFinderIndex)\r\n    {\r\n      #ifdef COMPRESS_MF_BT\r\n      #ifdef COMPRESS_MF_BT2\r\n      case kBT2:\r\n      {\r\n        NBT2::CMatchFinder *mfSpec = new NBT2::CMatchFinder;\r\n        setMfPasses = mfSpec;\r\n        _matchFinder = mfSpec;\r\n        break;\r\n      }\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT3\r\n      case kBT3:\r\n      {\r\n        NBT3::CMatchFinder *mfSpec = new NBT3::CMatchFinder;\r\n        setMfPasses = mfSpec;\r\n        _matchFinder = mfSpec;\r\n        break;\r\n      }\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT4\r\n      case kBT4:\r\n      {\r\n        NBT4::CMatchFinder *mfSpec = new NBT4::CMatchFinder;\r\n        setMfPasses = mfSpec;\r\n        _matchFinder = mfSpec;\r\n        break;\r\n      }\r\n      #endif\r\n      #endif\r\n      \r\n      #ifdef COMPRESS_MF_HC\r\n      case kHC4:\r\n      {\r\n        NHC4::CMatchFinder *mfSpec = new NHC4::CMatchFinder;\r\n        setMfPasses = mfSpec;\r\n        _matchFinder = mfSpec;\r\n        break;\r\n      }\r\n      #endif\r\n    }\r\n    if (_matchFinder == 0)\r\n      return E_OUTOFMEMORY;\r\n\r\n    #ifdef COMPRESS_MF_MT\r\n    if (_multiThread && !(_fastMode && (_matchFinderIndex == kHC4)))\r\n    {\r\n      CMatchFinderMT *mfSpec = new CMatchFinderMT;\r\n      if (mfSpec == 0)\r\n        return E_OUTOFMEMORY;\r\n      CMyComPtr<IMatchFinder> mf = mfSpec;\r\n      RINOK(mfSpec->SetMatchFinder(_matchFinder));\r\n      _matchFinder.Release();\r\n      _matchFinder = mf;\r\n    }\r\n    #endif\r\n  }\r\n  \r\n  if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))\r\n    return E_OUTOFMEMORY;\r\n\r\n  if (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n    return S_OK;\r\n  RINOK(_matchFinder->Create(_dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen + 1)); // actually it's + _numFastBytes - _numFastBytes\r\n  if (_matchFinderCycles != 0 && setMfPasses != 0)\r\n    setMfPasses->SetNumPasses(_matchFinderCycles);\r\n  _dictionarySizePrev = _dictionarySize;\r\n  _numFastBytesPrev = _numFastBytes;\r\n  return S_OK;\r\n}\r\n\r\nstatic bool AreStringsEqual(const wchar_t *base, const wchar_t *testString)\r\n{\r\n  while (true)\r\n  {\r\n    wchar_t c = *testString;\r\n    if (c >= 'a' && c <= 'z')\r\n      c -= 0x20;\r\n    if (*base != c)\r\n      return false;\r\n    if (c == 0)\r\n      return true;\r\n    base++;\r\n    testString++;\r\n  }\r\n}\r\n\r\nstatic int FindMatchFinder(const wchar_t *s)\r\n{\r\n  for (int m = 0; m < (int)(sizeof(kMatchFinderIDs) / sizeof(kMatchFinderIDs[0])); m++)\r\n    if (AreStringsEqual(kMatchFinderIDs[m], s))\r\n      return m;\r\n  return -1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, \r\n    const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  for (UInt32 i = 0; i < numProperties; i++)\r\n  {\r\n    const PROPVARIANT &prop = properties[i];\r\n    switch(propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 numFastBytes = prop.ulVal;\r\n        if(numFastBytes < 5 || numFastBytes > kMatchMaxLen)\r\n          return E_INVALIDARG;\r\n        _numFastBytes = numFastBytes;\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinderCycles:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        _matchFinderCycles = prop.ulVal;\r\n        break;\r\n      }\r\n      case NCoderPropID::kAlgorithm:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 maximize = prop.ulVal;\r\n        _fastMode = (maximize == 0); \r\n        // _maxMode = (maximize >= 2);\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinder:\r\n      {\r\n        if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        int matchFinderIndexPrev = _matchFinderIndex;\r\n        int m = FindMatchFinder(prop.bstrVal);\r\n        if (m < 0)\r\n          return E_INVALIDARG;\r\n        _matchFinderIndex = m;\r\n        if (_matchFinder && matchFinderIndexPrev != _matchFinderIndex)\r\n        {\r\n          _dictionarySizePrev = (UInt32)-1;\r\n          ReleaseMatchFinder();\r\n        }\r\n        break;\r\n      }\r\n      #ifdef COMPRESS_MF_MT\r\n      case NCoderPropID::kMultiThread:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        bool newMultiThread = (prop.boolVal == VARIANT_TRUE);\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          _dictionarySizePrev = (UInt32)-1;\r\n          ReleaseMatchFinder();\r\n          _multiThread = newMultiThread;\r\n        }\r\n        break;\r\n      }\r\n      case NCoderPropID::kNumThreads:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        bool newMultiThread = (prop.ulVal > 1);\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          _dictionarySizePrev = (UInt32)-1;\r\n          ReleaseMatchFinder();\r\n          _multiThread = newMultiThread;\r\n        }\r\n        break;\r\n      }\r\n      #endif\r\n      case NCoderPropID::kDictionarySize:\r\n      {\r\n        const int kDicLogSizeMaxCompress = 30;\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 dictionarySize = prop.ulVal;\r\n        if (dictionarySize < UInt32(1 << kDicLogSizeMin) ||\r\n            dictionarySize > UInt32(1 << kDicLogSizeMaxCompress))\r\n          return E_INVALIDARG;\r\n        _dictionarySize = dictionarySize;\r\n        UInt32 dicLogSize;\r\n        for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n          if (dictionarySize <= (UInt32(1) << dicLogSize))\r\n            break;\r\n        _distTableSize = dicLogSize * 2;\r\n        break;\r\n      }\r\n      case NCoderPropID::kPosStateBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _posStateBits = value;\r\n        _posStateMask = (1 << _posStateBits) - 1;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitPosBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralPosStateBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitContextBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitContextBitsMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralContextBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kEndMarker:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE);\r\n        break;\r\n      }\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{ \r\n  const UInt32 kPropSize = 5;\r\n  Byte properties[kPropSize];\r\n  properties[0] = (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits;\r\n  for (int i = 0; i < 4; i++)\r\n    properties[1 + i] = Byte(_dictionarySize >> (8 * i));\r\n  return WriteStream(outStream, properties, kPropSize, NULL);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _rangeEncoder.SetStream(outStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _rangeEncoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Init()\r\n{\r\n  CBaseState::Init();\r\n\r\n  // RINOK(_matchFinder->Init(inStream));\r\n  _rangeEncoder.Init();\r\n\r\n  for(int i = 0; i < kNumStates; i++)\r\n  {\r\n    for (UInt32 j = 0; j <= _posStateMask; j++)\r\n    {\r\n      _isMatch[i][j].Init();\r\n      _isRep0Long[i][j].Init();\r\n    }\r\n    _isRep[i].Init();\r\n    _isRepG0[i].Init();\r\n    _isRepG1[i].Init();\r\n    _isRepG2[i].Init();\r\n  }\r\n\r\n  _literalEncoder.Init();\r\n\r\n  {\r\n    for(UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n      _posSlotEncoder[i].Init();\r\n  }\r\n  {\r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posEncoders[i].Init();\r\n  }\r\n\r\n  _lenEncoder.Init(1 << _posStateBits);\r\n  _repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n  _posAlignEncoder.Init();\r\n\r\n  _longestMatchWasFound = false;\r\n  _optimumEndIndex = 0;\r\n  _optimumCurrentIndex = 0;\r\n  _additionalOffset = 0;\r\n\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::MovePos(UInt32 num)\r\n{\r\n  if (num == 0)\r\n    return S_OK;\r\n  _additionalOffset += num;\r\n  return _matchFinder->Skip(num);\r\n}\r\n\r\nUInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)\r\n{\r\n  _optimumEndIndex = cur;\r\n  UInt32 posMem = _optimum[cur].PosPrev;\r\n  UInt32 backMem = _optimum[cur].BackPrev;\r\n  do\r\n  {\r\n    if (_optimum[cur].Prev1IsChar)\r\n    {\r\n      _optimum[posMem].MakeAsChar();\r\n      _optimum[posMem].PosPrev = posMem - 1;\r\n      if (_optimum[cur].Prev2)\r\n      {\r\n        _optimum[posMem - 1].Prev1IsChar = false;\r\n        _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n        _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n      }\r\n    }\r\n    UInt32 posPrev = posMem;\r\n    UInt32 backCur = backMem;\r\n\r\n    backMem = _optimum[posPrev].BackPrev;\r\n    posMem = _optimum[posPrev].PosPrev;\r\n\r\n    _optimum[posPrev].BackPrev = backCur;\r\n    _optimum[posPrev].PosPrev = cur;\r\n    cur = posPrev;\r\n  }\r\n  while(cur != 0);\r\n  backRes = _optimum[0].BackPrev;\r\n  _optimumCurrentIndex  = _optimum[0].PosPrev;\r\n  return _optimumCurrentIndex; \r\n}\r\n\r\n/*\r\nOut:\r\n  (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal\r\n*/\r\n\r\nHRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\r\n{\r\n  if(_optimumEndIndex != _optimumCurrentIndex)\r\n  {\r\n    const COptimal &optimum = _optimum[_optimumCurrentIndex];\r\n    lenRes = optimum.PosPrev - _optimumCurrentIndex;\r\n    backRes = optimum.BackPrev;\r\n    _optimumCurrentIndex = optimum.PosPrev;\r\n    return S_OK;\r\n  }\r\n  _optimumCurrentIndex = _optimumEndIndex = 0;\r\n  \r\n  UInt32 lenMain, numDistancePairs;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    RINOK(ReadMatchDistances(lenMain, numDistancePairs));\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    numDistancePairs = _numDistancePairs;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n  const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;\r\n  UInt32 numAvailableBytes = _matchFinder->GetNumAvailableBytes() + 1;\r\n  if (numAvailableBytes < 2)\r\n  {\r\n    backRes = (UInt32)(-1);\r\n    lenRes = 1;\r\n    return S_OK;\r\n  }\r\n  if (numAvailableBytes > kMatchMaxLen)\r\n    numAvailableBytes = kMatchMaxLen;\r\n\r\n  UInt32 reps[kNumRepDistances];\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  UInt32 i;\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    reps[i] = _repDistances[i];\r\n    UInt32 backOffset = reps[i] + 1;\r\n    if (data[0] != data[(size_t)0 - backOffset] || data[1] != data[(size_t)1 - backOffset])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    UInt32 lenTest;\r\n    for (lenTest = 2; lenTest < numAvailableBytes && \r\n        data[lenTest] == data[(size_t)lenTest - backOffset]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    return MovePos(lenRes - 1);\r\n  }\r\n\r\n  UInt32 *matchDistances = _matchDistances + 1;\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 1);\r\n  }\r\n  Byte currentByte = *data;\r\n  Byte matchByte = data[(size_t)0 - reps[0] - 1];\r\n\r\n  if(lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    backRes = (UInt32)-1;\r\n    lenRes = 1;\r\n    return S_OK;\r\n  }\r\n\r\n  _optimum[0].State = _state;\r\n\r\n  UInt32 posState = (position & _posStateMask);\r\n\r\n  _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() + \r\n      _literalEncoder.GetSubCoder(position, _previousByte)->GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n  _optimum[1].MakeAsChar();\r\n\r\n  UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1();\r\n  UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n  if(matchByte == currentByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n    if(shortRepPrice < _optimum[1].Price)\r\n    {\r\n      _optimum[1].Price = shortRepPrice;\r\n      _optimum[1].MakeAsShortRep();\r\n    }\r\n  }\r\n  UInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n  if(lenEnd < 2)\r\n  {\r\n    backRes = _optimum[1].BackPrev;\r\n    lenRes = 1;\r\n    return S_OK;\r\n  }\r\n\r\n  _optimum[1].PosPrev = 0;\r\n  for (i = 0; i < kNumRepDistances; i++)\r\n    _optimum[0].Backs[i] = reps[i];\r\n\r\n  UInt32 len = lenEnd;\r\n  do\r\n    _optimum[len--].Price = kIfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    if (repLen < 2)\r\n      continue;\r\n    UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n      COptimal &optimum = _optimum[repLen];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = i;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n    }\r\n    while(--repLen >= 2);\r\n  }\r\n\r\n  UInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= lenMain)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matchDistances[offs])\r\n      offs += 2;\r\n    for(; ; len++)\r\n    {\r\n      UInt32 distance = matchDistances[offs + 1];\r\n      UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n      COptimal &optimum = _optimum[len];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = distance + kNumRepDistances;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n      if (len == matchDistances[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numDistancePairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  UInt32 cur = 0;\r\n\r\n  while(true)\r\n  {\r\n    cur++;\r\n    if(cur == lenEnd)\r\n    {\r\n      lenRes = Backward(backRes, cur);\r\n      return S_OK;\r\n    }\r\n    UInt32 newLen, numDistancePairs;\r\n    RINOK(ReadMatchDistances(newLen, numDistancePairs));\r\n    if(newLen >= _numFastBytes)\r\n    {\r\n      _numDistancePairs = numDistancePairs;\r\n      _longestMatchLength = newLen;\r\n      _longestMatchWasFound = true;\r\n      lenRes = Backward(backRes, cur);\r\n      return S_OK;\r\n    }\r\n    position++;\r\n    COptimal &curOptimum = _optimum[cur];\r\n    UInt32 posPrev = curOptimum.PosPrev;\r\n    CState state;\r\n    if (curOptimum.Prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOptimum.Prev2)\r\n      {\r\n        state = _optimum[curOptimum.PosPrev2].State;\r\n        if (curOptimum.BackPrev2 < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      else\r\n        state = _optimum[posPrev].State;\r\n      state.UpdateChar();\r\n    }\r\n    else\r\n      state = _optimum[posPrev].State;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (curOptimum.IsShortRep())\r\n        state.UpdateShortRep();\r\n      else\r\n        state.UpdateChar();\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      if (curOptimum.Prev1IsChar && curOptimum.Prev2)\r\n      {\r\n        posPrev = curOptimum.PosPrev2;\r\n        pos = curOptimum.BackPrev2;\r\n        state.UpdateRep();\r\n      }\r\n      else\r\n      {\r\n        pos = curOptimum.BackPrev;\r\n        if (pos < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      const COptimal &prevOptimum = _optimum[posPrev];\r\n      if (pos < kNumRepDistances)\r\n      {\r\n        reps[0] = prevOptimum.Backs[pos];\r\n    \t\tUInt32 i;\r\n        for(i = 1; i <= pos; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n        for(; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i];\r\n      }\r\n      else\r\n      {\r\n        reps[0] = (pos - kNumRepDistances);\r\n        for(UInt32 i = 1; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n      }\r\n    }\r\n    curOptimum.State = state;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n      curOptimum.Backs[i] = reps[i];\r\n    UInt32 curPrice = curOptimum.Price; \r\n    const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;\r\n    const Byte currentByte = *data;\r\n    const Byte matchByte = data[(size_t)0 - reps[0] - 1];\r\n\r\n    UInt32 posState = (position & _posStateMask);\r\n\r\n    UInt32 curAnd1Price = curPrice +\r\n        _isMatch[state.Index][posState].GetPrice0() +\r\n        _literalEncoder.GetSubCoder(position, data[(size_t)0 - 1])->GetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n    COptimal &nextOptimum = _optimum[cur + 1];\r\n\r\n    bool nextIsChar = false;\r\n    if (curAnd1Price < nextOptimum.Price) \r\n    {\r\n      nextOptimum.Price = curAnd1Price;\r\n      nextOptimum.PosPrev = cur;\r\n      nextOptimum.MakeAsChar();\r\n      nextIsChar = true;\r\n    }\r\n\r\n    UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();\r\n    UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n    \r\n    if(matchByte == currentByte &&\r\n        !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n      if(shortRepPrice <= nextOptimum.Price)\r\n      {\r\n        nextOptimum.Price = shortRepPrice;\r\n        nextOptimum.PosPrev = cur;\r\n        nextOptimum.MakeAsShortRep();\r\n        nextIsChar = true;\r\n      }\r\n    }\r\n    /*\r\n    if(newLen == 2 && matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n      continue;\r\n    */\r\n\r\n    UInt32 numAvailableBytesFull = _matchFinder->GetNumAvailableBytes() + 1;\r\n    numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n    UInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n    if (numAvailableBytes < 2)\r\n      continue;\r\n    if (numAvailableBytes > _numFastBytes)\r\n      numAvailableBytes = _numFastBytes;\r\n    if (!nextIsChar && matchByte != currentByte) // speed optimization\r\n    {\r\n      // try Literal + rep0\r\n      UInt32 backOffset = reps[0] + 1;\r\n      UInt32 limit = MyMin(numAvailableBytesFull, _numFastBytes + 1);\r\n      UInt32 temp;\r\n      for (temp = 1; temp < limit && \r\n          data[temp] == data[(size_t)temp - backOffset]; temp++);\r\n      UInt32 lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        CState state2 = state;\r\n        state2.UpdateChar();\r\n        UInt32 posStateNext = (position + 1) & _posStateMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price + \r\n            _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n            _isRep[state2.Index].GetPrice1();\r\n        // for (; lenTest2 >= 2; lenTest2--)\r\n        {\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while(lenEnd < offset)\r\n            _optimum[++lenEnd].Price = kIfinityPrice;\r\n          UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n              0, lenTest2, state2, posStateNext);\r\n          COptimal &optimum = _optimum[offset];\r\n          if (curAndLenPrice < optimum.Price) \r\n          {\r\n            optimum.Price = curAndLenPrice;\r\n            optimum.PosPrev = cur + 1;\r\n            optimum.BackPrev = 0;\r\n            optimum.Prev1IsChar = true;\r\n            optimum.Prev2 = false;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    UInt32 startLen = 2; // speed optimization \r\n    for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)\r\n    {\r\n      // UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n      UInt32 backOffset = reps[repIndex] + 1;\r\n      if (data[0] != data[(size_t)0 - backOffset] ||\r\n          data[1] != data[(size_t)1 - backOffset])\r\n        continue;\r\n      UInt32 lenTest;\r\n      for (lenTest = 2; lenTest < numAvailableBytes && \r\n          data[lenTest] == data[(size_t)lenTest - backOffset]; lenTest++);\r\n      while(lenEnd < cur + lenTest)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n      UInt32 lenTestTemp = lenTest;\r\n      UInt32 price = repMatchPrice + GetPureRepPrice(repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = repIndex;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n      }\r\n      while(--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      // if (_maxMode)\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit && \r\n              data[lenTest2] == data[(size_t)lenTest2 - backOffset]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateRep();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = \r\n                price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState) + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetSubCoder(position + lenTest, data[(size_t)lenTest - 1])->GetPrice(\r\n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextRepMatchPrice = curAndLenCharPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n                _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while(lenEnd < offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    \r\n    //    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n    if (newLen > numAvailableBytes)\r\n    {\r\n      newLen = numAvailableBytes;\r\n      for (numDistancePairs = 0; newLen > matchDistances[numDistancePairs]; numDistancePairs += 2);\r\n      matchDistances[numDistancePairs] = newLen;\r\n      numDistancePairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n      while(lenEnd < cur + newLen)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n      UInt32 offs = 0;\r\n      while(startLen > matchDistances[offs])\r\n        offs += 2;\r\n      UInt32 curBack = matchDistances[offs + 1];\r\n      UInt32 posSlot = GetPosSlot2(curBack);\r\n      for(UInt32 lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice;\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += _distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += _posSlotPrices[lenToPosState][posSlot] + _alignPrices[curBack & kAlignMask];\r\n  \r\n        curAndLenPrice += _lenEncoder.GetPrice(lenTest - kMatchMinLen, posState);\r\n        \r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = curBack + kNumRepDistances;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matchDistances[offs])\r\n        {\r\n          // Try Match + Literal + Rep0\r\n          UInt32 backOffset = curBack + 1;\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit && \r\n              data[lenTest2] == data[(size_t)lenTest2 - backOffset]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateMatch();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetSubCoder(position + lenTest, data[(size_t)lenTest - 1])->GetPrice( \r\n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (posStateNext + 1) & _posStateMask;\r\n            UInt32 nextRepMatchPrice = curAndLenCharPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n                _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while(lenEnd < offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = curBack + kNumRepDistances;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numDistancePairs)\r\n            break;\r\n          curBack = matchDistances[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            posSlot = GetPosSlot2(curBack);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n{\r\n  return ((bigDist >> 7) > smallDist);\r\n}\r\n\r\n\r\nHRESULT CEncoder::ReadMatchDistances(UInt32 &lenRes, UInt32 &numDistancePairs)\r\n{\r\n  lenRes = 0;\r\n  RINOK(_matchFinder->GetMatches(_matchDistances));\r\n  numDistancePairs = _matchDistances[0];\r\n  if (numDistancePairs > 0)\r\n  {\r\n    lenRes = _matchDistances[1 + numDistancePairs - 2];\r\n    if (lenRes == _numFastBytes)\r\n      lenRes += _matchFinder->GetMatchLen(lenRes - 1, _matchDistances[1 + numDistancePairs - 1], \r\n          kMatchMaxLen - lenRes);\r\n  }\r\n  _additionalOffset++;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\r\n{\r\n  UInt32 lenMain, numDistancePairs;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    RINOK(ReadMatchDistances(lenMain, numDistancePairs));\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    numDistancePairs = _numDistancePairs;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n  const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;\r\n  UInt32 numAvailableBytes = _matchFinder->GetNumAvailableBytes() + 1;\r\n  if (numAvailableBytes > kMatchMaxLen)\r\n    numAvailableBytes = kMatchMaxLen;\r\n  if (numAvailableBytes < 2)\r\n  {\r\n    backRes = (UInt32)(-1);\r\n    lenRes = 1;\r\n    return S_OK;\r\n  }\r\n\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n\r\n  for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    UInt32 backOffset = _repDistances[i] + 1;\r\n    if (data[0] != data[(size_t)0 - backOffset] || data[1] != data[(size_t)1 - backOffset])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    UInt32 len;\r\n    for (len = 2; len < numAvailableBytes && data[len] == data[(size_t)len - backOffset]; len++);\r\n    if(len >= _numFastBytes)\r\n    {\r\n      backRes = i;\r\n      lenRes = len;\r\n      return MovePos(lenRes - 1);\r\n    }\r\n    repLens[i] = len;\r\n    if (len > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  UInt32 *matchDistances = _matchDistances + 1;\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 1);\r\n  }\r\n\r\n  UInt32 backMain = 0; // for GCC\r\n  if (lenMain >= 2)\r\n  {\r\n    backMain = matchDistances[numDistancePairs - 1];\r\n    while (numDistancePairs > 2 && lenMain == matchDistances[numDistancePairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matchDistances[numDistancePairs - 3], backMain))\r\n        break;\r\n      numDistancePairs -= 2;\r\n      lenMain = matchDistances[numDistancePairs - 2];\r\n      backMain = matchDistances[numDistancePairs - 1];\r\n    }\r\n    if (lenMain == 2 && backMain >= 0x80)\r\n      lenMain = 1;\r\n  }\r\n\r\n  if (repLens[repMaxIndex] >= 2)\r\n  {\r\n    if (repLens[repMaxIndex] + 1 >= lenMain || \r\n        repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9)) ||\r\n        repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15)))\r\n    {\r\n      backRes = repMaxIndex;\r\n      lenRes = repLens[repMaxIndex];\r\n      return MovePos(lenRes - 1);\r\n    }\r\n  }\r\n  \r\n  if (lenMain >= 2 && numAvailableBytes > 2)\r\n  {\r\n    RINOK(ReadMatchDistances(_longestMatchLength, _numDistancePairs));\r\n    if (_longestMatchLength >= 2)\r\n    {\r\n      UInt32 newDistance = matchDistances[_numDistancePairs - 1];\r\n      if (_longestMatchLength >= lenMain && newDistance < backMain || \r\n          _longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance) ||\r\n          _longestMatchLength > lenMain + 1 ||\r\n          _longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain))\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        lenRes = 1;\r\n        return S_OK;\r\n      }\r\n    }\r\n    data++;\r\n    numAvailableBytes--;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n    {\r\n      UInt32 backOffset = _repDistances[i] + 1;\r\n      if (data[1] != data[(size_t)1 - backOffset] || data[2] != data[(size_t)2 - backOffset])\r\n      {\r\n        repLens[i] = 0;\r\n        continue;\r\n      }\r\n      UInt32 len;\r\n      for (len = 2; len < numAvailableBytes && data[len] == data[(size_t)len - backOffset]; len++);\r\n      if (len + 1 >= lenMain)\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        lenRes = 1;\r\n        return S_OK;\r\n      }\r\n    }\r\n    backRes = backMain + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 2);\r\n  }\r\n  backRes = UInt32(-1);\r\n  lenRes = 1;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Flush(UInt32 nowPos)\r\n{\r\n  ReleaseMFStream();\r\n  WriteEndMarker(nowPos & _posStateMask);\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nvoid CEncoder::WriteEndMarker(UInt32 posState)\r\n{\r\n  // This function for writing End Mark for stream version of LZMA. \r\n  // In current version this feature is not used.\r\n  if (!_writeEndMark)\r\n    return;\r\n\r\n  _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n  _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n  _state.UpdateMatch();\r\n  UInt32 len = kMatchMinLen; // kMatchMaxLen;\r\n  _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n  UInt32 posSlot = (1 << kNumPosSlotBits)  - 1;\r\n  UInt32 lenToPosState = GetLenToPosState(len);\r\n  _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n  UInt32 footerBits = 30;\r\n  UInt32 posReduced = (UInt32(1) << footerBits) - 1;\r\n  _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n  _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n}\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  _needReleaseMFStream = false;\r\n  CCoderReleaser coderReleaser(this);\r\n  RINOK(SetStreams(inStream, outStream, inSize, outSize));\r\n  while(true)\r\n  {\r\n    UInt64 processedInSize;\r\n    UInt64 processedOutSize;\r\n    Int32 finished;\r\n    RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished));\r\n    if (finished != 0)\r\n      return S_OK;\r\n    if (progress != 0)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize));\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CEncoder::SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  _inStream = inStream;\r\n  _finished = false;\r\n  RINOK(Create());\r\n  RINOK(SetOutStream(outStream));\r\n  RINOK(Init());\r\n  \r\n  // CCoderReleaser releaser(this);\r\n\r\n  /*\r\n  if (_matchFinder->GetNumAvailableBytes() == 0)\r\n    return Flush();\r\n  */\r\n\r\n  if (!_fastMode)\r\n  {\r\n    FillDistancesPrices();\r\n    FillAlignPrices();\r\n  }\r\n\r\n  _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _lenEncoder.UpdateTables(1 << _posStateBits);\r\n  _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n  nowPos64 = 0;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)\r\n{\r\n  if (_inStream != 0)\r\n  {\r\n    RINOK(_matchFinder->SetStream(_inStream));\r\n    RINOK(_matchFinder->Init());\r\n    _needReleaseMFStream = true;\r\n    _inStream = 0;\r\n  }\r\n\r\n\r\n  *finished = 1;\r\n  if (_finished)\r\n    return S_OK;\r\n  _finished = true;\r\n\r\n  if (nowPos64 == 0)\r\n  {\r\n    if (_matchFinder->GetNumAvailableBytes() == 0)\r\n      return Flush(UInt32(nowPos64));\r\n    UInt32 len, numDistancePairs;\r\n    RINOK(ReadMatchDistances(len, numDistancePairs));\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n    _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n    _state.UpdateChar();\r\n    Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\r\n    _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte);\r\n    _previousByte = curByte;\r\n    _additionalOffset--;\r\n    nowPos64++;\r\n  }\r\n\r\n  UInt32 nowPos32 = (UInt32)nowPos64;\r\n  UInt32 progressPosValuePrev = nowPos32;\r\n\r\n  if (_matchFinder->GetNumAvailableBytes() == 0)\r\n    return Flush(nowPos32);\r\n\r\n  while(true)\r\n  {\r\n    #ifdef _NO_EXCEPTIONS\r\n    if (_rangeEncoder.Stream.ErrorCode != S_OK)\r\n      return _rangeEncoder.Stream.ErrorCode;\r\n    #endif\r\n    UInt32 pos, len;\r\n    HRESULT result;\r\n    if (_fastMode)\r\n      result = GetOptimumFast(nowPos32, pos, len);\r\n    else\r\n      result = GetOptimum(nowPos32, pos, len);\r\n    RINOK(result);\r\n\r\n    UInt32 posState = nowPos32 & _posStateMask;\r\n    if(len == 1 && pos == 0xFFFFFFFF)\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n      Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\r\n      CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(nowPos32, _previousByte);\r\n      if(_state.IsCharState())\r\n        subCoder->Encode(&_rangeEncoder, curByte);\r\n      else\r\n      {\r\n        Byte matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - _additionalOffset);\r\n        subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);\r\n      }\r\n      _state.UpdateChar();\r\n      _previousByte = curByte;\r\n    }\r\n    else\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n      if(pos < kNumRepDistances)\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 1);\r\n        if(pos == 0)\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 0);\r\n          _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = _repDistances[pos];\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 1);\r\n          if (pos == 1)\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 0);\r\n          else\r\n          {\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 1);\r\n            _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);\r\n            if (pos == 3)\r\n              _repDistances[3] = _repDistances[2];\r\n            _repDistances[2] = _repDistances[1];\r\n          }\r\n          _repDistances[1] = _repDistances[0];\r\n          _repDistances[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          _state.UpdateShortRep();\r\n        else\r\n        {\r\n          _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n          _state.UpdateRep();\r\n        }\r\n      }\r\n      else\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n        _state.UpdateMatch();\r\n        _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n        pos -= kNumRepDistances;\r\n        UInt32 posSlot = GetPosSlot(pos);\r\n        _posSlotEncoder[GetLenToPosState(len)].Encode(&_rangeEncoder, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1, \r\n                &_rangeEncoder, footerBits, posReduced);\r\n          else\r\n          {\r\n            _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n            _alignPriceCount++;\r\n          }\r\n        }\r\n        _repDistances[3] = _repDistances[2];\r\n        _repDistances[2] = _repDistances[1];\r\n        _repDistances[1] = _repDistances[0];\r\n        _repDistances[0] = pos;\r\n        _matchPriceCount++;\r\n      }\r\n      _previousByte = _matchFinder->GetIndexByte(len - 1 - _additionalOffset);\r\n    }\r\n    _additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (_additionalOffset == 0)\r\n    {\r\n      if (!_fastMode)\r\n      {\r\n        if (_matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices();\r\n        if (_alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices();\r\n      }\r\n      if (_matchFinder->GetNumAvailableBytes() == 0)\r\n        return Flush(nowPos32);\r\n      if (nowPos32 - progressPosValuePrev >= (1 << 14))\r\n      {\r\n        nowPos64 += nowPos32 - progressPosValuePrev;\r\n        *inSize = nowPos64;\r\n        *outSize = _rangeEncoder.GetProcessedSize();\r\n        _finished = false;\r\n        *finished = 0;\r\n        return S_OK;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try \r\n  { \r\n  #endif\r\n    return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  #ifndef _NO_EXCEPTIONS\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return E_FAIL; }\r\n  #endif\r\n}\r\n  \r\nvoid CEncoder::FillDistancesPrices()\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  for (UInt32 i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  { \r\n    UInt32 posSlot = GetPosSlot(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = NRangeCoder::ReverseBitTreeGetPrice(_posEncoders + \r\n      base - posSlot - 1, footerBits, i - base);\r\n  }\r\n\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n\t  UInt32 posSlot;\r\n    NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> &encoder = _posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = _posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = encoder.GetPrice(posSlot);\r\n    for (posSlot = kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);\r\n\r\n    UInt32 *distancesPrices = _distancesPrices[lenToPosState];\r\n\t  UInt32 i;\r\n    for (i = 0; i < kStartPosModelIndex; i++)\r\n      distancesPrices[i] = posSlotPrices[i];\r\n    for (; i < kNumFullDistances; i++)\r\n      distancesPrices[i] = posSlotPrices[GetPosSlot(i)] + tempPrices[i];\r\n  }\r\n  _matchPriceCount = 0;\r\n}\r\n\r\nvoid CEncoder::FillAlignPrices()\r\n{\r\n  for (UInt32 i = 0; i < kAlignTableSize; i++)\r\n    _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n  _alignPriceCount = 0;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA/LZMAEncoder.h",
    "content": "// LZMA/Encoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/IMatchFinder.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;\r\n\r\nclass CBaseState\r\n{\r\nprotected:\r\n  CState _state;\r\n  Byte _previousByte;\r\n  UInt32 _repDistances[kNumRepDistances];\r\n  void Init()\r\n  {\r\n    _state.Init();\r\n    _previousByte = 0;\r\n    for(UInt32 i = 0 ; i < kNumRepDistances; i++)\r\n      _repDistances[i] = 0;\r\n  }\r\n};\r\n\r\nstruct COptimal\r\n{\r\n  CState State;\r\n\r\n  bool Prev1IsChar;\r\n  bool Prev2;\r\n\r\n  UInt32 PosPrev2;\r\n  UInt32 BackPrev2;     \r\n\r\n  UInt32 Price;    \r\n  UInt32 PosPrev;         // posNext;\r\n  UInt32 BackPrev;     \r\n  UInt32 Backs[kNumRepDistances];\r\n  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }\r\n  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n  bool IsShortRep() { return (BackPrev == 0); }\r\n};\r\n\r\n\r\nextern Byte g_FastPos[1 << 11];\r\ninline UInt32 GetPosSlot(UInt32 pos)\r\n{\r\n  if (pos < (1 << 11))\r\n    return g_FastPos[pos];\r\n  if (pos < (1 << 21))\r\n    return g_FastPos[pos >> 10] + 20;\r\n  return g_FastPos[pos >> 20] + 40;\r\n}\r\n\r\ninline UInt32 GetPosSlot2(UInt32 pos)\r\n{\r\n  if (pos < (1 << 17))\r\n    return g_FastPos[pos >> 6] + 12;\r\n  if (pos < (1 << 27))\r\n    return g_FastPos[pos >> 16] + 32;\r\n  return g_FastPos[pos >> 26] + 52;\r\n}\r\n\r\nconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\nconst UInt32 kNumOpts = 1 << 12;\r\n\r\n\r\nclass CLiteralEncoder2\r\n{\r\n  CMyBitEncoder _encoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _encoders[i].Init();\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);\r\n  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;\r\n};\r\n\r\nclass CLiteralEncoder\r\n{\r\n  CLiteralEncoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralEncoder(): _coders(0) {}\r\n  ~CLiteralEncoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)\r\n    { return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CEncoder\r\n{\r\n  CMyBitEncoder _choice;\r\n  CMyBitEncoder _choice2;\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;\r\npublic:\r\n  void Init(UInt32 numPosStates);\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);\r\n  void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;\r\n};\r\n\r\nconst UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\r\n\r\nclass CPriceTableEncoder: public CEncoder\r\n{\r\n  UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];\r\n  UInt32 _tableSize;\r\n  UInt32 _counters[kNumPosStatesEncodingMax];\r\npublic:\r\n  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }\r\n  void UpdateTable(UInt32 posState)\r\n  {\r\n    SetPrices(posState, _tableSize, _prices[posState]);\r\n    _counters[posState] = _tableSize;\r\n  }\r\n  void UpdateTables(UInt32 numPosStates)\r\n  {\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n      UpdateTable(posState);\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)\r\n  {\r\n    CEncoder::Encode(rangeEncoder, symbol, posState);\r\n    if (updatePrice)\r\n      if (--_counters[posState] == 0)\r\n        UpdateTable(posState);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CEncoder : \r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CBaseState,\r\n  public CMyUnknownImp\r\n{\r\n  COptimal _optimum[kNumOpts];\r\n  CMyComPtr<IMatchFinder> _matchFinder; // test it\r\n  NRangeCoder::CEncoder _rangeEncoder;\r\n\r\n  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n  CMyBitEncoder _isRep[kNumStates];\r\n  CMyBitEncoder _isRepG0[kNumStates];\r\n  CMyBitEncoder _isRepG1[kNumStates];\r\n  CMyBitEncoder _isRepG2[kNumStates];\r\n  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];\r\n\r\n  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;\r\n  \r\n  NLength::CPriceTableEncoder _lenEncoder;\r\n  NLength::CPriceTableEncoder _repMatchLenEncoder;\r\n\r\n  CLiteralEncoder _literalEncoder;\r\n\r\n  UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];\r\n\r\n  bool _fastMode;\r\n  // bool _maxMode;\r\n  UInt32 _numFastBytes;\r\n  UInt32 _longestMatchLength;    \r\n  UInt32 _numDistancePairs;\r\n\r\n  UInt32 _additionalOffset;\r\n\r\n  UInt32 _optimumEndIndex;\r\n  UInt32 _optimumCurrentIndex;\r\n\r\n  bool _longestMatchWasFound;\r\n\r\n  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  \r\n  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n\r\n  UInt32 _alignPrices[kAlignTableSize];\r\n  UInt32 _alignPriceCount;\r\n\r\n  UInt32 _distTableSize;\r\n\r\n  UInt32 _posStateBits;\r\n  UInt32 _posStateMask;\r\n  UInt32 _numLiteralPosStateBits;\r\n  UInt32 _numLiteralContextBits;\r\n\r\n  UInt32 _dictionarySize;\r\n\r\n  UInt32 _dictionarySizePrev;\r\n  UInt32 _numFastBytesPrev;\r\n\r\n  UInt32 _matchPriceCount;\r\n  UInt64 nowPos64;\r\n  bool _finished;\r\n  ISequentialInStream *_inStream;\r\n\r\n  UInt32 _matchFinderCycles;\r\n  int _matchFinderIndex;\r\n  #ifdef COMPRESS_MF_MT\r\n  bool _multiThread;\r\n  #endif\r\n\r\n  bool _writeEndMark;\r\n\r\n  bool _needReleaseMFStream;\r\n\r\n  IMatchFinderSetNumPasses *setMfPasses;\r\n\r\n  void ReleaseMatchFinder()\r\n  {\r\n    setMfPasses = 0;\r\n    _matchFinder.Release();\r\n  }\r\n  \r\n  HRESULT ReadMatchDistances(UInt32 &len, UInt32 &numDistancePairs);\r\n\r\n  HRESULT MovePos(UInt32 num);\r\n  UInt32 GetRepLen1Price(CState state, UInt32 posState) const\r\n  {\r\n    return _isRepG0[state.Index].GetPrice0() +\r\n        _isRep0Long[state.Index][posState].GetPrice0();\r\n  }\r\n  \r\n  UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    if(repIndex == 0)\r\n    {\r\n      price = _isRepG0[state.Index].GetPrice0();\r\n      price += _isRep0Long[state.Index][posState].GetPrice1();\r\n    }\r\n    else\r\n    {\r\n      price = _isRepG0[state.Index].GetPrice1();\r\n      if (repIndex == 1)\r\n        price += _isRepG1[state.Index].GetPrice0();\r\n      else\r\n      {\r\n        price += _isRepG1[state.Index].GetPrice1();\r\n        price += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n      }\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const\r\n  {\r\n    return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +\r\n        GetPureRepPrice(repIndex, state, posState);\r\n  }\r\n  /*\r\n  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const\r\n  {\r\n    if (pos >= kNumFullDistances)\r\n      return kIfinityPrice;\r\n    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);\r\n  }\r\n  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n  */\r\n  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n\r\n  UInt32 Backward(UInt32 &backRes, UInt32 cur);\r\n  HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r\n  HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r\n\r\n  void FillDistancesPrices();\r\n  void FillAlignPrices();\r\n    \r\n  void ReleaseMFStream()\r\n  {\r\n    if (_matchFinder && _needReleaseMFStream)\r\n    {\r\n      _matchFinder->ReleaseStream();\r\n      _needReleaseMFStream = false;\r\n    }\r\n  }\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    ReleaseMFStream();\r\n    ReleaseOutStream();\r\n  }\r\n\r\n  HRESULT Flush(UInt32 nowPos);\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()\r\n    {\r\n      _coder->ReleaseStreams();\r\n    }\r\n  };\r\n  friend class CCoderReleaser;\r\n\r\n  void WriteEndMarker(UInt32 posState);\r\n\r\npublic:\r\n  CEncoder();\r\n  void SetWriteEndMarkerMode(bool writeEndMarker)\r\n    { _writeEndMark= writeEndMarker; }\r\n\r\n  HRESULT Create();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  HRESULT Init();\r\n  \r\n  // ICompressCoder interface\r\n  HRESULT SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize);\r\n  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);\r\n\r\n  HRESULT CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressCoder interface\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressSetCoderProperties2\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  \r\n  // ICompressWriteCoderProperties\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"BT\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3Z.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTreeMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"HC\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HCMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\IMatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA_C\\LzmaDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA_C\\LzmaDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA_C\\LzmaTypes.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"LzmaRamDecode.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kMode,\r\n  kDictionary,\r\n  kFastBytes,\r\n  kMatchFinderCycles,\r\n  kLitContext,\r\n  kLitPos,\r\n  kPosBits,\r\n  kMatchFinder,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kSimple, false }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\"\r\n    \"  -d{N}:  set dictionary - [0,30], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -mc{N}: set number of cycles for match finder\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[], \r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA 4.43 Copyright (c) 1999-2006 Igor Pavlov  2006-06-04\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  if (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }   \r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++]; \r\n\r\n  bool dictionaryIsDefined = false;\r\n  UInt32 dictionary = 1 << 21;\r\n  if(parser[NKey::kDictionary].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dictionary = 1 << dicLog;\r\n    dictionaryIsDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 10;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchmark(stderr, numIterations, dictionary);\r\n  }\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++]; \r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\", \r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++]; \r\n    COutFileStream *outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\", \r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    UInt32 inSize = (UInt32)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize); \r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)\r\n      throw \"Can not read\";\r\n    if ((UInt32)inSize != processedSize)\r\n      throw \"Read size error\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSizeProcessed;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictionaryIsDefined)\r\n        dictionary = 1 << 23;\r\n      int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, \r\n          dictionary, SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      size_t outSize;\r\n      if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)\r\n        throw \"data error\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLZMA::CEncoder *encoderSpec = \r\n      new NCompress::NLZMA::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictionaryIsDefined)\r\n      dictionary = 1 << 23;\r\n\r\n    UInt32 posStateBits = 2;\r\n    UInt32 litContextBits = 3; // for normal files\r\n    // UInt32 litContextBits = 0; // for 32-bit data\r\n    UInt32 litPosBits = 0;\r\n    // UInt32 litPosBits = 2; // for 32-bit data\r\n    UInt32 algorithm = 2;\r\n    UInt32 numFastBytes = 128;\r\n    UInt32 matchFinderCycles = 16 + numFastBytes / 2;\r\n    bool matchFinderCyclesDefined = false;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    if(parser[NKey::kMode].ThereIs)\r\n      if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))\r\n        IncorrectCommand();\r\n\r\n    if(parser[NKey::kFastBytes].ThereIs)\r\n      if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))\r\n        IncorrectCommand();\r\n    if (matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs)\r\n      if (!GetNumber(parser[NKey::kMatchFinderCycles].PostStrings[0], matchFinderCycles))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitContext].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitPos].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kPosBits].ThereIs)\r\n      if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))\r\n        IncorrectCommand();\r\n\r\n    PROPID propIDs[] = \r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker,\r\n      NCoderPropID::kMatchFinderCycles\r\n    };\r\n    const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\r\n    /*\r\n    NWindows::NCOM::CPropVariant properties[kNumProps];\r\n    properties[0] = UInt32(dictionary);\r\n    properties[1] = UInt32(posStateBits);\r\n    properties[2] = UInt32(litContextBits);\r\n   \r\n    properties[3] = UInt32(litPosBits);\r\n    properties[4] = UInt32(algorithm);\r\n    properties[5] = UInt32(numFastBytes);\r\n    properties[6] = mf;\r\n    properties[7] = eos;\r\n    */\r\n    PROPVARIANT properties[kNumPropsMax];\r\n    for (int p = 0; p < 6; p++)\r\n      properties[p].vt = VT_UI4;\r\n\r\n    properties[0].ulVal = UInt32(dictionary);\r\n    properties[1].ulVal = UInt32(posStateBits);\r\n    properties[2].ulVal = UInt32(litContextBits);\r\n    properties[3].ulVal = UInt32(litPosBits);\r\n    properties[4].ulVal = UInt32(algorithm);\r\n    properties[5].ulVal = UInt32(numFastBytes);\r\n\r\n    properties[8].vt = VT_UI4;\r\n    properties[8].ulVal = UInt32(matchFinderCycles);\r\n    \r\n    properties[6].vt = VT_BSTR;\r\n    properties[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    properties[7].vt = VT_BOOL;\r\n    properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    int numProps = kNumPropsMax;\r\n    if (!matchFinderCyclesDefined)\r\n      numProps--;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }   \r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }   \r\n  }\r\n  else\r\n  {\r\n    NCompress::NLZMA::CDecoder *decoderSpec = \r\n        new NCompress::NLZMA::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte properties[kPropertiesSize];\r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, properties, kPropertiesSize, &processedSize) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (processedSize != kPropertiesSize)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b;\r\n      if (inStream->Read(&b, 1, &processedSize) != S_OK)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      if (processedSize != 1)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      fileSize |= ((UInt64)b) << (8 * i);\r\n    }\r\n    if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }   \r\n  }\r\n  return 0;\r\n}\r\n\r\nint main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s) \r\n  { \r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1; \r\n  }\r\n  catch(...) \r\n  { \r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1; \r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#include <time.h>\r\n#endif\r\n\r\n#include \"../../../Common/CRC.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\nstatic const UInt32 kAdditionalSize = \r\n#ifdef _WIN32_WCE\r\n(1 << 20);\r\n#else\r\n(6 << 20);\r\n#endif\r\n\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 10;\r\n\r\nclass CRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd() \r\n  {\r\n    return \r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBitRandomGenerator\r\n{\r\n  CRandomGenerator RG;\r\n  UInt32 Value;\r\n  int NumBits;\r\npublic:\r\n  void Init()\r\n  {\r\n    Value = 0;\r\n    NumBits = 0;\r\n  }\r\n  UInt32 GetRnd(int numBits) \r\n  {\r\n    if (NumBits > numBits)\r\n    {\r\n      UInt32 result = Value & ((1 << numBits) - 1);\r\n      Value >>= numBits;\r\n      NumBits -= numBits;\r\n      return result;\r\n    }\r\n    numBits -= NumBits;\r\n    UInt32 result = (Value << numBits);\r\n    Value = RG.GetRnd();\r\n    result |= Value & ((1 << numBits) - 1);\r\n    Value >>= numBits;\r\n    NumBits = 32 - numBits;\r\n    return result;\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator\r\n{\r\n  CBitRandomGenerator RG;\r\n  UInt32 Pos;\r\n  UInt32 Rep0;\r\npublic:\r\n  UInt32 BufferSize;\r\n  Byte *Buffer;\r\n  CBenchRandomGenerator(): Buffer(0) {} \r\n  ~CBenchRandomGenerator() { Free(); }\r\n  void Free() \r\n  { \r\n    ::MidFree(Buffer);\r\n    Buffer = 0;\r\n  }\r\n  bool Alloc(UInt32 bufferSize) \r\n  {\r\n    if (Buffer != 0 && BufferSize == bufferSize)\r\n      return true;\r\n    Free();\r\n    Buffer = (Byte *)::MidAlloc(bufferSize);\r\n    Pos = 0;\r\n    BufferSize = bufferSize;\r\n    return (Buffer != 0);\r\n  }\r\n  UInt32 GetRndBit() { return RG.GetRnd(1); }\r\n  /*\r\n  UInt32 GetLogRand(int maxLen)\r\n  {\r\n    UInt32 len = GetRnd() % (maxLen + 1);\r\n    return GetRnd() & ((1 << len) - 1);\r\n  }\r\n  */\r\n  UInt32 GetLogRandBits(int numBits)\r\n  {\r\n    UInt32 len = RG.GetRnd(numBits);\r\n    return RG.GetRnd(len);\r\n  }\r\n  UInt32 GetOffset()\r\n  {\r\n    if (GetRndBit() == 0)\r\n      return GetLogRandBits(4);\r\n    return (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n  }\r\n  UInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n  UInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n  void Generate()\r\n  {\r\n    RG.Init(); \r\n    Rep0 = 1;\r\n    while(Pos < BufferSize)\r\n    {\r\n      if (GetRndBit() == 0 || Pos < 1)\r\n        Buffer[Pos++] = (Byte)RG.GetRnd(8);\r\n      else\r\n      {\r\n        UInt32 len;\r\n        if (RG.GetRnd(3) == 0)\r\n          len = 1 + GetLen1();\r\n        else\r\n        {\r\n          do\r\n            Rep0 = GetOffset();\r\n          while (Rep0 >= Pos);\r\n          Rep0++;\r\n          len = 2 + GetLen2();\r\n        }\r\n        for (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n          Buffer[Pos] = Buffer[Pos - Rep0];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nclass CBenchmarkInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  UInt32 Pos;\r\n  UInt32 Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, UInt32 size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 remain = Size - Pos;\r\n  if (size > remain)\r\n    size = remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 BufferSize;\r\n  FILE *_f;\r\npublic:\r\n  UInt32 Pos;\r\n  Byte *Buffer;\r\n  CBenchmarkOutStream(): _f(0), Buffer(0) {} \r\n  virtual ~CBenchmarkOutStream() { delete []Buffer; }\r\n  void Init(FILE *f, UInt32 bufferSize) \r\n  {\r\n    delete []Buffer;\r\n    Buffer = 0;\r\n    Buffer = new Byte[bufferSize];\r\n    Pos = 0;\r\n    BufferSize = bufferSize;\r\n    _f = f;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < BufferSize; i++)\r\n    Buffer[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    fprintf(_f, \"\\nERROR: Buffer is full\\n\");\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CCRC CRC;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { CRC.Init(); }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  CRC.Update(data, size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef _WIN32\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  return GetTickCount();\r\n  #else\r\n  return clock();\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef _WIN32\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  return 1000;\r\n  #else\r\n  return CLOCKS_PER_SEC;\r\n  #endif \r\n}\r\n\r\nstruct CProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 ApprovedStart;\r\n  UInt64 InSize;\r\n  UInt64 Time;\r\n  void Init()\r\n  {\r\n    InSize = 0;\r\n    Time = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nSTDMETHODIMP CProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  if (*inSize >= ApprovedStart && InSize == 0)\r\n  {\r\n    Time = ::GetTimeCount();\r\n    InSize = *inSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n{\r\n  UInt64 freq = GetFreq();\r\n  UInt64 elTime = elapsedTime;\r\n  while(freq > 1000000)\r\n  {\r\n    freq >>= 1;\r\n    elTime >>= 1;\r\n  }\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)\r\n{\r\n  UInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n  UInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime);\r\n}\r\n\r\nstatic UInt64 GetDecompressRating(UInt64 elapsedTime, \r\n    UInt64 outSize, UInt64 inSize)\r\n{\r\n  UInt64 numCommands = inSize * 220 + outSize * 20;\r\n  return MyMultDiv64(numCommands, elapsedTime);\r\n}\r\n\r\n/*\r\nstatic UInt64 GetTotalRating(\r\n    UInt32 dictionarySize, \r\n    bool isBT4,\r\n    UInt64 elapsedTimeEn, UInt64 sizeEn,\r\n    UInt64 elapsedTimeDe, \r\n    UInt64 inSizeDe, UInt64 outSizeDe)\r\n{\r\n  return (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) + \r\n    GetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n}\r\n*/\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  fprintf(f, \"%5d MIPS\", (unsigned int)(rating / 1000000));\r\n}\r\n\r\nstatic void PrintResults(\r\n    FILE *f, \r\n    UInt32 dictionarySize,\r\n    UInt64 elapsedTime, \r\n    UInt64 size, \r\n    bool decompressMode, UInt64 secondSize)\r\n{\r\n  UInt64 speed = MyMultDiv64(size, elapsedTime);\r\n  fprintf(f, \"%6d KB/s  \", (unsigned int)(speed / 1024));\r\n  UInt64 rating;\r\n  if (decompressMode)\r\n    rating = GetDecompressRating(elapsedTime, size, secondSize);\r\n  else\r\n    rating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n  PrintRating(f, rating);\r\n}\r\n\r\nstatic void ThrowError(FILE *f, HRESULT result, const char *s)\r\n{\r\n  fprintf(f, \"\\nError: \");\r\n  if (result == E_ABORT)\r\n    fprintf(f, \"User break\");\r\n  if (result == E_OUTOFMEMORY)\r\n    fprintf(f, \"Can not allocate memory\");\r\n  else\r\n    fprintf(f, s);\r\n  fprintf(f, \"\\n\");\r\n}\r\n\r\nconst wchar_t *bt2 = L\"BT2\";\r\nconst wchar_t *bt4 = L\"BT4\";\r\n\r\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize)\r\n{\r\n  if (numIterations == 0)\r\n    return 0;\r\n  if (dictionarySize < (1 << 18))\r\n  {\r\n    fprintf(f, \"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\\n\");\r\n    return 1;\r\n  }\r\n  fprintf(f, \"\\n       Compressing                Decompressing\\n\\n\");\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;\r\n  CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n\r\n  CBenchmarkOutStream *propStreamSpec = new CBenchmarkOutStream;\r\n  CMyComPtr<ISequentialOutStream> propStream = propStreamSpec;\r\n  propStreamSpec->Init(f, kMaxLzmaPropSize);\r\n  \r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kDictionarySize\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = UInt32(dictionarySize);\r\n\r\n  const UInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n  {\r\n    fprintf(f, \"\\nError: Incorrect command\\n\");\r\n    return 1;\r\n  }\r\n  encoderSpec->WriteCoderProperties(propStream);\r\n\r\n  CBenchRandomGenerator rg;\r\n  if (!rg.Alloc(kBufferSize))\r\n  {\r\n    fprintf(f, \"\\nError: Can't allocate memory\\n\");\r\n    return 1;\r\n  }\r\n\r\n  rg.Generate();\r\n  CCRC crc;\r\n  crc.Update(rg.Buffer, rg.BufferSize);\r\n\r\n  CProgressInfo *progressInfoSpec = new CProgressInfo;\r\n  CMyComPtr<ICompressProgressInfo> progressInfo = progressInfoSpec;\r\n\r\n  progressInfoSpec->ApprovedStart = dictionarySize;\r\n\r\n  UInt64 totalBenchSize = 0;\r\n  UInt64 totalEncodeTime = 0;\r\n  UInt64 totalDecodeTime = 0;\r\n  UInt64 totalCompressedSize = 0;\r\n\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    progressInfoSpec->Init();\r\n    CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n    inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n    CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n    CBenchmarkOutStream *outStreamSpec = new CBenchmarkOutStream;\r\n    outStreamSpec->Init(f, kCompressedBufferSize);\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, progressInfo);\r\n    UInt64 encodeTime = ::GetTimeCount() - progressInfoSpec->Time;\r\n    UInt32 compressedSize = outStreamSpec->Pos;\r\n    if(result != S_OK)\r\n    {\r\n      ThrowError(f, result, \"Encoder Error\");\r\n      return 1;\r\n    }\r\n    if (progressInfoSpec->InSize == 0)\r\n    {\r\n      fprintf(f, \"\\nError: Internal ERROR 1282\\n\");\r\n      return 1;\r\n    }\r\n  \r\n    ///////////////////////\r\n    // Decompressing\r\n  \r\n    CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n    CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n    UInt64 decodeTime;\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n      crcOutStreamSpec->Init();\r\n      \r\n      if (decoderSpec->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos) != S_OK)\r\n      {\r\n        fprintf(f, \"\\nError: Set Decoder Properties Error\\n\");\r\n        return 1;\r\n      }\r\n      UInt64 outSize = kBufferSize;\r\n      UInt64 startTime = ::GetTimeCount();\r\n      result = decoder->Code(inStream, crcOutStream, 0, &outSize, 0);\r\n      decodeTime = ::GetTimeCount() - startTime;\r\n      if(result != S_OK)\r\n      {\r\n        ThrowError(f, result, \"Decode Error\");\r\n        return 1;\r\n      }\r\n      if (crcOutStreamSpec->CRC.GetDigest() != crc.GetDigest())\r\n      {\r\n        fprintf(f, \"\\nError: CRC Error\\n\");\r\n        return 1;\r\n      }\r\n    }\r\n    UInt64 benchSize = kBufferSize - progressInfoSpec->InSize;\r\n    PrintResults(f, dictionarySize, encodeTime, benchSize, false, 0);\r\n    fprintf(f, \"     \");\r\n    PrintResults(f, dictionarySize, decodeTime, kBufferSize, true, compressedSize);\r\n    fprintf(f, \"\\n\");\r\n\r\n    totalBenchSize += benchSize;\r\n    totalEncodeTime += encodeTime;\r\n    totalDecodeTime += decodeTime;\r\n    totalCompressedSize += compressedSize;\r\n  }\r\n  fprintf(f, \"---------------------------------------------------\\n\");\r\n  PrintResults(f, dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n  fprintf(f, \"     \");\r\n  PrintResults(f, dictionarySize, totalDecodeTime, \r\n      kBufferSize * numIterations, true, totalCompressedSize);\r\n  fprintf(f, \"    Average\\n\");\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LzmaBench_h\r\n#define __LzmaBench_h\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/LzmaRam.cpp",
    "content": "// LzmaRam.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../Branch/BranchX86.h\"\r\n}\r\n\r\nclass CInStreamRam: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Size;\r\n  size_t Pos;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 remain = Size - Pos;\r\n  if (size > remain)\r\n    size = remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass COutStreamRam: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  size_t Size;\r\npublic:\r\n  Byte *Data;\r\n  size_t Pos;\r\n  bool Overflow;\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n    Overflow = false;\r\n  }\r\n  void SetPos(size_t pos)\r\n  {\r\n    Overflow = false;\r\n    Pos = pos;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  HRESULT WriteByte(Byte b)\r\n  {\r\n    if (Pos >= Size)\r\n    {\r\n      Overflow = true;\r\n      return E_FAIL;\r\n    }\r\n    Data[Pos++] = b;\r\n    return S_OK;\r\n  }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < Size; i++)\r\n    Data[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    Overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\n#define SZE_FAIL (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_OUT_OVERFLOW (3)\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try { \r\n  #endif\r\n\r\n  *outSizeProcessed = 0;\r\n  const size_t kIdSize = 1;\r\n  const size_t kLzmaPropsSize = 5;\r\n  const size_t kMinDestSize = kIdSize + kLzmaPropsSize + 8;\r\n  if (outSize < kMinDestSize)\r\n    return SZE_OUT_OVERFLOW;\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kAlgorithm,\r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kNumFastBytes,\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[1].vt = VT_UI4;\r\n  properties[2].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)2;\r\n  properties[1].ulVal = (UInt32)dictionarySize;\r\n  properties[2].ulVal = (UInt32)64;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n    return 1;\r\n  \r\n  COutStreamRam *outStreamSpec = new COutStreamRam;\r\n  if (outStreamSpec == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n  CInStreamRam *inStreamSpec = new CInStreamRam;\r\n  if (inStreamSpec == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\r\n  outStreamSpec->Init(outBuffer, outSize);\r\n  if (outStreamSpec->WriteByte(0) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n\r\n  if (encoderSpec->WriteCoderProperties(outStream) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n  if (outStreamSpec->Pos != kIdSize + kLzmaPropsSize)\r\n    return 1;\r\n  \r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    UInt64 t = (UInt64)(inSize);\r\n    if (outStreamSpec->WriteByte((Byte)((t) >> (8 * i))) != S_OK)\r\n      return SZE_OUT_OVERFLOW;\r\n  }\r\n\r\n  Byte *filteredStream = 0;\r\n\r\n  bool useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (inSize != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(inSize);\r\n      if (filteredStream == 0)\r\n        return SZE_OUTOFMEMORY;\r\n      memmove(filteredStream, inBuffer, inSize);\r\n    }\r\n    UInt32 _prevMask;\r\n    UInt32 _prevPos;\r\n    x86_Convert_Init(_prevMask, _prevPos);\r\n    x86_Convert(filteredStream, (UInt32)inSize, 0, &_prevMask, &_prevPos, 1);\r\n  }\r\n  \r\n  UInt32 minSize = 0;\r\n  int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n  bool bestIsFiltered = false;\r\n  int mainResult = 0;\r\n  size_t startPos = outStreamSpec->Pos;\r\n  for (i = 0; i < numPasses; i++)\r\n  {\r\n    if (numPasses > 1 && i == numPasses - 1 && !bestIsFiltered)\r\n      break;\r\n    outStreamSpec->SetPos(startPos);\r\n    bool curModeIsFiltered = false;\r\n    if (useFilter && i == 0)\r\n      curModeIsFiltered = true;\r\n    if (numPasses > 1 && i == numPasses - 1)\r\n      curModeIsFiltered = true;\r\n\r\n    inStreamSpec->Init(curModeIsFiltered ? filteredStream : inBuffer, inSize);\r\n    \r\n    HRESULT lzmaResult = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    \r\n    mainResult = 0;\r\n    if (lzmaResult == E_OUTOFMEMORY)\r\n    {\r\n      mainResult = SZE_OUTOFMEMORY;\r\n      break;\r\n    } \r\n    if (i == 0 || outStreamSpec->Pos <= minSize)\r\n    {\r\n      minSize = outStreamSpec->Pos;\r\n      bestIsFiltered = curModeIsFiltered;\r\n    }\r\n    if (outStreamSpec->Overflow)\r\n      mainResult = SZE_OUT_OVERFLOW;\r\n    else if (lzmaResult != S_OK)\r\n    {\r\n      mainResult = SZE_FAIL;\r\n      break;\r\n    } \r\n  }\r\n  *outSizeProcessed = outStreamSpec->Pos;\r\n  if (bestIsFiltered)\r\n    outBuffer[0] = 1;\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n  \r\n  #ifndef _NO_EXCEPTIONS\r\n  } catch(...) { return SZE_OUTOFMEMORY; }\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/LzmaRam.h",
    "content": "// LzmaRam.h\r\n\r\n#ifndef __LzmaRam_h\r\n#define __LzmaRam_h\r\n\r\n#include <stdlib.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\n/*\r\nLzmaRamEncode: BCJ + LZMA RAM->RAM compressing.\r\nIt uses .lzma format, but it writes one additional byte to .lzma file:\r\n  0: - no filter\r\n  1: - x86(BCJ) filter.\r\n\r\nTo provide best compression ratio dictionarySize mustbe >= inSize\r\n\r\nLzmaRamEncode allocates Data with MyAlloc/BigAlloc functions.\r\nRAM Requirements:\r\n  RamSize = dictionarySize * 9.5 + 6MB + FilterBlockSize \r\n    FilterBlockSize = 0, if useFilter == false\r\n    FilterBlockSize = inSize, if useFilter == true\r\n\r\n  Return code:\r\n    0 - OK\r\n    1 - Unspecified Error\r\n    2 - Memory allocating error\r\n    3 - Output buffer OVERFLOW\r\n\r\nIf you use SZ_FILTER_AUTO mode, then encoder will use 2 or 3 passes:\r\n  2 passes when FILTER_NO provides better compression.\r\n  3 passes when FILTER_YES provides better compression.\r\n*/\r\n\r\nenum ESzFilterMode \r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.c",
    "content": "/* LzmaRamDecode.c */\r\n\r\n#include \"LzmaRamDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#include \"BranchX86.h\"\r\n#else\r\n#include \"../LZMA_C/LzmaDecode.h\"\r\n#include \"../Branch/BranchX86.h\"\r\n#endif\r\n\r\n#define LZMA_PROPS_SIZE 14\r\n#define LZMA_SIZE_OFFSET 6\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize, \r\n    size_t *outSize)\r\n{\r\n  unsigned int i;\r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  *outSize = 0;\r\n  for(i = 0; i < sizeof(size_t); i++)\r\n    *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);\r\n  for(; i < 8; i++)\r\n    if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)\r\n      return 1;\r\n  return 0;\r\n}\r\n\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *))\r\n{\r\n  CLzmaDecoderState state;  /* it's about 24 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  SizeT inProcessed;\r\n  int useFilter;\r\n  \r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  useFilter = inBuffer[0];\r\n\r\n  *outSizeProcessed = 0;\r\n  if (useFilter > 1)\r\n    return 1;\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return 1;\r\n  state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  result = LzmaDecode(&state,\r\n    inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed,\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  freeFunc(state.Probs);\r\n  if (result != LZMA_RESULT_OK)\r\n    return 1;\r\n  *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 _prevMask;\r\n    UInt32 _prevPos;\r\n    x86_Convert_Init(_prevMask, _prevPos);\r\n    x86_Convert(outBuffer, (UInt32)outSizeProcessedLoc, 0, &_prevMask, &_prevPos, 0);\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.h",
    "content": "/* LzmaRamDecode.h */\r\n\r\n#ifndef __LzmaRamDecode_h\r\n#define __LzmaRamDecode_h\r\n\r\n#include <stdlib.h>\r\n\r\n/*\r\nLzmaRamGetUncompressedSize:\r\n  In: \r\n    inBuffer - input data\r\n    inSize   - input data size\r\n  Out: \r\n    outSize  - uncompressed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers\r\n*/\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    size_t *outSize);\r\n\r\n\r\n/*\r\nLzmaRamDecompress:\r\n  In: \r\n    inBuffer  - input data\r\n    inSize    - input data size\r\n    outBuffer - output data\r\n    outSize   - output size\r\n    allocFunc - alloc function (can be malloc)\r\n    freeFunc  - free function (can be free)\r\n  Out: \r\n    outSizeProcessed - processed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers / data stream\r\n    2 - Memory allocating error\r\n\r\nMemory requirements depend from properties of LZMA stream.\r\nWith default lzma settings it's about 16 KB.\r\n*/\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/comp.cc",
    "content": "/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: comp.cc,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $ */\n\n// extract some parts from lzma443/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <assert.h>\n#include <errno.h>\n\n#include \"StdAfx.h\"\n#include \"../../../Common/MyInitGuid.h\"\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/StringConvert.h\"\n#include \"../LZMA/LZMAEncoder.h\"\n\n#include <pthread.h>\n#include <zlib.h>\n#include \"sqlzma.h\"\n\n//////////////////////////////////////////////////////////////////////\n\nclass CMemoryStream {\nprotected:\n\tBytef *m_data;\n\tUInt64 m_limit;\n\tUInt64 m_pos;\n\npublic:\n\tCMemoryStream(Bytef *data, UInt64 size)\n\t\t: m_data(data), m_limit(size), m_pos(0) {}\n\n\tvirtual ~CMemoryStream() {}\n};\n\nclass CInMemoryStream : public CMemoryStream, public IInStream,\n\t\t\tpublic CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialInStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IInStream);\n\n\tCInMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~CInMemoryStream() {}\n\n\tSTDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\n\t{\n\t\tUInt64 room = m_limit - m_pos;\n\t\tif (size > room)\n\t\t\tsize = room;\n\t\tif (size) {\n\t\t\tmemcpy(data, m_data + m_pos, size);\n\t\t\tm_pos += size;\n\t\t}\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\nclass COutMemoryStream : public CMemoryStream, public IOutStream,\n\t\t\t public CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialOutStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IOutStream);\n\n\tCOutMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~COutMemoryStream() {}\n\n\tUInt32 GetSize() {return m_pos;}\n\n\tSTDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) {\n\t\tif (m_pos + size > m_limit)\n\t\t\treturn -ENOSPC;\n\t\tmemcpy(m_data + m_pos, data, size);\n\t\tm_pos += size;\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n\tSTDMETHOD(SetSize)(Int64 newSize) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\n//////////////////////////////////////////////////////////////////////\n\nstatic int\nLzmaCompress(Bytef *next_in, uInt avail_in, Bytef *next_out, uInt avail_out,\n\t     uLong *total_out)\n{\n\tint err;\n\tHRESULT res;\n\tconst Byte a[] = {\n\t\tavail_in, avail_in >> 8, avail_in >> 16, avail_in >> 24,\n\t\t0, 0, 0, 0\n\t};\n\n\tNCompress::NLZMA::CEncoder encoderSpec;\n\tCMyComPtr<ICompressCoder> encoder = &encoderSpec;\n\tencoder->AddRef();\n\tCInMemoryStream inStreamSpec(next_in, avail_in);\n\tCMyComPtr<ISequentialInStream> inStream = &inStreamSpec;\n\tinStream->AddRef();\n\tCOutMemoryStream outStreamSpec(next_out, avail_out);\n\tCMyComPtr<ISequentialOutStream> outStream = &outStreamSpec;\n\toutStream->AddRef();\n\n\t// these values are dpending upon is_lzma() macro in sqlzma.h\n\tconst UInt32 dictionary = 1 << 23;\n\tconst UString mf = L\"BT4\";\n\tconst UInt32 posStateBits = 2;\n\tconst UInt32 litContextBits = 3; // for normal files\n\t// UInt32 litContextBits = 0; // for 32-bit data\n\tconst UInt32 litPosBits = 0;\n\t// UInt32 litPosBits = 2; // for 32-bit data\n\tconst UInt32 algorithm = 2;\n\tconst UInt32 numFastBytes = 128;\n\tconst UInt32 matchFinderCycles = 16 + numFastBytes / 2;\n\t//const bool matchFinderCyclesDefined = false;\n\tconst PROPID propIDs[] = {\n\t\tNCoderPropID::kDictionarySize,\n\t\tNCoderPropID::kPosStateBits,\n\t\tNCoderPropID::kLitContextBits,\n\t\tNCoderPropID::kLitPosBits,\n\t\tNCoderPropID::kAlgorithm,\n\t\tNCoderPropID::kNumFastBytes,\n\t\tNCoderPropID::kMatchFinder,\n\t\tNCoderPropID::kEndMarker,\n\t\tNCoderPropID::kMatchFinderCycles\n\t};\n\tconst int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\n\tPROPVARIANT properties[kNumPropsMax];\n\tfor (int p = 0; p < 6; p++)\n\t\tproperties[p].vt = VT_UI4;\n\tproperties[0].ulVal = UInt32(dictionary);\n\tproperties[1].ulVal = UInt32(posStateBits);\n\tproperties[2].ulVal = UInt32(litContextBits);\n\tproperties[3].ulVal = UInt32(litPosBits);\n\tproperties[4].ulVal = UInt32(algorithm);\n\tproperties[5].ulVal = UInt32(numFastBytes);\n\n\tproperties[6].vt = VT_BSTR;\n\tproperties[6].bstrVal = (BSTR)(const wchar_t *)mf;\n\tproperties[7].vt = VT_BOOL;\n\tproperties[7].boolVal = VARIANT_FALSE;\t// EOS\n\tproperties[8].vt = VT_UI4;\n\tproperties[8].ulVal = UInt32(matchFinderCycles);\n\n\terr = -EINVAL;\n\tres = encoderSpec.SetCoderProperties(propIDs, properties,\n\t\t\t\t\t     kNumPropsMax - 1);\n\tif (res)\n\t\tgoto out;\n\tres = encoderSpec.WriteCoderProperties(outStream);\n\tif (res)\n\t\tgoto out;\n\n\tUInt32 r;\n\tres = outStream->Write(a, sizeof(a), &r);\n\tif (res || r != sizeof(a))\n\t\tgoto out;\n\n\terr = encoder->Code(inStream, outStream, 0, /*broken*/0, 0);\n\tif (err)\n\t\tgoto out;\n\t*total_out = outStreamSpec.GetSize();\n\n out:\n\treturn err;\n}\n\n//////////////////////////////////////////////////////////////////////\n\n#define Failure(p) do { \\\n\tfprintf(stderr, \"%s:%d: please report to jro \" \\\n\t\t\"{%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x}\\n\", \\\n\t\t__func__, __LINE__, \\\n\t\tp[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); \\\n\tabort(); \\\n}while(0)\n\nextern \"C\" int\nsqlzma_cm(int try_lzma, z_stream *stream, Bytef *next_in, uInt avail_in,\n\t  Bytef *next_out, uInt avail_out)\n{\n\tint err;\n\tBytef *p = next_out;\n\tuInt l = avail_out;\n\n\tstream->next_in = next_in;\n\tstream->avail_in = avail_in;\n\tstream->next_out = p;\n\tstream->avail_out = l;\n\terr = deflate(stream, Z_FINISH);\n\tif (err != Z_STREAM_END && err != Z_OK)\n\t\tgoto out_err;\n\tif (avail_in < stream->total_out)\n\t\treturn err;\n\tif (is_lzma(*p))\n\t\tFailure(p);\n\n\tif (try_lzma) {\n\t\tunsigned char a[stream->total_out];\n\t\tuLong processed;\n\n\t\tmemcpy(a, p, stream->total_out);\n\n\t\t// malloc family in glibc and stdc++ seems to be thread-safe\n\t\terr = LzmaCompress(next_in, avail_in, p, l, &processed);\n\t\tif (!err && processed <= stream->total_out) {\n\t\t\tif (!is_lzma(*next_out))\n\t\t\t\tFailure(next_out);\n\t\t\tstream->total_out = processed;\n\t\t\terr = Z_STREAM_END;\n\t\t} else {\n\t\t\t//puts(\"by zlib\");\n\t\t\tmemcpy(p, a, stream->total_out);\n\t\t\terr = Z_STREAM_END;\n\t\t}\n\t}\n\treturn err;\n\n out_err:\n\tfprintf(stderr, \"%s: ZLIB err %s\\n\", __func__, zError(err));\n\treturn err;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nCFLAGS = $(CFLAGS) -I ../../../\r\nLIBS = $(LIBS) oleaut32.lib user32.lib\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaRam.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\String.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\Vector.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZInWindow.obj \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\n\r\nOBJS = \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $O\\LzmaRamDecode.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\LzmaRamDecode.obj: LzmaRamDecode.c\r\n\t$(COMPL_O1)\r\n$O\\LzmaDecode.obj: ../LZMA_C/LzmaDecode.c\r\n\t$(COMPL_O2)\r\n$O\\BranchX86.obj: ../Branch/BranchX86.c\r\n\t$(COMPL_O2)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c -I ../../../\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaRam.o \\\r\n  LzmaRamDecode.o \\\r\n  LzmaDecode.o \\\r\n  BranchX86.o \\\r\n  LZMADecoder.o \\\r\n  LZMAEncoder.o \\\r\n  LZInWindow.o \\\r\n  LZOutWindow.o \\\r\n  RangeCoderBit.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  Alloc.o \\\r\n  C_FileIO.o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  String.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  Vector.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaRam.o: LzmaRam.cpp\r\n\t$(CXX) $(CFLAGS) LzmaRam.cpp\r\n\r\nLzmaRamDecode.o: LzmaRamDecode.c\r\n\t$(CXX_C) $(CFLAGS) LzmaRamDecode.c\r\n\r\nLzmaDecode.o: ../LZMA_C/LzmaDecode.c\r\n\t$(CXX_C) $(CFLAGS) ../LZMA_C/LzmaDecode.c\r\n\r\nBranchX86.o: ../Branch/BranchX86.c\r\n\t$(CXX_C) $(CFLAGS) ../Branch/BranchX86.c\r\n\r\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\r\n\r\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\r\n\r\nLZInWindow.o: ../LZ/LZInWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp\r\n\r\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\r\n\r\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\r\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\nAlloc.o: ../../../Common/Alloc.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/Alloc.cpp\r\n\r\nC_FileIO.o: ../../../Common/C_FileIO.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nString.o: ../../../Common/String.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/String.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nVector.o: ../../../Common/Vector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/Vector.cpp\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_Alone/sqlzma.mk",
    "content": "\n# Copyright (C) 2006 Junjiro Okajima\n# Copyright (C) 2006 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\ninclude makefile.gcc\n\nifdef UseDebugFlags\nDebugFlags = -Wall -O0 -g -UNDEBUG\nendif\n# -pthread\nCXXFLAGS = ${CFLAGS} -D_REENTRANT -include pthread.h -DNDEBUG ${DebugFlags}\nTgt = liblzma_r.a\n\nall: ${Tgt}\n\nRObjs = LZMAEncoder_r.o Alloc_r.o LZInWindow_r.o CRC_r.o StreamUtils_r.o \\\n\tOutBuffer_r.o RangeCoderBit_r.o\n%_r.cc: ../LZMA/%.cpp\n\tln $< $@\n%_r.cc: ../LZ/%.cpp\n\tln $< $@\n%_r.cc: ../RangeCoder/%.cpp\n\tln $< $@\n%_r.cc: ../../Common/%.cpp\n\tln $< $@\n%_r.cc: ../../../Common/%.cpp\n\tln $< $@\nLZMAEncoder_r.o: CXXFLAGS += -I../LZMA\nLZInWindow_r.o: CXXFLAGS += -I../LZ\nRangeCoderBit_r.o: CXXFLAGS += -I../RangeCoder\nOutBuffer_r.o StreamUtils_r.o: CXXFLAGS += -I../../Common\nAlloc_r.o CRC_r.o: CXXFLAGS += -I../../../Common\n\ncomp.o: CXXFLAGS += -I${Sqlzma}\ncomp.o: comp.cc ${Sqlzma}/sqlzma.h\n\nliblzma_r.a: ${RObjs} comp.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) comp.o *_r.o ${Tgt} *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/LzmaDecode.c",
    "content": "/*\r\n  LzmaDecode.c\r\n  LZMA Decoder (optimized for Speed version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) \\\r\n  { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \\\r\n  BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}\r\n\r\n#define RC_INIT Buffer = BufferLim = 0; RC_INIT2\r\n\r\n#else\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#endif\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  const Byte *Buffer = vs->Buffer;\r\n  const Byte *BufferLim = vs->BufferLim;\r\n  #else\r\n  const Byte *Buffer = inStream;\r\n  const Byte *BufferLim = inStream + inSize;\r\n  #endif\r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      #ifdef _LZMA_IN_CB\r\n      RC_INIT;\r\n      #else\r\n      RC_INIT(inStream, inSize);\r\n      #endif\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  RC_INIT;\r\n  #else\r\n  RC_INIT(inStream, inSize);\r\n  #endif\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (Byte)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n            UpdateBit0(prob);\r\n            \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            \r\n            state = state < kNumLitStates ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = Buffer;\r\n  vs->BufferLim = BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/LzmaDecode.h",
    "content": "/* \r\n  LzmaDecode.h\r\n  LZMA Decoder interface\r\n\r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMADECODE_H\r\n#define __LZMADECODE_H\r\n\r\n#include \"LzmaTypes.h\"\r\n\r\n/* #define _LZMA_IN_CB */\r\n/* Use callback for input data */\r\n\r\n/* #define _LZMA_OUT_READ */\r\n/* Use read function for output data */\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_LOC_OPT */\r\n/* Enable local speed optimizations inside code */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#ifdef _LZMA_IN_CB\r\ntypedef struct _ILzmaInCallback\r\n{\r\n  int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);\r\n} ILzmaInCallback;\r\n#endif\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  #ifdef _LZMA_OUT_READ\r\n  UInt32 DictionarySize;\r\n  #endif\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  const unsigned char *Buffer;\r\n  const unsigned char *BufferLim;\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  unsigned char *Dictionary;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;\r\n  unsigned char TempDictionary[4];\r\n  #endif\r\n} CLzmaDecoderState;\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }\r\n#endif\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *inCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/LzmaDecodeSize.c",
    "content": "/*\r\n  LzmaDecodeSize.c\r\n  LZMA Decoder (optimized for Size version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\ntypedef struct _CRangeDecoder\r\n{\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  #ifdef _LZMA_IN_CB\r\n  ILzmaInCallback *InCallback;\r\n  int Result;\r\n  #endif\r\n  int ExtraBytes;\r\n} CRangeDecoder;\r\n\r\nByte RangeDecoderReadByte(CRangeDecoder *rd)\r\n{\r\n  if (rd->Buffer == rd->BufferLim)\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    SizeT size;\r\n    rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);\r\n    rd->BufferLim = rd->Buffer + size;\r\n    if (size == 0)\r\n    #endif\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n  }\r\n  return (*rd->Buffer++);\r\n}\r\n\r\n/* #define ReadByte (*rd->Buffer++) */\r\n#define ReadByte (RangeDecoderReadByte(rd))\r\n\r\nvoid RangeDecoderInit(CRangeDecoder *rd\r\n  #ifndef _LZMA_IN_CB\r\n    , const Byte *stream, SizeT bufferSize\r\n  #endif\r\n    )\r\n{\r\n  int i;\r\n  #ifdef _LZMA_IN_CB\r\n  rd->Buffer = rd->BufferLim = 0;\r\n  #else\r\n  rd->Buffer = stream;\r\n  rd->BufferLim = stream + bufferSize;\r\n  #endif\r\n  rd->ExtraBytes = 0;\r\n  rd->Code = 0;\r\n  rd->Range = (0xFFFFFFFF);\r\n  for(i = 0; i < 5; i++)\r\n    rd->Code = (rd->Code << 8) | ReadByte;\r\n}\r\n\r\n#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;        \r\n#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;\r\n#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }\r\n\r\nUInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)\r\n{\r\n  RC_INIT_VAR\r\n  UInt32 result = 0;\r\n  int i;\r\n  for (i = numTotalBits; i != 0; i--)\r\n  {\r\n    /* UInt32 t; */\r\n    range >>= 1;\r\n\r\n    result <<= 1;\r\n    if (code >= range)\r\n    {\r\n      code -= range;\r\n      result |= 1;\r\n    }\r\n    /*\r\n    t = (code - range) >> 31;\r\n    t &= 1;\r\n    code -= range & (t - 1);\r\n    result = (result + result) | (1 - t);\r\n    */\r\n    RC_NORMALIZE\r\n  }\r\n  RC_FLUSH_VAR\r\n  return result;\r\n}\r\n\r\nint RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)\r\n{\r\n  UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;\r\n  if (rd->Code < bound)\r\n  {\r\n    rd->Range = bound;\r\n    *prob += (kBitModelTotal - *prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 0;\r\n  }\r\n  else\r\n  {\r\n    rd->Range -= bound;\r\n    rd->Code -= bound;\r\n    *prob -= (*prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 1;\r\n  }\r\n}\r\n\r\n#define RC_GET_BIT2(prob, mi, A0, A1) \\\r\n  UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \\\r\n  if (code < bound) \\\r\n    { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \\\r\n  else \\\r\n    { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)               \r\n\r\nint RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = numLevels; i != 0; i--)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT(prob, mi)\r\n    #else\r\n    mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return mi - (1 << numLevels);\r\n}\r\n\r\nint RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  int symbol = 0;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = 0; i < numLevels; i++)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))\r\n    #else\r\n    int bit = RangeDecoderBitDecode(probs + mi, rd);\r\n    mi = mi + mi + bit;\r\n    symbol |= (bit << i);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + symbol;\r\n    RC_GET_BIT(prob, symbol)\r\n    #else\r\n    symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n    #endif\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    int bit;\r\n    int matchBit = (matchByte >> 7) & 1;\r\n    matchByte <<= 1;\r\n    #ifdef _LZMA_LOC_OPT\r\n    {\r\n      CProb *prob = probs + 0x100 + (matchBit << 8) + symbol;\r\n      RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)\r\n    }\r\n    #else\r\n    bit = RangeDecoderBitDecode(probs + 0x100 + (matchBit << 8) + symbol, rd);\r\n    symbol = (symbol << 1) | bit;\r\n    #endif\r\n    if (matchBit != bit)\r\n    {\r\n      while (symbol < 0x100)\r\n      {\r\n        #ifdef _LZMA_LOC_OPT\r\n        CProb *prob = probs + symbol;\r\n        RC_GET_BIT(prob, symbol)\r\n        #else\r\n        symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n        #endif\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\nint LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)\r\n{\r\n  if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)\r\n    return RangeDecoderBitTreeDecode(p + LenLow +\r\n        (posState << kLenNumLowBits), kLenNumLowBits, rd);\r\n  if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)\r\n    return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +\r\n        (posState << kLenNumMidBits), kLenNumMidBits, rd);\r\n  return kLenNumLowSymbols + kLenNumMidSymbols + \r\n      RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);\r\n}\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  CRangeDecoder rd;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  rd.Range = vs->Range;\r\n  rd.Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  rd.Buffer = vs->Buffer;\r\n  rd.BufferLim = vs->BufferLim;\r\n  #else\r\n  rd.Buffer = inStream;\r\n  rd.BufferLim = inStream + inSize;\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RangeDecoderInit(&rd\r\n          #ifndef _LZMA_IN_CB\r\n          , inStream, inSize\r\n          #endif\r\n          );\r\n      #ifdef _LZMA_IN_CB\r\n      if (rd.Result != LZMA_RESULT_OK)\r\n        return rd.Result;\r\n      #endif\r\n      if (rd.ExtraBytes != 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  rd.Result = LZMA_RESULT_OK;\r\n  #endif\r\n  rd.ExtraBytes = 0;\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  #endif\r\n  RangeDecoderInit(&rd\r\n      #ifndef _LZMA_IN_CB\r\n      , inStream, inSize\r\n      #endif\r\n      );\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  if (rd.Result != LZMA_RESULT_OK)\r\n    return rd.Result;\r\n  #endif\r\n  if (rd.ExtraBytes != 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n    #ifdef _LZMA_IN_CB\r\n    if (rd.Result != LZMA_RESULT_OK)\r\n      return rd.Result;\r\n    #endif\r\n    if (rd.ExtraBytes != 0)\r\n      return LZMA_RESULT_DATA_ERROR;\r\n    if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n    {\r\n      CProb *probs = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        Byte matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);\r\n      }\r\n      else\r\n        previousByte = LzmaLiteralDecode(probs, &rd);\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)\r\n      {\r\n        if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)\r\n        {\r\n          if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n      \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n\r\n            state = state < 7 ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n            continue;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)\r\n            distance = rep1;\r\n          else \r\n          {\r\n            if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)\r\n              distance = rep2;\r\n            else\r\n            {\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        len = LzmaLenDecode(p + RepLenCoder, &rd, posState);\r\n        state = state < 7 ? 8 : 11;\r\n      }\r\n      else\r\n      {\r\n        int posSlot;\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < 7 ? 7 : 10;\r\n        len = LzmaLenDecode(p + LenCoder, &rd, posState);\r\n        posSlot = RangeDecoderBitTreeDecode(p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits), kNumPosSlotBits, &rd);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 += RangeDecoderReverseBitTreeDecode(\r\n                p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);\r\n          }\r\n          else\r\n          {\r\n            rep0 += RangeDecoderDecodeDirectBits(&rd, \r\n                numDirectBits - kNumAlignBits) << kNumAlignBits;\r\n            rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = rd.Range;\r\n  vs->Code = rd.Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = rd.Buffer;\r\n  vs->BufferLim = rd.BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(rd.Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/LzmaStateDecode.c",
    "content": "/*\r\n  LzmaStateDecode.c\r\n  LZMA Decoder (State version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\n/* kRequiredInBufferSize = number of required input bytes for worst case: \r\n   longest match with longest distance.\r\n   kLzmaInBufferSize must be larger than kRequiredInBufferSize \r\n   23 bits = 2 (match select) + 10 (len) + 6 (distance) + 4(align) + 1 (RC_NORMALIZE)\r\n*/\r\n\r\n#define kRequiredInBufferSize ((23 * (kNumBitModelTotalBits - kNumMoveBits + 1) + 26 + 9) / 8)\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n    return LZMA_RESULT_OK;\r\n  }\r\n}\r\n\r\nint LzmaDecode(\r\n    CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding)\r\n{\r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n\r\n  unsigned char *Buffer = vs->Buffer;\r\n  int BufferSize = vs->BufferSize; /* don't change it to unsigned int */\r\n  CProb *p = vs->Probs;\r\n\r\n  int state = vs->State;\r\n  unsigned char previousByte;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  SizeT nowPos = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  unsigned char *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  unsigned char tempDictionary[4];\r\n\r\n  (*inSizeProcessed) = 0;\r\n  (*outSizeProcessed) = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n    {\r\n      Buffer[BufferSize++] = *inStream++;\r\n      (*inSizeProcessed)++;\r\n      inSize--;\r\n    }\r\n    if (BufferSize < 5)\r\n    {\r\n      vs->BufferSize = BufferSize;\r\n      return finishDecoding ? LZMA_RESULT_DATA_ERROR : LZMA_RESULT_OK;\r\n    }\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RC_INIT;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  while(1)\r\n  {\r\n    int bufferPos = (int)(Buffer - vs->Buffer);\r\n    if (BufferSize - bufferPos < kRequiredInBufferSize)\r\n    {\r\n      int i;\r\n      BufferSize -= bufferPos;\r\n      if (BufferSize < 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n      for (i = 0; i < BufferSize; i++)\r\n        vs->Buffer[i] = Buffer[i];\r\n      Buffer = vs->Buffer;\r\n      while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n      {\r\n        Buffer[BufferSize++] = *inStream++;\r\n        (*inSizeProcessed)++;\r\n        inSize--;\r\n      }\r\n      if (BufferSize < kRequiredInBufferSize && !finishDecoding)\r\n        break;\r\n    }\r\n    if (nowPos >= outSize)\r\n      break;\r\n    {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)((nowPos + globalPos) & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        ((((nowPos + globalPos)& literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (unsigned char)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            UInt32 pos;\r\n            UpdateBit0(prob);\r\n            if (distanceLimit == 0)\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            outStream[nowPos++] = previousByte;\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      if (rep0 > distanceLimit) \r\n        return LZMA_RESULT_DATA_ERROR;\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n\r\n      do\r\n      {\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  BufferSize -= (int)(Buffer - vs->Buffer);\r\n  if (BufferSize < 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    int i;\r\n    for (i = 0; i < BufferSize; i++)\r\n      vs->Buffer[i] = Buffer[i];\r\n  }\r\n  vs->BufferSize = BufferSize;\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = (UInt32)(globalPos + nowPos);\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n\r\n  (*outSizeProcessed) = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/LzmaStateDecode.h",
    "content": "/* \r\n  LzmaStateDecode.h\r\n  LZMA Decoder interface (State version)\r\n\r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMASTATEDECODE_H\r\n#define __LZMASTATEDECODE_H\r\n\r\n#include \"LzmaTypes.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  UInt32 DictionarySize;\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))\r\n\r\n#define kLzmaInBufferSize 64   /* don't change it. it must be larger than kRequiredInBufferSize */\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n  unsigned char *Dictionary;\r\n\r\n  unsigned char Buffer[kLzmaInBufferSize];\r\n  int BufferSize;\r\n\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;  /* -2: decoder needs internal initialization\r\n                     -1: stream was finished, \r\n                      0: ok\r\n                    > 0: need to write RemainLen bytes as match Reps[0],\r\n                  */\r\n  unsigned char TempDictionary[4];  /* it's required when DictionarySize = 0 */\r\n} CLzmaDecoderState;\r\n\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }\r\n\r\n/* LzmaDecode: decoding from input stream to output stream.\r\n  If finishDecoding != 0, then there are no more bytes in input stream\r\n  after inStream[inSize - 1]. */\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize,  SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/LzmaStateTest.c",
    "content": "/* \r\nLzmaStateTest.c\r\nTest application for LZMA Decoder (State version)\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\n#define kInBufferSize (1 << 15)\r\n#define kOutBufferSize (1 << 15)\r\n\r\nunsigned char g_InBuffer[kInBufferSize];\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n  { return fread(data, 1, size, file); }\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size); }\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0; \r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  int i;\r\n  int res = 0;\r\n  CLzmaDecoderState state;  /* it's about 140 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n  SizeT inAvail = 0;\r\n  unsigned char *inBuffer = 0;\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n  \r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    unsigned char b;\r\n    if (!MyReadFileAndCheck(inFile, &b, 1))\r\n      return PrintError(rs, kCantReadMessage);\r\n    if (b != 0xFF)\r\n      waitEOS = 0;\r\n    if (i < 4)\r\n      outSize += (UInt32)(b) << (i * 8);\r\n    else\r\n      outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  \r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      free(state.Probs);\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    }\r\n  }\r\n  \r\n  /* Decompress */\r\n  \r\n  LzmaDecoderInit(&state);\r\n  \r\n  do\r\n  {\r\n    SizeT inProcessed, outProcessed;\r\n    int finishDecoding;\r\n    UInt32 outAvail = kOutBufferSize;\r\n    if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n      outAvail = outSize;\r\n    if (inAvail == 0)\r\n    {\r\n      inAvail = (SizeT)MyReadFile(inFile, g_InBuffer, kInBufferSize);\r\n      inBuffer = g_InBuffer;\r\n    }\r\n    finishDecoding = (inAvail == 0);\r\n    res = LzmaDecode(&state,\r\n        inBuffer, inAvail, &inProcessed,\r\n        g_OutBuffer, outAvail, &outProcessed,\r\n        finishDecoding);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n      break;\r\n    }\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n    \r\n    if (outFile != 0)  \r\n      if (fwrite(g_OutBuffer, 1, outProcessed, outFile) != outProcessed)\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n        break;\r\n      }\r\n      \r\n    if (outSize < outProcessed)\r\n      outSizeHigh--;\r\n    outSize -= (UInt32)outProcessed;\r\n    outSize &= 0xFFFFFFFF;\r\n\r\n    if (outProcessed == 0 && finishDecoding)\r\n    {\r\n      if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n        res = 1;\r\n      break;\r\n    }\r\n  }\r\n  while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n\r\n  free(state.Dictionary);\r\n  free(state.Probs);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-02\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c",
    "content": "/* \r\nLzmaTest.c\r\nTest application for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-05)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fread(data, 1, size, file); \r\n}\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size);} \r\n\r\nsize_t MyWriteFile(FILE *file, const void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fwrite(data, 1, size, file); \r\n}\r\n\r\nint MyWriteFileAndCheck(FILE *file, const void *data, size_t size)\r\n  { return (MyWriteFile(file, data, size) == size); }\r\n\r\n#ifdef _LZMA_IN_CB\r\n#define kInBufferSize (1 << 15)\r\ntypedef struct _CBuffer\r\n{\r\n  ILzmaInCallback InCallback;\r\n  FILE *File;\r\n  unsigned char Buffer[kInBufferSize];\r\n} CBuffer;\r\n\r\nint LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CBuffer *b = (CBuffer *)object;\r\n  *buffer = b->Buffer;\r\n  *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);\r\n  return LZMA_RESULT_OK;\r\n}\r\nCBuffer g_InBuffer;\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define kOutBufferSize (1 << 15)\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n#endif\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0;\r\n  #ifndef _LZMA_OUT_READ\r\n  SizeT outSizeFull;\r\n  unsigned char *outStream;\r\n  #endif\r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  SizeT compressedSize;\r\n  unsigned char *inStream;\r\n  #endif\r\n\r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n  int res;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.File = inFile;\r\n  #endif\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  {\r\n    long length;\r\n    fseek(inFile, 0, SEEK_END);\r\n    length = ftell(inFile);\r\n    fseek(inFile, 0, SEEK_SET);\r\n    if ((long)(SizeT)length != length)\r\n      return PrintError(rs, \"Too big compressed stream\");\r\n    compressedSize = (SizeT)(length - (LZMA_PROPERTIES_SIZE + 8));\r\n  }\r\n  #endif\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n\r\n  {\r\n    int i;\r\n    for (i = 0; i < 8; i++)\r\n    {\r\n      unsigned char b;\r\n      if (!MyReadFileAndCheck(inFile, &b, 1))\r\n        return PrintError(rs, kCantReadMessage);\r\n      if (b != 0xFF)\r\n        waitEOS = 0;\r\n      if (i < 4)\r\n        outSize += (UInt32)(b) << (i * 8);\r\n      else\r\n        outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n    }\r\n    \r\n    #ifndef _LZMA_OUT_READ\r\n    if (waitEOS)\r\n      return PrintError(rs, \"Stream with EOS marker is not supported\");\r\n    outSizeFull = (SizeT)outSize;\r\n    if (sizeof(SizeT) >= 8)\r\n      outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);\r\n    else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)\r\n      return PrintError(rs, \"Too big uncompressed stream\");\r\n    #endif\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n  #else\r\n  if (outSizeFull == 0)\r\n    outStream = 0;\r\n  else\r\n    outStream = (unsigned char *)malloc(outSizeFull);\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  if (compressedSize == 0)\r\n    inStream = 0;\r\n  else\r\n    inStream = (unsigned char *)malloc(compressedSize);\r\n  #endif\r\n\r\n  if (state.Probs == 0 \r\n    #ifdef _LZMA_OUT_READ\r\n    || (state.Dictionary == 0 && state.Properties.DictionarySize != 0)\r\n    #else\r\n    || (outStream == 0 && outSizeFull != 0)\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    || (inStream == 0 && compressedSize != 0)\r\n    #endif\r\n    )\r\n  {\r\n    free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    free(state.Dictionary);\r\n    #else\r\n    free(outStream);\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    free(inStream);\r\n    #endif\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  }\r\n\r\n  /* Decompress */\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  #else\r\n  if (!MyReadFileAndCheck(inFile, inStream, compressedSize))\r\n    return PrintError(rs, kCantReadMessage);\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inAvail = compressedSize;\r\n    const unsigned char *inBuffer = inStream;\r\n    #endif\r\n    LzmaDecoderInit(&state);\r\n    do\r\n    {\r\n      #ifndef _LZMA_IN_CB\r\n      SizeT inProcessed;\r\n      #endif\r\n      SizeT outProcessed;\r\n      SizeT outAvail = kOutBufferSize;\r\n      if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n        outAvail = (SizeT)outSize;\r\n      res = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &g_InBuffer.InCallback,\r\n        #else\r\n        inBuffer, inAvail, &inProcessed,\r\n        #endif\r\n        g_OutBuffer, outAvail, &outProcessed);\r\n      if (res != 0)\r\n      {\r\n        sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n        res = 1;\r\n        break;\r\n      }\r\n      #ifndef _LZMA_IN_CB\r\n      inAvail -= inProcessed;\r\n      inBuffer += inProcessed;\r\n      #endif\r\n      \r\n      if (outFile != 0)  \r\n        if (!MyWriteFileAndCheck(outFile, g_OutBuffer, (size_t)outProcessed))\r\n        {\r\n          PrintError(rs, kCantWriteMessage);\r\n          res = 1;\r\n          break;\r\n        }\r\n        \r\n      if (outSize < outProcessed)\r\n        outSizeHigh--;\r\n      outSize -= (UInt32)outProcessed;\r\n      outSize &= 0xFFFFFFFF;\r\n        \r\n      if (outProcessed == 0)\r\n      {\r\n        if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n          res = 1;\r\n        break;\r\n      }\r\n    }\r\n    while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n  }\r\n\r\n  #else\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inProcessed;\r\n    #endif\r\n    SizeT outProcessed;\r\n    res = LzmaDecode(&state,\r\n      #ifdef _LZMA_IN_CB\r\n      &g_InBuffer.InCallback,\r\n      #else\r\n      inStream, compressedSize, &inProcessed,\r\n      #endif\r\n      outStream, outSizeFull, &outProcessed);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n    }\r\n    else if (outFile != 0)\r\n    {\r\n      if (!MyWriteFileAndCheck(outFile, outStream, (size_t)outProcessed))\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  free(state.Dictionary);\r\n  #else\r\n  free(outStream);\r\n  #endif\r\n  #ifndef _LZMA_IN_CB\r\n  free(inStream);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-05\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/LzmaTypes.h",
    "content": "/* \r\nLzmaTypes.h \r\n\r\nTypes for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.40 (2006-05-01)\r\n*/\r\n\r\n#ifndef __LZMATYPES_H\r\n#define __LZMATYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif \r\n\r\n/* #define _LZMA_SYSTEM_SIZE_T */\r\n/* Use system's size_t. You can use it to enable 64-bit sizes supporting */\r\n\r\n#ifndef _7ZIP_SIZET_DEFINED\r\n#define _7ZIP_SIZET_DEFINED\r\n#ifdef _LZMA_SYSTEM_SIZE_T\r\n#include <stddef.h>\r\ntypedef size_t SizeT;\r\n#else\r\ntypedef UInt32 SizeT;\r\n#endif\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/kmod/Makefile",
    "content": "\n# Copyright (C) 2006 Junjiro Okajima\n# Copyright (C) 2006 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: Makefile,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\n\nobj-m += unlzma.o sqlzma.o\nunlzma-y := module.o\nsqlzma-y := uncomp.o\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/kmod/module.c",
    "content": "\n/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: module.c,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $ */\n\n#include <linux/init.h>\n#include <linux/module.h>\n\n#include \"../LzmaDecode.c\"\n\nEXPORT_SYMBOL(LzmaDecodeProperties);\nEXPORT_SYMBOL(LzmaDecode);\n\n#if 0\nstatic int __init unlzma_init(void)\n{\n\treturn 0;\n}\n\nstatic void __exit unlzma_exit(void)\n{\n}\n\nmodule_init(unlzma_init);\nmodule_exit(unlzma_exit);\n#endif\n\nMODULE_LICENSE(\"GPL\");\nMODULE_VERSION(\"$Id: module.c,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\");\nMODULE_DESCRIPTION(\"LZMA uncompress. \"\n\t\t   \"A tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/kmod.mk",
    "content": "\n# Copyright (C) 2006 Junjiro Okajima\n# Copyright (C) 2006 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: kmod.mk,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\nifndef KDir\n$(error KDir is not defined)\nendif\n\n#include makefile.gcc\n\nKmod = kmod\nEXTRA_CFLAGS += -Wall -Werror -I${CURDIR} -I${Sqlzma}\n# -D_LZMA_PROB32\nEXTRA_CFLAGS += $(shell ${CPP} ${CFLAGS} -P testflags.c)\n\nall: ${Kmod}/uncomp.c\n\t${MAKE} EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\" M=${CURDIR}/${Kmod} \\\n\t\t-C ${KDir} C=0 V=0 modules\n\n${Kmod}/uncomp.c: uncomp.c\n\tln $< $@\n\nclean: clean_kmod\nclean_kmod:\n\t${MAKE} -C ${KDir} M=${CURDIR}/${Kmod} V=0 clean\n\t${RM} ${Kmod}/*~\n\t-@test -e ${Kmod}/uncomp.c && \\\n\t\tdiff -q ${Kmod}/uncomp.c uncomp.c > /dev/null && \\\n\t\tfind ${Kmod}/uncomp.c -links +1 | xargs -r ${RM}\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. KDir=/lib/modules/`uname -r`/build -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/makefile",
    "content": "PROG = lzmaDec.exe\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nOBJS = \\\r\n  $O\\LzmaTest.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$O\\LzmaTest.obj: $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/LZMA_C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/makefile.gcc",
    "content": "PROG = lzmadec\r\nCXX = gcc \r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall -pedantic -D _LZMA_PROB32 \r\n\r\nOBJS = LzmaTest.o LzmaDecode.o \r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\nLzmaTest.o: LzmaTest.c\r\n\t$(CXX) $(CFLAGS) LzmaTest.c\r\n\r\nLzmaDecode.o: LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) LzmaDecode.c\r\n\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/sqlzma.mk",
    "content": "\n# Copyright (C) 2006 Junjiro Okajima\n# Copyright (C) 2006 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\ninclude makefile.gcc\nifdef KDir\ninclude kmod.mk\nendif\n\nifdef UseDebugFlags\nDebugFlags = -O0 -g -UNDEBUG\nendif\nCFLAGS += -DNDEBUG ${DebugFlags}\nTgt = libunlzma.a libunlzma_r.a\n\nall: ${Tgt}\n\n%_r.c: %.c\n\tln $< $@\n# -pthread\n%_r.o: CFLAGS += -D_REENTRANT -include pthread.h\n\nuncomp.o uncomp_r.o: CFLAGS += -I${Sqlzma}\nuncomp.o: uncomp.c ${Sqlzma}/sqlzma.h\n\nlibunlzma.a: uncomp.o LzmaDecode.o\n\t${AR} cr $@ $^\nlibunlzma_r.a: uncomp_r.o LzmaDecode_r.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) ${Tgt} uncomp.o uncomp_r.o LzmaDecode_r.o *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/testflags.c",
    "content": "#ifdef _LZMA_PROB32\n-D_LZMA_PROB32\n#else\n-U_LZMA_PROB32\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/LZMA_C/uncomp.c",
    "content": "/*\n * Copyright (C) 2006, 2007 Junjiro Okajima\n * Copyright (C) 2006, 2007 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: uncomp.c,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $ */\n\n/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */\n\n#ifndef __KERNEL__\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <assert.h>\n#include <pthread.h>\n#define unlikely(x)\t\t__builtin_expect(!!(x), 0)\n#define BUG_ON(x)\t\tassert(!(x))\n/* sqlzma buffers are always larger than a page. true? */\n#define kmalloc(sz,gfp)\t\tmalloc(sz)\n#define kfree(p)\t\tfree(p)\n#define zlib_inflate(s, f)\tinflate(s, f)\n#define zlib_inflateInit(s)\tinflateInit(s)\n#define zlib_inflateReset(s)\tinflateReset(s)\n#define zlib_inflateEnd(s)\tinflateEnd(s)\n#else\n#include <linux/init.h>\n#include <linux/module.h>\n#include <linux/kernel.h>\n#include <linux/vmalloc.h>\n#ifndef WARN_ON_ONCE\n#define WARN_ON_ONCE(b)\tWARN_ON(b)\n#endif\n#endif /* __KERNEL__ */\n\n#include \"sqlzma.h\"\n#include \"LzmaDecode.h\"\n\nstatic int LzmaUncompress(struct sqlzma_un *un)\n{\n\tint err, i, ret;\n\tSizeT outSize, inProcessed, outProcessed, srclen;\n\t/* it's about 24-80 bytes structure, if int is 32-bit */\n\tCLzmaDecoderState state;\n\tunsigned char *dst, *src, a[8];\n\tstruct sized_buf *sbuf;\n\n\t/* Decode LZMA properties and allocate memory */\n\terr = -EINVAL;\n\tsrc = un->un_cmbuf;\n\tret = LzmaDecodeProperties(&state.Properties, src, LZMA_PROPERTIES_SIZE);\n\tsrc += LZMA_PROPERTIES_SIZE;\n\tif (unlikely(ret != LZMA_RESULT_OK))\n\t\tgoto out;\n\ti = LzmaGetNumProbs(&state.Properties);\n\tif (unlikely(i <= 0))\n\t\ti = 1;\n\ti *= sizeof(CProb);\n\tsbuf = un->un_a + SQUN_PROB;\n\tif (unlikely(sbuf->sz < i)) {\n\t\tif (sbuf->buf && sbuf->buf != un->un_prob)\n\t\t\tkfree(sbuf->buf);\n#ifdef __KERNEL__\n\t\tprintk(\"%s:%d: %d --> %d\\n\", __func__, __LINE__, sbuf->sz, i);\n#else\n\t\tprintf(\"%d --> %d\\n\", sbuf->sz, i);\n#endif\n\t\terr = -ENOMEM;\n\t\tsbuf->sz = 0;\n\t\tsbuf->buf = kmalloc(i, GFP_ATOMIC);\n\t\tif (unlikely(!sbuf->buf))\n\t\t\tgoto out;\n\t\tsbuf->sz = i;\n\t}\n\tstate.Probs = (void*)sbuf->buf;\n\n\t/* Read uncompressed size */\n\tmemcpy(a, src, sizeof(a));\n\tsrc += sizeof(a);\n\toutSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);\n\n\terr = -EINVAL;\n\tdst = un->un_resbuf;\n\tif (unlikely(!dst || outSize > un->un_reslen))\n\t\tgoto out;\n\tun->un_reslen = outSize;\n\tsrclen = un->un_cmlen - (src - un->un_cmbuf);\n\n\t/* Decompress */\n\terr = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,\n\t\t\t &outProcessed);\n\tif (err)\n\t\terr = -EINVAL;\n\n out:\n#ifndef __KERNEL__\n\tif (err)\n\t\tfprintf(stderr, \"err %d\\n\", err);\n#endif\n\treturn err;\n}\n\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst)\n{\n\tint err, by_lzma = 0;\n\tif (un->un_lzma && is_lzma(*src->buf)) {\n\t\tby_lzma = 1;\n\t\tun->un_cmbuf = src->buf;\n\t\tun->un_cmlen = src->sz;\n\t\tun->un_resbuf = dst->buf;\n\t\tun->un_reslen = dst->sz;\n\n\t\t/* this library is thread-safe */\n\t\terr = LzmaUncompress(un);\n\t\tgoto out;\n\t}\n\n\terr = zlib_inflateReset(&un->un_stream);\n\tif (unlikely(err != Z_OK))\n\t\tgoto out;\n\tun->un_stream.next_in = src->buf;\n\tun->un_stream.avail_in = src->sz;\n\tun->un_stream.next_out = dst->buf;\n\tun->un_stream.avail_out = dst->sz;\n\terr = zlib_inflate(&un->un_stream, Z_FINISH);\n\tif (err == Z_STREAM_END)\n\t\terr = 0;\n\n out:\n\tif (err) {\n#ifdef __KERNEL__\n\t\tWARN_ON_ONCE(1);\n#else\n\t\tchar a[64] = \"ZLIB \";\n\t\tif (by_lzma) {\n\t\t\tstrcpy(a, \"LZMA \");\n#ifdef _REENTRANT\n\t\t\tstrerror_r(err, a + 5, sizeof(a) - 5);\n#else\n\t\t\tstrncat(a, strerror(err), sizeof(a) - 5);\n#endif\n\t\t} else\n\t\t\tstrncat(a, zError(err), sizeof(a) - 5);\n\t\tfprintf(stderr, \"%s: %.*s\\n\", __func__, sizeof(a), a);\n#endif\n\t}\n\treturn err;\n}\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)\n{\n\tint err;\n\n\terr = -ENOMEM;\n\tun->un_lzma = do_lzma;\n\tmemset(un->un_a, 0, sizeof(un->un_a));\n\tun->un_a[SQUN_PROB].buf = un->un_prob;\n\tun->un_a[SQUN_PROB].sz = sizeof(un->un_prob);\n\tif (res_sz) {\n\t\tun->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);\n\t\tif (unlikely(!un->un_a[SQUN_RESULT].buf))\n\t\t\treturn err;\n\t\tun->un_a[SQUN_RESULT].sz = res_sz;\n\t}\n\n\tun->un_stream.next_in = NULL;\n\tun->un_stream.avail_in = 0;\n#ifdef __KERNEL__\n\tun->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);\n\tif (unlikely(!un->un_stream.workspace))\n\t\treturn err;\n#else\n\tun->un_stream.opaque = NULL;\n\tun->un_stream.zalloc = Z_NULL;\n\tun->un_stream.zfree = Z_NULL;\n#endif\n\terr = zlib_inflateInit(&un->un_stream);\n\tif (unlikely(err == Z_MEM_ERROR))\n\t\treturn -ENOMEM;\n\tBUG_ON(err);\n\treturn err;\n}\n\nvoid sqlzma_fin(struct sqlzma_un *un)\n{\n\tint i;\n\tfor (i = 0; i < SQUN_LAST; i++)\n\t\tif (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)\n\t\t\tkfree(un->un_a[i].buf);\n\tBUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);\n}\n\n#ifdef __KERNEL__\nEXPORT_SYMBOL(sqlzma_un);\nEXPORT_SYMBOL(sqlzma_init);\nEXPORT_SYMBOL(sqlzma_fin);\n\n#if 0\nstatic int __init sqlzma_init(void)\n{\n\treturn 0;\n}\n\nstatic void __exit sqlzma_exit(void)\n{\n}\n\nmodule_init(sqlzma_init);\nmodule_exit(sqlzma_exit);\n#endif\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Junjiro Okajima <hooanon05 at yahoo dot co dot jp>\");\nMODULE_VERSION(\"$Id: uncomp.c,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\");\nMODULE_DESCRIPTION(\"LZMA uncompress for squashfs. \"\n\t\t   \"Some functions for squashfs to support LZMA and \"\n\t\t   \"a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/RangeCoder/RangeCoder.h",
    "content": "// Compress/RangeCoder/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_H\r\n#define __COMPRESS_RANGECODER_H\r\n\r\n#include \"../../Common/InBuffer.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1; \r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) \r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);                      \r\n    } \r\n    _cacheSize++;                               \r\n    Low = (UInt32)Low << 8;                           \r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numTotalBits)\r\n  {\r\n    for (int i = numTotalBits - 1; i >= 0; i--)\r\n    {\r\n      Range >>= 1;\r\n      if (((value >> i) & 1) == 1)\r\n        Low += Range;\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;        \r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8; \r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/RangeCoder/RangeCoderBit.cpp",
    "content": "// Compress/RangeCoder/RangeCoderBit.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nUInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\nstatic CPriceTables g_PriceTables;\r\n\r\nCPriceTables::CPriceTables() { Init(); }\r\n\r\nvoid CPriceTables::Init()\r\n{\r\n  const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n  for(int i = kNumBits - 1; i >= 0; i--)\r\n  {\r\n    UInt32 start = 1 << (kNumBits - i - 1);\r\n    UInt32 end = 1 << (kNumBits - i);\r\n    for (UInt32 j = start; j < end; j++)\r\n      ProbPrices[j] = (i << kNumBitPriceShiftBits) + \r\n          (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n  }\r\n\r\n  /*\r\n  // simplest: bad solution\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = kBitPrice;\r\n  */\r\n  \r\n  /*\r\n  const double kDummyMultMid = (1.0 / kBitPrice) / 2;\r\n  const double kDummyMultMid = 0;\r\n  // float solution\r\n  double ln2 = log(double(2));\r\n  double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);\r\n  */\r\n  \r\n  /*\r\n  // experimental, slow, solution:\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n  {\r\n    const int kCyclesBits = 5;\r\n    const UInt32 kCycles = (1 << kCyclesBits);\r\n\r\n    UInt32 range = UInt32(-1);\r\n    UInt32 bitCount = 0;\r\n    for (UInt32 j = 0; j < kCycles; j++)\r\n    {\r\n      range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n      range *= i;\r\n      while(range < (1 << 31))\r\n      {\r\n        range <<= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    bitCount <<= kNumBitPriceShiftBits;\r\n    range -= (1 << 31);\r\n    for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)\r\n    {\r\n      range <<= 1;\r\n      if (range > (1 << 31))\r\n      {\r\n        bitCount += (1 << k);\r\n        range -= (1 << 31);\r\n      }\r\n    }\r\n    ProbPrices[i] = (bitCount \r\n      // + (1 << (kCyclesBits - 1))\r\n      ) >> kCyclesBits;\r\n  }\r\n  */\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/RangeCoder/RangeCoderBit.h",
    "content": "// Compress/RangeCoder/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_H\r\n#define __COMPRESS_RANGECODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 2;\r\n\r\nconst int kNumBitPriceShiftBits = 6;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nclass CPriceTables\r\n{\r\npublic:\r\n  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  static void Init();\r\n  CPriceTables();\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return CPriceTables::ProbPrices[\r\n      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/RangeCoder/RangeCoderBitTree.h",
    "content": "// Compress/RangeCoder/RangeCoderBitTree.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_TREE_H\r\n#define __COMPRESS_RANGECODER_BIT_TREE_H\r\n\r\n#include \"RangeCoderBit.h\"\r\n#include \"RangeCoderOpt.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeEncoder\r\n{\r\n  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  void Encode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int bitIndex = NumBitLevels; bitIndex != 0 ;)\r\n    {\r\n      bitIndex--;\r\n      UInt32 bit = (symbol >> bitIndex) & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n  };\r\n  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int i = 0; i < NumBitLevels; i++)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n      symbol >>= 1;\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    symbol |= (1 << NumBitLevels);\r\n    UInt32 price = 0;\r\n    while (symbol != 1)\r\n    {\r\n      price += Models[symbol >> 1].GetPrice(symbol & 1);\r\n      symbol >>= 1;\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 ReverseGetPrice(UInt32 symbol) const\r\n  {\r\n    UInt32 price = 0;\r\n    UInt32 modelIndex = 1;\r\n    for (int i = NumBitLevels; i != 0; i--)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      symbol >>= 1;\r\n      price += Models[modelIndex].GetPrice(bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n    return price;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeDecoder\r\n{\r\n  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  UInt32 Decode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n    {\r\n      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);\r\n      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)\r\n    }\r\n    RC_FLUSH_VAR\r\n    return modelIndex - (1 << NumBitLevels);\r\n  };\r\n  UInt32 ReverseDecode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    UInt32 symbol = 0;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n    {\r\n      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n      // modelIndex <<= 1;\r\n      // modelIndex += bit;\r\n      // symbol |= (bit << bitIndex);\r\n      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n    }\r\n    RC_FLUSH_VAR\r\n    return symbol;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nvoid ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models, \r\n    CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  for (int i = 0; i < NumBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    Models[modelIndex].Encode(rangeEncoder, bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models, \r\n    UInt32 NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 modelIndex = 1;\r\n  for (int i = NumBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += Models[modelIndex].GetPrice(bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models, \r\n    CDecoder *rangeDecoder, int NumBitLevels)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  UInt32 symbol = 0;\r\n  RC_INIT_VAR\r\n  for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n  {\r\n    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n    // modelIndex <<= 1;\r\n    // modelIndex += bit;\r\n    // symbol |= (bit << bitIndex);\r\n    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n  }\r\n  RC_FLUSH_VAR\r\n  return symbol;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/RangeCoder/RangeCoderOpt.h",
    "content": "// Compress/RangeCoder/RangeCoderOpt.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_OPT_H\r\n#define __COMPRESS_RANGECODER_OPT_H\r\n\r\n#define RC_INIT_VAR \\\r\n  UInt32 range = rangeDecoder->Range; \\\r\n  UInt32 code = rangeDecoder->Code;        \r\n\r\n#define RC_FLUSH_VAR \\\r\n  rangeDecoder->Range = range; \\\r\n  rangeDecoder->Code = code;\r\n\r\n#define RC_NORMALIZE \\\r\n  if (range < NCompress::NRangeCoder::kTopValue) \\\r\n    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }\r\n\r\n#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \\\r\n  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \\\r\n  if (code < bound) \\\r\n  { A0; range = bound; \\\r\n    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \\\r\n    mi <<= 1; } \\\r\n  else \\\r\n  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \\\r\n    mi = (mi + mi) + 1; }} \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/Compress/RangeCoder/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n// \"23170F69-40C1-278A-0000-000400xx0000\"\r\n#define CODER_INTERFACE(i, x) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \\\r\nstruct i: public IUnknown\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, \r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kMatchFinderCycles,\r\n    kNumPasses = 0x460, \r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kNumThreads,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetCoderMt, 0x25)\r\n{\r\n  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block \r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n// \"23170F69-40C1-278A-0000-000300xx0000\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, b, x) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \\\r\nstruct i: public b\r\n\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream, \r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/Alloc.cpp",
    "content": "// Common/Alloc.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount++);\r\n  #endif\r\n  return ::malloc(size);\r\n}\r\n\r\nvoid MyFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d\", --g_allocCount);\r\n  #endif\r\n  \r\n  ::free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  ::VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\nstatic SIZE_T g_LargePageSize = \r\n    #ifdef _WIN64\r\n    (1 << 21);\r\n    #else\r\n    (1 << 22);\r\n    #endif\r\n\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n\r\nbool SetLargePageSize()\r\n{\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return false;\r\n  SIZE_T size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return false;\r\n  g_LargePageSize = size;\r\n  return true;\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  if (size >= (1 << 18))\r\n  {\r\n    void *res = ::VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), \r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  ::VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/Alloc.h",
    "content": "// Common/Alloc.h\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size) throw();\r\nvoid MyFree(void *address) throw();\r\n\r\n#ifdef _WIN32\r\n\r\nbool SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size) throw();\r\nvoid MidFree(void *address) throw();\r\nvoid *BigAlloc(size_t size) throw();\r\nvoid BigFree(void *address) throw();\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CRC.h\"\r\n\r\nstatic const UInt32 kCRCPoly = 0xEDB88320;\r\n\r\nUInt32 CCRC::Table[256];\r\n\r\nvoid CCRC::InitTable()\r\n{\r\n  for (UInt32 i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    for (int j = 0; j < 8; j++)\r\n      if (r & 1) \r\n        r = (r >> 1) ^ kCRCPoly;\r\n      else     \r\n        r >>= 1;\r\n    CCRC::Table[i] = r;\r\n  }\r\n}\r\n\r\nclass CCRCTableInit\r\n{\r\npublic:\r\n  CCRCTableInit() { CCRC::InitTable(); }\r\n} g_CRCTableInit;\r\n\r\nvoid CCRC::UpdateByte(Byte b)\r\n{\r\n  _value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);\r\n}\r\n\r\nvoid CCRC::UpdateUInt16(UInt16 v)\r\n{\r\n  UpdateByte(Byte(v));\r\n  UpdateByte(Byte(v >> 8));\r\n}\r\n\r\nvoid CCRC::UpdateUInt32(UInt32 v)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n    UpdateByte((Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CCRC::UpdateUInt64(UInt64 v)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n    UpdateByte((Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CCRC::Update(const void *data, size_t size)\r\n{\r\n  UInt32 v = _value;\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);\r\n  _value = v;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/CRC.h",
    "content": "// Common/CRC.h\r\n\r\n#ifndef __COMMON_CRC_H\r\n#define __COMMON_CRC_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nclass CCRC\r\n{\r\n  UInt32 _value;\r\npublic:\r\n\tstatic UInt32 Table[256];\r\n\tstatic void InitTable();\r\n\r\n  CCRC():  _value(0xFFFFFFFF){};\r\n  void Init() { _value = 0xFFFFFFFF; }\r\n  void UpdateByte(Byte v);\r\n  void UpdateUInt16(UInt16 v);\r\n  void UpdateUInt32(UInt32 v);\r\n  void UpdateUInt64(UInt64 v);\r\n  void Update(const void *data, size_t size);\r\n  UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } \r\n  static UInt32 CalculateDigest(const void *data, size_t size)\r\n  {\r\n    CCRC crc;\r\n    crc.Update(data, size);\r\n    return crc.GetDigest();\r\n  }\r\n  static bool VerifyDigest(UInt32 digest, const void *data, size_t size)\r\n  {\r\n    return (CalculateDigest(data, size) == digest);\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else \r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  while (true)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      return;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{ \r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */); \r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms, \r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0) \r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while(pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len) \r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString: \r\n      case NSwitchType::kUnLimitedPostString: \r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for(int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString)\r\n{\r\n  for(int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if(commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"Common/String.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  { \r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms); \r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms, \r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p) \r\n  { \r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p) \r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR() { m_str = NULL; }\r\n  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR pSrc)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(pSrc);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const \r\n  { \r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memmove(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  void Attach(BSTR src) {  m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) { \r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline bool operator==(REFGUID g1, REFGUID g2)\r\n{ \r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return false;\r\n  return true;\r\n}\r\ninline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct \r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else \r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#define CHAR_PATH_SEPARATOR '\\\\'\r\n#define WCHAR_PATH_SEPARATOR L'\\\\'\r\n#define STRING_PATH_SEPARATOR \"\\\\\"\r\n#define WSTRING_PATH_SEPARATOR L\"\\\\\"\r\n\r\n#else\r\n\r\n#define CHAR_PATH_SEPARATOR '/'\r\n#define WCHAR_PATH_SEPARATOR L'/'\r\n#define STRING_PATH_SEPARATOR \"/\"\r\n#define WSTRING_PATH_SEPARATOR L\"/\"\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\n\r\n#undef BYTE\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\n\r\n#undef WORD\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\n\r\n#undef DWORD\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOTIMPL ((HRESULT)0x80004001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall \r\n#else\r\n#define STDMETHODCALLTYPE \r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct \r\n\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\t\r\n  VT_EMPTY\t= 0,\r\n\tVT_NULL\t= 1,\r\n\tVT_I2\t= 2,\r\n\tVT_I4\t= 3,\r\n\tVT_R4\t= 4,\r\n\tVT_R8\t= 5,\r\n\tVT_CY\t= 6,\r\n\tVT_DATE\t= 7,\r\n\tVT_BSTR\t= 8,\r\n\tVT_DISPATCH\t= 9,\r\n\tVT_ERROR\t= 10,\r\n\tVT_BOOL\t= 11,\r\n\tVT_VARIANT\t= 12,\r\n\tVT_UNKNOWN\t= 13,\r\n\tVT_DECIMAL\t= 14,\r\n\tVT_I1\t= 16,\r\n\tVT_UI1\t= 17,\r\n\tVT_UI2\t= 18,\r\n\tVT_UI4\t= 19,\r\n\tVT_I8\t= 20,\r\n\tVT_UI8\t= 21,\r\n\tVT_INT\t= 22,\r\n\tVT_UINT\t= 23,\r\n\tVT_VOID\t= 24,\r\n\tVT_HRESULT\t= 25,\r\n\tVT_FILETIME\t= 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union \r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\t\r\n  STREAM_SEEK_SET\t= 0,\r\n  STREAM_SEEK_CUR\t= 1,\r\n  STREAM_SEEK_END\t= 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\n#ifdef _WIN32\r\nvoid * \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n#endif\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\n#ifdef _WIN32\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw();\r\n#endif \r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/String.cpp",
    "content": "// Common/String.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"StringConvert.h\"\r\n#else\r\n#include <ctype.h>\r\n#endif\r\n\r\n#include \"Common/String.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{ \r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1), \r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), \r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{ \r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/String.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"Vector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\nstatic const char *kTrimDefaultCharSet  = \" \\n\\t\";\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{ \r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{ \r\n  T *destStart = dest;\r\n  while((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)CharUpperA((LPSTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)CharUpperW((LPWSTR)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)CharLowerA((LPSTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)CharLowerW((LPWSTR)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char  *s2);\r\n#endif\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex, \r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n\tint _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if(realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if(newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if(_capacity > 0)\r\n    {\r\n      for (int i = 0; i < (_length + 1); i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n      _chars = newBuffer;\r\n    }\r\n    else\r\n    {\r\n      _chars = newBuffer;\r\n      _chars[0] = 0;\r\n    }\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize) \r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0)\r\n    { SetCapacity(16 - 1); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;} \r\n\r\n  // The minimum size of the character buffer in characters. \r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if(minBufLength >= _capacity)\r\n      SetCapacity(minBufLength + 1);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if(newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length; \r\n    return *this;\r\n  }  \r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if(&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    while (true)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    while (true)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for(int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    for(int i = 0; i < (int)(sizeof(kTrimDefaultCharSet) /\r\n      sizeof(kTrimDefaultCharSet[0])); i++)\r\n      charSet += (T)kTrimDefaultCharSet[i];\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for(int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0) \r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0) \r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()), \r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 2;\r\n    int numChars = WideCharToMultiByte(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(numRequiredBytes), \r\n      numRequiredBytes + 1, NULL, NULL);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"Common/String.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT codePage)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_INT16_DEFINED\r\n#define _7ZIP_INT16_DEFINED\r\ntypedef short Int16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_INT32_DEFINED\r\n#define _7ZIP_INT32_DEFINED\r\ntypedef int Int32;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\ntypedef unsigned int UInt32;\r\n#endif \r\n\r\n#ifdef _MSC_VER\r\n\r\n#ifndef _7ZIP_INT64_DEFINED\r\n#define _7ZIP_INT64_DEFINED\r\ntypedef __int64 Int64;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\ntypedef unsigned __int64 UInt64;\r\n#endif \r\n\r\n#else\r\n\r\n#ifndef _7ZIP_INT64_DEFINED\r\n#define _7ZIP_INT64_DEFINED\r\ntypedef long long int Int64;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\ntypedef unsigned long long int UInt64;\r\n#endif \r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/Vector.cpp",
    "content": "// Common/Vector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"Vector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector()\r\n  { delete []((unsigned char *)_items); }\r\nvoid CBaseRecordVector::Clear() \r\n  { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() \r\n  { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index)\r\n  { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if(_size != _capacity)\r\n    return;\r\n  int delta;\r\n  if (_capacity > 64)\r\n    delta = _capacity / 2;\r\n  else if (_capacity > 8)\r\n    delta = 8;\r\n  else\r\n    delta = 4;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  if(newCapacity <= _capacity)\r\n    return;\r\n  /*\r\n  #ifndef _DEBUG\r\n  static const unsigned int kMaxVectorSize = 0xF0000000;\r\n  if(newCapacity < _size || \r\n      ((unsigned int )newCapacity * (unsigned int )_itemSize) > kMaxVectorSize) \r\n    throw 1052354;\r\n  #endif\r\n  */\r\n  unsigned char *p = new unsigned char[newCapacity * _itemSize];\r\n  int numRecordsToMove = _capacity;\r\n  memmove(p, _items, _itemSize * numRecordsToMove);\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize, \r\n    ((unsigned char  *)_items) + srcIndex * _itemSize, \r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Common/Vector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n\tint _capacity;\r\n  int _size;\r\n\tvoid *_items;\r\n  size_t _itemSize;\r\n\r\n\tvoid ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; } \r\npublic:\r\n  CBaseRecordVector(size_t itemSize):\r\n      _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n\tvirtual ~CBaseRecordVector();\r\n  int Size() const { return _size; }\r\n\tbool IsEmpty() const { return (_size == 0); }\r\n\tvoid Reserve(int newCapacity);\r\n\tvirtual void Delete(int index, int num = 1);\r\n\tvoid Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector():CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v):\r\n    CBaseRecordVector(sizeof(T)) { *this = v;}\r\n\tCRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n\tint Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n\tvoid Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n\tT& operator[](int index) { return ((T *)_items)[index]; }\r\n\tconst T& Front() const { return operator[](0); }\r\n  T& Front()   { return operator[](0); }\r\n\tconst T& Back() const { return operator[](_size - 1); }\r\n  T& Back()   { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  void Sort(int left, int right)\r\n  { \r\n    if (right - left < 2)\r\n      return;\r\n    Swap(left, (left + right) / 2);\r\n    int last = left;\r\n    for (int i = left; i < right; i++)\r\n      if (operator[](i) < operator[](left))\r\n        Swap(++last, i);\r\n    Swap(left, last);\r\n    Sort(left, last);\r\n    Sort(last + 1, right);\r\n  }\r\n  void Sort() { Sort(0, Size());  }\r\n  void Sort(int left, int right, int (*compare)(const T*, const T*, void *), void *param)\r\n  { \r\n    if (right - left < 2)\r\n      return;\r\n    Swap(left, (left + right) / 2);\r\n    int last = left;\r\n    for (int i = left; i < right; i++)\r\n      if (compare(&operator[](i), &operator[](left), param) < 0)\r\n        Swap(++last, i);\r\n    Swap(left, last);\r\n    Sort(left, last, compare, param);\r\n    Sort(last + 1, right, compare, param);\r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param) \r\n  {  \r\n    Sort(0, Size(), compare, param);  \r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector(){};\r\n  ~CObjectVector() { Clear(); }\r\n  CObjectVector(const CObjectVector &objectVector)\r\n    { *this = objectVector; }\r\n\tCObjectVector& operator=(const CObjectVector &objectVector)\r\n  {\r\n    Clear();\r\n    return (*this += objectVector);\r\n  }\r\n\tCObjectVector& operator+=(const CObjectVector &objectVector)\r\n  {\r\n    int size = objectVector.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(objectVector[i]);\r\n    return *this;\r\n  }\r\n\tconst T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n\tT& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n\tT& Front() { return operator[](0); }\r\n\tconst T& Front() const { return operator[](0); }\r\n\tT& Back() { return operator[](_size - 1); }\r\n\tconst T& Back() const { return operator[](_size - 1); }\r\n\tint Add(const T& item)\r\n    { return CPointerVector::Add(new T(item)); }\r\n\tvoid Insert(int index, const T& item)\r\n    { CPointerVector::Insert(index, new T(item)); }\r\n\tvirtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for(int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for(int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n      return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param) \r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void *param)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  Close();\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE) NULL);\r\n  return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    Close();\r\n    _handle = ::CreateFileW(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE) NULL);\r\n    return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));\r\n  }\r\n  return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP), \r\n    desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(!_fileIsOpen)\r\n    return true;\r\n  bool result = BOOLToBool(::CloseHandle(_handle));\r\n  _fileIsOpen = !result;\r\n  return result;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if(sizeLow == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR) \r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if(!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CreationTime = winFileInfo.ftCreationTime;\r\n  fileInfo.LastAccessTime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.LastWriteTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes; \r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 24);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, creationTime, lastAccessTime, lastWriteTime)); }\r\n\r\nbool COutFile::SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {  return SetTime(NULL, NULL, lastWriteTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if(!Seek(length, newPosition))\r\n    return false;\r\n  if(newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{ \r\n  DWORD    Attributes; \r\n  FILETIME CreationTime; \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime; \r\n  DWORD    VolumeSerialNumber; \r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks; \r\n  UInt64   FileIndex; \r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  bool _fileIsOpen;\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _fileIsOpen(false){};\r\n  virtual ~CFileBase();\r\n\r\n  virtual bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition); \r\n  bool SeekToBegin(); \r\n  bool SeekToEnd(UInt64 &newPosition); \r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/C/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CPL.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n<HTML><HEAD><TITLE>Common Public License - v 1.0</TITLE>\r\n<META http-equiv=Content-Type content=\"text/html; charset=ISO-8859-1\">\r\n<BODY vLink=#800000 bgColor=#ffffff>\r\n<P align=center><B>Common Public License - v 1.0</B> \r\n<P><B></B><FONT size=3></FONT>\r\n<P><FONT size=3></FONT><FONT size=2>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER \r\nTHE TERMS OF THIS COMMON PUBLIC LICENSE (\"AGREEMENT\"). ANY USE, REPRODUCTION OR \r\nDISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS \r\nAGREEMENT.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2><B>1. DEFINITIONS</B></FONT> \r\n<P><FONT size=2>\"Contribution\" means:</FONT> \r\n<UL><FONT size=2>a) in the case of the initial Contributor, the initial code \r\n  and documentation distributed under this Agreement, and<BR clear=left>b) in \r\n  the case of each subsequent Contributor:</FONT></UL>\r\n<UL><FONT size=2>i) changes to the Program, and</FONT></UL>\r\n<UL><FONT size=2>ii) additions to the Program;</FONT></UL>\r\n<UL><FONT size=2>where such changes and/or additions to the Program originate \r\n  from and are distributed by that particular Contributor. </FONT><FONT size=2>A \r\n  Contribution 'originates' from a Contributor if it was added to the Program by \r\n  such Contributor itself or anyone acting on such Contributor's behalf. \r\n  </FONT><FONT size=2>Contributions do not include additions to the Program \r\n  which: (i) are separate modules of software distributed in conjunction with \r\n  the Program under their own license agreement, and (ii) are not derivative \r\n  works of the Program. </FONT></UL>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>\"Contributor\" means any person or entity that distributes the \r\nProgram.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2>\"Licensed Patents \" mean patent claims licensable by a \r\nContributor which are necessarily infringed by the use or sale of its \r\nContribution alone or when combined with the Program. </FONT>\r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2>\"Program\" means the Contributions \r\ndistributed in accordance with this Agreement.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>\"Recipient\" means anyone who receives the Program under this \r\nAgreement, including all Contributors.</FONT> \r\n<P><FONT size=2><B></B></FONT>\r\n<P><FONT size=2><B>2. GRANT OF RIGHTS</B></FONT> \r\n<UL><FONT size=2></FONT><FONT size=2>a) </FONT><FONT size=2>Subject to the \r\n  terms of this Agreement, each Contributor hereby grants</FONT><FONT size=2> \r\n  Recipient a non-exclusive, worldwide, royalty-free copyright license \r\n  to</FONT><FONT color=#ff0000 size=2> </FONT><FONT size=2>reproduce, prepare \r\n  derivative works of, publicly display, publicly perform, distribute and \r\n  sublicense the Contribution of such Contributor, if any, and such derivative \r\n  works, in source code and object code form.</FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2></FONT><FONT size=2>b) Subject to the terms of this \r\n  Agreement, each Contributor hereby grants </FONT><FONT size=2>Recipient a \r\n  non-exclusive, worldwide,</FONT><FONT color=#008000 size=2> </FONT><FONT \r\n  size=2>royalty-free patent license under Licensed Patents to make, use, sell, \r\n  offer to sell, import and otherwise transfer the Contribution of such \r\n  Contributor, if any, in source code and object code form. This patent license \r\n  shall apply to the combination of the Contribution and the Program if, at the \r\n  time the Contribution is added by the Contributor, such addition of the \r\n  Contribution causes such combination to be covered by the Licensed Patents. \r\n  The patent license shall not apply to any other combinations which include the \r\n  Contribution. No hardware per se is licensed hereunder. </FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2>c) Recipient understands that although each Contributor \r\n  grants the licenses to its Contributions set forth herein, no assurances are \r\n  provided by any Contributor that the Program does not infringe the patent or \r\n  other intellectual property rights of any other entity. Each Contributor \r\n  disclaims any liability to Recipient for claims brought by any other entity \r\n  based on infringement of intellectual property rights or otherwise. As a \r\n  condition to exercising the rights and licenses granted hereunder, each \r\n  Recipient hereby assumes sole responsibility to secure any other intellectual \r\n  property rights needed, if any. For example, if a third party patent license \r\n  is required to allow Recipient to distribute the Program, it is Recipient's \r\n  responsibility to acquire that license before distributing the \r\nProgram.</FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2>d) Each Contributor represents that to its knowledge it has \r\n  sufficient copyright rights in its Contribution, if any, to grant the \r\n  copyright license set forth in this Agreement. </FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<P><FONT size=2><B>3. REQUIREMENTS</B></FONT> \r\n<P><FONT size=2><B></B>A Contributor may choose to distribute the Program in \r\nobject code form under its own license agreement, provided that:</FONT> \r\n<UL><FONT size=2>a) it complies with the terms and conditions of this \r\n  Agreement; and</FONT></UL>\r\n<UL><FONT size=2>b) its license agreement:</FONT></UL>\r\n<UL><FONT size=2>i) effectively disclaims</FONT><FONT size=2> on behalf of all \r\n  Contributors all warranties and conditions, express and implied, including \r\n  warranties or conditions of title and non-infringement, and implied warranties \r\n  or conditions of merchantability and fitness for a particular purpose; \r\n</FONT></UL>\r\n<UL><FONT size=2>ii) effectively excludes on behalf of all Contributors all \r\n  liability for damages, including direct, indirect, special, incidental and \r\n  consequential damages, such as lost profits; </FONT></UL>\r\n<UL><FONT size=2>iii)</FONT><FONT size=2> states that any provisions which \r\n  differ from this Agreement are offered by that Contributor alone and not by \r\n  any other party; and</FONT></UL>\r\n<UL><FONT size=2>iv) states that source code for the Program is available from \r\n  such Contributor, and informs licensees how to obtain it in a reasonable \r\n  manner on or through a medium customarily used for software \r\n  exchange.</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 \r\n  size=2></FONT></UL>\r\n<UL><FONT color=#ff0000 size=2></FONT><FONT size=2></FONT></UL>\r\n<P><FONT size=2>When the Program is made available in source code form:</FONT> \r\n<UL><FONT size=2>a) it must be made available under this Agreement; and \r\n</FONT></UL>\r\n<UL><FONT size=2>b) a copy of this Agreement must be included with each copy \r\n  of the Program. </FONT></UL>\r\n<P><FONT size=2></FONT><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT>\r\n<P><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT><FONT size=2>Contributors \r\nmay not remove or alter any copyright notices contained within the Program. \r\n</FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>Each Contributor must identify itself as the originator of its \r\nContribution, if any, in a manner that reasonably allows subsequent Recipients \r\nto identify the originator of the Contribution. </FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2><B>4. COMMERCIAL DISTRIBUTION</B></FONT> \r\n<P><FONT size=2>Commercial distributors of software may accept certain \r\nresponsibilities with respect to end users, business partners and the like. \r\nWhile this license is intended to facilitate the commercial use of the Program, \r\nthe Contributor who includes the Program in a commercial product offering should \r\ndo so in a manner which does not create potential liability for other \r\nContributors. Therefore, if a Contributor includes the Program in a commercial \r\nproduct offering, such Contributor (\"Commercial Contributor\") hereby agrees to \r\ndefend and indemnify every other Contributor (\"Indemnified Contributor\") against \r\nany losses, damages and costs (collectively \"Losses\") arising from claims, \r\nlawsuits and other legal actions brought by a third party against the \r\nIndemnified Contributor to the extent caused by the acts or omissions of such \r\nCommercial Contributor in connection with its distribution of the Program in a \r\ncommercial product offering. The obligations in this section do not apply to any \r\nclaims or Losses relating to any actual or alleged intellectual property \r\ninfringement. In order to qualify, an Indemnified Contributor must: a) promptly \r\nnotify the Commercial Contributor in writing of such claim, and b) allow the \r\nCommercial Contributor to control, and cooperate with the Commercial Contributor \r\nin, the defense and any related settlement negotiations. The Indemnified \r\nContributor may participate in any such claim at its own expense.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>For example, a Contributor might include the Program in a \r\ncommercial product offering, Product X. That Contributor is then a Commercial \r\nContributor. If that Commercial Contributor then makes performance claims, or \r\noffers warranties related to Product X, those performance claims and warranties \r\nare such Commercial Contributor's responsibility alone. Under this section, the \r\nCommercial Contributor would have to defend claims against the other \r\nContributors related to those performance claims and warranties, and if a court \r\nrequires any other Contributor to pay any damages as a result, the Commercial \r\nContributor must pay those damages.</FONT> \r\n<P><FONT size=2></FONT><FONT color=#0000ff size=2></FONT>\r\n<P><FONT color=#0000ff size=2></FONT><FONT size=2><B>5. NO WARRANTY</B></FONT> \r\n<P><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS \r\nPROVIDED ON AN \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r\nEITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR \r\nCONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A \r\nPARTICULAR PURPOSE. Each Recipient is</FONT><FONT size=2> solely responsible for \r\ndetermining the appropriateness of using and distributing </FONT><FONT \r\nsize=2>the Program</FONT><FONT size=2> and assumes all risks associated with its \r\nexercise of rights under this Agreement</FONT><FONT size=2>, including but not \r\nlimited to the risks and costs of program errors, compliance with applicable \r\nlaws, damage to or loss of data, </FONT><FONT size=2>programs or equipment, and \r\nunavailability or interruption of operations</FONT><FONT size=2>. </FONT><FONT \r\nsize=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2><B>6. DISCLAIMER OF LIABILITY</B></FONT> \r\n<P><FONT size=2></FONT><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS \r\nAGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR \r\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r\n</FONT><FONT size=2>(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT \r\nsize=2> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, \r\nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \r\nOUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS \r\nGRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2><B>7. GENERAL</B></FONT> \r\n<P><FONT size=2></FONT><FONT size=2>If any provision of this Agreement is \r\ninvalid or unenforceable under applicable law, it shall not affect the validity \r\nor enforceability of the remainder of the terms of this Agreement, and without \r\nfurther action by the parties hereto, such provision shall be reformed to the \r\nminimum extent necessary to make such provision valid and enforceable.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>If Recipient institutes patent litigation against a Contributor \r\nwith respect to a patent applicable to software (including a cross-claim or \r\ncounterclaim in a lawsuit), then any patent licenses granted by that Contributor \r\nto such Recipient under this Agreement shall terminate as of the date such \r\nlitigation is filed. In addition, if Recipient institutes patent litigation \r\nagainst any entity (including a cross-claim or counterclaim in a lawsuit) \r\nalleging that the Program itself (excluding combinations of the Program with \r\nother software or hardware) infringes such Recipient's patent(s), then such \r\nRecipient's rights granted under Section 2(b) shall terminate as of the date \r\nsuch litigation is filed. </FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>All Recipient's rights under this Agreement shall terminate if \r\nit fails to comply with any of the material terms or conditions of this \r\nAgreement and does not cure such failure in a reasonable period of time after \r\nbecoming aware of such noncompliance. If all Recipient's rights under this \r\nAgreement terminate, Recipient agrees to cease use and distribution of the \r\nProgram as soon as reasonably practicable. However, Recipient's obligations \r\nunder this Agreement and any licenses granted by Recipient relating to the \r\nProgram shall continue and survive. </FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2>Everyone is permitted to copy and distribute \r\ncopies of this Agreement, but in order to avoid inconsistency the Agreement is \r\ncopyrighted and may only be modified in the following manner. The Agreement \r\nSteward reserves the right to </FONT><FONT size=2>publish new versions \r\n(including revisions) of this Agreement from time to </FONT><FONT size=2>time. \r\nNo one other than the Agreement Steward has the right to modify this Agreement. \r\nIBM is the initial Agreement Steward. IBM may assign the responsibility to serve \r\nas the Agreement Steward to a suitable separate entity. </FONT><FONT size=2>Each \r\nnew version of the Agreement will be given a distinguishing version number. The \r\nProgram (including Contributions) may always be distributed subject to the \r\nversion of the Agreement under which it was received. In addition, after a new \r\nversion of the Agreement is published, Contributor may elect to distribute the \r\nProgram (including its Contributions) under the new </FONT><FONT size=2>version. \r\n</FONT><FONT size=2>Except as expressly stated in Sections 2(a) and 2(b) above, \r\nRecipient receives no rights or licenses to the intellectual property of any \r\nContributor under this Agreement, whether expressly, </FONT><FONT size=2>by \r\nimplication, estoppel or otherwise</FONT><FONT size=2>.</FONT><FONT size=2> All \r\nrights in the Program not expressly granted under this Agreement are \r\nreserved.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>This Agreement is governed by the laws of the State of New York \r\nand the intellectual property laws of the United States of America. No party to \r\nthis Agreement will bring a legal action under this Agreement more than one year \r\nafter the cause of action arose. Each party waives its rights to a jury trial in \r\nany resulting litigation.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT></P></BODY></HTML>\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid SetStream(System.IO.Stream inStream);\r\n\t\tvoid Init();\r\n\t\tvoid ReleaseStream();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetMatches(UInt32[] distances);\r\n\t\tvoid Skip(UInt32 num);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize = 0;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\tUInt32[] _son;\r\n\t\tUInt32[] _hash;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\t\tUInt32 _hashMask;\r\n\t\tUInt32 _hashSizeSum = 0;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\r\n\t\tconst UInt32 kHash2Size = 1 << 10;\r\n\t\tconst UInt32 kHash3Size = 1 << 16;\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kStartMaxLen = 1;\r\n\t\tconst UInt32 kHash3Offset = kHash2Size;\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\t\r\n\t\tUInt32 kNumHashDirectBytes = 0;\r\n\t\tUInt32 kMinMatchCheck = 4;\r\n\t\tUInt32 kFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\r\n\t\tpublic void SetType(int numHashBytes)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\t\tkMinMatchCheck = 4;\r\n\t\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\t\tkFixHashSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic new void SetStream(System.IO.Stream stream) { base.SetStream(stream); }\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\t\t\r\n\t\tpublic new void Init()\r\n\t\t{\r\n\t\t\tbase.Init();\r\n\t\t\tfor (UInt32 i = 0; i < _hashSizeSum; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\t\tthrow new Exception();\r\n\t\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\t\t\t\t\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\tUInt32 cyclicBufferSize = historySize + 1;\r\n\t\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t\t_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\t\tUInt32 hs = kBT2HashSize;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\ths = historySize - 1;\r\n\t\t\t\ths |= (hs >> 1);\r\n\t\t\t\ths |= (hs >> 2);\r\n\t\t\t\ths |= (hs >> 4);\r\n\t\t\t\ths |= (hs >> 8);\r\n\t\t\t\ths >>= 1;\r\n\t\t\t\ths |= 0xFFFF;\r\n\t\t\t\tif (hs > (1 << 24))\r\n\t\t\t\t\ths >>= 1;\r\n\t\t\t\t_hashMask = hs;\r\n\t\t\t\ths++;\r\n\t\t\t\ths += kFixHashSize;\r\n\t\t\t}\r\n\t\t\tif (hs != _hashSizeSum)\r\n\t\t\t\t_hash = new UInt32[_hashSizeSum = hs];\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetMatches(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 offset = 0;\r\n\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\t\t\tUInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 curMatch2 = _hash[hash2Value];\r\n\t\t\t\tUInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t\t{\r\n\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\t\t\t\r\n\t\t\tif (kNumHashDirectBytes != 0)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\r\n\t\t\twhile(true)\r\n\t\t\t{\r\n\t\t\t\tif(curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (maxLen < len)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t\treturn offset;\r\n\t\t}\r\n\r\n\t\tpublic void Skip(UInt32 num)\r\n\t\t{\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenLimit;\r\n\t\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tMovePos();\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\t\tUInt32 hashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\t\tUInt32 hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\t\tUInt32 hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\t\tUInt32 len0, len1;\r\n\t\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\t\tlen1 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\t\tlen0 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tMovePos();\r\n\t\t\t}\r\n\t\t\twhile (--num != 0);\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 subValue = _pos - _cyclicBufferSize;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize; // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos; // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos\r\n\t\tpublic UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\t\tif (offset > 0)\r\n\t\t\t\toffset--;\r\n\t\t\t\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { _stream = stream; }\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream) { Init(stream, false); }\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t\tpublic bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\t// public const int kDicLogSizeMax = 30;\r\n\t\t// public const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get { return 0; }}\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t};\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1 << 11];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 22;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 11))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 21))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 10] + 20);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 20] + 40);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 17))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 27))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 16] + 32);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 26] + 52);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 22;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32[] prices, UInt32 st)\r\n\t\t\t{\r\n\t\t\t\tUInt32 a0 = _choice.GetPrice0();\r\n\t\t\t\tUInt32 a1 = _choice.GetPrice1();\r\n\t\t\t\tUInt32 b0 = a1 + _choice2.GetPrice0();\r\n\t\t\t\tUInt32 b1 = a1 + _choice2.GetPrice1();\r\n\t\t\t\tUInt32 i = 0;\r\n\t\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\tLZ.IMatchFinder _matchFinder = null;\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates];\r\n\t\t\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];\r\n\t\t\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _numDistancePairs;\r\n\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\t\tSystem.IO.Stream _inStream;\r\n\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark = false;\r\n\t\t\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tif (_matchFinderType == EMatchFinderType.BT2)\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs)\r\n\t\t{\r\n\t\t\tlenRes = 0;\r\n\t\t\tnumDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\t\tif (numDistancePairs > 0)\r\n\t\t\t{\r\n\t\t\t\tlenRes = _matchDistances[numDistancePairs - 2];\r\n\t\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t}\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tif (num > 0)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Skip(num);\r\n\t\t\t\t_additionalOffset += num;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t\t}\r\n\t\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\t\tUInt32 lenMain, numDistancePairs;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain, out numDistancePairs);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\t\t\t\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = (UInt32)0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\t\tif(lenEnd < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\t\tUInt32 len = lenEnd;\r\n\t\t\tdo\r\n\t\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\t\twhile (len >= 2);\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tif (repLen < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tUInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--repLen >= 2);\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\t\t\t\r\n\t\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\t\tif (len <= lenMain)\r\n\t\t\t{\r\n\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\tfor (; ; len++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 distance = _matchDistances[offs + 1];\r\n\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen, out numDistancePairs);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_numDistancePairs = numDistancePairs;\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t\t{\r\n\t\t\t\t\t// try Literal + rep0\r\n\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 startLen = 2; // speed optimization \r\n\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t\t// if (_maxMode)\r\n\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, reps[repIndex], t);\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)(reps[repIndex] + 1))), \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t\t}\r\n\t\t\t\tif (newLen >= startLen)\r\n\t\t\t\t{\r\n\t\t\t\t\tnormalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = startLen; ; lenTest++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t);\r\n\t\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)(curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t\t_matchFinder.Init();\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len, numDistancePairs; // it's not used\r\n\t\t\t\tReadMatchDistances(out len, out numDistancePairs);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 len = GetOptimum((UInt32)nowPos64, out pos);\r\n\t\t\t\t\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t// if (!_fastMode)\r\n\t\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// if (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\t\t\r\n\t\tUInt32[] tempPrices = new UInt32[Base.kNumFullDistances];\r\n\t\tUInt32 _matchPriceCount;\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t\t{ \r\n\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, \r\n\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tRangeCoder.BitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\t\t\t\r\n\t\t\t\tUInt32 st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\t\tUInt32 st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t\t}\r\n\t\t\t_matchPriceCount = 0;\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = 0;\r\n\t\t}\r\n\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t/*\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t*/\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 30;\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0, 29], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.42 Copyright (c) 1999-2006 Igor Pavlov  2006-05-15\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[12];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary);\r\n\t\t\t}\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tFileStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.50727</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tUInt32 Rep0;\r\n\t\t\t\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\t\tUInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\tRG.Init();\r\n\t\t\t\tRep0 = 1;\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)RG.GetRnd(8);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 len;\r\n\t\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\t\tUInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 220 + outSize * 20;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 18))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "// LZ.BinTree\r\n\r\npackage SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\r\n\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize = 0;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\tint[] _hash;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\tint _hashMask;\r\n\tint _hashSizeSum = 0;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\r\n\tstatic final int kHash2Size = 1 << 10;\r\n\tstatic final int kHash3Size = 1 << 16;\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kStartMaxLen = 1;\r\n\tstatic final int kHash3Offset = kHash2Size;\r\n\tstatic final int kEmptyHashValue = 0;\r\n\tstatic final int kMaxValForNormalize = (1 << 30) - 1;\r\n\t\r\n\tint kNumHashDirectBytes = 0;\r\n\tint kMinMatchCheck = 4;\r\n\tint kFixHashSize = kHash2Size + kHash3Size;\r\n\r\n\tpublic void SetType(int numHashBytes)\r\n\t{\r\n\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\tkMinMatchCheck = 4;\r\n\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\tkFixHashSize = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tfor (int i = 0; i < _hashSizeSum; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\treturn false;\r\n\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\tint cyclicBufferSize = historySize + 1;\r\n\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t_son = new int[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\tint hs = kBT2HashSize;\r\n\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\ths = historySize - 1;\r\n\t\t\ths |= (hs >> 1);\r\n\t\t\ths |= (hs >> 2);\r\n\t\t\ths |= (hs >> 4);\r\n\t\t\ths |= (hs >> 8);\r\n\t\t\ths >>= 1;\r\n\t\t\ths |= 0xFFFF;\r\n\t\t\tif (hs > (1 << 24))\r\n\t\t\t\ths >>= 1;\r\n\t\t\t_hashMask = hs;\r\n\t\t\ths++;\r\n\t\t\ths += kFixHashSize;\r\n\t\t}\r\n\t\tif (hs != _hashSizeSum)\r\n\t\t\t_hash = new int [_hashSizeSum = hs];\r\n\t\treturn true;\r\n\t}\r\n\tpublic int GetMatches(int[] distances) throws IOException\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t{\r\n\t\t\t\tMovePos();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint offset = 0;\r\n\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\tint maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint curMatch2 = _hash[hash2Value];\r\n\t\t\tint curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t}\r\n\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t}\r\n\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t{\r\n\t\t\t\toffset -= 2;\r\n\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\tint len0, len1;\r\n\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\tif (kNumHashDirectBytes != 0)\r\n\t\t{\r\n\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint count = _cutValue;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint len = Math.min(len0, len1);\r\n\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t{\r\n\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tif (maxLen < len)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t{\r\n\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\tlen1 = len;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\tlen0 = len;\r\n\t\t\t}\r\n\t\t}\r\n\t\tMovePos();\r\n\t\treturn offset;\r\n\t}\r\n\r\n\tpublic void Skip(int num) throws IOException\r\n\t{\r\n\t\tdo\r\n\t\t{\r\n\t\t\tint lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tint cur = _bufferOffset + _pos;\r\n\t\t\t\r\n\t\t\tint hashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\t\tint hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\t\tint hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tint len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\tint count = _cutValue;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tint len = Math.min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t}\r\n\t\twhile (--num != 0);\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint subValue = _pos - _cyclicBufferSize;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue) { _cutValue = cutValue; }\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\tif (offset > 0)\r\n\t\t\toffset--;\r\n\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free() { _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream) { _stream = stream; \t}\r\n\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\t// public static final int kDicLogSizeMax = 28;\r\n\t// public static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\r\n\r\n\r\n\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\r\n\tstatic byte[] g_FastPos = new byte[1 << 11];\r\n\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 22;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 11))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 21))\r\n\t\t\treturn (g_FastPos[pos >> 10] + 20);\r\n\t\treturn (g_FastPos[pos >> 20] + 40);\r\n\t}\r\n\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 17))\r\n\t\t\treturn (g_FastPos[pos >> 6] + 12);\r\n\t\tif (pos < (1 << 27))\r\n\t\t\treturn (g_FastPos[pos >> 16] + 32);\r\n\t\treturn (g_FastPos[pos >> 26] + 52);\r\n\t}\r\n\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\r\n\tstatic final int kDefaultDictionaryLogSize = 22;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\r\n\t\t\tpublic void Init() { SevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders); }\r\n\r\n\r\n\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetPrices(int posState, int numSymbols, int[] prices, int st)\r\n\t\t{\r\n\t\t\tint a0 = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\tint a1 = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\tint b0 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\tint b1 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\tint i = 0;\r\n\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t}\r\n\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t}\r\n\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t}\r\n\t};\r\n\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols<<Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\tpublic void SetTableSize(int tableSize) { _tableSize = tableSize; }\r\n\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t}\r\n\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\r\n\tstatic final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;\r\n\t\tpublic int BackPrev;\r\n\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\r\n\t\tpublic void MakeAsChar() { BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep() { return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null;\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\r\n\tshort[] _isMatch = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances-Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen*2+2];\r\n\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _numDistancePairs;\r\n\r\n\tint _additionalOffset;\r\n\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\r\n\tboolean _longestMatchWasFound;\r\n\r\n\tint[] _posSlotPrices = new int[1<<(Base.kNumPosSlotBits+Base.kNumLenToPosStatesBits)];\r\n\tint[] _distancesPrices = new int[Base.kNumFullDistances<<Base.kNumLenToPosStatesBits];\r\n\tint[] _alignPrices = new int[Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\tjava.io.InputStream _inStream;\r\n\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\r\n\tboolean _needReleaseMFStream = false;\r\n\r\n\tvoid Create()\r\n\t{\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tif (_matchFinderType == EMatchFinderTypeBT2)\r\n\t\t\t\tnumHashBytes = 2;\r\n\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\r\n\tvoid SetWriteEndMarkerMode(boolean writeEndMarker)\r\n\t{\r\n\t\t_writeEndMark = writeEndMarker;\r\n\t}\r\n\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\r\n\r\n\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n\t\t_posAlignEncoder.Init();\r\n\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = 0;\r\n\t\t_numDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\tif (_numDistancePairs > 0)\r\n\t\t{\r\n\t\t\tlenRes = _matchDistances[_numDistancePairs - 2];\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[_numDistancePairs - 1],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t}\r\n\t\t_additionalOffset++;\r\n\t\treturn lenRes;\r\n\t}\r\n\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tif (num > 0)\r\n\t\t{\r\n\t\t\t_matchFinder.Skip(num);\r\n\t\t\t_additionalOffset += num;\r\n\t\t}\r\n\t}\r\n\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\r\n\tint GetPureRepPrice(int repIndex, int state, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t}\r\n\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\r\n\tint Backward(int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\tint backRes;\r\n\r\n\tint GetOptimum(int position) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\tint lenMain, numDistancePairs;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tnumDistancePairs = _numDistancePairs;\r\n\r\n\t\tint numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\tif (numAvailableBytes < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\tbyte matchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[0].State = _state;\r\n\r\n\t\tint posState = (position & _posStateMask);\r\n\r\n\t\t_optimum[1].Price = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\tif (lenEnd < 2)\r\n\t\t{\r\n\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\tint len = lenEnd;\r\n\t\tdo\r\n\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\twhile (len >= 2);\r\n\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tif (repLen < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tint price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twhile (--repLen >= 2);\r\n\t\t}\r\n\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\r\n\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\tif (len <= lenMain)\r\n\t\t{\r\n\t\t\tint offs = 0;\r\n\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\toffs += 2;\r\n\t\t\tfor (; ; len++)\r\n\t\t\t{\r\n\t\t\t\tint distance = _matchDistances[offs + 1];\r\n\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t{\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint cur = 0;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\r\n\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t{\r\n\t\t\t\t// try Literal + rep0\r\n\t\t\t\tint t = Math.min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint startLen = 2; // speed optimization \r\n\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\tint lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t// if (_maxMode)\r\n\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t{\r\n\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, reps[repIndex], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - (reps[repIndex] + 1)),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t{\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t}\r\n\t\t\tif (newLen >= startLen)\r\n\t\t\t{\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\tint offs = 0;\r\n\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\tfor (int lenTest = startLen; ; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, curBack, t);\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\r\n\t\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - (curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\r\n\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\r\n\t\t\tint len = GetOptimum((int)nowPos64);\r\n\t\t\tint pos = backRes;\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\t// if (!_fastMode)\r\n\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\r\n\t\t// if (!_fastMode)\r\n\t\t{\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\r\n\tlong[] processedInSize = new long[1]; long[] processedOutSize = new long[1]; boolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\r\n\r\n\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\r\n\tint[] tempPrices = new int[Base.kNumFullDistances];\r\n\tint _matchPriceCount;\r\n\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t{\r\n\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t}\r\n\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tBitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\r\n\t\t\tint st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\tint st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t}\r\n\t\t_matchPriceCount = 0;\r\n\t}\r\n\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = 0;\r\n\t}\r\n\r\n\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\t/*\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\t*/\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = 29;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++) ;\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SeNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.42 Copyright (c) 1999-2006 Igor Pavlov  2006-05-15\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SeNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator() { Init(); }\r\n\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tint Rep0;\r\n\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\r\n\t\tpublic CBenchRandomGenerator() { }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit() { return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\tint GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\tRG.Init();\r\n\t\t\tRep0 = 1;\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint len;\r\n\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, long elapsedTime, long size)\r\n\t{\r\n\t\tlong t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\tlong numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime, long outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 220 + outSize * 20;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 18))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 18 (256 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/LGPL.txt",
    "content": "      GNU LESSER GENERAL PUBLIC LICENSE\r\n           Version 2.1, February 1999\r\n\r\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\r\n     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n Everyone is permitted to copy and distribute verbatim copies\r\n of this license document, but changing it is not allowed.\r\n\r\n[This is the first released version of the Lesser GPL.  It also counts\r\n as the successor of the GNU Library Public License, version 2, hence\r\n the version number 2.1.]\r\n\r\n          Preamble\r\n\r\n  The licenses for most software are designed to take away your\r\nfreedom to share and change it.  By contrast, the GNU General Public\r\nLicenses are intended to guarantee your freedom to share and change\r\nfree software--to make sure the software is free for all its users.\r\n\r\n  This license, the Lesser General Public License, applies to some\r\nspecially designated software packages--typically libraries--of the\r\nFree Software Foundation and other authors who decide to use it.  You\r\ncan use it too, but we suggest you first think carefully about whether\r\nthis license or the ordinary General Public License is the better\r\nstrategy to use in any particular case, based on the explanations below.\r\n\r\n  When we speak of free software, we are referring to freedom of use,\r\nnot price.  Our General Public Licenses are designed to make sure that\r\nyou have the freedom to distribute copies of free software (and charge\r\nfor this service if you wish); that you receive source code or can get\r\nit if you want it; that you can change the software and use pieces of\r\nit in new free programs; and that you are informed that you can do\r\nthese things.\r\n\r\n  To protect your rights, we need to make restrictions that forbid\r\ndistributors to deny you these rights or to ask you to surrender these\r\nrights.  These restrictions translate to certain responsibilities for\r\nyou if you distribute copies of the library or if you modify it.\r\n\r\n  For example, if you distribute copies of the library, whether gratis\r\nor for a fee, you must give the recipients all the rights that we gave\r\nyou.  You must make sure that they, too, receive or can get the source\r\ncode.  If you link other code with the library, you must provide\r\ncomplete object files to the recipients, so that they can relink them\r\nwith the library after making changes to the library and recompiling\r\nit.  And you must show them these terms so they know their rights.\r\n\r\n  We protect your rights with a two-step method: (1) we copyright the\r\nlibrary, and (2) we offer you this license, which gives you legal\r\npermission to copy, distribute and/or modify the library.\r\n\r\n  To protect each distributor, we want to make it very clear that\r\nthere is no warranty for the free library.  Also, if the library is\r\nmodified by someone else and passed on, the recipients should know\r\nthat what they have is not the original version, so that the original\r\nauthor's reputation will not be affected by problems that might be\r\nintroduced by others.\r\n\f\r\n  Finally, software patents pose a constant threat to the existence of\r\nany free program.  We wish to make sure that a company cannot\r\neffectively restrict the users of a free program by obtaining a\r\nrestrictive license from a patent holder.  Therefore, we insist that\r\nany patent license obtained for a version of the library must be\r\nconsistent with the full freedom of use specified in this license.\r\n\r\n  Most GNU software, including some libraries, is covered by the\r\nordinary GNU General Public License.  This license, the GNU Lesser\r\nGeneral Public License, applies to certain designated libraries, and\r\nis quite different from the ordinary General Public License.  We use\r\nthis license for certain libraries in order to permit linking those\r\nlibraries into non-free programs.\r\n\r\n  When a program is linked with a library, whether statically or using\r\na shared library, the combination of the two is legally speaking a\r\ncombined work, a derivative of the original library.  The ordinary\r\nGeneral Public License therefore permits such linking only if the\r\nentire combination fits its criteria of freedom.  The Lesser General\r\nPublic License permits more lax criteria for linking other code with\r\nthe library.\r\n\r\n  We call this license the \"Lesser\" General Public License because it\r\ndoes Less to protect the user's freedom than the ordinary General\r\nPublic License.  It also provides other free software developers Less\r\nof an advantage over competing non-free programs.  These disadvantages\r\nare the reason we use the ordinary General Public License for many\r\nlibraries.  However, the Lesser license provides advantages in certain\r\nspecial circumstances.\r\n\r\n  For example, on rare occasions, there may be a special need to\r\nencourage the widest possible use of a certain library, so that it becomes\r\na de-facto standard.  To achieve this, non-free programs must be\r\nallowed to use the library.  A more frequent case is that a free\r\nlibrary does the same job as widely used non-free libraries.  In this\r\ncase, there is little to gain by limiting the free library to free\r\nsoftware only, so we use the Lesser General Public License.\r\n\r\n  In other cases, permission to use a particular library in non-free\r\nprograms enables a greater number of people to use a large body of\r\nfree software.  For example, permission to use the GNU C Library in\r\nnon-free programs enables many more people to use the whole GNU\r\noperating system, as well as its variant, the GNU/Linux operating\r\nsystem.\r\n\r\n  Although the Lesser General Public License is Less protective of the\r\nusers' freedom, it does ensure that the user of a program that is\r\nlinked with the Library has the freedom and the wherewithal to run\r\nthat program using a modified version of the Library.\r\n\r\n  The precise terms and conditions for copying, distribution and\r\nmodification follow.  Pay close attention to the difference between a\r\n\"work based on the library\" and a \"work that uses the library\".  The\r\nformer contains code derived from the library, whereas the latter must\r\nbe combined with the library in order to run.\r\n\f\r\n      GNU LESSER GENERAL PUBLIC LICENSE\r\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\r\n\r\n  0. This License Agreement applies to any software library or other\r\nprogram which contains a notice placed by the copyright holder or\r\nother authorized party saying it may be distributed under the terms of\r\nthis Lesser General Public License (also called \"this License\").\r\nEach licensee is addressed as \"you\".\r\n\r\n  A \"library\" means a collection of software functions and/or data\r\nprepared so as to be conveniently linked with application programs\r\n(which use some of those functions and data) to form executables.\r\n\r\n  The \"Library\", below, refers to any such software library or work\r\nwhich has been distributed under these terms.  A \"work based on the\r\nLibrary\" means either the Library or any derivative work under\r\ncopyright law: that is to say, a work containing the Library or a\r\nportion of it, either verbatim or with modifications and/or translated\r\nstraightforwardly into another language.  (Hereinafter, translation is\r\nincluded without limitation in the term \"modification\".)\r\n\r\n  \"Source code\" for a work means the preferred form of the work for\r\nmaking modifications to it.  For a library, complete source code means\r\nall the source code for all modules it contains, plus any associated\r\ninterface definition files, plus the scripts used to control compilation\r\nand installation of the library.\r\n\r\n  Activities other than copying, distribution and modification are not\r\ncovered by this License; they are outside its scope.  The act of\r\nrunning a program using the Library is not restricted, and output from\r\nsuch a program is covered only if its contents constitute a work based\r\non the Library (independent of the use of the Library in a tool for\r\nwriting it).  Whether that is true depends on what the Library does\r\nand what the program that uses the Library does.\r\n  \r\n  1. You may copy and distribute verbatim copies of the Library's\r\ncomplete source code as you receive it, in any medium, provided that\r\nyou conspicuously and appropriately publish on each copy an\r\nappropriate copyright notice and disclaimer of warranty; keep intact\r\nall the notices that refer to this License and to the absence of any\r\nwarranty; and distribute a copy of this License along with the\r\nLibrary.\r\n\r\n  You may charge a fee for the physical act of transferring a copy,\r\nand you may at your option offer warranty protection in exchange for a\r\nfee.\r\n\f\r\n  2. You may modify your copy or copies of the Library or any portion\r\nof it, thus forming a work based on the Library, and copy and\r\ndistribute such modifications or work under the terms of Section 1\r\nabove, provided that you also meet all of these conditions:\r\n\r\n    a) The modified work must itself be a software library.\r\n\r\n    b) You must cause the files modified to carry prominent notices\r\n    stating that you changed the files and the date of any change.\r\n\r\n    c) You must cause the whole of the work to be licensed at no\r\n    charge to all third parties under the terms of this License.\r\n\r\n    d) If a facility in the modified Library refers to a function or a\r\n    table of data to be supplied by an application program that uses\r\n    the facility, other than as an argument passed when the facility\r\n    is invoked, then you must make a good faith effort to ensure that,\r\n    in the event an application does not supply such function or\r\n    table, the facility still operates, and performs whatever part of\r\n    its purpose remains meaningful.\r\n\r\n    (For example, a function in a library to compute square roots has\r\n    a purpose that is entirely well-defined independent of the\r\n    application.  Therefore, Subsection 2d requires that any\r\n    application-supplied function or table used by this function must\r\n    be optional: if the application does not supply it, the square\r\n    root function must still compute square roots.)\r\n\r\nThese requirements apply to the modified work as a whole.  If\r\nidentifiable sections of that work are not derived from the Library,\r\nand can be reasonably considered independent and separate works in\r\nthemselves, then this License, and its terms, do not apply to those\r\nsections when you distribute them as separate works.  But when you\r\ndistribute the same sections as part of a whole which is a work based\r\non the Library, the distribution of the whole must be on the terms of\r\nthis License, whose permissions for other licensees extend to the\r\nentire whole, and thus to each and every part regardless of who wrote\r\nit.\r\n\r\nThus, it is not the intent of this section to claim rights or contest\r\nyour rights to work written entirely by you; rather, the intent is to\r\nexercise the right to control the distribution of derivative or\r\ncollective works based on the Library.\r\n\r\nIn addition, mere aggregation of another work not based on the Library\r\nwith the Library (or with a work based on the Library) on a volume of\r\na storage or distribution medium does not bring the other work under\r\nthe scope of this License.\r\n\r\n  3. You may opt to apply the terms of the ordinary GNU General Public\r\nLicense instead of this License to a given copy of the Library.  To do\r\nthis, you must alter all the notices that refer to this License, so\r\nthat they refer to the ordinary GNU General Public License, version 2,\r\ninstead of to this License.  (If a newer version than version 2 of the\r\nordinary GNU General Public License has appeared, then you can specify\r\nthat version instead if you wish.)  Do not make any other change in\r\nthese notices.\r\n\f\r\n  Once this change is made in a given copy, it is irreversible for\r\nthat copy, so the ordinary GNU General Public License applies to all\r\nsubsequent copies and derivative works made from that copy.\r\n\r\n  This option is useful when you wish to copy part of the code of\r\nthe Library into a program that is not a library.\r\n\r\n  4. You may copy and distribute the Library (or a portion or\r\nderivative of it, under Section 2) in object code or executable form\r\nunder the terms of Sections 1 and 2 above provided that you accompany\r\nit with the complete corresponding machine-readable source code, which\r\nmust be distributed under the terms of Sections 1 and 2 above on a\r\nmedium customarily used for software interchange.\r\n\r\n  If distribution of object code is made by offering access to copy\r\nfrom a designated place, then offering equivalent access to copy the\r\nsource code from the same place satisfies the requirement to\r\ndistribute the source code, even though third parties are not\r\ncompelled to copy the source along with the object code.\r\n\r\n  5. A program that contains no derivative of any portion of the\r\nLibrary, but is designed to work with the Library by being compiled or\r\nlinked with it, is called a \"work that uses the Library\".  Such a\r\nwork, in isolation, is not a derivative work of the Library, and\r\ntherefore falls outside the scope of this License.\r\n\r\n  However, linking a \"work that uses the Library\" with the Library\r\ncreates an executable that is a derivative of the Library (because it\r\ncontains portions of the Library), rather than a \"work that uses the\r\nlibrary\".  The executable is therefore covered by this License.\r\nSection 6 states terms for distribution of such executables.\r\n\r\n  When a \"work that uses the Library\" uses material from a header file\r\nthat is part of the Library, the object code for the work may be a\r\nderivative work of the Library even though the source code is not.\r\nWhether this is true is especially significant if the work can be\r\nlinked without the Library, or if the work is itself a library.  The\r\nthreshold for this to be true is not precisely defined by law.\r\n\r\n  If such an object file uses only numerical parameters, data\r\nstructure layouts and accessors, and small macros and small inline\r\nfunctions (ten lines or less in length), then the use of the object\r\nfile is unrestricted, regardless of whether it is legally a derivative\r\nwork.  (Executables containing this object code plus portions of the\r\nLibrary will still fall under Section 6.)\r\n\r\n  Otherwise, if the work is a derivative of the Library, you may\r\ndistribute the object code for the work under the terms of Section 6.\r\nAny executables containing that work also fall under Section 6,\r\nwhether or not they are linked directly with the Library itself.\r\n\f\r\n  6. As an exception to the Sections above, you may also combine or\r\nlink a \"work that uses the Library\" with the Library to produce a\r\nwork containing portions of the Library, and distribute that work\r\nunder terms of your choice, provided that the terms permit\r\nmodification of the work for the customer's own use and reverse\r\nengineering for debugging such modifications.\r\n\r\n  You must give prominent notice with each copy of the work that the\r\nLibrary is used in it and that the Library and its use are covered by\r\nthis License.  You must supply a copy of this License.  If the work\r\nduring execution displays copyright notices, you must include the\r\ncopyright notice for the Library among them, as well as a reference\r\ndirecting the user to the copy of this License.  Also, you must do one\r\nof these things:\r\n\r\n    a) Accompany the work with the complete corresponding\r\n    machine-readable source code for the Library including whatever\r\n    changes were used in the work (which must be distributed under\r\n    Sections 1 and 2 above); and, if the work is an executable linked\r\n    with the Library, with the complete machine-readable \"work that\r\n    uses the Library\", as object code and/or source code, so that the\r\n    user can modify the Library and then relink to produce a modified\r\n    executable containing the modified Library.  (It is understood\r\n    that the user who changes the contents of definitions files in the\r\n    Library will not necessarily be able to recompile the application\r\n    to use the modified definitions.)\r\n\r\n    b) Use a suitable shared library mechanism for linking with the\r\n    Library.  A suitable mechanism is one that (1) uses at run time a\r\n    copy of the library already present on the user's computer system,\r\n    rather than copying library functions into the executable, and (2)\r\n    will operate properly with a modified version of the library, if\r\n    the user installs one, as long as the modified version is\r\n    interface-compatible with the version that the work was made with.\r\n\r\n    c) Accompany the work with a written offer, valid for at\r\n    least three years, to give the same user the materials\r\n    specified in Subsection 6a, above, for a charge no more\r\n    than the cost of performing this distribution.\r\n\r\n    d) If distribution of the work is made by offering access to copy\r\n    from a designated place, offer equivalent access to copy the above\r\n    specified materials from the same place.\r\n\r\n    e) Verify that the user has already received a copy of these\r\n    materials or that you have already sent this user a copy.\r\n\r\n  For an executable, the required form of the \"work that uses the\r\nLibrary\" must include any data and utility programs needed for\r\nreproducing the executable from it.  However, as a special exception,\r\nthe materials to be distributed need not include anything that is\r\nnormally distributed (in either source or binary form) with the major\r\ncomponents (compiler, kernel, and so on) of the operating system on\r\nwhich the executable runs, unless that component itself accompanies\r\nthe executable.\r\n\r\n  It may happen that this requirement contradicts the license\r\nrestrictions of other proprietary libraries that do not normally\r\naccompany the operating system.  Such a contradiction means you cannot\r\nuse both them and the Library together in an executable that you\r\ndistribute.\r\n\f\r\n  7. You may place library facilities that are a work based on the\r\nLibrary side-by-side in a single library together with other library\r\nfacilities not covered by this License, and distribute such a combined\r\nlibrary, provided that the separate distribution of the work based on\r\nthe Library and of the other library facilities is otherwise\r\npermitted, and provided that you do these two things:\r\n\r\n    a) Accompany the combined library with a copy of the same work\r\n    based on the Library, uncombined with any other library\r\n    facilities.  This must be distributed under the terms of the\r\n    Sections above.\r\n\r\n    b) Give prominent notice with the combined library of the fact\r\n    that part of it is a work based on the Library, and explaining\r\n    where to find the accompanying uncombined form of the same work.\r\n\r\n  8. You may not copy, modify, sublicense, link with, or distribute\r\nthe Library except as expressly provided under this License.  Any\r\nattempt otherwise to copy, modify, sublicense, link with, or\r\ndistribute the Library is void, and will automatically terminate your\r\nrights under this License.  However, parties who have received copies,\r\nor rights, from you under this License will not have their licenses\r\nterminated so long as such parties remain in full compliance.\r\n\r\n  9. You are not required to accept this License, since you have not\r\nsigned it.  However, nothing else grants you permission to modify or\r\ndistribute the Library or its derivative works.  These actions are\r\nprohibited by law if you do not accept this License.  Therefore, by\r\nmodifying or distributing the Library (or any work based on the\r\nLibrary), you indicate your acceptance of this License to do so, and\r\nall its terms and conditions for copying, distributing or modifying\r\nthe Library or works based on it.\r\n\r\n  10. Each time you redistribute the Library (or any work based on the\r\nLibrary), the recipient automatically receives a license from the\r\noriginal licensor to copy, distribute, link with or modify the Library\r\nsubject to these terms and conditions.  You may not impose any further\r\nrestrictions on the recipients' exercise of the rights granted herein.\r\nYou are not responsible for enforcing compliance by third parties with\r\nthis License.\r\n\f\r\n  11. If, as a consequence of a court judgment or allegation of patent\r\ninfringement or for any other reason (not limited to patent issues),\r\nconditions are imposed on you (whether by court order, agreement or\r\notherwise) that contradict the conditions of this License, they do not\r\nexcuse you from the conditions of this License.  If you cannot\r\ndistribute so as to satisfy simultaneously your obligations under this\r\nLicense and any other pertinent obligations, then as a consequence you\r\nmay not distribute the Library at all.  For example, if a patent\r\nlicense would not permit royalty-free redistribution of the Library by\r\nall those who receive copies directly or indirectly through you, then\r\nthe only way you could satisfy both it and this License would be to\r\nrefrain entirely from distribution of the Library.\r\n\r\nIf any portion of this section is held invalid or unenforceable under any\r\nparticular circumstance, the balance of the section is intended to apply,\r\nand the section as a whole is intended to apply in other circumstances.\r\n\r\nIt is not the purpose of this section to induce you to infringe any\r\npatents or other property right claims or to contest validity of any\r\nsuch claims; this section has the sole purpose of protecting the\r\nintegrity of the free software distribution system which is\r\nimplemented by public license practices.  Many people have made\r\ngenerous contributions to the wide range of software distributed\r\nthrough that system in reliance on consistent application of that\r\nsystem; it is up to the author/donor to decide if he or she is willing\r\nto distribute software through any other system and a licensee cannot\r\nimpose that choice.\r\n\r\nThis section is intended to make thoroughly clear what is believed to\r\nbe a consequence of the rest of this License.\r\n\r\n  12. If the distribution and/or use of the Library is restricted in\r\ncertain countries either by patents or by copyrighted interfaces, the\r\noriginal copyright holder who places the Library under this License may add\r\nan explicit geographical distribution limitation excluding those countries,\r\nso that distribution is permitted only in or among countries not thus\r\nexcluded.  In such case, this License incorporates the limitation as if\r\nwritten in the body of this License.\r\n\r\n  13. The Free Software Foundation may publish revised and/or new\r\nversions of the Lesser General Public License from time to time.\r\nSuch new versions will be similar in spirit to the present version,\r\nbut may differ in detail to address new problems or concerns.\r\n\r\nEach version is given a distinguishing version number.  If the Library\r\nspecifies a version number of this License which applies to it and\r\n\"any later version\", you have the option of following the terms and\r\nconditions either of that version or of any later version published by\r\nthe Free Software Foundation.  If the Library does not specify a\r\nlicense version number, you may choose any version ever published by\r\nthe Free Software Foundation.\r\n\f\r\n  14. If you wish to incorporate parts of the Library into other free\r\nprograms whose distribution conditions are incompatible with these,\r\nwrite to the author to ask for permission.  For software which is\r\ncopyrighted by the Free Software Foundation, write to the Free\r\nSoftware Foundation; we sometimes make exceptions for this.  Our\r\ndecision will be guided by the two goals of preserving the free status\r\nof all derivatives of our free software and of promoting the sharing\r\nand reuse of software generally.\r\n\r\n          NO WARRANTY\r\n\r\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\r\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\r\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\r\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\r\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\r\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\r\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\r\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\r\n\r\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\r\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\r\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\r\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\r\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\r\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\r\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\r\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\r\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\r\nDAMAGES.\r\n\r\n         END OF TERMS AND CONDITIONS\r\n\f\r\n           How to Apply These Terms to Your New Libraries\r\n\r\n  If you develop a new library, and you want it to be of the greatest\r\npossible use to the public, we recommend making it free software that\r\neveryone can redistribute and change.  You can do so by permitting\r\nredistribution under these terms (or, alternatively, under the terms of the\r\nordinary General Public License).\r\n\r\n  To apply these terms, attach the following notices to the library.  It is\r\nsafest to attach them to the start of each source file to most effectively\r\nconvey the exclusion of warranty; and each file should have at least the\r\n\"copyright\" line and a pointer to where the full notice is found.\r\n\r\n    <one line to give the library's name and a brief idea of what it does.>\r\n    Copyright (C) <year>  <name of author>\r\n\r\n    This library is free software; you can redistribute it and/or\r\n    modify it under the terms of the GNU Lesser General Public\r\n    License as published by the Free Software Foundation; either\r\n    version 2.1 of the License, or (at your option) any later version.\r\n\r\n    This library is distributed in the hope that it will be useful,\r\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r\n    Lesser General Public License for more details.\r\n\r\n    You should have received a copy of the GNU Lesser General Public\r\n    License along with this library; if not, write to the Free Software\r\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nAlso add information on how to contact you by electronic and paper mail.\r\n\r\nYou should also get your employer (if you work as a programmer) or your\r\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\r\nnecessary.  Here is a sample; alter the names:\r\n\r\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\r\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\r\n\r\n  <signature of Ty Coon>, 1 April 1990\r\n  Ty Coon, President of Vice\r\n\r\nThat's all there is to it!\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/Methods.txt",
    "content": "Compression method IDs (4.38)\r\n-----------------------------\r\n\r\nEach compression method in 7z has unique binary value (ID).\r\nThe length of ID in bytes is arbitrary but it can not exceed 15 bytes.\r\n\r\nIf you want to add some new ID, you have two ways:\r\n1) Write request for allocating IDs to 7-zip developers.\r\n2) Use such random ID:\r\n  03 E0  ZZ ... ZZ  MM ... MM  VV ... VV\r\n\r\n    ZZ != 0, MM != 0, VV != 0\r\n\r\n    03 E0      - Prefix for random IDs \r\n    ZZ ... ZZ  - Developer ID. (length >= 4). Use real random bytes.\r\n                 You can notify 7-Zip developers about your Developer ID.\r\n    MM ... MM  - Method ID (length >= 1)\r\n    VV ... VV  - Version  (length >= 1)\r\n\r\n    Note: Use new ID (MM ... MM  VV .. VV) only if old codec can not decode \r\n    data encoded with new version.\r\n\r\n\r\nList of defined IDs\r\n-------------------\r\n      \r\n00 - Copy\r\n01 - Reserved\r\n02 - Common\r\n   03 Swap\r\n      - 2 Swap2\r\n      - 4 Swap4\r\n   04 Delta (subject to change)\r\n\r\n03 - 7z\r\n   01 - LZMA\r\n      01 - Version\r\n  \r\n   03 - Branch\r\n      01 - x86\r\n         03  - BCJ\r\n         1B  - BCJ2\r\n      02 - PPC\r\n         05 - BC_PPC_B (Big Endian)\r\n      03 - Alpha\r\n         01 - BC_Alpha\r\n      04 - IA64\r\n         01 - BC_IA64\r\n      05 - ARM\r\n         01 - BC_ARM\r\n      06 - M68\r\n         05 - BC_M68_B (Big Endian)\r\n      07 - ARM Thumb\r\n         01 - BC_ARMThumb\r\n      08 - SPARC\r\n         05 - BC_SPARC\r\n\r\n   04 - PPMD\r\n      01 - Version\r\n\r\n   80 - reserved for independent developers\r\n\r\n   E0 - Random IDs\r\n\r\n04 - Misc\r\n   00 - Reserved\r\n   01 - Zip\r\n      00 - Copy (not used). Use {00} instead\r\n      01 - Shrink\r\n      06 - Implode\r\n      08 - Deflate\r\n      09 - Deflate64\r\n      12 - BZip2 (not used). Use {04 02 02} instead\r\n   02 - BZip\r\n      02 - BZip2\r\n   03 - Rar\r\n      01 - Rar15\r\n      02 - Rar20\r\n      03 - Rar29\r\n   04 - Arj\r\n      01 - Arj (1,2,3)\r\n      02 - Arj 4\r\n   05 - Z\r\n   06 - Lzh\r\n   07 - Reserved for 7z\r\n   08 - Cab\r\n   09 - NSIS\r\n      01 - DeflateNSIS\r\n      02 - BZip2NSIS\r\n\r\n\r\n06 - Crypto \r\n   00 - \r\n   01 - AES\r\n      0x - AES-128\r\n      4x - AES-192\r\n      8x - AES-256\r\n\r\n      x0 - ECB\r\n      x1 - CBC\r\n      x2 - CFB\r\n      x3 - OFB\r\n\r\n   07 - Reserved\r\n   0F - Reserved\r\n\r\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\r\n\r\n   F1 - Misc Ciphers (Combine)\r\n      01 - Zip\r\n         01 - Main Zip crypto algo\r\n      03 - RAR\r\n         02 - \r\n         03 - Rar29 AES-128 + (modified SHA-1)\r\n      07 - 7z\r\n         01 - AES-256 + SHA-256\r\n\r\n07 - Hash (subject to change)\r\n   00 - \r\n   01 - CRC\r\n   02 - SHA-1\r\n   03 - SHA-256\r\n   04 - SHA-384\r\n   05 - SHA-512\r\n\r\n   F0 - Misc Hash\r\n\r\n   F1 - Misc\r\n      03 - RAR\r\n         03 - Rar29 Password Hashing (modified SHA1)\r\n      07 - 7z \r\n         01 - SHA-256 Password Hashing\r\n    \r\n   \r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/history.txt",
    "content": "HISTORY of the LZMA SDK\r\n-----------------------\r\n\r\n  Version 4.43                2006-06-04\r\n  --------------------------------------\r\n    - Small changes for more compatibility with some C/C++ compilers.\r\n      \r\n\r\n  Version 4.42                2006-05-15\r\n  --------------------------------------\r\n    - Small changes in .h files in ANSI-C version.\r\n      \r\n\r\n  Version 4.39 beta           2006-04-14\r\n  --------------------------------------\r\n    - Bug in versions 4.33b:4.38b was fixed:\r\n      C++ version of LZMA encoder could not correctly compress \r\n      files larger than 2 GB with HC4 match finder (-mfhc4).\r\n      \r\n\r\n  Version 4.37 beta           2005-04-06\r\n  --------------------------------------\r\n    - Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r\n\r\n  \r\n  Version 4.35 beta           2005-03-02\r\n  --------------------------------------\r\n    - Bug was fixed in C++ version of LZMA Decoder:\r\n       If encoded stream was corrupted, decoder could access memory \r\n       outside of allocated range.\r\n\r\n  \r\n  Version 4.34 beta           2006-02-27\r\n  --------------------------------------\r\n    - Compressing speed and memory requirements for compressing were increased\r\n    - LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r\n\r\n  \r\n  Version 4.32                2005-12-09\r\n  --------------------------------------\r\n    - Java version of LZMA SDK was included\r\n\r\n\r\n  Version 4.30                2005-11-20\r\n  --------------------------------------\r\n    - Compression ratio was improved in -a2 mode\r\n    - Speed optimizations for compressing in -a2 mode\r\n    - -fb switch now supports values up to 273\r\n    - Bug in 7z_C (7zIn.c) was fixed:\r\n      It used Alloc/Free functions from different memory pools.\r\n      So if program used two memory pools, it worked incorrectly.\r\n    - 7z_C: .7z format supporting was improved\r\n    - LZMA# SDK (C#.NET version) was included\r\n\r\n\r\n  Version 4.27 (Updated)      2005-09-21\r\n  --------------------------------------\r\n   - Some GUIDs/interfaces in C++ were changed.\r\n     IStream.h:\r\n       ISequentialInStream::Read now works as old ReadPart\r\n       ISequentialOutStream::Write now works as old WritePart\r\n\r\n  \r\n  Version 4.27                2005-08-07\r\n  --------------------------------------\r\n    - Bug in LzmaDecodeSize.c was fixed:\r\n       if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r\n       decompressing worked incorrectly.\r\n\r\n\r\n  Version 4.26                2005-08-05\r\n  --------------------------------------\r\n    - Fixes in 7z_C code and LzmaTest.c:\r\n      previous versions could work incorrectly,\r\n      if malloc(0) returns 0\r\n\r\n\r\n  Version 4.23                2005-06-29\r\n  --------------------------------------\r\n    - Small fixes in C++ code\r\n\r\n\r\n  Version 4.22                2005-06-10\r\n  --------------------------------------\r\n    - Small fixes\r\n\r\n\r\n  Version 4.21                2005-06-08\r\n  --------------------------------------\r\n    - Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r\n    - New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r\n        - LzmaStateDecode.h\r\n        - LzmaStateDecode.c\r\n        - LzmaStateTest.c\r\n    - ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r\n\r\n  \r\n  Version 4.17                2005-04-18\r\n  --------------------------------------\r\n    - New example for RAM->RAM compressing/decompressing: \r\n      LZMA + BCJ (filter for x86 code):\r\n        - LzmaRam.h\r\n        - LzmaRam.cpp\r\n        - LzmaRamDecode.h\r\n        - LzmaRamDecode.c\r\n        - -f86 switch for lzma.exe\r\n\r\n  \r\n  Version 4.16                2005-03-29\r\n  --------------------------------------\r\n    - Bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r\n       If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r\n       decoder could access memory outside of allocated range.\r\n    - Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r\n      Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r\n      LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r\n    - Small speed optimization in LZMA C++ code\r\n    - filter for SPARC's code was added\r\n    - Simplified version of .7z ANSI-C Decoder was included\r\n\r\n\r\n  Version 4.06                2004-09-05\r\n  --------------------------------------\r\n    - Bug in v4.05 was fixed:\r\n        LZMA-Encoder didn't release output stream in some cases.\r\n\r\n\r\n  Version 4.05                2004-08-25\r\n  --------------------------------------\r\n    - Source code of filters for x86, IA-64, ARM, ARM-Thumb \r\n      and PowerPC code was included to SDK\r\n    - Some internal minor changes\r\n\r\n\r\n  Version 4.04                2004-07-28\r\n  --------------------------------------\r\n    - More compatibility with some C++ compilers\r\n\r\n\r\n  Version 4.03                2004-06-18\r\n  --------------------------------------\r\n    - \"Benchmark\" command was added. It measures compressing \r\n      and decompressing speed and shows rating values. \r\n      Also it checks hardware errors.\r\n\r\n\r\n  Version 4.02                2004-06-10\r\n  --------------------------------------\r\n    - C++ LZMA Encoder/Decoder code now is more portable\r\n      and it can be compiled by GCC on Linux.\r\n\r\n\r\n  Version 4.01                2004-02-15\r\n  --------------------------------------\r\n    - Some detection of data corruption was enabled.\r\n        LzmaDecode.c / RangeDecoderReadByte\r\n        .....\r\n        {\r\n          rd->ExtraBytes = 1;\r\n          return 0xFF;\r\n        }\r\n\r\n\r\n  Version 4.00                2004-02-13\r\n  --------------------------------------\r\n    - Original version of LZMA SDK\r\n\r\n\r\n\r\nHISTORY of the LZMA\r\n-------------------\r\n  2001-2006:  Improvements to LZMA compressing/decompressing code, \r\n              keeping compatibility with original LZMA format\r\n  1996-2001:  Development of LZMA compression format\r\n\r\n  Some milestones:\r\n\r\n  2001-08-30: LZMA compression was added to 7-Zip\r\n  1999-01-02: First version of 7-Zip was released\r\n  \r\n\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/lzma.txt",
    "content": "LZMA SDK 4.43\r\n-------------\r\n\r\nLZMA SDK   Copyright (C) 1999-2006 Igor Pavlov\r\n\r\nLZMA SDK provides the documentation, samples, header files, libraries, \r\nand tools you need to develop applications that use LZMA compression.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\nLZMA is an improved version of famous LZ77 compression algorithm. \r\nIt was improved in way of maximum increasing of compression ratio,\r\nkeeping high decompression speed and low memory requirements for \r\ndecompressing.\r\n\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nLZMA SDK is available under any of the following licenses:\r\n\r\n1) GNU Lesser General Public License (GNU LGPL)\r\n2) Common Public License (CPL)\r\n3) Simplified license for unmodified code (read SPECIAL EXCEPTION) \r\n4) Proprietary license \r\n\r\nIt means that you can select one of these four options and follow rules of that license.\r\n\r\n\r\n1,2) GNU LGPL and CPL licenses are pretty similar and both these\r\nlicenses are classified as \r\n - \"Free software licenses\" at http://www.gnu.org/ \r\n - \"OSI-approved\" at http://www.opensource.org/\r\n\r\n\r\n3) SPECIAL EXCEPTION\r\n\r\nIgor Pavlov, as the author of this code, expressly permits you \r\nto statically or dynamically link your code (or bind by name) \r\nto the files from LZMA SDK without subjecting your linked \r\ncode to the terms of the CPL or GNU LGPL. \r\nAny modifications or additions to files from LZMA SDK, however, \r\nare subject to the GNU LGPL or CPL terms.\r\n\r\nSPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code, \r\nwhile you keep LZMA SDK code unmodified.\r\n\r\n\r\nSPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use this code under the same terms and conditions contained in the License \r\nAgreement you have for any previous version of LZMA SDK developed by Igor Pavlov.\r\n\r\nSPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version \r\nof LZMA SDK as update for previous versions.\r\n\r\n\r\nSPECIAL EXCEPTION #3: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use code of the following files: \r\nBranchTypes.h, LzmaTypes.h, LzmaTest.c, LzmaStateTest.c, LzmaAlone.cpp, \r\nLzmaAlone.cs, LzmaAlone.java\r\nas public domain code. \r\n\r\n\r\n4) Proprietary license\r\n\r\nLZMA SDK also can be available under a proprietary license which \r\ncan include:\r\n\r\n1) Right to modify code without subjecting modified code to the \r\nterms of the CPL or GNU LGPL\r\n2) Technical support for code\r\n\r\nTo request such proprietary license or any additional consultations,\r\nsend email message from that page:\r\nhttp://www.7-zip.org/support.html\r\n\r\n\r\nYou should have received a copy of the GNU Lesser General Public\r\nLicense along with this library; if not, write to the Free Software\r\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nYou should have received a copy of the Common Public License\r\nalong with this library.\r\n\r\n\r\nLZMA SDK Contents\r\n-----------------\r\n\r\nLZMA SDK includes:\r\n\r\n  - C++ source code of LZMA compressing and decompressing\r\n  - ANSI-C compatible source code for LZMA decompressing\r\n  - C# source code for LZMA compressing and decompressing\r\n  - Java source code for LZMA compressing and decompressing\r\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\r\n\r\nANSI-C LZMA decompression code was ported from original C++ sources to C.\r\nAlso it was simplified and optimized for code size. \r\nBut it is fully compatible with LZMA from 7-Zip.\r\n\r\n\r\nUNIX/Linux version \r\n------------------\r\nTo compile C++ version of file->file LZMA, go to directory\r\nC/7zip/Compress/LZMA_Alone \r\nand type \"make\" or \"make clean all\" to recompile all.\r\n\r\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\r\nTo compile with static libraries, change string in makefile\r\nLIB = -lm\r\nto string  \r\nLIB = -lm -static\r\n\r\n\r\nFiles\r\n---------------------\r\nC        - C / CPP source code\r\nCS       - C# source code\r\nJava     - Java source code\r\nlzma.txt - LZMA SDK description (this file)\r\n7zFormat.txt - 7z Format description\r\n7zC.txt  - 7z ANSI-C Decoder description (this file)\r\nmethods.txt  - Compression method IDs for .7z\r\nLGPL.txt - GNU Lesser General Public License\r\nCPL.html - Common Public License\r\nlzma.exe - Compiled file->file LZMA encoder/decoder for Windows\r\nhistory.txt - history of the LZMA SDK\r\n\r\n\r\nSource code structure\r\n---------------------\r\n\r\nC  - C / CPP files\r\n  Common  - common files for C++ projects\r\n  Windows - common files for Windows related code\r\n  7zip    - files related to 7-Zip Project\r\n    Common   - common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n        BinTree    - Binary Tree Match Finder for LZ algorithm\r\n        HashChain  - Hash Chain Match Finder for LZ algorithm\r\n        Patricia   - Patricia Match Finder for LZ algorithm\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n      LZMA         - LZMA compression/decompression on C++\r\n      LZMA_Alone   - file->file LZMA compression/decompression\r\n      LZMA_C       - ANSI-C compatible LZMA decompressor\r\n        LzmaDecode.h  - interface for LZMA decoding on ANSI-C\r\n        LzmaDecode.c      - LZMA decoding on ANSI-C (new fastest version)\r\n        LzmaDecodeSize.c  - LZMA decoding on ANSI-C (old size-optimized version)\r\n        LzmaTest.c        - test application that decodes LZMA encoded file\r\n        LzmaTypes.h       - basic types for LZMA Decoder\r\n        LzmaStateDecode.h - interface for LZMA decoding (State version)\r\n        LzmaStateDecode.c - LZMA decoding on ANSI-C (State version)\r\n        LzmaStateTest.c   - test application (State version)\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n    Archive - files related to archiving\r\n      7z_C     - 7z ANSI-C Decoder\r\n\r\nCS - C# files\r\n  7zip\r\n    Common   - some common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      LzmaAlone    - file->file LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nJava  - Java files\r\n  SevenZip\r\n    Compression    - files related to compression/decompression\r\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nC/C++ source code of LZMA SDK is part of 7-Zip project.\r\n\r\nYou can find ANSI-C LZMA decompressing code at folder \r\n  C/7zip/Compress/LZMA_C\r\n7-Zip doesn't use that ANSI-C LZMA code and that code was developed \r\nspecially for this SDK. And files from LZMA_C do not need files from \r\nother directories of SDK for compiling.\r\n\r\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r\n\r\n  http://sourceforge.net/projects/sevenzip/\r\n\r\n\r\nLZMA features\r\n-------------\r\n  - Variable dictionary size (up to 1 GB)\r\n  - Estimated compressing speed: about 1 MB/s on 1 GHz CPU\r\n  - Estimated decompressing speed: \r\n      - 8-12 MB/s on 1 GHz Intel Pentium 3 or AMD Athlon\r\n      - 500-1000 KB/s on 100 MHz ARM, MIPS, PowerPC or other simple RISC\r\n  - Small memory requirements for decompressing (8-32 KB + DictionarySize)\r\n  - Small code size for decompressing: 2-8 KB (depending from \r\n    speed optimizations) \r\n\r\nLZMA decoder uses only integer operations and can be \r\nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r\n\r\nSome critical operations that affect to speed of LZMA decompression:\r\n  1) 32*16 bit integer multiply\r\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\r\n  3) 32-bit shift and arithmetic operations\r\n\r\nSpeed of LZMA decompressing mostly depends from CPU speed.\r\nMemory speed has no big meaning. But if your CPU has small data cache, \r\noverall weight of memory speed will slightly increase.\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nUsing LZMA encoder/decoder executable\r\n--------------------------------------\r\n\r\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\r\n\r\n  e: encode file\r\n\r\n  d: decode file\r\n\r\n  b: Benchmark. There are two tests: compressing and decompressing \r\n     with LZMA method. Benchmark shows rating in MIPS (million \r\n     instructions per second). Rating value is calculated from \r\n     measured speed and it is normalized with AMD Athlon 64 X2 CPU\r\n     results. Also Benchmark checks possible hardware errors (RAM \r\n     errors in most cases). Benchmark uses these settings:\r\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d. Also you \r\n     can change number of iterations. Example for 30 iterations:\r\n\tLZMA b 30\r\n     Default number of iterations is 10.\r\n\r\n<Switches>\r\n  \r\n\r\n  -a{N}:  set compression mode 0 = fast, 1 = normal\r\n          default: 1 (normal)\r\n\r\n  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r\n          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \r\n          For decompressing file compressed by LZMA method with dictionary \r\n          size D = 2^N you need about D bytes of memory (RAM).\r\n\r\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\r\n          Usually big number gives a little bit better compression ratio \r\n          and slower compression process.\r\n\r\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\r\n          Sometimes lc=4 gives gain for big files.\r\n\r\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r\n          lp switch is intended for periodical data when period is \r\n          equal 2^N. For example, for 32-bit (4 bytes) \r\n          periodical data you can use lp=2. Often it's better to set lc0, \r\n          if you change lp switch.\r\n\r\n  -pb{N}: set number of pos bits - [0, 4], default: 2\r\n          pb switch is intended for periodical data \r\n          when period is equal 2^N.\r\n\r\n  -mf{MF_ID}: set Match Finder. Default: bt4. \r\n              Algorithms from hc* group doesn't provide good compression \r\n              ratio, but they often works pretty fast in combination with \r\n              fast mode (-a0).\r\n\r\n              Memory requirements depend from dictionary size \r\n              (parameter \"d\" in table below). \r\n\r\n               MF_ID     Memory                   Description\r\n\r\n                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r\n                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r\n                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r\n                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r\n\r\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \r\n          eos marker, since LZMA decoder knows uncompressed size \r\n          stored in .lzma file header.\r\n\r\n  -si:    Read data from stdin (it will write End Of Stream marker).\r\n  -so:    Write data to stdout\r\n\r\n\r\nExamples:\r\n\r\n1) LZMA e file.bin file.lzma -d16 -lc0 \r\n\r\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r\nand 0 literal context bits. -lc0 allows to reduce memory requirements \r\nfor decompression.\r\n\r\n\r\n2) LZMA e file.bin file.lzma -lc0 -lp2\r\n\r\ncompresses file.bin to file.lzma with settings suitable \r\nfor 32-bit periodical data (for example, ARM or MIPS code).\r\n\r\n3) LZMA d file.lzma file.bin\r\n\r\ndecompresses file.lzma to file.bin.\r\n\r\n\r\nCompression ratio hints\r\n-----------------------\r\n\r\nRecommendations\r\n---------------\r\n\r\nTo increase compression ratio for LZMA compressing it's desirable \r\nto have aligned data (if it's possible) and also it's desirable to locate\r\ndata in such order, where code is grouped in one place and data is \r\ngrouped in other place (it's better than such mixing: code, data, code,\r\ndata, ...).\r\n\r\n\r\nUsing Filters\r\n-------------\r\nYou can increase compression ratio for some data types, using\r\nspecial filters before compressing. For example, it's possible to \r\nincrease compression ratio on 5-10% for code for those CPU ISAs: \r\nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r\n\r\nYou can find C/C++ source code of such filters in folder \"7zip/Compress/Branch\"\r\n\r\nYou can check compression ratio gain of these filters with such \r\n7-Zip commands (example for ARM code):\r\nNo filter:\r\n  7z a a1.7z a.bin -m0=lzma\r\n\r\nWith filter for little-endian ARM code:\r\n  7z a a2.7z a.bin -m0=bc_arm -m1=lzma        \r\n\r\nWith filter for big-endian ARM code (using additional Swap4 filter):\r\n  7z a a3.7z a.bin -m0=swap4 -m1=bc_arm -m2=lzma\r\n\r\nIt works in such manner:\r\nCompressing    = Filter_encoding + LZMA_encoding\r\nDecompressing  = LZMA_decoding + Filter_decoding\r\n\r\nCompressing and decompressing speed of such filters is very high,\r\nso it will not increase decompressing time too much.\r\nMoreover, it reduces decompression time for LZMA_decoding, \r\nsince compression ratio with filtering is higher.\r\n\r\nThese filters convert CALL (calling procedure) instructions \r\nfrom relative offsets to absolute addresses, so such data becomes more \r\ncompressible. Source code of these CALL filters is pretty simple\r\n(about 20 lines of C++), so you can convert it from C++ version yourself.\r\n\r\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r\n\r\n\r\nLZMA compressed file format\r\n---------------------------\r\nOffset Size Description\r\n  0     1   Special LZMA properties for compressed data\r\n  1     4   Dictionary size (little endian)\r\n  5     8   Uncompressed size (little endian). -1 means unknown size\r\n 13         Compressed data\r\n\r\n\r\nANSI-C LZMA Decoder\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nTo compile ANSI-C LZMA Decoder you can use one of the following files sets:\r\n1) LzmaDecode.h + LzmaDecode.c + LzmaTest.c  (fastest version)\r\n2) LzmaDecode.h + LzmaDecodeSize.c + LzmaTest.c  (old size-optimized version)\r\n3) LzmaStateDecode.h + LzmaStateDecode.c + LzmaStateTest.c  (zlib-like interface)\r\n\r\n\r\nMemory requirements for LZMA decoding\r\n-------------------------------------\r\n\r\nLZMA decoder doesn't allocate memory itself, so you must \r\nallocate memory and send it to LZMA.\r\n\r\nStack usage of LZMA decoding function for local variables is not \r\nlarger than 200 bytes.\r\n\r\nHow To decompress data\r\n----------------------\r\n\r\nLZMA Decoder (ANSI-C version) now supports 5 interfaces:\r\n1) Single-call Decompressing\r\n2) Single-call Decompressing with input stream callback\r\n3) Multi-call Decompressing with output buffer\r\n4) Multi-call Decompressing with input callback and output buffer\r\n5) Multi-call State Decompressing (zlib-like interface)\r\n\r\nVariant-5 is similar to Variant-4, but Variant-5 doesn't use callback functions.\r\n\r\nDecompressing steps\r\n-------------------\r\n\r\n1) read LZMA properties (5 bytes):\r\n   unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n2) read uncompressed size (8 bytes, little-endian)\r\n\r\n3) Decode properties:\r\n\r\n  CLzmaDecoderState state;  /* it's 24-140 bytes structure, if int is 32-bit */\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n\r\n4) Allocate memory block for internal Structures:\r\n\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n\r\n  LZMA decoder uses array of CProb variables as internal structure.\r\n  By default, CProb is unsigned_short. But you can define _LZMA_PROB32 to make \r\n  it unsigned_int. It can increase speed on some 32-bit CPUs, but memory \r\n  usage will be doubled in that case.\r\n\r\n\r\n5) Main Decompressing\r\n\r\nYou must use one of the following interfaces:\r\n\r\n5.1 Single-call Decompressing\r\n-----------------------------\r\nWhen to use: RAM->RAM decompressing\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: no defines\r\nMemory Requirements:\r\n  - Input buffer: compressed size\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  int res = LzmaDecode(&state, \r\n      inStream, compressedSize, &inProcessed,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.2 Single-call Decompressing with input stream callback\r\n--------------------------------------------------------\r\nWhen to use: File->RAM or Flash->RAM decompressing.\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB\r\nMemory Requirements:\r\n  - Buffer for input stream: any size (for example, 16 KB)\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  typedef struct _CBuffer\r\n  {\r\n    ILzmaInCallback InCallback;\r\n    FILE *File;\r\n    unsigned char Buffer[kInBufferSize];\r\n  } CBuffer;\r\n\r\n  int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n  {\r\n    CBuffer *bo = (CBuffer *)object;\r\n    *buffer = bo->Buffer;\r\n    *size = MyReadFile(bo->File, bo->Buffer, kInBufferSize);\r\n    return LZMA_RESULT_OK;\r\n  }\r\n\r\n  CBuffer g_InBuffer;\r\n\r\n  g_InBuffer.File = inFile;\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  int res = LzmaDecode(&state, \r\n      &g_InBuffer.InCallback,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.3 Multi-call decompressing with output buffer\r\n-----------------------------------------------\r\nWhen to use: RAM->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Input buffer: compressed size\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details.\r\n\r\n\r\n5.4 Multi-call decompressing with input callback and output buffer\r\n------------------------------------------------------------------\r\nWhen to use: File->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB, _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      &bo.InCallback,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details:\r\n\r\n\r\n5.5 Multi-call State Decompressing (zlib-like interface)\r\n------------------------------------------------------------------\r\nWhen to use: file->file decompressing \r\nCompile files: LzmaStateDecode.h, LzmaStateDecode.c\r\nCompile defines:\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    res = LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed,\r\n      finishDecoding);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaStateTest.c for more details:\r\n\r\n\r\n6) Free all allocated blocks\r\n\r\n\r\nNote\r\n----\r\nLzmaDecodeSize.c is size-optimized version of LzmaDecode.c.\r\nBut compiled code of LzmaDecodeSize.c can be larger than \r\ncompiled code of LzmaDecode.c. So it's better to use \r\nLzmaDecode.c in most cases.\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\nLZMA decoder can return one of the following codes:\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\nIf you use callback function for input data and you return some \r\nerror code, LZMA Decoder also returns that code.\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB    - Use callback for input data\r\n\r\n_LZMA_OUT_READ - Use read function for output data\r\n\r\n_LZMA_LOC_OPT  - Enable local speed optimizations inside code.\r\n                 _LZMA_LOC_OPT is only for LzmaDecodeSize.c (size-optimized version).\r\n                 _LZMA_LOC_OPT doesn't affect LzmaDecode.c (speed-optimized version)\r\n                 and LzmaStateDecode.c\r\n\r\n_LZMA_PROB32   - It can increase speed on some 32-bit CPUs, \r\n                 but memory usage will be doubled in that case\r\n\r\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler\r\n                         and long is 32-bit.\r\n\r\n_LZMA_SYSTEM_SIZE_T  - Define it if you want to use system's size_t.\r\n                       You can use it to enable 64-bit sizes supporting\r\n\r\n\r\n\r\nC++ LZMA Encoder/Decoder \r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nC++ LZMA code use COM-like interfaces. So if you want to use it, \r\nyou can study basics of COM/OLE.\r\n\r\nBy default, LZMA Encoder contains all Match Finders.\r\nBut for compressing it's enough to have just one of them.\r\nSo for reducing size of compressing code you can define:\r\n  #define COMPRESS_MF_BT\r\n  #define COMPRESS_MF_BT4\r\nand it will use only bt4 match finder.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/lzma443/sqlzma1-443.patch",
    "content": "Index: lzma443/C/7zip/Compress/LZMA_Alone/comp.cc\n===================================================================\nRCS file: lzma443/C/7zip/Compress/LZMA_Alone/comp.cc\ndiff -N lzma443/C/7zip/Compress/LZMA_Alone/comp.cc\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma443/C/7zip/Compress/LZMA_Alone/comp.cc\t27 Nov 2006 03:54:58 -0000\t1.29\n@@ -0,0 +1,253 @@\n+/*\n+ * Copyright (C) 2006 Junjiro Okajima\n+ * Copyright (C) 2006 Tomas Matejicek, slax.org\n+ *\n+ * LICENSE follows the described one in lzma.txt.\n+ */\n+\n+/* $Id: sqlzma1-443.patch,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $ */\n+\n+// extract some parts from lzma443/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp\n+\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <assert.h>\n+#include <errno.h>\n+\n+#include \"StdAfx.h\"\n+#include \"../../../Common/MyInitGuid.h\"\n+#include \"../../../Common/MyWindows.h\"\n+#include \"../../../Common/StringConvert.h\"\n+#include \"../LZMA/LZMAEncoder.h\"\n+\n+#include <pthread.h>\n+#include <zlib.h>\n+#include \"sqlzma.h\"\n+\n+//////////////////////////////////////////////////////////////////////\n+\n+class CMemoryStream {\n+protected:\n+\tBytef *m_data;\n+\tUInt64 m_limit;\n+\tUInt64 m_pos;\n+\n+public:\n+\tCMemoryStream(Bytef *data, UInt64 size)\n+\t\t: m_data(data), m_limit(size), m_pos(0) {}\n+\n+\tvirtual ~CMemoryStream() {}\n+};\n+\n+class CInMemoryStream : public CMemoryStream, public IInStream,\n+\t\t\tpublic CMyUnknownImp {\n+//protected:\n+\tCMyComPtr<ISequentialInStream> m_stream;\n+\n+public:\n+\tMY_UNKNOWN_IMP1(IInStream);\n+\n+\tCInMemoryStream(Bytef *data, UInt64 size)\n+\t\t: CMemoryStream(data, size), m_stream(this) {}\n+\n+\tvirtual ~CInMemoryStream() {}\n+\n+\tSTDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\n+\t{\n+\t\tUInt64 room = m_limit - m_pos;\n+\t\tif (size > room)\n+\t\t\tsize = room;\n+\t\tif (size) {\n+\t\t\tmemcpy(data, m_data + m_pos, size);\n+\t\t\tm_pos += size;\n+\t\t}\n+\t\tif (processedSize)\n+\t\t\t*processedSize = size;\n+\t\treturn S_OK;\n+\t}\n+\n+\t// disabled all\n+\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n+\t\tassert(0);\n+\t\treturn E_NOTIMPL;\n+\t}\n+};\n+\n+class COutMemoryStream : public CMemoryStream, public IOutStream,\n+\t\t\t public CMyUnknownImp {\n+//protected:\n+\tCMyComPtr<ISequentialOutStream> m_stream;\n+\n+public:\n+\tMY_UNKNOWN_IMP1(IOutStream);\n+\n+\tCOutMemoryStream(Bytef *data, UInt64 size)\n+\t\t: CMemoryStream(data, size), m_stream(this) {}\n+\n+\tvirtual ~COutMemoryStream() {}\n+\n+\tUInt32 GetSize() {return m_pos;}\n+\n+\tSTDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) {\n+\t\tif (m_pos + size > m_limit)\n+\t\t\treturn -ENOSPC;\n+\t\tmemcpy(m_data + m_pos, data, size);\n+\t\tm_pos += size;\n+\t\tif (processedSize)\n+\t\t\t*processedSize = size;\n+\t\treturn S_OK;\n+\t}\n+\n+\t// disabled all\n+\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n+\t\tassert(0);\n+\t\treturn E_NOTIMPL;\n+\t}\n+\tSTDMETHOD(SetSize)(Int64 newSize) {\n+\t\tassert(0);\n+\t\treturn E_NOTIMPL;\n+\t}\n+};\n+\n+//////////////////////////////////////////////////////////////////////\n+\n+static int\n+LzmaCompress(Bytef *next_in, uInt avail_in, Bytef *next_out, uInt avail_out,\n+\t     uLong *total_out)\n+{\n+\tint err;\n+\tHRESULT res;\n+\tconst Byte a[] = {\n+\t\tavail_in, avail_in >> 8, avail_in >> 16, avail_in >> 24,\n+\t\t0, 0, 0, 0\n+\t};\n+\n+\tNCompress::NLZMA::CEncoder encoderSpec;\n+\tCMyComPtr<ICompressCoder> encoder = &encoderSpec;\n+\tencoder->AddRef();\n+\tCInMemoryStream inStreamSpec(next_in, avail_in);\n+\tCMyComPtr<ISequentialInStream> inStream = &inStreamSpec;\n+\tinStream->AddRef();\n+\tCOutMemoryStream outStreamSpec(next_out, avail_out);\n+\tCMyComPtr<ISequentialOutStream> outStream = &outStreamSpec;\n+\toutStream->AddRef();\n+\n+\t// these values are dpending upon is_lzma() macro in sqlzma.h\n+\tconst UInt32 dictionary = 1 << 23;\n+\tconst UString mf = L\"BT4\";\n+\tconst UInt32 posStateBits = 2;\n+\tconst UInt32 litContextBits = 3; // for normal files\n+\t// UInt32 litContextBits = 0; // for 32-bit data\n+\tconst UInt32 litPosBits = 0;\n+\t// UInt32 litPosBits = 2; // for 32-bit data\n+\tconst UInt32 algorithm = 2;\n+\tconst UInt32 numFastBytes = 128;\n+\tconst UInt32 matchFinderCycles = 16 + numFastBytes / 2;\n+\t//const bool matchFinderCyclesDefined = false;\n+\tconst PROPID propIDs[] = {\n+\t\tNCoderPropID::kDictionarySize,\n+\t\tNCoderPropID::kPosStateBits,\n+\t\tNCoderPropID::kLitContextBits,\n+\t\tNCoderPropID::kLitPosBits,\n+\t\tNCoderPropID::kAlgorithm,\n+\t\tNCoderPropID::kNumFastBytes,\n+\t\tNCoderPropID::kMatchFinder,\n+\t\tNCoderPropID::kEndMarker,\n+\t\tNCoderPropID::kMatchFinderCycles\n+\t};\n+\tconst int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\n+\tPROPVARIANT properties[kNumPropsMax];\n+\tfor (int p = 0; p < 6; p++)\n+\t\tproperties[p].vt = VT_UI4;\n+\tproperties[0].ulVal = UInt32(dictionary);\n+\tproperties[1].ulVal = UInt32(posStateBits);\n+\tproperties[2].ulVal = UInt32(litContextBits);\n+\tproperties[3].ulVal = UInt32(litPosBits);\n+\tproperties[4].ulVal = UInt32(algorithm);\n+\tproperties[5].ulVal = UInt32(numFastBytes);\n+\n+\tproperties[6].vt = VT_BSTR;\n+\tproperties[6].bstrVal = (BSTR)(const wchar_t *)mf;\n+\tproperties[7].vt = VT_BOOL;\n+\tproperties[7].boolVal = VARIANT_FALSE;\t// EOS\n+\tproperties[8].vt = VT_UI4;\n+\tproperties[8].ulVal = UInt32(matchFinderCycles);\n+\n+\terr = -EINVAL;\n+\tres = encoderSpec.SetCoderProperties(propIDs, properties,\n+\t\t\t\t\t     kNumPropsMax - 1);\n+\tif (res)\n+\t\tgoto out;\n+\tres = encoderSpec.WriteCoderProperties(outStream);\n+\tif (res)\n+\t\tgoto out;\n+\n+\tUInt32 r;\n+\tres = outStream->Write(a, sizeof(a), &r);\n+\tif (res || r != sizeof(a))\n+\t\tgoto out;\n+\n+\terr = encoder->Code(inStream, outStream, 0, /*broken*/0, 0);\n+\tif (err)\n+\t\tgoto out;\n+\t*total_out = outStreamSpec.GetSize();\n+\n+ out:\n+\treturn err;\n+}\n+\n+//////////////////////////////////////////////////////////////////////\n+\n+#define Failure(p) do { \\\n+\tfprintf(stderr, \"%s:%d: please report to jro \" \\\n+\t\t\"{%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x}\\n\", \\\n+\t\t__func__, __LINE__, \\\n+\t\tp[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); \\\n+\tabort(); \\\n+}while(0)\n+\n+extern \"C\" int\n+sqlzma_cm(int try_lzma, z_stream *stream, Bytef *next_in, uInt avail_in,\n+\t  Bytef *next_out, uInt avail_out)\n+{\n+\tint err;\n+\tBytef *p = next_out;\n+\tuInt l = avail_out;\n+\n+\tstream->next_in = next_in;\n+\tstream->avail_in = avail_in;\n+\tstream->next_out = p;\n+\tstream->avail_out = l;\n+\terr = deflate(stream, Z_FINISH);\n+\tif (err != Z_STREAM_END && err != Z_OK)\n+\t\tgoto out_err;\n+\tif (avail_in < stream->total_out)\n+\t\treturn err;\n+\tif (is_lzma(*p))\n+\t\tFailure(p);\n+\n+\tif (try_lzma) {\n+\t\tunsigned char a[stream->total_out];\n+\t\tuLong processed;\n+\n+\t\tmemcpy(a, p, stream->total_out);\n+\n+\t\t// malloc family in glibc and stdc++ seems to be thread-safe\n+\t\terr = LzmaCompress(next_in, avail_in, p, l, &processed);\n+\t\tif (!err && processed <= stream->total_out) {\n+\t\t\tif (!is_lzma(*next_out))\n+\t\t\t\tFailure(next_out);\n+\t\t\tstream->total_out = processed;\n+\t\t\terr = Z_STREAM_END;\n+\t\t} else {\n+\t\t\t//puts(\"by zlib\");\n+\t\t\tmemcpy(p, a, stream->total_out);\n+\t\t\terr = Z_STREAM_END;\n+\t\t}\n+\t}\n+\treturn err;\n+\n+ out_err:\n+\tfprintf(stderr, \"%s: ZLIB err %s\\n\", __func__, zError(err));\n+\treturn err;\n+}\nIndex: lzma443/C/7zip/Compress/LZMA_Alone/sqlzma.mk\n===================================================================\nRCS file: lzma443/C/7zip/Compress/LZMA_Alone/sqlzma.mk\ndiff -N lzma443/C/7zip/Compress/LZMA_Alone/sqlzma.mk\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma443/C/7zip/Compress/LZMA_Alone/sqlzma.mk\t27 Nov 2006 03:54:58 -0000\t1.23\n@@ -0,0 +1,54 @@\n+\n+# Copyright (C) 2006 Junjiro Okajima\n+# Copyright (C) 2006 Tomas Matejicek, slax.org\n+#\n+# LICENSE follows the described one in lzma.txt.\n+\n+# $Id: sqlzma1-443.patch,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\n+\n+ifndef Sqlzma\n+$(error Sqlzma is not defined)\n+endif\n+\n+include makefile.gcc\n+\n+ifdef UseDebugFlags\n+DebugFlags = -Wall -O0 -g -UNDEBUG\n+endif\n+# -pthread\n+CXXFLAGS = ${CFLAGS} -D_REENTRANT -include pthread.h -DNDEBUG ${DebugFlags}\n+Tgt = liblzma_r.a\n+\n+all: ${Tgt}\n+\n+RObjs = LZMAEncoder_r.o Alloc_r.o LZInWindow_r.o CRC_r.o StreamUtils_r.o \\\n+\tOutBuffer_r.o RangeCoderBit_r.o\n+%_r.cc: ../LZMA/%.cpp\n+\tln $< $@\n+%_r.cc: ../LZ/%.cpp\n+\tln $< $@\n+%_r.cc: ../RangeCoder/%.cpp\n+\tln $< $@\n+%_r.cc: ../../Common/%.cpp\n+\tln $< $@\n+%_r.cc: ../../../Common/%.cpp\n+\tln $< $@\n+LZMAEncoder_r.o: CXXFLAGS += -I../LZMA\n+LZInWindow_r.o: CXXFLAGS += -I../LZ\n+RangeCoderBit_r.o: CXXFLAGS += -I../RangeCoder\n+OutBuffer_r.o StreamUtils_r.o: CXXFLAGS += -I../../Common\n+Alloc_r.o CRC_r.o: CXXFLAGS += -I../../../Common\n+\n+comp.o: CXXFLAGS += -I${Sqlzma}\n+comp.o: comp.cc ${Sqlzma}/sqlzma.h\n+\n+liblzma_r.a: ${RObjs} comp.o\n+\t${AR} cr $@ $^\n+\n+clean: clean_sqlzma\n+clean_sqlzma:\n+\t$(RM) comp.o *_r.o ${Tgt} *~\n+\n+# Local variables: ;\n+# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n+# End: ;\nIndex: lzma443/C/7zip/Compress/LZMA_C/kmod.mk\n===================================================================\nRCS file: lzma443/C/7zip/Compress/LZMA_C/kmod.mk\ndiff -N lzma443/C/7zip/Compress/LZMA_C/kmod.mk\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma443/C/7zip/Compress/LZMA_C/kmod.mk\t7 Jan 2007 15:12:48 -0000\t1.9\n@@ -0,0 +1,40 @@\n+\n+# Copyright (C) 2006 Junjiro Okajima\n+# Copyright (C) 2006 Tomas Matejicek, slax.org\n+#\n+# LICENSE follows the described one in lzma.txt.\n+\n+# $Id: sqlzma1-443.patch,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\n+\n+ifndef Sqlzma\n+$(error Sqlzma is not defined)\n+endif\n+ifndef KDir\n+$(error KDir is not defined)\n+endif\n+\n+#include makefile.gcc\n+\n+Kmod = kmod\n+EXTRA_CFLAGS += -Wall -Werror -I${CURDIR} -I${Sqlzma}\n+# -D_LZMA_PROB32\n+EXTRA_CFLAGS += $(shell ${CPP} ${CFLAGS} -P testflags.c)\n+\n+all: ${Kmod}/uncomp.c\n+\t${MAKE} EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\" M=${CURDIR}/${Kmod} \\\n+\t\t-C ${KDir} C=0 V=0 modules\n+\n+${Kmod}/uncomp.c: uncomp.c\n+\tln $< $@\n+\n+clean: clean_kmod\n+clean_kmod:\n+\t${MAKE} -C ${KDir} M=${CURDIR}/${Kmod} V=0 clean\n+\t${RM} ${Kmod}/*~\n+\t-@test -e ${Kmod}/uncomp.c && \\\n+\t\tdiff -q ${Kmod}/uncomp.c uncomp.c > /dev/null && \\\n+\t\tfind ${Kmod}/uncomp.c -links +1 | xargs -r ${RM}\n+\n+# Local variables: ;\n+# compile-command: (concat \"make Sqlzma=../../../../.. KDir=/lib/modules/`uname -r`/build -f \" (file-name-nondirectory (buffer-file-name)));\n+# End: ;\nIndex: lzma443/C/7zip/Compress/LZMA_C/sqlzma.mk\n===================================================================\nRCS file: lzma443/C/7zip/Compress/LZMA_C/sqlzma.mk\ndiff -N lzma443/C/7zip/Compress/LZMA_C/sqlzma.mk\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma443/C/7zip/Compress/LZMA_C/sqlzma.mk\t7 Jan 2007 15:12:48 -0000\t1.20\n@@ -0,0 +1,45 @@\n+\n+# Copyright (C) 2006 Junjiro Okajima\n+# Copyright (C) 2006 Tomas Matejicek, slax.org\n+#\n+# LICENSE follows the described one in lzma.txt.\n+\n+# $Id: sqlzma1-443.patch,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\n+\n+ifndef Sqlzma\n+$(error Sqlzma is not defined)\n+endif\n+\n+include makefile.gcc\n+ifdef KDir\n+include kmod.mk\n+endif\n+\n+ifdef UseDebugFlags\n+DebugFlags = -O0 -g -UNDEBUG\n+endif\n+CFLAGS += -DNDEBUG ${DebugFlags}\n+Tgt = libunlzma.a libunlzma_r.a\n+\n+all: ${Tgt}\n+\n+%_r.c: %.c\n+\tln $< $@\n+# -pthread\n+%_r.o: CFLAGS += -D_REENTRANT -include pthread.h\n+\n+uncomp.o uncomp_r.o: CFLAGS += -I${Sqlzma}\n+uncomp.o: uncomp.c ${Sqlzma}/sqlzma.h\n+\n+libunlzma.a: uncomp.o LzmaDecode.o\n+\t${AR} cr $@ $^\n+libunlzma_r.a: uncomp_r.o LzmaDecode_r.o\n+\t${AR} cr $@ $^\n+\n+clean: clean_sqlzma\n+clean_sqlzma:\n+\t$(RM) ${Tgt} uncomp.o uncomp_r.o LzmaDecode_r.o *~\n+\n+# Local variables: ;\n+# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n+# End: ;\nIndex: lzma443/C/7zip/Compress/LZMA_C/testflags.c\n===================================================================\nRCS file: lzma443/C/7zip/Compress/LZMA_C/testflags.c\ndiff -N lzma443/C/7zip/Compress/LZMA_C/testflags.c\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma443/C/7zip/Compress/LZMA_C/testflags.c\t6 Nov 2006 06:33:10 -0000\t1.1\n@@ -0,0 +1,5 @@\n+#ifdef _LZMA_PROB32\n+-D_LZMA_PROB32\n+#else\n+-U_LZMA_PROB32\n+#endif\nIndex: lzma443/C/7zip/Compress/LZMA_C/uncomp.c\n===================================================================\nRCS file: lzma443/C/7zip/Compress/LZMA_C/uncomp.c\ndiff -N lzma443/C/7zip/Compress/LZMA_C/uncomp.c\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma443/C/7zip/Compress/LZMA_C/uncomp.c\t4 Mar 2007 12:45:53 -0000\t1.30\n@@ -0,0 +1,221 @@\n+/*\n+ * Copyright (C) 2006, 2007 Junjiro Okajima\n+ * Copyright (C) 2006, 2007 Tomas Matejicek, slax.org\n+ *\n+ * LICENSE follows the described one in lzma.txt.\n+ */\n+\n+/* $Id: sqlzma1-443.patch,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $ */\n+\n+/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */\n+\n+#ifndef __KERNEL__\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <errno.h>\n+#include <assert.h>\n+#include <pthread.h>\n+#define unlikely(x)\t\t__builtin_expect(!!(x), 0)\n+#define BUG_ON(x)\t\tassert(!(x))\n+/* sqlzma buffers are always larger than a page. true? */\n+#define kmalloc(sz,gfp)\t\tmalloc(sz)\n+#define kfree(p)\t\tfree(p)\n+#define zlib_inflate(s, f)\tinflate(s, f)\n+#define zlib_inflateInit(s)\tinflateInit(s)\n+#define zlib_inflateReset(s)\tinflateReset(s)\n+#define zlib_inflateEnd(s)\tinflateEnd(s)\n+#else\n+#include <linux/init.h>\n+#include <linux/module.h>\n+#include <linux/kernel.h>\n+#include <linux/vmalloc.h>\n+#ifndef WARN_ON_ONCE\n+#define WARN_ON_ONCE(b)\tWARN_ON(b)\n+#endif\n+#endif /* __KERNEL__ */\n+\n+#include \"sqlzma.h\"\n+#include \"LzmaDecode.h\"\n+\n+static int LzmaUncompress(struct sqlzma_un *un)\n+{\n+\tint err, i, ret;\n+\tSizeT outSize, inProcessed, outProcessed, srclen;\n+\t/* it's about 24-80 bytes structure, if int is 32-bit */\n+\tCLzmaDecoderState state;\n+\tunsigned char *dst, *src, a[8];\n+\tstruct sized_buf *sbuf;\n+\n+\t/* Decode LZMA properties and allocate memory */\n+\terr = -EINVAL;\n+\tsrc = un->un_cmbuf;\n+\tret = LzmaDecodeProperties(&state.Properties, src, LZMA_PROPERTIES_SIZE);\n+\tsrc += LZMA_PROPERTIES_SIZE;\n+\tif (unlikely(ret != LZMA_RESULT_OK))\n+\t\tgoto out;\n+\ti = LzmaGetNumProbs(&state.Properties);\n+\tif (unlikely(i <= 0))\n+\t\ti = 1;\n+\ti *= sizeof(CProb);\n+\tsbuf = un->un_a + SQUN_PROB;\n+\tif (unlikely(sbuf->sz < i)) {\n+\t\tif (sbuf->buf && sbuf->buf != un->un_prob)\n+\t\t\tkfree(sbuf->buf);\n+#ifdef __KERNEL__\n+\t\tprintk(\"%s:%d: %d --> %d\\n\", __func__, __LINE__, sbuf->sz, i);\n+#else\n+\t\tprintf(\"%d --> %d\\n\", sbuf->sz, i);\n+#endif\n+\t\terr = -ENOMEM;\n+\t\tsbuf->sz = 0;\n+\t\tsbuf->buf = kmalloc(i, GFP_ATOMIC);\n+\t\tif (unlikely(!sbuf->buf))\n+\t\t\tgoto out;\n+\t\tsbuf->sz = i;\n+\t}\n+\tstate.Probs = (void*)sbuf->buf;\n+\n+\t/* Read uncompressed size */\n+\tmemcpy(a, src, sizeof(a));\n+\tsrc += sizeof(a);\n+\toutSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);\n+\n+\terr = -EINVAL;\n+\tdst = un->un_resbuf;\n+\tif (unlikely(!dst || outSize > un->un_reslen))\n+\t\tgoto out;\n+\tun->un_reslen = outSize;\n+\tsrclen = un->un_cmlen - (src - un->un_cmbuf);\n+\n+\t/* Decompress */\n+\terr = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,\n+\t\t\t &outProcessed);\n+\tif (err)\n+\t\terr = -EINVAL;\n+\n+ out:\n+#ifndef __KERNEL__\n+\tif (err)\n+\t\tfprintf(stderr, \"err %d\\n\", err);\n+#endif\n+\treturn err;\n+}\n+\n+int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n+\t      struct sized_buf *dst)\n+{\n+\tint err, by_lzma = 0;\n+\tif (un->un_lzma && is_lzma(*src->buf)) {\n+\t\tby_lzma = 1;\n+\t\tun->un_cmbuf = src->buf;\n+\t\tun->un_cmlen = src->sz;\n+\t\tun->un_resbuf = dst->buf;\n+\t\tun->un_reslen = dst->sz;\n+\n+\t\t/* this library is thread-safe */\n+\t\terr = LzmaUncompress(un);\n+\t\tgoto out;\n+\t}\n+\n+\terr = zlib_inflateReset(&un->un_stream);\n+\tif (unlikely(err != Z_OK))\n+\t\tgoto out;\n+\tun->un_stream.next_in = src->buf;\n+\tun->un_stream.avail_in = src->sz;\n+\tun->un_stream.next_out = dst->buf;\n+\tun->un_stream.avail_out = dst->sz;\n+\terr = zlib_inflate(&un->un_stream, Z_FINISH);\n+\tif (err == Z_STREAM_END)\n+\t\terr = 0;\n+\n+ out:\n+\tif (err) {\n+#ifdef __KERNEL__\n+\t\tWARN_ON_ONCE(1);\n+#else\n+\t\tchar a[64] = \"ZLIB \";\n+\t\tif (by_lzma) {\n+\t\t\tstrcpy(a, \"LZMA \");\n+#ifdef _REENTRANT\n+\t\t\tstrerror_r(err, a + 5, sizeof(a) - 5);\n+#else\n+\t\t\tstrncat(a, strerror(err), sizeof(a) - 5);\n+#endif\n+\t\t} else\n+\t\t\tstrncat(a, zError(err), sizeof(a) - 5);\n+\t\tfprintf(stderr, \"%s: %.*s\\n\", __func__, sizeof(a), a);\n+#endif\n+\t}\n+\treturn err;\n+}\n+\n+int sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)\n+{\n+\tint err;\n+\n+\terr = -ENOMEM;\n+\tun->un_lzma = do_lzma;\n+\tmemset(un->un_a, 0, sizeof(un->un_a));\n+\tun->un_a[SQUN_PROB].buf = un->un_prob;\n+\tun->un_a[SQUN_PROB].sz = sizeof(un->un_prob);\n+\tif (res_sz) {\n+\t\tun->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);\n+\t\tif (unlikely(!un->un_a[SQUN_RESULT].buf))\n+\t\t\treturn err;\n+\t\tun->un_a[SQUN_RESULT].sz = res_sz;\n+\t}\n+\n+\tun->un_stream.next_in = NULL;\n+\tun->un_stream.avail_in = 0;\n+#ifdef __KERNEL__\n+\tun->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);\n+\tif (unlikely(!un->un_stream.workspace))\n+\t\treturn err;\n+#else\n+\tun->un_stream.opaque = NULL;\n+\tun->un_stream.zalloc = Z_NULL;\n+\tun->un_stream.zfree = Z_NULL;\n+#endif\n+\terr = zlib_inflateInit(&un->un_stream);\n+\tif (unlikely(err == Z_MEM_ERROR))\n+\t\treturn -ENOMEM;\n+\tBUG_ON(err);\n+\treturn err;\n+}\n+\n+void sqlzma_fin(struct sqlzma_un *un)\n+{\n+\tint i;\n+\tfor (i = 0; i < SQUN_LAST; i++)\n+\t\tif (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)\n+\t\t\tkfree(un->un_a[i].buf);\n+\tBUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);\n+}\n+\n+#ifdef __KERNEL__\n+EXPORT_SYMBOL(sqlzma_un);\n+EXPORT_SYMBOL(sqlzma_init);\n+EXPORT_SYMBOL(sqlzma_fin);\n+\n+#if 0\n+static int __init sqlzma_init(void)\n+{\n+\treturn 0;\n+}\n+\n+static void __exit sqlzma_exit(void)\n+{\n+}\n+\n+module_init(sqlzma_init);\n+module_exit(sqlzma_exit);\n+#endif\n+\n+MODULE_LICENSE(\"GPL\");\n+MODULE_AUTHOR(\"Junjiro Okajima <hooanon05 at yahoo dot co dot jp>\");\n+MODULE_VERSION(\"$Id: sqlzma1-443.patch,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\");\n+MODULE_DESCRIPTION(\"LZMA uncompress for squashfs. \"\n+\t\t   \"Some functions for squashfs to support LZMA and \"\n+\t\t   \"a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n+#endif\nIndex: lzma443/C/7zip/Compress/LZMA_C/kmod/Makefile\n===================================================================\nRCS file: lzma443/C/7zip/Compress/LZMA_C/kmod/Makefile\ndiff -N lzma443/C/7zip/Compress/LZMA_C/kmod/Makefile\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma443/C/7zip/Compress/LZMA_C/kmod/Makefile\t27 Nov 2006 03:54:58 -0000\t1.3\n@@ -0,0 +1,11 @@\n+\n+# Copyright (C) 2006 Junjiro Okajima\n+# Copyright (C) 2006 Tomas Matejicek, slax.org\n+#\n+# LICENSE follows the described one in lzma.txt.\n+\n+# $Id: sqlzma1-443.patch,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\n+\n+obj-m += unlzma.o sqlzma.o\n+unlzma-y := module.o\n+sqlzma-y := uncomp.o\nIndex: lzma443/C/7zip/Compress/LZMA_C/kmod/module.c\n===================================================================\nRCS file: lzma443/C/7zip/Compress/LZMA_C/kmod/module.c\ndiff -N lzma443/C/7zip/Compress/LZMA_C/kmod/module.c\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma443/C/7zip/Compress/LZMA_C/kmod/module.c\t27 Nov 2006 03:54:58 -0000\t1.5\n@@ -0,0 +1,36 @@\n+\n+/*\n+ * Copyright (C) 2006 Junjiro Okajima\n+ * Copyright (C) 2006 Tomas Matejicek, slax.org\n+ *\n+ * LICENSE follows the described one in lzma.txt.\n+ */\n+\n+/* $Id: sqlzma1-443.patch,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $ */\n+\n+#include <linux/init.h>\n+#include <linux/module.h>\n+\n+#include \"../LzmaDecode.c\"\n+\n+EXPORT_SYMBOL(LzmaDecodeProperties);\n+EXPORT_SYMBOL(LzmaDecode);\n+\n+#if 0\n+static int __init unlzma_init(void)\n+{\n+\treturn 0;\n+}\n+\n+static void __exit unlzma_exit(void)\n+{\n+}\n+\n+module_init(unlzma_init);\n+module_exit(unlzma_exit);\n+#endif\n+\n+MODULE_LICENSE(\"GPL\");\n+MODULE_VERSION(\"$Id: sqlzma1-443.patch,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $\");\n+MODULE_DESCRIPTION(\"LZMA uncompress. \"\n+\t\t   \"A tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/sqlzma.h",
    "content": "/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.\n */\n\n/* $Id: sqlzma.h,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $ */\n\n#ifndef __sqlzma_h__\n#define __sqlzma_h__\n\n#ifndef __KERNEL__\n#include <stdlib.h>\n#include <string.h>\n#include <zlib.h>\n#ifdef _REENTRANT\n#include <pthread.h>\n#endif\n#else\n#include <linux/zlib.h>\n#endif\n#define _7ZIP_BYTE_DEFINED\n\n/*\n * detect the compression method automatically by the first byte of compressed\n * data.\n * according to rfc1950, the first byte of zlib compression must be 0x?8.\n */\n#define is_lzma(c)\t(c == 0x5d)\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#ifndef __KERNEL__\n/* for mksquashfs only */\nint sqlzma_cm(int lzma, z_stream *stream, Bytef *next_in, uInt avail_in,\n\t      Bytef *next_out, uInt avail_out);\n#endif\n\n/* ---------------------------------------------------------------------- */\n/*\n * Three patterns for sqlzma uncompression. very dirty code.\n * - kernel space (squashfs kernel module)\n * - user space with pthread (mksquashfs)\n * - user space without pthread (unsquashfs)\n */\n\nstruct sized_buf {\n\tunsigned int\tsz;\n\tunsigned char\t*buf;\n};\n\nenum {SQUN_PROB, SQUN_RESULT, SQUN_LAST};\nstruct sqlzma_un {\n\tint\t\t\tun_lzma;\n\tstruct sized_buf\tun_a[SQUN_LAST];\n\tunsigned char\t\tun_prob[31960]; /* unlzma 64KB */\n\tz_stream\t\tun_stream;\n#define un_cmbuf\tun_stream.next_in\n#define un_cmlen\tun_stream.avail_in\n#define un_resbuf\tun_stream.next_out\n#define un_resroom\tun_stream.avail_out\n#define un_reslen\tun_stream.total_out\n};\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz);\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src, struct sized_buf *dst);\nvoid sqlzma_fin(struct sqlzma_un *un);\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\n};\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/sqmagic.h",
    "content": "/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE must follow the one in squashfs.\n */\n\n/* $Id: sqmagic.h,v 1.1.1.1 2007-11-22 06:05:47 steven Exp $ */\n\n#ifndef __sqmagic_h__\n#define __sqmagic_h__\n\n/* see SQUASHFS_MAGIC in squashfs_fs.h */\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/ACKNOWLEDGEMENTS",
    "content": "\t\t\tACKNOWLEDGEMENTS\n\nThanks to everyone who have download squashfs.  I appreciate people\nusing it, and any feedback you have.\n\nThe following have provided useful feedback, which has guided\nsome of the extra features in squashfs.  This is a randomly ordered\n(roughly in chronological order) list, which is updated when\nI remember...\n\nAcknowledgements for Squashfs-3.2-r2\n------------------------------------\n\nJunjiro Okajima discovered a couple of SMP issues, thanks.\n\nJunjiro Okajima and Tomas Matejicek have produced some good LZMA patches\nfor Squashfs.\n\nAcknowledgements for Squashfs-3.2\n---------------------------------\n\nPeter Korsgaard sent a patch updating Squashfs to changes in the VFS interface\nin Linux 2.6.20.\n\nAcknowledgements for Squashfs-3.1\n---------------------------------\n\nKenneth Duda and Ed Swierk of Arastra Inc. identified numerous bugs with\nSquashfs, and provided patches which were the basis for some of the\nfixes.  In particular they identified the fragment rounding bug, the\nNFS bug, the initrd bug, and helped identify the 4K stack overflow bug.\n\nScott James Remnant (Ubuntu) also identified the fragment rounding bug,\nand he also provided a patch.\n\nMing Zhang identified the Lseek bug in Mksquashfs.  His tests on the\nperformance of Mksquashfs on SMP systems encouraged the rewrite of\nMksquashfs.\n\nPeter Korsgaard, Daniel Olivera and Zilvinas Valinskas noticed\nSquashfs 3.0 didn't compile on Linux-2.6.18-rc[1-4] due to changes\nin the Linux VFS interfaces, and provided patches.\n\nTomas Matejicek (SLAX) suggested the -force option on Unsquashfs, and noticed\nUnsquashfs didn't return the correct exit status.\n\nYann Le Doare reported a kernel oops and provided a Qemu image that led\nto the identification of the simultaneously accessing multiply mounted Squashfs\nfilesystems bug.\n\n\nOlder acknowledgements\n----------------------\n\nMark Robson - pointed out early on that initrds didn't work\n\nAdam Warner - pointed out that greater than 2GB filesystems didn't work.\n\nJohn Sutton - raised the problem when archiving the entire filesystem\n(/) there was no way to prevent /proc being archived.  This prompted\nexclude files.\n\nMartin Mueller (LinuxTV) - noticed that the filesystem length in the\nsuperblock doesn't match the output filesystem length.  This is due to\npadding to a 4K boundary.  This prompted the addition of the -nopad option.\nHe also reported a problem where 32K block filesystems hung when used as\ninitrds.\n\nArkadiusz Patyk (Polish Linux Distribution - PLD) reported a problem where 32K\nblock filesystems hung when used as a root filesystem mounted as a loopback\ndevice.\n\nJoe Blow emailed me that I'd forgotten to put anything in the README about\nmounting the squashfs filesystem.\n\nDavid Fox (Lindows) noticed that the exit codes returned by Mksquashfs were\nwrong.  He also noticed that a lot of time was spent in the duplicate scan\nroutine.\n\nCameron Rich complained that Squashfs did not support FIFOs or sockets.\n\nSteve Chadsey and Thomas Weissmuller noticed that files larger than the\navailable memory could not be compressed by Mksquashfs.\n\n\"Ptwahyu\" and \"Hoan\" (I have no full names and I don't like giving people's\nemail addresses), noticed that Mksquashfs 1.3 SEGV'd occasionally.  Even though\nI had already noticed this bug, it is useful to be informed by other people.\n\nDon Elwell, Murray Jensen and Cameron Rich, have all sent in patches.  Thanks,\nI have not had time to do anything about them yet...\n\nDrew Scott Daniels has been a good advocate for Squashfs.\n\nErik Andersen has made some nice suggestions, unfortunately, I have\nnot had time to implement anything.\n\nArtemiy I. Pavlov has written a useful LDP mini-howto for Squashfs\n(http://linuxdoc.artemio.net/squashfs).\n\nYves Combe reported the Apple G5 bug, when using Squashfs for\nhis PPC Knoppix-mib livecd project.\n\nJaco Greeff (mklivecd project, and maintainer of the Mandrake\nsquashfs-tools package) suggested the new mksquashfs -ef option, and the\nstandalone build for mksquashfs.\n\nMike Schaudies made a donation.\n\nArkadiusz Patyk from the Polish Linux Distribution reported that Squashfs\ndidn't work on amd64 machines. He gave me an account on a PLD amd64 machine\nwhich allowed myself to track down these bugs.\n\nMiles Roper, Peter Kjellerstedt and Willy Tarreau reported that release 2.1 did\nnot compile with gcc < 3.x.\n\nMarcel J.E. Mol reported lack of kernel memory issues when using Squashfs\non small memory embedded systems.  This prompted the addition of the embedded\nsystem kernel configuration options.\n\nEra Scarecrow noticed that Mksquashfs had not been updated to reflect that\nsmaller than 4K blocks are no longer supported.\n\nKenichi Shima reported the Kconfig file had not been updated to 2.2.\n\nAaron Ten Clay made a donation!\n\nTomas Matejicek (SLAX) made a donation!\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/CHANGES",
    "content": "\t\t\tSQUASHFS CHANGE LOG\n\n3.2-r2\t15 JAN 2007\tKernel patch update and progress bar bug fix\n\n\t1. Kernel patches 2.6.19/2.6.20 have been updated to use\n\t   const structures and mutexes rather than older semaphores.\n\t2. Minor SMP bug fixes.\n\t3. Progress bar broken on x86-64.  Fixed.\n\n3.2\t2 JAN 2007\tNFS support, improvements to the Squashfs-tools, major\n\t\t\tbug fixes, lots of small improvements/bug fixes, and new\n\t\t\tkernel patches.\n\n\tImprovements:\n\n\t1. Squashfs filesystems can now be exported via NFS.\n\t2. Unsquashfs now supports 2.x filesystems.\n\t3. Mksquashfs now displays a progress bar.\n\t4. Squashfs kernel code has been hardened against accidently or\n\t   maliciously corrupted Squashfs filesystems.\n\n\tBug fixes:\n\n\t5. Race condition occurring on S390 in readpage() fixed.\n\t6. Odd behaviour of MIPS memcpy in read_data() routine worked-around.\n\t7. Missing cache_flush in Squashfs symlink_readpage() added.\n\t\n\n3.1-r2\t30 AUG 2006\tMksquashfs -sort bug fix\n\n\t\t\tA code optimisation after testing unfortunately\n\t\t\tbroke sorting in Mksquashfs.  This has been fixed.\n\n3.1\t19 AUG 2006\tThis release has some major improvements to\n\t\t\tthe squashfs-tools, a couple of major bug\n\t\t\tfixes, lots of small improvements/bug fixes,\n\t\t\tand new kernel patches.\n\n\t\t\t\n\t1. Mksquashfs has been rewritten to be multi-threaded.  It\n\t   has the following improvements\n\n\t   1.1. Parallel compression.  By default as many compression and\n\t\tfragment compression threads are created as there are available\n\t\tprocessors.  This significantly speeds up performance on SMP\n\t\tsystems.\n\t   1.2. File input and filesystem output is peformed in parallel on\n\t\tseparate threads to maximise I/O performance.  Even on single\n\t\tprocessor systems this speeds up performance by at least 10%.\n\t   1.3. Appending has been significantly improved, and files within the\n\t\tfilesystem being appended to are no longer scanned and\n\t\tchecksummed.  This significantly improves append time for large\n\t\tfilesystems.\n\t   1.4. File duplicate checking has been optimised, and split into two\n\t\tseparate phases.  Only files which are considered possible\n\t\tduplicates after the first phase are checksummed and cached in\n\t\tmemory.\n\t   1.5\tThe use of swap memory was found to significantly impact\n\t\tperformance. The amount of memory used to cache files is now a\n\t\tcommand line option, by default this is 512 Mbytes.\n \n\t2. Unsquashfs has the following improvements\n\n\t   2.1  Unsquashfs now allows you to specify the filename or the\n\t\tdirectory within the Squashfs filesystem that is to be\n\t\textracted, rather than always extracting the entire filesystem.\n\t   2.2  A new -force option has been added which forces Unsquashfs to\n\t\toutput to the destination directory even if files and directories\n\t\talready exist in the destination directory.  This allows you to\n\t\tupdate an already existing directory tree, or to Unsquashfs to\n\t\ta partially filled directory tree.  Without the -force option\n\t\tUnsquashfs will refuse to output.\n\n\t3.  The following major bug fixes have been made\n\n\t  3.1  \tA fragment table rounding bug has been fixed in Mksquashfs.\n\t\tPreviously if the number of fragments in the filesystem\n\t\twere a multiple of 512, Mksquashfs would generate an\n\t\tincorrect filesystem.\n\t  3.2  \tA rare SMP bug which occurred when simultaneously acccessing\n\t\tmultiply mounted Squashfs filesystems has been fixed.\n\n\t4. Miscellaneous improvements/bug fixes\n\n\t  4.1\tKernel code stack usage has been reduced.  This is to ensure\n\t\tSquashfs works with 4K stacks.\n\t  4.2   Readdir (Squashfs kernel code) has been fixed to always\n\t\treturn 0, rather than the number of directories read.  Squashfs\n\t\tshould now interact better with NFS.\n\t  4.3\tLseek bug in Mksquashfs when appending to larger than 4GB\n\t\tfilesystems fixed.\n\t  4.4\tSquashfs 2.x initrds can now been mounted.\n\t  4.5\tUnsquashfs exit status fixed.\n\t  4.6\tNew patches for linux-2.6.18 and linux-2.4.33.\n\n\t\n3.0\t15 MAR 2006\tMajor filesystem improvements\n\n\t1. Filesystems are no longer limited to 4 GB.  In\n\t   theory 2^64 or 4 exabytes is now supported.\n\t2. Files are no longer limited to 4 GB.  In theory the maximum\n\t   file size is 4 exabytes.\n\t3. Metadata (inode table and directory tables) are no longer\n\t   restricted to 16 Mbytes.\n\t4. Hardlinks are now suppported.\n\t5. Nlink counts are now supported.\n\t6. Readdir now returns '.' and '..' entries.\n\t7. Special support for files larger than 256 MB has been added to\n\t   the Squashfs kernel code for faster read access.\n\t8. Inode numbers are now stored within the inode rather than being\n\t   computed from inode location on disk (this is not so much an\n\t   improvement, but a change forced by the previously listed\n\t   improvements).\n\n2.2-r2\t8 SEPT 2005\tSecond release of 2.2, this release fixes a couple\n\t\t\tof small bugs, a couple of small documentation\n\t\t\tmistakes, and adds a patch for kernel 2.6.13. \n\n\t1. Mksquashfs now deletes the output filesystem image file if an\n\t   error occurs whilst generating the filesystem.  Previously on\n\t   error the image file was left empty or partially written.\n\t2. Updated mksquashfs so that it doesn't allow you to generate\n\t   filesystems with block sizes smaller than 4K.  Squashfs hasn't\n\t   supported block sizes less than 4K since 2.0-alpha.\n\t3. Mksquashfs now ignores missing files/directories in sort files.\n\t   This was the original behaviour before 2.2.\n\t4. Fixed small mistake in fs/Kconfig where the version was still\n\t   listed as 2.0.\n\t5. Updated ACKNOWLEDGEMENTS file.\n\n\n2.2\t3 JUL 2005\tThis release has some small improvements, bug fixes\n\t\t\tand patches for new kernels.\n\n\t1. Sort routine re-worked and debugged from release 2.1.  It now allows\n\t   you to give Mkisofs style sort files and checks for filenames that\n\t   don't match anything.  Sort priority has also been changed to\n\t   conform to Mkisofs usage, highest priority files are now placed\n\t   at the start of the filesystem (this means they will be on the\n\t   inside of a CD or DVD).\n\t2. New Configure options for embedded systems (memory constrained\n\t   systems).  See INSTALL file for further details.\n\t3. Directory index bug fixed where chars were treated as signed on\n           some architectures.  A file would not be found in the rare case\n\t   that the filename started with a chracter greater than 127.\n\t4. Bug introduced into the read_data() routine when sped up to use data\n\t   block queueing fixed.  If the second or later block resulted in an\n\t   I/O error this was not checked.\n\t5. Append bug introduced in 2.1 fixed.  The code to compute the new\n\t   compressed and uncompressed directory parts after appending was\n\t   wrong.\n\t6. Metadata block length read routine altered to not perform a\n\t   misaligned short read.  This was to fix reading on an ARM7 running\n\t   uCLinux without a misaligned read interrupt handler.\n\t7. Checkdata bug introduced in 2.1 fixed.\n\t\n\n2.1-r2  15 DEC 2004\tCode changed so it can be compiled with gcc 2.x\n\n\t1.  In some of the code added for release 2.1 I unknowingly used some\n\t    gcc extensions only supported by 3.x compilers.  I have received\n\t    a couple of reports that the 2.1 release doesn't build on 2.x and so\n\t    people are clearly still using gcc 2.x.  The code has been\n\t    rewritten to remove these extensions.\n\n2.1\t10 DEC 2004\tSignificantly improved directory handling plus numerous\n\t\t\tother smaller improvements\n\n\t1.  Fast indexed directories implemented.  These speed up directory\n\t    operations (ls, file lookup etc.) significantly for directories\n\t    larger than 8 KB.\n\t2.  All directories are now sorted in alphabetical order.  This again\n\t    speeds up directory operations, and in some cases it also results in\n\t    a small compression improvement (greater data similarity between\n\t    files with alphabetically similar names).\n\t3.  Maximum directory size increased from 512 KB to 128 MB.\n\t4.  Duplicate fragment checking and appending optimised in mksquashfs,\n\t    depending on filesystem, this is now up to 25% faster.\n\t5.  Mksquashfs help information reformatted and reorganised.\n\t6.  The Squashfs version and release date is now printed at kernel\n\t    boot-time or module insertion.  This addition will hopefully help\n\t    to reduce the growing problem where the Squashfs version supported\n\t    by a kernel is unknown and the kernel source is unavailable.\n        7.  New PERFORMANCE.README file.\n\t8.  New -2.0 mksquashfs option.\n\t9.  CHANGES file reorganised.\n\t10. README file reorganised, clarified and updated to include the 2.0\n\t    mksquashfs options.\n\t11. New patch for Linux 2.6.9.\n\t12. New patch for Linux 2.4.28.\n\n2.0r2\t29 AUG 2004\tWorkaround for kernel bug in kernels 2.6.8 and newer\n\t\t\tadded\n\n\t1. New patch for kernel 2.6.8.1.  This includes a workaround for a\n\t   kernel bug introduced in 2.6.7bk14, which is present in all later\n\t   versions of the kernel.  \n\n\t   If you're using a 2.6.8 kernel or later then you must use this\n\t   2.6.8.1 patch.  If you've experienced hangs or oopses using Squashfs\n\t   with a 2.6.8 or later kernel then you've hit this bug, and this\n\t   patch will fix it.\n\n\t   It is worth mentioning that this kernel bug potentially affects\n\t   other filesystems.  If you receive odd results with other\n\t   filesystems you may be experiencing this bug with that filesystem.\n\t   I submitted a patch but this has not yet gone into the\n\t   kernel, hopefully the bug will be fixed in later kernels. \n\n2.0\t13 JULY 2004\tA couple of new options, and some bug fixes\n\n\t1. New mksquashfs -all-root, -root-owned, -force-uid, and -force-gid\n\t   options.  These allow the uids/gids of files in the generated\n\t   filesystem to be specified, overriding the uids/gids in the\n\t   source filesystem.\n\t2. Initrds are now supported for kernels 2.6.x.\n\t3. amd64 bug fixes.  If you use an amd64, please read the README-AMD64\n\t   file.\n\t4. Check-data and gid bug fixes.  With 2.0-alpha when mounting 1.x\n\t   filesystems in certain cases file gids were corrupted.\n\t5. New patch for Linux 2.6.7.\n\n2.0-ALPHA\t21 MAY 2004\tFilesystem changes and compression improvements\n\n\t1. Squashfs 2.0 has added the concept of fragment blocks.\n           Files smaller than the file block size and optionally the\n\t   remainder of files that do not fit fully into a block (i.e. the\n\t   last 32K in a 96K file) are packed into shared fragments and\n\t   compressed together.  This achieves on average 5 - 20% better\n\t   compression than Squashfs 1.x.\n\t2. The maximum block size has been increased to 64K (in the ALPHA\n\t   version of Squashfs 2.0).\n\t3. The maximum number of UIDs has been increased to 256 (from 48 in\n\t   1.x).\n\t4. The maximum number of GIDs has been increased to 256 (from 15 in\n\t   1.x).\n\t5. Removal of sleep_on() function call in 2.6.x patch, to allow Squashfs\n\t   to work on the Fedora rc2 kernel.\n\t6. Numerous small bug fixes have been made.\n\n1.3r3\t18 JAN 2004\tThird release of 1.3, this adds a new mksquashfs option,\n\t\t\tsome bug fixes, and extra patches for new kernels\n\n\t1. New mksquashfs -ef exclude option.  This option reads the exclude\n\t   dirs/files from an exclude file, one exclude dir/file per line.  This\n\t   avoids the command line size limit when using the -e exclude option,\n\t2. When appending to existing filesystems, if mksquashfs experiences a\n\t   fatal error (e.g. out of space when adding to the destination), the\n\t   original filesystem is restored,\n\t3. Mksquashfs now builds standalone, without the kernel needing to be\n\t   patched.\n\t4. Bug fix in the kernel squashfs filesystem, where the pages being\n\t   filled were not kmapped.  This seems to only have caused problems\n\t   on an Apple G5,\n\t5. New patch for Linux 2.4.24,\n\n\t6. New patch for Linux 2.6.1, this replaces the patch for 2.6.0-test7.\n\n1.3r2\t14 OCT 2003\tSecond release of 1.3, bug fixes and extra patches for\n\t\t        new kernels\n\n\t1. Bug fix in routine that adds files to the filesystem being\n\t   generated in mksquashfs.  This bug was introduced in 1.3\n\t   (not enough testing...) when I rewrote it to handle files larger\n\t   than available memory.  This bug caused a SEGV, so if you've ever\n\t   got that, it is now fixed,\n\t2. Long running bug where ls -s and du reported wrong block size\n\t   fixed.  I'm pretty sure this used to work many kernel versions ago\n\t   (2.4.7) but it broke somewhere along the line since then,\n\t3. New patch for Linux 2.4.22,\n\t4. New patch for 2.6.0-test7, this replaces the patch for 2.6.0-test1.\n\n1.3\t29 JUL 2003\tFIFO/Socket support added plus optimisations and\n\t\t        improvements\n\n\t1. FIFOs and Socket inodes are now supported,\n\t2. Mksquashfs can now compress files larger than available\n\t   memory,\n\t3. File duplicate check routine optimised,\n\t4. Exit codes fixed in Mksquashfs,\n\t5. Patch for Linux 2.4.21,\n\t6. Patch for Linux 2.6.0-test1.  Hopefully, this will work for\n\t   the next few releases of 2.6.0-testx, otherwise, I'll be\n\t   releasing a lot of updates to the 2.6.0 patch...\n\n1.2\t13 MAR 2003\tAppend feature and new mksquashfs options added\n\n\tMksquashfs can now add to existing squashfs filesystems.  Three extra\n\toptions \"-noappend\", \"-keep-as-directory\", and \"root-becomes\"\n\thave been added.\n\n\tThe append option with file duplicate detection, means squashfs can be\n\tused as a simple versioning archiving filesystem. A squashfs\n\tfilesystem can be created with for example the linux-2.4.19 source.\n\tAppending the linux-2.4.20 source will create a filesystem with the\n\ttwo source trees, but only the changed files will take extra room,\n\tthe unchanged files will be detected as duplicates.\n\n\tSee the README file for usage changes.\n\n1.1b\t16 JAN 2003\tBug fix release\n\n\tFixed readpage deadlock bug.  This was a rare deadlock bug that\n\thappened when pushing pages into the page cache when using greater\n\tthan 4K blocks.  I never got this bug when I tested the filesystem,\n\tbut two people emailed me on the same day about the problem!\n\tI fixed it by using a page cache function that wasn't there when\n\tI originally did the work, which was nice :-)\n\n1.1\t8 JAN 2003\tAdded features\n\n\t1. Kernel squashfs can now mount different byte order filesystems.\n\t2. Additional features added to mksquashfs.  Mksquashfs now supports\n\t   exclude files and multiple source files/directories can be\n\t   specified.  A nopad option has also been added, which\n\t   informs mksquashfs not to pad filesystems to a multiple of 4K.\n\t   See README for mksquashfs usage changes.\n\t3. Greater than 2GB filesystems bug fix.  Filesystems greater than 2GB\n\t   can now be created.\n\n1.0c \t14 NOV 2002\tBug fix release\n\n\tFixed bugs with initrds and device nodes\n\n1.0 \t23 OCT 2002\tInitial release\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/COPYING",
    "content": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n\t\t    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n\t    How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) 19yy  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) 19yy name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/INSTALL",
    "content": "\t\t\tINSTALLING SQUASHFS\n\nThe squashfs3.2-r2.tar.gz file contains this file, a README-3.2 file, another\nREADME file, an ACKNOWLEDGEMENTS file, a CHANGES file, the kernel-patches\ndirectory containing the squashfs patches, and the squashfs-tools directory\n(mksquashfs and unsquashfs).\n\n1. Patching the kernel\n----------------------\n\nThere are eleven kernel patch directories depending on your linux kernel\nversion.  If your kernel version isn't listed then try the patch for the nearest\nkernel listed.\n\nTo patch your kernel, cd into the top level directory, and run the \"patch\"\ncommand, e.g. assuming linux-2.6.20\n\n%cd /usr/src/linux-2.6.20\n%patch -p1 < location-of-squashfs/kernel-patches/linux-2.6.20/squashfs3.2-patch\n\nWhere \"location-of-squashfs\" is the path to the squashfs3.2 source directory.\n\nThe squashfs patches patch the relevant kernel files to add configure support,\ninitrd support, include files, and the squashfs directory under linux/fs/.\nOnce patched, the kernel must be reconfigured, with squashfs support turned on\n(either Y/M) to ensure that inflate support is built into the kernel.  The\nsquashfs kernel option can be found in the miscellaneous filesystems submenu\nnear the bottom of the filesystems submenu.\n\nThere are a set of options which are intended for use by embedded systems with\nlow memory.  At the \"Additional options for memory-constrained systems\" prompt,\nplease say NO unless you're using an embedded system!  Saying Y here allows you\nto specify cache sizes and how Squashfs allocates memory.\n\nThe \"Number of fragments cached\" prompt allows the number of fragments cached\nto be controlled.  By default SquashFS caches the last 3 fragments read from\nthe filesystem.  Increasing this amount may mean SquashFS has to re-read\nfragments less often from disk, at the expense of extra system memory.\nDecreasing this amount will mean SquashFS uses less memory at the expense of\nextra reads from disk.  Note there must be at least one cached fragment.\nAnything much more than three will probably not make much difference.\n\nThe \"Use Vmalloc rather than Kmalloc\" prompt allows you to tell SquashFS to\nuse Vmalloc.  By default SquashFS uses kmalloc to obtain fragment cache memory.\nKmalloc memory is the standard kernel allocator, but it can fail on memory\nconstrained systems.  Because of the way Vmalloc works, Vmalloc can succeed\nwhen kmalloc fails.  Specifying this option will make SquashFS always use\nVmalloc to allocate the fragment cache memory.\n\n2. Building squashfs tools\n--------------------------\n\nThe squashfs-tools directory contains the mksquashfs and unsquashfs programs.\nThese can be made by typing make.  The source files use a local copy of\nsquashfs_fs.h (included in the kernel patches) allowing the tools to be made\nwithout needing to patch the kernel.\n\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/PERFORMANCE.README",
    "content": "GENERAL INFORMATION ON PERFORMANCE TESTS\n----------------------------------------\n\nThe following performance tests were based on two file sets: the\nliveCD filesystem from the Ubuntu liveCD (Warty release), and the\nliveCD filesystem from the Damn Small Linux liveCD (release 0.8.4).\nThe Ubuntu liveCD filesystem was used to test filesystem performance\nfrom CDROM and hard disk for Zisofs, Cloop, Squashfs 2.0 and Squashfs2.1.\nCRAMFS filesystem performance could not be tested for this filesystem\nbacause it exceeds the maximum supported size of CRAMFS.  To test\nCRAMFS performance against Squashfs, the liveCD filesystem from\nDamn Small Linux was used.\n\nNOTE: the usual warnings apply to these results, they are provided for\nillustrative purposes only, and due to different hardware and/or file data, you\nmay obtain different results.  As such the results are provided \"as is\" without\nany warranty (either express or implied) and you assume all risks as to their\nquality and accuracy.\n\n1. Ubuntu liveCD performance tests\n\n   ext3 uncompressed size      1.4 GB\n   Zisofs compressed size      589.81 MB\n   Cloop compressed size       471.89 MB\n   Squashfs2.0 compressed size 448.58 MB\n   Squashfs2.1 compressed size 448.58 MB\n\n1.1 Performance tests from CDROM\n\n1.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  Zisofs       49.88 seconds (User 2.60 secs, Sys 11.19 secs)\n  Cloop        20.80 seconds (User 2.71 secs, Sys 13.50 secs)\n  Squashfs2.0  16.56 seconds (User 2.42 secs, Sys 10.37 secs)\n  Squashfs2.1  10.14 seconds (User 2.48 secs, Sys 4.44 secs)\n\n1.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  Zisofs       27 minutes 28.54 seconds (User 3.00 secs, Sys 1 min 4.80 secs)\n  Cloop        5 minutes 55.72 seconds (User 2.90 secs, Sys 3 min 37.90 secs)\n  Squashfs2.0  5 minutes 20.87 seconds (User 2.33 secs, Sys 56.98 secs)\n  Squashfs2.1  5 minutes 15.46 seconds (user 2.28 secs, Sys 51.12 secs)\n\n1.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n  Zisofs       101 minutes 29.65 seconds (User 5.33 secs, Sys  1 min 17.20 secs)\n  Cloop        35 minutes 27.51 seconds (user 5.93 secs, Sys 4 mins 30.23 secs)\n  Squashfs2.0  21 minutes 53.05 seconds (user 5.71 secs, Sys 2 mins 36.59 secs)\n  Squashfs2.1  21 minutes 46.99 seconds (User 5.80 secs, Sys 2 mins 31.88 secs)\n\n\n1.2 Performance tests from Hard disk\n\n1.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk \n\n  Zisofs       17.29 seconds (User 2.62 secs, Sys 11.08 secs)\n  Cloop        16.46 seconds (User 2.63 secs, Sys 13.41 secs)\n  Squashfs2.0  13.75 seconds (User 2.44 secs, Sys 11.00 secs)\n  Squashfs2.1  6.94 seconds (User 2.44 secs, Sys 4.48 secs)\n\n1.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk\n\n  Zisofs       1 minute 21.47 seconds (User 2.73 secs, Sys 54.44 secs)\n  Cloop        1 minute 34.06 seconds (user 2.85 secs, Sys 1 min 12.13 secs)\n  Squashfs2.0  1 minute 21.22 seconds (User 2.42 secs, Sys 56.21 secs)\n  Squashfs2.1  1 minute 15.46 seconds (User 2.36 secs, Sys 49.78 secs)\n\n1.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk\n\n  Zisofs       11 minutes 13.64 seconds (User 5.08 secs, Sys 52.62 secs)\n  Cloop        5 minutes 37.93 seconds (user 6 secs, Sys 2 mins 22.38 secs)\n  Squashfs2.0  5 minutes 7.11 seconds (user 5.63 secs, Sys 2 mins 35.23 secs)\n  Squashfs2.1  5 minutes 1.87 seconds (User 5.71 secs, Sys 2 mins 29.98 secs)\n\n\n2. Damn Small Linux liveCD performance tests\n\n   ext3 uncompressed size      126 MB\n   CRAMFS compressed size      52.19 MB\n   Squashfs2.0 compressed size 46.52 MB\n   Squashfs2.1 compressed size 46.52 MB\n\n2.1 Performance tests from CDROM\n\n2.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  CRAMFS       10.85 seconds (User 0.39 secs, Sys 0.98 secs)\n  Squashfs2.0  2.97 seconds (User 0.36 secs, Sys 2.15 secs)\n  Squashfs2.1  2.43 seconds (User 0.40 secs, Sys 1.42 secs)\n\n2.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  CRAMFS       55.38 seconds (User 0.34 secs, Sys 6.98 secs)\n  Squashfs2.0  35.99 seconds (User 0.30 secs, Sys 6.35 secs)\n  Squashfs2.1  33.83 seconds (User 0.26 secs, Sys 5.56 secs)\n\n2.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n\n  CRAMFS        3 minutes 1.68 seconds (User 0.54 secs, Sys 9.51 secs)\n  Squashfs2.0   1 minute 39.45 seconds (User 0.57 secs, Sys 13.14 secs)\n  Squashfs2.1   1 minute 38.41 seconds (User 0.58 secs, Sys 13.08 secs)\n\n2.2 Performance tests from Hard disk\n\n2.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk\n\n  CRAMFS       1.77 seconds (User 0.53 secs, Sys 1.21 secs)\n  Squashfs2.0  2.67 seconds (User 0.41 secs, Sys 2.25 secs)\n  Squashfs2.1  1.87 seconds (User 0.41 secs, Sys 1.46 secs)\n\n2.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk \n\n  CRAMFS       6.80 seconds (User 0.36 secs, Sys 6.02 secs)\n  Squashfs2.0  7.23 seconds (User 0.29 secs, Sys 6.62 secs)\n  Squashfs2.1  6.53 seconds (User 0.31 secs, Sys 5.82 secs)\n\n2.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk \n\n\n  CRAMFS       28.55 seconds (User 0.49 secs, Sys 6.49 secs)\n  Squashfs2.0  25.44 seconds (User 0.58 secs, Sys 13.17 secs)\n  Squashfs2.1  24.72 seconds (User 0.56 secs, Sys 13.15 secs)\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/README",
    "content": "\tSQUASHFS 3.2 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.2.  Please read the README-3.2 and CHANGES\nfiles for details of changes.\n\nSquashfs is a highly compressed read-only filesystem for Linux.\nIt uses zlib compression to compress both files, inodes and directories.\nInodes in the system are very small and all blocks are packed to minimise\ndata overhead. Block sizes greater than 4K are supported up to a maximum\nof 64K.\n\nSquashfs is intended for general read-only filesystem use, for archival\nuse (i.e. in cases where a .tar.gz file may be used), and in constrained\nblock device/memory systems (e.g. embedded systems) where low overhead is\nneeded.\n\n1. SQUASHFS OVERVIEW\n--------------------\n\n1. Data, inodes and directories are compressed.\n\n2. Squashfs stores full uid/gids (32 bits), and file creation time.\n\n3. In theory files up to 2^64 bytes are supported.  In theory filesystems can\n   be up to 2^64 bytes.\n\n4. Inode and directory data are highly compacted, and packed on byte\n   boundaries.  Each compressed inode is on average 8 bytes in length\n   (the exact length varies on file type, i.e. regular file, directory,\n   symbolic link, and block/char device inodes have different sizes).\n\n5. Squashfs can use block sizes up to 64K (the default size is 64K).\n   Using 64K blocks achieves greater compression ratios than the normal\n   4K block size.\n\n6. File duplicates are detected and removed.\n\n7. Both big and little endian architectures are supported.  Squashfs can\n   mount filesystems created on different byte order machines.\n\n\n2. USING SQUASHFS\n-----------------\n\nSquashfs filesystems should be mounted with 'mount' with the filesystem type\n'squashfs'.  If the filesystem is on a block device, the filesystem can be\nmounted directly, e.g.\n\n%mount -t squashfs /dev/sda1 /mnt\n\nWill mount the squashfs filesystem on \"/dev/sda1\" under the directory \"/mnt\".\n\nIf the squashfs filesystem has been written to a file, the loopback device\ncan be used to mount it (loopback support must be in the kernel), e.g.\n\n%mount -t squashfs image /mnt -o loop\n\nWill mount the squashfs filesystem in the file \"image\" under\nthe directory \"/mnt\".\n\n\n3. MKSQUASHFS\n-------------\n\n3.1 Mksquashfs options and overview.\n------------------------------------\n\nAs squashfs is a read-only filesystem, the mksquashfs program must be used to\ncreate populated squashfs filesystems.\n\nSYNTAX:mksquashfs source1 source2 ...  dest [options] [-e list of exclude\ndirs/files]\n\nOptions are\n-version\t\tprint version, licence and copyright message\n-info\t\t\tprint files written to filesystem\n-b <block_size>\t\tset data block to <block_size>.  Default 65536 bytes\n-processors <number>\tUse <number> processors.  By default will use number of\n\t\t\tprocessors available\n-read-queue <size>\tSet input queue to <size> Mbytes.  Default 64 Mbytes\n-write-queue <size>\tSet output queue to <size> Mbytes.  Default 512 Mbytes\n-noI\t\t\tdo not compress inode table\n-noD\t\t\tdo not compress data blocks\n-noF\t\t\tdo not compress fragment blocks\n-no-fragments\t\tdo not use fragments\n-always-use-fragments\tuse fragment blocks for files larger than block size\n-no-duplicates\t\tdo not perform duplicate checking\n-noappend\t\tdo not append to existing filesystem\n-keep-as-directory\tif one source directory is specified, create a root\n\t\t\tdirectory containing that directory, rather than the\n\t\t\tcontents of the directory\n-root-becomes <name>\twhen appending source files/directories, make the\n\t\t\toriginal root become a subdirectory in the new root\n\t\t\tcalled <name>, rather than adding the new source items\n\t\t\tto the original root\n-all-root\t\tmake all files owned by root\n-force-uid uid\t\tset all file uids to uid\n-force-gid gid\t\tset all file gids to gid\n-le\t\t\tcreate a little endian filesystem\n-be\t\t\tcreate a big endian filesystem\n-nopad\t\t\tdo not pad filesystem to a multiple of 4K\n-check_data\t\tadd checkdata for greater filesystem checks\n-root-owned\t\talternative name for -all-root\n-noInodeCompression\talternative name for -noI\n-noDataCompression\talternative name for -noD\n-noFragmentCompression\talternative name for -noF\n-sort <sort_file>\tsort files according to priorities in <sort_file>.  One\n\t\t\tfile or dir with priority per line.  Priority -32768 to\n\t\t\t32767, default priority 0\n-ef <exclude_file>\tlist of exclude dirs/files.  One per line\n\nSource1 source2 ... are the source directories/files containing the\nfiles/directories that will form the squashfs filesystem.  If a single\ndirectory is specified (i.e. mksquashfs source output_fs) the squashfs\nfilesystem will consist of that directory, with the top-level root\ndirectory corresponding to the source directory.\n\nIf multiple source directories or files are specified, mksquashfs will merge\nthe specified sources into a single filesystem, with the root directory\ncontaining each of the source files/directories.  The name of each directory\nentry will be the basename of the source path.   If more than one source\nentry maps to the same name, the conflicts are named xxx_1, xxx_2, etc. where\nxxx is the original name.\n\nTo make this clear, take two example directories.  Source directory\n\"/home/phillip/test\" contains  \"file1\", \"file2\" and \"dir1\".\nSource directory \"goodies\" contains \"goodies1\", \"goodies2\" and \"goodies3\".\n\nusage example 1:\n\n%mksquashfs /home/phillip/test output_fs\n\nThis will generate a squashfs filesystem with root entries\n\"file1\", \"file2\" and \"dir1\".\n\nexample 2:\n\n%mksquashfs /home/phillip/test goodies output_fs\n\nThis will create a squashfs filesystem with the root containing\nentries \"test\" and \"goodies\" corresponding to the source\ndirectories \"/home/phillip/test\" and \"goodies\".\n\nexample 3:\n\n%mksquashfs /home/phillip/test goodies test output_fs\n\nThis is the same as the previous example, except a third\nsource directory \"test\" has been specified.  This conflicts\nwith the first directory named \"test\" and will be renamed \"test_1\".\n\nMultiple sources allow filesystems to be generated without needing to\ncopy all source files into a common directory.  This simplifies creating\nfilesystems.\n\nThe -keep-as-directory option can be used when only one source directory\nis specified, and you wish the root to contain that directory, rather than\nthe contents of the directory.  For example:\n\nexample 4:\n\n%mksquashfs /home/phillip/test output_fs -keep-as-directory\n\nThis is the same as example 1, except for -keep-as-directory.\nThis will generate a root directory containing directory \"test\",\nrather than the \"test\" directory contents \"file1\", \"file2\" and \"dir1\".\n\nThe Dest argument is the destination where the squashfs filesystem will be\nwritten.  This can either be a conventional file or a block device.  If the file\ndoesn't exist it will be created, if it does exist and a squashfs\nfilesystem exists on it, mksquashfs will append.  The -noappend option will\nwrite a new filesystem irrespective of whether an existing filesystem is\npresent.\n\n3.2 Changing compression defaults used in mksquashfs\n----------------------------------------------------\n\nThere are a large number of options that can be used to control the \ncompression in mksquashfs.  By and large the defaults are the most\noptimum settings and should only be changed in exceptional circumstances!\n\nThe -noI, -noD and -noF options (also -noInodeCompression, -noDataCompression\nand -noFragmentCompression) can be used to force mksquashfs to not compress\ninodes/directories, data and fragments respectively.  Giving all options\ngenerates an uncompressed filesystem.\n\nThe -no-fragments tells mksquashfs to not generate fragment blocks, and rather\ngenerate a filesystem similar to a Squashfs 1.x filesystem.  It will of course\nstill be a Squashfs 2.0 filesystem but without fragments, and so it won't be\nmountable on a Squashfs 1.x system.\n\nThe -always-use-fragments option tells mksquashfs to always generate\nfragments for files irrespective of the file length.  By default only small\nfiles less than the block size are packed into fragment blocks.  The ends of\nfiles which do not fit fully into a block, are NOT by default packed into\nfragments.  To illustrate this, a 100K file has an initial 64K block and a 36K\nremainder.  This 36K remainder is not packed into a fragment by default.  This\nis because to do so leads to a 10 - 20% drop in sequential I/O performance, as a\ndisk head seek is needed to seek to the initial file data and another disk seek\nis need to seek to the fragment block.  Specify this option if you want file\nremainders to be packed into fragment blocks.  Doing so may increase the\ncompression obtained BUT at the expense of I/O speed.\n\nThe -no-duplicates option tells mksquashfs to not check the files being\nadded to the filesystem for duplicates.  This can result in quicker filesystem\ngeneration and appending although obviously compression will suffer badly if\nthere is a lot of duplicate files.\n\nThe -b option allows the block size to be selected, this can be either\n4096, 8192, 16384, 32768 or 65536 bytes.\n\n3.3 Specifying the UIDs/GIDs used in the filesystem\n---------------------------------------------------\n\nBy default files in the generated filesystem inherit the UID and GID ownership\nof the original file.  However,  mksquashfs provides a number of options which\ncan be used to override the ownership.\n\nThe options -all-root and -root-owned (both do exactly the same thing) force all\nfile uids/gids in the generated Squashfs filesystem to be root.  This allows\nroot owned filesystems to be built without root access on the host machine.\n\nThe \"-force-uid uid\"  option forces all files in the generated Squashfs\nfilesystem to be owned by the specified uid.  The uid can be specified either by\nname (i.e. \"root\") or by number.\n\nThe \"-force-gid gid\" option forces all files in the generated Squashfs\nfilesystem to be group owned by the specified gid.  The gid can be specified\neither by name (i.e. \"root\") or by number.\n\n3.4 Excluding files from the filesystem\n---------------------------------------\n\nThe -e and -ef options allow files/directories to be specified which are\nexcluded from the output filesystem.  The -e option takes the exclude\nfiles/directories from the command line, the -ef option takes the\nexlude files/directories from the specified exclude file, one file/directory\nper line. If an exclude file/directory is absolute (i.e. prefixed with /, ../,\nor ./) the entry is treated as absolute, however, if an exclude file/directory\nis relative, it is treated as being relative to each of the sources in turn,\ni.e.\n\n%mksquashfs /tmp/source1 source2  output_fs -e ex1 /tmp/source1/ex2 out/ex3\n\nWill generate exclude files /tmp/source1/ex2, /tmp/source1/ex1, source2/ex1,\n/tmp/source1/out/ex3 and source2/out/ex3.\n\nThe -e and -ef exclude options are usefully used in archiving the entire\nfilesystem, where it is wished to avoid archiving /proc, and the filesystem\nbeing generated, i.e.\n\n%mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh\n\nMultiple -ef options can be specified on the command line, and the -ef\noption can be used in conjuction with the -e option.\n\n3.5 Appending to squashfs filesystems\n-------------------------------------\n\nRunning squashfs with the destination directory containing an existing\nfilesystem will add the source items to the existing filesystem.  By default,\nthe source items are added to the existing root directory.\n\nTo make this clear... An existing filesystem \"image\" contains root entries\n\"old1\", and \"old2\".  Source directory \"/home/phillip/test\" contains  \"file1\",\n\"file2\" and \"dir1\".\n\nexample 1:\n\n%mksquashfs /home/phillip/test image\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", \"file1\", \"file2\" and\n\"dir1\"\n\nexample 2:\n\n%mksquashfs /home/phillip/test image -keep-as-directory\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", and \"test\".\nAs shown in the previous section, for single source directories\n'-keep-as-directory' adds the source directory rather than the\ncontents of the directory.\n\nexample 3:\n\n%mksquashfs /home/phillip/test image -keep-as-directory -root-becomes\noriginal-root\n\nWill create a new \"image\" with root entries \"original-root\", and \"test\".  The\n'-root-becomes' option specifies that the original root becomes a subdirectory\nin the new root, with the specified name.\n\nThe append option with file duplicate detection, means squashfs can be\nused as a simple versioning archiving filesystem. A squashfs filesystem can\nbe created with for example the linux-2.4.19 source.  Appending the linux-2.4.20\nsource will create a filesystem with the two source trees, but only the\nchanged files will take extra room, the unchanged files will be detected as\nduplicates.\n\n3.6 Miscellaneous options\n-------------------------\n\nThe -info option displays the files/directories as they are compressed and\nadded to the filesystem.  The original uncompressed size of each file\nis printed, along with DUPLICATE if the file is a duplicate of a\nfile in the filesystem.\n\nThe -le and -be options can be used to force mksquashfs to generate a little\nendian or big endian filesystem.  Normally mksquashfs will generate a\nfilesystem in the host byte order.  Squashfs, for portability, will\nmount different ordered filesystems (i.e. it can mount big endian filesystems\nrunning on a little endian machine), but these options can be used for\ngreater optimisation.\n\nThe -nopad option informs mksquashfs to not pad the filesystem to a 4K multiple.\nThis is performed by default to enable the output filesystem file to be mounted\nby loopback, which requires files to be a 4K multiple.  If the filesystem is\nbeing written to a block device, or is to be stored in a bootimage, the extra\npad bytes are not needed.\n\n4. UNSQUASHFS\n-------------\n\nUnsquashfs allows you to decompress and extract a Squashfs filesystem without\nmounting it.  It can extract the entire filesystem, or a specific\nfile or directory.\n\nThe Unsquashfs usage info is:\n\nSYNTAX: ./unsquashfs [options] filesystem [directory or file to extract]\n\t-v[ersion]\t\tprint version, licence and copyright information\n\t-i[nfo]\t\t\tprint files as they are unsquashed\n\t-l[s]\t\t\tlist filesystem only\n\t-d[est] <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\t-f[orce]\t\tif file already exists then overwrite\n\n\nTo extract a subset of the filesystem, the filename or directory\ntree that is to be extracted can now be specified on the command line.  The\nfile/directory should be specified using the full path to the file/directory\nas it appears within the Squashfs filesystem.  The file/directory will also be\nextracted to that position within the specified destination directory.\n\nThe \"-ls\" option can be used to list the contents of a filesystem without\ndecompressing the filesystem data itself.\n\nThe \"-info\" option forces Unsquashfs to print each file as it is decompressed.\n\nThe \"-dest\" option specifies the directory that is used to decompress\nthe filesystem data.  If this option is not given then the filesystem is\ndecompressed to the directory \"squashfs-root\" in the current working directory.\n\nThe \"-force\" option forces Unsquashfs to output to the destination\ndirectory even if files or directories already exist.  This allows you\nto update an existing directory tree, or to Unsquashfs to a partially\nfilled directory.  Without the \"-force\" option, Unsquashfs will\nrefuse to overwrite any existing files, or to create any directories if they\nalready exist.  This is done to protect data in case of mistakes, and\nso the \"-force\" option should be used with caution.\n\nUnsquashfs can decompress 2.x and 3.x filesystems.  Support for 1.x filesystems\nwill be added in the future.\n\n5. FILESYSTEM LAYOUT\n--------------------\n\nBrief filesystem design notes follow for the original 1.x filesystem\nlayout.  A description of the 2.x and 3.x filesystem layouts will be written\nsometime!\n\nA squashfs filesystem consists of five parts, packed together on a byte\nalignment:\n\n\t ---------------\n\t|  superblock \t|\n\t|---------------|\n\t|     data\t|\n\t|    blocks\t|\n\t|---------------|\n\t|    inodes\t|\n\t|---------------|\n\t|   directories\t|\n\t|---------------|\n\t|    uid/gid\t|\n\t|  lookup table\t|\n\t ---------------\n\nCompressed data blocks are written to the filesystem as files are read from\nthe source directory, and checked for duplicates.  Once all file data has been\nwritten the completed inode, directory and uid/gid lookup tables are written.\n\n5.1 Metadata\n------------\n\nMetadata (inodes and directories) are compressed in 8Kbyte blocks.  Each\ncompressed block is prefixed by a two byte length, the top bit is set if the\nblock is uncompressed.  A block will be uncompressed if the -noI option is set,\nor if the compressed block was larger than the uncompressed block.\n\nInodes are packed into the metadata blocks, and are not aligned to block\nboundaries, therefore inodes overlap compressed blocks.  An inode is\nidentified by a two field tuple <start address of compressed block : offset\ninto de-compressed block>.\n\nInode contents vary depending on the file type.  The base inode consists of:\n\n\tbase inode:\n\t\tInode type\n\t\tMode\n\t\tuid index\n\t\tgid index\n\nThe inode type is 4 bits in size, and the mode is 12 bits.\n\nThe uid and gid indexes are 4 bits in length.  Ordinarily, this will allow 16\nunique indexes into the uid table.  To minimise overhead, the uid index is\nused in conjunction with the spare bit in the file type to form a 48 entry\nindex as follows:\n\n\tinode type 1 - 5: uid index = uid\n\tinode type 5 -10: uid index = 16 + uid\n\tinode type 11 - 15: uid index = 32 + uid\n\nIn this way 48 unique uids are supported using 4 bits, minimising data inode\noverhead.  The 4 bit gid index is used to index into a 15 entry gid table.\nGid index 15 is used to indicate that the gid is the same as the uid.\nThis prevents the 15 entry gid table filling up with the common case where\nthe uid/gid is the same.\n\nThe data contents of symbolic links are stored immediately after the symbolic\nlink inode, inside the inode table.  This allows the normally small symbolic\nlink to be compressed as part of the inode table, achieving much greater\ncompression than if the symbolic link was compressed individually.\n\nSimilarly, the block index for regular files is stored immediately after the\nregular file inode.  The block index is a list of block lengths (two bytes\neach), rather than block addresses, saving two bytes per block.  The block\naddress for a given block is computed by the summation of the previous\nblock lengths.  This takes advantage of the fact that the blocks making up a\nfile are stored contiguously in the filesystem.  The top bit of each block\nlength is set if the block is uncompressed, either because the -noD option is\nset, or if the compressed block was larger than the uncompressed block.\n\n5.2 Directories\n---------------\n\nLike inodes, directories are packed into the metadata blocks, and are not\naligned on block boundaries, therefore directories can overlap compressed\nblocks.  A directory is, again, identified by a two field tuple\n<start address of compressed block containing directory start : offset\ninto de-compressed block>.\n\nDirectories are organised in a slightly complex way, and are not simply\na list of file names and inode tuples.  The organisation takes advantage of the\nobservation that in most cases, the inodes of the files in the directory\nwill be in the same compressed metadata block, and therefore, the\ninode tuples will have the same start block.\n\nDirectories are therefore organised in a two level list, a directory\nheader containing the shared start block value, and a sequence of\ndirectory entries, each of which share the shared start block.  A\nnew directory header is written once/if the inode start block\nchanges.  The directory header/directory entry list is repeated as many times\nas necessary.  The organisation is as follows:\n\n\tdirectory_header:\n\t\tcount (8 bits)\n\t\tinode start block (24 bits)\n\t\t\n\t\tdirectory entry: * count\n\t\t\tinode offset (13 bits)\n\t\t\tinode type (3 bits)\n\t\t\tfilename size (8 bits)\n\t\t\tfilename\n\t\t\t\nThis organisation saves on average 3 bytes per filename.\n\n5.3 File data\n-------------\n\nFile data is compressed on a block by block basis and written to the\nfilesystem.  The filesystem supports up to 32K blocks, which achieves\ngreater compression ratios than the Linux 4K page size.\n\nThe disadvantage with using greater than 4K blocks (and the reason why\nmost filesystems do not), is that the VFS reads data in 4K pages.\nThe filesystem reads and decompresses a larger block containing that page\n(e.g. 32K).  However, only 4K can be returned to the VFS, resulting in a\nvery inefficient filesystem, as 28K must be thrown away.   Squashfs,\nsolves this problem by explicitly pushing the extra pages into the page\ncache.\n\n\n6. AUTHOR INFO\n--------------\n\nSquashfs was written by Phillip Lougher, email phillip@lougher.org.uk,\nin Chepstow, Wales, UK.   If you like the program, or have any problems,\nthen please email me, as it's nice to get feedback!\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/README-3.2",
    "content": "\tSQUASHFS 3.2 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.2.  Squashfs 3.2 has support for NFS exporting,\nsome improvements to the Squashfs tools (Mksquashfs and Unsquashfs), some\nmajor bug fixes, new kernel patches, and various other smaller improvements\nand bug fixes.  Please see the CHANGES file for a detailed list.\n\n1. MKSQUASHFS\n-------------\n\nNew command line options:\n\n-no-exports\n\n\tSquashfs now supports NFS exports.  By default the additional\n\tinformation necessary is added to the filesystem by Mksquashfs.  If you\n\tdo not wish this extra information, then this option can be specified.\n\tThis will save a couple of bytes per file, and the filesystem\n\twill be identical to Squashfs 3.1.\n\n-no-progress\n\n\tMksquashfs by default now displays a progress bar. This option disables\n\tit.\n\n2. UNSQUASHFS\n-------------\n\n\tUnsquashfs now supports Squashfs 2.x filesystems.\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/sqlzma2u-3.2-r2.patch",
    "content": "Index: squashfs3.2-r2/squashfs-tools/Makefile\n===================================================================\nRCS file: squashfs3.2-r2/squashfs-tools/Makefile,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.2-r2/squashfs-tools/Makefile\t16 Jan 2007 03:32:18 -0000\t1.1\n+++ squashfs3.2-r2/squashfs-tools/Makefile\t16 Jan 2007 05:08:17 -0000\t1.2\n@@ -1,19 +1,44 @@\n+\n+ifndef Sqlzma\n+$(error Sqlzma is not defined)\n+endif\n+\n INCLUDEDIR = .\n \n CFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\n+ifdef UseDebugFlags\n+DebugFlags = -g -Wall -Wno-unused-variable -O0 -UNDEBUG\n+endif\n+CFLAGS += -I${Sqlzma} -D_REENTRANT -DNDEBUG ${DebugFlags}\n+LDLIBS += -lz -L${LzmaAlone} -L${LzmaC}\n+Tgt = mksquashfs unsquashfs\n \n-all: mksquashfs unsquashfs\n+all: ${Tgt}\n \n-mksquashfs: mksquashfs.o read_fs.o sort.o\n-\t$(CC) mksquashfs.o read_fs.o sort.o -lz -lpthread -lm -o $@\n+read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h \\\n+\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h\n \n-mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h\n+sort.o: sort.c squashfs_fs.h global.h sort.h\n \n-read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h\n+mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \\\n+\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h \\\n+\t${LzmaAlone}/liblzma_r.a ${LzmaC}/libunlzma_r.a\n \n-sort.o: sort.c squashfs_fs.h global.h sort.h\n+mksquashfs: LDLIBS += -lpthread -lunlzma_r -llzma_r -lstdc++\n+mksquashfs: mksquashfs.o read_fs.o sort.o\n+\n+unsquashfs.o: CFLAGS += -U_REENTRANT\n+unsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h \\\n+\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h ${LzmaC}/libunlzma.a\n \n+unsquashfs: LDLIBS += -lunlzma\n unsquashfs: unsquashfs.o\n-\t$(CC) unsquashfs.o -lz -o $@\n \n-unsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h\n+clean:\n+\t${RM} *~ *.o ${Tgt}\n+\n+-include test.mk\n+\n+# Local variables: ;\n+# compile-command: (concat \"make Sqlzma=../.. -f \" (file-name-nondirectory (buffer-file-name)));\n+# End: ;\nIndex: squashfs3.2-r2/squashfs-tools/mksquashfs.c\n===================================================================\nRCS file: squashfs3.2-r2/squashfs-tools/mksquashfs.c,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.2-r2/squashfs-tools/mksquashfs.c\t16 Jan 2007 03:32:18 -0000\t1.1\n+++ squashfs3.2-r2/squashfs-tools/mksquashfs.c\t16 Jan 2007 05:08:17 -0000\t1.2\n@@ -59,6 +59,8 @@\n #include \"mksquashfs.h\"\n #include \"global.h\"\n #include \"sort.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n #ifdef SQUASHFS_TRACE\n #define TRACE(s, args...)\tdo { \\\n@@ -107,6 +109,7 @@ unsigned short uid_count = 0, guid_count\n squashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\n int block_offset;\n int file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n+struct sqlzma_un un;\n \n /* write position within data section */\n long long bytes = 0, total_bytes = 0;\n@@ -326,6 +329,7 @@ struct dir_info *dir_scan1(char *, int (\n struct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\n extern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\n extern struct priority_entry *priority_list[65536];\n+int dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\n \n \n struct allocator *alloc_init(int buffer_size, int max_buffers)\n@@ -593,21 +597,7 @@ unsigned int mangle2(z_stream **strm, ch\n \t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n \t}\n \n-\tstream->next_in = (unsigned char *) s;\n-\tstream->avail_in = size;\n-\tstream->next_out = (unsigned char *) d;\n-\tstream->avail_out = block_size;\n-\n-\tres = deflate(stream, Z_FINISH);\n-\tif(res != Z_STREAM_END && res != Z_OK) {\n-\t\tif(res == Z_STREAM_ERROR)\n-\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n-\t\telse if(res == Z_BUF_ERROR)\n-\t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\\n\");\n-\t\telse\n-\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n-\t}\n-\n+\tres = sqlzma_cm(un.un_lzma, stream, s, size, d, block_size);\n \tc_byte = stream->total_out;\n \n \tif(res != Z_STREAM_END || c_byte >= size) {\n@@ -706,6 +696,7 @@ void write_bytes(int fd, long long byte,\n \t\tEXIT_MKSQUASHFS();\n \t}\n \n+\t//printf(\"%d bytes at %Ld\\n\", bytes, off);\n \tif(write(fd, buff, bytes) == -1) {\n \t\tperror(\"Write on destination failed\");\n \t\tEXIT_MKSQUASHFS();\n@@ -1220,17 +1211,17 @@ char *get_fragment(char *buffer, struct \n \t\tint res;\n \t\tunsigned long bytes = block_size;\n \t\tchar cbuffer[block_size];\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = cbuffer, .sz = size},\n+\t\t\t{.buf = buffer, .sz = bytes}\n+\t\t};\n \n \t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n-\n-\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t}\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tBAD_ERROR(\"%s:%d: res %d\\n\", __func__, __LINE__, res);\n+\t\tbytes = un.un_reslen;\n \t} else\n \t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n \n@@ -1623,7 +1614,7 @@ void reader_read_file(struct dir_ent *di\n \t\tfile_buffer->block = count;\n \t\tfile_buffer->block_order = block_order ++;\n \t\tfile_buffer->error = FALSE;\n-\t\tif(file_buffer->fragment = count == frag_block)\n+\t\tif((file_buffer->fragment = (count == frag_block))) //??\n \t\t\tqueue_put(from_deflate, file_buffer);\n \t\telse\n \t\t\tqueue_put(from_reader, file_buffer);\n@@ -1682,6 +1673,7 @@ void *reader(void *arg)\n \t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n \t\t\t\treader_read_file(entry->dir);\n \t}\n+\treturn NULL;\n }\n \n \n@@ -1711,6 +1703,7 @@ void *writer(void *arg)\n \t\t\twrite_error = TRUE;\n \t\t}\n \n+\t\t//printf(\"%d bytes at %Ld\\n\", file_buffer->size, off);\n \t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n \t\t\tperror(\"Write on destination failed\");\n \t\t\twrite_error = TRUE;\n@@ -1830,7 +1823,7 @@ int progress_bar(long long current, long\n \tint spaces = columns - used - hashes;\n \n \tif(!progress || columns - used < 0)\n-\t\treturn;\n+\t\treturn 0;\n \n \tprintf(\"\\r[\");\n \n@@ -1843,6 +1836,7 @@ int progress_bar(long long current, long\n \tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n \tprintf(\" %3lld%%\", current * 100 / max);\n \tfflush(stdout);\n+\treturn 0;\n }\n \n \n@@ -2479,7 +2473,7 @@ error:\n \n int dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n {\n-\tint squashfs_type;\n+\tint squashfs_type = -1;\n \tint result = FALSE;\n \tint duplicate_file;\n \tchar *pathname = dir_info->pathname;\n@@ -2774,7 +2768,8 @@ skip_inode_hash_table:\n \tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n \tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n \tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n-\tprintf(\"GNU General Public License for more details.\\n\");\n+\tprintf(\"GNU General Public License for more details.\\n\"); \\\n+\tprintf(\"and LZMA support for slax.org by jro.\\n\");\n int main(int argc, char *argv[])\n {\n \tstruct winsize winsize;\n@@ -2792,6 +2787,7 @@ int main(int argc, char *argv[])\n \tbe = FALSE;\n #endif\n \n+\tun.un_lzma = 1;\n \tblock_log = slog(block_size);\n \tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n \t\tVERSION();\n@@ -2947,6 +2943,8 @@ int main(int argc, char *argv[])\n \t\t\t\texit(1);\n \t\t\t}\t\n \t\t\troot_name = argv[i];\n+\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n+\t\t\tun.un_lzma = 0;\n \t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n \t\t\tVERSION();\n \t\t} else {\n@@ -3125,8 +3123,8 @@ printOptions:\n \t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n \t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n \n-\t\tcompressed_data = inode_dir_offset + inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1);\n-\t\tuncompressed_data = inode_dir_offset + inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1);\n+\t\tcompressed_data = inode_dir_offset + (inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1)); //??\n+\t\tuncompressed_data = inode_dir_offset + (inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1)); //??\n \t\t\n \t\t/* save original filesystem state for restoring ... */\n \t\tsfragments = fragments;\n@@ -3193,6 +3191,11 @@ printOptions:\n #endif\n \n \tblock_offset = check_data ? 3 : 2;\n+\ti = sqlzma_init(&un, un.un_lzma, 0);\n+\tif (i != Z_OK) {\n+\t\tERROR(\"%s:%d: %d\\n\", __func__, __LINE__, i);\n+\t\tEXIT_MKSQUASHFS();\n+\t}\n \n \tif(progress) {\n \t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n@@ -3211,7 +3214,9 @@ printOptions:\n \t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n \tsBlk.root_inode = inode;\n \tsBlk.inodes = inode_count;\n-\tsBlk.s_magic = SQUASHFS_MAGIC;\n+\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n+\tif (!un.un_lzma)\n+\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n \tsBlk.s_major = SQUASHFS_MAJOR;\n \tsBlk.s_minor = SQUASHFS_MINOR;\n \tsBlk.block_size = block_size;\nIndex: squashfs3.2-r2/squashfs-tools/read_fs.c\n===================================================================\nRCS file: squashfs3.2-r2/squashfs-tools/read_fs.c,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.2-r2/squashfs-tools/read_fs.c\t16 Jan 2007 03:32:18 -0000\t1.1\n+++ squashfs3.2-r2/squashfs-tools/read_fs.c\t16 Jan 2007 05:08:17 -0000\t1.2\n@@ -46,6 +46,8 @@ extern int add_file(long long, long long\n #include <squashfs_fs.h>\n #include \"read_fs.h\"\n #include \"global.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n #include <stdlib.h>\n \n@@ -62,6 +64,7 @@ extern int add_file(long long, long long\n \t\t\t\t\t} while(0)\n \n int swap;\n+extern struct sqlzma_un un;\n \n int read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n {\n@@ -81,19 +84,20 @@ int read_block(int fd, long long start, \n \t\tchar buffer[SQUASHFS_METADATA_SIZE];\n \t\tint res;\n \t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = buffer},\n+\t\t\t{.buf = block, .sz = bytes}\n+\t\t};\n \n \t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n \t\tread_bytes(fd, start + offset, c_byte, buffer);\n \n-\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t\treturn 0;\n-\t\t}\n+\t\tsbuf[Src].sz = c_byte;\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tabort();\n+\t\tbytes = un.un_reslen;\n \t\tif(next)\n \t\t\t*next = start + offset + c_byte;\n \t\treturn bytes;\n@@ -351,18 +355,30 @@ int read_super(int fd, squashfs_super_bl\n \n \t/* Check it is a SQUASHFS superblock */\n \tswap = 0;\n-\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n-\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n-\t\t\tsquashfs_super_block sblk;\n-\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n-\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n-\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n-\t\t\tswap = 1;\n-\t\t} else  {\n-\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n-\t\t\tgoto failed_mount;\n-\t\t}\n-\t}\n+\tswitch (sBlk->s_magic) {\n+\t\tsquashfs_super_block sblk;\n+\n+\tcase SQUASHFS_MAGIC_LZMA:\n+\t\tif (!un.un_lzma)\n+\t\t\tgoto bad;\n+\t\tbreak;\n+\tcase SQUASHFS_MAGIC:\n+\t\tbreak;\n+\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n+\t\tif (!un.un_lzma)\n+\t\t\tgoto bad;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_SWAP:\n+\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n+\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n+\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n+\t\tswap = 1;\n+\t\tbreak;\n+\tbad:\n+\tdefault:\n+\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n+\t\tgoto failed_mount;\n+ \t}\n \n \t/* Check the MAJOR & MINOR versions */\n \tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n@@ -416,7 +432,8 @@ unsigned char *squashfs_readdir(int fd, \n \tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n \tunsigned char *directory_table = NULL;\n \tint byte, bytes = 0, dir_count;\n-\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block; \n+\tlong long start = sBlk->directory_table_start + directory_start_block,\n+\t\tlast_start_block = -1;\n \n \tsize += offset;\n \tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\nIndex: squashfs3.2-r2/squashfs-tools/unsquashfs.c\n===================================================================\nRCS file: squashfs3.2-r2/squashfs-tools/unsquashfs.c,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.2-r2/squashfs-tools/unsquashfs.c\t16 Jan 2007 03:32:18 -0000\t1.1\n+++ squashfs3.2-r2/squashfs-tools/unsquashfs.c\t16 Jan 2007 05:08:18 -0000\t1.2\n@@ -46,6 +46,8 @@\n #include <squashfs_fs.h>\n #include \"read_fs.h\"\n #include \"global.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n #include <stdlib.h>\n \n@@ -97,6 +99,7 @@ unsigned int block_size;\n int lsonly = FALSE, info = FALSE, force = FALSE;\n char **created_inode;\n int root_process;\n+struct sqlzma_un un;\n \n #define CALCULATE_HASH(start)\t(start & 0xffff)\n \n@@ -144,6 +147,7 @@ int read_bytes(long long byte, int bytes\n \t\treturn FALSE;\n \t}\n \n+\t/* printf(\"%d bytes at %Ld\\n\", bytes, off); */\n \tif(read(fd, buff, bytes) == -1) {\n \t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n \t\treturn FALSE;\n@@ -175,21 +179,21 @@ int read_block(long long start, long lon\n \t\tchar buffer[SQUASHFS_METADATA_SIZE];\n \t\tint res;\n \t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = buffer},\n+\t\t\t{.buf = block, .sz = bytes}\n+\t\t};\n \n \t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n \t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n \t\t\tgoto failed;\n \n-\t\tif((res = uncompress((unsigned char *) block, &bytes,\n-\t\t(const unsigned char *) buffer, c_byte)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t\tgoto failed;\n-\t\t}\n+\t\tsbuf[Src].sz = c_byte;\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tabort();\n+\t\tbytes = un.un_reslen;\n \t\tif(next)\n \t\t\t*next = start + offset + c_byte;\n \t\treturn bytes;\n@@ -216,20 +220,19 @@ int read_data_block(long long start, uns\n \tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n \n \tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = data, .sz = c_byte},\n+\t\t\t{.buf = block, .sz = bytes}\n+\t\t};\n+\n \t\tif(read_bytes(start, c_byte, data) == FALSE)\n \t\t\treturn 0;\n \n-\t\tif((res = uncompress((unsigned char *) block, &bytes,\n-\t\t(const unsigned char *) data, c_byte)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t\treturn 0;\n-\t\t}\n-\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tabort();\n+\t\tbytes = un.un_reslen;\n \t\treturn bytes;\n \t} else {\n \t\tif(read_bytes(start, c_byte, block) == FALSE)\n@@ -660,7 +663,7 @@ int create_inode(char *pathname, unsigne\n \t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n \t\t\t\tdev_count ++;\n \t\t\t} else\n-\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n+\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n \t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n \t\t\t\t\tpathname, strerror(errno));\n \t\t\tbreak;\n@@ -818,7 +821,7 @@ int create_inode_2(char *pathname, unsig\n \t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, sBlk.mkfs_time, TRUE);\n \t\t\t\tdev_count ++;\n \t\t\t} else\n-\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n+\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n \t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n \t\t\t\t\tpathname, strerror(errno));\n \t\t\tbreak;\n@@ -1225,18 +1228,26 @@ int read_super(char *source)\n \tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n \n \t/* Check it is a SQUASHFS superblock */\n+\tun.un_lzma = 1;\n \tswap = 0;\n-\tif(sBlk.s_magic != SQUASHFS_MAGIC) {\n-\t\tif(sBlk.s_magic == SQUASHFS_MAGIC_SWAP) {\n-\t\t\tsquashfs_super_block sblk;\n-\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n-\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n-\t\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n-\t\t\tswap = 1;\n-\t\t} else  {\n-\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n-\t\t\tgoto failed_mount;\n-\t\t}\n+\tswitch (sBlk.s_magic) {\n+\t\tsquashfs_super_block sblk;\n+\tcase SQUASHFS_MAGIC:\n+\t\tun.un_lzma = 0;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_LZMA:\n+\t\tbreak;\n+\tcase SQUASHFS_MAGIC_SWAP:\n+\t\tun.un_lzma = 0;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n+\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n+\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n+\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n+\t\tswap = 1;\n+\tdefault:\n+\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n+\t\tgoto failed_mount;\n \t}\n \n \t/* Check the MAJOR & MINOR versions */\n@@ -1305,14 +1316,15 @@ failed_mount:\n \tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n \tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n \tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n-\tprintf(\"GNU General Public License for more details.\\n\");\n+\tprintf(\"GNU General Public License for more details.\\n\"); \\\n+\tprintf(\"and LZMA support for slax.org by jro.\\n\");\n int main(int argc, char *argv[])\n {\n \tchar *dest = \"squashfs-root\";\n \tint i, version = FALSE;\n \tchar *target = \"\";\n \n-\tif(root_process = geteuid() == 0)\n+\tif((root_process = (geteuid() == 0))) //??\n \t\tumask(0);\n \t\n \tfor(i = 1; i < argc; i++) {\n@@ -1371,6 +1383,11 @@ options:\n \t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n \n \tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n+\ti = sqlzma_init(&un, un.un_lzma, 0);\n+\tif (i != Z_OK) {\n+\t\tfputs(\"sqlzma_init failed\", stderr);\n+\t\tabort();\n+\t}\n \n \tread_uids_guids();\n \ts_ops.read_fragment_table();\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/Makefile",
    "content": "\n\nINCLUDEDIR = .\n\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\nifdef UseDebugFlags\nDebugFlags = -g -Wall -Wno-unused-variable -O0 -UNDEBUG\nendif\nCFLAGS += -I${Sqlzma} -D_REENTRANT -DNDEBUG ${DebugFlags}\nLDLIBS += -L${LzmaAlone} -L${LzmaC}\nTgt = mksquashfs unsquashfs\n\nall: ${Tgt}\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h \\\n\t${LzmaAlone}/liblzma_r.a ${LzmaC}/libunlzma_r.a\n\nmksquashfs: LDLIBS += -lpthread -lm -lunlzma_r -llzma_r -lstdc++ -lz\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\nunsquashfs.o: CFLAGS += -U_REENTRANT\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h ${LzmaC}/libunlzma.a\n\nunsquashfs: LDLIBS += -lunlzma -lz\nunsquashfs: unsquashfs.o\n\nclean:\n\t${RM} *~ *.o ${Tgt}\n\n-include test.mk\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\nstruct sqlzma_un un;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* data allocator status struct.  Allocators are used to keep\n  track of memory buffers passed between different threads */\nstruct allocator {\n\tint\t\tmax_buffers;\n\tint\t\tcount;\n\tint\t\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t\twait;\n};\n\n/* struct describing a memory buffer passed between threads */\nstruct file_buffer {\n\tstruct allocator\t*allocator;\n\tvoid\t\t\t(*release)(int);\n\tint\t\t\trelease_data;\n\tlong long\t\tblock;\n\tint\t\t\tsize;\n\tint\t\t\tc_byte;\n\tunsigned int\t\tblock_order;\n\tint\t\t\tfragment;\n\tint\t\t\terror;\n\tstruct file_buffer\t*next;\n\tchar\t\t\tdata[0];\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n/* describes the list of blocks in a file which is a possible\n   duplicate.  For each block, it indicates whether the block is\n   in memory or on disk */\nstruct buffer_list {\n\tlong long start;\n\tint size;\n\tstruct file_buffer *read_buffer;\n};\n\nstruct allocator *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\nextern struct priority_entry *priority_list[65536];\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\n\n\nstruct allocator *alloc_init(int buffer_size, int max_buffers)\n{\n\tstruct allocator *allocator = malloc(sizeof(struct allocator));\n\n\tif(allocator == NULL)\n\t\treturn NULL;\n\n\tallocator->max_buffers = max_buffers;\n\tallocator->buffer_size = buffer_size;\n\tallocator->count = 0;\n\tpthread_mutex_init(&allocator->mutex, NULL);\n\tpthread_cond_init(&allocator->wait, NULL);\n\n\treturn allocator;\n}\n\n\nstruct file_buffer *alloc_get(struct allocator *allocator)\n{\n\tstruct file_buffer *file_buffer;\n\t\n\tpthread_mutex_lock(&allocator->mutex);\n\n\twhile(allocator->count == allocator->max_buffers)\n\t\tpthread_cond_wait(&allocator->wait, &allocator->mutex);\n\n\tif((file_buffer = malloc(sizeof(struct file_buffer) + allocator->buffer_size)) == NULL)\n\t\tgoto failed;\n\n\tfile_buffer->release = NULL;\n\tfile_buffer->allocator = allocator;\n\tallocator->count ++;\n\nfailed:\n\tpthread_mutex_unlock(&allocator->mutex);\n\treturn file_buffer;\n}\n\n\nstruct file_buffer *alloc_get_2(struct allocator *allocator, void (*release)(int), int release_data)\n{\n\tstruct file_buffer *file_buffer = alloc_get(allocator);\n\n\tif(file_buffer) {\n\t\tfile_buffer->release = release;\n\t\tfile_buffer->release_data = release_data;\n\t}\n\treturn file_buffer;\n}\n\n\nvoid alloc_free(struct file_buffer *file_buffer)\n{\n\tstruct allocator *allocator;\n\n\tif(file_buffer == NULL)\n\t\treturn;\n\n\tallocator = file_buffer->allocator;\n\n\tif(file_buffer->release)\n\t\tfile_buffer->release(file_buffer->release_data);\n\n\tpthread_mutex_lock(&allocator->mutex);\n\tfree(file_buffer);\n\tif(allocator->count == 0)\n\t\tERROR(\"alloc_free: freeing buffer for empty allocator!\\n\");\n\telse\n\t\tallocator->count --;\n\tpthread_cond_signal(&allocator->wait);\n\tpthread_mutex_unlock(&allocator->mutex);\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\n\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t}\n\n\tres = sqlzma_cm(un.un_lzma, stream, s, size, d, block_size);\n\tc_byte = stream->total_out;\n\n\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\t//printf(\"%d bytes at %Ld\\n\", bytes, off);\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\treturn FALSE;\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nint write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir) {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir) == FALSE)\n\t\t\treturn FALSE;\n\t} else {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL) == FALSE)\n\t\t\treturn FALSE;\n\t}\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn TRUE;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment, int *cached_fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\n\tif(fragment->index == *cached_fragment || fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn buffer + fragment->offset;\n\n\tif(fragment_data && fragment->index == fragments)\n\t\treturn fragment_data->data + fragment->offset;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragment_table[fragment->index].pending)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = cbuffer, .sz = size},\n\t\t\t{.buf = buffer, .sz = bytes}\n\t\t};\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tBAD_ERROR(\"%s:%d: res %d\\n\", __func__, __LINE__, res);\n\t\tbytes = un.un_reslen;\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\t*cached_fragment = fragment->index;\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid ensure_fragments_flushed()\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragments_outstanding)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].pending = TRUE;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\nvoid frag_release(int block)\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragment_table[block].pending = FALSE;\n\tpthread_cond_signal(&fragment_waiting);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = alloc_get(fragment_buffer);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint avail_bytes, compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tlong long slist[meta_blocks];\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_buffer(struct buffer_list *buffer_list, unsigned int blocks)\n{\n\tunsigned short chksum = 0;\n\tint block;\n\n\tfor(block = 0; block < blocks; block ++) {\n\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\tif(b->read_buffer)\n\t\t\tchksum = get_checksum(b->read_buffer->data, b->read_buffer->size, chksum);\n\t\telse\n\t\t\tchksum = get_checksum(read_from_disk(b->start, b->size), b->size, chksum);\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\nint cached_frag = -1;\nchar fragdata[SQUASHFS_FILE_MAX_SIZE];\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tchar *datap;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\nchar cached_fragment[SQUASHFS_FILE_SIZE];\nint cached_frag1 = -1;\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), file_size);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tchar buffer2[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tchar *buffer;\n\t\t\tint block;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_buffer(buffer_list, blocks);\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), frag_bytes);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\t\t\tif(b->read_buffer)\n\t\t\t\t\tbuffer = b->read_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tbuffer = read_from_disk(b->start, b->size);\n\n\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\n\t\t\t\tif(memcmp(buffer, buffer2, b->size) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_start += b->size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tchar *fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1);\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tint count;\n\tint blocks = (buf->st_size + block_size - 1) >> block_log;\n\tint frag_block = !no_fragments && (always_use_fragments ||\n\t\t(buf->st_size < block_size)) ? buf->st_size >> block_log : -1;\n\tint file;\n\tstatic int block_order = 0;\n\tstruct file_buffer *file_buffer;\n\n\tif(buf->st_size == 0 || dir_ent->inode->read)\n\t\treturn;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tfor(count = 0; count < blocks; count ++) {\n\t\tfile_buffer = alloc_get(reader_buffer);\n\n\t\tif((file_buffer->size = read(file, file_buffer->data, block_size)) == -1) {\n\t\t\tclose(file);\n\t\t\tgoto read_err2;\n\t\t}\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->block_order = block_order ++;\n\t\tfile_buffer->error = FALSE;\n\t\tif((file_buffer->fragment = (count == frag_block))) //??\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\telse\n\t\t\tqueue_put(from_reader, file_buffer);\n\t}\n\n\tclose(file);\n\tdir_ent->inode->read = TRUE;\n\n\treturn;\n\nread_err:\n\tfile_buffer = alloc_get(reader_buffer);\nread_err2:\n\tfile_buffer->block_order = block_order ++;\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\treturn NULL;\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tperror(\"Lseek on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\t//printf(\"%d bytes at %Ld\\n\", file_buffer->size, off);\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n\t\t\tperror(\"Write on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer = alloc_get(writer_buffer);\n\n\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\n\t\twrite_buffer->block = file_buffer->block;\n\t\twrite_buffer->block_order = file_buffer->block_order;\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\n\t\twrite_buffer->fragment = FALSE;\n\t\twrite_buffer->error = FALSE;\n\t\talloc_free(file_buffer);\n\t\tqueue_put(from_deflate, write_buffer);\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer = alloc_get_2(writer_buffer, frag_release, file_buffer->block);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\twrite_buffer->size = compressed_size;\n\t\twrite_buffer->block = bytes;\n\t\tqueue_put(to_writer, write_buffer);\n\t\tbytes += compressed_size;\n\t\ttotal_uncompressed += file_buffer->size;\n\t\ttotal_compressed += compressed_size;\n\t\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\n\t\tfragments_outstanding --;\n\t\tpthread_cond_signal(&fragment_waiting);\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->block_order);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int block_order = 0;\n\tint hash = BLOCK_HASH(block_order);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->block_order == block_order)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->block_order == block_order)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tblock_order ++;\n\n\treturn file_buffer;\n}\n\n\nint progress_bar(long long current, long long max, int columns)\n{\n\tint max_digits = ceil(log10(max));\n\tint used = max_digits * 2 + 10;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(!progress || columns - used < 0)\n\t\treturn 0;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n\treturn 0;\n}\n\n\nint write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n}\n\n\nint write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\n{\n\tint file;\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\talloc_free(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\tstruct file_buffer *file_buffer = get_file_buffer(from_deflate);\n\n\tif(file_buffer->error) {\n\t\talloc_free(file_buffer);\n\t\treturn FALSE;\n\t}\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum))\n\t\treturn write_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\talloc_free(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size)\n{\n\tint block, status;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list;\n\tstruct file_buffer *read_buffer;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\t\tqueue_put(to_writer, read_buffer);\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t} else\n\t\tread_buffer = NULL;\n\n\tfragment = get_and_fill_fragment(read_buffer);\n\talloc_free(read_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, int *duplicate_file)\n{\n\tint block, status, thresh;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer *read_buffer;\n\tstruct file_data *file_data;\n\tstruct buffer_list *buffer_list;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tthresh = blocks > (writer_buffer_size - processors) ? blocks - (writer_buffer_size - processors): 0;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\n\t\tif(block < thresh) {\n\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\tqueue_put(to_writer, read_buffer);\n\t\t} else\n\t\t\tbuffer_list[block].read_buffer = read_buffer;\n\t\tbuffer_list[block].start = read_buffer->block;\n\t\tbuffer_list[block].size = read_buffer->size;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t} else\n\t\tread_buffer = NULL;\n\n\tqueue_put(to_writer, NULL);\n\tif(queue_get(from_writer) != 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\n\t\tfragment = get_and_fill_fragment(read_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\talloc_free(buffer_list[block].read_buffer);\n\t\tbytes = buffer_list[0].start;\n\t\tif(thresh && !block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\n\talloc_free(read_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block && thresh) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\talloc_free(buffer_list[blocks].read_buffer);\n\tfree(buffer_list);\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)\n{\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %lld bytes\\n\", dir_ent->pathname, SQUASHFS_MAX_FILE_SIZE);\n\n\tif(read_size == 0)\n\t\treturn write_file_empty(inode, dir_ent, duplicate_file);\n\n\tif(!no_fragments && (read_size < block_size))\n\t\treturn write_file_frag(inode, dir_ent, read_size, duplicate_file);\n\n\tif(pre_duplicate(read_size))\n\t\treturn write_file_blocks_dup(inode, dir_ent, read_size, duplicate_file);\n\n\t*duplicate_file = FALSE;\n\treturn write_file_blocks(inode, dir_ent, read_size);\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFREG)\n\t\t\testimated_uncompressed += (buf.st_size + block_size - 1) >> block_log;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\n\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type = -1;\n\tint result = FALSE;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\tresult = write_file(inode, dir_ent, buf->st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tresult = dir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n\t\t\t\t}\n\t\t\tif(result)\n\t\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult = TRUE;\n\t\t}\n\t\t\n\n\t\tif(result)\n\t\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\tresult = write_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n\n\treturn result;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 16; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(processors * 2);\n\treader_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, reader_buffer_size);\n\twriter_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, writer_buffer_size);\n\tfragment_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, processors * 2);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\n\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\n}\n\n\t\t\t\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.2-r2 (2007/01/15)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\"); \\\n\tprintf(\"and LZMA support for slax.org by jro.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct winsize winsize;\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tun.un_lzma = 1;\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n\t\t\tun.un_lzma = 0;\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t} else  {\n\t\tsignal(SIGTERM, sighandler2);\n\t\tsignal(SIGINT, sighandler2);\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tinitialise_threads();\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t\t\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + (inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1)); //??\n\t\tuncompressed_data = inode_dir_offset + (inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1)); //??\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tERROR(\"%s:%d: %d\\n\", __func__, __LINE__, i);\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(progress) {\n\t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\t\tcolumns = 80;\n\t\t} else\n\t\t\tcolumns = winsize.ws_col;\n\t\tsignal(SIGWINCH, sigwinch_handler);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n\tif (!un.un_lzma)\n\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tensure_fragments_flushed();\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\tclose(fd);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\nextern struct sqlzma_un un;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = buffer},\n\t\t\t{.buf = block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk->s_magic) {\n\t\tsquashfs_super_block sblk;\n\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\tbreak;\n\tcase SQUASHFS_MAGIC:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\n\tbad:\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3.0 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is %d.%d, I support 3.0\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %xllx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block,\n\t\tlast_start_block = -1;\n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tlong long sindex[indexes];\n\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_inode_t sinode;\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\n\t\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern squashfs_inode write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\tif(write_file(&inode, entry->dir, entry->dir->inode->buf.st_size,\n\t\t\t\t\t\t\t&duplicate_file)) {\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-hg612-lzma/squashfs3.2-r2/squashfs-tools/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n *  Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir\t*(*squashfs_opendir)(unsigned int block_start, unsigned int offset);\n\tchar \t\t*(*read_fragment)(unsigned int fragment);\n\tvoid\t\t(*read_fragment_table)();\n\tint\t\t(*create_inode)(char *pathname, unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE, force = FALSE;\nchar **created_inode;\nint root_process;\nstruct sqlzma_un un;\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\t/* printf(\"%d bytes at %Ld\\n\", bytes, off); */\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = buffer},\n\t\t\t{.buf = block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = data, .sz = c_byte},\n\t\t\t{.buf = block, .sz = bytes}\n\t\t};\n\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, unsigned int mode, unsigned int uid,\nunsigned int guid, unsigned int mtime, unsigned int set_mode)\n{\n\tstruct utimbuf times = { (time_t) mtime, (time_t) mtime };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tuid_t uid_value = (uid_t) uid_table[uid];\n\t\tuid_t guid_value = guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[guid];\n\n\t\tif(chown(pathname, uid_value, guid_value) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nchar *read_fragment_2(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint write_file(char *pathname, unsigned int fragment, unsigned int frag_bytes,\nunsigned int offset, unsigned int blocks, long long start, char *block_ptr,\nunsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write(file_fd, file_data, bytes) < bytes) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = s_ops.read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write(file_fd, fragment_data + offset, frag_bytes) < frag_bytes) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\t\t\n\nint create_inode(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tif(created_inode[header.base.inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[header.base.inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\theader.base.mtime, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[header.base.inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nint create_inode_2(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header_2 header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, sBlk.mkfs_time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\tsBlk.mkfs_time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header_2 header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nint matches(char *targname, char *name)\n{\n\tif(*targname == '\\0' || strcmp(targname, name) == 0)\n\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, char *target)\n{\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tchar targname[1024];\n\n\ttarget = get_component(target, targname);\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(targname, name))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(lsonly || info)\n\t\t\tprintf(\"%s\\n\", pathname);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, target);\n\t\telse\n\t\t\tif(!lsonly)\n\t\t\t\ts_ops.create_inode(pathname, start_block, offset);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nint read_super(char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tun.un_lzma = 1;\n\tswap = 0;\n\tswitch (sBlk.s_magic) {\n\t\tsquashfs_super_block sblk;\n\tcase SQUASHFS_MAGIC:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\t// how on earth did this bug survive for so long?! MGM\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\n\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\ts_ops.read_fragment = read_fragment_2;\n\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\ts_ops.create_inode = create_inode_2;\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor == 0) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.create_inode = create_inode;\n\t} else {\n\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d)\\n\",\n\t\t\t\tsource, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"I support Squashfs 2.x and 3.0 filesystems!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\n\tTRACE(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not\" : \"\");\n\tTRACE(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tTRACE(\"\\tBlock size %d\\n\", sBlk.block_size);\n\tTRACE(\"\\tNumber of fragments %d\\n\", sBlk.fragments);\n\tTRACE(\"\\tNumber of inodes %d\\n\", sBlk.inodes);\n\tTRACE(\"\\tNumber of uids %d\\n\", sBlk.no_uids);\n\tTRACE(\"\\tNumber of gids %d\\n\", sBlk.no_guids);\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.3 (2007/01/02)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\"); \\\n\tprintf(\"and LZMA support for slax.org by jro.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, version = FALSE;\n\tchar *target = \"\";\n\n\tif((root_process = (geteuid() == 0))) //??\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc)\n\t\t\t\tgoto options;\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directory or file to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem only\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tif((i + 1) < argc)\n\t\ttarget = argv[i + 1];\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tblock_size = sBlk.block_size;\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tfputs(\"sqlzma_init failed\", stderr);\n\t\tabort();\n\t}\n\n\tread_uids_guids();\n\ts_ops.read_fragment_table();\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), target);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/7zCrc.c",
    "content": "/* 7zCrc.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++) \r\n    v = CRC_UPDATE_BYTE(v, *p);\r\n  return v;\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/7zCrc.h",
    "content": "/* 7zCrc.h */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"Types.h\"\r\n\r\nextern UInt32 g_CrcTable[];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void);\r\n\r\n#define CRC_INIT_VAL 0xFFFFFFFF\r\n#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)\r\n#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/7zCrcT8.c",
    "content": "/* 7zCrcT8.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\n#define CRC_NUM_TABLES 8\r\n\r\nUInt32 g_CrcTable[256 * CRC_NUM_TABLES];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable()\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n  #if CRC_NUM_TABLES > 1\r\n  for (; i < 256 * CRC_NUM_TABLES; i++)\r\n  {\r\n    UInt32 r = g_CrcTable[i - 256];\r\n    g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);\r\n  }\r\n  #endif\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  return CrcUpdateT8(v, data, size, g_CrcTable);\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdateT8(CRC_INIT_VAL, data, size, g_CrcTable) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Alloc.c",
    "content": "/* Alloc.c */\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdlib.h>\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount++);\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid MyFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d\", --g_allocCount);\r\n  #endif\r\n  free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#ifndef MEM_LARGE_PAGES\r\n#undef _7ZIP_LARGE_PAGES\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nSIZE_T g_LargePageSize = 0;\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n#endif\r\n\r\nvoid SetLargePageSize()\r\n{\r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  SIZE_T size = 0;\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        GetProcAddress(GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return;\r\n  size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return;\r\n  g_LargePageSize = size;\r\n  #endif\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))\r\n  {\r\n    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), \r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Alloc.h",
    "content": "/* Alloc.h */\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size);\r\nvoid MyFree(void *address);\r\n\r\n#ifdef _WIN32\r\n\r\nvoid SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size);\r\nvoid MidFree(void *address);\r\nvoid *BigAlloc(size_t size);\r\nvoid BigFree(void *address);\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zAlloc.c",
    "content": "/* 7zAlloc.c */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n#endif\r\n\r\nvoid *SzAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zAlloc.h",
    "content": "/* 7zAlloc.h */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\nvoid *SzAlloc(size_t size);\r\nvoid SzFree(void *address);\r\n\r\nvoid *SzAllocTemp(size_t size);\r\nvoid SzFreeTemp(void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zBuffer.c",
    "content": "/* 7zBuffer.c */\r\n\r\n#include \"7zBuffer.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer)\r\n{\r\n  buffer->Capacity = 0;\r\n  buffer->Items = 0;\r\n}\r\n\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))\r\n{\r\n  buffer->Capacity = newCapacity;\r\n  if (newCapacity == 0)\r\n  {\r\n    buffer->Items = 0;\r\n    return 1;\r\n  }\r\n  buffer->Items = (Byte *)allocFunc(newCapacity);\r\n  return (buffer->Items != 0);\r\n}\r\n\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(buffer->Items);\r\n  buffer->Items = 0;\r\n  buffer->Capacity = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zBuffer.h",
    "content": "/* 7zBuffer.h */\r\n\r\n#ifndef __7Z_BUFFER_H\r\n#define __7Z_BUFFER_H\r\n\r\n#include <stddef.h>\r\n#include \"../../Types.h\"\r\n\r\ntypedef struct _CSzByteBuffer\r\n{\r\n  size_t Capacity;\r\n  Byte *Items;\r\n}CSzByteBuffer;\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer);\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zDecode.c",
    "content": "/* 7zDecode.c */\r\n\r\n#include <memory.h>\r\n\r\n#include \"7zDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#else\r\n#include \"../../Compress/Lzma/LzmaDecode.h\"\r\n#include \"../../Compress/Branch/BranchX86.h\"\r\n#include \"../../Compress/Branch/BranchX86_2.h\"\r\n#endif\r\n\r\n#define k_Copy 0\r\n#define k_LZMA 0x30101\r\n#define k_BCJ 0x03030103\r\n#define k_BCJ2 0x0303011B\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\ntypedef struct _CLzmaInCallbackImp\r\n{\r\n  ILzmaInCallback InCallback;\r\n  ISzInStream *InStream;\r\n  CFileSize Size;\r\n} CLzmaInCallbackImp;\r\n\r\nint LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object;\r\n  size_t processedSize;\r\n  SZ_RESULT res;\r\n  size_t curSize = (1 << 20);\r\n  if (curSize > cb->Size)\r\n    curSize = (size_t)cb->Size;\r\n  *size = 0;\r\n  res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, curSize, &processedSize);\r\n  *size = (SizeT)processedSize;\r\n  if (processedSize > curSize)\r\n    return (int)SZE_FAIL;\r\n  cb->Size -= processedSize;\r\n  if (res == SZ_OK)\r\n    return 0;\r\n  return (int)res;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzDecodeLzma(CCoderInfo *coder, CFileSize inSize,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  CLzmaInCallbackImp lzmaCallback;\r\n  #else\r\n  SizeT inProcessed;\r\n  #endif\r\n  \r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  lzmaCallback.Size = inSize;\r\n  lzmaCallback.InStream = inStream;\r\n  lzmaCallback.InCallback.Read = LzmaReadImp;\r\n  #endif\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, \r\n      (unsigned)coder->Properties.Capacity) != LZMA_RESULT_OK)\r\n    return SZE_FAIL;\r\n  \r\n  state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      allocMain->Free(state.Probs);\r\n      return SZE_OUTOFMEMORY;\r\n    }\r\n  }\r\n  LzmaDecoderInit(&state);\r\n  #endif\r\n  \r\n  result = LzmaDecode(&state,\r\n  #ifdef _LZMA_IN_CB\r\n    &lzmaCallback.InCallback,\r\n  #else\r\n    inBuffer, (SizeT)inSize, &inProcessed,\r\n  #endif\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  allocMain->Free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  allocMain->Free(state.Dictionary);\r\n  #endif\r\n  if (result == LZMA_RESULT_DATA_ERROR)\r\n    return SZE_DATA_ERROR;\r\n  if (result != LZMA_RESULT_OK)\r\n    return SZE_FAIL;\r\n  return (outSizeProcessedLoc == outSize) ? SZ_OK : SZE_DATA_ERROR;\r\n}\r\n\r\n#ifdef _LZMA_IN_CB\r\nSZ_RESULT SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer)\r\n{\r\n  while (inSize > 0)\r\n  {\r\n    void *inBuffer;\r\n    size_t processedSize, curSize = (1 << 18);\r\n    if (curSize > inSize)\r\n      curSize = (size_t)(inSize);\r\n    RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, curSize, &processedSize));\r\n    if (processedSize == 0)\r\n      return SZE_DATA_ERROR;\r\n    if (processedSize > curSize)\r\n      return SZE_FAIL;\r\n    memcpy(outBuffer, inBuffer, processedSize);\r\n    outBuffer += processedSize;\r\n    inSize -= processedSize;\r\n  }\r\n  return SZ_OK;\r\n}\r\n#endif\r\n\r\n#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)\r\n#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)\r\n\r\nSZ_RESULT CheckSupportedFolder(const CFolder *f)\r\n{\r\n  if (f->NumCoders < 1 || f->NumCoders > 4)\r\n    return SZE_NOTIMPL;\r\n  if (IS_UNSUPPORTED_CODER(f->Coders[0]))\r\n    return SZE_NOTIMPL;\r\n  if (f->NumCoders == 1)\r\n  {\r\n    if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)\r\n      return SZE_NOTIMPL;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 2)\r\n  {\r\n    if (IS_NO_BCJ(f->Coders[1]) ||\r\n        f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||\r\n        f->NumBindPairs != 1 ||\r\n        f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)\r\n      return SZE_NOTIMPL;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 4)\r\n  {\r\n    if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||\r\n        IS_UNSUPPORTED_CODER(f->Coders[2]) ||\r\n        IS_NO_BCJ2(f->Coders[3]))\r\n      return SZE_NOTIMPL;\r\n    if (f->NumPackStreams != 4 || \r\n        f->PackStreams[0] != 2 ||\r\n        f->PackStreams[1] != 6 ||\r\n        f->PackStreams[2] != 1 ||\r\n        f->PackStreams[3] != 0 ||\r\n        f->NumBindPairs != 3 ||\r\n        f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||\r\n        f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||\r\n        f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)\r\n      return SZE_NOTIMPL;\r\n    return SZ_OK;\r\n  }\r\n  return SZE_NOTIMPL;\r\n}\r\n\r\nCFileSize GetSum(const CFileSize *values, UInt32 index)\r\n{\r\n  CFileSize sum = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < index; i++)\r\n    sum += values[i];\r\n  return sum;\r\n}\r\n\r\nSZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream, CFileSize startPos,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain,\r\n    Byte *tempBuf[])\r\n{\r\n  UInt32 ci;\r\n  size_t tempSizes[3] = { 0, 0, 0};\r\n  size_t tempSize3 = 0;\r\n  Byte *tempBuf3 = 0;\r\n\r\n  RINOK(CheckSupportedFolder(folder));\r\n\r\n  for (ci = 0; ci < folder->NumCoders; ci++)\r\n  {\r\n    CCoderInfo *coder = &folder->Coders[ci];\r\n\r\n    if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)\r\n    {\r\n      UInt32 si = 0;\r\n      CFileSize offset;\r\n      CFileSize inSize;\r\n      Byte *outBufCur = outBuffer;\r\n      size_t outSizeCur = outSize;\r\n      if (folder->NumCoders == 4)\r\n      {\r\n        UInt32 indices[] = { 3, 2, 0 };\r\n        CFileSize unpackSize = folder->UnPackSizes[ci];\r\n        si = indices[ci];\r\n        if (ci < 2)\r\n        {\r\n          Byte *temp;\r\n          outSizeCur = (size_t)unpackSize;\r\n          if (outSizeCur != unpackSize)\r\n            return SZE_OUTOFMEMORY;\r\n          temp = (Byte *)allocMain->Alloc(outSizeCur);\r\n          if (temp == 0 && outSizeCur != 0)\r\n            return SZE_OUTOFMEMORY;\r\n          outBufCur = tempBuf[1 - ci] = temp;\r\n          tempSizes[1 - ci] = outSizeCur;\r\n        }\r\n        else if (ci == 2)\r\n        {\r\n          if (unpackSize > outSize)\r\n            return SZE_OUTOFMEMORY;\r\n          tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);\r\n          tempSize3 = outSizeCur = (size_t)unpackSize;\r\n        }\r\n        else\r\n          return SZE_NOTIMPL;\r\n      }\r\n      offset = GetSum(packSizes, si);\r\n      inSize = packSizes[si];\r\n      #ifdef _LZMA_IN_CB\r\n      RINOK(inStream->Seek(inStream, startPos + offset));\r\n      #endif\r\n\r\n      if (coder->MethodID == k_Copy)\r\n      {\r\n        if (inSize != outSizeCur)\r\n          return SZE_DATA_ERROR;\r\n        \r\n        #ifdef _LZMA_IN_CB\r\n        RINOK(SzDecodeCopy(inSize, inStream, outBufCur));\r\n        #else\r\n        memcpy(outBufCur, inBuffer + (size_t)offset, (size_t)inSize);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        SZ_RESULT res = SzDecodeLzma(coder, inSize,\r\n            #ifdef _LZMA_IN_CB\r\n            inStream,\r\n            #else\r\n            inBuffer + (size_t)offset,\r\n            #endif\r\n            outBufCur, outSizeCur, allocMain);\r\n        RINOK(res)\r\n      }\r\n    }\r\n    else if (coder->MethodID == k_BCJ)\r\n    {\r\n      UInt32 state;\r\n      if (ci != 1)\r\n        return SZE_NOTIMPL;\r\n      x86_Convert_Init(state);\r\n      x86_Convert(outBuffer, outSize, 0, &state, 0);\r\n    }\r\n    else if (coder->MethodID == k_BCJ2)\r\n    {\r\n      CFileSize offset = GetSum(packSizes, 1);\r\n      CFileSize s3Size = packSizes[1];\r\n      SZ_RESULT res;\r\n      if (ci != 3)\r\n        return SZE_NOTIMPL;\r\n\r\n      #ifdef _LZMA_IN_CB\r\n      RINOK(inStream->Seek(inStream, startPos + offset));\r\n      tempSizes[2] = (size_t)s3Size;\r\n      if (tempSizes[2] != s3Size)\r\n        return SZE_OUTOFMEMORY;\r\n      tempBuf[2] = (Byte *)allocMain->Alloc(tempSizes[2]);\r\n      if (tempBuf[2] == 0 && tempSizes[2] != 0)\r\n        return SZE_OUTOFMEMORY;\r\n      res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);\r\n      RINOK(res)\r\n      #endif\r\n\r\n      res = x86_2_Decode(\r\n          tempBuf3, tempSize3, \r\n          tempBuf[0], tempSizes[0], \r\n          tempBuf[1], tempSizes[1], \r\n          #ifdef _LZMA_IN_CB\r\n          tempBuf[2], tempSizes[2], \r\n          #else\r\n          inBuffer + (size_t)offset, (size_t)s3Size, \r\n          #endif\r\n          outBuffer, outSize);\r\n      RINOK(res)\r\n    }\r\n    else \r\n      return SZE_NOTIMPL;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream, CFileSize startPos,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  Byte *tempBuf[3] = { 0, 0, 0};\r\n  int i;\r\n  SZ_RESULT res = SzDecode2(packSizes, folder,\r\n      #ifdef _LZMA_IN_CB\r\n      inStream, startPos,\r\n      #else\r\n      inBuffer,\r\n      #endif\r\n      outBuffer, outSize, allocMain, tempBuf);\r\n  for (i = 0; i < 3; i++)\r\n    allocMain->Free(tempBuf[i]);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zDecode.h",
    "content": "/* 7zDecode.h */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n#ifdef _LZMA_IN_CB\r\n#include \"7zIn.h\"\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *stream, CFileSize startPos,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zExtract.c",
    "content": "/* 7zExtract.c */\r\n\r\n#include \"7zExtract.h\"\r\n#include \"7zDecode.h\"\r\n#include \"../../7zCrc.h\"\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer, \r\n    size_t *outBufferSize,\r\n    size_t *offset, \r\n    size_t *outSizeProcessed, \r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];\r\n  SZ_RESULT res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    allocMain->Free(*outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CFolder *folder = db->Database.Folders + folderIndex;\r\n    CFileSize unPackSizeSpec = SzFolderGetUnPackSize(folder);\r\n    size_t unPackSize = (size_t)unPackSizeSpec;\r\n    CFileSize startOffset = SzArDbGetFolderStreamPos(db, folderIndex, 0);\r\n    #ifndef _LZMA_IN_CB\r\n    Byte *inBuffer = 0;\r\n    size_t processedSize;\r\n    CFileSize packSizeSpec;\r\n    size_t packSize;\r\n    RINOK(SzArDbGetFolderFullPackSize(db, folderIndex, &packSizeSpec));\r\n    packSize = (size_t)packSizeSpec;\r\n    if (packSize != packSizeSpec)\r\n      return SZE_OUTOFMEMORY;\r\n    #endif\r\n    if (unPackSize != unPackSizeSpec)\r\n      return SZE_OUTOFMEMORY;\r\n    *blockIndex = folderIndex;\r\n    allocMain->Free(*outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(inStream->Seek(inStream, startOffset));\r\n    \r\n    #ifndef _LZMA_IN_CB\r\n    if (packSize != 0)\r\n    {\r\n      inBuffer = (Byte *)allocTemp->Alloc(packSize);\r\n      if (inBuffer == 0)\r\n        return SZE_OUTOFMEMORY;\r\n    }\r\n    res = inStream->Read(inStream, inBuffer, packSize, &processedSize);\r\n    if (res == SZ_OK && processedSize != packSize)\r\n      res = SZE_FAIL;\r\n    #endif\r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = unPackSize;\r\n      if (unPackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)allocMain->Alloc(unPackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZE_OUTOFMEMORY;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        res = SzDecode(db->Database.PackSizes + \r\n          db->FolderStartPackStreamIndex[folderIndex], folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream, startOffset, \r\n          #else\r\n          inBuffer, \r\n          #endif\r\n          *outBuffer, unPackSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (folder->UnPackCRCDefined)\r\n          {\r\n            if (CrcCalc(*outBuffer, unPackSize) != folder->UnPackCRC)\r\n              res = SZE_CRC_ERROR;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    #ifndef _LZMA_IN_CB\r\n    allocTemp->Free(inBuffer);\r\n    #endif\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i; \r\n    CFileItem *fileItem = db->Database.Files + fileIndex;\r\n    *offset = 0;\r\n    for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)db->Database.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZE_FAIL;\r\n    {\r\n      if (fileItem->IsFileCRCDefined)\r\n      {\r\n        if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)\r\n          res = SZE_CRC_ERROR;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zExtract.h",
    "content": "/* 7zExtract.h */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive. \r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send \r\n    these values from previous call:\r\n      *blockIndex, \r\n      *outBuffer, \r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid, \r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables \r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zHeader.c",
    "content": "/*  7zHeader.c */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zHeader.h",
    "content": "/* 7zHeader.h */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnPackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnPackSize,\r\n  k7zIdNumUnPackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCreationTime,\r\n  k7zIdLastAccessTime,\r\n  k7zIdLastWriteTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zIn.c",
    "content": "/* 7zIn.c */\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zDecode.h\"\r\n#include \"../../7zCrc.h\"\r\n\r\n#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db)\r\n{\r\n  SzArchiveDatabaseInit(&db->Database);\r\n  db->FolderStartPackStreamIndex = 0;\r\n  db->PackStreamStartPositions = 0;\r\n  db->FolderStartFileIndex = 0;\r\n  db->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(db->FolderStartPackStreamIndex);\r\n  freeFunc(db->PackStreamStartPositions);\r\n  freeFunc(db->FolderStartFileIndex);\r\n  freeFunc(db->FileIndexToFolderIndexMap);\r\n  SzArchiveDatabaseFree(&db->Database, freeFunc);\r\n  SzArDbExInit(db);\r\n}\r\n\r\n/*\r\nCFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nCFileSize GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n#define MY_ALLOC(T, p, size, allocFunc) { if ((size) == 0) p = 0; else \\\r\n  if ((p = (T *)allocFunc((size) * sizeof(T))) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nSZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 startPos = 0;\r\n  CFileSize startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  MY_ALLOC(UInt32, db->FolderStartPackStreamIndex, db->Database.NumFolders, allocFunc);\r\n  for(i = 0; i < db->Database.NumFolders; i++)\r\n  {\r\n    db->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += db->Database.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  MY_ALLOC(CFileSize, db->PackStreamStartPositions, db->Database.NumPackStreams, allocFunc);\r\n\r\n  for(i = 0; i < db->Database.NumPackStreams; i++)\r\n  {\r\n    db->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += db->Database.PackSizes[i];\r\n  }\r\n\r\n  MY_ALLOC(UInt32, db->FolderStartFileIndex, db->Database.NumFolders, allocFunc);\r\n  MY_ALLOC(UInt32, db->FileIndexToFolderIndexMap, db->Database.NumFiles, allocFunc);\r\n\r\n  for (i = 0; i < db->Database.NumFiles; i++)\r\n  {\r\n    CFileItem *file = db->Database.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      db->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= db->Database.NumFolders)\r\n          return SZE_ARCHIVE_ERROR;\r\n        db->FolderStartFileIndex[folderIndex] = i;\r\n        if (db->Database.Folders[folderIndex].NumUnPackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    db->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return db->ArchiveInfo.DataStartPosition + \r\n    db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nint SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize)\r\n{\r\n  UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n  CFolder *folder = db->Database.Folders + folderIndex;\r\n  CFileSize size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n  {\r\n    CFileSize t = size + db->Database.PackSizes[packStreamIndex + i];\r\n    if (t < size)\r\n      return SZE_FAIL;\r\n    size = t;\r\n  }\r\n  *resSize = size;\r\n  return SZ_OK;\r\n}\r\n\r\n\r\n/*\r\nSZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case k7zIdLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case k7zIdLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nSZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  while (size > 0)\r\n  {\r\n    void *inBufferSpec;\r\n    size_t processedSize;\r\n    const Byte *inBuffer;\r\n    RINOK(inStream->Read(inStream, (void **)&inBufferSpec, size, &processedSize));\r\n    inBuffer = (const Byte *)inBufferSpec;\r\n    if (processedSize == 0 || processedSize > size)\r\n      return SZE_FAIL;\r\n    size -= processedSize;\r\n    do\r\n    {\r\n      *data++ = *inBuffer++;\r\n    }\r\n    while (--processedSize != 0);\r\n  }\r\n  #else\r\n  size_t processedSize;\r\n  RINOK(inStream->Read(inStream, data, size, &processedSize));\r\n  if (processedSize != size)\r\n    return SZE_FAIL;\r\n  #endif\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data)\r\n{\r\n  return SafeReadDirect(inStream, data, 1);\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n    *crc = CRC_UPDATE_BYTE(*crc, b);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    *crc = CRC_UPDATE_BYTE(*crc, b);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nint TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nSZ_RESULT SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  *value = (CFileSize)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZE_NOTIMPL;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZE_NOTIMPL;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadID(CSzData *sd, UInt64 *value) \r\n{ \r\n  return SzReadNumber(sd, value); \r\n}\r\n\r\nSZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nSZ_RESULT SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZE_ARCHIVE_ERROR;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  MY_ALLOC(Byte, *v, numItems, allocFunc);\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, allocFunc);\r\n  MY_ALLOC(Byte, *v, numItems, allocFunc);\r\n  for(i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHashDigests(\r\n    CSzData *sd, \r\n    size_t numItems,\r\n    Byte **digestsDefined, \r\n    UInt32 **digests, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc));\r\n  MY_ALLOC(UInt32, *digests, numItems, allocFunc);\r\n  for(i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadPackInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    CFileSize **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadSize(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, allocFunc);\r\n\r\n  for(i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadSize(sd, (*packSizes) + i));\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc)); \r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, allocFunc);\r\n    MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, allocFunc);\r\n    for(i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR;\r\n}\r\n\r\nSZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 numCoders;\r\n  UInt32 numBindPairs;\r\n  UInt32 numPackedStreams;\r\n  UInt32 i;\r\n  UInt32 numInStreams = 0;\r\n  UInt32 numOutStreams = 0;\r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  folder->NumCoders = numCoders;\r\n\r\n  MY_ALLOC(CCoderInfo, folder->Coders, (size_t)numCoders, allocFunc);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfoInit(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      unsigned idSize, j;\r\n      Byte longID[15];\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      idSize = (unsigned)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, longID, idSize));\r\n      if (idSize > sizeof(coder->MethodID))\r\n        return SZE_NOTIMPL;\r\n      coder->MethodID = 0;\r\n      for (j = 0; j < idSize; j++)\r\n        coder->MethodID |= (CMethodID)longID[idSize - 1 - j] << (8 * j);\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc))\r\n          return SZE_OUTOFMEMORY;\r\n        RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += (UInt32)coder->NumInStreams;\r\n    numOutStreams += (UInt32)coder->NumOutStreams;\r\n  }\r\n\r\n  numBindPairs = numOutStreams - 1;\r\n  folder->NumBindPairs = numBindPairs;\r\n\r\n\r\n  MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, allocFunc);\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bindPair = folder->BindPairs + i;;\r\n    RINOK(SzReadNumber32(sd, &bindPair->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bindPair->OutIndex)); \r\n  }\r\n\r\n  numPackedStreams = numInStreams - (UInt32)numBindPairs;\r\n\r\n  folder->NumPackStreams = numPackedStreams;\r\n  MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, allocFunc);\r\n\r\n  if (numPackedStreams == 1)\r\n  {\r\n    UInt32 j;\r\n    UInt32 pi = 0;\r\n    for (j = 0; j < numInStreams; j++)\r\n      if (SzFolderFindBindPairForInStream(folder, j) < 0)\r\n      {\r\n        folder->PackStreams[pi++] = j;\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUnPackInfo(\r\n    CSzData *sd, \r\n    UInt32 *numFolders,\r\n    CFolder **folders,  /* for allocFunc */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n    MY_ALLOC(CFolder, *folders, (size_t)*numFolders, allocFunc);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n      SzFolderInit((*folders) + i);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));\r\n\r\n  for(i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolderGetNumOutStreams(folder);\r\n\r\n    MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, allocFunc);\r\n\r\n    for(j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadSize(sd, folder->UnPackSizes + j));\r\n    }\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SZ_RESULT res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc); \r\n      if (res == SZ_OK)\r\n      {\r\n        for(i = 0; i < *numFolders; i++)\r\n        {\r\n          CFolder *folder = (*folders) + i;\r\n          folder->UnPackCRCDefined = crcsDefined[i];\r\n          folder->UnPackCRC = crcs[i];\r\n        }\r\n      }\r\n      allocTemp->Free(crcs);\r\n      allocTemp->Free(crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadSubStreamsInfo(\r\n    CSzData *sd, \r\n    UInt32 numFolders,\r\n    CFolder *folders,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n    folders[i].NumUnPackStreams = 1;\r\n  *numUnPackStreams = numFolders;\r\n\r\n  for (;;)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnPackStream)\r\n    {\r\n      *numUnPackStreams = 0;\r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnPackStreams = numStreams;\r\n        *numUnPackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnPackStreams == 0)\r\n  {\r\n    *unPackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize));\r\n    RINOM(*unPackSizes);\r\n    *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    CFileSize sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      CFileSize size;\r\n      RINOK(SzReadSize(sd, &size));\r\n      (*unPackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for(i = 0; i < *numUnPackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  for (;;)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0; \r\n      UInt32 *digests2 = 0;\r\n      SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnPackStreams;\r\n          if (numSubstreams == 1 && folder->UnPackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnPackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      allocTemp->Free(digestsDefined2);\r\n      allocTemp->Free(digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nSZ_RESULT SzReadStreamsInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    CArchiveDatabase *db,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZE_FAIL;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams, \r\n            &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc));\r\n        break;\r\n      }\r\n      case k7zIdUnPackInfo:\r\n      {\r\n        RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders, \r\n            numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZE_FAIL;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nSZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CFileItem *file = files + i;\r\n    while(pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZE_ARCHIVE_ERROR;\r\n        if (pos + 2 > sd->Size)\r\n          return SZE_ARCHIVE_ERROR;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZE_ARCHIVE_ERROR;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    MY_ALLOC(char, file->Name, (size_t)len, allocFunc);\r\n\r\n    len = 0;\r\n    while(2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while(numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHeader2(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db,   /* allocMain */\r\n    CFileSize **unPackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    Byte **lwtVector,         /* allocTemp */\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnPackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &db->ArchiveInfo.DataStartPosition,\r\n        &db->Database, \r\n        &numUnPackStreams,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests, allocMain->Alloc, allocTemp));\r\n    db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZE_ARCHIVE_ERROR;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  db->Database.NumFiles = numFiles;\r\n\r\n  MY_ALLOC(CFileItem, files, (size_t)numFiles, allocMain->Alloc);\r\n\r\n  db->Database.Files = files;\r\n  for(i = 0; i < numFiles; i++)\r\n    SzFileInit(files + i);\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc));\r\n        break;\r\n      }\r\n      case k7zIdLastWriteTime:\r\n      {\r\n        RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp->Alloc));\r\n        RINOK(SzReadSwitch(sd));\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem *f = &files[i];\r\n          Byte defined = (*lwtVector)[i];\r\n          f->IsLastWriteTimeDefined = defined;\r\n          f->LastWriteTime.Low = f->LastWriteTime.High = 0;\r\n          if (defined)\r\n          {\r\n            RINOK(SzReadUInt32(sd, &f->LastWriteTime.Low));\r\n            RINOK(SzReadUInt32(sd, &f->LastWriteTime.High));\r\n          }\r\n        }\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for(i = 0; i < numFiles; i++)\r\n    {\r\n      CFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if(file->HasStream)\r\n      {\r\n        file->IsDirectory = 0;\r\n        file->Size = (*unPackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->IsFileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDirectory = 1;\r\n        else\r\n          file->IsDirectory = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->IsFileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArDbExFill(db, allocMain->Alloc);\r\n}\r\n\r\nSZ_RESULT SzReadHeader(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db, \r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  Byte *lwtVector = 0;\r\n  SZ_RESULT res = SzReadHeader2(sd, db, \r\n      &unPackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector, &lwtVector, \r\n      allocMain, allocTemp);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  allocTemp->Free(emptyStreamVector);\r\n  allocTemp->Free(emptyFileVector);\r\n  allocTemp->Free(lwtVector);\r\n  return res;\r\n} \r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams2(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    CArchiveDatabase *db,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    #ifndef _LZMA_IN_CB\r\n    Byte **inBuffer,\r\n    #endif\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnPackStreams = 0;\r\n  CFileSize dataStartPos;\r\n  CFolder *folder;\r\n  #ifndef _LZMA_IN_CB\r\n  CFileSize packSize = 0;\r\n  UInt32 i = 0;\r\n  #endif\r\n  CFileSize unPackSize;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, db,\r\n      &numUnPackStreams,  unPackSizes, digestsDefined, digests, \r\n      allocTemp->Alloc, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (db->NumFolders != 1)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  folder = db->Folders;\r\n  unPackSize = SzFolderGetUnPackSize(folder);\r\n  \r\n  RINOK(inStream->Seek(inStream, dataStartPos));\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  for (i = 0; i < db->NumPackStreams; i++)\r\n    packSize += db->PackSizes[i];\r\n\r\n  MY_ALLOC(Byte, *inBuffer, (size_t)packSize, allocTemp->Alloc);\r\n\r\n  RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize));\r\n  #endif\r\n\r\n  if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  res = SzDecode(db->PackSizes, folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream, dataStartPos, \r\n          #else\r\n          *inBuffer, \r\n          #endif\r\n          outBuffer->Items, (size_t)unPackSize, allocTemp);\r\n  RINOK(res)\r\n  if (folder->UnPackCRCDefined)\r\n    if (CrcCalc(outBuffer->Items, (size_t)unPackSize) != folder->UnPackCRC)\r\n      return SZE_FAIL;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CArchiveDatabase db;\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  #ifndef _LZMA_IN_CB\r\n  Byte *inBuffer = 0;\r\n  #endif\r\n  SZ_RESULT res;\r\n  SzArchiveDatabaseInit(&db);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset, \r\n    &db, &unPackSizes, &digestsDefined, &digests, \r\n    #ifndef _LZMA_IN_CB\r\n    &inBuffer,\r\n    #endif\r\n    allocTemp);\r\n  SzArchiveDatabaseFree(&db, allocTemp->Free);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  #ifndef _LZMA_IN_CB\r\n  allocTemp->Free(inBuffer);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen2(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte signature[k7zSignatureSize];\r\n  Byte version;\r\n  UInt32 crcFromArchive;\r\n  UInt64 nextHeaderOffset;\r\n  UInt64 nextHeaderSize;\r\n  UInt32 nextHeaderCRC;\r\n  UInt32 crc = 0;\r\n  CFileSize pos = 0;\r\n  CSzByteBuffer buffer;\r\n  CSzData sd;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize));\r\n\r\n  if (!TestSignatureCandidate(signature))\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  /*\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n  */\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n  if (version != k7zMajorVersion)\r\n    return SZE_ARCHIVE_ERROR;\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n\r\n  RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive, &crc));\r\n\r\n  crc = CRC_INIT_VAL;\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset, &crc));\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize, &crc));\r\n  RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC, &crc));\r\n\r\n  pos = k7zStartHeaderSize;\r\n  db->ArchiveInfo.StartPositionAfterHeader = pos;\r\n  \r\n  if (CRC_GET_DIGEST(crc) != crcFromArchive)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  if (nextHeaderSize == 0)\r\n    return SZ_OK;\r\n\r\n  RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset)));\r\n\r\n  if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = SZE_ARCHIVE_ERROR;\r\n    if (CrcCalc(buffer.Items, (UInt32)nextHeaderSize) == nextHeaderCRC)\r\n    {\r\n      for (;;)\r\n      {\r\n        UInt64 type;\r\n        sd.Data = buffer.Items;\r\n        sd.Size = buffer.Capacity;\r\n        res = SzReadID(&sd, &type);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (type == k7zIdHeader)\r\n        {\r\n          res = SzReadHeader(&sd, db, allocMain, allocTemp);\r\n          break;\r\n        }\r\n        if (type != k7zIdEncodedHeader)\r\n        {\r\n          res = SZE_ARCHIVE_ERROR;\r\n          break;\r\n        }\r\n        {\r\n          CSzByteBuffer outBuffer;\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, \r\n              db->ArchiveInfo.StartPositionAfterHeader, \r\n              allocTemp);\r\n          if (res != SZ_OK)\r\n          {\r\n            SzByteBufferFree(&outBuffer, allocTemp->Free);\r\n            break;\r\n          }\r\n          SzByteBufferFree(&buffer, allocTemp->Free);\r\n          buffer.Items = outBuffer.Items;\r\n          buffer.Capacity = outBuffer.Capacity;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  SzByteBufferFree(&buffer, allocTemp->Free);\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArDbExFree(db, allocMain->Free);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zIn.h",
    "content": "/* 7zIn.h */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n \r\ntypedef struct _CInArchiveInfo\r\n{\r\n  CFileSize StartPositionAfterHeader; \r\n  CFileSize DataStartPosition;\r\n}CInArchiveInfo;\r\n\r\ntypedef struct _CArchiveDatabaseEx\r\n{\r\n  CArchiveDatabase Database;\r\n  CInArchiveInfo ArchiveInfo;\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  CFileSize *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n}CArchiveDatabaseEx;\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db);\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);\r\nint SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize);\r\n\r\ntypedef struct _ISzInStream\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  SZ_RESULT (*Read)(\r\n      void *object,           /* pointer to ISzInStream itself */\r\n      void **buffer,          /* out: pointer to buffer with data */\r\n      size_t maxRequiredSize, /* max required size to read */\r\n      size_t *processedSize); /* real processed size. \r\n                                 processedSize can be less than maxRequiredSize.\r\n                                 If processedSize == 0, then there are no more \r\n                                 bytes in stream. */\r\n  #else\r\n  SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);\r\n  #endif\r\n  SZ_RESULT (*Seek)(void *object, CFileSize pos);\r\n} ISzInStream;\r\n\r\n \r\nint SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zItem.c",
    "content": "/* 7zItem.c */\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder)\r\n{\r\n  SzByteBufferInit(&coder->Properties);\r\n}\r\n\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))\r\n{\r\n  SzByteBufferFree(&coder->Properties, freeFunc);\r\n  SzCoderInfoInit(coder);\r\n}\r\n\r\nvoid SzFolderInit(CFolder *folder)\r\n{\r\n  folder->NumCoders = 0;\r\n  folder->Coders = 0;\r\n  folder->NumBindPairs = 0;\r\n  folder->BindPairs = 0;\r\n  folder->NumPackStreams = 0;\r\n  folder->PackStreams = 0;\r\n  folder->UnPackSizes = 0;\r\n  folder->UnPackCRCDefined = 0;\r\n  folder->UnPackCRC = 0;\r\n  folder->NumUnPackStreams = 0;\r\n}\r\n\r\nvoid SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    SzCoderInfoFree(&folder->Coders[i], freeFunc);\r\n  freeFunc(folder->Coders);\r\n  freeFunc(folder->BindPairs);\r\n  freeFunc(folder->PackStreams);\r\n  freeFunc(folder->UnPackSizes);\r\n  SzFolderInit(folder);\r\n}\r\n\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    result += folder->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder)\r\n{ \r\n  int i = (int)SzFolderGetNumOutStreams(folder);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolderFindBindPairForOutStream(folder, i) < 0)\r\n      return folder->UnPackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\n/*\r\nint FindPackStreamArrayIndex(int inStreamIndex) const\r\n{\r\n  for(int i = 0; i < PackStreams.Size(); i++)\r\n  if (PackStreams[i] == inStreamIndex)\r\n    return i;\r\n  return -1;\r\n}\r\n*/\r\n\r\nvoid SzFileInit(CFileItem *fileItem)\r\n{\r\n  fileItem->IsFileCRCDefined = 0;\r\n  fileItem->HasStream = 1;\r\n  fileItem->IsDirectory = 0;\r\n  fileItem->IsAnti = 0;\r\n  fileItem->IsLastWriteTimeDefined = 0;\r\n  fileItem->Name = 0;\r\n}\r\n\r\nvoid SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))\r\n{\r\n  freeFunc(fileItem->Name);\r\n  SzFileInit(fileItem);\r\n}\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db)\r\n{\r\n  db->NumPackStreams = 0;\r\n  db->PackSizes = 0;\r\n  db->PackCRCsDefined = 0;\r\n  db->PackCRCs = 0;\r\n  db->NumFolders = 0;\r\n  db->Folders = 0;\r\n  db->NumFiles = 0;\r\n  db->Files = 0;\r\n}\r\n\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < db->NumFolders; i++)\r\n    SzFolderFree(&db->Folders[i], freeFunc);\r\n  for (i = 0; i < db->NumFiles; i++)\r\n    SzFileFree(&db->Files[i], freeFunc);\r\n  freeFunc(db->PackSizes);\r\n  freeFunc(db->PackCRCsDefined);\r\n  freeFunc(db->PackCRCs);\r\n  freeFunc(db->Folders);\r\n  freeFunc(db->Files);\r\n  SzArchiveDatabaseInit(db);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zItem.h",
    "content": "/* 7zItem.h */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"7zMethodID.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zBuffer.h\"\r\n\r\ntypedef struct _CCoderInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  CMethodID MethodID;\r\n  CSzByteBuffer Properties;\r\n}CCoderInfo;\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder);\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));\r\n\r\ntypedef struct _CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n}CBindPair;\r\n\r\ntypedef struct _CFolder\r\n{\r\n  UInt32 NumCoders;\r\n  CCoderInfo *Coders;\r\n  UInt32 NumBindPairs;\r\n  CBindPair *BindPairs;\r\n  UInt32 NumPackStreams; \r\n  UInt32 *PackStreams;\r\n  CFileSize *UnPackSizes;\r\n  int UnPackCRCDefined;\r\n  UInt32 UnPackCRC;\r\n\r\n  UInt32 NumUnPackStreams;\r\n}CFolder;\r\n\r\nvoid SzFolderInit(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\n\r\ntypedef struct _CArchiveFileTime\r\n{\r\n  UInt32 Low;\r\n  UInt32 High;\r\n} CArchiveFileTime;\r\n\r\ntypedef struct _CFileItem\r\n{\r\n  CArchiveFileTime LastWriteTime;\r\n  /*\r\n  CFileSize StartPos;\r\n  UInt32 Attributes; \r\n  */\r\n  CFileSize Size;\r\n  UInt32 FileCRC;\r\n  char *Name;\r\n\r\n  Byte IsFileCRCDefined;\r\n  Byte HasStream;\r\n  Byte IsDirectory;\r\n  Byte IsAnti;\r\n  Byte IsLastWriteTimeDefined;\r\n  /*\r\n  int AreAttributesDefined;\r\n  int IsLastWriteTimeDefined;\r\n  int IsStartPosDefined;\r\n  */\r\n}CFileItem;\r\n\r\nvoid SzFileInit(CFileItem *fileItem);\r\n\r\ntypedef struct _CArchiveDatabase\r\n{\r\n  UInt32 NumPackStreams;\r\n  CFileSize *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  UInt32 NumFolders;\r\n  CFolder *Folders;\r\n  UInt32 NumFiles;\r\n  CFileItem *Files;\r\n}CArchiveDatabase;\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db);\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));\r\n\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zMain.c",
    "content": "/* \r\n7zMain.c\r\nTest application for 7z Decoder\r\nLZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-06-04)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#ifdef _WIN32\r\n#define USE_WINDOWS_FUNCTIONS\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FUNCTIONS\r\n#include <windows.h>\r\n#endif\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zExtract.h\"\r\n\r\n#include \"../../7zCrc.h\"\r\n\r\n\r\n#ifdef USE_WINDOWS_FUNCTIONS\r\ntypedef HANDLE MY_FILE_HANDLE;\r\n#else\r\ntypedef FILE *MY_FILE_HANDLE;\r\n#endif\r\n\r\nvoid ConvertNumberToString(CFileSize value, char *s)\r\n{\r\n  char temp[32];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    temp[pos++] = (char)('0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while(pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\n#define PERIOD_4 (4 * 365 + 1)\r\n#define PERIOD_100 (PERIOD_4 * 25 - 1)\r\n#define PERIOD_400 (PERIOD_100 * 4 + 1)\r\n\r\nvoid ConvertFileTimeToString(CArchiveFileTime *ft, char *s)\r\n{\r\n  unsigned year, mon, day, hour, min, sec;\r\n  UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  unsigned temp;\r\n  UInt32 v; \r\n  v64 /= 10000000;\r\n  sec = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  min = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  hour = (unsigned)(v64 % 24);\r\n  v64 /= 24;\r\n\r\n  v = (UInt32)v64;\r\n\r\n  year = (unsigned)(1601 + v / PERIOD_400 * 400);\r\n  v %= PERIOD_400;\r\n\r\n  temp = (unsigned)(v / PERIOD_100);\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp * 100;\r\n  v -= temp * PERIOD_100;\r\n\r\n  temp = v / PERIOD_4;\r\n  if (temp == 25)\r\n    temp = 24;\r\n  year += temp * 4;\r\n  v -= temp * PERIOD_4;\r\n\r\n  temp = v / 365;\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp;\r\n  v -= temp * 365;\r\n\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  for (mon = 1; mon <= 12; mon++)\r\n  {\r\n    unsigned s = ms[mon - 1];\r\n    if (v < s)\r\n      break;\r\n    v -= s;\r\n  }\r\n  day = (unsigned)v + 1;\r\n  sprintf(s, \"%04d-%02d-%02d %02d:%02d:%02d\", year, mon, day, hour, min, sec);\r\n}\r\n\r\n\r\n#ifdef USE_WINDOWS_FUNCTIONS\r\n/*\r\n   ReadFile and WriteFile functions in Windows have BUG:\r\n   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n   (Insufficient system resources exist to complete the requested service).\r\n*/\r\n#define kChunkSizeMax (1 << 24)\r\n#endif\r\n\r\nsize_t MyReadFile(MY_FILE_HANDLE file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  {\r\n    size_t processedSize = 0;\r\n    do\r\n    {\r\n      DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;\r\n      DWORD processedLoc = 0;\r\n      BOOL res = ReadFile(file, data, curSize, &processedLoc, NULL);\r\n      data = (void *)((unsigned char *)data + processedLoc);\r\n      size -= processedLoc;\r\n      processedSize += processedLoc;\r\n      if (!res || processedLoc == 0)\r\n        break;\r\n    }\r\n    while (size > 0);\r\n    return processedSize;\r\n  }\r\n  #else\r\n  return fread(data, 1, size, file); \r\n  #endif\r\n}\r\n\r\nsize_t MyWriteFile(MY_FILE_HANDLE file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  {\r\n    size_t processedSize = 0;\r\n    do\r\n    {\r\n      DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;\r\n      DWORD processedLoc = 0;\r\n      BOOL res = WriteFile(file, data, curSize, &processedLoc, NULL);\r\n      data = (void *)((unsigned char *)data + processedLoc);\r\n      size -= processedLoc;\r\n      processedSize += processedLoc;\r\n      if (!res)\r\n        break;\r\n    }\r\n    while (size > 0);\r\n    return processedSize;\r\n  }\r\n  #else\r\n  return fwrite(data, 1, size, file); \r\n  #endif\r\n}\r\n\r\nint MyCloseFile(MY_FILE_HANDLE file)\r\n{ \r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  return (CloseHandle(file) != FALSE) ? 0 : 1;\r\n  #else\r\n  return fclose(file); \r\n  #endif\r\n}\r\n\r\ntypedef struct _CFileInStream\r\n{\r\n  ISzInStream InStream;\r\n  MY_FILE_HANDLE File;\r\n} CFileInStream;\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define kBufferSize (1 << 12)\r\nByte g_Buffer[kBufferSize];\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc;\r\n  if (maxRequiredSize > kBufferSize)\r\n    maxRequiredSize = kBufferSize;\r\n  processedSizeLoc = MyReadFile(s->File, g_Buffer, maxRequiredSize);\r\n  *buffer = g_Buffer;\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#else\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc = MyReadFile(s->File, buffer, size);\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzFileSeekImp(void *object, CFileSize pos)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n\r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  {\r\n    LARGE_INTEGER value;\r\n    value.LowPart = (DWORD)pos;\r\n    value.HighPart = (LONG)((UInt64)pos >> 32);\r\n    #ifdef _SZ_FILE_SIZE_32\r\n    /* VC 6.0 has bug with >> 32 shifts. */\r\n    value.HighPart = 0;\r\n    #endif\r\n    value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, FILE_BEGIN);\r\n    if (value.LowPart == 0xFFFFFFFF)\r\n      if(GetLastError() != NO_ERROR) \r\n        return SZE_FAIL;\r\n    return SZ_OK;\r\n  }\r\n  #else\r\n  int res = fseek(s->File, (long)pos, SEEK_SET);\r\n  if (res == 0)\r\n    return SZ_OK;\r\n  return SZE_FAIL;\r\n  #endif\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CArchiveDatabaseEx db;\r\n  SZ_RESULT res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder 4.48  Copyright (c) 1999-2007 Igor Pavlov  2007-06-21\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.File = \r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  CreateFile(args[2], GENERIC_READ, FILE_SHARE_READ, \r\n      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\r\n  if (archiveStream.File == INVALID_HANDLE_VALUE)\r\n  #else\r\n  archiveStream.File = fopen(args[2], \"rb\");\r\n  if (archiveStream.File == 0)\r\n  #endif\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.InStream.Read = SzFileReadImp;\r\n  archiveStream.InStream.Seek = SzFileSeekImp;\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  CrcGenerateTable();\r\n\r\n  SzArDbExInit(&db);\r\n  res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0;\r\n    int testCommand = 0;\r\n    int extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0)\r\n      listCommand = 1;\r\n    if (strcmp(command, \"t\") == 0)\r\n      testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0)\r\n      extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        char s[32], t[32];\r\n        ConvertNumberToString(f->Size, s);\r\n        if (f->IsLastWriteTimeDefined)\r\n          ConvertFileTimeToString(&f->LastWriteTime, t);\r\n        else\r\n          strcpy(t, \"                   \");\r\n\r\n        printf(\"%10s %s  %s\\n\", s, t, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      /*\r\n      if you need cache, use these 3 variables.\r\n      if you use external function, you can make these variable as static.\r\n      */\r\n      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r\n      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r\n      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CFileItem *f = db.Database.Files + i;\r\n        if (f->IsDirectory)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ? \r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDirectory)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzExtract(&archiveStream.InStream, &db, i, \r\n            &blockIndex, &outBuffer, &outBufferSize, \r\n            &offset, &outSizeProcessed, \r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          MY_FILE_HANDLE outputHandle;\r\n          size_t processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          outputHandle = \r\n          #ifdef USE_WINDOWS_FUNCTIONS\r\n            CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_READ, \r\n                NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\r\n          if (outputHandle == INVALID_HANDLE_VALUE)\r\n          #else\r\n          fopen(fileName, \"wb+\");\r\n          if (outputHandle == 0)\r\n          #endif\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          processedSize = MyWriteFile(outputHandle, outBuffer + offset, outSizeProcessed);\r\n          if (processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          if (MyCloseFile(outputHandle))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      allocImp.Free(outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZE_FAIL;\r\n    }\r\n  }\r\n  SzArDbExFree(&db, allocImp.Free);\r\n\r\n  MyCloseFile(archiveStream.File);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == (SZ_RESULT)SZE_NOTIMPL)\r\n    PrintError(\"decoder doesn't support this archive\");\r\n  else if (res == (SZ_RESULT)SZE_OUTOFMEMORY)\r\n    PrintError(\"can not allocate memory\");\r\n  else if (res == (SZ_RESULT)SZE_CRC_ERROR)\r\n    PrintError(\"CRC error\");\r\n  else     \r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zMethodID.c",
    "content": "/* 7zMethodID.c */\r\n\r\n#include \"7zMethodID.h\"\r\n\r\n/*\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2)\r\n{\r\n  return (*a1 == *a2) ? 1 : 0;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7zMethodID.h",
    "content": "/* 7zMethodID.h */\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Types.h\"\r\n\r\ntypedef UInt64 CMethodID;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7z_C.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z_C\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z_C - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\" CFG=\"7z_C - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z_C - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z_C - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z_C - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MD /W4 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z_C - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z_C - Win32 Release\"\r\n# Name \"7z_C - Win32 Debug\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Lzma\\LzmaDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Lzma\\LzmaDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Lzma\\LzmaTypes.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86_2.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86_2.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/7z_C.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z_C\"=.\\7z_C.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/makefile",
    "content": "PROG = 7zDec.exe\r\n\r\n!IFDEF CPU\r\nLIBS = $(LIBS) bufferoverflowU.lib \r\nCFLAGS = $(CFLAGS) -GS- -Zc:forScope -WX -GS- -Gy -W4 \r\n!ENDIF\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -D_LZMA_IN_CB\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zBuffer.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n  $O\\7zMethodID.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\BranchX86.obj \\\r\n  $O\\BranchX86_2.obj \\\r\n  $(C_OBJS) \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/Lzma/$(*B).c\r\n\t$(COMPL_O2)\r\n\r\n$O\\BranchX86.obj: ../../Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n\r\n$O\\BranchX86_2.obj: ../../Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Archive/7z/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall -D_LZMA_IN_CB\r\n\r\nOBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o BranchX86.o BranchX86_2.o\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuffer.o: 7zBuffer.c\r\n\t$(CXX) $(CFLAGS) 7zBuffer.c\r\n\r\n7zCrc.o: ../../7zCrc.c\r\n\t$(CXX) $(CFLAGS) ../../7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\n7zMethodID.o: 7zMethodID.c\r\n\t$(CXX) $(CFLAGS) 7zMethodID.c\r\n\r\nLzmaDecode.o: ../../Compress/Lzma/LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/Lzma/LzmaDecode.c\r\n\r\nBranchX86.o: ../../Compress/Branch/BranchX86.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86.c\r\n\r\nBranchX86_2.o: ../../Compress/Branch/BranchX86_2.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86_2.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchARM.c",
    "content": "/* BranchARM.c */\r\n\r\n#include \"BranchARM.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = (data[i + 2] << 16) | (data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = nowPos + i + 8 + src;\r\n      else\r\n        dest = src - (nowPos + i + 8);\r\n      dest >>= 2;\r\n      data[i + 2] = (Byte)(dest >> 16);\r\n      data[i + 1] = (Byte)(dest >> 8);\r\n      data[i + 0] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchARM.h",
    "content": "/* BranchARM.h */\r\n\r\n#ifndef __BRANCH_ARM_H\r\n#define __BRANCH_ARM_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchARMThumb.c",
    "content": "/* BranchARMThumb.c */\r\n\r\n#include \"BranchARMThumb.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 && \r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = \r\n        ((data[i + 1] & 0x7) << 19) |\r\n        (data[i + 0] << 11) |\r\n        ((data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      if (encoding)\r\n        dest = nowPos + i + 4 + src;\r\n      else\r\n        dest = src - (nowPos + i + 4);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));\r\n      data[i + 0] = (Byte)(dest >> 11);\r\n      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));\r\n      data[i + 2] = (Byte)dest;\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchARMThumb.h",
    "content": "/* BranchARMThumb.h */\r\n\r\n#ifndef __BRANCH_ARM_THUMB_H\r\n#define __BRANCH_ARM_THUMB_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchIA64.c",
    "content": "/* BranchIA64.c */\r\n\r\n#include \"BranchIA64.h\"\r\n\r\nconst Byte kBranchTable[32] = \r\n{ \r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0 \r\n};\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 16 <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    int slot;\r\n    for (slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      UInt32 bytePos, bitRes;\r\n      UInt64 instruction, instNorm;\r\n      int j;\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      bytePos = (bitPos >> 3);\r\n      bitRes = bitPos & 0x7;\r\n      instruction = 0;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);\r\n\r\n      instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 \r\n        &&  ((instNorm >> 9) & 0x7) == 0 \r\n        /* &&  (instNorm & 0x3F)== 0 */\r\n        )\r\n      {\r\n        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);\r\n        UInt32 dest;\r\n        src |= ((UInt32)(instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        if (encoding)\r\n          dest = nowPos + i + src;\r\n        else\r\n          dest = src - (nowPos + i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~((UInt64)(0x8FFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchIA64.h",
    "content": "/* BranchIA64.h */\r\n\r\n#ifndef __BRANCH_IA64_H\r\n#define __BRANCH_IA64_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchPPC.c",
    "content": "/* BranchPPC.c */\r\n\r\n#include \"BranchPPC.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    /* PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) */\r\n    if ((data[i] >> 2) == 0x12 && \r\n    (\r\n      (data[i + 3] & 3) == 1 \r\n      /* || (data[i+3] & 3) == 3 */\r\n      )\r\n    )\r\n    {\r\n      UInt32 src = ((data[i + 0] & 3) << 24) |\r\n        (data[i + 1] << 16) |\r\n        (data[i + 2] << 8) |\r\n        (data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchPPC.h",
    "content": "/* BranchPPC.h */\r\n\r\n#ifndef __BRANCH_PPC_H\r\n#define __BRANCH_PPC_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchSPARC.c",
    "content": "/* BranchSPARC.c */\r\n\r\n#include \"BranchSPARC.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || \r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      UInt32 dest;\r\n      \r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchSPARC.h",
    "content": "/* BranchSPARC.h */\r\n\r\n#ifndef __BRANCH_SPARC_H\r\n#define __BRANCH_SPARC_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchTypes.h",
    "content": "/* BranchTypes.h */\r\n\r\n#ifndef __BRANCHTYPES_H\r\n#define __BRANCHTYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif\r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\n#ifdef _SZ_NO_INT_64\r\ntypedef unsigned long UInt64;\r\n#else\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n#endif\r\n#endif\r\n\r\n/* #define _LZMA_NO_SYSTEM_SIZE_T */\r\n/* You can use it, if you don't want <stddef.h> */\r\n\r\n#ifndef _7ZIP_SIZET_DEFINED\r\n#define _7ZIP_SIZET_DEFINED\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\n#include <stddef.h>\r\ntypedef size_t SizeT;\r\n#endif\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchX86.c",
    "content": "/* BranchX86.c */\r\n\r\n#include \"BranchX86.h\"\r\n\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\nSizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *prevMaskMix, int encoding)\r\n{\r\n  SizeT bufferPos = 0, prevPosT;\r\n  UInt32 prevMask = *prevMaskMix & 0x7;\r\n  if (endPos < 5)\r\n    return 0;\r\n  nowPos += 5;\r\n  prevPosT = (SizeT)0 - 1;\r\n\r\n  for(;;)\r\n  {\r\n    Byte *p = buffer + bufferPos;\r\n    Byte *limit = buffer + endPos - 4;\r\n    for (; p < limit; p++)\r\n      if ((*p & 0xFE) == 0xE8)\r\n        break;\r\n    bufferPos = (SizeT)(p - buffer);\r\n    if (p >= limit)\r\n      break;\r\n    prevPosT = bufferPos - prevPosT;\r\n    if (prevPosT > 3)\r\n      prevMask = 0;\r\n    else\r\n    {\r\n      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r\n      if (prevMask != 0)\r\n      {\r\n        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r\n        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r\n        {\r\n          prevPosT = bufferPos;\r\n          prevMask = ((prevMask << 1) & 0x7) | 1;\r\n          bufferPos++;\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    prevPosT = bufferPos;\r\n\r\n    if (Test86MSByte(p[4]))\r\n    {\r\n      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r\n      UInt32 dest;\r\n      for (;;)\r\n      {\r\n        Byte b;\r\n        int index;\r\n        if (encoding)\r\n          dest = (nowPos + (UInt32)bufferPos) + src;\r\n        else\r\n          dest = src - (nowPos + (UInt32)bufferPos);\r\n        if (prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[prevMask] * 8;\r\n        b = (Byte)(dest >> (24 - index));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index)) - 1);\r\n      }\r\n      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      p[3] = (Byte)(dest >> 16);\r\n      p[2] = (Byte)(dest >> 8);\r\n      p[1] = (Byte)dest;\r\n      bufferPos += 5;\r\n    }\r\n    else\r\n    {\r\n      prevMask = ((prevMask << 1) & 0x7) | 1;\r\n      bufferPos++;\r\n    }\r\n  }\r\n  prevPosT = bufferPos - prevPosT;\r\n  *prevMaskMix = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchX86.h",
    "content": "/* BranchX86.h */\r\n\r\n#ifndef __BRANCHX86_H\r\n#define __BRANCHX86_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\n#define x86_Convert_Init(state) { state = 0; }\r\n\r\nSizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *state, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchX86_2.c",
    "content": "// BranchX86_2.c\r\n\r\n#include \"BranchX86_2.h\"\r\n\r\n#include \"../../Alloc.h\"\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)\r\n#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return BCJ2_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n// #define UpdateBit0(p) Range = bound; *(p) = (CProb)(*(p) + ((kBitModelTotal - *(p)) >> kNumMoveBits));\r\n// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) = (CProb)(*(p) - (*(p) >> kNumMoveBits));\r\n\r\nint x86_2_Decode(\r\n    const Byte *buf0, SizeT size0, \r\n    const Byte *buf1, SizeT size1, \r\n    const Byte *buf2, SizeT size2, \r\n    const Byte *buf3, SizeT size3, \r\n    Byte *outBuf, SizeT outSize)\r\n{\r\n  CProb p[256 + 2];\r\n  SizeT inPos = 0, outPos = 0;\r\n\r\n  const Byte *Buffer, *BufferLim;\r\n  UInt32 Range, Code;\r\n  Byte prevByte = 0;\r\n\r\n  unsigned int i;\r\n  for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)\r\n    p[i] = kBitModelTotal >> 1; \r\n  RC_INIT(buf3, size3);\r\n\r\n  if (outSize == 0)\r\n    return BCJ2_RESULT_OK;\r\n\r\n  for (;;)\r\n  {\r\n    Byte b;\r\n    CProb *prob;\r\n    UInt32 bound;\r\n\r\n    SizeT limit = size0 - inPos;\r\n    if (outSize - outPos < limit)\r\n      limit = outSize - outPos;\r\n    while (limit != 0)\r\n    {\r\n      Byte b = buf0[inPos];\r\n      outBuf[outPos++] = b;\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      inPos++;\r\n      prevByte = b;\r\n      limit--;\r\n    }\r\n\r\n    if (limit == 0 || outPos == outSize)\r\n      break;\r\n\r\n    b = buf0[inPos++];\r\n\r\n    if (b == 0xE8)\r\n      prob = p + prevByte;\r\n    else if (b == 0xE9)\r\n      prob = p + 256;\r\n    else\r\n      prob = p + 257;\r\n\r\n    IfBit0(prob)\r\n    {\r\n      UpdateBit0(prob)\r\n      prevByte = b;\r\n    }\r\n    else\r\n    {\r\n      UInt32 dest;\r\n      const Byte *v;\r\n      UpdateBit1(prob)\r\n      if (b == 0xE8)\r\n      {\r\n        v = buf1;\r\n        if (size1 < 4)\r\n          return BCJ2_RESULT_DATA_ERROR;\r\n        buf1 += 4;\r\n        size1 -= 4;\r\n      }\r\n      else\r\n      {\r\n        v = buf2;\r\n        if (size2 < 4)\r\n          return BCJ2_RESULT_DATA_ERROR;\r\n        buf2 += 4;\r\n        size2 -= 4;\r\n      }\r\n      dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) | \r\n          ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);\r\n      outBuf[outPos++] = (Byte)dest;\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 8);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 16);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = prevByte = (Byte)(dest >> 24);\r\n    }\r\n  }\r\n  return (outPos == outSize) ? BCJ2_RESULT_OK : BCJ2_RESULT_DATA_ERROR;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Branch/BranchX86_2.h",
    "content": "// BranchX86_2.h\r\n\r\n#ifndef __BRANCHX86_2_H\r\n#define __BRANCHX86_2_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\n#define BCJ2_RESULT_OK 0\r\n#define BCJ2_RESULT_DATA_ERROR 1\r\n\r\n/*\r\nConditions:\r\n  outSize <= FullOutputSize, \r\n  where FullOutputSize is full size of output stream of x86_2 filter.\r\n\r\nIf buf0 overlaps outBuf, there are two required conditions:\r\n  1) (buf0 >= outBuf)\r\n  2) (buf0 + size0 >= outBuf + FullOutputSize).\r\n*/\r\n\r\nint x86_2_Decode(\r\n    const Byte *buf0, SizeT size0, \r\n    const Byte *buf1, SizeT size1, \r\n    const Byte *buf2, SizeT size2, \r\n    const Byte *buf3, SizeT size3, \r\n    Byte *outBuf, SizeT outSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Huffman/HuffmanEncode.c",
    "content": "/* Compress/HuffmanEncode.c */\r\n\r\n#include \"HuffmanEncode.h\"\r\n#include \"../../Sort.h\"\r\n\r\n#define kMaxLen 16\r\n#define NUM_BITS 10\r\n#define MASK ((1 << NUM_BITS) - 1)\r\n\r\n#define NUM_COUNTERS 64\r\n\r\n/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M */\r\n#define HUFFMAN_SPEED_OPT\r\n\r\nvoid Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen)\r\n{\r\n  UInt32 num = 0;\r\n  /* if (maxLen > 10) maxLen = 10; */\r\n  {\r\n    UInt32 i;\r\n    \r\n    #ifdef HUFFMAN_SPEED_OPT\r\n    \r\n    UInt32 counters[NUM_COUNTERS];\r\n    for (i = 0; i < NUM_COUNTERS; i++) \r\n      counters[i] = 0;\r\n    for (i = 0; i < numSymbols; i++) \r\n    {\r\n      UInt32 freq = freqs[i];\r\n      counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++;\r\n    }\r\n \r\n    for (i = 1; i < NUM_COUNTERS; i++) \r\n    {\r\n      UInt32 temp = counters[i];\r\n      counters[i] = num;\r\n      num += temp;\r\n    }\r\n\r\n    for (i = 0; i < numSymbols; i++) \r\n    {\r\n      UInt32 freq = freqs[i];\r\n      if (freq == 0)\r\n        lens[i] = 0;\r\n      else\r\n        p[counters[((freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1)]++] = i | (freq << NUM_BITS);\r\n    }\r\n    counters[0] = 0;\r\n    HeapSort(p + counters[NUM_COUNTERS - 2], counters[NUM_COUNTERS - 1] - counters[NUM_COUNTERS - 2]);\r\n    \r\n    #else\r\n\r\n    for (i = 0; i < numSymbols; i++) \r\n    {\r\n      UInt32 freq = freqs[i];\r\n      if (freq == 0)\r\n        lens[i] = 0;\r\n      else\r\n        p[num++] = i | (freq << NUM_BITS);\r\n    }\r\n    HeapSort(p, num);\r\n\r\n    #endif\r\n  }\r\n\r\n  if (num < 2) \r\n  {\r\n    int minCode = 0;\r\n    int maxCode = 1;\r\n    if (num == 1)\r\n    {\r\n      maxCode = p[0] & MASK;\r\n      if (maxCode == 0)\r\n        maxCode++;\r\n    }\r\n    p[minCode] = 0;\r\n    p[maxCode] = 1;\r\n    lens[minCode] = lens[maxCode] = 1;\r\n    return;\r\n  }\r\n  \r\n  {\r\n    UInt32 b, e, i;\r\n  \r\n    i = b = e = 0;\r\n    do \r\n    {\r\n      UInt32 n, m, freq;\r\n      n = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;\r\n      freq = (p[n] & ~MASK);\r\n      p[n] = (p[n] & MASK) | (e << NUM_BITS);\r\n      m = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;\r\n      freq += (p[m] & ~MASK);\r\n      p[m] = (p[m] & MASK) | (e << NUM_BITS);\r\n      p[e] = (p[e] & MASK) | freq;\r\n      e++;\r\n    } \r\n    while (num - e > 1);\r\n    \r\n    {\r\n      UInt32 lenCounters[kMaxLen + 1];\r\n      for (i = 0; i <= kMaxLen; i++) \r\n        lenCounters[i] = 0;\r\n      \r\n      p[--e] &= MASK;\r\n      lenCounters[1] = 2;\r\n      while (e > 0) \r\n      {\r\n        UInt32 len = (p[p[--e] >> NUM_BITS] >> NUM_BITS) + 1;\r\n        p[e] = (p[e] & MASK) | (len << NUM_BITS);\r\n        if (len >= maxLen) \r\n          for (len = maxLen - 1; lenCounters[len] == 0; len--);\r\n        lenCounters[len]--;\r\n        lenCounters[len + 1] += 2;\r\n      }\r\n      \r\n      {\r\n        UInt32 len;\r\n        i = 0;\r\n        for (len = maxLen; len != 0; len--) \r\n        {\r\n          UInt32 num;\r\n          for (num = lenCounters[len]; num != 0; num--) \r\n            lens[p[i++] & MASK] = (Byte)len;\r\n        }\r\n      }\r\n      \r\n      {\r\n        UInt32 nextCodes[kMaxLen + 1];\r\n        {\r\n          UInt32 code = 0;\r\n          UInt32 len;\r\n          for (len = 1; len <= kMaxLen; len++) \r\n            nextCodes[len] = code = (code + lenCounters[len - 1]) << 1;\r\n        }\r\n        /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */\r\n\r\n        {\r\n          UInt32 i;\r\n          for (i = 0; i < numSymbols; i++) \r\n            p[i] = nextCodes[lens[i]]++;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Huffman/HuffmanEncode.h",
    "content": "/* Compress/HuffmanEncode.h */\r\n\r\n#ifndef __COMPRESS_HUFFMANENCODE_H\r\n#define __COMPRESS_HUFFMANENCODE_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n/*\r\nConditions:\r\n  num <= 1024 = 2 ^ NUM_BITS\r\n  Sum(freqs) < 4M = 2 ^ (32 - NUM_BITS)\r\n  maxLen <= 16 = kMaxLen\r\n  Num_Items(p) >= HUFFMAN_TEMP_SIZE(num)\r\n*/\r\n \r\nvoid Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lz/LzHash.h",
    "content": "/* LzHash.h */\r\n\r\n#ifndef __C_LZHASH_H\r\n#define __C_LZHASH_H\r\n\r\n#define kHash2Size (1 << 10)\r\n#define kHash3Size (1 << 16)\r\n#define kHash4Size (1 << 20)\r\n\r\n#define kFix3HashSize (kHash2Size)\r\n#define kFix4HashSize (kHash2Size + kHash3Size)\r\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r\n\r\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r\n\r\n#define HASH3_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r\n\r\n#define HASH4_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & p->hashMask; }\r\n\r\n#define HASH5_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)); \\\r\n  hashValue = (hash4Value ^ (g_CrcTable[cur[4]] << 3)) & p->hashMask; \\\r\n  hash4Value &= (kHash4Size - 1); }\r\n\r\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ g_CrcTable[cur[2]]) & 0xFFFF; */\r\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ g_CrcTable[cur[1]]) & 0xFFFF;\r\n\r\n\r\n#define MT_HASH2_CALC \\\r\n  hash2Value = (g_CrcTable[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r\n\r\n#define MT_HASH3_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r\n\r\n#define MT_HASH4_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & (kHash4Size - 1); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lz/MatchFinder.c",
    "content": "/* MatchFinder.c */\r\n/* Please call InitCrcTable before */\r\n\r\n#include <string.h>\r\n\r\n#include \"MatchFinder.h\"\r\n#include \"LzHash.h\"\r\n\r\n#include \"../../7zCrc.h\"\r\n\r\n#define kEmptyHashValue 0\r\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\r\n#define kMaxHistorySize ((UInt32)3 << 30)\r\n\r\n#define kStartMaxLen 3\r\n\r\nvoid LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  if (!p->directInput)\r\n  {\r\n    alloc->Free(p->bufferBase);\r\n    p->bufferBase = 0;\r\n  }\r\n}\r\n\r\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r\n\r\nint LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r\n{\r\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r\n  if (p->directInput)\r\n  {\r\n    p->blockSize = blockSize;\r\n    return 1;\r\n  }\r\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\r\n  {\r\n    LzInWindow_Free(p, alloc);\r\n    p->blockSize = blockSize;\r\n    p->bufferBase = (Byte *)alloc->Alloc(blockSize);\r\n  }\r\n  return (p->bufferBase != 0);\r\n}\r\n\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r\n\r\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r\n\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r\n{\r\n  p->posLimit -= subValue;\r\n  p->pos -= subValue;\r\n  p->streamPos -= subValue;\r\n}\r\n\r\nvoid MatchFinder_ReadBlock(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached || p->result != SZ_OK)\r\n    return;\r\n  for (;;)\r\n  {\r\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\r\n    UInt32 numReadBytes;\r\n    UInt32 size = (UInt32)(p->bufferBase + p->blockSize - dest);\r\n    if (size == 0)\r\n      return;\r\n    p->result = p->stream->Read(p->stream, dest, size, &numReadBytes);\r\n    if (p->result != SZ_OK)\r\n      return;\r\n    if (numReadBytes == 0)\r\n    {\r\n      p->streamEndWasReached = 1;\r\n      return;\r\n    }\r\n    p->streamPos += numReadBytes;\r\n    if (p->streamPos - p->pos > p->keepSizeAfter)\r\n      return;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\r\n{\r\n  memmove(p->bufferBase, \r\n    p->buffer - p->keepSizeBefore, \r\n    p->streamPos - p->pos + p->keepSizeBefore);\r\n  p->buffer = p->bufferBase + p->keepSizeBefore;\r\n}\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p)\r\n{\r\n  /* if (p->streamEndWasReached) return 0; */\r\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r\n}\r\n\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached) \r\n    return;\r\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\r\n    MatchFinder_ReadBlock(p);\r\n}\r\n\r\nvoid MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r\n{\r\n  if (MatchFinder_NeedMove(p))\r\n    MatchFinder_MoveBlock(p);\r\n  MatchFinder_ReadBlock(p);\r\n}\r\n\r\nvoid MatchFinder_SetDefaultSettings(CMatchFinder *p)\r\n{\r\n  p->cutValue = 32;\r\n  p->btMode = 1;\r\n  p->numHashBytes = 4;\r\n  /* p->skipModeBits = 0; */\r\n  p->directInput = 0;\r\n  p->bigHash = 0;\r\n}\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p)\r\n{\r\n  p->bufferBase = 0;\r\n  p->directInput = 0;\r\n  p->hash = 0;\r\n  MatchFinder_SetDefaultSettings(p);\r\n}\r\n\r\nvoid MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(p->hash);\r\n  p->hash = 0;\r\n}\r\n\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  MatchFinder_FreeThisClassMemory(p, alloc);\r\n  LzInWindow_Free(p, alloc);\r\n}\r\n\r\nCLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r\n{\r\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r\n  if (sizeInBytes / sizeof(CLzRef) != num)\r\n    return 0;\r\n  return (CLzRef *)alloc->Alloc(sizeInBytes);\r\n}\r\n\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize, \r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 sizeReserv;\r\n  if (historySize > kMaxHistorySize)\r\n  {\r\n    MatchFinder_Free(p, alloc);\r\n    return 0;\r\n  }\r\n  sizeReserv = historySize >> 1;\r\n  if (historySize > ((UInt32)2 << 30))\r\n    sizeReserv = historySize >> 2;\r\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r\n\r\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1; \r\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r\n  if (LzInWindow_Create(p, sizeReserv, alloc))\r\n  {\r\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r\n    UInt32 hs;\r\n    p->matchMaxLen = matchMaxLen;\r\n    {\r\n      p->fixedHashSize = 0;\r\n      if (p->numHashBytes == 2)\r\n        hs = (1 << 16) - 1;\r\n      else\r\n      {\r\n        hs = historySize - 1;\r\n        hs |= (hs >> 1);\r\n        hs |= (hs >> 2);\r\n        hs |= (hs >> 4);\r\n        hs |= (hs >> 8);\r\n        hs >>= 1;\r\n        /* hs >>= p->skipModeBits; */\r\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r\n        if (hs > (1 << 24))\r\n        {\r\n          if (p->numHashBytes == 3)\r\n            hs = (1 << 24) - 1;\r\n          else\r\n            hs >>= 1;\r\n        }\r\n      }\r\n      p->hashMask = hs;\r\n      hs++;\r\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r\n      hs += p->fixedHashSize;\r\n    }\r\n\r\n    {\r\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\r\n      UInt32 newSize;\r\n      p->historySize = historySize;\r\n      p->hashSizeSum = hs;\r\n      p->cyclicBufferSize = newCyclicBufferSize;\r\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r\n      newSize = p->hashSizeSum + p->numSons;\r\n      if (p->hash != 0 && prevSize == newSize)\r\n        return 1;\r\n      MatchFinder_FreeThisClassMemory(p, alloc);\r\n      p->hash = AllocRefs(newSize, alloc);\r\n      if (p->hash != 0)\r\n      {\r\n        p->son = p->hash + p->hashSizeSum;\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  MatchFinder_Free(p, alloc);\r\n  return 0;\r\n}\r\n\r\nvoid MatchFinder_SetLimits(CMatchFinder *p)\r\n{\r\n  UInt32 limit = kMaxValForNormalize - p->pos;\r\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r\n  if (limit2 < limit) \r\n    limit = limit2;\r\n  limit2 = p->streamPos - p->pos;\r\n  if (limit2 <= p->keepSizeAfter)\r\n  {\r\n    if (limit2 > 0)\r\n      limit2 = 1;\r\n  }\r\n  else\r\n    limit2 -= p->keepSizeAfter;\r\n  if (limit2 < limit) \r\n    limit = limit2;\r\n  {\r\n    UInt32 lenLimit = p->streamPos - p->pos;\r\n    if (lenLimit > p->matchMaxLen)\r\n      lenLimit = p->matchMaxLen;\r\n    p->lenLimit = lenLimit;\r\n  }\r\n  p->posLimit = p->pos + limit;\r\n}\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < p->hashSizeSum; i++)\r\n    p->hash[i] = kEmptyHashValue;\r\n  p->cyclicBufferPos = 0;\r\n  p->buffer = p->bufferBase;\r\n  p->pos = p->streamPos = p->cyclicBufferSize;\r\n  p->result = SZ_OK;\r\n  p->streamEndWasReached = 0;\r\n  MatchFinder_ReadBlock(p);\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nUInt32 MatchFinder_GetSubValue(CMatchFinder *p) \r\n{ \r\n  return (p->pos - p->historySize - 1) & kNormalizeMask; \r\n}\r\n\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_Normalize(CMatchFinder *p)\r\n{\r\n  UInt32 subValue = MatchFinder_GetSubValue(p);\r\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r\n  MatchFinder_ReduceOffsets(p, subValue);\r\n}\r\n\r\nvoid MatchFinder_CheckLimits(CMatchFinder *p)\r\n{\r\n  if (p->pos == kMaxValForNormalize)\r\n    MatchFinder_Normalize(p);\r\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r\n    MatchFinder_CheckAndMoveAndRead(p);\r\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\r\n    p->cyclicBufferPos = 0;\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nUInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, \r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  son[_cyclicBufferPos] = curMatch;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n      return distances;\r\n    {\r\n      const Byte *pb = cur - delta;\r\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r\n      {\r\n        UInt32 len = 0;\r\n        while(++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n            return distances;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, \r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return distances;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while(++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return distances;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nvoid SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        while(++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        {\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define MOVE_POS \\\r\n  ++p->cyclicBufferPos; \\\r\n  p->buffer++; \\\r\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r\n\r\n#define MOVE_POS_RET MOVE_POS return offset;\r\n\r\nvoid MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r\n\r\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\r\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\r\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\r\n  cur = p->buffer;\r\n\r\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r\n\r\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r\n\r\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\r\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\r\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\r\n\r\n#define SKIP_FOOTER \\\r\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r\n\r\nUInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(2)\r\n  HASH2_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 1)\r\n}\r\n\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 2)\r\n}\r\n\r\nUInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, delta2, maxLen, offset;\r\n  GET_MATCHES_HEADER(3)\r\n\r\n  HASH3_CALC;\r\n\r\n  delta2 = p->pos - p->hash[hash2Value];\r\n  curMatch = p->hash[kFix3HashSize + hashValue];\r\n  \r\n  p->hash[hash2Value] = \r\n  p->hash[kFix3HashSize + hashValue] = p->pos;\r\n\r\n\r\n  maxLen = 2;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[0] = maxLen;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET; \r\n    }\r\n  }\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nUInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n  \r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET; \r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nUInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n\r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      p->son[p->cyclicBufferPos] = curMatch;\r\n      MOVE_POS_RET; \r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances + offset, maxLen) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances, 2) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nvoid Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(2) \r\n    HASH2_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value;\r\n    SKIP_HEADER(3)\r\n    HASH3_CALC;\r\n    curMatch = p->hash[kFix3HashSize + hashValue];\r\n    p->hash[hash2Value] =\r\n    p->hash[kFix3HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4) \r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] =\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r\n  if (!p->btMode)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 2)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 3)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r\n  }\r\n  else\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lz/MatchFinder.h",
    "content": "/* MatchFinder.h */\r\n\r\n#ifndef __MATCHFINDER_H\r\n#define __MATCHFINDER_H\r\n\r\n#include \"../../IStream.h\"\r\n\r\ntypedef UInt32 CLzRef;\r\n\r\ntypedef struct _CMatchFinder\r\n{\r\n  Byte *buffer;\r\n  UInt32 pos;\r\n  UInt32 posLimit;\r\n  UInt32 streamPos;\r\n  UInt32 lenLimit;\r\n\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r\n\r\n  UInt32 matchMaxLen;\r\n  CLzRef *hash;\r\n  CLzRef *son;\r\n  UInt32 hashMask;\r\n  UInt32 cutValue;\r\n\r\n  Byte *bufferBase;\r\n  ISeqInStream *stream;\r\n  int streamEndWasReached;\r\n\r\n  UInt32 blockSize;\r\n  UInt32 keepSizeBefore;\r\n  UInt32 keepSizeAfter;\r\n\r\n  UInt32 numHashBytes;\r\n  int directInput;\r\n  int btMode;\r\n  /* int skipModeBits; */\r\n  int bigHash;\r\n  UInt32 historySize;\r\n  UInt32 fixedHashSize;\r\n  UInt32 hashSizeSum;\r\n  UInt32 numSons;\r\n\r\n  HRes result;\r\n} CMatchFinder;\r\n\r\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r\n\r\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p);\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p);\r\n\r\n/* Conditions:\r\n     historySize <= 3 GB\r\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r\n*/\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize, \r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc);\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, \r\n    UInt32 *distances, UInt32 maxLen);\r\n\r\n/* \r\nConditions:\r\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r\n*/\r\n\r\ntypedef void (*Mf_Init_Func)(void *object);\r\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\r\n\r\ntypedef struct _IMatchFinder\r\n{\r\n  Mf_Init_Func Init;\r\n  Mf_GetIndexByte_Func GetIndexByte;\r\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r\n  Mf_GetMatches_Func GetMatches;\r\n  Mf_Skip_Func Skip;\r\n} IMatchFinder;\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p);\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lz/MatchFinderMt.c",
    "content": "/* MatchFinderMt.c */\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"LzHash.h\"\r\n\r\n#include \"MatchFinderMt.h\"\r\n\r\nvoid MtSync_Construct(CMtSync *p)\r\n{\r\n  p->wasCreated = False;\r\n  p->csWasInitialized = False;\r\n  p->csWasEntered = False;\r\n  Thread_Construct(&p->thread);\r\n  Event_Construct(&p->canStart);\r\n  Event_Construct(&p->wasStarted);\r\n  Event_Construct(&p->wasStopped);\r\n  Semaphore_Construct(&p->freeSemaphore);\r\n  Semaphore_Construct(&p->filledSemaphore);\r\n}\r\n\r\nvoid MtSync_GetNextBlock(CMtSync *p)\r\n{\r\n  if (p->needStart)\r\n  {\r\n    p->numProcessedBlocks = 1;\r\n    p->needStart = False;\r\n    p->stopWriting = False;\r\n    p->exit = False;\r\n    Event_Reset(&p->wasStarted);\r\n    Event_Reset(&p->wasStopped);\r\n\r\n    Event_Set(&p->canStart);\r\n    Event_Wait(&p->wasStarted);\r\n  }\r\n  else\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n    p->numProcessedBlocks++;\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  Semaphore_Wait(&p->filledSemaphore);\r\n  CriticalSection_Enter(&p->cs);\r\n  p->csWasEntered = True;\r\n}\r\n\r\n/* MtSync_StopWriting must be called if Writing was started */\r\n\r\nvoid MtSync_StopWriting(CMtSync *p)\r\n{ \r\n  UInt32 myNumBlocks = p->numProcessedBlocks;\r\n  if (!Thread_WasCreated(&p->thread) || p->needStart)\r\n    return;\r\n  p->stopWriting = True;\r\n  if (p->csWasEntered)\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n  }\r\n  Semaphore_Release1(&p->freeSemaphore);\r\n \r\n  Event_Wait(&p->wasStopped);\r\n\r\n  while (myNumBlocks++ != p->numProcessedBlocks)\r\n  {\r\n    Semaphore_Wait(&p->filledSemaphore);\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  p->needStart = True;\r\n}\r\n\r\nvoid MtSync_Destruct(CMtSync *p)\r\n{\r\n  if (Thread_WasCreated(&p->thread))\r\n  {\r\n    MtSync_StopWriting(p);\r\n    p->exit = True;\r\n    if (p->needStart)\r\n      Event_Set(&p->canStart);\r\n    Thread_Wait(&p->thread);\r\n    Thread_Close(&p->thread);\r\n  }\r\n  if (p->csWasInitialized)\r\n  {\r\n    CriticalSection_Delete(&p->cs);\r\n    p->csWasInitialized = False;\r\n  }\r\n\r\n  Event_Close(&p->canStart);\r\n  Event_Close(&p->wasStarted);\r\n  Event_Close(&p->wasStopped);\r\n  Semaphore_Close(&p->freeSemaphore);\r\n  Semaphore_Close(&p->filledSemaphore);\r\n\r\n  p->wasCreated = False;\r\n}\r\n\r\nHRes MtSync_Create2(CMtSync *p, unsigned (StdCall *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  if (p->wasCreated)\r\n    return SZ_OK;\r\n\r\n  RINOK(CriticalSection_Init(&p->cs));\r\n  p->csWasInitialized = True;\r\n\r\n  RINOK(AutoResetEvent_CreateNotSignaled(&p->canStart));\r\n  RINOK(AutoResetEvent_CreateNotSignaled(&p->wasStarted));\r\n  RINOK(AutoResetEvent_CreateNotSignaled(&p->wasStopped));\r\n  \r\n  RINOK(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));\r\n  RINOK(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));\r\n\r\n  p->needStart = True;\r\n  \r\n  RINOK(Thread_Create(&p->thread, startAddress, obj));\r\n  p->wasCreated = True;\r\n  return SZ_OK;\r\n}\r\n\r\nHRes MtSync_Create(CMtSync *p, unsigned (StdCall *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  HRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\r\n  if (res != SZ_OK)\r\n    MtSync_Destruct(p);\r\n  return res;\r\n}\r\n\r\n\r\nvoid MtSync_Init(CMtSync *p) { p->needStart = True; }\r\n\r\n#define kMtMaxValForNormalize 0xFFFFFFFF\r\n\r\n#define DEF_GetHeads(name, v) \\\r\nstatic void GetHeads ## name(const Byte *p, UInt32 pos, \\\r\nUInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads) { \\\r\nfor (; numHeads != 0; numHeads--) { \\\r\nconst UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r\n\r\nDEF_GetHeads(2,  (p[0] | ((UInt32)p[1] << 8)) & hashMask)\r\nDEF_GetHeads(3,  (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\r\nDEF_GetHeads(4,  (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (g_CrcTable[p[3]] << 5)) & hashMask)\r\nDEF_GetHeads(4b, (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\r\nDEF_GetHeads(5,  (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (g_CrcTable[p[3]] << 5) ^ (g_CrcTable[p[4]] << 3)) & hashMask)\r\n\r\nvoid HashThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->hashSync;\r\n  for (;;)\r\n  {\r\n    UInt32 numProcessedBlocks = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = numProcessedBlocks;\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n\r\n      {\r\n        CMatchFinder *mf = mt->MatchFinder;\r\n        if (MatchFinder_NeedMove(mf))\r\n        {\r\n          CriticalSection_Enter(&mt->btSync.cs);\r\n          CriticalSection_Enter(&mt->hashSync.cs);\r\n          {\r\n            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            const Byte *afterPtr;\r\n            MatchFinder_MoveBlock(mf);\r\n            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            mt->pointerToCurPos -= beforePtr - afterPtr;\r\n            mt->buffer -= beforePtr - afterPtr;\r\n          }\r\n          CriticalSection_Leave(&mt->btSync.cs);\r\n          CriticalSection_Leave(&mt->hashSync.cs);\r\n          continue;\r\n        }\r\n\r\n        Semaphore_Wait(&p->freeSemaphore);\r\n\r\n        MatchFinder_ReadIfRequired(mf);\r\n        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))\r\n        {\r\n          UInt32 subValue = (mf->pos - mf->historySize - 1);\r\n          MatchFinder_ReduceOffsets(mf, subValue);\r\n          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);\r\n        }\r\n        {\r\n          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n          UInt32 num = mf->streamPos - mf->pos;\r\n          heads[0] = 2;\r\n          heads[1] = num;\r\n          if (num >= mf->numHashBytes)\r\n          {\r\n            num = num - mf->numHashBytes + 1;\r\n            if (num > kMtHashBlockSize - 2)\r\n              num = kMtHashBlockSize - 2;\r\n            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num);\r\n            heads[0] += num;\r\n          }\r\n          mf->pos += num;\r\n          mf->buffer += num;\r\n        }\r\n      }\r\n\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r\n{\r\n  MtSync_GetNextBlock(&p->hashSync);\r\n  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];\r\n  p->hashNumAvail = p->hashBuf[p->hashBufPos++];\r\n}\r\n\r\n#define kEmptyHashValue 0\r\n\r\n/* #define MFMT_GM_INLINE */\r\n\r\n#ifdef MFMT_GM_INLINE\r\n\r\n#if _MSC_VER >= 1300\r\n#define NO_INLINE __declspec(noinline) __fastcall \r\n#else\r\n#ifdef _MSC_VER\r\n#define NO_INLINE __fastcall \r\n#endif\r\n#endif\r\n\r\nInt32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, \r\n    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\r\n{\r\n  do\r\n  {\r\n  UInt32 *distances = _distances + 1;\r\n  UInt32 curMatch = pos - *hash++;\r\n\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  UInt32 cutValue = _cutValue;\r\n  UInt32 maxLen = _maxLen;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      break;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while(++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            break;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n  pos++;\r\n  _cyclicBufferPos++;\r\n  cur++;\r\n  {\r\n    UInt32 num = (UInt32)(distances - _distances);\r\n    *_distances = num - 1;\r\n    _distances += num;\r\n    limit -= num;\r\n  }\r\n  }\r\n  while (limit > 0 && --size != 0);\r\n  *posRes = pos;\r\n  return limit;\r\n}\r\n\r\n#endif\r\n\r\nvoid BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  UInt32 numProcessed = 0;\r\n  UInt32 curPos = 2;\r\n  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\r\n  distances[1] = p->hashNumAvail;\r\n  while (curPos < limit)\r\n  {\r\n    if (p->hashBufPos == p->hashBufPosLimit)\r\n    {\r\n      MatchFinderMt_GetNextBlock_Hash(p);\r\n      distances[1] = numProcessed + p->hashNumAvail;\r\n      if (p->hashNumAvail >= p->numHashBytes)\r\n        continue;\r\n      for (; p->hashNumAvail != 0; p->hashNumAvail--)\r\n        distances[curPos++] = 0;\r\n      break;\r\n    }\r\n    {\r\n      UInt32 size = p->hashBufPosLimit - p->hashBufPos;\r\n      UInt32 lenLimit = p->matchMaxLen;\r\n      UInt32 pos = p->pos;\r\n      UInt32 cyclicBufferPos = p->cyclicBufferPos;\r\n      if (lenLimit >= p->hashNumAvail)\r\n        lenLimit = p->hashNumAvail;\r\n      {\r\n        UInt32 size2 = p->hashNumAvail - lenLimit + 1;\r\n        if (size2 < size)\r\n          size = size2;\r\n        size2 = p->cyclicBufferSize - cyclicBufferPos;\r\n        if (size2 < size)\r\n          size = size2;\r\n      }\r\n      #ifndef MFMT_GM_INLINE\r\n      while (curPos < limit && size-- != 0)\r\n      {\r\n        UInt32 *startDistances = distances + curPos;\r\n        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++], \r\n          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, \r\n          startDistances + 1, p->numHashBytes - 1) - startDistances);\r\n        *startDistances = num - 1;\r\n        curPos += num;\r\n        cyclicBufferPos++;\r\n        pos++;\r\n        p->buffer++;\r\n      }\r\n      #else\r\n      {\r\n        UInt32 posRes;\r\n        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, \r\n          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);\r\n        p->hashBufPos += posRes - pos;\r\n        cyclicBufferPos += posRes - pos;\r\n        p->buffer += posRes - pos;\r\n        pos = posRes;\r\n      }\r\n      #endif\r\n\r\n      numProcessed += pos - p->pos;\r\n      p->hashNumAvail -= pos - p->pos;\r\n      p->pos = pos;\r\n      if (cyclicBufferPos == p->cyclicBufferSize)\r\n        cyclicBufferPos = 0;\r\n      p->cyclicBufferPos = cyclicBufferPos;\r\n    }\r\n  }\r\n  distances[0] = curPos;\r\n}\r\n\r\nvoid BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r\n{\r\n  CMtSync *sync = &p->hashSync;\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Enter(&sync->cs);\r\n    sync->csWasEntered = True;\r\n  }\r\n  \r\n  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);\r\n\r\n  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\r\n  {\r\n    UInt32 subValue = p->pos - p->cyclicBufferSize;\r\n    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);\r\n    p->pos -= subValue;\r\n  }\r\n\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Leave(&sync->cs);\r\n    sync->csWasEntered = False;\r\n  }\r\n}\r\n\r\nvoid BtThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->btSync;\r\n  for (;;)\r\n  {\r\n    UInt32 blockIndex = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = blockIndex;\r\n        MtSync_StopWriting(&mt->hashSync);\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n      Semaphore_Wait(&p->freeSemaphore);\r\n      BtFillBlock(mt, blockIndex++);\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p)\r\n{\r\n  p->hashBuf = 0;\r\n  MtSync_Construct(&p->hashSync);\r\n  MtSync_Construct(&p->btSync);\r\n}\r\n\r\nvoid MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(p->hashBuf);\r\n  p->hashBuf = 0;\r\n}\r\n\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  MtSync_Destruct(&p->hashSync);\r\n  MtSync_Destruct(&p->btSync);\r\n  MatchFinderMt_FreeMem(p, alloc);\r\n}\r\n\r\n#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\r\n#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\r\n\r\nstatic unsigned StdCall HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r\nstatic unsigned StdCall BtThreadFunc2(void *p) \r\n{ \r\n  #ifdef USE_ALLOCA\r\n  alloca(0x180);\r\n  #endif\r\n  BtThreadFunc((CMatchFinderMt *)p); \r\n  return 0; \r\n}\r\n\r\nHRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\r\n{ \r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->historySize = historySize;\r\n  if (kMtBtBlockSize <= matchMaxLen * 4)\r\n    return E_INVALIDARG;\r\n  if (p->hashBuf == 0)\r\n  {\r\n    p->hashBuf = (UInt32 *)alloc->Alloc((kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r\n    if (p->hashBuf == 0)\r\n      return SZE_OUTOFMEMORY;\r\n    p->btBuf = p->hashBuf + kHashBufferSize;\r\n  }\r\n  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);\r\n  keepAddBufferAfter += kMtHashBlockSize;\r\n  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));\r\n  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));\r\n  return SZ_OK;\r\n}\r\n\r\n/* Call it after ReleaseStream / SetStream */\r\nvoid MatchFinderMt_Init(CMatchFinderMt *p)\r\n{ \r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->btBufPos = p->btBufPosLimit = 0;\r\n  p->hashBufPos = p->hashBufPosLimit = 0;\r\n  MatchFinder_Init(mf);\r\n  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);\r\n  p->btNumAvailBytes = 0;\r\n  p->lzPos = p->historySize + 1;\r\n\r\n  p->hash = mf->hash;\r\n  p->fixedHashSize = mf->fixedHashSize;\r\n\r\n  p->son = mf->son;\r\n  p->matchMaxLen = mf->matchMaxLen;\r\n  p->numHashBytes = mf->numHashBytes;\r\n  p->pos = mf->pos;\r\n  p->buffer = mf->buffer;\r\n  p->cyclicBufferPos = mf->cyclicBufferPos;\r\n  p->cyclicBufferSize = mf->cyclicBufferSize;\r\n  p->cutValue = mf->cutValue;\r\n}\r\n\r\n/* ReleaseStream is required to finish multithreading */\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p)\r\n{ \r\n  MtSync_StopWriting(&p->btSync);\r\n  /* p->MatchFinder->ReleaseStream(); */\r\n}\r\n\r\nvoid MatchFinderMt_Normalize(CMatchFinderMt *p)\r\n{\r\n  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\r\n  p->lzPos = p->historySize + 1;\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r\n{\r\n  UInt32 blockIndex;\r\n  MtSync_GetNextBlock(&p->btSync);\r\n  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);\r\n  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;\r\n  p->btBufPosLimit += p->btBuf[p->btBufPos++];\r\n  p->btNumAvailBytes = p->btBuf[p->btBufPos++];\r\n  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize) \r\n    MatchFinderMt_Normalize(p);\r\n}\r\n\r\nconst Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r\n{\r\n  return p->pointerToCurPos;\r\n}\r\n\r\n#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\r\n\r\nUInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r\n{ \r\n  GET_NEXT_BLOCK_IF_REQUIRED;\r\n  return p->btNumAvailBytes;\r\n}\r\n\r\nByte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)\r\n{ \r\n  return p->pointerToCurPos[index]; \r\n}\r\n\r\nUInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, curMatch2;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos; \r\n  MT_HASH2_CALC\r\n      \r\n  curMatch2 = hash[hash2Value];\r\n  hash[hash2Value] = lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos) \r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n    {\r\n      *distances++ = 2; \r\n      *distances++ = lzPos - curMatch2 - 1;\r\n    }\r\n  return distances;\r\n}\r\n\r\nUInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos; \r\n  MT_HASH3_CALC\r\n\r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  \r\n  hash[                hash2Value] = \r\n  hash[kFix3HashSize + hash3Value] = \r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  { \r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] = 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2; \r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  { \r\n    *distances++ = 3; \r\n    *distances++ = lzPos - curMatch3 - 1; \r\n  }\r\n  return distances;\r\n}\r\n\r\n/*\r\nUInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos; \r\n  MT_HASH4_CALC\r\n      \r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  curMatch4 = hash[kFix4HashSize + hash4Value];\r\n  \r\n  hash[                hash2Value] = \r\n  hash[kFix3HashSize + hash3Value] = \r\n  hash[kFix4HashSize + hash4Value] = \r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch3 - 1;\r\n    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])\r\n    {\r\n      distances[0] = 4;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 3;\r\n    distances += 2;\r\n  }\r\n\r\n  if (curMatch4 >= matchMinPos)\r\n    if (\r\n      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&\r\n      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]\r\n      )\r\n    {\r\n      *distances++ = 4;\r\n      *distances++ = lzPos - curMatch4 - 1;\r\n    }\r\n  return distances;\r\n}\r\n*/\r\n\r\n#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\r\n\r\nUInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{ \r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n  p->btNumAvailBytes--;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < len; i += 2)\r\n    {\r\n      *distances++ = *btBuf++;\r\n      *distances++ = *btBuf++;\r\n    }\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\nUInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{ \r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n\r\n  if (len == 0)\r\n  {\r\n    if (p->btNumAvailBytes-- >= 4) \r\n      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\r\n  }\r\n  else\r\n  {\r\n    /* Condition: there are matches in btBuf with length < p->numHashBytes */\r\n    UInt32 *distances2;\r\n    p->btNumAvailBytes--;\r\n    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\r\n    do \r\n    {\r\n      *distances2++ = *btBuf++;\r\n      *distances2++ = *btBuf++;\r\n    }\r\n    while ((len -= 2) != 0);\r\n    len  = (UInt32)(distances2 - (distances));\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\n#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED\r\n#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r\n#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while(--num != 0);\r\n\r\nvoid MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER2 { p->btNumAvailBytes--;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER(2)\r\n      UInt32 hash2Value;\r\n      MT_HASH2_CALC\r\n      hash[hash2Value] = p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER(3)\r\n      UInt32 hash2Value, hash3Value;\r\n      MT_HASH3_CALC\r\n      hash[kFix3HashSize + hash3Value] = \r\n      hash[                hash2Value] = \r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\n/*\r\nvoid MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER(4)\r\n      UInt32 hash2Value, hash3Value, hash4Value;\r\n      MT_HASH4_CALC\r\n      hash[kFix4HashSize + hash4Value] = \r\n      hash[kFix3HashSize + hash3Value] = \r\n      hash[                hash2Value] = \r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n*/\r\n\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\r\n  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\r\n  switch(p->MatchFinder->numHashBytes)\r\n  {\r\n    case 2:\r\n      p->GetHeadsFunc = GetHeads2;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)0;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\r\n      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\r\n      break;\r\n    case 3:\r\n      p->GetHeadsFunc = GetHeads3;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;\r\n      break;\r\n    default:\r\n    /* case 4: */\r\n      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\r\n      /* p->GetHeadsFunc = GetHeads4; */\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\r\n      break;\r\n    /*\r\n    default:\r\n      p->GetHeadsFunc = GetHeads5;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;\r\n      break;\r\n    */\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lz/MatchFinderMt.h",
    "content": "/* MatchFinderMt.h */\r\n\r\n#ifndef __MATCHFINDERMT_H\r\n#define __MATCHFINDERMT_H\r\n\r\n#include \"../../Threads.h\"\r\n#include \"MatchFinder.h\"\r\n\r\n#define kMtHashBlockSize (1 << 13)\r\n#define kMtHashNumBlocks (1 << 3)\r\n#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)\r\n\r\n#define kMtBtBlockSize (1 << 14)\r\n#define kMtBtNumBlocks (1 << 6)\r\n#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)\r\n\r\ntypedef struct _CMtSync\r\n{\r\n  Bool wasCreated;\r\n  Bool needStart;\r\n  Bool exit;\r\n  Bool stopWriting;\r\n\r\n  CThread thread;\r\n  CAutoResetEvent canStart;\r\n  CAutoResetEvent wasStarted;\r\n  CAutoResetEvent wasStopped;\r\n  CSemaphore freeSemaphore;\r\n  CSemaphore filledSemaphore;\r\n  Bool csWasInitialized;\r\n  Bool csWasEntered;\r\n  CCriticalSection cs;\r\n  UInt32 numProcessedBlocks;\r\n} CMtSync;\r\n\r\ntypedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);\r\n\r\n/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */\r\n#define kMtCacheLineDummy 128\r\n\r\ntypedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,\r\n  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads);\r\n\r\ntypedef struct _CMatchFinderMt\r\n{\r\n  /* LZ */\r\n  const Byte *pointerToCurPos;\r\n  UInt32 *btBuf;\r\n  UInt32 btBufPos;\r\n  UInt32 btBufPosLimit;\r\n  UInt32 lzPos;\r\n  UInt32 btNumAvailBytes;\r\n\r\n  UInt32 *hash;\r\n  UInt32 fixedHashSize;\r\n  UInt32 historySize;\r\n\r\n  Mf_Mix_Matches MixMatchesFunc;\r\n  \r\n  /* LZ + BT */\r\n  CMtSync btSync;\r\n  Byte btDummy[kMtCacheLineDummy];\r\n\r\n  /* BT */\r\n  UInt32 *hashBuf;\r\n  UInt32 hashBufPos;\r\n  UInt32 hashBufPosLimit;\r\n  UInt32 hashNumAvail;\r\n\r\n  CLzRef *son;\r\n  UInt32 matchMaxLen;\r\n  UInt32 numHashBytes;\r\n  UInt32 pos;\r\n  Byte *buffer;\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be historySize + 1 */\r\n  UInt32 cutValue;\r\n\r\n  /* BT + Hash */\r\n  CMtSync hashSync;\r\n  /* Byte hashDummy[kMtCacheLineDummy]; */\r\n  \r\n  /* Hash */\r\n  Mf_GetHeads GetHeadsFunc;\r\n  CMatchFinder *MatchFinder;\r\n} CMatchFinderMt;\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p);\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);\r\nHRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/LzmaDecode.c",
    "content": "/*\r\n  LzmaDecode.c\r\n  LZMA Decoder (optimized for Speed version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) \\\r\n  { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \\\r\n  BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}\r\n\r\n#define RC_INIT Buffer = BufferLim = 0; RC_INIT2\r\n\r\n#else\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#endif\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  const Byte *Buffer = vs->Buffer;\r\n  const Byte *BufferLim = vs->BufferLim;\r\n  #else\r\n  const Byte *Buffer = inStream;\r\n  const Byte *BufferLim = inStream + inSize;\r\n  #endif\r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      #ifdef _LZMA_IN_CB\r\n      RC_INIT;\r\n      #else\r\n      RC_INIT(inStream, inSize);\r\n      #endif\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  RC_INIT;\r\n  #else\r\n  RC_INIT(inStream, inSize);\r\n  #endif\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (Byte)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n            UpdateBit0(prob);\r\n            \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            \r\n            state = state < kNumLitStates ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = Buffer;\r\n  vs->BufferLim = BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/LzmaDecode.h",
    "content": "/* \r\n  LzmaDecode.h\r\n  LZMA Decoder interface\r\n\r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMADECODE_H\r\n#define __LZMADECODE_H\r\n\r\n#include \"LzmaTypes.h\"\r\n\r\n/* #define _LZMA_IN_CB */\r\n/* Use callback for input data */\r\n\r\n/* #define _LZMA_OUT_READ */\r\n/* Use read function for output data */\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_LOC_OPT */\r\n/* Enable local speed optimizations inside code */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#ifdef _LZMA_IN_CB\r\ntypedef struct _ILzmaInCallback\r\n{\r\n  int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);\r\n} ILzmaInCallback;\r\n#endif\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  #ifdef _LZMA_OUT_READ\r\n  UInt32 DictionarySize;\r\n  #endif\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  const unsigned char *Buffer;\r\n  const unsigned char *BufferLim;\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  unsigned char *Dictionary;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;\r\n  unsigned char TempDictionary[4];\r\n  #endif\r\n} CLzmaDecoderState;\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }\r\n#endif\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *inCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/LzmaDecodeSize.c",
    "content": "/*\r\n  LzmaDecodeSize.c\r\n  LZMA Decoder (optimized for Size version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\ntypedef struct _CRangeDecoder\r\n{\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  #ifdef _LZMA_IN_CB\r\n  ILzmaInCallback *InCallback;\r\n  int Result;\r\n  #endif\r\n  int ExtraBytes;\r\n} CRangeDecoder;\r\n\r\nByte RangeDecoderReadByte(CRangeDecoder *rd)\r\n{\r\n  if (rd->Buffer == rd->BufferLim)\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    SizeT size;\r\n    rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);\r\n    rd->BufferLim = rd->Buffer + size;\r\n    if (size == 0)\r\n    #endif\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n  }\r\n  return (*rd->Buffer++);\r\n}\r\n\r\n/* #define ReadByte (*rd->Buffer++) */\r\n#define ReadByte (RangeDecoderReadByte(rd))\r\n\r\nvoid RangeDecoderInit(CRangeDecoder *rd\r\n  #ifndef _LZMA_IN_CB\r\n    , const Byte *stream, SizeT bufferSize\r\n  #endif\r\n    )\r\n{\r\n  int i;\r\n  #ifdef _LZMA_IN_CB\r\n  rd->Buffer = rd->BufferLim = 0;\r\n  #else\r\n  rd->Buffer = stream;\r\n  rd->BufferLim = stream + bufferSize;\r\n  #endif\r\n  rd->ExtraBytes = 0;\r\n  rd->Code = 0;\r\n  rd->Range = (0xFFFFFFFF);\r\n  for(i = 0; i < 5; i++)\r\n    rd->Code = (rd->Code << 8) | ReadByte;\r\n}\r\n\r\n#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;        \r\n#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;\r\n#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }\r\n\r\nUInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)\r\n{\r\n  RC_INIT_VAR\r\n  UInt32 result = 0;\r\n  int i;\r\n  for (i = numTotalBits; i != 0; i--)\r\n  {\r\n    /* UInt32 t; */\r\n    range >>= 1;\r\n\r\n    result <<= 1;\r\n    if (code >= range)\r\n    {\r\n      code -= range;\r\n      result |= 1;\r\n    }\r\n    /*\r\n    t = (code - range) >> 31;\r\n    t &= 1;\r\n    code -= range & (t - 1);\r\n    result = (result + result) | (1 - t);\r\n    */\r\n    RC_NORMALIZE\r\n  }\r\n  RC_FLUSH_VAR\r\n  return result;\r\n}\r\n\r\nint RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)\r\n{\r\n  UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;\r\n  if (rd->Code < bound)\r\n  {\r\n    rd->Range = bound;\r\n    *prob += (kBitModelTotal - *prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 0;\r\n  }\r\n  else\r\n  {\r\n    rd->Range -= bound;\r\n    rd->Code -= bound;\r\n    *prob -= (*prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 1;\r\n  }\r\n}\r\n\r\n#define RC_GET_BIT2(prob, mi, A0, A1) \\\r\n  UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \\\r\n  if (code < bound) \\\r\n    { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \\\r\n  else \\\r\n    { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)               \r\n\r\nint RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = numLevels; i != 0; i--)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT(prob, mi)\r\n    #else\r\n    mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return mi - (1 << numLevels);\r\n}\r\n\r\nint RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  int symbol = 0;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = 0; i < numLevels; i++)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))\r\n    #else\r\n    int bit = RangeDecoderBitDecode(probs + mi, rd);\r\n    mi = mi + mi + bit;\r\n    symbol |= (bit << i);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + symbol;\r\n    RC_GET_BIT(prob, symbol)\r\n    #else\r\n    symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n    #endif\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    int bit;\r\n    int matchBit = (matchByte >> 7) & 1;\r\n    matchByte <<= 1;\r\n    #ifdef _LZMA_LOC_OPT\r\n    {\r\n      CProb *prob = probs + 0x100 + (matchBit << 8) + symbol;\r\n      RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)\r\n    }\r\n    #else\r\n    bit = RangeDecoderBitDecode(probs + 0x100 + (matchBit << 8) + symbol, rd);\r\n    symbol = (symbol << 1) | bit;\r\n    #endif\r\n    if (matchBit != bit)\r\n    {\r\n      while (symbol < 0x100)\r\n      {\r\n        #ifdef _LZMA_LOC_OPT\r\n        CProb *prob = probs + symbol;\r\n        RC_GET_BIT(prob, symbol)\r\n        #else\r\n        symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n        #endif\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\nint LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)\r\n{\r\n  if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)\r\n    return RangeDecoderBitTreeDecode(p + LenLow +\r\n        (posState << kLenNumLowBits), kLenNumLowBits, rd);\r\n  if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)\r\n    return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +\r\n        (posState << kLenNumMidBits), kLenNumMidBits, rd);\r\n  return kLenNumLowSymbols + kLenNumMidSymbols + \r\n      RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);\r\n}\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  CRangeDecoder rd;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  rd.Range = vs->Range;\r\n  rd.Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  rd.Buffer = vs->Buffer;\r\n  rd.BufferLim = vs->BufferLim;\r\n  #else\r\n  rd.Buffer = inStream;\r\n  rd.BufferLim = inStream + inSize;\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RangeDecoderInit(&rd\r\n          #ifndef _LZMA_IN_CB\r\n          , inStream, inSize\r\n          #endif\r\n          );\r\n      #ifdef _LZMA_IN_CB\r\n      if (rd.Result != LZMA_RESULT_OK)\r\n        return rd.Result;\r\n      #endif\r\n      if (rd.ExtraBytes != 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  rd.Result = LZMA_RESULT_OK;\r\n  #endif\r\n  rd.ExtraBytes = 0;\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  #endif\r\n  RangeDecoderInit(&rd\r\n      #ifndef _LZMA_IN_CB\r\n      , inStream, inSize\r\n      #endif\r\n      );\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  if (rd.Result != LZMA_RESULT_OK)\r\n    return rd.Result;\r\n  #endif\r\n  if (rd.ExtraBytes != 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n    #ifdef _LZMA_IN_CB\r\n    if (rd.Result != LZMA_RESULT_OK)\r\n      return rd.Result;\r\n    #endif\r\n    if (rd.ExtraBytes != 0)\r\n      return LZMA_RESULT_DATA_ERROR;\r\n    if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n    {\r\n      CProb *probs = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        Byte matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);\r\n      }\r\n      else\r\n        previousByte = LzmaLiteralDecode(probs, &rd);\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)\r\n      {\r\n        if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)\r\n        {\r\n          if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n      \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n\r\n            state = state < 7 ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n            continue;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)\r\n            distance = rep1;\r\n          else \r\n          {\r\n            if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)\r\n              distance = rep2;\r\n            else\r\n            {\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        len = LzmaLenDecode(p + RepLenCoder, &rd, posState);\r\n        state = state < 7 ? 8 : 11;\r\n      }\r\n      else\r\n      {\r\n        int posSlot;\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < 7 ? 7 : 10;\r\n        len = LzmaLenDecode(p + LenCoder, &rd, posState);\r\n        posSlot = RangeDecoderBitTreeDecode(p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits), kNumPosSlotBits, &rd);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 += RangeDecoderReverseBitTreeDecode(\r\n                p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);\r\n          }\r\n          else\r\n          {\r\n            rep0 += RangeDecoderDecodeDirectBits(&rd, \r\n                numDirectBits - kNumAlignBits) << kNumAlignBits;\r\n            rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = rd.Range;\r\n  vs->Code = rd.Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = rd.Buffer;\r\n  vs->BufferLim = rd.BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(rd.Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/LzmaStateDecode.c",
    "content": "/*\r\n  LzmaStateDecode.c\r\n  LZMA Decoder (State version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\n/* kRequiredInBufferSize = number of required input bytes for worst case: \r\n   longest match with longest distance.\r\n   kLzmaInBufferSize must be larger than kRequiredInBufferSize \r\n   23 bits = 2 (match select) + 10 (len) + 6 (distance) + 4(align) + 1 (RC_NORMALIZE)\r\n*/\r\n\r\n#define kRequiredInBufferSize ((23 * (kNumBitModelTotalBits - kNumMoveBits + 1) + 26 + 9) / 8)\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n    return LZMA_RESULT_OK;\r\n  }\r\n}\r\n\r\nint LzmaDecode(\r\n    CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding)\r\n{\r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n\r\n  unsigned char *Buffer = vs->Buffer;\r\n  int BufferSize = vs->BufferSize; /* don't change it to unsigned int */\r\n  CProb *p = vs->Probs;\r\n\r\n  int state = vs->State;\r\n  unsigned char previousByte;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  SizeT nowPos = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  unsigned char *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  unsigned char tempDictionary[4];\r\n\r\n  (*inSizeProcessed) = 0;\r\n  (*outSizeProcessed) = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n    {\r\n      Buffer[BufferSize++] = *inStream++;\r\n      (*inSizeProcessed)++;\r\n      inSize--;\r\n    }\r\n    if (BufferSize < 5)\r\n    {\r\n      vs->BufferSize = BufferSize;\r\n      return finishDecoding ? LZMA_RESULT_DATA_ERROR : LZMA_RESULT_OK;\r\n    }\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RC_INIT;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  for (;;)\r\n  {\r\n    int bufferPos = (int)(Buffer - vs->Buffer);\r\n    if (BufferSize - bufferPos < kRequiredInBufferSize)\r\n    {\r\n      int i;\r\n      BufferSize -= bufferPos;\r\n      if (BufferSize < 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n      for (i = 0; i < BufferSize; i++)\r\n        vs->Buffer[i] = Buffer[i];\r\n      Buffer = vs->Buffer;\r\n      while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n      {\r\n        Buffer[BufferSize++] = *inStream++;\r\n        (*inSizeProcessed)++;\r\n        inSize--;\r\n      }\r\n      if (BufferSize < kRequiredInBufferSize && !finishDecoding)\r\n        break;\r\n    }\r\n    if (nowPos >= outSize)\r\n      break;\r\n    {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)((nowPos + globalPos) & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        ((((nowPos + globalPos)& literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (unsigned char)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            UInt32 pos;\r\n            UpdateBit0(prob);\r\n            if (distanceLimit == 0)\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            outStream[nowPos++] = previousByte;\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      if (rep0 > distanceLimit) \r\n        return LZMA_RESULT_DATA_ERROR;\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n\r\n      do\r\n      {\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  BufferSize -= (int)(Buffer - vs->Buffer);\r\n  if (BufferSize < 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    int i;\r\n    for (i = 0; i < BufferSize; i++)\r\n      vs->Buffer[i] = Buffer[i];\r\n  }\r\n  vs->BufferSize = BufferSize;\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = (UInt32)(globalPos + nowPos);\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n\r\n  (*outSizeProcessed) = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/LzmaStateDecode.h",
    "content": "/* \r\n  LzmaStateDecode.h\r\n  LZMA Decoder interface (State version)\r\n\r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMASTATEDECODE_H\r\n#define __LZMASTATEDECODE_H\r\n\r\n#include \"LzmaTypes.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  UInt32 DictionarySize;\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))\r\n\r\n#define kLzmaInBufferSize 64   /* don't change it. it must be larger than kRequiredInBufferSize */\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n  unsigned char *Dictionary;\r\n\r\n  unsigned char Buffer[kLzmaInBufferSize];\r\n  int BufferSize;\r\n\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;  /* -2: decoder needs internal initialization\r\n                     -1: stream was finished, \r\n                      0: ok\r\n                    > 0: need to write RemainLen bytes as match Reps[0],\r\n                  */\r\n  unsigned char TempDictionary[4];  /* it's required when DictionarySize = 0 */\r\n} CLzmaDecoderState;\r\n\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }\r\n\r\n/* LzmaDecode: decoding from input stream to output stream.\r\n  If finishDecoding != 0, then there are no more bytes in input stream\r\n  after inStream[inSize - 1]. */\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize,  SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/LzmaStateTest.c",
    "content": "/* \r\nLzmaStateTest.c\r\nTest application for LZMA Decoder (State version)\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\n#define kInBufferSize (1 << 15)\r\n#define kOutBufferSize (1 << 15)\r\n\r\nunsigned char g_InBuffer[kInBufferSize];\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n  { return fread(data, 1, size, file); }\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size); }\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0; \r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  int i;\r\n  int res = 0;\r\n  CLzmaDecoderState state;  /* it's about 140 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n  SizeT inAvail = 0;\r\n  unsigned char *inBuffer = 0;\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n  \r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    unsigned char b;\r\n    if (!MyReadFileAndCheck(inFile, &b, 1))\r\n      return PrintError(rs, kCantReadMessage);\r\n    if (b != 0xFF)\r\n      waitEOS = 0;\r\n    if (i < 4)\r\n      outSize += (UInt32)(b) << (i * 8);\r\n    else\r\n      outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  \r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      free(state.Probs);\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    }\r\n  }\r\n  \r\n  /* Decompress */\r\n  \r\n  LzmaDecoderInit(&state);\r\n  \r\n  do\r\n  {\r\n    SizeT inProcessed, outProcessed;\r\n    int finishDecoding;\r\n    UInt32 outAvail = kOutBufferSize;\r\n    if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n      outAvail = outSize;\r\n    if (inAvail == 0)\r\n    {\r\n      inAvail = (SizeT)MyReadFile(inFile, g_InBuffer, kInBufferSize);\r\n      inBuffer = g_InBuffer;\r\n    }\r\n    finishDecoding = (inAvail == 0);\r\n    res = LzmaDecode(&state,\r\n        inBuffer, inAvail, &inProcessed,\r\n        g_OutBuffer, outAvail, &outProcessed,\r\n        finishDecoding);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n      break;\r\n    }\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n    \r\n    if (outFile != 0)  \r\n      if (fwrite(g_OutBuffer, 1, outProcessed, outFile) != outProcessed)\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n        break;\r\n      }\r\n      \r\n    if (outSize < outProcessed)\r\n      outSizeHigh--;\r\n    outSize -= (UInt32)outProcessed;\r\n    outSize &= 0xFFFFFFFF;\r\n\r\n    if (outProcessed == 0 && finishDecoding)\r\n    {\r\n      if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n        res = 1;\r\n      break;\r\n    }\r\n  }\r\n  while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n\r\n  free(state.Dictionary);\r\n  free(state.Probs);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-02\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/LzmaTest.c",
    "content": "/* \r\nLzmaTest.c\r\nTest application for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-05)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fread(data, 1, size, file); \r\n}\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size);} \r\n\r\nsize_t MyWriteFile(FILE *file, const void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fwrite(data, 1, size, file); \r\n}\r\n\r\nint MyWriteFileAndCheck(FILE *file, const void *data, size_t size)\r\n  { return (MyWriteFile(file, data, size) == size); }\r\n\r\n#ifdef _LZMA_IN_CB\r\n#define kInBufferSize (1 << 15)\r\ntypedef struct _CBuffer\r\n{\r\n  ILzmaInCallback InCallback;\r\n  FILE *File;\r\n  unsigned char Buffer[kInBufferSize];\r\n} CBuffer;\r\n\r\nint LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CBuffer *b = (CBuffer *)object;\r\n  *buffer = b->Buffer;\r\n  *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);\r\n  return LZMA_RESULT_OK;\r\n}\r\nCBuffer g_InBuffer;\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define kOutBufferSize (1 << 15)\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n#endif\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0;\r\n  #ifndef _LZMA_OUT_READ\r\n  SizeT outSizeFull;\r\n  unsigned char *outStream;\r\n  #endif\r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  SizeT compressedSize;\r\n  unsigned char *inStream;\r\n  #endif\r\n\r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n  int res;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.File = inFile;\r\n  #endif\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  {\r\n    long length;\r\n    fseek(inFile, 0, SEEK_END);\r\n    length = ftell(inFile);\r\n    fseek(inFile, 0, SEEK_SET);\r\n    if ((long)(SizeT)length != length)\r\n      return PrintError(rs, \"Too big compressed stream\");\r\n    compressedSize = (SizeT)(length - (LZMA_PROPERTIES_SIZE + 8));\r\n  }\r\n  #endif\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n\r\n  {\r\n    int i;\r\n    for (i = 0; i < 8; i++)\r\n    {\r\n      unsigned char b;\r\n      if (!MyReadFileAndCheck(inFile, &b, 1))\r\n        return PrintError(rs, kCantReadMessage);\r\n      if (b != 0xFF)\r\n        waitEOS = 0;\r\n      if (i < 4)\r\n        outSize += (UInt32)(b) << (i * 8);\r\n      else\r\n        outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n    }\r\n    \r\n    #ifndef _LZMA_OUT_READ\r\n    if (waitEOS)\r\n      return PrintError(rs, \"Stream with EOS marker is not supported\");\r\n    outSizeFull = (SizeT)outSize;\r\n    if (sizeof(SizeT) >= 8)\r\n      outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);\r\n    else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)\r\n      return PrintError(rs, \"Too big uncompressed stream\");\r\n    #endif\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n  #else\r\n  if (outSizeFull == 0)\r\n    outStream = 0;\r\n  else\r\n    outStream = (unsigned char *)malloc(outSizeFull);\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  if (compressedSize == 0)\r\n    inStream = 0;\r\n  else\r\n    inStream = (unsigned char *)malloc(compressedSize);\r\n  #endif\r\n\r\n  if (state.Probs == 0 \r\n    #ifdef _LZMA_OUT_READ\r\n    || (state.Dictionary == 0 && state.Properties.DictionarySize != 0)\r\n    #else\r\n    || (outStream == 0 && outSizeFull != 0)\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    || (inStream == 0 && compressedSize != 0)\r\n    #endif\r\n    )\r\n  {\r\n    free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    free(state.Dictionary);\r\n    #else\r\n    free(outStream);\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    free(inStream);\r\n    #endif\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  }\r\n\r\n  /* Decompress */\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  #else\r\n  if (!MyReadFileAndCheck(inFile, inStream, compressedSize))\r\n    return PrintError(rs, kCantReadMessage);\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inAvail = compressedSize;\r\n    const unsigned char *inBuffer = inStream;\r\n    #endif\r\n    LzmaDecoderInit(&state);\r\n    do\r\n    {\r\n      #ifndef _LZMA_IN_CB\r\n      SizeT inProcessed;\r\n      #endif\r\n      SizeT outProcessed;\r\n      SizeT outAvail = kOutBufferSize;\r\n      if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n        outAvail = (SizeT)outSize;\r\n      res = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &g_InBuffer.InCallback,\r\n        #else\r\n        inBuffer, inAvail, &inProcessed,\r\n        #endif\r\n        g_OutBuffer, outAvail, &outProcessed);\r\n      if (res != 0)\r\n      {\r\n        sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n        res = 1;\r\n        break;\r\n      }\r\n      #ifndef _LZMA_IN_CB\r\n      inAvail -= inProcessed;\r\n      inBuffer += inProcessed;\r\n      #endif\r\n      \r\n      if (outFile != 0)  \r\n        if (!MyWriteFileAndCheck(outFile, g_OutBuffer, (size_t)outProcessed))\r\n        {\r\n          PrintError(rs, kCantWriteMessage);\r\n          res = 1;\r\n          break;\r\n        }\r\n        \r\n      if (outSize < outProcessed)\r\n        outSizeHigh--;\r\n      outSize -= (UInt32)outProcessed;\r\n      outSize &= 0xFFFFFFFF;\r\n        \r\n      if (outProcessed == 0)\r\n      {\r\n        if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n          res = 1;\r\n        break;\r\n      }\r\n    }\r\n    while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n  }\r\n\r\n  #else\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inProcessed;\r\n    #endif\r\n    SizeT outProcessed;\r\n    res = LzmaDecode(&state,\r\n      #ifdef _LZMA_IN_CB\r\n      &g_InBuffer.InCallback,\r\n      #else\r\n      inStream, compressedSize, &inProcessed,\r\n      #endif\r\n      outStream, outSizeFull, &outProcessed);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n    }\r\n    else if (outFile != 0)\r\n    {\r\n      if (!MyWriteFileAndCheck(outFile, outStream, (size_t)outProcessed))\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  free(state.Dictionary);\r\n  #else\r\n  free(outStream);\r\n  #endif\r\n  #ifndef _LZMA_IN_CB\r\n  free(inStream);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-05\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/LzmaTypes.h",
    "content": "/* \r\nLzmaTypes.h \r\n\r\nTypes for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.40 (2006-05-01)\r\n*/\r\n\r\n#ifndef __LZMATYPES_H\r\n#define __LZMATYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif \r\n\r\n/* #define _LZMA_NO_SYSTEM_SIZE_T */\r\n/* You can use it, if you don't want <stddef.h> */\r\n\r\n#ifndef _7ZIP_SIZET_DEFINED\r\n#define _7ZIP_SIZET_DEFINED\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\n#include <stddef.h>\r\ntypedef size_t SizeT;\r\n#endif\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/kmod/uncomp.c",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $ */\n\n/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */\n\n#ifndef __KERNEL__\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <assert.h>\n#include <pthread.h>\n#define unlikely(x)\t\t__builtin_expect(!!(x), 0)\n#define BUG_ON(x)\t\tassert(!(x))\n/* sqlzma buffers are always larger than a page. true? */\n#define kmalloc(sz,gfp)\t\tmalloc(sz)\n#define kfree(p)\t\tfree(p)\n#define zlib_inflate(s, f)\tinflate(s, f)\n#define zlib_inflateInit(s)\tinflateInit(s)\n#define zlib_inflateReset(s)\tinflateReset(s)\n#define zlib_inflateEnd(s)\tinflateEnd(s)\n#else\n#include <linux/init.h>\n#include <linux/module.h>\n#include <linux/kernel.h>\n#include <linux/vmalloc.h>\n#ifndef WARN_ON_ONCE\n#define WARN_ON_ONCE(b)\tWARN_ON(b)\n#endif\n#endif /* __KERNEL__ */\n\n#include \"sqlzma.h\"\n#include \"LzmaDecode.h\"\n\nstatic int LzmaUncompress(struct sqlzma_un *un)\n{\n\tint err, i, ret;\n\tSizeT outSize, inProcessed, outProcessed, srclen;\n\t/* it's about 24-80 bytes structure, if int is 32-bit */\n\tCLzmaDecoderState state;\n\tunsigned char *dst, *src, a[8];\n\tstruct sized_buf *sbuf;\n\n\t/* Decode LZMA properties and allocate memory */\n\terr = -EINVAL;\n\tsrc = (void *)un->un_cmbuf;\n\tret = LzmaDecodeProperties(&state.Properties, src,\n\t\t\t\t   LZMA_PROPERTIES_SIZE);\n\tsrc += LZMA_PROPERTIES_SIZE;\n\tif (unlikely(ret != LZMA_RESULT_OK))\n\t\tgoto out;\n\ti = LzmaGetNumProbs(&state.Properties);\n\tif (unlikely(i <= 0))\n\t\ti = 1;\n\ti *= sizeof(CProb);\n\tsbuf = un->un_a + SQUN_PROB;\n\tif (unlikely(sbuf->sz < i)) {\n\t\tif (sbuf->buf && sbuf->buf != un->un_prob)\n\t\t\tkfree(sbuf->buf);\n#ifdef __KERNEL__\n\t\tprintk(\"%s:%d: %d --> %d\\n\", __func__, __LINE__, sbuf->sz, i);\n#else\n\t\tprintf(\"%d --> %d\\n\", sbuf->sz, i);\n#endif\n\t\terr = -ENOMEM;\n\t\tsbuf->sz = 0;\n\t\tsbuf->buf = kmalloc(i, GFP_ATOMIC);\n\t\tif (unlikely(!sbuf->buf))\n\t\t\tgoto out;\n\t\tsbuf->sz = i;\n\t}\n\tstate.Probs = (void *)sbuf->buf;\n\n\t/* Read uncompressed size */\n\tmemcpy(a, src, sizeof(a));\n\tsrc += sizeof(a);\n\toutSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);\n\n\terr = -EINVAL;\n\tdst = un->un_resbuf;\n\tif (unlikely(!dst || outSize > un->un_reslen))\n\t\tgoto out;\n\tun->un_reslen = outSize;\n\tsrclen = un->un_cmlen - (src - un->un_cmbuf);\n\n\t/* Decompress */\n\terr = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,\n\t\t\t &outProcessed);\n\tif (unlikely(err))\n\t\terr = -EINVAL;\n\n out:\n#ifndef __KERNEL__\n\tif (err)\n\t\tfprintf(stderr, \"err %d\\n\", err);\n#endif\n\treturn err;\n}\n\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst)\n{\n\tint err, by_lzma = 1;\n\tif (un->un_lzma && is_lzma(*src->buf)) {\n\t\tun->un_cmbuf = src->buf;\n\t\tun->un_cmlen = src->sz;\n\t\tun->un_resbuf = dst->buf;\n\t\tun->un_reslen = dst->sz;\n\n\t\t/* this library is thread-safe */\n\t\terr = LzmaUncompress(un);\n\t\tgoto out;\n\t}\n\n\tby_lzma = 0;\n\terr = zlib_inflateReset(&un->un_stream);\n\tif (unlikely(err != Z_OK))\n\t\tgoto out;\n\tun->un_stream.next_in = src->buf;\n\tun->un_stream.avail_in = src->sz;\n\tun->un_stream.next_out = dst->buf;\n\tun->un_stream.avail_out = dst->sz;\n\terr = zlib_inflate(&un->un_stream, Z_FINISH);\n\tif (err == Z_STREAM_END)\n\t\terr = 0;\n\n out:\n\tif (unlikely(err)) {\n#ifdef __KERNEL__\n\t\tWARN_ON_ONCE(1);\n#else\n\t\tchar a[64] = \"ZLIB \";\n\t\tif (by_lzma) {\n\t\t\tstrcpy(a, \"LZMA \");\n#ifdef _REENTRANT\n\t\t\tstrerror_r(err, a + 5, sizeof(a) - 5);\n#else\n\t\t\tstrncat(a, strerror(err), sizeof(a) - 5);\n#endif\n\t\t} else\n\t\t\tstrncat(a, zError(err), sizeof(a) - 5);\n\t\tfprintf(stderr, \"%s: %.*s\\n\", __func__, sizeof(a), a);\n#endif\n\t}\n\treturn err;\n}\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)\n{\n\tint err;\n\n\terr = -ENOMEM;\n\tun->un_lzma = do_lzma;\n\tmemset(un->un_a, 0, sizeof(un->un_a));\n\tun->un_a[SQUN_PROB].buf = un->un_prob;\n\tun->un_a[SQUN_PROB].sz = sizeof(un->un_prob);\n\tif (res_sz) {\n\t\tun->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);\n\t\tif (unlikely(!un->un_a[SQUN_RESULT].buf))\n\t\t\treturn err;\n\t\tun->un_a[SQUN_RESULT].sz = res_sz;\n\t}\n\n\tun->un_stream.next_in = NULL;\n\tun->un_stream.avail_in = 0;\n#ifdef __KERNEL__\n\tun->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(),\n\t\t\t\t\t  GFP_KERNEL);\n\tif (unlikely(!un->un_stream.workspace))\n\t\treturn err;\n#else\n\tun->un_stream.opaque = NULL;\n\tun->un_stream.zalloc = Z_NULL;\n\tun->un_stream.zfree = Z_NULL;\n#endif\n\terr = zlib_inflateInit(&un->un_stream);\n\tif (unlikely(err == Z_MEM_ERROR))\n\t\treturn -ENOMEM;\n\tBUG_ON(err);\n\treturn err;\n}\n\nvoid sqlzma_fin(struct sqlzma_un *un)\n{\n\tint i;\n\tfor (i = 0; i < SQUN_LAST; i++)\n\t\tif (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)\n\t\t\tkfree(un->un_a[i].buf);\n\tBUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);\n}\n\n#ifdef __KERNEL__\nEXPORT_SYMBOL(sqlzma_un);\nEXPORT_SYMBOL(sqlzma_init);\nEXPORT_SYMBOL(sqlzma_fin);\n\n#if 0\nstatic int __init sqlzma_init(void)\n{\n\treturn 0;\n}\n\nstatic void __exit sqlzma_exit(void)\n{\n}\n\nmodule_init(sqlzma_init);\nmodule_exit(sqlzma_exit);\n#endif\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Junjiro Okajima <sfjro at users dot sf dot net>\");\nMODULE_VERSION(\"$Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $\");\nMODULE_DESCRIPTION(\"LZMA uncompress for squashfs. \"\n\t\t   \"Some functions for squashfs to support LZMA and \"\n\t\t   \"a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/kmod.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: kmod.mk,v 1.1 2007-11-05 05:43:35 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\nifndef KDir\n$(error KDir is not defined)\nendif\n\n#include makefile.gcc\n\nKmod = kmod\nEXTRA_CFLAGS += -Wall -Werror -I${CURDIR} -I${Sqlzma}\n# -D_LZMA_PROB32\nEXTRA_CFLAGS += $(shell ${CPP} ${CFLAGS} -P testflags.c)\n\nall: ${Kmod}/uncomp.c\n\t${MAKE} EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\" M=${CURDIR}/${Kmod} \\\n\t\t-C ${KDir} C=0 V=0 modules\n\n${Kmod}/uncomp.c: uncomp.c\n\tln $< $@\n\nclean: clean_kmod\nclean_kmod:\n\t${MAKE} -C ${KDir} M=${CURDIR}/${Kmod} V=0 clean\n\t${RM} ${Kmod}/*~\n\t-@test -e ${Kmod}/uncomp.c && \\\n\t\tdiff -q ${Kmod}/uncomp.c uncomp.c > /dev/null && \\\n\t\tfind ${Kmod}/uncomp.c -links +1 | xargs -r ${RM}\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. KDir=/lib/modules/`uname -r`/build -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/sqlzma.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\n#include makefile.gcc\nCFLAGS = -c -O2 -Wall -pedantic -D _LZMA_PROB32\n\nifdef KDir\ninclude kmod.mk\nendif\n\nifdef UseDebugFlags\nDebugFlags = -O0 -g -UNDEBUG\nendif\nCFLAGS += -DNDEBUG ${DebugFlags}\nTgt = libunlzma.a libunlzma_r.a\n\nall: ${Tgt}\n\n%_r.c: %.c\n\tln $< $@\n# -pthread\n%_r.o: CFLAGS += -D_REENTRANT -include pthread.h\n\nuncomp.o uncomp_r.o: CFLAGS += -I${Sqlzma}\nuncomp.o: uncomp.c ${Sqlzma}/sqlzma.h\n\nlibunlzma.a: uncomp.o LzmaDecode.o\n\t${AR} cr $@ $^\nlibunlzma_r.a: uncomp_r.o LzmaDecode_r.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) ${Tgt} uncomp.o uncomp_r.o LzmaDecode_r.o LzmaDecode.o  *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/testflags.c",
    "content": "#ifdef _LZMA_PROB32\n-D_LZMA_PROB32\n#else\n-U_LZMA_PROB32\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Compress/Lzma/uncomp.c",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $ */\n\n/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */\n\n#ifndef __KERNEL__\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <assert.h>\n#include <pthread.h>\n#define unlikely(x)\t\t__builtin_expect(!!(x), 0)\n#define BUG_ON(x)\t\tassert(!(x))\n/* sqlzma buffers are always larger than a page. true? */\n#define kmalloc(sz,gfp)\t\tmalloc(sz)\n#define kfree(p)\t\tfree(p)\n#define zlib_inflate(s, f)\tinflate(s, f)\n#define zlib_inflateInit(s)\tinflateInit(s)\n#define zlib_inflateReset(s)\tinflateReset(s)\n#define zlib_inflateEnd(s)\tinflateEnd(s)\n#else\n#include <linux/init.h>\n#include <linux/module.h>\n#include <linux/kernel.h>\n#include <linux/vmalloc.h>\n#ifndef WARN_ON_ONCE\n#define WARN_ON_ONCE(b)\tWARN_ON(b)\n#endif\n#endif /* __KERNEL__ */\n\n#include \"sqlzma.h\"\n#include \"LzmaDecode.h\"\n\nstatic int LzmaUncompress(struct sqlzma_un *un)\n{\n\tint err, i, ret;\n\tSizeT outSize, inProcessed, outProcessed, srclen;\n\t/* it's about 24-80 bytes structure, if int is 32-bit */\n\tCLzmaDecoderState state;\n\tunsigned char *dst, *src, a[8];\n\tstruct sized_buf *sbuf;\n\n\t/* Decode LZMA properties and allocate memory */\n\terr = -EINVAL;\n\tsrc = (void *)un->un_cmbuf;\n\tret = LzmaDecodeProperties(&state.Properties, src,\n\t\t\t\t   LZMA_PROPERTIES_SIZE);\n\tsrc += LZMA_PROPERTIES_SIZE;\n\tif (unlikely(ret != LZMA_RESULT_OK))\n\t\tgoto out;\n\ti = LzmaGetNumProbs(&state.Properties);\n\tif (unlikely(i <= 0))\n\t\ti = 1;\n\ti *= sizeof(CProb);\n\tsbuf = un->un_a + SQUN_PROB;\n\tif (unlikely(sbuf->sz < i)) {\n\t\tif (sbuf->buf && sbuf->buf != un->un_prob)\n\t\t\tkfree(sbuf->buf);\n#ifdef __KERNEL__\n\t\tprintk(\"%s:%d: %d --> %d\\n\", __func__, __LINE__, sbuf->sz, i);\n#else\n\t\tprintf(\"%d --> %d\\n\", sbuf->sz, i);\n#endif\n\t\terr = -ENOMEM;\n\t\tsbuf->sz = 0;\n\t\tsbuf->buf = kmalloc(i, GFP_ATOMIC);\n\t\tif (unlikely(!sbuf->buf))\n\t\t\tgoto out;\n\t\tsbuf->sz = i;\n\t}\n\tstate.Probs = (void *)sbuf->buf;\n\n\t/* Read uncompressed size */\n\tmemcpy(a, src, sizeof(a));\n\tsrc += sizeof(a);\n\toutSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);\n\n\terr = -EINVAL;\n\tdst = un->un_resbuf;\n\tif (unlikely(!dst || outSize > un->un_reslen))\n\t\tgoto out;\n\tun->un_reslen = outSize;\n\tsrclen = un->un_cmlen - (src - un->un_cmbuf);\n\n\t/* Decompress */\n\terr = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,\n\t\t\t &outProcessed);\n\tif (unlikely(err))\n\t\terr = -EINVAL;\n\n out:\n#ifndef __KERNEL__\n\tif (err)\n\t\tfprintf(stderr, \"err %d\\n\", err);\n#endif\n\treturn err;\n}\n\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst)\n{\n\tint err, by_lzma = 1;\n\tif (un->un_lzma && is_lzma(*src->buf)) {\n\t\tun->un_cmbuf = src->buf;\n\t\tun->un_cmlen = src->sz;\n\t\tun->un_resbuf = dst->buf;\n\t\tun->un_reslen = dst->sz;\n\n\t\t/* this library is thread-safe */\n\t\terr = LzmaUncompress(un);\n\t\tgoto out;\n\t}\n\n\tby_lzma = 0;\n\terr = zlib_inflateReset(&un->un_stream);\n\tif (unlikely(err != Z_OK))\n\t\tgoto out;\n\tun->un_stream.next_in = src->buf;\n\tun->un_stream.avail_in = src->sz;\n\tun->un_stream.next_out = dst->buf;\n\tun->un_stream.avail_out = dst->sz;\n\terr = zlib_inflate(&un->un_stream, Z_FINISH);\n\tif (err == Z_STREAM_END)\n\t\terr = 0;\n\n out:\n\tif (unlikely(err)) {\n#ifdef __KERNEL__\n\t\tWARN_ON_ONCE(1);\n#else\n\t\tchar a[64] = \"ZLIB \";\n\t\tif (by_lzma) {\n\t\t\tstrcpy(a, \"LZMA \");\n#ifdef _REENTRANT\n\t\t\tstrerror_r(err, a + 5, sizeof(a) - 5);\n#else\n\t\t\tstrncat(a, strerror(err), sizeof(a) - 5);\n#endif\n\t\t} else\n\t\t\tstrncat(a, zError(err), sizeof(a) - 5);\n\t\tfprintf(stderr, \"%s: %.*s\\n\", __func__, sizeof(a), a);\n#endif\n\t}\n\treturn err;\n}\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)\n{\n\tint err;\n\n\terr = -ENOMEM;\n\tun->un_lzma = do_lzma;\n\tmemset(un->un_a, 0, sizeof(un->un_a));\n\tun->un_a[SQUN_PROB].buf = un->un_prob;\n\tun->un_a[SQUN_PROB].sz = sizeof(un->un_prob);\n\tif (res_sz) {\n\t\tun->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);\n\t\tif (unlikely(!un->un_a[SQUN_RESULT].buf))\n\t\t\treturn err;\n\t\tun->un_a[SQUN_RESULT].sz = res_sz;\n\t}\n\n\tun->un_stream.next_in = NULL;\n\tun->un_stream.avail_in = 0;\n#ifdef __KERNEL__\n\tun->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(),\n\t\t\t\t\t  GFP_KERNEL);\n\tif (unlikely(!un->un_stream.workspace))\n\t\treturn err;\n#else\n\tun->un_stream.opaque = NULL;\n\tun->un_stream.zalloc = Z_NULL;\n\tun->un_stream.zfree = Z_NULL;\n#endif\n\terr = zlib_inflateInit(&un->un_stream);\n\tif (unlikely(err == Z_MEM_ERROR))\n\t\treturn -ENOMEM;\n\tBUG_ON(err);\n\treturn err;\n}\n\nvoid sqlzma_fin(struct sqlzma_un *un)\n{\n\tint i;\n\tfor (i = 0; i < SQUN_LAST; i++)\n\t\tif (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)\n\t\t\tkfree(un->un_a[i].buf);\n\tBUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);\n}\n\n#ifdef __KERNEL__\nEXPORT_SYMBOL(sqlzma_un);\nEXPORT_SYMBOL(sqlzma_init);\nEXPORT_SYMBOL(sqlzma_fin);\n\n#if 0\nstatic int __init sqlzma_init(void)\n{\n\treturn 0;\n}\n\nstatic void __exit sqlzma_exit(void)\n{\n}\n\nmodule_init(sqlzma_init);\nmodule_exit(sqlzma_exit);\n#endif\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Junjiro Okajima <sfjro at users dot sf dot net>\");\nMODULE_VERSION(\"$Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $\");\nMODULE_DESCRIPTION(\"LZMA uncompress for squashfs. \"\n\t\t   \"Some functions for squashfs to support LZMA and \"\n\t\t   \"a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/CpuArch.h",
    "content": "/* CpuArch.h */\r\n\r\n#ifndef __CPUARCH_H\r\n#define __CPUARCH_H\r\n\r\n/* \r\nLITTLE_ENDIAN_UNALIGN means:\r\n  1) CPU is LITTLE_ENDIAN\r\n  2) it's allowed to make unaligned memory accesses\r\nif LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know \r\nabout these properties of platform.\r\n*/\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/IStream.h",
    "content": "/* IStream.h */\r\n\r\n#ifndef __C_ISTREAM_H\r\n#define __C_ISTREAM_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _ISeqInStream\r\n{\r\n  HRes (*Read)(void *object, void *data, UInt32 size, UInt32 *processedSize);\r\n} ISeqInStream;\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Sort.c",
    "content": "/* Sort.c */\r\n\r\n#include \"Sort.h\"\r\n\r\n#define HeapSortDown(p, k, size, temp) \\\r\n  { for (;;) { \\\r\n    UInt32 s = (k << 1); \\\r\n    if (s > size) break; \\\r\n    if (s < size && p[s + 1] > p[s]) s++; \\\r\n    if (temp >= p[s]) break; \\\r\n    p[k] = p[s]; k = s; \\\r\n  } p[k] = temp; }\r\n\r\nvoid HeapSort(UInt32 *p, UInt32 size)\r\n{\r\n  if (size <= 1)\r\n    return;\r\n  p--;\r\n  {\r\n    UInt32 i = size / 2;\r\n    do\r\n    {\r\n      UInt32 temp = p[i];\r\n      UInt32 k = i;\r\n      HeapSortDown(p, k, size, temp)\r\n    }\r\n    while(--i != 0);\r\n  }\r\n  /*\r\n  do\r\n  {\r\n    UInt32 k = 1;\r\n    UInt32 temp = p[size];\r\n    p[size--] = p[1];\r\n    HeapSortDown(p, k, size, temp)\r\n  }\r\n  while (size > 1);\r\n  */\r\n  while (size > 3)\r\n  {\r\n    UInt32 temp = p[size];\r\n    UInt32 k = (p[3] > p[2]) ? 3 : 2;\r\n    p[size--] = p[1];\r\n    p[1] = p[k]; \r\n    HeapSortDown(p, k, size, temp)\r\n  }\r\n  {\r\n    UInt32 temp = p[size];\r\n    p[size] = p[1];\r\n    if (size > 2 && p[2] < temp)\r\n    {\r\n      p[1] = p[2];\r\n      p[2] = temp;\r\n    }\r\n    else\r\n      p[1] = temp;\r\n  }\r\n}\r\n\r\n/*\r\n#define HeapSortRefDown(p, vals, n, size, temp) \\\r\n  { UInt32 k = n; UInt32 val = vals[temp]; for (;;) { \\\r\n    UInt32 s = (k << 1); \\\r\n    if (s > size) break; \\\r\n    if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \\\r\n    if (val >= vals[p[s]]) break; \\\r\n    p[k] = p[s]; k = s; \\\r\n  } p[k] = temp; }\r\n\r\nvoid HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size)\r\n{\r\n  if (size <= 1)\r\n    return;\r\n  p--;\r\n  {\r\n    UInt32 i = size / 2;\r\n    do\r\n    {\r\n      UInt32 temp = p[i];\r\n      HeapSortRefDown(p, vals, i, size, temp);\r\n    }\r\n    while(--i != 0);\r\n  }\r\n  do\r\n  {\r\n    UInt32 temp = p[size];\r\n    p[size--] = p[1];\r\n    HeapSortRefDown(p, vals, 1, size, temp);\r\n  }\r\n  while (size > 1);\r\n}\r\n*/"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Sort.h",
    "content": "/* Sort.h */\r\n\r\n#ifndef __7Z_Sort_H\r\n#define __7Z_Sort_H\r\n\r\n#include \"Types.h\"\r\n\r\nvoid HeapSort(UInt32 *p, UInt32 size);\r\n/* void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size); */\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Threads.c",
    "content": "/* Threads.c */\r\n\r\n#include \"Threads.h\"\r\n#include <process.h>\r\n\r\nHRes GetError()\r\n{\r\n  DWORD res = GetLastError();\r\n  return (res) ? (HRes)(res) : SZE_FAIL;\r\n}\r\n\r\nHRes BoolToHRes(int v) { return v ? SZ_OK : GetError(); }\r\nHRes BOOLToHRes(BOOL v) { return v ? SZ_OK : GetError(); }\r\n\r\nHRes MyCloseHandle(HANDLE *h)\r\n{\r\n  if (*h != NULL)\r\n    if (!CloseHandle(*h))\r\n      return GetError();\r\n  *h = NULL;\r\n  return SZ_OK;\r\n}\r\n\r\nHRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n{ \r\n  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r\n  thread->handle = \r\n    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */\r\n    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);\r\n    /* maybe we must use errno here, but probably GetLastError() is also OK. */\r\n  return BoolToHRes(thread->handle != 0);\r\n}\r\n\r\nHRes WaitObject(HANDLE h)\r\n{\r\n  return (HRes)WaitForSingleObject(h, INFINITE); \r\n}\r\n\r\nHRes Thread_Wait(CThread *thread)\r\n{\r\n  if (thread->handle == NULL)\r\n    return 1;\r\n  return WaitObject(thread->handle); \r\n}\r\n\r\nHRes Thread_Close(CThread *thread)\r\n{\r\n  return MyCloseHandle(&thread->handle);\r\n}\r\n\r\nHRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)\r\n{\r\n  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);\r\n  return BoolToHRes(p->handle != 0);\r\n}\r\n\r\nHRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, TRUE, initialSignaled); }\r\nHRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) \r\n  { return ManualResetEvent_Create(p, 0); }\r\n\r\nHRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, FALSE, initialSignaled); }\r\nHRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) \r\n  { return AutoResetEvent_Create(p, 0); }\r\n\r\nHRes Event_Set(CEvent *p) { return BOOLToHRes(SetEvent(p->handle)); }\r\nHRes Event_Reset(CEvent *p) { return BOOLToHRes(ResetEvent(p->handle)); }\r\nHRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }\r\nHRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }\r\n\r\n\r\nHRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)\r\n{\r\n  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);\r\n  return BoolToHRes(p->handle != 0);\r\n}\r\n\r\nHRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) \r\n{ \r\n  return BOOLToHRes(ReleaseSemaphore(p->handle, releaseCount, previousCount)); \r\n}\r\nHRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)\r\n{\r\n  return Semaphore_Release(p, (LONG)releaseCount, NULL);\r\n}\r\nHRes Semaphore_Release1(CSemaphore *p)\r\n{\r\n  return Semaphore_ReleaseN(p, 1);\r\n}\r\n\r\nHRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }\r\nHRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }\r\n\r\nHRes CriticalSection_Init(CCriticalSection *p)\r\n{\r\n  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\r\n  __try \r\n  { \r\n    InitializeCriticalSection(p); \r\n    /* InitializeCriticalSectionAndSpinCount(p, 0); */\r\n  }  \r\n  __except (EXCEPTION_EXECUTE_HANDLER) { return SZE_OUTOFMEMORY; }\r\n  return SZ_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Threads.h",
    "content": "/* Threads.h */\r\n\r\n#ifndef __7Z_THRESDS_H\r\n#define __7Z_THRESDS_H\r\n\r\n#include <windows.h>\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _CThread\r\n{\r\n  HANDLE handle;\r\n} CThread;\r\n\r\n#define Thread_Construct(thread) (thread)->handle = NULL\r\n#define Thread_WasCreated(thread) ((thread)->handle != NULL)\r\n \r\ntypedef unsigned THREAD_FUNC_RET_TYPE;\r\n#define THREAD_FUNC_CALL_TYPE StdCall\r\n#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r\n\r\nHRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);\r\nHRes Thread_Wait(CThread *thread);\r\nHRes Thread_Close(CThread *thread);\r\n\r\ntypedef struct _CEvent\r\n{\r\n  HANDLE handle;\r\n} CEvent;\r\n\r\ntypedef CEvent CAutoResetEvent;\r\ntypedef CEvent CManualResetEvent;\r\n\r\n#define Event_Construct(event) (event)->handle = NULL\r\n#define Event_IsCreated(event) ((event)->handle != NULL)\r\n\r\nHRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);\r\nHRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);\r\nHRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);\r\nHRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);\r\nHRes Event_Set(CEvent *event);\r\nHRes Event_Reset(CEvent *event);\r\nHRes Event_Wait(CEvent *event);\r\nHRes Event_Close(CEvent *event);\r\n\r\n\r\ntypedef struct _CSemaphore\r\n{\r\n  HANDLE handle;\r\n} CSemaphore;\r\n\r\n#define Semaphore_Construct(p) (p)->handle = NULL\r\n\r\nHRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);\r\nHRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\r\nHRes Semaphore_Release1(CSemaphore *p);\r\nHRes Semaphore_Wait(CSemaphore *p);\r\nHRes Semaphore_Close(CSemaphore *p);\r\n\r\n\r\ntypedef CRITICAL_SECTION CCriticalSection;\r\n\r\nHRes CriticalSection_Init(CCriticalSection *p);\r\n#define CriticalSection_Delete(p) DeleteCriticalSection(p)\r\n#define CriticalSection_Enter(p) EnterCriticalSection(p)\r\n#define CriticalSection_Leave(p) LeaveCriticalSection(p)\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/C/Types.h",
    "content": "/* 7zTypes.h */\r\n\r\n#ifndef __C_TYPES_H\r\n#define __C_TYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif \r\n\r\n#ifndef _7ZIP_INT32_DEFINED\r\n#define _7ZIP_INT32_DEFINED\r\n#ifdef _LZMA_INT32_IS_ULONG\r\ntypedef long Int32;\r\n#else\r\ntypedef int Int32;\r\n#endif\r\n#endif \r\n\r\n/* #define _SZ_NO_INT_64 */\r\n/* define it your compiler doesn't support long long int */\r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\n#ifdef _SZ_NO_INT_64\r\ntypedef unsigned long UInt64;\r\n#else\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n#endif\r\n#endif\r\n\r\n\r\n/* #define _SZ_FILE_SIZE_32 */\r\n/* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/\r\n\r\n#ifndef CFileSize\r\n#ifdef _SZ_FILE_SIZE_32\r\ntypedef UInt32 CFileSize; \r\n#else\r\ntypedef UInt64 CFileSize; \r\n#endif\r\n#endif\r\n\r\n#define SZ_RESULT int\r\n\r\ntypedef int HRes;\r\n#define RES_OK (0)\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_CRC_ERROR (3)\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n#define SZE_OUTOFMEMORY (0x8007000EL)\r\n#define SZE_NOTIMPL (0x80004001L)\r\n#define SZE_FAIL (0x80004005L)\r\n#define SZE_INVALIDARG (0x80070057L)\r\n\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRes __result_ = (x); if(__result_ != 0) return __result_; }\r\n#endif\r\n\r\ntypedef int Bool;\r\n#define True 1\r\n#define False 0\r\n\r\n#ifdef _MSC_VER\r\n#define StdCall __stdcall \r\n#else\r\n#define StdCall\r\n#endif\r\n\r\n#if _MSC_VER >= 1300\r\n#define MY_FAST_CALL __declspec(noinline) __fastcall \r\n#elif defined( _MSC_VER)\r\n#define MY_FAST_CALL __fastcall \r\n#else\r\n#define MY_FAST_CALL\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zCompressionMode.cpp",
    "content": "// CompressionMethod.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zCompressionMode.h",
    "content": "// 7zCompressionMode.h\r\n\r\n#ifndef __7Z_COMPRESSION_MODE_H\r\n#define __7Z_COMPRESSION_MODE_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CMethodFull: public CMethod\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBind\r\n{\r\n  UInt32 InCoder;\r\n  UInt32 InStream;\r\n  UInt32 OutCoder;\r\n  UInt32 OutStream;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  CObjectVector<CMethodFull> Methods;\r\n  CRecordVector<CBind> Binds;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }\r\n  CCompressionMethodMode(): PasswordIsDefined(false)\r\n      #ifdef COMPRESS_MT\r\n      , NumThreads(1) \r\n      #endif\r\n  {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zDecode.cpp",
    "content": "// 7zDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zDecode.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/LockedStream.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertFolderItemInfoToBindInfo(const CFolder &folder,\r\n    CBindInfoEx &bindInfo)\r\n{\r\n  bindInfo.Clear();\r\n  int i;\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    NCoderMixer::CBindPair bindPair;\r\n    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;\r\n    bindInfo.BindPairs.Add(bindPair);\r\n  }\r\n  UInt32 outStreamIndex = 0;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    const CCoderInfo &coderInfo = folder.Coders[i];\r\n    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;\r\n    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    bindInfo.Coders.Add(coderStreamsInfo);\r\n    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);\r\n    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)\r\n      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)\r\n        bindInfo.OutStreams.Add(outStreamIndex);\r\n  }\r\n  for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);\r\n}\r\n\r\nstatic bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1, \r\n    const NCoderMixer::CCoderStreamsInfo &a2)\r\n{\r\n  return (a1.NumInStreams == a2.NumInStreams) &&\r\n    (a1.NumOutStreams == a2.NumOutStreams);\r\n}\r\n\r\nstatic bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)\r\n{\r\n  return (a1.InIndex == a2.InIndex) &&\r\n    (a1.OutIndex == a2.OutIndex);\r\n}\r\n\r\nstatic bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)\r\n{\r\n  if (a1.Coders.Size() != a2.Coders.Size())\r\n    return false;\r\n  int i;\r\n  for (i = 0; i < a1.Coders.Size(); i++)\r\n    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))\r\n      return false;\r\n  if (a1.BindPairs.Size() != a2.BindPairs.Size())\r\n    return false;\r\n  for (i = 0; i < a1.BindPairs.Size(); i++)\r\n    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))\r\n      return false;\r\n  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)\r\n    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])\r\n      return false;\r\n  if (a1.InStreams.Size() != a2.InStreams.Size())\r\n    return false;\r\n  if (a1.OutStreams.Size() != a2.OutStreams.Size())\r\n    return false;\r\n  return true;\r\n}\r\n\r\nCDecoder::CDecoder(bool multiThread)\r\n{\r\n  #ifndef _ST_MODE\r\n  multiThread = true;\r\n  #endif\r\n  _multiThread = multiThread;\r\n  _bindInfoExPrevIsDefined = false;\r\n}\r\n\r\nHRESULT CDecoder::Decode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    UInt64 startPos,\r\n    const UInt64 *packSizes,\r\n    const CFolder &folderInfo, \r\n    ISequentialOutStream *outStream,\r\n    ICompressProgressInfo *compressProgress\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    #ifdef COMPRESS_MT\r\n    , bool mtMode, UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;\r\n  \r\n  CLockedInStream lockedInStream;\r\n  lockedInStream.Init(inStream);\r\n  \r\n  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)\r\n  {\r\n    CLockedSequentialInStreamImp *lockedStreamImpSpec = new \r\n        CLockedSequentialInStreamImp;\r\n    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;\r\n    lockedStreamImpSpec->Init(&lockedInStream, startPos);\r\n    startPos += packSizes[j];\r\n    \r\n    CLimitedSequentialInStream *streamSpec = new \r\n        CLimitedSequentialInStream;\r\n    CMyComPtr<ISequentialInStream> inStream = streamSpec;\r\n    streamSpec->SetStream(lockedStreamImp);\r\n    streamSpec->Init(packSizes[j]);\r\n    inStreams.Add(inStream);\r\n  }\r\n  \r\n  int numCoders = folderInfo.Coders.Size();\r\n  \r\n  CBindInfoEx bindInfo;\r\n  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);\r\n  bool createNewCoders;\r\n  if (!_bindInfoExPrevIsDefined)\r\n    createNewCoders = true;\r\n  else\r\n    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);\r\n  if (createNewCoders)\r\n  {\r\n    int i;\r\n    _decoders.Clear();\r\n    // _decoders2.Clear();\r\n    \r\n    _mixerCoder.Release();\r\n\r\n    if (_multiThread)\r\n    {\r\n      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;\r\n      _mixerCoder = _mixerCoderMTSpec;\r\n      _mixerCoderCommon = _mixerCoderMTSpec;\r\n    }\r\n    else\r\n    {\r\n      #ifdef _ST_MODE\r\n      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;\r\n      _mixerCoder = _mixerCoderSTSpec;\r\n      _mixerCoderCommon = _mixerCoderSTSpec;\r\n      #endif\r\n    }\r\n    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));\r\n    \r\n    for (i = 0; i < numCoders; i++)\r\n    {\r\n      const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n\r\n  \r\n      CMyComPtr<ICompressCoder> decoder;\r\n      CMyComPtr<ICompressCoder2> decoder2;\r\n      RINOK(CreateCoder(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          coderInfo.MethodID, decoder, decoder2, false));\r\n      CMyComPtr<IUnknown> decoderUnknown;\r\n      if (coderInfo.IsSimpleCoder())\r\n      {\r\n        if (decoder == 0)\r\n          return E_NOTIMPL;\r\n\r\n        decoderUnknown = (IUnknown *)decoder;\r\n        \r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder(decoder);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder(decoder, false);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        if (decoder2 == 0)\r\n          return E_NOTIMPL;\r\n        decoderUnknown = (IUnknown *)decoder2;\r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder2(decoder2);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder2(decoder2, false);\r\n        #endif\r\n      }\r\n      _decoders.Add(decoderUnknown);\r\n      #ifdef EXTERNAL_CODECS\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n      }\r\n      #endif\r\n    }\r\n    _bindInfoExPrev = bindInfo;\r\n    _bindInfoExPrevIsDefined = true;\r\n  }\r\n  int i;\r\n  _mixerCoderCommon->ReInit();\r\n  \r\n  UInt32 packStreamIndex = 0, unPackStreamIndex = 0;\r\n  UInt32 coderIndex = 0;\r\n  // UInt32 coder2Index = 0;\r\n  \r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];\r\n    \r\n    {\r\n      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n      if (setDecoderProperties)\r\n      {\r\n        const CByteBuffer &properties = coderInfo.Properties;\r\n        size_t size = properties.GetCapacity();\r\n        if (size > 0xFFFFFFFF)\r\n          return E_NOTIMPL;\r\n        if (size > 0)\r\n        {\r\n          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)properties, (UInt32)size));\r\n        }\r\n      }\r\n    }\r\n\r\n    #ifdef COMPRESS_MT\r\n    if (mtMode)\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(numThreads));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    {\r\n      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n      if (cryptoSetPassword)\r\n      {\r\n        if (getTextPassword == 0)\r\n          return E_FAIL;\r\n        CMyComBSTR password;\r\n        RINOK(getTextPassword->CryptoGetTextPassword(&password));\r\n        CByteBuffer buffer;\r\n        UString unicodePassword(password);\r\n        const UInt32 sizeInBytes = unicodePassword.Length() * 2;\r\n        buffer.SetCapacity(sizeInBytes);\r\n        for (int i = 0; i < unicodePassword.Length(); i++)\r\n        {\r\n          wchar_t c = unicodePassword[i];\r\n          ((Byte *)buffer)[i * 2] = (Byte)c;\r\n          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n        }\r\n        RINOK(cryptoSetPassword->CryptoSetPassword(\r\n          (const Byte *)buffer, sizeInBytes));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    coderIndex++;\r\n    \r\n    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;\r\n    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    CRecordVector<const UInt64 *> packSizesPointers;\r\n    CRecordVector<const UInt64 *> unPackSizesPointers;\r\n    packSizesPointers.Reserve(numInStreams);\r\n    unPackSizesPointers.Reserve(numOutStreams);\r\n    UInt32 j;\r\n    for (j = 0; j < numOutStreams; j++, unPackStreamIndex++)\r\n      unPackSizesPointers.Add(&folderInfo.UnPackSizes[unPackStreamIndex]);\r\n    \r\n    for (j = 0; j < numInStreams; j++, packStreamIndex++)\r\n    {\r\n      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);\r\n      if (bindPairIndex >= 0)\r\n        packSizesPointers.Add(\r\n        &folderInfo.UnPackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);\r\n      else\r\n      {\r\n        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);\r\n        if (index < 0)\r\n          return E_FAIL;\r\n        packSizesPointers.Add(&packSizes[index]);\r\n      }\r\n    }\r\n    \r\n    _mixerCoderCommon->SetCoderInfo(i, \r\n        &packSizesPointers.Front(), \r\n        &unPackSizesPointers.Front());\r\n  }\r\n  UInt32 mainCoder, temp;\r\n  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);\r\n\r\n  if (_multiThread)\r\n    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);\r\n  /*\r\n  else\r\n    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;\r\n  */\r\n  \r\n  if (numCoders == 0)\r\n    return 0;\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  inStreamPointers.Reserve(inStreams.Size());\r\n  for (i = 0; i < inStreams.Size(); i++)\r\n    inStreamPointers.Add(inStreams[i]);\r\n  ISequentialOutStream *outStreamPointer = outStream;\r\n  return _mixerCoder->Code(&inStreamPointers.Front(), NULL, \r\n    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zDecode.h",
    "content": "// 7zDecode.h\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"7zItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CBindInfoEx: public NCoderMixer::CBindInfo\r\n{\r\n  CRecordVector<CMethodId> CoderMethodIDs;\r\n  void Clear()\r\n  {\r\n    CBindInfo::Clear();\r\n    CoderMethodIDs.Clear();\r\n  }\r\n};\r\n\r\nclass CDecoder\r\n{\r\n  bool _bindInfoExPrevIsDefined;\r\n  CBindInfoEx _bindInfoExPrev;\r\n  \r\n  bool _multiThread;\r\n  #ifdef _ST_MODE\r\n  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;\r\n  #endif\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;\r\n  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;\r\n  \r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n  CObjectVector<CMyComPtr<IUnknown> > _decoders;\r\n  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;\r\npublic:\r\n  CDecoder(bool multiThread);\r\n  HRESULT Decode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      IInStream *inStream,\r\n      UInt64 startPos,\r\n      const UInt64 *packSizes,\r\n      const CFolder &folder, \r\n      ISequentialOutStream *outStream,\r\n      ICompressProgressInfo *compressProgress\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPasswordSpec\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , bool mtMode, UInt32 numThreads\r\n      #endif\r\n      );\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zEncode.cpp",
    "content": "// Encode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zSpecStream.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/InOutTempBuffer.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nstatic const UInt64 k_AES = 0x06F10701;\r\nstatic const UInt64 k_BCJ  = 0x03030103;\r\nstatic const UInt64 k_BCJ2 = 0x0303011B;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,\r\n    const CRecordVector<CMethodId> decompressionMethods,\r\n    CFolder &folder)\r\n{\r\n  folder.Coders.Clear();\r\n  // bindInfo.CoderMethodIDs.Clear();\r\n  // folder.OutStreams.Clear();\r\n  folder.PackStreams.Clear();\r\n  folder.BindPairs.Clear();\r\n  int i;\r\n  for (i = 0; i < bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = bindInfo.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = bindInfo.BindPairs[i].OutIndex;\r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n  for (i = 0; i < bindInfo.Coders.Size(); i++)\r\n  {\r\n    CCoderInfo coderInfo;\r\n    const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];\r\n    coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;\r\n    coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;\r\n    coderInfo.MethodID = decompressionMethods[i];\r\n    folder.Coders.Add(coderInfo);\r\n  }\r\n  for (i = 0; i < bindInfo.InStreams.Size(); i++)\r\n    folder.PackStreams.Add(bindInfo.InStreams[i]);\r\n}\r\n\r\nHRESULT CEncoder::CreateMixerCoder(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const UInt64 *inSizeForReduce)\r\n{\r\n  _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;\r\n  _mixerCoder = _mixerCoderSpec;\r\n  RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));\r\n  for (int i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _codersInfo.Add(CCoderInfo());\r\n    CCoderInfo &encodingInfo = _codersInfo.Back();\r\n    encodingInfo.MethodID = methodFull.Id;\r\n    CMyComPtr<ICompressCoder> encoder;\r\n    CMyComPtr<ICompressCoder2> encoder2;\r\n    \r\n\r\n    RINOK(CreateCoder(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        methodFull.Id, encoder, encoder2, true));\r\n\r\n    if (!encoder && !encoder2)\r\n      return E_FAIL;\r\n\r\n    CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;\r\n   \r\n    #ifdef COMPRESS_MT\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));\r\n      }\r\n    }\r\n    #endif\r\n        \r\n\r\n    RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon));\r\n\r\n    /*\r\n    CMyComPtr<ICryptoResetSalt> resetSalt;\r\n    encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);\r\n    if (resetSalt != NULL)\r\n    {\r\n      resetSalt->ResetSalt();\r\n    }\r\n    */\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n    encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n    if (setCompressCodecsInfo)\r\n    {\r\n      RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n    }\r\n    #endif\r\n    \r\n    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n    encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n\r\n    if (cryptoSetPassword)\r\n    {\r\n      CByteBuffer buffer;\r\n      const UInt32 sizeInBytes = _options.Password.Length() * 2;\r\n      buffer.SetCapacity(sizeInBytes);\r\n      for (int i = 0; i < _options.Password.Length(); i++)\r\n      {\r\n        wchar_t c = _options.Password[i];\r\n        ((Byte *)buffer)[i * 2] = (Byte)c;\r\n        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n      }\r\n      RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n    }\r\n\r\n    if (encoder)\r\n      _mixerCoderSpec->AddCoder(encoder);\r\n    else\r\n      _mixerCoderSpec->AddCoder2(encoder2);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Encode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    ISequentialInStream *inStream,\r\n    const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n    CFolder &folderItem,\r\n    ISequentialOutStream *outStream,\r\n    CRecordVector<UInt64> &packSizes,\r\n    ICompressProgressInfo *compressProgress)\r\n{\r\n  RINOK(EncoderConstr());\r\n\r\n  if (_mixerCoderSpec == NULL)\r\n  {\r\n    RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));\r\n  }\r\n  _mixerCoderSpec->ReInit();\r\n  // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);\r\n\r\n  CObjectVector<CInOutTempBuffer> inOutTempBuffers;\r\n  CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;\r\n  CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;\r\n  int numMethods = _bindInfo.Coders.Size();\r\n  int i;\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    inOutTempBuffers.Add(CInOutTempBuffer());\r\n    inOutTempBuffers.Back().Create();\r\n    inOutTempBuffers.Back().InitWriting();\r\n  }\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CSequentialOutTempBufferImp *tempBufferSpec = \r\n        new CSequentialOutTempBufferImp;\r\n    CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;\r\n    tempBufferSpec->Init(&inOutTempBuffers[i - 1]);\r\n    tempBuffers.Add(tempBuffer);\r\n    tempBufferSpecs.Add(tempBufferSpec);\r\n  }\r\n\r\n  for (i = 0; i < numMethods; i++)\r\n    _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    return E_FAIL;\r\n  UInt32 mainCoderIndex, mainStreamIndex;\r\n  _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);\r\n  \r\n  if (inStreamSize != NULL)\r\n  {\r\n    CRecordVector<const UInt64 *> sizePointers;\r\n    for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)\r\n      if (i == mainStreamIndex)\r\n        sizePointers.Add(inStreamSize);\r\n      else\r\n        sizePointers.Add(NULL);\r\n    _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);\r\n  }\r\n\r\n  \r\n  // UInt64 outStreamStartPos;\r\n  // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));\r\n  \r\n  CSequentialInStreamSizeCount2 *inStreamSizeCountSpec = \r\n      new CSequentialInStreamSizeCount2;\r\n  CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;\r\n  CSequentialOutStreamSizeCount *outStreamSizeCountSpec = \r\n      new CSequentialOutStreamSizeCount;\r\n  CMyComPtr<ISequentialOutStream> outStreamSizeCount = outStreamSizeCountSpec;\r\n\r\n  inStreamSizeCountSpec->Init(inStream);\r\n  outStreamSizeCountSpec->SetStream(outStream);\r\n  outStreamSizeCountSpec->Init();\r\n\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  CRecordVector<ISequentialOutStream *> outStreamPointers;\r\n  inStreamPointers.Add(inStreamSizeCount);\r\n  outStreamPointers.Add(outStreamSizeCount);\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n    outStreamPointers.Add(tempBuffers[i - 1]);\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    CCoderInfo &encodingInfo = _codersInfo[i];\r\n    \r\n    CMyComPtr<ICryptoResetInitVector> resetInitVector;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);\r\n    if (resetInitVector != NULL)\r\n    {\r\n      resetInitVector->ResetInitVector();\r\n    }\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n    if (writeCoderProperties != NULL)\r\n    {\r\n      CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n      outStreamSpec->Init();\r\n      writeCoderProperties->WriteCoderProperties(outStream);\r\n      size_t size = outStreamSpec->GetSize();\r\n      encodingInfo.Properties.SetCapacity(size);\r\n      memmove(encodingInfo.Properties, outStreamSpec->GetBuffer(), size);\r\n    }\r\n  }\r\n\r\n  UInt32 progressIndex = mainCoderIndex;\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    const CCoderInfo &e = _codersInfo[i];\r\n    if ((e.MethodID == k_BCJ || e.MethodID == k_BCJ2) && i + 1 < _codersInfo.Size())\r\n      progressIndex = i + 1;\r\n  }\r\n\r\n  _mixerCoderSpec->SetProgressCoderIndex(progressIndex);\r\n  \r\n  RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,\r\n    &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));\r\n  \r\n  ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods,\r\n      folderItem);\r\n  \r\n  packSizes.Add(outStreamSizeCountSpec->GetSize());\r\n  \r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];\r\n    inOutTempBuffer.FlushWrite();\r\n    inOutTempBuffer.InitReading();\r\n    inOutTempBuffer.WriteToStream(outStream);\r\n    packSizes.Add(inOutTempBuffer.GetDataSize());\r\n  }\r\n  \r\n  for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)\r\n  {\r\n    int binder = _bindInfo.FindBinderForInStream(\r\n        _bindReverseConverter->DestOutToSrcInMap[i]);\r\n    UInt64 streamSize;\r\n    if (binder < 0)\r\n      streamSize = inStreamSizeCountSpec->GetSize();\r\n    else\r\n      streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);\r\n    folderItem.UnPackSizes.Add(streamSize);\r\n  }\r\n  for (i = numMethods - 1; i >= 0; i--)\r\n    folderItem.Coders[numMethods - 1 - i].Properties = _codersInfo[i].Properties;\r\n  return S_OK;\r\n}\r\n\r\n\r\nCEncoder::CEncoder(const CCompressionMethodMode &options):\r\n  _bindReverseConverter(0),\r\n  _constructed(false)\r\n{\r\n  if (options.IsEmpty())\r\n    throw 1;\r\n\r\n  _options = options;\r\n  _mixerCoderSpec = NULL;\r\n}\r\n\r\nHRESULT CEncoder::EncoderConstr()\r\n{\r\n  if (_constructed)\r\n    return S_OK;\r\n  if (_options.Methods.IsEmpty())\r\n  {\r\n    // it has only password method;\r\n    if (!_options.PasswordIsDefined)\r\n      throw 1;\r\n    if (!_options.Binds.IsEmpty())\r\n      throw 1;\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    CMethodFull method;\r\n    \r\n    method.NumInStreams = 1;\r\n    method.NumOutStreams = 1;\r\n    coderStreamsInfo.NumInStreams = 1;\r\n    coderStreamsInfo.NumOutStreams = 1;\r\n    method.Id = k_AES;\r\n    \r\n    _options.Methods.Add(method);\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  \r\n    _bindInfo.InStreams.Add(0);\r\n    _bindInfo.OutStreams.Add(0);\r\n  }\r\n  else\r\n  {\r\n\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  int i;\r\n  for (i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;\r\n    coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;\r\n    if (_options.Binds.IsEmpty())\r\n    {\r\n      if (i < _options.Methods.Size() - 1)\r\n      {\r\n        NCoderMixer::CBindPair bindPair;\r\n        bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;\r\n        bindPair.OutIndex = numOutStreams;\r\n        _bindInfo.BindPairs.Add(bindPair);\r\n      }\r\n      else\r\n        _bindInfo.OutStreams.Insert(0, numOutStreams);\r\n      for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)\r\n        _bindInfo.OutStreams.Add(numOutStreams + j);\r\n    }\r\n    \r\n    numInStreams += coderStreamsInfo.NumInStreams;\r\n    numOutStreams += coderStreamsInfo.NumOutStreams;\r\n\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  }\r\n\r\n  if (!_options.Binds.IsEmpty())\r\n  {\r\n    for (i = 0; i < _options.Binds.Size(); i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      const CBind &bind = _options.Binds[i];\r\n      bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;\r\n      bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    for (i = 0; i < (int)numOutStreams; i++)\r\n      if (_bindInfo.FindBinderForOutStream(i) == -1)\r\n        _bindInfo.OutStreams.Add(i);\r\n  }\r\n\r\n  for (i = 0; i < (int)numInStreams; i++)\r\n    if (_bindInfo.FindBinderForInStream(i) == -1)\r\n      _bindInfo.InStreams.Add(i);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    throw 1; // this is error\r\n\r\n  // Make main stream first in list\r\n  int inIndex = _bindInfo.InStreams[0];\r\n  for (;;)\r\n  {\r\n    UInt32 coderIndex, coderStreamIndex;\r\n    _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);\r\n    UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);\r\n    int binder = _bindInfo.FindBinderForOutStream(outIndex);\r\n    if (binder >= 0)\r\n    {\r\n      inIndex = _bindInfo.BindPairs[binder].InIndex;\r\n      continue;\r\n    }\r\n    for (i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n      if (_bindInfo.OutStreams[i] == outIndex)\r\n      {\r\n        _bindInfo.OutStreams.Delete(i);\r\n        _bindInfo.OutStreams.Insert(0, outIndex);\r\n        break;\r\n      }\r\n    break;\r\n  }\r\n\r\n  if (_options.PasswordIsDefined)\r\n  {\r\n    int numCryptoStreams = _bindInfo.OutStreams.Size();\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      bindPair.InIndex = numInStreams + i;\r\n      bindPair.OutIndex = _bindInfo.OutStreams[i];\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    _bindInfo.OutStreams.Clear();\r\n\r\n    /*\r\n    if (numCryptoStreams == 0)\r\n      numCryptoStreams = 1;\r\n    */\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n      CMethodFull method;\r\n      method.NumInStreams = 1;\r\n      method.NumOutStreams = 1;\r\n      coderStreamsInfo.NumInStreams = method.NumOutStreams;\r\n      coderStreamsInfo.NumOutStreams = method.NumInStreams;\r\n      method.Id = k_AES;\r\n\r\n      _options.Methods.Add(method);\r\n      _bindInfo.Coders.Add(coderStreamsInfo);\r\n      _bindInfo.OutStreams.Add(numOutStreams + i);\r\n    }\r\n  }\r\n\r\n  }\r\n\r\n  for (int i = _options.Methods.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _decompressionMethods.Add(methodFull.Id);\r\n  }\r\n\r\n  _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);\r\n  _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);\r\n  _constructed = true;\r\n  return S_OK;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  delete _bindReverseConverter;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zEncode.h",
    "content": "// 7zEncode.h\r\n\r\n#ifndef __7Z_ENCODE_H\r\n#define __7Z_ENCODE_H\r\n\r\n// #include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n#include \"7zItem.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CEncoder\r\n{\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;\r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n\r\n  CObjectVector<CCoderInfo> _codersInfo;\r\n\r\n  CCompressionMethodMode _options;\r\n  NCoderMixer::CBindInfo _bindInfo;\r\n  NCoderMixer::CBindInfo _decompressBindInfo;\r\n  NCoderMixer::CBindReverseConverter *_bindReverseConverter;\r\n  CRecordVector<CMethodId> _decompressionMethods;\r\n\r\n  HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const UInt64 *inSizeForReduce);\r\n\r\n  bool _constructed;\r\npublic:\r\n  CEncoder(const CCompressionMethodMode &options);\r\n  ~CEncoder();\r\n  HRESULT EncoderConstr();\r\n  HRESULT Encode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      ISequentialInStream *inStream,\r\n      const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n      CFolder &folderItem,\r\n      ISequentialOutStream *outStream,\r\n      CRecordVector<UInt64> &packSizes,\r\n      ICompressProgressInfo *compressProgress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zExtract.cpp",
    "content": "// 7zExtract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zFolderOutStream.h\"\r\n#include \"7zDecode.h\"\r\n// #include \"7z1Decode.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CExtractFolderInfo\r\n{\r\n  #ifdef _7Z_VOL\r\n  int VolumeIndex;\r\n  #endif\r\n  CNum FileIndex;\r\n  CNum FolderIndex;\r\n  CBoolVector ExtractStatuses;\r\n  UInt64 UnPackSize;\r\n  CExtractFolderInfo(\r\n    #ifdef _7Z_VOL\r\n    int volumeIndex, \r\n    #endif\r\n    CNum fileIndex, CNum folderIndex): \r\n    #ifdef _7Z_VOL\r\n    VolumeIndex(volumeIndex),\r\n    #endif\r\n    FileIndex(fileIndex),\r\n    FolderIndex(folderIndex), \r\n    UnPackSize(0) \r\n  {\r\n    if (fileIndex != kNumNoIndex)\r\n    {\r\n      ExtractStatuses.Reserve(1);\r\n      ExtractStatuses.Add(true);\r\n    }\r\n  };\r\n};\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool testMode = (testModeSpec != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;\r\n  UInt64 importantTotalUnPacked = 0;\r\n\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (allFilesMode)\r\n    numItems = \r\n    #ifdef _7Z_VOL\r\n    _refs.Size();\r\n    #else\r\n    _database.Files.Size();\r\n    #endif\r\n\r\n  if(numItems == 0)\r\n    return S_OK;\r\n\r\n  /*\r\n  if(_volumes.Size() != 1)\r\n    return E_FAIL;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_database = volume.Database;\r\n  IInStream *_inStream = volume.Stream;\r\n  */\r\n  \r\n  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;\r\n  for(UInt32 ii = 0; ii < numItems; ii++)\r\n  {\r\n    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];\r\n    UInt32 ref2Index = allFilesMode ? ii : indices[ii];\r\n    // const CRef2 &ref2 = _refs[ref2Index];\r\n\r\n    // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)\r\n    {\r\n      #ifdef _7Z_VOL\r\n      // const CRef &ref = ref2.Refs[ri];\r\n      const CRef &ref = _refs[ref2Index];\r\n\r\n      int volumeIndex = ref.VolumeIndex;\r\n      const CVolume &volume = _volumes[volumeIndex];\r\n      const CArchiveDatabaseEx &database = volume.Database;\r\n      UInt32 fileIndex = ref.ItemIndex;\r\n      #else\r\n      const CArchiveDatabaseEx &database = _database;\r\n      UInt32 fileIndex = ref2Index;\r\n      #endif\r\n\r\n      CNum folderIndex = database.FileIndexToFolderIndexMap[fileIndex];\r\n      if (folderIndex == kNumNoIndex)\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex, \r\n            #endif\r\n            fileIndex, kNumNoIndex));\r\n        continue;\r\n      }\r\n      if (extractFolderInfoVector.IsEmpty() || \r\n        folderIndex != extractFolderInfoVector.Back().FolderIndex \r\n        #ifdef _7Z_VOL\r\n        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex\r\n        #endif\r\n        )\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex, \r\n            #endif\r\n            kNumNoIndex, folderIndex));\r\n        const CFolder &folderInfo = database.Folders[folderIndex];\r\n        UInt64 unPackSize = folderInfo.GetUnPackSize();\r\n        importantTotalUnPacked += unPackSize;\r\n        extractFolderInfoVector.Back().UnPackSize = unPackSize;\r\n      }\r\n      \r\n      CExtractFolderInfo &efi = extractFolderInfoVector.Back();\r\n      \r\n      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];\r\n      CNum startIndex = database.FolderStartFileIndex[folderIndex];\r\n      for (CNum index = efi.ExtractStatuses.Size();\r\n          index <= fileIndex - startIndex; index++)\r\n      {\r\n        // UInt64 unPackSize = _database.Files[startIndex + index].UnPackSize;\r\n        // Count partial_folder_size\r\n        // efi.UnPackSize += unPackSize;\r\n        // importantTotalUnPacked += unPackSize;\r\n        efi.ExtractStatuses.Add(index == fileIndex - startIndex);\r\n      }\r\n    }\r\n  }\r\n\r\n  extractCallback->SetTotal(importantTotalUnPacked);\r\n\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  // CDecoder1 decoder;\r\n\r\n  UInt64 currentTotalPacked = 0;\r\n  UInt64 currentTotalUnPacked = 0;\r\n  UInt64 totalFolderUnPacked;\r\n  UInt64 totalFolderPacked;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for(int i = 0; i < extractFolderInfoVector.Size(); i++, \r\n      currentTotalUnPacked += totalFolderUnPacked,\r\n      currentTotalPacked += totalFolderPacked)\r\n  {\r\n    lps->OutSize = currentTotalUnPacked;\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    const CExtractFolderInfo &efi = extractFolderInfoVector[i];\r\n    totalFolderUnPacked = efi.UnPackSize;\r\n\r\n    totalFolderPacked = 0;\r\n\r\n    CFolderOutStream *folderOutStream = new CFolderOutStream;\r\n    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);\r\n\r\n    #ifdef _7Z_VOL\r\n    const CVolume &volume = _volumes[efi.VolumeIndex];\r\n    const CArchiveDatabaseEx &database = volume.Database;\r\n    #else\r\n    const CArchiveDatabaseEx &database = _database;\r\n    #endif\r\n\r\n    CNum startIndex;\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      startIndex = efi.FileIndex;\r\n    else\r\n      startIndex = database.FolderStartFileIndex[efi.FolderIndex];\r\n\r\n\r\n    HRESULT result = folderOutStream->Init(&database, \r\n        #ifdef _7Z_VOL\r\n        volume.StartRef2Index, \r\n        #else\r\n        0,\r\n        #endif\r\n        startIndex, \r\n        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);\r\n\r\n    RINOK(result);\r\n\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      continue;\r\n\r\n    CNum folderIndex = efi.FolderIndex;\r\n    const CFolder &folderInfo = database.Folders[folderIndex];\r\n\r\n    totalFolderPacked = _database.GetFolderFullPackSize(folderIndex);\r\n\r\n    CNum packStreamIndex = database.FolderStartPackStreamIndex[folderIndex];\r\n    UInt64 folderStartPackPos = database.GetFolderStreamPos(folderIndex, 0);\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (extractCallback)\r\n      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    #endif\r\n\r\n    try\r\n    {\r\n      HRESULT result = decoder.Decode(\r\n          EXTERNAL_CODECS_VARS\r\n          #ifdef _7Z_VOL\r\n          volume.Stream,\r\n          #else\r\n          _inStream,\r\n          #endif\r\n          folderStartPackPos, \r\n          &database.PackSizes[packStreamIndex],\r\n          folderInfo,\r\n          outStream,\r\n          progress\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword\r\n          #endif\r\n          #ifdef COMPRESS_MT\r\n          , true, _numThreads\r\n          #endif\r\n          );\r\n\r\n      if (result == S_FALSE)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));\r\n        continue;\r\n      }\r\n      if (result != S_OK)\r\n        return result;\r\n      if (folderOutStream->WasWritingFinished() != S_OK)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n      continue;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zFolderInStream.cpp",
    "content": "// 7zFolderInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderInStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderInStream::CFolderInStream()\r\n{\r\n  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;\r\n  _inStreamWithHash = _inStreamWithHashSpec;\r\n}\r\n\r\nvoid CFolderInStream::Init(IArchiveUpdateCallback *updateCallback, \r\n    const UInt32 *fileIndices, UInt32 numFiles)\r\n{\r\n  _updateCallback = updateCallback;\r\n  _numFiles = numFiles;\r\n  _fileIndex = 0;\r\n  _fileIndices = fileIndices;\r\n  Processed.Clear();\r\n  CRCs.Clear();\r\n  Sizes.Clear();\r\n  _fileIsOpen = false;\r\n  _currentSizeIsDefined = false;\r\n}\r\n\r\nHRESULT CFolderInStream::OpenStream()\r\n{\r\n  _filePos = 0;\r\n  while (_fileIndex < _numFiles)\r\n  {\r\n    _currentSizeIsDefined = false;\r\n    CMyComPtr<ISequentialInStream> stream;\r\n    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);\r\n    if (result != S_OK && result != S_FALSE)\r\n      return result;\r\n    _fileIndex++;\r\n    _inStreamWithHashSpec->SetStream(stream);\r\n    _inStreamWithHashSpec->Init();\r\n    if (!stream)\r\n    {\r\n      RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n      Sizes.Add(0);\r\n      Processed.Add(result == S_OK);\r\n      AddDigest();\r\n      continue;\r\n    }\r\n    CMyComPtr<IStreamGetSize> streamGetSize;\r\n    if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)\r\n    {\r\n      if(streamGetSize)\r\n      {\r\n        _currentSizeIsDefined = true;\r\n        RINOK(streamGetSize->GetSize(&_currentSize));\r\n      }\r\n    }\r\n\r\n    _fileIsOpen = true;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFolderInStream::AddDigest()\r\n{\r\n  CRCs.Add(_inStreamWithHashSpec->GetCRC());\r\n}\r\n\r\nHRESULT CFolderInStream::CloseStream()\r\n{\r\n  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n  _inStreamWithHashSpec->ReleaseStream();\r\n  _fileIsOpen = false;\r\n  Processed.Add(true);\r\n  Sizes.Add(_filePos);\r\n  AddDigest();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 localProcessedSize;\r\n      RINOK(_inStreamWithHash->Read(\r\n          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));\r\n      if (localProcessedSize == 0)\r\n      {\r\n        RINOK(CloseStream());\r\n        continue;\r\n      }\r\n      realProcessedSize += localProcessedSize;\r\n      _filePos += localProcessedSize;\r\n      size -= localProcessedSize;\r\n      break;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenStream());\r\n    }\r\n  }\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)\r\n{\r\n  *value = 0;\r\n  int subStreamIndex = (int)subStream;\r\n  if (subStreamIndex < 0 || subStream > Sizes.Size())\r\n    return E_FAIL;\r\n  if (subStreamIndex < Sizes.Size())\r\n  {\r\n    *value= Sizes[subStreamIndex];\r\n    return S_OK;\r\n  }\r\n  if (!_currentSizeIsDefined)\r\n    return S_FALSE;\r\n  *value = _currentSize;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zFolderInStream.h",
    "content": "// 7z/FolderInStream.h\r\n\r\n#ifndef __7Z_FOLDERINSTREAM_H\r\n#define __7Z_FOLDERINSTREAM_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zHeader.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../Common/InStreamWithCRC.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderInStream: \r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  CFolderInStream();\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\nprivate:\r\n  CSequentialInStreamWithCRC *_inStreamWithHashSpec;\r\n  CMyComPtr<ISequentialInStream> _inStreamWithHash;\r\n  CMyComPtr<IArchiveUpdateCallback> _updateCallback;\r\n\r\n  bool _currentSizeIsDefined;\r\n  UInt64 _currentSize;\r\n\r\n  bool _fileIsOpen;\r\n  UInt64 _filePos;\r\n\r\n  const UInt32 *_fileIndices;\r\n  UInt32 _numFiles;\r\n  UInt32 _fileIndex;\r\n\r\n  HRESULT OpenStream();\r\n  HRESULT CloseStream();\r\n  void AddDigest();\r\npublic:\r\n  void Init(IArchiveUpdateCallback *updateCallback, \r\n      const UInt32 *fileIndices, UInt32 numFiles);\r\n  CRecordVector<bool> Processed;\r\n  CRecordVector<UInt32> CRCs;\r\n  CRecordVector<UInt64> Sizes;\r\n  UInt64 GetFullSize() const\r\n  {\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < Sizes.Size(); i++)      \r\n      size += Sizes[i];\r\n    return size;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zFolderOutStream.cpp",
    "content": "// 7zFolderOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderOutStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderOutStream::CFolderOutStream()\r\n{\r\n  _outStreamWithHashSpec = new COutStreamWithCRC;\r\n  _outStreamWithHash = _outStreamWithHashSpec;\r\n}\r\n\r\nHRESULT CFolderOutStream::Init(\r\n    const CArchiveDatabaseEx *archiveDatabase,\r\n    UInt32 ref2Offset,\r\n    UInt32 startIndex,\r\n    const CBoolVector *extractStatuses, \r\n    IArchiveExtractCallback *extractCallback,\r\n    bool testMode,\r\n    bool checkCrc)\r\n{\r\n  _archiveDatabase = archiveDatabase;\r\n  _ref2Offset = ref2Offset;\r\n  _startIndex = startIndex;\r\n\r\n  _extractStatuses = extractStatuses;\r\n  _extractCallback = extractCallback;\r\n  _testMode = testMode;\r\n\r\n  _checkCrc = checkCrc;\r\n\r\n  _currentIndex = 0;\r\n  _fileIsOpen = false;\r\n  return WriteEmptyFiles();\r\n}\r\n\r\nHRESULT CFolderOutStream::OpenFile()\r\n{\r\n  Int32 askMode;\r\n  if((*_extractStatuses)[_currentIndex])\r\n    askMode = _testMode ? \r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n  else\r\n    askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n\r\n  UInt32 index = _startIndex + _currentIndex;\r\n  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));\r\n\r\n  _outStreamWithHashSpec->SetStream(realOutStream);\r\n  _outStreamWithHashSpec->Init(_checkCrc);\r\n  if (askMode == NArchive::NExtract::NAskMode::kExtract &&\r\n      (!realOutStream)) \r\n  {\r\n    const CFileItem &fileInfo = _archiveDatabase->Files[index];\r\n    if (!fileInfo.IsAnti && !fileInfo.IsDirectory)\r\n      askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  }\r\n  return _extractCallback->PrepareOperation(askMode);\r\n}\r\n\r\nHRESULT CFolderOutStream::WriteEmptyFiles()\r\n{\r\n  for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)\r\n  {\r\n    UInt32 index = _startIndex + _currentIndex;\r\n    const CFileItem &fileInfo = _archiveDatabase->Files[index];\r\n    if (!fileInfo.IsAnti && !fileInfo.IsDirectory && fileInfo.UnPackSize != 0)\r\n      return S_OK;\r\n    RINOK(OpenFile());\r\n    RINOK(_extractCallback->SetOperationResult(\r\n        NArchive::NExtract::NOperationResult::kOK));\r\n    _outStreamWithHashSpec->ReleaseStream();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderOutStream::Write(const void *data, \r\n    UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 index = _startIndex + _currentIndex;\r\n      const CFileItem &fileInfo = _archiveDatabase->Files[index];\r\n      UInt64 fileSize = fileInfo.UnPackSize;\r\n      \r\n      UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos, \r\n          UInt64(size - realProcessedSize));\r\n      \r\n      UInt32 processedSizeLocal;\r\n      RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize, \r\n            numBytesToWrite, &processedSizeLocal));\r\n\r\n      _filePos += processedSizeLocal;\r\n      realProcessedSize += processedSizeLocal;\r\n      if (_filePos == fileSize)\r\n      {\r\n        bool digestsAreEqual;\r\n        if (fileInfo.IsFileCRCDefined && _checkCrc)\r\n          digestsAreEqual = fileInfo.FileCRC == _outStreamWithHashSpec->GetCRC();\r\n        else\r\n          digestsAreEqual = true;\r\n\r\n        RINOK(_extractCallback->SetOperationResult(\r\n            digestsAreEqual ? \r\n            NArchive::NExtract::NOperationResult::kOK :\r\n            NArchive::NExtract::NOperationResult::kCRCError));\r\n        _outStreamWithHashSpec->ReleaseStream();\r\n        _fileIsOpen = false;\r\n        _currentIndex++;\r\n      }\r\n      if (realProcessedSize == size)\r\n      {\r\n        if (processedSize != NULL)\r\n          *processedSize = realProcessedSize;\r\n        return WriteEmptyFiles();\r\n      }\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n      _filePos = 0;\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)\r\n{\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      RINOK(_extractCallback->SetOperationResult(resultEOperationResult));\r\n      _outStreamWithHashSpec->ReleaseStream();\r\n      _fileIsOpen = false;\r\n      _currentIndex++;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::WasWritingFinished()\r\n{\r\n  if (_currentIndex == _extractStatuses->Size())\r\n    return S_OK;\r\n  return E_FAIL;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zFolderOutStream.h",
    "content": "// 7zFolderOutStream.h\r\n\r\n#ifndef __7Z_FOLDEROUTSTREAM_H\r\n#define __7Z_FOLDEROUTSTREAM_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../IArchive.h\"\r\n#include \"../Common/OutStreamWithCRC.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  \r\n  CFolderOutStream();\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n\r\n  COutStreamWithCRC *_outStreamWithHashSpec;\r\n  CMyComPtr<ISequentialOutStream> _outStreamWithHash;\r\n  const CArchiveDatabaseEx *_archiveDatabase;\r\n  const CBoolVector *_extractStatuses;\r\n  UInt32 _startIndex;\r\n  UInt32 _ref2Offset;\r\n  int _currentIndex;\r\n  // UInt64 _currentDataPos;\r\n  CMyComPtr<IArchiveExtractCallback> _extractCallback;\r\n  bool _testMode;\r\n\r\n  bool _fileIsOpen;\r\n\r\n  bool _checkCrc;\r\n  UInt64 _filePos;\r\n\r\n  HRESULT OpenFile();\r\n  HRESULT WriteEmptyFiles();\r\npublic:\r\n  HRESULT Init(\r\n      const CArchiveDatabaseEx *archiveDatabase,\r\n      UInt32 ref2Offset,\r\n      UInt32 startIndex,\r\n      const CBoolVector *extractStatuses, \r\n      IArchiveExtractCallback *extractCallback,\r\n      bool testMode,\r\n      bool checkCrc);\r\n  HRESULT FlushCorrupted(Int32 resultEOperationResult);\r\n  HRESULT WasWritingFinished();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zHandler.cpp",
    "content": "// 7zHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zProperties.h\"\r\n\r\n#include \"../../../Common/IntToString.h\"\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Windows/Defs.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#ifdef _7Z_VOL\r\n#include \"../Common/MultiStream.h\"\r\n#endif\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n#include \"../Common/ParseProperties.h\"\r\n#endif\r\n#endif\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nextern UString ConvertMethodIdToString(UInt64 id);\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCHandler::CHandler()\r\n{\r\n  _crcSize = 4;\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  #else\r\n  Init();\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = \r\n  #ifdef _7Z_VOL\r\n  _refs.Size();\r\n  #else\r\n  *numItems = _database.Files.Size();\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _SFX\r\n\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,     \r\n      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\n\r\n#else\r\n\r\nSTATPROPSTG kArcProps[] = \r\n{\r\n  { NULL, kpidMethod, VT_BSTR},\r\n  { NULL, kpidSolid, VT_BOOL},\r\n  { NULL, kpidNumBlocks, VT_UI4}\r\n};\r\n\r\nSTDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidMethod:\r\n    {\r\n      UString resString;\r\n      CRecordVector<UInt64> ids;\r\n      int i;\r\n      for (i = 0; i < _database.Folders.Size(); i++)\r\n      {\r\n        const CFolder &f = _database.Folders[i];\r\n        for (int j = f.Coders.Size() - 1; j >= 0; j--)\r\n          ids.AddToUniqueSorted(f.Coders[j].MethodID);\r\n      }\r\n\r\n      for (i = 0; i < ids.Size(); i++)\r\n      {\r\n        UInt64 id = ids[i];\r\n        UString methodName;\r\n        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);\r\n        if (methodName.IsEmpty())\r\n          methodName = ConvertMethodIdToString(id);\r\n        if (!resString.IsEmpty())\r\n          resString += L' ';\r\n        resString += methodName;\r\n      }\r\n      prop = resString; \r\n      break;\r\n    }\r\n    case kpidSolid: prop = _database.IsSolid(); break;\r\n    case kpidNumBlocks: prop = (UInt32)_database.Folders.Size(); break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nIMP_IInArchive_ArcProps\r\n\r\n#endif\r\n\r\nstatic void MySetFileTime(bool timeDefined, FILETIME unixTime, NWindows::NCOM::CPropVariant &prop)\r\n{\r\n  if (timeDefined)\r\n    prop = unixTime;\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString GetStringForSizeValue(UInt32 value)\r\n{\r\n  for (int i = 31; i >= 0; i--)\r\n    if ((UInt32(1) << i) == value)\r\n      return ConvertUInt32ToString(i);\r\n  UString result;\r\n  if (value % (1 << 20) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 20);\r\n    result += L\"m\";\r\n  }\r\n  else if (value % (1 << 10) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 10);\r\n    result += L\"k\";\r\n  }\r\n  else\r\n  {\r\n    result += ConvertUInt32ToString(value);\r\n    result += L\"b\";\r\n  }\r\n  return result;\r\n}\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_PPMD  = 0x030401;\r\n\r\nstatic wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));\r\n}\r\nstatic inline UString GetHex2(Byte value)\r\n{\r\n  UString result;\r\n  result += GetHex((Byte)(value >> 4));\r\n  result += GetHex((Byte)(value & 0xF));\r\n  return result;\r\n}\r\n\r\n#endif\r\n\r\nstatic const UInt64 k_AES  = 0x06F10701;\r\n\r\n#ifndef _SFX\r\nstatic inline UInt32 GetUInt32FromMemLE(const Byte *p)\r\n{\r\n  return p[0] | (((UInt32)p[1]) << 8) | (((UInt32)p[2]) << 16) | (((UInt32)p[3]) << 24);\r\n}\r\n#endif\r\n\r\nbool CHandler::IsEncrypted(UInt32 index2) const\r\n{\r\n  CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n  if (folderIndex != kNumNoIndex)\r\n  {\r\n    const CFolder &folderInfo = _database.Folders[folderIndex];\r\n    for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n      if (folderInfo.Coders[i].MethodID == k_AES)\r\n        return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  /*\r\n  const CRef2 &ref2 = _refs[index];\r\n  if (ref2.Refs.IsEmpty())\r\n    return E_FAIL;\r\n  const CRef &ref = ref2.Refs.Front();\r\n  */\r\n  \r\n  #ifdef _7Z_VOL\r\n  const CRef &ref = _refs[index];\r\n  const CVolume &volume = _volumes[ref.VolumeIndex];\r\n  const CArchiveDatabaseEx &_database = volume.Database;\r\n  UInt32 index2 = ref.ItemIndex;\r\n  const CFileItem &item = _database.Files[index2];\r\n  #else\r\n  const CFileItem &item = _database.Files[index];\r\n  UInt32 index2 = index;\r\n  #endif\r\n\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n    {\r\n      if (!item.Name.IsEmpty())\r\n        prop = NItemName::GetOSName(item.Name);\r\n      break;\r\n    }\r\n    case kpidIsFolder:\r\n      prop = item.IsDirectory;\r\n      break;\r\n    case kpidSize:\r\n    {\r\n      prop = item.UnPackSize;\r\n      // prop = ref2.UnPackSize;\r\n      break;\r\n    }\r\n    case kpidPosition:\r\n    {\r\n      /*\r\n      if (ref2.Refs.Size() > 1)\r\n        prop = ref2.StartPos;\r\n      else\r\n      */\r\n        if (item.IsStartPosDefined)\r\n          prop = item.StartPos;\r\n      break;\r\n    }\r\n    case kpidPackedSize:\r\n    {\r\n      // prop = ref2.PackSize;\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          if (_database.FolderStartFileIndex[folderIndex] == (CNum)index2)\r\n            prop = _database.GetFolderFullPackSize(folderIndex);\r\n          /*\r\n          else\r\n            prop = (UInt64)0;\r\n          */\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    }\r\n    case kpidLastAccessTime:\r\n      MySetFileTime(item.IsLastAccessTimeDefined, item.LastAccessTime, prop);\r\n      break;\r\n    case kpidCreationTime:\r\n      MySetFileTime(item.IsCreationTimeDefined, item.CreationTime, prop);\r\n      break;\r\n    case kpidLastWriteTime:\r\n      MySetFileTime(item.IsLastWriteTimeDefined, item.LastWriteTime, prop);\r\n      break;\r\n    case kpidAttributes:\r\n      if (item.AreAttributesDefined)\r\n        prop = item.Attributes;\r\n      break;\r\n    case kpidCRC:\r\n      if (item.IsFileCRCDefined)\r\n        prop = item.FileCRC;\r\n      break;\r\n    case kpidEncrypted:\r\n    {\r\n      prop = IsEncrypted(index2);\r\n      break;\r\n    }\r\n    #ifndef _SFX\r\n    case kpidMethod:\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _database.Folders[folderIndex];\r\n          UString methodsString;\r\n          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n          {\r\n            const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n            if (!methodsString.IsEmpty())\r\n              methodsString += L' ';\r\n\r\n            {\r\n              UString methodName;\r\n              bool methodIsKnown = FindMethod(\r\n                  EXTERNAL_CODECS_VARS \r\n                  coderInfo.MethodID, methodName);\r\n\r\n              if (methodIsKnown)\r\n              {\r\n                methodsString += methodName;\r\n                if (coderInfo.MethodID == k_LZMA)\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() >= 5)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    UInt32 dicSize = GetUInt32FromMemLE(\r\n                      ((const Byte *)coderInfo.Properties + 1));\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_PPMD)\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() >= 5)\r\n                  {\r\n                    Byte order = *(const Byte *)coderInfo.Properties;\r\n                    methodsString += L\":o\";\r\n                    methodsString += ConvertUInt32ToString(order);\r\n                    methodsString += L\":mem\";\r\n                    UInt32 dicSize = GetUInt32FromMemLE(\r\n                      ((const Byte *)coderInfo.Properties + 1));\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_AES)\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() >= 1)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    const Byte *data = (const Byte *)coderInfo.Properties;\r\n                    Byte firstByte = *data++;\r\n                    UInt32 numCyclesPower = firstByte & 0x3F;\r\n                    methodsString += ConvertUInt32ToString(numCyclesPower);\r\n                    /*\r\n                    if ((firstByte & 0xC0) != 0)\r\n                    {\r\n                      methodsString += L\":\";\r\n                      return S_OK;\r\n                      UInt32 saltSize = (firstByte >> 7) & 1;\r\n                      UInt32 ivSize = (firstByte >> 6) & 1;\r\n                      if (coderInfo.Properties.GetCapacity() >= 2)\r\n                      {\r\n                        Byte secondByte = *data++;\r\n                        saltSize += (secondByte >> 4);\r\n                        ivSize += (secondByte & 0x0F);\r\n                      }\r\n                    }\r\n                    */\r\n                  }\r\n                }\r\n                else\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() > 0)\r\n                  {\r\n                    methodsString += L\":[\";\r\n                    for (size_t bi = 0; bi < coderInfo.Properties.GetCapacity(); bi++)\r\n                    {\r\n                      if (bi > 5 && bi + 1 < coderInfo.Properties.GetCapacity())\r\n                      {\r\n                        methodsString += L\"..\";\r\n                        break;\r\n                      }\r\n                      else\r\n                        methodsString += GetHex2(coderInfo.Properties[bi]);\r\n                    }\r\n                    methodsString += L\"]\";\r\n                  }\r\n                }\r\n              }\r\n              else\r\n              {\r\n                methodsString += ConvertMethodIdToString(coderInfo.MethodID);\r\n              }\r\n            }\r\n          }\r\n          prop = methodsString;\r\n        }\r\n      }\r\n      break;\r\n    case kpidBlock:\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n          prop = (UInt32)folderIndex;\r\n      }\r\n      break;\r\n    case kpidPackedSize0:\r\n    case kpidPackedSize1:\r\n    case kpidPackedSize2:\r\n    case kpidPackedSize3:\r\n    case kpidPackedSize4:\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _database.Folders[folderIndex];\r\n          if (_database.FolderStartFileIndex[folderIndex] == (CNum)index2 &&\r\n              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))\r\n          {\r\n            prop = _database.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);\r\n          }\r\n          else\r\n            prop = (UInt64)0;\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    #endif\r\n    case kpidIsAnti:\r\n      prop = item.IsAnti;\r\n      break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef _7Z_VOL\r\n\r\nstatic const wchar_t *kExt = L\"7z\";\r\nstatic const wchar_t *kAfterPart = L\".7z\";\r\n\r\nclass CVolumeName\r\n{\r\n  bool _first;\r\n  UString _unchangedPart;\r\n  UString _changedPart;    \r\n  UString _afterPart;    \r\npublic:\r\n  bool InitName(const UString &name)\r\n  {\r\n    _first = true;\r\n    int dotPos = name.ReverseFind('.');\r\n    UString basePart = name;\r\n    if (dotPos >= 0)\r\n    {\r\n      UString ext = name.Mid(dotPos + 1);\r\n      if (ext.CompareNoCase(kExt)==0 || \r\n        ext.CompareNoCase(L\"EXE\") == 0)\r\n      {\r\n        _afterPart = kAfterPart;\r\n        basePart = name.Left(dotPos);\r\n      }\r\n    }\r\n\r\n    int numLetters = 1;\r\n    bool splitStyle = false;\r\n    if (basePart.Right(numLetters) == L\"1\")\r\n    {\r\n      while (numLetters < basePart.Length())\r\n      {\r\n        if (basePart[basePart.Length() - numLetters - 1] != '0')\r\n          break;\r\n        numLetters++;\r\n      }\r\n    }\r\n    else \r\n      return false;\r\n    _unchangedPart = basePart.Left(basePart.Length() - numLetters);\r\n    _changedPart = basePart.Right(numLetters);\r\n    return true;\r\n  }\r\n\r\n  UString GetNextName()\r\n  {\r\n    UString newName; \r\n    // if (_newStyle || !_first)\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == L'9')\r\n        {\r\n          c = L'0';\r\n          newName = c + newName;\r\n          if (i == 0)\r\n            newName = UString(L'1') + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        newName = UString(c) + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n      _changedPart = newName;\r\n    }\r\n    _first = false;\r\n    return _unchangedPart + _changedPart + _afterPart;\r\n  }\r\n};\r\n\r\n#endif\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 *maxCheckStartPosition, \r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Clear();\r\n  #endif\r\n  try\r\n  {\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;\r\n    #ifdef _7Z_VOL\r\n    CVolumeName seqName;\r\n\r\n    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(\r\n          IID_ICryptoGetTextPassword, &getTextPassword);\r\n    }\r\n    #endif\r\n    #ifdef _7Z_VOL\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback);\r\n    }\r\n    for (;;)\r\n    {\r\n      CMyComPtr<IInStream> inStream;\r\n      if (!_volumes.IsEmpty())\r\n      {\r\n        if (!openVolumeCallback)\r\n          break;\r\n        if(_volumes.Size() == 1)\r\n        {\r\n          UString baseName;\r\n          {\r\n            NCOM::CPropVariant prop;\r\n            RINOK(openVolumeCallback->GetProperty(kpidName, &prop));\r\n            if (prop.vt != VT_BSTR)\r\n              break;\r\n            baseName = prop.bstrVal;\r\n          }\r\n          seqName.InitName(baseName);\r\n        }\r\n\r\n        UString fullName = seqName.GetNextName();\r\n        HRESULT result = openVolumeCallback->GetStream(fullName, &inStream);\r\n        if (result == S_FALSE)\r\n          break;\r\n        if (result != S_OK)\r\n          return result;\r\n        if (!stream)\r\n          break;\r\n      }\r\n      else\r\n        inStream = stream;\r\n\r\n      CInArchive archive;\r\n      RINOK(archive.Open(inStream, maxCheckStartPosition));\r\n\r\n      _volumes.Add(CVolume());\r\n      CVolume &volume = _volumes.Back();\r\n      CArchiveDatabaseEx &database = volume.Database;\r\n      volume.Stream = inStream;\r\n      volume.StartRef2Index = _refs.Size();\r\n\r\n      HRESULT result = archive.ReadDatabase(database\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword\r\n          #endif\r\n          );\r\n      if (result != S_OK)\r\n      {\r\n        _volumes.Clear();\r\n        return result;\r\n      }\r\n      database.Fill();\r\n      for(int i = 0; i < database.Files.Size(); i++)\r\n      {\r\n        CRef refNew;\r\n        refNew.VolumeIndex = _volumes.Size() - 1;\r\n        refNew.ItemIndex = i;\r\n        _refs.Add(refNew);\r\n        /*\r\n        const CFileItem &file = database.Files[i];\r\n        int j;\r\n        */\r\n        /*\r\n        for (j = _refs.Size() - 1; j >= 0; j--)\r\n        {\r\n          CRef2 &ref2 = _refs[j];\r\n          const CRef &ref = ref2.Refs.Back();\r\n          const CVolume &volume2 = _volumes[ref.VolumeIndex];\r\n          const CArchiveDatabaseEx &database2 = volume2.Database;\r\n          const CFileItem &file2 = database2.Files[ref.ItemIndex];\r\n          if (file2.Name.CompareNoCase(file.Name) == 0)\r\n          {\r\n            if (!file.IsStartPosDefined)\r\n              continue;\r\n            if (file.StartPos != ref2.StartPos + ref2.UnPackSize)\r\n              continue;\r\n            ref2.Refs.Add(refNew);\r\n            break;\r\n          }\r\n        }\r\n        */\r\n        /*\r\n        j = -1;\r\n        if (j < 0)\r\n        {\r\n          CRef2 ref2New;\r\n          ref2New.Refs.Add(refNew);\r\n          j = _refs.Add(ref2New);\r\n        }\r\n        CRef2 &ref2 = _refs[j];\r\n        ref2.UnPackSize += file.UnPackSize;\r\n        ref2.PackSize += database.GetFilePackSize(i);\r\n        if (ref2.Refs.Size() == 1 && file.IsStartPosDefined)\r\n          ref2.StartPos = file.StartPos;\r\n        */\r\n      }\r\n      if (database.Files.Size() != 1)\r\n        break;\r\n      const CFileItem &file = database.Files.Front();\r\n      if (!file.IsStartPosDefined)\r\n        break;\r\n    }\r\n    #else\r\n    CInArchive archive;\r\n    RINOK(archive.Open(stream, maxCheckStartPosition));\r\n    HRESULT result = archive.ReadDatabase(\r\n      EXTERNAL_CODECS_VARS\r\n      _database\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    _database.Fill();\r\n    _inStream = stream;\r\n    #endif\r\n  }\r\n  catch(...)\r\n  {\r\n    Close();\r\n    return S_FALSE;\r\n  }\r\n  // _inStream = stream;\r\n  #ifndef _SFX\r\n  FillPopIDs();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef _7Z_VOL\r\n  _volumes.Clear();\r\n  _refs.Clear();\r\n  #else\r\n  _inStream.Release();\r\n  _database.Clear();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nSTDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  *stream = 0;\r\n  CMultiStream *streamSpec = new CMultiStream;\r\n  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;\r\n  \r\n  UInt64 pos = 0;\r\n  const UString *fileName;\r\n  for (int i = 0; i < _refs.Size(); i++)\r\n  {\r\n    const CRef &ref = _refs[i];\r\n    const CVolume &volume = _volumes[ref.VolumeIndex];\r\n    const CArchiveDatabaseEx &database = volume.Database;\r\n    const CFileItem &file = database.Files[ref.ItemIndex];\r\n    if (i == 0)\r\n      fileName = &file.Name;\r\n    else\r\n      if (fileName->Compare(file.Name) != 0)\r\n        return S_FALSE;\r\n    if (!file.IsStartPosDefined)\r\n      return S_FALSE;\r\n    if (file.StartPos != pos)\r\n      return S_FALSE;\r\n    CNum folderIndex = database.FileIndexToFolderIndexMap[ref.ItemIndex];\r\n    if (folderIndex == kNumNoIndex)\r\n    {\r\n      if (file.UnPackSize != 0)\r\n        return E_FAIL;\r\n      continue;\r\n    }\r\n    if (database.NumUnPackStreamsVector[folderIndex] != 1)\r\n      return S_FALSE;\r\n    const CFolder &folder = database.Folders[folderIndex];\r\n    if (folder.Coders.Size() != 1)\r\n      return S_FALSE;\r\n    const CCoderInfo &coder = folder.Coders.Front();\r\n    if (coder.NumInStreams != 1 || coder.NumOutStreams != 1)\r\n      return S_FALSE;\r\n    if (coder.MethodID != k_Copy)\r\n      return S_FALSE;\r\n\r\n    pos += file.UnPackSize;\r\n    CMultiStream::CSubStreamInfo subStreamInfo;\r\n    subStreamInfo.Stream = volume.Stream;\r\n    subStreamInfo.Pos = database.GetFolderStreamPos(folderIndex, 0);\r\n    subStreamInfo.Size = file.UnPackSize;\r\n    streamSpec->Streams.Add(subStreamInfo);\r\n  }\r\n  streamSpec->Init();\r\n  *stream = streamTemp.Detach();\r\n  return S_OK;\r\n}\r\n#endif\r\n\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef COMPRESS_MT\r\n  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();\r\n  _numThreads = numProcessors;\r\n  #endif\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    const PROPVARIANT &value = values[i];\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index == 0)\r\n    {\r\n      if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n      {\r\n        #ifdef COMPRESS_MT\r\n        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n        #endif\r\n        continue;\r\n      }\r\n      else\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}  \r\n\r\n#endif\r\n#endif\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zHandler.h",
    "content": "// 7z/Handler.h\r\n\r\n#ifndef __7Z_HANDLER_H\r\n#define __7Z_HANDLER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../IArchive.h\"\r\n#include \"7zIn.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#ifndef EXTRACT_ONLY\r\n#include \"../Common/HandlerOut.h\"\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\n#ifdef _7Z_VOL\r\nstruct CRef\r\n{\r\n  int VolumeIndex;\r\n  int ItemIndex;\r\n};\r\n\r\nstruct CVolume\r\n{\r\n  int StartRef2Index;\r\n  CMyComPtr<IInStream> Stream;\r\n  CArchiveDatabaseEx Database;\r\n};\r\n#endif\r\n\r\n#ifndef __7Z_SET_PROPERTIES\r\n\r\n#ifdef EXTRACT_ONLY\r\n#ifdef COMPRESS_MT\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n#else \r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n\r\n#endif\r\n\r\n\r\nclass CHandler: \r\n  #ifndef EXTRACT_ONLY\r\n  public NArchive::COutHandler,\r\n  #endif\r\n  public IInArchive,\r\n  #ifdef _7Z_VOL\r\n  public IInArchiveGetStream,\r\n  #endif\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  public ISetProperties, \r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public IOutArchive, \r\n  #endif\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IInArchive)\r\n  #ifdef _7Z_VOL\r\n  MY_QUERYINTERFACE_ENTRY(IInArchiveGetStream)\r\n  #endif\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  MY_QUERYINTERFACE_ENTRY(ISetProperties)\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  MY_QUERYINTERFACE_ENTRY(IOutArchive)\r\n  #endif\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  #ifdef _7Z_VOL\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);  \r\n  #endif\r\n\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);\r\n  #endif\r\n\r\n  #ifndef EXTRACT_ONLY\r\n  INTERFACE_IOutArchive(;)\r\n  #endif\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n  CHandler();\r\n\r\nprivate:\r\n  #ifdef _7Z_VOL\r\n  CObjectVector<CVolume> _volumes;\r\n  CObjectVector<CRef> _refs;\r\n  #else\r\n  CMyComPtr<IInStream> _inStream;\r\n  NArchive::N7z::CArchiveDatabaseEx _database;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  \r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  #else\r\n  \r\n  CRecordVector<CBind> _binds;\r\n\r\n  HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);\r\n\r\n  HRESULT SetCompressionMethod(CCompressionMethodMode &method,\r\n      CObjectVector<COneMethodInfo> &methodsInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  HRESULT SetCompressionMethod(\r\n      CCompressionMethodMode &method,\r\n      CCompressionMethodMode &headerMethod);\r\n\r\n  #endif\r\n\r\n  bool IsEncrypted(UInt32 index2) const;\r\n  #ifndef _SFX\r\n\r\n  CRecordVector<UInt64> _fileInfoPopIDs;\r\n  void FillPopIDs();\r\n\r\n  #endif\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zHandlerOut.cpp",
    "content": "// 7zHandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const UInt32 kLzmaAlgorithmX5 = 1;\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5;\r\n\r\nstatic inline bool IsCopyMethod(const UString &methodName)\r\n  { return (methodName.CompareNoCase(kCopyMethod) == 0); }\r\n\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  CMyComPtr<ICryptoGetTextPassword2> getTextPassword;\r\n  if (!getTextPassword)\r\n  {\r\n    CMyComPtr<IArchiveUpdateCallback> udateCallback2(updateCallback);\r\n    udateCallback2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);\r\n  }\r\n  \r\n  if (getTextPassword)\r\n  {\r\n    CMyComBSTR password;\r\n    Int32 passwordIsDefined;\r\n    RINOK(getTextPassword->CryptoGetTextPassword2(\r\n        &passwordIsDefined, &password));\r\n    methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);\r\n    if (methodMode.PasswordIsDefined)\r\n      methodMode.Password = password;\r\n  }\r\n  else\r\n    methodMode.PasswordIsDefined = false;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CCompressionMethodMode &headerMethod)\r\n{\r\n  HRESULT res = SetCompressionMethod(methodMode, _methods\r\n  #ifdef COMPRESS_MT\r\n  , _numThreads\r\n  #endif\r\n  );\r\n  RINOK(res);\r\n  methodMode.Binds = _binds;\r\n\r\n  if (_compressHeaders)\r\n  {\r\n    // headerMethod.Methods.Add(methodMode.Methods.Back());\r\n\r\n    CObjectVector<COneMethodInfo> headerMethodInfoVector;\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = kLZMAMethodName;\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kMatchFinder;\r\n      property.Value = kLzmaMatchFinderForHeaders;\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kAlgorithm;\r\n      property.Value = kAlgorithmForHeaders;\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kNumFastBytes;\r\n      property.Value = UInt32(kNumFastBytesForHeaders);\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n      property.Value = UInt32(kDictionaryForHeaders);\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    headerMethodInfoVector.Add(oneMethodInfo);\r\n    HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector\r\n      #ifdef COMPRESS_MT\r\n      ,1\r\n      #endif\r\n    );\r\n    RINOK(res);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CObjectVector<COneMethodInfo> &methodsInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  \r\n  if (methodsInfo.IsEmpty())\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = ((level == 0) ? kCopyMethod : kDefaultMethodName);\r\n    methodsInfo.Add(oneMethodInfo);\r\n  }\r\n\r\n  bool needSolid = false;\r\n  for(int i = 0; i < methodsInfo.Size(); i++)\r\n  {\r\n    COneMethodInfo &oneMethodInfo = methodsInfo[i];\r\n    SetCompressionMethod2(oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , numThreads\r\n      #endif\r\n      );\r\n\r\n    if (!IsCopyMethod(oneMethodInfo.MethodName))\r\n      needSolid = true;\r\n\r\n    CMethodFull methodFull;\r\n\r\n    if (!FindMethod(\r\n        EXTERNAL_CODECS_VARS\r\n        oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams))\r\n      return E_INVALIDARG;\r\n    methodFull.Properties = oneMethodInfo.Properties;\r\n    methodMode.Methods.Add(methodFull);\r\n\r\n    if (!_numSolidBytesDefined)\r\n    {\r\n      for (int j = 0; j < methodFull.Properties.Size(); j++)\r\n      {\r\n        const CProp &prop = methodFull.Properties[j];\r\n        if ((prop.Id == NCoderPropID::kDictionarySize || \r\n             prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4)\r\n        {\r\n          _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7;\r\n          const UInt64 kMinSize = (1 << 24);\r\n          if (_numSolidBytes < kMinSize)\r\n            _numSolidBytes = kMinSize;\r\n          _numSolidBytesDefined = true;\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (!needSolid && !_numSolidBytesDefined)\r\n  {\r\n    _numSolidBytesDefined = true;\r\n    _numSolidBytes  = 0;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, PROPID propID, CArchiveFileTime &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant propVariant;\r\n  RINOK(updateCallback->GetProperty(index, propID, &propVariant));\r\n  if (propVariant.vt == VT_FILETIME)\r\n  {\r\n    filetime = propVariant.filetime;\r\n    filetimeIsDefined = true;\r\n  }\r\n  else if (propVariant.vt != VT_EMPTY)\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  const CArchiveDatabaseEx *database = 0;\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() > 1)\r\n    return E_FAIL;\r\n  const CVolume *volume = 0;\r\n  if (_volumes.Size() == 1)\r\n  {\r\n    volume = &_volumes.Front();\r\n    database = &volume->Database;\r\n  }\r\n  #else\r\n  if (_inStream != 0)\r\n    database = &_database;\r\n  #endif\r\n\r\n  // CRecordVector<bool> compressStatuses;\r\n  CObjectVector<CUpdateItem> updateItems;\r\n  // CRecordVector<UInt32> copyIndices;\r\n  \r\n  // CMyComPtr<IUpdateCallback2> updateCallback2;\r\n  // updateCallback->QueryInterface(&updateCallback2);\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    Int32 newData;\r\n    Int32 newProperties;\r\n    UInt32 indexInArchive;\r\n    if (!updateCallback)\r\n      return E_FAIL;\r\n    RINOK(updateCallback->GetUpdateItemInfo(i,\r\n        &newData, &newProperties, &indexInArchive));\r\n    CUpdateItem updateItem;\r\n    updateItem.NewProperties = IntToBool(newProperties);\r\n    updateItem.NewData = IntToBool(newData);\r\n    updateItem.IndexInArchive = indexInArchive;\r\n    updateItem.IndexInClient = i;\r\n    updateItem.IsAnti = false;\r\n    updateItem.Size = 0;\r\n\r\n    if (updateItem.IndexInArchive != -1)\r\n    {\r\n      const CFileItem &fileItem = database->Files[updateItem.IndexInArchive];\r\n      updateItem.Name = fileItem.Name;\r\n      updateItem.IsDirectory = fileItem.IsDirectory;\r\n      updateItem.Size = fileItem.UnPackSize;\r\n      updateItem.IsAnti = fileItem.IsAnti;\r\n      \r\n      updateItem.CreationTime = fileItem.CreationTime;\r\n      updateItem.IsCreationTimeDefined = fileItem.IsCreationTimeDefined;\r\n      updateItem.LastWriteTime = fileItem.LastWriteTime;\r\n      updateItem.IsLastWriteTimeDefined = fileItem.IsLastWriteTimeDefined;\r\n      updateItem.LastAccessTime = fileItem.LastAccessTime;\r\n      updateItem.IsLastAccessTimeDefined = fileItem.IsLastAccessTimeDefined;\r\n    }\r\n\r\n    if (updateItem.NewProperties)\r\n    {\r\n      bool nameIsDefined;\r\n      bool folderStatusIsDefined;\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidAttributes, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          updateItem.AttributesAreDefined = false;\r\n        else if (propVariant.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          updateItem.Attributes = propVariant.ulVal;\r\n          updateItem.AttributesAreDefined = true;\r\n        }\r\n      }\r\n      \r\n      RINOK(GetTime(updateCallback, i, kpidCreationTime, updateItem.CreationTime, updateItem.IsCreationTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, kpidLastWriteTime, updateItem.LastWriteTime , updateItem.IsLastWriteTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, kpidLastAccessTime, updateItem.LastAccessTime, updateItem.IsLastAccessTimeDefined));\r\n\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidPath, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          nameIsDefined = false;\r\n        else if (propVariant.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          updateItem.Name = NItemName::MakeLegalName(propVariant.bstrVal);\r\n          nameIsDefined = true;\r\n        }\r\n      }\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsFolder, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          folderStatusIsDefined = false;\r\n        else if (propVariant.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          updateItem.IsDirectory = (propVariant.boolVal != VARIANT_FALSE);\r\n          folderStatusIsDefined = true;\r\n        }\r\n      }\r\n\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsAnti, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          updateItem.IsAnti = false;\r\n        else if (propVariant.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n          updateItem.IsAnti = (propVariant.boolVal != VARIANT_FALSE);\r\n      }\r\n\r\n      if (updateItem.IsAnti)\r\n      {\r\n        updateItem.AttributesAreDefined = false;\r\n\r\n        updateItem.IsCreationTimeDefined = false;\r\n        updateItem.IsLastWriteTimeDefined = false;\r\n        updateItem.IsLastAccessTimeDefined = false;\r\n        \r\n        updateItem.Size = 0;\r\n      }\r\n\r\n      if (!folderStatusIsDefined && updateItem.AttributesAreDefined)\r\n        updateItem.SetDirectoryStatusFromAttributes();\r\n    }\r\n\r\n    if (updateItem.NewData)\r\n    {\r\n      NCOM::CPropVariant propVariant;\r\n      RINOK(updateCallback->GetProperty(i, kpidSize, &propVariant));\r\n      if (propVariant.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      updateItem.Size = (UInt64)propVariant.uhVal.QuadPart;\r\n      if (updateItem.Size != 0 && updateItem.IsAnti)\r\n        return E_INVALIDARG;\r\n    }\r\n    updateItems.Add(updateItem);\r\n  }\r\n\r\n  CCompressionMethodMode methodMode, headerMethod;\r\n  RINOK(SetCompressionMethod(methodMode, headerMethod));\r\n  #ifdef COMPRESS_MT\r\n  methodMode.NumThreads = _numThreads;\r\n  headerMethod.NumThreads = 1;\r\n  #endif\r\n\r\n  RINOK(SetPassword(methodMode, updateCallback));\r\n\r\n  bool compressMainHeader = _compressHeaders;  // check it\r\n\r\n  if (methodMode.PasswordIsDefined)\r\n  {\r\n    compressMainHeader = true; \r\n    if(_encryptHeaders)\r\n      RINOK(SetPassword(headerMethod, updateCallback));\r\n  }\r\n\r\n  if (numItems < 2)\r\n    compressMainHeader = false;\r\n\r\n  CUpdateOptions options;\r\n  options.Method = &methodMode;\r\n  options.HeaderMethod = (_compressHeaders || \r\n      (methodMode.PasswordIsDefined && _encryptHeaders)) ? \r\n      &headerMethod : 0;\r\n  options.UseFilters = _level != 0 && _autoFilter;\r\n  options.MaxFilter = _level >= 8;\r\n\r\n  options.HeaderOptions.CompressMainHeader = compressMainHeader;\r\n  options.HeaderOptions.WriteModified = WriteModified;\r\n  options.HeaderOptions.WriteCreated = WriteCreated;\r\n  options.HeaderOptions.WriteAccessed = WriteAccessed;\r\n  \r\n  options.NumSolidFiles = _numSolidFiles;\r\n  options.NumSolidBytes = _numSolidBytes;\r\n  options.SolidExtension = _solidExtension;\r\n  options.RemoveSfxBlock = _removeSfxBlock;\r\n  options.VolumeMode = _volumeMode;\r\n  return Update(\r\n      EXTERNAL_CODECS_VARS\r\n      #ifdef _7Z_VOL\r\n      volume ? volume->Stream: 0, \r\n      volume ? database: 0, \r\n      #else\r\n      _inStream, \r\n      database,\r\n      #endif\r\n      updateItems, outStream, updateCallback, options);\r\n  COM_TRY_END\r\n}\r\n\r\nstatic HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)\r\n{\r\n  stream = 0;\r\n  int index = ParseStringToUInt32(srcString, coder);\r\n  if (index == 0)\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0, index);\r\n  if (srcString[0] == 'S')\r\n  {\r\n    srcString.Delete(0);\r\n    int index = ParseStringToUInt32(srcString, stream);\r\n    if (index == 0)\r\n      return E_INVALIDARG;\r\n    srcString.Delete(0, index);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetBindInfo(UString &srcString, CBind &bind)\r\n{\r\n  RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream));\r\n  if (srcString[0] != ':')\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0);\r\n  RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream));\r\n  if (!srcString.IsEmpty())\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  _binds.Clear();\r\n  BeforeSetProperty();\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n\r\n    const PROPVARIANT &value = values[i];\r\n\r\n    if (name[0] == 'B')\r\n    {\r\n      name.Delete(0);\r\n      CBind bind;\r\n      RINOK(GetBindInfo(name, bind));\r\n      _binds.Add(bind);\r\n      continue;\r\n    }\r\n\r\n    RINOK(SetProperty(name, value));\r\n  }\r\n\r\n  return S_OK;\r\n  COM_TRY_END\r\n}  \r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zHeader.cpp",
    "content": "// 7z/Header.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nByte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n#ifdef _7Z_VOL\r\nByte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};\r\n#endif\r\n\r\nclass SignatureInitializer\r\n{\r\npublic:\r\n  SignatureInitializer() \r\n  { \r\n    kSignature[0]--; \r\n    #ifdef _7Z_VOL\r\n    kFinishSignature[0]--;\r\n    #endif\r\n  };\r\n} g_SignatureInitializer;\r\n\r\n}}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zHeader.h",
    "content": "// 7z/7zHeader.h\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nconst int kSignatureSize = 6;\r\nextern Byte kSignature[kSignatureSize];\r\n\r\n// #define _7Z_VOL\r\n// 7z-MultiVolume is not finished yet.\r\n// It can work already, but I still do not like some \r\n// things of that new multivolume format.\r\n// So please keep it commented.\r\n\r\n#ifdef _7Z_VOL\r\nextern Byte kFinishSignature[kSignatureSize];\r\n#endif\r\n\r\nstruct CArchiveVersion\r\n{\r\n  Byte Major;\r\n  Byte Minor;\r\n};\r\n\r\nconst Byte kMajorVersion = 0;\r\n\r\nstruct CStartHeader\r\n{\r\n  UInt64 NextHeaderOffset;\r\n  UInt64 NextHeaderSize;\r\n  UInt32 NextHeaderCRC;\r\n};\r\n\r\nconst UInt32 kStartHeaderSize = 20;\r\n\r\n#ifdef _7Z_VOL\r\nstruct CFinishHeader: public CStartHeader\r\n{\r\n  UInt64 ArchiveStartOffset;  // data offset from end if that struct\r\n  UInt64 AdditionalStartBlockSize; // start  signature & start header size\r\n};\r\n\r\nconst UInt32 kFinishHeaderSize = kStartHeaderSize + 16;\r\n#endif\r\n\r\nnamespace NID\r\n{\r\n  enum EEnum\r\n  {\r\n    kEnd,\r\n\r\n    kHeader,\r\n\r\n    kArchiveProperties,\r\n    \r\n    kAdditionalStreamsInfo,\r\n    kMainStreamsInfo,\r\n    kFilesInfo,\r\n    \r\n    kPackInfo,\r\n    kUnPackInfo,\r\n    kSubStreamsInfo,\r\n\r\n    kSize,\r\n    kCRC,\r\n\r\n    kFolder,\r\n\r\n    kCodersUnPackSize,\r\n    kNumUnPackStream,\r\n\r\n    kEmptyStream,\r\n    kEmptyFile,\r\n    kAnti,\r\n\r\n    kName,\r\n    kCreationTime,\r\n    kLastAccessTime,\r\n    kLastWriteTime,\r\n    kWinAttributes,\r\n    kComment,\r\n\r\n    kEncodedHeader,\r\n\r\n    kStartPos\r\n  };\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zIn.cpp",
    "content": "// 7zIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zDecode.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\n// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader \r\n#ifndef _SFX\r\n#define FORMAT_7Z_RECOVERY\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CInArchiveException {};\r\n\r\nstatic void ThrowException() { throw CInArchiveException(); }\r\nstatic inline void ThrowEndOfData()   { ThrowException(); }\r\nstatic inline void ThrowUnsupported() { ThrowException(); }\r\nstatic inline void ThrowIncorrect()   { ThrowException(); }\r\nstatic inline void ThrowUnsupportedVersion() { ThrowException(); }\r\n\r\n/*\r\nclass CInArchiveException\r\n{\r\npublic:\r\n  enum CCauseType\r\n  {\r\n    kUnsupportedVersion = 0,\r\n    kUnsupported,\r\n    kIncorrect, \r\n    kEndOfData,\r\n  } Cause;\r\n  CInArchiveException(CCauseType cause): Cause(cause) {};\r\n};\r\n\r\nstatic void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }\r\nstatic void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }\r\nstatic void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }\r\nstatic void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }\r\nstatic void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }\r\n*/\r\n\r\nclass CStreamSwitch\r\n{\r\n  CInArchive *_archive;\r\n  bool _needRemove;\r\npublic:\r\n  CStreamSwitch(): _needRemove(false) {}\r\n  ~CStreamSwitch() { Remove(); }\r\n  void Remove();\r\n  void Set(CInArchive *archive, const Byte *data, size_t size);\r\n  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);\r\n  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);\r\n};\r\n\r\nvoid CStreamSwitch::Remove()\r\n{\r\n  if (_needRemove)\r\n  {\r\n    _archive->DeleteByteStream();\r\n    _needRemove = false;\r\n  }\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)\r\n{\r\n  Remove();\r\n  _archive = archive;\r\n  _archive->AddByteStream(data, size);\r\n  _needRemove = true;\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)\r\n{\r\n  Set(archive, byteBuffer, byteBuffer.GetCapacity());\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)\r\n{\r\n  Remove();\r\n  Byte external = archive->ReadByte();\r\n  if (external != 0)\r\n  {\r\n    int dataIndex = (int)archive->ReadNum();\r\n    if (dataIndex < 0 || dataIndex >= dataVector->Size())\r\n      ThrowIncorrect();\r\n    Set(archive, (*dataVector)[dataIndex]);\r\n  }\r\n}\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define SZ_LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#ifdef SZ_LITTLE_ENDIAN_UNALIGN\r\nstatic inline UInt16 GetUInt16FromMem(const Byte *p) { return *(const UInt16 *)p; }\r\nstatic inline UInt32 GetUInt32FromMem(const Byte *p) { return *(const UInt32 *)p; }\r\nstatic inline UInt64 GetUInt64FromMem(const Byte *p) { return *(const UInt64 *)p; }\r\n#else\r\nstatic inline UInt16 GetUInt16FromMem(const Byte *p) { return p[0] | ((UInt16)p[1] << 8); }\r\nstatic inline UInt32 GetUInt32FromMem(const Byte *p) { return p[0] | ((UInt32)p[1] << 8) | ((UInt32)p[2] << 16) | ((UInt32)p[3] << 24); }\r\nstatic inline UInt64 GetUInt64FromMem(const Byte *p) { return GetUInt32FromMem(p) | ((UInt64)GetUInt32FromMem(p + 4) << 32); }\r\n#endif\r\n\r\nByte CInByte2::ReadByte()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  return _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::ReadBytes(Byte *data, size_t size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  for (size_t i = 0; i < size; i++)\r\n    data[i] = _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::SkeepData(UInt64 size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n}\r\n\r\nvoid CInByte2::SkeepData()\r\n{\r\n  SkeepData(ReadNumber());\r\n}\r\n\r\nUInt64 CInByte2::ReadNumber()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  Byte firstByte = _buffer[_pos++];\r\n  Byte mask = 0x80;\r\n  UInt64 value = 0;\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      value += (highPart << (i * 8));\r\n      return value;\r\n    }\r\n    if (_pos >= _size)\r\n      ThrowEndOfData();\r\n    value |= ((UInt64)_buffer[_pos++] << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return value;\r\n}\r\n\r\nCNum CInByte2::ReadNum()\r\n{ \r\n  UInt64 value = ReadNumber(); \r\n  if (value > kNumMax)\r\n    ThrowUnsupported();\r\n  return (CNum)value;\r\n}\r\n\r\nUInt32 CInByte2::ReadUInt32()\r\n{\r\n  if (_pos + 4 > _size)\r\n    ThrowEndOfData();\r\n  UInt32 res = GetUInt32FromMem(_buffer + _pos);\r\n  _pos += 4;\r\n  return res;\r\n}\r\n\r\nUInt64 CInByte2::ReadUInt64()\r\n{\r\n  if (_pos + 8 > _size)\r\n    ThrowEndOfData();\r\n  UInt64 res = GetUInt64FromMem(_buffer + _pos);\r\n  _pos += 8;\r\n  return res;\r\n}\r\n\r\nvoid CInByte2::ReadString(UString &s)\r\n{\r\n  const Byte *buf = _buffer + _pos;\r\n  size_t rem = (_size - _pos) / 2 * 2;\r\n  {\r\n    size_t i;\r\n    for (i = 0; i < rem; i += 2)\r\n      if (buf[i] == 0 && buf[i + 1] == 0)\r\n        break;\r\n    if (i == rem)\r\n      ThrowEndOfData();\r\n    rem = i;\r\n  }\r\n  int len = (int)(rem / 2);\r\n  if (len < 0 || (size_t)len * 2 != rem)\r\n    ThrowUnsupported();\r\n  wchar_t *p = s.GetBuffer(len);\r\n  int i;\r\n  for (i = 0; i < len; i++, buf += 2) \r\n    p[i] = (wchar_t)GetUInt16FromMem(buf);\r\n  p[i] = 0;\r\n  s.ReleaseBuffer(len);\r\n  _pos += rem + 2;\r\n}\r\n\r\nstatic inline bool TestSignatureCandidate(const Byte *p)\r\n{\r\n  for (int i = 0; i < kSignatureSize; i++)\r\n    if (p[i] != kSignature[i])\r\n      return false;\r\n  return (p[0x1A] == 0 && p[0x1B] == 0);\r\n}\r\n\r\nHRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  UInt32 processedSize; \r\n  RINOK(ReadStream(stream, _header, kHeaderSize, &processedSize));\r\n  if (processedSize != kHeaderSize)\r\n    return S_FALSE;\r\n  if (TestSignatureCandidate(_header))\r\n    return S_OK;\r\n\r\n  CByteBuffer byteBuffer;\r\n  const UInt32 kBufferSize = (1 << 16);\r\n  byteBuffer.SetCapacity(kBufferSize);\r\n  Byte *buffer = byteBuffer;\r\n  UInt32 numPrevBytes = kHeaderSize - 1;\r\n  memcpy(buffer, _header + 1, numPrevBytes);\r\n  UInt64 curTestPos = _arhiveBeginStreamPosition + 1;\r\n  for (;;)\r\n  {\r\n    if (searchHeaderSizeLimit != NULL)\r\n      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)\r\n        break;\r\n    UInt32 numReadBytes = kBufferSize - numPrevBytes;\r\n    RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));\r\n    UInt32 numBytesInBuffer = numPrevBytes + processedSize;\r\n    if (numBytesInBuffer < kHeaderSize)\r\n      break;\r\n    UInt32 numTests = numBytesInBuffer - kHeaderSize + 1;\r\n    for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++)\r\n    { \r\n      if (TestSignatureCandidate(buffer + pos))\r\n      {\r\n        memcpy(_header, buffer + pos, kHeaderSize);\r\n        _arhiveBeginStreamPosition = curTestPos;\r\n        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);\r\n      }\r\n    }\r\n    numPrevBytes = numBytesInBuffer - numTests;\r\n    memmove(buffer, buffer + numTests, numPrevBytes);\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\n// S_FALSE means that file is not archive\r\nHRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  Close();\r\n  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))\r\n  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));\r\n  _stream = stream;\r\n  return S_OK;\r\n}\r\n  \r\nvoid CInArchive::Close()\r\n{\r\n  _stream.Release();\r\n}\r\n\r\nvoid CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)\r\n{\r\n  for (;;)\r\n  {\r\n    if (ReadID() == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::GetNextFolderItem(CFolder &folder)\r\n{\r\n  CNum numCoders = ReadNum();\r\n\r\n  folder.Coders.Clear();\r\n  folder.Coders.Reserve((int)numCoders);\r\n  CNum numInStreams = 0;\r\n  CNum numOutStreams = 0;\r\n  CNum i;\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    folder.Coders.Add(CCoderInfo());\r\n    CCoderInfo &coder = folder.Coders.Back();\r\n\r\n    {\r\n      Byte mainByte = ReadByte();\r\n      int idSize = (mainByte & 0xF);\r\n      Byte longID[15];\r\n      ReadBytes(longID, idSize);\r\n      if (idSize > 8)\r\n        ThrowUnsupported();\r\n      UInt64 id = 0;\r\n      for (int j = 0; j < idSize; j++)\r\n        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n      coder.MethodID = id;\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        coder.NumInStreams = ReadNum();\r\n        coder.NumOutStreams = ReadNum();\r\n      }\r\n      else\r\n      {\r\n        coder.NumInStreams = 1;\r\n        coder.NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        CNum propertiesSize = ReadNum();\r\n        coder.Properties.SetCapacity((size_t)propertiesSize);\r\n        ReadBytes((Byte *)coder.Properties, (size_t)propertiesSize);\r\n      }\r\n      if ((mainByte & 0x80) != 0)\r\n        ThrowUnsupported();\r\n    }\r\n    numInStreams += coder.NumInStreams;\r\n    numOutStreams += coder.NumOutStreams;\r\n  }\r\n\r\n  CNum numBindPairs;\r\n  numBindPairs = numOutStreams - 1;\r\n  folder.BindPairs.Clear();\r\n  folder.BindPairs.Reserve(numBindPairs);\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = ReadNum();\r\n    bindPair.OutIndex = ReadNum(); \r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n\r\n  CNum numPackedStreams = numInStreams - numBindPairs;\r\n  folder.PackStreams.Reserve(numPackedStreams);\r\n  if (numPackedStreams == 1)\r\n  {\r\n    for (CNum j = 0; j < numInStreams; j++)\r\n      if (folder.FindBindPairForInStream(j) < 0)\r\n      {\r\n        folder.PackStreams.Add(j);\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n      folder.PackStreams.Add(ReadNum());\r\n}\r\n\r\nvoid CInArchive::WaitAttribute(UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == attribute)\r\n      return;\r\n    if (type == NID::kEnd)\r\n      ThrowIncorrect();\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadHashDigests(int numItems,\r\n    CRecordVector<bool> &digestsDefined, \r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  ReadBoolVector2(numItems, digestsDefined);\r\n  digests.Clear();\r\n  digests.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 crc = 0;\r\n    if (digestsDefined[i])\r\n      crc = ReadUInt32();\r\n    digests.Add(crc);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadPackInfo(\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CRecordVector<bool> &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs)\r\n{\r\n  dataOffset = ReadNumber();\r\n  CNum numPackStreams = ReadNum();\r\n\r\n  WaitAttribute(NID::kSize);\r\n  packSizes.Clear();\r\n  packSizes.Reserve(numPackStreams);\r\n  for (CNum i = 0; i < numPackStreams; i++)\r\n    packSizes.Add(ReadNumber());\r\n\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    if (type == NID::kCRC)\r\n    {\r\n      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs); \r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n  if (packCRCsDefined.IsEmpty())\r\n  {\r\n    packCRCsDefined.Reserve(numPackStreams);\r\n    packCRCsDefined.Clear();\r\n    packCRCs.Reserve(numPackStreams);\r\n    packCRCs.Clear();\r\n    for(CNum i = 0; i < numPackStreams; i++)\r\n    {\r\n      packCRCsDefined.Add(false);\r\n      packCRCs.Add(0);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadUnPackInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    CObjectVector<CFolder> &folders)\r\n{\r\n  WaitAttribute(NID::kFolder);\r\n  CNum numFolders = ReadNum();\r\n\r\n  {\r\n    CStreamSwitch streamSwitch;\r\n    streamSwitch.Set(this, dataVector);\r\n    folders.Clear();\r\n    folders.Reserve(numFolders);\r\n    for(CNum i = 0; i < numFolders; i++)\r\n    {\r\n      folders.Add(CFolder());\r\n      GetNextFolderItem(folders.Back());\r\n    }\r\n  }\r\n\r\n  WaitAttribute(NID::kCodersUnPackSize);\r\n\r\n  CNum i;\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    CFolder &folder = folders[i];\r\n    CNum numOutStreams = folder.GetNumOutStreams();\r\n    folder.UnPackSizes.Reserve(numOutStreams);\r\n    for (CNum j = 0; j < numOutStreams; j++)\r\n      folder.UnPackSizes.Add(ReadNumber());\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      return;\r\n    if (type == NID::kCRC)\r\n    {\r\n      CRecordVector<bool> crcsDefined;\r\n      CRecordVector<UInt32> crcs;\r\n      ReadHashDigests(numFolders, crcsDefined, crcs); \r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        CFolder &folder = folders[i];\r\n        folder.UnPackCRCDefined = crcsDefined[i];\r\n        folder.UnPackCRC = crcs[i];\r\n      }\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n    CRecordVector<UInt64> &unPackSizes,\r\n    CRecordVector<bool> &digestsDefined, \r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  numUnPackStreamsInFolders.Clear();\r\n  numUnPackStreamsInFolders.Reserve(folders.Size());\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kNumUnPackStream)\r\n    {\r\n      for(int i = 0; i < folders.Size(); i++)\r\n        numUnPackStreamsInFolders.Add(ReadNum());\r\n      continue;\r\n    }\r\n    if (type == NID::kCRC || type == NID::kSize)\r\n      break;\r\n    if (type == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n\r\n  if (numUnPackStreamsInFolders.IsEmpty())\r\n    for(int i = 0; i < folders.Size(); i++)\r\n      numUnPackStreamsInFolders.Add(1);\r\n\r\n  int i;\r\n  for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n  {\r\n    // v3.13 incorrectly worked with empty folders\r\n    // v4.07: we check that folder is empty\r\n    CNum numSubstreams = numUnPackStreamsInFolders[i];\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    UInt64 sum = 0;\r\n    for (CNum j = 1; j < numSubstreams; j++)\r\n      if (type == NID::kSize)\r\n      {\r\n        UInt64 size = ReadNumber();\r\n        unPackSizes.Add(size);\r\n        sum += size;\r\n      }\r\n    unPackSizes.Add(folders[i].GetUnPackSize() - sum);\r\n  }\r\n  if (type == NID::kSize)\r\n    type = ReadID();\r\n\r\n  int numDigests = 0;\r\n  int numDigestsTotal = 0;\r\n  for(i = 0; i < folders.Size(); i++)\r\n  {\r\n    CNum numSubstreams = numUnPackStreamsInFolders[i];\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n    numDigestsTotal += numSubstreams;\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    if (type == NID::kCRC)\r\n    {\r\n      CRecordVector<bool> digestsDefined2; \r\n      CRecordVector<UInt32> digests2;\r\n      ReadHashDigests(numDigests, digestsDefined2, digests2);\r\n      int digestIndex = 0;\r\n      for (i = 0; i < folders.Size(); i++)\r\n      {\r\n        CNum numSubstreams = numUnPackStreamsInFolders[i];\r\n        const CFolder &folder = folders[i];\r\n        if (numSubstreams == 1 && folder.UnPackCRCDefined)\r\n        {\r\n          digestsDefined.Add(true);\r\n          digests.Add(folder.UnPackCRC);\r\n        }\r\n        else\r\n          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)\r\n          {\r\n            digestsDefined.Add(digestsDefined2[digestIndex]);\r\n            digests.Add(digests2[digestIndex]);\r\n          }\r\n      }\r\n    }\r\n    else if (type == NID::kEnd)\r\n    {\r\n      if (digestsDefined.IsEmpty())\r\n      {\r\n        digestsDefined.Clear();\r\n        digests.Clear();\r\n        for (int i = 0; i < numDigestsTotal; i++)\r\n        {\r\n          digestsDefined.Add(false);\r\n          digests.Add(0);\r\n        }\r\n      }\r\n      return;\r\n    }\r\n    else\r\n      SkeepData();\r\n    type = ReadID();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadStreamsInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CRecordVector<bool> &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs,\r\n    CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n    CRecordVector<UInt64> &unPackSizes,\r\n    CRecordVector<bool> &digestsDefined, \r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type > ((UInt32)1 << 30))\r\n      ThrowIncorrect();\r\n    switch((UInt32)type)\r\n    {\r\n      case NID::kEnd:\r\n        return;\r\n      case NID::kPackInfo:\r\n      {\r\n        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);\r\n        break;\r\n      }\r\n      case NID::kUnPackInfo:\r\n      {\r\n        ReadUnPackInfo(dataVector, folders);\r\n        break;\r\n      }\r\n      case NID::kSubStreamsInfo:\r\n      {\r\n        ReadSubStreamsInfo(folders, numUnPackStreamsInFolders,\r\n            unPackSizes, digestsDefined, digests);\r\n        break;\r\n      }\r\n      default:\r\n        ThrowIncorrect();\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector(int numItems, CBoolVector &v)\r\n{\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  for(int i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      b = ReadByte();\r\n      mask = 0x80;\r\n    }\r\n    v.Add((b & mask) != 0);\r\n    mask >>= 1;\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)\r\n{\r\n  Byte allAreDefined = ReadByte();\r\n  if (allAreDefined == 0)\r\n  {\r\n    ReadBoolVector(numItems, v);\r\n    return;\r\n  }\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n    v.Add(true);\r\n}\r\n\r\nvoid CInArchive::ReadTime(const CObjectVector<CByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt32 type)\r\n{\r\n  CBoolVector boolVector;\r\n  ReadBoolVector2(files.Size(), boolVector);\r\n\r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, &dataVector);\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    fileTime.dwLowDateTime = 0;\r\n    fileTime.dwHighDateTime = 0;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      fileTime.dwLowDateTime = ReadUInt32();\r\n      fileTime.dwHighDateTime = ReadUInt32();\r\n    }\r\n    switch(type)\r\n    {\r\n      case NID::kCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case NID::kLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case NID::kLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadAndDecodePackedStreams(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    UInt64 baseOffset, \r\n    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  CRecordVector<UInt64> packSizes;\r\n  CRecordVector<bool> packCRCsDefined;\r\n  CRecordVector<UInt32> packCRCs;\r\n  CObjectVector<CFolder> folders;\r\n  \r\n  CRecordVector<CNum> numUnPackStreamsInFolders;\r\n  CRecordVector<UInt64> unPackSizes;\r\n  CRecordVector<bool> digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  ReadStreamsInfo(NULL, \r\n    dataOffset,\r\n    packSizes, \r\n    packCRCsDefined, \r\n    packCRCs, \r\n    folders,\r\n    numUnPackStreamsInFolders,\r\n    unPackSizes,\r\n    digestsDefined, \r\n    digests);\r\n  \r\n  // database.ArchiveInfo.DataStartPosition2 += database.ArchiveInfo.StartPositionAfterHeader;\r\n  \r\n  CNum packIndex = 0;\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  UInt64 dataStartPos = baseOffset + dataOffset;\r\n  for(int i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    dataVector.Add(CByteBuffer());\r\n    CByteBuffer &data = dataVector.Back();\r\n    UInt64 unPackSize64 = folder.GetUnPackSize();\r\n    size_t unPackSize = (size_t)unPackSize64;\r\n    if (unPackSize != unPackSize64)\r\n      ThrowUnsupported();\r\n    data.SetCapacity(unPackSize);\r\n    \r\n    CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    outStreamSpec->Init(data, unPackSize);\r\n    \r\n    HRESULT result = decoder.Decode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      _stream, dataStartPos, \r\n      &packSizes[packIndex], folder, outStream, NULL\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , false, 1\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    \r\n    if (folder.UnPackCRCDefined)\r\n      if (CrcCalc(data, unPackSize) != folder.UnPackCRC)\r\n        ThrowIncorrect();\r\n      for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n        dataStartPos += packSizes[packIndex++];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CInArchive::ReadHeader(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &database\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  UInt64 type = ReadID();\r\n\r\n  if (type == NID::kArchiveProperties)\r\n  {\r\n    ReadArchiveProperties(database.ArchiveInfo);\r\n    type = ReadID();\r\n  }\r\n \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  if (type == NID::kAdditionalStreamsInfo)\r\n  {\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        database.ArchiveInfo.StartPositionAfterHeader, \r\n        database.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    database.ArchiveInfo.DataStartPosition2 += database.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n\r\n  CRecordVector<UInt64> unPackSizes;\r\n  CRecordVector<bool> digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  if (type == NID::kMainStreamsInfo)\r\n  {\r\n    ReadStreamsInfo(&dataVector,\r\n        database.ArchiveInfo.DataStartPosition,\r\n        database.PackSizes, \r\n        database.PackCRCsDefined, \r\n        database.PackCRCs, \r\n        database.Folders,\r\n        database.NumUnPackStreamsVector,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    database.ArchiveInfo.DataStartPosition += database.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n  else\r\n  {\r\n    for(int i = 0; i < database.Folders.Size(); i++)\r\n    {\r\n      database.NumUnPackStreamsVector.Add(1);\r\n      CFolder &folder = database.Folders[i];\r\n      unPackSizes.Add(folder.GetUnPackSize());\r\n      digestsDefined.Add(folder.UnPackCRCDefined);\r\n      digests.Add(folder.UnPackCRC);\r\n    }\r\n  }\r\n\r\n  database.Files.Clear();\r\n\r\n  if (type == NID::kEnd)\r\n    return S_OK;\r\n  if (type != NID::kFilesInfo)\r\n    ThrowIncorrect();\r\n  \r\n  CNum numFiles = ReadNum();\r\n  database.Files.Reserve(numFiles);\r\n  CNum i;\r\n  for(i = 0; i < numFiles; i++)\r\n    database.Files.Add(CFileItem());\r\n\r\n  database.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);\r\n  if (!database.PackSizes.IsEmpty())\r\n    database.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);\r\n  if (numFiles > 0  && !digests.IsEmpty())\r\n    database.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);\r\n\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve((int)numFiles);\r\n  for(i = 0; i < numFiles; i++)\r\n    emptyStreamVector.Add(false);\r\n  CBoolVector emptyFileVector;\r\n  CBoolVector antiFileVector;\r\n  CNum numEmptyStreams = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    UInt64 size = ReadNumber();\r\n    bool isKnownType = true;\r\n    if (type > ((UInt32)1 << 30))\r\n      isKnownType = false;\r\n    else switch((UInt32)type)\r\n    {\r\n      case NID::kName:\r\n      {\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for(int i = 0; i < database.Files.Size(); i++)\r\n          _inByteBack->ReadString(database.Files[i].Name);\r\n        break;\r\n      }\r\n      case NID::kWinAttributes:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(database.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for(i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = database.Files[i];\r\n          file.AreAttributesDefined = boolVector[i];\r\n          if (file.AreAttributesDefined)\r\n            file.Attributes = ReadUInt32();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kStartPos:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(database.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for(i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = database.Files[i];\r\n          file.IsStartPosDefined = boolVector[i];\r\n          if (file.IsStartPosDefined)\r\n            file.StartPos = ReadUInt64();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyStream:\r\n      {\r\n        ReadBoolVector(numFiles, emptyStreamVector);\r\n        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)\r\n          if (emptyStreamVector[i])\r\n            numEmptyStreams++;\r\n        emptyFileVector.Reserve(numEmptyStreams);\r\n        antiFileVector.Reserve(numEmptyStreams);\r\n        for (i = 0; i < numEmptyStreams; i++)\r\n        {\r\n          emptyFileVector.Add(false);\r\n          antiFileVector.Add(false);\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyFile:\r\n      {\r\n        ReadBoolVector(numEmptyStreams, emptyFileVector);\r\n        break;\r\n      }\r\n      case NID::kAnti:\r\n      {\r\n        ReadBoolVector(numEmptyStreams, antiFileVector);\r\n        break;\r\n      }\r\n      case NID::kCreationTime:\r\n      case NID::kLastWriteTime:\r\n      case NID::kLastAccessTime:\r\n      {\r\n        ReadTime(dataVector, database.Files, (UInt32)type);\r\n        break;\r\n      }\r\n      default:\r\n        isKnownType = false;\r\n    }\r\n    if (isKnownType)\r\n      database.ArchiveInfo.FileInfoPopIDs.Add(type);\r\n    else\r\n      SkeepData(size);\r\n  }\r\n\r\n  CNum emptyFileIndex = 0;\r\n  CNum sizeIndex = 0;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    CFileItem &file = database.Files[i];\r\n    file.HasStream = !emptyStreamVector[i];\r\n    if(file.HasStream)\r\n    {\r\n      file.IsDirectory = false;\r\n      file.IsAnti = false;\r\n      file.UnPackSize = unPackSizes[sizeIndex];\r\n      file.FileCRC = digests[sizeIndex];\r\n      file.IsFileCRCDefined = digestsDefined[sizeIndex];\r\n      sizeIndex++;\r\n    }\r\n    else\r\n    {\r\n      file.IsDirectory = !emptyFileVector[emptyFileIndex];\r\n      file.IsAnti = antiFileVector[emptyFileIndex];\r\n      emptyFileIndex++;\r\n      file.UnPackSize = 0;\r\n      file.IsFileCRCDefined = false;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartPackStream()\r\n{\r\n  FolderStartPackStreamIndex.Clear();\r\n  FolderStartPackStreamIndex.Reserve(Folders.Size());\r\n  CNum startPos = 0;\r\n  for(int i = 0; i < Folders.Size(); i++)\r\n  {\r\n    FolderStartPackStreamIndex.Add(startPos);\r\n    startPos += (CNum)Folders[i].PackStreams.Size();\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillStartPos()\r\n{\r\n  PackStreamStartPositions.Clear();\r\n  PackStreamStartPositions.Reserve(PackSizes.Size());\r\n  UInt64 startPos = 0;\r\n  for(int i = 0; i < PackSizes.Size(); i++)\r\n  {\r\n    PackStreamStartPositions.Add(startPos);\r\n    startPos += PackSizes[i];\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartFileIndex()\r\n{\r\n  FolderStartFileIndex.Clear();\r\n  FolderStartFileIndex.Reserve(Folders.Size());\r\n  FileIndexToFolderIndexMap.Clear();\r\n  FileIndexToFolderIndexMap.Reserve(Files.Size());\r\n  \r\n  int folderIndex = 0;\r\n  CNum indexInFolder = 0;\r\n  for (int i = 0; i < Files.Size(); i++)\r\n  {\r\n    const CFileItem &file = Files[i];\r\n    bool emptyStream = !file.HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      FileIndexToFolderIndexMap.Add(kNumNoIndex);\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      // v3.13 incorrectly worked with empty folders\r\n      // v4.07: Loop for skipping empty folders\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= Folders.Size())\r\n          ThrowIncorrect();\r\n        FolderStartFileIndex.Add(i); // check it\r\n        if (NumUnPackStreamsVector[folderIndex] != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    FileIndexToFolderIndexMap.Add(folderIndex);\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= NumUnPackStreamsVector[folderIndex])\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &database\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  database.Clear();\r\n  database.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n\r\n  database.ArchiveInfo.Version.Major = _header[6];\r\n  database.ArchiveInfo.Version.Minor = _header[7];\r\n\r\n  if (database.ArchiveInfo.Version.Major != kMajorVersion)\r\n    ThrowUnsupportedVersion();\r\n\r\n  UInt32 crcFromArchive = GetUInt32FromMem(_header + 8);\r\n  UInt64 nextHeaderOffset = GetUInt64FromMem(_header + 0xC);\r\n  UInt64 nextHeaderSize = GetUInt64FromMem(_header + 0x14);\r\n  UInt32 nextHeaderCRC =  GetUInt32FromMem(_header + 0x1C);\r\n  UInt32 crc = CrcCalc(_header + 0xC, 20);\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)\r\n  {\r\n    UInt64 cur, cur2;\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));\r\n    const int kCheckSize = 500;\r\n    Byte buf[kCheckSize];\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));\r\n    int checkSize = kCheckSize;\r\n    if (cur2 - cur < kCheckSize)\r\n      checkSize = (int)(cur2 - cur);\r\n    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));\r\n    \r\n    UInt32 realProcessedSize;\r\n    RINOK(_stream->Read(buf, (UInt32)kCheckSize, &realProcessedSize));\r\n\r\n    int i;\r\n    for (i = (int)realProcessedSize - 2; i >= 0; i--)\r\n      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)\r\n        break;\r\n    if (i < 0)\r\n      return S_FALSE;\r\n    nextHeaderSize = realProcessedSize - i;\r\n    nextHeaderOffset = cur2 - cur + i;\r\n    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);\r\n    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));\r\n  }\r\n  #endif\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  crcFromArchive = crc;\r\n  #endif\r\n\r\n  database.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;\r\n\r\n  if (crc != crcFromArchive)\r\n    ThrowIncorrect();\r\n\r\n  if (nextHeaderSize == 0)\r\n    return S_OK;\r\n\r\n  if (nextHeaderSize > (UInt64)0xFFFFFFFF)\r\n    return S_FALSE;\r\n\r\n  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));\r\n\r\n  CByteBuffer buffer2;\r\n  buffer2.SetCapacity((size_t)nextHeaderSize);\r\n\r\n  UInt32 realProcessedSize;\r\n  RINOK(_stream->Read(buffer2, (UInt32)nextHeaderSize, &realProcessedSize));\r\n  if (realProcessedSize != (UInt32)nextHeaderSize)\r\n    return S_FALSE;\r\n  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)\r\n    ThrowIncorrect();\r\n  \r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, buffer2);\r\n  \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kHeader)\r\n      break;\r\n    if (type != NID::kEncodedHeader)\r\n      ThrowIncorrect();\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        database.ArchiveInfo.StartPositionAfterHeader, \r\n        database.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    if (dataVector.Size() == 0)\r\n      return S_OK;\r\n    if (dataVector.Size() > 1)\r\n      ThrowIncorrect();\r\n    streamSwitch.Remove();\r\n    streamSwitch.Set(this, dataVector.Front());\r\n  }\r\n\r\n  return ReadHeader(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    database\r\n    #ifndef _NO_CRYPTO\r\n    , getTextPassword\r\n    #endif\r\n    );\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &database\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  try\r\n  {\r\n    return ReadDatabase2(\r\n      EXTERNAL_CODECS_LOC_VARS database\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword\r\n      #endif\r\n      );\r\n  }\r\n  catch(CInArchiveException &) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zIn.h",
    "content": "// 7zIn.h\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/InBuffer.h\"\r\n\r\n#include \"7zItem.h\"\r\n \r\nnamespace NArchive {\r\nnamespace N7z {\r\n  \r\nstruct CInArchiveInfo\r\n{\r\n  CArchiveVersion Version;\r\n  UInt64 StartPosition;\r\n  UInt64 StartPositionAfterHeader;\r\n  UInt64 DataStartPosition;\r\n  UInt64 DataStartPosition2;\r\n  CRecordVector<UInt64> FileInfoPopIDs;\r\n  void Clear()\r\n  {\r\n    FileInfoPopIDs.Clear();\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabaseEx: public CArchiveDatabase\r\n{\r\n  CInArchiveInfo ArchiveInfo;\r\n  CRecordVector<UInt64> PackStreamStartPositions;\r\n  CRecordVector<CNum> FolderStartPackStreamIndex;\r\n  CRecordVector<CNum> FolderStartFileIndex;\r\n  CRecordVector<CNum> FileIndexToFolderIndexMap;\r\n\r\n  void Clear()\r\n  {\r\n    CArchiveDatabase::Clear();\r\n    ArchiveInfo.Clear();\r\n    PackStreamStartPositions.Clear();\r\n    FolderStartPackStreamIndex.Clear();\r\n    FolderStartFileIndex.Clear();\r\n    FileIndexToFolderIndexMap.Clear();\r\n  }\r\n\r\n  void FillFolderStartPackStream();\r\n  void FillStartPos();\r\n  void FillFolderStartFileIndex();\r\n\r\n  void Fill()\r\n  {\r\n    FillFolderStartPackStream();\r\n    FillStartPos();\r\n    FillFolderStartFileIndex();\r\n  }\r\n  \r\n  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const\r\n  {\r\n    return ArchiveInfo.DataStartPosition +\r\n        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n  }\r\n  \r\n  UInt64 GetFolderFullPackSize(int folderIndex) const \r\n  {\r\n    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];\r\n    const CFolder &folder = Folders[folderIndex];\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < folder.PackStreams.Size(); i++)\r\n      size += PackSizes[packStreamIndex + i];\r\n    return size;\r\n  }\r\n  \r\n  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n  {\r\n    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n  }\r\n\r\n  UInt64 GetFilePackSize(CNum fileIndex) const\r\n  {\r\n    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n    if (folderIndex != kNumNoIndex)\r\n      if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n        return GetFolderFullPackSize(folderIndex);\r\n    return 0;\r\n  }\r\n};\r\n\r\nclass CInByte2\r\n{\r\n  const Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  void Init(const Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  Byte ReadByte();\r\n  void ReadBytes(Byte *data, size_t size);\r\n  void SkeepData(UInt64 size);\r\n  void SkeepData();\r\n  UInt64 ReadNumber();\r\n  CNum ReadNum();\r\n  UInt32 ReadUInt32();\r\n  UInt64 ReadUInt64();\r\n  void ReadString(UString &s);\r\n};\r\n\r\nclass CStreamSwitch;\r\n\r\nconst UInt32 kHeaderSize = 32;\r\n\r\nclass CInArchive\r\n{\r\n  friend class CStreamSwitch;\r\n\r\n  CMyComPtr<IInStream> _stream;\r\n\r\n  CObjectVector<CInByte2> _inByteVector;\r\n  CInByte2 *_inByteBack;\r\n \r\n  UInt64 _arhiveBeginStreamPosition;\r\n\r\n  Byte _header[kHeaderSize];\r\n\r\n  void AddByteStream(const Byte *buffer, size_t size)\r\n  {\r\n    _inByteVector.Add(CInByte2());\r\n    _inByteBack = &_inByteVector.Back();\r\n    _inByteBack->Init(buffer, size);\r\n  }\r\n  \r\n  void DeleteByteStream()\r\n  {\r\n    _inByteVector.DeleteBack();\r\n    if (!_inByteVector.IsEmpty())\r\n      _inByteBack = &_inByteVector.Back();\r\n  }\r\n\r\nprivate:\r\n  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);\r\n  \r\n  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }\r\n  Byte ReadByte() { return _inByteBack->ReadByte(); }\r\n  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }\r\n  CNum ReadNum() { return _inByteBack->ReadNum(); }\r\n  UInt64 ReadID() { return _inByteBack->ReadNumber(); }\r\n  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }\r\n  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }\r\n  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }\r\n  void SkeepData() { _inByteBack->SkeepData(); }\r\n  void WaitAttribute(UInt64 attribute);\r\n\r\n  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);\r\n  void GetNextFolderItem(CFolder &itemInfo);\r\n  void ReadHashDigests(int numItems,\r\n      CRecordVector<bool> &digestsDefined, CRecordVector<UInt32> &digests);\r\n  \r\n  void ReadPackInfo(\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CRecordVector<bool> &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs);\r\n  \r\n  void ReadUnPackInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      CObjectVector<CFolder> &folders);\r\n  \r\n  void ReadSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      CRecordVector<UInt64> &unPackSizes,\r\n      CRecordVector<bool> &digestsDefined, \r\n      CRecordVector<UInt32> &digests);\r\n\r\n  void ReadStreamsInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CRecordVector<bool> &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs,\r\n      CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      CRecordVector<UInt64> &unPackSizes,\r\n      CRecordVector<bool> &digestsDefined, \r\n      CRecordVector<UInt32> &digests);\r\n\r\n\r\n  void ReadBoolVector(int numItems, CBoolVector &v);\r\n  void ReadBoolVector2(int numItems, CBoolVector &v);\r\n  void ReadTime(const CObjectVector<CByteBuffer> &dataVector,\r\n      CObjectVector<CFileItem> &files, UInt32 type);\r\n  HRESULT ReadAndDecodePackedStreams(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      UInt64 baseOffset, UInt64 &dataOffset,\r\n      CObjectVector<CByteBuffer> &dataVector\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\n  HRESULT ReadHeader(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &database\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\n  HRESULT ReadDatabase2(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &database \r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\npublic:\r\n  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive\r\n  void Close();\r\n\r\n  HRESULT ReadDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &database \r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\n};\r\n  \r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zItem.h",
    "content": "// 7zItem.h\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../Common/MethodId.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\ntypedef UInt32 CNum;\r\nconst CNum kNumMax     = 0x7FFFFFFF;\r\nconst CNum kNumNoIndex = 0xFFFFFFFF;\r\n\r\nstruct CCoderInfo\r\n{\r\n  CMethodId MethodID;\r\n  CByteBuffer Properties;\r\n  CNum NumInStreams;\r\n  CNum NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBindPair\r\n{\r\n  CNum InIndex;\r\n  CNum OutIndex;\r\n};\r\n\r\nstruct CFolder\r\n{\r\n  CObjectVector<CCoderInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<CNum> PackStreams;\r\n  CRecordVector<UInt64> UnPackSizes;\r\n  UInt32 UnPackCRC;\r\n  bool UnPackCRCDefined;\r\n\r\n  CFolder(): UnPackCRCDefined(false) {}\r\n\r\n  UInt64 GetUnPackSize() const // test it\r\n  { \r\n    if (UnPackSizes.IsEmpty())\r\n      return 0;\r\n    for (int i = UnPackSizes.Size() - 1; i >= 0; i--)\r\n      if (FindBindPairForOutStream(i) < 0)\r\n        return UnPackSizes[i];\r\n    throw 1;\r\n  }\r\n\r\n  CNum GetNumOutStreams() const\r\n  {\r\n    CNum result = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n      result += Coders[i].NumOutStreams;\r\n    return result;\r\n  }\r\n\r\n  int FindBindPairForInStream(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBindPairForOutStream(CNum outStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindPackStreamArrayIndex(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < PackStreams.Size(); i++)\r\n      if (PackStreams[i] == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n};\r\n\r\ntypedef FILETIME CArchiveFileTime;\r\n\r\nclass CFileItem\r\n{\r\npublic:\r\n  CArchiveFileTime CreationTime;\r\n  CArchiveFileTime LastWriteTime;\r\n  CArchiveFileTime LastAccessTime;\r\n  UInt64 UnPackSize;\r\n  UInt64 StartPos;\r\n  UInt32 Attributes;\r\n  UInt32 FileCRC;\r\n  UString Name;\r\n\r\n  bool HasStream; // Test it !!! it means that there is \r\n                  // stream in some folder. It can be empty stream\r\n  bool IsDirectory;\r\n  bool IsAnti;\r\n  bool IsFileCRCDefined;\r\n  bool AreAttributesDefined;\r\n  bool IsCreationTimeDefined;\r\n  bool IsLastWriteTimeDefined;\r\n  bool IsLastAccessTimeDefined;\r\n  bool IsStartPosDefined;\r\n\r\n  /*\r\n  const bool HasStream() const { \r\n      return !IsDirectory && !IsAnti && UnPackSize != 0; }\r\n  */\r\n  CFileItem(): \r\n    HasStream(true),\r\n    IsDirectory(false),\r\n    IsAnti(false),\r\n    IsFileCRCDefined(false),\r\n    AreAttributesDefined(false), \r\n    IsCreationTimeDefined(false), \r\n    IsLastWriteTimeDefined(false), \r\n    IsLastAccessTimeDefined(false),\r\n    IsStartPosDefined(false)\r\n      {}\r\n  void SetAttributes(UInt32 attributes) \r\n  { \r\n    AreAttributesDefined = true;\r\n    Attributes = attributes;\r\n  }\r\n  void SetCreationTime(const CArchiveFileTime &creationTime) \r\n  { \r\n    IsCreationTimeDefined = true;\r\n    CreationTime = creationTime;\r\n  }\r\n  void SetLastWriteTime(const CArchiveFileTime &lastWriteTime) \r\n  {\r\n    IsLastWriteTimeDefined = true;\r\n    LastWriteTime = lastWriteTime;\r\n  }\r\n  void SetLastAccessTime(const CArchiveFileTime &lastAccessTime) \r\n  { \r\n    IsLastAccessTimeDefined = true;\r\n    LastAccessTime = lastAccessTime;\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabase\r\n{\r\n  CRecordVector<UInt64> PackSizes;\r\n  CRecordVector<bool> PackCRCsDefined;\r\n  CRecordVector<UInt32> PackCRCs;\r\n  CObjectVector<CFolder> Folders;\r\n  CRecordVector<CNum> NumUnPackStreamsVector;\r\n  CObjectVector<CFileItem> Files;\r\n  void Clear()\r\n  {\r\n    PackSizes.Clear();\r\n    PackCRCsDefined.Clear();\r\n    PackCRCs.Clear();\r\n    Folders.Clear();\r\n    NumUnPackStreamsVector.Clear();\r\n    Files.Clear();\r\n  }\r\n  bool IsEmpty() const\r\n  {\r\n    return (PackSizes.IsEmpty() && \r\n      PackCRCsDefined.IsEmpty() && \r\n      PackCRCs.IsEmpty() && \r\n      Folders.IsEmpty() && \r\n      NumUnPackStreamsVector.IsEmpty() && \r\n      Files.IsEmpty());\r\n  }\r\n  bool IsSolid() const\r\n  {\r\n    for (int i = 0; i < NumUnPackStreamsVector.Size(); i++)\r\n      if (NumUnPackStreamsVector[i] > 1)\r\n        return true;\r\n    return false;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zOut.cpp",
    "content": "// 7zOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/AutoPtr.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zOut.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nstatic HRESULT WriteBytes(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size > 0)\r\n  {\r\n    UInt32 curSize = (UInt32)MyMin(size, (size_t)0xFFFFFFFF);\r\n    UInt32 processedSize;\r\n    RINOK(stream->Write(data, curSize, &processedSize));\r\n    if(processedSize == 0)\r\n      return E_FAIL;\r\n    data = (const void *)((const Byte *)data + processedSize);\r\n    size -= processedSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nHRESULT COutArchive::WriteDirect(const void *data, UInt32 size)\r\n{\r\n  return ::WriteBytes(SeqStream, data, size);\r\n}\r\n\r\nUInt32 CrcUpdateUInt32(UInt32 crc, UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++, value >>= 8)\r\n    crc = CRC_UPDATE_BYTE(crc, (Byte)value);\r\n  return crc;\r\n}\r\n\r\nUInt32 CrcUpdateUInt64(UInt32 crc, UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++, value >>= 8)\r\n    crc = CRC_UPDATE_BYTE(crc, (Byte)value);\r\n  return crc;\r\n}\r\n\r\nHRESULT COutArchive::WriteDirectUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    RINOK(WriteDirectByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteDirectUInt64(UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    RINOK(WriteDirectByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteSignature()\r\n{\r\n  RINOK(WriteDirect(kSignature, kSignatureSize));\r\n  RINOK(WriteDirectByte(kMajorVersion));\r\n  return WriteDirectByte(2);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishSignature()\r\n{\r\n  RINOK(WriteDirect(kFinishSignature, kSignatureSize));\r\n  CArchiveVersion av;\r\n  av.Major = kMajorVersion;\r\n  av.Minor = 2;\r\n  RINOK(WriteDirectByte(av.Major));\r\n  return WriteDirectByte(av.Minor);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::WriteStartHeader(const CStartHeader &h)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;\r\n  crc = CrcUpdateUInt64(crc, h.NextHeaderOffset);\r\n  crc = CrcUpdateUInt64(crc, h.NextHeaderSize);\r\n  crc = CrcUpdateUInt32(crc, h.NextHeaderCRC);\r\n  RINOK(WriteDirectUInt32(CRC_GET_DIGEST(crc)));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  return WriteDirectUInt32(h.NextHeaderCRC);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)\r\n{\r\n  CCRC crc;\r\n  crc.UpdateUInt64(h.NextHeaderOffset);\r\n  crc.UpdateUInt64(h.NextHeaderSize);\r\n  crc.UpdateUInt32(h.NextHeaderCRC);\r\n  crc.UpdateUInt64(h.ArchiveStartOffset);\r\n  crc.UpdateUInt64(h.AdditionalStartBlockSize);\r\n  RINOK(WriteDirectUInt32(crc.GetDigest()));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  RINOK(WriteDirectUInt32(h.NextHeaderCRC));\r\n  RINOK(WriteDirectUInt64(h.ArchiveStartOffset));\r\n  return WriteDirectUInt64(h.AdditionalStartBlockSize);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)\r\n{\r\n  Close();\r\n  #ifdef _7Z_VOL\r\n  // endMarker = false;\r\n  _endMarker = endMarker;\r\n  #endif\r\n  SeqStream = stream;\r\n  if (!endMarker)\r\n  {\r\n    SeqStream.QueryInterface(IID_IOutStream, &Stream);\r\n    if (!Stream)\r\n    {\r\n      return E_NOTIMPL;\r\n      // endMarker = true;\r\n    }\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (endMarker)\r\n  {\r\n    /*\r\n    CStartHeader sh;\r\n    sh.NextHeaderOffset = (UInt32)(Int32)-1;\r\n    sh.NextHeaderSize = (UInt32)(Int32)-1;\r\n    sh.NextHeaderCRC = 0;\r\n    WriteStartHeader(sh);\r\n    */\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!Stream)\r\n      return E_FAIL;\r\n    RINOK(WriteSignature());\r\n    RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutArchive::Close()\r\n{\r\n  SeqStream.Release();\r\n  Stream.Release();\r\n}\r\n\r\nHRESULT COutArchive::SkeepPrefixArchiveHeader()\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n    return S_OK;\r\n  #endif\r\n  return Stream->Seek(24, STREAM_SEEK_CUR, NULL);\r\n}\r\n\r\nHRESULT COutArchive::WriteBytes(const void *data, size_t size)\r\n{\r\n  if (_mainMode)\r\n  {\r\n    if (_dynamicMode)\r\n      _dynamicBuffer.Write(data, size);\r\n    else\r\n      _outByte.WriteBytes(data, size);\r\n    _crc = CrcUpdate(_crc, data, size);\r\n  }\r\n  else\r\n  {\r\n    if (_countMode)\r\n      _countSize += size;\r\n    else\r\n      RINOK(_outByte2.Write(data, size));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteBytes(const CByteBuffer &data)\r\n{\r\n  return WriteBytes(data, data.GetCapacity());\r\n}\r\n\r\nHRESULT COutArchive::WriteByte(Byte b)\r\n{\r\n  return WriteBytes(&b, 1);\r\n}\r\n\r\nHRESULT COutArchive::WriteUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    RINOK(WriteByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteNumber(UInt64 value)\r\n{\r\n  Byte firstByte = 0;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n    {\r\n      firstByte |= Byte(value >> (8 * i));\r\n      break;\r\n    }\r\n    firstByte |= mask;\r\n    mask >>= 1;\r\n  }\r\n  RINOK(WriteByte(firstByte));\r\n  for (;i > 0; i--)\r\n  {\r\n    RINOK(WriteByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nstatic UInt32 GetBigNumberSize(UInt64 value)\r\n{\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n      break;\r\n  return 1 + i;\r\n}\r\n\r\nUInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)\r\n{\r\n  UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;\r\n  if (nameLength != 0)\r\n  {\r\n    nameLength = (nameLength + 1) * 2;\r\n    result += nameLength + GetBigNumberSize(nameLength) + 2;\r\n  }\r\n  if (props)\r\n  {\r\n    result += 20;\r\n  }\r\n  if (result >= 128)\r\n    result++;\r\n  result += kSignatureSize + 2 + kFinishHeaderSize;\r\n  return result;\r\n}\r\n\r\nUInt64 COutArchive::GetVolPureSize(UInt64 volSize, int nameLength, bool props)\r\n{\r\n  UInt32 headersSizeBase = COutArchive::GetVolHeadersSize(1, nameLength, props);\r\n  int testSize;\r\n  if (volSize > headersSizeBase)\r\n    testSize = volSize - headersSizeBase;\r\n  else\r\n    testSize = 1;\r\n  UInt32 headersSize = COutArchive::GetVolHeadersSize(testSize, nameLength, props);\r\n  UInt64 pureSize = 1;\r\n  if (volSize > headersSize)\r\n    pureSize = volSize - headersSize;\r\n  return pureSize;\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::WriteFolder(const CFolder &folder)\r\n{\r\n  RINOK(WriteNumber(folder.Coders.Size()));\r\n  int i;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    const CCoderInfo &coder = folder.Coders[i];\r\n    {\r\n      size_t propertiesSize = coder.Properties.GetCapacity();\r\n      \r\n      UInt64 id = coder.MethodID; \r\n      int idSize;\r\n      for (idSize = 1; idSize < sizeof(id); idSize++)\r\n        if ((id >> (8 * idSize)) == 0)\r\n          break;\r\n      BYTE longID[15];\r\n      for (int t = idSize - 1; t >= 0 ; t--, id >>= 8)\r\n        longID[t] = (Byte)(id & 0xFF);\r\n      Byte b;\r\n      b = (Byte)(idSize & 0xF);\r\n      bool isComplex = !coder.IsSimpleCoder();\r\n      b |= (isComplex ? 0x10 : 0);\r\n      b |= ((propertiesSize != 0) ? 0x20 : 0 );\r\n      RINOK(WriteByte(b));\r\n      RINOK(WriteBytes(longID, idSize));\r\n      if (isComplex)\r\n      {\r\n        RINOK(WriteNumber(coder.NumInStreams));\r\n        RINOK(WriteNumber(coder.NumOutStreams));\r\n      }\r\n      if (propertiesSize == 0)\r\n        continue;\r\n      RINOK(WriteNumber(propertiesSize));\r\n      RINOK(WriteBytes(coder.Properties, propertiesSize));\r\n    }\r\n  }\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = folder.BindPairs[i];\r\n    RINOK(WriteNumber(bindPair.InIndex));\r\n    RINOK(WriteNumber(bindPair.OutIndex));\r\n  }\r\n  if (folder.PackStreams.Size() > 1)\r\n    for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    {\r\n      RINOK(WriteNumber(folder.PackStreams[i]));\r\n    }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteBoolVector(const CBoolVector &boolVector)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0x80;\r\n  for(int i = 0; i < boolVector.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n      b |= mask;\r\n    mask >>= 1;\r\n    if (mask == 0)\r\n    {\r\n      RINOK(WriteByte(b));\r\n      mask = 0x80;\r\n      b = 0;\r\n    }\r\n  }\r\n  if (mask != 0x80)\r\n  {\r\n    RINOK(WriteByte(b));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nHRESULT COutArchive::WriteHashDigests(\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  int numDefined = 0;\r\n  int i;\r\n  for(i = 0; i < digestsDefined.Size(); i++)\r\n    if (digestsDefined[i])\r\n      numDefined++;\r\n  if (numDefined == 0)\r\n    return S_OK;\r\n\r\n  RINOK(WriteByte(NID::kCRC));\r\n  if (numDefined == digestsDefined.Size())\r\n  {\r\n    RINOK(WriteByte(1));\r\n  }\r\n  else\r\n  {\r\n    RINOK(WriteByte(0));\r\n    RINOK(WriteBoolVector(digestsDefined));\r\n  }\r\n  for(i = 0; i < digests.Size(); i++)\r\n  {\r\n    if(digestsDefined[i])\r\n      RINOK(WriteUInt32(digests[i]));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WritePackInfo(\r\n    UInt64 dataOffset,\r\n    const CRecordVector<UInt64> &packSizes,\r\n    const CRecordVector<bool> &packCRCsDefined,\r\n    const CRecordVector<UInt32> &packCRCs)\r\n{\r\n  if (packSizes.IsEmpty())\r\n    return S_OK;\r\n  RINOK(WriteByte(NID::kPackInfo));\r\n  RINOK(WriteNumber(dataOffset));\r\n  RINOK(WriteNumber(packSizes.Size()));\r\n  RINOK(WriteByte(NID::kSize));\r\n  for(int i = 0; i < packSizes.Size(); i++)\r\n    RINOK(WriteNumber(packSizes[i]));\r\n\r\n  RINOK(WriteHashDigests(packCRCsDefined, packCRCs));\r\n  \r\n  return WriteByte(NID::kEnd);\r\n}\r\n\r\nHRESULT COutArchive::WriteUnPackInfo(const CObjectVector<CFolder> &folders)\r\n{\r\n  if (folders.IsEmpty())\r\n    return S_OK;\r\n\r\n  RINOK(WriteByte(NID::kUnPackInfo));\r\n\r\n  RINOK(WriteByte(NID::kFolder));\r\n  RINOK(WriteNumber(folders.Size()));\r\n  {\r\n    RINOK(WriteByte(0));\r\n    for(int i = 0; i < folders.Size(); i++)\r\n      RINOK(WriteFolder(folders[i]));\r\n  }\r\n  \r\n  RINOK(WriteByte(NID::kCodersUnPackSize));\r\n  int i;\r\n  for(i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    for (int j = 0; j < folder.UnPackSizes.Size(); j++)\r\n      RINOK(WriteNumber(folder.UnPackSizes[j]));\r\n  }\r\n\r\n  CRecordVector<bool> unPackCRCsDefined;\r\n  CRecordVector<UInt32> unPackCRCs;\r\n  for(i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    unPackCRCsDefined.Add(folder.UnPackCRCDefined);\r\n    unPackCRCs.Add(folder.UnPackCRC);\r\n  }\r\n  RINOK(WriteHashDigests(unPackCRCsDefined, unPackCRCs));\r\n\r\n  return WriteByte(NID::kEnd);\r\n}\r\n\r\nHRESULT COutArchive::WriteSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    const CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n    const CRecordVector<UInt64> &unPackSizes,\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  RINOK(WriteByte(NID::kSubStreamsInfo));\r\n\r\n  int i;\r\n  for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n  {\r\n    if (numUnPackStreamsInFolders[i] != 1)\r\n    {\r\n      RINOK(WriteByte(NID::kNumUnPackStream));\r\n      for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n        RINOK(WriteNumber(numUnPackStreamsInFolders[i]));\r\n      break;\r\n    }\r\n  }\r\n \r\n\r\n  bool needFlag = true;\r\n  CNum index = 0;\r\n  for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n    for (CNum j = 0; j < numUnPackStreamsInFolders[i]; j++)\r\n    {\r\n      if (j + 1 != numUnPackStreamsInFolders[i])\r\n      {\r\n        if (needFlag)\r\n          RINOK(WriteByte(NID::kSize));\r\n        needFlag = false;\r\n        RINOK(WriteNumber(unPackSizes[index]));\r\n      }\r\n      index++;\r\n    }\r\n\r\n  CRecordVector<bool> digestsDefined2;\r\n  CRecordVector<UInt32> digests2;\r\n\r\n  int digestIndex = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    int numSubStreams = (int)numUnPackStreamsInFolders[i];\r\n    if (numSubStreams == 1 && folders[i].UnPackCRCDefined)\r\n      digestIndex++;\r\n    else\r\n      for (int j = 0; j < numSubStreams; j++, digestIndex++)\r\n      {\r\n        digestsDefined2.Add(digestsDefined[digestIndex]);\r\n        digests2.Add(digests[digestIndex]);\r\n      }\r\n  }\r\n  RINOK(WriteHashDigests(digestsDefined2, digests2));\r\n  return WriteByte(NID::kEnd);\r\n}\r\n\r\nHRESULT COutArchive::WriteTime(\r\n    const CObjectVector<CFileItem> &files, Byte type)\r\n{\r\n  /////////////////////////////////////////////////\r\n  // CreationTime\r\n  CBoolVector boolVector;\r\n  boolVector.Reserve(files.Size());\r\n  bool thereAreDefined = false;\r\n  bool allDefined = true;\r\n  int i;\r\n  for(i = 0; i < files.Size(); i++)\r\n  {\r\n    const CFileItem &item = files[i];\r\n    bool defined;\r\n    switch(type)\r\n    {\r\n      case NID::kCreationTime:\r\n        defined = item.IsCreationTimeDefined;\r\n        break;\r\n      case NID::kLastWriteTime:\r\n        defined = item.IsLastWriteTimeDefined;\r\n        break;\r\n      case NID::kLastAccessTime:\r\n        defined = item.IsLastAccessTimeDefined;\r\n        break;\r\n      default:\r\n        throw 1;\r\n    }\r\n    boolVector.Add(defined);\r\n    thereAreDefined = (thereAreDefined || defined);\r\n    allDefined = (allDefined && defined);\r\n  }\r\n  if (!thereAreDefined)\r\n    return S_OK;\r\n  RINOK(WriteByte(type));\r\n  size_t dataSize = 1 + 1;\r\n    dataSize += files.Size() * 8;\r\n  if (allDefined)\r\n  {\r\n    RINOK(WriteNumber(dataSize));\r\n    WriteByte(1);\r\n  }\r\n  else\r\n  {\r\n    RINOK(WriteNumber(1 + (boolVector.Size() + 7) / 8 + dataSize));\r\n    WriteByte(0);\r\n    RINOK(WriteBoolVector(boolVector));\r\n  }\r\n  RINOK(WriteByte(0));\r\n  for(i = 0; i < files.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n    {\r\n      const CFileItem &item = files[i];\r\n      CArchiveFileTime timeValue;\r\n      timeValue.dwLowDateTime = 0;\r\n      timeValue.dwHighDateTime = 0;\r\n      switch(type)\r\n      {\r\n        case NID::kCreationTime:\r\n          timeValue = item.CreationTime;\r\n          break;\r\n        case NID::kLastWriteTime:\r\n          timeValue = item.LastWriteTime;\r\n          break;\r\n        case NID::kLastAccessTime:\r\n          timeValue = item.LastAccessTime;\r\n          break;\r\n      }\r\n      RINOK(WriteUInt32(timeValue.dwLowDateTime));\r\n      RINOK(WriteUInt32(timeValue.dwHighDateTime));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const Byte *data, size_t dataSize,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  CSequentialInStreamImp *streamSpec = new CSequentialInStreamImp;\r\n  CMyComPtr<ISequentialInStream> stream = streamSpec;\r\n  streamSpec->Init(data, dataSize);\r\n  CFolder folderItem;\r\n  folderItem.UnPackCRCDefined = true;\r\n  folderItem.UnPackCRC = CrcCalc(data, dataSize);\r\n  UInt64 dataSize64 = dataSize;\r\n  RINOK(encoder.Encode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      stream, NULL, &dataSize64, folderItem, SeqStream, packSizes, NULL))\r\n  folders.Add(folderItem);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const CByteBuffer &data, \r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  return EncodeStream(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      encoder, data, data.GetCapacity(), packSizes, folders);\r\n}\r\n\r\nstatic void WriteUInt32ToBuffer(Byte *data, UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    *data++ = (Byte)value;\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nstatic void WriteUInt64ToBuffer(Byte *data, UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    *data++ = (Byte)value;\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\n\r\nHRESULT COutArchive::WriteHeader(\r\n    const CArchiveDatabase &database,\r\n    const CHeaderOptions &headerOptions,\r\n    UInt64 &headerOffset)\r\n{\r\n  int i;\r\n  \r\n  /////////////////////////////////\r\n  // Names\r\n\r\n  CNum numDefinedNames = 0;\r\n  size_t namesDataSize = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n  {\r\n    const UString &name = database.Files[i].Name;\r\n    if (!name.IsEmpty())\r\n      numDefinedNames++;\r\n    namesDataSize += (name.Length() + 1) * 2;\r\n  }\r\n\r\n  CByteBuffer namesData;\r\n  if (numDefinedNames > 0)\r\n  {\r\n    namesData.SetCapacity((size_t)namesDataSize);\r\n    size_t pos = 0;\r\n    for(int i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const UString &name = database.Files[i].Name;\r\n      for (int t = 0; t < name.Length(); t++)\r\n      {\r\n        wchar_t c = name[t];\r\n        namesData[pos++] = Byte(c);\r\n        namesData[pos++] = Byte(c >> 8);\r\n      }\r\n      namesData[pos++] = 0;\r\n      namesData[pos++] = 0;\r\n    }\r\n  }\r\n\r\n  /////////////////////////////////\r\n  // Write Attributes\r\n  CBoolVector attributesBoolVector;\r\n  attributesBoolVector.Reserve(database.Files.Size());\r\n  int numDefinedAttributes = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n  {\r\n    bool defined = database.Files[i].AreAttributesDefined;\r\n    attributesBoolVector.Add(defined);\r\n    if (defined)\r\n      numDefinedAttributes++;\r\n  }\r\n\r\n  CByteBuffer attributesData;\r\n  if (numDefinedAttributes > 0)\r\n  {\r\n    attributesData.SetCapacity(numDefinedAttributes * 4);\r\n    size_t pos = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (file.AreAttributesDefined)\r\n      {\r\n        WriteUInt32ToBuffer(attributesData + pos, file.Attributes);\r\n        pos += 4;\r\n      }\r\n    }\r\n  }\r\n\r\n  /////////////////////////////////\r\n  // Write StartPos\r\n  CBoolVector startsBoolVector;\r\n  startsBoolVector.Reserve(database.Files.Size());\r\n  int numDefinedStarts = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n  {\r\n    bool defined = database.Files[i].IsStartPosDefined;\r\n    startsBoolVector.Add(defined);\r\n    if (defined)\r\n      numDefinedStarts++;\r\n  }\r\n\r\n  CByteBuffer startsData;\r\n  if (numDefinedStarts > 0)\r\n  {\r\n    startsData.SetCapacity(numDefinedStarts * 8);\r\n    size_t pos = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (file.IsStartPosDefined)\r\n      {\r\n        WriteUInt64ToBuffer(startsData + pos, file.StartPos);\r\n        pos += 8;\r\n      }\r\n    }\r\n  }\r\n  \r\n  /////////////////////////////////\r\n  // Write Last Write Time\r\n  // /*\r\n  CNum numDefinedLastWriteTimes = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n    if (database.Files[i].IsLastWriteTimeDefined)\r\n      numDefinedLastWriteTimes++;\r\n\r\n  if (numDefinedLastWriteTimes > 0)\r\n  {\r\n    CByteBuffer lastWriteTimeData;\r\n    lastWriteTimeData.SetCapacity(numDefinedLastWriteTimes * 8);\r\n    size_t pos = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (file.IsLastWriteTimeDefined)\r\n      {\r\n        WriteUInt32ToBuffer(lastWriteTimeData + pos, file.LastWriteTime.dwLowDateTime);\r\n        pos += 4;\r\n        WriteUInt32ToBuffer(lastWriteTimeData + pos, file.LastWriteTime.dwHighDateTime);\r\n        pos += 4;\r\n      }\r\n    }\r\n  }\r\n  // */\r\n  \r\n\r\n  UInt64 packedSize = 0;\r\n  for(i = 0; i < database.PackSizes.Size(); i++)\r\n    packedSize += database.PackSizes[i];\r\n\r\n  headerOffset = packedSize;\r\n\r\n  _mainMode = true;\r\n\r\n  _outByte.SetStream(SeqStream);\r\n  _outByte.Init();\r\n  _crc = CRC_INIT_VAL;\r\n\r\n\r\n  RINOK(WriteByte(NID::kHeader));\r\n\r\n  // Archive Properties\r\n\r\n  if (database.Folders.Size() > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kMainStreamsInfo));\r\n    RINOK(WritePackInfo(0, database.PackSizes, \r\n        database.PackCRCsDefined,\r\n        database.PackCRCs));\r\n\r\n    RINOK(WriteUnPackInfo(database.Folders));\r\n\r\n    CRecordVector<UInt64> unPackSizes;\r\n    CRecordVector<bool> digestsDefined;\r\n    CRecordVector<UInt32> digests;\r\n    for (i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (!file.HasStream)\r\n        continue;\r\n      unPackSizes.Add(file.UnPackSize);\r\n      digestsDefined.Add(file.IsFileCRCDefined);\r\n      digests.Add(file.FileCRC);\r\n    }\r\n\r\n    RINOK(WriteSubStreamsInfo(\r\n        database.Folders,\r\n        database.NumUnPackStreamsVector,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests));\r\n    RINOK(WriteByte(NID::kEnd));\r\n  }\r\n\r\n  if (database.Files.IsEmpty())\r\n  {\r\n    RINOK(WriteByte(NID::kEnd));\r\n    return _outByte.Flush();\r\n  }\r\n\r\n  RINOK(WriteByte(NID::kFilesInfo));\r\n  RINOK(WriteNumber(database.Files.Size()));\r\n\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve(database.Files.Size());\r\n  int numEmptyStreams = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n    if (database.Files[i].HasStream)\r\n      emptyStreamVector.Add(false);\r\n    else\r\n    {\r\n      emptyStreamVector.Add(true);\r\n      numEmptyStreams++;\r\n    }\r\n  if (numEmptyStreams > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kEmptyStream));\r\n    RINOK(WriteNumber((emptyStreamVector.Size() + 7) / 8));\r\n    RINOK(WriteBoolVector(emptyStreamVector));\r\n\r\n    CBoolVector emptyFileVector, antiVector;\r\n    emptyFileVector.Reserve(numEmptyStreams);\r\n    antiVector.Reserve(numEmptyStreams);\r\n    CNum numEmptyFiles = 0, numAntiItems = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (!file.HasStream)\r\n      {\r\n        emptyFileVector.Add(!file.IsDirectory);\r\n        if (!file.IsDirectory)\r\n          numEmptyFiles++;\r\n        antiVector.Add(file.IsAnti);\r\n        if (file.IsAnti)\r\n          numAntiItems++;\r\n      }\r\n    }\r\n\r\n    if (numEmptyFiles > 0)\r\n    {\r\n      RINOK(WriteByte(NID::kEmptyFile));\r\n      RINOK(WriteNumber((emptyFileVector.Size() + 7) / 8));\r\n      RINOK(WriteBoolVector(emptyFileVector));\r\n    }\r\n\r\n    if (numAntiItems > 0)\r\n    {\r\n      RINOK(WriteByte(NID::kAnti));\r\n      RINOK(WriteNumber((antiVector.Size() + 7) / 8));\r\n      RINOK(WriteBoolVector(antiVector));\r\n    }\r\n  }\r\n\r\n  if (numDefinedNames > 0)\r\n  {\r\n    /////////////////////////////////////////////////\r\n    RINOK(WriteByte(NID::kName));\r\n    {\r\n      RINOK(WriteNumber(1 + namesData.GetCapacity()));\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBytes(namesData));\r\n    }\r\n\r\n  }\r\n\r\n  if (headerOptions.WriteCreated)\r\n  {\r\n    RINOK(WriteTime(database.Files, NID::kCreationTime));\r\n  }\r\n  if (headerOptions.WriteModified)\r\n  {\r\n    RINOK(WriteTime(database.Files, NID::kLastWriteTime));\r\n  }\r\n  if (headerOptions.WriteAccessed)\r\n  {\r\n    RINOK(WriteTime(database.Files, NID::kLastAccessTime));\r\n  }\r\n\r\n  if (numDefinedAttributes > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kWinAttributes));\r\n    size_t size = 2;\r\n    if (numDefinedAttributes != database.Files.Size())\r\n      size += (attributesBoolVector.Size() + 7) / 8 + 1;\r\n      size += attributesData.GetCapacity();\r\n\r\n    RINOK(WriteNumber(size));\r\n    if (numDefinedAttributes == database.Files.Size())\r\n    {\r\n      RINOK(WriteByte(1));\r\n    }\r\n    else\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBoolVector(attributesBoolVector));\r\n    }\r\n\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBytes(attributesData));\r\n    }\r\n  }\r\n\r\n  if (numDefinedStarts > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kStartPos));\r\n    size_t size = 2;\r\n    if (numDefinedStarts != database.Files.Size())\r\n      size += (startsBoolVector.Size() + 7) / 8 + 1;\r\n      size += startsData.GetCapacity();\r\n\r\n    RINOK(WriteNumber(size));\r\n    if (numDefinedStarts == database.Files.Size())\r\n    {\r\n      RINOK(WriteByte(1));\r\n    }\r\n    else\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBoolVector(startsBoolVector));\r\n    }\r\n\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBytes(startsData));\r\n    }\r\n  }\r\n\r\n  RINOK(WriteByte(NID::kEnd)); // for files\r\n  RINOK(WriteByte(NID::kEnd)); // for headers\r\n\r\n  return _outByte.Flush();\r\n}\r\n\r\nHRESULT COutArchive::WriteDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CArchiveDatabase &database,\r\n    const CCompressionMethodMode *options, \r\n    const CHeaderOptions &headerOptions)\r\n{\r\n  UInt64 headerOffset;\r\n  UInt32 headerCRC;\r\n  UInt64 headerSize;\r\n  if (database.IsEmpty())\r\n  {\r\n    headerSize = 0;\r\n    headerOffset = 0;\r\n    headerCRC = CrcCalc(0, 0);\r\n  }\r\n  else\r\n  {\r\n    _dynamicBuffer.Init();\r\n    _dynamicMode = false;\r\n\r\n    if (options != 0)\r\n      if (options->IsEmpty())\r\n        options = 0;\r\n    if (options != 0)\r\n      if (options->PasswordIsDefined || headerOptions.CompressMainHeader)\r\n        _dynamicMode = true;\r\n    RINOK(WriteHeader(database, headerOptions, headerOffset));\r\n\r\n    if (_dynamicMode)\r\n    {\r\n      CCompressionMethodMode encryptOptions;\r\n      encryptOptions.PasswordIsDefined = options->PasswordIsDefined;\r\n      encryptOptions.Password = options->Password;\r\n      CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions);\r\n      CRecordVector<UInt64> packSizes;\r\n      CObjectVector<CFolder> folders;\r\n      RINOK(EncodeStream(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          encoder, _dynamicBuffer, \r\n          _dynamicBuffer.GetSize(), packSizes, folders));\r\n      _dynamicMode = false;\r\n      _mainMode = true;\r\n      \r\n      _outByte.SetStream(SeqStream);\r\n      _outByte.Init();\r\n      _crc = CRC_INIT_VAL;\r\n      \r\n      if (folders.Size() == 0)\r\n        throw 1;\r\n\r\n      RINOK(WriteID(NID::kEncodedHeader));\r\n      RINOK(WritePackInfo(headerOffset, packSizes, \r\n        CRecordVector<bool>(), CRecordVector<UInt32>()));\r\n      RINOK(WriteUnPackInfo(folders));\r\n      RINOK(WriteByte(NID::kEnd));\r\n      for (int i = 0; i < packSizes.Size(); i++)\r\n        headerOffset += packSizes[i];\r\n      RINOK(_outByte.Flush());\r\n    }\r\n    headerCRC = CRC_GET_DIGEST(_crc);\r\n    headerSize = _outByte.GetProcessedSize();\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n  {\r\n    CFinishHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = \r\n        UInt64(0) - (headerSize + \r\n        4 + kFinishHeaderSize);\r\n    h.ArchiveStartOffset = h.NextHeaderOffset - headerOffset;\r\n    h.AdditionalStartBlockSize = 0;\r\n    RINOK(WriteFinishHeader(h));\r\n    return WriteFinishSignature();\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    CStartHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = headerOffset;\r\n    RINOK(Stream->Seek(_prefixHeaderPos, STREAM_SEEK_SET, NULL));\r\n    return WriteStartHeader(h);\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zOut.h",
    "content": "// 7z/Out.h\r\n\r\n#ifndef __7Z_OUT_H\r\n#define __7Z_OUT_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zCompressionMode.h\"\r\n#include \"7zEncode.h\"\r\n\r\n#include \"../../Common/OutBuffer.h\"\r\n#include \"../../../Common/DynamicBuffer.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CWriteBufferLoc\r\n{\r\n  Byte *_data;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  CWriteBufferLoc(): _size(0), _pos(0) {}\r\n  void Init(Byte *data, size_t size)  \r\n  { \r\n    _pos = 0;\r\n    _data = data;\r\n    _size = size; \r\n  }\r\n  HRESULT Write(const void *data, size_t size)\r\n  {\r\n    if (_pos + size > _size)\r\n      return E_FAIL;\r\n    memmove(_data + _pos, data, size);\r\n    _pos += size;\r\n    return S_OK; \r\n  }\r\n};\r\n\r\nclass CWriteDynamicBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _pos;\r\npublic:\r\n  CWriteDynamicBuffer(): _pos(0) {}\r\n  void Init()  \r\n  { \r\n    _pos = 0;\r\n  }\r\n  void Write(const void *data, size_t size)\r\n  {\r\n    if (_pos + size > _buffer.GetCapacity())\r\n      _buffer.EnsureCapacity(_pos + size);\r\n    memmove(((Byte *)_buffer) +_pos, data, size);\r\n    _pos += size;\r\n  }\r\n  operator Byte *() { return (Byte *)_buffer; };\r\n  operator const Byte *() const { return (const Byte *)_buffer; };\r\n  size_t GetSize() const { return _pos; }\r\n};\r\n\r\nstruct CHeaderOptions\r\n{\r\n  // bool UseAdditionalHeaderStreams;\r\n  bool CompressMainHeader;\r\n  bool WriteModified;\r\n  bool WriteCreated;\r\n  bool WriteAccessed;\r\n\r\n  CHeaderOptions(): \r\n      // UseAdditionalHeaderStreams(false), \r\n      CompressMainHeader(true),\r\n      WriteModified(true),\r\n      WriteCreated(false),\r\n      WriteAccessed(false) {} \r\n};\r\n\r\nclass COutArchive\r\n{\r\n  UInt64 _prefixHeaderPos;\r\n\r\n  HRESULT WriteDirect(const void *data, UInt32 size);\r\n  HRESULT WriteDirectByte(Byte b) { return WriteDirect(&b, 1); }\r\n  HRESULT WriteDirectUInt32(UInt32 value);\r\n  HRESULT WriteDirectUInt64(UInt64 value);\r\n  \r\n  HRESULT WriteBytes(const void *data, size_t size);\r\n  HRESULT WriteBytes(const CByteBuffer &data);\r\n  HRESULT WriteByte(Byte b);\r\n  HRESULT WriteUInt32(UInt32 value);\r\n  HRESULT WriteNumber(UInt64 value);\r\n  HRESULT WriteID(UInt64 value) { return WriteNumber(value); }\r\n\r\n  HRESULT WriteFolder(const CFolder &folder);\r\n  HRESULT WriteFileHeader(const CFileItem &itemInfo);\r\n  HRESULT WriteBoolVector(const CBoolVector &boolVector);\r\n  HRESULT WriteHashDigests(\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  HRESULT WritePackInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs);\r\n\r\n  HRESULT WriteUnPackInfo(const CObjectVector<CFolder> &folders);\r\n\r\n  HRESULT WriteSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unPackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  /*\r\n  HRESULT WriteStreamsInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs,\r\n      bool externalFolders,\r\n      UInt64 externalFoldersStreamIndex,\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unPackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n  */\r\n\r\n\r\n  HRESULT WriteTime(const CObjectVector<CFileItem> &files, Byte type);\r\n\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const Byte *data, size_t dataSize,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const CByteBuffer &data, \r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT WriteHeader(\r\n      const CArchiveDatabase &database,\r\n      const CHeaderOptions &headerOptions,\r\n      UInt64 &headerOffset);\r\n  \r\n  bool _mainMode;\r\n\r\n  bool _dynamicMode;\r\n\r\n  bool _countMode;\r\n  size_t _countSize;\r\n  COutBuffer _outByte;\r\n  CWriteBufferLoc _outByte2;\r\n  CWriteDynamicBuffer _dynamicBuffer;\r\n  UInt32 _crc;\r\n\r\n  #ifdef _7Z_VOL\r\n  bool _endMarker;\r\n  #endif\r\n\r\n  HRESULT WriteSignature();\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishSignature();\r\n  #endif\r\n  HRESULT WriteStartHeader(const CStartHeader &h);\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishHeader(const CFinishHeader &h);\r\n  #endif\r\n  CMyComPtr<IOutStream> Stream;\r\npublic:\r\n\r\n  COutArchive() { _outByte.Create(1 << 16); }\r\n  CMyComPtr<ISequentialOutStream> SeqStream;\r\n  HRESULT Create(ISequentialOutStream *stream, bool endMarker);\r\n  void Close();\r\n  HRESULT SkeepPrefixArchiveHeader();\r\n  HRESULT WriteDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CArchiveDatabase &database,\r\n      const CCompressionMethodMode *options, \r\n      const CHeaderOptions &headerOptions);\r\n\r\n  #ifdef _7Z_VOL\r\n  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);\r\n  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);\r\n  #endif\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zProperties.cpp",
    "content": "// 7zProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zProperties.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zHandler.h\"\r\n\r\n// #define _MULTI_PACK\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CPropMap\r\n{\r\n  UInt64 FilePropID;\r\n  STATPROPSTG StatPROPSTG;\r\n};\r\n\r\nCPropMap kPropMap[] = \r\n{\r\n  { NID::kName, NULL, kpidPath, VT_BSTR},\r\n  { NID::kSize, NULL, kpidSize, VT_UI8},\r\n  { NID::kPackInfo, NULL, kpidPackedSize, VT_UI8},\r\n  \r\n  #ifdef _MULTI_PACK\r\n  { 100, L\"Pack0\", kpidPackedSize0, VT_UI8},\r\n  { 101, L\"Pack1\", kpidPackedSize1, VT_UI8},\r\n  { 102, L\"Pack2\", kpidPackedSize2, VT_UI8},\r\n  { 103, L\"Pack3\", kpidPackedSize3, VT_UI8},\r\n  { 104, L\"Pack4\", kpidPackedSize4, VT_UI8},\r\n  #endif\r\n\r\n  { NID::kCreationTime, NULL, kpidCreationTime, VT_FILETIME},\r\n  { NID::kLastWriteTime, NULL, kpidLastWriteTime, VT_FILETIME},\r\n  { NID::kLastAccessTime, NULL, kpidLastAccessTime, VT_FILETIME},\r\n  { NID::kWinAttributes, NULL, kpidAttributes, VT_UI4},\r\n  { NID::kStartPos, NULL, kpidPosition, VT_UI4},\r\n\r\n  { NID::kCRC, NULL, kpidCRC, VT_UI4},\r\n  \r\n  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},\r\n  // { 97, NULL, kpidSolid, VT_BOOL},\r\n  #ifndef _SFX\r\n  { 98, NULL, kpidMethod, VT_BSTR},\r\n  { 99, NULL, kpidBlock, VT_UI4}\r\n  #endif\r\n};\r\n\r\nstatic const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);\r\n\r\nstatic int FindPropInMap(UInt64 filePropID)\r\n{\r\n  for (int i = 0; i < kPropMapSize; i++)\r\n    if (kPropMap[i].FilePropID == filePropID)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void CopyOneItem(CRecordVector<UInt64> &src, \r\n    CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      dest.Add(item);\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < dest.Size(); i++)\r\n    if (dest[i] == item)\r\n    {\r\n      dest.Delete(i);\r\n      break;\r\n    }\r\n  dest.Insert(0, item);\r\n}\r\n\r\nvoid CHandler::FillPopIDs()\r\n{ \r\n  _fileInfoPopIDs.Clear();\r\n\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() < 1)\r\n    return;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_database = volume.Database;\r\n  #endif\r\n\r\n  CRecordVector<UInt64> fileInfoPopIDs = _database.ArchiveInfo.FileInfoPopIDs;\r\n\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);\r\n\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCreationTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastWriteTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastAccessTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);\r\n  _fileInfoPopIDs += fileInfoPopIDs; \r\n \r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Add(98);\r\n  _fileInfoPopIDs.Add(99);\r\n  #endif\r\n  #ifdef _MULTI_PACK\r\n  _fileInfoPopIDs.Add(100);\r\n  _fileInfoPopIDs.Add(101);\r\n  _fileInfoPopIDs.Add(102);\r\n  _fileInfoPopIDs.Add(103);\r\n  _fileInfoPopIDs.Add(104);\r\n  #endif\r\n\r\n  #ifndef _SFX\r\n  InsertToHead(_fileInfoPopIDs, NID::kLastWriteTime);\r\n  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);\r\n  InsertToHead(_fileInfoPopIDs, NID::kSize);\r\n  InsertToHead(_fileInfoPopIDs, NID::kName);\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)\r\n{\r\n  *numProperties = _fileInfoPopIDs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 index,     \r\n      BSTR *name, PROPID *propID, VARTYPE *varType)\r\n{\r\n  if((int)index >= _fileInfoPopIDs.Size())\r\n    return E_INVALIDARG;\r\n  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);\r\n  if (indexInMap == -1)\r\n    return E_INVALIDARG;\r\n  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;\r\n  *propID = srcItem.propid;\r\n  *varType = srcItem.vt;\r\n  *name = 0;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zProperties.h",
    "content": "// 7zProperties.h\r\n\r\n#ifndef __7Z_PROPERTIES_H\r\n#define __7Z_PROPERTIES_H\r\n\r\n#include \"../../PropID.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nenum\r\n{\r\n  kpidPackedSize0 = kpidUserDefined,\r\n  kpidPackedSize1, \r\n  kpidPackedSize2,\r\n  kpidPackedSize3,\r\n  kpidPackedSize4\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zRegister.cpp",
    "content": "// 7zRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"7zHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::N7z::CHandler;  }\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"7z\", L\"7z\", 0, 7, {'7' + 1 , 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };\r\n\r\nREGISTER_ARC_DEC_SIG(7z)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zSpecStream.cpp",
    "content": "// 7zSpecStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zSpecStream.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result; \r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(\r\n    UInt64 subStream, UInt64 *value)\r\n{\r\n  if (_getSubStreamSize == NULL)\r\n    return E_NOTIMPL;\r\n  return  _getSubStreamSize->GetSubStreamSize(subStream, value);\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zSpecStream.h",
    "content": "// 7zSpecStream.h\r\n\r\n#ifndef __7Z_SPEC_STREAM_H\r\n#define __7Z_SPEC_STREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CSequentialInStreamSizeCount2: \r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _getSubStreamSize = 0;\r\n    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zUpdate.cpp",
    "content": "// UpdateMain.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zUpdate.h\"\r\n#include \"7zFolderInStream.h\"\r\n#include \"7zEncode.h\"\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n\r\n#include \"../../Compress/Copy/CopyCoder.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kMatchFinderForBCJ2_LZMA = L\"BT2\";\r\nstatic const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;\r\nstatic const UInt32 kAlgorithmForBCJ2_LZMA = 1;\r\nstatic const UInt32 kNumFastBytesForBCJ2_LZMA = 64;\r\n\r\nstatic HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream, \r\n    UInt64 position, UInt64 size, ICompressProgressInfo *progress)\r\n{\r\n  RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));\r\n  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;\r\n  CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);\r\n  streamSpec->SetStream(inStream);\r\n  streamSpec->Init(size);\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n  RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));\r\n  return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);\r\n}\r\n\r\nstatic int GetReverseSlashPos(const UString &name)\r\n{\r\n  int slashPos = name.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = name.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n  return slashPos;\r\n}\r\n\r\nint CUpdateItem::GetExtensionPos() const\r\n{\r\n  int slashPos = GetReverseSlashPos(Name);\r\n  int dotPos = Name.ReverseFind(L'.');\r\n  if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n    return Name.Length();\r\n  return dotPos + 1;\r\n}\r\n\r\nUString CUpdateItem::GetExtension() const\r\n{\r\n  return Name.Mid(GetExtensionPos());\r\n}\r\n\r\n#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }\r\n\r\nstatic int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)\r\n{\r\n  size_t c1 = a1.GetCapacity();\r\n  size_t c2 = a2.GetCapacity();\r\n  RINOZ(MyCompare(c1, c2));\r\n  for (size_t i = 0; i < c1; i++)\r\n    RINOZ(MyCompare(a1[i], a2[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareCoders(const CCoderInfo &c1, const CCoderInfo &c2)\r\n{\r\n  RINOZ(MyCompare(c1.NumInStreams, c2.NumInStreams));\r\n  RINOZ(MyCompare(c1.NumOutStreams, c2.NumOutStreams));\r\n  RINOZ(MyCompare(c1.MethodID, c2.MethodID));\r\n  return CompareBuffers(c1.Properties, c2.Properties);\r\n}\r\n\r\nstatic int CompareBindPairs(const CBindPair &b1, const CBindPair &b2)\r\n{\r\n  RINOZ(MyCompare(b1.InIndex, b2.InIndex));\r\n  return MyCompare(b1.OutIndex, b2.OutIndex);\r\n}\r\n\r\nstatic int CompareFolders(const CFolder &f1, const CFolder &f2)\r\n{\r\n  int s1 = f1.Coders.Size();\r\n  int s2 = f2.Coders.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  int i;\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareCoders(f1.Coders[i], f2.Coders[i]));\r\n  s1 = f1.BindPairs.Size();\r\n  s2 = f2.BindPairs.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareBindPairs(f1.BindPairs[i], f2.BindPairs[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareFiles(const CFileItem &f1, const CFileItem &f2)\r\n{\r\n  return MyStringCompareNoCase(f1.Name, f2.Name);\r\n}\r\n\r\nstatic int CompareFolderRefs(const int *p1, const int *p2, void *param)\r\n{\r\n  int i1 = *p1;\r\n  int i2 = *p2;\r\n  const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param;\r\n  RINOZ(CompareFolders(\r\n      db.Folders[i1],\r\n      db.Folders[i2]));\r\n  RINOZ(MyCompare(\r\n      db.NumUnPackStreamsVector[i1],\r\n      db.NumUnPackStreamsVector[i2]));\r\n  if (db.NumUnPackStreamsVector[i1] == 0)\r\n    return 0;\r\n  return CompareFiles(\r\n      db.Files[db.FolderStartFileIndex[i1]],\r\n      db.Files[db.FolderStartFileIndex[i2]]);\r\n}\r\n\r\n////////////////////////////////////////////////////////////\r\n\r\nstatic int CompareEmptyItems(const int *p1, const int *p2, void *param)\r\n{\r\n  const CObjectVector<CUpdateItem> &updateItems = *(const CObjectVector<CUpdateItem> *)param;\r\n  const CUpdateItem &u1 = updateItems[*p1];\r\n  const CUpdateItem &u2 = updateItems[*p2];\r\n  if (u1.IsDirectory != u2.IsDirectory)\r\n    return (u1.IsDirectory) ? 1 : -1;\r\n  if (u1.IsDirectory)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    int n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  if (u1.IsAnti != u2.IsAnti)\r\n    return (u1.IsAnti ? 1 : -1);\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstatic const char *g_Exts = \r\n  \" lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo\" \r\n  \" zip jar ear war msi\"\r\n  \" 3gp avi mov mpeg mpg mpe wmv\"\r\n  \" aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav\"\r\n  \" swf \"\r\n  \" chm hxi hxs\"\r\n  \" gif jpeg jpg jp2 png tiff  bmp ico psd psp\"\r\n  \" awg ps eps cgm dxf svg vrml wmf emf ai md\"\r\n  \" cad dwg pps key sxi\"\r\n  \" max 3ds\"\r\n  \" iso bin nrg mdf img pdi tar cpio xpi\"\r\n  \" vfd vhd vud vmc vsv\"\r\n  \" vmdk dsk nvram vmem vmsd vmsn vmss vmtm\"\r\n  \" inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def\" \r\n  \" f77 f f90 f95\"\r\n  \" asm sql manifest dep \"\r\n  \" mak clw csproj vcproj sln dsp dsw \"\r\n  \" class \"\r\n  \" bat cmd\"\r\n  \" xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml\"\r\n  \" awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs\"\r\n  \" text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf\"\r\n  \" sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf\"\r\n  \" abw afp cwk lwp wpd wps wpt wrf wri\"\r\n  \" abf afm bdf fon mgf otf pcf pfa snf ttf\"\r\n  \" dbf mdb nsf ntf wdb db fdb gdb\"\r\n  \" exe dll ocx vbx sfx sys tlb awx com obj lib out o so \"\r\n  \" pdb pch idb ncb opt\";\r\n\r\nint GetExtIndex(const char *ext)\r\n{\r\n  int extIndex = 1;\r\n  const char *p = g_Exts;\r\n  for (;;)\r\n  {\r\n    char c = *p++;\r\n    if (c == 0)\r\n      return extIndex;\r\n    if (c == ' ')\r\n      continue;\r\n    int pos = 0;\r\n    for (;;)\r\n    {\r\n      char c2 = ext[pos++];\r\n      if (c2 == 0 && (c == 0 || c == ' '))\r\n        return extIndex;\r\n      if (c != c2)\r\n        break;\r\n      c = *p++;\r\n    }\r\n    extIndex++;\r\n    for (;;)\r\n    {\r\n      if (c == 0)\r\n        return extIndex;\r\n      if (c == ' ')\r\n        break;\r\n      c = *p++;\r\n    }\r\n  }\r\n}\r\n\r\nstruct CRefItem\r\n{\r\n  UInt32 Index;\r\n  const CUpdateItem *UpdateItem;\r\n  UInt32 ExtensionPos;\r\n  UInt32 NamePos;\r\n  int ExtensionIndex;\r\n  CRefItem(UInt32 index, const CUpdateItem &updateItem, bool sortByType):\r\n    Index(index),\r\n    UpdateItem(&updateItem),\r\n    ExtensionPos(0),\r\n    NamePos(0),\r\n    ExtensionIndex(0)\r\n  {\r\n    if (sortByType)\r\n    {\r\n      int slashPos = GetReverseSlashPos(updateItem.Name);\r\n      NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0);\r\n      int dotPos = updateItem.Name.ReverseFind(L'.');\r\n      if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n        ExtensionPos = updateItem.Name.Length();\r\n      else \r\n      {\r\n        ExtensionPos = dotPos + 1;\r\n        UString us = updateItem.Name.Mid(ExtensionPos);\r\n        if (!us.IsEmpty())\r\n        {\r\n          us.MakeLower();\r\n          int i;\r\n          AString s;\r\n          for (i = 0; i < us.Length(); i++)\r\n          {\r\n            wchar_t c = us[i];\r\n            if (c >= 0x80)\r\n              break;\r\n            s += (char)c;\r\n          }\r\n          if (i == us.Length())\r\n            ExtensionIndex = GetExtIndex(s);\r\n          else\r\n            ExtensionIndex = 0;\r\n        }\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nstatic int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *param)\r\n{\r\n  const CRefItem &a1 = *p1;\r\n  const CRefItem &a2 = *p2;\r\n  const CUpdateItem &u1 = *a1.UpdateItem;\r\n  const CUpdateItem &u2 = *a2.UpdateItem;\r\n  int n;\r\n  if (u1.IsDirectory != u2.IsDirectory)\r\n    return (u1.IsDirectory) ? 1 : -1;\r\n  if (u1.IsDirectory)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  bool sortByType = *(bool *)param;\r\n  if (sortByType)\r\n  {\r\n    RINOZ(MyCompare(a1.ExtensionIndex, a2.ExtensionIndex))\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos));\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos));\r\n    if (u1.IsLastWriteTimeDefined && u2.IsLastWriteTimeDefined)\r\n      RINOZ(CompareFileTime(&u1.LastWriteTime, &u2.LastWriteTime));\r\n    RINOZ(MyCompare(u1.Size, u2.Size))\r\n  }\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstruct CSolidGroup\r\n{\r\n  CCompressionMethodMode Method;\r\n  CRecordVector<UInt32> Indices;\r\n};\r\n\r\nstatic wchar_t *g_ExeExts[] =\r\n{\r\n  L\"dll\",\r\n  L\"exe\",\r\n  L\"ocx\",\r\n  L\"sfx\",\r\n  L\"sys\"\r\n};\r\n\r\nstatic bool IsExeFile(const UString &ext)\r\n{\r\n  for (int i = 0; i < sizeof(g_ExeExts) / sizeof(g_ExeExts[0]); i++)\r\n    if (ext.CompareNoCase(g_ExeExts[i]) == 0)\r\n      return true;\r\n  return false;\r\n}\r\n\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_BCJ   = 0x03030103;\r\nstatic const UInt64 k_BCJ2  = 0x0303011B;\r\n\r\nstatic bool GetMethodFull(UInt64 methodID, \r\n    UInt32 numInStreams, CMethodFull &methodResult)\r\n{\r\n  methodResult.Id = methodID;\r\n  methodResult.NumInStreams = numInStreams;\r\n  methodResult.NumOutStreams = 1;\r\n  return true;\r\n}\r\n\r\nstatic bool MakeExeMethod(const CCompressionMethodMode &method, \r\n    bool bcj2Filter, CCompressionMethodMode &exeMethod)\r\n{\r\n  exeMethod = method;\r\n  if (bcj2Filter)\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ2, 4, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    if (!GetMethodFull(k_LZMA, 1, methodFull))\r\n      return false;\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kAlgorithm;\r\n      property.Value = kAlgorithmForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kMatchFinder;\r\n      property.Value = kMatchFinderForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n      property.Value = kDictionaryForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kNumFastBytes;\r\n      property.Value = kNumFastBytesForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n\r\n    exeMethod.Methods.Add(methodFull);\r\n    exeMethod.Methods.Add(methodFull);\r\n    CBind bind;\r\n\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 2;\r\n    bind.OutStream = 1;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 3;\r\n    bind.OutStream = 2;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  else\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ, 1, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    CBind bind;\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  return true;\r\n}   \r\n\r\nstatic void SplitFilesToGroups(\r\n    const CCompressionMethodMode &method, \r\n    bool useFilters, bool maxFilter,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    CObjectVector<CSolidGroup> &groups)\r\n{\r\n  if (method.Methods.Size() != 1 || method.Binds.Size() != 0)\r\n    useFilters = false;\r\n  groups.Clear();\r\n  groups.Add(CSolidGroup());\r\n  groups.Add(CSolidGroup());\r\n  CSolidGroup &generalGroup = groups[0];\r\n  CSolidGroup &exeGroup = groups[1];\r\n  generalGroup.Method = method;\r\n  int i;\r\n  for (i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &updateItem = updateItems[i];\r\n    if (!updateItem.NewData)\r\n      continue;\r\n    if (!updateItem.HasStream())\r\n      continue;\r\n    if (useFilters)\r\n    {\r\n      const UString name = updateItem.Name;\r\n      int dotPos = name.ReverseFind(L'.');\r\n      if (dotPos >= 0)\r\n      {\r\n        UString ext = name.Mid(dotPos + 1);\r\n        if (IsExeFile(ext))\r\n        {\r\n          exeGroup.Indices.Add(i);\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    generalGroup.Indices.Add(i);\r\n  }\r\n  if (exeGroup.Indices.Size() > 0)\r\n    if (!MakeExeMethod(method, maxFilter, exeGroup.Method))\r\n      exeGroup.Method = method;\r\n  for (i = 0; i < groups.Size();)\r\n    if (groups[i].Indices.Size() == 0)\r\n      groups.Delete(i);\r\n    else\r\n      i++;\r\n}\r\n\r\nstatic void FromUpdateItemToFileItem(const CUpdateItem &updateItem, \r\n    CFileItem &file)\r\n{\r\n  file.Name = NItemName::MakeLegalName(updateItem.Name);\r\n  if (updateItem.AttributesAreDefined)\r\n    file.SetAttributes(updateItem.Attributes);\r\n  \r\n  if (updateItem.IsCreationTimeDefined)\r\n    file.SetCreationTime(updateItem.CreationTime);\r\n  if (updateItem.IsLastWriteTimeDefined)\r\n    file.SetLastWriteTime(updateItem.LastWriteTime);\r\n  if (updateItem.IsLastAccessTimeDefined)\r\n    file.SetLastAccessTime(updateItem.LastAccessTime);\r\n  \r\n  file.UnPackSize = updateItem.Size;\r\n  file.IsDirectory = updateItem.IsDirectory;\r\n  file.IsAnti = updateItem.IsAnti;\r\n  file.HasStream = updateItem.HasStream();\r\n}\r\n\r\nstatic HRESULT Update2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  UInt64 numSolidFiles = options.NumSolidFiles;\r\n  if (numSolidFiles == 0)\r\n    numSolidFiles = 1;\r\n  /*\r\n  CMyComPtr<IOutStream> outStream;\r\n  RINOK(seqOutStream->QueryInterface(IID_IOutStream, (void **)&outStream));\r\n  if (!outStream)\r\n    return E_NOTIMPL;\r\n  */\r\n\r\n  UInt64 startBlockSize = database != 0 ? database->ArchiveInfo.StartPosition: 0;\r\n  if (startBlockSize > 0 && !options.RemoveSfxBlock)\r\n  {\r\n    RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));\r\n  }\r\n\r\n  CRecordVector<int> fileIndexToUpdateIndexMap;\r\n  if (database != 0)\r\n  {\r\n    fileIndexToUpdateIndexMap.Reserve(database->Files.Size());\r\n    for (int i = 0; i < database->Files.Size(); i++)\r\n      fileIndexToUpdateIndexMap.Add(-1);\r\n  }\r\n  int i;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    int index = updateItems[i].IndexInArchive;\r\n    if (index != -1)\r\n      fileIndexToUpdateIndexMap[index] = i;\r\n  }\r\n\r\n  CRecordVector<int> folderRefs;\r\n  if (database != 0)\r\n  {\r\n    for(i = 0; i < database->Folders.Size(); i++)\r\n    {\r\n      CNum indexInFolder = 0;\r\n      CNum numCopyItems = 0;\r\n      CNum numUnPackStreams = database->NumUnPackStreamsVector[i];\r\n      for (CNum fileIndex = database->FolderStartFileIndex[i];\r\n      indexInFolder < numUnPackStreams; fileIndex++)\r\n      {\r\n        if (database->Files[fileIndex].HasStream)\r\n        {\r\n          indexInFolder++;\r\n          int updateIndex = fileIndexToUpdateIndexMap[fileIndex];\r\n          if (updateIndex >= 0)\r\n            if (!updateItems[updateIndex].NewData)\r\n              numCopyItems++;\r\n        }\r\n      }\r\n      if (numCopyItems != numUnPackStreams && numCopyItems != 0)\r\n        return E_NOTIMPL; // It needs repacking !!!\r\n      if (numCopyItems > 0)\r\n        folderRefs.Add(i);\r\n    }\r\n    folderRefs.Sort(CompareFolderRefs, (void *)database);\r\n  }\r\n\r\n  CArchiveDatabase newDatabase;\r\n\r\n  ////////////////////////////\r\n\r\n  COutArchive archive;\r\n  RINOK(archive.Create(seqOutStream, false));\r\n  RINOK(archive.SkeepPrefixArchiveHeader());\r\n  UInt64 complexity = 0;\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n    complexity += database->GetFolderFullPackSize(folderRefs[i]);\r\n  UInt64 inSizeForReduce = 0;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &updateItem = updateItems[i];\r\n    if (updateItem.NewData)\r\n    {\r\n      complexity += updateItem.Size;\r\n      if (numSolidFiles == 1)\r\n      {\r\n        if (updateItem.Size > inSizeForReduce)\r\n          inSizeForReduce = updateItem.Size;\r\n      }\r\n      else\r\n        inSizeForReduce += updateItem.Size;\r\n    }\r\n  }\r\n  RINOK(updateCallback->SetTotal(complexity));\r\n  complexity = 0;\r\n  RINOK(updateCallback->SetCompleted(&complexity));\r\n\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(updateCallback, true);\r\n\r\n  /////////////////////////////////////////\r\n  // Write Copy Items\r\n\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n  {\r\n    int folderIndex = folderRefs[i];\r\n    \r\n    lps->ProgressOffset = complexity;\r\n    UInt64 packSize = database->GetFolderFullPackSize(folderIndex);\r\n    RINOK(WriteRange(inStream, archive.SeqStream,\r\n        database->GetFolderStreamPos(folderIndex, 0), packSize, progress));\r\n    complexity += packSize;\r\n    \r\n    const CFolder &folder = database->Folders[folderIndex];\r\n    CNum startIndex = database->FolderStartPackStreamIndex[folderIndex];\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      newDatabase.PackSizes.Add(database->PackSizes[startIndex + j]);\r\n      // newDatabase.PackCRCsDefined.Add(database.PackCRCsDefined[startIndex + j]);\r\n      // newDatabase.PackCRCs.Add(database.PackCRCs[startIndex + j]);\r\n    }\r\n    newDatabase.Folders.Add(folder);\r\n\r\n    CNum numUnPackStreams = database->NumUnPackStreamsVector[folderIndex];\r\n    newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);\r\n\r\n    CNum indexInFolder = 0;\r\n    for (CNum fi = database->FolderStartFileIndex[folderIndex];\r\n        indexInFolder < numUnPackStreams; fi++)\r\n    {\r\n      CFileItem file = database->Files[fi];\r\n      if (file.HasStream)\r\n      {\r\n        indexInFolder++;\r\n        int updateIndex = fileIndexToUpdateIndexMap[fi];\r\n        if (updateIndex >= 0)\r\n        {\r\n          const CUpdateItem &updateItem = updateItems[updateIndex];\r\n          if (updateItem.NewProperties)\r\n          {\r\n            CFileItem file2;\r\n            FromUpdateItemToFileItem(updateItem, file2);\r\n            file2.UnPackSize = file.UnPackSize;\r\n            file2.FileCRC = file.FileCRC;\r\n            file2.IsFileCRCDefined = file.IsFileCRCDefined;\r\n            file2.HasStream = file.HasStream;\r\n            file = file2;\r\n          }\r\n        }\r\n        newDatabase.Files.Add(file);\r\n      }\r\n    }\r\n  }\r\n\r\n  /////////////////////////////////////////\r\n  // Compress New Files\r\n\r\n  CObjectVector<CSolidGroup> groups;\r\n  SplitFilesToGroups(*options.Method, options.UseFilters, options.MaxFilter, \r\n      updateItems, groups);\r\n\r\n  const UInt32 kMinReduceSize = (1 << 16);\r\n  if (inSizeForReduce < kMinReduceSize)\r\n    inSizeForReduce = kMinReduceSize;\r\n\r\n  for (int groupIndex = 0; groupIndex < groups.Size(); groupIndex++)\r\n  {\r\n    const CSolidGroup &group = groups[groupIndex];\r\n    int numFiles = group.Indices.Size();\r\n    if (numFiles == 0)\r\n      continue;\r\n    CRecordVector<CRefItem> refItems;\r\n    refItems.Reserve(numFiles);\r\n    bool sortByType = (numSolidFiles > 1);\r\n    for (i = 0; i < numFiles; i++)\r\n      refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType));\r\n    refItems.Sort(CompareUpdateItems, (void *)&sortByType);\r\n    \r\n    CRecordVector<UInt32> indices;\r\n    indices.Reserve(numFiles);\r\n\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      UInt32 index = refItems[i].Index;\r\n      indices.Add(index);\r\n      /*\r\n      const CUpdateItem &updateItem = updateItems[index];\r\n      CFileItem file;\r\n      if (updateItem.NewProperties)\r\n        FromUpdateItemToFileItem(updateItem, file);\r\n      else\r\n        file = database.Files[updateItem.IndexInArchive];\r\n      if (file.IsAnti || file.IsDirectory)\r\n        return E_FAIL;\r\n      newDatabase.Files.Add(file);\r\n      */\r\n    }\r\n    \r\n    CEncoder encoder(group.Method);\r\n\r\n    for (i = 0; i < numFiles;)\r\n    {\r\n      UInt64 totalSize = 0;\r\n      int numSubFiles;\r\n      UString prevExtension;\r\n      for (numSubFiles = 0; i + numSubFiles < numFiles && \r\n          numSubFiles < numSolidFiles; numSubFiles++)\r\n      {\r\n        const CUpdateItem &updateItem = updateItems[indices[i + numSubFiles]];\r\n        totalSize += updateItem.Size;\r\n        if (totalSize > options.NumSolidBytes)\r\n          break;\r\n        if (options.SolidExtension)\r\n        {\r\n          UString ext = updateItem.GetExtension();\r\n          if (numSubFiles == 0)\r\n            prevExtension = ext;\r\n          else\r\n            if (ext.CompareNoCase(prevExtension) != 0)\r\n              break;\r\n        }\r\n      }\r\n      if (numSubFiles < 1)\r\n        numSubFiles = 1;\r\n\r\n      CFolderInStream *inStreamSpec = new CFolderInStream;\r\n      CMyComPtr<ISequentialInStream> solidInStream(inStreamSpec);\r\n      inStreamSpec->Init(updateCallback, &indices[i], numSubFiles);\r\n      \r\n      CFolder folderItem;\r\n\r\n      int startPackIndex = newDatabase.PackSizes.Size();\r\n      RINOK(encoder.Encode(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          solidInStream, NULL, &inSizeForReduce, folderItem, \r\n          archive.SeqStream, newDatabase.PackSizes, progress));\r\n\r\n      for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)\r\n        lps->OutSize += newDatabase.PackSizes[startPackIndex];\r\n\r\n      lps->InSize += folderItem.GetUnPackSize();\r\n      // for()\r\n      // newDatabase.PackCRCsDefined.Add(false);\r\n      // newDatabase.PackCRCs.Add(0);\r\n      \r\n      newDatabase.Folders.Add(folderItem);\r\n      \r\n      CNum numUnPackStreams = 0;\r\n      for (int subIndex = 0; subIndex < numSubFiles; subIndex++)\r\n      {\r\n        const CUpdateItem &updateItem = updateItems[indices[i + subIndex]];\r\n        CFileItem file;\r\n        if (updateItem.NewProperties)\r\n          FromUpdateItemToFileItem(updateItem, file);\r\n        else\r\n          file = database->Files[updateItem.IndexInArchive];\r\n        if (file.IsAnti || file.IsDirectory)\r\n          return E_FAIL;\r\n        \r\n        /*\r\n        CFileItem &file = newDatabase.Files[\r\n              startFileIndexInDatabase + i + subIndex];\r\n        */\r\n        if (!inStreamSpec->Processed[subIndex])\r\n        {\r\n          continue;\r\n          // file.Name += L\".locked\";\r\n        }\r\n\r\n        file.FileCRC = inStreamSpec->CRCs[subIndex];\r\n        file.UnPackSize = inStreamSpec->Sizes[subIndex];\r\n        if (file.UnPackSize != 0)\r\n        {\r\n          file.IsFileCRCDefined = true;\r\n          file.HasStream = true;\r\n          numUnPackStreams++;\r\n        }\r\n        else\r\n        {\r\n          file.IsFileCRCDefined = false;\r\n          file.HasStream = false;\r\n        }\r\n        newDatabase.Files.Add(file);\r\n      }\r\n      // numUnPackStreams = 0 is very bad case for locked files\r\n      // v3.13 doesn't understand it.\r\n      newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);\r\n      i += numSubFiles;\r\n    }\r\n  }\r\n\r\n  {\r\n    /////////////////////////////////////////\r\n    // Write Empty Files & Folders\r\n    \r\n    CRecordVector<int> emptyRefs;\r\n    for(i = 0; i < updateItems.Size(); i++)\r\n    {\r\n      const CUpdateItem &updateItem = updateItems[i];\r\n      if (updateItem.NewData)\r\n      {\r\n        if (updateItem.HasStream())\r\n          continue;\r\n      }\r\n      else\r\n        if (updateItem.IndexInArchive != -1)\r\n          if (database->Files[updateItem.IndexInArchive].HasStream)\r\n            continue;\r\n      emptyRefs.Add(i);\r\n    }\r\n    emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);\r\n    for(i = 0; i < emptyRefs.Size(); i++)\r\n    {\r\n      const CUpdateItem &updateItem = updateItems[emptyRefs[i]];\r\n      CFileItem file;\r\n      if (updateItem.NewProperties)\r\n        FromUpdateItemToFileItem(updateItem, file);\r\n      else\r\n        file = database->Files[updateItem.IndexInArchive];\r\n      newDatabase.Files.Add(file);\r\n    }\r\n  }\r\n    \r\n  /*\r\n  if (newDatabase.Files.Size() != updateItems.Size())\r\n    return E_FAIL;\r\n  */\r\n\r\n  return archive.WriteDatabase(EXTERNAL_CODECS_LOC_VARS\r\n      newDatabase, options.HeaderMethod, options.HeaderOptions);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\n\r\nstatic HRESULT WriteVolumeHeader(COutArchive &archive, CFileItem &file, const CUpdateOptions &options)\r\n{\r\n  CCoderInfo coder;\r\n  coder.NumInStreams = coder.NumOutStreams = 1;\r\n  coder.MethodID = k_Copy;\r\n  \r\n  CFolder folder;\r\n  folder.Coders.Add(coder);\r\n  folder.PackStreams.Add(0);\r\n  \r\n  CNum numUnPackStreams = 0;\r\n  if (file.UnPackSize != 0)\r\n  {\r\n    file.IsFileCRCDefined = true;\r\n    file.HasStream = true;\r\n    numUnPackStreams++;\r\n  }\r\n  else\r\n  {\r\n    throw 1;\r\n    file.IsFileCRCDefined = false;\r\n    file.HasStream = false;\r\n  }\r\n  folder.UnPackSizes.Add(file.UnPackSize);\r\n  \r\n  CArchiveDatabase newDatabase;\r\n  newDatabase.Files.Add(file);\r\n  newDatabase.Folders.Add(folder);\r\n  newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);\r\n  newDatabase.PackSizes.Add(file.UnPackSize);\r\n  newDatabase.PackCRCsDefined.Add(false);\r\n  newDatabase.PackCRCs.Add(file.FileCRC);\r\n  \r\n  return archive.WriteDatabase(newDatabase, \r\n      options.HeaderMethod, \r\n      false, \r\n      false);\r\n}\r\n\r\nHRESULT UpdateVolume(\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  if (updateItems.Size() != 1)\r\n    return E_NOTIMPL;\r\n\r\n  CMyComPtr<IArchiveUpdateCallback2> volumeCallback;\r\n  RINOK(updateCallback->QueryInterface(IID_IArchiveUpdateCallback2, (void **)&volumeCallback));\r\n  if (!volumeCallback)\r\n    return E_NOTIMPL;\r\n\r\n  CMyComPtr<ISequentialInStream> fileStream;\r\n  HRESULT result = updateCallback->GetStream(0, &fileStream);\r\n  if (result != S_OK && result != S_FALSE)\r\n    return result;\r\n  if (result == S_FALSE)\r\n    return E_FAIL;\r\n  \r\n  CFileItem file;\r\n  \r\n  const CUpdateItem &updateItem = updateItems[0];\r\n  if (updateItem.NewProperties)\r\n    FromUpdateItemToFileItem(updateItem, file);\r\n  else\r\n    file = database->Files[updateItem.IndexInArchive];\r\n  if (file.IsAnti || file.IsDirectory)\r\n    return E_FAIL;\r\n\r\n  UInt64 complexity = 0;\r\n  file.IsStartPosDefined = true;\r\n  file.StartPos = 0;\r\n  for (UInt64 volumeIndex = 0; true; volumeIndex++)\r\n  { \r\n    UInt64 volSize;\r\n    RINOK(volumeCallback->GetVolumeSize(volumeIndex, &volSize));\r\n    UInt64 pureSize = COutArchive::GetVolPureSize(volSize, file.Name.Length(), true);\r\n    CMyComPtr<ISequentialOutStream> volumeStream;\r\n    RINOK(volumeCallback->GetVolumeStream(volumeIndex, &volumeStream));\r\n   \r\n    COutArchive archive;\r\n    RINOK(archive.Create(volumeStream, true));\r\n    RINOK(archive.SkeepPrefixArchiveHeader());\r\n        \r\n    CSequentialInStreamWithCRC *inCrcStreamSpec = new CSequentialInStreamWithCRC;\r\n    CMyComPtr<ISequentialInStream> inCrcStream = inCrcStreamSpec;\r\n    inCrcStreamSpec->Init(fileStream);\r\n\r\n    RINOK(WriteRange(inCrcStream, volumeStream, pureSize, updateCallback, complexity));\r\n    file.UnPackSize = inCrcStreamSpec->GetSize();\r\n    if (file.UnPackSize == 0)\r\n      break;\r\n    file.FileCRC = inCrcStreamSpec->GetCRC();\r\n    RINOK(WriteVolumeHeader(archive, file, options));\r\n    file.StartPos += file.UnPackSize;\r\n    if (file.UnPackSize < pureSize)\r\n      break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nclass COutVolumeStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback, \r\n      const UString &name)  \r\n  { \r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutVolumeStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (!_volumeStream)\r\n    {\r\n      RINOK(VolumeCallback->GetVolumeSize(_volIndex, &_volSize));\r\n      RINOK(VolumeCallback->GetVolumeStream(_volIndex, &_volumeStream));\r\n      _volIndex++;\r\n      _curPos = 0;\r\n      RINOK(_archive.Create(_volumeStream, true));\r\n      RINOK(_archive.SkeepPrefixArchiveHeader());\r\n      _crc.Init();\r\n      continue;\r\n    }\r\n    UInt64 pureSize = COutArchive::GetVolPureSize(_volSize, _file.Name.Length());\r\n    UInt32 curSize = (UInt32)MyMin(UInt64(size), pureSize - _curPos);\r\n\r\n    _crc.Update(data, curSize);\r\n    UInt32 realProcessed;\r\n    RINOK(_volumeStream->Write(data, curSize, &realProcessed))\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _curPos += realProcessed;\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n    if (_curPos == pureSize)\r\n    {\r\n      RINOK(Flush());\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (seqOutStream)\r\n  #endif\r\n    return Update2(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        inStream, database, updateItems,\r\n        seqOutStream, updateCallback, options);\r\n  #ifdef _7Z_VOL\r\n  if (options.VolumeMode)\r\n    return UpdateVolume(inStream, database, updateItems,\r\n      seqOutStream, updateCallback, options);\r\n  COutVolumeStream *volStreamSpec = new COutVolumeStream;\r\n  CMyComPtr<ISequentialOutStream> volStream = volStreamSpec;\r\n  CMyComPtr<IArchiveUpdateCallback2> volumeCallback;\r\n  RINOK(updateCallback->QueryInterface(IID_IArchiveUpdateCallback2, (void **)&volumeCallback));\r\n  if (!volumeCallback)\r\n    return E_NOTIMPL;\r\n  volStreamSpec->Init(volumeCallback, L\"a.7z\");\r\n  volStreamSpec->_options = options;\r\n  RINOK(Update2(inStream, database, updateItems,\r\n    volStream, updateCallback, options));\r\n  return volStreamSpec->Flush();\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/7zUpdate.h",
    "content": "// 7zUpdate.h\r\n\r\n#ifndef __7Z_UPDATE_H\r\n#define __7Z_UPDATE_H\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CUpdateItem\r\n{\r\n  bool NewData;\r\n  bool NewProperties;\r\n  int IndexInArchive;\r\n  int IndexInClient;\r\n  \r\n  UInt32 Attributes;\r\n  FILETIME CreationTime;\r\n  FILETIME LastWriteTime;\r\n  FILETIME LastAccessTime;\r\n\r\n  UInt64 Size;\r\n  UString Name;\r\n  \r\n  bool IsAnti;\r\n  bool IsDirectory;\r\n\r\n  bool IsCreationTimeDefined;\r\n  bool IsLastWriteTimeDefined;\r\n  bool IsLastAccessTimeDefined;\r\n  bool AttributesAreDefined;\r\n\r\n  bool HasStream() const \r\n    { return !IsDirectory && !IsAnti && Size != 0; }\r\n  CUpdateItem():  \r\n      IsAnti(false), \r\n      AttributesAreDefined(false), \r\n      IsCreationTimeDefined(false), \r\n      IsLastWriteTimeDefined(false), \r\n      IsLastAccessTimeDefined(false)\r\n      {}\r\n  void SetDirectoryStatusFromAttributes()\r\n    { IsDirectory = ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0); };\r\n\r\n  int GetExtensionPos() const;\r\n  UString GetExtension() const;\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  const CCompressionMethodMode *Method;\r\n  const CCompressionMethodMode *HeaderMethod;\r\n  bool UseFilters;\r\n  bool MaxFilter;\r\n\r\n  CHeaderOptions HeaderOptions;\r\n\r\n  UInt64 NumSolidFiles;\r\n  UInt64 NumSolidBytes;\r\n  bool SolidExtension;\r\n  bool RemoveSfxBlock;\r\n  bool VolumeMode;\r\n};\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options);\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Archive.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Archive2.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n  GetNumberOfMethods PRIVATE\r\n  GetMethodProperty PRIVATE\r\n  SetLargePageMode PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/ArchiveExports.cpp",
    "content": "// ArchiveExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterArc.h\"\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax]; \r\nvoid RegisterArc(const CArcInfo *arcInfo) \r\n{ \r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo; \r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler, \r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\n#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nint FindFormatCalssId(const GUID *clsID)\r\n{\r\n  GUID cls = *clsID;\r\n  CLS_ARC_ID_ITEM(cls) = 0;\r\n  if (cls != CLSID_CArchiveHandler)\r\n    return -1;\r\n  Byte id = CLS_ARC_ID_ITEM(*clsID);\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n    if (g_Arcs[i]->ClassId == id)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nSTDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  {\r\n    int needIn = (*iid == IID_IInArchive);\r\n    int needOut = (*iid == IID_IOutArchive);\r\n    if (!needIn && !needOut)\r\n      return E_NOINTERFACE;\r\n    int formatIndex = FindFormatCalssId(clsid);\r\n    if (formatIndex < 0)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    \r\n    const CArcInfo &arc = *g_Arcs[formatIndex];\r\n    if (needIn)\r\n    {\r\n      *outObject = arc.CreateInArchive();\r\n      ((IInArchive *)*outObject)->AddRef();\r\n    }\r\n    else\r\n    {\r\n      if (!arc.CreateOutArchive)\r\n        return CLASS_E_CLASSNOTAVAILABLE;\r\n      *outObject = arc.CreateOutArchive();\r\n      ((IOutArchive *)*outObject)->AddRef();\r\n    }\r\n  }\r\n  COM_TRY_END\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  if (formatIndex >= g_NumArcs)\r\n    return E_INVALIDARG;\r\n  const CArcInfo &arc = *g_Arcs[formatIndex];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case NArchive::kName:\r\n      prop = arc.Name;\r\n      break;\r\n    case NArchive::kClassID:\r\n    {\r\n      GUID clsId = CLSID_CArchiveHandler;\r\n      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;\r\n      return SetPropGUID(clsId, value);\r\n    }\r\n    case NArchive::kExtension:\r\n      if (arc.Ext != 0)\r\n        prop = arc.Ext;\r\n      break;\r\n    case NArchive::kAddExtension:\r\n      if (arc.AddExt != 0)\r\n        prop = arc.AddExt;\r\n      break;\r\n    case NArchive::kUpdate:\r\n      prop = (bool)(arc.CreateOutArchive != 0);\r\n      break;\r\n    case NArchive::kKeepName:\r\n      prop = arc.KeepName;\r\n      break;\r\n    case NArchive::kStartSignature:\r\n      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  return GetHandlerProperty2(0, propID, value);\r\n}\r\n\r\nSTDAPI GetNumberOfFormats(UINT32 *numFormats)\r\n{\r\n  *numFormats = g_NumArcs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/CoderMixer2.cpp",
    "content": "// CoderMixer2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):\r\n  _srcBindInfo(srcBindInfo)\r\n{\r\n  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);\r\n\r\n  UInt32  j;\r\n  for (j = 0; j < NumSrcInStreams; j++)\r\n  {\r\n    _srcInToDestOutMap.Add(0);\r\n    DestOutToSrcInMap.Add(0);\r\n  }\r\n  for (j = 0; j < _numSrcOutStreams; j++)\r\n  {\r\n    _srcOutToDestInMap.Add(0);\r\n    _destInToSrcOutMap.Add(0);\r\n  }\r\n\r\n  UInt32 destInOffset = 0;\r\n  UInt32 destOutOffset = 0;\r\n  UInt32 srcInOffset = NumSrcInStreams;\r\n  UInt32 srcOutOffset = _numSrcOutStreams;\r\n\r\n  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];\r\n\r\n    srcInOffset -= srcCoderInfo.NumInStreams;\r\n    srcOutOffset -= srcCoderInfo.NumOutStreams;\r\n    \r\n    UInt32 j;\r\n    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)\r\n    {\r\n      UInt32 index = srcInOffset + j;\r\n      _srcInToDestOutMap[index] = destOutOffset;\r\n      DestOutToSrcInMap[destOutOffset] = index;\r\n    }\r\n    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)\r\n    {\r\n      UInt32 index = srcOutOffset + j;\r\n      _srcOutToDestInMap[index] = destInOffset;\r\n      _destInToSrcOutMap[destInOffset] = index;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)\r\n{\r\n  destBindInfo.Coders.Clear();\r\n  destBindInfo.BindPairs.Clear();\r\n  destBindInfo.InStreams.Clear();\r\n  destBindInfo.OutStreams.Clear();\r\n\r\n  int i;\r\n  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];\r\n    CCoderStreamsInfo destCoderInfo;\r\n    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;\r\n    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;\r\n    destBindInfo.Coders.Add(destCoderInfo);\r\n  }\r\n  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];\r\n    CBindPair destBindPair;\r\n    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];\r\n    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];\r\n    destBindInfo.BindPairs.Add(destBindPair);\r\n  }\r\n  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)\r\n    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);\r\n  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)\r\n    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);\r\n}\r\n\r\nCCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams): \r\n    NumInStreams(numInStreams),\r\n    NumOutStreams(numOutStreams)\r\n{\r\n  InSizes.Reserve(NumInStreams);\r\n  InSizePointers.Reserve(NumInStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes, \r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\nvoid CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,\r\n      const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n}  \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/CoderMixer2.h",
    "content": "// CoderMixer2.h\r\n\r\n#ifndef __CODER_MIXER2_H\r\n#define __CODER_MIXER2_H\r\n\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n};\r\n\r\nstruct CCoderStreamsInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n};\r\n\r\nstruct CBindInfo\r\n{\r\n  CRecordVector<CCoderStreamsInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<UInt32> InStreams;\r\n  CRecordVector<UInt32> OutStreams;\r\n\r\n  void Clear()\r\n  {\r\n    Coders.Clear();\r\n    BindPairs.Clear();\r\n    InStreams.Clear();\r\n    OutStreams.Clear();\r\n  }\r\n\r\n  /*\r\n  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const\r\n  {\r\n    UInt32 numOutStreams = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      numOutStreams += Coders[i].NumOutStreams;\r\n    return numOutStreams;\r\n  }\r\n  */\r\n\r\n\r\n  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const\r\n  {\r\n    numInStreams = 0;\r\n    numOutStreams = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n    {\r\n      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];\r\n      numInStreams += coderStreamsInfo.NumInStreams;\r\n      numOutStreams += coderStreamsInfo.NumOutStreams;\r\n    }\r\n  }\r\n\r\n  int FindBinderForInStream(UInt32 inStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBinderForOutStream(UInt32 outStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumInStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumOutStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n\r\n  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex, \r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumInStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex, \r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumOutStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n};\r\n\r\nclass CBindReverseConverter\r\n{\r\n  UInt32 _numSrcOutStreams;\r\n  NCoderMixer::CBindInfo _srcBindInfo;\r\n  CRecordVector<UInt32> _srcInToDestOutMap;\r\n  CRecordVector<UInt32> _srcOutToDestInMap;\r\n  CRecordVector<UInt32> _destInToSrcOutMap;\r\npublic:\r\n  UInt32 NumSrcInStreams;\r\n  CRecordVector<UInt32> DestOutToSrcInMap;\r\n\r\n  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);\r\n  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);\r\n};\r\n\r\nstruct CCoderInfo2\r\n{\r\n  CMyComPtr<ICompressCoder> Coder;\r\n  CMyComPtr<ICompressCoder2> Coder2;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n\r\n  CRecordVector<UInt64> InSizes;\r\n  CRecordVector<UInt64> OutSizes;\r\n  CRecordVector<const UInt64 *> InSizePointers;\r\n  CRecordVector<const UInt64 *> OutSizePointers;\r\n\r\n  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n\r\n  HRESULT QueryInterface(REFGUID iid, void** pp) const\r\n  {\r\n    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;\r\n    return p->QueryInterface(iid, pp);\r\n  }\r\n};\r\n\r\nclass CCoderMixer2\r\n{\r\npublic:\r\n  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;\r\n  virtual void ReInit() = 0;\r\n  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;\r\n};\r\n\r\n}\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/CoderMixer2MT.cpp",
    "content": "// CoderMixer2MT.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2MT.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams): \r\n    CCoderInfo2(numInStreams, numOutStreams)\r\n{\r\n  InStreams.Reserve(NumInStreams);\r\n  InStreamPointers.Reserve(NumInStreams);\r\n  OutStreams.Reserve(NumOutStreams);\r\n  OutStreamPointers.Reserve(NumOutStreams);\r\n}\r\n\r\nvoid CCoder2::Execute() { Code(NULL); }\r\n\r\nvoid CCoder2::Code(ICompressProgressInfo *progress)\r\n{\r\n  InStreamPointers.Clear();\r\n  OutStreamPointers.Clear();\r\n  UInt32 i;\r\n  for (i = 0; i < NumInStreams; i++)\r\n  {\r\n    if (InSizePointers[i] != NULL)\r\n      InSizePointers[i] = &InSizes[i];\r\n    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);\r\n  }\r\n  for (i = 0; i < NumOutStreams; i++)\r\n  {\r\n    if (OutSizePointers[i] != NULL)\r\n      OutSizePointers[i] = &OutSizes[i];\r\n    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);\r\n  }\r\n  if (Coder)\r\n    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0], \r\n        InSizePointers[0], OutSizePointers[0], progress);\r\n  else\r\n    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,\r\n      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);\r\n  {\r\n    int i;\r\n    for (i = 0; i < InStreams.Size(); i++)\r\n      InStreams[i].Release();\r\n    for (i = 0; i < OutStreams.Size(); i++)\r\n      OutStreams[i].Release();\r\n  }\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes, \r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\n\r\nvoid CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n//////////////////////////////////////\r\n// CCoderMixer2MT\r\n\r\nHRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)\r\n{  \r\n  _bindInfo = bindInfo; \r\n  _streamBinders.Clear();\r\n  for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    _streamBinders.Add(CStreamBinder());\r\n    RINOK(_streamBinders.Back().CreateEvents());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoderCommon()\r\n{\r\n  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];\r\n  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);\r\n  _coders.Add(threadCoderInfo);\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder(ICompressCoder *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder = coder;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder2 = coder;\r\n}\r\n\r\n\r\nvoid CCoderMixer2MT::ReInit()\r\n{\r\n  for(int i = 0; i < _streamBinders.Size(); i++)\r\n    _streamBinders[i].ReInit();\r\n}\r\n\r\n\r\nHRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams) \r\n{\r\n  /*\r\n  if (_coders.Size() != _bindInfo.Coders.Size())\r\n    throw 0;\r\n  */\r\n  int i;\r\n  for(i = 0; i < _coders.Size(); i++)\r\n  {\r\n    CCoder2 &coderInfo = _coders[i];\r\n    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];\r\n    coderInfo.InStreams.Clear();\r\n    UInt32 j;\r\n    for(j = 0; j < coderStreamsInfo.NumInStreams; j++)\r\n      coderInfo.InStreams.Add(NULL);\r\n    coderInfo.OutStreams.Clear();\r\n    for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)\r\n      coderInfo.OutStreams.Add(NULL);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = _bindInfo.BindPairs[i];\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);\r\n    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);\r\n\r\n    _streamBinders[i].CreateStreams(\r\n        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],\r\n        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.InStreams.Size(); i++)\r\n  {\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);\r\n    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];\r\n  }\r\n  \r\n  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);\r\n    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)\r\n{\r\n  for (int i = 0; i < _coders.Size(); i++)\r\n    if (_coders[i].Result == code)\r\n      return code;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||\r\n      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())\r\n    return E_INVALIDARG;\r\n\r\n  Init(inStreams, outStreams);\r\n\r\n  int i;\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n    {\r\n      RINOK(_coders[i].Create());\r\n    }\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].Start();\r\n\r\n  _coders[_progressCoderIndex].Code(progress);\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].WaitFinish();\r\n\r\n  RINOK(ReturnIfError(E_ABORT));\r\n  RINOK(ReturnIfError(E_OUTOFMEMORY));\r\n  RINOK(ReturnIfError(S_FALSE));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK && result != E_FAIL)\r\n      return result;\r\n  }\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}  \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/CoderMixer2MT.h",
    "content": "// CoderMixer2MT.h\r\n\r\n#ifndef __CODER_MIXER2_MT_H\r\n#define __CODER_MIXER2_MT_H\r\n\r\n#include \"CoderMixer2.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../Common/StreamBinder.h\"\r\n#include \"../../Common/VirtThread.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CCoder2: public CCoderInfo2, public CVirtThread\r\n{\r\n  HRESULT Result;\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;\r\n  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;\r\n  CRecordVector<ISequentialInStream*> InStreamPointers;\r\n  CRecordVector<ISequentialOutStream*> OutStreamPointers;\r\n\r\n  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n  virtual void Execute();\r\n  void Code(ICompressProgressInfo *progress);\r\n};\r\n\r\n\r\n/*\r\n  SetBindInfo()\r\n  for each coder\r\n    AddCoder[2]()\r\n  SetProgressIndex(UInt32 coderIndex);\r\n \r\n  for each file\r\n  {\r\n    ReInit()\r\n    for each coder\r\n      SetCoderInfo  \r\n    Code\r\n  }\r\n*/\r\n\r\nclass CCoderMixer2MT:\r\n  public ICompressCoder2,\r\n  public CCoderMixer2,\r\n  public CMyUnknownImp\r\n{\r\n  CBindInfo _bindInfo;\r\n  CObjectVector<CStreamBinder> _streamBinders;\r\n  int _progressCoderIndex;\r\n\r\n  void AddCoderCommon();\r\n  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);\r\n  HRESULT ReturnIfError(HRESULT code);\r\npublic:\r\n  CObjectVector<CCoder2> _coders;\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n\r\n  HRESULT SetBindInfo(const CBindInfo &bindInfo);\r\n  void AddCoder(ICompressCoder *coder);\r\n  void AddCoder2(ICompressCoder2 *coder);\r\n  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }\r\n\r\n  void ReInit();\r\n  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)\r\n    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }\r\n  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const\r\n    {  return _streamBinders[binderIndex].ProcessedSize; }\r\n};\r\n\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/CrossThreadProgress.cpp",
    "content": "// CrossThreadProgress.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CrossThreadProgress.h\"\r\n\r\nSTDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  InSize = inSize;\r\n  OutSize = outSize;\r\n  ProgressEvent.Set();\r\n  WaitEvent.Lock();\r\n  return Result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/CrossThreadProgress.h",
    "content": "// CrossThreadProgress.h\r\n\r\n#ifndef __CROSSTHREADPROGRESS_H\r\n#define __CROSSTHREADPROGRESS_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CCrossThreadProgress: \r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  const UInt64 *InSize;\r\n  const UInt64 *OutSize;\r\n  HRESULT Result;\r\n  NWindows::NSynchronization::CAutoResetEvent ProgressEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent WaitEvent;\r\n\r\n  HRes Create()\r\n  {\r\n    RINOK(ProgressEvent.CreateIfNotCreated());\r\n    return WaitEvent.CreateIfNotCreated();\r\n  }\r\n  void Init()\r\n  {\r\n    ProgressEvent.Reset();\r\n    WaitEvent.Reset();\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/DummyOutStream.cpp",
    "content": "// DummyOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DummyOutStream.h\"\r\n\r\nSTDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/DummyOutStream.h",
    "content": "// DummyOutStream.h\r\n\r\n#ifndef __DUMMYOUTSTREAM_H\r\n#define __DUMMYOUTSTREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nclass CDummyOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }\r\n  void Init() { _size = 0; }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/HandlerOut.cpp",
    "content": "// HandlerOutCommon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"HandlerOut.h\"\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\n\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kLZMA2MethodName = L\"LZMA2\";\r\nstatic const wchar_t *kBZip2MethodName = L\"BZip2\";\r\nstatic const wchar_t *kPpmdMethodName = L\"PPMd\";\r\nstatic const wchar_t *kDeflateMethodName = L\"Deflate\";\r\nstatic const wchar_t *kDeflate64MethodName = L\"Deflate64\";\r\n\r\nstatic const wchar_t *kLzmaMatchFinderX1 = L\"HC4\";\r\nstatic const wchar_t *kLzmaMatchFinderX5 = L\"BT4\";\r\n\r\nstatic const UInt32 kLzmaAlgoX1 = 0;\r\nstatic const UInt32 kLzmaAlgoX5 = 1;\r\n\r\nstatic const UInt32 kLzmaDicSizeX1 = 1 << 16;\r\nstatic const UInt32 kLzmaDicSizeX3 = 1 << 20;\r\nstatic const UInt32 kLzmaDicSizeX5 = 1 << 24;\r\nstatic const UInt32 kLzmaDicSizeX7 = 1 << 25;\r\nstatic const UInt32 kLzmaDicSizeX9 = 1 << 26;\r\n\r\nstatic const UInt32 kLzmaFastBytesX1 = 32;\r\nstatic const UInt32 kLzmaFastBytesX7 = 64;\r\n\r\nstatic const UInt32 kPpmdMemSizeX1 = (1 << 22);\r\nstatic const UInt32 kPpmdMemSizeX5 = (1 << 24);\r\nstatic const UInt32 kPpmdMemSizeX7 = (1 << 26);\r\nstatic const UInt32 kPpmdMemSizeX9 = (192 << 20);\r\n\r\nstatic const UInt32 kPpmdOrderX1 = 4;\r\nstatic const UInt32 kPpmdOrderX5 = 6;\r\nstatic const UInt32 kPpmdOrderX7 = 16;\r\nstatic const UInt32 kPpmdOrderX9 = 32;\r\n\r\nstatic const UInt32 kDeflateAlgoX1 = 0;\r\nstatic const UInt32 kDeflateAlgoX5 = 1;\r\n\r\nstatic const UInt32 kDeflateFastBytesX1 = 32;\r\nstatic const UInt32 kDeflateFastBytesX7 = 64;\r\nstatic const UInt32 kDeflateFastBytesX9 = 128;\r\n\r\nstatic const UInt32 kDeflatePassesX1 = 1;\r\nstatic const UInt32 kDeflatePassesX7 = 3;\r\nstatic const UInt32 kDeflatePassesX9 = 10;\r\n\r\nstatic const UInt32 kBZip2NumPassesX1 = 1;\r\nstatic const UInt32 kBZip2NumPassesX7 = 2;\r\nstatic const UInt32 kBZip2NumPassesX9 = 7;\r\n\r\nstatic const UInt32 kBZip2DicSizeX1 = 100000;\r\nstatic const UInt32 kBZip2DicSizeX3 = 500000;\r\nstatic const UInt32 kBZip2DicSizeX5 = 900000;\r\n\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5;\r\n\r\nstatic bool AreEqual(const UString &methodName, const wchar_t *s)\r\n  { return (methodName.CompareNoCase(s) == 0); }\r\n\r\nstatic inline bool IsLZMAMethod(const UString &methodName)\r\n{ \r\n  return \r\n    AreEqual(methodName, kLZMAMethodName) || \r\n    AreEqual(methodName, kLZMA2MethodName); \r\n}\r\n\r\nstatic inline bool IsBZip2Method(const UString &methodName)\r\n  { return AreEqual(methodName, kBZip2MethodName); }\r\n\r\nstatic inline bool IsPpmdMethod(const UString &methodName)\r\n  { return AreEqual(methodName, kPpmdMethodName); }\r\n\r\nstatic inline bool IsDeflateMethod(const UString &methodName)\r\n{ \r\n  return \r\n    AreEqual(methodName, kDeflateMethodName) || \r\n    AreEqual(methodName, kDeflate64MethodName); \r\n}\r\n\r\nstruct CNameToPropID\r\n{\r\n  PROPID PropID;\r\n  VARTYPE VarType;\r\n  const wchar_t *Name;\r\n};\r\n\r\nCNameToPropID g_NameToPropID[] = \r\n{\r\n  { NCoderPropID::kOrder, VT_UI4, L\"O\" },\r\n  { NCoderPropID::kPosStateBits, VT_UI4, L\"PB\" },\r\n  { NCoderPropID::kLitContextBits, VT_UI4, L\"LC\" },\r\n  { NCoderPropID::kLitPosBits, VT_UI4, L\"LP\" },\r\n  { NCoderPropID::kEndMarker, VT_BOOL, L\"eos\" },\r\n\r\n  { NCoderPropID::kNumPasses, VT_UI4, L\"Pass\" },\r\n  { NCoderPropID::kNumFastBytes, VT_UI4, L\"fb\" },\r\n  { NCoderPropID::kMatchFinderCycles, VT_UI4, L\"mc\" },\r\n  { NCoderPropID::kAlgorithm, VT_UI4, L\"a\" },\r\n  { NCoderPropID::kMatchFinder, VT_BSTR, L\"mf\" },\r\n  { NCoderPropID::kNumThreads, VT_UI4, L\"mt\" }\r\n};\r\n\r\nstatic bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp)\r\n{\r\n  if (varType == srcProp.vt)\r\n  {\r\n    destProp = srcProp;\r\n    return true;\r\n  }\r\n  if (varType == VT_UI1)\r\n  {\r\n    if (srcProp.vt == VT_UI4)\r\n    {\r\n      UInt32 value = srcProp.ulVal;\r\n      if (value > 0xFF)\r\n        return false;\r\n      destProp = (Byte)value;\r\n      return true;\r\n    }\r\n  }\r\n  else if (varType == VT_BOOL)\r\n  {\r\n    bool res;\r\n    if (SetBoolProperty(res, srcProp) != S_OK)\r\n      return false;\r\n    destProp = res;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n    \r\nstatic int FindPropIdFromStringName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)\r\n    if (name.CompareNoCase(g_NameToPropID[i].Name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID, \r\n    const NWindows::NCOM::CPropVariant &value)\r\n{\r\n  for (int j = 0; j < oneMethodInfo.Properties.Size(); j++)\r\n    if (oneMethodInfo.Properties[j].Id == propID)\r\n      return;\r\n  CProp property;\r\n  property.Id = propID;\r\n  property.Value = value;\r\n  oneMethodInfo.Properties.Add(property);\r\n}\r\n\r\nvoid COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  if (oneMethodInfo.MethodName.IsEmpty())\r\n    oneMethodInfo.MethodName = kDefaultMethodName;\r\n  \r\n  if (IsLZMAMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 dicSize = \r\n      (level >= 9 ? kLzmaDicSizeX9 : \r\n      (level >= 7 ? kLzmaDicSizeX7 : \r\n      (level >= 5 ? kLzmaDicSizeX5 : \r\n      (level >= 3 ? kLzmaDicSizeX3 : \r\n                    kLzmaDicSizeX1)))); \r\n    \r\n    UInt32 algo = \r\n      (level >= 5 ? kLzmaAlgoX5 : \r\n                    kLzmaAlgoX1); \r\n    \r\n    UInt32 fastBytes = \r\n      (level >= 7 ? kLzmaFastBytesX7 : \r\n                    kLzmaFastBytesX1); \r\n    \r\n    const wchar_t *matchFinder = \r\n      (level >= 5 ? kLzmaMatchFinderX5 : \r\n                    kLzmaMatchFinderX1); \r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsDeflateMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 fastBytes = \r\n      (level >= 9 ? kDeflateFastBytesX9 : \r\n      (level >= 7 ? kDeflateFastBytesX7 : \r\n                    kDeflateFastBytesX1));\r\n    \r\n    UInt32 numPasses = \r\n      (level >= 9 ? kDeflatePassesX9 :  \r\n      (level >= 7 ? kDeflatePassesX7 : \r\n                    kDeflatePassesX1));\r\n    \r\n    UInt32 algo = \r\n      (level >= 5 ? kDeflateAlgoX5 : \r\n                    kDeflateAlgoX1); \r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n  }\r\n  else if (IsBZip2Method(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 numPasses = \r\n      (level >= 9 ? kBZip2NumPassesX9 : \r\n      (level >= 7 ? kBZip2NumPassesX7 :  \r\n                    kBZip2NumPassesX1));\r\n    \r\n    UInt32 dicSize = \r\n      (level >= 5 ? kBZip2DicSizeX5 : \r\n      (level >= 3 ? kBZip2DicSizeX3 : \r\n                    kBZip2DicSizeX1));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsPpmdMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 useMemSize = \r\n      (level >= 9 ? kPpmdMemSizeX9 : \r\n      (level >= 7 ? kPpmdMemSizeX7 : \r\n      (level >= 5 ? kPpmdMemSizeX5 : \r\n                    kPpmdMemSizeX1)));\r\n    \r\n    UInt32 order = \r\n      (level >= 9 ? kPpmdOrderX9 : \r\n      (level >= 7 ? kPpmdOrderX7 : \r\n      (level >= 5 ? kPpmdOrderX5 : \r\n                    kPpmdOrderX1)));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order);\r\n  }\r\n}\r\n\r\nstatic void SplitParams(const UString &srcString, UStringVector &subStrings)\r\n{\r\n  subStrings.Clear();\r\n  UString name;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L':')\r\n    {\r\n      subStrings.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  subStrings.Add(name);\r\n}\r\n\r\nstatic void SplitParam(const UString &param, UString &name, UString &value)\r\n{\r\n  int eqPos = param.Find(L'=');\r\n  if (eqPos >= 0)\r\n  {\r\n    name = param.Left(eqPos);\r\n    value = param.Mid(eqPos + 1);\r\n    return;\r\n  }\r\n  for(int i = 0; i < param.Length(); i++)\r\n  {\r\n    wchar_t c = param[i];\r\n    if (c >= L'0' && c <= L'9')\r\n    {\r\n      name = param.Left(i);\r\n      value = param.Mid(i);\r\n      return;\r\n    }\r\n  }\r\n  name = param;\r\n}\r\n\r\nHRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value)\r\n{\r\n  CProp property;\r\n  if (\r\n    name.CompareNoCase(L\"D\") == 0 || \r\n    name.CompareNoCase(L\"MEM\") == 0)\r\n  {\r\n    UInt32 dicSize;\r\n    RINOK(ParsePropDictionaryValue(value, dicSize));\r\n    if (name.CompareNoCase(L\"D\") == 0)\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n    else\r\n      property.Id = NCoderPropID::kUsedMemorySize;\r\n    property.Value = dicSize;\r\n    oneMethodInfo.Properties.Add(property);\r\n  }\r\n  else\r\n  {\r\n    int index = FindPropIdFromStringName(name);\r\n    if (index < 0)\r\n      return E_INVALIDARG;\r\n    \r\n    const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n    property.Id = nameToPropID.PropID;\r\n    \r\n    NCOM::CPropVariant propValue;\r\n    \r\n    if (nameToPropID.VarType == VT_BSTR)\r\n      propValue = value;\r\n    else if (nameToPropID.VarType == VT_BOOL)\r\n    {\r\n      bool res;\r\n      if (!StringToBool(value, res))\r\n        return E_INVALIDARG;\r\n      propValue = res;\r\n    }\r\n    else\r\n    {\r\n      UInt32 number;\r\n      if (ParseStringToUInt32(value, number) == value.Length())\r\n        propValue = number;\r\n      else\r\n        propValue = value;\r\n    }\r\n    \r\n    if (!ConvertProperty(propValue, nameToPropID.VarType, property.Value))\r\n      return E_INVALIDARG;\r\n    \r\n    oneMethodInfo.Properties.Add(property);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString)\r\n{\r\n  UStringVector params;\r\n  SplitParams(srcString, params);\r\n  if (params.Size() > 0)\r\n    oneMethodInfo.MethodName = params[0];\r\n  for (int i = 1; i < params.Size(); i++)\r\n  {\r\n    const UString &param = params[i];\r\n    UString name, value;\r\n    SplitParam(param, name, value);\r\n    RINOK(SetParam(oneMethodInfo, name, value));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const UString &s)\r\n{\r\n  bool res;\r\n  if (StringToBool(s, res))\r\n  {\r\n    if (res)\r\n      InitSolid();\r\n    else\r\n      _numSolidFiles = 1;\r\n    return S_OK;\r\n  }\r\n  UString s2 = s;\r\n  s2.MakeUpper();\r\n  for (int i = 0; i < s2.Length();)\r\n  {\r\n    const wchar_t *start = ((const wchar_t *)s2) + i;\r\n    const wchar_t *end;\r\n    UInt64 v = ConvertStringToUInt64(start, &end);\r\n    if (start == end)\r\n    {\r\n      if (s2[i++] != 'E')\r\n        return E_INVALIDARG;\r\n      _solidExtension = true;\r\n      continue;\r\n    }\r\n    i += (int)(end - start);\r\n    if (i == s2.Length())\r\n      return E_INVALIDARG;\r\n    wchar_t c = s2[i++];\r\n    switch(c)\r\n    {\r\n      case 'F':\r\n        if (v < 1)\r\n          v = 1;\r\n        _numSolidFiles = v;\r\n        break;\r\n      case 'B':\r\n        _numSolidBytes = v;\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'K':\r\n        _numSolidBytes = (v << 10);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'M':\r\n        _numSolidBytes = (v << 20);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'G':\r\n        _numSolidBytes = (v << 30);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      InitSolid();\r\n      return S_OK;\r\n    case VT_BSTR:\r\n      return SetSolidSettings(value.bstrVal);\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n}\r\n\r\nvoid COutHandler::Init()\r\n{\r\n  _removeSfxBlock = false;\r\n  _compressHeaders = true;\r\n  _encryptHeaders = false;\r\n  \r\n  WriteModified = true;\r\n  WriteCreated = false;\r\n  WriteAccessed = false;\r\n  \r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  \r\n  _level = 5;\r\n  _autoFilter = true;\r\n  _volumeMode = false;\r\n  _crcSize = 4;\r\n  InitSolid();\r\n}\r\n\r\nvoid COutHandler::BeforeSetProperty()\r\n{\r\n  Init();\r\n  #ifdef COMPRESS_MT\r\n  numProcessors = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n\r\n  mainDicSize = 0xFFFFFFFF;\r\n  mainDicMethodIndex = 0xFFFFFFFF;\r\n  minNumber = 0;\r\n  _crcSize = 4;\r\n}\r\n\r\nHRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)\r\n{\r\n  UString name = nameSpec;\r\n  name.MakeUpper();\r\n  if (name.IsEmpty())\r\n    return E_INVALIDARG;\r\n  \r\n  if (name[0] == 'X')\r\n  {\r\n    name.Delete(0);\r\n    _level = 9;\r\n    return ParsePropValue(name, value, _level);\r\n  }\r\n  \r\n  if (name[0] == L'S')\r\n  {\r\n    name.Delete(0);\r\n    if (name.IsEmpty())\r\n      return SetSolidSettings(value);\r\n    if (value.vt != VT_EMPTY)\r\n      return E_INVALIDARG;\r\n    return SetSolidSettings(name);\r\n  }\r\n  \r\n  if (name == L\"CRC\")\r\n  {\r\n    _crcSize = 4;\r\n    name.Delete(0, 3);\r\n    return ParsePropValue(name, value, _crcSize);\r\n  }\r\n  \r\n  UInt32 number;\r\n  int index = ParseStringToUInt32(name, number);\r\n  UString realName = name.Mid(index);\r\n  if (index == 0)\r\n  {\r\n    if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n    {\r\n      #ifdef COMPRESS_MT\r\n      RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n      #endif\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"RSFX\") == 0)\r\n      return SetBoolProperty(_removeSfxBlock, value);\r\n    if (name.CompareNoCase(L\"F\") == 0)\r\n      return SetBoolProperty(_autoFilter, value);\r\n    if (name.CompareNoCase(L\"HC\") == 0)\r\n      return SetBoolProperty(_compressHeaders, value);\r\n    if (name.CompareNoCase(L\"HCF\") == 0)\r\n    {\r\n      bool compressHeadersFull = true;\r\n      RINOK(SetBoolProperty(compressHeadersFull, value));\r\n      if (!compressHeadersFull)\r\n        return E_INVALIDARG;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"HE\") == 0)\r\n      return SetBoolProperty(_encryptHeaders, value);\r\n    if (name.CompareNoCase(L\"TM\") == 0)\r\n      return SetBoolProperty(WriteModified, value);\r\n    if (name.CompareNoCase(L\"TC\") == 0)\r\n      return SetBoolProperty(WriteCreated, value);\r\n    if (name.CompareNoCase(L\"TA\") == 0)\r\n      return SetBoolProperty(WriteAccessed, value);\r\n    if (name.CompareNoCase(L\"V\") == 0)\r\n      return SetBoolProperty(_volumeMode, value);\r\n    number = 0;\r\n  }\r\n  if (number > 10000)\r\n    return E_FAIL;\r\n  if (number < minNumber)\r\n    return E_INVALIDARG;\r\n  number -= minNumber;\r\n  for(int j = _methods.Size(); j <= (int)number; j++)\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    _methods.Add(oneMethodInfo);\r\n  }\r\n  \r\n  COneMethodInfo &oneMethodInfo = _methods[number];\r\n  \r\n  if (realName.Length() == 0)\r\n  {\r\n    if (value.vt != VT_BSTR)\r\n      return E_INVALIDARG;\r\n    \r\n    RINOK(SetParams(oneMethodInfo, value.bstrVal));\r\n  }\r\n  else\r\n  {\r\n    CProp property;\r\n    if (realName.Left(1).CompareNoCase(L\"D\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize));\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n      property.Value = dicSize;\r\n      oneMethodInfo.Properties.Add(property);\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else if (realName.Left(3).CompareNoCase(L\"MEM\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize));\r\n      property.Id = NCoderPropID::kUsedMemorySize;\r\n      property.Value = dicSize;\r\n      oneMethodInfo.Properties.Add(property);\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else\r\n    {\r\n      int index = FindPropIdFromStringName(realName);\r\n      if (index < 0)\r\n        return E_INVALIDARG;\r\n      \r\n      const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n      property.Id = nameToPropID.PropID;\r\n      \r\n      if (!ConvertProperty(value, nameToPropID.VarType, property.Value))\r\n        return E_INVALIDARG;\r\n      \r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n  }\r\n  return S_OK;\r\n}  \r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/HandlerOut.h",
    "content": "// HandlerOut.h\r\n\r\n#ifndef __HANDLER_OUT_H\r\n#define __HANDLER_OUT_H\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\n\r\nstruct COneMethodInfo\r\n{\r\n  CObjectVector<CProp> Properties;\r\n  UString MethodName;\r\n};\r\n\r\nclass COutHandler\r\n{\r\npublic:\r\n  HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);\r\n  \r\n  HRESULT SetSolidSettings(const UString &s);\r\n  HRESULT SetSolidSettings(const PROPVARIANT &value);\r\n\r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  CObjectVector<COneMethodInfo> _methods;\r\n  bool _removeSfxBlock;\r\n  \r\n  UInt64 _numSolidFiles; \r\n  UInt64 _numSolidBytes;\r\n  bool _numSolidBytesDefined;\r\n  bool _solidExtension;\r\n\r\n  bool _compressHeaders;\r\n  bool _encryptHeaders;\r\n\r\n  bool WriteModified;\r\n  bool WriteCreated;\r\n  bool WriteAccessed;\r\n\r\n  bool _autoFilter;\r\n  UInt32 _level;\r\n\r\n  bool _volumeMode;\r\n\r\n  HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value);\r\n  HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);\r\n\r\n  void SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }\r\n  void InitSolidSize()  { _numSolidBytes = (UInt64)(Int64)(-1); }\r\n  void InitSolid()\r\n  {\r\n    InitSolidFiles();\r\n    InitSolidSize();\r\n    _solidExtension = false;\r\n    _numSolidBytesDefined = false;\r\n  }\r\n\r\n  void Init();\r\n\r\n  COutHandler() { Init(); }\r\n\r\n  void BeforeSetProperty();\r\n\r\n  UInt32 minNumber;\r\n  UInt32 numProcessors;\r\n  UInt32 mainDicSize;\r\n  UInt32 mainDicMethodIndex;\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/InStreamWithCRC.cpp",
    "content": "// InStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _size += realProcessedSize;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if (seekOrigin != STREAM_SEEK_SET || offset != 0)\r\n    return E_FAIL;\r\n  _size = 0;\r\n  _crc = CRC_INIT_VAL;\r\n  return _stream->Seek(offset, seekOrigin, newPosition);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/InStreamWithCRC.h",
    "content": "// InStreamWithCRC.h\r\n\r\n#ifndef __INSTREAMWITHCRC_H\r\n#define __INSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass CSequentialInStreamWithCRC: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CInStreamWithCRC: \r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\nprivate:\r\n  CMyComPtr<IInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(IInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/ItemNameUtils.cpp",
    "content": "// Archive/Common/ItemNameUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\nstatic const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;\r\nstatic const wchar_t kDirDelimiter = L'/';\r\n\r\nUString MakeLegalName(const UString &name)\r\n{\r\n  UString zipName = name;\r\n  zipName.Replace(kOSDirDelimiter, kDirDelimiter);\r\n  return zipName;\r\n}\r\n\r\nUString GetOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(kDirDelimiter, kOSDirDelimiter);\r\n  return newName;\r\n}\r\n\r\nUString GetOSName2(const UString &name)\r\n{\r\n  if (name.IsEmpty())\r\n    return UString();\r\n  UString newName = GetOSName(name);\r\n  if (newName[newName.Length() - 1] == kOSDirDelimiter)\r\n    newName.Delete(newName.Length() - 1);\r\n  return newName;\r\n}\r\n\r\nbool HasTailSlash(const AString &name, UINT codePage)\r\n{\r\n  if (name.IsEmpty())\r\n    return false;\r\n  LPCSTR prev = \r\n  #ifdef _WIN32\r\n    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);\r\n  #else\r\n    (LPCSTR)(name) + (name.Length() - 1);\r\n  #endif\r\n  return (*prev == '/');\r\n}\r\n\r\n#ifndef _WIN32\r\nUString WinNameToOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(L'\\\\', kOSDirDelimiter);\r\n  return newName;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/ItemNameUtils.h",
    "content": "// Archive/Common/ItemNameUtils.h\r\n\r\n#ifndef __ARCHIVE_ITEMNAMEUTILS_H\r\n#define __ARCHIVE_ITEMNAMEUTILS_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\n  UString MakeLegalName(const UString &name);\r\n  UString GetOSName(const UString &name);\r\n  UString GetOSName2(const UString &name);\r\n  bool HasTailSlash(const AString &name, UINT codePage);\r\n\r\n  #ifdef _WIN32\r\n  inline UString WinNameToOSName(const UString &name)  { return name; }\r\n  #else\r\n  UString WinNameToOSName(const UString &name);\r\n  #endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/MultiStream.cpp",
    "content": "// MultiStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MultiStream.h\"\r\n\r\nSTDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(_streamIndex < Streams.Size() && size > 0)\r\n  {\r\n    CSubStreamInfo &s = Streams[_streamIndex];\r\n    if (_pos == s.Size)\r\n    {\r\n      _streamIndex++;\r\n      _pos = 0;\r\n      continue;\r\n    }\r\n    RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));\r\n    UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));\r\n    UInt32 realProcessed;\r\n    HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _pos += realProcessed;\r\n    _seekPos += realProcessed;\r\n    RINOK(result);\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 newPos;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      newPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      newPos = _seekPos + offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      newPos = _totalLength + offset;\r\n      break;\r\n    default:\r\n      return STG_E_INVALIDFUNCTION;\r\n  }\r\n  _seekPos = 0;\r\n  for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)\r\n  {\r\n    UInt64 size = Streams[_streamIndex].Size;\r\n    if (newPos < _seekPos + size)\r\n    {\r\n      _pos = newPos - _seekPos;\r\n      _seekPos += _pos;\r\n      if (newPosition != 0)\r\n        *newPosition = newPos;\r\n      return S_OK;\r\n    }\r\n    _seekPos += size;\r\n  }\r\n  if (newPos == _seekPos)\r\n  {\r\n    if (newPosition != 0)\r\n      *newPosition = newPos;\r\n    return S_OK;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\n\r\n/*\r\nclass COutVolumeStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback, \r\n      const UString &name)  \r\n  { \r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n*/\r\n\r\n/*\r\nSTDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));\r\n      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));\r\n      subStream.Pos = 0;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n    if (_offsetPos >= subStream.Size)\r\n    {\r\n      _offsetPos -= subStream.Size;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      CMyComPtr<IOutStream> outStream;\r\n      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == subStream.Size)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/MultiStream.h",
    "content": "// MultiStream.h\r\n\r\n#ifndef __MULTISTREAM_H\r\n#define __MULTISTREAM_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nclass CMultiStream: \r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex;\r\n  UInt64 _pos;\r\n  UInt64 _seekPos;\r\n  UInt64 _totalLength;\r\npublic:\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<IInStream> Stream;\r\n    UInt64 Pos;\r\n    UInt64 Size;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _pos = 0;\r\n    _seekPos = 0;\r\n    _totalLength = 0;\r\n    for (int i = 0; i < Streams.Size(); i++)\r\n      _totalLength += Streams[i].Size;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n\r\n/*\r\nclass COutMultiStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<ISequentialOutStream> Stream;\r\n    UInt64 Size;\r\n    UInt64 Pos;\r\n };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp",
    "content": "// OutStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  if (_calculate)\r\n    _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.h",
    "content": "// OutStreamWithCRC.h\r\n\r\n#ifndef __OUTSTREAMWITHCRC_H\r\n#define __OUTSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass COutStreamWithCRC: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _calculate;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(bool calculate = true)\r\n  {\r\n    _size = 0;\r\n    _calculate = calculate;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void InitCRC() { _crc = CRC_INIT_VAL; }\r\n  UInt64 GetSize() const { return _size; }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/ParseProperties.cpp",
    "content": "// ParseProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ParseProperties.h\"\r\n\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (prop.vt == VT_UI4)\r\n  {\r\n    if (!name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    resValue = prop.ulVal;\r\n  }\r\n  else if (prop.vt == VT_EMPTY)\r\n  {\r\n    if(!name.IsEmpty())\r\n    {\r\n      const wchar_t *start = name;\r\n      const wchar_t *end;\r\n      UInt64 v = ConvertStringToUInt64(start, &end);\r\n      if (end - start != name.Length())\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)v;\r\n    }\r\n  }\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kLogarithmicSizeLimit = 32;\r\nstatic const wchar_t kByteSymbol = L'B';\r\nstatic const wchar_t kKiloByteSymbol = L'K';\r\nstatic const wchar_t kMegaByteSymbol = L'M';\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)\r\n{\r\n  UString srcString = srcStringSpec;\r\n  srcString.MakeUpper();\r\n\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || srcString.Length() > numDigits + 1)\r\n    return E_INVALIDARG;\r\n  if (srcString.Length() == numDigits)\r\n  {\r\n    if (number >= kLogarithmicSizeLimit)\r\n      return E_INVALIDARG;\r\n    dicSize = (UInt32)1 << (int)number;\r\n    return S_OK;\r\n  }\r\n  switch (srcString[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      if (number >= ((UInt64)1 << kLogarithmicSizeLimit))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)number;\r\n      break;\r\n    case kKiloByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 10);\r\n      break;\r\n    case kMegaByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 20);\r\n      break;\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    if (prop.vt == VT_UI4)\r\n    {\r\n      UInt32 logDicSize = prop.ulVal;\r\n      if (logDicSize >= 32)\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)1 << logDicSize;\r\n      return S_OK;\r\n    }\r\n    if (prop.vt == VT_BSTR)\r\n      return ParsePropDictionaryValue(prop.bstrVal, resValue);\r\n    return E_INVALIDARG;\r\n  }\r\n  return ParsePropDictionaryValue(name, resValue);\r\n}\r\n\r\nbool StringToBool(const UString &s, bool &res)\r\n{\r\n  if (s.IsEmpty() || s.CompareNoCase(L\"ON\") == 0)\r\n  {\r\n    res = true;\r\n    return true;\r\n  }\r\n  if (s.CompareNoCase(L\"OFF\") == 0)\r\n  {\r\n    res = false;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      dest = true;\r\n      return S_OK;\r\n    /*\r\n    case VT_UI4:\r\n      dest = (value.ulVal != 0);\r\n      break;\r\n    */\r\n    case VT_BSTR:\r\n      return StringToBool(value.bstrVal, dest) ?  S_OK : E_INVALIDARG;\r\n  }\r\n  return E_INVALIDARG;\r\n}\r\n\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number)\r\n{\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number64 = ConvertStringToUInt64(start, &end);\r\n  if (number64 > 0xFFFFFFFF) \r\n  {\r\n    number = 0;\r\n    return 0;\r\n  }\r\n  number = (UInt32)number64;\r\n  return (int)(end - start);\r\n}\r\n\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    switch(prop.vt)\r\n    {\r\n      case VT_UI4:\r\n        numThreads = prop.ulVal;\r\n        break;\r\n      default:\r\n      {\r\n        bool val; \r\n        RINOK(SetBoolProperty(val, prop));\r\n        numThreads = (val ? defaultNumThreads : 1);\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index != name.Length())\r\n      return E_INVALIDARG;\r\n    numThreads = number;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/Common/ParseProperties.h",
    "content": "// ParseProperties.h\r\n\r\n#ifndef __PARSEPROPERTIES_H\r\n#define __PARSEPROPERTIES_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\n\r\nbool StringToBool(const UString &s, bool &res);\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number);\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/DllExports2.cpp",
    "content": "// DLLExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyInitGuid.h\"\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\nextern \"C\" \r\n{ \r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nHINSTANCE g_hInstance;\r\n#ifndef _UNICODE\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)\r\n{\r\n  if (dwReason == DLL_PROCESS_ATTACH)\r\n  {\r\n    g_hInstance = hInstance;\r\n    #ifndef _UNICODE\r\n    #ifdef _WIN32\r\n    g_IsNT = IsItWindowsNT();\r\n    #endif\r\n    #endif\r\n  }\r\n  return TRUE;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler, \r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec, \r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);\r\nSTDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);\r\n\r\nSTDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  // COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)\r\n  {\r\n    return CreateCoder(clsid, iid, outObject);\r\n  }\r\n  else\r\n  {\r\n    return CreateArchiver(clsid, iid, outObject);\r\n  }\r\n  // COM_TRY_END\r\n}\r\n\r\nSTDAPI SetLargePageMode()\r\n{\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  SetLargePageSize();\r\n  #endif\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Archive/IArchive.h",
    "content": "// IArchive.h\r\n\r\n#ifndef __IARCHIVE_H\r\n#define __IARCHIVE_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../IProgress.h\"\r\n#include \"../PropID.h\"\r\n\r\n#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)\r\n#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nnamespace NFileTimeType\r\n{\r\n  enum EEnum\r\n  {\r\n    kWindows,\r\n    kUnix,\r\n    kDOS\r\n  };\r\n}\r\n\r\nnamespace NArchive\r\n{\r\n  enum \r\n  {\r\n    kName = 0,\r\n    kClassID,\r\n    kExtension,\r\n    kAddExtension,\r\n    kUpdate,\r\n    kKeepName,\r\n    kStartSignature,\r\n    kFinishSignature,\r\n    kAssociate\r\n  };\r\n\r\n  namespace NExtract\r\n  {\r\n    namespace NAskMode\r\n    {\r\n      enum \r\n      {\r\n        kExtract = 0,\r\n        kTest,\r\n        kSkip\r\n      };\r\n    }\r\n    namespace NOperationResult\r\n    {\r\n      enum \r\n      {\r\n        kOK = 0,\r\n        kUnSupportedMethod,\r\n        kDataError,\r\n        kCRCError\r\n      };\r\n    }\r\n  }\r\n  namespace NUpdate\r\n  {\r\n    namespace NOperationResult\r\n    {\r\n      enum \r\n      {\r\n        kOK = 0,\r\n        kError\r\n      };\r\n    }\r\n  }\r\n}\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)\r\n{\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, \r\n      Int32 askExtractMode) PURE;\r\n  // GetStream OUT: S_OK - OK, S_FALSE - skeep this file\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)\r\n{\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;  \r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)\r\n{\r\n  STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;\r\n};\r\n\r\n\r\n/*\r\nIInArchive::Extract:\r\n  indices must be sorted \r\n  numItems = 0xFFFFFFFF means \"all files\"\r\n  testMode != 0 means \"test files without writing to outStream\"\r\n*/\r\n\r\n#define INTERFACE_IInArchive(x) \\\r\n  STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \\\r\n  STDMETHOD(Close)() x; \\\r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \\\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \\\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;\r\n\r\nARCHIVE_INTERFACE(IInArchive, 0x60)\r\n{\r\n  INTERFACE_IInArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)\r\n{\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index, \r\n      Int32 *newData, // 1 - new data, 0 - old data\r\n      Int32 *newProperties, // 1 - new properties, 0 - old properties\r\n      UInt32 *indexInArchive // -1 if there is no in archive, or if doesn't matter\r\n      ) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)\r\n{\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) PURE;\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) PURE;\r\n};\r\n\r\n\r\n#define INTERFACE_IOutArchive(x) \\\r\n  STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \\\r\n  STDMETHOD(GetFileTimeType)(UInt32 *type) x;\r\n\r\nARCHIVE_INTERFACE(IOutArchive, 0xA0)\r\n{\r\n  INTERFACE_IOutArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(ISetProperties, 0x03)\r\n{\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;\r\n};\r\n\r\n\r\n#define IMP_IInArchive_GetProp(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \\\r\n\r\n#define IMP_IInArchive_GetProp_WITH_NAME(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; \\\r\n    if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \\\r\n\r\n#define IMP_IInArchive_Props \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)\r\n\r\n#define IMP_IInArchive_Props_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)\r\n\r\n\r\n#define IMP_IInArchive_ArcProps \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_NO \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = 0; return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \\\r\n    { return E_NOTIMPL; } \\\r\n  STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \\\r\n    { value->vt = VT_EMPTY; return S_OK; } \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Alone7z/Alone.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Alone\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Alone - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\" CFG=\"Alone - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Alone - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Alone - Win32 Release\"\r\n# Name \"Alone - Win32 Debug\"\r\n# Name \"Alone - Win32 ReleaseU\"\r\n# Name \"Alone - Win32 DebugU\"\r\n# Begin Group \"Console\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ArError.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\CompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\Main.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\MainAr.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\AutoPtr.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Buffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ComTry.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\DynamicBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyException.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyGuidDef.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyInitGuid.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Device.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Handle.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MSBFDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MSBFEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterArc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterCodec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\Coder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86_2.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86_2.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Copy\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Copy\\CopyCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Copy\\CopyCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Copy\\CopyRegister.cpp\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZ\\LZOutWindow.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMADecoder.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMAEncoder.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMARegister.cpp\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderBit.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_Alone\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Archive\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"7z\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zExtract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"split\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"UI Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Property.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7-zip\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IMyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IPassword.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\PropID.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"C Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARM.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARM.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARMThumb.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARMThumb.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchIA64.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchIA64.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchPPC.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchPPC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchSPARC.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchSPARC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Alone7z/Alone.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Alone\"=.\\Alone.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Alone7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Alone7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Alone7z/makefile",
    "content": "PROG = 7za.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib Advapi32.lib\r\n\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -D_NO_CRYPTO \\\r\n  -DWIN_LONG_PATH \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OffsetStream.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\DummyOutStream.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\MultiStream.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n\r\n\r\nBRANCH_OPT_OBJS = \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\x86.obj \\\r\n  $O\\x86_2.obj \\\r\n  $O\\ARM.obj \\\r\n  $O\\ARMThumb.obj \\\r\n  $O\\IA64.obj \\\r\n  $O\\PPC.obj \\\r\n  $O\\SPARC.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\BCJRegister.obj \\\r\n  $O\\BCJ2Register.obj \\\r\n\r\nSWAP_OPT_OBJS = \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n\r\nCOPY_OBJS = \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n  $O\\LZMARegister.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Sort.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZ_OBJS = \\\r\n  $O\\MatchFinder.obj \\\r\n  $O\\MatchFinderMt.obj \\\r\n\r\nC_BRANCH_OBJS = \\\r\n  $O\\BranchARM.obj \\\r\n  $O\\BranchARMThumb.obj \\\r\n  $O\\BranchIA64.obj \\\r\n  $O\\BranchPPC.obj \\\r\n  $O\\BranchSPARC.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(BRANCH_OPT_OBJS) \\\r\n  $(SWAP_OPT_OBJS) \\\r\n  $(COPY_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZ_OBJS) \\\r\n  $(C_BRANCH_OBJS) \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): ../../UI/Console/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../../UI/Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Alone7z/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_APP(\"7-Zip Standalone Console\", \"7za\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Format7zExtractR/makefile",
    "content": "PROG = 7zxr.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DEXTRACT_ONLY \\\r\n  -DCOMPRESS_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n\r\nSWAP_OPT_OBJS = \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n\r\nBRANCH_OPT_OBJS = \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\x86.obj \\\r\n  $O\\x86_2.obj \\\r\n  $O\\ARM.obj \\\r\n  $O\\ARMThumb.obj \\\r\n  $O\\IA64.obj \\\r\n  $O\\PPC.obj \\\r\n  $O\\SPARC.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\BCJRegister.obj \\\r\n  $O\\BCJ2Register.obj \\\r\n\r\nCOPY_OBJS = \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMARegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_BRANCH_OBJS = \\\r\n  $O\\BranchARM.obj \\\r\n  $O\\BranchARMThumb.obj \\\r\n  $O\\BranchIA64.obj \\\r\n  $O\\BranchPPC.obj \\\r\n  $O\\BranchSPARC.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(BRANCH_OPT_OBJS) \\\r\n  $(SWAP_OPT_OBJS) \\\r\n  $(COPY_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_BRANCH_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Format7zExtractR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Extracting Plugin\", \"7zxr\")\r\n\r\n101  ICON  \"../../Archive/7z/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Format7zR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Format7zR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Format7zR/makefile",
    "content": "PROG = 7zra.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n\r\nBRANCH_OPT_OBJS = \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\x86.obj \\\r\n  $O\\x86_2.obj \\\r\n  $O\\ARM.obj \\\r\n  $O\\ARMThumb.obj \\\r\n  $O\\IA64.obj \\\r\n  $O\\PPC.obj \\\r\n  $O\\SPARC.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\BCJRegister.obj \\\r\n  $O\\BCJ2Register.obj \\\r\n\r\nSWAP_OPT_OBJS = \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n\r\nCOPY_OBJS = \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n  $O\\LZMARegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Sort.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZ_OBJS = \\\r\n  $O\\MatchFinder.obj \\\r\n  $O\\MatchFinderMt.obj \\\r\n\r\nC_BRANCH_OBJS = \\\r\n  $O\\BranchARM.obj \\\r\n  $O\\BranchARMThumb.obj \\\r\n  $O\\BranchIA64.obj \\\r\n  $O\\BranchPPC.obj \\\r\n  $O\\BranchSPARC.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(BZIP2_OBJS) \\\r\n  $(BZIP2_OPT_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(BRANCH_OPT_OBJS) \\\r\n  $(SWAP_OPT_OBJS) \\\r\n  $(COPY_OBJS) \\\r\n  $(DEFLATE_OPT_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(PPMD_OPT_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZ_OBJS) \\\r\n  $(C_BRANCH_OBJS) \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$O\\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Bundles/Format7zR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Plugin\", \"7zr\")\r\n\r\n101  ICON  \"../../Archive/7z/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/CreateCoder.cpp",
    "content": "// CreateCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CreateCoder.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Windows/Defs.h\"\r\n#include \"FilterCoder.h\"\r\n#include \"RegisterCodec.h\"\r\n\r\nstatic const unsigned int kNumCodecsMax = 64;\r\nunsigned int g_NumCodecs = 0;\r\nconst CCodecInfo *g_Codecs[kNumCodecsMax]; \r\nvoid RegisterCodec(const CCodecInfo *codecInfo) \r\n{ \r\n  if (g_NumCodecs < kNumCodecsMax)\r\n    g_Codecs[g_NumCodecs++] = codecInfo; \r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = 1;\r\n  else if (prop.vt == VT_UI4)\r\n    res = prop.ulVal;\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = true;\r\n  else if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs)\r\n{\r\n  UInt32 num;\r\n  RINOK(codecsInfo->GetNumberOfMethods(&num));\r\n  for (UInt32 i = 0; i < num; i++)\r\n  {\r\n    CCodecInfoEx info;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kID, &prop));\r\n    // if (prop.vt != VT_BSTR)\r\n    // info.Id.IDSize = (Byte)SysStringByteLen(prop.bstrVal);\r\n    // memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);\r\n    if (prop.vt != VT_UI8)\r\n    {\r\n      continue; // old Interface \r\n      // return E_INVALIDARG;\r\n    }\r\n    info.Id = prop.uhVal.QuadPart;\r\n    prop.Clear();\r\n    \r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      info.Name = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_INVALIDARG;;\r\n    \r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kInStreams, info.NumInStreams));\r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kOutStreams, info.NumOutStreams));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned));\r\n    \r\n    externalCodecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  const UString &name,\r\n  CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i]; \r\n    if (name.CompareNoCase(codec.Name) == 0)\r\n    {\r\n      methodId = codec.Id;\r\n      numInStreams = codec.NumInStreams;\r\n      numOutStreams = 1;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i]; \r\n      if (codec.Name.CompareNoCase(name) == 0)\r\n      {\r\n        methodId = codec.Id;\r\n        numInStreams = codec.NumInStreams;\r\n        numOutStreams = codec.NumOutStreams;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  CMethodId methodId, UString &name)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i]; \r\n    if (methodId == codec.Id)\r\n    {\r\n      name = codec.Name;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i]; \r\n      if (methodId == codec.Id)\r\n      {\r\n        name = codec.Name;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder)\r\n{\r\n  bool created = false;\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i]; \r\n    if (codec.Id == methodId)\r\n    {\r\n      if (encode)\r\n      {\r\n        if (codec.CreateEncoder)\r\n        {\r\n          void *p = codec.CreateEncoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n      }\r\n      else\r\n        if (codec.CreateDecoder)\r\n        {\r\n          void *p = codec.CreateDecoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  if (!created && externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i]; \r\n      if (codec.Id == methodId)\r\n      {\r\n        if (encode)\r\n        {\r\n          if (codec.EncoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE) \r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n        }\r\n        else\r\n          if (codec.DecoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE) \r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n      }\r\n    }\r\n  #endif\r\n\r\n  if (onlyCoder && filter)\r\n  {\r\n    CFilterCoder *coderSpec = new CFilterCoder;\r\n    coder = coderSpec;\r\n    coderSpec->Filter = filter;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, \r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, true);\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    coder, coder2, encode);\r\n}\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressCoder> coder;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, false);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/CreateCoder.h",
    "content": "// CreateCoder.h\r\n\r\n#ifndef __CREATECODER_H\r\n#define __CREATECODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nstruct CCodecInfoEx\r\n{\r\n  UString Name;\r\n  CMethodId Id;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }\r\n  CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}\r\n};\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)\r\n#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);\r\n#define IMPL_ISetCompressCodecsInfo2(x) \\\r\nSTDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \\\r\n  COM_TRY_BEGIN _codecsInfo = compressCodecsInfo;  return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }\r\n#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)\r\n\r\n#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs\r\n#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,\r\n#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,\r\n\r\n#else\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo\r\n#define DECL_ISetCompressCodecsInfo\r\n#define IMPL_ISetCompressCodecsInfo\r\n#define EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_VARS\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2\r\n#define EXTERNAL_CODECS_LOC_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS\r\n#define EXTERNAL_CODECS_LOC_VARS\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, UString &name);\r\n\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, \r\n  CMyComPtr<ICompressCoder> &coder, bool encode);\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/FilePathAutoRename.cpp",
    "content": "// FilePathAutoRename.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"FilePathAutoRename.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic bool MakeAutoName(const UString &name, \r\n    const UString &extension, int value, UString &path)\r\n{\r\n  wchar_t number[32];\r\n  ConvertUInt64ToString(value, number);\r\n  path = name;\r\n  path += number;\r\n  path += extension;\r\n  return NFile::NFind::DoesFileExist(path);\r\n}\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath)\r\n{\r\n  UString path;\r\n  int dotPos = fullProcessedPath.ReverseFind(L'.');\r\n\r\n  int slashPos = fullProcessedPath.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = fullProcessedPath.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n\r\n  UString name, extension;\r\n  if (dotPos > slashPos &&  dotPos > 0)\r\n  {\r\n    name = fullProcessedPath.Left(dotPos);\r\n    extension = fullProcessedPath.Mid(dotPos);\r\n  }\r\n  else\r\n    name = fullProcessedPath;\r\n  name += L'_';\r\n  int indexLeft = 1, indexRight = (1 << 30);\r\n  while (indexLeft != indexRight)\r\n  {\r\n    int indexMid = (indexLeft + indexRight) / 2;\r\n    if (MakeAutoName(name, extension, indexMid, path))\r\n      indexLeft = indexMid + 1;\r\n    else\r\n      indexRight = indexMid;\r\n  }\r\n  if (MakeAutoName(name, extension, indexRight, fullProcessedPath))\r\n    return false;\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/FilePathAutoRename.h",
    "content": "// Util/FilePathAutoRename.h\r\n\r\n#ifndef __FILEPATHAUTORENAME_H\r\n#define __FILEPATHAUTORENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  #ifdef _WIN32\r\n  if (result)\r\n    return S_OK;\r\n  DWORD lastError = ::GetLastError();\r\n  if (lastError == 0)\r\n    return E_FAIL;\r\n  return lastError;\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nbool CInFileStream::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), \r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nHRESULT COutFileStream::Close()\r\n{\r\n  return ConvertBoolToHRESULT(File.Close());\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  ProcessedSize += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  ProcessedSize += res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15); \r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), \r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WIN_FILE\r\n#endif\r\n\r\n#ifdef USE_WIN_FILE\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\npublic:\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #endif\r\n  #endif\r\n\r\n  HRESULT Close();\r\n  \r\n  UInt64 ProcessedSize;\r\n\r\n  #ifdef USE_WIN_FILE\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  {\r\n    return File.SetTime(creationTime, lastAccessTime, lastWriteTime);\r\n  }\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {\r\n    return File.SetLastWriteTime(lastWriteTime);\r\n  }\r\n  #endif\r\n\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/FilterCoder.cpp",
    "content": "// FilterCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FilterCoder.h\"\r\nextern \"C\" \r\n{ \r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#include \"../../Common/Defs.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCFilterCoder::CFilterCoder()\r\n{ \r\n  _buffer = (Byte *)::MidAlloc(kBufferSize); \r\n}\r\n\r\nCFilterCoder::~CFilterCoder() \r\n{ \r\n  ::MidFree(_buffer); \r\n}\r\n\r\nHRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)\r\n{\r\n  if (_outSizeIsDefined)\r\n  {\r\n    UInt64 remSize = _outSize - _nowPos64;\r\n    if (size > remSize)\r\n      size = (UInt32)remSize;\r\n  }\r\n  UInt32 processedSize = 0;\r\n  RINOK(WriteStream(outStream, _buffer, size, &processedSize));\r\n  if (size != processedSize)\r\n    return E_FAIL;\r\n  _nowPos64 += processedSize;\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  RINOK(Init());\r\n  UInt32 bufferPos = 0;\r\n  _outSizeIsDefined = (outSize != 0);\r\n  if (_outSizeIsDefined)\r\n    _outSize = *outSize;\r\n\r\n  while(NeedMore())\r\n  {\r\n    UInt32 processedSize;\r\n    \r\n    // Change it: It can be optimized using ReadPart\r\n    RINOK(ReadStream(inStream, _buffer + bufferPos, kBufferSize - bufferPos, &processedSize));\r\n    \r\n    UInt32 endPos = bufferPos + processedSize;\r\n\r\n    bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (bufferPos > endPos)\r\n    {\r\n      for (; endPos< bufferPos; endPos++)\r\n        _buffer[endPos] = 0;\r\n      bufferPos = Filter->Filter(_buffer, endPos);\r\n    }\r\n\r\n    if (bufferPos == 0)\r\n    {\r\n      if (endPos > 0)\r\n        return WriteWithLimit(outStream, endPos);\r\n      return S_OK;\r\n    }\r\n    RINOK(WriteWithLimit(outStream, bufferPos));\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));\r\n    }\r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n// #ifdef _ST_MODE\r\nSTDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _bufferPos = 0;\r\n  _outStream = outStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseOutStream()\r\n{\r\n  _outStream.Release();\r\n  return S_OK;\r\n};\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    UInt32 sizeMax = kBufferSize - _bufferPos;\r\n    UInt32 sizeTemp = size;\r\n    if (sizeTemp > sizeMax)\r\n      sizeTemp = sizeMax;\r\n    memmove(_buffer + _bufferPos, data, sizeTemp);\r\n    size -= sizeTemp;\r\n    processedSizeTotal += sizeTemp;\r\n    data = (const Byte *)data + sizeTemp;\r\n    UInt32 endPos = _bufferPos + sizeTemp;\r\n    _bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (_bufferPos == 0)\r\n    {\r\n      _bufferPos = endPos;\r\n      break;\r\n    }\r\n    if (_bufferPos > endPos)\r\n    {\r\n      if (size != 0)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    RINOK(WriteWithLimit(_outStream, _bufferPos));\r\n    UInt32 i = 0;\r\n    while(_bufferPos < endPos)\r\n      _buffer[i++] = _buffer[_bufferPos++];\r\n    _bufferPos = i;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::Flush()\r\n{\r\n  if (_bufferPos != 0)\r\n  {\r\n    UInt32 endPos = Filter->Filter(_buffer, _bufferPos);\r\n    if (endPos > _bufferPos)\r\n    {\r\n      for (; _bufferPos < endPos; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      if (Filter->Filter(_buffer, endPos) != endPos)\r\n        return E_FAIL;\r\n    }\r\n    UInt32 processedSize;\r\n    RINOK(WriteStream(_outStream, _buffer, _bufferPos, &processedSize));\r\n    if (_bufferPos != processedSize)\r\n      return E_FAIL;\r\n    _bufferPos = 0;\r\n  }\r\n  CMyComPtr<IOutStreamFlush> flush;\r\n  _outStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n  if (flush)\r\n    return  flush->Flush();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _convertedPosBegin = _convertedPosEnd = _bufferPos = 0;\r\n  _inStream = inStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseInStream()\r\n{\r\n  _inStream.Release();\r\n  return S_OK;\r\n};\r\n\r\nSTDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_convertedPosBegin != _convertedPosEnd)\r\n    {\r\n      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);\r\n      memmove(data, _buffer + _convertedPosBegin, sizeTemp);\r\n      _convertedPosBegin += sizeTemp;\r\n      data = (void *)((Byte *)data + sizeTemp);\r\n      size -= sizeTemp;\r\n      processedSizeTotal += sizeTemp;\r\n      break;\r\n    }\r\n    int i;\r\n    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)\r\n      _buffer[i] = _buffer[i + _convertedPosEnd];\r\n    _bufferPos = i;\r\n    _convertedPosBegin = _convertedPosEnd = 0;\r\n    UInt32 processedSizeTemp;\r\n    UInt32 size0 = kBufferSize - _bufferPos;\r\n    // Optimize it:\r\n    RINOK(ReadStream(_inStream, _buffer + _bufferPos, size0, &processedSizeTemp));\r\n    _bufferPos = _bufferPos + processedSizeTemp;\r\n    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    if (_convertedPosEnd == 0)\r\n    {\r\n      if (_bufferPos == 0)\r\n        break;\r\n      else\r\n      {\r\n        _convertedPosEnd = _bufferPos; // check it\r\n        continue;\r\n      }\r\n    }\r\n    if (_convertedPosEnd > _bufferPos)\r\n    {\r\n      for (; _bufferPos < _convertedPosEnd; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\n// #endif // _ST_MODE\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)\r\n{\r\n  return _setPassword->CryptoSetPassword(data, size);\r\n}\r\n#endif\r\n\r\n#ifndef EXTRACT_ONLY\r\nSTDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  return _writeCoderProperties->WriteCoderProperties(outStream);\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CFilterCoder::ResetSalt()\r\n{\r\n  return _CryptoResetSalt->ResetSalt();\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CFilterCoder::ResetInitVector()\r\n{\r\n  return _CryptoResetInitVector->ResetInitVector();\r\n}\r\n#endif\r\n\r\nSTDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)\r\n{\r\n  return _setDecoderProperties->SetDecoderProperties2(data, size);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/FilterCoder.h",
    "content": "// FilterCoder.h\r\n\r\n#ifndef __FILTERCODER_H\r\n#define __FILTERCODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \\\r\n{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \\\r\n*outObject = (void *)(i *)this; AddRef(); return S_OK; } \r\n\r\nclass CFilterCoder:\r\n  public ICompressCoder,\r\n  // #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ISequentialInStream,\r\n  public ICompressSetOutStream,\r\n  public ISequentialOutStream,\r\n  public IOutStreamFlush,\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoSetPassword,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  // public ICryptoResetSalt,\r\n  public ICryptoResetInitVector,\r\n  #endif\r\n  public ICompressSetDecoderProperties2,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  // #ifdef _ST_MODE\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  CMyComPtr<ISequentialOutStream> _outStream;\r\n  UInt32 _bufferPos;\r\n  UInt32 _convertedPosBegin;\r\n  UInt32 _convertedPosEnd;\r\n  // #endif\r\n  bool _outSizeIsDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _nowPos64;\r\n\r\n  HRESULT Init() \r\n  { \r\n    _nowPos64 = 0;\r\n    _outSizeIsDefined = false;\r\n    return Filter->Init(); \r\n  }\r\n\r\n  CMyComPtr<ICryptoSetPassword> _setPassword;\r\n  #ifndef EXTRACT_ONLY\r\n  CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;\r\n  CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;\r\n  // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;\r\n  CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;\r\n  #endif\r\n  CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;\r\npublic:\r\n  CMyComPtr<ICompressFilter> Filter;\r\n\r\n  CFilterCoder();\r\n  ~CFilterCoder();\r\n  HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);\r\n  bool NeedMore() const  \r\n    { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }\r\n\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n    MY_QUERYINTERFACE_ENTRY(ICompressCoder)\r\n    // #ifdef _ST_MODE\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialInStream)\r\n\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)\r\n    // #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)\r\n    #endif\r\n\r\n    #ifndef EXTRACT_ONLY\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)\r\n    // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)\r\n    #endif\r\n\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  // #ifdef _ST_MODE\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \\\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Flush)();\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  // STDMETHOD(ResetSalt)();\r\n  STDMETHOD(ResetInitVector)();\r\n  #endif\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n};\r\n\r\n// #ifdef _ST_MODE\r\nclass CInStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  CInStreamReleaser(): FilterCoder(0) {}\r\n  ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }\r\n};\r\n\r\nclass COutStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  COutStreamReleaser(): FilterCoder(0) {}\r\n  ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }\r\n};\r\n// #endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nCInBuffer::CInBuffer(): \r\n  _buffer(0), \r\n  _bufferLimit(0), \r\n  _bufferBase(0), \r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct CInBufferException: public CSystemException \r\n{\r\n  CInBufferException(HRESULT errorCode): CSystemException(errorCode) {} \r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      if(!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)\r\n  {\r\n    for(processedSize = 0; processedSize < size; processedSize++)\r\n      if (!ReadByte(((Byte *)data)[processedSize]))\r\n        return;\r\n  }\r\n  bool ReadBytes(void *data, UInt32 size)\r\n  {\r\n    UInt32 processedSize;\r\n    ReadBytes(data, size, processedSize);\r\n    return (processedSize == size);\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/InOutTempBuffer.cpp",
    "content": "// InOutTempBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InOutTempBuffer.h\"\r\n#include \"../../Common/Defs.h\"\r\n// #include \"Windows/Defs.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic UInt32 kTmpBufferMemorySize = (1 << 20);\r\n\r\nstatic LPCTSTR kTempFilePrefixString = TEXT(\"iot\");\r\n\r\nCInOutTempBuffer::CInOutTempBuffer():\r\n  _buffer(NULL)\r\n{\r\n}\r\n\r\nvoid CInOutTempBuffer::Create()\r\n{\r\n  _buffer = new Byte[kTmpBufferMemorySize];\r\n}\r\n\r\nCInOutTempBuffer::~CInOutTempBuffer()\r\n{\r\n  delete []_buffer;\r\n}\r\nvoid CInOutTempBuffer::InitWriting()\r\n{\r\n  _bufferPosition = 0;\r\n  _tmpFileCreated = false;\r\n  _fileSize = 0;\r\n}\r\n\r\nbool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)\r\n{\r\n  if (size == 0)\r\n    return true;\r\n  if(!_tmpFileCreated)\r\n  {\r\n    CSysString tempDirPath;\r\n    if(!MyGetTempPath(tempDirPath))\r\n      return false;\r\n    if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)\r\n      return false;\r\n    // _outFile.SetOpenCreationDispositionCreateAlways();\r\n    if(!_outFile.Create(_tmpFileName, true))\r\n      return false;\r\n    _tmpFileCreated = true;\r\n  }\r\n  UInt32 processedSize;\r\n  if(!_outFile.Write(data, size, processedSize))\r\n    return false;\r\n  _fileSize += processedSize;\r\n  return (processedSize == size);\r\n}\r\n\r\nbool CInOutTempBuffer::FlushWrite()\r\n{\r\n  return _outFile.Close();\r\n}\r\n\r\nbool CInOutTempBuffer::Write(const void *data, UInt32 size)\r\n{\r\n  if(_bufferPosition < kTmpBufferMemorySize)\r\n  {\r\n    UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);\r\n    memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);\r\n    _bufferPosition += curSize;\r\n    size -= curSize;\r\n    data = ((const Byte *)data) + curSize;\r\n    _fileSize += curSize;\r\n  }\r\n  return WriteToFile(data, size);\r\n}\r\n\r\nbool CInOutTempBuffer::InitReading()\r\n{\r\n  _currentPositionInBuffer = 0;\r\n  if(_tmpFileCreated)\r\n    return _inFile.Open(_tmpFileName);\r\n  return true;\r\n}\r\n\r\nHRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)\r\n{\r\n  if (_currentPositionInBuffer < _bufferPosition)\r\n  {\r\n    UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;\r\n    RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite, NULL));\r\n    _currentPositionInBuffer += sizeToWrite;\r\n  }\r\n  if (!_tmpFileCreated)\r\n    return true;\r\n  for (;;)\r\n  {\r\n    UInt32 localProcessedSize;\r\n    if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))\r\n      return E_FAIL;\r\n    if (localProcessedSize == 0)\r\n      return S_OK;\r\n    RINOK(WriteStream(stream, _buffer, localProcessedSize, NULL));\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (!_buffer->Write(data, size))\r\n  {\r\n    if (processedSize != NULL)\r\n      *processedSize = 0;\r\n    return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/InOutTempBuffer.h",
    "content": "// Util/InOutTempBuffer.h\r\n\r\n#ifndef __IN_OUT_TEMP_BUFFER_H\r\n#define __IN_OUT_TEMP_BUFFER_H\r\n\r\n#include \"../../Windows/FileIO.h\"\r\n#include \"../../Windows/FileDir.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../IStream.h\"\r\n\r\nclass CInOutTempBuffer\r\n{\r\n  NWindows::NFile::NDirectory::CTempFile _tempFile;\r\n  NWindows::NFile::NIO::COutFile _outFile;\r\n  NWindows::NFile::NIO::CInFile _inFile;\r\n  Byte *_buffer;\r\n  UInt32 _bufferPosition;\r\n  UInt32 _currentPositionInBuffer;\r\n  CSysString _tmpFileName;\r\n  bool _tmpFileCreated;\r\n\r\n  UInt64 _fileSize;\r\n\r\n  bool WriteToFile(const void *data, UInt32 size);\r\npublic:\r\n  CInOutTempBuffer();\r\n  ~CInOutTempBuffer();\r\n  void Create();\r\n\r\n  void InitWriting();\r\n  bool Write(const void *data, UInt32 size);\r\n  UInt64 GetDataSize() const { return _fileSize; }\r\n  bool FlushWrite();\r\n  bool InitReading();\r\n  HRESULT WriteToStream(ISequentialOutStream *stream);\r\n};\r\n\r\nclass CSequentialOutTempBufferImp: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CInOutTempBuffer *_buffer;\r\npublic:\r\n  // CSequentialOutStreamImp(): _size(0) {}\r\n  // UInt32 _size;\r\n  void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }\r\n  // UInt32 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/LimitedStreams.cpp",
    "content": "// LimitedStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LimitedStreams.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\nSTDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size);\r\n  HRESULT result = S_OK;\r\n  if (sizeToRead > 0)\r\n  {\r\n    result = _stream->Read(data, sizeToRead, &realProcessedSize);\r\n    _pos += realProcessedSize;\r\n    if (realProcessedSize == 0)\r\n      _wasFinished = true;\r\n  }\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/LimitedStreams.h",
    "content": "// LimitedStreams.h\r\n\r\n#ifndef __LIMITEDSTREAMS_H\r\n#define __LIMITEDSTREAMS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLimitedSequentialInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt64 _pos;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream; }\r\n  void Init(UInt64 streamSize)  \r\n  { \r\n    _size = streamSize; \r\n    _pos = 0; \r\n    _wasFinished = false; \r\n  }\r\n \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _pos; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/LockedStream.cpp",
    "content": "// LockedStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LockedStream.h\"\r\n\r\nHRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size, \r\n  UInt32 *processedSize)\r\n{\r\n  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);\r\n  RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));\r\n  return _stream->Read(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);\r\n  _pos += realProcessedSize;\r\n  if (processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/LockedStream.h",
    "content": "// LockedStream.h\r\n\r\n#ifndef __LOCKEDSTREAM_H\r\n#define __LOCKEDSTREAM_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLockedInStream\r\n{\r\n  CMyComPtr<IInStream> _stream;\r\n  NWindows::NSynchronization::CCriticalSection _criticalSection;\r\npublic:\r\n  void Init(IInStream *stream)\r\n    { _stream = stream; }\r\n  HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CLockedSequentialInStreamImp: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CLockedInStream *_lockedInStream;\r\n  UInt64 _pos;\r\npublic:\r\n  void Init(CLockedInStream *lockedInStream, UInt64 startPos)\r\n  {\r\n    _lockedInStream = lockedInStream;\r\n    _pos = startPos;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/MethodId.cpp",
    "content": "// MethodId.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodId.h\"\r\n#include \"../../Common/MyString.h\"\r\n\r\nstatic inline wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nUString ConvertMethodIdToString(UInt64 id)\r\n{\r\n  wchar_t s[32];\r\n  int len = 32;\r\n  s[--len] = 0;\r\n  do\r\n  {\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n  }\r\n  while (id != 0);\r\n  return s + len;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/MethodId.h",
    "content": "// MethodId.h\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Common/Types.h\"\r\n\r\ntypedef UInt64 CMethodId;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/MethodProps.cpp",
    "content": "// MethodProps.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodProps.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nstatic UInt64 k_LZMA = 0x030101;\r\n// static UInt64 k_LZMA2 = 0x030102;\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)\r\n{\r\n  bool tryReduce = false;\r\n  UInt32 reducedDictionarySize = 1 << 10;\r\n  if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))\r\n  {\r\n    for (;;)\r\n    {\r\n      const UInt32 step = (reducedDictionarySize >> 1);\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      reducedDictionarySize += step;\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      if (reducedDictionarySize >= ((UInt32)3 << 30))\r\n        break;\r\n      reducedDictionarySize += step;\r\n    }\r\n  }\r\n\r\n  {\r\n    int numProperties = method.Properties.Size();\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n    if (setCoderProperties == NULL)\r\n    {\r\n      if (numProperties != 0)\r\n        return E_INVALIDARG;\r\n    }\r\n    else\r\n    {\r\n      CRecordVector<PROPID> propIDs;\r\n      NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties];\r\n      HRESULT res = S_OK;\r\n      try\r\n      {\r\n        for (int i = 0; i < numProperties; i++)\r\n        {\r\n          const CProp &prop = method.Properties[i];\r\n          propIDs.Add(prop.Id);\r\n          NWindows::NCOM::CPropVariant &value = values[i];\r\n          value = prop.Value;\r\n          // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)\r\n          if (tryReduce)\r\n            if (prop.Id == NCoderPropID::kDictionarySize)\r\n              if (value.vt == VT_UI4)\r\n                if (reducedDictionarySize < value.ulVal)\r\n            value.ulVal = reducedDictionarySize;\r\n        }\r\n        CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n        coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n        res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties);\r\n      }\r\n      catch(...)\r\n      {\r\n        delete []values;\r\n        throw;\r\n      }\r\n      delete []values;\r\n      RINOK(res);\r\n    }\r\n  }\r\n \r\n  /*\r\n  CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n  coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n  if (writeCoderProperties != NULL)\r\n  {\r\n    CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n    outStreamSpec->Init();\r\n    RINOK(writeCoderProperties->WriteCoderProperties(outStream));\r\n    size_t size = outStreamSpec->GetSize();\r\n    filterProps.SetCapacity(size);\r\n    memmove(filterProps, outStreamSpec->GetBuffer(), size);\r\n  }\r\n  */\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/MethodProps.h",
    "content": "// MethodProps.h\r\n\r\n#ifndef __7Z_METHOD_PROPS_H\r\n#define __7Z_METHOD_PROPS_H\r\n\r\n#include \"MethodId.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Common/MyVector.h\"\r\n#include \"../ICoder.h\"\r\n\r\nstruct CProp\r\n{\r\n  PROPID Id;\r\n  NWindows::NCOM::CPropVariant Value;\r\n};\r\n\r\nstruct CMethod\r\n{\r\n  CMethodId Id;\r\n  CObjectVector<CProp> Properties;\r\n};\r\n\r\nstruct CMethodsMode\r\n{\r\n  CObjectVector<CMethod> Methods;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n\r\n  CMethodsMode()\r\n      #ifdef COMPRESS_MT\r\n      : NumThreads(1) \r\n      #endif\r\n  {}\r\n  bool IsEmpty() const { return Methods.IsEmpty() ; }\r\n};\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/OffsetStream.cpp",
    "content": "// OffsetStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"OffsetStream.h\"\r\n\r\nHRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)\r\n{\r\n  _offset = offset;\r\n  _stream = stream;\r\n  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return _stream->Write(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 absoluteNewPosition;\r\n  if (seekOrigin == STREAM_SEEK_SET)\r\n    offset += _offset;\r\n  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);\r\n  if (newPosition != NULL)\r\n    *newPosition = absoluteNewPosition - _offset;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)\r\n{\r\n  return _stream->SetSize(_offset + newSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/OffsetStream.h",
    "content": "// OffsetStream.h\r\n\r\n#ifndef __OFFSETSTREAM_H\r\n#define __OFFSETSTREAM_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass COffsetOutStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 _offset;\r\n  CMyComPtr<IOutStream> _stream;\r\npublic:\r\n  HRESULT Init(IOutStream *stream, UInt64 offset);\r\n  \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{ \r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos) \r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode == S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = Flush();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException: public CSystemException \r\n{ \r\n  COutBufferException(HRESULT errorCode): CSystemException(errorCode) {} \r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void FlushWithCheck();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/ProgressUtils.cpp",
    "content": "// ProgressUtils.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ProgressUtils.h\"\r\n\r\nCLocalProgress::CLocalProgress()\r\n{\r\n  ProgressOffset = InSize = OutSize = 0;\r\n  SendRatio = SendProgress = true;\r\n}\r\n\r\nvoid CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)\r\n{\r\n  _ratioProgress.Release();\r\n  _progress = progress;\r\n  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);\r\n  _inSizeIsMain = inSizeIsMain;\r\n}\r\n\r\nSTDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  UInt64 inSizeNew = InSize, outSizeNew = OutSize;\r\n  if (inSize)\r\n    inSizeNew += (*inSize);\r\n  if (outSize)\r\n    outSizeNew += (*outSize);\r\n  if (SendRatio && _ratioProgress)\r\n  {\r\n    RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));\r\n  }\r\n  inSizeNew += ProgressOffset;\r\n  outSizeNew += ProgressOffset;\r\n  if (SendProgress)\r\n    return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CLocalProgress::SetCur()\r\n{\r\n  return SetRatioInfo(NULL, NULL);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/ProgressUtils.h",
    "content": "// ProgressUtils.h\r\n\r\n#ifndef __PROGRESSUTILS_H\r\n#define __PROGRESSUTILS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n#include \"../IProgress.h\"\r\n\r\nclass CLocalProgress: \r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<IProgress> _progress;\r\n  CMyComPtr<ICompressProgressInfo> _ratioProgress;\r\n  bool _inSizeIsMain;\r\npublic:\r\n  UInt64 ProgressOffset;\r\n  UInt64 InSize;\r\n  UInt64 OutSize;\r\n  bool SendRatio;\r\n  bool SendProgress;\r\n\r\n  CLocalProgress();\r\n  void Init(IProgress *progress, bool inSizeIsMain);\r\n  HRESULT SetCur();\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/RegisterArc.h",
    "content": "// RegisterArc.h\r\n\r\n#ifndef __REGISTERARC_H\r\n#define __REGISTERARC_H\r\n\r\n#include \"../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcInfo\r\n{\r\n  const wchar_t *Name;\r\n  const wchar_t *Ext;\r\n  const wchar_t *AddExt;\r\n  Byte ClassId;\r\n  Byte Signature[16];\r\n  int SignatureSize;\r\n  bool KeepName;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n};\r\n\r\nvoid RegisterArc(const CArcInfo *arcInfo);\r\n\r\n#define REGISTER_ARC_NAME(x) CRegister ## x \r\n\r\n#define REGISTER_ARC_DEC_SIG(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { g_ArcInfo.Signature[0]--; RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#define REGISTER_ARC(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/RegisterCodec.h",
    "content": "// RegisterCodec.h\r\n\r\n#ifndef __REGISTERCODEC_H\r\n#define __REGISTERCODEC_H\r\n\r\n#include \"../Common/MethodId.h\"\r\n\r\ntypedef void * (*CreateCodecP)();\r\nstruct CCodecInfo\r\n{\r\n  CreateCodecP CreateDecoder;\r\n  CreateCodecP CreateEncoder;\r\n  CMethodId Id;\r\n  const wchar_t *Name;\r\n  UInt32 NumInStreams;\r\n  bool IsFilter;\r\n};\r\n\r\nvoid RegisterCodec(const CCodecInfo *codecInfo);\r\n\r\n#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x \r\n\r\n#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \\\r\n    REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \\\r\n    static REGISTER_CODEC_NAME(x) g_RegisterCodec;\r\n\r\n#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x \r\n#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \\\r\n    REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \\\r\n    RegisterCodec(&g_CodecsInfo[i]); }}; \\\r\n    static REGISTER_CODECS_NAME(x) g_RegisterCodecs;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/StreamBinder.cpp",
    "content": "// StreamBinder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamBinder.h\"\r\n#include \"../../Common/Defs.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NSynchronization;\r\n\r\nclass CSequentialInStreamForBinder: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Read(data, size, processedSize); }\r\n\r\nclass CSequentialOutStreamForBinder: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialOutStreamForBinder() {  m_StreamBinder->CloseWrite(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Write(data, size, processedSize); }\r\n\r\n\r\n//////////////////////////\r\n// CStreamBinder\r\n// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.\r\n\r\nHRes CStreamBinder::CreateEvents()\r\n{\r\n  RINOK(_allBytesAreWritenEvent.Create(true));\r\n  RINOK(_thereAreBytesToReadEvent.Create());\r\n  return _readStreamIsClosedEvent.Create();\r\n}\r\n\r\nvoid CStreamBinder::ReInit()\r\n{\r\n  _thereAreBytesToReadEvent.Reset();\r\n  _readStreamIsClosedEvent.Reset();\r\n  ProcessedSize = 0;\r\n}\r\n\r\n\r\n  \r\nvoid CStreamBinder::CreateStreams(ISequentialInStream **inStream, \r\n      ISequentialOutStream **outStream)\r\n{\r\n  CSequentialInStreamForBinder *inStreamSpec = new \r\n      CSequentialInStreamForBinder;\r\n  CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n  inStreamSpec->SetBinder(this);\r\n  *inStream = inStreamLoc.Detach();\r\n\r\n  CSequentialOutStreamForBinder *outStreamSpec = new \r\n      CSequentialOutStreamForBinder;\r\n  CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);\r\n  outStreamSpec->SetBinder(this);\r\n  *outStream = outStreamLoc.Detach();\r\n\r\n  _buffer = NULL;\r\n  _bufferSize= 0;\r\n  ProcessedSize = 0;\r\n}\r\n\r\nHRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 sizeToRead = size;\r\n  if (size > 0)\r\n  {\r\n    RINOK(_thereAreBytesToReadEvent.Lock());\r\n    sizeToRead = MyMin(_bufferSize, size);\r\n    if (_bufferSize > 0)\r\n    {\r\n      MoveMemory(data, _buffer, sizeToRead);\r\n      _buffer = ((const Byte *)_buffer) + sizeToRead;\r\n      _bufferSize -= sizeToRead;\r\n      if (_bufferSize == 0)\r\n      {\r\n        _thereAreBytesToReadEvent.Reset();\r\n        _allBytesAreWritenEvent.Set();\r\n      }\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = sizeToRead;\r\n  ProcessedSize += sizeToRead;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseRead()\r\n{\r\n  _readStreamIsClosedEvent.Set();\r\n}\r\n\r\nHRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > 0)\r\n  {\r\n    _buffer = data;\r\n    _bufferSize = size;\r\n    _allBytesAreWritenEvent.Reset();\r\n    _thereAreBytesToReadEvent.Set();\r\n\r\n    HANDLE events[2]; \r\n    events[0] = _allBytesAreWritenEvent;\r\n    events[1] = _readStreamIsClosedEvent; \r\n    DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);\r\n    if (waitResult != WAIT_OBJECT_0 + 0)\r\n    {\r\n      // ReadingWasClosed = true;\r\n      return S_FALSE;\r\n    }\r\n    // if(!_allBytesAreWritenEvent.Lock())\r\n    //   return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseWrite()\r\n{\r\n  // _bufferSize must be = 0\r\n  _thereAreBytesToReadEvent.Set();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/StreamBinder.h",
    "content": "// StreamBinder.h\r\n\r\n#ifndef __STREAMBINDER_H\r\n#define __STREAMBINDER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Windows/Synchronization.h\"\r\n\r\nclass CStreamBinder\r\n{\r\n  NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent;\r\n  UInt32 _bufferSize;\r\n  const void *_buffer;\r\npublic:\r\n  // bool ReadingWasClosed;\r\n  UInt64 ProcessedSize;\r\n  CStreamBinder() {}\r\n  HRes CreateEvents();\r\n\r\n  void CreateStreams(ISequentialInStream **inStream, \r\n      ISequentialOutStream **outStream);\r\n  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseRead();\r\n\r\n  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseWrite();\r\n  void ReInit();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/StreamObjects.cpp",
    "content": "// StreamObjects.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamObjects.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\n\r\nSTDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 numBytesToRead = (UInt32)(MyMin(_pos + size, _size) - _pos);\r\n  memmove(data, _dataPointer + _pos, numBytesToRead);\r\n  _pos += numBytesToRead;\r\n  if(processedSize != NULL)\r\n    *processedSize = numBytesToRead;\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CWriteBuffer::Write(const void *data, size_t size)\r\n{\r\n  size_t newCapacity = _size + size;\r\n  _buffer.EnsureCapacity(newCapacity);\r\n  memmove(_buffer + _size, data, size);\r\n  _size += size;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  _writeBuffer.Write(data, size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK; \r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 newSize = size;\r\n  if (_pos + size > _size)\r\n    newSize = (UInt32)(_size - _pos);\r\n  memmove(_buffer + _pos, data, newSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = newSize;\r\n  _pos += newSize;\r\n  if (newSize != size)\r\n    return E_FAIL;\r\n  return S_OK; \r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result; \r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result; \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/StreamObjects.h",
    "content": "// StreamObjects.h\r\n\r\n#ifndef __STREAMOBJECTS_H\r\n#define __STREAMOBJECTS_H\r\n\r\n#include \"../../Common/DynamicBuffer.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CSequentialInStreamImp: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *_dataPointer;\r\n  size_t _size;\r\n  size_t _pos;\r\n\r\npublic:\r\n  void Init(const Byte *dataPointer, size_t size)\r\n  {\r\n    _dataPointer = dataPointer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n\r\nclass CWriteBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _size;\r\npublic:\r\n  CWriteBuffer(): _size(0) {}\r\n  void Init() { _size = 0;  }\r\n  void Write(const void *data, size_t size);\r\n  size_t GetSize() const { return _size; }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _buffer; }\r\n};\r\n\r\nclass CSequentialOutStreamImp: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CWriteBuffer _writeBuffer;\r\npublic:\r\n  void Init() { _writeBuffer.Init(); }\r\n  size_t GetSize() const { return _writeBuffer.GetSize(); }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamImp2: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n\r\n  void Init(Byte *buffer, size_t size)  \r\n  { \r\n    _buffer = buffer;\r\n    _pos = 0;\r\n    _size = size; \r\n  }\r\n\r\n  size_t GetPos() const { return _pos; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialInStreamSizeCount: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamSizeCount: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void Init() { _size = 0; }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Read(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (Byte *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Write(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/VirtThread.cpp",
    "content": "// VirtThread.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"VirtThread.h\"\r\n\r\nstatic THREAD_FUNC_DECL CoderThread(void *p)\r\n{\r\n  for (;;)\r\n  {\r\n    CVirtThread *t = (CVirtThread *)p;\r\n    t->StartEvent.Lock();\r\n    if (t->ExitEvent)\r\n      return 0;\r\n    t->Execute();\r\n    t->FinishedEvent.Set();\r\n  }\r\n}\r\n\r\nHRes CVirtThread::Create()\r\n{\r\n  RINOK(StartEvent.CreateIfNotCreated());\r\n  RINOK(FinishedEvent.CreateIfNotCreated());\r\n  StartEvent.Reset();\r\n  FinishedEvent.Reset();\r\n  ExitEvent = false;\r\n  if (Thread.IsCreated())\r\n    return S_OK;\r\n  return Thread.Create(CoderThread, this);\r\n}\r\n\r\nvoid CVirtThread::Start()\r\n{\r\n  ExitEvent = false;\r\n  StartEvent.Set();\r\n}\r\n\r\nCVirtThread::~CVirtThread()\r\n{\r\n  ExitEvent = true;\r\n  if (StartEvent.IsCreated())\r\n    StartEvent.Set();\r\n  Thread.Wait();\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Common/VirtThread.h",
    "content": "// VirtThread.h\r\n\r\n#ifndef __VIRTTHREAD_H\r\n#define __VIRTTHREAD_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Windows/Thread.h\"\r\n\r\nstruct CVirtThread\r\n{\r\n  NWindows::NSynchronization::CAutoResetEvent StartEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent FinishedEvent;\r\n  NWindows::CThread Thread;\r\n  bool ExitEvent;\r\n\r\n  ~CVirtThread();\r\n  HRes Create();\r\n  void Start();\r\n  void WaitFinish() { FinishedEvent.Lock(); } \r\n  virtual void Execute() = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/ARM.cpp",
    "content": "// ARM.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARM.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchARM.h\"\r\n}\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/ARM.h",
    "content": "// ARM.h\r\n\r\n#ifndef __ARM_H\r\n#define __ARM_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM, 0x05, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/ARMThumb.cpp",
    "content": "// ARMThumb.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ARMThumb.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchARMThumb.h\"\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/ARMThumb.h",
    "content": "// ARMThumb.h\r\n\r\n#ifndef __ARMTHUMB_H\r\n#define __ARMTHUMB_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARMThumb, 0x07, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/BCJ2Register.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"x86_2.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x0303011B, L\"BCJ2\", 4, false };\r\n\r\nREGISTER_CODEC(BCJ2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/BCJRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"x86.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x03030103, L\"BCJ\", 1, true };\r\n\r\nREGISTER_CODEC(BCJ)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __BRANCH_CODER_H\r\n#define __BRANCH_CODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/Types.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/BranchRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"PPC.h\"\r\n#include \"IA64.h\"\r\n#include \"ARM.h\"\r\n#include \"ARMThumb.h\"\r\n#include \"SPARC.h\"\r\n\r\n#define CREATE_CODEC(x) \\\r\n  static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \\\r\n  static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }\r\n\r\nCREATE_CODEC(BC_PPC_B)\r\nCREATE_CODEC(BC_IA64)\r\nCREATE_CODEC(BC_ARM)\r\nCREATE_CODEC(BC_ARMThumb)\r\nCREATE_CODEC(BC_SPARC)\r\n\r\n#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true  }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  METHOD_ITEM(BC_PPC_B,   0x02, 0x05, L\"BC_PPC_B\"),\r\n  METHOD_ITEM(BC_IA64,    0x04, 1, L\"BC_IA64\"),\r\n  METHOD_ITEM(BC_ARM,     0x05, 1, L\"BC_ARM\"),\r\n  METHOD_ITEM(BC_ARMThumb,0x07, 1, L\"BC_ARMThumb\"),\r\n  METHOD_ITEM(BC_SPARC,   0x08, 0x05, L\"BC_SPARC\")\r\n};\r\n\r\nREGISTER_CODECS(Branch)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/IA64.cpp",
    "content": "// IA64.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"IA64.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchIA64.h\"\r\n}\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/IA64.h",
    "content": "// IA64.h\r\n\r\n#ifndef __IA64_H\r\n#define __IA64_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_IA64, 0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/PPC.cpp",
    "content": "// PPC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"PPC.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchPPC.h\"\r\n}\r\n\r\nUInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/PPC.h",
    "content": "// PPC.h\r\n\r\n#ifndef __PPC_H\r\n#define __PPC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_PPC_B, 0x02, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/SPARC.cpp",
    "content": "// SPARC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"SPARC.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchSPARC.h\"\r\n}\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/SPARC.h",
    "content": "// SPARC.h\r\n\r\n#ifndef __SPARC_H\r\n#define __SPARC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_SPARC, 0x08, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/x86.cpp",
    "content": "// x86.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86.h\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/x86.h",
    "content": "// x86.h\r\n\r\n#ifndef __X86_H\r\n#define __X86_H\r\n\r\n#include \"BranchCoder.h\"\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchX86.h\"\r\n}\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  void x86Init() { x86_Convert_Init(_prevMask); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 , \r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/x86_2.cpp",
    "content": "// x86_2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86_2.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\ninline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }\r\ninline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }\r\ninline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CEncoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CEncoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize = 0;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusEncoder[i].Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    for (;;)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it \r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        UInt32 index;\r\n        if (b == 0xE8)\r\n          index = prevByte;\r\n        else if (b == 0xE9)\r\n          index = 256;\r\n        else if (IsJcc(prevByte, b))\r\n          index = 257;\r\n        else\r\n        {\r\n          prevByte = b;\r\n          continue;\r\n        }\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (!IsJ(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src = \r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;          \r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;          \r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      unsigned index = GetIndex(prevByte, b);\r\n      if (convert)\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 1);\r\n        bufferPos += 5;\r\n        COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n        for (int i = 24; i >= 0; i -= 8)\r\n          s.WriteByte((Byte)(dest >> i));\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize = \r\n        _mainStream.GetProcessedSize() + \r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeEncoder.GetProcessedSize();\r\n      */\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusDecoder[i].Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  for (;;)\r\n  {\r\n    if (processedBytes >= (1 << 20) && progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize = \r\n        _mainInStream.GetProcessedSize() + \r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeDecoder.GetProcessedSize();\r\n      */\r\n      const UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    UInt32 i;\r\n    Byte b = 0;\r\n    const UInt32 kBurstSize = (1 << 18);\r\n    for (i = 0; i < kBurstSize; i++)\r\n    {\r\n      if (!_mainInStream.ReadByte(b))\r\n        return Flush();\r\n      _outStream.WriteByte(b);\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      prevByte = b;\r\n    }\r\n    processedBytes += i;\r\n    if (i == kBurstSize)\r\n      continue;\r\n    unsigned index = GetIndex(prevByte, b);\r\n    if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)\r\n    {\r\n      UInt32 src = 0;\r\n      CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n      for (int i = 0; i < 4; i++)\r\n      {\r\n        Byte b0;\r\n        if(!s.ReadByte(b0))\r\n          return S_FALSE;\r\n        src <<= 8;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (Byte)(dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const CInBufferException &e) { return e.ErrorCode; }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Branch/x86_2.h",
    "content": "// x86_2.h\r\n\r\n#ifndef __BRANCH_X86_2_H\r\n#define __BRANCH_X86_2_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../RangeCoder/RangeCoderBit.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CEncoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CEncoder(): _buffer(0) {};\r\n  ~CEncoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n\r\nclass CDecoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{ \r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CDecoder *_coder;\r\n  public:\r\n    CCoderReleaser(CDecoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/ByteSwap/ByteSwap.cpp",
    "content": "// ByteSwap.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nSTDMETHODIMP CByteSwap2::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 2;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b = data[i];\r\n    data[i] = data[i + 1];\r\n    data[i + 1] = b;\r\n  }\r\n  return i;\r\n}\r\n\r\nSTDMETHODIMP CByteSwap4::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 4;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b0 = data[i];\r\n    Byte b1 = data[i + 1];\r\n    data[i] = data[i + 3];\r\n    data[i + 1] = data[i + 2];\r\n    data[i + 2] = b1;\r\n    data[i + 3] = b0;\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/ByteSwap/ByteSwap.h",
    "content": "// ByteSwap.h\r\n\r\n#ifndef __BYTESWAP_H\r\n#define __BYTESWAP_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n// {23170F69-40C1-278B-0203-020000000000}\r\nDEFINE_GUID(CLSID_CCompressConvertByteSwap2, \r\n0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\n// {23170F69-40C1-278B-0203-040000000000}\r\nDEFINE_GUID(CLSID_CCompressConvertByteSwap4, \r\n0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nclass CByteSwap2: \r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\nclass CByteSwap4: \r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/ByteSwap/ByteSwapRegister.cpp",
    "content": "// ByteSwapRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"ByteSwap.h\"\r\nstatic void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }\r\nstatic void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  { CreateCodec2, CreateCodec4, 0x020302, L\"Swap2\", 1, true },\r\n  { CreateCodec4, CreateCodec4, 0x020304, L\"Swap4\", 1, true }\r\n};\r\n\r\nREGISTER_CODECS(ByteSwap)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/ByteSwap/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/ByteSwap/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/CodecExports.cpp",
    "content": "// CodecExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterCodec.h\"\r\n#include \"../ICoder.h\"\r\n\r\nextern unsigned int g_NumCodecs;\r\nextern const CCodecInfo *g_Codecs[]; \r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec, \r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nstatic HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)\r\n{\r\n  GUID clsId = CLSID_CCodec;\r\n  for (int i = 0; i < sizeof(id); i++, id >>= 8)\r\n    clsId.Data4[i] = (Byte)(id & 0xFF);\r\n  if (encode)\r\n    clsId.Data3++;\r\n  return SetPropGUID(clsId, value);\r\n}\r\n\r\nstatic HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)\r\n{\r\n  index = -1;\r\n  if (clsID->Data1 != CLSID_CCodec.Data1 || \r\n      clsID->Data2 != CLSID_CCodec.Data2 ||\r\n      (clsID->Data3 & ~1) != kDecodeId)\r\n    return S_OK;\r\n  encode = (clsID->Data3 != kDecodeId);\r\n  UInt64 id = 0;\r\n  for (int j = 0; j < 8; j++)\r\n    id |= ((UInt64)clsID->Data4[j]) << (8 * j);\r\n  for (UInt32 i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)\r\n      continue;\r\n    if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n        codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n      return E_NOINTERFACE;\r\n    index = i;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  const CCodecInfo &codec = *g_Codecs[index];\r\n  if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n      codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n    return E_NOINTERFACE;\r\n  if (encode)\r\n  {\r\n    if (!codec.CreateEncoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateEncoder();\r\n  }\r\n  else\r\n  {\r\n    if (!codec.CreateDecoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateDecoder();\r\n  }\r\n  if (isCoder)\r\n    ((ICompressCoder *)*outObject)->AddRef();\r\n  else if (isCoder2)\r\n    ((ICompressCoder2 *)*outObject)->AddRef();\r\n  else\r\n    ((ICompressFilter *)*outObject)->AddRef();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  if (!isCoder && !isCoder2 && !isFilter)\r\n    return E_NOINTERFACE;\r\n  bool encode;\r\n  int codecIndex;\r\n  HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);\r\n  if (res != S_OK)\r\n    return res;\r\n  if (codecIndex < 0)\r\n    return CLASS_E_CLASSNOTAVAILABLE;\r\n  return CreateCoder2(encode, codecIndex, iid, outObject);\r\n}\r\n\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  ::VariantClear((VARIANTARG *)value);\r\n  const CCodecInfo &codec = *g_Codecs[codecIndex];\r\n  switch(propID)\r\n  {\r\n    case NMethodPropID::kID:\r\n    {\r\n      value->uhVal.QuadPart = (UInt64)codec.Id;\r\n      value->vt = VT_UI8;\r\n      break;\r\n    }\r\n    case NMethodPropID::kName:\r\n      if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)\r\n        value->vt = VT_BSTR;\r\n      break;\r\n    case NMethodPropID::kDecoder:\r\n      if (codec.CreateDecoder)\r\n        return SetClassID(codec.Id, false, value);\r\n      break;\r\n    case NMethodPropID::kEncoder:\r\n      if (codec.CreateEncoder)\r\n        return SetClassID(codec.Id, true, value);\r\n      break;\r\n    case NMethodPropID::kInStreams:\r\n    {\r\n      if (codec.NumInStreams != 1)\r\n      {\r\n        value->vt = VT_UI4;\r\n        value->ulVal = codec.NumInStreams;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetNumberOfMethods(UINT32 *numCodecs)\r\n{\r\n  *numCodecs = g_NumCodecs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Copy/CopyCoder.cpp",
    "content": "// Compress/CopyCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"CopyCoder.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\nnamespace NCompress {\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCCopyCoder::~CCopyCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 * /* inSize */, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  TotalSize = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 realProcessedSize;\r\n    UInt32 size = kBufferSize;\r\n    if (outSize != 0)\r\n      if (size > *outSize - TotalSize)\r\n        size = (UInt32)(*outSize - TotalSize);\r\n    RINOK(inStream->Read(_buffer, size, &realProcessedSize));\r\n    if (realProcessedSize == 0)\r\n      break;\r\n    RINOK(WriteStream(outStream, _buffer, realProcessedSize, NULL));\r\n    TotalSize += realProcessedSize;\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = TotalSize;\r\n  return S_OK;\r\n}\r\n\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Copy/CopyCoder.h",
    "content": "// Compress/CopyCoder.h\r\n\r\n#ifndef __COMPRESS_COPYCODER_H\r\n#define __COMPRESS_COPYCODER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nnamespace NCompress {\r\n\r\nclass CCopyCoder: \r\n  public ICompressCoder,\r\n  public ICompressGetInStreamProcessedSize,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  UInt64 TotalSize;\r\n  CCopyCoder(): TotalSize(0) , _buffer(0) {};\r\n  ~CCopyCoder();\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Copy/CopyRegister.cpp",
    "content": "// LZMARegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"CopyCoder.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n{ CreateCodec, CreateCodec, 0x00, L\"Copy\", 1, false };\r\n\r\nREGISTER_CODEC(Copy)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Copy/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/Copy/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZ/LZOutWindow.cpp",
    "content": "// LZOutWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZOutWindow.h\"\r\n\r\nvoid CLZOutWindow::Init(bool solid)\r\n{\r\n  if(!solid)\r\n    COutBuffer::Init();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZ/LZOutWindow.h",
    "content": "// LZOutWindow.h\r\n\r\n#ifndef __LZ_OUT_WINDOW_H\r\n#define __LZ_OUT_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\ntypedef COutBufferException CLZOutWindowException;\r\n#endif\r\n\r\nclass CLZOutWindow: public COutBuffer\r\n{\r\npublic:\r\n  void Init(bool solid = false);\r\n  \r\n  // distance >= 0, len > 0, \r\n  bool CopyBlock(UInt32 distance, UInt32 len)\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (distance >= _pos)\r\n    {\r\n      if (!_overDict || distance >= _bufferSize)\r\n        return false;\r\n      pos += _bufferSize;\r\n    }\r\n    if (_limitPos - _pos > len && _bufferSize - pos > len)\r\n    {\r\n      const Byte *src = _buffer + pos;\r\n      Byte *dest = _buffer + _pos;\r\n      _pos += len;\r\n      do\r\n        *dest++ = *src++;\r\n      while(--len != 0);\r\n    }\r\n    else do\r\n    {\r\n      if (pos == _bufferSize)\r\n        pos = 0;\r\n      _buffer[_pos++] = _buffer[pos++];\r\n      if (_pos == _limitPos)\r\n        FlushWithCheck();  \r\n    }\r\n    while(--len != 0);\r\n    return true;\r\n  }\r\n  \r\n  void PutByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if (_pos == _limitPos)\r\n      FlushWithCheck();  \r\n  }\r\n  \r\n  Byte GetByte(UInt32 distance) const\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n      pos += _bufferSize;\r\n    return _buffer[pos]; \r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZ/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA/LZMA.h",
    "content": "// LZMA.h\r\n\r\n#ifndef __LZMA_H\r\n#define __LZMA_H\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst UInt32 kNumRepDistances = 4;\r\n\r\nconst int kNumStates = 12;\r\n\r\nconst Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nconst Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nconst Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nconst Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\nclass CState\r\n{\r\npublic:\r\n  Byte Index;\r\n  void Init() { Index = 0; }\r\n  void UpdateChar() { Index = kLiteralNextStates[Index]; }\r\n  void UpdateMatch() { Index = kMatchNextStates[Index]; }\r\n  void UpdateRep() { Index = kRepNextStates[Index]; }\r\n  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }\r\n  bool IsCharState() const { return Index < 7; }\r\n};\r\n\r\nconst int kNumPosSlotBits = 6; \r\nconst int kDicLogSizeMin = 0; \r\nconst int kDicLogSizeMax = 32; \r\nconst int kDistTableSizeMax = kDicLogSizeMax * 2; \r\n\r\nconst UInt32 kNumLenToPosStates = 4;\r\n\r\ninline UInt32 GetLenToPosState(UInt32 len)\r\n{\r\n  len -= 2;\r\n  if (len < kNumLenToPosStates)\r\n    return len;\r\n  return kNumLenToPosStates - 1;\r\n}\r\n\r\nnamespace NLength {\r\n\r\nconst int kNumPosStatesBitsMax = 4;\r\nconst UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\r\nconst int kNumPosStatesBitsEncodingMax = 4;\r\nconst UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\nconst int kNumLowBits = 3;\r\nconst int kNumMidBits = 3;\r\nconst int kNumHighBits = 8;\r\nconst UInt32 kNumLowSymbols = 1 << kNumLowBits;\r\nconst UInt32 kNumMidSymbols = 1 << kNumMidBits;\r\nconst UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\r\n\r\n}\r\n\r\nconst UInt32 kMatchMinLen = 2;\r\nconst UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\r\n\r\nconst int kNumAlignBits = 4;\r\nconst UInt32 kAlignTableSize = 1 << kNumAlignBits;\r\nconst UInt32 kAlignMask = (kAlignTableSize - 1);\r\n\r\nconst UInt32 kStartPosModelIndex = 4;\r\nconst UInt32 kEndPosModelIndex = 14;\r\nconst UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\nconst UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\r\nconst int kNumLitPosStatesBitsEncodingMax = 4;\r\nconst int kNumLitContextBitsMax = 8;\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA/LZMADecoder.cpp",
    "content": "// LZMADecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\n#include \"../../../Common/Defs.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kLenIdFinished = -1;\r\nconst int kLenIdNeedInit = -2;\r\n\r\nvoid CDecoder::Init()\r\n{\r\n  { \r\n    for(int i = 0; i < kNumStates; i++)\r\n    {\r\n      for (UInt32 j = 0; j <= _posStateMask; j++)\r\n      {\r\n        _isMatch[i][j].Init();\r\n        _isRep0Long[i][j].Init();\r\n      }\r\n      _isRep[i].Init();\r\n      _isRepG0[i].Init();\r\n      _isRepG1[i].Init();\r\n      _isRepG2[i].Init();\r\n    }\r\n  }\r\n  { \r\n    for (UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n    _posSlotDecoder[i].Init();\r\n  }\r\n  { \r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posDecoders[i].Init();\r\n  }\r\n  _posAlignDecoder.Init();\r\n  _lenDecoder.Init(_posStateMask + 1);\r\n  _repMatchLenDecoder.Init(_posStateMask + 1);\r\n  _literalDecoder.Init();\r\n\r\n  _state.Init();\r\n  _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0;\r\n}\r\n\r\nHRESULT CDecoder::CodeSpec(UInt32 curSize)\r\n{\r\n  if (_outSizeDefined)\r\n  {\r\n    const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize();\r\n    if (curSize > rem)\r\n      curSize = (UInt32)rem;\r\n  }\r\n\r\n  if (_remainLen == kLenIdFinished)\r\n    return S_OK;\r\n  if (_remainLen == kLenIdNeedInit)\r\n  {\r\n    _rangeDecoder.Init();\r\n    Init();\r\n    _remainLen = 0;\r\n  }\r\n  if (curSize == 0)\r\n    return S_OK;\r\n\r\n  UInt32 rep0 = _reps[0];\r\n  UInt32 rep1 = _reps[1];\r\n  UInt32 rep2 = _reps[2];\r\n  UInt32 rep3 = _reps[3];\r\n  CState state = _state;\r\n  Byte previousByte;\r\n\r\n  while(_remainLen > 0 && curSize > 0)\r\n  {\r\n    previousByte = _outWindowStream.GetByte(rep0);\r\n    _outWindowStream.PutByte(previousByte);\r\n    _remainLen--;\r\n    curSize--;\r\n  }\r\n  UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n  if (nowPos64 == 0)\r\n    previousByte = 0;\r\n  else\r\n    previousByte = _outWindowStream.GetByte(0);\r\n\r\n  while(curSize > 0)\r\n  {\r\n    {\r\n      #ifdef _NO_EXCEPTIONS\r\n      if (_rangeDecoder.Stream.ErrorCode != S_OK)\r\n        return _rangeDecoder.Stream.ErrorCode;\r\n      #endif\r\n      if (_rangeDecoder.Stream.WasFinished())\r\n        return S_FALSE;\r\n      UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n      if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n      {\r\n        if(!state.IsCharState())\r\n          previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte, _outWindowStream.GetByte(rep0));\r\n        else\r\n          previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte);\r\n        _outWindowStream.PutByte(previousByte);\r\n        state.UpdateChar();\r\n        curSize--;\r\n        nowPos64++;\r\n      }\r\n      else             \r\n      {\r\n        UInt32 len;\r\n        if(_isRep[state.Index].Decode(&_rangeDecoder) == 1)\r\n        {\r\n          len = 0;\r\n          if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0)\r\n          {\r\n            if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n            {\r\n              state.UpdateShortRep();\r\n              len = 1;\r\n            }\r\n          }\r\n          else\r\n          {\r\n            UInt32 distance;\r\n            if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0)\r\n              distance = rep1;\r\n            else \r\n            {\r\n              if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0)\r\n                distance = rep2;\r\n              else\r\n              {\r\n                distance = rep3;\r\n                rep3 = rep2;\r\n              }\r\n              rep2 = rep1;\r\n            }\r\n            rep1 = rep0;\r\n            rep0 = distance;\r\n          }\r\n          if (len == 0)\r\n          {\r\n            len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;\r\n            state.UpdateRep();\r\n          }\r\n        }\r\n        else\r\n        {\r\n          rep3 = rep2;\r\n          rep2 = rep1;\r\n          rep1 = rep0;\r\n          len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);\r\n          state.UpdateMatch();\r\n          UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);\r\n          if (posSlot >= kStartPosModelIndex)\r\n          {\r\n            UInt32 numDirectBits = (posSlot >> 1) - 1;\r\n            rep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\r\n            if (posSlot < kEndPosModelIndex)\r\n              rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders + \r\n                  rep0 - posSlot - 1, &_rangeDecoder, numDirectBits);\r\n            else\r\n            {\r\n              rep0 += (_rangeDecoder.DecodeDirectBits(\r\n                  numDirectBits - kNumAlignBits) << kNumAlignBits);\r\n              rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder);\r\n              if (rep0 == 0xFFFFFFFF)\r\n              {\r\n                _remainLen = kLenIdFinished;\r\n                return S_OK;\r\n              }\r\n            }\r\n          }\r\n          else\r\n            rep0 = posSlot;\r\n        }\r\n        UInt32 locLen = len;\r\n        if (len > curSize)\r\n          locLen = (UInt32)curSize;\r\n        if (!_outWindowStream.CopyBlock(rep0, locLen))\r\n          return S_FALSE;\r\n        previousByte = _outWindowStream.GetByte(0);\r\n        curSize -= locLen;\r\n        nowPos64 += locLen;\r\n        len -= locLen;\r\n        if (len != 0)\r\n        {\r\n          _remainLen = (Int32)len;\r\n          break;\r\n        }\r\n\r\n        #ifdef _NO_EXCEPTIONS\r\n        if (_outWindowStream.ErrorCode != S_OK)\r\n          return _outWindowStream.ErrorCode;\r\n        #endif\r\n      }\r\n    }\r\n  }\r\n  if (_rangeDecoder.Stream.WasFinished())\r\n    return S_FALSE;\r\n  _reps[0] = rep0;\r\n  _reps[1] = rep1;\r\n  _reps[2] = rep2;\r\n  _reps[3] = rep3;\r\n  _state = state;\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 *, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  SetInStream(inStream);\r\n  _outWindowStream.SetStream(outStream);\r\n  SetOutStreamSize(outSize);\r\n  CDecoderFlusher flusher(this);\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 curSize = 1 << 18;\r\n    RINOK(CodeSpec(curSize));\r\n    if (_remainLen == kLenIdFinished)\r\n      break;\r\n    if (progress != NULL)\r\n    {\r\n      UInt64 inSize = _rangeDecoder.GetProcessedSize();\r\n      UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(&inSize, &nowPos64));\r\n    }\r\n    if (_outSizeDefined)\r\n      if (_outWindowStream.GetProcessedSize() >= _outSize)\r\n        break;\r\n  } \r\n  flusher.NeedFlush = false;\r\n  return Flush();\r\n}\r\n\r\n\r\n#ifdef _NO_EXCEPTIONS\r\n\r\n#define LZMA_TRY_BEGIN\r\n#define LZMA_TRY_END\r\n\r\n#else\r\n\r\n#define LZMA_TRY_BEGIN try { \r\n#define LZMA_TRY_END } \\\r\n  catch(const CInBufferException &e)  { return e.ErrorCode; } \\\r\n  catch(const CLZOutWindowException &e)  { return e.ErrorCode; } \\\r\n  catch(...) { return S_FALSE; }\r\n\r\n#endif\r\n\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  LZMA_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size)\r\n{\r\n  if (size < 5)\r\n    return E_INVALIDARG;\r\n  int lc = properties[0] % 9;\r\n  Byte remainder = (Byte)(properties[0] / 9);\r\n  int lp = remainder % 5;\r\n  int pb = remainder / 5;\r\n  if (pb > NLength::kNumPosStatesBitsMax)\r\n    return E_INVALIDARG;\r\n  _posStateMask = (1 << pb) - 1;\r\n  UInt32 dictionarySize = 0;\r\n  for (int i = 0; i < 4; i++)\r\n    dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n  if (!_outWindowStream.Create(dictionarySize))\r\n    return E_OUTOFMEMORY;\r\n  if (!_literalDecoder.Create(lp, lc))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = _rangeDecoder.GetProcessedSize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _rangeDecoder.SetStream(inStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::ReleaseInStream()\r\n{\r\n  _rangeDecoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  _outSizeDefined = (outSize != NULL);\r\n  if (_outSizeDefined)\r\n    _outSize = *outSize;\r\n  _remainLen = kLenIdNeedInit;\r\n  _outWindowStream.Init();\r\n  return S_OK;\r\n}\r\n\r\n#ifndef NO_READ_FROM_CODER\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  const UInt64 startPos = _outWindowStream.GetProcessedSize();\r\n  _outWindowStream.SetMemStream((Byte *)data);\r\n  RINOK(CodeSpec(size));\r\n  if (processedSize)\r\n    *processedSize = (UInt32)(_outWindowStream.GetProcessedSize() - startPos);\r\n  return Flush();\r\n  LZMA_TRY_END\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA/LZMADecoder.h",
    "content": "// LZMA/Decoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/LZOutWindow.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;\r\n\r\nclass CLiteralDecoder2\r\n{\r\n  CMyBitDecoder _decoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _decoders[i].Init();\r\n  }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n      RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, Byte matchByte)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      UInt32 matchBit = (matchByte >> 7) & 1;\r\n      matchByte <<= 1;\r\n      // UInt32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);\r\n      // symbol = (symbol << 1) | bit;\r\n      UInt32 bit;\r\n      RC_GETBIT2(kNumMoveBits, _decoders[0x100 + (matchBit << 8) + symbol].Prob, symbol, \r\n          bit = 0, bit = 1)\r\n      if (matchBit != bit)\r\n      {\r\n        while (symbol < 0x100)\r\n        {\r\n          // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n          RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n        }\r\n        break;\r\n      }\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n};\r\n\r\nclass CLiteralDecoder\r\n{\r\n  CLiteralDecoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralDecoder(): _coders(0) {}\r\n  ~CLiteralDecoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte, Byte matchByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CDecoder\r\n{\r\n  CMyBitDecoder _choice;\r\n  CMyBitDecoder _choice2;\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder; \r\npublic:\r\n  void Init(UInt32 numPosStates)\r\n  {\r\n    _choice.Init();\r\n    _choice2.Init();\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n    {\r\n      _lowCoder[posState].Init();\r\n      _midCoder[posState].Init();\r\n    }\r\n    _highCoder.Init();\r\n  }\r\n  UInt32 Decode(NRangeCoder::CDecoder *rangeDecoder, UInt32 posState)\r\n  {\r\n    if(_choice.Decode(rangeDecoder) == 0)\r\n      return _lowCoder[posState].Decode(rangeDecoder);\r\n    if(_choice2.Decode(rangeDecoder) == 0)\r\n      return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);\r\n    return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CDecoder: \r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  public ICompressGetInStreamProcessedSize,\r\n  #ifndef NO_READ_FROM_CODER\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CLZOutWindow _outWindowStream;\r\n  NRangeCoder::CDecoder _rangeDecoder;\r\n\r\n  CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax];\r\n  CMyBitDecoder _isRep[kNumStates];\r\n  CMyBitDecoder _isRepG0[kNumStates];\r\n  CMyBitDecoder _isRepG1[kNumStates];\r\n  CMyBitDecoder _isRepG2[kNumStates];\r\n  CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax];\r\n\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];\r\n\r\n  CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;\r\n  \r\n  NLength::CDecoder _lenDecoder;\r\n  NLength::CDecoder _repMatchLenDecoder;\r\n\r\n  CLiteralDecoder _literalDecoder;\r\n\r\n  UInt32 _posStateMask;\r\n\r\n  ///////////////////\r\n  // State\r\n  UInt32 _reps[4];\r\n  CState _state;\r\n  Int32 _remainLen; // -1 means end of stream. // -2 means need Init\r\n  UInt64 _outSize;\r\n  bool _outSizeDefined;\r\n\r\n  void Init();\r\n  HRESULT CodeSpec(UInt32 size);\r\npublic:\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  MY_UNKNOWN_IMP5(\r\n      ICompressSetDecoderProperties2, \r\n      ICompressGetInStreamProcessedSize,\r\n      ICompressSetInStream, \r\n      ICompressSetOutStreamSize, \r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize)\r\n  #endif\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _outWindowStream.ReleaseStream();\r\n    ReleaseInStream();\r\n  }\r\n\r\n  class CDecoderFlusher\r\n  {\r\n    CDecoder *_decoder;\r\n  public:\r\n    bool NeedFlush;\r\n    CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}\r\n    ~CDecoderFlusher() \r\n    { \r\n      if (NeedFlush)\r\n        _decoder->Flush();\r\n      _decoder->ReleaseStreams(); \r\n    }\r\n  };\r\n\r\n  HRESULT Flush() {  return _outWindowStream.Flush(); }  \r\n\r\n  STDMETHOD(CodeReal)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  \r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  CDecoder(): _outSizeDefined(false) {}\r\n  virtual ~CDecoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp",
    "content": "// LZMA/Encoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\n#include \"../../../Common/Defs.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"LZMAEncoder.h\"\r\n\r\n// extern \"C\" { #include \"../../../../C/7zCrc.h\" }\r\n\r\n// #define SHOW_STAT\r\n\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\n// struct CCrcInit { CCrcInit() { InitCrcTable(); } } g_CrcInit;\r\n\r\nconst int kDefaultDictionaryLogSize = 22;\r\nconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n#ifndef LZMA_LOG_BSR\r\nByte g_FastPos[1 << kNumLogBits];\r\n\r\nclass CFastPosInit\r\n{\r\npublic:\r\n  CFastPosInit() { Init(); }\r\n  void Init()\r\n  {\r\n    const Byte kFastSlots = kNumLogBits * 2;\r\n    int c = 2;\r\n    g_FastPos[0] = 0;\r\n    g_FastPos[1] = 1;\r\n\r\n    for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n    {\r\n      UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n      for (UInt32 j = 0; j < k; j++, c++)\r\n        g_FastPos[c] = slotFast;\r\n    }\r\n  }\r\n} g_FastPosInit;\r\n#endif\r\n\r\nvoid CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    _encoders[context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nvoid CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, \r\n    Byte matchByte, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    UInt32 matchBit = (matchByte >> i) & 1;\r\n    _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n    if (matchBit != bit)\r\n    {\r\n      while(i != 0)\r\n      {\r\n        i--;\r\n        UInt32 bit = (symbol >> i) & 1;\r\n        _encoders[context].Encode(rangeEncoder, bit);\r\n        context = (context << 1) | bit;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nUInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  if (matchMode)\r\n  {\r\n    do \r\n    {\r\n      i--;\r\n      UInt32 matchBit = (matchByte >> i) & 1;\r\n      UInt32 bit = (symbol >> i) & 1;\r\n      price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit);\r\n      context = (context << 1) | bit;\r\n      if (matchBit != bit)\r\n        break;\r\n    }\r\n    while (i != 0);\r\n  }\r\n  while(i != 0)\r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    price += _encoders[context].GetPrice(bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  return price;\r\n};\r\n\r\n\r\nnamespace NLength {\r\n\r\nvoid CEncoder::Init(UInt32 numPosStates)\r\n{\r\n  _choice.Init();\r\n  _choice2.Init();\r\n  for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n  {\r\n    _lowCoder[posState].Init();\r\n    _midCoder[posState].Init();\r\n  }\r\n  _highCoder.Init();\r\n}\r\n\r\nvoid CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n  {\r\n    _choice.Encode(rangeEncoder, 0);\r\n    _lowCoder[posState].Encode(rangeEncoder, symbol);\r\n  }\r\n  else\r\n  {\r\n    _choice.Encode(rangeEncoder, 1);\r\n    if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n    {\r\n      _choice2.Encode(rangeEncoder, 0);\r\n      _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      _choice2.Encode(rangeEncoder, 1);\r\n      _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CEncoder::SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const\r\n{\r\n  UInt32 a0 = _choice.GetPrice0();\r\n  UInt32 a1 = _choice.GetPrice1();\r\n  UInt32 b0 = a1 + _choice2.GetPrice0();\r\n  UInt32 b1 = a1 + _choice2.GetPrice1();\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + _lowCoder[posState].GetPrice(i);\r\n  }\r\n  for (; i < kNumLowSymbols + kNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + _midCoder[posState].GetPrice(i - kNumLowSymbols);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + _highCoder.GetPrice(i - kNumLowSymbols - kNumMidSymbols);\r\n}\r\n\r\n}\r\n\r\nCEncoder::CEncoder():\r\n  _numFastBytes(kNumFastBytesDefault),\r\n  _distTableSize(kDefaultDictionaryLogSize * 2),\r\n  _posStateBits(2),\r\n  _posStateMask(4 - 1),\r\n  _numLiteralPosStateBits(0),\r\n  _numLiteralContextBits(3),\r\n  _dictionarySize(1 << kDefaultDictionaryLogSize),\r\n  _matchFinderCycles(0),\r\n  #ifdef COMPRESS_MF_MT\r\n  _multiThread(false),\r\n  #endif\r\n  _writeEndMark(false)\r\n{\r\n  MatchFinder_Construct(&_matchFinderBase);\r\n  // _maxMode = false;\r\n  _fastMode = false;\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Construct(&_matchFinderMt);\r\n  _matchFinderMt.MatchFinder = &_matchFinderBase;\r\n  #endif\r\n}\r\n\r\n\r\nstatic void *SzAlloc(size_t size) { return BigAlloc(size); }\r\nstatic void SzFree(void *address) { BigFree(address); }\r\nISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Destruct(&_matchFinderMt, &g_Alloc);\r\n  #endif\r\n  MatchFinder_Free(&_matchFinderBase, &g_Alloc);\r\n}\r\n\r\nstatic const UInt32 kBigHashDicLimit = (UInt32)1 << 24;\r\n\r\nHRESULT CEncoder::Create()\r\n{\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  bool btMode = (_matchFinderBase.btMode != 0);\r\n  #ifdef COMPRESS_MF_MT\r\n  _mtMode = (_multiThread && !_fastMode && btMode);\r\n  #endif\r\n  \r\n  if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _matchFinderBase.bigHash = (_dictionarySize > kBigHashDicLimit);\r\n\r\n  UInt32 numCycles = 16 + (_numFastBytes >> 1);\r\n  if (!btMode)\r\n    numCycles >>= 1;\r\n  if (_matchFinderCycles != 0)\r\n    numCycles = _matchFinderCycles;\r\n  _matchFinderBase.cutValue = numCycles;\r\n  #ifdef COMPRESS_MF_MT\r\n  if (_mtMode)\r\n  {\r\n    RINOK(MatchFinderMt_Create(&_matchFinderMt, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc));\r\n    _matchFinderObj = &_matchFinderMt;\r\n    MatchFinderMt_CreateVTable(&_matchFinderMt, &_matchFinder);\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!MatchFinder_Create(&_matchFinderBase, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc))\r\n      return E_OUTOFMEMORY;\r\n    _matchFinderObj = &_matchFinderBase;\r\n    MatchFinder_CreateVTable(&_matchFinderBase, &_matchFinder);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\ninline wchar_t GetUpperChar(wchar_t c)\r\n{\r\n  if (c >= 'a' && c <= 'z')\r\n    c -= 0x20;\r\n  return c;\r\n}\r\n\r\nstatic int ParseMatchFinder(const wchar_t *s, int *btMode, UInt32 *numHashBytes /* , int *skipModeBits */)\r\n{\r\n  wchar_t c = GetUpperChar(*s++);\r\n  if (c == L'H')\r\n  {\r\n    if (GetUpperChar(*s++) != L'C')\r\n      return 0;\r\n    int numHashBytesLoc = (int)(*s++ - L'0');\r\n    if (numHashBytesLoc < 4 || numHashBytesLoc > 4)\r\n      return 0;\r\n    if (*s++ != 0)\r\n      return 0;\r\n    *btMode = 0;\r\n    *numHashBytes = numHashBytesLoc;\r\n    return 1;\r\n  }\r\n  if (c != L'B')\r\n    return 0;\r\n\r\n  if (GetUpperChar(*s++) != L'T')\r\n    return 0;\r\n  int numHashBytesLoc = (int)(*s++ - L'0');\r\n  if (numHashBytesLoc < 2 || numHashBytesLoc > 4)\r\n    return 0;\r\n  c = GetUpperChar(*s++);\r\n  /*\r\n  int skipModeBitsLoc = 0;\r\n  if (c == L'D')\r\n  {\r\n    skipModeBitsLoc = 2;\r\n    c = GetUpperChar(*s++);\r\n  }\r\n  */\r\n  if (c != L'\\0')\r\n    return 0;\r\n  *btMode = 1;\r\n  *numHashBytes = numHashBytesLoc;\r\n  // *skipModeBits = skipModeBitsLoc;\r\n  return 1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, \r\n    const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  for (UInt32 i = 0; i < numProperties; i++)\r\n  {\r\n    const PROPVARIANT &prop = properties[i];\r\n    switch(propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 numFastBytes = prop.ulVal;\r\n        if(numFastBytes < 5 || numFastBytes > kMatchMaxLen)\r\n          return E_INVALIDARG;\r\n        _numFastBytes = numFastBytes;\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinderCycles:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        _matchFinderCycles = prop.ulVal;\r\n        break;\r\n      }\r\n      case NCoderPropID::kAlgorithm:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 maximize = prop.ulVal;\r\n        _fastMode = (maximize == 0); \r\n        // _maxMode = (maximize >= 2);\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinder:\r\n      {\r\n        if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        if (!ParseMatchFinder(prop.bstrVal, &_matchFinderBase.btMode, &_matchFinderBase.numHashBytes /* , &_matchFinderBase.skipModeBits */))\r\n          return E_INVALIDARG;\r\n        break;\r\n      }\r\n      case NCoderPropID::kMultiThread:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        #ifdef COMPRESS_MF_MT\r\n        Bool newMultiThread = (prop.boolVal == VARIANT_TRUE);\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          ReleaseMatchFinder();\r\n          _multiThread = newMultiThread;\r\n        }\r\n        #endif\r\n        break;\r\n      }\r\n      case NCoderPropID::kNumThreads:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        #ifdef COMPRESS_MF_MT\r\n        Bool newMultiThread = (prop.ulVal > 1) ? True : False;\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          ReleaseMatchFinder();\r\n          _multiThread = newMultiThread;\r\n        }\r\n        #endif\r\n        break;\r\n      }\r\n      case NCoderPropID::kDictionarySize:\r\n      {\r\n        const int kDicLogSizeMaxCompress = 30; // must be <= ((kNumLogBits - 1) * 2) + 7 = 31;\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 dictionarySize = prop.ulVal;\r\n        if (dictionarySize < UInt32(1 << kDicLogSizeMin) ||\r\n            dictionarySize > UInt32(1 << kDicLogSizeMaxCompress))\r\n          return E_INVALIDARG;\r\n        _dictionarySize = dictionarySize;\r\n        UInt32 dicLogSize;\r\n        for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n          if (dictionarySize <= (UInt32(1) << dicLogSize))\r\n            break;\r\n        _distTableSize = dicLogSize * 2;\r\n        break;\r\n      }\r\n      case NCoderPropID::kPosStateBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _posStateBits = value;\r\n        _posStateMask = (1 << _posStateBits) - 1;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitPosBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralPosStateBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitContextBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitContextBitsMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralContextBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kEndMarker:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE);\r\n        break;\r\n      }\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{ \r\n  const UInt32 kPropSize = 5;\r\n  Byte properties[kPropSize];\r\n  properties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n  for (int i = 0; i < 4; i++)\r\n    properties[1 + i] = Byte(_dictionarySize >> (8 * i));\r\n  return WriteStream(outStream, properties, kPropSize, NULL);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _rangeEncoder.SetStream(outStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _rangeEncoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Init()\r\n{\r\n  CBaseState::Init();\r\n\r\n  _rangeEncoder.Init();\r\n\r\n  for(int i = 0; i < kNumStates; i++)\r\n  {\r\n    for (UInt32 j = 0; j <= _posStateMask; j++)\r\n    {\r\n      _isMatch[i][j].Init();\r\n      _isRep0Long[i][j].Init();\r\n    }\r\n    _isRep[i].Init();\r\n    _isRepG0[i].Init();\r\n    _isRepG1[i].Init();\r\n    _isRepG2[i].Init();\r\n  }\r\n\r\n  _literalEncoder.Init();\r\n\r\n  {\r\n    for(UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n      _posSlotEncoder[i].Init();\r\n  }\r\n  {\r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posEncoders[i].Init();\r\n  }\r\n\r\n  _lenEncoder.Init(1 << _posStateBits);\r\n  _repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n  _posAlignEncoder.Init();\r\n\r\n  _longestMatchWasFound = false;\r\n  _optimumEndIndex = 0;\r\n  _optimumCurrentIndex = 0;\r\n  _additionalOffset = 0;\r\n\r\n  return S_OK;\r\n}\r\n\r\n#ifdef SHOW_STAT\r\nstatic int ttt = 0;\r\n#endif\r\n\r\nvoid CEncoder::MovePos(UInt32 num)\r\n{\r\n  #ifdef SHOW_STAT\r\n  ttt += num;\r\n  printf(\"\\n MovePos %d\", num);\r\n  #endif\r\n  if (num != 0)\r\n  {\r\n    _additionalOffset += num;\r\n    _matchFinder.Skip(_matchFinderObj, num);\r\n  }\r\n}\r\n\r\nUInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)\r\n{\r\n  _optimumEndIndex = cur;\r\n  UInt32 posMem = _optimum[cur].PosPrev;\r\n  UInt32 backMem = _optimum[cur].BackPrev;\r\n  do\r\n  {\r\n    if (_optimum[cur].Prev1IsChar)\r\n    {\r\n      _optimum[posMem].MakeAsChar();\r\n      _optimum[posMem].PosPrev = posMem - 1;\r\n      if (_optimum[cur].Prev2)\r\n      {\r\n        _optimum[posMem - 1].Prev1IsChar = false;\r\n        _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n        _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n      }\r\n    }\r\n    UInt32 posPrev = posMem;\r\n    UInt32 backCur = backMem;\r\n\r\n    backMem = _optimum[posPrev].BackPrev;\r\n    posMem = _optimum[posPrev].PosPrev;\r\n\r\n    _optimum[posPrev].BackPrev = backCur;\r\n    _optimum[posPrev].PosPrev = cur;\r\n    cur = posPrev;\r\n  }\r\n  while(cur != 0);\r\n  backRes = _optimum[0].BackPrev;\r\n  _optimumCurrentIndex  = _optimum[0].PosPrev;\r\n  return _optimumCurrentIndex; \r\n}\r\n\r\n/*\r\nOut:\r\n  (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal\r\n*/\r\n\r\nUInt32 CEncoder::GetOptimum(UInt32 position, UInt32 &backRes)\r\n{\r\n  if(_optimumEndIndex != _optimumCurrentIndex)\r\n  {\r\n    const COptimal &optimum = _optimum[_optimumCurrentIndex];\r\n    UInt32 lenRes = optimum.PosPrev - _optimumCurrentIndex;\r\n    backRes = optimum.BackPrev;\r\n    _optimumCurrentIndex = optimum.PosPrev;\r\n    return lenRes;\r\n  }\r\n  _optimumCurrentIndex = _optimumEndIndex = 0;\r\n  \r\n  UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n\r\n  UInt32 lenMain, numDistancePairs;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    lenMain = ReadMatchDistances(numDistancePairs);\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    numDistancePairs = _numDistancePairs;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n  const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n  if (numAvailableBytes < 2)\r\n  {\r\n    backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n  if (numAvailableBytes > kMatchMaxLen)\r\n    numAvailableBytes = kMatchMaxLen;\r\n\r\n  UInt32 reps[kNumRepDistances];\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  UInt32 i;\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    reps[i] = _repDistances[i];\r\n    const Byte *data2 = data - (reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    UInt32 lenTest;\r\n    for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    UInt32 lenRes = repLens[repMaxIndex];\r\n    MovePos(lenRes - 1);\r\n    return lenRes;\r\n  }\r\n\r\n  UInt32 *matchDistances = _matchDistances;\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; \r\n    MovePos(lenMain - 1);\r\n    return lenMain;\r\n  }\r\n  Byte currentByte = *data;\r\n  Byte matchByte = *(data - (reps[0] + 1));\r\n\r\n  if(lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    backRes = (UInt32)-1;\r\n    return 1;\r\n  }\r\n\r\n  _optimum[0].State = _state;\r\n\r\n  UInt32 posState = (position & _posStateMask);\r\n\r\n  _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() + \r\n      _literalEncoder.GetSubCoder(position, _previousByte)->GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n  _optimum[1].MakeAsChar();\r\n\r\n  UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1();\r\n  UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n  if(matchByte == currentByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n    if(shortRepPrice < _optimum[1].Price)\r\n    {\r\n      _optimum[1].Price = shortRepPrice;\r\n      _optimum[1].MakeAsShortRep();\r\n    }\r\n  }\r\n  UInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n  if(lenEnd < 2)\r\n  {\r\n    backRes = _optimum[1].BackPrev;\r\n    return 1;\r\n  }\r\n\r\n  _optimum[1].PosPrev = 0;\r\n  for (i = 0; i < kNumRepDistances; i++)\r\n    _optimum[0].Backs[i] = reps[i];\r\n\r\n  UInt32 len = lenEnd;\r\n  do\r\n    _optimum[len--].Price = kIfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    if (repLen < 2)\r\n      continue;\r\n    UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n      COptimal &optimum = _optimum[repLen];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = i;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n    }\r\n    while(--repLen >= 2);\r\n  }\r\n\r\n  UInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= lenMain)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matchDistances[offs])\r\n      offs += 2;\r\n    for(; ; len++)\r\n    {\r\n      UInt32 distance = matchDistances[offs + 1];\r\n      UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n      COptimal &optimum = _optimum[len];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = distance + kNumRepDistances;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n      if (len == matchDistances[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numDistancePairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  UInt32 cur = 0;\r\n\r\n  for (;;)\r\n  {\r\n    cur++;\r\n    if(cur == lenEnd)\r\n    {\r\n      return Backward(backRes, cur);\r\n    }\r\n    UInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n    UInt32 newLen, numDistancePairs;\r\n    newLen = ReadMatchDistances(numDistancePairs);\r\n    if(newLen >= _numFastBytes)\r\n    {\r\n      _numDistancePairs = numDistancePairs;\r\n      _longestMatchLength = newLen;\r\n      _longestMatchWasFound = true;\r\n      return Backward(backRes, cur);\r\n    }\r\n    position++;\r\n    COptimal &curOptimum = _optimum[cur];\r\n    UInt32 posPrev = curOptimum.PosPrev;\r\n    CState state;\r\n    if (curOptimum.Prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOptimum.Prev2)\r\n      {\r\n        state = _optimum[curOptimum.PosPrev2].State;\r\n        if (curOptimum.BackPrev2 < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      else\r\n        state = _optimum[posPrev].State;\r\n      state.UpdateChar();\r\n    }\r\n    else\r\n      state = _optimum[posPrev].State;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (curOptimum.IsShortRep())\r\n        state.UpdateShortRep();\r\n      else\r\n        state.UpdateChar();\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      if (curOptimum.Prev1IsChar && curOptimum.Prev2)\r\n      {\r\n        posPrev = curOptimum.PosPrev2;\r\n        pos = curOptimum.BackPrev2;\r\n        state.UpdateRep();\r\n      }\r\n      else\r\n      {\r\n        pos = curOptimum.BackPrev;\r\n        if (pos < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      const COptimal &prevOptimum = _optimum[posPrev];\r\n      if (pos < kNumRepDistances)\r\n      {\r\n        reps[0] = prevOptimum.Backs[pos];\r\n        UInt32 i;\r\n        for(i = 1; i <= pos; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n        for(; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i];\r\n      }\r\n      else\r\n      {\r\n        reps[0] = (pos - kNumRepDistances);\r\n        for(UInt32 i = 1; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n      }\r\n    }\r\n    curOptimum.State = state;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n      curOptimum.Backs[i] = reps[i];\r\n    UInt32 curPrice = curOptimum.Price; \r\n    const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n    const Byte currentByte = *data;\r\n    const Byte matchByte = *(data - (reps[0] + 1));\r\n\r\n    UInt32 posState = (position & _posStateMask);\r\n\r\n    UInt32 curAnd1Price = curPrice +\r\n        _isMatch[state.Index][posState].GetPrice0() +\r\n        _literalEncoder.GetSubCoder(position, *(data - 1))->GetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n    COptimal &nextOptimum = _optimum[cur + 1];\r\n\r\n    bool nextIsChar = false;\r\n    if (curAnd1Price < nextOptimum.Price) \r\n    {\r\n      nextOptimum.Price = curAnd1Price;\r\n      nextOptimum.PosPrev = cur;\r\n      nextOptimum.MakeAsChar();\r\n      nextIsChar = true;\r\n    }\r\n\r\n    UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();\r\n    UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n    \r\n    if(matchByte == currentByte &&\r\n        !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n      if(shortRepPrice <= nextOptimum.Price)\r\n      {\r\n        nextOptimum.Price = shortRepPrice;\r\n        nextOptimum.PosPrev = cur;\r\n        nextOptimum.MakeAsShortRep();\r\n        nextIsChar = true;\r\n      }\r\n    }\r\n    /*\r\n    if(newLen == 2 && matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n      continue;\r\n    */\r\n\r\n    numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n    UInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n    if (numAvailableBytes < 2)\r\n      continue;\r\n    if (numAvailableBytes > _numFastBytes)\r\n      numAvailableBytes = _numFastBytes;\r\n    if (!nextIsChar && matchByte != currentByte) // speed optimization\r\n    {\r\n      // try Literal + rep0\r\n      const Byte *data2 = data - (reps[0] + 1);\r\n      UInt32 limit = MyMin(numAvailableBytesFull, _numFastBytes + 1);\r\n      UInt32 temp;\r\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r\n      UInt32 lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        CState state2 = state;\r\n        state2.UpdateChar();\r\n        UInt32 posStateNext = (position + 1) & _posStateMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price + \r\n            _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n            _isRep[state2.Index].GetPrice1();\r\n        // for (; lenTest2 >= 2; lenTest2--)\r\n        {\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while(lenEnd < offset)\r\n            _optimum[++lenEnd].Price = kIfinityPrice;\r\n          UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n              0, lenTest2, state2, posStateNext);\r\n          COptimal &optimum = _optimum[offset];\r\n          if (curAndLenPrice < optimum.Price) \r\n          {\r\n            optimum.Price = curAndLenPrice;\r\n            optimum.PosPrev = cur + 1;\r\n            optimum.BackPrev = 0;\r\n            optimum.Prev1IsChar = true;\r\n            optimum.Prev2 = false;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    UInt32 startLen = 2; // speed optimization \r\n    for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)\r\n    {\r\n      // UInt32 repLen = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n      const Byte *data2 = data - (reps[repIndex] + 1);\r\n      if (data[0] != data2[0] || data[1] != data2[1])\r\n        continue;\r\n      UInt32 lenTest;\r\n      for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);\r\n      while(lenEnd < cur + lenTest)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n      UInt32 lenTestTemp = lenTest;\r\n      UInt32 price = repMatchPrice + GetPureRepPrice(repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = repIndex;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n      }\r\n      while(--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      // if (_maxMode)\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateRep();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = \r\n                price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState) + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice(\r\n                true, data2[lenTest], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextRepMatchPrice = curAndLenCharPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n                _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while(lenEnd < offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    \r\n    //    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n    if (newLen > numAvailableBytes)\r\n    {\r\n      newLen = numAvailableBytes;\r\n      for (numDistancePairs = 0; newLen > matchDistances[numDistancePairs]; numDistancePairs += 2);\r\n      matchDistances[numDistancePairs] = newLen;\r\n      numDistancePairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n      while(lenEnd < cur + newLen)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n      UInt32 offs = 0;\r\n      while(startLen > matchDistances[offs])\r\n        offs += 2;\r\n      UInt32 curBack = matchDistances[offs + 1];\r\n      UInt32 posSlot = GetPosSlot2(curBack);\r\n      for(UInt32 lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice;\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += _distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += _posSlotPrices[lenToPosState][posSlot] + _alignPrices[curBack & kAlignMask];\r\n  \r\n        curAndLenPrice += _lenEncoder.GetPrice(lenTest - kMatchMinLen, posState);\r\n        \r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = curBack + kNumRepDistances;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matchDistances[offs])\r\n        {\r\n          // Try Match + Literal + Rep0\r\n          const Byte *data2 = data - (curBack + 1);\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateMatch();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice( \r\n                true, data2[lenTest], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (posStateNext + 1) & _posStateMask;\r\n            UInt32 nextRepMatchPrice = curAndLenCharPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n                _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while(lenEnd < offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = curBack + kNumRepDistances;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numDistancePairs)\r\n            break;\r\n          curBack = matchDistances[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            posSlot = GetPosSlot2(curBack);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n{\r\n  return ((bigDist >> 7) > smallDist);\r\n}\r\n\r\nUInt32 CEncoder::ReadMatchDistances(UInt32 &numDistancePairs)\r\n{\r\n  UInt32 lenRes = 0;\r\n  numDistancePairs = _matchFinder.GetMatches(_matchFinderObj, _matchDistances);\r\n  #ifdef SHOW_STAT\r\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numDistancePairs / 2);\r\n  if (ttt >= 61994)\r\n    ttt = ttt;\r\n\r\n  ttt++;\r\n  for (UInt32 i = 0; i < numDistancePairs; i += 2)\r\n    printf(\"%2d %6d   | \", _matchDistances[i], _matchDistances[i + 1]);\r\n  #endif\r\n  if (numDistancePairs > 0)\r\n  {\r\n    lenRes = _matchDistances[numDistancePairs - 2];\r\n    if (lenRes == _numFastBytes)\r\n    {\r\n      UInt32 numAvail = _matchFinder.GetNumAvailableBytes(_matchFinderObj) + 1;\r\n      const Byte *pby = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n      UInt32 distance = _matchDistances[numDistancePairs - 1] + 1;\r\n      if (numAvail > kMatchMaxLen)\r\n        numAvail = kMatchMaxLen;\r\n\r\n      const Byte *pby2 = pby - distance;\r\n      for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r\n    }\r\n  }\r\n  _additionalOffset++;\r\n  return lenRes;\r\n}\r\n\r\nUInt32 CEncoder::GetOptimumFast(UInt32 &backRes)\r\n{\r\n  UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n  UInt32 lenMain, numDistancePairs;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    lenMain = ReadMatchDistances(numDistancePairs);\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    numDistancePairs = _numDistancePairs;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n  const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n  if (numAvailableBytes > kMatchMaxLen)\r\n    numAvailableBytes = kMatchMaxLen;\r\n  if (numAvailableBytes < 2)\r\n  {\r\n    backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n\r\n  for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    const Byte *data2 = data - (_repDistances[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    UInt32 len;\r\n    for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);\r\n    if(len >= _numFastBytes)\r\n    {\r\n      backRes = i;\r\n      MovePos(len - 1);\r\n      return len;\r\n    }\r\n    repLens[i] = len;\r\n    if (len > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  UInt32 *matchDistances = _matchDistances;\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; \r\n    MovePos(lenMain - 1);\r\n    return lenMain;\r\n  }\r\n\r\n  UInt32 backMain = 0; // for GCC\r\n  if (lenMain >= 2)\r\n  {\r\n    backMain = matchDistances[numDistancePairs - 1];\r\n    while (numDistancePairs > 2 && lenMain == matchDistances[numDistancePairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matchDistances[numDistancePairs - 3], backMain))\r\n        break;\r\n      numDistancePairs -= 2;\r\n      lenMain = matchDistances[numDistancePairs - 2];\r\n      backMain = matchDistances[numDistancePairs - 1];\r\n    }\r\n    if (lenMain == 2 && backMain >= 0x80)\r\n      lenMain = 1;\r\n  }\r\n\r\n  if (repLens[repMaxIndex] >= 2)\r\n  {\r\n    if (repLens[repMaxIndex] + 1 >= lenMain || \r\n        repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9)) ||\r\n        repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15)))\r\n    {\r\n      backRes = repMaxIndex;\r\n      UInt32 lenRes = repLens[repMaxIndex];\r\n      MovePos(lenRes - 1);\r\n      return lenRes;\r\n    }\r\n  }\r\n  \r\n  if (lenMain >= 2 && numAvailableBytes > 2)\r\n  {\r\n    numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n    _longestMatchLength = ReadMatchDistances(_numDistancePairs);\r\n    if (_longestMatchLength >= 2)\r\n    {\r\n      UInt32 newDistance = matchDistances[_numDistancePairs - 1];\r\n      if (_longestMatchLength >= lenMain && newDistance < backMain || \r\n          _longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance) ||\r\n          _longestMatchLength > lenMain + 1 ||\r\n          _longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain))\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        return 1;\r\n      }\r\n    }\r\n    data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n    {\r\n      const Byte *data2 = data - (_repDistances[i] + 1);\r\n      if (data[1] != data2[1] || data[2] != data2[2])\r\n      {\r\n        repLens[i] = 0;\r\n        continue;\r\n      }\r\n      UInt32 len;\r\n      for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);\r\n      if (len + 1 >= lenMain)\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        return 1;\r\n      }\r\n    }\r\n    backRes = backMain + kNumRepDistances; \r\n    MovePos(lenMain - 2);\r\n    return lenMain;\r\n  }\r\n  backRes = UInt32(-1);\r\n  return 1;\r\n}\r\n\r\nHRESULT CEncoder::Flush(UInt32 nowPos)\r\n{\r\n  // ReleaseMFStream();\r\n  if (_matchFinderBase.result != SZ_OK)\r\n    return _matchFinderBase.result;\r\n  WriteEndMarker(nowPos & _posStateMask);\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nvoid CEncoder::WriteEndMarker(UInt32 posState)\r\n{\r\n  // This function for writing End Mark for stream version of LZMA. \r\n  // In current version this feature is not used.\r\n  if (!_writeEndMark)\r\n    return;\r\n\r\n  _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n  _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n  _state.UpdateMatch();\r\n  UInt32 len = kMatchMinLen; // kMatchMaxLen;\r\n  _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n  UInt32 posSlot = (1 << kNumPosSlotBits)  - 1;\r\n  UInt32 lenToPosState = GetLenToPosState(len);\r\n  _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n  UInt32 footerBits = 30;\r\n  UInt32 posReduced = (UInt32(1) << footerBits) - 1;\r\n  _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n  _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n}\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  // _needReleaseMFStream = false;\r\n  #ifdef COMPRESS_MF_MT\r\n  #ifdef USE_ALLOCA\r\n  alloca(0x300);\r\n  #endif\r\n  #endif\r\n  CCoderReleaser coderReleaser(this);\r\n  RINOK(SetStreams(inStream, outStream, inSize, outSize));\r\n  for (;;)\r\n  {\r\n    UInt64 processedInSize;\r\n    UInt64 processedOutSize;\r\n    Int32 finished;\r\n    RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished));\r\n    if (finished != 0)\r\n      break;\r\n    if (progress != 0)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  _inStream = inStream;\r\n  _finished = false;\r\n  RINOK(Create());\r\n  RINOK(SetOutStream(outStream));\r\n  RINOK(Init());\r\n  \r\n  if (!_fastMode)\r\n  {\r\n    FillDistancesPrices();\r\n    FillAlignPrices();\r\n  }\r\n\r\n  _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _lenEncoder.UpdateTables(1 << _posStateBits);\r\n  _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n  nowPos64 = 0;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRes MyRead(void *object, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return (HRes)((CSeqInStream *)object)->RealStream->Read(data, size, processedSize);\r\n}\r\n\r\nHRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)\r\n{\r\n  if (_inStream != 0)\r\n  {\r\n    _seqInStream.RealStream = _inStream;\r\n    _seqInStream.SeqInStream.Read = MyRead;\r\n    _matchFinderBase.stream = &_seqInStream.SeqInStream;\r\n    _matchFinder.Init(_matchFinderObj);\r\n    _needReleaseMFStream = true;\r\n    _inStream = 0;\r\n  }\r\n\r\n\r\n  *finished = 1;\r\n  if (_finished)\r\n    return _matchFinderBase.result;\r\n  _finished = true;\r\n\r\n  if (nowPos64 == 0)\r\n  {\r\n    if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)\r\n      return Flush((UInt32)nowPos64);\r\n    UInt32 len, numDistancePairs;\r\n    len = ReadMatchDistances(numDistancePairs);\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n    _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n    _state.UpdateChar();\r\n    Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset);\r\n    _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte);\r\n    _previousByte = curByte;\r\n    _additionalOffset--;\r\n    nowPos64++;\r\n  }\r\n\r\n  UInt32 nowPos32 = (UInt32)nowPos64;\r\n  UInt32 progressPosValuePrev = nowPos32;\r\n\r\n  if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)\r\n    return Flush(nowPos32);\r\n\r\n  for (;;)\r\n  {\r\n    #ifdef _NO_EXCEPTIONS\r\n    if (_rangeEncoder.Stream.ErrorCode != S_OK)\r\n      return _rangeEncoder.Stream.ErrorCode;\r\n    #endif\r\n    UInt32 pos, len;\r\n\r\n    if (_fastMode)\r\n      len = GetOptimumFast(pos);\r\n    else\r\n      len = GetOptimum(nowPos32, pos);\r\n\r\n    UInt32 posState = nowPos32 & _posStateMask;\r\n    if(len == 1 && pos == 0xFFFFFFFF)\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n      Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset);\r\n      CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(nowPos32, _previousByte);\r\n      if(_state.IsCharState())\r\n        subCoder->Encode(&_rangeEncoder, curByte);\r\n      else\r\n      {\r\n        Byte matchByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _repDistances[0] - 1 - _additionalOffset);\r\n        subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);\r\n      }\r\n      _state.UpdateChar();\r\n      _previousByte = curByte;\r\n    }\r\n    else\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n      if(pos < kNumRepDistances)\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 1);\r\n        if(pos == 0)\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 0);\r\n          _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = _repDistances[pos];\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 1);\r\n          if (pos == 1)\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 0);\r\n          else\r\n          {\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 1);\r\n            _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);\r\n            if (pos == 3)\r\n              _repDistances[3] = _repDistances[2];\r\n            _repDistances[2] = _repDistances[1];\r\n          }\r\n          _repDistances[1] = _repDistances[0];\r\n          _repDistances[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          _state.UpdateShortRep();\r\n        else\r\n        {\r\n          _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n          _state.UpdateRep();\r\n        }\r\n      }\r\n      else\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n        _state.UpdateMatch();\r\n        _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n        pos -= kNumRepDistances;\r\n        UInt32 posSlot = GetPosSlot(pos);\r\n        _posSlotEncoder[GetLenToPosState(len)].Encode(&_rangeEncoder, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1, \r\n                &_rangeEncoder, footerBits, posReduced);\r\n          else\r\n          {\r\n            _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n            _alignPriceCount++;\r\n          }\r\n        }\r\n        _repDistances[3] = _repDistances[2];\r\n        _repDistances[2] = _repDistances[1];\r\n        _repDistances[1] = _repDistances[0];\r\n        _repDistances[0] = pos;\r\n        _matchPriceCount++;\r\n      }\r\n      _previousByte = _matchFinder.GetIndexByte(_matchFinderObj, len - 1 - _additionalOffset);\r\n    }\r\n    _additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (_additionalOffset == 0)\r\n    {\r\n      if (!_fastMode)\r\n      {\r\n        if (_matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices();\r\n        if (_alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices();\r\n      }\r\n      if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)\r\n        return Flush(nowPos32);\r\n      if (nowPos32 - progressPosValuePrev >= (1 << 14))\r\n      {\r\n        nowPos64 += nowPos32 - progressPosValuePrev;\r\n        *inSize = nowPos64;\r\n        *outSize = _rangeEncoder.GetProcessedSize();\r\n        _finished = false;\r\n        *finished = 0;\r\n        return _matchFinderBase.result;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try \r\n  { \r\n  #endif\r\n    return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  #ifndef _NO_EXCEPTIONS\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return E_FAIL; }\r\n  #endif\r\n}\r\n  \r\nvoid CEncoder::FillDistancesPrices()\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  for (UInt32 i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  { \r\n    UInt32 posSlot = GetPosSlot(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = NRangeCoder::ReverseBitTreeGetPrice(_posEncoders + \r\n      base - posSlot - 1, footerBits, i - base);\r\n  }\r\n\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n    UInt32 posSlot;\r\n    NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> &encoder = _posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = _posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = encoder.GetPrice(posSlot);\r\n    for (posSlot = kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);\r\n\r\n    UInt32 *distancesPrices = _distancesPrices[lenToPosState];\r\n    UInt32 i;\r\n    for (i = 0; i < kStartPosModelIndex; i++)\r\n      distancesPrices[i] = posSlotPrices[i];\r\n    for (; i < kNumFullDistances; i++)\r\n      distancesPrices[i] = posSlotPrices[GetPosSlot(i)] + tempPrices[i];\r\n  }\r\n  _matchPriceCount = 0;\r\n}\r\n\r\nvoid CEncoder::FillAlignPrices()\r\n{\r\n  for (UInt32 i = 0; i < kAlignTableSize; i++)\r\n    _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n  _alignPriceCount = 0;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.h",
    "content": "// LZMA/Encoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/Alloc.h\"\r\n  #include \"../../../../C/Compress/Lz/MatchFinder.h\"\r\n  #ifdef COMPRESS_MF_MT\r\n  #include \"../../../../C/Compress/Lz/MatchFinderMt.h\"\r\n  #endif\r\n}\r\n\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;\r\n\r\nclass CBaseState\r\n{\r\nprotected:\r\n  CState _state;\r\n  Byte _previousByte;\r\n  UInt32 _repDistances[kNumRepDistances];\r\n  void Init()\r\n  {\r\n    _state.Init();\r\n    _previousByte = 0;\r\n    for(UInt32 i = 0 ; i < kNumRepDistances; i++)\r\n      _repDistances[i] = 0;\r\n  }\r\n};\r\n\r\nstruct COptimal\r\n{\r\n  CState State;\r\n\r\n  bool Prev1IsChar;\r\n  bool Prev2;\r\n\r\n  UInt32 PosPrev2;\r\n  UInt32 BackPrev2;     \r\n\r\n  UInt32 Price;    \r\n  UInt32 PosPrev;         // posNext;\r\n  UInt32 BackPrev;     \r\n  UInt32 Backs[kNumRepDistances];\r\n  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }\r\n  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n  bool IsShortRep() { return (BackPrev == 0); }\r\n};\r\n\r\n\r\n// #define LZMA_LOG_BRANCH\r\n\r\n#if _MSC_VER >= 1400\r\n// Must give gain in core 2. but slower ~2% on k8.\r\n// #define LZMA_LOG_BSR\r\n#endif\r\n\r\n#ifndef LZMA_LOG_BSR\r\nstatic const int kNumLogBits = 13; // don't change it !\r\nextern Byte g_FastPos[];\r\n#endif\r\ninline UInt32 GetPosSlot(UInt32 pos)\r\n{\r\n  #ifdef LZMA_LOG_BSR\r\n  if (pos < 2)\r\n    return pos;\r\n  unsigned long index;\r\n  _BitScanReverse(&index, pos);\r\n  return (index + index) + ((pos >> (index - 1)) & 1);\r\n  #else\r\n  if (pos < (1 << kNumLogBits))\r\n    return g_FastPos[pos];\r\n  if (pos < (1 << (kNumLogBits * 2 - 1)))\r\n    return g_FastPos[pos >> (kNumLogBits - 1)] + (kNumLogBits - 1) * 2;\r\n  return g_FastPos[pos >> (kNumLogBits - 1) * 2] + (kNumLogBits - 1) * 4;\r\n  #endif\r\n}\r\n\r\ninline UInt32 GetPosSlot2(UInt32 pos)\r\n{\r\n  #ifdef LZMA_LOG_BSR\r\n  unsigned long index;\r\n  _BitScanReverse(&index, pos);\r\n  return (index + index) + ((pos >> (index - 1)) & 1);\r\n  #else\r\n  #ifdef LZMA_LOG_BRANCH\r\n  if (pos < (1 << (kNumLogBits + 6)))\r\n    return g_FastPos[pos >> 6] + 12;\r\n  if (pos < (1 << (kNumLogBits * 2 + 5)))\r\n    return g_FastPos[pos >> (kNumLogBits + 5)] + (kNumLogBits + 5) * 2;\r\n  return g_FastPos[pos >> (kNumLogBits * 2 + 4)] + (kNumLogBits * 2 + 4) * 2;\r\n  #else\r\n  // it's faster with VC6-32bit.\r\n  UInt32 s = 6 + ((kNumLogBits - 1) & (UInt32)((Int32)(((1 << (kNumLogBits + 6)) - 1) -  pos) >> 31));\r\n  return g_FastPos[pos >> s] + (s * 2);\r\n  #endif\r\n  #endif\r\n}\r\n\r\nconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\nconst UInt32 kNumOpts = 1 << 12;\r\n\r\n\r\nclass CLiteralEncoder2\r\n{\r\n  CMyBitEncoder _encoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _encoders[i].Init();\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);\r\n  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;\r\n};\r\n\r\nclass CLiteralEncoder\r\n{\r\n  CLiteralEncoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralEncoder(): _coders(0) {}\r\n  ~CLiteralEncoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)\r\n    { return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CEncoder\r\n{\r\n  CMyBitEncoder _choice;\r\n  CMyBitEncoder _choice2;\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;\r\npublic:\r\n  void Init(UInt32 numPosStates);\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);\r\n  void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;\r\n};\r\n\r\nconst UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\r\n\r\nclass CPriceTableEncoder: public CEncoder\r\n{\r\n  UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];\r\n  UInt32 _tableSize;\r\n  UInt32 _counters[kNumPosStatesEncodingMax];\r\npublic:\r\n  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }\r\n  void UpdateTable(UInt32 posState)\r\n  {\r\n    SetPrices(posState, _tableSize, _prices[posState]);\r\n    _counters[posState] = _tableSize;\r\n  }\r\n  void UpdateTables(UInt32 numPosStates)\r\n  {\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n      UpdateTable(posState);\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)\r\n  {\r\n    CEncoder::Encode(rangeEncoder, symbol, posState);\r\n    if (updatePrice)\r\n      if (--_counters[posState] == 0)\r\n        UpdateTable(posState);\r\n  }\r\n};\r\n\r\n}\r\n\r\ntypedef struct _CSeqInStream\r\n{\r\n  ISeqInStream SeqInStream;\r\n  CMyComPtr<ISequentialInStream> RealStream;\r\n} CSeqInStream;\r\n\r\n\r\nclass CEncoder : \r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CBaseState,\r\n  public CMyUnknownImp\r\n{\r\n  NRangeCoder::CEncoder _rangeEncoder;\r\n\r\n  IMatchFinder _matchFinder;\r\n  void *_matchFinderObj;\r\n  \r\n  #ifdef COMPRESS_MF_MT\r\n  Bool _multiThread;\r\n  Bool _mtMode;\r\n  CMatchFinderMt _matchFinderMt;\r\n  #endif\r\n\r\n  CMatchFinder _matchFinderBase;\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte _pad1[kMtCacheLineDummy];\r\n  #endif\r\n\r\n  COptimal _optimum[kNumOpts];\r\n\r\n  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n  CMyBitEncoder _isRep[kNumStates];\r\n  CMyBitEncoder _isRepG0[kNumStates];\r\n  CMyBitEncoder _isRepG1[kNumStates];\r\n  CMyBitEncoder _isRepG2[kNumStates];\r\n  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];\r\n\r\n  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;\r\n  \r\n  NLength::CPriceTableEncoder _lenEncoder;\r\n  NLength::CPriceTableEncoder _repMatchLenEncoder;\r\n\r\n  CLiteralEncoder _literalEncoder;\r\n\r\n  UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];\r\n\r\n  bool _fastMode;\r\n  // bool _maxMode;\r\n  UInt32 _numFastBytes;\r\n  UInt32 _longestMatchLength;    \r\n  UInt32 _numDistancePairs;\r\n\r\n  UInt32 _additionalOffset;\r\n\r\n  UInt32 _optimumEndIndex;\r\n  UInt32 _optimumCurrentIndex;\r\n\r\n  bool _longestMatchWasFound;\r\n\r\n  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  \r\n  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n\r\n  UInt32 _alignPrices[kAlignTableSize];\r\n  UInt32 _alignPriceCount;\r\n\r\n  UInt32 _distTableSize;\r\n\r\n  UInt32 _posStateBits;\r\n  UInt32 _posStateMask;\r\n  UInt32 _numLiteralPosStateBits;\r\n  UInt32 _numLiteralContextBits;\r\n\r\n  UInt32 _dictionarySize;\r\n\r\n  UInt32 _matchPriceCount;\r\n  UInt64 nowPos64;\r\n  bool _finished;\r\n  ISequentialInStream *_inStream;\r\n\r\n  CSeqInStream _seqInStream;\r\n\r\n  UInt32 _matchFinderCycles;\r\n  // int _numSkip\r\n\r\n  bool _writeEndMark;\r\n\r\n  bool _needReleaseMFStream;\r\n\r\n  void ReleaseMatchFinder()\r\n  {\r\n    _matchFinder.Init = 0;\r\n    _seqInStream.RealStream.Release();\r\n  }\r\n\r\n  void ReleaseMFStream()\r\n  {\r\n    if (_matchFinderObj && _needReleaseMFStream)\r\n    {\r\n      #ifdef COMPRESS_MF_MT\r\n      if (_mtMode)\r\n        MatchFinderMt_ReleaseStream(&_matchFinderMt);\r\n      #endif\r\n      _needReleaseMFStream = false;\r\n    }\r\n    _seqInStream.RealStream.Release();\r\n  }\r\n  \r\n  UInt32 ReadMatchDistances(UInt32 &numDistancePairs);\r\n\r\n  void MovePos(UInt32 num);\r\n  UInt32 GetRepLen1Price(CState state, UInt32 posState) const\r\n  {\r\n    return _isRepG0[state.Index].GetPrice0() +\r\n        _isRep0Long[state.Index][posState].GetPrice0();\r\n  }\r\n  \r\n  UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    if(repIndex == 0)\r\n    {\r\n      price = _isRepG0[state.Index].GetPrice0();\r\n      price += _isRep0Long[state.Index][posState].GetPrice1();\r\n    }\r\n    else\r\n    {\r\n      price = _isRepG0[state.Index].GetPrice1();\r\n      if (repIndex == 1)\r\n        price += _isRepG1[state.Index].GetPrice0();\r\n      else\r\n      {\r\n        price += _isRepG1[state.Index].GetPrice1();\r\n        price += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n      }\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const\r\n  {\r\n    return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +\r\n        GetPureRepPrice(repIndex, state, posState);\r\n  }\r\n  /*\r\n  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const\r\n  {\r\n    if (pos >= kNumFullDistances)\r\n      return kIfinityPrice;\r\n    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);\r\n  }\r\n  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n  */\r\n  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n\r\n  UInt32 Backward(UInt32 &backRes, UInt32 cur);\r\n  UInt32 GetOptimum(UInt32 position, UInt32 &backRes);\r\n  UInt32 GetOptimumFast(UInt32 &backRes);\r\n\r\n  void FillDistancesPrices();\r\n  void FillAlignPrices();\r\n    \r\n  void ReleaseStreams()\r\n  {\r\n    ReleaseMFStream();\r\n    ReleaseOutStream();\r\n  }\r\n\r\n  HRESULT Flush(UInt32 nowPos);\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() { _coder->ReleaseStreams(); }\r\n  };\r\n  friend class CCoderReleaser;\r\n\r\n  void WriteEndMarker(UInt32 posState);\r\n\r\npublic:\r\n  CEncoder();\r\n  void SetWriteEndMarkerMode(bool writeEndMarker)\r\n    { _writeEndMark= writeEndMarker; }\r\n\r\n  HRESULT Create();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  HRESULT Init();\r\n  \r\n  // ICompressCoder interface\r\n  HRESULT SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize);\r\n  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);\r\n\r\n  HRESULT CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressCoder interface\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressSetCoderProperties2\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  \r\n  // ICompressWriteCoderProperties\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA/LZMARegister.cpp",
    "content": "// LZMARegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLZMA::CDecoder); }\r\n#ifndef EXTRACT_ONLY\r\n#include \"LZMAEncoder.h\"\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLZMA::CEncoder);  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x030101, L\"LZMA\", 1, false };\r\n\r\nREGISTER_CODEC(LZMA)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /FAcs /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"C-Lz\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lzma\\LzmaDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lzma\\LzmaDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lzma\\LzmaTypes.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#include \"LzmaBenchCon.h\"\r\n#include \"LzmaRam.h\"\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"LzmaRamDecode.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kMode,\r\n  kDictionary,\r\n  kFastBytes,\r\n  kMatchFinderCycles,\r\n  kLitContext,\r\n  kLitPos,\r\n  kPosBits,\r\n  kMatchFinder,\r\n  kMultiThread,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MT\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kPostChar, false, 0, 0, L\"+\" }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\"\r\n    \"  -d{N}:  set dictionary - [0,30], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -mc{N}: set number of cycles for match finder\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\\n\"\r\n    \"  -mt{N}: set number of CPU threads\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[], \r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);\r\n  if (unsupportedTypes)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }   \r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++]; \r\n\r\n  bool dictionaryIsDefined = false;\r\n  UInt32 dictionary = (UInt32)-1;\r\n  if(parser[NKey::kDictionary].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dictionary = 1 << dicLog;\r\n    dictionaryIsDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  UInt32 numThreads = (UInt32)-1;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (parser[NKey::kMultiThread].ThereIs)\r\n  {\r\n    UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n    const UString &s = parser[NKey::kMultiThread].PostStrings[0];\r\n    if (s.IsEmpty())\r\n      numThreads = numCPUs;\r\n    else\r\n      if (!GetNumber(s, numThreads))\r\n        IncorrectCommand();\r\n  }\r\n  #endif\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 1;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchCon(stderr, numIterations, numThreads, dictionary);\r\n  }\r\n\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = 1;\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++]; \r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\", \r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  COutFileStream *outStreamSpec = NULL;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++]; \r\n    outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\", \r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    UInt32 inSize = (UInt32)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize); \r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)\r\n      throw \"Can not read\";\r\n    if ((UInt32)inSize != processedSize)\r\n      throw \"Read size error\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSizeProcessed;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictionaryIsDefined)\r\n        dictionary = 1 << 23;\r\n      int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, \r\n          dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      size_t outSize;\r\n      if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)\r\n        throw \"data error\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictionaryIsDefined)\r\n      dictionary = 1 << 23;\r\n\r\n    UInt32 posStateBits = 2;\r\n    UInt32 litContextBits = 3; // for normal files\r\n    // UInt32 litContextBits = 0; // for 32-bit data\r\n    UInt32 litPosBits = 0;\r\n    // UInt32 litPosBits = 2; // for 32-bit data\r\n    UInt32 algorithm = 1;\r\n    UInt32 numFastBytes = 128;\r\n    UInt32 matchFinderCycles = 16 + numFastBytes / 2;\r\n    bool matchFinderCyclesDefined = false;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    if(parser[NKey::kMode].ThereIs)\r\n      if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))\r\n        IncorrectCommand();\r\n\r\n    if(parser[NKey::kFastBytes].ThereIs)\r\n      if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))\r\n        IncorrectCommand();\r\n    matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs;\r\n    if (matchFinderCyclesDefined)\r\n      if (!GetNumber(parser[NKey::kMatchFinderCycles].PostStrings[0], matchFinderCycles))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitContext].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitPos].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kPosBits].ThereIs)\r\n      if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))\r\n        IncorrectCommand();\r\n\r\n    PROPID propIDs[] = \r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker,\r\n      NCoderPropID::kNumThreads,\r\n      NCoderPropID::kMatchFinderCycles,\r\n    };\r\n    const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\r\n    PROPVARIANT properties[kNumPropsMax];\r\n    for (int p = 0; p < 6; p++)\r\n      properties[p].vt = VT_UI4;\r\n\r\n    properties[0].ulVal = (UInt32)dictionary;\r\n    properties[1].ulVal = (UInt32)posStateBits;\r\n    properties[2].ulVal = (UInt32)litContextBits;\r\n    properties[3].ulVal = (UInt32)litPosBits;\r\n    properties[4].ulVal = (UInt32)algorithm;\r\n    properties[5].ulVal = (UInt32)numFastBytes;\r\n\r\n    properties[6].vt = VT_BSTR;\r\n    properties[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    properties[7].vt = VT_BOOL;\r\n    properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    properties[8].vt = VT_UI4;\r\n    properties[8].ulVal = (UInt32)numThreads;\r\n\r\n    // it must be last in property list\r\n    properties[9].vt = VT_UI4;\r\n    properties[9].ulVal = (UInt32)matchFinderCycles;\r\n\r\n    int numProps = kNumPropsMax;\r\n    if (!matchFinderCyclesDefined)\r\n      numProps--;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }   \r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }   \r\n  }\r\n  else\r\n  {\r\n    NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte properties[kPropertiesSize];\r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, properties, kPropertiesSize, &processedSize) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (processedSize != kPropertiesSize)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b;\r\n      if (inStream->Read(&b, 1, &processedSize) != S_OK)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      if (processedSize != 1)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      fileSize |= ((UInt64)b) << (8 * i);\r\n    }\r\n    if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }   \r\n  }\r\n  if (outStreamSpec != NULL)\r\n  {\r\n    if (outStreamSpec->Close() != S_OK)\r\n    {\r\n      fprintf(stderr, \"File closing error\");\r\n      return 1;\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n\r\nint main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s) \r\n  { \r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1; \r\n  }\r\n  catch(...) \r\n  { \r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1; \r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#define USE_POSIX_TIME\r\n#define USE_POSIX_TIME2\r\n#endif\r\n\r\n#ifdef USE_POSIX_TIME\r\n#include <time.h>\r\n#ifdef USE_POSIX_TIME2\r\n#include <sys/time.h>\r\n#endif\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef BENCH_MT\r\n#include \"../../../Windows/Thread.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#endif\r\n\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../../Windows/PropVariant.h\"\r\n#else\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#endif\r\n\r\nstatic const UInt32 kUncompressMinBlockSize = 1 << 26;\r\nstatic const UInt32 kAdditionalSize = (1 << 16);\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 5;\r\n\r\nclass CBaseRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CBaseRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd() \r\n  {\r\n    return \r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBenchBuffer\r\n{\r\npublic:\r\n  size_t BufferSize;\r\n  Byte *Buffer;\r\n  CBenchBuffer(): Buffer(0) {} \r\n  virtual ~CBenchBuffer() { Free(); }\r\n  void Free() \r\n  { \r\n    ::MidFree(Buffer);\r\n    Buffer = 0;\r\n  }\r\n  bool Alloc(size_t bufferSize) \r\n  {\r\n    if (Buffer != 0 && BufferSize == bufferSize)\r\n      return true;\r\n    Free();\r\n    Buffer = (Byte *)::MidAlloc(bufferSize);\r\n    BufferSize = bufferSize;\r\n    return (Buffer != 0);\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator: public CBenchBuffer\r\n{\r\n  CBaseRandomGenerator *RG;\r\npublic:\r\n  void Set(CBaseRandomGenerator *rg) { RG = rg; }\r\n  UInt32 GetVal(UInt32 &res, int numBits) \r\n  {\r\n    UInt32 val = res & (((UInt32)1 << numBits) - 1);\r\n    res >>= numBits;\r\n    return val;\r\n  }\r\n  UInt32 GetLen(UInt32 &res) \r\n  { \r\n    UInt32 len = GetVal(res, 2);\r\n    return GetVal(res, 1 + len);\r\n  }\r\n  void Generate()\r\n  {\r\n    UInt32 pos = 0;\r\n    UInt32 rep0 = 1;\r\n    while (pos < BufferSize)\r\n    {\r\n      UInt32 res = RG->GetRnd();\r\n      res >>= 1;\r\n      if (GetVal(res, 1) == 0 || pos < 1024)\r\n        Buffer[pos++] = (Byte)(res & 0xFF);\r\n      else\r\n      {\r\n        UInt32 len;\r\n        len = 1 + GetLen(res);\r\n        if (GetVal(res, 3) != 0)\r\n        {\r\n          len += GetLen(res);\r\n          do\r\n          {\r\n            UInt32 ppp = GetVal(res, 5) + 6;\r\n            res = RG->GetRnd();\r\n            if (ppp > 30)\r\n              continue;\r\n            rep0 = /* (1 << ppp) +*/  GetVal(res, ppp);\r\n            res = RG->GetRnd();\r\n          }\r\n          while (rep0 >= pos);\r\n          rep0++;\r\n        }\r\n\r\n        for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)\r\n          Buffer[pos] = Buffer[pos - rep0];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\n\r\nclass CBenchmarkInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Pos;\r\n  size_t Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t remain = Size - Pos;\r\n  UInt32 kMaxBlockSize = (1 << 20);\r\n  if (size > kMaxBlockSize)\r\n    size = kMaxBlockSize;\r\n  if (size > remain)\r\n    size = (UInt32)remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream: \r\n  public ISequentialOutStream,\r\n  public CBenchBuffer,\r\n  public CMyUnknownImp\r\n{\r\n  // bool _overflow;\r\npublic:\r\n  UInt32 Pos;\r\n  // CBenchmarkOutStream(): _overflow(false) {} \r\n  void Init() \r\n  {\r\n    // _overflow = false;\r\n    Pos = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t curSize = BufferSize - Pos;\r\n  if (curSize > size)\r\n    curSize = size;\r\n  memcpy(Buffer + Pos, data, curSize);\r\n  Pos += (UInt32)curSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)curSize;\r\n  if (curSize != size)\r\n  {\r\n    // _overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  UInt32 Crc;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { Crc = CRC_INIT_VAL; }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  Crc = CrcUpdate(Crc, data, size);\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  timeval v;\r\n  if (gettimeofday(&v, 0) == 0)\r\n    return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;\r\n  return (UInt64)time(NULL) * 1000000;\r\n  #else\r\n  return time(NULL);\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return GetTickCount();\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  return 1000000;\r\n  #else\r\n  return 1;\r\n  #endif \r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return 1000;\r\n  #endif \r\n}\r\n\r\n#ifndef USE_POSIX_TIME\r\nstatic inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }\r\n#endif\r\nstatic UInt64 GetUserTime()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return clock();\r\n  #else\r\n  FILETIME creationTime, exitTime, kernelTime, userTime;\r\n  if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)\r\n    return GetTime64(userTime) + GetTime64(kernelTime);\r\n  return (UInt64)GetTickCount() * 10000;\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetUserFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return CLOCKS_PER_SEC;\r\n  #else\r\n  return 10000000;\r\n  #endif \r\n}\r\n\r\nclass CBenchProgressStatus\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::NSynchronization::CCriticalSection CS;  \r\n  #endif\r\npublic:\r\n  HRESULT Res;\r\n  bool EncodeMode;\r\n  void SetResult(HRESULT res) \r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    Res = res;\r\n  }\r\n  HRESULT GetResult()\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    return Res;\r\n  }\r\n};\r\n\r\nclass CBenchProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CBenchProgressStatus *Status;\r\n  CBenchInfo BenchInfo;\r\n  HRESULT Res;\r\n  IBenchCallback *callback;\r\n  CBenchProgressInfo(): callback(0) {}\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nvoid SetStartTime(CBenchInfo &bi)\r\n{\r\n  bi.GlobalFreq = GetFreq();\r\n  bi.UserFreq = GetUserFreq();\r\n  bi.GlobalTime = ::GetTimeCount();\r\n  bi.UserTime = ::GetUserTime();\r\n}\r\n\r\nvoid SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)\r\n{\r\n  dest.GlobalFreq = GetFreq();\r\n  dest.UserFreq = GetUserFreq();\r\n  dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;\r\n  dest.UserTime = ::GetUserTime() - biStart.UserTime;\r\n}\r\n\r\nSTDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  HRESULT res = Status->GetResult();\r\n  if (res != S_OK)\r\n    return res;\r\n  if (!callback)\r\n    return res;\r\n  CBenchInfo info = BenchInfo;\r\n  SetFinishTime(BenchInfo, info);\r\n  if (Status->EncodeMode)\r\n  {\r\n    info.UnpackSize = *inSize;\r\n    info.PackSize = *outSize;\r\n    res = callback->SetEncodeResult(info, false);\r\n  }\r\n  else\r\n  {\r\n    info.PackSize = BenchInfo.PackSize + *inSize;\r\n    info.UnpackSize = BenchInfo.UnpackSize + *outSize;\r\n    res = callback->SetDecodeResult(info, false);\r\n  }\r\n  if (res != S_OK)\r\n    Status->SetResult(res);\r\n  return res;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nUInt64 GetUsage(const CBenchInfo &info)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userTime, userFreq);\r\n  NormalizeVals(globalFreq, globalTime);\r\n  if (userFreq == 0)\r\n    userFreq = 1;\r\n  if (globalTime == 0)\r\n    globalTime = 1;\r\n  return userTime * globalFreq * 1000000 / userFreq / globalTime;\r\n}\r\n\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userFreq, userTime);\r\n  NormalizeVals(globalTime, globalFreq);\r\n  if (globalFreq == 0)\r\n    globalFreq = 1;\r\n  if (userTime == 0)\r\n    userTime = 1;\r\n  return userFreq * globalTime / globalFreq *  rating / userTime;\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)\r\n{\r\n  UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);\r\n  // UInt64 numCommandsForOne = 1000 + ((t * t * 7) >> (2 * kSubBits)); // AMD K8\r\n  UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits)); // Intel Core2\r\n\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)\r\n{\r\n  // UInt64 numCommands = (inSize * 216 + outSize * 14) * numIterations; // AMD K8\r\n  UInt64 numCommands = (inSize * 220 + outSize * 8) * numIterations; // Intel Core2\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\n#ifdef EXTERNAL_LZMA\r\ntypedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID, \r\n    const GUID *interfaceID, void **outObject);\r\n#endif\r\n\r\nstruct CEncoderInfo;\r\n\r\nstruct CEncoderInfo\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::CThread thread[2];\r\n  #endif\r\n  CMyComPtr<ICompressCoder> encoder;\r\n  CBenchProgressInfo *progressInfoSpec[2];\r\n  CMyComPtr<ICompressProgressInfo> progressInfo[2];\r\n  UInt32 NumIterations;\r\n  #ifdef USE_ALLOCA\r\n  size_t AllocaSize;\r\n  #endif\r\n\r\n  struct CDecoderInfo\r\n  {\r\n    CEncoderInfo *Encoder;\r\n    UInt32 DecoderIndex;\r\n    #ifdef USE_ALLOCA\r\n    size_t AllocaSize;\r\n    #endif\r\n    bool CallbackMode;\r\n  };\r\n  CDecoderInfo decodersInfo[2];\r\n\r\n  CMyComPtr<ICompressCoder> decoders[2];\r\n  HRESULT Results[2];\r\n  CBenchmarkOutStream *outStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  IBenchCallback *callback;\r\n  UInt32 crc;\r\n  UInt32 kBufferSize;\r\n  UInt32 compressedSize;\r\n  CBenchRandomGenerator rg;\r\n  CBenchmarkOutStream *propStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> propStream;\r\n  HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);\r\n  HRESULT Encode();\r\n  HRESULT Decode(UInt32 decoderIndex);\r\n\r\n  CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}\r\n\r\n  #ifdef BENCH_MT\r\n  static THREAD_FUNC_DECL EncodeThreadFunction(void *param)\r\n  {\r\n    CEncoderInfo *encoder = (CEncoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(encoder->AllocaSize);\r\n    #endif\r\n    HRESULT res = encoder->Encode();\r\n    encoder->Results[0] = res;\r\n    if (res != S_OK)\r\n      encoder->progressInfoSpec[0]->Status->SetResult(res);\r\n\r\n    return 0;\r\n  }\r\n  static THREAD_FUNC_DECL DecodeThreadFunction(void *param)\r\n  {\r\n    CDecoderInfo *decoder = (CDecoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(decoder->AllocaSize);\r\n    #endif\r\n    CEncoderInfo *encoder = decoder->Encoder;\r\n    encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);\r\n    return 0;\r\n  }\r\n\r\n  HRESULT CreateEncoderThread()\r\n  {\r\n    return thread[0].Create(EncodeThreadFunction, this);\r\n  }\r\n\r\n  HRESULT CreateDecoderThread(int index, bool callbackMode\r\n      #ifdef USE_ALLOCA\r\n      , size_t allocaSize\r\n      #endif\r\n      )\r\n  {\r\n    CDecoderInfo &decoder = decodersInfo[index];\r\n    decoder.DecoderIndex = index;\r\n    decoder.Encoder = this;\r\n    #ifdef USE_ALLOCA\r\n    decoder.AllocaSize = allocaSize;\r\n    #endif\r\n    decoder.CallbackMode = callbackMode;\r\n    return thread[index].Create(DecodeThreadFunction, &decoder);\r\n  }\r\n  #endif\r\n};\r\n\r\nHRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)\r\n{\r\n  rg.Set(rgLoc);\r\n  kBufferSize = dictionarySize + kAdditionalSize;\r\n  UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n  if (!rg.Alloc(kBufferSize))\r\n    return E_OUTOFMEMORY;\r\n  rg.Generate();\r\n  crc = CrcCalc(rg.Buffer, rg.BufferSize);\r\n\r\n  outStreamSpec = new CBenchmarkOutStream;\r\n  if (!outStreamSpec->Alloc(kCompressedBufferSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  outStream = outStreamSpec;\r\n\r\n  propStreamSpec = 0;\r\n  if (!propStream)\r\n  {\r\n    propStreamSpec = new CBenchmarkOutStream;\r\n    propStream = propStreamSpec;\r\n  }\r\n  if (!propStreamSpec->Alloc(kMaxLzmaPropSize))\r\n    return E_OUTOFMEMORY;\r\n  propStreamSpec->Init();\r\n  \r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kDictionarySize, \r\n    NCoderPropID::kMultiThread\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)dictionarySize;\r\n\r\n  properties[1].vt = VT_BOOL;\r\n  properties[1].boolVal = (numThreads > 1) ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n  {\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));\r\n    if (!setCoderProperties)\r\n      return E_FAIL;\r\n    RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, kNumProps));\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);\r\n    if (writeCoderProperties)\r\n    {\r\n      RINOK(writeCoderProperties->WriteCoderProperties(propStream));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Encode()\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n  outStreamSpec->Init();\r\n\r\n  RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));\r\n  compressedSize = outStreamSpec->Pos;\r\n  encoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Decode(UInt32 decoderIndex)\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];\r\n\r\n  CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;\r\n  decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);\r\n  if (!compressSetDecoderProperties)\r\n    return E_FAIL;\r\n\r\n  CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n  CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n  CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];\r\n  pi->BenchInfo.UnpackSize = 0;\r\n  pi->BenchInfo.PackSize = 0;\r\n\r\n  for (UInt32 j = 0; j < NumIterations; j++)\r\n  {\r\n    inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n    crcOutStreamSpec->Init();\r\n    \r\n    RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));\r\n    UInt64 outSize = kBufferSize;\r\n    RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));\r\n    if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)\r\n      return S_FALSE;\r\n    pi->BenchInfo.UnpackSize += kBufferSize;\r\n    pi->BenchInfo.PackSize += compressedSize;\r\n  }\r\n  decoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nstatic const UInt32 kNumThreadsMax = (1 << 16);\r\n\r\nstruct CBenchEncoders\r\n{\r\n  CEncoderInfo *encoders;\r\n  CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }\r\n  ~CBenchEncoders() { delete []encoders; }\r\n};\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)\r\n{\r\n  UInt32 numEncoderThreads = \r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? numThreads / 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  UInt32 numSubDecoderThreads = \r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)\r\n  {\r\n    return E_INVALIDARG;\r\n  }\r\n\r\n  CBenchEncoders encodersSpec(numEncoderThreads);\r\n  CEncoderInfo *encoders = encodersSpec.encoders;\r\n\r\n  #ifdef EXTERNAL_LZMA\r\n  UString name = L\"LZMA\";\r\n  #endif\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.callback = (i == 0) ? callback : 0;\r\n\r\n    #ifdef EXTERNAL_LZMA\r\n    RINOK(codecs->CreateCoder(name, true, encoder.encoder));\r\n    #else\r\n    encoder.encoder = new NCompress::NLZMA::CEncoder;\r\n    #endif\r\n    for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n    {\r\n      #ifdef EXTERNAL_LZMA\r\n      RINOK(codecs->CreateCoder(name, false, encoder.decoders[j]));\r\n      #else\r\n      encoder.decoders[j] = new NCompress::NLZMA::CDecoder;\r\n      #endif\r\n    }\r\n  }\r\n\r\n  CBaseRandomGenerator rg;\r\n  rg.Init();\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));\r\n  }\r\n\r\n  CBenchProgressStatus status;\r\n  status.Res = S_OK;\r\n  status.EncodeMode = true;\r\n\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;\r\n      encoder.progressInfoSpec[j]->Status = &status;\r\n    }\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numEncoderThreads > 1)\r\n    {\r\n      #ifdef USE_ALLOCA\r\n      encoder.AllocaSize = (i * 16 * 21) & 0x7FF;\r\n      #endif\r\n      RINOK(encoder.CreateEncoderThread())\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Encode());\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  if (numEncoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      encoders[i].thread[0].Wait();\r\n  #endif\r\n\r\n  RINOK(status.Res);\r\n\r\n  CBenchInfo info;\r\n\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = 1; // progressInfoSpec->NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetEncodeResult(info, true));\r\n\r\n\r\n  status.Res = S_OK;\r\n  status.EncodeMode = false;\r\n\r\n  UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;\r\n\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numDecoderThreads > 1)\r\n    {\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        size_t allocaSize = ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF;\r\n        HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)\r\n            #ifdef USE_ALLOCA\r\n            , allocaSize\r\n            #endif\r\n            );\r\n        RINOK(res);\r\n      }\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Decode(0));\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  HRESULT res = S_OK;\r\n  if (numDecoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        CEncoderInfo &encoder = encoders[i];\r\n        encoder.thread[j].Wait();\r\n        if (encoder.Results[j] != S_OK)\r\n          res = encoder.Results[j];\r\n      }\r\n  RINOK(res);\r\n  #endif\r\n  RINOK(status.Res);\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetDecodeResult(info, false));\r\n  RINOK(callback->SetDecodeResult(info, true));\r\n  return S_OK;\r\n}\r\n\r\n\r\ninline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)\r\n{ \r\n  UInt32 hs = dictionary - 1;\r\n  hs |= (hs >> 1);\r\n  hs |= (hs >> 2);\r\n  hs |= (hs >> 4);\r\n  hs |= (hs >> 8);\r\n  hs >>= 1;\r\n  hs |= 0xFFFF;\r\n  if (hs > (1 << 24))\r\n    hs >>= 1;\r\n  hs++;\r\n  return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 + \r\n      (1 << 20) + (multiThread ? (6 << 20) : 0);\r\n}\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  const UInt32 kBufferSize = dictionary;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2);\r\n  UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;\r\n  UInt32 numBigThreads = numThreads / numSubThreads;\r\n  return (kBufferSize + kCompressedBufferSize +\r\n    GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;\r\n}\r\n\r\nstatic bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)\r\n{\r\n  for (UInt32 i = 0; i < numCycles; i++)\r\n    if (CrcCalc(data, size) != crcBase)\r\n      return false;\r\n  return true;\r\n}\r\n\r\n#ifdef BENCH_MT\r\nstruct CCrcInfo\r\n{\r\n  NWindows::CThread Thread;\r\n  const Byte *Data;\r\n  UInt32 Size;\r\n  UInt32 NumCycles;\r\n  UInt32 Crc;\r\n  bool Res;\r\n  void Wait()\r\n  {\r\n    Thread.Wait();\r\n    Thread.Close();\r\n  }\r\n};\r\n\r\nstatic THREAD_FUNC_DECL CrcThreadFunction(void *param)\r\n{\r\n  CCrcInfo *p = (CCrcInfo *)param;\r\n  p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);\r\n  return 0;\r\n}\r\n\r\nstruct CCrcThreads\r\n{\r\n  UInt32 NumThreads;\r\n  CCrcInfo *Items;\r\n  CCrcThreads(): Items(0), NumThreads(0) {}\r\n  void WaitAll()\r\n  {\r\n    for (UInt32 i = 0; i < NumThreads; i++)\r\n      Items[i].Wait();\r\n    NumThreads = 0;\r\n  }\r\n  ~CCrcThreads() \r\n  { \r\n    WaitAll();\r\n    delete []Items; \r\n  }\r\n};\r\n#endif\r\n\r\nstatic UInt32 CrcCalc1(const Byte *buf, UInt32 size)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    crc = CRC_UPDATE_BYTE(crc, buf[i]);\r\n  return CRC_GET_DIGEST(crc);\r\n}\r\n\r\nstatic void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  for (UInt32 i = 0; i < size; i++)\r\n    buf[i] = (Byte)RG.GetRnd();\r\n}\r\n\r\nstatic UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  RandGen(buf, size, RG);\r\n  return CrcCalc1(buf, size);\r\n}\r\n\r\nbool CrcInternalTest()\r\n{\r\n  CBenchBuffer buffer;\r\n  const UInt32 kBufferSize0 = (1 << 8);\r\n  const UInt32 kBufferSize1 = (1 << 10);\r\n  const UInt32 kCheckSize = (1 << 5);\r\n  if (!buffer.Alloc(kBufferSize0 + kBufferSize1))\r\n    return false;\r\n  Byte *buf = buffer.Buffer;\r\n  UInt32 i;\r\n  for (i = 0; i < kBufferSize0; i++)\r\n    buf[i] = (Byte)i;\r\n  UInt32 crc1 = CrcCalc1(buf, kBufferSize0);\r\n  if (crc1 != 0x29058C73)\r\n    return false;\r\n  CBaseRandomGenerator RG;\r\n  RandGen(buf + kBufferSize0, kBufferSize1, RG);\r\n  for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)\r\n    for (UInt32 j = 0; j < kCheckSize; j++)\r\n      if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))\r\n        return false;\r\n  return true;\r\n}\r\n\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)\r\n{\r\n  if (numThreads == 0)\r\n    numThreads = 1;\r\n\r\n  CBenchBuffer buffer;\r\n  size_t totalSize = (size_t)bufferSize * numThreads;\r\n  if (totalSize / numThreads != bufferSize)\r\n    return E_OUTOFMEMORY;\r\n  if (!buffer.Alloc(totalSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  Byte *buf = buffer.Buffer;\r\n  CBaseRandomGenerator RG;\r\n  UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;\r\n\r\n  UInt64 timeVal;\r\n  #ifdef BENCH_MT\r\n  CCrcThreads threads;\r\n  if (numThreads > 1)\r\n  {\r\n    threads.Items = new CCrcInfo[numThreads];\r\n    UInt32 i;\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      Byte *data = buf + (size_t)bufferSize * i;\r\n      info.Data = data;\r\n      info.NumCycles = numCycles;\r\n      info.Size = bufferSize;\r\n      info.Crc = RandGenCrc(data, bufferSize, RG);\r\n    }\r\n    timeVal = GetTimeCount();\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      RINOK(info.Thread.Create(CrcThreadFunction, &info));\r\n      threads.NumThreads++;\r\n    }\r\n    threads.WaitAll();\r\n    for (i = 0; i < numThreads; i++)\r\n      if (!threads.Items[i].Res)\r\n        return S_FALSE;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 crc = RandGenCrc(buf, bufferSize, RG);\r\n    timeVal = GetTimeCount();\r\n    if (!CrcBig(buf, bufferSize, numCycles, crc))\r\n      return S_FALSE;\r\n  }\r\n  timeVal = GetTimeCount() - timeVal;\r\n  if (timeVal == 0)\r\n    timeVal = 1;\r\n\r\n  UInt64 size = (UInt64)numCycles * totalSize;\r\n  speed = MyMultDiv64(size, timeVal, GetFreq());\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LZMABENCH_H\r\n#define __LZMABENCH_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\n\r\nstruct CBenchInfo\r\n{\r\n  UInt64 GlobalTime;\r\n  UInt64 GlobalFreq; \r\n  UInt64 UserTime; \r\n  UInt64 UserFreq;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt32 NumIterations;\r\n  CBenchInfo(): NumIterations(0) {}\r\n};\r\n\r\nstruct IBenchCallback\r\n{\r\n  virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;\r\n  virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;\r\n};\r\n\r\nUInt64 GetUsage(const CBenchInfo &benchOnfo);\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);\r\n\r\nconst int kBenchMinDicLogSize = 18;\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);\r\n\r\nbool CrcInternalTest();\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp",
    "content": "// LzmaBenchCon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaBenchCon.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#if defined(BENCH_MT) || defined(_WIN32)\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#ifdef BREAK_HANDLER\r\n#include \"../../UI/Console/ConsoleClose.h\"\r\n#endif\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nstruct CTotalBenchRes\r\n{\r\n  UInt64 NumIterations;\r\n  UInt64 Rating;\r\n  UInt64 Usage;\r\n  UInt64 RPU;\r\n  void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }\r\n  void Normalize() \r\n  { \r\n    if (NumIterations == 0) \r\n      return;\r\n    Rating /= NumIterations; \r\n    Usage /= NumIterations; \r\n    RPU /= NumIterations; \r\n    NumIterations = 1;\r\n  }\r\n  void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2) \r\n  { \r\n    Rating = (r1.Rating + r2.Rating) / 2; \r\n    Usage = (r1.Usage + r2.Usage) / 2;\r\n    RPU = (r1.RPU + r2.RPU) / 2;\r\n    NumIterations = (r1.NumIterations + r2.NumIterations) / 2;\r\n  }\r\n};\r\n\r\nstruct CBenchCallback: public IBenchCallback\r\n{\r\n  CTotalBenchRes EncodeRes;\r\n  CTotalBenchRes DecodeRes;\r\n  FILE *f;\r\n  void Init() { EncodeRes.Init(); DecodeRes.Init(); }\r\n  void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }\r\n  UInt32 dictionarySize;\r\n  HRESULT SetEncodeResult(const CBenchInfo &info, bool final);\r\n  HRESULT SetDecodeResult(const CBenchInfo &info, bool final);\r\n};\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic void PrintNumber(FILE *f, UInt64 value, int size)\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(value, s);\r\n  fprintf(f, \" \");\r\n  for (int len = (int)strlen(s); len < size; len++)\r\n    fprintf(f, \" \");\r\n  fprintf(f, \"%s\", s);\r\n}\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  PrintNumber(f, rating / 1000000, 6);\r\n}\r\n\r\nstatic void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)\r\n{\r\n  PrintNumber(f, (usage + 5000) / 10000, 5);\r\n  PrintRating(f, rpu);\r\n  PrintRating(f, rating);\r\n}\r\n\r\n\r\nstatic void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)\r\n{\r\n  UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);\r\n  PrintNumber(f, speed / 1024, 7);\r\n  UInt64 usage = GetUsage(info);\r\n  UInt64 rpu = GetRatingPerUsage(info, rating);\r\n  PrintResults(f, usage, rpu, rating);\r\n  res.NumIterations++;\r\n  res.RPU += rpu;\r\n  res.Rating += rating;\r\n  res.Usage += usage;\r\n}\r\n\r\nstatic void PrintTotals(FILE *f, const CTotalBenchRes &res)\r\n{\r\n  fprintf(f, \"       \");\r\n  PrintResults(f, res.Usage, res.RPU, res.Rating);\r\n}\r\n\r\n\r\nHRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);\r\n    PrintResults(f, info, rating, EncodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const char *kSep = \"  | \";\r\n\r\n\r\nHRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);\r\n    fprintf(f, kSep);\r\n    CBenchInfo info2 = info;\r\n    info2.UnpackSize *= info2.NumIterations;\r\n    info2.PackSize *= info2.NumIterations;\r\n    info2.NumIterations = 1;\r\n    PrintResults(f, info2, rating, DecodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)\r\n{\r\n  fprintf(f, \"\\nRAM %s \", sizeString);\r\n  PrintNumber(f, (size >> 20), 5);\r\n  fprintf(f, \" MB,  # %s %3d\", threadsString, (unsigned int)numThreads);\r\n}\r\n\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();  // \r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  if (numThreads > 1)\r\n    numThreads &= ~1;\r\n  if (dictionary == (UInt32)-1)\r\n  {\r\n    int dicSizeLog;\r\n    for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)\r\n      if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)\r\n        break;\r\n    dictionary = (1 << dicSizeLog);\r\n  }\r\n  #else\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 22);\r\n  numThreads = 1;\r\n  #endif\r\n\r\n  PrintRequirements(f, \"usage:\", GetBenchMemoryUsage(numThreads, dictionary), \"Benchmark threads:   \", numThreads);\r\n\r\n  CBenchCallback callback;\r\n  callback.Init();\r\n  callback.f = f;\r\n  \r\n  fprintf(f, \"\\n\\nDict        Compressing          |        Decompressing\\n   \");\r\n  int j;\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"   Speed Usage    R/U Rating\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n   \");\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"    KB/s     %%   MIPS   MIPS\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    const int kStartDicLog = 22;\r\n    int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;\r\n    while (((UInt32)1 << pow) > dictionary)\r\n      pow--;\r\n    for (; ((UInt32)1 << pow) <= dictionary; pow++)\r\n    {\r\n      fprintf(f, \"%2d:\", pow);\r\n      callback.dictionarySize = (UInt32)1 << pow;\r\n      HRESULT res = LzmaBench(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        numThreads, callback.dictionarySize, &callback);\r\n      fprintf(f, \"\\n\");\r\n      RINOK(res);\r\n    }\r\n  }\r\n  callback.Normalize();\r\n  fprintf(f, \"----------------------------------------------------------------\\nAvr:\");\r\n  PrintTotals(f, callback.EncodeRes);\r\n  fprintf(f, \"     \");\r\n  PrintTotals(f, callback.DecodeRes);\r\n  fprintf(f, \"\\nTot:\");\r\n  CTotalBenchRes midRes;\r\n  midRes.SetMid(callback.EncodeRes, callback.DecodeRes);\r\n  PrintTotals(f, midRes);\r\n  fprintf(f, \"\\n\");\r\n  return S_OK;\r\n}\r\n\r\nstruct CTempValues\r\n{\r\n  UInt64 *Values;\r\n  CTempValues(UInt32 num) { Values = new UInt64[num]; }\r\n  ~CTempValues() { delete []Values; }\r\n};\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  #else\r\n  numThreads = 1;\r\n  #endif\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 24);\r\n\r\n  CTempValues speedTotals(numThreads);\r\n  fprintf(f, \"\\n\\nSize\");\r\n  for (UInt32 ti = 0; ti < numThreads; ti++)\r\n  {\r\n    fprintf(f, \" %5d\", ti + 1);\r\n    speedTotals.Values[ti] = 0;\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n\r\n  UInt64 numSteps = 0;\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    for (int pow = 10; pow < 32; pow++)\r\n    {\r\n      UInt32 bufSize = (UInt32)1 << pow;\r\n      if (bufSize > dictionary)\r\n        break;\r\n      fprintf(f, \"%2d: \", pow);\r\n      UInt64 speed;\r\n      for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      {\r\n        #ifdef BREAK_HANDLER\r\n        if (NConsoleClose::TestBreakSignal())\r\n          return E_ABORT;\r\n        #endif\r\n        RINOK(CrcBench(ti + 1, bufSize, speed));\r\n        PrintNumber(f, (speed >> 20), 5);\r\n        speedTotals.Values[ti] += speed;\r\n      }\r\n      fprintf(f, \"\\n\");\r\n      numSteps++;\r\n    }\r\n  }\r\n  if (numSteps != 0)\r\n  {\r\n    fprintf(f, \"\\nAvg:\");\r\n    for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);\r\n    fprintf(f, \"\\n\");\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h",
    "content": "// LzmaBenchCon.h\r\n\r\n#ifndef __LZMABENCHCON_H\r\n#define __LZMABENCHCON_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp",
    "content": "// LzmaRam.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/Compress/Branch/BranchX86.h\"\r\n}\r\n\r\nclass CInStreamRam: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Size;\r\n  size_t Pos;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > (Size - Pos))\r\n    size = (UInt32)(Size - Pos);\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass COutStreamRam: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  size_t Size;\r\npublic:\r\n  Byte *Data;\r\n  size_t Pos;\r\n  bool Overflow;\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n    Overflow = false;\r\n  }\r\n  void SetPos(size_t pos)\r\n  {\r\n    Overflow = false;\r\n    Pos = pos;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  HRESULT WriteByte(Byte b)\r\n  {\r\n    if (Pos >= Size)\r\n    {\r\n      Overflow = true;\r\n      return E_FAIL;\r\n    }\r\n    Data[Pos++] = b;\r\n    return S_OK;\r\n  }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < Size; i++)\r\n    Data[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    Overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\n#define SZ_RAM_E_FAIL (1)\r\n#define SZ_RAM_E_OUTOFMEMORY (2)\r\n#define SZE_OUT_OVERFLOW (3)\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try { \r\n  #endif\r\n\r\n  *outSizeProcessed = 0;\r\n  const size_t kIdSize = 1;\r\n  const size_t kLzmaPropsSize = 5;\r\n  const size_t kMinDestSize = kIdSize + kLzmaPropsSize + 8;\r\n  if (outSize < kMinDestSize)\r\n    return SZE_OUT_OVERFLOW;\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kAlgorithm,\r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kNumFastBytes,\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[1].vt = VT_UI4;\r\n  properties[2].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)2;\r\n  properties[1].ulVal = (UInt32)dictionarySize;\r\n  properties[2].ulVal = (UInt32)64;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n    return 1;\r\n  \r\n  COutStreamRam *outStreamSpec = new COutStreamRam;\r\n  if (outStreamSpec == 0)\r\n    return SZ_RAM_E_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n  CInStreamRam *inStreamSpec = new CInStreamRam;\r\n  if (inStreamSpec == 0)\r\n    return SZ_RAM_E_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\r\n  outStreamSpec->Init(outBuffer, outSize);\r\n  if (outStreamSpec->WriteByte(0) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n\r\n  if (encoderSpec->WriteCoderProperties(outStream) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n  if (outStreamSpec->Pos != kIdSize + kLzmaPropsSize)\r\n    return 1;\r\n  \r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    UInt64 t = (UInt64)(inSize);\r\n    if (outStreamSpec->WriteByte((Byte)((t) >> (8 * i))) != S_OK)\r\n      return SZE_OUT_OVERFLOW;\r\n  }\r\n\r\n  Byte *filteredStream = 0;\r\n\r\n  bool useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (inSize != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(inSize);\r\n      if (filteredStream == 0)\r\n        return SZ_RAM_E_OUTOFMEMORY;\r\n      memmove(filteredStream, inBuffer, inSize);\r\n    }\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(filteredStream, (SizeT)inSize, 0, &x86State, 1);\r\n  }\r\n  \r\n  size_t minSize = 0;\r\n  int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n  bool bestIsFiltered = false;\r\n  int mainResult = 0;\r\n  size_t startPos = outStreamSpec->Pos;\r\n  for (i = 0; i < numPasses; i++)\r\n  {\r\n    if (numPasses > 1 && i == numPasses - 1 && !bestIsFiltered)\r\n      break;\r\n    outStreamSpec->SetPos(startPos);\r\n    bool curModeIsFiltered = false;\r\n    if (useFilter && i == 0)\r\n      curModeIsFiltered = true;\r\n    if (numPasses > 1 && i == numPasses - 1)\r\n      curModeIsFiltered = true;\r\n\r\n    inStreamSpec->Init(curModeIsFiltered ? filteredStream : inBuffer, inSize);\r\n    \r\n    HRESULT lzmaResult = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    \r\n    mainResult = 0;\r\n    if (lzmaResult == E_OUTOFMEMORY)\r\n    {\r\n      mainResult = SZ_RAM_E_OUTOFMEMORY;\r\n      break;\r\n    } \r\n    if (i == 0 || outStreamSpec->Pos <= minSize)\r\n    {\r\n      minSize = outStreamSpec->Pos;\r\n      bestIsFiltered = curModeIsFiltered;\r\n    }\r\n    if (outStreamSpec->Overflow)\r\n      mainResult = SZE_OUT_OVERFLOW;\r\n    else if (lzmaResult != S_OK)\r\n    {\r\n      mainResult = SZ_RAM_E_FAIL;\r\n      break;\r\n    } \r\n  }\r\n  *outSizeProcessed = outStreamSpec->Pos;\r\n  if (bestIsFiltered)\r\n    outBuffer[0] = 1;\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n  \r\n  #ifndef _NO_EXCEPTIONS\r\n  } catch(...) { return SZ_RAM_E_OUTOFMEMORY; }\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h",
    "content": "// LzmaRam.h\r\n\r\n#ifndef __LzmaRam_h\r\n#define __LzmaRam_h\r\n\r\n#include <stdlib.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\n/*\r\nLzmaRamEncode: BCJ + LZMA RAM->RAM compressing.\r\nIt uses .lzma format, but it writes one additional byte to .lzma file:\r\n  0: - no filter\r\n  1: - x86(BCJ) filter.\r\n\r\nTo provide best compression ratio dictionarySize mustbe >= inSize\r\n\r\nLzmaRamEncode allocates Data with MyAlloc/BigAlloc functions.\r\nRAM Requirements:\r\n  RamSize = dictionarySize * 9.5 + 6MB + FilterBlockSize \r\n    FilterBlockSize = 0, if useFilter == false\r\n    FilterBlockSize = inSize, if useFilter == true\r\n\r\n  Return code:\r\n    0 - OK\r\n    1 - Unspecified Error\r\n    2 - Memory allocating error\r\n    3 - Output buffer OVERFLOW\r\n\r\nIf you use SZ_FILTER_AUTO mode, then encoder will use 2 or 3 passes:\r\n  2 passes when FILTER_NO provides better compression.\r\n  3 passes when FILTER_YES provides better compression.\r\n*/\r\n\r\nenum ESzFilterMode \r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c",
    "content": "/* LzmaRamDecode.c */\r\n\r\n#include \"LzmaRamDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#include \"BranchX86.h\"\r\n#else\r\n#include \"../../../../C/Compress/Lzma/LzmaDecode.h\"\r\n#include \"../../../../C/Compress/Branch/BranchX86.h\"\r\n#endif\r\n\r\n#define LZMA_PROPS_SIZE 14\r\n#define LZMA_SIZE_OFFSET 6\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize, \r\n    size_t *outSize)\r\n{\r\n  unsigned int i;\r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  *outSize = 0;\r\n  for(i = 0; i < sizeof(size_t); i++)\r\n    *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);\r\n  for(; i < 8; i++)\r\n    if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)\r\n      return 1;\r\n  return 0;\r\n}\r\n\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *))\r\n{\r\n  CLzmaDecoderState state;  /* it's about 24 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  SizeT inProcessed;\r\n  int useFilter;\r\n  \r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  useFilter = inBuffer[0];\r\n\r\n  *outSizeProcessed = 0;\r\n  if (useFilter > 1)\r\n    return 1;\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return 1;\r\n  state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  result = LzmaDecode(&state,\r\n    inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed,\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  freeFunc(state.Probs);\r\n  if (result != LZMA_RESULT_OK)\r\n    return 1;\r\n  *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(outBuffer, (SizeT)outSizeProcessedLoc, 0, &x86State, 0);\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h",
    "content": "/* LzmaRamDecode.h */\r\n\r\n#ifndef __LzmaRamDecode_h\r\n#define __LzmaRamDecode_h\r\n\r\n#include <stdlib.h>\r\n\r\n/*\r\nLzmaRamGetUncompressedSize:\r\n  In: \r\n    inBuffer - input data\r\n    inSize   - input data size\r\n  Out: \r\n    outSize  - uncompressed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers\r\n*/\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    size_t *outSize);\r\n\r\n\r\n/*\r\nLzmaRamDecompress:\r\n  In: \r\n    inBuffer  - input data\r\n    inSize    - input data size\r\n    outBuffer - output data\r\n    outSize   - output size\r\n    allocFunc - alloc function (can be malloc)\r\n    freeFunc  - free function (can be free)\r\n  Out: \r\n    outSizeProcessed - processed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers / data stream\r\n    2 - Memory allocating error\r\n\r\nMemory requirements depend from properties of LZMA stream.\r\nWith default lzma settings it's about 16 KB.\r\n*/\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/comp.cc",
    "content": "/*\n * Copyright (C) 2006-2007 Junjiro Okajima\n * Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: comp.cc,v 1.3 2007-11-13 13:27:23 jro Exp $ */\n\n// extract some parts from lzma443/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <assert.h>\n#include <errno.h>\n\n#include \"StdAfx.h\"\n#include \"../../../Common/MyInitGuid.h\"\n//#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/StringConvert.h\"\n//#include \"../../../Common/StringToInt.h\"\n//#include \"../../Common/StreamUtils.h\"\n#include \"../LZMA/LZMAEncoder.h\"\n\n#include <pthread.h>\n#include <zlib.h>\n#include \"sqlzma.h\"\n\n//////////////////////////////////////////////////////////////////////\n\nclass CMemoryStream {\nprotected:\n\tBytef *m_data;\n\tUInt64 m_limit;\n\tUInt64 m_pos;\n\npublic:\n\tCMemoryStream(Bytef *data, UInt64 size)\n\t\t: m_data(data), m_limit(size), m_pos(0) {}\n\n\tvirtual ~CMemoryStream() {}\n};\n\nclass CInMemoryStream : public CMemoryStream, public IInStream,\n\t\t\tpublic CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialInStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IInStream);\n\n\tCInMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~CInMemoryStream() {}\n\n\tSTDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\n\t{\n\t\tUInt64 room = m_limit - m_pos;\n\t\tif (size > room)\n\t\t\tsize = room;\n\t\tif (size) {\n\t\t\tmemcpy(data, m_data + m_pos, size);\n\t\t\tm_pos += size;\n\t\t}\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\nclass COutMemoryStream : public CMemoryStream, public IOutStream,\n\t\t\t public CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialOutStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IOutStream);\n\n\tCOutMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~COutMemoryStream() {}\n\n\tUInt32 GetSize() {return m_pos;}\n\n\tSTDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) {\n\t\tif (m_pos + size > m_limit)\n\t\t\treturn -ENOSPC;\n\t\tmemcpy(m_data + m_pos, data, size);\n\t\tm_pos += size;\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n\tSTDMETHOD(SetSize)(Int64 newSize) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\n//////////////////////////////////////////////////////////////////////\n\nstatic int\nLzmaCompress(Bytef *next_in, uInt avail_in, Bytef *next_out, uInt avail_out,\n\t     struct sqlzma_opts *opts, uLong *total_out)\n{\n\tint err;\n\tHRESULT res;\n\tconst Byte a[] = {\n\t\tavail_in, avail_in >> 8, avail_in >> 16, avail_in >> 24,\n\t\t0, 0, 0, 0\n\t};\n\n\tNCompress::NLZMA::CEncoder encoderSpec;\n\tCMyComPtr<ICompressCoder> encoder = &encoderSpec;\n\tencoder->AddRef();\n\tCInMemoryStream inStreamSpec(next_in, avail_in);\n\tCMyComPtr<ISequentialInStream> inStream = &inStreamSpec;\n\tinStream->AddRef();\n\tCOutMemoryStream outStreamSpec(next_out, avail_out);\n\tCMyComPtr<ISequentialOutStream> outStream = &outStreamSpec;\n\toutStream->AddRef();\n\n\t// these values are dpending upon is_lzma() macro in sqlzma.h\n\tconst UInt32 dictionary = opts->dicsize;\n\t//fprintf(stderr, \"dic %u\\n\", dictionary);\n\tconst UString mf = L\"BT4\";\n\tconst UInt32 posStateBits = 2;\n\tconst UInt32 litContextBits = 3; // for normal files\n\t// UInt32 litContextBits = 0; // for 32-bit data\n\tconst UInt32 litPosBits = 0;\n\t// UInt32 litPosBits = 2; // for 32-bit data\n\t//const UInt32 algorithm = 2;\n\tconst UInt32 algorithm = 1;\n\tconst UInt32 numFastBytes = 128;\n\tconst UInt32 matchFinderCycles = 16 + numFastBytes / 2;\n\t//const bool matchFinderCyclesDefined = false;\n\tconst PROPID propIDs[] = {\n\t\tNCoderPropID::kDictionarySize,\n\t\tNCoderPropID::kPosStateBits,\n\t\tNCoderPropID::kLitContextBits,\n\t\tNCoderPropID::kLitPosBits,\n\t\tNCoderPropID::kAlgorithm,\n\t\tNCoderPropID::kNumFastBytes,\n\t\tNCoderPropID::kMatchFinder,\n\t\tNCoderPropID::kEndMarker,\n\t\tNCoderPropID::kNumThreads,\n\t\tNCoderPropID::kMatchFinderCycles\n\t};\n\tconst int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\n\tPROPVARIANT properties[kNumPropsMax];\n\tfor (int p = 0; p < 6; p++)\n\t\tproperties[p].vt = VT_UI4;\n\tproperties[0].ulVal = UInt32(dictionary);\n\tproperties[1].ulVal = UInt32(posStateBits);\n\tproperties[2].ulVal = UInt32(litContextBits);\n\tproperties[3].ulVal = UInt32(litPosBits);\n\tproperties[4].ulVal = UInt32(algorithm);\n\tproperties[5].ulVal = UInt32(numFastBytes);\n\n\tproperties[6].vt = VT_BSTR;\n\tproperties[6].bstrVal = (BSTR)(const wchar_t *)mf;\n\tproperties[7].vt = VT_BOOL;\n\tproperties[7].boolVal = VARIANT_FALSE;\t// EOS\n\tproperties[8].vt = VT_UI4;\n\tproperties[8].ulVal = 1; // numThreads\n\tproperties[9].vt = VT_UI4;\n\tproperties[9].ulVal = UInt32(matchFinderCycles);\n\n\terr = -EINVAL;\n\tres = encoderSpec.SetCoderProperties(propIDs, properties,\n\t\t\t\t\t     kNumPropsMax - 1);\n\tif (res)\n\t\tgoto out;\n\tres = encoderSpec.WriteCoderProperties(outStream);\n\tif (res)\n\t\tgoto out;\n\n\tUInt32 r;\n\tres = outStream->Write(a, sizeof(a), &r);\n\tif (res || r != sizeof(a))\n\t\tgoto out;\n\n\terr = encoder->Code(inStream, outStream, 0, /*broken*/0, 0);\n\tif (err)\n\t\tgoto out;\n\t*total_out = outStreamSpec.GetSize();\n\n out:\n\treturn err;\n}\n\n//////////////////////////////////////////////////////////////////////\n\n#define Failure(p) do { \\\n\tfprintf(stderr, \"%s:%d: please report to jro \" \\\n\t\t\"{%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x}\\n\", \\\n\t\t__func__, __LINE__, \\\n\t\tp[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); \\\n\tabort(); \\\n} while(0)\n\nextern \"C\" int\nsqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in, uInt\n\t  avail_in, Bytef *next_out, uInt avail_out)\n{\n\tint err;\n\tBytef *p = next_out;\n\tuInt l = avail_out;\n\n\tstream->next_in = next_in;\n\tstream->avail_in = avail_in;\n\tstream->next_out = p;\n\tstream->avail_out = l;\n\terr = deflate(stream, Z_FINISH);\n\tif (err != Z_STREAM_END && err != Z_OK)\n\t\tgoto out_err;\n\tif (avail_in < stream->total_out)\n\t\treturn err;\n\tif (is_lzma(*p))\n\t\tFailure(p);\n\n\tif (opts->try_lzma) {\n\t\tunsigned char a[stream->total_out];\n\t\tuLong processed;\n\n\t\tmemcpy(a, p, stream->total_out);\n\n\t\t// malloc family in glibc and stdc++ seems to be thread-safe\n\t\terr = LzmaCompress(next_in, avail_in, p, l, opts, &processed);\n\t\tif (!err && processed <= stream->total_out) {\n\t\t\tif (!is_lzma(*next_out))\n\t\t\t\tFailure(next_out);\n\t\t\tstream->total_out = processed;\n\t\t\terr = Z_STREAM_END;\n\t\t} else {\n\t\t\t//puts(\"by zlib\");\n\t\t\tmemcpy(p, a, stream->total_out);\n\t\t\terr = Z_STREAM_END;\n\t\t}\n\t}\n\treturn err;\n\n out_err:\n\tfprintf(stderr, \"%s: ZLIB err %s\\n\", __func__, zError(err));\n\treturn err;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -DBENCH_MT \\\r\n\r\nLIBS = $(LIBS) oleaut32.lib user32.lib\r\n\r\n!IFDEF CPU\r\nLIBS = $(LIBS) bufferoverflowU.lib \r\nCFLAGS = $(CFLAGS) -GS- -Zc:forScope -W4 -Wp64 -DUNICODE -D_UNICODE\r\n!ENDIF\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n  $O\\LzmaRam.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj\r\n\r\nWIN_OBJS = \\\r\n  $O\\System.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZ_OBJS = \\\r\n  $O\\MatchFinder.obj \\\r\n  $O\\MatchFinderMt.obj \\\r\n\r\nOBJS = \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZ_OBJS) \\\r\n  $O\\LzmaRamDecode.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\LzmaRamDecode.obj: LzmaRamDecode.c\r\n\t$(COMPL_O1)\r\n$O\\LzmaDecode.obj: ../../../../C/Compress/Lzma/LzmaDecode.c\r\n\t$(COMPL_O2)\r\n$O\\BranchX86.obj: ../../../../C/Compress/Branch/BranchX86.c\r\n\t$(COMPL_O2)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c\r\n\r\nifdef SystemDrive\r\nIS_MINGW = 1\r\nendif\r\n\r\nifdef IS_MINGW\r\nFILE_IO =FileIO\r\nFILE_IO_2 =Windows/$(FILE_IO)\r\nLIB2 = -luuid \r\nelse\r\nFILE_IO =C_FileIO\r\nFILE_IO_2 =Common/$(FILE_IO)\r\nendif\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaBenchCon.o \\\r\n  LzmaRam.o \\\r\n  LZMADecoder.o \\\r\n  LZMAEncoder.o \\\r\n  LZOutWindow.o \\\r\n  RangeCoderBit.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  $(FILE_IO).o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  IntToString.o \\\r\n  MyString.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  MyVector.o \\\r\n  7zCrc.o \\\r\n  Alloc.o \\\r\n  BranchX86.o \\\r\n  MatchFinder.o \\\r\n  LzmaDecode.o \\\r\n  LzmaRamDecode.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaBenchCon.o: LzmaBenchCon.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBenchCon.cpp\r\n\r\nLzmaRam.o: LzmaRam.cpp\r\n\t$(CXX) $(CFLAGS) LzmaRam.cpp\r\n\r\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\r\n\r\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\r\n\r\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\r\n\r\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\r\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\n$(FILE_IO).o: ../../../$(FILE_IO_2).cpp\r\n\t$(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp\r\n\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nIntToString.o: ../../../Common/IntToString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp\r\n\r\nMyString.o: ../../../Common/MyString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyString.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nMyVector.o: ../../../Common/MyVector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyVector.cpp\r\n\r\n7zCrc.o: ../../../../C/7zCrc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c\r\n\r\nAlloc.o: ../../../../C/Alloc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c\r\n\r\nBranchX86.o: ../../../../C/Compress/Branch/BranchX86.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c\r\n\r\nMatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c\r\n\r\nLzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c\r\n\r\nLzmaRamDecode.o: LzmaRamDecode.c\r\n\t$(CXX_C) $(CFLAGS) LzmaRamDecode.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/LZMA_Alone/sqlzma.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\ninclude makefile.gcc\n\nifdef UseDebugFlags\nDebugFlags = -Wall -O0 -g -UNDEBUG\nendif\n# -pthread\nCXXFLAGS = ${CFLAGS} -D_REENTRANT -include pthread.h -DNDEBUG ${DebugFlags}\nTgt = liblzma_r.a\n\nall: ${Tgt}\n\nRObjs = LZMAEncoder_r.o Alloc_r.o StreamUtils_r.o MatchFinder_r.o \\\n\tRangeCoderBit_r.o OutBuffer_r.o 7zCrc_r.o\n\n%_r.cc: ../LZMA/%.cpp\n\tln $< $@\n%_r.c: ../../../../C/%.c\n\tln $< $@\n%_r.c: ../../../../C/Compress/Lz/%.c\n\tln $< $@\n%_r.cc: ../../Common/%.cpp\n\tln $< $@\n%_r.cc: ../RangeCoder/%.cpp\n\tln $< $@\nLZMAEncoder_r.o: CXXFLAGS += -I../LZMA\nAlloc_r.o: CFLAGS += -I../../../../C\nStreamUtils_r.o: CXXFLAGS += -I../../Common\nMatchFinder_r.o: CFLAGS += -I../../../../C/Compress/Lz\nRangeCoderBit_r.o: CXXFLAGS += -I../RangeCoder\nOutBuffer_r.o: CXXFLAGS += -I../../Common\n7zCrc_r.o: CFLAGS += -I../../../../C\n\ncomp.o: CXXFLAGS += -I${Sqlzma}\ncomp.o: comp.cc ${Sqlzma}/sqlzma.h\n\nliblzma_r.a: ${RObjs} comp.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) comp.o *_r.o ${Tgt} *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/RangeCoder/RangeCoder.h",
    "content": "// Compress/RangeCoder/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_H\r\n#define __COMPRESS_RANGECODER_H\r\n\r\n#include \"../../Common/InBuffer.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1; \r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) \r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);                      \r\n    } \r\n    _cacheSize++;                               \r\n    Low = (UInt32)Low << 8;                           \r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numTotalBits)\r\n  {\r\n    for (int i = numTotalBits - 1; i >= 0; i--)\r\n    {\r\n      Range >>= 1;\r\n      if (((value >> i) & 1) == 1)\r\n        Low += Range;\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;        \r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8; \r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp",
    "content": "// Compress/RangeCoder/RangeCoderBit.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nUInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\nstatic CPriceTables g_PriceTables;\r\n\r\nCPriceTables::CPriceTables() { Init(); }\r\n\r\nvoid CPriceTables::Init()\r\n{\r\n  const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n  for(int i = kNumBits - 1; i >= 0; i--)\r\n  {\r\n    UInt32 start = 1 << (kNumBits - i - 1);\r\n    UInt32 end = 1 << (kNumBits - i);\r\n    for (UInt32 j = start; j < end; j++)\r\n      ProbPrices[j] = (i << kNumBitPriceShiftBits) + \r\n          (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n  }\r\n\r\n  /*\r\n  // simplest: bad solution\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = kBitPrice;\r\n  */\r\n  \r\n  /*\r\n  const double kDummyMultMid = (1.0 / kBitPrice) / 2;\r\n  const double kDummyMultMid = 0;\r\n  // float solution\r\n  double ln2 = log(double(2));\r\n  double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);\r\n  */\r\n  \r\n  /*\r\n  // experimental, slow, solution:\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n  {\r\n    const int kCyclesBits = 5;\r\n    const UInt32 kCycles = (1 << kCyclesBits);\r\n\r\n    UInt32 range = UInt32(-1);\r\n    UInt32 bitCount = 0;\r\n    for (UInt32 j = 0; j < kCycles; j++)\r\n    {\r\n      range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n      range *= i;\r\n      while(range < (1 << 31))\r\n      {\r\n        range <<= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    bitCount <<= kNumBitPriceShiftBits;\r\n    range -= (1 << 31);\r\n    for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)\r\n    {\r\n      range <<= 1;\r\n      if (range > (1 << 31))\r\n      {\r\n        bitCount += (1 << k);\r\n        range -= (1 << 31);\r\n      }\r\n    }\r\n    ProbPrices[i] = (bitCount \r\n      // + (1 << (kCyclesBits - 1))\r\n      ) >> kCyclesBits;\r\n  }\r\n  */\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h",
    "content": "// Compress/RangeCoder/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_H\r\n#define __COMPRESS_RANGECODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 2;\r\n\r\nconst int kNumBitPriceShiftBits = 6;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nclass CPriceTables\r\n{\r\npublic:\r\n  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  static void Init();\r\n  CPriceTables();\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return CPriceTables::ProbPrices[\r\n      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h",
    "content": "// Compress/RangeCoder/RangeCoderBitTree.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_TREE_H\r\n#define __COMPRESS_RANGECODER_BIT_TREE_H\r\n\r\n#include \"RangeCoderBit.h\"\r\n#include \"RangeCoderOpt.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeEncoder\r\n{\r\n  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  void Encode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int bitIndex = NumBitLevels; bitIndex != 0 ;)\r\n    {\r\n      bitIndex--;\r\n      UInt32 bit = (symbol >> bitIndex) & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n  };\r\n  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int i = 0; i < NumBitLevels; i++)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n      symbol >>= 1;\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    symbol |= (1 << NumBitLevels);\r\n    UInt32 price = 0;\r\n    while (symbol != 1)\r\n    {\r\n      price += Models[symbol >> 1].GetPrice(symbol & 1);\r\n      symbol >>= 1;\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 ReverseGetPrice(UInt32 symbol) const\r\n  {\r\n    UInt32 price = 0;\r\n    UInt32 modelIndex = 1;\r\n    for (int i = NumBitLevels; i != 0; i--)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      symbol >>= 1;\r\n      price += Models[modelIndex].GetPrice(bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n    return price;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeDecoder\r\n{\r\n  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  UInt32 Decode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n    {\r\n      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);\r\n      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)\r\n    }\r\n    RC_FLUSH_VAR\r\n    return modelIndex - (1 << NumBitLevels);\r\n  };\r\n  UInt32 ReverseDecode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    UInt32 symbol = 0;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n    {\r\n      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n      // modelIndex <<= 1;\r\n      // modelIndex += bit;\r\n      // symbol |= (bit << bitIndex);\r\n      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n    }\r\n    RC_FLUSH_VAR\r\n    return symbol;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nvoid ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models, \r\n    CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  for (int i = 0; i < NumBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    Models[modelIndex].Encode(rangeEncoder, bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models, \r\n    UInt32 NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 modelIndex = 1;\r\n  for (int i = NumBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += Models[modelIndex].GetPrice(bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models, \r\n    CDecoder *rangeDecoder, int NumBitLevels)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  UInt32 symbol = 0;\r\n  RC_INIT_VAR\r\n  for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n  {\r\n    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n    // modelIndex <<= 1;\r\n    // modelIndex += bit;\r\n    // symbol |= (bit << bitIndex);\r\n    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n  }\r\n  RC_FLUSH_VAR\r\n  return symbol;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/RangeCoder/RangeCoderOpt.h",
    "content": "// Compress/RangeCoder/RangeCoderOpt.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_OPT_H\r\n#define __COMPRESS_RANGECODER_OPT_H\r\n\r\n#define RC_INIT_VAR \\\r\n  UInt32 range = rangeDecoder->Range; \\\r\n  UInt32 code = rangeDecoder->Code;        \r\n\r\n#define RC_FLUSH_VAR \\\r\n  rangeDecoder->Range = range; \\\r\n  rangeDecoder->Code = code;\r\n\r\n#define RC_NORMALIZE \\\r\n  if (range < NCompress::NRangeCoder::kTopValue) \\\r\n    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }\r\n\r\n#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \\\r\n  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \\\r\n  if (code < bound) \\\r\n  { A0; range = bound; \\\r\n    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \\\r\n    mi <<= 1; } \\\r\n  else \\\r\n  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \\\r\n    mi = (mi + mi) + 1; }} \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/Compress/RangeCoder/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, \r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kMatchFinderCycles,\r\n    kNumPasses = 0x460, \r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kNumThreads,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetCoderMt, 0x25)\r\n{\r\n  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block \r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICompressCodecsInfo, 0x60)\r\n{\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n};\r\nCODER_INTERFACE(ISetCompressCodecsInfo, 0x61)\r\n{\r\n  STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICryptoResetSalt, 0x88)\r\n{\r\n  STDMETHOD(ResetSalt)() PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICryptoResetInitVector, 0x8C)\r\n{\r\n  STDMETHOD(ResetInitVector)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription,\r\n    kDecoderIsAssigned,\r\n    kEncoderIsAssigned\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/IDecl.h",
    "content": "// IDecl.h\r\n\r\n#ifndef __IDECL_H\r\n#define __IDECL_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n\r\n#define DECL_INTERFACE_SUB(i, base, groupId, subId) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \\\r\nstruct i: public base\r\n\r\n#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/IPassword.h",
    "content": "// IPassword.h\r\n\r\n#ifndef __IPASSWORD_H\r\n#define __IPASSWORD_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;\r\n};\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;\r\n};\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/IProgress.h",
    "content": "// Interface/IProgress.h\r\n\r\n#ifndef __IPROGRESS_H\r\n#define __IPROGRESS_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\nDECL_INTERFACE(IProgress, 0, 5)\r\n{\r\n  STDMETHOD(SetTotal)(UInt64 total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000000050002}\r\nDEFINE_GUID(IID_IProgress2, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000050002\")\r\nIProgress2: public IUnknown\r\n{\r\npublic:\r\n  STDMETHOD(SetTotal)(const UInt64 *total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream, \r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/MyVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 57\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.57\"\r\n#define MY_7ZIP_VERSION \"7-Zip 4.57\"\r\n#define MY_DATE \"2007-12-06\"\r\n#define MY_COPYRIGHT \"Copyright (c) 1999-2007 Igor Pavlov\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \"  \" MY_COPYRIGHT \"  \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/MyVersionInfo.rc",
    "content": "#include <WinVer.h>\r\n#include \"MyVersion.h\"\r\n\r\n#define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0\r\n\r\n#ifdef DEBUG\r\n#define DBG_FL VS_FF_DEBUG\r\n#else\r\n#define DBG_FL 0\r\n#endif\r\n\r\n#define MY_VERSION_INFO(fileType, descr, intName, origName)  \\\r\nLANGUAGE 9, 1 \\\r\n1 VERSIONINFO \\\r\n  FILEVERSION MY_VER \\\r\n  PRODUCTVERSION MY_VER \\\r\n  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK \\\r\n  FILEFLAGS DBG_FL \\\r\n  FILEOS VOS_NT_WINDOWS32 \\\r\n  FILETYPE fileType \\\r\n  FILESUBTYPE 0x0L \\\r\nBEGIN \\\r\n    BLOCK \"StringFileInfo\" \\\r\n    BEGIN  \\\r\n        BLOCK \"040904b0\" \\\r\n        BEGIN \\\r\n            VALUE \"CompanyName\", \"Igor Pavlov\" \\\r\n            VALUE \"FileDescription\", descr \\\r\n            VALUE \"FileVersion\", MY_VERSION  \\\r\n            VALUE \"InternalName\", intName \\\r\n            VALUE \"LegalCopyright\", MY_COPYRIGHT \\\r\n            VALUE \"OriginalFilename\", origName \\\r\n            VALUE \"ProductName\", \"7-Zip\" \\\r\n            VALUE \"ProductVersion\", MY_VERSION \\\r\n        END \\\r\n    END \\\r\n    BLOCK \"VarFileInfo\" \\\r\n    BEGIN \\\r\n        VALUE \"Translation\", 0x409, 1200 \\\r\n    END \\\r\nEND\r\n\r\n#define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(VFT_APP, descr, intName, intName \".exe\")\r\n\r\n#define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(VFT_DLL, descr, intName, intName \".dll\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/PropID.h",
    "content": "// Interface/PropID.h\r\n\r\n#ifndef __INTERFACE_PROPID_H\r\n#define __INTERFACE_PROPID_H\r\n\r\nenum\r\n{\r\n  kpidNoProperty = 0,\r\n  \r\n  kpidHandlerItemIndex = 2,\r\n  kpidPath,\r\n  kpidName,\r\n  kpidExtension,\r\n  kpidIsFolder,\r\n  kpidSize,\r\n  kpidPackedSize,\r\n  kpidAttributes,\r\n  kpidCreationTime,\r\n  kpidLastAccessTime,\r\n  kpidLastWriteTime,\r\n  kpidSolid, \r\n  kpidCommented, \r\n  kpidEncrypted, \r\n  kpidSplitBefore, \r\n  kpidSplitAfter, \r\n  kpidDictionarySize, \r\n  kpidCRC, \r\n  kpidType,\r\n  kpidIsAnti,\r\n  kpidMethod,\r\n  kpidHostOS,\r\n  kpidFileSystem,\r\n  kpidUser,\r\n  kpidGroup,\r\n  kpidBlock,\r\n  kpidComment,\r\n  kpidPosition,\r\n  kpidPrefix,\r\n  kpidNumSubFolders,\r\n  kpidNumSubFiles,\r\n  kpidUnpackVer,\r\n  kpidVolume,\r\n  kpidIsVolume,\r\n  kpidOffset,\r\n  kpidLinks,\r\n  kpidNumBlocks,\r\n  kpidNumVolumes,\r\n\r\n  kpidTotalSize = 0x1100,\r\n  kpidFreeSpace, \r\n  kpidClusterSize,\r\n  kpidVolumeName,\r\n\r\n  kpidLocalName = 0x1200,\r\n  kpidProvider,\r\n\r\n  kpidUserDefined = 0x10000\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Client7z/Client7z.cpp",
    "content": "// Client7z.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/DLL.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../MyVersion.h\"\r\n\r\n\r\n// {23170F69-40C1-278A-1000-000110070000}\r\nDEFINE_GUID(CLSID_CFormat7z, \r\n  0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);\r\n\r\nusing namespace NWindows;\r\n\r\n#define kDllName \"7z.dll\"\r\n\r\nstatic const char *kCopyrightString = MY_7ZIP_VERSION\r\n\" (\"  kDllName \" client) \"  \r\nMY_COPYRIGHT \" \" MY_DATE;\r\n\r\nstatic const char *kHelpString = \r\n\"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\\n\"\r\n\"Examples:\\n\"\r\n\"  Client7z.exe a archive.7z f1.txt f2.txt  : compress two files to archive.7z\\n\"\r\n\"  Client7z.exe l archive.7z   : List contents of archive.7z\\n\"\r\n\"  Client7z.exe x archive.7z   : eXtract files from archive.7z\\n\";\r\n\r\n\r\ntypedef UINT32 (WINAPI * CreateObjectFunc)(\r\n    const GUID *clsID, \r\n    const GUID *interfaceID, \r\n    void **outObject);\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nvoid PrintString(const UString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)GetOemString(s));\r\n}\r\n\r\nvoid PrintString(const AString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)s);\r\n}\r\n\r\nvoid PrintNewLine()\r\n{\r\n  PrintString(\"\\n\");\r\n}\r\n\r\nvoid PrintStringLn(const AString &s)\r\n{\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nvoid PrintError(const AString &s)\r\n{\r\n  PrintNewLine();\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nstatic HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsFolder, result);\r\n}\r\n\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Open callback class\r\n\r\n\r\nclass CArchiveOpenCallback: \r\n  public IArchiveOpenCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveOpenCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream); \r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Extracting callback class\r\n\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCRCFailed = \"CRC Failed\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nclass CArchiveExtractCallback: \r\n  public IArchiveExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IArchiveExtractCallback\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  UString _directoryPath;  // Output directory\r\n  UString _filePath;       // name inside arcvhive\r\n  UString _diskFilePath;   // full path to file on disk\r\n  bool _extractMode;\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME UTCLastWriteTime;\r\n    UInt32 Attributes;\r\n    bool IsDirectory;\r\n    bool AttributesAreDefined;\r\n    bool UTCLastWriteTimeIsDefined;\r\n  } _processedFileInfo;\r\n\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n\r\npublic:\r\n  void Init(IInArchive *archiveHandler, const UString &directoryPath);\r\n\r\n  UInt64 NumErrors;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveExtractCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nvoid CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)\r\n{\r\n  NumErrors = 0;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, \r\n    ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  {\r\n    // Get Name\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPath, &propVariant));\r\n    \r\n    UString fullPath;\r\n    if(propVariant.vt == VT_EMPTY)\r\n      fullPath = kEmptyFileAlias;\r\n    else \r\n    {\r\n      if(propVariant.vt != VT_BSTR)\r\n        return E_FAIL;\r\n      fullPath = propVariant.bstrVal;\r\n    }\r\n    _filePath = fullPath;\r\n  }\r\n\r\n  if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)\r\n    return S_OK;\r\n\r\n  {\r\n    // Get Attributes\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &propVariant));\r\n    if (propVariant.vt == VT_EMPTY)\r\n    {\r\n      _processedFileInfo.Attributes = 0;\r\n      _processedFileInfo.AttributesAreDefined = false;\r\n    }\r\n    else\r\n    {\r\n      if (propVariant.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      _processedFileInfo.Attributes = propVariant.ulVal;\r\n      _processedFileInfo.AttributesAreDefined = true;\r\n    }\r\n  }\r\n\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDirectory));\r\n\r\n  {\r\n    // Get Modified Time\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidLastWriteTime, &propVariant));\r\n    _processedFileInfo.UTCLastWriteTimeIsDefined = false;\r\n    switch(propVariant.vt)\r\n    {\r\n      case VT_EMPTY:\r\n        // _processedFileInfo.UTCLastWriteTime = _utcLastWriteTimeDefault;\r\n        break;\r\n      case VT_FILETIME:\r\n        _processedFileInfo.UTCLastWriteTime = propVariant.filetime;\r\n        _processedFileInfo.UTCLastWriteTimeIsDefined = true;\r\n        break;\r\n      default:\r\n        return E_FAIL;\r\n    }\r\n\r\n  }\r\n  {\r\n    // Get Size\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &propVariant));\r\n    bool newFileSizeDefined = (propVariant.vt != VT_EMPTY);\r\n    UInt64 newFileSize;\r\n    if (newFileSizeDefined)\r\n      newFileSize = ConvertPropVariantToUInt64(propVariant);\r\n  }\r\n\r\n  \r\n  {\r\n    // Create folders for file\r\n    int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (slashPos >= 0)\r\n      NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));\r\n  }\r\n\r\n  UString fullProcessedPath = _directoryPath + _filePath;\r\n  _diskFilePath = fullProcessedPath;\r\n\r\n  if (_processedFileInfo.IsDirectory)\r\n  {\r\n    NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n      {\r\n        PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath);\r\n        return E_ABORT;\r\n      }\r\n    }\r\n    \r\n    _outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n    if (!_outFileStreamSpec->Open(fullProcessedPath, CREATE_ALWAYS))\r\n    {\r\n      PrintString((UString)L\"can not open output file \" + fullProcessedPath);\r\n      return E_ABORT;\r\n    }\r\n    _outFileStream = outStreamLoc;\r\n    *outStream = outStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      PrintString(kExtractingString);\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kTest:\r\n      PrintString(kTestingString);\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kSkip:\r\n      PrintString(kSkippingString);\r\n      break;\r\n  };\r\n  PrintString(_filePath);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumErrors++;\r\n      PrintString(\"     \");\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          PrintString(kUnsupportedMethod);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          PrintString(kCRCFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          PrintString(kDataError);\r\n          break;\r\n        default:\r\n          PrintString(kUnknownError);\r\n      }\r\n    }\r\n  }\r\n\r\n  if (_outFileStream != NULL)\r\n  {\r\n    if (_processedFileInfo.UTCLastWriteTimeIsDefined)\r\n      _outFileStreamSpec->SetLastWriteTime(&_processedFileInfo.UTCLastWriteTime);\r\n    RINOK(_outFileStreamSpec->Close());\r\n  }\r\n  _outFileStream.Release();\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream); \r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Creating callback class\r\n\r\nstruct CDirItem\r\n{ \r\n  UInt32 Attributes;\r\n  FILETIME CreationTime;\r\n  FILETIME LastAccessTime;\r\n  FILETIME LastWriteTime;\r\n  UInt64 Size;\r\n  UString Name;\r\n  UString FullPath;\r\n  bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CArchiveUpdateCallback: \r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IUpdateCallback2\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);  \r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  UString DirPrefix;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n  bool m_NeedBeClosed;\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {};\r\n\r\n  ~CArchiveUpdateCallback() { Finilize(); }\r\n  HRESULT Finilize();\r\n\r\n  void Init(const CObjectVector<CDirItem> *dirItems)\r\n  {\r\n    DirItems = dirItems;\r\n    m_NeedBeClosed = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  if(newData != NULL)\r\n    *newData = BoolToInt(true);\r\n  if(newProperties != NULL)\r\n    *newProperties = BoolToInt(true);\r\n  if(indexInArchive != NULL)\r\n    *indexInArchive = UInt32(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    propVariant = false;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[index];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:\r\n        propVariant = dirItem.Name;\r\n        break;\r\n      case kpidIsFolder:\r\n        propVariant = dirItem.IsDirectory();\r\n        break;\r\n      case kpidSize:\r\n        propVariant = dirItem.Size;\r\n        break;\r\n      case kpidAttributes:\r\n        propVariant = dirItem.Attributes;\r\n        break;\r\n      case kpidLastAccessTime:\r\n        propVariant = dirItem.LastAccessTime;\r\n        break;\r\n      case kpidCreationTime:\r\n        propVariant = dirItem.CreationTime;\r\n        break;\r\n      case kpidLastWriteTime:\r\n        propVariant = dirItem.LastWriteTime;\r\n        break;\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveUpdateCallback::Finilize()\r\n{\r\n  if (m_NeedBeClosed)\r\n  {\r\n    PrintNewLine();\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void GetStream2(const wchar_t *name)\r\n{\r\n  PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  PrintString(name);\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  RINOK(Finilize());\r\n\r\n  const CDirItem &dirItem = (*DirItems)[index];\r\n  GetStream2(dirItem.Name);\r\n \r\n  if(dirItem.IsDirectory())\r\n    return S_OK;\r\n\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if(!inStreamSpec->Open(path))\r\n    {\r\n      DWORD sysError = ::GetLastError();\r\n      FailedCodes.Add(sysError);\r\n      FailedFiles.Add(path);\r\n      // if (systemError == ERROR_SHARING_VIOLATION)\r\n      {\r\n        PrintNewLine();\r\n        PrintError(\"WARNING: can't open file\");\r\n        // PrintString(NError::MyFormatMessageW(systemError));\r\n        return S_FALSE;\r\n      }\r\n      // return sysError;\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */)\r\n{\r\n  m_NeedBeClosed = true;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if(!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined) \r\n  {\r\n    if (AskPassword)\r\n    {\r\n      // You can ask real password here from user\r\n      // Password = GetPassword(OutStream); \r\n      // PasswordIsDefined = true;\r\n      PrintError(\"Password is not defined\");\r\n      return E_ABORT;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////////////////\r\n// Main function\r\n\r\nint \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\nmain(int argc, char* argv[])\r\n{\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  #endif\r\n\r\n  PrintStringLn(kCopyrightString);\r\n\r\n  if (argc < 3)\r\n  {\r\n    PrintStringLn(kHelpString);\r\n    return 1;\r\n  }\r\n  NWindows::NDLL::CLibrary library;\r\n  if (!library.Load(TEXT(kDllName)))\r\n  {\r\n    PrintError(\"Can not load library\");\r\n    return 1;\r\n  }\r\n  CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress(\"CreateObject\");\r\n  if (createObjectFunc == 0)\r\n  {\r\n    PrintError(\"Can not get CreateObject\");\r\n    return 1;\r\n  }\r\n\r\n  AString command = argv[1];\r\n  UString archiveName = GetUnicodeString(argv[2], CP_OEMCP);\r\n  if (command.CompareNoCase(\"a\") == 0)\r\n  {\r\n    // create archive command\r\n    if (argc < 4)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n    CObjectVector<CDirItem> dirItems;\r\n    int i;\r\n    for (i = 3; i < argc; i++)\r\n    {\r\n      CDirItem item;\r\n      UString name = GetUnicodeString(argv[i], CP_OEMCP);\r\n      \r\n      NFile::NFind::CFileInfoW fileInfo;\r\n      if (!NFile::NFind::FindFile(name, fileInfo))\r\n      {\r\n        PrintString(UString(L\"Can't find file\") + name);\r\n        return 1;\r\n      }\r\n\r\n      item.Attributes = fileInfo.Attributes;\r\n      item.Size = fileInfo.Size;\r\n      item.CreationTime = fileInfo.CreationTime;\r\n      item.LastAccessTime = fileInfo.LastAccessTime;\r\n      item.LastWriteTime = fileInfo.LastWriteTime;\r\n      item.Name = name;\r\n      item.FullPath = name;\r\n      dirItems.Add(item);\r\n    }\r\n    COutFileStream *outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;\r\n    if (!outFileStreamSpec->Create(archiveName, false))\r\n    {\r\n      PrintError(\"can't create archive file\");\r\n      return 1;\r\n    }\r\n\r\n    CMyComPtr<IOutArchive> outArchive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n\r\n    CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n    CMyComPtr<IArchiveUpdateCallback2> updateCallback(updateCallbackSpec);\r\n    updateCallbackSpec->Init(&dirItems);\r\n    // updateCallbackSpec->PasswordIsDefined = true;\r\n    // updateCallbackSpec->Password = L\"1\";\r\n\r\n    HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);\r\n    updateCallbackSpec->Finilize();\r\n    if (result != S_OK)\r\n    {\r\n      PrintError(\"Update Error\");\r\n      return 1;\r\n    }\r\n    for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)\r\n    {\r\n      PrintNewLine();\r\n      PrintString((UString)L\"Error for file: \" + updateCallbackSpec->FailedFiles[i]);\r\n    }\r\n    if (updateCallbackSpec->FailedFiles.Size() != 0)\r\n      return 1;\r\n  }\r\n  else\r\n  {\r\n    if (argc != 3)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n\r\n    bool listCommand;\r\n    if (command.CompareNoCase(\"l\") == 0)\r\n      listCommand = true;\r\n    else if (command.CompareNoCase(\"x\") == 0)\r\n      listCommand = false;\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      return 1;\r\n    }\r\n  \r\n    CMyComPtr<IInArchive> archive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n    \r\n    CInFileStream *fileSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> file = fileSpec;\r\n    \r\n    if (!fileSpec->Open(archiveName))\r\n    {\r\n      PrintError(\"Can not open archive file\");\r\n      return 1;\r\n    }\r\n\r\n    {\r\n      CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;\r\n      CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);\r\n      openCallbackSpec->PasswordIsDefined = false;\r\n      // openCallbackSpec->PasswordIsDefined = true;\r\n      // openCallbackSpec->Password = L\"1\";\r\n      \r\n      if (archive->Open(file, 0, openCallback) != S_OK)\r\n      {\r\n        PrintError(\"Can not open archive\");\r\n        return 1;\r\n      }\r\n    }\r\n    \r\n    if (listCommand)\r\n    {\r\n      // List command\r\n      UInt32 numItems = 0;\r\n      archive->GetNumberOfItems(&numItems);  \r\n      for (UInt32 i = 0; i < numItems; i++)\r\n      {\r\n        {\r\n          // Get uncompressed size of file\r\n          NWindows::NCOM::CPropVariant propVariant;\r\n          archive->GetProperty(i, kpidSize, &propVariant);\r\n          UString s = ConvertPropVariantToString(propVariant);\r\n          PrintString(s);\r\n          PrintString(\"  \");\r\n        }\r\n        {\r\n          // Get name of file\r\n          NWindows::NCOM::CPropVariant propVariant;\r\n          archive->GetProperty(i, kpidPath, &propVariant);\r\n          UString s = ConvertPropVariantToString(propVariant);\r\n          PrintString(s);\r\n        }\r\n        PrintString(\"\\n\");\r\n      }\r\n    }\r\n    else\r\n    {\r\n      // Extract command\r\n      CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n      CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);\r\n      extractCallbackSpec->Init(archive, L\"\"); // second parameter is output folder path\r\n      extractCallbackSpec->PasswordIsDefined = false;\r\n      // extractCallbackSpec->PasswordIsDefined = true;\r\n      // extractCallbackSpec->Password = L\"1\";\r\n      HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);\r\n      if (result != S_OK)\r\n      {\r\n        PrintError(\"Extract Error\");\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Client7z/Client7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Client7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Client7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\" CFG=\"Client7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Client7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Client7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Client7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Client7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Client7z - Win32 Release\"\r\n# Name \"Client7z - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"stdafx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\Client7z.cpp\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Client7z/Client7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Client7z\"=.\\Client7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Client7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Client7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include <windows.h>\r\n#include <stdio.h>\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Client7z/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\Client7z.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FileStreams.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp",
    "content": "// ArchiveCommandLine.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <io.h>\r\n#endif\r\n#include <stdio.h>\r\n\r\n#include \"Common/ListFileUtils.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/FileMapping.h\"\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ArchiveCommandLine.h\"\r\n#include \"UpdateAction.h\"\r\n#include \"Update.h\"\r\n#include \"SortUtils.h\"\r\n#include \"EnumDirItems.h\"\r\n\r\nextern bool g_CaseSensitive;\r\n\r\n#if _MSC_VER >= 1400\r\n#define MY_isatty_fileno(x) _isatty(_fileno(x))\r\n#else\r\n#define MY_isatty_fileno(x) isatty(fileno(x))\r\n#endif\r\n\r\n#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0); \r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kHelp3,\r\n  kDisableHeaders,\r\n  kDisablePercents,\r\n  kArchiveType,\r\n  kYes,\r\n  kPassword,\r\n  kProperty,\r\n  kOutputDir,\r\n  kWorkingDir,\r\n  kInclude,\r\n  kExclude,\r\n  kArInclude,\r\n  kArExclude,\r\n  kNoArName,\r\n  kUpdate,\r\n  kVolume,\r\n  kRecursed,\r\n  kSfx,\r\n  kStdIn,\r\n  kStdOut,\r\n  kOverwrite,\r\n  kEmail,\r\n  kShowDialog,\r\n  kLargePages,\r\n  kCharSet,\r\n  kTechMode,\r\n  kShareForWrite,\r\n  kCaseSensitive\r\n};\r\n\r\n}\r\n\r\n\r\nstatic const wchar_t kRecursedIDChar = 'R';\r\nstatic const wchar_t *kRecursedPostCharSet = L\"0-\";\r\n\r\nnamespace NRecursedPostCharIndex {\r\n  enum EEnum \r\n  {\r\n    kWildCardRecursionOnly = 0, \r\n    kNoRecursion = 1\r\n  };\r\n}\r\n\r\nstatic const char kImmediateNameID = '!';\r\nstatic const char kMapNameID = '#';\r\nstatic const char kFileListID = '@';\r\n\r\nstatic const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be\r\nstatic const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be\r\n\r\nstatic const wchar_t *kOverwritePostCharSet = L\"asut\";\r\n\r\nNExtract::NOverwriteMode::EEnum k_OverwriteModes[] =\r\n{\r\n  NExtract::NOverwriteMode::kWithoutPrompt,\r\n  NExtract::NOverwriteMode::kSkipExisting,\r\n  NExtract::NOverwriteMode::kAutoRename,\r\n  NExtract::NOverwriteMode::kAutoRenameExisting\r\n};\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n  {\r\n    { L\"?\",  NSwitchType::kSimple, false },\r\n    { L\"H\",  NSwitchType::kSimple, false },\r\n    { L\"-HELP\",  NSwitchType::kSimple, false },\r\n    { L\"BA\", NSwitchType::kSimple, false },\r\n    { L\"BD\", NSwitchType::kSimple, false },\r\n    { L\"T\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"Y\",  NSwitchType::kSimple, false },\r\n    { L\"P\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"M\",  NSwitchType::kUnLimitedPostString, true, 1 },\r\n    { L\"O\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"W\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"I\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"X\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AI\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AX\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AN\", NSwitchType::kSimple, false },\r\n    { L\"U\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"V\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"R\",  NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },\r\n    { L\"SFX\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SI\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SO\", NSwitchType::kSimple, false, 0 },\r\n    { L\"AO\", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},\r\n    { L\"SEML\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"AD\",  NSwitchType::kSimple, false },\r\n    { L\"SLP\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SCS\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SLT\", NSwitchType::kSimple, false },\r\n    { L\"SSW\", NSwitchType::kSimple, false },\r\n    { L\"SSC\", NSwitchType::kPostChar, false, 0, 0, L\"-\" }\r\n  };\r\n\r\nstatic const CCommandForm g_CommandForms[] = \r\n{\r\n  { L\"A\", false },\r\n  { L\"U\", false },\r\n  { L\"D\", false },\r\n  { L\"T\", false },\r\n  { L\"E\", false },\r\n  { L\"X\", false },\r\n  { L\"L\", false },\r\n  { L\"B\", false },\r\n  { L\"I\", false }\r\n};\r\n\r\nstatic const int kNumCommandForms = sizeof(g_CommandForms) /  sizeof(g_CommandForms[0]);\r\n\r\nstatic const wchar_t *kUniversalWildcard = L\"*\";\r\nstatic const int kMinNonSwitchWords = 1;\r\nstatic const int kCommandIndex = 0;\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\";\r\nstatic const char *kIncorrectListFile = \"Incorrect item in listfile.\\nCheck charset encoding and -scs switch.\";\r\nstatic const char *kIncorrectWildCardInListFile = \"Incorrect wildcard in listfile\";\r\nstatic const char *kIncorrectWildCardInCommandLine  = \"Incorrect wildcard in command line\";\r\nstatic const char *kTerminalOutError = \"I won't write compressed data to a terminal\";\r\nstatic const char *kSameTerminalError = \"I won't write data and program's messages to same terminal\";\r\n\r\nstatic void ThrowException(const char *errorMessage)\r\n{\r\n  throw CArchiveCommandLineException(errorMessage);\r\n};\r\n\r\nstatic void ThrowUserErrorException()\r\n{\r\n  ThrowException(kUserErrorMessage);\r\n};\r\n\r\n// ---------------------------\r\n\r\nbool CArchiveCommand::IsFromExtractGroup() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kExtract:\r\n    case NCommandType::kFullExtract:\r\n      return true;\r\n    default:\r\n      return false;\r\n  }\r\n}\r\n\r\nNExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kFullExtract:\r\n      return NExtract::NPathMode::kFullPathnames;\r\n    default:\r\n      return NExtract::NPathMode::kNoPathnames;\r\n  }\r\n}\r\n\r\nbool CArchiveCommand::IsFromUpdateGroup() const\r\n{\r\n  return (CommandType == NCommandType::kAdd || \r\n    CommandType == NCommandType::kUpdate ||\r\n    CommandType == NCommandType::kDelete);\r\n}\r\n\r\nstatic NRecursedType::EEnum GetRecursedTypeFromIndex(int index)\r\n{\r\n  switch (index)\r\n  {\r\n    case NRecursedPostCharIndex::kWildCardRecursionOnly: \r\n      return NRecursedType::kWildCardOnlyRecursed;\r\n    case NRecursedPostCharIndex::kNoRecursion: \r\n      return NRecursedType::kNonRecursed;\r\n    default:\r\n      return NRecursedType::kRecursed;\r\n  }\r\n}\r\n\r\nstatic bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)\r\n{\r\n  UString commandStringUpper = commandString;\r\n  commandStringUpper.MakeUpper();\r\n  UString postString;\r\n  int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper, \r\n      postString) ;\r\n  if (commandIndex < 0)\r\n    return false;\r\n  command.CommandType = (NCommandType::EEnum)commandIndex;\r\n  return true;\r\n}\r\n\r\n// ------------------------------------------------------------------\r\n// filenames functions\r\n\r\nstatic bool AddNameToCensor(NWildcard::CCensor &wildcardCensor, \r\n    const UString &name, bool include, NRecursedType::EEnum type)\r\n{\r\n  bool isWildCard = DoesNameContainWildCard(name);\r\n  bool recursed = false;\r\n\r\n  switch (type)\r\n  {\r\n    case NRecursedType::kWildCardOnlyRecursed:\r\n      recursed = isWildCard;\r\n      break;\r\n    case NRecursedType::kRecursed:\r\n      recursed = true;\r\n      break;\r\n    case NRecursedType::kNonRecursed:\r\n      recursed = false;\r\n      break;\r\n  }\r\n  wildcardCensor.AddItem(include, name, recursed);\r\n  return true;\r\n}\r\n\r\nstatic void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor, \r\n    LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)\r\n{\r\n  UStringVector names;\r\n  if (!ReadNamesFromListFile(fileName, names, codePage))\r\n    throw kIncorrectListFile;\r\n  for (int i = 0; i < names.Size(); i++)\r\n    if (!AddNameToCensor(wildcardCensor, names[i], include, type))\r\n      throw kIncorrectWildCardInListFile;\r\n}\r\n\r\nstatic void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor, \r\n    const UString &name, bool include, NRecursedType::EEnum recursedType)\r\n{\r\n  if (!AddNameToCensor(wildcardCensor, name, include, recursedType))\r\n    throw kIncorrectWildCardInCommandLine;\r\n}\r\n\r\nstatic void AddToCensorFromNonSwitchesStrings(\r\n    int startIndex,\r\n    NWildcard::CCensor &wildcardCensor, \r\n    const UStringVector &nonSwitchStrings, NRecursedType::EEnum type, \r\n    bool thereAreSwitchIncludes, UINT codePage)\r\n{\r\n  if(nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes)) \r\n    AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);\r\n  for(int i = startIndex; i < nonSwitchStrings.Size(); i++)\r\n  {\r\n    const UString &s = nonSwitchStrings[i];\r\n    if (s[0] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);\r\n    else\r\n      AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor, \r\n    const UString &switchParam, bool include, \r\n    NRecursedType::EEnum commonRecursedType)\r\n{\r\n  int splitPos = switchParam.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  UString mappingName = switchParam.Left(splitPos);\r\n  \r\n  UString switchParam2 = switchParam.Mid(splitPos + 1);\r\n  splitPos = switchParam2.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  \r\n  UString mappingSize = switchParam2.Left(splitPos);\r\n  UString eventName = switchParam2.Mid(splitPos + 1);\r\n  \r\n  UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);\r\n  UInt32 dataSize = (UInt32)dataSize64;\r\n  {\r\n    CFileMapping fileMapping;\r\n    if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName)))\r\n      ThrowException(\"Can not open mapping\");\r\n    LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize);\r\n    if (data == NULL)\r\n      ThrowException(\"MapViewOfFile error\");\r\n    try\r\n    {\r\n      const wchar_t *curData = (const wchar_t *)data;\r\n      if (*curData != 0)\r\n        ThrowException(\"Incorrect mapping data\");\r\n      UInt32 numChars = dataSize / sizeof(wchar_t);\r\n      UString name;\r\n      for (UInt32 i = 1; i < numChars; i++)\r\n      {\r\n        wchar_t c = curData[i];\r\n        if (c == L'\\0')\r\n        {\r\n          AddCommandLineWildCardToCensr(wildcardCensor, \r\n              name, include, commonRecursedType);\r\n          name.Empty();\r\n        }\r\n        else\r\n          name += c;\r\n      }\r\n      if (!name.IsEmpty())\r\n        ThrowException(\"data error\");\r\n    }\r\n    catch(...)\r\n    {\r\n      UnmapViewOfFile(data);\r\n      throw;\r\n    }\r\n    UnmapViewOfFile(data);\r\n  }\r\n  \r\n  {\r\n    NSynchronization::CManualResetEvent event;\r\n    if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)\r\n      event.Set();\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor, \r\n    const UStringVector &strings, bool include, \r\n    NRecursedType::EEnum commonRecursedType, UINT codePage)\r\n{\r\n  for(int i = 0; i < strings.Size(); i++)\r\n  {\r\n    const UString &name = strings[i];\r\n    NRecursedType::EEnum recursedType;\r\n    int pos = 0;\r\n    if (name.Length() < kSomeCludePostStringMinSize)\r\n      ThrowUserErrorException();\r\n    if (::MyCharUpper(name[pos]) == kRecursedIDChar)\r\n    {\r\n      pos++;\r\n      int index = UString(kRecursedPostCharSet).Find(name[pos]);\r\n      recursedType = GetRecursedTypeFromIndex(index);\r\n      if (index >= 0)\r\n        pos++;\r\n    }\r\n    else\r\n      recursedType = commonRecursedType;\r\n    if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)\r\n      ThrowUserErrorException();\r\n    UString tail = name.Mid(pos + 1);\r\n    if (name[pos] == kImmediateNameID)\r\n      AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);\r\n    else if (name[pos] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);\r\n    #ifdef _WIN32\r\n    else if (name[pos] == kMapNameID)\r\n      ParseMapWithPaths(wildcardCensor, tail, include, recursedType);\r\n    #endif\r\n    else\r\n      ThrowUserErrorException();\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\n// This code converts all short file names to long file names.\r\n\r\nstatic void ConvertToLongName(const UString &prefix, UString &name)\r\n{\r\n  if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n    return;\r\n  NFind::CFileInfoW fileInfo;\r\n  if (NFind::FindFile(prefix + name, fileInfo))\r\n    name = fileInfo.Name;\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)\r\n{\r\n  for (int i = 0; i < items.Size(); i++)\r\n  {\r\n    NWildcard::CItem &item = items[i];\r\n    if (item.Recursive || item.PathParts.Size() != 1)\r\n      continue;\r\n    ConvertToLongName(prefix, item.PathParts.Front());\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)\r\n{\r\n  ConvertToLongNames(prefix, node.IncludeItems);\r\n  ConvertToLongNames(prefix, node.ExcludeItems);\r\n  int i;\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n    ConvertToLongName(prefix, node.SubNodes[i].Name);\r\n  // mix folders with same name\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];\r\n    for (int j = i + 1; j < node.SubNodes.Size();)\r\n    {\r\n      const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];\r\n      if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)\r\n      {\r\n        nextNode1.IncludeItems += nextNode2.IncludeItems;\r\n        nextNode1.ExcludeItems += nextNode2.ExcludeItems;\r\n        node.SubNodes.Delete(j);\r\n      }\r\n      else\r\n        j++;\r\n    }\r\n  }\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode = node.SubNodes[i];\r\n    ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode); \r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(NWildcard::CCensor &censor)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    NWildcard::CPair &pair = censor.Pairs[i];\r\n    ConvertToLongNames(pair.Prefix, pair.Head);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\nstatic NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)\r\n{\r\n  switch(i)\r\n  {\r\n    case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;\r\n    case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;\r\n    case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;\r\n    case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;\r\n  }\r\n  throw 98111603;\r\n}\r\n\r\nconst UString kUpdatePairStateIDSet = L\"PQRXYZW\";\r\nconst int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};\r\n\r\nconst UString kUpdatePairActionIDSet = L\"0123\"; //Ignore, Copy, Compress, Create Anti\r\n\r\nconst wchar_t *kUpdateIgnoreItselfPostStringID = L\"-\"; \r\nconst wchar_t kUpdateNewArchivePostCharID = '!'; \r\n\r\n\r\nstatic bool ParseUpdateCommandString2(const UString &command, \r\n    NUpdateArchive::CActionSet &actionSet, UString &postString)\r\n{\r\n  for(int i = 0; i < command.Length();)\r\n  {\r\n    wchar_t c = MyCharUpper(command[i]);\r\n    int statePos = kUpdatePairStateIDSet.Find(c);\r\n    if (statePos < 0)\r\n    {\r\n      postString = command.Mid(i);\r\n      return true;\r\n    }\r\n    i++;\r\n    if (i >= command.Length())\r\n      return false;\r\n    int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));\r\n    if (actionPos < 0)\r\n      return false;\r\n    actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);\r\n    if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)\r\n      return false;\r\n    i++;\r\n  }\r\n  postString.Empty();\r\n  return true;\r\n}\r\n\r\nstatic void ParseUpdateCommandString(CUpdateOptions &options, \r\n    const UStringVector &updatePostStrings, \r\n    const NUpdateArchive::CActionSet &defaultActionSet)\r\n{\r\n  for(int i = 0; i < updatePostStrings.Size(); i++)\r\n  {\r\n    const UString &updateString = updatePostStrings[i];\r\n    if(updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)\r\n    {\r\n      if(options.UpdateArchiveItself)\r\n      {\r\n        options.UpdateArchiveItself = false;\r\n        options.Commands.Delete(0);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      NUpdateArchive::CActionSet actionSet = defaultActionSet;\r\n\r\n      UString postString;\r\n      if (!ParseUpdateCommandString2(updateString, actionSet, postString))\r\n        ThrowUserErrorException();\r\n      if(postString.IsEmpty())\r\n      {\r\n        if(options.UpdateArchiveItself)\r\n          options.Commands[0].ActionSet = actionSet;\r\n      }\r\n      else\r\n      {\r\n        if(MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)\r\n          ThrowUserErrorException();\r\n        CUpdateArchiveCommand uc;\r\n        UString archivePath = postString.Mid(1);\r\n        if (archivePath.IsEmpty())\r\n          ThrowUserErrorException();\r\n        uc.UserArchivePath = archivePath;\r\n        uc.ActionSet = actionSet;\r\n        options.Commands.Add(uc);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic const char kByteSymbol = 'B';\r\nstatic const char kKiloSymbol = 'K';\r\nstatic const char kMegaSymbol = 'M';\r\nstatic const char kGigaSymbol = 'G';\r\n\r\nstatic bool ParseComplexSize(const UString &src, UInt64 &result)\r\n{\r\n  UString s = src;\r\n  s.MakeUpper();\r\n\r\n  const wchar_t *start = s;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || s.Length() > numDigits + 1)\r\n    return false;\r\n  if (s.Length() == numDigits)\r\n  {\r\n    result = number;\r\n    return true;\r\n  }\r\n  int numBits;\r\n  switch (s[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      result = number;\r\n      return true;\r\n    case kKiloSymbol:\r\n      numBits = 10;\r\n      break;\r\n    case kMegaSymbol:\r\n      numBits = 20;\r\n      break;\r\n    case kGigaSymbol:\r\n      numBits = 30;\r\n      break;\r\n    default:\r\n      return false;\r\n  }\r\n  if (number >= ((UInt64)1 << (64 - numBits)))\r\n    return false;\r\n  result = number << numBits;\r\n  return true;\r\n}\r\n\r\nstatic void SetAddCommandOptions(\r\n    NCommandType::EEnum commandType, \r\n    const CParser &parser, \r\n    CUpdateOptions &options)\r\n{\r\n  NUpdateArchive::CActionSet defaultActionSet;\r\n  switch(commandType)\r\n  {\r\n    case NCommandType::kAdd: \r\n      defaultActionSet = NUpdateArchive::kAddActionSet;\r\n      break;\r\n    case NCommandType::kDelete: \r\n      defaultActionSet = NUpdateArchive::kDeleteActionSet;\r\n      break;\r\n    default: \r\n      defaultActionSet = NUpdateArchive::kUpdateActionSet;\r\n  }\r\n  \r\n  options.UpdateArchiveItself = true;\r\n  \r\n  options.Commands.Clear();\r\n  CUpdateArchiveCommand updateMainCommand;\r\n  updateMainCommand.ActionSet = defaultActionSet;\r\n  options.Commands.Add(updateMainCommand);\r\n  if(parser[NKey::kUpdate].ThereIs)\r\n    ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings, \r\n        defaultActionSet);\r\n  if(parser[NKey::kWorkingDir].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];\r\n    if (postString.IsEmpty())\r\n      NDirectory::MyGetTempPath(options.WorkingDir);\r\n    else\r\n      options.WorkingDir = postString;\r\n  }\r\n  options.SfxMode = parser[NKey::kSfx].ThereIs;\r\n  if (options.SfxMode)\r\n    options.SfxModule = parser[NKey::kSfx].PostStrings[0];\r\n\r\n  if (parser[NKey::kVolume].ThereIs)\r\n  {\r\n    const UStringVector &sv = parser[NKey::kVolume].PostStrings;\r\n    for (int i = 0; i < sv.Size(); i++)\r\n    {\r\n      UInt64 size;\r\n      if (!ParseComplexSize(sv[i], size))\r\n        ThrowException(\"Incorrect volume size\");\r\n      options.VolumesSizes.Add(size);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)\r\n{\r\n  if (parser[NKey::kProperty].ThereIs)\r\n  {\r\n    // options.MethodMode.Properties.Clear();\r\n    for(int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      CProperty property;\r\n      const UString &postString = parser[NKey::kProperty].PostStrings[i];\r\n      int index = postString.Find(L'=');\r\n      if (index < 0)\r\n        property.Name = postString;\r\n      else\r\n      {\r\n        property.Name = postString.Left(index);\r\n        property.Value = postString.Mid(index + 1);\r\n      }\r\n      properties.Add(property);\r\n    }\r\n  }\r\n}\r\n\r\nCArchiveCommandLineParser::CArchiveCommandLineParser(): \r\n  parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}\r\n\r\nvoid CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,\r\n    CArchiveCommandLineOptions &options)\r\n{\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    ThrowUserErrorException();\r\n  }\r\n\r\n  options.IsInTerminal = MY_IS_TERMINAL(stdin);\r\n  options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);\r\n  options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);\r\n  options.StdOutMode = parser[NKey::kStdOut].ThereIs;\r\n  options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;\r\n  options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs  || parser[NKey::kHelp3].ThereIs;\r\n\r\n  #ifdef _WIN32\r\n  options.LargePages = false;\r\n  if (parser[NKey::kLargePages].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kLargePages].PostStrings.Front();\r\n    if (postString.IsEmpty())\r\n      options.LargePages = true;\r\n  }\r\n  #endif\r\n}\r\n\r\nstruct CCodePagePair\r\n{\r\n  const wchar_t *Name;\r\n  UINT CodePage;\r\n};\r\n\r\nstatic CCodePagePair g_CodePagePairs[] = \r\n{\r\n  { L\"UTF-8\", CP_UTF8 },\r\n  { L\"WIN\",   CP_ACP },\r\n  { L\"DOS\",   CP_OEMCP }\r\n};\r\n\r\nstatic const int kNumCodePages = sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]);\r\n\r\nstatic bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)\r\n{\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(s, &end);\r\n  if (*end != 0)\r\n    return false;\r\n  if (number > (UInt32)0xFFFFFFFF)\r\n    return false;\r\n  v = (UInt32)number;\r\n  return true;\r\n}\r\n\r\nvoid CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)\r\n{\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n  int numNonSwitchStrings = nonSwitchStrings.Size();\r\n  if(numNonSwitchStrings < kMinNonSwitchWords)  \r\n    ThrowUserErrorException();\r\n\r\n  if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))\r\n    ThrowUserErrorException();\r\n\r\n  options.TechMode = parser[NKey::kTechMode].ThereIs;\r\n\r\n  if (parser[NKey::kCaseSensitive].ThereIs)\r\n    g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);\r\n\r\n  NRecursedType::EEnum recursedType;\r\n  if (parser[NKey::kRecursed].ThereIs)\r\n    recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);\r\n  else\r\n    recursedType = NRecursedType::kNonRecursed;\r\n\r\n  UINT codePage = CP_UTF8;\r\n  if (parser[NKey::kCharSet].ThereIs)\r\n  {\r\n    UString name = parser[NKey::kCharSet].PostStrings.Front();\r\n    name.MakeUpper();\r\n    int i;\r\n    for (i = 0; i < kNumCodePages; i++)\r\n    {\r\n      const CCodePagePair &pair = g_CodePagePairs[i];\r\n      if (name.Compare(pair.Name) == 0)\r\n      {\r\n        codePage = pair.CodePage;\r\n        break;\r\n      }\r\n    }\r\n    if (i >= kNumCodePages)\r\n      ThrowUserErrorException();\r\n  }\r\n\r\n  bool thereAreSwitchIncludes = false;\r\n  if (parser[NKey::kInclude].ThereIs)\r\n  {\r\n    thereAreSwitchIncludes = true;\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor, \r\n        parser[NKey::kInclude].PostStrings, true, recursedType, codePage);\r\n  }\r\n  if (parser[NKey::kExclude].ThereIs)\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor, \r\n        parser[NKey::kExclude].PostStrings, false, recursedType, codePage);\r\n \r\n  int curCommandIndex = kCommandIndex + 1;\r\n  bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs && \r\n      options.Command.CommandType != NCommandType::kBenchmark && \r\n      options.Command.CommandType != NCommandType::kInfo;\r\n  if (thereIsArchiveName)\r\n  {\r\n    if(curCommandIndex >= numNonSwitchStrings)  \r\n      ThrowUserErrorException();\r\n    options.ArchiveName = nonSwitchStrings[curCommandIndex++];\r\n  }\r\n\r\n  AddToCensorFromNonSwitchesStrings(\r\n      curCommandIndex, options.WildcardCensor, \r\n      nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);\r\n\r\n  options.YesToAll = parser[NKey::kYes].ThereIs;\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  options.PasswordEnabled = parser[NKey::kPassword].ThereIs;\r\n\r\n  if(options.PasswordEnabled)\r\n    options.Password = parser[NKey::kPassword].PostStrings[0];\r\n\r\n  options.StdInMode = parser[NKey::kStdIn].ThereIs;\r\n  options.ShowDialog = parser[NKey::kShowDialog].ThereIs;\r\n\r\n  if(isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if (options.StdInMode)\r\n      ThrowException(\"Reading archives from stdin is not implemented\");\r\n    if (!options.WildcardCensor.AllAreRelative())\r\n      ThrowException(\"Cannot use absolute pathnames for this command\");\r\n\r\n    NWildcard::CCensor archiveWildcardCensor;\r\n\r\n    if (parser[NKey::kArInclude].ThereIs)\r\n    {\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor, \r\n        parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);\r\n    }\r\n    if (parser[NKey::kArExclude].ThereIs)\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor, \r\n      parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);\r\n\r\n    if (thereIsArchiveName)\r\n      AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(archiveWildcardCensor);\r\n    #endif\r\n\r\n    archiveWildcardCensor.ExtendExclude();\r\n\r\n    CObjectVector<CDirItem> dirItems;\r\n    {\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);\r\n      if (res != S_OK || errorPaths.Size() > 0)\r\n        throw \"cannot find archive\";\r\n    }\r\n    UStringVector archivePaths;\r\n    int i;\r\n    for (i = 0; i < dirItems.Size(); i++)\r\n    {\r\n      const CDirItem &dirItem = dirItems[i];\r\n      if (!dirItem.IsDirectory())\r\n        archivePaths.Add(dirItem.FullPath);\r\n    }\r\n\r\n    if (archivePaths.Size() == 0)\r\n      throw \"there is no such archive\";\r\n\r\n    UStringVector archivePathsFull;\r\n\r\n    for (i = 0; i < archivePaths.Size(); i++)\r\n    {\r\n      UString fullPath;\r\n      NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);\r\n      archivePathsFull.Add(fullPath);\r\n    }\r\n    CIntVector indices;\r\n    SortFileNames(archivePathsFull, indices);\r\n    options.ArchivePathsSorted.Reserve(indices.Size());\r\n    options.ArchivePathsFullSorted.Reserve(indices.Size());\r\n    for (i = 0; i < indices.Size(); i++)\r\n    {\r\n      options.ArchivePathsSorted.Add(archivePaths[indices[i]]);\r\n      options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);\r\n    }\r\n\r\n    if (isExtractGroupCommand)\r\n    {\r\n      SetMethodOptions(parser, options.ExtractProperties); \r\n      if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)\r\n        throw kSameTerminalError;\r\n      if(parser[NKey::kOutputDir].ThereIs)\r\n      {\r\n        options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];\r\n        NFile::NName::NormalizeDirPathPrefix(options.OutputDir);\r\n      }\r\n\r\n      options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;\r\n      if(parser[NKey::kOverwrite].ThereIs)\r\n        options.OverwriteMode = \r\n            k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];\r\n      else if (options.YesToAll)\r\n        options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    CUpdateOptions &updateOptions = options.UpdateOptions;\r\n\r\n    if(parser[NKey::kArchiveType].ThereIs)\r\n      options.ArcType = parser[NKey::kArchiveType].PostStrings[0];\r\n\r\n    SetAddCommandOptions(options.Command.CommandType, parser, updateOptions); \r\n    \r\n    SetMethodOptions(parser, updateOptions.MethodMode.Properties); \r\n\r\n    if (parser[NKey::kShareForWrite].ThereIs)\r\n      updateOptions.OpenShareForWrite = true;\r\n\r\n    options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;\r\n\r\n    if (options.EnablePercents)\r\n    {\r\n      if ((options.StdOutMode && !options.IsStdErrTerminal) || \r\n         (!options.StdOutMode && !options.IsStdOutTerminal))  \r\n        options.EnablePercents = false;\r\n    }\r\n\r\n    updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;\r\n    if (updateOptions.EMailMode)\r\n    {\r\n      updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();\r\n      if (updateOptions.EMailAddress.Length() > 0)\r\n        if (updateOptions.EMailAddress[0] == L'.')\r\n        {\r\n          updateOptions.EMailRemoveAfter = true;\r\n          updateOptions.EMailAddress.Delete(0);\r\n        }\r\n    }\r\n\r\n    updateOptions.StdOutMode = options.StdOutMode;\r\n    updateOptions.StdInMode = options.StdInMode;\r\n\r\n    if (updateOptions.StdOutMode && updateOptions.EMailMode)\r\n      throw \"stdout mode and email mode cannot be combined\";\r\n    if (updateOptions.StdOutMode && options.IsStdOutTerminal)\r\n      throw kTerminalOutError;\r\n    if(updateOptions.StdInMode)\r\n      updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(options.WildcardCensor);\r\n    #endif\r\n  }\r\n  else if(options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    options.NumThreads = (UInt32)-1;\r\n    options.DictionarySize = (UInt32)-1;\r\n    options.NumIterations = 1;\r\n    if (curCommandIndex < numNonSwitchStrings)  \r\n    {\r\n      if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))\r\n        ThrowUserErrorException();\r\n    }\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      UString postString = parser[NKey::kProperty].PostStrings[i];\r\n      postString.MakeUpper();\r\n      if (postString.Length() < 2)\r\n        ThrowUserErrorException();\r\n      if (postString[0] == 'D')\r\n      {\r\n        int pos = 1;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        UInt32 logSize;\r\n        if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))\r\n          ThrowUserErrorException();\r\n        if (logSize > 31)\r\n          ThrowUserErrorException();\r\n        options.DictionarySize = 1 << logSize;\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == 'T' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        if (postString[pos] != 0)\r\n          if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))\r\n            ThrowUserErrorException();\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == '=' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] != 0)\r\n          options.Method = postString.Mid(2);\r\n      }\r\n      else\r\n        ThrowUserErrorException();\r\n    }\r\n  }\r\n  else if(options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n  }\r\n  else \r\n    ThrowUserErrorException();\r\n  options.WildcardCensor.ExtendExclude();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h",
    "content": "// ArchiveCommandLine.h\r\n\r\n#ifndef __ARCHIVECOMMANDLINE_H\r\n#define __ARCHIVECOMMANDLINE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#include \"Extract.h\"\r\n#include \"Update.h\"\r\n\r\nstruct CArchiveCommandLineException: public AString\r\n{\r\n  CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {}\r\n};\r\n\r\nnamespace NCommandType { enum EEnum\r\n{\r\n  kAdd = 0,\r\n  kUpdate,\r\n  kDelete,\r\n  kTest,\r\n  kExtract,\r\n  kFullExtract,\r\n  kList,\r\n  kBenchmark,\r\n  kInfo\r\n};}\r\n\r\nnamespace NRecursedType { enum EEnum\r\n{\r\n  kRecursed,\r\n  kWildCardOnlyRecursed,\r\n  kNonRecursed\r\n};}\r\n\r\nstruct CArchiveCommand\r\n{\r\n  NCommandType::EEnum CommandType;\r\n  bool IsFromExtractGroup() const;\r\n  bool IsFromUpdateGroup() const;\r\n  bool IsTestMode() const { return CommandType == NCommandType::kTest; }\r\n  NExtract::NPathMode::EEnum GetPathMode() const;\r\n};\r\n\r\nstruct CArchiveCommandLineOptions\r\n{\r\n  bool HelpMode;\r\n\r\n  #ifdef _WIN32\r\n  bool LargePages;\r\n  #endif\r\n\r\n  bool IsInTerminal;\r\n  bool IsStdOutTerminal;\r\n  bool IsStdErrTerminal;\r\n  bool StdInMode;\r\n  bool StdOutMode;\r\n  bool EnableHeaders;\r\n\r\n  bool YesToAll;\r\n  bool ShowDialog;\r\n  // NWildcard::CCensor ArchiveWildcardCensor;\r\n  NWildcard::CCensor WildcardCensor;\r\n\r\n  CArchiveCommand Command; \r\n  UString ArchiveName;\r\n\r\n  bool PasswordEnabled;\r\n  UString Password;\r\n\r\n  bool TechMode;\r\n  // Extract\r\n  bool AppendName;\r\n  UString OutputDir;\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n  UStringVector ArchivePathsSorted;\r\n  UStringVector ArchivePathsFullSorted;\r\n  CObjectVector<CProperty> ExtractProperties;\r\n\r\n  CUpdateOptions UpdateOptions;\r\n  UString ArcType;\r\n  bool EnablePercents;\r\n\r\n  // Benchmark \r\n  UInt32 NumIterations;\r\n  UInt32 NumThreads;\r\n  UInt32 DictionarySize;\r\n  UString Method;\r\n\r\n\r\n  CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};\r\n};\r\n\r\nclass CArchiveCommandLineParser\r\n{\r\n  NCommandLineParser::CParser parser;\r\npublic:\r\n  CArchiveCommandLineParser();\r\n  void Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options);\r\n  void Parse2(CArchiveCommandLineOptions &options);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp",
    "content": "// ArchiveExtractCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n#include \"OpenArchive.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic const wchar_t *kCantAutoRename = L\"ERROR: Can not create file with auto name\";\r\nstatic const wchar_t *kCantRenameFile = L\"ERROR: Can not rename existing file \";\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\n\r\nvoid CArchiveExtractCallback::Init(\r\n    IInArchive *archiveHandler,\r\n    IFolderArchiveExtractCallback *extractCallback2,\r\n    bool stdOutMode,\r\n    const UString &directoryPath, \r\n    const UStringVector &removePathParts,\r\n    const UString &itemDefaultName,\r\n    const FILETIME &utcLastWriteTimeDefault,\r\n    UInt32 attributesDefault,\r\n    UInt64 packSize)\r\n{\r\n  _stdOutMode = stdOutMode;\r\n  _numErrors = 0;\r\n  _unpTotal = 1;\r\n  _packTotal = packSize;\r\n\r\n  _extractCallback2 = extractCallback2;\r\n  _compressProgress.Release();\r\n  _extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);\r\n\r\n  LocalProgressSpec->Init(extractCallback2, true);\r\n  LocalProgressSpec->SendProgress = false;\r\n\r\n  _itemDefaultName = itemDefaultName;\r\n  _utcLastWriteTimeDefault = utcLastWriteTimeDefault;\r\n  _attributesDefault = attributesDefault;\r\n  _removePathParts = removePathParts;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  _unpTotal = size;\r\n  if (!_multiArchives && _extractCallback2)\r\n    return _extractCallback2->SetTotal(size);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  const UInt64 kMax = (UInt64)1 << 31;\r\n  while (v1 > kMax)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)\r\n{\r\n  NormalizeVals(packTotal, unpTotal);\r\n  NormalizeVals(unpCur, unpTotal);\r\n  if (unpTotal == 0)\r\n    unpTotal = 1;\r\n  return unpCur * packTotal / unpTotal;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_extractCallback2)\r\n    return S_OK;\r\n\r\n  if (_multiArchives)\r\n  {\r\n    if (completeValue != NULL)\r\n    {\r\n      UInt64 packCur = LocalProgressSpec->InSize + MyMultDiv64(*completeValue, _unpTotal, _packTotal);\r\n      return _extractCallback2->SetCompleted(&packCur);\r\n    }\r\n  }\r\n  return _extractCallback2->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return _localProgress->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\nvoid CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)\r\n{\r\n  fullPath = _directoryPath;\r\n  for(int i = 0; i < dirPathParts.Size(); i++)\r\n  {\r\n    if (i > 0)\r\n      fullPath += wchar_t(NFile::NName::kDirDelimiter);\r\n    fullPath += dirPathParts[i];\r\n    NFile::NDirectory::MyCreateDirectory(fullPath);\r\n  }\r\n}\r\n\r\nstatic UString MakePathNameFromParts(const UStringVector &parts)\r\n{\r\n  UString result;\r\n  for(int i = 0; i < parts.Size(); i++)\r\n  {\r\n    if(i != 0)\r\n      result += wchar_t(NFile::NName::kDirDelimiter);\r\n    result += parts[i];\r\n  }\r\n  return result;\r\n}\r\n\r\n\r\nHRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(_archiveHandler->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    filetime = prop.filetime;\r\n    filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  _encrypted = false;\r\n  _isSplit = false;\r\n  _curSize = 0;\r\n\r\n  UString fullPath;\r\n\r\n  RINOK(GetArchiveItemPath(_archiveHandler, index, _itemDefaultName, fullPath));\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDirectory));\r\n\r\n  _filePath = fullPath;\r\n\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPosition, &prop));\r\n    if (prop.vt != VT_EMPTY)\r\n    {\r\n      if (prop.vt != VT_UI8)\r\n        return E_FAIL;\r\n      _position = prop.uhVal.QuadPart;\r\n      _isSplit = true;\r\n    }\r\n  }\r\n    \r\n  RINOK(IsArchiveItemProp(_archiveHandler, index, kpidEncrypted, _encrypted));\r\n\r\n  bool newFileSizeDefined;\r\n  UInt64 newFileSize;\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    if (newFileSizeDefined)\r\n    {\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n      _curSize = newFileSize;\r\n    }\r\n  }\r\n\r\n  if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)\r\n  {\r\n    if (_stdOutMode)\r\n    {\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc = new CStdOutFileStream;\r\n      *outStream = outStreamLoc.Detach();\r\n      return S_OK;\r\n    }\r\n\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n        _processedFileInfo.Attributes = _attributesDefault;\r\n        _processedFileInfo.AttributesAreDefined = false;\r\n      }\r\n      else\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_FAIL;\r\n        _processedFileInfo.Attributes = prop.ulVal;\r\n        _processedFileInfo.AttributesAreDefined = true;\r\n      }\r\n    }\r\n\r\n    RINOK(GetTime(index, kpidCreationTime, _processedFileInfo.CreationTime,\r\n        _processedFileInfo.IsCreationTimeDefined));\r\n    RINOK(GetTime(index, kpidLastWriteTime, _processedFileInfo.LastWriteTime, \r\n        _processedFileInfo.IsLastWriteTimeDefined));\r\n    RINOK(GetTime(index, kpidLastAccessTime, _processedFileInfo.LastAccessTime,\r\n        _processedFileInfo.IsLastAccessTimeDefined));\r\n\r\n    bool isAnti = false;\r\n    RINOK(IsArchiveItemProp(_archiveHandler, index, kpidIsAnti, isAnti));\r\n\r\n    UStringVector pathParts; \r\n    SplitPathToParts(fullPath, pathParts);\r\n    \r\n    if(pathParts.IsEmpty())\r\n      return E_FAIL;\r\n    int numRemovePathParts = 0;\r\n    switch(_pathMode)\r\n    {\r\n      case NExtract::NPathMode::kFullPathnames:\r\n        break;\r\n      case NExtract::NPathMode::kCurrentPathnames:\r\n      {\r\n        numRemovePathParts = _removePathParts.Size();\r\n        if (pathParts.Size() <= numRemovePathParts)\r\n          return E_FAIL;\r\n        for (int i = 0; i < numRemovePathParts; i++)\r\n          if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0)\r\n            return E_FAIL;\r\n        break;\r\n      }\r\n      case NExtract::NPathMode::kNoPathnames:\r\n      {\r\n        numRemovePathParts = pathParts.Size() - 1;\r\n        break;\r\n      }\r\n    }\r\n    pathParts.Delete(0, numRemovePathParts);\r\n    MakeCorrectPath(pathParts);\r\n    UString processedPath = MakePathNameFromParts(pathParts);\r\n    if (!isAnti)\r\n    {\r\n      if (!_processedFileInfo.IsDirectory)\r\n      {\r\n        if (!pathParts.IsEmpty())\r\n          pathParts.DeleteBack();\r\n      }\r\n    \r\n      if (!pathParts.IsEmpty())\r\n      {\r\n        UString fullPathNew;\r\n        CreateComplexDirectory(pathParts, fullPathNew);\r\n        if (_processedFileInfo.IsDirectory)\r\n          NFile::NDirectory::SetDirTime(fullPathNew, \r\n            (WriteCreated && _processedFileInfo.IsCreationTimeDefined) ? &_processedFileInfo.CreationTime : NULL, \r\n            (WriteAccessed && _processedFileInfo.IsLastAccessTimeDefined) ? &_processedFileInfo.LastAccessTime : NULL, \r\n            (WriteModified && _processedFileInfo.IsLastWriteTimeDefined) ? &_processedFileInfo.LastWriteTime : &_utcLastWriteTimeDefault);\r\n      }\r\n    }\r\n\r\n\r\n    UString fullProcessedPath = _directoryPath + processedPath;\r\n\r\n    if(_processedFileInfo.IsDirectory)\r\n    {\r\n      _diskFilePath = fullProcessedPath;\r\n      if (isAnti)\r\n        NFile::NDirectory::MyRemoveDirectory(_diskFilePath);\r\n      return S_OK;\r\n    }\r\n\r\n    if (!_isSplit)\r\n    {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      switch(_overwriteMode)\r\n      {\r\n        case NExtract::NOverwriteMode::kSkipExisting:\r\n          return S_OK;\r\n        case NExtract::NOverwriteMode::kAskBefore:\r\n        {\r\n          Int32 overwiteResult;\r\n          RINOK(_extractCallback2->AskOverwrite(\r\n              fullProcessedPath, &fileInfo.LastWriteTime, &fileInfo.Size, fullPath, \r\n              _processedFileInfo.IsLastWriteTimeDefined ? &_processedFileInfo.LastWriteTime : NULL, \r\n              newFileSizeDefined ? &newFileSize : NULL, \r\n              &overwiteResult))\r\n\r\n          switch(overwiteResult)\r\n          {\r\n            case NOverwriteAnswer::kCancel:\r\n              return E_ABORT;\r\n            case NOverwriteAnswer::kNo:\r\n              return S_OK;\r\n            case NOverwriteAnswer::kNoToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kSkipExisting;\r\n              return S_OK;\r\n            case NOverwriteAnswer::kYesToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n              break;\r\n            case NOverwriteAnswer::kYes:\r\n              break;\r\n            case NOverwriteAnswer::kAutoRename:\r\n              _overwriteMode = NExtract::NOverwriteMode::kAutoRename;\r\n              break;\r\n            default:\r\n              return E_FAIL;\r\n          }\r\n        }\r\n      }\r\n      if (_overwriteMode == NExtract::NOverwriteMode::kAutoRename)\r\n      {\r\n        if (!AutoRenamePath(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantAutoRename) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)\r\n      {\r\n        UString existPath = fullProcessedPath;\r\n        if (!AutoRenamePath(existPath))\r\n        {\r\n          UString message = kCantAutoRename + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n        if(!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))\r\n        {\r\n          UString message = UString(kCantRenameFile) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else\r\n        if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantDeleteOutputFile) +  fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n          // return E_FAIL;\r\n        }\r\n    }\r\n    }\r\n    if (!isAnti)\r\n    {\r\n      _outFileStreamSpec = new COutFileStream;\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n      if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))\r\n      {\r\n        // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)\r\n        {\r\n          UString message = L\"can not open output file \" + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n        }\r\n      }\r\n      if (_isSplit)\r\n      {\r\n        RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));\r\n      }\r\n      _outFileStream = outStreamLoc;\r\n      *outStream = outStreamLoc.Detach();\r\n    }\r\n    _diskFilePath = fullProcessedPath;\r\n  }\r\n  else\r\n  {\r\n    *outStream = NULL;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  return _extractCallback2->PrepareOperation(_filePath, _processedFileInfo.IsDirectory, \r\n      askExtractMode, _isSplit ? &_position: 0);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n    case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n    case NArchive::NExtract::NOperationResult::kCRCError:\r\n    case NArchive::NExtract::NOperationResult::kDataError:\r\n      break;\r\n    default:\r\n      _outFileStream.Release();\r\n      return E_FAIL;\r\n  }\r\n  if (_outFileStream != NULL)\r\n  {\r\n    _outFileStreamSpec->SetTime(\r\n        (WriteCreated && _processedFileInfo.IsCreationTimeDefined) ? &_processedFileInfo.CreationTime : NULL, \r\n        (WriteAccessed && _processedFileInfo.IsLastAccessTimeDefined) ? &_processedFileInfo.LastAccessTime : NULL, \r\n        (WriteModified && _processedFileInfo.IsLastWriteTimeDefined) ? &_processedFileInfo.LastWriteTime : &_utcLastWriteTimeDefault);\r\n    _curSize = _outFileStreamSpec->ProcessedSize;\r\n    RINOK(_outFileStreamSpec->Close());\r\n    _outFileStream.Release();\r\n  }\r\n  UnpackSize += _curSize;\r\n  if (_processedFileInfo.IsDirectory)\r\n    NumFolders++;\r\n  else\r\n    NumFiles++;\r\n\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CArchiveExtractCallback::GetInStream(\r\n    const wchar_t *name, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  CInFileStream *inFile = new CInFileStream;\r\n  CMyComPtr<ISequentialInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(_srcDirectoryPrefix + name))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_cryptoGetTextPassword)\r\n  {\r\n    RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword, \r\n        &_cryptoGetTextPassword));\r\n  }\r\n  return _cryptoGetTextPassword->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h",
    "content": "// ArchiveExtractCallback.h\r\n\r\n#ifndef __ARCHIVEEXTRACTCALLBACK_H\r\n#define __ARCHIVEEXTRACTCALLBACK_H\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"IFileExtractCallback.h\"\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"ExtractMode.h\"\r\n\r\nclass CArchiveExtractCallback: \r\n  public IArchiveExtractCallback,\r\n  // public IArchiveVolumeExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(ICryptoGetTextPassword, ICompressProgressInfo)\r\n  // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IExtractCallBack\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // IArchiveVolumeExtractCallback\r\n  // STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;\r\n  CMyComPtr<ICompressProgressInfo> _compressProgress;\r\n  CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;\r\n  UString _directoryPath;\r\n  NExtract::NPathMode::EEnum _pathMode;\r\n  NExtract::NOverwriteMode::EEnum _overwriteMode;\r\n\r\n  UString _filePath;\r\n  UInt64 _position;\r\n  bool _isSplit;\r\n\r\n  UString _diskFilePath;\r\n\r\n  bool _extractMode;\r\n\r\n  bool WriteModified;\r\n  bool WriteCreated;\r\n  bool WriteAccessed;\r\n\r\n  bool _encrypted;\r\n\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME CreationTime;\r\n    FILETIME LastWriteTime;\r\n    FILETIME LastAccessTime;\r\n    UInt32 Attributes;\r\n  \r\n    bool IsCreationTimeDefined;\r\n    bool IsLastWriteTimeDefined;\r\n    bool IsLastAccessTimeDefined;\r\n\r\n    bool IsDirectory;\r\n    bool AttributesAreDefined;\r\n  } _processedFileInfo;\r\n\r\n  UInt64 _curSize;\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n  UStringVector _removePathParts;\r\n\r\n  UString _itemDefaultName;\r\n  FILETIME _utcLastWriteTimeDefault;\r\n  UInt32 _attributesDefault;\r\n  bool _stdOutMode;\r\n\r\n  void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);\r\n  HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);\r\npublic:\r\n  CArchiveExtractCallback():\r\n      WriteModified(true),\r\n      WriteCreated(false),\r\n      WriteAccessed(false),\r\n      _multiArchives(false)\r\n  {\r\n    LocalProgressSpec = new CLocalProgress();\r\n    _localProgress = LocalProgressSpec;\r\n  }\r\n\r\n  CLocalProgress *LocalProgressSpec;\r\n  CMyComPtr<ICompressProgressInfo> _localProgress;\r\n  UInt64 _packTotal;\r\n  UInt64 _unpTotal;\r\n\r\n  bool _multiArchives;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  UInt64 UnpackSize;\r\n  \r\n  void InitForMulti(bool multiArchives, \r\n      NExtract::NPathMode::EEnum pathMode,\r\n      NExtract::NOverwriteMode::EEnum overwriteMode) \r\n  { \r\n    _multiArchives = multiArchives; NumFolders = NumFiles = UnpackSize = 0; \r\n    _pathMode = pathMode;\r\n    _overwriteMode = overwriteMode;\r\n  }\r\n\r\n  void Init(\r\n      IInArchive *archiveHandler, \r\n      IFolderArchiveExtractCallback *extractCallback2,\r\n      bool stdOutMode,\r\n      const UString &directoryPath,\r\n      const UStringVector &removePathParts,\r\n      const UString &itemDefaultName,\r\n      const FILETIME &utcLastWriteTimeDefault, \r\n      UInt32 attributesDefault,\r\n      UInt64 packSize);\r\n\r\n  UInt64 _numErrors;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ArchiveName.cpp",
    "content": "// ArchiveName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)\r\n{\r\n  UString resultName = L\"Archive\";\r\n  if (fromPrev)\r\n  {\r\n    UString dirPrefix;\r\n    if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))\r\n    {\r\n      if (dirPrefix.Length() > 0)\r\n        if (dirPrefix[dirPrefix.Length() - 1] == '\\\\')\r\n        {\r\n          dirPrefix.Delete(dirPrefix.Length() - 1);\r\n          NFile::NFind::CFileInfoW fileInfo;\r\n          if (NFile::NFind::FindFile(dirPrefix, fileInfo))\r\n            resultName = fileInfo.Name;\r\n        }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if (!NFile::NFind::FindFile(srcName, fileInfo))\r\n      return resultName;\r\n    resultName = fileInfo.Name;\r\n    if (!fileInfo.IsDirectory() && !keepName)\r\n    {\r\n      int dotPos = resultName.ReverseFind('.');\r\n      if (dotPos > 0)\r\n      {\r\n        UString archiveName2 = resultName.Left(dotPos);\r\n        if (archiveName2.ReverseFind('.') < 0)\r\n          resultName = archiveName2;\r\n      }\r\n    }\r\n  }\r\n  return resultName;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ArchiveName.h",
    "content": "// ArchiveName.h\r\n\r\n#ifndef __ARCHIVENAME_H\r\n#define __ARCHIVENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp",
    "content": "// ArchiveOpenCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n  \r\nSTDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant propVariant;\r\n  if (_subArchiveMode)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidName:\r\n        propVariant = _subArchiveName;\r\n        break;\r\n    }\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  switch(propID)\r\n  {\r\n    case kpidName:\r\n      propVariant = _fileInfo.Name;\r\n      break;\r\n    case kpidIsFolder:\r\n      propVariant = _fileInfo.IsDirectory();\r\n      break;\r\n    case kpidSize:\r\n      propVariant = _fileInfo.Size;\r\n      break;\r\n    case kpidAttributes:\r\n      propVariant = (UInt32)_fileInfo.Attributes;\r\n      break;\r\n    case kpidLastAccessTime:\r\n      propVariant = _fileInfo.LastAccessTime;\r\n      break;\r\n    case kpidCreationTime:\r\n      propVariant = _fileInfo.CreationTime;\r\n      break;\r\n    case kpidLastWriteTime:\r\n      propVariant = _fileInfo.LastWriteTime;\r\n      break;\r\n    }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nint COpenCallbackImp::FindName(const UString &name)\r\n{\r\n  for (int i = 0; i < FileNames.Size(); i++)\r\n    if (name.CompareNoCase(FileNames[i]) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstruct CInFileStreamVol: public CInFileStream\r\n{\r\n  UString Name;\r\n  COpenCallbackImp *OpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;\r\n  ~CInFileStreamVol()\r\n  {\r\n    int index = OpenCallbackImp->FindName(Name);\r\n    if (index >= 0)\r\n      OpenCallbackImp->FileNames.Delete(index);\r\n  }\r\n};\r\n\r\nSTDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (_subArchiveMode)\r\n    return S_FALSE;\r\n  if (Callback)\r\n  {\r\n    RINOK(Callback->CheckBreak());\r\n  }\r\n  *inStream = NULL;\r\n  UString fullPath = _folderPrefix + name;\r\n  if (!NFile::NFind::FindFile(fullPath, _fileInfo))\r\n    return S_FALSE;\r\n  if (_fileInfo.IsDirectory())\r\n    return S_FALSE;\r\n  CInFileStreamVol *inFile = new CInFileStreamVol;\r\n  CMyComPtr<IInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(fullPath))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  inFile->Name = name;\r\n  inFile->OpenCallbackImp = this;\r\n  inFile->OpenCallbackRef = this;\r\n  FileNames.Add(name);\r\n  TotalSize += _fileInfo.Size;\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!Callback)\r\n    return E_NOTIMPL;\r\n  return Callback->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n#endif\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h",
    "content": "// ArchiveOpenCallback.h\r\n\r\n#ifndef __ARCHIVE_OPEN_CALLBACK_H\r\n#define __ARCHIVE_OPEN_CALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#ifndef _NO_CRYPTO\r\n#include \"../../IPassword.h\"\r\n#endif  \r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct IOpenCallbackUI\r\n{\r\n  virtual HRESULT CheckBreak() = 0;\r\n  virtual HRESULT SetTotal(const UInt64 *files, const UInt64 *bytes) = 0;\r\n  virtual HRESULT SetCompleted(const UInt64 *files, const UInt64 *bytes) = 0;\r\n  #ifndef _NO_CRYPTO\r\n  virtual HRESULT CryptoGetTextPassword(BSTR *password) = 0;\r\n  virtual HRESULT GetPasswordIfAny(UString &password) = 0;\r\n  virtual bool WasPasswordAsked() = 0;\r\n  virtual void ClearPasswordWasAskedFlag() = 0;\r\n  #endif  \r\n};\r\n\r\nclass COpenCallbackImp: \r\n  public IArchiveOpenCallback,\r\n  public IArchiveOpenVolumeCallback,\r\n  public IArchiveOpenSetSubArchiveName,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif  \r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifndef _NO_CRYPTO\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveOpenVolumeCallback, \r\n      ICryptoGetTextPassword,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      IArchiveOpenVolumeCallback, \r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #endif\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  // IArchiveOpenVolumeCallback\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream);\r\n\r\n  #ifndef _NO_CRYPTO\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n  #endif\r\n\r\n  STDMETHOD(SetSubArchiveName(const wchar_t *name))\r\n  {\r\n    _subArchiveMode = true;\r\n    _subArchiveName = name;\r\n    return  S_OK;\r\n  }\r\n\r\nprivate:\r\n  UString _folderPrefix;\r\n  NWindows::NFile::NFind::CFileInfoW _fileInfo;\r\n  bool _subArchiveMode;\r\n  UString _subArchiveName;\r\npublic:\r\n  UStringVector FileNames;\r\n  IOpenCallbackUI *Callback;\r\n  UInt64 TotalSize;\r\n\r\n  COpenCallbackImp(): Callback(NULL) {}\r\n  void Init(const UString &folderPrefix,  const UString &fileName)\r\n  {\r\n    _folderPrefix = folderPrefix;\r\n    if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))\r\n      throw 1;\r\n    FileNames.Clear();\r\n    _subArchiveMode = false;\r\n    TotalSize = 0;\r\n  }\r\n  int FindName(const UString &name);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/DefaultName.cpp",
    "content": "// DefaultName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nUString GetDefaultName2(const UString &fileName, \r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  int extLength = extension.Length();\r\n  int fileNameLength = fileName.Length();\r\n  if (fileNameLength > extLength + 1)\r\n  {\r\n    int dotPos = fileNameLength - (extLength + 1);\r\n    if (fileName[dotPos] == '.')\r\n      if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)\r\n        return fileName.Left(dotPos) + addSubExtension;\r\n  }\r\n  int dotPos = fileName.ReverseFind(L'.');\r\n  if (dotPos > 0)\r\n    return fileName.Left(dotPos) + addSubExtension;\r\n  return kEmptyFileAlias;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/DefaultName.h",
    "content": "// DefaultName.h\r\n\r\n#ifndef __DEFAULTNAME_H\r\n#define __DEFAULTNAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString GetDefaultName2(const UString &fileName, \r\n    const UString &extension, const UString &addSubExtension);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/DirItem.h",
    "content": "// DirItem.h\r\n\r\n#ifndef __DIR_ITEM_H\r\n#define __DIR_ITEM_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nstruct CDirItem\r\n{ \r\n  UInt32 Attributes;\r\n  FILETIME CreationTime;\r\n  FILETIME LastAccessTime;\r\n  FILETIME LastWriteTime;\r\n  UInt64 Size;\r\n  UString Name;\r\n  UString FullPath;\r\n  bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nstruct CArchiveItem\r\n{ \r\n  bool IsDirectory;\r\n  // DWORD Attributes;\r\n  // NWindows::NCOM::CPropVariant LastWriteTime;\r\n  FILETIME LastWriteTime;\r\n  bool SizeIsDefined;\r\n  UInt64 Size;\r\n  UString Name;\r\n  bool Censored;\r\n  int IndexInServer;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/EnumDirItems.cpp",
    "content": "// EnumDirItems.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nvoid AddDirFileInfo(\r\n    const UString &prefix,        // prefix for logical path\r\n    const UString &fullPathName,  // path on disk: can be relative to some basePrefix\r\n    const NFind::CFileInfoW &fileInfo, \r\n    CObjectVector<CDirItem> &dirItems)\r\n{\r\n  CDirItem item;\r\n  item.Attributes = fileInfo.Attributes;\r\n  item.Size = fileInfo.Size;\r\n  item.CreationTime = fileInfo.CreationTime;\r\n  item.LastAccessTime = fileInfo.LastAccessTime;\r\n  item.LastWriteTime = fileInfo.LastWriteTime;\r\n  item.Name = prefix + fileInfo.Name;\r\n  item.FullPath = fullPathName;\r\n  dirItems.Add(item);\r\n}\r\n\r\nstatic void EnumerateDirectory(\r\n    const UString &baseFolderPrefix,  // base (disk) prefix for scanning  \r\n    const UString &directory,         // additional disk prefix starting from baseFolderPrefix\r\n    const UString &prefix,            // logical prefix\r\n    CObjectVector<CDirItem> &dirItems,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  NFind::CEnumeratorW enumerator(baseFolderPrefix + directory + wchar_t(kAnyStringWildcard));\r\n  for (;;)\r\n  { \r\n    NFind::CFileInfoW fileInfo;\r\n    bool found;\r\n    if (!enumerator.Next(fileInfo, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(baseFolderPrefix + directory);\r\n      return;\r\n    }\r\n    if (!found)\r\n      break;\r\n    AddDirFileInfo(prefix, directory + fileInfo.Name, fileInfo, dirItems);\r\n    if (fileInfo.IsDirectory())\r\n    {\r\n      EnumerateDirectory(baseFolderPrefix, directory + fileInfo.Name + wchar_t(kDirDelimiter), \r\n          prefix + fileInfo.Name + wchar_t(kDirDelimiter), dirItems, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nvoid EnumerateDirItems(\r\n    const UString &baseFolderPrefix,   // base (disk) prefix for scanning  \r\n    const UStringVector &fileNames,    // names relative to baseFolderPrefix\r\n    const UString &archiveNamePrefix, \r\n    CObjectVector<CDirItem> &dirItems,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for(int i = 0; i < fileNames.Size(); i++)\r\n  {\r\n    const UString &fileName = fileNames[i];\r\n    NFind::CFileInfoW fileInfo;\r\n    if (!NFind::FindFile(baseFolderPrefix + fileName, fileInfo))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(baseFolderPrefix + fileName);\r\n      continue;\r\n    }\r\n    AddDirFileInfo(archiveNamePrefix, fileName, fileInfo, dirItems);\r\n    if (fileInfo.IsDirectory())\r\n    {\r\n      EnumerateDirectory(baseFolderPrefix, fileName + wchar_t(kDirDelimiter), \r\n          archiveNamePrefix + fileInfo.Name +  wchar_t(kDirDelimiter), \r\n          dirItems, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nstatic HRESULT EnumerateDirItems(\r\n    const NWildcard::CCensorNode &curNode, \r\n    const UString &diskPrefix,        // full disk path prefix \r\n    const UString &archivePrefix,     // prefix from root\r\n    const UStringVector &addArchivePrefix,  // prefix from curNode\r\n    CObjectVector<CDirItem> &dirItems, \r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  if (!enterToSubFolders)\r\n    if (curNode.NeedCheckSubDirs())\r\n      enterToSubFolders = true;\r\n  if (callback)\r\n    RINOK(callback->CheckBreak());\r\n\r\n  // try direct_names case at first\r\n  if (addArchivePrefix.IsEmpty() && !enterToSubFolders)\r\n  {\r\n    // check that all names are direct\r\n    int i;\r\n    for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n    {\r\n      const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n      if (item.Recursive || item.PathParts.Size() != 1)\r\n        break;\r\n      const UString &name = item.PathParts.Front();\r\n      if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n        break;\r\n    }\r\n    if (i == curNode.IncludeItems.Size())\r\n    {\r\n      // all names are direct (no wildcards)\r\n      // so we don't need file_system's dir enumerator\r\n      CRecordVector<bool> needEnterVector;\r\n      for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n      {\r\n        const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n        const UString &name = item.PathParts.Front();\r\n        const UString fullPath = diskPrefix + name;\r\n        NFind::CFileInfoW fileInfo;\r\n        if (!NFind::FindFile(fullPath, fileInfo))\r\n        {\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        bool isDir = fileInfo.IsDirectory();\r\n        if (isDir && !item.ForDir || !isDir && !item.ForFile)\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        const UString realName = fileInfo.Name;\r\n        const UString realDiskPath = diskPrefix + realName;\r\n        {\r\n          UStringVector pathParts;\r\n          pathParts.Add(fileInfo.Name);\r\n          if (curNode.CheckPathToRoot(false, pathParts, !isDir))\r\n            continue;\r\n        }\r\n        AddDirFileInfo(archivePrefix, realDiskPath, fileInfo, dirItems);\r\n        if (!isDir)\r\n          continue;\r\n        \r\n        UStringVector addArchivePrefixNew;\r\n        const NWildcard::CCensorNode *nextNode = 0;\r\n        int index = curNode.FindSubNode(name);\r\n        if (index >= 0)\r\n        {\r\n          for (int t = needEnterVector.Size(); t <= index; t++)\r\n            needEnterVector.Add(true);\r\n          needEnterVector[index] = false;\r\n          nextNode = &curNode.SubNodes[index];\r\n        }\r\n        else\r\n        {\r\n          nextNode = &curNode;\r\n          addArchivePrefixNew.Add(name); // don't change it to realName. It's for shortnames support\r\n        }\r\n        RINOK(EnumerateDirItems(*nextNode,   \r\n            realDiskPath + wchar_t(kDirDelimiter), \r\n            archivePrefix + realName + wchar_t(kDirDelimiter), \r\n            addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes));\r\n      }\r\n      for (i = 0; i < curNode.SubNodes.Size(); i++)\r\n      {\r\n        if (i < needEnterVector.Size())\r\n          if (!needEnterVector[i])\r\n            continue;\r\n        const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];\r\n        const UString fullPath = diskPrefix + nextNode.Name;\r\n        NFind::CFileInfoW fileInfo;\r\n        if (!NFind::FindFile(fullPath, fileInfo))\r\n        {\r\n          if (!nextNode.AreThereIncludeItems())\r\n            continue;\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        if (!fileInfo.IsDirectory())\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        RINOK(EnumerateDirItems(nextNode, \r\n            diskPrefix + fileInfo.Name + wchar_t(kDirDelimiter), \r\n            archivePrefix + fileInfo.Name + wchar_t(kDirDelimiter), \r\n            UStringVector(), dirItems, false, callback, errorPaths, errorCodes));\r\n      }\r\n      return S_OK;\r\n    }\r\n  }\r\n\r\n\r\n  NFind::CEnumeratorW enumerator(diskPrefix + wchar_t(kAnyStringWildcard));\r\n  for (;;)\r\n  {\r\n    NFind::CFileInfoW fileInfo;\r\n    bool found;\r\n    if (!enumerator.Next(fileInfo, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(diskPrefix);\r\n      break;\r\n    }\r\n    if (!found)\r\n      break;\r\n\r\n    if (callback)\r\n      RINOK(callback->CheckBreak());\r\n    const UString &name = fileInfo.Name;\r\n    bool enterToSubFolders2 = enterToSubFolders;\r\n    UStringVector addArchivePrefixNew = addArchivePrefix;\r\n    addArchivePrefixNew.Add(name);\r\n    {\r\n      UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);\r\n      if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fileInfo.IsDirectory()))\r\n        continue;\r\n    }\r\n    if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fileInfo.IsDirectory()))\r\n    {\r\n      AddDirFileInfo(archivePrefix, diskPrefix + name, fileInfo, dirItems);\r\n      if (fileInfo.IsDirectory())\r\n        enterToSubFolders2 = true;\r\n    }\r\n    if (!fileInfo.IsDirectory())\r\n      continue;\r\n\r\n    const NWildcard::CCensorNode *nextNode = 0;\r\n    if (addArchivePrefix.IsEmpty())\r\n    {\r\n      int index = curNode.FindSubNode(name);\r\n      if (index >= 0)\r\n        nextNode = &curNode.SubNodes[index];\r\n    }\r\n    if (!enterToSubFolders2 && nextNode == 0)\r\n      continue;\r\n\r\n    addArchivePrefixNew = addArchivePrefix;\r\n    if (nextNode == 0)\r\n    {\r\n      nextNode = &curNode;\r\n      addArchivePrefixNew.Add(name);\r\n    }\r\n    RINOK(EnumerateDirItems(*nextNode,   \r\n        diskPrefix + name + wchar_t(kDirDelimiter), \r\n        archivePrefix + name + wchar_t(kDirDelimiter), \r\n        addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor, \r\n    CObjectVector<CDirItem> &dirItems, \r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    const NWildcard::CPair &pair = censor.Pairs[i];\r\n    RINOK(EnumerateDirItems(pair.Head, pair.Prefix, L\"\", UStringVector(), dirItems, false, \r\n        callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/EnumDirItems.h",
    "content": "// EnumDirItems.h\r\n\r\n#ifndef __ENUM_DIR_ITEMS_H\r\n#define __ENUM_DIR_ITEMS_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"DirItem.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n\r\nvoid AddDirFileInfo(\r\n    const UString &prefix, \r\n    const UString &fullPathName,\r\n    const NWindows::NFile::NFind::CFileInfoW &fileInfo, \r\n    CObjectVector<CDirItem> &dirItems);\r\n\r\n\r\nvoid EnumerateDirItems(\r\n    const UString &baseFolderPrefix,\r\n    const UStringVector &fileNames,\r\n    const UString &archiveNamePrefix, \r\n    CObjectVector<CDirItem> &dirItems, \r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\nstruct IEnumDirItemCallback\r\n{\r\n  virtual HRESULT CheckBreak() { return  S_OK; }\r\n};\r\n\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor, \r\n    CObjectVector<CDirItem> &dirItems, \r\n    IEnumDirItemCallback *callback, \r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ExitCode.h",
    "content": "// ExitCode.h\r\n\r\n#ifndef __EXIT_CODE_H\r\n#define __EXIT_CODE_H\r\n\r\nnamespace NExitCode {\r\n\r\nenum EEnum {\r\n\r\n  kSuccess       = 0,     // Successful operation\r\n  kWarning       = 1,     // Non fatal error(s) occurred\r\n  kFatalError    = 2,     // A fatal error occurred\r\n  // kCRCError      = 3,     // A CRC error occurred when unpacking     \r\n  // kLockedArchive = 4,     // Attempt to modify an archive previously locked\r\n  // kWriteError    = 5,     // Write to disk error\r\n  // kOpenError     = 6,     // Open file error\r\n  kUserError     = 7,     // Command line option error\r\n  kMemoryError   = 8,     // Not enough memory for operation\r\n  // kCreateFileError = 9,     // Create file error\r\n  \r\n  kUserBreak     = 255   // User stopped the process\r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/Extract.cpp",
    "content": "// Extract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Extract.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n#include \"SetProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT DecompressArchive(\r\n    IInArchive *archive,\r\n    UInt64 packSize,\r\n    const UString &defaultName,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IExtractCallbackUI *callback,\r\n    CArchiveExtractCallback *extractCallbackSpec,\r\n    UString &errorMessage)\r\n{\r\n  CRecordVector<UInt32> realIndices;\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UString filePath;\r\n    RINOK(GetArchiveItemPath(archive, i, options.DefaultItemName, filePath));\r\n    bool isFolder;\r\n    RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n    if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n      continue;\r\n    realIndices.Add(i);\r\n  }\r\n  if (realIndices.Size() == 0)\r\n  {\r\n    callback->ThereAreNoFiles();\r\n    return S_OK;\r\n  }\r\n\r\n  UStringVector removePathParts;\r\n\r\n  UString outDir = options.OutputDir;\r\n  outDir.Replace(L\"*\", defaultName);\r\n  if(!outDir.IsEmpty())\r\n    if(!NFile::NDirectory::CreateComplexDirectory(outDir))\r\n    {\r\n      HRESULT res = ::GetLastError();\r\n      if (res == S_OK)\r\n        res = E_FAIL;\r\n      errorMessage = ((UString)L\"Can not create output directory \") + outDir;\r\n      return res;\r\n    }\r\n\r\n  extractCallbackSpec->Init(\r\n      archive, \r\n      callback,\r\n      options.StdOutMode,\r\n      outDir, \r\n      removePathParts, \r\n      options.DefaultItemName, \r\n      options.ArchiveFileInfo.LastWriteTime,\r\n      options.ArchiveFileInfo.Attributes,\r\n      packSize);\r\n\r\n  #ifdef COMPRESS_MT\r\n  RINOK(SetProperties(archive, options.Properties));\r\n  #endif\r\n\r\n  HRESULT result = archive->Extract(&realIndices.Front(), \r\n    realIndices.Size(), options.TestMode? 1: 0, extractCallbackSpec);\r\n\r\n  return callback->ExtractResult(result);\r\n}\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,    \r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &optionsSpec,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback, \r\n    UString &errorMessage, \r\n    CDecompressStat &stat)\r\n{\r\n  stat.Clear();\r\n  CExtractOptions options = optionsSpec;\r\n  int i;\r\n  UInt64 totalPackSize = 0;\r\n  CRecordVector<UInt64> archiveSizes;\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW archiveFileInfo;\r\n    if (!NFile::NFind::FindFile(archivePath, archiveFileInfo))\r\n      throw \"there is no such archive\";\r\n    if (archiveFileInfo.IsDirectory())\r\n      throw \"can't decompress folder\";\r\n    archiveSizes.Add(archiveFileInfo.Size);\r\n    totalPackSize += archiveFileInfo.Size;\r\n  }\r\n  CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n  CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);\r\n  bool multi = (archivePaths.Size() > 1);\r\n  extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);\r\n  if (multi)\r\n  {\r\n    RINOK(extractCallback->SetTotal(totalPackSize));  \r\n  }\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW archiveFileInfo;\r\n    if (!NFile::NFind::FindFile(archivePath, archiveFileInfo))\r\n      throw \"there is no such archive\";\r\n\r\n    if (archiveFileInfo.IsDirectory())\r\n      throw \"there is no such archive\";\r\n\r\n    options.ArchiveFileInfo = archiveFileInfo;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    openCallback->ClearPasswordWasAskedFlag();\r\n    #endif\r\n\r\n    RINOK(extractCallback->BeforeOpen(archivePath));\r\n    CArchiveLink archiveLink;\r\n    HRESULT result = MyOpenArchive(codecs, archivePath, archiveLink, openCallback);\r\n\r\n    bool crypted = false;\r\n    #ifndef _NO_CRYPTO\r\n    crypted = openCallback->WasPasswordAsked();\r\n    #endif\r\n\r\n    RINOK(extractCallback->OpenResult(archivePath, result, crypted));\r\n    if (result != S_OK)\r\n      continue;\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n        totalPackSize -= archiveSizes[index];\r\n        archiveSizes.Delete(index);\r\n      }\r\n    }\r\n    if (archiveLink.VolumePaths.Size() != 0)\r\n    {\r\n      totalPackSize += archiveLink.VolumesSize;\r\n      RINOK(extractCallback->SetTotal(totalPackSize));  \r\n    }\r\n\r\n    #ifndef _NO_CRYPTO\r\n    UString password;\r\n    RINOK(openCallback->GetPasswordIfAny(password));\r\n    if (!password.IsEmpty())\r\n    {\r\n      RINOK(extractCallback->SetPassword(password));\r\n    }\r\n    #endif\r\n\r\n    options.DefaultItemName = archiveLink.GetDefaultItemName();\r\n    RINOK(DecompressArchive(\r\n        archiveLink.GetArchive(), \r\n        archiveFileInfo.Size + archiveLink.VolumesSize,\r\n        archiveLink.GetDefaultItemName(),\r\n        wildcardCensor, options, extractCallback, extractCallbackSpec, errorMessage));\r\n    extractCallbackSpec->LocalProgressSpec->InSize += archiveFileInfo.Size + \r\n        archiveLink.VolumesSize;\r\n    extractCallbackSpec->LocalProgressSpec->OutSize = extractCallbackSpec->UnpackSize;\r\n    if (!errorMessage.IsEmpty())\r\n      return E_FAIL;\r\n  }\r\n  stat.NumFolders = extractCallbackSpec->NumFolders;\r\n  stat.NumFiles = extractCallbackSpec->NumFiles;\r\n  stat.UnpackSize = extractCallbackSpec->UnpackSize;\r\n  stat.NumArchives = archivePaths.Size();\r\n  stat.PackSize = extractCallbackSpec->LocalProgressSpec->InSize;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/Extract.h",
    "content": "// Extract.h\r\n\r\n#ifndef __EXTRACT_H\r\n#define __EXTRACT_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"ExtractMode.h\"\r\n#include \"Property.h\"\r\n\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nclass CExtractOptions\r\n{\r\npublic:\r\n  bool StdOutMode;\r\n  bool TestMode;\r\n  NExtract::NPathMode::EEnum PathMode;\r\n\r\n  UString OutputDir;\r\n  bool YesToAll;\r\n  UString DefaultItemName;\r\n  NWindows::NFile::NFind::CFileInfoW ArchiveFileInfo;\r\n  \r\n  // bool ShowDialog;\r\n  // bool PasswordEnabled;\r\n  // UString Password;\r\n  #ifdef COMPRESS_MT\r\n  CObjectVector<CProperty> Properties;\r\n  #endif\r\n\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  CCodecs *Codecs;\r\n  #endif\r\n\r\n  CExtractOptions(): \r\n      StdOutMode(false), \r\n      YesToAll(false), \r\n      TestMode(false),\r\n      PathMode(NExtract::NPathMode::kFullPathnames),\r\n      OverwriteMode(NExtract::NOverwriteMode::kAskBefore)\r\n      {}\r\n\r\n  /*\r\n    bool FullPathMode() const { return (ExtractMode == NExtractMode::kTest) || \r\n    (ExtractMode == NExtractMode::kFullPath); }\r\n  */\r\n};\r\n\r\nstruct CDecompressStat\r\n{\r\n  UInt64 NumArchives;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  void Clear() { NumArchives = PackSize = UnpackSize = NumFolders = NumFiles = 0; }\r\n};\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage, \r\n    CDecompressStat &stat);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ExtractMode.h",
    "content": "// ExtractMode.h\r\n\r\n#ifndef __EXTRACT_MODE_H\r\n#define __EXTRACT_MODE_H\r\n\r\nnamespace NExtract {\r\n  \r\n  namespace NPathMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kFullPathnames,\r\n      kCurrentPathnames,\r\n      kNoPathnames\r\n    };\r\n  }\r\n  \r\n  namespace NOverwriteMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kAskBefore,\r\n      kWithoutPrompt,\r\n      kSkipExisting,\r\n      kAutoRename,\r\n      kAutoRenameExisting\r\n    };\r\n  }\r\n}  \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp",
    "content": "// ExtractingFilePath.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ExtractingFilePath.h\"\r\n\r\nstatic UString ReplaceIncorrectChars(const UString &s)\r\n{\r\n  #ifdef _WIN32\r\n  UString res;\r\n  for (int i = 0; i < s.Length(); i++)\r\n  {\r\n    wchar_t c = s[i];\r\n    if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>'  || c == '|' || c == ':' || c == '\"')\r\n      c = '_';\r\n    res += c;\r\n  }\r\n  return res;\r\n  #else\r\n  return s;\r\n  #endif\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t *g_ReservedNames[] =\r\n{\r\n  L\"CON\", L\"PRN\", L\"AUX\", L\"NUL\"\r\n};\r\n\r\nstatic bool CheckTail(const UString &name, int len)\r\n{\r\n  int dotPos = name.Find(L'.');\r\n  if (dotPos < 0)\r\n    dotPos = name.Length();\r\n  UString s = name.Left(dotPos);\r\n  s.TrimRight();\r\n  return (s.Length() != len);\r\n}\r\n\r\nstatic bool CheckNameNum(const UString &name, const wchar_t *reservedName)\r\n{\r\n  int len = MyStringLen(reservedName);\r\n  if (name.Length() <= len)\r\n    return true;\r\n  if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n    return true;\r\n  wchar_t c = name[len];\r\n  if (c < L'0' || c > L'9')\r\n    return true;\r\n  return CheckTail(name, len + 1);\r\n}\r\n\r\nstatic bool IsSupportedName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++)\r\n  {\r\n    const wchar_t *reservedName = g_ReservedNames[i];\r\n    int len = MyStringLen(reservedName);\r\n    if (name.Length() < len)\r\n      continue;\r\n    if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n      continue;\r\n    if (!CheckTail(name, len))\r\n      return false;\r\n  }\r\n  if (!CheckNameNum(name, L\"COM\"))\r\n    return false;\r\n  return CheckNameNum(name, L\"LPT\");\r\n}\r\n#endif\r\n\r\nstatic UString GetCorrectFileName(const UString &path)\r\n{\r\n  if (path == L\"..\" || path == L\".\")\r\n    return UString();\r\n  return ReplaceIncorrectChars(path);\r\n}\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts)\r\n{\r\n  for (int i = 0; i < pathParts.Size();)\r\n  {\r\n    UString &s = pathParts[i];\r\n    s = GetCorrectFileName(s);\r\n    if (s.IsEmpty())\r\n      pathParts.Delete(i);\r\n    else\r\n    {\r\n      #ifdef _WIN32\r\n      if (!IsSupportedName(s))\r\n        s = (UString)L\"_\" + s;\r\n      #endif\r\n      i++;\r\n    }\r\n  }\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ExtractingFilePath.h",
    "content": "// ExtractingFilePath.h\r\n\r\n#ifndef __EXTRACTINGFILEPATH_H\r\n#define __EXTRACTINGFILEPATH_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/IFileExtractCallback.h",
    "content": "// IFileExtractCallback.h\r\n\r\n#ifndef __IFILEEXTRACTCALLBACK_H\r\n#define __IFILEEXTRACTCALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"../../IDecl.h\"\r\n\r\nnamespace NOverwriteAnswer\r\n{\r\n  enum EEnum\r\n  {\r\n    kYes,\r\n    kYesToAll,\r\n    kNo,\r\n    kNoToAll,\r\n    kAutoRename,\r\n    kCancel\r\n  };\r\n}\r\n\r\nDECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)\r\n{\r\npublic:\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer) PURE;\r\n  STDMETHOD(PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position) PURE;\r\n  STDMETHOD(MessageError)(const wchar_t *message) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE;\r\n};\r\n\r\nstruct IExtractCallbackUI: IFolderArchiveExtractCallback\r\n{\r\n  virtual HRESULT BeforeOpen(const wchar_t *name) = 0;\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted) = 0;\r\n  virtual HRESULT ThereAreNoFiles() = 0;\r\n  virtual HRESULT ExtractResult(HRESULT result) = 0;\r\n  virtual HRESULT SetPassword(const UString &password) = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/LoadCodecs.cpp",
    "content": "// LoadCodecs.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LoadCodecs.h\"\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Common/StringToInt.h\"\r\n#endif\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/FileFind.h\"\r\n#include \"../../../Windows/DLL.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Windows/ResourceString.h\"\r\nstatic const UINT kIconTypesResId = 100;\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/Registry.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\n#ifdef _WIN32\r\nextern HINSTANCE g_hInstance;\r\n#endif\r\n\r\nstatic CSysString GetLibraryFolderPrefix()\r\n{\r\n  #ifdef _WIN32\r\n  TCHAR fullPath[MAX_PATH + 1];\r\n  ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);\r\n  CSysString path = fullPath;\r\n  int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  return path.Left(pos + 1);\r\n  #else\r\n  return CSysString(); // FIX IT\r\n  #endif\r\n}\r\n\r\n#define kCodecsFolderName TEXT(\"Codecs\")\r\n#define kFormatsFolderName TEXT(\"Formats\")\r\nstatic TCHAR *kMainDll = TEXT(\"7z.dll\");\r\n\r\n#ifdef _WIN32\r\nstatic LPCTSTR kRegistryPath = TEXT(\"Software\\\\7-zip\");\r\nstatic LPCTSTR kProgramPathValue = TEXT(\"Path\");\r\nstatic bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)\r\n{\r\n  NRegistry::CKey key;\r\n  if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)\r\n    if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)\r\n    {\r\n      NName::NormalizeDirPathPrefix(path);\r\n      return true;\r\n    }\r\n  return false;\r\n}\r\n\r\n#endif\r\n\r\nCSysString GetBaseFolderPrefixFromRegistry()\r\n{\r\n  CSysString moduleFolderPrefix = GetLibraryFolderPrefix();\r\n  NFind::CFileInfo fileInfo;\r\n  if (NFind::FindFile(moduleFolderPrefix + kMainDll, fileInfo))\r\n    if (!fileInfo.IsDirectory())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fileInfo))\r\n    if (fileInfo.IsDirectory())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fileInfo))\r\n    if (fileInfo.IsDirectory())\r\n      return moduleFolderPrefix;\r\n  #ifdef _WIN32\r\n  CSysString path;\r\n  if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))\r\n    return path;\r\n  if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))\r\n    return path;\r\n  #endif\r\n  return moduleFolderPrefix;\r\n}\r\n\r\ntypedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);\r\ntypedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, void **outObject);\r\ntypedef UInt32 (WINAPI *SetLargePageModeFunc)();\r\n\r\n\r\nstatic HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 index, \r\n    PROPID propId, CLSID &clsId, bool &isAssigned)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  isAssigned = false;\r\n  RINOK(getMethodProperty(index, propId, &prop));\r\n  if (prop.vt == VT_BSTR)\r\n  {\r\n    isAssigned = true;\r\n    clsId = *(const GUID *)prop.bstrVal;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::LoadCodecs()\r\n{\r\n  CCodecLib &lib = Libs.Back();\r\n  lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress(\"GetMethodProperty\");\r\n  if (lib.GetMethodProperty == NULL)\r\n    return S_OK;\r\n\r\n  UInt32 numMethods = 1;\r\n  GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProcAddress(\"GetNumberOfMethods\");\r\n  if (getNumberOfMethodsFunc != NULL)\r\n  {\r\n    RINOK(getNumberOfMethodsFunc(&numMethods));\r\n  }\r\n\r\n  for(UInt32 i = 0; i < numMethods; i++)\r\n  {\r\n    CDllCodecInfo info;\r\n    info.LibIndex = Libs.Size() - 1;\r\n    info.CodecIndex = i;\r\n\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));\r\n\r\n    Codecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadProp(\r\n    GetHandlerPropertyFunc getProp, \r\n    GetHandlerPropertyFunc2 getProp2, \r\n    UInt32 index, PROPID propID, NCOM::CPropVariant &prop)\r\n{\r\n  if (getProp2)\r\n    return getProp2(index, propID, &prop);;\r\n  return getProp(propID, &prop);\r\n}\r\n\r\nstatic HRESULT ReadBoolProp(\r\n    GetHandlerPropertyFunc getProp, \r\n    GetHandlerPropertyFunc2 getProp2, \r\n    UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadStringProp(\r\n    GetHandlerPropertyFunc getProp, \r\n    GetHandlerPropertyFunc2 getProp2, \r\n    UInt32 index, PROPID propID, UString &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BSTR)\r\n    res = prop.bstrVal;\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax]; \r\nvoid RegisterArc(const CArcInfo *arcInfo) \r\n{ \r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo; \r\n}\r\n\r\nstatic void SplitString(const UString &srcString, UStringVector &destStrings)\r\n{\r\n  destStrings.Clear();\r\n  UString s;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L' ')\r\n    {\r\n      if (!s.IsEmpty())\r\n      {\r\n        destStrings.Add(s);\r\n        s.Empty();\r\n      }\r\n    }\r\n    else\r\n      s += c;\r\n  }\r\n  if (!s.IsEmpty())\r\n    destStrings.Add(s);\r\n}\r\n\r\nvoid CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt)\r\n{\r\n  UStringVector exts, addExts;\r\n  SplitString(ext, exts);\r\n  if (addExt != 0)\r\n    SplitString(addExt, addExts);\r\n  for (int i = 0; i < exts.Size(); i++)\r\n  {\r\n    CArcExtInfo extInfo;\r\n    extInfo.Ext = exts[i];\r\n    if (i < addExts.Size())\r\n    {\r\n      extInfo.AddExt = addExts[i];\r\n      if (extInfo.AddExt == L\"*\")\r\n        extInfo.AddExt.Empty();\r\n    }\r\n    Exts.Add(extInfo);\r\n  }\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nHRESULT CCodecs::LoadFormats()\r\n{\r\n  const NDLL::CLibrary &lib = Libs.Back().Lib;\r\n  GetHandlerPropertyFunc getProp = 0;\r\n  GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)\r\n      lib.GetProcAddress(\"GetHandlerProperty2\");\r\n  if (getProp2 == NULL)\r\n  {\r\n    getProp = (GetHandlerPropertyFunc)\r\n        lib.GetProcAddress(\"GetHandlerProperty\");\r\n    if (getProp == NULL)\r\n      return S_OK;\r\n  }\r\n\r\n  UInt32 numFormats = 1;\r\n  GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)\r\n    lib.GetProcAddress(\"GetNumberOfFormats\");\r\n  if (getNumberOfFormats != NULL)\r\n  {\r\n    RINOK(getNumberOfFormats(&numFormats));\r\n  }\r\n  if (getProp2 == NULL)\r\n    numFormats = 1;\r\n\r\n  for(UInt32 i = 0; i < numFormats; i++)\r\n  {\r\n    CArcInfoEx item;\r\n    item.LibIndex = Libs.Size() - 1;\r\n    item.FormatIndex = i;\r\n\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)\r\n      continue;\r\n    if (prop.vt != VT_BSTR)\r\n      continue;\r\n    item.ClassID = *(const GUID *)prop.bstrVal;\r\n    prop.Clear();\r\n\r\n    UString ext, addExt;\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));\r\n    item.AddExts(ext, addExt);\r\n\r\n    ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);\r\n    if (item.UpdateEnabled)\r\n      ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);\r\n    \r\n    if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)\r\n      if (prop.vt == VT_BSTR)\r\n      {\r\n        UINT len = ::SysStringByteLen(prop.bstrVal);\r\n        item.StartSignature.SetCapacity(len);\r\n        memmove(item.StartSignature, prop.bstrVal, len);\r\n      }\r\n    Formats.Add(item);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef NEW_FOLDER_INTERFACE\r\nvoid CCodecLib::LoadIcons()\r\n{\r\n  UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId);\r\n  UStringVector pairs;\r\n  SplitString(iconTypes, pairs);\r\n  for (int i = 0; i < pairs.Size(); i++)\r\n  {\r\n    const UString &s = pairs[i];\r\n    int pos = s.Find(L':');\r\n    if (pos < 0)\r\n      continue;\r\n    CIconPair iconPair;\r\n    const wchar_t *end;\r\n    UString num = s.Mid(pos + 1);\r\n    iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);\r\n    if (*end != L'\\0')\r\n      continue;\r\n    iconPair.Ext = s.Left(pos);\r\n    IconPairs.Add(iconPair);\r\n  }\r\n}\r\n\r\nint CCodecLib::FindIconIndex(const UString &ext) const\r\n{\r\n  for (int i = 0; i < IconPairs.Size(); i++)\r\n  {\r\n    const CIconPair &pair = IconPairs[i];\r\n    if (ext.CompareNoCase(pair.Ext) == 0)\r\n      return pair.IconIndex;\r\n  }\r\n  return -1;\r\n}\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nextern \"C\" \r\n{\r\n  extern SIZE_T g_LargePageSize;\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::LoadDll(const CSysString &dllPath)\r\n{\r\n  {\r\n    NDLL::CLibrary library;\r\n    if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))\r\n      return S_OK;\r\n  }\r\n  Libs.Add(CCodecLib());\r\n  CCodecLib &lib = Libs.Back();\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  lib.Path = dllPath;\r\n  #endif\r\n  bool used = false;\r\n  HRESULT res = S_OK;\r\n  if (lib.Lib.Load(dllPath))\r\n  {\r\n    #ifdef NEW_FOLDER_INTERFACE\r\n    lib.LoadIcons();\r\n    #endif\r\n\r\n    #ifdef _7ZIP_LARGE_PAGES\r\n    if (g_LargePageSize != 0)\r\n    {\r\n      SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProcAddress(\"SetLargePageMode\");\r\n      if (setLargePageMode != 0)\r\n        setLargePageMode();\r\n    }\r\n    #endif\r\n\r\n    lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress(\"CreateObject\");\r\n    if (lib.CreateObject != 0)\r\n    {\r\n      int startSize = Codecs.Size();\r\n      res = LoadCodecs();\r\n      used = (Codecs.Size() != startSize);\r\n      if (res == S_OK)\r\n      {\r\n        startSize = Formats.Size();\r\n        res = LoadFormats();\r\n        used = used || (Formats.Size() != startSize);\r\n      }\r\n    }\r\n  }\r\n  if (!used)\r\n    Libs.DeleteBack();\r\n  return res;\r\n}\r\n\r\nHRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)\r\n{\r\n  NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT(\"*\")));\r\n  NFile::NFind::CFileInfo fileInfo;\r\n  while (enumerator.Next(fileInfo))\r\n  {\r\n    if (fileInfo.IsDirectory())\r\n      continue;\r\n    RINOK(LoadDll(folderPrefix + fileInfo.Name));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n#ifndef _SFX\r\nstatic inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)\r\n{\r\n  bb.SetCapacity(size);\r\n  memmove((Byte *)bb, data, size);\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::Load()\r\n{\r\n  Formats.Clear();\r\n  #ifdef EXTERNAL_CODECS\r\n  Codecs.Clear();\r\n  #endif\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n  {\r\n    const CArcInfo &arc = *g_Arcs[i];\r\n    CArcInfoEx item;\r\n    item.Name = arc.Name;\r\n    item.CreateInArchive = arc.CreateInArchive;\r\n    item.CreateOutArchive = arc.CreateOutArchive;\r\n    item.AddExts(arc.Ext, arc.AddExt);\r\n    item.UpdateEnabled = (arc.CreateOutArchive != 0);\r\n    item.KeepName = arc.KeepName;\r\n\r\n    #ifndef _SFX\r\n    SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);\r\n    #endif\r\n    Formats.Add(item);\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();\r\n  RINOK(LoadDll(baseFolder + kMainDll));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveName(const UString &archivePath) const\r\n{\r\n  int slashPos1 = archivePath.ReverseFind(L'\\\\');\r\n  int slashPos2 = archivePath.ReverseFind(L'.');\r\n  int dotPos = archivePath.ReverseFind(L'.');\r\n  if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)\r\n    return -1;\r\n  UString ext = archivePath.Mid(dotPos + 1);\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    // if (arc.FindExtension(ext) >= 0)\r\n    UString mainExt = arc.GetMainExt();\r\n    if (!mainExt.IsEmpty() && ext.CompareNoCase(mainExt) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveType(const UString &arcType) const\r\n{\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    if (arc.Name.CompareNoCase(arcType) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\n#ifdef EXPORT_CODECS\r\nextern unsigned int g_NumCodecs;\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);\r\n// STDAPI GetNumberOfMethods(UINT32 *numCodecs);\r\n#endif\r\n\r\nSTDMETHODIMP CCodecs::GetNumberOfMethods(UINT32 *numMethods)\r\n{\r\n  *numMethods = \r\n      #ifdef EXPORT_CODECS\r\n      g_NumCodecs + \r\n      #endif\r\n      Codecs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::GetProperty(UINT32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return GetMethodProperty(index, propID, value);\r\n  #endif\r\n\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n\r\n  if (propID == NMethodPropID::kDecoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.DecoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  if (propID == NMethodPropID::kEncoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.EncoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateDecoder(UINT32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(false, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.DecoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateEncoder(UINT32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(true, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.EncoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const\r\n{ \r\n  for (int i = 0; i < Codecs.Size(); i++)\r\n  {\r\n    const CDllCodecInfo &codec = Codecs[i];\r\n    if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigned)\r\n      continue;\r\n    const CCodecLib &lib = Libs[codec.LibIndex];\r\n    UString res;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      res = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      continue;\r\n    if (name.CompareNoCase(res) == 0)\r\n      return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICompressCoder, (void **)&coder);\r\n  }\r\n  return CLASS_E_CLASSNOTAVAILABLE;\r\n}\r\n\r\nint CCodecs::GetCodecLibIndex(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return -1;\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.LibIndex;\r\n  #else\r\n  return -1;\r\n  #endif\r\n}\r\n\r\nbool CCodecs::GetCodecEncoderIsAssigned(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n  {\r\n    NWindows::NCOM::CPropVariant prop;\r\n    if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK)\r\n      if (prop.vt != VT_EMPTY)\r\n        return true;\r\n    return false;\r\n  }\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.EncoderIsAssigned;\r\n  #else\r\n  return false;\r\n  #endif\r\n}\r\n\r\nHRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(GetProperty(index, NMethodPropID::kID, &prop));\r\n  if (prop.vt != VT_UI8)\r\n    return E_INVALIDARG;\r\n  id = prop.uhVal.QuadPart;\r\n  return S_OK;\r\n}\r\n\r\nUString CCodecs::GetCodecName(UInt32 index)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK)\r\n    if (prop.vt == VT_BSTR)\r\n      s = prop.bstrVal;\r\n  return s;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/LoadCodecs.h",
    "content": "// LoadCodecs.h\r\n\r\n#ifndef __LOADCODECS_H\r\n#define __LOADCODECS_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/DLL.h\"\r\n#endif\r\n\r\nstruct CDllCodecInfo\r\n{\r\n  CLSID Encoder;\r\n  CLSID Decoder;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  int LibIndex;\r\n  UInt32 CodecIndex;\r\n};\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcExtInfo\r\n{\r\n  UString Ext;\r\n  UString AddExt;\r\n  CArcExtInfo() {}\r\n  CArcExtInfo(const UString &ext): Ext(ext) {}\r\n  CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}\r\n};\r\n\r\n\r\nstruct CArcInfoEx\r\n{\r\n  #ifdef EXTERNAL_CODECS\r\n  int LibIndex;\r\n  UInt32 FormatIndex;\r\n  CLSID ClassID;\r\n  #endif\r\n  bool UpdateEnabled;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n  UString Name;\r\n  CObjectVector<CArcExtInfo> Exts;\r\n  #ifndef _SFX\r\n  CByteBuffer StartSignature;\r\n  // CByteBuffer FinishSignature;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  UStringVector AssociateExts;\r\n  #endif\r\n  #endif\r\n  bool KeepName;\r\n  UString GetMainExt() const\r\n  {\r\n    if (Exts.IsEmpty())\r\n      return UString();\r\n    return Exts[0].Ext;\r\n  }\r\n  int FindExtension(const UString &ext) const\r\n  {\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n      if (ext.CompareNoCase(Exts[i].Ext) == 0)\r\n        return i;\r\n    return -1;\r\n  }\r\n  UString GetAllExtensions() const\r\n  {\r\n    UString s;\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n    {\r\n      if (i > 0)\r\n        s += ' ';\r\n      s += Exts[i].Ext;\r\n    }\r\n    return s;\r\n  }\r\n\r\n  void AddExts(const wchar_t* ext, const wchar_t* addExt);\r\n\r\n  CArcInfoEx(): \r\n    #ifdef EXTERNAL_CODECS\r\n    LibIndex(-1),\r\n    #endif\r\n    UpdateEnabled(false),\r\n    CreateInArchive(0), CreateOutArchive(0),\r\n    KeepName(false)\r\n    #ifndef _SFX\r\n    #endif\r\n  {}\r\n};\r\n\r\n#ifdef EXTERNAL_CODECS\r\ntypedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);\r\n\r\n\r\nstruct CCodecLib\r\n{\r\n  NWindows::NDLL::CLibrary Lib;\r\n  GetMethodPropertyFunc GetMethodProperty;\r\n  CreateObjectFunc CreateObject;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  struct CIconPair\r\n  {\r\n    UString Ext;\r\n    UInt32 IconIndex;\r\n  };\r\n  CSysString Path;\r\n  CObjectVector<CIconPair> IconPairs;\r\n  void LoadIcons();\r\n  int FindIconIndex(const UString &ext) const;\r\n  #endif\r\n  CCodecLib(): GetMethodProperty(0) {}\r\n};\r\n#endif\r\n\r\nclass CCodecs:\r\n  #ifdef EXTERNAL_CODECS\r\n  public ICompressCodecsInfo,\r\n  #else\r\n  public IUnknown,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:  \r\n  #ifdef EXTERNAL_CODECS\r\n  CObjectVector<CCodecLib> Libs;\r\n  CObjectVector<CDllCodecInfo> Codecs;\r\n  HRESULT LoadCodecs();\r\n  HRESULT LoadFormats();\r\n  HRESULT LoadDll(const CSysString &path);\r\n  HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);\r\n\r\n  HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const\r\n  {\r\n    return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);\r\n  }\r\n  #endif\r\n\r\npublic:\r\n  CObjectVector<CArcInfoEx> Formats;\r\n  HRESULT Load();\r\n  int FindFormatForArchiveName(const UString &archivePath) const;\r\n  int FindFormatForArchiveType(const UString &arcType) const;\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  STDMETHOD(GetNumberOfMethods)(UINT32 *numMethods);\r\n  STDMETHOD(GetProperty)(UINT32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(CreateDecoder)(UINT32 index, const GUID *interfaceID, void **coder);\r\n  STDMETHOD(CreateEncoder)(UINT32 index, const GUID *interfaceID, void **coder);\r\n  #endif\r\n\r\n  int GetCodecLibIndex(UInt32 index);\r\n  bool GetCodecEncoderIsAssigned(UInt32 index);\r\n  HRESULT GetCodecId(UInt32 index, UInt64 &id);\r\n  UString GetCodecName(UInt32 index);\r\n\r\n  HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const\r\n  { \r\n    const CArcInfoEx &ai = Formats[formatIndex]; \r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateInArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, false); \r\n    #endif\r\n  }\r\n  HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const\r\n  { \r\n    const CArcInfoEx &ai = Formats[formatIndex]; \r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateOutArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, true); \r\n    #endif\r\n  }\r\n  int FindOutFormatFromName(const UString &name) const\r\n  {\r\n    for (int i = 0; i < Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = Formats[i];\r\n      if (!arc.UpdateEnabled)\r\n        continue;\r\n      if (arc.Name.CompareNoCase(name) == 0)\r\n        return i;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;\r\n  #endif\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/OpenArchive.cpp",
    "content": "// OpenArchive.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidPath, &prop));\r\n  if(prop.vt == VT_BSTR)\r\n    result = prop.bstrVal;\r\n  else if (prop.vt == VT_EMPTY)\r\n    result.Empty();\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result)\r\n{\r\n  RINOK(GetArchiveItemPath(archive, index, result));\r\n  if (result.IsEmpty())\r\n    result = defaultName;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index, \r\n    const FILETIME &defaultFileTime, FILETIME &fileTime)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidLastWriteTime, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n    fileTime = prop.filetime;\r\n  else if (prop.vt == VT_EMPTY)\r\n    fileTime = defaultFileTime;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsFolder, result);\r\n}\r\n\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsAnti, result);\r\n}\r\n\r\n// Static-SFX (for Linux) can be big.\r\nconst UInt64 kMaxCheckStartPosition = 1 << 22;\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  inStreamSpec->Open(fileName);\r\n  return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n}\r\n\r\n#ifndef _SFX\r\nstatic inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)\r\n{\r\n  for (size_t i = 0; i < size; i++)\r\n    if (p1[i] != p2[i])\r\n      return false;\r\n  return true;\r\n}\r\n#endif\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    IInStream *inStream,\r\n    const UString &fileName, \r\n    IInArchive **archiveResult, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  *archiveResult = NULL;\r\n  UString extension;\r\n  {\r\n    int dotPos = fileName.ReverseFind(L'.');\r\n    if (dotPos >= 0)\r\n      extension = fileName.Mid(dotPos + 1);\r\n  }\r\n  CIntVector orderIndices;\r\n  int i;\r\n  int numFinded = 0;\r\n  for (i = 0; i < codecs->Formats.Size(); i++)\r\n    if (codecs->Formats[i].FindExtension(extension) >= 0)\r\n      orderIndices.Insert(numFinded++, i);\r\n    else\r\n      orderIndices.Add(i);\r\n  \r\n  #ifndef _SFX\r\n  if (numFinded != 1)\r\n  {\r\n    CIntVector orderIndices2;\r\n    CByteBuffer byteBuffer;\r\n    const UInt32 kBufferSize = (200 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    UInt32 processedSize;\r\n    RINOK(ReadStream(inStream, buffer, kBufferSize, &processedSize));\r\n    for (UInt32 pos = 0; pos < processedSize; pos++)\r\n    {\r\n      for (int i = 0; i < orderIndices.Size(); i++)\r\n      {\r\n        int index = orderIndices[i];\r\n        const CArcInfoEx &ai = codecs->Formats[index];\r\n        const CByteBuffer &sig = ai.StartSignature;\r\n        if (sig.GetCapacity() == 0)\r\n          continue;\r\n        if (pos + sig.GetCapacity() > processedSize)\r\n          continue;\r\n        if (TestSignature(buffer + pos, sig, sig.GetCapacity()))\r\n        {\r\n          orderIndices2.Add(index);\r\n          orderIndices.Delete(i--);\r\n        }\r\n      }\r\n    }\r\n    orderIndices2 += orderIndices;\r\n    orderIndices = orderIndices2;\r\n  }\r\n  else if (extension == L\"000\" || extension == L\"001\")\r\n  {\r\n    CByteBuffer byteBuffer;\r\n    const UInt32 kBufferSize = (1 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    UInt32 processedSize;\r\n    RINOK(ReadStream(inStream, buffer, kBufferSize, &processedSize));\r\n    if (processedSize >= 16)\r\n    {\r\n      Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};\r\n      if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] && 1) != 0)\r\n      {\r\n        for (int i = 0; i < orderIndices.Size(); i++)\r\n        {\r\n          int index = orderIndices[i];\r\n          const CArcInfoEx &ai = codecs->Formats[index];\r\n          if (ai.Name.CompareNoCase(L\"rar\") != 0)\r\n            continue;\r\n          orderIndices.Delete(i--);\r\n          orderIndices.Insert(0, index);\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  HRESULT badResult = S_OK;\r\n  for(i = 0; i < orderIndices.Size(); i++)\r\n  {\r\n    inStream->Seek(0, STREAM_SEEK_SET, NULL);\r\n\r\n    CMyComPtr<IInArchive> archive;\r\n\r\n    formatIndex = orderIndices[i];\r\n    RINOK(codecs->CreateInArchive(formatIndex, archive));\r\n    if (!archive)\r\n      continue;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    HRESULT result = archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n    if (result == S_FALSE)\r\n      continue;\r\n    if(result != S_OK)\r\n    {\r\n      badResult = result;\r\n      if(result == E_ABORT)\r\n        break;\r\n      continue;\r\n    }\r\n    *archiveResult = archive.Detach();\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex];\r\n    if (format.Exts.Size() == 0)\r\n    {\r\n      defaultItemName = GetDefaultName2(fileName, L\"\", L\"\");\r\n    }\r\n    else\r\n    {\r\n      int subExtIndex = format.FindExtension(extension);\r\n      if (subExtIndex < 0)\r\n        subExtIndex = 0;\r\n      defaultItemName = GetDefaultName2(fileName, \r\n          format.Exts[subExtIndex].Ext, \r\n          format.Exts[subExtIndex].AddExt);\r\n    }\r\n    return S_OK;\r\n  }\r\n  if (badResult != S_OK)\r\n    return badResult;\r\n  return S_FALSE;\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &filePath, \r\n    IInArchive **archiveResult, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  if (!inStreamSpec->Open(filePath))\r\n    return GetLastError();\r\n  return OpenArchive(codecs, inStream, ExtractFileNameFromPath(filePath),\r\n    archiveResult, formatIndex,\r\n    defaultItemName, openArchiveCallback);\r\n}\r\n\r\nstatic void MakeDefaultName(UString &name)\r\n{\r\n  int dotPos = name.ReverseFind(L'.');\r\n  if (dotPos < 0)\r\n    return;\r\n  UString ext = name.Mid(dotPos + 1);\r\n  if (ext.IsEmpty())\r\n    return;\r\n  for (int pos = 0; pos < ext.Length(); pos++)\r\n    if (ext[pos] < L'0' || ext[pos] > L'9')\r\n      return;\r\n  name = name.Left(dotPos);\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &fileName, \r\n    IInArchive **archive0, \r\n    IInArchive **archive1, \r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  HRESULT result = OpenArchive(codecs, fileName, \r\n      archive0, formatIndex0, defaultItemName0, openArchiveCallback);\r\n  RINOK(result);\r\n  CMyComPtr<IInArchiveGetStream> getStream;\r\n  result = (*archive0)->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream);\r\n  if (result != S_OK || getStream == 0)\r\n    return S_OK;\r\n\r\n  CMyComPtr<ISequentialInStream> subSeqStream;\r\n  result = getStream->GetStream(0, &subSeqStream);\r\n  if (result != S_OK)\r\n    return S_OK;\r\n\r\n  CMyComPtr<IInStream> subStream;\r\n  if (subSeqStream.QueryInterface(IID_IInStream, &subStream) != S_OK)\r\n    return S_OK;\r\n  if (!subStream)\r\n    return S_OK;\r\n\r\n  UInt32 numItems;\r\n  RINOK((*archive0)->GetNumberOfItems(&numItems));\r\n  if (numItems < 1)\r\n    return S_OK;\r\n\r\n  UString subPath;\r\n  RINOK(GetArchiveItemPath(*archive0, 0, subPath))\r\n  if (subPath.IsEmpty())\r\n  {\r\n    MakeDefaultName(defaultItemName0);\r\n    subPath = defaultItemName0;\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex0];\r\n    if (format.Name.CompareNoCase(L\"7z\") == 0)\r\n    {\r\n      if (subPath.Right(3).CompareNoCase(L\".7z\") != 0)\r\n        subPath += L\".7z\";\r\n    }\r\n  }\r\n  else\r\n    subPath = ExtractFileNameFromPath(subPath);\r\n\r\n  CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;\r\n  openArchiveCallback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);\r\n  if (setSubArchiveName)\r\n    setSubArchiveName->SetSubArchiveName(subPath);\r\n\r\n  result = OpenArchive(codecs, subStream, subPath,\r\n      archive1, formatIndex1, defaultItemName1, openArchiveCallback);\r\n  return S_OK;\r\n}\r\n\r\nstatic void SetCallback(const UString &archiveName,\r\n    IOpenCallbackUI *openCallbackUI, CMyComPtr<IArchiveOpenCallback> &openCallback)\r\n{\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  openCallbackSpec->Init(\r\n      fullName.Left(fileNamePartStartIndex), \r\n      fullName.Mid(fileNamePartStartIndex));\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs, \r\n    const UString &archiveName,\r\n    IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI)\r\n{\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(archiveName, openCallbackUI, openCallback);\r\n  int formatInfo;\r\n  return OpenArchive(codecs, archiveName, archive, formatInfo, defaultItemName, openCallback);\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  volumesSize = 0;\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  UString prefix = fullName.Left(fileNamePartStartIndex);\r\n  UString name = fullName.Mid(fileNamePartStartIndex);\r\n  openCallbackSpec->Init(prefix, name);\r\n\r\n  int formatIndex0, formatIndex1;\r\n  RINOK(OpenArchive(codecs, archiveName,\r\n      archive0, \r\n      archive1, \r\n      formatIndex0, \r\n      formatIndex1, \r\n      defaultItemName0,\r\n      defaultItemName1,\r\n      openCallback));\r\n  volumePaths.Add(prefix + name);\r\n  for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)\r\n    volumePaths.Add(prefix + openCallbackSpec->FileNames[i]);\r\n  volumesSize = openCallbackSpec->TotalSize;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveLink::Close()\r\n{\r\n  if (Archive1 != 0)\r\n    RINOK(Archive1->Close());\r\n  if (Archive0 != 0)\r\n    RINOK(Archive0->Close());\r\n  IsOpen = false;\r\n  return S_OK;\r\n}\r\n\r\nvoid CArchiveLink::Release()\r\n{\r\n  IsOpen = false;\r\n  Archive1.Release();\r\n  Archive0.Release();\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  HRESULT res = OpenArchive(codecs, archiveName, \r\n    &archiveLink.Archive0, &archiveLink.Archive1, \r\n    archiveLink.FormatIndex0, archiveLink.FormatIndex1, \r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1, \r\n    openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT MyOpenArchive(CCodecs *codecs,\r\n    const UString &archiveName, \r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  HRESULT res = MyOpenArchive(codecs, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1, \r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1, \r\n    archiveLink.VolumePaths,\r\n    archiveLink.VolumesSize,\r\n    openCallbackUI);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT ReOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, const UString &fileName)\r\n{\r\n  if (archiveLink.GetNumLevels() > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (archiveLink.GetNumLevels() == 0)\r\n    return MyOpenArchive(codecs, fileName, archiveLink, 0);\r\n\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(fileName, NULL, openCallback);\r\n\r\n  HRESULT res = ReOpenArchive(archiveLink.GetArchive(), fileName, openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/OpenArchive.h",
    "content": "// OpenArchive.h\r\n\r\n#ifndef __OPENARCHIVE_H\r\n#define __OPENARCHIVE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"LoadCodecs.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result);\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result);\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index, \r\n    const FILETIME &defaultFileTime, FILETIME &fileTime);\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result);\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result);\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result);\r\n\r\nstruct ISetSubArchiveName\r\n{\r\n  virtual void SetSubArchiveName(const wchar_t *name) = 0;\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    IInStream *inStream,\r\n    const UString &fileName, \r\n    IInArchive **archiveResult, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &filePath, \r\n    IInArchive **archive, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &filePath, \r\n    IInArchive **archive0, \r\n    IInArchive **archive1, \r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    IInArchive **archive,\r\n    UString &defaultItemName,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nstruct CArchiveLink\r\n{\r\n  CMyComPtr<IInArchive> Archive0;\r\n  CMyComPtr<IInArchive> Archive1;\r\n  UString DefaultItemName0;\r\n  UString DefaultItemName1;\r\n\r\n  int FormatIndex0;\r\n  int FormatIndex1;\r\n  \r\n  UStringVector VolumePaths;\r\n\r\n  UInt64 VolumesSize;\r\n\r\n  int GetNumLevels() const\r\n  { \r\n    int result = 0;\r\n    if (Archive0)\r\n    {\r\n      result++;\r\n      if (Archive1)\r\n        result++;\r\n    }\r\n    return result;\r\n  }\r\n\r\n  bool IsOpen;\r\n\r\n  CArchiveLink(): IsOpen(false), VolumesSize(0) {};\r\n\r\n  IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; }\r\n  UString GetDefaultItemName()  { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; }\r\n  int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; }\r\n  HRESULT Close();\r\n  void Release();\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT ReOpenArchive(\r\n    CCodecs *codecs,\r\n    CArchiveLink &archiveLink, \r\n    const UString &fileName);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/PropIDUtils.cpp",
    "content": "// PropIDUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropIDUtils.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../PropID.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic void ConvertUInt32ToHex(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    int t = value & 0xF;\r\n    value >>= 4;\r\n    s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));\r\n  }\r\n  s[8] = L'\\0';\r\n}\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full)\r\n{\r\n  switch(propID)\r\n  {\r\n    case kpidCreationTime:\r\n    case kpidLastWriteTime:\r\n    case kpidLastAccessTime:\r\n    {\r\n      if (propVariant.vt != VT_FILETIME)\r\n        return UString(); // It is error;\r\n      FILETIME localFileTime;\r\n      if (propVariant.filetime.dwHighDateTime == 0 && \r\n          propVariant.filetime.dwLowDateTime == 0)\r\n        return UString();\r\n      if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n        return UString(); // It is error;\r\n      return ConvertFileTimeToString(localFileTime, true, full);\r\n    }\r\n    case kpidCRC:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      wchar_t temp[12];\r\n      ConvertUInt32ToHex(propVariant.ulVal, temp);\r\n      return temp;\r\n    }\r\n    case kpidAttributes:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UString result;\r\n      UInt32 attributes = propVariant.ulVal;\r\n      if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';\r\n      if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';\r\n      if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';\r\n      if (NFile::NFind::NAttributes::IsDirectory(attributes)) result += L'D';\r\n      if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';\r\n      if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';\r\n      if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';\r\n      return result;\r\n    }\r\n    case kpidDictionarySize:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UInt32 size = propVariant.ulVal;\r\n      if (size % (1 << 20) == 0)\r\n        return ConvertUInt32ToString(size >> 20) + L\"MB\";\r\n      if (size % (1 << 10) == 0)\r\n        return ConvertUInt32ToString(size >> 10) + L\"KB\";\r\n      return ConvertUInt32ToString(size);\r\n    }\r\n  }\r\n  return ConvertPropVariantToString(propVariant);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/PropIDUtils.h",
    "content": "// PropIDUtils.h\r\n\r\n#ifndef __PROPIDUTILS_H\r\n#define __PROPIDUTILS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/Property.h",
    "content": "// Property.h\r\n\r\n#ifndef __PROPERTY_H\r\n#define __PROPERTY_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nstruct CProperty\r\n{\r\n  UString Name;\r\n  UString Value;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/SetProperties.cpp",
    "content": "// SetProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SetProperties.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\n\r\nstatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)\r\n{\r\n  const wchar_t *endPtr;\r\n  UInt64 result = ConvertStringToUInt64(s, &endPtr);\r\n  if (endPtr - (const wchar_t *)s != s.Length())\r\n    prop = s;\r\n  else if (result <= 0xFFFFFFFF)\r\n    prop = (UInt32)result;\r\n  else \r\n    prop = result;\r\n}\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)\r\n{\r\n  if (properties.IsEmpty())\r\n    return S_OK;\r\n  CMyComPtr<ISetProperties> setProperties;\r\n  unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);\r\n  if (!setProperties)\r\n    return S_OK;\r\n\r\n  UStringVector realNames;\r\n  CPropVariant *values = new CPropVariant[properties.Size()];\r\n  try\r\n  {\r\n    int i;\r\n    for(i = 0; i < properties.Size(); i++)\r\n    {\r\n      const CProperty &property = properties[i];\r\n      NCOM::CPropVariant propVariant;\r\n      if (!property.Value.IsEmpty())\r\n        ParseNumberString(property.Value, propVariant);\r\n      realNames.Add(property.Name);\r\n      values[i] = propVariant;\r\n    }\r\n    CRecordVector<const wchar_t *> names;\r\n    for(i = 0; i < realNames.Size(); i++)\r\n      names.Add((const wchar_t *)realNames[i]);\r\n    \r\n    RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));\r\n  }\r\n  catch(...)\r\n  {\r\n    delete []values;\r\n    throw;\r\n  }\r\n  delete []values;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/SetProperties.h",
    "content": "// SetProperties.h\r\n\r\n#ifndef __SETPROPERTIES_H\r\n#define __SETPROPERTIES_H\r\n\r\n#include \"Property.h\"\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/SortUtils.cpp",
    "content": "// SortUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SortUtils.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nstatic int CompareStrings(const int *p1, const int *p2, void *param)\r\n{\r\n  const UStringVector &strings = *(const UStringVector *)param;\r\n  return CompareFileNames(strings[*p1], strings[*p2]);\r\n}\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numItems = strings.Size();\r\n  indices.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n    indices.Add(i);\r\n  indices.Sort(CompareStrings, (void *)&strings);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/SortUtils.h",
    "content": "// SortUtils.h\r\n\r\n#ifndef __SORTUTLS_H\r\n#define __SORTUTLS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/TempFiles.cpp",
    "content": "// TempFiles.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"TempFiles.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileIO.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nvoid CTempFiles::Clear()\r\n{\r\n  while(!Paths.IsEmpty())\r\n  {\r\n    NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());\r\n    Paths.DeleteBack();\r\n  }\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/TempFiles.h",
    "content": "// TempFiles.h\r\n\r\n#ifndef __TEMPFILES_H\r\n#define __TEMPFILES_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nclass CTempFiles\r\n{\r\n  void Clear();\r\npublic:\r\n  UStringVector Paths;\r\n  ~CTempFiles() { Clear(); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/Update.cpp",
    "content": "// Update.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <mapi.h>\r\n#endif\r\n\r\n#include \"Update.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/DLL.h\"\r\n#endif\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n// #include \"Windows/Synchronization.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Compress/Copy/CopyCoder.h\"\r\n\r\n#include \"../Common/DirItem.h\"\r\n#include \"../Common/EnumDirItems.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"TempFiles.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"EnumDirItems.h\"\r\n#include \"SetProperties.h\"\r\n\r\nstatic const char *kUpdateIsNotSupoorted = \r\n  \"update operations are not supported for this archive\";\r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nstatic const wchar_t *kTempFolderPrefix = L\"7zE\";\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)\r\n{\r\n  CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;\r\n  return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);\r\n}\r\n\r\nclass COutMultiVolStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    COutFileStream *StreamSpec;\r\n    CMyComPtr<IOutStream> Stream;\r\n    UString Name;\r\n    UInt64 Pos;\r\n    UInt64 RealSize;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  // CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  CRecordVector<UInt64> Sizes;\r\n  UString Prefix;\r\n  CTempFiles *TempFiles;\r\n\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  HRESULT Close(); \r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n// static NSynchronization::CCriticalSection g_TempPathsCS;\r\n\r\nHRESULT COutMultiVolStream::Close()\r\n{\r\n  HRESULT res = S_OK;\r\n  for (int i = 0; i < Streams.Size(); i++)\r\n  {\r\n    CSubStreamInfo &s = Streams[i];\r\n    if (s.StreamSpec)\r\n    {\r\n      HRESULT res2 = s.StreamSpec->Close();\r\n      if (res2 != S_OK)\r\n        res = res2;\r\n    }\r\n  }\r\n  return res;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n\r\n      wchar_t temp[32];\r\n      ConvertUInt64ToString(_streamIndex + 1, temp);\r\n      UString res = temp;\r\n      while (res.Length() < 3)\r\n        res = UString(L'0') + res;\r\n      UString name = Prefix + res;\r\n      subStream.StreamSpec = new COutFileStream;\r\n      subStream.Stream = subStream.StreamSpec;\r\n      if(!subStream.StreamSpec->Create(name, false))\r\n        return ::GetLastError();\r\n      {\r\n        // NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);\r\n        TempFiles->Paths.Add(name);\r\n      }\r\n\r\n      subStream.Pos = 0;\r\n      subStream.RealSize = 0;\r\n      subStream.Name = name;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n\r\n    int index = _streamIndex;\r\n    if (index >= Sizes.Size())\r\n      index = Sizes.Size() - 1;\r\n    UInt64 volSize = Sizes[index];\r\n\r\n    if (_offsetPos >= volSize)\r\n    {\r\n      _offsetPos -= volSize;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      // CMyComPtr<IOutStream> outStream;\r\n      // RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(subStream.Stream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, volSize - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if (_offsetPos > subStream.RealSize)\r\n      subStream.RealSize = _offsetPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == volSize)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed == 0 && curSize != 0)\r\n      return E_FAIL;\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  if (newPosition != NULL)\r\n    *newPosition = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::SetSize(Int64 newSize)\r\n{\r\n  if (newSize < 0)\r\n    return E_INVALIDARG;\r\n  int i = 0;\r\n  while (i < Streams.Size())\r\n  {\r\n    CSubStreamInfo &subStream = Streams[i++];\r\n    if ((UInt64)newSize < subStream.RealSize)\r\n    {\r\n      RINOK(subStream.Stream->SetSize(newSize));\r\n      subStream.RealSize = newSize;\r\n      break;\r\n    }\r\n    newSize -= subStream.RealSize;\r\n  }\r\n  while (i < Streams.Size())\r\n  {\r\n    {\r\n      CSubStreamInfo &subStream = Streams.Back();\r\n      subStream.Stream.Release();\r\n      NDirectory::DeleteFileAlways(subStream.Name);\r\n    }\r\n    Streams.DeleteBack();\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  _length = newSize;\r\n  return S_OK;\r\n}\r\n\r\nstatic const wchar_t *kDefaultArchiveType = L\"7z\";\r\nstatic const wchar_t *kSFXExtension =\r\n  #ifdef _WIN32\r\n    L\"exe\";\r\n  #else\r\n    L\"\";\r\n  #endif\r\n\r\nbool CUpdateOptions::Init(const CCodecs *codecs, const UString &arcPath, const UString &arcType)\r\n{\r\n  if (!arcType.IsEmpty())\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveType(arcType);\r\n  else\r\n  {\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveName(arcPath);\r\n    if (MethodMode.FormatIndex < 0)\r\n      MethodMode.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArchiveType);\r\n  }\r\n  if (MethodMode.FormatIndex < 0)\r\n    return false;\r\n  const CArcInfoEx &arcInfo = codecs->Formats[MethodMode.FormatIndex];\r\n  UString typeExt = arcInfo.GetMainExt();\r\n  UString ext = typeExt;\r\n  if (SfxMode)\r\n    ext = kSFXExtension;\r\n  ArchivePath.BaseExtension = ext;\r\n  ArchivePath.VolExtension = typeExt;\r\n  ArchivePath.ParseFromPath(arcPath);\r\n  for (int i = 0; i < Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &uc = Commands[i];\r\n    uc.ArchivePath.BaseExtension = ext;\r\n    uc.ArchivePath.VolExtension = typeExt;\r\n    uc.ArchivePath.ParseFromPath(uc.UserArchivePath);\r\n  }\r\n  return true;\r\n}\r\n\r\n\r\nstatic HRESULT Compress(\r\n    CCodecs *codecs,\r\n    const CActionSet &actionSet, \r\n    IInArchive *archive,\r\n    const CCompressionMethodMode &compressionMethod,\r\n    CArchivePath &archivePath, \r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    bool shareForWrite,\r\n    bool stdInMode,\r\n    /* const UString & stdInFileName, */\r\n    bool stdOutMode,\r\n    const CObjectVector<CDirItem> &dirItems,\r\n    bool sfxMode,\r\n    const UString &sfxModule,\r\n    const CRecordVector<UInt64> &volumesSizes,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI *callback)\r\n{\r\n  CMyComPtr<IOutArchive> outArchive;\r\n  if(archive != NULL)\r\n  {\r\n    CMyComPtr<IInArchive> archive2 = archive;\r\n    HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);\r\n    if(result != S_OK)\r\n      throw kUpdateIsNotSupoorted;\r\n  }\r\n  else\r\n  {\r\n    RINOK(codecs->CreateOutArchive(compressionMethod.FormatIndex, outArchive));\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n  }\r\n  if (outArchive == 0)\r\n    throw kUpdateIsNotSupoorted;\r\n  \r\n  NFileTimeType::EEnum fileTimeType;\r\n  UInt32 value;\r\n  RINOK(outArchive->GetFileTimeType(&value));\r\n\r\n  switch(value)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n    case NFileTimeType::kDOS:\r\n    case NFileTimeType::kUnix:\r\n      fileTimeType = NFileTimeType::EEnum(value);\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n\r\n  CObjectVector<CUpdatePair> updatePairs;\r\n  GetUpdatePairInfoList(dirItems, archiveItems, fileTimeType, updatePairs); // must be done only once!!!\r\n  \r\n  CObjectVector<CUpdatePair2> updatePairs2;\r\n  UpdateProduce(updatePairs, actionSet, updatePairs2);\r\n\r\n  UInt32 numFiles = 0;\r\n  for (int i = 0; i < updatePairs2.Size(); i++)\r\n    if (updatePairs2[i].NewData)\r\n      numFiles++;\r\n  \r\n  RINOK(callback->SetNumFiles(numFiles));\r\n\r\n  \r\n  CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n  CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);\r\n  \r\n  updateCallbackSpec->ShareForWrite = shareForWrite;\r\n  updateCallbackSpec->StdInMode = stdInMode;\r\n  updateCallbackSpec->Callback = callback;\r\n  updateCallbackSpec->DirItems = &dirItems;\r\n  updateCallbackSpec->ArchiveItems = &archiveItems;\r\n  updateCallbackSpec->UpdatePairs = &updatePairs2;\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n\r\n  const UString &archiveName = archivePath.GetFinalPath();\r\n  if (!stdOutMode)\r\n  {\r\n    UString resultPath;\r\n    int pos;\r\n    if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))\r\n      throw 1417161;\r\n    NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));\r\n  }\r\n\r\n  COutFileStream *outStreamSpec = NULL;\r\n  COutMultiVolStream *volStreamSpec = NULL;\r\n\r\n  if (volumesSizes.Size() == 0)\r\n  {\r\n    if (stdOutMode)\r\n      outStream = new CStdOutFileStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      outStream = outStreamSpec;\r\n      bool isOK = false;\r\n      UString realPath;\r\n      for (int i = 0; i < (1 << 16); i++)\r\n      {\r\n        if (archivePath.Temp)\r\n        {\r\n          if (i > 0)\r\n          {\r\n            wchar_t s[32];\r\n            ConvertUInt64ToString(i, s);\r\n            archivePath.TempPostfix = s;\r\n          }\r\n          realPath = archivePath.GetTempPath();\r\n        }\r\n        else\r\n          realPath = archivePath.GetFinalPath();\r\n        if (outStreamSpec->Create(realPath, false))\r\n        {\r\n          tempFiles.Paths.Add(realPath);\r\n          isOK = true;\r\n          break;\r\n        }\r\n        if (::GetLastError() != ERROR_FILE_EXISTS)\r\n          break;\r\n        if (!archivePath.Temp)\r\n          break;\r\n      }\r\n      if (!isOK)\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (stdOutMode)\r\n      return E_FAIL;\r\n    volStreamSpec = new COutMultiVolStream;\r\n    outStream = volStreamSpec;\r\n    volStreamSpec->Sizes = volumesSizes;\r\n    volStreamSpec->Prefix = archivePath.GetFinalPath() + UString(L\".\");\r\n    volStreamSpec->TempFiles = &tempFiles;\r\n    volStreamSpec->Init();\r\n\r\n    /*\r\n    updateCallbackSpec->VolumesSizes = volumesSizes;\r\n    updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;\r\n    if (!archivePath.VolExtension.IsEmpty())\r\n      updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;\r\n    */\r\n  }\r\n\r\n  RINOK(SetProperties(outArchive, compressionMethod.Properties));\r\n\r\n  if (sfxMode)\r\n  {\r\n    CInFileStream *sfxStreamSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> sfxStream(sfxStreamSpec);\r\n    if (!sfxStreamSpec->Open(sfxModule))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"Can't open sfx module\";\r\n      errorInfo.FileName = sfxModule;\r\n      return E_FAIL;\r\n    }\r\n\r\n    CMyComPtr<ISequentialOutStream> sfxOutStream;\r\n    COutFileStream *outStreamSpec = NULL;\r\n    if (volumesSizes.Size() == 0)\r\n      sfxOutStream = outStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      sfxOutStream = outStreamSpec;\r\n      UString realPath = archivePath.GetFinalPath();\r\n      if (!outStreamSpec->Create(realPath, false))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    RINOK(CopyBlock(sfxStream, sfxOutStream));\r\n    if (outStreamSpec)\r\n    {\r\n      RINOK(outStreamSpec->Close());\r\n    }\r\n  }\r\n\r\n  HRESULT result = outArchive->UpdateItems(outStream, updatePairs2.Size(), updateCallback);\r\n  callback->Finilize();\r\n  RINOK(result);\r\n  if (outStreamSpec)\r\n    result = outStreamSpec->Close();\r\n  else if (volStreamSpec)\r\n    result = volStreamSpec->Close();\r\n  return result;\r\n}\r\n\r\nHRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,\r\n    IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    CObjectVector<CArchiveItem> &archiveItems)\r\n{\r\n  archiveItems.Clear();\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n  archiveItems.Reserve(numItems);\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    CArchiveItem ai;\r\n\r\n    RINOK(GetArchiveItemPath(archive, i, ai.Name));\r\n    RINOK(IsArchiveItemFolder(archive, i, ai.IsDirectory));\r\n    ai.Censored = censor.CheckPath(ai.Name.IsEmpty() ? defaultItemName : ai.Name, !ai.IsDirectory);\r\n    RINOK(GetArchiveItemFileTime(archive, i, \r\n        archiveFileInfo.LastWriteTime, ai.LastWriteTime));\r\n\r\n    CPropVariant propertySize;\r\n    RINOK(archive->GetProperty(i, kpidSize, &propertySize));\r\n    ai.SizeIsDefined = (propertySize.vt != VT_EMPTY);\r\n    if (ai.SizeIsDefined)\r\n      ai.Size = ConvertPropVariantToUInt64(propertySize);\r\n\r\n    ai.IndexInServer = i;\r\n    archiveItems.Add(ai);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nstatic HRESULT UpdateWithItemLists(\r\n    CCodecs *codecs,\r\n    CUpdateOptions &options,\r\n    IInArchive *archive, \r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    const CObjectVector<CDirItem> &dirItems,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &command = options.Commands[i];\r\n    if (options.StdOutMode)\r\n    {\r\n      RINOK(callback->StartArchive(0, archive != 0));\r\n    }\r\n    else\r\n    {\r\n      RINOK(callback->StartArchive(command.ArchivePath.GetFinalPath(), \r\n          i == 0 && options.UpdateArchiveItself && archive != 0));\r\n    }\r\n\r\n    RINOK(Compress(\r\n        codecs,\r\n        command.ActionSet, archive,\r\n        options.MethodMode, \r\n        command.ArchivePath, \r\n        archiveItems, \r\n        options.OpenShareForWrite,\r\n        options.StdInMode, \r\n        /* options.StdInFileName, */\r\n        options.StdOutMode,\r\n        dirItems, \r\n        options.SfxMode, options.SfxModule, \r\n        options.VolumesSizes,\r\n        tempFiles,\r\n        errorInfo, callback));\r\n\r\n    RINOK(callback->FinishArchive());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _WIN32\r\nclass CCurrentDirRestorer\r\n{\r\n  UString m_CurrentDirectory;\r\npublic:\r\n  CCurrentDirRestorer()\r\n    { NFile::NDirectory::MyGetCurrentDirectory(m_CurrentDirectory); }\r\n  ~CCurrentDirRestorer()\r\n    { RestoreDirectory();}\r\n  bool RestoreDirectory()\r\n    { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(m_CurrentDirectory)); }\r\n};\r\n#endif\r\n\r\nstruct CEnumDirItemUpdateCallback: public IEnumDirItemCallback\r\n{\r\n  IUpdateCallbackUI2 *Callback;\r\n  HRESULT CheckBreak() { return Callback->CheckBreak(); }\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor, \r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  if (options.StdOutMode && options.EMailMode)\r\n    return E_FAIL;\r\n\r\n  if (options.VolumesSizes.Size() > 0 && (options.EMailMode || options.SfxMode))\r\n    return E_NOTIMPL;\r\n\r\n  if (options.SfxMode)\r\n  {\r\n    CProperty property;\r\n    property.Name = L\"rsfx\";\r\n    property.Value = L\"on\";\r\n    options.MethodMode.Properties.Add(property);\r\n    if (options.SfxModule.IsEmpty())\r\n    {\r\n      errorInfo.Message = L\"sfx file is not specified\";\r\n      return E_FAIL;\r\n    }\r\n    UString name = options.SfxModule;\r\n    if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))\r\n    {\r\n      errorInfo.Message = L\"can't find specified sfx module\";\r\n      return E_FAIL;\r\n    }\r\n  }\r\n\r\n  const UString archiveName = options.ArchivePath.GetFinalPath();\r\n\r\n  UString defaultItemName;\r\n  NFind::CFileInfoW archiveFileInfo;\r\n\r\n  CArchiveLink archiveLink;\r\n  IInArchive *archive = 0;\r\n  if (NFind::FindFile(archiveName, archiveFileInfo))\r\n  {\r\n    if (archiveFileInfo.IsDirectory())\r\n      throw \"there is no such archive\";\r\n    if (options.VolumesSizes.Size() > 0)\r\n      return E_NOTIMPL;\r\n    HRESULT result = MyOpenArchive(codecs, archiveName, archiveLink, openCallback);\r\n    RINOK(callback->OpenResult(archiveName, result));\r\n    RINOK(result);\r\n    if (archiveLink.VolumePaths.Size() > 1)\r\n    {\r\n      errorInfo.SystemError = (DWORD)E_NOTIMPL;\r\n      errorInfo.Message = L\"Updating for multivolume archives is not implemented\";\r\n      return E_NOTIMPL;\r\n    }\r\n    archive = archiveLink.GetArchive();\r\n    defaultItemName = archiveLink.GetDefaultItemName();\r\n  }\r\n  else\r\n  {\r\n    /*\r\n    if (archiveType.IsEmpty())\r\n      throw \"type of archive is not specified\";\r\n    */\r\n  }\r\n\r\n  CObjectVector<CDirItem> dirItems;\r\n  if (options.StdInMode)\r\n  {\r\n    CDirItem item;\r\n    item.FullPath = item.Name = options.StdInFileName;\r\n    item.Size = (UInt64)(Int64)-1;\r\n    item.Attributes = 0;\r\n    SYSTEMTIME st;\r\n    FILETIME ft;\r\n    GetSystemTime(&st);\r\n    SystemTimeToFileTime(&st, &ft);\r\n    item.CreationTime = item.LastAccessTime = item.LastWriteTime = ft;\r\n    dirItems.Add(item);\r\n  }\r\n  else\r\n  {\r\n    bool needScanning = false;\r\n    for(int i = 0; i < options.Commands.Size(); i++)\r\n      if (options.Commands[i].ActionSet.NeedScanning())\r\n        needScanning = true;\r\n    if (needScanning)\r\n    {\r\n      CEnumDirItemUpdateCallback enumCallback;\r\n      enumCallback.Callback = callback;\r\n      RINOK(callback->StartScanning());\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(censor, dirItems, &enumCallback, errorPaths, errorCodes);\r\n      for (int i = 0; i < errorPaths.Size(); i++)\r\n      {\r\n        RINOK(callback->CanNotFindError(errorPaths[i], errorCodes[i]));\r\n      }\r\n      if(res != S_OK) \r\n      {\r\n        errorInfo.Message = L\"Scanning error\";\r\n        // errorInfo.FileName = errorPath;\r\n        return res;\r\n      }\r\n      RINOK(callback->FinishScanning());\r\n    }\r\n  }\r\n\r\n  UString tempDirPrefix;\r\n  bool usesTempDir = false;\r\n  \r\n  #ifdef _WIN32\r\n  NDirectory::CTempDirectoryW tempDirectory;\r\n  if (options.EMailMode && options.EMailRemoveAfter)\r\n  {\r\n    tempDirectory.Create(kTempFolderPrefix);\r\n    tempDirPrefix = tempDirectory.GetPath();\r\n    NormalizeDirPathPrefix(tempDirPrefix);\r\n    usesTempDir = true;\r\n  }\r\n  #endif\r\n\r\n  CTempFiles tempFiles;\r\n\r\n  bool createTempFile = false;\r\n  if(!options.StdOutMode && options.UpdateArchiveItself)\r\n  {\r\n    CArchivePath &ap = options.Commands[0].ArchivePath;\r\n    ap = options.ArchivePath;\r\n    // if ((archive != 0 && !usesTempDir) || !options.WorkingDir.IsEmpty())\r\n    if ((archive != 0 || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)\r\n    {\r\n      createTempFile = true;\r\n      ap.Temp = true;\r\n      if (!options.WorkingDir.IsEmpty())\r\n      {\r\n        ap.TempPrefix = options.WorkingDir;\r\n        NormalizeDirPathPrefix(ap.TempPrefix);\r\n      }\r\n    }\r\n  }\r\n\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CArchivePath &ap = options.Commands[i].ArchivePath;\r\n    if (usesTempDir)\r\n    {\r\n      // Check it\r\n      ap.Prefix = tempDirPrefix;\r\n      // ap.Temp = true;\r\n      // ap.TempPrefix = tempDirPrefix;\r\n    }\r\n    if (i > 0 || !createTempFile)\r\n    {\r\n      const UString &path = ap.GetFinalPath();\r\n      if (NFind::DoesFileExist(path))\r\n      {\r\n        errorInfo.SystemError = 0;\r\n        errorInfo.Message = L\"File already exists\";\r\n        errorInfo.FileName = path;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n\r\n  CObjectVector<CArchiveItem> archiveItems;\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(EnumerateInArchiveItems(censor, \r\n        archive, defaultItemName, archiveFileInfo, archiveItems));\r\n  }\r\n\r\n  RINOK(UpdateWithItemLists(codecs, options, archive, archiveItems, dirItems, \r\n      tempFiles, errorInfo, callback));\r\n\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(archiveLink.Close());\r\n    archiveLink.Release();\r\n  }\r\n\r\n  tempFiles.Paths.Clear();\r\n  if(createTempFile)\r\n  {\r\n    try\r\n    {\r\n      CArchivePath &ap = options.Commands[0].ArchivePath;\r\n      const UString &tempPath = ap.GetTempPath();\r\n      if (archive != NULL)\r\n        if (!NDirectory::DeleteFileAlways(archiveName))\r\n        {\r\n          errorInfo.SystemError = ::GetLastError();\r\n          errorInfo.Message = L\"delete file error\";\r\n          errorInfo.FileName = archiveName;\r\n          return E_FAIL;\r\n        }\r\n      if (!NDirectory::MyMoveFile(tempPath, archiveName))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.Message = L\"move file error\";\r\n        errorInfo.FileName = tempPath;\r\n        errorInfo.FileName2 = archiveName;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      throw;\r\n    }\r\n  }\r\n\r\n  #ifdef _WIN32\r\n  if (options.EMailMode)\r\n  {\r\n    NDLL::CLibrary mapiLib;\r\n    if (!mapiLib.Load(TEXT(\"Mapi32.dll\")))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not load Mapi32.dll\";\r\n      return E_FAIL;\r\n    }\r\n    LPMAPISENDDOCUMENTS fnSend = (LPMAPISENDDOCUMENTS)\r\n        mapiLib.GetProcAddress(\"MAPISendDocuments\");\r\n    if (fnSend == 0)\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not find MAPISendDocuments function\";\r\n      return E_FAIL;\r\n    }\r\n    UStringVector fullPaths;\r\n    int i;\r\n    for(i = 0; i < options.Commands.Size(); i++)\r\n    {\r\n      CArchivePath &ap = options.Commands[i].ArchivePath;\r\n      UString arcPath;\r\n      if(!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        return E_FAIL;\r\n      }\r\n      fullPaths.Add(arcPath);\r\n    }\r\n    CCurrentDirRestorer curDirRestorer;\r\n    for(i = 0; i < fullPaths.Size(); i++)\r\n    {\r\n      UString arcPath = fullPaths[i];\r\n      UString fileName = ExtractFileNameFromPath(arcPath);\r\n      AString path = GetAnsiString(arcPath);\r\n      AString name = GetAnsiString(fileName);\r\n      // Warning!!! MAPISendDocuments function changes Current directory\r\n      fnSend(0, \";\", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0); \r\n    }\r\n  }\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/Update.h",
    "content": "// Update.h\r\n\r\n#ifndef __UPDATE_H\r\n#define __UPDATE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"Property.h\"\r\n#include \"LoadCodecs.h\"\r\n\r\nstruct CArchivePath\r\n{\r\n  UString Prefix;   // path(folder) prefix including slash\r\n  UString Name; // base name\r\n  UString BaseExtension; // archive type extension or \"exe\" extension \r\n  UString VolExtension;  // archive type extension for volumes\r\n\r\n  bool Temp;\r\n  UString TempPrefix;  // path(folder) for temp location\r\n  UString TempPostfix;\r\n\r\n  CArchivePath(): Temp(false) {};\r\n  \r\n  void ParseFromPath(const UString &path)\r\n  {\r\n    SplitPathToParts(path, Prefix, Name);\r\n    if (Name.IsEmpty())\r\n      return;\r\n    int dotPos = Name.ReverseFind(L'.');\r\n    if (dotPos <= 0)\r\n      return;\r\n    if (dotPos == Name.Length() - 1)\r\n    {\r\n      Name = Name.Left(dotPos);\r\n      BaseExtension.Empty();\r\n      return;\r\n    }\r\n    if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0)\r\n    {\r\n      BaseExtension = Name.Mid(dotPos + 1);\r\n      Name = Name.Left(dotPos);\r\n    }\r\n    else\r\n      BaseExtension.Empty();\r\n  }\r\n\r\n  UString GetPathWithoutExt() const\r\n  {\r\n    return Prefix + Name;\r\n  }\r\n\r\n  UString GetFinalPath() const\r\n  {\r\n    UString path = GetPathWithoutExt();\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    return path;\r\n  }\r\n\r\n  \r\n  UString GetTempPath() const\r\n  {\r\n    UString path = TempPrefix + Name;\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    path += L\".tmp\";\r\n    path += TempPostfix;\r\n    return path; \r\n  }\r\n};\r\n\r\nstruct CUpdateArchiveCommand\r\n{\r\n  UString UserArchivePath;\r\n  CArchivePath ArchivePath;\r\n  NUpdateArchive::CActionSet ActionSet;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  int FormatIndex;\r\n  CObjectVector<CProperty> Properties;\r\n  CCompressionMethodMode(): FormatIndex(-1) {}\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  CCompressionMethodMode MethodMode;\r\n\r\n  CObjectVector<CUpdateArchiveCommand> Commands;\r\n  bool UpdateArchiveItself;\r\n  CArchivePath ArchivePath;\r\n  \r\n  bool SfxMode;\r\n  UString SfxModule;\r\n  \r\n  bool OpenShareForWrite;\r\n\r\n  bool StdInMode;\r\n  UString StdInFileName;\r\n  bool StdOutMode;\r\n  \r\n  bool EMailMode;\r\n  bool EMailRemoveAfter;\r\n  UString EMailAddress;\r\n\r\n  UString WorkingDir;\r\n\r\n  bool Init(const CCodecs *codecs, const UString &arcPath, const UString &arcType);\r\n\r\n  CUpdateOptions():\r\n    UpdateArchiveItself(true),\r\n    SfxMode(false),\r\n    StdInMode(false),\r\n    StdOutMode(false),\r\n    EMailMode(false),\r\n    EMailRemoveAfter(false),\r\n    OpenShareForWrite(false)\r\n      {};\r\n  CRecordVector<UInt64> VolumesSizes;\r\n};\r\n\r\nstruct CErrorInfo\r\n{\r\n  DWORD SystemError;\r\n  UString FileName;\r\n  UString FileName2;\r\n  UString Message;\r\n  // UStringVector ErrorPaths;\r\n  // CRecordVector<DWORD> ErrorCodes;\r\n  CErrorInfo(): SystemError(0) {};\r\n};\r\n\r\nstruct CUpdateErrorInfo: public CErrorInfo\r\n{\r\n};\r\n\r\n#define INTERFACE_IUpdateCallbackUI2(x) \\\r\n  INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \\\r\n  virtual HRESULT StartScanning() x; \\\r\n  virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT FinishScanning() x; \\\r\n  virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \\\r\n  virtual HRESULT FinishArchive() x; \\\r\n\r\nstruct IUpdateCallbackUI2: public IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI2(=0)\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor, \r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/UpdateAction.cpp",
    "content": "// UpdateAction.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n\r\nnamespace NUpdateArchive {\r\n\r\nconst CActionSet kAddActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kUpdateActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kFreshActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kSynchronizeActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n};\r\n\r\nconst CActionSet kDeleteActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/UpdateAction.h",
    "content": "// UpdateAction.h\r\n\r\n#ifndef __UPDATE_ACTION_H\r\n#define __UPDATE_ACTION_H\r\n\r\nnamespace NUpdateArchive {\r\n\r\n  namespace NPairState \r\n  {\r\n    const int kNumValues = 7;\r\n    enum EEnum\r\n    {\r\n      kNotMasked = 0,\r\n      kOnlyInArchive,\r\n      kOnlyOnDisk,\r\n      kNewInArchive,\r\n      kOldInArchive,\r\n      kSameFiles,\r\n      kUnknowNewerFiles\r\n    };\r\n  }\r\n  namespace NPairAction\r\n  {\r\n    enum EEnum\r\n    {\r\n      kIgnore = 0,\r\n      kCopy,\r\n      kCompress,\r\n      kCompressAsAnti\r\n    };\r\n  }\r\n  struct CActionSet\r\n  {\r\n    NPairAction::EEnum StateActions[NPairState::kNumValues];\r\n    bool NeedScanning() const\r\n    {\r\n      int i;\r\n      for (i = 0; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] == NPairAction::kCompress)\r\n          return true;\r\n      for (i = 1; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] != NPairAction::kIgnore)\r\n          return true;\r\n      return false;\r\n    }\r\n  };\r\n  extern const CActionSet kAddActionSet;\r\n  extern const CActionSet kUpdateActionSet;\r\n  extern const CActionSet kFreshActionSet;\r\n  extern const CActionSet kSynchronizeActionSet;\r\n  extern const CActionSet kDeleteActionSet;\r\n};\r\n\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/UpdateCallback.cpp",
    "content": "// UpdateCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCArchiveUpdateCallback::CArchiveUpdateCallback():\r\n  Callback(0),\r\n  ShareForWrite(false),\r\n  StdInMode(false),\r\n  DirItems(0),\r\n  ArchiveItems(0),\r\n  UpdatePairs(0)\r\n  {}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetTotal(size);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\n\r\n/*\r\nSTATPROPSTG kProperties[] = \r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidIsFolder, VT_BOOL},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidLastAccessTime, VT_FILETIME},\r\n  { NULL, kpidCreationTime, VT_FILETIME},\r\n  { NULL, kpidLastWriteTime, VT_FILETIME},\r\n  { NULL, kpidAttributes, VT_UI4},\r\n  { NULL, kpidIsAnti, VT_BOOL}\r\n};\r\n*/\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)\r\n{\r\n  return E_NOTIMPL;\r\n  /*\r\n  return CStatPropEnumerator::CreateEnumerator(kProperties, \r\n      sizeof(kProperties) / sizeof(kProperties[0]), enumerator);\r\n  */\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  COM_TRY_BEGIN\r\n  RINOK(Callback->CheckBreak());\r\n  const CUpdatePair2 &updatePair = (*UpdatePairs)[index];\r\n  if(newData != NULL)\r\n    *newData = BoolToInt(updatePair.NewData);\r\n  if(newProperties != NULL)\r\n    *newProperties = BoolToInt(updatePair.NewProperties);\r\n  if(indexInArchive != NULL)\r\n  {\r\n    if (updatePair.ExistInArchive)\r\n    {\r\n      if (ArchiveItems == 0)\r\n        *indexInArchive = updatePair.ArchiveItemIndex;\r\n      else\r\n        *indexInArchive = (*ArchiveItems)[updatePair.ArchiveItemIndex].IndexInServer;\r\n    }\r\n    else\r\n      *indexInArchive = UInt32(-1);\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &updatePair = (*UpdatePairs)[index];\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    propVariant = updatePair.IsAnti;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  if (updatePair.IsAnti)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidIsFolder:\r\n      case kpidPath:\r\n        break;\r\n      case kpidSize:\r\n        propVariant = (UInt64)0;\r\n        propVariant.Detach(value);\r\n        return S_OK;\r\n      default:\r\n        propVariant.Detach(value);\r\n        return S_OK;\r\n    }\r\n  }\r\n  \r\n  if(updatePair.ExistOnDisk)\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[updatePair.DirItemIndex];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:\r\n        propVariant = dirItem.Name;\r\n        break;\r\n      case kpidIsFolder:\r\n        propVariant = dirItem.IsDirectory();\r\n        break;\r\n      case kpidSize:\r\n        propVariant = dirItem.Size;\r\n        break;\r\n      case kpidAttributes:\r\n        propVariant = dirItem.Attributes;\r\n        break;\r\n      case kpidLastAccessTime:\r\n        propVariant = dirItem.LastAccessTime;\r\n        break;\r\n      case kpidCreationTime:\r\n        propVariant = dirItem.CreationTime;\r\n        break;\r\n      case kpidLastWriteTime:\r\n        propVariant = dirItem.LastWriteTime;\r\n        break;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (propID == kpidPath)\r\n    {\r\n      if (updatePair.NewNameIsDefined)\r\n      {\r\n        propVariant = updatePair.NewName;\r\n        propVariant.Detach(value);\r\n        return S_OK;\r\n      }\r\n    }\r\n    if (updatePair.ExistInArchive && Archive)\r\n    {\r\n      UInt32 indexInArchive;\r\n      if (ArchiveItems == 0)\r\n        indexInArchive = updatePair.ArchiveItemIndex;\r\n      else\r\n        indexInArchive = (*ArchiveItems)[updatePair.ArchiveItemIndex].IndexInServer;\r\n      return Archive->GetProperty(indexInArchive, propID, value);\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &updatePair = (*UpdatePairs)[index];\r\n  if(!updatePair.NewData)\r\n    return E_FAIL;\r\n  \r\n  RINOK(Callback->CheckBreak());\r\n  RINOK(Callback->Finilize());\r\n\r\n  if(updatePair.IsAnti)\r\n  {\r\n    return Callback->GetStream((*ArchiveItems)[updatePair.ArchiveItemIndex].Name, true);\r\n  }\r\n  const CDirItem &dirItem = (*DirItems)[updatePair.DirItemIndex];\r\n  RINOK(Callback->GetStream(dirItem.Name, false));\r\n \r\n  if(dirItem.IsDirectory())\r\n    return S_OK;\r\n\r\n  if (StdInMode)\r\n  {\r\n    CStdInFileStream *inStreamSpec = new CStdInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  else\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if(!inStreamSpec->OpenShared(path, ShareForWrite))\r\n    {\r\n      return Callback->OpenFileError(path, ::GetLastError());\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetOperationResult(operationResult);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if(!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->CryptoGetTextPassword2(passwordIsDefined, password);\r\n  COM_TRY_END\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/UpdateCallback.h",
    "content": "// UpdateCallback.h\r\n\r\n#ifndef __UPDATECALLBACK_H\r\n#define __UPDATECALLBACK_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/UpdatePair.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#define INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT SetTotal(UInt64 size) x; \\\r\n  virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \\\r\n  virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x; \\\r\n  virtual HRESULT CheckBreak() x; \\\r\n  virtual HRESULT Finilize() x; \\\r\n  virtual HRESULT SetNumFiles(UInt64 numFiles) x; \\\r\n  virtual HRESULT GetStream(const wchar_t *name, bool isAnti) x; \\\r\n  virtual HRESULT OpenFileError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT SetOperationResult(Int32 operationResult) x; \\\r\n  virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x; \\\r\n\r\n  // virtual HRESULT CloseProgress() { return S_OK; };\r\n\r\nstruct IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI(=0)\r\n};\r\n\r\nclass CArchiveUpdateCallback: \r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveUpdateCallback2, \r\n      ICryptoGetTextPassword2,\r\n      ICompressProgressInfo)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IUpdateCallback\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);  \r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  IUpdateCallbackUI *Callback;\r\n\r\n  UString DirPrefix;\r\n  bool ShareForWrite;\r\n  bool StdInMode;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n  const CObjectVector<CArchiveItem> *ArchiveItems;\r\n  const CObjectVector<CUpdatePair2> *UpdatePairs;\r\n  CMyComPtr<IInArchive> Archive;\r\n\r\n  CArchiveUpdateCallback();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/UpdatePair.cpp",
    "content": "// UpdatePair.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <time.h>\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"UpdatePair.h\"\r\n#include \"SortUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nstatic int MyCompareTime(NFileTimeType::EEnum fileTimeType, \r\n    const FILETIME &time1, const FILETIME &time2)\r\n{\r\n  switch(fileTimeType)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n      return ::CompareFileTime(&time1, &time2);\r\n    case NFileTimeType::kUnix:\r\n      {\r\n        UInt32 unixTime1, unixTime2;\r\n        if (!FileTimeToUnixTime(time1, unixTime1))\r\n        {\r\n          unixTime1 = 0;\r\n          // throw 4191614;\r\n        }\r\n        if (!FileTimeToUnixTime(time2, unixTime2))\r\n        {\r\n          unixTime2 = 0;\r\n          // throw 4191615;\r\n        }\r\n        return MyCompare(unixTime1, unixTime2);\r\n      }\r\n    case NFileTimeType::kDOS:\r\n      {\r\n        UInt32 dosTime1, dosTime2;\r\n        FileTimeToDosTime(time1, dosTime1);\r\n        FileTimeToDosTime(time2, dosTime2);\r\n        /*\r\n        if (!FileTimeToDosTime(time1, dosTime1))\r\n          throw 4191616;\r\n        if (!FileTimeToDosTime(time2, dosTime2))\r\n          throw 4191617;\r\n        */\r\n        return MyCompare(dosTime1, dosTime2);\r\n      }\r\n  }\r\n  throw 4191618;\r\n}\r\n\r\nstatic const wchar_t *kDuplicateFileNameMessage = L\"Duplicate filename:\";\r\n\r\n/*\r\nstatic const char *kNotCensoredCollisionMessaged = \"Internal file name collision:\\n\";\r\nstatic const char *kSameTimeChangedSizeCollisionMessaged = \r\n    \"Collision between files with same date/time and different sizes:\\n\";\r\n*/\r\n\r\nstatic void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)\r\n{\r\n  for(int i = 0; i + 1 < indices.Size(); i++)\r\n    if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)\r\n    {\r\n      UString message = kDuplicateFileNameMessage;\r\n      message += L\"\\n\";\r\n      message += strings[indices[i]];\r\n      message += L\"\\n\";\r\n      message += strings[indices[i + 1]];\r\n      throw message;\r\n    }\r\n}\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CObjectVector<CDirItem> &dirItems, \r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CObjectVector<CUpdatePair> &updatePairs)\r\n{\r\n  CIntVector dirIndices, archiveIndices;\r\n  UStringVector dirNames, archiveNames;\r\n  \r\n  int numDirItems = dirItems.Size(); \r\n  int i;\r\n  for(i = 0; i < numDirItems; i++)\r\n    dirNames.Add(dirItems[i].Name);\r\n  SortFileNames(dirNames, dirIndices);\r\n  TestDuplicateString(dirNames, dirIndices);\r\n\r\n  int numArchiveItems = archiveItems.Size(); \r\n  for(i = 0; i < numArchiveItems; i++)\r\n    archiveNames.Add(archiveItems[i].Name);\r\n  SortFileNames(archiveNames, archiveIndices);\r\n  TestDuplicateString(archiveNames, archiveIndices);\r\n  \r\n  int dirItemIndex = 0, archiveItemIndex = 0; \r\n  CUpdatePair pair;\r\n  while(dirItemIndex < numDirItems && archiveItemIndex < numArchiveItems)\r\n  {\r\n    int dirItemIndex2 = dirIndices[dirItemIndex],\r\n        archiveItemIndex2 = archiveIndices[archiveItemIndex]; \r\n    const CDirItem &dirItem = dirItems[dirItemIndex2];\r\n    const CArchiveItem &archiveItem = archiveItems[archiveItemIndex2];\r\n    int compareResult = CompareFileNames(dirItem.Name, archiveItem.Name);\r\n    if (compareResult < 0)\r\n    {\r\n        pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n        pair.DirItemIndex = dirItemIndex2;\r\n        dirItemIndex++;\r\n    }\r\n    else if (compareResult > 0)\r\n    {\r\n      pair.State = archiveItem.Censored ? \r\n        NUpdateArchive::NPairState::kOnlyInArchive: NUpdateArchive::NPairState::kNotMasked;\r\n      pair.ArchiveItemIndex = archiveItemIndex2;\r\n      archiveItemIndex++;\r\n    }\r\n    else\r\n    {\r\n      if (!archiveItem.Censored)\r\n        throw 1082022;; // TTString(kNotCensoredCollisionMessaged + dirItem.Name);\r\n      pair.DirItemIndex = dirItemIndex2;\r\n      pair.ArchiveItemIndex = archiveItemIndex2;\r\n      switch (MyCompareTime(fileTimeType, dirItem.LastWriteTime, archiveItem.LastWriteTime))\r\n      {\r\n        case -1:\r\n          pair.State = NUpdateArchive::NPairState::kNewInArchive;\r\n          break;\r\n        case 1:\r\n          pair.State = NUpdateArchive::NPairState::kOldInArchive;\r\n          break;\r\n        default:\r\n          if (archiveItem.SizeIsDefined)\r\n            if (dirItem.Size != archiveItem.Size)\r\n              // throw 1082034; // kSameTimeChangedSizeCollisionMessaged;\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n            else\r\n              pair.State = NUpdateArchive::NPairState::kSameFiles;\r\n          else\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n      }\r\n      dirItemIndex++;\r\n      archiveItemIndex++;\r\n    }\r\n    updatePairs.Add(pair);\r\n  }\r\n  for(;dirItemIndex < numDirItems; dirItemIndex++)\r\n  {\r\n    pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n    pair.DirItemIndex = dirIndices[dirItemIndex];\r\n    updatePairs.Add(pair);\r\n  }\r\n  for(;archiveItemIndex < numArchiveItems; archiveItemIndex++)\r\n  {\r\n    int archiveItemIndex2 = archiveIndices[archiveItemIndex]; \r\n    const CArchiveItem &archiveItem = archiveItems[archiveItemIndex2];\r\n    pair.State = archiveItem.Censored ?  \r\n        NUpdateArchive::NPairState::kOnlyInArchive: NUpdateArchive::NPairState::kNotMasked;\r\n    pair.ArchiveItemIndex = archiveItemIndex2;\r\n    updatePairs.Add(pair);\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/UpdatePair.h",
    "content": "// UpdatePair.h\r\n\r\n#ifndef __UPDATE_PAIR_H\r\n#define __UPDATE_PAIR_H\r\n\r\n#include \"DirItem.h\"\r\n#include \"UpdateAction.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CUpdatePair\r\n{\r\n  NUpdateArchive::NPairState::EEnum State;\r\n  int ArchiveItemIndex;\r\n  int DirItemIndex;\r\n};\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CObjectVector<CDirItem> &dirItems,\r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CObjectVector<CUpdatePair> &updatePairs);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/UpdateProduce.cpp",
    "content": "// UpdateProduce.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateProduce.h\"\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic const char *kUpdateActionSetCollision =\r\n    \"Internal collision in update action set\";\r\n\r\nvoid UpdateProduce(\r\n    const CObjectVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CObjectVector<CUpdatePair2> &operationChain)\r\n{\r\n  for(int i = 0; i < updatePairs.Size(); i++)\r\n  {\r\n    // CUpdateArchiveRange aRange;\r\n    const CUpdatePair &pair = updatePairs[i];\r\n\r\n    CUpdatePair2 pair2;\r\n    pair2.IsAnti = false;\r\n    pair2.ArchiveItemIndex = pair.ArchiveItemIndex;\r\n    pair2.DirItemIndex = pair.DirItemIndex;\r\n    pair2.ExistInArchive = (pair.State != NPairState::kOnlyOnDisk);\r\n    pair2.ExistOnDisk = (pair.State != NPairState::kOnlyInArchive && pair.State != NPairState::kNotMasked);\r\n    switch(actionSet.StateActions[pair.State])\r\n    {\r\n      case NPairAction::kIgnore:\r\n        /*\r\n        if (pair.State != NPairState::kOnlyOnDisk)\r\n          IgnoreArchiveItem(m_ArchiveItems[pair.ArchiveItemIndex]);\r\n        // cout << \"deleting\";\r\n        */\r\n        break;\r\n      case NPairAction::kCopy:\r\n        {\r\n          if (pair.State == NPairState::kOnlyOnDisk)\r\n            throw kUpdateActionSetCollision;\r\n          pair2.NewData = pair2.NewProperties = false;\r\n          operationChain.Add(pair2);\r\n          break;\r\n        }\r\n      case NPairAction::kCompress:\r\n        {\r\n          if (pair.State == NPairState::kOnlyInArchive || \r\n            pair.State == NPairState::kNotMasked)\r\n            throw kUpdateActionSetCollision;\r\n          pair2.NewData = pair2.NewProperties = true;\r\n          operationChain.Add(pair2);\r\n          break;\r\n        }\r\n      case NPairAction::kCompressAsAnti:\r\n        {\r\n          pair2.IsAnti = true;\r\n          pair2.NewData = pair2.NewProperties = true;\r\n          operationChain.Add(pair2);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/UpdateProduce.h",
    "content": "// UpdateProduce.h\r\n\r\n#ifndef __UPDATE_PRODUCE_H\r\n#define __UPDATE_PRODUCE_H\r\n\r\n#include \"UpdatePair.h\"\r\n\r\nstruct CUpdatePair2\r\n{\r\n  // bool OperationIsCompress;\r\n  bool NewData;\r\n  bool NewProperties;\r\n\r\n  bool ExistInArchive;\r\n  bool ExistOnDisk;\r\n  bool IsAnti;\r\n  int ArchiveItemIndex;\r\n  int DirItemIndex;\r\n\r\n  bool NewNameIsDefined;\r\n  UString NewName;\r\n\r\n  CUpdatePair2(): NewNameIsDefined(false) {}\r\n};\r\n\r\nvoid UpdateProduce(\r\n    const CObjectVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CObjectVector<CUpdatePair2> &operationChain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/WorkDir.cpp",
    "content": "// WorkDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"WorkDir.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nstatic inline UINT GetCurrentCodePage() \r\n  { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)\r\n{\r\n  NWorkDir::NMode::EEnum mode = workDirInfo.Mode;\r\n  if (workDirInfo.ForRemovableOnly)\r\n  {\r\n    mode = NWorkDir::NMode::kCurrent;\r\n    UString prefix = path.Left(3);\r\n    if (prefix[1] == L':' && prefix[2] == L'\\\\')\r\n    {\r\n      UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));\r\n      if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)\r\n        mode = workDirInfo.Mode;\r\n    }\r\n    /*\r\n    CParsedPath parsedPath;\r\n    parsedPath.ParsePath(archiveName);\r\n    UINT driveType = GetDriveType(parsedPath.Prefix);\r\n    if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))\r\n      mode = NZipSettings::NWorkDir::NMode::kCurrent;\r\n    */\r\n  }\r\n  switch(mode)\r\n  {\r\n    case NWorkDir::NMode::kCurrent:\r\n    {\r\n      return ExtractDirPrefixFromPath(path);\r\n    }\r\n    case NWorkDir::NMode::kSpecified:\r\n    {\r\n      UString tempDir = workDirInfo.Path;\r\n      NormalizeDirPathPrefix(tempDir);\r\n      return tempDir;\r\n    }\r\n    default:\r\n    {\r\n      UString tempDir;\r\n      if(!NFile::NDirectory::MyGetTempPath(tempDir))\r\n        throw 141717;\r\n      return tempDir;\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/WorkDir.h",
    "content": "// WorkDir.h\r\n\r\n#ifndef __WORKDIR_H\r\n#define __WORKDIR_H\r\n\r\n#include \"ZipRegistry.h\"\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Common/ZipRegistry.h",
    "content": "// ZipRegistry.h\r\n\r\n#ifndef __ZIPREGISTRY_H\r\n#define __ZIPREGISTRY_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"ExtractMode.h\"\r\n\r\nnamespace NExtract\r\n{\r\n  struct CInfo\r\n  {\r\n    NPathMode::EEnum PathMode;\r\n    NOverwriteMode::EEnum OverwriteMode;\r\n    UStringVector Paths;\r\n    bool ShowPassword;\r\n  };\r\n}\r\n\r\nnamespace NCompression {\r\n  \r\n  struct CFormatOptions\r\n  {\r\n    CSysString FormatID;\r\n    UString Options;\r\n    UString Method;\r\n    UString EncryptionMethod;\r\n    UInt32 Level;\r\n    UInt32 Dictionary;\r\n    UInt32 Order;\r\n    UInt32 BlockLogSize;\r\n    UInt32 NumThreads;\r\n    void ResetForLevelChange() \r\n    { \r\n      BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1); \r\n      Method.Empty();\r\n      // EncryptionMethod.Empty();\r\n      // Options.Empty();\r\n    }\r\n    CFormatOptions() { ResetForLevelChange(); }\r\n  };\r\n\r\n  struct CInfo\r\n  {\r\n    UStringVector HistoryArchives;\r\n    UInt32 Level;\r\n    UString ArchiveType;\r\n\r\n    CObjectVector<CFormatOptions> FormatOptionsVector;\r\n\r\n    bool ShowPassword;\r\n    bool EncryptHeaders;\r\n  };\r\n}\r\n\r\nnamespace NWorkDir{\r\n  \r\n  namespace NMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kSystem,\r\n      kCurrent,\r\n      kSpecified\r\n    };\r\n  }\r\n  struct CInfo\r\n  {\r\n    NMode::EEnum Mode;\r\n    UString Path;\r\n    bool ForRemovableOnly;\r\n    void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }\r\n    void SetDefault()\r\n    {\r\n      Mode = NMode::kSystem;\r\n      Path.Empty();\r\n      SetForRemovableOnlyDefault();\r\n    }\r\n  };\r\n}\r\n\r\nvoid SaveExtractionInfo(const NExtract::CInfo &info);\r\nvoid ReadExtractionInfo(NExtract::CInfo &info);\r\n\r\nvoid SaveCompressionInfo(const NCompression::CInfo &info);\r\nvoid ReadCompressionInfo(NCompression::CInfo &info);\r\n\r\nvoid SaveWorkDirInfo(const NWorkDir::CInfo &info);\r\nvoid ReadWorkDirInfo(NWorkDir::CInfo &info);\r\n\r\nvoid SaveCascadedMenu(bool enabled);\r\nbool ReadCascadedMenu();\r\n\r\nvoid SaveContextMenuStatus(UInt32 value);\r\nbool ReadContextMenuStatus(UInt32 &value);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/ConsoleClose.cpp",
    "content": "// ConsoleClose.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n\r\nstatic int g_BreakCounter = 0;\r\nstatic const int kBreakAbortThreshold = 2;\r\n\r\nnamespace NConsoleClose {\r\n\r\nstatic BOOL WINAPI HandlerRoutine(DWORD ctrlType)\r\n{\r\n  if (ctrlType == CTRL_LOGOFF_EVENT)\r\n  {\r\n    // printf(\"\\nCTRL_LOGOFF_EVENT\\n\");\r\n    return TRUE;\r\n  }\r\n\r\n  g_BreakCounter++;\r\n  if (g_BreakCounter < kBreakAbortThreshold)\r\n    return TRUE;\r\n  return FALSE;\r\n  /*\r\n  switch(ctrlType)\r\n  {\r\n    case CTRL_C_EVENT:\r\n    case CTRL_BREAK_EVENT:\r\n      if (g_BreakCounter < kBreakAbortThreshold)\r\n      return TRUE;\r\n  }\r\n  return FALSE;\r\n  */\r\n}\r\n\r\nbool TestBreakSignal()\r\n{\r\n  /*\r\n  if (g_BreakCounter > 0)\r\n    return true;\r\n  */\r\n  return (g_BreakCounter > 0);\r\n}\r\n\r\nvoid CheckCtrlBreak()\r\n{\r\n  if (TestBreakSignal())\r\n    throw CCtrlBreakException();\r\n}\r\n\r\nCCtrlHandlerSetter::CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\nCCtrlHandlerSetter::~CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/ConsoleClose.h",
    "content": "// ConsoleCloseUtils.h\r\n\r\n#ifndef __CONSOLECLOSEUTILS_H\r\n#define __CONSOLECLOSEUTILS_H\r\n\r\nnamespace NConsoleClose {\r\n\r\nbool TestBreakSignal();\r\n\r\nclass CCtrlHandlerSetter\r\n{\r\npublic:\r\n  CCtrlHandlerSetter();\r\n  virtual ~CCtrlHandlerSetter();\r\n};\r\n\r\nclass CCtrlBreakException \r\n{};\r\n\r\nvoid CheckCtrlBreak();\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UserInputUtils.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Error.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\n// static const char *kCantAutoRename = \"can not create file with auto name\\n\";\r\n// static const char *kCantRenameFile = \"can not rename existing file\\n\";\r\n// static const char *kCantDeleteOutputFile = \"can not delete output file \";\r\nstatic const char *kError = \"ERROR: \";\r\nstatic const char *kMemoryExceptionMessage = \"Can't allocate required memory!\";\r\n\r\nstatic const char *kProcessing = \"Processing archive: \";\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kNoFiles = \"No files to process\";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCrcFailed = \"CRC Failed\";\r\nstatic const char *kCrcFailedEncrypted = \"CRC Failed in encrypted file. Wrong password?\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kDataErrorEncrypted = \"Data Error in encrypted file. Wrong password?\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::AskOverwrite(\r\n    const wchar_t *existName, const FILETIME *, const UInt64 *,\r\n    const wchar_t *newName, const FILETIME *, const UInt64 *,\r\n    Int32 *answer)\r\n{\r\n  (*OutStream) << \"file \" << existName << \r\n    \"\\nalready exists. Overwrite with \" << endl;\r\n  (*OutStream) << newName;\r\n  \r\n  NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);\r\n  \r\n  switch(overwriteAnswer)\r\n  {\r\n    case NUserAnswerMode::kQuit:\r\n      return E_ABORT;\r\n    case NUserAnswerMode::kNo:\r\n      *answer = NOverwriteAnswer::kNo;\r\n      break;\r\n    case NUserAnswerMode::kNoAll:\r\n      *answer = NOverwriteAnswer::kNoToAll;\r\n      break;\r\n    case NUserAnswerMode::kYesAll:\r\n      *answer = NOverwriteAnswer::kYesToAll;\r\n      break;\r\n    case NUserAnswerMode::kYes:\r\n      *answer = NOverwriteAnswer::kYes;\r\n      break;\r\n    case NUserAnswerMode::kAutoRename:\r\n      *answer = NOverwriteAnswer::kAutoRename;\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position)\r\n{\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      (*OutStream) << kExtractingString;\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kTest:\r\n      (*OutStream) << kTestingString;\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kSkip:\r\n      (*OutStream) << kSkippingString;\r\n      break;\r\n  };\r\n  (*OutStream) << name;\r\n  if (position != 0)\r\n    (*OutStream) << \" <\" << *position << \">\";\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)\r\n{\r\n  (*OutStream) << message << endl;\r\n  NumFileErrorsInCurrentArchive++;\r\n  NumFileErrors++;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumFileErrorsInCurrentArchive++;\r\n      NumFileErrors++;\r\n      (*OutStream) << \"     \";\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          (*OutStream) << kUnsupportedMethod;\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError);\r\n          break;\r\n        default:\r\n          (*OutStream) << kUnknownError;\r\n      }\r\n    }\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream); \r\n    PasswordIsDefined = true;\r\n  }\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)\r\n{\r\n  NumArchives++;\r\n  NumFileErrorsInCurrentArchive = 0;\r\n  (*OutStream) << endl << kProcessing << name << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT result, bool encrypted)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n  {\r\n    (*OutStream) << \"Error: \";\r\n    if (encrypted)\r\n      (*OutStream) << \"Can not open encrypted archive. Wrong password?\";\r\n    else\r\n      (*OutStream) << \"Can not open file as archive\";\r\n    (*OutStream) << endl;\r\n    NumArchiveErrors++;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nHRESULT CExtractCallbackConsole::ThereAreNoFiles()\r\n{\r\n  (*OutStream) << endl << kNoFiles << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)\r\n{\r\n  if (result == S_OK)\r\n  {\r\n    (*OutStream) << endl;\r\n    if (NumFileErrorsInCurrentArchive == 0)\r\n      (*OutStream) << kEverythingIsOk << endl;\r\n    else \r\n    {\r\n      NumArchiveErrors++;\r\n      (*OutStream) << \"Sub items Errors: \" << NumFileErrorsInCurrentArchive << endl;\r\n    }\r\n  }\r\n  if (result == S_OK)\r\n    return result;\r\n  NumArchiveErrors++;\r\n  if (result == E_ABORT || result == ERROR_DISK_FULL)\r\n    return result;\r\n  (*OutStream) << endl << kError;\r\n  if (result == E_OUTOFMEMORY)\r\n    (*OutStream) << kMemoryExceptionMessage;\r\n  else\r\n  {\r\n    UString message;\r\n    NError::MyFormatMessage(result, message);\r\n    (*OutStream) << message;\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::SetPassword(const UString &password)\r\n{\r\n  PasswordIsDefined = true;\r\n  Password = password;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.h",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#ifndef __EXTRACTCALLBACKCONSOLE_H\r\n#define __EXTRACTCALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../Common/ArchiveExtractCallback.h\"\r\n\r\nclass CExtractCallbackConsole: \r\n  public IExtractCallbackUI,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IFolderArchiveExtractCallback, ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(UInt64 total);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IFolderArchiveExtractCallback\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer);\r\n  STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position);\r\n\r\n  STDMETHOD(MessageError)(const wchar_t *message);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  HRESULT BeforeOpen(const wchar_t *name);\r\n  HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);\r\n  HRESULT ThereAreNoFiles();\r\n  HRESULT ExtractResult(HRESULT result);\r\n\r\n  HRESULT SetPassword(const UString &password);\r\n\r\npublic:\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  \r\n  UInt64 NumArchives;\r\n  UInt64 NumArchiveErrors;\r\n  UInt64 NumFileErrors;\r\n  UInt64 NumFileErrorsInCurrentArchive;\r\n\r\n  CStdOutStream *OutStream;\r\n\r\n  void Init()\r\n  {\r\n    NumArchives = 0;\r\n    NumArchiveErrors = 0;\r\n    NumFileErrors = 0;\r\n    NumFileErrorsInCurrentArchive = 0;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/List.cpp",
    "content": "// List.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"List.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../Common/PropIDUtils.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstruct CPropIdToName\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n};\r\n\r\nstatic CPropIdToName kPropIdToName[] =  \r\n{\r\n  { kpidPath, L\"Path\" },\r\n  { kpidName, L\"Name\" },\r\n  { kpidIsFolder, L\"Folder\" }, \r\n  { kpidSize, L\"Size\" },\r\n  { kpidPackedSize, L\"Packed Size\" },\r\n  { kpidAttributes, L\"Attributes\" },\r\n  { kpidCreationTime, L\"Created\" },\r\n  { kpidLastAccessTime, L\"Accessed\" },\r\n  { kpidLastWriteTime, L\"Modified\" },\r\n  { kpidSolid, L\"Solid\" },\r\n  { kpidCommented, L\"Commented\" },\r\n  { kpidEncrypted, L\"Encrypted\" },\r\n  { kpidSplitBefore, L\"Split Before\" },\r\n  { kpidSplitAfter, L\"Split After\" },\r\n  { kpidDictionarySize, L\"Dictionary Size\" },\r\n  { kpidCRC, L\"CRC\" },\r\n  { kpidType, L\"Type\" },\r\n  { kpidIsAnti, L\"Anti\" },\r\n  { kpidMethod, L\"Method\" },\r\n  { kpidHostOS, L\"Host OS\" },\r\n  { kpidFileSystem, L\"File System\" },\r\n  { kpidUser, L\"User\" },\r\n  { kpidGroup, L\"Group\" },\r\n  { kpidBlock, L\"Block\" },\r\n  { kpidComment, L\"Comment\" },\r\n  { kpidPosition, L\"Position\" },\r\n  { kpidPrefix, L\"Prefix\" },\r\n  { kpidNumSubFolders, L\"Folders\" },\r\n  { kpidNumSubFiles, L\"Files\" },\r\n  { kpidUnpackVer, L\"Version\" },\r\n  { kpidVolume, L\"Volume\" },\r\n  { kpidIsVolume, L\"Multivolume\" },\r\n  { kpidOffset, L\"Offset\" },\r\n  { kpidLinks, L\"Links\" },\r\n  { kpidNumBlocks, L\"Blocks\" },\r\n  { kpidNumVolumes, L\"Volumes\" }\r\n};\r\n\r\nstatic const char kEmptyAttributeChar = '.';\r\nstatic const char kDirectoryAttributeChar = 'D';\r\nstatic const char kReadonlyAttributeChar  = 'R';\r\nstatic const char kHiddenAttributeChar    = 'H';\r\nstatic const char kSystemAttributeChar    = 'S';\r\nstatic const char kArchiveAttributeChar   = 'A';\r\n\r\nstatic const char *kListing = \"Listing archive: \";\r\nstatic const wchar_t *kFilesMessage = L\"files\";\r\nstatic const wchar_t *kDirsMessage = L\"folders\";\r\n\r\nstatic void GetAttributesString(DWORD wa, bool directory, char *s)\r\n{\r\n  s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || directory) ? \r\n      kDirectoryAttributeChar: kEmptyAttributeChar;\r\n  s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0)? \r\n      kReadonlyAttributeChar: kEmptyAttributeChar;\r\n  s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? \r\n      kHiddenAttributeChar: kEmptyAttributeChar;\r\n  s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? \r\n      kSystemAttributeChar: kEmptyAttributeChar;\r\n  s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? \r\n      kArchiveAttributeChar: kEmptyAttributeChar;\r\n  s[5] = '\\0';\r\n}\r\n\r\nenum EAdjustment\r\n{\r\n  kLeft,\r\n  kCenter,\r\n  kRight\r\n};\r\n\r\nstruct CFieldInfo\r\n{\r\n  PROPID PropID;\r\n  UString Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nstruct CFieldInfoInit\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nCFieldInfoInit kStandardFieldTable[] = \r\n{\r\n  { kpidLastWriteTime, L\"   Date      Time\", kLeft, kLeft, 0, 19 },\r\n  { kpidAttributes, L\"Attr\", kRight, kCenter, 1, 5 },\r\n  { kpidSize, L\"Size\", kRight, kRight, 1, 12 },\r\n  { kpidPackedSize, L\"Compressed\", kRight, kRight, 1, 12 },\r\n  { kpidPath, L\"Name\", kLeft, kLeft, 2, 24 }\r\n};\r\n\r\nvoid PrintSpaces(int numSpaces)\r\n{\r\n  for (int i = 0; i < numSpaces; i++)\r\n    g_StdOut << ' ';\r\n}\r\n\r\nvoid PrintString(EAdjustment adjustment, int width, const UString &textString)\r\n{\r\n  const int numSpaces = width - textString.Length();\r\n  int numLeftSpaces = 0;\r\n  switch (adjustment)\r\n  {\r\n    case kLeft:\r\n      numLeftSpaces = 0;\r\n      break;\r\n    case kCenter:\r\n      numLeftSpaces = numSpaces / 2;\r\n      break;\r\n    case kRight:\r\n      numLeftSpaces = numSpaces;\r\n      break;\r\n  }\r\n  PrintSpaces(numLeftSpaces);\r\n  g_StdOut << textString;\r\n  PrintSpaces(numSpaces - numLeftSpaces);\r\n}\r\n\r\nclass CFieldPrinter\r\n{\r\n  CObjectVector<CFieldInfo> _fields;\r\npublic:\r\n  void Clear() { _fields.Clear(); }\r\n  void Init(const CFieldInfoInit *standardFieldTable, int numItems);\r\n  HRESULT Init(IInArchive *archive);\r\n  void PrintTitle();\r\n  void PrintTitleLines();\r\n  HRESULT PrintItemInfo(IInArchive *archive, \r\n      const UString &defaultItemName,\r\n      const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n      UInt32 index,\r\n      bool techMode);\r\n  HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs, \r\n      const UInt64 *size, const UInt64 *compressedSize);\r\n};\r\n\r\nvoid CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)\r\n{\r\n  Clear();\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    CFieldInfo fieldInfo;\r\n    const CFieldInfoInit &fieldInfoInit = standardFieldTable[i];\r\n    fieldInfo.PropID = fieldInfoInit.PropID;\r\n    fieldInfo.Name = fieldInfoInit.Name;\r\n    fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment;\r\n    fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment;\r\n    fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth;\r\n    fieldInfo.Width = fieldInfoInit.Width;\r\n    _fields.Add(fieldInfo);\r\n  }\r\n}\r\n\r\nstatic UString GetPropName(PROPID propID, BSTR name)\r\n{\r\n  for (int i = 0; i < sizeof(kPropIdToName) / sizeof(kPropIdToName[0]); i++)\r\n  {\r\n    const CPropIdToName &propIdToName = kPropIdToName[i];\r\n    if (propIdToName.PropID == propID)\r\n      return propIdToName.Name;\r\n  }\r\n  if (name)\r\n    return name;\r\n  return L\"?\";\r\n}\r\n\r\nHRESULT CFieldPrinter::Init(IInArchive *archive)\r\n{\r\n  Clear();\r\n  UInt32 numProps;\r\n  RINOK(archive->GetNumberOfProperties(&numProps));\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    CMyComBSTR name;\r\n    PROPID propID;\r\n    VARTYPE vt;\r\n    RINOK(archive->GetPropertyInfo(i, &name, &propID, &vt));\r\n    CFieldInfo fieldInfo;\r\n    fieldInfo.PropID = propID;\r\n    fieldInfo.Name = GetPropName(propID, name);\r\n    _fields.Add(fieldInfo);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitle()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    PrintString(fieldInfo.TitleAdjustment, \r\n      ((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);\r\n  }\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitleLines()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    for (int i = 0; i < fieldInfo.Width; i++)\r\n      g_StdOut << '-';\r\n  }\r\n}\r\n\r\n\r\nBOOL IsFileTimeZero(CONST FILETIME *lpFileTime)\r\n{\r\n  return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);\r\n}\r\n\r\nstatic const char *kEmptyTimeString = \"                   \";\r\nvoid PrintTime(const NCOM::CPropVariant &propVariant)\r\n{\r\n  if (propVariant.vt != VT_FILETIME)\r\n    throw \"incorrect item\";\r\n  if (IsFileTimeZero(&propVariant.filetime))\r\n    g_StdOut << kEmptyTimeString;\r\n  else\r\n  {\r\n    FILETIME localFileTime;\r\n    if (!FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n      throw \"FileTimeToLocalFileTime error\";\r\n    char s[32];\r\n    if (ConvertFileTimeToString(localFileTime, s, true, true))\r\n      g_StdOut << s;\r\n    else\r\n      g_StdOut << kEmptyTimeString;\r\n  }\r\n}\r\n\r\nHRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive, \r\n    const UString &defaultItemName, \r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    UInt32 index,\r\n    bool techMode)\r\n{\r\n  /*\r\n  if (techMode)\r\n  {\r\n    g_StdOut << \"Index = \";\r\n    g_StdOut << (UInt64)index;\r\n    g_StdOut << endl;\r\n  }\r\n  */\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    if (!techMode)\r\n      PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(archive->GetProperty(index, fieldInfo.PropID, &propVariant));\r\n    if (techMode)\r\n    {\r\n      g_StdOut << fieldInfo.Name << \" = \";\r\n    }\r\n    int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;\r\n    if (propVariant.vt == VT_EMPTY)\r\n    {\r\n      switch(fieldInfo.PropID)\r\n      {\r\n        case kpidPath:\r\n          propVariant = defaultItemName;\r\n          break;\r\n        case kpidLastWriteTime:\r\n          propVariant = archiveFileInfo.LastWriteTime;\r\n          break;\r\n        default:\r\n          if (techMode)\r\n            g_StdOut << endl;\r\n          else\r\n            PrintSpaces(width);\r\n          continue;\r\n      }\r\n    }\r\n    if (fieldInfo.PropID == kpidLastWriteTime)\r\n    {\r\n      PrintTime(propVariant);\r\n    }\r\n    else if (fieldInfo.PropID == kpidAttributes)\r\n    {\r\n      if (propVariant.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      UInt32 attributes = propVariant.ulVal;\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, index, isFolder));\r\n      char s[8];\r\n      GetAttributesString(attributes, isFolder, s);\r\n      g_StdOut << s;\r\n    }\r\n    else if (propVariant.vt == VT_BSTR)\r\n    {\r\n      if (techMode)\r\n        g_StdOut << propVariant.bstrVal;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, propVariant.bstrVal);\r\n    }\r\n    else\r\n    {\r\n      UString s = ConvertPropertyToString(propVariant, fieldInfo.PropID);\r\n      s.Replace(wchar_t(0xA), L' '); \r\n      s.Replace(wchar_t(0xD), L' '); \r\n\r\n      if (techMode)\r\n        g_StdOut << s;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, s);\r\n    }\r\n    if (techMode)\r\n      g_StdOut << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)\r\n{\r\n  wchar_t textString[32] = { 0 };\r\n  if (value != NULL)\r\n    ConvertUInt64ToString(*value, textString);\r\n  PrintString(adjustment, width, textString);\r\n}\r\n\r\n\r\nHRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs, \r\n    const UInt64 *size, const UInt64 *compressedSize)\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    NCOM::CPropVariant propVariant;\r\n    if (fieldInfo.PropID == kpidSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);\r\n    else if (fieldInfo.PropID == kpidPackedSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);\r\n    else if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      wchar_t textString[32];\r\n      ConvertUInt64ToString(numFiles, textString);\r\n      UString temp = textString;\r\n      temp += L\" \";\r\n      temp += kFilesMessage;\r\n      temp += L\", \";\r\n      ConvertUInt64ToString(numDirs, textString);\r\n      temp += textString;\r\n      temp += L\" \";\r\n      temp += kDirsMessage;\r\n      PrintString(fieldInfo.TextAdjustment, 0, temp);\r\n    }\r\n    else \r\n      PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L\"\");\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nbool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)\r\n{\r\n  NCOM::CPropVariant propVariant;\r\n  if (archive->GetProperty(index, propID, &propVariant) != S_OK)\r\n    throw \"GetPropertyValue error\";\r\n  if (propVariant.vt == VT_EMPTY)\r\n    return false;\r\n  value = ConvertPropVariantToUInt64(propVariant);\r\n  return true;\r\n}\r\n\r\nHRESULT ListArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &numErrors)\r\n{\r\n  numErrors = 0;\r\n  CFieldPrinter fieldPrinter;\r\n  if (!techMode)\r\n    fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));\r\n\r\n  UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;\r\n  UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;\r\n  for (int i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archiveName = archivePaths[i];\r\n    NFile::NFind::CFileInfoW archiveFileInfo;\r\n    if (!NFile::NFind::FindFile(archiveName, archiveFileInfo) || archiveFileInfo.IsDirectory())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not archive\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n    if (archiveFileInfo.IsDirectory())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not file\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    CArchiveLink archiveLink;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &g_StdOut;\r\n    openCallback.PasswordIsDefined = passwordEnabled;\r\n    openCallback.Password = password;\r\n\r\n    HRESULT result = MyOpenArchive(codecs, archiveName, archiveLink, &openCallback);\r\n    if (result != S_OK)\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not supported archive\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n      }\r\n    }\r\n\r\n    IInArchive *archive = archiveLink.GetArchive();\r\n    const UString defaultItemName = archiveLink.GetDefaultItemName();\r\n\r\n    if (enableHeaders)\r\n    {\r\n      g_StdOut << endl << kListing << archiveName << endl << endl;\r\n\r\n      UInt32 numProps;\r\n      if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)\r\n      {\r\n        for (UInt32 i = 0; i < numProps; i++)\r\n        {\r\n          CMyComBSTR name;\r\n          PROPID propID;\r\n          VARTYPE vt;\r\n          if (archive->GetArchivePropertyInfo(i, &name, &propID, &vt) != S_OK)\r\n            continue;\r\n          NCOM::CPropVariant prop;\r\n          if (archive->GetArchiveProperty(propID, &prop) != S_OK)\r\n            continue;\r\n          UString s = ConvertPropertyToString(prop, propID);\r\n          if (!s.IsEmpty())\r\n            g_StdOut << GetPropName(propID, name) << \" = \" << s << endl;\r\n        }\r\n      }\r\n      if (techMode)\r\n        g_StdOut << \"----------\\n\";\r\n      if (numProps > 0)\r\n        g_StdOut << endl;\r\n    }\r\n\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitle();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n    }\r\n\r\n    if (techMode)\r\n    {\r\n      RINOK(fieldPrinter.Init(archive));\r\n    }\r\n    UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0;\r\n    UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;\r\n    UInt32 numItems;\r\n    RINOK(archive->GetNumberOfItems(&numItems));\r\n    for(UInt32 i = 0; i < numItems; i++)\r\n    {\r\n      if (NConsoleClose::TestBreakSignal())\r\n        return E_ABORT;\r\n\r\n      UString filePath;\r\n      RINOK(GetArchiveItemPath(archive, i, defaultItemName, filePath));\r\n\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n      if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n        continue;\r\n      \r\n      fieldPrinter.PrintItemInfo(archive, defaultItemName, archiveFileInfo, i, techMode);\r\n      \r\n      UInt64 packSize, unpackSize;\r\n      if (!GetUInt64Value(archive, i, kpidSize, unpackSize))\r\n        unpackSize = 0;\r\n      else\r\n        totalUnPackSizePointer = &totalUnPackSize;\r\n      if (!GetUInt64Value(archive, i, kpidPackedSize, packSize))\r\n        packSize = 0;\r\n      else\r\n        totalPackSizePointer = &totalPackSize;\r\n      \r\n      g_StdOut << endl;\r\n\r\n      if (isFolder)\r\n        numDirs++;\r\n      else\r\n        numFiles++;\r\n      totalPackSize += packSize;\r\n      totalUnPackSize += unpackSize;\r\n    }\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintSummaryInfo(numFiles, numDirs, totalUnPackSizePointer, totalPackSizePointer);\r\n      g_StdOut << endl;\r\n    }\r\n    if (totalPackSizePointer != 0)\r\n    {\r\n      totalPackSizePointer2 = &totalPackSize2;\r\n      totalPackSize2 += totalPackSize;\r\n    }\r\n    if (totalUnPackSizePointer != 0)\r\n    {\r\n      totalUnPackSizePointer2 = &totalUnPackSize2;\r\n      totalUnPackSize2 += totalUnPackSize;\r\n    }\r\n    numFiles2 += numFiles;\r\n    numDirs2 += numDirs;\r\n  }\r\n  if (enableHeaders && !techMode && archivePaths.Size() > 1)\r\n  {\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintTitleLines();\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintSummaryInfo(numFiles2, numDirs2, totalUnPackSizePointer2, totalPackSizePointer2);\r\n    g_StdOut << endl;\r\n    g_StdOut << \"Archives: \" << archivePaths.Size() << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/List.h",
    "content": "// List.h\r\n\r\n#ifndef __LIST_H\r\n#define __LIST_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nHRESULT ListArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &errors);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/Main.cpp",
    "content": "// Main.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n\r\n#include \"Common/CommandLineParser.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/Error.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/MemoryLock.h\"\r\n#endif\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/UpdateAction.h\"\r\n#include \"../Common/Update.h\"\r\n#include \"../Common/Extract.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"../Common/ExitCode.h\"\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../Common/LoadCodecs.h\"\r\n#endif\r\n\r\n#include \"../../Compress/LZMA_Alone/LzmaBenchCon.h\"\r\n\r\n#include \"List.h\"\r\n#include \"OpenCallbackConsole.h\"\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\n#if defined( _WIN32) && defined( _7ZIP_LARGE_PAGES)\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NCommandLineParser;\r\n\r\nHINSTANCE g_hInstance = 0;\r\nextern CStdOutStream *g_StdStream;\r\n\r\nstatic const char *kCopyrightString = \"\\n7-Zip\"\r\n#ifndef EXTERNAL_CODECS\r\n\" (A)\"\r\n#endif\r\n\r\n#ifdef _WIN64\r\n\" [64]\"\r\n#endif\r\n\r\n\" \" MY_VERSION_COPYRIGHT_DATE \"\\n\";\r\n\r\nstatic const char *kHelpString = \r\n    \"\\nUsage: 7z\"\r\n#ifdef _NO_CRYPTO\r\n    \"r\"\r\n#else\r\n#ifndef EXTERNAL_CODECS\r\n    \"a\"\r\n#endif\r\n#endif\r\n    \" <command> [<switches>...] <archive_name> [<file_names>...]\\n\"\r\n    \"       [<@listfiles...>]\\n\"\r\n    \"\\n\"\r\n    \"<Commands>\\n\"\r\n    \"  a: Add files to archive\\n\"\r\n    \"  b: Benchmark\\n\"\r\n    \"  d: Delete files from archive\\n\"\r\n    \"  e: Extract files from archive (without using directory names)\\n\"\r\n    \"  l: List contents of archive\\n\"\r\n//    \"  l[a|t][f]: List contents of archive\\n\"\r\n//    \"    a - with Additional fields\\n\"\r\n//    \"    t - with all fields\\n\"\r\n//    \"    f - with Full pathnames\\n\"\r\n    \"  t: Test integrity of archive\\n\"\r\n    \"  u: Update files to archive\\n\"\r\n    \"  x: eXtract files with full paths\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -ai[r[-|0]]{@listfile|!wildcard}: Include archives\\n\"\r\n    \"  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives\\n\"\r\n    \"  -bd: Disable percentage indicator\\n\"\r\n    \"  -i[r[-|0]]{@listfile|!wildcard}: Include filenames\\n\"\r\n    \"  -m{Parameters}: set compression Method\\n\"\r\n    \"  -o{Directory}: set Output directory\\n\"\r\n    \"  -p{Password}: set Password\\n\"\r\n    \"  -r[-|0]: Recurse subdirectories\\n\"\r\n    \"  -scs{UTF-8 | WIN | DOS}: set charset for list files\\n\"\r\n    \"  -sfx[{name}]: Create SFX archive\\n\"\r\n    \"  -si[{name}]: read data from stdin\\n\"\r\n    \"  -slt: show technical information for l (List) command\\n\"\r\n    \"  -so: write data to stdout\\n\"\r\n    \"  -ssc[-]: set sensitive case mode\\n\"\r\n    \"  -ssw: compress shared files\\n\"\r\n    \"  -t{Type}: Set type of archive\\n\"\r\n    \"  -v{Size}[b|k|m|g]: Create volumes\\n\"\r\n    \"  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\\n\"\r\n    \"  -w[{path}]: assign Work directory. Empty path means a temporary directory\\n\"\r\n    \"  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\\n\"\r\n    \"  -y: assume Yes on all queries\\n\";\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\"; // NExitCode::kUserError\r\n\r\nstatic const wchar_t *kDefaultSfxModule = L\"7zCon.sfx\";\r\n\r\nstatic void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code)\r\n{\r\n  s << message << endl;\r\n  throw code;\r\n}\r\n\r\nstatic void PrintHelpAndExit(CStdOutStream &s) // yyy\r\n{\r\n  s << kHelpString;\r\n  ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError);\r\n}\r\n\r\n#ifndef _WIN32\r\nstatic void GetArguments(int numArguments, const char *arguments[], UStringVector &parts)\r\n{\r\n  parts.Clear();\r\n  for(int i = 0; i < numArguments; i++)\r\n  {\r\n    UString s = MultiByteToUnicodeString(arguments[i]);\r\n    parts.Add(s);\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp)\r\n{\r\n  s << kCopyrightString;\r\n  // s << \"# CPUs: \" << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << \"\\n\";\r\n  if (needHelp) \r\n    s << kHelpString;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic void PrintString(CStdOutStream &stdStream, const AString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n#endif\r\n\r\nstatic void PrintString(CStdOutStream &stdStream, const UString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n\r\nstatic inline char GetHex(Byte value)\r\n{\r\n  return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nint Main2(\r\n  #ifndef _WIN32  \r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n)\r\n{\r\n  #ifdef _WIN32  \r\n  SetFileApisToOEM();\r\n  #endif\r\n  \r\n  UStringVector commandStrings;\r\n  #ifdef _WIN32  \r\n  NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);\r\n  #else\r\n  GetArguments(numArguments, arguments, commandStrings);\r\n  #endif\r\n\r\n  if(commandStrings.Size() == 1)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n  commandStrings.Delete(0);\r\n\r\n  CArchiveCommandLineOptions options;\r\n\r\n  CArchiveCommandLineParser parser;\r\n\r\n  parser.Parse1(commandStrings, options);\r\n\r\n  if(options.HelpMode)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  if (options.LargePages)\r\n  {\r\n    SetLargePageSize();\r\n    NSecurity::EnableLockMemoryPrivilege();\r\n  }\r\n  #endif\r\n\r\n  CStdOutStream &stdStream = options.StdOutMode ? g_StdErr : g_StdOut;\r\n  g_StdStream = &stdStream;\r\n\r\n  if (options.EnableHeaders)\r\n    ShowCopyrightAndHelp(stdStream, false);\r\n\r\n  parser.Parse2(options);\r\n\r\n  CCodecs *codecs = new CCodecs;\r\n  CMyComPtr<\r\n    #ifdef EXTERNAL_CODECS\r\n    ICompressCodecsInfo\r\n    #else\r\n    IUnknown\r\n    #endif\r\n    > compressCodecsInfo = codecs;\r\n  HRESULT result = codecs->Load();\r\n  if (result != S_OK)\r\n    throw CSystemException(result);\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n  if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n    stdStream << endl << \"Formats:\" << endl;\r\n    int i;\r\n    for (i = 0; i < codecs->Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = codecs->Formats[i];\r\n      #ifdef EXTERNAL_CODECS\r\n      if (arc.LibIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(arc.LibIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n      #endif\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(arc.UpdateEnabled ? 'C' : ' ');\r\n      stdStream << (char)(arc.KeepName ? 'K' : ' ');\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, arc.Name, 6);\r\n      stdStream << \"  \";\r\n      UString s;\r\n      for (int t = 0; t < arc.Exts.Size(); t++)\r\n      {\r\n        const CArcExtInfo &ext = arc.Exts[t];\r\n        s += ext.Ext;\r\n        if (!ext.AddExt.IsEmpty())\r\n        {\r\n          s += L\" (\";\r\n          s += ext.AddExt;\r\n          s += L')';\r\n        }\r\n        s += L' ';\r\n      }\r\n      PrintString(stdStream, s, 14);\r\n      stdStream << \"  \";\r\n      const CByteBuffer &sig = arc.StartSignature;\r\n      for (size_t j = 0; j < sig.GetCapacity(); j++)\r\n      {\r\n        Byte b = sig[j];\r\n        if (b > 0x20 && b < 0x80)\r\n        {\r\n          stdStream << (char)b;\r\n        }\r\n        else\r\n        {\r\n          stdStream << GetHex((Byte)((b >> 4) & 0xF));\r\n          stdStream << GetHex((Byte)(b & 0xF));\r\n        }\r\n        stdStream << ' ';\r\n      }\r\n      stdStream << endl;\r\n    }\r\n    stdStream << endl << \"Codecs:\" << endl;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    UINT32 numMethods;\r\n    if (codecs->GetNumberOfMethods(&numMethods) == S_OK)\r\n    for (UInt32 j = 0; j < numMethods; j++)\r\n    {\r\n      int libIndex = codecs->GetCodecLibIndex(j);\r\n      if (libIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(libIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(codecs->GetCodecEncoderIsAssigned(j) ? 'C' : ' ');\r\n      UInt64 id;\r\n      stdStream << \"  \";\r\n      HRESULT res = codecs->GetCodecId(j, id);\r\n      if (res != S_OK)\r\n        id = (UInt64)(Int64)-1;\r\n      char s[32];\r\n      ConvertUInt64ToString(id, s, 16);\r\n      PrintString(stdStream, s, 8);\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, codecs->GetCodecName(j), 11);\r\n      stdStream << endl;\r\n      /*\r\n      if (res != S_OK)\r\n        throw \"incorrect Codec ID\";\r\n      */\r\n    }\r\n    #endif\r\n    return S_OK;\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    if (options.Method.CompareNoCase(L\"CRC\") == 0)\r\n    {\r\n      HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nCRC Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      HRESULT res = LzmaBenchCon(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        (FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nDecoding Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n  }\r\n  else if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if(isExtractGroupCommand)\r\n    {\r\n      CExtractCallbackConsole *ecs = new CExtractCallbackConsole;\r\n      CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;\r\n\r\n      ecs->OutStream = &stdStream;\r\n      ecs->PasswordIsDefined = options.PasswordEnabled;\r\n      ecs->Password = options.Password;\r\n      ecs->Init();\r\n\r\n      COpenCallbackConsole openCallback;\r\n      openCallback.OutStream = &stdStream;\r\n      openCallback.PasswordIsDefined = options.PasswordEnabled;\r\n      openCallback.Password = options.Password;\r\n\r\n      CExtractOptions eo;\r\n      eo.StdOutMode = options.StdOutMode;\r\n      eo.PathMode = options.Command.GetPathMode();\r\n      eo.TestMode = options.Command.IsTestMode();\r\n      eo.OverwriteMode = options.OverwriteMode;\r\n      eo.OutputDir = options.OutputDir;\r\n      eo.YesToAll = options.YesToAll;\r\n      #ifdef COMPRESS_MT\r\n      eo.Properties = options.ExtractProperties;\r\n      #endif\r\n      UString errorMessage;\r\n      CDecompressStat stat;\r\n      HRESULT result = DecompressArchives(\r\n          codecs,\r\n          options.ArchivePathsSorted, \r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head, \r\n          eo, &openCallback, ecs, errorMessage, stat);\r\n      if (!errorMessage.IsEmpty())\r\n      {\r\n        stdStream << endl << \"Error: \" << errorMessage;\r\n        if (result == S_OK)\r\n          result = E_FAIL;\r\n      }\r\n\r\n      stdStream << endl;\r\n      if (ecs->NumArchives > 1)\r\n        stdStream << \"Archives: \" << ecs->NumArchives << endl;\r\n      if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0)\r\n      {\r\n        if (ecs->NumArchives > 1)\r\n        {\r\n          stdStream << endl;\r\n          if (ecs->NumArchiveErrors != 0)\r\n            stdStream << \"Archive Errors: \" << ecs->NumArchiveErrors << endl;\r\n          if (ecs->NumFileErrors != 0)\r\n            stdStream << \"Sub items Errors: \" << ecs->NumFileErrors << endl;\r\n        }\r\n        if (result != S_OK)\r\n          throw CSystemException(result);\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n      if (stat.NumFolders != 0)\r\n        stdStream << \"Folders: \" << stat.NumFolders << endl;\r\n      if (stat.NumFiles != 1 || stat.NumFolders != 0)\r\n          stdStream << \"Files: \" << stat.NumFiles << endl;\r\n      stdStream \r\n           << \"Size:       \" << stat.UnpackSize << endl\r\n           << \"Compressed: \" << stat.PackSize << endl;\r\n    }\r\n    else\r\n    {\r\n      UInt64 numErrors = 0;\r\n      HRESULT result = ListArchives(\r\n          codecs,\r\n          options.ArchivePathsSorted, \r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head, \r\n          options.EnableHeaders, \r\n          options.TechMode,\r\n          options.PasswordEnabled, \r\n          options.Password, numErrors);\r\n      if (numErrors > 0)\r\n      {\r\n        g_StdOut << endl << \"Errors: \" << numErrors;\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    UString workingDir;\r\n\r\n    CUpdateOptions &uo = options.UpdateOptions;\r\n    if (uo.SfxMode && uo.SfxModule.IsEmpty())\r\n      uo.SfxModule = kDefaultSfxModule;\r\n\r\n    bool passwordIsDefined = \r\n        options.PasswordEnabled && !options.Password.IsEmpty();\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &stdStream;\r\n    openCallback.PasswordIsDefined = passwordIsDefined;\r\n    openCallback.Password = options.Password;\r\n\r\n    CUpdateCallbackConsole callback;\r\n    callback.EnablePercents = options.EnablePercents;\r\n    callback.PasswordIsDefined = passwordIsDefined;\r\n    callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty();\r\n    callback.Password = options.Password;\r\n    callback.StdOutMode = uo.StdOutMode;\r\n    callback.Init(&stdStream);\r\n\r\n    CUpdateErrorInfo errorInfo;\r\n\r\n    if (!uo.Init(codecs, options.ArchiveName, options.ArcType))\r\n      throw \"Unsupported archive type\";\r\n    HRESULT result = UpdateArchive(codecs, \r\n        options.WildcardCensor, uo, \r\n        errorInfo, &openCallback, &callback);\r\n\r\n    int exitCode = NExitCode::kSuccess;\r\n    if (callback.CantFindFiles.Size() > 0)\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      int numErrors = callback.CantFindFiles.Size();\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.CantFindFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.CantFindCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot find \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n\r\n    if (result != S_OK)\r\n    {\r\n      UString message;\r\n      if (!errorInfo.Message.IsEmpty())\r\n      {\r\n        message += errorInfo.Message;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName2.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName2;\r\n        message += L\"\\n\";\r\n      }\r\n      if (errorInfo.SystemError != 0)\r\n      {\r\n        message += NError::MyFormatMessageW(errorInfo.SystemError);\r\n        message += L\"\\n\";\r\n      }\r\n      if (!message.IsEmpty())\r\n        stdStream << L\"\\nError:\\n\" << message;\r\n      throw CSystemException(result);\r\n    }\r\n    int numErrors = callback.FailedFiles.Size();\r\n    if (numErrors == 0)\r\n    {\r\n      if (callback.CantFindFiles.Size() == 0)\r\n        stdStream << kEverythingIsOk << endl;\r\n    }\r\n    else\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.FailedFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.FailedCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot open \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n    return exitCode;\r\n  }\r\n  else \r\n    PrintHelpAndExit(stdStream);\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/MainAr.cpp",
    "content": "// MainAr.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <locale.h>\r\n\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"../Common/ExitCode.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCStdOutStream *g_StdStream = 0;\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\n#endif\r\n#if !defined(_UNICODE) || !defined(_WIN64)\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern int Main2(\r\n  #ifndef _WIN32  \r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n);\r\n\r\nstatic const char *kExceptionErrorMessage = \"\\n\\nError:\\n\";\r\nstatic const char *kUserBreak  = \"\\nBreak signaled\\n\";\r\n\r\nstatic const char *kMemoryExceptionMessage = \"\\n\\nERROR: Can't allocate required memory!\\n\";\r\nstatic const char *kUnknownExceptionMessage = \"\\n\\nUnknown Error\\n\";\r\nstatic const char *kInternalExceptionMessage = \"\\n\\nInternal Error #\";\r\n\r\nint \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\nmain\r\n(\r\n#ifndef _WIN32  \r\nint numArguments, const char *arguments[]\r\n#endif\r\n)\r\n{\r\n  g_StdStream = &g_StdOut;\r\n  #ifdef _WIN32\r\n  \r\n  #ifdef _UNICODE\r\n  #ifndef _WIN64\r\n  if (!IsItWindowsNT())\r\n  {\r\n    (*g_StdStream) << \"This program requires Windows NT/2000/XP/2003/Vista\";\r\n    return NExitCode::kFatalError;\r\n  }\r\n  #endif\r\n  #else\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  \r\n  #endif\r\n\r\n  // setlocale(LC_COLLATE, \".OCP\");\r\n  NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;\r\n  int res = 0;\r\n  try\r\n  {\r\n    res = Main2(\r\n#ifndef _WIN32\r\n      numArguments, arguments\r\n#endif\r\n    );\r\n  }\r\n  catch(const CNewException &)\r\n  {\r\n    (*g_StdStream) << kMemoryExceptionMessage;\r\n    return (NExitCode::kMemoryError);\r\n  }\r\n  catch(const NConsoleClose::CCtrlBreakException &)\r\n  {\r\n    (*g_StdStream) << endl << kUserBreak;\r\n    return (NExitCode::kUserBreak);\r\n  }\r\n  catch(const CArchiveCommandLineException &e)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << e << endl;\r\n    return (NExitCode::kUserError);\r\n  }\r\n  catch(const CSystemException &systemError)\r\n  {\r\n    if (systemError.ErrorCode == E_OUTOFMEMORY)\r\n    {\r\n      (*g_StdStream) << kMemoryExceptionMessage;\r\n      return (NExitCode::kMemoryError);\r\n    }\r\n    if (systemError.ErrorCode == E_ABORT)\r\n    {\r\n      (*g_StdStream) << endl << kUserBreak;\r\n      return (NExitCode::kUserBreak);\r\n    }\r\n    UString message;\r\n    NError::MyFormatMessage(systemError.ErrorCode, message);\r\n    (*g_StdStream) << endl << endl << \"System error:\" << endl << \r\n        message << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(NExitCode::EEnum &exitCode)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << exitCode << endl;\r\n    return (exitCode);\r\n  }\r\n  /*\r\n  catch(const NExitCode::CMultipleErrors &multipleErrors)\r\n  {\r\n    (*g_StdStream) << endl << multipleErrors.NumErrors << \" errors\" << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  */\r\n  catch(const UString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const AString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const char *s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(int t)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << t << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(...)\r\n  {\r\n    (*g_StdStream) << kUnknownExceptionMessage;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  return  res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/OpenCallbackConsole.cpp",
    "content": "// OpenCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nHRESULT COpenCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::SetTotal(const UInt64 *, const UInt64 *)\r\n{\r\n  return CheckBreak();\r\n}\r\n\r\nHRESULT COpenCallbackConsole::SetCompleted(const UInt64 *, const UInt64 *)\r\n{\r\n  return CheckBreak();\r\n}\r\n \r\nHRESULT COpenCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  PasswordWasAsked = true;\r\n  RINOK(CheckBreak());\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream); \r\n    PasswordIsDefined = true;\r\n  }\r\n  CMyComBSTR temp(Password);\r\n  *password = temp.Detach();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::GetPasswordIfAny(UString &password)\r\n{\r\n  if (PasswordIsDefined)\r\n    password = Password;\r\n  return S_OK;\r\n}\r\n\r\nbool COpenCallbackConsole::WasPasswordAsked()\r\n{\r\n  return PasswordWasAsked;\r\n}\r\n\r\nvoid COpenCallbackConsole::ClearPasswordWasAskedFlag()\r\n{\r\n  PasswordWasAsked = false;\r\n}\r\n\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/OpenCallbackConsole.h",
    "content": "// OpenCallbackConsole.h\r\n\r\n#ifndef __OPENCALLBACKCONSOLE_H\r\n#define __OPENCALLBACKCONSOLE_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../Common/ArchiveOpenCallback.h\"\r\n\r\nclass COpenCallbackConsole: public IOpenCallbackUI\r\n{\r\npublic:\r\n  HRESULT CheckBreak();\r\n  HRESULT SetTotal(const UInt64 *files, const UInt64 *bytes);\r\n  HRESULT SetCompleted(const UInt64 *files, const UInt64 *bytes);\r\n  HRESULT CryptoGetTextPassword(BSTR *password);\r\n  HRESULT GetPasswordIfAny(UString &password);\r\n  bool WasPasswordAsked();\r\n  void ClearPasswordWasAskedFlag();\r\n  \r\n  CStdOutStream *OutStream;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool PasswordWasAsked;\r\n  COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/PercentPrinter.cpp",
    "content": "// PercentPrinter.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"PercentPrinter.h\"\r\n\r\nconst int kPaddingSize = 2;\r\nconst int kPercentsSize = 4;\r\nconst int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;\r\n\r\nstatic void ClearPrev(char *p, int num)\r\n{\r\n  int i;\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  for (i = 0; i < num; i++) *p++ = ' ';\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  *p = '\\0';\r\n}\r\n\r\nvoid CPercentPrinter::ClosePrint()\r\n{\r\n  if (m_NumExtraChars == 0)\r\n    return;\r\n  char s[kMaxExtraSize * 3 + 1];\r\n  ClearPrev(s, m_NumExtraChars);\r\n  (*OutStream) << s;\r\n  m_NumExtraChars = 0;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const char *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const wchar_t *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintNewLine()\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << \"\\n\";\r\n}\r\n\r\nvoid CPercentPrinter::RePrintRatio()\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s);\r\n  int size = (int)strlen(s);\r\n  s[size++] = '%';\r\n  s[size] = '\\0';\r\n\r\n  int extraSize = kPaddingSize + MyMax(size, kPercentsSize);\r\n  if (extraSize < m_NumExtraChars)\r\n    extraSize = m_NumExtraChars;\r\n\r\n  char fullString[kMaxExtraSize * 3];\r\n  char *p = fullString;\r\n  int i;\r\n  if (m_NumExtraChars == 0)\r\n  {\r\n    for (i = 0; i < extraSize; i++) \r\n      *p++ = ' ';\r\n    m_NumExtraChars = extraSize;\r\n  }\r\n\r\n  for (i = 0; i < m_NumExtraChars; i++) \r\n    *p++ = '\\b';\r\n  m_NumExtraChars = extraSize;\r\n  for (; size < m_NumExtraChars; size++)\r\n    *p++ = ' ';\r\n  MyStringCopy(p, s);\r\n  (*OutStream) << fullString;\r\n  OutStream->Flush(); \r\n  m_PrevValue = m_CurValue;\r\n}\r\n\r\nvoid CPercentPrinter::PrintRatio()\r\n{\r\n  if (m_CurValue < m_PrevValue + m_MinStepSize && \r\n      m_CurValue + m_MinStepSize > m_PrevValue && m_NumExtraChars != 0)\r\n    return;\r\n  RePrintRatio();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/PercentPrinter.h",
    "content": "// PercentPrinter.h\r\n\r\n#ifndef __PERCENTPRINTER_H\r\n#define __PERCENTPRINTER_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/StdOutStream.h\"\r\n\r\nclass CPercentPrinter\r\n{\r\n  UInt64 m_MinStepSize;\r\n  UInt64 m_PrevValue;\r\n  UInt64 m_CurValue;\r\n  UInt64 m_Total;\r\n  int m_NumExtraChars;\r\npublic:\r\n  CStdOutStream *OutStream;\r\n\r\n  CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize), \r\n      m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}\r\n  void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }\r\n  void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }\r\n  void PrintString(const char *s);\r\n  void PrintString(const wchar_t *s);\r\n  void PrintNewLine();\r\n  void ClosePrint();\r\n  void RePrintRatio();\r\n  void PrintRatio();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp",
    "content": "// UpdateCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifdef COMPRESS_MT\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nusing namespace NWindows;\r\n\r\n#ifdef COMPRESS_MT\r\nstatic NSynchronization::CCriticalSection g_CriticalSection;\r\n#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);\r\n#else\r\n#define MT_LOCK\r\n#endif\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nstatic const char *kCreatingArchiveMessage = \"Creating archive \";\r\nstatic const char *kUpdatingArchiveMessage = \"Updating archive \";\r\nstatic const char *kScanningMessage = \"Scanning\";\r\n\r\n\r\nHRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n    (*OutStream) << \"Error: \" << name << \" is not supported archive\" << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartScanning()\r\n{\r\n  (*OutStream) << kScanningMessage;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)\r\n{\r\n  CantFindFiles.Add(name);\r\n  CantFindCodes.Add(systemError);\r\n  // m_PercentPrinter.ClosePrint();\r\n  if (!m_WarningsMode)\r\n  {\r\n    (*OutStream) << endl << endl;\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_WarningsMode = true;\r\n  }\r\n  m_PercentPrinter.PrintString(name);\r\n  m_PercentPrinter.PrintString(\":  WARNING: \");\r\n  m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n  m_PercentPrinter.PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishScanning()\r\n{\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)\r\n{\r\n  if(updating)\r\n    (*OutStream) << kUpdatingArchiveMessage;\r\n  else\r\n    (*OutStream) << kCreatingArchiveMessage; \r\n  if (name != 0)\r\n    (*OutStream) << name;\r\n  else\r\n    (*OutStream) << \"StdOut\";\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishArchive()\r\n{\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::Finilize()\r\n{\r\n  MT_LOCK\r\n  if (m_NeedBeClosed)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.ClosePrint();\r\n    }\r\n    if (!StdOutMode && m_NeedNewLine)\r\n    {\r\n      m_PercentPrinter.PrintNewLine();\r\n      m_NeedNewLine = false;\r\n    }\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)\r\n{\r\n  MT_LOCK\r\n  if (EnablePercents)\r\n    m_PercentPrinter.SetTotal(size);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  MT_LOCK\r\n  if (completeValue != NULL)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.SetRatio(*completeValue);\r\n      m_PercentPrinter.PrintRatio();\r\n      m_NeedBeClosed = true;\r\n    }\r\n  }\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  /*\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  */\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)\r\n{\r\n  MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  if(isAnti)\r\n    m_PercentPrinter.PrintString(\"Anti item    \");\r\n  else\r\n    m_PercentPrinter.PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)\r\n{\r\n  MT_LOCK\r\n  FailedCodes.Add(systemError);\r\n  FailedFiles.Add(name);\r\n  // if (systemError == ERROR_SHARING_VIOLATION)\r\n  {\r\n    m_PercentPrinter.ClosePrint();\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_PercentPrinter.PrintString(\"WARNING: \");\r\n    m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n    return S_FALSE;\r\n  }\r\n  // return systemError;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )\r\n{\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;  \r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined) \r\n  {\r\n    if (AskPassword)\r\n    {\r\n      Password = GetPassword(OutStream); \r\n      PasswordIsDefined = true;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.h",
    "content": "// UpdateCallbackConsole.h\r\n\r\n#ifndef __UPDATECALLBACKCONSOLE_H\r\n#define __UPDATECALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"PercentPrinter.h\"\r\n#include \"../Common/Update.h\"\r\n\r\nclass CUpdateCallbackConsole: public IUpdateCallbackUI2\r\n{\r\n  CPercentPrinter m_PercentPrinter;\r\n  bool m_NeedBeClosed;\r\n  bool m_NeedNewLine;\r\n\r\n  bool m_WarningsMode;\r\n\r\n  CStdOutStream *OutStream;\r\npublic:\r\n  bool EnablePercents;\r\n  bool StdOutMode;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n\r\n  CUpdateCallbackConsole(): \r\n      m_PercentPrinter(1 << 16),\r\n      PasswordIsDefined(false),\r\n      AskPassword(false),\r\n      StdOutMode(false),\r\n      EnablePercents(true),\r\n      m_WarningsMode(false)\r\n      {}\r\n  \r\n  ~CUpdateCallbackConsole() { Finilize(); }\r\n  void Init(CStdOutStream *outStream)\r\n  {\r\n    m_NeedBeClosed = false;\r\n    m_NeedNewLine = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n    OutStream = outStream;\r\n    m_PercentPrinter.OutStream = outStream;\r\n  }\r\n\r\n  INTERFACE_IUpdateCallbackUI2(;)\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  UStringVector CantFindFiles;\r\n  CRecordVector<HRESULT> CantFindCodes;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/UserInputUtils.cpp",
    "content": "// UserInputUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StdInStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"UserInputUtils.h\"\r\n\r\nstatic const char kYes = 'Y';\r\nstatic const char kNo = 'N';\r\nstatic const char kYesAll = 'A';\r\nstatic const char kNoAll = 'S';\r\nstatic const char kAutoRename = 'U';\r\nstatic const char kQuit = 'Q';\r\n\r\nstatic const char *kFirstQuestionMessage = \"?\\n\";\r\nstatic const char *kHelpQuestionMessage = \r\n  \"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename / (Q)uit? \";\r\n\r\n// return true if pressed Quite;\r\n// in: anAll\r\n// out: anAll, anYes;\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << kFirstQuestionMessage;\r\n  for(;;)\r\n  {\r\n    (*outStream) << kHelpQuestionMessage;\r\n    AString scannedString = g_StdIn.ScanStringUntilNewLine();\r\n    scannedString.Trim();\r\n    if(!scannedString.IsEmpty())\r\n      switch(::MyCharUpper(scannedString[0]))\r\n      {\r\n        case kYes:\r\n          return NUserAnswerMode::kYes;\r\n        case kNo:\r\n          return NUserAnswerMode::kNo;\r\n        case kYesAll:\r\n          return NUserAnswerMode::kYesAll;\r\n        case kNoAll:\r\n          return NUserAnswerMode::kNoAll;\r\n        case kAutoRename:\r\n          return NUserAnswerMode::kAutoRename;\r\n        case kQuit:\r\n          return NUserAnswerMode::kQuit;\r\n      }\r\n  }\r\n}\r\n\r\nUString GetPassword(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << \"\\nEnter password:\";\r\n  outStream->Flush();\r\n  AString oemPassword = g_StdIn.ScanStringUntilNewLine();\r\n  return MultiByteToUnicodeString(oemPassword, CP_OEMCP); \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/UserInputUtils.h",
    "content": "// UserInputUtils.h\r\n\r\n#ifndef __USERINPUTUTILS_H\r\n#define __USERINPUTUTILS_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n\r\nnamespace NUserAnswerMode {\r\n\r\nenum EEnum\r\n{\r\n  kYes,\r\n  kNo,\r\n  kYesAll,\r\n  kNoAll,\r\n  kAutoRename,\r\n  kQuit\r\n};\r\n}\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);\r\nUString GetPassword(CStdOutStream *outStream);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/7zip/UI/Console/afxres.h",
    "content": "#include <winresrc.h>\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Build.mak",
    "content": "!IFDEF CPU\r\nLIBS = $(LIBS) bufferoverflowU.lib \r\nCFLAGS = $(CFLAGS) -GS- -Zc:forScope\r\n!ENDIF\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IF \"$(CPU)\" != \"IA64\"\r\n!IF \"$(CPU)\" != \"AMD64\"\r\nMY_ML = ml\r\n!ELSE\r\nMY_ML = ml64\r\n!ENDIF\r\n!ENDIF\r\n\r\nCOMPL_ASM = $(MY_ML) -c -Fo$O/ $**\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -EHsc -Gz -WX -Gy\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\n!IFDEF NEW_COMPILER\r\nCFLAGS_O1 = $(CFLAGS) -O1 -W4 -Wp64\r\nCFLAGS_O2 = $(CFLAGS) -O2 -W4 -Wp64\r\n!ELSE\r\nCFLAGS_O1 = $(CFLAGS) -O1 -W3\r\nCFLAGS_O2 = $(CFLAGS) -O2 -W3\r\n!ENDIF\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF \r\n\r\n!IFDEF DEF_FILE\r\nLFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)\r\n!ENDIF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL_PCH  = $(CPP) $(CFLAGS_O1) -Yc\"StdAfx.h\" -Fp$O/a.pch $** \r\nCOMPL      = $(CPP) $(CFLAGS_O1) -Yu\"StdAfx.h\" -Fp$O/a.pch $**\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS) $(DEF_FILE)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n$O\\resource.res: $(*B).rc\r\n\trc -fo$@ $**\r\n$O\\StdAfx.obj: $(*B).cpp\r\n\t$(COMPL_PCH)\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/AutoPtr.h",
    "content": "// Common/AutoPtr.h\r\n\r\n#ifndef __COMMON_AUTOPTR_H\r\n#define __COMMON_AUTOPTR_H\r\n\r\ntemplate<class T> class CMyAutoPtr\r\n{\r\n  T *_p;\r\npublic:\r\n  CMyAutoPtr(T *p = 0) : _p(p) {}\r\n  CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {}\r\n  CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p) \r\n  {\r\n    reset(p.release());\r\n    return (*this);\r\n  }\r\n  ~CMyAutoPtr() { delete _p; }\r\n  T& operator*() const { return *_p; }\r\n  // T* operator->() const { return (&**this); }\r\n  T* get() const { return _p; }\r\n  T* release()\r\n  {\r\n    T *tmp = _p;\r\n    _p = 0;\r\n    return tmp;\r\n  }\r\n  void reset(T* p = 0)\r\n  {\r\n    if (p != _p)\r\n      delete _p;\r\n    _p = p;\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/Buffer.h",
    "content": "// Common/Buffer.h\r\n\r\n#ifndef __COMMON_BUFFER_H\r\n#define __COMMON_BUFFER_H\r\n\r\n#include \"Defs.h\"\r\n\r\ntemplate <class T> class CBuffer\r\n{    \r\nprotected:\r\n  size_t _capacity;\r\n  T *_items;\r\npublic:\r\n  void Free()\r\n  {\r\n    delete []_items;\r\n    _items = 0;\r\n    _capacity = 0;\r\n  }\r\n  CBuffer(): _capacity(0), _items(0) {};\r\n  CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }\r\n  CBuffer(size_t size): _items(0),  _capacity(0) {  SetCapacity(size); }\r\n  virtual ~CBuffer() { delete []_items; }\r\n  operator T *() { return _items; };\r\n  operator const T *() const { return _items; };\r\n  size_t GetCapacity() const { return  _capacity; }\r\n  void SetCapacity(size_t newCapacity)\r\n  {\r\n    if (newCapacity == _capacity)\r\n      return;\r\n    T *newBuffer;\r\n    if (newCapacity > 0)\r\n    {\r\n      newBuffer = new T[newCapacity];\r\n      if(_capacity > 0)\r\n        memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));\r\n    }\r\n    else\r\n      newBuffer = 0;\r\n    delete []_items;\r\n    _items = newBuffer;\r\n    _capacity = newCapacity;\r\n  }\r\n  CBuffer& operator=(const CBuffer &buffer)\r\n  {\r\n    Free();\r\n    if(buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nbool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  if (b1.GetCapacity() != b2.GetCapacity())\r\n    return false;\r\n  for (size_t i = 0; i < b1.GetCapacity(); i++)\r\n    if (b1[i] != b2[i])\r\n      return false;\r\n  return true;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  return !(b1 == b2);\r\n}\r\n\r\ntypedef CBuffer<char> CCharBuffer;\r\ntypedef CBuffer<wchar_t> CWCharBuffer;\r\ntypedef CBuffer<unsigned char> CByteBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../C/7zCrc.h\"\r\n}\r\n\r\nclass CCRCTableInit\r\n{\r\npublic:\r\n  CCRCTableInit() { CrcGenerateTable(); }\r\n} g_CRCTableInit;\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nbool CInFile::OpenShared(const char *name, bool)\r\n{\r\n  return Open(name);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nbool COutFile::Open(const char *name, DWORD creationDisposition)\r\n{\r\n  return Create(name, false);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  bool OpenShared(const char *name, bool shareForWrite);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  bool Open(const char *name, DWORD creationDisposition);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else \r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  for (;;)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      break;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{ \r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */); \r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms, \r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0) \r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while(pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len) \r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString: \r\n      case NSwitchType::kUnLimitedPostString: \r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for(int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString)\r\n{\r\n  for(int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if(commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"MyString.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  { \r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms); \r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms, \r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/DynamicBuffer.h",
    "content": "// Common/DynamicBuffer.h\r\n\r\n#ifndef __COMMON_DYNAMICBUFFER_H\r\n#define __COMMON_DYNAMICBUFFER_H\r\n\r\n#include \"Buffer.h\"\r\n\r\ntemplate <class T> class CDynamicBuffer: public CBuffer<T>\r\n{    \r\n  void GrowLength(size_t size)\r\n  {\r\n    size_t delta;\r\n    if (this->_capacity > 64)\r\n      delta = this->_capacity / 4;\r\n    else if (this->_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    delta = MyMax(delta, size);\r\n    SetCapacity(this->_capacity + delta);\r\n  }\r\npublic:\r\n  CDynamicBuffer(): CBuffer<T>() {};\r\n  CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};\r\n  CDynamicBuffer(size_t size): CBuffer<T>(size) {};\r\n  CDynamicBuffer& operator=(const CDynamicBuffer &buffer)\r\n  {\r\n    this->Free();\r\n    if(buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n  void EnsureCapacity(size_t capacity)\r\n  {\r\n    if (this->_capacity < capacity)\r\n      GrowLength(capacity - this->_capacity);\r\n  }\r\n};\r\n\r\ntypedef CDynamicBuffer<char> CCharDynamicBuffer;\r\ntypedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;\r\ntypedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/IntToString.cpp",
    "content": "// Common/IntToString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"IntToString.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)\r\n{\r\n  if (base < 2 || base > 36)\r\n  {\r\n    *s = '\\0';\r\n    return;\r\n  }\r\n  char temp[72];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    int delta = (int)(value % base);\r\n    temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));\r\n    value /= base;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while(pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s)\r\n{\r\n  wchar_t temp[32];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do \r\n    *s++ = temp[--pos];\r\n  while(pos > 0);\r\n  *s = L'\\0';\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = '-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = L'-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/IntToString.h",
    "content": "// Common/IntToString.h\r\n\r\n#ifndef __COMMON_INTTOSTRING_H\r\n#define __COMMON_INTTOSTRING_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s);\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s);\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/ListFileUtils.cpp",
    "content": "// Common/ListFileUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Windows/FileIO.h\"\r\n\r\n#include \"ListFileUtils.h\"\r\n#include \"StringConvert.h\"\r\n#include \"UTFConvert.h\"\r\n\r\nstatic const char kQuoteChar     = '\\\"';\r\nstatic void RemoveQuote(UString &s)\r\n{\r\n  if (s.Length() >= 2)\r\n    if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)\r\n      s = s.Mid(1, s.Length() - 2);\r\n}\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)\r\n{\r\n  NWindows::NFile::NIO::CInFile file;\r\n  if (!file.Open(fileName))\r\n    return false;\r\n  UInt64 length;\r\n  if (!file.GetLength(length))\r\n    return false;\r\n  if (length > ((UInt32)1 << 31))\r\n    return false;\r\n  AString s;\r\n  char *p = s.GetBuffer((int)length + 1);\r\n  UInt32 processed;\r\n  if (!file.Read(p, (UInt32)length, processed))\r\n    return false;\r\n  p[(UInt32)length] = 0;\r\n  s.ReleaseBuffer();\r\n  file.Close();\r\n\r\n  UString u;\r\n  #ifdef CP_UTF8\r\n  if (codePage == CP_UTF8)\r\n  {\r\n    if (!ConvertUTF8ToUnicode(s, u))\r\n      return false;\r\n  }\r\n  else\r\n  #endif\r\n    u = MultiByteToUnicodeString(s, codePage);\r\n  if (!u.IsEmpty())\r\n  {\r\n    if (u[0] == 0xFEFF)\r\n      u.Delete(0);\r\n  }\r\n\r\n  UString t;\r\n  for(int i = 0; i < u.Length(); i++)\r\n  {\r\n    wchar_t c = u[i];\r\n    if (c == L'\\n' || c == 0xD)\r\n    {\r\n      t.Trim();\r\n      RemoveQuote(t);\r\n      if (!t.IsEmpty())\r\n        resultStrings.Add(t);\r\n      t.Empty();\r\n    }\r\n    else\r\n      t += c;\r\n  }\r\n  t.Trim();\r\n  RemoveQuote(t);\r\n  if (!t.IsEmpty())\r\n    resultStrings.Add(t);\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/ListFileUtils.h",
    "content": "// Common/ListFileUtils.h\r\n\r\n#ifndef __COMMON_LISTFILEUTILS_H\r\n#define __COMMON_LISTFILEUTILS_H\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }\r\n#endif\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p) \r\n  { \r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p) \r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR() { m_str = NULL; }\r\n  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR pSrc)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(pSrc);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const \r\n  { \r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memmove(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  void Attach(BSTR src) {  m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) { \r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \\\r\n    { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \\\r\n    MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n    MY_QUERYINTERFACE_ENTRY(i)\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyException.h",
    "content": "// Common/Exception.h\r\n\r\n#ifndef __COMMON_EXCEPTION_H\r\n#define __COMMON_EXCEPTION_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\nstruct CSystemException\r\n{\r\n  HRESULT ErrorCode;\r\n  CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline int operator==(REFGUID g1, REFGUID g2)\r\n{ \r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return 0;\r\n  return 1;\r\n}\r\ninline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyString.cpp",
    "content": "// Common/MyString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"StringConvert.h\"\r\n#else\r\n#include <ctype.h>\r\n#endif\r\n\r\n#include \"MyString.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{ \r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1), \r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), \r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{ \r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyString.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{ \r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{ \r\n  T *destStart = dest;\r\n  while((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char  *s2);\r\n#endif\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex, \r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n  int _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if(realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if(newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if(_capacity > 0)\r\n    {\r\n      for (int i = 0; i < (_length + 1); i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n      _chars = newBuffer;\r\n    }\r\n    else\r\n    {\r\n      _chars = newBuffer;\r\n      _chars[0] = 0;\r\n    }\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize) \r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0)\r\n    { SetCapacity(16 - 1); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;} \r\n\r\n  // The minimum size of the character buffer in characters. \r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if(minBufLength >= _capacity)\r\n      SetCapacity(minBufLength + 1);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if(newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length; \r\n    return *this;\r\n  }  \r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if(&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int Compare(const T *s) const\r\n    { return MyStringCompare(_chars, s); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const T *s) const\r\n    { return MyStringCompareNoCase(_chars, s); }\r\n\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for(int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    charSet += (T)' ';\r\n    charSet += (T)'\\n';\r\n    charSet += (T)'\\t';\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for(int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0) \r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0) \r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct \r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else \r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyVector.cpp",
    "content": "// Common/MyVector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector() { Free(); }\r\n\r\nvoid CBaseRecordVector::Free()\r\n{ \r\n  delete []((unsigned char *)_items); \r\n  _capacity = 0;\r\n  _size = 0;\r\n  _items = 0;\r\n}\r\n\r\nvoid CBaseRecordVector::Clear() { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index) { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if (_size != _capacity)\r\n    return;\r\n  int delta;\r\n  if (_capacity > 64)\r\n    delta = _capacity / 2;\r\n  else if (_capacity > 8)\r\n    delta = 8;\r\n  else\r\n    delta = 4;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  if (newCapacity <= _capacity)\r\n    return;\r\n  if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))\r\n    throw 1052353;\r\n  size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;\r\n  if (newSize / _itemSize != (size_t)(unsigned)newCapacity)\r\n    throw 1052354;\r\n  unsigned char *p = new unsigned char[newSize];\r\n  if (p == 0)\r\n    throw 1052355;\r\n  int numRecordsToMove = _capacity;\r\n  memmove(p, _items, _itemSize * numRecordsToMove);\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize, \r\n    ((unsigned char  *)_items) + srcIndex * _itemSize, \r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyVector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n  int _capacity;\r\n  int _size;\r\n  void *_items;\r\n  size_t _itemSize;\r\n  \r\n  void ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; } \r\npublic:\r\n  CBaseRecordVector(size_t itemSize):\r\n      _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n  virtual ~CBaseRecordVector();\r\n  void Free();\r\n  int Size() const { return _size; }\r\n  bool IsEmpty() const { return (_size == 0); }\r\n  void Reserve(int newCapacity);\r\n  virtual void Delete(int index, int num = 1);\r\n  void Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector():CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v):\r\n    CBaseRecordVector(sizeof(T)) { *this = v;}\r\n  CRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  int Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n  void Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n  T& operator[](int index) { return ((T *)_items)[index]; }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Front()   { return operator[](0); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  T& Back()   { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  int AddToUniqueSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)\r\n  { \r\n    T temp = p[k];\r\n    for (;;)\r\n    {\r\n      int s = (k << 1);\r\n      if (s > size)\r\n        break;\r\n      if (s < size && compare(p + s + 1, p + s, param) > 0)\r\n        s++;\r\n      if (compare(&temp, p + s, param) >= 0)\r\n        break;\r\n      p[k] = p[s]; \r\n      k = s;\r\n    } \r\n    p[k] = temp; \r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    int size = _size;\r\n    if (size <= 1)\r\n      return;\r\n    T* p = (&Front()) - 1;\r\n    {\r\n      int i = size / 2;\r\n      do\r\n        SortRefDown(p, i, size, compare, param);\r\n      while(--i != 0);\r\n    }\r\n    do\r\n    {\r\n      T temp = p[size];\r\n      p[size--] = p[1];\r\n      p[1] = temp;\r\n      SortRefDown(p, 1, size, compare, param);\r\n    }\r\n    while (size > 1);\r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector(){};\r\n  ~CObjectVector() { Clear(); }\r\n  CObjectVector(const CObjectVector &objectVector)\r\n    { *this = objectVector; }\r\n  CObjectVector& operator=(const CObjectVector &objectVector)\r\n  {\r\n    Clear();\r\n    return (*this += objectVector);\r\n  }\r\n  CObjectVector& operator+=(const CObjectVector &objectVector)\r\n  {\r\n    int size = objectVector.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(objectVector[i]);\r\n    return *this;\r\n  }\r\n  const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n  T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Back() { return operator[](_size - 1); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  int Add(const T& item)\r\n    { return CPointerVector::Add(new T(item)); }\r\n  void Insert(int index, const T& item)\r\n    { CPointerVector::Insert(index, new T(item)); }\r\n  virtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for(int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for(int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n      return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param) \r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#define CHAR_PATH_SEPARATOR '\\\\'\r\n#define WCHAR_PATH_SEPARATOR L'\\\\'\r\n#define STRING_PATH_SEPARATOR \"\\\\\"\r\n#define WSTRING_PATH_SEPARATOR L\"\\\\\"\r\n\r\n#else\r\n\r\n#define CHAR_PATH_SEPARATOR '/'\r\n#define WCHAR_PATH_SEPARATOR L'/'\r\n#define STRING_PATH_SEPARATOR \"/\"\r\n#define WSTRING_PATH_SEPARATOR L\"/\"\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\n\r\n#undef BYTE\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\n\r\n#undef WORD\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\n\r\n#undef DWORD\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOTIMPL ((HRESULT)0x80004001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall \r\n#else\r\n#define STDMETHODCALLTYPE \r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct \r\n\r\n#ifdef __cplusplus\r\n\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n  #ifndef _WIN32\r\n  virtual ~IUnknown() {}\r\n  #endif\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#endif\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\r\n  VT_EMPTY = 0,\r\n  VT_NULL = 1,\r\n  VT_I2 = 2,\r\n  VT_I4 = 3,\r\n  VT_R4 = 4,\r\n  VT_R8 = 5,\r\n  VT_CY = 6,\r\n  VT_DATE = 7,\r\n  VT_BSTR = 8,\r\n  VT_DISPATCH = 9,\r\n  VT_ERROR = 10,\r\n  VT_BOOL = 11,\r\n  VT_VARIANT = 12,\r\n  VT_UNKNOWN = 13,\r\n  VT_DECIMAL = 14,\r\n  VT_I1 = 16,\r\n  VT_UI1 = 17,\r\n  VT_UI2 = 18,\r\n  VT_UI4 = 19,\r\n  VT_I8 = 20,\r\n  VT_UI8 = 21,\r\n  VT_INT = 22,\r\n  VT_UINT = 23,\r\n  VT_VOID = 24,\r\n  VT_HRESULT = 25,\r\n  VT_FILETIME = 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\n#ifdef __cplusplus\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union \r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\n\r\n#endif\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\r\n  STREAM_SEEK_SET = 0,\r\n  STREAM_SEEK_CUR = 1,\r\n  STREAM_SEEK_END = 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\n#ifdef _WIN32\r\nvoid * \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n#endif\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\n#ifdef _WIN32\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw();\r\n#endif \r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/StdInStream.cpp",
    "content": "// Common/StdInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n#include \"StdInStream.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kIllegalChar = '\\0';\r\nstatic const char kNewLineChar = '\\n';\r\n\r\nstatic const char *kEOFMessage = \"Unexpected end of input stream\";\r\nstatic const char *kReadErrorMessage  =\"Error reading input stream\"; \r\nstatic const char *kIllegalCharMessage = \"Illegal character in input stream\";\r\n\r\nstatic LPCTSTR kFileOpenMode = TEXT(\"r\");\r\n\r\nCStdInStream g_StdIn(stdin);\r\n\r\nbool CStdInStream::Open(LPCTSTR fileName)\r\n{\r\n  Close();\r\n  _stream = _tfopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdInStream::Close()\r\n{\r\n  if(!_streamIsOpen)\r\n    return true;\r\n  _streamIsOpen = (fclose(_stream) != 0);\r\n  return !_streamIsOpen;\r\n}\r\n\r\nCStdInStream::~CStdInStream()\r\n{\r\n  Close();\r\n}\r\n\r\nAString CStdInStream::ScanStringUntilNewLine()\r\n{\r\n  AString s;\r\n  for (;;)\r\n  {\r\n    int intChar = GetChar();\r\n    if(intChar == EOF)\r\n      throw kEOFMessage;\r\n    char c = char(intChar);\r\n    if (c == kIllegalChar)\r\n      throw kIllegalCharMessage;\r\n    if(c == kNewLineChar)\r\n      break;\r\n    s += c;\r\n  }\r\n  return s;\r\n}\r\n\r\nvoid CStdInStream::ReadToString(AString &resultString)\r\n{\r\n  resultString.Empty();\r\n  int c;\r\n  while((c = GetChar()) != EOF)\r\n    resultString += char(c);\r\n}\r\n\r\nbool CStdInStream::Eof()\r\n{\r\n  return (feof(_stream) != 0);\r\n}\r\n\r\nint CStdInStream::GetChar()\r\n{\r\n  int c = fgetc(_stream); // getc() doesn't work in BeOS?\r\n  if(c == EOF && !Eof())\r\n    throw kReadErrorMessage;\r\n  return c;\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/StdInStream.h",
    "content": "// Common/StdInStream.h\r\n\r\n#ifndef __COMMON_STDINSTREAM_H\r\n#define __COMMON_STDINSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nclass CStdInStream \r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdInStream(): _streamIsOpen(false) {};\r\n  CStdInStream(FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdInStream();\r\n  bool Open(LPCTSTR fileName);\r\n  bool Close();\r\n\r\n  AString ScanStringUntilNewLine();\r\n  void ReadToString(AString &resultString);\r\n\r\n  bool Eof();\r\n  int GetChar();\r\n};\r\n\r\nextern CStdInStream g_StdIn;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/StdOutStream.cpp",
    "content": "// Common/StdOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n\r\n#include \"StdOutStream.h\"\r\n#include \"IntToString.h\"\r\n#include \"StringConvert.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kNewLineChar =  '\\n';\r\n\r\nstatic const char *kFileOpenMode = \"wt\";\r\n\r\nCStdOutStream  g_StdOut(stdout);\r\nCStdOutStream  g_StdErr(stderr);\r\n\r\nbool CStdOutStream::Open(const char *fileName)\r\n{\r\n  Close();\r\n  _stream = fopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdOutStream::Close()\r\n{\r\n  if(!_streamIsOpen)\r\n    return true;\r\n  if (fclose(_stream) != 0)\r\n    return false;\r\n  _stream = 0;\r\n  _streamIsOpen = false;\r\n  return true;\r\n}\r\n\r\nbool CStdOutStream::Flush()\r\n{\r\n  return (fflush(_stream) == 0);\r\n}\r\n\r\nCStdOutStream::~CStdOutStream ()\r\n{\r\n  Close();\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream  &))\r\n{\r\n  (*aFunction)(*this);    \r\n  return *this;\r\n}\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream)\r\n{\r\n  return outStream << kNewLineChar;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const char *string)\r\n{\r\n  fputs(string, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const wchar_t *string)\r\n{\r\n  *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(char c)\r\n{\r\n  fputc(c, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(int number)\r\n{\r\n  char textString[32];\r\n  ConvertInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(UInt64 number)\r\n{\r\n  char textString[32];\r\n  ConvertUInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/StdOutStream.h",
    "content": "// Common/StdOutStream.h\r\n\r\n#ifndef __COMMON_STDOUTSTREAM_H\r\n#define __COMMON_STDOUTSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Types.h\"\r\n\r\nclass CStdOutStream \r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdOutStream (): _streamIsOpen(false), _stream(0) {};\r\n  CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdOutStream ();\r\n  operator FILE *() { return _stream; }\r\n  bool Open(const char *fileName);\r\n  bool Close();\r\n  bool Flush();\r\n  CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream  &));\r\n  CStdOutStream & operator<<(const char *string);\r\n  CStdOutStream & operator<<(const wchar_t *string);\r\n  CStdOutStream & operator<<(char c);\r\n  CStdOutStream & operator<<(int number);\r\n  CStdOutStream & operator<<(UInt64 number);\r\n};\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream);\r\n\r\nextern CStdOutStream g_StdOut;\r\nextern CStdOutStream g_StdErr;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()), \r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 2;\r\n    char defaultChar = '_';\r\n    int numChars = WideCharToMultiByte(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(numRequiredBytes), \r\n      numRequiredBytes + 1, &defaultChar, NULL);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_INT16_DEFINED\r\n#define _7ZIP_INT16_DEFINED\r\ntypedef short Int16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_INT32_DEFINED\r\n#define _7ZIP_INT32_DEFINED\r\ntypedef int Int32;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\ntypedef unsigned int UInt32;\r\n#endif \r\n\r\n#ifdef _MSC_VER\r\n\r\n#ifndef _7ZIP_INT64_DEFINED\r\n#define _7ZIP_INT64_DEFINED\r\ntypedef __int64 Int64;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\ntypedef unsigned __int64 UInt64;\r\n#endif \r\n\r\n#else\r\n\r\n#ifndef _7ZIP_INT64_DEFINED\r\n#define _7ZIP_INT64_DEFINED\r\ntypedef long long int Int64;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\ntypedef unsigned long long int UInt64;\r\n#endif \r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/UTFConvert.cpp",
    "content": "// UTFConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UTFConvert.h\"\r\n#include \"Types.h\"\r\n\r\nstatic Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\n// These functions are for UTF8 <-> UTF16 conversion.\r\n\r\nbool ConvertUTF8ToUnicode(const AString &src, UString &dest)\r\n{\r\n  dest.Empty();\r\n  for(int i = 0; i < src.Length();)\r\n  {\r\n    Byte c = (Byte)src[i++];\r\n    if (c < 0x80)\r\n    {\r\n      dest += (wchar_t)c;\r\n      continue;\r\n    }\r\n    if(c < 0xC0)\r\n      return false;\r\n    int numAdds;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (c < kUtf8Limits[numAdds])\r\n        break;\r\n    UInt32 value = (c - kUtf8Limits[numAdds - 1]);\r\n    do\r\n    {\r\n      if (i >= src.Length())\r\n        return false;\r\n      Byte c2 = (Byte)src[i++];\r\n      if (c2 < 0x80 || c2 >= 0xC0)\r\n        return false;\r\n      value <<= 6;\r\n      value |= (c2 - 0x80);\r\n      numAdds--;\r\n    }\r\n    while(numAdds > 0);\r\n    if (value < 0x10000)\r\n      dest += (wchar_t)(value);\r\n    else\r\n    {\r\n      value -= 0x10000;\r\n      if (value >= 0x100000)\r\n        return false;\r\n      dest += (wchar_t)(0xD800 + (value >> 10));\r\n      dest += (wchar_t)(0xDC00 + (value & 0x3FF));\r\n    }\r\n  }\r\n  return true; \r\n}\r\n\r\nbool ConvertUnicodeToUTF8(const UString &src, AString &dest)\r\n{\r\n  dest.Empty();\r\n  for(int i = 0; i < src.Length();)\r\n  {\r\n    UInt32 value = (UInt32)src[i++];\r\n    if (value < 0x80)\r\n    {\r\n      dest += (char)value;\r\n      continue;\r\n    }\r\n    if (value >= 0xD800 && value < 0xE000)\r\n    {\r\n      if (value >= 0xDC00)\r\n        return false;\r\n      if (i >= src.Length())\r\n        return false;\r\n      UInt32 c2 = (UInt32)src[i++];\r\n      if (c2 < 0xDC00 || c2 >= 0xE000)\r\n        return false;\r\n      value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n    }\r\n    int numAdds;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n        break;\r\n    dest += (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n    do\r\n    {\r\n      numAdds--;\r\n      dest += (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n    }\r\n    while(numAdds > 0);\r\n  }\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/UTFConvert.h",
    "content": "// Common/UTFConvert.h\r\n\r\n#ifndef __COMMON_UTFCONVERT_H\r\n#define __COMMON_UTFCONVERT_H\r\n\r\n#include \"MyString.h\"\r\n\r\nbool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);\r\nbool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/Wildcard.cpp",
    "content": "// Common/Wildcard.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Wildcard.h\"\r\n\r\nbool g_CaseSensitive = \r\n  #ifdef _WIN32\r\n    false;\r\n  #else\r\n    true;\r\n  #endif\r\n\r\nstatic const wchar_t kAnyCharsChar = L'*';\r\nstatic const wchar_t kAnyCharChar = L'?';\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t kDirDelimiter1 = L'\\\\';\r\n#endif\r\nstatic const wchar_t kDirDelimiter2 = L'/';\r\n\r\nstatic const UString kWildCardCharSet = L\"?*\";\r\n\r\nstatic const UString kIllegalWildCardFileNameChars=\r\n  L\"\\x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\xA\\xB\\xC\\xD\\xE\\xF\"\r\n  L\"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F\"\r\n  L\"\\\"/:<>\\\\|\";\r\n\r\n\r\nstatic inline bool IsCharDirLimiter(wchar_t c)\r\n{\r\n  return (\r\n    #ifdef _WIN32\r\n    c == kDirDelimiter1 || \r\n    #endif\r\n    c == kDirDelimiter2);\r\n}\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2)\r\n{\r\n  if (g_CaseSensitive)\r\n    return s1.Compare(s2);\r\n  return s1.CompareNoCase(s2);\r\n}\r\n\r\n// -----------------------------------------\r\n// this function compares name with mask\r\n// ? - any char\r\n// * - any char or empty\r\n\r\nstatic bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t m = *mask;\r\n    wchar_t c = *name;\r\n    if (m == 0) \r\n      return (c == 0);\r\n    if (m == kAnyCharsChar)\r\n    {\r\n      if (EnhancedMaskTest(mask + 1, name))\r\n        return true;\r\n      if (c == 0) \r\n        return false;\r\n    }\r\n    else\r\n    {\r\n      if (m == kAnyCharChar)\r\n      {\r\n        if (c == 0) \r\n          return false;\r\n      }\r\n      else if (m != c)\r\n        if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))\r\n          return false;\r\n      mask++;\r\n    }\r\n    name++;\r\n  }\r\n}\r\n\r\n// --------------------------------------------------\r\n// Splits path to strings\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts)\r\n{\r\n  pathParts.Clear();\r\n  UString name;\r\n  int len = path.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = path[i];\r\n    if (IsCharDirLimiter(c))\r\n    {\r\n      pathParts.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  pathParts.Add(name);\r\n}\r\n\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)\r\n{\r\n  int i;\r\n  for(i = path.Length() - 1; i >= 0; i--)\r\n    if(IsCharDirLimiter(path[i]))\r\n      break;\r\n  dirPrefix = path.Left(i + 1);\r\n  name = path.Mid(i + 1);\r\n}\r\n\r\nUString ExtractDirPrefixFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for(i = path.Length() - 1; i >= 0; i--)\r\n    if(IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Left(i + 1);\r\n}\r\n\r\nUString ExtractFileNameFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for(i = path.Length() - 1; i >= 0; i--)\r\n    if(IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Mid(i + 1);\r\n}\r\n\r\n\r\nbool CompareWildCardWithName(const UString &mask, const UString &name)\r\n{\r\n  return EnhancedMaskTest(mask, name);\r\n}\r\n\r\nbool DoesNameContainWildCard(const UString &path)\r\n{\r\n  return (path.FindOneOf(kWildCardCharSet) >= 0);\r\n}\r\n\r\n\r\n// ----------------------------------------------------------'\r\n// NWildcard\r\n\r\nnamespace NWildcard {\r\n\r\n\r\n/*\r\nM = MaskParts.Size();\r\nN = TestNameParts.Size();\r\n\r\n                           File                          Dir\r\nForFile     req   M<=N  [N-M, N)                          -\r\n         nonreq   M=N   [0, M)                            -  \r\n \r\nForDir      req   M<N   [0, M) ... [N-M-1, N-1)  same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\nForBoth     req   m<=N  [0, M) ... [N-M, N)      same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\n*/\r\n\r\nbool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (!isFile && !ForDir)\r\n    return false;\r\n  int delta = (int)pathParts.Size() - (int)PathParts.Size();\r\n  if (delta < 0)\r\n    return false;\r\n  int start = 0;\r\n  int finish = 0;\r\n  if (isFile)\r\n  {\r\n    if (!ForDir && !Recursive && delta !=0)\r\n      return false;\r\n    if (!ForFile && delta == 0)\r\n      return false;\r\n    if (!ForDir && Recursive)\r\n      start = delta;\r\n  }\r\n  if (Recursive)\r\n  {\r\n    finish = delta;\r\n    if (isFile && !ForFile)\r\n      finish = delta - 1;\r\n  }\r\n  for (int d = start; d <= finish; d++)\r\n  {\r\n    int i;\r\n    for (i = 0; i < PathParts.Size(); i++)\r\n      if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))\r\n        break;\r\n    if (i == PathParts.Size())\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nint CCensorNode::FindSubNode(const UString &name) const\r\n{\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (CompareFileNames(SubNodes[i].Name, name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensorNode::AddItemSimple(bool include, CItem &item)\r\n{\r\n  if (include)\r\n    IncludeItems.Add(item);\r\n  else\r\n    ExcludeItems.Add(item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, CItem &item)\r\n{\r\n  if (item.PathParts.Size() <= 1)\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  const UString &front = item.PathParts.Front();\r\n  if (DoesNameContainWildCard(front))\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  int index = FindSubNode(front);\r\n  if (index < 0)\r\n    index = SubNodes.Add(CCensorNode(front, this));\r\n  item.PathParts.Delete(0);\r\n  SubNodes[index].AddItem(include, item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)\r\n{\r\n  CItem item;\r\n  SplitPathToParts(path, item.PathParts);\r\n  item.Recursive = recursive;\r\n  item.ForFile = forFile;\r\n  item.ForDir = forDir;\r\n  AddItem(include, item);\r\n}\r\n\r\nbool CCensorNode::NeedCheckSubDirs() const\r\n{\r\n  for (int i = 0; i < IncludeItems.Size(); i++)\r\n  {\r\n    const CItem &item = IncludeItems[i];\r\n    if (item.Recursive || item.PathParts.Size() > 1)\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::AreThereIncludeItems() const\r\n{\r\n  if (IncludeItems.Size() > 0)\r\n    return true;\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (SubNodes[i].AreThereIncludeItems())\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const\r\n{\r\n  const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;\r\n  for (int i = 0; i < items.Size(); i++)\r\n    if (items[i].CheckPath(pathParts, isFile))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const\r\n{\r\n  if (CheckPathCurrent(false, pathParts, isFile))\r\n  {\r\n    include = false;\r\n    return true;\r\n  }\r\n  include = true;\r\n  bool finded = CheckPathCurrent(true, pathParts, isFile);\r\n  if (pathParts.Size() == 1)\r\n    return finded;\r\n  int index = FindSubNode(pathParts.Front());\r\n  if (index >= 0)\r\n  {\r\n    UStringVector pathParts2 = pathParts;\r\n    pathParts2.Delete(0);\r\n    if (SubNodes[index].CheckPath(pathParts2, isFile, include))\r\n      return true;\r\n  }\r\n  return finded;\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const\r\n{\r\n  UStringVector pathParts; \r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPath(pathParts, isFile, include);\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool include;\r\n  if(CheckPath(path, isFile, include))\r\n    return include;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (CheckPathCurrent(include, pathParts, isFile))\r\n    return true;\r\n  if (Parent == 0)\r\n    return false;\r\n  pathParts.Insert(0, Name);\r\n  return Parent->CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n\r\n/*\r\nbool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const\r\n{\r\n  UStringVector pathParts; \r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n*/\r\n\r\nvoid CCensorNode::AddItem2(bool include, const UString &path, bool recursive)\r\n{\r\n  if (path.IsEmpty())\r\n    return;\r\n  bool forFile = true;\r\n  bool forFolder = true;\r\n  UString path2 = path;\r\n  if (IsCharDirLimiter(path[path.Length() - 1]))\r\n  {\r\n    path2.Delete(path.Length() - 1);\r\n    forFile = false;\r\n  }\r\n  AddItem(include, path2, recursive, forFile, forFolder);\r\n}\r\n\r\nvoid CCensorNode::ExtendExclude(const CCensorNode &fromNodes)\r\n{\r\n  ExcludeItems += fromNodes.ExcludeItems;\r\n  for (int i = 0; i < fromNodes.SubNodes.Size(); i++)\r\n  {\r\n    const CCensorNode &node = fromNodes.SubNodes[i];\r\n    int subNodeIndex = FindSubNode(node.Name);\r\n    if (subNodeIndex < 0)\r\n      subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));\r\n    SubNodes[subNodeIndex].ExtendExclude(node);\r\n  }\r\n}\r\n\r\nint CCensor::FindPrefix(const UString &prefix) const\r\n{\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n    if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensor::AddItem(bool include, const UString &path, bool recursive)\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  bool forFile = true;\r\n  if (pathParts.Back().IsEmpty())\r\n  {\r\n    forFile = false;\r\n    pathParts.DeleteBack();\r\n  }\r\n  const UString &front = pathParts.Front();\r\n  bool isAbs = false;\r\n  if (front.IsEmpty())\r\n    isAbs = true;\r\n  else if (front.Length() == 2 && front[1] == L':')\r\n    isAbs = true;\r\n  else\r\n  {\r\n    for (int i = 0; i < pathParts.Size(); i++)\r\n    {\r\n      const UString &part = pathParts[i];\r\n      if (part == L\"..\" || part == L\".\")\r\n      {\r\n        isAbs = true;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  int numAbsParts = 0;\r\n  if (isAbs)\r\n    if (pathParts.Size() > 1)\r\n      numAbsParts = pathParts.Size() - 1;\r\n    else\r\n      numAbsParts = 1;\r\n  UString prefix;\r\n  for (int i = 0; i < numAbsParts; i++)\r\n  {\r\n    const UString &front = pathParts.Front();\r\n    if (DoesNameContainWildCard(front))\r\n      break;\r\n    prefix += front;\r\n    prefix += WCHAR_PATH_SEPARATOR;\r\n    pathParts.Delete(0);\r\n  }\r\n  int index = FindPrefix(prefix);\r\n  if (index < 0)\r\n    index = Pairs.Add(CPair(prefix));\r\n\r\n  CItem item;\r\n  item.PathParts = pathParts;\r\n  item.ForDir = true;\r\n  item.ForFile = forFile;\r\n  item.Recursive = recursive;\r\n  Pairs[index].Head.AddItem(include, item);\r\n}\r\n\r\nbool CCensor::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool finded = false;\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n  {\r\n    bool include;\r\n    if (Pairs[i].Head.CheckPath(path, isFile, include))\r\n    {\r\n      if (!include)\r\n        return false;\r\n      finded = true;\r\n    }\r\n  }\r\n  return finded;\r\n}\r\n\r\nvoid CCensor::ExtendExclude()\r\n{\r\n  int i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (Pairs[i].Prefix.IsEmpty())\r\n      break;\r\n  if (i == Pairs.Size())\r\n    return;\r\n  int index = i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (index != i)\r\n      Pairs[i].Head.ExtendExclude(Pairs[index].Head);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Common/Wildcard.h",
    "content": "// Common/Wildcard.h\r\n\r\n#ifndef __COMMON_WILDCARD_H\r\n#define __COMMON_WILDCARD_H\r\n\r\n#include \"MyString.h\"\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2);\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts);\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);\r\nUString ExtractDirPrefixFromPath(const UString &path);\r\nUString ExtractFileNameFromPath(const UString &path);\r\nbool DoesNameContainWildCard(const UString &path);\r\nbool CompareWildCardWithName(const UString &mask, const UString &name);\r\n\r\nnamespace NWildcard {\r\n\r\nstruct CItem\r\n{\r\n  UStringVector PathParts;\r\n  bool Recursive;\r\n  bool ForFile;\r\n  bool ForDir;\r\n  bool CheckPath(const UStringVector &pathParts, bool isFile) const;\r\n};\r\n\r\nclass CCensorNode\r\n{\r\n  CCensorNode *Parent;\r\n  bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;\r\n  void AddItemSimple(bool include, CItem &item);\r\n  bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;\r\npublic:\r\n  CCensorNode(): Parent(0) { };\r\n  CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };\r\n  UString Name;\r\n  CObjectVector<CCensorNode> SubNodes;\r\n  CObjectVector<CItem> IncludeItems;\r\n  CObjectVector<CItem> ExcludeItems;\r\n\r\n  int FindSubNode(const UString &path) const;\r\n\r\n  void AddItem(bool include, CItem &item);\r\n  void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);\r\n  void AddItem2(bool include, const UString &path, bool recursive);\r\n\r\n  bool NeedCheckSubDirs() const;\r\n  bool AreThereIncludeItems() const;\r\n\r\n  bool CheckPath(const UString &path, bool isFile, bool &include) const;\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n\r\n  bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;\r\n  // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;\r\n  void ExtendExclude(const CCensorNode &fromNodes);\r\n};\r\n\r\nstruct CPair\r\n{\r\n  UString Prefix;\r\n  CCensorNode Head;\r\n  CPair(const UString &prefix): Prefix(prefix) { };\r\n};\r\n\r\nclass CCensor\r\n{\r\n  int FindPrefix(const UString &prefix) const;\r\npublic:\r\n  CObjectVector<CPair> Pairs;\r\n  bool AllAreRelative() const\r\n    { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }\r\n  void AddItem(bool include, const UString &path, bool recursive);\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n  void ExtendExclude();\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/DLL.cpp",
    "content": "// Windows/DLL.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DLL.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nCLibrary::~CLibrary()\r\n{\r\n  Free();\r\n}\r\n\r\nbool CLibrary::Free()\r\n{\r\n  if (_module == 0)\r\n    return true;\r\n  // MessageBox(0, TEXT(\"\"), TEXT(\"Free\"), 0);\r\n  // Sleep(5000);\r\n  if (!::FreeLibrary(_module))\r\n    return false;\r\n  _module = 0;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadOperations(HMODULE newModule)\r\n{\r\n  if (newModule == NULL)\r\n    return false;\r\n  if(!Free())\r\n    return false;\r\n  _module = newModule;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"LoadEx\"), 0);\r\n  return LoadOperations(::LoadLibraryEx(fileName, NULL, flags));\r\n}\r\n\r\nbool CLibrary::Load(LPCTSTR fileName)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"Load\"), 0);\r\n  // Sleep(5000);\r\n  // OutputDebugString(fileName);\r\n  // OutputDebugString(TEXT(\"\\n\"));\r\n  return LoadOperations(::LoadLibrary(fileName));\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\nCSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n\r\nbool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));\r\n  return LoadEx(GetSysPath(fileName), flags);\r\n}\r\nbool CLibrary::Load(LPCWSTR fileName)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryW(fileName));\r\n  return Load(GetSysPath(fileName));\r\n}\r\n#endif\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result)\r\n{\r\n  result.Empty();\r\n  TCHAR fullPath[MAX_PATH + 2];\r\n  DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1);\r\n  if (size <= MAX_PATH && size != 0)\r\n  {\r\n    result = fullPath;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result)\r\n{\r\n  result.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    wchar_t fullPath[MAX_PATH + 2];\r\n    DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);\r\n    if (size <= MAX_PATH && size != 0)\r\n    {\r\n      result = fullPath;\r\n      return true;\r\n    }\r\n    return false;\r\n  }\r\n  CSysString resultSys;\r\n  if (!MyGetModuleFileName(hModule, resultSys))\r\n    return false;\r\n  result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());\r\n  return true;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/DLL.h",
    "content": "// Windows/DLL.h\r\n\r\n#ifndef __WINDOWS_DLL_H\r\n#define __WINDOWS_DLL_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nclass CLibrary\r\n{\r\n  bool LoadOperations(HMODULE newModule);\r\nprotected:\r\n  HMODULE _module;\r\npublic:\r\n  operator HMODULE() const { return _module; }\r\n  HMODULE* operator&() { return &_module; }\r\n\r\n  CLibrary():_module(NULL) {};\r\n  ~CLibrary();\r\n  void Attach(HMODULE m)\r\n  {\r\n    Free();\r\n    _module = m;\r\n  }\r\n  HMODULE Detach()\r\n  {\r\n    HMODULE m = _module;\r\n    _module = NULL;\r\n    return m;\r\n  }\r\n\r\n  // operator HMODULE() const { return _module; };\r\n  bool IsLoaded() const { return (_module != NULL); };\r\n  bool Free();\r\n  bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCWSTR fileName);\r\n  #endif\r\n  FARPROC GetProcAddress(LPCSTR procName) const\r\n    { return ::GetProcAddress(_module, procName); }\r\n};\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result);\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result);\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\n#ifdef _WIN32\r\ninline bool LRESULTToBool(LRESULT value)\r\n  { return (value != FALSE); }\r\n#endif\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/Error.cpp",
    "content": "// Windows/Error.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifndef _UNICODE\r\n#include \"Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message)\r\n{\r\n  LPVOID msgBuf;\r\n  if(::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r\n      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n      NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)\r\n    return false;\r\n  message = (LPCTSTR)msgBuf;\r\n  ::LocalFree(msgBuf);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyFormatMessage(DWORD messageID, UString &message)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPVOID msgBuf;\r\n    if(::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r\n        FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n        NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)\r\n      return false;\r\n    message = (LPCWSTR)msgBuf;\r\n    ::LocalFree(msgBuf);\r\n    return true;\r\n  }\r\n  CSysString messageSys;\r\n  bool result = MyFormatMessage(messageID, messageSys);\r\n  message = GetUnicodeString(messageSys);\r\n  return result;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/Error.h",
    "content": "// Windows/Error.h\r\n\r\n#ifndef __WINDOWS_ERROR_H\r\n#define __WINDOWS_ERROR_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message);\r\ninline CSysString MyFormatMessage(DWORD messageID)\r\n{\r\n  CSysString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#ifdef _UNICODE\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n  { return MyFormatMessage(messageID); }\r\n#else\r\nbool MyFormatMessage(DWORD messageID, UString &message);\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n{\r\n  UString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileDir.cpp",
    "content": "// Windows/FileDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileDir.h\"\r\n#include \"FileName.h\"\r\n#include \"FileFind.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n// SetCurrentDirectory doesn't support \\\\?\\ prefix\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR fileName, UString &res);\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n#endif\r\n\r\nnamespace NDirectory {\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\nstatic UString GetUnicodePath(const CSysString &sysPath)\r\n  { return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }\r\nstatic CSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\nbool MyGetSystemDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetWindowsDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n\r\nbool MyGetSystemDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetSystemDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n{\r\n  #ifndef _UNICODE\r\n  if (!g_IsNT)\r\n  {\r\n    ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\r\n    return false;\r\n  }\r\n  #endif \r\n  HANDLE hDir = ::CreateFileW(fileName, GENERIC_WRITE,\r\n      FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n      NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (hDir == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      hDir = ::CreateFileW(longPath, GENERIC_WRITE,\r\n        FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  }\r\n  #endif\r\n\r\n  bool res = false;\r\n  if (hDir != INVALID_HANDLE_VALUE)\r\n  {\r\n    res = BOOLToBool(::SetFileTime(hDir, creationTime, lastAccessTime, lastWriteTime));\r\n    ::CloseHandle(hDir);\r\n  }\r\n  return res;\r\n}\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (::SetFileAttributes(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyRemoveDirectory(LPCTSTR pathName)\r\n{ \r\n  if (::RemoveDirectory(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2)\r\n{\r\n  if (!GetLongPathBase(s1, d1) || !GetLongPathBase(s2, d2))\r\n    return false;\r\n  if (d1.IsEmpty() && d2.IsEmpty()) return false;\r\n  if (d1.IsEmpty()) d1 = s1;\r\n  if (d2.IsEmpty()) d2 = s2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName)\r\n{ \r\n  if (::MoveFile(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2)) \r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)\r\n{  \r\n  if (!g_IsNT)\r\n    return MySetFileAttributes(GetSysPath(fileName), fileAttributes);\r\n  if (::SetFileAttributesW(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n\r\nbool MyRemoveDirectory(LPCWSTR pathName)\r\n{  \r\n  if (!g_IsNT)\r\n    return MyRemoveDirectory(GetSysPath(pathName));\r\n  if (::RemoveDirectoryW(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)\r\n{  \r\n  if (!g_IsNT)\r\n    return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));\r\n  if (::MoveFileW(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2)) \r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nbool MyCreateDirectory(LPCTSTR pathName) \r\n{ \r\n  if (::CreateDirectory(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyCreateDirectory(LPCWSTR pathName)\r\n{  \r\n  if (!g_IsNT)\r\n    return MyCreateDirectory(GetSysPath(pathName));\r\n  if (::CreateDirectoryW(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\n/*\r\nbool CreateComplexDirectory(LPCTSTR pathName)\r\n{\r\n  NName::CParsedPath path;\r\n  path.ParsePath(pathName);\r\n  CSysString fullPath = path.Prefix;\r\n  DWORD errorCode = ERROR_SUCCESS;\r\n  for(int i = 0; i < path.PathParts.Size(); i++)\r\n  {\r\n    const CSysString &string = path.PathParts[i];\r\n    if(string.IsEmpty())\r\n    {\r\n      if(i != path.PathParts.Size() - 1)\r\n        return false;\r\n      return true;\r\n    }\r\n    fullPath += path.PathParts[i];\r\n    if (!MyCreateDirectory(fullPath))\r\n    {\r\n      DWORD errorCode = GetLastError();\r\n      if(errorCode != ERROR_ALREADY_EXISTS)\r\n        return false;\r\n    }\r\n    fullPath += NName::kDirDelimiter;\r\n  }\r\n  return true;\r\n}\r\n*/\r\n\r\nbool CreateComplexDirectory(LPCTSTR _aPathName)\r\n{\r\n  CSysString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == ':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  CSysString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if(MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfo fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDirectory())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == ':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while(pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateComplexDirectory(LPCWSTR _aPathName)\r\n{\r\n  UString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == L':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  UString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if(MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfoW fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDirectory())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == L':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while(pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\nbool DeleteFileAlways(LPCTSTR name)\r\n{\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFile(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DeleteFileAlways(LPCWSTR name)\r\n{  \r\n  if (!g_IsNT)\r\n    return DeleteFileAlways(GetSysPath(name));\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFileW(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nstatic bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)\r\n{\r\n  if(fileInfo.IsDirectory())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\n\r\nbool RemoveDirectoryWithSubItems(const CSysString &path)\r\n{\r\n  NFind::CFileInfo fileInfo;\r\n  CSysString pathPrefix = path + NName::kDirDelimiter;\r\n  {\r\n    NFind::CEnumerator enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));\r\n    while(enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)\r\n{\r\n  if(fileInfo.IsDirectory())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\nbool RemoveDirectoryWithSubItems(const UString &path)\r\n{\r\n  NFind::CFileInfoW fileInfo;\r\n  UString pathPrefix = path + UString(NName::kDirDelimiter);\r\n  {\r\n    NFind::CEnumeratorW enumerator(pathPrefix + UString(NName::kAnyStringWildcard));\r\n    while(enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\n\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)\r\n{\r\n  DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  shortPath.ReleaseBuffer();\r\n  return (needLength > 0 && needLength < MAX_PATH);\r\n}\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  LPTSTR fileNamePointer = 0;\r\n  LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n  DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n  resultPath.ReleaseBuffer();\r\n  if (needLength == 0)\r\n    return false;\r\n  if (needLength >= MAX_PATH)\r\n  {\r\n    #ifdef WIN_LONG_PATH2\r\n    needLength++;\r\n    buffer = resultPath.GetBuffer(needLength + 1);\r\n    DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength2 == 0 || needLength2 > needLength)\r\n    #endif\r\n      return false;\r\n  }\r\n  if (fileNamePointer == 0)\r\n    fileNamePartStartIndex = lstrlen(fileName);\r\n  else\r\n    fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR fileNamePointer = 0;\r\n    LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n    DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength == 0)\r\n      return false;\r\n    if (needLength >= MAX_PATH)\r\n    {\r\n      #ifdef WIN_LONG_PATH\r\n      needLength++;\r\n      buffer = resultPath.GetBuffer(needLength + 1);\r\n      DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n      resultPath.ReleaseBuffer();\r\n      if (needLength2 == 0 || needLength2 > needLength)\r\n      #endif\r\n        return false;\r\n    }\r\n    if (fileNamePointer == 0)\r\n      fileNamePartStartIndex = MyStringLen(fileName);\r\n    else\r\n      fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  }\r\n  else\r\n  {\r\n    CSysString sysPath;\r\n    if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))\r\n      return false;\r\n    UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));\r\n    UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));\r\n    fileNamePartStartIndex = resultPath1.Length();\r\n    resultPath = resultPath1 + resultPath2;\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n#endif\r\n\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetCurrentDirectory(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path)\r\n{\r\n  if (g_IsNT)\r\n    return BOOLToBool(::SetCurrentDirectoryW(path));\r\n  return MySetCurrentDirectory(GetSysPath(path));\r\n}\r\nbool MyGetCurrentDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetCurrentDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, \r\n  CSysString &resultPath, UINT32 &filePart)\r\n{\r\n  LPTSTR filePartPointer;\r\n  DWORD value = ::SearchPath(path, fileName, extension, \r\n    MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n  filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);\r\n  resultPath.ReleaseBuffer();\r\n  return (value > 0 && value <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, \r\n  UString &resultPath, UINT32 &filePart)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR filePartPointer = 0;\r\n    DWORD value = ::SearchPathW(path, fileName, extension, \r\n        MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n    filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);\r\n    resultPath.ReleaseBuffer();\r\n    return (value > 0 && value <= MAX_PATH);\r\n  }\r\n  \r\n  CSysString sysPath;\r\n  if (!MySearchPath(\r\n      path != 0 ? (LPCTSTR)GetSysPath(path): 0,\r\n      fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,\r\n      extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,\r\n      sysPath, filePart))\r\n    return false;\r\n  UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));\r\n  UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));\r\n  filePart = resultPath1.Length();\r\n  resultPath = resultPath1 + resultPath2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &path)\r\n{\r\n  path.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetTempPath(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)\r\n{\r\n  UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return number;\r\n}\r\n\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));\r\n    path.ReleaseBuffer();\r\n    return number;\r\n  }\r\n  CSysString sysPath;\r\n  UINT number = MyGetTempFileName(\r\n      dirPath ? (LPCTSTR)GetSysPath(dirPath): 0, \r\n      prefix ? (LPCTSTR)GetSysPath(prefix): 0, \r\n      sysPath);\r\n  path = GetUnicodePath(sysPath);\r\n  return number;\r\n}\r\n#endif\r\n\r\nUINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if(number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  CSysString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFile::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nUINT CTempFileW::Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if(number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFileW::Create(LPCWSTR prefix, UString &resultPath)\r\n{\r\n  UString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFileW::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFile tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!::DeleteFile(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if(NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectory::Create(LPCTSTR prefix)\r\n{ \r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir)); \r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateTempDirectory(LPCWSTR prefix, UString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFileW tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!DeleteFileAlways(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if(NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectoryW::Create(LPCWSTR prefix)\r\n{ \r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir)); \r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileDir.h",
    "content": "// Windows/FileDir.h\r\n\r\n#ifndef __WINDOWS_FILEDIR_H\r\n#define __WINDOWS_FILEDIR_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NDirectory {\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path);\r\nbool MyGetSystemDirectory(CSysString &path);\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path);\r\nbool MyGetSystemDirectory(UString &path);\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);\r\nbool MyRemoveDirectory(LPCTSTR pathName);\r\nbool MyCreateDirectory(LPCTSTR pathName);\r\nbool CreateComplexDirectory(LPCTSTR pathName);\r\nbool DeleteFileAlways(LPCTSTR name);\r\nbool RemoveDirectoryWithSubItems(const CSysString &path);\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);\r\nbool MyRemoveDirectory(LPCWSTR pathName);\r\nbool MyCreateDirectory(LPCWSTR pathName);\r\nbool CreateComplexDirectory(LPCWSTR pathName);\r\nbool DeleteFileAlways(LPCWSTR name);\r\nbool RemoveDirectoryWithSubItems(const UString &path);\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, \r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName);\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, \r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName);\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);\r\n#endif\r\n\r\ninline bool MySetCurrentDirectory(LPCTSTR path)\r\n  { return BOOLToBool(::SetCurrentDirectory(path)); }\r\nbool MyGetCurrentDirectory(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path);\r\nbool MyGetCurrentDirectory(UString &resultPath);\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, \r\n  CSysString &resultPath, UINT32 &filePart);\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, \r\n  UString &resultPath, UINT32 &filePart);\r\n#endif\r\n\r\ninline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, \r\n  CSysString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n\r\n#ifndef _UNICODE\r\ninline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, \r\n  UString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &resultPath);\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n#endif\r\n\r\nclass CTempFile\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _fileName;\r\npublic:\r\n  CTempFile(): _mustBeDeleted(false) {}\r\n  ~CTempFile() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n  bool Create(LPCTSTR prefix, CSysString &resultPath);\r\n  bool Remove();\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempFile CTempFileW;\r\n#else\r\nclass CTempFileW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _fileName;\r\npublic:\r\n  CTempFileW(): _mustBeDeleted(false) {}\r\n  ~CTempFileW() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n  bool Create(LPCWSTR prefix, UString &resultPath);\r\n  bool Remove();\r\n};\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);\r\n\r\nclass CTempDirectory\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _tempDir;\r\npublic:\r\n  const CSysString &GetPath() const { return _tempDir; }\r\n  CTempDirectory(): _mustBeDeleted(false) {}\r\n  ~CTempDirectory() { Remove();  }\r\n  bool Create(LPCTSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempDirectory CTempDirectoryW;\r\n#else\r\nclass CTempDirectoryW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _tempDir;\r\npublic:\r\n  const UString &GetPath() const { return _tempDir; }\r\n  CTempDirectoryW(): _mustBeDeleted(false) {}\r\n  ~CTempDirectoryW() { Remove();  }\r\n  bool Create(LPCWSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileFind.cpp",
    "content": "// Windows/FileFind.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileFind.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n\r\nnamespace NFind {\r\n\r\nstatic const TCHAR kDot = TEXT('.');\r\n\r\nbool CFileInfo::IsDots() const\r\n{ \r\n  if (!IsDirectory() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileInfoW::IsDots() const\r\n{ \r\n  if (!IsDirectory() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n#endif\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(\r\n    const WIN32_FIND_DATA &findData,\r\n    CFileInfo &fileInfo)\r\n{\r\n  fileInfo.Attributes = findData.dwFileAttributes; \r\n  fileInfo.CreationTime = findData.ftCreationTime;  \r\n  fileInfo.LastAccessTime = findData.ftLastAccessTime; \r\n  fileInfo.LastWriteTime = findData.ftLastWriteTime;\r\n  fileInfo.Size  = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow; \r\n  fileInfo.Name = findData.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fileInfo.ReparseTag = findData.dwReserved0;\r\n  #else\r\n  fileInfo.ObjectID = findData.dwOID;\r\n  #endif\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(\r\n    const WIN32_FIND_DATAW &findData,\r\n    CFileInfoW &fileInfo)\r\n{\r\n  fileInfo.Attributes = findData.dwFileAttributes; \r\n  fileInfo.CreationTime = findData.ftCreationTime;  \r\n  fileInfo.LastAccessTime = findData.ftLastAccessTime; \r\n  fileInfo.LastWriteTime = findData.ftLastWriteTime;\r\n  fileInfo.Size  = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow; \r\n  fileInfo.Name = findData.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fileInfo.ReparseTag = findData.dwReserved0;\r\n  #else\r\n  fileInfo.ObjectID = findData.dwOID;\r\n  #endif\r\n}\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(\r\n    const WIN32_FIND_DATA &findData,\r\n    CFileInfoW &fileInfo)\r\n{\r\n  fileInfo.Attributes = findData.dwFileAttributes; \r\n  fileInfo.CreationTime = findData.ftCreationTime;  \r\n  fileInfo.LastAccessTime = findData.ftLastAccessTime; \r\n  fileInfo.LastWriteTime = findData.ftLastWriteTime;\r\n  fileInfo.Size  = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow; \r\n  fileInfo.Name = GetUnicodeString(findData.cFileName, GetCurrentCodePage());\r\n  #ifndef _WIN32_WCE\r\n  fileInfo.ReparseTag = findData.dwReserved0;\r\n  #else\r\n  fileInfo.ObjectID = findData.dwOID;\r\n  #endif\r\n}\r\n#endif\r\n  \r\n////////////////////////////////\r\n// CFindFile\r\n\r\nbool CFindFile::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::FindClose(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\n          \r\nbool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  WIN32_FIND_DATA findData;\r\n  _handle = ::FindFirstFile(wildcard, &findData);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(wildcard, longPath))\r\n      _handle = ::FindFirstFileW(longPath, &findData);\r\n  }\r\n  #endif\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return false;\r\n  ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW findData;\r\n    _handle = ::FindFirstFileW(wildcard, &findData);\r\n    #ifdef WIN_LONG_PATH\r\n    if (_handle == INVALID_HANDLE_VALUE)\r\n    {\r\n      UString longPath;\r\n      if (GetLongPath(wildcard, longPath))\r\n        _handle = ::FindFirstFileW(longPath, &findData);\r\n    }\r\n    #endif\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA findData;\r\n    _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard, \r\n        GetCurrentCodePage()), &findData);\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFindFile::FindNext(CFileInfo &fileInfo)\r\n{\r\n  WIN32_FIND_DATA findData;\r\n  bool result = BOOLToBool(::FindNextFile(_handle, &findData));\r\n  if (result)\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  return result;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindNext(CFileInfoW &fileInfo)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW findData;\r\n    if (!::FindNextFileW(_handle, &findData))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA findData;\r\n    if (!::FindNextFileA(_handle, &findData))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n#endif\r\n\r\nbool DoesFileExist(LPCTSTR name)\r\n{\r\n  CFileInfo fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DoesFileExist(LPCWSTR name)\r\n{\r\n  CFileInfoW fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n#endif\r\n\r\n/////////////////////////////////////\r\n// CEnumerator\r\n\r\nbool CEnumerator::NextAny(CFileInfo &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CEnumeratorW::NextAny(CFileInfoW &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#endif\r\n\r\n////////////////////////////////\r\n// CFindChangeNotification\r\n// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.\r\n\r\nbool CFindChangeNotification::Close()\r\n{\r\n  if (!IsHandleAllocated())\r\n    return true;\r\n  if (!::FindCloseChangeNotification(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n           \r\nHANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  _handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n\r\n#ifndef _UNICODE\r\nHANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  if (!g_IsNT)\r\n    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);\r\n  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  UINT32 size = GetLogicalDriveStrings(0, NULL); \r\n  if (size == 0)\r\n    return false;\r\n  CSysString buffer;\r\n  UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size)); \r\n  if (newSize == 0)\r\n    return false;\r\n  if (newSize > size)\r\n    return false;\r\n  CSysString string;\r\n  for(UINT32 i = 0; i < newSize; i++)\r\n  {\r\n    TCHAR c = buffer[i];\r\n    if (c == TEXT('\\0'))\r\n    {\r\n      driveStrings.Add(string);\r\n      string.Empty();\r\n    }\r\n    else\r\n      string += c;\r\n  }\r\n  if (!string.IsEmpty())\r\n    return false;\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  if (g_IsNT)\r\n  {\r\n    UINT32 size = GetLogicalDriveStringsW(0, NULL); \r\n    if (size == 0)\r\n      return false;\r\n    UString buffer;\r\n    UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size)); \r\n    if (newSize == 0)\r\n      return false;\r\n    if (newSize > size)\r\n      return false;\r\n    UString string;\r\n    for(UINT32 i = 0; i < newSize; i++)\r\n    {\r\n      WCHAR c = buffer[i];\r\n      if (c == L'\\0')\r\n      {\r\n        driveStrings.Add(string);\r\n        string.Empty();\r\n      }\r\n      else\r\n        string += c;\r\n    }\r\n    return string.IsEmpty();\r\n  }\r\n  CSysStringVector driveStringsA;\r\n  bool res = MyGetLogicalDriveStrings(driveStringsA);\r\n  for (int i = 0; i < driveStringsA.Size(); i++)\r\n    driveStrings.Add(GetUnicodeString(driveStringsA[i]));\r\n  return res;\r\n}\r\n#endif\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileFind.h",
    "content": "// Windows/FileFind.h\r\n\r\n#ifndef __WINDOWS_FILEFIND_H\r\n#define __WINDOWS_FILEFIND_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"../Common/Types.h\"\r\n#include \"FileName.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NFind {\r\n\r\nnamespace NAttributes\r\n{\r\n  inline bool IsReadOnly(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_READONLY) != 0; }\r\n  inline bool IsHidden(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_HIDDEN) != 0; }\r\n  inline bool IsSystem(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_SYSTEM) != 0; }\r\n  inline bool IsDirectory(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }\r\n  inline bool IsArchived(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ARCHIVE) != 0; }\r\n  inline bool IsCompressed(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_COMPRESSED) != 0; }\r\n  inline bool IsEncrypted(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ENCRYPTED) != 0; }\r\n}\r\n\r\nclass CFileInfoBase\r\n{ \r\n  bool MatchesMask(UINT32 mask) const  { return ((Attributes & mask) != 0); }\r\npublic:\r\n  DWORD Attributes;\r\n  FILETIME CreationTime;  \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime;\r\n  UInt64 Size;\r\n  \r\n  #ifndef _WIN32_WCE\r\n  UINT32 ReparseTag;\r\n  #else\r\n  DWORD ObjectID; \r\n  #endif\r\n\r\n  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }\r\n  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }\r\n  bool IsDirectory() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }\r\n  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }\r\n  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }\r\n  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }\r\n  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }\r\n  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }\r\n  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }\r\n  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }\r\n  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }\r\n  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }\r\n};\r\n\r\nclass CFileInfo: public CFileInfoBase\r\n{ \r\npublic:\r\n  CSysString Name;\r\n  bool IsDots() const;\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CFileInfo CFileInfoW;\r\n#else\r\nclass CFileInfoW: public CFileInfoBase\r\n{ \r\npublic:\r\n  UString Name;\r\n  bool IsDots() const;\r\n};\r\n#endif\r\n\r\nclass CFindFile\r\n{\r\n  friend class CEnumerator;\r\n  HANDLE _handle;\r\npublic:\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }\r\n  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindFile() {  Close(); }\r\n  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n  bool FindNext(CFileInfo &fileInfo);\r\n  #ifndef _UNICODE\r\n  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\n  bool FindNext(CFileInfoW &fileInfo);\r\n  #endif\r\n  bool Close();\r\n};\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n\r\nbool DoesFileExist(LPCTSTR name);\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\nbool DoesFileExist(LPCWSTR name);\r\n#endif\r\n\r\nclass CEnumerator\r\n{\r\n  CFindFile _findFile;\r\n  CSysString _wildcard;\r\n  bool NextAny(CFileInfo &fileInfo);\r\npublic:\r\n  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfo &fileInfo);\r\n  bool Next(CFileInfo &fileInfo, bool &found);\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CEnumerator CEnumeratorW;\r\n#else\r\nclass CEnumeratorW\r\n{\r\n  CFindFile _findFile;\r\n  UString _wildcard;\r\n  bool NextAny(CFileInfoW &fileInfo);\r\npublic:\r\n  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfoW &fileInfo);\r\n  bool Next(CFileInfoW &fileInfo, bool &found);\r\n};\r\n#endif\r\n\r\nclass CFindChangeNotification\r\n{\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE () { return _handle; }\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }\r\n  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindChangeNotification() { Close(); }\r\n  bool Close();\r\n  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #ifndef _UNICODE\r\n  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #endif\r\n  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings);\r\n#endif\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifdef WIN_LONG_PATH\r\n#include \"../Common/MyString.h\"\r\n#endif\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR s, UString &res)\r\n{\r\n  res.Empty();\r\n  int len = MyStringLen(s);\r\n  wchar_t c = s[0];\r\n  if (len < 1 || c == L'\\\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))\r\n    return true;\r\n  UString curDir;\r\n  bool isAbs = false;\r\n  if (len > 3)\r\n    isAbs = (s[1] == L':' && s[2] == L'\\\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));\r\n\r\n  if (!isAbs)\r\n    {\r\n      DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));\r\n      curDir.ReleaseBuffer();\r\n      if (needLength == 0 || needLength > MAX_PATH)\r\n        return false;\r\n      if (curDir[curDir.Length() - 1] != L'\\\\')\r\n        curDir += L'\\\\';\r\n    }\r\n  res = UString(L\"\\\\\\\\?\\\\\") + curDir + s;\r\n  return true;\r\n}\r\n\r\nbool GetLongPath(LPCWSTR path, UString &longPath)\r\n{\r\n  if (GetLongPathBase(path, longPath)) \r\n    return !longPath.IsEmpty();\r\n  return false;\r\n}\r\n#endif\r\n\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode, \r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP), \r\n      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFileW(fileName, desiredAccess, shareMode, \r\n    (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n    flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode, \r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::CloseHandle(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if(sizeLow == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR) \r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if(!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CreationTime = winFileInfo.ftCreationTime;\r\n  fileInfo.LastAccessTime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.LastWriteTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes; \r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\n// Probably in some version of Windows there are problems with other sizes: \r\n// for 32 MB (maybe also for 16 MB). \r\n// And message can be \"Network connection was lost\"\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 22);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, creationTime, lastAccessTime, lastWriteTime)); }\r\n\r\nbool COutFile::SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {  return SetTime(NULL, NULL, lastWriteTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if(!Seek(length, newPosition))\r\n    return false;\r\n  if(newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{ \r\n  DWORD    Attributes; \r\n  FILETIME CreationTime; \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime; \r\n  DWORD    VolumeSerialNumber; \r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks; \r\n  UInt64   FileIndex; \r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _handle(INVALID_HANDLE_VALUE){};\r\n  ~CFileBase();\r\n\r\n  bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition); \r\n  bool SeekToBegin(); \r\n  bool SeekToEnd(UInt64 &newPosition); \r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileMapping.cpp",
    "content": "// Windows/FileMapping.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileMapping.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NMapping {\r\n\r\n\r\n\r\n\r\n}}}"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileMapping.h",
    "content": "// Windows/FileMapping.h\r\n\r\n#ifndef __WINDOWS_FILEMAPPING_H\r\n#define __WINDOWS_FILEMAPPING_H\r\n\r\n#include \"Windows/Handle.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\n// namespace NFile {\r\n// namespace NMapping {\r\n\r\nclass CFileMapping: public CHandle\r\n{\r\npublic:\r\n  bool Create(HANDLE file, LPSECURITY_ATTRIBUTES attributes,\r\n    DWORD protect, UINT64 maximumSize, LPCTSTR name)\r\n  {\r\n    _handle = ::CreateFileMapping(file, attributes,\r\n      protect, DWORD(maximumSize >> 32), DWORD(maximumSize), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenFileMapping(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  LPVOID MapViewOfFile(DWORD desiredAccess, UINT64 fileOffset, \r\n      SIZE_T numberOfBytesToMap)\r\n  {\r\n    return ::MapViewOfFile(_handle, desiredAccess, \r\n        DWORD(fileOffset >> 32), DWORD(fileOffset), numberOfBytesToMap);\r\n  }\r\n\r\n  LPVOID MapViewOfFileEx(DWORD desiredAccess, UINT64 fileOffset, \r\n      SIZE_T numberOfBytesToMap, LPVOID baseAddress)\r\n  {\r\n    return ::MapViewOfFileEx(_handle, desiredAccess, \r\n      DWORD(fileOffset >> 32), DWORD(fileOffset), \r\n      numberOfBytesToMap, baseAddress);\r\n  }\r\n  \r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileName.cpp",
    "content": "// Windows/FileName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)\r\n    dirPath += kDirDelimiter;\r\n}\r\n\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)\r\n    dirPath += wchar_t(kDirDelimiter);\r\n}\r\n#endif\r\n\r\n#ifdef _WIN32\r\n\r\nconst wchar_t kExtensionDelimiter = L'.';\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName, \r\n    UString &pureName, UString &extensionDelimiter, UString &extension)\r\n{\r\n  int index = fullName.ReverseFind(kExtensionDelimiter);\r\n  if (index < 0)\r\n  {\r\n    pureName = fullName;\r\n    extensionDelimiter.Empty();\r\n    extension.Empty();\r\n  }\r\n  else\r\n  {\r\n    pureName = fullName.Left(index);\r\n    extensionDelimiter = kExtensionDelimiter;\r\n    extension = fullName.Mid(index + 1);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/FileName.h",
    "content": "// Windows/FileName.h\r\n\r\n#ifndef __WINDOWS_FILENAME_H\r\n#define __WINDOWS_FILENAME_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nconst TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;\r\nconst TCHAR kAnyStringWildcard = '*';\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\\\'\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\\\'\r\n#endif\r\n\r\n#ifdef _WIN32\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName, \r\n    UString &pureName, UString &extensionDelimiter, UString &extension); \r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/Handle.h",
    "content": "// Windows/Handle.h\r\n\r\n#ifndef __WINDOWS_HANDLE_H\r\n#define __WINDOWS_HANDLE_H\r\n\r\nnamespace NWindows {\r\n\r\nclass CHandle\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE() { return _handle; }\r\n  CHandle(): _handle(NULL) {}\r\n  ~CHandle() { Close(); }\r\n  bool Close()\r\n  {\r\n    if (_handle == NULL)\r\n      return true;\r\n    if (!::CloseHandle(_handle))\r\n      return false;\r\n    _handle = NULL;\r\n    return true;\r\n  }\r\n  void Attach(HANDLE handle) \r\n    { _handle = handle; }\r\n  HANDLE Detach() \r\n  { \r\n    HANDLE handle = _handle;\r\n    _handle = NULL; \r\n    return handle;\r\n  }\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/MemoryLock.cpp",
    "content": "// Common/MemoryLock.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\n#ifndef _UNICODE\r\ntypedef BOOL (WINAPI * OpenProcessTokenP)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);\r\ntypedef BOOL (WINAPI * LookupPrivilegeValueP)(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID  lpLuid);\r\ntypedef BOOL (WINAPI * AdjustTokenPrivilegesP)(HANDLE TokenHandle, BOOL DisableAllPrivileges,\r\n    PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength);\r\n#endif\r\n\r\n#ifdef _UNICODE\r\nbool EnableLockMemoryPrivilege(\r\n#else\r\nstatic bool EnableLockMemoryPrivilege2(HMODULE hModule,\r\n#endif\r\nbool enable)\r\n{\r\n  #ifndef _UNICODE\r\n  if (hModule == NULL)\r\n    return false;\r\n  OpenProcessTokenP openProcessToken = (OpenProcessTokenP)GetProcAddress(hModule, \"OpenProcessToken\");\r\n  LookupPrivilegeValueP lookupPrivilegeValue = (LookupPrivilegeValueP)GetProcAddress(hModule, \"LookupPrivilegeValueA\" );\r\n  AdjustTokenPrivilegesP adjustTokenPrivileges = (AdjustTokenPrivilegesP)GetProcAddress(hModule, \"AdjustTokenPrivileges\");\r\n  if (openProcessToken == NULL || adjustTokenPrivileges == NULL || lookupPrivilegeValue == NULL)\r\n    return false;\r\n  #endif\r\n\r\n  HANDLE token;\r\n  if (!\r\n    #ifdef _UNICODE\r\n    ::OpenProcessToken\r\n    #else\r\n    openProcessToken\r\n    #endif\r\n    (::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))\r\n    return false;\r\n  TOKEN_PRIVILEGES tp;\r\n  bool res = false;\r\n  if (\r\n    #ifdef _UNICODE\r\n    ::LookupPrivilegeValue\r\n    #else\r\n    lookupPrivilegeValue\r\n    #endif\r\n    (NULL, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)))\r\n  {\r\n    tp.PrivilegeCount = 1;\r\n    tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED: 0;\r\n    if (\r\n      #ifdef _UNICODE\r\n      ::AdjustTokenPrivileges\r\n      #else\r\n      adjustTokenPrivileges\r\n      #endif\r\n      (token, FALSE, &tp, 0, NULL, NULL))\r\n      res = (GetLastError() == ERROR_SUCCESS);\r\n  }\r\n  ::CloseHandle(token);\r\n  return res;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool EnableLockMemoryPrivilege(bool enable)\r\n{\r\n  HMODULE hModule = LoadLibrary(TEXT(\"Advapi32.dll\"));\r\n  if(hModule == NULL)\r\n    return false;\r\n  bool res = EnableLockMemoryPrivilege2(hModule, enable);\r\n  ::FreeLibrary(hModule);\r\n  return res;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/MemoryLock.h",
    "content": "// Windows/MemoryLock.h\r\n\r\n#ifndef __WINDOWS_MEMORYLOCK_H\r\n#define __WINDOWS_MEMORYLOCK_H\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\nbool EnableLockMemoryPrivilege(bool enable = true);\r\n\r\n}}\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/PropVariant.cpp",
    "content": "// Windows/PropVariant.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariant.h\"\r\n\r\n#include \"../Common/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nCPropVariant::CPropVariant(const PROPVARIANT& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(const CPropVariant& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(BSTR bstrSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = bstrSrc;\r\n}\r\n\r\nCPropVariant::CPropVariant(LPCOLESTR lpszSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = lpszSrc;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const CPropVariant& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\nCPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(BSTR bstrSrc)\r\n{\r\n  *this = (LPCOLESTR)bstrSrc;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)\r\n{\r\n  InternalClear();\r\n  vt = VT_BSTR;\r\n  wReserved1 = 0;\r\n  bstrVal = ::SysAllocString(lpszSrc);\r\n  if (bstrVal == NULL && lpszSrc != NULL)\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = E_OUTOFMEMORY;\r\n  }\r\n  return *this;\r\n}\r\n\r\n\r\nCPropVariant& CPropVariant::operator=(bool bSrc)\r\n{\r\n  if (vt != VT_BOOL)\r\n  {\r\n    InternalClear();\r\n    vt = VT_BOOL;\r\n  }\r\n  boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt32 value)\r\n{\r\n  if (vt != VT_UI4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI4;\r\n  }\r\n  ulVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt64 value)\r\n{\r\n  if (vt != VT_UI8)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI8;\r\n  }\r\n  uhVal.QuadPart = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const FILETIME &value)\r\n{\r\n  if (vt != VT_FILETIME)\r\n  {\r\n    InternalClear();\r\n    vt = VT_FILETIME;\r\n  }\r\n  filetime = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int32 value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  \r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Byte value)\r\n{\r\n  if (vt != VT_UI1)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI1;\r\n  }\r\n  bVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int16 value)\r\n{\r\n  if (vt != VT_I2)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I2;\r\n  }\r\n  iVal = value;\r\n  return *this;\r\n}\r\n\r\n/*\r\nCPropVariant& CPropVariant::operator=(LONG value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  return *this;\r\n}\r\n*/\r\n\r\nstatic HRESULT MyPropVariantClear(PROPVARIANT *propVariant) \r\n{ \r\n  switch(propVariant->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      propVariant->vt = VT_EMPTY;\r\n      propVariant->wReserved1 = 0; \r\n      return S_OK;\r\n  }\r\n  return ::VariantClear((VARIANTARG *)propVariant); \r\n}\r\n\r\nHRESULT CPropVariant::Clear() \r\n{ \r\n  return MyPropVariantClear(this);\r\n}\r\n\r\nHRESULT CPropVariant::Copy(const PROPVARIANT* pSrc) \r\n{ \r\n  ::VariantClear((tagVARIANT *)this); \r\n  switch(pSrc->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));\r\n      return S_OK;\r\n  }\r\n  return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc)); \r\n}\r\n\r\n\r\nHRESULT CPropVariant::Attach(PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(this, pSrc, sizeof(PROPVARIANT));\r\n  pSrc->vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::Detach(PROPVARIANT* pDest)\r\n{\r\n  HRESULT hr = MyPropVariantClear(pDest);\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(pDest, this, sizeof(PROPVARIANT));\r\n  vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::InternalClear()\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n  return hr;\r\n}\r\n\r\nvoid CPropVariant::InternalCopy(const PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Copy(pSrc);\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n}\r\n\r\nint CPropVariant::Compare(const CPropVariant &a)\r\n{\r\n  if(vt != a.vt)\r\n    return 0; // it's mean some bug\r\n  switch (vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return 0;\r\n    \r\n    /*\r\n    case VT_I1:\r\n      return MyCompare(cVal, a.cVal);\r\n    */\r\n    case VT_UI1:\r\n      return MyCompare(bVal, a.bVal);\r\n\r\n    case VT_I2:\r\n      return MyCompare(iVal, a.iVal);\r\n    case VT_UI2:\r\n      return MyCompare(uiVal, a.uiVal);\r\n    \r\n    case VT_I4:\r\n      return MyCompare(lVal, a.lVal);\r\n    /*\r\n    case VT_INT:\r\n      return MyCompare(intVal, a.intVal);\r\n    */\r\n    case VT_UI4:\r\n      return MyCompare(ulVal, a.ulVal);\r\n    /*\r\n    case VT_UINT:\r\n      return MyCompare(uintVal, a.uintVal);\r\n    */\r\n    case VT_I8:\r\n      return MyCompare(hVal.QuadPart, a.hVal.QuadPart);\r\n    case VT_UI8:\r\n      return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);\r\n\r\n    case VT_BOOL:    \r\n      return -MyCompare(boolVal, a.boolVal);\r\n\r\n    case VT_FILETIME:\r\n      return ::CompareFileTime(&filetime, &a.filetime);\r\n    case VT_BSTR:\r\n      return 0; // Not implemented \r\n      // return MyCompare(aPropVarint.cVal);\r\n\r\n    default:\r\n      return 0;\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/PropVariant.h",
    "content": "// Windows/PropVariant.h\r\n\r\n#ifndef __WINDOWS_PROPVARIANT_H\r\n#define __WINDOWS_PROPVARIANT_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nclass CPropVariant : public tagPROPVARIANT\r\n{\r\npublic:\r\n  CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }\r\n  ~CPropVariant() { Clear(); }\r\n  CPropVariant(const PROPVARIANT& varSrc);\r\n  CPropVariant(const CPropVariant& varSrc);\r\n  CPropVariant(BSTR bstrSrc);\r\n  CPropVariant(LPCOLESTR lpszSrc);\r\n  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };\r\n  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }\r\n  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal = *(ULARGE_INTEGER*)&value; }\r\n  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }\r\n  CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }\r\n  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }\r\n  CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }\r\n  // CPropVariant(LONG value, VARTYPE vtSrc = VT_I4) { vt = vtSrc; lVal = value; }\r\n\r\n  CPropVariant& operator=(const CPropVariant& varSrc);\r\n  CPropVariant& operator=(const PROPVARIANT& varSrc);\r\n  CPropVariant& operator=(BSTR bstrSrc);\r\n  CPropVariant& operator=(LPCOLESTR lpszSrc);\r\n  CPropVariant& operator=(bool bSrc);\r\n  CPropVariant& operator=(UInt32 value);\r\n  CPropVariant& operator=(UInt64 value);\r\n  CPropVariant& operator=(const FILETIME &value);\r\n\r\n  CPropVariant& operator=(Int32 value);\r\n  CPropVariant& operator=(Byte value);\r\n  CPropVariant& operator=(Int16 value);\r\n  // CPropVariant& operator=(LONG  value);\r\n\r\n  HRESULT Clear();\r\n  HRESULT Copy(const PROPVARIANT* pSrc);\r\n  HRESULT Attach(PROPVARIANT* pSrc);\r\n  HRESULT Detach(PROPVARIANT* pDest);\r\n\r\n  HRESULT InternalClear();\r\n  void InternalCopy(const PROPVARIANT* pSrc);\r\n\r\n  int Compare(const CPropVariant &a1);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/PropVariantConversions.cpp",
    "content": "// PropVariantConversions.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <stdio.h>\r\n\r\n#include \"PropVariantConversions.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\nstatic UString ConvertUInt64ToString(UInt64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString ConvertInt64ToString(Int64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic char *UIntToStringSpec(UInt32 value, char *s, int numPos)\r\n{\r\n  char temp[16];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    temp[pos++] = (char)('0' + value % 10);\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  int i;\r\n  for (i = 0; i < numPos - pos; i++)\r\n    *s++ = '0';\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n  return s;\r\n}\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)\r\n{\r\n  s[0] = '\\0';\r\n  SYSTEMTIME st;\r\n  if(!BOOLToBool(FileTimeToSystemTime(&ft, &st)))\r\n    return false;\r\n  s = UIntToStringSpec(st.wYear, s, 4);\r\n  *s++ = '-';\r\n  s = UIntToStringSpec(st.wMonth, s, 2);\r\n  *s++ = '-';\r\n  s = UIntToStringSpec(st.wDay, s, 2);\r\n  if (includeTime)\r\n  {\r\n    *s++ = ' ';\r\n    s = UIntToStringSpec(st.wHour, s, 2);\r\n    *s++ = ':';\r\n    s = UIntToStringSpec(st.wMinute, s, 2);\r\n    if (includeSeconds)\r\n    {\r\n      *s++ = ':';\r\n      UIntToStringSpec(st.wSecond, s, 2);\r\n    }\r\n  }\r\n  /*\r\n  sprintf(s, \"%04d-%02d-%02d\", st.wYear, st.wMonth, st.wDay);\r\n  if (includeTime)\r\n  {\r\n    sprintf(s + strlen(s), \" %02d:%02d\", st.wHour, st.wMinute);\r\n    if (includeSeconds)\r\n      sprintf(s + strlen(s), \":%02d\", st.wSecond);\r\n  }\r\n  */\r\n  return true;\r\n}\r\n\r\nUString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds)\r\n{\r\n  char s[32];\r\n  ConvertFileTimeToString(fileTime, s,  includeTime, includeSeconds);\r\n  return GetUnicodeString(s);\r\n}\r\n \r\n\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant)\r\n{\r\n  switch (propVariant.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return UString();\r\n    case VT_BSTR:\r\n      return propVariant.bstrVal;\r\n    case VT_UI1:\r\n      return ConvertUInt64ToString(propVariant.bVal);\r\n    case VT_UI2:\r\n      return ConvertUInt64ToString(propVariant.uiVal);\r\n    case VT_UI4:\r\n      return ConvertUInt64ToString(propVariant.ulVal);\r\n    case VT_UI8:\r\n      return ConvertUInt64ToString(propVariant.uhVal.QuadPart);\r\n    case VT_FILETIME:\r\n      return ConvertFileTimeToString(propVariant.filetime, true, true);\r\n    /*\r\n    case VT_I1:\r\n      return ConvertInt64ToString(propVariant.cVal);\r\n    */\r\n    case VT_I2:\r\n      return ConvertInt64ToString(propVariant.iVal);\r\n    case VT_I4:\r\n      return ConvertInt64ToString(propVariant.lVal);\r\n    case VT_I8:\r\n      return ConvertInt64ToString(propVariant.hVal.QuadPart);\r\n\r\n    case VT_BOOL:\r\n      return VARIANT_BOOLToBool(propVariant.boolVal) ? L\"+\" : L\"-\";\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 150245;\r\n      #else\r\n      return UString();\r\n      #endif\r\n  }\r\n}\r\n\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant)\r\n{\r\n  switch (propVariant.vt)\r\n  {\r\n    case VT_UI1:\r\n      return propVariant.bVal;\r\n    case VT_UI2:\r\n      return propVariant.uiVal;\r\n    case VT_UI4:\r\n      return propVariant.ulVal;\r\n    case VT_UI8:\r\n      return (UInt64)propVariant.uhVal.QuadPart;\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 151199;\r\n      #else\r\n      return 0;\r\n      #endif\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/PropVariantConversions.h",
    "content": "// Windows/PropVariantConversions.h\r\n\r\n#ifndef __PROPVARIANTCONVERSIONS_H\r\n#define __PROPVARIANTCONVERSIONS_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/MyString.h\"\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant);\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/Synchronization.cpp",
    "content": "// Windows/Synchronization.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Synchronization.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/Synchronization.h",
    "content": "// Windows/Synchronization.h\r\n\r\n#ifndef __WINDOWS_SYNCHRONIZATION_H\r\n#define __WINDOWS_SYNCHRONIZATION_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\n#ifdef _WIN32\r\n#include \"Handle.h\"\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\nclass CBaseEvent\r\n{\r\nprotected:\r\n  ::CEvent _object;\r\npublic:\r\n  bool IsCreated() { return Event_IsCreated(&_object) != 0; }\r\n  operator HANDLE() { return _object.handle; }\r\n  CBaseEvent() { Event_Construct(&_object); }\r\n  ~CBaseEvent() { Close(); }\r\n  HRes Close() { return Event_Close(&_object); }\r\n  #ifdef _WIN32\r\n  HRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),\r\n        BoolToBOOL(initiallyOwn), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  #endif\r\n\r\n  HRes Set() { return Event_Set(&_object); }\r\n  // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }\r\n  HRes Reset() { return Event_Reset(&_object); }\r\n  HRes Lock() { return Event_Wait(&_object); }\r\n};\r\n\r\nclass CManualResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  HRes Create(bool initiallyOwn = false)\r\n  {\r\n    return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);\r\n  }\r\n  HRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return ManualResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  #ifdef _WIN32\r\n  HRes CreateWithName(bool initiallyOwn, LPCTSTR name)\r\n  {\r\n    return CBaseEvent::Create(true, initiallyOwn, name);\r\n  }\r\n  #endif\r\n};\r\n\r\nclass CAutoResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  HRes Create()\r\n  {\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  HRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\nclass CObject: public CHandle\r\n{\r\npublic:\r\n  HRes Lock(DWORD timeoutInterval = INFINITE)\r\n    { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }\r\n};\r\nclass CMutex: public CObject\r\n{\r\npublic:\r\n  HRes Create(bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  HRes Release() \r\n  { \r\n    return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();\r\n  }\r\n};\r\nclass CMutexLock\r\n{\r\n  CMutex *_object;\r\npublic:\r\n  CMutexLock(CMutex &object): _object(&object) { _object->Lock(); } \r\n  ~CMutexLock() { _object->Release(); }\r\n};\r\n#endif\r\n\r\nclass CSemaphore\r\n{\r\n  ::CSemaphore _object;\r\npublic:\r\n  CSemaphore() { Semaphore_Construct(&_object); }\r\n  ~CSemaphore() { Close(); }\r\n  HRes Close() {  return Semaphore_Close(&_object); }\r\n  operator HANDLE() { return _object.handle; }\r\n  HRes Create(UInt32 initiallyCount, UInt32 maxCount)\r\n  {\r\n    return Semaphore_Create(&_object, initiallyCount, maxCount);\r\n  }\r\n  HRes Release() { return Semaphore_Release1(&_object); }\r\n  HRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }\r\n  HRes Lock() { return Semaphore_Wait(&_object); }\r\n};\r\n\r\nclass CCriticalSection\r\n{\r\n  ::CCriticalSection _object;\r\npublic:\r\n  CCriticalSection() { CriticalSection_Init(&_object); }\r\n  ~CCriticalSection() { CriticalSection_Delete(&_object); }\r\n  void Enter() { CriticalSection_Enter(&_object); }\r\n  void Leave() { CriticalSection_Leave(&_object); }\r\n};\r\n\r\nclass CCriticalSectionLock\r\n{\r\n  CCriticalSection *_object;\r\n  void Unlock()  { _object->Leave(); }\r\npublic:\r\n  CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); } \r\n  ~CCriticalSectionLock() { Unlock(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/System.cpp",
    "content": "// Windows/System.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"System.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors()\r\n{\r\n  SYSTEM_INFO systemInfo;\r\n  GetSystemInfo(&systemInfo);\r\n  return (UInt32)systemInfo.dwNumberOfProcessors;\r\n}\r\n\r\n#if !defined(_WIN64) && defined(__GNUC__)\r\n\r\ntypedef struct _MY_MEMORYSTATUSEX {\r\n  DWORD dwLength;\r\n  DWORD dwMemoryLoad;\r\n  DWORDLONG ullTotalPhys;\r\n  DWORDLONG ullAvailPhys;\r\n  DWORDLONG ullTotalPageFile;\r\n  DWORDLONG ullAvailPageFile;\r\n  DWORDLONG ullTotalVirtual;\r\n  DWORDLONG ullAvailVirtual;\r\n  DWORDLONG ullAvailExtendedVirtual;\r\n} MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX;\r\n\r\n#else\r\n\r\n#define MY_MEMORYSTATUSEX MEMORYSTATUSEX\r\n#define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX\r\n\r\n#endif\r\n\r\ntypedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);\r\n\r\nUInt64 GetRamSize()\r\n{\r\n  MY_MEMORYSTATUSEX stat;\r\n  stat.dwLength = sizeof(stat);\r\n  #ifdef _WIN64\r\n  if (!::GlobalMemoryStatusEx(&stat))\r\n    return 0;\r\n  return stat.ullTotalPhys;\r\n  #else\r\n  GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")),\r\n        \"GlobalMemoryStatusEx\");\r\n  if (globalMemoryStatusEx != 0)\r\n    if (globalMemoryStatusEx(&stat))\r\n      return stat.ullTotalPhys;\r\n  {\r\n    MEMORYSTATUS stat;\r\n    stat.dwLength = sizeof(stat);\r\n    GlobalMemoryStatus(&stat);\r\n    return stat.dwTotalPhys;\r\n  }\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/System.h",
    "content": "// Windows/System.h\r\n\r\n#ifndef __WINDOWS_SYSTEM_H\r\n#define __WINDOWS_SYSTEM_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors();\r\nUInt64 GetRamSize();\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/Thread.h",
    "content": "// Windows/Thread.h\r\n\r\n#ifndef __WINDOWS_THREAD_H\r\n#define __WINDOWS_THREAD_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\nnamespace NWindows {\r\n\r\nclass CThread\r\n{\r\n  ::CThread thread;\r\npublic:\r\n  CThread() { Thread_Construct(&thread); }\r\n  ~CThread() { Close(); }\r\n  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }\r\n  HRes Close()  { return Thread_Close(&thread); }\r\n  HRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n    { return Thread_Create(&thread, startAddress, parameter); }\r\n  HRes Wait() { return Thread_Wait(&thread); }\r\n  \r\n  #ifdef _WIN32\r\n  DWORD Resume() { return ::ResumeThread(thread.handle); }\r\n  DWORD Suspend() { return ::SuspendThread(thread.handle); }\r\n  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }\r\n  int GetPriority() { return ::GetThreadPriority(thread.handle); }\r\n  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }\r\n  #endif\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/CPP/Windows/Time.h",
    "content": "// Windows/Time.h\r\n\r\n#ifndef __WINDOWS_TIME_H\r\n#define __WINDOWS_TIME_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\ninline bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)\r\n{\r\n  return BOOLToBool(::DosDateTimeToFileTime(UInt16(dosTime >> 16), \r\n      UInt16(dosTime & 0xFFFF), &fileTime));\r\n}\r\n\r\nconst UInt32 kHighDosTime = 0xFF9FBF7D;\r\nconst UInt32 kLowDosTime = 0x210000;\r\n\r\ninline bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)\r\n{\r\n  WORD datePart, timePart;\r\n  if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))\r\n  {\r\n    if (fileTime.dwHighDateTime >= 0x01C00000) // 2000\r\n      dosTime = kHighDosTime;\r\n    else\r\n      dosTime = kLowDosTime;\r\n    return false;\r\n  }\r\n  dosTime = (((UInt32)datePart) << 16) + timePart;\r\n  return true;\r\n}\r\n\r\nconst UInt32 kNumTimeQuantumsInSecond = 10000000;\r\nconst UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;\r\n\r\ninline void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)\r\n{\r\n  UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;\r\n  fileTime.dwLowDateTime = (DWORD)v;\r\n  fileTime.dwHighDateTime = (DWORD)(v >> 32);\r\n}\r\n\r\ninline bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)\r\n{\r\n  UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;\r\n  if (winTime < kUnixTimeStartValue)\r\n  {\r\n    unixTime = 0;\r\n    return false;\r\n  }\r\n  winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;\r\n  if (winTime > 0xFFFFFFFF)\r\n  {\r\n    unixTime = 0xFFFFFFFF;\r\n    return false;\r\n  }\r\n  unixTime = (UInt32)winTime;\r\n  return true;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/Makefile",
    "content": "\n# Copyright (C) 2006, 2007 Junjiro Okajima\n# Copyright (C) 2006, 2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described ones in lzma and squashfs.\n\n# $Id: Makefile,v 1.2 2007-10-26 07:25:05 steven Exp $\n\n# paths\nSqlzma = ${CURDIR}\n#LzmaVer = lzma443\nLzmaVer = \nLzma = ${Sqlzma}/${LzmaVer}\nSqVer = squashfs3.2-r2\nSquashfs = ${Sqlzma}/${SqVer}\n\n#LzmaC = ${Lzma}/C/7zip/Compress/LZMA_C\n#LzmaAlone = ${Lzma}/C/7zip/Compress/LZMA_Alone\nLzmaC = ${Lzma}/C/Compress/Lzma\nLzmaAlone = ${Lzma}/CPP/7zip/Compress/LZMA_Alone\nSqTools = ${Squashfs}/squashfs-tools\n\n# enable it if you want to add -g option when compiling\nUseDebugFlags =\n# disable it if you don't want to compile squashfs kernel module here\nBuildSquashfs = 1\n\nexport\n\nall:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\nclean:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\t${RM} *~\n\ninstall:\n\t#cp squashfs3.2-r2/squashfs-tools/mksquashfs /opt/buildroot-gdb/bin/mksquashfs_lzma-3.2\n\tcp squashfs3.2-r2/squashfs-tools/mksquashfs ../../source/vendors/Ralink/RT2880/mksquashfs_lzma-3.2\n \n########################################\n\n\n\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/sqlzma.h",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.\n */\n\n/* $Id: sqlzma.h,v 1.20 2008-03-12 16:58:34 jro Exp $ */\n\n#ifndef __sqlzma_h__\n#define __sqlzma_h__\n\n#ifndef __KERNEL__\n#include <stdlib.h>\n#include <string.h>\n#include <zlib.h>\n#ifdef _REENTRANT\n#include <pthread.h>\n#endif\n#else\n#include <linux/zlib.h>\n#endif\n#define _7ZIP_BYTE_DEFINED\n\n/*\n * detect the compression method automatically by the first byte of compressed\n * data.\n * according to rfc1950, the first byte of zlib compression must be 0x?8.\n */\n#define is_lzma(c)\t(c == 0x5d)\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#ifndef __KERNEL__\n/* for mksquashfs only */\nstruct sqlzma_opts {\n\tunsigned int\ttry_lzma;\n\tunsigned int \tdicsize;\n};\nint sqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in,\n\t      uInt avail_in, Bytef *next_out, uInt avail_out);\n#endif\n\n/* ---------------------------------------------------------------------- */\n/*\n * Three patterns for sqlzma uncompression. very dirty code.\n * - kernel space (squashfs kernel module)\n * - user space with pthread (mksquashfs)\n * - user space without pthread (unsquashfs)\n */\n\nstruct sized_buf {\n\tunsigned int\tsz;\n\tunsigned char\t*buf;\n};\n\nenum {SQUN_PROB, SQUN_RESULT, SQUN_LAST};\nstruct sqlzma_un {\n\tint\t\t\tun_lzma;\n\tstruct sized_buf\tun_a[SQUN_LAST];\n\tunsigned char           un_prob[31960]; /* unlzma 64KB - 1MB */\n\tz_stream\t\tun_stream;\n#define un_cmbuf\tun_stream.next_in\n#define un_cmlen\tun_stream.avail_in\n#define un_resbuf\tun_stream.next_out\n#define un_resroom\tun_stream.avail_out\n#define un_reslen\tun_stream.total_out\n};\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz);\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst);\nvoid sqlzma_fin(struct sqlzma_un *un);\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\n};\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/sqmagic.h",
    "content": "/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE must follow the one in squashfs.\n */\n\n/* $Id: sqmagic.h,v 1.1.1.1 2007-06-05 09:36:21 steven Exp $ */\n\n#ifndef __sqmagic_h__\n#define __sqmagic_h__\n\n/* see SQUASHFS_MAGIC in squashfs_fs.h */\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/ACKNOWLEDGEMENTS",
    "content": "\t\t\tACKNOWLEDGEMENTS\n\nThanks to everyone who have download squashfs.  I appreciate people\nusing it, and any feedback you have.\n\nThe following have provided useful feedback, which has guided\nsome of the extra features in squashfs.  This is a randomly ordered\n(roughly in chronological order) list, which is updated when\nI remember...\n\nAcknowledgements for Squashfs-3.2-r2\n------------------------------------\n\nJunjiro Okajima discovered a couple of SMP issues, thanks.\n\nJunjiro Okajima and Tomas Matejicek have produced some good LZMA patches\nfor Squashfs.\n\nAcknowledgements for Squashfs-3.2\n---------------------------------\n\nPeter Korsgaard sent a patch updating Squashfs to changes in the VFS interface\nin Linux 2.6.20.\n\nAcknowledgements for Squashfs-3.1\n---------------------------------\n\nKenneth Duda and Ed Swierk of Arastra Inc. identified numerous bugs with\nSquashfs, and provided patches which were the basis for some of the\nfixes.  In particular they identified the fragment rounding bug, the\nNFS bug, the initrd bug, and helped identify the 4K stack overflow bug.\n\nScott James Remnant (Ubuntu) also identified the fragment rounding bug,\nand he also provided a patch.\n\nMing Zhang identified the Lseek bug in Mksquashfs.  His tests on the\nperformance of Mksquashfs on SMP systems encouraged the rewrite of\nMksquashfs.\n\nPeter Korsgaard, Daniel Olivera and Zilvinas Valinskas noticed\nSquashfs 3.0 didn't compile on Linux-2.6.18-rc[1-4] due to changes\nin the Linux VFS interfaces, and provided patches.\n\nTomas Matejicek (SLAX) suggested the -force option on Unsquashfs, and noticed\nUnsquashfs didn't return the correct exit status.\n\nYann Le Doare reported a kernel oops and provided a Qemu image that led\nto the identification of the simultaneously accessing multiply mounted Squashfs\nfilesystems bug.\n\n\nOlder acknowledgements\n----------------------\n\nMark Robson - pointed out early on that initrds didn't work\n\nAdam Warner - pointed out that greater than 2GB filesystems didn't work.\n\nJohn Sutton - raised the problem when archiving the entire filesystem\n(/) there was no way to prevent /proc being archived.  This prompted\nexclude files.\n\nMartin Mueller (LinuxTV) - noticed that the filesystem length in the\nsuperblock doesn't match the output filesystem length.  This is due to\npadding to a 4K boundary.  This prompted the addition of the -nopad option.\nHe also reported a problem where 32K block filesystems hung when used as\ninitrds.\n\nArkadiusz Patyk (Polish Linux Distribution - PLD) reported a problem where 32K\nblock filesystems hung when used as a root filesystem mounted as a loopback\ndevice.\n\nJoe Blow emailed me that I'd forgotten to put anything in the README about\nmounting the squashfs filesystem.\n\nDavid Fox (Lindows) noticed that the exit codes returned by Mksquashfs were\nwrong.  He also noticed that a lot of time was spent in the duplicate scan\nroutine.\n\nCameron Rich complained that Squashfs did not support FIFOs or sockets.\n\nSteve Chadsey and Thomas Weissmuller noticed that files larger than the\navailable memory could not be compressed by Mksquashfs.\n\n\"Ptwahyu\" and \"Hoan\" (I have no full names and I don't like giving people's\nemail addresses), noticed that Mksquashfs 1.3 SEGV'd occasionally.  Even though\nI had already noticed this bug, it is useful to be informed by other people.\n\nDon Elwell, Murray Jensen and Cameron Rich, have all sent in patches.  Thanks,\nI have not had time to do anything about them yet...\n\nDrew Scott Daniels has been a good advocate for Squashfs.\n\nErik Andersen has made some nice suggestions, unfortunately, I have\nnot had time to implement anything.\n\nArtemiy I. Pavlov has written a useful LDP mini-howto for Squashfs\n(http://linuxdoc.artemio.net/squashfs).\n\nYves Combe reported the Apple G5 bug, when using Squashfs for\nhis PPC Knoppix-mib livecd project.\n\nJaco Greeff (mklivecd project, and maintainer of the Mandrake\nsquashfs-tools package) suggested the new mksquashfs -ef option, and the\nstandalone build for mksquashfs.\n\nMike Schaudies made a donation.\n\nArkadiusz Patyk from the Polish Linux Distribution reported that Squashfs\ndidn't work on amd64 machines. He gave me an account on a PLD amd64 machine\nwhich allowed myself to track down these bugs.\n\nMiles Roper, Peter Kjellerstedt and Willy Tarreau reported that release 2.1 did\nnot compile with gcc < 3.x.\n\nMarcel J.E. Mol reported lack of kernel memory issues when using Squashfs\non small memory embedded systems.  This prompted the addition of the embedded\nsystem kernel configuration options.\n\nEra Scarecrow noticed that Mksquashfs had not been updated to reflect that\nsmaller than 4K blocks are no longer supported.\n\nKenichi Shima reported the Kconfig file had not been updated to 2.2.\n\nAaron Ten Clay made a donation!\n\nTomas Matejicek (SLAX) made a donation!\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/CHANGES",
    "content": "\t\t\tSQUASHFS CHANGE LOG\n\n3.2-r2\t15 JAN 2007\tKernel patch update and progress bar bug fix\n\n\t1. Kernel patches 2.6.19/2.6.20 have been updated to use\n\t   const structures and mutexes rather than older semaphores.\n\t2. Minor SMP bug fixes.\n\t3. Progress bar broken on x86-64.  Fixed.\n\n3.2\t2 JAN 2007\tNFS support, improvements to the Squashfs-tools, major\n\t\t\tbug fixes, lots of small improvements/bug fixes, and new\n\t\t\tkernel patches.\n\n\tImprovements:\n\n\t1. Squashfs filesystems can now be exported via NFS.\n\t2. Unsquashfs now supports 2.x filesystems.\n\t3. Mksquashfs now displays a progress bar.\n\t4. Squashfs kernel code has been hardened against accidently or\n\t   maliciously corrupted Squashfs filesystems.\n\n\tBug fixes:\n\n\t5. Race condition occurring on S390 in readpage() fixed.\n\t6. Odd behaviour of MIPS memcpy in read_data() routine worked-around.\n\t7. Missing cache_flush in Squashfs symlink_readpage() added.\n\t\n\n3.1-r2\t30 AUG 2006\tMksquashfs -sort bug fix\n\n\t\t\tA code optimisation after testing unfortunately\n\t\t\tbroke sorting in Mksquashfs.  This has been fixed.\n\n3.1\t19 AUG 2006\tThis release has some major improvements to\n\t\t\tthe squashfs-tools, a couple of major bug\n\t\t\tfixes, lots of small improvements/bug fixes,\n\t\t\tand new kernel patches.\n\n\t\t\t\n\t1. Mksquashfs has been rewritten to be multi-threaded.  It\n\t   has the following improvements\n\n\t   1.1. Parallel compression.  By default as many compression and\n\t\tfragment compression threads are created as there are available\n\t\tprocessors.  This significantly speeds up performance on SMP\n\t\tsystems.\n\t   1.2. File input and filesystem output is peformed in parallel on\n\t\tseparate threads to maximise I/O performance.  Even on single\n\t\tprocessor systems this speeds up performance by at least 10%.\n\t   1.3. Appending has been significantly improved, and files within the\n\t\tfilesystem being appended to are no longer scanned and\n\t\tchecksummed.  This significantly improves append time for large\n\t\tfilesystems.\n\t   1.4. File duplicate checking has been optimised, and split into two\n\t\tseparate phases.  Only files which are considered possible\n\t\tduplicates after the first phase are checksummed and cached in\n\t\tmemory.\n\t   1.5\tThe use of swap memory was found to significantly impact\n\t\tperformance. The amount of memory used to cache files is now a\n\t\tcommand line option, by default this is 512 Mbytes.\n \n\t2. Unsquashfs has the following improvements\n\n\t   2.1  Unsquashfs now allows you to specify the filename or the\n\t\tdirectory within the Squashfs filesystem that is to be\n\t\textracted, rather than always extracting the entire filesystem.\n\t   2.2  A new -force option has been added which forces Unsquashfs to\n\t\toutput to the destination directory even if files and directories\n\t\talready exist in the destination directory.  This allows you to\n\t\tupdate an already existing directory tree, or to Unsquashfs to\n\t\ta partially filled directory tree.  Without the -force option\n\t\tUnsquashfs will refuse to output.\n\n\t3.  The following major bug fixes have been made\n\n\t  3.1  \tA fragment table rounding bug has been fixed in Mksquashfs.\n\t\tPreviously if the number of fragments in the filesystem\n\t\twere a multiple of 512, Mksquashfs would generate an\n\t\tincorrect filesystem.\n\t  3.2  \tA rare SMP bug which occurred when simultaneously acccessing\n\t\tmultiply mounted Squashfs filesystems has been fixed.\n\n\t4. Miscellaneous improvements/bug fixes\n\n\t  4.1\tKernel code stack usage has been reduced.  This is to ensure\n\t\tSquashfs works with 4K stacks.\n\t  4.2   Readdir (Squashfs kernel code) has been fixed to always\n\t\treturn 0, rather than the number of directories read.  Squashfs\n\t\tshould now interact better with NFS.\n\t  4.3\tLseek bug in Mksquashfs when appending to larger than 4GB\n\t\tfilesystems fixed.\n\t  4.4\tSquashfs 2.x initrds can now been mounted.\n\t  4.5\tUnsquashfs exit status fixed.\n\t  4.6\tNew patches for linux-2.6.18 and linux-2.4.33.\n\n\t\n3.0\t15 MAR 2006\tMajor filesystem improvements\n\n\t1. Filesystems are no longer limited to 4 GB.  In\n\t   theory 2^64 or 4 exabytes is now supported.\n\t2. Files are no longer limited to 4 GB.  In theory the maximum\n\t   file size is 4 exabytes.\n\t3. Metadata (inode table and directory tables) are no longer\n\t   restricted to 16 Mbytes.\n\t4. Hardlinks are now suppported.\n\t5. Nlink counts are now supported.\n\t6. Readdir now returns '.' and '..' entries.\n\t7. Special support for files larger than 256 MB has been added to\n\t   the Squashfs kernel code for faster read access.\n\t8. Inode numbers are now stored within the inode rather than being\n\t   computed from inode location on disk (this is not so much an\n\t   improvement, but a change forced by the previously listed\n\t   improvements).\n\n2.2-r2\t8 SEPT 2005\tSecond release of 2.2, this release fixes a couple\n\t\t\tof small bugs, a couple of small documentation\n\t\t\tmistakes, and adds a patch for kernel 2.6.13. \n\n\t1. Mksquashfs now deletes the output filesystem image file if an\n\t   error occurs whilst generating the filesystem.  Previously on\n\t   error the image file was left empty or partially written.\n\t2. Updated mksquashfs so that it doesn't allow you to generate\n\t   filesystems with block sizes smaller than 4K.  Squashfs hasn't\n\t   supported block sizes less than 4K since 2.0-alpha.\n\t3. Mksquashfs now ignores missing files/directories in sort files.\n\t   This was the original behaviour before 2.2.\n\t4. Fixed small mistake in fs/Kconfig where the version was still\n\t   listed as 2.0.\n\t5. Updated ACKNOWLEDGEMENTS file.\n\n\n2.2\t3 JUL 2005\tThis release has some small improvements, bug fixes\n\t\t\tand patches for new kernels.\n\n\t1. Sort routine re-worked and debugged from release 2.1.  It now allows\n\t   you to give Mkisofs style sort files and checks for filenames that\n\t   don't match anything.  Sort priority has also been changed to\n\t   conform to Mkisofs usage, highest priority files are now placed\n\t   at the start of the filesystem (this means they will be on the\n\t   inside of a CD or DVD).\n\t2. New Configure options for embedded systems (memory constrained\n\t   systems).  See INSTALL file for further details.\n\t3. Directory index bug fixed where chars were treated as signed on\n           some architectures.  A file would not be found in the rare case\n\t   that the filename started with a chracter greater than 127.\n\t4. Bug introduced into the read_data() routine when sped up to use data\n\t   block queueing fixed.  If the second or later block resulted in an\n\t   I/O error this was not checked.\n\t5. Append bug introduced in 2.1 fixed.  The code to compute the new\n\t   compressed and uncompressed directory parts after appending was\n\t   wrong.\n\t6. Metadata block length read routine altered to not perform a\n\t   misaligned short read.  This was to fix reading on an ARM7 running\n\t   uCLinux without a misaligned read interrupt handler.\n\t7. Checkdata bug introduced in 2.1 fixed.\n\t\n\n2.1-r2  15 DEC 2004\tCode changed so it can be compiled with gcc 2.x\n\n\t1.  In some of the code added for release 2.1 I unknowingly used some\n\t    gcc extensions only supported by 3.x compilers.  I have received\n\t    a couple of reports that the 2.1 release doesn't build on 2.x and so\n\t    people are clearly still using gcc 2.x.  The code has been\n\t    rewritten to remove these extensions.\n\n2.1\t10 DEC 2004\tSignificantly improved directory handling plus numerous\n\t\t\tother smaller improvements\n\n\t1.  Fast indexed directories implemented.  These speed up directory\n\t    operations (ls, file lookup etc.) significantly for directories\n\t    larger than 8 KB.\n\t2.  All directories are now sorted in alphabetical order.  This again\n\t    speeds up directory operations, and in some cases it also results in\n\t    a small compression improvement (greater data similarity between\n\t    files with alphabetically similar names).\n\t3.  Maximum directory size increased from 512 KB to 128 MB.\n\t4.  Duplicate fragment checking and appending optimised in mksquashfs,\n\t    depending on filesystem, this is now up to 25% faster.\n\t5.  Mksquashfs help information reformatted and reorganised.\n\t6.  The Squashfs version and release date is now printed at kernel\n\t    boot-time or module insertion.  This addition will hopefully help\n\t    to reduce the growing problem where the Squashfs version supported\n\t    by a kernel is unknown and the kernel source is unavailable.\n        7.  New PERFORMANCE.README file.\n\t8.  New -2.0 mksquashfs option.\n\t9.  CHANGES file reorganised.\n\t10. README file reorganised, clarified and updated to include the 2.0\n\t    mksquashfs options.\n\t11. New patch for Linux 2.6.9.\n\t12. New patch for Linux 2.4.28.\n\n2.0r2\t29 AUG 2004\tWorkaround for kernel bug in kernels 2.6.8 and newer\n\t\t\tadded\n\n\t1. New patch for kernel 2.6.8.1.  This includes a workaround for a\n\t   kernel bug introduced in 2.6.7bk14, which is present in all later\n\t   versions of the kernel.  \n\n\t   If you're using a 2.6.8 kernel or later then you must use this\n\t   2.6.8.1 patch.  If you've experienced hangs or oopses using Squashfs\n\t   with a 2.6.8 or later kernel then you've hit this bug, and this\n\t   patch will fix it.\n\n\t   It is worth mentioning that this kernel bug potentially affects\n\t   other filesystems.  If you receive odd results with other\n\t   filesystems you may be experiencing this bug with that filesystem.\n\t   I submitted a patch but this has not yet gone into the\n\t   kernel, hopefully the bug will be fixed in later kernels. \n\n2.0\t13 JULY 2004\tA couple of new options, and some bug fixes\n\n\t1. New mksquashfs -all-root, -root-owned, -force-uid, and -force-gid\n\t   options.  These allow the uids/gids of files in the generated\n\t   filesystem to be specified, overriding the uids/gids in the\n\t   source filesystem.\n\t2. Initrds are now supported for kernels 2.6.x.\n\t3. amd64 bug fixes.  If you use an amd64, please read the README-AMD64\n\t   file.\n\t4. Check-data and gid bug fixes.  With 2.0-alpha when mounting 1.x\n\t   filesystems in certain cases file gids were corrupted.\n\t5. New patch for Linux 2.6.7.\n\n2.0-ALPHA\t21 MAY 2004\tFilesystem changes and compression improvements\n\n\t1. Squashfs 2.0 has added the concept of fragment blocks.\n           Files smaller than the file block size and optionally the\n\t   remainder of files that do not fit fully into a block (i.e. the\n\t   last 32K in a 96K file) are packed into shared fragments and\n\t   compressed together.  This achieves on average 5 - 20% better\n\t   compression than Squashfs 1.x.\n\t2. The maximum block size has been increased to 64K (in the ALPHA\n\t   version of Squashfs 2.0).\n\t3. The maximum number of UIDs has been increased to 256 (from 48 in\n\t   1.x).\n\t4. The maximum number of GIDs has been increased to 256 (from 15 in\n\t   1.x).\n\t5. Removal of sleep_on() function call in 2.6.x patch, to allow Squashfs\n\t   to work on the Fedora rc2 kernel.\n\t6. Numerous small bug fixes have been made.\n\n1.3r3\t18 JAN 2004\tThird release of 1.3, this adds a new mksquashfs option,\n\t\t\tsome bug fixes, and extra patches for new kernels\n\n\t1. New mksquashfs -ef exclude option.  This option reads the exclude\n\t   dirs/files from an exclude file, one exclude dir/file per line.  This\n\t   avoids the command line size limit when using the -e exclude option,\n\t2. When appending to existing filesystems, if mksquashfs experiences a\n\t   fatal error (e.g. out of space when adding to the destination), the\n\t   original filesystem is restored,\n\t3. Mksquashfs now builds standalone, without the kernel needing to be\n\t   patched.\n\t4. Bug fix in the kernel squashfs filesystem, where the pages being\n\t   filled were not kmapped.  This seems to only have caused problems\n\t   on an Apple G5,\n\t5. New patch for Linux 2.4.24,\n\n\t6. New patch for Linux 2.6.1, this replaces the patch for 2.6.0-test7.\n\n1.3r2\t14 OCT 2003\tSecond release of 1.3, bug fixes and extra patches for\n\t\t        new kernels\n\n\t1. Bug fix in routine that adds files to the filesystem being\n\t   generated in mksquashfs.  This bug was introduced in 1.3\n\t   (not enough testing...) when I rewrote it to handle files larger\n\t   than available memory.  This bug caused a SEGV, so if you've ever\n\t   got that, it is now fixed,\n\t2. Long running bug where ls -s and du reported wrong block size\n\t   fixed.  I'm pretty sure this used to work many kernel versions ago\n\t   (2.4.7) but it broke somewhere along the line since then,\n\t3. New patch for Linux 2.4.22,\n\t4. New patch for 2.6.0-test7, this replaces the patch for 2.6.0-test1.\n\n1.3\t29 JUL 2003\tFIFO/Socket support added plus optimisations and\n\t\t        improvements\n\n\t1. FIFOs and Socket inodes are now supported,\n\t2. Mksquashfs can now compress files larger than available\n\t   memory,\n\t3. File duplicate check routine optimised,\n\t4. Exit codes fixed in Mksquashfs,\n\t5. Patch for Linux 2.4.21,\n\t6. Patch for Linux 2.6.0-test1.  Hopefully, this will work for\n\t   the next few releases of 2.6.0-testx, otherwise, I'll be\n\t   releasing a lot of updates to the 2.6.0 patch...\n\n1.2\t13 MAR 2003\tAppend feature and new mksquashfs options added\n\n\tMksquashfs can now add to existing squashfs filesystems.  Three extra\n\toptions \"-noappend\", \"-keep-as-directory\", and \"root-becomes\"\n\thave been added.\n\n\tThe append option with file duplicate detection, means squashfs can be\n\tused as a simple versioning archiving filesystem. A squashfs\n\tfilesystem can be created with for example the linux-2.4.19 source.\n\tAppending the linux-2.4.20 source will create a filesystem with the\n\ttwo source trees, but only the changed files will take extra room,\n\tthe unchanged files will be detected as duplicates.\n\n\tSee the README file for usage changes.\n\n1.1b\t16 JAN 2003\tBug fix release\n\n\tFixed readpage deadlock bug.  This was a rare deadlock bug that\n\thappened when pushing pages into the page cache when using greater\n\tthan 4K blocks.  I never got this bug when I tested the filesystem,\n\tbut two people emailed me on the same day about the problem!\n\tI fixed it by using a page cache function that wasn't there when\n\tI originally did the work, which was nice :-)\n\n1.1\t8 JAN 2003\tAdded features\n\n\t1. Kernel squashfs can now mount different byte order filesystems.\n\t2. Additional features added to mksquashfs.  Mksquashfs now supports\n\t   exclude files and multiple source files/directories can be\n\t   specified.  A nopad option has also been added, which\n\t   informs mksquashfs not to pad filesystems to a multiple of 4K.\n\t   See README for mksquashfs usage changes.\n\t3. Greater than 2GB filesystems bug fix.  Filesystems greater than 2GB\n\t   can now be created.\n\n1.0c \t14 NOV 2002\tBug fix release\n\n\tFixed bugs with initrds and device nodes\n\n1.0 \t23 OCT 2002\tInitial release\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/COPYING",
    "content": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n\t\t    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n\t    How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) 19yy  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) 19yy name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/INSTALL",
    "content": "\t\t\tINSTALLING SQUASHFS\n\nThe squashfs3.2-r2.tar.gz file contains this file, a README-3.2 file, another\nREADME file, an ACKNOWLEDGEMENTS file, a CHANGES file, the kernel-patches\ndirectory containing the squashfs patches, and the squashfs-tools directory\n(mksquashfs and unsquashfs).\n\n1. Patching the kernel\n----------------------\n\nThere are eleven kernel patch directories depending on your linux kernel\nversion.  If your kernel version isn't listed then try the patch for the nearest\nkernel listed.\n\nTo patch your kernel, cd into the top level directory, and run the \"patch\"\ncommand, e.g. assuming linux-2.6.20\n\n%cd /usr/src/linux-2.6.20\n%patch -p1 < location-of-squashfs/kernel-patches/linux-2.6.20/squashfs3.2-patch\n\nWhere \"location-of-squashfs\" is the path to the squashfs3.2 source directory.\n\nThe squashfs patches patch the relevant kernel files to add configure support,\ninitrd support, include files, and the squashfs directory under linux/fs/.\nOnce patched, the kernel must be reconfigured, with squashfs support turned on\n(either Y/M) to ensure that inflate support is built into the kernel.  The\nsquashfs kernel option can be found in the miscellaneous filesystems submenu\nnear the bottom of the filesystems submenu.\n\nThere are a set of options which are intended for use by embedded systems with\nlow memory.  At the \"Additional options for memory-constrained systems\" prompt,\nplease say NO unless you're using an embedded system!  Saying Y here allows you\nto specify cache sizes and how Squashfs allocates memory.\n\nThe \"Number of fragments cached\" prompt allows the number of fragments cached\nto be controlled.  By default SquashFS caches the last 3 fragments read from\nthe filesystem.  Increasing this amount may mean SquashFS has to re-read\nfragments less often from disk, at the expense of extra system memory.\nDecreasing this amount will mean SquashFS uses less memory at the expense of\nextra reads from disk.  Note there must be at least one cached fragment.\nAnything much more than three will probably not make much difference.\n\nThe \"Use Vmalloc rather than Kmalloc\" prompt allows you to tell SquashFS to\nuse Vmalloc.  By default SquashFS uses kmalloc to obtain fragment cache memory.\nKmalloc memory is the standard kernel allocator, but it can fail on memory\nconstrained systems.  Because of the way Vmalloc works, Vmalloc can succeed\nwhen kmalloc fails.  Specifying this option will make SquashFS always use\nVmalloc to allocate the fragment cache memory.\n\n2. Building squashfs tools\n--------------------------\n\nThe squashfs-tools directory contains the mksquashfs and unsquashfs programs.\nThese can be made by typing make.  The source files use a local copy of\nsquashfs_fs.h (included in the kernel patches) allowing the tools to be made\nwithout needing to patch the kernel.\n\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/OLD-READMEs/README-2.0",
    "content": "NOTE:  This the original README for version 2.0.  It is retained as it\ncontains information about the fragment design.  A description of the new 2.0\nmksquashfs options has been added to the main README file, and that\nfile should now be consulted for these.\n\n\tSQUASHFS 2.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2004 Phillip Lougher (plougher@users.sourceforge.net)\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to the final release of Squashfs version 2.0!  A lot of changes to the\nfilesystem have been made under the bonnet (hood).  Squashfs 2.0 uses fragment\nblocks and larger blocks (64K) to improve compression ratio by about 5 - 20%\nover Squashfs 1.0 depending on the files being compressed.  Using fragment\nblocks allows Squashfs 2.0 to achieve better compression than cloop and similar\ncompression to tgz files while retaining the I/O efficiency of a compressed\nfilesystem.\n\nDetailed changes:\n\n1. Squashfs 2.0 has added the concept of fragment blocks (see later discussion).\n   Files smaller than the file block size (64K in Squashfs 2.0) and optionally\n   the remainder of files that do not fit fully into a block (i.e. the last 32K\n   in a 96K file) are packed into shared fragments and compressed together.\n   This achieves on average 5 - 20% better compression than Squashfs 1.x.\n\n2. The maximum block size has been increased to 64K.\n\n3. The maximum number of UIDs has been increased to 256 (from 48 in 1.x).\n\n4. The maximum number of GIDs has been increased to 256 (from 15 in 1.x).\n\n5. New mksquashfs -all-root, -root-owned, -force-uid, and -force-gid\n   options.  These allow the uids/gids of files in the generated\n   filesystem to be specified, overriding the uids/gids in the\n   source filesystem.\n\n6. Initrds are now supported for kernels 2.6.x.\n\n7. Removal of sleep_on() function call in 2.6.x patch, to allow Squashfs\n   to work on the Fedora rc2 kernel.\n\n8. AMD64, check-data and gid bug fixes.\n\n9. Numerous small bug fixes have been made.\n\n10. New patch for Linux 2.6.7.\n\n\nNew Squashfs 2.0 options\n------------------------\n\n-noF or -noFragmentCompression\n\n\tDo not compress the fragments.  Added for compatibility with noI and\n\tnoD, probably not that useful.\n\n-no-fragments\n\n\tDo not use fragment blocks, and rather generate a filesystem\n\tsimilar to a Squashfs 1.x filesystem.  It will of course still\n\tbe a Squashfs 2.0 filesystem but without fragments, and so\n\tit won't be mountable on a Squashfs 1.x system.\n\n-always-use-fragments\n\n\tBy default only small files less than the block size are packed into\n\tfragment blocks.  The ends of files which do not fit fully into a block,\n\tare NOT by default packed into fragments.  To illustrate this, a\n\t100K file has an initial 64K block and a 36K remainder.  This\n\t36K remainder is not packed into a fragment by default.  This is\n\tbecause to do so leads to a 10 - 20% drop in sequential I/O\n\tperformance, as a disk head seek is needed to seek to the initial\n\tfile data and another disk seek is need to seek to the fragment\n\tblock.\n\n\tSpecify this option if you want file remainders to be packed into\n\tfragment blocks.  Doing so may increase the compression obtained\n\tBUT at the expense of I/O speed.\n\n-no-duplicates\n\n\tDo not detect duplicate files.\n\n-all-root\n-root-owned\n\n\tThese options (both do exactly the same thing), force all file\n\tuids/gids in the generated Squashfs filesystem to be root.\n\tThis allows root owned filesystems to be built without root access\n\ton the host machine.\n\n-force-uid uid\n\n\tThis option forces all files in the generated Squashfs filesystem to\n\tbe owned by the specified uid.  The uid can be specified either by\n\tname (i.e. \"root\") or by number.\n\n-force-gid gid\n\n\tThis option forces all files in the generated Squashfs filesystem to\n\tbe group owned by the specified gid.  The gid can be specified either by\n\tname (i.e. \"root\") or by number.\n\n\nCompression improvements example\n--------------------------------\n\nThe following is the compression results obtained compressing the 2.6.6\nlinux kernel source using CRAMFS, Cloop (with iso filesystem), Squashfs 1.3 and\nSquashfs 2.0 (results generated using big-endian filesystems).\n\nIn decreasing order of size:\n\n\tCRAMFS\t\t62791680 bytes (59.9M)\n\tSquashfs 1.x\t51351552 bytes (48.9M)\n\tCloop\t\t46118681 bytes (44.0M)\n\tSquashfs 2.0\t45604854 bytes (43.5M)\n\n\nThe Squashfs 1.x filesystem is 12.6% larger than the new 2.0 filesystem.\nThe cloop filesystem is 1.1% larger than the Squashfs 2.0 filesystem.\n\n\nFragment blocks in Squashfs 2.0\n-------------------------------\n\nSquashfs like all other compressed filesystems compresses files individually\non a block by block basis.  This is performed to allow mounting and\nde-compression of files on a block by block basis without requiring the entire\nfilesystem to be decompressed.  This is in contrast to data-based compression\nschemes which compress without understanding the underlying filesystem (i.e.\ncloop and tgz files) and which, therefore, do not compress files individually.\nEach approach has advantages and disadvantages, data-based systems have better\ncompression because compression is always performed at the maximum block size\n(64K in cloop) irrespective of the size of each file (which could be less than\nthe block size).  Compressed filesystems tend to be faster at I/O because\nthey understand the filesystem and therefore employ better caching stategies\nand read less un-needed data from the filesystem.\n\nFragment blocks in Squashfs 2.0 solves this problem by packing files (and\noptionally the ends of files) which are smaller than the block size into\nshared blocks, which are compressed together.  For example five files each of\n10K will be packed into one shared fragment of 50K and compressed together,\nrather than being compressed in five 10K blocks.\n\nThis scheme produces a hybrid filesystem, retaining the I/O efficiency\nof a compressed filesystem, while obtaining the compression efficiency\nof data-based schemes by compressing small files together.\n\n\nSquashfs 1.x and Squashfs 2.0 compatibility\n-------------------------------------------\n\nAppending to Squashfs 1.x filesystems is not supported.  If you wish to append\nto 1.x filesystems, then either use the original mksquashfs, or convert them\nto Squashfs 2.0 by mounting the filesystem and running the 2.0 mksquashfs\non the mounted filesystem.\n\nMounting Squashfs 1.x filesystems IS supported by the 2.0 kernel patch.\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/OLD-READMEs/README-2.1",
    "content": "\tSQUASHFS 2.1 - A squashed read-only filesystem for Linux\n\n\tCopyright 2004 Phillip Lougher (plougher@users.sourceforge.net)\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 2.1-r2.  Squashfs 2.1 introduces indexed\ndirectories which considerably speed up directory lookup (ls, find etc.) for\ndirectories which are greater than 8K in size.  All directories are now also\nsorted alphabetically which further speeds up directory lookup.  Many smaller\nimprovements have also been made to this release, please see the CHANGES file\nentry for detailed changes.\n\n1. DIRECTORY SPEED IMPROVEMENT EXAMPLES\n---------------------------------------\n\nTo give an indication of the directory speed improvements a number of test\nresults are shown here.  There is in addition a new PERFORMANCE.README file\nwhich gives details of I/O and lookup performance for Squashfs 2.1 against\nthe Zisofs, Cloop and CRAMFS filesystems.\n\nexample 1:\n\nFilesystems generated from a single directory of 72,784 files (2.6 MB\ndirectory size).  Each file is 10 bytes in size (the test is directory\nlookup and so the file size isn't an issue).  The ext3 uncompressed\ndirectory size is 288 MB (presumably because of one file per block).\n\nZisofs compressed size        153.50 MB\nCloop (isofs) compressed size 1.74 MB\nSquashfs2.1 compressed size   612 KB (0.60 MB)\n\nTime taken to perform \"ls -lR --color=always | cat > /dev/null\" on\nfilesystems mounted on hard disk.\n\nZisofs       35 minutes 7.895 seconds (User 7.868 secs, Sys 34 mins 5.621 secs)\nCloop        35 minutes 12.765 seconds (User 7.771 secs, Sys 34 mins 3.869 secs)\nSquashfs2.1  19 seconds (User 5.119 secs, Sys 14.547 secs)\n\nexample 2:\n\nFilesystems were generated from the Ubuntu Warty livecd (original uncompressed\nsize on ext3 is 1.4 GB).\n\nZisofs compressed size        589.81 MB\nCloop (isofs) compressed size 471.19 MB\nSquashfs2.0 compressed size   448.58 MB\nSquashfs2.1 compressed size   448.58 MB\n\nTime taken to perform \"ls -lR --color=always | cat > /dev/null\" on\nfilesystems mounted on hard disk.\n\nZisofs        49.875 seconds (User time 2.589 secs, Sys 11.194 secs)\nCloop         20.797 seconds (User time 2.706 secs, Sys 13.496 secs)\nSquashfs2.0   16.556 seconds (User time 2.424 secs, Sys 10.371 secs)\nSquashfs2.1   10.143 seconds (User time 2.475 secs, Sys 4.440 secs)\n\n\nNOTE: the usual warnings apply to these results, they are provided for\nillustrative purposes only, and due to different hardware and/or file data, you\nmay obtain different results.  As such the results are provided \"as is\" without\nany warranty (either express or implied) and you assume all risks as to their\nquality and accuracy.\n\n2. NEW MKSQUASHFS OPTIONS\n-------------------------\n\nThere is only one extra option \"-2.0\".  This tells mksquashfs to generate\na filesystem which is mountable with Squashfs version 2.0.\n\n3. APPENDING AND MOUNTING SQUASHFS 2.0 FILESYSTEMS\n--------------------------------------------------\n\nMounting 2.0 filesystems is supported by Squashfs 2.1.  In addition\nmksquashfs v2.1 can append to 2.0 filesystems, although the generated\nfilesystem will still be a 2.0 filesystem.\n\n4. DONATIONS\n------------\n\nIf you find Squashfs useful then please consider making a donation,\nparticularly if you use Squashfs in a commercial product.  Please consider\ngiving something back especially if you're making money from it.\n\nOff the Squashfs subject somewhat I'm currently looking for another\njob doing Linux kernel or filesystems work.  If you know of any such\nwork that can be performed from the UK then please get in touch.  Thanks.\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/OLD-READMEs/README-3.0",
    "content": "\tSQUASHFS 3.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2006 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to the first release of Squashfs version 3.0.  Squashfs 3.0 has the\nthe following improvements to 2.x.\n\n\t1. Filesystems are no longer limited to 4 GB.  In\n\t   theory 2^64 or 4 exabytes is now supported.\n\n\t2. Files are no longer limited to 4 GB.  In theory the maximum\n\t   file size is 4 exabytes.\n\n\t3. Metadata (inode table and directory tables) are no longer\n\t   restricted to 16 Mbytes.\n\n\t4. Hardlinks are now suppported.\n\n\t5. Nlink counts are now supported.\n\n\t6. Readdir now returns '.' and '..' entries.\n\n\t7. Special support for files larger than 256 MB has been added to\n\t   the Squashfs kernel code for faster read access.\n\n\t8. Inode numbers are now stored within the inode rather than being\n\t   computed from inode location on disk (this is not so much an\n\t   improvement, but a change forced by the previously listed\n\t   improvements).\n\nThere is a new Unsquashfs utility (in squashfs-tools) than can be used to\ndecompress a filesystem without mounting it.\n\nSquashfs 3.0 supports 2.x filesystems.  Support for 1.x filesystems\nwill be added in the future.\n\n1. UNSQUASHFS\n-------------\n\nUnsquashfs has the following options:\n\nSYNTAX: unsquashfs [-ls | -dest] filesystem\n\t-version\t\tprint version, licence and copyright information\n\t-info\t\t\tprint files as they are unsquashed\n\t-ls\t\t\tlist filesystem only\n\t-dest <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\nThe \"-ls\" option can be used to list the contents of a filesystem without\ndecompressing the filesystem data itself.\n\nThe \"-info\" option forces Unsquashfs to print each file as it is decompressed.\n\nThe \"-dest\" option specifies the directory that is used to decompress\nthe filesystem data.  If this option is not given then the filesystem is\ndecompressed to the directory \"squashfs-root\" in the current working directory.\n\nUnsquashfs can decompress 3.0 filesystems.  Support for 2.x and 1.x\nfilesystems will be added in the future.\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/OLD-READMEs/README-3.1",
    "content": "\tSQUASHFS 3.1 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2006 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.1-r2.  Squashfs 3.1 has major improvements to\nthe Squashfs tools (Mksquashfs and Unsquashfs), some major bug fixes, new\nkernel patches, and various other smaller improvements and bug fixes.\nPlease see the CHANGES file for a detailed list.\n\n1. MKSQUASHFS\n-------------\n\nMksquashfs has been rewritten and it is now multi-threaded.  It offers\nthe following improvements:\n\n1. Parallel compression.  By default as many compression and fragment\ncompression threads are created as there are available processors.\nThis significantly speeds up performance on SMP systems.\n\n2. File input and filesystem output is peformed in parallel on separate\nthreads to maximise I/O performance.  Even on single processor systems\nthis speeds up performance by at least 10%.\n\n3. Appending has been significantly improved, and files within the\nfilesystem being appended to are no longer scanned and checksummed.  This\nsignificantly improves append time for large filesystems.\n\n4. File duplicate checking has been optimised, and split into two separate\nphases.  Only files which are considered possible duplicates after the\nfirst phase are checksummed and cached in memory.\n\n5. The use of swap memory was found to significantly impact performance. The\namount of memory used to cache the file is now a command line option, by default\nthis is 512 Mbytes.\n\n1.1 NEW COMMAND LINE OPTIONS\n----------------------------\n\nThe new Mksquashfs program has a couple of extra command line options\nwhich can be used to control the new features:\n\n-processors <processors>\n\nThis specifies the number of processors used by Mksquashfs.\nBy default this is the number of available processors.\n\n-read_queue <size in Mbytes>\n\nThis specifies the size of the file input queue used by the reader thread.\nThis defaults to 64 Mbytes.\n\n-write_queue <size in Mbytes>\n\nThis specifies the size of the filesystem output queue used by the\nwriter thread.  It also specifies the maximum cache used in file\nduplicate detection (the output queue is shared between these tasks).\nThis defaults to 512 Mbytes.\n\n1.2 PERFORMANCE RESULTS\n-----------------------\n\nThe following results give an indication of the speed improvements.  Two\nexample filesystems were tested, a liveCD filesystem (about 1.8 Gbytes\nuncompressed), and my home directory consisting largely of text files\n(about 1.3 Gbytes uncompressed).  Tests were run on a single core\nand a dual core system.\n\nDual Core (AMDx2 3800+) system:\nSource directories on ext3.\n\nLiveCD, old mksquashfs:\n\nreal    11m48.401s\nuser    9m27.056s\nsys     0m15.281s\n\nLiveCD, new par_mksquashfs:\n\nreal    4m8.736s\nuser    7m11.771s\nsys     0m27.749s\n\n\"Home\", old mksquashfs:\n\nreal    4m34.360s\nuser    3m54.007s\nsys     0m32.155s\n\n\"Home\", new par_mksquashfs:\n\nreal    1m27.381s\nuser    2m7.304s\nsys     0m17.234s\n\nSingle Core PowerBook (PowerPC G4 1.5 GHz Ubuntu Linux)\nSource directories on ext3.\n\nLiveCD, old mksquashs:\n\nreal    11m38.472s\nuser    9m6.137s\nsys     0m23.799s\n\nLiveCD,  par_mksquashfs:\n\nreal    10m5.572s\nuser    8m59.921s\nsys     0m16.145s\n\n\"Home\", old mksquashfs:\n\nreal    3m42.298s\nuser    2m49.478s\nsys     0m13.675s\n\n\"Home\", new par_mksquashfs:\n\nreal    3m9.178s\nuser    2m50.699s\nsys     0m9.069s\n\nI'll be interested in any performance results obtained, especially from SMP\nmachines larger than my dual-core AMD box, as this will give an indication of\nthe scalability of the code.  Obviously, I'm also interested in any problems,\ndeadlocks, low performance etc.\n\n2. UNSQUASHFS\n-------------\n\nUnsquashfs now allows you to specify the filename or directory that is to be\nextracted from the Squashfs filesystem, rather than always extracting the\nentire filesystem.  It also has a new \"-force\" option, and all options can be\nspecified in a short form (-i rather than -info).\n\nThe Unsquashfs usage info is now:\n\nSYNTAX: ./unsquashfs [options] filesystem [directory or file to extract]\n\t-v[ersion]\t\tprint version, licence and copyright information\n\t-i[nfo]\t\t\tprint files as they are unsquashed\n\t-l[s]\t\t\tlist filesystem only\n\t-d[est] <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\t-f[orce]\t\tif file already exists then overwrite\n\nTo extract a subset of the filesystem, the filename or directory\ntree that is to be extracted can now be specified on the command line.  The\nfile/directory should be specified using the full path to the file/directory\nas it appears within the Squashfs filesystem.  The file/directory will also be\nextracted to that position within the specified destination directory.\n\nThe new \"-force\" option forces Unsquashfs to output to the destination\ndirectory even if files or directories already exist.  This allows you\nto update an existing directory tree, or to Unsquashfs to a partially\nfilled directory.  Without the \"-force\" option, Unsquashfs will\nrefuse to overwrite any existing files, or to create any directories if they\nalready exist.  This is done to protect data in case of mistakes, and\nso the \"-force\" option should be used with caution.\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/OLD-READMEs/README-AMD64",
    "content": "Information for amd64 users\n---------------------------\n\nAll releases of Squashfs prior to 2.0 generate incorrect\nfilesystems on amd64 machines.  Filesystems created on amd64 machines work\ncorrectly on amd64 machines, but cannot be mounted on non-amd64 machines.\nLikewise, filesystems created on non-amd64 machines cannot be mounted on amd64\nmachines.  This bug is caused by the different size of the \"time_t\" definition\nused in SquashFS filesystem structures.\n\nThis bug is fixed in releases 2.0 and newer.  However, all amd64 filesystems\ngenerated by previous releases will not be mountable on amd64 machines\nwith newer releases.  If you have amd64 filesystems generated with mksquashfs\nversion 2.0-alpha or older, it is important that you recreate the filesystem.\nThis can be performed by mounting the filesystem using a kernel with the\noriginal patch (i.e. a 2.0-alpha or older patch) and running the NEW (i.e. this\nrelease) mksquashfs tool to create a new SquashFS filesystem.\n\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/PERFORMANCE.README",
    "content": "GENERAL INFORMATION ON PERFORMANCE TESTS\n----------------------------------------\n\nThe following performance tests were based on two file sets: the\nliveCD filesystem from the Ubuntu liveCD (Warty release), and the\nliveCD filesystem from the Damn Small Linux liveCD (release 0.8.4).\nThe Ubuntu liveCD filesystem was used to test filesystem performance\nfrom CDROM and hard disk for Zisofs, Cloop, Squashfs 2.0 and Squashfs2.1.\nCRAMFS filesystem performance could not be tested for this filesystem\nbacause it exceeds the maximum supported size of CRAMFS.  To test\nCRAMFS performance against Squashfs, the liveCD filesystem from\nDamn Small Linux was used.\n\nNOTE: the usual warnings apply to these results, they are provided for\nillustrative purposes only, and due to different hardware and/or file data, you\nmay obtain different results.  As such the results are provided \"as is\" without\nany warranty (either express or implied) and you assume all risks as to their\nquality and accuracy.\n\n1. Ubuntu liveCD performance tests\n\n   ext3 uncompressed size      1.4 GB\n   Zisofs compressed size      589.81 MB\n   Cloop compressed size       471.89 MB\n   Squashfs2.0 compressed size 448.58 MB\n   Squashfs2.1 compressed size 448.58 MB\n\n1.1 Performance tests from CDROM\n\n1.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  Zisofs       49.88 seconds (User 2.60 secs, Sys 11.19 secs)\n  Cloop        20.80 seconds (User 2.71 secs, Sys 13.50 secs)\n  Squashfs2.0  16.56 seconds (User 2.42 secs, Sys 10.37 secs)\n  Squashfs2.1  10.14 seconds (User 2.48 secs, Sys 4.44 secs)\n\n1.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  Zisofs       27 minutes 28.54 seconds (User 3.00 secs, Sys 1 min 4.80 secs)\n  Cloop        5 minutes 55.72 seconds (User 2.90 secs, Sys 3 min 37.90 secs)\n  Squashfs2.0  5 minutes 20.87 seconds (User 2.33 secs, Sys 56.98 secs)\n  Squashfs2.1  5 minutes 15.46 seconds (user 2.28 secs, Sys 51.12 secs)\n\n1.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n  Zisofs       101 minutes 29.65 seconds (User 5.33 secs, Sys  1 min 17.20 secs)\n  Cloop        35 minutes 27.51 seconds (user 5.93 secs, Sys 4 mins 30.23 secs)\n  Squashfs2.0  21 minutes 53.05 seconds (user 5.71 secs, Sys 2 mins 36.59 secs)\n  Squashfs2.1  21 minutes 46.99 seconds (User 5.80 secs, Sys 2 mins 31.88 secs)\n\n\n1.2 Performance tests from Hard disk\n\n1.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk \n\n  Zisofs       17.29 seconds (User 2.62 secs, Sys 11.08 secs)\n  Cloop        16.46 seconds (User 2.63 secs, Sys 13.41 secs)\n  Squashfs2.0  13.75 seconds (User 2.44 secs, Sys 11.00 secs)\n  Squashfs2.1  6.94 seconds (User 2.44 secs, Sys 4.48 secs)\n\n1.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk\n\n  Zisofs       1 minute 21.47 seconds (User 2.73 secs, Sys 54.44 secs)\n  Cloop        1 minute 34.06 seconds (user 2.85 secs, Sys 1 min 12.13 secs)\n  Squashfs2.0  1 minute 21.22 seconds (User 2.42 secs, Sys 56.21 secs)\n  Squashfs2.1  1 minute 15.46 seconds (User 2.36 secs, Sys 49.78 secs)\n\n1.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk\n\n  Zisofs       11 minutes 13.64 seconds (User 5.08 secs, Sys 52.62 secs)\n  Cloop        5 minutes 37.93 seconds (user 6 secs, Sys 2 mins 22.38 secs)\n  Squashfs2.0  5 minutes 7.11 seconds (user 5.63 secs, Sys 2 mins 35.23 secs)\n  Squashfs2.1  5 minutes 1.87 seconds (User 5.71 secs, Sys 2 mins 29.98 secs)\n\n\n2. Damn Small Linux liveCD performance tests\n\n   ext3 uncompressed size      126 MB\n   CRAMFS compressed size      52.19 MB\n   Squashfs2.0 compressed size 46.52 MB\n   Squashfs2.1 compressed size 46.52 MB\n\n2.1 Performance tests from CDROM\n\n2.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  CRAMFS       10.85 seconds (User 0.39 secs, Sys 0.98 secs)\n  Squashfs2.0  2.97 seconds (User 0.36 secs, Sys 2.15 secs)\n  Squashfs2.1  2.43 seconds (User 0.40 secs, Sys 1.42 secs)\n\n2.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  CRAMFS       55.38 seconds (User 0.34 secs, Sys 6.98 secs)\n  Squashfs2.0  35.99 seconds (User 0.30 secs, Sys 6.35 secs)\n  Squashfs2.1  33.83 seconds (User 0.26 secs, Sys 5.56 secs)\n\n2.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n\n  CRAMFS        3 minutes 1.68 seconds (User 0.54 secs, Sys 9.51 secs)\n  Squashfs2.0   1 minute 39.45 seconds (User 0.57 secs, Sys 13.14 secs)\n  Squashfs2.1   1 minute 38.41 seconds (User 0.58 secs, Sys 13.08 secs)\n\n2.2 Performance tests from Hard disk\n\n2.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk\n\n  CRAMFS       1.77 seconds (User 0.53 secs, Sys 1.21 secs)\n  Squashfs2.0  2.67 seconds (User 0.41 secs, Sys 2.25 secs)\n  Squashfs2.1  1.87 seconds (User 0.41 secs, Sys 1.46 secs)\n\n2.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk \n\n  CRAMFS       6.80 seconds (User 0.36 secs, Sys 6.02 secs)\n  Squashfs2.0  7.23 seconds (User 0.29 secs, Sys 6.62 secs)\n  Squashfs2.1  6.53 seconds (User 0.31 secs, Sys 5.82 secs)\n\n2.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk \n\n\n  CRAMFS       28.55 seconds (User 0.49 secs, Sys 6.49 secs)\n  Squashfs2.0  25.44 seconds (User 0.58 secs, Sys 13.17 secs)\n  Squashfs2.1  24.72 seconds (User 0.56 secs, Sys 13.15 secs)\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/README",
    "content": "\tSQUASHFS 3.2 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.2.  Please read the README-3.2 and CHANGES\nfiles for details of changes.\n\nSquashfs is a highly compressed read-only filesystem for Linux.\nIt uses zlib compression to compress both files, inodes and directories.\nInodes in the system are very small and all blocks are packed to minimise\ndata overhead. Block sizes greater than 4K are supported up to a maximum\nof 64K.\n\nSquashfs is intended for general read-only filesystem use, for archival\nuse (i.e. in cases where a .tar.gz file may be used), and in constrained\nblock device/memory systems (e.g. embedded systems) where low overhead is\nneeded.\n\n1. SQUASHFS OVERVIEW\n--------------------\n\n1. Data, inodes and directories are compressed.\n\n2. Squashfs stores full uid/gids (32 bits), and file creation time.\n\n3. In theory files up to 2^64 bytes are supported.  In theory filesystems can\n   be up to 2^64 bytes.\n\n4. Inode and directory data are highly compacted, and packed on byte\n   boundaries.  Each compressed inode is on average 8 bytes in length\n   (the exact length varies on file type, i.e. regular file, directory,\n   symbolic link, and block/char device inodes have different sizes).\n\n5. Squashfs can use block sizes up to 64K (the default size is 64K).\n   Using 64K blocks achieves greater compression ratios than the normal\n   4K block size.\n\n6. File duplicates are detected and removed.\n\n7. Both big and little endian architectures are supported.  Squashfs can\n   mount filesystems created on different byte order machines.\n\n\n2. USING SQUASHFS\n-----------------\n\nSquashfs filesystems should be mounted with 'mount' with the filesystem type\n'squashfs'.  If the filesystem is on a block device, the filesystem can be\nmounted directly, e.g.\n\n%mount -t squashfs /dev/sda1 /mnt\n\nWill mount the squashfs filesystem on \"/dev/sda1\" under the directory \"/mnt\".\n\nIf the squashfs filesystem has been written to a file, the loopback device\ncan be used to mount it (loopback support must be in the kernel), e.g.\n\n%mount -t squashfs image /mnt -o loop\n\nWill mount the squashfs filesystem in the file \"image\" under\nthe directory \"/mnt\".\n\n\n3. MKSQUASHFS\n-------------\n\n3.1 Mksquashfs options and overview.\n------------------------------------\n\nAs squashfs is a read-only filesystem, the mksquashfs program must be used to\ncreate populated squashfs filesystems.\n\nSYNTAX:mksquashfs source1 source2 ...  dest [options] [-e list of exclude\ndirs/files]\n\nOptions are\n-version\t\tprint version, licence and copyright message\n-info\t\t\tprint files written to filesystem\n-b <block_size>\t\tset data block to <block_size>.  Default 65536 bytes\n-processors <number>\tUse <number> processors.  By default will use number of\n\t\t\tprocessors available\n-read-queue <size>\tSet input queue to <size> Mbytes.  Default 64 Mbytes\n-write-queue <size>\tSet output queue to <size> Mbytes.  Default 512 Mbytes\n-noI\t\t\tdo not compress inode table\n-noD\t\t\tdo not compress data blocks\n-noF\t\t\tdo not compress fragment blocks\n-no-fragments\t\tdo not use fragments\n-always-use-fragments\tuse fragment blocks for files larger than block size\n-no-duplicates\t\tdo not perform duplicate checking\n-noappend\t\tdo not append to existing filesystem\n-keep-as-directory\tif one source directory is specified, create a root\n\t\t\tdirectory containing that directory, rather than the\n\t\t\tcontents of the directory\n-root-becomes <name>\twhen appending source files/directories, make the\n\t\t\toriginal root become a subdirectory in the new root\n\t\t\tcalled <name>, rather than adding the new source items\n\t\t\tto the original root\n-all-root\t\tmake all files owned by root\n-force-uid uid\t\tset all file uids to uid\n-force-gid gid\t\tset all file gids to gid\n-le\t\t\tcreate a little endian filesystem\n-be\t\t\tcreate a big endian filesystem\n-nopad\t\t\tdo not pad filesystem to a multiple of 4K\n-check_data\t\tadd checkdata for greater filesystem checks\n-root-owned\t\talternative name for -all-root\n-noInodeCompression\talternative name for -noI\n-noDataCompression\talternative name for -noD\n-noFragmentCompression\talternative name for -noF\n-sort <sort_file>\tsort files according to priorities in <sort_file>.  One\n\t\t\tfile or dir with priority per line.  Priority -32768 to\n\t\t\t32767, default priority 0\n-ef <exclude_file>\tlist of exclude dirs/files.  One per line\n\nSource1 source2 ... are the source directories/files containing the\nfiles/directories that will form the squashfs filesystem.  If a single\ndirectory is specified (i.e. mksquashfs source output_fs) the squashfs\nfilesystem will consist of that directory, with the top-level root\ndirectory corresponding to the source directory.\n\nIf multiple source directories or files are specified, mksquashfs will merge\nthe specified sources into a single filesystem, with the root directory\ncontaining each of the source files/directories.  The name of each directory\nentry will be the basename of the source path.   If more than one source\nentry maps to the same name, the conflicts are named xxx_1, xxx_2, etc. where\nxxx is the original name.\n\nTo make this clear, take two example directories.  Source directory\n\"/home/phillip/test\" contains  \"file1\", \"file2\" and \"dir1\".\nSource directory \"goodies\" contains \"goodies1\", \"goodies2\" and \"goodies3\".\n\nusage example 1:\n\n%mksquashfs /home/phillip/test output_fs\n\nThis will generate a squashfs filesystem with root entries\n\"file1\", \"file2\" and \"dir1\".\n\nexample 2:\n\n%mksquashfs /home/phillip/test goodies output_fs\n\nThis will create a squashfs filesystem with the root containing\nentries \"test\" and \"goodies\" corresponding to the source\ndirectories \"/home/phillip/test\" and \"goodies\".\n\nexample 3:\n\n%mksquashfs /home/phillip/test goodies test output_fs\n\nThis is the same as the previous example, except a third\nsource directory \"test\" has been specified.  This conflicts\nwith the first directory named \"test\" and will be renamed \"test_1\".\n\nMultiple sources allow filesystems to be generated without needing to\ncopy all source files into a common directory.  This simplifies creating\nfilesystems.\n\nThe -keep-as-directory option can be used when only one source directory\nis specified, and you wish the root to contain that directory, rather than\nthe contents of the directory.  For example:\n\nexample 4:\n\n%mksquashfs /home/phillip/test output_fs -keep-as-directory\n\nThis is the same as example 1, except for -keep-as-directory.\nThis will generate a root directory containing directory \"test\",\nrather than the \"test\" directory contents \"file1\", \"file2\" and \"dir1\".\n\nThe Dest argument is the destination where the squashfs filesystem will be\nwritten.  This can either be a conventional file or a block device.  If the file\ndoesn't exist it will be created, if it does exist and a squashfs\nfilesystem exists on it, mksquashfs will append.  The -noappend option will\nwrite a new filesystem irrespective of whether an existing filesystem is\npresent.\n\n3.2 Changing compression defaults used in mksquashfs\n----------------------------------------------------\n\nThere are a large number of options that can be used to control the \ncompression in mksquashfs.  By and large the defaults are the most\noptimum settings and should only be changed in exceptional circumstances!\n\nThe -noI, -noD and -noF options (also -noInodeCompression, -noDataCompression\nand -noFragmentCompression) can be used to force mksquashfs to not compress\ninodes/directories, data and fragments respectively.  Giving all options\ngenerates an uncompressed filesystem.\n\nThe -no-fragments tells mksquashfs to not generate fragment blocks, and rather\ngenerate a filesystem similar to a Squashfs 1.x filesystem.  It will of course\nstill be a Squashfs 2.0 filesystem but without fragments, and so it won't be\nmountable on a Squashfs 1.x system.\n\nThe -always-use-fragments option tells mksquashfs to always generate\nfragments for files irrespective of the file length.  By default only small\nfiles less than the block size are packed into fragment blocks.  The ends of\nfiles which do not fit fully into a block, are NOT by default packed into\nfragments.  To illustrate this, a 100K file has an initial 64K block and a 36K\nremainder.  This 36K remainder is not packed into a fragment by default.  This\nis because to do so leads to a 10 - 20% drop in sequential I/O performance, as a\ndisk head seek is needed to seek to the initial file data and another disk seek\nis need to seek to the fragment block.  Specify this option if you want file\nremainders to be packed into fragment blocks.  Doing so may increase the\ncompression obtained BUT at the expense of I/O speed.\n\nThe -no-duplicates option tells mksquashfs to not check the files being\nadded to the filesystem for duplicates.  This can result in quicker filesystem\ngeneration and appending although obviously compression will suffer badly if\nthere is a lot of duplicate files.\n\nThe -b option allows the block size to be selected, this can be either\n4096, 8192, 16384, 32768 or 65536 bytes.\n\n3.3 Specifying the UIDs/GIDs used in the filesystem\n---------------------------------------------------\n\nBy default files in the generated filesystem inherit the UID and GID ownership\nof the original file.  However,  mksquashfs provides a number of options which\ncan be used to override the ownership.\n\nThe options -all-root and -root-owned (both do exactly the same thing) force all\nfile uids/gids in the generated Squashfs filesystem to be root.  This allows\nroot owned filesystems to be built without root access on the host machine.\n\nThe \"-force-uid uid\"  option forces all files in the generated Squashfs\nfilesystem to be owned by the specified uid.  The uid can be specified either by\nname (i.e. \"root\") or by number.\n\nThe \"-force-gid gid\" option forces all files in the generated Squashfs\nfilesystem to be group owned by the specified gid.  The gid can be specified\neither by name (i.e. \"root\") or by number.\n\n3.4 Excluding files from the filesystem\n---------------------------------------\n\nThe -e and -ef options allow files/directories to be specified which are\nexcluded from the output filesystem.  The -e option takes the exclude\nfiles/directories from the command line, the -ef option takes the\nexlude files/directories from the specified exclude file, one file/directory\nper line. If an exclude file/directory is absolute (i.e. prefixed with /, ../,\nor ./) the entry is treated as absolute, however, if an exclude file/directory\nis relative, it is treated as being relative to each of the sources in turn,\ni.e.\n\n%mksquashfs /tmp/source1 source2  output_fs -e ex1 /tmp/source1/ex2 out/ex3\n\nWill generate exclude files /tmp/source1/ex2, /tmp/source1/ex1, source2/ex1,\n/tmp/source1/out/ex3 and source2/out/ex3.\n\nThe -e and -ef exclude options are usefully used in archiving the entire\nfilesystem, where it is wished to avoid archiving /proc, and the filesystem\nbeing generated, i.e.\n\n%mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh\n\nMultiple -ef options can be specified on the command line, and the -ef\noption can be used in conjuction with the -e option.\n\n3.5 Appending to squashfs filesystems\n-------------------------------------\n\nRunning squashfs with the destination directory containing an existing\nfilesystem will add the source items to the existing filesystem.  By default,\nthe source items are added to the existing root directory.\n\nTo make this clear... An existing filesystem \"image\" contains root entries\n\"old1\", and \"old2\".  Source directory \"/home/phillip/test\" contains  \"file1\",\n\"file2\" and \"dir1\".\n\nexample 1:\n\n%mksquashfs /home/phillip/test image\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", \"file1\", \"file2\" and\n\"dir1\"\n\nexample 2:\n\n%mksquashfs /home/phillip/test image -keep-as-directory\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", and \"test\".\nAs shown in the previous section, for single source directories\n'-keep-as-directory' adds the source directory rather than the\ncontents of the directory.\n\nexample 3:\n\n%mksquashfs /home/phillip/test image -keep-as-directory -root-becomes\noriginal-root\n\nWill create a new \"image\" with root entries \"original-root\", and \"test\".  The\n'-root-becomes' option specifies that the original root becomes a subdirectory\nin the new root, with the specified name.\n\nThe append option with file duplicate detection, means squashfs can be\nused as a simple versioning archiving filesystem. A squashfs filesystem can\nbe created with for example the linux-2.4.19 source.  Appending the linux-2.4.20\nsource will create a filesystem with the two source trees, but only the\nchanged files will take extra room, the unchanged files will be detected as\nduplicates.\n\n3.6 Miscellaneous options\n-------------------------\n\nThe -info option displays the files/directories as they are compressed and\nadded to the filesystem.  The original uncompressed size of each file\nis printed, along with DUPLICATE if the file is a duplicate of a\nfile in the filesystem.\n\nThe -le and -be options can be used to force mksquashfs to generate a little\nendian or big endian filesystem.  Normally mksquashfs will generate a\nfilesystem in the host byte order.  Squashfs, for portability, will\nmount different ordered filesystems (i.e. it can mount big endian filesystems\nrunning on a little endian machine), but these options can be used for\ngreater optimisation.\n\nThe -nopad option informs mksquashfs to not pad the filesystem to a 4K multiple.\nThis is performed by default to enable the output filesystem file to be mounted\nby loopback, which requires files to be a 4K multiple.  If the filesystem is\nbeing written to a block device, or is to be stored in a bootimage, the extra\npad bytes are not needed.\n\n4. UNSQUASHFS\n-------------\n\nUnsquashfs allows you to decompress and extract a Squashfs filesystem without\nmounting it.  It can extract the entire filesystem, or a specific\nfile or directory.\n\nThe Unsquashfs usage info is:\n\nSYNTAX: ./unsquashfs [options] filesystem [directory or file to extract]\n\t-v[ersion]\t\tprint version, licence and copyright information\n\t-i[nfo]\t\t\tprint files as they are unsquashed\n\t-l[s]\t\t\tlist filesystem only\n\t-d[est] <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\t-f[orce]\t\tif file already exists then overwrite\n\n\nTo extract a subset of the filesystem, the filename or directory\ntree that is to be extracted can now be specified on the command line.  The\nfile/directory should be specified using the full path to the file/directory\nas it appears within the Squashfs filesystem.  The file/directory will also be\nextracted to that position within the specified destination directory.\n\nThe \"-ls\" option can be used to list the contents of a filesystem without\ndecompressing the filesystem data itself.\n\nThe \"-info\" option forces Unsquashfs to print each file as it is decompressed.\n\nThe \"-dest\" option specifies the directory that is used to decompress\nthe filesystem data.  If this option is not given then the filesystem is\ndecompressed to the directory \"squashfs-root\" in the current working directory.\n\nThe \"-force\" option forces Unsquashfs to output to the destination\ndirectory even if files or directories already exist.  This allows you\nto update an existing directory tree, or to Unsquashfs to a partially\nfilled directory.  Without the \"-force\" option, Unsquashfs will\nrefuse to overwrite any existing files, or to create any directories if they\nalready exist.  This is done to protect data in case of mistakes, and\nso the \"-force\" option should be used with caution.\n\nUnsquashfs can decompress 2.x and 3.x filesystems.  Support for 1.x filesystems\nwill be added in the future.\n\n5. FILESYSTEM LAYOUT\n--------------------\n\nBrief filesystem design notes follow for the original 1.x filesystem\nlayout.  A description of the 2.x and 3.x filesystem layouts will be written\nsometime!\n\nA squashfs filesystem consists of five parts, packed together on a byte\nalignment:\n\n\t ---------------\n\t|  superblock \t|\n\t|---------------|\n\t|     data\t|\n\t|    blocks\t|\n\t|---------------|\n\t|    inodes\t|\n\t|---------------|\n\t|   directories\t|\n\t|---------------|\n\t|    uid/gid\t|\n\t|  lookup table\t|\n\t ---------------\n\nCompressed data blocks are written to the filesystem as files are read from\nthe source directory, and checked for duplicates.  Once all file data has been\nwritten the completed inode, directory and uid/gid lookup tables are written.\n\n5.1 Metadata\n------------\n\nMetadata (inodes and directories) are compressed in 8Kbyte blocks.  Each\ncompressed block is prefixed by a two byte length, the top bit is set if the\nblock is uncompressed.  A block will be uncompressed if the -noI option is set,\nor if the compressed block was larger than the uncompressed block.\n\nInodes are packed into the metadata blocks, and are not aligned to block\nboundaries, therefore inodes overlap compressed blocks.  An inode is\nidentified by a two field tuple <start address of compressed block : offset\ninto de-compressed block>.\n\nInode contents vary depending on the file type.  The base inode consists of:\n\n\tbase inode:\n\t\tInode type\n\t\tMode\n\t\tuid index\n\t\tgid index\n\nThe inode type is 4 bits in size, and the mode is 12 bits.\n\nThe uid and gid indexes are 4 bits in length.  Ordinarily, this will allow 16\nunique indexes into the uid table.  To minimise overhead, the uid index is\nused in conjunction with the spare bit in the file type to form a 48 entry\nindex as follows:\n\n\tinode type 1 - 5: uid index = uid\n\tinode type 5 -10: uid index = 16 + uid\n\tinode type 11 - 15: uid index = 32 + uid\n\nIn this way 48 unique uids are supported using 4 bits, minimising data inode\noverhead.  The 4 bit gid index is used to index into a 15 entry gid table.\nGid index 15 is used to indicate that the gid is the same as the uid.\nThis prevents the 15 entry gid table filling up with the common case where\nthe uid/gid is the same.\n\nThe data contents of symbolic links are stored immediately after the symbolic\nlink inode, inside the inode table.  This allows the normally small symbolic\nlink to be compressed as part of the inode table, achieving much greater\ncompression than if the symbolic link was compressed individually.\n\nSimilarly, the block index for regular files is stored immediately after the\nregular file inode.  The block index is a list of block lengths (two bytes\neach), rather than block addresses, saving two bytes per block.  The block\naddress for a given block is computed by the summation of the previous\nblock lengths.  This takes advantage of the fact that the blocks making up a\nfile are stored contiguously in the filesystem.  The top bit of each block\nlength is set if the block is uncompressed, either because the -noD option is\nset, or if the compressed block was larger than the uncompressed block.\n\n5.2 Directories\n---------------\n\nLike inodes, directories are packed into the metadata blocks, and are not\naligned on block boundaries, therefore directories can overlap compressed\nblocks.  A directory is, again, identified by a two field tuple\n<start address of compressed block containing directory start : offset\ninto de-compressed block>.\n\nDirectories are organised in a slightly complex way, and are not simply\na list of file names and inode tuples.  The organisation takes advantage of the\nobservation that in most cases, the inodes of the files in the directory\nwill be in the same compressed metadata block, and therefore, the\ninode tuples will have the same start block.\n\nDirectories are therefore organised in a two level list, a directory\nheader containing the shared start block value, and a sequence of\ndirectory entries, each of which share the shared start block.  A\nnew directory header is written once/if the inode start block\nchanges.  The directory header/directory entry list is repeated as many times\nas necessary.  The organisation is as follows:\n\n\tdirectory_header:\n\t\tcount (8 bits)\n\t\tinode start block (24 bits)\n\t\t\n\t\tdirectory entry: * count\n\t\t\tinode offset (13 bits)\n\t\t\tinode type (3 bits)\n\t\t\tfilename size (8 bits)\n\t\t\tfilename\n\t\t\t\nThis organisation saves on average 3 bytes per filename.\n\n5.3 File data\n-------------\n\nFile data is compressed on a block by block basis and written to the\nfilesystem.  The filesystem supports up to 32K blocks, which achieves\ngreater compression ratios than the Linux 4K page size.\n\nThe disadvantage with using greater than 4K blocks (and the reason why\nmost filesystems do not), is that the VFS reads data in 4K pages.\nThe filesystem reads and decompresses a larger block containing that page\n(e.g. 32K).  However, only 4K can be returned to the VFS, resulting in a\nvery inefficient filesystem, as 28K must be thrown away.   Squashfs,\nsolves this problem by explicitly pushing the extra pages into the page\ncache.\n\n\n6. AUTHOR INFO\n--------------\n\nSquashfs was written by Phillip Lougher, email phillip@lougher.org.uk,\nin Chepstow, Wales, UK.   If you like the program, or have any problems,\nthen please email me, as it's nice to get feedback!\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/README-3.2",
    "content": "\tSQUASHFS 3.2 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.2.  Squashfs 3.2 has support for NFS exporting,\nsome improvements to the Squashfs tools (Mksquashfs and Unsquashfs), some\nmajor bug fixes, new kernel patches, and various other smaller improvements\nand bug fixes.  Please see the CHANGES file for a detailed list.\n\n1. MKSQUASHFS\n-------------\n\nNew command line options:\n\n-no-exports\n\n\tSquashfs now supports NFS exports.  By default the additional\n\tinformation necessary is added to the filesystem by Mksquashfs.  If you\n\tdo not wish this extra information, then this option can be specified.\n\tThis will save a couple of bytes per file, and the filesystem\n\twill be identical to Squashfs 3.1.\n\n-no-progress\n\n\tMksquashfs by default now displays a progress bar. This option disables\n\tit.\n\n2. UNSQUASHFS\n-------------\n\n\tUnsquashfs now supports Squashfs 2.x filesystems.\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/sqlzma2u-3.2-r2.patch",
    "content": "Index: squashfs3.2-r2/squashfs-tools/Makefile\n===================================================================\nRCS file: squashfs3.2-r2/squashfs-tools/Makefile,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.2-r2/squashfs-tools/Makefile\t16 Jan 2007 03:32:18 -0000\t1.1\n+++ squashfs3.2-r2/squashfs-tools/Makefile\t16 Jan 2007 05:08:17 -0000\t1.2\n@@ -1,19 +1,44 @@\n+\n+ifndef Sqlzma\n+$(error Sqlzma is not defined)\n+endif\n+\n INCLUDEDIR = .\n \n CFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\n+ifdef UseDebugFlags\n+DebugFlags = -g -Wall -Wno-unused-variable -O0 -UNDEBUG\n+endif\n+CFLAGS += -I${Sqlzma} -D_REENTRANT -DNDEBUG ${DebugFlags}\n+LDLIBS += -lz -L${LzmaAlone} -L${LzmaC}\n+Tgt = mksquashfs unsquashfs\n \n-all: mksquashfs unsquashfs\n+all: ${Tgt}\n \n-mksquashfs: mksquashfs.o read_fs.o sort.o\n-\t$(CC) mksquashfs.o read_fs.o sort.o -lz -lpthread -lm -o $@\n+read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h \\\n+\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h\n \n-mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h\n+sort.o: sort.c squashfs_fs.h global.h sort.h\n \n-read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h\n+mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \\\n+\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h \\\n+\t${LzmaAlone}/liblzma_r.a ${LzmaC}/libunlzma_r.a\n \n-sort.o: sort.c squashfs_fs.h global.h sort.h\n+mksquashfs: LDLIBS += -lpthread -lunlzma_r -llzma_r -lstdc++\n+mksquashfs: mksquashfs.o read_fs.o sort.o\n+\n+unsquashfs.o: CFLAGS += -U_REENTRANT\n+unsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h \\\n+\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h ${LzmaC}/libunlzma.a\n \n+unsquashfs: LDLIBS += -lunlzma\n unsquashfs: unsquashfs.o\n-\t$(CC) unsquashfs.o -lz -o $@\n \n-unsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h\n+clean:\n+\t${RM} *~ *.o ${Tgt}\n+\n+-include test.mk\n+\n+# Local variables: ;\n+# compile-command: (concat \"make Sqlzma=../.. -f \" (file-name-nondirectory (buffer-file-name)));\n+# End: ;\nIndex: squashfs3.2-r2/squashfs-tools/mksquashfs.c\n===================================================================\nRCS file: squashfs3.2-r2/squashfs-tools/mksquashfs.c,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.2-r2/squashfs-tools/mksquashfs.c\t16 Jan 2007 03:32:18 -0000\t1.1\n+++ squashfs3.2-r2/squashfs-tools/mksquashfs.c\t16 Jan 2007 05:08:17 -0000\t1.2\n@@ -59,6 +59,8 @@\n #include \"mksquashfs.h\"\n #include \"global.h\"\n #include \"sort.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n #ifdef SQUASHFS_TRACE\n #define TRACE(s, args...)\tdo { \\\n@@ -107,6 +109,7 @@ unsigned short uid_count = 0, guid_count\n squashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\n int block_offset;\n int file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n+struct sqlzma_un un;\n \n /* write position within data section */\n long long bytes = 0, total_bytes = 0;\n@@ -326,6 +329,7 @@ struct dir_info *dir_scan1(char *, int (\n struct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\n extern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\n extern struct priority_entry *priority_list[65536];\n+int dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\n \n \n struct allocator *alloc_init(int buffer_size, int max_buffers)\n@@ -593,21 +597,7 @@ unsigned int mangle2(z_stream **strm, ch\n \t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n \t}\n \n-\tstream->next_in = (unsigned char *) s;\n-\tstream->avail_in = size;\n-\tstream->next_out = (unsigned char *) d;\n-\tstream->avail_out = block_size;\n-\n-\tres = deflate(stream, Z_FINISH);\n-\tif(res != Z_STREAM_END && res != Z_OK) {\n-\t\tif(res == Z_STREAM_ERROR)\n-\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n-\t\telse if(res == Z_BUF_ERROR)\n-\t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\\n\");\n-\t\telse\n-\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n-\t}\n-\n+\tres = sqlzma_cm(un.un_lzma, stream, s, size, d, block_size);\n \tc_byte = stream->total_out;\n \n \tif(res != Z_STREAM_END || c_byte >= size) {\n@@ -706,6 +696,7 @@ void write_bytes(int fd, long long byte,\n \t\tEXIT_MKSQUASHFS();\n \t}\n \n+\t//printf(\"%d bytes at %Ld\\n\", bytes, off);\n \tif(write(fd, buff, bytes) == -1) {\n \t\tperror(\"Write on destination failed\");\n \t\tEXIT_MKSQUASHFS();\n@@ -1220,17 +1211,17 @@ char *get_fragment(char *buffer, struct \n \t\tint res;\n \t\tunsigned long bytes = block_size;\n \t\tchar cbuffer[block_size];\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = cbuffer, .sz = size},\n+\t\t\t{.buf = buffer, .sz = bytes}\n+\t\t};\n \n \t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n-\n-\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t}\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tBAD_ERROR(\"%s:%d: res %d\\n\", __func__, __LINE__, res);\n+\t\tbytes = un.un_reslen;\n \t} else\n \t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n \n@@ -1623,7 +1614,7 @@ void reader_read_file(struct dir_ent *di\n \t\tfile_buffer->block = count;\n \t\tfile_buffer->block_order = block_order ++;\n \t\tfile_buffer->error = FALSE;\n-\t\tif(file_buffer->fragment = count == frag_block)\n+\t\tif((file_buffer->fragment = (count == frag_block))) //??\n \t\t\tqueue_put(from_deflate, file_buffer);\n \t\telse\n \t\t\tqueue_put(from_reader, file_buffer);\n@@ -1682,6 +1673,7 @@ void *reader(void *arg)\n \t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n \t\t\t\treader_read_file(entry->dir);\n \t}\n+\treturn NULL;\n }\n \n \n@@ -1711,6 +1703,7 @@ void *writer(void *arg)\n \t\t\twrite_error = TRUE;\n \t\t}\n \n+\t\t//printf(\"%d bytes at %Ld\\n\", file_buffer->size, off);\n \t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n \t\t\tperror(\"Write on destination failed\");\n \t\t\twrite_error = TRUE;\n@@ -1830,7 +1823,7 @@ int progress_bar(long long current, long\n \tint spaces = columns - used - hashes;\n \n \tif(!progress || columns - used < 0)\n-\t\treturn;\n+\t\treturn 0;\n \n \tprintf(\"\\r[\");\n \n@@ -1843,6 +1836,7 @@ int progress_bar(long long current, long\n \tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n \tprintf(\" %3lld%%\", current * 100 / max);\n \tfflush(stdout);\n+\treturn 0;\n }\n \n \n@@ -2479,7 +2473,7 @@ error:\n \n int dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n {\n-\tint squashfs_type;\n+\tint squashfs_type = -1;\n \tint result = FALSE;\n \tint duplicate_file;\n \tchar *pathname = dir_info->pathname;\n@@ -2774,7 +2768,8 @@ skip_inode_hash_table:\n \tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n \tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n \tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n-\tprintf(\"GNU General Public License for more details.\\n\");\n+\tprintf(\"GNU General Public License for more details.\\n\"); \\\n+\tprintf(\"and LZMA support for slax.org by jro.\\n\");\n int main(int argc, char *argv[])\n {\n \tstruct winsize winsize;\n@@ -2792,6 +2787,7 @@ int main(int argc, char *argv[])\n \tbe = FALSE;\n #endif\n \n+\tun.un_lzma = 1;\n \tblock_log = slog(block_size);\n \tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n \t\tVERSION();\n@@ -2947,6 +2943,8 @@ int main(int argc, char *argv[])\n \t\t\t\texit(1);\n \t\t\t}\t\n \t\t\troot_name = argv[i];\n+\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n+\t\t\tun.un_lzma = 0;\n \t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n \t\t\tVERSION();\n \t\t} else {\n@@ -3125,8 +3123,8 @@ printOptions:\n \t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n \t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n \n-\t\tcompressed_data = inode_dir_offset + inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1);\n-\t\tuncompressed_data = inode_dir_offset + inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1);\n+\t\tcompressed_data = inode_dir_offset + (inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1)); //??\n+\t\tuncompressed_data = inode_dir_offset + (inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1)); //??\n \t\t\n \t\t/* save original filesystem state for restoring ... */\n \t\tsfragments = fragments;\n@@ -3193,6 +3191,11 @@ printOptions:\n #endif\n \n \tblock_offset = check_data ? 3 : 2;\n+\ti = sqlzma_init(&un, un.un_lzma, 0);\n+\tif (i != Z_OK) {\n+\t\tERROR(\"%s:%d: %d\\n\", __func__, __LINE__, i);\n+\t\tEXIT_MKSQUASHFS();\n+\t}\n \n \tif(progress) {\n \t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n@@ -3211,7 +3214,9 @@ printOptions:\n \t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n \tsBlk.root_inode = inode;\n \tsBlk.inodes = inode_count;\n-\tsBlk.s_magic = SQUASHFS_MAGIC;\n+\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n+\tif (!un.un_lzma)\n+\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n \tsBlk.s_major = SQUASHFS_MAJOR;\n \tsBlk.s_minor = SQUASHFS_MINOR;\n \tsBlk.block_size = block_size;\nIndex: squashfs3.2-r2/squashfs-tools/read_fs.c\n===================================================================\nRCS file: squashfs3.2-r2/squashfs-tools/read_fs.c,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.2-r2/squashfs-tools/read_fs.c\t16 Jan 2007 03:32:18 -0000\t1.1\n+++ squashfs3.2-r2/squashfs-tools/read_fs.c\t16 Jan 2007 05:08:17 -0000\t1.2\n@@ -46,6 +46,8 @@ extern int add_file(long long, long long\n #include <squashfs_fs.h>\n #include \"read_fs.h\"\n #include \"global.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n #include <stdlib.h>\n \n@@ -62,6 +64,7 @@ extern int add_file(long long, long long\n \t\t\t\t\t} while(0)\n \n int swap;\n+extern struct sqlzma_un un;\n \n int read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n {\n@@ -81,19 +84,20 @@ int read_block(int fd, long long start, \n \t\tchar buffer[SQUASHFS_METADATA_SIZE];\n \t\tint res;\n \t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = buffer},\n+\t\t\t{.buf = block, .sz = bytes}\n+\t\t};\n \n \t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n \t\tread_bytes(fd, start + offset, c_byte, buffer);\n \n-\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t\treturn 0;\n-\t\t}\n+\t\tsbuf[Src].sz = c_byte;\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tabort();\n+\t\tbytes = un.un_reslen;\n \t\tif(next)\n \t\t\t*next = start + offset + c_byte;\n \t\treturn bytes;\n@@ -351,18 +355,30 @@ int read_super(int fd, squashfs_super_bl\n \n \t/* Check it is a SQUASHFS superblock */\n \tswap = 0;\n-\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n-\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n-\t\t\tsquashfs_super_block sblk;\n-\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n-\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n-\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n-\t\t\tswap = 1;\n-\t\t} else  {\n-\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n-\t\t\tgoto failed_mount;\n-\t\t}\n-\t}\n+\tswitch (sBlk->s_magic) {\n+\t\tsquashfs_super_block sblk;\n+\n+\tcase SQUASHFS_MAGIC_LZMA:\n+\t\tif (!un.un_lzma)\n+\t\t\tgoto bad;\n+\t\tbreak;\n+\tcase SQUASHFS_MAGIC:\n+\t\tbreak;\n+\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n+\t\tif (!un.un_lzma)\n+\t\t\tgoto bad;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_SWAP:\n+\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n+\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n+\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n+\t\tswap = 1;\n+\t\tbreak;\n+\tbad:\n+\tdefault:\n+\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n+\t\tgoto failed_mount;\n+ \t}\n \n \t/* Check the MAJOR & MINOR versions */\n \tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n@@ -416,7 +432,8 @@ unsigned char *squashfs_readdir(int fd, \n \tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n \tunsigned char *directory_table = NULL;\n \tint byte, bytes = 0, dir_count;\n-\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block; \n+\tlong long start = sBlk->directory_table_start + directory_start_block,\n+\t\tlast_start_block = -1;\n \n \tsize += offset;\n \tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\nIndex: squashfs3.2-r2/squashfs-tools/unsquashfs.c\n===================================================================\nRCS file: squashfs3.2-r2/squashfs-tools/unsquashfs.c,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.2-r2/squashfs-tools/unsquashfs.c\t16 Jan 2007 03:32:18 -0000\t1.1\n+++ squashfs3.2-r2/squashfs-tools/unsquashfs.c\t16 Jan 2007 05:08:18 -0000\t1.2\n@@ -46,6 +46,8 @@\n #include <squashfs_fs.h>\n #include \"read_fs.h\"\n #include \"global.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n #include <stdlib.h>\n \n@@ -97,6 +99,7 @@ unsigned int block_size;\n int lsonly = FALSE, info = FALSE, force = FALSE;\n char **created_inode;\n int root_process;\n+struct sqlzma_un un;\n \n #define CALCULATE_HASH(start)\t(start & 0xffff)\n \n@@ -144,6 +147,7 @@ int read_bytes(long long byte, int bytes\n \t\treturn FALSE;\n \t}\n \n+\t/* printf(\"%d bytes at %Ld\\n\", bytes, off); */\n \tif(read(fd, buff, bytes) == -1) {\n \t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n \t\treturn FALSE;\n@@ -175,21 +179,21 @@ int read_block(long long start, long lon\n \t\tchar buffer[SQUASHFS_METADATA_SIZE];\n \t\tint res;\n \t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = buffer},\n+\t\t\t{.buf = block, .sz = bytes}\n+\t\t};\n \n \t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n \t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n \t\t\tgoto failed;\n \n-\t\tif((res = uncompress((unsigned char *) block, &bytes,\n-\t\t(const unsigned char *) buffer, c_byte)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t\tgoto failed;\n-\t\t}\n+\t\tsbuf[Src].sz = c_byte;\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tabort();\n+\t\tbytes = un.un_reslen;\n \t\tif(next)\n \t\t\t*next = start + offset + c_byte;\n \t\treturn bytes;\n@@ -216,20 +220,19 @@ int read_data_block(long long start, uns\n \tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n \n \tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = data, .sz = c_byte},\n+\t\t\t{.buf = block, .sz = bytes}\n+\t\t};\n+\n \t\tif(read_bytes(start, c_byte, data) == FALSE)\n \t\t\treturn 0;\n \n-\t\tif((res = uncompress((unsigned char *) block, &bytes,\n-\t\t(const unsigned char *) data, c_byte)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t\treturn 0;\n-\t\t}\n-\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tabort();\n+\t\tbytes = un.un_reslen;\n \t\treturn bytes;\n \t} else {\n \t\tif(read_bytes(start, c_byte, block) == FALSE)\n@@ -660,7 +663,7 @@ int create_inode(char *pathname, unsigne\n \t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n \t\t\t\tdev_count ++;\n \t\t\t} else\n-\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n+\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n \t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n \t\t\t\t\tpathname, strerror(errno));\n \t\t\tbreak;\n@@ -818,7 +821,7 @@ int create_inode_2(char *pathname, unsig\n \t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, sBlk.mkfs_time, TRUE);\n \t\t\t\tdev_count ++;\n \t\t\t} else\n-\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n+\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n \t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n \t\t\t\t\tpathname, strerror(errno));\n \t\t\tbreak;\n@@ -1225,18 +1228,26 @@ int read_super(char *source)\n \tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n \n \t/* Check it is a SQUASHFS superblock */\n+\tun.un_lzma = 1;\n \tswap = 0;\n-\tif(sBlk.s_magic != SQUASHFS_MAGIC) {\n-\t\tif(sBlk.s_magic == SQUASHFS_MAGIC_SWAP) {\n-\t\t\tsquashfs_super_block sblk;\n-\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n-\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n-\t\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n-\t\t\tswap = 1;\n-\t\t} else  {\n-\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n-\t\t\tgoto failed_mount;\n-\t\t}\n+\tswitch (sBlk.s_magic) {\n+\t\tsquashfs_super_block sblk;\n+\tcase SQUASHFS_MAGIC:\n+\t\tun.un_lzma = 0;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_LZMA:\n+\t\tbreak;\n+\tcase SQUASHFS_MAGIC_SWAP:\n+\t\tun.un_lzma = 0;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n+\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n+\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n+\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n+\t\tswap = 1;\n+\tdefault:\n+\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n+\t\tgoto failed_mount;\n \t}\n \n \t/* Check the MAJOR & MINOR versions */\n@@ -1305,14 +1316,15 @@ failed_mount:\n \tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n \tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n \tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n-\tprintf(\"GNU General Public License for more details.\\n\");\n+\tprintf(\"GNU General Public License for more details.\\n\"); \\\n+\tprintf(\"and LZMA support for slax.org by jro.\\n\");\n int main(int argc, char *argv[])\n {\n \tchar *dest = \"squashfs-root\";\n \tint i, version = FALSE;\n \tchar *target = \"\";\n \n-\tif(root_process = geteuid() == 0)\n+\tif((root_process = (geteuid() == 0))) //??\n \t\tumask(0);\n \t\n \tfor(i = 1; i < argc; i++) {\n@@ -1371,6 +1383,11 @@ options:\n \t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n \n \tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n+\ti = sqlzma_init(&un, un.un_lzma, 0);\n+\tif (i != Z_OK) {\n+\t\tfputs(\"sqlzma_init failed\", stderr);\n+\t\tabort();\n+\t}\n \n \tread_uids_guids();\n \ts_ops.read_fragment_table();\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/Makefile",
    "content": "\n\nINCLUDEDIR = .\n\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\nifdef UseDebugFlags\nDebugFlags = -g -Wall -Wno-unused-variable -O0 -UNDEBUG\nendif\nCFLAGS += -I${Sqlzma} -D_REENTRANT -DNDEBUG ${DebugFlags}\nLDLIBS += -lz -lm -L${LzmaAlone} -L${LzmaC}\nTgt = mksquashfs unsquashfs\n\nall: ${Tgt}\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h \\\n\t${LzmaAlone}/liblzma_r.a ${LzmaC}/libunlzma_r.a\n\nmksquashfs: LDLIBS += -lpthread -lunlzma_r -llzma_r -lstdc++\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\nunsquashfs.o: CFLAGS += -U_REENTRANT\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h ${LzmaC}/libunlzma.a\n\nunsquashfs: LDLIBS += -lunlzma\nunsquashfs: unsquashfs.o\n\t$(CC) unsquashfs.o -o unsquashfs $(LDLIBS) -lz\n\nclean:\n\t${RM} *~ *.o ${Tgt}\n\n-include test.mk\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\nstruct sqlzma_un un;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* data allocator status struct.  Allocators are used to keep\n  track of memory buffers passed between different threads */\nstruct allocator {\n\tint\t\tmax_buffers;\n\tint\t\tcount;\n\tint\t\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t\twait;\n};\n\n/* struct describing a memory buffer passed between threads */\nstruct file_buffer {\n\tstruct allocator\t*allocator;\n\tvoid\t\t\t(*release)(int);\n\tint\t\t\trelease_data;\n\tlong long\t\tblock;\n\tint\t\t\tsize;\n\tint\t\t\tc_byte;\n\tunsigned int\t\tblock_order;\n\tint\t\t\tfragment;\n\tint\t\t\terror;\n\tstruct file_buffer\t*next;\n\tchar\t\t\tdata[0];\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n/* describes the list of blocks in a file which is a possible\n   duplicate.  For each block, it indicates whether the block is\n   in memory or on disk */\nstruct buffer_list {\n\tlong long start;\n\tint size;\n\tstruct file_buffer *read_buffer;\n};\n\nstruct allocator *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\nextern struct priority_entry *priority_list[65536];\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\n\n\nstruct allocator *alloc_init(int buffer_size, int max_buffers)\n{\n\tstruct allocator *allocator = malloc(sizeof(struct allocator));\n\n\tif(allocator == NULL)\n\t\treturn NULL;\n\n\tallocator->max_buffers = max_buffers;\n\tallocator->buffer_size = buffer_size;\n\tallocator->count = 0;\n\tpthread_mutex_init(&allocator->mutex, NULL);\n\tpthread_cond_init(&allocator->wait, NULL);\n\n\treturn allocator;\n}\n\n\nstruct file_buffer *alloc_get(struct allocator *allocator)\n{\n\tstruct file_buffer *file_buffer;\n\t\n\tpthread_mutex_lock(&allocator->mutex);\n\n\twhile(allocator->count == allocator->max_buffers)\n\t\tpthread_cond_wait(&allocator->wait, &allocator->mutex);\n\n\tif((file_buffer = malloc(sizeof(struct file_buffer) + allocator->buffer_size)) == NULL)\n\t\tgoto failed;\n\n\tfile_buffer->release = NULL;\n\tfile_buffer->allocator = allocator;\n\tallocator->count ++;\n\nfailed:\n\tpthread_mutex_unlock(&allocator->mutex);\n\treturn file_buffer;\n}\n\n\nstruct file_buffer *alloc_get_2(struct allocator *allocator, void (*release)(int), int release_data)\n{\n\tstruct file_buffer *file_buffer = alloc_get(allocator);\n\n\tif(file_buffer) {\n\t\tfile_buffer->release = release;\n\t\tfile_buffer->release_data = release_data;\n\t}\n\treturn file_buffer;\n}\n\n\nvoid alloc_free(struct file_buffer *file_buffer)\n{\n\tstruct allocator *allocator;\n\n\tif(file_buffer == NULL)\n\t\treturn;\n\n\tallocator = file_buffer->allocator;\n\n\tif(file_buffer->release)\n\t\tfile_buffer->release(file_buffer->release_data);\n\n\tpthread_mutex_lock(&allocator->mutex);\n\tfree(file_buffer);\n\tif(allocator->count == 0)\n\t\tERROR(\"alloc_free: freeing buffer for empty allocator!\\n\");\n\telse\n\t\tallocator->count --;\n\tpthread_cond_signal(&allocator->wait);\n\tpthread_mutex_unlock(&allocator->mutex);\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\n\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t}\n\n\tstruct sqlzma_opts sqopts;\n\tsqopts.try_lzma=un.un_lzma;\n\tsqopts.dicsize=64435;\n\tres = sqlzma_cm(&sqopts, stream, s, size, d, block_size);\n\n\tc_byte = stream->total_out;\n\n\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\t//printf(\"%d bytes at %Ld\\n\", bytes, off);\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\treturn FALSE;\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nint write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir) {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir) == FALSE)\n\t\t\treturn FALSE;\n\t} else {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL) == FALSE)\n\t\t\treturn FALSE;\n\t}\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn TRUE;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment, int *cached_fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\n\tif(fragment->index == *cached_fragment || fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn buffer + fragment->offset;\n\n\tif(fragment_data && fragment->index == fragments)\n\t\treturn fragment_data->data + fragment->offset;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragment_table[fragment->index].pending)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = cbuffer, .sz = size},\n\t\t\t{.buf = buffer, .sz = bytes}\n\t\t};\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tBAD_ERROR(\"%s:%d: res %d\\n\", __func__, __LINE__, res);\n\t\tbytes = un.un_reslen;\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\t*cached_fragment = fragment->index;\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid ensure_fragments_flushed()\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragments_outstanding)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].pending = TRUE;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\nvoid frag_release(int block)\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragment_table[block].pending = FALSE;\n\tpthread_cond_signal(&fragment_waiting);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = alloc_get(fragment_buffer);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint avail_bytes, compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tlong long slist[meta_blocks];\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_buffer(struct buffer_list *buffer_list, unsigned int blocks)\n{\n\tunsigned short chksum = 0;\n\tint block;\n\n\tfor(block = 0; block < blocks; block ++) {\n\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\tif(b->read_buffer)\n\t\t\tchksum = get_checksum(b->read_buffer->data, b->read_buffer->size, chksum);\n\t\telse\n\t\t\tchksum = get_checksum(read_from_disk(b->start, b->size), b->size, chksum);\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\nint cached_frag = -1;\nchar fragdata[SQUASHFS_FILE_MAX_SIZE];\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tchar *datap;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\nchar cached_fragment[SQUASHFS_FILE_SIZE];\nint cached_frag1 = -1;\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), file_size);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tchar buffer2[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tchar *buffer;\n\t\t\tint block;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_buffer(buffer_list, blocks);\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), frag_bytes);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\t\t\tif(b->read_buffer)\n\t\t\t\t\tbuffer = b->read_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tbuffer = read_from_disk(b->start, b->size);\n\n\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\n\t\t\t\tif(memcmp(buffer, buffer2, b->size) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_start += b->size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tchar *fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1);\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tint count;\n\tint blocks = (buf->st_size + block_size - 1) >> block_log;\n\tint frag_block = !no_fragments && (always_use_fragments ||\n\t\t(buf->st_size < block_size)) ? buf->st_size >> block_log : -1;\n\tint file;\n\tstatic int block_order = 0;\n\tstruct file_buffer *file_buffer;\n\n\tif(buf->st_size == 0 || dir_ent->inode->read)\n\t\treturn;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tfor(count = 0; count < blocks; count ++) {\n\t\tfile_buffer = alloc_get(reader_buffer);\n\n\t\tif((file_buffer->size = read(file, file_buffer->data, block_size)) == -1) {\n\t\t\tclose(file);\n\t\t\tgoto read_err2;\n\t\t}\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->block_order = block_order ++;\n\t\tfile_buffer->error = FALSE;\n\t\tif((file_buffer->fragment = (count == frag_block))) //??\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\telse\n\t\t\tqueue_put(from_reader, file_buffer);\n\t}\n\n\tclose(file);\n\tdir_ent->inode->read = TRUE;\n\n\treturn;\n\nread_err:\n\tfile_buffer = alloc_get(reader_buffer);\nread_err2:\n\tfile_buffer->block_order = block_order ++;\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\treturn NULL;\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tperror(\"Lseek on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\t//printf(\"%d bytes at %Ld\\n\", file_buffer->size, off);\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n\t\t\tperror(\"Write on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer = alloc_get(writer_buffer);\n\n\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\n\t\twrite_buffer->block = file_buffer->block;\n\t\twrite_buffer->block_order = file_buffer->block_order;\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\n\t\twrite_buffer->fragment = FALSE;\n\t\twrite_buffer->error = FALSE;\n\t\talloc_free(file_buffer);\n\t\tqueue_put(from_deflate, write_buffer);\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer = alloc_get_2(writer_buffer, frag_release, file_buffer->block);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\twrite_buffer->size = compressed_size;\n\t\twrite_buffer->block = bytes;\n\t\tqueue_put(to_writer, write_buffer);\n\t\tbytes += compressed_size;\n\t\ttotal_uncompressed += file_buffer->size;\n\t\ttotal_compressed += compressed_size;\n\t\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\n\t\tfragments_outstanding --;\n\t\tpthread_cond_signal(&fragment_waiting);\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->block_order);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int block_order = 0;\n\tint hash = BLOCK_HASH(block_order);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->block_order == block_order)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->block_order == block_order)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tblock_order ++;\n\n\treturn file_buffer;\n}\n\n\nint progress_bar(long long current, long long max, int columns)\n{\n\tint max_digits = ceil(log10(max));\n\tint used = max_digits * 2 + 10;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(!progress || columns - used < 0)\n\t\treturn 0;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n\treturn 0;\n}\n\n\nint write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n}\n\n\nint write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\n{\n\tint file;\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\talloc_free(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\tstruct file_buffer *file_buffer = get_file_buffer(from_deflate);\n\n\tif(file_buffer->error) {\n\t\talloc_free(file_buffer);\n\t\treturn FALSE;\n\t}\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum))\n\t\treturn write_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\talloc_free(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size)\n{\n\tint block, status;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list;\n\tstruct file_buffer *read_buffer;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\t\tqueue_put(to_writer, read_buffer);\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t} else\n\t\tread_buffer = NULL;\n\n\tfragment = get_and_fill_fragment(read_buffer);\n\talloc_free(read_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, int *duplicate_file)\n{\n\tint block, status, thresh;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer *read_buffer;\n\tstruct file_data *file_data;\n\tstruct buffer_list *buffer_list;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tthresh = blocks > (writer_buffer_size - processors) ? blocks - (writer_buffer_size - processors): 0;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\n\t\tif(block < thresh) {\n\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\tqueue_put(to_writer, read_buffer);\n\t\t} else\n\t\t\tbuffer_list[block].read_buffer = read_buffer;\n\t\tbuffer_list[block].start = read_buffer->block;\n\t\tbuffer_list[block].size = read_buffer->size;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t} else\n\t\tread_buffer = NULL;\n\n\tqueue_put(to_writer, NULL);\n\tif(queue_get(from_writer) != 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\n\t\tfragment = get_and_fill_fragment(read_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\talloc_free(buffer_list[block].read_buffer);\n\t\tbytes = buffer_list[0].start;\n\t\tif(thresh && !block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\n\talloc_free(read_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block && thresh) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\talloc_free(buffer_list[blocks].read_buffer);\n\tfree(buffer_list);\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)\n{\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %lld bytes\\n\", dir_ent->pathname, SQUASHFS_MAX_FILE_SIZE);\n\n\tif(read_size == 0)\n\t\treturn write_file_empty(inode, dir_ent, duplicate_file);\n\n\tif(!no_fragments && (read_size < block_size))\n\t\treturn write_file_frag(inode, dir_ent, read_size, duplicate_file);\n\n\tif(pre_duplicate(read_size))\n\t\treturn write_file_blocks_dup(inode, dir_ent, read_size, duplicate_file);\n\n\t*duplicate_file = FALSE;\n\treturn write_file_blocks(inode, dir_ent, read_size);\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFREG)\n\t\t\testimated_uncompressed += (buf.st_size + block_size - 1) >> block_log;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\n\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type = -1;\n\tint result = FALSE;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\tresult = write_file(inode, dir_ent, buf->st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tresult = dir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n\t\t\t\t}\n\t\t\tif(result)\n\t\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult = TRUE;\n\t\t}\n\t\t\n\n\t\tif(result)\n\t\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\tresult = write_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n\n\treturn result;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 16; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(processors * 2);\n\treader_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, reader_buffer_size);\n\twriter_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, writer_buffer_size);\n\tfragment_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, processors * 2);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\n\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\n}\n\n\t\t\t\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.2-r2 (2007/01/15)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\"); \\\n\tprintf(\"and LZMA support for slax.org by jro.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct winsize winsize;\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tun.un_lzma = 1;\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n\t\t\tun.un_lzma = 0;\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t} else  {\n\t\tsignal(SIGTERM, sighandler2);\n\t\tsignal(SIGINT, sighandler2);\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tinitialise_threads();\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t\t\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + (inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1)); //??\n\t\tuncompressed_data = inode_dir_offset + (inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1)); //??\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tERROR(\"%s:%d: %d\\n\", __func__, __LINE__, i);\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(progress) {\n\t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\t\tcolumns = 80;\n\t\t} else\n\t\t\tcolumns = winsize.ws_col;\n\t\tsignal(SIGWINCH, sigwinch_handler);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n\tif (!un.un_lzma)\n\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tensure_fragments_flushed();\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\tclose(fd);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\nextern struct sqlzma_un un;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = buffer},\n\t\t\t{.buf = block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk->s_magic) {\n\t\tsquashfs_super_block sblk;\n\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\tbreak;\n\tcase SQUASHFS_MAGIC:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\n\tbad:\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3.0 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is %d.%d, I support 3.0\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %xllx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block,\n\t\tlast_start_block = -1;\n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tlong long sindex[indexes];\n\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_inode_t sinode;\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\n\t\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern squashfs_inode write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\tif(write_file(&inode, entry->dir, entry->dir->inode->buf.st_size,\n\t\t\t\t\t\t\t&duplicate_file)) {\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n *  Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir\t*(*squashfs_opendir)(unsigned int block_start, unsigned int offset);\n\tchar \t\t*(*read_fragment)(unsigned int fragment);\n\tvoid\t\t(*read_fragment_table)();\n\tint\t\t(*create_inode)(char *pathname, unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE, force = FALSE;\nchar **created_inode;\nint root_process;\nstruct sqlzma_un un;\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\t/* printf(\"%d bytes at %Ld\\n\", bytes, off); */\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = buffer},\n\t\t\t{.buf = block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = data, .sz = c_byte},\n\t\t\t{.buf = block, .sz = bytes}\n\t\t};\n\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, unsigned int mode, unsigned int uid,\nunsigned int guid, unsigned int mtime, unsigned int set_mode)\n{\n\tstruct utimbuf times = { (time_t) mtime, (time_t) mtime };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tuid_t uid_value = (uid_t) uid_table[uid];\n\t\tuid_t guid_value = guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[guid];\n\n\t\tif(chown(pathname, uid_value, guid_value) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nchar *read_fragment_2(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint write_file(char *pathname, unsigned int fragment, unsigned int frag_bytes,\nunsigned int offset, unsigned int blocks, long long start, char *block_ptr,\nunsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write(file_fd, file_data, bytes) < bytes) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = s_ops.read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write(file_fd, fragment_data + offset, frag_bytes) < frag_bytes) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\t\t\n\nint create_inode(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tif(created_inode[header.base.inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[header.base.inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\theader.base.mtime, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[header.base.inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nint create_inode_2(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header_2 header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, sBlk.mkfs_time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\tsBlk.mkfs_time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header_2 header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nint matches(char *targname, char *name)\n{\n\tif(*targname == '\\0' || strcmp(targname, name) == 0)\n\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, char *target)\n{\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tchar targname[1024];\n\n\ttarget = get_component(target, targname);\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(targname, name))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(lsonly || info)\n\t\t\tprintf(\"%s\\n\", pathname);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, target);\n\t\telse\n\t\t\tif(!lsonly)\n\t\t\t\ts_ops.create_inode(pathname, start_block, offset);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nint read_super(char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tun.un_lzma = 1;\n\tswap = 0;\n\tswitch (sBlk.s_magic) {\n\t\tsquashfs_super_block sblk;\n\tcase SQUASHFS_MAGIC:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\n\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\ts_ops.read_fragment = read_fragment_2;\n\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\ts_ops.create_inode = create_inode_2;\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor == 0) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.create_inode = create_inode;\n\t} else {\n\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d)\\n\",\n\t\t\t\tsource, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"I support Squashfs 2.x and 3.0 filesystems!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\n\tTRACE(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not\" : \"\");\n\tTRACE(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tTRACE(\"\\tBlock size %d\\n\", sBlk.block_size);\n\tTRACE(\"\\tNumber of fragments %d\\n\", sBlk.fragments);\n\tTRACE(\"\\tNumber of inodes %d\\n\", sBlk.inodes);\n\tTRACE(\"\\tNumber of uids %d\\n\", sBlk.no_uids);\n\tTRACE(\"\\tNumber of gids %d\\n\", sBlk.no_guids);\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.3 (2007/01/02)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\"); \\\n\tprintf(\"and LZMA support for slax.org by jro.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, version = FALSE;\n\tchar *target = \"\";\n\n\tif((root_process = (geteuid() == 0))) //??\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc)\n\t\t\t\tgoto options;\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directory or file to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem only\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tif((i + 1) < argc)\n\t\ttarget = argv[i + 1];\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tblock_size = sBlk.block_size;\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tfputs(\"sqlzma_init failed\", stderr);\n\t\tabort();\n\t}\n\n\tread_uids_guids();\n\ts_ops.read_fragment_table();\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), target);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/Makefile",
    "content": "CC = gcc\n\nSRCBASE = .\nINCLUDEDIR = -I$(SRCBASE)/include -I.\nLZMADIR = $(SRCBASE)/lzma_src/C\n\nCFLAGS := $(INCLUDEDIR) -I$(LZMADIR) -I$(LINUXDIR)/include -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\n\nLZMAOBJS = LzmaEnc.o LzFind.o LzmaDec.o\nMKOBJS = mksquashfs.o read_fs.o sort.o sqlzma.o\n\nall: mksquashfs unsquashfs\n\n$(LZMAOBJS): %.o: $(LZMADIR)/%.c\n\t$(CC) -c $(CFLAGS) $(CPPFLAGS) $^ -o $@\n\nmksquashfs: $(MKOBJS) $(LZMAOBJS)\n\t$(CC) $(MKOBJS) $(LZMAOBJS) -lz -lpthread -lm -lstdc++ -o $@\n\nunsquashfs: unsquashfs.o $(LZMAOBJS)\n\t$(CC) unsquashfs.o  sqlzma.o $(LZMAOBJS) -lz -lpthread -lm -o $@\n\nclean:\n\t-rm -f *.o mksquashfs unsquashfs\n\ninstall: mksquashfs unsquashfs\n\tmkdir -p $(INSTALL_DIR)\n\tcp mksquashfs unsquashfs $(INSTALL_DIR)\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/lzma_src/C/Alloc.h",
    "content": "/* Alloc.h -- Memory allocation functions\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size);\r\nvoid MyFree(void *address);\r\n\r\n#ifdef _WIN32\r\n\r\nvoid SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size);\r\nvoid MidFree(void *address);\r\nvoid *BigAlloc(size_t size);\r\nvoid BigFree(void *address);\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/lzma_src/C/LzFind.c",
    "content": "/* LzFind.c -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"LzFind.h\"\r\n#include \"LzHash.h\"\r\n\r\n#define kEmptyHashValue 0\r\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\r\n#define kMaxHistorySize ((UInt32)3 << 30)\r\n\r\n#define kStartMaxLen 3\r\n\r\nstatic void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  if (!p->directInput)\r\n  {\r\n    alloc->Free(alloc, p->bufferBase);\r\n    p->bufferBase = 0;\r\n  }\r\n}\r\n\r\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r\n\r\nstatic int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r\n{\r\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r\n  if (p->directInput)\r\n  {\r\n    p->blockSize = blockSize;\r\n    return 1;\r\n  }\r\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\r\n  {\r\n    LzInWindow_Free(p, alloc);\r\n    p->blockSize = blockSize;\r\n    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r\n  }\r\n  return (p->bufferBase != 0);\r\n}\r\n\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r\n\r\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r\n\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r\n{\r\n  p->posLimit -= subValue;\r\n  p->pos -= subValue;\r\n  p->streamPos -= subValue;\r\n}\r\n\r\nstatic void MatchFinder_ReadBlock(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached || p->result != SZ_OK)\r\n    return;\r\n  for (;;)\r\n  {\r\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\r\n    size_t size = (p->bufferBase + p->blockSize - dest);\r\n    if (size == 0)\r\n      return;\r\n    p->result = p->stream->Read(p->stream, dest, &size);\r\n    if (p->result != SZ_OK)\r\n      return;\r\n    if (size == 0)\r\n    {\r\n      p->streamEndWasReached = 1;\r\n      return;\r\n    }\r\n    p->streamPos += (UInt32)size;\r\n    if (p->streamPos - p->pos > p->keepSizeAfter)\r\n      return;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\r\n{\r\n  memmove(p->bufferBase,\r\n    p->buffer - p->keepSizeBefore,\r\n    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\r\n  p->buffer = p->bufferBase + p->keepSizeBefore;\r\n}\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p)\r\n{\r\n  /* if (p->streamEndWasReached) return 0; */\r\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r\n}\r\n\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached)\r\n    return;\r\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\r\n    MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r\n{\r\n  if (MatchFinder_NeedMove(p))\r\n    MatchFinder_MoveBlock(p);\r\n  MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_SetDefaultSettings(CMatchFinder *p)\r\n{\r\n  p->cutValue = 32;\r\n  p->btMode = 1;\r\n  p->numHashBytes = 4;\r\n  /* p->skipModeBits = 0; */\r\n  p->directInput = 0;\r\n  p->bigHash = 0;\r\n}\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  p->bufferBase = 0;\r\n  p->directInput = 0;\r\n  p->hash = 0;\r\n  MatchFinder_SetDefaultSettings(p);\r\n\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    p->crc[i] = r;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hash);\r\n  p->hash = 0;\r\n}\r\n\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  MatchFinder_FreeThisClassMemory(p, alloc);\r\n  LzInWindow_Free(p, alloc);\r\n}\r\n\r\nstatic CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r\n{\r\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r\n  if (sizeInBytes / sizeof(CLzRef) != num)\r\n    return 0;\r\n  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r\n}\r\n\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 sizeReserv;\r\n  if (historySize > kMaxHistorySize)\r\n  {\r\n    MatchFinder_Free(p, alloc);\r\n    return 0;\r\n  }\r\n  sizeReserv = historySize >> 1;\r\n  if (historySize > ((UInt32)2 << 30))\r\n    sizeReserv = historySize >> 2;\r\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r\n\r\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r\n  if (LzInWindow_Create(p, sizeReserv, alloc))\r\n  {\r\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r\n    UInt32 hs;\r\n    p->matchMaxLen = matchMaxLen;\r\n    {\r\n      p->fixedHashSize = 0;\r\n      if (p->numHashBytes == 2)\r\n        hs = (1 << 16) - 1;\r\n      else\r\n      {\r\n        hs = historySize - 1;\r\n        hs |= (hs >> 1);\r\n        hs |= (hs >> 2);\r\n        hs |= (hs >> 4);\r\n        hs |= (hs >> 8);\r\n        hs >>= 1;\r\n        /* hs >>= p->skipModeBits; */\r\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r\n        if (hs > (1 << 24))\r\n        {\r\n          if (p->numHashBytes == 3)\r\n            hs = (1 << 24) - 1;\r\n          else\r\n            hs >>= 1;\r\n        }\r\n      }\r\n      p->hashMask = hs;\r\n      hs++;\r\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r\n      hs += p->fixedHashSize;\r\n    }\r\n\r\n    {\r\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\r\n      UInt32 newSize;\r\n      p->historySize = historySize;\r\n      p->hashSizeSum = hs;\r\n      p->cyclicBufferSize = newCyclicBufferSize;\r\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r\n      newSize = p->hashSizeSum + p->numSons;\r\n      if (p->hash != 0 && prevSize == newSize)\r\n        return 1;\r\n      MatchFinder_FreeThisClassMemory(p, alloc);\r\n      p->hash = AllocRefs(newSize, alloc);\r\n      if (p->hash != 0)\r\n      {\r\n        p->son = p->hash + p->hashSizeSum;\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  MatchFinder_Free(p, alloc);\r\n  return 0;\r\n}\r\n\r\nstatic void MatchFinder_SetLimits(CMatchFinder *p)\r\n{\r\n  UInt32 limit = kMaxValForNormalize - p->pos;\r\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  limit2 = p->streamPos - p->pos;\r\n  if (limit2 <= p->keepSizeAfter)\r\n  {\r\n    if (limit2 > 0)\r\n      limit2 = 1;\r\n  }\r\n  else\r\n    limit2 -= p->keepSizeAfter;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  {\r\n    UInt32 lenLimit = p->streamPos - p->pos;\r\n    if (lenLimit > p->matchMaxLen)\r\n      lenLimit = p->matchMaxLen;\r\n    p->lenLimit = lenLimit;\r\n  }\r\n  p->posLimit = p->pos + limit;\r\n}\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->hashSizeSum; i++)\r\n    p->hash[i] = kEmptyHashValue;\r\n  p->cyclicBufferPos = 0;\r\n  p->buffer = p->bufferBase;\r\n  p->pos = p->streamPos = p->cyclicBufferSize;\r\n  p->result = SZ_OK;\r\n  p->streamEndWasReached = 0;\r\n  MatchFinder_ReadBlock(p);\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r\n{\r\n  return (p->pos - p->historySize - 1) & kNormalizeMask;\r\n}\r\n\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_Normalize(CMatchFinder *p)\r\n{\r\n  UInt32 subValue = MatchFinder_GetSubValue(p);\r\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r\n  MatchFinder_ReduceOffsets(p, subValue);\r\n}\r\n\r\nstatic void MatchFinder_CheckLimits(CMatchFinder *p)\r\n{\r\n  if (p->pos == kMaxValForNormalize)\r\n    MatchFinder_Normalize(p);\r\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r\n    MatchFinder_CheckAndMoveAndRead(p);\r\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\r\n    p->cyclicBufferPos = 0;\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  son[_cyclicBufferPos] = curMatch;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n      return distances;\r\n    {\r\n      const Byte *pb = cur - delta;\r\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r\n      {\r\n        UInt32 len = 0;\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n            return distances;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return distances;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return distances;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        {\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define MOVE_POS \\\r\n  ++p->cyclicBufferPos; \\\r\n  p->buffer++; \\\r\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r\n\r\n#define MOVE_POS_RET MOVE_POS return offset;\r\n\r\nstatic void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r\n\r\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\r\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\r\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\r\n  cur = p->buffer;\r\n\r\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r\n\r\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r\n\r\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\r\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\r\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\r\n\r\n#define SKIP_FOOTER \\\r\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r\n\r\nstatic UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(2)\r\n  HASH2_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 1)\r\n}\r\n\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 2)\r\n}\r\n\r\nstatic UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, delta2, maxLen, offset;\r\n  GET_MATCHES_HEADER(3)\r\n\r\n  HASH3_CALC;\r\n\r\n  delta2 = p->pos - p->hash[hash2Value];\r\n  curMatch = p->hash[kFix3HashSize + hashValue];\r\n  \r\n  p->hash[hash2Value] =\r\n  p->hash[kFix3HashSize + hashValue] = p->pos;\r\n\r\n\r\n  maxLen = 2;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[0] = maxLen;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n  \r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n\r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      p->son[p->cyclicBufferPos] = curMatch;\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances + offset, maxLen) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances, 2) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nstatic void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(2)\r\n    HASH2_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value;\r\n    SKIP_HEADER(3)\r\n    HASH3_CALC;\r\n    curMatch = p->hash[kFix3HashSize + hashValue];\r\n    p->hash[hash2Value] =\r\n    p->hash[kFix3HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] =\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r\n  if (!p->btMode)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 2)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 3)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r\n  }\r\n  else\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/lzma_src/C/LzFind.h",
    "content": "/* LzFind.h -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFIND_H\r\n#define __LZFIND_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef UInt32 CLzRef;\r\n\r\ntypedef struct _CMatchFinder\r\n{\r\n  Byte *buffer;\r\n  UInt32 pos;\r\n  UInt32 posLimit;\r\n  UInt32 streamPos;\r\n  UInt32 lenLimit;\r\n\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r\n\r\n  UInt32 matchMaxLen;\r\n  CLzRef *hash;\r\n  CLzRef *son;\r\n  UInt32 hashMask;\r\n  UInt32 cutValue;\r\n\r\n  Byte *bufferBase;\r\n  ISeqInStream *stream;\r\n  int streamEndWasReached;\r\n\r\n  UInt32 blockSize;\r\n  UInt32 keepSizeBefore;\r\n  UInt32 keepSizeAfter;\r\n\r\n  UInt32 numHashBytes;\r\n  int directInput;\r\n  int btMode;\r\n  /* int skipModeBits; */\r\n  int bigHash;\r\n  UInt32 historySize;\r\n  UInt32 fixedHashSize;\r\n  UInt32 hashSizeSum;\r\n  UInt32 numSons;\r\n  SRes result;\r\n  UInt32 crc[256];\r\n} CMatchFinder;\r\n\r\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r\n\r\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p);\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p);\r\n\r\n/* Conditions:\r\n     historySize <= 3 GB\r\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r\n*/\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc);\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *distances, UInt32 maxLen);\r\n\r\n/*\r\nConditions:\r\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r\n*/\r\n\r\ntypedef void (*Mf_Init_Func)(void *object);\r\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\r\n\r\ntypedef struct _IMatchFinder\r\n{\r\n  Mf_Init_Func Init;\r\n  Mf_GetIndexByte_Func GetIndexByte;\r\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r\n  Mf_GetMatches_Func GetMatches;\r\n  Mf_Skip_Func Skip;\r\n} IMatchFinder;\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p);\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/lzma_src/C/LzHash.h",
    "content": "/* LzHash.h -- HASH functions for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZHASH_H\r\n#define __LZHASH_H\r\n\r\n#define kHash2Size (1 << 10)\r\n#define kHash3Size (1 << 16)\r\n#define kHash4Size (1 << 20)\r\n\r\n#define kFix3HashSize (kHash2Size)\r\n#define kFix4HashSize (kHash2Size + kHash3Size)\r\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r\n\r\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r\n\r\n#define HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r\n\r\n#define HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r\n\r\n#define HASH5_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\\r\n  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\\r\n  hash4Value &= (kHash4Size - 1); }\r\n\r\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r\n\r\n\r\n#define MT_HASH2_CALC \\\r\n  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r\n\r\n#define MT_HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r\n\r\n#define MT_HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/lzma_src/C/LzmaDec.c",
    "content": "/* LzmaDec.c -- LZMA Decoder\r\n2008-11-06 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzmaDec.h\"\r\n#ifndef BCMLZMA\r\n#include <string.h>\r\n#endif\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_INIT_SIZE 5\r\n\r\n#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));\r\n#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \\\r\n  { UPDATE_0(p); i = (i + i); A0; } else \\\r\n  { UPDATE_1(p); i = (i + i) + 1; A1; }\r\n#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)\r\n\r\n#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }\r\n#define TREE_DECODE(probs, limit, i) \\\r\n  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }\r\n\r\n/* #define _LZMA_SIZE_OPT */\r\n\r\n#ifdef _LZMA_SIZE_OPT\r\n#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)\r\n#else\r\n#define TREE_6_DECODE(probs, i) \\\r\n  { i = 1; \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  i -= 0x40; }\r\n#endif\r\n\r\n#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0_CHECK range = bound;\r\n#define UPDATE_1_CHECK range -= bound; code -= bound;\r\n#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \\\r\n  { UPDATE_0_CHECK; i = (i + i); A0; } else \\\r\n  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }\r\n#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)\r\n#define TREE_DECODE_CHECK(probs, limit, i) \\\r\n  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols)\r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nstatic const Byte kLiteralNextStates[kNumStates * 2] =\r\n{\r\n  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\r\n  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\r\n};\r\n\r\n#define LZMA_DIC_MIN (1 << 12)\r\n\r\n/* First LZMA-symbol is always decoded.\r\nAnd it decodes new LZMA-symbols while (buf < bufLimit), but \"buf\" is without last normalization\r\nOut:\r\n  Result:\r\n    SZ_OK - OK\r\n    SZ_ERROR_DATA - Error\r\n  p->remainLen:\r\n    < kMatchSpecLenStart : normal remain\r\n    = kMatchSpecLenStart : finished\r\n    = kMatchSpecLenStart + 1 : Flush marker\r\n    = kMatchSpecLenStart + 2 : State Init Marker\r\n*/\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  CLzmaProb *probs = p->probs;\r\n\r\n  unsigned state = p->state;\r\n  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];\r\n  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;\r\n  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;\r\n  unsigned lc = p->prop.lc;\r\n\r\n  Byte *dic = p->dic;\r\n  SizeT dicBufSize = p->dicBufSize;\r\n  SizeT dicPos = p->dicPos;\r\n  \r\n  UInt32 processedPos = p->processedPos;\r\n  UInt32 checkDicSize = p->checkDicSize;\r\n  unsigned len = 0;\r\n\r\n  const Byte *buf = p->buf;\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n\r\n  do\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = processedPos & pbMask;\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0(prob)\r\n    {\r\n      unsigned symbol;\r\n      UPDATE_0(prob);\r\n      prob = probs + Literal;\r\n      if (checkDicSize != 0 || processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r\n        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        symbol = 1;\r\n        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      dic[dicPos++] = (Byte)symbol;\r\n      processedPos++;\r\n\r\n      state = kLiteralNextStates[state];\r\n      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\r\n      continue;\r\n    }\r\n    else\r\n    {\r\n      UPDATE_1(prob);\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0(prob)\r\n      {\r\n        UPDATE_0(prob);\r\n        state += kNumStates;\r\n        prob = probs + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1(prob);\r\n        if (checkDicSize == 0 && processedPos == 0)\r\n          return SZ_ERROR_DATA;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0(prob)\r\n        {\r\n          UPDATE_0(prob);\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n            dicPos++;\r\n            processedPos++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            continue;\r\n          }\r\n          UPDATE_1(prob);\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UPDATE_1(prob);\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            distance = rep1;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(prob);\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0(prob)\r\n            {\r\n              UPDATE_0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0(probLen)\r\n        {\r\n          UPDATE_0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = (1 << kLenNumLowBits);\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0(probLen)\r\n          {\r\n            UPDATE_0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = (1 << kLenNumMidBits);\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = (1 << kLenNumHighBits);\r\n          }\r\n        }\r\n        TREE_DECODE(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state >= kNumStates)\r\n      {\r\n        UInt32 distance;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);\r\n        TREE_6_DECODE(prob, distance);\r\n        if (distance >= kStartPosModelIndex)\r\n        {\r\n          unsigned posSlot = (unsigned)distance;\r\n          int numDirectBits = (int)(((distance >> 1) - 1));\r\n          distance = (2 | (distance & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            distance <<= numDirectBits;\r\n            prob = probs + SpecPos + distance - posSlot - 1;\r\n            {\r\n              UInt32 mask = 1;\r\n              unsigned i = 1;\r\n              do\r\n              {\r\n                GET_BIT2(prob + i, i, ; , distance |= mask);\r\n                mask <<= 1;\r\n              }\r\n              while (--numDirectBits != 0);\r\n            }\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE\r\n              range >>= 1;\r\n              \r\n              {\r\n                UInt32 t;\r\n                code -= range;\r\n                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */\r\n                distance = (distance << 1) + (t + 1);\r\n                code += range & t;\r\n              }\r\n              /*\r\n              distance <<= 1;\r\n              if (code >= range)\r\n              {\r\n                code -= range;\r\n                distance |= 1;\r\n              }\r\n              */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            distance <<= kNumAlignBits;\r\n            {\r\n              unsigned i = 1;\r\n              GET_BIT2(prob + i, i, ; , distance |= 1);\r\n              GET_BIT2(prob + i, i, ; , distance |= 2);\r\n              GET_BIT2(prob + i, i, ; , distance |= 4);\r\n              GET_BIT2(prob + i, i, ; , distance |= 8);\r\n            }\r\n            if (distance == (UInt32)0xFFFFFFFF)\r\n            {\r\n              len += kMatchSpecLenStart;\r\n              state -= kNumStates;\r\n              break;\r\n            }\r\n          }\r\n        }\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        rep0 = distance + 1;\r\n        if (checkDicSize == 0)\r\n        {\r\n          if (distance >= processedPos)\r\n            return SZ_ERROR_DATA;\r\n        }\r\n        else if (distance >= checkDicSize)\r\n          return SZ_ERROR_DATA;\r\n        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r\n        /* state = kLiteralNextStates[state]; */\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n\r\n      if (limit == dicPos)\r\n        return SZ_ERROR_DATA;\r\n      {\r\n        SizeT rem = limit - dicPos;\r\n        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\r\n        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\r\n\r\n        processedPos += curLen;\r\n\r\n        len -= curLen;\r\n        if (pos + curLen <= dicBufSize)\r\n        {\r\n          Byte *dest = dic + dicPos;\r\n          int src = (int)pos - (int)dicPos;\r\n          const Byte *lim = dest + curLen;\r\n          dicPos += curLen;\r\n          do\r\n            *(dest) = (Byte)*(dest + src);\r\n          while (++dest != lim);\r\n        }\r\n        else\r\n        {\r\n          do\r\n          {\r\n            dic[dicPos++] = dic[pos];\r\n            if (++pos == dicBufSize)\r\n              pos = 0;\r\n          }\r\n          while (--curLen != 0);\r\n        }\r\n      }\r\n    }\r\n  }\r\n  while (dicPos < limit && buf < bufLimit);\r\n  NORMALIZE;\r\n  p->buf = buf;\r\n  p->range = range;\r\n  p->code = code;\r\n  p->remainLen = len;\r\n  p->dicPos = dicPos;\r\n  p->processedPos = processedPos;\r\n  p->reps[0] = rep0;\r\n  p->reps[1] = rep1;\r\n  p->reps[2] = rep2;\r\n  p->reps[3] = rep3;\r\n  p->state = state;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\r\n{\r\n  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\r\n  {\r\n    Byte *dic = p->dic;\r\n    SizeT dicPos = p->dicPos;\r\n    SizeT dicBufSize = p->dicBufSize;\r\n    unsigned len = p->remainLen;\r\n    UInt32 rep0 = p->reps[0];\r\n    if (limit - dicPos < len)\r\n      len = (unsigned)(limit - dicPos);\r\n\r\n    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r\n      p->checkDicSize = p->prop.dicSize;\r\n\r\n    p->processedPos += len;\r\n    p->remainLen -= len;\r\n    while (len-- != 0)\r\n    {\r\n      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n      dicPos++;\r\n    }\r\n    p->dicPos = dicPos;\r\n  }\r\n}\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  do\r\n  {\r\n    SizeT limit2 = limit;\r\n    if (p->checkDicSize == 0)\r\n    {\r\n      UInt32 rem = p->prop.dicSize - p->processedPos;\r\n      if (limit - p->dicPos > rem)\r\n        limit2 = p->dicPos + rem;\r\n    }\r\n    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r\n    if (p->processedPos >= p->prop.dicSize)\r\n      p->checkDicSize = p->prop.dicSize;\r\n    LzmaDec_WriteRem(p, limit);\r\n  }\r\n  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r\n\r\n  if (p->remainLen > kMatchSpecLenStart)\r\n  {\r\n    p->remainLen = kMatchSpecLenStart;\r\n  }\r\n  return 0;\r\n}\r\n\r\ntypedef enum\r\n{\r\n  DUMMY_ERROR, /* unexpected end of input stream */\r\n  DUMMY_LIT,\r\n  DUMMY_MATCH,\r\n  DUMMY_REP\r\n} ELzmaDummy;\r\n\r\nstatic ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\r\n{\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n  const Byte *bufLimit = buf + inSize;\r\n  CLzmaProb *probs = p->probs;\r\n  unsigned state = p->state;\r\n  ELzmaDummy res;\r\n\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0_CHECK(prob)\r\n    {\r\n      UPDATE_0_CHECK\r\n\r\n      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\r\n\r\n      prob = probs + Literal;\r\n      if (p->checkDicSize != 0 || p->processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE *\r\n          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r\n          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        unsigned symbol = 1;\r\n        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r\n            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        unsigned symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      res = DUMMY_LIT;\r\n    }\r\n    else\r\n    {\r\n      unsigned len;\r\n      UPDATE_1_CHECK;\r\n\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0_CHECK(prob)\r\n      {\r\n        UPDATE_0_CHECK;\r\n        state = 0;\r\n        prob = probs + LenCoder;\r\n        res = DUMMY_MATCH;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1_CHECK;\r\n        res = DUMMY_REP;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0_CHECK(prob)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            NORMALIZE_CHECK;\r\n            return DUMMY_REP;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0_CHECK(prob)\r\n            {\r\n              UPDATE_0_CHECK;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1_CHECK;\r\n            }\r\n          }\r\n        }\r\n        state = kNumStates;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0_CHECK(probLen)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = 1 << kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0_CHECK(probLen)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = 1 << kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = 1 << kLenNumHighBits;\r\n          }\r\n        }\r\n        TREE_DECODE_CHECK(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        unsigned posSlot;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<\r\n            kNumPosSlotBits);\r\n        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n\r\n          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE_CHECK\r\n              range >>= 1;\r\n              code -= range & (((code - range) >> 31) - 1);\r\n              /* if (code >= range) code -= range; */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            unsigned i = 1;\r\n            do\r\n            {\r\n              GET_BIT_CHECK(prob + i, i);\r\n            }\r\n            while (--numDirectBits != 0);\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  NORMALIZE_CHECK;\r\n  return res;\r\n}\r\n\r\n\r\nstatic void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\r\n{\r\n  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\r\n  p->range = 0xFFFFFFFF;\r\n  p->needFlush = 0;\r\n}\r\n\r\nstatic void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r\n{\r\n  p->needFlush = 1;\r\n  p->remainLen = 0;\r\n  p->tempBufSize = 0;\r\n\r\n  if (initDic)\r\n  {\r\n    p->processedPos = 0;\r\n    p->checkDicSize = 0;\r\n    p->needInitState = 1;\r\n  }\r\n  if (initState)\r\n    p->needInitState = 1;\r\n}\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p)\r\n{\r\n  p->dicPos = 0;\r\n  LzmaDec_InitDicAndState(p, True, True);\r\n}\r\n\r\nstatic void LzmaDec_InitStateReal(CLzmaDec *p)\r\n{\r\n  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\r\n  UInt32 i;\r\n  CLzmaProb *probs = p->probs;\r\n  for (i = 0; i < numProbs; i++)\r\n    probs[i] = kBitModelTotal >> 1;\r\n  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;\r\n  p->state = 0;\r\n  p->needInitState = 0;\r\n}\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\r\n    ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT inSize = *srcLen;\r\n  (*srcLen) = 0;\r\n  LzmaDec_WriteRem(p, dicLimit);\r\n  \r\n  *status = LZMA_STATUS_NOT_SPECIFIED;\r\n\r\n  while (p->remainLen != kMatchSpecLenStart)\r\n  {\r\n      int checkEndMarkNow;\r\n\r\n      if (p->needFlush != 0)\r\n      {\r\n        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r\n          p->tempBuf[p->tempBufSize++] = *src++;\r\n        if (p->tempBufSize < RC_INIT_SIZE)\r\n        {\r\n          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n          return SZ_OK;\r\n        }\r\n        if (p->tempBuf[0] != 0)\r\n          return SZ_ERROR_DATA;\r\n\r\n        LzmaDec_InitRc(p, p->tempBuf);\r\n        p->tempBufSize = 0;\r\n      }\r\n\r\n      checkEndMarkNow = 0;\r\n      if (p->dicPos >= dicLimit)\r\n      {\r\n        if (p->remainLen == 0 && p->code == 0)\r\n        {\r\n          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;\r\n          return SZ_OK;\r\n        }\r\n        if (finishMode == LZMA_FINISH_ANY)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_OK;\r\n        }\r\n        if (p->remainLen != 0)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_ERROR_DATA;\r\n        }\r\n        checkEndMarkNow = 1;\r\n      }\r\n\r\n      if (p->needInitState)\r\n        LzmaDec_InitStateReal(p);\r\n  \r\n      if (p->tempBufSize == 0)\r\n      {\r\n        SizeT processed;\r\n        const Byte *bufLimit;\r\n        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            memcpy(p->tempBuf, src, inSize);\r\n            p->tempBufSize = (unsigned)inSize;\r\n            (*srcLen) += inSize;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n          bufLimit = src;\r\n        }\r\n        else\r\n          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\r\n        p->buf = src;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\r\n          return SZ_ERROR_DATA;\r\n        processed = (SizeT)(p->buf - src);\r\n        (*srcLen) += processed;\r\n        src += processed;\r\n        inSize -= processed;\r\n      }\r\n      else\r\n      {\r\n        unsigned rem = p->tempBufSize, lookAhead = 0;\r\n        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\r\n          p->tempBuf[rem++] = src[lookAhead++];\r\n        p->tempBufSize = rem;\r\n        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            (*srcLen) += lookAhead;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n        }\r\n        p->buf = p->tempBuf;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r\n          return SZ_ERROR_DATA;\r\n        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\r\n        (*srcLen) += lookAhead;\r\n        src += lookAhead;\r\n        inSize -= lookAhead;\r\n        p->tempBufSize = 0;\r\n      }\r\n  }\r\n  if (p->code == 0)\r\n    *status = LZMA_STATUS_FINISHED_WITH_MARK;\r\n  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT outSize = *destLen;\r\n  SizeT inSize = *srcLen;\r\n  *srcLen = *destLen = 0;\r\n  for (;;)\r\n  {\r\n    SizeT inSizeCur = inSize, outSizeCur, dicPos;\r\n    ELzmaFinishMode curFinishMode;\r\n    SRes res;\r\n    if (p->dicPos == p->dicBufSize)\r\n      p->dicPos = 0;\r\n    dicPos = p->dicPos;\r\n    if (outSize > p->dicBufSize - dicPos)\r\n    {\r\n      outSizeCur = p->dicBufSize;\r\n      curFinishMode = LZMA_FINISH_ANY;\r\n    }\r\n    else\r\n    {\r\n      outSizeCur = dicPos + outSize;\r\n      curFinishMode = finishMode;\r\n    }\r\n\r\n    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);\r\n    src += inSizeCur;\r\n    inSize -= inSizeCur;\r\n    *srcLen += inSizeCur;\r\n    outSizeCur = p->dicPos - dicPos;\r\n    memcpy(dest, p->dic + dicPos, outSizeCur);\r\n    dest += outSizeCur;\r\n    outSize -= outSizeCur;\r\n    *destLen += outSizeCur;\r\n    if (res != 0)\r\n      return res;\r\n    if (outSizeCur == 0 || outSize == 0)\r\n      return SZ_OK;\r\n  }\r\n}\r\n\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->probs);\r\n  p->probs = 0;\r\n}\r\n\r\nstatic void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->dic);\r\n  p->dic = 0;\r\n}\r\n\r\nvoid LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  LzmaDec_FreeProbs(p, alloc);\r\n  LzmaDec_FreeDict(p, alloc);\r\n}\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)\r\n{\r\n  UInt32 dicSize;\r\n  Byte d;\r\n  \r\n  if (size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  else\r\n    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);\r\n \r\n  if (dicSize < LZMA_DIC_MIN)\r\n    dicSize = LZMA_DIC_MIN;\r\n  p->dicSize = dicSize;\r\n\r\n  d = data[0];\r\n  if (d >= (9 * 5 * 5))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  p->lc = d % 9;\r\n  d /= 9;\r\n  p->pb = d / 5;\r\n  p->lp = d % 5;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r\n{\r\n  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r\n  if (p->probs == 0 || numProbs != p->numProbs)\r\n  {\r\n    LzmaDec_FreeProbs(p, alloc);\r\n    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r\n    p->numProbs = numProbs;\r\n    if (p->probs == 0)\r\n      return SZ_ERROR_MEM;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  SizeT dicBufSize;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  dicBufSize = propNew.dicSize;\r\n  if (p->dic == 0 || dicBufSize != p->dicBufSize)\r\n  {\r\n    LzmaDec_FreeDict(p, alloc);\r\n    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r\n    if (p->dic == 0)\r\n    {\r\n      LzmaDec_FreeProbs(p, alloc);\r\n      return SZ_ERROR_MEM;\r\n    }\r\n  }\r\n  p->dicBufSize = dicBufSize;\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc)\r\n{\r\n  CLzmaDec p;\r\n  SRes res;\r\n  SizeT inSize = *srcLen;\r\n  SizeT outSize = *destLen;\r\n  *srcLen = *destLen = 0;\r\n  if (inSize < RC_INIT_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  LzmaDec_Construct(&p);\r\n  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\r\n  if (res != 0)\r\n    return res;\r\n  p.dic = dest;\r\n  p.dicBufSize = outSize;\r\n\r\n  LzmaDec_Init(&p);\r\n  \r\n  *srcLen = inSize;\r\n  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r\n\r\n  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r\n    res = SZ_ERROR_INPUT_EOF;\r\n\r\n  (*destLen) = p.dicPos;\r\n  LzmaDec_FreeProbs(&p, alloc);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/lzma_src/C/LzmaDec.h",
    "content": "/* LzmaDec.h -- LZMA Decoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMADEC_H\r\n#define __LZMADEC_H\r\n\r\n#include \"Types.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* _LZMA_PROB32 can increase the speed on some CPUs,\r\n   but memory usage for CLzmaDec::probs will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n\r\n/* ---------- LZMA Properties ---------- */\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaProps\r\n{\r\n  unsigned lc, lp, pb;\r\n  UInt32 dicSize;\r\n} CLzmaProps;\r\n\r\n/* LzmaProps_Decode - decodes properties\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);\r\n\r\n\r\n/* ---------- LZMA Decoder state ---------- */\r\n\r\n/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.\r\n   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */\r\n\r\n#define LZMA_REQUIRED_INPUT_MAX 20\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProps prop;\r\n  CLzmaProb *probs;\r\n  Byte *dic;\r\n  const Byte *buf;\r\n  UInt32 range, code;\r\n  SizeT dicPos;\r\n  SizeT dicBufSize;\r\n  UInt32 processedPos;\r\n  UInt32 checkDicSize;\r\n  unsigned state;\r\n  UInt32 reps[4];\r\n  unsigned remainLen;\r\n  int needFlush;\r\n  int needInitState;\r\n  UInt32 numProbs;\r\n  unsigned tempBufSize;\r\n  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];\r\n} CLzmaDec;\r\n\r\n#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p);\r\n\r\n/* There are two types of LZMA streams:\r\n     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.\r\n     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_FINISH_ANY,   /* finish at any point */\r\n  LZMA_FINISH_END    /* block must be finished at the end */\r\n} ELzmaFinishMode;\r\n\r\n/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!\r\n\r\n   You must use LZMA_FINISH_END, when you know that current output buffer\r\n   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.\r\n\r\n   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,\r\n   and output value of destLen will be less than output buffer size limit.\r\n   You can check status result also.\r\n\r\n   You can use multiple checks to test data integrity after full decompression:\r\n     1) Check Result and \"status\" variable.\r\n     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.\r\n        You must use correct finish mode in that case. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */\r\n  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\r\n  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */\r\n  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */\r\n  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */\r\n} ELzmaStatus;\r\n\r\n/* ELzmaStatus is used only as output value for function call */\r\n\r\n\r\n/* ---------- Interfaces ---------- */\r\n\r\n/* There are 3 levels of interfaces:\r\n     1) Dictionary Interface\r\n     2) Buffer Interface\r\n     3) One Call Interface\r\n   You can select any of these interfaces, but don't mix functions from different\r\n   groups for same object. */\r\n\r\n\r\n/* There are two variants to allocate state for Dictionary Interface:\r\n     1) LzmaDec_Allocate / LzmaDec_Free\r\n     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs\r\n   You can use variant 2, if you set dictionary buffer manually.\r\n   For Buffer Interface you must always use variant 1.\r\n\r\nLzmaDec_Allocate* can return:\r\n  SZ_OK\r\n  SZ_ERROR_MEM         - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n   \r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);\r\n\r\n/* ---------- Dictionary Interface ---------- */\r\n\r\n/* You can use it, if you want to eliminate the overhead for data copying from\r\n   dictionary to some other external buffer.\r\n   You must work with CLzmaDec variables directly in this interface.\r\n\r\n   STEPS:\r\n     LzmaDec_Constr()\r\n     LzmaDec_Allocate()\r\n     for (each new stream)\r\n     {\r\n       LzmaDec_Init()\r\n       while (it needs more decompression)\r\n       {\r\n         LzmaDec_DecodeToDic()\r\n         use data from CLzmaDec::dic and update CLzmaDec::dicPos\r\n       }\r\n     }\r\n     LzmaDec_Free()\r\n*/\r\n\r\n/* LzmaDec_DecodeToDic\r\n   \r\n   The decoding to internal dictionary buffer (CLzmaDec::dic).\r\n   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (dicLimit).\r\n  LZMA_FINISH_ANY - Decode just dicLimit bytes.\r\n  LZMA_FINISH_END - Stream must be finished after dicLimit.\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_NEEDS_MORE_INPUT\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- Buffer Interface ---------- */\r\n\r\n/* It's zlib-like interface.\r\n   See LzmaDec_DecodeToDic description for information about STEPS and return results,\r\n   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need\r\n   to work with CLzmaDec variables manually.\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n*/\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaDecode\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n  SZ_ERROR_MEM  - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n*/\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/lzma_src/C/LzmaEnc.c",
    "content": "/* LzmaEnc.c -- LZMA Encoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n/* #define SHOW_STAT */\r\n/* #define SHOW_STAT2 */\r\n\r\n#if defined(SHOW_STAT) || defined(SHOW_STAT2)\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"LzmaEnc.h\"\r\n\r\n#include \"LzFind.h\"\r\n#ifdef COMPRESS_MF_MT\r\n#include \"LzFindMt.h\"\r\n#endif\r\n\r\n#ifdef SHOW_STAT\r\nstatic int ttt = 0;\r\n#endif\r\n\r\n#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)\r\n\r\n#define kBlockSize (9 << 10)\r\n#define kUnpackBlockSize (1 << 18)\r\n#define kMatchArraySize (1 << 21)\r\n#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)\r\n\r\n#define kNumMaxDirectBits (31)\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n#define kProbInitValue (kBitModelTotal >> 1)\r\n\r\n#define kNumMoveReducingBits 4\r\n#define kNumBitPriceShiftBits 4\r\n#define kBitPrice (1 << kNumBitPriceShiftBits)\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p)\r\n{\r\n/* The default dictionary size is 16M, it is too big for CFE heap memory size (400K).\r\n * The lzma_compression_level is between 1 to 5 and dictionary size is \r\n * (1<< (lzma_compression_level*2+14)).\r\n */\r\n\tp->level = 1;\r\n  p->dictSize = p->mc = 0;\r\n  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\r\n  p->writeEndMark = 0;\r\n}\r\n\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p)\r\n{\r\n  int level = p->level;\r\n  if (level < 0) level = 5;\r\n  p->level = level;\r\n  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));\r\n  if (p->lc < 0) p->lc = 3;\r\n  if (p->lp < 0) p->lp = 0;\r\n  if (p->pb < 0) p->pb = 2;\r\n  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);\r\n  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);\r\n  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);\r\n  if (p->numHashBytes < 0) p->numHashBytes = 4;\r\n  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\r\n  if (p->numThreads < 0) p->numThreads = ((p->btMode && p->algo) ? 2 : 1);\r\n}\r\n\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n  return props.dictSize;\r\n}\r\n\r\n/* #define LZMA_LOG_BSR */\r\n/* Define it for Intel's CPU */\r\n\r\n\r\n#ifdef LZMA_LOG_BSR\r\n\r\n#define kDicLogSizeMaxCompress 30\r\n\r\n#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }\r\n\r\nUInt32 GetPosSlot1(UInt32 pos)\r\n{\r\n  UInt32 res;\r\n  BSR2_RET(pos, res);\r\n  return res;\r\n}\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }\r\n\r\n#else\r\n\r\n#define kNumLogBits (9 + (int)sizeof(size_t) / 2)\r\n#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)\r\n\r\nvoid LzmaEnc_FastPosInit(Byte *g_FastPos)\r\n{\r\n  int c = 2, slotFast;\r\n  g_FastPos[0] = 0;\r\n  g_FastPos[1] = 1;\r\n  \r\n  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)\r\n  {\r\n    UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n    UInt32 j;\r\n    for (j = 0; j < k; j++, c++)\r\n      g_FastPos[c] = (Byte)slotFast;\r\n  }\r\n}\r\n\r\n#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \\\r\n  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \\\r\n  res = p->g_FastPos[pos >> i] + (i * 2); }\r\n/*\r\n#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \\\r\n  p->g_FastPos[pos >> 6] + 12 : \\\r\n  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }\r\n*/\r\n\r\n#define GetPosSlot1(pos) p->g_FastPos[pos]\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }\r\n\r\n#endif\r\n\r\n\r\n#define LZMA_NUM_REPS 4\r\n\r\ntypedef unsigned CState;\r\n\r\ntypedef struct _COptimal\r\n{\r\n  UInt32 price;\r\n\r\n  CState state;\r\n  int prev1IsChar;\r\n  int prev2;\r\n\r\n  UInt32 posPrev2;\r\n  UInt32 backPrev2;\r\n\r\n  UInt32 posPrev;\r\n  UInt32 backPrev;\r\n  UInt32 backs[LZMA_NUM_REPS];\r\n} COptimal;\r\n\r\n#define kNumOpts (1 << 12)\r\n\r\n#define kNumLenToPosStates 4\r\n#define kNumPosSlotBits 6\r\n#define kDicLogSizeMin 0\r\n#define kDicLogSizeMax 32\r\n#define kDistTableSizeMax (kDicLogSizeMax * 2)\r\n\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n#define kAlignMask (kAlignTableSize - 1)\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)\r\n\r\n#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n#define LZMA_PB_MAX 4\r\n#define LZMA_LC_MAX 8\r\n#define LZMA_LP_MAX 4\r\n\r\n#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)\r\n\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define LZMA_MATCH_LEN_MIN 2\r\n#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)\r\n\r\n#define kNumStates 12\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb choice;\r\n  CLzmaProb choice2;\r\n  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];\r\n  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];\r\n  CLzmaProb high[kLenNumHighSymbols];\r\n} CLenEnc;\r\n\r\ntypedef struct\r\n{\r\n  CLenEnc p;\r\n  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\r\n  UInt32 tableSize;\r\n  UInt32 counters[LZMA_NUM_PB_STATES_MAX];\r\n} CLenPriceEnc;\r\n\r\ntypedef struct _CRangeEnc\r\n{\r\n  UInt32 range;\r\n  Byte cache;\r\n  UInt64 low;\r\n  UInt64 cacheSize;\r\n  Byte *buf;\r\n  Byte *bufLim;\r\n  Byte *bufBase;\r\n  ISeqOutStream *outStream;\r\n  UInt64 processed;\r\n  SRes res;\r\n} CRangeEnc;\r\n\r\ntypedef struct _CSeqInStreamBuf\r\n{\r\n  ISeqInStream funcTable;\r\n  const Byte *data;\r\n  SizeT rem;\r\n} CSeqInStreamBuf;\r\n\r\nstatic SRes MyRead(void *pp, void *data, size_t *size)\r\n{\r\n  size_t curSize = *size;\r\n  CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;\r\n  if (p->rem < curSize)\r\n    curSize = p->rem;\r\n  memcpy(data, p->data, curSize);\r\n  p->rem -= curSize;\r\n  p->data += curSize;\r\n  *size = curSize;\r\n  return SZ_OK;\r\n}\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n} CSaveState;\r\n\r\ntypedef struct _CLzmaEnc\r\n{\r\n  IMatchFinder matchFinder;\r\n  void *matchFinderObj;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Bool mtMode;\r\n  CMatchFinderMt matchFinderMt;\r\n  #endif\r\n\r\n  CMatchFinder matchFinderBase;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte pad[128];\r\n  #endif\r\n  \r\n  UInt32 optimumEndIndex;\r\n  UInt32 optimumCurrentIndex;\r\n\r\n  UInt32 longestMatchLength;\r\n  UInt32 numPairs;\r\n  UInt32 numAvail;\r\n  COptimal opt[kNumOpts];\r\n  \r\n  #ifndef LZMA_LOG_BSR\r\n  Byte g_FastPos[1 << kNumLogBits];\r\n  #endif\r\n\r\n  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];\r\n  UInt32 numFastBytes;\r\n  UInt32 additionalOffset;\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n\r\n  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n  UInt32 alignPrices[kAlignTableSize];\r\n  UInt32 alignPriceCount;\r\n\r\n  UInt32 distTableSize;\r\n\r\n  unsigned lc, lp, pb;\r\n  unsigned lpMask, pbMask;\r\n\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  unsigned lclp;\r\n\r\n  Bool fastMode;\r\n  \r\n  CRangeEnc rc;\r\n\r\n  Bool writeEndMark;\r\n  UInt64 nowPos64;\r\n  UInt32 matchPriceCount;\r\n  Bool finished;\r\n  Bool multiThread;\r\n\r\n  SRes result;\r\n  UInt32 dictSize;\r\n  UInt32 matchFinderCycles;\r\n\r\n  ISeqInStream *inStream;\r\n  CSeqInStreamBuf seqBufInStream;\r\n\r\n  CSaveState saveState;\r\n} CLzmaEnc;\r\n\r\nvoid LzmaEnc_SaveState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CSaveState *dest = &p->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nvoid LzmaEnc_RestoreState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *dest = (CLzmaEnc *)pp;\r\n  const CSaveState *p = &dest->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n\r\n  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||\r\n      props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))\r\n    return SZ_ERROR_PARAM;\r\n  p->dictSize = props.dictSize;\r\n  p->matchFinderCycles = props.mc;\r\n  {\r\n    unsigned fb = props.fb;\r\n    if (fb < 5)\r\n      fb = 5;\r\n    if (fb > LZMA_MATCH_LEN_MAX)\r\n      fb = LZMA_MATCH_LEN_MAX;\r\n    p->numFastBytes = fb;\r\n  }\r\n  p->lc = props.lc;\r\n  p->lp = props.lp;\r\n  p->pb = props.pb;\r\n  p->fastMode = (props.algo == 0);\r\n  p->matchFinderBase.btMode = props.btMode;\r\n  {\r\n    UInt32 numHashBytes = 4;\r\n    if (props.btMode)\r\n    {\r\n      if (props.numHashBytes < 2)\r\n        numHashBytes = 2;\r\n      else if (props.numHashBytes < 4)\r\n        numHashBytes = props.numHashBytes;\r\n    }\r\n    p->matchFinderBase.numHashBytes = numHashBytes;\r\n  }\r\n\r\n  p->matchFinderBase.cutValue = props.mc;\r\n\r\n  p->writeEndMark = props.writeEndMark;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  /*\r\n  if (newMultiThread != _multiThread)\r\n  {\r\n    ReleaseMatchFinder();\r\n    _multiThread = newMultiThread;\r\n  }\r\n  */\r\n  p->multiThread = (props.numThreads > 1);\r\n  #endif\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nstatic const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nstatic const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nstatic const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n#define IsCharState(s) ((s) < 7)\r\n\r\n#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)\r\n\r\n#define kInfinityPrice (1 << 30)\r\n\r\nstatic void RangeEnc_Construct(CRangeEnc *p)\r\n{\r\n  p->outStream = 0;\r\n  p->bufBase = 0;\r\n}\r\n\r\n#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)\r\n\r\n#define RC_BUF_SIZE (1 << 16)\r\nstatic int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  if (p->bufBase == 0)\r\n  {\r\n    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);\r\n    if (p->bufBase == 0)\r\n      return 0;\r\n    p->bufLim = p->bufBase + RC_BUF_SIZE;\r\n  }\r\n  return 1;\r\n}\r\n\r\nstatic void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->bufBase);\r\n  p->bufBase = 0;\r\n}\r\n\r\nstatic void RangeEnc_Init(CRangeEnc *p)\r\n{\r\n  /* Stream.Init(); */\r\n  p->low = 0;\r\n  p->range = 0xFFFFFFFF;\r\n  p->cacheSize = 1;\r\n  p->cache = 0;\r\n\r\n  p->buf = p->bufBase;\r\n\r\n  p->processed = 0;\r\n  p->res = SZ_OK;\r\n}\r\n\r\nstatic void RangeEnc_FlushStream(CRangeEnc *p)\r\n{\r\n  size_t num;\r\n  if (p->res != SZ_OK)\r\n    return;\r\n  num = p->buf - p->bufBase;\r\n  if (num != p->outStream->Write(p->outStream, p->bufBase, num))\r\n    p->res = SZ_ERROR_WRITE;\r\n  p->processed += num;\r\n  p->buf = p->bufBase;\r\n}\r\n\r\nstatic void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)\r\n{\r\n  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)\r\n  {\r\n    Byte temp = p->cache;\r\n    do\r\n    {\r\n      Byte *buf = p->buf;\r\n      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));\r\n      p->buf = buf;\r\n      if (buf == p->bufLim)\r\n        RangeEnc_FlushStream(p);\r\n      temp = 0xFF;\r\n    }\r\n    while (--p->cacheSize != 0);\r\n    p->cache = (Byte)((UInt32)p->low >> 24);\r\n  }\r\n  p->cacheSize++;\r\n  p->low = (UInt32)p->low << 8;\r\n}\r\n\r\nstatic void RangeEnc_FlushData(CRangeEnc *p)\r\n{\r\n  int i;\r\n  for (i = 0; i < 5; i++)\r\n    RangeEnc_ShiftLow(p);\r\n}\r\n\r\nstatic void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)\r\n{\r\n  do\r\n  {\r\n    p->range >>= 1;\r\n    p->low += p->range & (0 - ((value >> --numBits) & 1));\r\n    if (p->range < kTopValue)\r\n    {\r\n      p->range <<= 8;\r\n      RangeEnc_ShiftLow(p);\r\n    }\r\n  }\r\n  while (numBits != 0);\r\n}\r\n\r\nstatic void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)\r\n{\r\n  UInt32 ttt = *prob;\r\n  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;\r\n  if (symbol == 0)\r\n  {\r\n    p->range = newBound;\r\n    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;\r\n  }\r\n  else\r\n  {\r\n    p->low += newBound;\r\n    p->range -= newBound;\r\n    ttt -= ttt >> kNumMoveBits;\r\n  }\r\n  *prob = (CLzmaProb)ttt;\r\n  if (p->range < kTopValue)\r\n  {\r\n    p->range <<= 8;\r\n    RangeEnc_ShiftLow(p);\r\n  }\r\n}\r\n\r\nstatic void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)\r\n{\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nstatic void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)\r\n{\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nvoid LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\r\n{\r\n  UInt32 i;\r\n  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))\r\n  {\r\n    const int kCyclesBits = kNumBitPriceShiftBits;\r\n    UInt32 w = i;\r\n    UInt32 bitCount = 0;\r\n    int j;\r\n    for (j = 0; j < kCyclesBits; j++)\r\n    {\r\n      w = w * w;\r\n      bitCount <<= 1;\r\n      while (w >= ((UInt32)1 << 16))\r\n      {\r\n        w >>= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);\r\n  }\r\n}\r\n\r\n\r\n#define GET_PRICE(prob, symbol) \\\r\n  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICEa(prob, symbol) \\\r\n  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\n#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\nstatic UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\nstatic UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\n\r\nstatic void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0;)\r\n  {\r\n    UInt32 bit;\r\n    i--;\r\n    bit = (symbol >> i) & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n}\r\n\r\nstatic void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = 0; i < numBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= (1 << numBitLevels);\r\n  while (symbol != 1)\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);\r\n    symbol >>= 1;\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += GET_PRICEa(probs[m], bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\n\r\nstatic void LenEnc_Init(CLenEnc *p)\r\n{\r\n  unsigned i;\r\n  p->choice = p->choice2 = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)\r\n    p->low[i] = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)\r\n    p->mid[i] = kProbInitValue;\r\n  for (i = 0; i < kLenNumHighSymbols; i++)\r\n    p->high[i] = kProbInitValue;\r\n}\r\n\r\nstatic void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)\r\n{\r\n  if (symbol < kLenNumLowSymbols)\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 0);\r\n    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);\r\n  }\r\n  else\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 1);\r\n    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 0);\r\n      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 1);\r\n      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)\r\n{\r\n  UInt32 a0 = GET_PRICE_0a(p->choice);\r\n  UInt32 a1 = GET_PRICE_1a(p->choice);\r\n  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);\r\n  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kLenNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);\r\n  }\r\n  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);\r\n}\r\n\r\nstatic void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);\r\n  p->counters[posState] = p->tableSize;\r\n}\r\n\r\nstatic void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)\r\n{\r\n  UInt32 posState;\r\n  for (posState = 0; posState < numPosStates; posState++)\r\n    LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\nstatic void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_Encode(&p->p, rc, symbol, posState);\r\n  if (updatePrice)\r\n    if (--p->counters[posState] == 0)\r\n      LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\n\r\n\r\n\r\nstatic void MovePos(CLzmaEnc *p, UInt32 num)\r\n{\r\n  #ifdef SHOW_STAT\r\n  ttt += num;\r\n  printf(\"\\n MovePos %d\", num);\r\n  #endif\r\n  if (num != 0)\r\n  {\r\n    p->additionalOffset += num;\r\n    p->matchFinder.Skip(p->matchFinderObj, num);\r\n  }\r\n}\r\n\r\nstatic UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)\r\n{\r\n  UInt32 lenRes = 0, numPairs;\r\n  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);\r\n  #ifdef SHOW_STAT\r\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numPairs / 2);\r\n  ttt++;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < numPairs; i += 2)\r\n      printf(\"%2d %6d   | \", p->matches[i], p->matches[i + 1]);\r\n  }\r\n  #endif\r\n  if (numPairs > 0)\r\n  {\r\n    lenRes = p->matches[numPairs - 2];\r\n    if (lenRes == p->numFastBytes)\r\n    {\r\n      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n      UInt32 distance = p->matches[numPairs - 1] + 1;\r\n      UInt32 numAvail = p->numAvail;\r\n      if (numAvail > LZMA_MATCH_LEN_MAX)\r\n        numAvail = LZMA_MATCH_LEN_MAX;\r\n      {\r\n        const Byte *pby2 = pby - distance;\r\n        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r\n      }\r\n    }\r\n  }\r\n  p->additionalOffset++;\r\n  *numDistancePairsRes = numPairs;\r\n  return lenRes;\r\n}\r\n\r\n\r\n#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;\r\n#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;\r\n#define IsShortRep(p) ((p)->backPrev == 0)\r\n\r\nstatic UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)\r\n{\r\n  return\r\n    GET_PRICE_0(p->isRepG0[state]) +\r\n    GET_PRICE_0(p->isRep0Long[state][posState]);\r\n}\r\n\r\nstatic UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)\r\n{\r\n  UInt32 price;\r\n  if (repIndex == 0)\r\n  {\r\n    price = GET_PRICE_0(p->isRepG0[state]);\r\n    price += GET_PRICE_1(p->isRep0Long[state][posState]);\r\n  }\r\n  else\r\n  {\r\n    price = GET_PRICE_1(p->isRepG0[state]);\r\n    if (repIndex == 1)\r\n      price += GET_PRICE_0(p->isRepG1[state]);\r\n    else\r\n    {\r\n      price += GET_PRICE_1(p->isRepG1[state]);\r\n      price += GET_PRICE(p->isRepG2[state], repIndex - 2);\r\n    }\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)\r\n{\r\n  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +\r\n    GetPureRepPrice(p, repIndex, state, posState);\r\n}\r\n\r\nstatic UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)\r\n{\r\n  UInt32 posMem = p->opt[cur].posPrev;\r\n  UInt32 backMem = p->opt[cur].backPrev;\r\n  p->optimumEndIndex = cur;\r\n  do\r\n  {\r\n    if (p->opt[cur].prev1IsChar)\r\n    {\r\n      MakeAsChar(&p->opt[posMem])\r\n      p->opt[posMem].posPrev = posMem - 1;\r\n      if (p->opt[cur].prev2)\r\n      {\r\n        p->opt[posMem - 1].prev1IsChar = False;\r\n        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;\r\n        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;\r\n      }\r\n    }\r\n    {\r\n      UInt32 posPrev = posMem;\r\n      UInt32 backCur = backMem;\r\n      \r\n      backMem = p->opt[posPrev].backPrev;\r\n      posMem = p->opt[posPrev].posPrev;\r\n      \r\n      p->opt[posPrev].backPrev = backCur;\r\n      p->opt[posPrev].posPrev = cur;\r\n      cur = posPrev;\r\n    }\r\n  }\r\n  while (cur != 0);\r\n  *backRes = p->opt[0].backPrev;\r\n  p->optimumCurrentIndex  = p->opt[0].posPrev;\r\n  return p->optimumCurrentIndex;\r\n}\r\n\r\n#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)\r\n\r\nstatic UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;\r\n  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\r\n  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];\r\n  UInt32 *matches;\r\n  const Byte *data;\r\n  Byte curByte, matchByte;\r\n  if (p->optimumEndIndex != p->optimumCurrentIndex)\r\n  {\r\n    const COptimal *opt = &p->opt[p->optimumCurrentIndex];\r\n    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;\r\n    *backRes = opt->backPrev;\r\n    p->optimumCurrentIndex = opt->posPrev;\r\n    return lenRes;\r\n  }\r\n  p->optimumCurrentIndex = p->optimumEndIndex = 0;\r\n  \r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  if (numAvail < 2)\r\n  {\r\n    *backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  repMaxIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 lenTest;\r\n    const Byte *data2;\r\n    reps[i] = p->reps[i];\r\n    data2 = data - (reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if (repLens[repMaxIndex] >= p->numFastBytes)\r\n  {\r\n    UInt32 lenRes;\r\n    *backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    MovePos(p, lenRes - 1);\r\n    return lenRes;\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n  curByte = *data;\r\n  matchByte = *(data - (reps[0] + 1));\r\n\r\n  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    *backRes = (UInt32)-1;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[0].state = (CState)p->state;\r\n\r\n  posState = (position & p->pbMask);\r\n\r\n  {\r\n    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +\r\n        (!IsCharState(p->state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n  }\r\n\r\n  MakeAsChar(&p->opt[1]);\r\n\r\n  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);\r\n  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);\r\n\r\n  if (matchByte == curByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);\r\n    if (shortRepPrice < p->opt[1].price)\r\n    {\r\n      p->opt[1].price = shortRepPrice;\r\n      MakeAsShortRep(&p->opt[1]);\r\n    }\r\n  }\r\n  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);\r\n\r\n  if (lenEnd < 2)\r\n  {\r\n    *backRes = p->opt[1].backPrev;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[1].posPrev = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n    p->opt[0].backs[i] = reps[i];\r\n\r\n  len = lenEnd;\r\n  do\r\n    p->opt[len--].price = kInfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    UInt32 price;\r\n    if (repLen < 2)\r\n      continue;\r\n    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];\r\n      COptimal *opt = &p->opt[repLen];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = i;\r\n        opt->prev1IsChar = False;\r\n      }\r\n    }\r\n    while (--repLen >= 2);\r\n  }\r\n\r\n  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= mainLen)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matches[offs])\r\n      offs += 2;\r\n    for (; ; len++)\r\n    {\r\n      COptimal *opt;\r\n      UInt32 distance = matches[offs + 1];\r\n\r\n      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];\r\n      UInt32 lenToPosState = GetLenToPosState(len);\r\n      if (distance < kNumFullDistances)\r\n        curAndLenPrice += p->distancesPrices[lenToPosState][distance];\r\n      else\r\n      {\r\n        UInt32 slot;\r\n        GetPosSlot2(distance, slot);\r\n        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];\r\n      }\r\n      opt = &p->opt[len];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = distance + LZMA_NUM_REPS;\r\n        opt->prev1IsChar = False;\r\n      }\r\n      if (len == matches[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numPairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  cur = 0;\r\n\r\n    #ifdef SHOW_STAT2\r\n    if (position >= 0)\r\n    {\r\n      unsigned i;\r\n      printf(\"\\n pos = %4X\", position);\r\n      for (i = cur; i <= lenEnd; i++)\r\n      printf(\"\\nprice[%4X] = %d\", position - cur + i, p->opt[i].price);\r\n    }\r\n    #endif\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;\r\n    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;\r\n    Bool nextIsChar;\r\n    Byte curByte, matchByte;\r\n    const Byte *data;\r\n    COptimal *curOpt;\r\n    COptimal *nextOpt;\r\n\r\n    cur++;\r\n    if (cur == lenEnd)\r\n      return Backward(p, backRes, cur);\r\n\r\n    newLen = ReadMatchDistances(p, &numPairs);\r\n    if (newLen >= p->numFastBytes)\r\n    {\r\n      p->numPairs = numPairs;\r\n      p->longestMatchLength = newLen;\r\n      return Backward(p, backRes, cur);\r\n    }\r\n    position++;\r\n    curOpt = &p->opt[cur];\r\n    posPrev = curOpt->posPrev;\r\n    if (curOpt->prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOpt->prev2)\r\n      {\r\n        state = p->opt[curOpt->posPrev2].state;\r\n        if (curOpt->backPrev2 < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      else\r\n        state = p->opt[posPrev].state;\r\n      state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n      state = p->opt[posPrev].state;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (IsShortRep(curOpt))\r\n        state = kShortRepNextStates[state];\r\n      else\r\n        state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      const COptimal *prevOpt;\r\n      if (curOpt->prev1IsChar && curOpt->prev2)\r\n      {\r\n        posPrev = curOpt->posPrev2;\r\n        pos = curOpt->backPrev2;\r\n        state = kRepNextStates[state];\r\n      }\r\n      else\r\n      {\r\n        pos = curOpt->backPrev;\r\n        if (pos < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      prevOpt = &p->opt[posPrev];\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        UInt32 i;\r\n        reps[0] = prevOpt->backs[pos];\r\n        for (i = 1; i <= pos; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n        for (; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i];\r\n      }\r\n      else\r\n      {\r\n        UInt32 i;\r\n        reps[0] = (pos - LZMA_NUM_REPS);\r\n        for (i = 1; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n      }\r\n    }\r\n    curOpt->state = (CState)state;\r\n\r\n    curOpt->backs[0] = reps[0];\r\n    curOpt->backs[1] = reps[1];\r\n    curOpt->backs[2] = reps[2];\r\n    curOpt->backs[3] = reps[3];\r\n\r\n    curPrice = curOpt->price;\r\n    nextIsChar = False;\r\n    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n    curByte = *data;\r\n    matchByte = *(data - (reps[0] + 1));\r\n\r\n    posState = (position & p->pbMask);\r\n\r\n    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);\r\n    {\r\n      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n      curAnd1Price +=\r\n        (!IsCharState(state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n    }\r\n\r\n    nextOpt = &p->opt[cur + 1];\r\n\r\n    if (curAnd1Price < nextOpt->price)\r\n    {\r\n      nextOpt->price = curAnd1Price;\r\n      nextOpt->posPrev = cur;\r\n      MakeAsChar(nextOpt);\r\n      nextIsChar = True;\r\n    }\r\n\r\n    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);\r\n    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);\r\n    \r\n    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);\r\n      if (shortRepPrice <= nextOpt->price)\r\n      {\r\n        nextOpt->price = shortRepPrice;\r\n        nextOpt->posPrev = cur;\r\n        MakeAsShortRep(nextOpt);\r\n        nextIsChar = True;\r\n      }\r\n    }\r\n    numAvailFull = p->numAvail;\r\n    {\r\n      UInt32 temp = kNumOpts - 1 - cur;\r\n      if (temp < numAvailFull)\r\n        numAvailFull = temp;\r\n    }\r\n\r\n    if (numAvailFull < 2)\r\n      continue;\r\n    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);\r\n\r\n    if (!nextIsChar && matchByte != curByte) /* speed optimization */\r\n    {\r\n      /* try Literal + rep0 */\r\n      UInt32 temp;\r\n      UInt32 lenTest2;\r\n      const Byte *data2 = data - (reps[0] + 1);\r\n      UInt32 limit = p->numFastBytes + 1;\r\n      if (limit > numAvailFull)\r\n        limit = numAvailFull;\r\n\r\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r\n      lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        UInt32 state2 = kLiteralNextStates[state];\r\n        UInt32 posStateNext = (position + 1) & p->pbMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price +\r\n            GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n            GET_PRICE_1(p->isRep[state2]);\r\n        /* for (; lenTest2 >= 2; lenTest2--) */\r\n        {\r\n          UInt32 curAndLenPrice;\r\n          COptimal *opt;\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while (lenEnd < offset)\r\n            p->opt[++lenEnd].price = kInfinityPrice;\r\n          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n          opt = &p->opt[offset];\r\n          if (curAndLenPrice < opt->price)\r\n          {\r\n            opt->price = curAndLenPrice;\r\n            opt->posPrev = cur + 1;\r\n            opt->backPrev = 0;\r\n            opt->prev1IsChar = True;\r\n            opt->prev2 = False;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    startLen = 2; /* speed optimization */\r\n    {\r\n    UInt32 repIndex;\r\n    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)\r\n    {\r\n      UInt32 lenTest;\r\n      UInt32 lenTestTemp;\r\n      UInt32 price;\r\n      const Byte *data2 = data - (reps[repIndex] + 1);\r\n      if (data[0] != data2[0] || data[1] != data2[1])\r\n        continue;\r\n      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n      while (lenEnd < cur + lenTest)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n      lenTestTemp = lenTest;\r\n      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];\r\n        COptimal *opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = repIndex;\r\n          opt->prev1IsChar = False;\r\n        }\r\n      }\r\n      while (--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      /* if (_maxMode) */\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kRepNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice =\r\n                price + p->repLenEnc.prices[posState][lenTest - 2] +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (position + lenTest + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n    }\r\n    }\r\n    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */\r\n    if (newLen > numAvail)\r\n    {\r\n      newLen = numAvail;\r\n      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);\r\n      matches[numPairs] = newLen;\r\n      numPairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\r\n      UInt32 offs, curBack, posSlot;\r\n      UInt32 lenTest;\r\n      while (lenEnd < cur + newLen)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n\r\n      offs = 0;\r\n      while (startLen > matches[offs])\r\n        offs += 2;\r\n      curBack = matches[offs + 1];\r\n      GetPosSlot2(curBack, posSlot);\r\n      for (lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        COptimal *opt;\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];\r\n        \r\n        opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = curBack + LZMA_NUM_REPS;\r\n          opt->prev1IsChar = False;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matches[offs])\r\n        {\r\n          /* Try Match + Literal + Rep0 */\r\n          const Byte *data2 = data - (curBack + 1);\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kMatchNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (posStateNext + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = curBack + LZMA_NUM_REPS;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numPairs)\r\n            break;\r\n          curBack = matches[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            GetPosSlot2(curBack, posSlot);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))\r\n\r\nstatic UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;\r\n  const Byte *data;\r\n  const UInt32 *matches;\r\n\r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  *backRes = (UInt32)-1;\r\n  if (numAvail < 2)\r\n    return 1;\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n\r\n  repLen = repIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    for (len = 2; len < numAvail && data[len] == data2[len]; len++);\r\n    if (len >= p->numFastBytes)\r\n    {\r\n      *backRes = i;\r\n      MovePos(p, len - 1);\r\n      return len;\r\n    }\r\n    if (len > repLen)\r\n    {\r\n      repIndex = i;\r\n      repLen = len;\r\n    }\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n\r\n  mainDist = 0; /* for GCC */\r\n  if (mainLen >= 2)\r\n  {\r\n    mainDist = matches[numPairs - 1];\r\n    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matches[numPairs - 3], mainDist))\r\n        break;\r\n      numPairs -= 2;\r\n      mainLen = matches[numPairs - 2];\r\n      mainDist = matches[numPairs - 1];\r\n    }\r\n    if (mainLen == 2 && mainDist >= 0x80)\r\n      mainLen = 1;\r\n  }\r\n\r\n  if (repLen >= 2 && (\r\n        (repLen + 1 >= mainLen) ||\r\n        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||\r\n        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))\r\n  {\r\n    *backRes = repIndex;\r\n    MovePos(p, repLen - 1);\r\n    return repLen;\r\n  }\r\n  \r\n  if (mainLen < 2 || numAvail <= 2)\r\n    return 1;\r\n\r\n  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);\r\n  if (p->longestMatchLength >= 2)\r\n  {\r\n    UInt32 newDistance = matches[p->numPairs - 1];\r\n    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||\r\n        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||\r\n        (p->longestMatchLength > mainLen + 1) ||\r\n        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))\r\n      return 1;\r\n  }\r\n  \r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len, limit;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    limit = mainLen - 1;\r\n    for (len = 2; len < limit && data[len] == data2[len]; len++);\r\n    if (len >= limit)\r\n      return 1;\r\n  }\r\n  *backRes = mainDist + LZMA_NUM_REPS;\r\n  MovePos(p, mainLen - 2);\r\n  return mainLen;\r\n}\r\n\r\nstatic void WriteEndMarker(CLzmaEnc *p, UInt32 posState)\r\n{\r\n  UInt32 len;\r\n  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n  p->state = kMatchNextStates[p->state];\r\n  len = LZMA_MATCH_LEN_MIN;\r\n  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);\r\n  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);\r\n  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);\r\n}\r\n\r\nstatic SRes CheckErrors(CLzmaEnc *p)\r\n{\r\n  if (p->result != SZ_OK)\r\n    return p->result;\r\n  if (p->rc.res != SZ_OK)\r\n    p->result = SZ_ERROR_WRITE;\r\n  if (p->matchFinderBase.result != SZ_OK)\r\n    p->result = SZ_ERROR_READ;\r\n  if (p->result != SZ_OK)\r\n    p->finished = True;\r\n  return p->result;\r\n}\r\n\r\nstatic SRes Flush(CLzmaEnc *p, UInt32 nowPos)\r\n{\r\n  /* ReleaseMFStream(); */\r\n  p->finished = True;\r\n  if (p->writeEndMark)\r\n    WriteEndMarker(p, nowPos & p->pbMask);\r\n  RangeEnc_FlushData(&p->rc);\r\n  RangeEnc_FlushStream(&p->rc);\r\n  return CheckErrors(p);\r\n}\r\n\r\nstatic void FillAlignPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < kAlignTableSize; i++)\r\n    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);\r\n  p->alignPriceCount = 0;\r\n}\r\n\r\nstatic void FillDistancesPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  UInt32 i, lenToPosState;\r\n  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  {\r\n    UInt32 posSlot = GetPosSlot1(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);\r\n  }\r\n\r\n  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n    UInt32 posSlot;\r\n    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);\r\n    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);\r\n\r\n    {\r\n      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];\r\n      UInt32 i;\r\n      for (i = 0; i < kStartPosModelIndex; i++)\r\n        distancesPrices[i] = posSlotPrices[i];\r\n      for (; i < kNumFullDistances; i++)\r\n        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];\r\n    }\r\n  }\r\n  p->matchPriceCount = 0;\r\n}\r\n\r\nvoid LzmaEnc_Construct(CLzmaEnc *p)\r\n{\r\n  RangeEnc_Construct(&p->rc);\r\n  MatchFinder_Construct(&p->matchFinderBase);\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Construct(&p->matchFinderMt);\r\n  p->matchFinderMt.MatchFinder = &p->matchFinderBase;\r\n  #endif\r\n\r\n  {\r\n    CLzmaEncProps props;\r\n    LzmaEncProps_Init(&props);\r\n    LzmaEnc_SetProps(p, &props);\r\n  }\r\n\r\n  #ifndef LZMA_LOG_BSR\r\n  LzmaEnc_FastPosInit(p->g_FastPos);\r\n  #endif\r\n\r\n  LzmaEnc_InitPriceTables(p->ProbPrices);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)\r\n{\r\n  void *p;\r\n  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));\r\n  if (p != 0)\r\n    LzmaEnc_Construct((CLzmaEnc *)p);\r\n  return p;\r\n}\r\n\r\nvoid LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->litProbs);\r\n  alloc->Free(alloc, p->saveState.litProbs);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nvoid LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);\r\n  #endif\r\n  MatchFinder_Free(&p->matchFinderBase, allocBig);\r\n  LzmaEnc_FreeLits(p, alloc);\r\n  RangeEnc_Free(&p->rc, alloc);\r\n}\r\n\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);\r\n  alloc->Free(alloc, p);\r\n}\r\n\r\nstatic SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)\r\n{\r\n  UInt32 nowPos32, startPos32;\r\n  if (p->inStream != 0)\r\n  {\r\n    p->matchFinderBase.stream = p->inStream;\r\n    p->matchFinder.Init(p->matchFinderObj);\r\n    p->inStream = 0;\r\n  }\r\n\r\n  if (p->finished)\r\n    return p->result;\r\n  RINOK(CheckErrors(p));\r\n\r\n  nowPos32 = (UInt32)p->nowPos64;\r\n  startPos32 = nowPos32;\r\n\r\n  if (p->nowPos64 == 0)\r\n  {\r\n    UInt32 numPairs;\r\n    Byte curByte;\r\n    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n      return Flush(p, nowPos32);\r\n    ReadMatchDistances(p, &numPairs);\r\n    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);\r\n    p->state = kLiteralNextStates[p->state];\r\n    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);\r\n    LitEnc_Encode(&p->rc, p->litProbs, curByte);\r\n    p->additionalOffset--;\r\n    nowPos32++;\r\n  }\r\n\r\n  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)\r\n  for (;;)\r\n  {\r\n    UInt32 pos, len, posState;\r\n\r\n    if (p->fastMode)\r\n      len = GetOptimumFast(p, &pos);\r\n    else\r\n      len = GetOptimum(p, nowPos32, &pos);\r\n\r\n    #ifdef SHOW_STAT2\r\n    printf(\"\\n pos = %4X,   len = %d   pos = %d\", nowPos32, len, pos);\r\n    #endif\r\n\r\n    posState = nowPos32 & p->pbMask;\r\n    if (len == 1 && pos == (UInt32)-1)\r\n    {\r\n      Byte curByte;\r\n      CLzmaProb *probs;\r\n      const Byte *data;\r\n\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);\r\n      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n      curByte = *data;\r\n      probs = LIT_PROBS(nowPos32, *(data - 1));\r\n      if (IsCharState(p->state))\r\n        LitEnc_Encode(&p->rc, probs, curByte);\r\n      else\r\n        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));\r\n      p->state = kLiteralNextStates[p->state];\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);\r\n        if (pos == 0)\r\n        {\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = p->reps[pos];\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);\r\n          if (pos == 1)\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);\r\n          else\r\n          {\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);\r\n            if (pos == 3)\r\n              p->reps[3] = p->reps[2];\r\n            p->reps[2] = p->reps[1];\r\n          }\r\n          p->reps[1] = p->reps[0];\r\n          p->reps[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          p->state = kShortRepNextStates[p->state];\r\n        else\r\n        {\r\n          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n          p->state = kRepNextStates[p->state];\r\n        }\r\n      }\r\n      else\r\n      {\r\n        UInt32 posSlot;\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n        p->state = kMatchNextStates[p->state];\r\n        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n        pos -= LZMA_NUM_REPS;\r\n        GetPosSlot(pos, posSlot);\r\n        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);\r\n          else\r\n          {\r\n            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);\r\n            p->alignPriceCount++;\r\n          }\r\n        }\r\n        p->reps[3] = p->reps[2];\r\n        p->reps[2] = p->reps[1];\r\n        p->reps[1] = p->reps[0];\r\n        p->reps[0] = pos;\r\n        p->matchPriceCount++;\r\n      }\r\n    }\r\n    p->additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (p->additionalOffset == 0)\r\n    {\r\n      UInt32 processed;\r\n      if (!p->fastMode)\r\n      {\r\n        if (p->matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices(p);\r\n        if (p->alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices(p);\r\n      }\r\n      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n        break;\r\n      processed = nowPos32 - startPos32;\r\n      if (useLimits)\r\n      {\r\n        if (processed + kNumOpts + 300 >= maxUnpackSize ||\r\n            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)\r\n          break;\r\n      }\r\n      else if (processed >= (1 << 15))\r\n      {\r\n        p->nowPos64 += nowPos32 - startPos32;\r\n        return CheckErrors(p);\r\n      }\r\n    }\r\n  }\r\n  p->nowPos64 += nowPos32 - startPos32;\r\n  return Flush(p, nowPos32);\r\n}\r\n\r\n#define kBigHashDicLimit ((UInt32)1 << 24)\r\n\r\nstatic SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 beforeSize = kNumOpts;\r\n  Bool btMode;\r\n  if (!RangeEnc_Alloc(&p->rc, alloc))\r\n    return SZ_ERROR_MEM;\r\n  btMode = (p->matchFinderBase.btMode != 0);\r\n  #ifdef COMPRESS_MF_MT\r\n  p->mtMode = (p->multiThread && !p->fastMode && btMode);\r\n  #endif\r\n\r\n  {\r\n    unsigned lclp = p->lc + p->lp;\r\n    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)\r\n    {\r\n      LzmaEnc_FreeLits(p, alloc);\r\n      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      if (p->litProbs == 0 || p->saveState.litProbs == 0)\r\n      {\r\n        LzmaEnc_FreeLits(p, alloc);\r\n        return SZ_ERROR_MEM;\r\n      }\r\n      p->lclp = lclp;\r\n    }\r\n  }\r\n\r\n  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);\r\n\r\n  if (beforeSize + p->dictSize < keepWindowSize)\r\n    beforeSize = keepWindowSize - p->dictSize;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (p->mtMode)\r\n  {\r\n    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));\r\n    p->matchFinderObj = &p->matchFinderMt;\r\n    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))\r\n      return SZ_ERROR_MEM;\r\n    p->matchFinderObj = &p->matchFinderBase;\r\n    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nvoid LzmaEnc_Init(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  p->state = 0;\r\n  for (i = 0 ; i < LZMA_NUM_REPS; i++)\r\n    p->reps[i] = 0;\r\n\r\n  RangeEnc_Init(&p->rc);\r\n\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    UInt32 j;\r\n    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)\r\n    {\r\n      p->isMatch[i][j] = kProbInitValue;\r\n      p->isRep0Long[i][j] = kProbInitValue;\r\n    }\r\n    p->isRep[i] = kProbInitValue;\r\n    p->isRepG0[i] = kProbInitValue;\r\n    p->isRepG1[i] = kProbInitValue;\r\n    p->isRepG2[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    UInt32 num = 0x300 << (p->lp + p->lc);\r\n    for (i = 0; i < num; i++)\r\n      p->litProbs[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    for (i = 0; i < kNumLenToPosStates; i++)\r\n    {\r\n      CLzmaProb *probs = p->posSlotEncoder[i];\r\n      UInt32 j;\r\n      for (j = 0; j < (1 << kNumPosSlotBits); j++)\r\n        probs[j] = kProbInitValue;\r\n    }\r\n  }\r\n  {\r\n    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      p->posEncoders[i] = kProbInitValue;\r\n  }\r\n\r\n  LenEnc_Init(&p->lenEnc.p);\r\n  LenEnc_Init(&p->repLenEnc.p);\r\n\r\n  for (i = 0; i < (1 << kNumAlignBits); i++)\r\n    p->posAlignEncoder[i] = kProbInitValue;\r\n\r\n  p->optimumEndIndex = 0;\r\n  p->optimumCurrentIndex = 0;\r\n  p->additionalOffset = 0;\r\n\r\n  p->pbMask = (1 << p->pb) - 1;\r\n  p->lpMask = (1 << p->lp) - 1;\r\n}\r\n\r\nvoid LzmaEnc_InitPrices(CLzmaEnc *p)\r\n{\r\n  if (!p->fastMode)\r\n  {\r\n    FillDistancesPrices(p);\r\n    FillAlignPrices(p);\r\n  }\r\n\r\n  p->lenEnc.tableSize =\r\n  p->repLenEnc.tableSize =\r\n      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;\r\n  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);\r\n  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);\r\n}\r\n\r\nstatic SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)\r\n    if (p->dictSize <= ((UInt32)1 << i))\r\n      break;\r\n  p->distTableSize = i * 2;\r\n\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));\r\n  LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  p->nowPos64 = 0;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  p->rc.outStream = outStream;\r\n  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);\r\n}\r\n\r\nSRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,\r\n    ISeqInStream *inStream, UInt32 keepWindowSize,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nstatic void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)\r\n{\r\n  p->seqBufInStream.funcTable.Read = MyRead;\r\n  p->seqBufInStream.data = src;\r\n  p->seqBufInStream.rem = srcLen;\r\n}\r\n\r\nSRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\r\n    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n  p->inStream = &p->seqBufInStream.funcTable;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nvoid LzmaEnc_Finish(CLzmaEncHandle pp)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  if (p->mtMode)\r\n    MatchFinderMt_ReleaseStream(&p->matchFinderMt);\r\n  #else\r\n  pp = pp;\r\n  #endif\r\n}\r\n\r\ntypedef struct _CSeqOutStreamBuf\r\n{\r\n  ISeqOutStream funcTable;\r\n  Byte *data;\r\n  SizeT rem;\r\n  Bool overflow;\r\n} CSeqOutStreamBuf;\r\n\r\nstatic size_t MyWrite(void *pp, const void *data, size_t size)\r\n{\r\n  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;\r\n  if (p->rem < size)\r\n  {\r\n    size = p->rem;\r\n    p->overflow = True;\r\n  }\r\n  memcpy(p->data, data, size);\r\n  p->rem -= size;\r\n  p->data += size;\r\n  return size;\r\n}\r\n\r\n\r\nUInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n}\r\n\r\nconst Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n}\r\n\r\nSRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\r\n    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  UInt64 nowPos64;\r\n  SRes res;\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = False;\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n\r\n  if (reInit)\r\n    LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  nowPos64 = p->nowPos64;\r\n  RangeEnc_Init(&p->rc);\r\n  p->rc.outStream = &outStream.funcTable;\r\n\r\n  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);\r\n  \r\n  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  SRes res = SZ_OK;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte allocaDummy[0x300];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  #endif\r\n\r\n  RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));\r\n\r\n  for (;;)\r\n  {\r\n    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);\r\n    if (res != SZ_OK || p->finished != 0)\r\n      break;\r\n    if (progress != 0)\r\n    {\r\n      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));\r\n      if (res != SZ_OK)\r\n      {\r\n        res = SZ_ERROR_PROGRESS;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  LzmaEnc_Finish(pp);\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  int i;\r\n  UInt32 dictSize = p->dictSize;\r\n  if (*size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_PARAM;\r\n  *size = LZMA_PROPS_SIZE;\r\n  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);\r\n\r\n  for (i = 11; i <= 30; i++)\r\n  {\r\n    if (dictSize <= ((UInt32)2 << i))\r\n    {\r\n      dictSize = (2 << i);\r\n      break;\r\n    }\r\n    if (dictSize <= ((UInt32)3 << i))\r\n    {\r\n      dictSize = (3 << i);\r\n      break;\r\n    }\r\n  }\r\n\r\n  for (i = 0; i < 4; i++)\r\n    props[1 + i] = (Byte)(dictSize >> (8 * i));\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  SRes res;\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = writeEndMark;\r\n  res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,\r\n      progress, alloc, allocBig);\r\n\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n  return res;\r\n}\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);\r\n  SRes res;\r\n  if (p == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LzmaEnc_SetProps(p, props);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);\r\n    if (res == SZ_OK)\r\n      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,\r\n          writeEndMark, progress, alloc, allocBig);\r\n  }\r\n\r\n  LzmaEnc_Destroy(p, alloc, allocBig);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/lzma_src/C/LzmaEnc.h",
    "content": "/*  LzmaEnc.h -- LZMA Encoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMAENC_H\r\n#define __LZMAENC_H\r\n\r\n#include \"Types.h\"\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaEncProps\r\n{\r\n  int level;       /*  0 <= level <= 9 */\r\n  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version\r\n                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version\r\n                       default = (1 << 24) */\r\n  int lc;          /* 0 <= lc <= 8, default = 3 */\r\n  int lp;          /* 0 <= lp <= 4, default = 0 */\r\n  int pb;          /* 0 <= pb <= 4, default = 2 */\r\n  int algo;        /* 0 - fast, 1 - normal, default = 1 */\r\n  int fb;          /* 5 <= fb <= 273, default = 32 */\r\n  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */\r\n  int numHashBytes; /* 2, 3 or 4, default = 4 */\r\n  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */\r\n  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */\r\n  int numThreads;  /* 1 or 2, default = 2 */\r\n} CLzmaEncProps;\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p);\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p);\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);\r\n\r\n\r\n/* ---------- CLzmaEncHandle Interface ---------- */\r\n\r\n/* LzmaEnc_* functions can return the following exit codes:\r\nReturns:\r\n  SZ_OK           - OK\r\n  SZ_ERROR_MEM    - Memory allocation error\r\n  SZ_ERROR_PARAM  - Incorrect paramater in props\r\n  SZ_ERROR_WRITE  - Write callback error.\r\n  SZ_ERROR_PROGRESS - some break from progress callback\r\n  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\ntypedef void * CLzmaEncHandle;\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);\r\nSRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaEncode\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/lzma_src/C/Types.h",
    "content": "/* Types.h -- Basic types\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_TYPES_H\r\n#define __7Z_TYPES_H\r\n\r\n#ifndef BCMLZMA\r\n#include <stddef.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#define SZ_OK 0\r\n\r\n#define SZ_ERROR_DATA 1\r\n#define SZ_ERROR_MEM 2\r\n#define SZ_ERROR_CRC 3\r\n#define SZ_ERROR_UNSUPPORTED 4\r\n#define SZ_ERROR_PARAM 5\r\n#define SZ_ERROR_INPUT_EOF 6\r\n#define SZ_ERROR_OUTPUT_EOF 7\r\n#define SZ_ERROR_READ 8\r\n#define SZ_ERROR_WRITE 9\r\n#define SZ_ERROR_PROGRESS 10\r\n#define SZ_ERROR_FAIL 11\r\n#define SZ_ERROR_THREAD 12\r\n\r\n#define SZ_ERROR_ARCHIVE 16\r\n#define SZ_ERROR_NO_ARCHIVE 17\r\n\r\ntypedef int SRes;\r\n\r\n#ifdef _WIN32\r\ntypedef DWORD WRes;\r\n#else\r\ntypedef int WRes;\r\n#endif\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r\n#endif\r\n\r\n#ifndef Byte\r\ntypedef unsigned char Byte;\r\n#endif\r\ntypedef short Int16;\r\ntypedef unsigned short UInt16;\r\n\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef long Int32;\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef int Int32;\r\ntypedef unsigned int UInt32;\r\n#endif\r\n\r\n#ifdef _SZ_NO_INT_64\r\n\r\n/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r\n   NOTES: Some code will work incorrectly in that case! */\r\n\r\ntypedef long Int64;\r\ntypedef unsigned long UInt64;\r\n\r\n#else\r\n\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef __int64 Int64;\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef long long int Int64;\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\ntypedef size_t SizeT;\r\n#endif\r\n\r\ntypedef int Bool;\r\n#define True 1\r\n#define False 0\r\n\r\n\r\n#ifdef _MSC_VER\r\n\r\n#if _MSC_VER >= 1300\r\n#define MY_NO_INLINE __declspec(noinline)\r\n#else\r\n#define MY_NO_INLINE\r\n#endif\r\n\r\n#define MY_CDECL __cdecl\r\n#define MY_STD_CALL __stdcall\r\n#define MY_FAST_CALL MY_NO_INLINE __fastcall\r\n\r\n#else\r\n\r\n#define MY_CDECL\r\n#define MY_STD_CALL\r\n#define MY_FAST_CALL\r\n\r\n#endif\r\n\r\n\r\n/* The following interfaces use first parameter as pointer to structure */\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) < input(*size)) is allowed */\r\n} ISeqInStream;\r\n\r\n/* it can return SZ_ERROR_INPUT_EOF */\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r\n\r\ntypedef struct\r\n{\r\n  size_t (*Write)(void *p, const void *buf, size_t size);\r\n    /* Returns: result - the number of actually written bytes.\r\n       (result < size) means error */\r\n} ISeqOutStream;\r\n\r\ntypedef enum\r\n{\r\n  SZ_SEEK_SET = 0,\r\n  SZ_SEEK_CUR = 1,\r\n  SZ_SEEK_END = 2\r\n} ESzSeek;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ISeekInStream;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Look)(void *p, void **buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) > input(*size)) is not allowed\r\n       (output(*size) < input(*size)) is allowed */\r\n  SRes (*Skip)(void *p, size_t offset);\r\n    /* offset must be <= output(*size) of Look */\r\n\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ILookInStream;\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r\n\r\n/* reads via ILookInStream::Read */\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r\n\r\n#define LookToRead_BUF_SIZE (1 << 14)\r\n\r\ntypedef struct\r\n{\r\n  ILookInStream s;\r\n  ISeekInStream *realStream;\r\n  size_t pos;\r\n  size_t size;\r\n  Byte buf[LookToRead_BUF_SIZE];\r\n} CLookToRead;\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r\nvoid LookToRead_Init(CLookToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToLook;\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToRead;\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r\n    /* Returns: result. (result != SZ_OK) means break.\r\n       Value (UInt64)(Int64)-1 for size means unknown value. */\r\n} ICompressProgress;\r\n\r\ntypedef struct\r\n{\r\n  void *(*Alloc)(void *p, size_t size);\r\n  void (*Free)(void *p, void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\n#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r\n#define IAlloc_Free(p, a) (p)->Free((p), a)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"sqmagic.h\"\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"LzmaEnc.h\"\n#include \"Alloc.h\"\n#include \"sqlzma.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\nint lzma = 1;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nstruct squashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* data allocator status struct.  Allocators are used to keep\n  track of memory buffers passed between different threads */\nstruct allocator {\n\tint\t\tmax_buffers;\n\tint\t\tcount;\n\tint\t\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t\twait;\n};\n\n/* struct describing a memory buffer passed between threads */\nstruct file_buffer {\n\tstruct allocator\t*allocator;\n\tvoid\t\t\t(*release)(int);\n\tint\t\t\trelease_data;\n\tlong long\t\tblock;\n\tint\t\t\tsize;\n\tint\t\t\tc_byte;\n\tunsigned int\t\tblock_order;\n\tint\t\t\tfragment;\n\tint\t\t\terror;\n\tstruct file_buffer\t*next;\n\tchar\t\t\tdata[0];\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n/* describes the list of blocks in a file which is a possible\n   duplicate.  For each block, it indicates whether the block is\n   in memory or on disk */\nstruct buffer_list {\n\tlong long start;\n\tint size;\n\tstruct file_buffer *read_buffer;\n};\n\nstruct allocator *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\nextern struct priority_entry *priority_list[65536];\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\n\n\nstruct allocator *alloc_init(int buffer_size, int max_buffers)\n{\n\tstruct allocator *allocator = malloc(sizeof(struct allocator));\n\n\tif(allocator == NULL)\n\t\treturn NULL;\n\n\tallocator->max_buffers = max_buffers;\n\tallocator->buffer_size = buffer_size;\n\tallocator->count = 0;\n\tpthread_mutex_init(&allocator->mutex, NULL);\n\tpthread_cond_init(&allocator->wait, NULL);\n\n\treturn allocator;\n}\n\n\nstruct file_buffer *alloc_get(struct allocator *allocator)\n{\n\tstruct file_buffer *file_buffer;\n\t\n\tpthread_mutex_lock(&allocator->mutex);\n\n\twhile(allocator->count == allocator->max_buffers)\n\t\tpthread_cond_wait(&allocator->wait, &allocator->mutex);\n\n\tif((file_buffer = malloc(sizeof(struct file_buffer) + allocator->buffer_size)) == NULL)\n\t\tgoto failed;\n\n\tfile_buffer->release = NULL;\n\tfile_buffer->allocator = allocator;\n\tallocator->count ++;\n\nfailed:\n\tpthread_mutex_unlock(&allocator->mutex);\n\treturn file_buffer;\n}\n\n\nstruct file_buffer *alloc_get_2(struct allocator *allocator, void (*release)(int), int release_data)\n{\n\tstruct file_buffer *file_buffer = alloc_get(allocator);\n\n\tif(file_buffer) {\n\t\tfile_buffer->release = release;\n\t\tfile_buffer->release_data = release_data;\n\t}\n\treturn file_buffer;\n}\n\n\nvoid alloc_free(struct file_buffer *file_buffer)\n{\n\tstruct allocator *allocator;\n\n\tif(file_buffer == NULL)\n\t\treturn;\n\n\tallocator = file_buffer->allocator;\n\n\tif(file_buffer->release)\n\t\tfile_buffer->release(file_buffer->release_data);\n\n\tpthread_mutex_lock(&allocator->mutex);\n\tfree(file_buffer);\n\tif(allocator->count == 0)\n\t\tERROR(\"alloc_free: freeing buffer for empty allocator!\\n\");\n\telse\n\t\tallocator->count --;\n\tpthread_cond_signal(&allocator->wait);\n\tpthread_mutex_unlock(&allocator->mutex);\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\t\n\tif (!lzma) {\n\t\tif(stream == NULL) {\n\t\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\n\t\n\t\t\tstream->zalloc = Z_NULL;\n\t\t\tstream->zfree = Z_NULL;\n\t\t\tstream->opaque = 0;\n\t\n\t\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\n\t\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\n\t\t\t\telse\n\t\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t\t}\n\t\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\t\tif(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\n\t\tstream->next_in = (unsigned char *) s;\n\t\tstream->avail_in = size;\n\t\tstream->next_out = (unsigned char *) d;\n\t\tstream->avail_out = block_size;\n\t\t\n\t\tres = deflate(stream, Z_FINISH);\n\t\tif(res != Z_STREAM_END && res != Z_OK) {\n\t\t\tif(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\t\tc_byte = stream->total_out;\n\t\t\n\t\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\t\tmemcpy(d, s, size);\n\t\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t\t}\t\n\t}\n\t /* broadcom start */\n\telse {\n\t\tres = LzmaCompress(s, size, d, block_size, &c_byte);\n\t    if (res) {\n\t\t\tmemcpy(d, s, size);\n\t\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t\t}\n\t} \n\t/* broadcom end */\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\treturn FALSE;\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nint write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir) {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir) == FALSE)\n\t\t\treturn FALSE;\n\t} else {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL) == FALSE)\n\t\t\treturn FALSE;\n\t}\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn TRUE;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment, int *cached_fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\n\tif(fragment->index == *cached_fragment || fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn buffer + fragment->offset;\n\n\tif(fragment_data && fragment->index == fragments)\n\t\treturn fragment_data->data + fragment->offset;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragment_table[fragment->index].pending)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\t\tif (!lzma) {\n\t\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\t\telse\n\t\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t}\n\t\t}\n\t\t/* LZMA */\n\t\telse {\n\t\t\tif((res = LzmaUncompress(buffer, &bytes, cbuffer, size)) != SZ_OK)\n\t\t\t\tBAD_ERROR(\"LzmaUncompress: error (%d)\\n\", res);\n\t\t}\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\t*cached_fragment = fragment->index;\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid ensure_fragments_flushed()\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragments_outstanding)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].pending = TRUE;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\nvoid frag_release(int block)\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragment_table[block].pending = FALSE;\n\tpthread_cond_signal(&fragment_waiting);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = alloc_get(fragment_buffer);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint avail_bytes, compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tlong long slist[meta_blocks];\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_buffer(struct buffer_list *buffer_list, unsigned int blocks)\n{\n\tunsigned short chksum = 0;\n\tint block;\n\n\tfor(block = 0; block < blocks; block ++) {\n\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\tif(b->read_buffer)\n\t\t\tchksum = get_checksum(b->read_buffer->data, b->read_buffer->size, chksum);\n\t\telse\n\t\t\tchksum = get_checksum(read_from_disk(b->start, b->size), b->size, chksum);\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\nint cached_frag = -1;\nchar fragdata[SQUASHFS_FILE_MAX_SIZE];\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tchar *datap;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\nchar cached_fragment[SQUASHFS_FILE_SIZE];\nint cached_frag1 = -1;\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), file_size);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tchar buffer2[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tchar *buffer;\n\t\t\tint block;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_buffer(buffer_list, blocks);\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), frag_bytes);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\t\t\tif(b->read_buffer)\n\t\t\t\t\tbuffer = b->read_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tbuffer = read_from_disk(b->start, b->size);\n\n\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\n\t\t\t\tif(memcmp(buffer, buffer2, b->size) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_start += b->size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tchar *fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1);\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tint count;\n\tint blocks = (buf->st_size + block_size - 1) >> block_log;\n\tint frag_block = !no_fragments && (always_use_fragments ||\n\t\t(buf->st_size < block_size)) ? buf->st_size >> block_log : -1;\n\tint file;\n\tstatic int block_order = 0;\n\tstruct file_buffer *file_buffer;\n\n\tif(buf->st_size == 0 || dir_ent->inode->read)\n\t\treturn;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tfor(count = 0; count < blocks; count ++) {\n\t\tfile_buffer = alloc_get(reader_buffer);\n\n\t\tif((file_buffer->size = read(file, file_buffer->data, block_size)) == -1) {\n\t\t\tclose(file);\n\t\t\tgoto read_err2;\n\t\t}\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->block_order = block_order ++;\n\t\tfile_buffer->error = FALSE;\n\t\tif((file_buffer->fragment = (count == frag_block)))\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\telse\n\t\t\tqueue_put(from_reader, file_buffer);\n\t}\n\n\tclose(file);\n\tdir_ent->inode->read = TRUE;\n\n\treturn;\n\nread_err:\n\tfile_buffer = alloc_get(reader_buffer);\nread_err2:\n\tfile_buffer->block_order = block_order ++;\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\treturn NULL;\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tperror(\"Lseek on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n\t\t\tperror(\"Write on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer = alloc_get(writer_buffer);\n\n\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\n\t\twrite_buffer->block = file_buffer->block;\n\t\twrite_buffer->block_order = file_buffer->block_order;\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\n\t\twrite_buffer->fragment = FALSE;\n\t\twrite_buffer->error = FALSE;\n\t\talloc_free(file_buffer);\n\t\tqueue_put(from_deflate, write_buffer);\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer = alloc_get_2(writer_buffer, frag_release, file_buffer->block);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\twrite_buffer->size = compressed_size;\n\t\twrite_buffer->block = bytes;\n\t\tqueue_put(to_writer, write_buffer);\n\t\tbytes += compressed_size;\n\t\ttotal_uncompressed += file_buffer->size;\n\t\ttotal_compressed += compressed_size;\n\t\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\n\t\tfragments_outstanding --;\n\t\tpthread_cond_signal(&fragment_waiting);\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->block_order);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int block_order = 0;\n\tint hash = BLOCK_HASH(block_order);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->block_order == block_order)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->block_order == block_order)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tblock_order ++;\n\n\treturn file_buffer;\n}\n\n\nint progress_bar(long long current, long long max, int columns)\n{\n\tint max_digits = ceil(log10(max));\n\tint used = max_digits * 2 + 10;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(!progress || columns - used < 0)\n\t\treturn 0;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n\treturn 0;\n}\n\n\nint write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n}\n\n\nint write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\n{\n\tint file;\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\talloc_free(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\tstruct file_buffer *file_buffer = get_file_buffer(from_deflate);\n\n\tif(file_buffer->error) {\n\t\talloc_free(file_buffer);\n\t\treturn FALSE;\n\t}\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum))\n\t\treturn write_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\talloc_free(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size)\n{\n\tint block, status;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list;\n\tstruct file_buffer *read_buffer;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\t\tqueue_put(to_writer, read_buffer);\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t} else\n\t\tread_buffer = NULL;\n\n\tfragment = get_and_fill_fragment(read_buffer);\n\talloc_free(read_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, int *duplicate_file)\n{\n\tint block, status, thresh;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer *read_buffer;\n\tstruct file_data *file_data;\n\tstruct buffer_list *buffer_list;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tthresh = blocks > (writer_buffer_size - processors) ? blocks - (writer_buffer_size - processors): 0;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\n\t\tif(block < thresh) {\n\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\tqueue_put(to_writer, read_buffer);\n\t\t} else\n\t\t\tbuffer_list[block].read_buffer = read_buffer;\n\t\tbuffer_list[block].start = read_buffer->block;\n\t\tbuffer_list[block].size = read_buffer->size;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t} else\n\t\tread_buffer = NULL;\n\n\tqueue_put(to_writer, NULL);\n\tif(queue_get(from_writer) != 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\n\t\tfragment = get_and_fill_fragment(read_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\talloc_free(buffer_list[block].read_buffer);\n\t\tbytes = buffer_list[0].start;\n\t\tif(thresh && !block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\n\talloc_free(read_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block && thresh) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\talloc_free(buffer_list[blocks].read_buffer);\n\tfree(buffer_list);\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)\n{\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %lld bytes\\n\", dir_ent->pathname, SQUASHFS_MAX_FILE_SIZE);\n\n\tif(read_size == 0)\n\t\treturn write_file_empty(inode, dir_ent, duplicate_file);\n\n\tif(!no_fragments && (read_size < block_size))\n\t\treturn write_file_frag(inode, dir_ent, read_size, duplicate_file);\n\n\tif(pre_duplicate(read_size))\n\t\treturn write_file_blocks_dup(inode, dir_ent, read_size, duplicate_file);\n\n\t*duplicate_file = FALSE;\n\treturn write_file_blocks(inode, dir_ent, read_size);\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFREG)\n\t\t\testimated_uncompressed += (buf.st_size + block_size - 1) >> block_log;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\n\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type = -1;\n\tint result = FALSE;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\tresult = write_file(inode, dir_ent, buf->st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tresult = dir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n\t\t\t\t}\n\t\t\tif(result)\n\t\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult = TRUE;\n\t\t}\n\t\t\n\n\t\tif(result)\n\t\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\tresult = write_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n\n\treturn result;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 16; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(processors * 2);\n\treader_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, reader_buffer_size);\n\twriter_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, writer_buffer_size);\n\tfragment_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, processors * 2);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\n\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\n}\n\n\t\t\t\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.2-r2 (2007/01/15)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct winsize winsize;\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n\t\t\tlzma = 0;\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t} else  {\n\t\tsignal(SIGTERM, sighandler2);\n\t\tsignal(SIGINT, sighandler2);\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tinitialise_threads();\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem using %s on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, lzma ? \"LZMA\" : \"GZIP\", argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t\t\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + (inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1));\n\t\tuncompressed_data = inode_dir_offset + (inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1));\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(progress) {\n\t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\t\tcolumns = 80;\n\t\t} else\n\t\t\tcolumns = winsize.ws_col;\n\t\tsignal(SIGWINCH, sigwinch_handler);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tif (lzma)\n\t\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n\telse\n\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tensure_fragments_flushed();\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\tclose(fd);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"sqmagic.h\"\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"LzmaDec.h\"\n#include \"sqlzma.h\"\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\nextern int lzma;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tif(!lzma) {\n\t\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\t\telse\n\t\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\t/* lzma */\n\t\telse {\n\t\t\tif((res = LzmaUncompress(block, &bytes, buffer, c_byte)) != SZ_OK)\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tsquashfs_super_block sblk;\n\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk->s_magic) {\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tif (!lzma)\n\t\t\tgoto bad;\n\t\tbreak;\n\tcase SQUASHFS_MAGIC:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\n\tbad:\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3.0 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is %d.%d, I support 3.0\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %xllx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block = -1;\n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tlong long sindex[indexes];\n\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_inode_t sinode;\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\n\t\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include \"squashfs_fs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern squashfs_inode write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\tif(write_file(&inode, entry->dir, entry->dir->inode->buf.st_size,\n\t\t\t\t\t\t\t&duplicate_file)) {\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/sqlzma.c",
    "content": "/*\n * squashfs with lzma compression\n *\n * Copyright (C) 2008, Broadcom Corporation\n * All Rights Reserved.\n * \n * THIS SOFTWARE IS OFFERED \"AS IS\", AND BROADCOM GRANTS NO WARRANTIES OF ANY\n * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM\n * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.\n *\n * $Id: sqlzma.c,v 1.3 2009/03/10 08:42:14 Exp $\n */\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include \"LzmaDec.h\"\n#include \"LzmaEnc.h\"\n#include \"sqlzma.h\"\n\nstatic void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\nstatic void SzFree(void *p, void *address) { p = p; free(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\nint LzmaUncompress(char *dst, unsigned long * dstlen, char *src, int srclen)\n{\n\tint res;\n\tSizeT inSizePure;\n\tELzmaStatus status;\n\n\tif (srclen < LZMA_PROPS_SIZE)\n\t{\n\t\tmemcpy(dst, src, srclen);\n\t\treturn srclen;\n\t}\n\tinSizePure = srclen - LZMA_PROPS_SIZE;\n\tres = LzmaDecode(dst, dstlen, src + LZMA_PROPS_SIZE, &inSizePure,\n\t                 src, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);\n\tsrclen = inSizePure ;\n\n\tif ((res == SZ_OK) ||\n\t\t((res == SZ_ERROR_INPUT_EOF) && (srclen == inSizePure)))\n\t\tres = 0;\n\tif (res != SZ_OK)\n\t\tprintf(\"LzmaUncompress: error (%d)\\n\", res);\n\treturn res;\n}\n\n\nint LzmaCompress(char *in_data, int in_size, char *out_data, int out_size, unsigned long *total_out)\n{\n\tCLzmaEncProps props;\n\tsize_t headerSize = LZMA_PROPS_SIZE;\n\tint ret;\n\tSizeT outProcess;\n\n\tLzmaEncProps_Init(&props);\n\tprops.algo = 1;\n\toutProcess = out_size - LZMA_PROPS_SIZE;\n\tret = LzmaEncode(out_data+LZMA_PROPS_SIZE, &outProcess, in_data, in_size, &props, out_data, \n\t\t\t\t\t\t&headerSize, 0, NULL, &g_Alloc, &g_Alloc);\n\t*total_out = outProcess + LZMA_PROPS_SIZE;\n\treturn ret;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/sqlzma.h",
    "content": "/*\n * squashfs with lzma compression\n *\n * Copyright (C) 2008, Broadcom Corporation\n * All Rights Reserved.\n * \n * THIS SOFTWARE IS OFFERED \"AS IS\", AND BROADCOM GRANTS NO WARRANTIES OF ANY\n * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM\n * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.\n *\n * $Id: sqlzma.h,v 1.3 2009/03/10 08:42:14 Exp $\n */\n#ifndef __sqlzma_h__\n#define __sqlzma_h__\n\n#ifndef __KERNEL__\n#include <stdlib.h>\n#include <string.h>\n#endif\n\n/*\n * detect the compression method automatically by the first byte of compressed\n * data.\n */\n#define is_lzma(c)\t(c == 0x5d)\n\nint LzmaUncompress(char *dst, unsigned long * dstlen, char *src, int srclen);\nint LzmaCompress(char *in_data, int in_size, char *out_data, int out_size, unsigned long *total_out);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/sqmagic.h",
    "content": "#define SQUASHFS_MAGIC_LZMA             0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP        0x73687371\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#ifdef CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\n#define SQUASHFS_CACHED_FRAGMENTS       CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\n#else\n#define SQUASHFS_CACHED_FRAGMENTS       3\n#endif\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-rtn12/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n *  Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"LzmaDec.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir\t*(*squashfs_opendir)(unsigned int block_start, unsigned int offset);\n\tchar \t\t*(*read_fragment)(unsigned int fragment);\n\tvoid\t\t(*read_fragment_table)();\n\tint\t\t(*create_inode)(char *pathname, unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE, force = FALSE;\nchar **created_inode;\nint root_process;\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\t\tif (!is_lzma(buffer[0])) {\n\t\t\tif((res = uncompress((unsigned char *) block, &bytes,\n\t\t\t(const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\t\telse\n\t\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif((res = LzmaUncompress(block, &bytes, buffer, c_byte)) != SZ_OK)\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\n\t\t}\n\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tif (!is_lzma(data[0])) {\n\t\t\tif((res = uncompress((unsigned char *) block, &bytes,\n\t\t\t(const unsigned char *) data, c_byte)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\t\telse\n\t\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\t/* LZMA */\n\t\telse {\n\t\t\tif((res = LzmaUncompress(block, &bytes, data, c_byte)) != SZ_OK)\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\n\t\t}\n\t\t\t\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, unsigned int mode, unsigned int uid,\nunsigned int guid, unsigned int mtime, unsigned int set_mode)\n{\n\tstruct utimbuf times = { (time_t) mtime, (time_t) mtime };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tuid_t uid_value = (uid_t) uid_table[uid];\n\t\tuid_t guid_value = guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[guid];\n\n\t\tif(chown(pathname, uid_value, guid_value) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nchar *read_fragment_2(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint write_file(char *pathname, unsigned int fragment, unsigned int frag_bytes,\nunsigned int offset, unsigned int blocks, long long start, char *block_ptr,\nunsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write(file_fd, file_data, bytes) < bytes) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = s_ops.read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write(file_fd, fragment_data + offset, frag_bytes) < frag_bytes) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\t\t\n\nint create_inode(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tif(created_inode[header.base.inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[header.base.inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\theader.base.mtime, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[header.base.inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nint create_inode_2(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header_2 header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, sBlk.mkfs_time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\tsBlk.mkfs_time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header_2 header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nint matches(char *targname, char *name)\n{\n\tif(*targname == '\\0' || strcmp(targname, name) == 0)\n\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, char *target)\n{\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tchar targname[1024];\n\n\ttarget = get_component(target, targname);\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(targname, name))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(lsonly || info)\n\t\t\tprintf(\"%s\\n\", pathname);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, target);\n\t\telse\n\t\t\tif(!lsonly)\n\t\t\t\ts_ops.create_inode(pathname, start_block, offset);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nint read_super(char *source)\n{\n\tsquashfs_super_block sblk;\n\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk.s_magic) {\n\tcase SQUASHFS_MAGIC:\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\n\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\ts_ops.read_fragment = read_fragment_2;\n\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\ts_ops.create_inode = create_inode_2;\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor == 0) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.create_inode = create_inode;\n\t} else {\n\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d)\\n\",\n\t\t\t\tsource, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"I support Squashfs 2.x and 3.0 filesystems!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\n\tTRACE(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not\" : \"\");\n\tTRACE(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tTRACE(\"\\tBlock size %d\\n\", sBlk.block_size);\n\tTRACE(\"\\tNumber of fragments %d\\n\", sBlk.fragments);\n\tTRACE(\"\\tNumber of inodes %d\\n\", sBlk.inodes);\n\tTRACE(\"\\tNumber of uids %d\\n\", sBlk.no_uids);\n\tTRACE(\"\\tNumber of gids %d\\n\", sBlk.no_guids);\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.3 (2007/01/02)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, version = FALSE;\n\tchar *target = \"\";\n\n\tif((root_process = (geteuid() == 0)))\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc)\n\t\t\t\tgoto options;\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directory or file to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem only\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tif((i + 1) < argc)\n\t\ttarget = argv[i + 1];\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tblock_size = sBlk.block_size;\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids();\n\ts_ops.read_fragment_table();\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), target);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/Makefile",
    "content": "CC = gcc\n\nLZMADIR = ./lzma_src/C\n\nCFLAGS := -I$(LZMADIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\n\nLZMAOBJS = LzmaEnc.o LzFind.o LzmaDec.o\nMKOBJS = mksquashfs.o read_fs.o sort.o sqlzma.o\n\nall: mksquashfs unsquashfs\n\n$(LZMAOBJS): %.o: $(LZMADIR)/%.c\n\t$(CC) -c $(CFLAGS) $(CPPFLAGS) $^ -o $@\n\nmksquashfs: $(MKOBJS) $(LZMAOBJS)\n\t$(CC) $(MKOBJS) $(LZMAOBJS) -lz -lpthread -lm -lstdc++ -o $@\n\nunsquashfs: unsquashfs.o $(LZMAOBJS)\n\t$(CC) unsquashfs.o  sqlzma.o $(LZMAOBJS) -lz -lpthread -lm -o $@\n\nclean:\n\t-rm -f *.o mksquashfs unsquashfs\n\ninstall: mksquashfs unsquashfs\n\tmkdir -p $(INSTALL_DIR)\n\tcp mksquashfs unsquashfs $(INSTALL_DIR)\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/lzma_src/C/Alloc.h",
    "content": "/* Alloc.h -- Memory allocation functions\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size);\r\nvoid MyFree(void *address);\r\n\r\n#ifdef _WIN32\r\n\r\nvoid SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size);\r\nvoid MidFree(void *address);\r\nvoid *BigAlloc(size_t size);\r\nvoid BigFree(void *address);\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/lzma_src/C/LzFind.c",
    "content": "/* LzFind.c -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"LzFind.h\"\r\n#include \"LzHash.h\"\r\n\r\n#define kEmptyHashValue 0\r\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\r\n#define kMaxHistorySize ((UInt32)3 << 30)\r\n\r\n#define kStartMaxLen 3\r\n\r\nstatic void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  if (!p->directInput)\r\n  {\r\n    alloc->Free(alloc, p->bufferBase);\r\n    p->bufferBase = 0;\r\n  }\r\n}\r\n\r\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r\n\r\nstatic int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r\n{\r\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r\n  if (p->directInput)\r\n  {\r\n    p->blockSize = blockSize;\r\n    return 1;\r\n  }\r\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\r\n  {\r\n    LzInWindow_Free(p, alloc);\r\n    p->blockSize = blockSize;\r\n    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r\n  }\r\n  return (p->bufferBase != 0);\r\n}\r\n\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r\n\r\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r\n\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r\n{\r\n  p->posLimit -= subValue;\r\n  p->pos -= subValue;\r\n  p->streamPos -= subValue;\r\n}\r\n\r\nstatic void MatchFinder_ReadBlock(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached || p->result != SZ_OK)\r\n    return;\r\n  for (;;)\r\n  {\r\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\r\n    size_t size = (p->bufferBase + p->blockSize - dest);\r\n    if (size == 0)\r\n      return;\r\n    p->result = p->stream->Read(p->stream, dest, &size);\r\n    if (p->result != SZ_OK)\r\n      return;\r\n    if (size == 0)\r\n    {\r\n      p->streamEndWasReached = 1;\r\n      return;\r\n    }\r\n    p->streamPos += (UInt32)size;\r\n    if (p->streamPos - p->pos > p->keepSizeAfter)\r\n      return;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\r\n{\r\n  memmove(p->bufferBase,\r\n    p->buffer - p->keepSizeBefore,\r\n    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\r\n  p->buffer = p->bufferBase + p->keepSizeBefore;\r\n}\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p)\r\n{\r\n  /* if (p->streamEndWasReached) return 0; */\r\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r\n}\r\n\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached)\r\n    return;\r\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\r\n    MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r\n{\r\n  if (MatchFinder_NeedMove(p))\r\n    MatchFinder_MoveBlock(p);\r\n  MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_SetDefaultSettings(CMatchFinder *p)\r\n{\r\n  p->cutValue = 32;\r\n  p->btMode = 1;\r\n  p->numHashBytes = 4;\r\n  /* p->skipModeBits = 0; */\r\n  p->directInput = 0;\r\n  p->bigHash = 0;\r\n}\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  p->bufferBase = 0;\r\n  p->directInput = 0;\r\n  p->hash = 0;\r\n  MatchFinder_SetDefaultSettings(p);\r\n\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    p->crc[i] = r;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hash);\r\n  p->hash = 0;\r\n}\r\n\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  MatchFinder_FreeThisClassMemory(p, alloc);\r\n  LzInWindow_Free(p, alloc);\r\n}\r\n\r\nstatic CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r\n{\r\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r\n  if (sizeInBytes / sizeof(CLzRef) != num)\r\n    return 0;\r\n  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r\n}\r\n\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 sizeReserv;\r\n  if (historySize > kMaxHistorySize)\r\n  {\r\n    MatchFinder_Free(p, alloc);\r\n    return 0;\r\n  }\r\n  sizeReserv = historySize >> 1;\r\n  if (historySize > ((UInt32)2 << 30))\r\n    sizeReserv = historySize >> 2;\r\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r\n\r\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r\n  if (LzInWindow_Create(p, sizeReserv, alloc))\r\n  {\r\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r\n    UInt32 hs;\r\n    p->matchMaxLen = matchMaxLen;\r\n    {\r\n      p->fixedHashSize = 0;\r\n      if (p->numHashBytes == 2)\r\n        hs = (1 << 16) - 1;\r\n      else\r\n      {\r\n        hs = historySize - 1;\r\n        hs |= (hs >> 1);\r\n        hs |= (hs >> 2);\r\n        hs |= (hs >> 4);\r\n        hs |= (hs >> 8);\r\n        hs >>= 1;\r\n        /* hs >>= p->skipModeBits; */\r\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r\n        if (hs > (1 << 24))\r\n        {\r\n          if (p->numHashBytes == 3)\r\n            hs = (1 << 24) - 1;\r\n          else\r\n            hs >>= 1;\r\n        }\r\n      }\r\n      p->hashMask = hs;\r\n      hs++;\r\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r\n      hs += p->fixedHashSize;\r\n    }\r\n\r\n    {\r\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\r\n      UInt32 newSize;\r\n      p->historySize = historySize;\r\n      p->hashSizeSum = hs;\r\n      p->cyclicBufferSize = newCyclicBufferSize;\r\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r\n      newSize = p->hashSizeSum + p->numSons;\r\n      if (p->hash != 0 && prevSize == newSize)\r\n        return 1;\r\n      MatchFinder_FreeThisClassMemory(p, alloc);\r\n      p->hash = AllocRefs(newSize, alloc);\r\n      if (p->hash != 0)\r\n      {\r\n        p->son = p->hash + p->hashSizeSum;\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  MatchFinder_Free(p, alloc);\r\n  return 0;\r\n}\r\n\r\nstatic void MatchFinder_SetLimits(CMatchFinder *p)\r\n{\r\n  UInt32 limit = kMaxValForNormalize - p->pos;\r\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  limit2 = p->streamPos - p->pos;\r\n  if (limit2 <= p->keepSizeAfter)\r\n  {\r\n    if (limit2 > 0)\r\n      limit2 = 1;\r\n  }\r\n  else\r\n    limit2 -= p->keepSizeAfter;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  {\r\n    UInt32 lenLimit = p->streamPos - p->pos;\r\n    if (lenLimit > p->matchMaxLen)\r\n      lenLimit = p->matchMaxLen;\r\n    p->lenLimit = lenLimit;\r\n  }\r\n  p->posLimit = p->pos + limit;\r\n}\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->hashSizeSum; i++)\r\n    p->hash[i] = kEmptyHashValue;\r\n  p->cyclicBufferPos = 0;\r\n  p->buffer = p->bufferBase;\r\n  p->pos = p->streamPos = p->cyclicBufferSize;\r\n  p->result = SZ_OK;\r\n  p->streamEndWasReached = 0;\r\n  MatchFinder_ReadBlock(p);\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r\n{\r\n  return (p->pos - p->historySize - 1) & kNormalizeMask;\r\n}\r\n\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_Normalize(CMatchFinder *p)\r\n{\r\n  UInt32 subValue = MatchFinder_GetSubValue(p);\r\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r\n  MatchFinder_ReduceOffsets(p, subValue);\r\n}\r\n\r\nstatic void MatchFinder_CheckLimits(CMatchFinder *p)\r\n{\r\n  if (p->pos == kMaxValForNormalize)\r\n    MatchFinder_Normalize(p);\r\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r\n    MatchFinder_CheckAndMoveAndRead(p);\r\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\r\n    p->cyclicBufferPos = 0;\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  son[_cyclicBufferPos] = curMatch;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n      return distances;\r\n    {\r\n      const Byte *pb = cur - delta;\r\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r\n      {\r\n        UInt32 len = 0;\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n            return distances;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return distances;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return distances;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        {\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define MOVE_POS \\\r\n  ++p->cyclicBufferPos; \\\r\n  p->buffer++; \\\r\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r\n\r\n#define MOVE_POS_RET MOVE_POS return offset;\r\n\r\nstatic void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r\n\r\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\r\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\r\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\r\n  cur = p->buffer;\r\n\r\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r\n\r\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r\n\r\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\r\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\r\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\r\n\r\n#define SKIP_FOOTER \\\r\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r\n\r\nstatic UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(2)\r\n  HASH2_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 1)\r\n}\r\n\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 2)\r\n}\r\n\r\nstatic UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, delta2, maxLen, offset;\r\n  GET_MATCHES_HEADER(3)\r\n\r\n  HASH3_CALC;\r\n\r\n  delta2 = p->pos - p->hash[hash2Value];\r\n  curMatch = p->hash[kFix3HashSize + hashValue];\r\n  \r\n  p->hash[hash2Value] =\r\n  p->hash[kFix3HashSize + hashValue] = p->pos;\r\n\r\n\r\n  maxLen = 2;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[0] = maxLen;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n  \r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n\r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      p->son[p->cyclicBufferPos] = curMatch;\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances + offset, maxLen) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances, 2) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nstatic void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(2)\r\n    HASH2_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value;\r\n    SKIP_HEADER(3)\r\n    HASH3_CALC;\r\n    curMatch = p->hash[kFix3HashSize + hashValue];\r\n    p->hash[hash2Value] =\r\n    p->hash[kFix3HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] =\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r\n  if (!p->btMode)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 2)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 3)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r\n  }\r\n  else\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/lzma_src/C/LzFind.h",
    "content": "/* LzFind.h -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFIND_H\r\n#define __LZFIND_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef UInt32 CLzRef;\r\n\r\ntypedef struct _CMatchFinder\r\n{\r\n  Byte *buffer;\r\n  UInt32 pos;\r\n  UInt32 posLimit;\r\n  UInt32 streamPos;\r\n  UInt32 lenLimit;\r\n\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r\n\r\n  UInt32 matchMaxLen;\r\n  CLzRef *hash;\r\n  CLzRef *son;\r\n  UInt32 hashMask;\r\n  UInt32 cutValue;\r\n\r\n  Byte *bufferBase;\r\n  ISeqInStream *stream;\r\n  int streamEndWasReached;\r\n\r\n  UInt32 blockSize;\r\n  UInt32 keepSizeBefore;\r\n  UInt32 keepSizeAfter;\r\n\r\n  UInt32 numHashBytes;\r\n  int directInput;\r\n  int btMode;\r\n  /* int skipModeBits; */\r\n  int bigHash;\r\n  UInt32 historySize;\r\n  UInt32 fixedHashSize;\r\n  UInt32 hashSizeSum;\r\n  UInt32 numSons;\r\n  SRes result;\r\n  UInt32 crc[256];\r\n} CMatchFinder;\r\n\r\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r\n\r\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p);\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p);\r\n\r\n/* Conditions:\r\n     historySize <= 3 GB\r\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r\n*/\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc);\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *distances, UInt32 maxLen);\r\n\r\n/*\r\nConditions:\r\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r\n*/\r\n\r\ntypedef void (*Mf_Init_Func)(void *object);\r\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\r\n\r\ntypedef struct _IMatchFinder\r\n{\r\n  Mf_Init_Func Init;\r\n  Mf_GetIndexByte_Func GetIndexByte;\r\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r\n  Mf_GetMatches_Func GetMatches;\r\n  Mf_Skip_Func Skip;\r\n} IMatchFinder;\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p);\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/lzma_src/C/LzHash.h",
    "content": "/* LzHash.h -- HASH functions for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZHASH_H\r\n#define __LZHASH_H\r\n\r\n#define kHash2Size (1 << 10)\r\n#define kHash3Size (1 << 16)\r\n#define kHash4Size (1 << 20)\r\n\r\n#define kFix3HashSize (kHash2Size)\r\n#define kFix4HashSize (kHash2Size + kHash3Size)\r\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r\n\r\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r\n\r\n#define HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r\n\r\n#define HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r\n\r\n#define HASH5_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\\r\n  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\\r\n  hash4Value &= (kHash4Size - 1); }\r\n\r\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r\n\r\n\r\n#define MT_HASH2_CALC \\\r\n  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r\n\r\n#define MT_HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r\n\r\n#define MT_HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/lzma_src/C/LzmaDec.c",
    "content": "/* LzmaDec.c -- LZMA Decoder\r\n2008-11-06 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzmaDec.h\"\r\n#ifndef BCMLZMA\r\n#include <string.h>\r\n#endif\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_INIT_SIZE 5\r\n\r\n#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));\r\n#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \\\r\n  { UPDATE_0(p); i = (i + i); A0; } else \\\r\n  { UPDATE_1(p); i = (i + i) + 1; A1; }\r\n#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)\r\n\r\n#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }\r\n#define TREE_DECODE(probs, limit, i) \\\r\n  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }\r\n\r\n/* #define _LZMA_SIZE_OPT */\r\n\r\n#ifdef _LZMA_SIZE_OPT\r\n#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)\r\n#else\r\n#define TREE_6_DECODE(probs, i) \\\r\n  { i = 1; \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  i -= 0x40; }\r\n#endif\r\n\r\n#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0_CHECK range = bound;\r\n#define UPDATE_1_CHECK range -= bound; code -= bound;\r\n#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \\\r\n  { UPDATE_0_CHECK; i = (i + i); A0; } else \\\r\n  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }\r\n#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)\r\n#define TREE_DECODE_CHECK(probs, limit, i) \\\r\n  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols)\r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nstatic const Byte kLiteralNextStates[kNumStates * 2] =\r\n{\r\n  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\r\n  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\r\n};\r\n\r\n#define LZMA_DIC_MIN (1 << 12)\r\n\r\n/* First LZMA-symbol is always decoded.\r\nAnd it decodes new LZMA-symbols while (buf < bufLimit), but \"buf\" is without last normalization\r\nOut:\r\n  Result:\r\n    SZ_OK - OK\r\n    SZ_ERROR_DATA - Error\r\n  p->remainLen:\r\n    < kMatchSpecLenStart : normal remain\r\n    = kMatchSpecLenStart : finished\r\n    = kMatchSpecLenStart + 1 : Flush marker\r\n    = kMatchSpecLenStart + 2 : State Init Marker\r\n*/\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  CLzmaProb *probs = p->probs;\r\n\r\n  unsigned state = p->state;\r\n  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];\r\n  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;\r\n  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;\r\n  unsigned lc = p->prop.lc;\r\n\r\n  Byte *dic = p->dic;\r\n  SizeT dicBufSize = p->dicBufSize;\r\n  SizeT dicPos = p->dicPos;\r\n  \r\n  UInt32 processedPos = p->processedPos;\r\n  UInt32 checkDicSize = p->checkDicSize;\r\n  unsigned len = 0;\r\n\r\n  const Byte *buf = p->buf;\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n\r\n  do\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = processedPos & pbMask;\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0(prob)\r\n    {\r\n      unsigned symbol;\r\n      UPDATE_0(prob);\r\n      prob = probs + Literal;\r\n      if (checkDicSize != 0 || processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r\n        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        symbol = 1;\r\n        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      dic[dicPos++] = (Byte)symbol;\r\n      processedPos++;\r\n\r\n      state = kLiteralNextStates[state];\r\n      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\r\n      continue;\r\n    }\r\n    else\r\n    {\r\n      UPDATE_1(prob);\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0(prob)\r\n      {\r\n        UPDATE_0(prob);\r\n        state += kNumStates;\r\n        prob = probs + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1(prob);\r\n        if (checkDicSize == 0 && processedPos == 0)\r\n          return SZ_ERROR_DATA;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0(prob)\r\n        {\r\n          UPDATE_0(prob);\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n            dicPos++;\r\n            processedPos++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            continue;\r\n          }\r\n          UPDATE_1(prob);\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UPDATE_1(prob);\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            distance = rep1;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(prob);\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0(prob)\r\n            {\r\n              UPDATE_0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0(probLen)\r\n        {\r\n          UPDATE_0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = (1 << kLenNumLowBits);\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0(probLen)\r\n          {\r\n            UPDATE_0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = (1 << kLenNumMidBits);\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = (1 << kLenNumHighBits);\r\n          }\r\n        }\r\n        TREE_DECODE(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state >= kNumStates)\r\n      {\r\n        UInt32 distance;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);\r\n        TREE_6_DECODE(prob, distance);\r\n        if (distance >= kStartPosModelIndex)\r\n        {\r\n          unsigned posSlot = (unsigned)distance;\r\n          int numDirectBits = (int)(((distance >> 1) - 1));\r\n          distance = (2 | (distance & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            distance <<= numDirectBits;\r\n            prob = probs + SpecPos + distance - posSlot - 1;\r\n            {\r\n              UInt32 mask = 1;\r\n              unsigned i = 1;\r\n              do\r\n              {\r\n                GET_BIT2(prob + i, i, ; , distance |= mask);\r\n                mask <<= 1;\r\n              }\r\n              while (--numDirectBits != 0);\r\n            }\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE\r\n              range >>= 1;\r\n              \r\n              {\r\n                UInt32 t;\r\n                code -= range;\r\n                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */\r\n                distance = (distance << 1) + (t + 1);\r\n                code += range & t;\r\n              }\r\n              /*\r\n              distance <<= 1;\r\n              if (code >= range)\r\n              {\r\n                code -= range;\r\n                distance |= 1;\r\n              }\r\n              */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            distance <<= kNumAlignBits;\r\n            {\r\n              unsigned i = 1;\r\n              GET_BIT2(prob + i, i, ; , distance |= 1);\r\n              GET_BIT2(prob + i, i, ; , distance |= 2);\r\n              GET_BIT2(prob + i, i, ; , distance |= 4);\r\n              GET_BIT2(prob + i, i, ; , distance |= 8);\r\n            }\r\n            if (distance == (UInt32)0xFFFFFFFF)\r\n            {\r\n              len += kMatchSpecLenStart;\r\n              state -= kNumStates;\r\n              break;\r\n            }\r\n          }\r\n        }\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        rep0 = distance + 1;\r\n        if (checkDicSize == 0)\r\n        {\r\n          if (distance >= processedPos)\r\n            return SZ_ERROR_DATA;\r\n        }\r\n        else if (distance >= checkDicSize)\r\n          return SZ_ERROR_DATA;\r\n        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r\n        /* state = kLiteralNextStates[state]; */\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n\r\n      if (limit == dicPos)\r\n        return SZ_ERROR_DATA;\r\n      {\r\n        SizeT rem = limit - dicPos;\r\n        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\r\n        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\r\n\r\n        processedPos += curLen;\r\n\r\n        len -= curLen;\r\n        if (pos + curLen <= dicBufSize)\r\n        {\r\n          Byte *dest = dic + dicPos;\r\n          int src = (int)pos - (int)dicPos;\r\n          const Byte *lim = dest + curLen;\r\n          dicPos += curLen;\r\n          do\r\n            *(dest) = (Byte)*(dest + src);\r\n          while (++dest != lim);\r\n        }\r\n        else\r\n        {\r\n          do\r\n          {\r\n            dic[dicPos++] = dic[pos];\r\n            if (++pos == dicBufSize)\r\n              pos = 0;\r\n          }\r\n          while (--curLen != 0);\r\n        }\r\n      }\r\n    }\r\n  }\r\n  while (dicPos < limit && buf < bufLimit);\r\n  NORMALIZE;\r\n  p->buf = buf;\r\n  p->range = range;\r\n  p->code = code;\r\n  p->remainLen = len;\r\n  p->dicPos = dicPos;\r\n  p->processedPos = processedPos;\r\n  p->reps[0] = rep0;\r\n  p->reps[1] = rep1;\r\n  p->reps[2] = rep2;\r\n  p->reps[3] = rep3;\r\n  p->state = state;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\r\n{\r\n  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\r\n  {\r\n    Byte *dic = p->dic;\r\n    SizeT dicPos = p->dicPos;\r\n    SizeT dicBufSize = p->dicBufSize;\r\n    unsigned len = p->remainLen;\r\n    UInt32 rep0 = p->reps[0];\r\n    if (limit - dicPos < len)\r\n      len = (unsigned)(limit - dicPos);\r\n\r\n    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r\n      p->checkDicSize = p->prop.dicSize;\r\n\r\n    p->processedPos += len;\r\n    p->remainLen -= len;\r\n    while (len-- != 0)\r\n    {\r\n      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n      dicPos++;\r\n    }\r\n    p->dicPos = dicPos;\r\n  }\r\n}\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  do\r\n  {\r\n    SizeT limit2 = limit;\r\n    if (p->checkDicSize == 0)\r\n    {\r\n      UInt32 rem = p->prop.dicSize - p->processedPos;\r\n      if (limit - p->dicPos > rem)\r\n        limit2 = p->dicPos + rem;\r\n    }\r\n    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r\n    if (p->processedPos >= p->prop.dicSize)\r\n      p->checkDicSize = p->prop.dicSize;\r\n    LzmaDec_WriteRem(p, limit);\r\n  }\r\n  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r\n\r\n  if (p->remainLen > kMatchSpecLenStart)\r\n  {\r\n    p->remainLen = kMatchSpecLenStart;\r\n  }\r\n  return 0;\r\n}\r\n\r\ntypedef enum\r\n{\r\n  DUMMY_ERROR, /* unexpected end of input stream */\r\n  DUMMY_LIT,\r\n  DUMMY_MATCH,\r\n  DUMMY_REP\r\n} ELzmaDummy;\r\n\r\nstatic ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\r\n{\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n  const Byte *bufLimit = buf + inSize;\r\n  CLzmaProb *probs = p->probs;\r\n  unsigned state = p->state;\r\n  ELzmaDummy res;\r\n\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0_CHECK(prob)\r\n    {\r\n      UPDATE_0_CHECK\r\n\r\n      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\r\n\r\n      prob = probs + Literal;\r\n      if (p->checkDicSize != 0 || p->processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE *\r\n          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r\n          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        unsigned symbol = 1;\r\n        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r\n            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        unsigned symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      res = DUMMY_LIT;\r\n    }\r\n    else\r\n    {\r\n      unsigned len;\r\n      UPDATE_1_CHECK;\r\n\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0_CHECK(prob)\r\n      {\r\n        UPDATE_0_CHECK;\r\n        state = 0;\r\n        prob = probs + LenCoder;\r\n        res = DUMMY_MATCH;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1_CHECK;\r\n        res = DUMMY_REP;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0_CHECK(prob)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            NORMALIZE_CHECK;\r\n            return DUMMY_REP;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0_CHECK(prob)\r\n            {\r\n              UPDATE_0_CHECK;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1_CHECK;\r\n            }\r\n          }\r\n        }\r\n        state = kNumStates;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0_CHECK(probLen)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = 1 << kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0_CHECK(probLen)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = 1 << kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = 1 << kLenNumHighBits;\r\n          }\r\n        }\r\n        TREE_DECODE_CHECK(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        unsigned posSlot;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<\r\n            kNumPosSlotBits);\r\n        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n\r\n          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE_CHECK\r\n              range >>= 1;\r\n              code -= range & (((code - range) >> 31) - 1);\r\n              /* if (code >= range) code -= range; */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            unsigned i = 1;\r\n            do\r\n            {\r\n              GET_BIT_CHECK(prob + i, i);\r\n            }\r\n            while (--numDirectBits != 0);\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  NORMALIZE_CHECK;\r\n  return res;\r\n}\r\n\r\n\r\nstatic void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\r\n{\r\n  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\r\n  p->range = 0xFFFFFFFF;\r\n  p->needFlush = 0;\r\n}\r\n\r\nstatic void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r\n{\r\n  p->needFlush = 1;\r\n  p->remainLen = 0;\r\n  p->tempBufSize = 0;\r\n\r\n  if (initDic)\r\n  {\r\n    p->processedPos = 0;\r\n    p->checkDicSize = 0;\r\n    p->needInitState = 1;\r\n  }\r\n  if (initState)\r\n    p->needInitState = 1;\r\n}\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p)\r\n{\r\n  p->dicPos = 0;\r\n  LzmaDec_InitDicAndState(p, True, True);\r\n}\r\n\r\nstatic void LzmaDec_InitStateReal(CLzmaDec *p)\r\n{\r\n  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\r\n  UInt32 i;\r\n  CLzmaProb *probs = p->probs;\r\n  for (i = 0; i < numProbs; i++)\r\n    probs[i] = kBitModelTotal >> 1;\r\n  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;\r\n  p->state = 0;\r\n  p->needInitState = 0;\r\n}\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\r\n    ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT inSize = *srcLen;\r\n  (*srcLen) = 0;\r\n  LzmaDec_WriteRem(p, dicLimit);\r\n  \r\n  *status = LZMA_STATUS_NOT_SPECIFIED;\r\n\r\n  while (p->remainLen != kMatchSpecLenStart)\r\n  {\r\n      int checkEndMarkNow;\r\n\r\n      if (p->needFlush != 0)\r\n      {\r\n        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r\n          p->tempBuf[p->tempBufSize++] = *src++;\r\n        if (p->tempBufSize < RC_INIT_SIZE)\r\n        {\r\n          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n          return SZ_OK;\r\n        }\r\n        if (p->tempBuf[0] != 0)\r\n          return SZ_ERROR_DATA;\r\n\r\n        LzmaDec_InitRc(p, p->tempBuf);\r\n        p->tempBufSize = 0;\r\n      }\r\n\r\n      checkEndMarkNow = 0;\r\n      if (p->dicPos >= dicLimit)\r\n      {\r\n        if (p->remainLen == 0 && p->code == 0)\r\n        {\r\n          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;\r\n          return SZ_OK;\r\n        }\r\n        if (finishMode == LZMA_FINISH_ANY)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_OK;\r\n        }\r\n        if (p->remainLen != 0)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_ERROR_DATA;\r\n        }\r\n        checkEndMarkNow = 1;\r\n      }\r\n\r\n      if (p->needInitState)\r\n        LzmaDec_InitStateReal(p);\r\n  \r\n      if (p->tempBufSize == 0)\r\n      {\r\n        SizeT processed;\r\n        const Byte *bufLimit;\r\n        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            memcpy(p->tempBuf, src, inSize);\r\n            p->tempBufSize = (unsigned)inSize;\r\n            (*srcLen) += inSize;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n          bufLimit = src;\r\n        }\r\n        else\r\n          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\r\n        p->buf = src;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\r\n          return SZ_ERROR_DATA;\r\n        processed = (SizeT)(p->buf - src);\r\n        (*srcLen) += processed;\r\n        src += processed;\r\n        inSize -= processed;\r\n      }\r\n      else\r\n      {\r\n        unsigned rem = p->tempBufSize, lookAhead = 0;\r\n        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\r\n          p->tempBuf[rem++] = src[lookAhead++];\r\n        p->tempBufSize = rem;\r\n        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            (*srcLen) += lookAhead;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n        }\r\n        p->buf = p->tempBuf;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r\n          return SZ_ERROR_DATA;\r\n        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\r\n        (*srcLen) += lookAhead;\r\n        src += lookAhead;\r\n        inSize -= lookAhead;\r\n        p->tempBufSize = 0;\r\n      }\r\n  }\r\n  if (p->code == 0)\r\n    *status = LZMA_STATUS_FINISHED_WITH_MARK;\r\n  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT outSize = *destLen;\r\n  SizeT inSize = *srcLen;\r\n  *srcLen = *destLen = 0;\r\n  for (;;)\r\n  {\r\n    SizeT inSizeCur = inSize, outSizeCur, dicPos;\r\n    ELzmaFinishMode curFinishMode;\r\n    SRes res;\r\n    if (p->dicPos == p->dicBufSize)\r\n      p->dicPos = 0;\r\n    dicPos = p->dicPos;\r\n    if (outSize > p->dicBufSize - dicPos)\r\n    {\r\n      outSizeCur = p->dicBufSize;\r\n      curFinishMode = LZMA_FINISH_ANY;\r\n    }\r\n    else\r\n    {\r\n      outSizeCur = dicPos + outSize;\r\n      curFinishMode = finishMode;\r\n    }\r\n\r\n    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);\r\n    src += inSizeCur;\r\n    inSize -= inSizeCur;\r\n    *srcLen += inSizeCur;\r\n    outSizeCur = p->dicPos - dicPos;\r\n    memcpy(dest, p->dic + dicPos, outSizeCur);\r\n    dest += outSizeCur;\r\n    outSize -= outSizeCur;\r\n    *destLen += outSizeCur;\r\n    if (res != 0)\r\n      return res;\r\n    if (outSizeCur == 0 || outSize == 0)\r\n      return SZ_OK;\r\n  }\r\n}\r\n\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->probs);\r\n  p->probs = 0;\r\n}\r\n\r\nstatic void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->dic);\r\n  p->dic = 0;\r\n}\r\n\r\nvoid LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  LzmaDec_FreeProbs(p, alloc);\r\n  LzmaDec_FreeDict(p, alloc);\r\n}\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)\r\n{\r\n  UInt32 dicSize;\r\n  Byte d;\r\n  \r\n  if (size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  else\r\n    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);\r\n \r\n  if (dicSize < LZMA_DIC_MIN)\r\n    dicSize = LZMA_DIC_MIN;\r\n  p->dicSize = dicSize;\r\n\r\n  d = data[0];\r\n  if (d >= (9 * 5 * 5))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  p->lc = d % 9;\r\n  d /= 9;\r\n  p->pb = d / 5;\r\n  p->lp = d % 5;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r\n{\r\n  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r\n  if (p->probs == 0 || numProbs != p->numProbs)\r\n  {\r\n    LzmaDec_FreeProbs(p, alloc);\r\n    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r\n    p->numProbs = numProbs;\r\n    if (p->probs == 0)\r\n      return SZ_ERROR_MEM;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  SizeT dicBufSize;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  dicBufSize = propNew.dicSize;\r\n  if (p->dic == 0 || dicBufSize != p->dicBufSize)\r\n  {\r\n    LzmaDec_FreeDict(p, alloc);\r\n    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r\n    if (p->dic == 0)\r\n    {\r\n      LzmaDec_FreeProbs(p, alloc);\r\n      return SZ_ERROR_MEM;\r\n    }\r\n  }\r\n  p->dicBufSize = dicBufSize;\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc)\r\n{\r\n  CLzmaDec p;\r\n  SRes res;\r\n  SizeT inSize = *srcLen;\r\n  SizeT outSize = *destLen;\r\n  *srcLen = *destLen = 0;\r\n  if (inSize < RC_INIT_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  LzmaDec_Construct(&p);\r\n  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\r\n  if (res != 0)\r\n    return res;\r\n  p.dic = dest;\r\n  p.dicBufSize = outSize;\r\n\r\n  LzmaDec_Init(&p);\r\n  \r\n  *srcLen = inSize;\r\n  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r\n\r\n  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r\n    res = SZ_ERROR_INPUT_EOF;\r\n\r\n  (*destLen) = p.dicPos;\r\n  LzmaDec_FreeProbs(&p, alloc);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/lzma_src/C/LzmaDec.h",
    "content": "/* LzmaDec.h -- LZMA Decoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMADEC_H\r\n#define __LZMADEC_H\r\n\r\n#include \"Types.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* _LZMA_PROB32 can increase the speed on some CPUs,\r\n   but memory usage for CLzmaDec::probs will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n\r\n/* ---------- LZMA Properties ---------- */\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaProps\r\n{\r\n  unsigned lc, lp, pb;\r\n  UInt32 dicSize;\r\n} CLzmaProps;\r\n\r\n/* LzmaProps_Decode - decodes properties\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);\r\n\r\n\r\n/* ---------- LZMA Decoder state ---------- */\r\n\r\n/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.\r\n   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */\r\n\r\n#define LZMA_REQUIRED_INPUT_MAX 20\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProps prop;\r\n  CLzmaProb *probs;\r\n  Byte *dic;\r\n  const Byte *buf;\r\n  UInt32 range, code;\r\n  SizeT dicPos;\r\n  SizeT dicBufSize;\r\n  UInt32 processedPos;\r\n  UInt32 checkDicSize;\r\n  unsigned state;\r\n  UInt32 reps[4];\r\n  unsigned remainLen;\r\n  int needFlush;\r\n  int needInitState;\r\n  UInt32 numProbs;\r\n  unsigned tempBufSize;\r\n  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];\r\n} CLzmaDec;\r\n\r\n#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p);\r\n\r\n/* There are two types of LZMA streams:\r\n     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.\r\n     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_FINISH_ANY,   /* finish at any point */\r\n  LZMA_FINISH_END    /* block must be finished at the end */\r\n} ELzmaFinishMode;\r\n\r\n/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!\r\n\r\n   You must use LZMA_FINISH_END, when you know that current output buffer\r\n   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.\r\n\r\n   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,\r\n   and output value of destLen will be less than output buffer size limit.\r\n   You can check status result also.\r\n\r\n   You can use multiple checks to test data integrity after full decompression:\r\n     1) Check Result and \"status\" variable.\r\n     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.\r\n        You must use correct finish mode in that case. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */\r\n  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\r\n  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */\r\n  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */\r\n  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */\r\n} ELzmaStatus;\r\n\r\n/* ELzmaStatus is used only as output value for function call */\r\n\r\n\r\n/* ---------- Interfaces ---------- */\r\n\r\n/* There are 3 levels of interfaces:\r\n     1) Dictionary Interface\r\n     2) Buffer Interface\r\n     3) One Call Interface\r\n   You can select any of these interfaces, but don't mix functions from different\r\n   groups for same object. */\r\n\r\n\r\n/* There are two variants to allocate state for Dictionary Interface:\r\n     1) LzmaDec_Allocate / LzmaDec_Free\r\n     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs\r\n   You can use variant 2, if you set dictionary buffer manually.\r\n   For Buffer Interface you must always use variant 1.\r\n\r\nLzmaDec_Allocate* can return:\r\n  SZ_OK\r\n  SZ_ERROR_MEM         - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n   \r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);\r\n\r\n/* ---------- Dictionary Interface ---------- */\r\n\r\n/* You can use it, if you want to eliminate the overhead for data copying from\r\n   dictionary to some other external buffer.\r\n   You must work with CLzmaDec variables directly in this interface.\r\n\r\n   STEPS:\r\n     LzmaDec_Constr()\r\n     LzmaDec_Allocate()\r\n     for (each new stream)\r\n     {\r\n       LzmaDec_Init()\r\n       while (it needs more decompression)\r\n       {\r\n         LzmaDec_DecodeToDic()\r\n         use data from CLzmaDec::dic and update CLzmaDec::dicPos\r\n       }\r\n     }\r\n     LzmaDec_Free()\r\n*/\r\n\r\n/* LzmaDec_DecodeToDic\r\n   \r\n   The decoding to internal dictionary buffer (CLzmaDec::dic).\r\n   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (dicLimit).\r\n  LZMA_FINISH_ANY - Decode just dicLimit bytes.\r\n  LZMA_FINISH_END - Stream must be finished after dicLimit.\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_NEEDS_MORE_INPUT\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- Buffer Interface ---------- */\r\n\r\n/* It's zlib-like interface.\r\n   See LzmaDec_DecodeToDic description for information about STEPS and return results,\r\n   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need\r\n   to work with CLzmaDec variables manually.\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n*/\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaDecode\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n  SZ_ERROR_MEM  - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n*/\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/lzma_src/C/LzmaEnc.c",
    "content": "/* LzmaEnc.c -- LZMA Encoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n/* #define SHOW_STAT */\r\n/* #define SHOW_STAT2 */\r\n\r\n#if defined(SHOW_STAT) || defined(SHOW_STAT2)\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"LzmaEnc.h\"\r\n\r\n#include \"LzFind.h\"\r\n#ifdef COMPRESS_MF_MT\r\n#include \"LzFindMt.h\"\r\n#endif\r\n\r\n#ifdef SHOW_STAT\r\nstatic int ttt = 0;\r\n#endif\r\n\r\n#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)\r\n\r\n#define kBlockSize (9 << 10)\r\n#define kUnpackBlockSize (1 << 18)\r\n#define kMatchArraySize (1 << 21)\r\n#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)\r\n\r\n#define kNumMaxDirectBits (31)\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n#define kProbInitValue (kBitModelTotal >> 1)\r\n\r\n#define kNumMoveReducingBits 4\r\n#define kNumBitPriceShiftBits 4\r\n#define kBitPrice (1 << kNumBitPriceShiftBits)\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p)\r\n{\r\n/* The default dictionary size is 16M, it is too big for CFE heap memory size (400K).\r\n * The lzma_compression_level is between 1 to 5 and dictionary size is \r\n * (1<< (lzma_compression_level*2+14)).\r\n */\r\n\tp->level = 1;\r\n  p->dictSize = p->mc = 0;\r\n  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\r\n  p->writeEndMark = 0;\r\n}\r\n\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p)\r\n{\r\n  int level = p->level;\r\n  if (level < 0) level = 5;\r\n  p->level = level;\r\n  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));\r\n  if (p->lc < 0) p->lc = 3;\r\n  if (p->lp < 0) p->lp = 0;\r\n  if (p->pb < 0) p->pb = 2;\r\n  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);\r\n  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);\r\n  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);\r\n  if (p->numHashBytes < 0) p->numHashBytes = 4;\r\n  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\r\n  if (p->numThreads < 0) p->numThreads = ((p->btMode && p->algo) ? 2 : 1);\r\n}\r\n\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n  return props.dictSize;\r\n}\r\n\r\n/* #define LZMA_LOG_BSR */\r\n/* Define it for Intel's CPU */\r\n\r\n\r\n#ifdef LZMA_LOG_BSR\r\n\r\n#define kDicLogSizeMaxCompress 30\r\n\r\n#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }\r\n\r\nUInt32 GetPosSlot1(UInt32 pos)\r\n{\r\n  UInt32 res;\r\n  BSR2_RET(pos, res);\r\n  return res;\r\n}\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }\r\n\r\n#else\r\n\r\n#define kNumLogBits (9 + (int)sizeof(size_t) / 2)\r\n#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)\r\n\r\nvoid LzmaEnc_FastPosInit(Byte *g_FastPos)\r\n{\r\n  int c = 2, slotFast;\r\n  g_FastPos[0] = 0;\r\n  g_FastPos[1] = 1;\r\n  \r\n  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)\r\n  {\r\n    UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n    UInt32 j;\r\n    for (j = 0; j < k; j++, c++)\r\n      g_FastPos[c] = (Byte)slotFast;\r\n  }\r\n}\r\n\r\n#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \\\r\n  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \\\r\n  res = p->g_FastPos[pos >> i] + (i * 2); }\r\n/*\r\n#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \\\r\n  p->g_FastPos[pos >> 6] + 12 : \\\r\n  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }\r\n*/\r\n\r\n#define GetPosSlot1(pos) p->g_FastPos[pos]\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }\r\n\r\n#endif\r\n\r\n\r\n#define LZMA_NUM_REPS 4\r\n\r\ntypedef unsigned CState;\r\n\r\ntypedef struct _COptimal\r\n{\r\n  UInt32 price;\r\n\r\n  CState state;\r\n  int prev1IsChar;\r\n  int prev2;\r\n\r\n  UInt32 posPrev2;\r\n  UInt32 backPrev2;\r\n\r\n  UInt32 posPrev;\r\n  UInt32 backPrev;\r\n  UInt32 backs[LZMA_NUM_REPS];\r\n} COptimal;\r\n\r\n#define kNumOpts (1 << 12)\r\n\r\n#define kNumLenToPosStates 4\r\n#define kNumPosSlotBits 6\r\n#define kDicLogSizeMin 0\r\n#define kDicLogSizeMax 32\r\n#define kDistTableSizeMax (kDicLogSizeMax * 2)\r\n\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n#define kAlignMask (kAlignTableSize - 1)\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)\r\n\r\n#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n#define LZMA_PB_MAX 4\r\n#define LZMA_LC_MAX 8\r\n#define LZMA_LP_MAX 4\r\n\r\n#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)\r\n\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define LZMA_MATCH_LEN_MIN 2\r\n#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)\r\n\r\n#define kNumStates 12\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb choice;\r\n  CLzmaProb choice2;\r\n  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];\r\n  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];\r\n  CLzmaProb high[kLenNumHighSymbols];\r\n} CLenEnc;\r\n\r\ntypedef struct\r\n{\r\n  CLenEnc p;\r\n  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\r\n  UInt32 tableSize;\r\n  UInt32 counters[LZMA_NUM_PB_STATES_MAX];\r\n} CLenPriceEnc;\r\n\r\ntypedef struct _CRangeEnc\r\n{\r\n  UInt32 range;\r\n  Byte cache;\r\n  UInt64 low;\r\n  UInt64 cacheSize;\r\n  Byte *buf;\r\n  Byte *bufLim;\r\n  Byte *bufBase;\r\n  ISeqOutStream *outStream;\r\n  UInt64 processed;\r\n  SRes res;\r\n} CRangeEnc;\r\n\r\ntypedef struct _CSeqInStreamBuf\r\n{\r\n  ISeqInStream funcTable;\r\n  const Byte *data;\r\n  SizeT rem;\r\n} CSeqInStreamBuf;\r\n\r\nstatic SRes MyRead(void *pp, void *data, size_t *size)\r\n{\r\n  size_t curSize = *size;\r\n  CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;\r\n  if (p->rem < curSize)\r\n    curSize = p->rem;\r\n  memcpy(data, p->data, curSize);\r\n  p->rem -= curSize;\r\n  p->data += curSize;\r\n  *size = curSize;\r\n  return SZ_OK;\r\n}\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n} CSaveState;\r\n\r\ntypedef struct _CLzmaEnc\r\n{\r\n  IMatchFinder matchFinder;\r\n  void *matchFinderObj;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Bool mtMode;\r\n  CMatchFinderMt matchFinderMt;\r\n  #endif\r\n\r\n  CMatchFinder matchFinderBase;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte pad[128];\r\n  #endif\r\n  \r\n  UInt32 optimumEndIndex;\r\n  UInt32 optimumCurrentIndex;\r\n\r\n  UInt32 longestMatchLength;\r\n  UInt32 numPairs;\r\n  UInt32 numAvail;\r\n  COptimal opt[kNumOpts];\r\n  \r\n  #ifndef LZMA_LOG_BSR\r\n  Byte g_FastPos[1 << kNumLogBits];\r\n  #endif\r\n\r\n  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];\r\n  UInt32 numFastBytes;\r\n  UInt32 additionalOffset;\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n\r\n  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n  UInt32 alignPrices[kAlignTableSize];\r\n  UInt32 alignPriceCount;\r\n\r\n  UInt32 distTableSize;\r\n\r\n  unsigned lc, lp, pb;\r\n  unsigned lpMask, pbMask;\r\n\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  unsigned lclp;\r\n\r\n  Bool fastMode;\r\n  \r\n  CRangeEnc rc;\r\n\r\n  Bool writeEndMark;\r\n  UInt64 nowPos64;\r\n  UInt32 matchPriceCount;\r\n  Bool finished;\r\n  Bool multiThread;\r\n\r\n  SRes result;\r\n  UInt32 dictSize;\r\n  UInt32 matchFinderCycles;\r\n\r\n  ISeqInStream *inStream;\r\n  CSeqInStreamBuf seqBufInStream;\r\n\r\n  CSaveState saveState;\r\n} CLzmaEnc;\r\n\r\nvoid LzmaEnc_SaveState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CSaveState *dest = &p->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nvoid LzmaEnc_RestoreState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *dest = (CLzmaEnc *)pp;\r\n  const CSaveState *p = &dest->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n\r\n  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||\r\n      props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))\r\n    return SZ_ERROR_PARAM;\r\n  p->dictSize = props.dictSize;\r\n  p->matchFinderCycles = props.mc;\r\n  {\r\n    unsigned fb = props.fb;\r\n    if (fb < 5)\r\n      fb = 5;\r\n    if (fb > LZMA_MATCH_LEN_MAX)\r\n      fb = LZMA_MATCH_LEN_MAX;\r\n    p->numFastBytes = fb;\r\n  }\r\n  p->lc = props.lc;\r\n  p->lp = props.lp;\r\n  p->pb = props.pb;\r\n  p->fastMode = (props.algo == 0);\r\n  p->matchFinderBase.btMode = props.btMode;\r\n  {\r\n    UInt32 numHashBytes = 4;\r\n    if (props.btMode)\r\n    {\r\n      if (props.numHashBytes < 2)\r\n        numHashBytes = 2;\r\n      else if (props.numHashBytes < 4)\r\n        numHashBytes = props.numHashBytes;\r\n    }\r\n    p->matchFinderBase.numHashBytes = numHashBytes;\r\n  }\r\n\r\n  p->matchFinderBase.cutValue = props.mc;\r\n\r\n  p->writeEndMark = props.writeEndMark;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  /*\r\n  if (newMultiThread != _multiThread)\r\n  {\r\n    ReleaseMatchFinder();\r\n    _multiThread = newMultiThread;\r\n  }\r\n  */\r\n  p->multiThread = (props.numThreads > 1);\r\n  #endif\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nstatic const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nstatic const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nstatic const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n#define IsCharState(s) ((s) < 7)\r\n\r\n#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)\r\n\r\n#define kInfinityPrice (1 << 30)\r\n\r\nstatic void RangeEnc_Construct(CRangeEnc *p)\r\n{\r\n  p->outStream = 0;\r\n  p->bufBase = 0;\r\n}\r\n\r\n#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)\r\n\r\n#define RC_BUF_SIZE (1 << 16)\r\nstatic int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  if (p->bufBase == 0)\r\n  {\r\n    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);\r\n    if (p->bufBase == 0)\r\n      return 0;\r\n    p->bufLim = p->bufBase + RC_BUF_SIZE;\r\n  }\r\n  return 1;\r\n}\r\n\r\nstatic void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->bufBase);\r\n  p->bufBase = 0;\r\n}\r\n\r\nstatic void RangeEnc_Init(CRangeEnc *p)\r\n{\r\n  /* Stream.Init(); */\r\n  p->low = 0;\r\n  p->range = 0xFFFFFFFF;\r\n  p->cacheSize = 1;\r\n  p->cache = 0;\r\n\r\n  p->buf = p->bufBase;\r\n\r\n  p->processed = 0;\r\n  p->res = SZ_OK;\r\n}\r\n\r\nstatic void RangeEnc_FlushStream(CRangeEnc *p)\r\n{\r\n  size_t num;\r\n  if (p->res != SZ_OK)\r\n    return;\r\n  num = p->buf - p->bufBase;\r\n  if (num != p->outStream->Write(p->outStream, p->bufBase, num))\r\n    p->res = SZ_ERROR_WRITE;\r\n  p->processed += num;\r\n  p->buf = p->bufBase;\r\n}\r\n\r\nstatic void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)\r\n{\r\n  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)\r\n  {\r\n    Byte temp = p->cache;\r\n    do\r\n    {\r\n      Byte *buf = p->buf;\r\n      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));\r\n      p->buf = buf;\r\n      if (buf == p->bufLim)\r\n        RangeEnc_FlushStream(p);\r\n      temp = 0xFF;\r\n    }\r\n    while (--p->cacheSize != 0);\r\n    p->cache = (Byte)((UInt32)p->low >> 24);\r\n  }\r\n  p->cacheSize++;\r\n  p->low = (UInt32)p->low << 8;\r\n}\r\n\r\nstatic void RangeEnc_FlushData(CRangeEnc *p)\r\n{\r\n  int i;\r\n  for (i = 0; i < 5; i++)\r\n    RangeEnc_ShiftLow(p);\r\n}\r\n\r\nstatic void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)\r\n{\r\n  do\r\n  {\r\n    p->range >>= 1;\r\n    p->low += p->range & (0 - ((value >> --numBits) & 1));\r\n    if (p->range < kTopValue)\r\n    {\r\n      p->range <<= 8;\r\n      RangeEnc_ShiftLow(p);\r\n    }\r\n  }\r\n  while (numBits != 0);\r\n}\r\n\r\nstatic void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)\r\n{\r\n  UInt32 ttt = *prob;\r\n  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;\r\n  if (symbol == 0)\r\n  {\r\n    p->range = newBound;\r\n    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;\r\n  }\r\n  else\r\n  {\r\n    p->low += newBound;\r\n    p->range -= newBound;\r\n    ttt -= ttt >> kNumMoveBits;\r\n  }\r\n  *prob = (CLzmaProb)ttt;\r\n  if (p->range < kTopValue)\r\n  {\r\n    p->range <<= 8;\r\n    RangeEnc_ShiftLow(p);\r\n  }\r\n}\r\n\r\nstatic void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)\r\n{\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nstatic void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)\r\n{\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nvoid LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\r\n{\r\n  UInt32 i;\r\n  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))\r\n  {\r\n    const int kCyclesBits = kNumBitPriceShiftBits;\r\n    UInt32 w = i;\r\n    UInt32 bitCount = 0;\r\n    int j;\r\n    for (j = 0; j < kCyclesBits; j++)\r\n    {\r\n      w = w * w;\r\n      bitCount <<= 1;\r\n      while (w >= ((UInt32)1 << 16))\r\n      {\r\n        w >>= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);\r\n  }\r\n}\r\n\r\n\r\n#define GET_PRICE(prob, symbol) \\\r\n  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICEa(prob, symbol) \\\r\n  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\n#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\nstatic UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\nstatic UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\n\r\nstatic void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0;)\r\n  {\r\n    UInt32 bit;\r\n    i--;\r\n    bit = (symbol >> i) & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n}\r\n\r\nstatic void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = 0; i < numBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= (1 << numBitLevels);\r\n  while (symbol != 1)\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);\r\n    symbol >>= 1;\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += GET_PRICEa(probs[m], bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\n\r\nstatic void LenEnc_Init(CLenEnc *p)\r\n{\r\n  unsigned i;\r\n  p->choice = p->choice2 = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)\r\n    p->low[i] = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)\r\n    p->mid[i] = kProbInitValue;\r\n  for (i = 0; i < kLenNumHighSymbols; i++)\r\n    p->high[i] = kProbInitValue;\r\n}\r\n\r\nstatic void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)\r\n{\r\n  if (symbol < kLenNumLowSymbols)\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 0);\r\n    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);\r\n  }\r\n  else\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 1);\r\n    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 0);\r\n      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 1);\r\n      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)\r\n{\r\n  UInt32 a0 = GET_PRICE_0a(p->choice);\r\n  UInt32 a1 = GET_PRICE_1a(p->choice);\r\n  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);\r\n  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kLenNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);\r\n  }\r\n  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);\r\n}\r\n\r\nstatic void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);\r\n  p->counters[posState] = p->tableSize;\r\n}\r\n\r\nstatic void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)\r\n{\r\n  UInt32 posState;\r\n  for (posState = 0; posState < numPosStates; posState++)\r\n    LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\nstatic void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_Encode(&p->p, rc, symbol, posState);\r\n  if (updatePrice)\r\n    if (--p->counters[posState] == 0)\r\n      LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\n\r\n\r\n\r\nstatic void MovePos(CLzmaEnc *p, UInt32 num)\r\n{\r\n  #ifdef SHOW_STAT\r\n  ttt += num;\r\n  printf(\"\\n MovePos %d\", num);\r\n  #endif\r\n  if (num != 0)\r\n  {\r\n    p->additionalOffset += num;\r\n    p->matchFinder.Skip(p->matchFinderObj, num);\r\n  }\r\n}\r\n\r\nstatic UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)\r\n{\r\n  UInt32 lenRes = 0, numPairs;\r\n  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);\r\n  #ifdef SHOW_STAT\r\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numPairs / 2);\r\n  ttt++;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < numPairs; i += 2)\r\n      printf(\"%2d %6d   | \", p->matches[i], p->matches[i + 1]);\r\n  }\r\n  #endif\r\n  if (numPairs > 0)\r\n  {\r\n    lenRes = p->matches[numPairs - 2];\r\n    if (lenRes == p->numFastBytes)\r\n    {\r\n      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n      UInt32 distance = p->matches[numPairs - 1] + 1;\r\n      UInt32 numAvail = p->numAvail;\r\n      if (numAvail > LZMA_MATCH_LEN_MAX)\r\n        numAvail = LZMA_MATCH_LEN_MAX;\r\n      {\r\n        const Byte *pby2 = pby - distance;\r\n        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r\n      }\r\n    }\r\n  }\r\n  p->additionalOffset++;\r\n  *numDistancePairsRes = numPairs;\r\n  return lenRes;\r\n}\r\n\r\n\r\n#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;\r\n#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;\r\n#define IsShortRep(p) ((p)->backPrev == 0)\r\n\r\nstatic UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)\r\n{\r\n  return\r\n    GET_PRICE_0(p->isRepG0[state]) +\r\n    GET_PRICE_0(p->isRep0Long[state][posState]);\r\n}\r\n\r\nstatic UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)\r\n{\r\n  UInt32 price;\r\n  if (repIndex == 0)\r\n  {\r\n    price = GET_PRICE_0(p->isRepG0[state]);\r\n    price += GET_PRICE_1(p->isRep0Long[state][posState]);\r\n  }\r\n  else\r\n  {\r\n    price = GET_PRICE_1(p->isRepG0[state]);\r\n    if (repIndex == 1)\r\n      price += GET_PRICE_0(p->isRepG1[state]);\r\n    else\r\n    {\r\n      price += GET_PRICE_1(p->isRepG1[state]);\r\n      price += GET_PRICE(p->isRepG2[state], repIndex - 2);\r\n    }\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)\r\n{\r\n  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +\r\n    GetPureRepPrice(p, repIndex, state, posState);\r\n}\r\n\r\nstatic UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)\r\n{\r\n  UInt32 posMem = p->opt[cur].posPrev;\r\n  UInt32 backMem = p->opt[cur].backPrev;\r\n  p->optimumEndIndex = cur;\r\n  do\r\n  {\r\n    if (p->opt[cur].prev1IsChar)\r\n    {\r\n      MakeAsChar(&p->opt[posMem])\r\n      p->opt[posMem].posPrev = posMem - 1;\r\n      if (p->opt[cur].prev2)\r\n      {\r\n        p->opt[posMem - 1].prev1IsChar = False;\r\n        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;\r\n        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;\r\n      }\r\n    }\r\n    {\r\n      UInt32 posPrev = posMem;\r\n      UInt32 backCur = backMem;\r\n      \r\n      backMem = p->opt[posPrev].backPrev;\r\n      posMem = p->opt[posPrev].posPrev;\r\n      \r\n      p->opt[posPrev].backPrev = backCur;\r\n      p->opt[posPrev].posPrev = cur;\r\n      cur = posPrev;\r\n    }\r\n  }\r\n  while (cur != 0);\r\n  *backRes = p->opt[0].backPrev;\r\n  p->optimumCurrentIndex  = p->opt[0].posPrev;\r\n  return p->optimumCurrentIndex;\r\n}\r\n\r\n#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)\r\n\r\nstatic UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;\r\n  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\r\n  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];\r\n  UInt32 *matches;\r\n  const Byte *data;\r\n  Byte curByte, matchByte;\r\n  if (p->optimumEndIndex != p->optimumCurrentIndex)\r\n  {\r\n    const COptimal *opt = &p->opt[p->optimumCurrentIndex];\r\n    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;\r\n    *backRes = opt->backPrev;\r\n    p->optimumCurrentIndex = opt->posPrev;\r\n    return lenRes;\r\n  }\r\n  p->optimumCurrentIndex = p->optimumEndIndex = 0;\r\n  \r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  if (numAvail < 2)\r\n  {\r\n    *backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  repMaxIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 lenTest;\r\n    const Byte *data2;\r\n    reps[i] = p->reps[i];\r\n    data2 = data - (reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if (repLens[repMaxIndex] >= p->numFastBytes)\r\n  {\r\n    UInt32 lenRes;\r\n    *backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    MovePos(p, lenRes - 1);\r\n    return lenRes;\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n  curByte = *data;\r\n  matchByte = *(data - (reps[0] + 1));\r\n\r\n  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    *backRes = (UInt32)-1;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[0].state = (CState)p->state;\r\n\r\n  posState = (position & p->pbMask);\r\n\r\n  {\r\n    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +\r\n        (!IsCharState(p->state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n  }\r\n\r\n  MakeAsChar(&p->opt[1]);\r\n\r\n  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);\r\n  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);\r\n\r\n  if (matchByte == curByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);\r\n    if (shortRepPrice < p->opt[1].price)\r\n    {\r\n      p->opt[1].price = shortRepPrice;\r\n      MakeAsShortRep(&p->opt[1]);\r\n    }\r\n  }\r\n  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);\r\n\r\n  if (lenEnd < 2)\r\n  {\r\n    *backRes = p->opt[1].backPrev;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[1].posPrev = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n    p->opt[0].backs[i] = reps[i];\r\n\r\n  len = lenEnd;\r\n  do\r\n    p->opt[len--].price = kInfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    UInt32 price;\r\n    if (repLen < 2)\r\n      continue;\r\n    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];\r\n      COptimal *opt = &p->opt[repLen];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = i;\r\n        opt->prev1IsChar = False;\r\n      }\r\n    }\r\n    while (--repLen >= 2);\r\n  }\r\n\r\n  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= mainLen)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matches[offs])\r\n      offs += 2;\r\n    for (; ; len++)\r\n    {\r\n      COptimal *opt;\r\n      UInt32 distance = matches[offs + 1];\r\n\r\n      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];\r\n      UInt32 lenToPosState = GetLenToPosState(len);\r\n      if (distance < kNumFullDistances)\r\n        curAndLenPrice += p->distancesPrices[lenToPosState][distance];\r\n      else\r\n      {\r\n        UInt32 slot;\r\n        GetPosSlot2(distance, slot);\r\n        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];\r\n      }\r\n      opt = &p->opt[len];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = distance + LZMA_NUM_REPS;\r\n        opt->prev1IsChar = False;\r\n      }\r\n      if (len == matches[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numPairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  cur = 0;\r\n\r\n    #ifdef SHOW_STAT2\r\n    if (position >= 0)\r\n    {\r\n      unsigned i;\r\n      printf(\"\\n pos = %4X\", position);\r\n      for (i = cur; i <= lenEnd; i++)\r\n      printf(\"\\nprice[%4X] = %d\", position - cur + i, p->opt[i].price);\r\n    }\r\n    #endif\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;\r\n    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;\r\n    Bool nextIsChar;\r\n    Byte curByte, matchByte;\r\n    const Byte *data;\r\n    COptimal *curOpt;\r\n    COptimal *nextOpt;\r\n\r\n    cur++;\r\n    if (cur == lenEnd)\r\n      return Backward(p, backRes, cur);\r\n\r\n    newLen = ReadMatchDistances(p, &numPairs);\r\n    if (newLen >= p->numFastBytes)\r\n    {\r\n      p->numPairs = numPairs;\r\n      p->longestMatchLength = newLen;\r\n      return Backward(p, backRes, cur);\r\n    }\r\n    position++;\r\n    curOpt = &p->opt[cur];\r\n    posPrev = curOpt->posPrev;\r\n    if (curOpt->prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOpt->prev2)\r\n      {\r\n        state = p->opt[curOpt->posPrev2].state;\r\n        if (curOpt->backPrev2 < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      else\r\n        state = p->opt[posPrev].state;\r\n      state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n      state = p->opt[posPrev].state;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (IsShortRep(curOpt))\r\n        state = kShortRepNextStates[state];\r\n      else\r\n        state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      const COptimal *prevOpt;\r\n      if (curOpt->prev1IsChar && curOpt->prev2)\r\n      {\r\n        posPrev = curOpt->posPrev2;\r\n        pos = curOpt->backPrev2;\r\n        state = kRepNextStates[state];\r\n      }\r\n      else\r\n      {\r\n        pos = curOpt->backPrev;\r\n        if (pos < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      prevOpt = &p->opt[posPrev];\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        UInt32 i;\r\n        reps[0] = prevOpt->backs[pos];\r\n        for (i = 1; i <= pos; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n        for (; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i];\r\n      }\r\n      else\r\n      {\r\n        UInt32 i;\r\n        reps[0] = (pos - LZMA_NUM_REPS);\r\n        for (i = 1; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n      }\r\n    }\r\n    curOpt->state = (CState)state;\r\n\r\n    curOpt->backs[0] = reps[0];\r\n    curOpt->backs[1] = reps[1];\r\n    curOpt->backs[2] = reps[2];\r\n    curOpt->backs[3] = reps[3];\r\n\r\n    curPrice = curOpt->price;\r\n    nextIsChar = False;\r\n    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n    curByte = *data;\r\n    matchByte = *(data - (reps[0] + 1));\r\n\r\n    posState = (position & p->pbMask);\r\n\r\n    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);\r\n    {\r\n      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n      curAnd1Price +=\r\n        (!IsCharState(state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n    }\r\n\r\n    nextOpt = &p->opt[cur + 1];\r\n\r\n    if (curAnd1Price < nextOpt->price)\r\n    {\r\n      nextOpt->price = curAnd1Price;\r\n      nextOpt->posPrev = cur;\r\n      MakeAsChar(nextOpt);\r\n      nextIsChar = True;\r\n    }\r\n\r\n    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);\r\n    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);\r\n    \r\n    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);\r\n      if (shortRepPrice <= nextOpt->price)\r\n      {\r\n        nextOpt->price = shortRepPrice;\r\n        nextOpt->posPrev = cur;\r\n        MakeAsShortRep(nextOpt);\r\n        nextIsChar = True;\r\n      }\r\n    }\r\n    numAvailFull = p->numAvail;\r\n    {\r\n      UInt32 temp = kNumOpts - 1 - cur;\r\n      if (temp < numAvailFull)\r\n        numAvailFull = temp;\r\n    }\r\n\r\n    if (numAvailFull < 2)\r\n      continue;\r\n    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);\r\n\r\n    if (!nextIsChar && matchByte != curByte) /* speed optimization */\r\n    {\r\n      /* try Literal + rep0 */\r\n      UInt32 temp;\r\n      UInt32 lenTest2;\r\n      const Byte *data2 = data - (reps[0] + 1);\r\n      UInt32 limit = p->numFastBytes + 1;\r\n      if (limit > numAvailFull)\r\n        limit = numAvailFull;\r\n\r\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r\n      lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        UInt32 state2 = kLiteralNextStates[state];\r\n        UInt32 posStateNext = (position + 1) & p->pbMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price +\r\n            GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n            GET_PRICE_1(p->isRep[state2]);\r\n        /* for (; lenTest2 >= 2; lenTest2--) */\r\n        {\r\n          UInt32 curAndLenPrice;\r\n          COptimal *opt;\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while (lenEnd < offset)\r\n            p->opt[++lenEnd].price = kInfinityPrice;\r\n          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n          opt = &p->opt[offset];\r\n          if (curAndLenPrice < opt->price)\r\n          {\r\n            opt->price = curAndLenPrice;\r\n            opt->posPrev = cur + 1;\r\n            opt->backPrev = 0;\r\n            opt->prev1IsChar = True;\r\n            opt->prev2 = False;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    startLen = 2; /* speed optimization */\r\n    {\r\n    UInt32 repIndex;\r\n    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)\r\n    {\r\n      UInt32 lenTest;\r\n      UInt32 lenTestTemp;\r\n      UInt32 price;\r\n      const Byte *data2 = data - (reps[repIndex] + 1);\r\n      if (data[0] != data2[0] || data[1] != data2[1])\r\n        continue;\r\n      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n      while (lenEnd < cur + lenTest)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n      lenTestTemp = lenTest;\r\n      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];\r\n        COptimal *opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = repIndex;\r\n          opt->prev1IsChar = False;\r\n        }\r\n      }\r\n      while (--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      /* if (_maxMode) */\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kRepNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice =\r\n                price + p->repLenEnc.prices[posState][lenTest - 2] +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (position + lenTest + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n    }\r\n    }\r\n    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */\r\n    if (newLen > numAvail)\r\n    {\r\n      newLen = numAvail;\r\n      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);\r\n      matches[numPairs] = newLen;\r\n      numPairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\r\n      UInt32 offs, curBack, posSlot;\r\n      UInt32 lenTest;\r\n      while (lenEnd < cur + newLen)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n\r\n      offs = 0;\r\n      while (startLen > matches[offs])\r\n        offs += 2;\r\n      curBack = matches[offs + 1];\r\n      GetPosSlot2(curBack, posSlot);\r\n      for (lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        COptimal *opt;\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];\r\n        \r\n        opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = curBack + LZMA_NUM_REPS;\r\n          opt->prev1IsChar = False;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matches[offs])\r\n        {\r\n          /* Try Match + Literal + Rep0 */\r\n          const Byte *data2 = data - (curBack + 1);\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kMatchNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (posStateNext + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = curBack + LZMA_NUM_REPS;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numPairs)\r\n            break;\r\n          curBack = matches[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            GetPosSlot2(curBack, posSlot);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))\r\n\r\nstatic UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;\r\n  const Byte *data;\r\n  const UInt32 *matches;\r\n\r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  *backRes = (UInt32)-1;\r\n  if (numAvail < 2)\r\n    return 1;\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n\r\n  repLen = repIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    for (len = 2; len < numAvail && data[len] == data2[len]; len++);\r\n    if (len >= p->numFastBytes)\r\n    {\r\n      *backRes = i;\r\n      MovePos(p, len - 1);\r\n      return len;\r\n    }\r\n    if (len > repLen)\r\n    {\r\n      repIndex = i;\r\n      repLen = len;\r\n    }\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n\r\n  mainDist = 0; /* for GCC */\r\n  if (mainLen >= 2)\r\n  {\r\n    mainDist = matches[numPairs - 1];\r\n    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matches[numPairs - 3], mainDist))\r\n        break;\r\n      numPairs -= 2;\r\n      mainLen = matches[numPairs - 2];\r\n      mainDist = matches[numPairs - 1];\r\n    }\r\n    if (mainLen == 2 && mainDist >= 0x80)\r\n      mainLen = 1;\r\n  }\r\n\r\n  if (repLen >= 2 && (\r\n        (repLen + 1 >= mainLen) ||\r\n        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||\r\n        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))\r\n  {\r\n    *backRes = repIndex;\r\n    MovePos(p, repLen - 1);\r\n    return repLen;\r\n  }\r\n  \r\n  if (mainLen < 2 || numAvail <= 2)\r\n    return 1;\r\n\r\n  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);\r\n  if (p->longestMatchLength >= 2)\r\n  {\r\n    UInt32 newDistance = matches[p->numPairs - 1];\r\n    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||\r\n        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||\r\n        (p->longestMatchLength > mainLen + 1) ||\r\n        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))\r\n      return 1;\r\n  }\r\n  \r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len, limit;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    limit = mainLen - 1;\r\n    for (len = 2; len < limit && data[len] == data2[len]; len++);\r\n    if (len >= limit)\r\n      return 1;\r\n  }\r\n  *backRes = mainDist + LZMA_NUM_REPS;\r\n  MovePos(p, mainLen - 2);\r\n  return mainLen;\r\n}\r\n\r\nstatic void WriteEndMarker(CLzmaEnc *p, UInt32 posState)\r\n{\r\n  UInt32 len;\r\n  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n  p->state = kMatchNextStates[p->state];\r\n  len = LZMA_MATCH_LEN_MIN;\r\n  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);\r\n  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);\r\n  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);\r\n}\r\n\r\nstatic SRes CheckErrors(CLzmaEnc *p)\r\n{\r\n  if (p->result != SZ_OK)\r\n    return p->result;\r\n  if (p->rc.res != SZ_OK)\r\n    p->result = SZ_ERROR_WRITE;\r\n  if (p->matchFinderBase.result != SZ_OK)\r\n    p->result = SZ_ERROR_READ;\r\n  if (p->result != SZ_OK)\r\n    p->finished = True;\r\n  return p->result;\r\n}\r\n\r\nstatic SRes Flush(CLzmaEnc *p, UInt32 nowPos)\r\n{\r\n  /* ReleaseMFStream(); */\r\n  p->finished = True;\r\n  if (p->writeEndMark)\r\n    WriteEndMarker(p, nowPos & p->pbMask);\r\n  RangeEnc_FlushData(&p->rc);\r\n  RangeEnc_FlushStream(&p->rc);\r\n  return CheckErrors(p);\r\n}\r\n\r\nstatic void FillAlignPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < kAlignTableSize; i++)\r\n    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);\r\n  p->alignPriceCount = 0;\r\n}\r\n\r\nstatic void FillDistancesPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  UInt32 i, lenToPosState;\r\n  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  {\r\n    UInt32 posSlot = GetPosSlot1(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);\r\n  }\r\n\r\n  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n    UInt32 posSlot;\r\n    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);\r\n    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);\r\n\r\n    {\r\n      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];\r\n      UInt32 i;\r\n      for (i = 0; i < kStartPosModelIndex; i++)\r\n        distancesPrices[i] = posSlotPrices[i];\r\n      for (; i < kNumFullDistances; i++)\r\n        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];\r\n    }\r\n  }\r\n  p->matchPriceCount = 0;\r\n}\r\n\r\nvoid LzmaEnc_Construct(CLzmaEnc *p)\r\n{\r\n  RangeEnc_Construct(&p->rc);\r\n  MatchFinder_Construct(&p->matchFinderBase);\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Construct(&p->matchFinderMt);\r\n  p->matchFinderMt.MatchFinder = &p->matchFinderBase;\r\n  #endif\r\n\r\n  {\r\n    CLzmaEncProps props;\r\n    LzmaEncProps_Init(&props);\r\n    LzmaEnc_SetProps(p, &props);\r\n  }\r\n\r\n  #ifndef LZMA_LOG_BSR\r\n  LzmaEnc_FastPosInit(p->g_FastPos);\r\n  #endif\r\n\r\n  LzmaEnc_InitPriceTables(p->ProbPrices);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)\r\n{\r\n  void *p;\r\n  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));\r\n  if (p != 0)\r\n    LzmaEnc_Construct((CLzmaEnc *)p);\r\n  return p;\r\n}\r\n\r\nvoid LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->litProbs);\r\n  alloc->Free(alloc, p->saveState.litProbs);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nvoid LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);\r\n  #endif\r\n  MatchFinder_Free(&p->matchFinderBase, allocBig);\r\n  LzmaEnc_FreeLits(p, alloc);\r\n  RangeEnc_Free(&p->rc, alloc);\r\n}\r\n\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);\r\n  alloc->Free(alloc, p);\r\n}\r\n\r\nstatic SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)\r\n{\r\n  UInt32 nowPos32, startPos32;\r\n  if (p->inStream != 0)\r\n  {\r\n    p->matchFinderBase.stream = p->inStream;\r\n    p->matchFinder.Init(p->matchFinderObj);\r\n    p->inStream = 0;\r\n  }\r\n\r\n  if (p->finished)\r\n    return p->result;\r\n  RINOK(CheckErrors(p));\r\n\r\n  nowPos32 = (UInt32)p->nowPos64;\r\n  startPos32 = nowPos32;\r\n\r\n  if (p->nowPos64 == 0)\r\n  {\r\n    UInt32 numPairs;\r\n    Byte curByte;\r\n    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n      return Flush(p, nowPos32);\r\n    ReadMatchDistances(p, &numPairs);\r\n    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);\r\n    p->state = kLiteralNextStates[p->state];\r\n    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);\r\n    LitEnc_Encode(&p->rc, p->litProbs, curByte);\r\n    p->additionalOffset--;\r\n    nowPos32++;\r\n  }\r\n\r\n  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)\r\n  for (;;)\r\n  {\r\n    UInt32 pos, len, posState;\r\n\r\n    if (p->fastMode)\r\n      len = GetOptimumFast(p, &pos);\r\n    else\r\n      len = GetOptimum(p, nowPos32, &pos);\r\n\r\n    #ifdef SHOW_STAT2\r\n    printf(\"\\n pos = %4X,   len = %d   pos = %d\", nowPos32, len, pos);\r\n    #endif\r\n\r\n    posState = nowPos32 & p->pbMask;\r\n    if (len == 1 && pos == (UInt32)-1)\r\n    {\r\n      Byte curByte;\r\n      CLzmaProb *probs;\r\n      const Byte *data;\r\n\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);\r\n      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n      curByte = *data;\r\n      probs = LIT_PROBS(nowPos32, *(data - 1));\r\n      if (IsCharState(p->state))\r\n        LitEnc_Encode(&p->rc, probs, curByte);\r\n      else\r\n        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));\r\n      p->state = kLiteralNextStates[p->state];\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);\r\n        if (pos == 0)\r\n        {\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = p->reps[pos];\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);\r\n          if (pos == 1)\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);\r\n          else\r\n          {\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);\r\n            if (pos == 3)\r\n              p->reps[3] = p->reps[2];\r\n            p->reps[2] = p->reps[1];\r\n          }\r\n          p->reps[1] = p->reps[0];\r\n          p->reps[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          p->state = kShortRepNextStates[p->state];\r\n        else\r\n        {\r\n          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n          p->state = kRepNextStates[p->state];\r\n        }\r\n      }\r\n      else\r\n      {\r\n        UInt32 posSlot;\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n        p->state = kMatchNextStates[p->state];\r\n        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n        pos -= LZMA_NUM_REPS;\r\n        GetPosSlot(pos, posSlot);\r\n        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);\r\n          else\r\n          {\r\n            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);\r\n            p->alignPriceCount++;\r\n          }\r\n        }\r\n        p->reps[3] = p->reps[2];\r\n        p->reps[2] = p->reps[1];\r\n        p->reps[1] = p->reps[0];\r\n        p->reps[0] = pos;\r\n        p->matchPriceCount++;\r\n      }\r\n    }\r\n    p->additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (p->additionalOffset == 0)\r\n    {\r\n      UInt32 processed;\r\n      if (!p->fastMode)\r\n      {\r\n        if (p->matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices(p);\r\n        if (p->alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices(p);\r\n      }\r\n      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n        break;\r\n      processed = nowPos32 - startPos32;\r\n      if (useLimits)\r\n      {\r\n        if (processed + kNumOpts + 300 >= maxUnpackSize ||\r\n            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)\r\n          break;\r\n      }\r\n      else if (processed >= (1 << 15))\r\n      {\r\n        p->nowPos64 += nowPos32 - startPos32;\r\n        return CheckErrors(p);\r\n      }\r\n    }\r\n  }\r\n  p->nowPos64 += nowPos32 - startPos32;\r\n  return Flush(p, nowPos32);\r\n}\r\n\r\n#define kBigHashDicLimit ((UInt32)1 << 24)\r\n\r\nstatic SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 beforeSize = kNumOpts;\r\n  Bool btMode;\r\n  if (!RangeEnc_Alloc(&p->rc, alloc))\r\n    return SZ_ERROR_MEM;\r\n  btMode = (p->matchFinderBase.btMode != 0);\r\n  #ifdef COMPRESS_MF_MT\r\n  p->mtMode = (p->multiThread && !p->fastMode && btMode);\r\n  #endif\r\n\r\n  {\r\n    unsigned lclp = p->lc + p->lp;\r\n    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)\r\n    {\r\n      LzmaEnc_FreeLits(p, alloc);\r\n      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      if (p->litProbs == 0 || p->saveState.litProbs == 0)\r\n      {\r\n        LzmaEnc_FreeLits(p, alloc);\r\n        return SZ_ERROR_MEM;\r\n      }\r\n      p->lclp = lclp;\r\n    }\r\n  }\r\n\r\n  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);\r\n\r\n  if (beforeSize + p->dictSize < keepWindowSize)\r\n    beforeSize = keepWindowSize - p->dictSize;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (p->mtMode)\r\n  {\r\n    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));\r\n    p->matchFinderObj = &p->matchFinderMt;\r\n    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))\r\n      return SZ_ERROR_MEM;\r\n    p->matchFinderObj = &p->matchFinderBase;\r\n    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nvoid LzmaEnc_Init(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  p->state = 0;\r\n  for (i = 0 ; i < LZMA_NUM_REPS; i++)\r\n    p->reps[i] = 0;\r\n\r\n  RangeEnc_Init(&p->rc);\r\n\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    UInt32 j;\r\n    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)\r\n    {\r\n      p->isMatch[i][j] = kProbInitValue;\r\n      p->isRep0Long[i][j] = kProbInitValue;\r\n    }\r\n    p->isRep[i] = kProbInitValue;\r\n    p->isRepG0[i] = kProbInitValue;\r\n    p->isRepG1[i] = kProbInitValue;\r\n    p->isRepG2[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    UInt32 num = 0x300 << (p->lp + p->lc);\r\n    for (i = 0; i < num; i++)\r\n      p->litProbs[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    for (i = 0; i < kNumLenToPosStates; i++)\r\n    {\r\n      CLzmaProb *probs = p->posSlotEncoder[i];\r\n      UInt32 j;\r\n      for (j = 0; j < (1 << kNumPosSlotBits); j++)\r\n        probs[j] = kProbInitValue;\r\n    }\r\n  }\r\n  {\r\n    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      p->posEncoders[i] = kProbInitValue;\r\n  }\r\n\r\n  LenEnc_Init(&p->lenEnc.p);\r\n  LenEnc_Init(&p->repLenEnc.p);\r\n\r\n  for (i = 0; i < (1 << kNumAlignBits); i++)\r\n    p->posAlignEncoder[i] = kProbInitValue;\r\n\r\n  p->optimumEndIndex = 0;\r\n  p->optimumCurrentIndex = 0;\r\n  p->additionalOffset = 0;\r\n\r\n  p->pbMask = (1 << p->pb) - 1;\r\n  p->lpMask = (1 << p->lp) - 1;\r\n}\r\n\r\nvoid LzmaEnc_InitPrices(CLzmaEnc *p)\r\n{\r\n  if (!p->fastMode)\r\n  {\r\n    FillDistancesPrices(p);\r\n    FillAlignPrices(p);\r\n  }\r\n\r\n  p->lenEnc.tableSize =\r\n  p->repLenEnc.tableSize =\r\n      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;\r\n  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);\r\n  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);\r\n}\r\n\r\nstatic SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)\r\n    if (p->dictSize <= ((UInt32)1 << i))\r\n      break;\r\n  p->distTableSize = i * 2;\r\n\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));\r\n  LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  p->nowPos64 = 0;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  p->rc.outStream = outStream;\r\n  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);\r\n}\r\n\r\nSRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,\r\n    ISeqInStream *inStream, UInt32 keepWindowSize,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nstatic void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)\r\n{\r\n  p->seqBufInStream.funcTable.Read = MyRead;\r\n  p->seqBufInStream.data = src;\r\n  p->seqBufInStream.rem = srcLen;\r\n}\r\n\r\nSRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\r\n    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n  p->inStream = &p->seqBufInStream.funcTable;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nvoid LzmaEnc_Finish(CLzmaEncHandle pp)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  if (p->mtMode)\r\n    MatchFinderMt_ReleaseStream(&p->matchFinderMt);\r\n  #else\r\n  pp = pp;\r\n  #endif\r\n}\r\n\r\ntypedef struct _CSeqOutStreamBuf\r\n{\r\n  ISeqOutStream funcTable;\r\n  Byte *data;\r\n  SizeT rem;\r\n  Bool overflow;\r\n} CSeqOutStreamBuf;\r\n\r\nstatic size_t MyWrite(void *pp, const void *data, size_t size)\r\n{\r\n  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;\r\n  if (p->rem < size)\r\n  {\r\n    size = p->rem;\r\n    p->overflow = True;\r\n  }\r\n  memcpy(p->data, data, size);\r\n  p->rem -= size;\r\n  p->data += size;\r\n  return size;\r\n}\r\n\r\n\r\nUInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n}\r\n\r\nconst Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n}\r\n\r\nSRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\r\n    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  UInt64 nowPos64;\r\n  SRes res;\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = False;\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n\r\n  if (reInit)\r\n    LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  nowPos64 = p->nowPos64;\r\n  RangeEnc_Init(&p->rc);\r\n  p->rc.outStream = &outStream.funcTable;\r\n\r\n  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);\r\n  \r\n  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  SRes res = SZ_OK;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte allocaDummy[0x300];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  #endif\r\n\r\n  RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));\r\n\r\n  for (;;)\r\n  {\r\n    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);\r\n    if (res != SZ_OK || p->finished != 0)\r\n      break;\r\n    if (progress != 0)\r\n    {\r\n      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));\r\n      if (res != SZ_OK)\r\n      {\r\n        res = SZ_ERROR_PROGRESS;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  LzmaEnc_Finish(pp);\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  int i;\r\n  UInt32 dictSize = p->dictSize;\r\n  if (*size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_PARAM;\r\n  *size = LZMA_PROPS_SIZE;\r\n  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);\r\n\r\n  for (i = 11; i <= 30; i++)\r\n  {\r\n    if (dictSize <= ((UInt32)2 << i))\r\n    {\r\n      dictSize = (2 << i);\r\n      break;\r\n    }\r\n    if (dictSize <= ((UInt32)3 << i))\r\n    {\r\n      dictSize = (3 << i);\r\n      break;\r\n    }\r\n  }\r\n\r\n  for (i = 0; i < 4; i++)\r\n    props[1 + i] = (Byte)(dictSize >> (8 * i));\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  SRes res;\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = writeEndMark;\r\n  res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,\r\n      progress, alloc, allocBig);\r\n\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n  return res;\r\n}\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);\r\n  SRes res;\r\n  if (p == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LzmaEnc_SetProps(p, props);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);\r\n    if (res == SZ_OK)\r\n      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,\r\n          writeEndMark, progress, alloc, allocBig);\r\n  }\r\n\r\n  LzmaEnc_Destroy(p, alloc, allocBig);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/lzma_src/C/LzmaEnc.h",
    "content": "/*  LzmaEnc.h -- LZMA Encoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMAENC_H\r\n#define __LZMAENC_H\r\n\r\n#include \"Types.h\"\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaEncProps\r\n{\r\n  int level;       /*  0 <= level <= 9 */\r\n  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version\r\n                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version\r\n                       default = (1 << 24) */\r\n  int lc;          /* 0 <= lc <= 8, default = 3 */\r\n  int lp;          /* 0 <= lp <= 4, default = 0 */\r\n  int pb;          /* 0 <= pb <= 4, default = 2 */\r\n  int algo;        /* 0 - fast, 1 - normal, default = 1 */\r\n  int fb;          /* 5 <= fb <= 273, default = 32 */\r\n  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */\r\n  int numHashBytes; /* 2, 3 or 4, default = 4 */\r\n  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */\r\n  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */\r\n  int numThreads;  /* 1 or 2, default = 2 */\r\n} CLzmaEncProps;\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p);\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p);\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);\r\n\r\n\r\n/* ---------- CLzmaEncHandle Interface ---------- */\r\n\r\n/* LzmaEnc_* functions can return the following exit codes:\r\nReturns:\r\n  SZ_OK           - OK\r\n  SZ_ERROR_MEM    - Memory allocation error\r\n  SZ_ERROR_PARAM  - Incorrect paramater in props\r\n  SZ_ERROR_WRITE  - Write callback error.\r\n  SZ_ERROR_PROGRESS - some break from progress callback\r\n  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\ntypedef void * CLzmaEncHandle;\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);\r\nSRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaEncode\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/lzma_src/C/Types.h",
    "content": "/* Types.h -- Basic types\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_TYPES_H\r\n#define __7Z_TYPES_H\r\n\r\n#ifndef BCMLZMA\r\n#include <stddef.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#define SZ_OK 0\r\n\r\n#define SZ_ERROR_DATA 1\r\n#define SZ_ERROR_MEM 2\r\n#define SZ_ERROR_CRC 3\r\n#define SZ_ERROR_UNSUPPORTED 4\r\n#define SZ_ERROR_PARAM 5\r\n#define SZ_ERROR_INPUT_EOF 6\r\n#define SZ_ERROR_OUTPUT_EOF 7\r\n#define SZ_ERROR_READ 8\r\n#define SZ_ERROR_WRITE 9\r\n#define SZ_ERROR_PROGRESS 10\r\n#define SZ_ERROR_FAIL 11\r\n#define SZ_ERROR_THREAD 12\r\n\r\n#define SZ_ERROR_ARCHIVE 16\r\n#define SZ_ERROR_NO_ARCHIVE 17\r\n\r\ntypedef int SRes;\r\n\r\n#ifdef _WIN32\r\ntypedef DWORD WRes;\r\n#else\r\ntypedef int WRes;\r\n#endif\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r\n#endif\r\n\r\n#ifndef Byte\r\ntypedef unsigned char Byte;\r\n#endif\r\ntypedef short Int16;\r\ntypedef unsigned short UInt16;\r\n\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef long Int32;\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef int Int32;\r\ntypedef unsigned int UInt32;\r\n#endif\r\n\r\n#ifdef _SZ_NO_INT_64\r\n\r\n/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r\n   NOTES: Some code will work incorrectly in that case! */\r\n\r\ntypedef long Int64;\r\ntypedef unsigned long UInt64;\r\n\r\n#else\r\n\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef __int64 Int64;\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef long long int Int64;\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\ntypedef size_t SizeT;\r\n#endif\r\n\r\ntypedef int Bool;\r\n#define True 1\r\n#define False 0\r\n\r\n\r\n#ifdef _MSC_VER\r\n\r\n#if _MSC_VER >= 1300\r\n#define MY_NO_INLINE __declspec(noinline)\r\n#else\r\n#define MY_NO_INLINE\r\n#endif\r\n\r\n#define MY_CDECL __cdecl\r\n#define MY_STD_CALL __stdcall\r\n#define MY_FAST_CALL MY_NO_INLINE __fastcall\r\n\r\n#else\r\n\r\n#define MY_CDECL\r\n#define MY_STD_CALL\r\n#define MY_FAST_CALL\r\n\r\n#endif\r\n\r\n\r\n/* The following interfaces use first parameter as pointer to structure */\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) < input(*size)) is allowed */\r\n} ISeqInStream;\r\n\r\n/* it can return SZ_ERROR_INPUT_EOF */\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r\n\r\ntypedef struct\r\n{\r\n  size_t (*Write)(void *p, const void *buf, size_t size);\r\n    /* Returns: result - the number of actually written bytes.\r\n       (result < size) means error */\r\n} ISeqOutStream;\r\n\r\ntypedef enum\r\n{\r\n  SZ_SEEK_SET = 0,\r\n  SZ_SEEK_CUR = 1,\r\n  SZ_SEEK_END = 2\r\n} ESzSeek;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ISeekInStream;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Look)(void *p, void **buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) > input(*size)) is not allowed\r\n       (output(*size) < input(*size)) is allowed */\r\n  SRes (*Skip)(void *p, size_t offset);\r\n    /* offset must be <= output(*size) of Look */\r\n\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ILookInStream;\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r\n\r\n/* reads via ILookInStream::Read */\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r\n\r\n#define LookToRead_BUF_SIZE (1 << 14)\r\n\r\ntypedef struct\r\n{\r\n  ILookInStream s;\r\n  ISeekInStream *realStream;\r\n  size_t pos;\r\n  size_t size;\r\n  Byte buf[LookToRead_BUF_SIZE];\r\n} CLookToRead;\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r\nvoid LookToRead_Init(CLookToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToLook;\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToRead;\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r\n    /* Returns: result. (result != SZ_OK) means break.\r\n       Value (UInt64)(Int64)-1 for size means unknown value. */\r\n} ICompressProgress;\r\n\r\ntypedef struct\r\n{\r\n  void *(*Alloc)(void *p, size_t size);\r\n  void (*Free)(void *p, void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\n#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r\n#define IAlloc_Free(p, a) (p)->Free((p), a)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"LzmaEnc.h\"\n#include \"Alloc.h\"\n#include \"sqlzma.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\nint lzma = 1;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nstruct squashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* data allocator status struct.  Allocators are used to keep\n  track of memory buffers passed between different threads */\nstruct allocator {\n\tint\t\tmax_buffers;\n\tint\t\tcount;\n\tint\t\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t\twait;\n};\n\n/* struct describing a memory buffer passed between threads */\nstruct file_buffer {\n\tstruct allocator\t*allocator;\n\tvoid\t\t\t(*release)(int);\n\tint\t\t\trelease_data;\n\tlong long\t\tblock;\n\tint\t\t\tsize;\n\tint\t\t\tc_byte;\n\tunsigned int\t\tblock_order;\n\tint\t\t\tfragment;\n\tint\t\t\terror;\n\tstruct file_buffer\t*next;\n\tchar\t\t\tdata[0];\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n/* describes the list of blocks in a file which is a possible\n   duplicate.  For each block, it indicates whether the block is\n   in memory or on disk */\nstruct buffer_list {\n\tlong long start;\n\tint size;\n\tstruct file_buffer *read_buffer;\n};\n\nstruct allocator *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\nextern struct priority_entry *priority_list[65536];\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\n\n\nstruct allocator *alloc_init(int buffer_size, int max_buffers)\n{\n\tstruct allocator *allocator = malloc(sizeof(struct allocator));\n\n\tif(allocator == NULL)\n\t\treturn NULL;\n\n\tallocator->max_buffers = max_buffers;\n\tallocator->buffer_size = buffer_size;\n\tallocator->count = 0;\n\tpthread_mutex_init(&allocator->mutex, NULL);\n\tpthread_cond_init(&allocator->wait, NULL);\n\n\treturn allocator;\n}\n\n\nstruct file_buffer *alloc_get(struct allocator *allocator)\n{\n\tstruct file_buffer *file_buffer;\n\t\n\tpthread_mutex_lock(&allocator->mutex);\n\n\twhile(allocator->count == allocator->max_buffers)\n\t\tpthread_cond_wait(&allocator->wait, &allocator->mutex);\n\n\tif((file_buffer = malloc(sizeof(struct file_buffer) + allocator->buffer_size)) == NULL)\n\t\tgoto failed;\n\n\tfile_buffer->release = NULL;\n\tfile_buffer->allocator = allocator;\n\tallocator->count ++;\n\nfailed:\n\tpthread_mutex_unlock(&allocator->mutex);\n\treturn file_buffer;\n}\n\n\nstruct file_buffer *alloc_get_2(struct allocator *allocator, void (*release)(int), int release_data)\n{\n\tstruct file_buffer *file_buffer = alloc_get(allocator);\n\n\tif(file_buffer) {\n\t\tfile_buffer->release = release;\n\t\tfile_buffer->release_data = release_data;\n\t}\n\treturn file_buffer;\n}\n\n\nvoid alloc_free(struct file_buffer *file_buffer)\n{\n\tstruct allocator *allocator;\n\n\tif(file_buffer == NULL)\n\t\treturn;\n\n\tallocator = file_buffer->allocator;\n\n\tif(file_buffer->release)\n\t\tfile_buffer->release(file_buffer->release_data);\n\n\tpthread_mutex_lock(&allocator->mutex);\n\tfree(file_buffer);\n\tif(allocator->count == 0)\n\t\tERROR(\"alloc_free: freeing buffer for empty allocator!\\n\");\n\telse\n\t\tallocator->count --;\n\tpthread_cond_signal(&allocator->wait);\n\tpthread_mutex_unlock(&allocator->mutex);\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\t\n\tif (!lzma) {\n\t\tif(stream == NULL) {\n\t\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\n\t\n\t\t\tstream->zalloc = Z_NULL;\n\t\t\tstream->zfree = Z_NULL;\n\t\t\tstream->opaque = 0;\n\t\n\t\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\n\t\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\n\t\t\t\telse\n\t\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t\t}\n\t\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\t\tif(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\n\t\tstream->next_in = (unsigned char *) s;\n\t\tstream->avail_in = size;\n\t\tstream->next_out = (unsigned char *) d;\n\t\tstream->avail_out = block_size;\n\t\t\n\t\tres = deflate(stream, Z_FINISH);\n\t\tif(res != Z_STREAM_END && res != Z_OK) {\n\t\t\tif(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\t\tc_byte = stream->total_out;\n\t\t\n\t\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\t\tmemcpy(d, s, size);\n\t\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t\t}\t\n\t}\n\t /* broadcom start */\n\telse {\n\t\tres = LzmaCompress(s, size, d, block_size, &c_byte);\n\t    if (res) {\n\t\t\tmemcpy(d, s, size);\n\t\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t\t}\n\t} \n\t/* broadcom end */\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\treturn FALSE;\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nint write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir) {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir) == FALSE)\n\t\t\treturn FALSE;\n\t} else {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL) == FALSE)\n\t\t\treturn FALSE;\n\t}\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn TRUE;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment, int *cached_fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\n\tif(fragment->index == *cached_fragment || fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn buffer + fragment->offset;\n\n\tif(fragment_data && fragment->index == fragments)\n\t\treturn fragment_data->data + fragment->offset;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragment_table[fragment->index].pending)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\t\tif (!lzma) {\n\t\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\t\telse\n\t\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t}\n\t\t}\n\t\t/* LZMA */\n\t\telse {\n\t\t\tif((res = LzmaUncompress(buffer, &bytes, cbuffer, size)) != SZ_OK)\n\t\t\t\tBAD_ERROR(\"LzmaUncompress: error (%d)\\n\", res);\n\t\t}\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\t*cached_fragment = fragment->index;\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid ensure_fragments_flushed()\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragments_outstanding)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].pending = TRUE;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\nvoid frag_release(int block)\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragment_table[block].pending = FALSE;\n\tpthread_cond_signal(&fragment_waiting);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = alloc_get(fragment_buffer);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint avail_bytes, compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tlong long slist[meta_blocks];\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_buffer(struct buffer_list *buffer_list, unsigned int blocks)\n{\n\tunsigned short chksum = 0;\n\tint block;\n\n\tfor(block = 0; block < blocks; block ++) {\n\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\tif(b->read_buffer)\n\t\t\tchksum = get_checksum(b->read_buffer->data, b->read_buffer->size, chksum);\n\t\telse\n\t\t\tchksum = get_checksum(read_from_disk(b->start, b->size), b->size, chksum);\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\nint cached_frag = -1;\nchar fragdata[SQUASHFS_FILE_MAX_SIZE];\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tchar *datap;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\nchar cached_fragment[SQUASHFS_FILE_SIZE];\nint cached_frag1 = -1;\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), file_size);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tchar buffer2[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tchar *buffer;\n\t\t\tint block;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_buffer(buffer_list, blocks);\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), frag_bytes);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\t\t\tif(b->read_buffer)\n\t\t\t\t\tbuffer = b->read_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tbuffer = read_from_disk(b->start, b->size);\n\n\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\n\t\t\t\tif(memcmp(buffer, buffer2, b->size) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_start += b->size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tchar *fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1);\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tint count;\n\tint blocks = (buf->st_size + block_size - 1) >> block_log;\n\tint frag_block = !no_fragments && (always_use_fragments ||\n\t\t(buf->st_size < block_size)) ? buf->st_size >> block_log : -1;\n\tint file;\n\tstatic int block_order = 0;\n\tstruct file_buffer *file_buffer;\n\n\tif(buf->st_size == 0 || dir_ent->inode->read)\n\t\treturn;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tfor(count = 0; count < blocks; count ++) {\n\t\tfile_buffer = alloc_get(reader_buffer);\n\n\t\tif((file_buffer->size = read(file, file_buffer->data, block_size)) == -1) {\n\t\t\tclose(file);\n\t\t\tgoto read_err2;\n\t\t}\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->block_order = block_order ++;\n\t\tfile_buffer->error = FALSE;\n\t\tif((file_buffer->fragment = (count == frag_block)))\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\telse\n\t\t\tqueue_put(from_reader, file_buffer);\n\t}\n\n\tclose(file);\n\tdir_ent->inode->read = TRUE;\n\n\treturn;\n\nread_err:\n\tfile_buffer = alloc_get(reader_buffer);\nread_err2:\n\tfile_buffer->block_order = block_order ++;\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\treturn NULL;\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tperror(\"Lseek on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n\t\t\tperror(\"Write on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer = alloc_get(writer_buffer);\n\n\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\n\t\twrite_buffer->block = file_buffer->block;\n\t\twrite_buffer->block_order = file_buffer->block_order;\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\n\t\twrite_buffer->fragment = FALSE;\n\t\twrite_buffer->error = FALSE;\n\t\talloc_free(file_buffer);\n\t\tqueue_put(from_deflate, write_buffer);\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer = alloc_get_2(writer_buffer, frag_release, file_buffer->block);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\twrite_buffer->size = compressed_size;\n\t\twrite_buffer->block = bytes;\n\t\tqueue_put(to_writer, write_buffer);\n\t\tbytes += compressed_size;\n\t\ttotal_uncompressed += file_buffer->size;\n\t\ttotal_compressed += compressed_size;\n\t\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\n\t\tfragments_outstanding --;\n\t\tpthread_cond_signal(&fragment_waiting);\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->block_order);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int block_order = 0;\n\tint hash = BLOCK_HASH(block_order);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->block_order == block_order)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->block_order == block_order)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tblock_order ++;\n\n\treturn file_buffer;\n}\n\n\nint progress_bar(long long current, long long max, int columns)\n{\n\tint max_digits = ceil(log10(max));\n\tint used = max_digits * 2 + 10;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(!progress || columns - used < 0)\n\t\treturn 0;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n\treturn 0;\n}\n\n\nint write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n}\n\n\nint write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\n{\n\tint file;\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\talloc_free(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\tstruct file_buffer *file_buffer = get_file_buffer(from_deflate);\n\n\tif(file_buffer->error) {\n\t\talloc_free(file_buffer);\n\t\treturn FALSE;\n\t}\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum))\n\t\treturn write_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\talloc_free(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\treturn dir_ent->inode->nlink == 1 ?\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL) :\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size)\n{\n\tint block, status;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list;\n\tstruct file_buffer *read_buffer;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\t\tqueue_put(to_writer, read_buffer);\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t} else\n\t\tread_buffer = NULL;\n\n\tfragment = get_and_fill_fragment(read_buffer);\n\talloc_free(read_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, int *duplicate_file)\n{\n\tint block, status, thresh;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer *read_buffer;\n\tstruct file_data *file_data;\n\tstruct buffer_list *buffer_list;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tthresh = blocks > (writer_buffer_size - processors) ? blocks - (writer_buffer_size - processors): 0;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tread_buffer->block = bytes;\n\t\tbytes += read_buffer->size;\n\t\tfile_bytes += read_buffer->size;\n\n\t\tif(block < thresh) {\n\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\tqueue_put(to_writer, read_buffer);\n\t\t} else\n\t\t\tbuffer_list[block].read_buffer = read_buffer;\n\t\tbuffer_list[block].start = read_buffer->block;\n\t\tbuffer_list[block].size = read_buffer->size;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t} else\n\t\tread_buffer = NULL;\n\n\tqueue_put(to_writer, NULL);\n\tif(queue_get(from_writer) != 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\n\t\tfragment = get_and_fill_fragment(read_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\talloc_free(buffer_list[block].read_buffer);\n\t\tbytes = buffer_list[0].start;\n\t\tif(thresh && !block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\n\talloc_free(read_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tif(block && thresh) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\talloc_free(buffer_list[blocks].read_buffer);\n\tfree(buffer_list);\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn FALSE;\n}\n\n\nint write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)\n{\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %lld bytes\\n\", dir_ent->pathname, SQUASHFS_MAX_FILE_SIZE);\n\n\tif(read_size == 0)\n\t\treturn write_file_empty(inode, dir_ent, duplicate_file);\n\n\tif(!no_fragments && (read_size < block_size))\n\t\treturn write_file_frag(inode, dir_ent, read_size, duplicate_file);\n\n\tif(pre_duplicate(read_size))\n\t\treturn write_file_blocks_dup(inode, dir_ent, read_size, duplicate_file);\n\n\t*duplicate_file = FALSE;\n\treturn write_file_blocks(inode, dir_ent, read_size);\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFREG)\n\t\t\testimated_uncompressed += (buf.st_size + block_size - 1) >> block_log;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\n\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type = -1;\n\tint result = FALSE;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\tresult = write_file(inode, dir_ent, buf->st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tresult = dir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n\t\t\t\t}\n\t\t\tif(result)\n\t\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult = TRUE;\n\t\t}\n\t\t\n\n\t\tif(result)\n\t\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\tresult = write_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n\n\treturn result;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 16; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(processors * 2);\n\treader_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, reader_buffer_size);\n\twriter_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, writer_buffer_size);\n\tfragment_buffer = alloc_init(SQUASHFS_FILE_MAX_SIZE, processors * 2);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\n\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\n}\n\n\t\t\t\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.2-r2 (2007/01/15)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct winsize winsize;\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n\t\t\tlzma = 0;\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t} else  {\n\t\tsignal(SIGTERM, sighandler2);\n\t\tsignal(SIGINT, sighandler2);\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tinitialise_threads();\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem using %s on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, lzma ? \"LZMA\" : \"GZIP\", argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t\t\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + (inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1));\n\t\tuncompressed_data = inode_dir_offset + (inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1));\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(progress) {\n\t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\t\tcolumns = 80;\n\t\t} else\n\t\t\tcolumns = winsize.ws_col;\n\t\tsignal(SIGWINCH, sigwinch_handler);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tif (lzma)\n\t\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n\telse\n\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tensure_fragments_flushed();\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\tclose(fd);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"LzmaDec.h\"\n#include \"sqlzma.h\"\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\nextern int lzma;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tif(!lzma) {\n\t\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\t\telse\n\t\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\t/* lzma */\n\t\telse {\n\t\t\tif((res = LzmaUncompress(block, &bytes, buffer, c_byte)) != SZ_OK)\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tsquashfs_super_block sblk;\n\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk->s_magic) {\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tif (!lzma)\n\t\t\tgoto bad;\n\t\tbreak;\n\tcase SQUASHFS_MAGIC:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\n\tbad:\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3.0 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is %d.%d, I support 3.0\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %xllx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block = -1;\n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tlong long sindex[indexes];\n\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_inode_t sinode;\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\n\t\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include \"squashfs_fs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern squashfs_inode write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\tif(write_file(&inode, entry->dir, entry->dir->inode->buf.st_size,\n\t\t\t\t\t\t\t&duplicate_file)) {\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/sqlzma.c",
    "content": "/*\n * squashfs with lzma compression\n *\n * Copyright (C) 2008, Broadcom Corporation\n * All Rights Reserved.\n * \n * THIS SOFTWARE IS OFFERED \"AS IS\", AND BROADCOM GRANTS NO WARRANTIES OF ANY\n * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM\n * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.\n *\n * $Id: sqlzma.c,v 1.3 2009/03/10 08:42:14 Exp $\n */\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include \"LzmaDec.h\"\n#include \"LzmaEnc.h\"\n#include \"sqlzma.h\"\n\nstatic void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\nstatic void SzFree(void *p, void *address) { p = p; free(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\nint LzmaUncompress(char *dst, unsigned long * dstlen, char *src, int srclen)\n{\n\tint res;\n\tSizeT inSizePure;\n\tELzmaStatus status;\n\n\tif (srclen < LZMA_PROPS_SIZE)\n\t{\n\t\tmemcpy(dst, src, srclen);\n\t\treturn srclen;\n\t}\n\tinSizePure = srclen - LZMA_PROPS_SIZE;\n\tres = LzmaDecode(dst, dstlen, src + LZMA_PROPS_SIZE, &inSizePure,\n\t                 src, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);\n\tsrclen = inSizePure ;\n\n\tif ((res == SZ_OK) ||\n\t\t((res == SZ_ERROR_INPUT_EOF) && (srclen == inSizePure)))\n\t\tres = 0;\n\tif (res != SZ_OK)\n\t\tprintf(\"LzmaUncompress: error (%d)\\n\", res);\n\treturn res;\n}\n\n\nint LzmaCompress(char *in_data, int in_size, char *out_data, int out_size, unsigned long *total_out)\n{\n\tCLzmaEncProps props;\n\tsize_t headerSize = LZMA_PROPS_SIZE;\n\tint ret;\n\tSizeT outProcess;\n\n\tLzmaEncProps_Init(&props);\n\tprops.algo = 1;\n\toutProcess = out_size - LZMA_PROPS_SIZE;\n\tret = LzmaEncode(out_data+LZMA_PROPS_SIZE, &outProcess, in_data, in_size, &props, out_data, \n\t\t\t\t\t\t&headerSize, 0, NULL, &g_Alloc, &g_Alloc);\n\t*total_out = outProcess + LZMA_PROPS_SIZE;\n\treturn ret;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/sqlzma.h",
    "content": "/*\n * squashfs with lzma compression\n *\n * Copyright (C) 2008, Broadcom Corporation\n * All Rights Reserved.\n * \n * THIS SOFTWARE IS OFFERED \"AS IS\", AND BROADCOM GRANTS NO WARRANTIES OF ANY\n * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM\n * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.\n *\n * $Id: sqlzma.h,v 1.3 2009/03/10 08:42:14 Exp $\n */\n#ifndef __sqlzma_h__\n#define __sqlzma_h__\n\n#ifndef __KERNEL__\n#include <stdlib.h>\n#include <string.h>\n#endif\n\n/*\n * detect the compression method automatically by the first byte of compressed\n * data.\n */\n#define is_lzma(c)\t(c == 0x5d)\n\nint LzmaUncompress(char *dst, unsigned long * dstlen, char *src, int srclen);\nint LzmaCompress(char *in_data, int in_size, char *out_data, int out_size, unsigned long *total_out);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#ifdef CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\n#define SQUASHFS_CACHED_FRAGMENTS       CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\n#else\n#define SQUASHFS_CACHED_FRAGMENTS       3\n#endif\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.2-r2-wnr1000/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n *  Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"LzmaDec.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir\t*(*squashfs_opendir)(unsigned int block_start, unsigned int offset);\n\tchar \t\t*(*read_fragment)(unsigned int fragment);\n\tvoid\t\t(*read_fragment_table)();\n\tint\t\t(*create_inode)(char *pathname, unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE, force = FALSE;\nchar **created_inode;\nint root_process;\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\t\tif (!is_lzma(buffer[0])) {\n\t\t\tif((res = uncompress((unsigned char *) block, &bytes,\n\t\t\t(const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\t\telse\n\t\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif((res = LzmaUncompress(block, &bytes, buffer, c_byte)) != SZ_OK)\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\n\t\t}\n\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tif (!is_lzma(data[0])) {\n\t\t\tif((res = uncompress((unsigned char *) block, &bytes,\n\t\t\t(const unsigned char *) data, c_byte)) != Z_OK) {\n\t\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\t\telse\n\t\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\t/* LZMA */\n\t\telse {\n\t\t\tif((res = LzmaUncompress(block, &bytes, data, c_byte)) != SZ_OK)\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\n\t\t}\n\t\t\t\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, unsigned int mode, unsigned int uid,\nunsigned int guid, unsigned int mtime, unsigned int set_mode)\n{\n\tstruct utimbuf times = { (time_t) mtime, (time_t) mtime };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tuid_t uid_value = (uid_t) uid_table[uid];\n\t\tuid_t guid_value = guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[guid];\n\n\t\tif(chown(pathname, uid_value, guid_value) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nchar *read_fragment_2(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint write_file(char *pathname, unsigned int fragment, unsigned int frag_bytes,\nunsigned int offset, unsigned int blocks, long long start, char *block_ptr,\nunsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write(file_fd, file_data, bytes) < bytes) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = s_ops.read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write(file_fd, fragment_data + offset, frag_bytes) < frag_bytes) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\t\t\n\nint create_inode(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tif(created_inode[header.base.inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[header.base.inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\theader.base.mtime, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[header.base.inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nint create_inode_2(char *pathname, unsigned int start_block, unsigned int offset)\n{\n\tlong long start = sBlk.inode_table_start + start_block;\n\tsquashfs_inode_header_2 header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes,\n\t\t\t\t\toffset, blocks, start, block_ptr +\n\t\t\t\t\tsizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid ==\n\t\t\t\t\tSQUASHFS_GUIDS ? uid_value : (uid_t)\n\t\t\t\t\tguid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, inodep->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK, makedev((inodep->rdev >> 8)\n\t\t\t\t\t& 0xff, inodep->rdev & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, sBlk.mkfs_time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\tsBlk.mkfs_time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start = sBlk.inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header_2 header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nint matches(char *targname, char *name)\n{\n\tif(*targname == '\\0' || strcmp(targname, name) == 0)\n\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, char *target)\n{\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tchar targname[1024];\n\n\ttarget = get_component(target, targname);\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(targname, name))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(lsonly || info)\n\t\t\tprintf(\"%s\\n\", pathname);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, target);\n\t\telse\n\t\t\tif(!lsonly)\n\t\t\t\ts_ops.create_inode(pathname, start_block, offset);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nint read_super(char *source)\n{\n\tsquashfs_super_block sblk;\n\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk.s_magic) {\n\tcase SQUASHFS_MAGIC:\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\n\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\ts_ops.read_fragment = read_fragment_2;\n\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\ts_ops.create_inode = create_inode_2;\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor == 0) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.create_inode = create_inode;\n\t} else {\n\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d)\\n\",\n\t\t\t\tsource, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"I support Squashfs 2.x and 3.0 filesystems!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tTRACE(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\n\tTRACE(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tTRACE(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not\" : \"\");\n\tTRACE(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tTRACE(\"\\tBlock size %d\\n\", sBlk.block_size);\n\tTRACE(\"\\tNumber of fragments %d\\n\", sBlk.fragments);\n\tTRACE(\"\\tNumber of inodes %d\\n\", sBlk.inodes);\n\tTRACE(\"\\tNumber of uids %d\\n\", sBlk.no_uids);\n\tTRACE(\"\\tNumber of gids %d\\n\", sBlk.no_guids);\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.3 (2007/01/02)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, version = FALSE;\n\tchar *target = \"\";\n\n\tif((root_process = (geteuid() == 0)))\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc)\n\t\t\t\tgoto options;\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directory or file to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem only\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tif((i + 1) < argc)\n\t\ttarget = argv[i + 1];\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tblock_size = sBlk.block_size;\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids();\n\ts_ops.read_fragment_table();\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), target);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3/Makefile",
    "content": "CC := gcc\nCXX := g++\nINCLUDEDIR = .\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\nLZMAPATH = ../../lzma/C/7zip/Compress/LZMA_Lib\n\nall: mksquashfs unsquashfs # mksquashfs-lzma unsquashfs-lzma\n\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\t$(CC) mksquashfs.o read_fs.o sort.o -lpthread -lz -lm -o $@\n\n#mksquashfs-lzma: mksquashfs.o read_fs.o sort.o\n#\tmake -C $(LZMAPATH)\n#\t$(CXX) -O3 mksquashfs.o read_fs.o sort.o -L$(LZMAPATH) -lpthread -lm -llzma -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\n#unsquashfs-lzma: unsquashfs.o\n#\tmake -C $(LZMAPATH)\n#\t$(CXX) -O3 unsquashfs.o -L$(LZMAPATH) -llzma -o $@\n\nunsquashfs: unsquashfs.o\n\t$(CC) unsquashfs.o -lz -o $@\n\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h\n\nclean:\n\trm -f *.o\n\trm -f mksquashfs\n\trm -f unsquashfs\n\trm -f mksquashfs-lzma\n\trm -f unsquashfs-lzma\n\trm -f mksquashfs.exe\n\trm -f unsquashfs.exe\n\trm -f mksquashfs-lzma.exe\n\trm -f unsquashfs-lzma.exe\n\tmake -C $(LZMAPATH) clean\n"
  },
  {
    "path": "src/others/squashfs-3.3/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\ntypedef union squashfs_inode_header_1 squashfs_inode_header_1;\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n#define _GNU_SOURCE\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\nint sparse_files = TRUE;\nint old_exclude = TRUE;\nint use_regex = FALSE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* exclude file handling */\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint old_excluded(char *filename, struct stat *buf);\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nstruct pathnames *paths = NULL;\nstruct pathname *path = NULL;\nstruct pathname *stickypath = NULL;\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* recovery file for abnormal exit on appending */\nchar recovery_file[1024] = \"\";\nint recover = TRUE;\n\n/* data allocator status struct.  Allocators are used to keep\n  track of memory buffers passed between different threads */\nstruct allocator {\n\tint\t\tmax_buffers;\n\tint\t\tcount;\n\tint\t\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t\twait;\n};\n\n/* struct describing a memory buffer passed between threads */\nstruct file_buffer {\n\tlong long\t\tfile_size;\n\tstruct allocator\t*allocator;\n\tvoid\t\t\t(*release)(int);\n\tint\t\t\trelease_data;\n\tlong long\t\tblock;\n\tint\t\t\tsize;\n\tint\t\t\tc_byte;\n\tunsigned int\t\tblock_order;\n\tint\t\t\tfragment;\n\tint\t\t\terror;\n\tstruct file_buffer\t*next;\n\tchar\t\t\tdata[0];\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n/* describes the list of blocks in a file which is a possible\n   duplicate.  For each block, it indicates whether the block is\n   in memory or on disk */\nstruct buffer_list {\n\tlong long start;\n\tint size;\n\tstruct file_buffer *read_buffer;\n};\n\nstruct allocator *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *, char *, struct dir_info *));\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\nextern struct priority_entry *priority_list[65536];\n\n\nstruct allocator *alloc_init(int buffer_size, int max_buffers)\n{\n\tstruct allocator *allocator = malloc(sizeof(struct allocator));\n\n\tif(allocator == NULL)\n\t\treturn NULL;\n\n\tallocator->max_buffers = max_buffers;\n\tallocator->buffer_size = buffer_size;\n\tallocator->count = 0;\n\tpthread_mutex_init(&allocator->mutex, NULL);\n\tpthread_cond_init(&allocator->wait, NULL);\n\n\treturn allocator;\n}\n\n\nstruct file_buffer *alloc_get(struct allocator *allocator)\n{\n\tstruct file_buffer *file_buffer;\n\t\n\tpthread_mutex_lock(&allocator->mutex);\n\n\twhile(allocator->count == allocator->max_buffers)\n\t\tpthread_cond_wait(&allocator->wait, &allocator->mutex);\n\n\tif((file_buffer = malloc(sizeof(struct file_buffer) + allocator->buffer_size)) == NULL)\n\t\tgoto failed;\n\n\tfile_buffer->release = NULL;\n\tfile_buffer->allocator = allocator;\n\tallocator->count ++;\n\nfailed:\n\tpthread_mutex_unlock(&allocator->mutex);\n\treturn file_buffer;\n}\n\n\nstruct file_buffer *alloc_get_2(struct allocator *allocator, void (*release)(int), int release_data)\n{\n\tstruct file_buffer *file_buffer = alloc_get(allocator);\n\n\tif(file_buffer) {\n\t\tfile_buffer->release = release;\n\t\tfile_buffer->release_data = release_data;\n\t}\n\treturn file_buffer;\n}\n\n\nvoid alloc_free(struct file_buffer *file_buffer)\n{\n\tstruct allocator *allocator;\n\n\tif(file_buffer == NULL)\n\t\treturn;\n\n\tallocator = file_buffer->allocator;\n\n\tif(file_buffer->release)\n\t\tfile_buffer->release(file_buffer->release_data);\n\n\tpthread_mutex_lock(&allocator->mutex);\n\tfree(file_buffer);\n\tif(allocator->count == 0)\n\t\tERROR(\"alloc_free: freeing buffer for empty allocator!\\n\");\n\telse\n\t\tallocator->count --;\n\tpthread_cond_signal(&allocator->wait);\n\tpthread_mutex_unlock(&allocator->mutex);\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\n\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t}\n\n\tstream->next_in = (unsigned char *) s;\n\tstream->avail_in = size;\n\tstream->next_out = (unsigned char *) d;\n\tstream->avail_out = block_size;\n\n\tres = deflate(stream, Z_FINISH);\n\tif(res != Z_STREAM_END && res != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\telse if(res == Z_BUF_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t}\n\n\tc_byte = stream->total_out;\n\n\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tERROR(\"Failed to read symlink %d, creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %d is greater than 65536 bytes! Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\");\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir)\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir);\n\telse\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL);\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment, int *cached_fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\n\tif(fragment->index == *cached_fragment || fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn buffer + fragment->offset;\n\n\tif(fragment_data && fragment->index == fragments)\n\t\treturn fragment_data->data + fragment->offset;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragment_table[fragment->index].pending)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\n\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\t*cached_fragment = fragment->index;\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid ensure_fragments_flushed()\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragments_outstanding)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].pending = TRUE;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\nvoid frag_release(int block)\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragment_table[block].pending = FALSE;\n\tpthread_cond_signal(&fragment_waiting);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = alloc_get(fragment_buffer);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint avail_bytes, compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tlong long slist[meta_blocks];\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_buffer(struct buffer_list *buffer_list, unsigned int blocks)\n{\n\tunsigned short chksum = 0;\n\tint block;\n\n\tfor(block = 0; block < blocks; block ++) {\n\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\tif(b->read_buffer)\n\t\t\tchksum = get_checksum(b->read_buffer->data, b->read_buffer->size, chksum);\n\t\telse if(b->size != 0)\n\t\t\tchksum = get_checksum(read_from_disk(b->start, b->size), b->size, chksum);\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\nint cached_frag = -1;\nchar fragdata[SQUASHFS_FILE_MAX_SIZE];\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tchar *datap;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\nchar cached_fragment[SQUASHFS_FILE_MAX_SIZE];\nint cached_frag1 = -1;\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), file_size);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nchar buffer2[SQUASHFS_FILE_MAX_SIZE];\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tchar *buffer;\n\t\t\tint block;\n\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks) != 0)\n\t\t\t\tcontinue;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_buffer(buffer_list, blocks);\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), frag_bytes);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\t\t\tif(b->read_buffer)\n\t\t\t\t\tbuffer = b->read_buffer->data;\n\t\t\t\telse if(b->size)\n\t\t\t\t\tbuffer = read_from_disk(b->start, b->size);\n\t\t\t\telse\n\t\t\t\t\tcontinue;\n\n\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\n\t\t\t\tif(memcmp(buffer, buffer2, b->size) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_start += b->size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tchar *fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1);\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\n\tstruct file_buffer *file_buffer;\n\tstatic int block_order = 0;\n\tint blocks, byte, count, expected, file, frag_block;\n\tlong long bytes, read_size;\n\n\tif(dir_ent->inode->read)\n\t\treturn;\n\n\tdir_ent->inode->read = TRUE;\nagain:\n\tbytes = 0;\n\tcount = 0;\n\tfile_buffer = NULL;\n\tread_size = buf->st_size;\n\tblocks = (read_size + block_size - 1) >> block_log;\n\tfrag_block = !no_fragments && (always_use_fragments ||\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\texpected = read_size - ((long long) count * block_size) > block_size ? block_size : read_size - ((long long) count * block_size);\n\n\t\tif(file_buffer)\n\t\t\tqueue_put(from_reader, file_buffer);\n\t\tfile_buffer = alloc_get(reader_buffer);\n\n\t\tbyte = file_buffer->size = read(file, file_buffer->data, block_size);\n\n\t\tfile_buffer->block_order = block_order ++;\n\t\tfile_buffer->file_size = read_size;\n\n\t\tif(byte != expected)\n\t\t\tgoto restat;\n\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->error = FALSE;\n\n\t\tbytes += byte;\n\t\tcount ++;\n\t} while(count < blocks);\n\n\tif(read_size != bytes)\n\t\tgoto restat;\n\n\tif(expected == block_size) {\n\t\tchar buffer;\n\n\t\tif(read(file, &buffer, 1) == 1)\n\t\t\tgoto restat;\n\t}\n\n\tif(file_buffer->fragment = file_buffer->block == frag_block)\n\t\tqueue_put(from_deflate, file_buffer);\n\telse\n\t\tqueue_put(from_reader, file_buffer);\n\n\tclose(file);\n\n\treturn;\n\nread_err:\n\tfile_buffer = alloc_get(reader_buffer);\n\tfile_buffer->block_order = block_order ++;\nread_err2:\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n\treturn;\nrestat:\n\tfstat(file, &buf2);\n\tclose(file);\n\tif(read_size != buf2.st_size) {\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\n\t\tfile_buffer->error = 2;\n\t\tqueue_put(from_deflate, file_buffer);\n\t\tgoto again;\n\t}\n\tgoto read_err2;\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tperror(\"Lseek on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n\t\t\tperror(\"Write on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\nint all_zero(struct file_buffer *file_buffer)\n{\n\tint i;\n\tlong entries = file_buffer->size / sizeof(long);\n\tlong *p = (long *) file_buffer->data;\n\n\tfor(i = 0; i < entries && p[i] == 0; i++);\n\n\tif(i == entries) {\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1); i < file_buffer->size &&\n\t\t\t\t\t\tfile_buffer->data[i] == 0; i++);\n\n\t\treturn i == file_buffer->size;\n\t}\n\n\treturn 0;\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer = alloc_get(writer_buffer);\n\n\t\tif(sparse_files && all_zero(file_buffer)) \n\t\t\twrite_buffer->c_byte = 0;\n\t\telse\n\t\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\n\t\twrite_buffer->file_size = file_buffer->file_size;\n\t\twrite_buffer->block = file_buffer->block;\n\t\twrite_buffer->block_order = file_buffer->block_order;\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\n\t\twrite_buffer->fragment = FALSE;\n\t\twrite_buffer->error = FALSE;\n\t\talloc_free(file_buffer);\n\t\tqueue_put(from_deflate, write_buffer);\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer = alloc_get_2(writer_buffer, frag_release, file_buffer->block);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\twrite_buffer->size = compressed_size;\n\t\twrite_buffer->block = bytes;\n\t\tqueue_put(to_writer, write_buffer);\n\t\tbytes += compressed_size;\n\t\ttotal_uncompressed += file_buffer->size;\n\t\ttotal_compressed += compressed_size;\n\t\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\n\t\tfragments_outstanding --;\n\t\tpthread_cond_signal(&fragment_waiting);\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->block_order);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int block_order = 0;\n\tint hash = BLOCK_HASH(block_order);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->block_order == block_order)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->block_order == block_order)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tblock_order ++;\n\n\treturn file_buffer;\n}\n\n\nint progress_bar(long long current, long long max, int columns)\n{\n\tint max_digits = ceil(log10(max));\n\tint used = max_digits * 2 + 10;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(!progress || columns - used < 0)\n\t\treturn;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n}\n\n\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\n{\n\tint file;\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\talloc_free(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, struct file_buffer *file_buffer, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum)) {\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\n\t\treturn;\n\t}\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\talloc_free(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n\n\treturn;\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\n{\n\tint block;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list;\n\tstruct file_buffer *read_buffer;\n\tint status;\n\n\t*duplicate_file = FALSE;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tif(reader_buffer) {\n\t\t\tread_buffer = reader_buffer;\n\t\t\treader_buffer = NULL;\n\t\t} else {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tif(read_buffer->c_byte) {\n\t\t\tread_buffer->block = bytes;\n\t\t\tbytes += read_buffer->size;\n\t\t\tfile_bytes += read_buffer->size;\n\t\t\tqueue_put(to_writer, read_buffer);\n\t\t} else\n\t\t\talloc_free(read_buffer);\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t} else\n\t\tread_buffer = NULL;\n\n\tfragment = get_and_fill_fragment(read_buffer);\n\talloc_free(read_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tif(block) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\n{\n\tint block, thresh;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer *read_buffer;\n\tstruct file_data *file_data;\n\tstruct buffer_list *buffer_list;\n\tint status;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tthresh = blocks > (writer_buffer_size - processors) ? blocks - (writer_buffer_size - processors): 0;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tif(reader_buffer) {\n\t\t\tread_buffer = reader_buffer;\n\t\t\treader_buffer = NULL;\n\t\t } else {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\n\t\tif(read_buffer->c_byte) {\n\t\t\tread_buffer->block = bytes;\n\t\t\tbytes += read_buffer->size;\n\t\t\tfile_bytes += read_buffer->size;\n\t\t\tif(block < thresh) {\n\t\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else\n\t\t\t\tbuffer_list[block].read_buffer = read_buffer;\n\t\t} else {\n\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\talloc_free(read_buffer);\n\t\t}\n\t\tbuffer_list[block].start = read_buffer->block;\n\t\tbuffer_list[block].size = read_buffer->size;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t} else\n\t\tread_buffer = NULL;\n\n\tqueue_put(to_writer, NULL);\n\tif(queue_get(from_writer) != 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\n\t\tfragment = get_and_fill_fragment(read_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\talloc_free(buffer_list[block].read_buffer);\n\t\tbytes = buffer_list[0].start;\n\t\tif(thresh && !block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\n\talloc_free(read_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tif(block && thresh) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\talloc_free(buffer_list[blocks].read_buffer);\n\tfree(buffer_list);\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn status;\n}\n\n\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tint status;\n\tstruct file_buffer *read_buffer;\n\tlong long read_size;\n\nagain:\n\tread_buffer = get_file_buffer(from_deflate);\n\tif(status = read_buffer->error) {\n\t\talloc_free(read_buffer);\n\t\tgoto file_err;\n\t}\n\t\n\tread_size = read_buffer->file_size;\n\n\tif(read_size == 0) {\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t\talloc_free(read_buffer);\n\t} else if(!no_fragments && (read_size < block_size))\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\telse if(pre_duplicate(read_size))\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\telse\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\nfile_err:\n\tif(status == 2) {\n\t\tERROR(\"File %s changed size while reading filesystem, attempting to re-read\\n\", dir_ent->pathname);\n\t\tgoto again;\n\t} else if(status == 1) {\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\", dir_ent->pathname);\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t}\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\tstruct pathnames *new;\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", filename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\\n\", filename, buf.st_mode & S_IFMT);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(old_exclude) {\n\t\t\tif(old_excluded(filename, &buf))\n\t\t\t\tcontinue;\n\t\t} else {\n\t\t\tif(excluded(paths, dir_name, &new))\n\t\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFREG)\n\t\t\testimated_uncompressed += (buf.st_size + block_size - 1) >> block_log;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, new, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\twrite_file(inode, dir_ent, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tdir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n#if 0\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n#endif\n\t\t\t}\n\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\twrite_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 20; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint old_excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint old_add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(processors * 2);\n\treader_buffer = alloc_init(block_size, reader_buffer_size);\n\twriter_buffer = alloc_init(block_size, writer_buffer_size);\n\tfragment_buffer = alloc_init(block_size, processors * 2);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\n\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\n}\n\n\t\t\t\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\tif(error = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB)) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing exclude which subsumes the exclude currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific excludes, delete as they're subsumed by this exclude\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\t\n\t\nvoid add_exclude(char *target)\n{\n\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 || strncmp(target, \"../\", 3) == 0)\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with -wildcards or -regex options\\n\");\t\n\telse if(strncmp(target, \"... \", 4) == 0)\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\n\telse\t\n\t\tpath = add_path(path, target, target);\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n, res;\n\t\t\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\n\t*new = init_subdir();\n\tif(stickypath)\n\t\t*new = add_subdir(*new, stickypath);\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\n\t\t\tif(match && path->name[i].paths == NULL) {\n\t\t\t\t/* match on a leaf component, any subdirectories in the\n\t\t\t\t * filesystem should be excluded */\n\t\t\t\tres = TRUE;\n\t\t\t\tgoto empty_set;\n\t\t\t}\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t\t/* no matching names found, return empty new search set */\n\t\t\tres = FALSE;\n\t\t\tgoto empty_set;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches).\n\t * Return new set */\n\treturn FALSE;\n\nempty_set:\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn res;\n}\n\n\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\n#define RECOVER_ID_SIZE 28\n\nvoid write_recovery_data(squashfs_super_block *sBlk)\n{\n\tint recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\n\tpid_t pid = getpid();\n\tchar *metadata;\n\tchar header[] = RECOVER_ID;\n\n\tif(recover == FALSE) {\n\t\tprintf(\"No recovery data option specified.\\n\");\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\n\t\treturn;\n\t}\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in write_recovery_data\\n\");\n\n\tread_bytes(fd, sBlk->inode_table_start, bytes, metadata);\n\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\", getbase(destination_file), pid);\n\tif((recoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1)\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  Aborting\\n\", strerror(errno));\n\t\t\n\tif(write(recoverfd, header, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tif(write(recoverfd, sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tif(write(recoverfd, metadata, bytes) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tclose(recoverfd);\n\tfree(metadata);\n\t\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file, recovery_file);\n\tprintf(\"to restore filesystem\\n\\n\");\n}\n\n\nvoid read_recovery_data(char *recovery_file, char *destination_file)\n{\n\tint fd, recoverfd, bytes;\n\tsquashfs_super_block orig_sBlk, sBlk;\n\tchar *metadata;\n\tint readbytes;\n\tstruct stat buf;\n\tchar header[] = RECOVER_ID;\n\tchar header2[RECOVER_ID_SIZE];\n\n\tif((recoverfd = open(recovery_file, O_RDONLY)) == -1)\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\", strerror(errno));\n\n\tif(stat(destination_file, &buf) == -1)\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\", strerror(errno));\n\n\tif((fd = open(destination_file, O_RDWR)) == -1)\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\", strerror(errno));\n\n\tif(read(recoverfd, header2, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\n\n\tif(read(recoverfd, &sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\n\tread_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &orig_sBlk);\n\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4, sizeof(squashfs_super_block) - 4) != 0)\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to match\\n\");\n\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in read_recovery_data\\n\");\n\n\tif((readbytes = read(recoverfd, metadata, bytes)) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\n\tif(readbytes != bytes)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\twrite_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\twrite_bytes(fd, sBlk.inode_table_start, bytes, metadata);\n\n\tclose(recoverfd);\n\tclose(fd);\n\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\", recovery_file);\n\t\n\texit(0);\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.3 (2007/10/31)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct winsize winsize;\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT;\n\tint s_minor;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-recover\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\n\t\t\trecover = FALSE;\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = FALSE;\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\n\t\t\tsparse_files = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -b missing block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_size = strtol(argv[i], &b, 10);\n\t\t\tif(*b == 'm' || *b == 'M')\n\t\t\t\tblock_size *= 1048576;\n\t\t\telse if(*b == 'k' || *b == 'K')\n\t\t\t\tblock_size *= 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tERROR(\"%s: -b invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 1Mbyte\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data using recovery file <name>\\n\");\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery file\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards (globbing) to be used in\\n\\t\\t\\texclude dirs/files\\n\");\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n\tif(block_size <= 65536 && sparse_files == FALSE)\n\t\ts_minor = 0;\n\telse\n\t\ts_minor = SQUASHFS_MINOR;\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tsignal(SIGTERM, sighandler2);\n\tsignal(SIGINT, sighandler2);\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\t\tif(old_exclude)\n\t\t\t\t\t\told_add_exclude(filename);\n\t\t\t\t\telse\n\t\t\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc)\n\t\t\tif(old_exclude)\n\t\t\t\told_add_exclude(argv[i++]);\n\t\t\telse\n\t\t\t\tadd_exclude(argv[i++]);\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\ts_minor = sBlk.s_minor;\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t}\n\n\tinitialise_threads();\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = inode_dir_offset + inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\twrite_recovery_data(&sBlk);\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(progress) {\n\t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\t\tcolumns = 80;\n\t\t} else\n\t\t\tcolumns = winsize.ws_col;\n\t\tsignal(SIGWINCH, sigwinch_handler);\n\t}\n\n\tif(path || stickypath) {\n\t\tpaths = init_subdir();\n\t\tif(path)\n\t\t\tpaths = add_subdir(paths, path);\n\t\tif(stickypath)\n\t\t\tpaths = add_subdir(paths, stickypath);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = s_minor;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tensure_fragments_flushed();\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\tclose(fd);\n\n\tif(recovery_file[0] != '\\0')\n\t\tunlink(recovery_file);\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tint uid = uids[i];\n\t\tstruct passwd *user = getpwuid(uid);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.3/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Filesystem on %s is %d.%d, which is a later filesystem version than I support\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %xllx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block; \n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tlong long sindex[indexes];\n\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_inode_t sinode;\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\n\t\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.3/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\twrite_file(&inode, entry->dir, &duplicate_file);\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3/sqmagic.h",
    "content": "/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE must follow the one in squashfs.\n */\n\n/* $Id: sqmagic.h,v 1.2 2006-11-27 03:54:58 jro Exp $ */\n\n#ifndef __sqmagic_h__\n#define __sqmagic_h__\n\n/* see SQUASHFS_MAGIC in squashfs_fs.h */\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t1\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n *  Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_1_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define _GNU_SOURCE\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"sqmagic.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n#include <time.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(char *pathname, unsigned int block_start, unsigned int offset);\n\tchar *(*read_fragment)(unsigned int fragment);\n\tvoid (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, unsigned char *block_ptr, int blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar symlink[65536];\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n};\n\t\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE, use_regex = FALSE;\nchar **created_inode;\nint root_process;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0} };\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\tif((user = getpwuid(inode->uid)) == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tif((group = getgrgid(inode->gid)) == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0, inode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \", (int) inode->data >> 8, (int) inode->data & 0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes,\n\t\t(const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes,\n\t\t(const unsigned char *) data, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid read_block_list(unsigned int *block_list, unsigned char *block_ptr, int blocks)\n{\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nvoid read_block_list_1(unsigned int *block_list, unsigned char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) | (SQUASHFS_COMPRESSED(block_size) ? 0 : SQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time, unsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_1()\n{\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nchar *read_fragment_2(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data;\nlong long hole;\n\nint write_block(int file_fd, char *buffer, int size)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(lseek_broken == FALSE && lseek(file_fd, off, SEEK_CUR) == -1) {\n\t\t\t/* failed to seek beyond end of file */\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t\tlseek_broken = TRUE;\n\t\t}\n\t\tif(lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size : hole;\n\t\t\t\tif(write(file_fd, zero_data, avail_bytes) < avail_bytes)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t\thole = 0;\n\t}\n\n\tif(write(file_fd, buffer, size) < size)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\t\nint write_file(long long file_size, char *pathname, unsigned int fragment, unsigned int frag_bytes,\nunsigned int offset, unsigned int blocks, long long start, char *block_ptr,\nunsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\tint file_end = file_size / block_size;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\thole = 0;\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\ts_ops.read_block_list(block_list, block_ptr, blocks);\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif(block_list[i] == 0) { /* sparse file */\n\t\t\thole += i == file_end ? file_size & (block_size - 1) : block_size;\n\t\t\tcontinue;\n\t\t}\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write_block(file_fd, file_data, bytes) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = s_ops.read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write_block(file_fd, fragment_data + offset, frag_bytes) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tif(hole) {\n\t\t/* corner case for hole extending to end of file */\n\t\thole --;\n\t\tif(write_block(file_fd, \"\\0\", 1) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write sparse data block\\n\");\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\tfree(block_list);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\n\nstatic struct inode *read_inode(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i->data, pathname, i->fragment, i->frag_bytes,\n\t\t\t\t\ti->offset, i->blocks, i->start, i->block_ptr, i->mode)) {\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", i->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\tmakedev((i->data >> 8) & 0xff, i->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", i->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_2 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[header.base.uid];\n    i.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_2!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_1 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode, sizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[(header.base.inode_type - 1) / SQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) % SQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n    i.gid = header.base.guid == 15 ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_1), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_1!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(char *pathname, unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tstruct inode *i;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + i->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(pathname, i);\n\n\tbytes += i->offset;\n\tsize = i->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = i->mode;\n\tdir->uid = i->uid;\n\tdir->guid = i->gid;\n\tdir->mtime = i->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(char *pathname, unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tstruct inode *i;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + i->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(pathname, i);\n\n\tbytes += i->offset;\n\tsize = i->data + bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = i->mode;\n\tdir->uid = i->uid;\n\tdir->guid = i->gid;\n\tdir->mtime = i->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\tif(error = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB)) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing extract which subsumes the extract currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific extracts, delete as they're subsumed by this extract\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/* match on a leaf component, any subdirectories will\n\t\t\t\t * implicitly match, therefore return an empty new search set */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/* no matching names found, delete empty search set, and return\n        * FALSE */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches),\n     * return new search set and return TRUE */\n\treturn TRUE;\n\nempty_set:\n   /* found matching leaf exclude, return empty search set and return TRUE */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, struct pathnames *paths)\n{\n\tstruct dir *dir = s_ops.squashfs_opendir(parent_name, start_block, offset);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly)\n\t\t\t\tcreate_inode(pathname, i);\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str : \"failed to get time\\n\");\n\tprintf(\"Filesystem is %sexportable via NFS\\n\", SQUASHFS_EXPORTABLE(sBlk.flags) ? \"\" : \"not \");\n\n\tprintf(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tif(sBlk.s_major > 1 && !SQUASHFS_NO_FRAGMENTS(sBlk.flags))\n\t\tprintf(\"Fragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Check data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not \");\n\tif(sBlk.s_major > 1) {\n\t\tprintf(\"Fragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not \" : \"\");\n\t\tprintf(\"Always_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not \");\n\t} else\n\t\tprintf(\"Fragments are not supported by the filesystem\\n\");\n\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tprintf(\"Block size %d\\n\", sBlk.block_size);\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.fragments);\n\tprintf(\"Number of inodes %d\\n\", sBlk.inodes);\n\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tif(sBlk.s_major > 1)\n\t\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n}\n\n\nint read_super(char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk.s_magic != SQUASHFS_MAGIC && sBlk.s_magic != SQUASHFS_MAGIC_LZMA) {\n\t\tif(sBlk.s_magic == SQUASHFS_MAGIC_SWAP || sBlk.s_magic == SQUASHFS_MAGIC_LZMA_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 1 || sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s_major == 1) {\n\t\t\tsBlk.block_size = sBlk.block_size_1;\n\t\t\tsBlk.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t} else {\n\t\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t}\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor <= 1) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.read_block_list = read_block_list;\n\t\ts_ops.read_inode = read_inode;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tif((fd = fopen(filename, \"r\")) == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename, strerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.5 (2007/10/31)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tchar **target_name = NULL;\n\tint n, targets = 0;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\n\tif(root_process = geteuid() == 0)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 || strcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 || strcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 || strcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 || strcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 || strcmp(argv[i], \"-r\") == 0)\n\t\t\tuse_regex = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are unsquashed with file\\n\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file attributes (like\\n\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX regular expressions\\n\\t\\t\\t\\trather than use the default shell wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tblock_size = sBlk.block_size;\n\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids();\n\n\ts_ops.read_fragment_table();\n\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/.tmpdeps",
    "content": "t/squashfs-lzma\nt/lzma\nt/sqlzma\nt/ksquashfs\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/.topdeps",
    "content": "squashfs\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/.topmsg",
    "content": "From: Michael Gebetsroither <gebi@sbox.tugraz.at>\nSubject: [PATCH] t/squashfs-lzma\n\nsquashfs lzma patch\n\nSigned-off-by: Michael Gebetsroither <gebi@sbox.tugraz.at>\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/Makefile",
    "content": "\n# Copyright (C) 2006-2008 Junjiro Okajima\n# Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described ones in lzma and squashfs.\n\n# $Id: Makefile,v 1.30 2008-03-12 16:24:54 jro Exp $\n\n# paths\nSqlzma = ${CURDIR}\n\nLzmaVer = lzma\nLzma = ${Sqlzma}/${LzmaVer}\nSqVer = squashfs3.3\nSquashfs = ${Sqlzma}/${SqVer}\nKVer = linux-2.6.24.3\nSqFs = ${Squashfs}/kernel-patches/${KVer}/fs/squashfs\n#KDir = /lib/modules/$(shell uname -r)/build\n\nifeq (${LzmaVer}, lzma443)\nLzmaC = ${Lzma}/C/7zip/Compress/LZMA_C\nLzmaAlone = ${Lzma}/C/7zip/Compress/LZMA_Alone\nelse\nLzmaC = ${Lzma}/C/Compress/Lzma\nLzmaAlone = ${Lzma}/CPP/7zip/Compress/LZMA_Alone\nendif\nSqTools = ${Squashfs}/squashfs-tools\n\n# enable it if you want to add -g option when compiling\nUseDebugFlags =\n# disable it if you don't want to compile squashfs kernel module here\n#BuildSquashfs = 1\n\nexport\n\nall:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\nclean:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\t${RM} *~\n\n########################################\n\n-include priv.mk\n\nifdef BuildSquashfs\nCONFIG_SQUASHFS = m\nCONFIG_SQUASHFS_EMBEDDED =\nCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE = 3\nEXTRA_CFLAGS = -I${Sqlzma} -I${SqFs}/../../include -Wall -Werror\nEXTRA_CFLAGS += -DCONFIG_SQUASHFS_MODULE -UCONFIG_SQUASHFS\nEXTRA_CFLAGS += -UCONFIG_SQUASHFS_EMBEDDED -DCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3\n# if you enabled CONFIG_PREEMPT, but want CPU to try concentrating\n# the uncompression, then define UnsquashNoPreempt.\n# if you don't define UnsquashNoPreempt, the behaviour follows\n# the CONFIG_PREEMPT.\nEXTRA_CFLAGS += -DUnsquashNoPreempt\nexport\n\n# the environment variables are not inherited since 2.6.23\nMAKE += SQLZMA_EXTRA_CFLAGS=\"$(shell echo ${EXTRA_CFLAGS} | sed -e 's/\\\"/\\\\\\\\\\\\\"/g')\"\n\nall: all_sq\n\nFORCE:\nall_sq:\n\t${MAKE} -C ${KDir} M=${SqFs} modules\n\nclean: clean_sq\nclean_sq:\n\t${MAKE} -C ${KDir} M=${SqFs} clean\nendif\n\n########################################\n\nload:\n\tfor i in ${LzmaC}/kmod/unlzma.ko ${LzmaC}/kmod/sqlzma.ko \\\n\t\t${SqFs}/squashfs.ko; \\\n\tdo sudo insmod $$i; done\n\nunload:\n\t-sudo rmmod squashfs sqlzma unlzma\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/changelog",
    "content": "squashfs-lzma (3.3-1) unstable; urgency=low\n\n  [ Michael Gebetsroither ]\n  * Initial release [Closes: issue465]\n\n  [ Michael Prokop ]\n  * Fix build of squashfs-lzma-source.\n  * Bump Standard Version to 3.8.0 (no further changes).\n  * Add myself to uploaders.\n\n -- Michael Prokop <mika@grml.org>  Tue, 16 Sep 2008 12:53:30 +0200\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/compat",
    "content": "5\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/control",
    "content": "Source: squashfs-lzma\nSection: admin\nPriority: optional\nMaintainer: Michael Gebetsroither <gebi@grml.org>\nUploaders: Michael Prokop <mika@grml.org>\nBuild-Depends: cdbs (>= 0.4.23-1.1),\n               patchutils (>= 0.2.25),\n               debhelper (>= 5),\n               zlib1g-dev,\n               po4a (>= 0.21),\n               xsltproc,\n               docbook-xsl,\n               bzip2,\n               binutils-hppa64 [hppa],\n               gcc-4.2-hppa64 [hppa],\n               docbook-xml\nStandards-Version: 3.8.0\nHomepage: http://squashfs.sourceforge.net/\nXS-Vcs-git: git://git.grml.org/squashfs-lzma.git\nXS-Vcs-Browser: http://git.grml.org/?p=squashfs-lzma.git\n\nPackage: squashfs-lzma-tools\nArchitecture: any\nDepends: ${shlibs:Depends}, ${misc:Depends}\nReplaces: squashfs-tools\nProvides: squashfs-tools\nConflicts: squashfs-tools\nSuggests: squashfs-source\nDescription: Tool to create and append to squashfs filesystems\n Squashfs is a highly compressed read-only filesystem for Linux. It uses zlib\n compression to compress both files, inodes and directories. Inodes in the\n system are very small and all blocks are packed to minimise data overhead.\n Block sizes greater than 4K are supported up to a maximum of 64K.\n .\n Squashfs is intended for general read-only filesystem use, for archival\n use (i.e. in cases where a .tar.gz file may be used), and in constrained\n block device/memory systems (e.g. embedded systems) where low overhead is\n needed.\n .\n This version supports lzma for http://grml.org.\n\nPackage: squashfs-lzma-source\nArchitecture: all\nDepends: module-assistant,\n\t debhelper (>= 5),\n\t make,\n\t bzip2,\n\t zlib1g-dev\nRecommends: squashfs-tools\nConflicts: kernel-patch-squashfs\nReplaces: kernel-patch-squashfs\nDescription: Source for the squash filesystem\n Squashfs is a highly compressed read-only filesystem for Linux. It uses zlib\n compression to compress both files, inodes and directories. Inodes in the\n system are very small and all blocks are packed to minimise data overhead.\n Block sizes greater than 4K are supported up to a maximum of 64K.\n .\n Squashfs is intended for general read-only filesystem use, for archival\n use (i.e. in cases where a .tar.gz file may be used), and in constrained\n block device/memory systems (e.g. embedded systems) where low overhead is\n needed.\n .\n This package provides the source code for the squashfs kernel modules.\n The squashfs-tools package is also required in order to make use of these\n modules. Kernel source or headers are required to compile these modules.\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/control.modules.in",
    "content": "Source: squashfs-lzma\nSection: misc\nPriority: optional\nMaintainer: Michael Gebetsroither <gebi@grml.org>\nBuild-Depends: debhelper (>= 5), linux-headers-_KVERS_, zlib1g-dev\nStandards-Version: 3.7.3\nHomepage: http://squashfs.sourceforge.net/\n\nPackage: squashfs-lzma-modules-_KVERS_\nArchitecture: any\nProvides: squashfs-modules\nDepends: linux-modules-_KVERS_ | linux-image-_KVERS_\nDescription: Squash filesystem support for Debian Linux kernels\n Squashfs is a highly compressed read-only filesystem for Linux. It uses zlib\n compression to compress both files, inodes and directories. Inodes in the\n system are very small and all blocks are packed to minimise data overhead.\n Block sizes greater than 4K are supported up to a maximum of 64K.\n .\n Squashfs is intended for general read-only filesystem use, for archival use\n (e.g. in cases where a .tar.gz file may be used), and in constrained block\n device/memory systems (e.g. embedded systems) where low overhead is needed.\n .\n This package contains the compiled kernel module for _KVERS_\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/copyright",
    "content": "This package was debianized by Michael Gebetsroither <gebi@grml.org> on\nThu, 04 Sep 2008 18:15:47 +0200.\n\nIt was downloaded from http://www.squashfs-lzma.org/\n\nCopyright:\n\nUpstream Author: Phillip Lougher (plougher@users.sourceforge.net)\n\nLicense:\n\n   This  package is  free  software; you  can  redistribute it  and/or\n   modify  it under the  terms of  the GNU  General Public  License as\n   published by  the Free Software  Foundation; version 2  dated June,\n   1991.\n\n   This package is distributed in the hope that it will be useful, but\n   WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of\n   MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU\n   General Public License for more details.\n\n   You should have  received a copy of the  GNU General Public License\n   along  with  this package;  if  not,  write  to the  Free  Software\n   Foundation,  Inc.,   51  Franklin  St,  Fifth   Floor,  Boston,  MA\n   02110-1301, USA.\n\nOn Debian systems, the complete text of the GNU General Public License\ncan be found in `/usr/share/common-licenses/GPL-2'.\n\nThe Debian packaging is (C) 2008, Michael Gebetsroither <gebi@grml.org> and\nis licensed under the GPL, see `/usr/share/common-licenses/GPL'.\n\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/doc/en/mksquashfs.dbk",
    "content": "<?xml version='1.0' encoding='UTF-8'?>\n<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"\n\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\" [\n\n<!--\n\nProcess this file with an XSLT processor: `xsltproc \\\n-''-nonet /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/\\\nmanpages/docbook.xsl manpage.dbk'.  A manual page\n<package>.<section> will be generated.  You may view the\nmanual page with: nroff -man <package>.<section> | less'.  A\ntypical entry in a Makefile or Makefile.am is:\n\nDB2MAN=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/\\\nmanpages/docbook.xsl\nXP=xsltproc -''-nonet\n\nmanpage.1: manpage.dbk\n        $(XP) $(DB2MAN) $<\n\nThe xsltproc binary is found in the xsltproc package.  The\nXSL files are in docbook-xsl.  Please remember that if you\ncreate the nroff version in one of the debian/rules file\ntargets (such as build), you will need to include xsltproc\nand docbook-xsl in your Build-Depends control field.\n\n-->\n\n  <!-- Fill in your name for FIRSTNAME and SURNAME. -->\n  <!ENTITY dhfirstname \"<firstname>Frédéric</firstname>\">\n  <!ENTITY dhsurname   \"<surname>Boiteux</surname>\">\n\n  <!-- Please adjust the date whenever revising the manpage. -->\n  <!ENTITY dhdate      \"<date>december 20, 2004</date>\">\n\n  <!-- SECTION should be 1-8, maybe w/ subsection other parameters are\n       allowed: see man(7), man(1). -->\n  <!ENTITY dhsection   \"<manvolnum>1</manvolnum>\">\n  <!ENTITY dhemail     \"<email>fboiteux@calistel.com</email>\">\n  <!ENTITY dhusername  \"Frédéric Boiteux\">\n  <!ENTITY dhucpackage \"<refentrytitle>MKSQUASHFS</refentrytitle>\">\n  <!ENTITY dhpackage   \"mksquashfs\">\n\n  <!ENTITY debian      \"<productname>Debian</productname>\">\n  <!ENTITY gnu         \"<acronym>GNU</acronym>\">\n  <!ENTITY gpl         \"&gnu; <acronym>GPL</acronym>\">\n]>\n\n<!-- ====================================================================== -->\n<refentry lang=\"fr\">\n  <refentryinfo>\n    <address>\n      &dhemail;\n    </address>\n    <!-- <author> -->\n<!--       &dhfirstname; -->\n<!--       &dhsurname; -->\n<!--     </author> -->\n    <copyright>\n      <year>2005</year>\n      <holder>&dhusername;</holder>\n    </copyright>\n    &dhdate;\n  </refentryinfo>\n\n  <!-- ============================================================ -->\n  <refmeta>\n    &dhucpackage;\n\n    &dhsection;\n  </refmeta>\n\n  <!-- ============================================================ -->\n  <refnamediv>\n    <refname>&dhpackage;</refname>\n\n    <refpurpose>Create or modify a Squash file system</refpurpose>\n  </refnamediv>\n\n  <!-- ============================================================ -->\n  <refsynopsisdiv>\n    <cmdsynopsis>\n      <command>&dhpackage;</command>\n      <arg><option>-version</option></arg>\n    </cmdsynopsis>\n\n    <cmdsynopsis>\n      <command>&dhpackage;</command>\n      <arg choice=\"plain\"\n        rep=\"repeat\"><replaceable>source</replaceable></arg>\n      <arg choice=\"plain\"><replaceable>dest</replaceable></arg>\n      <arg><option>options</option></arg>\n      <arg><option>-e  <replaceable>list of exclude\n            dirs/files</replaceable></option></arg>\n      <arg><option>-ef <replaceable>exclude_file</replaceable></option></arg>\n    </cmdsynopsis>\n  </refsynopsisdiv>\n\n  <!-- ============================================================ -->\n  <refsect1>\n    <title>DESCRIPTION</title>\n\n    <para>A squashfs is a compressed read-only file system. Use the\n      <command>&dhpackage;</command> program to create a new\n      squashed file system, and to append new data to an existing\n      squashed file system.</para>\n\n    <para>If a single source directory is specified\n      (i.e. <userinput>mksquashfs <replaceable>source</replaceable>\n        <replaceable>output_fs</replaceable></userinput>), the\n      squashfs filesystem will consist of that directory, with the\n      top-level root directory corresponding to the source\n      directory.</para>\n\n    <para>If multiple source directories or files are specified,\n      <command>&dhpackage;</command> will merge the specified sources\n      into a single filesystem, with the root directory containing each\n      of the source files/directories.  The name of each directory entry\n      will be the basename of the source path.   If more than one source\n      entry maps to the same name, the conflicts are named\n      <replaceable>xxx</replaceable>_1, <replaceable>xxx</replaceable>_2,\n      etc. where <replaceable>xxx</replaceable> is the original\n      name. </para>\n\n    <para>The <replaceable>dest</replaceable> argument can either\n      be a conventional file or a block device. If the file doesn't\n      exist it will be created, if it does exist and a squashfs\n      filesystem exists on it, <command>&dhpackage;</command> will\n      append.  The <option>-noappend </option>option will write a new\n      filesystem irrespective of whether an existing filesystem is\n      present.</para>\n\n    <para>There are a large number of options that can be used to\n      control the compression in <command>&dhpackage;</command>.  By\n      and large the defaults are the most optimum settings and should\n      only be changed in exceptional circumstances !</para>\n\n    <para>The <option>-noI</option>, <option>-noD</option> and\n      <option>-noF</option> options (also\n      <option>-noInodeCompression</option>,\n      <option>-noDataCompression</option> and\n      <option>-noFragmentCompression</option>) can be used to force\n      <command>&dhpackage;</command> to not compress\n      inodes/directories, data and fragments respectively.  Giving all\n      options generates an uncompressed filesystem.</para>\n\n\n    <para>By default files in the generated filesystem inherit the UID\n      and GID ownership of the original file.  However,\n      <command>&dhpackage;</command> provides a number of options\n      which can be used to override the ownership:\n    </para>\n\n      <itemizedlist>\n        <listitem>\n\t<para>\n\t The options <option>-all-root</option> and\n            <option>-root-owned</option> (both do exactly the same\n            thing) force all file uids/gids in the generated Squashfs\n            filesystem to be <literal>root</literal>.  This allows\n            root owned filesystems to be built without root access on\n            the host machine.</para></listitem>\n        <listitem>\n          <para>The <option>-force-uid\n              <replaceable>uid</replaceable></option> option forces\n            all files in the generated Squashfs filesystem to be owned\n            by the specified <replaceable>uid</replaceable>.  The uid\n            can be specified either by name\n            (i.e. <literal>root</literal>) or by\n            number.</para></listitem>\n        <listitem>\n          <para>The <option>-force-gid\n              <replaceable>gid</replaceable></option> option forces\n            all files in the generated Squashfs filesystem to be group\n            owned by the specified <replaceable>gid</replaceable>.\n            The gid can be specified either by name\n            (i.e. <literal>root</literal>) or by\n            number.</para></listitem>\n      </itemizedlist>\n\n    <para>The <option>-e</option> and <option>-ef</option> options\n      allow files/directories to be specified which are\n      excluded from the output filesystem.  The <option>-e</option>\n      option takes the exclude files/directories from the command\n      line, the <option>-ef</option> option takes the exlude\n      files/directories from the specified exclude file, one\n      file/directory per line. If an exclude file/directory is\n      absolute (i.e. prefixed with <filename>/</filename>,\n      <filename>../</filename>, or <filename>./</filename>) the entry\n      is treated as absolute, however, if an exclude file/directory\n      is relative, it is treated as being relative to each of the\n      sources in turn, i.e.\n      <userinput>mksquashfs /tmp/source1 source2 output_fs -e ex1 /tmp/source1/ex2 out/ex3</userinput>\n      Will generate exclude files\n      <filename>/tmp/source1/ex2</filename>,\n      <filename>/tmp/source1/ex1</filename>,\n      <filename>source2/ex1</filename>,\n      <filename>/tmp/source1/out/ex3</filename> and\n      <filename>source2/out/ex3</filename>.</para>\n\n    <para>The <option>-e</option> and <option>-ef</option> exclude\n      options are usefully used in archiving the entire filesystem,\n      where it is wished to avoid archiving\n      <filename>/proc</filename>, and the filesystem being generated,\n      i.e.\n      <userinput>mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh</userinput></para>\n\n    <para>Multiple <option>-ef</option> options can be specified on\n      the command line, and the <option>-ef</option>\n      option can be used in conjuction with the <option>-e</option>\n      option.</para>\n\n    <para>The <option>-info</option> option displays the\n      files/directories as they are compressed and added to the\n      filesystem.  The original uncompressed size of each file is\n      printed, along with <literal>DUPLICATE</literal> if the file is\n      a duplicate of a file in the filesystem.</para>\n\n    <para>The <option>-no-exports</option> option doesn't make the\n      filesystem exportable via NFS.</para>\n\n    <para>The <option>-no-progress</option> option doesn't display the\n      progress bar.</para>\n\n    <para>The <option>-le</option> and <option>-be</option> options\n      can be used to force <command>&dhpackage;</command> to generate\n      a little endian or big endian filesystem.  Normally\n      <command>&dhpackage;</command> will generate a filesystem in the\n      host byte order.  Squashfs, for portability, will mount\n      different ordered filesystems (i.e. it can mount big endian\n      filesystems running on a little endian machine), but these\n      options can be used for greater optimisation.</para>\n  </refsect1>\n\n  <!-- ============================================================ -->\n  <refsect1>\n    <title>OPTIONS</title>\n\n    <variablelist>\n      <varlistentry>\n        <term>\n          <option>-version</option>\n        </term>\n        <listitem>\n          <para>print version, licence and copyright message.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-recover\n            <replaceable>name</replaceable></option></term>\n\n        <listitem><para>Allows the original filesystem to be recovered\n            if Mksquashfs aborts unexpectedly (i.e.  power failure)\n            using recovery file <replaceable>name</replaceable>.\n            Recovery files are now created when appending to existing\n            Squashfs filesystems.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-no-recovery</option></term>\n        <listitem><para>don't generate a recovery file</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-info</option></term>\n        <listitem><para>print files written to filesystem</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-no-exports</option></term>\n        <listitem><para>don't make the filesystem exportable via\n        NFS</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-no-progress</option></term>\n        <listitem><para>don't display the progress bar</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-no-sparse</option></term>\n        <listitem><para>don't detect sparse files</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-b\n            <replaceable>block_size</replaceable></option></term>\n        <listitem><para>set data block to\n            <replaceable>block_size</replaceable>. Default is\n            131072 bytes</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-processors\n            <replaceable>number</replaceable></option></term>\n        <listitem><para>Use <replaceable>number</replaceable>\n\tprocessors.  By default will use number of processors\n\tavailable</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-read-queue\n            <replaceable>size</replaceable></option></term>\n        <listitem><para>Set input queue to\n\t<replaceable>size</replaceable> Mbytes. Default 64\n\tMbytes.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-write-queue\n            <replaceable>size</replaceable></option></term>\n        <listitem><para>Set output queue to\n\t<replaceable>size</replaceable> Mbytes. Default 512\n\tMbytes.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-noI</option> or\n          <option>-noInodeCompression</option></term>\n        <listitem><para>do not compress inode table</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-noD</option>or\n          <option>-noDataCompression</option></term>\n        <listitem><para>do not compress data blocks</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-noF</option> or\n          <option>-noFragmentCompression</option></term>\n        <listitem><para>do not compress fragment blocks</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-no-fragments</option></term>\n        <listitem><para>do not use fragments: tells\n            <command>&dhpackage;</command> to not generate fragment\n            blocks, and rather generate a filesystem similar to a\n            Squashfs 1.x filesystem. It will of course still be a\n            Squashfs 2.0 filesystem but without fragments, and so it\n            won't be mountable on a Squashfs 1.x system.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-always-use-fragments</option></term>\n        <listitem><para>use fragment blocks for files larger than\n            block size: tells <command>&dhpackage;</command> to\n            always generate fragments for files irrespective of the\n            file length.  By default only small files less than the\n            block size are packed into fragment blocks.  The ends of\n            files which do not fit fully into a block, are\n            <emphasis>NOT</emphasis> by\n            default packed into fragments.  To illustrate this, a 100K\n            file has an initial 64K block and a 36K remainder.  This\n            36K remainder is not packed into a fragment by default.\n            This is because to do so leads to a 10 - 20% drop in\n            sequential I/O performance, as a disk head seek is needed\n            to seek to the initial file data and another disk seek is\n            need to seek to the fragment block. Specify this option if\n            you want file remainders to be packed into fragment\n            blocks. Doing so may increase the compression obtained\n            <emphasis>BUT</emphasis> at the expense of I/O\n            speed.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-no-duplicates</option></term>\n        <listitem><para>do not perform duplicate checking: tells\n            <command>&dhpackage;</command> to not check the files\n            being added to the filesystem for duplicates.  This can\n            result in quicker filesystem generation and appending\n            although obviously compression will suffer badly if there\n            is a lot of duplicate files.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-noappend</option></term>\n        <listitem><para>do not append to existing\n            filesystem</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-keep-as-directory</option></term>\n        <listitem><para>if one source directory is specified,\n            create a root directory containing that directory, rather\n            than the contents of the directory</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-root-becomes\n            <replaceable>name</replaceable></option></term>\n        <listitem><para>when appending source files/directories,\n            make the original root become a subdirectory in the new\n            root called <replaceable>name</replaceable>, rather than\n            adding the new source items to the original root</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-all-root</option> or\n          <option>-root-owned</option></term>\n        <listitem><para>make all files owned by root</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-force-uid\n            <replaceable>uid</replaceable></option></term>\n        <listitem><para>set all file uids to\n            <replaceable>uid</replaceable></para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-force-gid\n            <replaceable>gid</replaceable></option></term>\n        <listitem><para>set all file gids to\n            <replaceable>gid</replaceable></para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-le</option></term>\n        <listitem><para>create a little endian filesystem</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-be</option></term>\n        <listitem><para>create a big endian filesystem</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-nopad</option></term>\n        <listitem><para>do not pad filesystem to a multiple of 4Ko.\n            This is performed by default to enable the output\n            filesystem file to be mounted by loopback, which requires\n            files to be a 4K multiple.  If the filesystem is being\n            written to a block device, or is to be stored in a\n            bootimage, the extra pad bytes are not needed.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-check_data</option></term>\n        <listitem><para>add checkdata for greater filesystem\n            checks</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-sort\n            <replaceable>sort_file</replaceable></option></term>\n        <listitem><para>sort files according to priorities in\n            <replaceable>sort_file</replaceable>.  One file or dir\n            with priority per line.  Priority -32768 to 32767, default\n            priority 0</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-e <replaceable>list of exclude\n              dirs/files</replaceable></option></term>\n        <listitem><para>inline list of files / directories to\n            exclude</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-ef\n            <replaceable>exclude_file</replaceable></option></term>\n        <listitem><para>file containing a list of files /\n            directories to exclude, one per line</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-wildcards</option></term>\n        <listitem><para>Allow extended shell wildcards (globbing) to\n  \tbe used in exclude dirs/files</para></listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-regex</option></term>\n        <listitem><para>Allow POSIX regular expressions to be used in\n\texclude dirs/files</para></listitem>\n      </varlistentry>\n    </variablelist>\n  </refsect1>\n\n  <!-- ============================================================ -->\n  <refsect1>\n    <title>EXAMPLES</title>\n\n    <para>For following examples, take two example directories:\n      <itemizedlist>\n        <listitem>\n          <para>Source directory\n            <filename>/home/phillip/test</filename> contains\n            <filename>file1</filename>, <filename>file2</filename> and\n            <filename>dir1</filename>.</para>\n        </listitem>\n        <listitem>\n          <para> Source directory\n            <filename>goodies</filename> contains\n            <filename>goodies1</filename>,\n            <filename>goodies2</filename> and\n            <filename>goodies3</filename>.</para>\n        </listitem>\n      </itemizedlist>\n    </para>\n\n    <refsect2>\n      <example id=\"exemple_1\">\n        <title></title>\n        <screen><userinput>mksquashfs /home/phillip/test output_fs</userinput></screen>\n        <para>This will generate a squashfs filesystem with root\n          entries <filename>file1</filename>, <filename>file2</filename>\n          and <filename>dir1</filename>.</para>\n      </example>\n    </refsect2>\n\n    <refsect2>\n      <example>\n        <title></title>\n        <screen><userinput>mksquashfs /home/phillip/test goodies output_fs</userinput></screen>\n        <para>This will create a squashfs filesystem with the root\n          containing entries <filename>test</filename> and\n          <filename>goodies</filename> corresponding to the source\n          directories <filename>/home/phillip/test</filename> and\n          <filename>goodies</filename>.</para>\n      </example>\n    </refsect2>\n\n    <refsect2>\n      <example>\n        <title></title>\n        <screen><userinput>mksquashfs /home/phillip/test goodies test output_fs</userinput></screen>\n\n        <para>This is the same as the previous example, except a third\n          source directory <filename>test</filename> has been\n          specified. This conflicts with the first directory named\n          <filename>test</filename> and will be renamed\n          <filename>test_1</filename>.</para>\n        <para>Multiple sources allow filesystems to be generated\n          without needing to copy all source files into a common\n          directory.  This simplifies creating filesystems.</para>\n      </example>\n    </refsect2>\n\n    <refsect2>\n      <example>\n        <title></title>\n        <screen><userinput>mksquashfs /home/phillip/test output_fs -keep-as-directory</userinput></screen>\n\n        <para>This is the same as the first example,\n          except for <option>-keep-as-directory</option>. This will\n          generate a root directory containing directory\n          <filename>test</filename>, rather than the\n          <filename>test</filename> directory contents\n          <filename>file1</filename>, <filename>file2</filename> and\n          <filename>dir1</filename>.</para>\n      </example>\n    </refsect2>\n  </refsect1>\n\n  <!-- ============================================================ -->\n  <refsect1>\n    <title>AUTHORS</title>\n\n    <para>Squashfs was written by <personname>\n        <firstname>Phillip</firstname>\n        <surname>Lougher</surname>\n      </personname>\n      <email>plougher@users.sourceforge.net</email>, in Chepstow,\n      Wales, UK. If you like the program, or have any problems, then\n      please email me, as it's nice to get feedback !</para>\n\n    <para>This manual page was written by &dhusername; &dhemail; for\n      the &debian; system (but may be used by others) using the\n      <citetitle>SquashFS HOWTO</citetitle> from <author>\n        <firstname>Artemiy I.</firstname>\n        <surname>Pavlov</surname>\n      </author> and squashfs's <filename>README</filename> file.\n      Permission is granted to copy, distribute and/or\n      modify this document under the terms of the &gnu; General Public\n      License, Version 2 any later version published by the Free\n      Software Foundation.\n    </para>\n\n    <para>\n      On Debian systems, the complete text of the &gnu;\n      General Public License can be found in\n      <filename>/usr/share/common-licenses/GPL</filename>.\n    </para>\n  </refsect1>\n</refentry>\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/doc/en/unsquashfs.dbk",
    "content": "<?xml version='1.0' encoding='UTF-8'?>\n<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"\n\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\" [\n\n<!--\n\nProcess this file with an XSLT processor: `xsltproc \\\n-''-nonet /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/\\\nmanpages/docbook.xsl manpage.dbk'.  A manual page\n<package>.<section> will be generated.  You may view the\nmanual page with: nroff -man <package>.<section> | less'.  A\ntypical entry in a Makefile or Makefile.am is:\n\nDB2MAN=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh/\\\nmanpages/docbook.xsl\nXP=xsltproc -''-nonet\n\nmanpage.1: manpage.dbk\n        $(XP) $(DB2MAN) $<\n\nThe xsltproc binary is found in the xsltproc package.  The\nXSL files are in docbook-xsl.  Please remember that if you\ncreate the nroff version in one of the debian/rules file\ntargets (such as build), you will need to include xsltproc\nand docbook-xsl in your Build-Depends control field.\n\n-->\n\n  <!-- Fill in your name for FIRSTNAME and SURNAME. -->\n  <!ENTITY dhfirstname \"<firstname>Arnaud</firstname>\">\n  <!ENTITY dhsurname   \"<surname>Fontaine</surname>\">\n\n  <!-- Please adjust the date whenever revising the manpage. -->\n  <!ENTITY dhdate      \"<date>november 02, 2006</date>\">\n\n  <!-- SECTION should be 1-8, maybe w/ subsection other parameters are\n       allowed: see man(7), man(1). -->\n  <!ENTITY dhsection   \"<manvolnum>1</manvolnum>\">\n  <!ENTITY dhemail     \"<email>arnau@debian.org</email>\">\n  <!ENTITY dhusername  \"Arnaud Fontaine\">\n  <!ENTITY dhucpackage \"<refentrytitle>UNSQUASHFS</refentrytitle>\">\n  <!ENTITY dhpackage   \"unsquashfs\">\n\n  <!ENTITY debian      \"<productname>Debian</productname>\">\n  <!ENTITY gnu         \"<acronym>GNU</acronym>\">\n  <!ENTITY gpl         \"&gnu; <acronym>GPL</acronym>\">\n]>\n\n<!-- ====================================================================== -->\n<refentry lang=\"fr\">\n  <refentryinfo>\n    <address>\n      &dhemail;\n    </address>\n    <copyright>\n      <year>2006</year>\n      <holder>&dhusername;</holder>\n    </copyright>\n    &dhdate;\n  </refentryinfo>\n\n  <!-- ============================================================ -->\n  <refmeta>\n    &dhucpackage;\n\n    &dhsection;\n  </refmeta>\n\n  <!-- ============================================================ -->\n  <refnamediv>\n    <refname>&dhpackage;</refname>\n\n    <refpurpose>Decompress and extract a Squash file system</refpurpose>\n  </refnamediv>\n\n  <!-- ============================================================ -->\n  <refsynopsisdiv>\n    <cmdsynopsis>\n      <command>&dhpackage;</command>\n      <arg><option>-v[ersion]</option></arg>\n    </cmdsynopsis>\n\n    <cmdsynopsis>\n      <command>&dhpackage;</command>\n      <arg><option>-l[s] <replaceable>list filesystem only</replaceable></option></arg>\n      <arg><option>-ll[s] <replaceable>list filesystem only with file attributes</replaceable></option></arg>\n    </cmdsynopsis>\n\n    <cmdsynopsis>\n      <command>&dhpackage;</command>\n      <arg choice=\"plain\"><replaceable>filesystem</replaceable></arg>\n      <arg choice=\"plain\"><replaceable>to_extract</replaceable></arg>\n      <arg><option>options</option></arg>\n      <arg><option>-i[nfo]</option></arg>\n      <arg><option>-li[nfo]</option></arg>\n      <arg><option>-d[est] <replaceable>target</replaceable></option></arg>\n      <arg><option>-e[f] <replaceable>extract file</replaceable></option></arg>\n      <arg><option>-r[egex] </option></arg>\n      <arg><option>-f[force] </option></arg>\n    </cmdsynopsis>\n  </refsynopsisdiv>\n\n  <!-- ============================================================ -->\n  <refsect1>\n    <title>DESCRIPTION</title>\n\n    <para>A squashfs is a compressed read-only file system.  Use the\n      <command>&dhpackage;</command> program to decompress and extract\n      a Squash file system without mounting\n      it. <command>&dhpackage;</command> is able to extract the entire\n      file system or a specific file or directory.</para>\n  </refsect1>\n\n  <!-- ============================================================ -->\n  <refsect1>\n    <title>OPTIONS</title>\n\n    <variablelist>\n      <varlistentry>\n        <term>\n          <option>-v[ersion]</option>\n        </term>\n        <listitem>\n          <para>print version, licence and copyright message.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-i[nfo]</option></term>\n        <listitem><para>print files as they are unsquashed.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-li[info]</option></term>\n        <listitem><para>print files as they are unsquashed with file\n        attributes (like ls -l output).</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-l[s]</option></term>\n        <listitem><para>list filesystem only, doesn't decompress anything.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-ll[s]</option></term>\n        <listitem><para>list filesystem only with file attributes,\n        doesn't decompress anything.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-d[est]\n            <replaceable>pathname</replaceable></option></term>\n            <listitem><para>decompress to\n            <replaceable>pathname</replaceable>. This default to\n            <replaceable>squashfs-root</replaceable>.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-f[orce]</option></term>\n        <listitem><para>if file already exists then overwrite.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-s[tat]</option></term>\n        <listitem><para>display filesystem superblock information.</para></listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-e[f]\n            <replaceable>extract file</replaceable></option></term>\n            <listitem><para>list of directories or files to\n            extract. One per line.</para>\n        </listitem>\n      </varlistentry>\n\n      <varlistentry>\n        <term><option>-r[egex]</option></term>\n        <listitem><para>treat extract names as POSIX regular\n        expressions rather than use the default shell wildcard\n        expansion (globbing).</para>\n        </listitem>\n      </varlistentry>\n    </variablelist>\n  </refsect1>\n\n  <!-- ============================================================ -->\n  <refsect1>\n    <title>AUTHORS</title>\n\n    <para>Squashfs was written by <personname>\n        <firstname>Phillip</firstname>\n        <surname>Lougher</surname>\n      </personname>\n      <email>plougher@users.sourceforge.net</email>, in Chepstow,\n      Wales, UK. If you like the program, or have any problems, then\n      please email me, as it's nice to get feedback !</para>\n\n    <para>This manual page was written by &dhusername; &dhemail; for\n      the &debian; system (but may be used by others).  Permission is\n      granted to copy, distribute and/or modify this document under\n      the terms of the &gnu; General Public License, Version 2 any\n      later version published by the Free Software Foundation.\n    </para>\n\n    <para>\n      On Debian systems, the complete text of the &gnu;\n      General Public License can be found in\n      <filename>/usr/share/common-licenses/GPL</filename>.\n    </para>\n  </refsect1>\n</refentry>\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/doc/po/mksquashfs.fr.add",
    "content": "PO4A-HEADER:position=AUTEURS;mode=after;beginboundary=</refsect1>\n\n    <para>Traduction française : &dhusername; &dhemail;.</para>\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/doc/po/mksquashfs.fr.po",
    "content": "# mksquashfs's manpages translation to French\n# Copyright (C) 2005 Free Software Foundation, Inc.\n# Frédéric Boiteux <fboiteux@calistel.com>, 2005.\nmsgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: squashfs\\n\"\n\"POT-Creation-Date: 2008-04-05 09:29-0300\\n\"\n\"PO-Revision-Date: 2007-08-08 17:23+0100\\n\"\n\"Last-Translator: Arnaud Fontaine <arnau@debian.org>\\n\"\n\"Language-Team: \\n\"\n\"MIME-Version: 1.0\\n\"\n\"Content-Type: text/plain; charset=UTF-8\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"\n\n# type: Content of the dhfirstname entity\n#: ../en/mksquashfs.dbk:30\nmsgid \"<firstname>Frédéric</firstname>\"\nmsgstr \"<firstname>Frédéric</firstname>\"\n\n# type: Content of the dhsurname entity\n#: ../en/mksquashfs.dbk:31\nmsgid \"<surname>Boiteux</surname>\"\nmsgstr \"<surname>Boiteux</surname>\"\n\n# type: Content of the dhdate entity\n#: ../en/mksquashfs.dbk:34\nmsgid \"<date>december 20, 2004</date>\"\nmsgstr \"<date>december 20, 2004</date>\"\n\n# type: Content of the dhsection entity\n#: ../en/mksquashfs.dbk:38\nmsgid \"<manvolnum>1</manvolnum>\"\nmsgstr \"<manvolnum>1</manvolnum>\"\n\n# type: Content of the dhemail entity\n#: ../en/mksquashfs.dbk:39\nmsgid \"<email>fboiteux@calistel.com</email>\"\nmsgstr \"<email>fboiteux@calistel.com</email>\"\n\n# type: Content of the dhusername entity\n#: ../en/mksquashfs.dbk:40\nmsgid \"Frédéric Boiteux\"\nmsgstr \"Frédéric Boiteux\"\n\n# type: Content of the dhucpackage entity\n#: ../en/mksquashfs.dbk:41\nmsgid \"<refentrytitle>MKSQUASHFS</refentrytitle>\"\nmsgstr \"<refentrytitle>MKSQUASHFS</refentrytitle>\"\n\n# type: Content of the dhpackage entity\n#: ../en/mksquashfs.dbk:42\nmsgid \"mksquashfs\"\nmsgstr \"mksquashfs\"\n\n# type: Content of the debian entity\n#: ../en/mksquashfs.dbk:44\nmsgid \"<productname>Debian</productname>\"\nmsgstr \"<productname>Debian</productname>\"\n\n# type: Content of the gnu entity\n#: ../en/mksquashfs.dbk:45\nmsgid \"<acronym>GNU</acronym>\"\nmsgstr \"<acronym>GNU</acronym>\"\n\n# type: Content of the gpl entity\n#: ../en/mksquashfs.dbk:46\nmsgid \"&gnu; <acronym>GPL</acronym>\"\nmsgstr \"&gnu; <acronym>GPL</acronym>\"\n\n# type: Attribute 'lang' of: <refentry>\n#: ../en/mksquashfs.dbk:50\nmsgid \"fr\"\nmsgstr \"fr\"\n\n# type: Content of: <refentry><refentryinfo><address>\n#: ../en/mksquashfs.dbk:52\n#, no-wrap\nmsgid \"\"\n\"\\n\"\n\"      &dhemail;\\n\"\n\"    \"\nmsgstr \"\"\n\n# type: Content of: <refentry><refentryinfo><copyright><holder>\n#: ../en/mksquashfs.dbk:61\nmsgid \"&dhusername;\"\nmsgstr \"&dhusername;\"\n\n# type: Content of: <refentry><refnamediv><refname>\n#: ../en/mksquashfs.dbk:75\nmsgid \"&dhpackage;\"\nmsgstr \"&dhpackage;\"\n\n# type: Content of: <refentry><refnamediv><refpurpose>\n#: ../en/mksquashfs.dbk:77\nmsgid \"Create or modify a Squash file system\"\nmsgstr \"\"\n\"Crée ou modifie un système de fichiers compressé <literal>Squash</literal>\"\n\n# type: Content of: <refentry><refsynopsisdiv><cmdsynopsis>\n#: ../en/mksquashfs.dbk:83\nmsgid \"<command>&dhpackage;</command> <arg><option>-version</option></arg>\"\nmsgstr \"<command>&dhpackage;</command> <arg><option>-version</option></arg>\"\n\n# type: Content of: <refentry><refsynopsisdiv><cmdsynopsis>\n#: ../en/mksquashfs.dbk:88\nmsgid \"\"\n\"<command>&dhpackage;</command> <arg choice=\\\"plain\\\" rep=\\\"repeat\"\n\"\\\"><replaceable>source</replaceable></arg> <arg choice=\\\"plain\"\n\"\\\"><replaceable>dest</replaceable></arg> <arg><option>options</option></arg> \"\n\"<arg><option>-e <replaceable>list of exclude dirs/files</replaceable></\"\n\"option></arg> <arg><option>-ef <replaceable>exclude_file</replaceable></\"\n\"option></arg>\"\nmsgstr \"\"\n\"<command>&dhpackage;</command> <arg choice=\\\"plain\\\" rep=\\\"repeat\"\n\"\\\"><replaceable>source</replaceable></arg> <arg choice=\\\"plain\"\n\"\\\"><replaceable>dest</replaceable></arg> <arg><option>options</option></arg> \"\n\"<arg><option>-e <replaceable>list of exclude dirs/files</replaceable></\"\n\"option></arg> <arg><option>-ef <replaceable>exclude_file</replaceable></\"\n\"option></arg>\"\n\n# type: Content of: <refentry><refsect1><title>\n#: ../en/mksquashfs.dbk:101\nmsgid \"DESCRIPTION\"\nmsgstr \"DESCRIPTION\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:103\nmsgid \"\"\n\"A squashfs is a compressed read-only file system. Use the \"\n\"<command>&dhpackage;</command> program to create a new squashed file system, \"\n\"and to append new data to an existing squashed file system.\"\nmsgstr \"\"\n\"Squashfs est un système de fichiers compressé, accessible en lecture \"\n\"seulement. Utilisez la commande <command>&dhpackage;</command> pour créer un \"\n\"nouveau système de fichiers de ce type ou pour ajouter des données à un \"\n\"système existant.\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:108\nmsgid \"\"\n\"If a single source directory is specified (i.e. <userinput>mksquashfs \"\n\"<replaceable>source</replaceable> <replaceable>output_fs</replaceable></\"\n\"userinput>), the squashfs filesystem will consist of that directory, with \"\n\"the top-level root directory corresponding to the source directory.\"\nmsgstr \"\"\n\"Si on ne donne qu'un seul répertoire source (i.e. <userinput>mksquashfs \"\n\"<replaceable>source</replaceable> <replaceable>sf_résultant</replaceable></\"\n\"userinput>), on obtiendra un système de fichiers constitué du contenu de ce \"\n\"répertoire source.\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:115\nmsgid \"\"\n\"If multiple source directories or files are specified, <command>&dhpackage;</\"\n\"command> will merge the specified sources into a single filesystem, with the \"\n\"root directory containing each of the source files/directories.  The name of \"\n\"each directory entry will be the basename of the source path.  If more than \"\n\"one source entry maps to the same name, the conflicts are named \"\n\"<replaceable>xxx</replaceable>_1, <replaceable>xxx</replaceable>_2, etc. \"\n\"where <replaceable>xxx</replaceable> is the original name.\"\nmsgstr \"\"\n\"Si on fournit plusieurs fichier(s) ou répertoire(s)  sources, \"\n\"<command>&dhpackage;</command> créera un seul système de fichiers qui \"\n\"contiendra tous les répertoires et fichiers source. Le nom de chaque \"\n\"répertoire obtenu sera le nom <emphasis>sans chemin d'accès</emphasis> de \"\n\"chaque répertoire source ; En cas de noms identiques, les doublons seront \"\n\"renommés en <replaceable>xxx</replaceable>_1, <replaceable>xxx</\"\n\"replaceable>_2, etc.\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:125\nmsgid \"\"\n\"The <replaceable>dest</replaceable> argument can either be a conventional \"\n\"file or a block device. If the file doesn't exist it will be created, if it \"\n\"does exist and a squashfs filesystem exists on it, <command>&dhpackage;</\"\n\"command> will append.  The <option>-noappend </option>option will write a \"\n\"new filesystem irrespective of whether an existing filesystem is present.\"\nmsgstr \"\"\n\"L'argument <replaceable>dest</replaceable> peut être soit un fichier \"\n\"classique, soit un périphérique de type bloc (comme un disque ou une \"\n\"partition). Si le fichier n'existe pas, il sera créé ; s'il existe déjà et \"\n\"contient un système de fichiers Squashfs, <command>&dhpackage;</command> \"\n\"rajoutera les sources données à son contenu actuel, sauf si l'option \"\n\"<option>-noappend</option> est précisée.\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:133\nmsgid \"\"\n\"There are a large number of options that can be used to control the \"\n\"compression in <command>&dhpackage;</command>.  By and large the defaults \"\n\"are the most optimum settings and should only be changed in exceptional \"\n\"circumstances !\"\nmsgstr \"\"\n\"Il existe un grand nombre d'options qui permettent de contrôler la \"\n\"compression de <command>&dhpackage;</command>. Les valeurs par défaut sont \"\n\"de loin les optimales et ne devraient être modifiées qu'exceptionnellement !\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:138\nmsgid \"\"\n\"The <option>-noI</option>, <option>-noD</option> and <option>-noF</option> \"\n\"options (also <option>-noInodeCompression</option>, <option>-\"\n\"noDataCompression</option> and <option>-noFragmentCompression</option>) can \"\n\"be used to force <command>&dhpackage;</command> to not compress inodes/\"\n\"directories, data and fragments respectively.  Giving all options generates \"\n\"an uncompressed filesystem.\"\nmsgstr \"\"\n\"Les options <option>-noI</option>, <option>-noD</option> et <option>-noF</\"\n\"option> (équivalentes à <option>-noInodeCompression</option>, <option>-\"\n\"noDataCompression</option> et <option>-noFragmentCompression</option>) \"\n\"peuvent être utilisées pour obliger <command>&dhpackage;</command> à ne pas \"\n\"comprimer respectivement les i-noeuds et répertoires, les blocs de données \"\n\"et les blocs de données fragmentés. Si l'on utilise ces trois options, on \"\n\"obtient un système de fichiers non comprimé.\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:148\nmsgid \"\"\n\"By default files in the generated filesystem inherit the UID and GID \"\n\"ownership of the original file.  However, <command>&dhpackage;</command> \"\n\"provides a number of options which can be used to override the ownership:\"\nmsgstr \"\"\n\"Par défaut, les fichiers contenus dans le système de fichiers résultat ont \"\n\"le même propriétaire et groupe que les fichiers sources. Toutefois, \"\n\"<command>&dhpackage;</command> propose certaines options pour modifier ce \"\n\"comportement :\"\n\n# type: Content of: <refentry><refsect1><para><itemizedlist><listitem><simpara>\n#: ../en/mksquashfs.dbk:157\nmsgid \"\"\n\"The options <option>-all-root</option> and <option>-root-owned</option> \"\n\"(both do exactly the same thing) force all file uids/gids in the generated \"\n\"Squashfs filesystem to be <literal>root</literal>.  This allows root owned \"\n\"filesystems to be built without root access on the host machine.\"\nmsgstr \"\"\n\"Les options <option>-all-root</option> et <option>-root-owned</option> \"\n\"(synonymes) forcent tous les fichiers du système de fichiers Squashfs généré \"\n\"à appartenir à <literal>root</literal> (utilisateur et groupe). Elle permet \"\n\"de construire un système de fichiers appartenant à <literal>root</literal> \"\n\"sans avoir un accès à ce compte sur la machine où on le construit.\"\n\n# type: Content of: <refentry><refsect1><para><itemizedlist><listitem><simpara>\n#: ../en/mksquashfs.dbk:164\nmsgid \"\"\n\"The <option>-force-uid <replaceable>uid</replaceable></option> option forces \"\n\"all files in the generated Squashfs filesystem to be owned by the specified \"\n\"<replaceable>uid</replaceable>.  The uid can be specified either by name (i.\"\n\"e. <literal>root</literal>) or by number.\"\nmsgstr \"\"\n\"L'option <option>-force-uid <replaceable>uid</replaceable></option> force \"\n\"tous les fichiers du système de fichiers Squashfs généré à appartenir à \"\n\"l'utilisateur d'identifiant <replaceable>uid</replaceable> donné. Cet \"\n\"identifiant peut être soit un nom (par exemple <literal>root</literal>), \"\n\"soit un nombre.\"\n\n# type: Content of: <refentry><refsect1><para><itemizedlist><listitem><simpara>\n#: ../en/mksquashfs.dbk:172\nmsgid \"\"\n\"The <option>-force-gid <replaceable>gid</replaceable></option> option forces \"\n\"all files in the generated Squashfs filesystem to be group owned by the \"\n\"specified <replaceable>gid</replaceable>.  The gid can be specified either \"\n\"by name (i.e. <literal>root</literal>) or by number.\"\nmsgstr \"\"\n\"L'option <option>-force-gid <replaceable>gid</replaceable></option> force \"\n\"tous les fichiers du système de fichiers Squashfs généré à appartenir au \"\n\"groupe d'identifiant <replaceable>gid</replaceable> donné. Cet identifiant \"\n\"peut être soit un nom (par exemple <literal>root</literal>), soit un nombre.\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:181\nmsgid \"\"\n\"The <option>-e</option> and <option>-ef</option> options allow files/\"\n\"directories to be specified which are excluded from the output filesystem.  \"\n\"The <option>-e</option> option takes the exclude files/directories from the \"\n\"command line, the <option>-ef</option> option takes the exlude files/\"\n\"directories from the specified exclude file, one file/directory per line. If \"\n\"an exclude file/directory is absolute (i.e. prefixed with <filename>/</\"\n\"filename>, <filename>../</filename>, or <filename>./</filename>) the entry \"\n\"is treated as absolute, however, if an exclude file/directory is relative, \"\n\"it is treated as being relative to each of the sources in turn, i.e.  \"\n\"<userinput>mksquashfs /tmp/source1 source2 output_fs -e ex1 /tmp/source1/ex2 \"\n\"out/ex3</userinput> Will generate exclude files <filename>/tmp/source1/ex2</\"\n\"filename>, <filename>/tmp/source1/ex1</filename>, <filename>source2/ex1</\"\n\"filename>, <filename>/tmp/source1/out/ex3</filename> and <filename>source2/\"\n\"out/ex3</filename>.\"\nmsgstr \"\"\n\"Les options <option>-e</option> et <option>-ef</option> permettent de \"\n\"déclarer des fichiers ou répertoires à exclure du système de fichiers \"\n\"résultat. L'option <option>-e</option> lit les fichiers/répertoires à \"\n\"exclure sur la ligne de commande, tandis que l'option <option>-ef</option> \"\n\"les trouve dans le fichier d'exclusions spécifié contenant un fichier ou \"\n\"répertoire par ligne. Si le chemin d'un fichier ou répertoire à exclure est \"\n\"absolu (c'est-à-dire débutant par <filename>/</filename>, <filename>../</\"\n\"filename> ou <filename>./</filename>), il est considéré indépendamment des \"\n\"sources ; en revanche, s'il est relatif, il s'appliquera pour chaque \"\n\"répertoire source ; par exemple, <userinput>mksquashfs /tmp/source1 source2 \"\n\"sf_résultant -e ex1 /tmp/source1/ex2 out/ex3</userinput> exclura les \"\n\"fichiers <filename>/tmp/source1/ex2</filename>, <filename>/tmp/source1/ex1</\"\n\"filename>, <filename>source2/ex1</filename>, <filename>/tmp/source1/out/ex3</\"\n\"filename> et <filename>source2/out/ex3</filename>.\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:201\nmsgid \"\"\n\"The <option>-e</option> and <option>-ef</option> exclude options are \"\n\"usefully used in archiving the entire filesystem, where it is wished to \"\n\"avoid archiving <filename>/proc</filename>, and the filesystem being \"\n\"generated, i.e.  <userinput>mksquashfs / /tmp/root.sqsh -e proc /tmp/root.\"\n\"sqsh</userinput>\"\nmsgstr \"\"\n\"Ces options <option>-e</option> et <option>-ef</option> sont pratiques pour, \"\n\"par exemple, archiver un système de fichier complet en évitant le répertoire \"\n\"<filename>/proc</filename> et le système de fichiers résultat : \"\n\"<userinput>mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh</userinput>\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:208\nmsgid \"\"\n\"Multiple <option>-ef</option> options can be specified on the command line, \"\n\"and the <option>-ef</option> option can be used in conjuction with the \"\n\"<option>-e</option> option.\"\nmsgstr \"\"\n\"On peut utiliser plusieurs fois l'option <option>-ef</option> dans une même \"\n\"commande, et on peut également l'utiliser en même temps que l'option \"\n\"<option>-e</option>.\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:213\nmsgid \"\"\n\"The <option>-info</option> option displays the files/directories as they are \"\n\"compressed and added to the filesystem.  The original uncompressed size of \"\n\"each file is printed, along with <literal>DUPLICATE</literal> if the file is \"\n\"a duplicate of a file in the filesystem.\"\nmsgstr \"\"\n\"L'option <option>-info</option> affiche les fichiers et répertoires ajoutés \"\n\"au système de fichiers, avec leur taille originelle et éventuellement le mot \"\n\"<literal>DUPLICATE</literal> si un fichier avec un contenu identique y est \"\n\"déjà présent.\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:219\nmsgid \"\"\n\"The <option>-no-exports</option> option doesn't make the filesystem \"\n\"exportable via NFS.\"\nmsgstr \"\"\n\"L'option <option>-no-exports</option> permet d'éviter le partage du système \"\n\"de fichiers par NFS\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:222\nmsgid \"\"\n\"The <option>-no-progress</option> option doesn't display the progress bar.\"\nmsgstr \"\"\n\"L'option <option>-no-progress</option> n'affiche pas la barre de progression\"\n\n# type: Content of: <refentry><refsect1><simpara>\n#: ../en/mksquashfs.dbk:225\nmsgid \"\"\n\"The <option>-le</option> and <option>-be</option> options can be used to \"\n\"force <command>&dhpackage;</command> to generate a little endian or big \"\n\"endian filesystem.  Normally <command>&dhpackage;</command> will generate a \"\n\"filesystem in the host byte order.  Squashfs, for portability, will mount \"\n\"different ordered filesystems (i.e. it can mount big endian filesystems \"\n\"running on a little endian machine), but these options can be used for \"\n\"greater optimisation.\"\nmsgstr \"\"\n\"Les options <option>-le</option> et <option>-be</option> peuvent servir à \"\n\"forcer <command>&dhpackage;</command> à générer un système de fichiers \"\n\"<foreignphrase>little endian</foreignphrase> ou <foreignphrase>big endian</\"\n\"foreignphrase>. Par défaut, <command>&dhpackage;</command> génère un système \"\n\"de fichiers avec le boutisme de la machine hôte. Le pilote Squashfs \"\n\"permettant, par souci de portabilité, de monter les deux types de systèmes \"\n\"de fichiers (c'est-à-dire qu'il peut monter un système <foreignphrase>big \"\n\"endian</foreignphrase> sur une machine <foreignphrase>little endian</\"\n\"foreignphrase>), ces options peuvent servir à améliorer l'efficacité d'un \"\n\"système de fichiers généré pour une architecture différente.\"\n\n# type: Content of: <refentry><refsect1><title>\n#: ../en/mksquashfs.dbk:237\nmsgid \"OPTIONS\"\nmsgstr \"OPTIONS\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:242\nmsgid \"<option>-version</option>\"\nmsgstr \"<option>-version</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:245\nmsgid \"print version, licence and copyright message.\"\nmsgstr \"affiche la version, la licence et un message de copyright.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:250\nmsgid \"<option>-recover <replaceable>name</replaceable></option>\"\nmsgstr \"<option>-recover <replaceable>nom</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:253\nmsgid \"\"\n\"Allows the original filesystem to be recovered if Mksquashfs aborts \"\n\"unexpectedly (i.e.  power failure)  using recovery file <replaceable>name</\"\n\"replaceable>.  Recovery files are now created when appending to existing \"\n\"Squashfs filesystems.\"\nmsgstr \"\"\n\"Permet au système de fichier original d'être restauré si Mksquashfs se \"\n\"termine de façon inattendu (par exemple alimentation défaillante) en \"\n\"utilisant le fichier de restauration <replaceable>nom</replaceable>. Les \"\n\"fichiers de restauration sont désormais créés lors de l'ajout à un système \"\n\"de fichier Squashfs existant.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:262\nmsgid \"<option>-no-recovery</option>\"\nmsgstr \"<option>-no-recovery</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:263\nmsgid \"don't generate a recovery file\"\nmsgstr \"ne pas générer un fichier de restauration\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:268\nmsgid \"<option>-info</option>\"\nmsgstr \"<option>-info</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:269\nmsgid \"print files written to filesystem\"\nmsgstr \"affiche les fichiers ajoutés au système de fichiers.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:274\nmsgid \"<option>-no-exports</option>\"\nmsgstr \"<option>-no-exports</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:275\nmsgid \"don't make the filesystem exportable via NFS\"\nmsgstr \"permet d'éviter le partage du système de fichier par NFS\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:281\nmsgid \"<option>-no-progress</option>\"\nmsgstr \"<option>-no-progress</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:282\nmsgid \"don't display the progress bar\"\nmsgstr \"n'affiche pas la barre de progression\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:287\nmsgid \"<option>-no-sparse</option>\"\nmsgstr \"<option>-no-sparse</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:288\nmsgid \"don't detect sparse files\"\nmsgstr \"ne pas détecter les fichiers vides\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:293\nmsgid \"<option>-b <replaceable>block_size</replaceable></option>\"\nmsgstr \"<option>-b <replaceable>taille_bloc</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:295\nmsgid \"\"\n\"set data block to <replaceable>block_size</replaceable>. Default is 131072 \"\n\"bytes\"\nmsgstr \"\"\n\"fixe la taille des blocs de données à <replaceable>block_size</replaceable>. \"\n\"Par défaut, elle vaut 65536 octets.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:302\nmsgid \"<option>-processors <replaceable>number</replaceable></option>\"\nmsgstr \"<option>-processors <replaceable>nombre</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:304\nmsgid \"\"\n\"Use <replaceable>number</replaceable> processors.  By default will use \"\n\"number of processors available\"\nmsgstr \"\"\n\"Utilise <replaceable>nombre</replaceable> processeurs. Utilise par défaut le \"\n\"nombre de processeurs disponibles\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:311\nmsgid \"<option>-read-queue <replaceable>size</replaceable></option>\"\nmsgstr \"<option>-read-queue <replaceable>taille</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:313\nmsgid \"\"\n\"Set input queue to <replaceable>size</replaceable> Mbytes. Default 64 Mbytes.\"\nmsgstr \"\"\n\"Initialise la file d'entrée à <replaceable>taille</replaceable> Mo. La \"\n\"valeur par défaut est 64Mo.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:320\nmsgid \"<option>-write-queue <replaceable>size</replaceable></option>\"\nmsgstr \"<option>-write-queue <replaceable>taille</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:322\nmsgid \"\"\n\"Set output queue to <replaceable>size</replaceable> Mbytes. Default 512 \"\n\"Mbytes.\"\nmsgstr \"\"\n\"Initialise la file de sortie à <replaceable>taille</replaceable> Mo. La \"\n\"valeur par défaut est 512Mo.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:329\nmsgid \"<option>-noI</option> or <option>-noInodeCompression</option>\"\nmsgstr \"<option>-noI</option> ou <option>-noInodeCompression</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:331\nmsgid \"do not compress inode table\"\nmsgstr \"ne comprime pas la table des i-noeuds.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:336\nmsgid \"<option>-noD</option>or <option>-noDataCompression</option>\"\nmsgstr \"<option>-noD</option> ou <option>-noDataCompression</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:338\nmsgid \"do not compress data blocks\"\nmsgstr \"ne comprime pas les blocs de données.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:343\nmsgid \"<option>-noF</option> or <option>-noFragmentCompression</option>\"\nmsgstr \"<option>-noF</option> ou <option>-noFragmentCompression</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:345\nmsgid \"do not compress fragment blocks\"\nmsgstr \"ne comprime pas les blocs fragmentés.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:350\nmsgid \"<option>-no-fragments</option>\"\nmsgstr \"<option>-no-fragments</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:351\nmsgid \"\"\n\"do not use fragments: tells <command>&dhpackage;</command> to not generate \"\n\"fragment blocks, and rather generate a filesystem similar to a Squashfs 1.x \"\n\"filesystem. It will of course still be a Squashfs 2.0 filesystem but without \"\n\"fragments, and so it won't be mountable on a Squashfs 1.x system.\"\nmsgstr \"\"\n\"n'utilise pas de blocs fragmentés : indique à <command>&dhpackage;</command> \"\n\"de ne pas créer de blocs fragmentés, mais plutôt un système de fichiers du \"\n\"même genre que ceux des versions 1.x de Squashfs. Ce sera quand même un \"\n\"système de fichiers Squashfs 2.0 (mais sans fragments), donc il ne pourra \"\n\"être monté par un système Squashfs en version 1.x.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:361\nmsgid \"<option>-always-use-fragments</option>\"\nmsgstr \"<option>-always-use-fragments</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:362\nmsgid \"\"\n\"use fragment blocks for files larger than block size: tells \"\n\"<command>&dhpackage;</command> to always generate fragments for files \"\n\"irrespective of the file length.  By default only small files less than the \"\n\"block size are packed into fragment blocks.  The ends of files which do not \"\n\"fit fully into a block, are <emphasis>NOT</emphasis> by default packed into \"\n\"fragments.  To illustrate this, a 100K file has an initial 64K block and a \"\n\"36K remainder.  This 36K remainder is not packed into a fragment by \"\n\"default.  This is because to do so leads to a 10 - 20% drop in sequential I/\"\n\"O performance, as a disk head seek is needed to seek to the initial file \"\n\"data and another disk seek is need to seek to the fragment block. Specify \"\n\"this option if you want file remainders to be packed into fragment blocks. \"\n\"Doing so may increase the compression obtained <emphasis>BUT</emphasis> at \"\n\"the expense of I/O speed.\"\nmsgstr \"\"\n\"utilise des blocs fragmentés pour les fichiers plus gros que la taille d'un \"\n\"bloc : indique à <command>&dhpackage;</command> d'utiliser des blocs \"\n\"fragmentés quelle que soit la longueur des fichiers. Par défaut, seuls les \"\n\"petits fichiers (dont la taille est inférieure à celle d'un bloc) sont \"\n\"assemblés dans des blocs fragmentés. La fin des fichiers qui remplisse plus \"\n\"d'un bloc ne sont <emphasis>pas</emphasis>, par défaut, assemblés dans des \"\n\"fragments.  Par exemple, un fichier de 100 ko est découpé en un bloc de \"\n\"64 ko et un reste de 36 ko, qui par défaut n'est pas placé dans un bloc \"\n\"fragmenté. Ce choix est fait pour éviter une perte de performance de 10 à \"\n\"20% en accès séquentiel à ce genre de fichiers, car il faudrait sinon \"\n\"déplacer la tête de lecture d'un disque pour accéder au(x) bloc(s) entier(s) \"\n\"et un autre pour le fragment (qui ne sera sans doute pas consécutif). \"\n\"Utilisez cette option pour forcer ces fins de fichiers à être rassemblées \"\n\"dans les blocs fragmentés ; cela améliore le taux de compression obtenu \"\n\"<emphasis>mais</emphasis> au dépens de la vitesse d'accès.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:384\nmsgid \"<option>-no-duplicates</option>\"\nmsgstr \"<option>-no-duplicates</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:385\nmsgid \"\"\n\"do not perform duplicate checking: tells <command>&dhpackage;</command> to \"\n\"not check the files being added to the filesystem for duplicates.  This can \"\n\"result in quicker filesystem generation and appending although obviously \"\n\"compression will suffer badly if there is a lot of duplicate files.\"\nmsgstr \"\"\n\"ne vérifie pas s'il y a des doublons : indique à <command>&dhpackage;</\"\n\"command> de ne pas vérifier dans les fichiers ajoutés s'il y en a avec des \"\n\"contenus identiques. Ceci permet une génération/modification du système de \"\n\"fichiers résultant plus rapide, mais bien sûr le taux de compression sera \"\n\"nettement moins bon s'il y a beaucoup de fichiers aux contenus identiques.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:395\nmsgid \"<option>-noappend</option>\"\nmsgstr \"<option>-noappend</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:396\nmsgid \"do not append to existing filesystem\"\nmsgstr \"ne pas ajouter en fin d'un système de fichiers existant.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:402\nmsgid \"<option>-keep-as-directory</option>\"\nmsgstr \"<option>-keep-as-directory</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:403\nmsgid \"\"\n\"if one source directory is specified, create a root directory containing \"\n\"that directory, rather than the contents of the directory\"\nmsgstr \"\"\n\"si un répertoire source est donné, crée un système de fichiers contenant ce \"\n\"répertoire plutôt que simplement son contenu.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:410\nmsgid \"<option>-root-becomes <replaceable>name</replaceable></option>\"\nmsgstr \"<option>-root-becomes <replaceable>nom</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:412\nmsgid \"\"\n\"when appending source files/directories, make the original root become a \"\n\"subdirectory in the new root called <replaceable>name</replaceable>, rather \"\n\"than adding the new source items to the original root\"\nmsgstr \"\"\n\"lorsqu'on ajoute des fichiers ou répertoires à un système existant, le \"\n\"contenu de l'ancien système sera placé dans un répertoire de \"\n\"<replaceable>nom</replaceable> donné, plutôt que de mélanger les anciens \"\n\"fichiers et les nouveaux.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:420\nmsgid \"<option>-all-root</option> or <option>-root-owned</option>\"\nmsgstr \"<option>-all-root</option> ou <option>-root-owned</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:422\nmsgid \"make all files owned by root\"\nmsgstr \"\"\n\"tous les fichiers ajoutés au système appartiendront à <literal>root</\"\n\"literal>.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:427\nmsgid \"<option>-force-uid <replaceable>uid</replaceable></option>\"\nmsgstr \"<option>-force-uid <replaceable>uid</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:429\nmsgid \"set all file uids to <replaceable>uid</replaceable>\"\nmsgstr \"\"\n\"tous les fichiers ajoutés au système appartiendront à l'utilisateur \"\n\"d'identifiant <replaceable>uid</replaceable> (un nom ou un nombre).\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:435\nmsgid \"<option>-force-gid <replaceable>gid</replaceable></option>\"\nmsgstr \"<option>-force-gid <replaceable>gid</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:437\nmsgid \"set all file gids to <replaceable>gid</replaceable>\"\nmsgstr \"\"\n\"tous les fichiers ajoutés au système appartiendront au groupe d'identifiant \"\n\"<replaceable>gid</replaceable> (un nom ou un nombre).\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:443\nmsgid \"<option>-le</option>\"\nmsgstr \"<option>-le</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:444\nmsgid \"create a little endian filesystem\"\nmsgstr \"\"\n\"crée un système de fichiers au format petit boutiens (<foreignphrase>little \"\n\"endian</foreignphrase> en anglais).\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:449\nmsgid \"<option>-be</option>\"\nmsgstr \"<option>-be</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:450\nmsgid \"create a big endian filesystem\"\nmsgstr \"\"\n\"crée un système de fichiers au format gros boutiens (<foreignphrase>big \"\n\"endian</foreignphrase> en anglais).\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:455\nmsgid \"<option>-nopad</option>\"\nmsgstr \"<option>-nopad</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:456\nmsgid \"\"\n\"do not pad filesystem to a multiple of 4Ko.  This is performed by default to \"\n\"enable the output filesystem file to be mounted by loopback, which requires \"\n\"files to be a 4K multiple.  If the filesystem is being written to a block \"\n\"device, or is to be stored in a bootimage, the extra pad bytes are not \"\n\"needed.\"\nmsgstr \"\"\n\"Ne pas arrondir le système de fichiers au multiple de 4 ko [supérieur] : cet \"\n\"arrondi, effectué par défaut, permet au système de fichiers d'être monté par \"\n\"l'interface <literal>loopback</literal> qui ne fonctionne qu'avec des \"\n\"fichiers multiples de 4 ko. Si le système de fichiers est destiné à être \"\n\"écrit sur un périphérique de type bloc (un disque ou une partition par \"\n\"exemple) ou être placé dans une image de démarrage, cet arrondi est inutile.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:466\nmsgid \"<option>-check_data</option>\"\nmsgstr \"<option>-check_data</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:467\nmsgid \"add checkdata for greater filesystem checks\"\nmsgstr \"\"\n\"positionne un drapeau dans le système de fichiers créé pour plus de \"\n\"vérifications de ce système lorsqu'il est monté.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:473\nmsgid \"<option>-sort <replaceable>sort_file</replaceable></option>\"\nmsgstr \"<option>-sort <replaceable>ordre</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:475\nmsgid \"\"\n\"sort files according to priorities in <replaceable>sort_file</replaceable>.  \"\n\"One file or dir with priority per line.  Priority -32768 to 32767, default \"\n\"priority 0\"\nmsgstr \"\"\n\"trie les fichiers suivant les priorités décrites dans le fichier \"\n\"<replaceable>ordre</replaceable>, qui doit contenir un nom de fichier ou \"\n\"répertoire par ligne avec sa priorité associée (nombre entre -32768 et \"\n\"32767, 0 par défaut).\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:483\nmsgid \"\"\n\"<option>-e <replaceable>list of exclude dirs/files</replaceable></option>\"\nmsgstr \"\"\n\"<option>-e <replaceable>liste des répertoires/fichiers exclus</replaceable></\"\n\"option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:485\nmsgid \"inline list of files / directories to exclude\"\nmsgstr \"liste (en ligne) des fichiers et répertoires à exclure.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:491\nmsgid \"<option>-ef <replaceable>exclude_file</replaceable></option>\"\nmsgstr \"<option>-ef <replaceable>fichier_exclus</replaceable></option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><simpara>\n#: ../en/mksquashfs.dbk:493\nmsgid \"file containing a list of files / directories to exclude, one per line\"\nmsgstr \"\"\n\"le fichier <replaceable>fichier_exclus</replaceable> contient la liste des \"\n\"fichiers ou répertoires à exclure, un par ligne.\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:499\nmsgid \"<option>-wildcards</option>\"\nmsgstr \"<option>-wildcards</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:500\nmsgid \"\"\n\"Allow extended shell wildcards (globbing) to be used in exclude dirs/files\"\nmsgstr \"\"\n\"Permet l'utilisation des caractères spéciaux de l'interpréteur de commande \"\n\"afin d'exclure des répertoires ou fichiers\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:505\nmsgid \"<option>-regex</option>\"\nmsgstr \"<option>-regex</option>\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:506\nmsgid \"Allow POSIX regular expressions to be used in exclude dirs/files\"\nmsgstr \"\"\n\"Permet l'utilisation des expressions rationnelle POSIX pour l'exclusion de \"\n\"fichiers ou répertoires\"\n\n# type: Content of: <refentry><refsect1><title>\n#: ../en/mksquashfs.dbk:514\nmsgid \"EXAMPLES\"\nmsgstr \"EXEMPLES\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:516\nmsgid \"For following examples, take two example directories:\"\nmsgstr \"Pour les exemples suivants, on utilise deux répertoires :\"\n\n# type: Content of: <refentry><refsect1><para><itemizedlist><listitem><simpara>\n#: ../en/mksquashfs.dbk:519\nmsgid \"\"\n\"Source directory <filename>/home/phillip/test</filename> contains \"\n\"<filename>file1</filename>, <filename>file2</filename> and <filename>dir1</\"\n\"filename>.\"\nmsgstr \"\"\n\"le répertoire source <filename>/home/phillip/test</filename> contient \"\n\"<filename>fichier1</filename>, <filename>fichier2</filename> et \"\n\"<filename>rep1</filename>.\"\n\n# type: Content of: <refentry><refsect1><para><itemizedlist><listitem><simpara>\n#: ../en/mksquashfs.dbk:525\nmsgid \"\"\n\"Source directory <filename>goodies</filename> contains <filename>goodies1</\"\n\"filename>, <filename>goodies2</filename> and <filename>goodies3</filename>.\"\nmsgstr \"\"\n\"le répertoire source <filename>outils</filename> contient <filename>outils1</\"\n\"filename>, <filename>outils2</filename> et <filename>outils3</filename>.\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><screen>\n#: ../en/mksquashfs.dbk:537\n#, no-wrap\nmsgid \"<userinput>mksquashfs /home/phillip/test output_fs</userinput>\"\nmsgstr \"<userinput>mksquashfs /home/phillip/test sf_resultat</userinput>\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><simpara>\n#: ../en/mksquashfs.dbk:538\nmsgid \"\"\n\"This will generate a squashfs filesystem with root entries <filename>file1</\"\n\"filename>, <filename>file2</filename> and <filename>dir1</filename>.\"\nmsgstr \"\"\n\"va créer un système de fichiers Squashfs contenant dans sa racine les items \"\n\"<filename>fichier1</filename>, <filename>fichier2</filename> et \"\n\"<filename>rep1</filename>.\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><screen>\n#: ../en/mksquashfs.dbk:547\n#, no-wrap\nmsgid \"<userinput>mksquashfs /home/phillip/test goodies output_fs</userinput>\"\nmsgstr \"<userinput>mksquashfs /home/phillip/test outils sf_resultat</userinput>\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><simpara>\n#: ../en/mksquashfs.dbk:548\nmsgid \"\"\n\"This will create a squashfs filesystem with the root containing entries \"\n\"<filename>test</filename> and <filename>goodies</filename> corresponding to \"\n\"the source directories <filename>/home/phillip/test</filename> and \"\n\"<filename>goodies</filename>.\"\nmsgstr \"\"\n\"va créer un système de fichiers Squashfs contenant dans sa racine les \"\n\"répertoires <filename>test</filename> et <filename>outils</filename>, \"\n\"correspondant aux répertoires source <filename>/home/phillip/test</filename> \"\n\"et <filename>outils</filename>.\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><screen>\n#: ../en/mksquashfs.dbk:559\n#, no-wrap\nmsgid \"<userinput>mksquashfs /home/phillip/test goodies test output_fs</userinput>\"\nmsgstr \"<userinput>mksquashfs /home/phillip/test outils test sf_resultat</userinput>\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><simpara>\n#: ../en/mksquashfs.dbk:561\nmsgid \"\"\n\"This is the same as the previous example, except a third source directory \"\n\"<filename>test</filename> has been specified. This conflicts with the first \"\n\"directory named <filename>test</filename> and will be renamed \"\n\"<filename>test_1</filename>.\"\nmsgstr \"\"\n\"commande identique à l'exemple précédent, sauf qu'un troisième répertoire \"\n\"source <filename>test</filename> a été donné, d'où un conflit avec le \"\n\"premier répertoire <filename>test</filename>. Ce troisième répertoire sera \"\n\"donc renommé <filename>test_1</filename>.\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><simpara>\n#: ../en/mksquashfs.dbk:566\nmsgid \"\"\n\"Multiple sources allow filesystems to be generated without needing to copy \"\n\"all source files into a common directory.  This simplifies creating \"\n\"filesystems.\"\nmsgstr \"\"\n\"Donner plusieurs répertoires source permet de générer des systèmes de \"\n\"fichiers sans préalablement copier tous les fichiers nécessaires dans un \"\n\"répertoire commun, ce qui simplifie le processus.\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><screen>\n#: ../en/mksquashfs.dbk:575\n#, no-wrap\nmsgid \"<userinput>mksquashfs /home/phillip/test output_fs -keep-as-directory</userinput>\"\nmsgstr \"<userinput>mksquashfs /home/phillip/test sf_resultat -keep-as-directory</userinput>\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><simpara>\n#: ../en/mksquashfs.dbk:577\nmsgid \"\"\n\"This is the same as the first example, except for <option>-keep-as-\"\n\"directory</option>. This will generate a root directory containing directory \"\n\"<filename>test</filename>, rather than the <filename>test</filename> \"\n\"directory contents <filename>file1</filename>, <filename>file2</filename> \"\n\"and <filename>dir1</filename>.\"\nmsgstr \"\"\n\"commande identique au premier exemple, sauf que l'option <option>-keep-as-\"\n\"directory</option> va donner un système de fichiers dont la racine \"\n\"contiendra un répertoire <filename>test</filename>, au lieu de n'avoir que \"\n\"son contenu <filename>fichier1</filename>, <filename>fichier2</filename> et \"\n\"<filename>rep1</filename>.\"\n\n# type: Content of: <refentry><refsect1><title>\n#: ../en/mksquashfs.dbk:590\nmsgid \"AUTHORS\"\nmsgstr \"AUTEURS\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:592\nmsgid \"\"\n\"Squashfs was written by <personname> <firstname>Phillip</firstname> \"\n\"<surname>Lougher</surname> </personname> <email>plougher@users.sourceforge.\"\n\"net</email>, in Chepstow, Wales, UK. If you like the program, or have any \"\n\"problems, then please email me, as it's nice to get feedback !\"\nmsgstr \"\"\n\"Squashfs a été écrit par <personname> <firstname>Phillip</firstname> \"\n\"<surname>Lougher</surname> </personname> <email>plougher@users.sourceforge.\"\n\"net</email>, à Chepstow, Pays de Galles, Royaume-Uni. Si vous appréciez ce \"\n\"programme ou rencontrez des problèmes en l'utilisant, contactez-le, il est \"\n\"intéressé par des retours d'expérience.\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:600\nmsgid \"\"\n\"This manual page was written by &dhusername; &dhemail; for the &debian; \"\n\"system (but may be used by others) using the <citetitle>SquashFS HOWTO</\"\n\"citetitle> from <author> <firstname>Artemiy I.</firstname> <surname>Pavlov</\"\n\"surname> </author> and squashfs's <filename>README</filename> file.  \"\n\"Permission is granted to copy, distribute and/or modify this document under \"\n\"the terms of the &gnu; General Public License, Version 2 any later version \"\n\"published by the Free Software Foundation.\"\nmsgstr \"\"\n\"Cette page de manuel a été écrit par &dhusername; &dhemail; pour le système \"\n\"&debian; (mais peut être utilisé par d'autres) à partir du document \"\n\"<citetitle>SquashFS HOWTO</citetitle> de <author> <firstname>Artemiy I.</\"\n\"firstname> <surname>Pavlov</surname> </author> et du fichier \"\n\"<filename>README</filename> des sources de SquashFS. Il est permis de \"\n\"copier, distribuer et/ou modifier ce document en vertu de la licence GPL \"\n\"version 2 ou postérieure, telle que publiée par la Free Software Foundation.\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:613\nmsgid \"\"\n\"On Debian systems, the complete text of the &gnu; General Public License can \"\n\"be found in <filename>/usr/share/common-licenses/GPL</filename>.\"\nmsgstr \"\"\n\"Sur les systèmes Debian, le texte complet de la licence &gpl; (Licence \"\n\"Public Générale &gnu;) se trouve dans le fichier <filename>/usr/share/common-\"\n\"licenses/GPL</filename>.\"\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/doc/po/mksquashfs.pot",
    "content": "# SOME DESCRIPTIVE TITLE\n# Copyright (C) YEAR Free Software Foundation, Inc.\n# This file is distributed under the same license as the PACKAGE package.\n# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n#\n#, fuzzy\nmsgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"POT-Creation-Date: 2008-04-05 09:29-0300\\n\"\n\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n\"MIME-Version: 1.0\\n\"\n\"Content-Type: text/plain; charset=utf-8\\n\"\n\"Content-Transfer-Encoding: ENCODING\"\n\n# type: Content of the dhfirstname entity\n#: ../en/mksquashfs.dbk:30\nmsgid \"<firstname>Frédéric</firstname>\"\nmsgstr \"\"\n\n# type: Content of the dhsurname entity\n#: ../en/mksquashfs.dbk:31\nmsgid \"<surname>Boiteux</surname>\"\nmsgstr \"\"\n\n# type: Content of the dhdate entity\n#: ../en/mksquashfs.dbk:34\nmsgid \"<date>december 20, 2004</date>\"\nmsgstr \"\"\n\n# type: Content of the dhsection entity\n#: ../en/mksquashfs.dbk:38\nmsgid \"<manvolnum>1</manvolnum>\"\nmsgstr \"\"\n\n# type: Content of the dhemail entity\n#: ../en/mksquashfs.dbk:39\nmsgid \"<email>fboiteux@calistel.com</email>\"\nmsgstr \"\"\n\n# type: Content of the dhusername entity\n#: ../en/mksquashfs.dbk:40\nmsgid \"Frédéric Boiteux\"\nmsgstr \"\"\n\n# type: Content of the dhucpackage entity\n#: ../en/mksquashfs.dbk:41\nmsgid \"<refentrytitle>MKSQUASHFS</refentrytitle>\"\nmsgstr \"\"\n\n# type: Content of the dhpackage entity\n#: ../en/mksquashfs.dbk:42\nmsgid \"mksquashfs\"\nmsgstr \"\"\n\n# type: Content of the debian entity\n#: ../en/mksquashfs.dbk:44\nmsgid \"<productname>Debian</productname>\"\nmsgstr \"\"\n\n# type: Content of the gnu entity\n#: ../en/mksquashfs.dbk:45\nmsgid \"<acronym>GNU</acronym>\"\nmsgstr \"\"\n\n# type: Content of the gpl entity\n#: ../en/mksquashfs.dbk:46\nmsgid \"&gnu; <acronym>GPL</acronym>\"\nmsgstr \"\"\n\n# type: Attribute 'lang' of: <refentry>\n#: ../en/mksquashfs.dbk:50\nmsgid \"fr\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refentryinfo><address>\n#: ../en/mksquashfs.dbk:52\n#, no-wrap\nmsgid \"\"\n\"\\n\"\n\"      &dhemail;\\n\"\n\"    \"\nmsgstr \"\"\n\n# type: Content of: <refentry><refentryinfo><copyright><holder>\n#: ../en/mksquashfs.dbk:61\nmsgid \"&dhusername;\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refnamediv><refname>\n#: ../en/mksquashfs.dbk:75\nmsgid \"&dhpackage;\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refnamediv><refpurpose>\n#: ../en/mksquashfs.dbk:77\nmsgid \"Create or modify a Squash file system\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsynopsisdiv><cmdsynopsis>\n#: ../en/mksquashfs.dbk:83\nmsgid \"<command>&dhpackage;</command> <arg><option>-version</option></arg>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsynopsisdiv><cmdsynopsis>\n#: ../en/mksquashfs.dbk:88\nmsgid \"\"\n\"<command>&dhpackage;</command> <arg choice=\\\"plain\\\" \"\n\"rep=\\\"repeat\\\"><replaceable>source</replaceable></arg> <arg \"\n\"choice=\\\"plain\\\"><replaceable>dest</replaceable></arg> \"\n\"<arg><option>options</option></arg> <arg><option>-e <replaceable>list of \"\n\"exclude dirs/files</replaceable></option></arg> <arg><option>-ef \"\n\"<replaceable>exclude_file</replaceable></option></arg>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><title>\n#: ../en/mksquashfs.dbk:101\nmsgid \"DESCRIPTION\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:103\nmsgid \"\"\n\"A squashfs is a compressed read-only file system. Use the \"\n\"<command>&dhpackage;</command> program to create a new squashed file system, \"\n\"and to append new data to an existing squashed file system.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:108\nmsgid \"\"\n\"If a single source directory is specified (i.e. <userinput>mksquashfs \"\n\"<replaceable>source</replaceable> \"\n\"<replaceable>output_fs</replaceable></userinput>), the squashfs filesystem \"\n\"will consist of that directory, with the top-level root directory \"\n\"corresponding to the source directory.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:115\nmsgid \"\"\n\"If multiple source directories or files are specified, \"\n\"<command>&dhpackage;</command> will merge the specified sources into a \"\n\"single filesystem, with the root directory containing each of the source \"\n\"files/directories.  The name of each directory entry will be the basename of \"\n\"the source path.  If more than one source entry maps to the same name, the \"\n\"conflicts are named <replaceable>xxx</replaceable>_1, \"\n\"<replaceable>xxx</replaceable>_2, etc. where <replaceable>xxx</replaceable> \"\n\"is the original name.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:125\nmsgid \"\"\n\"The <replaceable>dest</replaceable> argument can either be a conventional \"\n\"file or a block device. If the file doesn't exist it will be created, if it \"\n\"does exist and a squashfs filesystem exists on it, \"\n\"<command>&dhpackage;</command> will append.  The <option>-noappend \"\n\"</option>option will write a new filesystem irrespective of whether an \"\n\"existing filesystem is present.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:133\nmsgid \"\"\n\"There are a large number of options that can be used to control the \"\n\"compression in <command>&dhpackage;</command>.  By and large the defaults \"\n\"are the most optimum settings and should only be changed in exceptional \"\n\"circumstances !\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:138\nmsgid \"\"\n\"The <option>-noI</option>, <option>-noD</option> and <option>-noF</option> \"\n\"options (also <option>-noInodeCompression</option>, \"\n\"<option>-noDataCompression</option> and \"\n\"<option>-noFragmentCompression</option>) can be used to force \"\n\"<command>&dhpackage;</command> to not compress inodes/directories, data and \"\n\"fragments respectively.  Giving all options generates an uncompressed \"\n\"filesystem.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:148\nmsgid \"\"\n\"By default files in the generated filesystem inherit the UID and GID \"\n\"ownership of the original file.  However, <command>&dhpackage;</command> \"\n\"provides a number of options which can be used to override the ownership:\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><itemizedlist><listitem><para>\n#: ../en/mksquashfs.dbk:157\nmsgid \"\"\n\"The options <option>-all-root</option> and <option>-root-owned</option> \"\n\"(both do exactly the same thing) force all file uids/gids in the generated \"\n\"Squashfs filesystem to be <literal>root</literal>.  This allows root owned \"\n\"filesystems to be built without root access on the host machine.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><itemizedlist><listitem><para>\n#: ../en/mksquashfs.dbk:164\nmsgid \"\"\n\"The <option>-force-uid <replaceable>uid</replaceable></option> option forces \"\n\"all files in the generated Squashfs filesystem to be owned by the specified \"\n\"<replaceable>uid</replaceable>.  The uid can be specified either by name \"\n\"(i.e. <literal>root</literal>) or by number.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><itemizedlist><listitem><para>\n#: ../en/mksquashfs.dbk:172\nmsgid \"\"\n\"The <option>-force-gid <replaceable>gid</replaceable></option> option forces \"\n\"all files in the generated Squashfs filesystem to be group owned by the \"\n\"specified <replaceable>gid</replaceable>.  The gid can be specified either \"\n\"by name (i.e. <literal>root</literal>) or by number.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:181\nmsgid \"\"\n\"The <option>-e</option> and <option>-ef</option> options allow \"\n\"files/directories to be specified which are excluded from the output \"\n\"filesystem.  The <option>-e</option> option takes the exclude \"\n\"files/directories from the command line, the <option>-ef</option> option \"\n\"takes the exlude files/directories from the specified exclude file, one \"\n\"file/directory per line. If an exclude file/directory is absolute \"\n\"(i.e. prefixed with <filename>/</filename>, <filename>../</filename>, or \"\n\"<filename>./</filename>) the entry is treated as absolute, however, if an \"\n\"exclude file/directory is relative, it is treated as being relative to each \"\n\"of the sources in turn, i.e.  <userinput>mksquashfs /tmp/source1 source2 \"\n\"output_fs -e ex1 /tmp/source1/ex2 out/ex3</userinput> Will generate exclude \"\n\"files <filename>/tmp/source1/ex2</filename>, \"\n\"<filename>/tmp/source1/ex1</filename>, <filename>source2/ex1</filename>, \"\n\"<filename>/tmp/source1/out/ex3</filename> and \"\n\"<filename>source2/out/ex3</filename>.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:201\nmsgid \"\"\n\"The <option>-e</option> and <option>-ef</option> exclude options are \"\n\"usefully used in archiving the entire filesystem, where it is wished to \"\n\"avoid archiving <filename>/proc</filename>, and the filesystem being \"\n\"generated, i.e.  <userinput>mksquashfs / /tmp/root.sqsh -e proc \"\n\"/tmp/root.sqsh</userinput>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:208\nmsgid \"\"\n\"Multiple <option>-ef</option> options can be specified on the command line, \"\n\"and the <option>-ef</option> option can be used in conjuction with the \"\n\"<option>-e</option> option.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:213\nmsgid \"\"\n\"The <option>-info</option> option displays the files/directories as they are \"\n\"compressed and added to the filesystem.  The original uncompressed size of \"\n\"each file is printed, along with <literal>DUPLICATE</literal> if the file is \"\n\"a duplicate of a file in the filesystem.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:219\nmsgid \"\"\n\"The <option>-no-exports</option> option doesn't make the filesystem \"\n\"exportable via NFS.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:222\nmsgid \"The <option>-no-progress</option> option doesn't display the progress bar.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:225\nmsgid \"\"\n\"The <option>-le</option> and <option>-be</option> options can be used to \"\n\"force <command>&dhpackage;</command> to generate a little endian or big \"\n\"endian filesystem.  Normally <command>&dhpackage;</command> will generate a \"\n\"filesystem in the host byte order.  Squashfs, for portability, will mount \"\n\"different ordered filesystems (i.e. it can mount big endian filesystems \"\n\"running on a little endian machine), but these options can be used for \"\n\"greater optimisation.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><title>\n#: ../en/mksquashfs.dbk:237\nmsgid \"OPTIONS\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:242\nmsgid \"<option>-version</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:245\nmsgid \"print version, licence and copyright message.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:250\nmsgid \"<option>-recover <replaceable>name</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:253\nmsgid \"\"\n\"Allows the original filesystem to be recovered if Mksquashfs aborts \"\n\"unexpectedly (i.e.  power failure)  using recovery file \"\n\"<replaceable>name</replaceable>.  Recovery files are now created when \"\n\"appending to existing Squashfs filesystems.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:262\nmsgid \"<option>-no-recovery</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:263\nmsgid \"don't generate a recovery file\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:268\nmsgid \"<option>-info</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:269\nmsgid \"print files written to filesystem\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:274\nmsgid \"<option>-no-exports</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:275\nmsgid \"don't make the filesystem exportable via NFS\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:281\nmsgid \"<option>-no-progress</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:282\nmsgid \"don't display the progress bar\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:287\nmsgid \"<option>-no-sparse</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:288\nmsgid \"don't detect sparse files\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:293\nmsgid \"<option>-b <replaceable>block_size</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:295\nmsgid \"\"\n\"set data block to <replaceable>block_size</replaceable>. Default is 131072 \"\n\"bytes\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:302\nmsgid \"<option>-processors <replaceable>number</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:304\nmsgid \"\"\n\"Use <replaceable>number</replaceable> processors.  By default will use \"\n\"number of processors available\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:311\nmsgid \"<option>-read-queue <replaceable>size</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:313\nmsgid \"\"\n\"Set input queue to <replaceable>size</replaceable> Mbytes. Default 64 \"\n\"Mbytes.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:320\nmsgid \"<option>-write-queue <replaceable>size</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:322\nmsgid \"\"\n\"Set output queue to <replaceable>size</replaceable> Mbytes. Default 512 \"\n\"Mbytes.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:329\nmsgid \"<option>-noI</option> or <option>-noInodeCompression</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:331\nmsgid \"do not compress inode table\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:336\nmsgid \"<option>-noD</option>or <option>-noDataCompression</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:338\nmsgid \"do not compress data blocks\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:343\nmsgid \"<option>-noF</option> or <option>-noFragmentCompression</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:345\nmsgid \"do not compress fragment blocks\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:350\nmsgid \"<option>-no-fragments</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:351\nmsgid \"\"\n\"do not use fragments: tells <command>&dhpackage;</command> to not generate \"\n\"fragment blocks, and rather generate a filesystem similar to a Squashfs 1.x \"\n\"filesystem. It will of course still be a Squashfs 2.0 filesystem but without \"\n\"fragments, and so it won't be mountable on a Squashfs 1.x system.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:361\nmsgid \"<option>-always-use-fragments</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:362\nmsgid \"\"\n\"use fragment blocks for files larger than block size: tells \"\n\"<command>&dhpackage;</command> to always generate fragments for files \"\n\"irrespective of the file length.  By default only small files less than the \"\n\"block size are packed into fragment blocks.  The ends of files which do not \"\n\"fit fully into a block, are <emphasis>NOT</emphasis> by default packed into \"\n\"fragments.  To illustrate this, a 100K file has an initial 64K block and a \"\n\"36K remainder.  This 36K remainder is not packed into a fragment by \"\n\"default.  This is because to do so leads to a 10 - 20% drop in sequential \"\n\"I/O performance, as a disk head seek is needed to seek to the initial file \"\n\"data and another disk seek is need to seek to the fragment block. Specify \"\n\"this option if you want file remainders to be packed into fragment \"\n\"blocks. Doing so may increase the compression obtained \"\n\"<emphasis>BUT</emphasis> at the expense of I/O speed.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:384\nmsgid \"<option>-no-duplicates</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:385\nmsgid \"\"\n\"do not perform duplicate checking: tells <command>&dhpackage;</command> to \"\n\"not check the files being added to the filesystem for duplicates.  This can \"\n\"result in quicker filesystem generation and appending although obviously \"\n\"compression will suffer badly if there is a lot of duplicate files.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:395\nmsgid \"<option>-noappend</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:396\nmsgid \"do not append to existing filesystem\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:402\nmsgid \"<option>-keep-as-directory</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:403\nmsgid \"\"\n\"if one source directory is specified, create a root directory containing \"\n\"that directory, rather than the contents of the directory\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:410\nmsgid \"<option>-root-becomes <replaceable>name</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:412\nmsgid \"\"\n\"when appending source files/directories, make the original root become a \"\n\"subdirectory in the new root called <replaceable>name</replaceable>, rather \"\n\"than adding the new source items to the original root\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:420\nmsgid \"<option>-all-root</option> or <option>-root-owned</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:422\nmsgid \"make all files owned by root\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:427\nmsgid \"<option>-force-uid <replaceable>uid</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:429\nmsgid \"set all file uids to <replaceable>uid</replaceable>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:435\nmsgid \"<option>-force-gid <replaceable>gid</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:437\nmsgid \"set all file gids to <replaceable>gid</replaceable>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:443\nmsgid \"<option>-le</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:444\nmsgid \"create a little endian filesystem\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:449\nmsgid \"<option>-be</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:450\nmsgid \"create a big endian filesystem\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:455\nmsgid \"<option>-nopad</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:456\nmsgid \"\"\n\"do not pad filesystem to a multiple of 4Ko.  This is performed by default to \"\n\"enable the output filesystem file to be mounted by loopback, which requires \"\n\"files to be a 4K multiple.  If the filesystem is being written to a block \"\n\"device, or is to be stored in a bootimage, the extra pad bytes are not \"\n\"needed.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:466\nmsgid \"<option>-check_data</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:467\nmsgid \"add checkdata for greater filesystem checks\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:473\nmsgid \"<option>-sort <replaceable>sort_file</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:475\nmsgid \"\"\n\"sort files according to priorities in <replaceable>sort_file</replaceable>.  \"\n\"One file or dir with priority per line.  Priority -32768 to 32767, default \"\n\"priority 0\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:483\nmsgid \"<option>-e <replaceable>list of exclude dirs/files</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:485\nmsgid \"inline list of files / directories to exclude\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:491\nmsgid \"<option>-ef <replaceable>exclude_file</replaceable></option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:493\nmsgid \"file containing a list of files / directories to exclude, one per line\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:499\nmsgid \"<option>-wildcards</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:500\nmsgid \"Allow extended shell wildcards (globbing) to be used in exclude dirs/files\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><term>\n#: ../en/mksquashfs.dbk:505\nmsgid \"<option>-regex</option>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><variablelist><varlistentry><listitem><para>\n#: ../en/mksquashfs.dbk:506\nmsgid \"Allow POSIX regular expressions to be used in exclude dirs/files\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><title>\n#: ../en/mksquashfs.dbk:514\nmsgid \"EXAMPLES\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:516\nmsgid \"For following examples, take two example directories:\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para><itemizedlist><listitem><para>\n#: ../en/mksquashfs.dbk:519\nmsgid \"\"\n\"Source directory <filename>/home/phillip/test</filename> contains \"\n\"<filename>file1</filename>, <filename>file2</filename> and \"\n\"<filename>dir1</filename>.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para><itemizedlist><listitem><para>\n#: ../en/mksquashfs.dbk:525\nmsgid \"\"\n\"Source directory <filename>goodies</filename> contains \"\n\"<filename>goodies1</filename>, <filename>goodies2</filename> and \"\n\"<filename>goodies3</filename>.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><screen>\n#: ../en/mksquashfs.dbk:537\n#, no-wrap\nmsgid \"<userinput>mksquashfs /home/phillip/test output_fs</userinput>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><para>\n#: ../en/mksquashfs.dbk:538\nmsgid \"\"\n\"This will generate a squashfs filesystem with root entries \"\n\"<filename>file1</filename>, <filename>file2</filename> and \"\n\"<filename>dir1</filename>.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><screen>\n#: ../en/mksquashfs.dbk:547\n#, no-wrap\nmsgid \"<userinput>mksquashfs /home/phillip/test goodies output_fs</userinput>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><para>\n#: ../en/mksquashfs.dbk:548\nmsgid \"\"\n\"This will create a squashfs filesystem with the root containing entries \"\n\"<filename>test</filename> and <filename>goodies</filename> corresponding to \"\n\"the source directories <filename>/home/phillip/test</filename> and \"\n\"<filename>goodies</filename>.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><screen>\n#: ../en/mksquashfs.dbk:559\n#, no-wrap\nmsgid \"<userinput>mksquashfs /home/phillip/test goodies test output_fs</userinput>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><para>\n#: ../en/mksquashfs.dbk:561\nmsgid \"\"\n\"This is the same as the previous example, except a third source directory \"\n\"<filename>test</filename> has been specified. This conflicts with the first \"\n\"directory named <filename>test</filename> and will be renamed \"\n\"<filename>test_1</filename>.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><para>\n#: ../en/mksquashfs.dbk:566\nmsgid \"\"\n\"Multiple sources allow filesystems to be generated without needing to copy \"\n\"all source files into a common directory.  This simplifies creating \"\n\"filesystems.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><screen>\n#: ../en/mksquashfs.dbk:575\n#, no-wrap\nmsgid \"\"\n\"<userinput>mksquashfs /home/phillip/test output_fs \"\n\"-keep-as-directory</userinput>\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><refsect2><example><para>\n#: ../en/mksquashfs.dbk:577\nmsgid \"\"\n\"This is the same as the first example, except for \"\n\"<option>-keep-as-directory</option>. This will generate a root directory \"\n\"containing directory <filename>test</filename>, rather than the \"\n\"<filename>test</filename> directory contents <filename>file1</filename>, \"\n\"<filename>file2</filename> and <filename>dir1</filename>.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><title>\n#: ../en/mksquashfs.dbk:590\nmsgid \"AUTHORS\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:592\nmsgid \"\"\n\"Squashfs was written by <personname> <firstname>Phillip</firstname> \"\n\"<surname>Lougher</surname> </personname> \"\n\"<email>plougher@users.sourceforge.net</email>, in Chepstow, Wales, UK. If \"\n\"you like the program, or have any problems, then please email me, as it's \"\n\"nice to get feedback !\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:600\nmsgid \"\"\n\"This manual page was written by &dhusername; &dhemail; for the &debian; \"\n\"system (but may be used by others) using the <citetitle>SquashFS \"\n\"HOWTO</citetitle> from <author> <firstname>Artemiy I.</firstname> \"\n\"<surname>Pavlov</surname> </author> and squashfs's \"\n\"<filename>README</filename> file.  Permission is granted to copy, distribute \"\n\"and/or modify this document under the terms of the &gnu; General Public \"\n\"License, Version 2 any later version published by the Free Software \"\n\"Foundation.\"\nmsgstr \"\"\n\n# type: Content of: <refentry><refsect1><para>\n#: ../en/mksquashfs.dbk:613\nmsgid \"\"\n\"On Debian systems, the complete text of the &gnu; General Public License can \"\n\"be found in <filename>/usr/share/common-licenses/GPL</filename>.\"\nmsgstr \"\"\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/doc/po/po4a.cfg",
    "content": "[po4a_langs] fr\n[po4a_paths] mksquashfs.pot fr:mksquashfs.fr.po\n\n[type:docbook] ../en/mksquashfs.dbk \\\n               fr:../fr/mksquashfs.fr.dbk add_fr:mksquashfs.fr.add \\\n               opt:\"-o inline=<option> -M UTF-8\"\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/rules",
    "content": "#!/usr/bin/make -f\n# -*- mode: makefile; coding: utf-8 -*-\n\n# Common include files\ninclude /usr/share/cdbs/1/rules/debhelper.mk\ninclude /usr/share/cdbs/1/class/makefile.mk\n\n# Path to squashfs-tools\nDEB_STOOLS  = $(CURDIR)/squashfs3.3/squashfs-tools\n\n# Manpages stuff\nDOC_DIR\t       = debian/doc\nPO_DIR\t       = $(DOC_DIR)/po\nMAN_TMP_DIR    = $(DOC_DIR)/manpages\n\nMANPAGES       = $(addprefix $(DOC_DIR)/,en/mksquashfs.1 fr/mksquashfs.fr.1 en/unsquashfs.1)\nXSLT_CMD       = xsltproc -''-nonet  -''-param man.charmap.use.subset \"0\"\nDB2MAN         = /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl\n\n# Flags to GCC\n#CFLAGS        += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE\n\n# The build directory is squashfs-tools\nDEB_MAKE_INVOKE := make\n\nDEB_MAKE_BUILD_TARGET := all\nDEB_MAKE_CHECK_TARGET :=\nDEB_MAKE_CLEAN_TARGET :=\n\n# Squashfs-tools manpages targets\ninstall/squashfs-lzma-tools:: po $(MANPAGES)\n\npo:\n\tmkdir -p $(dir $(MANPAGES))\n\tcd $(PO_DIR) && po4a -v po4a.cfg\n\n%.1: %.dbk\n\tcd $(<D) && $(XSLT_CMD) $(DB2MAN) $(<F)\n\tmv $(@D)/*.1 $(DOC_DIR)/$(@F)\n\n## Squashfs-modules packages\nSTAMP_CONFIG = $(CURDIR)/debian/stamp-configure\n\n# Version of the Linux Kernel\nSRC_DIR_MOD = ksquashfs\nDIR_MOD  = linux-2.6\nSNAME    = squashfs-lzma\nPSOURCE  = $(SNAME)-source\nMNAME    = $(SNAME)-modules\n\npre-build::\n\t# Create the 'linux-2.6' directory using last patch of squashfs, it is\n\t# needed for out-of-tree compilation\n\tif ! test -f $(STAMP_CONFIG); then \\\n\t  mkdir -p $(DIR_MOD); \\\n\t  cp $(SRC_DIR_MOD)/fs/squashfs/* $(DIR_MOD); \\\n\t  cp $(SRC_DIR_MOD)/include/linux/* $(DIR_MOD); \\\n\t  touch $(STAMP_CONFIG); \\\n\tfi \n\n# For creating correctly the 'squashfs-source' package which will be\n# used for building module package with custom kernel\ninstall/squashfs-lzma-source::\n\t# Create the needed directories\n\tmkdir -p debian/modules/$(SNAME)/debian \\\n\t\t debian/$(PSOURCE)/usr/src\n\n\t# Copy the source and header files\n\tcp $(DIR_MOD)/*.h $(DIR_MOD)/*.c $(DIR_MOD)/Makefile \\\n\t\tdebian/modules/$(SNAME)\n\n\t# Copy the debian specific files\n\tcp debian/changelog debian/compat debian/copyright debian/*.modules.in \\\n\t\tdebian/modules/$(SNAME)/debian\n\n\t# This rules file is specific to m-a\n\tinstall -m755 debian/rules.modules \\\n\t\tdebian/modules/$(SNAME)/debian/rules\n\n\t# Finally create the tarball which contains the modules directory\n\tcd debian && tar jcf $(PSOURCE)/usr/src/$(SNAME).tar.bz2 modules\n\n# Common targets\nclean::\n\trm -rf $(DOC_DIR)/fr $(DOC_DIR)/*.8 $(DOC_DIR)/*.1 $(DOC_DIR)/en/*.8 $(DIR_MOD) debian/modules\n\trm -f $(DEB_STOOLS)/*.o $(DEB_STOOLS)/mksquashfs $(DEB_STOOLS)/unsquashfs $(STAMP_CONFIG)\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/rules.modules",
    "content": "#!/usr/bin/make -f\n# -*- mode: makefile; coding: utf-8 -*-\n\n# prefix of the target package name\nPACKAGE=squashfs-lzma-modules\n# modifieable for experiments or debugging m-a\nMA_DIR ?= /usr/share/modass\n# load generic variable handling\n-include $(MA_DIR)/include/generic.make\n# load default rules, including kdist, kdist_image, ...\n-include $(MA_DIR)/include/common-rules.make\n\n# module assistant calculates all needed things for us and sets\n# following variables:\n# KSRC (kernel source directory), KVERS (kernel version string), KDREV\n# (revision of the Debian kernel-image package), CC (the correct\n# compiler), VERSION (the final package version string), PKGNAME (full\n# package name with KVERS included), DEB_DESTDIR (path to store DEBs)\n\n# The kdist_configure target is called by make-kpkg modules_config and\n# by kdist* rules by dependency. It should configure the module so it is\n# ready for compilation (mostly useful for calling configure).\n# prep-deb-files from module-assistant creates the neccessary debian/ files\nkdist_config: prep-deb-files\n\n# the kdist_clean target is called by make-kpkg modules_clean and from\n# kdist* rules. It is responsible for cleaning up any changes that have\n# been made by the other kdist_commands (except for the .deb files created)\nkdist_clean:\n\t$(MAKE) -C $(KSRC) M=$(PWD) clean\n\nbinary-modules:\n\tdh_testroot\n\tdh_clean -k\n\tdh_installdirs\n\n\t$(MAKE) -C $(KSRC) M=$(PWD) modules\n\n\t# Install the module\n\tmkdir -p debian/$(PACKAGE)-$(KVERS)/lib/modules/$(KVERS)/kernel/fs/squashfs\n\tcp squashfs.ko debian/$(PACKAGE)-$(KVERS)/lib/modules/$(KVERS)/kernel/fs/squashfs\n\n\tdh_installdocs\n\tdh_installchangelogs\n\tdh_installmodules\n\tdh_compress\n\tdh_fixperms\n\tdh_installdeb\n\tdh_gencontrol -- -v$(VERSION)\n\tdh_md5sums\n\tdh_builddeb --destdir=$(DEB_DESTDIR)\n\tdh_clean -k\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/squashfs-lzma-source.NEWS",
    "content": "squashfs (1:3.3-4) unstable; urgency=medium\n\n  This version removes LZMA compression support again.\n\n  Current released squashfs versions have bugs in lzma mode which are also\n  affection the normal operation of squashfs when using zlib compression. This\n  can be avoided by carefully tracking squashfs cvs, which the current\n  maintainers of squashfs do not have the time for. Therefore, for the moment,\n  lzma support is removed again.\n\n -- Daniel Baumann <daniel@debian.org>  Fri, 21 Mar 2008 20:37:00 +0100\n\nsquashfs (1:3.2r2-9exp1) experimental; urgency=low\n\n  This version introduces LZMA compression in addition of ZLIB.\n\n  WARNING!  The  new  squashfs  image file  (generated  without  '-nolzma'\n    option) has no backward  compatibility, while the patched squashfs and\n    its tools can handle the old squashfs image generated by the unpatched\n    squashfs-tools.\n\n -- Arnaud Fontaine <arnaud@andesi.org>  Mon, 29 Oct 2007 20:06:05 +0000\n\nsquashfs (2.0-ALPHA-1) unstable; urgency=low\n\n  WARNING! Images prepared by new mksquashfs 2.0 aren't readable by kernel with\n  old squashfs 1.3 driver. You'll get the following kernel message:\n\n  SQUASHFS error: Major/Minor mismatch, filesystem is (2:0), I support (1: <= 0)\n\n  The new driver reads old images without problem.\n\n -- Piotr Roszatycki <dexter@debian.org>  Mon, 21 Jun 2004 13:06:46 +0200\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/squashfs-lzma-source.README.Debian",
    "content": "squashfs for Debian\n-------------------\n\nThe  Squash  filesystem driver  isn't  [currently]  integrated in  the\nofficial Linux  kernel, so to  be able to  use such a  filesystem, you\nneed  to use  the 'squashfs-modules-*'  package if  you are  using the\nofficial Debian kernel, or the 'squashfs-source' package otherwise (by\nusing 'module-assistant': '# m-a install squashfs').\n\n -- Arnaud Fontaine <arnau@debian.org>, Sun,  2 Apr 2006 11:47:00 +0200\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/squashfs-lzma-source.docs",
    "content": "squashfs3.3/ACKNOWLEDGEMENTS\nsquashfs3.3/PERFORMANCE.README\nsquashfs3.3/README\nsquashfs3.3/README-3.3\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/squashfs-lzma-source.links",
    "content": "/usr/share/modass/packages/default.sh\t/usr/share/modass/overrides/squashfs-source\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/squashfs-lzma-tools.README.Debian",
    "content": "this package from git.grml.org is packaged with topgit\nAND uses a temporary build branch (which is only tagged on release)\n\n# create the build branch\ngit checkout build\ngit reset --hard master\nfor i in $(cat .tmpdeps|xargs); do g merge -n $i; done\n\n# building this package\ngit checkout build (create as stated above)\ngit-buildpackage --git-debian-branch=build\n\n# want to make your own modifications to the debian packaging\njust work on build branch and cherry-pick the changes back to master.\nafter that recreate your build branch\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/squashfs-lzma-tools.dirs",
    "content": "usr/bin\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/squashfs-lzma-tools.install",
    "content": "squashfs3.3/squashfs-tools/mksquashfs\t/usr/bin\nsquashfs3.3/squashfs-tools/unsquashfs\t/usr/bin\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/squashfs-lzma-tools.manpages",
    "content": "debian/doc/mksquashfs.1\ndebian/doc/mksquashfs.fr.1\ndebian/doc/unsquashfs.1\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/debian/watch",
    "content": "# watch control file for uscan\nversion=3\n\nopts=\"uversionmangle=s/-r/r/\" \\\nftp://heanet.dl.sourceforge.net/s/sq/squashfs/squashfs(.*)\\.tar\\.gz \\\n\tdebian  git-import-orig\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/ksquashfs/fs/squashfs/Makefile",
    "content": "#\n# Makefile for the linux squashfs routines.\n#\n\n# the environment variables are not inherited since 2.6.23\nifdef SQLZMA_EXTRA_CFLAGS\nEXTRA_CFLAGS += ${SQLZMA_EXTRA_CFLAGS}\nendif\n\nobj-$(CONFIG_SQUASHFS) += squashfs.o\nsquashfs-y += inode.o\nsquashfs-y += squashfs2_0.o\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/ksquashfs/fs/squashfs/inode.c",
    "content": "/*\n * Squashfs - a compressed read only filesystem for Linux\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * inode.c\n */\n\n#include <linux/squashfs_fs.h>\n#include <linux/module.h>\n#include <linux/zlib.h>\n#include <linux/fs.h>\n#include <linux/squashfs_fs_sb.h>\n#include <linux/squashfs_fs_i.h>\n#include <linux/buffer_head.h>\n#include <linux/vfs.h>\n#include <linux/vmalloc.h>\n#include <linux/smp_lock.h>\n#include <linux/exportfs.h>\n\n#include \"squashfs.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#undef KeepPreemptive\n#if defined(CONFIG_PREEMPT) && !defined(UnsquashNoPreempt)\n#define KeepPreemptive\n#endif\n\nstruct sqlzma {\n#ifdef KeepPreemptive\n\tstruct mutex mtx;\n#endif\n\tunsigned char read_data[SQUASHFS_FILE_MAX_SIZE];\n\tstruct sqlzma_un un;\n};\nstatic DEFINE_PER_CPU(struct sqlzma *, sqlzma);\n\n#define dpri(fmt, args...) /* printk(\"%s:%d: \" fmt, __func__, __LINE__, ##args) */\n#define dpri_un(un)\tdpri(\"un{%d, {%d %p}, {%d %p}, {%d %p}}\\n\", \\\n\t\t\t     (un)->un_lzma, (un)->un_a[0].sz, (un)->un_a[0].buf, \\\n\t\t\t     (un)->un_a[1].sz, (un)->un_a[1].buf, \\\n\t\t\t     (un)->un_a[2].sz, (un)->un_a[2].buf)\n\nstatic int squashfs_cached_blks;\n\nstatic void vfs_read_inode(struct inode *i);\nstatic struct dentry *squashfs_get_parent(struct dentry *child);\nstatic int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\nstatic int squashfs_statfs(struct dentry *, struct kstatfs *);\nstatic int squashfs_symlink_readpage(struct file *file, struct page *page);\nstatic long long read_blocklist(struct inode *inode, int index,\n\t\t\t\tint readahead_blks, char *block_list,\n\t\t\t\tunsigned short **block_p, unsigned int *bsize);\nstatic int squashfs_readpage(struct file *file, struct page *page);\nstatic int squashfs_readdir(struct file *, void *, filldir_t);\nstatic struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n\t\t\t\tstruct nameidata *);\nstatic int squashfs_remount(struct super_block *s, int *flags, char *data);\nstatic void squashfs_put_super(struct super_block *);\nstatic int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n\t\t\t\tstruct vfsmount *);\nstatic struct inode *squashfs_alloc_inode(struct super_block *sb);\nstatic void squashfs_destroy_inode(struct inode *inode);\nstatic int init_inodecache(void);\nstatic void destroy_inodecache(void);\n\nstatic struct file_system_type squashfs_fs_type = {\n\t.owner = THIS_MODULE,\n\t.name = \"squashfs\",\n\t.get_sb = squashfs_get_sb,\n\t.kill_sb = kill_block_super,\n\t.fs_flags = FS_REQUIRES_DEV\n};\n\nstatic const unsigned char squashfs_filetype_table[] = {\n\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n};\n\nstatic struct super_operations squashfs_super_ops = {\n\t.alloc_inode = squashfs_alloc_inode,\n\t.destroy_inode = squashfs_destroy_inode,\n\t.statfs = squashfs_statfs,\n\t.put_super = squashfs_put_super,\n\t.remount_fs = squashfs_remount\n};\n\nstatic struct super_operations squashfs_export_super_ops = {\n\t.alloc_inode = squashfs_alloc_inode,\n\t.destroy_inode = squashfs_destroy_inode,\n\t.statfs = squashfs_statfs,\n\t.put_super = squashfs_put_super,\n\t.read_inode = vfs_read_inode\n};\n\nstatic struct export_operations squashfs_export_ops = {\n\t.get_parent = squashfs_get_parent\n};\n\nSQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n\t.readpage = squashfs_symlink_readpage\n};\n\nSQSH_EXTERN const struct address_space_operations squashfs_aops = {\n\t.readpage = squashfs_readpage\n};\n\nstatic const struct file_operations squashfs_dir_ops = {\n\t.read = generic_read_dir,\n\t.readdir = squashfs_readdir\n};\n\nSQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n\t.lookup = squashfs_lookup\n};\n\n\nstatic struct buffer_head *get_block_length(struct super_block *s,\n\t\t\t\tint *cur_index, int *offset, int *c_byte)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tunsigned short temp;\n\tstruct buffer_head *bh;\n\n\tif (!(bh = sb_bread(s, *cur_index)))\n\t\tgoto out;\n\n\tif (msblk->devblksize - *offset == 1) {\n\t\tif (msblk->swap)\n\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n\t\t\t\t(bh->b_data + *offset));\n\t\telse\n\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n\t\t\t\t(bh->b_data + *offset));\n\t\tbrelse(bh);\n\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n\t\t\tgoto out;\n\t\tif (msblk->swap)\n\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n\t\t\t\tbh->b_data); \n\t\telse\n\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n\t\t\t\tbh->b_data); \n\t\t*c_byte = temp;\n\t\t*offset = 1;\n\t} else {\n\t\tif (msblk->swap) {\n\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n\t\t\t\t(bh->b_data + *offset));\n\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n\t\t\t\t(bh->b_data + *offset + 1)); \n\t\t} else {\n\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n\t\t\t\t(bh->b_data + *offset));\n\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n\t\t\t\t(bh->b_data + *offset + 1)); \n\t\t}\n\t\t*c_byte = temp;\n\t\t*offset += 2;\n\t}\n\n\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n\t\tif (*offset == msblk->devblksize) {\n\t\t\tbrelse(bh);\n\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n\t\t\t\tgoto out;\n\t\t\t*offset = 0;\n\t\t}\n\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n\t\t\t\t\t\t*cur_index);\n\t\t\tbrelse(bh);\n\t\t\tgoto out;\n\t\t}\n\t\t(*offset)++;\n\t}\n\treturn bh;\n\nout:\n\treturn NULL;\n}\n\n\nSQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n\t\t\tlong long index, unsigned int length,\n\t\t\tlong long *next_index, int srclength)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tstruct buffer_head **bh;\n\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n\tunsigned int cur_index = index >> msblk->devblksize_log2;\n\tint bytes, avail_bytes, b = 0, k = 0;\n\tunsigned int compressed;\n\tunsigned int c_byte = length;\n\n\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n\tif (bh == NULL)\n\t\tgoto read_failure;\n\n\tif (c_byte) {\n\t\tbytes = msblk->devblksize - offset;\n\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\n\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n\n\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n\t\t\tgoto read_failure;\n\n\t\tbh[0] = sb_getblk(s, cur_index);\n\t\tif (bh[0] == NULL)\n\t\t\tgoto block_release;\n\n\t\tfor (b = 1; bytes < c_byte; b++) {\n\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n\t\t\tif (bh[b] == NULL)\n\t\t\t\tgoto block_release;\n\t\t\tbytes += msblk->devblksize;\n\t\t}\n\t\tll_rw_block(READ, b, bh);\n\t} else {\n\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n\t\t\tgoto read_failure;\n\n\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n\t\tif (bh[0] == NULL)\n\t\t\tgoto read_failure;\n\n\t\tbytes = msblk->devblksize - offset;\n\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\n\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n\n\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n\t\t\tgoto read_failure;\n\n\t\tfor (b = 1; bytes < c_byte; b++) {\n\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n\t\t\tif (bh[b] == NULL)\n\t\t\t\tgoto block_release;\n\t\t\tbytes += msblk->devblksize;\n\t\t}\n\t\tll_rw_block(READ, b - 1, bh + 1);\n\t}\n\n\tif (compressed) {\n\t\tint zlib_err = Z_STREAM_END;\n\t\tint start;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[2];\n\t\tstruct sqlzma *percpu;\n\t\tunsigned char *p;\n\n\t\t/*\n\t \t* uncompress block\n\t \t*/\n\n\t\t/* mutex_lock(&msblk->read_data_mutex); */\n\n\t\tstart = k;\n\t\tfor (; k < b; k++) {\n\t\t\twait_on_buffer(bh[k]);\n\t\t\tif (!buffer_uptodate(bh[k]))\n\t\t\t\tgoto release_mutex;\n\t\t}\n\n\t\t/* it disables preemption */\n\t\tpercpu = get_cpu_var(sqlzma);\n#ifdef KeepPreemptive\n\t\tput_cpu_var(sqlzma);\n\t\tmutex_lock(&percpu->mtx);\n#endif\n\t\tp = percpu->read_data;\n\t\tk = start;\n\t\tfor (bytes = 0; k < b; k++) {\n\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n\n\t\t\tif (k == 0) {\n\t\t\t\t/*\n\t\t\t\t * keep this block structture to simplify the\n\t\t\t\t * diff.\n\t\t\t\t */\n\t\t\t\tif (avail_bytes == 0) {\n\t\t\t\t\toffset = 0;\n\t\t\t\t\tbrelse(bh[k]);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmemcpy(p, bh[k]->b_data + offset, avail_bytes);\n\t\t\tp += avail_bytes;\n#if 0\n\t\t\tBUG_ON(percpu->read_data + sizeof(percpu->read_data)\n\t\t\t       < p);\n#endif\n\n\t\t\tbytes += avail_bytes;\n\t\t\toffset = 0;\n\t\t\tbrelse(bh[k]);\n\t\t}\n\n\t\tsbuf[Src].buf = percpu->read_data;\n\t\tsbuf[Src].sz = bytes;\n\t\tsbuf[Dst].buf = buffer;\n\t\tsbuf[Dst].sz = srclength;\n\t\tdpri_un(&percpu->un);\n\t\tdpri(\"src %d %p, dst %d %p\\n\", sbuf[Src].sz, sbuf[Src].buf,\n\t\t     sbuf[Dst].sz, sbuf[Dst].buf);\n\t\tzlib_err = sqlzma_un(&percpu->un, sbuf + Src, sbuf + Dst);\n\t\tbytes = percpu->un.un_reslen;\n\n#ifdef KeepPreemptive\n\t\tmutex_unlock(&percpu->mtx);\n#else\n\t\tput_cpu_var(sqlzma);\n#endif\n\t\tif (unlikely(zlib_err)) {\n\t\t\tdpri(\"zlib_err %d\\n\", zlib_err);\n\t\t\tgoto release_mutex;\n\t\t}\n\t\t/* mutex_unlock(&msblk->read_data_mutex); */\n\t} else {\n\t\tint i;\n\n\t\tfor(i = 0; i < b; i++) {\n\t\t\twait_on_buffer(bh[i]);\n\t\t\tif (!buffer_uptodate(bh[i]))\n\t\t\t\tgoto block_release;\n\t\t}\n\n\t\tfor (bytes = 0; k < b; k++) {\n\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n\n\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n\t\t\tbytes += avail_bytes;\n\t\t\toffset = 0;\n\t\t\tbrelse(bh[k]);\n\t\t}\n\t}\n\n\tif (next_index)\n\t\t*next_index = index + c_byte + (length ? 0 :\n\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n\n\tkfree(bh);\n\treturn bytes;\n\nrelease_mutex:\n\t/* mutex_unlock(&msblk->read_data_mutex); */\n\nblock_release:\n\tfor (; k < b; k++)\n\t\tbrelse(bh[k]);\n\nread_failure:\n\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n\tkfree(bh);\n\treturn 0;\n}\n\n\nSQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n\t\t\t\tlong long block, unsigned int offset,\n\t\t\t\tint length, long long *next_block,\n\t\t\t\tunsigned int *next_offset)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tint n, i, bytes, return_length = length;\n\tlong long next_index;\n\n\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n\n\twhile (1) {\n\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n\t\t\tif (msblk->block_cache[i].block == block)\n\t\t\t\tbreak; \n\t\t\n\t\tmutex_lock(&msblk->block_cache_mutex);\n\n\t\tif (i == squashfs_cached_blks) {\n\t\t\t/* read inode header block */\n\t\t\tif (msblk->unused_cache_blks == 0) {\n\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ti = msblk->next_cache;\n\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n\t\t\t\t\tbreak;\n\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n\t\t\t}\n\n\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n\n\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n\t\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n\t\t\t\t\tgoto out;\n\t\t\t\t}\n\t\t\t}\n\t\n\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n\t\t\tmsblk->unused_cache_blks --;\n\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n\n\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n\t\t\t\tSQUASHFS_METADATA_SIZE);\n\n\t\t\tif (msblk->block_cache[i].length == 0) {\n\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n\t\t\t\tmutex_lock(&msblk->block_cache_mutex);\n\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n\t\t\t\tmsblk->unused_cache_blks ++;\n\t\t\t\tsmp_mb();\n\t\t\t\tvfree(msblk->block_cache[i].data);\n\t\t\t\twake_up(&msblk->waitq);\n\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n\t\t\t\tgoto out;\n\t\t\t}\n\n\t\t\tmutex_lock(&msblk->block_cache_mutex);\n\t\t\tmsblk->block_cache[i].block = block;\n\t\t\tmsblk->block_cache[i].next_index = next_index;\n\t\t\tmsblk->unused_cache_blks ++;\n\t\t\tsmp_mb();\n\t\t\twake_up(&msblk->waitq);\n\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n\t\t}\n\n\t\tif (msblk->block_cache[i].block != block) {\n\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n\t\t\tcontinue;\n\t\t}\n\n\t\tbytes = msblk->block_cache[i].length - offset;\n\n\t\tif (bytes < 1) {\n\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n\t\t\tgoto out;\n\t\t} else if (bytes >= length) {\n\t\t\tif (buffer)\n\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n\t\t\tif (msblk->block_cache[i].length - offset == length) {\n\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n\t\t\t\t*next_offset = 0;\n\t\t\t} else {\n\t\t\t\t*next_block = block;\n\t\t\t\t*next_offset = offset + length;\n\t\t\t}\n\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n\t\t\tgoto finish;\n\t\t} else {\n\t\t\tif (buffer) {\n\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n\t\t\t\tbuffer = (char *) buffer + bytes;\n\t\t\t}\n\t\t\tblock = msblk->block_cache[i].next_index;\n\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n\t\t\tlength -= bytes;\n\t\t\toffset = 0;\n\t\t}\n\t}\n\nfinish:\n\treturn return_length;\nout:\n\treturn 0;\n}\n\n\nstatic int get_fragment_location(struct super_block *s, unsigned int fragment,\n\t\t\t\tlong long *fragment_start_block,\n\t\t\t\tunsigned int *fragment_size)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tlong long start_block =\n\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n\tstruct squashfs_fragment_entry fragment_entry;\n\n\tif (msblk->swap) {\n\t\tstruct squashfs_fragment_entry sfragment_entry;\n\n\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n\t\t\tgoto out;\n\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n\t} else\n\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n\t\t\tgoto out;\n\n\t*fragment_start_block = fragment_entry.start_block;\n\t*fragment_size = fragment_entry.size;\n\n\treturn 1;\n\nout:\n\treturn 0;\n}\n\n\nSQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n\t\t\t\tstruct squashfs_fragment_cache *fragment)\n{\n\tmutex_lock(&msblk->fragment_mutex);\n\tfragment->locked --;\n\tif (fragment->locked == 0) {\n\t\tmsblk->unused_frag_blks ++;\n\t\tsmp_mb();\n\t\twake_up(&msblk->fragment_wait_queue);\n\t}\n\tmutex_unlock(&msblk->fragment_mutex);\n}\n\n\nSQSH_EXTERN\nstruct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n\t\t\t\tlong long start_block, int length)\n{\n\tint i, n;\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\n\twhile (1) {\n\t\tmutex_lock(&msblk->fragment_mutex);\n\n\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n\n\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n\t\t\tif (msblk->unused_frag_blks == 0) {\n\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ti = msblk->next_fragment;\n\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n\t\t\t\tif (msblk->fragment[i].locked == 0)\n\t\t\t\t\tbreak;\n\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n\t\t\t}\n\n\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n\t\t\t\n\t\t\tif (msblk->fragment[i].data == NULL) {\n\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n\t\t\t\tif (msblk->fragment[i].data == NULL) {\n\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n\t\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n\t\t\t\t\tgoto out;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmsblk->unused_frag_blks --;\n\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n\t\t\tmsblk->fragment[i].locked = 1;\n\t\t\tmutex_unlock(&msblk->fragment_mutex);\n\n\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n\t\t\t\tsblk->block_size);\n\n\t\t\tif (msblk->fragment[i].length == 0) {\n\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n\t\t\t\tmsblk->fragment[i].locked = 0;\n\t\t\t\tmsblk->unused_frag_blks ++;\n\t\t\t\tsmp_mb();\n\t\t\t\twake_up(&msblk->fragment_wait_queue);\n\t\t\t\tgoto out;\n\t\t\t}\n\n\t\t\tmutex_lock(&msblk->fragment_mutex);\n\t\t\tmsblk->fragment[i].block = start_block;\n\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n\t\t\tmutex_unlock(&msblk->fragment_mutex);\n\t\t\tbreak;\n\t\t}\n\n\t\tif (msblk->fragment[i].locked == 0)\n\t\t\tmsblk->unused_frag_blks --;\n\t\tmsblk->fragment[i].locked++;\n\t\tmutex_unlock(&msblk->fragment_mutex);\n\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n\t\tbreak;\n\t}\n\n\treturn &msblk->fragment[i];\n\nout:\n\treturn NULL;\n}\n\n\nstatic void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n{\n\ti->i_ino = inodeb->inode_number;\n\ti->i_mtime.tv_sec = inodeb->mtime;\n\ti->i_atime.tv_sec = inodeb->mtime;\n\ti->i_ctime.tv_sec = inodeb->mtime;\n\ti->i_uid = msblk->uid[inodeb->uid];\n\ti->i_mode = inodeb->mode;\n\ti->i_size = 0;\n\n\tif (inodeb->guid == SQUASHFS_GUIDS)\n\t\ti->i_gid = i->i_uid;\n\telse\n\t\ti->i_gid = msblk->guid[inodeb->guid];\n}\n\n\nstatic squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n\tsquashfs_inode_t inode;\n\n\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n\n\tif (msblk->swap) {\n\t\tsquashfs_inode_t sinode;\n\n\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n\t\t\t\t\tsizeof(sinode), &start, &offset))\n\t\t\tgoto out;\n\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n\t\t\t\t\tsizeof(inode), &start, &offset))\n\t\t\tgoto out;\n\n\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n\n\treturn inode;\n\nout:\n\treturn SQUASHFS_INVALID_BLK;\n}\n\t\n\nstatic void vfs_read_inode(struct inode *i)\n{\n\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n\n\tTRACE(\"Entered vfs_read_inode\\n\");\n\n\tif(inode != SQUASHFS_INVALID_BLK)\n\t\t(msblk->read_inode)(i, inode);\n}\n\n\nstatic struct dentry *squashfs_get_parent(struct dentry *child)\n{\n\tstruct inode *i = child->d_inode;\n\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n\tstruct dentry *rv;\n\n\tTRACE(\"Entered squashfs_get_parent\\n\");\n\n\tif(parent == NULL) {\n\t\trv = ERR_PTR(-EACCES);\n\t\tgoto out;\n\t}\n\n\trv = d_alloc_anon(parent);\n\tif(rv == NULL)\n\t\trv = ERR_PTR(-ENOMEM);\n\nout:\n\treturn rv;\n}\n\n\t\nSQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct inode *i = iget_locked(s, inode_number);\n\n\tTRACE(\"Entered squashfs_iget\\n\");\n\n\tif(i && (i->i_state & I_NEW)) {\n\t\t(msblk->read_inode)(i, inode);\n\t\tunlock_new_inode(i);\n\t}\n\n\treturn i;\n}\n\n\nstatic int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n{\n\tstruct super_block *s = i->i_sb;\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n\tlong long next_block;\n\tunsigned int next_offset;\n\tunion squashfs_inode_header id, sid;\n\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n\n\tTRACE(\"Entered squashfs_read_inode\\n\");\n\n\tif (msblk->swap) {\n\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n\t\t\tgoto failed_read;\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n\t} else\n\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n\t\t\tgoto failed_read;\n\n\tsquashfs_new_inode(msblk, i, inodeb);\n\n\tswitch(inodeb->inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_size;\n\t\t\tlong long frag_blk;\n\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n\t\t\t\t\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n\t\t\t} else\n\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n\n\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n\t\t\t\t\t\tgoto failed_read;\n\t\t\t\t\n\t\t\ti->i_nlink = 1;\n\t\t\ti->i_size = inodep->file_size;\n\t\t\ti->i_fop = &generic_ro_fops;\n\t\t\ti->i_mode |= S_IFREG;\n\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n\t\t\tSQUASHFS_I(i)->offset = next_offset;\n\t\t\ti->i_data.a_ops = &squashfs_aops;\n\n\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n\t\t\t\t\tinodep->start_block, next_block,\n\t\t\t\t\tnext_offset);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_size;\n\t\t\tlong long frag_blk;\n\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n\t\t\t\t\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n\t\t\t} else\n\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n\n\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\t\n\t\t\ti->i_nlink = inodep->nlink;\n\t\t\ti->i_size = inodep->file_size;\n\t\t\ti->i_fop = &generic_ro_fops;\n\t\t\ti->i_mode |= S_IFREG;\n\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n\t\t\tSQUASHFS_I(i)->offset = next_offset;\n\t\t\ti->i_data.a_ops = &squashfs_aops;\n\n\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n\t\t\t\t\tinodep->start_block, next_block,\n\t\t\t\t\tnext_offset);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n\t\t\t} else\n\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\ti->i_nlink = inodep->nlink;\n\t\t\ti->i_size = inodep->file_size;\n\t\t\ti->i_op = &squashfs_dir_inode_ops;\n\t\t\ti->i_fop = &squashfs_dir_ops;\n\t\t\ti->i_mode |= S_IFDIR;\n\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n\n\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n\t\t\t\t\toffset, inodep->start_block,\n\t\t\t\t\tinodep->offset);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n\t\t\t} else\n\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\ti->i_nlink = inodep->nlink;\n\t\t\ti->i_size = inodep->file_size;\n\t\t\ti->i_op = &squashfs_dir_inode_ops;\n\t\t\ti->i_fop = &squashfs_dir_ops;\n\t\t\ti->i_mode |= S_IFDIR;\n\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n\n\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n\t\t\t\t\tinodep->start_block, inodep->offset);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n\t\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n\t\t\t} else\n\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\ti->i_nlink = inodep->nlink;\n\t\t\ti->i_size = inodep->symlink_size;\n\t\t\ti->i_op = &page_symlink_inode_operations;\n\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n\t\t\ti->i_mode |= S_IFLNK;\n\t\t\tSQUASHFS_I(i)->start_block = next_block;\n\t\t\tSQUASHFS_I(i)->offset = next_offset;\n\n\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n\t\t\t\t\tnext_block, next_offset);\n\t\t\tbreak;\n\t\t }\n\t\t case SQUASHFS_BLKDEV_TYPE:\n\t\t case SQUASHFS_CHRDEV_TYPE: {\n\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n\t\t\t} else\t\n\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\ti->i_nlink = inodep->nlink;\n\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n\t\t\t\t\tS_IFCHR : S_IFBLK;\n\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n\n\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n\t\t\tbreak;\n\t\t }\n\t\t case SQUASHFS_FIFO_TYPE:\n\t\t case SQUASHFS_SOCKET_TYPE: {\n\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n\t\t\t} else\t\n\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\ti->i_nlink = inodep->nlink;\n\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n\t\t\tinit_special_inode(i, i->i_mode, 0);\n\t\t\tbreak;\n\t\t }\n\t\t default:\n\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n\t\t\t\t\tinodeb->inode_type);\n\t\t\tgoto failed_read1;\n\t}\n\t\n\treturn 1;\n\nfailed_read:\n\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n\nfailed_read1:\n\tmake_bad_inode(i);\n\treturn 0;\n}\n\n\nstatic int read_inode_lookup_table(struct super_block *s)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n\n\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n\n\t/* Allocate inode lookup table */\n\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n\tif (msblk->inode_lookup_table == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n   \n\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n\t\t\tsblk->lookup_table_start, length |\n\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n\t\tERROR(\"unable to read inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif (msblk->swap) {\n\t\tint i;\n\t\tlong long block;\n\n\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n\t\t\t/* XXX */\n\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n\t\t\tmsblk->inode_lookup_table[i] = block;\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nstatic int read_fragment_index_table(struct super_block *s)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n\n\tif(length == 0)\n\t\treturn 1;\n\n\t/* Allocate fragment index table */\n\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n\tif (msblk->fragment_index == NULL) {\n\t\tERROR(\"Failed to allocate fragment index table\\n\");\n\t\treturn 0;\n\t}\n   \n\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n\t\t\tsblk->fragment_table_start, length |\n\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n\t\tERROR(\"unable to read fragment index table\\n\");\n\t\treturn 0;\n\t}\n\n\tif (msblk->swap) {\n\t\tint i;\n\t\tlong long fragment;\n\n\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n\t\t\t/* XXX */\n\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n\t\t\tmsblk->fragment_index[i] = fragment;\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nstatic int readahead_metadata(struct super_block *s)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tint i;\n\n\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n\n\t/* Init inode_table block pointer array */\n\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n\tif (msblk->block_cache == NULL) {\n\t\tERROR(\"Failed to allocate block cache\\n\");\n\t\tgoto failed;\n\t}\n\n\tfor (i = 0; i < squashfs_cached_blks; i++)\n\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n\n\tmsblk->next_cache = 0;\n\tmsblk->unused_cache_blks = squashfs_cached_blks;\n\n\treturn 1;\n\nfailed:\n\treturn 0;\n}\n\n\nstatic int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n{\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\n\tmsblk->read_inode = squashfs_read_inode;\n\tmsblk->read_blocklist = read_blocklist;\n\tmsblk->read_fragment_index_table = read_fragment_index_table;\n\n\tif (sblk->s_major == 1) {\n\t\tif (!squashfs_1_0_supported(msblk)) {\n\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n\t\t\t\t\"are unsupported\\n\");\n\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n\t\t\treturn 0;\n\t\t}\n\t} else if (sblk->s_major == 2) {\n\t\tif (!squashfs_2_0_supported(msblk)) {\n\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n\t\t\t\t\"are unsupported\\n\");\n\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n\t\t\treturn 0;\n\t\t}\n\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n\t\t\tSQUASHFS_MINOR) {\n\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n\t\tSERROR(\"Please update your kernel\\n\");\n\t\treturn 0;\n\t}\n\n\treturn 1;\n}\n\n\nstatic int squashfs_fill_super(struct super_block *s, void *data, int silent)\n{\n\tstruct squashfs_sb_info *msblk;\n\tstruct squashfs_super_block *sblk;\n\tint i, err;\n\tchar b[BDEVNAME_SIZE];\n\tstruct inode *root;\n\n\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n\n\terr = -ENOMEM;\n\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n\tif (s->s_fs_info == NULL) {\n\t\tERROR(\"Failed to allocate superblock\\n\");\n\t\tgoto failure;\n\t}\n\tmsblk = s->s_fs_info;\n\n\tsblk = &msblk->sblk;\n\t\n\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n\n\t/* mutex_init(&msblk->read_data_mutex); */\n\tmutex_init(&msblk->read_page_mutex);\n\tmutex_init(&msblk->block_cache_mutex);\n\tmutex_init(&msblk->fragment_mutex);\n\tmutex_init(&msblk->meta_index_mutex);\n\t\n\tinit_waitqueue_head(&msblk->waitq);\n\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n\n\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n \t * first set sblk->bytes_used to a useful value */\n\terr = -EINVAL;\n\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n\t\t\t\t\tsizeof(struct squashfs_super_block) |\n\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n\t\tSERROR(\"unable to read superblock\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check it is a SQUASHFS superblock */\n\ts->s_magic = sblk->s_magic;\n\tmsblk->swap = 0;\n\tdpri(\"magic 0x%x\\n\", sblk->s_magic);\n\tswitch (sblk->s_magic) {\n\t\tstruct squashfs_super_block ssblk;\n\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tWARNING(\"Mounting a different endian SQUASHFS \"\n\t\t\t\"filesystem on %s\\n\", bdevname(s->s_bdev, b));\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n\t\tmsblk->swap = 1;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC:\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tbreak;\n\tdefault:\n\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n\t\t       bdevname(s->s_bdev, b));\n\t\tgoto failed_mount;\n\t}\n\n\t{\n\t\tstruct sqlzma *p;\n\t\tdpri(\"block_size %d, devblksize %d\\n\",\n\t\t     sblk->block_size, msblk->devblksize);\n\t\tBUG_ON(sblk->block_size > sizeof(p->read_data));\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(!supported_squashfs_filesystem(msblk, silent))\n\t\tgoto failed_mount;\n\n\t/* Check the filesystem does not extend beyond the end of the\n\t   block device */\n\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n\t\tgoto failed_mount;\n\n\t/* Check the root inode for sanity */\n\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n\t\tgoto failed_mount;\n\n\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n\t\t\t\t\t? \"un\" : \"\");\n\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n\t\t\t\t\t? \"un\" : \"\");\n\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n\tTRACE(\"Block size %d\\n\", sblk->block_size);\n\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n\tif (sblk->s_major > 1)\n\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n\tif (sblk->s_major > 1)\n\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n\n\ts->s_maxbytes = MAX_LFS_FILESIZE;\n\ts->s_flags |= MS_RDONLY;\n\ts->s_op = &squashfs_super_ops;\n\n\tif (readahead_metadata(s) == 0)\n\t\tgoto failed_mount;\n\n\t/* Allocate read_page block */\n\terr = -ENOMEM;\n\tmsblk->read_page = vmalloc(sblk->block_size);\n\tif (msblk->read_page == NULL) {\n\t\tERROR(\"Failed to allocate read_page block\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\t/* Allocate uid and gid tables */\n\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n\tif (msblk->uid == NULL) {\n\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n\t\tgoto failed_mount;\n\t}\n\tmsblk->guid = msblk->uid + sblk->no_uids;\n   \n\tdpri(\"swap %d\\n\", msblk->swap);\n\terr = -EINVAL;\n\tif (msblk->swap) {\n\t\tunsigned int *suid;\n\n\t\terr = -ENOMEM;\n\t\tsuid = kmalloc(sizeof(*suid) * (sblk->no_uids + sblk->no_guids),\n\t\t\t       GFP_KERNEL);\n\t\tif (unlikely(!suid))\n\t\t\tgoto failed_mount;\n\n\t\terr = -EINVAL;\n\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n\t\t\t\t\t sizeof(unsigned int)) |\n\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n\t\t\tERROR(\"unable to read uid/gid table\\n\");\n\t\t\tkfree(suid);\n\t\t\tgoto failed_mount;\n\t\t}\n\n\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n\t\tkfree(suid);\n\t} else\n\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n\t\t\t\t\t sizeof(unsigned int)) |\n\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n\t\t\tERROR(\"unable to read uid/gid table\\n\");\n\t\t\tgoto failed_mount;\n\t\t}\n\n\n\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n\t\tgoto allocate_root;\n\n\terr = -ENOMEM;\n\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n\tif (msblk->fragment == NULL) {\n\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n\t}\n\n\tmsblk->next_fragment = 0;\n\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n\n\t/* Allocate and read fragment index table */\n\tif (msblk->read_fragment_index_table(s) == 0)\n\t\tgoto failed_mount;\n\n\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\tgoto allocate_root;\n\n\t/* Allocate and read inode lookup table */\n\tif (read_inode_lookup_table(s) == 0)\n\t\tgoto failed_mount;\n\n\ts->s_op = &squashfs_export_super_ops;\n\ts->s_export_op = &squashfs_export_ops;\n\nallocate_root:\n\tdpri(\"alloate_root\\n\");\n\troot = new_inode(s);\n\tif ((msblk->read_inode)(root, sblk->root_inode) == 0) {\n\t\tiput(root);\n\t\tgoto failed_mount;\n\t}\n\tinsert_inode_hash(root);\n\n\ts->s_root = d_alloc_root(root);\n\tif (s->s_root == NULL) {\n\t\tERROR(\"Root inode create failed\\n\");\n\t\tiput(root);\n\t\tgoto failed_mount;\n\t}\n\n\tTRACE(\"Leaving squashfs_fill_super\\n\");\n\treturn 0;\n\nfailed_mount:\n\tkfree(msblk->inode_lookup_table);\n\tkfree(msblk->fragment_index);\n\tkfree(msblk->fragment);\n\tkfree(msblk->uid);\n\tvfree(msblk->read_page);\n\tkfree(msblk->block_cache);\n\tkfree(msblk->fragment_index_2);\n\tkfree(s->s_fs_info);\n\ts->s_fs_info = NULL;\n failure:\n\treturn err;\n}\n\n\nstatic int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n{\n\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\n\tTRACE(\"Entered squashfs_statfs\\n\");\n\n\tbuf->f_type = sblk->s_magic;\n\tbuf->f_bsize = sblk->block_size;\n\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n\tbuf->f_bfree = buf->f_bavail = 0;\n\tbuf->f_files = sblk->inodes;\n\tbuf->f_ffree = 0;\n\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n\n\treturn 0;\n}\n\n\nstatic int squashfs_symlink_readpage(struct file *file, struct page *page)\n{\n\tstruct inode *inode = page->mapping->host;\n\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n\tlong long block = SQUASHFS_I(inode)->start_block;\n\tint offset = SQUASHFS_I(inode)->offset;\n\tvoid *pageaddr = kmap(page);\n\n\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n\t\t\t\t\"%llx, offset %x\\n\", page->index,\n\t\t\t\tSQUASHFS_I(inode)->start_block,\n\t\t\t\tSQUASHFS_I(inode)->offset);\n\n\tfor (length = 0; length < index; length += bytes) {\n\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n\t\tif (bytes == 0) {\n\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n\t\t\tgoto skip_read;\n\t\t}\n\t}\n\n\tif (length != index) {\n\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n\t\tbytes = 0;\n\t\tgoto skip_read;\n\t}\n\n\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n\n\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n\t\tavail_bytes, &block, &offset);\n\tif (bytes == 0)\n\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n\nskip_read:\n\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n\tkunmap(page);\n\tflush_dcache_page(page);\n\tSetPageUptodate(page);\n\tunlock_page(page);\n\n\treturn 0;\n}\n\n\nstruct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n{\n\tstruct meta_index *meta = NULL;\n\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n\tint i;\n\n\tmutex_lock(&msblk->meta_index_mutex);\n\n\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n\n\tif (msblk->meta_index == NULL)\n\t\tgoto not_allocated;\n\n\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n\t\t\t\tmsblk->meta_index[i].offset <= index &&\n\t\t\t\tmsblk->meta_index[i].locked == 0) {\n\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n\t\t\t\t\tmsblk->meta_index[i].offset);\n\t\t\tmeta = &msblk->meta_index[i];\n\t\t\toffset = meta->offset;\n\t\t}\n\t}\n\n\tif (meta)\n\t\tmeta->locked = 1;\n\nnot_allocated:\n\tmutex_unlock(&msblk->meta_index_mutex);\n\n\treturn meta;\n}\n\n\nstruct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n{\n\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n\tstruct meta_index *meta = NULL;\n\tint i;\n\n\tmutex_lock(&msblk->meta_index_mutex);\n\n\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n\n\tif (msblk->meta_index == NULL) {\n\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n\t\tif (msblk->meta_index == NULL) {\n\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n\t\t\tgoto failed;\n\t\t}\n\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n\t\t\tmsblk->meta_index[i].inode_number = 0;\n\t\t\tmsblk->meta_index[i].locked = 0;\n\t\t}\n\t\tmsblk->next_meta_index = 0;\n\t}\n\n\tfor (i = SQUASHFS_META_NUMBER; i &&\n\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n\t\t\tSQUASHFS_META_NUMBER;\n\n\tif (i == 0) {\n\t\tTRACE(\"empty_meta_index: failed!\\n\");\n\t\tgoto failed;\n\t}\n\n\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n\t\t\tmsblk->next_meta_index,\n\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n\n\tmeta = &msblk->meta_index[msblk->next_meta_index];\n\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n\t\t\tSQUASHFS_META_NUMBER;\n\n\tmeta->inode_number = inode->i_ino;\n\tmeta->offset = offset;\n\tmeta->skip = skip;\n\tmeta->entries = 0;\n\tmeta->locked = 1;\n\nfailed:\n\tmutex_unlock(&msblk->meta_index_mutex);\n\treturn meta;\n}\n\n\nvoid release_meta_index(struct inode *inode, struct meta_index *meta)\n{\n\tmeta->locked = 0;\n\tsmp_mb();\n}\n\n\nstatic int read_block_index(struct super_block *s, int blocks, char *block_list,\n\t\t\t\tlong long *start_block, int *offset)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tunsigned int *block_listp;\n\tint block = 0;\n\t\n\tif (msblk->swap) {\n\t\tchar *sblock_list;\n\n\t\tsblock_list = kmalloc(blocks << 2, GFP_KERNEL);\n\t\tif (unlikely(!sblock_list))\n\t\t\tgoto failure;\n\n\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n\t\t\tkfree(sblock_list);\n\t\t\tgoto failure;\n\t\t}\n\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n\t\t\t\t((unsigned int *)sblock_list), blocks);\n\t\tkfree(sblock_list);\n\t} else {\n\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tfor (block_listp = (unsigned int *) block_list; blocks;\n\t\t\t\tblock_listp++, blocks --)\n\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n\n\treturn block;\n\nfailure:\n\treturn -1;\n}\n\n\n#define SIZE 256\n\nstatic inline int calculate_skip(int blocks) {\n\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n\treturn skip >= 7 ? 7 : skip + 1;\n}\n\n\nstatic int get_meta_index(struct inode *inode, int index,\n\t\tlong long *index_block, int *index_offset,\n\t\tlong long *data_block, char *block_list)\n{\n\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n\tint offset = 0;\n\tstruct meta_index *meta;\n\tstruct meta_entry *meta_entry;\n\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n\tint cur_offset = SQUASHFS_I(inode)->offset;\n\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n\tint i;\n \n\tindex /= SQUASHFS_META_INDEXES * skip;\n\n\twhile (offset < index) {\n\t\tmeta = locate_meta_index(inode, index, offset + 1);\n\n\t\tif (meta == NULL) {\n\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n\t\t\tif (meta == NULL)\n\t\t\t\tgoto all_done;\n\t\t} else {\n\t\t\tif(meta->entries == 0)\n\t\t\t\tgoto failed;\n\t\t\t/* XXX */\n\t\t\toffset = index < meta->offset + meta->entries ? index :\n\t\t\t\tmeta->offset + meta->entries - 1;\n\t\t\t/* XXX */\n\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n\t\t\tcur_offset = meta_entry->offset;\n\t\t\tcur_data_block = meta_entry->data_block;\n\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n\t\t\t\tcur_offset, cur_data_block);\n\t\t}\n\n\t\tfor (i = meta->offset + meta->entries; i <= index &&\n\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n\n\t\t\twhile (blocks) {\n\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n\t\t\t\t\t&cur_index_block, &cur_offset);\n\n\t\t\t\tif (res == -1)\n\t\t\t\t\tgoto failed;\n\n\t\t\t\tcur_data_block += res;\n\t\t\t\tblocks -= block;\n\t\t\t}\n\n\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n\t\t\tmeta_entry->offset = cur_offset;\n\t\t\tmeta_entry->data_block = cur_data_block;\n\t\t\tmeta->entries ++;\n\t\t\toffset ++;\n\t\t}\n\n\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n\t\t\t\tmeta->offset, meta->entries);\n\n\t\trelease_meta_index(inode, meta);\n\t}\n\nall_done:\n\t*index_block = cur_index_block;\n\t*index_offset = cur_offset;\n\t*data_block = cur_data_block;\n\n\treturn offset * SQUASHFS_META_INDEXES * skip;\n\nfailed:\n\trelease_meta_index(inode, meta);\n\treturn -1;\n}\n\n\nstatic long long read_blocklist(struct inode *inode, int index,\n\t\t\t\tint readahead_blks, char *block_list,\n\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n{\n\tlong long block_ptr;\n\tint offset;\n\tlong long block;\n\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n\t\tblock_list);\n\n\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n\n\tif(res == -1)\n\t\tgoto failure;\n\n\tindex -= res;\n\n\twhile (index) {\n\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n\t\t\t&block_ptr, &offset);\n\t\tif (res == -1)\n\t\t\tgoto failure;\n\t\tblock += res;\n\t\tindex -= blocks;\n\t}\n\n\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n\t\tgoto failure;\n\t*bsize = *((unsigned int *) block_list);\n\n\treturn block;\n\nfailure:\n\treturn 0;\n}\n\n\nstatic int squashfs_readpage(struct file *file, struct page *page)\n{\n\tstruct inode *inode = page->mapping->host;\n\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tunsigned char *block_list = NULL;\n\tlong long block;\n\tunsigned int bsize, i;\n\tint bytes;\n\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n \tvoid *pageaddr;\n\tstruct squashfs_fragment_cache *fragment = NULL;\n\tchar *data_ptr = msblk->read_page;\n\t\n\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n\tint start_index = page->index & ~mask;\n\tint end_index = start_index | mask;\n\tint file_end = i_size_read(inode) >> sblk->block_log;\n\tint sparse = 0;\n\n\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n\n\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n\t\t\t\t\tPAGE_CACHE_SHIFT))\n\t\tgoto out;\n\n\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n\t\t\t\t\t|| index < file_end) {\n\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n\t\tif (block_list == NULL) {\n\t\t\tERROR(\"Failed to allocate block_list\\n\");\n\t\t\tgoto error_out;\n\t\t}\n\n\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n\t\tif (block == 0)\n\t\t\tgoto error_out;\n\n\t\tif (bsize == 0) { /* hole */\n\t\t\tbytes = index == file_end ?\n\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n\t\t\tsparse = 1;\n\t\t} else {\n\t\t\tmutex_lock(&msblk->read_page_mutex);\n\t\t\n\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n\t\t\t\tbsize, NULL, sblk->block_size);\n\n\t\t\tif (bytes == 0) {\n\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n\t\t\t\tgoto error_out;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfragment = get_cached_fragment(inode->i_sb,\n\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n\n\t\tif (fragment == NULL) {\n\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n\t\t\tgoto error_out;\n\t\t}\n\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n\t}\n\n\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n\t\tstruct page *push_page;\n\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n\n\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n\n\t\tpush_page = (i == page->index) ? page :\n\t\t\tgrab_cache_page_nowait(page->mapping, i);\n\n\t\tif (!push_page)\n\t\t\tcontinue;\n\n\t\tif (PageUptodate(push_page))\n\t\t\tgoto skip_page;\n\n \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n\t\tmemcpy(pageaddr, data_ptr, avail);\n\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n\t\tkunmap_atomic(pageaddr, KM_USER0);\n\t\tflush_dcache_page(push_page);\n\t\tSetPageUptodate(push_page);\nskip_page:\n\t\tunlock_page(push_page);\n\t\tif(i != page->index)\n\t\t\tpage_cache_release(push_page);\n\t}\n\n\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n\t\t\t\t\t|| index < file_end) {\n\t\tif (!sparse)\n\t\t\tmutex_unlock(&msblk->read_page_mutex);\n\t\tkfree(block_list);\n\t} else\n\t\trelease_cached_fragment(msblk, fragment);\n\n\treturn 0;\n\nerror_out:\n\tSetPageError(page);\nout:\n\tpageaddr = kmap_atomic(page, KM_USER0);\n\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n\tkunmap_atomic(pageaddr, KM_USER0);\n\tflush_dcache_page(page);\n\tif (!PageError(page))\n\t\tSetPageUptodate(page);\n\tunlock_page(page);\n\n\tkfree(block_list);\n\treturn 0;\n}\n\n\nstatic int get_dir_index_using_offset(struct super_block *s,\n\t\t\t\tlong long *next_block, unsigned int *next_offset,\n\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n\t\t\t\tlong long f_pos)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tint i, length = 0;\n\tstruct squashfs_dir_index index;\n\n\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n\t\t\t\t\ti_count, (unsigned int) f_pos);\n\n\tf_pos =- 3;\n\tif (f_pos == 0)\n\t\tgoto finish;\n\n\tfor (i = 0; i < i_count; i++) {\n\t\tif (msblk->swap) {\n\t\t\tstruct squashfs_dir_index sindex;\n\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t} else\n\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n\n\t\tif (index.index > f_pos)\n\t\t\tbreak;\n\n\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n\n\t\tlength = index.index;\n\t\t*next_block = index.start_block + sblk->directory_table_start;\n\t}\n\n\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n\nfinish:\n\treturn length + 3;\n}\n\n\nstatic int get_dir_index_using_name(struct super_block *s,\n\t\t\t\tlong long *next_block, unsigned int *next_offset,\n\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n\t\t\t\tconst char *name, int size)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tint i, length = 0;\n\tstruct squashfs_dir_index *index;\n\tchar *str;\n\n\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n\n\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n\tif (str == NULL) {\n\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n\t\tgoto failure;\n\t}\n\n\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n\tstrncpy(str, name, size);\n\tstr[size] = '\\0';\n\n\tfor (i = 0; i < i_count; i++) {\n\t\tif (msblk->swap) {\n\t\t\tstruct squashfs_dir_index sindex;\n\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n\t\t} else\n\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n\n\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n\n\t\tindex->name[index->size + 1] = '\\0';\n\n\t\tif (strcmp(index->name, str) > 0)\n\t\t\tbreak;\n\n\t\tlength = index->index;\n\t\t*next_block = index->start_block + sblk->directory_table_start;\n\t}\n\n\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n\tkfree(str);\n\nfailure:\n\treturn length + 3;\n}\n\n\t\t\nstatic int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n{\n\tstruct inode *i = file->f_dentry->d_inode;\n\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tlong long next_block = SQUASHFS_I(i)->start_block +\n\t\tsblk->directory_table_start;\n\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n\tstruct squashfs_dir_header dirh;\n\tstruct squashfs_dir_entry *dire;\n\n\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n\n\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n\tif (dire == NULL) {\n\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n\t\tgoto finish;\n\t}\n\n\twhile(file->f_pos < 3) {\n\t\tchar *name;\n\t\tint size, i_ino;\n\n\t\tif(file->f_pos == 0) {\n\t\t\tname = \".\";\n\t\t\tsize = 1;\n\t\t\ti_ino = i->i_ino;\n\t\t} else {\n\t\t\tname = \"..\";\n\t\t\tsize = 2;\n\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n\t\t}\n\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n\t\t\t\t(unsigned int) dirent, name, size, (int)\n\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n\n\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n\t\t\tgoto finish;\n\t\t}\n\t\tfile->f_pos += size;\n\t}\n\n\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n\n\twhile (length < i_size_read(i)) {\n\t\t/* read directory header */\n\t\tif (msblk->swap) {\n\t\t\tstruct squashfs_dir_header sdirh;\n\t\t\t\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += sizeof(sdirh);\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else {\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += sizeof(dirh);\n\t\t}\n\n\t\tdir_count = dirh.count + 1;\n\t\twhile (dir_count--) {\n\t\t\tif (msblk->swap) {\n\t\t\t\tstruct squashfs_dir_entry sdire;\n\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\t\n\t\t\t\tlength += sizeof(sdire);\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else {\n\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\t\tlength += sizeof(*dire);\n\t\t\t}\n\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += dire->size + 1;\n\n\t\t\tif (file->f_pos >= length)\n\t\t\t\tcontinue;\n\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\n\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n\t\t\t\t\tdirh.inode_number + dire->inode_number,\n\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n\n\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n\t\t\t\t\tdirh.inode_number + dire->inode_number,\n\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\tfile->f_pos = length;\n\t\t}\n\t}\n\nfinish:\n\tkfree(dire);\n\treturn 0;\n\nfailed_read:\n\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n\t\tnext_offset);\n\tkfree(dire);\n\treturn 0;\n}\n\n\nstatic struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n\t\t\t\tstruct nameidata *nd)\n{\n\tconst unsigned char *name = dentry->d_name.name;\n\tint len = dentry->d_name.len;\n\tstruct inode *inode = NULL;\n\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tlong long next_block = SQUASHFS_I(i)->start_block +\n\t\t\t\tsblk->directory_table_start;\n\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n\tstruct squashfs_dir_header dirh;\n\tstruct squashfs_dir_entry *dire;\n\n\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n\n\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n\tif (dire == NULL) {\n\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n\t\tgoto exit_lookup;\n\t}\n\n\tif (len > SQUASHFS_NAME_LEN)\n\t\tgoto exit_lookup;\n\n\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n\n\twhile (length < i_size_read(i)) {\n\t\t/* read directory header */\n\t\tif (msblk->swap) {\n\t\t\tstruct squashfs_dir_header sdirh;\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += sizeof(sdirh);\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else {\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += sizeof(dirh);\n\t\t}\n\n\t\tdir_count = dirh.count + 1;\n\t\twhile (dir_count--) {\n\t\t\tif (msblk->swap) {\n\t\t\t\tstruct squashfs_dir_entry sdire;\n\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\t\n\t\t\t\tlength += sizeof(sdire);\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else {\n\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\t\tlength += sizeof(*dire);\n\t\t\t}\n\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += dire->size + 1;\n\n\t\t\tif (name[0] < dire->name[0])\n\t\t\t\tgoto exit_lookup;\n\n\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n\t\t\t\t\t\t\t\tdire->offset);\n\n\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n\t\t\t\t\tdirh.inode_number + dire->inode_number);\n\n\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n\n\t\t\t\tgoto exit_lookup;\n\t\t\t}\n\t\t}\n\t}\n\nexit_lookup:\n\tkfree(dire);\n\tif (inode)\n\t\treturn d_splice_alias(inode, dentry);\n\td_add(dentry, inode);\n\treturn ERR_PTR(0);\n\nfailed_read:\n\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n\t\tnext_offset);\n\tgoto exit_lookup;\n}\n\n\nstatic int squashfs_remount(struct super_block *s, int *flags, char *data)\n{\n\t*flags |= MS_RDONLY;\n\treturn 0;\n}\n\n\nstatic void squashfs_put_super(struct super_block *s)\n{\n\tint i;\n\n\tif (s->s_fs_info) {\n\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n\t\tif (sbi->block_cache)\n\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n\t\t\t\t\tvfree(sbi->block_cache[i].data);\n\t\tif (sbi->fragment)\n\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n\t\t\t\tvfree(sbi->fragment[i].data);\n\t\tkfree(sbi->fragment);\n\t\tkfree(sbi->block_cache);\n\t\tvfree(sbi->read_page);\n\t\tkfree(sbi->uid);\n\t\tkfree(sbi->fragment_index);\n\t\tkfree(sbi->fragment_index_2);\n\t\tkfree(sbi->meta_index);\n\t\tkfree(s->s_fs_info);\n\t\ts->s_fs_info = NULL;\n\t}\n}\n\n\nstatic int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n{\n\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n\t\t\t\tmnt);\n}\n\nstatic void free_sqlzma(void)\n{\n\tint cpu;\n\tstruct sqlzma *p;\n\n\tfor_each_online_cpu(cpu) {\n\t\tp = per_cpu(sqlzma, cpu);\n\t\tif (p) {\n#ifdef KeepPreemptive\n\t\t\tmutex_destroy(&p->mtx);\n#endif\n\t\t\tsqlzma_fin(&p->un);\n\t\t\tkfree(p);\n\t\t}\n\t}\n}\n\nstatic int __init init_squashfs_fs(void)\n{\n\tstruct sqlzma *p;\n\tint cpu;\n\tint err = init_inodecache();\n\tif (err)\n\t\tgoto out;\n\n\tfor_each_online_cpu(cpu) {\n\t\tdpri(\"%d: %p\\n\", cpu, per_cpu(sqlzma, cpu));\n\t\terr = -ENOMEM;\n\t\tp = kmalloc(sizeof(struct sqlzma), GFP_KERNEL);\n\t\tif (p) {\n#ifdef KeepPreemptive\n\t\t\tmutex_init(&p->mtx);\n#endif\n\t\t\terr = sqlzma_init(&p->un, 1, 0);\n\t\t\tif (unlikely(err)) {\n\t\t\t\tERROR(\"Failed to intialize uncompress workspace\\n\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tper_cpu(sqlzma, cpu) = p;\n\t\t\terr = 0;\n\t\t} else\n\t\t\tbreak;\n\t}\n\tif (unlikely(err)) {\n\t\tfree_sqlzma();\n\t\tgoto out;\n\t}\n\n\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n\t\t\"Phillip Lougher\\n\"\n\t\t\"squashfs: LZMA suppport for slax.org by jro\\n\");\n\n\terr = register_filesystem(&squashfs_fs_type);\n\tif (err) {\n\t\tfree_sqlzma();\n\t\tdestroy_inodecache();\n\t}\n\nout:\n\treturn err;\n}\n\n\nstatic void __exit exit_squashfs_fs(void)\n{\n\tunregister_filesystem(&squashfs_fs_type);\n\tfree_sqlzma();\n\tdestroy_inodecache();\n}\n\n\nstatic struct kmem_cache * squashfs_inode_cachep;\n\n\nstatic struct inode *squashfs_alloc_inode(struct super_block *sb)\n{\n\tstruct squashfs_inode_info *ei;\n\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n\treturn ei ? &ei->vfs_inode : NULL;\n}\n\n\nstatic void squashfs_destroy_inode(struct inode *inode)\n{\n\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n}\n\n\nstatic void init_once(struct kmem_cache *cachep, void *foo)\n{\n\tstruct squashfs_inode_info *ei = foo;\n\n\tinode_init_once(&ei->vfs_inode);\n}\n \n\nstatic int __init init_inodecache(void)\n{\n\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n\t    sizeof(struct squashfs_inode_info), 0,\n\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);\n\tif (squashfs_inode_cachep == NULL)\n\t\treturn -ENOMEM;\n\treturn 0;\n}\n\n\nstatic void destroy_inodecache(void)\n{\n\tkmem_cache_destroy(squashfs_inode_cachep);\n}\n\n\nmodule_init(init_squashfs_fs);\nmodule_exit(exit_squashfs_fs);\nMODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem, and LZMA suppport for slax.org\");\nMODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>, and LZMA suppport for slax.org by jro\");\nMODULE_LICENSE(\"GPL\");\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/ksquashfs/fs/squashfs/squashfs.h",
    "content": "/*\n * Squashfs - a compressed read only filesystem for Linux\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs.h\n */\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n#endif\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n#else\n#define TRACE(s, args...)\t{}\n#endif\n\n#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n\n#define SERROR(s, args...)\tdo { \\\n\t\t\t\tif (!silent) \\\n\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n\t\t\t\t} while(0)\n\n#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n\nstatic inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n{\n\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n}\n\n#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n#define SQSH_EXTERN\nextern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n\t\t\t\tlong long index, unsigned int length,\n\t\t\t\tlong long *next_index, int srclength);\nextern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n\t\t\t\tlong long block, unsigned int offset,\n\t\t\t\tint length, long long *next_block,\n\t\t\t\tunsigned int *next_offset);\nextern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n\t\t\t\t\tsquashfs_fragment_cache *fragment);\nextern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n\t\t\t\t\t*s, long long start_block,\n\t\t\t\t\tint length);\nextern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\nextern const struct address_space_operations squashfs_symlink_aops;\nextern const struct address_space_operations squashfs_aops;\nextern struct inode_operations squashfs_dir_inode_ops;\n#else\n#define SQSH_EXTERN static\n#endif\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\nextern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n#else\nstatic inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n{\n\treturn 0;\n}\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\nextern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n#else\nstatic inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n{\n\treturn 0;\n}\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/ksquashfs/fs/squashfs/squashfs2_0.c",
    "content": "/*\n * Squashfs - a compressed read only filesystem for Linux\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs2_0.c\n */\n\n#include <linux/squashfs_fs.h>\n#include <linux/module.h>\n#include <linux/zlib.h>\n#include <linux/fs.h>\n#include <linux/squashfs_fs_sb.h>\n#include <linux/squashfs_fs_i.h>\n\n#include \"squashfs.h\"\nstatic int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\nstatic struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n\t\t\t\tstruct nameidata *);\n\nstatic struct file_operations squashfs_dir_ops_2 = {\n\t.read = generic_read_dir,\n\t.readdir = squashfs_readdir_2\n};\n\nstatic struct inode_operations squashfs_dir_inode_ops_2 = {\n\t.lookup = squashfs_lookup_2\n};\n\nstatic unsigned char squashfs_filetype_table[] = {\n\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n};\n\nstatic int read_fragment_index_table_2(struct super_block *s)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\n\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n\t\treturn 0;\n\t}\n   \n\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n\t\t\t\t\t!squashfs_read_data(s, (char *)\n\t\t\t\t\tmsblk->fragment_index_2,\n\t\t\t\t\tsblk->fragment_table_start,\n\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n\t\t\t\t\t(sblk->fragments) |\n\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n\t\tERROR(\"unable to read fragment index table\\n\");\n\t\treturn 0;\n\t}\n\n\tif (msblk->swap) {\n\t\tint i;\n\t\tunsigned int fragment;\n\n\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n\t\t\t\t\t\t\t\t\ti++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n\t\t\tmsblk->fragment_index_2[i] = fragment;\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nstatic int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n\t\t\t\tlong long *fragment_start_block,\n\t\t\t\tunsigned int *fragment_size)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tlong long start_block =\n\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n\tstruct squashfs_fragment_entry_2 fragment_entry;\n\n\tif (msblk->swap) {\n\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n\n\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n\t\t\t\t\tstart_block, offset,\n\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n\t\t\t\t\t&offset))\n\t\t\tgoto out;\n\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n\t} else\n\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n\t\t\t\t\tstart_block, offset,\n\t\t\t\t\tsizeof(fragment_entry), &start_block,\n\t\t\t\t\t&offset))\n\t\t\tgoto out;\n\n\t*fragment_start_block = fragment_entry.start_block;\n\t*fragment_size = fragment_entry.size;\n\n\treturn 1;\n\nout:\n\treturn 0;\n}\n\n\nstatic void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n{\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\n\ti->i_ino = ino;\n\ti->i_mtime.tv_sec = sblk->mkfs_time;\n\ti->i_atime.tv_sec = sblk->mkfs_time;\n\ti->i_ctime.tv_sec = sblk->mkfs_time;\n\ti->i_uid = msblk->uid[inodeb->uid];\n\ti->i_mode = inodeb->mode;\n\ti->i_nlink = 1;\n\ti->i_size = 0;\n\tif (inodeb->guid == SQUASHFS_GUIDS)\n\t\ti->i_gid = i->i_uid;\n\telse\n\t\ti->i_gid = msblk->guid[inodeb->guid];\n}\n\n\nstatic int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n{\n\tstruct super_block *s = i->i_sb;\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n\t\tsblk->inode_table_start;\n\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n\t\tsblk->inode_table_start, offset);\n\tlong long next_block;\n\tunsigned int next_offset;\n\tunion squashfs_inode_header_2 id, sid;\n\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n\t\t\t\t\t  *sinodeb = &sid.base;\n\n\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n\n\tif (msblk->swap) {\n\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n\t\t\t\t\t&next_offset))\n\t\t\tgoto failed_read;\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n\t\t\t\t\tsizeof(*sinodeb));\n\t} else\n\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n\t\t\t\t\t&next_offset))\n\t\t\tgoto failed_read;\n\n\tsquashfs_new_inode(msblk, i, inodeb, ino);\n\n\tswitch(inodeb->inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n\t\t\tlong long frag_blk;\n\t\t\tunsigned int frag_size = 0;\n\t\t\t\t\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tsinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n\t\t\t} else\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tinodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n\t\t\t\t\t!get_fragment_location_2(s,\n\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n\t\t\t\tgoto failed_read;\n\t\t\t\t\n\t\t\ti->i_size = inodep->file_size;\n\t\t\ti->i_fop = &generic_ro_fops;\n\t\t\ti->i_mode |= S_IFREG;\n\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n\t\t\ti->i_atime.tv_sec = inodep->mtime;\n\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n\t\t\tSQUASHFS_I(i)->offset = next_offset;\n\t\t\ti->i_data.a_ops = &squashfs_aops;\n\n\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n\t\t\t\t\tinodep->start_block, next_block,\n\t\t\t\t\tnext_offset);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tsinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n\t\t\t} else\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tinodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\ti->i_size = inodep->file_size;\n\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n\t\t\ti->i_fop = &squashfs_dir_ops_2;\n\t\t\ti->i_mode |= S_IFDIR;\n\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n\t\t\ti->i_atime.tv_sec = inodep->mtime;\n\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n\n\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n\t\t\t\t\toffset, inodep->start_block,\n\t\t\t\t\tinodep->offset);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tsinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n\t\t\t\t\t\tsinodep);\n\t\t\t} else\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tinodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\ti->i_size = inodep->file_size;\n\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n\t\t\ti->i_fop = &squashfs_dir_ops_2;\n\t\t\ti->i_mode |= S_IFDIR;\n\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n\t\t\ti->i_atime.tv_sec = inodep->mtime;\n\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n\t\t\t\t\t\t\t\tnext_offset;\n\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n\t\t\t\t\t\t\t\tinodep->i_count;\n\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n\n\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n\t\t\t\t\t\"offset %x\\n\",\n\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n\t\t\t\t\tinodep->start_block, inodep->offset);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n\t\t\t\t\t\t\t\t&id.symlink;\n\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n\t\t\t\t\t\t\t\t&sid.symlink;\n\t\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tsinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n\t\t\t\t\t\t\t\tsinodep);\n\t\t\t} else\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tinodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\ti->i_size = inodep->symlink_size;\n\t\t\ti->i_op = &page_symlink_inode_operations;\n\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n\t\t\ti->i_mode |= S_IFLNK;\n\t\t\tSQUASHFS_I(i)->start_block = next_block;\n\t\t\tSQUASHFS_I(i)->offset = next_offset;\n\n\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n\t\t\t\t\t\"offset %x\\n\",\n\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n\t\t\t\t\tnext_block, next_offset);\n\t\t\tbreak;\n\t\t }\n\t\t case SQUASHFS_BLKDEV_TYPE:\n\t\t case SQUASHFS_CHRDEV_TYPE: {\n\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n\n\t\t\tif (msblk->swap) {\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tsinodep, block, offset,\n\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n\t\t\t} else\t\n\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n\t\t\t\t\t\tinodep, block, offset,\n\t\t\t\t\t\tsizeof(*inodep), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\ti->i_mode |= (inodeb->inode_type ==\n\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n\t\t\t\t\tS_IFBLK;\n\t\t\tinit_special_inode(i, i->i_mode,\n\t\t\t\t\told_decode_dev(inodep->rdev));\n\n\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n\t\t\t\t\tinodep->rdev);\n\t\t\tbreak;\n\t\t }\n\t\t case SQUASHFS_FIFO_TYPE:\n\t\t case SQUASHFS_SOCKET_TYPE: {\n\n\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n\t\t\tinit_special_inode(i, i->i_mode, 0);\n\t\t\tbreak;\n\t\t }\n\t\t default:\n\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n\t\t\t\t\tinodeb->inode_type);\n\t\t\tgoto failed_read1;\n\t}\n\t\n\treturn 1;\n\nfailed_read:\n\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n\nfailed_read1:\n\treturn 0;\n}\n\n\nstatic int get_dir_index_using_offset(struct super_block *s, long long \n\t\t\t\t*next_block, unsigned int *next_offset,\n\t\t\t\tlong long index_start,\n\t\t\t\tunsigned int index_offset, int i_count,\n\t\t\t\tlong long f_pos)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tint i, length = 0;\n\tstruct squashfs_dir_index_2 index;\n\n\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n\t\t\t\t\ti_count, (unsigned int) f_pos);\n\n\tif (f_pos == 0)\n\t\tgoto finish;\n\n\tfor (i = 0; i < i_count; i++) {\n\t\tif (msblk->swap) {\n\t\t\tstruct squashfs_dir_index_2 sindex;\n\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n\t\t\t\t\tindex_start, index_offset,\n\t\t\t\t\tsizeof(sindex), &index_start,\n\t\t\t\t\t&index_offset);\n\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n\t\t} else\n\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n\t\t\t\t\tindex_start, index_offset,\n\t\t\t\t\tsizeof(index), &index_start,\n\t\t\t\t\t&index_offset);\n\n\t\tif (index.index > f_pos)\n\t\t\tbreak;\n\n\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n\t\t\t\t\tindex.size + 1, &index_start,\n\t\t\t\t\t&index_offset);\n\n\t\tlength = index.index;\n\t\t*next_block = index.start_block + sblk->directory_table_start;\n\t}\n\n\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n\nfinish:\n\treturn length;\n}\n\n\nstatic int get_dir_index_using_name(struct super_block *s, long long\n\t\t\t\t*next_block, unsigned int *next_offset,\n\t\t\t\tlong long index_start,\n\t\t\t\tunsigned int index_offset, int i_count,\n\t\t\t\tconst char *name, int size)\n{\n\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tint i, length = 0;\n\tstruct squashfs_dir_index_2 *index;\n\tchar *str;\n\n\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n\n\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n\t\tgoto failure;\n\t}\n\n\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n\tstrncpy(str, name, size);\n\tstr[size] = '\\0';\n\n\tfor (i = 0; i < i_count; i++) {\n\t\tif (msblk->swap) {\n\t\t\tstruct squashfs_dir_index_2 sindex;\n\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n\t\t\t\t\tindex_start, index_offset,\n\t\t\t\t\tsizeof(sindex), &index_start,\n\t\t\t\t\t&index_offset);\n\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n\t\t} else\n\t\t\tsquashfs_get_cached_block(s, (char *) index,\n\t\t\t\t\tindex_start, index_offset,\n\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n\t\t\t\t\t&index_start, &index_offset);\n\n\t\tsquashfs_get_cached_block(s, index->name, index_start,\n\t\t\t\t\tindex_offset, index->size + 1,\n\t\t\t\t\t&index_start, &index_offset);\n\n\t\tindex->name[index->size + 1] = '\\0';\n\n\t\tif (strcmp(index->name, str) > 0)\n\t\t\tbreak;\n\n\t\tlength = index->index;\n\t\t*next_block = index->start_block + sblk->directory_table_start;\n\t}\n\n\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n\tkfree(str);\nfailure:\n\treturn length;\n}\n\n\t\t\nstatic int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n{\n\tstruct inode *i = file->f_dentry->d_inode;\n\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tlong long next_block = SQUASHFS_I(i)->start_block +\n\t\tsblk->directory_table_start;\n\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n\t\tdir_count;\n\tstruct squashfs_dir_header_2 dirh;\n\tstruct squashfs_dir_entry_2 *dire;\n\n\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n\n\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n\t\tgoto finish;\n\t}\n\n\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n\t\t\t\tfile->f_pos);\n\n\twhile (length < i_size_read(i)) {\n\t\t/* read directory header */\n\t\tif (msblk->swap) {\n\t\t\tstruct squashfs_dir_header_2 sdirh;\n\t\t\t\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n\t\t\t\t\t&next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += sizeof(sdirh);\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else {\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n\t\t\t\t\t&next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += sizeof(dirh);\n\t\t}\n\n\t\tdir_count = dirh.count + 1;\n\t\twhile (dir_count--) {\n\t\t\tif (msblk->swap) {\n\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n\t\t\t\t\t\t&sdire, next_block, next_offset,\n\t\t\t\t\t\tsizeof(sdire), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\t\n\t\t\t\tlength += sizeof(sdire);\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else {\n\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n\t\t\t\t\t\tdire, next_block, next_offset,\n\t\t\t\t\t\tsizeof(*dire), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\t\tlength += sizeof(*dire);\n\t\t\t}\n\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n\t\t\t\t\t\tnext_block, next_offset,\n\t\t\t\t\t\tdire->size + 1, &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += dire->size + 1;\n\n\t\t\tif (file->f_pos >= length)\n\t\t\t\tcontinue;\n\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\n\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n\t\t\t\t\t(unsigned int) dirent, dire->name,\n\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n\t\t\t\t\tdirh.start_block, dire->offset,\n\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n\n\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n\t\t\t\t\tdirh.start_block, dire->offset),\n\t\t\t\t\tsquashfs_filetype_table[dire->type])\n\t\t\t\t\t< 0) {\n\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n\t\t\t\tgoto finish;\n\t\t\t}\n\t\t\tfile->f_pos = length;\n\t\t}\n\t}\n\nfinish:\n\tkfree(dire);\n\treturn 0;\n\nfailed_read:\n\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n\t\tnext_offset);\n\tkfree(dire);\n\treturn 0;\n}\n\n\nstatic struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n\t\t\t\tstruct nameidata *nd)\n{\n\tconst unsigned char *name = dentry->d_name.name;\n\tint len = dentry->d_name.len;\n\tstruct inode *inode = NULL;\n\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\tlong long next_block = SQUASHFS_I(i)->start_block +\n\t\t\t\tsblk->directory_table_start;\n\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n\t\t\t\tdir_count;\n\tstruct squashfs_dir_header_2 dirh;\n\tstruct squashfs_dir_entry_2 *dire;\n\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n\n\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n\n\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n\t\tgoto exit_loop;\n\t}\n\n\tif (len > SQUASHFS_NAME_LEN)\n\t\tgoto exit_loop;\n\n\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n\t\t\t\tlen);\n\n\twhile (length < i_size_read(i)) {\n\t\t/* read directory header */\n\t\tif (msblk->swap) {\n\t\t\tstruct squashfs_dir_header_2 sdirh;\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n\t\t\t\t\t&next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += sizeof(sdirh);\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else {\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n\t\t\t\t\t&next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += sizeof(dirh);\n\t\t}\n\n\t\tdir_count = dirh.count + 1;\n\t\twhile (dir_count--) {\n\t\t\tif (msblk->swap) {\n\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n\t\t\t\t\t\t&sdire, next_block,next_offset,\n\t\t\t\t\t\tsizeof(sdire), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\t\t\t\t\n\t\t\t\tlength += sizeof(sdire);\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else {\n\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n\t\t\t\t\t\tdire, next_block,next_offset,\n\t\t\t\t\t\tsizeof(*dire), &next_block,\n\t\t\t\t\t\t&next_offset))\n\t\t\t\t\tgoto failed_read;\n\n\t\t\t\tlength += sizeof(*dire);\n\t\t\t}\n\n\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n\t\t\t\t\t&next_block, &next_offset))\n\t\t\t\tgoto failed_read;\n\n\t\t\tlength += dire->size + 1;\n\n\t\t\tif (sorted && name[0] < dire->name[0])\n\t\t\t\tgoto exit_loop;\n\n\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n\t\t\t\t\t\tdire->name, len)) {\n\t\t\t\tsquashfs_inode_t ino =\n\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n\t\t\t\t\tdire->offset);\n\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n\t\t\t\t\tdire->offset);\n\n\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n\t\t\t\t\tdirh.start_block, dire->offset, ino);\n\n\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n\n\t\t\t\tgoto exit_loop;\n\t\t\t}\n\t\t}\n\t}\n\nexit_loop:\n\tkfree(dire);\n\td_add(dentry, inode);\n\treturn ERR_PTR(0);\n\nfailed_read:\n\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n\t\tnext_offset);\n\tgoto exit_loop;\n}\n\n\nint squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n{\n\tstruct squashfs_super_block *sblk = &msblk->sblk;\n\n\tmsblk->read_inode = squashfs_read_inode_2;\n\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n\n\tsblk->bytes_used = sblk->bytes_used_2;\n\tsblk->uid_start = sblk->uid_start_2;\n\tsblk->guid_start = sblk->guid_start_2;\n\tsblk->inode_table_start = sblk->inode_table_start_2;\n\tsblk->directory_table_start = sblk->directory_table_start_2;\n\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n\n\treturn 1;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/ksquashfs/include/linux/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t1\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tsigned int\t\tinode_number:16; /* very important signedness */\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/ksquashfs/include/linux/squashfs_fs_i.h",
    "content": "#ifndef SQUASHFS_FS_I\n#define SQUASHFS_FS_I\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs_i.h\n */\n\nstruct squashfs_inode_info {\n\tlong long\tstart_block;\n\tunsigned int\toffset;\n\tunion {\n\t\tstruct {\n\t\t\tlong long\tfragment_start_block;\n\t\t\tunsigned int\tfragment_size;\n\t\t\tunsigned int\tfragment_offset;\n\t\t\tlong long\tblock_list_start;\n\t\t} s1;\n\t\tstruct {\n\t\t\tlong long\tdirectory_index_start;\n\t\t\tunsigned int\tdirectory_index_offset;\n\t\t\tunsigned int\tdirectory_index_count;\n\t\t\tunsigned int\tparent_inode;\n\t\t} s2;\n\t} u;\n\tstruct inode\tvfs_inode;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/ksquashfs/include/linux/squashfs_fs_sb.h",
    "content": "#ifndef SQUASHFS_FS_SB\n#define SQUASHFS_FS_SB\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs_sb.h\n */\n\n#include <linux/squashfs_fs.h>\n\nstruct squashfs_cache {\n\tlong long\tblock;\n\tint\t\tlength;\n\tlong long\tnext_index;\n\tchar\t\t*data;\n};\n\nstruct squashfs_fragment_cache {\n\tlong long\tblock;\n\tint\t\tlength;\n\tunsigned int\tlocked;\n\tchar\t\t*data;\n};\n\nstruct squashfs_sb_info {\n\tstruct squashfs_super_block\tsblk;\n\tint\t\t\tdevblksize;\n\tint\t\t\tdevblksize_log2;\n\tint\t\t\tswap;\n\tstruct squashfs_cache\t*block_cache;\n\tstruct squashfs_fragment_cache\t*fragment;\n\tint\t\t\tnext_cache;\n\tint\t\t\tnext_fragment;\n\tint\t\t\tnext_meta_index;\n\tunsigned int\t\t*uid;\n\tunsigned int\t\t*guid;\n\tlong long\t\t*fragment_index;\n\tunsigned int\t\t*fragment_index_2;\n\tchar\t\t\t*read_page;\n\t/* struct mutex\t\tread_data_mutex; */\n\tstruct mutex\t\tread_page_mutex;\n\tstruct mutex\t\tblock_cache_mutex;\n\tstruct mutex\t\tfragment_mutex;\n\tstruct mutex\t\tmeta_index_mutex;\n\twait_queue_head_t\twaitq;\n\twait_queue_head_t\tfragment_wait_queue;\n\tstruct meta_index\t*meta_index;\n\t/* z_stream\t\tstream; */\n\tlong long\t\t*inode_lookup_table;\n\tint\t\t\tunused_cache_blks;\n\tint\t\t\tunused_frag_blks;\n\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n\t\t\t\tinode);\n\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n\t\t\t\tindex, int readahead_blks, char *block_list, \\\n\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/7zC.txt",
    "content": "7z ANSI-C Decoder 4.48\r\n----------------------\r\n\r\n7z ANSI-C Decoder 4.48 Copyright (C) 1999-2006 Igor Pavlov\r\n\r\n7z ANSI-C provides 7z/LZMA decoding.\r\n7z ANSI-C version is simplified version ported from C++ code.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nRead lzma.txt for information about license.\r\n\r\n\r\nFiles\r\n---------------------\r\n\r\n7zAlloc.*    - Allocate and Free\r\n7zBuffer.*   - Buffer structure\r\n7zCrc.*      - CRC32 code\r\n7zDecode.*   - Low level memory->memory decoding\r\n7zExtract.*  - High level stream->memory decoding\r\n7zHeader.*   - .7z format constants\r\n7zIn.*       - .7z archive opening\r\n7zItem.*     - .7z structures\r\n7zMain.c     - Test application\r\n7zMethodID.* - MethodID structure\r\n7zTypes.h    - Base types and constants\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nYou must download 7-Zip program from www.7-zip.org.\r\n\r\nYou can create .7z archive with 7z.exe or 7za.exe:\r\n\r\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255\r\n\r\nIf you have big number of files in archive, and you need fast extracting, \r\nyou can use partly-solid archives:\r\n  \r\n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\r\n\r\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r\n512KB for extracting one file from such archive.\r\n\r\n\r\nLimitations of current version of 7z ANSI-C Decoder\r\n---------------------------------------------------\r\n\r\n - It reads only \"FileName\", \"Size\", \"LastWriteTime\" and \"CRC\" information for each file in archive.\r\n - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.\r\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r\n \r\nThese limitations will be fixed in future versions.\r\n\r\n\r\nUsing 7z ANSI-C Decoder Test application:\r\n-----------------------------------------\r\n\r\nUsage: 7zDec <command> <archive_name>\r\n\r\n<Command>:\r\n  e: Extract files from archive\r\n  l: List contents of archive\r\n  t: Test integrity of archive\r\n\r\nExample: \r\n\r\n  7zDec l archive.7z\r\n\r\nlists contents of archive.7z\r\n\r\n  7zDec e archive.7z\r\n\r\nextracts files from archive.7z to current folder.\r\n\r\n\r\nHow to use .7z Decoder\r\n----------------------\r\n\r\n.7z Decoder can be compiled in one of two modes:\r\n\r\n1) Default mode. In that mode 7z Decoder will read full compressed \r\n   block to RAM before decompressing.\r\n  \r\n2) Mode with defined _LZMA_IN_CB. In that mode 7z Decoder can read\r\n   compressed block by parts. And you can specify desired buffer size. \r\n   So memory requirements can be reduced. But decompressing speed will \r\n   be 5-10% lower and code size is slightly larger.\r\n\r\n   \r\nMemory allocation\r\n~~~~~~~~~~~~~~~~~\r\n\r\n7z Decoder uses two memory pools:\r\n1) Temporary pool\r\n2) Main pool\r\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\r\n\r\nSteps for using 7z decoder\r\n--------------------------\r\n\r\nUse code at 7zMain.c as example.\r\n\r\n1) Declare variables:\r\n  inStream                     /* implements ISzInStream interface */\r\n  CArchiveDatabaseEx db;       /* 7z archive database structure */\r\n  ISzAlloc allocImp;           /* memory functions for main pool */\r\n  ISzAlloc allocTempImp;       /* memory functions for temporary pool */\r\n\r\n2) call InitCrcTable(); function to initialize CRC structures.\r\n\r\n3) call SzArDbExInit(&db); function to initialize db structures.\r\n\r\n4) call SzArchiveOpen(inStream, &db, &allocMain, &allocTemp) to open archive\r\n\r\nThis function opens archive \"inStream\" and reads headers to \"db\".\r\nAll items in \"db\" will be allocated with \"allocMain\" functions.\r\nSzArchiveOpen function allocates and frees temporary structures by \"allocTemp\" functions.\r\n\r\n5) List items or Extract items\r\n\r\n  Listing code:\r\n  ~~~~~~~~~~~~~\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n\r\n  Extracting code:\r\n  ~~~~~~~~~~~~~~~~\r\n\r\n  SZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n  If you need to decompress more than one file, you can send these values from previous call:\r\n    blockIndex, \r\n    outBuffer, \r\n    outBufferSize,\r\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \r\n  it will increase decompression speed.\r\n\r\n  After decompressing you must free \"outBuffer\":\r\n  allocImp.Free(outBuffer);\r\n\r\n6) call SzArDbExFree(&db, allocImp.Free) to free allocated items in \"db\".\r\n\r\n\r\n\r\n\r\nMemory requirements for .7z decoding \r\n------------------------------------\r\n\r\nMemory usage for Archive opening:\r\n  - Temporary pool:\r\n     - Memory for compressed .7z headers (if _LZMA_IN_CB is not defined)\r\n     - Memory for uncompressed .7z headers\r\n     - some other temporary blocks\r\n  - Main pool:\r\n     - Memory for database: \r\n       Estimated size of one file structures in solid archive:\r\n         - Size (4 or 8 Bytes)\r\n         - CRC32 (4 bytes)\r\n         - LastWriteTime (8 bytes)\r\n         - Some file information (4 bytes)\r\n         - File Name (variable length) + pointer + allocation structures\r\n\r\nMemory usage for archive Decompressing:\r\n  - Temporary pool:\r\n     - Memory for compressed solid block (if _LZMA_IN_CB is not defined)\r\n     - Memory for LZMA decompressing structures\r\n  - Main pool:\r\n     - Memory for decompressed solid block\r\n     - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these \r\n       temprorary buffers can be about 15% of solid block size. \r\n  \r\n\r\nIf _LZMA_IN_CB is defined, 7z Decoder will not allocate memory for \r\ncompressed blocks. Instead of this, you must allocate buffer with desired \r\nsize before calling 7z Decoder. Use 7zMain.c as example.\r\n\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\n7z Decoder functions can return one of the following codes:\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_CRC_ERROR (3)\r\n\r\n#define SZE_NOTIMPL (4)\r\n#define SZE_FAIL (5)\r\n\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB       - Use special callback mode for input stream to reduce memory requirements\r\n\r\n_SZ_FILE_SIZE_32  - define it if you need only support for files smaller than 4 GB\r\n_SZ_NO_INT_64     - define it if your compiler doesn't support long long int or __int64.\r\n\r\n_LZMA_PROB32      - it can increase LZMA decompressing speed on some 32-bit CPUs.\r\n\r\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\r\n-----------------------------------\r\n\r\nThis file contains description of 7z archive format. \r\n7z archive can contain files compressed with any method.\r\nSee \"Methods.txt\" for description for defined compressing methods.\r\n\r\n\r\nFormat structure Overview\r\n-------------------------\r\n\r\nSome fields can be optional.\r\n\r\nArchive structure\r\n~~~~~~~~~~~~~~~~~  \r\nSignatureHeader\r\n[PackedStreams]\r\n[PackedStreamsForHeaders]\r\n[\r\n  Header \r\n  or \r\n  {\r\n    Packed Header\r\n    HeaderInfo\r\n  }\r\n]\r\n\r\n\r\n\r\nHeader structure\r\n~~~~~~~~~~~~~~~~  \r\n{\r\n  ArchiveProperties\r\n  AdditionalStreams\r\n  {\r\n    PackInfo\r\n    {\r\n      PackPos\r\n      NumPackStreams\r\n      Sizes[NumPackStreams]\r\n      CRCs[NumPackStreams]\r\n    }\r\n    CodersInfo\r\n    {\r\n      NumFolders\r\n      Folders[NumFolders]\r\n      {\r\n        NumCoders\r\n        CodersInfo[NumCoders]\r\n        {\r\n          ID\r\n          NumInStreams;\r\n          NumOutStreams;\r\n          PropertiesSize\r\n          Properties[PropertiesSize]\r\n        }\r\n        NumBindPairs\r\n        BindPairsInfo[NumBindPairs]\r\n        {\r\n          InIndex;\r\n          OutIndex;\r\n        }\r\n        PackedIndices\r\n      }\r\n      UnPackSize[Folders][Folders.NumOutstreams]\r\n      CRCs[NumFolders]\r\n    }\r\n    SubStreamsInfo\r\n    {\r\n      NumUnPackStreamsInFolders[NumFolders];\r\n      UnPackSizes[]\r\n      CRCs[]\r\n    }\r\n  }\r\n  MainStreamsInfo\r\n  {\r\n    (Same as in AdditionalStreams)\r\n  }\r\n  FilesInfo\r\n  {\r\n    NumFiles\r\n    Properties[]\r\n    {\r\n      ID\r\n      Size\r\n      Data\r\n    }\r\n  }\r\n}\r\n\r\nHeaderInfo structure\r\n~~~~~~~~~~~~~~~~~~~~\r\n{\r\n  (Same as in AdditionalStreams)\r\n}\r\n\r\n\r\n\r\nNotes about Notation and encoding\r\n---------------------------------\r\n\r\n7z uses little endian encoding.\r\n\r\n7z archive format has optional headers that are marked as\r\n[]\r\nHeader\r\n[]\r\n\r\nREAL_UINT64 means real UINT64.\r\n\r\nUINT64 means real UINT64 encoded with the following scheme:\r\n\r\n  Size of encoding sequence depends from first byte:\r\n  First_Byte  Extra_Bytes        Value\r\n  (binary)   \r\n  0xxxxxxx               : ( xxxxxxx           )\r\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r\n  ...\r\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r\n  11111110    BYTE y[7]  :                         y\r\n  11111111    BYTE y[8]  :                         y\r\n\r\n\r\n\r\nProperty IDs\r\n------------\r\n\r\n0x00 = kEnd,\r\n\r\n0x01 = kHeader,\r\n\r\n0x02 = kArchiveProperties,\r\n    \r\n0x03 = kAdditionalStreamsInfo,\r\n0x04 = kMainStreamsInfo,\r\n0x05 = kFilesInfo,\r\n    \r\n0x06 = kPackInfo,\r\n0x07 = kUnPackInfo,\r\n0x08 = kSubStreamsInfo,\r\n\r\n0x09 = kSize,\r\n0x0A = kCRC,\r\n\r\n0x0B = kFolder,\r\n\r\n0x0C = kCodersUnPackSize,\r\n0x0D = kNumUnPackStream,\r\n\r\n0x0E = kEmptyStream,\r\n0x0F = kEmptyFile,\r\n0x10 = kAnti,\r\n\r\n0x11 = kName,\r\n0x12 = kCreationTime,\r\n0x13 = kLastAccessTime,\r\n0x14 = kLastWriteTime,\r\n0x15 = kWinAttributes,\r\n0x16 = kComment,\r\n\r\n0x17 = kEncodedHeader,\r\n\r\n\r\n7z format headers\r\n-----------------\r\n\r\nSignatureHeader\r\n~~~~~~~~~~~~~~~\r\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n\r\n  ArchiveVersion\r\n  {\r\n    BYTE Major;   // now = 0\r\n    BYTE Minor;   // now = 2\r\n  };\r\n\r\n  UINT32 StartHeaderCRC;\r\n\r\n  StartHeader\r\n  {\r\n    REAL_UINT64 NextHeaderOffset\r\n    REAL_UINT64 NextHeaderSize\r\n    UINT32 NextHeaderCRC\r\n  }\r\n\r\n\r\n...........................\r\n\r\n\r\nArchiveProperties\r\n~~~~~~~~~~~~~~~~~\r\nBYTE NID::kArchiveProperties (0x02)\r\nfor (;;)\r\n{\r\n  BYTE PropertyType;\r\n  if (aType == 0)\r\n    break;\r\n  UINT64 PropertySize;\r\n  BYTE PropertyData[PropertySize];\r\n}\r\n\r\n\r\nDigests (NumStreams)\r\n~~~~~~~~~~~~~~~~~~~~~\r\n  BYTE AllAreDefined\r\n  if (AllAreDefined == 0)\r\n  {\r\n    for(NumStreams)\r\n      BIT Defined\r\n  }\r\n  UINT32 CRCs[NumDefined]\r\n\r\n\r\nPackInfo\r\n~~~~~~~~~~~~\r\n  BYTE NID::kPackInfo  (0x06)\r\n  UINT64 PackPos\r\n  UINT64 NumPackStreams\r\n\r\n  []\r\n  BYTE NID::kSize    (0x09)\r\n  UINT64 PackSizes[NumPackStreams]\r\n  []\r\n\r\n  []\r\n  BYTE NID::kCRC      (0x0A)\r\n  PackStreamDigests[NumPackStreams]\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFolder\r\n~~~~~~\r\n  UINT64 NumCoders;\r\n  for (NumCoders)\r\n  {\r\n    BYTE \r\n    {\r\n      0:3 DecompressionMethod.IDSize\r\n      4:\r\n        0 - IsSimple\r\n        1 - Is not simple\r\n      5:\r\n        0 - No Attributes\r\n        1 - There Are Attributes\r\n      7:\r\n        0 - Last Method in Alternative_Method_List\r\n        1 - There are more alternative methods\r\n    } \r\n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\r\n    if (!IsSimple)\r\n    {\r\n      UINT64 NumInStreams;\r\n      UINT64 NumOutStreams;\r\n    }\r\n    if (DecompressionMethod[0] != 0)\r\n    {\r\n      UINT64 PropertiesSize\r\n      BYTE Properties[PropertiesSize]\r\n    }\r\n  }\r\n    \r\n  NumBindPairs = NumOutStreamsTotal - 1;\r\n\r\n  for (NumBindPairs)\r\n  {\r\n    UINT64 InIndex;\r\n    UINT64 OutIndex;\r\n  }\r\n\r\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r\n  if (NumPackedStreams > 1)\r\n    for(NumPackedStreams)\r\n    {\r\n      UINT64 Index;\r\n    };\r\n\r\n\r\n\r\n\r\nCoders Info\r\n~~~~~~~~~~~\r\n\r\n  BYTE NID::kUnPackInfo  (0x07)\r\n\r\n\r\n  BYTE NID::kFolder  (0x0B)\r\n  UINT64 NumFolders\r\n  BYTE External\r\n  switch(External)\r\n  {\r\n    case 0:\r\n      Folders[NumFolders]\r\n    case 1:\r\n      UINT64 DataStreamIndex\r\n  }\r\n\r\n\r\n  BYTE ID::kCodersUnPackSize  (0x0C)\r\n  for(Folders)\r\n    for(Folder.NumOutStreams)\r\n     UINT64 UnPackSize;\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC   (0x0A)\r\n  UnPackDigests[NumFolders]\r\n  []\r\n\r\n  \r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\n\r\nSubStreams Info\r\n~~~~~~~~~~~~~~\r\n  BYTE NID::kSubStreamsInfo; (0x08)\r\n\r\n  []\r\n  BYTE NID::kNumUnPackStream; (0x0D)\r\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kSize  (0x09)\r\n  UINT64 UnPackSizes[]\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC  (0x0A)\r\n  Digests[Number of streams with unknown CRC]\r\n  []\r\n\r\n  \r\n  BYTE NID::kEnd\r\n\r\n\r\nStreams Info\r\n~~~~~~~~~~~~\r\n\r\n  []\r\n  PackInfo\r\n  []\r\n\r\n\r\n  []\r\n  CodersInfo\r\n  []\r\n\r\n\r\n  []\r\n  SubStreamsInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFilesInfo\r\n~~~~~~~~~\r\n  BYTE NID::kFilesInfo;  (0x05)\r\n  UINT64 NumFiles\r\n\r\n  for (;;)\r\n  {\r\n    BYTE PropertyType;\r\n    if (aType == 0)\r\n      break;\r\n\r\n    UINT64 Size;\r\n\r\n    switch(PropertyType)\r\n    {\r\n      kEmptyStream:   (0x0E)\r\n        for(NumFiles)\r\n          BIT IsEmptyStream\r\n\r\n      kEmptyFile:     (0x0F)\r\n        for(EmptyStreams)\r\n          BIT IsEmptyFile\r\n\r\n      kAnti:          (0x10)\r\n        for(EmptyStreams)\r\n          BIT IsAntiFile\r\n      \r\n      case kCreationTime:   (0x12)\r\n      case kLastAccessTime: (0x13)\r\n      case kLastWriteTime:  (0x14)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT TimeDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Items)\r\n          UINT32 Time\r\n        []\r\n      \r\n      kNames:     (0x11)\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Files)\r\n        {\r\n          wchar_t Names[NameSize];\r\n          wchar_t 0;\r\n        }\r\n        []\r\n\r\n      kAttributes:  (0x15)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT AttributesAreDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Attributes)\r\n          UINT32 Attributes\r\n        []\r\n    }\r\n  }\r\n\r\n\r\nHeader\r\n~~~~~~\r\n  BYTE NID::kHeader (0x01)\r\n\r\n  []\r\n  ArchiveProperties\r\n  []\r\n\r\n  []\r\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  BYTE NID::kMainStreamsInfo;    (0x04)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  FilesInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nHeaderInfo\r\n~~~~~~~~~~\r\n  []\r\n  BYTE NID::kEncodedHeader; (0x17)\r\n  StreamsInfo for Encoded Header\r\n  []\r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/7zCrc.c",
    "content": "/* 7zCrc.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++) \r\n    v = CRC_UPDATE_BYTE(v, *p);\r\n  return v;\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/7zCrc.h",
    "content": "/* 7zCrc.h */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"Types.h\"\r\n\r\nextern UInt32 g_CrcTable[];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void);\r\n\r\n#define CRC_INIT_VAL 0xFFFFFFFF\r\n#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)\r\n#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/7zCrcT8.c",
    "content": "/* 7zCrcT8.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\n#define CRC_NUM_TABLES 8\r\n\r\nUInt32 g_CrcTable[256 * CRC_NUM_TABLES];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable()\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n  #if CRC_NUM_TABLES > 1\r\n  for (; i < 256 * CRC_NUM_TABLES; i++)\r\n  {\r\n    UInt32 r = g_CrcTable[i - 256];\r\n    g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);\r\n  }\r\n  #endif\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  return CrcUpdateT8(v, data, size, g_CrcTable);\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdateT8(CRC_INIT_VAL, data, size, g_CrcTable) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Alloc.c",
    "content": "/* Alloc.c */\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdlib.h>\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount++);\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid MyFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d\", --g_allocCount);\r\n  #endif\r\n  free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#ifndef MEM_LARGE_PAGES\r\n#undef _7ZIP_LARGE_PAGES\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nSIZE_T g_LargePageSize = 0;\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n#endif\r\n\r\nvoid SetLargePageSize()\r\n{\r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  SIZE_T size = 0;\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        GetProcAddress(GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return;\r\n  size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return;\r\n  g_LargePageSize = size;\r\n  #endif\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))\r\n  {\r\n    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), \r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Alloc.h",
    "content": "/* Alloc.h */\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size);\r\nvoid MyFree(void *address);\r\n\r\n#ifdef _WIN32\r\n\r\nvoid SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size);\r\nvoid MidFree(void *address);\r\nvoid *BigAlloc(size_t size);\r\nvoid BigFree(void *address);\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zAlloc.c",
    "content": "/* 7zAlloc.c */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n#endif\r\n\r\nvoid *SzAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zAlloc.h",
    "content": "/* 7zAlloc.h */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\nvoid *SzAlloc(size_t size);\r\nvoid SzFree(void *address);\r\n\r\nvoid *SzAllocTemp(size_t size);\r\nvoid SzFreeTemp(void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zBuffer.c",
    "content": "/* 7zBuffer.c */\r\n\r\n#include \"7zBuffer.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer)\r\n{\r\n  buffer->Capacity = 0;\r\n  buffer->Items = 0;\r\n}\r\n\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))\r\n{\r\n  buffer->Capacity = newCapacity;\r\n  if (newCapacity == 0)\r\n  {\r\n    buffer->Items = 0;\r\n    return 1;\r\n  }\r\n  buffer->Items = (Byte *)allocFunc(newCapacity);\r\n  return (buffer->Items != 0);\r\n}\r\n\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(buffer->Items);\r\n  buffer->Items = 0;\r\n  buffer->Capacity = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zBuffer.h",
    "content": "/* 7zBuffer.h */\r\n\r\n#ifndef __7Z_BUFFER_H\r\n#define __7Z_BUFFER_H\r\n\r\n#include <stddef.h>\r\n#include \"../../Types.h\"\r\n\r\ntypedef struct _CSzByteBuffer\r\n{\r\n  size_t Capacity;\r\n  Byte *Items;\r\n}CSzByteBuffer;\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer);\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zDecode.c",
    "content": "/* 7zDecode.c */\r\n\r\n#include <memory.h>\r\n\r\n#include \"7zDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#else\r\n#include \"../../Compress/Lzma/LzmaDecode.h\"\r\n#include \"../../Compress/Branch/BranchX86.h\"\r\n#include \"../../Compress/Branch/BranchX86_2.h\"\r\n#endif\r\n\r\n#define k_Copy 0\r\n#define k_LZMA 0x30101\r\n#define k_BCJ 0x03030103\r\n#define k_BCJ2 0x0303011B\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\ntypedef struct _CLzmaInCallbackImp\r\n{\r\n  ILzmaInCallback InCallback;\r\n  ISzInStream *InStream;\r\n  CFileSize Size;\r\n} CLzmaInCallbackImp;\r\n\r\nint LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object;\r\n  size_t processedSize;\r\n  SZ_RESULT res;\r\n  size_t curSize = (1 << 20);\r\n  if (curSize > cb->Size)\r\n    curSize = (size_t)cb->Size;\r\n  *size = 0;\r\n  res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, curSize, &processedSize);\r\n  *size = (SizeT)processedSize;\r\n  if (processedSize > curSize)\r\n    return (int)SZE_FAIL;\r\n  cb->Size -= processedSize;\r\n  if (res == SZ_OK)\r\n    return 0;\r\n  return (int)res;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzDecodeLzma(CCoderInfo *coder, CFileSize inSize,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  CLzmaInCallbackImp lzmaCallback;\r\n  #else\r\n  SizeT inProcessed;\r\n  #endif\r\n  \r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  lzmaCallback.Size = inSize;\r\n  lzmaCallback.InStream = inStream;\r\n  lzmaCallback.InCallback.Read = LzmaReadImp;\r\n  #endif\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, \r\n      (unsigned)coder->Properties.Capacity) != LZMA_RESULT_OK)\r\n    return SZE_FAIL;\r\n  \r\n  state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      allocMain->Free(state.Probs);\r\n      return SZE_OUTOFMEMORY;\r\n    }\r\n  }\r\n  LzmaDecoderInit(&state);\r\n  #endif\r\n  \r\n  result = LzmaDecode(&state,\r\n  #ifdef _LZMA_IN_CB\r\n    &lzmaCallback.InCallback,\r\n  #else\r\n    inBuffer, (SizeT)inSize, &inProcessed,\r\n  #endif\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  allocMain->Free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  allocMain->Free(state.Dictionary);\r\n  #endif\r\n  if (result == LZMA_RESULT_DATA_ERROR)\r\n    return SZE_DATA_ERROR;\r\n  if (result != LZMA_RESULT_OK)\r\n    return SZE_FAIL;\r\n  return (outSizeProcessedLoc == outSize) ? SZ_OK : SZE_DATA_ERROR;\r\n}\r\n\r\n#ifdef _LZMA_IN_CB\r\nSZ_RESULT SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer)\r\n{\r\n  while (inSize > 0)\r\n  {\r\n    void *inBuffer;\r\n    size_t processedSize, curSize = (1 << 18);\r\n    if (curSize > inSize)\r\n      curSize = (size_t)(inSize);\r\n    RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, curSize, &processedSize));\r\n    if (processedSize == 0)\r\n      return SZE_DATA_ERROR;\r\n    if (processedSize > curSize)\r\n      return SZE_FAIL;\r\n    memcpy(outBuffer, inBuffer, processedSize);\r\n    outBuffer += processedSize;\r\n    inSize -= processedSize;\r\n  }\r\n  return SZ_OK;\r\n}\r\n#endif\r\n\r\n#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)\r\n#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)\r\n\r\nSZ_RESULT CheckSupportedFolder(const CFolder *f)\r\n{\r\n  if (f->NumCoders < 1 || f->NumCoders > 4)\r\n    return SZE_NOTIMPL;\r\n  if (IS_UNSUPPORTED_CODER(f->Coders[0]))\r\n    return SZE_NOTIMPL;\r\n  if (f->NumCoders == 1)\r\n  {\r\n    if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)\r\n      return SZE_NOTIMPL;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 2)\r\n  {\r\n    if (IS_NO_BCJ(f->Coders[1]) ||\r\n        f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||\r\n        f->NumBindPairs != 1 ||\r\n        f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)\r\n      return SZE_NOTIMPL;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 4)\r\n  {\r\n    if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||\r\n        IS_UNSUPPORTED_CODER(f->Coders[2]) ||\r\n        IS_NO_BCJ2(f->Coders[3]))\r\n      return SZE_NOTIMPL;\r\n    if (f->NumPackStreams != 4 || \r\n        f->PackStreams[0] != 2 ||\r\n        f->PackStreams[1] != 6 ||\r\n        f->PackStreams[2] != 1 ||\r\n        f->PackStreams[3] != 0 ||\r\n        f->NumBindPairs != 3 ||\r\n        f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||\r\n        f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||\r\n        f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)\r\n      return SZE_NOTIMPL;\r\n    return SZ_OK;\r\n  }\r\n  return SZE_NOTIMPL;\r\n}\r\n\r\nCFileSize GetSum(const CFileSize *values, UInt32 index)\r\n{\r\n  CFileSize sum = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < index; i++)\r\n    sum += values[i];\r\n  return sum;\r\n}\r\n\r\nSZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream, CFileSize startPos,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain,\r\n    Byte *tempBuf[])\r\n{\r\n  UInt32 ci;\r\n  size_t tempSizes[3] = { 0, 0, 0};\r\n  size_t tempSize3 = 0;\r\n  Byte *tempBuf3 = 0;\r\n\r\n  RINOK(CheckSupportedFolder(folder));\r\n\r\n  for (ci = 0; ci < folder->NumCoders; ci++)\r\n  {\r\n    CCoderInfo *coder = &folder->Coders[ci];\r\n\r\n    if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)\r\n    {\r\n      UInt32 si = 0;\r\n      CFileSize offset;\r\n      CFileSize inSize;\r\n      Byte *outBufCur = outBuffer;\r\n      size_t outSizeCur = outSize;\r\n      if (folder->NumCoders == 4)\r\n      {\r\n        UInt32 indices[] = { 3, 2, 0 };\r\n        CFileSize unpackSize = folder->UnPackSizes[ci];\r\n        si = indices[ci];\r\n        if (ci < 2)\r\n        {\r\n          Byte *temp;\r\n          outSizeCur = (size_t)unpackSize;\r\n          if (outSizeCur != unpackSize)\r\n            return SZE_OUTOFMEMORY;\r\n          temp = (Byte *)allocMain->Alloc(outSizeCur);\r\n          if (temp == 0 && outSizeCur != 0)\r\n            return SZE_OUTOFMEMORY;\r\n          outBufCur = tempBuf[1 - ci] = temp;\r\n          tempSizes[1 - ci] = outSizeCur;\r\n        }\r\n        else if (ci == 2)\r\n        {\r\n          if (unpackSize > outSize)\r\n            return SZE_OUTOFMEMORY;\r\n          tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);\r\n          tempSize3 = outSizeCur = (size_t)unpackSize;\r\n        }\r\n        else\r\n          return SZE_NOTIMPL;\r\n      }\r\n      offset = GetSum(packSizes, si);\r\n      inSize = packSizes[si];\r\n      #ifdef _LZMA_IN_CB\r\n      RINOK(inStream->Seek(inStream, startPos + offset));\r\n      #endif\r\n\r\n      if (coder->MethodID == k_Copy)\r\n      {\r\n        if (inSize != outSizeCur)\r\n          return SZE_DATA_ERROR;\r\n        \r\n        #ifdef _LZMA_IN_CB\r\n        RINOK(SzDecodeCopy(inSize, inStream, outBufCur));\r\n        #else\r\n        memcpy(outBufCur, inBuffer + (size_t)offset, (size_t)inSize);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        SZ_RESULT res = SzDecodeLzma(coder, inSize,\r\n            #ifdef _LZMA_IN_CB\r\n            inStream,\r\n            #else\r\n            inBuffer + (size_t)offset,\r\n            #endif\r\n            outBufCur, outSizeCur, allocMain);\r\n        RINOK(res)\r\n      }\r\n    }\r\n    else if (coder->MethodID == k_BCJ)\r\n    {\r\n      UInt32 state;\r\n      if (ci != 1)\r\n        return SZE_NOTIMPL;\r\n      x86_Convert_Init(state);\r\n      x86_Convert(outBuffer, outSize, 0, &state, 0);\r\n    }\r\n    else if (coder->MethodID == k_BCJ2)\r\n    {\r\n      CFileSize offset = GetSum(packSizes, 1);\r\n      CFileSize s3Size = packSizes[1];\r\n      SZ_RESULT res;\r\n      if (ci != 3)\r\n        return SZE_NOTIMPL;\r\n\r\n      #ifdef _LZMA_IN_CB\r\n      RINOK(inStream->Seek(inStream, startPos + offset));\r\n      tempSizes[2] = (size_t)s3Size;\r\n      if (tempSizes[2] != s3Size)\r\n        return SZE_OUTOFMEMORY;\r\n      tempBuf[2] = (Byte *)allocMain->Alloc(tempSizes[2]);\r\n      if (tempBuf[2] == 0 && tempSizes[2] != 0)\r\n        return SZE_OUTOFMEMORY;\r\n      res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);\r\n      RINOK(res)\r\n      #endif\r\n\r\n      res = x86_2_Decode(\r\n          tempBuf3, tempSize3, \r\n          tempBuf[0], tempSizes[0], \r\n          tempBuf[1], tempSizes[1], \r\n          #ifdef _LZMA_IN_CB\r\n          tempBuf[2], tempSizes[2], \r\n          #else\r\n          inBuffer + (size_t)offset, (size_t)s3Size, \r\n          #endif\r\n          outBuffer, outSize);\r\n      RINOK(res)\r\n    }\r\n    else \r\n      return SZE_NOTIMPL;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream, CFileSize startPos,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  Byte *tempBuf[3] = { 0, 0, 0};\r\n  int i;\r\n  SZ_RESULT res = SzDecode2(packSizes, folder,\r\n      #ifdef _LZMA_IN_CB\r\n      inStream, startPos,\r\n      #else\r\n      inBuffer,\r\n      #endif\r\n      outBuffer, outSize, allocMain, tempBuf);\r\n  for (i = 0; i < 3; i++)\r\n    allocMain->Free(tempBuf[i]);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zDecode.h",
    "content": "/* 7zDecode.h */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n#ifdef _LZMA_IN_CB\r\n#include \"7zIn.h\"\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *stream, CFileSize startPos,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zExtract.c",
    "content": "/* 7zExtract.c */\r\n\r\n#include \"7zExtract.h\"\r\n#include \"7zDecode.h\"\r\n#include \"../../7zCrc.h\"\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer, \r\n    size_t *outBufferSize,\r\n    size_t *offset, \r\n    size_t *outSizeProcessed, \r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];\r\n  SZ_RESULT res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    allocMain->Free(*outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CFolder *folder = db->Database.Folders + folderIndex;\r\n    CFileSize unPackSizeSpec = SzFolderGetUnPackSize(folder);\r\n    size_t unPackSize = (size_t)unPackSizeSpec;\r\n    CFileSize startOffset = SzArDbGetFolderStreamPos(db, folderIndex, 0);\r\n    #ifndef _LZMA_IN_CB\r\n    Byte *inBuffer = 0;\r\n    size_t processedSize;\r\n    CFileSize packSizeSpec;\r\n    size_t packSize;\r\n    RINOK(SzArDbGetFolderFullPackSize(db, folderIndex, &packSizeSpec));\r\n    packSize = (size_t)packSizeSpec;\r\n    if (packSize != packSizeSpec)\r\n      return SZE_OUTOFMEMORY;\r\n    #endif\r\n    if (unPackSize != unPackSizeSpec)\r\n      return SZE_OUTOFMEMORY;\r\n    *blockIndex = folderIndex;\r\n    allocMain->Free(*outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(inStream->Seek(inStream, startOffset));\r\n    \r\n    #ifndef _LZMA_IN_CB\r\n    if (packSize != 0)\r\n    {\r\n      inBuffer = (Byte *)allocTemp->Alloc(packSize);\r\n      if (inBuffer == 0)\r\n        return SZE_OUTOFMEMORY;\r\n    }\r\n    res = inStream->Read(inStream, inBuffer, packSize, &processedSize);\r\n    if (res == SZ_OK && processedSize != packSize)\r\n      res = SZE_FAIL;\r\n    #endif\r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = unPackSize;\r\n      if (unPackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)allocMain->Alloc(unPackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZE_OUTOFMEMORY;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        res = SzDecode(db->Database.PackSizes + \r\n          db->FolderStartPackStreamIndex[folderIndex], folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream, startOffset, \r\n          #else\r\n          inBuffer, \r\n          #endif\r\n          *outBuffer, unPackSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (folder->UnPackCRCDefined)\r\n          {\r\n            if (CrcCalc(*outBuffer, unPackSize) != folder->UnPackCRC)\r\n              res = SZE_CRC_ERROR;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    #ifndef _LZMA_IN_CB\r\n    allocTemp->Free(inBuffer);\r\n    #endif\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i; \r\n    CFileItem *fileItem = db->Database.Files + fileIndex;\r\n    *offset = 0;\r\n    for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)db->Database.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZE_FAIL;\r\n    {\r\n      if (fileItem->IsFileCRCDefined)\r\n      {\r\n        if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)\r\n          res = SZE_CRC_ERROR;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zExtract.h",
    "content": "/* 7zExtract.h */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive. \r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send \r\n    these values from previous call:\r\n      *blockIndex, \r\n      *outBuffer, \r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid, \r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables \r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zHeader.c",
    "content": "/*  7zHeader.c */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zHeader.h",
    "content": "/* 7zHeader.h */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnPackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnPackSize,\r\n  k7zIdNumUnPackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCreationTime,\r\n  k7zIdLastAccessTime,\r\n  k7zIdLastWriteTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zIn.c",
    "content": "/* 7zIn.c */\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zDecode.h\"\r\n#include \"../../7zCrc.h\"\r\n\r\n#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db)\r\n{\r\n  SzArchiveDatabaseInit(&db->Database);\r\n  db->FolderStartPackStreamIndex = 0;\r\n  db->PackStreamStartPositions = 0;\r\n  db->FolderStartFileIndex = 0;\r\n  db->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(db->FolderStartPackStreamIndex);\r\n  freeFunc(db->PackStreamStartPositions);\r\n  freeFunc(db->FolderStartFileIndex);\r\n  freeFunc(db->FileIndexToFolderIndexMap);\r\n  SzArchiveDatabaseFree(&db->Database, freeFunc);\r\n  SzArDbExInit(db);\r\n}\r\n\r\n/*\r\nCFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nCFileSize GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n#define MY_ALLOC(T, p, size, allocFunc) { if ((size) == 0) p = 0; else \\\r\n  if ((p = (T *)allocFunc((size) * sizeof(T))) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nSZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 startPos = 0;\r\n  CFileSize startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  MY_ALLOC(UInt32, db->FolderStartPackStreamIndex, db->Database.NumFolders, allocFunc);\r\n  for(i = 0; i < db->Database.NumFolders; i++)\r\n  {\r\n    db->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += db->Database.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  MY_ALLOC(CFileSize, db->PackStreamStartPositions, db->Database.NumPackStreams, allocFunc);\r\n\r\n  for(i = 0; i < db->Database.NumPackStreams; i++)\r\n  {\r\n    db->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += db->Database.PackSizes[i];\r\n  }\r\n\r\n  MY_ALLOC(UInt32, db->FolderStartFileIndex, db->Database.NumFolders, allocFunc);\r\n  MY_ALLOC(UInt32, db->FileIndexToFolderIndexMap, db->Database.NumFiles, allocFunc);\r\n\r\n  for (i = 0; i < db->Database.NumFiles; i++)\r\n  {\r\n    CFileItem *file = db->Database.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      db->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= db->Database.NumFolders)\r\n          return SZE_ARCHIVE_ERROR;\r\n        db->FolderStartFileIndex[folderIndex] = i;\r\n        if (db->Database.Folders[folderIndex].NumUnPackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    db->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return db->ArchiveInfo.DataStartPosition + \r\n    db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nint SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize)\r\n{\r\n  UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n  CFolder *folder = db->Database.Folders + folderIndex;\r\n  CFileSize size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n  {\r\n    CFileSize t = size + db->Database.PackSizes[packStreamIndex + i];\r\n    if (t < size)\r\n      return SZE_FAIL;\r\n    size = t;\r\n  }\r\n  *resSize = size;\r\n  return SZ_OK;\r\n}\r\n\r\n\r\n/*\r\nSZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case k7zIdLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case k7zIdLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nSZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  while (size > 0)\r\n  {\r\n    void *inBufferSpec;\r\n    size_t processedSize;\r\n    const Byte *inBuffer;\r\n    RINOK(inStream->Read(inStream, (void **)&inBufferSpec, size, &processedSize));\r\n    inBuffer = (const Byte *)inBufferSpec;\r\n    if (processedSize == 0 || processedSize > size)\r\n      return SZE_FAIL;\r\n    size -= processedSize;\r\n    do\r\n    {\r\n      *data++ = *inBuffer++;\r\n    }\r\n    while (--processedSize != 0);\r\n  }\r\n  #else\r\n  size_t processedSize;\r\n  RINOK(inStream->Read(inStream, data, size, &processedSize));\r\n  if (processedSize != size)\r\n    return SZE_FAIL;\r\n  #endif\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data)\r\n{\r\n  return SafeReadDirect(inStream, data, 1);\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n    *crc = CRC_UPDATE_BYTE(*crc, b);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    *crc = CRC_UPDATE_BYTE(*crc, b);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nint TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nSZ_RESULT SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  *value = (CFileSize)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZE_NOTIMPL;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZE_NOTIMPL;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadID(CSzData *sd, UInt64 *value) \r\n{ \r\n  return SzReadNumber(sd, value); \r\n}\r\n\r\nSZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nSZ_RESULT SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZE_ARCHIVE_ERROR;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  MY_ALLOC(Byte, *v, numItems, allocFunc);\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, allocFunc);\r\n  MY_ALLOC(Byte, *v, numItems, allocFunc);\r\n  for(i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHashDigests(\r\n    CSzData *sd, \r\n    size_t numItems,\r\n    Byte **digestsDefined, \r\n    UInt32 **digests, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc));\r\n  MY_ALLOC(UInt32, *digests, numItems, allocFunc);\r\n  for(i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadPackInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    CFileSize **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadSize(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, allocFunc);\r\n\r\n  for(i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadSize(sd, (*packSizes) + i));\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc)); \r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, allocFunc);\r\n    MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, allocFunc);\r\n    for(i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR;\r\n}\r\n\r\nSZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 numCoders;\r\n  UInt32 numBindPairs;\r\n  UInt32 numPackedStreams;\r\n  UInt32 i;\r\n  UInt32 numInStreams = 0;\r\n  UInt32 numOutStreams = 0;\r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  folder->NumCoders = numCoders;\r\n\r\n  MY_ALLOC(CCoderInfo, folder->Coders, (size_t)numCoders, allocFunc);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfoInit(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      unsigned idSize, j;\r\n      Byte longID[15];\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      idSize = (unsigned)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, longID, idSize));\r\n      if (idSize > sizeof(coder->MethodID))\r\n        return SZE_NOTIMPL;\r\n      coder->MethodID = 0;\r\n      for (j = 0; j < idSize; j++)\r\n        coder->MethodID |= (CMethodID)longID[idSize - 1 - j] << (8 * j);\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc))\r\n          return SZE_OUTOFMEMORY;\r\n        RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += (UInt32)coder->NumInStreams;\r\n    numOutStreams += (UInt32)coder->NumOutStreams;\r\n  }\r\n\r\n  numBindPairs = numOutStreams - 1;\r\n  folder->NumBindPairs = numBindPairs;\r\n\r\n\r\n  MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, allocFunc);\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bindPair = folder->BindPairs + i;;\r\n    RINOK(SzReadNumber32(sd, &bindPair->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bindPair->OutIndex)); \r\n  }\r\n\r\n  numPackedStreams = numInStreams - (UInt32)numBindPairs;\r\n\r\n  folder->NumPackStreams = numPackedStreams;\r\n  MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, allocFunc);\r\n\r\n  if (numPackedStreams == 1)\r\n  {\r\n    UInt32 j;\r\n    UInt32 pi = 0;\r\n    for (j = 0; j < numInStreams; j++)\r\n      if (SzFolderFindBindPairForInStream(folder, j) < 0)\r\n      {\r\n        folder->PackStreams[pi++] = j;\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUnPackInfo(\r\n    CSzData *sd, \r\n    UInt32 *numFolders,\r\n    CFolder **folders,  /* for allocFunc */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n    MY_ALLOC(CFolder, *folders, (size_t)*numFolders, allocFunc);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n      SzFolderInit((*folders) + i);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));\r\n\r\n  for(i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolderGetNumOutStreams(folder);\r\n\r\n    MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, allocFunc);\r\n\r\n    for(j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadSize(sd, folder->UnPackSizes + j));\r\n    }\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SZ_RESULT res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc); \r\n      if (res == SZ_OK)\r\n      {\r\n        for(i = 0; i < *numFolders; i++)\r\n        {\r\n          CFolder *folder = (*folders) + i;\r\n          folder->UnPackCRCDefined = crcsDefined[i];\r\n          folder->UnPackCRC = crcs[i];\r\n        }\r\n      }\r\n      allocTemp->Free(crcs);\r\n      allocTemp->Free(crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadSubStreamsInfo(\r\n    CSzData *sd, \r\n    UInt32 numFolders,\r\n    CFolder *folders,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n    folders[i].NumUnPackStreams = 1;\r\n  *numUnPackStreams = numFolders;\r\n\r\n  for (;;)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnPackStream)\r\n    {\r\n      *numUnPackStreams = 0;\r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnPackStreams = numStreams;\r\n        *numUnPackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnPackStreams == 0)\r\n  {\r\n    *unPackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize));\r\n    RINOM(*unPackSizes);\r\n    *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    CFileSize sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      CFileSize size;\r\n      RINOK(SzReadSize(sd, &size));\r\n      (*unPackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for(i = 0; i < *numUnPackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  for (;;)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0; \r\n      UInt32 *digests2 = 0;\r\n      SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnPackStreams;\r\n          if (numSubstreams == 1 && folder->UnPackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnPackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      allocTemp->Free(digestsDefined2);\r\n      allocTemp->Free(digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nSZ_RESULT SzReadStreamsInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    CArchiveDatabase *db,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZE_FAIL;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams, \r\n            &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc));\r\n        break;\r\n      }\r\n      case k7zIdUnPackInfo:\r\n      {\r\n        RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders, \r\n            numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZE_FAIL;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nSZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CFileItem *file = files + i;\r\n    while(pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZE_ARCHIVE_ERROR;\r\n        if (pos + 2 > sd->Size)\r\n          return SZE_ARCHIVE_ERROR;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZE_ARCHIVE_ERROR;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    MY_ALLOC(char, file->Name, (size_t)len, allocFunc);\r\n\r\n    len = 0;\r\n    while(2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while(numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHeader2(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db,   /* allocMain */\r\n    CFileSize **unPackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    Byte **lwtVector,         /* allocTemp */\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnPackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &db->ArchiveInfo.DataStartPosition,\r\n        &db->Database, \r\n        &numUnPackStreams,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests, allocMain->Alloc, allocTemp));\r\n    db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZE_ARCHIVE_ERROR;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  db->Database.NumFiles = numFiles;\r\n\r\n  MY_ALLOC(CFileItem, files, (size_t)numFiles, allocMain->Alloc);\r\n\r\n  db->Database.Files = files;\r\n  for(i = 0; i < numFiles; i++)\r\n    SzFileInit(files + i);\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc));\r\n        break;\r\n      }\r\n      case k7zIdLastWriteTime:\r\n      {\r\n        RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp->Alloc));\r\n        RINOK(SzReadSwitch(sd));\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem *f = &files[i];\r\n          Byte defined = (*lwtVector)[i];\r\n          f->IsLastWriteTimeDefined = defined;\r\n          f->LastWriteTime.Low = f->LastWriteTime.High = 0;\r\n          if (defined)\r\n          {\r\n            RINOK(SzReadUInt32(sd, &f->LastWriteTime.Low));\r\n            RINOK(SzReadUInt32(sd, &f->LastWriteTime.High));\r\n          }\r\n        }\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for(i = 0; i < numFiles; i++)\r\n    {\r\n      CFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if(file->HasStream)\r\n      {\r\n        file->IsDirectory = 0;\r\n        file->Size = (*unPackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->IsFileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDirectory = 1;\r\n        else\r\n          file->IsDirectory = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->IsFileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArDbExFill(db, allocMain->Alloc);\r\n}\r\n\r\nSZ_RESULT SzReadHeader(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db, \r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  Byte *lwtVector = 0;\r\n  SZ_RESULT res = SzReadHeader2(sd, db, \r\n      &unPackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector, &lwtVector, \r\n      allocMain, allocTemp);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  allocTemp->Free(emptyStreamVector);\r\n  allocTemp->Free(emptyFileVector);\r\n  allocTemp->Free(lwtVector);\r\n  return res;\r\n} \r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams2(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    CArchiveDatabase *db,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    #ifndef _LZMA_IN_CB\r\n    Byte **inBuffer,\r\n    #endif\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnPackStreams = 0;\r\n  CFileSize dataStartPos;\r\n  CFolder *folder;\r\n  #ifndef _LZMA_IN_CB\r\n  CFileSize packSize = 0;\r\n  UInt32 i = 0;\r\n  #endif\r\n  CFileSize unPackSize;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, db,\r\n      &numUnPackStreams,  unPackSizes, digestsDefined, digests, \r\n      allocTemp->Alloc, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (db->NumFolders != 1)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  folder = db->Folders;\r\n  unPackSize = SzFolderGetUnPackSize(folder);\r\n  \r\n  RINOK(inStream->Seek(inStream, dataStartPos));\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  for (i = 0; i < db->NumPackStreams; i++)\r\n    packSize += db->PackSizes[i];\r\n\r\n  MY_ALLOC(Byte, *inBuffer, (size_t)packSize, allocTemp->Alloc);\r\n\r\n  RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize));\r\n  #endif\r\n\r\n  if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  res = SzDecode(db->PackSizes, folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream, dataStartPos, \r\n          #else\r\n          *inBuffer, \r\n          #endif\r\n          outBuffer->Items, (size_t)unPackSize, allocTemp);\r\n  RINOK(res)\r\n  if (folder->UnPackCRCDefined)\r\n    if (CrcCalc(outBuffer->Items, (size_t)unPackSize) != folder->UnPackCRC)\r\n      return SZE_FAIL;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CArchiveDatabase db;\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  #ifndef _LZMA_IN_CB\r\n  Byte *inBuffer = 0;\r\n  #endif\r\n  SZ_RESULT res;\r\n  SzArchiveDatabaseInit(&db);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset, \r\n    &db, &unPackSizes, &digestsDefined, &digests, \r\n    #ifndef _LZMA_IN_CB\r\n    &inBuffer,\r\n    #endif\r\n    allocTemp);\r\n  SzArchiveDatabaseFree(&db, allocTemp->Free);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  #ifndef _LZMA_IN_CB\r\n  allocTemp->Free(inBuffer);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen2(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte signature[k7zSignatureSize];\r\n  Byte version;\r\n  UInt32 crcFromArchive;\r\n  UInt64 nextHeaderOffset;\r\n  UInt64 nextHeaderSize;\r\n  UInt32 nextHeaderCRC;\r\n  UInt32 crc = 0;\r\n  CFileSize pos = 0;\r\n  CSzByteBuffer buffer;\r\n  CSzData sd;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize));\r\n\r\n  if (!TestSignatureCandidate(signature))\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  /*\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n  */\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n  if (version != k7zMajorVersion)\r\n    return SZE_ARCHIVE_ERROR;\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n\r\n  RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive, &crc));\r\n\r\n  crc = CRC_INIT_VAL;\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset, &crc));\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize, &crc));\r\n  RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC, &crc));\r\n\r\n  pos = k7zStartHeaderSize;\r\n  db->ArchiveInfo.StartPositionAfterHeader = pos;\r\n  \r\n  if (CRC_GET_DIGEST(crc) != crcFromArchive)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  if (nextHeaderSize == 0)\r\n    return SZ_OK;\r\n\r\n  RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset)));\r\n\r\n  if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = SZE_ARCHIVE_ERROR;\r\n    if (CrcCalc(buffer.Items, (UInt32)nextHeaderSize) == nextHeaderCRC)\r\n    {\r\n      for (;;)\r\n      {\r\n        UInt64 type;\r\n        sd.Data = buffer.Items;\r\n        sd.Size = buffer.Capacity;\r\n        res = SzReadID(&sd, &type);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (type == k7zIdHeader)\r\n        {\r\n          res = SzReadHeader(&sd, db, allocMain, allocTemp);\r\n          break;\r\n        }\r\n        if (type != k7zIdEncodedHeader)\r\n        {\r\n          res = SZE_ARCHIVE_ERROR;\r\n          break;\r\n        }\r\n        {\r\n          CSzByteBuffer outBuffer;\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, \r\n              db->ArchiveInfo.StartPositionAfterHeader, \r\n              allocTemp);\r\n          if (res != SZ_OK)\r\n          {\r\n            SzByteBufferFree(&outBuffer, allocTemp->Free);\r\n            break;\r\n          }\r\n          SzByteBufferFree(&buffer, allocTemp->Free);\r\n          buffer.Items = outBuffer.Items;\r\n          buffer.Capacity = outBuffer.Capacity;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  SzByteBufferFree(&buffer, allocTemp->Free);\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArDbExFree(db, allocMain->Free);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zIn.h",
    "content": "/* 7zIn.h */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n \r\ntypedef struct _CInArchiveInfo\r\n{\r\n  CFileSize StartPositionAfterHeader; \r\n  CFileSize DataStartPosition;\r\n}CInArchiveInfo;\r\n\r\ntypedef struct _CArchiveDatabaseEx\r\n{\r\n  CArchiveDatabase Database;\r\n  CInArchiveInfo ArchiveInfo;\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  CFileSize *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n}CArchiveDatabaseEx;\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db);\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);\r\nint SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize);\r\n\r\ntypedef struct _ISzInStream\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  SZ_RESULT (*Read)(\r\n      void *object,           /* pointer to ISzInStream itself */\r\n      void **buffer,          /* out: pointer to buffer with data */\r\n      size_t maxRequiredSize, /* max required size to read */\r\n      size_t *processedSize); /* real processed size. \r\n                                 processedSize can be less than maxRequiredSize.\r\n                                 If processedSize == 0, then there are no more \r\n                                 bytes in stream. */\r\n  #else\r\n  SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);\r\n  #endif\r\n  SZ_RESULT (*Seek)(void *object, CFileSize pos);\r\n} ISzInStream;\r\n\r\n \r\nint SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zItem.c",
    "content": "/* 7zItem.c */\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder)\r\n{\r\n  SzByteBufferInit(&coder->Properties);\r\n}\r\n\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))\r\n{\r\n  SzByteBufferFree(&coder->Properties, freeFunc);\r\n  SzCoderInfoInit(coder);\r\n}\r\n\r\nvoid SzFolderInit(CFolder *folder)\r\n{\r\n  folder->NumCoders = 0;\r\n  folder->Coders = 0;\r\n  folder->NumBindPairs = 0;\r\n  folder->BindPairs = 0;\r\n  folder->NumPackStreams = 0;\r\n  folder->PackStreams = 0;\r\n  folder->UnPackSizes = 0;\r\n  folder->UnPackCRCDefined = 0;\r\n  folder->UnPackCRC = 0;\r\n  folder->NumUnPackStreams = 0;\r\n}\r\n\r\nvoid SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    SzCoderInfoFree(&folder->Coders[i], freeFunc);\r\n  freeFunc(folder->Coders);\r\n  freeFunc(folder->BindPairs);\r\n  freeFunc(folder->PackStreams);\r\n  freeFunc(folder->UnPackSizes);\r\n  SzFolderInit(folder);\r\n}\r\n\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    result += folder->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder)\r\n{ \r\n  int i = (int)SzFolderGetNumOutStreams(folder);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolderFindBindPairForOutStream(folder, i) < 0)\r\n      return folder->UnPackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\n/*\r\nint FindPackStreamArrayIndex(int inStreamIndex) const\r\n{\r\n  for(int i = 0; i < PackStreams.Size(); i++)\r\n  if (PackStreams[i] == inStreamIndex)\r\n    return i;\r\n  return -1;\r\n}\r\n*/\r\n\r\nvoid SzFileInit(CFileItem *fileItem)\r\n{\r\n  fileItem->IsFileCRCDefined = 0;\r\n  fileItem->HasStream = 1;\r\n  fileItem->IsDirectory = 0;\r\n  fileItem->IsAnti = 0;\r\n  fileItem->IsLastWriteTimeDefined = 0;\r\n  fileItem->Name = 0;\r\n}\r\n\r\nvoid SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))\r\n{\r\n  freeFunc(fileItem->Name);\r\n  SzFileInit(fileItem);\r\n}\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db)\r\n{\r\n  db->NumPackStreams = 0;\r\n  db->PackSizes = 0;\r\n  db->PackCRCsDefined = 0;\r\n  db->PackCRCs = 0;\r\n  db->NumFolders = 0;\r\n  db->Folders = 0;\r\n  db->NumFiles = 0;\r\n  db->Files = 0;\r\n}\r\n\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < db->NumFolders; i++)\r\n    SzFolderFree(&db->Folders[i], freeFunc);\r\n  for (i = 0; i < db->NumFiles; i++)\r\n    SzFileFree(&db->Files[i], freeFunc);\r\n  freeFunc(db->PackSizes);\r\n  freeFunc(db->PackCRCsDefined);\r\n  freeFunc(db->PackCRCs);\r\n  freeFunc(db->Folders);\r\n  freeFunc(db->Files);\r\n  SzArchiveDatabaseInit(db);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zItem.h",
    "content": "/* 7zItem.h */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"7zMethodID.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zBuffer.h\"\r\n\r\ntypedef struct _CCoderInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  CMethodID MethodID;\r\n  CSzByteBuffer Properties;\r\n}CCoderInfo;\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder);\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));\r\n\r\ntypedef struct _CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n}CBindPair;\r\n\r\ntypedef struct _CFolder\r\n{\r\n  UInt32 NumCoders;\r\n  CCoderInfo *Coders;\r\n  UInt32 NumBindPairs;\r\n  CBindPair *BindPairs;\r\n  UInt32 NumPackStreams; \r\n  UInt32 *PackStreams;\r\n  CFileSize *UnPackSizes;\r\n  int UnPackCRCDefined;\r\n  UInt32 UnPackCRC;\r\n\r\n  UInt32 NumUnPackStreams;\r\n}CFolder;\r\n\r\nvoid SzFolderInit(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\n\r\ntypedef struct _CArchiveFileTime\r\n{\r\n  UInt32 Low;\r\n  UInt32 High;\r\n} CArchiveFileTime;\r\n\r\ntypedef struct _CFileItem\r\n{\r\n  CArchiveFileTime LastWriteTime;\r\n  /*\r\n  CFileSize StartPos;\r\n  UInt32 Attributes; \r\n  */\r\n  CFileSize Size;\r\n  UInt32 FileCRC;\r\n  char *Name;\r\n\r\n  Byte IsFileCRCDefined;\r\n  Byte HasStream;\r\n  Byte IsDirectory;\r\n  Byte IsAnti;\r\n  Byte IsLastWriteTimeDefined;\r\n  /*\r\n  int AreAttributesDefined;\r\n  int IsLastWriteTimeDefined;\r\n  int IsStartPosDefined;\r\n  */\r\n}CFileItem;\r\n\r\nvoid SzFileInit(CFileItem *fileItem);\r\n\r\ntypedef struct _CArchiveDatabase\r\n{\r\n  UInt32 NumPackStreams;\r\n  CFileSize *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  UInt32 NumFolders;\r\n  CFolder *Folders;\r\n  UInt32 NumFiles;\r\n  CFileItem *Files;\r\n}CArchiveDatabase;\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db);\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));\r\n\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zMain.c",
    "content": "/* \r\n7zMain.c\r\nTest application for 7z Decoder\r\nLZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-06-04)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#ifdef _WIN32\r\n#define USE_WINDOWS_FUNCTIONS\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FUNCTIONS\r\n#include <windows.h>\r\n#endif\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zExtract.h\"\r\n\r\n#include \"../../7zCrc.h\"\r\n\r\n\r\n#ifdef USE_WINDOWS_FUNCTIONS\r\ntypedef HANDLE MY_FILE_HANDLE;\r\n#else\r\ntypedef FILE *MY_FILE_HANDLE;\r\n#endif\r\n\r\nvoid ConvertNumberToString(CFileSize value, char *s)\r\n{\r\n  char temp[32];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    temp[pos++] = (char)('0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while(pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\n#define PERIOD_4 (4 * 365 + 1)\r\n#define PERIOD_100 (PERIOD_4 * 25 - 1)\r\n#define PERIOD_400 (PERIOD_100 * 4 + 1)\r\n\r\nvoid ConvertFileTimeToString(CArchiveFileTime *ft, char *s)\r\n{\r\n  unsigned year, mon, day, hour, min, sec;\r\n  UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  unsigned temp;\r\n  UInt32 v; \r\n  v64 /= 10000000;\r\n  sec = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  min = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  hour = (unsigned)(v64 % 24);\r\n  v64 /= 24;\r\n\r\n  v = (UInt32)v64;\r\n\r\n  year = (unsigned)(1601 + v / PERIOD_400 * 400);\r\n  v %= PERIOD_400;\r\n\r\n  temp = (unsigned)(v / PERIOD_100);\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp * 100;\r\n  v -= temp * PERIOD_100;\r\n\r\n  temp = v / PERIOD_4;\r\n  if (temp == 25)\r\n    temp = 24;\r\n  year += temp * 4;\r\n  v -= temp * PERIOD_4;\r\n\r\n  temp = v / 365;\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp;\r\n  v -= temp * 365;\r\n\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  for (mon = 1; mon <= 12; mon++)\r\n  {\r\n    unsigned s = ms[mon - 1];\r\n    if (v < s)\r\n      break;\r\n    v -= s;\r\n  }\r\n  day = (unsigned)v + 1;\r\n  sprintf(s, \"%04d-%02d-%02d %02d:%02d:%02d\", year, mon, day, hour, min, sec);\r\n}\r\n\r\n\r\n#ifdef USE_WINDOWS_FUNCTIONS\r\n/*\r\n   ReadFile and WriteFile functions in Windows have BUG:\r\n   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n   (Insufficient system resources exist to complete the requested service).\r\n*/\r\n#define kChunkSizeMax (1 << 24)\r\n#endif\r\n\r\nsize_t MyReadFile(MY_FILE_HANDLE file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  {\r\n    size_t processedSize = 0;\r\n    do\r\n    {\r\n      DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;\r\n      DWORD processedLoc = 0;\r\n      BOOL res = ReadFile(file, data, curSize, &processedLoc, NULL);\r\n      data = (void *)((unsigned char *)data + processedLoc);\r\n      size -= processedLoc;\r\n      processedSize += processedLoc;\r\n      if (!res || processedLoc == 0)\r\n        break;\r\n    }\r\n    while (size > 0);\r\n    return processedSize;\r\n  }\r\n  #else\r\n  return fread(data, 1, size, file); \r\n  #endif\r\n}\r\n\r\nsize_t MyWriteFile(MY_FILE_HANDLE file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  {\r\n    size_t processedSize = 0;\r\n    do\r\n    {\r\n      DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;\r\n      DWORD processedLoc = 0;\r\n      BOOL res = WriteFile(file, data, curSize, &processedLoc, NULL);\r\n      data = (void *)((unsigned char *)data + processedLoc);\r\n      size -= processedLoc;\r\n      processedSize += processedLoc;\r\n      if (!res)\r\n        break;\r\n    }\r\n    while (size > 0);\r\n    return processedSize;\r\n  }\r\n  #else\r\n  return fwrite(data, 1, size, file); \r\n  #endif\r\n}\r\n\r\nint MyCloseFile(MY_FILE_HANDLE file)\r\n{ \r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  return (CloseHandle(file) != FALSE) ? 0 : 1;\r\n  #else\r\n  return fclose(file); \r\n  #endif\r\n}\r\n\r\ntypedef struct _CFileInStream\r\n{\r\n  ISzInStream InStream;\r\n  MY_FILE_HANDLE File;\r\n} CFileInStream;\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define kBufferSize (1 << 12)\r\nByte g_Buffer[kBufferSize];\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc;\r\n  if (maxRequiredSize > kBufferSize)\r\n    maxRequiredSize = kBufferSize;\r\n  processedSizeLoc = MyReadFile(s->File, g_Buffer, maxRequiredSize);\r\n  *buffer = g_Buffer;\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#else\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc = MyReadFile(s->File, buffer, size);\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzFileSeekImp(void *object, CFileSize pos)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n\r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  {\r\n    LARGE_INTEGER value;\r\n    value.LowPart = (DWORD)pos;\r\n    value.HighPart = (LONG)((UInt64)pos >> 32);\r\n    #ifdef _SZ_FILE_SIZE_32\r\n    /* VC 6.0 has bug with >> 32 shifts. */\r\n    value.HighPart = 0;\r\n    #endif\r\n    value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, FILE_BEGIN);\r\n    if (value.LowPart == 0xFFFFFFFF)\r\n      if(GetLastError() != NO_ERROR) \r\n        return SZE_FAIL;\r\n    return SZ_OK;\r\n  }\r\n  #else\r\n  int res = fseek(s->File, (long)pos, SEEK_SET);\r\n  if (res == 0)\r\n    return SZ_OK;\r\n  return SZE_FAIL;\r\n  #endif\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CArchiveDatabaseEx db;\r\n  SZ_RESULT res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder 4.48  Copyright (c) 1999-2007 Igor Pavlov  2007-06-21\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.File = \r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  CreateFile(args[2], GENERIC_READ, FILE_SHARE_READ, \r\n      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\r\n  if (archiveStream.File == INVALID_HANDLE_VALUE)\r\n  #else\r\n  archiveStream.File = fopen(args[2], \"rb\");\r\n  if (archiveStream.File == 0)\r\n  #endif\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.InStream.Read = SzFileReadImp;\r\n  archiveStream.InStream.Seek = SzFileSeekImp;\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  CrcGenerateTable();\r\n\r\n  SzArDbExInit(&db);\r\n  res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0;\r\n    int testCommand = 0;\r\n    int extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0)\r\n      listCommand = 1;\r\n    if (strcmp(command, \"t\") == 0)\r\n      testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0)\r\n      extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        char s[32], t[32];\r\n        ConvertNumberToString(f->Size, s);\r\n        if (f->IsLastWriteTimeDefined)\r\n          ConvertFileTimeToString(&f->LastWriteTime, t);\r\n        else\r\n          strcpy(t, \"                   \");\r\n\r\n        printf(\"%10s %s  %s\\n\", s, t, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      /*\r\n      if you need cache, use these 3 variables.\r\n      if you use external function, you can make these variable as static.\r\n      */\r\n      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r\n      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r\n      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CFileItem *f = db.Database.Files + i;\r\n        if (f->IsDirectory)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ? \r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDirectory)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzExtract(&archiveStream.InStream, &db, i, \r\n            &blockIndex, &outBuffer, &outBufferSize, \r\n            &offset, &outSizeProcessed, \r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          MY_FILE_HANDLE outputHandle;\r\n          size_t processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          outputHandle = \r\n          #ifdef USE_WINDOWS_FUNCTIONS\r\n            CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_READ, \r\n                NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\r\n          if (outputHandle == INVALID_HANDLE_VALUE)\r\n          #else\r\n          fopen(fileName, \"wb+\");\r\n          if (outputHandle == 0)\r\n          #endif\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          processedSize = MyWriteFile(outputHandle, outBuffer + offset, outSizeProcessed);\r\n          if (processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          if (MyCloseFile(outputHandle))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      allocImp.Free(outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZE_FAIL;\r\n    }\r\n  }\r\n  SzArDbExFree(&db, allocImp.Free);\r\n\r\n  MyCloseFile(archiveStream.File);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == (SZ_RESULT)SZE_NOTIMPL)\r\n    PrintError(\"decoder doesn't support this archive\");\r\n  else if (res == (SZ_RESULT)SZE_OUTOFMEMORY)\r\n    PrintError(\"can not allocate memory\");\r\n  else if (res == (SZ_RESULT)SZE_CRC_ERROR)\r\n    PrintError(\"CRC error\");\r\n  else     \r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zMethodID.c",
    "content": "/* 7zMethodID.c */\r\n\r\n#include \"7zMethodID.h\"\r\n\r\n/*\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2)\r\n{\r\n  return (*a1 == *a2) ? 1 : 0;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7zMethodID.h",
    "content": "/* 7zMethodID.h */\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Types.h\"\r\n\r\ntypedef UInt64 CMethodID;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7z_C.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z_C\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z_C - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\" CFG=\"7z_C - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z_C - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z_C - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z_C - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MD /W4 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z_C - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z_C - Win32 Release\"\r\n# Name \"7z_C - Win32 Debug\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Lzma\\LzmaDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Lzma\\LzmaDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Lzma\\LzmaTypes.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86_2.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86_2.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/7z_C.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z_C\"=.\\7z_C.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/makefile",
    "content": "PROG = 7zDec.exe\r\n\r\n!IFDEF CPU\r\nLIBS = $(LIBS) bufferoverflowU.lib \r\nCFLAGS = $(CFLAGS) -GS- -Zc:forScope -WX -GS- -Gy -W4 \r\n!ENDIF\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -D_LZMA_IN_CB\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zBuffer.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n  $O\\7zMethodID.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\BranchX86.obj \\\r\n  $O\\BranchX86_2.obj \\\r\n  $(C_OBJS) \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/Lzma/$(*B).c\r\n\t$(COMPL_O2)\r\n\r\n$O\\BranchX86.obj: ../../Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n\r\n$O\\BranchX86_2.obj: ../../Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Archive/7z/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall -D_LZMA_IN_CB\r\n\r\nOBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o BranchX86.o BranchX86_2.o\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuffer.o: 7zBuffer.c\r\n\t$(CXX) $(CFLAGS) 7zBuffer.c\r\n\r\n7zCrc.o: ../../7zCrc.c\r\n\t$(CXX) $(CFLAGS) ../../7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\n7zMethodID.o: 7zMethodID.c\r\n\t$(CXX) $(CFLAGS) 7zMethodID.c\r\n\r\nLzmaDecode.o: ../../Compress/Lzma/LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/Lzma/LzmaDecode.c\r\n\r\nBranchX86.o: ../../Compress/Branch/BranchX86.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86.c\r\n\r\nBranchX86_2.o: ../../Compress/Branch/BranchX86_2.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86_2.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchARM.c",
    "content": "/* BranchARM.c */\r\n\r\n#include \"BranchARM.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = (data[i + 2] << 16) | (data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = nowPos + i + 8 + src;\r\n      else\r\n        dest = src - (nowPos + i + 8);\r\n      dest >>= 2;\r\n      data[i + 2] = (Byte)(dest >> 16);\r\n      data[i + 1] = (Byte)(dest >> 8);\r\n      data[i + 0] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchARM.h",
    "content": "/* BranchARM.h */\r\n\r\n#ifndef __BRANCH_ARM_H\r\n#define __BRANCH_ARM_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchARMThumb.c",
    "content": "/* BranchARMThumb.c */\r\n\r\n#include \"BranchARMThumb.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 && \r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = \r\n        ((data[i + 1] & 0x7) << 19) |\r\n        (data[i + 0] << 11) |\r\n        ((data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      if (encoding)\r\n        dest = nowPos + i + 4 + src;\r\n      else\r\n        dest = src - (nowPos + i + 4);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));\r\n      data[i + 0] = (Byte)(dest >> 11);\r\n      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));\r\n      data[i + 2] = (Byte)dest;\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchARMThumb.h",
    "content": "/* BranchARMThumb.h */\r\n\r\n#ifndef __BRANCH_ARM_THUMB_H\r\n#define __BRANCH_ARM_THUMB_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchIA64.c",
    "content": "/* BranchIA64.c */\r\n\r\n#include \"BranchIA64.h\"\r\n\r\nconst Byte kBranchTable[32] = \r\n{ \r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0 \r\n};\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 16 <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    int slot;\r\n    for (slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      UInt32 bytePos, bitRes;\r\n      UInt64 instruction, instNorm;\r\n      int j;\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      bytePos = (bitPos >> 3);\r\n      bitRes = bitPos & 0x7;\r\n      instruction = 0;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);\r\n\r\n      instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 \r\n        &&  ((instNorm >> 9) & 0x7) == 0 \r\n        /* &&  (instNorm & 0x3F)== 0 */\r\n        )\r\n      {\r\n        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);\r\n        UInt32 dest;\r\n        src |= ((UInt32)(instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        if (encoding)\r\n          dest = nowPos + i + src;\r\n        else\r\n          dest = src - (nowPos + i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~((UInt64)(0x8FFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchIA64.h",
    "content": "/* BranchIA64.h */\r\n\r\n#ifndef __BRANCH_IA64_H\r\n#define __BRANCH_IA64_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchPPC.c",
    "content": "/* BranchPPC.c */\r\n\r\n#include \"BranchPPC.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    /* PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) */\r\n    if ((data[i] >> 2) == 0x12 && \r\n    (\r\n      (data[i + 3] & 3) == 1 \r\n      /* || (data[i+3] & 3) == 3 */\r\n      )\r\n    )\r\n    {\r\n      UInt32 src = ((data[i + 0] & 3) << 24) |\r\n        (data[i + 1] << 16) |\r\n        (data[i + 2] << 8) |\r\n        (data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchPPC.h",
    "content": "/* BranchPPC.h */\r\n\r\n#ifndef __BRANCH_PPC_H\r\n#define __BRANCH_PPC_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchSPARC.c",
    "content": "/* BranchSPARC.c */\r\n\r\n#include \"BranchSPARC.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || \r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      UInt32 dest;\r\n      \r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchSPARC.h",
    "content": "/* BranchSPARC.h */\r\n\r\n#ifndef __BRANCH_SPARC_H\r\n#define __BRANCH_SPARC_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchTypes.h",
    "content": "/* BranchTypes.h */\r\n\r\n#ifndef __BRANCHTYPES_H\r\n#define __BRANCHTYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif\r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\n#ifdef _SZ_NO_INT_64\r\ntypedef unsigned long UInt64;\r\n#else\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n#endif\r\n#endif\r\n\r\n/* #define _LZMA_NO_SYSTEM_SIZE_T */\r\n/* You can use it, if you don't want <stddef.h> */\r\n\r\n#ifndef _7ZIP_SIZET_DEFINED\r\n#define _7ZIP_SIZET_DEFINED\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\n#include <stddef.h>\r\ntypedef size_t SizeT;\r\n#endif\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchX86.c",
    "content": "/* BranchX86.c */\r\n\r\n#include \"BranchX86.h\"\r\n\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\nSizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *prevMaskMix, int encoding)\r\n{\r\n  SizeT bufferPos = 0, prevPosT;\r\n  UInt32 prevMask = *prevMaskMix & 0x7;\r\n  if (endPos < 5)\r\n    return 0;\r\n  nowPos += 5;\r\n  prevPosT = (SizeT)0 - 1;\r\n\r\n  for(;;)\r\n  {\r\n    Byte *p = buffer + bufferPos;\r\n    Byte *limit = buffer + endPos - 4;\r\n    for (; p < limit; p++)\r\n      if ((*p & 0xFE) == 0xE8)\r\n        break;\r\n    bufferPos = (SizeT)(p - buffer);\r\n    if (p >= limit)\r\n      break;\r\n    prevPosT = bufferPos - prevPosT;\r\n    if (prevPosT > 3)\r\n      prevMask = 0;\r\n    else\r\n    {\r\n      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r\n      if (prevMask != 0)\r\n      {\r\n        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r\n        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r\n        {\r\n          prevPosT = bufferPos;\r\n          prevMask = ((prevMask << 1) & 0x7) | 1;\r\n          bufferPos++;\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    prevPosT = bufferPos;\r\n\r\n    if (Test86MSByte(p[4]))\r\n    {\r\n      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r\n      UInt32 dest;\r\n      for (;;)\r\n      {\r\n        Byte b;\r\n        int index;\r\n        if (encoding)\r\n          dest = (nowPos + (UInt32)bufferPos) + src;\r\n        else\r\n          dest = src - (nowPos + (UInt32)bufferPos);\r\n        if (prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[prevMask] * 8;\r\n        b = (Byte)(dest >> (24 - index));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index)) - 1);\r\n      }\r\n      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      p[3] = (Byte)(dest >> 16);\r\n      p[2] = (Byte)(dest >> 8);\r\n      p[1] = (Byte)dest;\r\n      bufferPos += 5;\r\n    }\r\n    else\r\n    {\r\n      prevMask = ((prevMask << 1) & 0x7) | 1;\r\n      bufferPos++;\r\n    }\r\n  }\r\n  prevPosT = bufferPos - prevPosT;\r\n  *prevMaskMix = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchX86.h",
    "content": "/* BranchX86.h */\r\n\r\n#ifndef __BRANCHX86_H\r\n#define __BRANCHX86_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\n#define x86_Convert_Init(state) { state = 0; }\r\n\r\nSizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *state, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchX86_2.c",
    "content": "// BranchX86_2.c\r\n\r\n#include \"BranchX86_2.h\"\r\n\r\n#include \"../../Alloc.h\"\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)\r\n#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return BCJ2_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n// #define UpdateBit0(p) Range = bound; *(p) = (CProb)(*(p) + ((kBitModelTotal - *(p)) >> kNumMoveBits));\r\n// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) = (CProb)(*(p) - (*(p) >> kNumMoveBits));\r\n\r\nint x86_2_Decode(\r\n    const Byte *buf0, SizeT size0, \r\n    const Byte *buf1, SizeT size1, \r\n    const Byte *buf2, SizeT size2, \r\n    const Byte *buf3, SizeT size3, \r\n    Byte *outBuf, SizeT outSize)\r\n{\r\n  CProb p[256 + 2];\r\n  SizeT inPos = 0, outPos = 0;\r\n\r\n  const Byte *Buffer, *BufferLim;\r\n  UInt32 Range, Code;\r\n  Byte prevByte = 0;\r\n\r\n  unsigned int i;\r\n  for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)\r\n    p[i] = kBitModelTotal >> 1; \r\n  RC_INIT(buf3, size3);\r\n\r\n  if (outSize == 0)\r\n    return BCJ2_RESULT_OK;\r\n\r\n  for (;;)\r\n  {\r\n    Byte b;\r\n    CProb *prob;\r\n    UInt32 bound;\r\n\r\n    SizeT limit = size0 - inPos;\r\n    if (outSize - outPos < limit)\r\n      limit = outSize - outPos;\r\n    while (limit != 0)\r\n    {\r\n      Byte b = buf0[inPos];\r\n      outBuf[outPos++] = b;\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      inPos++;\r\n      prevByte = b;\r\n      limit--;\r\n    }\r\n\r\n    if (limit == 0 || outPos == outSize)\r\n      break;\r\n\r\n    b = buf0[inPos++];\r\n\r\n    if (b == 0xE8)\r\n      prob = p + prevByte;\r\n    else if (b == 0xE9)\r\n      prob = p + 256;\r\n    else\r\n      prob = p + 257;\r\n\r\n    IfBit0(prob)\r\n    {\r\n      UpdateBit0(prob)\r\n      prevByte = b;\r\n    }\r\n    else\r\n    {\r\n      UInt32 dest;\r\n      const Byte *v;\r\n      UpdateBit1(prob)\r\n      if (b == 0xE8)\r\n      {\r\n        v = buf1;\r\n        if (size1 < 4)\r\n          return BCJ2_RESULT_DATA_ERROR;\r\n        buf1 += 4;\r\n        size1 -= 4;\r\n      }\r\n      else\r\n      {\r\n        v = buf2;\r\n        if (size2 < 4)\r\n          return BCJ2_RESULT_DATA_ERROR;\r\n        buf2 += 4;\r\n        size2 -= 4;\r\n      }\r\n      dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) | \r\n          ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);\r\n      outBuf[outPos++] = (Byte)dest;\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 8);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 16);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = prevByte = (Byte)(dest >> 24);\r\n    }\r\n  }\r\n  return (outPos == outSize) ? BCJ2_RESULT_OK : BCJ2_RESULT_DATA_ERROR;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Branch/BranchX86_2.h",
    "content": "// BranchX86_2.h\r\n\r\n#ifndef __BRANCHX86_2_H\r\n#define __BRANCHX86_2_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\n#define BCJ2_RESULT_OK 0\r\n#define BCJ2_RESULT_DATA_ERROR 1\r\n\r\n/*\r\nConditions:\r\n  outSize <= FullOutputSize, \r\n  where FullOutputSize is full size of output stream of x86_2 filter.\r\n\r\nIf buf0 overlaps outBuf, there are two required conditions:\r\n  1) (buf0 >= outBuf)\r\n  2) (buf0 + size0 >= outBuf + FullOutputSize).\r\n*/\r\n\r\nint x86_2_Decode(\r\n    const Byte *buf0, SizeT size0, \r\n    const Byte *buf1, SizeT size1, \r\n    const Byte *buf2, SizeT size2, \r\n    const Byte *buf3, SizeT size3, \r\n    Byte *outBuf, SizeT outSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Huffman/HuffmanEncode.c",
    "content": "/* Compress/HuffmanEncode.c */\r\n\r\n#include \"HuffmanEncode.h\"\r\n#include \"../../Sort.h\"\r\n\r\n#define kMaxLen 16\r\n#define NUM_BITS 10\r\n#define MASK ((1 << NUM_BITS) - 1)\r\n\r\n#define NUM_COUNTERS 64\r\n\r\n/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M */\r\n#define HUFFMAN_SPEED_OPT\r\n\r\nvoid Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen)\r\n{\r\n  UInt32 num = 0;\r\n  /* if (maxLen > 10) maxLen = 10; */\r\n  {\r\n    UInt32 i;\r\n    \r\n    #ifdef HUFFMAN_SPEED_OPT\r\n    \r\n    UInt32 counters[NUM_COUNTERS];\r\n    for (i = 0; i < NUM_COUNTERS; i++) \r\n      counters[i] = 0;\r\n    for (i = 0; i < numSymbols; i++) \r\n    {\r\n      UInt32 freq = freqs[i];\r\n      counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++;\r\n    }\r\n \r\n    for (i = 1; i < NUM_COUNTERS; i++) \r\n    {\r\n      UInt32 temp = counters[i];\r\n      counters[i] = num;\r\n      num += temp;\r\n    }\r\n\r\n    for (i = 0; i < numSymbols; i++) \r\n    {\r\n      UInt32 freq = freqs[i];\r\n      if (freq == 0)\r\n        lens[i] = 0;\r\n      else\r\n        p[counters[((freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1)]++] = i | (freq << NUM_BITS);\r\n    }\r\n    counters[0] = 0;\r\n    HeapSort(p + counters[NUM_COUNTERS - 2], counters[NUM_COUNTERS - 1] - counters[NUM_COUNTERS - 2]);\r\n    \r\n    #else\r\n\r\n    for (i = 0; i < numSymbols; i++) \r\n    {\r\n      UInt32 freq = freqs[i];\r\n      if (freq == 0)\r\n        lens[i] = 0;\r\n      else\r\n        p[num++] = i | (freq << NUM_BITS);\r\n    }\r\n    HeapSort(p, num);\r\n\r\n    #endif\r\n  }\r\n\r\n  if (num < 2) \r\n  {\r\n    int minCode = 0;\r\n    int maxCode = 1;\r\n    if (num == 1)\r\n    {\r\n      maxCode = p[0] & MASK;\r\n      if (maxCode == 0)\r\n        maxCode++;\r\n    }\r\n    p[minCode] = 0;\r\n    p[maxCode] = 1;\r\n    lens[minCode] = lens[maxCode] = 1;\r\n    return;\r\n  }\r\n  \r\n  {\r\n    UInt32 b, e, i;\r\n  \r\n    i = b = e = 0;\r\n    do \r\n    {\r\n      UInt32 n, m, freq;\r\n      n = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;\r\n      freq = (p[n] & ~MASK);\r\n      p[n] = (p[n] & MASK) | (e << NUM_BITS);\r\n      m = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;\r\n      freq += (p[m] & ~MASK);\r\n      p[m] = (p[m] & MASK) | (e << NUM_BITS);\r\n      p[e] = (p[e] & MASK) | freq;\r\n      e++;\r\n    } \r\n    while (num - e > 1);\r\n    \r\n    {\r\n      UInt32 lenCounters[kMaxLen + 1];\r\n      for (i = 0; i <= kMaxLen; i++) \r\n        lenCounters[i] = 0;\r\n      \r\n      p[--e] &= MASK;\r\n      lenCounters[1] = 2;\r\n      while (e > 0) \r\n      {\r\n        UInt32 len = (p[p[--e] >> NUM_BITS] >> NUM_BITS) + 1;\r\n        p[e] = (p[e] & MASK) | (len << NUM_BITS);\r\n        if (len >= maxLen) \r\n          for (len = maxLen - 1; lenCounters[len] == 0; len--);\r\n        lenCounters[len]--;\r\n        lenCounters[len + 1] += 2;\r\n      }\r\n      \r\n      {\r\n        UInt32 len;\r\n        i = 0;\r\n        for (len = maxLen; len != 0; len--) \r\n        {\r\n          UInt32 num;\r\n          for (num = lenCounters[len]; num != 0; num--) \r\n            lens[p[i++] & MASK] = (Byte)len;\r\n        }\r\n      }\r\n      \r\n      {\r\n        UInt32 nextCodes[kMaxLen + 1];\r\n        {\r\n          UInt32 code = 0;\r\n          UInt32 len;\r\n          for (len = 1; len <= kMaxLen; len++) \r\n            nextCodes[len] = code = (code + lenCounters[len - 1]) << 1;\r\n        }\r\n        /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */\r\n\r\n        {\r\n          UInt32 i;\r\n          for (i = 0; i < numSymbols; i++) \r\n            p[i] = nextCodes[lens[i]]++;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Huffman/HuffmanEncode.h",
    "content": "/* Compress/HuffmanEncode.h */\r\n\r\n#ifndef __COMPRESS_HUFFMANENCODE_H\r\n#define __COMPRESS_HUFFMANENCODE_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n/*\r\nConditions:\r\n  num <= 1024 = 2 ^ NUM_BITS\r\n  Sum(freqs) < 4M = 2 ^ (32 - NUM_BITS)\r\n  maxLen <= 16 = kMaxLen\r\n  Num_Items(p) >= HUFFMAN_TEMP_SIZE(num)\r\n*/\r\n \r\nvoid Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lz/LzHash.h",
    "content": "/* LzHash.h */\r\n\r\n#ifndef __C_LZHASH_H\r\n#define __C_LZHASH_H\r\n\r\n#define kHash2Size (1 << 10)\r\n#define kHash3Size (1 << 16)\r\n#define kHash4Size (1 << 20)\r\n\r\n#define kFix3HashSize (kHash2Size)\r\n#define kFix4HashSize (kHash2Size + kHash3Size)\r\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r\n\r\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r\n\r\n#define HASH3_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r\n\r\n#define HASH4_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & p->hashMask; }\r\n\r\n#define HASH5_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)); \\\r\n  hashValue = (hash4Value ^ (g_CrcTable[cur[4]] << 3)) & p->hashMask; \\\r\n  hash4Value &= (kHash4Size - 1); }\r\n\r\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ g_CrcTable[cur[2]]) & 0xFFFF; */\r\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ g_CrcTable[cur[1]]) & 0xFFFF;\r\n\r\n\r\n#define MT_HASH2_CALC \\\r\n  hash2Value = (g_CrcTable[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r\n\r\n#define MT_HASH3_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r\n\r\n#define MT_HASH4_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & (kHash4Size - 1); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lz/MatchFinder.c",
    "content": "/* MatchFinder.c */\r\n/* Please call InitCrcTable before */\r\n\r\n#include <string.h>\r\n\r\n#include \"MatchFinder.h\"\r\n#include \"LzHash.h\"\r\n\r\n#include \"../../7zCrc.h\"\r\n\r\n#define kEmptyHashValue 0\r\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\r\n#define kMaxHistorySize ((UInt32)3 << 30)\r\n\r\n#define kStartMaxLen 3\r\n\r\nvoid LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  if (!p->directInput)\r\n  {\r\n    alloc->Free(p->bufferBase);\r\n    p->bufferBase = 0;\r\n  }\r\n}\r\n\r\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r\n\r\nint LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r\n{\r\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r\n  if (p->directInput)\r\n  {\r\n    p->blockSize = blockSize;\r\n    return 1;\r\n  }\r\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\r\n  {\r\n    LzInWindow_Free(p, alloc);\r\n    p->blockSize = blockSize;\r\n    p->bufferBase = (Byte *)alloc->Alloc(blockSize);\r\n  }\r\n  return (p->bufferBase != 0);\r\n}\r\n\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r\n\r\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r\n\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r\n{\r\n  p->posLimit -= subValue;\r\n  p->pos -= subValue;\r\n  p->streamPos -= subValue;\r\n}\r\n\r\nvoid MatchFinder_ReadBlock(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached || p->result != SZ_OK)\r\n    return;\r\n  for (;;)\r\n  {\r\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\r\n    UInt32 numReadBytes;\r\n    UInt32 size = (UInt32)(p->bufferBase + p->blockSize - dest);\r\n    if (size == 0)\r\n      return;\r\n    p->result = p->stream->Read(p->stream, dest, size, &numReadBytes);\r\n    if (p->result != SZ_OK)\r\n      return;\r\n    if (numReadBytes == 0)\r\n    {\r\n      p->streamEndWasReached = 1;\r\n      return;\r\n    }\r\n    p->streamPos += numReadBytes;\r\n    if (p->streamPos - p->pos > p->keepSizeAfter)\r\n      return;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\r\n{\r\n  memmove(p->bufferBase, \r\n    p->buffer - p->keepSizeBefore, \r\n    p->streamPos - p->pos + p->keepSizeBefore);\r\n  p->buffer = p->bufferBase + p->keepSizeBefore;\r\n}\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p)\r\n{\r\n  /* if (p->streamEndWasReached) return 0; */\r\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r\n}\r\n\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached) \r\n    return;\r\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\r\n    MatchFinder_ReadBlock(p);\r\n}\r\n\r\nvoid MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r\n{\r\n  if (MatchFinder_NeedMove(p))\r\n    MatchFinder_MoveBlock(p);\r\n  MatchFinder_ReadBlock(p);\r\n}\r\n\r\nvoid MatchFinder_SetDefaultSettings(CMatchFinder *p)\r\n{\r\n  p->cutValue = 32;\r\n  p->btMode = 1;\r\n  p->numHashBytes = 4;\r\n  /* p->skipModeBits = 0; */\r\n  p->directInput = 0;\r\n  p->bigHash = 0;\r\n}\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p)\r\n{\r\n  p->bufferBase = 0;\r\n  p->directInput = 0;\r\n  p->hash = 0;\r\n  MatchFinder_SetDefaultSettings(p);\r\n}\r\n\r\nvoid MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(p->hash);\r\n  p->hash = 0;\r\n}\r\n\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  MatchFinder_FreeThisClassMemory(p, alloc);\r\n  LzInWindow_Free(p, alloc);\r\n}\r\n\r\nCLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r\n{\r\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r\n  if (sizeInBytes / sizeof(CLzRef) != num)\r\n    return 0;\r\n  return (CLzRef *)alloc->Alloc(sizeInBytes);\r\n}\r\n\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize, \r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 sizeReserv;\r\n  if (historySize > kMaxHistorySize)\r\n  {\r\n    MatchFinder_Free(p, alloc);\r\n    return 0;\r\n  }\r\n  sizeReserv = historySize >> 1;\r\n  if (historySize > ((UInt32)2 << 30))\r\n    sizeReserv = historySize >> 2;\r\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r\n\r\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1; \r\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r\n  if (LzInWindow_Create(p, sizeReserv, alloc))\r\n  {\r\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r\n    UInt32 hs;\r\n    p->matchMaxLen = matchMaxLen;\r\n    {\r\n      p->fixedHashSize = 0;\r\n      if (p->numHashBytes == 2)\r\n        hs = (1 << 16) - 1;\r\n      else\r\n      {\r\n        hs = historySize - 1;\r\n        hs |= (hs >> 1);\r\n        hs |= (hs >> 2);\r\n        hs |= (hs >> 4);\r\n        hs |= (hs >> 8);\r\n        hs >>= 1;\r\n        /* hs >>= p->skipModeBits; */\r\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r\n        if (hs > (1 << 24))\r\n        {\r\n          if (p->numHashBytes == 3)\r\n            hs = (1 << 24) - 1;\r\n          else\r\n            hs >>= 1;\r\n        }\r\n      }\r\n      p->hashMask = hs;\r\n      hs++;\r\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r\n      hs += p->fixedHashSize;\r\n    }\r\n\r\n    {\r\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\r\n      UInt32 newSize;\r\n      p->historySize = historySize;\r\n      p->hashSizeSum = hs;\r\n      p->cyclicBufferSize = newCyclicBufferSize;\r\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r\n      newSize = p->hashSizeSum + p->numSons;\r\n      if (p->hash != 0 && prevSize == newSize)\r\n        return 1;\r\n      MatchFinder_FreeThisClassMemory(p, alloc);\r\n      p->hash = AllocRefs(newSize, alloc);\r\n      if (p->hash != 0)\r\n      {\r\n        p->son = p->hash + p->hashSizeSum;\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  MatchFinder_Free(p, alloc);\r\n  return 0;\r\n}\r\n\r\nvoid MatchFinder_SetLimits(CMatchFinder *p)\r\n{\r\n  UInt32 limit = kMaxValForNormalize - p->pos;\r\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r\n  if (limit2 < limit) \r\n    limit = limit2;\r\n  limit2 = p->streamPos - p->pos;\r\n  if (limit2 <= p->keepSizeAfter)\r\n  {\r\n    if (limit2 > 0)\r\n      limit2 = 1;\r\n  }\r\n  else\r\n    limit2 -= p->keepSizeAfter;\r\n  if (limit2 < limit) \r\n    limit = limit2;\r\n  {\r\n    UInt32 lenLimit = p->streamPos - p->pos;\r\n    if (lenLimit > p->matchMaxLen)\r\n      lenLimit = p->matchMaxLen;\r\n    p->lenLimit = lenLimit;\r\n  }\r\n  p->posLimit = p->pos + limit;\r\n}\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < p->hashSizeSum; i++)\r\n    p->hash[i] = kEmptyHashValue;\r\n  p->cyclicBufferPos = 0;\r\n  p->buffer = p->bufferBase;\r\n  p->pos = p->streamPos = p->cyclicBufferSize;\r\n  p->result = SZ_OK;\r\n  p->streamEndWasReached = 0;\r\n  MatchFinder_ReadBlock(p);\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nUInt32 MatchFinder_GetSubValue(CMatchFinder *p) \r\n{ \r\n  return (p->pos - p->historySize - 1) & kNormalizeMask; \r\n}\r\n\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_Normalize(CMatchFinder *p)\r\n{\r\n  UInt32 subValue = MatchFinder_GetSubValue(p);\r\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r\n  MatchFinder_ReduceOffsets(p, subValue);\r\n}\r\n\r\nvoid MatchFinder_CheckLimits(CMatchFinder *p)\r\n{\r\n  if (p->pos == kMaxValForNormalize)\r\n    MatchFinder_Normalize(p);\r\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r\n    MatchFinder_CheckAndMoveAndRead(p);\r\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\r\n    p->cyclicBufferPos = 0;\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nUInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, \r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  son[_cyclicBufferPos] = curMatch;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n      return distances;\r\n    {\r\n      const Byte *pb = cur - delta;\r\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r\n      {\r\n        UInt32 len = 0;\r\n        while(++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n            return distances;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, \r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return distances;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while(++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return distances;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nvoid SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        while(++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        {\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define MOVE_POS \\\r\n  ++p->cyclicBufferPos; \\\r\n  p->buffer++; \\\r\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r\n\r\n#define MOVE_POS_RET MOVE_POS return offset;\r\n\r\nvoid MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r\n\r\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\r\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\r\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\r\n  cur = p->buffer;\r\n\r\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r\n\r\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r\n\r\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\r\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\r\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\r\n\r\n#define SKIP_FOOTER \\\r\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r\n\r\nUInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(2)\r\n  HASH2_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 1)\r\n}\r\n\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 2)\r\n}\r\n\r\nUInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, delta2, maxLen, offset;\r\n  GET_MATCHES_HEADER(3)\r\n\r\n  HASH3_CALC;\r\n\r\n  delta2 = p->pos - p->hash[hash2Value];\r\n  curMatch = p->hash[kFix3HashSize + hashValue];\r\n  \r\n  p->hash[hash2Value] = \r\n  p->hash[kFix3HashSize + hashValue] = p->pos;\r\n\r\n\r\n  maxLen = 2;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[0] = maxLen;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET; \r\n    }\r\n  }\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nUInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n  \r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET; \r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nUInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n\r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      p->son[p->cyclicBufferPos] = curMatch;\r\n      MOVE_POS_RET; \r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances + offset, maxLen) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances, 2) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nvoid Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(2) \r\n    HASH2_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value;\r\n    SKIP_HEADER(3)\r\n    HASH3_CALC;\r\n    curMatch = p->hash[kFix3HashSize + hashValue];\r\n    p->hash[hash2Value] =\r\n    p->hash[kFix3HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4) \r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] =\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r\n  if (!p->btMode)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 2)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 3)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r\n  }\r\n  else\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lz/MatchFinder.h",
    "content": "/* MatchFinder.h */\r\n\r\n#ifndef __MATCHFINDER_H\r\n#define __MATCHFINDER_H\r\n\r\n#include \"../../IStream.h\"\r\n\r\ntypedef UInt32 CLzRef;\r\n\r\ntypedef struct _CMatchFinder\r\n{\r\n  Byte *buffer;\r\n  UInt32 pos;\r\n  UInt32 posLimit;\r\n  UInt32 streamPos;\r\n  UInt32 lenLimit;\r\n\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r\n\r\n  UInt32 matchMaxLen;\r\n  CLzRef *hash;\r\n  CLzRef *son;\r\n  UInt32 hashMask;\r\n  UInt32 cutValue;\r\n\r\n  Byte *bufferBase;\r\n  ISeqInStream *stream;\r\n  int streamEndWasReached;\r\n\r\n  UInt32 blockSize;\r\n  UInt32 keepSizeBefore;\r\n  UInt32 keepSizeAfter;\r\n\r\n  UInt32 numHashBytes;\r\n  int directInput;\r\n  int btMode;\r\n  /* int skipModeBits; */\r\n  int bigHash;\r\n  UInt32 historySize;\r\n  UInt32 fixedHashSize;\r\n  UInt32 hashSizeSum;\r\n  UInt32 numSons;\r\n\r\n  HRes result;\r\n} CMatchFinder;\r\n\r\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r\n\r\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p);\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p);\r\n\r\n/* Conditions:\r\n     historySize <= 3 GB\r\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r\n*/\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize, \r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc);\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, \r\n    UInt32 *distances, UInt32 maxLen);\r\n\r\n/* \r\nConditions:\r\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r\n*/\r\n\r\ntypedef void (*Mf_Init_Func)(void *object);\r\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\r\n\r\ntypedef struct _IMatchFinder\r\n{\r\n  Mf_Init_Func Init;\r\n  Mf_GetIndexByte_Func GetIndexByte;\r\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r\n  Mf_GetMatches_Func GetMatches;\r\n  Mf_Skip_Func Skip;\r\n} IMatchFinder;\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p);\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lz/MatchFinderMt.c",
    "content": "/* MatchFinderMt.c */\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"LzHash.h\"\r\n\r\n#include \"MatchFinderMt.h\"\r\n\r\nvoid MtSync_Construct(CMtSync *p)\r\n{\r\n  p->wasCreated = False;\r\n  p->csWasInitialized = False;\r\n  p->csWasEntered = False;\r\n  Thread_Construct(&p->thread);\r\n  Event_Construct(&p->canStart);\r\n  Event_Construct(&p->wasStarted);\r\n  Event_Construct(&p->wasStopped);\r\n  Semaphore_Construct(&p->freeSemaphore);\r\n  Semaphore_Construct(&p->filledSemaphore);\r\n}\r\n\r\nvoid MtSync_GetNextBlock(CMtSync *p)\r\n{\r\n  if (p->needStart)\r\n  {\r\n    p->numProcessedBlocks = 1;\r\n    p->needStart = False;\r\n    p->stopWriting = False;\r\n    p->exit = False;\r\n    Event_Reset(&p->wasStarted);\r\n    Event_Reset(&p->wasStopped);\r\n\r\n    Event_Set(&p->canStart);\r\n    Event_Wait(&p->wasStarted);\r\n  }\r\n  else\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n    p->numProcessedBlocks++;\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  Semaphore_Wait(&p->filledSemaphore);\r\n  CriticalSection_Enter(&p->cs);\r\n  p->csWasEntered = True;\r\n}\r\n\r\n/* MtSync_StopWriting must be called if Writing was started */\r\n\r\nvoid MtSync_StopWriting(CMtSync *p)\r\n{ \r\n  UInt32 myNumBlocks = p->numProcessedBlocks;\r\n  if (!Thread_WasCreated(&p->thread) || p->needStart)\r\n    return;\r\n  p->stopWriting = True;\r\n  if (p->csWasEntered)\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n  }\r\n  Semaphore_Release1(&p->freeSemaphore);\r\n \r\n  Event_Wait(&p->wasStopped);\r\n\r\n  while (myNumBlocks++ != p->numProcessedBlocks)\r\n  {\r\n    Semaphore_Wait(&p->filledSemaphore);\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  p->needStart = True;\r\n}\r\n\r\nvoid MtSync_Destruct(CMtSync *p)\r\n{\r\n  if (Thread_WasCreated(&p->thread))\r\n  {\r\n    MtSync_StopWriting(p);\r\n    p->exit = True;\r\n    if (p->needStart)\r\n      Event_Set(&p->canStart);\r\n    Thread_Wait(&p->thread);\r\n    Thread_Close(&p->thread);\r\n  }\r\n  if (p->csWasInitialized)\r\n  {\r\n    CriticalSection_Delete(&p->cs);\r\n    p->csWasInitialized = False;\r\n  }\r\n\r\n  Event_Close(&p->canStart);\r\n  Event_Close(&p->wasStarted);\r\n  Event_Close(&p->wasStopped);\r\n  Semaphore_Close(&p->freeSemaphore);\r\n  Semaphore_Close(&p->filledSemaphore);\r\n\r\n  p->wasCreated = False;\r\n}\r\n\r\nHRes MtSync_Create2(CMtSync *p, unsigned (StdCall *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  if (p->wasCreated)\r\n    return SZ_OK;\r\n\r\n  RINOK(CriticalSection_Init(&p->cs));\r\n  p->csWasInitialized = True;\r\n\r\n  RINOK(AutoResetEvent_CreateNotSignaled(&p->canStart));\r\n  RINOK(AutoResetEvent_CreateNotSignaled(&p->wasStarted));\r\n  RINOK(AutoResetEvent_CreateNotSignaled(&p->wasStopped));\r\n  \r\n  RINOK(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));\r\n  RINOK(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));\r\n\r\n  p->needStart = True;\r\n  \r\n  RINOK(Thread_Create(&p->thread, startAddress, obj));\r\n  p->wasCreated = True;\r\n  return SZ_OK;\r\n}\r\n\r\nHRes MtSync_Create(CMtSync *p, unsigned (StdCall *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  HRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\r\n  if (res != SZ_OK)\r\n    MtSync_Destruct(p);\r\n  return res;\r\n}\r\n\r\n\r\nvoid MtSync_Init(CMtSync *p) { p->needStart = True; }\r\n\r\n#define kMtMaxValForNormalize 0xFFFFFFFF\r\n\r\n#define DEF_GetHeads(name, v) \\\r\nstatic void GetHeads ## name(const Byte *p, UInt32 pos, \\\r\nUInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads) { \\\r\nfor (; numHeads != 0; numHeads--) { \\\r\nconst UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r\n\r\nDEF_GetHeads(2,  (p[0] | ((UInt32)p[1] << 8)) & hashMask)\r\nDEF_GetHeads(3,  (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\r\nDEF_GetHeads(4,  (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (g_CrcTable[p[3]] << 5)) & hashMask)\r\nDEF_GetHeads(4b, (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\r\nDEF_GetHeads(5,  (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (g_CrcTable[p[3]] << 5) ^ (g_CrcTable[p[4]] << 3)) & hashMask)\r\n\r\nvoid HashThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->hashSync;\r\n  for (;;)\r\n  {\r\n    UInt32 numProcessedBlocks = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = numProcessedBlocks;\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n\r\n      {\r\n        CMatchFinder *mf = mt->MatchFinder;\r\n        if (MatchFinder_NeedMove(mf))\r\n        {\r\n          CriticalSection_Enter(&mt->btSync.cs);\r\n          CriticalSection_Enter(&mt->hashSync.cs);\r\n          {\r\n            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            const Byte *afterPtr;\r\n            MatchFinder_MoveBlock(mf);\r\n            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            mt->pointerToCurPos -= beforePtr - afterPtr;\r\n            mt->buffer -= beforePtr - afterPtr;\r\n          }\r\n          CriticalSection_Leave(&mt->btSync.cs);\r\n          CriticalSection_Leave(&mt->hashSync.cs);\r\n          continue;\r\n        }\r\n\r\n        Semaphore_Wait(&p->freeSemaphore);\r\n\r\n        MatchFinder_ReadIfRequired(mf);\r\n        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))\r\n        {\r\n          UInt32 subValue = (mf->pos - mf->historySize - 1);\r\n          MatchFinder_ReduceOffsets(mf, subValue);\r\n          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);\r\n        }\r\n        {\r\n          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n          UInt32 num = mf->streamPos - mf->pos;\r\n          heads[0] = 2;\r\n          heads[1] = num;\r\n          if (num >= mf->numHashBytes)\r\n          {\r\n            num = num - mf->numHashBytes + 1;\r\n            if (num > kMtHashBlockSize - 2)\r\n              num = kMtHashBlockSize - 2;\r\n            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num);\r\n            heads[0] += num;\r\n          }\r\n          mf->pos += num;\r\n          mf->buffer += num;\r\n        }\r\n      }\r\n\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r\n{\r\n  MtSync_GetNextBlock(&p->hashSync);\r\n  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];\r\n  p->hashNumAvail = p->hashBuf[p->hashBufPos++];\r\n}\r\n\r\n#define kEmptyHashValue 0\r\n\r\n/* #define MFMT_GM_INLINE */\r\n\r\n#ifdef MFMT_GM_INLINE\r\n\r\n#if _MSC_VER >= 1300\r\n#define NO_INLINE __declspec(noinline) __fastcall \r\n#else\r\n#ifdef _MSC_VER\r\n#define NO_INLINE __fastcall \r\n#endif\r\n#endif\r\n\r\nInt32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, \r\n    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\r\n{\r\n  do\r\n  {\r\n  UInt32 *distances = _distances + 1;\r\n  UInt32 curMatch = pos - *hash++;\r\n\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  UInt32 cutValue = _cutValue;\r\n  UInt32 maxLen = _maxLen;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      break;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while(++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            break;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n  pos++;\r\n  _cyclicBufferPos++;\r\n  cur++;\r\n  {\r\n    UInt32 num = (UInt32)(distances - _distances);\r\n    *_distances = num - 1;\r\n    _distances += num;\r\n    limit -= num;\r\n  }\r\n  }\r\n  while (limit > 0 && --size != 0);\r\n  *posRes = pos;\r\n  return limit;\r\n}\r\n\r\n#endif\r\n\r\nvoid BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  UInt32 numProcessed = 0;\r\n  UInt32 curPos = 2;\r\n  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\r\n  distances[1] = p->hashNumAvail;\r\n  while (curPos < limit)\r\n  {\r\n    if (p->hashBufPos == p->hashBufPosLimit)\r\n    {\r\n      MatchFinderMt_GetNextBlock_Hash(p);\r\n      distances[1] = numProcessed + p->hashNumAvail;\r\n      if (p->hashNumAvail >= p->numHashBytes)\r\n        continue;\r\n      for (; p->hashNumAvail != 0; p->hashNumAvail--)\r\n        distances[curPos++] = 0;\r\n      break;\r\n    }\r\n    {\r\n      UInt32 size = p->hashBufPosLimit - p->hashBufPos;\r\n      UInt32 lenLimit = p->matchMaxLen;\r\n      UInt32 pos = p->pos;\r\n      UInt32 cyclicBufferPos = p->cyclicBufferPos;\r\n      if (lenLimit >= p->hashNumAvail)\r\n        lenLimit = p->hashNumAvail;\r\n      {\r\n        UInt32 size2 = p->hashNumAvail - lenLimit + 1;\r\n        if (size2 < size)\r\n          size = size2;\r\n        size2 = p->cyclicBufferSize - cyclicBufferPos;\r\n        if (size2 < size)\r\n          size = size2;\r\n      }\r\n      #ifndef MFMT_GM_INLINE\r\n      while (curPos < limit && size-- != 0)\r\n      {\r\n        UInt32 *startDistances = distances + curPos;\r\n        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++], \r\n          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, \r\n          startDistances + 1, p->numHashBytes - 1) - startDistances);\r\n        *startDistances = num - 1;\r\n        curPos += num;\r\n        cyclicBufferPos++;\r\n        pos++;\r\n        p->buffer++;\r\n      }\r\n      #else\r\n      {\r\n        UInt32 posRes;\r\n        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, \r\n          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);\r\n        p->hashBufPos += posRes - pos;\r\n        cyclicBufferPos += posRes - pos;\r\n        p->buffer += posRes - pos;\r\n        pos = posRes;\r\n      }\r\n      #endif\r\n\r\n      numProcessed += pos - p->pos;\r\n      p->hashNumAvail -= pos - p->pos;\r\n      p->pos = pos;\r\n      if (cyclicBufferPos == p->cyclicBufferSize)\r\n        cyclicBufferPos = 0;\r\n      p->cyclicBufferPos = cyclicBufferPos;\r\n    }\r\n  }\r\n  distances[0] = curPos;\r\n}\r\n\r\nvoid BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r\n{\r\n  CMtSync *sync = &p->hashSync;\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Enter(&sync->cs);\r\n    sync->csWasEntered = True;\r\n  }\r\n  \r\n  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);\r\n\r\n  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\r\n  {\r\n    UInt32 subValue = p->pos - p->cyclicBufferSize;\r\n    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);\r\n    p->pos -= subValue;\r\n  }\r\n\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Leave(&sync->cs);\r\n    sync->csWasEntered = False;\r\n  }\r\n}\r\n\r\nvoid BtThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->btSync;\r\n  for (;;)\r\n  {\r\n    UInt32 blockIndex = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = blockIndex;\r\n        MtSync_StopWriting(&mt->hashSync);\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n      Semaphore_Wait(&p->freeSemaphore);\r\n      BtFillBlock(mt, blockIndex++);\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p)\r\n{\r\n  p->hashBuf = 0;\r\n  MtSync_Construct(&p->hashSync);\r\n  MtSync_Construct(&p->btSync);\r\n}\r\n\r\nvoid MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(p->hashBuf);\r\n  p->hashBuf = 0;\r\n}\r\n\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  MtSync_Destruct(&p->hashSync);\r\n  MtSync_Destruct(&p->btSync);\r\n  MatchFinderMt_FreeMem(p, alloc);\r\n}\r\n\r\n#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\r\n#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\r\n\r\nstatic unsigned StdCall HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r\nstatic unsigned StdCall BtThreadFunc2(void *p) \r\n{ \r\n  #ifdef USE_ALLOCA\r\n  alloca(0x180);\r\n  #endif\r\n  BtThreadFunc((CMatchFinderMt *)p); \r\n  return 0; \r\n}\r\n\r\nHRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\r\n{ \r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->historySize = historySize;\r\n  if (kMtBtBlockSize <= matchMaxLen * 4)\r\n    return E_INVALIDARG;\r\n  if (p->hashBuf == 0)\r\n  {\r\n    p->hashBuf = (UInt32 *)alloc->Alloc((kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r\n    if (p->hashBuf == 0)\r\n      return SZE_OUTOFMEMORY;\r\n    p->btBuf = p->hashBuf + kHashBufferSize;\r\n  }\r\n  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);\r\n  keepAddBufferAfter += kMtHashBlockSize;\r\n  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));\r\n  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));\r\n  return SZ_OK;\r\n}\r\n\r\n/* Call it after ReleaseStream / SetStream */\r\nvoid MatchFinderMt_Init(CMatchFinderMt *p)\r\n{ \r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->btBufPos = p->btBufPosLimit = 0;\r\n  p->hashBufPos = p->hashBufPosLimit = 0;\r\n  MatchFinder_Init(mf);\r\n  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);\r\n  p->btNumAvailBytes = 0;\r\n  p->lzPos = p->historySize + 1;\r\n\r\n  p->hash = mf->hash;\r\n  p->fixedHashSize = mf->fixedHashSize;\r\n\r\n  p->son = mf->son;\r\n  p->matchMaxLen = mf->matchMaxLen;\r\n  p->numHashBytes = mf->numHashBytes;\r\n  p->pos = mf->pos;\r\n  p->buffer = mf->buffer;\r\n  p->cyclicBufferPos = mf->cyclicBufferPos;\r\n  p->cyclicBufferSize = mf->cyclicBufferSize;\r\n  p->cutValue = mf->cutValue;\r\n}\r\n\r\n/* ReleaseStream is required to finish multithreading */\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p)\r\n{ \r\n  MtSync_StopWriting(&p->btSync);\r\n  /* p->MatchFinder->ReleaseStream(); */\r\n}\r\n\r\nvoid MatchFinderMt_Normalize(CMatchFinderMt *p)\r\n{\r\n  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\r\n  p->lzPos = p->historySize + 1;\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r\n{\r\n  UInt32 blockIndex;\r\n  MtSync_GetNextBlock(&p->btSync);\r\n  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);\r\n  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;\r\n  p->btBufPosLimit += p->btBuf[p->btBufPos++];\r\n  p->btNumAvailBytes = p->btBuf[p->btBufPos++];\r\n  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize) \r\n    MatchFinderMt_Normalize(p);\r\n}\r\n\r\nconst Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r\n{\r\n  return p->pointerToCurPos;\r\n}\r\n\r\n#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\r\n\r\nUInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r\n{ \r\n  GET_NEXT_BLOCK_IF_REQUIRED;\r\n  return p->btNumAvailBytes;\r\n}\r\n\r\nByte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)\r\n{ \r\n  return p->pointerToCurPos[index]; \r\n}\r\n\r\nUInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, curMatch2;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos; \r\n  MT_HASH2_CALC\r\n      \r\n  curMatch2 = hash[hash2Value];\r\n  hash[hash2Value] = lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos) \r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n    {\r\n      *distances++ = 2; \r\n      *distances++ = lzPos - curMatch2 - 1;\r\n    }\r\n  return distances;\r\n}\r\n\r\nUInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos; \r\n  MT_HASH3_CALC\r\n\r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  \r\n  hash[                hash2Value] = \r\n  hash[kFix3HashSize + hash3Value] = \r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  { \r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] = 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2; \r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  { \r\n    *distances++ = 3; \r\n    *distances++ = lzPos - curMatch3 - 1; \r\n  }\r\n  return distances;\r\n}\r\n\r\n/*\r\nUInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos; \r\n  MT_HASH4_CALC\r\n      \r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  curMatch4 = hash[kFix4HashSize + hash4Value];\r\n  \r\n  hash[                hash2Value] = \r\n  hash[kFix3HashSize + hash3Value] = \r\n  hash[kFix4HashSize + hash4Value] = \r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch3 - 1;\r\n    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])\r\n    {\r\n      distances[0] = 4;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 3;\r\n    distances += 2;\r\n  }\r\n\r\n  if (curMatch4 >= matchMinPos)\r\n    if (\r\n      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&\r\n      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]\r\n      )\r\n    {\r\n      *distances++ = 4;\r\n      *distances++ = lzPos - curMatch4 - 1;\r\n    }\r\n  return distances;\r\n}\r\n*/\r\n\r\n#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\r\n\r\nUInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{ \r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n  p->btNumAvailBytes--;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < len; i += 2)\r\n    {\r\n      *distances++ = *btBuf++;\r\n      *distances++ = *btBuf++;\r\n    }\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\nUInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{ \r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n\r\n  if (len == 0)\r\n  {\r\n    if (p->btNumAvailBytes-- >= 4) \r\n      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\r\n  }\r\n  else\r\n  {\r\n    /* Condition: there are matches in btBuf with length < p->numHashBytes */\r\n    UInt32 *distances2;\r\n    p->btNumAvailBytes--;\r\n    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\r\n    do \r\n    {\r\n      *distances2++ = *btBuf++;\r\n      *distances2++ = *btBuf++;\r\n    }\r\n    while ((len -= 2) != 0);\r\n    len  = (UInt32)(distances2 - (distances));\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\n#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED\r\n#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r\n#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while(--num != 0);\r\n\r\nvoid MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER2 { p->btNumAvailBytes--;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER(2)\r\n      UInt32 hash2Value;\r\n      MT_HASH2_CALC\r\n      hash[hash2Value] = p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER(3)\r\n      UInt32 hash2Value, hash3Value;\r\n      MT_HASH3_CALC\r\n      hash[kFix3HashSize + hash3Value] = \r\n      hash[                hash2Value] = \r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\n/*\r\nvoid MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER(4)\r\n      UInt32 hash2Value, hash3Value, hash4Value;\r\n      MT_HASH4_CALC\r\n      hash[kFix4HashSize + hash4Value] = \r\n      hash[kFix3HashSize + hash3Value] = \r\n      hash[                hash2Value] = \r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n*/\r\n\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\r\n  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\r\n  switch(p->MatchFinder->numHashBytes)\r\n  {\r\n    case 2:\r\n      p->GetHeadsFunc = GetHeads2;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)0;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\r\n      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\r\n      break;\r\n    case 3:\r\n      p->GetHeadsFunc = GetHeads3;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;\r\n      break;\r\n    default:\r\n    /* case 4: */\r\n      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\r\n      /* p->GetHeadsFunc = GetHeads4; */\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\r\n      break;\r\n    /*\r\n    default:\r\n      p->GetHeadsFunc = GetHeads5;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;\r\n      break;\r\n    */\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lz/MatchFinderMt.h",
    "content": "/* MatchFinderMt.h */\r\n\r\n#ifndef __MATCHFINDERMT_H\r\n#define __MATCHFINDERMT_H\r\n\r\n#include \"../../Threads.h\"\r\n#include \"MatchFinder.h\"\r\n\r\n#define kMtHashBlockSize (1 << 13)\r\n#define kMtHashNumBlocks (1 << 3)\r\n#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)\r\n\r\n#define kMtBtBlockSize (1 << 14)\r\n#define kMtBtNumBlocks (1 << 6)\r\n#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)\r\n\r\ntypedef struct _CMtSync\r\n{\r\n  Bool wasCreated;\r\n  Bool needStart;\r\n  Bool exit;\r\n  Bool stopWriting;\r\n\r\n  CThread thread;\r\n  CAutoResetEvent canStart;\r\n  CAutoResetEvent wasStarted;\r\n  CAutoResetEvent wasStopped;\r\n  CSemaphore freeSemaphore;\r\n  CSemaphore filledSemaphore;\r\n  Bool csWasInitialized;\r\n  Bool csWasEntered;\r\n  CCriticalSection cs;\r\n  UInt32 numProcessedBlocks;\r\n} CMtSync;\r\n\r\ntypedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);\r\n\r\n/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */\r\n#define kMtCacheLineDummy 128\r\n\r\ntypedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,\r\n  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads);\r\n\r\ntypedef struct _CMatchFinderMt\r\n{\r\n  /* LZ */\r\n  const Byte *pointerToCurPos;\r\n  UInt32 *btBuf;\r\n  UInt32 btBufPos;\r\n  UInt32 btBufPosLimit;\r\n  UInt32 lzPos;\r\n  UInt32 btNumAvailBytes;\r\n\r\n  UInt32 *hash;\r\n  UInt32 fixedHashSize;\r\n  UInt32 historySize;\r\n\r\n  Mf_Mix_Matches MixMatchesFunc;\r\n  \r\n  /* LZ + BT */\r\n  CMtSync btSync;\r\n  Byte btDummy[kMtCacheLineDummy];\r\n\r\n  /* BT */\r\n  UInt32 *hashBuf;\r\n  UInt32 hashBufPos;\r\n  UInt32 hashBufPosLimit;\r\n  UInt32 hashNumAvail;\r\n\r\n  CLzRef *son;\r\n  UInt32 matchMaxLen;\r\n  UInt32 numHashBytes;\r\n  UInt32 pos;\r\n  Byte *buffer;\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be historySize + 1 */\r\n  UInt32 cutValue;\r\n\r\n  /* BT + Hash */\r\n  CMtSync hashSync;\r\n  /* Byte hashDummy[kMtCacheLineDummy]; */\r\n  \r\n  /* Hash */\r\n  Mf_GetHeads GetHeadsFunc;\r\n  CMatchFinder *MatchFinder;\r\n} CMatchFinderMt;\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p);\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);\r\nHRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/LzmaDecode.c",
    "content": "/*\r\n  LzmaDecode.c\r\n  LZMA Decoder (optimized for Speed version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) \\\r\n  { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \\\r\n  BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}\r\n\r\n#define RC_INIT Buffer = BufferLim = 0; RC_INIT2\r\n\r\n#else\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#endif\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  const Byte *Buffer = vs->Buffer;\r\n  const Byte *BufferLim = vs->BufferLim;\r\n  #else\r\n  const Byte *Buffer = inStream;\r\n  const Byte *BufferLim = inStream + inSize;\r\n  #endif\r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      #ifdef _LZMA_IN_CB\r\n      RC_INIT;\r\n      #else\r\n      RC_INIT(inStream, inSize);\r\n      #endif\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  RC_INIT;\r\n  #else\r\n  RC_INIT(inStream, inSize);\r\n  #endif\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (Byte)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n            UpdateBit0(prob);\r\n            \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            \r\n            state = state < kNumLitStates ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = Buffer;\r\n  vs->BufferLim = BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/LzmaDecode.h",
    "content": "/* \r\n  LzmaDecode.h\r\n  LZMA Decoder interface\r\n\r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMADECODE_H\r\n#define __LZMADECODE_H\r\n\r\n#include \"LzmaTypes.h\"\r\n\r\n/* #define _LZMA_IN_CB */\r\n/* Use callback for input data */\r\n\r\n/* #define _LZMA_OUT_READ */\r\n/* Use read function for output data */\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_LOC_OPT */\r\n/* Enable local speed optimizations inside code */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#ifdef _LZMA_IN_CB\r\ntypedef struct _ILzmaInCallback\r\n{\r\n  int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);\r\n} ILzmaInCallback;\r\n#endif\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  #ifdef _LZMA_OUT_READ\r\n  UInt32 DictionarySize;\r\n  #endif\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  const unsigned char *Buffer;\r\n  const unsigned char *BufferLim;\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  unsigned char *Dictionary;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;\r\n  unsigned char TempDictionary[4];\r\n  #endif\r\n} CLzmaDecoderState;\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }\r\n#endif\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *inCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/LzmaDecodeSize.c",
    "content": "/*\r\n  LzmaDecodeSize.c\r\n  LZMA Decoder (optimized for Size version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\ntypedef struct _CRangeDecoder\r\n{\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  #ifdef _LZMA_IN_CB\r\n  ILzmaInCallback *InCallback;\r\n  int Result;\r\n  #endif\r\n  int ExtraBytes;\r\n} CRangeDecoder;\r\n\r\nByte RangeDecoderReadByte(CRangeDecoder *rd)\r\n{\r\n  if (rd->Buffer == rd->BufferLim)\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    SizeT size;\r\n    rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);\r\n    rd->BufferLim = rd->Buffer + size;\r\n    if (size == 0)\r\n    #endif\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n  }\r\n  return (*rd->Buffer++);\r\n}\r\n\r\n/* #define ReadByte (*rd->Buffer++) */\r\n#define ReadByte (RangeDecoderReadByte(rd))\r\n\r\nvoid RangeDecoderInit(CRangeDecoder *rd\r\n  #ifndef _LZMA_IN_CB\r\n    , const Byte *stream, SizeT bufferSize\r\n  #endif\r\n    )\r\n{\r\n  int i;\r\n  #ifdef _LZMA_IN_CB\r\n  rd->Buffer = rd->BufferLim = 0;\r\n  #else\r\n  rd->Buffer = stream;\r\n  rd->BufferLim = stream + bufferSize;\r\n  #endif\r\n  rd->ExtraBytes = 0;\r\n  rd->Code = 0;\r\n  rd->Range = (0xFFFFFFFF);\r\n  for(i = 0; i < 5; i++)\r\n    rd->Code = (rd->Code << 8) | ReadByte;\r\n}\r\n\r\n#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;        \r\n#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;\r\n#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }\r\n\r\nUInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)\r\n{\r\n  RC_INIT_VAR\r\n  UInt32 result = 0;\r\n  int i;\r\n  for (i = numTotalBits; i != 0; i--)\r\n  {\r\n    /* UInt32 t; */\r\n    range >>= 1;\r\n\r\n    result <<= 1;\r\n    if (code >= range)\r\n    {\r\n      code -= range;\r\n      result |= 1;\r\n    }\r\n    /*\r\n    t = (code - range) >> 31;\r\n    t &= 1;\r\n    code -= range & (t - 1);\r\n    result = (result + result) | (1 - t);\r\n    */\r\n    RC_NORMALIZE\r\n  }\r\n  RC_FLUSH_VAR\r\n  return result;\r\n}\r\n\r\nint RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)\r\n{\r\n  UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;\r\n  if (rd->Code < bound)\r\n  {\r\n    rd->Range = bound;\r\n    *prob += (kBitModelTotal - *prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 0;\r\n  }\r\n  else\r\n  {\r\n    rd->Range -= bound;\r\n    rd->Code -= bound;\r\n    *prob -= (*prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 1;\r\n  }\r\n}\r\n\r\n#define RC_GET_BIT2(prob, mi, A0, A1) \\\r\n  UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \\\r\n  if (code < bound) \\\r\n    { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \\\r\n  else \\\r\n    { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)               \r\n\r\nint RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = numLevels; i != 0; i--)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT(prob, mi)\r\n    #else\r\n    mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return mi - (1 << numLevels);\r\n}\r\n\r\nint RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  int symbol = 0;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = 0; i < numLevels; i++)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))\r\n    #else\r\n    int bit = RangeDecoderBitDecode(probs + mi, rd);\r\n    mi = mi + mi + bit;\r\n    symbol |= (bit << i);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + symbol;\r\n    RC_GET_BIT(prob, symbol)\r\n    #else\r\n    symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n    #endif\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    int bit;\r\n    int matchBit = (matchByte >> 7) & 1;\r\n    matchByte <<= 1;\r\n    #ifdef _LZMA_LOC_OPT\r\n    {\r\n      CProb *prob = probs + 0x100 + (matchBit << 8) + symbol;\r\n      RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)\r\n    }\r\n    #else\r\n    bit = RangeDecoderBitDecode(probs + 0x100 + (matchBit << 8) + symbol, rd);\r\n    symbol = (symbol << 1) | bit;\r\n    #endif\r\n    if (matchBit != bit)\r\n    {\r\n      while (symbol < 0x100)\r\n      {\r\n        #ifdef _LZMA_LOC_OPT\r\n        CProb *prob = probs + symbol;\r\n        RC_GET_BIT(prob, symbol)\r\n        #else\r\n        symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n        #endif\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\nint LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)\r\n{\r\n  if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)\r\n    return RangeDecoderBitTreeDecode(p + LenLow +\r\n        (posState << kLenNumLowBits), kLenNumLowBits, rd);\r\n  if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)\r\n    return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +\r\n        (posState << kLenNumMidBits), kLenNumMidBits, rd);\r\n  return kLenNumLowSymbols + kLenNumMidSymbols + \r\n      RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);\r\n}\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  CRangeDecoder rd;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  rd.Range = vs->Range;\r\n  rd.Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  rd.Buffer = vs->Buffer;\r\n  rd.BufferLim = vs->BufferLim;\r\n  #else\r\n  rd.Buffer = inStream;\r\n  rd.BufferLim = inStream + inSize;\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RangeDecoderInit(&rd\r\n          #ifndef _LZMA_IN_CB\r\n          , inStream, inSize\r\n          #endif\r\n          );\r\n      #ifdef _LZMA_IN_CB\r\n      if (rd.Result != LZMA_RESULT_OK)\r\n        return rd.Result;\r\n      #endif\r\n      if (rd.ExtraBytes != 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  rd.Result = LZMA_RESULT_OK;\r\n  #endif\r\n  rd.ExtraBytes = 0;\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  #endif\r\n  RangeDecoderInit(&rd\r\n      #ifndef _LZMA_IN_CB\r\n      , inStream, inSize\r\n      #endif\r\n      );\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  if (rd.Result != LZMA_RESULT_OK)\r\n    return rd.Result;\r\n  #endif\r\n  if (rd.ExtraBytes != 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n    #ifdef _LZMA_IN_CB\r\n    if (rd.Result != LZMA_RESULT_OK)\r\n      return rd.Result;\r\n    #endif\r\n    if (rd.ExtraBytes != 0)\r\n      return LZMA_RESULT_DATA_ERROR;\r\n    if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n    {\r\n      CProb *probs = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        Byte matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);\r\n      }\r\n      else\r\n        previousByte = LzmaLiteralDecode(probs, &rd);\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)\r\n      {\r\n        if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)\r\n        {\r\n          if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n      \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n\r\n            state = state < 7 ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n            continue;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)\r\n            distance = rep1;\r\n          else \r\n          {\r\n            if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)\r\n              distance = rep2;\r\n            else\r\n            {\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        len = LzmaLenDecode(p + RepLenCoder, &rd, posState);\r\n        state = state < 7 ? 8 : 11;\r\n      }\r\n      else\r\n      {\r\n        int posSlot;\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < 7 ? 7 : 10;\r\n        len = LzmaLenDecode(p + LenCoder, &rd, posState);\r\n        posSlot = RangeDecoderBitTreeDecode(p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits), kNumPosSlotBits, &rd);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 += RangeDecoderReverseBitTreeDecode(\r\n                p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);\r\n          }\r\n          else\r\n          {\r\n            rep0 += RangeDecoderDecodeDirectBits(&rd, \r\n                numDirectBits - kNumAlignBits) << kNumAlignBits;\r\n            rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = rd.Range;\r\n  vs->Code = rd.Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = rd.Buffer;\r\n  vs->BufferLim = rd.BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(rd.Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/LzmaStateDecode.c",
    "content": "/*\r\n  LzmaStateDecode.c\r\n  LZMA Decoder (State version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\n/* kRequiredInBufferSize = number of required input bytes for worst case: \r\n   longest match with longest distance.\r\n   kLzmaInBufferSize must be larger than kRequiredInBufferSize \r\n   23 bits = 2 (match select) + 10 (len) + 6 (distance) + 4(align) + 1 (RC_NORMALIZE)\r\n*/\r\n\r\n#define kRequiredInBufferSize ((23 * (kNumBitModelTotalBits - kNumMoveBits + 1) + 26 + 9) / 8)\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n    return LZMA_RESULT_OK;\r\n  }\r\n}\r\n\r\nint LzmaDecode(\r\n    CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding)\r\n{\r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n\r\n  unsigned char *Buffer = vs->Buffer;\r\n  int BufferSize = vs->BufferSize; /* don't change it to unsigned int */\r\n  CProb *p = vs->Probs;\r\n\r\n  int state = vs->State;\r\n  unsigned char previousByte;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  SizeT nowPos = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  unsigned char *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  unsigned char tempDictionary[4];\r\n\r\n  (*inSizeProcessed) = 0;\r\n  (*outSizeProcessed) = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n    {\r\n      Buffer[BufferSize++] = *inStream++;\r\n      (*inSizeProcessed)++;\r\n      inSize--;\r\n    }\r\n    if (BufferSize < 5)\r\n    {\r\n      vs->BufferSize = BufferSize;\r\n      return finishDecoding ? LZMA_RESULT_DATA_ERROR : LZMA_RESULT_OK;\r\n    }\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RC_INIT;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  for (;;)\r\n  {\r\n    int bufferPos = (int)(Buffer - vs->Buffer);\r\n    if (BufferSize - bufferPos < kRequiredInBufferSize)\r\n    {\r\n      int i;\r\n      BufferSize -= bufferPos;\r\n      if (BufferSize < 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n      for (i = 0; i < BufferSize; i++)\r\n        vs->Buffer[i] = Buffer[i];\r\n      Buffer = vs->Buffer;\r\n      while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n      {\r\n        Buffer[BufferSize++] = *inStream++;\r\n        (*inSizeProcessed)++;\r\n        inSize--;\r\n      }\r\n      if (BufferSize < kRequiredInBufferSize && !finishDecoding)\r\n        break;\r\n    }\r\n    if (nowPos >= outSize)\r\n      break;\r\n    {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)((nowPos + globalPos) & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        ((((nowPos + globalPos)& literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (unsigned char)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            UInt32 pos;\r\n            UpdateBit0(prob);\r\n            if (distanceLimit == 0)\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            outStream[nowPos++] = previousByte;\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      if (rep0 > distanceLimit) \r\n        return LZMA_RESULT_DATA_ERROR;\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n\r\n      do\r\n      {\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  BufferSize -= (int)(Buffer - vs->Buffer);\r\n  if (BufferSize < 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    int i;\r\n    for (i = 0; i < BufferSize; i++)\r\n      vs->Buffer[i] = Buffer[i];\r\n  }\r\n  vs->BufferSize = BufferSize;\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = (UInt32)(globalPos + nowPos);\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n\r\n  (*outSizeProcessed) = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/LzmaStateDecode.h",
    "content": "/* \r\n  LzmaStateDecode.h\r\n  LZMA Decoder interface (State version)\r\n\r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMASTATEDECODE_H\r\n#define __LZMASTATEDECODE_H\r\n\r\n#include \"LzmaTypes.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  UInt32 DictionarySize;\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))\r\n\r\n#define kLzmaInBufferSize 64   /* don't change it. it must be larger than kRequiredInBufferSize */\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n  unsigned char *Dictionary;\r\n\r\n  unsigned char Buffer[kLzmaInBufferSize];\r\n  int BufferSize;\r\n\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;  /* -2: decoder needs internal initialization\r\n                     -1: stream was finished, \r\n                      0: ok\r\n                    > 0: need to write RemainLen bytes as match Reps[0],\r\n                  */\r\n  unsigned char TempDictionary[4];  /* it's required when DictionarySize = 0 */\r\n} CLzmaDecoderState;\r\n\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }\r\n\r\n/* LzmaDecode: decoding from input stream to output stream.\r\n  If finishDecoding != 0, then there are no more bytes in input stream\r\n  after inStream[inSize - 1]. */\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize,  SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/LzmaStateTest.c",
    "content": "/* \r\nLzmaStateTest.c\r\nTest application for LZMA Decoder (State version)\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\n#define kInBufferSize (1 << 15)\r\n#define kOutBufferSize (1 << 15)\r\n\r\nunsigned char g_InBuffer[kInBufferSize];\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n  { return fread(data, 1, size, file); }\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size); }\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0; \r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  int i;\r\n  int res = 0;\r\n  CLzmaDecoderState state;  /* it's about 140 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n  SizeT inAvail = 0;\r\n  unsigned char *inBuffer = 0;\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n  \r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    unsigned char b;\r\n    if (!MyReadFileAndCheck(inFile, &b, 1))\r\n      return PrintError(rs, kCantReadMessage);\r\n    if (b != 0xFF)\r\n      waitEOS = 0;\r\n    if (i < 4)\r\n      outSize += (UInt32)(b) << (i * 8);\r\n    else\r\n      outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  \r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      free(state.Probs);\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    }\r\n  }\r\n  \r\n  /* Decompress */\r\n  \r\n  LzmaDecoderInit(&state);\r\n  \r\n  do\r\n  {\r\n    SizeT inProcessed, outProcessed;\r\n    int finishDecoding;\r\n    UInt32 outAvail = kOutBufferSize;\r\n    if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n      outAvail = outSize;\r\n    if (inAvail == 0)\r\n    {\r\n      inAvail = (SizeT)MyReadFile(inFile, g_InBuffer, kInBufferSize);\r\n      inBuffer = g_InBuffer;\r\n    }\r\n    finishDecoding = (inAvail == 0);\r\n    res = LzmaDecode(&state,\r\n        inBuffer, inAvail, &inProcessed,\r\n        g_OutBuffer, outAvail, &outProcessed,\r\n        finishDecoding);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n      break;\r\n    }\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n    \r\n    if (outFile != 0)  \r\n      if (fwrite(g_OutBuffer, 1, outProcessed, outFile) != outProcessed)\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n        break;\r\n      }\r\n      \r\n    if (outSize < outProcessed)\r\n      outSizeHigh--;\r\n    outSize -= (UInt32)outProcessed;\r\n    outSize &= 0xFFFFFFFF;\r\n\r\n    if (outProcessed == 0 && finishDecoding)\r\n    {\r\n      if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n        res = 1;\r\n      break;\r\n    }\r\n  }\r\n  while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n\r\n  free(state.Dictionary);\r\n  free(state.Probs);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-02\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/LzmaTest.c",
    "content": "/* \r\nLzmaTest.c\r\nTest application for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-05)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fread(data, 1, size, file); \r\n}\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size);} \r\n\r\nsize_t MyWriteFile(FILE *file, const void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fwrite(data, 1, size, file); \r\n}\r\n\r\nint MyWriteFileAndCheck(FILE *file, const void *data, size_t size)\r\n  { return (MyWriteFile(file, data, size) == size); }\r\n\r\n#ifdef _LZMA_IN_CB\r\n#define kInBufferSize (1 << 15)\r\ntypedef struct _CBuffer\r\n{\r\n  ILzmaInCallback InCallback;\r\n  FILE *File;\r\n  unsigned char Buffer[kInBufferSize];\r\n} CBuffer;\r\n\r\nint LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CBuffer *b = (CBuffer *)object;\r\n  *buffer = b->Buffer;\r\n  *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);\r\n  return LZMA_RESULT_OK;\r\n}\r\nCBuffer g_InBuffer;\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define kOutBufferSize (1 << 15)\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n#endif\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0;\r\n  #ifndef _LZMA_OUT_READ\r\n  SizeT outSizeFull;\r\n  unsigned char *outStream;\r\n  #endif\r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  SizeT compressedSize;\r\n  unsigned char *inStream;\r\n  #endif\r\n\r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n  int res;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.File = inFile;\r\n  #endif\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  {\r\n    long length;\r\n    fseek(inFile, 0, SEEK_END);\r\n    length = ftell(inFile);\r\n    fseek(inFile, 0, SEEK_SET);\r\n    if ((long)(SizeT)length != length)\r\n      return PrintError(rs, \"Too big compressed stream\");\r\n    compressedSize = (SizeT)(length - (LZMA_PROPERTIES_SIZE + 8));\r\n  }\r\n  #endif\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n\r\n  {\r\n    int i;\r\n    for (i = 0; i < 8; i++)\r\n    {\r\n      unsigned char b;\r\n      if (!MyReadFileAndCheck(inFile, &b, 1))\r\n        return PrintError(rs, kCantReadMessage);\r\n      if (b != 0xFF)\r\n        waitEOS = 0;\r\n      if (i < 4)\r\n        outSize += (UInt32)(b) << (i * 8);\r\n      else\r\n        outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n    }\r\n    \r\n    #ifndef _LZMA_OUT_READ\r\n    if (waitEOS)\r\n      return PrintError(rs, \"Stream with EOS marker is not supported\");\r\n    outSizeFull = (SizeT)outSize;\r\n    if (sizeof(SizeT) >= 8)\r\n      outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);\r\n    else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)\r\n      return PrintError(rs, \"Too big uncompressed stream\");\r\n    #endif\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n  #else\r\n  if (outSizeFull == 0)\r\n    outStream = 0;\r\n  else\r\n    outStream = (unsigned char *)malloc(outSizeFull);\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  if (compressedSize == 0)\r\n    inStream = 0;\r\n  else\r\n    inStream = (unsigned char *)malloc(compressedSize);\r\n  #endif\r\n\r\n  if (state.Probs == 0 \r\n    #ifdef _LZMA_OUT_READ\r\n    || (state.Dictionary == 0 && state.Properties.DictionarySize != 0)\r\n    #else\r\n    || (outStream == 0 && outSizeFull != 0)\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    || (inStream == 0 && compressedSize != 0)\r\n    #endif\r\n    )\r\n  {\r\n    free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    free(state.Dictionary);\r\n    #else\r\n    free(outStream);\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    free(inStream);\r\n    #endif\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  }\r\n\r\n  /* Decompress */\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  #else\r\n  if (!MyReadFileAndCheck(inFile, inStream, compressedSize))\r\n    return PrintError(rs, kCantReadMessage);\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inAvail = compressedSize;\r\n    const unsigned char *inBuffer = inStream;\r\n    #endif\r\n    LzmaDecoderInit(&state);\r\n    do\r\n    {\r\n      #ifndef _LZMA_IN_CB\r\n      SizeT inProcessed;\r\n      #endif\r\n      SizeT outProcessed;\r\n      SizeT outAvail = kOutBufferSize;\r\n      if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n        outAvail = (SizeT)outSize;\r\n      res = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &g_InBuffer.InCallback,\r\n        #else\r\n        inBuffer, inAvail, &inProcessed,\r\n        #endif\r\n        g_OutBuffer, outAvail, &outProcessed);\r\n      if (res != 0)\r\n      {\r\n        sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n        res = 1;\r\n        break;\r\n      }\r\n      #ifndef _LZMA_IN_CB\r\n      inAvail -= inProcessed;\r\n      inBuffer += inProcessed;\r\n      #endif\r\n      \r\n      if (outFile != 0)  \r\n        if (!MyWriteFileAndCheck(outFile, g_OutBuffer, (size_t)outProcessed))\r\n        {\r\n          PrintError(rs, kCantWriteMessage);\r\n          res = 1;\r\n          break;\r\n        }\r\n        \r\n      if (outSize < outProcessed)\r\n        outSizeHigh--;\r\n      outSize -= (UInt32)outProcessed;\r\n      outSize &= 0xFFFFFFFF;\r\n        \r\n      if (outProcessed == 0)\r\n      {\r\n        if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n          res = 1;\r\n        break;\r\n      }\r\n    }\r\n    while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n  }\r\n\r\n  #else\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inProcessed;\r\n    #endif\r\n    SizeT outProcessed;\r\n    res = LzmaDecode(&state,\r\n      #ifdef _LZMA_IN_CB\r\n      &g_InBuffer.InCallback,\r\n      #else\r\n      inStream, compressedSize, &inProcessed,\r\n      #endif\r\n      outStream, outSizeFull, &outProcessed);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n    }\r\n    else if (outFile != 0)\r\n    {\r\n      if (!MyWriteFileAndCheck(outFile, outStream, (size_t)outProcessed))\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  free(state.Dictionary);\r\n  #else\r\n  free(outStream);\r\n  #endif\r\n  #ifndef _LZMA_IN_CB\r\n  free(inStream);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-05\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/LzmaTypes.h",
    "content": "/* \r\nLzmaTypes.h \r\n\r\nTypes for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.40 (2006-05-01)\r\n*/\r\n\r\n#ifndef __LZMATYPES_H\r\n#define __LZMATYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif \r\n\r\n/* #define _LZMA_NO_SYSTEM_SIZE_T */\r\n/* You can use it, if you don't want <stddef.h> */\r\n\r\n#ifndef _7ZIP_SIZET_DEFINED\r\n#define _7ZIP_SIZET_DEFINED\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\n#include <stddef.h>\r\ntypedef size_t SizeT;\r\n#endif\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/kmod/Makefile",
    "content": "\n# Copyright (C) 2006-2008 Junjiro Okajima\n# Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: Makefile,v 1.3 2008-03-12 01:49:39 jro Exp $\n\n# # the environment variables are not inherited since 2.6.23\n# ifdef SQLZMA_EXTRA_CFLAGS\n# EXTRA_CFLAGS += ${SQLZMA_EXTRA_CFLAGS}\n# endif\n\nobj-m += unlzma.o sqlzma.o\nunlzma-y := module.o\nsqlzma-y := uncomp.o\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/kmod/module.c",
    "content": "\n/*\n * Copyright (C) 2006-2007 Junjiro Okajima\n * Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: module.c,v 1.1 2007-11-05 05:43:36 jro Exp $ */\n\n#include <linux/init.h>\n#include <linux/module.h>\n\n#include \"../LzmaDecode.c\"\n\nEXPORT_SYMBOL(LzmaDecodeProperties);\nEXPORT_SYMBOL(LzmaDecode);\n\n#if 0\nstatic int __init unlzma_init(void)\n{\n\treturn 0;\n}\n\nstatic void __exit unlzma_exit(void)\n{\n}\n\nmodule_init(unlzma_init);\nmodule_exit(unlzma_exit);\n#endif\n\nMODULE_LICENSE(\"GPL\");\nMODULE_VERSION(\"$Id: module.c,v 1.1 2007-11-05 05:43:36 jro Exp $\");\nMODULE_DESCRIPTION(\"LZMA uncompress. \"\n\t\t   \"A tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/kmod.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: kmod.mk,v 1.1 2007-11-05 05:43:35 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\nifndef KDir\n$(error KDir is not defined)\nendif\n\n#include makefile.gcc\n\nKmod = kmod\nEXTRA_CFLAGS += -Wall -Werror -I${CURDIR} -I${Sqlzma}\n# -D_LZMA_PROB32\nEXTRA_CFLAGS += $(shell ${CPP} ${CFLAGS} -P testflags.c)\n\nall: ${Kmod}/uncomp.c\n\t${MAKE} EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\" M=${CURDIR}/${Kmod} \\\n\t\t-C ${KDir} C=0 V=0 modules\n\n${Kmod}/uncomp.c: uncomp.c\n\tln $< $@\n\nclean: clean_kmod\nclean_kmod:\n\t${MAKE} -C ${KDir} M=${CURDIR}/${Kmod} V=0 clean\n\t${RM} ${Kmod}/*~\n\t-@test -e ${Kmod}/uncomp.c && \\\n\t\tdiff -q ${Kmod}/uncomp.c uncomp.c > /dev/null && \\\n\t\tfind ${Kmod}/uncomp.c -links +1 | xargs -r ${RM}\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. KDir=/lib/modules/`uname -r`/build -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/sqlzma.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\n#include makefile.gcc\nCFLAGS = -c -O2 -Wall -pedantic -D _LZMA_PROB32\n\nifdef KDir\ninclude kmod.mk\nendif\n\nifdef UseDebugFlags\nDebugFlags = -O0 -g -UNDEBUG\nendif\nCFLAGS += -DNDEBUG ${DebugFlags}\nTgt = libunlzma.a libunlzma_r.a\n\nall: ${Tgt}\n\n%_r.c: %.c\n\tln $< $@\n# -pthread\n%_r.o: CFLAGS += -D_REENTRANT -include pthread.h\n\nuncomp.o uncomp_r.o: CFLAGS += -I${Sqlzma}\nuncomp.o: uncomp.c ${Sqlzma}/sqlzma.h\n\nlibunlzma.a: uncomp.o LzmaDecode.o\n\t${AR} cr $@ $^\nlibunlzma_r.a: uncomp_r.o LzmaDecode_r.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) ${Tgt} uncomp.o uncomp_r.o LzmaDecode_r.o LzmaDecode.o  *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/testflags.c",
    "content": "#ifdef _LZMA_PROB32\n-D_LZMA_PROB32\n#else\n-U_LZMA_PROB32\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Compress/Lzma/uncomp.c",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $ */\n\n/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */\n\n#ifndef __KERNEL__\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <assert.h>\n#include <pthread.h>\n#define unlikely(x)\t\t__builtin_expect(!!(x), 0)\n#define BUG_ON(x)\t\tassert(!(x))\n/* sqlzma buffers are always larger than a page. true? */\n#define kmalloc(sz,gfp)\t\tmalloc(sz)\n#define kfree(p)\t\tfree(p)\n#define zlib_inflate(s, f)\tinflate(s, f)\n#define zlib_inflateInit(s)\tinflateInit(s)\n#define zlib_inflateReset(s)\tinflateReset(s)\n#define zlib_inflateEnd(s)\tinflateEnd(s)\n#else\n#include <linux/init.h>\n#include <linux/module.h>\n#include <linux/kernel.h>\n#include <linux/vmalloc.h>\n#ifndef WARN_ON_ONCE\n#define WARN_ON_ONCE(b)\tWARN_ON(b)\n#endif\n#endif /* __KERNEL__ */\n\n#include \"sqlzma.h\"\n#include \"LzmaDecode.h\"\n\nstatic int LzmaUncompress(struct sqlzma_un *un)\n{\n\tint err, i, ret;\n\tSizeT outSize, inProcessed, outProcessed, srclen;\n\t/* it's about 24-80 bytes structure, if int is 32-bit */\n\tCLzmaDecoderState state;\n\tunsigned char *dst, *src, a[8];\n\tstruct sized_buf *sbuf;\n\n\t/* Decode LZMA properties and allocate memory */\n\terr = -EINVAL;\n\tsrc = (void *)un->un_cmbuf;\n\tret = LzmaDecodeProperties(&state.Properties, src,\n\t\t\t\t   LZMA_PROPERTIES_SIZE);\n\tsrc += LZMA_PROPERTIES_SIZE;\n\tif (unlikely(ret != LZMA_RESULT_OK))\n\t\tgoto out;\n\ti = LzmaGetNumProbs(&state.Properties);\n\tif (unlikely(i <= 0))\n\t\ti = 1;\n\ti *= sizeof(CProb);\n\tsbuf = un->un_a + SQUN_PROB;\n\tif (unlikely(sbuf->sz < i)) {\n\t\tif (sbuf->buf && sbuf->buf != un->un_prob)\n\t\t\tkfree(sbuf->buf);\n#ifdef __KERNEL__\n\t\tprintk(\"%s:%d: %d --> %d\\n\", __func__, __LINE__, sbuf->sz, i);\n#else\n\t\tprintf(\"%d --> %d\\n\", sbuf->sz, i);\n#endif\n\t\terr = -ENOMEM;\n\t\tsbuf->sz = 0;\n\t\tsbuf->buf = kmalloc(i, GFP_ATOMIC);\n\t\tif (unlikely(!sbuf->buf))\n\t\t\tgoto out;\n\t\tsbuf->sz = i;\n\t}\n\tstate.Probs = (void *)sbuf->buf;\n\n\t/* Read uncompressed size */\n\tmemcpy(a, src, sizeof(a));\n\tsrc += sizeof(a);\n\toutSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);\n\n\terr = -EINVAL;\n\tdst = un->un_resbuf;\n\tif (unlikely(!dst || outSize > un->un_reslen))\n\t\tgoto out;\n\tun->un_reslen = outSize;\n\tsrclen = un->un_cmlen - (src - un->un_cmbuf);\n\n\t/* Decompress */\n\terr = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,\n\t\t\t &outProcessed);\n\tif (unlikely(err))\n\t\terr = -EINVAL;\n\n out:\n#ifndef __KERNEL__\n\tif (err)\n\t\tfprintf(stderr, \"err %d\\n\", err);\n#endif\n\treturn err;\n}\n\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst)\n{\n\tint err, by_lzma = 1;\n\tif (un->un_lzma && is_lzma(*src->buf)) {\n\t\tun->un_cmbuf = src->buf;\n\t\tun->un_cmlen = src->sz;\n\t\tun->un_resbuf = dst->buf;\n\t\tun->un_reslen = dst->sz;\n\n\t\t/* this library is thread-safe */\n\t\terr = LzmaUncompress(un);\n\t\tgoto out;\n\t}\n\n\tby_lzma = 0;\n\terr = zlib_inflateReset(&un->un_stream);\n\tif (unlikely(err != Z_OK))\n\t\tgoto out;\n\tun->un_stream.next_in = src->buf;\n\tun->un_stream.avail_in = src->sz;\n\tun->un_stream.next_out = dst->buf;\n\tun->un_stream.avail_out = dst->sz;\n\terr = zlib_inflate(&un->un_stream, Z_FINISH);\n\tif (err == Z_STREAM_END)\n\t\terr = 0;\n\n out:\n\tif (unlikely(err)) {\n#ifdef __KERNEL__\n\t\tWARN_ON_ONCE(1);\n#else\n\t\tchar a[64] = \"ZLIB \";\n\t\tif (by_lzma) {\n\t\t\tstrcpy(a, \"LZMA \");\n#ifdef _REENTRANT\n\t\t\tstrerror_r(err, a + 5, sizeof(a) - 5);\n#else\n\t\t\tstrncat(a, strerror(err), sizeof(a) - 5);\n#endif\n\t\t} else\n\t\t\tstrncat(a, zError(err), sizeof(a) - 5);\n\t\tfprintf(stderr, \"%s: %.*s\\n\", __func__, sizeof(a), a);\n#endif\n\t}\n\treturn err;\n}\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)\n{\n\tint err;\n\n\terr = -ENOMEM;\n\tun->un_lzma = do_lzma;\n\tmemset(un->un_a, 0, sizeof(un->un_a));\n\tun->un_a[SQUN_PROB].buf = un->un_prob;\n\tun->un_a[SQUN_PROB].sz = sizeof(un->un_prob);\n\tif (res_sz) {\n\t\tun->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);\n\t\tif (unlikely(!un->un_a[SQUN_RESULT].buf))\n\t\t\treturn err;\n\t\tun->un_a[SQUN_RESULT].sz = res_sz;\n\t}\n\n\tun->un_stream.next_in = NULL;\n\tun->un_stream.avail_in = 0;\n#ifdef __KERNEL__\n\tun->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(),\n\t\t\t\t\t  GFP_KERNEL);\n\tif (unlikely(!un->un_stream.workspace))\n\t\treturn err;\n#else\n\tun->un_stream.opaque = NULL;\n\tun->un_stream.zalloc = Z_NULL;\n\tun->un_stream.zfree = Z_NULL;\n#endif\n\terr = zlib_inflateInit(&un->un_stream);\n\tif (unlikely(err == Z_MEM_ERROR))\n\t\treturn -ENOMEM;\n\tBUG_ON(err);\n\treturn err;\n}\n\nvoid sqlzma_fin(struct sqlzma_un *un)\n{\n\tint i;\n\tfor (i = 0; i < SQUN_LAST; i++)\n\t\tif (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)\n\t\t\tkfree(un->un_a[i].buf);\n\tBUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);\n}\n\n#ifdef __KERNEL__\nEXPORT_SYMBOL(sqlzma_un);\nEXPORT_SYMBOL(sqlzma_init);\nEXPORT_SYMBOL(sqlzma_fin);\n\n#if 0\nstatic int __init sqlzma_init(void)\n{\n\treturn 0;\n}\n\nstatic void __exit sqlzma_exit(void)\n{\n}\n\nmodule_init(sqlzma_init);\nmodule_exit(sqlzma_exit);\n#endif\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Junjiro Okajima <sfjro at users dot sf dot net>\");\nMODULE_VERSION(\"$Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $\");\nMODULE_DESCRIPTION(\"LZMA uncompress for squashfs. \"\n\t\t   \"Some functions for squashfs to support LZMA and \"\n\t\t   \"a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/CpuArch.h",
    "content": "/* CpuArch.h */\r\n\r\n#ifndef __CPUARCH_H\r\n#define __CPUARCH_H\r\n\r\n/* \r\nLITTLE_ENDIAN_UNALIGN means:\r\n  1) CPU is LITTLE_ENDIAN\r\n  2) it's allowed to make unaligned memory accesses\r\nif LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know \r\nabout these properties of platform.\r\n*/\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/IStream.h",
    "content": "/* IStream.h */\r\n\r\n#ifndef __C_ISTREAM_H\r\n#define __C_ISTREAM_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _ISeqInStream\r\n{\r\n  HRes (*Read)(void *object, void *data, UInt32 size, UInt32 *processedSize);\r\n} ISeqInStream;\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Sort.c",
    "content": "/* Sort.c */\r\n\r\n#include \"Sort.h\"\r\n\r\n#define HeapSortDown(p, k, size, temp) \\\r\n  { for (;;) { \\\r\n    UInt32 s = (k << 1); \\\r\n    if (s > size) break; \\\r\n    if (s < size && p[s + 1] > p[s]) s++; \\\r\n    if (temp >= p[s]) break; \\\r\n    p[k] = p[s]; k = s; \\\r\n  } p[k] = temp; }\r\n\r\nvoid HeapSort(UInt32 *p, UInt32 size)\r\n{\r\n  if (size <= 1)\r\n    return;\r\n  p--;\r\n  {\r\n    UInt32 i = size / 2;\r\n    do\r\n    {\r\n      UInt32 temp = p[i];\r\n      UInt32 k = i;\r\n      HeapSortDown(p, k, size, temp)\r\n    }\r\n    while(--i != 0);\r\n  }\r\n  /*\r\n  do\r\n  {\r\n    UInt32 k = 1;\r\n    UInt32 temp = p[size];\r\n    p[size--] = p[1];\r\n    HeapSortDown(p, k, size, temp)\r\n  }\r\n  while (size > 1);\r\n  */\r\n  while (size > 3)\r\n  {\r\n    UInt32 temp = p[size];\r\n    UInt32 k = (p[3] > p[2]) ? 3 : 2;\r\n    p[size--] = p[1];\r\n    p[1] = p[k]; \r\n    HeapSortDown(p, k, size, temp)\r\n  }\r\n  {\r\n    UInt32 temp = p[size];\r\n    p[size] = p[1];\r\n    if (size > 2 && p[2] < temp)\r\n    {\r\n      p[1] = p[2];\r\n      p[2] = temp;\r\n    }\r\n    else\r\n      p[1] = temp;\r\n  }\r\n}\r\n\r\n/*\r\n#define HeapSortRefDown(p, vals, n, size, temp) \\\r\n  { UInt32 k = n; UInt32 val = vals[temp]; for (;;) { \\\r\n    UInt32 s = (k << 1); \\\r\n    if (s > size) break; \\\r\n    if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \\\r\n    if (val >= vals[p[s]]) break; \\\r\n    p[k] = p[s]; k = s; \\\r\n  } p[k] = temp; }\r\n\r\nvoid HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size)\r\n{\r\n  if (size <= 1)\r\n    return;\r\n  p--;\r\n  {\r\n    UInt32 i = size / 2;\r\n    do\r\n    {\r\n      UInt32 temp = p[i];\r\n      HeapSortRefDown(p, vals, i, size, temp);\r\n    }\r\n    while(--i != 0);\r\n  }\r\n  do\r\n  {\r\n    UInt32 temp = p[size];\r\n    p[size--] = p[1];\r\n    HeapSortRefDown(p, vals, 1, size, temp);\r\n  }\r\n  while (size > 1);\r\n}\r\n*/"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Sort.h",
    "content": "/* Sort.h */\r\n\r\n#ifndef __7Z_Sort_H\r\n#define __7Z_Sort_H\r\n\r\n#include \"Types.h\"\r\n\r\nvoid HeapSort(UInt32 *p, UInt32 size);\r\n/* void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size); */\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Threads.c",
    "content": "/* Threads.c */\r\n\r\n#include \"Threads.h\"\r\n#include <process.h>\r\n\r\nHRes GetError()\r\n{\r\n  DWORD res = GetLastError();\r\n  return (res) ? (HRes)(res) : SZE_FAIL;\r\n}\r\n\r\nHRes BoolToHRes(int v) { return v ? SZ_OK : GetError(); }\r\nHRes BOOLToHRes(BOOL v) { return v ? SZ_OK : GetError(); }\r\n\r\nHRes MyCloseHandle(HANDLE *h)\r\n{\r\n  if (*h != NULL)\r\n    if (!CloseHandle(*h))\r\n      return GetError();\r\n  *h = NULL;\r\n  return SZ_OK;\r\n}\r\n\r\nHRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n{ \r\n  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r\n  thread->handle = \r\n    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */\r\n    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);\r\n    /* maybe we must use errno here, but probably GetLastError() is also OK. */\r\n  return BoolToHRes(thread->handle != 0);\r\n}\r\n\r\nHRes WaitObject(HANDLE h)\r\n{\r\n  return (HRes)WaitForSingleObject(h, INFINITE); \r\n}\r\n\r\nHRes Thread_Wait(CThread *thread)\r\n{\r\n  if (thread->handle == NULL)\r\n    return 1;\r\n  return WaitObject(thread->handle); \r\n}\r\n\r\nHRes Thread_Close(CThread *thread)\r\n{\r\n  return MyCloseHandle(&thread->handle);\r\n}\r\n\r\nHRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)\r\n{\r\n  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);\r\n  return BoolToHRes(p->handle != 0);\r\n}\r\n\r\nHRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, TRUE, initialSignaled); }\r\nHRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) \r\n  { return ManualResetEvent_Create(p, 0); }\r\n\r\nHRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, FALSE, initialSignaled); }\r\nHRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) \r\n  { return AutoResetEvent_Create(p, 0); }\r\n\r\nHRes Event_Set(CEvent *p) { return BOOLToHRes(SetEvent(p->handle)); }\r\nHRes Event_Reset(CEvent *p) { return BOOLToHRes(ResetEvent(p->handle)); }\r\nHRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }\r\nHRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }\r\n\r\n\r\nHRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)\r\n{\r\n  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);\r\n  return BoolToHRes(p->handle != 0);\r\n}\r\n\r\nHRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) \r\n{ \r\n  return BOOLToHRes(ReleaseSemaphore(p->handle, releaseCount, previousCount)); \r\n}\r\nHRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)\r\n{\r\n  return Semaphore_Release(p, (LONG)releaseCount, NULL);\r\n}\r\nHRes Semaphore_Release1(CSemaphore *p)\r\n{\r\n  return Semaphore_ReleaseN(p, 1);\r\n}\r\n\r\nHRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }\r\nHRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }\r\n\r\nHRes CriticalSection_Init(CCriticalSection *p)\r\n{\r\n  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\r\n  __try \r\n  { \r\n    InitializeCriticalSection(p); \r\n    /* InitializeCriticalSectionAndSpinCount(p, 0); */\r\n  }  \r\n  __except (EXCEPTION_EXECUTE_HANDLER) { return SZE_OUTOFMEMORY; }\r\n  return SZ_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Threads.h",
    "content": "/* Threads.h */\r\n\r\n#ifndef __7Z_THRESDS_H\r\n#define __7Z_THRESDS_H\r\n\r\n#include <windows.h>\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _CThread\r\n{\r\n  HANDLE handle;\r\n} CThread;\r\n\r\n#define Thread_Construct(thread) (thread)->handle = NULL\r\n#define Thread_WasCreated(thread) ((thread)->handle != NULL)\r\n \r\ntypedef unsigned THREAD_FUNC_RET_TYPE;\r\n#define THREAD_FUNC_CALL_TYPE StdCall\r\n#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r\n\r\nHRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);\r\nHRes Thread_Wait(CThread *thread);\r\nHRes Thread_Close(CThread *thread);\r\n\r\ntypedef struct _CEvent\r\n{\r\n  HANDLE handle;\r\n} CEvent;\r\n\r\ntypedef CEvent CAutoResetEvent;\r\ntypedef CEvent CManualResetEvent;\r\n\r\n#define Event_Construct(event) (event)->handle = NULL\r\n#define Event_IsCreated(event) ((event)->handle != NULL)\r\n\r\nHRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);\r\nHRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);\r\nHRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);\r\nHRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);\r\nHRes Event_Set(CEvent *event);\r\nHRes Event_Reset(CEvent *event);\r\nHRes Event_Wait(CEvent *event);\r\nHRes Event_Close(CEvent *event);\r\n\r\n\r\ntypedef struct _CSemaphore\r\n{\r\n  HANDLE handle;\r\n} CSemaphore;\r\n\r\n#define Semaphore_Construct(p) (p)->handle = NULL\r\n\r\nHRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);\r\nHRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\r\nHRes Semaphore_Release1(CSemaphore *p);\r\nHRes Semaphore_Wait(CSemaphore *p);\r\nHRes Semaphore_Close(CSemaphore *p);\r\n\r\n\r\ntypedef CRITICAL_SECTION CCriticalSection;\r\n\r\nHRes CriticalSection_Init(CCriticalSection *p);\r\n#define CriticalSection_Delete(p) DeleteCriticalSection(p)\r\n#define CriticalSection_Enter(p) EnterCriticalSection(p)\r\n#define CriticalSection_Leave(p) LeaveCriticalSection(p)\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/C/Types.h",
    "content": "/* 7zTypes.h */\r\n\r\n#ifndef __C_TYPES_H\r\n#define __C_TYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif \r\n\r\n#ifndef _7ZIP_INT32_DEFINED\r\n#define _7ZIP_INT32_DEFINED\r\n#ifdef _LZMA_INT32_IS_ULONG\r\ntypedef long Int32;\r\n#else\r\ntypedef int Int32;\r\n#endif\r\n#endif \r\n\r\n/* #define _SZ_NO_INT_64 */\r\n/* define it your compiler doesn't support long long int */\r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\n#ifdef _SZ_NO_INT_64\r\ntypedef unsigned long UInt64;\r\n#else\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n#endif\r\n#endif\r\n\r\n\r\n/* #define _SZ_FILE_SIZE_32 */\r\n/* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/\r\n\r\n#ifndef CFileSize\r\n#ifdef _SZ_FILE_SIZE_32\r\ntypedef UInt32 CFileSize; \r\n#else\r\ntypedef UInt64 CFileSize; \r\n#endif\r\n#endif\r\n\r\n#define SZ_RESULT int\r\n\r\ntypedef int HRes;\r\n#define RES_OK (0)\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_CRC_ERROR (3)\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n#define SZE_OUTOFMEMORY (0x8007000EL)\r\n#define SZE_NOTIMPL (0x80004001L)\r\n#define SZE_FAIL (0x80004005L)\r\n#define SZE_INVALIDARG (0x80070057L)\r\n\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRes __result_ = (x); if(__result_ != 0) return __result_; }\r\n#endif\r\n\r\ntypedef int Bool;\r\n#define True 1\r\n#define False 0\r\n\r\n#ifdef _MSC_VER\r\n#define StdCall __stdcall \r\n#else\r\n#define StdCall\r\n#endif\r\n\r\n#if _MSC_VER >= 1300\r\n#define MY_FAST_CALL __declspec(noinline) __fastcall \r\n#elif defined( _MSC_VER)\r\n#define MY_FAST_CALL __fastcall \r\n#else\r\n#define MY_FAST_CALL\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zCompressionMode.cpp",
    "content": "// CompressionMethod.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zCompressionMode.h",
    "content": "// 7zCompressionMode.h\r\n\r\n#ifndef __7Z_COMPRESSION_MODE_H\r\n#define __7Z_COMPRESSION_MODE_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CMethodFull: public CMethod\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBind\r\n{\r\n  UInt32 InCoder;\r\n  UInt32 InStream;\r\n  UInt32 OutCoder;\r\n  UInt32 OutStream;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  CObjectVector<CMethodFull> Methods;\r\n  CRecordVector<CBind> Binds;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }\r\n  CCompressionMethodMode(): PasswordIsDefined(false)\r\n      #ifdef COMPRESS_MT\r\n      , NumThreads(1) \r\n      #endif\r\n  {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zDecode.cpp",
    "content": "// 7zDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zDecode.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/LockedStream.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertFolderItemInfoToBindInfo(const CFolder &folder,\r\n    CBindInfoEx &bindInfo)\r\n{\r\n  bindInfo.Clear();\r\n  int i;\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    NCoderMixer::CBindPair bindPair;\r\n    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;\r\n    bindInfo.BindPairs.Add(bindPair);\r\n  }\r\n  UInt32 outStreamIndex = 0;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    const CCoderInfo &coderInfo = folder.Coders[i];\r\n    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;\r\n    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    bindInfo.Coders.Add(coderStreamsInfo);\r\n    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);\r\n    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)\r\n      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)\r\n        bindInfo.OutStreams.Add(outStreamIndex);\r\n  }\r\n  for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);\r\n}\r\n\r\nstatic bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1, \r\n    const NCoderMixer::CCoderStreamsInfo &a2)\r\n{\r\n  return (a1.NumInStreams == a2.NumInStreams) &&\r\n    (a1.NumOutStreams == a2.NumOutStreams);\r\n}\r\n\r\nstatic bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)\r\n{\r\n  return (a1.InIndex == a2.InIndex) &&\r\n    (a1.OutIndex == a2.OutIndex);\r\n}\r\n\r\nstatic bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)\r\n{\r\n  if (a1.Coders.Size() != a2.Coders.Size())\r\n    return false;\r\n  int i;\r\n  for (i = 0; i < a1.Coders.Size(); i++)\r\n    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))\r\n      return false;\r\n  if (a1.BindPairs.Size() != a2.BindPairs.Size())\r\n    return false;\r\n  for (i = 0; i < a1.BindPairs.Size(); i++)\r\n    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))\r\n      return false;\r\n  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)\r\n    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])\r\n      return false;\r\n  if (a1.InStreams.Size() != a2.InStreams.Size())\r\n    return false;\r\n  if (a1.OutStreams.Size() != a2.OutStreams.Size())\r\n    return false;\r\n  return true;\r\n}\r\n\r\nCDecoder::CDecoder(bool multiThread)\r\n{\r\n  #ifndef _ST_MODE\r\n  multiThread = true;\r\n  #endif\r\n  _multiThread = multiThread;\r\n  _bindInfoExPrevIsDefined = false;\r\n}\r\n\r\nHRESULT CDecoder::Decode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    UInt64 startPos,\r\n    const UInt64 *packSizes,\r\n    const CFolder &folderInfo, \r\n    ISequentialOutStream *outStream,\r\n    ICompressProgressInfo *compressProgress\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    #ifdef COMPRESS_MT\r\n    , bool mtMode, UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;\r\n  \r\n  CLockedInStream lockedInStream;\r\n  lockedInStream.Init(inStream);\r\n  \r\n  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)\r\n  {\r\n    CLockedSequentialInStreamImp *lockedStreamImpSpec = new \r\n        CLockedSequentialInStreamImp;\r\n    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;\r\n    lockedStreamImpSpec->Init(&lockedInStream, startPos);\r\n    startPos += packSizes[j];\r\n    \r\n    CLimitedSequentialInStream *streamSpec = new \r\n        CLimitedSequentialInStream;\r\n    CMyComPtr<ISequentialInStream> inStream = streamSpec;\r\n    streamSpec->SetStream(lockedStreamImp);\r\n    streamSpec->Init(packSizes[j]);\r\n    inStreams.Add(inStream);\r\n  }\r\n  \r\n  int numCoders = folderInfo.Coders.Size();\r\n  \r\n  CBindInfoEx bindInfo;\r\n  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);\r\n  bool createNewCoders;\r\n  if (!_bindInfoExPrevIsDefined)\r\n    createNewCoders = true;\r\n  else\r\n    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);\r\n  if (createNewCoders)\r\n  {\r\n    int i;\r\n    _decoders.Clear();\r\n    // _decoders2.Clear();\r\n    \r\n    _mixerCoder.Release();\r\n\r\n    if (_multiThread)\r\n    {\r\n      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;\r\n      _mixerCoder = _mixerCoderMTSpec;\r\n      _mixerCoderCommon = _mixerCoderMTSpec;\r\n    }\r\n    else\r\n    {\r\n      #ifdef _ST_MODE\r\n      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;\r\n      _mixerCoder = _mixerCoderSTSpec;\r\n      _mixerCoderCommon = _mixerCoderSTSpec;\r\n      #endif\r\n    }\r\n    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));\r\n    \r\n    for (i = 0; i < numCoders; i++)\r\n    {\r\n      const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n\r\n  \r\n      CMyComPtr<ICompressCoder> decoder;\r\n      CMyComPtr<ICompressCoder2> decoder2;\r\n      RINOK(CreateCoder(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          coderInfo.MethodID, decoder, decoder2, false));\r\n      CMyComPtr<IUnknown> decoderUnknown;\r\n      if (coderInfo.IsSimpleCoder())\r\n      {\r\n        if (decoder == 0)\r\n          return E_NOTIMPL;\r\n\r\n        decoderUnknown = (IUnknown *)decoder;\r\n        \r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder(decoder);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder(decoder, false);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        if (decoder2 == 0)\r\n          return E_NOTIMPL;\r\n        decoderUnknown = (IUnknown *)decoder2;\r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder2(decoder2);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder2(decoder2, false);\r\n        #endif\r\n      }\r\n      _decoders.Add(decoderUnknown);\r\n      #ifdef EXTERNAL_CODECS\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n      }\r\n      #endif\r\n    }\r\n    _bindInfoExPrev = bindInfo;\r\n    _bindInfoExPrevIsDefined = true;\r\n  }\r\n  int i;\r\n  _mixerCoderCommon->ReInit();\r\n  \r\n  UInt32 packStreamIndex = 0, unPackStreamIndex = 0;\r\n  UInt32 coderIndex = 0;\r\n  // UInt32 coder2Index = 0;\r\n  \r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];\r\n    \r\n    {\r\n      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n      if (setDecoderProperties)\r\n      {\r\n        const CByteBuffer &properties = coderInfo.Properties;\r\n        size_t size = properties.GetCapacity();\r\n        if (size > 0xFFFFFFFF)\r\n          return E_NOTIMPL;\r\n        if (size > 0)\r\n        {\r\n          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)properties, (UInt32)size));\r\n        }\r\n      }\r\n    }\r\n\r\n    #ifdef COMPRESS_MT\r\n    if (mtMode)\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(numThreads));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    {\r\n      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n      if (cryptoSetPassword)\r\n      {\r\n        if (getTextPassword == 0)\r\n          return E_FAIL;\r\n        CMyComBSTR password;\r\n        RINOK(getTextPassword->CryptoGetTextPassword(&password));\r\n        CByteBuffer buffer;\r\n        UString unicodePassword(password);\r\n        const UInt32 sizeInBytes = unicodePassword.Length() * 2;\r\n        buffer.SetCapacity(sizeInBytes);\r\n        for (int i = 0; i < unicodePassword.Length(); i++)\r\n        {\r\n          wchar_t c = unicodePassword[i];\r\n          ((Byte *)buffer)[i * 2] = (Byte)c;\r\n          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n        }\r\n        RINOK(cryptoSetPassword->CryptoSetPassword(\r\n          (const Byte *)buffer, sizeInBytes));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    coderIndex++;\r\n    \r\n    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;\r\n    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    CRecordVector<const UInt64 *> packSizesPointers;\r\n    CRecordVector<const UInt64 *> unPackSizesPointers;\r\n    packSizesPointers.Reserve(numInStreams);\r\n    unPackSizesPointers.Reserve(numOutStreams);\r\n    UInt32 j;\r\n    for (j = 0; j < numOutStreams; j++, unPackStreamIndex++)\r\n      unPackSizesPointers.Add(&folderInfo.UnPackSizes[unPackStreamIndex]);\r\n    \r\n    for (j = 0; j < numInStreams; j++, packStreamIndex++)\r\n    {\r\n      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);\r\n      if (bindPairIndex >= 0)\r\n        packSizesPointers.Add(\r\n        &folderInfo.UnPackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);\r\n      else\r\n      {\r\n        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);\r\n        if (index < 0)\r\n          return E_FAIL;\r\n        packSizesPointers.Add(&packSizes[index]);\r\n      }\r\n    }\r\n    \r\n    _mixerCoderCommon->SetCoderInfo(i, \r\n        &packSizesPointers.Front(), \r\n        &unPackSizesPointers.Front());\r\n  }\r\n  UInt32 mainCoder, temp;\r\n  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);\r\n\r\n  if (_multiThread)\r\n    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);\r\n  /*\r\n  else\r\n    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;\r\n  */\r\n  \r\n  if (numCoders == 0)\r\n    return 0;\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  inStreamPointers.Reserve(inStreams.Size());\r\n  for (i = 0; i < inStreams.Size(); i++)\r\n    inStreamPointers.Add(inStreams[i]);\r\n  ISequentialOutStream *outStreamPointer = outStream;\r\n  return _mixerCoder->Code(&inStreamPointers.Front(), NULL, \r\n    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zDecode.h",
    "content": "// 7zDecode.h\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"7zItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CBindInfoEx: public NCoderMixer::CBindInfo\r\n{\r\n  CRecordVector<CMethodId> CoderMethodIDs;\r\n  void Clear()\r\n  {\r\n    CBindInfo::Clear();\r\n    CoderMethodIDs.Clear();\r\n  }\r\n};\r\n\r\nclass CDecoder\r\n{\r\n  bool _bindInfoExPrevIsDefined;\r\n  CBindInfoEx _bindInfoExPrev;\r\n  \r\n  bool _multiThread;\r\n  #ifdef _ST_MODE\r\n  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;\r\n  #endif\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;\r\n  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;\r\n  \r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n  CObjectVector<CMyComPtr<IUnknown> > _decoders;\r\n  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;\r\npublic:\r\n  CDecoder(bool multiThread);\r\n  HRESULT Decode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      IInStream *inStream,\r\n      UInt64 startPos,\r\n      const UInt64 *packSizes,\r\n      const CFolder &folder, \r\n      ISequentialOutStream *outStream,\r\n      ICompressProgressInfo *compressProgress\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPasswordSpec\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , bool mtMode, UInt32 numThreads\r\n      #endif\r\n      );\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zEncode.cpp",
    "content": "// Encode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zSpecStream.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/InOutTempBuffer.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nstatic const UInt64 k_AES = 0x06F10701;\r\nstatic const UInt64 k_BCJ  = 0x03030103;\r\nstatic const UInt64 k_BCJ2 = 0x0303011B;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,\r\n    const CRecordVector<CMethodId> decompressionMethods,\r\n    CFolder &folder)\r\n{\r\n  folder.Coders.Clear();\r\n  // bindInfo.CoderMethodIDs.Clear();\r\n  // folder.OutStreams.Clear();\r\n  folder.PackStreams.Clear();\r\n  folder.BindPairs.Clear();\r\n  int i;\r\n  for (i = 0; i < bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = bindInfo.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = bindInfo.BindPairs[i].OutIndex;\r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n  for (i = 0; i < bindInfo.Coders.Size(); i++)\r\n  {\r\n    CCoderInfo coderInfo;\r\n    const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];\r\n    coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;\r\n    coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;\r\n    coderInfo.MethodID = decompressionMethods[i];\r\n    folder.Coders.Add(coderInfo);\r\n  }\r\n  for (i = 0; i < bindInfo.InStreams.Size(); i++)\r\n    folder.PackStreams.Add(bindInfo.InStreams[i]);\r\n}\r\n\r\nHRESULT CEncoder::CreateMixerCoder(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const UInt64 *inSizeForReduce)\r\n{\r\n  _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;\r\n  _mixerCoder = _mixerCoderSpec;\r\n  RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));\r\n  for (int i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _codersInfo.Add(CCoderInfo());\r\n    CCoderInfo &encodingInfo = _codersInfo.Back();\r\n    encodingInfo.MethodID = methodFull.Id;\r\n    CMyComPtr<ICompressCoder> encoder;\r\n    CMyComPtr<ICompressCoder2> encoder2;\r\n    \r\n\r\n    RINOK(CreateCoder(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        methodFull.Id, encoder, encoder2, true));\r\n\r\n    if (!encoder && !encoder2)\r\n      return E_FAIL;\r\n\r\n    CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;\r\n   \r\n    #ifdef COMPRESS_MT\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));\r\n      }\r\n    }\r\n    #endif\r\n        \r\n\r\n    RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon));\r\n\r\n    /*\r\n    CMyComPtr<ICryptoResetSalt> resetSalt;\r\n    encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);\r\n    if (resetSalt != NULL)\r\n    {\r\n      resetSalt->ResetSalt();\r\n    }\r\n    */\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n    encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n    if (setCompressCodecsInfo)\r\n    {\r\n      RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n    }\r\n    #endif\r\n    \r\n    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n    encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n\r\n    if (cryptoSetPassword)\r\n    {\r\n      CByteBuffer buffer;\r\n      const UInt32 sizeInBytes = _options.Password.Length() * 2;\r\n      buffer.SetCapacity(sizeInBytes);\r\n      for (int i = 0; i < _options.Password.Length(); i++)\r\n      {\r\n        wchar_t c = _options.Password[i];\r\n        ((Byte *)buffer)[i * 2] = (Byte)c;\r\n        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n      }\r\n      RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n    }\r\n\r\n    if (encoder)\r\n      _mixerCoderSpec->AddCoder(encoder);\r\n    else\r\n      _mixerCoderSpec->AddCoder2(encoder2);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Encode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    ISequentialInStream *inStream,\r\n    const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n    CFolder &folderItem,\r\n    ISequentialOutStream *outStream,\r\n    CRecordVector<UInt64> &packSizes,\r\n    ICompressProgressInfo *compressProgress)\r\n{\r\n  RINOK(EncoderConstr());\r\n\r\n  if (_mixerCoderSpec == NULL)\r\n  {\r\n    RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));\r\n  }\r\n  _mixerCoderSpec->ReInit();\r\n  // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);\r\n\r\n  CObjectVector<CInOutTempBuffer> inOutTempBuffers;\r\n  CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;\r\n  CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;\r\n  int numMethods = _bindInfo.Coders.Size();\r\n  int i;\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    inOutTempBuffers.Add(CInOutTempBuffer());\r\n    inOutTempBuffers.Back().Create();\r\n    inOutTempBuffers.Back().InitWriting();\r\n  }\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CSequentialOutTempBufferImp *tempBufferSpec = \r\n        new CSequentialOutTempBufferImp;\r\n    CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;\r\n    tempBufferSpec->Init(&inOutTempBuffers[i - 1]);\r\n    tempBuffers.Add(tempBuffer);\r\n    tempBufferSpecs.Add(tempBufferSpec);\r\n  }\r\n\r\n  for (i = 0; i < numMethods; i++)\r\n    _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    return E_FAIL;\r\n  UInt32 mainCoderIndex, mainStreamIndex;\r\n  _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);\r\n  \r\n  if (inStreamSize != NULL)\r\n  {\r\n    CRecordVector<const UInt64 *> sizePointers;\r\n    for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)\r\n      if (i == mainStreamIndex)\r\n        sizePointers.Add(inStreamSize);\r\n      else\r\n        sizePointers.Add(NULL);\r\n    _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);\r\n  }\r\n\r\n  \r\n  // UInt64 outStreamStartPos;\r\n  // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));\r\n  \r\n  CSequentialInStreamSizeCount2 *inStreamSizeCountSpec = \r\n      new CSequentialInStreamSizeCount2;\r\n  CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;\r\n  CSequentialOutStreamSizeCount *outStreamSizeCountSpec = \r\n      new CSequentialOutStreamSizeCount;\r\n  CMyComPtr<ISequentialOutStream> outStreamSizeCount = outStreamSizeCountSpec;\r\n\r\n  inStreamSizeCountSpec->Init(inStream);\r\n  outStreamSizeCountSpec->SetStream(outStream);\r\n  outStreamSizeCountSpec->Init();\r\n\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  CRecordVector<ISequentialOutStream *> outStreamPointers;\r\n  inStreamPointers.Add(inStreamSizeCount);\r\n  outStreamPointers.Add(outStreamSizeCount);\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n    outStreamPointers.Add(tempBuffers[i - 1]);\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    CCoderInfo &encodingInfo = _codersInfo[i];\r\n    \r\n    CMyComPtr<ICryptoResetInitVector> resetInitVector;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);\r\n    if (resetInitVector != NULL)\r\n    {\r\n      resetInitVector->ResetInitVector();\r\n    }\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n    if (writeCoderProperties != NULL)\r\n    {\r\n      CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n      outStreamSpec->Init();\r\n      writeCoderProperties->WriteCoderProperties(outStream);\r\n      size_t size = outStreamSpec->GetSize();\r\n      encodingInfo.Properties.SetCapacity(size);\r\n      memmove(encodingInfo.Properties, outStreamSpec->GetBuffer(), size);\r\n    }\r\n  }\r\n\r\n  UInt32 progressIndex = mainCoderIndex;\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    const CCoderInfo &e = _codersInfo[i];\r\n    if ((e.MethodID == k_BCJ || e.MethodID == k_BCJ2) && i + 1 < _codersInfo.Size())\r\n      progressIndex = i + 1;\r\n  }\r\n\r\n  _mixerCoderSpec->SetProgressCoderIndex(progressIndex);\r\n  \r\n  RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,\r\n    &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));\r\n  \r\n  ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods,\r\n      folderItem);\r\n  \r\n  packSizes.Add(outStreamSizeCountSpec->GetSize());\r\n  \r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];\r\n    inOutTempBuffer.FlushWrite();\r\n    inOutTempBuffer.InitReading();\r\n    inOutTempBuffer.WriteToStream(outStream);\r\n    packSizes.Add(inOutTempBuffer.GetDataSize());\r\n  }\r\n  \r\n  for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)\r\n  {\r\n    int binder = _bindInfo.FindBinderForInStream(\r\n        _bindReverseConverter->DestOutToSrcInMap[i]);\r\n    UInt64 streamSize;\r\n    if (binder < 0)\r\n      streamSize = inStreamSizeCountSpec->GetSize();\r\n    else\r\n      streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);\r\n    folderItem.UnPackSizes.Add(streamSize);\r\n  }\r\n  for (i = numMethods - 1; i >= 0; i--)\r\n    folderItem.Coders[numMethods - 1 - i].Properties = _codersInfo[i].Properties;\r\n  return S_OK;\r\n}\r\n\r\n\r\nCEncoder::CEncoder(const CCompressionMethodMode &options):\r\n  _bindReverseConverter(0),\r\n  _constructed(false)\r\n{\r\n  if (options.IsEmpty())\r\n    throw 1;\r\n\r\n  _options = options;\r\n  _mixerCoderSpec = NULL;\r\n}\r\n\r\nHRESULT CEncoder::EncoderConstr()\r\n{\r\n  if (_constructed)\r\n    return S_OK;\r\n  if (_options.Methods.IsEmpty())\r\n  {\r\n    // it has only password method;\r\n    if (!_options.PasswordIsDefined)\r\n      throw 1;\r\n    if (!_options.Binds.IsEmpty())\r\n      throw 1;\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    CMethodFull method;\r\n    \r\n    method.NumInStreams = 1;\r\n    method.NumOutStreams = 1;\r\n    coderStreamsInfo.NumInStreams = 1;\r\n    coderStreamsInfo.NumOutStreams = 1;\r\n    method.Id = k_AES;\r\n    \r\n    _options.Methods.Add(method);\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  \r\n    _bindInfo.InStreams.Add(0);\r\n    _bindInfo.OutStreams.Add(0);\r\n  }\r\n  else\r\n  {\r\n\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  int i;\r\n  for (i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;\r\n    coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;\r\n    if (_options.Binds.IsEmpty())\r\n    {\r\n      if (i < _options.Methods.Size() - 1)\r\n      {\r\n        NCoderMixer::CBindPair bindPair;\r\n        bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;\r\n        bindPair.OutIndex = numOutStreams;\r\n        _bindInfo.BindPairs.Add(bindPair);\r\n      }\r\n      else\r\n        _bindInfo.OutStreams.Insert(0, numOutStreams);\r\n      for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)\r\n        _bindInfo.OutStreams.Add(numOutStreams + j);\r\n    }\r\n    \r\n    numInStreams += coderStreamsInfo.NumInStreams;\r\n    numOutStreams += coderStreamsInfo.NumOutStreams;\r\n\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  }\r\n\r\n  if (!_options.Binds.IsEmpty())\r\n  {\r\n    for (i = 0; i < _options.Binds.Size(); i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      const CBind &bind = _options.Binds[i];\r\n      bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;\r\n      bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    for (i = 0; i < (int)numOutStreams; i++)\r\n      if (_bindInfo.FindBinderForOutStream(i) == -1)\r\n        _bindInfo.OutStreams.Add(i);\r\n  }\r\n\r\n  for (i = 0; i < (int)numInStreams; i++)\r\n    if (_bindInfo.FindBinderForInStream(i) == -1)\r\n      _bindInfo.InStreams.Add(i);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    throw 1; // this is error\r\n\r\n  // Make main stream first in list\r\n  int inIndex = _bindInfo.InStreams[0];\r\n  for (;;)\r\n  {\r\n    UInt32 coderIndex, coderStreamIndex;\r\n    _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);\r\n    UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);\r\n    int binder = _bindInfo.FindBinderForOutStream(outIndex);\r\n    if (binder >= 0)\r\n    {\r\n      inIndex = _bindInfo.BindPairs[binder].InIndex;\r\n      continue;\r\n    }\r\n    for (i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n      if (_bindInfo.OutStreams[i] == outIndex)\r\n      {\r\n        _bindInfo.OutStreams.Delete(i);\r\n        _bindInfo.OutStreams.Insert(0, outIndex);\r\n        break;\r\n      }\r\n    break;\r\n  }\r\n\r\n  if (_options.PasswordIsDefined)\r\n  {\r\n    int numCryptoStreams = _bindInfo.OutStreams.Size();\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      bindPair.InIndex = numInStreams + i;\r\n      bindPair.OutIndex = _bindInfo.OutStreams[i];\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    _bindInfo.OutStreams.Clear();\r\n\r\n    /*\r\n    if (numCryptoStreams == 0)\r\n      numCryptoStreams = 1;\r\n    */\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n      CMethodFull method;\r\n      method.NumInStreams = 1;\r\n      method.NumOutStreams = 1;\r\n      coderStreamsInfo.NumInStreams = method.NumOutStreams;\r\n      coderStreamsInfo.NumOutStreams = method.NumInStreams;\r\n      method.Id = k_AES;\r\n\r\n      _options.Methods.Add(method);\r\n      _bindInfo.Coders.Add(coderStreamsInfo);\r\n      _bindInfo.OutStreams.Add(numOutStreams + i);\r\n    }\r\n  }\r\n\r\n  }\r\n\r\n  for (int i = _options.Methods.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _decompressionMethods.Add(methodFull.Id);\r\n  }\r\n\r\n  _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);\r\n  _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);\r\n  _constructed = true;\r\n  return S_OK;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  delete _bindReverseConverter;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zEncode.h",
    "content": "// 7zEncode.h\r\n\r\n#ifndef __7Z_ENCODE_H\r\n#define __7Z_ENCODE_H\r\n\r\n// #include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n#include \"7zItem.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CEncoder\r\n{\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;\r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n\r\n  CObjectVector<CCoderInfo> _codersInfo;\r\n\r\n  CCompressionMethodMode _options;\r\n  NCoderMixer::CBindInfo _bindInfo;\r\n  NCoderMixer::CBindInfo _decompressBindInfo;\r\n  NCoderMixer::CBindReverseConverter *_bindReverseConverter;\r\n  CRecordVector<CMethodId> _decompressionMethods;\r\n\r\n  HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const UInt64 *inSizeForReduce);\r\n\r\n  bool _constructed;\r\npublic:\r\n  CEncoder(const CCompressionMethodMode &options);\r\n  ~CEncoder();\r\n  HRESULT EncoderConstr();\r\n  HRESULT Encode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      ISequentialInStream *inStream,\r\n      const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n      CFolder &folderItem,\r\n      ISequentialOutStream *outStream,\r\n      CRecordVector<UInt64> &packSizes,\r\n      ICompressProgressInfo *compressProgress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zExtract.cpp",
    "content": "// 7zExtract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zFolderOutStream.h\"\r\n#include \"7zDecode.h\"\r\n// #include \"7z1Decode.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CExtractFolderInfo\r\n{\r\n  #ifdef _7Z_VOL\r\n  int VolumeIndex;\r\n  #endif\r\n  CNum FileIndex;\r\n  CNum FolderIndex;\r\n  CBoolVector ExtractStatuses;\r\n  UInt64 UnPackSize;\r\n  CExtractFolderInfo(\r\n    #ifdef _7Z_VOL\r\n    int volumeIndex, \r\n    #endif\r\n    CNum fileIndex, CNum folderIndex): \r\n    #ifdef _7Z_VOL\r\n    VolumeIndex(volumeIndex),\r\n    #endif\r\n    FileIndex(fileIndex),\r\n    FolderIndex(folderIndex), \r\n    UnPackSize(0) \r\n  {\r\n    if (fileIndex != kNumNoIndex)\r\n    {\r\n      ExtractStatuses.Reserve(1);\r\n      ExtractStatuses.Add(true);\r\n    }\r\n  };\r\n};\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool testMode = (testModeSpec != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;\r\n  UInt64 importantTotalUnPacked = 0;\r\n\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (allFilesMode)\r\n    numItems = \r\n    #ifdef _7Z_VOL\r\n    _refs.Size();\r\n    #else\r\n    _database.Files.Size();\r\n    #endif\r\n\r\n  if(numItems == 0)\r\n    return S_OK;\r\n\r\n  /*\r\n  if(_volumes.Size() != 1)\r\n    return E_FAIL;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_database = volume.Database;\r\n  IInStream *_inStream = volume.Stream;\r\n  */\r\n  \r\n  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;\r\n  for(UInt32 ii = 0; ii < numItems; ii++)\r\n  {\r\n    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];\r\n    UInt32 ref2Index = allFilesMode ? ii : indices[ii];\r\n    // const CRef2 &ref2 = _refs[ref2Index];\r\n\r\n    // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)\r\n    {\r\n      #ifdef _7Z_VOL\r\n      // const CRef &ref = ref2.Refs[ri];\r\n      const CRef &ref = _refs[ref2Index];\r\n\r\n      int volumeIndex = ref.VolumeIndex;\r\n      const CVolume &volume = _volumes[volumeIndex];\r\n      const CArchiveDatabaseEx &database = volume.Database;\r\n      UInt32 fileIndex = ref.ItemIndex;\r\n      #else\r\n      const CArchiveDatabaseEx &database = _database;\r\n      UInt32 fileIndex = ref2Index;\r\n      #endif\r\n\r\n      CNum folderIndex = database.FileIndexToFolderIndexMap[fileIndex];\r\n      if (folderIndex == kNumNoIndex)\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex, \r\n            #endif\r\n            fileIndex, kNumNoIndex));\r\n        continue;\r\n      }\r\n      if (extractFolderInfoVector.IsEmpty() || \r\n        folderIndex != extractFolderInfoVector.Back().FolderIndex \r\n        #ifdef _7Z_VOL\r\n        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex\r\n        #endif\r\n        )\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex, \r\n            #endif\r\n            kNumNoIndex, folderIndex));\r\n        const CFolder &folderInfo = database.Folders[folderIndex];\r\n        UInt64 unPackSize = folderInfo.GetUnPackSize();\r\n        importantTotalUnPacked += unPackSize;\r\n        extractFolderInfoVector.Back().UnPackSize = unPackSize;\r\n      }\r\n      \r\n      CExtractFolderInfo &efi = extractFolderInfoVector.Back();\r\n      \r\n      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];\r\n      CNum startIndex = database.FolderStartFileIndex[folderIndex];\r\n      for (CNum index = efi.ExtractStatuses.Size();\r\n          index <= fileIndex - startIndex; index++)\r\n      {\r\n        // UInt64 unPackSize = _database.Files[startIndex + index].UnPackSize;\r\n        // Count partial_folder_size\r\n        // efi.UnPackSize += unPackSize;\r\n        // importantTotalUnPacked += unPackSize;\r\n        efi.ExtractStatuses.Add(index == fileIndex - startIndex);\r\n      }\r\n    }\r\n  }\r\n\r\n  extractCallback->SetTotal(importantTotalUnPacked);\r\n\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  // CDecoder1 decoder;\r\n\r\n  UInt64 currentTotalPacked = 0;\r\n  UInt64 currentTotalUnPacked = 0;\r\n  UInt64 totalFolderUnPacked;\r\n  UInt64 totalFolderPacked;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for(int i = 0; i < extractFolderInfoVector.Size(); i++, \r\n      currentTotalUnPacked += totalFolderUnPacked,\r\n      currentTotalPacked += totalFolderPacked)\r\n  {\r\n    lps->OutSize = currentTotalUnPacked;\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    const CExtractFolderInfo &efi = extractFolderInfoVector[i];\r\n    totalFolderUnPacked = efi.UnPackSize;\r\n\r\n    totalFolderPacked = 0;\r\n\r\n    CFolderOutStream *folderOutStream = new CFolderOutStream;\r\n    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);\r\n\r\n    #ifdef _7Z_VOL\r\n    const CVolume &volume = _volumes[efi.VolumeIndex];\r\n    const CArchiveDatabaseEx &database = volume.Database;\r\n    #else\r\n    const CArchiveDatabaseEx &database = _database;\r\n    #endif\r\n\r\n    CNum startIndex;\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      startIndex = efi.FileIndex;\r\n    else\r\n      startIndex = database.FolderStartFileIndex[efi.FolderIndex];\r\n\r\n\r\n    HRESULT result = folderOutStream->Init(&database, \r\n        #ifdef _7Z_VOL\r\n        volume.StartRef2Index, \r\n        #else\r\n        0,\r\n        #endif\r\n        startIndex, \r\n        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);\r\n\r\n    RINOK(result);\r\n\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      continue;\r\n\r\n    CNum folderIndex = efi.FolderIndex;\r\n    const CFolder &folderInfo = database.Folders[folderIndex];\r\n\r\n    totalFolderPacked = _database.GetFolderFullPackSize(folderIndex);\r\n\r\n    CNum packStreamIndex = database.FolderStartPackStreamIndex[folderIndex];\r\n    UInt64 folderStartPackPos = database.GetFolderStreamPos(folderIndex, 0);\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (extractCallback)\r\n      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    #endif\r\n\r\n    try\r\n    {\r\n      HRESULT result = decoder.Decode(\r\n          EXTERNAL_CODECS_VARS\r\n          #ifdef _7Z_VOL\r\n          volume.Stream,\r\n          #else\r\n          _inStream,\r\n          #endif\r\n          folderStartPackPos, \r\n          &database.PackSizes[packStreamIndex],\r\n          folderInfo,\r\n          outStream,\r\n          progress\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword\r\n          #endif\r\n          #ifdef COMPRESS_MT\r\n          , true, _numThreads\r\n          #endif\r\n          );\r\n\r\n      if (result == S_FALSE)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));\r\n        continue;\r\n      }\r\n      if (result != S_OK)\r\n        return result;\r\n      if (folderOutStream->WasWritingFinished() != S_OK)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n      continue;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zFolderInStream.cpp",
    "content": "// 7zFolderInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderInStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderInStream::CFolderInStream()\r\n{\r\n  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;\r\n  _inStreamWithHash = _inStreamWithHashSpec;\r\n}\r\n\r\nvoid CFolderInStream::Init(IArchiveUpdateCallback *updateCallback, \r\n    const UInt32 *fileIndices, UInt32 numFiles)\r\n{\r\n  _updateCallback = updateCallback;\r\n  _numFiles = numFiles;\r\n  _fileIndex = 0;\r\n  _fileIndices = fileIndices;\r\n  Processed.Clear();\r\n  CRCs.Clear();\r\n  Sizes.Clear();\r\n  _fileIsOpen = false;\r\n  _currentSizeIsDefined = false;\r\n}\r\n\r\nHRESULT CFolderInStream::OpenStream()\r\n{\r\n  _filePos = 0;\r\n  while (_fileIndex < _numFiles)\r\n  {\r\n    _currentSizeIsDefined = false;\r\n    CMyComPtr<ISequentialInStream> stream;\r\n    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);\r\n    if (result != S_OK && result != S_FALSE)\r\n      return result;\r\n    _fileIndex++;\r\n    _inStreamWithHashSpec->SetStream(stream);\r\n    _inStreamWithHashSpec->Init();\r\n    if (!stream)\r\n    {\r\n      RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n      Sizes.Add(0);\r\n      Processed.Add(result == S_OK);\r\n      AddDigest();\r\n      continue;\r\n    }\r\n    CMyComPtr<IStreamGetSize> streamGetSize;\r\n    if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)\r\n    {\r\n      if(streamGetSize)\r\n      {\r\n        _currentSizeIsDefined = true;\r\n        RINOK(streamGetSize->GetSize(&_currentSize));\r\n      }\r\n    }\r\n\r\n    _fileIsOpen = true;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFolderInStream::AddDigest()\r\n{\r\n  CRCs.Add(_inStreamWithHashSpec->GetCRC());\r\n}\r\n\r\nHRESULT CFolderInStream::CloseStream()\r\n{\r\n  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n  _inStreamWithHashSpec->ReleaseStream();\r\n  _fileIsOpen = false;\r\n  Processed.Add(true);\r\n  Sizes.Add(_filePos);\r\n  AddDigest();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 localProcessedSize;\r\n      RINOK(_inStreamWithHash->Read(\r\n          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));\r\n      if (localProcessedSize == 0)\r\n      {\r\n        RINOK(CloseStream());\r\n        continue;\r\n      }\r\n      realProcessedSize += localProcessedSize;\r\n      _filePos += localProcessedSize;\r\n      size -= localProcessedSize;\r\n      break;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenStream());\r\n    }\r\n  }\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)\r\n{\r\n  *value = 0;\r\n  int subStreamIndex = (int)subStream;\r\n  if (subStreamIndex < 0 || subStream > Sizes.Size())\r\n    return E_FAIL;\r\n  if (subStreamIndex < Sizes.Size())\r\n  {\r\n    *value= Sizes[subStreamIndex];\r\n    return S_OK;\r\n  }\r\n  if (!_currentSizeIsDefined)\r\n    return S_FALSE;\r\n  *value = _currentSize;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zFolderInStream.h",
    "content": "// 7z/FolderInStream.h\r\n\r\n#ifndef __7Z_FOLDERINSTREAM_H\r\n#define __7Z_FOLDERINSTREAM_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zHeader.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../Common/InStreamWithCRC.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderInStream: \r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  CFolderInStream();\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\nprivate:\r\n  CSequentialInStreamWithCRC *_inStreamWithHashSpec;\r\n  CMyComPtr<ISequentialInStream> _inStreamWithHash;\r\n  CMyComPtr<IArchiveUpdateCallback> _updateCallback;\r\n\r\n  bool _currentSizeIsDefined;\r\n  UInt64 _currentSize;\r\n\r\n  bool _fileIsOpen;\r\n  UInt64 _filePos;\r\n\r\n  const UInt32 *_fileIndices;\r\n  UInt32 _numFiles;\r\n  UInt32 _fileIndex;\r\n\r\n  HRESULT OpenStream();\r\n  HRESULT CloseStream();\r\n  void AddDigest();\r\npublic:\r\n  void Init(IArchiveUpdateCallback *updateCallback, \r\n      const UInt32 *fileIndices, UInt32 numFiles);\r\n  CRecordVector<bool> Processed;\r\n  CRecordVector<UInt32> CRCs;\r\n  CRecordVector<UInt64> Sizes;\r\n  UInt64 GetFullSize() const\r\n  {\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < Sizes.Size(); i++)      \r\n      size += Sizes[i];\r\n    return size;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zFolderOutStream.cpp",
    "content": "// 7zFolderOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderOutStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderOutStream::CFolderOutStream()\r\n{\r\n  _outStreamWithHashSpec = new COutStreamWithCRC;\r\n  _outStreamWithHash = _outStreamWithHashSpec;\r\n}\r\n\r\nHRESULT CFolderOutStream::Init(\r\n    const CArchiveDatabaseEx *archiveDatabase,\r\n    UInt32 ref2Offset,\r\n    UInt32 startIndex,\r\n    const CBoolVector *extractStatuses, \r\n    IArchiveExtractCallback *extractCallback,\r\n    bool testMode,\r\n    bool checkCrc)\r\n{\r\n  _archiveDatabase = archiveDatabase;\r\n  _ref2Offset = ref2Offset;\r\n  _startIndex = startIndex;\r\n\r\n  _extractStatuses = extractStatuses;\r\n  _extractCallback = extractCallback;\r\n  _testMode = testMode;\r\n\r\n  _checkCrc = checkCrc;\r\n\r\n  _currentIndex = 0;\r\n  _fileIsOpen = false;\r\n  return WriteEmptyFiles();\r\n}\r\n\r\nHRESULT CFolderOutStream::OpenFile()\r\n{\r\n  Int32 askMode;\r\n  if((*_extractStatuses)[_currentIndex])\r\n    askMode = _testMode ? \r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n  else\r\n    askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n\r\n  UInt32 index = _startIndex + _currentIndex;\r\n  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));\r\n\r\n  _outStreamWithHashSpec->SetStream(realOutStream);\r\n  _outStreamWithHashSpec->Init(_checkCrc);\r\n  if (askMode == NArchive::NExtract::NAskMode::kExtract &&\r\n      (!realOutStream)) \r\n  {\r\n    const CFileItem &fileInfo = _archiveDatabase->Files[index];\r\n    if (!fileInfo.IsAnti && !fileInfo.IsDirectory)\r\n      askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  }\r\n  return _extractCallback->PrepareOperation(askMode);\r\n}\r\n\r\nHRESULT CFolderOutStream::WriteEmptyFiles()\r\n{\r\n  for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)\r\n  {\r\n    UInt32 index = _startIndex + _currentIndex;\r\n    const CFileItem &fileInfo = _archiveDatabase->Files[index];\r\n    if (!fileInfo.IsAnti && !fileInfo.IsDirectory && fileInfo.UnPackSize != 0)\r\n      return S_OK;\r\n    RINOK(OpenFile());\r\n    RINOK(_extractCallback->SetOperationResult(\r\n        NArchive::NExtract::NOperationResult::kOK));\r\n    _outStreamWithHashSpec->ReleaseStream();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderOutStream::Write(const void *data, \r\n    UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 index = _startIndex + _currentIndex;\r\n      const CFileItem &fileInfo = _archiveDatabase->Files[index];\r\n      UInt64 fileSize = fileInfo.UnPackSize;\r\n      \r\n      UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos, \r\n          UInt64(size - realProcessedSize));\r\n      \r\n      UInt32 processedSizeLocal;\r\n      RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize, \r\n            numBytesToWrite, &processedSizeLocal));\r\n\r\n      _filePos += processedSizeLocal;\r\n      realProcessedSize += processedSizeLocal;\r\n      if (_filePos == fileSize)\r\n      {\r\n        bool digestsAreEqual;\r\n        if (fileInfo.IsFileCRCDefined && _checkCrc)\r\n          digestsAreEqual = fileInfo.FileCRC == _outStreamWithHashSpec->GetCRC();\r\n        else\r\n          digestsAreEqual = true;\r\n\r\n        RINOK(_extractCallback->SetOperationResult(\r\n            digestsAreEqual ? \r\n            NArchive::NExtract::NOperationResult::kOK :\r\n            NArchive::NExtract::NOperationResult::kCRCError));\r\n        _outStreamWithHashSpec->ReleaseStream();\r\n        _fileIsOpen = false;\r\n        _currentIndex++;\r\n      }\r\n      if (realProcessedSize == size)\r\n      {\r\n        if (processedSize != NULL)\r\n          *processedSize = realProcessedSize;\r\n        return WriteEmptyFiles();\r\n      }\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n      _filePos = 0;\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)\r\n{\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      RINOK(_extractCallback->SetOperationResult(resultEOperationResult));\r\n      _outStreamWithHashSpec->ReleaseStream();\r\n      _fileIsOpen = false;\r\n      _currentIndex++;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::WasWritingFinished()\r\n{\r\n  if (_currentIndex == _extractStatuses->Size())\r\n    return S_OK;\r\n  return E_FAIL;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zFolderOutStream.h",
    "content": "// 7zFolderOutStream.h\r\n\r\n#ifndef __7Z_FOLDEROUTSTREAM_H\r\n#define __7Z_FOLDEROUTSTREAM_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../IArchive.h\"\r\n#include \"../Common/OutStreamWithCRC.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  \r\n  CFolderOutStream();\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n\r\n  COutStreamWithCRC *_outStreamWithHashSpec;\r\n  CMyComPtr<ISequentialOutStream> _outStreamWithHash;\r\n  const CArchiveDatabaseEx *_archiveDatabase;\r\n  const CBoolVector *_extractStatuses;\r\n  UInt32 _startIndex;\r\n  UInt32 _ref2Offset;\r\n  int _currentIndex;\r\n  // UInt64 _currentDataPos;\r\n  CMyComPtr<IArchiveExtractCallback> _extractCallback;\r\n  bool _testMode;\r\n\r\n  bool _fileIsOpen;\r\n\r\n  bool _checkCrc;\r\n  UInt64 _filePos;\r\n\r\n  HRESULT OpenFile();\r\n  HRESULT WriteEmptyFiles();\r\npublic:\r\n  HRESULT Init(\r\n      const CArchiveDatabaseEx *archiveDatabase,\r\n      UInt32 ref2Offset,\r\n      UInt32 startIndex,\r\n      const CBoolVector *extractStatuses, \r\n      IArchiveExtractCallback *extractCallback,\r\n      bool testMode,\r\n      bool checkCrc);\r\n  HRESULT FlushCorrupted(Int32 resultEOperationResult);\r\n  HRESULT WasWritingFinished();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zHandler.cpp",
    "content": "// 7zHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zProperties.h\"\r\n\r\n#include \"../../../Common/IntToString.h\"\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Windows/Defs.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#ifdef _7Z_VOL\r\n#include \"../Common/MultiStream.h\"\r\n#endif\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n#include \"../Common/ParseProperties.h\"\r\n#endif\r\n#endif\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nextern UString ConvertMethodIdToString(UInt64 id);\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCHandler::CHandler()\r\n{\r\n  _crcSize = 4;\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  #else\r\n  Init();\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = \r\n  #ifdef _7Z_VOL\r\n  _refs.Size();\r\n  #else\r\n  *numItems = _database.Files.Size();\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _SFX\r\n\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,     \r\n      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\n\r\n#else\r\n\r\nSTATPROPSTG kArcProps[] = \r\n{\r\n  { NULL, kpidMethod, VT_BSTR},\r\n  { NULL, kpidSolid, VT_BOOL},\r\n  { NULL, kpidNumBlocks, VT_UI4}\r\n};\r\n\r\nSTDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidMethod:\r\n    {\r\n      UString resString;\r\n      CRecordVector<UInt64> ids;\r\n      int i;\r\n      for (i = 0; i < _database.Folders.Size(); i++)\r\n      {\r\n        const CFolder &f = _database.Folders[i];\r\n        for (int j = f.Coders.Size() - 1; j >= 0; j--)\r\n          ids.AddToUniqueSorted(f.Coders[j].MethodID);\r\n      }\r\n\r\n      for (i = 0; i < ids.Size(); i++)\r\n      {\r\n        UInt64 id = ids[i];\r\n        UString methodName;\r\n        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);\r\n        if (methodName.IsEmpty())\r\n          methodName = ConvertMethodIdToString(id);\r\n        if (!resString.IsEmpty())\r\n          resString += L' ';\r\n        resString += methodName;\r\n      }\r\n      prop = resString; \r\n      break;\r\n    }\r\n    case kpidSolid: prop = _database.IsSolid(); break;\r\n    case kpidNumBlocks: prop = (UInt32)_database.Folders.Size(); break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nIMP_IInArchive_ArcProps\r\n\r\n#endif\r\n\r\nstatic void MySetFileTime(bool timeDefined, FILETIME unixTime, NWindows::NCOM::CPropVariant &prop)\r\n{\r\n  if (timeDefined)\r\n    prop = unixTime;\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString GetStringForSizeValue(UInt32 value)\r\n{\r\n  for (int i = 31; i >= 0; i--)\r\n    if ((UInt32(1) << i) == value)\r\n      return ConvertUInt32ToString(i);\r\n  UString result;\r\n  if (value % (1 << 20) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 20);\r\n    result += L\"m\";\r\n  }\r\n  else if (value % (1 << 10) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 10);\r\n    result += L\"k\";\r\n  }\r\n  else\r\n  {\r\n    result += ConvertUInt32ToString(value);\r\n    result += L\"b\";\r\n  }\r\n  return result;\r\n}\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_PPMD  = 0x030401;\r\n\r\nstatic wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));\r\n}\r\nstatic inline UString GetHex2(Byte value)\r\n{\r\n  UString result;\r\n  result += GetHex((Byte)(value >> 4));\r\n  result += GetHex((Byte)(value & 0xF));\r\n  return result;\r\n}\r\n\r\n#endif\r\n\r\nstatic const UInt64 k_AES  = 0x06F10701;\r\n\r\n#ifndef _SFX\r\nstatic inline UInt32 GetUInt32FromMemLE(const Byte *p)\r\n{\r\n  return p[0] | (((UInt32)p[1]) << 8) | (((UInt32)p[2]) << 16) | (((UInt32)p[3]) << 24);\r\n}\r\n#endif\r\n\r\nbool CHandler::IsEncrypted(UInt32 index2) const\r\n{\r\n  CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n  if (folderIndex != kNumNoIndex)\r\n  {\r\n    const CFolder &folderInfo = _database.Folders[folderIndex];\r\n    for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n      if (folderInfo.Coders[i].MethodID == k_AES)\r\n        return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  /*\r\n  const CRef2 &ref2 = _refs[index];\r\n  if (ref2.Refs.IsEmpty())\r\n    return E_FAIL;\r\n  const CRef &ref = ref2.Refs.Front();\r\n  */\r\n  \r\n  #ifdef _7Z_VOL\r\n  const CRef &ref = _refs[index];\r\n  const CVolume &volume = _volumes[ref.VolumeIndex];\r\n  const CArchiveDatabaseEx &_database = volume.Database;\r\n  UInt32 index2 = ref.ItemIndex;\r\n  const CFileItem &item = _database.Files[index2];\r\n  #else\r\n  const CFileItem &item = _database.Files[index];\r\n  UInt32 index2 = index;\r\n  #endif\r\n\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n    {\r\n      if (!item.Name.IsEmpty())\r\n        prop = NItemName::GetOSName(item.Name);\r\n      break;\r\n    }\r\n    case kpidIsFolder:\r\n      prop = item.IsDirectory;\r\n      break;\r\n    case kpidSize:\r\n    {\r\n      prop = item.UnPackSize;\r\n      // prop = ref2.UnPackSize;\r\n      break;\r\n    }\r\n    case kpidPosition:\r\n    {\r\n      /*\r\n      if (ref2.Refs.Size() > 1)\r\n        prop = ref2.StartPos;\r\n      else\r\n      */\r\n        if (item.IsStartPosDefined)\r\n          prop = item.StartPos;\r\n      break;\r\n    }\r\n    case kpidPackedSize:\r\n    {\r\n      // prop = ref2.PackSize;\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          if (_database.FolderStartFileIndex[folderIndex] == (CNum)index2)\r\n            prop = _database.GetFolderFullPackSize(folderIndex);\r\n          /*\r\n          else\r\n            prop = (UInt64)0;\r\n          */\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    }\r\n    case kpidLastAccessTime:\r\n      MySetFileTime(item.IsLastAccessTimeDefined, item.LastAccessTime, prop);\r\n      break;\r\n    case kpidCreationTime:\r\n      MySetFileTime(item.IsCreationTimeDefined, item.CreationTime, prop);\r\n      break;\r\n    case kpidLastWriteTime:\r\n      MySetFileTime(item.IsLastWriteTimeDefined, item.LastWriteTime, prop);\r\n      break;\r\n    case kpidAttributes:\r\n      if (item.AreAttributesDefined)\r\n        prop = item.Attributes;\r\n      break;\r\n    case kpidCRC:\r\n      if (item.IsFileCRCDefined)\r\n        prop = item.FileCRC;\r\n      break;\r\n    case kpidEncrypted:\r\n    {\r\n      prop = IsEncrypted(index2);\r\n      break;\r\n    }\r\n    #ifndef _SFX\r\n    case kpidMethod:\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _database.Folders[folderIndex];\r\n          UString methodsString;\r\n          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n          {\r\n            const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n            if (!methodsString.IsEmpty())\r\n              methodsString += L' ';\r\n\r\n            {\r\n              UString methodName;\r\n              bool methodIsKnown = FindMethod(\r\n                  EXTERNAL_CODECS_VARS \r\n                  coderInfo.MethodID, methodName);\r\n\r\n              if (methodIsKnown)\r\n              {\r\n                methodsString += methodName;\r\n                if (coderInfo.MethodID == k_LZMA)\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() >= 5)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    UInt32 dicSize = GetUInt32FromMemLE(\r\n                      ((const Byte *)coderInfo.Properties + 1));\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_PPMD)\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() >= 5)\r\n                  {\r\n                    Byte order = *(const Byte *)coderInfo.Properties;\r\n                    methodsString += L\":o\";\r\n                    methodsString += ConvertUInt32ToString(order);\r\n                    methodsString += L\":mem\";\r\n                    UInt32 dicSize = GetUInt32FromMemLE(\r\n                      ((const Byte *)coderInfo.Properties + 1));\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_AES)\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() >= 1)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    const Byte *data = (const Byte *)coderInfo.Properties;\r\n                    Byte firstByte = *data++;\r\n                    UInt32 numCyclesPower = firstByte & 0x3F;\r\n                    methodsString += ConvertUInt32ToString(numCyclesPower);\r\n                    /*\r\n                    if ((firstByte & 0xC0) != 0)\r\n                    {\r\n                      methodsString += L\":\";\r\n                      return S_OK;\r\n                      UInt32 saltSize = (firstByte >> 7) & 1;\r\n                      UInt32 ivSize = (firstByte >> 6) & 1;\r\n                      if (coderInfo.Properties.GetCapacity() >= 2)\r\n                      {\r\n                        Byte secondByte = *data++;\r\n                        saltSize += (secondByte >> 4);\r\n                        ivSize += (secondByte & 0x0F);\r\n                      }\r\n                    }\r\n                    */\r\n                  }\r\n                }\r\n                else\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() > 0)\r\n                  {\r\n                    methodsString += L\":[\";\r\n                    for (size_t bi = 0; bi < coderInfo.Properties.GetCapacity(); bi++)\r\n                    {\r\n                      if (bi > 5 && bi + 1 < coderInfo.Properties.GetCapacity())\r\n                      {\r\n                        methodsString += L\"..\";\r\n                        break;\r\n                      }\r\n                      else\r\n                        methodsString += GetHex2(coderInfo.Properties[bi]);\r\n                    }\r\n                    methodsString += L\"]\";\r\n                  }\r\n                }\r\n              }\r\n              else\r\n              {\r\n                methodsString += ConvertMethodIdToString(coderInfo.MethodID);\r\n              }\r\n            }\r\n          }\r\n          prop = methodsString;\r\n        }\r\n      }\r\n      break;\r\n    case kpidBlock:\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n          prop = (UInt32)folderIndex;\r\n      }\r\n      break;\r\n    case kpidPackedSize0:\r\n    case kpidPackedSize1:\r\n    case kpidPackedSize2:\r\n    case kpidPackedSize3:\r\n    case kpidPackedSize4:\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _database.Folders[folderIndex];\r\n          if (_database.FolderStartFileIndex[folderIndex] == (CNum)index2 &&\r\n              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))\r\n          {\r\n            prop = _database.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);\r\n          }\r\n          else\r\n            prop = (UInt64)0;\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    #endif\r\n    case kpidIsAnti:\r\n      prop = item.IsAnti;\r\n      break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef _7Z_VOL\r\n\r\nstatic const wchar_t *kExt = L\"7z\";\r\nstatic const wchar_t *kAfterPart = L\".7z\";\r\n\r\nclass CVolumeName\r\n{\r\n  bool _first;\r\n  UString _unchangedPart;\r\n  UString _changedPart;    \r\n  UString _afterPart;    \r\npublic:\r\n  bool InitName(const UString &name)\r\n  {\r\n    _first = true;\r\n    int dotPos = name.ReverseFind('.');\r\n    UString basePart = name;\r\n    if (dotPos >= 0)\r\n    {\r\n      UString ext = name.Mid(dotPos + 1);\r\n      if (ext.CompareNoCase(kExt)==0 || \r\n        ext.CompareNoCase(L\"EXE\") == 0)\r\n      {\r\n        _afterPart = kAfterPart;\r\n        basePart = name.Left(dotPos);\r\n      }\r\n    }\r\n\r\n    int numLetters = 1;\r\n    bool splitStyle = false;\r\n    if (basePart.Right(numLetters) == L\"1\")\r\n    {\r\n      while (numLetters < basePart.Length())\r\n      {\r\n        if (basePart[basePart.Length() - numLetters - 1] != '0')\r\n          break;\r\n        numLetters++;\r\n      }\r\n    }\r\n    else \r\n      return false;\r\n    _unchangedPart = basePart.Left(basePart.Length() - numLetters);\r\n    _changedPart = basePart.Right(numLetters);\r\n    return true;\r\n  }\r\n\r\n  UString GetNextName()\r\n  {\r\n    UString newName; \r\n    // if (_newStyle || !_first)\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == L'9')\r\n        {\r\n          c = L'0';\r\n          newName = c + newName;\r\n          if (i == 0)\r\n            newName = UString(L'1') + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        newName = UString(c) + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n      _changedPart = newName;\r\n    }\r\n    _first = false;\r\n    return _unchangedPart + _changedPart + _afterPart;\r\n  }\r\n};\r\n\r\n#endif\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 *maxCheckStartPosition, \r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Clear();\r\n  #endif\r\n  try\r\n  {\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;\r\n    #ifdef _7Z_VOL\r\n    CVolumeName seqName;\r\n\r\n    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(\r\n          IID_ICryptoGetTextPassword, &getTextPassword);\r\n    }\r\n    #endif\r\n    #ifdef _7Z_VOL\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback);\r\n    }\r\n    for (;;)\r\n    {\r\n      CMyComPtr<IInStream> inStream;\r\n      if (!_volumes.IsEmpty())\r\n      {\r\n        if (!openVolumeCallback)\r\n          break;\r\n        if(_volumes.Size() == 1)\r\n        {\r\n          UString baseName;\r\n          {\r\n            NCOM::CPropVariant prop;\r\n            RINOK(openVolumeCallback->GetProperty(kpidName, &prop));\r\n            if (prop.vt != VT_BSTR)\r\n              break;\r\n            baseName = prop.bstrVal;\r\n          }\r\n          seqName.InitName(baseName);\r\n        }\r\n\r\n        UString fullName = seqName.GetNextName();\r\n        HRESULT result = openVolumeCallback->GetStream(fullName, &inStream);\r\n        if (result == S_FALSE)\r\n          break;\r\n        if (result != S_OK)\r\n          return result;\r\n        if (!stream)\r\n          break;\r\n      }\r\n      else\r\n        inStream = stream;\r\n\r\n      CInArchive archive;\r\n      RINOK(archive.Open(inStream, maxCheckStartPosition));\r\n\r\n      _volumes.Add(CVolume());\r\n      CVolume &volume = _volumes.Back();\r\n      CArchiveDatabaseEx &database = volume.Database;\r\n      volume.Stream = inStream;\r\n      volume.StartRef2Index = _refs.Size();\r\n\r\n      HRESULT result = archive.ReadDatabase(database\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword\r\n          #endif\r\n          );\r\n      if (result != S_OK)\r\n      {\r\n        _volumes.Clear();\r\n        return result;\r\n      }\r\n      database.Fill();\r\n      for(int i = 0; i < database.Files.Size(); i++)\r\n      {\r\n        CRef refNew;\r\n        refNew.VolumeIndex = _volumes.Size() - 1;\r\n        refNew.ItemIndex = i;\r\n        _refs.Add(refNew);\r\n        /*\r\n        const CFileItem &file = database.Files[i];\r\n        int j;\r\n        */\r\n        /*\r\n        for (j = _refs.Size() - 1; j >= 0; j--)\r\n        {\r\n          CRef2 &ref2 = _refs[j];\r\n          const CRef &ref = ref2.Refs.Back();\r\n          const CVolume &volume2 = _volumes[ref.VolumeIndex];\r\n          const CArchiveDatabaseEx &database2 = volume2.Database;\r\n          const CFileItem &file2 = database2.Files[ref.ItemIndex];\r\n          if (file2.Name.CompareNoCase(file.Name) == 0)\r\n          {\r\n            if (!file.IsStartPosDefined)\r\n              continue;\r\n            if (file.StartPos != ref2.StartPos + ref2.UnPackSize)\r\n              continue;\r\n            ref2.Refs.Add(refNew);\r\n            break;\r\n          }\r\n        }\r\n        */\r\n        /*\r\n        j = -1;\r\n        if (j < 0)\r\n        {\r\n          CRef2 ref2New;\r\n          ref2New.Refs.Add(refNew);\r\n          j = _refs.Add(ref2New);\r\n        }\r\n        CRef2 &ref2 = _refs[j];\r\n        ref2.UnPackSize += file.UnPackSize;\r\n        ref2.PackSize += database.GetFilePackSize(i);\r\n        if (ref2.Refs.Size() == 1 && file.IsStartPosDefined)\r\n          ref2.StartPos = file.StartPos;\r\n        */\r\n      }\r\n      if (database.Files.Size() != 1)\r\n        break;\r\n      const CFileItem &file = database.Files.Front();\r\n      if (!file.IsStartPosDefined)\r\n        break;\r\n    }\r\n    #else\r\n    CInArchive archive;\r\n    RINOK(archive.Open(stream, maxCheckStartPosition));\r\n    HRESULT result = archive.ReadDatabase(\r\n      EXTERNAL_CODECS_VARS\r\n      _database\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    _database.Fill();\r\n    _inStream = stream;\r\n    #endif\r\n  }\r\n  catch(...)\r\n  {\r\n    Close();\r\n    return S_FALSE;\r\n  }\r\n  // _inStream = stream;\r\n  #ifndef _SFX\r\n  FillPopIDs();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef _7Z_VOL\r\n  _volumes.Clear();\r\n  _refs.Clear();\r\n  #else\r\n  _inStream.Release();\r\n  _database.Clear();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nSTDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  *stream = 0;\r\n  CMultiStream *streamSpec = new CMultiStream;\r\n  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;\r\n  \r\n  UInt64 pos = 0;\r\n  const UString *fileName;\r\n  for (int i = 0; i < _refs.Size(); i++)\r\n  {\r\n    const CRef &ref = _refs[i];\r\n    const CVolume &volume = _volumes[ref.VolumeIndex];\r\n    const CArchiveDatabaseEx &database = volume.Database;\r\n    const CFileItem &file = database.Files[ref.ItemIndex];\r\n    if (i == 0)\r\n      fileName = &file.Name;\r\n    else\r\n      if (fileName->Compare(file.Name) != 0)\r\n        return S_FALSE;\r\n    if (!file.IsStartPosDefined)\r\n      return S_FALSE;\r\n    if (file.StartPos != pos)\r\n      return S_FALSE;\r\n    CNum folderIndex = database.FileIndexToFolderIndexMap[ref.ItemIndex];\r\n    if (folderIndex == kNumNoIndex)\r\n    {\r\n      if (file.UnPackSize != 0)\r\n        return E_FAIL;\r\n      continue;\r\n    }\r\n    if (database.NumUnPackStreamsVector[folderIndex] != 1)\r\n      return S_FALSE;\r\n    const CFolder &folder = database.Folders[folderIndex];\r\n    if (folder.Coders.Size() != 1)\r\n      return S_FALSE;\r\n    const CCoderInfo &coder = folder.Coders.Front();\r\n    if (coder.NumInStreams != 1 || coder.NumOutStreams != 1)\r\n      return S_FALSE;\r\n    if (coder.MethodID != k_Copy)\r\n      return S_FALSE;\r\n\r\n    pos += file.UnPackSize;\r\n    CMultiStream::CSubStreamInfo subStreamInfo;\r\n    subStreamInfo.Stream = volume.Stream;\r\n    subStreamInfo.Pos = database.GetFolderStreamPos(folderIndex, 0);\r\n    subStreamInfo.Size = file.UnPackSize;\r\n    streamSpec->Streams.Add(subStreamInfo);\r\n  }\r\n  streamSpec->Init();\r\n  *stream = streamTemp.Detach();\r\n  return S_OK;\r\n}\r\n#endif\r\n\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef COMPRESS_MT\r\n  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();\r\n  _numThreads = numProcessors;\r\n  #endif\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    const PROPVARIANT &value = values[i];\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index == 0)\r\n    {\r\n      if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n      {\r\n        #ifdef COMPRESS_MT\r\n        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n        #endif\r\n        continue;\r\n      }\r\n      else\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}  \r\n\r\n#endif\r\n#endif\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zHandler.h",
    "content": "// 7z/Handler.h\r\n\r\n#ifndef __7Z_HANDLER_H\r\n#define __7Z_HANDLER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../IArchive.h\"\r\n#include \"7zIn.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#ifndef EXTRACT_ONLY\r\n#include \"../Common/HandlerOut.h\"\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\n#ifdef _7Z_VOL\r\nstruct CRef\r\n{\r\n  int VolumeIndex;\r\n  int ItemIndex;\r\n};\r\n\r\nstruct CVolume\r\n{\r\n  int StartRef2Index;\r\n  CMyComPtr<IInStream> Stream;\r\n  CArchiveDatabaseEx Database;\r\n};\r\n#endif\r\n\r\n#ifndef __7Z_SET_PROPERTIES\r\n\r\n#ifdef EXTRACT_ONLY\r\n#ifdef COMPRESS_MT\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n#else \r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n\r\n#endif\r\n\r\n\r\nclass CHandler: \r\n  #ifndef EXTRACT_ONLY\r\n  public NArchive::COutHandler,\r\n  #endif\r\n  public IInArchive,\r\n  #ifdef _7Z_VOL\r\n  public IInArchiveGetStream,\r\n  #endif\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  public ISetProperties, \r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public IOutArchive, \r\n  #endif\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IInArchive)\r\n  #ifdef _7Z_VOL\r\n  MY_QUERYINTERFACE_ENTRY(IInArchiveGetStream)\r\n  #endif\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  MY_QUERYINTERFACE_ENTRY(ISetProperties)\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  MY_QUERYINTERFACE_ENTRY(IOutArchive)\r\n  #endif\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  #ifdef _7Z_VOL\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);  \r\n  #endif\r\n\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);\r\n  #endif\r\n\r\n  #ifndef EXTRACT_ONLY\r\n  INTERFACE_IOutArchive(;)\r\n  #endif\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n  CHandler();\r\n\r\nprivate:\r\n  #ifdef _7Z_VOL\r\n  CObjectVector<CVolume> _volumes;\r\n  CObjectVector<CRef> _refs;\r\n  #else\r\n  CMyComPtr<IInStream> _inStream;\r\n  NArchive::N7z::CArchiveDatabaseEx _database;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  \r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  #else\r\n  \r\n  CRecordVector<CBind> _binds;\r\n\r\n  HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);\r\n\r\n  HRESULT SetCompressionMethod(CCompressionMethodMode &method,\r\n      CObjectVector<COneMethodInfo> &methodsInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  HRESULT SetCompressionMethod(\r\n      CCompressionMethodMode &method,\r\n      CCompressionMethodMode &headerMethod);\r\n\r\n  #endif\r\n\r\n  bool IsEncrypted(UInt32 index2) const;\r\n  #ifndef _SFX\r\n\r\n  CRecordVector<UInt64> _fileInfoPopIDs;\r\n  void FillPopIDs();\r\n\r\n  #endif\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zHandlerOut.cpp",
    "content": "// 7zHandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const UInt32 kLzmaAlgorithmX5 = 1;\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5;\r\n\r\nstatic inline bool IsCopyMethod(const UString &methodName)\r\n  { return (methodName.CompareNoCase(kCopyMethod) == 0); }\r\n\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  CMyComPtr<ICryptoGetTextPassword2> getTextPassword;\r\n  if (!getTextPassword)\r\n  {\r\n    CMyComPtr<IArchiveUpdateCallback> udateCallback2(updateCallback);\r\n    udateCallback2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);\r\n  }\r\n  \r\n  if (getTextPassword)\r\n  {\r\n    CMyComBSTR password;\r\n    Int32 passwordIsDefined;\r\n    RINOK(getTextPassword->CryptoGetTextPassword2(\r\n        &passwordIsDefined, &password));\r\n    methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);\r\n    if (methodMode.PasswordIsDefined)\r\n      methodMode.Password = password;\r\n  }\r\n  else\r\n    methodMode.PasswordIsDefined = false;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CCompressionMethodMode &headerMethod)\r\n{\r\n  HRESULT res = SetCompressionMethod(methodMode, _methods\r\n  #ifdef COMPRESS_MT\r\n  , _numThreads\r\n  #endif\r\n  );\r\n  RINOK(res);\r\n  methodMode.Binds = _binds;\r\n\r\n  if (_compressHeaders)\r\n  {\r\n    // headerMethod.Methods.Add(methodMode.Methods.Back());\r\n\r\n    CObjectVector<COneMethodInfo> headerMethodInfoVector;\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = kLZMAMethodName;\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kMatchFinder;\r\n      property.Value = kLzmaMatchFinderForHeaders;\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kAlgorithm;\r\n      property.Value = kAlgorithmForHeaders;\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kNumFastBytes;\r\n      property.Value = UInt32(kNumFastBytesForHeaders);\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n      property.Value = UInt32(kDictionaryForHeaders);\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    headerMethodInfoVector.Add(oneMethodInfo);\r\n    HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector\r\n      #ifdef COMPRESS_MT\r\n      ,1\r\n      #endif\r\n    );\r\n    RINOK(res);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CObjectVector<COneMethodInfo> &methodsInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  \r\n  if (methodsInfo.IsEmpty())\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = ((level == 0) ? kCopyMethod : kDefaultMethodName);\r\n    methodsInfo.Add(oneMethodInfo);\r\n  }\r\n\r\n  bool needSolid = false;\r\n  for(int i = 0; i < methodsInfo.Size(); i++)\r\n  {\r\n    COneMethodInfo &oneMethodInfo = methodsInfo[i];\r\n    SetCompressionMethod2(oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , numThreads\r\n      #endif\r\n      );\r\n\r\n    if (!IsCopyMethod(oneMethodInfo.MethodName))\r\n      needSolid = true;\r\n\r\n    CMethodFull methodFull;\r\n\r\n    if (!FindMethod(\r\n        EXTERNAL_CODECS_VARS\r\n        oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams))\r\n      return E_INVALIDARG;\r\n    methodFull.Properties = oneMethodInfo.Properties;\r\n    methodMode.Methods.Add(methodFull);\r\n\r\n    if (!_numSolidBytesDefined)\r\n    {\r\n      for (int j = 0; j < methodFull.Properties.Size(); j++)\r\n      {\r\n        const CProp &prop = methodFull.Properties[j];\r\n        if ((prop.Id == NCoderPropID::kDictionarySize || \r\n             prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4)\r\n        {\r\n          _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7;\r\n          const UInt64 kMinSize = (1 << 24);\r\n          if (_numSolidBytes < kMinSize)\r\n            _numSolidBytes = kMinSize;\r\n          _numSolidBytesDefined = true;\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (!needSolid && !_numSolidBytesDefined)\r\n  {\r\n    _numSolidBytesDefined = true;\r\n    _numSolidBytes  = 0;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, PROPID propID, CArchiveFileTime &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant propVariant;\r\n  RINOK(updateCallback->GetProperty(index, propID, &propVariant));\r\n  if (propVariant.vt == VT_FILETIME)\r\n  {\r\n    filetime = propVariant.filetime;\r\n    filetimeIsDefined = true;\r\n  }\r\n  else if (propVariant.vt != VT_EMPTY)\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  const CArchiveDatabaseEx *database = 0;\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() > 1)\r\n    return E_FAIL;\r\n  const CVolume *volume = 0;\r\n  if (_volumes.Size() == 1)\r\n  {\r\n    volume = &_volumes.Front();\r\n    database = &volume->Database;\r\n  }\r\n  #else\r\n  if (_inStream != 0)\r\n    database = &_database;\r\n  #endif\r\n\r\n  // CRecordVector<bool> compressStatuses;\r\n  CObjectVector<CUpdateItem> updateItems;\r\n  // CRecordVector<UInt32> copyIndices;\r\n  \r\n  // CMyComPtr<IUpdateCallback2> updateCallback2;\r\n  // updateCallback->QueryInterface(&updateCallback2);\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    Int32 newData;\r\n    Int32 newProperties;\r\n    UInt32 indexInArchive;\r\n    if (!updateCallback)\r\n      return E_FAIL;\r\n    RINOK(updateCallback->GetUpdateItemInfo(i,\r\n        &newData, &newProperties, &indexInArchive));\r\n    CUpdateItem updateItem;\r\n    updateItem.NewProperties = IntToBool(newProperties);\r\n    updateItem.NewData = IntToBool(newData);\r\n    updateItem.IndexInArchive = indexInArchive;\r\n    updateItem.IndexInClient = i;\r\n    updateItem.IsAnti = false;\r\n    updateItem.Size = 0;\r\n\r\n    if (updateItem.IndexInArchive != -1)\r\n    {\r\n      const CFileItem &fileItem = database->Files[updateItem.IndexInArchive];\r\n      updateItem.Name = fileItem.Name;\r\n      updateItem.IsDirectory = fileItem.IsDirectory;\r\n      updateItem.Size = fileItem.UnPackSize;\r\n      updateItem.IsAnti = fileItem.IsAnti;\r\n      \r\n      updateItem.CreationTime = fileItem.CreationTime;\r\n      updateItem.IsCreationTimeDefined = fileItem.IsCreationTimeDefined;\r\n      updateItem.LastWriteTime = fileItem.LastWriteTime;\r\n      updateItem.IsLastWriteTimeDefined = fileItem.IsLastWriteTimeDefined;\r\n      updateItem.LastAccessTime = fileItem.LastAccessTime;\r\n      updateItem.IsLastAccessTimeDefined = fileItem.IsLastAccessTimeDefined;\r\n    }\r\n\r\n    if (updateItem.NewProperties)\r\n    {\r\n      bool nameIsDefined;\r\n      bool folderStatusIsDefined;\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidAttributes, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          updateItem.AttributesAreDefined = false;\r\n        else if (propVariant.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          updateItem.Attributes = propVariant.ulVal;\r\n          updateItem.AttributesAreDefined = true;\r\n        }\r\n      }\r\n      \r\n      RINOK(GetTime(updateCallback, i, kpidCreationTime, updateItem.CreationTime, updateItem.IsCreationTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, kpidLastWriteTime, updateItem.LastWriteTime , updateItem.IsLastWriteTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, kpidLastAccessTime, updateItem.LastAccessTime, updateItem.IsLastAccessTimeDefined));\r\n\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidPath, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          nameIsDefined = false;\r\n        else if (propVariant.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          updateItem.Name = NItemName::MakeLegalName(propVariant.bstrVal);\r\n          nameIsDefined = true;\r\n        }\r\n      }\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsFolder, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          folderStatusIsDefined = false;\r\n        else if (propVariant.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          updateItem.IsDirectory = (propVariant.boolVal != VARIANT_FALSE);\r\n          folderStatusIsDefined = true;\r\n        }\r\n      }\r\n\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsAnti, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          updateItem.IsAnti = false;\r\n        else if (propVariant.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n          updateItem.IsAnti = (propVariant.boolVal != VARIANT_FALSE);\r\n      }\r\n\r\n      if (updateItem.IsAnti)\r\n      {\r\n        updateItem.AttributesAreDefined = false;\r\n\r\n        updateItem.IsCreationTimeDefined = false;\r\n        updateItem.IsLastWriteTimeDefined = false;\r\n        updateItem.IsLastAccessTimeDefined = false;\r\n        \r\n        updateItem.Size = 0;\r\n      }\r\n\r\n      if (!folderStatusIsDefined && updateItem.AttributesAreDefined)\r\n        updateItem.SetDirectoryStatusFromAttributes();\r\n    }\r\n\r\n    if (updateItem.NewData)\r\n    {\r\n      NCOM::CPropVariant propVariant;\r\n      RINOK(updateCallback->GetProperty(i, kpidSize, &propVariant));\r\n      if (propVariant.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      updateItem.Size = (UInt64)propVariant.uhVal.QuadPart;\r\n      if (updateItem.Size != 0 && updateItem.IsAnti)\r\n        return E_INVALIDARG;\r\n    }\r\n    updateItems.Add(updateItem);\r\n  }\r\n\r\n  CCompressionMethodMode methodMode, headerMethod;\r\n  RINOK(SetCompressionMethod(methodMode, headerMethod));\r\n  #ifdef COMPRESS_MT\r\n  methodMode.NumThreads = _numThreads;\r\n  headerMethod.NumThreads = 1;\r\n  #endif\r\n\r\n  RINOK(SetPassword(methodMode, updateCallback));\r\n\r\n  bool compressMainHeader = _compressHeaders;  // check it\r\n\r\n  if (methodMode.PasswordIsDefined)\r\n  {\r\n    compressMainHeader = true; \r\n    if(_encryptHeaders)\r\n      RINOK(SetPassword(headerMethod, updateCallback));\r\n  }\r\n\r\n  if (numItems < 2)\r\n    compressMainHeader = false;\r\n\r\n  CUpdateOptions options;\r\n  options.Method = &methodMode;\r\n  options.HeaderMethod = (_compressHeaders || \r\n      (methodMode.PasswordIsDefined && _encryptHeaders)) ? \r\n      &headerMethod : 0;\r\n  options.UseFilters = _level != 0 && _autoFilter;\r\n  options.MaxFilter = _level >= 8;\r\n\r\n  options.HeaderOptions.CompressMainHeader = compressMainHeader;\r\n  options.HeaderOptions.WriteModified = WriteModified;\r\n  options.HeaderOptions.WriteCreated = WriteCreated;\r\n  options.HeaderOptions.WriteAccessed = WriteAccessed;\r\n  \r\n  options.NumSolidFiles = _numSolidFiles;\r\n  options.NumSolidBytes = _numSolidBytes;\r\n  options.SolidExtension = _solidExtension;\r\n  options.RemoveSfxBlock = _removeSfxBlock;\r\n  options.VolumeMode = _volumeMode;\r\n  return Update(\r\n      EXTERNAL_CODECS_VARS\r\n      #ifdef _7Z_VOL\r\n      volume ? volume->Stream: 0, \r\n      volume ? database: 0, \r\n      #else\r\n      _inStream, \r\n      database,\r\n      #endif\r\n      updateItems, outStream, updateCallback, options);\r\n  COM_TRY_END\r\n}\r\n\r\nstatic HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)\r\n{\r\n  stream = 0;\r\n  int index = ParseStringToUInt32(srcString, coder);\r\n  if (index == 0)\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0, index);\r\n  if (srcString[0] == 'S')\r\n  {\r\n    srcString.Delete(0);\r\n    int index = ParseStringToUInt32(srcString, stream);\r\n    if (index == 0)\r\n      return E_INVALIDARG;\r\n    srcString.Delete(0, index);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetBindInfo(UString &srcString, CBind &bind)\r\n{\r\n  RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream));\r\n  if (srcString[0] != ':')\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0);\r\n  RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream));\r\n  if (!srcString.IsEmpty())\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  _binds.Clear();\r\n  BeforeSetProperty();\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n\r\n    const PROPVARIANT &value = values[i];\r\n\r\n    if (name[0] == 'B')\r\n    {\r\n      name.Delete(0);\r\n      CBind bind;\r\n      RINOK(GetBindInfo(name, bind));\r\n      _binds.Add(bind);\r\n      continue;\r\n    }\r\n\r\n    RINOK(SetProperty(name, value));\r\n  }\r\n\r\n  return S_OK;\r\n  COM_TRY_END\r\n}  \r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zHeader.cpp",
    "content": "// 7z/Header.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nByte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n#ifdef _7Z_VOL\r\nByte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};\r\n#endif\r\n\r\nclass SignatureInitializer\r\n{\r\npublic:\r\n  SignatureInitializer() \r\n  { \r\n    kSignature[0]--; \r\n    #ifdef _7Z_VOL\r\n    kFinishSignature[0]--;\r\n    #endif\r\n  };\r\n} g_SignatureInitializer;\r\n\r\n}}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zHeader.h",
    "content": "// 7z/7zHeader.h\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nconst int kSignatureSize = 6;\r\nextern Byte kSignature[kSignatureSize];\r\n\r\n// #define _7Z_VOL\r\n// 7z-MultiVolume is not finished yet.\r\n// It can work already, but I still do not like some \r\n// things of that new multivolume format.\r\n// So please keep it commented.\r\n\r\n#ifdef _7Z_VOL\r\nextern Byte kFinishSignature[kSignatureSize];\r\n#endif\r\n\r\nstruct CArchiveVersion\r\n{\r\n  Byte Major;\r\n  Byte Minor;\r\n};\r\n\r\nconst Byte kMajorVersion = 0;\r\n\r\nstruct CStartHeader\r\n{\r\n  UInt64 NextHeaderOffset;\r\n  UInt64 NextHeaderSize;\r\n  UInt32 NextHeaderCRC;\r\n};\r\n\r\nconst UInt32 kStartHeaderSize = 20;\r\n\r\n#ifdef _7Z_VOL\r\nstruct CFinishHeader: public CStartHeader\r\n{\r\n  UInt64 ArchiveStartOffset;  // data offset from end if that struct\r\n  UInt64 AdditionalStartBlockSize; // start  signature & start header size\r\n};\r\n\r\nconst UInt32 kFinishHeaderSize = kStartHeaderSize + 16;\r\n#endif\r\n\r\nnamespace NID\r\n{\r\n  enum EEnum\r\n  {\r\n    kEnd,\r\n\r\n    kHeader,\r\n\r\n    kArchiveProperties,\r\n    \r\n    kAdditionalStreamsInfo,\r\n    kMainStreamsInfo,\r\n    kFilesInfo,\r\n    \r\n    kPackInfo,\r\n    kUnPackInfo,\r\n    kSubStreamsInfo,\r\n\r\n    kSize,\r\n    kCRC,\r\n\r\n    kFolder,\r\n\r\n    kCodersUnPackSize,\r\n    kNumUnPackStream,\r\n\r\n    kEmptyStream,\r\n    kEmptyFile,\r\n    kAnti,\r\n\r\n    kName,\r\n    kCreationTime,\r\n    kLastAccessTime,\r\n    kLastWriteTime,\r\n    kWinAttributes,\r\n    kComment,\r\n\r\n    kEncodedHeader,\r\n\r\n    kStartPos\r\n  };\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zIn.cpp",
    "content": "// 7zIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zDecode.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\n// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader \r\n#ifndef _SFX\r\n#define FORMAT_7Z_RECOVERY\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CInArchiveException {};\r\n\r\nstatic void ThrowException() { throw CInArchiveException(); }\r\nstatic inline void ThrowEndOfData()   { ThrowException(); }\r\nstatic inline void ThrowUnsupported() { ThrowException(); }\r\nstatic inline void ThrowIncorrect()   { ThrowException(); }\r\nstatic inline void ThrowUnsupportedVersion() { ThrowException(); }\r\n\r\n/*\r\nclass CInArchiveException\r\n{\r\npublic:\r\n  enum CCauseType\r\n  {\r\n    kUnsupportedVersion = 0,\r\n    kUnsupported,\r\n    kIncorrect, \r\n    kEndOfData,\r\n  } Cause;\r\n  CInArchiveException(CCauseType cause): Cause(cause) {};\r\n};\r\n\r\nstatic void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }\r\nstatic void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }\r\nstatic void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }\r\nstatic void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }\r\nstatic void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }\r\n*/\r\n\r\nclass CStreamSwitch\r\n{\r\n  CInArchive *_archive;\r\n  bool _needRemove;\r\npublic:\r\n  CStreamSwitch(): _needRemove(false) {}\r\n  ~CStreamSwitch() { Remove(); }\r\n  void Remove();\r\n  void Set(CInArchive *archive, const Byte *data, size_t size);\r\n  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);\r\n  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);\r\n};\r\n\r\nvoid CStreamSwitch::Remove()\r\n{\r\n  if (_needRemove)\r\n  {\r\n    _archive->DeleteByteStream();\r\n    _needRemove = false;\r\n  }\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)\r\n{\r\n  Remove();\r\n  _archive = archive;\r\n  _archive->AddByteStream(data, size);\r\n  _needRemove = true;\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)\r\n{\r\n  Set(archive, byteBuffer, byteBuffer.GetCapacity());\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)\r\n{\r\n  Remove();\r\n  Byte external = archive->ReadByte();\r\n  if (external != 0)\r\n  {\r\n    int dataIndex = (int)archive->ReadNum();\r\n    if (dataIndex < 0 || dataIndex >= dataVector->Size())\r\n      ThrowIncorrect();\r\n    Set(archive, (*dataVector)[dataIndex]);\r\n  }\r\n}\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define SZ_LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#ifdef SZ_LITTLE_ENDIAN_UNALIGN\r\nstatic inline UInt16 GetUInt16FromMem(const Byte *p) { return *(const UInt16 *)p; }\r\nstatic inline UInt32 GetUInt32FromMem(const Byte *p) { return *(const UInt32 *)p; }\r\nstatic inline UInt64 GetUInt64FromMem(const Byte *p) { return *(const UInt64 *)p; }\r\n#else\r\nstatic inline UInt16 GetUInt16FromMem(const Byte *p) { return p[0] | ((UInt16)p[1] << 8); }\r\nstatic inline UInt32 GetUInt32FromMem(const Byte *p) { return p[0] | ((UInt32)p[1] << 8) | ((UInt32)p[2] << 16) | ((UInt32)p[3] << 24); }\r\nstatic inline UInt64 GetUInt64FromMem(const Byte *p) { return GetUInt32FromMem(p) | ((UInt64)GetUInt32FromMem(p + 4) << 32); }\r\n#endif\r\n\r\nByte CInByte2::ReadByte()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  return _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::ReadBytes(Byte *data, size_t size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  for (size_t i = 0; i < size; i++)\r\n    data[i] = _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::SkeepData(UInt64 size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n}\r\n\r\nvoid CInByte2::SkeepData()\r\n{\r\n  SkeepData(ReadNumber());\r\n}\r\n\r\nUInt64 CInByte2::ReadNumber()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  Byte firstByte = _buffer[_pos++];\r\n  Byte mask = 0x80;\r\n  UInt64 value = 0;\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      value += (highPart << (i * 8));\r\n      return value;\r\n    }\r\n    if (_pos >= _size)\r\n      ThrowEndOfData();\r\n    value |= ((UInt64)_buffer[_pos++] << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return value;\r\n}\r\n\r\nCNum CInByte2::ReadNum()\r\n{ \r\n  UInt64 value = ReadNumber(); \r\n  if (value > kNumMax)\r\n    ThrowUnsupported();\r\n  return (CNum)value;\r\n}\r\n\r\nUInt32 CInByte2::ReadUInt32()\r\n{\r\n  if (_pos + 4 > _size)\r\n    ThrowEndOfData();\r\n  UInt32 res = GetUInt32FromMem(_buffer + _pos);\r\n  _pos += 4;\r\n  return res;\r\n}\r\n\r\nUInt64 CInByte2::ReadUInt64()\r\n{\r\n  if (_pos + 8 > _size)\r\n    ThrowEndOfData();\r\n  UInt64 res = GetUInt64FromMem(_buffer + _pos);\r\n  _pos += 8;\r\n  return res;\r\n}\r\n\r\nvoid CInByte2::ReadString(UString &s)\r\n{\r\n  const Byte *buf = _buffer + _pos;\r\n  size_t rem = (_size - _pos) / 2 * 2;\r\n  {\r\n    size_t i;\r\n    for (i = 0; i < rem; i += 2)\r\n      if (buf[i] == 0 && buf[i + 1] == 0)\r\n        break;\r\n    if (i == rem)\r\n      ThrowEndOfData();\r\n    rem = i;\r\n  }\r\n  int len = (int)(rem / 2);\r\n  if (len < 0 || (size_t)len * 2 != rem)\r\n    ThrowUnsupported();\r\n  wchar_t *p = s.GetBuffer(len);\r\n  int i;\r\n  for (i = 0; i < len; i++, buf += 2) \r\n    p[i] = (wchar_t)GetUInt16FromMem(buf);\r\n  p[i] = 0;\r\n  s.ReleaseBuffer(len);\r\n  _pos += rem + 2;\r\n}\r\n\r\nstatic inline bool TestSignatureCandidate(const Byte *p)\r\n{\r\n  for (int i = 0; i < kSignatureSize; i++)\r\n    if (p[i] != kSignature[i])\r\n      return false;\r\n  return (p[0x1A] == 0 && p[0x1B] == 0);\r\n}\r\n\r\nHRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  UInt32 processedSize; \r\n  RINOK(ReadStream(stream, _header, kHeaderSize, &processedSize));\r\n  if (processedSize != kHeaderSize)\r\n    return S_FALSE;\r\n  if (TestSignatureCandidate(_header))\r\n    return S_OK;\r\n\r\n  CByteBuffer byteBuffer;\r\n  const UInt32 kBufferSize = (1 << 16);\r\n  byteBuffer.SetCapacity(kBufferSize);\r\n  Byte *buffer = byteBuffer;\r\n  UInt32 numPrevBytes = kHeaderSize - 1;\r\n  memcpy(buffer, _header + 1, numPrevBytes);\r\n  UInt64 curTestPos = _arhiveBeginStreamPosition + 1;\r\n  for (;;)\r\n  {\r\n    if (searchHeaderSizeLimit != NULL)\r\n      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)\r\n        break;\r\n    UInt32 numReadBytes = kBufferSize - numPrevBytes;\r\n    RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));\r\n    UInt32 numBytesInBuffer = numPrevBytes + processedSize;\r\n    if (numBytesInBuffer < kHeaderSize)\r\n      break;\r\n    UInt32 numTests = numBytesInBuffer - kHeaderSize + 1;\r\n    for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++)\r\n    { \r\n      if (TestSignatureCandidate(buffer + pos))\r\n      {\r\n        memcpy(_header, buffer + pos, kHeaderSize);\r\n        _arhiveBeginStreamPosition = curTestPos;\r\n        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);\r\n      }\r\n    }\r\n    numPrevBytes = numBytesInBuffer - numTests;\r\n    memmove(buffer, buffer + numTests, numPrevBytes);\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\n// S_FALSE means that file is not archive\r\nHRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  Close();\r\n  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))\r\n  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));\r\n  _stream = stream;\r\n  return S_OK;\r\n}\r\n  \r\nvoid CInArchive::Close()\r\n{\r\n  _stream.Release();\r\n}\r\n\r\nvoid CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)\r\n{\r\n  for (;;)\r\n  {\r\n    if (ReadID() == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::GetNextFolderItem(CFolder &folder)\r\n{\r\n  CNum numCoders = ReadNum();\r\n\r\n  folder.Coders.Clear();\r\n  folder.Coders.Reserve((int)numCoders);\r\n  CNum numInStreams = 0;\r\n  CNum numOutStreams = 0;\r\n  CNum i;\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    folder.Coders.Add(CCoderInfo());\r\n    CCoderInfo &coder = folder.Coders.Back();\r\n\r\n    {\r\n      Byte mainByte = ReadByte();\r\n      int idSize = (mainByte & 0xF);\r\n      Byte longID[15];\r\n      ReadBytes(longID, idSize);\r\n      if (idSize > 8)\r\n        ThrowUnsupported();\r\n      UInt64 id = 0;\r\n      for (int j = 0; j < idSize; j++)\r\n        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n      coder.MethodID = id;\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        coder.NumInStreams = ReadNum();\r\n        coder.NumOutStreams = ReadNum();\r\n      }\r\n      else\r\n      {\r\n        coder.NumInStreams = 1;\r\n        coder.NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        CNum propertiesSize = ReadNum();\r\n        coder.Properties.SetCapacity((size_t)propertiesSize);\r\n        ReadBytes((Byte *)coder.Properties, (size_t)propertiesSize);\r\n      }\r\n      if ((mainByte & 0x80) != 0)\r\n        ThrowUnsupported();\r\n    }\r\n    numInStreams += coder.NumInStreams;\r\n    numOutStreams += coder.NumOutStreams;\r\n  }\r\n\r\n  CNum numBindPairs;\r\n  numBindPairs = numOutStreams - 1;\r\n  folder.BindPairs.Clear();\r\n  folder.BindPairs.Reserve(numBindPairs);\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = ReadNum();\r\n    bindPair.OutIndex = ReadNum(); \r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n\r\n  CNum numPackedStreams = numInStreams - numBindPairs;\r\n  folder.PackStreams.Reserve(numPackedStreams);\r\n  if (numPackedStreams == 1)\r\n  {\r\n    for (CNum j = 0; j < numInStreams; j++)\r\n      if (folder.FindBindPairForInStream(j) < 0)\r\n      {\r\n        folder.PackStreams.Add(j);\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n      folder.PackStreams.Add(ReadNum());\r\n}\r\n\r\nvoid CInArchive::WaitAttribute(UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == attribute)\r\n      return;\r\n    if (type == NID::kEnd)\r\n      ThrowIncorrect();\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadHashDigests(int numItems,\r\n    CRecordVector<bool> &digestsDefined, \r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  ReadBoolVector2(numItems, digestsDefined);\r\n  digests.Clear();\r\n  digests.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 crc = 0;\r\n    if (digestsDefined[i])\r\n      crc = ReadUInt32();\r\n    digests.Add(crc);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadPackInfo(\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CRecordVector<bool> &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs)\r\n{\r\n  dataOffset = ReadNumber();\r\n  CNum numPackStreams = ReadNum();\r\n\r\n  WaitAttribute(NID::kSize);\r\n  packSizes.Clear();\r\n  packSizes.Reserve(numPackStreams);\r\n  for (CNum i = 0; i < numPackStreams; i++)\r\n    packSizes.Add(ReadNumber());\r\n\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    if (type == NID::kCRC)\r\n    {\r\n      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs); \r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n  if (packCRCsDefined.IsEmpty())\r\n  {\r\n    packCRCsDefined.Reserve(numPackStreams);\r\n    packCRCsDefined.Clear();\r\n    packCRCs.Reserve(numPackStreams);\r\n    packCRCs.Clear();\r\n    for(CNum i = 0; i < numPackStreams; i++)\r\n    {\r\n      packCRCsDefined.Add(false);\r\n      packCRCs.Add(0);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadUnPackInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    CObjectVector<CFolder> &folders)\r\n{\r\n  WaitAttribute(NID::kFolder);\r\n  CNum numFolders = ReadNum();\r\n\r\n  {\r\n    CStreamSwitch streamSwitch;\r\n    streamSwitch.Set(this, dataVector);\r\n    folders.Clear();\r\n    folders.Reserve(numFolders);\r\n    for(CNum i = 0; i < numFolders; i++)\r\n    {\r\n      folders.Add(CFolder());\r\n      GetNextFolderItem(folders.Back());\r\n    }\r\n  }\r\n\r\n  WaitAttribute(NID::kCodersUnPackSize);\r\n\r\n  CNum i;\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    CFolder &folder = folders[i];\r\n    CNum numOutStreams = folder.GetNumOutStreams();\r\n    folder.UnPackSizes.Reserve(numOutStreams);\r\n    for (CNum j = 0; j < numOutStreams; j++)\r\n      folder.UnPackSizes.Add(ReadNumber());\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      return;\r\n    if (type == NID::kCRC)\r\n    {\r\n      CRecordVector<bool> crcsDefined;\r\n      CRecordVector<UInt32> crcs;\r\n      ReadHashDigests(numFolders, crcsDefined, crcs); \r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        CFolder &folder = folders[i];\r\n        folder.UnPackCRCDefined = crcsDefined[i];\r\n        folder.UnPackCRC = crcs[i];\r\n      }\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n    CRecordVector<UInt64> &unPackSizes,\r\n    CRecordVector<bool> &digestsDefined, \r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  numUnPackStreamsInFolders.Clear();\r\n  numUnPackStreamsInFolders.Reserve(folders.Size());\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kNumUnPackStream)\r\n    {\r\n      for(int i = 0; i < folders.Size(); i++)\r\n        numUnPackStreamsInFolders.Add(ReadNum());\r\n      continue;\r\n    }\r\n    if (type == NID::kCRC || type == NID::kSize)\r\n      break;\r\n    if (type == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n\r\n  if (numUnPackStreamsInFolders.IsEmpty())\r\n    for(int i = 0; i < folders.Size(); i++)\r\n      numUnPackStreamsInFolders.Add(1);\r\n\r\n  int i;\r\n  for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n  {\r\n    // v3.13 incorrectly worked with empty folders\r\n    // v4.07: we check that folder is empty\r\n    CNum numSubstreams = numUnPackStreamsInFolders[i];\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    UInt64 sum = 0;\r\n    for (CNum j = 1; j < numSubstreams; j++)\r\n      if (type == NID::kSize)\r\n      {\r\n        UInt64 size = ReadNumber();\r\n        unPackSizes.Add(size);\r\n        sum += size;\r\n      }\r\n    unPackSizes.Add(folders[i].GetUnPackSize() - sum);\r\n  }\r\n  if (type == NID::kSize)\r\n    type = ReadID();\r\n\r\n  int numDigests = 0;\r\n  int numDigestsTotal = 0;\r\n  for(i = 0; i < folders.Size(); i++)\r\n  {\r\n    CNum numSubstreams = numUnPackStreamsInFolders[i];\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n    numDigestsTotal += numSubstreams;\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    if (type == NID::kCRC)\r\n    {\r\n      CRecordVector<bool> digestsDefined2; \r\n      CRecordVector<UInt32> digests2;\r\n      ReadHashDigests(numDigests, digestsDefined2, digests2);\r\n      int digestIndex = 0;\r\n      for (i = 0; i < folders.Size(); i++)\r\n      {\r\n        CNum numSubstreams = numUnPackStreamsInFolders[i];\r\n        const CFolder &folder = folders[i];\r\n        if (numSubstreams == 1 && folder.UnPackCRCDefined)\r\n        {\r\n          digestsDefined.Add(true);\r\n          digests.Add(folder.UnPackCRC);\r\n        }\r\n        else\r\n          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)\r\n          {\r\n            digestsDefined.Add(digestsDefined2[digestIndex]);\r\n            digests.Add(digests2[digestIndex]);\r\n          }\r\n      }\r\n    }\r\n    else if (type == NID::kEnd)\r\n    {\r\n      if (digestsDefined.IsEmpty())\r\n      {\r\n        digestsDefined.Clear();\r\n        digests.Clear();\r\n        for (int i = 0; i < numDigestsTotal; i++)\r\n        {\r\n          digestsDefined.Add(false);\r\n          digests.Add(0);\r\n        }\r\n      }\r\n      return;\r\n    }\r\n    else\r\n      SkeepData();\r\n    type = ReadID();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadStreamsInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CRecordVector<bool> &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs,\r\n    CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n    CRecordVector<UInt64> &unPackSizes,\r\n    CRecordVector<bool> &digestsDefined, \r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type > ((UInt32)1 << 30))\r\n      ThrowIncorrect();\r\n    switch((UInt32)type)\r\n    {\r\n      case NID::kEnd:\r\n        return;\r\n      case NID::kPackInfo:\r\n      {\r\n        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);\r\n        break;\r\n      }\r\n      case NID::kUnPackInfo:\r\n      {\r\n        ReadUnPackInfo(dataVector, folders);\r\n        break;\r\n      }\r\n      case NID::kSubStreamsInfo:\r\n      {\r\n        ReadSubStreamsInfo(folders, numUnPackStreamsInFolders,\r\n            unPackSizes, digestsDefined, digests);\r\n        break;\r\n      }\r\n      default:\r\n        ThrowIncorrect();\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector(int numItems, CBoolVector &v)\r\n{\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  for(int i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      b = ReadByte();\r\n      mask = 0x80;\r\n    }\r\n    v.Add((b & mask) != 0);\r\n    mask >>= 1;\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)\r\n{\r\n  Byte allAreDefined = ReadByte();\r\n  if (allAreDefined == 0)\r\n  {\r\n    ReadBoolVector(numItems, v);\r\n    return;\r\n  }\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n    v.Add(true);\r\n}\r\n\r\nvoid CInArchive::ReadTime(const CObjectVector<CByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt32 type)\r\n{\r\n  CBoolVector boolVector;\r\n  ReadBoolVector2(files.Size(), boolVector);\r\n\r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, &dataVector);\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    fileTime.dwLowDateTime = 0;\r\n    fileTime.dwHighDateTime = 0;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      fileTime.dwLowDateTime = ReadUInt32();\r\n      fileTime.dwHighDateTime = ReadUInt32();\r\n    }\r\n    switch(type)\r\n    {\r\n      case NID::kCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case NID::kLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case NID::kLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadAndDecodePackedStreams(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    UInt64 baseOffset, \r\n    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  CRecordVector<UInt64> packSizes;\r\n  CRecordVector<bool> packCRCsDefined;\r\n  CRecordVector<UInt32> packCRCs;\r\n  CObjectVector<CFolder> folders;\r\n  \r\n  CRecordVector<CNum> numUnPackStreamsInFolders;\r\n  CRecordVector<UInt64> unPackSizes;\r\n  CRecordVector<bool> digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  ReadStreamsInfo(NULL, \r\n    dataOffset,\r\n    packSizes, \r\n    packCRCsDefined, \r\n    packCRCs, \r\n    folders,\r\n    numUnPackStreamsInFolders,\r\n    unPackSizes,\r\n    digestsDefined, \r\n    digests);\r\n  \r\n  // database.ArchiveInfo.DataStartPosition2 += database.ArchiveInfo.StartPositionAfterHeader;\r\n  \r\n  CNum packIndex = 0;\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  UInt64 dataStartPos = baseOffset + dataOffset;\r\n  for(int i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    dataVector.Add(CByteBuffer());\r\n    CByteBuffer &data = dataVector.Back();\r\n    UInt64 unPackSize64 = folder.GetUnPackSize();\r\n    size_t unPackSize = (size_t)unPackSize64;\r\n    if (unPackSize != unPackSize64)\r\n      ThrowUnsupported();\r\n    data.SetCapacity(unPackSize);\r\n    \r\n    CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    outStreamSpec->Init(data, unPackSize);\r\n    \r\n    HRESULT result = decoder.Decode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      _stream, dataStartPos, \r\n      &packSizes[packIndex], folder, outStream, NULL\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , false, 1\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    \r\n    if (folder.UnPackCRCDefined)\r\n      if (CrcCalc(data, unPackSize) != folder.UnPackCRC)\r\n        ThrowIncorrect();\r\n      for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n        dataStartPos += packSizes[packIndex++];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CInArchive::ReadHeader(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &database\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  UInt64 type = ReadID();\r\n\r\n  if (type == NID::kArchiveProperties)\r\n  {\r\n    ReadArchiveProperties(database.ArchiveInfo);\r\n    type = ReadID();\r\n  }\r\n \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  if (type == NID::kAdditionalStreamsInfo)\r\n  {\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        database.ArchiveInfo.StartPositionAfterHeader, \r\n        database.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    database.ArchiveInfo.DataStartPosition2 += database.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n\r\n  CRecordVector<UInt64> unPackSizes;\r\n  CRecordVector<bool> digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  if (type == NID::kMainStreamsInfo)\r\n  {\r\n    ReadStreamsInfo(&dataVector,\r\n        database.ArchiveInfo.DataStartPosition,\r\n        database.PackSizes, \r\n        database.PackCRCsDefined, \r\n        database.PackCRCs, \r\n        database.Folders,\r\n        database.NumUnPackStreamsVector,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    database.ArchiveInfo.DataStartPosition += database.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n  else\r\n  {\r\n    for(int i = 0; i < database.Folders.Size(); i++)\r\n    {\r\n      database.NumUnPackStreamsVector.Add(1);\r\n      CFolder &folder = database.Folders[i];\r\n      unPackSizes.Add(folder.GetUnPackSize());\r\n      digestsDefined.Add(folder.UnPackCRCDefined);\r\n      digests.Add(folder.UnPackCRC);\r\n    }\r\n  }\r\n\r\n  database.Files.Clear();\r\n\r\n  if (type == NID::kEnd)\r\n    return S_OK;\r\n  if (type != NID::kFilesInfo)\r\n    ThrowIncorrect();\r\n  \r\n  CNum numFiles = ReadNum();\r\n  database.Files.Reserve(numFiles);\r\n  CNum i;\r\n  for(i = 0; i < numFiles; i++)\r\n    database.Files.Add(CFileItem());\r\n\r\n  database.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);\r\n  if (!database.PackSizes.IsEmpty())\r\n    database.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);\r\n  if (numFiles > 0  && !digests.IsEmpty())\r\n    database.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);\r\n\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve((int)numFiles);\r\n  for(i = 0; i < numFiles; i++)\r\n    emptyStreamVector.Add(false);\r\n  CBoolVector emptyFileVector;\r\n  CBoolVector antiFileVector;\r\n  CNum numEmptyStreams = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    UInt64 size = ReadNumber();\r\n    bool isKnownType = true;\r\n    if (type > ((UInt32)1 << 30))\r\n      isKnownType = false;\r\n    else switch((UInt32)type)\r\n    {\r\n      case NID::kName:\r\n      {\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for(int i = 0; i < database.Files.Size(); i++)\r\n          _inByteBack->ReadString(database.Files[i].Name);\r\n        break;\r\n      }\r\n      case NID::kWinAttributes:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(database.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for(i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = database.Files[i];\r\n          file.AreAttributesDefined = boolVector[i];\r\n          if (file.AreAttributesDefined)\r\n            file.Attributes = ReadUInt32();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kStartPos:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(database.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for(i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = database.Files[i];\r\n          file.IsStartPosDefined = boolVector[i];\r\n          if (file.IsStartPosDefined)\r\n            file.StartPos = ReadUInt64();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyStream:\r\n      {\r\n        ReadBoolVector(numFiles, emptyStreamVector);\r\n        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)\r\n          if (emptyStreamVector[i])\r\n            numEmptyStreams++;\r\n        emptyFileVector.Reserve(numEmptyStreams);\r\n        antiFileVector.Reserve(numEmptyStreams);\r\n        for (i = 0; i < numEmptyStreams; i++)\r\n        {\r\n          emptyFileVector.Add(false);\r\n          antiFileVector.Add(false);\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyFile:\r\n      {\r\n        ReadBoolVector(numEmptyStreams, emptyFileVector);\r\n        break;\r\n      }\r\n      case NID::kAnti:\r\n      {\r\n        ReadBoolVector(numEmptyStreams, antiFileVector);\r\n        break;\r\n      }\r\n      case NID::kCreationTime:\r\n      case NID::kLastWriteTime:\r\n      case NID::kLastAccessTime:\r\n      {\r\n        ReadTime(dataVector, database.Files, (UInt32)type);\r\n        break;\r\n      }\r\n      default:\r\n        isKnownType = false;\r\n    }\r\n    if (isKnownType)\r\n      database.ArchiveInfo.FileInfoPopIDs.Add(type);\r\n    else\r\n      SkeepData(size);\r\n  }\r\n\r\n  CNum emptyFileIndex = 0;\r\n  CNum sizeIndex = 0;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    CFileItem &file = database.Files[i];\r\n    file.HasStream = !emptyStreamVector[i];\r\n    if(file.HasStream)\r\n    {\r\n      file.IsDirectory = false;\r\n      file.IsAnti = false;\r\n      file.UnPackSize = unPackSizes[sizeIndex];\r\n      file.FileCRC = digests[sizeIndex];\r\n      file.IsFileCRCDefined = digestsDefined[sizeIndex];\r\n      sizeIndex++;\r\n    }\r\n    else\r\n    {\r\n      file.IsDirectory = !emptyFileVector[emptyFileIndex];\r\n      file.IsAnti = antiFileVector[emptyFileIndex];\r\n      emptyFileIndex++;\r\n      file.UnPackSize = 0;\r\n      file.IsFileCRCDefined = false;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartPackStream()\r\n{\r\n  FolderStartPackStreamIndex.Clear();\r\n  FolderStartPackStreamIndex.Reserve(Folders.Size());\r\n  CNum startPos = 0;\r\n  for(int i = 0; i < Folders.Size(); i++)\r\n  {\r\n    FolderStartPackStreamIndex.Add(startPos);\r\n    startPos += (CNum)Folders[i].PackStreams.Size();\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillStartPos()\r\n{\r\n  PackStreamStartPositions.Clear();\r\n  PackStreamStartPositions.Reserve(PackSizes.Size());\r\n  UInt64 startPos = 0;\r\n  for(int i = 0; i < PackSizes.Size(); i++)\r\n  {\r\n    PackStreamStartPositions.Add(startPos);\r\n    startPos += PackSizes[i];\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartFileIndex()\r\n{\r\n  FolderStartFileIndex.Clear();\r\n  FolderStartFileIndex.Reserve(Folders.Size());\r\n  FileIndexToFolderIndexMap.Clear();\r\n  FileIndexToFolderIndexMap.Reserve(Files.Size());\r\n  \r\n  int folderIndex = 0;\r\n  CNum indexInFolder = 0;\r\n  for (int i = 0; i < Files.Size(); i++)\r\n  {\r\n    const CFileItem &file = Files[i];\r\n    bool emptyStream = !file.HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      FileIndexToFolderIndexMap.Add(kNumNoIndex);\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      // v3.13 incorrectly worked with empty folders\r\n      // v4.07: Loop for skipping empty folders\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= Folders.Size())\r\n          ThrowIncorrect();\r\n        FolderStartFileIndex.Add(i); // check it\r\n        if (NumUnPackStreamsVector[folderIndex] != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    FileIndexToFolderIndexMap.Add(folderIndex);\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= NumUnPackStreamsVector[folderIndex])\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &database\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  database.Clear();\r\n  database.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n\r\n  database.ArchiveInfo.Version.Major = _header[6];\r\n  database.ArchiveInfo.Version.Minor = _header[7];\r\n\r\n  if (database.ArchiveInfo.Version.Major != kMajorVersion)\r\n    ThrowUnsupportedVersion();\r\n\r\n  UInt32 crcFromArchive = GetUInt32FromMem(_header + 8);\r\n  UInt64 nextHeaderOffset = GetUInt64FromMem(_header + 0xC);\r\n  UInt64 nextHeaderSize = GetUInt64FromMem(_header + 0x14);\r\n  UInt32 nextHeaderCRC =  GetUInt32FromMem(_header + 0x1C);\r\n  UInt32 crc = CrcCalc(_header + 0xC, 20);\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)\r\n  {\r\n    UInt64 cur, cur2;\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));\r\n    const int kCheckSize = 500;\r\n    Byte buf[kCheckSize];\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));\r\n    int checkSize = kCheckSize;\r\n    if (cur2 - cur < kCheckSize)\r\n      checkSize = (int)(cur2 - cur);\r\n    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));\r\n    \r\n    UInt32 realProcessedSize;\r\n    RINOK(_stream->Read(buf, (UInt32)kCheckSize, &realProcessedSize));\r\n\r\n    int i;\r\n    for (i = (int)realProcessedSize - 2; i >= 0; i--)\r\n      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)\r\n        break;\r\n    if (i < 0)\r\n      return S_FALSE;\r\n    nextHeaderSize = realProcessedSize - i;\r\n    nextHeaderOffset = cur2 - cur + i;\r\n    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);\r\n    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));\r\n  }\r\n  #endif\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  crcFromArchive = crc;\r\n  #endif\r\n\r\n  database.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;\r\n\r\n  if (crc != crcFromArchive)\r\n    ThrowIncorrect();\r\n\r\n  if (nextHeaderSize == 0)\r\n    return S_OK;\r\n\r\n  if (nextHeaderSize > (UInt64)0xFFFFFFFF)\r\n    return S_FALSE;\r\n\r\n  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));\r\n\r\n  CByteBuffer buffer2;\r\n  buffer2.SetCapacity((size_t)nextHeaderSize);\r\n\r\n  UInt32 realProcessedSize;\r\n  RINOK(_stream->Read(buffer2, (UInt32)nextHeaderSize, &realProcessedSize));\r\n  if (realProcessedSize != (UInt32)nextHeaderSize)\r\n    return S_FALSE;\r\n  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)\r\n    ThrowIncorrect();\r\n  \r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, buffer2);\r\n  \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kHeader)\r\n      break;\r\n    if (type != NID::kEncodedHeader)\r\n      ThrowIncorrect();\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        database.ArchiveInfo.StartPositionAfterHeader, \r\n        database.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    if (dataVector.Size() == 0)\r\n      return S_OK;\r\n    if (dataVector.Size() > 1)\r\n      ThrowIncorrect();\r\n    streamSwitch.Remove();\r\n    streamSwitch.Set(this, dataVector.Front());\r\n  }\r\n\r\n  return ReadHeader(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    database\r\n    #ifndef _NO_CRYPTO\r\n    , getTextPassword\r\n    #endif\r\n    );\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &database\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  try\r\n  {\r\n    return ReadDatabase2(\r\n      EXTERNAL_CODECS_LOC_VARS database\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword\r\n      #endif\r\n      );\r\n  }\r\n  catch(CInArchiveException &) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zIn.h",
    "content": "// 7zIn.h\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/InBuffer.h\"\r\n\r\n#include \"7zItem.h\"\r\n \r\nnamespace NArchive {\r\nnamespace N7z {\r\n  \r\nstruct CInArchiveInfo\r\n{\r\n  CArchiveVersion Version;\r\n  UInt64 StartPosition;\r\n  UInt64 StartPositionAfterHeader;\r\n  UInt64 DataStartPosition;\r\n  UInt64 DataStartPosition2;\r\n  CRecordVector<UInt64> FileInfoPopIDs;\r\n  void Clear()\r\n  {\r\n    FileInfoPopIDs.Clear();\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabaseEx: public CArchiveDatabase\r\n{\r\n  CInArchiveInfo ArchiveInfo;\r\n  CRecordVector<UInt64> PackStreamStartPositions;\r\n  CRecordVector<CNum> FolderStartPackStreamIndex;\r\n  CRecordVector<CNum> FolderStartFileIndex;\r\n  CRecordVector<CNum> FileIndexToFolderIndexMap;\r\n\r\n  void Clear()\r\n  {\r\n    CArchiveDatabase::Clear();\r\n    ArchiveInfo.Clear();\r\n    PackStreamStartPositions.Clear();\r\n    FolderStartPackStreamIndex.Clear();\r\n    FolderStartFileIndex.Clear();\r\n    FileIndexToFolderIndexMap.Clear();\r\n  }\r\n\r\n  void FillFolderStartPackStream();\r\n  void FillStartPos();\r\n  void FillFolderStartFileIndex();\r\n\r\n  void Fill()\r\n  {\r\n    FillFolderStartPackStream();\r\n    FillStartPos();\r\n    FillFolderStartFileIndex();\r\n  }\r\n  \r\n  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const\r\n  {\r\n    return ArchiveInfo.DataStartPosition +\r\n        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n  }\r\n  \r\n  UInt64 GetFolderFullPackSize(int folderIndex) const \r\n  {\r\n    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];\r\n    const CFolder &folder = Folders[folderIndex];\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < folder.PackStreams.Size(); i++)\r\n      size += PackSizes[packStreamIndex + i];\r\n    return size;\r\n  }\r\n  \r\n  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n  {\r\n    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n  }\r\n\r\n  UInt64 GetFilePackSize(CNum fileIndex) const\r\n  {\r\n    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n    if (folderIndex != kNumNoIndex)\r\n      if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n        return GetFolderFullPackSize(folderIndex);\r\n    return 0;\r\n  }\r\n};\r\n\r\nclass CInByte2\r\n{\r\n  const Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  void Init(const Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  Byte ReadByte();\r\n  void ReadBytes(Byte *data, size_t size);\r\n  void SkeepData(UInt64 size);\r\n  void SkeepData();\r\n  UInt64 ReadNumber();\r\n  CNum ReadNum();\r\n  UInt32 ReadUInt32();\r\n  UInt64 ReadUInt64();\r\n  void ReadString(UString &s);\r\n};\r\n\r\nclass CStreamSwitch;\r\n\r\nconst UInt32 kHeaderSize = 32;\r\n\r\nclass CInArchive\r\n{\r\n  friend class CStreamSwitch;\r\n\r\n  CMyComPtr<IInStream> _stream;\r\n\r\n  CObjectVector<CInByte2> _inByteVector;\r\n  CInByte2 *_inByteBack;\r\n \r\n  UInt64 _arhiveBeginStreamPosition;\r\n\r\n  Byte _header[kHeaderSize];\r\n\r\n  void AddByteStream(const Byte *buffer, size_t size)\r\n  {\r\n    _inByteVector.Add(CInByte2());\r\n    _inByteBack = &_inByteVector.Back();\r\n    _inByteBack->Init(buffer, size);\r\n  }\r\n  \r\n  void DeleteByteStream()\r\n  {\r\n    _inByteVector.DeleteBack();\r\n    if (!_inByteVector.IsEmpty())\r\n      _inByteBack = &_inByteVector.Back();\r\n  }\r\n\r\nprivate:\r\n  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);\r\n  \r\n  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }\r\n  Byte ReadByte() { return _inByteBack->ReadByte(); }\r\n  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }\r\n  CNum ReadNum() { return _inByteBack->ReadNum(); }\r\n  UInt64 ReadID() { return _inByteBack->ReadNumber(); }\r\n  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }\r\n  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }\r\n  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }\r\n  void SkeepData() { _inByteBack->SkeepData(); }\r\n  void WaitAttribute(UInt64 attribute);\r\n\r\n  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);\r\n  void GetNextFolderItem(CFolder &itemInfo);\r\n  void ReadHashDigests(int numItems,\r\n      CRecordVector<bool> &digestsDefined, CRecordVector<UInt32> &digests);\r\n  \r\n  void ReadPackInfo(\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CRecordVector<bool> &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs);\r\n  \r\n  void ReadUnPackInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      CObjectVector<CFolder> &folders);\r\n  \r\n  void ReadSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      CRecordVector<UInt64> &unPackSizes,\r\n      CRecordVector<bool> &digestsDefined, \r\n      CRecordVector<UInt32> &digests);\r\n\r\n  void ReadStreamsInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CRecordVector<bool> &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs,\r\n      CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      CRecordVector<UInt64> &unPackSizes,\r\n      CRecordVector<bool> &digestsDefined, \r\n      CRecordVector<UInt32> &digests);\r\n\r\n\r\n  void ReadBoolVector(int numItems, CBoolVector &v);\r\n  void ReadBoolVector2(int numItems, CBoolVector &v);\r\n  void ReadTime(const CObjectVector<CByteBuffer> &dataVector,\r\n      CObjectVector<CFileItem> &files, UInt32 type);\r\n  HRESULT ReadAndDecodePackedStreams(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      UInt64 baseOffset, UInt64 &dataOffset,\r\n      CObjectVector<CByteBuffer> &dataVector\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\n  HRESULT ReadHeader(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &database\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\n  HRESULT ReadDatabase2(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &database \r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\npublic:\r\n  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive\r\n  void Close();\r\n\r\n  HRESULT ReadDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &database \r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\n};\r\n  \r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zItem.h",
    "content": "// 7zItem.h\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../Common/MethodId.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\ntypedef UInt32 CNum;\r\nconst CNum kNumMax     = 0x7FFFFFFF;\r\nconst CNum kNumNoIndex = 0xFFFFFFFF;\r\n\r\nstruct CCoderInfo\r\n{\r\n  CMethodId MethodID;\r\n  CByteBuffer Properties;\r\n  CNum NumInStreams;\r\n  CNum NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBindPair\r\n{\r\n  CNum InIndex;\r\n  CNum OutIndex;\r\n};\r\n\r\nstruct CFolder\r\n{\r\n  CObjectVector<CCoderInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<CNum> PackStreams;\r\n  CRecordVector<UInt64> UnPackSizes;\r\n  UInt32 UnPackCRC;\r\n  bool UnPackCRCDefined;\r\n\r\n  CFolder(): UnPackCRCDefined(false) {}\r\n\r\n  UInt64 GetUnPackSize() const // test it\r\n  { \r\n    if (UnPackSizes.IsEmpty())\r\n      return 0;\r\n    for (int i = UnPackSizes.Size() - 1; i >= 0; i--)\r\n      if (FindBindPairForOutStream(i) < 0)\r\n        return UnPackSizes[i];\r\n    throw 1;\r\n  }\r\n\r\n  CNum GetNumOutStreams() const\r\n  {\r\n    CNum result = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n      result += Coders[i].NumOutStreams;\r\n    return result;\r\n  }\r\n\r\n  int FindBindPairForInStream(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBindPairForOutStream(CNum outStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindPackStreamArrayIndex(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < PackStreams.Size(); i++)\r\n      if (PackStreams[i] == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n};\r\n\r\ntypedef FILETIME CArchiveFileTime;\r\n\r\nclass CFileItem\r\n{\r\npublic:\r\n  CArchiveFileTime CreationTime;\r\n  CArchiveFileTime LastWriteTime;\r\n  CArchiveFileTime LastAccessTime;\r\n  UInt64 UnPackSize;\r\n  UInt64 StartPos;\r\n  UInt32 Attributes;\r\n  UInt32 FileCRC;\r\n  UString Name;\r\n\r\n  bool HasStream; // Test it !!! it means that there is \r\n                  // stream in some folder. It can be empty stream\r\n  bool IsDirectory;\r\n  bool IsAnti;\r\n  bool IsFileCRCDefined;\r\n  bool AreAttributesDefined;\r\n  bool IsCreationTimeDefined;\r\n  bool IsLastWriteTimeDefined;\r\n  bool IsLastAccessTimeDefined;\r\n  bool IsStartPosDefined;\r\n\r\n  /*\r\n  const bool HasStream() const { \r\n      return !IsDirectory && !IsAnti && UnPackSize != 0; }\r\n  */\r\n  CFileItem(): \r\n    HasStream(true),\r\n    IsDirectory(false),\r\n    IsAnti(false),\r\n    IsFileCRCDefined(false),\r\n    AreAttributesDefined(false), \r\n    IsCreationTimeDefined(false), \r\n    IsLastWriteTimeDefined(false), \r\n    IsLastAccessTimeDefined(false),\r\n    IsStartPosDefined(false)\r\n      {}\r\n  void SetAttributes(UInt32 attributes) \r\n  { \r\n    AreAttributesDefined = true;\r\n    Attributes = attributes;\r\n  }\r\n  void SetCreationTime(const CArchiveFileTime &creationTime) \r\n  { \r\n    IsCreationTimeDefined = true;\r\n    CreationTime = creationTime;\r\n  }\r\n  void SetLastWriteTime(const CArchiveFileTime &lastWriteTime) \r\n  {\r\n    IsLastWriteTimeDefined = true;\r\n    LastWriteTime = lastWriteTime;\r\n  }\r\n  void SetLastAccessTime(const CArchiveFileTime &lastAccessTime) \r\n  { \r\n    IsLastAccessTimeDefined = true;\r\n    LastAccessTime = lastAccessTime;\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabase\r\n{\r\n  CRecordVector<UInt64> PackSizes;\r\n  CRecordVector<bool> PackCRCsDefined;\r\n  CRecordVector<UInt32> PackCRCs;\r\n  CObjectVector<CFolder> Folders;\r\n  CRecordVector<CNum> NumUnPackStreamsVector;\r\n  CObjectVector<CFileItem> Files;\r\n  void Clear()\r\n  {\r\n    PackSizes.Clear();\r\n    PackCRCsDefined.Clear();\r\n    PackCRCs.Clear();\r\n    Folders.Clear();\r\n    NumUnPackStreamsVector.Clear();\r\n    Files.Clear();\r\n  }\r\n  bool IsEmpty() const\r\n  {\r\n    return (PackSizes.IsEmpty() && \r\n      PackCRCsDefined.IsEmpty() && \r\n      PackCRCs.IsEmpty() && \r\n      Folders.IsEmpty() && \r\n      NumUnPackStreamsVector.IsEmpty() && \r\n      Files.IsEmpty());\r\n  }\r\n  bool IsSolid() const\r\n  {\r\n    for (int i = 0; i < NumUnPackStreamsVector.Size(); i++)\r\n      if (NumUnPackStreamsVector[i] > 1)\r\n        return true;\r\n    return false;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zOut.cpp",
    "content": "// 7zOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/AutoPtr.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zOut.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nstatic HRESULT WriteBytes(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size > 0)\r\n  {\r\n    UInt32 curSize = (UInt32)MyMin(size, (size_t)0xFFFFFFFF);\r\n    UInt32 processedSize;\r\n    RINOK(stream->Write(data, curSize, &processedSize));\r\n    if(processedSize == 0)\r\n      return E_FAIL;\r\n    data = (const void *)((const Byte *)data + processedSize);\r\n    size -= processedSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nHRESULT COutArchive::WriteDirect(const void *data, UInt32 size)\r\n{\r\n  return ::WriteBytes(SeqStream, data, size);\r\n}\r\n\r\nUInt32 CrcUpdateUInt32(UInt32 crc, UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++, value >>= 8)\r\n    crc = CRC_UPDATE_BYTE(crc, (Byte)value);\r\n  return crc;\r\n}\r\n\r\nUInt32 CrcUpdateUInt64(UInt32 crc, UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++, value >>= 8)\r\n    crc = CRC_UPDATE_BYTE(crc, (Byte)value);\r\n  return crc;\r\n}\r\n\r\nHRESULT COutArchive::WriteDirectUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    RINOK(WriteDirectByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteDirectUInt64(UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    RINOK(WriteDirectByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteSignature()\r\n{\r\n  RINOK(WriteDirect(kSignature, kSignatureSize));\r\n  RINOK(WriteDirectByte(kMajorVersion));\r\n  return WriteDirectByte(2);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishSignature()\r\n{\r\n  RINOK(WriteDirect(kFinishSignature, kSignatureSize));\r\n  CArchiveVersion av;\r\n  av.Major = kMajorVersion;\r\n  av.Minor = 2;\r\n  RINOK(WriteDirectByte(av.Major));\r\n  return WriteDirectByte(av.Minor);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::WriteStartHeader(const CStartHeader &h)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;\r\n  crc = CrcUpdateUInt64(crc, h.NextHeaderOffset);\r\n  crc = CrcUpdateUInt64(crc, h.NextHeaderSize);\r\n  crc = CrcUpdateUInt32(crc, h.NextHeaderCRC);\r\n  RINOK(WriteDirectUInt32(CRC_GET_DIGEST(crc)));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  return WriteDirectUInt32(h.NextHeaderCRC);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)\r\n{\r\n  CCRC crc;\r\n  crc.UpdateUInt64(h.NextHeaderOffset);\r\n  crc.UpdateUInt64(h.NextHeaderSize);\r\n  crc.UpdateUInt32(h.NextHeaderCRC);\r\n  crc.UpdateUInt64(h.ArchiveStartOffset);\r\n  crc.UpdateUInt64(h.AdditionalStartBlockSize);\r\n  RINOK(WriteDirectUInt32(crc.GetDigest()));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  RINOK(WriteDirectUInt32(h.NextHeaderCRC));\r\n  RINOK(WriteDirectUInt64(h.ArchiveStartOffset));\r\n  return WriteDirectUInt64(h.AdditionalStartBlockSize);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)\r\n{\r\n  Close();\r\n  #ifdef _7Z_VOL\r\n  // endMarker = false;\r\n  _endMarker = endMarker;\r\n  #endif\r\n  SeqStream = stream;\r\n  if (!endMarker)\r\n  {\r\n    SeqStream.QueryInterface(IID_IOutStream, &Stream);\r\n    if (!Stream)\r\n    {\r\n      return E_NOTIMPL;\r\n      // endMarker = true;\r\n    }\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (endMarker)\r\n  {\r\n    /*\r\n    CStartHeader sh;\r\n    sh.NextHeaderOffset = (UInt32)(Int32)-1;\r\n    sh.NextHeaderSize = (UInt32)(Int32)-1;\r\n    sh.NextHeaderCRC = 0;\r\n    WriteStartHeader(sh);\r\n    */\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!Stream)\r\n      return E_FAIL;\r\n    RINOK(WriteSignature());\r\n    RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutArchive::Close()\r\n{\r\n  SeqStream.Release();\r\n  Stream.Release();\r\n}\r\n\r\nHRESULT COutArchive::SkeepPrefixArchiveHeader()\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n    return S_OK;\r\n  #endif\r\n  return Stream->Seek(24, STREAM_SEEK_CUR, NULL);\r\n}\r\n\r\nHRESULT COutArchive::WriteBytes(const void *data, size_t size)\r\n{\r\n  if (_mainMode)\r\n  {\r\n    if (_dynamicMode)\r\n      _dynamicBuffer.Write(data, size);\r\n    else\r\n      _outByte.WriteBytes(data, size);\r\n    _crc = CrcUpdate(_crc, data, size);\r\n  }\r\n  else\r\n  {\r\n    if (_countMode)\r\n      _countSize += size;\r\n    else\r\n      RINOK(_outByte2.Write(data, size));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteBytes(const CByteBuffer &data)\r\n{\r\n  return WriteBytes(data, data.GetCapacity());\r\n}\r\n\r\nHRESULT COutArchive::WriteByte(Byte b)\r\n{\r\n  return WriteBytes(&b, 1);\r\n}\r\n\r\nHRESULT COutArchive::WriteUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    RINOK(WriteByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteNumber(UInt64 value)\r\n{\r\n  Byte firstByte = 0;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n    {\r\n      firstByte |= Byte(value >> (8 * i));\r\n      break;\r\n    }\r\n    firstByte |= mask;\r\n    mask >>= 1;\r\n  }\r\n  RINOK(WriteByte(firstByte));\r\n  for (;i > 0; i--)\r\n  {\r\n    RINOK(WriteByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nstatic UInt32 GetBigNumberSize(UInt64 value)\r\n{\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n      break;\r\n  return 1 + i;\r\n}\r\n\r\nUInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)\r\n{\r\n  UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;\r\n  if (nameLength != 0)\r\n  {\r\n    nameLength = (nameLength + 1) * 2;\r\n    result += nameLength + GetBigNumberSize(nameLength) + 2;\r\n  }\r\n  if (props)\r\n  {\r\n    result += 20;\r\n  }\r\n  if (result >= 128)\r\n    result++;\r\n  result += kSignatureSize + 2 + kFinishHeaderSize;\r\n  return result;\r\n}\r\n\r\nUInt64 COutArchive::GetVolPureSize(UInt64 volSize, int nameLength, bool props)\r\n{\r\n  UInt32 headersSizeBase = COutArchive::GetVolHeadersSize(1, nameLength, props);\r\n  int testSize;\r\n  if (volSize > headersSizeBase)\r\n    testSize = volSize - headersSizeBase;\r\n  else\r\n    testSize = 1;\r\n  UInt32 headersSize = COutArchive::GetVolHeadersSize(testSize, nameLength, props);\r\n  UInt64 pureSize = 1;\r\n  if (volSize > headersSize)\r\n    pureSize = volSize - headersSize;\r\n  return pureSize;\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::WriteFolder(const CFolder &folder)\r\n{\r\n  RINOK(WriteNumber(folder.Coders.Size()));\r\n  int i;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    const CCoderInfo &coder = folder.Coders[i];\r\n    {\r\n      size_t propertiesSize = coder.Properties.GetCapacity();\r\n      \r\n      UInt64 id = coder.MethodID; \r\n      int idSize;\r\n      for (idSize = 1; idSize < sizeof(id); idSize++)\r\n        if ((id >> (8 * idSize)) == 0)\r\n          break;\r\n      BYTE longID[15];\r\n      for (int t = idSize - 1; t >= 0 ; t--, id >>= 8)\r\n        longID[t] = (Byte)(id & 0xFF);\r\n      Byte b;\r\n      b = (Byte)(idSize & 0xF);\r\n      bool isComplex = !coder.IsSimpleCoder();\r\n      b |= (isComplex ? 0x10 : 0);\r\n      b |= ((propertiesSize != 0) ? 0x20 : 0 );\r\n      RINOK(WriteByte(b));\r\n      RINOK(WriteBytes(longID, idSize));\r\n      if (isComplex)\r\n      {\r\n        RINOK(WriteNumber(coder.NumInStreams));\r\n        RINOK(WriteNumber(coder.NumOutStreams));\r\n      }\r\n      if (propertiesSize == 0)\r\n        continue;\r\n      RINOK(WriteNumber(propertiesSize));\r\n      RINOK(WriteBytes(coder.Properties, propertiesSize));\r\n    }\r\n  }\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = folder.BindPairs[i];\r\n    RINOK(WriteNumber(bindPair.InIndex));\r\n    RINOK(WriteNumber(bindPair.OutIndex));\r\n  }\r\n  if (folder.PackStreams.Size() > 1)\r\n    for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    {\r\n      RINOK(WriteNumber(folder.PackStreams[i]));\r\n    }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteBoolVector(const CBoolVector &boolVector)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0x80;\r\n  for(int i = 0; i < boolVector.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n      b |= mask;\r\n    mask >>= 1;\r\n    if (mask == 0)\r\n    {\r\n      RINOK(WriteByte(b));\r\n      mask = 0x80;\r\n      b = 0;\r\n    }\r\n  }\r\n  if (mask != 0x80)\r\n  {\r\n    RINOK(WriteByte(b));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nHRESULT COutArchive::WriteHashDigests(\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  int numDefined = 0;\r\n  int i;\r\n  for(i = 0; i < digestsDefined.Size(); i++)\r\n    if (digestsDefined[i])\r\n      numDefined++;\r\n  if (numDefined == 0)\r\n    return S_OK;\r\n\r\n  RINOK(WriteByte(NID::kCRC));\r\n  if (numDefined == digestsDefined.Size())\r\n  {\r\n    RINOK(WriteByte(1));\r\n  }\r\n  else\r\n  {\r\n    RINOK(WriteByte(0));\r\n    RINOK(WriteBoolVector(digestsDefined));\r\n  }\r\n  for(i = 0; i < digests.Size(); i++)\r\n  {\r\n    if(digestsDefined[i])\r\n      RINOK(WriteUInt32(digests[i]));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WritePackInfo(\r\n    UInt64 dataOffset,\r\n    const CRecordVector<UInt64> &packSizes,\r\n    const CRecordVector<bool> &packCRCsDefined,\r\n    const CRecordVector<UInt32> &packCRCs)\r\n{\r\n  if (packSizes.IsEmpty())\r\n    return S_OK;\r\n  RINOK(WriteByte(NID::kPackInfo));\r\n  RINOK(WriteNumber(dataOffset));\r\n  RINOK(WriteNumber(packSizes.Size()));\r\n  RINOK(WriteByte(NID::kSize));\r\n  for(int i = 0; i < packSizes.Size(); i++)\r\n    RINOK(WriteNumber(packSizes[i]));\r\n\r\n  RINOK(WriteHashDigests(packCRCsDefined, packCRCs));\r\n  \r\n  return WriteByte(NID::kEnd);\r\n}\r\n\r\nHRESULT COutArchive::WriteUnPackInfo(const CObjectVector<CFolder> &folders)\r\n{\r\n  if (folders.IsEmpty())\r\n    return S_OK;\r\n\r\n  RINOK(WriteByte(NID::kUnPackInfo));\r\n\r\n  RINOK(WriteByte(NID::kFolder));\r\n  RINOK(WriteNumber(folders.Size()));\r\n  {\r\n    RINOK(WriteByte(0));\r\n    for(int i = 0; i < folders.Size(); i++)\r\n      RINOK(WriteFolder(folders[i]));\r\n  }\r\n  \r\n  RINOK(WriteByte(NID::kCodersUnPackSize));\r\n  int i;\r\n  for(i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    for (int j = 0; j < folder.UnPackSizes.Size(); j++)\r\n      RINOK(WriteNumber(folder.UnPackSizes[j]));\r\n  }\r\n\r\n  CRecordVector<bool> unPackCRCsDefined;\r\n  CRecordVector<UInt32> unPackCRCs;\r\n  for(i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    unPackCRCsDefined.Add(folder.UnPackCRCDefined);\r\n    unPackCRCs.Add(folder.UnPackCRC);\r\n  }\r\n  RINOK(WriteHashDigests(unPackCRCsDefined, unPackCRCs));\r\n\r\n  return WriteByte(NID::kEnd);\r\n}\r\n\r\nHRESULT COutArchive::WriteSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    const CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n    const CRecordVector<UInt64> &unPackSizes,\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  RINOK(WriteByte(NID::kSubStreamsInfo));\r\n\r\n  int i;\r\n  for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n  {\r\n    if (numUnPackStreamsInFolders[i] != 1)\r\n    {\r\n      RINOK(WriteByte(NID::kNumUnPackStream));\r\n      for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n        RINOK(WriteNumber(numUnPackStreamsInFolders[i]));\r\n      break;\r\n    }\r\n  }\r\n \r\n\r\n  bool needFlag = true;\r\n  CNum index = 0;\r\n  for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n    for (CNum j = 0; j < numUnPackStreamsInFolders[i]; j++)\r\n    {\r\n      if (j + 1 != numUnPackStreamsInFolders[i])\r\n      {\r\n        if (needFlag)\r\n          RINOK(WriteByte(NID::kSize));\r\n        needFlag = false;\r\n        RINOK(WriteNumber(unPackSizes[index]));\r\n      }\r\n      index++;\r\n    }\r\n\r\n  CRecordVector<bool> digestsDefined2;\r\n  CRecordVector<UInt32> digests2;\r\n\r\n  int digestIndex = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    int numSubStreams = (int)numUnPackStreamsInFolders[i];\r\n    if (numSubStreams == 1 && folders[i].UnPackCRCDefined)\r\n      digestIndex++;\r\n    else\r\n      for (int j = 0; j < numSubStreams; j++, digestIndex++)\r\n      {\r\n        digestsDefined2.Add(digestsDefined[digestIndex]);\r\n        digests2.Add(digests[digestIndex]);\r\n      }\r\n  }\r\n  RINOK(WriteHashDigests(digestsDefined2, digests2));\r\n  return WriteByte(NID::kEnd);\r\n}\r\n\r\nHRESULT COutArchive::WriteTime(\r\n    const CObjectVector<CFileItem> &files, Byte type)\r\n{\r\n  /////////////////////////////////////////////////\r\n  // CreationTime\r\n  CBoolVector boolVector;\r\n  boolVector.Reserve(files.Size());\r\n  bool thereAreDefined = false;\r\n  bool allDefined = true;\r\n  int i;\r\n  for(i = 0; i < files.Size(); i++)\r\n  {\r\n    const CFileItem &item = files[i];\r\n    bool defined;\r\n    switch(type)\r\n    {\r\n      case NID::kCreationTime:\r\n        defined = item.IsCreationTimeDefined;\r\n        break;\r\n      case NID::kLastWriteTime:\r\n        defined = item.IsLastWriteTimeDefined;\r\n        break;\r\n      case NID::kLastAccessTime:\r\n        defined = item.IsLastAccessTimeDefined;\r\n        break;\r\n      default:\r\n        throw 1;\r\n    }\r\n    boolVector.Add(defined);\r\n    thereAreDefined = (thereAreDefined || defined);\r\n    allDefined = (allDefined && defined);\r\n  }\r\n  if (!thereAreDefined)\r\n    return S_OK;\r\n  RINOK(WriteByte(type));\r\n  size_t dataSize = 1 + 1;\r\n    dataSize += files.Size() * 8;\r\n  if (allDefined)\r\n  {\r\n    RINOK(WriteNumber(dataSize));\r\n    WriteByte(1);\r\n  }\r\n  else\r\n  {\r\n    RINOK(WriteNumber(1 + (boolVector.Size() + 7) / 8 + dataSize));\r\n    WriteByte(0);\r\n    RINOK(WriteBoolVector(boolVector));\r\n  }\r\n  RINOK(WriteByte(0));\r\n  for(i = 0; i < files.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n    {\r\n      const CFileItem &item = files[i];\r\n      CArchiveFileTime timeValue;\r\n      timeValue.dwLowDateTime = 0;\r\n      timeValue.dwHighDateTime = 0;\r\n      switch(type)\r\n      {\r\n        case NID::kCreationTime:\r\n          timeValue = item.CreationTime;\r\n          break;\r\n        case NID::kLastWriteTime:\r\n          timeValue = item.LastWriteTime;\r\n          break;\r\n        case NID::kLastAccessTime:\r\n          timeValue = item.LastAccessTime;\r\n          break;\r\n      }\r\n      RINOK(WriteUInt32(timeValue.dwLowDateTime));\r\n      RINOK(WriteUInt32(timeValue.dwHighDateTime));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const Byte *data, size_t dataSize,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  CSequentialInStreamImp *streamSpec = new CSequentialInStreamImp;\r\n  CMyComPtr<ISequentialInStream> stream = streamSpec;\r\n  streamSpec->Init(data, dataSize);\r\n  CFolder folderItem;\r\n  folderItem.UnPackCRCDefined = true;\r\n  folderItem.UnPackCRC = CrcCalc(data, dataSize);\r\n  UInt64 dataSize64 = dataSize;\r\n  RINOK(encoder.Encode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      stream, NULL, &dataSize64, folderItem, SeqStream, packSizes, NULL))\r\n  folders.Add(folderItem);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const CByteBuffer &data, \r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  return EncodeStream(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      encoder, data, data.GetCapacity(), packSizes, folders);\r\n}\r\n\r\nstatic void WriteUInt32ToBuffer(Byte *data, UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    *data++ = (Byte)value;\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nstatic void WriteUInt64ToBuffer(Byte *data, UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    *data++ = (Byte)value;\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\n\r\nHRESULT COutArchive::WriteHeader(\r\n    const CArchiveDatabase &database,\r\n    const CHeaderOptions &headerOptions,\r\n    UInt64 &headerOffset)\r\n{\r\n  int i;\r\n  \r\n  /////////////////////////////////\r\n  // Names\r\n\r\n  CNum numDefinedNames = 0;\r\n  size_t namesDataSize = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n  {\r\n    const UString &name = database.Files[i].Name;\r\n    if (!name.IsEmpty())\r\n      numDefinedNames++;\r\n    namesDataSize += (name.Length() + 1) * 2;\r\n  }\r\n\r\n  CByteBuffer namesData;\r\n  if (numDefinedNames > 0)\r\n  {\r\n    namesData.SetCapacity((size_t)namesDataSize);\r\n    size_t pos = 0;\r\n    for(int i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const UString &name = database.Files[i].Name;\r\n      for (int t = 0; t < name.Length(); t++)\r\n      {\r\n        wchar_t c = name[t];\r\n        namesData[pos++] = Byte(c);\r\n        namesData[pos++] = Byte(c >> 8);\r\n      }\r\n      namesData[pos++] = 0;\r\n      namesData[pos++] = 0;\r\n    }\r\n  }\r\n\r\n  /////////////////////////////////\r\n  // Write Attributes\r\n  CBoolVector attributesBoolVector;\r\n  attributesBoolVector.Reserve(database.Files.Size());\r\n  int numDefinedAttributes = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n  {\r\n    bool defined = database.Files[i].AreAttributesDefined;\r\n    attributesBoolVector.Add(defined);\r\n    if (defined)\r\n      numDefinedAttributes++;\r\n  }\r\n\r\n  CByteBuffer attributesData;\r\n  if (numDefinedAttributes > 0)\r\n  {\r\n    attributesData.SetCapacity(numDefinedAttributes * 4);\r\n    size_t pos = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (file.AreAttributesDefined)\r\n      {\r\n        WriteUInt32ToBuffer(attributesData + pos, file.Attributes);\r\n        pos += 4;\r\n      }\r\n    }\r\n  }\r\n\r\n  /////////////////////////////////\r\n  // Write StartPos\r\n  CBoolVector startsBoolVector;\r\n  startsBoolVector.Reserve(database.Files.Size());\r\n  int numDefinedStarts = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n  {\r\n    bool defined = database.Files[i].IsStartPosDefined;\r\n    startsBoolVector.Add(defined);\r\n    if (defined)\r\n      numDefinedStarts++;\r\n  }\r\n\r\n  CByteBuffer startsData;\r\n  if (numDefinedStarts > 0)\r\n  {\r\n    startsData.SetCapacity(numDefinedStarts * 8);\r\n    size_t pos = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (file.IsStartPosDefined)\r\n      {\r\n        WriteUInt64ToBuffer(startsData + pos, file.StartPos);\r\n        pos += 8;\r\n      }\r\n    }\r\n  }\r\n  \r\n  /////////////////////////////////\r\n  // Write Last Write Time\r\n  // /*\r\n  CNum numDefinedLastWriteTimes = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n    if (database.Files[i].IsLastWriteTimeDefined)\r\n      numDefinedLastWriteTimes++;\r\n\r\n  if (numDefinedLastWriteTimes > 0)\r\n  {\r\n    CByteBuffer lastWriteTimeData;\r\n    lastWriteTimeData.SetCapacity(numDefinedLastWriteTimes * 8);\r\n    size_t pos = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (file.IsLastWriteTimeDefined)\r\n      {\r\n        WriteUInt32ToBuffer(lastWriteTimeData + pos, file.LastWriteTime.dwLowDateTime);\r\n        pos += 4;\r\n        WriteUInt32ToBuffer(lastWriteTimeData + pos, file.LastWriteTime.dwHighDateTime);\r\n        pos += 4;\r\n      }\r\n    }\r\n  }\r\n  // */\r\n  \r\n\r\n  UInt64 packedSize = 0;\r\n  for(i = 0; i < database.PackSizes.Size(); i++)\r\n    packedSize += database.PackSizes[i];\r\n\r\n  headerOffset = packedSize;\r\n\r\n  _mainMode = true;\r\n\r\n  _outByte.SetStream(SeqStream);\r\n  _outByte.Init();\r\n  _crc = CRC_INIT_VAL;\r\n\r\n\r\n  RINOK(WriteByte(NID::kHeader));\r\n\r\n  // Archive Properties\r\n\r\n  if (database.Folders.Size() > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kMainStreamsInfo));\r\n    RINOK(WritePackInfo(0, database.PackSizes, \r\n        database.PackCRCsDefined,\r\n        database.PackCRCs));\r\n\r\n    RINOK(WriteUnPackInfo(database.Folders));\r\n\r\n    CRecordVector<UInt64> unPackSizes;\r\n    CRecordVector<bool> digestsDefined;\r\n    CRecordVector<UInt32> digests;\r\n    for (i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (!file.HasStream)\r\n        continue;\r\n      unPackSizes.Add(file.UnPackSize);\r\n      digestsDefined.Add(file.IsFileCRCDefined);\r\n      digests.Add(file.FileCRC);\r\n    }\r\n\r\n    RINOK(WriteSubStreamsInfo(\r\n        database.Folders,\r\n        database.NumUnPackStreamsVector,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests));\r\n    RINOK(WriteByte(NID::kEnd));\r\n  }\r\n\r\n  if (database.Files.IsEmpty())\r\n  {\r\n    RINOK(WriteByte(NID::kEnd));\r\n    return _outByte.Flush();\r\n  }\r\n\r\n  RINOK(WriteByte(NID::kFilesInfo));\r\n  RINOK(WriteNumber(database.Files.Size()));\r\n\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve(database.Files.Size());\r\n  int numEmptyStreams = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n    if (database.Files[i].HasStream)\r\n      emptyStreamVector.Add(false);\r\n    else\r\n    {\r\n      emptyStreamVector.Add(true);\r\n      numEmptyStreams++;\r\n    }\r\n  if (numEmptyStreams > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kEmptyStream));\r\n    RINOK(WriteNumber((emptyStreamVector.Size() + 7) / 8));\r\n    RINOK(WriteBoolVector(emptyStreamVector));\r\n\r\n    CBoolVector emptyFileVector, antiVector;\r\n    emptyFileVector.Reserve(numEmptyStreams);\r\n    antiVector.Reserve(numEmptyStreams);\r\n    CNum numEmptyFiles = 0, numAntiItems = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (!file.HasStream)\r\n      {\r\n        emptyFileVector.Add(!file.IsDirectory);\r\n        if (!file.IsDirectory)\r\n          numEmptyFiles++;\r\n        antiVector.Add(file.IsAnti);\r\n        if (file.IsAnti)\r\n          numAntiItems++;\r\n      }\r\n    }\r\n\r\n    if (numEmptyFiles > 0)\r\n    {\r\n      RINOK(WriteByte(NID::kEmptyFile));\r\n      RINOK(WriteNumber((emptyFileVector.Size() + 7) / 8));\r\n      RINOK(WriteBoolVector(emptyFileVector));\r\n    }\r\n\r\n    if (numAntiItems > 0)\r\n    {\r\n      RINOK(WriteByte(NID::kAnti));\r\n      RINOK(WriteNumber((antiVector.Size() + 7) / 8));\r\n      RINOK(WriteBoolVector(antiVector));\r\n    }\r\n  }\r\n\r\n  if (numDefinedNames > 0)\r\n  {\r\n    /////////////////////////////////////////////////\r\n    RINOK(WriteByte(NID::kName));\r\n    {\r\n      RINOK(WriteNumber(1 + namesData.GetCapacity()));\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBytes(namesData));\r\n    }\r\n\r\n  }\r\n\r\n  if (headerOptions.WriteCreated)\r\n  {\r\n    RINOK(WriteTime(database.Files, NID::kCreationTime));\r\n  }\r\n  if (headerOptions.WriteModified)\r\n  {\r\n    RINOK(WriteTime(database.Files, NID::kLastWriteTime));\r\n  }\r\n  if (headerOptions.WriteAccessed)\r\n  {\r\n    RINOK(WriteTime(database.Files, NID::kLastAccessTime));\r\n  }\r\n\r\n  if (numDefinedAttributes > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kWinAttributes));\r\n    size_t size = 2;\r\n    if (numDefinedAttributes != database.Files.Size())\r\n      size += (attributesBoolVector.Size() + 7) / 8 + 1;\r\n      size += attributesData.GetCapacity();\r\n\r\n    RINOK(WriteNumber(size));\r\n    if (numDefinedAttributes == database.Files.Size())\r\n    {\r\n      RINOK(WriteByte(1));\r\n    }\r\n    else\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBoolVector(attributesBoolVector));\r\n    }\r\n\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBytes(attributesData));\r\n    }\r\n  }\r\n\r\n  if (numDefinedStarts > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kStartPos));\r\n    size_t size = 2;\r\n    if (numDefinedStarts != database.Files.Size())\r\n      size += (startsBoolVector.Size() + 7) / 8 + 1;\r\n      size += startsData.GetCapacity();\r\n\r\n    RINOK(WriteNumber(size));\r\n    if (numDefinedStarts == database.Files.Size())\r\n    {\r\n      RINOK(WriteByte(1));\r\n    }\r\n    else\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBoolVector(startsBoolVector));\r\n    }\r\n\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBytes(startsData));\r\n    }\r\n  }\r\n\r\n  RINOK(WriteByte(NID::kEnd)); // for files\r\n  RINOK(WriteByte(NID::kEnd)); // for headers\r\n\r\n  return _outByte.Flush();\r\n}\r\n\r\nHRESULT COutArchive::WriteDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CArchiveDatabase &database,\r\n    const CCompressionMethodMode *options, \r\n    const CHeaderOptions &headerOptions)\r\n{\r\n  UInt64 headerOffset;\r\n  UInt32 headerCRC;\r\n  UInt64 headerSize;\r\n  if (database.IsEmpty())\r\n  {\r\n    headerSize = 0;\r\n    headerOffset = 0;\r\n    headerCRC = CrcCalc(0, 0);\r\n  }\r\n  else\r\n  {\r\n    _dynamicBuffer.Init();\r\n    _dynamicMode = false;\r\n\r\n    if (options != 0)\r\n      if (options->IsEmpty())\r\n        options = 0;\r\n    if (options != 0)\r\n      if (options->PasswordIsDefined || headerOptions.CompressMainHeader)\r\n        _dynamicMode = true;\r\n    RINOK(WriteHeader(database, headerOptions, headerOffset));\r\n\r\n    if (_dynamicMode)\r\n    {\r\n      CCompressionMethodMode encryptOptions;\r\n      encryptOptions.PasswordIsDefined = options->PasswordIsDefined;\r\n      encryptOptions.Password = options->Password;\r\n      CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions);\r\n      CRecordVector<UInt64> packSizes;\r\n      CObjectVector<CFolder> folders;\r\n      RINOK(EncodeStream(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          encoder, _dynamicBuffer, \r\n          _dynamicBuffer.GetSize(), packSizes, folders));\r\n      _dynamicMode = false;\r\n      _mainMode = true;\r\n      \r\n      _outByte.SetStream(SeqStream);\r\n      _outByte.Init();\r\n      _crc = CRC_INIT_VAL;\r\n      \r\n      if (folders.Size() == 0)\r\n        throw 1;\r\n\r\n      RINOK(WriteID(NID::kEncodedHeader));\r\n      RINOK(WritePackInfo(headerOffset, packSizes, \r\n        CRecordVector<bool>(), CRecordVector<UInt32>()));\r\n      RINOK(WriteUnPackInfo(folders));\r\n      RINOK(WriteByte(NID::kEnd));\r\n      for (int i = 0; i < packSizes.Size(); i++)\r\n        headerOffset += packSizes[i];\r\n      RINOK(_outByte.Flush());\r\n    }\r\n    headerCRC = CRC_GET_DIGEST(_crc);\r\n    headerSize = _outByte.GetProcessedSize();\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n  {\r\n    CFinishHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = \r\n        UInt64(0) - (headerSize + \r\n        4 + kFinishHeaderSize);\r\n    h.ArchiveStartOffset = h.NextHeaderOffset - headerOffset;\r\n    h.AdditionalStartBlockSize = 0;\r\n    RINOK(WriteFinishHeader(h));\r\n    return WriteFinishSignature();\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    CStartHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = headerOffset;\r\n    RINOK(Stream->Seek(_prefixHeaderPos, STREAM_SEEK_SET, NULL));\r\n    return WriteStartHeader(h);\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zOut.h",
    "content": "// 7z/Out.h\r\n\r\n#ifndef __7Z_OUT_H\r\n#define __7Z_OUT_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zCompressionMode.h\"\r\n#include \"7zEncode.h\"\r\n\r\n#include \"../../Common/OutBuffer.h\"\r\n#include \"../../../Common/DynamicBuffer.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CWriteBufferLoc\r\n{\r\n  Byte *_data;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  CWriteBufferLoc(): _size(0), _pos(0) {}\r\n  void Init(Byte *data, size_t size)  \r\n  { \r\n    _pos = 0;\r\n    _data = data;\r\n    _size = size; \r\n  }\r\n  HRESULT Write(const void *data, size_t size)\r\n  {\r\n    if (_pos + size > _size)\r\n      return E_FAIL;\r\n    memmove(_data + _pos, data, size);\r\n    _pos += size;\r\n    return S_OK; \r\n  }\r\n};\r\n\r\nclass CWriteDynamicBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _pos;\r\npublic:\r\n  CWriteDynamicBuffer(): _pos(0) {}\r\n  void Init()  \r\n  { \r\n    _pos = 0;\r\n  }\r\n  void Write(const void *data, size_t size)\r\n  {\r\n    if (_pos + size > _buffer.GetCapacity())\r\n      _buffer.EnsureCapacity(_pos + size);\r\n    memmove(((Byte *)_buffer) +_pos, data, size);\r\n    _pos += size;\r\n  }\r\n  operator Byte *() { return (Byte *)_buffer; };\r\n  operator const Byte *() const { return (const Byte *)_buffer; };\r\n  size_t GetSize() const { return _pos; }\r\n};\r\n\r\nstruct CHeaderOptions\r\n{\r\n  // bool UseAdditionalHeaderStreams;\r\n  bool CompressMainHeader;\r\n  bool WriteModified;\r\n  bool WriteCreated;\r\n  bool WriteAccessed;\r\n\r\n  CHeaderOptions(): \r\n      // UseAdditionalHeaderStreams(false), \r\n      CompressMainHeader(true),\r\n      WriteModified(true),\r\n      WriteCreated(false),\r\n      WriteAccessed(false) {} \r\n};\r\n\r\nclass COutArchive\r\n{\r\n  UInt64 _prefixHeaderPos;\r\n\r\n  HRESULT WriteDirect(const void *data, UInt32 size);\r\n  HRESULT WriteDirectByte(Byte b) { return WriteDirect(&b, 1); }\r\n  HRESULT WriteDirectUInt32(UInt32 value);\r\n  HRESULT WriteDirectUInt64(UInt64 value);\r\n  \r\n  HRESULT WriteBytes(const void *data, size_t size);\r\n  HRESULT WriteBytes(const CByteBuffer &data);\r\n  HRESULT WriteByte(Byte b);\r\n  HRESULT WriteUInt32(UInt32 value);\r\n  HRESULT WriteNumber(UInt64 value);\r\n  HRESULT WriteID(UInt64 value) { return WriteNumber(value); }\r\n\r\n  HRESULT WriteFolder(const CFolder &folder);\r\n  HRESULT WriteFileHeader(const CFileItem &itemInfo);\r\n  HRESULT WriteBoolVector(const CBoolVector &boolVector);\r\n  HRESULT WriteHashDigests(\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  HRESULT WritePackInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs);\r\n\r\n  HRESULT WriteUnPackInfo(const CObjectVector<CFolder> &folders);\r\n\r\n  HRESULT WriteSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unPackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  /*\r\n  HRESULT WriteStreamsInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs,\r\n      bool externalFolders,\r\n      UInt64 externalFoldersStreamIndex,\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unPackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n  */\r\n\r\n\r\n  HRESULT WriteTime(const CObjectVector<CFileItem> &files, Byte type);\r\n\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const Byte *data, size_t dataSize,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const CByteBuffer &data, \r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT WriteHeader(\r\n      const CArchiveDatabase &database,\r\n      const CHeaderOptions &headerOptions,\r\n      UInt64 &headerOffset);\r\n  \r\n  bool _mainMode;\r\n\r\n  bool _dynamicMode;\r\n\r\n  bool _countMode;\r\n  size_t _countSize;\r\n  COutBuffer _outByte;\r\n  CWriteBufferLoc _outByte2;\r\n  CWriteDynamicBuffer _dynamicBuffer;\r\n  UInt32 _crc;\r\n\r\n  #ifdef _7Z_VOL\r\n  bool _endMarker;\r\n  #endif\r\n\r\n  HRESULT WriteSignature();\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishSignature();\r\n  #endif\r\n  HRESULT WriteStartHeader(const CStartHeader &h);\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishHeader(const CFinishHeader &h);\r\n  #endif\r\n  CMyComPtr<IOutStream> Stream;\r\npublic:\r\n\r\n  COutArchive() { _outByte.Create(1 << 16); }\r\n  CMyComPtr<ISequentialOutStream> SeqStream;\r\n  HRESULT Create(ISequentialOutStream *stream, bool endMarker);\r\n  void Close();\r\n  HRESULT SkeepPrefixArchiveHeader();\r\n  HRESULT WriteDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CArchiveDatabase &database,\r\n      const CCompressionMethodMode *options, \r\n      const CHeaderOptions &headerOptions);\r\n\r\n  #ifdef _7Z_VOL\r\n  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);\r\n  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);\r\n  #endif\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zProperties.cpp",
    "content": "// 7zProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zProperties.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zHandler.h\"\r\n\r\n// #define _MULTI_PACK\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CPropMap\r\n{\r\n  UInt64 FilePropID;\r\n  STATPROPSTG StatPROPSTG;\r\n};\r\n\r\nCPropMap kPropMap[] = \r\n{\r\n  { NID::kName, NULL, kpidPath, VT_BSTR},\r\n  { NID::kSize, NULL, kpidSize, VT_UI8},\r\n  { NID::kPackInfo, NULL, kpidPackedSize, VT_UI8},\r\n  \r\n  #ifdef _MULTI_PACK\r\n  { 100, L\"Pack0\", kpidPackedSize0, VT_UI8},\r\n  { 101, L\"Pack1\", kpidPackedSize1, VT_UI8},\r\n  { 102, L\"Pack2\", kpidPackedSize2, VT_UI8},\r\n  { 103, L\"Pack3\", kpidPackedSize3, VT_UI8},\r\n  { 104, L\"Pack4\", kpidPackedSize4, VT_UI8},\r\n  #endif\r\n\r\n  { NID::kCreationTime, NULL, kpidCreationTime, VT_FILETIME},\r\n  { NID::kLastWriteTime, NULL, kpidLastWriteTime, VT_FILETIME},\r\n  { NID::kLastAccessTime, NULL, kpidLastAccessTime, VT_FILETIME},\r\n  { NID::kWinAttributes, NULL, kpidAttributes, VT_UI4},\r\n  { NID::kStartPos, NULL, kpidPosition, VT_UI4},\r\n\r\n  { NID::kCRC, NULL, kpidCRC, VT_UI4},\r\n  \r\n  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},\r\n  // { 97, NULL, kpidSolid, VT_BOOL},\r\n  #ifndef _SFX\r\n  { 98, NULL, kpidMethod, VT_BSTR},\r\n  { 99, NULL, kpidBlock, VT_UI4}\r\n  #endif\r\n};\r\n\r\nstatic const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);\r\n\r\nstatic int FindPropInMap(UInt64 filePropID)\r\n{\r\n  for (int i = 0; i < kPropMapSize; i++)\r\n    if (kPropMap[i].FilePropID == filePropID)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void CopyOneItem(CRecordVector<UInt64> &src, \r\n    CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      dest.Add(item);\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < dest.Size(); i++)\r\n    if (dest[i] == item)\r\n    {\r\n      dest.Delete(i);\r\n      break;\r\n    }\r\n  dest.Insert(0, item);\r\n}\r\n\r\nvoid CHandler::FillPopIDs()\r\n{ \r\n  _fileInfoPopIDs.Clear();\r\n\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() < 1)\r\n    return;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_database = volume.Database;\r\n  #endif\r\n\r\n  CRecordVector<UInt64> fileInfoPopIDs = _database.ArchiveInfo.FileInfoPopIDs;\r\n\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);\r\n\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCreationTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastWriteTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastAccessTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);\r\n  _fileInfoPopIDs += fileInfoPopIDs; \r\n \r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Add(98);\r\n  _fileInfoPopIDs.Add(99);\r\n  #endif\r\n  #ifdef _MULTI_PACK\r\n  _fileInfoPopIDs.Add(100);\r\n  _fileInfoPopIDs.Add(101);\r\n  _fileInfoPopIDs.Add(102);\r\n  _fileInfoPopIDs.Add(103);\r\n  _fileInfoPopIDs.Add(104);\r\n  #endif\r\n\r\n  #ifndef _SFX\r\n  InsertToHead(_fileInfoPopIDs, NID::kLastWriteTime);\r\n  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);\r\n  InsertToHead(_fileInfoPopIDs, NID::kSize);\r\n  InsertToHead(_fileInfoPopIDs, NID::kName);\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)\r\n{\r\n  *numProperties = _fileInfoPopIDs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 index,     \r\n      BSTR *name, PROPID *propID, VARTYPE *varType)\r\n{\r\n  if((int)index >= _fileInfoPopIDs.Size())\r\n    return E_INVALIDARG;\r\n  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);\r\n  if (indexInMap == -1)\r\n    return E_INVALIDARG;\r\n  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;\r\n  *propID = srcItem.propid;\r\n  *varType = srcItem.vt;\r\n  *name = 0;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zProperties.h",
    "content": "// 7zProperties.h\r\n\r\n#ifndef __7Z_PROPERTIES_H\r\n#define __7Z_PROPERTIES_H\r\n\r\n#include \"../../PropID.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nenum\r\n{\r\n  kpidPackedSize0 = kpidUserDefined,\r\n  kpidPackedSize1, \r\n  kpidPackedSize2,\r\n  kpidPackedSize3,\r\n  kpidPackedSize4\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zRegister.cpp",
    "content": "// 7zRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"7zHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::N7z::CHandler;  }\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"7z\", L\"7z\", 0, 7, {'7' + 1 , 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };\r\n\r\nREGISTER_ARC_DEC_SIG(7z)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zSpecStream.cpp",
    "content": "// 7zSpecStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zSpecStream.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result; \r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(\r\n    UInt64 subStream, UInt64 *value)\r\n{\r\n  if (_getSubStreamSize == NULL)\r\n    return E_NOTIMPL;\r\n  return  _getSubStreamSize->GetSubStreamSize(subStream, value);\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zSpecStream.h",
    "content": "// 7zSpecStream.h\r\n\r\n#ifndef __7Z_SPEC_STREAM_H\r\n#define __7Z_SPEC_STREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CSequentialInStreamSizeCount2: \r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _getSubStreamSize = 0;\r\n    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zUpdate.cpp",
    "content": "// UpdateMain.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zUpdate.h\"\r\n#include \"7zFolderInStream.h\"\r\n#include \"7zEncode.h\"\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n\r\n#include \"../../Compress/Copy/CopyCoder.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kMatchFinderForBCJ2_LZMA = L\"BT2\";\r\nstatic const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;\r\nstatic const UInt32 kAlgorithmForBCJ2_LZMA = 1;\r\nstatic const UInt32 kNumFastBytesForBCJ2_LZMA = 64;\r\n\r\nstatic HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream, \r\n    UInt64 position, UInt64 size, ICompressProgressInfo *progress)\r\n{\r\n  RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));\r\n  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;\r\n  CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);\r\n  streamSpec->SetStream(inStream);\r\n  streamSpec->Init(size);\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n  RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));\r\n  return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);\r\n}\r\n\r\nstatic int GetReverseSlashPos(const UString &name)\r\n{\r\n  int slashPos = name.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = name.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n  return slashPos;\r\n}\r\n\r\nint CUpdateItem::GetExtensionPos() const\r\n{\r\n  int slashPos = GetReverseSlashPos(Name);\r\n  int dotPos = Name.ReverseFind(L'.');\r\n  if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n    return Name.Length();\r\n  return dotPos + 1;\r\n}\r\n\r\nUString CUpdateItem::GetExtension() const\r\n{\r\n  return Name.Mid(GetExtensionPos());\r\n}\r\n\r\n#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }\r\n\r\nstatic int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)\r\n{\r\n  size_t c1 = a1.GetCapacity();\r\n  size_t c2 = a2.GetCapacity();\r\n  RINOZ(MyCompare(c1, c2));\r\n  for (size_t i = 0; i < c1; i++)\r\n    RINOZ(MyCompare(a1[i], a2[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareCoders(const CCoderInfo &c1, const CCoderInfo &c2)\r\n{\r\n  RINOZ(MyCompare(c1.NumInStreams, c2.NumInStreams));\r\n  RINOZ(MyCompare(c1.NumOutStreams, c2.NumOutStreams));\r\n  RINOZ(MyCompare(c1.MethodID, c2.MethodID));\r\n  return CompareBuffers(c1.Properties, c2.Properties);\r\n}\r\n\r\nstatic int CompareBindPairs(const CBindPair &b1, const CBindPair &b2)\r\n{\r\n  RINOZ(MyCompare(b1.InIndex, b2.InIndex));\r\n  return MyCompare(b1.OutIndex, b2.OutIndex);\r\n}\r\n\r\nstatic int CompareFolders(const CFolder &f1, const CFolder &f2)\r\n{\r\n  int s1 = f1.Coders.Size();\r\n  int s2 = f2.Coders.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  int i;\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareCoders(f1.Coders[i], f2.Coders[i]));\r\n  s1 = f1.BindPairs.Size();\r\n  s2 = f2.BindPairs.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareBindPairs(f1.BindPairs[i], f2.BindPairs[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareFiles(const CFileItem &f1, const CFileItem &f2)\r\n{\r\n  return MyStringCompareNoCase(f1.Name, f2.Name);\r\n}\r\n\r\nstatic int CompareFolderRefs(const int *p1, const int *p2, void *param)\r\n{\r\n  int i1 = *p1;\r\n  int i2 = *p2;\r\n  const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param;\r\n  RINOZ(CompareFolders(\r\n      db.Folders[i1],\r\n      db.Folders[i2]));\r\n  RINOZ(MyCompare(\r\n      db.NumUnPackStreamsVector[i1],\r\n      db.NumUnPackStreamsVector[i2]));\r\n  if (db.NumUnPackStreamsVector[i1] == 0)\r\n    return 0;\r\n  return CompareFiles(\r\n      db.Files[db.FolderStartFileIndex[i1]],\r\n      db.Files[db.FolderStartFileIndex[i2]]);\r\n}\r\n\r\n////////////////////////////////////////////////////////////\r\n\r\nstatic int CompareEmptyItems(const int *p1, const int *p2, void *param)\r\n{\r\n  const CObjectVector<CUpdateItem> &updateItems = *(const CObjectVector<CUpdateItem> *)param;\r\n  const CUpdateItem &u1 = updateItems[*p1];\r\n  const CUpdateItem &u2 = updateItems[*p2];\r\n  if (u1.IsDirectory != u2.IsDirectory)\r\n    return (u1.IsDirectory) ? 1 : -1;\r\n  if (u1.IsDirectory)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    int n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  if (u1.IsAnti != u2.IsAnti)\r\n    return (u1.IsAnti ? 1 : -1);\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstatic const char *g_Exts = \r\n  \" lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo\" \r\n  \" zip jar ear war msi\"\r\n  \" 3gp avi mov mpeg mpg mpe wmv\"\r\n  \" aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav\"\r\n  \" swf \"\r\n  \" chm hxi hxs\"\r\n  \" gif jpeg jpg jp2 png tiff  bmp ico psd psp\"\r\n  \" awg ps eps cgm dxf svg vrml wmf emf ai md\"\r\n  \" cad dwg pps key sxi\"\r\n  \" max 3ds\"\r\n  \" iso bin nrg mdf img pdi tar cpio xpi\"\r\n  \" vfd vhd vud vmc vsv\"\r\n  \" vmdk dsk nvram vmem vmsd vmsn vmss vmtm\"\r\n  \" inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def\" \r\n  \" f77 f f90 f95\"\r\n  \" asm sql manifest dep \"\r\n  \" mak clw csproj vcproj sln dsp dsw \"\r\n  \" class \"\r\n  \" bat cmd\"\r\n  \" xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml\"\r\n  \" awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs\"\r\n  \" text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf\"\r\n  \" sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf\"\r\n  \" abw afp cwk lwp wpd wps wpt wrf wri\"\r\n  \" abf afm bdf fon mgf otf pcf pfa snf ttf\"\r\n  \" dbf mdb nsf ntf wdb db fdb gdb\"\r\n  \" exe dll ocx vbx sfx sys tlb awx com obj lib out o so \"\r\n  \" pdb pch idb ncb opt\";\r\n\r\nint GetExtIndex(const char *ext)\r\n{\r\n  int extIndex = 1;\r\n  const char *p = g_Exts;\r\n  for (;;)\r\n  {\r\n    char c = *p++;\r\n    if (c == 0)\r\n      return extIndex;\r\n    if (c == ' ')\r\n      continue;\r\n    int pos = 0;\r\n    for (;;)\r\n    {\r\n      char c2 = ext[pos++];\r\n      if (c2 == 0 && (c == 0 || c == ' '))\r\n        return extIndex;\r\n      if (c != c2)\r\n        break;\r\n      c = *p++;\r\n    }\r\n    extIndex++;\r\n    for (;;)\r\n    {\r\n      if (c == 0)\r\n        return extIndex;\r\n      if (c == ' ')\r\n        break;\r\n      c = *p++;\r\n    }\r\n  }\r\n}\r\n\r\nstruct CRefItem\r\n{\r\n  UInt32 Index;\r\n  const CUpdateItem *UpdateItem;\r\n  UInt32 ExtensionPos;\r\n  UInt32 NamePos;\r\n  int ExtensionIndex;\r\n  CRefItem(UInt32 index, const CUpdateItem &updateItem, bool sortByType):\r\n    Index(index),\r\n    UpdateItem(&updateItem),\r\n    ExtensionPos(0),\r\n    NamePos(0),\r\n    ExtensionIndex(0)\r\n  {\r\n    if (sortByType)\r\n    {\r\n      int slashPos = GetReverseSlashPos(updateItem.Name);\r\n      NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0);\r\n      int dotPos = updateItem.Name.ReverseFind(L'.');\r\n      if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n        ExtensionPos = updateItem.Name.Length();\r\n      else \r\n      {\r\n        ExtensionPos = dotPos + 1;\r\n        UString us = updateItem.Name.Mid(ExtensionPos);\r\n        if (!us.IsEmpty())\r\n        {\r\n          us.MakeLower();\r\n          int i;\r\n          AString s;\r\n          for (i = 0; i < us.Length(); i++)\r\n          {\r\n            wchar_t c = us[i];\r\n            if (c >= 0x80)\r\n              break;\r\n            s += (char)c;\r\n          }\r\n          if (i == us.Length())\r\n            ExtensionIndex = GetExtIndex(s);\r\n          else\r\n            ExtensionIndex = 0;\r\n        }\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nstatic int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *param)\r\n{\r\n  const CRefItem &a1 = *p1;\r\n  const CRefItem &a2 = *p2;\r\n  const CUpdateItem &u1 = *a1.UpdateItem;\r\n  const CUpdateItem &u2 = *a2.UpdateItem;\r\n  int n;\r\n  if (u1.IsDirectory != u2.IsDirectory)\r\n    return (u1.IsDirectory) ? 1 : -1;\r\n  if (u1.IsDirectory)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  bool sortByType = *(bool *)param;\r\n  if (sortByType)\r\n  {\r\n    RINOZ(MyCompare(a1.ExtensionIndex, a2.ExtensionIndex))\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos));\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos));\r\n    if (u1.IsLastWriteTimeDefined && u2.IsLastWriteTimeDefined)\r\n      RINOZ(CompareFileTime(&u1.LastWriteTime, &u2.LastWriteTime));\r\n    RINOZ(MyCompare(u1.Size, u2.Size))\r\n  }\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstruct CSolidGroup\r\n{\r\n  CCompressionMethodMode Method;\r\n  CRecordVector<UInt32> Indices;\r\n};\r\n\r\nstatic wchar_t *g_ExeExts[] =\r\n{\r\n  L\"dll\",\r\n  L\"exe\",\r\n  L\"ocx\",\r\n  L\"sfx\",\r\n  L\"sys\"\r\n};\r\n\r\nstatic bool IsExeFile(const UString &ext)\r\n{\r\n  for (int i = 0; i < sizeof(g_ExeExts) / sizeof(g_ExeExts[0]); i++)\r\n    if (ext.CompareNoCase(g_ExeExts[i]) == 0)\r\n      return true;\r\n  return false;\r\n}\r\n\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_BCJ   = 0x03030103;\r\nstatic const UInt64 k_BCJ2  = 0x0303011B;\r\n\r\nstatic bool GetMethodFull(UInt64 methodID, \r\n    UInt32 numInStreams, CMethodFull &methodResult)\r\n{\r\n  methodResult.Id = methodID;\r\n  methodResult.NumInStreams = numInStreams;\r\n  methodResult.NumOutStreams = 1;\r\n  return true;\r\n}\r\n\r\nstatic bool MakeExeMethod(const CCompressionMethodMode &method, \r\n    bool bcj2Filter, CCompressionMethodMode &exeMethod)\r\n{\r\n  exeMethod = method;\r\n  if (bcj2Filter)\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ2, 4, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    if (!GetMethodFull(k_LZMA, 1, methodFull))\r\n      return false;\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kAlgorithm;\r\n      property.Value = kAlgorithmForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kMatchFinder;\r\n      property.Value = kMatchFinderForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n      property.Value = kDictionaryForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kNumFastBytes;\r\n      property.Value = kNumFastBytesForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n\r\n    exeMethod.Methods.Add(methodFull);\r\n    exeMethod.Methods.Add(methodFull);\r\n    CBind bind;\r\n\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 2;\r\n    bind.OutStream = 1;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 3;\r\n    bind.OutStream = 2;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  else\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ, 1, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    CBind bind;\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  return true;\r\n}   \r\n\r\nstatic void SplitFilesToGroups(\r\n    const CCompressionMethodMode &method, \r\n    bool useFilters, bool maxFilter,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    CObjectVector<CSolidGroup> &groups)\r\n{\r\n  if (method.Methods.Size() != 1 || method.Binds.Size() != 0)\r\n    useFilters = false;\r\n  groups.Clear();\r\n  groups.Add(CSolidGroup());\r\n  groups.Add(CSolidGroup());\r\n  CSolidGroup &generalGroup = groups[0];\r\n  CSolidGroup &exeGroup = groups[1];\r\n  generalGroup.Method = method;\r\n  int i;\r\n  for (i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &updateItem = updateItems[i];\r\n    if (!updateItem.NewData)\r\n      continue;\r\n    if (!updateItem.HasStream())\r\n      continue;\r\n    if (useFilters)\r\n    {\r\n      const UString name = updateItem.Name;\r\n      int dotPos = name.ReverseFind(L'.');\r\n      if (dotPos >= 0)\r\n      {\r\n        UString ext = name.Mid(dotPos + 1);\r\n        if (IsExeFile(ext))\r\n        {\r\n          exeGroup.Indices.Add(i);\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    generalGroup.Indices.Add(i);\r\n  }\r\n  if (exeGroup.Indices.Size() > 0)\r\n    if (!MakeExeMethod(method, maxFilter, exeGroup.Method))\r\n      exeGroup.Method = method;\r\n  for (i = 0; i < groups.Size();)\r\n    if (groups[i].Indices.Size() == 0)\r\n      groups.Delete(i);\r\n    else\r\n      i++;\r\n}\r\n\r\nstatic void FromUpdateItemToFileItem(const CUpdateItem &updateItem, \r\n    CFileItem &file)\r\n{\r\n  file.Name = NItemName::MakeLegalName(updateItem.Name);\r\n  if (updateItem.AttributesAreDefined)\r\n    file.SetAttributes(updateItem.Attributes);\r\n  \r\n  if (updateItem.IsCreationTimeDefined)\r\n    file.SetCreationTime(updateItem.CreationTime);\r\n  if (updateItem.IsLastWriteTimeDefined)\r\n    file.SetLastWriteTime(updateItem.LastWriteTime);\r\n  if (updateItem.IsLastAccessTimeDefined)\r\n    file.SetLastAccessTime(updateItem.LastAccessTime);\r\n  \r\n  file.UnPackSize = updateItem.Size;\r\n  file.IsDirectory = updateItem.IsDirectory;\r\n  file.IsAnti = updateItem.IsAnti;\r\n  file.HasStream = updateItem.HasStream();\r\n}\r\n\r\nstatic HRESULT Update2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  UInt64 numSolidFiles = options.NumSolidFiles;\r\n  if (numSolidFiles == 0)\r\n    numSolidFiles = 1;\r\n  /*\r\n  CMyComPtr<IOutStream> outStream;\r\n  RINOK(seqOutStream->QueryInterface(IID_IOutStream, (void **)&outStream));\r\n  if (!outStream)\r\n    return E_NOTIMPL;\r\n  */\r\n\r\n  UInt64 startBlockSize = database != 0 ? database->ArchiveInfo.StartPosition: 0;\r\n  if (startBlockSize > 0 && !options.RemoveSfxBlock)\r\n  {\r\n    RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));\r\n  }\r\n\r\n  CRecordVector<int> fileIndexToUpdateIndexMap;\r\n  if (database != 0)\r\n  {\r\n    fileIndexToUpdateIndexMap.Reserve(database->Files.Size());\r\n    for (int i = 0; i < database->Files.Size(); i++)\r\n      fileIndexToUpdateIndexMap.Add(-1);\r\n  }\r\n  int i;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    int index = updateItems[i].IndexInArchive;\r\n    if (index != -1)\r\n      fileIndexToUpdateIndexMap[index] = i;\r\n  }\r\n\r\n  CRecordVector<int> folderRefs;\r\n  if (database != 0)\r\n  {\r\n    for(i = 0; i < database->Folders.Size(); i++)\r\n    {\r\n      CNum indexInFolder = 0;\r\n      CNum numCopyItems = 0;\r\n      CNum numUnPackStreams = database->NumUnPackStreamsVector[i];\r\n      for (CNum fileIndex = database->FolderStartFileIndex[i];\r\n      indexInFolder < numUnPackStreams; fileIndex++)\r\n      {\r\n        if (database->Files[fileIndex].HasStream)\r\n        {\r\n          indexInFolder++;\r\n          int updateIndex = fileIndexToUpdateIndexMap[fileIndex];\r\n          if (updateIndex >= 0)\r\n            if (!updateItems[updateIndex].NewData)\r\n              numCopyItems++;\r\n        }\r\n      }\r\n      if (numCopyItems != numUnPackStreams && numCopyItems != 0)\r\n        return E_NOTIMPL; // It needs repacking !!!\r\n      if (numCopyItems > 0)\r\n        folderRefs.Add(i);\r\n    }\r\n    folderRefs.Sort(CompareFolderRefs, (void *)database);\r\n  }\r\n\r\n  CArchiveDatabase newDatabase;\r\n\r\n  ////////////////////////////\r\n\r\n  COutArchive archive;\r\n  RINOK(archive.Create(seqOutStream, false));\r\n  RINOK(archive.SkeepPrefixArchiveHeader());\r\n  UInt64 complexity = 0;\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n    complexity += database->GetFolderFullPackSize(folderRefs[i]);\r\n  UInt64 inSizeForReduce = 0;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &updateItem = updateItems[i];\r\n    if (updateItem.NewData)\r\n    {\r\n      complexity += updateItem.Size;\r\n      if (numSolidFiles == 1)\r\n      {\r\n        if (updateItem.Size > inSizeForReduce)\r\n          inSizeForReduce = updateItem.Size;\r\n      }\r\n      else\r\n        inSizeForReduce += updateItem.Size;\r\n    }\r\n  }\r\n  RINOK(updateCallback->SetTotal(complexity));\r\n  complexity = 0;\r\n  RINOK(updateCallback->SetCompleted(&complexity));\r\n\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(updateCallback, true);\r\n\r\n  /////////////////////////////////////////\r\n  // Write Copy Items\r\n\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n  {\r\n    int folderIndex = folderRefs[i];\r\n    \r\n    lps->ProgressOffset = complexity;\r\n    UInt64 packSize = database->GetFolderFullPackSize(folderIndex);\r\n    RINOK(WriteRange(inStream, archive.SeqStream,\r\n        database->GetFolderStreamPos(folderIndex, 0), packSize, progress));\r\n    complexity += packSize;\r\n    \r\n    const CFolder &folder = database->Folders[folderIndex];\r\n    CNum startIndex = database->FolderStartPackStreamIndex[folderIndex];\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      newDatabase.PackSizes.Add(database->PackSizes[startIndex + j]);\r\n      // newDatabase.PackCRCsDefined.Add(database.PackCRCsDefined[startIndex + j]);\r\n      // newDatabase.PackCRCs.Add(database.PackCRCs[startIndex + j]);\r\n    }\r\n    newDatabase.Folders.Add(folder);\r\n\r\n    CNum numUnPackStreams = database->NumUnPackStreamsVector[folderIndex];\r\n    newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);\r\n\r\n    CNum indexInFolder = 0;\r\n    for (CNum fi = database->FolderStartFileIndex[folderIndex];\r\n        indexInFolder < numUnPackStreams; fi++)\r\n    {\r\n      CFileItem file = database->Files[fi];\r\n      if (file.HasStream)\r\n      {\r\n        indexInFolder++;\r\n        int updateIndex = fileIndexToUpdateIndexMap[fi];\r\n        if (updateIndex >= 0)\r\n        {\r\n          const CUpdateItem &updateItem = updateItems[updateIndex];\r\n          if (updateItem.NewProperties)\r\n          {\r\n            CFileItem file2;\r\n            FromUpdateItemToFileItem(updateItem, file2);\r\n            file2.UnPackSize = file.UnPackSize;\r\n            file2.FileCRC = file.FileCRC;\r\n            file2.IsFileCRCDefined = file.IsFileCRCDefined;\r\n            file2.HasStream = file.HasStream;\r\n            file = file2;\r\n          }\r\n        }\r\n        newDatabase.Files.Add(file);\r\n      }\r\n    }\r\n  }\r\n\r\n  /////////////////////////////////////////\r\n  // Compress New Files\r\n\r\n  CObjectVector<CSolidGroup> groups;\r\n  SplitFilesToGroups(*options.Method, options.UseFilters, options.MaxFilter, \r\n      updateItems, groups);\r\n\r\n  const UInt32 kMinReduceSize = (1 << 16);\r\n  if (inSizeForReduce < kMinReduceSize)\r\n    inSizeForReduce = kMinReduceSize;\r\n\r\n  for (int groupIndex = 0; groupIndex < groups.Size(); groupIndex++)\r\n  {\r\n    const CSolidGroup &group = groups[groupIndex];\r\n    int numFiles = group.Indices.Size();\r\n    if (numFiles == 0)\r\n      continue;\r\n    CRecordVector<CRefItem> refItems;\r\n    refItems.Reserve(numFiles);\r\n    bool sortByType = (numSolidFiles > 1);\r\n    for (i = 0; i < numFiles; i++)\r\n      refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType));\r\n    refItems.Sort(CompareUpdateItems, (void *)&sortByType);\r\n    \r\n    CRecordVector<UInt32> indices;\r\n    indices.Reserve(numFiles);\r\n\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      UInt32 index = refItems[i].Index;\r\n      indices.Add(index);\r\n      /*\r\n      const CUpdateItem &updateItem = updateItems[index];\r\n      CFileItem file;\r\n      if (updateItem.NewProperties)\r\n        FromUpdateItemToFileItem(updateItem, file);\r\n      else\r\n        file = database.Files[updateItem.IndexInArchive];\r\n      if (file.IsAnti || file.IsDirectory)\r\n        return E_FAIL;\r\n      newDatabase.Files.Add(file);\r\n      */\r\n    }\r\n    \r\n    CEncoder encoder(group.Method);\r\n\r\n    for (i = 0; i < numFiles;)\r\n    {\r\n      UInt64 totalSize = 0;\r\n      int numSubFiles;\r\n      UString prevExtension;\r\n      for (numSubFiles = 0; i + numSubFiles < numFiles && \r\n          numSubFiles < numSolidFiles; numSubFiles++)\r\n      {\r\n        const CUpdateItem &updateItem = updateItems[indices[i + numSubFiles]];\r\n        totalSize += updateItem.Size;\r\n        if (totalSize > options.NumSolidBytes)\r\n          break;\r\n        if (options.SolidExtension)\r\n        {\r\n          UString ext = updateItem.GetExtension();\r\n          if (numSubFiles == 0)\r\n            prevExtension = ext;\r\n          else\r\n            if (ext.CompareNoCase(prevExtension) != 0)\r\n              break;\r\n        }\r\n      }\r\n      if (numSubFiles < 1)\r\n        numSubFiles = 1;\r\n\r\n      CFolderInStream *inStreamSpec = new CFolderInStream;\r\n      CMyComPtr<ISequentialInStream> solidInStream(inStreamSpec);\r\n      inStreamSpec->Init(updateCallback, &indices[i], numSubFiles);\r\n      \r\n      CFolder folderItem;\r\n\r\n      int startPackIndex = newDatabase.PackSizes.Size();\r\n      RINOK(encoder.Encode(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          solidInStream, NULL, &inSizeForReduce, folderItem, \r\n          archive.SeqStream, newDatabase.PackSizes, progress));\r\n\r\n      for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)\r\n        lps->OutSize += newDatabase.PackSizes[startPackIndex];\r\n\r\n      lps->InSize += folderItem.GetUnPackSize();\r\n      // for()\r\n      // newDatabase.PackCRCsDefined.Add(false);\r\n      // newDatabase.PackCRCs.Add(0);\r\n      \r\n      newDatabase.Folders.Add(folderItem);\r\n      \r\n      CNum numUnPackStreams = 0;\r\n      for (int subIndex = 0; subIndex < numSubFiles; subIndex++)\r\n      {\r\n        const CUpdateItem &updateItem = updateItems[indices[i + subIndex]];\r\n        CFileItem file;\r\n        if (updateItem.NewProperties)\r\n          FromUpdateItemToFileItem(updateItem, file);\r\n        else\r\n          file = database->Files[updateItem.IndexInArchive];\r\n        if (file.IsAnti || file.IsDirectory)\r\n          return E_FAIL;\r\n        \r\n        /*\r\n        CFileItem &file = newDatabase.Files[\r\n              startFileIndexInDatabase + i + subIndex];\r\n        */\r\n        if (!inStreamSpec->Processed[subIndex])\r\n        {\r\n          continue;\r\n          // file.Name += L\".locked\";\r\n        }\r\n\r\n        file.FileCRC = inStreamSpec->CRCs[subIndex];\r\n        file.UnPackSize = inStreamSpec->Sizes[subIndex];\r\n        if (file.UnPackSize != 0)\r\n        {\r\n          file.IsFileCRCDefined = true;\r\n          file.HasStream = true;\r\n          numUnPackStreams++;\r\n        }\r\n        else\r\n        {\r\n          file.IsFileCRCDefined = false;\r\n          file.HasStream = false;\r\n        }\r\n        newDatabase.Files.Add(file);\r\n      }\r\n      // numUnPackStreams = 0 is very bad case for locked files\r\n      // v3.13 doesn't understand it.\r\n      newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);\r\n      i += numSubFiles;\r\n    }\r\n  }\r\n\r\n  {\r\n    /////////////////////////////////////////\r\n    // Write Empty Files & Folders\r\n    \r\n    CRecordVector<int> emptyRefs;\r\n    for(i = 0; i < updateItems.Size(); i++)\r\n    {\r\n      const CUpdateItem &updateItem = updateItems[i];\r\n      if (updateItem.NewData)\r\n      {\r\n        if (updateItem.HasStream())\r\n          continue;\r\n      }\r\n      else\r\n        if (updateItem.IndexInArchive != -1)\r\n          if (database->Files[updateItem.IndexInArchive].HasStream)\r\n            continue;\r\n      emptyRefs.Add(i);\r\n    }\r\n    emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);\r\n    for(i = 0; i < emptyRefs.Size(); i++)\r\n    {\r\n      const CUpdateItem &updateItem = updateItems[emptyRefs[i]];\r\n      CFileItem file;\r\n      if (updateItem.NewProperties)\r\n        FromUpdateItemToFileItem(updateItem, file);\r\n      else\r\n        file = database->Files[updateItem.IndexInArchive];\r\n      newDatabase.Files.Add(file);\r\n    }\r\n  }\r\n    \r\n  /*\r\n  if (newDatabase.Files.Size() != updateItems.Size())\r\n    return E_FAIL;\r\n  */\r\n\r\n  return archive.WriteDatabase(EXTERNAL_CODECS_LOC_VARS\r\n      newDatabase, options.HeaderMethod, options.HeaderOptions);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\n\r\nstatic HRESULT WriteVolumeHeader(COutArchive &archive, CFileItem &file, const CUpdateOptions &options)\r\n{\r\n  CCoderInfo coder;\r\n  coder.NumInStreams = coder.NumOutStreams = 1;\r\n  coder.MethodID = k_Copy;\r\n  \r\n  CFolder folder;\r\n  folder.Coders.Add(coder);\r\n  folder.PackStreams.Add(0);\r\n  \r\n  CNum numUnPackStreams = 0;\r\n  if (file.UnPackSize != 0)\r\n  {\r\n    file.IsFileCRCDefined = true;\r\n    file.HasStream = true;\r\n    numUnPackStreams++;\r\n  }\r\n  else\r\n  {\r\n    throw 1;\r\n    file.IsFileCRCDefined = false;\r\n    file.HasStream = false;\r\n  }\r\n  folder.UnPackSizes.Add(file.UnPackSize);\r\n  \r\n  CArchiveDatabase newDatabase;\r\n  newDatabase.Files.Add(file);\r\n  newDatabase.Folders.Add(folder);\r\n  newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);\r\n  newDatabase.PackSizes.Add(file.UnPackSize);\r\n  newDatabase.PackCRCsDefined.Add(false);\r\n  newDatabase.PackCRCs.Add(file.FileCRC);\r\n  \r\n  return archive.WriteDatabase(newDatabase, \r\n      options.HeaderMethod, \r\n      false, \r\n      false);\r\n}\r\n\r\nHRESULT UpdateVolume(\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  if (updateItems.Size() != 1)\r\n    return E_NOTIMPL;\r\n\r\n  CMyComPtr<IArchiveUpdateCallback2> volumeCallback;\r\n  RINOK(updateCallback->QueryInterface(IID_IArchiveUpdateCallback2, (void **)&volumeCallback));\r\n  if (!volumeCallback)\r\n    return E_NOTIMPL;\r\n\r\n  CMyComPtr<ISequentialInStream> fileStream;\r\n  HRESULT result = updateCallback->GetStream(0, &fileStream);\r\n  if (result != S_OK && result != S_FALSE)\r\n    return result;\r\n  if (result == S_FALSE)\r\n    return E_FAIL;\r\n  \r\n  CFileItem file;\r\n  \r\n  const CUpdateItem &updateItem = updateItems[0];\r\n  if (updateItem.NewProperties)\r\n    FromUpdateItemToFileItem(updateItem, file);\r\n  else\r\n    file = database->Files[updateItem.IndexInArchive];\r\n  if (file.IsAnti || file.IsDirectory)\r\n    return E_FAIL;\r\n\r\n  UInt64 complexity = 0;\r\n  file.IsStartPosDefined = true;\r\n  file.StartPos = 0;\r\n  for (UInt64 volumeIndex = 0; true; volumeIndex++)\r\n  { \r\n    UInt64 volSize;\r\n    RINOK(volumeCallback->GetVolumeSize(volumeIndex, &volSize));\r\n    UInt64 pureSize = COutArchive::GetVolPureSize(volSize, file.Name.Length(), true);\r\n    CMyComPtr<ISequentialOutStream> volumeStream;\r\n    RINOK(volumeCallback->GetVolumeStream(volumeIndex, &volumeStream));\r\n   \r\n    COutArchive archive;\r\n    RINOK(archive.Create(volumeStream, true));\r\n    RINOK(archive.SkeepPrefixArchiveHeader());\r\n        \r\n    CSequentialInStreamWithCRC *inCrcStreamSpec = new CSequentialInStreamWithCRC;\r\n    CMyComPtr<ISequentialInStream> inCrcStream = inCrcStreamSpec;\r\n    inCrcStreamSpec->Init(fileStream);\r\n\r\n    RINOK(WriteRange(inCrcStream, volumeStream, pureSize, updateCallback, complexity));\r\n    file.UnPackSize = inCrcStreamSpec->GetSize();\r\n    if (file.UnPackSize == 0)\r\n      break;\r\n    file.FileCRC = inCrcStreamSpec->GetCRC();\r\n    RINOK(WriteVolumeHeader(archive, file, options));\r\n    file.StartPos += file.UnPackSize;\r\n    if (file.UnPackSize < pureSize)\r\n      break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nclass COutVolumeStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback, \r\n      const UString &name)  \r\n  { \r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutVolumeStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (!_volumeStream)\r\n    {\r\n      RINOK(VolumeCallback->GetVolumeSize(_volIndex, &_volSize));\r\n      RINOK(VolumeCallback->GetVolumeStream(_volIndex, &_volumeStream));\r\n      _volIndex++;\r\n      _curPos = 0;\r\n      RINOK(_archive.Create(_volumeStream, true));\r\n      RINOK(_archive.SkeepPrefixArchiveHeader());\r\n      _crc.Init();\r\n      continue;\r\n    }\r\n    UInt64 pureSize = COutArchive::GetVolPureSize(_volSize, _file.Name.Length());\r\n    UInt32 curSize = (UInt32)MyMin(UInt64(size), pureSize - _curPos);\r\n\r\n    _crc.Update(data, curSize);\r\n    UInt32 realProcessed;\r\n    RINOK(_volumeStream->Write(data, curSize, &realProcessed))\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _curPos += realProcessed;\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n    if (_curPos == pureSize)\r\n    {\r\n      RINOK(Flush());\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (seqOutStream)\r\n  #endif\r\n    return Update2(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        inStream, database, updateItems,\r\n        seqOutStream, updateCallback, options);\r\n  #ifdef _7Z_VOL\r\n  if (options.VolumeMode)\r\n    return UpdateVolume(inStream, database, updateItems,\r\n      seqOutStream, updateCallback, options);\r\n  COutVolumeStream *volStreamSpec = new COutVolumeStream;\r\n  CMyComPtr<ISequentialOutStream> volStream = volStreamSpec;\r\n  CMyComPtr<IArchiveUpdateCallback2> volumeCallback;\r\n  RINOK(updateCallback->QueryInterface(IID_IArchiveUpdateCallback2, (void **)&volumeCallback));\r\n  if (!volumeCallback)\r\n    return E_NOTIMPL;\r\n  volStreamSpec->Init(volumeCallback, L\"a.7z\");\r\n  volStreamSpec->_options = options;\r\n  RINOK(Update2(inStream, database, updateItems,\r\n    volStream, updateCallback, options));\r\n  return volStreamSpec->Flush();\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/7zUpdate.h",
    "content": "// 7zUpdate.h\r\n\r\n#ifndef __7Z_UPDATE_H\r\n#define __7Z_UPDATE_H\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CUpdateItem\r\n{\r\n  bool NewData;\r\n  bool NewProperties;\r\n  int IndexInArchive;\r\n  int IndexInClient;\r\n  \r\n  UInt32 Attributes;\r\n  FILETIME CreationTime;\r\n  FILETIME LastWriteTime;\r\n  FILETIME LastAccessTime;\r\n\r\n  UInt64 Size;\r\n  UString Name;\r\n  \r\n  bool IsAnti;\r\n  bool IsDirectory;\r\n\r\n  bool IsCreationTimeDefined;\r\n  bool IsLastWriteTimeDefined;\r\n  bool IsLastAccessTimeDefined;\r\n  bool AttributesAreDefined;\r\n\r\n  bool HasStream() const \r\n    { return !IsDirectory && !IsAnti && Size != 0; }\r\n  CUpdateItem():  \r\n      IsAnti(false), \r\n      AttributesAreDefined(false), \r\n      IsCreationTimeDefined(false), \r\n      IsLastWriteTimeDefined(false), \r\n      IsLastAccessTimeDefined(false)\r\n      {}\r\n  void SetDirectoryStatusFromAttributes()\r\n    { IsDirectory = ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0); };\r\n\r\n  int GetExtensionPos() const;\r\n  UString GetExtension() const;\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  const CCompressionMethodMode *Method;\r\n  const CCompressionMethodMode *HeaderMethod;\r\n  bool UseFilters;\r\n  bool MaxFilter;\r\n\r\n  CHeaderOptions HeaderOptions;\r\n\r\n  UInt64 NumSolidFiles;\r\n  UInt64 NumSolidBytes;\r\n  bool SolidExtension;\r\n  bool RemoveSfxBlock;\r\n  bool VolumeMode;\r\n};\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options);\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Archive.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Archive2.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n  GetNumberOfMethods PRIVATE\r\n  GetMethodProperty PRIVATE\r\n  SetLargePageMode PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/ArchiveExports.cpp",
    "content": "// ArchiveExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterArc.h\"\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax]; \r\nvoid RegisterArc(const CArcInfo *arcInfo) \r\n{ \r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo; \r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler, \r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\n#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nint FindFormatCalssId(const GUID *clsID)\r\n{\r\n  GUID cls = *clsID;\r\n  CLS_ARC_ID_ITEM(cls) = 0;\r\n  if (cls != CLSID_CArchiveHandler)\r\n    return -1;\r\n  Byte id = CLS_ARC_ID_ITEM(*clsID);\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n    if (g_Arcs[i]->ClassId == id)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nSTDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  {\r\n    int needIn = (*iid == IID_IInArchive);\r\n    int needOut = (*iid == IID_IOutArchive);\r\n    if (!needIn && !needOut)\r\n      return E_NOINTERFACE;\r\n    int formatIndex = FindFormatCalssId(clsid);\r\n    if (formatIndex < 0)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    \r\n    const CArcInfo &arc = *g_Arcs[formatIndex];\r\n    if (needIn)\r\n    {\r\n      *outObject = arc.CreateInArchive();\r\n      ((IInArchive *)*outObject)->AddRef();\r\n    }\r\n    else\r\n    {\r\n      if (!arc.CreateOutArchive)\r\n        return CLASS_E_CLASSNOTAVAILABLE;\r\n      *outObject = arc.CreateOutArchive();\r\n      ((IOutArchive *)*outObject)->AddRef();\r\n    }\r\n  }\r\n  COM_TRY_END\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  if (formatIndex >= g_NumArcs)\r\n    return E_INVALIDARG;\r\n  const CArcInfo &arc = *g_Arcs[formatIndex];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case NArchive::kName:\r\n      prop = arc.Name;\r\n      break;\r\n    case NArchive::kClassID:\r\n    {\r\n      GUID clsId = CLSID_CArchiveHandler;\r\n      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;\r\n      return SetPropGUID(clsId, value);\r\n    }\r\n    case NArchive::kExtension:\r\n      if (arc.Ext != 0)\r\n        prop = arc.Ext;\r\n      break;\r\n    case NArchive::kAddExtension:\r\n      if (arc.AddExt != 0)\r\n        prop = arc.AddExt;\r\n      break;\r\n    case NArchive::kUpdate:\r\n      prop = (bool)(arc.CreateOutArchive != 0);\r\n      break;\r\n    case NArchive::kKeepName:\r\n      prop = arc.KeepName;\r\n      break;\r\n    case NArchive::kStartSignature:\r\n      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  return GetHandlerProperty2(0, propID, value);\r\n}\r\n\r\nSTDAPI GetNumberOfFormats(UINT32 *numFormats)\r\n{\r\n  *numFormats = g_NumArcs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/CoderMixer2.cpp",
    "content": "// CoderMixer2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):\r\n  _srcBindInfo(srcBindInfo)\r\n{\r\n  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);\r\n\r\n  UInt32  j;\r\n  for (j = 0; j < NumSrcInStreams; j++)\r\n  {\r\n    _srcInToDestOutMap.Add(0);\r\n    DestOutToSrcInMap.Add(0);\r\n  }\r\n  for (j = 0; j < _numSrcOutStreams; j++)\r\n  {\r\n    _srcOutToDestInMap.Add(0);\r\n    _destInToSrcOutMap.Add(0);\r\n  }\r\n\r\n  UInt32 destInOffset = 0;\r\n  UInt32 destOutOffset = 0;\r\n  UInt32 srcInOffset = NumSrcInStreams;\r\n  UInt32 srcOutOffset = _numSrcOutStreams;\r\n\r\n  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];\r\n\r\n    srcInOffset -= srcCoderInfo.NumInStreams;\r\n    srcOutOffset -= srcCoderInfo.NumOutStreams;\r\n    \r\n    UInt32 j;\r\n    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)\r\n    {\r\n      UInt32 index = srcInOffset + j;\r\n      _srcInToDestOutMap[index] = destOutOffset;\r\n      DestOutToSrcInMap[destOutOffset] = index;\r\n    }\r\n    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)\r\n    {\r\n      UInt32 index = srcOutOffset + j;\r\n      _srcOutToDestInMap[index] = destInOffset;\r\n      _destInToSrcOutMap[destInOffset] = index;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)\r\n{\r\n  destBindInfo.Coders.Clear();\r\n  destBindInfo.BindPairs.Clear();\r\n  destBindInfo.InStreams.Clear();\r\n  destBindInfo.OutStreams.Clear();\r\n\r\n  int i;\r\n  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];\r\n    CCoderStreamsInfo destCoderInfo;\r\n    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;\r\n    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;\r\n    destBindInfo.Coders.Add(destCoderInfo);\r\n  }\r\n  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];\r\n    CBindPair destBindPair;\r\n    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];\r\n    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];\r\n    destBindInfo.BindPairs.Add(destBindPair);\r\n  }\r\n  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)\r\n    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);\r\n  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)\r\n    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);\r\n}\r\n\r\nCCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams): \r\n    NumInStreams(numInStreams),\r\n    NumOutStreams(numOutStreams)\r\n{\r\n  InSizes.Reserve(NumInStreams);\r\n  InSizePointers.Reserve(NumInStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes, \r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\nvoid CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,\r\n      const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n}  \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/CoderMixer2.h",
    "content": "// CoderMixer2.h\r\n\r\n#ifndef __CODER_MIXER2_H\r\n#define __CODER_MIXER2_H\r\n\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n};\r\n\r\nstruct CCoderStreamsInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n};\r\n\r\nstruct CBindInfo\r\n{\r\n  CRecordVector<CCoderStreamsInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<UInt32> InStreams;\r\n  CRecordVector<UInt32> OutStreams;\r\n\r\n  void Clear()\r\n  {\r\n    Coders.Clear();\r\n    BindPairs.Clear();\r\n    InStreams.Clear();\r\n    OutStreams.Clear();\r\n  }\r\n\r\n  /*\r\n  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const\r\n  {\r\n    UInt32 numOutStreams = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      numOutStreams += Coders[i].NumOutStreams;\r\n    return numOutStreams;\r\n  }\r\n  */\r\n\r\n\r\n  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const\r\n  {\r\n    numInStreams = 0;\r\n    numOutStreams = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n    {\r\n      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];\r\n      numInStreams += coderStreamsInfo.NumInStreams;\r\n      numOutStreams += coderStreamsInfo.NumOutStreams;\r\n    }\r\n  }\r\n\r\n  int FindBinderForInStream(UInt32 inStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBinderForOutStream(UInt32 outStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumInStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumOutStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n\r\n  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex, \r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumInStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex, \r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumOutStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n};\r\n\r\nclass CBindReverseConverter\r\n{\r\n  UInt32 _numSrcOutStreams;\r\n  NCoderMixer::CBindInfo _srcBindInfo;\r\n  CRecordVector<UInt32> _srcInToDestOutMap;\r\n  CRecordVector<UInt32> _srcOutToDestInMap;\r\n  CRecordVector<UInt32> _destInToSrcOutMap;\r\npublic:\r\n  UInt32 NumSrcInStreams;\r\n  CRecordVector<UInt32> DestOutToSrcInMap;\r\n\r\n  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);\r\n  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);\r\n};\r\n\r\nstruct CCoderInfo2\r\n{\r\n  CMyComPtr<ICompressCoder> Coder;\r\n  CMyComPtr<ICompressCoder2> Coder2;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n\r\n  CRecordVector<UInt64> InSizes;\r\n  CRecordVector<UInt64> OutSizes;\r\n  CRecordVector<const UInt64 *> InSizePointers;\r\n  CRecordVector<const UInt64 *> OutSizePointers;\r\n\r\n  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n\r\n  HRESULT QueryInterface(REFGUID iid, void** pp) const\r\n  {\r\n    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;\r\n    return p->QueryInterface(iid, pp);\r\n  }\r\n};\r\n\r\nclass CCoderMixer2\r\n{\r\npublic:\r\n  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;\r\n  virtual void ReInit() = 0;\r\n  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;\r\n};\r\n\r\n}\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/CoderMixer2MT.cpp",
    "content": "// CoderMixer2MT.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2MT.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams): \r\n    CCoderInfo2(numInStreams, numOutStreams)\r\n{\r\n  InStreams.Reserve(NumInStreams);\r\n  InStreamPointers.Reserve(NumInStreams);\r\n  OutStreams.Reserve(NumOutStreams);\r\n  OutStreamPointers.Reserve(NumOutStreams);\r\n}\r\n\r\nvoid CCoder2::Execute() { Code(NULL); }\r\n\r\nvoid CCoder2::Code(ICompressProgressInfo *progress)\r\n{\r\n  InStreamPointers.Clear();\r\n  OutStreamPointers.Clear();\r\n  UInt32 i;\r\n  for (i = 0; i < NumInStreams; i++)\r\n  {\r\n    if (InSizePointers[i] != NULL)\r\n      InSizePointers[i] = &InSizes[i];\r\n    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);\r\n  }\r\n  for (i = 0; i < NumOutStreams; i++)\r\n  {\r\n    if (OutSizePointers[i] != NULL)\r\n      OutSizePointers[i] = &OutSizes[i];\r\n    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);\r\n  }\r\n  if (Coder)\r\n    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0], \r\n        InSizePointers[0], OutSizePointers[0], progress);\r\n  else\r\n    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,\r\n      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);\r\n  {\r\n    int i;\r\n    for (i = 0; i < InStreams.Size(); i++)\r\n      InStreams[i].Release();\r\n    for (i = 0; i < OutStreams.Size(); i++)\r\n      OutStreams[i].Release();\r\n  }\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes, \r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\n\r\nvoid CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n//////////////////////////////////////\r\n// CCoderMixer2MT\r\n\r\nHRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)\r\n{  \r\n  _bindInfo = bindInfo; \r\n  _streamBinders.Clear();\r\n  for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    _streamBinders.Add(CStreamBinder());\r\n    RINOK(_streamBinders.Back().CreateEvents());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoderCommon()\r\n{\r\n  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];\r\n  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);\r\n  _coders.Add(threadCoderInfo);\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder(ICompressCoder *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder = coder;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder2 = coder;\r\n}\r\n\r\n\r\nvoid CCoderMixer2MT::ReInit()\r\n{\r\n  for(int i = 0; i < _streamBinders.Size(); i++)\r\n    _streamBinders[i].ReInit();\r\n}\r\n\r\n\r\nHRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams) \r\n{\r\n  /*\r\n  if (_coders.Size() != _bindInfo.Coders.Size())\r\n    throw 0;\r\n  */\r\n  int i;\r\n  for(i = 0; i < _coders.Size(); i++)\r\n  {\r\n    CCoder2 &coderInfo = _coders[i];\r\n    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];\r\n    coderInfo.InStreams.Clear();\r\n    UInt32 j;\r\n    for(j = 0; j < coderStreamsInfo.NumInStreams; j++)\r\n      coderInfo.InStreams.Add(NULL);\r\n    coderInfo.OutStreams.Clear();\r\n    for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)\r\n      coderInfo.OutStreams.Add(NULL);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = _bindInfo.BindPairs[i];\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);\r\n    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);\r\n\r\n    _streamBinders[i].CreateStreams(\r\n        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],\r\n        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.InStreams.Size(); i++)\r\n  {\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);\r\n    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];\r\n  }\r\n  \r\n  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);\r\n    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)\r\n{\r\n  for (int i = 0; i < _coders.Size(); i++)\r\n    if (_coders[i].Result == code)\r\n      return code;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||\r\n      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())\r\n    return E_INVALIDARG;\r\n\r\n  Init(inStreams, outStreams);\r\n\r\n  int i;\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n    {\r\n      RINOK(_coders[i].Create());\r\n    }\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].Start();\r\n\r\n  _coders[_progressCoderIndex].Code(progress);\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].WaitFinish();\r\n\r\n  RINOK(ReturnIfError(E_ABORT));\r\n  RINOK(ReturnIfError(E_OUTOFMEMORY));\r\n  RINOK(ReturnIfError(S_FALSE));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK && result != E_FAIL)\r\n      return result;\r\n  }\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}  \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/CoderMixer2MT.h",
    "content": "// CoderMixer2MT.h\r\n\r\n#ifndef __CODER_MIXER2_MT_H\r\n#define __CODER_MIXER2_MT_H\r\n\r\n#include \"CoderMixer2.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../Common/StreamBinder.h\"\r\n#include \"../../Common/VirtThread.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CCoder2: public CCoderInfo2, public CVirtThread\r\n{\r\n  HRESULT Result;\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;\r\n  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;\r\n  CRecordVector<ISequentialInStream*> InStreamPointers;\r\n  CRecordVector<ISequentialOutStream*> OutStreamPointers;\r\n\r\n  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n  virtual void Execute();\r\n  void Code(ICompressProgressInfo *progress);\r\n};\r\n\r\n\r\n/*\r\n  SetBindInfo()\r\n  for each coder\r\n    AddCoder[2]()\r\n  SetProgressIndex(UInt32 coderIndex);\r\n \r\n  for each file\r\n  {\r\n    ReInit()\r\n    for each coder\r\n      SetCoderInfo  \r\n    Code\r\n  }\r\n*/\r\n\r\nclass CCoderMixer2MT:\r\n  public ICompressCoder2,\r\n  public CCoderMixer2,\r\n  public CMyUnknownImp\r\n{\r\n  CBindInfo _bindInfo;\r\n  CObjectVector<CStreamBinder> _streamBinders;\r\n  int _progressCoderIndex;\r\n\r\n  void AddCoderCommon();\r\n  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);\r\n  HRESULT ReturnIfError(HRESULT code);\r\npublic:\r\n  CObjectVector<CCoder2> _coders;\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n\r\n  HRESULT SetBindInfo(const CBindInfo &bindInfo);\r\n  void AddCoder(ICompressCoder *coder);\r\n  void AddCoder2(ICompressCoder2 *coder);\r\n  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }\r\n\r\n  void ReInit();\r\n  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)\r\n    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }\r\n  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const\r\n    {  return _streamBinders[binderIndex].ProcessedSize; }\r\n};\r\n\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/CrossThreadProgress.cpp",
    "content": "// CrossThreadProgress.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CrossThreadProgress.h\"\r\n\r\nSTDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  InSize = inSize;\r\n  OutSize = outSize;\r\n  ProgressEvent.Set();\r\n  WaitEvent.Lock();\r\n  return Result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/CrossThreadProgress.h",
    "content": "// CrossThreadProgress.h\r\n\r\n#ifndef __CROSSTHREADPROGRESS_H\r\n#define __CROSSTHREADPROGRESS_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CCrossThreadProgress: \r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  const UInt64 *InSize;\r\n  const UInt64 *OutSize;\r\n  HRESULT Result;\r\n  NWindows::NSynchronization::CAutoResetEvent ProgressEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent WaitEvent;\r\n\r\n  HRes Create()\r\n  {\r\n    RINOK(ProgressEvent.CreateIfNotCreated());\r\n    return WaitEvent.CreateIfNotCreated();\r\n  }\r\n  void Init()\r\n  {\r\n    ProgressEvent.Reset();\r\n    WaitEvent.Reset();\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/DummyOutStream.cpp",
    "content": "// DummyOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DummyOutStream.h\"\r\n\r\nSTDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/DummyOutStream.h",
    "content": "// DummyOutStream.h\r\n\r\n#ifndef __DUMMYOUTSTREAM_H\r\n#define __DUMMYOUTSTREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nclass CDummyOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }\r\n  void Init() { _size = 0; }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/HandlerOut.cpp",
    "content": "// HandlerOutCommon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"HandlerOut.h\"\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\n\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kLZMA2MethodName = L\"LZMA2\";\r\nstatic const wchar_t *kBZip2MethodName = L\"BZip2\";\r\nstatic const wchar_t *kPpmdMethodName = L\"PPMd\";\r\nstatic const wchar_t *kDeflateMethodName = L\"Deflate\";\r\nstatic const wchar_t *kDeflate64MethodName = L\"Deflate64\";\r\n\r\nstatic const wchar_t *kLzmaMatchFinderX1 = L\"HC4\";\r\nstatic const wchar_t *kLzmaMatchFinderX5 = L\"BT4\";\r\n\r\nstatic const UInt32 kLzmaAlgoX1 = 0;\r\nstatic const UInt32 kLzmaAlgoX5 = 1;\r\n\r\nstatic const UInt32 kLzmaDicSizeX1 = 1 << 16;\r\nstatic const UInt32 kLzmaDicSizeX3 = 1 << 20;\r\nstatic const UInt32 kLzmaDicSizeX5 = 1 << 24;\r\nstatic const UInt32 kLzmaDicSizeX7 = 1 << 25;\r\nstatic const UInt32 kLzmaDicSizeX9 = 1 << 26;\r\n\r\nstatic const UInt32 kLzmaFastBytesX1 = 32;\r\nstatic const UInt32 kLzmaFastBytesX7 = 64;\r\n\r\nstatic const UInt32 kPpmdMemSizeX1 = (1 << 22);\r\nstatic const UInt32 kPpmdMemSizeX5 = (1 << 24);\r\nstatic const UInt32 kPpmdMemSizeX7 = (1 << 26);\r\nstatic const UInt32 kPpmdMemSizeX9 = (192 << 20);\r\n\r\nstatic const UInt32 kPpmdOrderX1 = 4;\r\nstatic const UInt32 kPpmdOrderX5 = 6;\r\nstatic const UInt32 kPpmdOrderX7 = 16;\r\nstatic const UInt32 kPpmdOrderX9 = 32;\r\n\r\nstatic const UInt32 kDeflateAlgoX1 = 0;\r\nstatic const UInt32 kDeflateAlgoX5 = 1;\r\n\r\nstatic const UInt32 kDeflateFastBytesX1 = 32;\r\nstatic const UInt32 kDeflateFastBytesX7 = 64;\r\nstatic const UInt32 kDeflateFastBytesX9 = 128;\r\n\r\nstatic const UInt32 kDeflatePassesX1 = 1;\r\nstatic const UInt32 kDeflatePassesX7 = 3;\r\nstatic const UInt32 kDeflatePassesX9 = 10;\r\n\r\nstatic const UInt32 kBZip2NumPassesX1 = 1;\r\nstatic const UInt32 kBZip2NumPassesX7 = 2;\r\nstatic const UInt32 kBZip2NumPassesX9 = 7;\r\n\r\nstatic const UInt32 kBZip2DicSizeX1 = 100000;\r\nstatic const UInt32 kBZip2DicSizeX3 = 500000;\r\nstatic const UInt32 kBZip2DicSizeX5 = 900000;\r\n\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5;\r\n\r\nstatic bool AreEqual(const UString &methodName, const wchar_t *s)\r\n  { return (methodName.CompareNoCase(s) == 0); }\r\n\r\nstatic inline bool IsLZMAMethod(const UString &methodName)\r\n{ \r\n  return \r\n    AreEqual(methodName, kLZMAMethodName) || \r\n    AreEqual(methodName, kLZMA2MethodName); \r\n}\r\n\r\nstatic inline bool IsBZip2Method(const UString &methodName)\r\n  { return AreEqual(methodName, kBZip2MethodName); }\r\n\r\nstatic inline bool IsPpmdMethod(const UString &methodName)\r\n  { return AreEqual(methodName, kPpmdMethodName); }\r\n\r\nstatic inline bool IsDeflateMethod(const UString &methodName)\r\n{ \r\n  return \r\n    AreEqual(methodName, kDeflateMethodName) || \r\n    AreEqual(methodName, kDeflate64MethodName); \r\n}\r\n\r\nstruct CNameToPropID\r\n{\r\n  PROPID PropID;\r\n  VARTYPE VarType;\r\n  const wchar_t *Name;\r\n};\r\n\r\nCNameToPropID g_NameToPropID[] = \r\n{\r\n  { NCoderPropID::kOrder, VT_UI4, L\"O\" },\r\n  { NCoderPropID::kPosStateBits, VT_UI4, L\"PB\" },\r\n  { NCoderPropID::kLitContextBits, VT_UI4, L\"LC\" },\r\n  { NCoderPropID::kLitPosBits, VT_UI4, L\"LP\" },\r\n  { NCoderPropID::kEndMarker, VT_BOOL, L\"eos\" },\r\n\r\n  { NCoderPropID::kNumPasses, VT_UI4, L\"Pass\" },\r\n  { NCoderPropID::kNumFastBytes, VT_UI4, L\"fb\" },\r\n  { NCoderPropID::kMatchFinderCycles, VT_UI4, L\"mc\" },\r\n  { NCoderPropID::kAlgorithm, VT_UI4, L\"a\" },\r\n  { NCoderPropID::kMatchFinder, VT_BSTR, L\"mf\" },\r\n  { NCoderPropID::kNumThreads, VT_UI4, L\"mt\" }\r\n};\r\n\r\nstatic bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp)\r\n{\r\n  if (varType == srcProp.vt)\r\n  {\r\n    destProp = srcProp;\r\n    return true;\r\n  }\r\n  if (varType == VT_UI1)\r\n  {\r\n    if (srcProp.vt == VT_UI4)\r\n    {\r\n      UInt32 value = srcProp.ulVal;\r\n      if (value > 0xFF)\r\n        return false;\r\n      destProp = (Byte)value;\r\n      return true;\r\n    }\r\n  }\r\n  else if (varType == VT_BOOL)\r\n  {\r\n    bool res;\r\n    if (SetBoolProperty(res, srcProp) != S_OK)\r\n      return false;\r\n    destProp = res;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n    \r\nstatic int FindPropIdFromStringName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)\r\n    if (name.CompareNoCase(g_NameToPropID[i].Name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID, \r\n    const NWindows::NCOM::CPropVariant &value)\r\n{\r\n  for (int j = 0; j < oneMethodInfo.Properties.Size(); j++)\r\n    if (oneMethodInfo.Properties[j].Id == propID)\r\n      return;\r\n  CProp property;\r\n  property.Id = propID;\r\n  property.Value = value;\r\n  oneMethodInfo.Properties.Add(property);\r\n}\r\n\r\nvoid COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  if (oneMethodInfo.MethodName.IsEmpty())\r\n    oneMethodInfo.MethodName = kDefaultMethodName;\r\n  \r\n  if (IsLZMAMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 dicSize = \r\n      (level >= 9 ? kLzmaDicSizeX9 : \r\n      (level >= 7 ? kLzmaDicSizeX7 : \r\n      (level >= 5 ? kLzmaDicSizeX5 : \r\n      (level >= 3 ? kLzmaDicSizeX3 : \r\n                    kLzmaDicSizeX1)))); \r\n    \r\n    UInt32 algo = \r\n      (level >= 5 ? kLzmaAlgoX5 : \r\n                    kLzmaAlgoX1); \r\n    \r\n    UInt32 fastBytes = \r\n      (level >= 7 ? kLzmaFastBytesX7 : \r\n                    kLzmaFastBytesX1); \r\n    \r\n    const wchar_t *matchFinder = \r\n      (level >= 5 ? kLzmaMatchFinderX5 : \r\n                    kLzmaMatchFinderX1); \r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsDeflateMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 fastBytes = \r\n      (level >= 9 ? kDeflateFastBytesX9 : \r\n      (level >= 7 ? kDeflateFastBytesX7 : \r\n                    kDeflateFastBytesX1));\r\n    \r\n    UInt32 numPasses = \r\n      (level >= 9 ? kDeflatePassesX9 :  \r\n      (level >= 7 ? kDeflatePassesX7 : \r\n                    kDeflatePassesX1));\r\n    \r\n    UInt32 algo = \r\n      (level >= 5 ? kDeflateAlgoX5 : \r\n                    kDeflateAlgoX1); \r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n  }\r\n  else if (IsBZip2Method(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 numPasses = \r\n      (level >= 9 ? kBZip2NumPassesX9 : \r\n      (level >= 7 ? kBZip2NumPassesX7 :  \r\n                    kBZip2NumPassesX1));\r\n    \r\n    UInt32 dicSize = \r\n      (level >= 5 ? kBZip2DicSizeX5 : \r\n      (level >= 3 ? kBZip2DicSizeX3 : \r\n                    kBZip2DicSizeX1));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsPpmdMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 useMemSize = \r\n      (level >= 9 ? kPpmdMemSizeX9 : \r\n      (level >= 7 ? kPpmdMemSizeX7 : \r\n      (level >= 5 ? kPpmdMemSizeX5 : \r\n                    kPpmdMemSizeX1)));\r\n    \r\n    UInt32 order = \r\n      (level >= 9 ? kPpmdOrderX9 : \r\n      (level >= 7 ? kPpmdOrderX7 : \r\n      (level >= 5 ? kPpmdOrderX5 : \r\n                    kPpmdOrderX1)));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order);\r\n  }\r\n}\r\n\r\nstatic void SplitParams(const UString &srcString, UStringVector &subStrings)\r\n{\r\n  subStrings.Clear();\r\n  UString name;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L':')\r\n    {\r\n      subStrings.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  subStrings.Add(name);\r\n}\r\n\r\nstatic void SplitParam(const UString &param, UString &name, UString &value)\r\n{\r\n  int eqPos = param.Find(L'=');\r\n  if (eqPos >= 0)\r\n  {\r\n    name = param.Left(eqPos);\r\n    value = param.Mid(eqPos + 1);\r\n    return;\r\n  }\r\n  for(int i = 0; i < param.Length(); i++)\r\n  {\r\n    wchar_t c = param[i];\r\n    if (c >= L'0' && c <= L'9')\r\n    {\r\n      name = param.Left(i);\r\n      value = param.Mid(i);\r\n      return;\r\n    }\r\n  }\r\n  name = param;\r\n}\r\n\r\nHRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value)\r\n{\r\n  CProp property;\r\n  if (\r\n    name.CompareNoCase(L\"D\") == 0 || \r\n    name.CompareNoCase(L\"MEM\") == 0)\r\n  {\r\n    UInt32 dicSize;\r\n    RINOK(ParsePropDictionaryValue(value, dicSize));\r\n    if (name.CompareNoCase(L\"D\") == 0)\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n    else\r\n      property.Id = NCoderPropID::kUsedMemorySize;\r\n    property.Value = dicSize;\r\n    oneMethodInfo.Properties.Add(property);\r\n  }\r\n  else\r\n  {\r\n    int index = FindPropIdFromStringName(name);\r\n    if (index < 0)\r\n      return E_INVALIDARG;\r\n    \r\n    const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n    property.Id = nameToPropID.PropID;\r\n    \r\n    NCOM::CPropVariant propValue;\r\n    \r\n    if (nameToPropID.VarType == VT_BSTR)\r\n      propValue = value;\r\n    else if (nameToPropID.VarType == VT_BOOL)\r\n    {\r\n      bool res;\r\n      if (!StringToBool(value, res))\r\n        return E_INVALIDARG;\r\n      propValue = res;\r\n    }\r\n    else\r\n    {\r\n      UInt32 number;\r\n      if (ParseStringToUInt32(value, number) == value.Length())\r\n        propValue = number;\r\n      else\r\n        propValue = value;\r\n    }\r\n    \r\n    if (!ConvertProperty(propValue, nameToPropID.VarType, property.Value))\r\n      return E_INVALIDARG;\r\n    \r\n    oneMethodInfo.Properties.Add(property);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString)\r\n{\r\n  UStringVector params;\r\n  SplitParams(srcString, params);\r\n  if (params.Size() > 0)\r\n    oneMethodInfo.MethodName = params[0];\r\n  for (int i = 1; i < params.Size(); i++)\r\n  {\r\n    const UString &param = params[i];\r\n    UString name, value;\r\n    SplitParam(param, name, value);\r\n    RINOK(SetParam(oneMethodInfo, name, value));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const UString &s)\r\n{\r\n  bool res;\r\n  if (StringToBool(s, res))\r\n  {\r\n    if (res)\r\n      InitSolid();\r\n    else\r\n      _numSolidFiles = 1;\r\n    return S_OK;\r\n  }\r\n  UString s2 = s;\r\n  s2.MakeUpper();\r\n  for (int i = 0; i < s2.Length();)\r\n  {\r\n    const wchar_t *start = ((const wchar_t *)s2) + i;\r\n    const wchar_t *end;\r\n    UInt64 v = ConvertStringToUInt64(start, &end);\r\n    if (start == end)\r\n    {\r\n      if (s2[i++] != 'E')\r\n        return E_INVALIDARG;\r\n      _solidExtension = true;\r\n      continue;\r\n    }\r\n    i += (int)(end - start);\r\n    if (i == s2.Length())\r\n      return E_INVALIDARG;\r\n    wchar_t c = s2[i++];\r\n    switch(c)\r\n    {\r\n      case 'F':\r\n        if (v < 1)\r\n          v = 1;\r\n        _numSolidFiles = v;\r\n        break;\r\n      case 'B':\r\n        _numSolidBytes = v;\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'K':\r\n        _numSolidBytes = (v << 10);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'M':\r\n        _numSolidBytes = (v << 20);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'G':\r\n        _numSolidBytes = (v << 30);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      InitSolid();\r\n      return S_OK;\r\n    case VT_BSTR:\r\n      return SetSolidSettings(value.bstrVal);\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n}\r\n\r\nvoid COutHandler::Init()\r\n{\r\n  _removeSfxBlock = false;\r\n  _compressHeaders = true;\r\n  _encryptHeaders = false;\r\n  \r\n  WriteModified = true;\r\n  WriteCreated = false;\r\n  WriteAccessed = false;\r\n  \r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  \r\n  _level = 5;\r\n  _autoFilter = true;\r\n  _volumeMode = false;\r\n  _crcSize = 4;\r\n  InitSolid();\r\n}\r\n\r\nvoid COutHandler::BeforeSetProperty()\r\n{\r\n  Init();\r\n  #ifdef COMPRESS_MT\r\n  numProcessors = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n\r\n  mainDicSize = 0xFFFFFFFF;\r\n  mainDicMethodIndex = 0xFFFFFFFF;\r\n  minNumber = 0;\r\n  _crcSize = 4;\r\n}\r\n\r\nHRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)\r\n{\r\n  UString name = nameSpec;\r\n  name.MakeUpper();\r\n  if (name.IsEmpty())\r\n    return E_INVALIDARG;\r\n  \r\n  if (name[0] == 'X')\r\n  {\r\n    name.Delete(0);\r\n    _level = 9;\r\n    return ParsePropValue(name, value, _level);\r\n  }\r\n  \r\n  if (name[0] == L'S')\r\n  {\r\n    name.Delete(0);\r\n    if (name.IsEmpty())\r\n      return SetSolidSettings(value);\r\n    if (value.vt != VT_EMPTY)\r\n      return E_INVALIDARG;\r\n    return SetSolidSettings(name);\r\n  }\r\n  \r\n  if (name == L\"CRC\")\r\n  {\r\n    _crcSize = 4;\r\n    name.Delete(0, 3);\r\n    return ParsePropValue(name, value, _crcSize);\r\n  }\r\n  \r\n  UInt32 number;\r\n  int index = ParseStringToUInt32(name, number);\r\n  UString realName = name.Mid(index);\r\n  if (index == 0)\r\n  {\r\n    if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n    {\r\n      #ifdef COMPRESS_MT\r\n      RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n      #endif\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"RSFX\") == 0)\r\n      return SetBoolProperty(_removeSfxBlock, value);\r\n    if (name.CompareNoCase(L\"F\") == 0)\r\n      return SetBoolProperty(_autoFilter, value);\r\n    if (name.CompareNoCase(L\"HC\") == 0)\r\n      return SetBoolProperty(_compressHeaders, value);\r\n    if (name.CompareNoCase(L\"HCF\") == 0)\r\n    {\r\n      bool compressHeadersFull = true;\r\n      RINOK(SetBoolProperty(compressHeadersFull, value));\r\n      if (!compressHeadersFull)\r\n        return E_INVALIDARG;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"HE\") == 0)\r\n      return SetBoolProperty(_encryptHeaders, value);\r\n    if (name.CompareNoCase(L\"TM\") == 0)\r\n      return SetBoolProperty(WriteModified, value);\r\n    if (name.CompareNoCase(L\"TC\") == 0)\r\n      return SetBoolProperty(WriteCreated, value);\r\n    if (name.CompareNoCase(L\"TA\") == 0)\r\n      return SetBoolProperty(WriteAccessed, value);\r\n    if (name.CompareNoCase(L\"V\") == 0)\r\n      return SetBoolProperty(_volumeMode, value);\r\n    number = 0;\r\n  }\r\n  if (number > 10000)\r\n    return E_FAIL;\r\n  if (number < minNumber)\r\n    return E_INVALIDARG;\r\n  number -= minNumber;\r\n  for(int j = _methods.Size(); j <= (int)number; j++)\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    _methods.Add(oneMethodInfo);\r\n  }\r\n  \r\n  COneMethodInfo &oneMethodInfo = _methods[number];\r\n  \r\n  if (realName.Length() == 0)\r\n  {\r\n    if (value.vt != VT_BSTR)\r\n      return E_INVALIDARG;\r\n    \r\n    RINOK(SetParams(oneMethodInfo, value.bstrVal));\r\n  }\r\n  else\r\n  {\r\n    CProp property;\r\n    if (realName.Left(1).CompareNoCase(L\"D\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize));\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n      property.Value = dicSize;\r\n      oneMethodInfo.Properties.Add(property);\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else if (realName.Left(3).CompareNoCase(L\"MEM\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize));\r\n      property.Id = NCoderPropID::kUsedMemorySize;\r\n      property.Value = dicSize;\r\n      oneMethodInfo.Properties.Add(property);\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else\r\n    {\r\n      int index = FindPropIdFromStringName(realName);\r\n      if (index < 0)\r\n        return E_INVALIDARG;\r\n      \r\n      const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n      property.Id = nameToPropID.PropID;\r\n      \r\n      if (!ConvertProperty(value, nameToPropID.VarType, property.Value))\r\n        return E_INVALIDARG;\r\n      \r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n  }\r\n  return S_OK;\r\n}  \r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/HandlerOut.h",
    "content": "// HandlerOut.h\r\n\r\n#ifndef __HANDLER_OUT_H\r\n#define __HANDLER_OUT_H\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\n\r\nstruct COneMethodInfo\r\n{\r\n  CObjectVector<CProp> Properties;\r\n  UString MethodName;\r\n};\r\n\r\nclass COutHandler\r\n{\r\npublic:\r\n  HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);\r\n  \r\n  HRESULT SetSolidSettings(const UString &s);\r\n  HRESULT SetSolidSettings(const PROPVARIANT &value);\r\n\r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  CObjectVector<COneMethodInfo> _methods;\r\n  bool _removeSfxBlock;\r\n  \r\n  UInt64 _numSolidFiles; \r\n  UInt64 _numSolidBytes;\r\n  bool _numSolidBytesDefined;\r\n  bool _solidExtension;\r\n\r\n  bool _compressHeaders;\r\n  bool _encryptHeaders;\r\n\r\n  bool WriteModified;\r\n  bool WriteCreated;\r\n  bool WriteAccessed;\r\n\r\n  bool _autoFilter;\r\n  UInt32 _level;\r\n\r\n  bool _volumeMode;\r\n\r\n  HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value);\r\n  HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);\r\n\r\n  void SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }\r\n  void InitSolidSize()  { _numSolidBytes = (UInt64)(Int64)(-1); }\r\n  void InitSolid()\r\n  {\r\n    InitSolidFiles();\r\n    InitSolidSize();\r\n    _solidExtension = false;\r\n    _numSolidBytesDefined = false;\r\n  }\r\n\r\n  void Init();\r\n\r\n  COutHandler() { Init(); }\r\n\r\n  void BeforeSetProperty();\r\n\r\n  UInt32 minNumber;\r\n  UInt32 numProcessors;\r\n  UInt32 mainDicSize;\r\n  UInt32 mainDicMethodIndex;\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.cpp",
    "content": "// InStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _size += realProcessedSize;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if (seekOrigin != STREAM_SEEK_SET || offset != 0)\r\n    return E_FAIL;\r\n  _size = 0;\r\n  _crc = CRC_INIT_VAL;\r\n  return _stream->Seek(offset, seekOrigin, newPosition);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.h",
    "content": "// InStreamWithCRC.h\r\n\r\n#ifndef __INSTREAMWITHCRC_H\r\n#define __INSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass CSequentialInStreamWithCRC: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CInStreamWithCRC: \r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\nprivate:\r\n  CMyComPtr<IInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(IInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/ItemNameUtils.cpp",
    "content": "// Archive/Common/ItemNameUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\nstatic const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;\r\nstatic const wchar_t kDirDelimiter = L'/';\r\n\r\nUString MakeLegalName(const UString &name)\r\n{\r\n  UString zipName = name;\r\n  zipName.Replace(kOSDirDelimiter, kDirDelimiter);\r\n  return zipName;\r\n}\r\n\r\nUString GetOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(kDirDelimiter, kOSDirDelimiter);\r\n  return newName;\r\n}\r\n\r\nUString GetOSName2(const UString &name)\r\n{\r\n  if (name.IsEmpty())\r\n    return UString();\r\n  UString newName = GetOSName(name);\r\n  if (newName[newName.Length() - 1] == kOSDirDelimiter)\r\n    newName.Delete(newName.Length() - 1);\r\n  return newName;\r\n}\r\n\r\nbool HasTailSlash(const AString &name, UINT codePage)\r\n{\r\n  if (name.IsEmpty())\r\n    return false;\r\n  LPCSTR prev = \r\n  #ifdef _WIN32\r\n    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);\r\n  #else\r\n    (LPCSTR)(name) + (name.Length() - 1);\r\n  #endif\r\n  return (*prev == '/');\r\n}\r\n\r\n#ifndef _WIN32\r\nUString WinNameToOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(L'\\\\', kOSDirDelimiter);\r\n  return newName;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/ItemNameUtils.h",
    "content": "// Archive/Common/ItemNameUtils.h\r\n\r\n#ifndef __ARCHIVE_ITEMNAMEUTILS_H\r\n#define __ARCHIVE_ITEMNAMEUTILS_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\n  UString MakeLegalName(const UString &name);\r\n  UString GetOSName(const UString &name);\r\n  UString GetOSName2(const UString &name);\r\n  bool HasTailSlash(const AString &name, UINT codePage);\r\n\r\n  #ifdef _WIN32\r\n  inline UString WinNameToOSName(const UString &name)  { return name; }\r\n  #else\r\n  UString WinNameToOSName(const UString &name);\r\n  #endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/MultiStream.cpp",
    "content": "// MultiStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MultiStream.h\"\r\n\r\nSTDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(_streamIndex < Streams.Size() && size > 0)\r\n  {\r\n    CSubStreamInfo &s = Streams[_streamIndex];\r\n    if (_pos == s.Size)\r\n    {\r\n      _streamIndex++;\r\n      _pos = 0;\r\n      continue;\r\n    }\r\n    RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));\r\n    UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));\r\n    UInt32 realProcessed;\r\n    HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _pos += realProcessed;\r\n    _seekPos += realProcessed;\r\n    RINOK(result);\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 newPos;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      newPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      newPos = _seekPos + offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      newPos = _totalLength + offset;\r\n      break;\r\n    default:\r\n      return STG_E_INVALIDFUNCTION;\r\n  }\r\n  _seekPos = 0;\r\n  for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)\r\n  {\r\n    UInt64 size = Streams[_streamIndex].Size;\r\n    if (newPos < _seekPos + size)\r\n    {\r\n      _pos = newPos - _seekPos;\r\n      _seekPos += _pos;\r\n      if (newPosition != 0)\r\n        *newPosition = newPos;\r\n      return S_OK;\r\n    }\r\n    _seekPos += size;\r\n  }\r\n  if (newPos == _seekPos)\r\n  {\r\n    if (newPosition != 0)\r\n      *newPosition = newPos;\r\n    return S_OK;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\n\r\n/*\r\nclass COutVolumeStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback, \r\n      const UString &name)  \r\n  { \r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n*/\r\n\r\n/*\r\nSTDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));\r\n      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));\r\n      subStream.Pos = 0;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n    if (_offsetPos >= subStream.Size)\r\n    {\r\n      _offsetPos -= subStream.Size;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      CMyComPtr<IOutStream> outStream;\r\n      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == subStream.Size)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/MultiStream.h",
    "content": "// MultiStream.h\r\n\r\n#ifndef __MULTISTREAM_H\r\n#define __MULTISTREAM_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nclass CMultiStream: \r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex;\r\n  UInt64 _pos;\r\n  UInt64 _seekPos;\r\n  UInt64 _totalLength;\r\npublic:\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<IInStream> Stream;\r\n    UInt64 Pos;\r\n    UInt64 Size;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _pos = 0;\r\n    _seekPos = 0;\r\n    _totalLength = 0;\r\n    for (int i = 0; i < Streams.Size(); i++)\r\n      _totalLength += Streams[i].Size;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n\r\n/*\r\nclass COutMultiStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<ISequentialOutStream> Stream;\r\n    UInt64 Size;\r\n    UInt64 Pos;\r\n };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp",
    "content": "// OutStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  if (_calculate)\r\n    _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.h",
    "content": "// OutStreamWithCRC.h\r\n\r\n#ifndef __OUTSTREAMWITHCRC_H\r\n#define __OUTSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass COutStreamWithCRC: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _calculate;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(bool calculate = true)\r\n  {\r\n    _size = 0;\r\n    _calculate = calculate;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void InitCRC() { _crc = CRC_INIT_VAL; }\r\n  UInt64 GetSize() const { return _size; }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/ParseProperties.cpp",
    "content": "// ParseProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ParseProperties.h\"\r\n\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (prop.vt == VT_UI4)\r\n  {\r\n    if (!name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    resValue = prop.ulVal;\r\n  }\r\n  else if (prop.vt == VT_EMPTY)\r\n  {\r\n    if(!name.IsEmpty())\r\n    {\r\n      const wchar_t *start = name;\r\n      const wchar_t *end;\r\n      UInt64 v = ConvertStringToUInt64(start, &end);\r\n      if (end - start != name.Length())\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)v;\r\n    }\r\n  }\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kLogarithmicSizeLimit = 32;\r\nstatic const wchar_t kByteSymbol = L'B';\r\nstatic const wchar_t kKiloByteSymbol = L'K';\r\nstatic const wchar_t kMegaByteSymbol = L'M';\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)\r\n{\r\n  UString srcString = srcStringSpec;\r\n  srcString.MakeUpper();\r\n\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || srcString.Length() > numDigits + 1)\r\n    return E_INVALIDARG;\r\n  if (srcString.Length() == numDigits)\r\n  {\r\n    if (number >= kLogarithmicSizeLimit)\r\n      return E_INVALIDARG;\r\n    dicSize = (UInt32)1 << (int)number;\r\n    return S_OK;\r\n  }\r\n  switch (srcString[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      if (number >= ((UInt64)1 << kLogarithmicSizeLimit))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)number;\r\n      break;\r\n    case kKiloByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 10);\r\n      break;\r\n    case kMegaByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 20);\r\n      break;\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    if (prop.vt == VT_UI4)\r\n    {\r\n      UInt32 logDicSize = prop.ulVal;\r\n      if (logDicSize >= 32)\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)1 << logDicSize;\r\n      return S_OK;\r\n    }\r\n    if (prop.vt == VT_BSTR)\r\n      return ParsePropDictionaryValue(prop.bstrVal, resValue);\r\n    return E_INVALIDARG;\r\n  }\r\n  return ParsePropDictionaryValue(name, resValue);\r\n}\r\n\r\nbool StringToBool(const UString &s, bool &res)\r\n{\r\n  if (s.IsEmpty() || s.CompareNoCase(L\"ON\") == 0)\r\n  {\r\n    res = true;\r\n    return true;\r\n  }\r\n  if (s.CompareNoCase(L\"OFF\") == 0)\r\n  {\r\n    res = false;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      dest = true;\r\n      return S_OK;\r\n    /*\r\n    case VT_UI4:\r\n      dest = (value.ulVal != 0);\r\n      break;\r\n    */\r\n    case VT_BSTR:\r\n      return StringToBool(value.bstrVal, dest) ?  S_OK : E_INVALIDARG;\r\n  }\r\n  return E_INVALIDARG;\r\n}\r\n\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number)\r\n{\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number64 = ConvertStringToUInt64(start, &end);\r\n  if (number64 > 0xFFFFFFFF) \r\n  {\r\n    number = 0;\r\n    return 0;\r\n  }\r\n  number = (UInt32)number64;\r\n  return (int)(end - start);\r\n}\r\n\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    switch(prop.vt)\r\n    {\r\n      case VT_UI4:\r\n        numThreads = prop.ulVal;\r\n        break;\r\n      default:\r\n      {\r\n        bool val; \r\n        RINOK(SetBoolProperty(val, prop));\r\n        numThreads = (val ? defaultNumThreads : 1);\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index != name.Length())\r\n      return E_INVALIDARG;\r\n    numThreads = number;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/Common/ParseProperties.h",
    "content": "// ParseProperties.h\r\n\r\n#ifndef __PARSEPROPERTIES_H\r\n#define __PARSEPROPERTIES_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\n\r\nbool StringToBool(const UString &s, bool &res);\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number);\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/DllExports2.cpp",
    "content": "// DLLExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyInitGuid.h\"\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\nextern \"C\" \r\n{ \r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nHINSTANCE g_hInstance;\r\n#ifndef _UNICODE\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)\r\n{\r\n  if (dwReason == DLL_PROCESS_ATTACH)\r\n  {\r\n    g_hInstance = hInstance;\r\n    #ifndef _UNICODE\r\n    #ifdef _WIN32\r\n    g_IsNT = IsItWindowsNT();\r\n    #endif\r\n    #endif\r\n  }\r\n  return TRUE;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler, \r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec, \r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);\r\nSTDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);\r\n\r\nSTDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  // COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)\r\n  {\r\n    return CreateCoder(clsid, iid, outObject);\r\n  }\r\n  else\r\n  {\r\n    return CreateArchiver(clsid, iid, outObject);\r\n  }\r\n  // COM_TRY_END\r\n}\r\n\r\nSTDAPI SetLargePageMode()\r\n{\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  SetLargePageSize();\r\n  #endif\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Archive/IArchive.h",
    "content": "// IArchive.h\r\n\r\n#ifndef __IARCHIVE_H\r\n#define __IARCHIVE_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../IProgress.h\"\r\n#include \"../PropID.h\"\r\n\r\n#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)\r\n#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nnamespace NFileTimeType\r\n{\r\n  enum EEnum\r\n  {\r\n    kWindows,\r\n    kUnix,\r\n    kDOS\r\n  };\r\n}\r\n\r\nnamespace NArchive\r\n{\r\n  enum \r\n  {\r\n    kName = 0,\r\n    kClassID,\r\n    kExtension,\r\n    kAddExtension,\r\n    kUpdate,\r\n    kKeepName,\r\n    kStartSignature,\r\n    kFinishSignature,\r\n    kAssociate\r\n  };\r\n\r\n  namespace NExtract\r\n  {\r\n    namespace NAskMode\r\n    {\r\n      enum \r\n      {\r\n        kExtract = 0,\r\n        kTest,\r\n        kSkip\r\n      };\r\n    }\r\n    namespace NOperationResult\r\n    {\r\n      enum \r\n      {\r\n        kOK = 0,\r\n        kUnSupportedMethod,\r\n        kDataError,\r\n        kCRCError\r\n      };\r\n    }\r\n  }\r\n  namespace NUpdate\r\n  {\r\n    namespace NOperationResult\r\n    {\r\n      enum \r\n      {\r\n        kOK = 0,\r\n        kError\r\n      };\r\n    }\r\n  }\r\n}\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)\r\n{\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, \r\n      Int32 askExtractMode) PURE;\r\n  // GetStream OUT: S_OK - OK, S_FALSE - skeep this file\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)\r\n{\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;  \r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)\r\n{\r\n  STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;\r\n};\r\n\r\n\r\n/*\r\nIInArchive::Extract:\r\n  indices must be sorted \r\n  numItems = 0xFFFFFFFF means \"all files\"\r\n  testMode != 0 means \"test files without writing to outStream\"\r\n*/\r\n\r\n#define INTERFACE_IInArchive(x) \\\r\n  STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \\\r\n  STDMETHOD(Close)() x; \\\r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \\\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \\\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;\r\n\r\nARCHIVE_INTERFACE(IInArchive, 0x60)\r\n{\r\n  INTERFACE_IInArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)\r\n{\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index, \r\n      Int32 *newData, // 1 - new data, 0 - old data\r\n      Int32 *newProperties, // 1 - new properties, 0 - old properties\r\n      UInt32 *indexInArchive // -1 if there is no in archive, or if doesn't matter\r\n      ) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)\r\n{\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) PURE;\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) PURE;\r\n};\r\n\r\n\r\n#define INTERFACE_IOutArchive(x) \\\r\n  STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \\\r\n  STDMETHOD(GetFileTimeType)(UInt32 *type) x;\r\n\r\nARCHIVE_INTERFACE(IOutArchive, 0xA0)\r\n{\r\n  INTERFACE_IOutArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(ISetProperties, 0x03)\r\n{\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;\r\n};\r\n\r\n\r\n#define IMP_IInArchive_GetProp(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \\\r\n\r\n#define IMP_IInArchive_GetProp_WITH_NAME(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; \\\r\n    if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \\\r\n\r\n#define IMP_IInArchive_Props \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)\r\n\r\n#define IMP_IInArchive_Props_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)\r\n\r\n\r\n#define IMP_IInArchive_ArcProps \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_NO \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = 0; return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \\\r\n    { return E_NOTIMPL; } \\\r\n  STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \\\r\n    { value->vt = VT_EMPTY; return S_OK; } \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Alone\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Alone - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\" CFG=\"Alone - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Alone - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Alone - Win32 Release\"\r\n# Name \"Alone - Win32 Debug\"\r\n# Name \"Alone - Win32 ReleaseU\"\r\n# Name \"Alone - Win32 DebugU\"\r\n# Begin Group \"Console\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ArError.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\CompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\Main.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\MainAr.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\AutoPtr.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Buffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ComTry.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\DynamicBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyException.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyGuidDef.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyInitGuid.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Device.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Handle.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MSBFDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MSBFEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterArc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterCodec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\Coder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86_2.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86_2.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Copy\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Copy\\CopyCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Copy\\CopyCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Copy\\CopyRegister.cpp\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZ\\LZOutWindow.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMADecoder.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMAEncoder.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMARegister.cpp\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderBit.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_Alone\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Archive\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"7z\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zExtract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"split\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"UI Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Property.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7-zip\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IMyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IPassword.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\PropID.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"C Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARM.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARM.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARMThumb.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARMThumb.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchIA64.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchIA64.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchPPC.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchPPC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchSPARC.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchSPARC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Alone\"=.\\Alone.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Alone7z/makefile",
    "content": "PROG = 7za.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib Advapi32.lib\r\n\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -D_NO_CRYPTO \\\r\n  -DWIN_LONG_PATH \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OffsetStream.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\DummyOutStream.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\MultiStream.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n\r\n\r\nBRANCH_OPT_OBJS = \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\x86.obj \\\r\n  $O\\x86_2.obj \\\r\n  $O\\ARM.obj \\\r\n  $O\\ARMThumb.obj \\\r\n  $O\\IA64.obj \\\r\n  $O\\PPC.obj \\\r\n  $O\\SPARC.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\BCJRegister.obj \\\r\n  $O\\BCJ2Register.obj \\\r\n\r\nSWAP_OPT_OBJS = \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n\r\nCOPY_OBJS = \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n  $O\\LZMARegister.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Sort.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZ_OBJS = \\\r\n  $O\\MatchFinder.obj \\\r\n  $O\\MatchFinderMt.obj \\\r\n\r\nC_BRANCH_OBJS = \\\r\n  $O\\BranchARM.obj \\\r\n  $O\\BranchARMThumb.obj \\\r\n  $O\\BranchIA64.obj \\\r\n  $O\\BranchPPC.obj \\\r\n  $O\\BranchSPARC.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(BRANCH_OPT_OBJS) \\\r\n  $(SWAP_OPT_OBJS) \\\r\n  $(COPY_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZ_OBJS) \\\r\n  $(C_BRANCH_OBJS) \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): ../../UI/Console/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../../UI/Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Alone7z/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_APP(\"7-Zip Standalone Console\", \"7za\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Format7zExtractR/makefile",
    "content": "PROG = 7zxr.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DEXTRACT_ONLY \\\r\n  -DCOMPRESS_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n\r\nSWAP_OPT_OBJS = \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n\r\nBRANCH_OPT_OBJS = \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\x86.obj \\\r\n  $O\\x86_2.obj \\\r\n  $O\\ARM.obj \\\r\n  $O\\ARMThumb.obj \\\r\n  $O\\IA64.obj \\\r\n  $O\\PPC.obj \\\r\n  $O\\SPARC.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\BCJRegister.obj \\\r\n  $O\\BCJ2Register.obj \\\r\n\r\nCOPY_OBJS = \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMARegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_BRANCH_OBJS = \\\r\n  $O\\BranchARM.obj \\\r\n  $O\\BranchARMThumb.obj \\\r\n  $O\\BranchIA64.obj \\\r\n  $O\\BranchPPC.obj \\\r\n  $O\\BranchSPARC.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(BRANCH_OPT_OBJS) \\\r\n  $(SWAP_OPT_OBJS) \\\r\n  $(COPY_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_BRANCH_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Format7zExtractR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Extracting Plugin\", \"7zxr\")\r\n\r\n101  ICON  \"../../Archive/7z/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Format7zR/makefile",
    "content": "PROG = 7zra.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n\r\nBRANCH_OPT_OBJS = \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\x86.obj \\\r\n  $O\\x86_2.obj \\\r\n  $O\\ARM.obj \\\r\n  $O\\ARMThumb.obj \\\r\n  $O\\IA64.obj \\\r\n  $O\\PPC.obj \\\r\n  $O\\SPARC.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\BCJRegister.obj \\\r\n  $O\\BCJ2Register.obj \\\r\n\r\nSWAP_OPT_OBJS = \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n\r\nCOPY_OBJS = \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n  $O\\LZMARegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Sort.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZ_OBJS = \\\r\n  $O\\MatchFinder.obj \\\r\n  $O\\MatchFinderMt.obj \\\r\n\r\nC_BRANCH_OBJS = \\\r\n  $O\\BranchARM.obj \\\r\n  $O\\BranchARMThumb.obj \\\r\n  $O\\BranchIA64.obj \\\r\n  $O\\BranchPPC.obj \\\r\n  $O\\BranchSPARC.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(BZIP2_OBJS) \\\r\n  $(BZIP2_OPT_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(BRANCH_OPT_OBJS) \\\r\n  $(SWAP_OPT_OBJS) \\\r\n  $(COPY_OBJS) \\\r\n  $(DEFLATE_OPT_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(PPMD_OPT_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZ_OBJS) \\\r\n  $(C_BRANCH_OBJS) \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$O\\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Bundles/Format7zR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Plugin\", \"7zr\")\r\n\r\n101  ICON  \"../../Archive/7z/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/CreateCoder.cpp",
    "content": "// CreateCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CreateCoder.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Windows/Defs.h\"\r\n#include \"FilterCoder.h\"\r\n#include \"RegisterCodec.h\"\r\n\r\nstatic const unsigned int kNumCodecsMax = 64;\r\nunsigned int g_NumCodecs = 0;\r\nconst CCodecInfo *g_Codecs[kNumCodecsMax]; \r\nvoid RegisterCodec(const CCodecInfo *codecInfo) \r\n{ \r\n  if (g_NumCodecs < kNumCodecsMax)\r\n    g_Codecs[g_NumCodecs++] = codecInfo; \r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = 1;\r\n  else if (prop.vt == VT_UI4)\r\n    res = prop.ulVal;\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = true;\r\n  else if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs)\r\n{\r\n  UInt32 num;\r\n  RINOK(codecsInfo->GetNumberOfMethods(&num));\r\n  for (UInt32 i = 0; i < num; i++)\r\n  {\r\n    CCodecInfoEx info;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kID, &prop));\r\n    // if (prop.vt != VT_BSTR)\r\n    // info.Id.IDSize = (Byte)SysStringByteLen(prop.bstrVal);\r\n    // memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);\r\n    if (prop.vt != VT_UI8)\r\n    {\r\n      continue; // old Interface \r\n      // return E_INVALIDARG;\r\n    }\r\n    info.Id = prop.uhVal.QuadPart;\r\n    prop.Clear();\r\n    \r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      info.Name = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_INVALIDARG;;\r\n    \r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kInStreams, info.NumInStreams));\r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kOutStreams, info.NumOutStreams));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned));\r\n    \r\n    externalCodecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  const UString &name,\r\n  CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i]; \r\n    if (name.CompareNoCase(codec.Name) == 0)\r\n    {\r\n      methodId = codec.Id;\r\n      numInStreams = codec.NumInStreams;\r\n      numOutStreams = 1;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i]; \r\n      if (codec.Name.CompareNoCase(name) == 0)\r\n      {\r\n        methodId = codec.Id;\r\n        numInStreams = codec.NumInStreams;\r\n        numOutStreams = codec.NumOutStreams;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  CMethodId methodId, UString &name)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i]; \r\n    if (methodId == codec.Id)\r\n    {\r\n      name = codec.Name;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i]; \r\n      if (methodId == codec.Id)\r\n      {\r\n        name = codec.Name;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder)\r\n{\r\n  bool created = false;\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i]; \r\n    if (codec.Id == methodId)\r\n    {\r\n      if (encode)\r\n      {\r\n        if (codec.CreateEncoder)\r\n        {\r\n          void *p = codec.CreateEncoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n      }\r\n      else\r\n        if (codec.CreateDecoder)\r\n        {\r\n          void *p = codec.CreateDecoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  if (!created && externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i]; \r\n      if (codec.Id == methodId)\r\n      {\r\n        if (encode)\r\n        {\r\n          if (codec.EncoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE) \r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n        }\r\n        else\r\n          if (codec.DecoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE) \r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n      }\r\n    }\r\n  #endif\r\n\r\n  if (onlyCoder && filter)\r\n  {\r\n    CFilterCoder *coderSpec = new CFilterCoder;\r\n    coder = coderSpec;\r\n    coderSpec->Filter = filter;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, \r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, true);\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    coder, coder2, encode);\r\n}\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressCoder> coder;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, false);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/CreateCoder.h",
    "content": "// CreateCoder.h\r\n\r\n#ifndef __CREATECODER_H\r\n#define __CREATECODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nstruct CCodecInfoEx\r\n{\r\n  UString Name;\r\n  CMethodId Id;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }\r\n  CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}\r\n};\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)\r\n#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);\r\n#define IMPL_ISetCompressCodecsInfo2(x) \\\r\nSTDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \\\r\n  COM_TRY_BEGIN _codecsInfo = compressCodecsInfo;  return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }\r\n#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)\r\n\r\n#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs\r\n#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,\r\n#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,\r\n\r\n#else\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo\r\n#define DECL_ISetCompressCodecsInfo\r\n#define IMPL_ISetCompressCodecsInfo\r\n#define EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_VARS\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2\r\n#define EXTERNAL_CODECS_LOC_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS\r\n#define EXTERNAL_CODECS_LOC_VARS\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, UString &name);\r\n\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, \r\n  CMyComPtr<ICompressCoder> &coder, bool encode);\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/FilePathAutoRename.cpp",
    "content": "// FilePathAutoRename.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"FilePathAutoRename.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic bool MakeAutoName(const UString &name, \r\n    const UString &extension, int value, UString &path)\r\n{\r\n  wchar_t number[32];\r\n  ConvertUInt64ToString(value, number);\r\n  path = name;\r\n  path += number;\r\n  path += extension;\r\n  return NFile::NFind::DoesFileExist(path);\r\n}\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath)\r\n{\r\n  UString path;\r\n  int dotPos = fullProcessedPath.ReverseFind(L'.');\r\n\r\n  int slashPos = fullProcessedPath.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = fullProcessedPath.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n\r\n  UString name, extension;\r\n  if (dotPos > slashPos &&  dotPos > 0)\r\n  {\r\n    name = fullProcessedPath.Left(dotPos);\r\n    extension = fullProcessedPath.Mid(dotPos);\r\n  }\r\n  else\r\n    name = fullProcessedPath;\r\n  name += L'_';\r\n  int indexLeft = 1, indexRight = (1 << 30);\r\n  while (indexLeft != indexRight)\r\n  {\r\n    int indexMid = (indexLeft + indexRight) / 2;\r\n    if (MakeAutoName(name, extension, indexMid, path))\r\n      indexLeft = indexMid + 1;\r\n    else\r\n      indexRight = indexMid;\r\n  }\r\n  if (MakeAutoName(name, extension, indexRight, fullProcessedPath))\r\n    return false;\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/FilePathAutoRename.h",
    "content": "// Util/FilePathAutoRename.h\r\n\r\n#ifndef __FILEPATHAUTORENAME_H\r\n#define __FILEPATHAUTORENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  #ifdef _WIN32\r\n  if (result)\r\n    return S_OK;\r\n  DWORD lastError = ::GetLastError();\r\n  if (lastError == 0)\r\n    return E_FAIL;\r\n  return lastError;\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nbool CInFileStream::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), \r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nHRESULT COutFileStream::Close()\r\n{\r\n  return ConvertBoolToHRESULT(File.Close());\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  ProcessedSize += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  ProcessedSize += res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15); \r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), \r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WIN_FILE\r\n#endif\r\n\r\n#ifdef USE_WIN_FILE\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\npublic:\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #endif\r\n  #endif\r\n\r\n  HRESULT Close();\r\n  \r\n  UInt64 ProcessedSize;\r\n\r\n  #ifdef USE_WIN_FILE\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  {\r\n    return File.SetTime(creationTime, lastAccessTime, lastWriteTime);\r\n  }\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {\r\n    return File.SetLastWriteTime(lastWriteTime);\r\n  }\r\n  #endif\r\n\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/FilterCoder.cpp",
    "content": "// FilterCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FilterCoder.h\"\r\nextern \"C\" \r\n{ \r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#include \"../../Common/Defs.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCFilterCoder::CFilterCoder()\r\n{ \r\n  _buffer = (Byte *)::MidAlloc(kBufferSize); \r\n}\r\n\r\nCFilterCoder::~CFilterCoder() \r\n{ \r\n  ::MidFree(_buffer); \r\n}\r\n\r\nHRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)\r\n{\r\n  if (_outSizeIsDefined)\r\n  {\r\n    UInt64 remSize = _outSize - _nowPos64;\r\n    if (size > remSize)\r\n      size = (UInt32)remSize;\r\n  }\r\n  UInt32 processedSize = 0;\r\n  RINOK(WriteStream(outStream, _buffer, size, &processedSize));\r\n  if (size != processedSize)\r\n    return E_FAIL;\r\n  _nowPos64 += processedSize;\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  RINOK(Init());\r\n  UInt32 bufferPos = 0;\r\n  _outSizeIsDefined = (outSize != 0);\r\n  if (_outSizeIsDefined)\r\n    _outSize = *outSize;\r\n\r\n  while(NeedMore())\r\n  {\r\n    UInt32 processedSize;\r\n    \r\n    // Change it: It can be optimized using ReadPart\r\n    RINOK(ReadStream(inStream, _buffer + bufferPos, kBufferSize - bufferPos, &processedSize));\r\n    \r\n    UInt32 endPos = bufferPos + processedSize;\r\n\r\n    bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (bufferPos > endPos)\r\n    {\r\n      for (; endPos< bufferPos; endPos++)\r\n        _buffer[endPos] = 0;\r\n      bufferPos = Filter->Filter(_buffer, endPos);\r\n    }\r\n\r\n    if (bufferPos == 0)\r\n    {\r\n      if (endPos > 0)\r\n        return WriteWithLimit(outStream, endPos);\r\n      return S_OK;\r\n    }\r\n    RINOK(WriteWithLimit(outStream, bufferPos));\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));\r\n    }\r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n// #ifdef _ST_MODE\r\nSTDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _bufferPos = 0;\r\n  _outStream = outStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseOutStream()\r\n{\r\n  _outStream.Release();\r\n  return S_OK;\r\n};\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    UInt32 sizeMax = kBufferSize - _bufferPos;\r\n    UInt32 sizeTemp = size;\r\n    if (sizeTemp > sizeMax)\r\n      sizeTemp = sizeMax;\r\n    memmove(_buffer + _bufferPos, data, sizeTemp);\r\n    size -= sizeTemp;\r\n    processedSizeTotal += sizeTemp;\r\n    data = (const Byte *)data + sizeTemp;\r\n    UInt32 endPos = _bufferPos + sizeTemp;\r\n    _bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (_bufferPos == 0)\r\n    {\r\n      _bufferPos = endPos;\r\n      break;\r\n    }\r\n    if (_bufferPos > endPos)\r\n    {\r\n      if (size != 0)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    RINOK(WriteWithLimit(_outStream, _bufferPos));\r\n    UInt32 i = 0;\r\n    while(_bufferPos < endPos)\r\n      _buffer[i++] = _buffer[_bufferPos++];\r\n    _bufferPos = i;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::Flush()\r\n{\r\n  if (_bufferPos != 0)\r\n  {\r\n    UInt32 endPos = Filter->Filter(_buffer, _bufferPos);\r\n    if (endPos > _bufferPos)\r\n    {\r\n      for (; _bufferPos < endPos; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      if (Filter->Filter(_buffer, endPos) != endPos)\r\n        return E_FAIL;\r\n    }\r\n    UInt32 processedSize;\r\n    RINOK(WriteStream(_outStream, _buffer, _bufferPos, &processedSize));\r\n    if (_bufferPos != processedSize)\r\n      return E_FAIL;\r\n    _bufferPos = 0;\r\n  }\r\n  CMyComPtr<IOutStreamFlush> flush;\r\n  _outStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n  if (flush)\r\n    return  flush->Flush();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _convertedPosBegin = _convertedPosEnd = _bufferPos = 0;\r\n  _inStream = inStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseInStream()\r\n{\r\n  _inStream.Release();\r\n  return S_OK;\r\n};\r\n\r\nSTDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_convertedPosBegin != _convertedPosEnd)\r\n    {\r\n      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);\r\n      memmove(data, _buffer + _convertedPosBegin, sizeTemp);\r\n      _convertedPosBegin += sizeTemp;\r\n      data = (void *)((Byte *)data + sizeTemp);\r\n      size -= sizeTemp;\r\n      processedSizeTotal += sizeTemp;\r\n      break;\r\n    }\r\n    int i;\r\n    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)\r\n      _buffer[i] = _buffer[i + _convertedPosEnd];\r\n    _bufferPos = i;\r\n    _convertedPosBegin = _convertedPosEnd = 0;\r\n    UInt32 processedSizeTemp;\r\n    UInt32 size0 = kBufferSize - _bufferPos;\r\n    // Optimize it:\r\n    RINOK(ReadStream(_inStream, _buffer + _bufferPos, size0, &processedSizeTemp));\r\n    _bufferPos = _bufferPos + processedSizeTemp;\r\n    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    if (_convertedPosEnd == 0)\r\n    {\r\n      if (_bufferPos == 0)\r\n        break;\r\n      else\r\n      {\r\n        _convertedPosEnd = _bufferPos; // check it\r\n        continue;\r\n      }\r\n    }\r\n    if (_convertedPosEnd > _bufferPos)\r\n    {\r\n      for (; _bufferPos < _convertedPosEnd; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\n// #endif // _ST_MODE\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)\r\n{\r\n  return _setPassword->CryptoSetPassword(data, size);\r\n}\r\n#endif\r\n\r\n#ifndef EXTRACT_ONLY\r\nSTDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  return _writeCoderProperties->WriteCoderProperties(outStream);\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CFilterCoder::ResetSalt()\r\n{\r\n  return _CryptoResetSalt->ResetSalt();\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CFilterCoder::ResetInitVector()\r\n{\r\n  return _CryptoResetInitVector->ResetInitVector();\r\n}\r\n#endif\r\n\r\nSTDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)\r\n{\r\n  return _setDecoderProperties->SetDecoderProperties2(data, size);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/FilterCoder.h",
    "content": "// FilterCoder.h\r\n\r\n#ifndef __FILTERCODER_H\r\n#define __FILTERCODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \\\r\n{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \\\r\n*outObject = (void *)(i *)this; AddRef(); return S_OK; } \r\n\r\nclass CFilterCoder:\r\n  public ICompressCoder,\r\n  // #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ISequentialInStream,\r\n  public ICompressSetOutStream,\r\n  public ISequentialOutStream,\r\n  public IOutStreamFlush,\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoSetPassword,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  // public ICryptoResetSalt,\r\n  public ICryptoResetInitVector,\r\n  #endif\r\n  public ICompressSetDecoderProperties2,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  // #ifdef _ST_MODE\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  CMyComPtr<ISequentialOutStream> _outStream;\r\n  UInt32 _bufferPos;\r\n  UInt32 _convertedPosBegin;\r\n  UInt32 _convertedPosEnd;\r\n  // #endif\r\n  bool _outSizeIsDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _nowPos64;\r\n\r\n  HRESULT Init() \r\n  { \r\n    _nowPos64 = 0;\r\n    _outSizeIsDefined = false;\r\n    return Filter->Init(); \r\n  }\r\n\r\n  CMyComPtr<ICryptoSetPassword> _setPassword;\r\n  #ifndef EXTRACT_ONLY\r\n  CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;\r\n  CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;\r\n  // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;\r\n  CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;\r\n  #endif\r\n  CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;\r\npublic:\r\n  CMyComPtr<ICompressFilter> Filter;\r\n\r\n  CFilterCoder();\r\n  ~CFilterCoder();\r\n  HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);\r\n  bool NeedMore() const  \r\n    { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }\r\n\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n    MY_QUERYINTERFACE_ENTRY(ICompressCoder)\r\n    // #ifdef _ST_MODE\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialInStream)\r\n\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)\r\n    // #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)\r\n    #endif\r\n\r\n    #ifndef EXTRACT_ONLY\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)\r\n    // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)\r\n    #endif\r\n\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  // #ifdef _ST_MODE\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \\\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Flush)();\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  // STDMETHOD(ResetSalt)();\r\n  STDMETHOD(ResetInitVector)();\r\n  #endif\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n};\r\n\r\n// #ifdef _ST_MODE\r\nclass CInStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  CInStreamReleaser(): FilterCoder(0) {}\r\n  ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }\r\n};\r\n\r\nclass COutStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  COutStreamReleaser(): FilterCoder(0) {}\r\n  ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }\r\n};\r\n// #endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nCInBuffer::CInBuffer(): \r\n  _buffer(0), \r\n  _bufferLimit(0), \r\n  _bufferBase(0), \r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct CInBufferException: public CSystemException \r\n{\r\n  CInBufferException(HRESULT errorCode): CSystemException(errorCode) {} \r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      if(!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)\r\n  {\r\n    for(processedSize = 0; processedSize < size; processedSize++)\r\n      if (!ReadByte(((Byte *)data)[processedSize]))\r\n        return;\r\n  }\r\n  bool ReadBytes(void *data, UInt32 size)\r\n  {\r\n    UInt32 processedSize;\r\n    ReadBytes(data, size, processedSize);\r\n    return (processedSize == size);\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/InOutTempBuffer.cpp",
    "content": "// InOutTempBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InOutTempBuffer.h\"\r\n#include \"../../Common/Defs.h\"\r\n// #include \"Windows/Defs.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic UInt32 kTmpBufferMemorySize = (1 << 20);\r\n\r\nstatic LPCTSTR kTempFilePrefixString = TEXT(\"iot\");\r\n\r\nCInOutTempBuffer::CInOutTempBuffer():\r\n  _buffer(NULL)\r\n{\r\n}\r\n\r\nvoid CInOutTempBuffer::Create()\r\n{\r\n  _buffer = new Byte[kTmpBufferMemorySize];\r\n}\r\n\r\nCInOutTempBuffer::~CInOutTempBuffer()\r\n{\r\n  delete []_buffer;\r\n}\r\nvoid CInOutTempBuffer::InitWriting()\r\n{\r\n  _bufferPosition = 0;\r\n  _tmpFileCreated = false;\r\n  _fileSize = 0;\r\n}\r\n\r\nbool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)\r\n{\r\n  if (size == 0)\r\n    return true;\r\n  if(!_tmpFileCreated)\r\n  {\r\n    CSysString tempDirPath;\r\n    if(!MyGetTempPath(tempDirPath))\r\n      return false;\r\n    if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)\r\n      return false;\r\n    // _outFile.SetOpenCreationDispositionCreateAlways();\r\n    if(!_outFile.Create(_tmpFileName, true))\r\n      return false;\r\n    _tmpFileCreated = true;\r\n  }\r\n  UInt32 processedSize;\r\n  if(!_outFile.Write(data, size, processedSize))\r\n    return false;\r\n  _fileSize += processedSize;\r\n  return (processedSize == size);\r\n}\r\n\r\nbool CInOutTempBuffer::FlushWrite()\r\n{\r\n  return _outFile.Close();\r\n}\r\n\r\nbool CInOutTempBuffer::Write(const void *data, UInt32 size)\r\n{\r\n  if(_bufferPosition < kTmpBufferMemorySize)\r\n  {\r\n    UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);\r\n    memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);\r\n    _bufferPosition += curSize;\r\n    size -= curSize;\r\n    data = ((const Byte *)data) + curSize;\r\n    _fileSize += curSize;\r\n  }\r\n  return WriteToFile(data, size);\r\n}\r\n\r\nbool CInOutTempBuffer::InitReading()\r\n{\r\n  _currentPositionInBuffer = 0;\r\n  if(_tmpFileCreated)\r\n    return _inFile.Open(_tmpFileName);\r\n  return true;\r\n}\r\n\r\nHRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)\r\n{\r\n  if (_currentPositionInBuffer < _bufferPosition)\r\n  {\r\n    UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;\r\n    RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite, NULL));\r\n    _currentPositionInBuffer += sizeToWrite;\r\n  }\r\n  if (!_tmpFileCreated)\r\n    return true;\r\n  for (;;)\r\n  {\r\n    UInt32 localProcessedSize;\r\n    if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))\r\n      return E_FAIL;\r\n    if (localProcessedSize == 0)\r\n      return S_OK;\r\n    RINOK(WriteStream(stream, _buffer, localProcessedSize, NULL));\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (!_buffer->Write(data, size))\r\n  {\r\n    if (processedSize != NULL)\r\n      *processedSize = 0;\r\n    return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/InOutTempBuffer.h",
    "content": "// Util/InOutTempBuffer.h\r\n\r\n#ifndef __IN_OUT_TEMP_BUFFER_H\r\n#define __IN_OUT_TEMP_BUFFER_H\r\n\r\n#include \"../../Windows/FileIO.h\"\r\n#include \"../../Windows/FileDir.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../IStream.h\"\r\n\r\nclass CInOutTempBuffer\r\n{\r\n  NWindows::NFile::NDirectory::CTempFile _tempFile;\r\n  NWindows::NFile::NIO::COutFile _outFile;\r\n  NWindows::NFile::NIO::CInFile _inFile;\r\n  Byte *_buffer;\r\n  UInt32 _bufferPosition;\r\n  UInt32 _currentPositionInBuffer;\r\n  CSysString _tmpFileName;\r\n  bool _tmpFileCreated;\r\n\r\n  UInt64 _fileSize;\r\n\r\n  bool WriteToFile(const void *data, UInt32 size);\r\npublic:\r\n  CInOutTempBuffer();\r\n  ~CInOutTempBuffer();\r\n  void Create();\r\n\r\n  void InitWriting();\r\n  bool Write(const void *data, UInt32 size);\r\n  UInt64 GetDataSize() const { return _fileSize; }\r\n  bool FlushWrite();\r\n  bool InitReading();\r\n  HRESULT WriteToStream(ISequentialOutStream *stream);\r\n};\r\n\r\nclass CSequentialOutTempBufferImp: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CInOutTempBuffer *_buffer;\r\npublic:\r\n  // CSequentialOutStreamImp(): _size(0) {}\r\n  // UInt32 _size;\r\n  void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }\r\n  // UInt32 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/LimitedStreams.cpp",
    "content": "// LimitedStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LimitedStreams.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\nSTDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size);\r\n  HRESULT result = S_OK;\r\n  if (sizeToRead > 0)\r\n  {\r\n    result = _stream->Read(data, sizeToRead, &realProcessedSize);\r\n    _pos += realProcessedSize;\r\n    if (realProcessedSize == 0)\r\n      _wasFinished = true;\r\n  }\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/LimitedStreams.h",
    "content": "// LimitedStreams.h\r\n\r\n#ifndef __LIMITEDSTREAMS_H\r\n#define __LIMITEDSTREAMS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLimitedSequentialInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt64 _pos;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream; }\r\n  void Init(UInt64 streamSize)  \r\n  { \r\n    _size = streamSize; \r\n    _pos = 0; \r\n    _wasFinished = false; \r\n  }\r\n \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _pos; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/LockedStream.cpp",
    "content": "// LockedStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LockedStream.h\"\r\n\r\nHRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size, \r\n  UInt32 *processedSize)\r\n{\r\n  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);\r\n  RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));\r\n  return _stream->Read(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);\r\n  _pos += realProcessedSize;\r\n  if (processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/LockedStream.h",
    "content": "// LockedStream.h\r\n\r\n#ifndef __LOCKEDSTREAM_H\r\n#define __LOCKEDSTREAM_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLockedInStream\r\n{\r\n  CMyComPtr<IInStream> _stream;\r\n  NWindows::NSynchronization::CCriticalSection _criticalSection;\r\npublic:\r\n  void Init(IInStream *stream)\r\n    { _stream = stream; }\r\n  HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CLockedSequentialInStreamImp: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CLockedInStream *_lockedInStream;\r\n  UInt64 _pos;\r\npublic:\r\n  void Init(CLockedInStream *lockedInStream, UInt64 startPos)\r\n  {\r\n    _lockedInStream = lockedInStream;\r\n    _pos = startPos;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/MethodId.cpp",
    "content": "// MethodId.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodId.h\"\r\n#include \"../../Common/MyString.h\"\r\n\r\nstatic inline wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nUString ConvertMethodIdToString(UInt64 id)\r\n{\r\n  wchar_t s[32];\r\n  int len = 32;\r\n  s[--len] = 0;\r\n  do\r\n  {\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n  }\r\n  while (id != 0);\r\n  return s + len;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/MethodId.h",
    "content": "// MethodId.h\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Common/Types.h\"\r\n\r\ntypedef UInt64 CMethodId;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/MethodProps.cpp",
    "content": "// MethodProps.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodProps.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nstatic UInt64 k_LZMA = 0x030101;\r\n// static UInt64 k_LZMA2 = 0x030102;\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)\r\n{\r\n  bool tryReduce = false;\r\n  UInt32 reducedDictionarySize = 1 << 10;\r\n  if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))\r\n  {\r\n    for (;;)\r\n    {\r\n      const UInt32 step = (reducedDictionarySize >> 1);\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      reducedDictionarySize += step;\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      if (reducedDictionarySize >= ((UInt32)3 << 30))\r\n        break;\r\n      reducedDictionarySize += step;\r\n    }\r\n  }\r\n\r\n  {\r\n    int numProperties = method.Properties.Size();\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n    if (setCoderProperties == NULL)\r\n    {\r\n      if (numProperties != 0)\r\n        return E_INVALIDARG;\r\n    }\r\n    else\r\n    {\r\n      CRecordVector<PROPID> propIDs;\r\n      NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties];\r\n      HRESULT res = S_OK;\r\n      try\r\n      {\r\n        for (int i = 0; i < numProperties; i++)\r\n        {\r\n          const CProp &prop = method.Properties[i];\r\n          propIDs.Add(prop.Id);\r\n          NWindows::NCOM::CPropVariant &value = values[i];\r\n          value = prop.Value;\r\n          // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)\r\n          if (tryReduce)\r\n            if (prop.Id == NCoderPropID::kDictionarySize)\r\n              if (value.vt == VT_UI4)\r\n                if (reducedDictionarySize < value.ulVal)\r\n            value.ulVal = reducedDictionarySize;\r\n        }\r\n        CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n        coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n        res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties);\r\n      }\r\n      catch(...)\r\n      {\r\n        delete []values;\r\n        throw;\r\n      }\r\n      delete []values;\r\n      RINOK(res);\r\n    }\r\n  }\r\n \r\n  /*\r\n  CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n  coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n  if (writeCoderProperties != NULL)\r\n  {\r\n    CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n    outStreamSpec->Init();\r\n    RINOK(writeCoderProperties->WriteCoderProperties(outStream));\r\n    size_t size = outStreamSpec->GetSize();\r\n    filterProps.SetCapacity(size);\r\n    memmove(filterProps, outStreamSpec->GetBuffer(), size);\r\n  }\r\n  */\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/MethodProps.h",
    "content": "// MethodProps.h\r\n\r\n#ifndef __7Z_METHOD_PROPS_H\r\n#define __7Z_METHOD_PROPS_H\r\n\r\n#include \"MethodId.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Common/MyVector.h\"\r\n#include \"../ICoder.h\"\r\n\r\nstruct CProp\r\n{\r\n  PROPID Id;\r\n  NWindows::NCOM::CPropVariant Value;\r\n};\r\n\r\nstruct CMethod\r\n{\r\n  CMethodId Id;\r\n  CObjectVector<CProp> Properties;\r\n};\r\n\r\nstruct CMethodsMode\r\n{\r\n  CObjectVector<CMethod> Methods;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n\r\n  CMethodsMode()\r\n      #ifdef COMPRESS_MT\r\n      : NumThreads(1) \r\n      #endif\r\n  {}\r\n  bool IsEmpty() const { return Methods.IsEmpty() ; }\r\n};\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/OffsetStream.cpp",
    "content": "// OffsetStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"OffsetStream.h\"\r\n\r\nHRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)\r\n{\r\n  _offset = offset;\r\n  _stream = stream;\r\n  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return _stream->Write(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 absoluteNewPosition;\r\n  if (seekOrigin == STREAM_SEEK_SET)\r\n    offset += _offset;\r\n  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);\r\n  if (newPosition != NULL)\r\n    *newPosition = absoluteNewPosition - _offset;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)\r\n{\r\n  return _stream->SetSize(_offset + newSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/OffsetStream.h",
    "content": "// OffsetStream.h\r\n\r\n#ifndef __OFFSETSTREAM_H\r\n#define __OFFSETSTREAM_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass COffsetOutStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 _offset;\r\n  CMyComPtr<IOutStream> _stream;\r\npublic:\r\n  HRESULT Init(IOutStream *stream, UInt64 offset);\r\n  \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{ \r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos) \r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode == S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = Flush();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException: public CSystemException \r\n{ \r\n  COutBufferException(HRESULT errorCode): CSystemException(errorCode) {} \r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void FlushWithCheck();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/ProgressUtils.cpp",
    "content": "// ProgressUtils.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ProgressUtils.h\"\r\n\r\nCLocalProgress::CLocalProgress()\r\n{\r\n  ProgressOffset = InSize = OutSize = 0;\r\n  SendRatio = SendProgress = true;\r\n}\r\n\r\nvoid CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)\r\n{\r\n  _ratioProgress.Release();\r\n  _progress = progress;\r\n  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);\r\n  _inSizeIsMain = inSizeIsMain;\r\n}\r\n\r\nSTDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  UInt64 inSizeNew = InSize, outSizeNew = OutSize;\r\n  if (inSize)\r\n    inSizeNew += (*inSize);\r\n  if (outSize)\r\n    outSizeNew += (*outSize);\r\n  if (SendRatio && _ratioProgress)\r\n  {\r\n    RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));\r\n  }\r\n  inSizeNew += ProgressOffset;\r\n  outSizeNew += ProgressOffset;\r\n  if (SendProgress)\r\n    return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CLocalProgress::SetCur()\r\n{\r\n  return SetRatioInfo(NULL, NULL);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/ProgressUtils.h",
    "content": "// ProgressUtils.h\r\n\r\n#ifndef __PROGRESSUTILS_H\r\n#define __PROGRESSUTILS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n#include \"../IProgress.h\"\r\n\r\nclass CLocalProgress: \r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<IProgress> _progress;\r\n  CMyComPtr<ICompressProgressInfo> _ratioProgress;\r\n  bool _inSizeIsMain;\r\npublic:\r\n  UInt64 ProgressOffset;\r\n  UInt64 InSize;\r\n  UInt64 OutSize;\r\n  bool SendRatio;\r\n  bool SendProgress;\r\n\r\n  CLocalProgress();\r\n  void Init(IProgress *progress, bool inSizeIsMain);\r\n  HRESULT SetCur();\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/RegisterArc.h",
    "content": "// RegisterArc.h\r\n\r\n#ifndef __REGISTERARC_H\r\n#define __REGISTERARC_H\r\n\r\n#include \"../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcInfo\r\n{\r\n  const wchar_t *Name;\r\n  const wchar_t *Ext;\r\n  const wchar_t *AddExt;\r\n  Byte ClassId;\r\n  Byte Signature[16];\r\n  int SignatureSize;\r\n  bool KeepName;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n};\r\n\r\nvoid RegisterArc(const CArcInfo *arcInfo);\r\n\r\n#define REGISTER_ARC_NAME(x) CRegister ## x \r\n\r\n#define REGISTER_ARC_DEC_SIG(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { g_ArcInfo.Signature[0]--; RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#define REGISTER_ARC(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/RegisterCodec.h",
    "content": "// RegisterCodec.h\r\n\r\n#ifndef __REGISTERCODEC_H\r\n#define __REGISTERCODEC_H\r\n\r\n#include \"../Common/MethodId.h\"\r\n\r\ntypedef void * (*CreateCodecP)();\r\nstruct CCodecInfo\r\n{\r\n  CreateCodecP CreateDecoder;\r\n  CreateCodecP CreateEncoder;\r\n  CMethodId Id;\r\n  const wchar_t *Name;\r\n  UInt32 NumInStreams;\r\n  bool IsFilter;\r\n};\r\n\r\nvoid RegisterCodec(const CCodecInfo *codecInfo);\r\n\r\n#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x \r\n\r\n#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \\\r\n    REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \\\r\n    static REGISTER_CODEC_NAME(x) g_RegisterCodec;\r\n\r\n#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x \r\n#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \\\r\n    REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \\\r\n    RegisterCodec(&g_CodecsInfo[i]); }}; \\\r\n    static REGISTER_CODECS_NAME(x) g_RegisterCodecs;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/StreamBinder.cpp",
    "content": "// StreamBinder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamBinder.h\"\r\n#include \"../../Common/Defs.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NSynchronization;\r\n\r\nclass CSequentialInStreamForBinder: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Read(data, size, processedSize); }\r\n\r\nclass CSequentialOutStreamForBinder: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialOutStreamForBinder() {  m_StreamBinder->CloseWrite(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Write(data, size, processedSize); }\r\n\r\n\r\n//////////////////////////\r\n// CStreamBinder\r\n// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.\r\n\r\nHRes CStreamBinder::CreateEvents()\r\n{\r\n  RINOK(_allBytesAreWritenEvent.Create(true));\r\n  RINOK(_thereAreBytesToReadEvent.Create());\r\n  return _readStreamIsClosedEvent.Create();\r\n}\r\n\r\nvoid CStreamBinder::ReInit()\r\n{\r\n  _thereAreBytesToReadEvent.Reset();\r\n  _readStreamIsClosedEvent.Reset();\r\n  ProcessedSize = 0;\r\n}\r\n\r\n\r\n  \r\nvoid CStreamBinder::CreateStreams(ISequentialInStream **inStream, \r\n      ISequentialOutStream **outStream)\r\n{\r\n  CSequentialInStreamForBinder *inStreamSpec = new \r\n      CSequentialInStreamForBinder;\r\n  CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n  inStreamSpec->SetBinder(this);\r\n  *inStream = inStreamLoc.Detach();\r\n\r\n  CSequentialOutStreamForBinder *outStreamSpec = new \r\n      CSequentialOutStreamForBinder;\r\n  CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);\r\n  outStreamSpec->SetBinder(this);\r\n  *outStream = outStreamLoc.Detach();\r\n\r\n  _buffer = NULL;\r\n  _bufferSize= 0;\r\n  ProcessedSize = 0;\r\n}\r\n\r\nHRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 sizeToRead = size;\r\n  if (size > 0)\r\n  {\r\n    RINOK(_thereAreBytesToReadEvent.Lock());\r\n    sizeToRead = MyMin(_bufferSize, size);\r\n    if (_bufferSize > 0)\r\n    {\r\n      MoveMemory(data, _buffer, sizeToRead);\r\n      _buffer = ((const Byte *)_buffer) + sizeToRead;\r\n      _bufferSize -= sizeToRead;\r\n      if (_bufferSize == 0)\r\n      {\r\n        _thereAreBytesToReadEvent.Reset();\r\n        _allBytesAreWritenEvent.Set();\r\n      }\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = sizeToRead;\r\n  ProcessedSize += sizeToRead;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseRead()\r\n{\r\n  _readStreamIsClosedEvent.Set();\r\n}\r\n\r\nHRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > 0)\r\n  {\r\n    _buffer = data;\r\n    _bufferSize = size;\r\n    _allBytesAreWritenEvent.Reset();\r\n    _thereAreBytesToReadEvent.Set();\r\n\r\n    HANDLE events[2]; \r\n    events[0] = _allBytesAreWritenEvent;\r\n    events[1] = _readStreamIsClosedEvent; \r\n    DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);\r\n    if (waitResult != WAIT_OBJECT_0 + 0)\r\n    {\r\n      // ReadingWasClosed = true;\r\n      return S_FALSE;\r\n    }\r\n    // if(!_allBytesAreWritenEvent.Lock())\r\n    //   return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseWrite()\r\n{\r\n  // _bufferSize must be = 0\r\n  _thereAreBytesToReadEvent.Set();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/StreamBinder.h",
    "content": "// StreamBinder.h\r\n\r\n#ifndef __STREAMBINDER_H\r\n#define __STREAMBINDER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Windows/Synchronization.h\"\r\n\r\nclass CStreamBinder\r\n{\r\n  NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent;\r\n  UInt32 _bufferSize;\r\n  const void *_buffer;\r\npublic:\r\n  // bool ReadingWasClosed;\r\n  UInt64 ProcessedSize;\r\n  CStreamBinder() {}\r\n  HRes CreateEvents();\r\n\r\n  void CreateStreams(ISequentialInStream **inStream, \r\n      ISequentialOutStream **outStream);\r\n  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseRead();\r\n\r\n  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseWrite();\r\n  void ReInit();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/StreamObjects.cpp",
    "content": "// StreamObjects.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamObjects.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\n\r\nSTDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 numBytesToRead = (UInt32)(MyMin(_pos + size, _size) - _pos);\r\n  memmove(data, _dataPointer + _pos, numBytesToRead);\r\n  _pos += numBytesToRead;\r\n  if(processedSize != NULL)\r\n    *processedSize = numBytesToRead;\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CWriteBuffer::Write(const void *data, size_t size)\r\n{\r\n  size_t newCapacity = _size + size;\r\n  _buffer.EnsureCapacity(newCapacity);\r\n  memmove(_buffer + _size, data, size);\r\n  _size += size;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  _writeBuffer.Write(data, size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK; \r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 newSize = size;\r\n  if (_pos + size > _size)\r\n    newSize = (UInt32)(_size - _pos);\r\n  memmove(_buffer + _pos, data, newSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = newSize;\r\n  _pos += newSize;\r\n  if (newSize != size)\r\n    return E_FAIL;\r\n  return S_OK; \r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result; \r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result; \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/StreamObjects.h",
    "content": "// StreamObjects.h\r\n\r\n#ifndef __STREAMOBJECTS_H\r\n#define __STREAMOBJECTS_H\r\n\r\n#include \"../../Common/DynamicBuffer.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CSequentialInStreamImp: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *_dataPointer;\r\n  size_t _size;\r\n  size_t _pos;\r\n\r\npublic:\r\n  void Init(const Byte *dataPointer, size_t size)\r\n  {\r\n    _dataPointer = dataPointer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n\r\nclass CWriteBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _size;\r\npublic:\r\n  CWriteBuffer(): _size(0) {}\r\n  void Init() { _size = 0;  }\r\n  void Write(const void *data, size_t size);\r\n  size_t GetSize() const { return _size; }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _buffer; }\r\n};\r\n\r\nclass CSequentialOutStreamImp: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CWriteBuffer _writeBuffer;\r\npublic:\r\n  void Init() { _writeBuffer.Init(); }\r\n  size_t GetSize() const { return _writeBuffer.GetSize(); }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamImp2: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n\r\n  void Init(Byte *buffer, size_t size)  \r\n  { \r\n    _buffer = buffer;\r\n    _pos = 0;\r\n    _size = size; \r\n  }\r\n\r\n  size_t GetPos() const { return _pos; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialInStreamSizeCount: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamSizeCount: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void Init() { _size = 0; }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Read(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (Byte *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Write(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/VirtThread.cpp",
    "content": "// VirtThread.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"VirtThread.h\"\r\n\r\nstatic THREAD_FUNC_DECL CoderThread(void *p)\r\n{\r\n  for (;;)\r\n  {\r\n    CVirtThread *t = (CVirtThread *)p;\r\n    t->StartEvent.Lock();\r\n    if (t->ExitEvent)\r\n      return 0;\r\n    t->Execute();\r\n    t->FinishedEvent.Set();\r\n  }\r\n}\r\n\r\nHRes CVirtThread::Create()\r\n{\r\n  RINOK(StartEvent.CreateIfNotCreated());\r\n  RINOK(FinishedEvent.CreateIfNotCreated());\r\n  StartEvent.Reset();\r\n  FinishedEvent.Reset();\r\n  ExitEvent = false;\r\n  if (Thread.IsCreated())\r\n    return S_OK;\r\n  return Thread.Create(CoderThread, this);\r\n}\r\n\r\nvoid CVirtThread::Start()\r\n{\r\n  ExitEvent = false;\r\n  StartEvent.Set();\r\n}\r\n\r\nCVirtThread::~CVirtThread()\r\n{\r\n  ExitEvent = true;\r\n  if (StartEvent.IsCreated())\r\n    StartEvent.Set();\r\n  Thread.Wait();\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Common/VirtThread.h",
    "content": "// VirtThread.h\r\n\r\n#ifndef __VIRTTHREAD_H\r\n#define __VIRTTHREAD_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Windows/Thread.h\"\r\n\r\nstruct CVirtThread\r\n{\r\n  NWindows::NSynchronization::CAutoResetEvent StartEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent FinishedEvent;\r\n  NWindows::CThread Thread;\r\n  bool ExitEvent;\r\n\r\n  ~CVirtThread();\r\n  HRes Create();\r\n  void Start();\r\n  void WaitFinish() { FinishedEvent.Lock(); } \r\n  virtual void Execute() = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/ARM.cpp",
    "content": "// ARM.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARM.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchARM.h\"\r\n}\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/ARM.h",
    "content": "// ARM.h\r\n\r\n#ifndef __ARM_H\r\n#define __ARM_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM, 0x05, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/ARMThumb.cpp",
    "content": "// ARMThumb.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ARMThumb.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchARMThumb.h\"\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/ARMThumb.h",
    "content": "// ARMThumb.h\r\n\r\n#ifndef __ARMTHUMB_H\r\n#define __ARMTHUMB_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARMThumb, 0x07, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/BCJ2Register.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"x86_2.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x0303011B, L\"BCJ2\", 4, false };\r\n\r\nREGISTER_CODEC(BCJ2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/BCJRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"x86.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x03030103, L\"BCJ\", 1, true };\r\n\r\nREGISTER_CODEC(BCJ)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __BRANCH_CODER_H\r\n#define __BRANCH_CODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/Types.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/BranchRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"PPC.h\"\r\n#include \"IA64.h\"\r\n#include \"ARM.h\"\r\n#include \"ARMThumb.h\"\r\n#include \"SPARC.h\"\r\n\r\n#define CREATE_CODEC(x) \\\r\n  static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \\\r\n  static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }\r\n\r\nCREATE_CODEC(BC_PPC_B)\r\nCREATE_CODEC(BC_IA64)\r\nCREATE_CODEC(BC_ARM)\r\nCREATE_CODEC(BC_ARMThumb)\r\nCREATE_CODEC(BC_SPARC)\r\n\r\n#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true  }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  METHOD_ITEM(BC_PPC_B,   0x02, 0x05, L\"BC_PPC_B\"),\r\n  METHOD_ITEM(BC_IA64,    0x04, 1, L\"BC_IA64\"),\r\n  METHOD_ITEM(BC_ARM,     0x05, 1, L\"BC_ARM\"),\r\n  METHOD_ITEM(BC_ARMThumb,0x07, 1, L\"BC_ARMThumb\"),\r\n  METHOD_ITEM(BC_SPARC,   0x08, 0x05, L\"BC_SPARC\")\r\n};\r\n\r\nREGISTER_CODECS(Branch)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/IA64.cpp",
    "content": "// IA64.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"IA64.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchIA64.h\"\r\n}\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/IA64.h",
    "content": "// IA64.h\r\n\r\n#ifndef __IA64_H\r\n#define __IA64_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_IA64, 0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/PPC.cpp",
    "content": "// PPC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"PPC.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchPPC.h\"\r\n}\r\n\r\nUInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/PPC.h",
    "content": "// PPC.h\r\n\r\n#ifndef __PPC_H\r\n#define __PPC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_PPC_B, 0x02, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/SPARC.cpp",
    "content": "// SPARC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"SPARC.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchSPARC.h\"\r\n}\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/SPARC.h",
    "content": "// SPARC.h\r\n\r\n#ifndef __SPARC_H\r\n#define __SPARC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_SPARC, 0x08, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/x86.cpp",
    "content": "// x86.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86.h\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/x86.h",
    "content": "// x86.h\r\n\r\n#ifndef __X86_H\r\n#define __X86_H\r\n\r\n#include \"BranchCoder.h\"\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchX86.h\"\r\n}\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  void x86Init() { x86_Convert_Init(_prevMask); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 , \r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/x86_2.cpp",
    "content": "// x86_2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86_2.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\ninline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }\r\ninline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }\r\ninline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CEncoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CEncoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize = 0;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusEncoder[i].Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    for (;;)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it \r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        UInt32 index;\r\n        if (b == 0xE8)\r\n          index = prevByte;\r\n        else if (b == 0xE9)\r\n          index = 256;\r\n        else if (IsJcc(prevByte, b))\r\n          index = 257;\r\n        else\r\n        {\r\n          prevByte = b;\r\n          continue;\r\n        }\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (!IsJ(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src = \r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;          \r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;          \r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      unsigned index = GetIndex(prevByte, b);\r\n      if (convert)\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 1);\r\n        bufferPos += 5;\r\n        COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n        for (int i = 24; i >= 0; i -= 8)\r\n          s.WriteByte((Byte)(dest >> i));\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize = \r\n        _mainStream.GetProcessedSize() + \r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeEncoder.GetProcessedSize();\r\n      */\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusDecoder[i].Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  for (;;)\r\n  {\r\n    if (processedBytes >= (1 << 20) && progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize = \r\n        _mainInStream.GetProcessedSize() + \r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeDecoder.GetProcessedSize();\r\n      */\r\n      const UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    UInt32 i;\r\n    Byte b = 0;\r\n    const UInt32 kBurstSize = (1 << 18);\r\n    for (i = 0; i < kBurstSize; i++)\r\n    {\r\n      if (!_mainInStream.ReadByte(b))\r\n        return Flush();\r\n      _outStream.WriteByte(b);\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      prevByte = b;\r\n    }\r\n    processedBytes += i;\r\n    if (i == kBurstSize)\r\n      continue;\r\n    unsigned index = GetIndex(prevByte, b);\r\n    if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)\r\n    {\r\n      UInt32 src = 0;\r\n      CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n      for (int i = 0; i < 4; i++)\r\n      {\r\n        Byte b0;\r\n        if(!s.ReadByte(b0))\r\n          return S_FALSE;\r\n        src <<= 8;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (Byte)(dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const CInBufferException &e) { return e.ErrorCode; }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Branch/x86_2.h",
    "content": "// x86_2.h\r\n\r\n#ifndef __BRANCH_X86_2_H\r\n#define __BRANCH_X86_2_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../RangeCoder/RangeCoderBit.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CEncoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CEncoder(): _buffer(0) {};\r\n  ~CEncoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n\r\nclass CDecoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{ \r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CDecoder *_coder;\r\n  public:\r\n    CCoderReleaser(CDecoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/ByteSwap/ByteSwap.cpp",
    "content": "// ByteSwap.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nSTDMETHODIMP CByteSwap2::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 2;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b = data[i];\r\n    data[i] = data[i + 1];\r\n    data[i + 1] = b;\r\n  }\r\n  return i;\r\n}\r\n\r\nSTDMETHODIMP CByteSwap4::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 4;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b0 = data[i];\r\n    Byte b1 = data[i + 1];\r\n    data[i] = data[i + 3];\r\n    data[i + 1] = data[i + 2];\r\n    data[i + 2] = b1;\r\n    data[i + 3] = b0;\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/ByteSwap/ByteSwap.h",
    "content": "// ByteSwap.h\r\n\r\n#ifndef __BYTESWAP_H\r\n#define __BYTESWAP_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n// {23170F69-40C1-278B-0203-020000000000}\r\nDEFINE_GUID(CLSID_CCompressConvertByteSwap2, \r\n0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\n// {23170F69-40C1-278B-0203-040000000000}\r\nDEFINE_GUID(CLSID_CCompressConvertByteSwap4, \r\n0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nclass CByteSwap2: \r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\nclass CByteSwap4: \r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/ByteSwap/ByteSwapRegister.cpp",
    "content": "// ByteSwapRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"ByteSwap.h\"\r\nstatic void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }\r\nstatic void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  { CreateCodec2, CreateCodec4, 0x020302, L\"Swap2\", 1, true },\r\n  { CreateCodec4, CreateCodec4, 0x020304, L\"Swap4\", 1, true }\r\n};\r\n\r\nREGISTER_CODECS(ByteSwap)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/ByteSwap/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/ByteSwap/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/CodecExports.cpp",
    "content": "// CodecExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterCodec.h\"\r\n#include \"../ICoder.h\"\r\n\r\nextern unsigned int g_NumCodecs;\r\nextern const CCodecInfo *g_Codecs[]; \r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec, \r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nstatic HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)\r\n{\r\n  GUID clsId = CLSID_CCodec;\r\n  for (int i = 0; i < sizeof(id); i++, id >>= 8)\r\n    clsId.Data4[i] = (Byte)(id & 0xFF);\r\n  if (encode)\r\n    clsId.Data3++;\r\n  return SetPropGUID(clsId, value);\r\n}\r\n\r\nstatic HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)\r\n{\r\n  index = -1;\r\n  if (clsID->Data1 != CLSID_CCodec.Data1 || \r\n      clsID->Data2 != CLSID_CCodec.Data2 ||\r\n      (clsID->Data3 & ~1) != kDecodeId)\r\n    return S_OK;\r\n  encode = (clsID->Data3 != kDecodeId);\r\n  UInt64 id = 0;\r\n  for (int j = 0; j < 8; j++)\r\n    id |= ((UInt64)clsID->Data4[j]) << (8 * j);\r\n  for (UInt32 i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)\r\n      continue;\r\n    if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n        codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n      return E_NOINTERFACE;\r\n    index = i;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  const CCodecInfo &codec = *g_Codecs[index];\r\n  if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n      codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n    return E_NOINTERFACE;\r\n  if (encode)\r\n  {\r\n    if (!codec.CreateEncoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateEncoder();\r\n  }\r\n  else\r\n  {\r\n    if (!codec.CreateDecoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateDecoder();\r\n  }\r\n  if (isCoder)\r\n    ((ICompressCoder *)*outObject)->AddRef();\r\n  else if (isCoder2)\r\n    ((ICompressCoder2 *)*outObject)->AddRef();\r\n  else\r\n    ((ICompressFilter *)*outObject)->AddRef();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  if (!isCoder && !isCoder2 && !isFilter)\r\n    return E_NOINTERFACE;\r\n  bool encode;\r\n  int codecIndex;\r\n  HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);\r\n  if (res != S_OK)\r\n    return res;\r\n  if (codecIndex < 0)\r\n    return CLASS_E_CLASSNOTAVAILABLE;\r\n  return CreateCoder2(encode, codecIndex, iid, outObject);\r\n}\r\n\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  ::VariantClear((VARIANTARG *)value);\r\n  const CCodecInfo &codec = *g_Codecs[codecIndex];\r\n  switch(propID)\r\n  {\r\n    case NMethodPropID::kID:\r\n    {\r\n      value->uhVal.QuadPart = (UInt64)codec.Id;\r\n      value->vt = VT_UI8;\r\n      break;\r\n    }\r\n    case NMethodPropID::kName:\r\n      if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)\r\n        value->vt = VT_BSTR;\r\n      break;\r\n    case NMethodPropID::kDecoder:\r\n      if (codec.CreateDecoder)\r\n        return SetClassID(codec.Id, false, value);\r\n      break;\r\n    case NMethodPropID::kEncoder:\r\n      if (codec.CreateEncoder)\r\n        return SetClassID(codec.Id, true, value);\r\n      break;\r\n    case NMethodPropID::kInStreams:\r\n    {\r\n      if (codec.NumInStreams != 1)\r\n      {\r\n        value->vt = VT_UI4;\r\n        value->ulVal = codec.NumInStreams;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetNumberOfMethods(UINT32 *numCodecs)\r\n{\r\n  *numCodecs = g_NumCodecs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Copy/CopyCoder.cpp",
    "content": "// Compress/CopyCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"CopyCoder.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\nnamespace NCompress {\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCCopyCoder::~CCopyCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 * /* inSize */, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  TotalSize = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 realProcessedSize;\r\n    UInt32 size = kBufferSize;\r\n    if (outSize != 0)\r\n      if (size > *outSize - TotalSize)\r\n        size = (UInt32)(*outSize - TotalSize);\r\n    RINOK(inStream->Read(_buffer, size, &realProcessedSize));\r\n    if (realProcessedSize == 0)\r\n      break;\r\n    RINOK(WriteStream(outStream, _buffer, realProcessedSize, NULL));\r\n    TotalSize += realProcessedSize;\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = TotalSize;\r\n  return S_OK;\r\n}\r\n\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Copy/CopyCoder.h",
    "content": "// Compress/CopyCoder.h\r\n\r\n#ifndef __COMPRESS_COPYCODER_H\r\n#define __COMPRESS_COPYCODER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nnamespace NCompress {\r\n\r\nclass CCopyCoder: \r\n  public ICompressCoder,\r\n  public ICompressGetInStreamProcessedSize,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  UInt64 TotalSize;\r\n  CCopyCoder(): TotalSize(0) , _buffer(0) {};\r\n  ~CCopyCoder();\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Copy/CopyRegister.cpp",
    "content": "// LZMARegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"CopyCoder.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n{ CreateCodec, CreateCodec, 0x00, L\"Copy\", 1, false };\r\n\r\nREGISTER_CODEC(Copy)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Copy/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/Copy/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZ/LZOutWindow.cpp",
    "content": "// LZOutWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZOutWindow.h\"\r\n\r\nvoid CLZOutWindow::Init(bool solid)\r\n{\r\n  if(!solid)\r\n    COutBuffer::Init();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZ/LZOutWindow.h",
    "content": "// LZOutWindow.h\r\n\r\n#ifndef __LZ_OUT_WINDOW_H\r\n#define __LZ_OUT_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\ntypedef COutBufferException CLZOutWindowException;\r\n#endif\r\n\r\nclass CLZOutWindow: public COutBuffer\r\n{\r\npublic:\r\n  void Init(bool solid = false);\r\n  \r\n  // distance >= 0, len > 0, \r\n  bool CopyBlock(UInt32 distance, UInt32 len)\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (distance >= _pos)\r\n    {\r\n      if (!_overDict || distance >= _bufferSize)\r\n        return false;\r\n      pos += _bufferSize;\r\n    }\r\n    if (_limitPos - _pos > len && _bufferSize - pos > len)\r\n    {\r\n      const Byte *src = _buffer + pos;\r\n      Byte *dest = _buffer + _pos;\r\n      _pos += len;\r\n      do\r\n        *dest++ = *src++;\r\n      while(--len != 0);\r\n    }\r\n    else do\r\n    {\r\n      if (pos == _bufferSize)\r\n        pos = 0;\r\n      _buffer[_pos++] = _buffer[pos++];\r\n      if (_pos == _limitPos)\r\n        FlushWithCheck();  \r\n    }\r\n    while(--len != 0);\r\n    return true;\r\n  }\r\n  \r\n  void PutByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if (_pos == _limitPos)\r\n      FlushWithCheck();  \r\n  }\r\n  \r\n  Byte GetByte(UInt32 distance) const\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n      pos += _bufferSize;\r\n    return _buffer[pos]; \r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZ/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA/LZMA.h",
    "content": "// LZMA.h\r\n\r\n#ifndef __LZMA_H\r\n#define __LZMA_H\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst UInt32 kNumRepDistances = 4;\r\n\r\nconst int kNumStates = 12;\r\n\r\nconst Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nconst Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nconst Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nconst Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\nclass CState\r\n{\r\npublic:\r\n  Byte Index;\r\n  void Init() { Index = 0; }\r\n  void UpdateChar() { Index = kLiteralNextStates[Index]; }\r\n  void UpdateMatch() { Index = kMatchNextStates[Index]; }\r\n  void UpdateRep() { Index = kRepNextStates[Index]; }\r\n  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }\r\n  bool IsCharState() const { return Index < 7; }\r\n};\r\n\r\nconst int kNumPosSlotBits = 6; \r\nconst int kDicLogSizeMin = 0; \r\nconst int kDicLogSizeMax = 32; \r\nconst int kDistTableSizeMax = kDicLogSizeMax * 2; \r\n\r\nconst UInt32 kNumLenToPosStates = 4;\r\n\r\ninline UInt32 GetLenToPosState(UInt32 len)\r\n{\r\n  len -= 2;\r\n  if (len < kNumLenToPosStates)\r\n    return len;\r\n  return kNumLenToPosStates - 1;\r\n}\r\n\r\nnamespace NLength {\r\n\r\nconst int kNumPosStatesBitsMax = 4;\r\nconst UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\r\nconst int kNumPosStatesBitsEncodingMax = 4;\r\nconst UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\nconst int kNumLowBits = 3;\r\nconst int kNumMidBits = 3;\r\nconst int kNumHighBits = 8;\r\nconst UInt32 kNumLowSymbols = 1 << kNumLowBits;\r\nconst UInt32 kNumMidSymbols = 1 << kNumMidBits;\r\nconst UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\r\n\r\n}\r\n\r\nconst UInt32 kMatchMinLen = 2;\r\nconst UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\r\n\r\nconst int kNumAlignBits = 4;\r\nconst UInt32 kAlignTableSize = 1 << kNumAlignBits;\r\nconst UInt32 kAlignMask = (kAlignTableSize - 1);\r\n\r\nconst UInt32 kStartPosModelIndex = 4;\r\nconst UInt32 kEndPosModelIndex = 14;\r\nconst UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\nconst UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\r\nconst int kNumLitPosStatesBitsEncodingMax = 4;\r\nconst int kNumLitContextBitsMax = 8;\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA/LZMADecoder.cpp",
    "content": "// LZMADecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\n#include \"../../../Common/Defs.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kLenIdFinished = -1;\r\nconst int kLenIdNeedInit = -2;\r\n\r\nvoid CDecoder::Init()\r\n{\r\n  { \r\n    for(int i = 0; i < kNumStates; i++)\r\n    {\r\n      for (UInt32 j = 0; j <= _posStateMask; j++)\r\n      {\r\n        _isMatch[i][j].Init();\r\n        _isRep0Long[i][j].Init();\r\n      }\r\n      _isRep[i].Init();\r\n      _isRepG0[i].Init();\r\n      _isRepG1[i].Init();\r\n      _isRepG2[i].Init();\r\n    }\r\n  }\r\n  { \r\n    for (UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n    _posSlotDecoder[i].Init();\r\n  }\r\n  { \r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posDecoders[i].Init();\r\n  }\r\n  _posAlignDecoder.Init();\r\n  _lenDecoder.Init(_posStateMask + 1);\r\n  _repMatchLenDecoder.Init(_posStateMask + 1);\r\n  _literalDecoder.Init();\r\n\r\n  _state.Init();\r\n  _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0;\r\n}\r\n\r\nHRESULT CDecoder::CodeSpec(UInt32 curSize)\r\n{\r\n  if (_outSizeDefined)\r\n  {\r\n    const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize();\r\n    if (curSize > rem)\r\n      curSize = (UInt32)rem;\r\n  }\r\n\r\n  if (_remainLen == kLenIdFinished)\r\n    return S_OK;\r\n  if (_remainLen == kLenIdNeedInit)\r\n  {\r\n    _rangeDecoder.Init();\r\n    Init();\r\n    _remainLen = 0;\r\n  }\r\n  if (curSize == 0)\r\n    return S_OK;\r\n\r\n  UInt32 rep0 = _reps[0];\r\n  UInt32 rep1 = _reps[1];\r\n  UInt32 rep2 = _reps[2];\r\n  UInt32 rep3 = _reps[3];\r\n  CState state = _state;\r\n  Byte previousByte;\r\n\r\n  while(_remainLen > 0 && curSize > 0)\r\n  {\r\n    previousByte = _outWindowStream.GetByte(rep0);\r\n    _outWindowStream.PutByte(previousByte);\r\n    _remainLen--;\r\n    curSize--;\r\n  }\r\n  UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n  if (nowPos64 == 0)\r\n    previousByte = 0;\r\n  else\r\n    previousByte = _outWindowStream.GetByte(0);\r\n\r\n  while(curSize > 0)\r\n  {\r\n    {\r\n      #ifdef _NO_EXCEPTIONS\r\n      if (_rangeDecoder.Stream.ErrorCode != S_OK)\r\n        return _rangeDecoder.Stream.ErrorCode;\r\n      #endif\r\n      if (_rangeDecoder.Stream.WasFinished())\r\n        return S_FALSE;\r\n      UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n      if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n      {\r\n        if(!state.IsCharState())\r\n          previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte, _outWindowStream.GetByte(rep0));\r\n        else\r\n          previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte);\r\n        _outWindowStream.PutByte(previousByte);\r\n        state.UpdateChar();\r\n        curSize--;\r\n        nowPos64++;\r\n      }\r\n      else             \r\n      {\r\n        UInt32 len;\r\n        if(_isRep[state.Index].Decode(&_rangeDecoder) == 1)\r\n        {\r\n          len = 0;\r\n          if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0)\r\n          {\r\n            if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n            {\r\n              state.UpdateShortRep();\r\n              len = 1;\r\n            }\r\n          }\r\n          else\r\n          {\r\n            UInt32 distance;\r\n            if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0)\r\n              distance = rep1;\r\n            else \r\n            {\r\n              if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0)\r\n                distance = rep2;\r\n              else\r\n              {\r\n                distance = rep3;\r\n                rep3 = rep2;\r\n              }\r\n              rep2 = rep1;\r\n            }\r\n            rep1 = rep0;\r\n            rep0 = distance;\r\n          }\r\n          if (len == 0)\r\n          {\r\n            len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;\r\n            state.UpdateRep();\r\n          }\r\n        }\r\n        else\r\n        {\r\n          rep3 = rep2;\r\n          rep2 = rep1;\r\n          rep1 = rep0;\r\n          len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);\r\n          state.UpdateMatch();\r\n          UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);\r\n          if (posSlot >= kStartPosModelIndex)\r\n          {\r\n            UInt32 numDirectBits = (posSlot >> 1) - 1;\r\n            rep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\r\n            if (posSlot < kEndPosModelIndex)\r\n              rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders + \r\n                  rep0 - posSlot - 1, &_rangeDecoder, numDirectBits);\r\n            else\r\n            {\r\n              rep0 += (_rangeDecoder.DecodeDirectBits(\r\n                  numDirectBits - kNumAlignBits) << kNumAlignBits);\r\n              rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder);\r\n              if (rep0 == 0xFFFFFFFF)\r\n              {\r\n                _remainLen = kLenIdFinished;\r\n                return S_OK;\r\n              }\r\n            }\r\n          }\r\n          else\r\n            rep0 = posSlot;\r\n        }\r\n        UInt32 locLen = len;\r\n        if (len > curSize)\r\n          locLen = (UInt32)curSize;\r\n        if (!_outWindowStream.CopyBlock(rep0, locLen))\r\n          return S_FALSE;\r\n        previousByte = _outWindowStream.GetByte(0);\r\n        curSize -= locLen;\r\n        nowPos64 += locLen;\r\n        len -= locLen;\r\n        if (len != 0)\r\n        {\r\n          _remainLen = (Int32)len;\r\n          break;\r\n        }\r\n\r\n        #ifdef _NO_EXCEPTIONS\r\n        if (_outWindowStream.ErrorCode != S_OK)\r\n          return _outWindowStream.ErrorCode;\r\n        #endif\r\n      }\r\n    }\r\n  }\r\n  if (_rangeDecoder.Stream.WasFinished())\r\n    return S_FALSE;\r\n  _reps[0] = rep0;\r\n  _reps[1] = rep1;\r\n  _reps[2] = rep2;\r\n  _reps[3] = rep3;\r\n  _state = state;\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 *, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  SetInStream(inStream);\r\n  _outWindowStream.SetStream(outStream);\r\n  SetOutStreamSize(outSize);\r\n  CDecoderFlusher flusher(this);\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 curSize = 1 << 18;\r\n    RINOK(CodeSpec(curSize));\r\n    if (_remainLen == kLenIdFinished)\r\n      break;\r\n    if (progress != NULL)\r\n    {\r\n      UInt64 inSize = _rangeDecoder.GetProcessedSize();\r\n      UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(&inSize, &nowPos64));\r\n    }\r\n    if (_outSizeDefined)\r\n      if (_outWindowStream.GetProcessedSize() >= _outSize)\r\n        break;\r\n  } \r\n  flusher.NeedFlush = false;\r\n  return Flush();\r\n}\r\n\r\n\r\n#ifdef _NO_EXCEPTIONS\r\n\r\n#define LZMA_TRY_BEGIN\r\n#define LZMA_TRY_END\r\n\r\n#else\r\n\r\n#define LZMA_TRY_BEGIN try { \r\n#define LZMA_TRY_END } \\\r\n  catch(const CInBufferException &e)  { return e.ErrorCode; } \\\r\n  catch(const CLZOutWindowException &e)  { return e.ErrorCode; } \\\r\n  catch(...) { return S_FALSE; }\r\n\r\n#endif\r\n\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  LZMA_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size)\r\n{\r\n  if (size < 5)\r\n    return E_INVALIDARG;\r\n  int lc = properties[0] % 9;\r\n  Byte remainder = (Byte)(properties[0] / 9);\r\n  int lp = remainder % 5;\r\n  int pb = remainder / 5;\r\n  if (pb > NLength::kNumPosStatesBitsMax)\r\n    return E_INVALIDARG;\r\n  _posStateMask = (1 << pb) - 1;\r\n  UInt32 dictionarySize = 0;\r\n  for (int i = 0; i < 4; i++)\r\n    dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n  if (!_outWindowStream.Create(dictionarySize))\r\n    return E_OUTOFMEMORY;\r\n  if (!_literalDecoder.Create(lp, lc))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = _rangeDecoder.GetProcessedSize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _rangeDecoder.SetStream(inStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::ReleaseInStream()\r\n{\r\n  _rangeDecoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  _outSizeDefined = (outSize != NULL);\r\n  if (_outSizeDefined)\r\n    _outSize = *outSize;\r\n  _remainLen = kLenIdNeedInit;\r\n  _outWindowStream.Init();\r\n  return S_OK;\r\n}\r\n\r\n#ifndef NO_READ_FROM_CODER\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  const UInt64 startPos = _outWindowStream.GetProcessedSize();\r\n  _outWindowStream.SetMemStream((Byte *)data);\r\n  RINOK(CodeSpec(size));\r\n  if (processedSize)\r\n    *processedSize = (UInt32)(_outWindowStream.GetProcessedSize() - startPos);\r\n  return Flush();\r\n  LZMA_TRY_END\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA/LZMADecoder.h",
    "content": "// LZMA/Decoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/LZOutWindow.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;\r\n\r\nclass CLiteralDecoder2\r\n{\r\n  CMyBitDecoder _decoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _decoders[i].Init();\r\n  }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n      RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, Byte matchByte)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      UInt32 matchBit = (matchByte >> 7) & 1;\r\n      matchByte <<= 1;\r\n      // UInt32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);\r\n      // symbol = (symbol << 1) | bit;\r\n      UInt32 bit;\r\n      RC_GETBIT2(kNumMoveBits, _decoders[0x100 + (matchBit << 8) + symbol].Prob, symbol, \r\n          bit = 0, bit = 1)\r\n      if (matchBit != bit)\r\n      {\r\n        while (symbol < 0x100)\r\n        {\r\n          // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n          RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n        }\r\n        break;\r\n      }\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n};\r\n\r\nclass CLiteralDecoder\r\n{\r\n  CLiteralDecoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralDecoder(): _coders(0) {}\r\n  ~CLiteralDecoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte, Byte matchByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CDecoder\r\n{\r\n  CMyBitDecoder _choice;\r\n  CMyBitDecoder _choice2;\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder; \r\npublic:\r\n  void Init(UInt32 numPosStates)\r\n  {\r\n    _choice.Init();\r\n    _choice2.Init();\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n    {\r\n      _lowCoder[posState].Init();\r\n      _midCoder[posState].Init();\r\n    }\r\n    _highCoder.Init();\r\n  }\r\n  UInt32 Decode(NRangeCoder::CDecoder *rangeDecoder, UInt32 posState)\r\n  {\r\n    if(_choice.Decode(rangeDecoder) == 0)\r\n      return _lowCoder[posState].Decode(rangeDecoder);\r\n    if(_choice2.Decode(rangeDecoder) == 0)\r\n      return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);\r\n    return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CDecoder: \r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  public ICompressGetInStreamProcessedSize,\r\n  #ifndef NO_READ_FROM_CODER\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CLZOutWindow _outWindowStream;\r\n  NRangeCoder::CDecoder _rangeDecoder;\r\n\r\n  CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax];\r\n  CMyBitDecoder _isRep[kNumStates];\r\n  CMyBitDecoder _isRepG0[kNumStates];\r\n  CMyBitDecoder _isRepG1[kNumStates];\r\n  CMyBitDecoder _isRepG2[kNumStates];\r\n  CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax];\r\n\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];\r\n\r\n  CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;\r\n  \r\n  NLength::CDecoder _lenDecoder;\r\n  NLength::CDecoder _repMatchLenDecoder;\r\n\r\n  CLiteralDecoder _literalDecoder;\r\n\r\n  UInt32 _posStateMask;\r\n\r\n  ///////////////////\r\n  // State\r\n  UInt32 _reps[4];\r\n  CState _state;\r\n  Int32 _remainLen; // -1 means end of stream. // -2 means need Init\r\n  UInt64 _outSize;\r\n  bool _outSizeDefined;\r\n\r\n  void Init();\r\n  HRESULT CodeSpec(UInt32 size);\r\npublic:\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  MY_UNKNOWN_IMP5(\r\n      ICompressSetDecoderProperties2, \r\n      ICompressGetInStreamProcessedSize,\r\n      ICompressSetInStream, \r\n      ICompressSetOutStreamSize, \r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize)\r\n  #endif\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _outWindowStream.ReleaseStream();\r\n    ReleaseInStream();\r\n  }\r\n\r\n  class CDecoderFlusher\r\n  {\r\n    CDecoder *_decoder;\r\n  public:\r\n    bool NeedFlush;\r\n    CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}\r\n    ~CDecoderFlusher() \r\n    { \r\n      if (NeedFlush)\r\n        _decoder->Flush();\r\n      _decoder->ReleaseStreams(); \r\n    }\r\n  };\r\n\r\n  HRESULT Flush() {  return _outWindowStream.Flush(); }  \r\n\r\n  STDMETHOD(CodeReal)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  \r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  CDecoder(): _outSizeDefined(false) {}\r\n  virtual ~CDecoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp",
    "content": "// LZMA/Encoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\n#include \"../../../Common/Defs.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"LZMAEncoder.h\"\r\n\r\n// extern \"C\" { #include \"../../../../C/7zCrc.h\" }\r\n\r\n// #define SHOW_STAT\r\n\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\n// struct CCrcInit { CCrcInit() { InitCrcTable(); } } g_CrcInit;\r\n\r\nconst int kDefaultDictionaryLogSize = 22;\r\nconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n#ifndef LZMA_LOG_BSR\r\nByte g_FastPos[1 << kNumLogBits];\r\n\r\nclass CFastPosInit\r\n{\r\npublic:\r\n  CFastPosInit() { Init(); }\r\n  void Init()\r\n  {\r\n    const Byte kFastSlots = kNumLogBits * 2;\r\n    int c = 2;\r\n    g_FastPos[0] = 0;\r\n    g_FastPos[1] = 1;\r\n\r\n    for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n    {\r\n      UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n      for (UInt32 j = 0; j < k; j++, c++)\r\n        g_FastPos[c] = slotFast;\r\n    }\r\n  }\r\n} g_FastPosInit;\r\n#endif\r\n\r\nvoid CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    _encoders[context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nvoid CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, \r\n    Byte matchByte, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    UInt32 matchBit = (matchByte >> i) & 1;\r\n    _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n    if (matchBit != bit)\r\n    {\r\n      while(i != 0)\r\n      {\r\n        i--;\r\n        UInt32 bit = (symbol >> i) & 1;\r\n        _encoders[context].Encode(rangeEncoder, bit);\r\n        context = (context << 1) | bit;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nUInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  if (matchMode)\r\n  {\r\n    do \r\n    {\r\n      i--;\r\n      UInt32 matchBit = (matchByte >> i) & 1;\r\n      UInt32 bit = (symbol >> i) & 1;\r\n      price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit);\r\n      context = (context << 1) | bit;\r\n      if (matchBit != bit)\r\n        break;\r\n    }\r\n    while (i != 0);\r\n  }\r\n  while(i != 0)\r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    price += _encoders[context].GetPrice(bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  return price;\r\n};\r\n\r\n\r\nnamespace NLength {\r\n\r\nvoid CEncoder::Init(UInt32 numPosStates)\r\n{\r\n  _choice.Init();\r\n  _choice2.Init();\r\n  for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n  {\r\n    _lowCoder[posState].Init();\r\n    _midCoder[posState].Init();\r\n  }\r\n  _highCoder.Init();\r\n}\r\n\r\nvoid CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n  {\r\n    _choice.Encode(rangeEncoder, 0);\r\n    _lowCoder[posState].Encode(rangeEncoder, symbol);\r\n  }\r\n  else\r\n  {\r\n    _choice.Encode(rangeEncoder, 1);\r\n    if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n    {\r\n      _choice2.Encode(rangeEncoder, 0);\r\n      _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      _choice2.Encode(rangeEncoder, 1);\r\n      _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CEncoder::SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const\r\n{\r\n  UInt32 a0 = _choice.GetPrice0();\r\n  UInt32 a1 = _choice.GetPrice1();\r\n  UInt32 b0 = a1 + _choice2.GetPrice0();\r\n  UInt32 b1 = a1 + _choice2.GetPrice1();\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + _lowCoder[posState].GetPrice(i);\r\n  }\r\n  for (; i < kNumLowSymbols + kNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + _midCoder[posState].GetPrice(i - kNumLowSymbols);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + _highCoder.GetPrice(i - kNumLowSymbols - kNumMidSymbols);\r\n}\r\n\r\n}\r\n\r\nCEncoder::CEncoder():\r\n  _numFastBytes(kNumFastBytesDefault),\r\n  _distTableSize(kDefaultDictionaryLogSize * 2),\r\n  _posStateBits(2),\r\n  _posStateMask(4 - 1),\r\n  _numLiteralPosStateBits(0),\r\n  _numLiteralContextBits(3),\r\n  _dictionarySize(1 << kDefaultDictionaryLogSize),\r\n  _matchFinderCycles(0),\r\n  #ifdef COMPRESS_MF_MT\r\n  _multiThread(false),\r\n  #endif\r\n  _writeEndMark(false)\r\n{\r\n  MatchFinder_Construct(&_matchFinderBase);\r\n  // _maxMode = false;\r\n  _fastMode = false;\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Construct(&_matchFinderMt);\r\n  _matchFinderMt.MatchFinder = &_matchFinderBase;\r\n  #endif\r\n}\r\n\r\n\r\nstatic void *SzAlloc(size_t size) { return BigAlloc(size); }\r\nstatic void SzFree(void *address) { BigFree(address); }\r\nISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Destruct(&_matchFinderMt, &g_Alloc);\r\n  #endif\r\n  MatchFinder_Free(&_matchFinderBase, &g_Alloc);\r\n}\r\n\r\nstatic const UInt32 kBigHashDicLimit = (UInt32)1 << 24;\r\n\r\nHRESULT CEncoder::Create()\r\n{\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  bool btMode = (_matchFinderBase.btMode != 0);\r\n  #ifdef COMPRESS_MF_MT\r\n  _mtMode = (_multiThread && !_fastMode && btMode);\r\n  #endif\r\n  \r\n  if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _matchFinderBase.bigHash = (_dictionarySize > kBigHashDicLimit);\r\n\r\n  UInt32 numCycles = 16 + (_numFastBytes >> 1);\r\n  if (!btMode)\r\n    numCycles >>= 1;\r\n  if (_matchFinderCycles != 0)\r\n    numCycles = _matchFinderCycles;\r\n  _matchFinderBase.cutValue = numCycles;\r\n  #ifdef COMPRESS_MF_MT\r\n  if (_mtMode)\r\n  {\r\n    RINOK(MatchFinderMt_Create(&_matchFinderMt, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc));\r\n    _matchFinderObj = &_matchFinderMt;\r\n    MatchFinderMt_CreateVTable(&_matchFinderMt, &_matchFinder);\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!MatchFinder_Create(&_matchFinderBase, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc))\r\n      return E_OUTOFMEMORY;\r\n    _matchFinderObj = &_matchFinderBase;\r\n    MatchFinder_CreateVTable(&_matchFinderBase, &_matchFinder);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\ninline wchar_t GetUpperChar(wchar_t c)\r\n{\r\n  if (c >= 'a' && c <= 'z')\r\n    c -= 0x20;\r\n  return c;\r\n}\r\n\r\nstatic int ParseMatchFinder(const wchar_t *s, int *btMode, UInt32 *numHashBytes /* , int *skipModeBits */)\r\n{\r\n  wchar_t c = GetUpperChar(*s++);\r\n  if (c == L'H')\r\n  {\r\n    if (GetUpperChar(*s++) != L'C')\r\n      return 0;\r\n    int numHashBytesLoc = (int)(*s++ - L'0');\r\n    if (numHashBytesLoc < 4 || numHashBytesLoc > 4)\r\n      return 0;\r\n    if (*s++ != 0)\r\n      return 0;\r\n    *btMode = 0;\r\n    *numHashBytes = numHashBytesLoc;\r\n    return 1;\r\n  }\r\n  if (c != L'B')\r\n    return 0;\r\n\r\n  if (GetUpperChar(*s++) != L'T')\r\n    return 0;\r\n  int numHashBytesLoc = (int)(*s++ - L'0');\r\n  if (numHashBytesLoc < 2 || numHashBytesLoc > 4)\r\n    return 0;\r\n  c = GetUpperChar(*s++);\r\n  /*\r\n  int skipModeBitsLoc = 0;\r\n  if (c == L'D')\r\n  {\r\n    skipModeBitsLoc = 2;\r\n    c = GetUpperChar(*s++);\r\n  }\r\n  */\r\n  if (c != L'\\0')\r\n    return 0;\r\n  *btMode = 1;\r\n  *numHashBytes = numHashBytesLoc;\r\n  // *skipModeBits = skipModeBitsLoc;\r\n  return 1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, \r\n    const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  for (UInt32 i = 0; i < numProperties; i++)\r\n  {\r\n    const PROPVARIANT &prop = properties[i];\r\n    switch(propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 numFastBytes = prop.ulVal;\r\n        if(numFastBytes < 5 || numFastBytes > kMatchMaxLen)\r\n          return E_INVALIDARG;\r\n        _numFastBytes = numFastBytes;\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinderCycles:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        _matchFinderCycles = prop.ulVal;\r\n        break;\r\n      }\r\n      case NCoderPropID::kAlgorithm:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 maximize = prop.ulVal;\r\n        _fastMode = (maximize == 0); \r\n        // _maxMode = (maximize >= 2);\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinder:\r\n      {\r\n        if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        if (!ParseMatchFinder(prop.bstrVal, &_matchFinderBase.btMode, &_matchFinderBase.numHashBytes /* , &_matchFinderBase.skipModeBits */))\r\n          return E_INVALIDARG;\r\n        break;\r\n      }\r\n      case NCoderPropID::kMultiThread:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        #ifdef COMPRESS_MF_MT\r\n        Bool newMultiThread = (prop.boolVal == VARIANT_TRUE);\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          ReleaseMatchFinder();\r\n          _multiThread = newMultiThread;\r\n        }\r\n        #endif\r\n        break;\r\n      }\r\n      case NCoderPropID::kNumThreads:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        #ifdef COMPRESS_MF_MT\r\n        Bool newMultiThread = (prop.ulVal > 1) ? True : False;\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          ReleaseMatchFinder();\r\n          _multiThread = newMultiThread;\r\n        }\r\n        #endif\r\n        break;\r\n      }\r\n      case NCoderPropID::kDictionarySize:\r\n      {\r\n        const int kDicLogSizeMaxCompress = 30; // must be <= ((kNumLogBits - 1) * 2) + 7 = 31;\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 dictionarySize = prop.ulVal;\r\n        if (dictionarySize < UInt32(1 << kDicLogSizeMin) ||\r\n            dictionarySize > UInt32(1 << kDicLogSizeMaxCompress))\r\n          return E_INVALIDARG;\r\n        _dictionarySize = dictionarySize;\r\n        UInt32 dicLogSize;\r\n        for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n          if (dictionarySize <= (UInt32(1) << dicLogSize))\r\n            break;\r\n        _distTableSize = dicLogSize * 2;\r\n        break;\r\n      }\r\n      case NCoderPropID::kPosStateBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _posStateBits = value;\r\n        _posStateMask = (1 << _posStateBits) - 1;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitPosBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralPosStateBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitContextBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitContextBitsMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralContextBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kEndMarker:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE);\r\n        break;\r\n      }\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{ \r\n  const UInt32 kPropSize = 5;\r\n  Byte properties[kPropSize];\r\n  properties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n  for (int i = 0; i < 4; i++)\r\n    properties[1 + i] = Byte(_dictionarySize >> (8 * i));\r\n  return WriteStream(outStream, properties, kPropSize, NULL);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _rangeEncoder.SetStream(outStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _rangeEncoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Init()\r\n{\r\n  CBaseState::Init();\r\n\r\n  _rangeEncoder.Init();\r\n\r\n  for(int i = 0; i < kNumStates; i++)\r\n  {\r\n    for (UInt32 j = 0; j <= _posStateMask; j++)\r\n    {\r\n      _isMatch[i][j].Init();\r\n      _isRep0Long[i][j].Init();\r\n    }\r\n    _isRep[i].Init();\r\n    _isRepG0[i].Init();\r\n    _isRepG1[i].Init();\r\n    _isRepG2[i].Init();\r\n  }\r\n\r\n  _literalEncoder.Init();\r\n\r\n  {\r\n    for(UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n      _posSlotEncoder[i].Init();\r\n  }\r\n  {\r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posEncoders[i].Init();\r\n  }\r\n\r\n  _lenEncoder.Init(1 << _posStateBits);\r\n  _repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n  _posAlignEncoder.Init();\r\n\r\n  _longestMatchWasFound = false;\r\n  _optimumEndIndex = 0;\r\n  _optimumCurrentIndex = 0;\r\n  _additionalOffset = 0;\r\n\r\n  return S_OK;\r\n}\r\n\r\n#ifdef SHOW_STAT\r\nstatic int ttt = 0;\r\n#endif\r\n\r\nvoid CEncoder::MovePos(UInt32 num)\r\n{\r\n  #ifdef SHOW_STAT\r\n  ttt += num;\r\n  printf(\"\\n MovePos %d\", num);\r\n  #endif\r\n  if (num != 0)\r\n  {\r\n    _additionalOffset += num;\r\n    _matchFinder.Skip(_matchFinderObj, num);\r\n  }\r\n}\r\n\r\nUInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)\r\n{\r\n  _optimumEndIndex = cur;\r\n  UInt32 posMem = _optimum[cur].PosPrev;\r\n  UInt32 backMem = _optimum[cur].BackPrev;\r\n  do\r\n  {\r\n    if (_optimum[cur].Prev1IsChar)\r\n    {\r\n      _optimum[posMem].MakeAsChar();\r\n      _optimum[posMem].PosPrev = posMem - 1;\r\n      if (_optimum[cur].Prev2)\r\n      {\r\n        _optimum[posMem - 1].Prev1IsChar = false;\r\n        _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n        _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n      }\r\n    }\r\n    UInt32 posPrev = posMem;\r\n    UInt32 backCur = backMem;\r\n\r\n    backMem = _optimum[posPrev].BackPrev;\r\n    posMem = _optimum[posPrev].PosPrev;\r\n\r\n    _optimum[posPrev].BackPrev = backCur;\r\n    _optimum[posPrev].PosPrev = cur;\r\n    cur = posPrev;\r\n  }\r\n  while(cur != 0);\r\n  backRes = _optimum[0].BackPrev;\r\n  _optimumCurrentIndex  = _optimum[0].PosPrev;\r\n  return _optimumCurrentIndex; \r\n}\r\n\r\n/*\r\nOut:\r\n  (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal\r\n*/\r\n\r\nUInt32 CEncoder::GetOptimum(UInt32 position, UInt32 &backRes)\r\n{\r\n  if(_optimumEndIndex != _optimumCurrentIndex)\r\n  {\r\n    const COptimal &optimum = _optimum[_optimumCurrentIndex];\r\n    UInt32 lenRes = optimum.PosPrev - _optimumCurrentIndex;\r\n    backRes = optimum.BackPrev;\r\n    _optimumCurrentIndex = optimum.PosPrev;\r\n    return lenRes;\r\n  }\r\n  _optimumCurrentIndex = _optimumEndIndex = 0;\r\n  \r\n  UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n\r\n  UInt32 lenMain, numDistancePairs;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    lenMain = ReadMatchDistances(numDistancePairs);\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    numDistancePairs = _numDistancePairs;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n  const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n  if (numAvailableBytes < 2)\r\n  {\r\n    backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n  if (numAvailableBytes > kMatchMaxLen)\r\n    numAvailableBytes = kMatchMaxLen;\r\n\r\n  UInt32 reps[kNumRepDistances];\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  UInt32 i;\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    reps[i] = _repDistances[i];\r\n    const Byte *data2 = data - (reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    UInt32 lenTest;\r\n    for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    UInt32 lenRes = repLens[repMaxIndex];\r\n    MovePos(lenRes - 1);\r\n    return lenRes;\r\n  }\r\n\r\n  UInt32 *matchDistances = _matchDistances;\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; \r\n    MovePos(lenMain - 1);\r\n    return lenMain;\r\n  }\r\n  Byte currentByte = *data;\r\n  Byte matchByte = *(data - (reps[0] + 1));\r\n\r\n  if(lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    backRes = (UInt32)-1;\r\n    return 1;\r\n  }\r\n\r\n  _optimum[0].State = _state;\r\n\r\n  UInt32 posState = (position & _posStateMask);\r\n\r\n  _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() + \r\n      _literalEncoder.GetSubCoder(position, _previousByte)->GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n  _optimum[1].MakeAsChar();\r\n\r\n  UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1();\r\n  UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n  if(matchByte == currentByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n    if(shortRepPrice < _optimum[1].Price)\r\n    {\r\n      _optimum[1].Price = shortRepPrice;\r\n      _optimum[1].MakeAsShortRep();\r\n    }\r\n  }\r\n  UInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n  if(lenEnd < 2)\r\n  {\r\n    backRes = _optimum[1].BackPrev;\r\n    return 1;\r\n  }\r\n\r\n  _optimum[1].PosPrev = 0;\r\n  for (i = 0; i < kNumRepDistances; i++)\r\n    _optimum[0].Backs[i] = reps[i];\r\n\r\n  UInt32 len = lenEnd;\r\n  do\r\n    _optimum[len--].Price = kIfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    if (repLen < 2)\r\n      continue;\r\n    UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n      COptimal &optimum = _optimum[repLen];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = i;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n    }\r\n    while(--repLen >= 2);\r\n  }\r\n\r\n  UInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= lenMain)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matchDistances[offs])\r\n      offs += 2;\r\n    for(; ; len++)\r\n    {\r\n      UInt32 distance = matchDistances[offs + 1];\r\n      UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n      COptimal &optimum = _optimum[len];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = distance + kNumRepDistances;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n      if (len == matchDistances[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numDistancePairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  UInt32 cur = 0;\r\n\r\n  for (;;)\r\n  {\r\n    cur++;\r\n    if(cur == lenEnd)\r\n    {\r\n      return Backward(backRes, cur);\r\n    }\r\n    UInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n    UInt32 newLen, numDistancePairs;\r\n    newLen = ReadMatchDistances(numDistancePairs);\r\n    if(newLen >= _numFastBytes)\r\n    {\r\n      _numDistancePairs = numDistancePairs;\r\n      _longestMatchLength = newLen;\r\n      _longestMatchWasFound = true;\r\n      return Backward(backRes, cur);\r\n    }\r\n    position++;\r\n    COptimal &curOptimum = _optimum[cur];\r\n    UInt32 posPrev = curOptimum.PosPrev;\r\n    CState state;\r\n    if (curOptimum.Prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOptimum.Prev2)\r\n      {\r\n        state = _optimum[curOptimum.PosPrev2].State;\r\n        if (curOptimum.BackPrev2 < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      else\r\n        state = _optimum[posPrev].State;\r\n      state.UpdateChar();\r\n    }\r\n    else\r\n      state = _optimum[posPrev].State;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (curOptimum.IsShortRep())\r\n        state.UpdateShortRep();\r\n      else\r\n        state.UpdateChar();\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      if (curOptimum.Prev1IsChar && curOptimum.Prev2)\r\n      {\r\n        posPrev = curOptimum.PosPrev2;\r\n        pos = curOptimum.BackPrev2;\r\n        state.UpdateRep();\r\n      }\r\n      else\r\n      {\r\n        pos = curOptimum.BackPrev;\r\n        if (pos < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      const COptimal &prevOptimum = _optimum[posPrev];\r\n      if (pos < kNumRepDistances)\r\n      {\r\n        reps[0] = prevOptimum.Backs[pos];\r\n        UInt32 i;\r\n        for(i = 1; i <= pos; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n        for(; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i];\r\n      }\r\n      else\r\n      {\r\n        reps[0] = (pos - kNumRepDistances);\r\n        for(UInt32 i = 1; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n      }\r\n    }\r\n    curOptimum.State = state;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n      curOptimum.Backs[i] = reps[i];\r\n    UInt32 curPrice = curOptimum.Price; \r\n    const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n    const Byte currentByte = *data;\r\n    const Byte matchByte = *(data - (reps[0] + 1));\r\n\r\n    UInt32 posState = (position & _posStateMask);\r\n\r\n    UInt32 curAnd1Price = curPrice +\r\n        _isMatch[state.Index][posState].GetPrice0() +\r\n        _literalEncoder.GetSubCoder(position, *(data - 1))->GetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n    COptimal &nextOptimum = _optimum[cur + 1];\r\n\r\n    bool nextIsChar = false;\r\n    if (curAnd1Price < nextOptimum.Price) \r\n    {\r\n      nextOptimum.Price = curAnd1Price;\r\n      nextOptimum.PosPrev = cur;\r\n      nextOptimum.MakeAsChar();\r\n      nextIsChar = true;\r\n    }\r\n\r\n    UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();\r\n    UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n    \r\n    if(matchByte == currentByte &&\r\n        !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n      if(shortRepPrice <= nextOptimum.Price)\r\n      {\r\n        nextOptimum.Price = shortRepPrice;\r\n        nextOptimum.PosPrev = cur;\r\n        nextOptimum.MakeAsShortRep();\r\n        nextIsChar = true;\r\n      }\r\n    }\r\n    /*\r\n    if(newLen == 2 && matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n      continue;\r\n    */\r\n\r\n    numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n    UInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n    if (numAvailableBytes < 2)\r\n      continue;\r\n    if (numAvailableBytes > _numFastBytes)\r\n      numAvailableBytes = _numFastBytes;\r\n    if (!nextIsChar && matchByte != currentByte) // speed optimization\r\n    {\r\n      // try Literal + rep0\r\n      const Byte *data2 = data - (reps[0] + 1);\r\n      UInt32 limit = MyMin(numAvailableBytesFull, _numFastBytes + 1);\r\n      UInt32 temp;\r\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r\n      UInt32 lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        CState state2 = state;\r\n        state2.UpdateChar();\r\n        UInt32 posStateNext = (position + 1) & _posStateMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price + \r\n            _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n            _isRep[state2.Index].GetPrice1();\r\n        // for (; lenTest2 >= 2; lenTest2--)\r\n        {\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while(lenEnd < offset)\r\n            _optimum[++lenEnd].Price = kIfinityPrice;\r\n          UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n              0, lenTest2, state2, posStateNext);\r\n          COptimal &optimum = _optimum[offset];\r\n          if (curAndLenPrice < optimum.Price) \r\n          {\r\n            optimum.Price = curAndLenPrice;\r\n            optimum.PosPrev = cur + 1;\r\n            optimum.BackPrev = 0;\r\n            optimum.Prev1IsChar = true;\r\n            optimum.Prev2 = false;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    UInt32 startLen = 2; // speed optimization \r\n    for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)\r\n    {\r\n      // UInt32 repLen = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n      const Byte *data2 = data - (reps[repIndex] + 1);\r\n      if (data[0] != data2[0] || data[1] != data2[1])\r\n        continue;\r\n      UInt32 lenTest;\r\n      for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);\r\n      while(lenEnd < cur + lenTest)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n      UInt32 lenTestTemp = lenTest;\r\n      UInt32 price = repMatchPrice + GetPureRepPrice(repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = repIndex;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n      }\r\n      while(--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      // if (_maxMode)\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateRep();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = \r\n                price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState) + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice(\r\n                true, data2[lenTest], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextRepMatchPrice = curAndLenCharPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n                _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while(lenEnd < offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    \r\n    //    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n    if (newLen > numAvailableBytes)\r\n    {\r\n      newLen = numAvailableBytes;\r\n      for (numDistancePairs = 0; newLen > matchDistances[numDistancePairs]; numDistancePairs += 2);\r\n      matchDistances[numDistancePairs] = newLen;\r\n      numDistancePairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n      while(lenEnd < cur + newLen)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n      UInt32 offs = 0;\r\n      while(startLen > matchDistances[offs])\r\n        offs += 2;\r\n      UInt32 curBack = matchDistances[offs + 1];\r\n      UInt32 posSlot = GetPosSlot2(curBack);\r\n      for(UInt32 lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice;\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += _distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += _posSlotPrices[lenToPosState][posSlot] + _alignPrices[curBack & kAlignMask];\r\n  \r\n        curAndLenPrice += _lenEncoder.GetPrice(lenTest - kMatchMinLen, posState);\r\n        \r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = curBack + kNumRepDistances;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matchDistances[offs])\r\n        {\r\n          // Try Match + Literal + Rep0\r\n          const Byte *data2 = data - (curBack + 1);\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateMatch();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice( \r\n                true, data2[lenTest], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (posStateNext + 1) & _posStateMask;\r\n            UInt32 nextRepMatchPrice = curAndLenCharPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n                _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while(lenEnd < offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = curBack + kNumRepDistances;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numDistancePairs)\r\n            break;\r\n          curBack = matchDistances[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            posSlot = GetPosSlot2(curBack);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n{\r\n  return ((bigDist >> 7) > smallDist);\r\n}\r\n\r\nUInt32 CEncoder::ReadMatchDistances(UInt32 &numDistancePairs)\r\n{\r\n  UInt32 lenRes = 0;\r\n  numDistancePairs = _matchFinder.GetMatches(_matchFinderObj, _matchDistances);\r\n  #ifdef SHOW_STAT\r\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numDistancePairs / 2);\r\n  if (ttt >= 61994)\r\n    ttt = ttt;\r\n\r\n  ttt++;\r\n  for (UInt32 i = 0; i < numDistancePairs; i += 2)\r\n    printf(\"%2d %6d   | \", _matchDistances[i], _matchDistances[i + 1]);\r\n  #endif\r\n  if (numDistancePairs > 0)\r\n  {\r\n    lenRes = _matchDistances[numDistancePairs - 2];\r\n    if (lenRes == _numFastBytes)\r\n    {\r\n      UInt32 numAvail = _matchFinder.GetNumAvailableBytes(_matchFinderObj) + 1;\r\n      const Byte *pby = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n      UInt32 distance = _matchDistances[numDistancePairs - 1] + 1;\r\n      if (numAvail > kMatchMaxLen)\r\n        numAvail = kMatchMaxLen;\r\n\r\n      const Byte *pby2 = pby - distance;\r\n      for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r\n    }\r\n  }\r\n  _additionalOffset++;\r\n  return lenRes;\r\n}\r\n\r\nUInt32 CEncoder::GetOptimumFast(UInt32 &backRes)\r\n{\r\n  UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n  UInt32 lenMain, numDistancePairs;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    lenMain = ReadMatchDistances(numDistancePairs);\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    numDistancePairs = _numDistancePairs;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n  const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n  if (numAvailableBytes > kMatchMaxLen)\r\n    numAvailableBytes = kMatchMaxLen;\r\n  if (numAvailableBytes < 2)\r\n  {\r\n    backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n\r\n  for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    const Byte *data2 = data - (_repDistances[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    UInt32 len;\r\n    for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);\r\n    if(len >= _numFastBytes)\r\n    {\r\n      backRes = i;\r\n      MovePos(len - 1);\r\n      return len;\r\n    }\r\n    repLens[i] = len;\r\n    if (len > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  UInt32 *matchDistances = _matchDistances;\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; \r\n    MovePos(lenMain - 1);\r\n    return lenMain;\r\n  }\r\n\r\n  UInt32 backMain = 0; // for GCC\r\n  if (lenMain >= 2)\r\n  {\r\n    backMain = matchDistances[numDistancePairs - 1];\r\n    while (numDistancePairs > 2 && lenMain == matchDistances[numDistancePairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matchDistances[numDistancePairs - 3], backMain))\r\n        break;\r\n      numDistancePairs -= 2;\r\n      lenMain = matchDistances[numDistancePairs - 2];\r\n      backMain = matchDistances[numDistancePairs - 1];\r\n    }\r\n    if (lenMain == 2 && backMain >= 0x80)\r\n      lenMain = 1;\r\n  }\r\n\r\n  if (repLens[repMaxIndex] >= 2)\r\n  {\r\n    if (repLens[repMaxIndex] + 1 >= lenMain || \r\n        repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9)) ||\r\n        repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15)))\r\n    {\r\n      backRes = repMaxIndex;\r\n      UInt32 lenRes = repLens[repMaxIndex];\r\n      MovePos(lenRes - 1);\r\n      return lenRes;\r\n    }\r\n  }\r\n  \r\n  if (lenMain >= 2 && numAvailableBytes > 2)\r\n  {\r\n    numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n    _longestMatchLength = ReadMatchDistances(_numDistancePairs);\r\n    if (_longestMatchLength >= 2)\r\n    {\r\n      UInt32 newDistance = matchDistances[_numDistancePairs - 1];\r\n      if (_longestMatchLength >= lenMain && newDistance < backMain || \r\n          _longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance) ||\r\n          _longestMatchLength > lenMain + 1 ||\r\n          _longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain))\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        return 1;\r\n      }\r\n    }\r\n    data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n    {\r\n      const Byte *data2 = data - (_repDistances[i] + 1);\r\n      if (data[1] != data2[1] || data[2] != data2[2])\r\n      {\r\n        repLens[i] = 0;\r\n        continue;\r\n      }\r\n      UInt32 len;\r\n      for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);\r\n      if (len + 1 >= lenMain)\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        return 1;\r\n      }\r\n    }\r\n    backRes = backMain + kNumRepDistances; \r\n    MovePos(lenMain - 2);\r\n    return lenMain;\r\n  }\r\n  backRes = UInt32(-1);\r\n  return 1;\r\n}\r\n\r\nHRESULT CEncoder::Flush(UInt32 nowPos)\r\n{\r\n  // ReleaseMFStream();\r\n  if (_matchFinderBase.result != SZ_OK)\r\n    return _matchFinderBase.result;\r\n  WriteEndMarker(nowPos & _posStateMask);\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nvoid CEncoder::WriteEndMarker(UInt32 posState)\r\n{\r\n  // This function for writing End Mark for stream version of LZMA. \r\n  // In current version this feature is not used.\r\n  if (!_writeEndMark)\r\n    return;\r\n\r\n  _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n  _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n  _state.UpdateMatch();\r\n  UInt32 len = kMatchMinLen; // kMatchMaxLen;\r\n  _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n  UInt32 posSlot = (1 << kNumPosSlotBits)  - 1;\r\n  UInt32 lenToPosState = GetLenToPosState(len);\r\n  _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n  UInt32 footerBits = 30;\r\n  UInt32 posReduced = (UInt32(1) << footerBits) - 1;\r\n  _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n  _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n}\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  // _needReleaseMFStream = false;\r\n  #ifdef COMPRESS_MF_MT\r\n  #ifdef USE_ALLOCA\r\n  alloca(0x300);\r\n  #endif\r\n  #endif\r\n  CCoderReleaser coderReleaser(this);\r\n  RINOK(SetStreams(inStream, outStream, inSize, outSize));\r\n  for (;;)\r\n  {\r\n    UInt64 processedInSize;\r\n    UInt64 processedOutSize;\r\n    Int32 finished;\r\n    RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished));\r\n    if (finished != 0)\r\n      break;\r\n    if (progress != 0)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  _inStream = inStream;\r\n  _finished = false;\r\n  RINOK(Create());\r\n  RINOK(SetOutStream(outStream));\r\n  RINOK(Init());\r\n  \r\n  if (!_fastMode)\r\n  {\r\n    FillDistancesPrices();\r\n    FillAlignPrices();\r\n  }\r\n\r\n  _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _lenEncoder.UpdateTables(1 << _posStateBits);\r\n  _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n  nowPos64 = 0;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRes MyRead(void *object, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return (HRes)((CSeqInStream *)object)->RealStream->Read(data, size, processedSize);\r\n}\r\n\r\nHRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)\r\n{\r\n  if (_inStream != 0)\r\n  {\r\n    _seqInStream.RealStream = _inStream;\r\n    _seqInStream.SeqInStream.Read = MyRead;\r\n    _matchFinderBase.stream = &_seqInStream.SeqInStream;\r\n    _matchFinder.Init(_matchFinderObj);\r\n    _needReleaseMFStream = true;\r\n    _inStream = 0;\r\n  }\r\n\r\n\r\n  *finished = 1;\r\n  if (_finished)\r\n    return _matchFinderBase.result;\r\n  _finished = true;\r\n\r\n  if (nowPos64 == 0)\r\n  {\r\n    if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)\r\n      return Flush((UInt32)nowPos64);\r\n    UInt32 len, numDistancePairs;\r\n    len = ReadMatchDistances(numDistancePairs);\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n    _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n    _state.UpdateChar();\r\n    Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset);\r\n    _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte);\r\n    _previousByte = curByte;\r\n    _additionalOffset--;\r\n    nowPos64++;\r\n  }\r\n\r\n  UInt32 nowPos32 = (UInt32)nowPos64;\r\n  UInt32 progressPosValuePrev = nowPos32;\r\n\r\n  if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)\r\n    return Flush(nowPos32);\r\n\r\n  for (;;)\r\n  {\r\n    #ifdef _NO_EXCEPTIONS\r\n    if (_rangeEncoder.Stream.ErrorCode != S_OK)\r\n      return _rangeEncoder.Stream.ErrorCode;\r\n    #endif\r\n    UInt32 pos, len;\r\n\r\n    if (_fastMode)\r\n      len = GetOptimumFast(pos);\r\n    else\r\n      len = GetOptimum(nowPos32, pos);\r\n\r\n    UInt32 posState = nowPos32 & _posStateMask;\r\n    if(len == 1 && pos == 0xFFFFFFFF)\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n      Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset);\r\n      CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(nowPos32, _previousByte);\r\n      if(_state.IsCharState())\r\n        subCoder->Encode(&_rangeEncoder, curByte);\r\n      else\r\n      {\r\n        Byte matchByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _repDistances[0] - 1 - _additionalOffset);\r\n        subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);\r\n      }\r\n      _state.UpdateChar();\r\n      _previousByte = curByte;\r\n    }\r\n    else\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n      if(pos < kNumRepDistances)\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 1);\r\n        if(pos == 0)\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 0);\r\n          _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = _repDistances[pos];\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 1);\r\n          if (pos == 1)\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 0);\r\n          else\r\n          {\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 1);\r\n            _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);\r\n            if (pos == 3)\r\n              _repDistances[3] = _repDistances[2];\r\n            _repDistances[2] = _repDistances[1];\r\n          }\r\n          _repDistances[1] = _repDistances[0];\r\n          _repDistances[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          _state.UpdateShortRep();\r\n        else\r\n        {\r\n          _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n          _state.UpdateRep();\r\n        }\r\n      }\r\n      else\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n        _state.UpdateMatch();\r\n        _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n        pos -= kNumRepDistances;\r\n        UInt32 posSlot = GetPosSlot(pos);\r\n        _posSlotEncoder[GetLenToPosState(len)].Encode(&_rangeEncoder, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1, \r\n                &_rangeEncoder, footerBits, posReduced);\r\n          else\r\n          {\r\n            _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n            _alignPriceCount++;\r\n          }\r\n        }\r\n        _repDistances[3] = _repDistances[2];\r\n        _repDistances[2] = _repDistances[1];\r\n        _repDistances[1] = _repDistances[0];\r\n        _repDistances[0] = pos;\r\n        _matchPriceCount++;\r\n      }\r\n      _previousByte = _matchFinder.GetIndexByte(_matchFinderObj, len - 1 - _additionalOffset);\r\n    }\r\n    _additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (_additionalOffset == 0)\r\n    {\r\n      if (!_fastMode)\r\n      {\r\n        if (_matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices();\r\n        if (_alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices();\r\n      }\r\n      if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)\r\n        return Flush(nowPos32);\r\n      if (nowPos32 - progressPosValuePrev >= (1 << 14))\r\n      {\r\n        nowPos64 += nowPos32 - progressPosValuePrev;\r\n        *inSize = nowPos64;\r\n        *outSize = _rangeEncoder.GetProcessedSize();\r\n        _finished = false;\r\n        *finished = 0;\r\n        return _matchFinderBase.result;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try \r\n  { \r\n  #endif\r\n    return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  #ifndef _NO_EXCEPTIONS\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return E_FAIL; }\r\n  #endif\r\n}\r\n  \r\nvoid CEncoder::FillDistancesPrices()\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  for (UInt32 i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  { \r\n    UInt32 posSlot = GetPosSlot(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = NRangeCoder::ReverseBitTreeGetPrice(_posEncoders + \r\n      base - posSlot - 1, footerBits, i - base);\r\n  }\r\n\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n    UInt32 posSlot;\r\n    NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> &encoder = _posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = _posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = encoder.GetPrice(posSlot);\r\n    for (posSlot = kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);\r\n\r\n    UInt32 *distancesPrices = _distancesPrices[lenToPosState];\r\n    UInt32 i;\r\n    for (i = 0; i < kStartPosModelIndex; i++)\r\n      distancesPrices[i] = posSlotPrices[i];\r\n    for (; i < kNumFullDistances; i++)\r\n      distancesPrices[i] = posSlotPrices[GetPosSlot(i)] + tempPrices[i];\r\n  }\r\n  _matchPriceCount = 0;\r\n}\r\n\r\nvoid CEncoder::FillAlignPrices()\r\n{\r\n  for (UInt32 i = 0; i < kAlignTableSize; i++)\r\n    _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n  _alignPriceCount = 0;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.h",
    "content": "// LZMA/Encoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/Alloc.h\"\r\n  #include \"../../../../C/Compress/Lz/MatchFinder.h\"\r\n  #ifdef COMPRESS_MF_MT\r\n  #include \"../../../../C/Compress/Lz/MatchFinderMt.h\"\r\n  #endif\r\n}\r\n\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;\r\n\r\nclass CBaseState\r\n{\r\nprotected:\r\n  CState _state;\r\n  Byte _previousByte;\r\n  UInt32 _repDistances[kNumRepDistances];\r\n  void Init()\r\n  {\r\n    _state.Init();\r\n    _previousByte = 0;\r\n    for(UInt32 i = 0 ; i < kNumRepDistances; i++)\r\n      _repDistances[i] = 0;\r\n  }\r\n};\r\n\r\nstruct COptimal\r\n{\r\n  CState State;\r\n\r\n  bool Prev1IsChar;\r\n  bool Prev2;\r\n\r\n  UInt32 PosPrev2;\r\n  UInt32 BackPrev2;     \r\n\r\n  UInt32 Price;    \r\n  UInt32 PosPrev;         // posNext;\r\n  UInt32 BackPrev;     \r\n  UInt32 Backs[kNumRepDistances];\r\n  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }\r\n  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n  bool IsShortRep() { return (BackPrev == 0); }\r\n};\r\n\r\n\r\n// #define LZMA_LOG_BRANCH\r\n\r\n#if _MSC_VER >= 1400\r\n// Must give gain in core 2. but slower ~2% on k8.\r\n// #define LZMA_LOG_BSR\r\n#endif\r\n\r\n#ifndef LZMA_LOG_BSR\r\nstatic const int kNumLogBits = 13; // don't change it !\r\nextern Byte g_FastPos[];\r\n#endif\r\ninline UInt32 GetPosSlot(UInt32 pos)\r\n{\r\n  #ifdef LZMA_LOG_BSR\r\n  if (pos < 2)\r\n    return pos;\r\n  unsigned long index;\r\n  _BitScanReverse(&index, pos);\r\n  return (index + index) + ((pos >> (index - 1)) & 1);\r\n  #else\r\n  if (pos < (1 << kNumLogBits))\r\n    return g_FastPos[pos];\r\n  if (pos < (1 << (kNumLogBits * 2 - 1)))\r\n    return g_FastPos[pos >> (kNumLogBits - 1)] + (kNumLogBits - 1) * 2;\r\n  return g_FastPos[pos >> (kNumLogBits - 1) * 2] + (kNumLogBits - 1) * 4;\r\n  #endif\r\n}\r\n\r\ninline UInt32 GetPosSlot2(UInt32 pos)\r\n{\r\n  #ifdef LZMA_LOG_BSR\r\n  unsigned long index;\r\n  _BitScanReverse(&index, pos);\r\n  return (index + index) + ((pos >> (index - 1)) & 1);\r\n  #else\r\n  #ifdef LZMA_LOG_BRANCH\r\n  if (pos < (1 << (kNumLogBits + 6)))\r\n    return g_FastPos[pos >> 6] + 12;\r\n  if (pos < (1 << (kNumLogBits * 2 + 5)))\r\n    return g_FastPos[pos >> (kNumLogBits + 5)] + (kNumLogBits + 5) * 2;\r\n  return g_FastPos[pos >> (kNumLogBits * 2 + 4)] + (kNumLogBits * 2 + 4) * 2;\r\n  #else\r\n  // it's faster with VC6-32bit.\r\n  UInt32 s = 6 + ((kNumLogBits - 1) & (UInt32)((Int32)(((1 << (kNumLogBits + 6)) - 1) -  pos) >> 31));\r\n  return g_FastPos[pos >> s] + (s * 2);\r\n  #endif\r\n  #endif\r\n}\r\n\r\nconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\nconst UInt32 kNumOpts = 1 << 12;\r\n\r\n\r\nclass CLiteralEncoder2\r\n{\r\n  CMyBitEncoder _encoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _encoders[i].Init();\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);\r\n  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;\r\n};\r\n\r\nclass CLiteralEncoder\r\n{\r\n  CLiteralEncoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralEncoder(): _coders(0) {}\r\n  ~CLiteralEncoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)\r\n    { return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CEncoder\r\n{\r\n  CMyBitEncoder _choice;\r\n  CMyBitEncoder _choice2;\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;\r\npublic:\r\n  void Init(UInt32 numPosStates);\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);\r\n  void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;\r\n};\r\n\r\nconst UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\r\n\r\nclass CPriceTableEncoder: public CEncoder\r\n{\r\n  UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];\r\n  UInt32 _tableSize;\r\n  UInt32 _counters[kNumPosStatesEncodingMax];\r\npublic:\r\n  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }\r\n  void UpdateTable(UInt32 posState)\r\n  {\r\n    SetPrices(posState, _tableSize, _prices[posState]);\r\n    _counters[posState] = _tableSize;\r\n  }\r\n  void UpdateTables(UInt32 numPosStates)\r\n  {\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n      UpdateTable(posState);\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)\r\n  {\r\n    CEncoder::Encode(rangeEncoder, symbol, posState);\r\n    if (updatePrice)\r\n      if (--_counters[posState] == 0)\r\n        UpdateTable(posState);\r\n  }\r\n};\r\n\r\n}\r\n\r\ntypedef struct _CSeqInStream\r\n{\r\n  ISeqInStream SeqInStream;\r\n  CMyComPtr<ISequentialInStream> RealStream;\r\n} CSeqInStream;\r\n\r\n\r\nclass CEncoder : \r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CBaseState,\r\n  public CMyUnknownImp\r\n{\r\n  NRangeCoder::CEncoder _rangeEncoder;\r\n\r\n  IMatchFinder _matchFinder;\r\n  void *_matchFinderObj;\r\n  \r\n  #ifdef COMPRESS_MF_MT\r\n  Bool _multiThread;\r\n  Bool _mtMode;\r\n  CMatchFinderMt _matchFinderMt;\r\n  #endif\r\n\r\n  CMatchFinder _matchFinderBase;\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte _pad1[kMtCacheLineDummy];\r\n  #endif\r\n\r\n  COptimal _optimum[kNumOpts];\r\n\r\n  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n  CMyBitEncoder _isRep[kNumStates];\r\n  CMyBitEncoder _isRepG0[kNumStates];\r\n  CMyBitEncoder _isRepG1[kNumStates];\r\n  CMyBitEncoder _isRepG2[kNumStates];\r\n  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];\r\n\r\n  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;\r\n  \r\n  NLength::CPriceTableEncoder _lenEncoder;\r\n  NLength::CPriceTableEncoder _repMatchLenEncoder;\r\n\r\n  CLiteralEncoder _literalEncoder;\r\n\r\n  UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];\r\n\r\n  bool _fastMode;\r\n  // bool _maxMode;\r\n  UInt32 _numFastBytes;\r\n  UInt32 _longestMatchLength;    \r\n  UInt32 _numDistancePairs;\r\n\r\n  UInt32 _additionalOffset;\r\n\r\n  UInt32 _optimumEndIndex;\r\n  UInt32 _optimumCurrentIndex;\r\n\r\n  bool _longestMatchWasFound;\r\n\r\n  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  \r\n  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n\r\n  UInt32 _alignPrices[kAlignTableSize];\r\n  UInt32 _alignPriceCount;\r\n\r\n  UInt32 _distTableSize;\r\n\r\n  UInt32 _posStateBits;\r\n  UInt32 _posStateMask;\r\n  UInt32 _numLiteralPosStateBits;\r\n  UInt32 _numLiteralContextBits;\r\n\r\n  UInt32 _dictionarySize;\r\n\r\n  UInt32 _matchPriceCount;\r\n  UInt64 nowPos64;\r\n  bool _finished;\r\n  ISequentialInStream *_inStream;\r\n\r\n  CSeqInStream _seqInStream;\r\n\r\n  UInt32 _matchFinderCycles;\r\n  // int _numSkip\r\n\r\n  bool _writeEndMark;\r\n\r\n  bool _needReleaseMFStream;\r\n\r\n  void ReleaseMatchFinder()\r\n  {\r\n    _matchFinder.Init = 0;\r\n    _seqInStream.RealStream.Release();\r\n  }\r\n\r\n  void ReleaseMFStream()\r\n  {\r\n    if (_matchFinderObj && _needReleaseMFStream)\r\n    {\r\n      #ifdef COMPRESS_MF_MT\r\n      if (_mtMode)\r\n        MatchFinderMt_ReleaseStream(&_matchFinderMt);\r\n      #endif\r\n      _needReleaseMFStream = false;\r\n    }\r\n    _seqInStream.RealStream.Release();\r\n  }\r\n  \r\n  UInt32 ReadMatchDistances(UInt32 &numDistancePairs);\r\n\r\n  void MovePos(UInt32 num);\r\n  UInt32 GetRepLen1Price(CState state, UInt32 posState) const\r\n  {\r\n    return _isRepG0[state.Index].GetPrice0() +\r\n        _isRep0Long[state.Index][posState].GetPrice0();\r\n  }\r\n  \r\n  UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    if(repIndex == 0)\r\n    {\r\n      price = _isRepG0[state.Index].GetPrice0();\r\n      price += _isRep0Long[state.Index][posState].GetPrice1();\r\n    }\r\n    else\r\n    {\r\n      price = _isRepG0[state.Index].GetPrice1();\r\n      if (repIndex == 1)\r\n        price += _isRepG1[state.Index].GetPrice0();\r\n      else\r\n      {\r\n        price += _isRepG1[state.Index].GetPrice1();\r\n        price += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n      }\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const\r\n  {\r\n    return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +\r\n        GetPureRepPrice(repIndex, state, posState);\r\n  }\r\n  /*\r\n  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const\r\n  {\r\n    if (pos >= kNumFullDistances)\r\n      return kIfinityPrice;\r\n    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);\r\n  }\r\n  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n  */\r\n  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n\r\n  UInt32 Backward(UInt32 &backRes, UInt32 cur);\r\n  UInt32 GetOptimum(UInt32 position, UInt32 &backRes);\r\n  UInt32 GetOptimumFast(UInt32 &backRes);\r\n\r\n  void FillDistancesPrices();\r\n  void FillAlignPrices();\r\n    \r\n  void ReleaseStreams()\r\n  {\r\n    ReleaseMFStream();\r\n    ReleaseOutStream();\r\n  }\r\n\r\n  HRESULT Flush(UInt32 nowPos);\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() { _coder->ReleaseStreams(); }\r\n  };\r\n  friend class CCoderReleaser;\r\n\r\n  void WriteEndMarker(UInt32 posState);\r\n\r\npublic:\r\n  CEncoder();\r\n  void SetWriteEndMarkerMode(bool writeEndMarker)\r\n    { _writeEndMark= writeEndMarker; }\r\n\r\n  HRESULT Create();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  HRESULT Init();\r\n  \r\n  // ICompressCoder interface\r\n  HRESULT SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize);\r\n  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);\r\n\r\n  HRESULT CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressCoder interface\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressSetCoderProperties2\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  \r\n  // ICompressWriteCoderProperties\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA/LZMARegister.cpp",
    "content": "// LZMARegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLZMA::CDecoder); }\r\n#ifndef EXTRACT_ONLY\r\n#include \"LZMAEncoder.h\"\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLZMA::CEncoder);  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x030101, L\"LZMA\", 1, false };\r\n\r\nREGISTER_CODEC(LZMA)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /FAcs /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"C-Lz\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lzma\\LzmaDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lzma\\LzmaDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lzma\\LzmaTypes.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#include \"LzmaBenchCon.h\"\r\n#include \"LzmaRam.h\"\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"LzmaRamDecode.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kMode,\r\n  kDictionary,\r\n  kFastBytes,\r\n  kMatchFinderCycles,\r\n  kLitContext,\r\n  kLitPos,\r\n  kPosBits,\r\n  kMatchFinder,\r\n  kMultiThread,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MT\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kPostChar, false, 0, 0, L\"+\" }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\"\r\n    \"  -d{N}:  set dictionary - [0,30], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -mc{N}: set number of cycles for match finder\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\\n\"\r\n    \"  -mt{N}: set number of CPU threads\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[], \r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);\r\n  if (unsupportedTypes)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }   \r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++]; \r\n\r\n  bool dictionaryIsDefined = false;\r\n  UInt32 dictionary = (UInt32)-1;\r\n  if(parser[NKey::kDictionary].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dictionary = 1 << dicLog;\r\n    dictionaryIsDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  UInt32 numThreads = (UInt32)-1;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (parser[NKey::kMultiThread].ThereIs)\r\n  {\r\n    UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n    const UString &s = parser[NKey::kMultiThread].PostStrings[0];\r\n    if (s.IsEmpty())\r\n      numThreads = numCPUs;\r\n    else\r\n      if (!GetNumber(s, numThreads))\r\n        IncorrectCommand();\r\n  }\r\n  #endif\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 1;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchCon(stderr, numIterations, numThreads, dictionary);\r\n  }\r\n\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = 1;\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++]; \r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\", \r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  COutFileStream *outStreamSpec = NULL;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++]; \r\n    outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\", \r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    UInt32 inSize = (UInt32)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize); \r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)\r\n      throw \"Can not read\";\r\n    if ((UInt32)inSize != processedSize)\r\n      throw \"Read size error\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSizeProcessed;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictionaryIsDefined)\r\n        dictionary = 1 << 23;\r\n      int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, \r\n          dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      size_t outSize;\r\n      if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)\r\n        throw \"data error\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictionaryIsDefined)\r\n      dictionary = 1 << 23;\r\n\r\n    UInt32 posStateBits = 2;\r\n    UInt32 litContextBits = 3; // for normal files\r\n    // UInt32 litContextBits = 0; // for 32-bit data\r\n    UInt32 litPosBits = 0;\r\n    // UInt32 litPosBits = 2; // for 32-bit data\r\n    UInt32 algorithm = 1;\r\n    UInt32 numFastBytes = 128;\r\n    UInt32 matchFinderCycles = 16 + numFastBytes / 2;\r\n    bool matchFinderCyclesDefined = false;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    if(parser[NKey::kMode].ThereIs)\r\n      if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))\r\n        IncorrectCommand();\r\n\r\n    if(parser[NKey::kFastBytes].ThereIs)\r\n      if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))\r\n        IncorrectCommand();\r\n    matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs;\r\n    if (matchFinderCyclesDefined)\r\n      if (!GetNumber(parser[NKey::kMatchFinderCycles].PostStrings[0], matchFinderCycles))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitContext].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitPos].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kPosBits].ThereIs)\r\n      if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))\r\n        IncorrectCommand();\r\n\r\n    PROPID propIDs[] = \r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker,\r\n      NCoderPropID::kNumThreads,\r\n      NCoderPropID::kMatchFinderCycles,\r\n    };\r\n    const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\r\n    PROPVARIANT properties[kNumPropsMax];\r\n    for (int p = 0; p < 6; p++)\r\n      properties[p].vt = VT_UI4;\r\n\r\n    properties[0].ulVal = (UInt32)dictionary;\r\n    properties[1].ulVal = (UInt32)posStateBits;\r\n    properties[2].ulVal = (UInt32)litContextBits;\r\n    properties[3].ulVal = (UInt32)litPosBits;\r\n    properties[4].ulVal = (UInt32)algorithm;\r\n    properties[5].ulVal = (UInt32)numFastBytes;\r\n\r\n    properties[6].vt = VT_BSTR;\r\n    properties[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    properties[7].vt = VT_BOOL;\r\n    properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    properties[8].vt = VT_UI4;\r\n    properties[8].ulVal = (UInt32)numThreads;\r\n\r\n    // it must be last in property list\r\n    properties[9].vt = VT_UI4;\r\n    properties[9].ulVal = (UInt32)matchFinderCycles;\r\n\r\n    int numProps = kNumPropsMax;\r\n    if (!matchFinderCyclesDefined)\r\n      numProps--;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }   \r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }   \r\n  }\r\n  else\r\n  {\r\n    NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte properties[kPropertiesSize];\r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, properties, kPropertiesSize, &processedSize) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (processedSize != kPropertiesSize)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b;\r\n      if (inStream->Read(&b, 1, &processedSize) != S_OK)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      if (processedSize != 1)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      fileSize |= ((UInt64)b) << (8 * i);\r\n    }\r\n    if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }   \r\n  }\r\n  if (outStreamSpec != NULL)\r\n  {\r\n    if (outStreamSpec->Close() != S_OK)\r\n    {\r\n      fprintf(stderr, \"File closing error\");\r\n      return 1;\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n\r\nint main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s) \r\n  { \r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1; \r\n  }\r\n  catch(...) \r\n  { \r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1; \r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#define USE_POSIX_TIME\r\n#define USE_POSIX_TIME2\r\n#endif\r\n\r\n#ifdef USE_POSIX_TIME\r\n#include <time.h>\r\n#ifdef USE_POSIX_TIME2\r\n#include <sys/time.h>\r\n#endif\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef BENCH_MT\r\n#include \"../../../Windows/Thread.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#endif\r\n\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../../Windows/PropVariant.h\"\r\n#else\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#endif\r\n\r\nstatic const UInt32 kUncompressMinBlockSize = 1 << 26;\r\nstatic const UInt32 kAdditionalSize = (1 << 16);\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 5;\r\n\r\nclass CBaseRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CBaseRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd() \r\n  {\r\n    return \r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBenchBuffer\r\n{\r\npublic:\r\n  size_t BufferSize;\r\n  Byte *Buffer;\r\n  CBenchBuffer(): Buffer(0) {} \r\n  virtual ~CBenchBuffer() { Free(); }\r\n  void Free() \r\n  { \r\n    ::MidFree(Buffer);\r\n    Buffer = 0;\r\n  }\r\n  bool Alloc(size_t bufferSize) \r\n  {\r\n    if (Buffer != 0 && BufferSize == bufferSize)\r\n      return true;\r\n    Free();\r\n    Buffer = (Byte *)::MidAlloc(bufferSize);\r\n    BufferSize = bufferSize;\r\n    return (Buffer != 0);\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator: public CBenchBuffer\r\n{\r\n  CBaseRandomGenerator *RG;\r\npublic:\r\n  void Set(CBaseRandomGenerator *rg) { RG = rg; }\r\n  UInt32 GetVal(UInt32 &res, int numBits) \r\n  {\r\n    UInt32 val = res & (((UInt32)1 << numBits) - 1);\r\n    res >>= numBits;\r\n    return val;\r\n  }\r\n  UInt32 GetLen(UInt32 &res) \r\n  { \r\n    UInt32 len = GetVal(res, 2);\r\n    return GetVal(res, 1 + len);\r\n  }\r\n  void Generate()\r\n  {\r\n    UInt32 pos = 0;\r\n    UInt32 rep0 = 1;\r\n    while (pos < BufferSize)\r\n    {\r\n      UInt32 res = RG->GetRnd();\r\n      res >>= 1;\r\n      if (GetVal(res, 1) == 0 || pos < 1024)\r\n        Buffer[pos++] = (Byte)(res & 0xFF);\r\n      else\r\n      {\r\n        UInt32 len;\r\n        len = 1 + GetLen(res);\r\n        if (GetVal(res, 3) != 0)\r\n        {\r\n          len += GetLen(res);\r\n          do\r\n          {\r\n            UInt32 ppp = GetVal(res, 5) + 6;\r\n            res = RG->GetRnd();\r\n            if (ppp > 30)\r\n              continue;\r\n            rep0 = /* (1 << ppp) +*/  GetVal(res, ppp);\r\n            res = RG->GetRnd();\r\n          }\r\n          while (rep0 >= pos);\r\n          rep0++;\r\n        }\r\n\r\n        for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)\r\n          Buffer[pos] = Buffer[pos - rep0];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\n\r\nclass CBenchmarkInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Pos;\r\n  size_t Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t remain = Size - Pos;\r\n  UInt32 kMaxBlockSize = (1 << 20);\r\n  if (size > kMaxBlockSize)\r\n    size = kMaxBlockSize;\r\n  if (size > remain)\r\n    size = (UInt32)remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream: \r\n  public ISequentialOutStream,\r\n  public CBenchBuffer,\r\n  public CMyUnknownImp\r\n{\r\n  // bool _overflow;\r\npublic:\r\n  UInt32 Pos;\r\n  // CBenchmarkOutStream(): _overflow(false) {} \r\n  void Init() \r\n  {\r\n    // _overflow = false;\r\n    Pos = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t curSize = BufferSize - Pos;\r\n  if (curSize > size)\r\n    curSize = size;\r\n  memcpy(Buffer + Pos, data, curSize);\r\n  Pos += (UInt32)curSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)curSize;\r\n  if (curSize != size)\r\n  {\r\n    // _overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  UInt32 Crc;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { Crc = CRC_INIT_VAL; }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  Crc = CrcUpdate(Crc, data, size);\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  timeval v;\r\n  if (gettimeofday(&v, 0) == 0)\r\n    return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;\r\n  return (UInt64)time(NULL) * 1000000;\r\n  #else\r\n  return time(NULL);\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return GetTickCount();\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  return 1000000;\r\n  #else\r\n  return 1;\r\n  #endif \r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return 1000;\r\n  #endif \r\n}\r\n\r\n#ifndef USE_POSIX_TIME\r\nstatic inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }\r\n#endif\r\nstatic UInt64 GetUserTime()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return clock();\r\n  #else\r\n  FILETIME creationTime, exitTime, kernelTime, userTime;\r\n  if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)\r\n    return GetTime64(userTime) + GetTime64(kernelTime);\r\n  return (UInt64)GetTickCount() * 10000;\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetUserFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return CLOCKS_PER_SEC;\r\n  #else\r\n  return 10000000;\r\n  #endif \r\n}\r\n\r\nclass CBenchProgressStatus\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::NSynchronization::CCriticalSection CS;  \r\n  #endif\r\npublic:\r\n  HRESULT Res;\r\n  bool EncodeMode;\r\n  void SetResult(HRESULT res) \r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    Res = res;\r\n  }\r\n  HRESULT GetResult()\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    return Res;\r\n  }\r\n};\r\n\r\nclass CBenchProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CBenchProgressStatus *Status;\r\n  CBenchInfo BenchInfo;\r\n  HRESULT Res;\r\n  IBenchCallback *callback;\r\n  CBenchProgressInfo(): callback(0) {}\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nvoid SetStartTime(CBenchInfo &bi)\r\n{\r\n  bi.GlobalFreq = GetFreq();\r\n  bi.UserFreq = GetUserFreq();\r\n  bi.GlobalTime = ::GetTimeCount();\r\n  bi.UserTime = ::GetUserTime();\r\n}\r\n\r\nvoid SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)\r\n{\r\n  dest.GlobalFreq = GetFreq();\r\n  dest.UserFreq = GetUserFreq();\r\n  dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;\r\n  dest.UserTime = ::GetUserTime() - biStart.UserTime;\r\n}\r\n\r\nSTDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  HRESULT res = Status->GetResult();\r\n  if (res != S_OK)\r\n    return res;\r\n  if (!callback)\r\n    return res;\r\n  CBenchInfo info = BenchInfo;\r\n  SetFinishTime(BenchInfo, info);\r\n  if (Status->EncodeMode)\r\n  {\r\n    info.UnpackSize = *inSize;\r\n    info.PackSize = *outSize;\r\n    res = callback->SetEncodeResult(info, false);\r\n  }\r\n  else\r\n  {\r\n    info.PackSize = BenchInfo.PackSize + *inSize;\r\n    info.UnpackSize = BenchInfo.UnpackSize + *outSize;\r\n    res = callback->SetDecodeResult(info, false);\r\n  }\r\n  if (res != S_OK)\r\n    Status->SetResult(res);\r\n  return res;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nUInt64 GetUsage(const CBenchInfo &info)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userTime, userFreq);\r\n  NormalizeVals(globalFreq, globalTime);\r\n  if (userFreq == 0)\r\n    userFreq = 1;\r\n  if (globalTime == 0)\r\n    globalTime = 1;\r\n  return userTime * globalFreq * 1000000 / userFreq / globalTime;\r\n}\r\n\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userFreq, userTime);\r\n  NormalizeVals(globalTime, globalFreq);\r\n  if (globalFreq == 0)\r\n    globalFreq = 1;\r\n  if (userTime == 0)\r\n    userTime = 1;\r\n  return userFreq * globalTime / globalFreq *  rating / userTime;\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)\r\n{\r\n  UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);\r\n  // UInt64 numCommandsForOne = 1000 + ((t * t * 7) >> (2 * kSubBits)); // AMD K8\r\n  UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits)); // Intel Core2\r\n\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)\r\n{\r\n  // UInt64 numCommands = (inSize * 216 + outSize * 14) * numIterations; // AMD K8\r\n  UInt64 numCommands = (inSize * 220 + outSize * 8) * numIterations; // Intel Core2\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\n#ifdef EXTERNAL_LZMA\r\ntypedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID, \r\n    const GUID *interfaceID, void **outObject);\r\n#endif\r\n\r\nstruct CEncoderInfo;\r\n\r\nstruct CEncoderInfo\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::CThread thread[2];\r\n  #endif\r\n  CMyComPtr<ICompressCoder> encoder;\r\n  CBenchProgressInfo *progressInfoSpec[2];\r\n  CMyComPtr<ICompressProgressInfo> progressInfo[2];\r\n  UInt32 NumIterations;\r\n  #ifdef USE_ALLOCA\r\n  size_t AllocaSize;\r\n  #endif\r\n\r\n  struct CDecoderInfo\r\n  {\r\n    CEncoderInfo *Encoder;\r\n    UInt32 DecoderIndex;\r\n    #ifdef USE_ALLOCA\r\n    size_t AllocaSize;\r\n    #endif\r\n    bool CallbackMode;\r\n  };\r\n  CDecoderInfo decodersInfo[2];\r\n\r\n  CMyComPtr<ICompressCoder> decoders[2];\r\n  HRESULT Results[2];\r\n  CBenchmarkOutStream *outStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  IBenchCallback *callback;\r\n  UInt32 crc;\r\n  UInt32 kBufferSize;\r\n  UInt32 compressedSize;\r\n  CBenchRandomGenerator rg;\r\n  CBenchmarkOutStream *propStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> propStream;\r\n  HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);\r\n  HRESULT Encode();\r\n  HRESULT Decode(UInt32 decoderIndex);\r\n\r\n  CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}\r\n\r\n  #ifdef BENCH_MT\r\n  static THREAD_FUNC_DECL EncodeThreadFunction(void *param)\r\n  {\r\n    CEncoderInfo *encoder = (CEncoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(encoder->AllocaSize);\r\n    #endif\r\n    HRESULT res = encoder->Encode();\r\n    encoder->Results[0] = res;\r\n    if (res != S_OK)\r\n      encoder->progressInfoSpec[0]->Status->SetResult(res);\r\n\r\n    return 0;\r\n  }\r\n  static THREAD_FUNC_DECL DecodeThreadFunction(void *param)\r\n  {\r\n    CDecoderInfo *decoder = (CDecoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(decoder->AllocaSize);\r\n    #endif\r\n    CEncoderInfo *encoder = decoder->Encoder;\r\n    encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);\r\n    return 0;\r\n  }\r\n\r\n  HRESULT CreateEncoderThread()\r\n  {\r\n    return thread[0].Create(EncodeThreadFunction, this);\r\n  }\r\n\r\n  HRESULT CreateDecoderThread(int index, bool callbackMode\r\n      #ifdef USE_ALLOCA\r\n      , size_t allocaSize\r\n      #endif\r\n      )\r\n  {\r\n    CDecoderInfo &decoder = decodersInfo[index];\r\n    decoder.DecoderIndex = index;\r\n    decoder.Encoder = this;\r\n    #ifdef USE_ALLOCA\r\n    decoder.AllocaSize = allocaSize;\r\n    #endif\r\n    decoder.CallbackMode = callbackMode;\r\n    return thread[index].Create(DecodeThreadFunction, &decoder);\r\n  }\r\n  #endif\r\n};\r\n\r\nHRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)\r\n{\r\n  rg.Set(rgLoc);\r\n  kBufferSize = dictionarySize + kAdditionalSize;\r\n  UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n  if (!rg.Alloc(kBufferSize))\r\n    return E_OUTOFMEMORY;\r\n  rg.Generate();\r\n  crc = CrcCalc(rg.Buffer, rg.BufferSize);\r\n\r\n  outStreamSpec = new CBenchmarkOutStream;\r\n  if (!outStreamSpec->Alloc(kCompressedBufferSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  outStream = outStreamSpec;\r\n\r\n  propStreamSpec = 0;\r\n  if (!propStream)\r\n  {\r\n    propStreamSpec = new CBenchmarkOutStream;\r\n    propStream = propStreamSpec;\r\n  }\r\n  if (!propStreamSpec->Alloc(kMaxLzmaPropSize))\r\n    return E_OUTOFMEMORY;\r\n  propStreamSpec->Init();\r\n  \r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kDictionarySize, \r\n    NCoderPropID::kMultiThread\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)dictionarySize;\r\n\r\n  properties[1].vt = VT_BOOL;\r\n  properties[1].boolVal = (numThreads > 1) ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n  {\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));\r\n    if (!setCoderProperties)\r\n      return E_FAIL;\r\n    RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, kNumProps));\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);\r\n    if (writeCoderProperties)\r\n    {\r\n      RINOK(writeCoderProperties->WriteCoderProperties(propStream));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Encode()\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n  outStreamSpec->Init();\r\n\r\n  RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));\r\n  compressedSize = outStreamSpec->Pos;\r\n  encoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Decode(UInt32 decoderIndex)\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];\r\n\r\n  CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;\r\n  decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);\r\n  if (!compressSetDecoderProperties)\r\n    return E_FAIL;\r\n\r\n  CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n  CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n  CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];\r\n  pi->BenchInfo.UnpackSize = 0;\r\n  pi->BenchInfo.PackSize = 0;\r\n\r\n  for (UInt32 j = 0; j < NumIterations; j++)\r\n  {\r\n    inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n    crcOutStreamSpec->Init();\r\n    \r\n    RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));\r\n    UInt64 outSize = kBufferSize;\r\n    RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));\r\n    if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)\r\n      return S_FALSE;\r\n    pi->BenchInfo.UnpackSize += kBufferSize;\r\n    pi->BenchInfo.PackSize += compressedSize;\r\n  }\r\n  decoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nstatic const UInt32 kNumThreadsMax = (1 << 16);\r\n\r\nstruct CBenchEncoders\r\n{\r\n  CEncoderInfo *encoders;\r\n  CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }\r\n  ~CBenchEncoders() { delete []encoders; }\r\n};\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)\r\n{\r\n  UInt32 numEncoderThreads = \r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? numThreads / 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  UInt32 numSubDecoderThreads = \r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)\r\n  {\r\n    return E_INVALIDARG;\r\n  }\r\n\r\n  CBenchEncoders encodersSpec(numEncoderThreads);\r\n  CEncoderInfo *encoders = encodersSpec.encoders;\r\n\r\n  #ifdef EXTERNAL_LZMA\r\n  UString name = L\"LZMA\";\r\n  #endif\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.callback = (i == 0) ? callback : 0;\r\n\r\n    #ifdef EXTERNAL_LZMA\r\n    RINOK(codecs->CreateCoder(name, true, encoder.encoder));\r\n    #else\r\n    encoder.encoder = new NCompress::NLZMA::CEncoder;\r\n    #endif\r\n    for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n    {\r\n      #ifdef EXTERNAL_LZMA\r\n      RINOK(codecs->CreateCoder(name, false, encoder.decoders[j]));\r\n      #else\r\n      encoder.decoders[j] = new NCompress::NLZMA::CDecoder;\r\n      #endif\r\n    }\r\n  }\r\n\r\n  CBaseRandomGenerator rg;\r\n  rg.Init();\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));\r\n  }\r\n\r\n  CBenchProgressStatus status;\r\n  status.Res = S_OK;\r\n  status.EncodeMode = true;\r\n\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;\r\n      encoder.progressInfoSpec[j]->Status = &status;\r\n    }\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numEncoderThreads > 1)\r\n    {\r\n      #ifdef USE_ALLOCA\r\n      encoder.AllocaSize = (i * 16 * 21) & 0x7FF;\r\n      #endif\r\n      RINOK(encoder.CreateEncoderThread())\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Encode());\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  if (numEncoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      encoders[i].thread[0].Wait();\r\n  #endif\r\n\r\n  RINOK(status.Res);\r\n\r\n  CBenchInfo info;\r\n\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = 1; // progressInfoSpec->NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetEncodeResult(info, true));\r\n\r\n\r\n  status.Res = S_OK;\r\n  status.EncodeMode = false;\r\n\r\n  UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;\r\n\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numDecoderThreads > 1)\r\n    {\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        size_t allocaSize = ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF;\r\n        HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)\r\n            #ifdef USE_ALLOCA\r\n            , allocaSize\r\n            #endif\r\n            );\r\n        RINOK(res);\r\n      }\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Decode(0));\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  HRESULT res = S_OK;\r\n  if (numDecoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        CEncoderInfo &encoder = encoders[i];\r\n        encoder.thread[j].Wait();\r\n        if (encoder.Results[j] != S_OK)\r\n          res = encoder.Results[j];\r\n      }\r\n  RINOK(res);\r\n  #endif\r\n  RINOK(status.Res);\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetDecodeResult(info, false));\r\n  RINOK(callback->SetDecodeResult(info, true));\r\n  return S_OK;\r\n}\r\n\r\n\r\ninline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)\r\n{ \r\n  UInt32 hs = dictionary - 1;\r\n  hs |= (hs >> 1);\r\n  hs |= (hs >> 2);\r\n  hs |= (hs >> 4);\r\n  hs |= (hs >> 8);\r\n  hs >>= 1;\r\n  hs |= 0xFFFF;\r\n  if (hs > (1 << 24))\r\n    hs >>= 1;\r\n  hs++;\r\n  return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 + \r\n      (1 << 20) + (multiThread ? (6 << 20) : 0);\r\n}\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  const UInt32 kBufferSize = dictionary;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2);\r\n  UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;\r\n  UInt32 numBigThreads = numThreads / numSubThreads;\r\n  return (kBufferSize + kCompressedBufferSize +\r\n    GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;\r\n}\r\n\r\nstatic bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)\r\n{\r\n  for (UInt32 i = 0; i < numCycles; i++)\r\n    if (CrcCalc(data, size) != crcBase)\r\n      return false;\r\n  return true;\r\n}\r\n\r\n#ifdef BENCH_MT\r\nstruct CCrcInfo\r\n{\r\n  NWindows::CThread Thread;\r\n  const Byte *Data;\r\n  UInt32 Size;\r\n  UInt32 NumCycles;\r\n  UInt32 Crc;\r\n  bool Res;\r\n  void Wait()\r\n  {\r\n    Thread.Wait();\r\n    Thread.Close();\r\n  }\r\n};\r\n\r\nstatic THREAD_FUNC_DECL CrcThreadFunction(void *param)\r\n{\r\n  CCrcInfo *p = (CCrcInfo *)param;\r\n  p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);\r\n  return 0;\r\n}\r\n\r\nstruct CCrcThreads\r\n{\r\n  UInt32 NumThreads;\r\n  CCrcInfo *Items;\r\n  CCrcThreads(): Items(0), NumThreads(0) {}\r\n  void WaitAll()\r\n  {\r\n    for (UInt32 i = 0; i < NumThreads; i++)\r\n      Items[i].Wait();\r\n    NumThreads = 0;\r\n  }\r\n  ~CCrcThreads() \r\n  { \r\n    WaitAll();\r\n    delete []Items; \r\n  }\r\n};\r\n#endif\r\n\r\nstatic UInt32 CrcCalc1(const Byte *buf, UInt32 size)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    crc = CRC_UPDATE_BYTE(crc, buf[i]);\r\n  return CRC_GET_DIGEST(crc);\r\n}\r\n\r\nstatic void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  for (UInt32 i = 0; i < size; i++)\r\n    buf[i] = (Byte)RG.GetRnd();\r\n}\r\n\r\nstatic UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  RandGen(buf, size, RG);\r\n  return CrcCalc1(buf, size);\r\n}\r\n\r\nbool CrcInternalTest()\r\n{\r\n  CBenchBuffer buffer;\r\n  const UInt32 kBufferSize0 = (1 << 8);\r\n  const UInt32 kBufferSize1 = (1 << 10);\r\n  const UInt32 kCheckSize = (1 << 5);\r\n  if (!buffer.Alloc(kBufferSize0 + kBufferSize1))\r\n    return false;\r\n  Byte *buf = buffer.Buffer;\r\n  UInt32 i;\r\n  for (i = 0; i < kBufferSize0; i++)\r\n    buf[i] = (Byte)i;\r\n  UInt32 crc1 = CrcCalc1(buf, kBufferSize0);\r\n  if (crc1 != 0x29058C73)\r\n    return false;\r\n  CBaseRandomGenerator RG;\r\n  RandGen(buf + kBufferSize0, kBufferSize1, RG);\r\n  for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)\r\n    for (UInt32 j = 0; j < kCheckSize; j++)\r\n      if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))\r\n        return false;\r\n  return true;\r\n}\r\n\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)\r\n{\r\n  if (numThreads == 0)\r\n    numThreads = 1;\r\n\r\n  CBenchBuffer buffer;\r\n  size_t totalSize = (size_t)bufferSize * numThreads;\r\n  if (totalSize / numThreads != bufferSize)\r\n    return E_OUTOFMEMORY;\r\n  if (!buffer.Alloc(totalSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  Byte *buf = buffer.Buffer;\r\n  CBaseRandomGenerator RG;\r\n  UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;\r\n\r\n  UInt64 timeVal;\r\n  #ifdef BENCH_MT\r\n  CCrcThreads threads;\r\n  if (numThreads > 1)\r\n  {\r\n    threads.Items = new CCrcInfo[numThreads];\r\n    UInt32 i;\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      Byte *data = buf + (size_t)bufferSize * i;\r\n      info.Data = data;\r\n      info.NumCycles = numCycles;\r\n      info.Size = bufferSize;\r\n      info.Crc = RandGenCrc(data, bufferSize, RG);\r\n    }\r\n    timeVal = GetTimeCount();\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      RINOK(info.Thread.Create(CrcThreadFunction, &info));\r\n      threads.NumThreads++;\r\n    }\r\n    threads.WaitAll();\r\n    for (i = 0; i < numThreads; i++)\r\n      if (!threads.Items[i].Res)\r\n        return S_FALSE;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 crc = RandGenCrc(buf, bufferSize, RG);\r\n    timeVal = GetTimeCount();\r\n    if (!CrcBig(buf, bufferSize, numCycles, crc))\r\n      return S_FALSE;\r\n  }\r\n  timeVal = GetTimeCount() - timeVal;\r\n  if (timeVal == 0)\r\n    timeVal = 1;\r\n\r\n  UInt64 size = (UInt64)numCycles * totalSize;\r\n  speed = MyMultDiv64(size, timeVal, GetFreq());\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LZMABENCH_H\r\n#define __LZMABENCH_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\n\r\nstruct CBenchInfo\r\n{\r\n  UInt64 GlobalTime;\r\n  UInt64 GlobalFreq; \r\n  UInt64 UserTime; \r\n  UInt64 UserFreq;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt32 NumIterations;\r\n  CBenchInfo(): NumIterations(0) {}\r\n};\r\n\r\nstruct IBenchCallback\r\n{\r\n  virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;\r\n  virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;\r\n};\r\n\r\nUInt64 GetUsage(const CBenchInfo &benchOnfo);\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);\r\n\r\nconst int kBenchMinDicLogSize = 18;\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);\r\n\r\nbool CrcInternalTest();\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp",
    "content": "// LzmaBenchCon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaBenchCon.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#if defined(BENCH_MT) || defined(_WIN32)\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#ifdef BREAK_HANDLER\r\n#include \"../../UI/Console/ConsoleClose.h\"\r\n#endif\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nstruct CTotalBenchRes\r\n{\r\n  UInt64 NumIterations;\r\n  UInt64 Rating;\r\n  UInt64 Usage;\r\n  UInt64 RPU;\r\n  void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }\r\n  void Normalize() \r\n  { \r\n    if (NumIterations == 0) \r\n      return;\r\n    Rating /= NumIterations; \r\n    Usage /= NumIterations; \r\n    RPU /= NumIterations; \r\n    NumIterations = 1;\r\n  }\r\n  void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2) \r\n  { \r\n    Rating = (r1.Rating + r2.Rating) / 2; \r\n    Usage = (r1.Usage + r2.Usage) / 2;\r\n    RPU = (r1.RPU + r2.RPU) / 2;\r\n    NumIterations = (r1.NumIterations + r2.NumIterations) / 2;\r\n  }\r\n};\r\n\r\nstruct CBenchCallback: public IBenchCallback\r\n{\r\n  CTotalBenchRes EncodeRes;\r\n  CTotalBenchRes DecodeRes;\r\n  FILE *f;\r\n  void Init() { EncodeRes.Init(); DecodeRes.Init(); }\r\n  void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }\r\n  UInt32 dictionarySize;\r\n  HRESULT SetEncodeResult(const CBenchInfo &info, bool final);\r\n  HRESULT SetDecodeResult(const CBenchInfo &info, bool final);\r\n};\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic void PrintNumber(FILE *f, UInt64 value, int size)\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(value, s);\r\n  fprintf(f, \" \");\r\n  for (int len = (int)strlen(s); len < size; len++)\r\n    fprintf(f, \" \");\r\n  fprintf(f, \"%s\", s);\r\n}\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  PrintNumber(f, rating / 1000000, 6);\r\n}\r\n\r\nstatic void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)\r\n{\r\n  PrintNumber(f, (usage + 5000) / 10000, 5);\r\n  PrintRating(f, rpu);\r\n  PrintRating(f, rating);\r\n}\r\n\r\n\r\nstatic void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)\r\n{\r\n  UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);\r\n  PrintNumber(f, speed / 1024, 7);\r\n  UInt64 usage = GetUsage(info);\r\n  UInt64 rpu = GetRatingPerUsage(info, rating);\r\n  PrintResults(f, usage, rpu, rating);\r\n  res.NumIterations++;\r\n  res.RPU += rpu;\r\n  res.Rating += rating;\r\n  res.Usage += usage;\r\n}\r\n\r\nstatic void PrintTotals(FILE *f, const CTotalBenchRes &res)\r\n{\r\n  fprintf(f, \"       \");\r\n  PrintResults(f, res.Usage, res.RPU, res.Rating);\r\n}\r\n\r\n\r\nHRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);\r\n    PrintResults(f, info, rating, EncodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const char *kSep = \"  | \";\r\n\r\n\r\nHRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);\r\n    fprintf(f, kSep);\r\n    CBenchInfo info2 = info;\r\n    info2.UnpackSize *= info2.NumIterations;\r\n    info2.PackSize *= info2.NumIterations;\r\n    info2.NumIterations = 1;\r\n    PrintResults(f, info2, rating, DecodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)\r\n{\r\n  fprintf(f, \"\\nRAM %s \", sizeString);\r\n  PrintNumber(f, (size >> 20), 5);\r\n  fprintf(f, \" MB,  # %s %3d\", threadsString, (unsigned int)numThreads);\r\n}\r\n\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();  // \r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  if (numThreads > 1)\r\n    numThreads &= ~1;\r\n  if (dictionary == (UInt32)-1)\r\n  {\r\n    int dicSizeLog;\r\n    for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)\r\n      if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)\r\n        break;\r\n    dictionary = (1 << dicSizeLog);\r\n  }\r\n  #else\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 22);\r\n  numThreads = 1;\r\n  #endif\r\n\r\n  PrintRequirements(f, \"usage:\", GetBenchMemoryUsage(numThreads, dictionary), \"Benchmark threads:   \", numThreads);\r\n\r\n  CBenchCallback callback;\r\n  callback.Init();\r\n  callback.f = f;\r\n  \r\n  fprintf(f, \"\\n\\nDict        Compressing          |        Decompressing\\n   \");\r\n  int j;\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"   Speed Usage    R/U Rating\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n   \");\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"    KB/s     %%   MIPS   MIPS\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    const int kStartDicLog = 22;\r\n    int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;\r\n    while (((UInt32)1 << pow) > dictionary)\r\n      pow--;\r\n    for (; ((UInt32)1 << pow) <= dictionary; pow++)\r\n    {\r\n      fprintf(f, \"%2d:\", pow);\r\n      callback.dictionarySize = (UInt32)1 << pow;\r\n      HRESULT res = LzmaBench(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        numThreads, callback.dictionarySize, &callback);\r\n      fprintf(f, \"\\n\");\r\n      RINOK(res);\r\n    }\r\n  }\r\n  callback.Normalize();\r\n  fprintf(f, \"----------------------------------------------------------------\\nAvr:\");\r\n  PrintTotals(f, callback.EncodeRes);\r\n  fprintf(f, \"     \");\r\n  PrintTotals(f, callback.DecodeRes);\r\n  fprintf(f, \"\\nTot:\");\r\n  CTotalBenchRes midRes;\r\n  midRes.SetMid(callback.EncodeRes, callback.DecodeRes);\r\n  PrintTotals(f, midRes);\r\n  fprintf(f, \"\\n\");\r\n  return S_OK;\r\n}\r\n\r\nstruct CTempValues\r\n{\r\n  UInt64 *Values;\r\n  CTempValues(UInt32 num) { Values = new UInt64[num]; }\r\n  ~CTempValues() { delete []Values; }\r\n};\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  #else\r\n  numThreads = 1;\r\n  #endif\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 24);\r\n\r\n  CTempValues speedTotals(numThreads);\r\n  fprintf(f, \"\\n\\nSize\");\r\n  for (UInt32 ti = 0; ti < numThreads; ti++)\r\n  {\r\n    fprintf(f, \" %5d\", ti + 1);\r\n    speedTotals.Values[ti] = 0;\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n\r\n  UInt64 numSteps = 0;\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    for (int pow = 10; pow < 32; pow++)\r\n    {\r\n      UInt32 bufSize = (UInt32)1 << pow;\r\n      if (bufSize > dictionary)\r\n        break;\r\n      fprintf(f, \"%2d: \", pow);\r\n      UInt64 speed;\r\n      for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      {\r\n        #ifdef BREAK_HANDLER\r\n        if (NConsoleClose::TestBreakSignal())\r\n          return E_ABORT;\r\n        #endif\r\n        RINOK(CrcBench(ti + 1, bufSize, speed));\r\n        PrintNumber(f, (speed >> 20), 5);\r\n        speedTotals.Values[ti] += speed;\r\n      }\r\n      fprintf(f, \"\\n\");\r\n      numSteps++;\r\n    }\r\n  }\r\n  if (numSteps != 0)\r\n  {\r\n    fprintf(f, \"\\nAvg:\");\r\n    for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);\r\n    fprintf(f, \"\\n\");\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h",
    "content": "// LzmaBenchCon.h\r\n\r\n#ifndef __LZMABENCHCON_H\r\n#define __LZMABENCHCON_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp",
    "content": "// LzmaRam.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/Compress/Branch/BranchX86.h\"\r\n}\r\n\r\nclass CInStreamRam: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Size;\r\n  size_t Pos;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > (Size - Pos))\r\n    size = (UInt32)(Size - Pos);\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass COutStreamRam: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  size_t Size;\r\npublic:\r\n  Byte *Data;\r\n  size_t Pos;\r\n  bool Overflow;\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n    Overflow = false;\r\n  }\r\n  void SetPos(size_t pos)\r\n  {\r\n    Overflow = false;\r\n    Pos = pos;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  HRESULT WriteByte(Byte b)\r\n  {\r\n    if (Pos >= Size)\r\n    {\r\n      Overflow = true;\r\n      return E_FAIL;\r\n    }\r\n    Data[Pos++] = b;\r\n    return S_OK;\r\n  }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < Size; i++)\r\n    Data[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    Overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\n#define SZ_RAM_E_FAIL (1)\r\n#define SZ_RAM_E_OUTOFMEMORY (2)\r\n#define SZE_OUT_OVERFLOW (3)\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try { \r\n  #endif\r\n\r\n  *outSizeProcessed = 0;\r\n  const size_t kIdSize = 1;\r\n  const size_t kLzmaPropsSize = 5;\r\n  const size_t kMinDestSize = kIdSize + kLzmaPropsSize + 8;\r\n  if (outSize < kMinDestSize)\r\n    return SZE_OUT_OVERFLOW;\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kAlgorithm,\r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kNumFastBytes,\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[1].vt = VT_UI4;\r\n  properties[2].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)2;\r\n  properties[1].ulVal = (UInt32)dictionarySize;\r\n  properties[2].ulVal = (UInt32)64;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n    return 1;\r\n  \r\n  COutStreamRam *outStreamSpec = new COutStreamRam;\r\n  if (outStreamSpec == 0)\r\n    return SZ_RAM_E_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n  CInStreamRam *inStreamSpec = new CInStreamRam;\r\n  if (inStreamSpec == 0)\r\n    return SZ_RAM_E_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\r\n  outStreamSpec->Init(outBuffer, outSize);\r\n  if (outStreamSpec->WriteByte(0) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n\r\n  if (encoderSpec->WriteCoderProperties(outStream) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n  if (outStreamSpec->Pos != kIdSize + kLzmaPropsSize)\r\n    return 1;\r\n  \r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    UInt64 t = (UInt64)(inSize);\r\n    if (outStreamSpec->WriteByte((Byte)((t) >> (8 * i))) != S_OK)\r\n      return SZE_OUT_OVERFLOW;\r\n  }\r\n\r\n  Byte *filteredStream = 0;\r\n\r\n  bool useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (inSize != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(inSize);\r\n      if (filteredStream == 0)\r\n        return SZ_RAM_E_OUTOFMEMORY;\r\n      memmove(filteredStream, inBuffer, inSize);\r\n    }\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(filteredStream, (SizeT)inSize, 0, &x86State, 1);\r\n  }\r\n  \r\n  size_t minSize = 0;\r\n  int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n  bool bestIsFiltered = false;\r\n  int mainResult = 0;\r\n  size_t startPos = outStreamSpec->Pos;\r\n  for (i = 0; i < numPasses; i++)\r\n  {\r\n    if (numPasses > 1 && i == numPasses - 1 && !bestIsFiltered)\r\n      break;\r\n    outStreamSpec->SetPos(startPos);\r\n    bool curModeIsFiltered = false;\r\n    if (useFilter && i == 0)\r\n      curModeIsFiltered = true;\r\n    if (numPasses > 1 && i == numPasses - 1)\r\n      curModeIsFiltered = true;\r\n\r\n    inStreamSpec->Init(curModeIsFiltered ? filteredStream : inBuffer, inSize);\r\n    \r\n    HRESULT lzmaResult = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    \r\n    mainResult = 0;\r\n    if (lzmaResult == E_OUTOFMEMORY)\r\n    {\r\n      mainResult = SZ_RAM_E_OUTOFMEMORY;\r\n      break;\r\n    } \r\n    if (i == 0 || outStreamSpec->Pos <= minSize)\r\n    {\r\n      minSize = outStreamSpec->Pos;\r\n      bestIsFiltered = curModeIsFiltered;\r\n    }\r\n    if (outStreamSpec->Overflow)\r\n      mainResult = SZE_OUT_OVERFLOW;\r\n    else if (lzmaResult != S_OK)\r\n    {\r\n      mainResult = SZ_RAM_E_FAIL;\r\n      break;\r\n    } \r\n  }\r\n  *outSizeProcessed = outStreamSpec->Pos;\r\n  if (bestIsFiltered)\r\n    outBuffer[0] = 1;\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n  \r\n  #ifndef _NO_EXCEPTIONS\r\n  } catch(...) { return SZ_RAM_E_OUTOFMEMORY; }\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h",
    "content": "// LzmaRam.h\r\n\r\n#ifndef __LzmaRam_h\r\n#define __LzmaRam_h\r\n\r\n#include <stdlib.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\n/*\r\nLzmaRamEncode: BCJ + LZMA RAM->RAM compressing.\r\nIt uses .lzma format, but it writes one additional byte to .lzma file:\r\n  0: - no filter\r\n  1: - x86(BCJ) filter.\r\n\r\nTo provide best compression ratio dictionarySize mustbe >= inSize\r\n\r\nLzmaRamEncode allocates Data with MyAlloc/BigAlloc functions.\r\nRAM Requirements:\r\n  RamSize = dictionarySize * 9.5 + 6MB + FilterBlockSize \r\n    FilterBlockSize = 0, if useFilter == false\r\n    FilterBlockSize = inSize, if useFilter == true\r\n\r\n  Return code:\r\n    0 - OK\r\n    1 - Unspecified Error\r\n    2 - Memory allocating error\r\n    3 - Output buffer OVERFLOW\r\n\r\nIf you use SZ_FILTER_AUTO mode, then encoder will use 2 or 3 passes:\r\n  2 passes when FILTER_NO provides better compression.\r\n  3 passes when FILTER_YES provides better compression.\r\n*/\r\n\r\nenum ESzFilterMode \r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c",
    "content": "/* LzmaRamDecode.c */\r\n\r\n#include \"LzmaRamDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#include \"BranchX86.h\"\r\n#else\r\n#include \"../../../../C/Compress/Lzma/LzmaDecode.h\"\r\n#include \"../../../../C/Compress/Branch/BranchX86.h\"\r\n#endif\r\n\r\n#define LZMA_PROPS_SIZE 14\r\n#define LZMA_SIZE_OFFSET 6\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize, \r\n    size_t *outSize)\r\n{\r\n  unsigned int i;\r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  *outSize = 0;\r\n  for(i = 0; i < sizeof(size_t); i++)\r\n    *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);\r\n  for(; i < 8; i++)\r\n    if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)\r\n      return 1;\r\n  return 0;\r\n}\r\n\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *))\r\n{\r\n  CLzmaDecoderState state;  /* it's about 24 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  SizeT inProcessed;\r\n  int useFilter;\r\n  \r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  useFilter = inBuffer[0];\r\n\r\n  *outSizeProcessed = 0;\r\n  if (useFilter > 1)\r\n    return 1;\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return 1;\r\n  state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  result = LzmaDecode(&state,\r\n    inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed,\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  freeFunc(state.Probs);\r\n  if (result != LZMA_RESULT_OK)\r\n    return 1;\r\n  *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(outBuffer, (SizeT)outSizeProcessedLoc, 0, &x86State, 0);\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h",
    "content": "/* LzmaRamDecode.h */\r\n\r\n#ifndef __LzmaRamDecode_h\r\n#define __LzmaRamDecode_h\r\n\r\n#include <stdlib.h>\r\n\r\n/*\r\nLzmaRamGetUncompressedSize:\r\n  In: \r\n    inBuffer - input data\r\n    inSize   - input data size\r\n  Out: \r\n    outSize  - uncompressed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers\r\n*/\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    size_t *outSize);\r\n\r\n\r\n/*\r\nLzmaRamDecompress:\r\n  In: \r\n    inBuffer  - input data\r\n    inSize    - input data size\r\n    outBuffer - output data\r\n    outSize   - output size\r\n    allocFunc - alloc function (can be malloc)\r\n    freeFunc  - free function (can be free)\r\n  Out: \r\n    outSizeProcessed - processed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers / data stream\r\n    2 - Memory allocating error\r\n\r\nMemory requirements depend from properties of LZMA stream.\r\nWith default lzma settings it's about 16 KB.\r\n*/\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/comp.cc",
    "content": "/*\n * Copyright (C) 2006-2007 Junjiro Okajima\n * Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: comp.cc,v 1.3 2007-11-13 13:27:23 jro Exp $ */\n\n// extract some parts from lzma443/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <assert.h>\n#include <errno.h>\n\n#include \"StdAfx.h\"\n#include \"../../../Common/MyInitGuid.h\"\n//#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/StringConvert.h\"\n//#include \"../../../Common/StringToInt.h\"\n//#include \"../../Common/StreamUtils.h\"\n#include \"../LZMA/LZMAEncoder.h\"\n\n#include <pthread.h>\n#include <zlib.h>\n#include \"sqlzma.h\"\n\n//////////////////////////////////////////////////////////////////////\n\nclass CMemoryStream {\nprotected:\n\tBytef *m_data;\n\tUInt64 m_limit;\n\tUInt64 m_pos;\n\npublic:\n\tCMemoryStream(Bytef *data, UInt64 size)\n\t\t: m_data(data), m_limit(size), m_pos(0) {}\n\n\tvirtual ~CMemoryStream() {}\n};\n\nclass CInMemoryStream : public CMemoryStream, public IInStream,\n\t\t\tpublic CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialInStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IInStream);\n\n\tCInMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~CInMemoryStream() {}\n\n\tSTDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\n\t{\n\t\tUInt64 room = m_limit - m_pos;\n\t\tif (size > room)\n\t\t\tsize = room;\n\t\tif (size) {\n\t\t\tmemcpy(data, m_data + m_pos, size);\n\t\t\tm_pos += size;\n\t\t}\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\nclass COutMemoryStream : public CMemoryStream, public IOutStream,\n\t\t\t public CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialOutStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IOutStream);\n\n\tCOutMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~COutMemoryStream() {}\n\n\tUInt32 GetSize() {return m_pos;}\n\n\tSTDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) {\n\t\tif (m_pos + size > m_limit)\n\t\t\treturn -ENOSPC;\n\t\tmemcpy(m_data + m_pos, data, size);\n\t\tm_pos += size;\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n\tSTDMETHOD(SetSize)(Int64 newSize) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\n//////////////////////////////////////////////////////////////////////\n\nstatic int\nLzmaCompress(Bytef *next_in, uInt avail_in, Bytef *next_out, uInt avail_out,\n\t     struct sqlzma_opts *opts, uLong *total_out)\n{\n\tint err;\n\tHRESULT res;\n\tconst Byte a[] = {\n\t\tavail_in, avail_in >> 8, avail_in >> 16, avail_in >> 24,\n\t\t0, 0, 0, 0\n\t};\n\n\tNCompress::NLZMA::CEncoder encoderSpec;\n\tCMyComPtr<ICompressCoder> encoder = &encoderSpec;\n\tencoder->AddRef();\n\tCInMemoryStream inStreamSpec(next_in, avail_in);\n\tCMyComPtr<ISequentialInStream> inStream = &inStreamSpec;\n\tinStream->AddRef();\n\tCOutMemoryStream outStreamSpec(next_out, avail_out);\n\tCMyComPtr<ISequentialOutStream> outStream = &outStreamSpec;\n\toutStream->AddRef();\n\n\t// these values are dpending upon is_lzma() macro in sqlzma.h\n\tconst UInt32 dictionary = opts->dicsize;\n\t//fprintf(stderr, \"dic %u\\n\", dictionary);\n\tconst UString mf = L\"BT4\";\n\tconst UInt32 posStateBits = 2;\n\tconst UInt32 litContextBits = 3; // for normal files\n\t// UInt32 litContextBits = 0; // for 32-bit data\n\tconst UInt32 litPosBits = 0;\n\t// UInt32 litPosBits = 2; // for 32-bit data\n\t//const UInt32 algorithm = 2;\n\tconst UInt32 algorithm = 1;\n\tconst UInt32 numFastBytes = 128;\n\tconst UInt32 matchFinderCycles = 16 + numFastBytes / 2;\n\t//const bool matchFinderCyclesDefined = false;\n\tconst PROPID propIDs[] = {\n\t\tNCoderPropID::kDictionarySize,\n\t\tNCoderPropID::kPosStateBits,\n\t\tNCoderPropID::kLitContextBits,\n\t\tNCoderPropID::kLitPosBits,\n\t\tNCoderPropID::kAlgorithm,\n\t\tNCoderPropID::kNumFastBytes,\n\t\tNCoderPropID::kMatchFinder,\n\t\tNCoderPropID::kEndMarker,\n\t\tNCoderPropID::kNumThreads,\n\t\tNCoderPropID::kMatchFinderCycles\n\t};\n\tconst int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\n\tPROPVARIANT properties[kNumPropsMax];\n\tfor (int p = 0; p < 6; p++)\n\t\tproperties[p].vt = VT_UI4;\n\tproperties[0].ulVal = UInt32(dictionary);\n\tproperties[1].ulVal = UInt32(posStateBits);\n\tproperties[2].ulVal = UInt32(litContextBits);\n\tproperties[3].ulVal = UInt32(litPosBits);\n\tproperties[4].ulVal = UInt32(algorithm);\n\tproperties[5].ulVal = UInt32(numFastBytes);\n\n\tproperties[6].vt = VT_BSTR;\n\tproperties[6].bstrVal = (BSTR)(const wchar_t *)mf;\n\tproperties[7].vt = VT_BOOL;\n\tproperties[7].boolVal = VARIANT_FALSE;\t// EOS\n\tproperties[8].vt = VT_UI4;\n\tproperties[8].ulVal = 1; // numThreads\n\tproperties[9].vt = VT_UI4;\n\tproperties[9].ulVal = UInt32(matchFinderCycles);\n\n\terr = -EINVAL;\n\tres = encoderSpec.SetCoderProperties(propIDs, properties,\n\t\t\t\t\t     kNumPropsMax - 1);\n\tif (res)\n\t\tgoto out;\n\tres = encoderSpec.WriteCoderProperties(outStream);\n\tif (res)\n\t\tgoto out;\n\n\tUInt32 r;\n\tres = outStream->Write(a, sizeof(a), &r);\n\tif (res || r != sizeof(a))\n\t\tgoto out;\n\n\terr = encoder->Code(inStream, outStream, 0, /*broken*/0, 0);\n\tif (err)\n\t\tgoto out;\n\t*total_out = outStreamSpec.GetSize();\n\n out:\n\treturn err;\n}\n\n//////////////////////////////////////////////////////////////////////\n\n#define Failure(p) do { \\\n\tfprintf(stderr, \"%s:%d: please report to jro \" \\\n\t\t\"{%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x}\\n\", \\\n\t\t__func__, __LINE__, \\\n\t\tp[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); \\\n\tabort(); \\\n} while(0)\n\nextern \"C\" int\nsqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in, uInt\n\t  avail_in, Bytef *next_out, uInt avail_out)\n{\n\tint err;\n\tBytef *p = next_out;\n\tuInt l = avail_out;\n\n\tstream->next_in = next_in;\n\tstream->avail_in = avail_in;\n\tstream->next_out = p;\n\tstream->avail_out = l;\n\terr = deflate(stream, Z_FINISH);\n\tif (err != Z_STREAM_END && err != Z_OK)\n\t\tgoto out_err;\n\tif (avail_in < stream->total_out)\n\t\treturn err;\n\tif (is_lzma(*p))\n\t\tFailure(p);\n\n\tif (opts->try_lzma) {\n\t\tunsigned char a[stream->total_out];\n\t\tuLong processed;\n\n\t\tmemcpy(a, p, stream->total_out);\n\n\t\t// malloc family in glibc and stdc++ seems to be thread-safe\n\t\terr = LzmaCompress(next_in, avail_in, p, l, opts, &processed);\n\t\tif (!err && processed <= stream->total_out) {\n\t\t\tif (!is_lzma(*next_out))\n\t\t\t\tFailure(next_out);\n\t\t\tstream->total_out = processed;\n\t\t\terr = Z_STREAM_END;\n\t\t} else {\n\t\t\t//puts(\"by zlib\");\n\t\t\tmemcpy(p, a, stream->total_out);\n\t\t\terr = Z_STREAM_END;\n\t\t}\n\t}\n\treturn err;\n\n out_err:\n\tfprintf(stderr, \"%s: ZLIB err %s\\n\", __func__, zError(err));\n\treturn err;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -DBENCH_MT \\\r\n\r\nLIBS = $(LIBS) oleaut32.lib user32.lib\r\n\r\n!IFDEF CPU\r\nLIBS = $(LIBS) bufferoverflowU.lib \r\nCFLAGS = $(CFLAGS) -GS- -Zc:forScope -W4 -Wp64 -DUNICODE -D_UNICODE\r\n!ENDIF\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n  $O\\LzmaRam.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj\r\n\r\nWIN_OBJS = \\\r\n  $O\\System.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZ_OBJS = \\\r\n  $O\\MatchFinder.obj \\\r\n  $O\\MatchFinderMt.obj \\\r\n\r\nOBJS = \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZ_OBJS) \\\r\n  $O\\LzmaRamDecode.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\LzmaRamDecode.obj: LzmaRamDecode.c\r\n\t$(COMPL_O1)\r\n$O\\LzmaDecode.obj: ../../../../C/Compress/Lzma/LzmaDecode.c\r\n\t$(COMPL_O2)\r\n$O\\BranchX86.obj: ../../../../C/Compress/Branch/BranchX86.c\r\n\t$(COMPL_O2)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c\r\n\r\nifdef SystemDrive\r\nIS_MINGW = 1\r\nendif\r\n\r\nifdef IS_MINGW\r\nFILE_IO =FileIO\r\nFILE_IO_2 =Windows/$(FILE_IO)\r\nLIB2 = -luuid \r\nelse\r\nFILE_IO =C_FileIO\r\nFILE_IO_2 =Common/$(FILE_IO)\r\nendif\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaBenchCon.o \\\r\n  LzmaRam.o \\\r\n  LZMADecoder.o \\\r\n  LZMAEncoder.o \\\r\n  LZOutWindow.o \\\r\n  RangeCoderBit.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  $(FILE_IO).o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  IntToString.o \\\r\n  MyString.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  MyVector.o \\\r\n  7zCrc.o \\\r\n  Alloc.o \\\r\n  BranchX86.o \\\r\n  MatchFinder.o \\\r\n  LzmaDecode.o \\\r\n  LzmaRamDecode.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaBenchCon.o: LzmaBenchCon.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBenchCon.cpp\r\n\r\nLzmaRam.o: LzmaRam.cpp\r\n\t$(CXX) $(CFLAGS) LzmaRam.cpp\r\n\r\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\r\n\r\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\r\n\r\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\r\n\r\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\r\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\n$(FILE_IO).o: ../../../$(FILE_IO_2).cpp\r\n\t$(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp\r\n\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nIntToString.o: ../../../Common/IntToString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp\r\n\r\nMyString.o: ../../../Common/MyString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyString.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nMyVector.o: ../../../Common/MyVector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyVector.cpp\r\n\r\n7zCrc.o: ../../../../C/7zCrc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c\r\n\r\nAlloc.o: ../../../../C/Alloc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c\r\n\r\nBranchX86.o: ../../../../C/Compress/Branch/BranchX86.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c\r\n\r\nMatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c\r\n\r\nLzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c\r\n\r\nLzmaRamDecode.o: LzmaRamDecode.c\r\n\t$(CXX_C) $(CFLAGS) LzmaRamDecode.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/sqlzma.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\ninclude makefile.gcc\n\nifdef UseDebugFlags\nDebugFlags = -Wall -O0 -g -UNDEBUG\nendif\n# -pthread\nCXXFLAGS = ${CFLAGS} -D_REENTRANT -include pthread.h -DNDEBUG ${DebugFlags}\nTgt = liblzma_r.a\n\nall: ${Tgt}\n\nRObjs = LZMAEncoder_r.o Alloc_r.o StreamUtils_r.o MatchFinder_r.o \\\n\tRangeCoderBit_r.o OutBuffer_r.o 7zCrc_r.o\n\n%_r.cc: ../LZMA/%.cpp\n\tln $< $@\n%_r.c: ../../../../C/%.c\n\tln $< $@\n%_r.c: ../../../../C/Compress/Lz/%.c\n\tln $< $@\n%_r.cc: ../../Common/%.cpp\n\tln $< $@\n%_r.cc: ../RangeCoder/%.cpp\n\tln $< $@\nLZMAEncoder_r.o: CXXFLAGS += -I../LZMA\nAlloc_r.o: CFLAGS += -I../../../../C\nStreamUtils_r.o: CXXFLAGS += -I../../Common\nMatchFinder_r.o: CFLAGS += -I../../../../C/Compress/Lz\nRangeCoderBit_r.o: CXXFLAGS += -I../RangeCoder\nOutBuffer_r.o: CXXFLAGS += -I../../Common\n7zCrc_r.o: CFLAGS += -I../../../../C\n\ncomp.o: CXXFLAGS += -I${Sqlzma}\ncomp.o: comp.cc ${Sqlzma}/sqlzma.h\n\nliblzma_r.a: ${RObjs} comp.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) comp.o *_r.o ${Tgt} *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/RangeCoder/RangeCoder.h",
    "content": "// Compress/RangeCoder/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_H\r\n#define __COMPRESS_RANGECODER_H\r\n\r\n#include \"../../Common/InBuffer.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1; \r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) \r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);                      \r\n    } \r\n    _cacheSize++;                               \r\n    Low = (UInt32)Low << 8;                           \r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numTotalBits)\r\n  {\r\n    for (int i = numTotalBits - 1; i >= 0; i--)\r\n    {\r\n      Range >>= 1;\r\n      if (((value >> i) & 1) == 1)\r\n        Low += Range;\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;        \r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8; \r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp",
    "content": "// Compress/RangeCoder/RangeCoderBit.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nUInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\nstatic CPriceTables g_PriceTables;\r\n\r\nCPriceTables::CPriceTables() { Init(); }\r\n\r\nvoid CPriceTables::Init()\r\n{\r\n  const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n  for(int i = kNumBits - 1; i >= 0; i--)\r\n  {\r\n    UInt32 start = 1 << (kNumBits - i - 1);\r\n    UInt32 end = 1 << (kNumBits - i);\r\n    for (UInt32 j = start; j < end; j++)\r\n      ProbPrices[j] = (i << kNumBitPriceShiftBits) + \r\n          (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n  }\r\n\r\n  /*\r\n  // simplest: bad solution\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = kBitPrice;\r\n  */\r\n  \r\n  /*\r\n  const double kDummyMultMid = (1.0 / kBitPrice) / 2;\r\n  const double kDummyMultMid = 0;\r\n  // float solution\r\n  double ln2 = log(double(2));\r\n  double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);\r\n  */\r\n  \r\n  /*\r\n  // experimental, slow, solution:\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n  {\r\n    const int kCyclesBits = 5;\r\n    const UInt32 kCycles = (1 << kCyclesBits);\r\n\r\n    UInt32 range = UInt32(-1);\r\n    UInt32 bitCount = 0;\r\n    for (UInt32 j = 0; j < kCycles; j++)\r\n    {\r\n      range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n      range *= i;\r\n      while(range < (1 << 31))\r\n      {\r\n        range <<= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    bitCount <<= kNumBitPriceShiftBits;\r\n    range -= (1 << 31);\r\n    for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)\r\n    {\r\n      range <<= 1;\r\n      if (range > (1 << 31))\r\n      {\r\n        bitCount += (1 << k);\r\n        range -= (1 << 31);\r\n      }\r\n    }\r\n    ProbPrices[i] = (bitCount \r\n      // + (1 << (kCyclesBits - 1))\r\n      ) >> kCyclesBits;\r\n  }\r\n  */\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h",
    "content": "// Compress/RangeCoder/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_H\r\n#define __COMPRESS_RANGECODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 2;\r\n\r\nconst int kNumBitPriceShiftBits = 6;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nclass CPriceTables\r\n{\r\npublic:\r\n  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  static void Init();\r\n  CPriceTables();\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return CPriceTables::ProbPrices[\r\n      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h",
    "content": "// Compress/RangeCoder/RangeCoderBitTree.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_TREE_H\r\n#define __COMPRESS_RANGECODER_BIT_TREE_H\r\n\r\n#include \"RangeCoderBit.h\"\r\n#include \"RangeCoderOpt.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeEncoder\r\n{\r\n  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  void Encode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int bitIndex = NumBitLevels; bitIndex != 0 ;)\r\n    {\r\n      bitIndex--;\r\n      UInt32 bit = (symbol >> bitIndex) & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n  };\r\n  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int i = 0; i < NumBitLevels; i++)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n      symbol >>= 1;\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    symbol |= (1 << NumBitLevels);\r\n    UInt32 price = 0;\r\n    while (symbol != 1)\r\n    {\r\n      price += Models[symbol >> 1].GetPrice(symbol & 1);\r\n      symbol >>= 1;\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 ReverseGetPrice(UInt32 symbol) const\r\n  {\r\n    UInt32 price = 0;\r\n    UInt32 modelIndex = 1;\r\n    for (int i = NumBitLevels; i != 0; i--)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      symbol >>= 1;\r\n      price += Models[modelIndex].GetPrice(bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n    return price;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeDecoder\r\n{\r\n  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  UInt32 Decode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n    {\r\n      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);\r\n      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)\r\n    }\r\n    RC_FLUSH_VAR\r\n    return modelIndex - (1 << NumBitLevels);\r\n  };\r\n  UInt32 ReverseDecode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    UInt32 symbol = 0;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n    {\r\n      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n      // modelIndex <<= 1;\r\n      // modelIndex += bit;\r\n      // symbol |= (bit << bitIndex);\r\n      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n    }\r\n    RC_FLUSH_VAR\r\n    return symbol;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nvoid ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models, \r\n    CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  for (int i = 0; i < NumBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    Models[modelIndex].Encode(rangeEncoder, bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models, \r\n    UInt32 NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 modelIndex = 1;\r\n  for (int i = NumBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += Models[modelIndex].GetPrice(bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models, \r\n    CDecoder *rangeDecoder, int NumBitLevels)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  UInt32 symbol = 0;\r\n  RC_INIT_VAR\r\n  for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n  {\r\n    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n    // modelIndex <<= 1;\r\n    // modelIndex += bit;\r\n    // symbol |= (bit << bitIndex);\r\n    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n  }\r\n  RC_FLUSH_VAR\r\n  return symbol;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/RangeCoder/RangeCoderOpt.h",
    "content": "// Compress/RangeCoder/RangeCoderOpt.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_OPT_H\r\n#define __COMPRESS_RANGECODER_OPT_H\r\n\r\n#define RC_INIT_VAR \\\r\n  UInt32 range = rangeDecoder->Range; \\\r\n  UInt32 code = rangeDecoder->Code;        \r\n\r\n#define RC_FLUSH_VAR \\\r\n  rangeDecoder->Range = range; \\\r\n  rangeDecoder->Code = code;\r\n\r\n#define RC_NORMALIZE \\\r\n  if (range < NCompress::NRangeCoder::kTopValue) \\\r\n    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }\r\n\r\n#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \\\r\n  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \\\r\n  if (code < bound) \\\r\n  { A0; range = bound; \\\r\n    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \\\r\n    mi <<= 1; } \\\r\n  else \\\r\n  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \\\r\n    mi = (mi + mi) + 1; }} \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/Compress/RangeCoder/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, \r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kMatchFinderCycles,\r\n    kNumPasses = 0x460, \r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kNumThreads,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetCoderMt, 0x25)\r\n{\r\n  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block \r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICompressCodecsInfo, 0x60)\r\n{\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n};\r\nCODER_INTERFACE(ISetCompressCodecsInfo, 0x61)\r\n{\r\n  STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICryptoResetSalt, 0x88)\r\n{\r\n  STDMETHOD(ResetSalt)() PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICryptoResetInitVector, 0x8C)\r\n{\r\n  STDMETHOD(ResetInitVector)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription,\r\n    kDecoderIsAssigned,\r\n    kEncoderIsAssigned\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/IDecl.h",
    "content": "// IDecl.h\r\n\r\n#ifndef __IDECL_H\r\n#define __IDECL_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n\r\n#define DECL_INTERFACE_SUB(i, base, groupId, subId) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \\\r\nstruct i: public base\r\n\r\n#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/IPassword.h",
    "content": "// IPassword.h\r\n\r\n#ifndef __IPASSWORD_H\r\n#define __IPASSWORD_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;\r\n};\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;\r\n};\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/IProgress.h",
    "content": "// Interface/IProgress.h\r\n\r\n#ifndef __IPROGRESS_H\r\n#define __IPROGRESS_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\nDECL_INTERFACE(IProgress, 0, 5)\r\n{\r\n  STDMETHOD(SetTotal)(UInt64 total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000000050002}\r\nDEFINE_GUID(IID_IProgress2, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000050002\")\r\nIProgress2: public IUnknown\r\n{\r\npublic:\r\n  STDMETHOD(SetTotal)(const UInt64 *total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream, \r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/MyVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 57\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.57\"\r\n#define MY_7ZIP_VERSION \"7-Zip 4.57\"\r\n#define MY_DATE \"2007-12-06\"\r\n#define MY_COPYRIGHT \"Copyright (c) 1999-2007 Igor Pavlov\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \"  \" MY_COPYRIGHT \"  \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/MyVersionInfo.rc",
    "content": "#include <WinVer.h>\r\n#include \"MyVersion.h\"\r\n\r\n#define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0\r\n\r\n#ifdef DEBUG\r\n#define DBG_FL VS_FF_DEBUG\r\n#else\r\n#define DBG_FL 0\r\n#endif\r\n\r\n#define MY_VERSION_INFO(fileType, descr, intName, origName)  \\\r\nLANGUAGE 9, 1 \\\r\n1 VERSIONINFO \\\r\n  FILEVERSION MY_VER \\\r\n  PRODUCTVERSION MY_VER \\\r\n  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK \\\r\n  FILEFLAGS DBG_FL \\\r\n  FILEOS VOS_NT_WINDOWS32 \\\r\n  FILETYPE fileType \\\r\n  FILESUBTYPE 0x0L \\\r\nBEGIN \\\r\n    BLOCK \"StringFileInfo\" \\\r\n    BEGIN  \\\r\n        BLOCK \"040904b0\" \\\r\n        BEGIN \\\r\n            VALUE \"CompanyName\", \"Igor Pavlov\" \\\r\n            VALUE \"FileDescription\", descr \\\r\n            VALUE \"FileVersion\", MY_VERSION  \\\r\n            VALUE \"InternalName\", intName \\\r\n            VALUE \"LegalCopyright\", MY_COPYRIGHT \\\r\n            VALUE \"OriginalFilename\", origName \\\r\n            VALUE \"ProductName\", \"7-Zip\" \\\r\n            VALUE \"ProductVersion\", MY_VERSION \\\r\n        END \\\r\n    END \\\r\n    BLOCK \"VarFileInfo\" \\\r\n    BEGIN \\\r\n        VALUE \"Translation\", 0x409, 1200 \\\r\n    END \\\r\nEND\r\n\r\n#define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(VFT_APP, descr, intName, intName \".exe\")\r\n\r\n#define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(VFT_DLL, descr, intName, intName \".dll\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/PropID.h",
    "content": "// Interface/PropID.h\r\n\r\n#ifndef __INTERFACE_PROPID_H\r\n#define __INTERFACE_PROPID_H\r\n\r\nenum\r\n{\r\n  kpidNoProperty = 0,\r\n  \r\n  kpidHandlerItemIndex = 2,\r\n  kpidPath,\r\n  kpidName,\r\n  kpidExtension,\r\n  kpidIsFolder,\r\n  kpidSize,\r\n  kpidPackedSize,\r\n  kpidAttributes,\r\n  kpidCreationTime,\r\n  kpidLastAccessTime,\r\n  kpidLastWriteTime,\r\n  kpidSolid, \r\n  kpidCommented, \r\n  kpidEncrypted, \r\n  kpidSplitBefore, \r\n  kpidSplitAfter, \r\n  kpidDictionarySize, \r\n  kpidCRC, \r\n  kpidType,\r\n  kpidIsAnti,\r\n  kpidMethod,\r\n  kpidHostOS,\r\n  kpidFileSystem,\r\n  kpidUser,\r\n  kpidGroup,\r\n  kpidBlock,\r\n  kpidComment,\r\n  kpidPosition,\r\n  kpidPrefix,\r\n  kpidNumSubFolders,\r\n  kpidNumSubFiles,\r\n  kpidUnpackVer,\r\n  kpidVolume,\r\n  kpidIsVolume,\r\n  kpidOffset,\r\n  kpidLinks,\r\n  kpidNumBlocks,\r\n  kpidNumVolumes,\r\n\r\n  kpidTotalSize = 0x1100,\r\n  kpidFreeSpace, \r\n  kpidClusterSize,\r\n  kpidVolumeName,\r\n\r\n  kpidLocalName = 0x1200,\r\n  kpidProvider,\r\n\r\n  kpidUserDefined = 0x10000\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Client7z/Client7z.cpp",
    "content": "// Client7z.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/DLL.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../MyVersion.h\"\r\n\r\n\r\n// {23170F69-40C1-278A-1000-000110070000}\r\nDEFINE_GUID(CLSID_CFormat7z, \r\n  0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);\r\n\r\nusing namespace NWindows;\r\n\r\n#define kDllName \"7z.dll\"\r\n\r\nstatic const char *kCopyrightString = MY_7ZIP_VERSION\r\n\" (\"  kDllName \" client) \"  \r\nMY_COPYRIGHT \" \" MY_DATE;\r\n\r\nstatic const char *kHelpString = \r\n\"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\\n\"\r\n\"Examples:\\n\"\r\n\"  Client7z.exe a archive.7z f1.txt f2.txt  : compress two files to archive.7z\\n\"\r\n\"  Client7z.exe l archive.7z   : List contents of archive.7z\\n\"\r\n\"  Client7z.exe x archive.7z   : eXtract files from archive.7z\\n\";\r\n\r\n\r\ntypedef UINT32 (WINAPI * CreateObjectFunc)(\r\n    const GUID *clsID, \r\n    const GUID *interfaceID, \r\n    void **outObject);\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nvoid PrintString(const UString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)GetOemString(s));\r\n}\r\n\r\nvoid PrintString(const AString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)s);\r\n}\r\n\r\nvoid PrintNewLine()\r\n{\r\n  PrintString(\"\\n\");\r\n}\r\n\r\nvoid PrintStringLn(const AString &s)\r\n{\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nvoid PrintError(const AString &s)\r\n{\r\n  PrintNewLine();\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nstatic HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsFolder, result);\r\n}\r\n\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Open callback class\r\n\r\n\r\nclass CArchiveOpenCallback: \r\n  public IArchiveOpenCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveOpenCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream); \r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Extracting callback class\r\n\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCRCFailed = \"CRC Failed\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nclass CArchiveExtractCallback: \r\n  public IArchiveExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IArchiveExtractCallback\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  UString _directoryPath;  // Output directory\r\n  UString _filePath;       // name inside arcvhive\r\n  UString _diskFilePath;   // full path to file on disk\r\n  bool _extractMode;\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME UTCLastWriteTime;\r\n    UInt32 Attributes;\r\n    bool IsDirectory;\r\n    bool AttributesAreDefined;\r\n    bool UTCLastWriteTimeIsDefined;\r\n  } _processedFileInfo;\r\n\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n\r\npublic:\r\n  void Init(IInArchive *archiveHandler, const UString &directoryPath);\r\n\r\n  UInt64 NumErrors;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveExtractCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nvoid CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)\r\n{\r\n  NumErrors = 0;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, \r\n    ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  {\r\n    // Get Name\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPath, &propVariant));\r\n    \r\n    UString fullPath;\r\n    if(propVariant.vt == VT_EMPTY)\r\n      fullPath = kEmptyFileAlias;\r\n    else \r\n    {\r\n      if(propVariant.vt != VT_BSTR)\r\n        return E_FAIL;\r\n      fullPath = propVariant.bstrVal;\r\n    }\r\n    _filePath = fullPath;\r\n  }\r\n\r\n  if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)\r\n    return S_OK;\r\n\r\n  {\r\n    // Get Attributes\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &propVariant));\r\n    if (propVariant.vt == VT_EMPTY)\r\n    {\r\n      _processedFileInfo.Attributes = 0;\r\n      _processedFileInfo.AttributesAreDefined = false;\r\n    }\r\n    else\r\n    {\r\n      if (propVariant.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      _processedFileInfo.Attributes = propVariant.ulVal;\r\n      _processedFileInfo.AttributesAreDefined = true;\r\n    }\r\n  }\r\n\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDirectory));\r\n\r\n  {\r\n    // Get Modified Time\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidLastWriteTime, &propVariant));\r\n    _processedFileInfo.UTCLastWriteTimeIsDefined = false;\r\n    switch(propVariant.vt)\r\n    {\r\n      case VT_EMPTY:\r\n        // _processedFileInfo.UTCLastWriteTime = _utcLastWriteTimeDefault;\r\n        break;\r\n      case VT_FILETIME:\r\n        _processedFileInfo.UTCLastWriteTime = propVariant.filetime;\r\n        _processedFileInfo.UTCLastWriteTimeIsDefined = true;\r\n        break;\r\n      default:\r\n        return E_FAIL;\r\n    }\r\n\r\n  }\r\n  {\r\n    // Get Size\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &propVariant));\r\n    bool newFileSizeDefined = (propVariant.vt != VT_EMPTY);\r\n    UInt64 newFileSize;\r\n    if (newFileSizeDefined)\r\n      newFileSize = ConvertPropVariantToUInt64(propVariant);\r\n  }\r\n\r\n  \r\n  {\r\n    // Create folders for file\r\n    int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (slashPos >= 0)\r\n      NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));\r\n  }\r\n\r\n  UString fullProcessedPath = _directoryPath + _filePath;\r\n  _diskFilePath = fullProcessedPath;\r\n\r\n  if (_processedFileInfo.IsDirectory)\r\n  {\r\n    NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n      {\r\n        PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath);\r\n        return E_ABORT;\r\n      }\r\n    }\r\n    \r\n    _outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n    if (!_outFileStreamSpec->Open(fullProcessedPath, CREATE_ALWAYS))\r\n    {\r\n      PrintString((UString)L\"can not open output file \" + fullProcessedPath);\r\n      return E_ABORT;\r\n    }\r\n    _outFileStream = outStreamLoc;\r\n    *outStream = outStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      PrintString(kExtractingString);\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kTest:\r\n      PrintString(kTestingString);\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kSkip:\r\n      PrintString(kSkippingString);\r\n      break;\r\n  };\r\n  PrintString(_filePath);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumErrors++;\r\n      PrintString(\"     \");\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          PrintString(kUnsupportedMethod);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          PrintString(kCRCFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          PrintString(kDataError);\r\n          break;\r\n        default:\r\n          PrintString(kUnknownError);\r\n      }\r\n    }\r\n  }\r\n\r\n  if (_outFileStream != NULL)\r\n  {\r\n    if (_processedFileInfo.UTCLastWriteTimeIsDefined)\r\n      _outFileStreamSpec->SetLastWriteTime(&_processedFileInfo.UTCLastWriteTime);\r\n    RINOK(_outFileStreamSpec->Close());\r\n  }\r\n  _outFileStream.Release();\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream); \r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Creating callback class\r\n\r\nstruct CDirItem\r\n{ \r\n  UInt32 Attributes;\r\n  FILETIME CreationTime;\r\n  FILETIME LastAccessTime;\r\n  FILETIME LastWriteTime;\r\n  UInt64 Size;\r\n  UString Name;\r\n  UString FullPath;\r\n  bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CArchiveUpdateCallback: \r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IUpdateCallback2\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);  \r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  UString DirPrefix;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n  bool m_NeedBeClosed;\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {};\r\n\r\n  ~CArchiveUpdateCallback() { Finilize(); }\r\n  HRESULT Finilize();\r\n\r\n  void Init(const CObjectVector<CDirItem> *dirItems)\r\n  {\r\n    DirItems = dirItems;\r\n    m_NeedBeClosed = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  if(newData != NULL)\r\n    *newData = BoolToInt(true);\r\n  if(newProperties != NULL)\r\n    *newProperties = BoolToInt(true);\r\n  if(indexInArchive != NULL)\r\n    *indexInArchive = UInt32(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    propVariant = false;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[index];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:\r\n        propVariant = dirItem.Name;\r\n        break;\r\n      case kpidIsFolder:\r\n        propVariant = dirItem.IsDirectory();\r\n        break;\r\n      case kpidSize:\r\n        propVariant = dirItem.Size;\r\n        break;\r\n      case kpidAttributes:\r\n        propVariant = dirItem.Attributes;\r\n        break;\r\n      case kpidLastAccessTime:\r\n        propVariant = dirItem.LastAccessTime;\r\n        break;\r\n      case kpidCreationTime:\r\n        propVariant = dirItem.CreationTime;\r\n        break;\r\n      case kpidLastWriteTime:\r\n        propVariant = dirItem.LastWriteTime;\r\n        break;\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveUpdateCallback::Finilize()\r\n{\r\n  if (m_NeedBeClosed)\r\n  {\r\n    PrintNewLine();\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void GetStream2(const wchar_t *name)\r\n{\r\n  PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  PrintString(name);\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  RINOK(Finilize());\r\n\r\n  const CDirItem &dirItem = (*DirItems)[index];\r\n  GetStream2(dirItem.Name);\r\n \r\n  if(dirItem.IsDirectory())\r\n    return S_OK;\r\n\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if(!inStreamSpec->Open(path))\r\n    {\r\n      DWORD sysError = ::GetLastError();\r\n      FailedCodes.Add(sysError);\r\n      FailedFiles.Add(path);\r\n      // if (systemError == ERROR_SHARING_VIOLATION)\r\n      {\r\n        PrintNewLine();\r\n        PrintError(\"WARNING: can't open file\");\r\n        // PrintString(NError::MyFormatMessageW(systemError));\r\n        return S_FALSE;\r\n      }\r\n      // return sysError;\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */)\r\n{\r\n  m_NeedBeClosed = true;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if(!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined) \r\n  {\r\n    if (AskPassword)\r\n    {\r\n      // You can ask real password here from user\r\n      // Password = GetPassword(OutStream); \r\n      // PasswordIsDefined = true;\r\n      PrintError(\"Password is not defined\");\r\n      return E_ABORT;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////////////////\r\n// Main function\r\n\r\nint \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\nmain(int argc, char* argv[])\r\n{\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  #endif\r\n\r\n  PrintStringLn(kCopyrightString);\r\n\r\n  if (argc < 3)\r\n  {\r\n    PrintStringLn(kHelpString);\r\n    return 1;\r\n  }\r\n  NWindows::NDLL::CLibrary library;\r\n  if (!library.Load(TEXT(kDllName)))\r\n  {\r\n    PrintError(\"Can not load library\");\r\n    return 1;\r\n  }\r\n  CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress(\"CreateObject\");\r\n  if (createObjectFunc == 0)\r\n  {\r\n    PrintError(\"Can not get CreateObject\");\r\n    return 1;\r\n  }\r\n\r\n  AString command = argv[1];\r\n  UString archiveName = GetUnicodeString(argv[2], CP_OEMCP);\r\n  if (command.CompareNoCase(\"a\") == 0)\r\n  {\r\n    // create archive command\r\n    if (argc < 4)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n    CObjectVector<CDirItem> dirItems;\r\n    int i;\r\n    for (i = 3; i < argc; i++)\r\n    {\r\n      CDirItem item;\r\n      UString name = GetUnicodeString(argv[i], CP_OEMCP);\r\n      \r\n      NFile::NFind::CFileInfoW fileInfo;\r\n      if (!NFile::NFind::FindFile(name, fileInfo))\r\n      {\r\n        PrintString(UString(L\"Can't find file\") + name);\r\n        return 1;\r\n      }\r\n\r\n      item.Attributes = fileInfo.Attributes;\r\n      item.Size = fileInfo.Size;\r\n      item.CreationTime = fileInfo.CreationTime;\r\n      item.LastAccessTime = fileInfo.LastAccessTime;\r\n      item.LastWriteTime = fileInfo.LastWriteTime;\r\n      item.Name = name;\r\n      item.FullPath = name;\r\n      dirItems.Add(item);\r\n    }\r\n    COutFileStream *outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;\r\n    if (!outFileStreamSpec->Create(archiveName, false))\r\n    {\r\n      PrintError(\"can't create archive file\");\r\n      return 1;\r\n    }\r\n\r\n    CMyComPtr<IOutArchive> outArchive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n\r\n    CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n    CMyComPtr<IArchiveUpdateCallback2> updateCallback(updateCallbackSpec);\r\n    updateCallbackSpec->Init(&dirItems);\r\n    // updateCallbackSpec->PasswordIsDefined = true;\r\n    // updateCallbackSpec->Password = L\"1\";\r\n\r\n    HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);\r\n    updateCallbackSpec->Finilize();\r\n    if (result != S_OK)\r\n    {\r\n      PrintError(\"Update Error\");\r\n      return 1;\r\n    }\r\n    for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)\r\n    {\r\n      PrintNewLine();\r\n      PrintString((UString)L\"Error for file: \" + updateCallbackSpec->FailedFiles[i]);\r\n    }\r\n    if (updateCallbackSpec->FailedFiles.Size() != 0)\r\n      return 1;\r\n  }\r\n  else\r\n  {\r\n    if (argc != 3)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n\r\n    bool listCommand;\r\n    if (command.CompareNoCase(\"l\") == 0)\r\n      listCommand = true;\r\n    else if (command.CompareNoCase(\"x\") == 0)\r\n      listCommand = false;\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      return 1;\r\n    }\r\n  \r\n    CMyComPtr<IInArchive> archive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n    \r\n    CInFileStream *fileSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> file = fileSpec;\r\n    \r\n    if (!fileSpec->Open(archiveName))\r\n    {\r\n      PrintError(\"Can not open archive file\");\r\n      return 1;\r\n    }\r\n\r\n    {\r\n      CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;\r\n      CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);\r\n      openCallbackSpec->PasswordIsDefined = false;\r\n      // openCallbackSpec->PasswordIsDefined = true;\r\n      // openCallbackSpec->Password = L\"1\";\r\n      \r\n      if (archive->Open(file, 0, openCallback) != S_OK)\r\n      {\r\n        PrintError(\"Can not open archive\");\r\n        return 1;\r\n      }\r\n    }\r\n    \r\n    if (listCommand)\r\n    {\r\n      // List command\r\n      UInt32 numItems = 0;\r\n      archive->GetNumberOfItems(&numItems);  \r\n      for (UInt32 i = 0; i < numItems; i++)\r\n      {\r\n        {\r\n          // Get uncompressed size of file\r\n          NWindows::NCOM::CPropVariant propVariant;\r\n          archive->GetProperty(i, kpidSize, &propVariant);\r\n          UString s = ConvertPropVariantToString(propVariant);\r\n          PrintString(s);\r\n          PrintString(\"  \");\r\n        }\r\n        {\r\n          // Get name of file\r\n          NWindows::NCOM::CPropVariant propVariant;\r\n          archive->GetProperty(i, kpidPath, &propVariant);\r\n          UString s = ConvertPropVariantToString(propVariant);\r\n          PrintString(s);\r\n        }\r\n        PrintString(\"\\n\");\r\n      }\r\n    }\r\n    else\r\n    {\r\n      // Extract command\r\n      CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n      CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);\r\n      extractCallbackSpec->Init(archive, L\"\"); // second parameter is output folder path\r\n      extractCallbackSpec->PasswordIsDefined = false;\r\n      // extractCallbackSpec->PasswordIsDefined = true;\r\n      // extractCallbackSpec->Password = L\"1\";\r\n      HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);\r\n      if (result != S_OK)\r\n      {\r\n        PrintError(\"Extract Error\");\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Client7z/Client7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Client7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Client7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\" CFG=\"Client7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Client7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Client7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Client7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Client7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Client7z - Win32 Release\"\r\n# Name \"Client7z - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"stdafx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\Client7z.cpp\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Client7z/Client7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Client7z\"=.\\Client7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Client7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Client7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include <windows.h>\r\n#include <stdio.h>\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Client7z/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\Client7z.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FileStreams.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp",
    "content": "// ArchiveCommandLine.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <io.h>\r\n#endif\r\n#include <stdio.h>\r\n\r\n#include \"Common/ListFileUtils.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/FileMapping.h\"\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ArchiveCommandLine.h\"\r\n#include \"UpdateAction.h\"\r\n#include \"Update.h\"\r\n#include \"SortUtils.h\"\r\n#include \"EnumDirItems.h\"\r\n\r\nextern bool g_CaseSensitive;\r\n\r\n#if _MSC_VER >= 1400\r\n#define MY_isatty_fileno(x) _isatty(_fileno(x))\r\n#else\r\n#define MY_isatty_fileno(x) isatty(fileno(x))\r\n#endif\r\n\r\n#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0); \r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kHelp3,\r\n  kDisableHeaders,\r\n  kDisablePercents,\r\n  kArchiveType,\r\n  kYes,\r\n  kPassword,\r\n  kProperty,\r\n  kOutputDir,\r\n  kWorkingDir,\r\n  kInclude,\r\n  kExclude,\r\n  kArInclude,\r\n  kArExclude,\r\n  kNoArName,\r\n  kUpdate,\r\n  kVolume,\r\n  kRecursed,\r\n  kSfx,\r\n  kStdIn,\r\n  kStdOut,\r\n  kOverwrite,\r\n  kEmail,\r\n  kShowDialog,\r\n  kLargePages,\r\n  kCharSet,\r\n  kTechMode,\r\n  kShareForWrite,\r\n  kCaseSensitive\r\n};\r\n\r\n}\r\n\r\n\r\nstatic const wchar_t kRecursedIDChar = 'R';\r\nstatic const wchar_t *kRecursedPostCharSet = L\"0-\";\r\n\r\nnamespace NRecursedPostCharIndex {\r\n  enum EEnum \r\n  {\r\n    kWildCardRecursionOnly = 0, \r\n    kNoRecursion = 1\r\n  };\r\n}\r\n\r\nstatic const char kImmediateNameID = '!';\r\nstatic const char kMapNameID = '#';\r\nstatic const char kFileListID = '@';\r\n\r\nstatic const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be\r\nstatic const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be\r\n\r\nstatic const wchar_t *kOverwritePostCharSet = L\"asut\";\r\n\r\nNExtract::NOverwriteMode::EEnum k_OverwriteModes[] =\r\n{\r\n  NExtract::NOverwriteMode::kWithoutPrompt,\r\n  NExtract::NOverwriteMode::kSkipExisting,\r\n  NExtract::NOverwriteMode::kAutoRename,\r\n  NExtract::NOverwriteMode::kAutoRenameExisting\r\n};\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n  {\r\n    { L\"?\",  NSwitchType::kSimple, false },\r\n    { L\"H\",  NSwitchType::kSimple, false },\r\n    { L\"-HELP\",  NSwitchType::kSimple, false },\r\n    { L\"BA\", NSwitchType::kSimple, false },\r\n    { L\"BD\", NSwitchType::kSimple, false },\r\n    { L\"T\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"Y\",  NSwitchType::kSimple, false },\r\n    { L\"P\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"M\",  NSwitchType::kUnLimitedPostString, true, 1 },\r\n    { L\"O\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"W\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"I\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"X\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AI\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AX\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AN\", NSwitchType::kSimple, false },\r\n    { L\"U\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"V\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"R\",  NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },\r\n    { L\"SFX\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SI\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SO\", NSwitchType::kSimple, false, 0 },\r\n    { L\"AO\", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},\r\n    { L\"SEML\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"AD\",  NSwitchType::kSimple, false },\r\n    { L\"SLP\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SCS\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SLT\", NSwitchType::kSimple, false },\r\n    { L\"SSW\", NSwitchType::kSimple, false },\r\n    { L\"SSC\", NSwitchType::kPostChar, false, 0, 0, L\"-\" }\r\n  };\r\n\r\nstatic const CCommandForm g_CommandForms[] = \r\n{\r\n  { L\"A\", false },\r\n  { L\"U\", false },\r\n  { L\"D\", false },\r\n  { L\"T\", false },\r\n  { L\"E\", false },\r\n  { L\"X\", false },\r\n  { L\"L\", false },\r\n  { L\"B\", false },\r\n  { L\"I\", false }\r\n};\r\n\r\nstatic const int kNumCommandForms = sizeof(g_CommandForms) /  sizeof(g_CommandForms[0]);\r\n\r\nstatic const wchar_t *kUniversalWildcard = L\"*\";\r\nstatic const int kMinNonSwitchWords = 1;\r\nstatic const int kCommandIndex = 0;\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\";\r\nstatic const char *kIncorrectListFile = \"Incorrect item in listfile.\\nCheck charset encoding and -scs switch.\";\r\nstatic const char *kIncorrectWildCardInListFile = \"Incorrect wildcard in listfile\";\r\nstatic const char *kIncorrectWildCardInCommandLine  = \"Incorrect wildcard in command line\";\r\nstatic const char *kTerminalOutError = \"I won't write compressed data to a terminal\";\r\nstatic const char *kSameTerminalError = \"I won't write data and program's messages to same terminal\";\r\n\r\nstatic void ThrowException(const char *errorMessage)\r\n{\r\n  throw CArchiveCommandLineException(errorMessage);\r\n};\r\n\r\nstatic void ThrowUserErrorException()\r\n{\r\n  ThrowException(kUserErrorMessage);\r\n};\r\n\r\n// ---------------------------\r\n\r\nbool CArchiveCommand::IsFromExtractGroup() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kExtract:\r\n    case NCommandType::kFullExtract:\r\n      return true;\r\n    default:\r\n      return false;\r\n  }\r\n}\r\n\r\nNExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kFullExtract:\r\n      return NExtract::NPathMode::kFullPathnames;\r\n    default:\r\n      return NExtract::NPathMode::kNoPathnames;\r\n  }\r\n}\r\n\r\nbool CArchiveCommand::IsFromUpdateGroup() const\r\n{\r\n  return (CommandType == NCommandType::kAdd || \r\n    CommandType == NCommandType::kUpdate ||\r\n    CommandType == NCommandType::kDelete);\r\n}\r\n\r\nstatic NRecursedType::EEnum GetRecursedTypeFromIndex(int index)\r\n{\r\n  switch (index)\r\n  {\r\n    case NRecursedPostCharIndex::kWildCardRecursionOnly: \r\n      return NRecursedType::kWildCardOnlyRecursed;\r\n    case NRecursedPostCharIndex::kNoRecursion: \r\n      return NRecursedType::kNonRecursed;\r\n    default:\r\n      return NRecursedType::kRecursed;\r\n  }\r\n}\r\n\r\nstatic bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)\r\n{\r\n  UString commandStringUpper = commandString;\r\n  commandStringUpper.MakeUpper();\r\n  UString postString;\r\n  int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper, \r\n      postString) ;\r\n  if (commandIndex < 0)\r\n    return false;\r\n  command.CommandType = (NCommandType::EEnum)commandIndex;\r\n  return true;\r\n}\r\n\r\n// ------------------------------------------------------------------\r\n// filenames functions\r\n\r\nstatic bool AddNameToCensor(NWildcard::CCensor &wildcardCensor, \r\n    const UString &name, bool include, NRecursedType::EEnum type)\r\n{\r\n  bool isWildCard = DoesNameContainWildCard(name);\r\n  bool recursed = false;\r\n\r\n  switch (type)\r\n  {\r\n    case NRecursedType::kWildCardOnlyRecursed:\r\n      recursed = isWildCard;\r\n      break;\r\n    case NRecursedType::kRecursed:\r\n      recursed = true;\r\n      break;\r\n    case NRecursedType::kNonRecursed:\r\n      recursed = false;\r\n      break;\r\n  }\r\n  wildcardCensor.AddItem(include, name, recursed);\r\n  return true;\r\n}\r\n\r\nstatic void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor, \r\n    LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)\r\n{\r\n  UStringVector names;\r\n  if (!ReadNamesFromListFile(fileName, names, codePage))\r\n    throw kIncorrectListFile;\r\n  for (int i = 0; i < names.Size(); i++)\r\n    if (!AddNameToCensor(wildcardCensor, names[i], include, type))\r\n      throw kIncorrectWildCardInListFile;\r\n}\r\n\r\nstatic void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor, \r\n    const UString &name, bool include, NRecursedType::EEnum recursedType)\r\n{\r\n  if (!AddNameToCensor(wildcardCensor, name, include, recursedType))\r\n    throw kIncorrectWildCardInCommandLine;\r\n}\r\n\r\nstatic void AddToCensorFromNonSwitchesStrings(\r\n    int startIndex,\r\n    NWildcard::CCensor &wildcardCensor, \r\n    const UStringVector &nonSwitchStrings, NRecursedType::EEnum type, \r\n    bool thereAreSwitchIncludes, UINT codePage)\r\n{\r\n  if(nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes)) \r\n    AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);\r\n  for(int i = startIndex; i < nonSwitchStrings.Size(); i++)\r\n  {\r\n    const UString &s = nonSwitchStrings[i];\r\n    if (s[0] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);\r\n    else\r\n      AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor, \r\n    const UString &switchParam, bool include, \r\n    NRecursedType::EEnum commonRecursedType)\r\n{\r\n  int splitPos = switchParam.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  UString mappingName = switchParam.Left(splitPos);\r\n  \r\n  UString switchParam2 = switchParam.Mid(splitPos + 1);\r\n  splitPos = switchParam2.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  \r\n  UString mappingSize = switchParam2.Left(splitPos);\r\n  UString eventName = switchParam2.Mid(splitPos + 1);\r\n  \r\n  UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);\r\n  UInt32 dataSize = (UInt32)dataSize64;\r\n  {\r\n    CFileMapping fileMapping;\r\n    if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName)))\r\n      ThrowException(\"Can not open mapping\");\r\n    LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize);\r\n    if (data == NULL)\r\n      ThrowException(\"MapViewOfFile error\");\r\n    try\r\n    {\r\n      const wchar_t *curData = (const wchar_t *)data;\r\n      if (*curData != 0)\r\n        ThrowException(\"Incorrect mapping data\");\r\n      UInt32 numChars = dataSize / sizeof(wchar_t);\r\n      UString name;\r\n      for (UInt32 i = 1; i < numChars; i++)\r\n      {\r\n        wchar_t c = curData[i];\r\n        if (c == L'\\0')\r\n        {\r\n          AddCommandLineWildCardToCensr(wildcardCensor, \r\n              name, include, commonRecursedType);\r\n          name.Empty();\r\n        }\r\n        else\r\n          name += c;\r\n      }\r\n      if (!name.IsEmpty())\r\n        ThrowException(\"data error\");\r\n    }\r\n    catch(...)\r\n    {\r\n      UnmapViewOfFile(data);\r\n      throw;\r\n    }\r\n    UnmapViewOfFile(data);\r\n  }\r\n  \r\n  {\r\n    NSynchronization::CManualResetEvent event;\r\n    if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)\r\n      event.Set();\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor, \r\n    const UStringVector &strings, bool include, \r\n    NRecursedType::EEnum commonRecursedType, UINT codePage)\r\n{\r\n  for(int i = 0; i < strings.Size(); i++)\r\n  {\r\n    const UString &name = strings[i];\r\n    NRecursedType::EEnum recursedType;\r\n    int pos = 0;\r\n    if (name.Length() < kSomeCludePostStringMinSize)\r\n      ThrowUserErrorException();\r\n    if (::MyCharUpper(name[pos]) == kRecursedIDChar)\r\n    {\r\n      pos++;\r\n      int index = UString(kRecursedPostCharSet).Find(name[pos]);\r\n      recursedType = GetRecursedTypeFromIndex(index);\r\n      if (index >= 0)\r\n        pos++;\r\n    }\r\n    else\r\n      recursedType = commonRecursedType;\r\n    if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)\r\n      ThrowUserErrorException();\r\n    UString tail = name.Mid(pos + 1);\r\n    if (name[pos] == kImmediateNameID)\r\n      AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);\r\n    else if (name[pos] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);\r\n    #ifdef _WIN32\r\n    else if (name[pos] == kMapNameID)\r\n      ParseMapWithPaths(wildcardCensor, tail, include, recursedType);\r\n    #endif\r\n    else\r\n      ThrowUserErrorException();\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\n// This code converts all short file names to long file names.\r\n\r\nstatic void ConvertToLongName(const UString &prefix, UString &name)\r\n{\r\n  if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n    return;\r\n  NFind::CFileInfoW fileInfo;\r\n  if (NFind::FindFile(prefix + name, fileInfo))\r\n    name = fileInfo.Name;\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)\r\n{\r\n  for (int i = 0; i < items.Size(); i++)\r\n  {\r\n    NWildcard::CItem &item = items[i];\r\n    if (item.Recursive || item.PathParts.Size() != 1)\r\n      continue;\r\n    ConvertToLongName(prefix, item.PathParts.Front());\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)\r\n{\r\n  ConvertToLongNames(prefix, node.IncludeItems);\r\n  ConvertToLongNames(prefix, node.ExcludeItems);\r\n  int i;\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n    ConvertToLongName(prefix, node.SubNodes[i].Name);\r\n  // mix folders with same name\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];\r\n    for (int j = i + 1; j < node.SubNodes.Size();)\r\n    {\r\n      const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];\r\n      if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)\r\n      {\r\n        nextNode1.IncludeItems += nextNode2.IncludeItems;\r\n        nextNode1.ExcludeItems += nextNode2.ExcludeItems;\r\n        node.SubNodes.Delete(j);\r\n      }\r\n      else\r\n        j++;\r\n    }\r\n  }\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode = node.SubNodes[i];\r\n    ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode); \r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(NWildcard::CCensor &censor)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    NWildcard::CPair &pair = censor.Pairs[i];\r\n    ConvertToLongNames(pair.Prefix, pair.Head);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\nstatic NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)\r\n{\r\n  switch(i)\r\n  {\r\n    case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;\r\n    case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;\r\n    case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;\r\n    case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;\r\n  }\r\n  throw 98111603;\r\n}\r\n\r\nconst UString kUpdatePairStateIDSet = L\"PQRXYZW\";\r\nconst int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};\r\n\r\nconst UString kUpdatePairActionIDSet = L\"0123\"; //Ignore, Copy, Compress, Create Anti\r\n\r\nconst wchar_t *kUpdateIgnoreItselfPostStringID = L\"-\"; \r\nconst wchar_t kUpdateNewArchivePostCharID = '!'; \r\n\r\n\r\nstatic bool ParseUpdateCommandString2(const UString &command, \r\n    NUpdateArchive::CActionSet &actionSet, UString &postString)\r\n{\r\n  for(int i = 0; i < command.Length();)\r\n  {\r\n    wchar_t c = MyCharUpper(command[i]);\r\n    int statePos = kUpdatePairStateIDSet.Find(c);\r\n    if (statePos < 0)\r\n    {\r\n      postString = command.Mid(i);\r\n      return true;\r\n    }\r\n    i++;\r\n    if (i >= command.Length())\r\n      return false;\r\n    int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));\r\n    if (actionPos < 0)\r\n      return false;\r\n    actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);\r\n    if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)\r\n      return false;\r\n    i++;\r\n  }\r\n  postString.Empty();\r\n  return true;\r\n}\r\n\r\nstatic void ParseUpdateCommandString(CUpdateOptions &options, \r\n    const UStringVector &updatePostStrings, \r\n    const NUpdateArchive::CActionSet &defaultActionSet)\r\n{\r\n  for(int i = 0; i < updatePostStrings.Size(); i++)\r\n  {\r\n    const UString &updateString = updatePostStrings[i];\r\n    if(updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)\r\n    {\r\n      if(options.UpdateArchiveItself)\r\n      {\r\n        options.UpdateArchiveItself = false;\r\n        options.Commands.Delete(0);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      NUpdateArchive::CActionSet actionSet = defaultActionSet;\r\n\r\n      UString postString;\r\n      if (!ParseUpdateCommandString2(updateString, actionSet, postString))\r\n        ThrowUserErrorException();\r\n      if(postString.IsEmpty())\r\n      {\r\n        if(options.UpdateArchiveItself)\r\n          options.Commands[0].ActionSet = actionSet;\r\n      }\r\n      else\r\n      {\r\n        if(MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)\r\n          ThrowUserErrorException();\r\n        CUpdateArchiveCommand uc;\r\n        UString archivePath = postString.Mid(1);\r\n        if (archivePath.IsEmpty())\r\n          ThrowUserErrorException();\r\n        uc.UserArchivePath = archivePath;\r\n        uc.ActionSet = actionSet;\r\n        options.Commands.Add(uc);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic const char kByteSymbol = 'B';\r\nstatic const char kKiloSymbol = 'K';\r\nstatic const char kMegaSymbol = 'M';\r\nstatic const char kGigaSymbol = 'G';\r\n\r\nstatic bool ParseComplexSize(const UString &src, UInt64 &result)\r\n{\r\n  UString s = src;\r\n  s.MakeUpper();\r\n\r\n  const wchar_t *start = s;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || s.Length() > numDigits + 1)\r\n    return false;\r\n  if (s.Length() == numDigits)\r\n  {\r\n    result = number;\r\n    return true;\r\n  }\r\n  int numBits;\r\n  switch (s[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      result = number;\r\n      return true;\r\n    case kKiloSymbol:\r\n      numBits = 10;\r\n      break;\r\n    case kMegaSymbol:\r\n      numBits = 20;\r\n      break;\r\n    case kGigaSymbol:\r\n      numBits = 30;\r\n      break;\r\n    default:\r\n      return false;\r\n  }\r\n  if (number >= ((UInt64)1 << (64 - numBits)))\r\n    return false;\r\n  result = number << numBits;\r\n  return true;\r\n}\r\n\r\nstatic void SetAddCommandOptions(\r\n    NCommandType::EEnum commandType, \r\n    const CParser &parser, \r\n    CUpdateOptions &options)\r\n{\r\n  NUpdateArchive::CActionSet defaultActionSet;\r\n  switch(commandType)\r\n  {\r\n    case NCommandType::kAdd: \r\n      defaultActionSet = NUpdateArchive::kAddActionSet;\r\n      break;\r\n    case NCommandType::kDelete: \r\n      defaultActionSet = NUpdateArchive::kDeleteActionSet;\r\n      break;\r\n    default: \r\n      defaultActionSet = NUpdateArchive::kUpdateActionSet;\r\n  }\r\n  \r\n  options.UpdateArchiveItself = true;\r\n  \r\n  options.Commands.Clear();\r\n  CUpdateArchiveCommand updateMainCommand;\r\n  updateMainCommand.ActionSet = defaultActionSet;\r\n  options.Commands.Add(updateMainCommand);\r\n  if(parser[NKey::kUpdate].ThereIs)\r\n    ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings, \r\n        defaultActionSet);\r\n  if(parser[NKey::kWorkingDir].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];\r\n    if (postString.IsEmpty())\r\n      NDirectory::MyGetTempPath(options.WorkingDir);\r\n    else\r\n      options.WorkingDir = postString;\r\n  }\r\n  options.SfxMode = parser[NKey::kSfx].ThereIs;\r\n  if (options.SfxMode)\r\n    options.SfxModule = parser[NKey::kSfx].PostStrings[0];\r\n\r\n  if (parser[NKey::kVolume].ThereIs)\r\n  {\r\n    const UStringVector &sv = parser[NKey::kVolume].PostStrings;\r\n    for (int i = 0; i < sv.Size(); i++)\r\n    {\r\n      UInt64 size;\r\n      if (!ParseComplexSize(sv[i], size))\r\n        ThrowException(\"Incorrect volume size\");\r\n      options.VolumesSizes.Add(size);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)\r\n{\r\n  if (parser[NKey::kProperty].ThereIs)\r\n  {\r\n    // options.MethodMode.Properties.Clear();\r\n    for(int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      CProperty property;\r\n      const UString &postString = parser[NKey::kProperty].PostStrings[i];\r\n      int index = postString.Find(L'=');\r\n      if (index < 0)\r\n        property.Name = postString;\r\n      else\r\n      {\r\n        property.Name = postString.Left(index);\r\n        property.Value = postString.Mid(index + 1);\r\n      }\r\n      properties.Add(property);\r\n    }\r\n  }\r\n}\r\n\r\nCArchiveCommandLineParser::CArchiveCommandLineParser(): \r\n  parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}\r\n\r\nvoid CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,\r\n    CArchiveCommandLineOptions &options)\r\n{\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    ThrowUserErrorException();\r\n  }\r\n\r\n  options.IsInTerminal = MY_IS_TERMINAL(stdin);\r\n  options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);\r\n  options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);\r\n  options.StdOutMode = parser[NKey::kStdOut].ThereIs;\r\n  options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;\r\n  options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs  || parser[NKey::kHelp3].ThereIs;\r\n\r\n  #ifdef _WIN32\r\n  options.LargePages = false;\r\n  if (parser[NKey::kLargePages].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kLargePages].PostStrings.Front();\r\n    if (postString.IsEmpty())\r\n      options.LargePages = true;\r\n  }\r\n  #endif\r\n}\r\n\r\nstruct CCodePagePair\r\n{\r\n  const wchar_t *Name;\r\n  UINT CodePage;\r\n};\r\n\r\nstatic CCodePagePair g_CodePagePairs[] = \r\n{\r\n  { L\"UTF-8\", CP_UTF8 },\r\n  { L\"WIN\",   CP_ACP },\r\n  { L\"DOS\",   CP_OEMCP }\r\n};\r\n\r\nstatic const int kNumCodePages = sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]);\r\n\r\nstatic bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)\r\n{\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(s, &end);\r\n  if (*end != 0)\r\n    return false;\r\n  if (number > (UInt32)0xFFFFFFFF)\r\n    return false;\r\n  v = (UInt32)number;\r\n  return true;\r\n}\r\n\r\nvoid CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)\r\n{\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n  int numNonSwitchStrings = nonSwitchStrings.Size();\r\n  if(numNonSwitchStrings < kMinNonSwitchWords)  \r\n    ThrowUserErrorException();\r\n\r\n  if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))\r\n    ThrowUserErrorException();\r\n\r\n  options.TechMode = parser[NKey::kTechMode].ThereIs;\r\n\r\n  if (parser[NKey::kCaseSensitive].ThereIs)\r\n    g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);\r\n\r\n  NRecursedType::EEnum recursedType;\r\n  if (parser[NKey::kRecursed].ThereIs)\r\n    recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);\r\n  else\r\n    recursedType = NRecursedType::kNonRecursed;\r\n\r\n  UINT codePage = CP_UTF8;\r\n  if (parser[NKey::kCharSet].ThereIs)\r\n  {\r\n    UString name = parser[NKey::kCharSet].PostStrings.Front();\r\n    name.MakeUpper();\r\n    int i;\r\n    for (i = 0; i < kNumCodePages; i++)\r\n    {\r\n      const CCodePagePair &pair = g_CodePagePairs[i];\r\n      if (name.Compare(pair.Name) == 0)\r\n      {\r\n        codePage = pair.CodePage;\r\n        break;\r\n      }\r\n    }\r\n    if (i >= kNumCodePages)\r\n      ThrowUserErrorException();\r\n  }\r\n\r\n  bool thereAreSwitchIncludes = false;\r\n  if (parser[NKey::kInclude].ThereIs)\r\n  {\r\n    thereAreSwitchIncludes = true;\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor, \r\n        parser[NKey::kInclude].PostStrings, true, recursedType, codePage);\r\n  }\r\n  if (parser[NKey::kExclude].ThereIs)\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor, \r\n        parser[NKey::kExclude].PostStrings, false, recursedType, codePage);\r\n \r\n  int curCommandIndex = kCommandIndex + 1;\r\n  bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs && \r\n      options.Command.CommandType != NCommandType::kBenchmark && \r\n      options.Command.CommandType != NCommandType::kInfo;\r\n  if (thereIsArchiveName)\r\n  {\r\n    if(curCommandIndex >= numNonSwitchStrings)  \r\n      ThrowUserErrorException();\r\n    options.ArchiveName = nonSwitchStrings[curCommandIndex++];\r\n  }\r\n\r\n  AddToCensorFromNonSwitchesStrings(\r\n      curCommandIndex, options.WildcardCensor, \r\n      nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);\r\n\r\n  options.YesToAll = parser[NKey::kYes].ThereIs;\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  options.PasswordEnabled = parser[NKey::kPassword].ThereIs;\r\n\r\n  if(options.PasswordEnabled)\r\n    options.Password = parser[NKey::kPassword].PostStrings[0];\r\n\r\n  options.StdInMode = parser[NKey::kStdIn].ThereIs;\r\n  options.ShowDialog = parser[NKey::kShowDialog].ThereIs;\r\n\r\n  if(isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if (options.StdInMode)\r\n      ThrowException(\"Reading archives from stdin is not implemented\");\r\n    if (!options.WildcardCensor.AllAreRelative())\r\n      ThrowException(\"Cannot use absolute pathnames for this command\");\r\n\r\n    NWildcard::CCensor archiveWildcardCensor;\r\n\r\n    if (parser[NKey::kArInclude].ThereIs)\r\n    {\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor, \r\n        parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);\r\n    }\r\n    if (parser[NKey::kArExclude].ThereIs)\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor, \r\n      parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);\r\n\r\n    if (thereIsArchiveName)\r\n      AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(archiveWildcardCensor);\r\n    #endif\r\n\r\n    archiveWildcardCensor.ExtendExclude();\r\n\r\n    CObjectVector<CDirItem> dirItems;\r\n    {\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);\r\n      if (res != S_OK || errorPaths.Size() > 0)\r\n        throw \"cannot find archive\";\r\n    }\r\n    UStringVector archivePaths;\r\n    int i;\r\n    for (i = 0; i < dirItems.Size(); i++)\r\n    {\r\n      const CDirItem &dirItem = dirItems[i];\r\n      if (!dirItem.IsDirectory())\r\n        archivePaths.Add(dirItem.FullPath);\r\n    }\r\n\r\n    if (archivePaths.Size() == 0)\r\n      throw \"there is no such archive\";\r\n\r\n    UStringVector archivePathsFull;\r\n\r\n    for (i = 0; i < archivePaths.Size(); i++)\r\n    {\r\n      UString fullPath;\r\n      NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);\r\n      archivePathsFull.Add(fullPath);\r\n    }\r\n    CIntVector indices;\r\n    SortFileNames(archivePathsFull, indices);\r\n    options.ArchivePathsSorted.Reserve(indices.Size());\r\n    options.ArchivePathsFullSorted.Reserve(indices.Size());\r\n    for (i = 0; i < indices.Size(); i++)\r\n    {\r\n      options.ArchivePathsSorted.Add(archivePaths[indices[i]]);\r\n      options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);\r\n    }\r\n\r\n    if (isExtractGroupCommand)\r\n    {\r\n      SetMethodOptions(parser, options.ExtractProperties); \r\n      if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)\r\n        throw kSameTerminalError;\r\n      if(parser[NKey::kOutputDir].ThereIs)\r\n      {\r\n        options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];\r\n        NFile::NName::NormalizeDirPathPrefix(options.OutputDir);\r\n      }\r\n\r\n      options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;\r\n      if(parser[NKey::kOverwrite].ThereIs)\r\n        options.OverwriteMode = \r\n            k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];\r\n      else if (options.YesToAll)\r\n        options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    CUpdateOptions &updateOptions = options.UpdateOptions;\r\n\r\n    if(parser[NKey::kArchiveType].ThereIs)\r\n      options.ArcType = parser[NKey::kArchiveType].PostStrings[0];\r\n\r\n    SetAddCommandOptions(options.Command.CommandType, parser, updateOptions); \r\n    \r\n    SetMethodOptions(parser, updateOptions.MethodMode.Properties); \r\n\r\n    if (parser[NKey::kShareForWrite].ThereIs)\r\n      updateOptions.OpenShareForWrite = true;\r\n\r\n    options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;\r\n\r\n    if (options.EnablePercents)\r\n    {\r\n      if ((options.StdOutMode && !options.IsStdErrTerminal) || \r\n         (!options.StdOutMode && !options.IsStdOutTerminal))  \r\n        options.EnablePercents = false;\r\n    }\r\n\r\n    updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;\r\n    if (updateOptions.EMailMode)\r\n    {\r\n      updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();\r\n      if (updateOptions.EMailAddress.Length() > 0)\r\n        if (updateOptions.EMailAddress[0] == L'.')\r\n        {\r\n          updateOptions.EMailRemoveAfter = true;\r\n          updateOptions.EMailAddress.Delete(0);\r\n        }\r\n    }\r\n\r\n    updateOptions.StdOutMode = options.StdOutMode;\r\n    updateOptions.StdInMode = options.StdInMode;\r\n\r\n    if (updateOptions.StdOutMode && updateOptions.EMailMode)\r\n      throw \"stdout mode and email mode cannot be combined\";\r\n    if (updateOptions.StdOutMode && options.IsStdOutTerminal)\r\n      throw kTerminalOutError;\r\n    if(updateOptions.StdInMode)\r\n      updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(options.WildcardCensor);\r\n    #endif\r\n  }\r\n  else if(options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    options.NumThreads = (UInt32)-1;\r\n    options.DictionarySize = (UInt32)-1;\r\n    options.NumIterations = 1;\r\n    if (curCommandIndex < numNonSwitchStrings)  \r\n    {\r\n      if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))\r\n        ThrowUserErrorException();\r\n    }\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      UString postString = parser[NKey::kProperty].PostStrings[i];\r\n      postString.MakeUpper();\r\n      if (postString.Length() < 2)\r\n        ThrowUserErrorException();\r\n      if (postString[0] == 'D')\r\n      {\r\n        int pos = 1;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        UInt32 logSize;\r\n        if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))\r\n          ThrowUserErrorException();\r\n        if (logSize > 31)\r\n          ThrowUserErrorException();\r\n        options.DictionarySize = 1 << logSize;\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == 'T' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        if (postString[pos] != 0)\r\n          if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))\r\n            ThrowUserErrorException();\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == '=' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] != 0)\r\n          options.Method = postString.Mid(2);\r\n      }\r\n      else\r\n        ThrowUserErrorException();\r\n    }\r\n  }\r\n  else if(options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n  }\r\n  else \r\n    ThrowUserErrorException();\r\n  options.WildcardCensor.ExtendExclude();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h",
    "content": "// ArchiveCommandLine.h\r\n\r\n#ifndef __ARCHIVECOMMANDLINE_H\r\n#define __ARCHIVECOMMANDLINE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#include \"Extract.h\"\r\n#include \"Update.h\"\r\n\r\nstruct CArchiveCommandLineException: public AString\r\n{\r\n  CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {}\r\n};\r\n\r\nnamespace NCommandType { enum EEnum\r\n{\r\n  kAdd = 0,\r\n  kUpdate,\r\n  kDelete,\r\n  kTest,\r\n  kExtract,\r\n  kFullExtract,\r\n  kList,\r\n  kBenchmark,\r\n  kInfo\r\n};}\r\n\r\nnamespace NRecursedType { enum EEnum\r\n{\r\n  kRecursed,\r\n  kWildCardOnlyRecursed,\r\n  kNonRecursed\r\n};}\r\n\r\nstruct CArchiveCommand\r\n{\r\n  NCommandType::EEnum CommandType;\r\n  bool IsFromExtractGroup() const;\r\n  bool IsFromUpdateGroup() const;\r\n  bool IsTestMode() const { return CommandType == NCommandType::kTest; }\r\n  NExtract::NPathMode::EEnum GetPathMode() const;\r\n};\r\n\r\nstruct CArchiveCommandLineOptions\r\n{\r\n  bool HelpMode;\r\n\r\n  #ifdef _WIN32\r\n  bool LargePages;\r\n  #endif\r\n\r\n  bool IsInTerminal;\r\n  bool IsStdOutTerminal;\r\n  bool IsStdErrTerminal;\r\n  bool StdInMode;\r\n  bool StdOutMode;\r\n  bool EnableHeaders;\r\n\r\n  bool YesToAll;\r\n  bool ShowDialog;\r\n  // NWildcard::CCensor ArchiveWildcardCensor;\r\n  NWildcard::CCensor WildcardCensor;\r\n\r\n  CArchiveCommand Command; \r\n  UString ArchiveName;\r\n\r\n  bool PasswordEnabled;\r\n  UString Password;\r\n\r\n  bool TechMode;\r\n  // Extract\r\n  bool AppendName;\r\n  UString OutputDir;\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n  UStringVector ArchivePathsSorted;\r\n  UStringVector ArchivePathsFullSorted;\r\n  CObjectVector<CProperty> ExtractProperties;\r\n\r\n  CUpdateOptions UpdateOptions;\r\n  UString ArcType;\r\n  bool EnablePercents;\r\n\r\n  // Benchmark \r\n  UInt32 NumIterations;\r\n  UInt32 NumThreads;\r\n  UInt32 DictionarySize;\r\n  UString Method;\r\n\r\n\r\n  CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};\r\n};\r\n\r\nclass CArchiveCommandLineParser\r\n{\r\n  NCommandLineParser::CParser parser;\r\npublic:\r\n  CArchiveCommandLineParser();\r\n  void Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options);\r\n  void Parse2(CArchiveCommandLineOptions &options);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp",
    "content": "// ArchiveExtractCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n#include \"OpenArchive.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic const wchar_t *kCantAutoRename = L\"ERROR: Can not create file with auto name\";\r\nstatic const wchar_t *kCantRenameFile = L\"ERROR: Can not rename existing file \";\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\n\r\nvoid CArchiveExtractCallback::Init(\r\n    IInArchive *archiveHandler,\r\n    IFolderArchiveExtractCallback *extractCallback2,\r\n    bool stdOutMode,\r\n    const UString &directoryPath, \r\n    const UStringVector &removePathParts,\r\n    const UString &itemDefaultName,\r\n    const FILETIME &utcLastWriteTimeDefault,\r\n    UInt32 attributesDefault,\r\n    UInt64 packSize)\r\n{\r\n  _stdOutMode = stdOutMode;\r\n  _numErrors = 0;\r\n  _unpTotal = 1;\r\n  _packTotal = packSize;\r\n\r\n  _extractCallback2 = extractCallback2;\r\n  _compressProgress.Release();\r\n  _extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);\r\n\r\n  LocalProgressSpec->Init(extractCallback2, true);\r\n  LocalProgressSpec->SendProgress = false;\r\n\r\n  _itemDefaultName = itemDefaultName;\r\n  _utcLastWriteTimeDefault = utcLastWriteTimeDefault;\r\n  _attributesDefault = attributesDefault;\r\n  _removePathParts = removePathParts;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  _unpTotal = size;\r\n  if (!_multiArchives && _extractCallback2)\r\n    return _extractCallback2->SetTotal(size);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  const UInt64 kMax = (UInt64)1 << 31;\r\n  while (v1 > kMax)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)\r\n{\r\n  NormalizeVals(packTotal, unpTotal);\r\n  NormalizeVals(unpCur, unpTotal);\r\n  if (unpTotal == 0)\r\n    unpTotal = 1;\r\n  return unpCur * packTotal / unpTotal;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_extractCallback2)\r\n    return S_OK;\r\n\r\n  if (_multiArchives)\r\n  {\r\n    if (completeValue != NULL)\r\n    {\r\n      UInt64 packCur = LocalProgressSpec->InSize + MyMultDiv64(*completeValue, _unpTotal, _packTotal);\r\n      return _extractCallback2->SetCompleted(&packCur);\r\n    }\r\n  }\r\n  return _extractCallback2->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return _localProgress->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\nvoid CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)\r\n{\r\n  fullPath = _directoryPath;\r\n  for(int i = 0; i < dirPathParts.Size(); i++)\r\n  {\r\n    if (i > 0)\r\n      fullPath += wchar_t(NFile::NName::kDirDelimiter);\r\n    fullPath += dirPathParts[i];\r\n    NFile::NDirectory::MyCreateDirectory(fullPath);\r\n  }\r\n}\r\n\r\nstatic UString MakePathNameFromParts(const UStringVector &parts)\r\n{\r\n  UString result;\r\n  for(int i = 0; i < parts.Size(); i++)\r\n  {\r\n    if(i != 0)\r\n      result += wchar_t(NFile::NName::kDirDelimiter);\r\n    result += parts[i];\r\n  }\r\n  return result;\r\n}\r\n\r\n\r\nHRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(_archiveHandler->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    filetime = prop.filetime;\r\n    filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  _encrypted = false;\r\n  _isSplit = false;\r\n  _curSize = 0;\r\n\r\n  UString fullPath;\r\n\r\n  RINOK(GetArchiveItemPath(_archiveHandler, index, _itemDefaultName, fullPath));\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDirectory));\r\n\r\n  _filePath = fullPath;\r\n\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPosition, &prop));\r\n    if (prop.vt != VT_EMPTY)\r\n    {\r\n      if (prop.vt != VT_UI8)\r\n        return E_FAIL;\r\n      _position = prop.uhVal.QuadPart;\r\n      _isSplit = true;\r\n    }\r\n  }\r\n    \r\n  RINOK(IsArchiveItemProp(_archiveHandler, index, kpidEncrypted, _encrypted));\r\n\r\n  bool newFileSizeDefined;\r\n  UInt64 newFileSize;\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    if (newFileSizeDefined)\r\n    {\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n      _curSize = newFileSize;\r\n    }\r\n  }\r\n\r\n  if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)\r\n  {\r\n    if (_stdOutMode)\r\n    {\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc = new CStdOutFileStream;\r\n      *outStream = outStreamLoc.Detach();\r\n      return S_OK;\r\n    }\r\n\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n        _processedFileInfo.Attributes = _attributesDefault;\r\n        _processedFileInfo.AttributesAreDefined = false;\r\n      }\r\n      else\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_FAIL;\r\n        _processedFileInfo.Attributes = prop.ulVal;\r\n        _processedFileInfo.AttributesAreDefined = true;\r\n      }\r\n    }\r\n\r\n    RINOK(GetTime(index, kpidCreationTime, _processedFileInfo.CreationTime,\r\n        _processedFileInfo.IsCreationTimeDefined));\r\n    RINOK(GetTime(index, kpidLastWriteTime, _processedFileInfo.LastWriteTime, \r\n        _processedFileInfo.IsLastWriteTimeDefined));\r\n    RINOK(GetTime(index, kpidLastAccessTime, _processedFileInfo.LastAccessTime,\r\n        _processedFileInfo.IsLastAccessTimeDefined));\r\n\r\n    bool isAnti = false;\r\n    RINOK(IsArchiveItemProp(_archiveHandler, index, kpidIsAnti, isAnti));\r\n\r\n    UStringVector pathParts; \r\n    SplitPathToParts(fullPath, pathParts);\r\n    \r\n    if(pathParts.IsEmpty())\r\n      return E_FAIL;\r\n    int numRemovePathParts = 0;\r\n    switch(_pathMode)\r\n    {\r\n      case NExtract::NPathMode::kFullPathnames:\r\n        break;\r\n      case NExtract::NPathMode::kCurrentPathnames:\r\n      {\r\n        numRemovePathParts = _removePathParts.Size();\r\n        if (pathParts.Size() <= numRemovePathParts)\r\n          return E_FAIL;\r\n        for (int i = 0; i < numRemovePathParts; i++)\r\n          if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0)\r\n            return E_FAIL;\r\n        break;\r\n      }\r\n      case NExtract::NPathMode::kNoPathnames:\r\n      {\r\n        numRemovePathParts = pathParts.Size() - 1;\r\n        break;\r\n      }\r\n    }\r\n    pathParts.Delete(0, numRemovePathParts);\r\n    MakeCorrectPath(pathParts);\r\n    UString processedPath = MakePathNameFromParts(pathParts);\r\n    if (!isAnti)\r\n    {\r\n      if (!_processedFileInfo.IsDirectory)\r\n      {\r\n        if (!pathParts.IsEmpty())\r\n          pathParts.DeleteBack();\r\n      }\r\n    \r\n      if (!pathParts.IsEmpty())\r\n      {\r\n        UString fullPathNew;\r\n        CreateComplexDirectory(pathParts, fullPathNew);\r\n        if (_processedFileInfo.IsDirectory)\r\n          NFile::NDirectory::SetDirTime(fullPathNew, \r\n            (WriteCreated && _processedFileInfo.IsCreationTimeDefined) ? &_processedFileInfo.CreationTime : NULL, \r\n            (WriteAccessed && _processedFileInfo.IsLastAccessTimeDefined) ? &_processedFileInfo.LastAccessTime : NULL, \r\n            (WriteModified && _processedFileInfo.IsLastWriteTimeDefined) ? &_processedFileInfo.LastWriteTime : &_utcLastWriteTimeDefault);\r\n      }\r\n    }\r\n\r\n\r\n    UString fullProcessedPath = _directoryPath + processedPath;\r\n\r\n    if(_processedFileInfo.IsDirectory)\r\n    {\r\n      _diskFilePath = fullProcessedPath;\r\n      if (isAnti)\r\n        NFile::NDirectory::MyRemoveDirectory(_diskFilePath);\r\n      return S_OK;\r\n    }\r\n\r\n    if (!_isSplit)\r\n    {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      switch(_overwriteMode)\r\n      {\r\n        case NExtract::NOverwriteMode::kSkipExisting:\r\n          return S_OK;\r\n        case NExtract::NOverwriteMode::kAskBefore:\r\n        {\r\n          Int32 overwiteResult;\r\n          RINOK(_extractCallback2->AskOverwrite(\r\n              fullProcessedPath, &fileInfo.LastWriteTime, &fileInfo.Size, fullPath, \r\n              _processedFileInfo.IsLastWriteTimeDefined ? &_processedFileInfo.LastWriteTime : NULL, \r\n              newFileSizeDefined ? &newFileSize : NULL, \r\n              &overwiteResult))\r\n\r\n          switch(overwiteResult)\r\n          {\r\n            case NOverwriteAnswer::kCancel:\r\n              return E_ABORT;\r\n            case NOverwriteAnswer::kNo:\r\n              return S_OK;\r\n            case NOverwriteAnswer::kNoToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kSkipExisting;\r\n              return S_OK;\r\n            case NOverwriteAnswer::kYesToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n              break;\r\n            case NOverwriteAnswer::kYes:\r\n              break;\r\n            case NOverwriteAnswer::kAutoRename:\r\n              _overwriteMode = NExtract::NOverwriteMode::kAutoRename;\r\n              break;\r\n            default:\r\n              return E_FAIL;\r\n          }\r\n        }\r\n      }\r\n      if (_overwriteMode == NExtract::NOverwriteMode::kAutoRename)\r\n      {\r\n        if (!AutoRenamePath(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantAutoRename) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)\r\n      {\r\n        UString existPath = fullProcessedPath;\r\n        if (!AutoRenamePath(existPath))\r\n        {\r\n          UString message = kCantAutoRename + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n        if(!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))\r\n        {\r\n          UString message = UString(kCantRenameFile) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else\r\n        if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantDeleteOutputFile) +  fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n          // return E_FAIL;\r\n        }\r\n    }\r\n    }\r\n    if (!isAnti)\r\n    {\r\n      _outFileStreamSpec = new COutFileStream;\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n      if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))\r\n      {\r\n        // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)\r\n        {\r\n          UString message = L\"can not open output file \" + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n        }\r\n      }\r\n      if (_isSplit)\r\n      {\r\n        RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));\r\n      }\r\n      _outFileStream = outStreamLoc;\r\n      *outStream = outStreamLoc.Detach();\r\n    }\r\n    _diskFilePath = fullProcessedPath;\r\n  }\r\n  else\r\n  {\r\n    *outStream = NULL;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  return _extractCallback2->PrepareOperation(_filePath, _processedFileInfo.IsDirectory, \r\n      askExtractMode, _isSplit ? &_position: 0);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n    case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n    case NArchive::NExtract::NOperationResult::kCRCError:\r\n    case NArchive::NExtract::NOperationResult::kDataError:\r\n      break;\r\n    default:\r\n      _outFileStream.Release();\r\n      return E_FAIL;\r\n  }\r\n  if (_outFileStream != NULL)\r\n  {\r\n    _outFileStreamSpec->SetTime(\r\n        (WriteCreated && _processedFileInfo.IsCreationTimeDefined) ? &_processedFileInfo.CreationTime : NULL, \r\n        (WriteAccessed && _processedFileInfo.IsLastAccessTimeDefined) ? &_processedFileInfo.LastAccessTime : NULL, \r\n        (WriteModified && _processedFileInfo.IsLastWriteTimeDefined) ? &_processedFileInfo.LastWriteTime : &_utcLastWriteTimeDefault);\r\n    _curSize = _outFileStreamSpec->ProcessedSize;\r\n    RINOK(_outFileStreamSpec->Close());\r\n    _outFileStream.Release();\r\n  }\r\n  UnpackSize += _curSize;\r\n  if (_processedFileInfo.IsDirectory)\r\n    NumFolders++;\r\n  else\r\n    NumFiles++;\r\n\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CArchiveExtractCallback::GetInStream(\r\n    const wchar_t *name, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  CInFileStream *inFile = new CInFileStream;\r\n  CMyComPtr<ISequentialInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(_srcDirectoryPrefix + name))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_cryptoGetTextPassword)\r\n  {\r\n    RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword, \r\n        &_cryptoGetTextPassword));\r\n  }\r\n  return _cryptoGetTextPassword->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h",
    "content": "// ArchiveExtractCallback.h\r\n\r\n#ifndef __ARCHIVEEXTRACTCALLBACK_H\r\n#define __ARCHIVEEXTRACTCALLBACK_H\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"IFileExtractCallback.h\"\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"ExtractMode.h\"\r\n\r\nclass CArchiveExtractCallback: \r\n  public IArchiveExtractCallback,\r\n  // public IArchiveVolumeExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(ICryptoGetTextPassword, ICompressProgressInfo)\r\n  // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IExtractCallBack\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // IArchiveVolumeExtractCallback\r\n  // STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;\r\n  CMyComPtr<ICompressProgressInfo> _compressProgress;\r\n  CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;\r\n  UString _directoryPath;\r\n  NExtract::NPathMode::EEnum _pathMode;\r\n  NExtract::NOverwriteMode::EEnum _overwriteMode;\r\n\r\n  UString _filePath;\r\n  UInt64 _position;\r\n  bool _isSplit;\r\n\r\n  UString _diskFilePath;\r\n\r\n  bool _extractMode;\r\n\r\n  bool WriteModified;\r\n  bool WriteCreated;\r\n  bool WriteAccessed;\r\n\r\n  bool _encrypted;\r\n\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME CreationTime;\r\n    FILETIME LastWriteTime;\r\n    FILETIME LastAccessTime;\r\n    UInt32 Attributes;\r\n  \r\n    bool IsCreationTimeDefined;\r\n    bool IsLastWriteTimeDefined;\r\n    bool IsLastAccessTimeDefined;\r\n\r\n    bool IsDirectory;\r\n    bool AttributesAreDefined;\r\n  } _processedFileInfo;\r\n\r\n  UInt64 _curSize;\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n  UStringVector _removePathParts;\r\n\r\n  UString _itemDefaultName;\r\n  FILETIME _utcLastWriteTimeDefault;\r\n  UInt32 _attributesDefault;\r\n  bool _stdOutMode;\r\n\r\n  void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);\r\n  HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);\r\npublic:\r\n  CArchiveExtractCallback():\r\n      WriteModified(true),\r\n      WriteCreated(false),\r\n      WriteAccessed(false),\r\n      _multiArchives(false)\r\n  {\r\n    LocalProgressSpec = new CLocalProgress();\r\n    _localProgress = LocalProgressSpec;\r\n  }\r\n\r\n  CLocalProgress *LocalProgressSpec;\r\n  CMyComPtr<ICompressProgressInfo> _localProgress;\r\n  UInt64 _packTotal;\r\n  UInt64 _unpTotal;\r\n\r\n  bool _multiArchives;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  UInt64 UnpackSize;\r\n  \r\n  void InitForMulti(bool multiArchives, \r\n      NExtract::NPathMode::EEnum pathMode,\r\n      NExtract::NOverwriteMode::EEnum overwriteMode) \r\n  { \r\n    _multiArchives = multiArchives; NumFolders = NumFiles = UnpackSize = 0; \r\n    _pathMode = pathMode;\r\n    _overwriteMode = overwriteMode;\r\n  }\r\n\r\n  void Init(\r\n      IInArchive *archiveHandler, \r\n      IFolderArchiveExtractCallback *extractCallback2,\r\n      bool stdOutMode,\r\n      const UString &directoryPath,\r\n      const UStringVector &removePathParts,\r\n      const UString &itemDefaultName,\r\n      const FILETIME &utcLastWriteTimeDefault, \r\n      UInt32 attributesDefault,\r\n      UInt64 packSize);\r\n\r\n  UInt64 _numErrors;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ArchiveName.cpp",
    "content": "// ArchiveName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)\r\n{\r\n  UString resultName = L\"Archive\";\r\n  if (fromPrev)\r\n  {\r\n    UString dirPrefix;\r\n    if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))\r\n    {\r\n      if (dirPrefix.Length() > 0)\r\n        if (dirPrefix[dirPrefix.Length() - 1] == '\\\\')\r\n        {\r\n          dirPrefix.Delete(dirPrefix.Length() - 1);\r\n          NFile::NFind::CFileInfoW fileInfo;\r\n          if (NFile::NFind::FindFile(dirPrefix, fileInfo))\r\n            resultName = fileInfo.Name;\r\n        }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if (!NFile::NFind::FindFile(srcName, fileInfo))\r\n      return resultName;\r\n    resultName = fileInfo.Name;\r\n    if (!fileInfo.IsDirectory() && !keepName)\r\n    {\r\n      int dotPos = resultName.ReverseFind('.');\r\n      if (dotPos > 0)\r\n      {\r\n        UString archiveName2 = resultName.Left(dotPos);\r\n        if (archiveName2.ReverseFind('.') < 0)\r\n          resultName = archiveName2;\r\n      }\r\n    }\r\n  }\r\n  return resultName;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ArchiveName.h",
    "content": "// ArchiveName.h\r\n\r\n#ifndef __ARCHIVENAME_H\r\n#define __ARCHIVENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp",
    "content": "// ArchiveOpenCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n  \r\nSTDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant propVariant;\r\n  if (_subArchiveMode)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidName:\r\n        propVariant = _subArchiveName;\r\n        break;\r\n    }\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  switch(propID)\r\n  {\r\n    case kpidName:\r\n      propVariant = _fileInfo.Name;\r\n      break;\r\n    case kpidIsFolder:\r\n      propVariant = _fileInfo.IsDirectory();\r\n      break;\r\n    case kpidSize:\r\n      propVariant = _fileInfo.Size;\r\n      break;\r\n    case kpidAttributes:\r\n      propVariant = (UInt32)_fileInfo.Attributes;\r\n      break;\r\n    case kpidLastAccessTime:\r\n      propVariant = _fileInfo.LastAccessTime;\r\n      break;\r\n    case kpidCreationTime:\r\n      propVariant = _fileInfo.CreationTime;\r\n      break;\r\n    case kpidLastWriteTime:\r\n      propVariant = _fileInfo.LastWriteTime;\r\n      break;\r\n    }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nint COpenCallbackImp::FindName(const UString &name)\r\n{\r\n  for (int i = 0; i < FileNames.Size(); i++)\r\n    if (name.CompareNoCase(FileNames[i]) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstruct CInFileStreamVol: public CInFileStream\r\n{\r\n  UString Name;\r\n  COpenCallbackImp *OpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;\r\n  ~CInFileStreamVol()\r\n  {\r\n    int index = OpenCallbackImp->FindName(Name);\r\n    if (index >= 0)\r\n      OpenCallbackImp->FileNames.Delete(index);\r\n  }\r\n};\r\n\r\nSTDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (_subArchiveMode)\r\n    return S_FALSE;\r\n  if (Callback)\r\n  {\r\n    RINOK(Callback->CheckBreak());\r\n  }\r\n  *inStream = NULL;\r\n  UString fullPath = _folderPrefix + name;\r\n  if (!NFile::NFind::FindFile(fullPath, _fileInfo))\r\n    return S_FALSE;\r\n  if (_fileInfo.IsDirectory())\r\n    return S_FALSE;\r\n  CInFileStreamVol *inFile = new CInFileStreamVol;\r\n  CMyComPtr<IInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(fullPath))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  inFile->Name = name;\r\n  inFile->OpenCallbackImp = this;\r\n  inFile->OpenCallbackRef = this;\r\n  FileNames.Add(name);\r\n  TotalSize += _fileInfo.Size;\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!Callback)\r\n    return E_NOTIMPL;\r\n  return Callback->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n#endif\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h",
    "content": "// ArchiveOpenCallback.h\r\n\r\n#ifndef __ARCHIVE_OPEN_CALLBACK_H\r\n#define __ARCHIVE_OPEN_CALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#ifndef _NO_CRYPTO\r\n#include \"../../IPassword.h\"\r\n#endif  \r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct IOpenCallbackUI\r\n{\r\n  virtual HRESULT CheckBreak() = 0;\r\n  virtual HRESULT SetTotal(const UInt64 *files, const UInt64 *bytes) = 0;\r\n  virtual HRESULT SetCompleted(const UInt64 *files, const UInt64 *bytes) = 0;\r\n  #ifndef _NO_CRYPTO\r\n  virtual HRESULT CryptoGetTextPassword(BSTR *password) = 0;\r\n  virtual HRESULT GetPasswordIfAny(UString &password) = 0;\r\n  virtual bool WasPasswordAsked() = 0;\r\n  virtual void ClearPasswordWasAskedFlag() = 0;\r\n  #endif  \r\n};\r\n\r\nclass COpenCallbackImp: \r\n  public IArchiveOpenCallback,\r\n  public IArchiveOpenVolumeCallback,\r\n  public IArchiveOpenSetSubArchiveName,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif  \r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifndef _NO_CRYPTO\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveOpenVolumeCallback, \r\n      ICryptoGetTextPassword,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      IArchiveOpenVolumeCallback, \r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #endif\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  // IArchiveOpenVolumeCallback\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream);\r\n\r\n  #ifndef _NO_CRYPTO\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n  #endif\r\n\r\n  STDMETHOD(SetSubArchiveName(const wchar_t *name))\r\n  {\r\n    _subArchiveMode = true;\r\n    _subArchiveName = name;\r\n    return  S_OK;\r\n  }\r\n\r\nprivate:\r\n  UString _folderPrefix;\r\n  NWindows::NFile::NFind::CFileInfoW _fileInfo;\r\n  bool _subArchiveMode;\r\n  UString _subArchiveName;\r\npublic:\r\n  UStringVector FileNames;\r\n  IOpenCallbackUI *Callback;\r\n  UInt64 TotalSize;\r\n\r\n  COpenCallbackImp(): Callback(NULL) {}\r\n  void Init(const UString &folderPrefix,  const UString &fileName)\r\n  {\r\n    _folderPrefix = folderPrefix;\r\n    if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))\r\n      throw 1;\r\n    FileNames.Clear();\r\n    _subArchiveMode = false;\r\n    TotalSize = 0;\r\n  }\r\n  int FindName(const UString &name);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/DefaultName.cpp",
    "content": "// DefaultName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nUString GetDefaultName2(const UString &fileName, \r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  int extLength = extension.Length();\r\n  int fileNameLength = fileName.Length();\r\n  if (fileNameLength > extLength + 1)\r\n  {\r\n    int dotPos = fileNameLength - (extLength + 1);\r\n    if (fileName[dotPos] == '.')\r\n      if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)\r\n        return fileName.Left(dotPos) + addSubExtension;\r\n  }\r\n  int dotPos = fileName.ReverseFind(L'.');\r\n  if (dotPos > 0)\r\n    return fileName.Left(dotPos) + addSubExtension;\r\n  return kEmptyFileAlias;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/DefaultName.h",
    "content": "// DefaultName.h\r\n\r\n#ifndef __DEFAULTNAME_H\r\n#define __DEFAULTNAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString GetDefaultName2(const UString &fileName, \r\n    const UString &extension, const UString &addSubExtension);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/DirItem.h",
    "content": "// DirItem.h\r\n\r\n#ifndef __DIR_ITEM_H\r\n#define __DIR_ITEM_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nstruct CDirItem\r\n{ \r\n  UInt32 Attributes;\r\n  FILETIME CreationTime;\r\n  FILETIME LastAccessTime;\r\n  FILETIME LastWriteTime;\r\n  UInt64 Size;\r\n  UString Name;\r\n  UString FullPath;\r\n  bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nstruct CArchiveItem\r\n{ \r\n  bool IsDirectory;\r\n  // DWORD Attributes;\r\n  // NWindows::NCOM::CPropVariant LastWriteTime;\r\n  FILETIME LastWriteTime;\r\n  bool SizeIsDefined;\r\n  UInt64 Size;\r\n  UString Name;\r\n  bool Censored;\r\n  int IndexInServer;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp",
    "content": "// EnumDirItems.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nvoid AddDirFileInfo(\r\n    const UString &prefix,        // prefix for logical path\r\n    const UString &fullPathName,  // path on disk: can be relative to some basePrefix\r\n    const NFind::CFileInfoW &fileInfo, \r\n    CObjectVector<CDirItem> &dirItems)\r\n{\r\n  CDirItem item;\r\n  item.Attributes = fileInfo.Attributes;\r\n  item.Size = fileInfo.Size;\r\n  item.CreationTime = fileInfo.CreationTime;\r\n  item.LastAccessTime = fileInfo.LastAccessTime;\r\n  item.LastWriteTime = fileInfo.LastWriteTime;\r\n  item.Name = prefix + fileInfo.Name;\r\n  item.FullPath = fullPathName;\r\n  dirItems.Add(item);\r\n}\r\n\r\nstatic void EnumerateDirectory(\r\n    const UString &baseFolderPrefix,  // base (disk) prefix for scanning  \r\n    const UString &directory,         // additional disk prefix starting from baseFolderPrefix\r\n    const UString &prefix,            // logical prefix\r\n    CObjectVector<CDirItem> &dirItems,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  NFind::CEnumeratorW enumerator(baseFolderPrefix + directory + wchar_t(kAnyStringWildcard));\r\n  for (;;)\r\n  { \r\n    NFind::CFileInfoW fileInfo;\r\n    bool found;\r\n    if (!enumerator.Next(fileInfo, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(baseFolderPrefix + directory);\r\n      return;\r\n    }\r\n    if (!found)\r\n      break;\r\n    AddDirFileInfo(prefix, directory + fileInfo.Name, fileInfo, dirItems);\r\n    if (fileInfo.IsDirectory())\r\n    {\r\n      EnumerateDirectory(baseFolderPrefix, directory + fileInfo.Name + wchar_t(kDirDelimiter), \r\n          prefix + fileInfo.Name + wchar_t(kDirDelimiter), dirItems, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nvoid EnumerateDirItems(\r\n    const UString &baseFolderPrefix,   // base (disk) prefix for scanning  \r\n    const UStringVector &fileNames,    // names relative to baseFolderPrefix\r\n    const UString &archiveNamePrefix, \r\n    CObjectVector<CDirItem> &dirItems,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for(int i = 0; i < fileNames.Size(); i++)\r\n  {\r\n    const UString &fileName = fileNames[i];\r\n    NFind::CFileInfoW fileInfo;\r\n    if (!NFind::FindFile(baseFolderPrefix + fileName, fileInfo))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(baseFolderPrefix + fileName);\r\n      continue;\r\n    }\r\n    AddDirFileInfo(archiveNamePrefix, fileName, fileInfo, dirItems);\r\n    if (fileInfo.IsDirectory())\r\n    {\r\n      EnumerateDirectory(baseFolderPrefix, fileName + wchar_t(kDirDelimiter), \r\n          archiveNamePrefix + fileInfo.Name +  wchar_t(kDirDelimiter), \r\n          dirItems, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nstatic HRESULT EnumerateDirItems(\r\n    const NWildcard::CCensorNode &curNode, \r\n    const UString &diskPrefix,        // full disk path prefix \r\n    const UString &archivePrefix,     // prefix from root\r\n    const UStringVector &addArchivePrefix,  // prefix from curNode\r\n    CObjectVector<CDirItem> &dirItems, \r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  if (!enterToSubFolders)\r\n    if (curNode.NeedCheckSubDirs())\r\n      enterToSubFolders = true;\r\n  if (callback)\r\n    RINOK(callback->CheckBreak());\r\n\r\n  // try direct_names case at first\r\n  if (addArchivePrefix.IsEmpty() && !enterToSubFolders)\r\n  {\r\n    // check that all names are direct\r\n    int i;\r\n    for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n    {\r\n      const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n      if (item.Recursive || item.PathParts.Size() != 1)\r\n        break;\r\n      const UString &name = item.PathParts.Front();\r\n      if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n        break;\r\n    }\r\n    if (i == curNode.IncludeItems.Size())\r\n    {\r\n      // all names are direct (no wildcards)\r\n      // so we don't need file_system's dir enumerator\r\n      CRecordVector<bool> needEnterVector;\r\n      for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n      {\r\n        const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n        const UString &name = item.PathParts.Front();\r\n        const UString fullPath = diskPrefix + name;\r\n        NFind::CFileInfoW fileInfo;\r\n        if (!NFind::FindFile(fullPath, fileInfo))\r\n        {\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        bool isDir = fileInfo.IsDirectory();\r\n        if (isDir && !item.ForDir || !isDir && !item.ForFile)\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        const UString realName = fileInfo.Name;\r\n        const UString realDiskPath = diskPrefix + realName;\r\n        {\r\n          UStringVector pathParts;\r\n          pathParts.Add(fileInfo.Name);\r\n          if (curNode.CheckPathToRoot(false, pathParts, !isDir))\r\n            continue;\r\n        }\r\n        AddDirFileInfo(archivePrefix, realDiskPath, fileInfo, dirItems);\r\n        if (!isDir)\r\n          continue;\r\n        \r\n        UStringVector addArchivePrefixNew;\r\n        const NWildcard::CCensorNode *nextNode = 0;\r\n        int index = curNode.FindSubNode(name);\r\n        if (index >= 0)\r\n        {\r\n          for (int t = needEnterVector.Size(); t <= index; t++)\r\n            needEnterVector.Add(true);\r\n          needEnterVector[index] = false;\r\n          nextNode = &curNode.SubNodes[index];\r\n        }\r\n        else\r\n        {\r\n          nextNode = &curNode;\r\n          addArchivePrefixNew.Add(name); // don't change it to realName. It's for shortnames support\r\n        }\r\n        RINOK(EnumerateDirItems(*nextNode,   \r\n            realDiskPath + wchar_t(kDirDelimiter), \r\n            archivePrefix + realName + wchar_t(kDirDelimiter), \r\n            addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes));\r\n      }\r\n      for (i = 0; i < curNode.SubNodes.Size(); i++)\r\n      {\r\n        if (i < needEnterVector.Size())\r\n          if (!needEnterVector[i])\r\n            continue;\r\n        const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];\r\n        const UString fullPath = diskPrefix + nextNode.Name;\r\n        NFind::CFileInfoW fileInfo;\r\n        if (!NFind::FindFile(fullPath, fileInfo))\r\n        {\r\n          if (!nextNode.AreThereIncludeItems())\r\n            continue;\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        if (!fileInfo.IsDirectory())\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        RINOK(EnumerateDirItems(nextNode, \r\n            diskPrefix + fileInfo.Name + wchar_t(kDirDelimiter), \r\n            archivePrefix + fileInfo.Name + wchar_t(kDirDelimiter), \r\n            UStringVector(), dirItems, false, callback, errorPaths, errorCodes));\r\n      }\r\n      return S_OK;\r\n    }\r\n  }\r\n\r\n\r\n  NFind::CEnumeratorW enumerator(diskPrefix + wchar_t(kAnyStringWildcard));\r\n  for (;;)\r\n  {\r\n    NFind::CFileInfoW fileInfo;\r\n    bool found;\r\n    if (!enumerator.Next(fileInfo, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(diskPrefix);\r\n      break;\r\n    }\r\n    if (!found)\r\n      break;\r\n\r\n    if (callback)\r\n      RINOK(callback->CheckBreak());\r\n    const UString &name = fileInfo.Name;\r\n    bool enterToSubFolders2 = enterToSubFolders;\r\n    UStringVector addArchivePrefixNew = addArchivePrefix;\r\n    addArchivePrefixNew.Add(name);\r\n    {\r\n      UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);\r\n      if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fileInfo.IsDirectory()))\r\n        continue;\r\n    }\r\n    if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fileInfo.IsDirectory()))\r\n    {\r\n      AddDirFileInfo(archivePrefix, diskPrefix + name, fileInfo, dirItems);\r\n      if (fileInfo.IsDirectory())\r\n        enterToSubFolders2 = true;\r\n    }\r\n    if (!fileInfo.IsDirectory())\r\n      continue;\r\n\r\n    const NWildcard::CCensorNode *nextNode = 0;\r\n    if (addArchivePrefix.IsEmpty())\r\n    {\r\n      int index = curNode.FindSubNode(name);\r\n      if (index >= 0)\r\n        nextNode = &curNode.SubNodes[index];\r\n    }\r\n    if (!enterToSubFolders2 && nextNode == 0)\r\n      continue;\r\n\r\n    addArchivePrefixNew = addArchivePrefix;\r\n    if (nextNode == 0)\r\n    {\r\n      nextNode = &curNode;\r\n      addArchivePrefixNew.Add(name);\r\n    }\r\n    RINOK(EnumerateDirItems(*nextNode,   \r\n        diskPrefix + name + wchar_t(kDirDelimiter), \r\n        archivePrefix + name + wchar_t(kDirDelimiter), \r\n        addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor, \r\n    CObjectVector<CDirItem> &dirItems, \r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    const NWildcard::CPair &pair = censor.Pairs[i];\r\n    RINOK(EnumerateDirItems(pair.Head, pair.Prefix, L\"\", UStringVector(), dirItems, false, \r\n        callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/EnumDirItems.h",
    "content": "// EnumDirItems.h\r\n\r\n#ifndef __ENUM_DIR_ITEMS_H\r\n#define __ENUM_DIR_ITEMS_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"DirItem.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n\r\nvoid AddDirFileInfo(\r\n    const UString &prefix, \r\n    const UString &fullPathName,\r\n    const NWindows::NFile::NFind::CFileInfoW &fileInfo, \r\n    CObjectVector<CDirItem> &dirItems);\r\n\r\n\r\nvoid EnumerateDirItems(\r\n    const UString &baseFolderPrefix,\r\n    const UStringVector &fileNames,\r\n    const UString &archiveNamePrefix, \r\n    CObjectVector<CDirItem> &dirItems, \r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\nstruct IEnumDirItemCallback\r\n{\r\n  virtual HRESULT CheckBreak() { return  S_OK; }\r\n};\r\n\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor, \r\n    CObjectVector<CDirItem> &dirItems, \r\n    IEnumDirItemCallback *callback, \r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ExitCode.h",
    "content": "// ExitCode.h\r\n\r\n#ifndef __EXIT_CODE_H\r\n#define __EXIT_CODE_H\r\n\r\nnamespace NExitCode {\r\n\r\nenum EEnum {\r\n\r\n  kSuccess       = 0,     // Successful operation\r\n  kWarning       = 1,     // Non fatal error(s) occurred\r\n  kFatalError    = 2,     // A fatal error occurred\r\n  // kCRCError      = 3,     // A CRC error occurred when unpacking     \r\n  // kLockedArchive = 4,     // Attempt to modify an archive previously locked\r\n  // kWriteError    = 5,     // Write to disk error\r\n  // kOpenError     = 6,     // Open file error\r\n  kUserError     = 7,     // Command line option error\r\n  kMemoryError   = 8,     // Not enough memory for operation\r\n  // kCreateFileError = 9,     // Create file error\r\n  \r\n  kUserBreak     = 255   // User stopped the process\r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/Extract.cpp",
    "content": "// Extract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Extract.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n#include \"SetProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT DecompressArchive(\r\n    IInArchive *archive,\r\n    UInt64 packSize,\r\n    const UString &defaultName,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IExtractCallbackUI *callback,\r\n    CArchiveExtractCallback *extractCallbackSpec,\r\n    UString &errorMessage)\r\n{\r\n  CRecordVector<UInt32> realIndices;\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UString filePath;\r\n    RINOK(GetArchiveItemPath(archive, i, options.DefaultItemName, filePath));\r\n    bool isFolder;\r\n    RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n    if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n      continue;\r\n    realIndices.Add(i);\r\n  }\r\n  if (realIndices.Size() == 0)\r\n  {\r\n    callback->ThereAreNoFiles();\r\n    return S_OK;\r\n  }\r\n\r\n  UStringVector removePathParts;\r\n\r\n  UString outDir = options.OutputDir;\r\n  outDir.Replace(L\"*\", defaultName);\r\n  if(!outDir.IsEmpty())\r\n    if(!NFile::NDirectory::CreateComplexDirectory(outDir))\r\n    {\r\n      HRESULT res = ::GetLastError();\r\n      if (res == S_OK)\r\n        res = E_FAIL;\r\n      errorMessage = ((UString)L\"Can not create output directory \") + outDir;\r\n      return res;\r\n    }\r\n\r\n  extractCallbackSpec->Init(\r\n      archive, \r\n      callback,\r\n      options.StdOutMode,\r\n      outDir, \r\n      removePathParts, \r\n      options.DefaultItemName, \r\n      options.ArchiveFileInfo.LastWriteTime,\r\n      options.ArchiveFileInfo.Attributes,\r\n      packSize);\r\n\r\n  #ifdef COMPRESS_MT\r\n  RINOK(SetProperties(archive, options.Properties));\r\n  #endif\r\n\r\n  HRESULT result = archive->Extract(&realIndices.Front(), \r\n    realIndices.Size(), options.TestMode? 1: 0, extractCallbackSpec);\r\n\r\n  return callback->ExtractResult(result);\r\n}\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,    \r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &optionsSpec,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback, \r\n    UString &errorMessage, \r\n    CDecompressStat &stat)\r\n{\r\n  stat.Clear();\r\n  CExtractOptions options = optionsSpec;\r\n  int i;\r\n  UInt64 totalPackSize = 0;\r\n  CRecordVector<UInt64> archiveSizes;\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW archiveFileInfo;\r\n    if (!NFile::NFind::FindFile(archivePath, archiveFileInfo))\r\n      throw \"there is no such archive\";\r\n    if (archiveFileInfo.IsDirectory())\r\n      throw \"can't decompress folder\";\r\n    archiveSizes.Add(archiveFileInfo.Size);\r\n    totalPackSize += archiveFileInfo.Size;\r\n  }\r\n  CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n  CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);\r\n  bool multi = (archivePaths.Size() > 1);\r\n  extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);\r\n  if (multi)\r\n  {\r\n    RINOK(extractCallback->SetTotal(totalPackSize));  \r\n  }\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW archiveFileInfo;\r\n    if (!NFile::NFind::FindFile(archivePath, archiveFileInfo))\r\n      throw \"there is no such archive\";\r\n\r\n    if (archiveFileInfo.IsDirectory())\r\n      throw \"there is no such archive\";\r\n\r\n    options.ArchiveFileInfo = archiveFileInfo;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    openCallback->ClearPasswordWasAskedFlag();\r\n    #endif\r\n\r\n    RINOK(extractCallback->BeforeOpen(archivePath));\r\n    CArchiveLink archiveLink;\r\n    HRESULT result = MyOpenArchive(codecs, archivePath, archiveLink, openCallback);\r\n\r\n    bool crypted = false;\r\n    #ifndef _NO_CRYPTO\r\n    crypted = openCallback->WasPasswordAsked();\r\n    #endif\r\n\r\n    RINOK(extractCallback->OpenResult(archivePath, result, crypted));\r\n    if (result != S_OK)\r\n      continue;\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n        totalPackSize -= archiveSizes[index];\r\n        archiveSizes.Delete(index);\r\n      }\r\n    }\r\n    if (archiveLink.VolumePaths.Size() != 0)\r\n    {\r\n      totalPackSize += archiveLink.VolumesSize;\r\n      RINOK(extractCallback->SetTotal(totalPackSize));  \r\n    }\r\n\r\n    #ifndef _NO_CRYPTO\r\n    UString password;\r\n    RINOK(openCallback->GetPasswordIfAny(password));\r\n    if (!password.IsEmpty())\r\n    {\r\n      RINOK(extractCallback->SetPassword(password));\r\n    }\r\n    #endif\r\n\r\n    options.DefaultItemName = archiveLink.GetDefaultItemName();\r\n    RINOK(DecompressArchive(\r\n        archiveLink.GetArchive(), \r\n        archiveFileInfo.Size + archiveLink.VolumesSize,\r\n        archiveLink.GetDefaultItemName(),\r\n        wildcardCensor, options, extractCallback, extractCallbackSpec, errorMessage));\r\n    extractCallbackSpec->LocalProgressSpec->InSize += archiveFileInfo.Size + \r\n        archiveLink.VolumesSize;\r\n    extractCallbackSpec->LocalProgressSpec->OutSize = extractCallbackSpec->UnpackSize;\r\n    if (!errorMessage.IsEmpty())\r\n      return E_FAIL;\r\n  }\r\n  stat.NumFolders = extractCallbackSpec->NumFolders;\r\n  stat.NumFiles = extractCallbackSpec->NumFiles;\r\n  stat.UnpackSize = extractCallbackSpec->UnpackSize;\r\n  stat.NumArchives = archivePaths.Size();\r\n  stat.PackSize = extractCallbackSpec->LocalProgressSpec->InSize;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/Extract.h",
    "content": "// Extract.h\r\n\r\n#ifndef __EXTRACT_H\r\n#define __EXTRACT_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"ExtractMode.h\"\r\n#include \"Property.h\"\r\n\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nclass CExtractOptions\r\n{\r\npublic:\r\n  bool StdOutMode;\r\n  bool TestMode;\r\n  NExtract::NPathMode::EEnum PathMode;\r\n\r\n  UString OutputDir;\r\n  bool YesToAll;\r\n  UString DefaultItemName;\r\n  NWindows::NFile::NFind::CFileInfoW ArchiveFileInfo;\r\n  \r\n  // bool ShowDialog;\r\n  // bool PasswordEnabled;\r\n  // UString Password;\r\n  #ifdef COMPRESS_MT\r\n  CObjectVector<CProperty> Properties;\r\n  #endif\r\n\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  CCodecs *Codecs;\r\n  #endif\r\n\r\n  CExtractOptions(): \r\n      StdOutMode(false), \r\n      YesToAll(false), \r\n      TestMode(false),\r\n      PathMode(NExtract::NPathMode::kFullPathnames),\r\n      OverwriteMode(NExtract::NOverwriteMode::kAskBefore)\r\n      {}\r\n\r\n  /*\r\n    bool FullPathMode() const { return (ExtractMode == NExtractMode::kTest) || \r\n    (ExtractMode == NExtractMode::kFullPath); }\r\n  */\r\n};\r\n\r\nstruct CDecompressStat\r\n{\r\n  UInt64 NumArchives;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  void Clear() { NumArchives = PackSize = UnpackSize = NumFolders = NumFiles = 0; }\r\n};\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage, \r\n    CDecompressStat &stat);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ExtractMode.h",
    "content": "// ExtractMode.h\r\n\r\n#ifndef __EXTRACT_MODE_H\r\n#define __EXTRACT_MODE_H\r\n\r\nnamespace NExtract {\r\n  \r\n  namespace NPathMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kFullPathnames,\r\n      kCurrentPathnames,\r\n      kNoPathnames\r\n    };\r\n  }\r\n  \r\n  namespace NOverwriteMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kAskBefore,\r\n      kWithoutPrompt,\r\n      kSkipExisting,\r\n      kAutoRename,\r\n      kAutoRenameExisting\r\n    };\r\n  }\r\n}  \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp",
    "content": "// ExtractingFilePath.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ExtractingFilePath.h\"\r\n\r\nstatic UString ReplaceIncorrectChars(const UString &s)\r\n{\r\n  #ifdef _WIN32\r\n  UString res;\r\n  for (int i = 0; i < s.Length(); i++)\r\n  {\r\n    wchar_t c = s[i];\r\n    if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>'  || c == '|' || c == ':' || c == '\"')\r\n      c = '_';\r\n    res += c;\r\n  }\r\n  return res;\r\n  #else\r\n  return s;\r\n  #endif\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t *g_ReservedNames[] =\r\n{\r\n  L\"CON\", L\"PRN\", L\"AUX\", L\"NUL\"\r\n};\r\n\r\nstatic bool CheckTail(const UString &name, int len)\r\n{\r\n  int dotPos = name.Find(L'.');\r\n  if (dotPos < 0)\r\n    dotPos = name.Length();\r\n  UString s = name.Left(dotPos);\r\n  s.TrimRight();\r\n  return (s.Length() != len);\r\n}\r\n\r\nstatic bool CheckNameNum(const UString &name, const wchar_t *reservedName)\r\n{\r\n  int len = MyStringLen(reservedName);\r\n  if (name.Length() <= len)\r\n    return true;\r\n  if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n    return true;\r\n  wchar_t c = name[len];\r\n  if (c < L'0' || c > L'9')\r\n    return true;\r\n  return CheckTail(name, len + 1);\r\n}\r\n\r\nstatic bool IsSupportedName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++)\r\n  {\r\n    const wchar_t *reservedName = g_ReservedNames[i];\r\n    int len = MyStringLen(reservedName);\r\n    if (name.Length() < len)\r\n      continue;\r\n    if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n      continue;\r\n    if (!CheckTail(name, len))\r\n      return false;\r\n  }\r\n  if (!CheckNameNum(name, L\"COM\"))\r\n    return false;\r\n  return CheckNameNum(name, L\"LPT\");\r\n}\r\n#endif\r\n\r\nstatic UString GetCorrectFileName(const UString &path)\r\n{\r\n  if (path == L\"..\" || path == L\".\")\r\n    return UString();\r\n  return ReplaceIncorrectChars(path);\r\n}\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts)\r\n{\r\n  for (int i = 0; i < pathParts.Size();)\r\n  {\r\n    UString &s = pathParts[i];\r\n    s = GetCorrectFileName(s);\r\n    if (s.IsEmpty())\r\n      pathParts.Delete(i);\r\n    else\r\n    {\r\n      #ifdef _WIN32\r\n      if (!IsSupportedName(s))\r\n        s = (UString)L\"_\" + s;\r\n      #endif\r\n      i++;\r\n    }\r\n  }\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h",
    "content": "// ExtractingFilePath.h\r\n\r\n#ifndef __EXTRACTINGFILEPATH_H\r\n#define __EXTRACTINGFILEPATH_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h",
    "content": "// IFileExtractCallback.h\r\n\r\n#ifndef __IFILEEXTRACTCALLBACK_H\r\n#define __IFILEEXTRACTCALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"../../IDecl.h\"\r\n\r\nnamespace NOverwriteAnswer\r\n{\r\n  enum EEnum\r\n  {\r\n    kYes,\r\n    kYesToAll,\r\n    kNo,\r\n    kNoToAll,\r\n    kAutoRename,\r\n    kCancel\r\n  };\r\n}\r\n\r\nDECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)\r\n{\r\npublic:\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer) PURE;\r\n  STDMETHOD(PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position) PURE;\r\n  STDMETHOD(MessageError)(const wchar_t *message) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE;\r\n};\r\n\r\nstruct IExtractCallbackUI: IFolderArchiveExtractCallback\r\n{\r\n  virtual HRESULT BeforeOpen(const wchar_t *name) = 0;\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted) = 0;\r\n  virtual HRESULT ThereAreNoFiles() = 0;\r\n  virtual HRESULT ExtractResult(HRESULT result) = 0;\r\n  virtual HRESULT SetPassword(const UString &password) = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp",
    "content": "// LoadCodecs.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LoadCodecs.h\"\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Common/StringToInt.h\"\r\n#endif\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/FileFind.h\"\r\n#include \"../../../Windows/DLL.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Windows/ResourceString.h\"\r\nstatic const UINT kIconTypesResId = 100;\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/Registry.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\n#ifdef _WIN32\r\nextern HINSTANCE g_hInstance;\r\n#endif\r\n\r\nstatic CSysString GetLibraryFolderPrefix()\r\n{\r\n  #ifdef _WIN32\r\n  TCHAR fullPath[MAX_PATH + 1];\r\n  ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);\r\n  CSysString path = fullPath;\r\n  int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  return path.Left(pos + 1);\r\n  #else\r\n  return CSysString(); // FIX IT\r\n  #endif\r\n}\r\n\r\n#define kCodecsFolderName TEXT(\"Codecs\")\r\n#define kFormatsFolderName TEXT(\"Formats\")\r\nstatic TCHAR *kMainDll = TEXT(\"7z.dll\");\r\n\r\n#ifdef _WIN32\r\nstatic LPCTSTR kRegistryPath = TEXT(\"Software\\\\7-zip\");\r\nstatic LPCTSTR kProgramPathValue = TEXT(\"Path\");\r\nstatic bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)\r\n{\r\n  NRegistry::CKey key;\r\n  if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)\r\n    if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)\r\n    {\r\n      NName::NormalizeDirPathPrefix(path);\r\n      return true;\r\n    }\r\n  return false;\r\n}\r\n\r\n#endif\r\n\r\nCSysString GetBaseFolderPrefixFromRegistry()\r\n{\r\n  CSysString moduleFolderPrefix = GetLibraryFolderPrefix();\r\n  NFind::CFileInfo fileInfo;\r\n  if (NFind::FindFile(moduleFolderPrefix + kMainDll, fileInfo))\r\n    if (!fileInfo.IsDirectory())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fileInfo))\r\n    if (fileInfo.IsDirectory())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fileInfo))\r\n    if (fileInfo.IsDirectory())\r\n      return moduleFolderPrefix;\r\n  #ifdef _WIN32\r\n  CSysString path;\r\n  if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))\r\n    return path;\r\n  if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))\r\n    return path;\r\n  #endif\r\n  return moduleFolderPrefix;\r\n}\r\n\r\ntypedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);\r\ntypedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, void **outObject);\r\ntypedef UInt32 (WINAPI *SetLargePageModeFunc)();\r\n\r\n\r\nstatic HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 index, \r\n    PROPID propId, CLSID &clsId, bool &isAssigned)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  isAssigned = false;\r\n  RINOK(getMethodProperty(index, propId, &prop));\r\n  if (prop.vt == VT_BSTR)\r\n  {\r\n    isAssigned = true;\r\n    clsId = *(const GUID *)prop.bstrVal;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::LoadCodecs()\r\n{\r\n  CCodecLib &lib = Libs.Back();\r\n  lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress(\"GetMethodProperty\");\r\n  if (lib.GetMethodProperty == NULL)\r\n    return S_OK;\r\n\r\n  UInt32 numMethods = 1;\r\n  GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProcAddress(\"GetNumberOfMethods\");\r\n  if (getNumberOfMethodsFunc != NULL)\r\n  {\r\n    RINOK(getNumberOfMethodsFunc(&numMethods));\r\n  }\r\n\r\n  for(UInt32 i = 0; i < numMethods; i++)\r\n  {\r\n    CDllCodecInfo info;\r\n    info.LibIndex = Libs.Size() - 1;\r\n    info.CodecIndex = i;\r\n\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));\r\n\r\n    Codecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadProp(\r\n    GetHandlerPropertyFunc getProp, \r\n    GetHandlerPropertyFunc2 getProp2, \r\n    UInt32 index, PROPID propID, NCOM::CPropVariant &prop)\r\n{\r\n  if (getProp2)\r\n    return getProp2(index, propID, &prop);;\r\n  return getProp(propID, &prop);\r\n}\r\n\r\nstatic HRESULT ReadBoolProp(\r\n    GetHandlerPropertyFunc getProp, \r\n    GetHandlerPropertyFunc2 getProp2, \r\n    UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadStringProp(\r\n    GetHandlerPropertyFunc getProp, \r\n    GetHandlerPropertyFunc2 getProp2, \r\n    UInt32 index, PROPID propID, UString &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BSTR)\r\n    res = prop.bstrVal;\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax]; \r\nvoid RegisterArc(const CArcInfo *arcInfo) \r\n{ \r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo; \r\n}\r\n\r\nstatic void SplitString(const UString &srcString, UStringVector &destStrings)\r\n{\r\n  destStrings.Clear();\r\n  UString s;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L' ')\r\n    {\r\n      if (!s.IsEmpty())\r\n      {\r\n        destStrings.Add(s);\r\n        s.Empty();\r\n      }\r\n    }\r\n    else\r\n      s += c;\r\n  }\r\n  if (!s.IsEmpty())\r\n    destStrings.Add(s);\r\n}\r\n\r\nvoid CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt)\r\n{\r\n  UStringVector exts, addExts;\r\n  SplitString(ext, exts);\r\n  if (addExt != 0)\r\n    SplitString(addExt, addExts);\r\n  for (int i = 0; i < exts.Size(); i++)\r\n  {\r\n    CArcExtInfo extInfo;\r\n    extInfo.Ext = exts[i];\r\n    if (i < addExts.Size())\r\n    {\r\n      extInfo.AddExt = addExts[i];\r\n      if (extInfo.AddExt == L\"*\")\r\n        extInfo.AddExt.Empty();\r\n    }\r\n    Exts.Add(extInfo);\r\n  }\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nHRESULT CCodecs::LoadFormats()\r\n{\r\n  const NDLL::CLibrary &lib = Libs.Back().Lib;\r\n  GetHandlerPropertyFunc getProp = 0;\r\n  GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)\r\n      lib.GetProcAddress(\"GetHandlerProperty2\");\r\n  if (getProp2 == NULL)\r\n  {\r\n    getProp = (GetHandlerPropertyFunc)\r\n        lib.GetProcAddress(\"GetHandlerProperty\");\r\n    if (getProp == NULL)\r\n      return S_OK;\r\n  }\r\n\r\n  UInt32 numFormats = 1;\r\n  GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)\r\n    lib.GetProcAddress(\"GetNumberOfFormats\");\r\n  if (getNumberOfFormats != NULL)\r\n  {\r\n    RINOK(getNumberOfFormats(&numFormats));\r\n  }\r\n  if (getProp2 == NULL)\r\n    numFormats = 1;\r\n\r\n  for(UInt32 i = 0; i < numFormats; i++)\r\n  {\r\n    CArcInfoEx item;\r\n    item.LibIndex = Libs.Size() - 1;\r\n    item.FormatIndex = i;\r\n\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)\r\n      continue;\r\n    if (prop.vt != VT_BSTR)\r\n      continue;\r\n    item.ClassID = *(const GUID *)prop.bstrVal;\r\n    prop.Clear();\r\n\r\n    UString ext, addExt;\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));\r\n    item.AddExts(ext, addExt);\r\n\r\n    ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);\r\n    if (item.UpdateEnabled)\r\n      ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);\r\n    \r\n    if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)\r\n      if (prop.vt == VT_BSTR)\r\n      {\r\n        UINT len = ::SysStringByteLen(prop.bstrVal);\r\n        item.StartSignature.SetCapacity(len);\r\n        memmove(item.StartSignature, prop.bstrVal, len);\r\n      }\r\n    Formats.Add(item);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef NEW_FOLDER_INTERFACE\r\nvoid CCodecLib::LoadIcons()\r\n{\r\n  UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId);\r\n  UStringVector pairs;\r\n  SplitString(iconTypes, pairs);\r\n  for (int i = 0; i < pairs.Size(); i++)\r\n  {\r\n    const UString &s = pairs[i];\r\n    int pos = s.Find(L':');\r\n    if (pos < 0)\r\n      continue;\r\n    CIconPair iconPair;\r\n    const wchar_t *end;\r\n    UString num = s.Mid(pos + 1);\r\n    iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);\r\n    if (*end != L'\\0')\r\n      continue;\r\n    iconPair.Ext = s.Left(pos);\r\n    IconPairs.Add(iconPair);\r\n  }\r\n}\r\n\r\nint CCodecLib::FindIconIndex(const UString &ext) const\r\n{\r\n  for (int i = 0; i < IconPairs.Size(); i++)\r\n  {\r\n    const CIconPair &pair = IconPairs[i];\r\n    if (ext.CompareNoCase(pair.Ext) == 0)\r\n      return pair.IconIndex;\r\n  }\r\n  return -1;\r\n}\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nextern \"C\" \r\n{\r\n  extern SIZE_T g_LargePageSize;\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::LoadDll(const CSysString &dllPath)\r\n{\r\n  {\r\n    NDLL::CLibrary library;\r\n    if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))\r\n      return S_OK;\r\n  }\r\n  Libs.Add(CCodecLib());\r\n  CCodecLib &lib = Libs.Back();\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  lib.Path = dllPath;\r\n  #endif\r\n  bool used = false;\r\n  HRESULT res = S_OK;\r\n  if (lib.Lib.Load(dllPath))\r\n  {\r\n    #ifdef NEW_FOLDER_INTERFACE\r\n    lib.LoadIcons();\r\n    #endif\r\n\r\n    #ifdef _7ZIP_LARGE_PAGES\r\n    if (g_LargePageSize != 0)\r\n    {\r\n      SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProcAddress(\"SetLargePageMode\");\r\n      if (setLargePageMode != 0)\r\n        setLargePageMode();\r\n    }\r\n    #endif\r\n\r\n    lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress(\"CreateObject\");\r\n    if (lib.CreateObject != 0)\r\n    {\r\n      int startSize = Codecs.Size();\r\n      res = LoadCodecs();\r\n      used = (Codecs.Size() != startSize);\r\n      if (res == S_OK)\r\n      {\r\n        startSize = Formats.Size();\r\n        res = LoadFormats();\r\n        used = used || (Formats.Size() != startSize);\r\n      }\r\n    }\r\n  }\r\n  if (!used)\r\n    Libs.DeleteBack();\r\n  return res;\r\n}\r\n\r\nHRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)\r\n{\r\n  NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT(\"*\")));\r\n  NFile::NFind::CFileInfo fileInfo;\r\n  while (enumerator.Next(fileInfo))\r\n  {\r\n    if (fileInfo.IsDirectory())\r\n      continue;\r\n    RINOK(LoadDll(folderPrefix + fileInfo.Name));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n#ifndef _SFX\r\nstatic inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)\r\n{\r\n  bb.SetCapacity(size);\r\n  memmove((Byte *)bb, data, size);\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::Load()\r\n{\r\n  Formats.Clear();\r\n  #ifdef EXTERNAL_CODECS\r\n  Codecs.Clear();\r\n  #endif\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n  {\r\n    const CArcInfo &arc = *g_Arcs[i];\r\n    CArcInfoEx item;\r\n    item.Name = arc.Name;\r\n    item.CreateInArchive = arc.CreateInArchive;\r\n    item.CreateOutArchive = arc.CreateOutArchive;\r\n    item.AddExts(arc.Ext, arc.AddExt);\r\n    item.UpdateEnabled = (arc.CreateOutArchive != 0);\r\n    item.KeepName = arc.KeepName;\r\n\r\n    #ifndef _SFX\r\n    SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);\r\n    #endif\r\n    Formats.Add(item);\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();\r\n  RINOK(LoadDll(baseFolder + kMainDll));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveName(const UString &archivePath) const\r\n{\r\n  int slashPos1 = archivePath.ReverseFind(L'\\\\');\r\n  int slashPos2 = archivePath.ReverseFind(L'.');\r\n  int dotPos = archivePath.ReverseFind(L'.');\r\n  if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)\r\n    return -1;\r\n  UString ext = archivePath.Mid(dotPos + 1);\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    // if (arc.FindExtension(ext) >= 0)\r\n    UString mainExt = arc.GetMainExt();\r\n    if (!mainExt.IsEmpty() && ext.CompareNoCase(mainExt) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveType(const UString &arcType) const\r\n{\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    if (arc.Name.CompareNoCase(arcType) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\n#ifdef EXPORT_CODECS\r\nextern unsigned int g_NumCodecs;\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);\r\n// STDAPI GetNumberOfMethods(UINT32 *numCodecs);\r\n#endif\r\n\r\nSTDMETHODIMP CCodecs::GetNumberOfMethods(UINT32 *numMethods)\r\n{\r\n  *numMethods = \r\n      #ifdef EXPORT_CODECS\r\n      g_NumCodecs + \r\n      #endif\r\n      Codecs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::GetProperty(UINT32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return GetMethodProperty(index, propID, value);\r\n  #endif\r\n\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n\r\n  if (propID == NMethodPropID::kDecoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.DecoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  if (propID == NMethodPropID::kEncoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.EncoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateDecoder(UINT32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(false, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.DecoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateEncoder(UINT32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(true, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.EncoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const\r\n{ \r\n  for (int i = 0; i < Codecs.Size(); i++)\r\n  {\r\n    const CDllCodecInfo &codec = Codecs[i];\r\n    if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigned)\r\n      continue;\r\n    const CCodecLib &lib = Libs[codec.LibIndex];\r\n    UString res;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      res = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      continue;\r\n    if (name.CompareNoCase(res) == 0)\r\n      return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICompressCoder, (void **)&coder);\r\n  }\r\n  return CLASS_E_CLASSNOTAVAILABLE;\r\n}\r\n\r\nint CCodecs::GetCodecLibIndex(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return -1;\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.LibIndex;\r\n  #else\r\n  return -1;\r\n  #endif\r\n}\r\n\r\nbool CCodecs::GetCodecEncoderIsAssigned(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n  {\r\n    NWindows::NCOM::CPropVariant prop;\r\n    if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK)\r\n      if (prop.vt != VT_EMPTY)\r\n        return true;\r\n    return false;\r\n  }\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.EncoderIsAssigned;\r\n  #else\r\n  return false;\r\n  #endif\r\n}\r\n\r\nHRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(GetProperty(index, NMethodPropID::kID, &prop));\r\n  if (prop.vt != VT_UI8)\r\n    return E_INVALIDARG;\r\n  id = prop.uhVal.QuadPart;\r\n  return S_OK;\r\n}\r\n\r\nUString CCodecs::GetCodecName(UInt32 index)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK)\r\n    if (prop.vt == VT_BSTR)\r\n      s = prop.bstrVal;\r\n  return s;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/LoadCodecs.h",
    "content": "// LoadCodecs.h\r\n\r\n#ifndef __LOADCODECS_H\r\n#define __LOADCODECS_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/DLL.h\"\r\n#endif\r\n\r\nstruct CDllCodecInfo\r\n{\r\n  CLSID Encoder;\r\n  CLSID Decoder;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  int LibIndex;\r\n  UInt32 CodecIndex;\r\n};\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcExtInfo\r\n{\r\n  UString Ext;\r\n  UString AddExt;\r\n  CArcExtInfo() {}\r\n  CArcExtInfo(const UString &ext): Ext(ext) {}\r\n  CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}\r\n};\r\n\r\n\r\nstruct CArcInfoEx\r\n{\r\n  #ifdef EXTERNAL_CODECS\r\n  int LibIndex;\r\n  UInt32 FormatIndex;\r\n  CLSID ClassID;\r\n  #endif\r\n  bool UpdateEnabled;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n  UString Name;\r\n  CObjectVector<CArcExtInfo> Exts;\r\n  #ifndef _SFX\r\n  CByteBuffer StartSignature;\r\n  // CByteBuffer FinishSignature;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  UStringVector AssociateExts;\r\n  #endif\r\n  #endif\r\n  bool KeepName;\r\n  UString GetMainExt() const\r\n  {\r\n    if (Exts.IsEmpty())\r\n      return UString();\r\n    return Exts[0].Ext;\r\n  }\r\n  int FindExtension(const UString &ext) const\r\n  {\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n      if (ext.CompareNoCase(Exts[i].Ext) == 0)\r\n        return i;\r\n    return -1;\r\n  }\r\n  UString GetAllExtensions() const\r\n  {\r\n    UString s;\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n    {\r\n      if (i > 0)\r\n        s += ' ';\r\n      s += Exts[i].Ext;\r\n    }\r\n    return s;\r\n  }\r\n\r\n  void AddExts(const wchar_t* ext, const wchar_t* addExt);\r\n\r\n  CArcInfoEx(): \r\n    #ifdef EXTERNAL_CODECS\r\n    LibIndex(-1),\r\n    #endif\r\n    UpdateEnabled(false),\r\n    CreateInArchive(0), CreateOutArchive(0),\r\n    KeepName(false)\r\n    #ifndef _SFX\r\n    #endif\r\n  {}\r\n};\r\n\r\n#ifdef EXTERNAL_CODECS\r\ntypedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);\r\n\r\n\r\nstruct CCodecLib\r\n{\r\n  NWindows::NDLL::CLibrary Lib;\r\n  GetMethodPropertyFunc GetMethodProperty;\r\n  CreateObjectFunc CreateObject;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  struct CIconPair\r\n  {\r\n    UString Ext;\r\n    UInt32 IconIndex;\r\n  };\r\n  CSysString Path;\r\n  CObjectVector<CIconPair> IconPairs;\r\n  void LoadIcons();\r\n  int FindIconIndex(const UString &ext) const;\r\n  #endif\r\n  CCodecLib(): GetMethodProperty(0) {}\r\n};\r\n#endif\r\n\r\nclass CCodecs:\r\n  #ifdef EXTERNAL_CODECS\r\n  public ICompressCodecsInfo,\r\n  #else\r\n  public IUnknown,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:  \r\n  #ifdef EXTERNAL_CODECS\r\n  CObjectVector<CCodecLib> Libs;\r\n  CObjectVector<CDllCodecInfo> Codecs;\r\n  HRESULT LoadCodecs();\r\n  HRESULT LoadFormats();\r\n  HRESULT LoadDll(const CSysString &path);\r\n  HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);\r\n\r\n  HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const\r\n  {\r\n    return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);\r\n  }\r\n  #endif\r\n\r\npublic:\r\n  CObjectVector<CArcInfoEx> Formats;\r\n  HRESULT Load();\r\n  int FindFormatForArchiveName(const UString &archivePath) const;\r\n  int FindFormatForArchiveType(const UString &arcType) const;\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  STDMETHOD(GetNumberOfMethods)(UINT32 *numMethods);\r\n  STDMETHOD(GetProperty)(UINT32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(CreateDecoder)(UINT32 index, const GUID *interfaceID, void **coder);\r\n  STDMETHOD(CreateEncoder)(UINT32 index, const GUID *interfaceID, void **coder);\r\n  #endif\r\n\r\n  int GetCodecLibIndex(UInt32 index);\r\n  bool GetCodecEncoderIsAssigned(UInt32 index);\r\n  HRESULT GetCodecId(UInt32 index, UInt64 &id);\r\n  UString GetCodecName(UInt32 index);\r\n\r\n  HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const\r\n  { \r\n    const CArcInfoEx &ai = Formats[formatIndex]; \r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateInArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, false); \r\n    #endif\r\n  }\r\n  HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const\r\n  { \r\n    const CArcInfoEx &ai = Formats[formatIndex]; \r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateOutArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, true); \r\n    #endif\r\n  }\r\n  int FindOutFormatFromName(const UString &name) const\r\n  {\r\n    for (int i = 0; i < Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = Formats[i];\r\n      if (!arc.UpdateEnabled)\r\n        continue;\r\n      if (arc.Name.CompareNoCase(name) == 0)\r\n        return i;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;\r\n  #endif\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/OpenArchive.cpp",
    "content": "// OpenArchive.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidPath, &prop));\r\n  if(prop.vt == VT_BSTR)\r\n    result = prop.bstrVal;\r\n  else if (prop.vt == VT_EMPTY)\r\n    result.Empty();\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result)\r\n{\r\n  RINOK(GetArchiveItemPath(archive, index, result));\r\n  if (result.IsEmpty())\r\n    result = defaultName;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index, \r\n    const FILETIME &defaultFileTime, FILETIME &fileTime)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidLastWriteTime, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n    fileTime = prop.filetime;\r\n  else if (prop.vt == VT_EMPTY)\r\n    fileTime = defaultFileTime;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsFolder, result);\r\n}\r\n\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsAnti, result);\r\n}\r\n\r\n// Static-SFX (for Linux) can be big.\r\nconst UInt64 kMaxCheckStartPosition = 1 << 22;\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  inStreamSpec->Open(fileName);\r\n  return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n}\r\n\r\n#ifndef _SFX\r\nstatic inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)\r\n{\r\n  for (size_t i = 0; i < size; i++)\r\n    if (p1[i] != p2[i])\r\n      return false;\r\n  return true;\r\n}\r\n#endif\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    IInStream *inStream,\r\n    const UString &fileName, \r\n    IInArchive **archiveResult, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  *archiveResult = NULL;\r\n  UString extension;\r\n  {\r\n    int dotPos = fileName.ReverseFind(L'.');\r\n    if (dotPos >= 0)\r\n      extension = fileName.Mid(dotPos + 1);\r\n  }\r\n  CIntVector orderIndices;\r\n  int i;\r\n  int numFinded = 0;\r\n  for (i = 0; i < codecs->Formats.Size(); i++)\r\n    if (codecs->Formats[i].FindExtension(extension) >= 0)\r\n      orderIndices.Insert(numFinded++, i);\r\n    else\r\n      orderIndices.Add(i);\r\n  \r\n  #ifndef _SFX\r\n  if (numFinded != 1)\r\n  {\r\n    CIntVector orderIndices2;\r\n    CByteBuffer byteBuffer;\r\n    const UInt32 kBufferSize = (200 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    UInt32 processedSize;\r\n    RINOK(ReadStream(inStream, buffer, kBufferSize, &processedSize));\r\n    for (UInt32 pos = 0; pos < processedSize; pos++)\r\n    {\r\n      for (int i = 0; i < orderIndices.Size(); i++)\r\n      {\r\n        int index = orderIndices[i];\r\n        const CArcInfoEx &ai = codecs->Formats[index];\r\n        const CByteBuffer &sig = ai.StartSignature;\r\n        if (sig.GetCapacity() == 0)\r\n          continue;\r\n        if (pos + sig.GetCapacity() > processedSize)\r\n          continue;\r\n        if (TestSignature(buffer + pos, sig, sig.GetCapacity()))\r\n        {\r\n          orderIndices2.Add(index);\r\n          orderIndices.Delete(i--);\r\n        }\r\n      }\r\n    }\r\n    orderIndices2 += orderIndices;\r\n    orderIndices = orderIndices2;\r\n  }\r\n  else if (extension == L\"000\" || extension == L\"001\")\r\n  {\r\n    CByteBuffer byteBuffer;\r\n    const UInt32 kBufferSize = (1 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    UInt32 processedSize;\r\n    RINOK(ReadStream(inStream, buffer, kBufferSize, &processedSize));\r\n    if (processedSize >= 16)\r\n    {\r\n      Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};\r\n      if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] && 1) != 0)\r\n      {\r\n        for (int i = 0; i < orderIndices.Size(); i++)\r\n        {\r\n          int index = orderIndices[i];\r\n          const CArcInfoEx &ai = codecs->Formats[index];\r\n          if (ai.Name.CompareNoCase(L\"rar\") != 0)\r\n            continue;\r\n          orderIndices.Delete(i--);\r\n          orderIndices.Insert(0, index);\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  HRESULT badResult = S_OK;\r\n  for(i = 0; i < orderIndices.Size(); i++)\r\n  {\r\n    inStream->Seek(0, STREAM_SEEK_SET, NULL);\r\n\r\n    CMyComPtr<IInArchive> archive;\r\n\r\n    formatIndex = orderIndices[i];\r\n    RINOK(codecs->CreateInArchive(formatIndex, archive));\r\n    if (!archive)\r\n      continue;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    HRESULT result = archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n    if (result == S_FALSE)\r\n      continue;\r\n    if(result != S_OK)\r\n    {\r\n      badResult = result;\r\n      if(result == E_ABORT)\r\n        break;\r\n      continue;\r\n    }\r\n    *archiveResult = archive.Detach();\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex];\r\n    if (format.Exts.Size() == 0)\r\n    {\r\n      defaultItemName = GetDefaultName2(fileName, L\"\", L\"\");\r\n    }\r\n    else\r\n    {\r\n      int subExtIndex = format.FindExtension(extension);\r\n      if (subExtIndex < 0)\r\n        subExtIndex = 0;\r\n      defaultItemName = GetDefaultName2(fileName, \r\n          format.Exts[subExtIndex].Ext, \r\n          format.Exts[subExtIndex].AddExt);\r\n    }\r\n    return S_OK;\r\n  }\r\n  if (badResult != S_OK)\r\n    return badResult;\r\n  return S_FALSE;\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &filePath, \r\n    IInArchive **archiveResult, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  if (!inStreamSpec->Open(filePath))\r\n    return GetLastError();\r\n  return OpenArchive(codecs, inStream, ExtractFileNameFromPath(filePath),\r\n    archiveResult, formatIndex,\r\n    defaultItemName, openArchiveCallback);\r\n}\r\n\r\nstatic void MakeDefaultName(UString &name)\r\n{\r\n  int dotPos = name.ReverseFind(L'.');\r\n  if (dotPos < 0)\r\n    return;\r\n  UString ext = name.Mid(dotPos + 1);\r\n  if (ext.IsEmpty())\r\n    return;\r\n  for (int pos = 0; pos < ext.Length(); pos++)\r\n    if (ext[pos] < L'0' || ext[pos] > L'9')\r\n      return;\r\n  name = name.Left(dotPos);\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &fileName, \r\n    IInArchive **archive0, \r\n    IInArchive **archive1, \r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  HRESULT result = OpenArchive(codecs, fileName, \r\n      archive0, formatIndex0, defaultItemName0, openArchiveCallback);\r\n  RINOK(result);\r\n  CMyComPtr<IInArchiveGetStream> getStream;\r\n  result = (*archive0)->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream);\r\n  if (result != S_OK || getStream == 0)\r\n    return S_OK;\r\n\r\n  CMyComPtr<ISequentialInStream> subSeqStream;\r\n  result = getStream->GetStream(0, &subSeqStream);\r\n  if (result != S_OK)\r\n    return S_OK;\r\n\r\n  CMyComPtr<IInStream> subStream;\r\n  if (subSeqStream.QueryInterface(IID_IInStream, &subStream) != S_OK)\r\n    return S_OK;\r\n  if (!subStream)\r\n    return S_OK;\r\n\r\n  UInt32 numItems;\r\n  RINOK((*archive0)->GetNumberOfItems(&numItems));\r\n  if (numItems < 1)\r\n    return S_OK;\r\n\r\n  UString subPath;\r\n  RINOK(GetArchiveItemPath(*archive0, 0, subPath))\r\n  if (subPath.IsEmpty())\r\n  {\r\n    MakeDefaultName(defaultItemName0);\r\n    subPath = defaultItemName0;\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex0];\r\n    if (format.Name.CompareNoCase(L\"7z\") == 0)\r\n    {\r\n      if (subPath.Right(3).CompareNoCase(L\".7z\") != 0)\r\n        subPath += L\".7z\";\r\n    }\r\n  }\r\n  else\r\n    subPath = ExtractFileNameFromPath(subPath);\r\n\r\n  CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;\r\n  openArchiveCallback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);\r\n  if (setSubArchiveName)\r\n    setSubArchiveName->SetSubArchiveName(subPath);\r\n\r\n  result = OpenArchive(codecs, subStream, subPath,\r\n      archive1, formatIndex1, defaultItemName1, openArchiveCallback);\r\n  return S_OK;\r\n}\r\n\r\nstatic void SetCallback(const UString &archiveName,\r\n    IOpenCallbackUI *openCallbackUI, CMyComPtr<IArchiveOpenCallback> &openCallback)\r\n{\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  openCallbackSpec->Init(\r\n      fullName.Left(fileNamePartStartIndex), \r\n      fullName.Mid(fileNamePartStartIndex));\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs, \r\n    const UString &archiveName,\r\n    IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI)\r\n{\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(archiveName, openCallbackUI, openCallback);\r\n  int formatInfo;\r\n  return OpenArchive(codecs, archiveName, archive, formatInfo, defaultItemName, openCallback);\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  volumesSize = 0;\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  UString prefix = fullName.Left(fileNamePartStartIndex);\r\n  UString name = fullName.Mid(fileNamePartStartIndex);\r\n  openCallbackSpec->Init(prefix, name);\r\n\r\n  int formatIndex0, formatIndex1;\r\n  RINOK(OpenArchive(codecs, archiveName,\r\n      archive0, \r\n      archive1, \r\n      formatIndex0, \r\n      formatIndex1, \r\n      defaultItemName0,\r\n      defaultItemName1,\r\n      openCallback));\r\n  volumePaths.Add(prefix + name);\r\n  for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)\r\n    volumePaths.Add(prefix + openCallbackSpec->FileNames[i]);\r\n  volumesSize = openCallbackSpec->TotalSize;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveLink::Close()\r\n{\r\n  if (Archive1 != 0)\r\n    RINOK(Archive1->Close());\r\n  if (Archive0 != 0)\r\n    RINOK(Archive0->Close());\r\n  IsOpen = false;\r\n  return S_OK;\r\n}\r\n\r\nvoid CArchiveLink::Release()\r\n{\r\n  IsOpen = false;\r\n  Archive1.Release();\r\n  Archive0.Release();\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  HRESULT res = OpenArchive(codecs, archiveName, \r\n    &archiveLink.Archive0, &archiveLink.Archive1, \r\n    archiveLink.FormatIndex0, archiveLink.FormatIndex1, \r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1, \r\n    openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT MyOpenArchive(CCodecs *codecs,\r\n    const UString &archiveName, \r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  HRESULT res = MyOpenArchive(codecs, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1, \r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1, \r\n    archiveLink.VolumePaths,\r\n    archiveLink.VolumesSize,\r\n    openCallbackUI);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT ReOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, const UString &fileName)\r\n{\r\n  if (archiveLink.GetNumLevels() > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (archiveLink.GetNumLevels() == 0)\r\n    return MyOpenArchive(codecs, fileName, archiveLink, 0);\r\n\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(fileName, NULL, openCallback);\r\n\r\n  HRESULT res = ReOpenArchive(archiveLink.GetArchive(), fileName, openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/OpenArchive.h",
    "content": "// OpenArchive.h\r\n\r\n#ifndef __OPENARCHIVE_H\r\n#define __OPENARCHIVE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"LoadCodecs.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result);\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result);\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index, \r\n    const FILETIME &defaultFileTime, FILETIME &fileTime);\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result);\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result);\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result);\r\n\r\nstruct ISetSubArchiveName\r\n{\r\n  virtual void SetSubArchiveName(const wchar_t *name) = 0;\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    IInStream *inStream,\r\n    const UString &fileName, \r\n    IInArchive **archiveResult, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &filePath, \r\n    IInArchive **archive, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &filePath, \r\n    IInArchive **archive0, \r\n    IInArchive **archive1, \r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    IInArchive **archive,\r\n    UString &defaultItemName,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nstruct CArchiveLink\r\n{\r\n  CMyComPtr<IInArchive> Archive0;\r\n  CMyComPtr<IInArchive> Archive1;\r\n  UString DefaultItemName0;\r\n  UString DefaultItemName1;\r\n\r\n  int FormatIndex0;\r\n  int FormatIndex1;\r\n  \r\n  UStringVector VolumePaths;\r\n\r\n  UInt64 VolumesSize;\r\n\r\n  int GetNumLevels() const\r\n  { \r\n    int result = 0;\r\n    if (Archive0)\r\n    {\r\n      result++;\r\n      if (Archive1)\r\n        result++;\r\n    }\r\n    return result;\r\n  }\r\n\r\n  bool IsOpen;\r\n\r\n  CArchiveLink(): IsOpen(false), VolumesSize(0) {};\r\n\r\n  IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; }\r\n  UString GetDefaultItemName()  { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; }\r\n  int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; }\r\n  HRESULT Close();\r\n  void Release();\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT ReOpenArchive(\r\n    CCodecs *codecs,\r\n    CArchiveLink &archiveLink, \r\n    const UString &fileName);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp",
    "content": "// PropIDUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropIDUtils.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../PropID.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic void ConvertUInt32ToHex(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    int t = value & 0xF;\r\n    value >>= 4;\r\n    s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));\r\n  }\r\n  s[8] = L'\\0';\r\n}\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full)\r\n{\r\n  switch(propID)\r\n  {\r\n    case kpidCreationTime:\r\n    case kpidLastWriteTime:\r\n    case kpidLastAccessTime:\r\n    {\r\n      if (propVariant.vt != VT_FILETIME)\r\n        return UString(); // It is error;\r\n      FILETIME localFileTime;\r\n      if (propVariant.filetime.dwHighDateTime == 0 && \r\n          propVariant.filetime.dwLowDateTime == 0)\r\n        return UString();\r\n      if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n        return UString(); // It is error;\r\n      return ConvertFileTimeToString(localFileTime, true, full);\r\n    }\r\n    case kpidCRC:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      wchar_t temp[12];\r\n      ConvertUInt32ToHex(propVariant.ulVal, temp);\r\n      return temp;\r\n    }\r\n    case kpidAttributes:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UString result;\r\n      UInt32 attributes = propVariant.ulVal;\r\n      if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';\r\n      if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';\r\n      if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';\r\n      if (NFile::NFind::NAttributes::IsDirectory(attributes)) result += L'D';\r\n      if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';\r\n      if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';\r\n      if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';\r\n      return result;\r\n    }\r\n    case kpidDictionarySize:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UInt32 size = propVariant.ulVal;\r\n      if (size % (1 << 20) == 0)\r\n        return ConvertUInt32ToString(size >> 20) + L\"MB\";\r\n      if (size % (1 << 10) == 0)\r\n        return ConvertUInt32ToString(size >> 10) + L\"KB\";\r\n      return ConvertUInt32ToString(size);\r\n    }\r\n  }\r\n  return ConvertPropVariantToString(propVariant);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/PropIDUtils.h",
    "content": "// PropIDUtils.h\r\n\r\n#ifndef __PROPIDUTILS_H\r\n#define __PROPIDUTILS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/Property.h",
    "content": "// Property.h\r\n\r\n#ifndef __PROPERTY_H\r\n#define __PROPERTY_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nstruct CProperty\r\n{\r\n  UString Name;\r\n  UString Value;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/SetProperties.cpp",
    "content": "// SetProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SetProperties.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\n\r\nstatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)\r\n{\r\n  const wchar_t *endPtr;\r\n  UInt64 result = ConvertStringToUInt64(s, &endPtr);\r\n  if (endPtr - (const wchar_t *)s != s.Length())\r\n    prop = s;\r\n  else if (result <= 0xFFFFFFFF)\r\n    prop = (UInt32)result;\r\n  else \r\n    prop = result;\r\n}\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)\r\n{\r\n  if (properties.IsEmpty())\r\n    return S_OK;\r\n  CMyComPtr<ISetProperties> setProperties;\r\n  unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);\r\n  if (!setProperties)\r\n    return S_OK;\r\n\r\n  UStringVector realNames;\r\n  CPropVariant *values = new CPropVariant[properties.Size()];\r\n  try\r\n  {\r\n    int i;\r\n    for(i = 0; i < properties.Size(); i++)\r\n    {\r\n      const CProperty &property = properties[i];\r\n      NCOM::CPropVariant propVariant;\r\n      if (!property.Value.IsEmpty())\r\n        ParseNumberString(property.Value, propVariant);\r\n      realNames.Add(property.Name);\r\n      values[i] = propVariant;\r\n    }\r\n    CRecordVector<const wchar_t *> names;\r\n    for(i = 0; i < realNames.Size(); i++)\r\n      names.Add((const wchar_t *)realNames[i]);\r\n    \r\n    RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));\r\n  }\r\n  catch(...)\r\n  {\r\n    delete []values;\r\n    throw;\r\n  }\r\n  delete []values;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/SetProperties.h",
    "content": "// SetProperties.h\r\n\r\n#ifndef __SETPROPERTIES_H\r\n#define __SETPROPERTIES_H\r\n\r\n#include \"Property.h\"\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/SortUtils.cpp",
    "content": "// SortUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SortUtils.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nstatic int CompareStrings(const int *p1, const int *p2, void *param)\r\n{\r\n  const UStringVector &strings = *(const UStringVector *)param;\r\n  return CompareFileNames(strings[*p1], strings[*p2]);\r\n}\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numItems = strings.Size();\r\n  indices.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n    indices.Add(i);\r\n  indices.Sort(CompareStrings, (void *)&strings);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/SortUtils.h",
    "content": "// SortUtils.h\r\n\r\n#ifndef __SORTUTLS_H\r\n#define __SORTUTLS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/TempFiles.cpp",
    "content": "// TempFiles.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"TempFiles.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileIO.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nvoid CTempFiles::Clear()\r\n{\r\n  while(!Paths.IsEmpty())\r\n  {\r\n    NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());\r\n    Paths.DeleteBack();\r\n  }\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/TempFiles.h",
    "content": "// TempFiles.h\r\n\r\n#ifndef __TEMPFILES_H\r\n#define __TEMPFILES_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nclass CTempFiles\r\n{\r\n  void Clear();\r\npublic:\r\n  UStringVector Paths;\r\n  ~CTempFiles() { Clear(); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/Update.cpp",
    "content": "// Update.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <mapi.h>\r\n#endif\r\n\r\n#include \"Update.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/DLL.h\"\r\n#endif\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n// #include \"Windows/Synchronization.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Compress/Copy/CopyCoder.h\"\r\n\r\n#include \"../Common/DirItem.h\"\r\n#include \"../Common/EnumDirItems.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"TempFiles.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"EnumDirItems.h\"\r\n#include \"SetProperties.h\"\r\n\r\nstatic const char *kUpdateIsNotSupoorted = \r\n  \"update operations are not supported for this archive\";\r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nstatic const wchar_t *kTempFolderPrefix = L\"7zE\";\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)\r\n{\r\n  CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;\r\n  return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);\r\n}\r\n\r\nclass COutMultiVolStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    COutFileStream *StreamSpec;\r\n    CMyComPtr<IOutStream> Stream;\r\n    UString Name;\r\n    UInt64 Pos;\r\n    UInt64 RealSize;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  // CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  CRecordVector<UInt64> Sizes;\r\n  UString Prefix;\r\n  CTempFiles *TempFiles;\r\n\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  HRESULT Close(); \r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n// static NSynchronization::CCriticalSection g_TempPathsCS;\r\n\r\nHRESULT COutMultiVolStream::Close()\r\n{\r\n  HRESULT res = S_OK;\r\n  for (int i = 0; i < Streams.Size(); i++)\r\n  {\r\n    CSubStreamInfo &s = Streams[i];\r\n    if (s.StreamSpec)\r\n    {\r\n      HRESULT res2 = s.StreamSpec->Close();\r\n      if (res2 != S_OK)\r\n        res = res2;\r\n    }\r\n  }\r\n  return res;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n\r\n      wchar_t temp[32];\r\n      ConvertUInt64ToString(_streamIndex + 1, temp);\r\n      UString res = temp;\r\n      while (res.Length() < 3)\r\n        res = UString(L'0') + res;\r\n      UString name = Prefix + res;\r\n      subStream.StreamSpec = new COutFileStream;\r\n      subStream.Stream = subStream.StreamSpec;\r\n      if(!subStream.StreamSpec->Create(name, false))\r\n        return ::GetLastError();\r\n      {\r\n        // NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);\r\n        TempFiles->Paths.Add(name);\r\n      }\r\n\r\n      subStream.Pos = 0;\r\n      subStream.RealSize = 0;\r\n      subStream.Name = name;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n\r\n    int index = _streamIndex;\r\n    if (index >= Sizes.Size())\r\n      index = Sizes.Size() - 1;\r\n    UInt64 volSize = Sizes[index];\r\n\r\n    if (_offsetPos >= volSize)\r\n    {\r\n      _offsetPos -= volSize;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      // CMyComPtr<IOutStream> outStream;\r\n      // RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(subStream.Stream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, volSize - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if (_offsetPos > subStream.RealSize)\r\n      subStream.RealSize = _offsetPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == volSize)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed == 0 && curSize != 0)\r\n      return E_FAIL;\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  if (newPosition != NULL)\r\n    *newPosition = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::SetSize(Int64 newSize)\r\n{\r\n  if (newSize < 0)\r\n    return E_INVALIDARG;\r\n  int i = 0;\r\n  while (i < Streams.Size())\r\n  {\r\n    CSubStreamInfo &subStream = Streams[i++];\r\n    if ((UInt64)newSize < subStream.RealSize)\r\n    {\r\n      RINOK(subStream.Stream->SetSize(newSize));\r\n      subStream.RealSize = newSize;\r\n      break;\r\n    }\r\n    newSize -= subStream.RealSize;\r\n  }\r\n  while (i < Streams.Size())\r\n  {\r\n    {\r\n      CSubStreamInfo &subStream = Streams.Back();\r\n      subStream.Stream.Release();\r\n      NDirectory::DeleteFileAlways(subStream.Name);\r\n    }\r\n    Streams.DeleteBack();\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  _length = newSize;\r\n  return S_OK;\r\n}\r\n\r\nstatic const wchar_t *kDefaultArchiveType = L\"7z\";\r\nstatic const wchar_t *kSFXExtension =\r\n  #ifdef _WIN32\r\n    L\"exe\";\r\n  #else\r\n    L\"\";\r\n  #endif\r\n\r\nbool CUpdateOptions::Init(const CCodecs *codecs, const UString &arcPath, const UString &arcType)\r\n{\r\n  if (!arcType.IsEmpty())\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveType(arcType);\r\n  else\r\n  {\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveName(arcPath);\r\n    if (MethodMode.FormatIndex < 0)\r\n      MethodMode.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArchiveType);\r\n  }\r\n  if (MethodMode.FormatIndex < 0)\r\n    return false;\r\n  const CArcInfoEx &arcInfo = codecs->Formats[MethodMode.FormatIndex];\r\n  UString typeExt = arcInfo.GetMainExt();\r\n  UString ext = typeExt;\r\n  if (SfxMode)\r\n    ext = kSFXExtension;\r\n  ArchivePath.BaseExtension = ext;\r\n  ArchivePath.VolExtension = typeExt;\r\n  ArchivePath.ParseFromPath(arcPath);\r\n  for (int i = 0; i < Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &uc = Commands[i];\r\n    uc.ArchivePath.BaseExtension = ext;\r\n    uc.ArchivePath.VolExtension = typeExt;\r\n    uc.ArchivePath.ParseFromPath(uc.UserArchivePath);\r\n  }\r\n  return true;\r\n}\r\n\r\n\r\nstatic HRESULT Compress(\r\n    CCodecs *codecs,\r\n    const CActionSet &actionSet, \r\n    IInArchive *archive,\r\n    const CCompressionMethodMode &compressionMethod,\r\n    CArchivePath &archivePath, \r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    bool shareForWrite,\r\n    bool stdInMode,\r\n    /* const UString & stdInFileName, */\r\n    bool stdOutMode,\r\n    const CObjectVector<CDirItem> &dirItems,\r\n    bool sfxMode,\r\n    const UString &sfxModule,\r\n    const CRecordVector<UInt64> &volumesSizes,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI *callback)\r\n{\r\n  CMyComPtr<IOutArchive> outArchive;\r\n  if(archive != NULL)\r\n  {\r\n    CMyComPtr<IInArchive> archive2 = archive;\r\n    HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);\r\n    if(result != S_OK)\r\n      throw kUpdateIsNotSupoorted;\r\n  }\r\n  else\r\n  {\r\n    RINOK(codecs->CreateOutArchive(compressionMethod.FormatIndex, outArchive));\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n  }\r\n  if (outArchive == 0)\r\n    throw kUpdateIsNotSupoorted;\r\n  \r\n  NFileTimeType::EEnum fileTimeType;\r\n  UInt32 value;\r\n  RINOK(outArchive->GetFileTimeType(&value));\r\n\r\n  switch(value)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n    case NFileTimeType::kDOS:\r\n    case NFileTimeType::kUnix:\r\n      fileTimeType = NFileTimeType::EEnum(value);\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n\r\n  CObjectVector<CUpdatePair> updatePairs;\r\n  GetUpdatePairInfoList(dirItems, archiveItems, fileTimeType, updatePairs); // must be done only once!!!\r\n  \r\n  CObjectVector<CUpdatePair2> updatePairs2;\r\n  UpdateProduce(updatePairs, actionSet, updatePairs2);\r\n\r\n  UInt32 numFiles = 0;\r\n  for (int i = 0; i < updatePairs2.Size(); i++)\r\n    if (updatePairs2[i].NewData)\r\n      numFiles++;\r\n  \r\n  RINOK(callback->SetNumFiles(numFiles));\r\n\r\n  \r\n  CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n  CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);\r\n  \r\n  updateCallbackSpec->ShareForWrite = shareForWrite;\r\n  updateCallbackSpec->StdInMode = stdInMode;\r\n  updateCallbackSpec->Callback = callback;\r\n  updateCallbackSpec->DirItems = &dirItems;\r\n  updateCallbackSpec->ArchiveItems = &archiveItems;\r\n  updateCallbackSpec->UpdatePairs = &updatePairs2;\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n\r\n  const UString &archiveName = archivePath.GetFinalPath();\r\n  if (!stdOutMode)\r\n  {\r\n    UString resultPath;\r\n    int pos;\r\n    if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))\r\n      throw 1417161;\r\n    NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));\r\n  }\r\n\r\n  COutFileStream *outStreamSpec = NULL;\r\n  COutMultiVolStream *volStreamSpec = NULL;\r\n\r\n  if (volumesSizes.Size() == 0)\r\n  {\r\n    if (stdOutMode)\r\n      outStream = new CStdOutFileStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      outStream = outStreamSpec;\r\n      bool isOK = false;\r\n      UString realPath;\r\n      for (int i = 0; i < (1 << 16); i++)\r\n      {\r\n        if (archivePath.Temp)\r\n        {\r\n          if (i > 0)\r\n          {\r\n            wchar_t s[32];\r\n            ConvertUInt64ToString(i, s);\r\n            archivePath.TempPostfix = s;\r\n          }\r\n          realPath = archivePath.GetTempPath();\r\n        }\r\n        else\r\n          realPath = archivePath.GetFinalPath();\r\n        if (outStreamSpec->Create(realPath, false))\r\n        {\r\n          tempFiles.Paths.Add(realPath);\r\n          isOK = true;\r\n          break;\r\n        }\r\n        if (::GetLastError() != ERROR_FILE_EXISTS)\r\n          break;\r\n        if (!archivePath.Temp)\r\n          break;\r\n      }\r\n      if (!isOK)\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (stdOutMode)\r\n      return E_FAIL;\r\n    volStreamSpec = new COutMultiVolStream;\r\n    outStream = volStreamSpec;\r\n    volStreamSpec->Sizes = volumesSizes;\r\n    volStreamSpec->Prefix = archivePath.GetFinalPath() + UString(L\".\");\r\n    volStreamSpec->TempFiles = &tempFiles;\r\n    volStreamSpec->Init();\r\n\r\n    /*\r\n    updateCallbackSpec->VolumesSizes = volumesSizes;\r\n    updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;\r\n    if (!archivePath.VolExtension.IsEmpty())\r\n      updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;\r\n    */\r\n  }\r\n\r\n  RINOK(SetProperties(outArchive, compressionMethod.Properties));\r\n\r\n  if (sfxMode)\r\n  {\r\n    CInFileStream *sfxStreamSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> sfxStream(sfxStreamSpec);\r\n    if (!sfxStreamSpec->Open(sfxModule))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"Can't open sfx module\";\r\n      errorInfo.FileName = sfxModule;\r\n      return E_FAIL;\r\n    }\r\n\r\n    CMyComPtr<ISequentialOutStream> sfxOutStream;\r\n    COutFileStream *outStreamSpec = NULL;\r\n    if (volumesSizes.Size() == 0)\r\n      sfxOutStream = outStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      sfxOutStream = outStreamSpec;\r\n      UString realPath = archivePath.GetFinalPath();\r\n      if (!outStreamSpec->Create(realPath, false))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    RINOK(CopyBlock(sfxStream, sfxOutStream));\r\n    if (outStreamSpec)\r\n    {\r\n      RINOK(outStreamSpec->Close());\r\n    }\r\n  }\r\n\r\n  HRESULT result = outArchive->UpdateItems(outStream, updatePairs2.Size(), updateCallback);\r\n  callback->Finilize();\r\n  RINOK(result);\r\n  if (outStreamSpec)\r\n    result = outStreamSpec->Close();\r\n  else if (volStreamSpec)\r\n    result = volStreamSpec->Close();\r\n  return result;\r\n}\r\n\r\nHRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,\r\n    IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    CObjectVector<CArchiveItem> &archiveItems)\r\n{\r\n  archiveItems.Clear();\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n  archiveItems.Reserve(numItems);\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    CArchiveItem ai;\r\n\r\n    RINOK(GetArchiveItemPath(archive, i, ai.Name));\r\n    RINOK(IsArchiveItemFolder(archive, i, ai.IsDirectory));\r\n    ai.Censored = censor.CheckPath(ai.Name.IsEmpty() ? defaultItemName : ai.Name, !ai.IsDirectory);\r\n    RINOK(GetArchiveItemFileTime(archive, i, \r\n        archiveFileInfo.LastWriteTime, ai.LastWriteTime));\r\n\r\n    CPropVariant propertySize;\r\n    RINOK(archive->GetProperty(i, kpidSize, &propertySize));\r\n    ai.SizeIsDefined = (propertySize.vt != VT_EMPTY);\r\n    if (ai.SizeIsDefined)\r\n      ai.Size = ConvertPropVariantToUInt64(propertySize);\r\n\r\n    ai.IndexInServer = i;\r\n    archiveItems.Add(ai);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nstatic HRESULT UpdateWithItemLists(\r\n    CCodecs *codecs,\r\n    CUpdateOptions &options,\r\n    IInArchive *archive, \r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    const CObjectVector<CDirItem> &dirItems,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &command = options.Commands[i];\r\n    if (options.StdOutMode)\r\n    {\r\n      RINOK(callback->StartArchive(0, archive != 0));\r\n    }\r\n    else\r\n    {\r\n      RINOK(callback->StartArchive(command.ArchivePath.GetFinalPath(), \r\n          i == 0 && options.UpdateArchiveItself && archive != 0));\r\n    }\r\n\r\n    RINOK(Compress(\r\n        codecs,\r\n        command.ActionSet, archive,\r\n        options.MethodMode, \r\n        command.ArchivePath, \r\n        archiveItems, \r\n        options.OpenShareForWrite,\r\n        options.StdInMode, \r\n        /* options.StdInFileName, */\r\n        options.StdOutMode,\r\n        dirItems, \r\n        options.SfxMode, options.SfxModule, \r\n        options.VolumesSizes,\r\n        tempFiles,\r\n        errorInfo, callback));\r\n\r\n    RINOK(callback->FinishArchive());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _WIN32\r\nclass CCurrentDirRestorer\r\n{\r\n  UString m_CurrentDirectory;\r\npublic:\r\n  CCurrentDirRestorer()\r\n    { NFile::NDirectory::MyGetCurrentDirectory(m_CurrentDirectory); }\r\n  ~CCurrentDirRestorer()\r\n    { RestoreDirectory();}\r\n  bool RestoreDirectory()\r\n    { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(m_CurrentDirectory)); }\r\n};\r\n#endif\r\n\r\nstruct CEnumDirItemUpdateCallback: public IEnumDirItemCallback\r\n{\r\n  IUpdateCallbackUI2 *Callback;\r\n  HRESULT CheckBreak() { return Callback->CheckBreak(); }\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor, \r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  if (options.StdOutMode && options.EMailMode)\r\n    return E_FAIL;\r\n\r\n  if (options.VolumesSizes.Size() > 0 && (options.EMailMode || options.SfxMode))\r\n    return E_NOTIMPL;\r\n\r\n  if (options.SfxMode)\r\n  {\r\n    CProperty property;\r\n    property.Name = L\"rsfx\";\r\n    property.Value = L\"on\";\r\n    options.MethodMode.Properties.Add(property);\r\n    if (options.SfxModule.IsEmpty())\r\n    {\r\n      errorInfo.Message = L\"sfx file is not specified\";\r\n      return E_FAIL;\r\n    }\r\n    UString name = options.SfxModule;\r\n    if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))\r\n    {\r\n      errorInfo.Message = L\"can't find specified sfx module\";\r\n      return E_FAIL;\r\n    }\r\n  }\r\n\r\n  const UString archiveName = options.ArchivePath.GetFinalPath();\r\n\r\n  UString defaultItemName;\r\n  NFind::CFileInfoW archiveFileInfo;\r\n\r\n  CArchiveLink archiveLink;\r\n  IInArchive *archive = 0;\r\n  if (NFind::FindFile(archiveName, archiveFileInfo))\r\n  {\r\n    if (archiveFileInfo.IsDirectory())\r\n      throw \"there is no such archive\";\r\n    if (options.VolumesSizes.Size() > 0)\r\n      return E_NOTIMPL;\r\n    HRESULT result = MyOpenArchive(codecs, archiveName, archiveLink, openCallback);\r\n    RINOK(callback->OpenResult(archiveName, result));\r\n    RINOK(result);\r\n    if (archiveLink.VolumePaths.Size() > 1)\r\n    {\r\n      errorInfo.SystemError = (DWORD)E_NOTIMPL;\r\n      errorInfo.Message = L\"Updating for multivolume archives is not implemented\";\r\n      return E_NOTIMPL;\r\n    }\r\n    archive = archiveLink.GetArchive();\r\n    defaultItemName = archiveLink.GetDefaultItemName();\r\n  }\r\n  else\r\n  {\r\n    /*\r\n    if (archiveType.IsEmpty())\r\n      throw \"type of archive is not specified\";\r\n    */\r\n  }\r\n\r\n  CObjectVector<CDirItem> dirItems;\r\n  if (options.StdInMode)\r\n  {\r\n    CDirItem item;\r\n    item.FullPath = item.Name = options.StdInFileName;\r\n    item.Size = (UInt64)(Int64)-1;\r\n    item.Attributes = 0;\r\n    SYSTEMTIME st;\r\n    FILETIME ft;\r\n    GetSystemTime(&st);\r\n    SystemTimeToFileTime(&st, &ft);\r\n    item.CreationTime = item.LastAccessTime = item.LastWriteTime = ft;\r\n    dirItems.Add(item);\r\n  }\r\n  else\r\n  {\r\n    bool needScanning = false;\r\n    for(int i = 0; i < options.Commands.Size(); i++)\r\n      if (options.Commands[i].ActionSet.NeedScanning())\r\n        needScanning = true;\r\n    if (needScanning)\r\n    {\r\n      CEnumDirItemUpdateCallback enumCallback;\r\n      enumCallback.Callback = callback;\r\n      RINOK(callback->StartScanning());\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(censor, dirItems, &enumCallback, errorPaths, errorCodes);\r\n      for (int i = 0; i < errorPaths.Size(); i++)\r\n      {\r\n        RINOK(callback->CanNotFindError(errorPaths[i], errorCodes[i]));\r\n      }\r\n      if(res != S_OK) \r\n      {\r\n        errorInfo.Message = L\"Scanning error\";\r\n        // errorInfo.FileName = errorPath;\r\n        return res;\r\n      }\r\n      RINOK(callback->FinishScanning());\r\n    }\r\n  }\r\n\r\n  UString tempDirPrefix;\r\n  bool usesTempDir = false;\r\n  \r\n  #ifdef _WIN32\r\n  NDirectory::CTempDirectoryW tempDirectory;\r\n  if (options.EMailMode && options.EMailRemoveAfter)\r\n  {\r\n    tempDirectory.Create(kTempFolderPrefix);\r\n    tempDirPrefix = tempDirectory.GetPath();\r\n    NormalizeDirPathPrefix(tempDirPrefix);\r\n    usesTempDir = true;\r\n  }\r\n  #endif\r\n\r\n  CTempFiles tempFiles;\r\n\r\n  bool createTempFile = false;\r\n  if(!options.StdOutMode && options.UpdateArchiveItself)\r\n  {\r\n    CArchivePath &ap = options.Commands[0].ArchivePath;\r\n    ap = options.ArchivePath;\r\n    // if ((archive != 0 && !usesTempDir) || !options.WorkingDir.IsEmpty())\r\n    if ((archive != 0 || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)\r\n    {\r\n      createTempFile = true;\r\n      ap.Temp = true;\r\n      if (!options.WorkingDir.IsEmpty())\r\n      {\r\n        ap.TempPrefix = options.WorkingDir;\r\n        NormalizeDirPathPrefix(ap.TempPrefix);\r\n      }\r\n    }\r\n  }\r\n\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CArchivePath &ap = options.Commands[i].ArchivePath;\r\n    if (usesTempDir)\r\n    {\r\n      // Check it\r\n      ap.Prefix = tempDirPrefix;\r\n      // ap.Temp = true;\r\n      // ap.TempPrefix = tempDirPrefix;\r\n    }\r\n    if (i > 0 || !createTempFile)\r\n    {\r\n      const UString &path = ap.GetFinalPath();\r\n      if (NFind::DoesFileExist(path))\r\n      {\r\n        errorInfo.SystemError = 0;\r\n        errorInfo.Message = L\"File already exists\";\r\n        errorInfo.FileName = path;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n\r\n  CObjectVector<CArchiveItem> archiveItems;\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(EnumerateInArchiveItems(censor, \r\n        archive, defaultItemName, archiveFileInfo, archiveItems));\r\n  }\r\n\r\n  RINOK(UpdateWithItemLists(codecs, options, archive, archiveItems, dirItems, \r\n      tempFiles, errorInfo, callback));\r\n\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(archiveLink.Close());\r\n    archiveLink.Release();\r\n  }\r\n\r\n  tempFiles.Paths.Clear();\r\n  if(createTempFile)\r\n  {\r\n    try\r\n    {\r\n      CArchivePath &ap = options.Commands[0].ArchivePath;\r\n      const UString &tempPath = ap.GetTempPath();\r\n      if (archive != NULL)\r\n        if (!NDirectory::DeleteFileAlways(archiveName))\r\n        {\r\n          errorInfo.SystemError = ::GetLastError();\r\n          errorInfo.Message = L\"delete file error\";\r\n          errorInfo.FileName = archiveName;\r\n          return E_FAIL;\r\n        }\r\n      if (!NDirectory::MyMoveFile(tempPath, archiveName))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.Message = L\"move file error\";\r\n        errorInfo.FileName = tempPath;\r\n        errorInfo.FileName2 = archiveName;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      throw;\r\n    }\r\n  }\r\n\r\n  #ifdef _WIN32\r\n  if (options.EMailMode)\r\n  {\r\n    NDLL::CLibrary mapiLib;\r\n    if (!mapiLib.Load(TEXT(\"Mapi32.dll\")))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not load Mapi32.dll\";\r\n      return E_FAIL;\r\n    }\r\n    LPMAPISENDDOCUMENTS fnSend = (LPMAPISENDDOCUMENTS)\r\n        mapiLib.GetProcAddress(\"MAPISendDocuments\");\r\n    if (fnSend == 0)\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not find MAPISendDocuments function\";\r\n      return E_FAIL;\r\n    }\r\n    UStringVector fullPaths;\r\n    int i;\r\n    for(i = 0; i < options.Commands.Size(); i++)\r\n    {\r\n      CArchivePath &ap = options.Commands[i].ArchivePath;\r\n      UString arcPath;\r\n      if(!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        return E_FAIL;\r\n      }\r\n      fullPaths.Add(arcPath);\r\n    }\r\n    CCurrentDirRestorer curDirRestorer;\r\n    for(i = 0; i < fullPaths.Size(); i++)\r\n    {\r\n      UString arcPath = fullPaths[i];\r\n      UString fileName = ExtractFileNameFromPath(arcPath);\r\n      AString path = GetAnsiString(arcPath);\r\n      AString name = GetAnsiString(fileName);\r\n      // Warning!!! MAPISendDocuments function changes Current directory\r\n      fnSend(0, \";\", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0); \r\n    }\r\n  }\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/Update.h",
    "content": "// Update.h\r\n\r\n#ifndef __UPDATE_H\r\n#define __UPDATE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"Property.h\"\r\n#include \"LoadCodecs.h\"\r\n\r\nstruct CArchivePath\r\n{\r\n  UString Prefix;   // path(folder) prefix including slash\r\n  UString Name; // base name\r\n  UString BaseExtension; // archive type extension or \"exe\" extension \r\n  UString VolExtension;  // archive type extension for volumes\r\n\r\n  bool Temp;\r\n  UString TempPrefix;  // path(folder) for temp location\r\n  UString TempPostfix;\r\n\r\n  CArchivePath(): Temp(false) {};\r\n  \r\n  void ParseFromPath(const UString &path)\r\n  {\r\n    SplitPathToParts(path, Prefix, Name);\r\n    if (Name.IsEmpty())\r\n      return;\r\n    int dotPos = Name.ReverseFind(L'.');\r\n    if (dotPos <= 0)\r\n      return;\r\n    if (dotPos == Name.Length() - 1)\r\n    {\r\n      Name = Name.Left(dotPos);\r\n      BaseExtension.Empty();\r\n      return;\r\n    }\r\n    if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0)\r\n    {\r\n      BaseExtension = Name.Mid(dotPos + 1);\r\n      Name = Name.Left(dotPos);\r\n    }\r\n    else\r\n      BaseExtension.Empty();\r\n  }\r\n\r\n  UString GetPathWithoutExt() const\r\n  {\r\n    return Prefix + Name;\r\n  }\r\n\r\n  UString GetFinalPath() const\r\n  {\r\n    UString path = GetPathWithoutExt();\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    return path;\r\n  }\r\n\r\n  \r\n  UString GetTempPath() const\r\n  {\r\n    UString path = TempPrefix + Name;\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    path += L\".tmp\";\r\n    path += TempPostfix;\r\n    return path; \r\n  }\r\n};\r\n\r\nstruct CUpdateArchiveCommand\r\n{\r\n  UString UserArchivePath;\r\n  CArchivePath ArchivePath;\r\n  NUpdateArchive::CActionSet ActionSet;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  int FormatIndex;\r\n  CObjectVector<CProperty> Properties;\r\n  CCompressionMethodMode(): FormatIndex(-1) {}\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  CCompressionMethodMode MethodMode;\r\n\r\n  CObjectVector<CUpdateArchiveCommand> Commands;\r\n  bool UpdateArchiveItself;\r\n  CArchivePath ArchivePath;\r\n  \r\n  bool SfxMode;\r\n  UString SfxModule;\r\n  \r\n  bool OpenShareForWrite;\r\n\r\n  bool StdInMode;\r\n  UString StdInFileName;\r\n  bool StdOutMode;\r\n  \r\n  bool EMailMode;\r\n  bool EMailRemoveAfter;\r\n  UString EMailAddress;\r\n\r\n  UString WorkingDir;\r\n\r\n  bool Init(const CCodecs *codecs, const UString &arcPath, const UString &arcType);\r\n\r\n  CUpdateOptions():\r\n    UpdateArchiveItself(true),\r\n    SfxMode(false),\r\n    StdInMode(false),\r\n    StdOutMode(false),\r\n    EMailMode(false),\r\n    EMailRemoveAfter(false),\r\n    OpenShareForWrite(false)\r\n      {};\r\n  CRecordVector<UInt64> VolumesSizes;\r\n};\r\n\r\nstruct CErrorInfo\r\n{\r\n  DWORD SystemError;\r\n  UString FileName;\r\n  UString FileName2;\r\n  UString Message;\r\n  // UStringVector ErrorPaths;\r\n  // CRecordVector<DWORD> ErrorCodes;\r\n  CErrorInfo(): SystemError(0) {};\r\n};\r\n\r\nstruct CUpdateErrorInfo: public CErrorInfo\r\n{\r\n};\r\n\r\n#define INTERFACE_IUpdateCallbackUI2(x) \\\r\n  INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \\\r\n  virtual HRESULT StartScanning() x; \\\r\n  virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT FinishScanning() x; \\\r\n  virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \\\r\n  virtual HRESULT FinishArchive() x; \\\r\n\r\nstruct IUpdateCallbackUI2: public IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI2(=0)\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor, \r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/UpdateAction.cpp",
    "content": "// UpdateAction.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n\r\nnamespace NUpdateArchive {\r\n\r\nconst CActionSet kAddActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kUpdateActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kFreshActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kSynchronizeActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n};\r\n\r\nconst CActionSet kDeleteActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/UpdateAction.h",
    "content": "// UpdateAction.h\r\n\r\n#ifndef __UPDATE_ACTION_H\r\n#define __UPDATE_ACTION_H\r\n\r\nnamespace NUpdateArchive {\r\n\r\n  namespace NPairState \r\n  {\r\n    const int kNumValues = 7;\r\n    enum EEnum\r\n    {\r\n      kNotMasked = 0,\r\n      kOnlyInArchive,\r\n      kOnlyOnDisk,\r\n      kNewInArchive,\r\n      kOldInArchive,\r\n      kSameFiles,\r\n      kUnknowNewerFiles\r\n    };\r\n  }\r\n  namespace NPairAction\r\n  {\r\n    enum EEnum\r\n    {\r\n      kIgnore = 0,\r\n      kCopy,\r\n      kCompress,\r\n      kCompressAsAnti\r\n    };\r\n  }\r\n  struct CActionSet\r\n  {\r\n    NPairAction::EEnum StateActions[NPairState::kNumValues];\r\n    bool NeedScanning() const\r\n    {\r\n      int i;\r\n      for (i = 0; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] == NPairAction::kCompress)\r\n          return true;\r\n      for (i = 1; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] != NPairAction::kIgnore)\r\n          return true;\r\n      return false;\r\n    }\r\n  };\r\n  extern const CActionSet kAddActionSet;\r\n  extern const CActionSet kUpdateActionSet;\r\n  extern const CActionSet kFreshActionSet;\r\n  extern const CActionSet kSynchronizeActionSet;\r\n  extern const CActionSet kDeleteActionSet;\r\n};\r\n\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp",
    "content": "// UpdateCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCArchiveUpdateCallback::CArchiveUpdateCallback():\r\n  Callback(0),\r\n  ShareForWrite(false),\r\n  StdInMode(false),\r\n  DirItems(0),\r\n  ArchiveItems(0),\r\n  UpdatePairs(0)\r\n  {}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetTotal(size);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\n\r\n/*\r\nSTATPROPSTG kProperties[] = \r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidIsFolder, VT_BOOL},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidLastAccessTime, VT_FILETIME},\r\n  { NULL, kpidCreationTime, VT_FILETIME},\r\n  { NULL, kpidLastWriteTime, VT_FILETIME},\r\n  { NULL, kpidAttributes, VT_UI4},\r\n  { NULL, kpidIsAnti, VT_BOOL}\r\n};\r\n*/\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)\r\n{\r\n  return E_NOTIMPL;\r\n  /*\r\n  return CStatPropEnumerator::CreateEnumerator(kProperties, \r\n      sizeof(kProperties) / sizeof(kProperties[0]), enumerator);\r\n  */\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  COM_TRY_BEGIN\r\n  RINOK(Callback->CheckBreak());\r\n  const CUpdatePair2 &updatePair = (*UpdatePairs)[index];\r\n  if(newData != NULL)\r\n    *newData = BoolToInt(updatePair.NewData);\r\n  if(newProperties != NULL)\r\n    *newProperties = BoolToInt(updatePair.NewProperties);\r\n  if(indexInArchive != NULL)\r\n  {\r\n    if (updatePair.ExistInArchive)\r\n    {\r\n      if (ArchiveItems == 0)\r\n        *indexInArchive = updatePair.ArchiveItemIndex;\r\n      else\r\n        *indexInArchive = (*ArchiveItems)[updatePair.ArchiveItemIndex].IndexInServer;\r\n    }\r\n    else\r\n      *indexInArchive = UInt32(-1);\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &updatePair = (*UpdatePairs)[index];\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    propVariant = updatePair.IsAnti;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  if (updatePair.IsAnti)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidIsFolder:\r\n      case kpidPath:\r\n        break;\r\n      case kpidSize:\r\n        propVariant = (UInt64)0;\r\n        propVariant.Detach(value);\r\n        return S_OK;\r\n      default:\r\n        propVariant.Detach(value);\r\n        return S_OK;\r\n    }\r\n  }\r\n  \r\n  if(updatePair.ExistOnDisk)\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[updatePair.DirItemIndex];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:\r\n        propVariant = dirItem.Name;\r\n        break;\r\n      case kpidIsFolder:\r\n        propVariant = dirItem.IsDirectory();\r\n        break;\r\n      case kpidSize:\r\n        propVariant = dirItem.Size;\r\n        break;\r\n      case kpidAttributes:\r\n        propVariant = dirItem.Attributes;\r\n        break;\r\n      case kpidLastAccessTime:\r\n        propVariant = dirItem.LastAccessTime;\r\n        break;\r\n      case kpidCreationTime:\r\n        propVariant = dirItem.CreationTime;\r\n        break;\r\n      case kpidLastWriteTime:\r\n        propVariant = dirItem.LastWriteTime;\r\n        break;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (propID == kpidPath)\r\n    {\r\n      if (updatePair.NewNameIsDefined)\r\n      {\r\n        propVariant = updatePair.NewName;\r\n        propVariant.Detach(value);\r\n        return S_OK;\r\n      }\r\n    }\r\n    if (updatePair.ExistInArchive && Archive)\r\n    {\r\n      UInt32 indexInArchive;\r\n      if (ArchiveItems == 0)\r\n        indexInArchive = updatePair.ArchiveItemIndex;\r\n      else\r\n        indexInArchive = (*ArchiveItems)[updatePair.ArchiveItemIndex].IndexInServer;\r\n      return Archive->GetProperty(indexInArchive, propID, value);\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &updatePair = (*UpdatePairs)[index];\r\n  if(!updatePair.NewData)\r\n    return E_FAIL;\r\n  \r\n  RINOK(Callback->CheckBreak());\r\n  RINOK(Callback->Finilize());\r\n\r\n  if(updatePair.IsAnti)\r\n  {\r\n    return Callback->GetStream((*ArchiveItems)[updatePair.ArchiveItemIndex].Name, true);\r\n  }\r\n  const CDirItem &dirItem = (*DirItems)[updatePair.DirItemIndex];\r\n  RINOK(Callback->GetStream(dirItem.Name, false));\r\n \r\n  if(dirItem.IsDirectory())\r\n    return S_OK;\r\n\r\n  if (StdInMode)\r\n  {\r\n    CStdInFileStream *inStreamSpec = new CStdInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  else\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if(!inStreamSpec->OpenShared(path, ShareForWrite))\r\n    {\r\n      return Callback->OpenFileError(path, ::GetLastError());\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetOperationResult(operationResult);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if(!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->CryptoGetTextPassword2(passwordIsDefined, password);\r\n  COM_TRY_END\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/UpdateCallback.h",
    "content": "// UpdateCallback.h\r\n\r\n#ifndef __UPDATECALLBACK_H\r\n#define __UPDATECALLBACK_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/UpdatePair.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#define INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT SetTotal(UInt64 size) x; \\\r\n  virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \\\r\n  virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x; \\\r\n  virtual HRESULT CheckBreak() x; \\\r\n  virtual HRESULT Finilize() x; \\\r\n  virtual HRESULT SetNumFiles(UInt64 numFiles) x; \\\r\n  virtual HRESULT GetStream(const wchar_t *name, bool isAnti) x; \\\r\n  virtual HRESULT OpenFileError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT SetOperationResult(Int32 operationResult) x; \\\r\n  virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x; \\\r\n\r\n  // virtual HRESULT CloseProgress() { return S_OK; };\r\n\r\nstruct IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI(=0)\r\n};\r\n\r\nclass CArchiveUpdateCallback: \r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveUpdateCallback2, \r\n      ICryptoGetTextPassword2,\r\n      ICompressProgressInfo)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IUpdateCallback\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);  \r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  IUpdateCallbackUI *Callback;\r\n\r\n  UString DirPrefix;\r\n  bool ShareForWrite;\r\n  bool StdInMode;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n  const CObjectVector<CArchiveItem> *ArchiveItems;\r\n  const CObjectVector<CUpdatePair2> *UpdatePairs;\r\n  CMyComPtr<IInArchive> Archive;\r\n\r\n  CArchiveUpdateCallback();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/UpdatePair.cpp",
    "content": "// UpdatePair.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <time.h>\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"UpdatePair.h\"\r\n#include \"SortUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nstatic int MyCompareTime(NFileTimeType::EEnum fileTimeType, \r\n    const FILETIME &time1, const FILETIME &time2)\r\n{\r\n  switch(fileTimeType)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n      return ::CompareFileTime(&time1, &time2);\r\n    case NFileTimeType::kUnix:\r\n      {\r\n        UInt32 unixTime1, unixTime2;\r\n        if (!FileTimeToUnixTime(time1, unixTime1))\r\n        {\r\n          unixTime1 = 0;\r\n          // throw 4191614;\r\n        }\r\n        if (!FileTimeToUnixTime(time2, unixTime2))\r\n        {\r\n          unixTime2 = 0;\r\n          // throw 4191615;\r\n        }\r\n        return MyCompare(unixTime1, unixTime2);\r\n      }\r\n    case NFileTimeType::kDOS:\r\n      {\r\n        UInt32 dosTime1, dosTime2;\r\n        FileTimeToDosTime(time1, dosTime1);\r\n        FileTimeToDosTime(time2, dosTime2);\r\n        /*\r\n        if (!FileTimeToDosTime(time1, dosTime1))\r\n          throw 4191616;\r\n        if (!FileTimeToDosTime(time2, dosTime2))\r\n          throw 4191617;\r\n        */\r\n        return MyCompare(dosTime1, dosTime2);\r\n      }\r\n  }\r\n  throw 4191618;\r\n}\r\n\r\nstatic const wchar_t *kDuplicateFileNameMessage = L\"Duplicate filename:\";\r\n\r\n/*\r\nstatic const char *kNotCensoredCollisionMessaged = \"Internal file name collision:\\n\";\r\nstatic const char *kSameTimeChangedSizeCollisionMessaged = \r\n    \"Collision between files with same date/time and different sizes:\\n\";\r\n*/\r\n\r\nstatic void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)\r\n{\r\n  for(int i = 0; i + 1 < indices.Size(); i++)\r\n    if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)\r\n    {\r\n      UString message = kDuplicateFileNameMessage;\r\n      message += L\"\\n\";\r\n      message += strings[indices[i]];\r\n      message += L\"\\n\";\r\n      message += strings[indices[i + 1]];\r\n      throw message;\r\n    }\r\n}\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CObjectVector<CDirItem> &dirItems, \r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CObjectVector<CUpdatePair> &updatePairs)\r\n{\r\n  CIntVector dirIndices, archiveIndices;\r\n  UStringVector dirNames, archiveNames;\r\n  \r\n  int numDirItems = dirItems.Size(); \r\n  int i;\r\n  for(i = 0; i < numDirItems; i++)\r\n    dirNames.Add(dirItems[i].Name);\r\n  SortFileNames(dirNames, dirIndices);\r\n  TestDuplicateString(dirNames, dirIndices);\r\n\r\n  int numArchiveItems = archiveItems.Size(); \r\n  for(i = 0; i < numArchiveItems; i++)\r\n    archiveNames.Add(archiveItems[i].Name);\r\n  SortFileNames(archiveNames, archiveIndices);\r\n  TestDuplicateString(archiveNames, archiveIndices);\r\n  \r\n  int dirItemIndex = 0, archiveItemIndex = 0; \r\n  CUpdatePair pair;\r\n  while(dirItemIndex < numDirItems && archiveItemIndex < numArchiveItems)\r\n  {\r\n    int dirItemIndex2 = dirIndices[dirItemIndex],\r\n        archiveItemIndex2 = archiveIndices[archiveItemIndex]; \r\n    const CDirItem &dirItem = dirItems[dirItemIndex2];\r\n    const CArchiveItem &archiveItem = archiveItems[archiveItemIndex2];\r\n    int compareResult = CompareFileNames(dirItem.Name, archiveItem.Name);\r\n    if (compareResult < 0)\r\n    {\r\n        pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n        pair.DirItemIndex = dirItemIndex2;\r\n        dirItemIndex++;\r\n    }\r\n    else if (compareResult > 0)\r\n    {\r\n      pair.State = archiveItem.Censored ? \r\n        NUpdateArchive::NPairState::kOnlyInArchive: NUpdateArchive::NPairState::kNotMasked;\r\n      pair.ArchiveItemIndex = archiveItemIndex2;\r\n      archiveItemIndex++;\r\n    }\r\n    else\r\n    {\r\n      if (!archiveItem.Censored)\r\n        throw 1082022;; // TTString(kNotCensoredCollisionMessaged + dirItem.Name);\r\n      pair.DirItemIndex = dirItemIndex2;\r\n      pair.ArchiveItemIndex = archiveItemIndex2;\r\n      switch (MyCompareTime(fileTimeType, dirItem.LastWriteTime, archiveItem.LastWriteTime))\r\n      {\r\n        case -1:\r\n          pair.State = NUpdateArchive::NPairState::kNewInArchive;\r\n          break;\r\n        case 1:\r\n          pair.State = NUpdateArchive::NPairState::kOldInArchive;\r\n          break;\r\n        default:\r\n          if (archiveItem.SizeIsDefined)\r\n            if (dirItem.Size != archiveItem.Size)\r\n              // throw 1082034; // kSameTimeChangedSizeCollisionMessaged;\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n            else\r\n              pair.State = NUpdateArchive::NPairState::kSameFiles;\r\n          else\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n      }\r\n      dirItemIndex++;\r\n      archiveItemIndex++;\r\n    }\r\n    updatePairs.Add(pair);\r\n  }\r\n  for(;dirItemIndex < numDirItems; dirItemIndex++)\r\n  {\r\n    pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n    pair.DirItemIndex = dirIndices[dirItemIndex];\r\n    updatePairs.Add(pair);\r\n  }\r\n  for(;archiveItemIndex < numArchiveItems; archiveItemIndex++)\r\n  {\r\n    int archiveItemIndex2 = archiveIndices[archiveItemIndex]; \r\n    const CArchiveItem &archiveItem = archiveItems[archiveItemIndex2];\r\n    pair.State = archiveItem.Censored ?  \r\n        NUpdateArchive::NPairState::kOnlyInArchive: NUpdateArchive::NPairState::kNotMasked;\r\n    pair.ArchiveItemIndex = archiveItemIndex2;\r\n    updatePairs.Add(pair);\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/UpdatePair.h",
    "content": "// UpdatePair.h\r\n\r\n#ifndef __UPDATE_PAIR_H\r\n#define __UPDATE_PAIR_H\r\n\r\n#include \"DirItem.h\"\r\n#include \"UpdateAction.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CUpdatePair\r\n{\r\n  NUpdateArchive::NPairState::EEnum State;\r\n  int ArchiveItemIndex;\r\n  int DirItemIndex;\r\n};\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CObjectVector<CDirItem> &dirItems,\r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CObjectVector<CUpdatePair> &updatePairs);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp",
    "content": "// UpdateProduce.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateProduce.h\"\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic const char *kUpdateActionSetCollision =\r\n    \"Internal collision in update action set\";\r\n\r\nvoid UpdateProduce(\r\n    const CObjectVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CObjectVector<CUpdatePair2> &operationChain)\r\n{\r\n  for(int i = 0; i < updatePairs.Size(); i++)\r\n  {\r\n    // CUpdateArchiveRange aRange;\r\n    const CUpdatePair &pair = updatePairs[i];\r\n\r\n    CUpdatePair2 pair2;\r\n    pair2.IsAnti = false;\r\n    pair2.ArchiveItemIndex = pair.ArchiveItemIndex;\r\n    pair2.DirItemIndex = pair.DirItemIndex;\r\n    pair2.ExistInArchive = (pair.State != NPairState::kOnlyOnDisk);\r\n    pair2.ExistOnDisk = (pair.State != NPairState::kOnlyInArchive && pair.State != NPairState::kNotMasked);\r\n    switch(actionSet.StateActions[pair.State])\r\n    {\r\n      case NPairAction::kIgnore:\r\n        /*\r\n        if (pair.State != NPairState::kOnlyOnDisk)\r\n          IgnoreArchiveItem(m_ArchiveItems[pair.ArchiveItemIndex]);\r\n        // cout << \"deleting\";\r\n        */\r\n        break;\r\n      case NPairAction::kCopy:\r\n        {\r\n          if (pair.State == NPairState::kOnlyOnDisk)\r\n            throw kUpdateActionSetCollision;\r\n          pair2.NewData = pair2.NewProperties = false;\r\n          operationChain.Add(pair2);\r\n          break;\r\n        }\r\n      case NPairAction::kCompress:\r\n        {\r\n          if (pair.State == NPairState::kOnlyInArchive || \r\n            pair.State == NPairState::kNotMasked)\r\n            throw kUpdateActionSetCollision;\r\n          pair2.NewData = pair2.NewProperties = true;\r\n          operationChain.Add(pair2);\r\n          break;\r\n        }\r\n      case NPairAction::kCompressAsAnti:\r\n        {\r\n          pair2.IsAnti = true;\r\n          pair2.NewData = pair2.NewProperties = true;\r\n          operationChain.Add(pair2);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/UpdateProduce.h",
    "content": "// UpdateProduce.h\r\n\r\n#ifndef __UPDATE_PRODUCE_H\r\n#define __UPDATE_PRODUCE_H\r\n\r\n#include \"UpdatePair.h\"\r\n\r\nstruct CUpdatePair2\r\n{\r\n  // bool OperationIsCompress;\r\n  bool NewData;\r\n  bool NewProperties;\r\n\r\n  bool ExistInArchive;\r\n  bool ExistOnDisk;\r\n  bool IsAnti;\r\n  int ArchiveItemIndex;\r\n  int DirItemIndex;\r\n\r\n  bool NewNameIsDefined;\r\n  UString NewName;\r\n\r\n  CUpdatePair2(): NewNameIsDefined(false) {}\r\n};\r\n\r\nvoid UpdateProduce(\r\n    const CObjectVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CObjectVector<CUpdatePair2> &operationChain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/WorkDir.cpp",
    "content": "// WorkDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"WorkDir.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nstatic inline UINT GetCurrentCodePage() \r\n  { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)\r\n{\r\n  NWorkDir::NMode::EEnum mode = workDirInfo.Mode;\r\n  if (workDirInfo.ForRemovableOnly)\r\n  {\r\n    mode = NWorkDir::NMode::kCurrent;\r\n    UString prefix = path.Left(3);\r\n    if (prefix[1] == L':' && prefix[2] == L'\\\\')\r\n    {\r\n      UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));\r\n      if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)\r\n        mode = workDirInfo.Mode;\r\n    }\r\n    /*\r\n    CParsedPath parsedPath;\r\n    parsedPath.ParsePath(archiveName);\r\n    UINT driveType = GetDriveType(parsedPath.Prefix);\r\n    if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))\r\n      mode = NZipSettings::NWorkDir::NMode::kCurrent;\r\n    */\r\n  }\r\n  switch(mode)\r\n  {\r\n    case NWorkDir::NMode::kCurrent:\r\n    {\r\n      return ExtractDirPrefixFromPath(path);\r\n    }\r\n    case NWorkDir::NMode::kSpecified:\r\n    {\r\n      UString tempDir = workDirInfo.Path;\r\n      NormalizeDirPathPrefix(tempDir);\r\n      return tempDir;\r\n    }\r\n    default:\r\n    {\r\n      UString tempDir;\r\n      if(!NFile::NDirectory::MyGetTempPath(tempDir))\r\n        throw 141717;\r\n      return tempDir;\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/WorkDir.h",
    "content": "// WorkDir.h\r\n\r\n#ifndef __WORKDIR_H\r\n#define __WORKDIR_H\r\n\r\n#include \"ZipRegistry.h\"\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Common/ZipRegistry.h",
    "content": "// ZipRegistry.h\r\n\r\n#ifndef __ZIPREGISTRY_H\r\n#define __ZIPREGISTRY_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"ExtractMode.h\"\r\n\r\nnamespace NExtract\r\n{\r\n  struct CInfo\r\n  {\r\n    NPathMode::EEnum PathMode;\r\n    NOverwriteMode::EEnum OverwriteMode;\r\n    UStringVector Paths;\r\n    bool ShowPassword;\r\n  };\r\n}\r\n\r\nnamespace NCompression {\r\n  \r\n  struct CFormatOptions\r\n  {\r\n    CSysString FormatID;\r\n    UString Options;\r\n    UString Method;\r\n    UString EncryptionMethod;\r\n    UInt32 Level;\r\n    UInt32 Dictionary;\r\n    UInt32 Order;\r\n    UInt32 BlockLogSize;\r\n    UInt32 NumThreads;\r\n    void ResetForLevelChange() \r\n    { \r\n      BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1); \r\n      Method.Empty();\r\n      // EncryptionMethod.Empty();\r\n      // Options.Empty();\r\n    }\r\n    CFormatOptions() { ResetForLevelChange(); }\r\n  };\r\n\r\n  struct CInfo\r\n  {\r\n    UStringVector HistoryArchives;\r\n    UInt32 Level;\r\n    UString ArchiveType;\r\n\r\n    CObjectVector<CFormatOptions> FormatOptionsVector;\r\n\r\n    bool ShowPassword;\r\n    bool EncryptHeaders;\r\n  };\r\n}\r\n\r\nnamespace NWorkDir{\r\n  \r\n  namespace NMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kSystem,\r\n      kCurrent,\r\n      kSpecified\r\n    };\r\n  }\r\n  struct CInfo\r\n  {\r\n    NMode::EEnum Mode;\r\n    UString Path;\r\n    bool ForRemovableOnly;\r\n    void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }\r\n    void SetDefault()\r\n    {\r\n      Mode = NMode::kSystem;\r\n      Path.Empty();\r\n      SetForRemovableOnlyDefault();\r\n    }\r\n  };\r\n}\r\n\r\nvoid SaveExtractionInfo(const NExtract::CInfo &info);\r\nvoid ReadExtractionInfo(NExtract::CInfo &info);\r\n\r\nvoid SaveCompressionInfo(const NCompression::CInfo &info);\r\nvoid ReadCompressionInfo(NCompression::CInfo &info);\r\n\r\nvoid SaveWorkDirInfo(const NWorkDir::CInfo &info);\r\nvoid ReadWorkDirInfo(NWorkDir::CInfo &info);\r\n\r\nvoid SaveCascadedMenu(bool enabled);\r\nbool ReadCascadedMenu();\r\n\r\nvoid SaveContextMenuStatus(UInt32 value);\r\nbool ReadContextMenuStatus(UInt32 &value);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/ConsoleClose.cpp",
    "content": "// ConsoleClose.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n\r\nstatic int g_BreakCounter = 0;\r\nstatic const int kBreakAbortThreshold = 2;\r\n\r\nnamespace NConsoleClose {\r\n\r\nstatic BOOL WINAPI HandlerRoutine(DWORD ctrlType)\r\n{\r\n  if (ctrlType == CTRL_LOGOFF_EVENT)\r\n  {\r\n    // printf(\"\\nCTRL_LOGOFF_EVENT\\n\");\r\n    return TRUE;\r\n  }\r\n\r\n  g_BreakCounter++;\r\n  if (g_BreakCounter < kBreakAbortThreshold)\r\n    return TRUE;\r\n  return FALSE;\r\n  /*\r\n  switch(ctrlType)\r\n  {\r\n    case CTRL_C_EVENT:\r\n    case CTRL_BREAK_EVENT:\r\n      if (g_BreakCounter < kBreakAbortThreshold)\r\n      return TRUE;\r\n  }\r\n  return FALSE;\r\n  */\r\n}\r\n\r\nbool TestBreakSignal()\r\n{\r\n  /*\r\n  if (g_BreakCounter > 0)\r\n    return true;\r\n  */\r\n  return (g_BreakCounter > 0);\r\n}\r\n\r\nvoid CheckCtrlBreak()\r\n{\r\n  if (TestBreakSignal())\r\n    throw CCtrlBreakException();\r\n}\r\n\r\nCCtrlHandlerSetter::CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\nCCtrlHandlerSetter::~CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/ConsoleClose.h",
    "content": "// ConsoleCloseUtils.h\r\n\r\n#ifndef __CONSOLECLOSEUTILS_H\r\n#define __CONSOLECLOSEUTILS_H\r\n\r\nnamespace NConsoleClose {\r\n\r\nbool TestBreakSignal();\r\n\r\nclass CCtrlHandlerSetter\r\n{\r\npublic:\r\n  CCtrlHandlerSetter();\r\n  virtual ~CCtrlHandlerSetter();\r\n};\r\n\r\nclass CCtrlBreakException \r\n{};\r\n\r\nvoid CheckCtrlBreak();\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UserInputUtils.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Error.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\n// static const char *kCantAutoRename = \"can not create file with auto name\\n\";\r\n// static const char *kCantRenameFile = \"can not rename existing file\\n\";\r\n// static const char *kCantDeleteOutputFile = \"can not delete output file \";\r\nstatic const char *kError = \"ERROR: \";\r\nstatic const char *kMemoryExceptionMessage = \"Can't allocate required memory!\";\r\n\r\nstatic const char *kProcessing = \"Processing archive: \";\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kNoFiles = \"No files to process\";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCrcFailed = \"CRC Failed\";\r\nstatic const char *kCrcFailedEncrypted = \"CRC Failed in encrypted file. Wrong password?\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kDataErrorEncrypted = \"Data Error in encrypted file. Wrong password?\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::AskOverwrite(\r\n    const wchar_t *existName, const FILETIME *, const UInt64 *,\r\n    const wchar_t *newName, const FILETIME *, const UInt64 *,\r\n    Int32 *answer)\r\n{\r\n  (*OutStream) << \"file \" << existName << \r\n    \"\\nalready exists. Overwrite with \" << endl;\r\n  (*OutStream) << newName;\r\n  \r\n  NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);\r\n  \r\n  switch(overwriteAnswer)\r\n  {\r\n    case NUserAnswerMode::kQuit:\r\n      return E_ABORT;\r\n    case NUserAnswerMode::kNo:\r\n      *answer = NOverwriteAnswer::kNo;\r\n      break;\r\n    case NUserAnswerMode::kNoAll:\r\n      *answer = NOverwriteAnswer::kNoToAll;\r\n      break;\r\n    case NUserAnswerMode::kYesAll:\r\n      *answer = NOverwriteAnswer::kYesToAll;\r\n      break;\r\n    case NUserAnswerMode::kYes:\r\n      *answer = NOverwriteAnswer::kYes;\r\n      break;\r\n    case NUserAnswerMode::kAutoRename:\r\n      *answer = NOverwriteAnswer::kAutoRename;\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position)\r\n{\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      (*OutStream) << kExtractingString;\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kTest:\r\n      (*OutStream) << kTestingString;\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kSkip:\r\n      (*OutStream) << kSkippingString;\r\n      break;\r\n  };\r\n  (*OutStream) << name;\r\n  if (position != 0)\r\n    (*OutStream) << \" <\" << *position << \">\";\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)\r\n{\r\n  (*OutStream) << message << endl;\r\n  NumFileErrorsInCurrentArchive++;\r\n  NumFileErrors++;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumFileErrorsInCurrentArchive++;\r\n      NumFileErrors++;\r\n      (*OutStream) << \"     \";\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          (*OutStream) << kUnsupportedMethod;\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError);\r\n          break;\r\n        default:\r\n          (*OutStream) << kUnknownError;\r\n      }\r\n    }\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream); \r\n    PasswordIsDefined = true;\r\n  }\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)\r\n{\r\n  NumArchives++;\r\n  NumFileErrorsInCurrentArchive = 0;\r\n  (*OutStream) << endl << kProcessing << name << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT result, bool encrypted)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n  {\r\n    (*OutStream) << \"Error: \";\r\n    if (encrypted)\r\n      (*OutStream) << \"Can not open encrypted archive. Wrong password?\";\r\n    else\r\n      (*OutStream) << \"Can not open file as archive\";\r\n    (*OutStream) << endl;\r\n    NumArchiveErrors++;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nHRESULT CExtractCallbackConsole::ThereAreNoFiles()\r\n{\r\n  (*OutStream) << endl << kNoFiles << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)\r\n{\r\n  if (result == S_OK)\r\n  {\r\n    (*OutStream) << endl;\r\n    if (NumFileErrorsInCurrentArchive == 0)\r\n      (*OutStream) << kEverythingIsOk << endl;\r\n    else \r\n    {\r\n      NumArchiveErrors++;\r\n      (*OutStream) << \"Sub items Errors: \" << NumFileErrorsInCurrentArchive << endl;\r\n    }\r\n  }\r\n  if (result == S_OK)\r\n    return result;\r\n  NumArchiveErrors++;\r\n  if (result == E_ABORT || result == ERROR_DISK_FULL)\r\n    return result;\r\n  (*OutStream) << endl << kError;\r\n  if (result == E_OUTOFMEMORY)\r\n    (*OutStream) << kMemoryExceptionMessage;\r\n  else\r\n  {\r\n    UString message;\r\n    NError::MyFormatMessage(result, message);\r\n    (*OutStream) << message;\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::SetPassword(const UString &password)\r\n{\r\n  PasswordIsDefined = true;\r\n  Password = password;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.h",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#ifndef __EXTRACTCALLBACKCONSOLE_H\r\n#define __EXTRACTCALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../Common/ArchiveExtractCallback.h\"\r\n\r\nclass CExtractCallbackConsole: \r\n  public IExtractCallbackUI,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IFolderArchiveExtractCallback, ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(UInt64 total);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IFolderArchiveExtractCallback\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer);\r\n  STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position);\r\n\r\n  STDMETHOD(MessageError)(const wchar_t *message);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  HRESULT BeforeOpen(const wchar_t *name);\r\n  HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);\r\n  HRESULT ThereAreNoFiles();\r\n  HRESULT ExtractResult(HRESULT result);\r\n\r\n  HRESULT SetPassword(const UString &password);\r\n\r\npublic:\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  \r\n  UInt64 NumArchives;\r\n  UInt64 NumArchiveErrors;\r\n  UInt64 NumFileErrors;\r\n  UInt64 NumFileErrorsInCurrentArchive;\r\n\r\n  CStdOutStream *OutStream;\r\n\r\n  void Init()\r\n  {\r\n    NumArchives = 0;\r\n    NumArchiveErrors = 0;\r\n    NumFileErrors = 0;\r\n    NumFileErrorsInCurrentArchive = 0;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/List.cpp",
    "content": "// List.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"List.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../Common/PropIDUtils.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstruct CPropIdToName\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n};\r\n\r\nstatic CPropIdToName kPropIdToName[] =  \r\n{\r\n  { kpidPath, L\"Path\" },\r\n  { kpidName, L\"Name\" },\r\n  { kpidIsFolder, L\"Folder\" }, \r\n  { kpidSize, L\"Size\" },\r\n  { kpidPackedSize, L\"Packed Size\" },\r\n  { kpidAttributes, L\"Attributes\" },\r\n  { kpidCreationTime, L\"Created\" },\r\n  { kpidLastAccessTime, L\"Accessed\" },\r\n  { kpidLastWriteTime, L\"Modified\" },\r\n  { kpidSolid, L\"Solid\" },\r\n  { kpidCommented, L\"Commented\" },\r\n  { kpidEncrypted, L\"Encrypted\" },\r\n  { kpidSplitBefore, L\"Split Before\" },\r\n  { kpidSplitAfter, L\"Split After\" },\r\n  { kpidDictionarySize, L\"Dictionary Size\" },\r\n  { kpidCRC, L\"CRC\" },\r\n  { kpidType, L\"Type\" },\r\n  { kpidIsAnti, L\"Anti\" },\r\n  { kpidMethod, L\"Method\" },\r\n  { kpidHostOS, L\"Host OS\" },\r\n  { kpidFileSystem, L\"File System\" },\r\n  { kpidUser, L\"User\" },\r\n  { kpidGroup, L\"Group\" },\r\n  { kpidBlock, L\"Block\" },\r\n  { kpidComment, L\"Comment\" },\r\n  { kpidPosition, L\"Position\" },\r\n  { kpidPrefix, L\"Prefix\" },\r\n  { kpidNumSubFolders, L\"Folders\" },\r\n  { kpidNumSubFiles, L\"Files\" },\r\n  { kpidUnpackVer, L\"Version\" },\r\n  { kpidVolume, L\"Volume\" },\r\n  { kpidIsVolume, L\"Multivolume\" },\r\n  { kpidOffset, L\"Offset\" },\r\n  { kpidLinks, L\"Links\" },\r\n  { kpidNumBlocks, L\"Blocks\" },\r\n  { kpidNumVolumes, L\"Volumes\" }\r\n};\r\n\r\nstatic const char kEmptyAttributeChar = '.';\r\nstatic const char kDirectoryAttributeChar = 'D';\r\nstatic const char kReadonlyAttributeChar  = 'R';\r\nstatic const char kHiddenAttributeChar    = 'H';\r\nstatic const char kSystemAttributeChar    = 'S';\r\nstatic const char kArchiveAttributeChar   = 'A';\r\n\r\nstatic const char *kListing = \"Listing archive: \";\r\nstatic const wchar_t *kFilesMessage = L\"files\";\r\nstatic const wchar_t *kDirsMessage = L\"folders\";\r\n\r\nstatic void GetAttributesString(DWORD wa, bool directory, char *s)\r\n{\r\n  s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || directory) ? \r\n      kDirectoryAttributeChar: kEmptyAttributeChar;\r\n  s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0)? \r\n      kReadonlyAttributeChar: kEmptyAttributeChar;\r\n  s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? \r\n      kHiddenAttributeChar: kEmptyAttributeChar;\r\n  s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? \r\n      kSystemAttributeChar: kEmptyAttributeChar;\r\n  s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? \r\n      kArchiveAttributeChar: kEmptyAttributeChar;\r\n  s[5] = '\\0';\r\n}\r\n\r\nenum EAdjustment\r\n{\r\n  kLeft,\r\n  kCenter,\r\n  kRight\r\n};\r\n\r\nstruct CFieldInfo\r\n{\r\n  PROPID PropID;\r\n  UString Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nstruct CFieldInfoInit\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nCFieldInfoInit kStandardFieldTable[] = \r\n{\r\n  { kpidLastWriteTime, L\"   Date      Time\", kLeft, kLeft, 0, 19 },\r\n  { kpidAttributes, L\"Attr\", kRight, kCenter, 1, 5 },\r\n  { kpidSize, L\"Size\", kRight, kRight, 1, 12 },\r\n  { kpidPackedSize, L\"Compressed\", kRight, kRight, 1, 12 },\r\n  { kpidPath, L\"Name\", kLeft, kLeft, 2, 24 }\r\n};\r\n\r\nvoid PrintSpaces(int numSpaces)\r\n{\r\n  for (int i = 0; i < numSpaces; i++)\r\n    g_StdOut << ' ';\r\n}\r\n\r\nvoid PrintString(EAdjustment adjustment, int width, const UString &textString)\r\n{\r\n  const int numSpaces = width - textString.Length();\r\n  int numLeftSpaces = 0;\r\n  switch (adjustment)\r\n  {\r\n    case kLeft:\r\n      numLeftSpaces = 0;\r\n      break;\r\n    case kCenter:\r\n      numLeftSpaces = numSpaces / 2;\r\n      break;\r\n    case kRight:\r\n      numLeftSpaces = numSpaces;\r\n      break;\r\n  }\r\n  PrintSpaces(numLeftSpaces);\r\n  g_StdOut << textString;\r\n  PrintSpaces(numSpaces - numLeftSpaces);\r\n}\r\n\r\nclass CFieldPrinter\r\n{\r\n  CObjectVector<CFieldInfo> _fields;\r\npublic:\r\n  void Clear() { _fields.Clear(); }\r\n  void Init(const CFieldInfoInit *standardFieldTable, int numItems);\r\n  HRESULT Init(IInArchive *archive);\r\n  void PrintTitle();\r\n  void PrintTitleLines();\r\n  HRESULT PrintItemInfo(IInArchive *archive, \r\n      const UString &defaultItemName,\r\n      const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n      UInt32 index,\r\n      bool techMode);\r\n  HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs, \r\n      const UInt64 *size, const UInt64 *compressedSize);\r\n};\r\n\r\nvoid CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)\r\n{\r\n  Clear();\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    CFieldInfo fieldInfo;\r\n    const CFieldInfoInit &fieldInfoInit = standardFieldTable[i];\r\n    fieldInfo.PropID = fieldInfoInit.PropID;\r\n    fieldInfo.Name = fieldInfoInit.Name;\r\n    fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment;\r\n    fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment;\r\n    fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth;\r\n    fieldInfo.Width = fieldInfoInit.Width;\r\n    _fields.Add(fieldInfo);\r\n  }\r\n}\r\n\r\nstatic UString GetPropName(PROPID propID, BSTR name)\r\n{\r\n  for (int i = 0; i < sizeof(kPropIdToName) / sizeof(kPropIdToName[0]); i++)\r\n  {\r\n    const CPropIdToName &propIdToName = kPropIdToName[i];\r\n    if (propIdToName.PropID == propID)\r\n      return propIdToName.Name;\r\n  }\r\n  if (name)\r\n    return name;\r\n  return L\"?\";\r\n}\r\n\r\nHRESULT CFieldPrinter::Init(IInArchive *archive)\r\n{\r\n  Clear();\r\n  UInt32 numProps;\r\n  RINOK(archive->GetNumberOfProperties(&numProps));\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    CMyComBSTR name;\r\n    PROPID propID;\r\n    VARTYPE vt;\r\n    RINOK(archive->GetPropertyInfo(i, &name, &propID, &vt));\r\n    CFieldInfo fieldInfo;\r\n    fieldInfo.PropID = propID;\r\n    fieldInfo.Name = GetPropName(propID, name);\r\n    _fields.Add(fieldInfo);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitle()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    PrintString(fieldInfo.TitleAdjustment, \r\n      ((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);\r\n  }\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitleLines()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    for (int i = 0; i < fieldInfo.Width; i++)\r\n      g_StdOut << '-';\r\n  }\r\n}\r\n\r\n\r\nBOOL IsFileTimeZero(CONST FILETIME *lpFileTime)\r\n{\r\n  return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);\r\n}\r\n\r\nstatic const char *kEmptyTimeString = \"                   \";\r\nvoid PrintTime(const NCOM::CPropVariant &propVariant)\r\n{\r\n  if (propVariant.vt != VT_FILETIME)\r\n    throw \"incorrect item\";\r\n  if (IsFileTimeZero(&propVariant.filetime))\r\n    g_StdOut << kEmptyTimeString;\r\n  else\r\n  {\r\n    FILETIME localFileTime;\r\n    if (!FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n      throw \"FileTimeToLocalFileTime error\";\r\n    char s[32];\r\n    if (ConvertFileTimeToString(localFileTime, s, true, true))\r\n      g_StdOut << s;\r\n    else\r\n      g_StdOut << kEmptyTimeString;\r\n  }\r\n}\r\n\r\nHRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive, \r\n    const UString &defaultItemName, \r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    UInt32 index,\r\n    bool techMode)\r\n{\r\n  /*\r\n  if (techMode)\r\n  {\r\n    g_StdOut << \"Index = \";\r\n    g_StdOut << (UInt64)index;\r\n    g_StdOut << endl;\r\n  }\r\n  */\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    if (!techMode)\r\n      PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(archive->GetProperty(index, fieldInfo.PropID, &propVariant));\r\n    if (techMode)\r\n    {\r\n      g_StdOut << fieldInfo.Name << \" = \";\r\n    }\r\n    int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;\r\n    if (propVariant.vt == VT_EMPTY)\r\n    {\r\n      switch(fieldInfo.PropID)\r\n      {\r\n        case kpidPath:\r\n          propVariant = defaultItemName;\r\n          break;\r\n        case kpidLastWriteTime:\r\n          propVariant = archiveFileInfo.LastWriteTime;\r\n          break;\r\n        default:\r\n          if (techMode)\r\n            g_StdOut << endl;\r\n          else\r\n            PrintSpaces(width);\r\n          continue;\r\n      }\r\n    }\r\n    if (fieldInfo.PropID == kpidLastWriteTime)\r\n    {\r\n      PrintTime(propVariant);\r\n    }\r\n    else if (fieldInfo.PropID == kpidAttributes)\r\n    {\r\n      if (propVariant.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      UInt32 attributes = propVariant.ulVal;\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, index, isFolder));\r\n      char s[8];\r\n      GetAttributesString(attributes, isFolder, s);\r\n      g_StdOut << s;\r\n    }\r\n    else if (propVariant.vt == VT_BSTR)\r\n    {\r\n      if (techMode)\r\n        g_StdOut << propVariant.bstrVal;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, propVariant.bstrVal);\r\n    }\r\n    else\r\n    {\r\n      UString s = ConvertPropertyToString(propVariant, fieldInfo.PropID);\r\n      s.Replace(wchar_t(0xA), L' '); \r\n      s.Replace(wchar_t(0xD), L' '); \r\n\r\n      if (techMode)\r\n        g_StdOut << s;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, s);\r\n    }\r\n    if (techMode)\r\n      g_StdOut << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)\r\n{\r\n  wchar_t textString[32] = { 0 };\r\n  if (value != NULL)\r\n    ConvertUInt64ToString(*value, textString);\r\n  PrintString(adjustment, width, textString);\r\n}\r\n\r\n\r\nHRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs, \r\n    const UInt64 *size, const UInt64 *compressedSize)\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    NCOM::CPropVariant propVariant;\r\n    if (fieldInfo.PropID == kpidSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);\r\n    else if (fieldInfo.PropID == kpidPackedSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);\r\n    else if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      wchar_t textString[32];\r\n      ConvertUInt64ToString(numFiles, textString);\r\n      UString temp = textString;\r\n      temp += L\" \";\r\n      temp += kFilesMessage;\r\n      temp += L\", \";\r\n      ConvertUInt64ToString(numDirs, textString);\r\n      temp += textString;\r\n      temp += L\" \";\r\n      temp += kDirsMessage;\r\n      PrintString(fieldInfo.TextAdjustment, 0, temp);\r\n    }\r\n    else \r\n      PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L\"\");\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nbool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)\r\n{\r\n  NCOM::CPropVariant propVariant;\r\n  if (archive->GetProperty(index, propID, &propVariant) != S_OK)\r\n    throw \"GetPropertyValue error\";\r\n  if (propVariant.vt == VT_EMPTY)\r\n    return false;\r\n  value = ConvertPropVariantToUInt64(propVariant);\r\n  return true;\r\n}\r\n\r\nHRESULT ListArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &numErrors)\r\n{\r\n  numErrors = 0;\r\n  CFieldPrinter fieldPrinter;\r\n  if (!techMode)\r\n    fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));\r\n\r\n  UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;\r\n  UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;\r\n  for (int i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archiveName = archivePaths[i];\r\n    NFile::NFind::CFileInfoW archiveFileInfo;\r\n    if (!NFile::NFind::FindFile(archiveName, archiveFileInfo) || archiveFileInfo.IsDirectory())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not archive\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n    if (archiveFileInfo.IsDirectory())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not file\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    CArchiveLink archiveLink;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &g_StdOut;\r\n    openCallback.PasswordIsDefined = passwordEnabled;\r\n    openCallback.Password = password;\r\n\r\n    HRESULT result = MyOpenArchive(codecs, archiveName, archiveLink, &openCallback);\r\n    if (result != S_OK)\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not supported archive\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n      }\r\n    }\r\n\r\n    IInArchive *archive = archiveLink.GetArchive();\r\n    const UString defaultItemName = archiveLink.GetDefaultItemName();\r\n\r\n    if (enableHeaders)\r\n    {\r\n      g_StdOut << endl << kListing << archiveName << endl << endl;\r\n\r\n      UInt32 numProps;\r\n      if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)\r\n      {\r\n        for (UInt32 i = 0; i < numProps; i++)\r\n        {\r\n          CMyComBSTR name;\r\n          PROPID propID;\r\n          VARTYPE vt;\r\n          if (archive->GetArchivePropertyInfo(i, &name, &propID, &vt) != S_OK)\r\n            continue;\r\n          NCOM::CPropVariant prop;\r\n          if (archive->GetArchiveProperty(propID, &prop) != S_OK)\r\n            continue;\r\n          UString s = ConvertPropertyToString(prop, propID);\r\n          if (!s.IsEmpty())\r\n            g_StdOut << GetPropName(propID, name) << \" = \" << s << endl;\r\n        }\r\n      }\r\n      if (techMode)\r\n        g_StdOut << \"----------\\n\";\r\n      if (numProps > 0)\r\n        g_StdOut << endl;\r\n    }\r\n\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitle();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n    }\r\n\r\n    if (techMode)\r\n    {\r\n      RINOK(fieldPrinter.Init(archive));\r\n    }\r\n    UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0;\r\n    UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;\r\n    UInt32 numItems;\r\n    RINOK(archive->GetNumberOfItems(&numItems));\r\n    for(UInt32 i = 0; i < numItems; i++)\r\n    {\r\n      if (NConsoleClose::TestBreakSignal())\r\n        return E_ABORT;\r\n\r\n      UString filePath;\r\n      RINOK(GetArchiveItemPath(archive, i, defaultItemName, filePath));\r\n\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n      if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n        continue;\r\n      \r\n      fieldPrinter.PrintItemInfo(archive, defaultItemName, archiveFileInfo, i, techMode);\r\n      \r\n      UInt64 packSize, unpackSize;\r\n      if (!GetUInt64Value(archive, i, kpidSize, unpackSize))\r\n        unpackSize = 0;\r\n      else\r\n        totalUnPackSizePointer = &totalUnPackSize;\r\n      if (!GetUInt64Value(archive, i, kpidPackedSize, packSize))\r\n        packSize = 0;\r\n      else\r\n        totalPackSizePointer = &totalPackSize;\r\n      \r\n      g_StdOut << endl;\r\n\r\n      if (isFolder)\r\n        numDirs++;\r\n      else\r\n        numFiles++;\r\n      totalPackSize += packSize;\r\n      totalUnPackSize += unpackSize;\r\n    }\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintSummaryInfo(numFiles, numDirs, totalUnPackSizePointer, totalPackSizePointer);\r\n      g_StdOut << endl;\r\n    }\r\n    if (totalPackSizePointer != 0)\r\n    {\r\n      totalPackSizePointer2 = &totalPackSize2;\r\n      totalPackSize2 += totalPackSize;\r\n    }\r\n    if (totalUnPackSizePointer != 0)\r\n    {\r\n      totalUnPackSizePointer2 = &totalUnPackSize2;\r\n      totalUnPackSize2 += totalUnPackSize;\r\n    }\r\n    numFiles2 += numFiles;\r\n    numDirs2 += numDirs;\r\n  }\r\n  if (enableHeaders && !techMode && archivePaths.Size() > 1)\r\n  {\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintTitleLines();\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintSummaryInfo(numFiles2, numDirs2, totalUnPackSizePointer2, totalPackSizePointer2);\r\n    g_StdOut << endl;\r\n    g_StdOut << \"Archives: \" << archivePaths.Size() << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/List.h",
    "content": "// List.h\r\n\r\n#ifndef __LIST_H\r\n#define __LIST_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nHRESULT ListArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &errors);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/Main.cpp",
    "content": "// Main.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n\r\n#include \"Common/CommandLineParser.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/Error.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/MemoryLock.h\"\r\n#endif\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/UpdateAction.h\"\r\n#include \"../Common/Update.h\"\r\n#include \"../Common/Extract.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"../Common/ExitCode.h\"\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../Common/LoadCodecs.h\"\r\n#endif\r\n\r\n#include \"../../Compress/LZMA_Alone/LzmaBenchCon.h\"\r\n\r\n#include \"List.h\"\r\n#include \"OpenCallbackConsole.h\"\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\n#if defined( _WIN32) && defined( _7ZIP_LARGE_PAGES)\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NCommandLineParser;\r\n\r\nHINSTANCE g_hInstance = 0;\r\nextern CStdOutStream *g_StdStream;\r\n\r\nstatic const char *kCopyrightString = \"\\n7-Zip\"\r\n#ifndef EXTERNAL_CODECS\r\n\" (A)\"\r\n#endif\r\n\r\n#ifdef _WIN64\r\n\" [64]\"\r\n#endif\r\n\r\n\" \" MY_VERSION_COPYRIGHT_DATE \"\\n\";\r\n\r\nstatic const char *kHelpString = \r\n    \"\\nUsage: 7z\"\r\n#ifdef _NO_CRYPTO\r\n    \"r\"\r\n#else\r\n#ifndef EXTERNAL_CODECS\r\n    \"a\"\r\n#endif\r\n#endif\r\n    \" <command> [<switches>...] <archive_name> [<file_names>...]\\n\"\r\n    \"       [<@listfiles...>]\\n\"\r\n    \"\\n\"\r\n    \"<Commands>\\n\"\r\n    \"  a: Add files to archive\\n\"\r\n    \"  b: Benchmark\\n\"\r\n    \"  d: Delete files from archive\\n\"\r\n    \"  e: Extract files from archive (without using directory names)\\n\"\r\n    \"  l: List contents of archive\\n\"\r\n//    \"  l[a|t][f]: List contents of archive\\n\"\r\n//    \"    a - with Additional fields\\n\"\r\n//    \"    t - with all fields\\n\"\r\n//    \"    f - with Full pathnames\\n\"\r\n    \"  t: Test integrity of archive\\n\"\r\n    \"  u: Update files to archive\\n\"\r\n    \"  x: eXtract files with full paths\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -ai[r[-|0]]{@listfile|!wildcard}: Include archives\\n\"\r\n    \"  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives\\n\"\r\n    \"  -bd: Disable percentage indicator\\n\"\r\n    \"  -i[r[-|0]]{@listfile|!wildcard}: Include filenames\\n\"\r\n    \"  -m{Parameters}: set compression Method\\n\"\r\n    \"  -o{Directory}: set Output directory\\n\"\r\n    \"  -p{Password}: set Password\\n\"\r\n    \"  -r[-|0]: Recurse subdirectories\\n\"\r\n    \"  -scs{UTF-8 | WIN | DOS}: set charset for list files\\n\"\r\n    \"  -sfx[{name}]: Create SFX archive\\n\"\r\n    \"  -si[{name}]: read data from stdin\\n\"\r\n    \"  -slt: show technical information for l (List) command\\n\"\r\n    \"  -so: write data to stdout\\n\"\r\n    \"  -ssc[-]: set sensitive case mode\\n\"\r\n    \"  -ssw: compress shared files\\n\"\r\n    \"  -t{Type}: Set type of archive\\n\"\r\n    \"  -v{Size}[b|k|m|g]: Create volumes\\n\"\r\n    \"  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\\n\"\r\n    \"  -w[{path}]: assign Work directory. Empty path means a temporary directory\\n\"\r\n    \"  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\\n\"\r\n    \"  -y: assume Yes on all queries\\n\";\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\"; // NExitCode::kUserError\r\n\r\nstatic const wchar_t *kDefaultSfxModule = L\"7zCon.sfx\";\r\n\r\nstatic void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code)\r\n{\r\n  s << message << endl;\r\n  throw code;\r\n}\r\n\r\nstatic void PrintHelpAndExit(CStdOutStream &s) // yyy\r\n{\r\n  s << kHelpString;\r\n  ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError);\r\n}\r\n\r\n#ifndef _WIN32\r\nstatic void GetArguments(int numArguments, const char *arguments[], UStringVector &parts)\r\n{\r\n  parts.Clear();\r\n  for(int i = 0; i < numArguments; i++)\r\n  {\r\n    UString s = MultiByteToUnicodeString(arguments[i]);\r\n    parts.Add(s);\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp)\r\n{\r\n  s << kCopyrightString;\r\n  // s << \"# CPUs: \" << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << \"\\n\";\r\n  if (needHelp) \r\n    s << kHelpString;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic void PrintString(CStdOutStream &stdStream, const AString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n#endif\r\n\r\nstatic void PrintString(CStdOutStream &stdStream, const UString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n\r\nstatic inline char GetHex(Byte value)\r\n{\r\n  return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nint Main2(\r\n  #ifndef _WIN32  \r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n)\r\n{\r\n  #ifdef _WIN32  \r\n  SetFileApisToOEM();\r\n  #endif\r\n  \r\n  UStringVector commandStrings;\r\n  #ifdef _WIN32  \r\n  NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);\r\n  #else\r\n  GetArguments(numArguments, arguments, commandStrings);\r\n  #endif\r\n\r\n  if(commandStrings.Size() == 1)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n  commandStrings.Delete(0);\r\n\r\n  CArchiveCommandLineOptions options;\r\n\r\n  CArchiveCommandLineParser parser;\r\n\r\n  parser.Parse1(commandStrings, options);\r\n\r\n  if(options.HelpMode)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  if (options.LargePages)\r\n  {\r\n    SetLargePageSize();\r\n    NSecurity::EnableLockMemoryPrivilege();\r\n  }\r\n  #endif\r\n\r\n  CStdOutStream &stdStream = options.StdOutMode ? g_StdErr : g_StdOut;\r\n  g_StdStream = &stdStream;\r\n\r\n  if (options.EnableHeaders)\r\n    ShowCopyrightAndHelp(stdStream, false);\r\n\r\n  parser.Parse2(options);\r\n\r\n  CCodecs *codecs = new CCodecs;\r\n  CMyComPtr<\r\n    #ifdef EXTERNAL_CODECS\r\n    ICompressCodecsInfo\r\n    #else\r\n    IUnknown\r\n    #endif\r\n    > compressCodecsInfo = codecs;\r\n  HRESULT result = codecs->Load();\r\n  if (result != S_OK)\r\n    throw CSystemException(result);\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n  if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n    stdStream << endl << \"Formats:\" << endl;\r\n    int i;\r\n    for (i = 0; i < codecs->Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = codecs->Formats[i];\r\n      #ifdef EXTERNAL_CODECS\r\n      if (arc.LibIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(arc.LibIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n      #endif\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(arc.UpdateEnabled ? 'C' : ' ');\r\n      stdStream << (char)(arc.KeepName ? 'K' : ' ');\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, arc.Name, 6);\r\n      stdStream << \"  \";\r\n      UString s;\r\n      for (int t = 0; t < arc.Exts.Size(); t++)\r\n      {\r\n        const CArcExtInfo &ext = arc.Exts[t];\r\n        s += ext.Ext;\r\n        if (!ext.AddExt.IsEmpty())\r\n        {\r\n          s += L\" (\";\r\n          s += ext.AddExt;\r\n          s += L')';\r\n        }\r\n        s += L' ';\r\n      }\r\n      PrintString(stdStream, s, 14);\r\n      stdStream << \"  \";\r\n      const CByteBuffer &sig = arc.StartSignature;\r\n      for (size_t j = 0; j < sig.GetCapacity(); j++)\r\n      {\r\n        Byte b = sig[j];\r\n        if (b > 0x20 && b < 0x80)\r\n        {\r\n          stdStream << (char)b;\r\n        }\r\n        else\r\n        {\r\n          stdStream << GetHex((Byte)((b >> 4) & 0xF));\r\n          stdStream << GetHex((Byte)(b & 0xF));\r\n        }\r\n        stdStream << ' ';\r\n      }\r\n      stdStream << endl;\r\n    }\r\n    stdStream << endl << \"Codecs:\" << endl;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    UINT32 numMethods;\r\n    if (codecs->GetNumberOfMethods(&numMethods) == S_OK)\r\n    for (UInt32 j = 0; j < numMethods; j++)\r\n    {\r\n      int libIndex = codecs->GetCodecLibIndex(j);\r\n      if (libIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(libIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(codecs->GetCodecEncoderIsAssigned(j) ? 'C' : ' ');\r\n      UInt64 id;\r\n      stdStream << \"  \";\r\n      HRESULT res = codecs->GetCodecId(j, id);\r\n      if (res != S_OK)\r\n        id = (UInt64)(Int64)-1;\r\n      char s[32];\r\n      ConvertUInt64ToString(id, s, 16);\r\n      PrintString(stdStream, s, 8);\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, codecs->GetCodecName(j), 11);\r\n      stdStream << endl;\r\n      /*\r\n      if (res != S_OK)\r\n        throw \"incorrect Codec ID\";\r\n      */\r\n    }\r\n    #endif\r\n    return S_OK;\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    if (options.Method.CompareNoCase(L\"CRC\") == 0)\r\n    {\r\n      HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nCRC Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      HRESULT res = LzmaBenchCon(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        (FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nDecoding Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n  }\r\n  else if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if(isExtractGroupCommand)\r\n    {\r\n      CExtractCallbackConsole *ecs = new CExtractCallbackConsole;\r\n      CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;\r\n\r\n      ecs->OutStream = &stdStream;\r\n      ecs->PasswordIsDefined = options.PasswordEnabled;\r\n      ecs->Password = options.Password;\r\n      ecs->Init();\r\n\r\n      COpenCallbackConsole openCallback;\r\n      openCallback.OutStream = &stdStream;\r\n      openCallback.PasswordIsDefined = options.PasswordEnabled;\r\n      openCallback.Password = options.Password;\r\n\r\n      CExtractOptions eo;\r\n      eo.StdOutMode = options.StdOutMode;\r\n      eo.PathMode = options.Command.GetPathMode();\r\n      eo.TestMode = options.Command.IsTestMode();\r\n      eo.OverwriteMode = options.OverwriteMode;\r\n      eo.OutputDir = options.OutputDir;\r\n      eo.YesToAll = options.YesToAll;\r\n      #ifdef COMPRESS_MT\r\n      eo.Properties = options.ExtractProperties;\r\n      #endif\r\n      UString errorMessage;\r\n      CDecompressStat stat;\r\n      HRESULT result = DecompressArchives(\r\n          codecs,\r\n          options.ArchivePathsSorted, \r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head, \r\n          eo, &openCallback, ecs, errorMessage, stat);\r\n      if (!errorMessage.IsEmpty())\r\n      {\r\n        stdStream << endl << \"Error: \" << errorMessage;\r\n        if (result == S_OK)\r\n          result = E_FAIL;\r\n      }\r\n\r\n      stdStream << endl;\r\n      if (ecs->NumArchives > 1)\r\n        stdStream << \"Archives: \" << ecs->NumArchives << endl;\r\n      if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0)\r\n      {\r\n        if (ecs->NumArchives > 1)\r\n        {\r\n          stdStream << endl;\r\n          if (ecs->NumArchiveErrors != 0)\r\n            stdStream << \"Archive Errors: \" << ecs->NumArchiveErrors << endl;\r\n          if (ecs->NumFileErrors != 0)\r\n            stdStream << \"Sub items Errors: \" << ecs->NumFileErrors << endl;\r\n        }\r\n        if (result != S_OK)\r\n          throw CSystemException(result);\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n      if (stat.NumFolders != 0)\r\n        stdStream << \"Folders: \" << stat.NumFolders << endl;\r\n      if (stat.NumFiles != 1 || stat.NumFolders != 0)\r\n          stdStream << \"Files: \" << stat.NumFiles << endl;\r\n      stdStream \r\n           << \"Size:       \" << stat.UnpackSize << endl\r\n           << \"Compressed: \" << stat.PackSize << endl;\r\n    }\r\n    else\r\n    {\r\n      UInt64 numErrors = 0;\r\n      HRESULT result = ListArchives(\r\n          codecs,\r\n          options.ArchivePathsSorted, \r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head, \r\n          options.EnableHeaders, \r\n          options.TechMode,\r\n          options.PasswordEnabled, \r\n          options.Password, numErrors);\r\n      if (numErrors > 0)\r\n      {\r\n        g_StdOut << endl << \"Errors: \" << numErrors;\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    UString workingDir;\r\n\r\n    CUpdateOptions &uo = options.UpdateOptions;\r\n    if (uo.SfxMode && uo.SfxModule.IsEmpty())\r\n      uo.SfxModule = kDefaultSfxModule;\r\n\r\n    bool passwordIsDefined = \r\n        options.PasswordEnabled && !options.Password.IsEmpty();\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &stdStream;\r\n    openCallback.PasswordIsDefined = passwordIsDefined;\r\n    openCallback.Password = options.Password;\r\n\r\n    CUpdateCallbackConsole callback;\r\n    callback.EnablePercents = options.EnablePercents;\r\n    callback.PasswordIsDefined = passwordIsDefined;\r\n    callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty();\r\n    callback.Password = options.Password;\r\n    callback.StdOutMode = uo.StdOutMode;\r\n    callback.Init(&stdStream);\r\n\r\n    CUpdateErrorInfo errorInfo;\r\n\r\n    if (!uo.Init(codecs, options.ArchiveName, options.ArcType))\r\n      throw \"Unsupported archive type\";\r\n    HRESULT result = UpdateArchive(codecs, \r\n        options.WildcardCensor, uo, \r\n        errorInfo, &openCallback, &callback);\r\n\r\n    int exitCode = NExitCode::kSuccess;\r\n    if (callback.CantFindFiles.Size() > 0)\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      int numErrors = callback.CantFindFiles.Size();\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.CantFindFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.CantFindCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot find \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n\r\n    if (result != S_OK)\r\n    {\r\n      UString message;\r\n      if (!errorInfo.Message.IsEmpty())\r\n      {\r\n        message += errorInfo.Message;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName2.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName2;\r\n        message += L\"\\n\";\r\n      }\r\n      if (errorInfo.SystemError != 0)\r\n      {\r\n        message += NError::MyFormatMessageW(errorInfo.SystemError);\r\n        message += L\"\\n\";\r\n      }\r\n      if (!message.IsEmpty())\r\n        stdStream << L\"\\nError:\\n\" << message;\r\n      throw CSystemException(result);\r\n    }\r\n    int numErrors = callback.FailedFiles.Size();\r\n    if (numErrors == 0)\r\n    {\r\n      if (callback.CantFindFiles.Size() == 0)\r\n        stdStream << kEverythingIsOk << endl;\r\n    }\r\n    else\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.FailedFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.FailedCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot open \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n    return exitCode;\r\n  }\r\n  else \r\n    PrintHelpAndExit(stdStream);\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/MainAr.cpp",
    "content": "// MainAr.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <locale.h>\r\n\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"../Common/ExitCode.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCStdOutStream *g_StdStream = 0;\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\n#endif\r\n#if !defined(_UNICODE) || !defined(_WIN64)\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern int Main2(\r\n  #ifndef _WIN32  \r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n);\r\n\r\nstatic const char *kExceptionErrorMessage = \"\\n\\nError:\\n\";\r\nstatic const char *kUserBreak  = \"\\nBreak signaled\\n\";\r\n\r\nstatic const char *kMemoryExceptionMessage = \"\\n\\nERROR: Can't allocate required memory!\\n\";\r\nstatic const char *kUnknownExceptionMessage = \"\\n\\nUnknown Error\\n\";\r\nstatic const char *kInternalExceptionMessage = \"\\n\\nInternal Error #\";\r\n\r\nint \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\nmain\r\n(\r\n#ifndef _WIN32  \r\nint numArguments, const char *arguments[]\r\n#endif\r\n)\r\n{\r\n  g_StdStream = &g_StdOut;\r\n  #ifdef _WIN32\r\n  \r\n  #ifdef _UNICODE\r\n  #ifndef _WIN64\r\n  if (!IsItWindowsNT())\r\n  {\r\n    (*g_StdStream) << \"This program requires Windows NT/2000/XP/2003/Vista\";\r\n    return NExitCode::kFatalError;\r\n  }\r\n  #endif\r\n  #else\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  \r\n  #endif\r\n\r\n  // setlocale(LC_COLLATE, \".OCP\");\r\n  NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;\r\n  int res = 0;\r\n  try\r\n  {\r\n    res = Main2(\r\n#ifndef _WIN32\r\n      numArguments, arguments\r\n#endif\r\n    );\r\n  }\r\n  catch(const CNewException &)\r\n  {\r\n    (*g_StdStream) << kMemoryExceptionMessage;\r\n    return (NExitCode::kMemoryError);\r\n  }\r\n  catch(const NConsoleClose::CCtrlBreakException &)\r\n  {\r\n    (*g_StdStream) << endl << kUserBreak;\r\n    return (NExitCode::kUserBreak);\r\n  }\r\n  catch(const CArchiveCommandLineException &e)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << e << endl;\r\n    return (NExitCode::kUserError);\r\n  }\r\n  catch(const CSystemException &systemError)\r\n  {\r\n    if (systemError.ErrorCode == E_OUTOFMEMORY)\r\n    {\r\n      (*g_StdStream) << kMemoryExceptionMessage;\r\n      return (NExitCode::kMemoryError);\r\n    }\r\n    if (systemError.ErrorCode == E_ABORT)\r\n    {\r\n      (*g_StdStream) << endl << kUserBreak;\r\n      return (NExitCode::kUserBreak);\r\n    }\r\n    UString message;\r\n    NError::MyFormatMessage(systemError.ErrorCode, message);\r\n    (*g_StdStream) << endl << endl << \"System error:\" << endl << \r\n        message << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(NExitCode::EEnum &exitCode)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << exitCode << endl;\r\n    return (exitCode);\r\n  }\r\n  /*\r\n  catch(const NExitCode::CMultipleErrors &multipleErrors)\r\n  {\r\n    (*g_StdStream) << endl << multipleErrors.NumErrors << \" errors\" << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  */\r\n  catch(const UString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const AString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const char *s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(int t)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << t << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(...)\r\n  {\r\n    (*g_StdStream) << kUnknownExceptionMessage;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  return  res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.cpp",
    "content": "// OpenCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nHRESULT COpenCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::SetTotal(const UInt64 *, const UInt64 *)\r\n{\r\n  return CheckBreak();\r\n}\r\n\r\nHRESULT COpenCallbackConsole::SetCompleted(const UInt64 *, const UInt64 *)\r\n{\r\n  return CheckBreak();\r\n}\r\n \r\nHRESULT COpenCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  PasswordWasAsked = true;\r\n  RINOK(CheckBreak());\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream); \r\n    PasswordIsDefined = true;\r\n  }\r\n  CMyComBSTR temp(Password);\r\n  *password = temp.Detach();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::GetPasswordIfAny(UString &password)\r\n{\r\n  if (PasswordIsDefined)\r\n    password = Password;\r\n  return S_OK;\r\n}\r\n\r\nbool COpenCallbackConsole::WasPasswordAsked()\r\n{\r\n  return PasswordWasAsked;\r\n}\r\n\r\nvoid COpenCallbackConsole::ClearPasswordWasAskedFlag()\r\n{\r\n  PasswordWasAsked = false;\r\n}\r\n\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.h",
    "content": "// OpenCallbackConsole.h\r\n\r\n#ifndef __OPENCALLBACKCONSOLE_H\r\n#define __OPENCALLBACKCONSOLE_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../Common/ArchiveOpenCallback.h\"\r\n\r\nclass COpenCallbackConsole: public IOpenCallbackUI\r\n{\r\npublic:\r\n  HRESULT CheckBreak();\r\n  HRESULT SetTotal(const UInt64 *files, const UInt64 *bytes);\r\n  HRESULT SetCompleted(const UInt64 *files, const UInt64 *bytes);\r\n  HRESULT CryptoGetTextPassword(BSTR *password);\r\n  HRESULT GetPasswordIfAny(UString &password);\r\n  bool WasPasswordAsked();\r\n  void ClearPasswordWasAskedFlag();\r\n  \r\n  CStdOutStream *OutStream;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool PasswordWasAsked;\r\n  COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/PercentPrinter.cpp",
    "content": "// PercentPrinter.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"PercentPrinter.h\"\r\n\r\nconst int kPaddingSize = 2;\r\nconst int kPercentsSize = 4;\r\nconst int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;\r\n\r\nstatic void ClearPrev(char *p, int num)\r\n{\r\n  int i;\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  for (i = 0; i < num; i++) *p++ = ' ';\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  *p = '\\0';\r\n}\r\n\r\nvoid CPercentPrinter::ClosePrint()\r\n{\r\n  if (m_NumExtraChars == 0)\r\n    return;\r\n  char s[kMaxExtraSize * 3 + 1];\r\n  ClearPrev(s, m_NumExtraChars);\r\n  (*OutStream) << s;\r\n  m_NumExtraChars = 0;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const char *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const wchar_t *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintNewLine()\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << \"\\n\";\r\n}\r\n\r\nvoid CPercentPrinter::RePrintRatio()\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s);\r\n  int size = (int)strlen(s);\r\n  s[size++] = '%';\r\n  s[size] = '\\0';\r\n\r\n  int extraSize = kPaddingSize + MyMax(size, kPercentsSize);\r\n  if (extraSize < m_NumExtraChars)\r\n    extraSize = m_NumExtraChars;\r\n\r\n  char fullString[kMaxExtraSize * 3];\r\n  char *p = fullString;\r\n  int i;\r\n  if (m_NumExtraChars == 0)\r\n  {\r\n    for (i = 0; i < extraSize; i++) \r\n      *p++ = ' ';\r\n    m_NumExtraChars = extraSize;\r\n  }\r\n\r\n  for (i = 0; i < m_NumExtraChars; i++) \r\n    *p++ = '\\b';\r\n  m_NumExtraChars = extraSize;\r\n  for (; size < m_NumExtraChars; size++)\r\n    *p++ = ' ';\r\n  MyStringCopy(p, s);\r\n  (*OutStream) << fullString;\r\n  OutStream->Flush(); \r\n  m_PrevValue = m_CurValue;\r\n}\r\n\r\nvoid CPercentPrinter::PrintRatio()\r\n{\r\n  if (m_CurValue < m_PrevValue + m_MinStepSize && \r\n      m_CurValue + m_MinStepSize > m_PrevValue && m_NumExtraChars != 0)\r\n    return;\r\n  RePrintRatio();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/PercentPrinter.h",
    "content": "// PercentPrinter.h\r\n\r\n#ifndef __PERCENTPRINTER_H\r\n#define __PERCENTPRINTER_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/StdOutStream.h\"\r\n\r\nclass CPercentPrinter\r\n{\r\n  UInt64 m_MinStepSize;\r\n  UInt64 m_PrevValue;\r\n  UInt64 m_CurValue;\r\n  UInt64 m_Total;\r\n  int m_NumExtraChars;\r\npublic:\r\n  CStdOutStream *OutStream;\r\n\r\n  CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize), \r\n      m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}\r\n  void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }\r\n  void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }\r\n  void PrintString(const char *s);\r\n  void PrintString(const wchar_t *s);\r\n  void PrintNewLine();\r\n  void ClosePrint();\r\n  void RePrintRatio();\r\n  void PrintRatio();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp",
    "content": "// UpdateCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifdef COMPRESS_MT\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nusing namespace NWindows;\r\n\r\n#ifdef COMPRESS_MT\r\nstatic NSynchronization::CCriticalSection g_CriticalSection;\r\n#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);\r\n#else\r\n#define MT_LOCK\r\n#endif\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nstatic const char *kCreatingArchiveMessage = \"Creating archive \";\r\nstatic const char *kUpdatingArchiveMessage = \"Updating archive \";\r\nstatic const char *kScanningMessage = \"Scanning\";\r\n\r\n\r\nHRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n    (*OutStream) << \"Error: \" << name << \" is not supported archive\" << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartScanning()\r\n{\r\n  (*OutStream) << kScanningMessage;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)\r\n{\r\n  CantFindFiles.Add(name);\r\n  CantFindCodes.Add(systemError);\r\n  // m_PercentPrinter.ClosePrint();\r\n  if (!m_WarningsMode)\r\n  {\r\n    (*OutStream) << endl << endl;\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_WarningsMode = true;\r\n  }\r\n  m_PercentPrinter.PrintString(name);\r\n  m_PercentPrinter.PrintString(\":  WARNING: \");\r\n  m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n  m_PercentPrinter.PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishScanning()\r\n{\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)\r\n{\r\n  if(updating)\r\n    (*OutStream) << kUpdatingArchiveMessage;\r\n  else\r\n    (*OutStream) << kCreatingArchiveMessage; \r\n  if (name != 0)\r\n    (*OutStream) << name;\r\n  else\r\n    (*OutStream) << \"StdOut\";\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishArchive()\r\n{\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::Finilize()\r\n{\r\n  MT_LOCK\r\n  if (m_NeedBeClosed)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.ClosePrint();\r\n    }\r\n    if (!StdOutMode && m_NeedNewLine)\r\n    {\r\n      m_PercentPrinter.PrintNewLine();\r\n      m_NeedNewLine = false;\r\n    }\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)\r\n{\r\n  MT_LOCK\r\n  if (EnablePercents)\r\n    m_PercentPrinter.SetTotal(size);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  MT_LOCK\r\n  if (completeValue != NULL)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.SetRatio(*completeValue);\r\n      m_PercentPrinter.PrintRatio();\r\n      m_NeedBeClosed = true;\r\n    }\r\n  }\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  /*\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  */\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)\r\n{\r\n  MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  if(isAnti)\r\n    m_PercentPrinter.PrintString(\"Anti item    \");\r\n  else\r\n    m_PercentPrinter.PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)\r\n{\r\n  MT_LOCK\r\n  FailedCodes.Add(systemError);\r\n  FailedFiles.Add(name);\r\n  // if (systemError == ERROR_SHARING_VIOLATION)\r\n  {\r\n    m_PercentPrinter.ClosePrint();\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_PercentPrinter.PrintString(\"WARNING: \");\r\n    m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n    return S_FALSE;\r\n  }\r\n  // return systemError;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )\r\n{\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;  \r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined) \r\n  {\r\n    if (AskPassword)\r\n    {\r\n      Password = GetPassword(OutStream); \r\n      PasswordIsDefined = true;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.h",
    "content": "// UpdateCallbackConsole.h\r\n\r\n#ifndef __UPDATECALLBACKCONSOLE_H\r\n#define __UPDATECALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"PercentPrinter.h\"\r\n#include \"../Common/Update.h\"\r\n\r\nclass CUpdateCallbackConsole: public IUpdateCallbackUI2\r\n{\r\n  CPercentPrinter m_PercentPrinter;\r\n  bool m_NeedBeClosed;\r\n  bool m_NeedNewLine;\r\n\r\n  bool m_WarningsMode;\r\n\r\n  CStdOutStream *OutStream;\r\npublic:\r\n  bool EnablePercents;\r\n  bool StdOutMode;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n\r\n  CUpdateCallbackConsole(): \r\n      m_PercentPrinter(1 << 16),\r\n      PasswordIsDefined(false),\r\n      AskPassword(false),\r\n      StdOutMode(false),\r\n      EnablePercents(true),\r\n      m_WarningsMode(false)\r\n      {}\r\n  \r\n  ~CUpdateCallbackConsole() { Finilize(); }\r\n  void Init(CStdOutStream *outStream)\r\n  {\r\n    m_NeedBeClosed = false;\r\n    m_NeedNewLine = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n    OutStream = outStream;\r\n    m_PercentPrinter.OutStream = outStream;\r\n  }\r\n\r\n  INTERFACE_IUpdateCallbackUI2(;)\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  UStringVector CantFindFiles;\r\n  CRecordVector<HRESULT> CantFindCodes;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp",
    "content": "// UserInputUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StdInStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"UserInputUtils.h\"\r\n\r\nstatic const char kYes = 'Y';\r\nstatic const char kNo = 'N';\r\nstatic const char kYesAll = 'A';\r\nstatic const char kNoAll = 'S';\r\nstatic const char kAutoRename = 'U';\r\nstatic const char kQuit = 'Q';\r\n\r\nstatic const char *kFirstQuestionMessage = \"?\\n\";\r\nstatic const char *kHelpQuestionMessage = \r\n  \"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename / (Q)uit? \";\r\n\r\n// return true if pressed Quite;\r\n// in: anAll\r\n// out: anAll, anYes;\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << kFirstQuestionMessage;\r\n  for(;;)\r\n  {\r\n    (*outStream) << kHelpQuestionMessage;\r\n    AString scannedString = g_StdIn.ScanStringUntilNewLine();\r\n    scannedString.Trim();\r\n    if(!scannedString.IsEmpty())\r\n      switch(::MyCharUpper(scannedString[0]))\r\n      {\r\n        case kYes:\r\n          return NUserAnswerMode::kYes;\r\n        case kNo:\r\n          return NUserAnswerMode::kNo;\r\n        case kYesAll:\r\n          return NUserAnswerMode::kYesAll;\r\n        case kNoAll:\r\n          return NUserAnswerMode::kNoAll;\r\n        case kAutoRename:\r\n          return NUserAnswerMode::kAutoRename;\r\n        case kQuit:\r\n          return NUserAnswerMode::kQuit;\r\n      }\r\n  }\r\n}\r\n\r\nUString GetPassword(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << \"\\nEnter password:\";\r\n  outStream->Flush();\r\n  AString oemPassword = g_StdIn.ScanStringUntilNewLine();\r\n  return MultiByteToUnicodeString(oemPassword, CP_OEMCP); \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/UserInputUtils.h",
    "content": "// UserInputUtils.h\r\n\r\n#ifndef __USERINPUTUTILS_H\r\n#define __USERINPUTUTILS_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n\r\nnamespace NUserAnswerMode {\r\n\r\nenum EEnum\r\n{\r\n  kYes,\r\n  kNo,\r\n  kYesAll,\r\n  kNoAll,\r\n  kAutoRename,\r\n  kQuit\r\n};\r\n}\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);\r\nUString GetPassword(CStdOutStream *outStream);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/7zip/UI/Console/afxres.h",
    "content": "#include <winresrc.h>\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Build.mak",
    "content": "!IFDEF CPU\r\nLIBS = $(LIBS) bufferoverflowU.lib \r\nCFLAGS = $(CFLAGS) -GS- -Zc:forScope\r\n!ENDIF\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IF \"$(CPU)\" != \"IA64\"\r\n!IF \"$(CPU)\" != \"AMD64\"\r\nMY_ML = ml\r\n!ELSE\r\nMY_ML = ml64\r\n!ENDIF\r\n!ENDIF\r\n\r\nCOMPL_ASM = $(MY_ML) -c -Fo$O/ $**\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -EHsc -Gz -WX -Gy\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\n!IFDEF NEW_COMPILER\r\nCFLAGS_O1 = $(CFLAGS) -O1 -W4 -Wp64\r\nCFLAGS_O2 = $(CFLAGS) -O2 -W4 -Wp64\r\n!ELSE\r\nCFLAGS_O1 = $(CFLAGS) -O1 -W3\r\nCFLAGS_O2 = $(CFLAGS) -O2 -W3\r\n!ENDIF\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF \r\n\r\n!IFDEF DEF_FILE\r\nLFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)\r\n!ENDIF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL_PCH  = $(CPP) $(CFLAGS_O1) -Yc\"StdAfx.h\" -Fp$O/a.pch $** \r\nCOMPL      = $(CPP) $(CFLAGS_O1) -Yu\"StdAfx.h\" -Fp$O/a.pch $**\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS) $(DEF_FILE)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n$O\\resource.res: $(*B).rc\r\n\trc -fo$@ $**\r\n$O\\StdAfx.obj: $(*B).cpp\r\n\t$(COMPL_PCH)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/AutoPtr.h",
    "content": "// Common/AutoPtr.h\r\n\r\n#ifndef __COMMON_AUTOPTR_H\r\n#define __COMMON_AUTOPTR_H\r\n\r\ntemplate<class T> class CMyAutoPtr\r\n{\r\n  T *_p;\r\npublic:\r\n  CMyAutoPtr(T *p = 0) : _p(p) {}\r\n  CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {}\r\n  CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p) \r\n  {\r\n    reset(p.release());\r\n    return (*this);\r\n  }\r\n  ~CMyAutoPtr() { delete _p; }\r\n  T& operator*() const { return *_p; }\r\n  // T* operator->() const { return (&**this); }\r\n  T* get() const { return _p; }\r\n  T* release()\r\n  {\r\n    T *tmp = _p;\r\n    _p = 0;\r\n    return tmp;\r\n  }\r\n  void reset(T* p = 0)\r\n  {\r\n    if (p != _p)\r\n      delete _p;\r\n    _p = p;\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/Buffer.h",
    "content": "// Common/Buffer.h\r\n\r\n#ifndef __COMMON_BUFFER_H\r\n#define __COMMON_BUFFER_H\r\n\r\n#include \"Defs.h\"\r\n\r\ntemplate <class T> class CBuffer\r\n{    \r\nprotected:\r\n  size_t _capacity;\r\n  T *_items;\r\npublic:\r\n  void Free()\r\n  {\r\n    delete []_items;\r\n    _items = 0;\r\n    _capacity = 0;\r\n  }\r\n  CBuffer(): _capacity(0), _items(0) {};\r\n  CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }\r\n  CBuffer(size_t size): _items(0),  _capacity(0) {  SetCapacity(size); }\r\n  virtual ~CBuffer() { delete []_items; }\r\n  operator T *() { return _items; };\r\n  operator const T *() const { return _items; };\r\n  size_t GetCapacity() const { return  _capacity; }\r\n  void SetCapacity(size_t newCapacity)\r\n  {\r\n    if (newCapacity == _capacity)\r\n      return;\r\n    T *newBuffer;\r\n    if (newCapacity > 0)\r\n    {\r\n      newBuffer = new T[newCapacity];\r\n      if(_capacity > 0)\r\n        memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));\r\n    }\r\n    else\r\n      newBuffer = 0;\r\n    delete []_items;\r\n    _items = newBuffer;\r\n    _capacity = newCapacity;\r\n  }\r\n  CBuffer& operator=(const CBuffer &buffer)\r\n  {\r\n    Free();\r\n    if(buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nbool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  if (b1.GetCapacity() != b2.GetCapacity())\r\n    return false;\r\n  for (size_t i = 0; i < b1.GetCapacity(); i++)\r\n    if (b1[i] != b2[i])\r\n      return false;\r\n  return true;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  return !(b1 == b2);\r\n}\r\n\r\ntypedef CBuffer<char> CCharBuffer;\r\ntypedef CBuffer<wchar_t> CWCharBuffer;\r\ntypedef CBuffer<unsigned char> CByteBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../C/7zCrc.h\"\r\n}\r\n\r\nclass CCRCTableInit\r\n{\r\npublic:\r\n  CCRCTableInit() { CrcGenerateTable(); }\r\n} g_CRCTableInit;\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nbool CInFile::OpenShared(const char *name, bool)\r\n{\r\n  return Open(name);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nbool COutFile::Open(const char *name, DWORD creationDisposition)\r\n{\r\n  return Create(name, false);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  bool OpenShared(const char *name, bool shareForWrite);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  bool Open(const char *name, DWORD creationDisposition);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else \r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  for (;;)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      break;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{ \r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */); \r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms, \r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0) \r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while(pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len) \r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString: \r\n      case NSwitchType::kUnLimitedPostString: \r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for(int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString)\r\n{\r\n  for(int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if(commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"MyString.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  { \r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms); \r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms, \r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/DynamicBuffer.h",
    "content": "// Common/DynamicBuffer.h\r\n\r\n#ifndef __COMMON_DYNAMICBUFFER_H\r\n#define __COMMON_DYNAMICBUFFER_H\r\n\r\n#include \"Buffer.h\"\r\n\r\ntemplate <class T> class CDynamicBuffer: public CBuffer<T>\r\n{    \r\n  void GrowLength(size_t size)\r\n  {\r\n    size_t delta;\r\n    if (this->_capacity > 64)\r\n      delta = this->_capacity / 4;\r\n    else if (this->_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    delta = MyMax(delta, size);\r\n    SetCapacity(this->_capacity + delta);\r\n  }\r\npublic:\r\n  CDynamicBuffer(): CBuffer<T>() {};\r\n  CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};\r\n  CDynamicBuffer(size_t size): CBuffer<T>(size) {};\r\n  CDynamicBuffer& operator=(const CDynamicBuffer &buffer)\r\n  {\r\n    this->Free();\r\n    if(buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n  void EnsureCapacity(size_t capacity)\r\n  {\r\n    if (this->_capacity < capacity)\r\n      GrowLength(capacity - this->_capacity);\r\n  }\r\n};\r\n\r\ntypedef CDynamicBuffer<char> CCharDynamicBuffer;\r\ntypedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;\r\ntypedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/IntToString.cpp",
    "content": "// Common/IntToString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"IntToString.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)\r\n{\r\n  if (base < 2 || base > 36)\r\n  {\r\n    *s = '\\0';\r\n    return;\r\n  }\r\n  char temp[72];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    int delta = (int)(value % base);\r\n    temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));\r\n    value /= base;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while(pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s)\r\n{\r\n  wchar_t temp[32];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do \r\n    *s++ = temp[--pos];\r\n  while(pos > 0);\r\n  *s = L'\\0';\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = '-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = L'-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/IntToString.h",
    "content": "// Common/IntToString.h\r\n\r\n#ifndef __COMMON_INTTOSTRING_H\r\n#define __COMMON_INTTOSTRING_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s);\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s);\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/ListFileUtils.cpp",
    "content": "// Common/ListFileUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Windows/FileIO.h\"\r\n\r\n#include \"ListFileUtils.h\"\r\n#include \"StringConvert.h\"\r\n#include \"UTFConvert.h\"\r\n\r\nstatic const char kQuoteChar     = '\\\"';\r\nstatic void RemoveQuote(UString &s)\r\n{\r\n  if (s.Length() >= 2)\r\n    if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)\r\n      s = s.Mid(1, s.Length() - 2);\r\n}\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)\r\n{\r\n  NWindows::NFile::NIO::CInFile file;\r\n  if (!file.Open(fileName))\r\n    return false;\r\n  UInt64 length;\r\n  if (!file.GetLength(length))\r\n    return false;\r\n  if (length > ((UInt32)1 << 31))\r\n    return false;\r\n  AString s;\r\n  char *p = s.GetBuffer((int)length + 1);\r\n  UInt32 processed;\r\n  if (!file.Read(p, (UInt32)length, processed))\r\n    return false;\r\n  p[(UInt32)length] = 0;\r\n  s.ReleaseBuffer();\r\n  file.Close();\r\n\r\n  UString u;\r\n  #ifdef CP_UTF8\r\n  if (codePage == CP_UTF8)\r\n  {\r\n    if (!ConvertUTF8ToUnicode(s, u))\r\n      return false;\r\n  }\r\n  else\r\n  #endif\r\n    u = MultiByteToUnicodeString(s, codePage);\r\n  if (!u.IsEmpty())\r\n  {\r\n    if (u[0] == 0xFEFF)\r\n      u.Delete(0);\r\n  }\r\n\r\n  UString t;\r\n  for(int i = 0; i < u.Length(); i++)\r\n  {\r\n    wchar_t c = u[i];\r\n    if (c == L'\\n' || c == 0xD)\r\n    {\r\n      t.Trim();\r\n      RemoveQuote(t);\r\n      if (!t.IsEmpty())\r\n        resultStrings.Add(t);\r\n      t.Empty();\r\n    }\r\n    else\r\n      t += c;\r\n  }\r\n  t.Trim();\r\n  RemoveQuote(t);\r\n  if (!t.IsEmpty())\r\n    resultStrings.Add(t);\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/ListFileUtils.h",
    "content": "// Common/ListFileUtils.h\r\n\r\n#ifndef __COMMON_LISTFILEUTILS_H\r\n#define __COMMON_LISTFILEUTILS_H\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }\r\n#endif\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p) \r\n  { \r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p) \r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR() { m_str = NULL; }\r\n  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR pSrc)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(pSrc);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const \r\n  { \r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memmove(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  void Attach(BSTR src) {  m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) { \r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \\\r\n    { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \\\r\n    MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n    MY_QUERYINTERFACE_ENTRY(i)\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyException.h",
    "content": "// Common/Exception.h\r\n\r\n#ifndef __COMMON_EXCEPTION_H\r\n#define __COMMON_EXCEPTION_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\nstruct CSystemException\r\n{\r\n  HRESULT ErrorCode;\r\n  CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline int operator==(REFGUID g1, REFGUID g2)\r\n{ \r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return 0;\r\n  return 1;\r\n}\r\ninline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyString.cpp",
    "content": "// Common/MyString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"StringConvert.h\"\r\n#else\r\n#include <ctype.h>\r\n#endif\r\n\r\n#include \"MyString.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{ \r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1), \r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), \r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{ \r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyString.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{ \r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{ \r\n  T *destStart = dest;\r\n  while((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char  *s2);\r\n#endif\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex, \r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n  int _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if(realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if(newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if(_capacity > 0)\r\n    {\r\n      for (int i = 0; i < (_length + 1); i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n      _chars = newBuffer;\r\n    }\r\n    else\r\n    {\r\n      _chars = newBuffer;\r\n      _chars[0] = 0;\r\n    }\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize) \r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0)\r\n    { SetCapacity(16 - 1); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;} \r\n\r\n  // The minimum size of the character buffer in characters. \r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if(minBufLength >= _capacity)\r\n      SetCapacity(minBufLength + 1);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if(newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length; \r\n    return *this;\r\n  }  \r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if(&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int Compare(const T *s) const\r\n    { return MyStringCompare(_chars, s); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const T *s) const\r\n    { return MyStringCompareNoCase(_chars, s); }\r\n\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for(int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    charSet += (T)' ';\r\n    charSet += (T)'\\n';\r\n    charSet += (T)'\\t';\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for(int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0) \r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0) \r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct \r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else \r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyVector.cpp",
    "content": "// Common/MyVector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector() { Free(); }\r\n\r\nvoid CBaseRecordVector::Free()\r\n{ \r\n  delete []((unsigned char *)_items); \r\n  _capacity = 0;\r\n  _size = 0;\r\n  _items = 0;\r\n}\r\n\r\nvoid CBaseRecordVector::Clear() { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index) { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if (_size != _capacity)\r\n    return;\r\n  int delta;\r\n  if (_capacity > 64)\r\n    delta = _capacity / 2;\r\n  else if (_capacity > 8)\r\n    delta = 8;\r\n  else\r\n    delta = 4;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  if (newCapacity <= _capacity)\r\n    return;\r\n  if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))\r\n    throw 1052353;\r\n  size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;\r\n  if (newSize / _itemSize != (size_t)(unsigned)newCapacity)\r\n    throw 1052354;\r\n  unsigned char *p = new unsigned char[newSize];\r\n  if (p == 0)\r\n    throw 1052355;\r\n  int numRecordsToMove = _capacity;\r\n  memmove(p, _items, _itemSize * numRecordsToMove);\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize, \r\n    ((unsigned char  *)_items) + srcIndex * _itemSize, \r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyVector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n  int _capacity;\r\n  int _size;\r\n  void *_items;\r\n  size_t _itemSize;\r\n  \r\n  void ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; } \r\npublic:\r\n  CBaseRecordVector(size_t itemSize):\r\n      _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n  virtual ~CBaseRecordVector();\r\n  void Free();\r\n  int Size() const { return _size; }\r\n  bool IsEmpty() const { return (_size == 0); }\r\n  void Reserve(int newCapacity);\r\n  virtual void Delete(int index, int num = 1);\r\n  void Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector():CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v):\r\n    CBaseRecordVector(sizeof(T)) { *this = v;}\r\n  CRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  int Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n  void Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n  T& operator[](int index) { return ((T *)_items)[index]; }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Front()   { return operator[](0); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  T& Back()   { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  int AddToUniqueSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)\r\n  { \r\n    T temp = p[k];\r\n    for (;;)\r\n    {\r\n      int s = (k << 1);\r\n      if (s > size)\r\n        break;\r\n      if (s < size && compare(p + s + 1, p + s, param) > 0)\r\n        s++;\r\n      if (compare(&temp, p + s, param) >= 0)\r\n        break;\r\n      p[k] = p[s]; \r\n      k = s;\r\n    } \r\n    p[k] = temp; \r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    int size = _size;\r\n    if (size <= 1)\r\n      return;\r\n    T* p = (&Front()) - 1;\r\n    {\r\n      int i = size / 2;\r\n      do\r\n        SortRefDown(p, i, size, compare, param);\r\n      while(--i != 0);\r\n    }\r\n    do\r\n    {\r\n      T temp = p[size];\r\n      p[size--] = p[1];\r\n      p[1] = temp;\r\n      SortRefDown(p, 1, size, compare, param);\r\n    }\r\n    while (size > 1);\r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector(){};\r\n  ~CObjectVector() { Clear(); }\r\n  CObjectVector(const CObjectVector &objectVector)\r\n    { *this = objectVector; }\r\n  CObjectVector& operator=(const CObjectVector &objectVector)\r\n  {\r\n    Clear();\r\n    return (*this += objectVector);\r\n  }\r\n  CObjectVector& operator+=(const CObjectVector &objectVector)\r\n  {\r\n    int size = objectVector.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(objectVector[i]);\r\n    return *this;\r\n  }\r\n  const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n  T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Back() { return operator[](_size - 1); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  int Add(const T& item)\r\n    { return CPointerVector::Add(new T(item)); }\r\n  void Insert(int index, const T& item)\r\n    { CPointerVector::Insert(index, new T(item)); }\r\n  virtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for(int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for(int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n      return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param) \r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#define CHAR_PATH_SEPARATOR '\\\\'\r\n#define WCHAR_PATH_SEPARATOR L'\\\\'\r\n#define STRING_PATH_SEPARATOR \"\\\\\"\r\n#define WSTRING_PATH_SEPARATOR L\"\\\\\"\r\n\r\n#else\r\n\r\n#define CHAR_PATH_SEPARATOR '/'\r\n#define WCHAR_PATH_SEPARATOR L'/'\r\n#define STRING_PATH_SEPARATOR \"/\"\r\n#define WSTRING_PATH_SEPARATOR L\"/\"\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\n\r\n#undef BYTE\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\n\r\n#undef WORD\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\n\r\n#undef DWORD\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOTIMPL ((HRESULT)0x80004001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall \r\n#else\r\n#define STDMETHODCALLTYPE \r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct \r\n\r\n#ifdef __cplusplus\r\n\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n  #ifndef _WIN32\r\n  virtual ~IUnknown() {}\r\n  #endif\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#endif\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\r\n  VT_EMPTY = 0,\r\n  VT_NULL = 1,\r\n  VT_I2 = 2,\r\n  VT_I4 = 3,\r\n  VT_R4 = 4,\r\n  VT_R8 = 5,\r\n  VT_CY = 6,\r\n  VT_DATE = 7,\r\n  VT_BSTR = 8,\r\n  VT_DISPATCH = 9,\r\n  VT_ERROR = 10,\r\n  VT_BOOL = 11,\r\n  VT_VARIANT = 12,\r\n  VT_UNKNOWN = 13,\r\n  VT_DECIMAL = 14,\r\n  VT_I1 = 16,\r\n  VT_UI1 = 17,\r\n  VT_UI2 = 18,\r\n  VT_UI4 = 19,\r\n  VT_I8 = 20,\r\n  VT_UI8 = 21,\r\n  VT_INT = 22,\r\n  VT_UINT = 23,\r\n  VT_VOID = 24,\r\n  VT_HRESULT = 25,\r\n  VT_FILETIME = 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\n#ifdef __cplusplus\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union \r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\n\r\n#endif\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\r\n  STREAM_SEEK_SET = 0,\r\n  STREAM_SEEK_CUR = 1,\r\n  STREAM_SEEK_END = 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\n#ifdef _WIN32\r\nvoid * \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n#endif\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\n#ifdef _WIN32\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw();\r\n#endif \r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/StdInStream.cpp",
    "content": "// Common/StdInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n#include \"StdInStream.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kIllegalChar = '\\0';\r\nstatic const char kNewLineChar = '\\n';\r\n\r\nstatic const char *kEOFMessage = \"Unexpected end of input stream\";\r\nstatic const char *kReadErrorMessage  =\"Error reading input stream\"; \r\nstatic const char *kIllegalCharMessage = \"Illegal character in input stream\";\r\n\r\nstatic LPCTSTR kFileOpenMode = TEXT(\"r\");\r\n\r\nCStdInStream g_StdIn(stdin);\r\n\r\nbool CStdInStream::Open(LPCTSTR fileName)\r\n{\r\n  Close();\r\n  _stream = _tfopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdInStream::Close()\r\n{\r\n  if(!_streamIsOpen)\r\n    return true;\r\n  _streamIsOpen = (fclose(_stream) != 0);\r\n  return !_streamIsOpen;\r\n}\r\n\r\nCStdInStream::~CStdInStream()\r\n{\r\n  Close();\r\n}\r\n\r\nAString CStdInStream::ScanStringUntilNewLine()\r\n{\r\n  AString s;\r\n  for (;;)\r\n  {\r\n    int intChar = GetChar();\r\n    if(intChar == EOF)\r\n      throw kEOFMessage;\r\n    char c = char(intChar);\r\n    if (c == kIllegalChar)\r\n      throw kIllegalCharMessage;\r\n    if(c == kNewLineChar)\r\n      break;\r\n    s += c;\r\n  }\r\n  return s;\r\n}\r\n\r\nvoid CStdInStream::ReadToString(AString &resultString)\r\n{\r\n  resultString.Empty();\r\n  int c;\r\n  while((c = GetChar()) != EOF)\r\n    resultString += char(c);\r\n}\r\n\r\nbool CStdInStream::Eof()\r\n{\r\n  return (feof(_stream) != 0);\r\n}\r\n\r\nint CStdInStream::GetChar()\r\n{\r\n  int c = fgetc(_stream); // getc() doesn't work in BeOS?\r\n  if(c == EOF && !Eof())\r\n    throw kReadErrorMessage;\r\n  return c;\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/StdInStream.h",
    "content": "// Common/StdInStream.h\r\n\r\n#ifndef __COMMON_STDINSTREAM_H\r\n#define __COMMON_STDINSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nclass CStdInStream \r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdInStream(): _streamIsOpen(false) {};\r\n  CStdInStream(FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdInStream();\r\n  bool Open(LPCTSTR fileName);\r\n  bool Close();\r\n\r\n  AString ScanStringUntilNewLine();\r\n  void ReadToString(AString &resultString);\r\n\r\n  bool Eof();\r\n  int GetChar();\r\n};\r\n\r\nextern CStdInStream g_StdIn;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/StdOutStream.cpp",
    "content": "// Common/StdOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n\r\n#include \"StdOutStream.h\"\r\n#include \"IntToString.h\"\r\n#include \"StringConvert.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kNewLineChar =  '\\n';\r\n\r\nstatic const char *kFileOpenMode = \"wt\";\r\n\r\nCStdOutStream  g_StdOut(stdout);\r\nCStdOutStream  g_StdErr(stderr);\r\n\r\nbool CStdOutStream::Open(const char *fileName)\r\n{\r\n  Close();\r\n  _stream = fopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdOutStream::Close()\r\n{\r\n  if(!_streamIsOpen)\r\n    return true;\r\n  if (fclose(_stream) != 0)\r\n    return false;\r\n  _stream = 0;\r\n  _streamIsOpen = false;\r\n  return true;\r\n}\r\n\r\nbool CStdOutStream::Flush()\r\n{\r\n  return (fflush(_stream) == 0);\r\n}\r\n\r\nCStdOutStream::~CStdOutStream ()\r\n{\r\n  Close();\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream  &))\r\n{\r\n  (*aFunction)(*this);    \r\n  return *this;\r\n}\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream)\r\n{\r\n  return outStream << kNewLineChar;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const char *string)\r\n{\r\n  fputs(string, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const wchar_t *string)\r\n{\r\n  *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(char c)\r\n{\r\n  fputc(c, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(int number)\r\n{\r\n  char textString[32];\r\n  ConvertInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(UInt64 number)\r\n{\r\n  char textString[32];\r\n  ConvertUInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/StdOutStream.h",
    "content": "// Common/StdOutStream.h\r\n\r\n#ifndef __COMMON_STDOUTSTREAM_H\r\n#define __COMMON_STDOUTSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Types.h\"\r\n\r\nclass CStdOutStream \r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdOutStream (): _streamIsOpen(false), _stream(0) {};\r\n  CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdOutStream ();\r\n  operator FILE *() { return _stream; }\r\n  bool Open(const char *fileName);\r\n  bool Close();\r\n  bool Flush();\r\n  CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream  &));\r\n  CStdOutStream & operator<<(const char *string);\r\n  CStdOutStream & operator<<(const wchar_t *string);\r\n  CStdOutStream & operator<<(char c);\r\n  CStdOutStream & operator<<(int number);\r\n  CStdOutStream & operator<<(UInt64 number);\r\n};\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream);\r\n\r\nextern CStdOutStream g_StdOut;\r\nextern CStdOutStream g_StdErr;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()), \r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 2;\r\n    char defaultChar = '_';\r\n    int numChars = WideCharToMultiByte(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(numRequiredBytes), \r\n      numRequiredBytes + 1, &defaultChar, NULL);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_INT16_DEFINED\r\n#define _7ZIP_INT16_DEFINED\r\ntypedef short Int16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_INT32_DEFINED\r\n#define _7ZIP_INT32_DEFINED\r\ntypedef int Int32;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\ntypedef unsigned int UInt32;\r\n#endif \r\n\r\n#ifdef _MSC_VER\r\n\r\n#ifndef _7ZIP_INT64_DEFINED\r\n#define _7ZIP_INT64_DEFINED\r\ntypedef __int64 Int64;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\ntypedef unsigned __int64 UInt64;\r\n#endif \r\n\r\n#else\r\n\r\n#ifndef _7ZIP_INT64_DEFINED\r\n#define _7ZIP_INT64_DEFINED\r\ntypedef long long int Int64;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\ntypedef unsigned long long int UInt64;\r\n#endif \r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/UTFConvert.cpp",
    "content": "// UTFConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UTFConvert.h\"\r\n#include \"Types.h\"\r\n\r\nstatic Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\n// These functions are for UTF8 <-> UTF16 conversion.\r\n\r\nbool ConvertUTF8ToUnicode(const AString &src, UString &dest)\r\n{\r\n  dest.Empty();\r\n  for(int i = 0; i < src.Length();)\r\n  {\r\n    Byte c = (Byte)src[i++];\r\n    if (c < 0x80)\r\n    {\r\n      dest += (wchar_t)c;\r\n      continue;\r\n    }\r\n    if(c < 0xC0)\r\n      return false;\r\n    int numAdds;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (c < kUtf8Limits[numAdds])\r\n        break;\r\n    UInt32 value = (c - kUtf8Limits[numAdds - 1]);\r\n    do\r\n    {\r\n      if (i >= src.Length())\r\n        return false;\r\n      Byte c2 = (Byte)src[i++];\r\n      if (c2 < 0x80 || c2 >= 0xC0)\r\n        return false;\r\n      value <<= 6;\r\n      value |= (c2 - 0x80);\r\n      numAdds--;\r\n    }\r\n    while(numAdds > 0);\r\n    if (value < 0x10000)\r\n      dest += (wchar_t)(value);\r\n    else\r\n    {\r\n      value -= 0x10000;\r\n      if (value >= 0x100000)\r\n        return false;\r\n      dest += (wchar_t)(0xD800 + (value >> 10));\r\n      dest += (wchar_t)(0xDC00 + (value & 0x3FF));\r\n    }\r\n  }\r\n  return true; \r\n}\r\n\r\nbool ConvertUnicodeToUTF8(const UString &src, AString &dest)\r\n{\r\n  dest.Empty();\r\n  for(int i = 0; i < src.Length();)\r\n  {\r\n    UInt32 value = (UInt32)src[i++];\r\n    if (value < 0x80)\r\n    {\r\n      dest += (char)value;\r\n      continue;\r\n    }\r\n    if (value >= 0xD800 && value < 0xE000)\r\n    {\r\n      if (value >= 0xDC00)\r\n        return false;\r\n      if (i >= src.Length())\r\n        return false;\r\n      UInt32 c2 = (UInt32)src[i++];\r\n      if (c2 < 0xDC00 || c2 >= 0xE000)\r\n        return false;\r\n      value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n    }\r\n    int numAdds;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n        break;\r\n    dest += (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n    do\r\n    {\r\n      numAdds--;\r\n      dest += (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n    }\r\n    while(numAdds > 0);\r\n  }\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/UTFConvert.h",
    "content": "// Common/UTFConvert.h\r\n\r\n#ifndef __COMMON_UTFCONVERT_H\r\n#define __COMMON_UTFCONVERT_H\r\n\r\n#include \"MyString.h\"\r\n\r\nbool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);\r\nbool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/Wildcard.cpp",
    "content": "// Common/Wildcard.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Wildcard.h\"\r\n\r\nbool g_CaseSensitive = \r\n  #ifdef _WIN32\r\n    false;\r\n  #else\r\n    true;\r\n  #endif\r\n\r\nstatic const wchar_t kAnyCharsChar = L'*';\r\nstatic const wchar_t kAnyCharChar = L'?';\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t kDirDelimiter1 = L'\\\\';\r\n#endif\r\nstatic const wchar_t kDirDelimiter2 = L'/';\r\n\r\nstatic const UString kWildCardCharSet = L\"?*\";\r\n\r\nstatic const UString kIllegalWildCardFileNameChars=\r\n  L\"\\x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\xA\\xB\\xC\\xD\\xE\\xF\"\r\n  L\"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F\"\r\n  L\"\\\"/:<>\\\\|\";\r\n\r\n\r\nstatic inline bool IsCharDirLimiter(wchar_t c)\r\n{\r\n  return (\r\n    #ifdef _WIN32\r\n    c == kDirDelimiter1 || \r\n    #endif\r\n    c == kDirDelimiter2);\r\n}\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2)\r\n{\r\n  if (g_CaseSensitive)\r\n    return s1.Compare(s2);\r\n  return s1.CompareNoCase(s2);\r\n}\r\n\r\n// -----------------------------------------\r\n// this function compares name with mask\r\n// ? - any char\r\n// * - any char or empty\r\n\r\nstatic bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t m = *mask;\r\n    wchar_t c = *name;\r\n    if (m == 0) \r\n      return (c == 0);\r\n    if (m == kAnyCharsChar)\r\n    {\r\n      if (EnhancedMaskTest(mask + 1, name))\r\n        return true;\r\n      if (c == 0) \r\n        return false;\r\n    }\r\n    else\r\n    {\r\n      if (m == kAnyCharChar)\r\n      {\r\n        if (c == 0) \r\n          return false;\r\n      }\r\n      else if (m != c)\r\n        if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))\r\n          return false;\r\n      mask++;\r\n    }\r\n    name++;\r\n  }\r\n}\r\n\r\n// --------------------------------------------------\r\n// Splits path to strings\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts)\r\n{\r\n  pathParts.Clear();\r\n  UString name;\r\n  int len = path.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = path[i];\r\n    if (IsCharDirLimiter(c))\r\n    {\r\n      pathParts.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  pathParts.Add(name);\r\n}\r\n\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)\r\n{\r\n  int i;\r\n  for(i = path.Length() - 1; i >= 0; i--)\r\n    if(IsCharDirLimiter(path[i]))\r\n      break;\r\n  dirPrefix = path.Left(i + 1);\r\n  name = path.Mid(i + 1);\r\n}\r\n\r\nUString ExtractDirPrefixFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for(i = path.Length() - 1; i >= 0; i--)\r\n    if(IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Left(i + 1);\r\n}\r\n\r\nUString ExtractFileNameFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for(i = path.Length() - 1; i >= 0; i--)\r\n    if(IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Mid(i + 1);\r\n}\r\n\r\n\r\nbool CompareWildCardWithName(const UString &mask, const UString &name)\r\n{\r\n  return EnhancedMaskTest(mask, name);\r\n}\r\n\r\nbool DoesNameContainWildCard(const UString &path)\r\n{\r\n  return (path.FindOneOf(kWildCardCharSet) >= 0);\r\n}\r\n\r\n\r\n// ----------------------------------------------------------'\r\n// NWildcard\r\n\r\nnamespace NWildcard {\r\n\r\n\r\n/*\r\nM = MaskParts.Size();\r\nN = TestNameParts.Size();\r\n\r\n                           File                          Dir\r\nForFile     req   M<=N  [N-M, N)                          -\r\n         nonreq   M=N   [0, M)                            -  \r\n \r\nForDir      req   M<N   [0, M) ... [N-M-1, N-1)  same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\nForBoth     req   m<=N  [0, M) ... [N-M, N)      same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\n*/\r\n\r\nbool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (!isFile && !ForDir)\r\n    return false;\r\n  int delta = (int)pathParts.Size() - (int)PathParts.Size();\r\n  if (delta < 0)\r\n    return false;\r\n  int start = 0;\r\n  int finish = 0;\r\n  if (isFile)\r\n  {\r\n    if (!ForDir && !Recursive && delta !=0)\r\n      return false;\r\n    if (!ForFile && delta == 0)\r\n      return false;\r\n    if (!ForDir && Recursive)\r\n      start = delta;\r\n  }\r\n  if (Recursive)\r\n  {\r\n    finish = delta;\r\n    if (isFile && !ForFile)\r\n      finish = delta - 1;\r\n  }\r\n  for (int d = start; d <= finish; d++)\r\n  {\r\n    int i;\r\n    for (i = 0; i < PathParts.Size(); i++)\r\n      if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))\r\n        break;\r\n    if (i == PathParts.Size())\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nint CCensorNode::FindSubNode(const UString &name) const\r\n{\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (CompareFileNames(SubNodes[i].Name, name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensorNode::AddItemSimple(bool include, CItem &item)\r\n{\r\n  if (include)\r\n    IncludeItems.Add(item);\r\n  else\r\n    ExcludeItems.Add(item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, CItem &item)\r\n{\r\n  if (item.PathParts.Size() <= 1)\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  const UString &front = item.PathParts.Front();\r\n  if (DoesNameContainWildCard(front))\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  int index = FindSubNode(front);\r\n  if (index < 0)\r\n    index = SubNodes.Add(CCensorNode(front, this));\r\n  item.PathParts.Delete(0);\r\n  SubNodes[index].AddItem(include, item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)\r\n{\r\n  CItem item;\r\n  SplitPathToParts(path, item.PathParts);\r\n  item.Recursive = recursive;\r\n  item.ForFile = forFile;\r\n  item.ForDir = forDir;\r\n  AddItem(include, item);\r\n}\r\n\r\nbool CCensorNode::NeedCheckSubDirs() const\r\n{\r\n  for (int i = 0; i < IncludeItems.Size(); i++)\r\n  {\r\n    const CItem &item = IncludeItems[i];\r\n    if (item.Recursive || item.PathParts.Size() > 1)\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::AreThereIncludeItems() const\r\n{\r\n  if (IncludeItems.Size() > 0)\r\n    return true;\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (SubNodes[i].AreThereIncludeItems())\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const\r\n{\r\n  const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;\r\n  for (int i = 0; i < items.Size(); i++)\r\n    if (items[i].CheckPath(pathParts, isFile))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const\r\n{\r\n  if (CheckPathCurrent(false, pathParts, isFile))\r\n  {\r\n    include = false;\r\n    return true;\r\n  }\r\n  include = true;\r\n  bool finded = CheckPathCurrent(true, pathParts, isFile);\r\n  if (pathParts.Size() == 1)\r\n    return finded;\r\n  int index = FindSubNode(pathParts.Front());\r\n  if (index >= 0)\r\n  {\r\n    UStringVector pathParts2 = pathParts;\r\n    pathParts2.Delete(0);\r\n    if (SubNodes[index].CheckPath(pathParts2, isFile, include))\r\n      return true;\r\n  }\r\n  return finded;\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const\r\n{\r\n  UStringVector pathParts; \r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPath(pathParts, isFile, include);\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool include;\r\n  if(CheckPath(path, isFile, include))\r\n    return include;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (CheckPathCurrent(include, pathParts, isFile))\r\n    return true;\r\n  if (Parent == 0)\r\n    return false;\r\n  pathParts.Insert(0, Name);\r\n  return Parent->CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n\r\n/*\r\nbool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const\r\n{\r\n  UStringVector pathParts; \r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n*/\r\n\r\nvoid CCensorNode::AddItem2(bool include, const UString &path, bool recursive)\r\n{\r\n  if (path.IsEmpty())\r\n    return;\r\n  bool forFile = true;\r\n  bool forFolder = true;\r\n  UString path2 = path;\r\n  if (IsCharDirLimiter(path[path.Length() - 1]))\r\n  {\r\n    path2.Delete(path.Length() - 1);\r\n    forFile = false;\r\n  }\r\n  AddItem(include, path2, recursive, forFile, forFolder);\r\n}\r\n\r\nvoid CCensorNode::ExtendExclude(const CCensorNode &fromNodes)\r\n{\r\n  ExcludeItems += fromNodes.ExcludeItems;\r\n  for (int i = 0; i < fromNodes.SubNodes.Size(); i++)\r\n  {\r\n    const CCensorNode &node = fromNodes.SubNodes[i];\r\n    int subNodeIndex = FindSubNode(node.Name);\r\n    if (subNodeIndex < 0)\r\n      subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));\r\n    SubNodes[subNodeIndex].ExtendExclude(node);\r\n  }\r\n}\r\n\r\nint CCensor::FindPrefix(const UString &prefix) const\r\n{\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n    if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensor::AddItem(bool include, const UString &path, bool recursive)\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  bool forFile = true;\r\n  if (pathParts.Back().IsEmpty())\r\n  {\r\n    forFile = false;\r\n    pathParts.DeleteBack();\r\n  }\r\n  const UString &front = pathParts.Front();\r\n  bool isAbs = false;\r\n  if (front.IsEmpty())\r\n    isAbs = true;\r\n  else if (front.Length() == 2 && front[1] == L':')\r\n    isAbs = true;\r\n  else\r\n  {\r\n    for (int i = 0; i < pathParts.Size(); i++)\r\n    {\r\n      const UString &part = pathParts[i];\r\n      if (part == L\"..\" || part == L\".\")\r\n      {\r\n        isAbs = true;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  int numAbsParts = 0;\r\n  if (isAbs)\r\n    if (pathParts.Size() > 1)\r\n      numAbsParts = pathParts.Size() - 1;\r\n    else\r\n      numAbsParts = 1;\r\n  UString prefix;\r\n  for (int i = 0; i < numAbsParts; i++)\r\n  {\r\n    const UString &front = pathParts.Front();\r\n    if (DoesNameContainWildCard(front))\r\n      break;\r\n    prefix += front;\r\n    prefix += WCHAR_PATH_SEPARATOR;\r\n    pathParts.Delete(0);\r\n  }\r\n  int index = FindPrefix(prefix);\r\n  if (index < 0)\r\n    index = Pairs.Add(CPair(prefix));\r\n\r\n  CItem item;\r\n  item.PathParts = pathParts;\r\n  item.ForDir = true;\r\n  item.ForFile = forFile;\r\n  item.Recursive = recursive;\r\n  Pairs[index].Head.AddItem(include, item);\r\n}\r\n\r\nbool CCensor::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool finded = false;\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n  {\r\n    bool include;\r\n    if (Pairs[i].Head.CheckPath(path, isFile, include))\r\n    {\r\n      if (!include)\r\n        return false;\r\n      finded = true;\r\n    }\r\n  }\r\n  return finded;\r\n}\r\n\r\nvoid CCensor::ExtendExclude()\r\n{\r\n  int i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (Pairs[i].Prefix.IsEmpty())\r\n      break;\r\n  if (i == Pairs.Size())\r\n    return;\r\n  int index = i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (index != i)\r\n      Pairs[i].Head.ExtendExclude(Pairs[index].Head);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Common/Wildcard.h",
    "content": "// Common/Wildcard.h\r\n\r\n#ifndef __COMMON_WILDCARD_H\r\n#define __COMMON_WILDCARD_H\r\n\r\n#include \"MyString.h\"\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2);\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts);\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);\r\nUString ExtractDirPrefixFromPath(const UString &path);\r\nUString ExtractFileNameFromPath(const UString &path);\r\nbool DoesNameContainWildCard(const UString &path);\r\nbool CompareWildCardWithName(const UString &mask, const UString &name);\r\n\r\nnamespace NWildcard {\r\n\r\nstruct CItem\r\n{\r\n  UStringVector PathParts;\r\n  bool Recursive;\r\n  bool ForFile;\r\n  bool ForDir;\r\n  bool CheckPath(const UStringVector &pathParts, bool isFile) const;\r\n};\r\n\r\nclass CCensorNode\r\n{\r\n  CCensorNode *Parent;\r\n  bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;\r\n  void AddItemSimple(bool include, CItem &item);\r\n  bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;\r\npublic:\r\n  CCensorNode(): Parent(0) { };\r\n  CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };\r\n  UString Name;\r\n  CObjectVector<CCensorNode> SubNodes;\r\n  CObjectVector<CItem> IncludeItems;\r\n  CObjectVector<CItem> ExcludeItems;\r\n\r\n  int FindSubNode(const UString &path) const;\r\n\r\n  void AddItem(bool include, CItem &item);\r\n  void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);\r\n  void AddItem2(bool include, const UString &path, bool recursive);\r\n\r\n  bool NeedCheckSubDirs() const;\r\n  bool AreThereIncludeItems() const;\r\n\r\n  bool CheckPath(const UString &path, bool isFile, bool &include) const;\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n\r\n  bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;\r\n  // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;\r\n  void ExtendExclude(const CCensorNode &fromNodes);\r\n};\r\n\r\nstruct CPair\r\n{\r\n  UString Prefix;\r\n  CCensorNode Head;\r\n  CPair(const UString &prefix): Prefix(prefix) { };\r\n};\r\n\r\nclass CCensor\r\n{\r\n  int FindPrefix(const UString &prefix) const;\r\npublic:\r\n  CObjectVector<CPair> Pairs;\r\n  bool AllAreRelative() const\r\n    { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }\r\n  void AddItem(bool include, const UString &path, bool recursive);\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n  void ExtendExclude();\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/DLL.cpp",
    "content": "// Windows/DLL.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DLL.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nCLibrary::~CLibrary()\r\n{\r\n  Free();\r\n}\r\n\r\nbool CLibrary::Free()\r\n{\r\n  if (_module == 0)\r\n    return true;\r\n  // MessageBox(0, TEXT(\"\"), TEXT(\"Free\"), 0);\r\n  // Sleep(5000);\r\n  if (!::FreeLibrary(_module))\r\n    return false;\r\n  _module = 0;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadOperations(HMODULE newModule)\r\n{\r\n  if (newModule == NULL)\r\n    return false;\r\n  if(!Free())\r\n    return false;\r\n  _module = newModule;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"LoadEx\"), 0);\r\n  return LoadOperations(::LoadLibraryEx(fileName, NULL, flags));\r\n}\r\n\r\nbool CLibrary::Load(LPCTSTR fileName)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"Load\"), 0);\r\n  // Sleep(5000);\r\n  // OutputDebugString(fileName);\r\n  // OutputDebugString(TEXT(\"\\n\"));\r\n  return LoadOperations(::LoadLibrary(fileName));\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\nCSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n\r\nbool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));\r\n  return LoadEx(GetSysPath(fileName), flags);\r\n}\r\nbool CLibrary::Load(LPCWSTR fileName)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryW(fileName));\r\n  return Load(GetSysPath(fileName));\r\n}\r\n#endif\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result)\r\n{\r\n  result.Empty();\r\n  TCHAR fullPath[MAX_PATH + 2];\r\n  DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1);\r\n  if (size <= MAX_PATH && size != 0)\r\n  {\r\n    result = fullPath;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result)\r\n{\r\n  result.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    wchar_t fullPath[MAX_PATH + 2];\r\n    DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);\r\n    if (size <= MAX_PATH && size != 0)\r\n    {\r\n      result = fullPath;\r\n      return true;\r\n    }\r\n    return false;\r\n  }\r\n  CSysString resultSys;\r\n  if (!MyGetModuleFileName(hModule, resultSys))\r\n    return false;\r\n  result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());\r\n  return true;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/DLL.h",
    "content": "// Windows/DLL.h\r\n\r\n#ifndef __WINDOWS_DLL_H\r\n#define __WINDOWS_DLL_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nclass CLibrary\r\n{\r\n  bool LoadOperations(HMODULE newModule);\r\nprotected:\r\n  HMODULE _module;\r\npublic:\r\n  operator HMODULE() const { return _module; }\r\n  HMODULE* operator&() { return &_module; }\r\n\r\n  CLibrary():_module(NULL) {};\r\n  ~CLibrary();\r\n  void Attach(HMODULE m)\r\n  {\r\n    Free();\r\n    _module = m;\r\n  }\r\n  HMODULE Detach()\r\n  {\r\n    HMODULE m = _module;\r\n    _module = NULL;\r\n    return m;\r\n  }\r\n\r\n  // operator HMODULE() const { return _module; };\r\n  bool IsLoaded() const { return (_module != NULL); };\r\n  bool Free();\r\n  bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCWSTR fileName);\r\n  #endif\r\n  FARPROC GetProcAddress(LPCSTR procName) const\r\n    { return ::GetProcAddress(_module, procName); }\r\n};\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result);\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result);\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\n#ifdef _WIN32\r\ninline bool LRESULTToBool(LRESULT value)\r\n  { return (value != FALSE); }\r\n#endif\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/Error.cpp",
    "content": "// Windows/Error.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifndef _UNICODE\r\n#include \"Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message)\r\n{\r\n  LPVOID msgBuf;\r\n  if(::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r\n      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n      NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)\r\n    return false;\r\n  message = (LPCTSTR)msgBuf;\r\n  ::LocalFree(msgBuf);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyFormatMessage(DWORD messageID, UString &message)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPVOID msgBuf;\r\n    if(::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r\n        FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n        NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)\r\n      return false;\r\n    message = (LPCWSTR)msgBuf;\r\n    ::LocalFree(msgBuf);\r\n    return true;\r\n  }\r\n  CSysString messageSys;\r\n  bool result = MyFormatMessage(messageID, messageSys);\r\n  message = GetUnicodeString(messageSys);\r\n  return result;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/Error.h",
    "content": "// Windows/Error.h\r\n\r\n#ifndef __WINDOWS_ERROR_H\r\n#define __WINDOWS_ERROR_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message);\r\ninline CSysString MyFormatMessage(DWORD messageID)\r\n{\r\n  CSysString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#ifdef _UNICODE\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n  { return MyFormatMessage(messageID); }\r\n#else\r\nbool MyFormatMessage(DWORD messageID, UString &message);\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n{\r\n  UString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileDir.cpp",
    "content": "// Windows/FileDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileDir.h\"\r\n#include \"FileName.h\"\r\n#include \"FileFind.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n// SetCurrentDirectory doesn't support \\\\?\\ prefix\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR fileName, UString &res);\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n#endif\r\n\r\nnamespace NDirectory {\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\nstatic UString GetUnicodePath(const CSysString &sysPath)\r\n  { return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }\r\nstatic CSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\nbool MyGetSystemDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetWindowsDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n\r\nbool MyGetSystemDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetSystemDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n{\r\n  #ifndef _UNICODE\r\n  if (!g_IsNT)\r\n  {\r\n    ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\r\n    return false;\r\n  }\r\n  #endif \r\n  HANDLE hDir = ::CreateFileW(fileName, GENERIC_WRITE,\r\n      FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n      NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (hDir == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      hDir = ::CreateFileW(longPath, GENERIC_WRITE,\r\n        FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  }\r\n  #endif\r\n\r\n  bool res = false;\r\n  if (hDir != INVALID_HANDLE_VALUE)\r\n  {\r\n    res = BOOLToBool(::SetFileTime(hDir, creationTime, lastAccessTime, lastWriteTime));\r\n    ::CloseHandle(hDir);\r\n  }\r\n  return res;\r\n}\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (::SetFileAttributes(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyRemoveDirectory(LPCTSTR pathName)\r\n{ \r\n  if (::RemoveDirectory(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2)\r\n{\r\n  if (!GetLongPathBase(s1, d1) || !GetLongPathBase(s2, d2))\r\n    return false;\r\n  if (d1.IsEmpty() && d2.IsEmpty()) return false;\r\n  if (d1.IsEmpty()) d1 = s1;\r\n  if (d2.IsEmpty()) d2 = s2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName)\r\n{ \r\n  if (::MoveFile(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2)) \r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)\r\n{  \r\n  if (!g_IsNT)\r\n    return MySetFileAttributes(GetSysPath(fileName), fileAttributes);\r\n  if (::SetFileAttributesW(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n\r\nbool MyRemoveDirectory(LPCWSTR pathName)\r\n{  \r\n  if (!g_IsNT)\r\n    return MyRemoveDirectory(GetSysPath(pathName));\r\n  if (::RemoveDirectoryW(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)\r\n{  \r\n  if (!g_IsNT)\r\n    return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));\r\n  if (::MoveFileW(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2)) \r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nbool MyCreateDirectory(LPCTSTR pathName) \r\n{ \r\n  if (::CreateDirectory(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyCreateDirectory(LPCWSTR pathName)\r\n{  \r\n  if (!g_IsNT)\r\n    return MyCreateDirectory(GetSysPath(pathName));\r\n  if (::CreateDirectoryW(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\n/*\r\nbool CreateComplexDirectory(LPCTSTR pathName)\r\n{\r\n  NName::CParsedPath path;\r\n  path.ParsePath(pathName);\r\n  CSysString fullPath = path.Prefix;\r\n  DWORD errorCode = ERROR_SUCCESS;\r\n  for(int i = 0; i < path.PathParts.Size(); i++)\r\n  {\r\n    const CSysString &string = path.PathParts[i];\r\n    if(string.IsEmpty())\r\n    {\r\n      if(i != path.PathParts.Size() - 1)\r\n        return false;\r\n      return true;\r\n    }\r\n    fullPath += path.PathParts[i];\r\n    if (!MyCreateDirectory(fullPath))\r\n    {\r\n      DWORD errorCode = GetLastError();\r\n      if(errorCode != ERROR_ALREADY_EXISTS)\r\n        return false;\r\n    }\r\n    fullPath += NName::kDirDelimiter;\r\n  }\r\n  return true;\r\n}\r\n*/\r\n\r\nbool CreateComplexDirectory(LPCTSTR _aPathName)\r\n{\r\n  CSysString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == ':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  CSysString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if(MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfo fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDirectory())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == ':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while(pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateComplexDirectory(LPCWSTR _aPathName)\r\n{\r\n  UString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == L':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  UString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if(MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfoW fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDirectory())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == L':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while(pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\nbool DeleteFileAlways(LPCTSTR name)\r\n{\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFile(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DeleteFileAlways(LPCWSTR name)\r\n{  \r\n  if (!g_IsNT)\r\n    return DeleteFileAlways(GetSysPath(name));\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFileW(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nstatic bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)\r\n{\r\n  if(fileInfo.IsDirectory())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\n\r\nbool RemoveDirectoryWithSubItems(const CSysString &path)\r\n{\r\n  NFind::CFileInfo fileInfo;\r\n  CSysString pathPrefix = path + NName::kDirDelimiter;\r\n  {\r\n    NFind::CEnumerator enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));\r\n    while(enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)\r\n{\r\n  if(fileInfo.IsDirectory())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\nbool RemoveDirectoryWithSubItems(const UString &path)\r\n{\r\n  NFind::CFileInfoW fileInfo;\r\n  UString pathPrefix = path + UString(NName::kDirDelimiter);\r\n  {\r\n    NFind::CEnumeratorW enumerator(pathPrefix + UString(NName::kAnyStringWildcard));\r\n    while(enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\n\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)\r\n{\r\n  DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  shortPath.ReleaseBuffer();\r\n  return (needLength > 0 && needLength < MAX_PATH);\r\n}\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  LPTSTR fileNamePointer = 0;\r\n  LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n  DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n  resultPath.ReleaseBuffer();\r\n  if (needLength == 0)\r\n    return false;\r\n  if (needLength >= MAX_PATH)\r\n  {\r\n    #ifdef WIN_LONG_PATH2\r\n    needLength++;\r\n    buffer = resultPath.GetBuffer(needLength + 1);\r\n    DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength2 == 0 || needLength2 > needLength)\r\n    #endif\r\n      return false;\r\n  }\r\n  if (fileNamePointer == 0)\r\n    fileNamePartStartIndex = lstrlen(fileName);\r\n  else\r\n    fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR fileNamePointer = 0;\r\n    LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n    DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength == 0)\r\n      return false;\r\n    if (needLength >= MAX_PATH)\r\n    {\r\n      #ifdef WIN_LONG_PATH\r\n      needLength++;\r\n      buffer = resultPath.GetBuffer(needLength + 1);\r\n      DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n      resultPath.ReleaseBuffer();\r\n      if (needLength2 == 0 || needLength2 > needLength)\r\n      #endif\r\n        return false;\r\n    }\r\n    if (fileNamePointer == 0)\r\n      fileNamePartStartIndex = MyStringLen(fileName);\r\n    else\r\n      fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  }\r\n  else\r\n  {\r\n    CSysString sysPath;\r\n    if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))\r\n      return false;\r\n    UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));\r\n    UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));\r\n    fileNamePartStartIndex = resultPath1.Length();\r\n    resultPath = resultPath1 + resultPath2;\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n#endif\r\n\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetCurrentDirectory(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path)\r\n{\r\n  if (g_IsNT)\r\n    return BOOLToBool(::SetCurrentDirectoryW(path));\r\n  return MySetCurrentDirectory(GetSysPath(path));\r\n}\r\nbool MyGetCurrentDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetCurrentDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, \r\n  CSysString &resultPath, UINT32 &filePart)\r\n{\r\n  LPTSTR filePartPointer;\r\n  DWORD value = ::SearchPath(path, fileName, extension, \r\n    MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n  filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);\r\n  resultPath.ReleaseBuffer();\r\n  return (value > 0 && value <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, \r\n  UString &resultPath, UINT32 &filePart)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR filePartPointer = 0;\r\n    DWORD value = ::SearchPathW(path, fileName, extension, \r\n        MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n    filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);\r\n    resultPath.ReleaseBuffer();\r\n    return (value > 0 && value <= MAX_PATH);\r\n  }\r\n  \r\n  CSysString sysPath;\r\n  if (!MySearchPath(\r\n      path != 0 ? (LPCTSTR)GetSysPath(path): 0,\r\n      fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,\r\n      extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,\r\n      sysPath, filePart))\r\n    return false;\r\n  UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));\r\n  UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));\r\n  filePart = resultPath1.Length();\r\n  resultPath = resultPath1 + resultPath2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &path)\r\n{\r\n  path.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetTempPath(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)\r\n{\r\n  UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return number;\r\n}\r\n\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));\r\n    path.ReleaseBuffer();\r\n    return number;\r\n  }\r\n  CSysString sysPath;\r\n  UINT number = MyGetTempFileName(\r\n      dirPath ? (LPCTSTR)GetSysPath(dirPath): 0, \r\n      prefix ? (LPCTSTR)GetSysPath(prefix): 0, \r\n      sysPath);\r\n  path = GetUnicodePath(sysPath);\r\n  return number;\r\n}\r\n#endif\r\n\r\nUINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if(number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  CSysString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFile::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nUINT CTempFileW::Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if(number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFileW::Create(LPCWSTR prefix, UString &resultPath)\r\n{\r\n  UString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFileW::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFile tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!::DeleteFile(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if(NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectory::Create(LPCTSTR prefix)\r\n{ \r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir)); \r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateTempDirectory(LPCWSTR prefix, UString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFileW tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!DeleteFileAlways(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if(NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectoryW::Create(LPCWSTR prefix)\r\n{ \r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir)); \r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileDir.h",
    "content": "// Windows/FileDir.h\r\n\r\n#ifndef __WINDOWS_FILEDIR_H\r\n#define __WINDOWS_FILEDIR_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NDirectory {\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path);\r\nbool MyGetSystemDirectory(CSysString &path);\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path);\r\nbool MyGetSystemDirectory(UString &path);\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);\r\nbool MyRemoveDirectory(LPCTSTR pathName);\r\nbool MyCreateDirectory(LPCTSTR pathName);\r\nbool CreateComplexDirectory(LPCTSTR pathName);\r\nbool DeleteFileAlways(LPCTSTR name);\r\nbool RemoveDirectoryWithSubItems(const CSysString &path);\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);\r\nbool MyRemoveDirectory(LPCWSTR pathName);\r\nbool MyCreateDirectory(LPCWSTR pathName);\r\nbool CreateComplexDirectory(LPCWSTR pathName);\r\nbool DeleteFileAlways(LPCWSTR name);\r\nbool RemoveDirectoryWithSubItems(const UString &path);\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, \r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName);\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, \r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName);\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);\r\n#endif\r\n\r\ninline bool MySetCurrentDirectory(LPCTSTR path)\r\n  { return BOOLToBool(::SetCurrentDirectory(path)); }\r\nbool MyGetCurrentDirectory(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path);\r\nbool MyGetCurrentDirectory(UString &resultPath);\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, \r\n  CSysString &resultPath, UINT32 &filePart);\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, \r\n  UString &resultPath, UINT32 &filePart);\r\n#endif\r\n\r\ninline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, \r\n  CSysString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n\r\n#ifndef _UNICODE\r\ninline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, \r\n  UString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &resultPath);\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n#endif\r\n\r\nclass CTempFile\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _fileName;\r\npublic:\r\n  CTempFile(): _mustBeDeleted(false) {}\r\n  ~CTempFile() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n  bool Create(LPCTSTR prefix, CSysString &resultPath);\r\n  bool Remove();\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempFile CTempFileW;\r\n#else\r\nclass CTempFileW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _fileName;\r\npublic:\r\n  CTempFileW(): _mustBeDeleted(false) {}\r\n  ~CTempFileW() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n  bool Create(LPCWSTR prefix, UString &resultPath);\r\n  bool Remove();\r\n};\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);\r\n\r\nclass CTempDirectory\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _tempDir;\r\npublic:\r\n  const CSysString &GetPath() const { return _tempDir; }\r\n  CTempDirectory(): _mustBeDeleted(false) {}\r\n  ~CTempDirectory() { Remove();  }\r\n  bool Create(LPCTSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempDirectory CTempDirectoryW;\r\n#else\r\nclass CTempDirectoryW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _tempDir;\r\npublic:\r\n  const UString &GetPath() const { return _tempDir; }\r\n  CTempDirectoryW(): _mustBeDeleted(false) {}\r\n  ~CTempDirectoryW() { Remove();  }\r\n  bool Create(LPCWSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileFind.cpp",
    "content": "// Windows/FileFind.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileFind.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n\r\nnamespace NFind {\r\n\r\nstatic const TCHAR kDot = TEXT('.');\r\n\r\nbool CFileInfo::IsDots() const\r\n{ \r\n  if (!IsDirectory() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileInfoW::IsDots() const\r\n{ \r\n  if (!IsDirectory() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n#endif\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(\r\n    const WIN32_FIND_DATA &findData,\r\n    CFileInfo &fileInfo)\r\n{\r\n  fileInfo.Attributes = findData.dwFileAttributes; \r\n  fileInfo.CreationTime = findData.ftCreationTime;  \r\n  fileInfo.LastAccessTime = findData.ftLastAccessTime; \r\n  fileInfo.LastWriteTime = findData.ftLastWriteTime;\r\n  fileInfo.Size  = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow; \r\n  fileInfo.Name = findData.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fileInfo.ReparseTag = findData.dwReserved0;\r\n  #else\r\n  fileInfo.ObjectID = findData.dwOID;\r\n  #endif\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(\r\n    const WIN32_FIND_DATAW &findData,\r\n    CFileInfoW &fileInfo)\r\n{\r\n  fileInfo.Attributes = findData.dwFileAttributes; \r\n  fileInfo.CreationTime = findData.ftCreationTime;  \r\n  fileInfo.LastAccessTime = findData.ftLastAccessTime; \r\n  fileInfo.LastWriteTime = findData.ftLastWriteTime;\r\n  fileInfo.Size  = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow; \r\n  fileInfo.Name = findData.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fileInfo.ReparseTag = findData.dwReserved0;\r\n  #else\r\n  fileInfo.ObjectID = findData.dwOID;\r\n  #endif\r\n}\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(\r\n    const WIN32_FIND_DATA &findData,\r\n    CFileInfoW &fileInfo)\r\n{\r\n  fileInfo.Attributes = findData.dwFileAttributes; \r\n  fileInfo.CreationTime = findData.ftCreationTime;  \r\n  fileInfo.LastAccessTime = findData.ftLastAccessTime; \r\n  fileInfo.LastWriteTime = findData.ftLastWriteTime;\r\n  fileInfo.Size  = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow; \r\n  fileInfo.Name = GetUnicodeString(findData.cFileName, GetCurrentCodePage());\r\n  #ifndef _WIN32_WCE\r\n  fileInfo.ReparseTag = findData.dwReserved0;\r\n  #else\r\n  fileInfo.ObjectID = findData.dwOID;\r\n  #endif\r\n}\r\n#endif\r\n  \r\n////////////////////////////////\r\n// CFindFile\r\n\r\nbool CFindFile::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::FindClose(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\n          \r\nbool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  WIN32_FIND_DATA findData;\r\n  _handle = ::FindFirstFile(wildcard, &findData);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(wildcard, longPath))\r\n      _handle = ::FindFirstFileW(longPath, &findData);\r\n  }\r\n  #endif\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return false;\r\n  ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW findData;\r\n    _handle = ::FindFirstFileW(wildcard, &findData);\r\n    #ifdef WIN_LONG_PATH\r\n    if (_handle == INVALID_HANDLE_VALUE)\r\n    {\r\n      UString longPath;\r\n      if (GetLongPath(wildcard, longPath))\r\n        _handle = ::FindFirstFileW(longPath, &findData);\r\n    }\r\n    #endif\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA findData;\r\n    _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard, \r\n        GetCurrentCodePage()), &findData);\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFindFile::FindNext(CFileInfo &fileInfo)\r\n{\r\n  WIN32_FIND_DATA findData;\r\n  bool result = BOOLToBool(::FindNextFile(_handle, &findData));\r\n  if (result)\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  return result;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindNext(CFileInfoW &fileInfo)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW findData;\r\n    if (!::FindNextFileW(_handle, &findData))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA findData;\r\n    if (!::FindNextFileA(_handle, &findData))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n#endif\r\n\r\nbool DoesFileExist(LPCTSTR name)\r\n{\r\n  CFileInfo fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DoesFileExist(LPCWSTR name)\r\n{\r\n  CFileInfoW fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n#endif\r\n\r\n/////////////////////////////////////\r\n// CEnumerator\r\n\r\nbool CEnumerator::NextAny(CFileInfo &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CEnumeratorW::NextAny(CFileInfoW &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#endif\r\n\r\n////////////////////////////////\r\n// CFindChangeNotification\r\n// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.\r\n\r\nbool CFindChangeNotification::Close()\r\n{\r\n  if (!IsHandleAllocated())\r\n    return true;\r\n  if (!::FindCloseChangeNotification(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n           \r\nHANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  _handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n\r\n#ifndef _UNICODE\r\nHANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  if (!g_IsNT)\r\n    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);\r\n  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  UINT32 size = GetLogicalDriveStrings(0, NULL); \r\n  if (size == 0)\r\n    return false;\r\n  CSysString buffer;\r\n  UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size)); \r\n  if (newSize == 0)\r\n    return false;\r\n  if (newSize > size)\r\n    return false;\r\n  CSysString string;\r\n  for(UINT32 i = 0; i < newSize; i++)\r\n  {\r\n    TCHAR c = buffer[i];\r\n    if (c == TEXT('\\0'))\r\n    {\r\n      driveStrings.Add(string);\r\n      string.Empty();\r\n    }\r\n    else\r\n      string += c;\r\n  }\r\n  if (!string.IsEmpty())\r\n    return false;\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  if (g_IsNT)\r\n  {\r\n    UINT32 size = GetLogicalDriveStringsW(0, NULL); \r\n    if (size == 0)\r\n      return false;\r\n    UString buffer;\r\n    UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size)); \r\n    if (newSize == 0)\r\n      return false;\r\n    if (newSize > size)\r\n      return false;\r\n    UString string;\r\n    for(UINT32 i = 0; i < newSize; i++)\r\n    {\r\n      WCHAR c = buffer[i];\r\n      if (c == L'\\0')\r\n      {\r\n        driveStrings.Add(string);\r\n        string.Empty();\r\n      }\r\n      else\r\n        string += c;\r\n    }\r\n    return string.IsEmpty();\r\n  }\r\n  CSysStringVector driveStringsA;\r\n  bool res = MyGetLogicalDriveStrings(driveStringsA);\r\n  for (int i = 0; i < driveStringsA.Size(); i++)\r\n    driveStrings.Add(GetUnicodeString(driveStringsA[i]));\r\n  return res;\r\n}\r\n#endif\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileFind.h",
    "content": "// Windows/FileFind.h\r\n\r\n#ifndef __WINDOWS_FILEFIND_H\r\n#define __WINDOWS_FILEFIND_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"../Common/Types.h\"\r\n#include \"FileName.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NFind {\r\n\r\nnamespace NAttributes\r\n{\r\n  inline bool IsReadOnly(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_READONLY) != 0; }\r\n  inline bool IsHidden(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_HIDDEN) != 0; }\r\n  inline bool IsSystem(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_SYSTEM) != 0; }\r\n  inline bool IsDirectory(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }\r\n  inline bool IsArchived(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ARCHIVE) != 0; }\r\n  inline bool IsCompressed(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_COMPRESSED) != 0; }\r\n  inline bool IsEncrypted(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ENCRYPTED) != 0; }\r\n}\r\n\r\nclass CFileInfoBase\r\n{ \r\n  bool MatchesMask(UINT32 mask) const  { return ((Attributes & mask) != 0); }\r\npublic:\r\n  DWORD Attributes;\r\n  FILETIME CreationTime;  \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime;\r\n  UInt64 Size;\r\n  \r\n  #ifndef _WIN32_WCE\r\n  UINT32 ReparseTag;\r\n  #else\r\n  DWORD ObjectID; \r\n  #endif\r\n\r\n  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }\r\n  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }\r\n  bool IsDirectory() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }\r\n  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }\r\n  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }\r\n  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }\r\n  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }\r\n  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }\r\n  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }\r\n  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }\r\n  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }\r\n  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }\r\n};\r\n\r\nclass CFileInfo: public CFileInfoBase\r\n{ \r\npublic:\r\n  CSysString Name;\r\n  bool IsDots() const;\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CFileInfo CFileInfoW;\r\n#else\r\nclass CFileInfoW: public CFileInfoBase\r\n{ \r\npublic:\r\n  UString Name;\r\n  bool IsDots() const;\r\n};\r\n#endif\r\n\r\nclass CFindFile\r\n{\r\n  friend class CEnumerator;\r\n  HANDLE _handle;\r\npublic:\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }\r\n  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindFile() {  Close(); }\r\n  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n  bool FindNext(CFileInfo &fileInfo);\r\n  #ifndef _UNICODE\r\n  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\n  bool FindNext(CFileInfoW &fileInfo);\r\n  #endif\r\n  bool Close();\r\n};\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n\r\nbool DoesFileExist(LPCTSTR name);\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\nbool DoesFileExist(LPCWSTR name);\r\n#endif\r\n\r\nclass CEnumerator\r\n{\r\n  CFindFile _findFile;\r\n  CSysString _wildcard;\r\n  bool NextAny(CFileInfo &fileInfo);\r\npublic:\r\n  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfo &fileInfo);\r\n  bool Next(CFileInfo &fileInfo, bool &found);\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CEnumerator CEnumeratorW;\r\n#else\r\nclass CEnumeratorW\r\n{\r\n  CFindFile _findFile;\r\n  UString _wildcard;\r\n  bool NextAny(CFileInfoW &fileInfo);\r\npublic:\r\n  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfoW &fileInfo);\r\n  bool Next(CFileInfoW &fileInfo, bool &found);\r\n};\r\n#endif\r\n\r\nclass CFindChangeNotification\r\n{\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE () { return _handle; }\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }\r\n  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindChangeNotification() { Close(); }\r\n  bool Close();\r\n  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #ifndef _UNICODE\r\n  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #endif\r\n  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings);\r\n#endif\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifdef WIN_LONG_PATH\r\n#include \"../Common/MyString.h\"\r\n#endif\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR s, UString &res)\r\n{\r\n  res.Empty();\r\n  int len = MyStringLen(s);\r\n  wchar_t c = s[0];\r\n  if (len < 1 || c == L'\\\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))\r\n    return true;\r\n  UString curDir;\r\n  bool isAbs = false;\r\n  if (len > 3)\r\n    isAbs = (s[1] == L':' && s[2] == L'\\\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));\r\n\r\n  if (!isAbs)\r\n    {\r\n      DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));\r\n      curDir.ReleaseBuffer();\r\n      if (needLength == 0 || needLength > MAX_PATH)\r\n        return false;\r\n      if (curDir[curDir.Length() - 1] != L'\\\\')\r\n        curDir += L'\\\\';\r\n    }\r\n  res = UString(L\"\\\\\\\\?\\\\\") + curDir + s;\r\n  return true;\r\n}\r\n\r\nbool GetLongPath(LPCWSTR path, UString &longPath)\r\n{\r\n  if (GetLongPathBase(path, longPath)) \r\n    return !longPath.IsEmpty();\r\n  return false;\r\n}\r\n#endif\r\n\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode, \r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP), \r\n      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFileW(fileName, desiredAccess, shareMode, \r\n    (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n    flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode, \r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::CloseHandle(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if(sizeLow == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR) \r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if(!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CreationTime = winFileInfo.ftCreationTime;\r\n  fileInfo.LastAccessTime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.LastWriteTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes; \r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\n// Probably in some version of Windows there are problems with other sizes: \r\n// for 32 MB (maybe also for 16 MB). \r\n// And message can be \"Network connection was lost\"\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 22);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, creationTime, lastAccessTime, lastWriteTime)); }\r\n\r\nbool COutFile::SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {  return SetTime(NULL, NULL, lastWriteTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if(!Seek(length, newPosition))\r\n    return false;\r\n  if(newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{ \r\n  DWORD    Attributes; \r\n  FILETIME CreationTime; \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime; \r\n  DWORD    VolumeSerialNumber; \r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks; \r\n  UInt64   FileIndex; \r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _handle(INVALID_HANDLE_VALUE){};\r\n  ~CFileBase();\r\n\r\n  bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition); \r\n  bool SeekToBegin(); \r\n  bool SeekToEnd(UInt64 &newPosition); \r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileMapping.cpp",
    "content": "// Windows/FileMapping.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileMapping.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NMapping {\r\n\r\n\r\n\r\n\r\n}}}"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileMapping.h",
    "content": "// Windows/FileMapping.h\r\n\r\n#ifndef __WINDOWS_FILEMAPPING_H\r\n#define __WINDOWS_FILEMAPPING_H\r\n\r\n#include \"Windows/Handle.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\n// namespace NFile {\r\n// namespace NMapping {\r\n\r\nclass CFileMapping: public CHandle\r\n{\r\npublic:\r\n  bool Create(HANDLE file, LPSECURITY_ATTRIBUTES attributes,\r\n    DWORD protect, UINT64 maximumSize, LPCTSTR name)\r\n  {\r\n    _handle = ::CreateFileMapping(file, attributes,\r\n      protect, DWORD(maximumSize >> 32), DWORD(maximumSize), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenFileMapping(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  LPVOID MapViewOfFile(DWORD desiredAccess, UINT64 fileOffset, \r\n      SIZE_T numberOfBytesToMap)\r\n  {\r\n    return ::MapViewOfFile(_handle, desiredAccess, \r\n        DWORD(fileOffset >> 32), DWORD(fileOffset), numberOfBytesToMap);\r\n  }\r\n\r\n  LPVOID MapViewOfFileEx(DWORD desiredAccess, UINT64 fileOffset, \r\n      SIZE_T numberOfBytesToMap, LPVOID baseAddress)\r\n  {\r\n    return ::MapViewOfFileEx(_handle, desiredAccess, \r\n      DWORD(fileOffset >> 32), DWORD(fileOffset), \r\n      numberOfBytesToMap, baseAddress);\r\n  }\r\n  \r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileName.cpp",
    "content": "// Windows/FileName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)\r\n    dirPath += kDirDelimiter;\r\n}\r\n\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)\r\n    dirPath += wchar_t(kDirDelimiter);\r\n}\r\n#endif\r\n\r\n#ifdef _WIN32\r\n\r\nconst wchar_t kExtensionDelimiter = L'.';\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName, \r\n    UString &pureName, UString &extensionDelimiter, UString &extension)\r\n{\r\n  int index = fullName.ReverseFind(kExtensionDelimiter);\r\n  if (index < 0)\r\n  {\r\n    pureName = fullName;\r\n    extensionDelimiter.Empty();\r\n    extension.Empty();\r\n  }\r\n  else\r\n  {\r\n    pureName = fullName.Left(index);\r\n    extensionDelimiter = kExtensionDelimiter;\r\n    extension = fullName.Mid(index + 1);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/FileName.h",
    "content": "// Windows/FileName.h\r\n\r\n#ifndef __WINDOWS_FILENAME_H\r\n#define __WINDOWS_FILENAME_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nconst TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;\r\nconst TCHAR kAnyStringWildcard = '*';\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\\\'\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\\\'\r\n#endif\r\n\r\n#ifdef _WIN32\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName, \r\n    UString &pureName, UString &extensionDelimiter, UString &extension); \r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/Handle.h",
    "content": "// Windows/Handle.h\r\n\r\n#ifndef __WINDOWS_HANDLE_H\r\n#define __WINDOWS_HANDLE_H\r\n\r\nnamespace NWindows {\r\n\r\nclass CHandle\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE() { return _handle; }\r\n  CHandle(): _handle(NULL) {}\r\n  ~CHandle() { Close(); }\r\n  bool Close()\r\n  {\r\n    if (_handle == NULL)\r\n      return true;\r\n    if (!::CloseHandle(_handle))\r\n      return false;\r\n    _handle = NULL;\r\n    return true;\r\n  }\r\n  void Attach(HANDLE handle) \r\n    { _handle = handle; }\r\n  HANDLE Detach() \r\n  { \r\n    HANDLE handle = _handle;\r\n    _handle = NULL; \r\n    return handle;\r\n  }\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/MemoryLock.cpp",
    "content": "// Common/MemoryLock.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\n#ifndef _UNICODE\r\ntypedef BOOL (WINAPI * OpenProcessTokenP)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);\r\ntypedef BOOL (WINAPI * LookupPrivilegeValueP)(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID  lpLuid);\r\ntypedef BOOL (WINAPI * AdjustTokenPrivilegesP)(HANDLE TokenHandle, BOOL DisableAllPrivileges,\r\n    PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength);\r\n#endif\r\n\r\n#ifdef _UNICODE\r\nbool EnableLockMemoryPrivilege(\r\n#else\r\nstatic bool EnableLockMemoryPrivilege2(HMODULE hModule,\r\n#endif\r\nbool enable)\r\n{\r\n  #ifndef _UNICODE\r\n  if (hModule == NULL)\r\n    return false;\r\n  OpenProcessTokenP openProcessToken = (OpenProcessTokenP)GetProcAddress(hModule, \"OpenProcessToken\");\r\n  LookupPrivilegeValueP lookupPrivilegeValue = (LookupPrivilegeValueP)GetProcAddress(hModule, \"LookupPrivilegeValueA\" );\r\n  AdjustTokenPrivilegesP adjustTokenPrivileges = (AdjustTokenPrivilegesP)GetProcAddress(hModule, \"AdjustTokenPrivileges\");\r\n  if (openProcessToken == NULL || adjustTokenPrivileges == NULL || lookupPrivilegeValue == NULL)\r\n    return false;\r\n  #endif\r\n\r\n  HANDLE token;\r\n  if (!\r\n    #ifdef _UNICODE\r\n    ::OpenProcessToken\r\n    #else\r\n    openProcessToken\r\n    #endif\r\n    (::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))\r\n    return false;\r\n  TOKEN_PRIVILEGES tp;\r\n  bool res = false;\r\n  if (\r\n    #ifdef _UNICODE\r\n    ::LookupPrivilegeValue\r\n    #else\r\n    lookupPrivilegeValue\r\n    #endif\r\n    (NULL, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)))\r\n  {\r\n    tp.PrivilegeCount = 1;\r\n    tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED: 0;\r\n    if (\r\n      #ifdef _UNICODE\r\n      ::AdjustTokenPrivileges\r\n      #else\r\n      adjustTokenPrivileges\r\n      #endif\r\n      (token, FALSE, &tp, 0, NULL, NULL))\r\n      res = (GetLastError() == ERROR_SUCCESS);\r\n  }\r\n  ::CloseHandle(token);\r\n  return res;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool EnableLockMemoryPrivilege(bool enable)\r\n{\r\n  HMODULE hModule = LoadLibrary(TEXT(\"Advapi32.dll\"));\r\n  if(hModule == NULL)\r\n    return false;\r\n  bool res = EnableLockMemoryPrivilege2(hModule, enable);\r\n  ::FreeLibrary(hModule);\r\n  return res;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/MemoryLock.h",
    "content": "// Windows/MemoryLock.h\r\n\r\n#ifndef __WINDOWS_MEMORYLOCK_H\r\n#define __WINDOWS_MEMORYLOCK_H\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\nbool EnableLockMemoryPrivilege(bool enable = true);\r\n\r\n}}\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/PropVariant.cpp",
    "content": "// Windows/PropVariant.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariant.h\"\r\n\r\n#include \"../Common/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nCPropVariant::CPropVariant(const PROPVARIANT& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(const CPropVariant& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(BSTR bstrSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = bstrSrc;\r\n}\r\n\r\nCPropVariant::CPropVariant(LPCOLESTR lpszSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = lpszSrc;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const CPropVariant& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\nCPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(BSTR bstrSrc)\r\n{\r\n  *this = (LPCOLESTR)bstrSrc;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)\r\n{\r\n  InternalClear();\r\n  vt = VT_BSTR;\r\n  wReserved1 = 0;\r\n  bstrVal = ::SysAllocString(lpszSrc);\r\n  if (bstrVal == NULL && lpszSrc != NULL)\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = E_OUTOFMEMORY;\r\n  }\r\n  return *this;\r\n}\r\n\r\n\r\nCPropVariant& CPropVariant::operator=(bool bSrc)\r\n{\r\n  if (vt != VT_BOOL)\r\n  {\r\n    InternalClear();\r\n    vt = VT_BOOL;\r\n  }\r\n  boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt32 value)\r\n{\r\n  if (vt != VT_UI4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI4;\r\n  }\r\n  ulVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt64 value)\r\n{\r\n  if (vt != VT_UI8)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI8;\r\n  }\r\n  uhVal.QuadPart = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const FILETIME &value)\r\n{\r\n  if (vt != VT_FILETIME)\r\n  {\r\n    InternalClear();\r\n    vt = VT_FILETIME;\r\n  }\r\n  filetime = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int32 value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  \r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Byte value)\r\n{\r\n  if (vt != VT_UI1)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI1;\r\n  }\r\n  bVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int16 value)\r\n{\r\n  if (vt != VT_I2)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I2;\r\n  }\r\n  iVal = value;\r\n  return *this;\r\n}\r\n\r\n/*\r\nCPropVariant& CPropVariant::operator=(LONG value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  return *this;\r\n}\r\n*/\r\n\r\nstatic HRESULT MyPropVariantClear(PROPVARIANT *propVariant) \r\n{ \r\n  switch(propVariant->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      propVariant->vt = VT_EMPTY;\r\n      propVariant->wReserved1 = 0; \r\n      return S_OK;\r\n  }\r\n  return ::VariantClear((VARIANTARG *)propVariant); \r\n}\r\n\r\nHRESULT CPropVariant::Clear() \r\n{ \r\n  return MyPropVariantClear(this);\r\n}\r\n\r\nHRESULT CPropVariant::Copy(const PROPVARIANT* pSrc) \r\n{ \r\n  ::VariantClear((tagVARIANT *)this); \r\n  switch(pSrc->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));\r\n      return S_OK;\r\n  }\r\n  return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc)); \r\n}\r\n\r\n\r\nHRESULT CPropVariant::Attach(PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(this, pSrc, sizeof(PROPVARIANT));\r\n  pSrc->vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::Detach(PROPVARIANT* pDest)\r\n{\r\n  HRESULT hr = MyPropVariantClear(pDest);\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(pDest, this, sizeof(PROPVARIANT));\r\n  vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::InternalClear()\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n  return hr;\r\n}\r\n\r\nvoid CPropVariant::InternalCopy(const PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Copy(pSrc);\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n}\r\n\r\nint CPropVariant::Compare(const CPropVariant &a)\r\n{\r\n  if(vt != a.vt)\r\n    return 0; // it's mean some bug\r\n  switch (vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return 0;\r\n    \r\n    /*\r\n    case VT_I1:\r\n      return MyCompare(cVal, a.cVal);\r\n    */\r\n    case VT_UI1:\r\n      return MyCompare(bVal, a.bVal);\r\n\r\n    case VT_I2:\r\n      return MyCompare(iVal, a.iVal);\r\n    case VT_UI2:\r\n      return MyCompare(uiVal, a.uiVal);\r\n    \r\n    case VT_I4:\r\n      return MyCompare(lVal, a.lVal);\r\n    /*\r\n    case VT_INT:\r\n      return MyCompare(intVal, a.intVal);\r\n    */\r\n    case VT_UI4:\r\n      return MyCompare(ulVal, a.ulVal);\r\n    /*\r\n    case VT_UINT:\r\n      return MyCompare(uintVal, a.uintVal);\r\n    */\r\n    case VT_I8:\r\n      return MyCompare(hVal.QuadPart, a.hVal.QuadPart);\r\n    case VT_UI8:\r\n      return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);\r\n\r\n    case VT_BOOL:    \r\n      return -MyCompare(boolVal, a.boolVal);\r\n\r\n    case VT_FILETIME:\r\n      return ::CompareFileTime(&filetime, &a.filetime);\r\n    case VT_BSTR:\r\n      return 0; // Not implemented \r\n      // return MyCompare(aPropVarint.cVal);\r\n\r\n    default:\r\n      return 0;\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/PropVariant.h",
    "content": "// Windows/PropVariant.h\r\n\r\n#ifndef __WINDOWS_PROPVARIANT_H\r\n#define __WINDOWS_PROPVARIANT_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nclass CPropVariant : public tagPROPVARIANT\r\n{\r\npublic:\r\n  CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }\r\n  ~CPropVariant() { Clear(); }\r\n  CPropVariant(const PROPVARIANT& varSrc);\r\n  CPropVariant(const CPropVariant& varSrc);\r\n  CPropVariant(BSTR bstrSrc);\r\n  CPropVariant(LPCOLESTR lpszSrc);\r\n  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };\r\n  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }\r\n  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal = *(ULARGE_INTEGER*)&value; }\r\n  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }\r\n  CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }\r\n  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }\r\n  CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }\r\n  // CPropVariant(LONG value, VARTYPE vtSrc = VT_I4) { vt = vtSrc; lVal = value; }\r\n\r\n  CPropVariant& operator=(const CPropVariant& varSrc);\r\n  CPropVariant& operator=(const PROPVARIANT& varSrc);\r\n  CPropVariant& operator=(BSTR bstrSrc);\r\n  CPropVariant& operator=(LPCOLESTR lpszSrc);\r\n  CPropVariant& operator=(bool bSrc);\r\n  CPropVariant& operator=(UInt32 value);\r\n  CPropVariant& operator=(UInt64 value);\r\n  CPropVariant& operator=(const FILETIME &value);\r\n\r\n  CPropVariant& operator=(Int32 value);\r\n  CPropVariant& operator=(Byte value);\r\n  CPropVariant& operator=(Int16 value);\r\n  // CPropVariant& operator=(LONG  value);\r\n\r\n  HRESULT Clear();\r\n  HRESULT Copy(const PROPVARIANT* pSrc);\r\n  HRESULT Attach(PROPVARIANT* pSrc);\r\n  HRESULT Detach(PROPVARIANT* pDest);\r\n\r\n  HRESULT InternalClear();\r\n  void InternalCopy(const PROPVARIANT* pSrc);\r\n\r\n  int Compare(const CPropVariant &a1);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/PropVariantConversions.cpp",
    "content": "// PropVariantConversions.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <stdio.h>\r\n\r\n#include \"PropVariantConversions.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\nstatic UString ConvertUInt64ToString(UInt64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString ConvertInt64ToString(Int64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic char *UIntToStringSpec(UInt32 value, char *s, int numPos)\r\n{\r\n  char temp[16];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    temp[pos++] = (char)('0' + value % 10);\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  int i;\r\n  for (i = 0; i < numPos - pos; i++)\r\n    *s++ = '0';\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n  return s;\r\n}\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)\r\n{\r\n  s[0] = '\\0';\r\n  SYSTEMTIME st;\r\n  if(!BOOLToBool(FileTimeToSystemTime(&ft, &st)))\r\n    return false;\r\n  s = UIntToStringSpec(st.wYear, s, 4);\r\n  *s++ = '-';\r\n  s = UIntToStringSpec(st.wMonth, s, 2);\r\n  *s++ = '-';\r\n  s = UIntToStringSpec(st.wDay, s, 2);\r\n  if (includeTime)\r\n  {\r\n    *s++ = ' ';\r\n    s = UIntToStringSpec(st.wHour, s, 2);\r\n    *s++ = ':';\r\n    s = UIntToStringSpec(st.wMinute, s, 2);\r\n    if (includeSeconds)\r\n    {\r\n      *s++ = ':';\r\n      UIntToStringSpec(st.wSecond, s, 2);\r\n    }\r\n  }\r\n  /*\r\n  sprintf(s, \"%04d-%02d-%02d\", st.wYear, st.wMonth, st.wDay);\r\n  if (includeTime)\r\n  {\r\n    sprintf(s + strlen(s), \" %02d:%02d\", st.wHour, st.wMinute);\r\n    if (includeSeconds)\r\n      sprintf(s + strlen(s), \":%02d\", st.wSecond);\r\n  }\r\n  */\r\n  return true;\r\n}\r\n\r\nUString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds)\r\n{\r\n  char s[32];\r\n  ConvertFileTimeToString(fileTime, s,  includeTime, includeSeconds);\r\n  return GetUnicodeString(s);\r\n}\r\n \r\n\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant)\r\n{\r\n  switch (propVariant.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return UString();\r\n    case VT_BSTR:\r\n      return propVariant.bstrVal;\r\n    case VT_UI1:\r\n      return ConvertUInt64ToString(propVariant.bVal);\r\n    case VT_UI2:\r\n      return ConvertUInt64ToString(propVariant.uiVal);\r\n    case VT_UI4:\r\n      return ConvertUInt64ToString(propVariant.ulVal);\r\n    case VT_UI8:\r\n      return ConvertUInt64ToString(propVariant.uhVal.QuadPart);\r\n    case VT_FILETIME:\r\n      return ConvertFileTimeToString(propVariant.filetime, true, true);\r\n    /*\r\n    case VT_I1:\r\n      return ConvertInt64ToString(propVariant.cVal);\r\n    */\r\n    case VT_I2:\r\n      return ConvertInt64ToString(propVariant.iVal);\r\n    case VT_I4:\r\n      return ConvertInt64ToString(propVariant.lVal);\r\n    case VT_I8:\r\n      return ConvertInt64ToString(propVariant.hVal.QuadPart);\r\n\r\n    case VT_BOOL:\r\n      return VARIANT_BOOLToBool(propVariant.boolVal) ? L\"+\" : L\"-\";\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 150245;\r\n      #else\r\n      return UString();\r\n      #endif\r\n  }\r\n}\r\n\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant)\r\n{\r\n  switch (propVariant.vt)\r\n  {\r\n    case VT_UI1:\r\n      return propVariant.bVal;\r\n    case VT_UI2:\r\n      return propVariant.uiVal;\r\n    case VT_UI4:\r\n      return propVariant.ulVal;\r\n    case VT_UI8:\r\n      return (UInt64)propVariant.uhVal.QuadPart;\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 151199;\r\n      #else\r\n      return 0;\r\n      #endif\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/PropVariantConversions.h",
    "content": "// Windows/PropVariantConversions.h\r\n\r\n#ifndef __PROPVARIANTCONVERSIONS_H\r\n#define __PROPVARIANTCONVERSIONS_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/MyString.h\"\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant);\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/Synchronization.cpp",
    "content": "// Windows/Synchronization.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Synchronization.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/Synchronization.h",
    "content": "// Windows/Synchronization.h\r\n\r\n#ifndef __WINDOWS_SYNCHRONIZATION_H\r\n#define __WINDOWS_SYNCHRONIZATION_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\n#ifdef _WIN32\r\n#include \"Handle.h\"\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\nclass CBaseEvent\r\n{\r\nprotected:\r\n  ::CEvent _object;\r\npublic:\r\n  bool IsCreated() { return Event_IsCreated(&_object) != 0; }\r\n  operator HANDLE() { return _object.handle; }\r\n  CBaseEvent() { Event_Construct(&_object); }\r\n  ~CBaseEvent() { Close(); }\r\n  HRes Close() { return Event_Close(&_object); }\r\n  #ifdef _WIN32\r\n  HRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),\r\n        BoolToBOOL(initiallyOwn), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  #endif\r\n\r\n  HRes Set() { return Event_Set(&_object); }\r\n  // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }\r\n  HRes Reset() { return Event_Reset(&_object); }\r\n  HRes Lock() { return Event_Wait(&_object); }\r\n};\r\n\r\nclass CManualResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  HRes Create(bool initiallyOwn = false)\r\n  {\r\n    return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);\r\n  }\r\n  HRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return ManualResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  #ifdef _WIN32\r\n  HRes CreateWithName(bool initiallyOwn, LPCTSTR name)\r\n  {\r\n    return CBaseEvent::Create(true, initiallyOwn, name);\r\n  }\r\n  #endif\r\n};\r\n\r\nclass CAutoResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  HRes Create()\r\n  {\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  HRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\nclass CObject: public CHandle\r\n{\r\npublic:\r\n  HRes Lock(DWORD timeoutInterval = INFINITE)\r\n    { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }\r\n};\r\nclass CMutex: public CObject\r\n{\r\npublic:\r\n  HRes Create(bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  HRes Release() \r\n  { \r\n    return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();\r\n  }\r\n};\r\nclass CMutexLock\r\n{\r\n  CMutex *_object;\r\npublic:\r\n  CMutexLock(CMutex &object): _object(&object) { _object->Lock(); } \r\n  ~CMutexLock() { _object->Release(); }\r\n};\r\n#endif\r\n\r\nclass CSemaphore\r\n{\r\n  ::CSemaphore _object;\r\npublic:\r\n  CSemaphore() { Semaphore_Construct(&_object); }\r\n  ~CSemaphore() { Close(); }\r\n  HRes Close() {  return Semaphore_Close(&_object); }\r\n  operator HANDLE() { return _object.handle; }\r\n  HRes Create(UInt32 initiallyCount, UInt32 maxCount)\r\n  {\r\n    return Semaphore_Create(&_object, initiallyCount, maxCount);\r\n  }\r\n  HRes Release() { return Semaphore_Release1(&_object); }\r\n  HRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }\r\n  HRes Lock() { return Semaphore_Wait(&_object); }\r\n};\r\n\r\nclass CCriticalSection\r\n{\r\n  ::CCriticalSection _object;\r\npublic:\r\n  CCriticalSection() { CriticalSection_Init(&_object); }\r\n  ~CCriticalSection() { CriticalSection_Delete(&_object); }\r\n  void Enter() { CriticalSection_Enter(&_object); }\r\n  void Leave() { CriticalSection_Leave(&_object); }\r\n};\r\n\r\nclass CCriticalSectionLock\r\n{\r\n  CCriticalSection *_object;\r\n  void Unlock()  { _object->Leave(); }\r\npublic:\r\n  CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); } \r\n  ~CCriticalSectionLock() { Unlock(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/System.cpp",
    "content": "// Windows/System.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"System.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors()\r\n{\r\n  SYSTEM_INFO systemInfo;\r\n  GetSystemInfo(&systemInfo);\r\n  return (UInt32)systemInfo.dwNumberOfProcessors;\r\n}\r\n\r\n#if !defined(_WIN64) && defined(__GNUC__)\r\n\r\ntypedef struct _MY_MEMORYSTATUSEX {\r\n  DWORD dwLength;\r\n  DWORD dwMemoryLoad;\r\n  DWORDLONG ullTotalPhys;\r\n  DWORDLONG ullAvailPhys;\r\n  DWORDLONG ullTotalPageFile;\r\n  DWORDLONG ullAvailPageFile;\r\n  DWORDLONG ullTotalVirtual;\r\n  DWORDLONG ullAvailVirtual;\r\n  DWORDLONG ullAvailExtendedVirtual;\r\n} MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX;\r\n\r\n#else\r\n\r\n#define MY_MEMORYSTATUSEX MEMORYSTATUSEX\r\n#define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX\r\n\r\n#endif\r\n\r\ntypedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);\r\n\r\nUInt64 GetRamSize()\r\n{\r\n  MY_MEMORYSTATUSEX stat;\r\n  stat.dwLength = sizeof(stat);\r\n  #ifdef _WIN64\r\n  if (!::GlobalMemoryStatusEx(&stat))\r\n    return 0;\r\n  return stat.ullTotalPhys;\r\n  #else\r\n  GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")),\r\n        \"GlobalMemoryStatusEx\");\r\n  if (globalMemoryStatusEx != 0)\r\n    if (globalMemoryStatusEx(&stat))\r\n      return stat.ullTotalPhys;\r\n  {\r\n    MEMORYSTATUS stat;\r\n    stat.dwLength = sizeof(stat);\r\n    GlobalMemoryStatus(&stat);\r\n    return stat.dwTotalPhys;\r\n  }\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/System.h",
    "content": "// Windows/System.h\r\n\r\n#ifndef __WINDOWS_SYSTEM_H\r\n#define __WINDOWS_SYSTEM_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors();\r\nUInt64 GetRamSize();\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/Thread.h",
    "content": "// Windows/Thread.h\r\n\r\n#ifndef __WINDOWS_THREAD_H\r\n#define __WINDOWS_THREAD_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\nnamespace NWindows {\r\n\r\nclass CThread\r\n{\r\n  ::CThread thread;\r\npublic:\r\n  CThread() { Thread_Construct(&thread); }\r\n  ~CThread() { Close(); }\r\n  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }\r\n  HRes Close()  { return Thread_Close(&thread); }\r\n  HRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n    { return Thread_Create(&thread, startAddress, parameter); }\r\n  HRes Wait() { return Thread_Wait(&thread); }\r\n  \r\n  #ifdef _WIN32\r\n  DWORD Resume() { return ::ResumeThread(thread.handle); }\r\n  DWORD Suspend() { return ::SuspendThread(thread.handle); }\r\n  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }\r\n  int GetPriority() { return ::GetThreadPriority(thread.handle); }\r\n  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }\r\n  #endif\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CPP/Windows/Time.h",
    "content": "// Windows/Time.h\r\n\r\n#ifndef __WINDOWS_TIME_H\r\n#define __WINDOWS_TIME_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\ninline bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)\r\n{\r\n  return BOOLToBool(::DosDateTimeToFileTime(UInt16(dosTime >> 16), \r\n      UInt16(dosTime & 0xFFFF), &fileTime));\r\n}\r\n\r\nconst UInt32 kHighDosTime = 0xFF9FBF7D;\r\nconst UInt32 kLowDosTime = 0x210000;\r\n\r\ninline bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)\r\n{\r\n  WORD datePart, timePart;\r\n  if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))\r\n  {\r\n    if (fileTime.dwHighDateTime >= 0x01C00000) // 2000\r\n      dosTime = kHighDosTime;\r\n    else\r\n      dosTime = kLowDosTime;\r\n    return false;\r\n  }\r\n  dosTime = (((UInt32)datePart) << 16) + timePart;\r\n  return true;\r\n}\r\n\r\nconst UInt32 kNumTimeQuantumsInSecond = 10000000;\r\nconst UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;\r\n\r\ninline void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)\r\n{\r\n  UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;\r\n  fileTime.dwLowDateTime = (DWORD)v;\r\n  fileTime.dwHighDateTime = (DWORD)(v >> 32);\r\n}\r\n\r\ninline bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)\r\n{\r\n  UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;\r\n  if (winTime < kUnixTimeStartValue)\r\n  {\r\n    unixTime = 0;\r\n    return false;\r\n  }\r\n  winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;\r\n  if (winTime > 0xFFFFFFFF)\r\n  {\r\n    unixTime = 0xFFFFFFFF;\r\n    return false;\r\n  }\r\n  unixTime = (UInt32)winTime;\r\n  return true;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid SetStream(System.IO.Stream inStream);\r\n\t\tvoid Init();\r\n\t\tvoid ReleaseStream();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetMatches(UInt32[] distances);\r\n\t\tvoid Skip(UInt32 num);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize = 0;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\tUInt32[] _son;\r\n\t\tUInt32[] _hash;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\t\tUInt32 _hashMask;\r\n\t\tUInt32 _hashSizeSum = 0;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\r\n\t\tconst UInt32 kHash2Size = 1 << 10;\r\n\t\tconst UInt32 kHash3Size = 1 << 16;\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kStartMaxLen = 1;\r\n\t\tconst UInt32 kHash3Offset = kHash2Size;\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\t\r\n\t\tUInt32 kNumHashDirectBytes = 0;\r\n\t\tUInt32 kMinMatchCheck = 4;\r\n\t\tUInt32 kFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\r\n\t\tpublic void SetType(int numHashBytes)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\t\tkMinMatchCheck = 4;\r\n\t\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\t\tkFixHashSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic new void SetStream(System.IO.Stream stream) { base.SetStream(stream); }\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\t\t\r\n\t\tpublic new void Init()\r\n\t\t{\r\n\t\t\tbase.Init();\r\n\t\t\tfor (UInt32 i = 0; i < _hashSizeSum; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\t\tthrow new Exception();\r\n\t\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\t\t\t\t\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\tUInt32 cyclicBufferSize = historySize + 1;\r\n\t\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t\t_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\t\tUInt32 hs = kBT2HashSize;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\ths = historySize - 1;\r\n\t\t\t\ths |= (hs >> 1);\r\n\t\t\t\ths |= (hs >> 2);\r\n\t\t\t\ths |= (hs >> 4);\r\n\t\t\t\ths |= (hs >> 8);\r\n\t\t\t\ths >>= 1;\r\n\t\t\t\ths |= 0xFFFF;\r\n\t\t\t\tif (hs > (1 << 24))\r\n\t\t\t\t\ths >>= 1;\r\n\t\t\t\t_hashMask = hs;\r\n\t\t\t\ths++;\r\n\t\t\t\ths += kFixHashSize;\r\n\t\t\t}\r\n\t\t\tif (hs != _hashSizeSum)\r\n\t\t\t\t_hash = new UInt32[_hashSizeSum = hs];\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetMatches(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 offset = 0;\r\n\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\t\t\tUInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 curMatch2 = _hash[hash2Value];\r\n\t\t\t\tUInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t\t{\r\n\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\t\t\t\r\n\t\t\tif (kNumHashDirectBytes != 0)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\r\n\t\t\twhile(true)\r\n\t\t\t{\r\n\t\t\t\tif(curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (maxLen < len)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t\treturn offset;\r\n\t\t}\r\n\r\n\t\tpublic void Skip(UInt32 num)\r\n\t\t{\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenLimit;\r\n\t\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tMovePos();\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\t\tUInt32 hashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\t\tUInt32 hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\t\tUInt32 hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\t\tUInt32 len0, len1;\r\n\t\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\t\tlen1 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\t\tlen0 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tMovePos();\r\n\t\t\t}\r\n\t\t\twhile (--num != 0);\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 subValue = _pos - _cyclicBufferSize;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize; // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos; // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos\r\n\t\tpublic UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\t\tif (offset > 0)\r\n\t\t\t\toffset--;\r\n\t\t\t\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { _stream = stream; }\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic uint TrainSize = 0;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t\tTrainSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tlong len = stream.Length;\r\n\t\t\tuint size = (len < _windowSize) ? (uint)len : _windowSize;\r\n\t\t\tTrainSize = size;\r\n\t\t\tstream.Position = len - size;\r\n\t\t\t_streamPos = _pos = 0;\r\n\t\t\twhile (size > 0)\r\n\t\t\t{\r\n\t\t\t\tuint curSize = _windowSize - _pos;\r\n\t\t\t\tif (size < curSize)\r\n\t\t\t\t\tcurSize = size;\r\n\t\t\t\tint numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tsize -= (uint)numReadBytes;\r\n\t\t\t\t_pos += (uint)numReadBytes;\r\n\t\t\t\t_streamPos += (uint)numReadBytes;\r\n\t\t\t\tif (_pos == _windowSize)\r\n\t\t\t\t\t_streamPos = _pos = 0;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t\tpublic bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\t// public const int kDicLogSizeMax = 30;\r\n\t\t// public const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tbool _solid = false;\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream, _solid);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t_solid = true;\r\n\t\t\treturn m_OutWindow.Train(stream);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get { return 0; }}\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t};\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1 << 11];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 22;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 11))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 21))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 10] + 20);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 20] + 40);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 17))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 27))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 16] + 32);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 26] + 52);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 22;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32[] prices, UInt32 st)\r\n\t\t\t{\r\n\t\t\t\tUInt32 a0 = _choice.GetPrice0();\r\n\t\t\t\tUInt32 a1 = _choice.GetPrice1();\r\n\t\t\t\tUInt32 b0 = a1 + _choice2.GetPrice0();\r\n\t\t\t\tUInt32 b1 = a1 + _choice2.GetPrice1();\r\n\t\t\t\tUInt32 i = 0;\r\n\t\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\tLZ.IMatchFinder _matchFinder = null;\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates];\r\n\t\t\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];\r\n\t\t\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _numDistancePairs;\r\n\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\t\tSystem.IO.Stream _inStream;\r\n\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark = false;\r\n\t\t\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tif (_matchFinderType == EMatchFinderType.BT2)\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs)\r\n\t\t{\r\n\t\t\tlenRes = 0;\r\n\t\t\tnumDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\t\tif (numDistancePairs > 0)\r\n\t\t\t{\r\n\t\t\t\tlenRes = _matchDistances[numDistancePairs - 2];\r\n\t\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t}\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tif (num > 0)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Skip(num);\r\n\t\t\t\t_additionalOffset += num;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t\t}\r\n\t\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\t\tUInt32 lenMain, numDistancePairs;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain, out numDistancePairs);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\t\t\t\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = (UInt32)0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\t\tif(lenEnd < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\t\tUInt32 len = lenEnd;\r\n\t\t\tdo\r\n\t\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\t\twhile (len >= 2);\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tif (repLen < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tUInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--repLen >= 2);\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\t\t\t\r\n\t\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\t\tif (len <= lenMain)\r\n\t\t\t{\r\n\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\tfor (; ; len++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 distance = _matchDistances[offs + 1];\r\n\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen, out numDistancePairs);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_numDistancePairs = numDistancePairs;\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t\t{\r\n\t\t\t\t\t// try Literal + rep0\r\n\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 startLen = 2; // speed optimization \r\n\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t\t// if (_maxMode)\r\n\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, reps[repIndex], t);\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)(reps[repIndex] + 1))), \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t\t}\r\n\t\t\t\tif (newLen >= startLen)\r\n\t\t\t\t{\r\n\t\t\t\t\tnormalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = startLen; ; lenTest++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t);\r\n\t\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)(curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t\t_matchFinder.Init();\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t\tif (_trainSize > 0)\r\n\t\t\t\t\t_matchFinder.Skip(_trainSize);\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len, numDistancePairs; // it's not used\r\n\t\t\t\tReadMatchDistances(out len, out numDistancePairs);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 len = GetOptimum((UInt32)nowPos64, out pos);\r\n\t\t\t\t\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t// if (!_fastMode)\r\n\t\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// if (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\t\t\r\n\t\tUInt32[] tempPrices = new UInt32[Base.kNumFullDistances];\r\n\t\tUInt32 _matchPriceCount;\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t\t{ \r\n\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, \r\n\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tRangeCoder.BitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\t\t\t\r\n\t\t\t\tUInt32 st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\t\tUInt32 st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t\t}\r\n\t\t\t_matchPriceCount = 0;\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = 0;\r\n\t\t}\r\n\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t/*\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t*/\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 30;\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _trainSize = 0;\r\n\t\tpublic void SetTrainSize(uint trainSize)\r\n\t\t{\r\n\t\t\t_trainSize = trainSize;\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\t\r\n\tpublic class CDoubleStream: Stream\r\n\t{\r\n\t\tpublic System.IO.Stream s1;\r\n\t\tpublic System.IO.Stream s2;\r\n\t\tpublic int fileIndex;\r\n\t\tpublic long skipSize;\r\n\t\t\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return false; }}\r\n\t\tpublic override bool CanSeek { get { return false; }}\r\n\t\tpublic override long Length { get { return s1.Length + s2.Length - skipSize; } }\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\tint numTotal = 0;\r\n\t\t\twhile (count > 0)\r\n\t\t\t{\r\n\t\t\t\tif (fileIndex == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tint num = s1.Read(buffer, offset, count);\r\n\t\t\t\t\toffset += num;\r\n\t\t\t\t\tcount -= num;\r\n\t\t\t\t\tnumTotal += num;\r\n\t\t\t\t\tif (num == 0)\r\n\t\t\t\t\t\tfileIndex++;\r\n\t\t\t\t}\r\n\t\t\t\tif (fileIndex == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tnumTotal += s2.Read(buffer, offset, count);\r\n\t\t\t\t\treturn numTotal;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn numTotal;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Write\"));\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Seek\"));\r\n\t\t}\r\n\t\tpublic override void SetLength(long value)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't SetLength\"));\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut,\r\n\t\t\tTrain\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0, 29], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.49 Copyright (c) 1999-2007 Igor Pavlov  2006-07-05\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[13];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"T\", SwitchType.UnLimitedPostString, false, 1);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary);\r\n\t\t\t}\r\n\r\n\t\t\tstring train = \"\";\r\n\t\t\tif (parser[(int)Key.Train].ThereIs)\r\n\t\t\t\ttrain = (string)parser[(int)Key.Train].PostStrings[0];\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream trainStream = null;\r\n\t\t\tif (train.Length != 0)\r\n\t\t\t\ttrainStream = new FileStream(train, FileMode.Open, FileAccess.Read);\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tCDoubleStream doubleStream = new CDoubleStream();\r\n\t\t\t\t\tdoubleStream.s1 = trainStream;\r\n\t\t\t\t\tdoubleStream.s2 = inStream;\r\n\t\t\t\t\tdoubleStream.fileIndex = 0;\r\n\t\t\t\t\tinStream = doubleStream;\r\n\t\t\t\t\tlong trainFileSize = trainStream.Length;\r\n\t\t\t\t\tdoubleStream.skipSize = 0;\r\n\t\t\t\t\tif (trainFileSize > dictionary)\r\n\t\t\t\t\t\tdoubleStream.skipSize = trainFileSize - dictionary;\r\n\t\t\t\t\ttrainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);\r\n\t\t\t\t\tencoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));\r\n\t\t\t\t}\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!decoder.Train(trainStream))\r\n\t\t\t\t\t\tthrow (new Exception(\"can't train\"));\r\n\t\t\t\t}\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.50727</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tUInt32 Rep0;\r\n\t\t\t\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\t\tUInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\tRG.Init();\r\n\t\t\t\tRep0 = 1;\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)RG.GetRnd(8);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 len;\r\n\t\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\t\tUInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 220 + outSize * 20;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 18))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "// LZ.BinTree\r\n\r\npackage SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\r\n\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize = 0;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\tint[] _hash;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\tint _hashMask;\r\n\tint _hashSizeSum = 0;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\r\n\tstatic final int kHash2Size = 1 << 10;\r\n\tstatic final int kHash3Size = 1 << 16;\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kStartMaxLen = 1;\r\n\tstatic final int kHash3Offset = kHash2Size;\r\n\tstatic final int kEmptyHashValue = 0;\r\n\tstatic final int kMaxValForNormalize = (1 << 30) - 1;\r\n\t\r\n\tint kNumHashDirectBytes = 0;\r\n\tint kMinMatchCheck = 4;\r\n\tint kFixHashSize = kHash2Size + kHash3Size;\r\n\r\n\tpublic void SetType(int numHashBytes)\r\n\t{\r\n\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\tkMinMatchCheck = 4;\r\n\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\tkFixHashSize = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tfor (int i = 0; i < _hashSizeSum; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\treturn false;\r\n\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\tint cyclicBufferSize = historySize + 1;\r\n\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t_son = new int[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\tint hs = kBT2HashSize;\r\n\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\ths = historySize - 1;\r\n\t\t\ths |= (hs >> 1);\r\n\t\t\ths |= (hs >> 2);\r\n\t\t\ths |= (hs >> 4);\r\n\t\t\ths |= (hs >> 8);\r\n\t\t\ths >>= 1;\r\n\t\t\ths |= 0xFFFF;\r\n\t\t\tif (hs > (1 << 24))\r\n\t\t\t\ths >>= 1;\r\n\t\t\t_hashMask = hs;\r\n\t\t\ths++;\r\n\t\t\ths += kFixHashSize;\r\n\t\t}\r\n\t\tif (hs != _hashSizeSum)\r\n\t\t\t_hash = new int [_hashSizeSum = hs];\r\n\t\treturn true;\r\n\t}\r\n\tpublic int GetMatches(int[] distances) throws IOException\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t{\r\n\t\t\t\tMovePos();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint offset = 0;\r\n\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\tint maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint curMatch2 = _hash[hash2Value];\r\n\t\t\tint curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t}\r\n\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t}\r\n\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t{\r\n\t\t\t\toffset -= 2;\r\n\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\tint len0, len1;\r\n\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\tif (kNumHashDirectBytes != 0)\r\n\t\t{\r\n\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint count = _cutValue;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint len = Math.min(len0, len1);\r\n\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t{\r\n\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tif (maxLen < len)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t{\r\n\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\tlen1 = len;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\tlen0 = len;\r\n\t\t\t}\r\n\t\t}\r\n\t\tMovePos();\r\n\t\treturn offset;\r\n\t}\r\n\r\n\tpublic void Skip(int num) throws IOException\r\n\t{\r\n\t\tdo\r\n\t\t{\r\n\t\t\tint lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tint cur = _bufferOffset + _pos;\r\n\t\t\t\r\n\t\t\tint hashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\t\tint hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\t\tint hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tint len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\tint count = _cutValue;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tint len = Math.min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t}\r\n\t\twhile (--num != 0);\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint subValue = _pos - _cyclicBufferSize;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue) { _cutValue = cutValue; }\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\tif (offset > 0)\r\n\t\t\toffset--;\r\n\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free() { _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream) { _stream = stream; \t}\r\n\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\t// public static final int kDicLogSizeMax = 28;\r\n\t// public static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\r\n\r\n\r\n\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\r\n\tstatic byte[] g_FastPos = new byte[1 << 11];\r\n\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 22;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 11))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 21))\r\n\t\t\treturn (g_FastPos[pos >> 10] + 20);\r\n\t\treturn (g_FastPos[pos >> 20] + 40);\r\n\t}\r\n\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 17))\r\n\t\t\treturn (g_FastPos[pos >> 6] + 12);\r\n\t\tif (pos < (1 << 27))\r\n\t\t\treturn (g_FastPos[pos >> 16] + 32);\r\n\t\treturn (g_FastPos[pos >> 26] + 52);\r\n\t}\r\n\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\r\n\tstatic final int kDefaultDictionaryLogSize = 22;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\r\n\t\t\tpublic void Init() { SevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders); }\r\n\r\n\r\n\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetPrices(int posState, int numSymbols, int[] prices, int st)\r\n\t\t{\r\n\t\t\tint a0 = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\tint a1 = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\tint b0 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\tint b1 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\tint i = 0;\r\n\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t}\r\n\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t}\r\n\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t}\r\n\t};\r\n\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols<<Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\tpublic void SetTableSize(int tableSize) { _tableSize = tableSize; }\r\n\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t}\r\n\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\r\n\tstatic final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;\r\n\t\tpublic int BackPrev;\r\n\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\r\n\t\tpublic void MakeAsChar() { BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep() { return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null;\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\r\n\tshort[] _isMatch = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances-Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen*2+2];\r\n\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _numDistancePairs;\r\n\r\n\tint _additionalOffset;\r\n\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\r\n\tboolean _longestMatchWasFound;\r\n\r\n\tint[] _posSlotPrices = new int[1<<(Base.kNumPosSlotBits+Base.kNumLenToPosStatesBits)];\r\n\tint[] _distancesPrices = new int[Base.kNumFullDistances<<Base.kNumLenToPosStatesBits];\r\n\tint[] _alignPrices = new int[Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\tjava.io.InputStream _inStream;\r\n\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\r\n\tboolean _needReleaseMFStream = false;\r\n\r\n\tvoid Create()\r\n\t{\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tif (_matchFinderType == EMatchFinderTypeBT2)\r\n\t\t\t\tnumHashBytes = 2;\r\n\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\r\n\tvoid SetWriteEndMarkerMode(boolean writeEndMarker)\r\n\t{\r\n\t\t_writeEndMark = writeEndMarker;\r\n\t}\r\n\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\r\n\r\n\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n\t\t_posAlignEncoder.Init();\r\n\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = 0;\r\n\t\t_numDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\tif (_numDistancePairs > 0)\r\n\t\t{\r\n\t\t\tlenRes = _matchDistances[_numDistancePairs - 2];\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[_numDistancePairs - 1],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t}\r\n\t\t_additionalOffset++;\r\n\t\treturn lenRes;\r\n\t}\r\n\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tif (num > 0)\r\n\t\t{\r\n\t\t\t_matchFinder.Skip(num);\r\n\t\t\t_additionalOffset += num;\r\n\t\t}\r\n\t}\r\n\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\r\n\tint GetPureRepPrice(int repIndex, int state, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t}\r\n\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\r\n\tint Backward(int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\tint backRes;\r\n\r\n\tint GetOptimum(int position) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\tint lenMain, numDistancePairs;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tnumDistancePairs = _numDistancePairs;\r\n\r\n\t\tint numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\tif (numAvailableBytes < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\tbyte matchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[0].State = _state;\r\n\r\n\t\tint posState = (position & _posStateMask);\r\n\r\n\t\t_optimum[1].Price = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\tif (lenEnd < 2)\r\n\t\t{\r\n\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\tint len = lenEnd;\r\n\t\tdo\r\n\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\twhile (len >= 2);\r\n\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tif (repLen < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tint price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twhile (--repLen >= 2);\r\n\t\t}\r\n\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\r\n\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\tif (len <= lenMain)\r\n\t\t{\r\n\t\t\tint offs = 0;\r\n\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\toffs += 2;\r\n\t\t\tfor (; ; len++)\r\n\t\t\t{\r\n\t\t\t\tint distance = _matchDistances[offs + 1];\r\n\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t{\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint cur = 0;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\r\n\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t{\r\n\t\t\t\t// try Literal + rep0\r\n\t\t\t\tint t = Math.min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint startLen = 2; // speed optimization \r\n\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\tint lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t// if (_maxMode)\r\n\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t{\r\n\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, reps[repIndex], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - (reps[repIndex] + 1)),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t{\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t}\r\n\t\t\tif (newLen >= startLen)\r\n\t\t\t{\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\tint offs = 0;\r\n\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\tfor (int lenTest = startLen; ; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, curBack, t);\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\r\n\t\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - (curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\r\n\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\r\n\t\t\tint len = GetOptimum((int)nowPos64);\r\n\t\t\tint pos = backRes;\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\t// if (!_fastMode)\r\n\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\r\n\t\t// if (!_fastMode)\r\n\t\t{\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\r\n\tlong[] processedInSize = new long[1]; long[] processedOutSize = new long[1]; boolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\r\n\r\n\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\r\n\tint[] tempPrices = new int[Base.kNumFullDistances];\r\n\tint _matchPriceCount;\r\n\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t{\r\n\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t}\r\n\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tBitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\r\n\t\t\tint st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\tint st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t}\r\n\t\t_matchPriceCount = 0;\r\n\t}\r\n\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = 0;\r\n\t}\r\n\r\n\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\t/*\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\t*/\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = 29;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++) ;\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SeNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.42 Copyright (c) 1999-2006 Igor Pavlov  2006-05-15\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SeNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator() { Init(); }\r\n\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tint Rep0;\r\n\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\r\n\t\tpublic CBenchRandomGenerator() { }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit() { return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\tint GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\tRG.Init();\r\n\t\t\tRep0 = 1;\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint len;\r\n\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, long elapsedTime, long size)\r\n\t{\r\n\t\tlong t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\tlong numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime, long outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 220 + outSize * 20;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 18))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 18 (256 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/LGPL.txt",
    "content": "      GNU LESSER GENERAL PUBLIC LICENSE\r\n           Version 2.1, February 1999\r\n\r\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\r\n     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n Everyone is permitted to copy and distribute verbatim copies\r\n of this license document, but changing it is not allowed.\r\n\r\n[This is the first released version of the Lesser GPL.  It also counts\r\n as the successor of the GNU Library Public License, version 2, hence\r\n the version number 2.1.]\r\n\r\n          Preamble\r\n\r\n  The licenses for most software are designed to take away your\r\nfreedom to share and change it.  By contrast, the GNU General Public\r\nLicenses are intended to guarantee your freedom to share and change\r\nfree software--to make sure the software is free for all its users.\r\n\r\n  This license, the Lesser General Public License, applies to some\r\nspecially designated software packages--typically libraries--of the\r\nFree Software Foundation and other authors who decide to use it.  You\r\ncan use it too, but we suggest you first think carefully about whether\r\nthis license or the ordinary General Public License is the better\r\nstrategy to use in any particular case, based on the explanations below.\r\n\r\n  When we speak of free software, we are referring to freedom of use,\r\nnot price.  Our General Public Licenses are designed to make sure that\r\nyou have the freedom to distribute copies of free software (and charge\r\nfor this service if you wish); that you receive source code or can get\r\nit if you want it; that you can change the software and use pieces of\r\nit in new free programs; and that you are informed that you can do\r\nthese things.\r\n\r\n  To protect your rights, we need to make restrictions that forbid\r\ndistributors to deny you these rights or to ask you to surrender these\r\nrights.  These restrictions translate to certain responsibilities for\r\nyou if you distribute copies of the library or if you modify it.\r\n\r\n  For example, if you distribute copies of the library, whether gratis\r\nor for a fee, you must give the recipients all the rights that we gave\r\nyou.  You must make sure that they, too, receive or can get the source\r\ncode.  If you link other code with the library, you must provide\r\ncomplete object files to the recipients, so that they can relink them\r\nwith the library after making changes to the library and recompiling\r\nit.  And you must show them these terms so they know their rights.\r\n\r\n  We protect your rights with a two-step method: (1) we copyright the\r\nlibrary, and (2) we offer you this license, which gives you legal\r\npermission to copy, distribute and/or modify the library.\r\n\r\n  To protect each distributor, we want to make it very clear that\r\nthere is no warranty for the free library.  Also, if the library is\r\nmodified by someone else and passed on, the recipients should know\r\nthat what they have is not the original version, so that the original\r\nauthor's reputation will not be affected by problems that might be\r\nintroduced by others.\r\n\f\r\n  Finally, software patents pose a constant threat to the existence of\r\nany free program.  We wish to make sure that a company cannot\r\neffectively restrict the users of a free program by obtaining a\r\nrestrictive license from a patent holder.  Therefore, we insist that\r\nany patent license obtained for a version of the library must be\r\nconsistent with the full freedom of use specified in this license.\r\n\r\n  Most GNU software, including some libraries, is covered by the\r\nordinary GNU General Public License.  This license, the GNU Lesser\r\nGeneral Public License, applies to certain designated libraries, and\r\nis quite different from the ordinary General Public License.  We use\r\nthis license for certain libraries in order to permit linking those\r\nlibraries into non-free programs.\r\n\r\n  When a program is linked with a library, whether statically or using\r\na shared library, the combination of the two is legally speaking a\r\ncombined work, a derivative of the original library.  The ordinary\r\nGeneral Public License therefore permits such linking only if the\r\nentire combination fits its criteria of freedom.  The Lesser General\r\nPublic License permits more lax criteria for linking other code with\r\nthe library.\r\n\r\n  We call this license the \"Lesser\" General Public License because it\r\ndoes Less to protect the user's freedom than the ordinary General\r\nPublic License.  It also provides other free software developers Less\r\nof an advantage over competing non-free programs.  These disadvantages\r\nare the reason we use the ordinary General Public License for many\r\nlibraries.  However, the Lesser license provides advantages in certain\r\nspecial circumstances.\r\n\r\n  For example, on rare occasions, there may be a special need to\r\nencourage the widest possible use of a certain library, so that it becomes\r\na de-facto standard.  To achieve this, non-free programs must be\r\nallowed to use the library.  A more frequent case is that a free\r\nlibrary does the same job as widely used non-free libraries.  In this\r\ncase, there is little to gain by limiting the free library to free\r\nsoftware only, so we use the Lesser General Public License.\r\n\r\n  In other cases, permission to use a particular library in non-free\r\nprograms enables a greater number of people to use a large body of\r\nfree software.  For example, permission to use the GNU C Library in\r\nnon-free programs enables many more people to use the whole GNU\r\noperating system, as well as its variant, the GNU/Linux operating\r\nsystem.\r\n\r\n  Although the Lesser General Public License is Less protective of the\r\nusers' freedom, it does ensure that the user of a program that is\r\nlinked with the Library has the freedom and the wherewithal to run\r\nthat program using a modified version of the Library.\r\n\r\n  The precise terms and conditions for copying, distribution and\r\nmodification follow.  Pay close attention to the difference between a\r\n\"work based on the library\" and a \"work that uses the library\".  The\r\nformer contains code derived from the library, whereas the latter must\r\nbe combined with the library in order to run.\r\n\f\r\n      GNU LESSER GENERAL PUBLIC LICENSE\r\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\r\n\r\n  0. This License Agreement applies to any software library or other\r\nprogram which contains a notice placed by the copyright holder or\r\nother authorized party saying it may be distributed under the terms of\r\nthis Lesser General Public License (also called \"this License\").\r\nEach licensee is addressed as \"you\".\r\n\r\n  A \"library\" means a collection of software functions and/or data\r\nprepared so as to be conveniently linked with application programs\r\n(which use some of those functions and data) to form executables.\r\n\r\n  The \"Library\", below, refers to any such software library or work\r\nwhich has been distributed under these terms.  A \"work based on the\r\nLibrary\" means either the Library or any derivative work under\r\ncopyright law: that is to say, a work containing the Library or a\r\nportion of it, either verbatim or with modifications and/or translated\r\nstraightforwardly into another language.  (Hereinafter, translation is\r\nincluded without limitation in the term \"modification\".)\r\n\r\n  \"Source code\" for a work means the preferred form of the work for\r\nmaking modifications to it.  For a library, complete source code means\r\nall the source code for all modules it contains, plus any associated\r\ninterface definition files, plus the scripts used to control compilation\r\nand installation of the library.\r\n\r\n  Activities other than copying, distribution and modification are not\r\ncovered by this License; they are outside its scope.  The act of\r\nrunning a program using the Library is not restricted, and output from\r\nsuch a program is covered only if its contents constitute a work based\r\non the Library (independent of the use of the Library in a tool for\r\nwriting it).  Whether that is true depends on what the Library does\r\nand what the program that uses the Library does.\r\n  \r\n  1. You may copy and distribute verbatim copies of the Library's\r\ncomplete source code as you receive it, in any medium, provided that\r\nyou conspicuously and appropriately publish on each copy an\r\nappropriate copyright notice and disclaimer of warranty; keep intact\r\nall the notices that refer to this License and to the absence of any\r\nwarranty; and distribute a copy of this License along with the\r\nLibrary.\r\n\r\n  You may charge a fee for the physical act of transferring a copy,\r\nand you may at your option offer warranty protection in exchange for a\r\nfee.\r\n\f\r\n  2. You may modify your copy or copies of the Library or any portion\r\nof it, thus forming a work based on the Library, and copy and\r\ndistribute such modifications or work under the terms of Section 1\r\nabove, provided that you also meet all of these conditions:\r\n\r\n    a) The modified work must itself be a software library.\r\n\r\n    b) You must cause the files modified to carry prominent notices\r\n    stating that you changed the files and the date of any change.\r\n\r\n    c) You must cause the whole of the work to be licensed at no\r\n    charge to all third parties under the terms of this License.\r\n\r\n    d) If a facility in the modified Library refers to a function or a\r\n    table of data to be supplied by an application program that uses\r\n    the facility, other than as an argument passed when the facility\r\n    is invoked, then you must make a good faith effort to ensure that,\r\n    in the event an application does not supply such function or\r\n    table, the facility still operates, and performs whatever part of\r\n    its purpose remains meaningful.\r\n\r\n    (For example, a function in a library to compute square roots has\r\n    a purpose that is entirely well-defined independent of the\r\n    application.  Therefore, Subsection 2d requires that any\r\n    application-supplied function or table used by this function must\r\n    be optional: if the application does not supply it, the square\r\n    root function must still compute square roots.)\r\n\r\nThese requirements apply to the modified work as a whole.  If\r\nidentifiable sections of that work are not derived from the Library,\r\nand can be reasonably considered independent and separate works in\r\nthemselves, then this License, and its terms, do not apply to those\r\nsections when you distribute them as separate works.  But when you\r\ndistribute the same sections as part of a whole which is a work based\r\non the Library, the distribution of the whole must be on the terms of\r\nthis License, whose permissions for other licensees extend to the\r\nentire whole, and thus to each and every part regardless of who wrote\r\nit.\r\n\r\nThus, it is not the intent of this section to claim rights or contest\r\nyour rights to work written entirely by you; rather, the intent is to\r\nexercise the right to control the distribution of derivative or\r\ncollective works based on the Library.\r\n\r\nIn addition, mere aggregation of another work not based on the Library\r\nwith the Library (or with a work based on the Library) on a volume of\r\na storage or distribution medium does not bring the other work under\r\nthe scope of this License.\r\n\r\n  3. You may opt to apply the terms of the ordinary GNU General Public\r\nLicense instead of this License to a given copy of the Library.  To do\r\nthis, you must alter all the notices that refer to this License, so\r\nthat they refer to the ordinary GNU General Public License, version 2,\r\ninstead of to this License.  (If a newer version than version 2 of the\r\nordinary GNU General Public License has appeared, then you can specify\r\nthat version instead if you wish.)  Do not make any other change in\r\nthese notices.\r\n\f\r\n  Once this change is made in a given copy, it is irreversible for\r\nthat copy, so the ordinary GNU General Public License applies to all\r\nsubsequent copies and derivative works made from that copy.\r\n\r\n  This option is useful when you wish to copy part of the code of\r\nthe Library into a program that is not a library.\r\n\r\n  4. You may copy and distribute the Library (or a portion or\r\nderivative of it, under Section 2) in object code or executable form\r\nunder the terms of Sections 1 and 2 above provided that you accompany\r\nit with the complete corresponding machine-readable source code, which\r\nmust be distributed under the terms of Sections 1 and 2 above on a\r\nmedium customarily used for software interchange.\r\n\r\n  If distribution of object code is made by offering access to copy\r\nfrom a designated place, then offering equivalent access to copy the\r\nsource code from the same place satisfies the requirement to\r\ndistribute the source code, even though third parties are not\r\ncompelled to copy the source along with the object code.\r\n\r\n  5. A program that contains no derivative of any portion of the\r\nLibrary, but is designed to work with the Library by being compiled or\r\nlinked with it, is called a \"work that uses the Library\".  Such a\r\nwork, in isolation, is not a derivative work of the Library, and\r\ntherefore falls outside the scope of this License.\r\n\r\n  However, linking a \"work that uses the Library\" with the Library\r\ncreates an executable that is a derivative of the Library (because it\r\ncontains portions of the Library), rather than a \"work that uses the\r\nlibrary\".  The executable is therefore covered by this License.\r\nSection 6 states terms for distribution of such executables.\r\n\r\n  When a \"work that uses the Library\" uses material from a header file\r\nthat is part of the Library, the object code for the work may be a\r\nderivative work of the Library even though the source code is not.\r\nWhether this is true is especially significant if the work can be\r\nlinked without the Library, or if the work is itself a library.  The\r\nthreshold for this to be true is not precisely defined by law.\r\n\r\n  If such an object file uses only numerical parameters, data\r\nstructure layouts and accessors, and small macros and small inline\r\nfunctions (ten lines or less in length), then the use of the object\r\nfile is unrestricted, regardless of whether it is legally a derivative\r\nwork.  (Executables containing this object code plus portions of the\r\nLibrary will still fall under Section 6.)\r\n\r\n  Otherwise, if the work is a derivative of the Library, you may\r\ndistribute the object code for the work under the terms of Section 6.\r\nAny executables containing that work also fall under Section 6,\r\nwhether or not they are linked directly with the Library itself.\r\n\f\r\n  6. As an exception to the Sections above, you may also combine or\r\nlink a \"work that uses the Library\" with the Library to produce a\r\nwork containing portions of the Library, and distribute that work\r\nunder terms of your choice, provided that the terms permit\r\nmodification of the work for the customer's own use and reverse\r\nengineering for debugging such modifications.\r\n\r\n  You must give prominent notice with each copy of the work that the\r\nLibrary is used in it and that the Library and its use are covered by\r\nthis License.  You must supply a copy of this License.  If the work\r\nduring execution displays copyright notices, you must include the\r\ncopyright notice for the Library among them, as well as a reference\r\ndirecting the user to the copy of this License.  Also, you must do one\r\nof these things:\r\n\r\n    a) Accompany the work with the complete corresponding\r\n    machine-readable source code for the Library including whatever\r\n    changes were used in the work (which must be distributed under\r\n    Sections 1 and 2 above); and, if the work is an executable linked\r\n    with the Library, with the complete machine-readable \"work that\r\n    uses the Library\", as object code and/or source code, so that the\r\n    user can modify the Library and then relink to produce a modified\r\n    executable containing the modified Library.  (It is understood\r\n    that the user who changes the contents of definitions files in the\r\n    Library will not necessarily be able to recompile the application\r\n    to use the modified definitions.)\r\n\r\n    b) Use a suitable shared library mechanism for linking with the\r\n    Library.  A suitable mechanism is one that (1) uses at run time a\r\n    copy of the library already present on the user's computer system,\r\n    rather than copying library functions into the executable, and (2)\r\n    will operate properly with a modified version of the library, if\r\n    the user installs one, as long as the modified version is\r\n    interface-compatible with the version that the work was made with.\r\n\r\n    c) Accompany the work with a written offer, valid for at\r\n    least three years, to give the same user the materials\r\n    specified in Subsection 6a, above, for a charge no more\r\n    than the cost of performing this distribution.\r\n\r\n    d) If distribution of the work is made by offering access to copy\r\n    from a designated place, offer equivalent access to copy the above\r\n    specified materials from the same place.\r\n\r\n    e) Verify that the user has already received a copy of these\r\n    materials or that you have already sent this user a copy.\r\n\r\n  For an executable, the required form of the \"work that uses the\r\nLibrary\" must include any data and utility programs needed for\r\nreproducing the executable from it.  However, as a special exception,\r\nthe materials to be distributed need not include anything that is\r\nnormally distributed (in either source or binary form) with the major\r\ncomponents (compiler, kernel, and so on) of the operating system on\r\nwhich the executable runs, unless that component itself accompanies\r\nthe executable.\r\n\r\n  It may happen that this requirement contradicts the license\r\nrestrictions of other proprietary libraries that do not normally\r\naccompany the operating system.  Such a contradiction means you cannot\r\nuse both them and the Library together in an executable that you\r\ndistribute.\r\n\f\r\n  7. You may place library facilities that are a work based on the\r\nLibrary side-by-side in a single library together with other library\r\nfacilities not covered by this License, and distribute such a combined\r\nlibrary, provided that the separate distribution of the work based on\r\nthe Library and of the other library facilities is otherwise\r\npermitted, and provided that you do these two things:\r\n\r\n    a) Accompany the combined library with a copy of the same work\r\n    based on the Library, uncombined with any other library\r\n    facilities.  This must be distributed under the terms of the\r\n    Sections above.\r\n\r\n    b) Give prominent notice with the combined library of the fact\r\n    that part of it is a work based on the Library, and explaining\r\n    where to find the accompanying uncombined form of the same work.\r\n\r\n  8. You may not copy, modify, sublicense, link with, or distribute\r\nthe Library except as expressly provided under this License.  Any\r\nattempt otherwise to copy, modify, sublicense, link with, or\r\ndistribute the Library is void, and will automatically terminate your\r\nrights under this License.  However, parties who have received copies,\r\nor rights, from you under this License will not have their licenses\r\nterminated so long as such parties remain in full compliance.\r\n\r\n  9. You are not required to accept this License, since you have not\r\nsigned it.  However, nothing else grants you permission to modify or\r\ndistribute the Library or its derivative works.  These actions are\r\nprohibited by law if you do not accept this License.  Therefore, by\r\nmodifying or distributing the Library (or any work based on the\r\nLibrary), you indicate your acceptance of this License to do so, and\r\nall its terms and conditions for copying, distributing or modifying\r\nthe Library or works based on it.\r\n\r\n  10. Each time you redistribute the Library (or any work based on the\r\nLibrary), the recipient automatically receives a license from the\r\noriginal licensor to copy, distribute, link with or modify the Library\r\nsubject to these terms and conditions.  You may not impose any further\r\nrestrictions on the recipients' exercise of the rights granted herein.\r\nYou are not responsible for enforcing compliance by third parties with\r\nthis License.\r\n\f\r\n  11. If, as a consequence of a court judgment or allegation of patent\r\ninfringement or for any other reason (not limited to patent issues),\r\nconditions are imposed on you (whether by court order, agreement or\r\notherwise) that contradict the conditions of this License, they do not\r\nexcuse you from the conditions of this License.  If you cannot\r\ndistribute so as to satisfy simultaneously your obligations under this\r\nLicense and any other pertinent obligations, then as a consequence you\r\nmay not distribute the Library at all.  For example, if a patent\r\nlicense would not permit royalty-free redistribution of the Library by\r\nall those who receive copies directly or indirectly through you, then\r\nthe only way you could satisfy both it and this License would be to\r\nrefrain entirely from distribution of the Library.\r\n\r\nIf any portion of this section is held invalid or unenforceable under any\r\nparticular circumstance, the balance of the section is intended to apply,\r\nand the section as a whole is intended to apply in other circumstances.\r\n\r\nIt is not the purpose of this section to induce you to infringe any\r\npatents or other property right claims or to contest validity of any\r\nsuch claims; this section has the sole purpose of protecting the\r\nintegrity of the free software distribution system which is\r\nimplemented by public license practices.  Many people have made\r\ngenerous contributions to the wide range of software distributed\r\nthrough that system in reliance on consistent application of that\r\nsystem; it is up to the author/donor to decide if he or she is willing\r\nto distribute software through any other system and a licensee cannot\r\nimpose that choice.\r\n\r\nThis section is intended to make thoroughly clear what is believed to\r\nbe a consequence of the rest of this License.\r\n\r\n  12. If the distribution and/or use of the Library is restricted in\r\ncertain countries either by patents or by copyrighted interfaces, the\r\noriginal copyright holder who places the Library under this License may add\r\nan explicit geographical distribution limitation excluding those countries,\r\nso that distribution is permitted only in or among countries not thus\r\nexcluded.  In such case, this License incorporates the limitation as if\r\nwritten in the body of this License.\r\n\r\n  13. The Free Software Foundation may publish revised and/or new\r\nversions of the Lesser General Public License from time to time.\r\nSuch new versions will be similar in spirit to the present version,\r\nbut may differ in detail to address new problems or concerns.\r\n\r\nEach version is given a distinguishing version number.  If the Library\r\nspecifies a version number of this License which applies to it and\r\n\"any later version\", you have the option of following the terms and\r\nconditions either of that version or of any later version published by\r\nthe Free Software Foundation.  If the Library does not specify a\r\nlicense version number, you may choose any version ever published by\r\nthe Free Software Foundation.\r\n\f\r\n  14. If you wish to incorporate parts of the Library into other free\r\nprograms whose distribution conditions are incompatible with these,\r\nwrite to the author to ask for permission.  For software which is\r\ncopyrighted by the Free Software Foundation, write to the Free\r\nSoftware Foundation; we sometimes make exceptions for this.  Our\r\ndecision will be guided by the two goals of preserving the free status\r\nof all derivatives of our free software and of promoting the sharing\r\nand reuse of software generally.\r\n\r\n          NO WARRANTY\r\n\r\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\r\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\r\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\r\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\r\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\r\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\r\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\r\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\r\n\r\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\r\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\r\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\r\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\r\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\r\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\r\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\r\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\r\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\r\nDAMAGES.\r\n\r\n         END OF TERMS AND CONDITIONS\r\n\f\r\n           How to Apply These Terms to Your New Libraries\r\n\r\n  If you develop a new library, and you want it to be of the greatest\r\npossible use to the public, we recommend making it free software that\r\neveryone can redistribute and change.  You can do so by permitting\r\nredistribution under these terms (or, alternatively, under the terms of the\r\nordinary General Public License).\r\n\r\n  To apply these terms, attach the following notices to the library.  It is\r\nsafest to attach them to the start of each source file to most effectively\r\nconvey the exclusion of warranty; and each file should have at least the\r\n\"copyright\" line and a pointer to where the full notice is found.\r\n\r\n    <one line to give the library's name and a brief idea of what it does.>\r\n    Copyright (C) <year>  <name of author>\r\n\r\n    This library is free software; you can redistribute it and/or\r\n    modify it under the terms of the GNU Lesser General Public\r\n    License as published by the Free Software Foundation; either\r\n    version 2.1 of the License, or (at your option) any later version.\r\n\r\n    This library is distributed in the hope that it will be useful,\r\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r\n    Lesser General Public License for more details.\r\n\r\n    You should have received a copy of the GNU Lesser General Public\r\n    License along with this library; if not, write to the Free Software\r\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nAlso add information on how to contact you by electronic and paper mail.\r\n\r\nYou should also get your employer (if you work as a programmer) or your\r\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\r\nnecessary.  Here is a sample; alter the names:\r\n\r\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\r\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\r\n\r\n  <signature of Ty Coon>, 1 April 1990\r\n  Ty Coon, President of Vice\r\n\r\nThat's all there is to it!\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/Methods.txt",
    "content": "7-Zip method IDs (4.56)\r\n-----------------------\r\n\r\nEach compression or crypto method in 7z has unique binary value (ID).\r\nThe length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).\r\n\r\nIf you want to add some new ID, you have two ways:\r\n1) Write request for allocating IDs to 7-zip developers.\r\n2) Generate 8-bytes ID:\r\n\r\n    7F ZZ ZZ ZZ ZZ ZZ MM MM \r\n\r\n    7F              - Prefix for random IDs (1 byte)\r\n    ZZ ZZ ZZ ZZ ZZ  - Developer ID (5 bytes). Use real random bytes. \r\n                      \r\n    MM MM           - Method ID (2 bytes)\r\n\r\n    You can notify 7-Zip developers about your Developer ID / Method ID.\r\n\r\n    Note: Use new ID only if old codec can not decode data encoded with new version.\r\n\r\n\r\nList of defined IDs\r\n-------------------\r\n      \r\n00 - Copy\r\n01 - Reserved\r\n02 - Common\r\n   03 Swap\r\n      - 2 Swap2\r\n      - 4 Swap4\r\n   04 Delta (subject to change)\r\n\r\n03 - 7z\r\n   01 - LZMA\r\n      01 - Version\r\n  \r\n   03 - Branch\r\n      01 - x86\r\n         03  - BCJ\r\n         1B  - BCJ2\r\n      02 - PPC\r\n         05 - BC_PPC_B (Big Endian)\r\n      03 - Alpha\r\n         01 - BC_Alpha\r\n      04 - IA64\r\n         01 - BC_IA64\r\n      05 - ARM\r\n         01 - BC_ARM\r\n      06 - M68\r\n         05 - BC_M68_B (Big Endian)\r\n      07 - ARM Thumb\r\n         01 - BC_ARMThumb\r\n      08 - SPARC\r\n         05 - BC_SPARC\r\n\r\n   04 - PPMD\r\n      01 - Version\r\n\r\n   7F -\r\n      01 - experimental methods.\r\n\r\n   80 - reserved for independent developers\r\n\r\n   E0 - Random IDs\r\n\r\n04 - Misc\r\n   00 - Reserved\r\n   01 - Zip\r\n      00 - Copy (not used). Use {00} instead\r\n      01 - Shrink\r\n      06 - Implode\r\n      08 - Deflate\r\n      09 - Deflate64\r\n      12 - BZip2 (not used). Use {04 02 02} instead\r\n   02 - BZip\r\n      02 - BZip2\r\n   03 - Rar\r\n      01 - Rar15\r\n      02 - Rar20\r\n      03 - Rar29\r\n   04 - Arj\r\n      01 - Arj (1,2,3)\r\n      02 - Arj 4\r\n   05 - Z\r\n   06 - Lzh\r\n   07 - Reserved for 7z\r\n   08 - Cab\r\n   09 - NSIS\r\n      01 - DeflateNSIS\r\n      02 - BZip2NSIS\r\n\r\n\r\n06 - Crypto \r\n   00 - \r\n   01 - AES\r\n      0x - AES-128\r\n      4x - AES-192\r\n      8x - AES-256\r\n      Cx - AES\r\n\r\n      x0 - ECB\r\n      x1 - CBC\r\n      x2 - CFB\r\n      x3 - OFB\r\n\r\n   07 - Reserved\r\n   0F - Reserved\r\n\r\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\r\n\r\n   F1 - Misc Ciphers (Combine)\r\n      01 - Zip\r\n         01 - Main Zip crypto algo\r\n      03 - RAR\r\n         02 - \r\n         03 - Rar29 AES-128 + (modified SHA-1)\r\n      07 - 7z\r\n         01 - AES-256 + SHA-256\r\n\r\n07 - Hash (subject to change)\r\n   00 - \r\n   01 - CRC\r\n   02 - SHA-1\r\n   03 - SHA-256\r\n   04 - SHA-384\r\n   05 - SHA-512\r\n\r\n   F0 - Misc Hash\r\n\r\n   F1 - Misc\r\n      03 - RAR\r\n         03 - Rar29 Password Hashing (modified SHA1)\r\n      07 - 7z \r\n         01 - SHA-256 Password Hashing\r\n    \r\n   \r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/history.txt",
    "content": "HISTORY of the LZMA SDK\r\n-----------------------\r\n\r\n  4.57           2007-12-12\r\n  -------------------------\r\n    - Speed optimizations in ++ LZMA Decoder. \r\n    - Small changes for more compatibility with some C/C++ compilers.\r\n\r\n  \r\n  4.49 beta      2007-07-05\r\n  -------------------------\r\n    - .7z ANSI-C Decoder:\r\n         - now it supports BCJ and BCJ2 filters\r\n         - now it supports files larger than 4 GB.\r\n         - now it supports \"Last Write Time\" field for files.\r\n    - C++ code for .7z archives compressing/decompressing from 7-zip \r\n      was included to LZMA SDK.\r\n      \r\n\r\n  4.43           2006-06-04\r\n  -------------------------\r\n    - Small changes for more compatibility with some C/C++ compilers.\r\n      \r\n\r\n  4.42           2006-05-15\r\n  -------------------------\r\n    - Small changes in .h files in ANSI-C version.\r\n      \r\n\r\n  4.39 beta      2006-04-14\r\n  -------------------------\r\n    - Bug in versions 4.33b:4.38b was fixed:\r\n      C++ version of LZMA encoder could not correctly compress \r\n      files larger than 2 GB with HC4 match finder (-mfhc4).\r\n      \r\n\r\n  4.37 beta      2005-04-06\r\n  -------------------------\r\n    - Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r\n\r\n  \r\n  4.35 beta      2005-03-02\r\n  -------------------------\r\n    - Bug was fixed in C++ version of LZMA Decoder:\r\n       If encoded stream was corrupted, decoder could access memory \r\n       outside of allocated range.\r\n\r\n  \r\n  4.34 beta      2006-02-27\r\n  -------------------------\r\n    - Compressing speed and memory requirements for compressing were increased\r\n    - LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r\n\r\n  \r\n  4.32           2005-12-09\r\n  -------------------------\r\n    - Java version of LZMA SDK was included\r\n\r\n\r\n  4.30           2005-11-20\r\n  -------------------------\r\n    - Compression ratio was improved in -a2 mode\r\n    - Speed optimizations for compressing in -a2 mode\r\n    - -fb switch now supports values up to 273\r\n    - Bug in 7z_C (7zIn.c) was fixed:\r\n      It used Alloc/Free functions from different memory pools.\r\n      So if program used two memory pools, it worked incorrectly.\r\n    - 7z_C: .7z format supporting was improved\r\n    - LZMA# SDK (C#.NET version) was included\r\n\r\n\r\n  4.27 (Updated) 2005-09-21\r\n  -------------------------\r\n   - Some GUIDs/interfaces in C++ were changed.\r\n     IStream.h:\r\n       ISequentialInStream::Read now works as old ReadPart\r\n       ISequentialOutStream::Write now works as old WritePart\r\n\r\n  \r\n  4.27           2005-08-07\r\n  -------------------------\r\n    - Bug in LzmaDecodeSize.c was fixed:\r\n       if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r\n       decompressing worked incorrectly.\r\n\r\n\r\n  4.26           2005-08-05\r\n  -------------------------\r\n    - Fixes in 7z_C code and LzmaTest.c:\r\n      previous versions could work incorrectly,\r\n      if malloc(0) returns 0\r\n\r\n\r\n  4.23           2005-06-29\r\n  -------------------------\r\n    - Small fixes in C++ code\r\n\r\n\r\n  4.22           2005-06-10\r\n  -------------------------\r\n    - Small fixes\r\n\r\n\r\n  4.21           2005-06-08\r\n  -------------------------\r\n    - Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r\n    - New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r\n        - LzmaStateDecode.h\r\n        - LzmaStateDecode.c\r\n        - LzmaStateTest.c\r\n    - ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r\n\r\n  \r\n  4.17           2005-04-18\r\n  -------------------------\r\n    - New example for RAM->RAM compressing/decompressing: \r\n      LZMA + BCJ (filter for x86 code):\r\n        - LzmaRam.h\r\n        - LzmaRam.cpp\r\n        - LzmaRamDecode.h\r\n        - LzmaRamDecode.c\r\n        - -f86 switch for lzma.exe\r\n\r\n  \r\n  4.16           2005-03-29\r\n  -------------------------\r\n    - Bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r\n       If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r\n       decoder could access memory outside of allocated range.\r\n    - Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r\n      Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r\n      LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r\n    - Small speed optimization in LZMA C++ code\r\n    - filter for SPARC's code was added\r\n    - Simplified version of .7z ANSI-C Decoder was included\r\n\r\n\r\n  4.06           2004-09-05\r\n  -------------------------\r\n    - Bug in v4.05 was fixed:\r\n        LZMA-Encoder didn't release output stream in some cases.\r\n\r\n\r\n  4.05           2004-08-25\r\n  -------------------------\r\n    - Source code of filters for x86, IA-64, ARM, ARM-Thumb \r\n      and PowerPC code was included to SDK\r\n    - Some internal minor changes\r\n\r\n\r\n  4.04           2004-07-28\r\n  -------------------------\r\n    - More compatibility with some C++ compilers\r\n\r\n\r\n  4.03           2004-06-18\r\n  -------------------------\r\n    - \"Benchmark\" command was added. It measures compressing \r\n      and decompressing speed and shows rating values. \r\n      Also it checks hardware errors.\r\n\r\n\r\n  4.02           2004-06-10\r\n  -------------------------\r\n    - C++ LZMA Encoder/Decoder code now is more portable\r\n      and it can be compiled by GCC on Linux.\r\n\r\n\r\n  4.01           2004-02-15\r\n  -------------------------\r\n    - Some detection of data corruption was enabled.\r\n        LzmaDecode.c / RangeDecoderReadByte\r\n        .....\r\n        {\r\n          rd->ExtraBytes = 1;\r\n          return 0xFF;\r\n        }\r\n\r\n\r\n  4.00           2004-02-13\r\n  -------------------------\r\n    - Original version of LZMA SDK\r\n\r\n\r\n\r\nHISTORY of the LZMA\r\n-------------------\r\n  2001-2007:  Improvements to LZMA compressing/decompressing code, \r\n              keeping compatibility with original LZMA format\r\n  1996-2001:  Development of LZMA compression format\r\n\r\n  Some milestones:\r\n\r\n  2001-08-30: LZMA compression was added to 7-Zip\r\n  1999-01-02: First version of 7-Zip was released\r\n  \r\n\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/lzma/lzma.txt",
    "content": "LZMA SDK 4.57\r\n-------------\r\n\r\nLZMA SDK   Copyright (C) 1999-2007 Igor Pavlov\r\n\r\nLZMA SDK provides the documentation, samples, header files, libraries, \r\nand tools you need to develop applications that use LZMA compression.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\nLZMA is an improved version of famous LZ77 compression algorithm. \r\nIt was improved in way of maximum increasing of compression ratio,\r\nkeeping high decompression speed and low memory requirements for \r\ndecompressing.\r\n\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nLZMA SDK is available under any of the following licenses:\r\n\r\n1) GNU Lesser General Public License (GNU LGPL)\r\n2) Common Public License (CPL)\r\n3) Simplified license for unmodified code (read SPECIAL EXCEPTION) \r\n4) Proprietary license \r\n\r\nIt means that you can select one of these four options and follow rules of that license.\r\n\r\n\r\n1,2) GNU LGPL and CPL licenses are pretty similar and both these\r\nlicenses are classified as \r\n - \"Free software licenses\" at http://www.gnu.org/ \r\n - \"OSI-approved\" at http://www.opensource.org/\r\n\r\n\r\n3) SPECIAL EXCEPTION\r\n\r\nIgor Pavlov, as the author of this code, expressly permits you \r\nto statically or dynamically link your code (or bind by name) \r\nto the files from LZMA SDK without subjecting your linked \r\ncode to the terms of the CPL or GNU LGPL. \r\nAny modifications or additions to files from LZMA SDK, however, \r\nare subject to the GNU LGPL or CPL terms.\r\n\r\nSPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code, \r\nwhile you keep LZMA SDK code unmodified.\r\n\r\n\r\nSPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use this code under the same terms and conditions contained in the License \r\nAgreement you have for any previous version of LZMA SDK developed by Igor Pavlov.\r\n\r\nSPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version \r\nof LZMA SDK as update for previous versions.\r\n\r\n\r\nSPECIAL EXCEPTION #3: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use code of the following files: \r\nBranchTypes.h, LzmaTypes.h, LzmaTest.c, LzmaStateTest.c, LzmaAlone.cpp, \r\nLzmaAlone.cs, LzmaAlone.java\r\nas public domain code. \r\n\r\n\r\n4) Proprietary license\r\n\r\nLZMA SDK also can be available under a proprietary license which \r\ncan include:\r\n\r\n1) Right to modify code without subjecting modified code to the \r\nterms of the CPL or GNU LGPL\r\n2) Technical support for code\r\n\r\nTo request such proprietary license or any additional consultations,\r\nsend email message from that page:\r\nhttp://www.7-zip.org/support.html\r\n\r\n\r\nYou should have received a copy of the GNU Lesser General Public\r\nLicense along with this library; if not, write to the Free Software\r\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nYou should have received a copy of the Common Public License\r\nalong with this library.\r\n\r\n\r\nLZMA SDK Contents\r\n-----------------\r\n\r\nLZMA SDK includes:\r\n\r\n  - C++ source code of LZMA compressing and decompressing\r\n  - ANSI-C compatible source code for LZMA decompressing\r\n  - C# source code for LZMA compressing and decompressing\r\n  - Java source code for LZMA compressing and decompressing\r\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\r\n\r\nANSI-C LZMA decompression code was ported from original C++ sources to C.\r\nAlso it was simplified and optimized for code size. \r\nBut it is fully compatible with LZMA from 7-Zip.\r\n\r\n\r\nUNIX/Linux version \r\n------------------\r\nTo compile C++ version of file->file LZMA, go to directory\r\nC/7zip/Compress/LZMA_Alone \r\nand type \"make\" or \"make clean all\" to recompile all.\r\n\r\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\r\nTo compile with static libraries, change string in makefile\r\nLIB = -lm\r\nto string  \r\nLIB = -lm -static\r\n\r\n\r\nFiles\r\n---------------------\r\nC        - C source code\r\nCPP      - CPP source code\r\nCS       - C# source code\r\nJava     - Java source code\r\nlzma.txt - LZMA SDK description (this file)\r\n7zFormat.txt - 7z Format description\r\n7zC.txt  - 7z ANSI-C Decoder description (this file)\r\nmethods.txt  - Compression method IDs for .7z\r\nLGPL.txt - GNU Lesser General Public License\r\nCPL.html - Common Public License\r\nlzma.exe - Compiled file->file LZMA encoder/decoder for Windows\r\nhistory.txt - history of the LZMA SDK\r\n\r\n\r\nSource code structure\r\n---------------------\r\n\r\nC  - C files\r\n    Compress - files related to compression/decompression\r\n      Lz     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      Lzma   - ANSI-C compatible LZMA decompressor\r\n\r\n        LzmaDecode.h  - interface for LZMA decoding on ANSI-C\r\n        LzmaDecode.c      - LZMA decoding on ANSI-C (new fastest version)\r\n        LzmaDecodeSize.c  - LZMA decoding on ANSI-C (old size-optimized version)\r\n        LzmaTest.c        - test application that decodes LZMA encoded file\r\n        LzmaTypes.h       - basic types for LZMA Decoder\r\n        LzmaStateDecode.h - interface for LZMA decoding (State version)\r\n        LzmaStateDecode.c - LZMA decoding on ANSI-C (State version)\r\n        LzmaStateTest.c   - test application (State version)\r\n\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n\r\n    Archive - files related to archiving\r\n      7z_C     - 7z ANSI-C Decoder\r\n\r\n\r\nCPP -- CPP files\r\n\r\n  Common  - common files for C++ projects\r\n  Windows - common files for Windows related code\r\n  7zip    - files related to 7-Zip Project\r\n\r\n    Common   - common files for 7-Zip\r\n\r\n    Compress - files related to compression/decompression\r\n\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n\r\n      Copy         - Copy coder\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n      LZMA         - LZMA compression/decompression on C++\r\n      LZMA_Alone   - file->file LZMA compression/decompression\r\n\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n\r\n    Archive - files related to archiving\r\n\r\n      Common   - common files for archive handling\r\n      7z       - 7z C++ Encoder/Decoder\r\n\r\n    Bundles    - Modules that are bundles of other modules\r\n  \r\n      Alone7z           - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2\r\n      Format7zR         - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r\n      Format7zExtractR  - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.\r\n\r\n    UI        - User Interface files\r\n         \r\n      Client7z - Test application for 7za.dll,  7zr.dll, 7zxr.dll\r\n      Common   - Common UI files\r\n      Console  - Code for console archiver\r\n\r\n\r\n\r\nCS - C# files\r\n  7zip\r\n    Common   - some common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      LzmaAlone    - file->file LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nJava  - Java files\r\n  SevenZip\r\n    Compression    - files related to compression/decompression\r\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nC/C++ source code of LZMA SDK is part of 7-Zip project.\r\n\r\nYou can find ANSI-C LZMA decompressing code at folder \r\n  C/7zip/Compress/Lzma\r\n7-Zip doesn't use that ANSI-C LZMA code and that code was developed \r\nspecially for this SDK. And files from C/7zip/Compress/Lzma do not need \r\nfiles from other directories of SDK for compiling.\r\n\r\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r\n\r\n  http://sourceforge.net/projects/sevenzip/\r\n\r\n\r\nLZMA features\r\n-------------\r\n  - Variable dictionary size (up to 1 GB)\r\n  - Estimated compressing speed: about 1 MB/s on 1 GHz CPU\r\n  - Estimated decompressing speed: \r\n      - 8-12 MB/s on 1 GHz Intel Pentium 3 or AMD Athlon\r\n      - 500-1000 KB/s on 100 MHz ARM, MIPS, PowerPC or other simple RISC\r\n  - Small memory requirements for decompressing (8-32 KB + DictionarySize)\r\n  - Small code size for decompressing: 2-8 KB (depending from \r\n    speed optimizations) \r\n\r\nLZMA decoder uses only integer operations and can be \r\nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r\n\r\nSome critical operations that affect to speed of LZMA decompression:\r\n  1) 32*16 bit integer multiply\r\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\r\n  3) 32-bit shift and arithmetic operations\r\n\r\nSpeed of LZMA decompressing mostly depends from CPU speed.\r\nMemory speed has no big meaning. But if your CPU has small data cache, \r\noverall weight of memory speed will slightly increase.\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nUsing LZMA encoder/decoder executable\r\n--------------------------------------\r\n\r\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\r\n\r\n  e: encode file\r\n\r\n  d: decode file\r\n\r\n  b: Benchmark. There are two tests: compressing and decompressing \r\n     with LZMA method. Benchmark shows rating in MIPS (million \r\n     instructions per second). Rating value is calculated from \r\n     measured speed and it is normalized with AMD Athlon 64 X2 CPU\r\n     results. Also Benchmark checks possible hardware errors (RAM \r\n     errors in most cases). Benchmark uses these settings:\r\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d. Also you \r\n     can change number of iterations. Example for 30 iterations:\r\n       LZMA b 30\r\n     Default number of iterations is 10.\r\n\r\n<Switches>\r\n  \r\n\r\n  -a{N}:  set compression mode 0 = fast, 1 = normal\r\n          default: 1 (normal)\r\n\r\n  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r\n          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \r\n          For decompressing file compressed by LZMA method with dictionary \r\n          size D = 2^N you need about D bytes of memory (RAM).\r\n\r\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\r\n          Usually big number gives a little bit better compression ratio \r\n          and slower compression process.\r\n\r\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\r\n          Sometimes lc=4 gives gain for big files.\r\n\r\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r\n          lp switch is intended for periodical data when period is \r\n          equal 2^N. For example, for 32-bit (4 bytes) \r\n          periodical data you can use lp=2. Often it's better to set lc0, \r\n          if you change lp switch.\r\n\r\n  -pb{N}: set number of pos bits - [0, 4], default: 2\r\n          pb switch is intended for periodical data \r\n          when period is equal 2^N.\r\n\r\n  -mf{MF_ID}: set Match Finder. Default: bt4. \r\n              Algorithms from hc* group doesn't provide good compression \r\n              ratio, but they often works pretty fast in combination with \r\n              fast mode (-a0).\r\n\r\n              Memory requirements depend from dictionary size \r\n              (parameter \"d\" in table below). \r\n\r\n               MF_ID     Memory                   Description\r\n\r\n                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r\n                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r\n                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r\n                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r\n\r\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \r\n          eos marker, since LZMA decoder knows uncompressed size \r\n          stored in .lzma file header.\r\n\r\n  -si:    Read data from stdin (it will write End Of Stream marker).\r\n  -so:    Write data to stdout\r\n\r\n\r\nExamples:\r\n\r\n1) LZMA e file.bin file.lzma -d16 -lc0 \r\n\r\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r\nand 0 literal context bits. -lc0 allows to reduce memory requirements \r\nfor decompression.\r\n\r\n\r\n2) LZMA e file.bin file.lzma -lc0 -lp2\r\n\r\ncompresses file.bin to file.lzma with settings suitable \r\nfor 32-bit periodical data (for example, ARM or MIPS code).\r\n\r\n3) LZMA d file.lzma file.bin\r\n\r\ndecompresses file.lzma to file.bin.\r\n\r\n\r\nCompression ratio hints\r\n-----------------------\r\n\r\nRecommendations\r\n---------------\r\n\r\nTo increase compression ratio for LZMA compressing it's desirable \r\nto have aligned data (if it's possible) and also it's desirable to locate\r\ndata in such order, where code is grouped in one place and data is \r\ngrouped in other place (it's better than such mixing: code, data, code,\r\ndata, ...).\r\n\r\n\r\nUsing Filters\r\n-------------\r\nYou can increase compression ratio for some data types, using\r\nspecial filters before compressing. For example, it's possible to \r\nincrease compression ratio on 5-10% for code for those CPU ISAs: \r\nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r\n\r\nYou can find C/C++ source code of such filters in folder \"7zip/Compress/Branch\"\r\n\r\nYou can check compression ratio gain of these filters with such \r\n7-Zip commands (example for ARM code):\r\nNo filter:\r\n  7z a a1.7z a.bin -m0=lzma\r\n\r\nWith filter for little-endian ARM code:\r\n  7z a a2.7z a.bin -m0=bc_arm -m1=lzma        \r\n\r\nWith filter for big-endian ARM code (using additional Swap4 filter):\r\n  7z a a3.7z a.bin -m0=swap4 -m1=bc_arm -m2=lzma\r\n\r\nIt works in such manner:\r\nCompressing    = Filter_encoding + LZMA_encoding\r\nDecompressing  = LZMA_decoding + Filter_decoding\r\n\r\nCompressing and decompressing speed of such filters is very high,\r\nso it will not increase decompressing time too much.\r\nMoreover, it reduces decompression time for LZMA_decoding, \r\nsince compression ratio with filtering is higher.\r\n\r\nThese filters convert CALL (calling procedure) instructions \r\nfrom relative offsets to absolute addresses, so such data becomes more \r\ncompressible. Source code of these CALL filters is pretty simple\r\n(about 20 lines of C++), so you can convert it from C++ version yourself.\r\n\r\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r\n\r\n\r\nLZMA compressed file format\r\n---------------------------\r\nOffset Size Description\r\n  0     1   Special LZMA properties for compressed data\r\n  1     4   Dictionary size (little endian)\r\n  5     8   Uncompressed size (little endian). -1 means unknown size\r\n 13         Compressed data\r\n\r\n\r\nANSI-C LZMA Decoder\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nTo compile ANSI-C LZMA Decoder you can use one of the following files sets:\r\n1) LzmaDecode.h + LzmaDecode.c + LzmaTest.c  (fastest version)\r\n2) LzmaDecode.h + LzmaDecodeSize.c + LzmaTest.c  (old size-optimized version)\r\n3) LzmaStateDecode.h + LzmaStateDecode.c + LzmaStateTest.c  (zlib-like interface)\r\n\r\n\r\nMemory requirements for LZMA decoding\r\n-------------------------------------\r\n\r\nLZMA decoder doesn't allocate memory itself, so you must \r\nallocate memory and send it to LZMA.\r\n\r\nStack usage of LZMA decoding function for local variables is not \r\nlarger than 200 bytes.\r\n\r\nHow To decompress data\r\n----------------------\r\n\r\nLZMA Decoder (ANSI-C version) now supports 5 interfaces:\r\n1) Single-call Decompressing\r\n2) Single-call Decompressing with input stream callback\r\n3) Multi-call Decompressing with output buffer\r\n4) Multi-call Decompressing with input callback and output buffer\r\n5) Multi-call State Decompressing (zlib-like interface)\r\n\r\nVariant-5 is similar to Variant-4, but Variant-5 doesn't use callback functions.\r\n\r\nDecompressing steps\r\n-------------------\r\n\r\n1) read LZMA properties (5 bytes):\r\n   unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n2) read uncompressed size (8 bytes, little-endian)\r\n\r\n3) Decode properties:\r\n\r\n  CLzmaDecoderState state;  /* it's 24-140 bytes structure, if int is 32-bit */\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n\r\n4) Allocate memory block for internal Structures:\r\n\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n\r\n  LZMA decoder uses array of CProb variables as internal structure.\r\n  By default, CProb is unsigned_short. But you can define _LZMA_PROB32 to make \r\n  it unsigned_int. It can increase speed on some 32-bit CPUs, but memory \r\n  usage will be doubled in that case.\r\n\r\n\r\n5) Main Decompressing\r\n\r\nYou must use one of the following interfaces:\r\n\r\n5.1 Single-call Decompressing\r\n-----------------------------\r\nWhen to use: RAM->RAM decompressing\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: no defines\r\nMemory Requirements:\r\n  - Input buffer: compressed size\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  int res = LzmaDecode(&state, \r\n      inStream, compressedSize, &inProcessed,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.2 Single-call Decompressing with input stream callback\r\n--------------------------------------------------------\r\nWhen to use: File->RAM or Flash->RAM decompressing.\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB\r\nMemory Requirements:\r\n  - Buffer for input stream: any size (for example, 16 KB)\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  typedef struct _CBuffer\r\n  {\r\n    ILzmaInCallback InCallback;\r\n    FILE *File;\r\n    unsigned char Buffer[kInBufferSize];\r\n  } CBuffer;\r\n\r\n  int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n  {\r\n    CBuffer *bo = (CBuffer *)object;\r\n    *buffer = bo->Buffer;\r\n    *size = MyReadFile(bo->File, bo->Buffer, kInBufferSize);\r\n    return LZMA_RESULT_OK;\r\n  }\r\n\r\n  CBuffer g_InBuffer;\r\n\r\n  g_InBuffer.File = inFile;\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  int res = LzmaDecode(&state, \r\n      &g_InBuffer.InCallback,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.3 Multi-call decompressing with output buffer\r\n-----------------------------------------------\r\nWhen to use: RAM->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Input buffer: compressed size\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details.\r\n\r\n\r\n5.4 Multi-call decompressing with input callback and output buffer\r\n------------------------------------------------------------------\r\nWhen to use: File->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB, _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      &bo.InCallback,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details:\r\n\r\n\r\n5.5 Multi-call State Decompressing (zlib-like interface)\r\n------------------------------------------------------------------\r\nWhen to use: file->file decompressing \r\nCompile files: LzmaStateDecode.h, LzmaStateDecode.c\r\nCompile defines:\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    res = LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed,\r\n      finishDecoding);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaStateTest.c for more details:\r\n\r\n\r\n6) Free all allocated blocks\r\n\r\n\r\nNote\r\n----\r\nLzmaDecodeSize.c is size-optimized version of LzmaDecode.c.\r\nBut compiled code of LzmaDecodeSize.c can be larger than \r\ncompiled code of LzmaDecode.c. So it's better to use \r\nLzmaDecode.c in most cases.\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\nLZMA decoder can return one of the following codes:\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\nIf you use callback function for input data and you return some \r\nerror code, LZMA Decoder also returns that code.\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB    - Use callback for input data\r\n\r\n_LZMA_OUT_READ - Use read function for output data\r\n\r\n_LZMA_LOC_OPT  - Enable local speed optimizations inside code.\r\n                 _LZMA_LOC_OPT is only for LzmaDecodeSize.c (size-optimized version).\r\n                 _LZMA_LOC_OPT doesn't affect LzmaDecode.c (speed-optimized version)\r\n                 and LzmaStateDecode.c\r\n\r\n_LZMA_PROB32   - It can increase speed on some 32-bit CPUs, \r\n                 but memory usage will be doubled in that case\r\n\r\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler\r\n                         and long is 32-bit.\r\n\r\n_LZMA_SYSTEM_SIZE_T  - Define it if you want to use system's size_t.\r\n                       You can use it to enable 64-bit sizes supporting\r\n\r\n\r\n\r\nC++ LZMA Encoder/Decoder \r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nC++ LZMA code use COM-like interfaces. So if you want to use it, \r\nyou can study basics of COM/OLE.\r\n\r\nBy default, LZMA Encoder contains all Match Finders.\r\nBut for compressing it's enough to have just one of them.\r\nSo for reducing size of compressing code you can define:\r\n  #define COMPRESS_MF_BT\r\n  #define COMPRESS_MF_BT4\r\nand it will use only bt4 match finder.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/sqlzma.h",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.\n */\n\n/* $Id: sqlzma.h,v 1.20 2008-03-12 16:58:34 jro Exp $ */\n\n#ifndef __sqlzma_h__\n#define __sqlzma_h__\n\n#ifndef __KERNEL__\n#include <stdlib.h>\n#include <string.h>\n#include <zlib.h>\n#ifdef _REENTRANT\n#include <pthread.h>\n#endif\n#else\n#include <linux/zlib.h>\n#endif\n#define _7ZIP_BYTE_DEFINED\n\n/*\n * detect the compression method automatically by the first byte of compressed\n * data.\n * according to rfc1950, the first byte of zlib compression must be 0x?8.\n */\n#define is_lzma(c)\t(c == 0x5d)\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#ifndef __KERNEL__\n/* for mksquashfs only */\nstruct sqlzma_opts {\n\tunsigned int\ttry_lzma;\n\tunsigned int \tdicsize;\n};\nint sqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in,\n\t      uInt avail_in, Bytef *next_out, uInt avail_out);\n#endif\n\n/* ---------------------------------------------------------------------- */\n/*\n * Three patterns for sqlzma uncompression. very dirty code.\n * - kernel space (squashfs kernel module)\n * - user space with pthread (mksquashfs)\n * - user space without pthread (unsquashfs)\n */\n\nstruct sized_buf {\n\tunsigned int\tsz;\n\tunsigned char\t*buf;\n};\n\nenum {SQUN_PROB, SQUN_RESULT, SQUN_LAST};\nstruct sqlzma_un {\n\tint\t\t\tun_lzma;\n\tstruct sized_buf\tun_a[SQUN_LAST];\n\tunsigned char           un_prob[31960]; /* unlzma 64KB - 1MB */\n\tz_stream\t\tun_stream;\n#define un_cmbuf\tun_stream.next_in\n#define un_cmlen\tun_stream.avail_in\n#define un_resbuf\tun_stream.next_out\n#define un_resroom\tun_stream.avail_out\n#define un_reslen\tun_stream.total_out\n};\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz);\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst);\nvoid sqlzma_fin(struct sqlzma_un *un);\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\n};\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/sqlzma.txt",
    "content": "\n# Copyright (C) 2006-2008 Junjiro Okajima\n# Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described ones in lzma and squashfs.\n\n# $Id: sqlzma.txt,v 1.37 2008-03-12 15:16:50 jro Exp $\n\nLZMA patch for squashfs\nJunjiro Okajima\n\n\no What is this?\nThis is a patch against lzma449.tar.bz2 and squashfs3.3.tar.gz, and\nmakes squashfs to support both of LZMA compression and ZLIB\ncompression.\nThe new squashfs image file (generated without '-nolzma' option) has no\nbackward compatibility, while the patched squashfs and its tools can handle\nthe old squashfs image generated by the unpatched squashfs-tools.\n\nThis patch is developed and tested on linux-2.6.24.3.\n\n\no Files\n- Makefile\n  a toplevel makefile which builds everything. it is recommended to use this\n  makefile.\n- sqlzma.h\n  a global header file. this file is used from kernel and userspace utilities.\n- sqmagic.h\n  defines patched squashfs magic number.\n- sqlzma1-XXX.patch\n  a patch against lzma package. currently it is lzma449.tar.bz2 and the 'XXX\n  in filename is '449'.\n- sqlzma2k-YYY.patch\n  a patch against squashfs kernel source. currently it is\n  squashfs3.3.tar.gz and the 'YYY' in filename is '3.3'.\n- sqlzma2u-YYY.patch\n  a patch against squashfs utility.\n\n\no Download, Extract, Patch and Build\n- choose the lzma version you use, and modify ./Makefile.\n- mkdir lzmaXXX, get SourceForge/sevenzip/lzmaXXX.tar.bz2, and extract it into\n  lzmaXXX dir.\n- apply sqlzma1-XXX.patch to lzmaXXX.\n- get SourceForge/squashfs/squashfsYYY.tar.gz, extract, and get squashfsYYY/.\n- apply squashfsYYY/kernel-patches/linux-2.6.24.3/squashfsYYY-patch to your\n  kernel source, and then also apply sqlzma2k-YYY.patch to it.\n- apply sqlzma2u-YYY.patch to squashfsYYY.\n- make them. if you have lzmaXXX and squashfsYYY in the same dir, a toplevel\n  Makefile in this patchset builds everything for you.\n  If you want to change their path, edit the variable definitions in\n  ./Makefile.\n- It builds these things.\n\t+ ${Squashfs}/kernel-patches/${KVer}/fs/squashfs/\n\t\t* squashfs.ko\n\t\t  a patched squashfs which supports LZMA uncompression. If you\n\t\t  didn't load unlzma.ko and sqlzma.ko before compilation of\n\t\t  squashfs.ko, the linker may produce some warnings about the\n\t\t  functions in sqlzma.ko. But you can ignore them in safe.\n\t+ ${Lzma}/C/7zip/Compress/LZMA_C/\n\t\t* libunlzma.a\n\t\t  LZMA uncompression user library for squashfs utilities.\n\t\t* libunlzma_r.a\n\t\t  thread-safe one.\n\t+ ${Lzma}/C/7zip/Compress/LZMA_C/kmod/\n\t\t* unlzma.ko\n\t\t  generic LZMA uncompression module for linux kernel.\n\t\t* sqlzma.ko\n\t\t  LZMA uncompression kernel module for squashfs, a bridge\n\t\t  library between squashfs and unlzma.ko.\n\t+ ${Lzma}/C/7zip/Compress/LZMA_Alone/\n\t\t* liblzma_r.a\n\t\t  thread-safe LZMA compression user library for squashfs\n\t\t  utilities.\n\t+ ${Squashfs}/squashfs-tools/\n\t\t* mksquashfs, unsquashfs\n\t\t  patched squashfs utilities which support LZMA compression.\n- copy the modules squashfs.ko, unlzma.ko and sqlzma.ko to wherever you like.\n- load these modules.\n- create your filesystem image by mksquashfs.\n- mount it and enjoy.\n\n\no Added options\n- mksquashfs -lzmadic N\n  This option sets the dictionary size for LZMA compression.\n  The default value is same as the block size, even if you change the\n  block size by specifying -b (block size) option for mksquashfs. The\n  dictionary size always follows it by default.\n  If you want to set a different value from the block size, then use\n  this option ALONE or AFTER -b option.\n  In append mode, you can't change the block size, but the LZMA\n  dictionary size since the compression is done for every and each\n  block.\n  The syntax is equivalent ot -b option, ie. you can use K\n  (kilobyte) or M (megabyte).\n- mksquashfs -nolzma\n  This option makes mksquashfs not to try LZMA compression. And it uses only\n  ZLIB compression, as it was unpatched.\n- no options are added to unsquashfs.\n  the patched unsquashfs automatically detects whether the given squashfs\n  image uses LZMA compression or not.\n\n\no LZMA and ZLIB\nThere are three groups of byte stream in compression.\n- both of LZMA and ZLIB cannot compress.\n- LZMA gets better compression.\n- ZLIB gets better compression.\n\nThis patch supports both compression methods. The patched mksquashfs tries\nZLIB compression first. If the data cannot be compressed, store the data\nuncompressed as unpatched mksquashfs does. If it succeeds and -nolzma option\nis not specified, then keep the compressed data and try LZMA compression.\nAfter LZMA compression, compares the sizes of the two compressed data and\ndiscard the larger one.\n\nHonestly speaking, I do know nothing about the compression theory. This is the\nfact I got from using these libraries.\n(What is this thing called in English? a rule of thumb?)\n\n\no Multi-call decompression and parallel decompression\nWhile squashfs3.1-r2 took the approach of single-call ZLIB decompression,\nsquashfs3.2 and later takes the approach of multi-call which has an\nadvantage of memory consumption. So I tried implementing multi-call\nLZMA decompression too, but I gave up. Because of memory usage. While\nsingle-call LZMA decompression doesn't require a dictionary,\nmulti-call does. And its size can be mega-bytes (the dictionary size\nwhich I checked was 8388608).\nIn the case of single-call LZMA decompression, it requires 64KB buffer at\nmaximum to store the compressed squashfs block.\nFinally I decided to implement the parallel single-call LZMA decompression.\nThe parallel decompression is also applied to ZLIB decompression. It\nalso requires more memory than multi-call ZLIB decompression, but less than\nmulti-call LZMA decompression. And it can take an advantage of speed\nperformance, especially on SMP machine.\n\n\no Backporting\nA user, dystryk, had backported this patch (previous version) to\nlinux-2.6.17. His URL is,\nhttps://sourceforge.net/project/showfiles.php?group_id=116780&package_id=222970\n\n\nEnjoy your smaller squashfs.\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/sqlzma1-449.patch",
    "content": "Index: lzma449/C/Compress/Lzma/kmod.mk\n===================================================================\nRCS file: lzma449/C/Compress/Lzma/kmod.mk\ndiff -N lzma449/C/Compress/Lzma/kmod.mk\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma449/C/Compress/Lzma/kmod.mk\t5 Nov 2007 05:43:35 -0000\t1.1\n@@ -0,0 +1,40 @@\n+\n+# Copyright (C) 2006-2007 Junjiro Okajima\n+# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n+#\n+# LICENSE follows the described one in lzma.txt.\n+\n+# $Id: kmod.mk,v 1.1 2007-11-05 05:43:35 jro Exp $\n+\n+ifndef Sqlzma\n+$(error Sqlzma is not defined)\n+endif\n+ifndef KDir\n+$(error KDir is not defined)\n+endif\n+\n+#include makefile.gcc\n+\n+Kmod = kmod\n+EXTRA_CFLAGS += -Wall -Werror -I${CURDIR} -I${Sqlzma}\n+# -D_LZMA_PROB32\n+EXTRA_CFLAGS += $(shell ${CPP} ${CFLAGS} -P testflags.c)\n+\n+all: ${Kmod}/uncomp.c\n+\t${MAKE} EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\" M=${CURDIR}/${Kmod} \\\n+\t\t-C ${KDir} C=0 V=0 modules\n+\n+${Kmod}/uncomp.c: uncomp.c\n+\tln $< $@\n+\n+clean: clean_kmod\n+clean_kmod:\n+\t${MAKE} -C ${KDir} M=${CURDIR}/${Kmod} V=0 clean\n+\t${RM} ${Kmod}/*~\n+\t-@test -e ${Kmod}/uncomp.c && \\\n+\t\tdiff -q ${Kmod}/uncomp.c uncomp.c > /dev/null && \\\n+\t\tfind ${Kmod}/uncomp.c -links +1 | xargs -r ${RM}\n+\n+# Local variables: ;\n+# compile-command: (concat \"make Sqlzma=../../../../.. KDir=/lib/modules/`uname -r`/build -f \" (file-name-nondirectory (buffer-file-name)));\n+# End: ;\nIndex: lzma449/C/Compress/Lzma/sqlzma.mk\n===================================================================\nRCS file: lzma449/C/Compress/Lzma/sqlzma.mk\ndiff -N lzma449/C/Compress/Lzma/sqlzma.mk\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma449/C/Compress/Lzma/sqlzma.mk\t5 Nov 2007 05:43:36 -0000\t1.1\n@@ -0,0 +1,47 @@\n+\n+# Copyright (C) 2006-2007 Junjiro Okajima\n+# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n+#\n+# LICENSE follows the described one in lzma.txt.\n+\n+# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n+\n+ifndef Sqlzma\n+$(error Sqlzma is not defined)\n+endif\n+\n+#include makefile.gcc\n+CFLAGS = -c -O2 -Wall -pedantic -D _LZMA_PROB32\n+\n+ifdef KDir\n+include kmod.mk\n+endif\n+\n+ifdef UseDebugFlags\n+DebugFlags = -O0 -g -UNDEBUG\n+endif\n+CFLAGS += -DNDEBUG ${DebugFlags}\n+Tgt = libunlzma.a libunlzma_r.a\n+\n+all: ${Tgt}\n+\n+%_r.c: %.c\n+\tln $< $@\n+# -pthread\n+%_r.o: CFLAGS += -D_REENTRANT -include pthread.h\n+\n+uncomp.o uncomp_r.o: CFLAGS += -I${Sqlzma}\n+uncomp.o: uncomp.c ${Sqlzma}/sqlzma.h\n+\n+libunlzma.a: uncomp.o LzmaDecode.o\n+\t${AR} cr $@ $^\n+libunlzma_r.a: uncomp_r.o LzmaDecode_r.o\n+\t${AR} cr $@ $^\n+\n+clean: clean_sqlzma\n+clean_sqlzma:\n+\t$(RM) ${Tgt} uncomp.o uncomp_r.o LzmaDecode_r.o LzmaDecode.o  *~\n+\n+# Local variables: ;\n+# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n+# End: ;\nIndex: lzma449/C/Compress/Lzma/testflags.c\n===================================================================\nRCS file: lzma449/C/Compress/Lzma/testflags.c\ndiff -N lzma449/C/Compress/Lzma/testflags.c\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma449/C/Compress/Lzma/testflags.c\t5 Nov 2007 05:43:36 -0000\t1.1\n@@ -0,0 +1,5 @@\n+#ifdef _LZMA_PROB32\n+-D_LZMA_PROB32\n+#else\n+-U_LZMA_PROB32\n+#endif\nIndex: lzma449/C/Compress/Lzma/uncomp.c\n===================================================================\nRCS file: lzma449/C/Compress/Lzma/uncomp.c\ndiff -N lzma449/C/Compress/Lzma/uncomp.c\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma449/C/Compress/Lzma/uncomp.c\t12 Mar 2008 16:58:34 -0000\t1.7\n@@ -0,0 +1,223 @@\n+/*\n+ * Copyright (C) 2006-2008 Junjiro Okajima\n+ * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n+ *\n+ * LICENSE follows the described one in lzma.txt.\n+ */\n+\n+/* $Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $ */\n+\n+/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */\n+\n+#ifndef __KERNEL__\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <errno.h>\n+#include <assert.h>\n+#include <pthread.h>\n+#define unlikely(x)\t\t__builtin_expect(!!(x), 0)\n+#define BUG_ON(x)\t\tassert(!(x))\n+/* sqlzma buffers are always larger than a page. true? */\n+#define kmalloc(sz,gfp)\t\tmalloc(sz)\n+#define kfree(p)\t\tfree(p)\n+#define zlib_inflate(s, f)\tinflate(s, f)\n+#define zlib_inflateInit(s)\tinflateInit(s)\n+#define zlib_inflateReset(s)\tinflateReset(s)\n+#define zlib_inflateEnd(s)\tinflateEnd(s)\n+#else\n+#include <linux/init.h>\n+#include <linux/module.h>\n+#include <linux/kernel.h>\n+#include <linux/vmalloc.h>\n+#ifndef WARN_ON_ONCE\n+#define WARN_ON_ONCE(b)\tWARN_ON(b)\n+#endif\n+#endif /* __KERNEL__ */\n+\n+#include \"sqlzma.h\"\n+#include \"LzmaDecode.h\"\n+\n+static int LzmaUncompress(struct sqlzma_un *un)\n+{\n+\tint err, i, ret;\n+\tSizeT outSize, inProcessed, outProcessed, srclen;\n+\t/* it's about 24-80 bytes structure, if int is 32-bit */\n+\tCLzmaDecoderState state;\n+\tunsigned char *dst, *src, a[8];\n+\tstruct sized_buf *sbuf;\n+\n+\t/* Decode LZMA properties and allocate memory */\n+\terr = -EINVAL;\n+\tsrc = (void *)un->un_cmbuf;\n+\tret = LzmaDecodeProperties(&state.Properties, src,\n+\t\t\t\t   LZMA_PROPERTIES_SIZE);\n+\tsrc += LZMA_PROPERTIES_SIZE;\n+\tif (unlikely(ret != LZMA_RESULT_OK))\n+\t\tgoto out;\n+\ti = LzmaGetNumProbs(&state.Properties);\n+\tif (unlikely(i <= 0))\n+\t\ti = 1;\n+\ti *= sizeof(CProb);\n+\tsbuf = un->un_a + SQUN_PROB;\n+\tif (unlikely(sbuf->sz < i)) {\n+\t\tif (sbuf->buf && sbuf->buf != un->un_prob)\n+\t\t\tkfree(sbuf->buf);\n+#ifdef __KERNEL__\n+\t\tprintk(\"%s:%d: %d --> %d\\n\", __func__, __LINE__, sbuf->sz, i);\n+#else\n+\t\tprintf(\"%d --> %d\\n\", sbuf->sz, i);\n+#endif\n+\t\terr = -ENOMEM;\n+\t\tsbuf->sz = 0;\n+\t\tsbuf->buf = kmalloc(i, GFP_ATOMIC);\n+\t\tif (unlikely(!sbuf->buf))\n+\t\t\tgoto out;\n+\t\tsbuf->sz = i;\n+\t}\n+\tstate.Probs = (void *)sbuf->buf;\n+\n+\t/* Read uncompressed size */\n+\tmemcpy(a, src, sizeof(a));\n+\tsrc += sizeof(a);\n+\toutSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);\n+\n+\terr = -EINVAL;\n+\tdst = un->un_resbuf;\n+\tif (unlikely(!dst || outSize > un->un_reslen))\n+\t\tgoto out;\n+\tun->un_reslen = outSize;\n+\tsrclen = un->un_cmlen - (src - un->un_cmbuf);\n+\n+\t/* Decompress */\n+\terr = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,\n+\t\t\t &outProcessed);\n+\tif (unlikely(err))\n+\t\terr = -EINVAL;\n+\n+ out:\n+#ifndef __KERNEL__\n+\tif (err)\n+\t\tfprintf(stderr, \"err %d\\n\", err);\n+#endif\n+\treturn err;\n+}\n+\n+int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n+\t      struct sized_buf *dst)\n+{\n+\tint err, by_lzma = 1;\n+\tif (un->un_lzma && is_lzma(*src->buf)) {\n+\t\tun->un_cmbuf = src->buf;\n+\t\tun->un_cmlen = src->sz;\n+\t\tun->un_resbuf = dst->buf;\n+\t\tun->un_reslen = dst->sz;\n+\n+\t\t/* this library is thread-safe */\n+\t\terr = LzmaUncompress(un);\n+\t\tgoto out;\n+\t}\n+\n+\tby_lzma = 0;\n+\terr = zlib_inflateReset(&un->un_stream);\n+\tif (unlikely(err != Z_OK))\n+\t\tgoto out;\n+\tun->un_stream.next_in = src->buf;\n+\tun->un_stream.avail_in = src->sz;\n+\tun->un_stream.next_out = dst->buf;\n+\tun->un_stream.avail_out = dst->sz;\n+\terr = zlib_inflate(&un->un_stream, Z_FINISH);\n+\tif (err == Z_STREAM_END)\n+\t\terr = 0;\n+\n+ out:\n+\tif (unlikely(err)) {\n+#ifdef __KERNEL__\n+\t\tWARN_ON_ONCE(1);\n+#else\n+\t\tchar a[64] = \"ZLIB \";\n+\t\tif (by_lzma) {\n+\t\t\tstrcpy(a, \"LZMA \");\n+#ifdef _REENTRANT\n+\t\t\tstrerror_r(err, a + 5, sizeof(a) - 5);\n+#else\n+\t\t\tstrncat(a, strerror(err), sizeof(a) - 5);\n+#endif\n+\t\t} else\n+\t\t\tstrncat(a, zError(err), sizeof(a) - 5);\n+\t\tfprintf(stderr, \"%s: %.*s\\n\", __func__, sizeof(a), a);\n+#endif\n+\t}\n+\treturn err;\n+}\n+\n+int sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)\n+{\n+\tint err;\n+\n+\terr = -ENOMEM;\n+\tun->un_lzma = do_lzma;\n+\tmemset(un->un_a, 0, sizeof(un->un_a));\n+\tun->un_a[SQUN_PROB].buf = un->un_prob;\n+\tun->un_a[SQUN_PROB].sz = sizeof(un->un_prob);\n+\tif (res_sz) {\n+\t\tun->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);\n+\t\tif (unlikely(!un->un_a[SQUN_RESULT].buf))\n+\t\t\treturn err;\n+\t\tun->un_a[SQUN_RESULT].sz = res_sz;\n+\t}\n+\n+\tun->un_stream.next_in = NULL;\n+\tun->un_stream.avail_in = 0;\n+#ifdef __KERNEL__\n+\tun->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(),\n+\t\t\t\t\t  GFP_KERNEL);\n+\tif (unlikely(!un->un_stream.workspace))\n+\t\treturn err;\n+#else\n+\tun->un_stream.opaque = NULL;\n+\tun->un_stream.zalloc = Z_NULL;\n+\tun->un_stream.zfree = Z_NULL;\n+#endif\n+\terr = zlib_inflateInit(&un->un_stream);\n+\tif (unlikely(err == Z_MEM_ERROR))\n+\t\treturn -ENOMEM;\n+\tBUG_ON(err);\n+\treturn err;\n+}\n+\n+void sqlzma_fin(struct sqlzma_un *un)\n+{\n+\tint i;\n+\tfor (i = 0; i < SQUN_LAST; i++)\n+\t\tif (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)\n+\t\t\tkfree(un->un_a[i].buf);\n+\tBUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);\n+}\n+\n+#ifdef __KERNEL__\n+EXPORT_SYMBOL(sqlzma_un);\n+EXPORT_SYMBOL(sqlzma_init);\n+EXPORT_SYMBOL(sqlzma_fin);\n+\n+#if 0\n+static int __init sqlzma_init(void)\n+{\n+\treturn 0;\n+}\n+\n+static void __exit sqlzma_exit(void)\n+{\n+}\n+\n+module_init(sqlzma_init);\n+module_exit(sqlzma_exit);\n+#endif\n+\n+MODULE_LICENSE(\"GPL\");\n+MODULE_AUTHOR(\"Junjiro Okajima <sfjro at users dot sf dot net>\");\n+MODULE_VERSION(\"$Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $\");\n+MODULE_DESCRIPTION(\"LZMA uncompress for squashfs. \"\n+\t\t   \"Some functions for squashfs to support LZMA and \"\n+\t\t   \"a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n+#endif\nIndex: lzma449/C/Compress/Lzma/kmod/Makefile\n===================================================================\nRCS file: lzma449/C/Compress/Lzma/kmod/Makefile\ndiff -N lzma449/C/Compress/Lzma/kmod/Makefile\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma449/C/Compress/Lzma/kmod/Makefile\t12 Mar 2008 01:49:39 -0000\t1.3\n@@ -0,0 +1,16 @@\n+\n+# Copyright (C) 2006-2008 Junjiro Okajima\n+# Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n+#\n+# LICENSE follows the described one in lzma.txt.\n+\n+# $Id: Makefile,v 1.3 2008-03-12 01:49:39 jro Exp $\n+\n+# # the environment variables are not inherited since 2.6.23\n+# ifdef SQLZMA_EXTRA_CFLAGS\n+# EXTRA_CFLAGS += ${SQLZMA_EXTRA_CFLAGS}\n+# endif\n+\n+obj-m += unlzma.o sqlzma.o\n+unlzma-y := module.o\n+sqlzma-y := uncomp.o\nIndex: lzma449/C/Compress/Lzma/kmod/module.c\n===================================================================\nRCS file: lzma449/C/Compress/Lzma/kmod/module.c\ndiff -N lzma449/C/Compress/Lzma/kmod/module.c\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma449/C/Compress/Lzma/kmod/module.c\t5 Nov 2007 05:43:36 -0000\t1.1\n@@ -0,0 +1,36 @@\n+\n+/*\n+ * Copyright (C) 2006-2007 Junjiro Okajima\n+ * Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n+ *\n+ * LICENSE follows the described one in lzma.txt.\n+ */\n+\n+/* $Id: module.c,v 1.1 2007-11-05 05:43:36 jro Exp $ */\n+\n+#include <linux/init.h>\n+#include <linux/module.h>\n+\n+#include \"../LzmaDecode.c\"\n+\n+EXPORT_SYMBOL(LzmaDecodeProperties);\n+EXPORT_SYMBOL(LzmaDecode);\n+\n+#if 0\n+static int __init unlzma_init(void)\n+{\n+\treturn 0;\n+}\n+\n+static void __exit unlzma_exit(void)\n+{\n+}\n+\n+module_init(unlzma_init);\n+module_exit(unlzma_exit);\n+#endif\n+\n+MODULE_LICENSE(\"GPL\");\n+MODULE_VERSION(\"$Id: module.c,v 1.1 2007-11-05 05:43:36 jro Exp $\");\n+MODULE_DESCRIPTION(\"LZMA uncompress. \"\n+\t\t   \"A tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\nIndex: lzma449/CPP/7zip/Compress/LZMA_Alone/comp.cc\n===================================================================\nRCS file: lzma449/CPP/7zip/Compress/LZMA_Alone/comp.cc\ndiff -N lzma449/CPP/7zip/Compress/LZMA_Alone/comp.cc\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma449/CPP/7zip/Compress/LZMA_Alone/comp.cc\t13 Nov 2007 13:27:23 -0000\t1.3\n@@ -0,0 +1,260 @@\n+/*\n+ * Copyright (C) 2006-2007 Junjiro Okajima\n+ * Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n+ *\n+ * LICENSE follows the described one in lzma.txt.\n+ */\n+\n+/* $Id: comp.cc,v 1.3 2007-11-13 13:27:23 jro Exp $ */\n+\n+// extract some parts from lzma443/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp\n+\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <assert.h>\n+#include <errno.h>\n+\n+#include \"StdAfx.h\"\n+#include \"../../../Common/MyInitGuid.h\"\n+//#include \"../../../Common/MyWindows.h\"\n+#include \"../../../Common/StringConvert.h\"\n+//#include \"../../../Common/StringToInt.h\"\n+//#include \"../../Common/StreamUtils.h\"\n+#include \"../LZMA/LZMAEncoder.h\"\n+\n+#include <pthread.h>\n+#include <zlib.h>\n+#include \"sqlzma.h\"\n+\n+//////////////////////////////////////////////////////////////////////\n+\n+class CMemoryStream {\n+protected:\n+\tBytef *m_data;\n+\tUInt64 m_limit;\n+\tUInt64 m_pos;\n+\n+public:\n+\tCMemoryStream(Bytef *data, UInt64 size)\n+\t\t: m_data(data), m_limit(size), m_pos(0) {}\n+\n+\tvirtual ~CMemoryStream() {}\n+};\n+\n+class CInMemoryStream : public CMemoryStream, public IInStream,\n+\t\t\tpublic CMyUnknownImp {\n+//protected:\n+\tCMyComPtr<ISequentialInStream> m_stream;\n+\n+public:\n+\tMY_UNKNOWN_IMP1(IInStream);\n+\n+\tCInMemoryStream(Bytef *data, UInt64 size)\n+\t\t: CMemoryStream(data, size), m_stream(this) {}\n+\n+\tvirtual ~CInMemoryStream() {}\n+\n+\tSTDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\n+\t{\n+\t\tUInt64 room = m_limit - m_pos;\n+\t\tif (size > room)\n+\t\t\tsize = room;\n+\t\tif (size) {\n+\t\t\tmemcpy(data, m_data + m_pos, size);\n+\t\t\tm_pos += size;\n+\t\t}\n+\t\tif (processedSize)\n+\t\t\t*processedSize = size;\n+\t\treturn S_OK;\n+\t}\n+\n+\t// disabled all\n+\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n+\t\tassert(0);\n+\t\treturn E_NOTIMPL;\n+\t}\n+};\n+\n+class COutMemoryStream : public CMemoryStream, public IOutStream,\n+\t\t\t public CMyUnknownImp {\n+//protected:\n+\tCMyComPtr<ISequentialOutStream> m_stream;\n+\n+public:\n+\tMY_UNKNOWN_IMP1(IOutStream);\n+\n+\tCOutMemoryStream(Bytef *data, UInt64 size)\n+\t\t: CMemoryStream(data, size), m_stream(this) {}\n+\n+\tvirtual ~COutMemoryStream() {}\n+\n+\tUInt32 GetSize() {return m_pos;}\n+\n+\tSTDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) {\n+\t\tif (m_pos + size > m_limit)\n+\t\t\treturn -ENOSPC;\n+\t\tmemcpy(m_data + m_pos, data, size);\n+\t\tm_pos += size;\n+\t\tif (processedSize)\n+\t\t\t*processedSize = size;\n+\t\treturn S_OK;\n+\t}\n+\n+\t// disabled all\n+\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n+\t\tassert(0);\n+\t\treturn E_NOTIMPL;\n+\t}\n+\tSTDMETHOD(SetSize)(Int64 newSize) {\n+\t\tassert(0);\n+\t\treturn E_NOTIMPL;\n+\t}\n+};\n+\n+//////////////////////////////////////////////////////////////////////\n+\n+static int\n+LzmaCompress(Bytef *next_in, uInt avail_in, Bytef *next_out, uInt avail_out,\n+\t     struct sqlzma_opts *opts, uLong *total_out)\n+{\n+\tint err;\n+\tHRESULT res;\n+\tconst Byte a[] = {\n+\t\tavail_in, avail_in >> 8, avail_in >> 16, avail_in >> 24,\n+\t\t0, 0, 0, 0\n+\t};\n+\n+\tNCompress::NLZMA::CEncoder encoderSpec;\n+\tCMyComPtr<ICompressCoder> encoder = &encoderSpec;\n+\tencoder->AddRef();\n+\tCInMemoryStream inStreamSpec(next_in, avail_in);\n+\tCMyComPtr<ISequentialInStream> inStream = &inStreamSpec;\n+\tinStream->AddRef();\n+\tCOutMemoryStream outStreamSpec(next_out, avail_out);\n+\tCMyComPtr<ISequentialOutStream> outStream = &outStreamSpec;\n+\toutStream->AddRef();\n+\n+\t// these values are dpending upon is_lzma() macro in sqlzma.h\n+\tconst UInt32 dictionary = opts->dicsize;\n+\t//fprintf(stderr, \"dic %u\\n\", dictionary);\n+\tconst UString mf = L\"BT4\";\n+\tconst UInt32 posStateBits = 2;\n+\tconst UInt32 litContextBits = 3; // for normal files\n+\t// UInt32 litContextBits = 0; // for 32-bit data\n+\tconst UInt32 litPosBits = 0;\n+\t// UInt32 litPosBits = 2; // for 32-bit data\n+\t//const UInt32 algorithm = 2;\n+\tconst UInt32 algorithm = 1;\n+\tconst UInt32 numFastBytes = 128;\n+\tconst UInt32 matchFinderCycles = 16 + numFastBytes / 2;\n+\t//const bool matchFinderCyclesDefined = false;\n+\tconst PROPID propIDs[] = {\n+\t\tNCoderPropID::kDictionarySize,\n+\t\tNCoderPropID::kPosStateBits,\n+\t\tNCoderPropID::kLitContextBits,\n+\t\tNCoderPropID::kLitPosBits,\n+\t\tNCoderPropID::kAlgorithm,\n+\t\tNCoderPropID::kNumFastBytes,\n+\t\tNCoderPropID::kMatchFinder,\n+\t\tNCoderPropID::kEndMarker,\n+\t\tNCoderPropID::kNumThreads,\n+\t\tNCoderPropID::kMatchFinderCycles\n+\t};\n+\tconst int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\n+\tPROPVARIANT properties[kNumPropsMax];\n+\tfor (int p = 0; p < 6; p++)\n+\t\tproperties[p].vt = VT_UI4;\n+\tproperties[0].ulVal = UInt32(dictionary);\n+\tproperties[1].ulVal = UInt32(posStateBits);\n+\tproperties[2].ulVal = UInt32(litContextBits);\n+\tproperties[3].ulVal = UInt32(litPosBits);\n+\tproperties[4].ulVal = UInt32(algorithm);\n+\tproperties[5].ulVal = UInt32(numFastBytes);\n+\n+\tproperties[6].vt = VT_BSTR;\n+\tproperties[6].bstrVal = (BSTR)(const wchar_t *)mf;\n+\tproperties[7].vt = VT_BOOL;\n+\tproperties[7].boolVal = VARIANT_FALSE;\t// EOS\n+\tproperties[8].vt = VT_UI4;\n+\tproperties[8].ulVal = 1; // numThreads\n+\tproperties[9].vt = VT_UI4;\n+\tproperties[9].ulVal = UInt32(matchFinderCycles);\n+\n+\terr = -EINVAL;\n+\tres = encoderSpec.SetCoderProperties(propIDs, properties,\n+\t\t\t\t\t     kNumPropsMax - 1);\n+\tif (res)\n+\t\tgoto out;\n+\tres = encoderSpec.WriteCoderProperties(outStream);\n+\tif (res)\n+\t\tgoto out;\n+\n+\tUInt32 r;\n+\tres = outStream->Write(a, sizeof(a), &r);\n+\tif (res || r != sizeof(a))\n+\t\tgoto out;\n+\n+\terr = encoder->Code(inStream, outStream, 0, /*broken*/0, 0);\n+\tif (err)\n+\t\tgoto out;\n+\t*total_out = outStreamSpec.GetSize();\n+\n+ out:\n+\treturn err;\n+}\n+\n+//////////////////////////////////////////////////////////////////////\n+\n+#define Failure(p) do { \\\n+\tfprintf(stderr, \"%s:%d: please report to jro \" \\\n+\t\t\"{%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x}\\n\", \\\n+\t\t__func__, __LINE__, \\\n+\t\tp[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); \\\n+\tabort(); \\\n+} while(0)\n+\n+extern \"C\" int\n+sqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in, uInt\n+\t  avail_in, Bytef *next_out, uInt avail_out)\n+{\n+\tint err;\n+\tBytef *p = next_out;\n+\tuInt l = avail_out;\n+\n+\tstream->next_in = next_in;\n+\tstream->avail_in = avail_in;\n+\tstream->next_out = p;\n+\tstream->avail_out = l;\n+\terr = deflate(stream, Z_FINISH);\n+\tif (err != Z_STREAM_END && err != Z_OK)\n+\t\tgoto out_err;\n+\tif (avail_in < stream->total_out)\n+\t\treturn err;\n+\tif (is_lzma(*p))\n+\t\tFailure(p);\n+\n+\tif (opts->try_lzma) {\n+\t\tunsigned char a[stream->total_out];\n+\t\tuLong processed;\n+\n+\t\tmemcpy(a, p, stream->total_out);\n+\n+\t\t// malloc family in glibc and stdc++ seems to be thread-safe\n+\t\terr = LzmaCompress(next_in, avail_in, p, l, opts, &processed);\n+\t\tif (!err && processed <= stream->total_out) {\n+\t\t\tif (!is_lzma(*next_out))\n+\t\t\t\tFailure(next_out);\n+\t\t\tstream->total_out = processed;\n+\t\t\terr = Z_STREAM_END;\n+\t\t} else {\n+\t\t\t//puts(\"by zlib\");\n+\t\t\tmemcpy(p, a, stream->total_out);\n+\t\t\terr = Z_STREAM_END;\n+\t\t}\n+\t}\n+\treturn err;\n+\n+ out_err:\n+\tfprintf(stderr, \"%s: ZLIB err %s\\n\", __func__, zError(err));\n+\treturn err;\n+}\nIndex: lzma449/CPP/7zip/Compress/LZMA_Alone/sqlzma.mk\n===================================================================\nRCS file: lzma449/CPP/7zip/Compress/LZMA_Alone/sqlzma.mk\ndiff -N lzma449/CPP/7zip/Compress/LZMA_Alone/sqlzma.mk\n--- /dev/null\t1 Jan 1970 00:00:00 -0000\n+++ lzma449/CPP/7zip/Compress/LZMA_Alone/sqlzma.mk\t5 Nov 2007 05:43:36 -0000\t1.1\n@@ -0,0 +1,57 @@\n+\n+# Copyright (C) 2006-2007 Junjiro Okajima\n+# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n+#\n+# LICENSE follows the described one in lzma.txt.\n+\n+# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n+\n+ifndef Sqlzma\n+$(error Sqlzma is not defined)\n+endif\n+\n+include makefile.gcc\n+\n+ifdef UseDebugFlags\n+DebugFlags = -Wall -O0 -g -UNDEBUG\n+endif\n+# -pthread\n+CXXFLAGS = ${CFLAGS} -D_REENTRANT -include pthread.h -DNDEBUG ${DebugFlags}\n+Tgt = liblzma_r.a\n+\n+all: ${Tgt}\n+\n+RObjs = LZMAEncoder_r.o Alloc_r.o StreamUtils_r.o MatchFinder_r.o \\\n+\tRangeCoderBit_r.o OutBuffer_r.o 7zCrc_r.o\n+\n+%_r.cc: ../LZMA/%.cpp\n+\tln $< $@\n+%_r.c: ../../../../C/%.c\n+\tln $< $@\n+%_r.c: ../../../../C/Compress/Lz/%.c\n+\tln $< $@\n+%_r.cc: ../../Common/%.cpp\n+\tln $< $@\n+%_r.cc: ../RangeCoder/%.cpp\n+\tln $< $@\n+LZMAEncoder_r.o: CXXFLAGS += -I../LZMA\n+Alloc_r.o: CFLAGS += -I../../../../C\n+StreamUtils_r.o: CXXFLAGS += -I../../Common\n+MatchFinder_r.o: CFLAGS += -I../../../../C/Compress/Lz\n+RangeCoderBit_r.o: CXXFLAGS += -I../RangeCoder\n+OutBuffer_r.o: CXXFLAGS += -I../../Common\n+7zCrc_r.o: CFLAGS += -I../../../../C\n+\n+comp.o: CXXFLAGS += -I${Sqlzma}\n+comp.o: comp.cc ${Sqlzma}/sqlzma.h\n+\n+liblzma_r.a: ${RObjs} comp.o\n+\t${AR} cr $@ $^\n+\n+clean: clean_sqlzma\n+clean_sqlzma:\n+\t$(RM) comp.o *_r.o ${Tgt} *~\n+\n+# Local variables: ;\n+# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n+# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/sqlzma2k-3.3.patch",
    "content": "Index: linux-2.6.24.3/fs/squashfs/Makefile\n===================================================================\nRCS file: /proj/sqlzma/repository/linux-2.6.24.3/fs/squashfs/Makefile,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- linux-2.6.24.3/fs/squashfs/Makefile\t12 Mar 2008 14:18:02 -0000\t1.1\n+++ linux-2.6.24.3/fs/squashfs/Makefile\t12 Mar 2008 14:49:49 -0000\t1.2\n@@ -2,6 +2,11 @@\n # Makefile for the linux squashfs routines.\n #\n \n+# the environment variables are not inherited since 2.6.23\n+ifdef SQLZMA_EXTRA_CFLAGS\n+EXTRA_CFLAGS += ${SQLZMA_EXTRA_CFLAGS}\n+endif\n+\n obj-$(CONFIG_SQUASHFS) += squashfs.o\n squashfs-y += inode.o\n squashfs-y += squashfs2_0.o\nIndex: linux-2.6.24.3/fs/squashfs/inode.c\n===================================================================\nRCS file: /proj/sqlzma/repository/linux-2.6.24.3/fs/squashfs/inode.c,v\nretrieving revision 1.1\nretrieving revision 1.8\ndiff -u -p -r1.1 -r1.8\n--- linux-2.6.24.3/fs/squashfs/inode.c\t12 Mar 2008 14:18:02 -0000\t1.1\n+++ linux-2.6.24.3/fs/squashfs/inode.c\t14 Mar 2008 13:53:27 -0000\t1.8\n@@ -34,8 +34,30 @@\n #include <linux/exportfs.h>\n \n #include \"squashfs.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n-int squashfs_cached_blks;\n+#undef KeepPreemptive\n+#if defined(CONFIG_PREEMPT) && !defined(UnsquashNoPreempt)\n+#define KeepPreemptive\n+#endif\n+\n+struct sqlzma {\n+#ifdef KeepPreemptive\n+\tstruct mutex mtx;\n+#endif\n+\tunsigned char read_data[SQUASHFS_FILE_MAX_SIZE];\n+\tstruct sqlzma_un un;\n+};\n+static DEFINE_PER_CPU(struct sqlzma *, sqlzma);\n+\n+#define dpri(fmt, args...) /* printk(\"%s:%d: \" fmt, __func__, __LINE__, ##args) */\n+#define dpri_un(un)\tdpri(\"un{%d, {%d %p}, {%d %p}, {%d %p}}\\n\", \\\n+\t\t\t     (un)->un_lzma, (un)->un_a[0].sz, (un)->un_a[0].buf, \\\n+\t\t\t     (un)->un_a[1].sz, (un)->un_a[1].buf, \\\n+\t\t\t     (un)->un_a[2].sz, (un)->un_a[2].buf)\n+\n+static int squashfs_cached_blks;\n \n static void vfs_read_inode(struct inode *i);\n static struct dentry *squashfs_get_parent(struct dentry *child);\n@@ -243,35 +265,42 @@ SQSH_EXTERN unsigned int squashfs_read_d\n \t}\n \n \tif (compressed) {\n-\t\tint zlib_err = 0;\n+\t\tint zlib_err = Z_STREAM_END;\n+\t\tint start;\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[2];\n+\t\tstruct sqlzma *percpu;\n+\t\tunsigned char *p;\n \n \t\t/*\n \t \t* uncompress block\n \t \t*/\n \n-\t\tmutex_lock(&msblk->read_data_mutex);\n-\n-\t\tmsblk->stream.next_out = buffer;\n-\t\tmsblk->stream.avail_out = srclength;\n-\n-\t\tfor (bytes = 0; k < b; k++) {\n-\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\t\t/* mutex_lock(&msblk->read_data_mutex); */\n \n+\t\tstart = k;\n+\t\tfor (; k < b; k++) {\n \t\t\twait_on_buffer(bh[k]);\n \t\t\tif (!buffer_uptodate(bh[k]))\n \t\t\t\tgoto release_mutex;\n+\t\t}\n \n-\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n-\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\t\t/* it disables preemption */\n+\t\tpercpu = get_cpu_var(sqlzma);\n+#ifdef KeepPreemptive\n+\t\tput_cpu_var(sqlzma);\n+\t\tmutex_lock(&percpu->mtx);\n+#endif\n+\t\tp = percpu->read_data;\n+\t\tk = start;\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n \n \t\t\tif (k == 0) {\n-\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n-\t\t\t\tif (zlib_err != Z_OK) {\n-\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n-\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n-\t\t\t\t\tgoto release_mutex;\n-\t\t\t\t}\n-\n+\t\t\t\t/*\n+\t\t\t\t * keep this block structture to simplify the\n+\t\t\t\t * diff.\n+\t\t\t\t */\n \t\t\t\tif (avail_bytes == 0) {\n \t\t\t\t\toffset = 0;\n \t\t\t\t\tbrelse(bh[k]);\n@@ -279,30 +308,38 @@ SQSH_EXTERN unsigned int squashfs_read_d\n \t\t\t\t}\n \t\t\t}\n \n-\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n-\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n-\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n-\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n-\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n-\t\t\t\tgoto release_mutex;\n-\t\t\t}\n+\t\t\tmemcpy(p, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tp += avail_bytes;\n+#if 0\n+\t\t\tBUG_ON(percpu->read_data + sizeof(percpu->read_data)\n+\t\t\t       < p);\n+#endif\n \n \t\t\tbytes += avail_bytes;\n \t\t\toffset = 0;\n \t\t\tbrelse(bh[k]);\n \t\t}\n \n-\t\tif (zlib_err != Z_STREAM_END)\n-\t\t\tgoto release_mutex;\n-\n-\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n-\t\tif (zlib_err != Z_OK) {\n-\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n-\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\tsbuf[Src].buf = percpu->read_data;\n+\t\tsbuf[Src].sz = bytes;\n+\t\tsbuf[Dst].buf = buffer;\n+\t\tsbuf[Dst].sz = srclength;\n+\t\tdpri_un(&percpu->un);\n+\t\tdpri(\"src %d %p, dst %d %p\\n\", sbuf[Src].sz, sbuf[Src].buf,\n+\t\t     sbuf[Dst].sz, sbuf[Dst].buf);\n+\t\tzlib_err = sqlzma_un(&percpu->un, sbuf + Src, sbuf + Dst);\n+\t\tbytes = percpu->un.un_reslen;\n+\n+#ifdef KeepPreemptive\n+\t\tmutex_unlock(&percpu->mtx);\n+#else\n+\t\tput_cpu_var(sqlzma);\n+#endif\n+\t\tif (unlikely(zlib_err)) {\n+\t\t\tdpri(\"zlib_err %d\\n\", zlib_err);\n \t\t\tgoto release_mutex;\n \t\t}\n-\t\tbytes = msblk->stream.total_out;\n-\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t\t/* mutex_unlock(&msblk->read_data_mutex); */\n \t} else {\n \t\tint i;\n \n@@ -330,7 +367,7 @@ SQSH_EXTERN unsigned int squashfs_read_d\n \treturn bytes;\n \n release_mutex:\n-\tmutex_unlock(&msblk->read_data_mutex);\n+\t/* mutex_unlock(&msblk->read_data_mutex); */\n \n block_release:\n \tfor (; k < b; k++)\n@@ -1089,12 +1126,13 @@ static int squashfs_fill_super(struct su\n {\n \tstruct squashfs_sb_info *msblk;\n \tstruct squashfs_super_block *sblk;\n-\tint i;\n+\tint i, err;\n \tchar b[BDEVNAME_SIZE];\n \tstruct inode *root;\n \n \tTRACE(\"Entered squashfs_fill_superblock\\n\");\n \n+\terr = -ENOMEM;\n \ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n \tif (s->s_fs_info == NULL) {\n \t\tERROR(\"Failed to allocate superblock\\n\");\n@@ -1102,17 +1140,12 @@ static int squashfs_fill_super(struct su\n \t}\n \tmsblk = s->s_fs_info;\n \n-\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n-\tif (msblk->stream.workspace == NULL) {\n-\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n-\t\tgoto failure;\n-\t}\n \tsblk = &msblk->sblk;\n \t\n \tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n \tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n \n-\tmutex_init(&msblk->read_data_mutex);\n+\t/* mutex_init(&msblk->read_data_mutex); */\n \tmutex_init(&msblk->read_page_mutex);\n \tmutex_init(&msblk->block_cache_mutex);\n \tmutex_init(&msblk->fragment_mutex);\n@@ -1124,6 +1157,7 @@ static int squashfs_fill_super(struct su\n \t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n  \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n  \t * first set sblk->bytes_used to a useful value */\n+\terr = -EINVAL;\n \tsblk->bytes_used = sizeof(struct squashfs_super_block);\n \tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n \t\t\t\t\tsizeof(struct squashfs_super_block) |\n@@ -1133,21 +1167,36 @@ static int squashfs_fill_super(struct su\n \t}\n \n \t/* Check it is a SQUASHFS superblock */\n-\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n-\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n-\t\t\tstruct squashfs_super_block ssblk;\n-\n-\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n-\t\t\t\tbdevname(s->s_bdev, b));\n-\n-\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n-\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n-\t\t\tmsblk->swap = 1;\n-\t\t} else  {\n-\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n-\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n-\t\t\tgoto failed_mount;\n-\t\t}\n+\ts->s_magic = sblk->s_magic;\n+\tmsblk->swap = 0;\n+\tdpri(\"magic 0x%x\\n\", sblk->s_magic);\n+\tswitch (sblk->s_magic) {\n+\t\tstruct squashfs_super_block ssblk;\n+\n+\tcase SQUASHFS_MAGIC_SWAP:\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n+\t\tWARNING(\"Mounting a different endian SQUASHFS \"\n+\t\t\t\"filesystem on %s\\n\", bdevname(s->s_bdev, b));\n+\n+\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\tmsblk->swap = 1;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC:\n+\tcase SQUASHFS_MAGIC_LZMA:\n+\t\tbreak;\n+\tdefault:\n+\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t       bdevname(s->s_bdev, b));\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t{\n+\t\tstruct sqlzma *p;\n+\t\tdpri(\"block_size %d, devblksize %d\\n\",\n+\t\t     sblk->block_size, msblk->devblksize);\n+\t\tBUG_ON(sblk->block_size > sizeof(p->read_data));\n \t}\n \n \t/* Check the MAJOR & MINOR versions */\n@@ -1191,6 +1240,7 @@ static int squashfs_fill_super(struct su\n \t\tgoto failed_mount;\n \n \t/* Allocate read_page block */\n+\terr = -ENOMEM;\n \tmsblk->read_page = vmalloc(sblk->block_size);\n \tif (msblk->read_page == NULL) {\n \t\tERROR(\"Failed to allocate read_page block\\n\");\n@@ -1206,19 +1256,30 @@ static int squashfs_fill_super(struct su\n \t}\n \tmsblk->guid = msblk->uid + sblk->no_uids;\n    \n+\tdpri(\"swap %d\\n\", msblk->swap);\n+\terr = -EINVAL;\n \tif (msblk->swap) {\n-\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\t\tunsigned int *suid;\n+\n+\t\terr = -ENOMEM;\n+\t\tsuid = kmalloc(sizeof(*suid) * (sblk->no_uids + sblk->no_guids),\n+\t\t\t       GFP_KERNEL);\n+\t\tif (unlikely(!suid))\n+\t\t\tgoto failed_mount;\n \n+\t\terr = -EINVAL;\n \t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n \t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n \t\t\t\t\t sizeof(unsigned int)) |\n \t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n \t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tkfree(suid);\n \t\t\tgoto failed_mount;\n \t\t}\n \n \t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n \t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t\tkfree(suid);\n \t} else\n \t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n \t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n@@ -1232,6 +1293,7 @@ static int squashfs_fill_super(struct su\n \tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n \t\tgoto allocate_root;\n \n+\terr = -ENOMEM;\n \tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n \t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n \tif (msblk->fragment == NULL) {\n@@ -1261,9 +1323,12 @@ static int squashfs_fill_super(struct su\n \ts->s_export_op = &squashfs_export_ops;\n \n allocate_root:\n+\tdpri(\"alloate_root\\n\");\n \troot = new_inode(s);\n-\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0) {\n+\t\tiput(root);\n \t\tgoto failed_mount;\n+\t}\n \tinsert_inode_hash(root);\n \n \ts->s_root = d_alloc_root(root);\n@@ -1284,13 +1349,10 @@ failed_mount:\n \tvfree(msblk->read_page);\n \tkfree(msblk->block_cache);\n \tkfree(msblk->fragment_index_2);\n-\tvfree(msblk->stream.workspace);\n \tkfree(s->s_fs_info);\n \ts->s_fs_info = NULL;\n-\treturn -EINVAL;\n-\n-failure:\n-\treturn -ENOMEM;\n+ failure:\n+\treturn err;\n }\n \n \n@@ -1301,7 +1363,7 @@ static int squashfs_statfs(struct dentry\n \n \tTRACE(\"Entered squashfs_statfs\\n\");\n \n-\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_type = sblk->s_magic;\n \tbuf->f_bsize = sblk->block_size;\n \tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n \tbuf->f_bfree = buf->f_bavail = 0;\n@@ -1463,15 +1525,21 @@ static int read_block_index(struct super\n \tint block = 0;\n \t\n \tif (msblk->swap) {\n-\t\tchar sblock_list[blocks << 2];\n+\t\tchar *sblock_list;\n+\n+\t\tsblock_list = kmalloc(blocks << 2, GFP_KERNEL);\n+\t\tif (unlikely(!sblock_list))\n+\t\t\tgoto failure;\n \n \t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n \t\t\t\t*offset, blocks << 2, start_block, offset)) {\n \t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tkfree(sblock_list);\n \t\t\tgoto failure;\n \t\t}\n \t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n \t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t\tkfree(sblock_list);\n \t} else {\n \t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n \t\t\t\t*offset, blocks << 2, start_block, offset)) {\n@@ -2103,7 +2171,6 @@ static void squashfs_put_super(struct su\n \t\tkfree(sbi->fragment_index);\n \t\tkfree(sbi->fragment_index_2);\n \t\tkfree(sbi->meta_index);\n-\t\tvfree(sbi->stream.workspace);\n \t\tkfree(s->s_fs_info);\n \t\ts->s_fs_info = NULL;\n \t}\n@@ -2117,19 +2184,63 @@ static int squashfs_get_sb(struct file_s\n \t\t\t\tmnt);\n }\n \n+static void free_sqlzma(void)\n+{\n+\tint cpu;\n+\tstruct sqlzma *p;\n+\n+\tfor_each_online_cpu(cpu) {\n+\t\tp = per_cpu(sqlzma, cpu);\n+\t\tif (p) {\n+#ifdef KeepPreemptive\n+\t\t\tmutex_destroy(&p->mtx);\n+#endif\n+\t\t\tsqlzma_fin(&p->un);\n+\t\t\tkfree(p);\n+\t\t}\n+\t}\n+}\n \n static int __init init_squashfs_fs(void)\n {\n+\tstruct sqlzma *p;\n+\tint cpu;\n \tint err = init_inodecache();\n \tif (err)\n \t\tgoto out;\n \n+\tfor_each_online_cpu(cpu) {\n+\t\tdpri(\"%d: %p\\n\", cpu, per_cpu(sqlzma, cpu));\n+\t\terr = -ENOMEM;\n+\t\tp = kmalloc(sizeof(struct sqlzma), GFP_KERNEL);\n+\t\tif (p) {\n+#ifdef KeepPreemptive\n+\t\t\tmutex_init(&p->mtx);\n+#endif\n+\t\t\terr = sqlzma_init(&p->un, 1, 0);\n+\t\t\tif (unlikely(err)) {\n+\t\t\t\tERROR(\"Failed to intialize uncompress workspace\\n\");\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tper_cpu(sqlzma, cpu) = p;\n+\t\t\terr = 0;\n+\t\t} else\n+\t\t\tbreak;\n+\t}\n+\tif (unlikely(err)) {\n+\t\tfree_sqlzma();\n+\t\tgoto out;\n+\t}\n+\n \tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n-\t\t\"Phillip Lougher\\n\");\n+\t\t\"Phillip Lougher\\n\"\n+\t\t\"squashfs: LZMA suppport for slax.org by jro\\n\");\n \n \terr = register_filesystem(&squashfs_fs_type);\n-\tif (err)\n+\tif (err) {\n+\t\tfree_sqlzma();\n \t\tdestroy_inodecache();\n+\t}\n \n out:\n \treturn err;\n@@ -2139,6 +2250,7 @@ out:\n static void __exit exit_squashfs_fs(void)\n {\n \tunregister_filesystem(&squashfs_fs_type);\n+\tfree_sqlzma();\n \tdestroy_inodecache();\n }\n \n@@ -2187,6 +2299,6 @@ static void destroy_inodecache(void)\n \n module_init(init_squashfs_fs);\n module_exit(exit_squashfs_fs);\n-MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n-MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem, and LZMA suppport for slax.org\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>, and LZMA suppport for slax.org by jro\");\n MODULE_LICENSE(\"GPL\");\nIndex: linux-2.6.24.3/include/linux/squashfs_fs.h\n===================================================================\nRCS file: /proj/sqlzma/repository/linux-2.6.24.3/include/linux/squashfs_fs.h,v\nretrieving revision 1.1\nretrieving revision 1.3\ndiff -u -p -r1.1 -r1.3\n--- linux-2.6.24.3/include/linux/squashfs_fs.h\t12 Mar 2008 14:18:13 -0000\t1.1\n+++ linux-2.6.24.3/include/linux/squashfs_fs.h\t14 Mar 2008 04:53:33 -0000\t1.3\n@@ -341,7 +341,7 @@ struct squashfs_dir_entry {\n \tunsigned int\t\toffset:13;\n \tunsigned int\t\ttype:3;\n \tunsigned int\t\tsize:8;\n-\tint\t\t\tinode_number:16;\n+\tsigned int\t\tinode_number:16; /* very important signedness */\n \tchar\t\t\tname[0];\n } __attribute__ ((packed));\n \nIndex: linux-2.6.24.3/include/linux/squashfs_fs_sb.h\n===================================================================\nRCS file: /proj/sqlzma/repository/linux-2.6.24.3/include/linux/squashfs_fs_sb.h,v\nretrieving revision 1.1\nretrieving revision 1.5\ndiff -u -p -r1.1 -r1.5\n--- linux-2.6.24.3/include/linux/squashfs_fs_sb.h\t12 Mar 2008 14:18:13 -0000\t1.1\n+++ linux-2.6.24.3/include/linux/squashfs_fs_sb.h\t14 Mar 2008 13:53:27 -0000\t1.5\n@@ -54,7 +54,7 @@ struct squashfs_sb_info {\n \tlong long\t\t*fragment_index;\n \tunsigned int\t\t*fragment_index_2;\n \tchar\t\t\t*read_page;\n-\tstruct mutex\t\tread_data_mutex;\n+\t/* struct mutex\t\tread_data_mutex; */\n \tstruct mutex\t\tread_page_mutex;\n \tstruct mutex\t\tblock_cache_mutex;\n \tstruct mutex\t\tfragment_mutex;\n@@ -62,7 +62,7 @@ struct squashfs_sb_info {\n \twait_queue_head_t\twaitq;\n \twait_queue_head_t\tfragment_wait_queue;\n \tstruct meta_index\t*meta_index;\n-\tz_stream\t\tstream;\n+\t/* z_stream\t\tstream; */\n \tlong long\t\t*inode_lookup_table;\n \tint\t\t\tunused_cache_blks;\n \tint\t\t\tunused_frag_blks;\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/sqlzma2u-3.3.patch",
    "content": "Index: squashfs3.3/squashfs-tools/Makefile\n===================================================================\nRCS file: /proj/sqlzma/repository/squashfs3.3/squashfs-tools/Makefile,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.3/squashfs-tools/Makefile\t4 Nov 2007 13:19:11 -0000\t1.1\n+++ squashfs3.3/squashfs-tools/Makefile\t5 Nov 2007 05:43:36 -0000\t1.2\n@@ -1,19 +1,42 @@\n-INCLUDEDIR = .\n \n-CFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\n+ifndef Sqlzma\n+$(error Sqlzma is not defined)\n+endif\n \n-all: mksquashfs unsquashfs\n+INCLUDEDIR = .\n \n-mksquashfs: mksquashfs.o read_fs.o sort.o\n-\t$(CC) mksquashfs.o read_fs.o sort.o -lz -lpthread -lm -o $@\n+CFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\n+ifdef UseDebugFlags\n+DebugFlags = -g -Wall -Wno-unused-variable -O0 -UNDEBUG\n+endif\n+CFLAGS += -I${Sqlzma} -D_REENTRANT -DNDEBUG ${DebugFlags}\n+LDLIBS += -lz -L${LzmaAlone} -L${LzmaC}\n+Tgt = mksquashfs unsquashfs\n \n-mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h\n+all: ${Tgt}\n \n-read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h\n+read_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h \\\n+\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h\n \n sort.o: sort.c squashfs_fs.h global.h sort.h\n \n+mksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \\\n+\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h \\\n+\t${LzmaAlone}/liblzma_r.a ${LzmaC}/libunlzma_r.a\n+mksquashfs: LDLIBS += -lpthread -lunlzma_r -llzma_r -lstdc++\n+mksquashfs: mksquashfs.o read_fs.o sort.o\n+\n+unsquashfs.o: CFLAGS += -U_REENTRANT\n+unsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h \\\n+\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h ${LzmaC}/libunlzma.a\n+unsquashfs: LDLIBS += -lunlzma\n unsquashfs: unsquashfs.o\n-\t$(CC) unsquashfs.o -lz -o $@\n \n-unsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h\n+clean:\n+\t${RM} *~ *.o ${Tgt}\n+\n+-include test.mk\n+\n+# Local variables: ;\n+# compile-command: (concat \"make Sqlzma=../.. -f \" (file-name-nondirectory (buffer-file-name)));\n+# End: ;\nIndex: squashfs3.3/squashfs-tools/mksquashfs.c\n===================================================================\nRCS file: /proj/sqlzma/repository/squashfs3.3/squashfs-tools/mksquashfs.c,v\nretrieving revision 1.1\nretrieving revision 1.8\ndiff -u -p -r1.1 -r1.8\n--- squashfs3.3/squashfs-tools/mksquashfs.c\t4 Nov 2007 13:19:11 -0000\t1.1\n+++ squashfs3.3/squashfs-tools/mksquashfs.c\t14 Mar 2008 13:53:27 -0000\t1.8\n@@ -61,6 +61,8 @@\n #include \"mksquashfs.h\"\n #include \"global.h\"\n #include \"sort.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n #ifdef SQUASHFS_TRACE\n #define TRACE(s, args...)\tdo { \\\n@@ -112,6 +114,11 @@ unsigned short uid_count = 0, guid_count\n squashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\n int block_offset;\n int file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n+struct sqlzma_un un;\n+struct sqlzma_opts sqlzma_opts = {\n+\t.try_lzma\t= 1,\n+\t.dicsize\t= SQUASHFS_FILE_SIZE\n+};\n \n /* write position within data section */\n long long bytes = 0, total_bytes = 0;\n@@ -626,21 +633,8 @@ unsigned int mangle2(z_stream **strm, ch\n \t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n \t}\n \n-\tstream->next_in = (unsigned char *) s;\n-\tstream->avail_in = size;\n-\tstream->next_out = (unsigned char *) d;\n-\tstream->avail_out = block_size;\n-\n-\tres = deflate(stream, Z_FINISH);\n-\tif(res != Z_STREAM_END && res != Z_OK) {\n-\t\tif(res == Z_STREAM_ERROR)\n-\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n-\t\telse if(res == Z_BUF_ERROR)\n-\t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\\n\");\n-\t\telse\n-\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n-\t}\n-\n+\tres = sqlzma_cm(&sqlzma_opts, stream, (void *)s, size, (void *)d,\n+\t\t\tblock_size);\n \tc_byte = stream->total_out;\n \n \tif(res != Z_STREAM_END || c_byte >= size) {\n@@ -991,12 +985,12 @@ int create_inode(squashfs_inode *i_no, s\n \t\tchar buff[65536];\n \n \t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n-\t\t\tERROR(\"Failed to read symlink %d, creating empty symlink\\n\", filename);\n+\t\t\tERROR(\"Failed to read symlink %s, creating empty symlink\\n\", filename);\n \t\t\tbyte = 0;\n \t\t}\n \n \t\tif(byte == 65536) {\n-\t\t\tERROR(\"Symlink %d is greater than 65536 bytes! Creating empty symlink\\n\", filename);\n+\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! Creating empty symlink\\n\", filename);\n \t\t\tbyte = 0;\n \t\t}\n \n@@ -1022,7 +1016,7 @@ int create_inode(squashfs_inode *i_no, s\n \t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n \t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n \t} else\n-\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\");\n+\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\n \n \t*i_no = MKINODE(inode);\n \tinode_count ++;\n@@ -1250,17 +1244,17 @@ char *get_fragment(char *buffer, struct \n \t\tint res;\n \t\tunsigned long bytes = block_size;\n \t\tchar cbuffer[block_size];\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = (void *)cbuffer, .sz = size},\n+\t\t\t{.buf = (void *)buffer, .sz = bytes}\n+\t\t};\n \n \t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n \n-\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t}\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tBAD_ERROR(\"%s:%d: res %d\\n\", __func__, __LINE__, res);\n \t} else\n \t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n \n@@ -1755,6 +1749,7 @@ void *reader(void *arg)\n \t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n \t\t\t\treader_read_file(entry->dir);\n \t}\n+\treturn NULL;\n }\n \n \n@@ -1926,7 +1921,7 @@ int progress_bar(long long current, long\n \tint spaces = columns - used - hashes;\n \n \tif(!progress || columns - used < 0)\n-\t\treturn;\n+\t\treturn 0;\n \n \tprintf(\"\\r[\");\n \n@@ -1939,6 +1934,7 @@ int progress_bar(long long current, long\n \tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n \tprintf(\" %3lld%%\", current * 100 / max);\n \tfflush(stdout);\n+\treturn 0;\n }\n \n \n@@ -2635,7 +2631,7 @@ error:\n \n void dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n {\n-\tint squashfs_type;\n+\tint squashfs_type = -1;\n \tint duplicate_file;\n \tchar *pathname = dir_info->pathname;\n \tstruct directory dir;\n@@ -3242,7 +3238,8 @@ void read_recovery_data(char *recovery_f\n \tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n \tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n \tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n-\tprintf(\"GNU General Public License for more details.\\n\");\n+\tprintf(\"GNU General Public License for more details.\\n\");\\\n+\tprintf(\"and LZMA support for slax.org by jro.\\n\");\n int main(int argc, char *argv[])\n {\n \tstruct winsize winsize;\n@@ -3261,6 +3258,7 @@ int main(int argc, char *argv[])\n \tbe = FALSE;\n #endif\n \n+\tun.un_lzma = 1;\n \tblock_log = slog(block_size);\n \tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n \t\tVERSION();\n@@ -3319,24 +3317,33 @@ int main(int argc, char *argv[])\n \t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n \t\t\t\texit(1);\n \t\t\t}\n-\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n+\t\t} else if(strcmp(argv[i], \"-b\") == 0\n+\t\t\t|| strcmp(argv[i], \"-lzmadic\") == 0) {\n+\t\t\tlong bs;\n+\t\t\tunsigned int bl;\n \t\t\tif(++i == argc) {\n-\t\t\t\tERROR(\"%s: -b missing block size\\n\", argv[0]);\n+\t\t\t\tERROR(\"%s: -b|-lzmadic missing block size\\n\", argv[0]);\n \t\t\t\texit(1);\n \t\t\t}\n-\t\t\tblock_size = strtol(argv[i], &b, 10);\n+\t\t\tbs = strtol(argv[i], &b, 10);\n \t\t\tif(*b == 'm' || *b == 'M')\n-\t\t\t\tblock_size *= 1048576;\n+\t\t\t\tbs *= 1048576;\n \t\t\telse if(*b == 'k' || *b == 'K')\n-\t\t\t\tblock_size *= 1024;\n+\t\t\t\tbs *= 1024;\n \t\t\telse if(*b != '\\0') {\n-\t\t\t\tERROR(\"%s: -b invalid block size\\n\", argv[0]);\n+\t\t\t\tERROR(\"%s: -b|-lzmadic invalid size\\n\", argv[0]);\n \t\t\t\texit(1);\n \t\t\t}\n-\t\t\tif((block_log = slog(block_size)) == 0) {\n-\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 1Mbyte\\n\", argv[0]);\n+\t\t\tbl = slog(bs);\n+\t\t\tif(bl == 0) {\n+\t\t\t\tERROR(\"%s: -b|-lzmadic size not power of two or not between 4096 and 1Mbyte\\n\", argv[0]);\n \t\t\t\texit(1);\n \t\t\t}\n+\t\t\tif (!strcmp(argv[i - 1], \"-b\")) {\n+\t\t\t\tblock_size = bs;\n+\t\t\t\tblock_log = bl;\n+\t\t\t}\n+\t\t\tsqlzma_opts.dicsize = bs;\n \t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n \t\t\tif(++i == argc) {\n \t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n@@ -3440,6 +3447,9 @@ int main(int argc, char *argv[])\n \t\t\t\texit(1);\n \t\t\t}\t\n \t\t\troot_name = argv[i];\n+\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n+\t\t\tun.un_lzma = 0;\n+\t\t\tsqlzma_opts.try_lzma = 0;\n \t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n \t\t\tVERSION();\n \t\t} else {\n@@ -3489,6 +3499,12 @@ printOptions:\n \t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n \t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards (globbing) to be used in\\n\\t\\t\\texclude dirs/files\\n\");\n \t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n+\t\t\tERROR(\"-lzmadic <dic_size>\\tset the LZMA dictionary\"\n+\t\t\t      \" size to <dic_size>\\n\"\n+\t\t\t      \"\\t\\t\\tDefault value always follow the block\"\n+\t\t\t      \" size\\n\"\n+\t\t\t      \"\\t\\t\\tUse this alone or AFTER -b option\\n\");\n+\t\t\tERROR(\"-nolzma\\t\\t\\tnever try LZMA compression\\n\");\n \t\t\texit(1);\n \t\t}\n \t}\n@@ -3595,6 +3611,7 @@ printOptions:\n \n \t\tbe = orig_be;\n \t\tblock_log = slog(block_size = sBlk.block_size);\n+\t\t//sqlzma_opts.dicsize = block_size;\n \t\ts_minor = sBlk.s_minor;\n \t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n \t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n@@ -3608,10 +3625,18 @@ printOptions:\n \n \tinitialise_threads();\n \n+\ti = sqlzma_init(&un, un.un_lzma, 0);\n+\tif (i != Z_OK) {\n+\t\tERROR(\"%s:%d: %d\\n\", __func__, __LINE__, i);\n+\t\tEXIT_MKSQUASHFS();\n+\t}\n+\n \tif(delete) {\n \t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n \t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n \t\tbytes = sizeof(squashfs_super_block);\n+\t\tif (sqlzma_opts.try_lzma)\n+\t\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n \t} else {\n \t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n \t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n@@ -3635,6 +3660,8 @@ printOptions:\n \n \t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n \t\t\t\"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n+\t\tif (sqlzma_opts.try_lzma)\n+\t\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n \t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n \t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n \n@@ -3733,7 +3760,9 @@ printOptions:\n \t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n \tsBlk.root_inode = inode;\n \tsBlk.inodes = inode_count;\n-\tsBlk.s_magic = SQUASHFS_MAGIC;\n+\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n+\tif (!un.un_lzma)\n+\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n \tsBlk.s_major = SQUASHFS_MAJOR;\n \tsBlk.s_minor = s_minor;\n \tsBlk.block_size = block_size;\n@@ -3819,6 +3848,8 @@ restore_filesystem:\n \t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n \t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n \t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n+\tif (sqlzma_opts.try_lzma)\n+\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n \tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n \tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n \t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\nIndex: squashfs3.3/squashfs-tools/read_fs.c\n===================================================================\nRCS file: /proj/sqlzma/repository/squashfs3.3/squashfs-tools/read_fs.c,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.3/squashfs-tools/read_fs.c\t4 Nov 2007 13:19:11 -0000\t1.1\n+++ squashfs3.3/squashfs-tools/read_fs.c\t5 Nov 2007 05:43:36 -0000\t1.2\n@@ -46,6 +46,8 @@ extern int add_file(long long, long long\n #include <squashfs_fs.h>\n #include \"read_fs.h\"\n #include \"global.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n #include <stdlib.h>\n \n@@ -62,6 +64,7 @@ extern int add_file(long long, long long\n \t\t\t\t\t} while(0)\n \n int swap;\n+extern struct sqlzma_un un;\n \n int read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n {\n@@ -81,19 +84,20 @@ int read_block(int fd, long long start, \n \t\tchar buffer[SQUASHFS_METADATA_SIZE];\n \t\tint res;\n \t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = (void *)buffer},\n+\t\t\t{.buf = (void *)block, .sz = bytes}\n+\t\t};\n \n \t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n \t\tread_bytes(fd, start + offset, c_byte, buffer);\n \n-\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t\treturn 0;\n-\t\t}\n+\t\tsbuf[Src].sz = c_byte;\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tabort();\n+\t\tbytes = un.un_reslen;\n \t\tif(next)\n \t\t\t*next = start + offset + c_byte;\n \t\treturn bytes;\n@@ -351,18 +355,30 @@ int read_super(int fd, squashfs_super_bl\n \n \t/* Check it is a SQUASHFS superblock */\n \tswap = 0;\n-\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n-\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n-\t\t\tsquashfs_super_block sblk;\n-\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n-\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n-\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n-\t\t\tswap = 1;\n-\t\t} else  {\n-\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n-\t\t\tgoto failed_mount;\n-\t\t}\n-\t}\n+\tswitch (sBlk->s_magic) {\n+\t\tsquashfs_super_block sblk;\n+\n+\tcase SQUASHFS_MAGIC_LZMA:\n+\t\tif (!un.un_lzma)\n+\t\t\tgoto bad;\n+\t\tbreak;\n+\tcase SQUASHFS_MAGIC:\n+\t\tbreak;\n+\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n+\t\tif (!un.un_lzma)\n+\t\t\tgoto bad;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_SWAP:\n+\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n+\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n+\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n+\t\tswap = 1;\n+\t\tbreak;\n+\tbad:\n+\tdefault:\n+\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n+\t\tgoto failed_mount;\n+ \t}\n \n \t/* Check the MAJOR & MINOR versions */\n \tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n@@ -416,7 +432,7 @@ unsigned char *squashfs_readdir(int fd, \n \tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n \tunsigned char *directory_table = NULL;\n \tint byte, bytes = 0, dir_count;\n-\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block; \n+\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block = -1; \n \n \tsize += offset;\n \tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\nIndex: squashfs3.3/squashfs-tools/sort.c\n===================================================================\nRCS file: /proj/sqlzma/repository/squashfs3.3/squashfs-tools/sort.c,v\nretrieving revision 1.1\nretrieving revision 1.2\ndiff -u -p -r1.1 -r1.2\n--- squashfs3.3/squashfs-tools/sort.c\t4 Nov 2007 13:19:11 -0000\t1.1\n+++ squashfs3.3/squashfs-tools/sort.c\t5 Nov 2007 05:43:36 -0000\t1.2\n@@ -74,7 +74,7 @@ struct sort_info *sort_info_list[65536];\n struct priority_entry *priority_list[65536];\n \n extern int silent;\n-extern write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *c_size);\n+extern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *c_size);\n \n \n int add_priority_list(struct dir_ent *dir, int priority)\nIndex: squashfs3.3/squashfs-tools/unsquashfs.c\n===================================================================\nRCS file: /proj/sqlzma/repository/squashfs3.3/squashfs-tools/unsquashfs.c,v\nretrieving revision 1.1\nretrieving revision 1.6\ndiff -u -p -r1.1 -r1.6\n--- squashfs3.3/squashfs-tools/unsquashfs.c\t4 Nov 2007 13:19:11 -0000\t1.1\n+++ squashfs3.3/squashfs-tools/unsquashfs.c\t14 Mar 2008 13:53:27 -0000\t1.6\n@@ -52,6 +52,8 @@\n #include <squashfs_fs.h>\n #include \"read_fs.h\"\n #include \"global.h\"\n+#include \"sqlzma.h\"\n+#include \"sqmagic.h\"\n \n #include <stdlib.h>\n #include <time.h>\n@@ -131,6 +133,7 @@ unsigned int block_size;\n int lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE, use_regex = FALSE;\n char **created_inode;\n int root_process;\n+struct sqlzma_un un;\n \n int lookup_type[] = {\n \t0,\n@@ -199,6 +202,8 @@ int print_filename(char *pathname, struc\n \t\treturn 1;\n \t}\n \n+\t/* printf(\"i%d \", inode->inode_number); */\n+\n \tif((user = getpwuid(inode->uid)) == NULL) {\n \t\tsprintf(dummy, \"%d\", inode->uid);\n \t\tuserstr = dummy;\n@@ -318,21 +323,21 @@ int read_block(long long start, long lon\n \t\tchar buffer[SQUASHFS_METADATA_SIZE];\n \t\tint res;\n \t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = (void *)buffer},\n+\t\t\t{.buf = (void *)block, .sz = bytes}\n+\t\t};\n \n \t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n \t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n \t\t\tgoto failed;\n \n-\t\tif((res = uncompress((unsigned char *) block, &bytes,\n-\t\t(const unsigned char *) buffer, c_byte)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t\tgoto failed;\n-\t\t}\n+\t\tsbuf[Src].sz = c_byte;\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tabort();\n+\t\tbytes = un.un_reslen;\n \t\tif(next)\n \t\t\t*next = start + offset + c_byte;\n \t\treturn bytes;\n@@ -359,20 +364,19 @@ int read_data_block(long long start, uns\n \tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n \n \tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n+\t\tenum {Src, Dst};\n+\t\tstruct sized_buf sbuf[] = {\n+\t\t\t{.buf = (void *)data, .sz = c_byte},\n+\t\t\t{.buf = (void *)block, .sz = bytes}\n+\t\t};\n+\n \t\tif(read_bytes(start, c_byte, data) == FALSE)\n \t\t\treturn 0;\n \n-\t\tif((res = uncompress((unsigned char *) block, &bytes,\n-\t\t(const unsigned char *) data, c_byte)) != Z_OK) {\n-\t\t\tif(res == Z_MEM_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n-\t\t\telse if(res == Z_BUF_ERROR)\n-\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n-\t\t\telse\n-\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n-\t\t\treturn 0;\n-\t\t}\n-\n+\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n+\t\tif (res)\n+\t\t\tabort();\n+\t\tbytes = un.un_reslen;\n \t\treturn bytes;\n \t} else {\n \t\tif(read_bytes(start, c_byte, block) == FALSE)\n@@ -921,7 +925,7 @@ int create_inode(char *pathname, struct \n \t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n \t\t\t\tdev_count ++;\n \t\t\t} else\n-\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n+\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n \t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n \t\t\tbreak;\n \t\t}\n@@ -1775,19 +1779,27 @@ int read_super(char *source)\n \tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n \n \t/* Check it is a SQUASHFS superblock */\n+\tun.un_lzma = 1;\n \tswap = 0;\n-\tif(sBlk.s_magic != SQUASHFS_MAGIC) {\n-\t\tif(sBlk.s_magic == SQUASHFS_MAGIC_SWAP) {\n-\t\t\tsquashfs_super_block sblk;\n-\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n-\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n-\t\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n-\t\t\tswap = 1;\n-\t\t} else  {\n-\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n-\t\t\tgoto failed_mount;\n-\t\t}\n-\t}\n+\tswitch (sBlk.s_magic) {\n+\t\tsquashfs_super_block sblk;\n+\tcase SQUASHFS_MAGIC:\n+\t\tun.un_lzma = 0;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_LZMA:\n+\t\tbreak;\n+\tcase SQUASHFS_MAGIC_SWAP:\n+\t\tun.un_lzma = 0;\n+\t\t/*FALLTHROUGH*/\n+\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n+\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n+\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n+\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n+\t\tswap = 1;\n+\tdefault:\n+\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n+\t\tgoto failed_mount;\n+ \t}\n \n \t/* Check the MAJOR & MINOR versions */\n \tif(sBlk.s_major == 1 || sBlk.s_major == 2) {\n@@ -1857,7 +1869,8 @@ struct pathname *process_extract_files(s\n \tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n \tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n \tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n-\tprintf(\"GNU General Public License for more details.\\n\");\n+\tprintf(\"GNU General Public License for more details.\\n\");\\\n+\tprintf(\"and LZMA support for slax.org by jro.\\n\");\n int main(int argc, char *argv[])\n {\n \tchar *dest = \"squashfs-root\";\n@@ -1957,6 +1970,11 @@ options:\n \t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n \n \tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n+\ti = sqlzma_init(&un, un.un_lzma, 0);\n+\tif (i != Z_OK) {\n+\t\tfputs(\"sqlzma_init failed\", stderr);\n+\t\tabort();\n+\t}\n \n \tread_uids_guids();\n \n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/sqmagic.h",
    "content": "/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE must follow the one in squashfs.\n */\n\n/* $Id: sqmagic.h,v 1.2 2006-11-27 03:54:58 jro Exp $ */\n\n#ifndef __sqmagic_h__\n#define __sqmagic_h__\n\n/* see SQUASHFS_MAGIC in squashfs_fs.h */\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/ACKNOWLEDGEMENTS",
    "content": "\t\t\tACKNOWLEDGEMENTS\n\nThanks to everyone who have download squashfs.  I appreciate people\nusing it, and any feedback you have.\n\nThe following have provided useful feedback, which has guided\nsome of the extra features in squashfs.  This is a randomly ordered\n(roughly in chronological order) list, which is updated when\nI remember...\n\nAcknowledgements for Squashfs-3.3\n------------------------------------\n\nPeter Korsgaard and others sent patches updating Squashfs to changes in the\nVFS interface for 2.6.22/2.6.23/2.6.24-rc1.  Peter also sent some small patches\nfor the Squashfs kernel code.\n\nVito Di Leo sent a patch extending Mksquashfs to support regex filters.\nWhile his patched worked, it unfortunately made it easy to make Mksquashfs\nperform unpredictably with poorly choosen regex expressions.  It, however,\nencouraged myself to add support for wildcard pattern matching and regex\nfilters in a different way.\n\nAcknowledgements for Squashfs-3.2-r2\n------------------------------------\n\nJunjiro Okajima discovered a couple of SMP issues, thanks.\n\nJunjiro Okajima and Tomas Matejicek have produced some good LZMA patches\nfor Squashfs.\n\nAcknowledgements for Squashfs-3.2\n---------------------------------\n\nPeter Korsgaard sent a patch updating Squashfs to changes in the VFS interface\nin Linux 2.6.20.\n\nAcknowledgements for Squashfs-3.1\n---------------------------------\n\nKenneth Duda and Ed Swierk of Arastra Inc. identified numerous bugs with\nSquashfs, and provided patches which were the basis for some of the\nfixes.  In particular they identified the fragment rounding bug, the\nNFS bug, the initrd bug, and helped identify the 4K stack overflow bug.\n\nScott James Remnant (Ubuntu) also identified the fragment rounding bug,\nand he also provided a patch.\n\nMing Zhang identified the Lseek bug in Mksquashfs.  His tests on the\nperformance of Mksquashfs on SMP systems encouraged the rewrite of\nMksquashfs.\n\nPeter Korsgaard, Daniel Olivera and Zilvinas Valinskas noticed\nSquashfs 3.0 didn't compile on Linux-2.6.18-rc[1-4] due to changes\nin the Linux VFS interfaces, and provided patches.\n\nTomas Matejicek (SLAX) suggested the -force option on Unsquashfs, and noticed\nUnsquashfs didn't return the correct exit status.\n\nYann Le Doare reported a kernel oops and provided a Qemu image that led\nto the identification of the simultaneously accessing multiply mounted Squashfs\nfilesystems bug.\n\n\nOlder acknowledgements\n----------------------\n\nMark Robson - pointed out early on that initrds didn't work\n\nAdam Warner - pointed out that greater than 2GB filesystems didn't work.\n\nJohn Sutton - raised the problem when archiving the entire filesystem\n(/) there was no way to prevent /proc being archived.  This prompted\nexclude files.\n\nMartin Mueller (LinuxTV) - noticed that the filesystem length in the\nsuperblock doesn't match the output filesystem length.  This is due to\npadding to a 4K boundary.  This prompted the addition of the -nopad option.\nHe also reported a problem where 32K block filesystems hung when used as\ninitrds.\n\nArkadiusz Patyk (Polish Linux Distribution - PLD) reported a problem where 32K\nblock filesystems hung when used as a root filesystem mounted as a loopback\ndevice.\n\nJoe Blow emailed me that I'd forgotten to put anything in the README about\nmounting the squashfs filesystem.\n\nDavid Fox (Lindows) noticed that the exit codes returned by Mksquashfs were\nwrong.  He also noticed that a lot of time was spent in the duplicate scan\nroutine.\n\nCameron Rich complained that Squashfs did not support FIFOs or sockets.\n\nSteve Chadsey and Thomas Weissmuller noticed that files larger than the\navailable memory could not be compressed by Mksquashfs.\n\n\"Ptwahyu\" and \"Hoan\" (I have no full names and I don't like giving people's\nemail addresses), noticed that Mksquashfs 1.3 SEGV'd occasionally.  Even though\nI had already noticed this bug, it is useful to be informed by other people.\n\nDon Elwell, Murray Jensen and Cameron Rich, have all sent in patches.  Thanks,\nI have not had time to do anything about them yet...\n\nDrew Scott Daniels has been a good advocate for Squashfs.\n\nErik Andersen has made some nice suggestions, unfortunately, I have\nnot had time to implement anything.\n\nArtemiy I. Pavlov has written a useful LDP mini-howto for Squashfs\n(http://linuxdoc.artemio.net/squashfs).\n\nYves Combe reported the Apple G5 bug, when using Squashfs for\nhis PPC Knoppix-mib livecd project.\n\nJaco Greeff (mklivecd project, and maintainer of the Mandrake\nsquashfs-tools package) suggested the new mksquashfs -ef option, and the\nstandalone build for mksquashfs.\n\nMike Schaudies made a donation.\n\nArkadiusz Patyk from the Polish Linux Distribution reported that Squashfs\ndidn't work on amd64 machines. He gave me an account on a PLD amd64 machine\nwhich allowed myself to track down these bugs.\n\nMiles Roper, Peter Kjellerstedt and Willy Tarreau reported that release 2.1 did\nnot compile with gcc < 3.x.\n\nMarcel J.E. Mol reported lack of kernel memory issues when using Squashfs\non small memory embedded systems.  This prompted the addition of the embedded\nsystem kernel configuration options.\n\nEra Scarecrow noticed that Mksquashfs had not been updated to reflect that\nsmaller than 4K blocks are no longer supported.\n\nKenichi Shima reported the Kconfig file had not been updated to 2.2.\n\nAaron Ten Clay made a donation!\n\nTomas Matejicek (SLAX) made a donation!\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/CHANGES",
    "content": "\t\t\tSQUASHFS CHANGE LOG\n\n3.3\t1 NOV 2007\tIncrease in block size, sparse file support,\n\t\t\tMksquashfs and Unsquashfs extended to use\n\t\t\tpattern matching in exclude/extract files, plus\n\t\t\tmany more improvements and bug fixes.\n\n\t1. Filesystem improvements:\n\n\t     1.1. Maximum block size has been increased to 1Mbyte, and the\n\t    \t  default block size has been increased to 128 Kbytes.\n\t\t  This improves compression.\n\n\t     1.2. Sparse files are now supported.  Sparse files are files\n\t\t  which have large areas of unallocated data commonly called\n\t\t  holes.  These files are now detected by Squashfs and stored\n\t\t  more efficiently.  This improves compression and read\n\t\t  performance for sparse files.\n\n\t2. Mksquashfs improvements:\n\n\t   2.1.  Exclude files have been extended to use wildcard pattern\n\t\t matching and regular expressions.  Support has also been\n\t\t added for non-anchored excludes, which means it is\n\t\t now possible to specify excludes which match anywhere\n\t\t in the filesystem (i.e. leaf files), rather than always\n\t\t having to specify exclude files starting from the root\n\t\t directory (anchored excludes).\n\n\t   2.2.  Recovery files are now created when appending to existing\n\t\t Squashfs filesystems.  This allows the original filesystem\n\t\t to be recovered if Mksquashfs aborts unexpectedly\n\t\t (i.e. power failure).\n\n\t3. Unsquashfs improvements:\n\n\t    3.1. Multiple extract files can now be specified on the\n\t\t command line, and the files/directories to be extracted can\n\t\t now also be given in a file.\n\n\t    3.2. Extract files have been extended to use wildcard pattern\n\t\t matching and regular expressions.\n\n\t    3.3. Filename printing has been enhanced and Unquashfs can\n\t\t now display filenames with file attributes\n\t\t ('ls -l' style output).\n\n\t    3.4. A -stat option has been added which displays the filesystem\n\t\t superblock information.\n\n\t    3.5. Unsquashfs now supports 1.x filesystems.\n\n\t4. Miscellaneous improvements/bug fixes:\n\n\t    4.1. Squashfs kernel code improved to use SetPageError in\n\t\t squashfs_readpage() if I/O error occurs.\n\n\t    4.2. Fixed Squashfs kernel code bug preventing file\n\t\t seeking beyond 2GB.\n\n\t    4.3. Mksquashfs now detects file size changes between\n\t\t first phase directory scan and second phase filesystem create.\n\t\t It also deals better with file I/O errors.\n\n\n3.2-r2\t15 JAN 2007\tKernel patch update and progress bar bug fix\n\n\t1. Kernel patches 2.6.19/2.6.20 have been updated to use\n\t   const structures and mutexes rather than older semaphores.\n\t2. Minor SMP bug fixes.\n\t3. Progress bar broken on x86-64.  Fixed.\n\n3.2\t2 JAN 2007\tNFS support, improvements to the Squashfs-tools, major\n\t\t\tbug fixes, lots of small improvements/bug fixes, and new\n\t\t\tkernel patches.\n\n\tImprovements:\n\n\t1. Squashfs filesystems can now be exported via NFS.\n\t2. Unsquashfs now supports 2.x filesystems.\n\t3. Mksquashfs now displays a progress bar.\n\t4. Squashfs kernel code has been hardened against accidently or\n\t   maliciously corrupted Squashfs filesystems.\n\n\tBug fixes:\n\n\t5. Race condition occurring on S390 in readpage() fixed.\n\t6. Odd behaviour of MIPS memcpy in read_data() routine worked-around.\n\t7. Missing cache_flush in Squashfs symlink_readpage() added.\n\t\n\n3.1-r2\t30 AUG 2006\tMksquashfs -sort bug fix\n\n\t\t\tA code optimisation after testing unfortunately\n\t\t\tbroke sorting in Mksquashfs.  This has been fixed.\n\n3.1\t19 AUG 2006\tThis release has some major improvements to\n\t\t\tthe squashfs-tools, a couple of major bug\n\t\t\tfixes, lots of small improvements/bug fixes,\n\t\t\tand new kernel patches.\n\n\t\t\t\n\t1. Mksquashfs has been rewritten to be multi-threaded.  It\n\t   has the following improvements\n\n\t   1.1. Parallel compression.  By default as many compression and\n\t\tfragment compression threads are created as there are available\n\t\tprocessors.  This significantly speeds up performance on SMP\n\t\tsystems.\n\t   1.2. File input and filesystem output is peformed in parallel on\n\t\tseparate threads to maximise I/O performance.  Even on single\n\t\tprocessor systems this speeds up performance by at least 10%.\n\t   1.3. Appending has been significantly improved, and files within the\n\t\tfilesystem being appended to are no longer scanned and\n\t\tchecksummed.  This significantly improves append time for large\n\t\tfilesystems.\n\t   1.4. File duplicate checking has been optimised, and split into two\n\t\tseparate phases.  Only files which are considered possible\n\t\tduplicates after the first phase are checksummed and cached in\n\t\tmemory.\n\t   1.5\tThe use of swap memory was found to significantly impact\n\t\tperformance. The amount of memory used to cache files is now a\n\t\tcommand line option, by default this is 512 Mbytes.\n \n\t2. Unsquashfs has the following improvements\n\n\t   2.1  Unsquashfs now allows you to specify the filename or the\n\t\tdirectory within the Squashfs filesystem that is to be\n\t\textracted, rather than always extracting the entire filesystem.\n\t   2.2  A new -force option has been added which forces Unsquashfs to\n\t\toutput to the destination directory even if files and directories\n\t\talready exist in the destination directory.  This allows you to\n\t\tupdate an already existing directory tree, or to Unsquashfs to\n\t\ta partially filled directory tree.  Without the -force option\n\t\tUnsquashfs will refuse to output.\n\n\t3.  The following major bug fixes have been made\n\n\t  3.1  \tA fragment table rounding bug has been fixed in Mksquashfs.\n\t\tPreviously if the number of fragments in the filesystem\n\t\twere a multiple of 512, Mksquashfs would generate an\n\t\tincorrect filesystem.\n\t  3.2  \tA rare SMP bug which occurred when simultaneously acccessing\n\t\tmultiply mounted Squashfs filesystems has been fixed.\n\n\t4. Miscellaneous improvements/bug fixes\n\n\t  4.1\tKernel code stack usage has been reduced.  This is to ensure\n\t\tSquashfs works with 4K stacks.\n\t  4.2   Readdir (Squashfs kernel code) has been fixed to always\n\t\treturn 0, rather than the number of directories read.  Squashfs\n\t\tshould now interact better with NFS.\n\t  4.3\tLseek bug in Mksquashfs when appending to larger than 4GB\n\t\tfilesystems fixed.\n\t  4.4\tSquashfs 2.x initrds can now been mounted.\n\t  4.5\tUnsquashfs exit status fixed.\n\t  4.6\tNew patches for linux-2.6.18 and linux-2.4.33.\n\n\t\n3.0\t15 MAR 2006\tMajor filesystem improvements\n\n\t1. Filesystems are no longer limited to 4 GB.  In\n\t   theory 2^64 or 4 exabytes is now supported.\n\t2. Files are no longer limited to 4 GB.  In theory the maximum\n\t   file size is 4 exabytes.\n\t3. Metadata (inode table and directory tables) are no longer\n\t   restricted to 16 Mbytes.\n\t4. Hardlinks are now suppported.\n\t5. Nlink counts are now supported.\n\t6. Readdir now returns '.' and '..' entries.\n\t7. Special support for files larger than 256 MB has been added to\n\t   the Squashfs kernel code for faster read access.\n\t8. Inode numbers are now stored within the inode rather than being\n\t   computed from inode location on disk (this is not so much an\n\t   improvement, but a change forced by the previously listed\n\t   improvements).\n\n2.2-r2\t8 SEPT 2005\tSecond release of 2.2, this release fixes a couple\n\t\t\tof small bugs, a couple of small documentation\n\t\t\tmistakes, and adds a patch for kernel 2.6.13. \n\n\t1. Mksquashfs now deletes the output filesystem image file if an\n\t   error occurs whilst generating the filesystem.  Previously on\n\t   error the image file was left empty or partially written.\n\t2. Updated mksquashfs so that it doesn't allow you to generate\n\t   filesystems with block sizes smaller than 4K.  Squashfs hasn't\n\t   supported block sizes less than 4K since 2.0-alpha.\n\t3. Mksquashfs now ignores missing files/directories in sort files.\n\t   This was the original behaviour before 2.2.\n\t4. Fixed small mistake in fs/Kconfig where the version was still\n\t   listed as 2.0.\n\t5. Updated ACKNOWLEDGEMENTS file.\n\n\n2.2\t3 JUL 2005\tThis release has some small improvements, bug fixes\n\t\t\tand patches for new kernels.\n\n\t1. Sort routine re-worked and debugged from release 2.1.  It now allows\n\t   you to give Mkisofs style sort files and checks for filenames that\n\t   don't match anything.  Sort priority has also been changed to\n\t   conform to Mkisofs usage, highest priority files are now placed\n\t   at the start of the filesystem (this means they will be on the\n\t   inside of a CD or DVD).\n\t2. New Configure options for embedded systems (memory constrained\n\t   systems).  See INSTALL file for further details.\n\t3. Directory index bug fixed where chars were treated as signed on\n           some architectures.  A file would not be found in the rare case\n\t   that the filename started with a chracter greater than 127.\n\t4. Bug introduced into the read_data() routine when sped up to use data\n\t   block queueing fixed.  If the second or later block resulted in an\n\t   I/O error this was not checked.\n\t5. Append bug introduced in 2.1 fixed.  The code to compute the new\n\t   compressed and uncompressed directory parts after appending was\n\t   wrong.\n\t6. Metadata block length read routine altered to not perform a\n\t   misaligned short read.  This was to fix reading on an ARM7 running\n\t   uCLinux without a misaligned read interrupt handler.\n\t7. Checkdata bug introduced in 2.1 fixed.\n\t\n\n2.1-r2  15 DEC 2004\tCode changed so it can be compiled with gcc 2.x\n\n\t1.  In some of the code added for release 2.1 I unknowingly used some\n\t    gcc extensions only supported by 3.x compilers.  I have received\n\t    a couple of reports that the 2.1 release doesn't build on 2.x and so\n\t    people are clearly still using gcc 2.x.  The code has been\n\t    rewritten to remove these extensions.\n\n2.1\t10 DEC 2004\tSignificantly improved directory handling plus numerous\n\t\t\tother smaller improvements\n\n\t1.  Fast indexed directories implemented.  These speed up directory\n\t    operations (ls, file lookup etc.) significantly for directories\n\t    larger than 8 KB.\n\t2.  All directories are now sorted in alphabetical order.  This again\n\t    speeds up directory operations, and in some cases it also results in\n\t    a small compression improvement (greater data similarity between\n\t    files with alphabetically similar names).\n\t3.  Maximum directory size increased from 512 KB to 128 MB.\n\t4.  Duplicate fragment checking and appending optimised in mksquashfs,\n\t    depending on filesystem, this is now up to 25% faster.\n\t5.  Mksquashfs help information reformatted and reorganised.\n\t6.  The Squashfs version and release date is now printed at kernel\n\t    boot-time or module insertion.  This addition will hopefully help\n\t    to reduce the growing problem where the Squashfs version supported\n\t    by a kernel is unknown and the kernel source is unavailable.\n        7.  New PERFORMANCE.README file.\n\t8.  New -2.0 mksquashfs option.\n\t9.  CHANGES file reorganised.\n\t10. README file reorganised, clarified and updated to include the 2.0\n\t    mksquashfs options.\n\t11. New patch for Linux 2.6.9.\n\t12. New patch for Linux 2.4.28.\n\n2.0r2\t29 AUG 2004\tWorkaround for kernel bug in kernels 2.6.8 and newer\n\t\t\tadded\n\n\t1. New patch for kernel 2.6.8.1.  This includes a workaround for a\n\t   kernel bug introduced in 2.6.7bk14, which is present in all later\n\t   versions of the kernel.  \n\n\t   If you're using a 2.6.8 kernel or later then you must use this\n\t   2.6.8.1 patch.  If you've experienced hangs or oopses using Squashfs\n\t   with a 2.6.8 or later kernel then you've hit this bug, and this\n\t   patch will fix it.\n\n\t   It is worth mentioning that this kernel bug potentially affects\n\t   other filesystems.  If you receive odd results with other\n\t   filesystems you may be experiencing this bug with that filesystem.\n\t   I submitted a patch but this has not yet gone into the\n\t   kernel, hopefully the bug will be fixed in later kernels. \n\n2.0\t13 JULY 2004\tA couple of new options, and some bug fixes\n\n\t1. New mksquashfs -all-root, -root-owned, -force-uid, and -force-gid\n\t   options.  These allow the uids/gids of files in the generated\n\t   filesystem to be specified, overriding the uids/gids in the\n\t   source filesystem.\n\t2. Initrds are now supported for kernels 2.6.x.\n\t3. amd64 bug fixes.  If you use an amd64, please read the README-AMD64\n\t   file.\n\t4. Check-data and gid bug fixes.  With 2.0-alpha when mounting 1.x\n\t   filesystems in certain cases file gids were corrupted.\n\t5. New patch for Linux 2.6.7.\n\n2.0-ALPHA\t21 MAY 2004\tFilesystem changes and compression improvements\n\n\t1. Squashfs 2.0 has added the concept of fragment blocks.\n           Files smaller than the file block size and optionally the\n\t   remainder of files that do not fit fully into a block (i.e. the\n\t   last 32K in a 96K file) are packed into shared fragments and\n\t   compressed together.  This achieves on average 5 - 20% better\n\t   compression than Squashfs 1.x.\n\t2. The maximum block size has been increased to 64K (in the ALPHA\n\t   version of Squashfs 2.0).\n\t3. The maximum number of UIDs has been increased to 256 (from 48 in\n\t   1.x).\n\t4. The maximum number of GIDs has been increased to 256 (from 15 in\n\t   1.x).\n\t5. Removal of sleep_on() function call in 2.6.x patch, to allow Squashfs\n\t   to work on the Fedora rc2 kernel.\n\t6. Numerous small bug fixes have been made.\n\n1.3r3\t18 JAN 2004\tThird release of 1.3, this adds a new mksquashfs option,\n\t\t\tsome bug fixes, and extra patches for new kernels\n\n\t1. New mksquashfs -ef exclude option.  This option reads the exclude\n\t   dirs/files from an exclude file, one exclude dir/file per line.  This\n\t   avoids the command line size limit when using the -e exclude option,\n\t2. When appending to existing filesystems, if mksquashfs experiences a\n\t   fatal error (e.g. out of space when adding to the destination), the\n\t   original filesystem is restored,\n\t3. Mksquashfs now builds standalone, without the kernel needing to be\n\t   patched.\n\t4. Bug fix in the kernel squashfs filesystem, where the pages being\n\t   filled were not kmapped.  This seems to only have caused problems\n\t   on an Apple G5,\n\t5. New patch for Linux 2.4.24,\n\n\t6. New patch for Linux 2.6.1, this replaces the patch for 2.6.0-test7.\n\n1.3r2\t14 OCT 2003\tSecond release of 1.3, bug fixes and extra patches for\n\t\t        new kernels\n\n\t1. Bug fix in routine that adds files to the filesystem being\n\t   generated in mksquashfs.  This bug was introduced in 1.3\n\t   (not enough testing...) when I rewrote it to handle files larger\n\t   than available memory.  This bug caused a SEGV, so if you've ever\n\t   got that, it is now fixed,\n\t2. Long running bug where ls -s and du reported wrong block size\n\t   fixed.  I'm pretty sure this used to work many kernel versions ago\n\t   (2.4.7) but it broke somewhere along the line since then,\n\t3. New patch for Linux 2.4.22,\n\t4. New patch for 2.6.0-test7, this replaces the patch for 2.6.0-test1.\n\n1.3\t29 JUL 2003\tFIFO/Socket support added plus optimisations and\n\t\t        improvements\n\n\t1. FIFOs and Socket inodes are now supported,\n\t2. Mksquashfs can now compress files larger than available\n\t   memory,\n\t3. File duplicate check routine optimised,\n\t4. Exit codes fixed in Mksquashfs,\n\t5. Patch for Linux 2.4.21,\n\t6. Patch for Linux 2.6.0-test1.  Hopefully, this will work for\n\t   the next few releases of 2.6.0-testx, otherwise, I'll be\n\t   releasing a lot of updates to the 2.6.0 patch...\n\n1.2\t13 MAR 2003\tAppend feature and new mksquashfs options added\n\n\tMksquashfs can now add to existing squashfs filesystems.  Three extra\n\toptions \"-noappend\", \"-keep-as-directory\", and \"root-becomes\"\n\thave been added.\n\n\tThe append option with file duplicate detection, means squashfs can be\n\tused as a simple versioning archiving filesystem. A squashfs\n\tfilesystem can be created with for example the linux-2.4.19 source.\n\tAppending the linux-2.4.20 source will create a filesystem with the\n\ttwo source trees, but only the changed files will take extra room,\n\tthe unchanged files will be detected as duplicates.\n\n\tSee the README file for usage changes.\n\n1.1b\t16 JAN 2003\tBug fix release\n\n\tFixed readpage deadlock bug.  This was a rare deadlock bug that\n\thappened when pushing pages into the page cache when using greater\n\tthan 4K blocks.  I never got this bug when I tested the filesystem,\n\tbut two people emailed me on the same day about the problem!\n\tI fixed it by using a page cache function that wasn't there when\n\tI originally did the work, which was nice :-)\n\n1.1\t8 JAN 2003\tAdded features\n\n\t1. Kernel squashfs can now mount different byte order filesystems.\n\t2. Additional features added to mksquashfs.  Mksquashfs now supports\n\t   exclude files and multiple source files/directories can be\n\t   specified.  A nopad option has also been added, which\n\t   informs mksquashfs not to pad filesystems to a multiple of 4K.\n\t   See README for mksquashfs usage changes.\n\t3. Greater than 2GB filesystems bug fix.  Filesystems greater than 2GB\n\t   can now be created.\n\n1.0c \t14 NOV 2002\tBug fix release\n\n\tFixed bugs with initrds and device nodes\n\n1.0 \t23 OCT 2002\tInitial release\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/COPYING",
    "content": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n\t\t    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n\t    How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) 19yy  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) 19yy name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/INSTALL",
    "content": "\t\t\tINSTALLING SQUASHFS\n\nThe squashfs3.3.tar.gz file contains this file, a README-3.3 file, another\nREADME file, an ACKNOWLEDGEMENTS file, a CHANGES file, the kernel-patches\ndirectory containing the squashfs patches, and the squashfs-tools directory\n(mksquashfs and unsquashfs).\n\n1. Patching the kernel\n----------------------\n\nThere are eleven kernel patch directories depending on your linux kernel\nversion.  If your kernel version isn't listed then try the patch for the nearest\nkernel listed.\n\nTo patch your kernel, cd into the top level directory, and run the \"patch\"\ncommand, e.g. assuming linux-2.6.22\n\n%cd /usr/src/linux-2.6.22\n%patch -p1 < location-of-squashfs/kernel-patches/linux-2.6.22/squashfs3.3-patch\n\nWhere \"location-of-squashfs\" is the path to the squashfs3.3 source directory.\n\nThe squashfs patches patch the relevant kernel files to add configure support,\ninitrd support, include files, and the squashfs directory under linux/fs/.\nOnce patched, the kernel must be reconfigured, with squashfs support turned on\n(either Y/M) to ensure that inflate support is built into the kernel.  The\nsquashfs kernel option can be found in the miscellaneous filesystems submenu\nnear the bottom of the filesystems submenu.\n\nThere are a set of options which are intended for use by embedded systems with\nlow memory.  At the \"Additional option for memory-constrained systems\" prompt,\nplease say NO unless you're using an embedded system!  Saying Y here allows you\nto specify cache sizes.\n\nThe \"Number of fragments cached\" prompt allows the number of fragments cached\nto be controlled.  By default SquashFS caches the last 3 fragments read from\nthe filesystem.  Increasing this amount may mean SquashFS has to re-read\nfragments less often from disk, at the expense of extra system memory.\nDecreasing this amount will mean SquashFS uses less memory at the expense of\nextra reads from disk.  Note there must be at least one cached fragment.\nAnything much more than three will probably not make much difference.\n\n2. Building squashfs tools\n--------------------------\n\nThe squashfs-tools directory contains the mksquashfs and unsquashfs programs.\nThese can be made by typing make.  The source files use a local copy of\nsquashfs_fs.h (included in the kernel patches) allowing the tools to be made\nwithout needing to patch the kernel.\n\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/OLD-READMEs/README-2.0",
    "content": "NOTE:  This the original README for version 2.0.  It is retained as it\ncontains information about the fragment design.  A description of the new 2.0\nmksquashfs options has been added to the main README file, and that\nfile should now be consulted for these.\n\n\tSQUASHFS 2.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2004 Phillip Lougher (plougher@users.sourceforge.net)\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to the final release of Squashfs version 2.0!  A lot of changes to the\nfilesystem have been made under the bonnet (hood).  Squashfs 2.0 uses fragment\nblocks and larger blocks (64K) to improve compression ratio by about 5 - 20%\nover Squashfs 1.0 depending on the files being compressed.  Using fragment\nblocks allows Squashfs 2.0 to achieve better compression than cloop and similar\ncompression to tgz files while retaining the I/O efficiency of a compressed\nfilesystem.\n\nDetailed changes:\n\n1. Squashfs 2.0 has added the concept of fragment blocks (see later discussion).\n   Files smaller than the file block size (64K in Squashfs 2.0) and optionally\n   the remainder of files that do not fit fully into a block (i.e. the last 32K\n   in a 96K file) are packed into shared fragments and compressed together.\n   This achieves on average 5 - 20% better compression than Squashfs 1.x.\n\n2. The maximum block size has been increased to 64K.\n\n3. The maximum number of UIDs has been increased to 256 (from 48 in 1.x).\n\n4. The maximum number of GIDs has been increased to 256 (from 15 in 1.x).\n\n5. New mksquashfs -all-root, -root-owned, -force-uid, and -force-gid\n   options.  These allow the uids/gids of files in the generated\n   filesystem to be specified, overriding the uids/gids in the\n   source filesystem.\n\n6. Initrds are now supported for kernels 2.6.x.\n\n7. Removal of sleep_on() function call in 2.6.x patch, to allow Squashfs\n   to work on the Fedora rc2 kernel.\n\n8. AMD64, check-data and gid bug fixes.\n\n9. Numerous small bug fixes have been made.\n\n10. New patch for Linux 2.6.7.\n\n\nNew Squashfs 2.0 options\n------------------------\n\n-noF or -noFragmentCompression\n\n\tDo not compress the fragments.  Added for compatibility with noI and\n\tnoD, probably not that useful.\n\n-no-fragments\n\n\tDo not use fragment blocks, and rather generate a filesystem\n\tsimilar to a Squashfs 1.x filesystem.  It will of course still\n\tbe a Squashfs 2.0 filesystem but without fragments, and so\n\tit won't be mountable on a Squashfs 1.x system.\n\n-always-use-fragments\n\n\tBy default only small files less than the block size are packed into\n\tfragment blocks.  The ends of files which do not fit fully into a block,\n\tare NOT by default packed into fragments.  To illustrate this, a\n\t100K file has an initial 64K block and a 36K remainder.  This\n\t36K remainder is not packed into a fragment by default.  This is\n\tbecause to do so leads to a 10 - 20% drop in sequential I/O\n\tperformance, as a disk head seek is needed to seek to the initial\n\tfile data and another disk seek is need to seek to the fragment\n\tblock.\n\n\tSpecify this option if you want file remainders to be packed into\n\tfragment blocks.  Doing so may increase the compression obtained\n\tBUT at the expense of I/O speed.\n\n-no-duplicates\n\n\tDo not detect duplicate files.\n\n-all-root\n-root-owned\n\n\tThese options (both do exactly the same thing), force all file\n\tuids/gids in the generated Squashfs filesystem to be root.\n\tThis allows root owned filesystems to be built without root access\n\ton the host machine.\n\n-force-uid uid\n\n\tThis option forces all files in the generated Squashfs filesystem to\n\tbe owned by the specified uid.  The uid can be specified either by\n\tname (i.e. \"root\") or by number.\n\n-force-gid gid\n\n\tThis option forces all files in the generated Squashfs filesystem to\n\tbe group owned by the specified gid.  The gid can be specified either by\n\tname (i.e. \"root\") or by number.\n\n\nCompression improvements example\n--------------------------------\n\nThe following is the compression results obtained compressing the 2.6.6\nlinux kernel source using CRAMFS, Cloop (with iso filesystem), Squashfs 1.3 and\nSquashfs 2.0 (results generated using big-endian filesystems).\n\nIn decreasing order of size:\n\n\tCRAMFS\t\t62791680 bytes (59.9M)\n\tSquashfs 1.x\t51351552 bytes (48.9M)\n\tCloop\t\t46118681 bytes (44.0M)\n\tSquashfs 2.0\t45604854 bytes (43.5M)\n\n\nThe Squashfs 1.x filesystem is 12.6% larger than the new 2.0 filesystem.\nThe cloop filesystem is 1.1% larger than the Squashfs 2.0 filesystem.\n\n\nFragment blocks in Squashfs 2.0\n-------------------------------\n\nSquashfs like all other compressed filesystems compresses files individually\non a block by block basis.  This is performed to allow mounting and\nde-compression of files on a block by block basis without requiring the entire\nfilesystem to be decompressed.  This is in contrast to data-based compression\nschemes which compress without understanding the underlying filesystem (i.e.\ncloop and tgz files) and which, therefore, do not compress files individually.\nEach approach has advantages and disadvantages, data-based systems have better\ncompression because compression is always performed at the maximum block size\n(64K in cloop) irrespective of the size of each file (which could be less than\nthe block size).  Compressed filesystems tend to be faster at I/O because\nthey understand the filesystem and therefore employ better caching stategies\nand read less un-needed data from the filesystem.\n\nFragment blocks in Squashfs 2.0 solves this problem by packing files (and\noptionally the ends of files) which are smaller than the block size into\nshared blocks, which are compressed together.  For example five files each of\n10K will be packed into one shared fragment of 50K and compressed together,\nrather than being compressed in five 10K blocks.\n\nThis scheme produces a hybrid filesystem, retaining the I/O efficiency\nof a compressed filesystem, while obtaining the compression efficiency\nof data-based schemes by compressing small files together.\n\n\nSquashfs 1.x and Squashfs 2.0 compatibility\n-------------------------------------------\n\nAppending to Squashfs 1.x filesystems is not supported.  If you wish to append\nto 1.x filesystems, then either use the original mksquashfs, or convert them\nto Squashfs 2.0 by mounting the filesystem and running the 2.0 mksquashfs\non the mounted filesystem.\n\nMounting Squashfs 1.x filesystems IS supported by the 2.0 kernel patch.\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/OLD-READMEs/README-2.1",
    "content": "\tSQUASHFS 2.1 - A squashed read-only filesystem for Linux\n\n\tCopyright 2004 Phillip Lougher (plougher@users.sourceforge.net)\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 2.1-r2.  Squashfs 2.1 introduces indexed\ndirectories which considerably speed up directory lookup (ls, find etc.) for\ndirectories which are greater than 8K in size.  All directories are now also\nsorted alphabetically which further speeds up directory lookup.  Many smaller\nimprovements have also been made to this release, please see the CHANGES file\nentry for detailed changes.\n\n1. DIRECTORY SPEED IMPROVEMENT EXAMPLES\n---------------------------------------\n\nTo give an indication of the directory speed improvements a number of test\nresults are shown here.  There is in addition a new PERFORMANCE.README file\nwhich gives details of I/O and lookup performance for Squashfs 2.1 against\nthe Zisofs, Cloop and CRAMFS filesystems.\n\nexample 1:\n\nFilesystems generated from a single directory of 72,784 files (2.6 MB\ndirectory size).  Each file is 10 bytes in size (the test is directory\nlookup and so the file size isn't an issue).  The ext3 uncompressed\ndirectory size is 288 MB (presumably because of one file per block).\n\nZisofs compressed size        153.50 MB\nCloop (isofs) compressed size 1.74 MB\nSquashfs2.1 compressed size   612 KB (0.60 MB)\n\nTime taken to perform \"ls -lR --color=always | cat > /dev/null\" on\nfilesystems mounted on hard disk.\n\nZisofs       35 minutes 7.895 seconds (User 7.868 secs, Sys 34 mins 5.621 secs)\nCloop        35 minutes 12.765 seconds (User 7.771 secs, Sys 34 mins 3.869 secs)\nSquashfs2.1  19 seconds (User 5.119 secs, Sys 14.547 secs)\n\nexample 2:\n\nFilesystems were generated from the Ubuntu Warty livecd (original uncompressed\nsize on ext3 is 1.4 GB).\n\nZisofs compressed size        589.81 MB\nCloop (isofs) compressed size 471.19 MB\nSquashfs2.0 compressed size   448.58 MB\nSquashfs2.1 compressed size   448.58 MB\n\nTime taken to perform \"ls -lR --color=always | cat > /dev/null\" on\nfilesystems mounted on hard disk.\n\nZisofs        49.875 seconds (User time 2.589 secs, Sys 11.194 secs)\nCloop         20.797 seconds (User time 2.706 secs, Sys 13.496 secs)\nSquashfs2.0   16.556 seconds (User time 2.424 secs, Sys 10.371 secs)\nSquashfs2.1   10.143 seconds (User time 2.475 secs, Sys 4.440 secs)\n\n\nNOTE: the usual warnings apply to these results, they are provided for\nillustrative purposes only, and due to different hardware and/or file data, you\nmay obtain different results.  As such the results are provided \"as is\" without\nany warranty (either express or implied) and you assume all risks as to their\nquality and accuracy.\n\n2. NEW MKSQUASHFS OPTIONS\n-------------------------\n\nThere is only one extra option \"-2.0\".  This tells mksquashfs to generate\na filesystem which is mountable with Squashfs version 2.0.\n\n3. APPENDING AND MOUNTING SQUASHFS 2.0 FILESYSTEMS\n--------------------------------------------------\n\nMounting 2.0 filesystems is supported by Squashfs 2.1.  In addition\nmksquashfs v2.1 can append to 2.0 filesystems, although the generated\nfilesystem will still be a 2.0 filesystem.\n\n4. DONATIONS\n------------\n\nIf you find Squashfs useful then please consider making a donation,\nparticularly if you use Squashfs in a commercial product.  Please consider\ngiving something back especially if you're making money from it.\n\nOff the Squashfs subject somewhat I'm currently looking for another\njob doing Linux kernel or filesystems work.  If you know of any such\nwork that can be performed from the UK then please get in touch.  Thanks.\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/OLD-READMEs/README-3.0",
    "content": "\tSQUASHFS 3.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2006 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to the first release of Squashfs version 3.0.  Squashfs 3.0 has the\nthe following improvements to 2.x.\n\n\t1. Filesystems are no longer limited to 4 GB.  In\n\t   theory 2^64 or 4 exabytes is now supported.\n\n\t2. Files are no longer limited to 4 GB.  In theory the maximum\n\t   file size is 4 exabytes.\n\n\t3. Metadata (inode table and directory tables) are no longer\n\t   restricted to 16 Mbytes.\n\n\t4. Hardlinks are now suppported.\n\n\t5. Nlink counts are now supported.\n\n\t6. Readdir now returns '.' and '..' entries.\n\n\t7. Special support for files larger than 256 MB has been added to\n\t   the Squashfs kernel code for faster read access.\n\n\t8. Inode numbers are now stored within the inode rather than being\n\t   computed from inode location on disk (this is not so much an\n\t   improvement, but a change forced by the previously listed\n\t   improvements).\n\nThere is a new Unsquashfs utility (in squashfs-tools) than can be used to\ndecompress a filesystem without mounting it.\n\nSquashfs 3.0 supports 2.x filesystems.  Support for 1.x filesystems\nwill be added in the future.\n\n1. UNSQUASHFS\n-------------\n\nUnsquashfs has the following options:\n\nSYNTAX: unsquashfs [-ls | -dest] filesystem\n\t-version\t\tprint version, licence and copyright information\n\t-info\t\t\tprint files as they are unsquashed\n\t-ls\t\t\tlist filesystem only\n\t-dest <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\nThe \"-ls\" option can be used to list the contents of a filesystem without\ndecompressing the filesystem data itself.\n\nThe \"-info\" option forces Unsquashfs to print each file as it is decompressed.\n\nThe \"-dest\" option specifies the directory that is used to decompress\nthe filesystem data.  If this option is not given then the filesystem is\ndecompressed to the directory \"squashfs-root\" in the current working directory.\n\nUnsquashfs can decompress 3.0 filesystems.  Support for 2.x and 1.x\nfilesystems will be added in the future.\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/OLD-READMEs/README-3.1",
    "content": "\tSQUASHFS 3.1 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2006 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.1-r2.  Squashfs 3.1 has major improvements to\nthe Squashfs tools (Mksquashfs and Unsquashfs), some major bug fixes, new\nkernel patches, and various other smaller improvements and bug fixes.\nPlease see the CHANGES file for a detailed list.\n\n1. MKSQUASHFS\n-------------\n\nMksquashfs has been rewritten and it is now multi-threaded.  It offers\nthe following improvements:\n\n1. Parallel compression.  By default as many compression and fragment\ncompression threads are created as there are available processors.\nThis significantly speeds up performance on SMP systems.\n\n2. File input and filesystem output is peformed in parallel on separate\nthreads to maximise I/O performance.  Even on single processor systems\nthis speeds up performance by at least 10%.\n\n3. Appending has been significantly improved, and files within the\nfilesystem being appended to are no longer scanned and checksummed.  This\nsignificantly improves append time for large filesystems.\n\n4. File duplicate checking has been optimised, and split into two separate\nphases.  Only files which are considered possible duplicates after the\nfirst phase are checksummed and cached in memory.\n\n5. The use of swap memory was found to significantly impact performance. The\namount of memory used to cache the file is now a command line option, by default\nthis is 512 Mbytes.\n\n1.1 NEW COMMAND LINE OPTIONS\n----------------------------\n\nThe new Mksquashfs program has a couple of extra command line options\nwhich can be used to control the new features:\n\n-processors <processors>\n\nThis specifies the number of processors used by Mksquashfs.\nBy default this is the number of available processors.\n\n-read_queue <size in Mbytes>\n\nThis specifies the size of the file input queue used by the reader thread.\nThis defaults to 64 Mbytes.\n\n-write_queue <size in Mbytes>\n\nThis specifies the size of the filesystem output queue used by the\nwriter thread.  It also specifies the maximum cache used in file\nduplicate detection (the output queue is shared between these tasks).\nThis defaults to 512 Mbytes.\n\n1.2 PERFORMANCE RESULTS\n-----------------------\n\nThe following results give an indication of the speed improvements.  Two\nexample filesystems were tested, a liveCD filesystem (about 1.8 Gbytes\nuncompressed), and my home directory consisting largely of text files\n(about 1.3 Gbytes uncompressed).  Tests were run on a single core\nand a dual core system.\n\nDual Core (AMDx2 3800+) system:\nSource directories on ext3.\n\nLiveCD, old mksquashfs:\n\nreal    11m48.401s\nuser    9m27.056s\nsys     0m15.281s\n\nLiveCD, new par_mksquashfs:\n\nreal    4m8.736s\nuser    7m11.771s\nsys     0m27.749s\n\n\"Home\", old mksquashfs:\n\nreal    4m34.360s\nuser    3m54.007s\nsys     0m32.155s\n\n\"Home\", new par_mksquashfs:\n\nreal    1m27.381s\nuser    2m7.304s\nsys     0m17.234s\n\nSingle Core PowerBook (PowerPC G4 1.5 GHz Ubuntu Linux)\nSource directories on ext3.\n\nLiveCD, old mksquashs:\n\nreal    11m38.472s\nuser    9m6.137s\nsys     0m23.799s\n\nLiveCD,  par_mksquashfs:\n\nreal    10m5.572s\nuser    8m59.921s\nsys     0m16.145s\n\n\"Home\", old mksquashfs:\n\nreal    3m42.298s\nuser    2m49.478s\nsys     0m13.675s\n\n\"Home\", new par_mksquashfs:\n\nreal    3m9.178s\nuser    2m50.699s\nsys     0m9.069s\n\nI'll be interested in any performance results obtained, especially from SMP\nmachines larger than my dual-core AMD box, as this will give an indication of\nthe scalability of the code.  Obviously, I'm also interested in any problems,\ndeadlocks, low performance etc.\n\n2. UNSQUASHFS\n-------------\n\nUnsquashfs now allows you to specify the filename or directory that is to be\nextracted from the Squashfs filesystem, rather than always extracting the\nentire filesystem.  It also has a new \"-force\" option, and all options can be\nspecified in a short form (-i rather than -info).\n\nThe Unsquashfs usage info is now:\n\nSYNTAX: ./unsquashfs [options] filesystem [directory or file to extract]\n\t-v[ersion]\t\tprint version, licence and copyright information\n\t-i[nfo]\t\t\tprint files as they are unsquashed\n\t-l[s]\t\t\tlist filesystem only\n\t-d[est] <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\t-f[orce]\t\tif file already exists then overwrite\n\nTo extract a subset of the filesystem, the filename or directory\ntree that is to be extracted can now be specified on the command line.  The\nfile/directory should be specified using the full path to the file/directory\nas it appears within the Squashfs filesystem.  The file/directory will also be\nextracted to that position within the specified destination directory.\n\nThe new \"-force\" option forces Unsquashfs to output to the destination\ndirectory even if files or directories already exist.  This allows you\nto update an existing directory tree, or to Unsquashfs to a partially\nfilled directory.  Without the \"-force\" option, Unsquashfs will\nrefuse to overwrite any existing files, or to create any directories if they\nalready exist.  This is done to protect data in case of mistakes, and\nso the \"-force\" option should be used with caution.\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/OLD-READMEs/README-3.2",
    "content": "\tSQUASHFS 3.2 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.2.  Squashfs 3.2 has support for NFS exporting,\nsome improvements to the Squashfs tools (Mksquashfs and Unsquashfs), some\nmajor bug fixes, new kernel patches, and various other smaller improvements\nand bug fixes.  Please see the CHANGES file for a detailed list.\n\n1. MKSQUASHFS\n-------------\n\nNew command line options:\n\n-no-exports\n\n\tSquashfs now supports NFS exports.  By default the additional\n\tinformation necessary is added to the filesystem by Mksquashfs.  If you\n\tdo not wish this extra information, then this option can be specified.\n\tThis will save a couple of bytes per file, and the filesystem\n\twill be identical to Squashfs 3.1.\n\n-no-progress\n\n\tMksquashfs by default now displays a progress bar. This option disables\n\tit.\n\n2. UNSQUASHFS\n-------------\n\n\tUnsquashfs now supports Squashfs 2.x filesystems.\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/OLD-READMEs/README-AMD64",
    "content": "Information for amd64 users\n---------------------------\n\nAll releases of Squashfs prior to 2.0 generate incorrect\nfilesystems on amd64 machines.  Filesystems created on amd64 machines work\ncorrectly on amd64 machines, but cannot be mounted on non-amd64 machines.\nLikewise, filesystems created on non-amd64 machines cannot be mounted on amd64\nmachines.  This bug is caused by the different size of the \"time_t\" definition\nused in SquashFS filesystem structures.\n\nThis bug is fixed in releases 2.0 and newer.  However, all amd64 filesystems\ngenerated by previous releases will not be mountable on amd64 machines\nwith newer releases.  If you have amd64 filesystems generated with mksquashfs\nversion 2.0-alpha or older, it is important that you recreate the filesystem.\nThis can be performed by mounting the filesystem using a kernel with the\noriginal patch (i.e. a 2.0-alpha or older patch) and running the NEW (i.e. this\nrelease) mksquashfs tool to create a new SquashFS filesystem.\n\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/PERFORMANCE.README",
    "content": "GENERAL INFORMATION ON PERFORMANCE TESTS\n----------------------------------------\n\nThe following performance tests were based on two file sets: the\nliveCD filesystem from the Ubuntu liveCD (Warty release), and the\nliveCD filesystem from the Damn Small Linux liveCD (release 0.8.4).\nThe Ubuntu liveCD filesystem was used to test filesystem performance\nfrom CDROM and hard disk for Zisofs, Cloop, Squashfs 2.0 and Squashfs2.1.\nCRAMFS filesystem performance could not be tested for this filesystem\nbacause it exceeds the maximum supported size of CRAMFS.  To test\nCRAMFS performance against Squashfs, the liveCD filesystem from\nDamn Small Linux was used.\n\nNOTE: the usual warnings apply to these results, they are provided for\nillustrative purposes only, and due to different hardware and/or file data, you\nmay obtain different results.  As such the results are provided \"as is\" without\nany warranty (either express or implied) and you assume all risks as to their\nquality and accuracy.\n\n1. Ubuntu liveCD performance tests\n\n   ext3 uncompressed size      1.4 GB\n   Zisofs compressed size      589.81 MB\n   Cloop compressed size       471.89 MB\n   Squashfs2.0 compressed size 448.58 MB\n   Squashfs2.1 compressed size 448.58 MB\n\n1.1 Performance tests from CDROM\n\n1.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  Zisofs       49.88 seconds (User 2.60 secs, Sys 11.19 secs)\n  Cloop        20.80 seconds (User 2.71 secs, Sys 13.50 secs)\n  Squashfs2.0  16.56 seconds (User 2.42 secs, Sys 10.37 secs)\n  Squashfs2.1  10.14 seconds (User 2.48 secs, Sys 4.44 secs)\n\n1.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  Zisofs       27 minutes 28.54 seconds (User 3.00 secs, Sys 1 min 4.80 secs)\n  Cloop        5 minutes 55.72 seconds (User 2.90 secs, Sys 3 min 37.90 secs)\n  Squashfs2.0  5 minutes 20.87 seconds (User 2.33 secs, Sys 56.98 secs)\n  Squashfs2.1  5 minutes 15.46 seconds (user 2.28 secs, Sys 51.12 secs)\n\n1.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n  Zisofs       101 minutes 29.65 seconds (User 5.33 secs, Sys  1 min 17.20 secs)\n  Cloop        35 minutes 27.51 seconds (user 5.93 secs, Sys 4 mins 30.23 secs)\n  Squashfs2.0  21 minutes 53.05 seconds (user 5.71 secs, Sys 2 mins 36.59 secs)\n  Squashfs2.1  21 minutes 46.99 seconds (User 5.80 secs, Sys 2 mins 31.88 secs)\n\n\n1.2 Performance tests from Hard disk\n\n1.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk \n\n  Zisofs       17.29 seconds (User 2.62 secs, Sys 11.08 secs)\n  Cloop        16.46 seconds (User 2.63 secs, Sys 13.41 secs)\n  Squashfs2.0  13.75 seconds (User 2.44 secs, Sys 11.00 secs)\n  Squashfs2.1  6.94 seconds (User 2.44 secs, Sys 4.48 secs)\n\n1.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk\n\n  Zisofs       1 minute 21.47 seconds (User 2.73 secs, Sys 54.44 secs)\n  Cloop        1 minute 34.06 seconds (user 2.85 secs, Sys 1 min 12.13 secs)\n  Squashfs2.0  1 minute 21.22 seconds (User 2.42 secs, Sys 56.21 secs)\n  Squashfs2.1  1 minute 15.46 seconds (User 2.36 secs, Sys 49.78 secs)\n\n1.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk\n\n  Zisofs       11 minutes 13.64 seconds (User 5.08 secs, Sys 52.62 secs)\n  Cloop        5 minutes 37.93 seconds (user 6 secs, Sys 2 mins 22.38 secs)\n  Squashfs2.0  5 minutes 7.11 seconds (user 5.63 secs, Sys 2 mins 35.23 secs)\n  Squashfs2.1  5 minutes 1.87 seconds (User 5.71 secs, Sys 2 mins 29.98 secs)\n\n\n2. Damn Small Linux liveCD performance tests\n\n   ext3 uncompressed size      126 MB\n   CRAMFS compressed size      52.19 MB\n   Squashfs2.0 compressed size 46.52 MB\n   Squashfs2.1 compressed size 46.52 MB\n\n2.1 Performance tests from CDROM\n\n2.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  CRAMFS       10.85 seconds (User 0.39 secs, Sys 0.98 secs)\n  Squashfs2.0  2.97 seconds (User 0.36 secs, Sys 2.15 secs)\n  Squashfs2.1  2.43 seconds (User 0.40 secs, Sys 1.42 secs)\n\n2.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  CRAMFS       55.38 seconds (User 0.34 secs, Sys 6.98 secs)\n  Squashfs2.0  35.99 seconds (User 0.30 secs, Sys 6.35 secs)\n  Squashfs2.1  33.83 seconds (User 0.26 secs, Sys 5.56 secs)\n\n2.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n\n  CRAMFS        3 minutes 1.68 seconds (User 0.54 secs, Sys 9.51 secs)\n  Squashfs2.0   1 minute 39.45 seconds (User 0.57 secs, Sys 13.14 secs)\n  Squashfs2.1   1 minute 38.41 seconds (User 0.58 secs, Sys 13.08 secs)\n\n2.2 Performance tests from Hard disk\n\n2.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk\n\n  CRAMFS       1.77 seconds (User 0.53 secs, Sys 1.21 secs)\n  Squashfs2.0  2.67 seconds (User 0.41 secs, Sys 2.25 secs)\n  Squashfs2.1  1.87 seconds (User 0.41 secs, Sys 1.46 secs)\n\n2.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk \n\n  CRAMFS       6.80 seconds (User 0.36 secs, Sys 6.02 secs)\n  Squashfs2.0  7.23 seconds (User 0.29 secs, Sys 6.62 secs)\n  Squashfs2.1  6.53 seconds (User 0.31 secs, Sys 5.82 secs)\n\n2.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk \n\n\n  CRAMFS       28.55 seconds (User 0.49 secs, Sys 6.49 secs)\n  Squashfs2.0  25.44 seconds (User 0.58 secs, Sys 13.17 secs)\n  Squashfs2.1  24.72 seconds (User 0.56 secs, Sys 13.15 secs)\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/README",
    "content": "\tSQUASHFS 3.3 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.3.  Please read the README-3.3 and CHANGES\nfiles for details of changes.\n\nSquashfs is a highly compressed read-only filesystem for Linux.\nIt uses zlib compression to compress both files, inodes and directories.\nInodes in the system are very small and all blocks are packed to minimise\ndata overhead. Block sizes greater than 4K are supported up to a maximum\nof 1Mbytes (default block size 128K).\n\nSquashfs is intended for general read-only filesystem use, for archival\nuse (i.e. in cases where a .tar.gz file may be used), and in constrained\nblock device/memory systems (e.g. embedded systems) where low overhead is\nneeded.\n\n1. SQUASHFS OVERVIEW\n--------------------\n\n1. Data, inodes and directories are compressed.\n\n2. Squashfs stores full uid/gids (32 bits), and file creation time.\n\n3. In theory files up to 2^64 bytes are supported.  In theory filesystems can\n   be up to 2^64 bytes.\n\n4. Inode and directory data are highly compacted, and packed on byte\n   boundaries.  Each compressed inode is on average 8 bytes in length\n   (the exact length varies on file type, i.e. regular file, directory,\n   symbolic link, and block/char device inodes have different sizes).\n\n5. Squashfs can use block sizes up to 1Mbyte (the default size is 128K).\n   Using 128K blocks achieves greater compression ratios than the normal\n   4K block size.\n\n6. File duplicates are detected and removed.\n\n7. Both big and little endian architectures are supported.  Squashfs can\n   mount filesystems created on different byte order machines.\n\n\n2. USING SQUASHFS\n-----------------\n\nSquashfs filesystems should be mounted with 'mount' with the filesystem type\n'squashfs'.  If the filesystem is on a block device, the filesystem can be\nmounted directly, e.g.\n\n%mount -t squashfs /dev/sda1 /mnt\n\nWill mount the squashfs filesystem on \"/dev/sda1\" under the directory \"/mnt\".\n\nIf the squashfs filesystem has been written to a file, the loopback device\ncan be used to mount it (loopback support must be in the kernel), e.g.\n\n%mount -t squashfs image /mnt -o loop\n\nWill mount the squashfs filesystem in the file \"image\" under\nthe directory \"/mnt\".\n\n\n3. MKSQUASHFS\n-------------\n\n3.1 Mksquashfs options and overview.\n------------------------------------\n\nAs squashfs is a read-only filesystem, the mksquashfs program must be used to\ncreate populated squashfs filesystems.\n\nSYNTAX:mksquashfs source1 source2 ...  dest [options] [-e list of exclude\ndirs/files]\n\nOptions are\n-version                print version, licence and copyright message\n-recover <name>         recover filesystem data using recovery file <name>\n-no-recovery            don't generate a recovery file\n-info                   print files written to filesystem\n-no-exports             don't make the filesystem exportable via NFS\n-no-progress            don't display the progress bar\n-no-sparse              don't detect sparse files\n-b <block_size>         set data block to <block_size>.  Default 131072 bytes\n-processors <number>    Use <number> processors.  By default will use number of\n                        processors available\n-read-queue <size>      Set input queue to <size> Mbytes.  Default 64 Mbytes\n-write-queue <size>     Set output queue to <size> Mbytes.  Default 512 Mbytes\n-noI                    do not compress inode table\n-noD                    do not compress data blocks\n-noF                    do not compress fragment blocks\n-no-fragments           do not use fragments\n-always-use-fragments   use fragment blocks for files larger than block size\n-no-duplicates          do not perform duplicate checking\n-noappend               do not append to existing filesystem\n-keep-as-directory      if one source directory is specified, create a root\n                        directory containing that directory, rather than the\n                        contents of the directory\n-root-becomes <name>    when appending source files/directories, make the\n                        original root become a subdirectory in the new root\n                        called <name>, rather than adding the new source items\n                        to the original root\n-all-root               make all files owned by root\n-force-uid uid          set all file uids to uid\n-force-gid gid          set all file gids to gid\n-le                     create a little endian filesystem\n-be                     create a big endian filesystem\n-nopad                  do not pad filesystem to a multiple of 4K\n-check_data             add checkdata for greater filesystem checks\n-root-owned             alternative name for -all-root\n-noInodeCompression     alternative name for -noI\n-noDataCompression      alternative name for -noD\n-noFragmentCompression  alternative name for -noF\n-sort <sort_file>       sort files according to priorities in <sort_file>.  One\n                        file or dir with priority per line.  Priority -32768 to\n                        32767, default priority 0\n-ef <exclude_file>      list of exclude dirs/files.  One per line\n-wildcards              Allow extended shell wildcards (globbing) to be used in\n                        exclude dirs/files\n-regex                  Allow POSIX regular expressions to be used in exclude\n                        dirs/files\n\nSource1 source2 ... are the source directories/files containing the\nfiles/directories that will form the squashfs filesystem.  If a single\ndirectory is specified (i.e. mksquashfs source output_fs) the squashfs\nfilesystem will consist of that directory, with the top-level root\ndirectory corresponding to the source directory.\n\nIf multiple source directories or files are specified, mksquashfs will merge\nthe specified sources into a single filesystem, with the root directory\ncontaining each of the source files/directories.  The name of each directory\nentry will be the basename of the source path.   If more than one source\nentry maps to the same name, the conflicts are named xxx_1, xxx_2, etc. where\nxxx is the original name.\n\nTo make this clear, take two example directories.  Source directory\n\"/home/phillip/test\" contains  \"file1\", \"file2\" and \"dir1\".\nSource directory \"goodies\" contains \"goodies1\", \"goodies2\" and \"goodies3\".\n\nusage example 1:\n\n%mksquashfs /home/phillip/test output_fs\n\nThis will generate a squashfs filesystem with root entries\n\"file1\", \"file2\" and \"dir1\".\n\nexample 2:\n\n%mksquashfs /home/phillip/test goodies output_fs\n\nThis will create a squashfs filesystem with the root containing\nentries \"test\" and \"goodies\" corresponding to the source\ndirectories \"/home/phillip/test\" and \"goodies\".\n\nexample 3:\n\n%mksquashfs /home/phillip/test goodies test output_fs\n\nThis is the same as the previous example, except a third\nsource directory \"test\" has been specified.  This conflicts\nwith the first directory named \"test\" and will be renamed \"test_1\".\n\nMultiple sources allow filesystems to be generated without needing to\ncopy all source files into a common directory.  This simplifies creating\nfilesystems.\n\nThe -keep-as-directory option can be used when only one source directory\nis specified, and you wish the root to contain that directory, rather than\nthe contents of the directory.  For example:\n\nexample 4:\n\n%mksquashfs /home/phillip/test output_fs -keep-as-directory\n\nThis is the same as example 1, except for -keep-as-directory.\nThis will generate a root directory containing directory \"test\",\nrather than the \"test\" directory contents \"file1\", \"file2\" and \"dir1\".\n\nThe Dest argument is the destination where the squashfs filesystem will be\nwritten.  This can either be a conventional file or a block device.  If the file\ndoesn't exist it will be created, if it does exist and a squashfs\nfilesystem exists on it, mksquashfs will append.  The -noappend option will\nwrite a new filesystem irrespective of whether an existing filesystem is\npresent.\n\n3.2 Changing compression defaults used in mksquashfs\n----------------------------------------------------\n\nThere are a large number of options that can be used to control the \ncompression in mksquashfs.  By and large the defaults are the most\noptimum settings and should only be changed in exceptional circumstances!\n\nThe -noI, -noD and -noF options (also -noInodeCompression, -noDataCompression\nand -noFragmentCompression) can be used to force mksquashfs to not compress\ninodes/directories, data and fragments respectively.  Giving all options\ngenerates an uncompressed filesystem.\n\nThe -no-fragments tells mksquashfs to not generate fragment blocks, and rather\ngenerate a filesystem similar to a Squashfs 1.x filesystem.  It will of course\nstill be a Squashfs 3.1 filesystem but without fragments, and so it won't be\nmountable on a Squashfs 1.x system.\n\nThe -always-use-fragments option tells mksquashfs to always generate\nfragments for files irrespective of the file length.  By default only small\nfiles less than the block size are packed into fragment blocks.  The ends of\nfiles which do not fit fully into a block, are NOT by default packed into\nfragments.  To illustrate this, a 100K file has an initial 64K block and a 36K\nremainder.  This 36K remainder is not packed into a fragment by default.  This\nis because to do so leads to a 10 - 20% drop in sequential I/O performance, as a\ndisk head seek is needed to seek to the initial file data and another disk seek\nis need to seek to the fragment block.  Specify this option if you want file\nremainders to be packed into fragment blocks.  Doing so may increase the\ncompression obtained BUT at the expense of I/O speed.\n\nThe -no-duplicates option tells mksquashfs to not check the files being\nadded to the filesystem for duplicates.  This can result in quicker filesystem\ngeneration and appending although obviously compression will suffer badly if\nthere is a lot of duplicate files.\n\nThe -b option allows the block size to be selected, both \"K\" and \"M\" postfixes\nare supported, this can be either 4K, 8K, 16K, 32K, 64K, 128K, 256K, 512K or\n1M bytes.\n\n3.3 Specifying the UIDs/GIDs used in the filesystem\n---------------------------------------------------\n\nBy default files in the generated filesystem inherit the UID and GID ownership\nof the original file.  However,  mksquashfs provides a number of options which\ncan be used to override the ownership.\n\nThe options -all-root and -root-owned (both do exactly the same thing) force all\nfile uids/gids in the generated Squashfs filesystem to be root.  This allows\nroot owned filesystems to be built without root access on the host machine.\n\nThe \"-force-uid uid\"  option forces all files in the generated Squashfs\nfilesystem to be owned by the specified uid.  The uid can be specified either by\nname (i.e. \"root\") or by number.\n\nThe \"-force-gid gid\" option forces all files in the generated Squashfs\nfilesystem to be group owned by the specified gid.  The gid can be specified\neither by name (i.e. \"root\") or by number.\n\n3.4 Excluding files from the filesystem\n---------------------------------------\n\nFor new wildcard exclude file handling please refer to the README-3.3 file.\nThe older exclude functionality described here is used if the -wildcard\nor -regex options are not specified.\n\nThe -e and -ef options allow files/directories to be specified which are\nexcluded from the output filesystem.  The -e option takes the exclude\nfiles/directories from the command line, the -ef option takes the\nexlude files/directories from the specified exclude file, one file/directory\nper line. If an exclude file/directory is absolute (i.e. prefixed with /, ../,\nor ./) the entry is treated as absolute, however, if an exclude file/directory\nis relative, it is treated as being relative to each of the sources in turn,\ni.e.\n\n%mksquashfs /tmp/source1 source2  output_fs -e ex1 /tmp/source1/ex2 out/ex3\n\nWill generate exclude files /tmp/source1/ex2, /tmp/source1/ex1, source2/ex1,\n/tmp/source1/out/ex3 and source2/out/ex3.\n\nThe -e and -ef exclude options are usefully used in archiving the entire\nfilesystem, where it is wished to avoid archiving /proc, and the filesystem\nbeing generated, i.e.\n\n%mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh\n\nMultiple -ef options can be specified on the command line, and the -ef\noption can be used in conjuction with the -e option.\n\n3.5 Appending to squashfs filesystems\n-------------------------------------\n\nRunning squashfs with the destination directory containing an existing\nfilesystem will add the source items to the existing filesystem.  By default,\nthe source items are added to the existing root directory.\n\nTo make this clear... An existing filesystem \"image\" contains root entries\n\"old1\", and \"old2\".  Source directory \"/home/phillip/test\" contains  \"file1\",\n\"file2\" and \"dir1\".\n\nexample 1:\n\n%mksquashfs /home/phillip/test image\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", \"file1\", \"file2\" and\n\"dir1\"\n\nexample 2:\n\n%mksquashfs /home/phillip/test image -keep-as-directory\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", and \"test\".\nAs shown in the previous section, for single source directories\n'-keep-as-directory' adds the source directory rather than the\ncontents of the directory.\n\nexample 3:\n\n%mksquashfs /home/phillip/test image -keep-as-directory -root-becomes\noriginal-root\n\nWill create a new \"image\" with root entries \"original-root\", and \"test\".  The\n'-root-becomes' option specifies that the original root becomes a subdirectory\nin the new root, with the specified name.\n\nThe append option with file duplicate detection, means squashfs can be\nused as a simple versioning archiving filesystem. A squashfs filesystem can\nbe created with for example the linux-2.4.19 source.  Appending the linux-2.4.20\nsource will create a filesystem with the two source trees, but only the\nchanged files will take extra room, the unchanged files will be detected as\nduplicates.\n\n3.6 Miscellaneous options\n-------------------------\n\nThe -info option displays the files/directories as they are compressed and\nadded to the filesystem.  The original uncompressed size of each file\nis printed, along with DUPLICATE if the file is a duplicate of a\nfile in the filesystem.\n\nThe -le and -be options can be used to force mksquashfs to generate a little\nendian or big endian filesystem.  Normally mksquashfs will generate a\nfilesystem in the host byte order.  Squashfs, for portability, will\nmount different ordered filesystems (i.e. it can mount big endian filesystems\nrunning on a little endian machine), but these options can be used for\ngreater optimisation.\n\nThe -nopad option informs mksquashfs to not pad the filesystem to a 4K multiple.\nThis is performed by default to enable the output filesystem file to be mounted\nby loopback, which requires files to be a 4K multiple.  If the filesystem is\nbeing written to a block device, or is to be stored in a bootimage, the extra\npad bytes are not needed.\n\n4. UNSQUASHFS\n-------------\n\nUnsquashfs allows you to decompress and extract a Squashfs filesystem without\nmounting it.  It can extract the entire filesystem, or a specific\nfile or directory.\n\nThe Unsquashfs usage info is:\n\nSYNTAX: unsquashfs [options] filesystem [directories or files to extract]\n        -v[ersion]              print version, licence and copyright information\n        -i[nfo]                 print files as they are unsquashed\n        -li[nfo]                print files as they are unsquashed with file\n                                attributes (like ls -l output)\n        -l[s]                   list filesystem, but don't unsquash\n        -ll[s]                  list filesystem with file attributes (like\n                                ls -l output), but don't unsquash\n        -d[est] <pathname>      unsquash to <pathname>, default \"squashfs-root\"\n        -f[orce]                if file already exists then overwrite\n        -s[tat]                 display filesystem superblock information\n        -e[f] <extract file>    list of directories or files to extract.\n                                One per line\n        -r[egex]                treat extract names as POSIX regular expressions\n                                rather than use the default shell wildcard\n                                expansion (globbing)\n\nTo extract a subset of the filesystem, the filenames or directory\ntrees that are to be extracted can now be specified on the command line.  The\nfiles/directories should be specified using the full path to the\nfiles/directories as they appear within the Squashfs filesystem.  The\nfiles/directories will also be extracted to those positions within the specified\ndestination directory.\n\nPlease refer to the README-3.3 file for a description of the new wildcard\npattern matching functionality for extract files.\n\nThe \"-ls\" option can be used to list the contents of a filesystem without\ndecompressing the filesystem data itself.\n\nThe \"-info\" option forces Unsquashfs to print each file as it is decompressed.\n\nThe \"-dest\" option specifies the directory that is used to decompress\nthe filesystem data.  If this option is not given then the filesystem is\ndecompressed to the directory \"squashfs-root\" in the current working directory.\n\nThe \"-force\" option forces Unsquashfs to output to the destination\ndirectory even if files or directories already exist.  This allows you\nto update an existing directory tree, or to Unsquashfs to a partially\nfilled directory.  Without the \"-force\" option, Unsquashfs will\nrefuse to overwrite any existing files, or to create any directories if they\nalready exist.  This is done to protect data in case of mistakes, and\nso the \"-force\" option should be used with caution.\n\nUnsquashfs can decompress all Squashfs filesystem versions, 1.x, 2.x and 3.x\nfilesystems.\n\n5. FILESYSTEM LAYOUT\n--------------------\n\nBrief filesystem design notes follow for the original 1.x filesystem\nlayout.  A description of the 2.x and 3.x filesystem layouts will be written\nsometime!\n\nA squashfs filesystem consists of five parts, packed together on a byte\nalignment:\n\n\t ---------------\n\t|  superblock \t|\n\t|---------------|\n\t|     data\t|\n\t|    blocks\t|\n\t|---------------|\n\t|    inodes\t|\n\t|---------------|\n\t|   directories\t|\n\t|---------------|\n\t|    uid/gid\t|\n\t|  lookup table\t|\n\t ---------------\n\nCompressed data blocks are written to the filesystem as files are read from\nthe source directory, and checked for duplicates.  Once all file data has been\nwritten the completed inode, directory and uid/gid lookup tables are written.\n\n5.1 Metadata\n------------\n\nMetadata (inodes and directories) are compressed in 8Kbyte blocks.  Each\ncompressed block is prefixed by a two byte length, the top bit is set if the\nblock is uncompressed.  A block will be uncompressed if the -noI option is set,\nor if the compressed block was larger than the uncompressed block.\n\nInodes are packed into the metadata blocks, and are not aligned to block\nboundaries, therefore inodes overlap compressed blocks.  An inode is\nidentified by a two field tuple <start address of compressed block : offset\ninto de-compressed block>.\n\nInode contents vary depending on the file type.  The base inode consists of:\n\n\tbase inode:\n\t\tInode type\n\t\tMode\n\t\tuid index\n\t\tgid index\n\nThe inode type is 4 bits in size, and the mode is 12 bits.\n\nThe uid and gid indexes are 4 bits in length.  Ordinarily, this will allow 16\nunique indexes into the uid table.  To minimise overhead, the uid index is\nused in conjunction with the spare bit in the file type to form a 48 entry\nindex as follows:\n\n\tinode type 1 - 5: uid index = uid\n\tinode type 5 -10: uid index = 16 + uid\n\tinode type 11 - 15: uid index = 32 + uid\n\nIn this way 48 unique uids are supported using 4 bits, minimising data inode\noverhead.  The 4 bit gid index is used to index into a 15 entry gid table.\nGid index 15 is used to indicate that the gid is the same as the uid.\nThis prevents the 15 entry gid table filling up with the common case where\nthe uid/gid is the same.\n\nThe data contents of symbolic links are stored immediately after the symbolic\nlink inode, inside the inode table.  This allows the normally small symbolic\nlink to be compressed as part of the inode table, achieving much greater\ncompression than if the symbolic link was compressed individually.\n\nSimilarly, the block index for regular files is stored immediately after the\nregular file inode.  The block index is a list of block lengths (two bytes\neach), rather than block addresses, saving two bytes per block.  The block\naddress for a given block is computed by the summation of the previous\nblock lengths.  This takes advantage of the fact that the blocks making up a\nfile are stored contiguously in the filesystem.  The top bit of each block\nlength is set if the block is uncompressed, either because the -noD option is\nset, or if the compressed block was larger than the uncompressed block.\n\n5.2 Directories\n---------------\n\nLike inodes, directories are packed into the metadata blocks, and are not\naligned on block boundaries, therefore directories can overlap compressed\nblocks.  A directory is, again, identified by a two field tuple\n<start address of compressed block containing directory start : offset\ninto de-compressed block>.\n\nDirectories are organised in a slightly complex way, and are not simply\na list of file names and inode tuples.  The organisation takes advantage of the\nobservation that in most cases, the inodes of the files in the directory\nwill be in the same compressed metadata block, and therefore, the\ninode tuples will have the same start block.\n\nDirectories are therefore organised in a two level list, a directory\nheader containing the shared start block value, and a sequence of\ndirectory entries, each of which share the shared start block.  A\nnew directory header is written once/if the inode start block\nchanges.  The directory header/directory entry list is repeated as many times\nas necessary.  The organisation is as follows:\n\n\tdirectory_header:\n\t\tcount (8 bits)\n\t\tinode start block (24 bits)\n\t\t\n\t\tdirectory entry: * count\n\t\t\tinode offset (13 bits)\n\t\t\tinode type (3 bits)\n\t\t\tfilename size (8 bits)\n\t\t\tfilename\n\t\t\t\nThis organisation saves on average 3 bytes per filename.\n\n5.3 File data\n-------------\n\nFile data is compressed on a block by block basis and written to the\nfilesystem.  The filesystem supports up to 32K blocks, which achieves\ngreater compression ratios than the Linux 4K page size.\n\nThe disadvantage with using greater than 4K blocks (and the reason why\nmost filesystems do not), is that the VFS reads data in 4K pages.\nThe filesystem reads and decompresses a larger block containing that page\n(e.g. 32K).  However, only 4K can be returned to the VFS, resulting in a\nvery inefficient filesystem, as 28K must be thrown away.   Squashfs,\nsolves this problem by explicitly pushing the extra pages into the page\ncache.\n\n\n6. AUTHOR INFO\n--------------\n\nSquashfs was written by Phillip Lougher, email phillip@lougher.org.uk,\nin Chepstow, Wales, UK.   If you like the program, or have any problems,\nthen please email me, as it's nice to get feedback!\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/README-3.3",
    "content": "\tSQUASHFS 3.3 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to another release of Squashfs.  This is the 22nd release in just\nover five years of work.  Squashfs 3.3 has lots of nice improvements,\nboth to the filesystem itself (bigger blocks, and sparse files), but\nalso to the Squashfs-tools Mksquashfs and Unsquashfs.  As usual the\nCHANGES file has a detailed list of all the improvements.\n\nFollowing is a description of the changes to the Squashfs tools, usage\nguides to the new options, and a summary of the new options.\n\n1. MKSQUASHFS - EXTENDED EXCLUDE FILE HANDLING\n----------------------------------------------\n\n1. Extended wildcard pattern matching now supported in exclude files\n\n  Enabled by specifying -wildcard option\n\n  Supports both anchored and non-anchored exclude files.\n\n1.1 Anchored excludes\n\n  Similar to existing exclude files except with wildcards.  Exclude\n  file matches from root of source directories.\n\n  Examples:\n\n  1. mksquashfs example image.sqsh -e 'test/*.gz'\n\n     Exclude all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. mksquashfs example image.sqsh -e '*/[Tt]est/example*'\n\n     Exclude all files beginning with \"example\" inside directories called\n     \"Test\" or \"test\", that occur inside any top level directory.\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -e 'test/!(*data*).gz'\n\n     Exclude all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\n1.2 Non-anchored excludes\n\n  By default excludes match from the top level directory, but it is\n  often useful to exclude a file matching anywhere in the source directories.\n  For this non-anchored excludes can be used, specified by pre-fixing the\n  exclude with \"...\".\n\n  Examples:\n\n  1. mksquashfs example image.sqsh -e '... *.gz'\n\n     Exclude files matching \"*.gz\" anywhere in the source directories.\n     For example this will match \"example.gz\", \"test/example.gz\", and\n     \"test/test/example.gz\".\n\n  2. mksquashfs example image.sqsh -e '... [Tt]est/*.gz'\n\n     Exclude files matching \"*.gz\" inside directories called \"Test\" or\n     \"test\" that occur anywhere in the source directories.\n\n  Again, using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -e '... !(*data*).gz'\n\n     Exclude all files matching \"*.gz\" anywhere in the source directories,\n     except those with \"data\" in the name.\n\n2. Regular expression pattern matching now supported in exclude files\n\n  Enabled by specifying -regex option.  Identical behaviour to wild\ncard pattern matching, except patterns are considered to be regular\nexpressions.\n\n  Supports both anchored and non-anchored exclude files.\n\n\n2. MKSQUASHFS - NEW RECOVERY FILE FEATURE\n-----------------------------------------\n\nRecovery files are now created when appending to existing Squashfs\nfilesystems.  This allows the original filesystem to be recovered\nif Mksquashfs aborts unexpectedly (i.e. power failure).\n\nThe recovery files are called squashfs_recovery_xxx_yyy, where\n\"xxx\" is the name of the filesystem being appended to, and \"yyy\" is a\nnumber to guarantee filename uniqueness (the PID of the parent Mksquashfs\nprocess).\n\nNormally if Mksquashfs exits correctly the recovery file is deleted to\navoid cluttering the filesystem.  If Mksquashfs aborts, the \"-recover\"\noption can be used to recover the filesystem, giving the previously\ncreated recovery file as a parameter, i.e.\n\nmksquashfs dummy image.sqsh -recover squashfs_recovery_image.sqsh_1234\n\nThe writing of the recovery file can be disabled by specifying the\n\"-no-recovery\" option.\n\n\n3. UNSQUASHFS - EXTENDED EXTRACT FILE HANDLING\n----------------------------------------------\n\n1. Multiple extract files can now be specified on the command line, and the\nfiles/directories to be extracted can now also be given in a file.\n\nTo specify a file containing the extract files use the \"-e[f]\" option.\n\n2. Extended wildcard pattern matching now supported in extract files\n\n  Enabled by default.  Similar to existing extract files except with\nwildcards.\n\n  Examples:\n\n  1. unsquashfs image.sqsh 'test/*.gz'\n\n     Extract all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. unsquashfs image.sqsh '[Tt]est/example*'\n\n     Extract all files beginning with \"example\" inside top level directories\n     called \"Test\" or \"test\".\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. unsquashfs image.sqsh 'test/!(*data*).gz'\n\n     Extract all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\n3. Regular expression pattern matching now supported in extract files\n\n  Enabled by specifying -r[egex] option.  Identical behaviour to wild\ncard pattern matching, except patterns are considered to be regular\nexpressions.\n\n4. UNSQUASHFS - EXTENDED FILENAME PRINTING\n------------------------------------------\n\nFilename printing has been enhanced and Unquashfs can now display filenames\nwith file attributes ('ls -l' style output).\n\nNew options:\n\n  -ll[s]\n\n   list filesystem with file attributes, but don't unsquash\n\n  -li[nfo]\n\n   print files as they are unsquashed with file attributes\n\n\n5. UNSQUASHFS - MISCELLANEOUS OPTIONS\n-------------------------------------\n\n   -s[tat]\n\n   Display the filesystem superblock information.  This is useful to\n   discover the filesystem version, byte ordering, whether it has an\n   NFS export table, and what options were used to compress\n   the filesystem.\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.10/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.10/fs/Kconfig linux-2.6.10-squashfs3.3/fs/Kconfig\n--- linux-2.6.10/fs/Kconfig\t2004-12-24 21:34:58.000000000 +0000\n+++ linux-2.6.10-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:24.000000000 +0000\n@@ -1266,6 +1266,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.10/fs/Makefile linux-2.6.10-squashfs3.3/fs/Makefile\n--- linux-2.6.10/fs/Makefile\t2004-12-24 21:34:58.000000000 +0000\n+++ linux-2.6.10-squashfs3.3/fs/Makefile\t2007-11-01 05:06:24.000000000 +0000\n@@ -51,6 +51,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.10/fs/squashfs/inode.c linux-2.6.10-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.10/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.10-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:11:22.000000000 +0000\n@@ -0,0 +1,2215 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct super_block *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static struct super_block *squashfs_get_sb(struct file_system_type *,int, const char *, void *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static void *kzalloc(int size, int flags)\n+{\n+\tvoid *buff = kmalloc(size, flags);\n+\n+\tif(buff != NULL)\n+\t\tmemset(buff, 0, size);\n+\n+\treturn buff;\n+}\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tdown(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tup(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tup(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tdown(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tdown(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tup(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tdown(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tup(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tup(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tup(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tinit_MUTEX(&msblk->read_data_mutex);\n+\tinit_MUTEX(&msblk->read_page_mutex);\n+\tinit_MUTEX(&msblk->block_cache_mutex);\n+\tinit_MUTEX(&msblk->fragment_mutex);\n+\tinit_MUTEX(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tup(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tup(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tdown(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tup(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tup(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.10/fs/squashfs/Makefile linux-2.6.10-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.10/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.10-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.10/fs/squashfs/squashfs2_0.c linux-2.6.10-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.10/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.10-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-31 22:57:55.000000000 +0000\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.10/fs/squashfs/squashfs.h linux-2.6.10-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.10/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.10-squashfs3.3/fs/squashfs/squashfs.h\t2007-11-01 02:13:29.000000000 +0000\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern struct address_space_operations squashfs_symlink_aops;\n+extern struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.10/include/linux/squashfs_fs.h linux-2.6.10-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.10/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.10-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.10/include/linux/squashfs_fs_i.h linux-2.6.10-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.10/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.10-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.10/include/linux/squashfs_fs_sb.h linux-2.6.10-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.10/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.10-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-10-31 14:28:58.000000000 +0000\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct semaphore\t\tread_data_mutex;\n+\tstruct semaphore\t\tread_page_mutex;\n+\tstruct semaphore\t\tblock_cache_mutex;\n+\tstruct semaphore\t\tfragment_mutex;\n+\tstruct semaphore\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.10/init/do_mounts_rd.c linux-2.6.10-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.10/init/do_mounts_rd.c\t2004-12-24 21:35:23.000000000 +0000\n+++ linux-2.6.10-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:24.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.12/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.12/fs/Kconfig linux-2.6.12-squashfs3.3/fs/Kconfig\n--- linux-2.6.12/fs/Kconfig\t2005-06-17 20:48:29.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:24.000000000 +0000\n@@ -1171,6 +1171,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.12/fs/Makefile linux-2.6.12-squashfs3.3/fs/Makefile\n--- linux-2.6.12/fs/Makefile\t2005-06-17 20:48:29.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/fs/Makefile\t2007-11-01 05:06:24.000000000 +0000\n@@ -52,6 +52,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.12/fs/squashfs/inode.c linux-2.6.12-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.12/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:11:08.000000000 +0000\n@@ -0,0 +1,2215 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct super_block *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static struct super_block *squashfs_get_sb(struct file_system_type *,int, const char *, void *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static void *kzalloc(int size, int flags)\n+{\n+\tvoid *buff = kmalloc(size, flags);\n+\n+\tif(buff != NULL)\n+\t\tmemset(buff, 0, size);\n+\n+\treturn buff;\n+}\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tdown(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tup(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tup(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tdown(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tdown(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tup(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tdown(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tup(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tup(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tup(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tinit_MUTEX(&msblk->read_data_mutex);\n+\tinit_MUTEX(&msblk->read_page_mutex);\n+\tinit_MUTEX(&msblk->block_cache_mutex);\n+\tinit_MUTEX(&msblk->fragment_mutex);\n+\tinit_MUTEX(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tup(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tup(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tdown(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tup(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tup(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.12/fs/squashfs/Makefile linux-2.6.12-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.12/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.12/fs/squashfs/squashfs2_0.c linux-2.6.12-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.12/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-31 22:57:55.000000000 +0000\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.12/fs/squashfs/squashfs.h linux-2.6.12-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.12/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/fs/squashfs/squashfs.h\t2007-11-01 02:13:23.000000000 +0000\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern struct address_space_operations squashfs_symlink_aops;\n+extern struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.12/include/linux/squashfs_fs.h linux-2.6.12-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.12/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.12/include/linux/squashfs_fs_i.h linux-2.6.12-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.12/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.12/include/linux/squashfs_fs_sb.h linux-2.6.12-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.12/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-10-31 14:28:58.000000000 +0000\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct semaphore\t\tread_data_mutex;\n+\tstruct semaphore\t\tread_page_mutex;\n+\tstruct semaphore\t\tblock_cache_mutex;\n+\tstruct semaphore\t\tfragment_mutex;\n+\tstruct semaphore\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.12/init/do_mounts_rd.c linux-2.6.12-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.12/init/do_mounts_rd.c\t2005-06-17 20:48:29.000000000 +0100\n+++ linux-2.6.12-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:24.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.14/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.14/fs/Kconfig linux-2.6.14-squashfs3.3/fs/Kconfig\n--- linux-2.6.14/fs/Kconfig\t2005-10-28 01:02:08.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:24.000000000 +0000\n@@ -1137,6 +1137,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.14/fs/Makefile linux-2.6.14-squashfs3.3/fs/Makefile\n--- linux-2.6.14/fs/Makefile\t2005-10-28 01:02:08.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/fs/Makefile\t2007-11-01 05:06:24.000000000 +0000\n@@ -55,6 +55,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.14/fs/squashfs/inode.c linux-2.6.14-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.14/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:10:57.000000000 +0000\n@@ -0,0 +1,2204 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct super_block *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static struct super_block *squashfs_get_sb(struct file_system_type *,int, const char *, void *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tdown(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tup(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tup(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tdown(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tdown(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tup(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tdown(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tup(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tup(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tup(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tinit_MUTEX(&msblk->read_data_mutex);\n+\tinit_MUTEX(&msblk->read_page_mutex);\n+\tinit_MUTEX(&msblk->block_cache_mutex);\n+\tinit_MUTEX(&msblk->fragment_mutex);\n+\tinit_MUTEX(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tup(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tup(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tdown(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tup(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tup(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.14/fs/squashfs/Makefile linux-2.6.14-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.14/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.14/fs/squashfs/squashfs2_0.c linux-2.6.14-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.14/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-31 22:58:14.000000000 +0000\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.14/fs/squashfs/squashfs.h linux-2.6.14-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.14/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/fs/squashfs/squashfs.h\t2007-11-01 02:13:16.000000000 +0000\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern struct address_space_operations squashfs_symlink_aops;\n+extern struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.14/include/linux/squashfs_fs.h linux-2.6.14-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.14/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.14/include/linux/squashfs_fs_i.h linux-2.6.14-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.14/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.14/include/linux/squashfs_fs_sb.h linux-2.6.14-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.14/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-10-31 14:28:58.000000000 +0000\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct semaphore\t\tread_data_mutex;\n+\tstruct semaphore\t\tread_page_mutex;\n+\tstruct semaphore\t\tblock_cache_mutex;\n+\tstruct semaphore\t\tfragment_mutex;\n+\tstruct semaphore\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.14/init/do_mounts_rd.c linux-2.6.14-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.14/init/do_mounts_rd.c\t2005-10-28 01:02:08.000000000 +0100\n+++ linux-2.6.14-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:24.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.16/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.16/fs/Kconfig linux-2.6.16-squashfs3.3/fs/Kconfig\n--- linux-2.6.16/fs/Kconfig\t2006-03-20 05:53:29.000000000 +0000\n+++ linux-2.6.16-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:25.000000000 +0000\n@@ -1193,6 +1193,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.16/fs/Makefile linux-2.6.16-squashfs3.3/fs/Makefile\n--- linux-2.6.16/fs/Makefile\t2006-03-20 05:53:29.000000000 +0000\n+++ linux-2.6.16-squashfs3.3/fs/Makefile\t2007-11-01 05:06:25.000000000 +0000\n@@ -55,6 +55,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.16/fs/squashfs/inode.c linux-2.6.16-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.16/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:10:37.000000000 +0000\n@@ -0,0 +1,2204 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct super_block *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static struct super_block *squashfs_get_sb(struct file_system_type *,int, const char *, void *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tmutex_lock(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tmutex_lock(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tmutex_unlock(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tmutex_lock(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->block_cache_mutex);\n+\tmutex_init(&msblk->fragment_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.16/fs/squashfs/Makefile linux-2.6.16-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.16/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.16/fs/squashfs/squashfs2_0.c linux-2.6.16-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.16/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-31 22:58:35.000000000 +0000\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.16/fs/squashfs/squashfs.h linux-2.6.16-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.16/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.3/fs/squashfs/squashfs.h\t2007-11-01 02:12:17.000000000 +0000\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern struct address_space_operations squashfs_symlink_aops;\n+extern struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.16/include/linux/squashfs_fs.h linux-2.6.16-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.16/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.16/include/linux/squashfs_fs_i.h linux-2.6.16-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.16/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.16/include/linux/squashfs_fs_sb.h linux-2.6.16-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.16/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-08-19 04:24:26.000000000 +0100\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tblock_cache_mutex;\n+\tstruct mutex\t\tfragment_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.16/init/do_mounts_rd.c linux-2.6.16-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.16/init/do_mounts_rd.c\t2006-03-20 05:53:29.000000000 +0000\n+++ linux-2.6.16-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:25.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.18/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.18/fs/Kconfig linux-2.6.18-squashfs3.3/fs/Kconfig\n--- linux-2.6.18/fs/Kconfig\t2006-09-20 04:42:06.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:25.000000000 +0000\n@@ -1249,6 +1249,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.18/fs/Makefile linux-2.6.18-squashfs3.3/fs/Makefile\n--- linux-2.6.18/fs/Makefile\t2006-09-20 04:42:06.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/fs/Makefile\t2007-11-01 05:06:25.000000000 +0000\n@@ -57,6 +57,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.18/fs/squashfs/inode.c linux-2.6.18-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.18/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:10:25.000000000 +0000\n@@ -0,0 +1,2206 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tmutex_lock(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tmutex_lock(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tmutex_unlock(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tmutex_lock(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->block_cache_mutex);\n+\tmutex_init(&msblk->fragment_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.18/fs/squashfs/Makefile linux-2.6.18-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.18/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.18/fs/squashfs/squashfs2_0.c linux-2.6.18-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.18/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-31 22:58:54.000000000 +0000\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.18/fs/squashfs/squashfs.h linux-2.6.18-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.18/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/fs/squashfs/squashfs.h\t2007-08-19 04:23:16.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.18/include/linux/squashfs_fs.h linux-2.6.18-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.18/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.18/include/linux/squashfs_fs_i.h linux-2.6.18-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.18/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.18/include/linux/squashfs_fs_sb.h linux-2.6.18-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.18/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-08-19 04:24:26.000000000 +0100\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tblock_cache_mutex;\n+\tstruct mutex\t\tfragment_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.18/init/do_mounts_rd.c linux-2.6.18-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.18/init/do_mounts_rd.c\t2006-09-20 04:42:06.000000000 +0100\n+++ linux-2.6.18-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:25.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.20/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.20/fs/Kconfig linux-2.6.20-squashfs3.3/fs/Kconfig\n--- linux-2.6.20/fs/Kconfig\t2007-02-04 18:44:54.000000000 +0000\n+++ linux-2.6.20-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:25.000000000 +0000\n@@ -1404,6 +1404,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.20/fs/Makefile linux-2.6.20-squashfs3.3/fs/Makefile\n--- linux-2.6.20/fs/Makefile\t2007-02-04 18:44:54.000000000 +0000\n+++ linux-2.6.20-squashfs3.3/fs/Makefile\t2007-11-01 05:06:25.000000000 +0000\n@@ -68,6 +68,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/inode.c linux-2.6.20-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.20/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:10:13.000000000 +0000\n@@ -0,0 +1,2192 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/smp_lock.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tmutex_lock(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tmutex_lock(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tmutex_unlock(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tmutex_lock(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->block_cache_mutex);\n+\tmutex_init(&msblk->fragment_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/Makefile linux-2.6.20-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.20/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/squashfs2_0.c linux-2.6.20-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.20/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-25 00:43:59.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/squashfs.h linux-2.6.20-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.20/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.3/fs/squashfs/squashfs.h\t2007-08-19 04:23:16.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.20/include/linux/squashfs_fs.h linux-2.6.20-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.20/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.20/include/linux/squashfs_fs_i.h linux-2.6.20-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.20/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.20/include/linux/squashfs_fs_sb.h linux-2.6.20-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.20/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-08-19 04:24:26.000000000 +0100\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tblock_cache_mutex;\n+\tstruct mutex\t\tfragment_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.20/init/do_mounts_rd.c linux-2.6.20-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.20/init/do_mounts_rd.c\t2007-02-04 18:44:54.000000000 +0000\n+++ linux-2.6.20-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:25.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.22/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.22/fs/Kconfig linux-2.6.22-squashfs3.3/fs/Kconfig\n--- linux-2.6.22/fs/Kconfig\t2007-07-09 00:32:17.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:25.000000000 +0000\n@@ -1367,6 +1367,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.22/fs/Makefile linux-2.6.22-squashfs3.3/fs/Makefile\n--- linux-2.6.22/fs/Makefile\t2007-07-09 00:32:17.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/fs/Makefile\t2007-11-01 05:06:25.000000000 +0000\n@@ -72,6 +72,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.22/fs/squashfs/inode.c linux-2.6.22-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.22/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:09:57.000000000 +0000\n@@ -0,0 +1,2191 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/smp_lock.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tmutex_lock(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tmutex_lock(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tmutex_unlock(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tmutex_lock(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->block_cache_mutex);\n+\tmutex_init(&msblk->fragment_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.22/fs/squashfs/Makefile linux-2.6.22-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.22/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.22/fs/squashfs/squashfs2_0.c linux-2.6.22-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.22/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-25 00:43:59.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.22/fs/squashfs/squashfs.h linux-2.6.22-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.22/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/fs/squashfs/squashfs.h\t2007-08-19 04:23:16.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.22/include/linux/squashfs_fs.h linux-2.6.22-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.22/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.22/include/linux/squashfs_fs_i.h linux-2.6.22-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.22/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.22/include/linux/squashfs_fs_sb.h linux-2.6.22-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.22/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-08-19 04:24:26.000000000 +0100\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tblock_cache_mutex;\n+\tstruct mutex\t\tfragment_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.22/init/do_mounts_rd.c linux-2.6.22-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.22/init/do_mounts_rd.c\t2007-07-09 00:32:17.000000000 +0100\n+++ linux-2.6.22-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:25.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.23/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.23/fs/Kconfig linux-2.6.23-squashfs3.3/fs/Kconfig\n--- linux-2.6.23/fs/Kconfig\t2007-10-09 21:31:38.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:25.000000000 +0000\n@@ -1364,6 +1364,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.23/fs/Makefile linux-2.6.23-squashfs3.3/fs/Makefile\n--- linux-2.6.23/fs/Makefile\t2007-10-09 21:31:38.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/fs/Makefile\t2007-11-01 05:06:25.000000000 +0000\n@@ -72,6 +72,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.23/fs/squashfs/inode.c linux-2.6.23-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.23/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:09:05.000000000 +0000\n@@ -0,0 +1,2192 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/smp_lock.h>\n+#include <linux/exportfs.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tmutex_lock(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tmutex_lock(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tmutex_unlock(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tmutex_lock(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->block_cache_mutex);\n+\tmutex_init(&msblk->fragment_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.23/fs/squashfs/Makefile linux-2.6.23-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.23/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.23/fs/squashfs/squashfs2_0.c linux-2.6.23-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.23/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-25 00:43:59.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.23/fs/squashfs/squashfs.h linux-2.6.23-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.23/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/fs/squashfs/squashfs.h\t2007-08-19 04:23:16.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.23/include/linux/squashfs_fs.h linux-2.6.23-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.23/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.23/include/linux/squashfs_fs_i.h linux-2.6.23-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.23/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.23/include/linux/squashfs_fs_sb.h linux-2.6.23-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.23/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-08-19 04:24:26.000000000 +0100\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tblock_cache_mutex;\n+\tstruct mutex\t\tfragment_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.23/init/do_mounts_rd.c linux-2.6.23-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.23/init/do_mounts_rd.c\t2007-10-09 21:31:38.000000000 +0100\n+++ linux-2.6.23-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:25.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.24/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.24/fs/Kconfig linux-2.6.24-squashfs3.3/fs/Kconfig\n--- linux-2.6.24/fs/Kconfig\t2007-10-25 17:41:45.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:25.000000000 +0000\n@@ -1396,6 +1396,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.24/fs/Makefile linux-2.6.24-squashfs3.3/fs/Makefile\n--- linux-2.6.24/fs/Makefile\t2007-10-25 17:41:45.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/fs/Makefile\t2007-11-01 05:08:09.000000000 +0000\n@@ -72,6 +72,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-y\t\t\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/inode.c linux-2.6.24-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.24/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 05:05:00.000000000 +0000\n@@ -0,0 +1,2192 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/smp_lock.h>\n+#include <linux/exportfs.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tmutex_lock(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tmutex_unlock(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tmutex_lock(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tmutex_unlock(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tmutex_lock(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tmutex_lock(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tmutex_unlock(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->block_cache_mutex);\n+\tmutex_init(&msblk->fragment_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(struct kmem_cache *cachep, void *foo)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/Makefile linux-2.6.24-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.24/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs2_0.c linux-2.6.24-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.24/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-25 00:43:59.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs.h linux-2.6.24-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.24/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/fs/squashfs/squashfs.h\t2007-08-19 04:23:16.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.24/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs_i.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.24/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs_sb.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.24/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-08-19 04:24:26.000000000 +0100\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tblock_cache_mutex;\n+\tstruct mutex\t\tfragment_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.24/init/do_mounts_rd.c linux-2.6.24-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.24/init/do_mounts_rd.c\t2007-10-25 17:41:49.000000000 +0100\n+++ linux-2.6.24-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:25.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.6/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.6/fs/Kconfig linux-2.6.6-squashfs3.3/fs/Kconfig\n--- linux-2.6.6/fs/Kconfig\t2004-05-10 03:32:38.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:25.000000000 +0000\n@@ -1145,6 +1145,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.6/fs/Makefile linux-2.6.6-squashfs3.3/fs/Makefile\n--- linux-2.6.6/fs/Makefile\t2004-05-10 03:32:38.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/fs/Makefile\t2007-11-01 05:06:25.000000000 +0000\n@@ -50,6 +50,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.6/fs/squashfs/inode.c linux-2.6.6-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.6/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:11:47.000000000 +0000\n@@ -0,0 +1,2215 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct super_block *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static struct super_block *squashfs_get_sb(struct file_system_type *,int, const char *, void *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static void *kzalloc(int size, int flags)\n+{\n+\tvoid *buff = kmalloc(size, flags);\n+\n+\tif(buff != NULL)\n+\t\tmemset(buff, 0, size);\n+\n+\treturn buff;\n+}\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tdown(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tup(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tup(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tdown(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tdown(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tup(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tdown(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tup(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tup(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tup(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tinit_MUTEX(&msblk->read_data_mutex);\n+\tinit_MUTEX(&msblk->read_page_mutex);\n+\tinit_MUTEX(&msblk->block_cache_mutex);\n+\tinit_MUTEX(&msblk->fragment_mutex);\n+\tinit_MUTEX(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tup(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tup(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tdown(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tup(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tup(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.6/fs/squashfs/Makefile linux-2.6.6-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.6/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.6/fs/squashfs/squashfs2_0.c linux-2.6.6-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.6/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-31 22:57:55.000000000 +0000\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.6/fs/squashfs/squashfs.h linux-2.6.6-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.6/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/fs/squashfs/squashfs.h\t2007-11-01 02:13:45.000000000 +0000\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern struct address_space_operations squashfs_symlink_aops;\n+extern struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.6/include/linux/squashfs_fs.h linux-2.6.6-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.6/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.6/include/linux/squashfs_fs_i.h linux-2.6.6-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.6/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.6/include/linux/squashfs_fs_sb.h linux-2.6.6-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.6/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-10-31 14:28:58.000000000 +0000\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct semaphore\t\tread_data_mutex;\n+\tstruct semaphore\t\tread_page_mutex;\n+\tstruct semaphore\t\tblock_cache_mutex;\n+\tstruct semaphore\t\tfragment_mutex;\n+\tstruct semaphore\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.6/init/do_mounts_rd.c linux-2.6.6-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.6/init/do_mounts_rd.c\t2004-05-10 03:32:54.000000000 +0100\n+++ linux-2.6.6-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:25.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/kernel-patches/linux-2.6.8.1/squashfs3.3-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.8.1/fs/Kconfig linux-2.6.8.1-squashfs3.3/fs/Kconfig\n--- linux-2.6.8.1/fs/Kconfig\t2004-08-14 11:55:33.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/fs/Kconfig\t2007-11-01 05:06:25.000000000 +0000\n@@ -1231,6 +1231,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.3 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.3 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.8.1/fs/Makefile linux-2.6.8.1-squashfs3.3/fs/Makefile\n--- linux-2.6.8.1/fs/Makefile\t2004-08-14 11:55:33.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/fs/Makefile\t2007-11-01 05:06:25.000000000 +0000\n@@ -50,6 +50,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.8.1/fs/squashfs/inode.c linux-2.6.8.1-squashfs3.3/fs/squashfs/inode.c\n--- linux-2.6.8.1/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/fs/squashfs/inode.c\t2007-11-01 03:11:35.000000000 +0000\n@@ -0,0 +1,2215 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+int squashfs_cached_blks;\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct super_block *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static struct super_block *squashfs_get_sb(struct file_system_type *,int, const char *, void *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static void *kzalloc(int size, int flags)\n+{\n+\tvoid *buff = kmalloc(size, flags);\n+\n+\tif(buff != NULL)\n+\t\tmemset(buff, 0, size);\n+\n+\treturn buff;\n+}\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = sb_getblk(s, cur_index);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 1; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tdown(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tup(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tup(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint n, i, bytes, return_length = length;\n+\tlong long next_index;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < squashfs_cached_blks; i++) \n+\t\t\tif (msblk->block_cache[i].block == block)\n+\t\t\t\tbreak; \n+\t\t\n+\t\tdown(&msblk->block_cache_mutex);\n+\n+\t\tif (i == squashfs_cached_blks) {\n+\t\t\t/* read inode header block */\n+\t\t\tif (msblk->unused_cache_blks == 0) {\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\twait_event(msblk->waitq, msblk->unused_cache_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_cache;\n+\t\t\tfor (n = 0; n < squashfs_cached_blks; n++) {\n+\t\t\t\tif (msblk->block_cache[i].block != SQUASHFS_USED_BLK)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % squashfs_cached_blks;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_cache = (i + 1) % squashfs_cached_blks;\n+\n+\t\t\tif (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {\n+\t\t\t\tmsblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);\n+\t\t\t\tif (msblk->block_cache[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate cache block\\n\");\n+\t\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\t\n+\t\t\tmsblk->block_cache[i].block = SQUASHFS_USED_BLK;\n+\t\t\tmsblk->unused_cache_blks --;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\n+\t\t\tmsblk->block_cache[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->block_cache[i].data, block, 0, &next_index,\n+\t\t\t\tSQUASHFS_METADATA_SIZE);\n+\n+\t\t\tif (msblk->block_cache[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read cache block [%llx:%x]\\n\", block, offset);\n+\t\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\tvfree(msblk->block_cache[i].data);\n+\t\t\t\twake_up(&msblk->waitq);\n+\t\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->block_cache_mutex);\n+\t\t\tmsblk->block_cache[i].block = block;\n+\t\t\tmsblk->block_cache[i].next_index = next_index;\n+\t\t\tmsblk->unused_cache_blks ++;\n+\t\t\tsmp_mb();\n+\t\t\twake_up(&msblk->waitq);\n+\t\t\tTRACE(\"Read cache block [%llx:%x]\\n\", block, offset);\n+\t\t}\n+\n+\t\tif (msblk->block_cache[i].block != block) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tbytes = msblk->block_cache[i].length - offset;\n+\n+\t\tif (bytes < 1) {\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto out;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, length);\n+\t\t\tif (msblk->block_cache[i].length - offset == length) {\n+\t\t\t\t*next_block = msblk->block_cache[i].next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, msblk->block_cache[i].data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = msblk->block_cache[i].next_index;\n+\t\t\tup(&msblk->block_cache_mutex);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\treturn return_length;\n+out:\n+\treturn 0;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_fragment_cache *fragment)\n+{\n+\tdown(&msblk->fragment_mutex);\n+\tfragment->locked --;\n+\tif (fragment->locked == 0) {\n+\t\tmsblk->unused_frag_blks ++;\n+\t\tsmp_mb();\n+\t\twake_up(&msblk->fragment_wait_queue);\n+\t}\n+\tup(&msblk->fragment_mutex);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\twhile (1) {\n+\t\tdown(&msblk->fragment_mutex);\n+\n+\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&\n+\t\t\t\tmsblk->fragment[i].block != start_block; i++);\n+\n+\t\tif (i == SQUASHFS_CACHED_FRAGMENTS) {\n+\t\t\tif (msblk->unused_frag_blks == 0) {\n+\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\twait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = msblk->next_fragment;\n+\t\t\tfor (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {\n+\t\t\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t}\n+\n+\t\t\tmsblk->next_fragment = (msblk->next_fragment + 1) %\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS;\n+\t\t\t\n+\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\tmsblk->fragment[i].data = vmalloc(sblk->block_size);\n+\t\t\t\tif (msblk->fragment[i].data == NULL) {\n+\t\t\t\t\tERROR(\"Failed to allocate fragment cache block\\n\");\n+\t\t\t\t\tup(&msblk->fragment_mutex);\n+\t\t\t\t\tgoto out;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t\t\tmsblk->fragment[i].locked = 1;\n+\t\t\tup(&msblk->fragment_mutex);\n+\n+\t\t\tmsblk->fragment[i].length = squashfs_read_data(s,\n+\t\t\t\tmsblk->fragment[i].data, start_block, length, NULL,\n+\t\t\t\tsblk->block_size);\n+\n+\t\t\tif (msblk->fragment[i].length == 0) {\n+\t\t\t\tERROR(\"Unable to read fragment cache block [%llx]\\n\", start_block);\n+\t\t\t\tmsblk->fragment[i].locked = 0;\n+\t\t\t\tmsblk->unused_frag_blks ++;\n+\t\t\t\tsmp_mb();\n+\t\t\t\twake_up(&msblk->fragment_wait_queue);\n+\t\t\t\tgoto out;\n+\t\t\t}\n+\n+\t\t\tdown(&msblk->fragment_mutex);\n+\t\t\tmsblk->fragment[i].block = start_block;\n+\t\t\tTRACE(\"New fragment %d, start block %lld, locked %d\\n\",\n+\t\t\t\ti, msblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\t\tup(&msblk->fragment_mutex);\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (msblk->fragment[i].locked == 0)\n+\t\t\tmsblk->unused_frag_blks --;\n+\t\tmsblk->fragment[i].locked++;\n+\t\tup(&msblk->fragment_mutex);\n+\t\tTRACE(\"Got fragment %d, start block %lld, locked %d\\n\", i,\n+\t\t\tmsblk->fragment[i].block, msblk->fragment[i].locked);\n+\t\tbreak;\n+\t}\n+\n+\treturn &msblk->fragment[i];\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int readahead_metadata(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint i;\n+\n+\tsquashfs_cached_blks = SQUASHFS_CACHED_BLKS;\n+\n+\t/* Init inode_table block pointer array */\n+\tmsblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *\n+\t\t\t\t\tsquashfs_cached_blks, GFP_KERNEL);\n+\tif (msblk->block_cache == NULL) {\n+\t\tERROR(\"Failed to allocate block cache\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\tmsblk->block_cache[i].block = SQUASHFS_INVALID_BLK;\n+\n+\tmsblk->next_cache = 0;\n+\tmsblk->unused_cache_blks = squashfs_cached_blks;\n+\n+\treturn 1;\n+\n+failed:\n+\treturn 0;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tint i;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tinit_MUTEX(&msblk->read_data_mutex);\n+\tinit_MUTEX(&msblk->read_page_mutex);\n+\tinit_MUTEX(&msblk->block_cache_mutex);\n+\tinit_MUTEX(&msblk->fragment_mutex);\n+\tinit_MUTEX(&msblk->meta_index_mutex);\n+\t\n+\tinit_waitqueue_head(&msblk->waitq);\n+\tinit_waitqueue_head(&msblk->fragment_wait_queue);\n+\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tif (readahead_metadata(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *\n+\t\t\t\tSQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);\n+\tif (msblk->fragment == NULL) {\n+\t\tERROR(\"Failed to allocate fragment block cache\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {\n+\t\tmsblk->fragment[i].block = SQUASHFS_INVALID_BLK;\n+\t}\n+\n+\tmsblk->next_fragment = 0;\n+\tmsblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tkfree(msblk->fragment);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tkfree(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tup(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tup(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_fragment_cache *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tdown(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tup(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment == NULL) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tup(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos =- 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tint i;\n+\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tif (sbi->block_cache)\n+\t\t\tfor (i = 0; i < squashfs_cached_blks; i++)\n+\t\t\t\tif (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)\n+\t\t\t\t\tvfree(sbi->block_cache[i].data);\n+\t\tif (sbi->fragment)\n+\t\t\tfor (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) \n+\t\t\t\tvfree(sbi->fragment[i].data);\n+\t\tkfree(sbi->fragment);\n+\t\tkfree(sbi->block_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.3 (2007/10/31) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.2-r2-CVS, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.8.1/fs/squashfs/Makefile linux-2.6.8.1-squashfs3.3/fs/squashfs/Makefile\n--- linux-2.6.8.1/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/fs/squashfs/Makefile\t2005-11-20 14:31:00.000000000 +0000\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.8.1/fs/squashfs/squashfs2_0.c linux-2.6.8.1-squashfs3.3/fs/squashfs/squashfs2_0.c\n--- linux-2.6.8.1/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/fs/squashfs/squashfs2_0.c\t2007-10-31 22:57:55.000000000 +0000\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.8.1/fs/squashfs/squashfs.h linux-2.6.8.1-squashfs3.3/fs/squashfs/squashfs.h\n--- linux-2.6.8.1/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/fs/squashfs/squashfs.h\t2007-11-01 02:13:38.000000000 +0000\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_fragment_cache *fragment);\n+extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern struct address_space_operations squashfs_symlink_aops;\n+extern struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.8.1/include/linux/squashfs_fs.h linux-2.6.8.1-squashfs3.3/include/linux/squashfs_fs.h\n--- linux-2.6.8.1/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/include/linux/squashfs_fs.h\t2007-11-01 03:50:57.000000000 +0000\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tpending;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.8.1/include/linux/squashfs_fs_i.h linux-2.6.8.1-squashfs3.3/include/linux/squashfs_fs_i.h\n--- linux-2.6.8.1/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/include/linux/squashfs_fs_i.h\t2007-08-19 04:24:08.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.8.1/include/linux/squashfs_fs_sb.h linux-2.6.8.1-squashfs3.3/include/linux/squashfs_fs_sb.h\n--- linux-2.6.8.1/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/include/linux/squashfs_fs_sb.h\t2007-10-31 14:28:58.000000000 +0000\n@@ -0,0 +1,76 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tlong long\tnext_index;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_fragment_cache {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tunsigned int\tlocked;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_fragment_cache\t*fragment;\n+\tint\t\t\tnext_cache;\n+\tint\t\t\tnext_fragment;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct semaphore\t\tread_data_mutex;\n+\tstruct semaphore\t\tread_page_mutex;\n+\tstruct semaphore\t\tblock_cache_mutex;\n+\tstruct semaphore\t\tfragment_mutex;\n+\tstruct semaphore\t\tmeta_index_mutex;\n+\twait_queue_head_t\twaitq;\n+\twait_queue_head_t\tfragment_wait_queue;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\tunused_cache_blks;\n+\tint\t\t\tunused_frag_blks;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.8.1/init/do_mounts_rd.c linux-2.6.8.1-squashfs3.3/init/do_mounts_rd.c\n--- linux-2.6.8.1/init/do_mounts_rd.c\t2004-08-14 11:55:48.000000000 +0100\n+++ linux-2.6.8.1-squashfs3.3/init/do_mounts_rd.c\t2007-11-01 05:06:25.000000000 +0000\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/Makefile",
    "content": "\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\nINCLUDEDIR = .\n\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\nifdef UseDebugFlags\nDebugFlags = -g -Wall -Wno-unused-variable -O0 -UNDEBUG\nendif\nCFLAGS += -I${Sqlzma} -D_REENTRANT -DNDEBUG ${DebugFlags}\nLDLIBS += -lm -L${LzmaAlone} -L${LzmaC}\nTgt = mksquashfs unsquashfs\n\nall: ${Tgt}\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h \\\n\t${LzmaAlone}/liblzma_r.a ${LzmaC}/libunlzma_r.a\nmksquashfs: LDLIBS += -lpthread -lunlzma_r -llzma_r -lstdc++ -lz\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\nunsquashfs.o: CFLAGS += -U_REENTRANT\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h ${LzmaC}/libunlzma.a\nunsquashfs: LDLIBS += -lunlzma -lz\nunsquashfs: unsquashfs.o\n\nclean:\n\t${RM} *~ *.o ${Tgt}\n\n-include test.mk\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\ntypedef union squashfs_inode_header_1 squashfs_inode_header_1;\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\nint sparse_files = TRUE;\nint old_exclude = TRUE;\nint use_regex = FALSE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\nstruct sqlzma_un un;\nstruct sqlzma_opts sqlzma_opts = {\n\t.try_lzma\t= 1,\n\t.dicsize\t= SQUASHFS_FILE_SIZE\n};\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* exclude file handling */\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint old_excluded(char *filename, struct stat *buf);\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nstruct pathnames *paths = NULL;\nstruct pathname *path = NULL;\nstruct pathname *stickypath = NULL;\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* recovery file for abnormal exit on appending */\nchar recovery_file[1024] = \"\";\nint recover = TRUE;\n\n/* data allocator status struct.  Allocators are used to keep\n  track of memory buffers passed between different threads */\nstruct allocator {\n\tint\t\tmax_buffers;\n\tint\t\tcount;\n\tint\t\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t\twait;\n};\n\n/* struct describing a memory buffer passed between threads */\nstruct file_buffer {\n\tlong long\t\tfile_size;\n\tstruct allocator\t*allocator;\n\tvoid\t\t\t(*release)(int);\n\tint\t\t\trelease_data;\n\tlong long\t\tblock;\n\tint\t\t\tsize;\n\tint\t\t\tc_byte;\n\tunsigned int\t\tblock_order;\n\tint\t\t\tfragment;\n\tint\t\t\terror;\n\tstruct file_buffer\t*next;\n\tchar\t\t\tdata[0];\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n/* describes the list of blocks in a file which is a possible\n   duplicate.  For each block, it indicates whether the block is\n   in memory or on disk */\nstruct buffer_list {\n\tlong long start;\n\tint size;\n\tstruct file_buffer *read_buffer;\n};\n\nstruct allocator *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *, char *, struct dir_info *));\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\nextern struct priority_entry *priority_list[65536];\n\n\nstruct allocator *alloc_init(int buffer_size, int max_buffers)\n{\n\tstruct allocator *allocator = malloc(sizeof(struct allocator));\n\n\tif(allocator == NULL)\n\t\treturn NULL;\n\n\tallocator->max_buffers = max_buffers;\n\tallocator->buffer_size = buffer_size;\n\tallocator->count = 0;\n\tpthread_mutex_init(&allocator->mutex, NULL);\n\tpthread_cond_init(&allocator->wait, NULL);\n\n\treturn allocator;\n}\n\n\nstruct file_buffer *alloc_get(struct allocator *allocator)\n{\n\tstruct file_buffer *file_buffer;\n\t\n\tpthread_mutex_lock(&allocator->mutex);\n\n\twhile(allocator->count == allocator->max_buffers)\n\t\tpthread_cond_wait(&allocator->wait, &allocator->mutex);\n\n\tif((file_buffer = malloc(sizeof(struct file_buffer) + allocator->buffer_size)) == NULL)\n\t\tgoto failed;\n\n\tfile_buffer->release = NULL;\n\tfile_buffer->allocator = allocator;\n\tallocator->count ++;\n\nfailed:\n\tpthread_mutex_unlock(&allocator->mutex);\n\treturn file_buffer;\n}\n\n\nstruct file_buffer *alloc_get_2(struct allocator *allocator, void (*release)(int), int release_data)\n{\n\tstruct file_buffer *file_buffer = alloc_get(allocator);\n\n\tif(file_buffer) {\n\t\tfile_buffer->release = release;\n\t\tfile_buffer->release_data = release_data;\n\t}\n\treturn file_buffer;\n}\n\n\nvoid alloc_free(struct file_buffer *file_buffer)\n{\n\tstruct allocator *allocator;\n\n\tif(file_buffer == NULL)\n\t\treturn;\n\n\tallocator = file_buffer->allocator;\n\n\tif(file_buffer->release)\n\t\tfile_buffer->release(file_buffer->release_data);\n\n\tpthread_mutex_lock(&allocator->mutex);\n\tfree(file_buffer);\n\tif(allocator->count == 0)\n\t\tERROR(\"alloc_free: freeing buffer for empty allocator!\\n\");\n\telse\n\t\tallocator->count --;\n\tpthread_cond_signal(&allocator->wait);\n\tpthread_mutex_unlock(&allocator->mutex);\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\n\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t}\n\n\tres = sqlzma_cm(&sqlzma_opts, stream, (void *)s, size, (void *)d,\n\t\t\tblock_size);\n\tc_byte = stream->total_out;\n\n\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir)\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir);\n\telse\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL);\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment, int *cached_fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\n\tif(fragment->index == *cached_fragment || fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn buffer + fragment->offset;\n\n\tif(fragment_data && fragment->index == fragments)\n\t\treturn fragment_data->data + fragment->offset;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragment_table[fragment->index].pending)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)cbuffer, .sz = size},\n\t\t\t{.buf = (void *)buffer, .sz = bytes}\n\t\t};\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tBAD_ERROR(\"%s:%d: res %d\\n\", __func__, __LINE__, res);\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\t*cached_fragment = fragment->index;\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid ensure_fragments_flushed()\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragments_outstanding)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].pending = TRUE;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\nvoid frag_release(int block)\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragment_table[block].pending = FALSE;\n\tpthread_cond_signal(&fragment_waiting);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = alloc_get(fragment_buffer);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint avail_bytes, compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tlong long slist[meta_blocks];\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_buffer(struct buffer_list *buffer_list, unsigned int blocks)\n{\n\tunsigned short chksum = 0;\n\tint block;\n\n\tfor(block = 0; block < blocks; block ++) {\n\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\tif(b->read_buffer)\n\t\t\tchksum = get_checksum(b->read_buffer->data, b->read_buffer->size, chksum);\n\t\telse if(b->size != 0)\n\t\t\tchksum = get_checksum(read_from_disk(b->start, b->size), b->size, chksum);\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\nint cached_frag = -1;\nchar fragdata[SQUASHFS_FILE_MAX_SIZE];\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tchar *datap;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\nchar cached_fragment[SQUASHFS_FILE_MAX_SIZE];\nint cached_frag1 = -1;\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), file_size);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nchar buffer2[SQUASHFS_FILE_MAX_SIZE];\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tchar *buffer;\n\t\t\tint block;\n\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks) != 0)\n\t\t\t\tcontinue;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_buffer(buffer_list, blocks);\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), frag_bytes);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\t\t\tif(b->read_buffer)\n\t\t\t\t\tbuffer = b->read_buffer->data;\n\t\t\t\telse if(b->size)\n\t\t\t\t\tbuffer = read_from_disk(b->start, b->size);\n\t\t\t\telse\n\t\t\t\t\tcontinue;\n\n\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\n\t\t\t\tif(memcmp(buffer, buffer2, b->size) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_start += b->size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tchar *fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1);\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\n\tstruct file_buffer *file_buffer;\n\tstatic int block_order = 0;\n\tint blocks, byte, count, expected, file, frag_block;\n\tlong long bytes, read_size;\n\n\tif(dir_ent->inode->read)\n\t\treturn;\n\n\tdir_ent->inode->read = TRUE;\nagain:\n\tbytes = 0;\n\tcount = 0;\n\tfile_buffer = NULL;\n\tread_size = buf->st_size;\n\tblocks = (read_size + block_size - 1) >> block_log;\n\tfrag_block = !no_fragments && (always_use_fragments ||\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\texpected = read_size - ((long long) count * block_size) > block_size ? block_size : read_size - ((long long) count * block_size);\n\n\t\tif(file_buffer)\n\t\t\tqueue_put(from_reader, file_buffer);\n\t\tfile_buffer = alloc_get(reader_buffer);\n\n\t\tbyte = file_buffer->size = read(file, file_buffer->data, block_size);\n\n\t\tfile_buffer->block_order = block_order ++;\n\t\tfile_buffer->file_size = read_size;\n\n\t\tif(byte != expected)\n\t\t\tgoto restat;\n\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->error = FALSE;\n\n\t\tbytes += byte;\n\t\tcount ++;\n\t} while(count < blocks);\n\n\tif(read_size != bytes)\n\t\tgoto restat;\n\n\tif(expected == block_size) {\n\t\tchar buffer;\n\n\t\tif(read(file, &buffer, 1) == 1)\n\t\t\tgoto restat;\n\t}\n\n\tif(file_buffer->fragment = file_buffer->block == frag_block)\n\t\tqueue_put(from_deflate, file_buffer);\n\telse\n\t\tqueue_put(from_reader, file_buffer);\n\n\tclose(file);\n\n\treturn;\n\nread_err:\n\tfile_buffer = alloc_get(reader_buffer);\n\tfile_buffer->block_order = block_order ++;\nread_err2:\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n\treturn;\nrestat:\n\tfstat(file, &buf2);\n\tclose(file);\n\tif(read_size != buf2.st_size) {\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\n\t\tfile_buffer->error = 2;\n\t\tqueue_put(from_deflate, file_buffer);\n\t\tgoto again;\n\t}\n\tgoto read_err2;\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\treturn NULL;\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tperror(\"Lseek on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n\t\t\tperror(\"Write on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\nint all_zero(struct file_buffer *file_buffer)\n{\n\tint i;\n\tlong entries = file_buffer->size / sizeof(long);\n\tlong *p = (long *) file_buffer->data;\n\n\tfor(i = 0; i < entries && p[i] == 0; i++);\n\n\tif(i == entries) {\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1); i < file_buffer->size &&\n\t\t\t\t\t\tfile_buffer->data[i] == 0; i++);\n\n\t\treturn i == file_buffer->size;\n\t}\n\n\treturn 0;\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer = alloc_get(writer_buffer);\n\n\t\tif(sparse_files && all_zero(file_buffer)) \n\t\t\twrite_buffer->c_byte = 0;\n\t\telse\n\t\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\n\t\twrite_buffer->file_size = file_buffer->file_size;\n\t\twrite_buffer->block = file_buffer->block;\n\t\twrite_buffer->block_order = file_buffer->block_order;\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\n\t\twrite_buffer->fragment = FALSE;\n\t\twrite_buffer->error = FALSE;\n\t\talloc_free(file_buffer);\n\t\tqueue_put(from_deflate, write_buffer);\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer = alloc_get_2(writer_buffer, frag_release, file_buffer->block);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\twrite_buffer->size = compressed_size;\n\t\twrite_buffer->block = bytes;\n\t\tqueue_put(to_writer, write_buffer);\n\t\tbytes += compressed_size;\n\t\ttotal_uncompressed += file_buffer->size;\n\t\ttotal_compressed += compressed_size;\n\t\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\n\t\tfragments_outstanding --;\n\t\tpthread_cond_signal(&fragment_waiting);\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->block_order);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int block_order = 0;\n\tint hash = BLOCK_HASH(block_order);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->block_order == block_order)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->block_order == block_order)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tblock_order ++;\n\n\treturn file_buffer;\n}\n\n\nint progress_bar(long long current, long long max, int columns)\n{\n\tint max_digits = ceil(log10(max));\n\tint used = max_digits * 2 + 10;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(!progress || columns - used < 0)\n\t\treturn 0;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n\treturn 0;\n}\n\n\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n}\n\n\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\n{\n\tint file;\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\talloc_free(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, struct file_buffer *file_buffer, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum)) {\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\n\t\treturn;\n\t}\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\talloc_free(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n\n\treturn;\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\n{\n\tint block;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list;\n\tstruct file_buffer *read_buffer;\n\tint status;\n\n\t*duplicate_file = FALSE;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tif(reader_buffer) {\n\t\t\tread_buffer = reader_buffer;\n\t\t\treader_buffer = NULL;\n\t\t} else {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tif(read_buffer->c_byte) {\n\t\t\tread_buffer->block = bytes;\n\t\t\tbytes += read_buffer->size;\n\t\t\tfile_bytes += read_buffer->size;\n\t\t\tqueue_put(to_writer, read_buffer);\n\t\t} else\n\t\t\talloc_free(read_buffer);\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t} else\n\t\tread_buffer = NULL;\n\n\tfragment = get_and_fill_fragment(read_buffer);\n\talloc_free(read_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tif(block) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\n{\n\tint block, thresh;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer *read_buffer;\n\tstruct file_data *file_data;\n\tstruct buffer_list *buffer_list;\n\tint status;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tthresh = blocks > (writer_buffer_size - processors) ? blocks - (writer_buffer_size - processors): 0;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tif(reader_buffer) {\n\t\t\tread_buffer = reader_buffer;\n\t\t\treader_buffer = NULL;\n\t\t } else {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\n\t\tif(read_buffer->c_byte) {\n\t\t\tread_buffer->block = bytes;\n\t\t\tbytes += read_buffer->size;\n\t\t\tfile_bytes += read_buffer->size;\n\t\t\tif(block < thresh) {\n\t\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else\n\t\t\t\tbuffer_list[block].read_buffer = read_buffer;\n\t\t} else {\n\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\talloc_free(read_buffer);\n\t\t}\n\t\tbuffer_list[block].start = read_buffer->block;\n\t\tbuffer_list[block].size = read_buffer->size;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t} else\n\t\tread_buffer = NULL;\n\n\tqueue_put(to_writer, NULL);\n\tif(queue_get(from_writer) != 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\n\t\tfragment = get_and_fill_fragment(read_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\talloc_free(buffer_list[block].read_buffer);\n\t\tbytes = buffer_list[0].start;\n\t\tif(thresh && !block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\n\talloc_free(read_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tif(block && thresh) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\talloc_free(buffer_list[blocks].read_buffer);\n\tfree(buffer_list);\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn status;\n}\n\n\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tint status;\n\tstruct file_buffer *read_buffer;\n\tlong long read_size;\n\nagain:\n\tread_buffer = get_file_buffer(from_deflate);\n\tif(status = read_buffer->error) {\n\t\talloc_free(read_buffer);\n\t\tgoto file_err;\n\t}\n\t\n\tread_size = read_buffer->file_size;\n\n\tif(read_size == 0) {\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t\talloc_free(read_buffer);\n\t} else if(!no_fragments && (read_size < block_size))\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\telse if(pre_duplicate(read_size))\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\telse\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\nfile_err:\n\tif(status == 2) {\n\t\tERROR(\"File %s changed size while reading filesystem, attempting to re-read\\n\", dir_ent->pathname);\n\t\tgoto again;\n\t} else if(status == 1) {\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\", dir_ent->pathname);\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t}\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\tstruct pathnames *new;\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", filename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\\n\", filename, buf.st_mode & S_IFMT);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(old_exclude) {\n\t\t\tif(old_excluded(filename, &buf))\n\t\t\t\tcontinue;\n\t\t} else {\n\t\t\tif(excluded(paths, dir_name, &new))\n\t\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFREG)\n\t\t\testimated_uncompressed += (buf.st_size + block_size - 1) >> block_log;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, new, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type = -1;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\twrite_file(inode, dir_ent, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tdir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n#if 0\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n#endif\n\t\t\t}\n\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\twrite_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 20; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint old_excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint old_add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(processors * 2);\n\treader_buffer = alloc_init(block_size, reader_buffer_size);\n\twriter_buffer = alloc_init(block_size, writer_buffer_size);\n\tfragment_buffer = alloc_init(block_size, processors * 2);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\n\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\n}\n\n\t\t\t\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\tif(error = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB)) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing exclude which subsumes the exclude currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific excludes, delete as they're subsumed by this exclude\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\t\n\t\nvoid add_exclude(char *target)\n{\n\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 || strncmp(target, \"../\", 3) == 0)\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with -wildcards or -regex options\\n\");\t\n\telse if(strncmp(target, \"... \", 4) == 0)\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\n\telse\t\n\t\tpath = add_path(path, target, target);\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n, res;\n\t\t\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\n\t*new = init_subdir();\n\tif(stickypath)\n\t\t*new = add_subdir(*new, stickypath);\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\n\t\t\tif(match && path->name[i].paths == NULL) {\n\t\t\t\t/* match on a leaf component, any subdirectories in the\n\t\t\t\t * filesystem should be excluded */\n\t\t\t\tres = TRUE;\n\t\t\t\tgoto empty_set;\n\t\t\t}\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t\t/* no matching names found, return empty new search set */\n\t\t\tres = FALSE;\n\t\t\tgoto empty_set;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches).\n\t * Return new set */\n\treturn FALSE;\n\nempty_set:\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn res;\n}\n\n\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\n#define RECOVER_ID_SIZE 28\n\nvoid write_recovery_data(squashfs_super_block *sBlk)\n{\n\tint recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\n\tpid_t pid = getpid();\n\tchar *metadata;\n\tchar header[] = RECOVER_ID;\n\n\tif(recover == FALSE) {\n\t\tprintf(\"No recovery data option specified.\\n\");\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\n\t\treturn;\n\t}\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in write_recovery_data\\n\");\n\n\tread_bytes(fd, sBlk->inode_table_start, bytes, metadata);\n\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\", getbase(destination_file), pid);\n\tif((recoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1)\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  Aborting\\n\", strerror(errno));\n\t\t\n\tif(write(recoverfd, header, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tif(write(recoverfd, sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tif(write(recoverfd, metadata, bytes) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tclose(recoverfd);\n\tfree(metadata);\n\t\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file, recovery_file);\n\tprintf(\"to restore filesystem\\n\\n\");\n}\n\n\nvoid read_recovery_data(char *recovery_file, char *destination_file)\n{\n\tint fd, recoverfd, bytes;\n\tsquashfs_super_block orig_sBlk, sBlk;\n\tchar *metadata;\n\tint readbytes;\n\tstruct stat buf;\n\tchar header[] = RECOVER_ID;\n\tchar header2[RECOVER_ID_SIZE];\n\n\tif((recoverfd = open(recovery_file, O_RDONLY)) == -1)\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\", strerror(errno));\n\n\tif(stat(destination_file, &buf) == -1)\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\", strerror(errno));\n\n\tif((fd = open(destination_file, O_RDWR)) == -1)\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\", strerror(errno));\n\n\tif(read(recoverfd, header2, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\n\n\tif(read(recoverfd, &sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\n\tread_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &orig_sBlk);\n\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4, sizeof(squashfs_super_block) - 4) != 0)\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to match\\n\");\n\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in read_recovery_data\\n\");\n\n\tif((readbytes = read(recoverfd, metadata, bytes)) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\n\tif(readbytes != bytes)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\twrite_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\twrite_bytes(fd, sBlk.inode_table_start, bytes, metadata);\n\n\tclose(recoverfd);\n\tclose(fd);\n\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\", recovery_file);\n\t\n\texit(0);\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.3 (2007/10/31)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\\\n\tprintf(\"and LZMA support for slax.org by jro.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct winsize winsize;\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT;\n\tint s_minor;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tun.un_lzma = 1;\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-recover\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\n\t\t\trecover = FALSE;\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = FALSE;\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\n\t\t\tsparse_files = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0\n\t\t\t|| strcmp(argv[i], \"-lzmadic\") == 0) {\n\t\t\tlong bs;\n\t\t\tunsigned int bl;\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -b|-lzmadic missing block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tbs = strtol(argv[i], &b, 10);\n\t\t\tif(*b == 'm' || *b == 'M')\n\t\t\t\tbs *= 1048576;\n\t\t\telse if(*b == 'k' || *b == 'K')\n\t\t\t\tbs *= 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tERROR(\"%s: -b|-lzmadic invalid size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tbl = slog(bs);\n\t\t\tif(bl == 0) {\n\t\t\t\tERROR(\"%s: -b|-lzmadic size not power of two or not between 4096 and 1Mbyte\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif (!strcmp(argv[i - 1], \"-b\")) {\n\t\t\t\tblock_size = bs;\n\t\t\t\tblock_log = bl;\n\t\t\t}\n\t\t\tsqlzma_opts.dicsize = bs;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n\t\t\tun.un_lzma = 0;\n\t\t\tsqlzma_opts.try_lzma = 0;\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data using recovery file <name>\\n\");\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery file\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards (globbing) to be used in\\n\\t\\t\\texclude dirs/files\\n\");\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n\t\t\tERROR(\"-lzmadic <dic_size>\\tset the LZMA dictionary\"\n\t\t\t      \" size to <dic_size>\\n\"\n\t\t\t      \"\\t\\t\\tDefault value always follow the block\"\n\t\t\t      \" size\\n\"\n\t\t\t      \"\\t\\t\\tUse this alone or AFTER -b option\\n\");\n\t\t\tERROR(\"-nolzma\\t\\t\\tnever try LZMA compression\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n\tif(block_size <= 65536 && sparse_files == FALSE)\n\t\ts_minor = 0;\n\telse\n\t\ts_minor = SQUASHFS_MINOR;\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tsignal(SIGTERM, sighandler2);\n\tsignal(SIGINT, sighandler2);\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\t\tif(old_exclude)\n\t\t\t\t\t\told_add_exclude(filename);\n\t\t\t\t\telse\n\t\t\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc)\n\t\t\tif(old_exclude)\n\t\t\t\told_add_exclude(argv[i++]);\n\t\t\telse\n\t\t\t\tadd_exclude(argv[i++]);\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\t//sqlzma_opts.dicsize = block_size;\n\t\ts_minor = sBlk.s_minor;\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t}\n\n\tinitialise_threads();\n\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tERROR(\"%s:%d: %d\\n\", __func__, __LINE__, i);\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t\tif (sqlzma_opts.try_lzma)\n\t\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tif (sqlzma_opts.try_lzma)\n\t\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = inode_dir_offset + inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\twrite_recovery_data(&sBlk);\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(progress) {\n\t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\t\tcolumns = 80;\n\t\t} else\n\t\t\tcolumns = winsize.ws_col;\n\t\tsignal(SIGWINCH, sigwinch_handler);\n\t}\n\n\tif(path || stickypath) {\n\t\tpaths = init_subdir();\n\t\tif(path)\n\t\t\tpaths = add_subdir(paths, path);\n\t\tif(stickypath)\n\t\t\tpaths = add_subdir(paths, stickypath);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n\tif (!un.un_lzma)\n\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = s_minor;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tensure_fragments_flushed();\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\tclose(fd);\n\n\tif(recovery_file[0] != '\\0')\n\t\tunlink(recovery_file);\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n\tif (sqlzma_opts.try_lzma)\n\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tint uid = uids[i];\n\t\tstruct passwd *user = getpwuid(uid);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\nextern struct sqlzma_un un;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)buffer},\n\t\t\t{.buf = (void *)block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk->s_magic) {\n\t\tsquashfs_super_block sblk;\n\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\tbreak;\n\tcase SQUASHFS_MAGIC:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\n\tbad:\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Filesystem on %s is %d.%d, which is a later filesystem version than I support\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %xllx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block = -1; \n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tlong long sindex[indexes];\n\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_inode_t sinode;\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\n\t\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\twrite_file(&inode, entry->dir, &duplicate_file);\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t1\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exortable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n *  Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_1_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#include <stdlib.h>\n#include <time.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(char *pathname, unsigned int block_start, unsigned int offset);\n\tchar *(*read_fragment)(unsigned int fragment);\n\tvoid (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, unsigned char *block_ptr, int blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar symlink[65536];\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n};\n\t\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE, use_regex = FALSE;\nchar **created_inode;\nint root_process;\nstruct sqlzma_un un;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0} };\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\t/* printf(\"i%d \", inode->inode_number); */\n\n\tif((user = getpwuid(inode->uid)) == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tif((group = getgrgid(inode->gid)) == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0, inode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \", (int) inode->data >> 8, (int) inode->data & 0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)buffer},\n\t\t\t{.buf = (void *)block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)data, .sz = c_byte},\n\t\t\t{.buf = (void *)block, .sz = bytes}\n\t\t};\n\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid read_block_list(unsigned int *block_list, unsigned char *block_ptr, int blocks)\n{\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nvoid read_block_list_1(unsigned int *block_list, unsigned char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) | (SQUASHFS_COMPRESSED(block_size) ? 0 : SQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time, unsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_1()\n{\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nchar *read_fragment_2(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data;\nlong long hole;\n\nint write_block(int file_fd, char *buffer, int size)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(lseek_broken == FALSE && lseek(file_fd, off, SEEK_CUR) == -1) {\n\t\t\t/* failed to seek beyond end of file */\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t\tlseek_broken = TRUE;\n\t\t}\n\t\tif(lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size : hole;\n\t\t\t\tif(write(file_fd, zero_data, avail_bytes) < avail_bytes)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t\thole = 0;\n\t}\n\n\tif(write(file_fd, buffer, size) < size)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\t\nint write_file(long long file_size, char *pathname, unsigned int fragment, unsigned int frag_bytes,\nunsigned int offset, unsigned int blocks, long long start, char *block_ptr,\nunsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\tint file_end = file_size / block_size;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\thole = 0;\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\ts_ops.read_block_list(block_list, block_ptr, blocks);\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif(block_list[i] == 0) { /* sparse file */\n\t\t\thole += i == file_end ? file_size & (block_size - 1) : block_size;\n\t\t\tcontinue;\n\t\t}\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write_block(file_fd, file_data, bytes) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = s_ops.read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write_block(file_fd, fragment_data + offset, frag_bytes) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tif(hole) {\n\t\t/* corner case for hole extending to end of file */\n\t\thole --;\n\t\tif(write_block(file_fd, \"\\0\", 1) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write sparse data block\\n\");\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\tfree(block_list);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\n\nstatic struct inode *read_inode(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i->data, pathname, i->fragment, i->frag_bytes,\n\t\t\t\t\ti->offset, i->blocks, i->start, i->block_ptr, i->mode)) {\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", i->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\tmakedev((i->data >> 8) & 0xff, i->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", i->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_2 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[header.base.uid];\n    i.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_2!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_1 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode, sizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[(header.base.inode_type - 1) / SQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) % SQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n    i.gid = header.base.guid == 15 ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_1), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_1!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(char *pathname, unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tstruct inode *i;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + i->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(pathname, i);\n\n\tbytes += i->offset;\n\tsize = i->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = i->mode;\n\tdir->uid = i->uid;\n\tdir->guid = i->gid;\n\tdir->mtime = i->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(char *pathname, unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tstruct inode *i;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + i->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(pathname, i);\n\n\tbytes += i->offset;\n\tsize = i->data + bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = i->mode;\n\tdir->uid = i->uid;\n\tdir->guid = i->gid;\n\tdir->mtime = i->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\tif(error = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB)) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing extract which subsumes the extract currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific extracts, delete as they're subsumed by this extract\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/* match on a leaf component, any subdirectories will\n\t\t\t\t * implicitly match, therefore return an empty new search set */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/* no matching names found, delete empty search set, and return\n        * FALSE */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches),\n     * return new search set and return TRUE */\n\treturn TRUE;\n\nempty_set:\n   /* found matching leaf exclude, return empty search set and return TRUE */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, struct pathnames *paths)\n{\n\tstruct dir *dir = s_ops.squashfs_opendir(parent_name, start_block, offset);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly)\n\t\t\t\tcreate_inode(pathname, i);\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str : \"failed to get time\\n\");\n\tprintf(\"Filesystem is %sexportable via NFS\\n\", SQUASHFS_EXPORTABLE(sBlk.flags) ? \"\" : \"not \");\n\n\tprintf(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tif(sBlk.s_major > 1 && !SQUASHFS_NO_FRAGMENTS(sBlk.flags))\n\t\tprintf(\"Fragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Check data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not \");\n\tif(sBlk.s_major > 1) {\n\t\tprintf(\"Fragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not \" : \"\");\n\t\tprintf(\"Always_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not \");\n\t} else\n\t\tprintf(\"Fragments are not supported by the filesystem\\n\");\n\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tprintf(\"Block size %d\\n\", sBlk.block_size);\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.fragments);\n\tprintf(\"Number of inodes %d\\n\", sBlk.inodes);\n\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tif(sBlk.s_major > 1)\n\t\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n}\n\n\nint read_super(char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tun.un_lzma = 1;\n\tswap = 0;\n\tswitch (sBlk.s_magic) {\n\t\tsquashfs_super_block sblk;\n\tcase SQUASHFS_MAGIC:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 1 || sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s_major == 1) {\n\t\t\tsBlk.block_size = sBlk.block_size_1;\n\t\t\tsBlk.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t} else {\n\t\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t}\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor <= 1) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.read_block_list = read_block_list;\n\t\ts_ops.read_inode = read_inode;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tif((fd = fopen(filename, \"r\")) == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename, strerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.5 (2007/10/31)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\\\n\tprintf(\"and LZMA support for slax.org by jro.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tchar **target_name = NULL;\n\tint n, targets = 0;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\n\tif(root_process = geteuid() == 0)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 || strcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 || strcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 || strcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 || strcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 || strcmp(argv[i], \"-r\") == 0)\n\t\t\tuse_regex = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are unsquashed with file\\n\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file attributes (like\\n\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX regular expressions\\n\\t\\t\\t\\trather than use the default shell wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tblock_size = sBlk.block_size;\n\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tfputs(\"sqlzma_init failed\", stderr);\n\t\tabort();\n\t}\n\n\tread_uids_guids();\n\n\ts_ops.read_fragment_table();\n\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/7zCrc.c",
    "content": "/* 7zCrc.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++) \r\n    v = CRC_UPDATE_BYTE(v, *p);\r\n  return v;\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/7zCrc.h",
    "content": "/* 7zCrc.h */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"Types.h\"\r\n\r\nextern UInt32 g_CrcTable[];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void);\r\n\r\n#define CRC_INIT_VAL 0xFFFFFFFF\r\n#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)\r\n#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/7zCrcT8.c",
    "content": "/* 7zCrcT8.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\n#define CRC_NUM_TABLES 8\r\n\r\nUInt32 g_CrcTable[256 * CRC_NUM_TABLES];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable()\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n  #if CRC_NUM_TABLES > 1\r\n  for (; i < 256 * CRC_NUM_TABLES; i++)\r\n  {\r\n    UInt32 r = g_CrcTable[i - 256];\r\n    g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);\r\n  }\r\n  #endif\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  return CrcUpdateT8(v, data, size, g_CrcTable);\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdateT8(CRC_INIT_VAL, data, size, g_CrcTable) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Alloc.c",
    "content": "/* Alloc.c */\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdlib.h>\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount++);\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid MyFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d\", --g_allocCount);\r\n  #endif\r\n  free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#ifndef MEM_LARGE_PAGES\r\n#undef _7ZIP_LARGE_PAGES\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nSIZE_T g_LargePageSize = 0;\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n#endif\r\n\r\nvoid SetLargePageSize()\r\n{\r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  SIZE_T size = 0;\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        GetProcAddress(GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return;\r\n  size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return;\r\n  g_LargePageSize = size;\r\n  #endif\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))\r\n  {\r\n    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), \r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Alloc.h",
    "content": "/* Alloc.h */\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size);\r\nvoid MyFree(void *address);\r\n\r\n#ifdef _WIN32\r\n\r\nvoid SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size);\r\nvoid MidFree(void *address);\r\nvoid *BigAlloc(size_t size);\r\nvoid BigFree(void *address);\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zAlloc.c",
    "content": "/* 7zAlloc.c */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n#endif\r\n\r\nvoid *SzAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zAlloc.h",
    "content": "/* 7zAlloc.h */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\nvoid *SzAlloc(size_t size);\r\nvoid SzFree(void *address);\r\n\r\nvoid *SzAllocTemp(size_t size);\r\nvoid SzFreeTemp(void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zBuffer.c",
    "content": "/* 7zBuffer.c */\r\n\r\n#include \"7zBuffer.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer)\r\n{\r\n  buffer->Capacity = 0;\r\n  buffer->Items = 0;\r\n}\r\n\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))\r\n{\r\n  buffer->Capacity = newCapacity;\r\n  if (newCapacity == 0)\r\n  {\r\n    buffer->Items = 0;\r\n    return 1;\r\n  }\r\n  buffer->Items = (Byte *)allocFunc(newCapacity);\r\n  return (buffer->Items != 0);\r\n}\r\n\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(buffer->Items);\r\n  buffer->Items = 0;\r\n  buffer->Capacity = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zBuffer.h",
    "content": "/* 7zBuffer.h */\r\n\r\n#ifndef __7Z_BUFFER_H\r\n#define __7Z_BUFFER_H\r\n\r\n#include <stddef.h>\r\n#include \"../../Types.h\"\r\n\r\ntypedef struct _CSzByteBuffer\r\n{\r\n  size_t Capacity;\r\n  Byte *Items;\r\n}CSzByteBuffer;\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer);\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zDecode.c",
    "content": "/* 7zDecode.c */\r\n\r\n#include <memory.h>\r\n\r\n#include \"7zDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#else\r\n#include \"../../Compress/Lzma/LzmaDecode.h\"\r\n#include \"../../Compress/Branch/BranchX86.h\"\r\n#include \"../../Compress/Branch/BranchX86_2.h\"\r\n#endif\r\n\r\n#define k_Copy 0\r\n#define k_LZMA 0x30101\r\n#define k_BCJ 0x03030103\r\n#define k_BCJ2 0x0303011B\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\ntypedef struct _CLzmaInCallbackImp\r\n{\r\n  ILzmaInCallback InCallback;\r\n  ISzInStream *InStream;\r\n  CFileSize Size;\r\n} CLzmaInCallbackImp;\r\n\r\nint LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object;\r\n  size_t processedSize;\r\n  SZ_RESULT res;\r\n  size_t curSize = (1 << 20);\r\n  if (curSize > cb->Size)\r\n    curSize = (size_t)cb->Size;\r\n  *size = 0;\r\n  res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, curSize, &processedSize);\r\n  *size = (SizeT)processedSize;\r\n  if (processedSize > curSize)\r\n    return (int)SZE_FAIL;\r\n  cb->Size -= processedSize;\r\n  if (res == SZ_OK)\r\n    return 0;\r\n  return (int)res;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzDecodeLzma(CCoderInfo *coder, CFileSize inSize,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  CLzmaInCallbackImp lzmaCallback;\r\n  #else\r\n  SizeT inProcessed;\r\n  #endif\r\n  \r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  lzmaCallback.Size = inSize;\r\n  lzmaCallback.InStream = inStream;\r\n  lzmaCallback.InCallback.Read = LzmaReadImp;\r\n  #endif\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, \r\n      (unsigned)coder->Properties.Capacity) != LZMA_RESULT_OK)\r\n    return SZE_FAIL;\r\n  \r\n  state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      allocMain->Free(state.Probs);\r\n      return SZE_OUTOFMEMORY;\r\n    }\r\n  }\r\n  LzmaDecoderInit(&state);\r\n  #endif\r\n  \r\n  result = LzmaDecode(&state,\r\n  #ifdef _LZMA_IN_CB\r\n    &lzmaCallback.InCallback,\r\n  #else\r\n    inBuffer, (SizeT)inSize, &inProcessed,\r\n  #endif\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  allocMain->Free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  allocMain->Free(state.Dictionary);\r\n  #endif\r\n  if (result == LZMA_RESULT_DATA_ERROR)\r\n    return SZE_DATA_ERROR;\r\n  if (result != LZMA_RESULT_OK)\r\n    return SZE_FAIL;\r\n  return (outSizeProcessedLoc == outSize) ? SZ_OK : SZE_DATA_ERROR;\r\n}\r\n\r\n#ifdef _LZMA_IN_CB\r\nSZ_RESULT SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer)\r\n{\r\n  while (inSize > 0)\r\n  {\r\n    void *inBuffer;\r\n    size_t processedSize, curSize = (1 << 18);\r\n    if (curSize > inSize)\r\n      curSize = (size_t)(inSize);\r\n    RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, curSize, &processedSize));\r\n    if (processedSize == 0)\r\n      return SZE_DATA_ERROR;\r\n    if (processedSize > curSize)\r\n      return SZE_FAIL;\r\n    memcpy(outBuffer, inBuffer, processedSize);\r\n    outBuffer += processedSize;\r\n    inSize -= processedSize;\r\n  }\r\n  return SZ_OK;\r\n}\r\n#endif\r\n\r\n#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)\r\n#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)\r\n\r\nSZ_RESULT CheckSupportedFolder(const CFolder *f)\r\n{\r\n  if (f->NumCoders < 1 || f->NumCoders > 4)\r\n    return SZE_NOTIMPL;\r\n  if (IS_UNSUPPORTED_CODER(f->Coders[0]))\r\n    return SZE_NOTIMPL;\r\n  if (f->NumCoders == 1)\r\n  {\r\n    if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)\r\n      return SZE_NOTIMPL;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 2)\r\n  {\r\n    if (IS_NO_BCJ(f->Coders[1]) ||\r\n        f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||\r\n        f->NumBindPairs != 1 ||\r\n        f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)\r\n      return SZE_NOTIMPL;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 4)\r\n  {\r\n    if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||\r\n        IS_UNSUPPORTED_CODER(f->Coders[2]) ||\r\n        IS_NO_BCJ2(f->Coders[3]))\r\n      return SZE_NOTIMPL;\r\n    if (f->NumPackStreams != 4 || \r\n        f->PackStreams[0] != 2 ||\r\n        f->PackStreams[1] != 6 ||\r\n        f->PackStreams[2] != 1 ||\r\n        f->PackStreams[3] != 0 ||\r\n        f->NumBindPairs != 3 ||\r\n        f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||\r\n        f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||\r\n        f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)\r\n      return SZE_NOTIMPL;\r\n    return SZ_OK;\r\n  }\r\n  return SZE_NOTIMPL;\r\n}\r\n\r\nCFileSize GetSum(const CFileSize *values, UInt32 index)\r\n{\r\n  CFileSize sum = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < index; i++)\r\n    sum += values[i];\r\n  return sum;\r\n}\r\n\r\nSZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream, CFileSize startPos,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain,\r\n    Byte *tempBuf[])\r\n{\r\n  UInt32 ci;\r\n  size_t tempSizes[3] = { 0, 0, 0};\r\n  size_t tempSize3 = 0;\r\n  Byte *tempBuf3 = 0;\r\n\r\n  RINOK(CheckSupportedFolder(folder));\r\n\r\n  for (ci = 0; ci < folder->NumCoders; ci++)\r\n  {\r\n    CCoderInfo *coder = &folder->Coders[ci];\r\n\r\n    if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)\r\n    {\r\n      UInt32 si = 0;\r\n      CFileSize offset;\r\n      CFileSize inSize;\r\n      Byte *outBufCur = outBuffer;\r\n      size_t outSizeCur = outSize;\r\n      if (folder->NumCoders == 4)\r\n      {\r\n        UInt32 indices[] = { 3, 2, 0 };\r\n        CFileSize unpackSize = folder->UnPackSizes[ci];\r\n        si = indices[ci];\r\n        if (ci < 2)\r\n        {\r\n          Byte *temp;\r\n          outSizeCur = (size_t)unpackSize;\r\n          if (outSizeCur != unpackSize)\r\n            return SZE_OUTOFMEMORY;\r\n          temp = (Byte *)allocMain->Alloc(outSizeCur);\r\n          if (temp == 0 && outSizeCur != 0)\r\n            return SZE_OUTOFMEMORY;\r\n          outBufCur = tempBuf[1 - ci] = temp;\r\n          tempSizes[1 - ci] = outSizeCur;\r\n        }\r\n        else if (ci == 2)\r\n        {\r\n          if (unpackSize > outSize)\r\n            return SZE_OUTOFMEMORY;\r\n          tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);\r\n          tempSize3 = outSizeCur = (size_t)unpackSize;\r\n        }\r\n        else\r\n          return SZE_NOTIMPL;\r\n      }\r\n      offset = GetSum(packSizes, si);\r\n      inSize = packSizes[si];\r\n      #ifdef _LZMA_IN_CB\r\n      RINOK(inStream->Seek(inStream, startPos + offset));\r\n      #endif\r\n\r\n      if (coder->MethodID == k_Copy)\r\n      {\r\n        if (inSize != outSizeCur)\r\n          return SZE_DATA_ERROR;\r\n        \r\n        #ifdef _LZMA_IN_CB\r\n        RINOK(SzDecodeCopy(inSize, inStream, outBufCur));\r\n        #else\r\n        memcpy(outBufCur, inBuffer + (size_t)offset, (size_t)inSize);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        SZ_RESULT res = SzDecodeLzma(coder, inSize,\r\n            #ifdef _LZMA_IN_CB\r\n            inStream,\r\n            #else\r\n            inBuffer + (size_t)offset,\r\n            #endif\r\n            outBufCur, outSizeCur, allocMain);\r\n        RINOK(res)\r\n      }\r\n    }\r\n    else if (coder->MethodID == k_BCJ)\r\n    {\r\n      UInt32 state;\r\n      if (ci != 1)\r\n        return SZE_NOTIMPL;\r\n      x86_Convert_Init(state);\r\n      x86_Convert(outBuffer, outSize, 0, &state, 0);\r\n    }\r\n    else if (coder->MethodID == k_BCJ2)\r\n    {\r\n      CFileSize offset = GetSum(packSizes, 1);\r\n      CFileSize s3Size = packSizes[1];\r\n      SZ_RESULT res;\r\n      if (ci != 3)\r\n        return SZE_NOTIMPL;\r\n\r\n      #ifdef _LZMA_IN_CB\r\n      RINOK(inStream->Seek(inStream, startPos + offset));\r\n      tempSizes[2] = (size_t)s3Size;\r\n      if (tempSizes[2] != s3Size)\r\n        return SZE_OUTOFMEMORY;\r\n      tempBuf[2] = (Byte *)allocMain->Alloc(tempSizes[2]);\r\n      if (tempBuf[2] == 0 && tempSizes[2] != 0)\r\n        return SZE_OUTOFMEMORY;\r\n      res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);\r\n      RINOK(res)\r\n      #endif\r\n\r\n      res = x86_2_Decode(\r\n          tempBuf3, tempSize3, \r\n          tempBuf[0], tempSizes[0], \r\n          tempBuf[1], tempSizes[1], \r\n          #ifdef _LZMA_IN_CB\r\n          tempBuf[2], tempSizes[2], \r\n          #else\r\n          inBuffer + (size_t)offset, (size_t)s3Size, \r\n          #endif\r\n          outBuffer, outSize);\r\n      RINOK(res)\r\n    }\r\n    else \r\n      return SZE_NOTIMPL;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream, CFileSize startPos,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  Byte *tempBuf[3] = { 0, 0, 0};\r\n  int i;\r\n  SZ_RESULT res = SzDecode2(packSizes, folder,\r\n      #ifdef _LZMA_IN_CB\r\n      inStream, startPos,\r\n      #else\r\n      inBuffer,\r\n      #endif\r\n      outBuffer, outSize, allocMain, tempBuf);\r\n  for (i = 0; i < 3; i++)\r\n    allocMain->Free(tempBuf[i]);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zDecode.h",
    "content": "/* 7zDecode.h */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n#ifdef _LZMA_IN_CB\r\n#include \"7zIn.h\"\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *stream, CFileSize startPos,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zExtract.c",
    "content": "/* 7zExtract.c */\r\n\r\n#include \"7zExtract.h\"\r\n#include \"7zDecode.h\"\r\n#include \"../../7zCrc.h\"\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer, \r\n    size_t *outBufferSize,\r\n    size_t *offset, \r\n    size_t *outSizeProcessed, \r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];\r\n  SZ_RESULT res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    allocMain->Free(*outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CFolder *folder = db->Database.Folders + folderIndex;\r\n    CFileSize unPackSizeSpec = SzFolderGetUnPackSize(folder);\r\n    size_t unPackSize = (size_t)unPackSizeSpec;\r\n    CFileSize startOffset = SzArDbGetFolderStreamPos(db, folderIndex, 0);\r\n    #ifndef _LZMA_IN_CB\r\n    Byte *inBuffer = 0;\r\n    size_t processedSize;\r\n    CFileSize packSizeSpec;\r\n    size_t packSize;\r\n    RINOK(SzArDbGetFolderFullPackSize(db, folderIndex, &packSizeSpec));\r\n    packSize = (size_t)packSizeSpec;\r\n    if (packSize != packSizeSpec)\r\n      return SZE_OUTOFMEMORY;\r\n    #endif\r\n    if (unPackSize != unPackSizeSpec)\r\n      return SZE_OUTOFMEMORY;\r\n    *blockIndex = folderIndex;\r\n    allocMain->Free(*outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(inStream->Seek(inStream, startOffset));\r\n    \r\n    #ifndef _LZMA_IN_CB\r\n    if (packSize != 0)\r\n    {\r\n      inBuffer = (Byte *)allocTemp->Alloc(packSize);\r\n      if (inBuffer == 0)\r\n        return SZE_OUTOFMEMORY;\r\n    }\r\n    res = inStream->Read(inStream, inBuffer, packSize, &processedSize);\r\n    if (res == SZ_OK && processedSize != packSize)\r\n      res = SZE_FAIL;\r\n    #endif\r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = unPackSize;\r\n      if (unPackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)allocMain->Alloc(unPackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZE_OUTOFMEMORY;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        res = SzDecode(db->Database.PackSizes + \r\n          db->FolderStartPackStreamIndex[folderIndex], folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream, startOffset, \r\n          #else\r\n          inBuffer, \r\n          #endif\r\n          *outBuffer, unPackSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (folder->UnPackCRCDefined)\r\n          {\r\n            if (CrcCalc(*outBuffer, unPackSize) != folder->UnPackCRC)\r\n              res = SZE_CRC_ERROR;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    #ifndef _LZMA_IN_CB\r\n    allocTemp->Free(inBuffer);\r\n    #endif\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i; \r\n    CFileItem *fileItem = db->Database.Files + fileIndex;\r\n    *offset = 0;\r\n    for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)db->Database.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZE_FAIL;\r\n    {\r\n      if (fileItem->IsFileCRCDefined)\r\n      {\r\n        if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)\r\n          res = SZE_CRC_ERROR;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zExtract.h",
    "content": "/* 7zExtract.h */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive. \r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send \r\n    these values from previous call:\r\n      *blockIndex, \r\n      *outBuffer, \r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid, \r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables \r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zHeader.c",
    "content": "/*  7zHeader.c */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zHeader.h",
    "content": "/* 7zHeader.h */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnPackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnPackSize,\r\n  k7zIdNumUnPackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCreationTime,\r\n  k7zIdLastAccessTime,\r\n  k7zIdLastWriteTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zIn.c",
    "content": "/* 7zIn.c */\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zDecode.h\"\r\n#include \"../../7zCrc.h\"\r\n\r\n#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db)\r\n{\r\n  SzArchiveDatabaseInit(&db->Database);\r\n  db->FolderStartPackStreamIndex = 0;\r\n  db->PackStreamStartPositions = 0;\r\n  db->FolderStartFileIndex = 0;\r\n  db->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(db->FolderStartPackStreamIndex);\r\n  freeFunc(db->PackStreamStartPositions);\r\n  freeFunc(db->FolderStartFileIndex);\r\n  freeFunc(db->FileIndexToFolderIndexMap);\r\n  SzArchiveDatabaseFree(&db->Database, freeFunc);\r\n  SzArDbExInit(db);\r\n}\r\n\r\n/*\r\nCFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nCFileSize GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n#define MY_ALLOC(T, p, size, allocFunc) { if ((size) == 0) p = 0; else \\\r\n  if ((p = (T *)allocFunc((size) * sizeof(T))) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nSZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 startPos = 0;\r\n  CFileSize startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  MY_ALLOC(UInt32, db->FolderStartPackStreamIndex, db->Database.NumFolders, allocFunc);\r\n  for(i = 0; i < db->Database.NumFolders; i++)\r\n  {\r\n    db->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += db->Database.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  MY_ALLOC(CFileSize, db->PackStreamStartPositions, db->Database.NumPackStreams, allocFunc);\r\n\r\n  for(i = 0; i < db->Database.NumPackStreams; i++)\r\n  {\r\n    db->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += db->Database.PackSizes[i];\r\n  }\r\n\r\n  MY_ALLOC(UInt32, db->FolderStartFileIndex, db->Database.NumFolders, allocFunc);\r\n  MY_ALLOC(UInt32, db->FileIndexToFolderIndexMap, db->Database.NumFiles, allocFunc);\r\n\r\n  for (i = 0; i < db->Database.NumFiles; i++)\r\n  {\r\n    CFileItem *file = db->Database.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      db->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= db->Database.NumFolders)\r\n          return SZE_ARCHIVE_ERROR;\r\n        db->FolderStartFileIndex[folderIndex] = i;\r\n        if (db->Database.Folders[folderIndex].NumUnPackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    db->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return db->ArchiveInfo.DataStartPosition + \r\n    db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nint SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize)\r\n{\r\n  UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n  CFolder *folder = db->Database.Folders + folderIndex;\r\n  CFileSize size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n  {\r\n    CFileSize t = size + db->Database.PackSizes[packStreamIndex + i];\r\n    if (t < size)\r\n      return SZE_FAIL;\r\n    size = t;\r\n  }\r\n  *resSize = size;\r\n  return SZ_OK;\r\n}\r\n\r\n\r\n/*\r\nSZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case k7zIdLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case k7zIdLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nSZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  while (size > 0)\r\n  {\r\n    void *inBufferSpec;\r\n    size_t processedSize;\r\n    const Byte *inBuffer;\r\n    RINOK(inStream->Read(inStream, (void **)&inBufferSpec, size, &processedSize));\r\n    inBuffer = (const Byte *)inBufferSpec;\r\n    if (processedSize == 0 || processedSize > size)\r\n      return SZE_FAIL;\r\n    size -= processedSize;\r\n    do\r\n    {\r\n      *data++ = *inBuffer++;\r\n    }\r\n    while (--processedSize != 0);\r\n  }\r\n  #else\r\n  size_t processedSize;\r\n  RINOK(inStream->Read(inStream, data, size, &processedSize));\r\n  if (processedSize != size)\r\n    return SZE_FAIL;\r\n  #endif\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data)\r\n{\r\n  return SafeReadDirect(inStream, data, 1);\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n    *crc = CRC_UPDATE_BYTE(*crc, b);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    *crc = CRC_UPDATE_BYTE(*crc, b);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nint TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nSZ_RESULT SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  *value = (CFileSize)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZE_NOTIMPL;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZE_NOTIMPL;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadID(CSzData *sd, UInt64 *value) \r\n{ \r\n  return SzReadNumber(sd, value); \r\n}\r\n\r\nSZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nSZ_RESULT SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZE_ARCHIVE_ERROR;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  MY_ALLOC(Byte, *v, numItems, allocFunc);\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, allocFunc);\r\n  MY_ALLOC(Byte, *v, numItems, allocFunc);\r\n  for(i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHashDigests(\r\n    CSzData *sd, \r\n    size_t numItems,\r\n    Byte **digestsDefined, \r\n    UInt32 **digests, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc));\r\n  MY_ALLOC(UInt32, *digests, numItems, allocFunc);\r\n  for(i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadPackInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    CFileSize **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadSize(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, allocFunc);\r\n\r\n  for(i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadSize(sd, (*packSizes) + i));\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc)); \r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, allocFunc);\r\n    MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, allocFunc);\r\n    for(i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR;\r\n}\r\n\r\nSZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 numCoders;\r\n  UInt32 numBindPairs;\r\n  UInt32 numPackedStreams;\r\n  UInt32 i;\r\n  UInt32 numInStreams = 0;\r\n  UInt32 numOutStreams = 0;\r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  folder->NumCoders = numCoders;\r\n\r\n  MY_ALLOC(CCoderInfo, folder->Coders, (size_t)numCoders, allocFunc);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfoInit(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      unsigned idSize, j;\r\n      Byte longID[15];\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      idSize = (unsigned)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, longID, idSize));\r\n      if (idSize > sizeof(coder->MethodID))\r\n        return SZE_NOTIMPL;\r\n      coder->MethodID = 0;\r\n      for (j = 0; j < idSize; j++)\r\n        coder->MethodID |= (CMethodID)longID[idSize - 1 - j] << (8 * j);\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc))\r\n          return SZE_OUTOFMEMORY;\r\n        RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += (UInt32)coder->NumInStreams;\r\n    numOutStreams += (UInt32)coder->NumOutStreams;\r\n  }\r\n\r\n  numBindPairs = numOutStreams - 1;\r\n  folder->NumBindPairs = numBindPairs;\r\n\r\n\r\n  MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, allocFunc);\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bindPair = folder->BindPairs + i;;\r\n    RINOK(SzReadNumber32(sd, &bindPair->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bindPair->OutIndex)); \r\n  }\r\n\r\n  numPackedStreams = numInStreams - (UInt32)numBindPairs;\r\n\r\n  folder->NumPackStreams = numPackedStreams;\r\n  MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, allocFunc);\r\n\r\n  if (numPackedStreams == 1)\r\n  {\r\n    UInt32 j;\r\n    UInt32 pi = 0;\r\n    for (j = 0; j < numInStreams; j++)\r\n      if (SzFolderFindBindPairForInStream(folder, j) < 0)\r\n      {\r\n        folder->PackStreams[pi++] = j;\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUnPackInfo(\r\n    CSzData *sd, \r\n    UInt32 *numFolders,\r\n    CFolder **folders,  /* for allocFunc */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n    MY_ALLOC(CFolder, *folders, (size_t)*numFolders, allocFunc);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n      SzFolderInit((*folders) + i);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));\r\n\r\n  for(i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolderGetNumOutStreams(folder);\r\n\r\n    MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, allocFunc);\r\n\r\n    for(j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadSize(sd, folder->UnPackSizes + j));\r\n    }\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SZ_RESULT res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc); \r\n      if (res == SZ_OK)\r\n      {\r\n        for(i = 0; i < *numFolders; i++)\r\n        {\r\n          CFolder *folder = (*folders) + i;\r\n          folder->UnPackCRCDefined = crcsDefined[i];\r\n          folder->UnPackCRC = crcs[i];\r\n        }\r\n      }\r\n      allocTemp->Free(crcs);\r\n      allocTemp->Free(crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadSubStreamsInfo(\r\n    CSzData *sd, \r\n    UInt32 numFolders,\r\n    CFolder *folders,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n    folders[i].NumUnPackStreams = 1;\r\n  *numUnPackStreams = numFolders;\r\n\r\n  for (;;)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnPackStream)\r\n    {\r\n      *numUnPackStreams = 0;\r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnPackStreams = numStreams;\r\n        *numUnPackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnPackStreams == 0)\r\n  {\r\n    *unPackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize));\r\n    RINOM(*unPackSizes);\r\n    *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    CFileSize sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      CFileSize size;\r\n      RINOK(SzReadSize(sd, &size));\r\n      (*unPackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for(i = 0; i < *numUnPackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  for (;;)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0; \r\n      UInt32 *digests2 = 0;\r\n      SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnPackStreams;\r\n          if (numSubstreams == 1 && folder->UnPackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnPackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      allocTemp->Free(digestsDefined2);\r\n      allocTemp->Free(digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nSZ_RESULT SzReadStreamsInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    CArchiveDatabase *db,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZE_FAIL;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams, \r\n            &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc));\r\n        break;\r\n      }\r\n      case k7zIdUnPackInfo:\r\n      {\r\n        RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders, \r\n            numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZE_FAIL;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nSZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CFileItem *file = files + i;\r\n    while(pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZE_ARCHIVE_ERROR;\r\n        if (pos + 2 > sd->Size)\r\n          return SZE_ARCHIVE_ERROR;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZE_ARCHIVE_ERROR;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    MY_ALLOC(char, file->Name, (size_t)len, allocFunc);\r\n\r\n    len = 0;\r\n    while(2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while(numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHeader2(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db,   /* allocMain */\r\n    CFileSize **unPackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    Byte **lwtVector,         /* allocTemp */\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnPackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &db->ArchiveInfo.DataStartPosition,\r\n        &db->Database, \r\n        &numUnPackStreams,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests, allocMain->Alloc, allocTemp));\r\n    db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZE_ARCHIVE_ERROR;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  db->Database.NumFiles = numFiles;\r\n\r\n  MY_ALLOC(CFileItem, files, (size_t)numFiles, allocMain->Alloc);\r\n\r\n  db->Database.Files = files;\r\n  for(i = 0; i < numFiles; i++)\r\n    SzFileInit(files + i);\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc));\r\n        break;\r\n      }\r\n      case k7zIdLastWriteTime:\r\n      {\r\n        RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp->Alloc));\r\n        RINOK(SzReadSwitch(sd));\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem *f = &files[i];\r\n          Byte defined = (*lwtVector)[i];\r\n          f->IsLastWriteTimeDefined = defined;\r\n          f->LastWriteTime.Low = f->LastWriteTime.High = 0;\r\n          if (defined)\r\n          {\r\n            RINOK(SzReadUInt32(sd, &f->LastWriteTime.Low));\r\n            RINOK(SzReadUInt32(sd, &f->LastWriteTime.High));\r\n          }\r\n        }\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for(i = 0; i < numFiles; i++)\r\n    {\r\n      CFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if(file->HasStream)\r\n      {\r\n        file->IsDirectory = 0;\r\n        file->Size = (*unPackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->IsFileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDirectory = 1;\r\n        else\r\n          file->IsDirectory = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->IsFileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArDbExFill(db, allocMain->Alloc);\r\n}\r\n\r\nSZ_RESULT SzReadHeader(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db, \r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  Byte *lwtVector = 0;\r\n  SZ_RESULT res = SzReadHeader2(sd, db, \r\n      &unPackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector, &lwtVector, \r\n      allocMain, allocTemp);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  allocTemp->Free(emptyStreamVector);\r\n  allocTemp->Free(emptyFileVector);\r\n  allocTemp->Free(lwtVector);\r\n  return res;\r\n} \r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams2(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    CArchiveDatabase *db,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    #ifndef _LZMA_IN_CB\r\n    Byte **inBuffer,\r\n    #endif\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnPackStreams = 0;\r\n  CFileSize dataStartPos;\r\n  CFolder *folder;\r\n  #ifndef _LZMA_IN_CB\r\n  CFileSize packSize = 0;\r\n  UInt32 i = 0;\r\n  #endif\r\n  CFileSize unPackSize;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, db,\r\n      &numUnPackStreams,  unPackSizes, digestsDefined, digests, \r\n      allocTemp->Alloc, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (db->NumFolders != 1)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  folder = db->Folders;\r\n  unPackSize = SzFolderGetUnPackSize(folder);\r\n  \r\n  RINOK(inStream->Seek(inStream, dataStartPos));\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  for (i = 0; i < db->NumPackStreams; i++)\r\n    packSize += db->PackSizes[i];\r\n\r\n  MY_ALLOC(Byte, *inBuffer, (size_t)packSize, allocTemp->Alloc);\r\n\r\n  RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize));\r\n  #endif\r\n\r\n  if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  res = SzDecode(db->PackSizes, folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream, dataStartPos, \r\n          #else\r\n          *inBuffer, \r\n          #endif\r\n          outBuffer->Items, (size_t)unPackSize, allocTemp);\r\n  RINOK(res)\r\n  if (folder->UnPackCRCDefined)\r\n    if (CrcCalc(outBuffer->Items, (size_t)unPackSize) != folder->UnPackCRC)\r\n      return SZE_FAIL;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CArchiveDatabase db;\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  #ifndef _LZMA_IN_CB\r\n  Byte *inBuffer = 0;\r\n  #endif\r\n  SZ_RESULT res;\r\n  SzArchiveDatabaseInit(&db);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset, \r\n    &db, &unPackSizes, &digestsDefined, &digests, \r\n    #ifndef _LZMA_IN_CB\r\n    &inBuffer,\r\n    #endif\r\n    allocTemp);\r\n  SzArchiveDatabaseFree(&db, allocTemp->Free);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  #ifndef _LZMA_IN_CB\r\n  allocTemp->Free(inBuffer);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen2(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte signature[k7zSignatureSize];\r\n  Byte version;\r\n  UInt32 crcFromArchive;\r\n  UInt64 nextHeaderOffset;\r\n  UInt64 nextHeaderSize;\r\n  UInt32 nextHeaderCRC;\r\n  UInt32 crc = 0;\r\n  CFileSize pos = 0;\r\n  CSzByteBuffer buffer;\r\n  CSzData sd;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize));\r\n\r\n  if (!TestSignatureCandidate(signature))\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  /*\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n  */\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n  if (version != k7zMajorVersion)\r\n    return SZE_ARCHIVE_ERROR;\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n\r\n  RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive, &crc));\r\n\r\n  crc = CRC_INIT_VAL;\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset, &crc));\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize, &crc));\r\n  RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC, &crc));\r\n\r\n  pos = k7zStartHeaderSize;\r\n  db->ArchiveInfo.StartPositionAfterHeader = pos;\r\n  \r\n  if (CRC_GET_DIGEST(crc) != crcFromArchive)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  if (nextHeaderSize == 0)\r\n    return SZ_OK;\r\n\r\n  RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset)));\r\n\r\n  if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = SZE_ARCHIVE_ERROR;\r\n    if (CrcCalc(buffer.Items, (UInt32)nextHeaderSize) == nextHeaderCRC)\r\n    {\r\n      for (;;)\r\n      {\r\n        UInt64 type;\r\n        sd.Data = buffer.Items;\r\n        sd.Size = buffer.Capacity;\r\n        res = SzReadID(&sd, &type);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (type == k7zIdHeader)\r\n        {\r\n          res = SzReadHeader(&sd, db, allocMain, allocTemp);\r\n          break;\r\n        }\r\n        if (type != k7zIdEncodedHeader)\r\n        {\r\n          res = SZE_ARCHIVE_ERROR;\r\n          break;\r\n        }\r\n        {\r\n          CSzByteBuffer outBuffer;\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, \r\n              db->ArchiveInfo.StartPositionAfterHeader, \r\n              allocTemp);\r\n          if (res != SZ_OK)\r\n          {\r\n            SzByteBufferFree(&outBuffer, allocTemp->Free);\r\n            break;\r\n          }\r\n          SzByteBufferFree(&buffer, allocTemp->Free);\r\n          buffer.Items = outBuffer.Items;\r\n          buffer.Capacity = outBuffer.Capacity;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  SzByteBufferFree(&buffer, allocTemp->Free);\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArDbExFree(db, allocMain->Free);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zIn.h",
    "content": "/* 7zIn.h */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n \r\ntypedef struct _CInArchiveInfo\r\n{\r\n  CFileSize StartPositionAfterHeader; \r\n  CFileSize DataStartPosition;\r\n}CInArchiveInfo;\r\n\r\ntypedef struct _CArchiveDatabaseEx\r\n{\r\n  CArchiveDatabase Database;\r\n  CInArchiveInfo ArchiveInfo;\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  CFileSize *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n}CArchiveDatabaseEx;\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db);\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);\r\nint SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize);\r\n\r\ntypedef struct _ISzInStream\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  SZ_RESULT (*Read)(\r\n      void *object,           /* pointer to ISzInStream itself */\r\n      void **buffer,          /* out: pointer to buffer with data */\r\n      size_t maxRequiredSize, /* max required size to read */\r\n      size_t *processedSize); /* real processed size. \r\n                                 processedSize can be less than maxRequiredSize.\r\n                                 If processedSize == 0, then there are no more \r\n                                 bytes in stream. */\r\n  #else\r\n  SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);\r\n  #endif\r\n  SZ_RESULT (*Seek)(void *object, CFileSize pos);\r\n} ISzInStream;\r\n\r\n \r\nint SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zItem.c",
    "content": "/* 7zItem.c */\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder)\r\n{\r\n  SzByteBufferInit(&coder->Properties);\r\n}\r\n\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))\r\n{\r\n  SzByteBufferFree(&coder->Properties, freeFunc);\r\n  SzCoderInfoInit(coder);\r\n}\r\n\r\nvoid SzFolderInit(CFolder *folder)\r\n{\r\n  folder->NumCoders = 0;\r\n  folder->Coders = 0;\r\n  folder->NumBindPairs = 0;\r\n  folder->BindPairs = 0;\r\n  folder->NumPackStreams = 0;\r\n  folder->PackStreams = 0;\r\n  folder->UnPackSizes = 0;\r\n  folder->UnPackCRCDefined = 0;\r\n  folder->UnPackCRC = 0;\r\n  folder->NumUnPackStreams = 0;\r\n}\r\n\r\nvoid SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    SzCoderInfoFree(&folder->Coders[i], freeFunc);\r\n  freeFunc(folder->Coders);\r\n  freeFunc(folder->BindPairs);\r\n  freeFunc(folder->PackStreams);\r\n  freeFunc(folder->UnPackSizes);\r\n  SzFolderInit(folder);\r\n}\r\n\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    result += folder->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder)\r\n{ \r\n  int i = (int)SzFolderGetNumOutStreams(folder);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolderFindBindPairForOutStream(folder, i) < 0)\r\n      return folder->UnPackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\n/*\r\nint FindPackStreamArrayIndex(int inStreamIndex) const\r\n{\r\n  for(int i = 0; i < PackStreams.Size(); i++)\r\n  if (PackStreams[i] == inStreamIndex)\r\n    return i;\r\n  return -1;\r\n}\r\n*/\r\n\r\nvoid SzFileInit(CFileItem *fileItem)\r\n{\r\n  fileItem->IsFileCRCDefined = 0;\r\n  fileItem->HasStream = 1;\r\n  fileItem->IsDirectory = 0;\r\n  fileItem->IsAnti = 0;\r\n  fileItem->IsLastWriteTimeDefined = 0;\r\n  fileItem->Name = 0;\r\n}\r\n\r\nvoid SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))\r\n{\r\n  freeFunc(fileItem->Name);\r\n  SzFileInit(fileItem);\r\n}\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db)\r\n{\r\n  db->NumPackStreams = 0;\r\n  db->PackSizes = 0;\r\n  db->PackCRCsDefined = 0;\r\n  db->PackCRCs = 0;\r\n  db->NumFolders = 0;\r\n  db->Folders = 0;\r\n  db->NumFiles = 0;\r\n  db->Files = 0;\r\n}\r\n\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < db->NumFolders; i++)\r\n    SzFolderFree(&db->Folders[i], freeFunc);\r\n  for (i = 0; i < db->NumFiles; i++)\r\n    SzFileFree(&db->Files[i], freeFunc);\r\n  freeFunc(db->PackSizes);\r\n  freeFunc(db->PackCRCsDefined);\r\n  freeFunc(db->PackCRCs);\r\n  freeFunc(db->Folders);\r\n  freeFunc(db->Files);\r\n  SzArchiveDatabaseInit(db);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zItem.h",
    "content": "/* 7zItem.h */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"7zMethodID.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zBuffer.h\"\r\n\r\ntypedef struct _CCoderInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  CMethodID MethodID;\r\n  CSzByteBuffer Properties;\r\n}CCoderInfo;\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder);\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));\r\n\r\ntypedef struct _CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n}CBindPair;\r\n\r\ntypedef struct _CFolder\r\n{\r\n  UInt32 NumCoders;\r\n  CCoderInfo *Coders;\r\n  UInt32 NumBindPairs;\r\n  CBindPair *BindPairs;\r\n  UInt32 NumPackStreams; \r\n  UInt32 *PackStreams;\r\n  CFileSize *UnPackSizes;\r\n  int UnPackCRCDefined;\r\n  UInt32 UnPackCRC;\r\n\r\n  UInt32 NumUnPackStreams;\r\n}CFolder;\r\n\r\nvoid SzFolderInit(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\n\r\ntypedef struct _CArchiveFileTime\r\n{\r\n  UInt32 Low;\r\n  UInt32 High;\r\n} CArchiveFileTime;\r\n\r\ntypedef struct _CFileItem\r\n{\r\n  CArchiveFileTime LastWriteTime;\r\n  /*\r\n  CFileSize StartPos;\r\n  UInt32 Attributes; \r\n  */\r\n  CFileSize Size;\r\n  UInt32 FileCRC;\r\n  char *Name;\r\n\r\n  Byte IsFileCRCDefined;\r\n  Byte HasStream;\r\n  Byte IsDirectory;\r\n  Byte IsAnti;\r\n  Byte IsLastWriteTimeDefined;\r\n  /*\r\n  int AreAttributesDefined;\r\n  int IsLastWriteTimeDefined;\r\n  int IsStartPosDefined;\r\n  */\r\n}CFileItem;\r\n\r\nvoid SzFileInit(CFileItem *fileItem);\r\n\r\ntypedef struct _CArchiveDatabase\r\n{\r\n  UInt32 NumPackStreams;\r\n  CFileSize *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  UInt32 NumFolders;\r\n  CFolder *Folders;\r\n  UInt32 NumFiles;\r\n  CFileItem *Files;\r\n}CArchiveDatabase;\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db);\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));\r\n\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zMain.c",
    "content": "/* \r\n7zMain.c\r\nTest application for 7z Decoder\r\nLZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-06-04)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#ifdef _WIN32\r\n#define USE_WINDOWS_FUNCTIONS\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FUNCTIONS\r\n#include <windows.h>\r\n#endif\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zExtract.h\"\r\n\r\n#include \"../../7zCrc.h\"\r\n\r\n\r\n#ifdef USE_WINDOWS_FUNCTIONS\r\ntypedef HANDLE MY_FILE_HANDLE;\r\n#else\r\ntypedef FILE *MY_FILE_HANDLE;\r\n#endif\r\n\r\nvoid ConvertNumberToString(CFileSize value, char *s)\r\n{\r\n  char temp[32];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    temp[pos++] = (char)('0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while(pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\n#define PERIOD_4 (4 * 365 + 1)\r\n#define PERIOD_100 (PERIOD_4 * 25 - 1)\r\n#define PERIOD_400 (PERIOD_100 * 4 + 1)\r\n\r\nvoid ConvertFileTimeToString(CArchiveFileTime *ft, char *s)\r\n{\r\n  unsigned year, mon, day, hour, min, sec;\r\n  UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  unsigned temp;\r\n  UInt32 v; \r\n  v64 /= 10000000;\r\n  sec = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  min = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  hour = (unsigned)(v64 % 24);\r\n  v64 /= 24;\r\n\r\n  v = (UInt32)v64;\r\n\r\n  year = (unsigned)(1601 + v / PERIOD_400 * 400);\r\n  v %= PERIOD_400;\r\n\r\n  temp = (unsigned)(v / PERIOD_100);\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp * 100;\r\n  v -= temp * PERIOD_100;\r\n\r\n  temp = v / PERIOD_4;\r\n  if (temp == 25)\r\n    temp = 24;\r\n  year += temp * 4;\r\n  v -= temp * PERIOD_4;\r\n\r\n  temp = v / 365;\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp;\r\n  v -= temp * 365;\r\n\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  for (mon = 1; mon <= 12; mon++)\r\n  {\r\n    unsigned s = ms[mon - 1];\r\n    if (v < s)\r\n      break;\r\n    v -= s;\r\n  }\r\n  day = (unsigned)v + 1;\r\n  sprintf(s, \"%04d-%02d-%02d %02d:%02d:%02d\", year, mon, day, hour, min, sec);\r\n}\r\n\r\n\r\n#ifdef USE_WINDOWS_FUNCTIONS\r\n/*\r\n   ReadFile and WriteFile functions in Windows have BUG:\r\n   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n   (Insufficient system resources exist to complete the requested service).\r\n*/\r\n#define kChunkSizeMax (1 << 24)\r\n#endif\r\n\r\nsize_t MyReadFile(MY_FILE_HANDLE file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  {\r\n    size_t processedSize = 0;\r\n    do\r\n    {\r\n      DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;\r\n      DWORD processedLoc = 0;\r\n      BOOL res = ReadFile(file, data, curSize, &processedLoc, NULL);\r\n      data = (void *)((unsigned char *)data + processedLoc);\r\n      size -= processedLoc;\r\n      processedSize += processedLoc;\r\n      if (!res || processedLoc == 0)\r\n        break;\r\n    }\r\n    while (size > 0);\r\n    return processedSize;\r\n  }\r\n  #else\r\n  return fread(data, 1, size, file); \r\n  #endif\r\n}\r\n\r\nsize_t MyWriteFile(MY_FILE_HANDLE file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  {\r\n    size_t processedSize = 0;\r\n    do\r\n    {\r\n      DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;\r\n      DWORD processedLoc = 0;\r\n      BOOL res = WriteFile(file, data, curSize, &processedLoc, NULL);\r\n      data = (void *)((unsigned char *)data + processedLoc);\r\n      size -= processedLoc;\r\n      processedSize += processedLoc;\r\n      if (!res)\r\n        break;\r\n    }\r\n    while (size > 0);\r\n    return processedSize;\r\n  }\r\n  #else\r\n  return fwrite(data, 1, size, file); \r\n  #endif\r\n}\r\n\r\nint MyCloseFile(MY_FILE_HANDLE file)\r\n{ \r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  return (CloseHandle(file) != FALSE) ? 0 : 1;\r\n  #else\r\n  return fclose(file); \r\n  #endif\r\n}\r\n\r\ntypedef struct _CFileInStream\r\n{\r\n  ISzInStream InStream;\r\n  MY_FILE_HANDLE File;\r\n} CFileInStream;\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define kBufferSize (1 << 12)\r\nByte g_Buffer[kBufferSize];\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc;\r\n  if (maxRequiredSize > kBufferSize)\r\n    maxRequiredSize = kBufferSize;\r\n  processedSizeLoc = MyReadFile(s->File, g_Buffer, maxRequiredSize);\r\n  *buffer = g_Buffer;\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#else\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc = MyReadFile(s->File, buffer, size);\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzFileSeekImp(void *object, CFileSize pos)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n\r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  {\r\n    LARGE_INTEGER value;\r\n    value.LowPart = (DWORD)pos;\r\n    value.HighPart = (LONG)((UInt64)pos >> 32);\r\n    #ifdef _SZ_FILE_SIZE_32\r\n    /* VC 6.0 has bug with >> 32 shifts. */\r\n    value.HighPart = 0;\r\n    #endif\r\n    value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, FILE_BEGIN);\r\n    if (value.LowPart == 0xFFFFFFFF)\r\n      if(GetLastError() != NO_ERROR) \r\n        return SZE_FAIL;\r\n    return SZ_OK;\r\n  }\r\n  #else\r\n  int res = fseek(s->File, (long)pos, SEEK_SET);\r\n  if (res == 0)\r\n    return SZ_OK;\r\n  return SZE_FAIL;\r\n  #endif\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CArchiveDatabaseEx db;\r\n  SZ_RESULT res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder 4.48  Copyright (c) 1999-2007 Igor Pavlov  2007-06-21\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.File = \r\n  #ifdef USE_WINDOWS_FUNCTIONS\r\n  CreateFile(args[2], GENERIC_READ, FILE_SHARE_READ, \r\n      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);\r\n  if (archiveStream.File == INVALID_HANDLE_VALUE)\r\n  #else\r\n  archiveStream.File = fopen(args[2], \"rb\");\r\n  if (archiveStream.File == 0)\r\n  #endif\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.InStream.Read = SzFileReadImp;\r\n  archiveStream.InStream.Seek = SzFileSeekImp;\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  CrcGenerateTable();\r\n\r\n  SzArDbExInit(&db);\r\n  res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0;\r\n    int testCommand = 0;\r\n    int extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0)\r\n      listCommand = 1;\r\n    if (strcmp(command, \"t\") == 0)\r\n      testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0)\r\n      extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        char s[32], t[32];\r\n        ConvertNumberToString(f->Size, s);\r\n        if (f->IsLastWriteTimeDefined)\r\n          ConvertFileTimeToString(&f->LastWriteTime, t);\r\n        else\r\n          strcpy(t, \"                   \");\r\n\r\n        printf(\"%10s %s  %s\\n\", s, t, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      /*\r\n      if you need cache, use these 3 variables.\r\n      if you use external function, you can make these variable as static.\r\n      */\r\n      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r\n      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r\n      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CFileItem *f = db.Database.Files + i;\r\n        if (f->IsDirectory)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ? \r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDirectory)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzExtract(&archiveStream.InStream, &db, i, \r\n            &blockIndex, &outBuffer, &outBufferSize, \r\n            &offset, &outSizeProcessed, \r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          MY_FILE_HANDLE outputHandle;\r\n          size_t processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          outputHandle = \r\n          #ifdef USE_WINDOWS_FUNCTIONS\r\n            CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_READ, \r\n                NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\r\n          if (outputHandle == INVALID_HANDLE_VALUE)\r\n          #else\r\n          fopen(fileName, \"wb+\");\r\n          if (outputHandle == 0)\r\n          #endif\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          processedSize = MyWriteFile(outputHandle, outBuffer + offset, outSizeProcessed);\r\n          if (processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          if (MyCloseFile(outputHandle))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      allocImp.Free(outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZE_FAIL;\r\n    }\r\n  }\r\n  SzArDbExFree(&db, allocImp.Free);\r\n\r\n  MyCloseFile(archiveStream.File);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == (SZ_RESULT)SZE_NOTIMPL)\r\n    PrintError(\"decoder doesn't support this archive\");\r\n  else if (res == (SZ_RESULT)SZE_OUTOFMEMORY)\r\n    PrintError(\"can not allocate memory\");\r\n  else if (res == (SZ_RESULT)SZE_CRC_ERROR)\r\n    PrintError(\"CRC error\");\r\n  else     \r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zMethodID.c",
    "content": "/* 7zMethodID.c */\r\n\r\n#include \"7zMethodID.h\"\r\n\r\n/*\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2)\r\n{\r\n  return (*a1 == *a2) ? 1 : 0;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7zMethodID.h",
    "content": "/* 7zMethodID.h */\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Types.h\"\r\n\r\ntypedef UInt64 CMethodID;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7z_C.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z_C\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z_C - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\" CFG=\"7z_C - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z_C - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z_C - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z_C - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MD /W4 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z_C - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z_C - Win32 Release\"\r\n# Name \"7z_C - Win32 Debug\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Lzma\\LzmaDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Lzma\\LzmaDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Lzma\\LzmaTypes.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86_2.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchX86_2.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/7z_C.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z_C\"=.\\7z_C.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/makefile",
    "content": "PROG = 7zDec.exe\r\n\r\n!IFDEF CPU\r\nLIBS = $(LIBS) bufferoverflowU.lib \r\nCFLAGS = $(CFLAGS) -GS- -Zc:forScope -WX -GS- -Gy -W4 \r\n!ENDIF\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -D_LZMA_IN_CB\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zBuffer.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n  $O\\7zMethodID.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\BranchX86.obj \\\r\n  $O\\BranchX86_2.obj \\\r\n  $(C_OBJS) \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/Lzma/$(*B).c\r\n\t$(COMPL_O2)\r\n\r\n$O\\BranchX86.obj: ../../Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n\r\n$O\\BranchX86_2.obj: ../../Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Archive/7z/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall -D_LZMA_IN_CB\r\n\r\nOBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o BranchX86.o BranchX86_2.o\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuffer.o: 7zBuffer.c\r\n\t$(CXX) $(CFLAGS) 7zBuffer.c\r\n\r\n7zCrc.o: ../../7zCrc.c\r\n\t$(CXX) $(CFLAGS) ../../7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\n7zMethodID.o: 7zMethodID.c\r\n\t$(CXX) $(CFLAGS) 7zMethodID.c\r\n\r\nLzmaDecode.o: ../../Compress/Lzma/LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/Lzma/LzmaDecode.c\r\n\r\nBranchX86.o: ../../Compress/Branch/BranchX86.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86.c\r\n\r\nBranchX86_2.o: ../../Compress/Branch/BranchX86_2.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86_2.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchARM.c",
    "content": "/* BranchARM.c */\r\n\r\n#include \"BranchARM.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = (data[i + 2] << 16) | (data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = nowPos + i + 8 + src;\r\n      else\r\n        dest = src - (nowPos + i + 8);\r\n      dest >>= 2;\r\n      data[i + 2] = (Byte)(dest >> 16);\r\n      data[i + 1] = (Byte)(dest >> 8);\r\n      data[i + 0] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchARM.h",
    "content": "/* BranchARM.h */\r\n\r\n#ifndef __BRANCH_ARM_H\r\n#define __BRANCH_ARM_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchARMThumb.c",
    "content": "/* BranchARMThumb.c */\r\n\r\n#include \"BranchARMThumb.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 && \r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = \r\n        ((data[i + 1] & 0x7) << 19) |\r\n        (data[i + 0] << 11) |\r\n        ((data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      if (encoding)\r\n        dest = nowPos + i + 4 + src;\r\n      else\r\n        dest = src - (nowPos + i + 4);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));\r\n      data[i + 0] = (Byte)(dest >> 11);\r\n      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));\r\n      data[i + 2] = (Byte)dest;\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchARMThumb.h",
    "content": "/* BranchARMThumb.h */\r\n\r\n#ifndef __BRANCH_ARM_THUMB_H\r\n#define __BRANCH_ARM_THUMB_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchIA64.c",
    "content": "/* BranchIA64.c */\r\n\r\n#include \"BranchIA64.h\"\r\n\r\nconst Byte kBranchTable[32] = \r\n{ \r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0 \r\n};\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 16 <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    int slot;\r\n    for (slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      UInt32 bytePos, bitRes;\r\n      UInt64 instruction, instNorm;\r\n      int j;\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      bytePos = (bitPos >> 3);\r\n      bitRes = bitPos & 0x7;\r\n      instruction = 0;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);\r\n\r\n      instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 \r\n        &&  ((instNorm >> 9) & 0x7) == 0 \r\n        /* &&  (instNorm & 0x3F)== 0 */\r\n        )\r\n      {\r\n        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);\r\n        UInt32 dest;\r\n        src |= ((UInt32)(instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        if (encoding)\r\n          dest = nowPos + i + src;\r\n        else\r\n          dest = src - (nowPos + i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~((UInt64)(0x8FFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchIA64.h",
    "content": "/* BranchIA64.h */\r\n\r\n#ifndef __BRANCH_IA64_H\r\n#define __BRANCH_IA64_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchPPC.c",
    "content": "/* BranchPPC.c */\r\n\r\n#include \"BranchPPC.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    /* PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) */\r\n    if ((data[i] >> 2) == 0x12 && \r\n    (\r\n      (data[i + 3] & 3) == 1 \r\n      /* || (data[i+3] & 3) == 3 */\r\n      )\r\n    )\r\n    {\r\n      UInt32 src = ((data[i + 0] & 3) << 24) |\r\n        (data[i + 1] << 16) |\r\n        (data[i + 2] << 8) |\r\n        (data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchPPC.h",
    "content": "/* BranchPPC.h */\r\n\r\n#ifndef __BRANCH_PPC_H\r\n#define __BRANCH_PPC_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchSPARC.c",
    "content": "/* BranchSPARC.c */\r\n\r\n#include \"BranchSPARC.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || \r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      UInt32 dest;\r\n      \r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchSPARC.h",
    "content": "/* BranchSPARC.h */\r\n\r\n#ifndef __BRANCH_SPARC_H\r\n#define __BRANCH_SPARC_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchTypes.h",
    "content": "/* BranchTypes.h */\r\n\r\n#ifndef __BRANCHTYPES_H\r\n#define __BRANCHTYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif\r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\n#ifdef _SZ_NO_INT_64\r\ntypedef unsigned long UInt64;\r\n#else\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n#endif\r\n#endif\r\n\r\n/* #define _LZMA_NO_SYSTEM_SIZE_T */\r\n/* You can use it, if you don't want <stddef.h> */\r\n\r\n#ifndef _7ZIP_SIZET_DEFINED\r\n#define _7ZIP_SIZET_DEFINED\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\n#include <stddef.h>\r\ntypedef size_t SizeT;\r\n#endif\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchX86.c",
    "content": "/* BranchX86.c */\r\n\r\n#include \"BranchX86.h\"\r\n\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\nSizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *prevMaskMix, int encoding)\r\n{\r\n  SizeT bufferPos = 0, prevPosT;\r\n  UInt32 prevMask = *prevMaskMix & 0x7;\r\n  if (endPos < 5)\r\n    return 0;\r\n  nowPos += 5;\r\n  prevPosT = (SizeT)0 - 1;\r\n\r\n  for(;;)\r\n  {\r\n    Byte *p = buffer + bufferPos;\r\n    Byte *limit = buffer + endPos - 4;\r\n    for (; p < limit; p++)\r\n      if ((*p & 0xFE) == 0xE8)\r\n        break;\r\n    bufferPos = (SizeT)(p - buffer);\r\n    if (p >= limit)\r\n      break;\r\n    prevPosT = bufferPos - prevPosT;\r\n    if (prevPosT > 3)\r\n      prevMask = 0;\r\n    else\r\n    {\r\n      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r\n      if (prevMask != 0)\r\n      {\r\n        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r\n        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r\n        {\r\n          prevPosT = bufferPos;\r\n          prevMask = ((prevMask << 1) & 0x7) | 1;\r\n          bufferPos++;\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    prevPosT = bufferPos;\r\n\r\n    if (Test86MSByte(p[4]))\r\n    {\r\n      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r\n      UInt32 dest;\r\n      for (;;)\r\n      {\r\n        Byte b;\r\n        int index;\r\n        if (encoding)\r\n          dest = (nowPos + (UInt32)bufferPos) + src;\r\n        else\r\n          dest = src - (nowPos + (UInt32)bufferPos);\r\n        if (prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[prevMask] * 8;\r\n        b = (Byte)(dest >> (24 - index));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index)) - 1);\r\n      }\r\n      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      p[3] = (Byte)(dest >> 16);\r\n      p[2] = (Byte)(dest >> 8);\r\n      p[1] = (Byte)dest;\r\n      bufferPos += 5;\r\n    }\r\n    else\r\n    {\r\n      prevMask = ((prevMask << 1) & 0x7) | 1;\r\n      bufferPos++;\r\n    }\r\n  }\r\n  prevPosT = bufferPos - prevPosT;\r\n  *prevMaskMix = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchX86.h",
    "content": "/* BranchX86.h */\r\n\r\n#ifndef __BRANCHX86_H\r\n#define __BRANCHX86_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\n#define x86_Convert_Init(state) { state = 0; }\r\n\r\nSizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *state, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchX86_2.c",
    "content": "// BranchX86_2.c\r\n\r\n#include \"BranchX86_2.h\"\r\n\r\n#include \"../../Alloc.h\"\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)\r\n#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return BCJ2_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n// #define UpdateBit0(p) Range = bound; *(p) = (CProb)(*(p) + ((kBitModelTotal - *(p)) >> kNumMoveBits));\r\n// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) = (CProb)(*(p) - (*(p) >> kNumMoveBits));\r\n\r\nint x86_2_Decode(\r\n    const Byte *buf0, SizeT size0, \r\n    const Byte *buf1, SizeT size1, \r\n    const Byte *buf2, SizeT size2, \r\n    const Byte *buf3, SizeT size3, \r\n    Byte *outBuf, SizeT outSize)\r\n{\r\n  CProb p[256 + 2];\r\n  SizeT inPos = 0, outPos = 0;\r\n\r\n  const Byte *Buffer, *BufferLim;\r\n  UInt32 Range, Code;\r\n  Byte prevByte = 0;\r\n\r\n  unsigned int i;\r\n  for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)\r\n    p[i] = kBitModelTotal >> 1; \r\n  RC_INIT(buf3, size3);\r\n\r\n  if (outSize == 0)\r\n    return BCJ2_RESULT_OK;\r\n\r\n  for (;;)\r\n  {\r\n    Byte b;\r\n    CProb *prob;\r\n    UInt32 bound;\r\n\r\n    SizeT limit = size0 - inPos;\r\n    if (outSize - outPos < limit)\r\n      limit = outSize - outPos;\r\n    while (limit != 0)\r\n    {\r\n      Byte b = buf0[inPos];\r\n      outBuf[outPos++] = b;\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      inPos++;\r\n      prevByte = b;\r\n      limit--;\r\n    }\r\n\r\n    if (limit == 0 || outPos == outSize)\r\n      break;\r\n\r\n    b = buf0[inPos++];\r\n\r\n    if (b == 0xE8)\r\n      prob = p + prevByte;\r\n    else if (b == 0xE9)\r\n      prob = p + 256;\r\n    else\r\n      prob = p + 257;\r\n\r\n    IfBit0(prob)\r\n    {\r\n      UpdateBit0(prob)\r\n      prevByte = b;\r\n    }\r\n    else\r\n    {\r\n      UInt32 dest;\r\n      const Byte *v;\r\n      UpdateBit1(prob)\r\n      if (b == 0xE8)\r\n      {\r\n        v = buf1;\r\n        if (size1 < 4)\r\n          return BCJ2_RESULT_DATA_ERROR;\r\n        buf1 += 4;\r\n        size1 -= 4;\r\n      }\r\n      else\r\n      {\r\n        v = buf2;\r\n        if (size2 < 4)\r\n          return BCJ2_RESULT_DATA_ERROR;\r\n        buf2 += 4;\r\n        size2 -= 4;\r\n      }\r\n      dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) | \r\n          ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);\r\n      outBuf[outPos++] = (Byte)dest;\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 8);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 16);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = prevByte = (Byte)(dest >> 24);\r\n    }\r\n  }\r\n  return (outPos == outSize) ? BCJ2_RESULT_OK : BCJ2_RESULT_DATA_ERROR;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Branch/BranchX86_2.h",
    "content": "// BranchX86_2.h\r\n\r\n#ifndef __BRANCHX86_2_H\r\n#define __BRANCHX86_2_H\r\n\r\n#include \"BranchTypes.h\"\r\n\r\n#define BCJ2_RESULT_OK 0\r\n#define BCJ2_RESULT_DATA_ERROR 1\r\n\r\n/*\r\nConditions:\r\n  outSize <= FullOutputSize, \r\n  where FullOutputSize is full size of output stream of x86_2 filter.\r\n\r\nIf buf0 overlaps outBuf, there are two required conditions:\r\n  1) (buf0 >= outBuf)\r\n  2) (buf0 + size0 >= outBuf + FullOutputSize).\r\n*/\r\n\r\nint x86_2_Decode(\r\n    const Byte *buf0, SizeT size0, \r\n    const Byte *buf1, SizeT size1, \r\n    const Byte *buf2, SizeT size2, \r\n    const Byte *buf3, SizeT size3, \r\n    Byte *outBuf, SizeT outSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Huffman/HuffmanEncode.c",
    "content": "/* Compress/HuffmanEncode.c */\r\n\r\n#include \"HuffmanEncode.h\"\r\n#include \"../../Sort.h\"\r\n\r\n#define kMaxLen 16\r\n#define NUM_BITS 10\r\n#define MASK ((1 << NUM_BITS) - 1)\r\n\r\n#define NUM_COUNTERS 64\r\n\r\n/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M */\r\n#define HUFFMAN_SPEED_OPT\r\n\r\nvoid Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen)\r\n{\r\n  UInt32 num = 0;\r\n  /* if (maxLen > 10) maxLen = 10; */\r\n  {\r\n    UInt32 i;\r\n    \r\n    #ifdef HUFFMAN_SPEED_OPT\r\n    \r\n    UInt32 counters[NUM_COUNTERS];\r\n    for (i = 0; i < NUM_COUNTERS; i++) \r\n      counters[i] = 0;\r\n    for (i = 0; i < numSymbols; i++) \r\n    {\r\n      UInt32 freq = freqs[i];\r\n      counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++;\r\n    }\r\n \r\n    for (i = 1; i < NUM_COUNTERS; i++) \r\n    {\r\n      UInt32 temp = counters[i];\r\n      counters[i] = num;\r\n      num += temp;\r\n    }\r\n\r\n    for (i = 0; i < numSymbols; i++) \r\n    {\r\n      UInt32 freq = freqs[i];\r\n      if (freq == 0)\r\n        lens[i] = 0;\r\n      else\r\n        p[counters[((freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1)]++] = i | (freq << NUM_BITS);\r\n    }\r\n    counters[0] = 0;\r\n    HeapSort(p + counters[NUM_COUNTERS - 2], counters[NUM_COUNTERS - 1] - counters[NUM_COUNTERS - 2]);\r\n    \r\n    #else\r\n\r\n    for (i = 0; i < numSymbols; i++) \r\n    {\r\n      UInt32 freq = freqs[i];\r\n      if (freq == 0)\r\n        lens[i] = 0;\r\n      else\r\n        p[num++] = i | (freq << NUM_BITS);\r\n    }\r\n    HeapSort(p, num);\r\n\r\n    #endif\r\n  }\r\n\r\n  if (num < 2) \r\n  {\r\n    int minCode = 0;\r\n    int maxCode = 1;\r\n    if (num == 1)\r\n    {\r\n      maxCode = p[0] & MASK;\r\n      if (maxCode == 0)\r\n        maxCode++;\r\n    }\r\n    p[minCode] = 0;\r\n    p[maxCode] = 1;\r\n    lens[minCode] = lens[maxCode] = 1;\r\n    return;\r\n  }\r\n  \r\n  {\r\n    UInt32 b, e, i;\r\n  \r\n    i = b = e = 0;\r\n    do \r\n    {\r\n      UInt32 n, m, freq;\r\n      n = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;\r\n      freq = (p[n] & ~MASK);\r\n      p[n] = (p[n] & MASK) | (e << NUM_BITS);\r\n      m = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;\r\n      freq += (p[m] & ~MASK);\r\n      p[m] = (p[m] & MASK) | (e << NUM_BITS);\r\n      p[e] = (p[e] & MASK) | freq;\r\n      e++;\r\n    } \r\n    while (num - e > 1);\r\n    \r\n    {\r\n      UInt32 lenCounters[kMaxLen + 1];\r\n      for (i = 0; i <= kMaxLen; i++) \r\n        lenCounters[i] = 0;\r\n      \r\n      p[--e] &= MASK;\r\n      lenCounters[1] = 2;\r\n      while (e > 0) \r\n      {\r\n        UInt32 len = (p[p[--e] >> NUM_BITS] >> NUM_BITS) + 1;\r\n        p[e] = (p[e] & MASK) | (len << NUM_BITS);\r\n        if (len >= maxLen) \r\n          for (len = maxLen - 1; lenCounters[len] == 0; len--);\r\n        lenCounters[len]--;\r\n        lenCounters[len + 1] += 2;\r\n      }\r\n      \r\n      {\r\n        UInt32 len;\r\n        i = 0;\r\n        for (len = maxLen; len != 0; len--) \r\n        {\r\n          UInt32 num;\r\n          for (num = lenCounters[len]; num != 0; num--) \r\n            lens[p[i++] & MASK] = (Byte)len;\r\n        }\r\n      }\r\n      \r\n      {\r\n        UInt32 nextCodes[kMaxLen + 1];\r\n        {\r\n          UInt32 code = 0;\r\n          UInt32 len;\r\n          for (len = 1; len <= kMaxLen; len++) \r\n            nextCodes[len] = code = (code + lenCounters[len - 1]) << 1;\r\n        }\r\n        /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */\r\n\r\n        {\r\n          UInt32 i;\r\n          for (i = 0; i < numSymbols; i++) \r\n            p[i] = nextCodes[lens[i]]++;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Huffman/HuffmanEncode.h",
    "content": "/* Compress/HuffmanEncode.h */\r\n\r\n#ifndef __COMPRESS_HUFFMANENCODE_H\r\n#define __COMPRESS_HUFFMANENCODE_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n/*\r\nConditions:\r\n  num <= 1024 = 2 ^ NUM_BITS\r\n  Sum(freqs) < 4M = 2 ^ (32 - NUM_BITS)\r\n  maxLen <= 16 = kMaxLen\r\n  Num_Items(p) >= HUFFMAN_TEMP_SIZE(num)\r\n*/\r\n \r\nvoid Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lz/LzHash.h",
    "content": "/* LzHash.h */\r\n\r\n#ifndef __C_LZHASH_H\r\n#define __C_LZHASH_H\r\n\r\n#define kHash2Size (1 << 10)\r\n#define kHash3Size (1 << 16)\r\n#define kHash4Size (1 << 20)\r\n\r\n#define kFix3HashSize (kHash2Size)\r\n#define kFix4HashSize (kHash2Size + kHash3Size)\r\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r\n\r\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r\n\r\n#define HASH3_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r\n\r\n#define HASH4_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & p->hashMask; }\r\n\r\n#define HASH5_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)); \\\r\n  hashValue = (hash4Value ^ (g_CrcTable[cur[4]] << 3)) & p->hashMask; \\\r\n  hash4Value &= (kHash4Size - 1); }\r\n\r\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ g_CrcTable[cur[2]]) & 0xFFFF; */\r\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ g_CrcTable[cur[1]]) & 0xFFFF;\r\n\r\n\r\n#define MT_HASH2_CALC \\\r\n  hash2Value = (g_CrcTable[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r\n\r\n#define MT_HASH3_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r\n\r\n#define MT_HASH4_CALC { \\\r\n  UInt32 temp = g_CrcTable[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (g_CrcTable[cur[3]] << 5)) & (kHash4Size - 1); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lz/MatchFinder.c",
    "content": "/* MatchFinder.c */\r\n/* Please call InitCrcTable before */\r\n\r\n#include <string.h>\r\n\r\n#include \"MatchFinder.h\"\r\n#include \"LzHash.h\"\r\n\r\n#include \"../../7zCrc.h\"\r\n\r\n#define kEmptyHashValue 0\r\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\r\n#define kMaxHistorySize ((UInt32)3 << 30)\r\n\r\n#define kStartMaxLen 3\r\n\r\nvoid LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  if (!p->directInput)\r\n  {\r\n    alloc->Free(p->bufferBase);\r\n    p->bufferBase = 0;\r\n  }\r\n}\r\n\r\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r\n\r\nint LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r\n{\r\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r\n  if (p->directInput)\r\n  {\r\n    p->blockSize = blockSize;\r\n    return 1;\r\n  }\r\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\r\n  {\r\n    LzInWindow_Free(p, alloc);\r\n    p->blockSize = blockSize;\r\n    p->bufferBase = (Byte *)alloc->Alloc(blockSize);\r\n  }\r\n  return (p->bufferBase != 0);\r\n}\r\n\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r\n\r\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r\n\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r\n{\r\n  p->posLimit -= subValue;\r\n  p->pos -= subValue;\r\n  p->streamPos -= subValue;\r\n}\r\n\r\nvoid MatchFinder_ReadBlock(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached || p->result != SZ_OK)\r\n    return;\r\n  for (;;)\r\n  {\r\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\r\n    UInt32 numReadBytes;\r\n    UInt32 size = (UInt32)(p->bufferBase + p->blockSize - dest);\r\n    if (size == 0)\r\n      return;\r\n    p->result = p->stream->Read(p->stream, dest, size, &numReadBytes);\r\n    if (p->result != SZ_OK)\r\n      return;\r\n    if (numReadBytes == 0)\r\n    {\r\n      p->streamEndWasReached = 1;\r\n      return;\r\n    }\r\n    p->streamPos += numReadBytes;\r\n    if (p->streamPos - p->pos > p->keepSizeAfter)\r\n      return;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\r\n{\r\n  memmove(p->bufferBase, \r\n    p->buffer - p->keepSizeBefore, \r\n    p->streamPos - p->pos + p->keepSizeBefore);\r\n  p->buffer = p->bufferBase + p->keepSizeBefore;\r\n}\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p)\r\n{\r\n  /* if (p->streamEndWasReached) return 0; */\r\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r\n}\r\n\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached) \r\n    return;\r\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\r\n    MatchFinder_ReadBlock(p);\r\n}\r\n\r\nvoid MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r\n{\r\n  if (MatchFinder_NeedMove(p))\r\n    MatchFinder_MoveBlock(p);\r\n  MatchFinder_ReadBlock(p);\r\n}\r\n\r\nvoid MatchFinder_SetDefaultSettings(CMatchFinder *p)\r\n{\r\n  p->cutValue = 32;\r\n  p->btMode = 1;\r\n  p->numHashBytes = 4;\r\n  /* p->skipModeBits = 0; */\r\n  p->directInput = 0;\r\n  p->bigHash = 0;\r\n}\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p)\r\n{\r\n  p->bufferBase = 0;\r\n  p->directInput = 0;\r\n  p->hash = 0;\r\n  MatchFinder_SetDefaultSettings(p);\r\n}\r\n\r\nvoid MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(p->hash);\r\n  p->hash = 0;\r\n}\r\n\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  MatchFinder_FreeThisClassMemory(p, alloc);\r\n  LzInWindow_Free(p, alloc);\r\n}\r\n\r\nCLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r\n{\r\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r\n  if (sizeInBytes / sizeof(CLzRef) != num)\r\n    return 0;\r\n  return (CLzRef *)alloc->Alloc(sizeInBytes);\r\n}\r\n\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize, \r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 sizeReserv;\r\n  if (historySize > kMaxHistorySize)\r\n  {\r\n    MatchFinder_Free(p, alloc);\r\n    return 0;\r\n  }\r\n  sizeReserv = historySize >> 1;\r\n  if (historySize > ((UInt32)2 << 30))\r\n    sizeReserv = historySize >> 2;\r\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r\n\r\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1; \r\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r\n  if (LzInWindow_Create(p, sizeReserv, alloc))\r\n  {\r\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r\n    UInt32 hs;\r\n    p->matchMaxLen = matchMaxLen;\r\n    {\r\n      p->fixedHashSize = 0;\r\n      if (p->numHashBytes == 2)\r\n        hs = (1 << 16) - 1;\r\n      else\r\n      {\r\n        hs = historySize - 1;\r\n        hs |= (hs >> 1);\r\n        hs |= (hs >> 2);\r\n        hs |= (hs >> 4);\r\n        hs |= (hs >> 8);\r\n        hs >>= 1;\r\n        /* hs >>= p->skipModeBits; */\r\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r\n        if (hs > (1 << 24))\r\n        {\r\n          if (p->numHashBytes == 3)\r\n            hs = (1 << 24) - 1;\r\n          else\r\n            hs >>= 1;\r\n        }\r\n      }\r\n      p->hashMask = hs;\r\n      hs++;\r\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r\n      hs += p->fixedHashSize;\r\n    }\r\n\r\n    {\r\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\r\n      UInt32 newSize;\r\n      p->historySize = historySize;\r\n      p->hashSizeSum = hs;\r\n      p->cyclicBufferSize = newCyclicBufferSize;\r\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r\n      newSize = p->hashSizeSum + p->numSons;\r\n      if (p->hash != 0 && prevSize == newSize)\r\n        return 1;\r\n      MatchFinder_FreeThisClassMemory(p, alloc);\r\n      p->hash = AllocRefs(newSize, alloc);\r\n      if (p->hash != 0)\r\n      {\r\n        p->son = p->hash + p->hashSizeSum;\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  MatchFinder_Free(p, alloc);\r\n  return 0;\r\n}\r\n\r\nvoid MatchFinder_SetLimits(CMatchFinder *p)\r\n{\r\n  UInt32 limit = kMaxValForNormalize - p->pos;\r\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r\n  if (limit2 < limit) \r\n    limit = limit2;\r\n  limit2 = p->streamPos - p->pos;\r\n  if (limit2 <= p->keepSizeAfter)\r\n  {\r\n    if (limit2 > 0)\r\n      limit2 = 1;\r\n  }\r\n  else\r\n    limit2 -= p->keepSizeAfter;\r\n  if (limit2 < limit) \r\n    limit = limit2;\r\n  {\r\n    UInt32 lenLimit = p->streamPos - p->pos;\r\n    if (lenLimit > p->matchMaxLen)\r\n      lenLimit = p->matchMaxLen;\r\n    p->lenLimit = lenLimit;\r\n  }\r\n  p->posLimit = p->pos + limit;\r\n}\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < p->hashSizeSum; i++)\r\n    p->hash[i] = kEmptyHashValue;\r\n  p->cyclicBufferPos = 0;\r\n  p->buffer = p->bufferBase;\r\n  p->pos = p->streamPos = p->cyclicBufferSize;\r\n  p->result = SZ_OK;\r\n  p->streamEndWasReached = 0;\r\n  MatchFinder_ReadBlock(p);\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nUInt32 MatchFinder_GetSubValue(CMatchFinder *p) \r\n{ \r\n  return (p->pos - p->historySize - 1) & kNormalizeMask; \r\n}\r\n\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_Normalize(CMatchFinder *p)\r\n{\r\n  UInt32 subValue = MatchFinder_GetSubValue(p);\r\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r\n  MatchFinder_ReduceOffsets(p, subValue);\r\n}\r\n\r\nvoid MatchFinder_CheckLimits(CMatchFinder *p)\r\n{\r\n  if (p->pos == kMaxValForNormalize)\r\n    MatchFinder_Normalize(p);\r\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r\n    MatchFinder_CheckAndMoveAndRead(p);\r\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\r\n    p->cyclicBufferPos = 0;\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nUInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, \r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  son[_cyclicBufferPos] = curMatch;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n      return distances;\r\n    {\r\n      const Byte *pb = cur - delta;\r\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r\n      {\r\n        UInt32 len = 0;\r\n        while(++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n            return distances;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, \r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return distances;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while(++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return distances;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nvoid SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        while(++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        {\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define MOVE_POS \\\r\n  ++p->cyclicBufferPos; \\\r\n  p->buffer++; \\\r\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r\n\r\n#define MOVE_POS_RET MOVE_POS return offset;\r\n\r\nvoid MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r\n\r\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\r\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\r\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\r\n  cur = p->buffer;\r\n\r\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r\n\r\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r\n\r\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\r\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\r\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\r\n\r\n#define SKIP_FOOTER \\\r\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r\n\r\nUInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(2)\r\n  HASH2_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 1)\r\n}\r\n\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 2)\r\n}\r\n\r\nUInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, delta2, maxLen, offset;\r\n  GET_MATCHES_HEADER(3)\r\n\r\n  HASH3_CALC;\r\n\r\n  delta2 = p->pos - p->hash[hash2Value];\r\n  curMatch = p->hash[kFix3HashSize + hashValue];\r\n  \r\n  p->hash[hash2Value] = \r\n  p->hash[kFix3HashSize + hashValue] = p->pos;\r\n\r\n\r\n  maxLen = 2;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[0] = maxLen;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET; \r\n    }\r\n  }\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nUInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n  \r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET; \r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nUInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n\r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      p->son[p->cyclicBufferPos] = curMatch;\r\n      MOVE_POS_RET; \r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances + offset, maxLen) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances, 2) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nvoid Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(2) \r\n    HASH2_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value;\r\n    SKIP_HEADER(3)\r\n    HASH3_CALC;\r\n    curMatch = p->hash[kFix3HashSize + hashValue];\r\n    p->hash[hash2Value] =\r\n    p->hash[kFix3HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4) \r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] =\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r\n  if (!p->btMode)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 2)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 3)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r\n  }\r\n  else\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lz/MatchFinder.h",
    "content": "/* MatchFinder.h */\r\n\r\n#ifndef __MATCHFINDER_H\r\n#define __MATCHFINDER_H\r\n\r\n#include \"../../IStream.h\"\r\n\r\ntypedef UInt32 CLzRef;\r\n\r\ntypedef struct _CMatchFinder\r\n{\r\n  Byte *buffer;\r\n  UInt32 pos;\r\n  UInt32 posLimit;\r\n  UInt32 streamPos;\r\n  UInt32 lenLimit;\r\n\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r\n\r\n  UInt32 matchMaxLen;\r\n  CLzRef *hash;\r\n  CLzRef *son;\r\n  UInt32 hashMask;\r\n  UInt32 cutValue;\r\n\r\n  Byte *bufferBase;\r\n  ISeqInStream *stream;\r\n  int streamEndWasReached;\r\n\r\n  UInt32 blockSize;\r\n  UInt32 keepSizeBefore;\r\n  UInt32 keepSizeAfter;\r\n\r\n  UInt32 numHashBytes;\r\n  int directInput;\r\n  int btMode;\r\n  /* int skipModeBits; */\r\n  int bigHash;\r\n  UInt32 historySize;\r\n  UInt32 fixedHashSize;\r\n  UInt32 hashSizeSum;\r\n  UInt32 numSons;\r\n\r\n  HRes result;\r\n} CMatchFinder;\r\n\r\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r\n\r\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p);\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p);\r\n\r\n/* Conditions:\r\n     historySize <= 3 GB\r\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r\n*/\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize, \r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc);\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, \r\n    UInt32 *distances, UInt32 maxLen);\r\n\r\n/* \r\nConditions:\r\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r\n*/\r\n\r\ntypedef void (*Mf_Init_Func)(void *object);\r\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\r\n\r\ntypedef struct _IMatchFinder\r\n{\r\n  Mf_Init_Func Init;\r\n  Mf_GetIndexByte_Func GetIndexByte;\r\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r\n  Mf_GetMatches_Func GetMatches;\r\n  Mf_Skip_Func Skip;\r\n} IMatchFinder;\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p);\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lz/MatchFinderMt.c",
    "content": "/* MatchFinderMt.c */\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"LzHash.h\"\r\n\r\n#include \"MatchFinderMt.h\"\r\n\r\nvoid MtSync_Construct(CMtSync *p)\r\n{\r\n  p->wasCreated = False;\r\n  p->csWasInitialized = False;\r\n  p->csWasEntered = False;\r\n  Thread_Construct(&p->thread);\r\n  Event_Construct(&p->canStart);\r\n  Event_Construct(&p->wasStarted);\r\n  Event_Construct(&p->wasStopped);\r\n  Semaphore_Construct(&p->freeSemaphore);\r\n  Semaphore_Construct(&p->filledSemaphore);\r\n}\r\n\r\nvoid MtSync_GetNextBlock(CMtSync *p)\r\n{\r\n  if (p->needStart)\r\n  {\r\n    p->numProcessedBlocks = 1;\r\n    p->needStart = False;\r\n    p->stopWriting = False;\r\n    p->exit = False;\r\n    Event_Reset(&p->wasStarted);\r\n    Event_Reset(&p->wasStopped);\r\n\r\n    Event_Set(&p->canStart);\r\n    Event_Wait(&p->wasStarted);\r\n  }\r\n  else\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n    p->numProcessedBlocks++;\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  Semaphore_Wait(&p->filledSemaphore);\r\n  CriticalSection_Enter(&p->cs);\r\n  p->csWasEntered = True;\r\n}\r\n\r\n/* MtSync_StopWriting must be called if Writing was started */\r\n\r\nvoid MtSync_StopWriting(CMtSync *p)\r\n{ \r\n  UInt32 myNumBlocks = p->numProcessedBlocks;\r\n  if (!Thread_WasCreated(&p->thread) || p->needStart)\r\n    return;\r\n  p->stopWriting = True;\r\n  if (p->csWasEntered)\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n  }\r\n  Semaphore_Release1(&p->freeSemaphore);\r\n \r\n  Event_Wait(&p->wasStopped);\r\n\r\n  while (myNumBlocks++ != p->numProcessedBlocks)\r\n  {\r\n    Semaphore_Wait(&p->filledSemaphore);\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  p->needStart = True;\r\n}\r\n\r\nvoid MtSync_Destruct(CMtSync *p)\r\n{\r\n  if (Thread_WasCreated(&p->thread))\r\n  {\r\n    MtSync_StopWriting(p);\r\n    p->exit = True;\r\n    if (p->needStart)\r\n      Event_Set(&p->canStart);\r\n    Thread_Wait(&p->thread);\r\n    Thread_Close(&p->thread);\r\n  }\r\n  if (p->csWasInitialized)\r\n  {\r\n    CriticalSection_Delete(&p->cs);\r\n    p->csWasInitialized = False;\r\n  }\r\n\r\n  Event_Close(&p->canStart);\r\n  Event_Close(&p->wasStarted);\r\n  Event_Close(&p->wasStopped);\r\n  Semaphore_Close(&p->freeSemaphore);\r\n  Semaphore_Close(&p->filledSemaphore);\r\n\r\n  p->wasCreated = False;\r\n}\r\n\r\nHRes MtSync_Create2(CMtSync *p, unsigned (StdCall *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  if (p->wasCreated)\r\n    return SZ_OK;\r\n\r\n  RINOK(CriticalSection_Init(&p->cs));\r\n  p->csWasInitialized = True;\r\n\r\n  RINOK(AutoResetEvent_CreateNotSignaled(&p->canStart));\r\n  RINOK(AutoResetEvent_CreateNotSignaled(&p->wasStarted));\r\n  RINOK(AutoResetEvent_CreateNotSignaled(&p->wasStopped));\r\n  \r\n  RINOK(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));\r\n  RINOK(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));\r\n\r\n  p->needStart = True;\r\n  \r\n  RINOK(Thread_Create(&p->thread, startAddress, obj));\r\n  p->wasCreated = True;\r\n  return SZ_OK;\r\n}\r\n\r\nHRes MtSync_Create(CMtSync *p, unsigned (StdCall *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  HRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\r\n  if (res != SZ_OK)\r\n    MtSync_Destruct(p);\r\n  return res;\r\n}\r\n\r\n\r\nvoid MtSync_Init(CMtSync *p) { p->needStart = True; }\r\n\r\n#define kMtMaxValForNormalize 0xFFFFFFFF\r\n\r\n#define DEF_GetHeads(name, v) \\\r\nstatic void GetHeads ## name(const Byte *p, UInt32 pos, \\\r\nUInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads) { \\\r\nfor (; numHeads != 0; numHeads--) { \\\r\nconst UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r\n\r\nDEF_GetHeads(2,  (p[0] | ((UInt32)p[1] << 8)) & hashMask)\r\nDEF_GetHeads(3,  (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\r\nDEF_GetHeads(4,  (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (g_CrcTable[p[3]] << 5)) & hashMask)\r\nDEF_GetHeads(4b, (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\r\nDEF_GetHeads(5,  (g_CrcTable[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (g_CrcTable[p[3]] << 5) ^ (g_CrcTable[p[4]] << 3)) & hashMask)\r\n\r\nvoid HashThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->hashSync;\r\n  for (;;)\r\n  {\r\n    UInt32 numProcessedBlocks = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = numProcessedBlocks;\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n\r\n      {\r\n        CMatchFinder *mf = mt->MatchFinder;\r\n        if (MatchFinder_NeedMove(mf))\r\n        {\r\n          CriticalSection_Enter(&mt->btSync.cs);\r\n          CriticalSection_Enter(&mt->hashSync.cs);\r\n          {\r\n            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            const Byte *afterPtr;\r\n            MatchFinder_MoveBlock(mf);\r\n            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            mt->pointerToCurPos -= beforePtr - afterPtr;\r\n            mt->buffer -= beforePtr - afterPtr;\r\n          }\r\n          CriticalSection_Leave(&mt->btSync.cs);\r\n          CriticalSection_Leave(&mt->hashSync.cs);\r\n          continue;\r\n        }\r\n\r\n        Semaphore_Wait(&p->freeSemaphore);\r\n\r\n        MatchFinder_ReadIfRequired(mf);\r\n        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))\r\n        {\r\n          UInt32 subValue = (mf->pos - mf->historySize - 1);\r\n          MatchFinder_ReduceOffsets(mf, subValue);\r\n          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);\r\n        }\r\n        {\r\n          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n          UInt32 num = mf->streamPos - mf->pos;\r\n          heads[0] = 2;\r\n          heads[1] = num;\r\n          if (num >= mf->numHashBytes)\r\n          {\r\n            num = num - mf->numHashBytes + 1;\r\n            if (num > kMtHashBlockSize - 2)\r\n              num = kMtHashBlockSize - 2;\r\n            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num);\r\n            heads[0] += num;\r\n          }\r\n          mf->pos += num;\r\n          mf->buffer += num;\r\n        }\r\n      }\r\n\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r\n{\r\n  MtSync_GetNextBlock(&p->hashSync);\r\n  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];\r\n  p->hashNumAvail = p->hashBuf[p->hashBufPos++];\r\n}\r\n\r\n#define kEmptyHashValue 0\r\n\r\n/* #define MFMT_GM_INLINE */\r\n\r\n#ifdef MFMT_GM_INLINE\r\n\r\n#if _MSC_VER >= 1300\r\n#define NO_INLINE __declspec(noinline) __fastcall \r\n#else\r\n#ifdef _MSC_VER\r\n#define NO_INLINE __fastcall \r\n#endif\r\n#endif\r\n\r\nInt32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son, \r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, \r\n    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\r\n{\r\n  do\r\n  {\r\n  UInt32 *distances = _distances + 1;\r\n  UInt32 curMatch = pos - *hash++;\r\n\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  UInt32 cutValue = _cutValue;\r\n  UInt32 maxLen = _maxLen;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      break;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while(++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            break;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n  pos++;\r\n  _cyclicBufferPos++;\r\n  cur++;\r\n  {\r\n    UInt32 num = (UInt32)(distances - _distances);\r\n    *_distances = num - 1;\r\n    _distances += num;\r\n    limit -= num;\r\n  }\r\n  }\r\n  while (limit > 0 && --size != 0);\r\n  *posRes = pos;\r\n  return limit;\r\n}\r\n\r\n#endif\r\n\r\nvoid BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  UInt32 numProcessed = 0;\r\n  UInt32 curPos = 2;\r\n  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\r\n  distances[1] = p->hashNumAvail;\r\n  while (curPos < limit)\r\n  {\r\n    if (p->hashBufPos == p->hashBufPosLimit)\r\n    {\r\n      MatchFinderMt_GetNextBlock_Hash(p);\r\n      distances[1] = numProcessed + p->hashNumAvail;\r\n      if (p->hashNumAvail >= p->numHashBytes)\r\n        continue;\r\n      for (; p->hashNumAvail != 0; p->hashNumAvail--)\r\n        distances[curPos++] = 0;\r\n      break;\r\n    }\r\n    {\r\n      UInt32 size = p->hashBufPosLimit - p->hashBufPos;\r\n      UInt32 lenLimit = p->matchMaxLen;\r\n      UInt32 pos = p->pos;\r\n      UInt32 cyclicBufferPos = p->cyclicBufferPos;\r\n      if (lenLimit >= p->hashNumAvail)\r\n        lenLimit = p->hashNumAvail;\r\n      {\r\n        UInt32 size2 = p->hashNumAvail - lenLimit + 1;\r\n        if (size2 < size)\r\n          size = size2;\r\n        size2 = p->cyclicBufferSize - cyclicBufferPos;\r\n        if (size2 < size)\r\n          size = size2;\r\n      }\r\n      #ifndef MFMT_GM_INLINE\r\n      while (curPos < limit && size-- != 0)\r\n      {\r\n        UInt32 *startDistances = distances + curPos;\r\n        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++], \r\n          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, \r\n          startDistances + 1, p->numHashBytes - 1) - startDistances);\r\n        *startDistances = num - 1;\r\n        curPos += num;\r\n        cyclicBufferPos++;\r\n        pos++;\r\n        p->buffer++;\r\n      }\r\n      #else\r\n      {\r\n        UInt32 posRes;\r\n        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, \r\n          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);\r\n        p->hashBufPos += posRes - pos;\r\n        cyclicBufferPos += posRes - pos;\r\n        p->buffer += posRes - pos;\r\n        pos = posRes;\r\n      }\r\n      #endif\r\n\r\n      numProcessed += pos - p->pos;\r\n      p->hashNumAvail -= pos - p->pos;\r\n      p->pos = pos;\r\n      if (cyclicBufferPos == p->cyclicBufferSize)\r\n        cyclicBufferPos = 0;\r\n      p->cyclicBufferPos = cyclicBufferPos;\r\n    }\r\n  }\r\n  distances[0] = curPos;\r\n}\r\n\r\nvoid BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r\n{\r\n  CMtSync *sync = &p->hashSync;\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Enter(&sync->cs);\r\n    sync->csWasEntered = True;\r\n  }\r\n  \r\n  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);\r\n\r\n  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\r\n  {\r\n    UInt32 subValue = p->pos - p->cyclicBufferSize;\r\n    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);\r\n    p->pos -= subValue;\r\n  }\r\n\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Leave(&sync->cs);\r\n    sync->csWasEntered = False;\r\n  }\r\n}\r\n\r\nvoid BtThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->btSync;\r\n  for (;;)\r\n  {\r\n    UInt32 blockIndex = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = blockIndex;\r\n        MtSync_StopWriting(&mt->hashSync);\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n      Semaphore_Wait(&p->freeSemaphore);\r\n      BtFillBlock(mt, blockIndex++);\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p)\r\n{\r\n  p->hashBuf = 0;\r\n  MtSync_Construct(&p->hashSync);\r\n  MtSync_Construct(&p->btSync);\r\n}\r\n\r\nvoid MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(p->hashBuf);\r\n  p->hashBuf = 0;\r\n}\r\n\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  MtSync_Destruct(&p->hashSync);\r\n  MtSync_Destruct(&p->btSync);\r\n  MatchFinderMt_FreeMem(p, alloc);\r\n}\r\n\r\n#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\r\n#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\r\n\r\nstatic unsigned StdCall HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r\nstatic unsigned StdCall BtThreadFunc2(void *p) \r\n{ \r\n  #ifdef USE_ALLOCA\r\n  alloca(0x180);\r\n  #endif\r\n  BtThreadFunc((CMatchFinderMt *)p); \r\n  return 0; \r\n}\r\n\r\nHRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\r\n{ \r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->historySize = historySize;\r\n  if (kMtBtBlockSize <= matchMaxLen * 4)\r\n    return E_INVALIDARG;\r\n  if (p->hashBuf == 0)\r\n  {\r\n    p->hashBuf = (UInt32 *)alloc->Alloc((kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r\n    if (p->hashBuf == 0)\r\n      return SZE_OUTOFMEMORY;\r\n    p->btBuf = p->hashBuf + kHashBufferSize;\r\n  }\r\n  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);\r\n  keepAddBufferAfter += kMtHashBlockSize;\r\n  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));\r\n  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));\r\n  return SZ_OK;\r\n}\r\n\r\n/* Call it after ReleaseStream / SetStream */\r\nvoid MatchFinderMt_Init(CMatchFinderMt *p)\r\n{ \r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->btBufPos = p->btBufPosLimit = 0;\r\n  p->hashBufPos = p->hashBufPosLimit = 0;\r\n  MatchFinder_Init(mf);\r\n  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);\r\n  p->btNumAvailBytes = 0;\r\n  p->lzPos = p->historySize + 1;\r\n\r\n  p->hash = mf->hash;\r\n  p->fixedHashSize = mf->fixedHashSize;\r\n\r\n  p->son = mf->son;\r\n  p->matchMaxLen = mf->matchMaxLen;\r\n  p->numHashBytes = mf->numHashBytes;\r\n  p->pos = mf->pos;\r\n  p->buffer = mf->buffer;\r\n  p->cyclicBufferPos = mf->cyclicBufferPos;\r\n  p->cyclicBufferSize = mf->cyclicBufferSize;\r\n  p->cutValue = mf->cutValue;\r\n}\r\n\r\n/* ReleaseStream is required to finish multithreading */\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p)\r\n{ \r\n  MtSync_StopWriting(&p->btSync);\r\n  /* p->MatchFinder->ReleaseStream(); */\r\n}\r\n\r\nvoid MatchFinderMt_Normalize(CMatchFinderMt *p)\r\n{\r\n  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\r\n  p->lzPos = p->historySize + 1;\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r\n{\r\n  UInt32 blockIndex;\r\n  MtSync_GetNextBlock(&p->btSync);\r\n  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);\r\n  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;\r\n  p->btBufPosLimit += p->btBuf[p->btBufPos++];\r\n  p->btNumAvailBytes = p->btBuf[p->btBufPos++];\r\n  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize) \r\n    MatchFinderMt_Normalize(p);\r\n}\r\n\r\nconst Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r\n{\r\n  return p->pointerToCurPos;\r\n}\r\n\r\n#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\r\n\r\nUInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r\n{ \r\n  GET_NEXT_BLOCK_IF_REQUIRED;\r\n  return p->btNumAvailBytes;\r\n}\r\n\r\nByte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)\r\n{ \r\n  return p->pointerToCurPos[index]; \r\n}\r\n\r\nUInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, curMatch2;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos; \r\n  MT_HASH2_CALC\r\n      \r\n  curMatch2 = hash[hash2Value];\r\n  hash[hash2Value] = lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos) \r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n    {\r\n      *distances++ = 2; \r\n      *distances++ = lzPos - curMatch2 - 1;\r\n    }\r\n  return distances;\r\n}\r\n\r\nUInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos; \r\n  MT_HASH3_CALC\r\n\r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  \r\n  hash[                hash2Value] = \r\n  hash[kFix3HashSize + hash3Value] = \r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  { \r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] = 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2; \r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  { \r\n    *distances++ = 3; \r\n    *distances++ = lzPos - curMatch3 - 1; \r\n  }\r\n  return distances;\r\n}\r\n\r\n/*\r\nUInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos; \r\n  MT_HASH4_CALC\r\n      \r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  curMatch4 = hash[kFix4HashSize + hash4Value];\r\n  \r\n  hash[                hash2Value] = \r\n  hash[kFix3HashSize + hash3Value] = \r\n  hash[kFix4HashSize + hash4Value] = \r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch3 - 1;\r\n    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])\r\n    {\r\n      distances[0] = 4;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 3;\r\n    distances += 2;\r\n  }\r\n\r\n  if (curMatch4 >= matchMinPos)\r\n    if (\r\n      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&\r\n      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]\r\n      )\r\n    {\r\n      *distances++ = 4;\r\n      *distances++ = lzPos - curMatch4 - 1;\r\n    }\r\n  return distances;\r\n}\r\n*/\r\n\r\n#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\r\n\r\nUInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{ \r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n  p->btNumAvailBytes--;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < len; i += 2)\r\n    {\r\n      *distances++ = *btBuf++;\r\n      *distances++ = *btBuf++;\r\n    }\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\nUInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{ \r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n\r\n  if (len == 0)\r\n  {\r\n    if (p->btNumAvailBytes-- >= 4) \r\n      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\r\n  }\r\n  else\r\n  {\r\n    /* Condition: there are matches in btBuf with length < p->numHashBytes */\r\n    UInt32 *distances2;\r\n    p->btNumAvailBytes--;\r\n    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\r\n    do \r\n    {\r\n      *distances2++ = *btBuf++;\r\n      *distances2++ = *btBuf++;\r\n    }\r\n    while ((len -= 2) != 0);\r\n    len  = (UInt32)(distances2 - (distances));\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\n#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED\r\n#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r\n#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while(--num != 0);\r\n\r\nvoid MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER2 { p->btNumAvailBytes--;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER(2)\r\n      UInt32 hash2Value;\r\n      MT_HASH2_CALC\r\n      hash[hash2Value] = p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER(3)\r\n      UInt32 hash2Value, hash3Value;\r\n      MT_HASH3_CALC\r\n      hash[kFix3HashSize + hash3Value] = \r\n      hash[                hash2Value] = \r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\n/*\r\nvoid MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r\n{ \r\n  SKIP_HEADER(4)\r\n      UInt32 hash2Value, hash3Value, hash4Value;\r\n      MT_HASH4_CALC\r\n      hash[kFix4HashSize + hash4Value] = \r\n      hash[kFix3HashSize + hash3Value] = \r\n      hash[                hash2Value] = \r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n*/\r\n\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\r\n  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\r\n  switch(p->MatchFinder->numHashBytes)\r\n  {\r\n    case 2:\r\n      p->GetHeadsFunc = GetHeads2;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)0;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\r\n      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\r\n      break;\r\n    case 3:\r\n      p->GetHeadsFunc = GetHeads3;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;\r\n      break;\r\n    default:\r\n    /* case 4: */\r\n      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\r\n      /* p->GetHeadsFunc = GetHeads4; */\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\r\n      break;\r\n    /*\r\n    default:\r\n      p->GetHeadsFunc = GetHeads5;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;\r\n      break;\r\n    */\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lz/MatchFinderMt.h",
    "content": "/* MatchFinderMt.h */\r\n\r\n#ifndef __MATCHFINDERMT_H\r\n#define __MATCHFINDERMT_H\r\n\r\n#include \"../../Threads.h\"\r\n#include \"MatchFinder.h\"\r\n\r\n#define kMtHashBlockSize (1 << 13)\r\n#define kMtHashNumBlocks (1 << 3)\r\n#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)\r\n\r\n#define kMtBtBlockSize (1 << 14)\r\n#define kMtBtNumBlocks (1 << 6)\r\n#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)\r\n\r\ntypedef struct _CMtSync\r\n{\r\n  Bool wasCreated;\r\n  Bool needStart;\r\n  Bool exit;\r\n  Bool stopWriting;\r\n\r\n  CThread thread;\r\n  CAutoResetEvent canStart;\r\n  CAutoResetEvent wasStarted;\r\n  CAutoResetEvent wasStopped;\r\n  CSemaphore freeSemaphore;\r\n  CSemaphore filledSemaphore;\r\n  Bool csWasInitialized;\r\n  Bool csWasEntered;\r\n  CCriticalSection cs;\r\n  UInt32 numProcessedBlocks;\r\n} CMtSync;\r\n\r\ntypedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);\r\n\r\n/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */\r\n#define kMtCacheLineDummy 128\r\n\r\ntypedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,\r\n  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads);\r\n\r\ntypedef struct _CMatchFinderMt\r\n{\r\n  /* LZ */\r\n  const Byte *pointerToCurPos;\r\n  UInt32 *btBuf;\r\n  UInt32 btBufPos;\r\n  UInt32 btBufPosLimit;\r\n  UInt32 lzPos;\r\n  UInt32 btNumAvailBytes;\r\n\r\n  UInt32 *hash;\r\n  UInt32 fixedHashSize;\r\n  UInt32 historySize;\r\n\r\n  Mf_Mix_Matches MixMatchesFunc;\r\n  \r\n  /* LZ + BT */\r\n  CMtSync btSync;\r\n  Byte btDummy[kMtCacheLineDummy];\r\n\r\n  /* BT */\r\n  UInt32 *hashBuf;\r\n  UInt32 hashBufPos;\r\n  UInt32 hashBufPosLimit;\r\n  UInt32 hashNumAvail;\r\n\r\n  CLzRef *son;\r\n  UInt32 matchMaxLen;\r\n  UInt32 numHashBytes;\r\n  UInt32 pos;\r\n  Byte *buffer;\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be historySize + 1 */\r\n  UInt32 cutValue;\r\n\r\n  /* BT + Hash */\r\n  CMtSync hashSync;\r\n  /* Byte hashDummy[kMtCacheLineDummy]; */\r\n  \r\n  /* Hash */\r\n  Mf_GetHeads GetHeadsFunc;\r\n  CMatchFinder *MatchFinder;\r\n} CMatchFinderMt;\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p);\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);\r\nHRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/LzmaDecode.c",
    "content": "/*\r\n  LzmaDecode.c\r\n  LZMA Decoder (optimized for Speed version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) \\\r\n  { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \\\r\n  BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}\r\n\r\n#define RC_INIT Buffer = BufferLim = 0; RC_INIT2\r\n\r\n#else\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#endif\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  const Byte *Buffer = vs->Buffer;\r\n  const Byte *BufferLim = vs->BufferLim;\r\n  #else\r\n  const Byte *Buffer = inStream;\r\n  const Byte *BufferLim = inStream + inSize;\r\n  #endif\r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      #ifdef _LZMA_IN_CB\r\n      RC_INIT;\r\n      #else\r\n      RC_INIT(inStream, inSize);\r\n      #endif\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  RC_INIT;\r\n  #else\r\n  RC_INIT(inStream, inSize);\r\n  #endif\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (Byte)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n            UpdateBit0(prob);\r\n            \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            \r\n            state = state < kNumLitStates ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = Buffer;\r\n  vs->BufferLim = BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/LzmaDecode.h",
    "content": "/* \r\n  LzmaDecode.h\r\n  LZMA Decoder interface\r\n\r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMADECODE_H\r\n#define __LZMADECODE_H\r\n\r\n#include \"LzmaTypes.h\"\r\n\r\n/* #define _LZMA_IN_CB */\r\n/* Use callback for input data */\r\n\r\n/* #define _LZMA_OUT_READ */\r\n/* Use read function for output data */\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_LOC_OPT */\r\n/* Enable local speed optimizations inside code */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#ifdef _LZMA_IN_CB\r\ntypedef struct _ILzmaInCallback\r\n{\r\n  int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);\r\n} ILzmaInCallback;\r\n#endif\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  #ifdef _LZMA_OUT_READ\r\n  UInt32 DictionarySize;\r\n  #endif\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  const unsigned char *Buffer;\r\n  const unsigned char *BufferLim;\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  unsigned char *Dictionary;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;\r\n  unsigned char TempDictionary[4];\r\n  #endif\r\n} CLzmaDecoderState;\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }\r\n#endif\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *inCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/LzmaDecodeSize.c",
    "content": "/*\r\n  LzmaDecodeSize.c\r\n  LZMA Decoder (optimized for Size version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\ntypedef struct _CRangeDecoder\r\n{\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  #ifdef _LZMA_IN_CB\r\n  ILzmaInCallback *InCallback;\r\n  int Result;\r\n  #endif\r\n  int ExtraBytes;\r\n} CRangeDecoder;\r\n\r\nByte RangeDecoderReadByte(CRangeDecoder *rd)\r\n{\r\n  if (rd->Buffer == rd->BufferLim)\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    SizeT size;\r\n    rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);\r\n    rd->BufferLim = rd->Buffer + size;\r\n    if (size == 0)\r\n    #endif\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n  }\r\n  return (*rd->Buffer++);\r\n}\r\n\r\n/* #define ReadByte (*rd->Buffer++) */\r\n#define ReadByte (RangeDecoderReadByte(rd))\r\n\r\nvoid RangeDecoderInit(CRangeDecoder *rd\r\n  #ifndef _LZMA_IN_CB\r\n    , const Byte *stream, SizeT bufferSize\r\n  #endif\r\n    )\r\n{\r\n  int i;\r\n  #ifdef _LZMA_IN_CB\r\n  rd->Buffer = rd->BufferLim = 0;\r\n  #else\r\n  rd->Buffer = stream;\r\n  rd->BufferLim = stream + bufferSize;\r\n  #endif\r\n  rd->ExtraBytes = 0;\r\n  rd->Code = 0;\r\n  rd->Range = (0xFFFFFFFF);\r\n  for(i = 0; i < 5; i++)\r\n    rd->Code = (rd->Code << 8) | ReadByte;\r\n}\r\n\r\n#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;        \r\n#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;\r\n#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }\r\n\r\nUInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)\r\n{\r\n  RC_INIT_VAR\r\n  UInt32 result = 0;\r\n  int i;\r\n  for (i = numTotalBits; i != 0; i--)\r\n  {\r\n    /* UInt32 t; */\r\n    range >>= 1;\r\n\r\n    result <<= 1;\r\n    if (code >= range)\r\n    {\r\n      code -= range;\r\n      result |= 1;\r\n    }\r\n    /*\r\n    t = (code - range) >> 31;\r\n    t &= 1;\r\n    code -= range & (t - 1);\r\n    result = (result + result) | (1 - t);\r\n    */\r\n    RC_NORMALIZE\r\n  }\r\n  RC_FLUSH_VAR\r\n  return result;\r\n}\r\n\r\nint RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)\r\n{\r\n  UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;\r\n  if (rd->Code < bound)\r\n  {\r\n    rd->Range = bound;\r\n    *prob += (kBitModelTotal - *prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 0;\r\n  }\r\n  else\r\n  {\r\n    rd->Range -= bound;\r\n    rd->Code -= bound;\r\n    *prob -= (*prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 1;\r\n  }\r\n}\r\n\r\n#define RC_GET_BIT2(prob, mi, A0, A1) \\\r\n  UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \\\r\n  if (code < bound) \\\r\n    { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \\\r\n  else \\\r\n    { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)               \r\n\r\nint RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = numLevels; i != 0; i--)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT(prob, mi)\r\n    #else\r\n    mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return mi - (1 << numLevels);\r\n}\r\n\r\nint RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  int symbol = 0;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = 0; i < numLevels; i++)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))\r\n    #else\r\n    int bit = RangeDecoderBitDecode(probs + mi, rd);\r\n    mi = mi + mi + bit;\r\n    symbol |= (bit << i);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + symbol;\r\n    RC_GET_BIT(prob, symbol)\r\n    #else\r\n    symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n    #endif\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    int bit;\r\n    int matchBit = (matchByte >> 7) & 1;\r\n    matchByte <<= 1;\r\n    #ifdef _LZMA_LOC_OPT\r\n    {\r\n      CProb *prob = probs + 0x100 + (matchBit << 8) + symbol;\r\n      RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)\r\n    }\r\n    #else\r\n    bit = RangeDecoderBitDecode(probs + 0x100 + (matchBit << 8) + symbol, rd);\r\n    symbol = (symbol << 1) | bit;\r\n    #endif\r\n    if (matchBit != bit)\r\n    {\r\n      while (symbol < 0x100)\r\n      {\r\n        #ifdef _LZMA_LOC_OPT\r\n        CProb *prob = probs + symbol;\r\n        RC_GET_BIT(prob, symbol)\r\n        #else\r\n        symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n        #endif\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\nint LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)\r\n{\r\n  if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)\r\n    return RangeDecoderBitTreeDecode(p + LenLow +\r\n        (posState << kLenNumLowBits), kLenNumLowBits, rd);\r\n  if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)\r\n    return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +\r\n        (posState << kLenNumMidBits), kLenNumMidBits, rd);\r\n  return kLenNumLowSymbols + kLenNumMidSymbols + \r\n      RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);\r\n}\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  CRangeDecoder rd;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  rd.Range = vs->Range;\r\n  rd.Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  rd.Buffer = vs->Buffer;\r\n  rd.BufferLim = vs->BufferLim;\r\n  #else\r\n  rd.Buffer = inStream;\r\n  rd.BufferLim = inStream + inSize;\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RangeDecoderInit(&rd\r\n          #ifndef _LZMA_IN_CB\r\n          , inStream, inSize\r\n          #endif\r\n          );\r\n      #ifdef _LZMA_IN_CB\r\n      if (rd.Result != LZMA_RESULT_OK)\r\n        return rd.Result;\r\n      #endif\r\n      if (rd.ExtraBytes != 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  rd.Result = LZMA_RESULT_OK;\r\n  #endif\r\n  rd.ExtraBytes = 0;\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  #endif\r\n  RangeDecoderInit(&rd\r\n      #ifndef _LZMA_IN_CB\r\n      , inStream, inSize\r\n      #endif\r\n      );\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  if (rd.Result != LZMA_RESULT_OK)\r\n    return rd.Result;\r\n  #endif\r\n  if (rd.ExtraBytes != 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n    #ifdef _LZMA_IN_CB\r\n    if (rd.Result != LZMA_RESULT_OK)\r\n      return rd.Result;\r\n    #endif\r\n    if (rd.ExtraBytes != 0)\r\n      return LZMA_RESULT_DATA_ERROR;\r\n    if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n    {\r\n      CProb *probs = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        Byte matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);\r\n      }\r\n      else\r\n        previousByte = LzmaLiteralDecode(probs, &rd);\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)\r\n      {\r\n        if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)\r\n        {\r\n          if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n      \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n\r\n            state = state < 7 ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n            continue;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)\r\n            distance = rep1;\r\n          else \r\n          {\r\n            if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)\r\n              distance = rep2;\r\n            else\r\n            {\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        len = LzmaLenDecode(p + RepLenCoder, &rd, posState);\r\n        state = state < 7 ? 8 : 11;\r\n      }\r\n      else\r\n      {\r\n        int posSlot;\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < 7 ? 7 : 10;\r\n        len = LzmaLenDecode(p + LenCoder, &rd, posState);\r\n        posSlot = RangeDecoderBitTreeDecode(p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits), kNumPosSlotBits, &rd);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 += RangeDecoderReverseBitTreeDecode(\r\n                p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);\r\n          }\r\n          else\r\n          {\r\n            rep0 += RangeDecoderDecodeDirectBits(&rd, \r\n                numDirectBits - kNumAlignBits) << kNumAlignBits;\r\n            rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = rd.Range;\r\n  vs->Code = rd.Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = rd.Buffer;\r\n  vs->BufferLim = rd.BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(rd.Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/LzmaStateDecode.c",
    "content": "/*\r\n  LzmaStateDecode.c\r\n  LZMA Decoder (State version)\r\n  \r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\n/* kRequiredInBufferSize = number of required input bytes for worst case: \r\n   longest match with longest distance.\r\n   kLzmaInBufferSize must be larger than kRequiredInBufferSize \r\n   23 bits = 2 (match select) + 10 (len) + 6 (distance) + 4(align) + 1 (RC_NORMALIZE)\r\n*/\r\n\r\n#define kRequiredInBufferSize ((23 * (kNumBitModelTotalBits - kNumMoveBits + 1) + 26 + 9) / 8)\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n    return LZMA_RESULT_OK;\r\n  }\r\n}\r\n\r\nint LzmaDecode(\r\n    CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding)\r\n{\r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n\r\n  unsigned char *Buffer = vs->Buffer;\r\n  int BufferSize = vs->BufferSize; /* don't change it to unsigned int */\r\n  CProb *p = vs->Probs;\r\n\r\n  int state = vs->State;\r\n  unsigned char previousByte;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  SizeT nowPos = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  unsigned char *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  unsigned char tempDictionary[4];\r\n\r\n  (*inSizeProcessed) = 0;\r\n  (*outSizeProcessed) = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n    {\r\n      Buffer[BufferSize++] = *inStream++;\r\n      (*inSizeProcessed)++;\r\n      inSize--;\r\n    }\r\n    if (BufferSize < 5)\r\n    {\r\n      vs->BufferSize = BufferSize;\r\n      return finishDecoding ? LZMA_RESULT_DATA_ERROR : LZMA_RESULT_OK;\r\n    }\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RC_INIT;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  for (;;)\r\n  {\r\n    int bufferPos = (int)(Buffer - vs->Buffer);\r\n    if (BufferSize - bufferPos < kRequiredInBufferSize)\r\n    {\r\n      int i;\r\n      BufferSize -= bufferPos;\r\n      if (BufferSize < 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n      for (i = 0; i < BufferSize; i++)\r\n        vs->Buffer[i] = Buffer[i];\r\n      Buffer = vs->Buffer;\r\n      while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n      {\r\n        Buffer[BufferSize++] = *inStream++;\r\n        (*inSizeProcessed)++;\r\n        inSize--;\r\n      }\r\n      if (BufferSize < kRequiredInBufferSize && !finishDecoding)\r\n        break;\r\n    }\r\n    if (nowPos >= outSize)\r\n      break;\r\n    {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)((nowPos + globalPos) & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        ((((nowPos + globalPos)& literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (unsigned char)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            UInt32 pos;\r\n            UpdateBit0(prob);\r\n            if (distanceLimit == 0)\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            outStream[nowPos++] = previousByte;\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      if (rep0 > distanceLimit) \r\n        return LZMA_RESULT_DATA_ERROR;\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n\r\n      do\r\n      {\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  BufferSize -= (int)(Buffer - vs->Buffer);\r\n  if (BufferSize < 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    int i;\r\n    for (i = 0; i < BufferSize; i++)\r\n      vs->Buffer[i] = Buffer[i];\r\n  }\r\n  vs->BufferSize = BufferSize;\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = (UInt32)(globalPos + nowPos);\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n\r\n  (*outSizeProcessed) = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/LzmaStateDecode.h",
    "content": "/* \r\n  LzmaStateDecode.h\r\n  LZMA Decoder interface (State version)\r\n\r\n  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMASTATEDECODE_H\r\n#define __LZMASTATEDECODE_H\r\n\r\n#include \"LzmaTypes.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  UInt32 DictionarySize;\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))\r\n\r\n#define kLzmaInBufferSize 64   /* don't change it. it must be larger than kRequiredInBufferSize */\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n  unsigned char *Dictionary;\r\n\r\n  unsigned char Buffer[kLzmaInBufferSize];\r\n  int BufferSize;\r\n\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;  /* -2: decoder needs internal initialization\r\n                     -1: stream was finished, \r\n                      0: ok\r\n                    > 0: need to write RemainLen bytes as match Reps[0],\r\n                  */\r\n  unsigned char TempDictionary[4];  /* it's required when DictionarySize = 0 */\r\n} CLzmaDecoderState;\r\n\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }\r\n\r\n/* LzmaDecode: decoding from input stream to output stream.\r\n  If finishDecoding != 0, then there are no more bytes in input stream\r\n  after inStream[inSize - 1]. */\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize,  SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/LzmaStateTest.c",
    "content": "/* \r\nLzmaStateTest.c\r\nTest application for LZMA Decoder (State version)\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\n#define kInBufferSize (1 << 15)\r\n#define kOutBufferSize (1 << 15)\r\n\r\nunsigned char g_InBuffer[kInBufferSize];\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n  { return fread(data, 1, size, file); }\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size); }\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0; \r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  int i;\r\n  int res = 0;\r\n  CLzmaDecoderState state;  /* it's about 140 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n  SizeT inAvail = 0;\r\n  unsigned char *inBuffer = 0;\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n  \r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    unsigned char b;\r\n    if (!MyReadFileAndCheck(inFile, &b, 1))\r\n      return PrintError(rs, kCantReadMessage);\r\n    if (b != 0xFF)\r\n      waitEOS = 0;\r\n    if (i < 4)\r\n      outSize += (UInt32)(b) << (i * 8);\r\n    else\r\n      outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  \r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      free(state.Probs);\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    }\r\n  }\r\n  \r\n  /* Decompress */\r\n  \r\n  LzmaDecoderInit(&state);\r\n  \r\n  do\r\n  {\r\n    SizeT inProcessed, outProcessed;\r\n    int finishDecoding;\r\n    UInt32 outAvail = kOutBufferSize;\r\n    if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n      outAvail = outSize;\r\n    if (inAvail == 0)\r\n    {\r\n      inAvail = (SizeT)MyReadFile(inFile, g_InBuffer, kInBufferSize);\r\n      inBuffer = g_InBuffer;\r\n    }\r\n    finishDecoding = (inAvail == 0);\r\n    res = LzmaDecode(&state,\r\n        inBuffer, inAvail, &inProcessed,\r\n        g_OutBuffer, outAvail, &outProcessed,\r\n        finishDecoding);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n      break;\r\n    }\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n    \r\n    if (outFile != 0)  \r\n      if (fwrite(g_OutBuffer, 1, outProcessed, outFile) != outProcessed)\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n        break;\r\n      }\r\n      \r\n    if (outSize < outProcessed)\r\n      outSizeHigh--;\r\n    outSize -= (UInt32)outProcessed;\r\n    outSize &= 0xFFFFFFFF;\r\n\r\n    if (outProcessed == 0 && finishDecoding)\r\n    {\r\n      if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n        res = 1;\r\n      break;\r\n    }\r\n  }\r\n  while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n\r\n  free(state.Dictionary);\r\n  free(state.Probs);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-02\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/LzmaTest.c",
    "content": "/* \r\nLzmaTest.c\r\nTest application for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-05)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fread(data, 1, size, file); \r\n}\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size);} \r\n\r\nsize_t MyWriteFile(FILE *file, const void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fwrite(data, 1, size, file); \r\n}\r\n\r\nint MyWriteFileAndCheck(FILE *file, const void *data, size_t size)\r\n  { return (MyWriteFile(file, data, size) == size); }\r\n\r\n#ifdef _LZMA_IN_CB\r\n#define kInBufferSize (1 << 15)\r\ntypedef struct _CBuffer\r\n{\r\n  ILzmaInCallback InCallback;\r\n  FILE *File;\r\n  unsigned char Buffer[kInBufferSize];\r\n} CBuffer;\r\n\r\nint LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CBuffer *b = (CBuffer *)object;\r\n  *buffer = b->Buffer;\r\n  *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);\r\n  return LZMA_RESULT_OK;\r\n}\r\nCBuffer g_InBuffer;\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define kOutBufferSize (1 << 15)\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n#endif\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0;\r\n  #ifndef _LZMA_OUT_READ\r\n  SizeT outSizeFull;\r\n  unsigned char *outStream;\r\n  #endif\r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  SizeT compressedSize;\r\n  unsigned char *inStream;\r\n  #endif\r\n\r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n  int res;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.File = inFile;\r\n  #endif\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  {\r\n    long length;\r\n    fseek(inFile, 0, SEEK_END);\r\n    length = ftell(inFile);\r\n    fseek(inFile, 0, SEEK_SET);\r\n    if ((long)(SizeT)length != length)\r\n      return PrintError(rs, \"Too big compressed stream\");\r\n    compressedSize = (SizeT)(length - (LZMA_PROPERTIES_SIZE + 8));\r\n  }\r\n  #endif\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n\r\n  {\r\n    int i;\r\n    for (i = 0; i < 8; i++)\r\n    {\r\n      unsigned char b;\r\n      if (!MyReadFileAndCheck(inFile, &b, 1))\r\n        return PrintError(rs, kCantReadMessage);\r\n      if (b != 0xFF)\r\n        waitEOS = 0;\r\n      if (i < 4)\r\n        outSize += (UInt32)(b) << (i * 8);\r\n      else\r\n        outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n    }\r\n    \r\n    #ifndef _LZMA_OUT_READ\r\n    if (waitEOS)\r\n      return PrintError(rs, \"Stream with EOS marker is not supported\");\r\n    outSizeFull = (SizeT)outSize;\r\n    if (sizeof(SizeT) >= 8)\r\n      outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);\r\n    else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)\r\n      return PrintError(rs, \"Too big uncompressed stream\");\r\n    #endif\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n  #else\r\n  if (outSizeFull == 0)\r\n    outStream = 0;\r\n  else\r\n    outStream = (unsigned char *)malloc(outSizeFull);\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  if (compressedSize == 0)\r\n    inStream = 0;\r\n  else\r\n    inStream = (unsigned char *)malloc(compressedSize);\r\n  #endif\r\n\r\n  if (state.Probs == 0 \r\n    #ifdef _LZMA_OUT_READ\r\n    || (state.Dictionary == 0 && state.Properties.DictionarySize != 0)\r\n    #else\r\n    || (outStream == 0 && outSizeFull != 0)\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    || (inStream == 0 && compressedSize != 0)\r\n    #endif\r\n    )\r\n  {\r\n    free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    free(state.Dictionary);\r\n    #else\r\n    free(outStream);\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    free(inStream);\r\n    #endif\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  }\r\n\r\n  /* Decompress */\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  #else\r\n  if (!MyReadFileAndCheck(inFile, inStream, compressedSize))\r\n    return PrintError(rs, kCantReadMessage);\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inAvail = compressedSize;\r\n    const unsigned char *inBuffer = inStream;\r\n    #endif\r\n    LzmaDecoderInit(&state);\r\n    do\r\n    {\r\n      #ifndef _LZMA_IN_CB\r\n      SizeT inProcessed;\r\n      #endif\r\n      SizeT outProcessed;\r\n      SizeT outAvail = kOutBufferSize;\r\n      if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n        outAvail = (SizeT)outSize;\r\n      res = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &g_InBuffer.InCallback,\r\n        #else\r\n        inBuffer, inAvail, &inProcessed,\r\n        #endif\r\n        g_OutBuffer, outAvail, &outProcessed);\r\n      if (res != 0)\r\n      {\r\n        sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n        res = 1;\r\n        break;\r\n      }\r\n      #ifndef _LZMA_IN_CB\r\n      inAvail -= inProcessed;\r\n      inBuffer += inProcessed;\r\n      #endif\r\n      \r\n      if (outFile != 0)  \r\n        if (!MyWriteFileAndCheck(outFile, g_OutBuffer, (size_t)outProcessed))\r\n        {\r\n          PrintError(rs, kCantWriteMessage);\r\n          res = 1;\r\n          break;\r\n        }\r\n        \r\n      if (outSize < outProcessed)\r\n        outSizeHigh--;\r\n      outSize -= (UInt32)outProcessed;\r\n      outSize &= 0xFFFFFFFF;\r\n        \r\n      if (outProcessed == 0)\r\n      {\r\n        if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n          res = 1;\r\n        break;\r\n      }\r\n    }\r\n    while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n  }\r\n\r\n  #else\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inProcessed;\r\n    #endif\r\n    SizeT outProcessed;\r\n    res = LzmaDecode(&state,\r\n      #ifdef _LZMA_IN_CB\r\n      &g_InBuffer.InCallback,\r\n      #else\r\n      inStream, compressedSize, &inProcessed,\r\n      #endif\r\n      outStream, outSizeFull, &outProcessed);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n    }\r\n    else if (outFile != 0)\r\n    {\r\n      if (!MyWriteFileAndCheck(outFile, outStream, (size_t)outProcessed))\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  free(state.Dictionary);\r\n  #else\r\n  free(outStream);\r\n  #endif\r\n  #ifndef _LZMA_IN_CB\r\n  free(inStream);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-05\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/LzmaTypes.h",
    "content": "/* \r\nLzmaTypes.h \r\n\r\nTypes for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.40 (2006-05-01)\r\n*/\r\n\r\n#ifndef __LZMATYPES_H\r\n#define __LZMATYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif \r\n\r\n/* #define _LZMA_NO_SYSTEM_SIZE_T */\r\n/* You can use it, if you don't want <stddef.h> */\r\n\r\n#ifndef _7ZIP_SIZET_DEFINED\r\n#define _7ZIP_SIZET_DEFINED\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\n#include <stddef.h>\r\ntypedef size_t SizeT;\r\n#endif\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/kmod/uncomp.c",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $ */\n\n/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */\n\n#ifndef __KERNEL__\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <assert.h>\n#include <pthread.h>\n#define unlikely(x)\t\t__builtin_expect(!!(x), 0)\n#define BUG_ON(x)\t\tassert(!(x))\n/* sqlzma buffers are always larger than a page. true? */\n#define kmalloc(sz,gfp)\t\tmalloc(sz)\n#define kfree(p)\t\tfree(p)\n#define zlib_inflate(s, f)\tinflate(s, f)\n#define zlib_inflateInit(s)\tinflateInit(s)\n#define zlib_inflateReset(s)\tinflateReset(s)\n#define zlib_inflateEnd(s)\tinflateEnd(s)\n#else\n#include <linux/init.h>\n#include <linux/module.h>\n#include <linux/kernel.h>\n#include <linux/vmalloc.h>\n#ifndef WARN_ON_ONCE\n#define WARN_ON_ONCE(b)\tWARN_ON(b)\n#endif\n#endif /* __KERNEL__ */\n\n#include \"sqlzma.h\"\n#include \"LzmaDecode.h\"\n\nstatic int LzmaUncompress(struct sqlzma_un *un)\n{\n\tint err, i, ret;\n\tSizeT outSize, inProcessed, outProcessed, srclen;\n\t/* it's about 24-80 bytes structure, if int is 32-bit */\n\tCLzmaDecoderState state;\n\tunsigned char *dst, *src, a[8];\n\tstruct sized_buf *sbuf;\n\n\t/* Decode LZMA properties and allocate memory */\n\terr = -EINVAL;\n\tsrc = (void *)un->un_cmbuf;\n\tret = LzmaDecodeProperties(&state.Properties, src,\n\t\t\t\t   LZMA_PROPERTIES_SIZE);\n\tsrc += LZMA_PROPERTIES_SIZE;\n\tif (unlikely(ret != LZMA_RESULT_OK))\n\t\tgoto out;\n\ti = LzmaGetNumProbs(&state.Properties);\n\tif (unlikely(i <= 0))\n\t\ti = 1;\n\ti *= sizeof(CProb);\n\tsbuf = un->un_a + SQUN_PROB;\n\tif (unlikely(sbuf->sz < i)) {\n\t\tif (sbuf->buf && sbuf->buf != un->un_prob)\n\t\t\tkfree(sbuf->buf);\n#ifdef __KERNEL__\n\t\tprintk(\"%s:%d: %d --> %d\\n\", __func__, __LINE__, sbuf->sz, i);\n#else\n\t\tprintf(\"%d --> %d\\n\", sbuf->sz, i);\n#endif\n\t\terr = -ENOMEM;\n\t\tsbuf->sz = 0;\n\t\tsbuf->buf = kmalloc(i, GFP_ATOMIC);\n\t\tif (unlikely(!sbuf->buf))\n\t\t\tgoto out;\n\t\tsbuf->sz = i;\n\t}\n\tstate.Probs = (void *)sbuf->buf;\n\n\t/* Read uncompressed size */\n\tmemcpy(a, src, sizeof(a));\n\tsrc += sizeof(a);\n\toutSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);\n\n\terr = -EINVAL;\n\tdst = un->un_resbuf;\n\tif (unlikely(!dst || outSize > un->un_reslen))\n\t\tgoto out;\n\tun->un_reslen = outSize;\n\tsrclen = un->un_cmlen - (src - un->un_cmbuf);\n\n\t/* Decompress */\n\terr = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,\n\t\t\t &outProcessed);\n\tif (unlikely(err))\n\t\terr = -EINVAL;\n\n out:\n#ifndef __KERNEL__\n\tif (err)\n\t\tfprintf(stderr, \"err %d\\n\", err);\n#endif\n\treturn err;\n}\n\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst)\n{\n\tint err, by_lzma = 1;\n\tif (un->un_lzma && is_lzma(*src->buf)) {\n\t\tun->un_cmbuf = src->buf;\n\t\tun->un_cmlen = src->sz;\n\t\tun->un_resbuf = dst->buf;\n\t\tun->un_reslen = dst->sz;\n\n\t\t/* this library is thread-safe */\n\t\terr = LzmaUncompress(un);\n\t\tgoto out;\n\t}\n\n\tby_lzma = 0;\n\terr = zlib_inflateReset(&un->un_stream);\n\tif (unlikely(err != Z_OK))\n\t\tgoto out;\n\tun->un_stream.next_in = src->buf;\n\tun->un_stream.avail_in = src->sz;\n\tun->un_stream.next_out = dst->buf;\n\tun->un_stream.avail_out = dst->sz;\n\terr = zlib_inflate(&un->un_stream, Z_FINISH);\n\tif (err == Z_STREAM_END)\n\t\terr = 0;\n\n out:\n\tif (unlikely(err)) {\n#ifdef __KERNEL__\n\t\tWARN_ON_ONCE(1);\n#else\n\t\tchar a[64] = \"ZLIB \";\n\t\tif (by_lzma) {\n\t\t\tstrcpy(a, \"LZMA \");\n#ifdef _REENTRANT\n\t\t\tstrerror_r(err, a + 5, sizeof(a) - 5);\n#else\n\t\t\tstrncat(a, strerror(err), sizeof(a) - 5);\n#endif\n\t\t} else\n\t\t\tstrncat(a, zError(err), sizeof(a) - 5);\n\t\tfprintf(stderr, \"%s: %.*s\\n\", __func__, sizeof(a), a);\n#endif\n\t}\n\treturn err;\n}\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)\n{\n\tint err;\n\n\terr = -ENOMEM;\n\tun->un_lzma = do_lzma;\n\tmemset(un->un_a, 0, sizeof(un->un_a));\n\tun->un_a[SQUN_PROB].buf = un->un_prob;\n\tun->un_a[SQUN_PROB].sz = sizeof(un->un_prob);\n\tif (res_sz) {\n\t\tun->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);\n\t\tif (unlikely(!un->un_a[SQUN_RESULT].buf))\n\t\t\treturn err;\n\t\tun->un_a[SQUN_RESULT].sz = res_sz;\n\t}\n\n\tun->un_stream.next_in = NULL;\n\tun->un_stream.avail_in = 0;\n#ifdef __KERNEL__\n\tun->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(),\n\t\t\t\t\t  GFP_KERNEL);\n\tif (unlikely(!un->un_stream.workspace))\n\t\treturn err;\n#else\n\tun->un_stream.opaque = NULL;\n\tun->un_stream.zalloc = Z_NULL;\n\tun->un_stream.zfree = Z_NULL;\n#endif\n\terr = zlib_inflateInit(&un->un_stream);\n\tif (unlikely(err == Z_MEM_ERROR))\n\t\treturn -ENOMEM;\n\tBUG_ON(err);\n\treturn err;\n}\n\nvoid sqlzma_fin(struct sqlzma_un *un)\n{\n\tint i;\n\tfor (i = 0; i < SQUN_LAST; i++)\n\t\tif (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)\n\t\t\tkfree(un->un_a[i].buf);\n\tBUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);\n}\n\n#ifdef __KERNEL__\nEXPORT_SYMBOL(sqlzma_un);\nEXPORT_SYMBOL(sqlzma_init);\nEXPORT_SYMBOL(sqlzma_fin);\n\n#if 0\nstatic int __init sqlzma_init(void)\n{\n\treturn 0;\n}\n\nstatic void __exit sqlzma_exit(void)\n{\n}\n\nmodule_init(sqlzma_init);\nmodule_exit(sqlzma_exit);\n#endif\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Junjiro Okajima <sfjro at users dot sf dot net>\");\nMODULE_VERSION(\"$Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $\");\nMODULE_DESCRIPTION(\"LZMA uncompress for squashfs. \"\n\t\t   \"Some functions for squashfs to support LZMA and \"\n\t\t   \"a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/kmod.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: kmod.mk,v 1.1 2007-11-05 05:43:35 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\nifndef KDir\n$(error KDir is not defined)\nendif\n\n#include makefile.gcc\n\nKmod = kmod\nEXTRA_CFLAGS += -Wall -Werror -I${CURDIR} -I${Sqlzma}\n# -D_LZMA_PROB32\nEXTRA_CFLAGS += $(shell ${CPP} ${CFLAGS} -P testflags.c)\n\nall: ${Kmod}/uncomp.c\n\t${MAKE} EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\" M=${CURDIR}/${Kmod} \\\n\t\t-C ${KDir} C=0 V=0 modules\n\n${Kmod}/uncomp.c: uncomp.c\n\tln $< $@\n\nclean: clean_kmod\nclean_kmod:\n\t${MAKE} -C ${KDir} M=${CURDIR}/${Kmod} V=0 clean\n\t${RM} ${Kmod}/*~\n\t-@test -e ${Kmod}/uncomp.c && \\\n\t\tdiff -q ${Kmod}/uncomp.c uncomp.c > /dev/null && \\\n\t\tfind ${Kmod}/uncomp.c -links +1 | xargs -r ${RM}\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. KDir=/lib/modules/`uname -r`/build -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/sqlzma.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\n#include makefile.gcc\nCFLAGS = -c -O2 -Wall -pedantic -D _LZMA_PROB32\n\nifdef KDir\ninclude kmod.mk\nendif\n\nifdef UseDebugFlags\nDebugFlags = -O0 -g -UNDEBUG\nendif\nCFLAGS += -DNDEBUG ${DebugFlags}\nTgt = libunlzma.a libunlzma_r.a\n\nall: ${Tgt}\n\n%_r.c: %.c\n\tln $< $@\n# -pthread\n%_r.o: CFLAGS += -D_REENTRANT -include pthread.h\n\nuncomp.o uncomp_r.o: CFLAGS += -I${Sqlzma}\nuncomp.o: uncomp.c ${Sqlzma}/sqlzma.h\n\nlibunlzma.a: uncomp.o LzmaDecode.o\n\t${AR} cr $@ $^\nlibunlzma_r.a: uncomp_r.o LzmaDecode_r.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) ${Tgt} uncomp.o uncomp_r.o LzmaDecode_r.o LzmaDecode.o  *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/testflags.c",
    "content": "#ifdef _LZMA_PROB32\n-D_LZMA_PROB32\n#else\n-U_LZMA_PROB32\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Compress/Lzma/uncomp.c",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $ */\n\n/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */\n\n#ifndef __KERNEL__\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <assert.h>\n#include <pthread.h>\n#define unlikely(x)\t\t__builtin_expect(!!(x), 0)\n#define BUG_ON(x)\t\tassert(!(x))\n/* sqlzma buffers are always larger than a page. true? */\n#define kmalloc(sz,gfp)\t\tmalloc(sz)\n#define kfree(p)\t\tfree(p)\n#define zlib_inflate(s, f)\tinflate(s, f)\n#define zlib_inflateInit(s)\tinflateInit(s)\n#define zlib_inflateReset(s)\tinflateReset(s)\n#define zlib_inflateEnd(s)\tinflateEnd(s)\n#else\n#include <linux/init.h>\n#include <linux/module.h>\n#include <linux/kernel.h>\n#include <linux/vmalloc.h>\n#ifndef WARN_ON_ONCE\n#define WARN_ON_ONCE(b)\tWARN_ON(b)\n#endif\n#endif /* __KERNEL__ */\n\n#include \"sqlzma.h\"\n#include \"LzmaDecode.h\"\n\nstatic int LzmaUncompress(struct sqlzma_un *un)\n{\n\tint err, i, ret;\n\tSizeT outSize, inProcessed, outProcessed, srclen;\n\t/* it's about 24-80 bytes structure, if int is 32-bit */\n\tCLzmaDecoderState state;\n\tunsigned char *dst, *src, a[8];\n\tstruct sized_buf *sbuf;\n\n\t/* Decode LZMA properties and allocate memory */\n\terr = -EINVAL;\n\tsrc = (void *)un->un_cmbuf;\n\tret = LzmaDecodeProperties(&state.Properties, src,\n\t\t\t\t   LZMA_PROPERTIES_SIZE);\n\tsrc += LZMA_PROPERTIES_SIZE;\n\tif (unlikely(ret != LZMA_RESULT_OK))\n\t\tgoto out;\n\ti = LzmaGetNumProbs(&state.Properties);\n\tif (unlikely(i <= 0))\n\t\ti = 1;\n\ti *= sizeof(CProb);\n\tsbuf = un->un_a + SQUN_PROB;\n\tif (unlikely(sbuf->sz < i)) {\n\t\tif (sbuf->buf && sbuf->buf != un->un_prob)\n\t\t\tkfree(sbuf->buf);\n#ifdef __KERNEL__\n\t\tprintk(\"%s:%d: %d --> %d\\n\", __func__, __LINE__, sbuf->sz, i);\n#else\n\t\tprintf(\"%d --> %d\\n\", sbuf->sz, i);\n#endif\n\t\terr = -ENOMEM;\n\t\tsbuf->sz = 0;\n\t\tsbuf->buf = kmalloc(i, GFP_ATOMIC);\n\t\tif (unlikely(!sbuf->buf))\n\t\t\tgoto out;\n\t\tsbuf->sz = i;\n\t}\n\tstate.Probs = (void *)sbuf->buf;\n\n\t/* Read uncompressed size */\n\tmemcpy(a, src, sizeof(a));\n\tsrc += sizeof(a);\n\toutSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);\n\n\terr = -EINVAL;\n\tdst = un->un_resbuf;\n\tif (unlikely(!dst || outSize > un->un_reslen))\n\t\tgoto out;\n\tun->un_reslen = outSize;\n\tsrclen = un->un_cmlen - (src - un->un_cmbuf);\n\n\t/* Decompress */\n\terr = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,\n\t\t\t &outProcessed);\n\tif (unlikely(err))\n\t\terr = -EINVAL;\n\n out:\n#ifndef __KERNEL__\n\tif (err)\n\t\tfprintf(stderr, \"err %d\\n\", err);\n#endif\n\treturn err;\n}\n\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst)\n{\n\tint err, by_lzma = 1;\n\tif (un->un_lzma && is_lzma(*src->buf)) {\n\t\tun->un_cmbuf = src->buf;\n\t\tun->un_cmlen = src->sz;\n\t\tun->un_resbuf = dst->buf;\n\t\tun->un_reslen = dst->sz;\n\n\t\t/* this library is thread-safe */\n\t\terr = LzmaUncompress(un);\n\t\tgoto out;\n\t}\n\n\tby_lzma = 0;\n\terr = zlib_inflateReset(&un->un_stream);\n\tif (unlikely(err != Z_OK))\n\t\tgoto out;\n\tun->un_stream.next_in = src->buf;\n\tun->un_stream.avail_in = src->sz;\n\tun->un_stream.next_out = dst->buf;\n\tun->un_stream.avail_out = dst->sz;\n\terr = zlib_inflate(&un->un_stream, Z_FINISH);\n\tif (err == Z_STREAM_END)\n\t\terr = 0;\n\n out:\n\tif (unlikely(err)) {\n#ifdef __KERNEL__\n\t\tWARN_ON_ONCE(1);\n#else\n\t\tchar a[64] = \"ZLIB \";\n\t\tif (by_lzma) {\n\t\t\tstrcpy(a, \"LZMA \");\n#ifdef _REENTRANT\n\t\t\tstrerror_r(err, a + 5, sizeof(a) - 5);\n#else\n\t\t\tstrncat(a, strerror(err), sizeof(a) - 5);\n#endif\n\t\t} else\n\t\t\tstrncat(a, zError(err), sizeof(a) - 5);\n\t\tfprintf(stderr, \"%s: %.*s\\n\", __func__, sizeof(a), a);\n#endif\n\t}\n\treturn err;\n}\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)\n{\n\tint err;\n\n\terr = -ENOMEM;\n\tun->un_lzma = do_lzma;\n\tmemset(un->un_a, 0, sizeof(un->un_a));\n\tun->un_a[SQUN_PROB].buf = un->un_prob;\n\tun->un_a[SQUN_PROB].sz = sizeof(un->un_prob);\n\tif (res_sz) {\n\t\tun->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);\n\t\tif (unlikely(!un->un_a[SQUN_RESULT].buf))\n\t\t\treturn err;\n\t\tun->un_a[SQUN_RESULT].sz = res_sz;\n\t}\n\n\tun->un_stream.next_in = NULL;\n\tun->un_stream.avail_in = 0;\n#ifdef __KERNEL__\n\tun->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(),\n\t\t\t\t\t  GFP_KERNEL);\n\tif (unlikely(!un->un_stream.workspace))\n\t\treturn err;\n#else\n\tun->un_stream.opaque = NULL;\n\tun->un_stream.zalloc = Z_NULL;\n\tun->un_stream.zfree = Z_NULL;\n#endif\n\terr = zlib_inflateInit(&un->un_stream);\n\tif (unlikely(err == Z_MEM_ERROR))\n\t\treturn -ENOMEM;\n\tBUG_ON(err);\n\treturn err;\n}\n\nvoid sqlzma_fin(struct sqlzma_un *un)\n{\n\tint i;\n\tfor (i = 0; i < SQUN_LAST; i++)\n\t\tif (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)\n\t\t\tkfree(un->un_a[i].buf);\n\tBUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);\n}\n\n#ifdef __KERNEL__\nEXPORT_SYMBOL(sqlzma_un);\nEXPORT_SYMBOL(sqlzma_init);\nEXPORT_SYMBOL(sqlzma_fin);\n\n#if 0\nstatic int __init sqlzma_init(void)\n{\n\treturn 0;\n}\n\nstatic void __exit sqlzma_exit(void)\n{\n}\n\nmodule_init(sqlzma_init);\nmodule_exit(sqlzma_exit);\n#endif\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Junjiro Okajima <sfjro at users dot sf dot net>\");\nMODULE_VERSION(\"$Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $\");\nMODULE_DESCRIPTION(\"LZMA uncompress for squashfs. \"\n\t\t   \"Some functions for squashfs to support LZMA and \"\n\t\t   \"a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/CpuArch.h",
    "content": "/* CpuArch.h */\r\n\r\n#ifndef __CPUARCH_H\r\n#define __CPUARCH_H\r\n\r\n/* \r\nLITTLE_ENDIAN_UNALIGN means:\r\n  1) CPU is LITTLE_ENDIAN\r\n  2) it's allowed to make unaligned memory accesses\r\nif LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know \r\nabout these properties of platform.\r\n*/\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/IStream.h",
    "content": "/* IStream.h */\r\n\r\n#ifndef __C_ISTREAM_H\r\n#define __C_ISTREAM_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _ISeqInStream\r\n{\r\n  HRes (*Read)(void *object, void *data, UInt32 size, UInt32 *processedSize);\r\n} ISeqInStream;\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Sort.c",
    "content": "/* Sort.c */\r\n\r\n#include \"Sort.h\"\r\n\r\n#define HeapSortDown(p, k, size, temp) \\\r\n  { for (;;) { \\\r\n    UInt32 s = (k << 1); \\\r\n    if (s > size) break; \\\r\n    if (s < size && p[s + 1] > p[s]) s++; \\\r\n    if (temp >= p[s]) break; \\\r\n    p[k] = p[s]; k = s; \\\r\n  } p[k] = temp; }\r\n\r\nvoid HeapSort(UInt32 *p, UInt32 size)\r\n{\r\n  if (size <= 1)\r\n    return;\r\n  p--;\r\n  {\r\n    UInt32 i = size / 2;\r\n    do\r\n    {\r\n      UInt32 temp = p[i];\r\n      UInt32 k = i;\r\n      HeapSortDown(p, k, size, temp)\r\n    }\r\n    while(--i != 0);\r\n  }\r\n  /*\r\n  do\r\n  {\r\n    UInt32 k = 1;\r\n    UInt32 temp = p[size];\r\n    p[size--] = p[1];\r\n    HeapSortDown(p, k, size, temp)\r\n  }\r\n  while (size > 1);\r\n  */\r\n  while (size > 3)\r\n  {\r\n    UInt32 temp = p[size];\r\n    UInt32 k = (p[3] > p[2]) ? 3 : 2;\r\n    p[size--] = p[1];\r\n    p[1] = p[k]; \r\n    HeapSortDown(p, k, size, temp)\r\n  }\r\n  {\r\n    UInt32 temp = p[size];\r\n    p[size] = p[1];\r\n    if (size > 2 && p[2] < temp)\r\n    {\r\n      p[1] = p[2];\r\n      p[2] = temp;\r\n    }\r\n    else\r\n      p[1] = temp;\r\n  }\r\n}\r\n\r\n/*\r\n#define HeapSortRefDown(p, vals, n, size, temp) \\\r\n  { UInt32 k = n; UInt32 val = vals[temp]; for (;;) { \\\r\n    UInt32 s = (k << 1); \\\r\n    if (s > size) break; \\\r\n    if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \\\r\n    if (val >= vals[p[s]]) break; \\\r\n    p[k] = p[s]; k = s; \\\r\n  } p[k] = temp; }\r\n\r\nvoid HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size)\r\n{\r\n  if (size <= 1)\r\n    return;\r\n  p--;\r\n  {\r\n    UInt32 i = size / 2;\r\n    do\r\n    {\r\n      UInt32 temp = p[i];\r\n      HeapSortRefDown(p, vals, i, size, temp);\r\n    }\r\n    while(--i != 0);\r\n  }\r\n  do\r\n  {\r\n    UInt32 temp = p[size];\r\n    p[size--] = p[1];\r\n    HeapSortRefDown(p, vals, 1, size, temp);\r\n  }\r\n  while (size > 1);\r\n}\r\n*/"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Sort.h",
    "content": "/* Sort.h */\r\n\r\n#ifndef __7Z_Sort_H\r\n#define __7Z_Sort_H\r\n\r\n#include \"Types.h\"\r\n\r\nvoid HeapSort(UInt32 *p, UInt32 size);\r\n/* void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size); */\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Threads.c",
    "content": "/* Threads.c */\r\n\r\n#include \"Threads.h\"\r\n#include <process.h>\r\n\r\nHRes GetError()\r\n{\r\n  DWORD res = GetLastError();\r\n  return (res) ? (HRes)(res) : SZE_FAIL;\r\n}\r\n\r\nHRes BoolToHRes(int v) { return v ? SZ_OK : GetError(); }\r\nHRes BOOLToHRes(BOOL v) { return v ? SZ_OK : GetError(); }\r\n\r\nHRes MyCloseHandle(HANDLE *h)\r\n{\r\n  if (*h != NULL)\r\n    if (!CloseHandle(*h))\r\n      return GetError();\r\n  *h = NULL;\r\n  return SZ_OK;\r\n}\r\n\r\nHRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n{ \r\n  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r\n  thread->handle = \r\n    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */\r\n    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);\r\n    /* maybe we must use errno here, but probably GetLastError() is also OK. */\r\n  return BoolToHRes(thread->handle != 0);\r\n}\r\n\r\nHRes WaitObject(HANDLE h)\r\n{\r\n  return (HRes)WaitForSingleObject(h, INFINITE); \r\n}\r\n\r\nHRes Thread_Wait(CThread *thread)\r\n{\r\n  if (thread->handle == NULL)\r\n    return 1;\r\n  return WaitObject(thread->handle); \r\n}\r\n\r\nHRes Thread_Close(CThread *thread)\r\n{\r\n  return MyCloseHandle(&thread->handle);\r\n}\r\n\r\nHRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)\r\n{\r\n  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);\r\n  return BoolToHRes(p->handle != 0);\r\n}\r\n\r\nHRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, TRUE, initialSignaled); }\r\nHRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) \r\n  { return ManualResetEvent_Create(p, 0); }\r\n\r\nHRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, FALSE, initialSignaled); }\r\nHRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) \r\n  { return AutoResetEvent_Create(p, 0); }\r\n\r\nHRes Event_Set(CEvent *p) { return BOOLToHRes(SetEvent(p->handle)); }\r\nHRes Event_Reset(CEvent *p) { return BOOLToHRes(ResetEvent(p->handle)); }\r\nHRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }\r\nHRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }\r\n\r\n\r\nHRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)\r\n{\r\n  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);\r\n  return BoolToHRes(p->handle != 0);\r\n}\r\n\r\nHRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) \r\n{ \r\n  return BOOLToHRes(ReleaseSemaphore(p->handle, releaseCount, previousCount)); \r\n}\r\nHRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)\r\n{\r\n  return Semaphore_Release(p, (LONG)releaseCount, NULL);\r\n}\r\nHRes Semaphore_Release1(CSemaphore *p)\r\n{\r\n  return Semaphore_ReleaseN(p, 1);\r\n}\r\n\r\nHRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }\r\nHRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }\r\n\r\nHRes CriticalSection_Init(CCriticalSection *p)\r\n{\r\n  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\r\n  __try \r\n  { \r\n    InitializeCriticalSection(p); \r\n    /* InitializeCriticalSectionAndSpinCount(p, 0); */\r\n  }  \r\n  __except (EXCEPTION_EXECUTE_HANDLER) { return SZE_OUTOFMEMORY; }\r\n  return SZ_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Threads.h",
    "content": "/* Threads.h */\r\n\r\n#ifndef __7Z_THRESDS_H\r\n#define __7Z_THRESDS_H\r\n\r\n#include <windows.h>\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _CThread\r\n{\r\n  HANDLE handle;\r\n} CThread;\r\n\r\n#define Thread_Construct(thread) (thread)->handle = NULL\r\n#define Thread_WasCreated(thread) ((thread)->handle != NULL)\r\n \r\ntypedef unsigned THREAD_FUNC_RET_TYPE;\r\n#define THREAD_FUNC_CALL_TYPE StdCall\r\n#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r\n\r\nHRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);\r\nHRes Thread_Wait(CThread *thread);\r\nHRes Thread_Close(CThread *thread);\r\n\r\ntypedef struct _CEvent\r\n{\r\n  HANDLE handle;\r\n} CEvent;\r\n\r\ntypedef CEvent CAutoResetEvent;\r\ntypedef CEvent CManualResetEvent;\r\n\r\n#define Event_Construct(event) (event)->handle = NULL\r\n#define Event_IsCreated(event) ((event)->handle != NULL)\r\n\r\nHRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);\r\nHRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);\r\nHRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);\r\nHRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);\r\nHRes Event_Set(CEvent *event);\r\nHRes Event_Reset(CEvent *event);\r\nHRes Event_Wait(CEvent *event);\r\nHRes Event_Close(CEvent *event);\r\n\r\n\r\ntypedef struct _CSemaphore\r\n{\r\n  HANDLE handle;\r\n} CSemaphore;\r\n\r\n#define Semaphore_Construct(p) (p)->handle = NULL\r\n\r\nHRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);\r\nHRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\r\nHRes Semaphore_Release1(CSemaphore *p);\r\nHRes Semaphore_Wait(CSemaphore *p);\r\nHRes Semaphore_Close(CSemaphore *p);\r\n\r\n\r\ntypedef CRITICAL_SECTION CCriticalSection;\r\n\r\nHRes CriticalSection_Init(CCriticalSection *p);\r\n#define CriticalSection_Delete(p) DeleteCriticalSection(p)\r\n#define CriticalSection_Enter(p) EnterCriticalSection(p)\r\n#define CriticalSection_Leave(p) LeaveCriticalSection(p)\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/C/Types.h",
    "content": "/* 7zTypes.h */\r\n\r\n#ifndef __C_TYPES_H\r\n#define __C_TYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef unsigned int UInt32;\r\n#endif\r\n#endif \r\n\r\n#ifndef _7ZIP_INT32_DEFINED\r\n#define _7ZIP_INT32_DEFINED\r\n#ifdef _LZMA_INT32_IS_ULONG\r\ntypedef long Int32;\r\n#else\r\ntypedef int Int32;\r\n#endif\r\n#endif \r\n\r\n/* #define _SZ_NO_INT_64 */\r\n/* define it your compiler doesn't support long long int */\r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\n#ifdef _SZ_NO_INT_64\r\ntypedef unsigned long UInt64;\r\n#else\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n#endif\r\n#endif\r\n\r\n\r\n/* #define _SZ_FILE_SIZE_32 */\r\n/* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/\r\n\r\n#ifndef CFileSize\r\n#ifdef _SZ_FILE_SIZE_32\r\ntypedef UInt32 CFileSize; \r\n#else\r\ntypedef UInt64 CFileSize; \r\n#endif\r\n#endif\r\n\r\n#define SZ_RESULT int\r\n\r\ntypedef int HRes;\r\n#define RES_OK (0)\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_CRC_ERROR (3)\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n#define SZE_OUTOFMEMORY (0x8007000EL)\r\n#define SZE_NOTIMPL (0x80004001L)\r\n#define SZE_FAIL (0x80004005L)\r\n#define SZE_INVALIDARG (0x80070057L)\r\n\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRes __result_ = (x); if(__result_ != 0) return __result_; }\r\n#endif\r\n\r\ntypedef int Bool;\r\n#define True 1\r\n#define False 0\r\n\r\n#ifdef _MSC_VER\r\n#define StdCall __stdcall \r\n#else\r\n#define StdCall\r\n#endif\r\n\r\n#if _MSC_VER >= 1300\r\n#define MY_FAST_CALL __declspec(noinline) __fastcall \r\n#elif defined( _MSC_VER)\r\n#define MY_FAST_CALL __fastcall \r\n#else\r\n#define MY_FAST_CALL\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zCompressionMode.cpp",
    "content": "// CompressionMethod.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zCompressionMode.h",
    "content": "// 7zCompressionMode.h\r\n\r\n#ifndef __7Z_COMPRESSION_MODE_H\r\n#define __7Z_COMPRESSION_MODE_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CMethodFull: public CMethod\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBind\r\n{\r\n  UInt32 InCoder;\r\n  UInt32 InStream;\r\n  UInt32 OutCoder;\r\n  UInt32 OutStream;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  CObjectVector<CMethodFull> Methods;\r\n  CRecordVector<CBind> Binds;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }\r\n  CCompressionMethodMode(): PasswordIsDefined(false)\r\n      #ifdef COMPRESS_MT\r\n      , NumThreads(1) \r\n      #endif\r\n  {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zDecode.cpp",
    "content": "// 7zDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zDecode.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/LockedStream.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertFolderItemInfoToBindInfo(const CFolder &folder,\r\n    CBindInfoEx &bindInfo)\r\n{\r\n  bindInfo.Clear();\r\n  int i;\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    NCoderMixer::CBindPair bindPair;\r\n    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;\r\n    bindInfo.BindPairs.Add(bindPair);\r\n  }\r\n  UInt32 outStreamIndex = 0;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    const CCoderInfo &coderInfo = folder.Coders[i];\r\n    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;\r\n    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    bindInfo.Coders.Add(coderStreamsInfo);\r\n    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);\r\n    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)\r\n      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)\r\n        bindInfo.OutStreams.Add(outStreamIndex);\r\n  }\r\n  for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);\r\n}\r\n\r\nstatic bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1, \r\n    const NCoderMixer::CCoderStreamsInfo &a2)\r\n{\r\n  return (a1.NumInStreams == a2.NumInStreams) &&\r\n    (a1.NumOutStreams == a2.NumOutStreams);\r\n}\r\n\r\nstatic bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)\r\n{\r\n  return (a1.InIndex == a2.InIndex) &&\r\n    (a1.OutIndex == a2.OutIndex);\r\n}\r\n\r\nstatic bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)\r\n{\r\n  if (a1.Coders.Size() != a2.Coders.Size())\r\n    return false;\r\n  int i;\r\n  for (i = 0; i < a1.Coders.Size(); i++)\r\n    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))\r\n      return false;\r\n  if (a1.BindPairs.Size() != a2.BindPairs.Size())\r\n    return false;\r\n  for (i = 0; i < a1.BindPairs.Size(); i++)\r\n    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))\r\n      return false;\r\n  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)\r\n    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])\r\n      return false;\r\n  if (a1.InStreams.Size() != a2.InStreams.Size())\r\n    return false;\r\n  if (a1.OutStreams.Size() != a2.OutStreams.Size())\r\n    return false;\r\n  return true;\r\n}\r\n\r\nCDecoder::CDecoder(bool multiThread)\r\n{\r\n  #ifndef _ST_MODE\r\n  multiThread = true;\r\n  #endif\r\n  _multiThread = multiThread;\r\n  _bindInfoExPrevIsDefined = false;\r\n}\r\n\r\nHRESULT CDecoder::Decode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    UInt64 startPos,\r\n    const UInt64 *packSizes,\r\n    const CFolder &folderInfo, \r\n    ISequentialOutStream *outStream,\r\n    ICompressProgressInfo *compressProgress\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    #ifdef COMPRESS_MT\r\n    , bool mtMode, UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;\r\n  \r\n  CLockedInStream lockedInStream;\r\n  lockedInStream.Init(inStream);\r\n  \r\n  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)\r\n  {\r\n    CLockedSequentialInStreamImp *lockedStreamImpSpec = new \r\n        CLockedSequentialInStreamImp;\r\n    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;\r\n    lockedStreamImpSpec->Init(&lockedInStream, startPos);\r\n    startPos += packSizes[j];\r\n    \r\n    CLimitedSequentialInStream *streamSpec = new \r\n        CLimitedSequentialInStream;\r\n    CMyComPtr<ISequentialInStream> inStream = streamSpec;\r\n    streamSpec->SetStream(lockedStreamImp);\r\n    streamSpec->Init(packSizes[j]);\r\n    inStreams.Add(inStream);\r\n  }\r\n  \r\n  int numCoders = folderInfo.Coders.Size();\r\n  \r\n  CBindInfoEx bindInfo;\r\n  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);\r\n  bool createNewCoders;\r\n  if (!_bindInfoExPrevIsDefined)\r\n    createNewCoders = true;\r\n  else\r\n    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);\r\n  if (createNewCoders)\r\n  {\r\n    int i;\r\n    _decoders.Clear();\r\n    // _decoders2.Clear();\r\n    \r\n    _mixerCoder.Release();\r\n\r\n    if (_multiThread)\r\n    {\r\n      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;\r\n      _mixerCoder = _mixerCoderMTSpec;\r\n      _mixerCoderCommon = _mixerCoderMTSpec;\r\n    }\r\n    else\r\n    {\r\n      #ifdef _ST_MODE\r\n      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;\r\n      _mixerCoder = _mixerCoderSTSpec;\r\n      _mixerCoderCommon = _mixerCoderSTSpec;\r\n      #endif\r\n    }\r\n    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));\r\n    \r\n    for (i = 0; i < numCoders; i++)\r\n    {\r\n      const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n\r\n  \r\n      CMyComPtr<ICompressCoder> decoder;\r\n      CMyComPtr<ICompressCoder2> decoder2;\r\n      RINOK(CreateCoder(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          coderInfo.MethodID, decoder, decoder2, false));\r\n      CMyComPtr<IUnknown> decoderUnknown;\r\n      if (coderInfo.IsSimpleCoder())\r\n      {\r\n        if (decoder == 0)\r\n          return E_NOTIMPL;\r\n\r\n        decoderUnknown = (IUnknown *)decoder;\r\n        \r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder(decoder);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder(decoder, false);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        if (decoder2 == 0)\r\n          return E_NOTIMPL;\r\n        decoderUnknown = (IUnknown *)decoder2;\r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder2(decoder2);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder2(decoder2, false);\r\n        #endif\r\n      }\r\n      _decoders.Add(decoderUnknown);\r\n      #ifdef EXTERNAL_CODECS\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n      }\r\n      #endif\r\n    }\r\n    _bindInfoExPrev = bindInfo;\r\n    _bindInfoExPrevIsDefined = true;\r\n  }\r\n  int i;\r\n  _mixerCoderCommon->ReInit();\r\n  \r\n  UInt32 packStreamIndex = 0, unPackStreamIndex = 0;\r\n  UInt32 coderIndex = 0;\r\n  // UInt32 coder2Index = 0;\r\n  \r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];\r\n    \r\n    {\r\n      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n      if (setDecoderProperties)\r\n      {\r\n        const CByteBuffer &properties = coderInfo.Properties;\r\n        size_t size = properties.GetCapacity();\r\n        if (size > 0xFFFFFFFF)\r\n          return E_NOTIMPL;\r\n        if (size > 0)\r\n        {\r\n          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)properties, (UInt32)size));\r\n        }\r\n      }\r\n    }\r\n\r\n    #ifdef COMPRESS_MT\r\n    if (mtMode)\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(numThreads));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    {\r\n      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n      if (cryptoSetPassword)\r\n      {\r\n        if (getTextPassword == 0)\r\n          return E_FAIL;\r\n        CMyComBSTR password;\r\n        RINOK(getTextPassword->CryptoGetTextPassword(&password));\r\n        CByteBuffer buffer;\r\n        UString unicodePassword(password);\r\n        const UInt32 sizeInBytes = unicodePassword.Length() * 2;\r\n        buffer.SetCapacity(sizeInBytes);\r\n        for (int i = 0; i < unicodePassword.Length(); i++)\r\n        {\r\n          wchar_t c = unicodePassword[i];\r\n          ((Byte *)buffer)[i * 2] = (Byte)c;\r\n          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n        }\r\n        RINOK(cryptoSetPassword->CryptoSetPassword(\r\n          (const Byte *)buffer, sizeInBytes));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    coderIndex++;\r\n    \r\n    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;\r\n    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    CRecordVector<const UInt64 *> packSizesPointers;\r\n    CRecordVector<const UInt64 *> unPackSizesPointers;\r\n    packSizesPointers.Reserve(numInStreams);\r\n    unPackSizesPointers.Reserve(numOutStreams);\r\n    UInt32 j;\r\n    for (j = 0; j < numOutStreams; j++, unPackStreamIndex++)\r\n      unPackSizesPointers.Add(&folderInfo.UnPackSizes[unPackStreamIndex]);\r\n    \r\n    for (j = 0; j < numInStreams; j++, packStreamIndex++)\r\n    {\r\n      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);\r\n      if (bindPairIndex >= 0)\r\n        packSizesPointers.Add(\r\n        &folderInfo.UnPackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);\r\n      else\r\n      {\r\n        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);\r\n        if (index < 0)\r\n          return E_FAIL;\r\n        packSizesPointers.Add(&packSizes[index]);\r\n      }\r\n    }\r\n    \r\n    _mixerCoderCommon->SetCoderInfo(i, \r\n        &packSizesPointers.Front(), \r\n        &unPackSizesPointers.Front());\r\n  }\r\n  UInt32 mainCoder, temp;\r\n  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);\r\n\r\n  if (_multiThread)\r\n    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);\r\n  /*\r\n  else\r\n    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;\r\n  */\r\n  \r\n  if (numCoders == 0)\r\n    return 0;\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  inStreamPointers.Reserve(inStreams.Size());\r\n  for (i = 0; i < inStreams.Size(); i++)\r\n    inStreamPointers.Add(inStreams[i]);\r\n  ISequentialOutStream *outStreamPointer = outStream;\r\n  return _mixerCoder->Code(&inStreamPointers.Front(), NULL, \r\n    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zDecode.h",
    "content": "// 7zDecode.h\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"7zItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CBindInfoEx: public NCoderMixer::CBindInfo\r\n{\r\n  CRecordVector<CMethodId> CoderMethodIDs;\r\n  void Clear()\r\n  {\r\n    CBindInfo::Clear();\r\n    CoderMethodIDs.Clear();\r\n  }\r\n};\r\n\r\nclass CDecoder\r\n{\r\n  bool _bindInfoExPrevIsDefined;\r\n  CBindInfoEx _bindInfoExPrev;\r\n  \r\n  bool _multiThread;\r\n  #ifdef _ST_MODE\r\n  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;\r\n  #endif\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;\r\n  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;\r\n  \r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n  CObjectVector<CMyComPtr<IUnknown> > _decoders;\r\n  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;\r\npublic:\r\n  CDecoder(bool multiThread);\r\n  HRESULT Decode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      IInStream *inStream,\r\n      UInt64 startPos,\r\n      const UInt64 *packSizes,\r\n      const CFolder &folder, \r\n      ISequentialOutStream *outStream,\r\n      ICompressProgressInfo *compressProgress\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPasswordSpec\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , bool mtMode, UInt32 numThreads\r\n      #endif\r\n      );\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zEncode.cpp",
    "content": "// Encode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zSpecStream.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/InOutTempBuffer.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nstatic const UInt64 k_AES = 0x06F10701;\r\nstatic const UInt64 k_BCJ  = 0x03030103;\r\nstatic const UInt64 k_BCJ2 = 0x0303011B;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,\r\n    const CRecordVector<CMethodId> decompressionMethods,\r\n    CFolder &folder)\r\n{\r\n  folder.Coders.Clear();\r\n  // bindInfo.CoderMethodIDs.Clear();\r\n  // folder.OutStreams.Clear();\r\n  folder.PackStreams.Clear();\r\n  folder.BindPairs.Clear();\r\n  int i;\r\n  for (i = 0; i < bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = bindInfo.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = bindInfo.BindPairs[i].OutIndex;\r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n  for (i = 0; i < bindInfo.Coders.Size(); i++)\r\n  {\r\n    CCoderInfo coderInfo;\r\n    const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];\r\n    coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;\r\n    coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;\r\n    coderInfo.MethodID = decompressionMethods[i];\r\n    folder.Coders.Add(coderInfo);\r\n  }\r\n  for (i = 0; i < bindInfo.InStreams.Size(); i++)\r\n    folder.PackStreams.Add(bindInfo.InStreams[i]);\r\n}\r\n\r\nHRESULT CEncoder::CreateMixerCoder(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const UInt64 *inSizeForReduce)\r\n{\r\n  _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;\r\n  _mixerCoder = _mixerCoderSpec;\r\n  RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));\r\n  for (int i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _codersInfo.Add(CCoderInfo());\r\n    CCoderInfo &encodingInfo = _codersInfo.Back();\r\n    encodingInfo.MethodID = methodFull.Id;\r\n    CMyComPtr<ICompressCoder> encoder;\r\n    CMyComPtr<ICompressCoder2> encoder2;\r\n    \r\n\r\n    RINOK(CreateCoder(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        methodFull.Id, encoder, encoder2, true));\r\n\r\n    if (!encoder && !encoder2)\r\n      return E_FAIL;\r\n\r\n    CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;\r\n   \r\n    #ifdef COMPRESS_MT\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));\r\n      }\r\n    }\r\n    #endif\r\n        \r\n\r\n    RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon));\r\n\r\n    /*\r\n    CMyComPtr<ICryptoResetSalt> resetSalt;\r\n    encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);\r\n    if (resetSalt != NULL)\r\n    {\r\n      resetSalt->ResetSalt();\r\n    }\r\n    */\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n    encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n    if (setCompressCodecsInfo)\r\n    {\r\n      RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n    }\r\n    #endif\r\n    \r\n    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n    encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n\r\n    if (cryptoSetPassword)\r\n    {\r\n      CByteBuffer buffer;\r\n      const UInt32 sizeInBytes = _options.Password.Length() * 2;\r\n      buffer.SetCapacity(sizeInBytes);\r\n      for (int i = 0; i < _options.Password.Length(); i++)\r\n      {\r\n        wchar_t c = _options.Password[i];\r\n        ((Byte *)buffer)[i * 2] = (Byte)c;\r\n        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n      }\r\n      RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n    }\r\n\r\n    if (encoder)\r\n      _mixerCoderSpec->AddCoder(encoder);\r\n    else\r\n      _mixerCoderSpec->AddCoder2(encoder2);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Encode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    ISequentialInStream *inStream,\r\n    const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n    CFolder &folderItem,\r\n    ISequentialOutStream *outStream,\r\n    CRecordVector<UInt64> &packSizes,\r\n    ICompressProgressInfo *compressProgress)\r\n{\r\n  RINOK(EncoderConstr());\r\n\r\n  if (_mixerCoderSpec == NULL)\r\n  {\r\n    RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));\r\n  }\r\n  _mixerCoderSpec->ReInit();\r\n  // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);\r\n\r\n  CObjectVector<CInOutTempBuffer> inOutTempBuffers;\r\n  CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;\r\n  CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;\r\n  int numMethods = _bindInfo.Coders.Size();\r\n  int i;\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    inOutTempBuffers.Add(CInOutTempBuffer());\r\n    inOutTempBuffers.Back().Create();\r\n    inOutTempBuffers.Back().InitWriting();\r\n  }\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CSequentialOutTempBufferImp *tempBufferSpec = \r\n        new CSequentialOutTempBufferImp;\r\n    CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;\r\n    tempBufferSpec->Init(&inOutTempBuffers[i - 1]);\r\n    tempBuffers.Add(tempBuffer);\r\n    tempBufferSpecs.Add(tempBufferSpec);\r\n  }\r\n\r\n  for (i = 0; i < numMethods; i++)\r\n    _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    return E_FAIL;\r\n  UInt32 mainCoderIndex, mainStreamIndex;\r\n  _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);\r\n  \r\n  if (inStreamSize != NULL)\r\n  {\r\n    CRecordVector<const UInt64 *> sizePointers;\r\n    for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)\r\n      if (i == mainStreamIndex)\r\n        sizePointers.Add(inStreamSize);\r\n      else\r\n        sizePointers.Add(NULL);\r\n    _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);\r\n  }\r\n\r\n  \r\n  // UInt64 outStreamStartPos;\r\n  // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));\r\n  \r\n  CSequentialInStreamSizeCount2 *inStreamSizeCountSpec = \r\n      new CSequentialInStreamSizeCount2;\r\n  CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;\r\n  CSequentialOutStreamSizeCount *outStreamSizeCountSpec = \r\n      new CSequentialOutStreamSizeCount;\r\n  CMyComPtr<ISequentialOutStream> outStreamSizeCount = outStreamSizeCountSpec;\r\n\r\n  inStreamSizeCountSpec->Init(inStream);\r\n  outStreamSizeCountSpec->SetStream(outStream);\r\n  outStreamSizeCountSpec->Init();\r\n\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  CRecordVector<ISequentialOutStream *> outStreamPointers;\r\n  inStreamPointers.Add(inStreamSizeCount);\r\n  outStreamPointers.Add(outStreamSizeCount);\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n    outStreamPointers.Add(tempBuffers[i - 1]);\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    CCoderInfo &encodingInfo = _codersInfo[i];\r\n    \r\n    CMyComPtr<ICryptoResetInitVector> resetInitVector;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);\r\n    if (resetInitVector != NULL)\r\n    {\r\n      resetInitVector->ResetInitVector();\r\n    }\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n    if (writeCoderProperties != NULL)\r\n    {\r\n      CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n      outStreamSpec->Init();\r\n      writeCoderProperties->WriteCoderProperties(outStream);\r\n      size_t size = outStreamSpec->GetSize();\r\n      encodingInfo.Properties.SetCapacity(size);\r\n      memmove(encodingInfo.Properties, outStreamSpec->GetBuffer(), size);\r\n    }\r\n  }\r\n\r\n  UInt32 progressIndex = mainCoderIndex;\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    const CCoderInfo &e = _codersInfo[i];\r\n    if ((e.MethodID == k_BCJ || e.MethodID == k_BCJ2) && i + 1 < _codersInfo.Size())\r\n      progressIndex = i + 1;\r\n  }\r\n\r\n  _mixerCoderSpec->SetProgressCoderIndex(progressIndex);\r\n  \r\n  RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,\r\n    &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));\r\n  \r\n  ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods,\r\n      folderItem);\r\n  \r\n  packSizes.Add(outStreamSizeCountSpec->GetSize());\r\n  \r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];\r\n    inOutTempBuffer.FlushWrite();\r\n    inOutTempBuffer.InitReading();\r\n    inOutTempBuffer.WriteToStream(outStream);\r\n    packSizes.Add(inOutTempBuffer.GetDataSize());\r\n  }\r\n  \r\n  for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)\r\n  {\r\n    int binder = _bindInfo.FindBinderForInStream(\r\n        _bindReverseConverter->DestOutToSrcInMap[i]);\r\n    UInt64 streamSize;\r\n    if (binder < 0)\r\n      streamSize = inStreamSizeCountSpec->GetSize();\r\n    else\r\n      streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);\r\n    folderItem.UnPackSizes.Add(streamSize);\r\n  }\r\n  for (i = numMethods - 1; i >= 0; i--)\r\n    folderItem.Coders[numMethods - 1 - i].Properties = _codersInfo[i].Properties;\r\n  return S_OK;\r\n}\r\n\r\n\r\nCEncoder::CEncoder(const CCompressionMethodMode &options):\r\n  _bindReverseConverter(0),\r\n  _constructed(false)\r\n{\r\n  if (options.IsEmpty())\r\n    throw 1;\r\n\r\n  _options = options;\r\n  _mixerCoderSpec = NULL;\r\n}\r\n\r\nHRESULT CEncoder::EncoderConstr()\r\n{\r\n  if (_constructed)\r\n    return S_OK;\r\n  if (_options.Methods.IsEmpty())\r\n  {\r\n    // it has only password method;\r\n    if (!_options.PasswordIsDefined)\r\n      throw 1;\r\n    if (!_options.Binds.IsEmpty())\r\n      throw 1;\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    CMethodFull method;\r\n    \r\n    method.NumInStreams = 1;\r\n    method.NumOutStreams = 1;\r\n    coderStreamsInfo.NumInStreams = 1;\r\n    coderStreamsInfo.NumOutStreams = 1;\r\n    method.Id = k_AES;\r\n    \r\n    _options.Methods.Add(method);\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  \r\n    _bindInfo.InStreams.Add(0);\r\n    _bindInfo.OutStreams.Add(0);\r\n  }\r\n  else\r\n  {\r\n\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  int i;\r\n  for (i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;\r\n    coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;\r\n    if (_options.Binds.IsEmpty())\r\n    {\r\n      if (i < _options.Methods.Size() - 1)\r\n      {\r\n        NCoderMixer::CBindPair bindPair;\r\n        bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;\r\n        bindPair.OutIndex = numOutStreams;\r\n        _bindInfo.BindPairs.Add(bindPair);\r\n      }\r\n      else\r\n        _bindInfo.OutStreams.Insert(0, numOutStreams);\r\n      for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)\r\n        _bindInfo.OutStreams.Add(numOutStreams + j);\r\n    }\r\n    \r\n    numInStreams += coderStreamsInfo.NumInStreams;\r\n    numOutStreams += coderStreamsInfo.NumOutStreams;\r\n\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  }\r\n\r\n  if (!_options.Binds.IsEmpty())\r\n  {\r\n    for (i = 0; i < _options.Binds.Size(); i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      const CBind &bind = _options.Binds[i];\r\n      bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;\r\n      bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    for (i = 0; i < (int)numOutStreams; i++)\r\n      if (_bindInfo.FindBinderForOutStream(i) == -1)\r\n        _bindInfo.OutStreams.Add(i);\r\n  }\r\n\r\n  for (i = 0; i < (int)numInStreams; i++)\r\n    if (_bindInfo.FindBinderForInStream(i) == -1)\r\n      _bindInfo.InStreams.Add(i);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    throw 1; // this is error\r\n\r\n  // Make main stream first in list\r\n  int inIndex = _bindInfo.InStreams[0];\r\n  for (;;)\r\n  {\r\n    UInt32 coderIndex, coderStreamIndex;\r\n    _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);\r\n    UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);\r\n    int binder = _bindInfo.FindBinderForOutStream(outIndex);\r\n    if (binder >= 0)\r\n    {\r\n      inIndex = _bindInfo.BindPairs[binder].InIndex;\r\n      continue;\r\n    }\r\n    for (i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n      if (_bindInfo.OutStreams[i] == outIndex)\r\n      {\r\n        _bindInfo.OutStreams.Delete(i);\r\n        _bindInfo.OutStreams.Insert(0, outIndex);\r\n        break;\r\n      }\r\n    break;\r\n  }\r\n\r\n  if (_options.PasswordIsDefined)\r\n  {\r\n    int numCryptoStreams = _bindInfo.OutStreams.Size();\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      bindPair.InIndex = numInStreams + i;\r\n      bindPair.OutIndex = _bindInfo.OutStreams[i];\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    _bindInfo.OutStreams.Clear();\r\n\r\n    /*\r\n    if (numCryptoStreams == 0)\r\n      numCryptoStreams = 1;\r\n    */\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n      CMethodFull method;\r\n      method.NumInStreams = 1;\r\n      method.NumOutStreams = 1;\r\n      coderStreamsInfo.NumInStreams = method.NumOutStreams;\r\n      coderStreamsInfo.NumOutStreams = method.NumInStreams;\r\n      method.Id = k_AES;\r\n\r\n      _options.Methods.Add(method);\r\n      _bindInfo.Coders.Add(coderStreamsInfo);\r\n      _bindInfo.OutStreams.Add(numOutStreams + i);\r\n    }\r\n  }\r\n\r\n  }\r\n\r\n  for (int i = _options.Methods.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _decompressionMethods.Add(methodFull.Id);\r\n  }\r\n\r\n  _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);\r\n  _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);\r\n  _constructed = true;\r\n  return S_OK;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  delete _bindReverseConverter;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zEncode.h",
    "content": "// 7zEncode.h\r\n\r\n#ifndef __7Z_ENCODE_H\r\n#define __7Z_ENCODE_H\r\n\r\n// #include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n#include \"7zItem.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CEncoder\r\n{\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;\r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n\r\n  CObjectVector<CCoderInfo> _codersInfo;\r\n\r\n  CCompressionMethodMode _options;\r\n  NCoderMixer::CBindInfo _bindInfo;\r\n  NCoderMixer::CBindInfo _decompressBindInfo;\r\n  NCoderMixer::CBindReverseConverter *_bindReverseConverter;\r\n  CRecordVector<CMethodId> _decompressionMethods;\r\n\r\n  HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const UInt64 *inSizeForReduce);\r\n\r\n  bool _constructed;\r\npublic:\r\n  CEncoder(const CCompressionMethodMode &options);\r\n  ~CEncoder();\r\n  HRESULT EncoderConstr();\r\n  HRESULT Encode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      ISequentialInStream *inStream,\r\n      const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n      CFolder &folderItem,\r\n      ISequentialOutStream *outStream,\r\n      CRecordVector<UInt64> &packSizes,\r\n      ICompressProgressInfo *compressProgress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zExtract.cpp",
    "content": "// 7zExtract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zFolderOutStream.h\"\r\n#include \"7zDecode.h\"\r\n// #include \"7z1Decode.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CExtractFolderInfo\r\n{\r\n  #ifdef _7Z_VOL\r\n  int VolumeIndex;\r\n  #endif\r\n  CNum FileIndex;\r\n  CNum FolderIndex;\r\n  CBoolVector ExtractStatuses;\r\n  UInt64 UnPackSize;\r\n  CExtractFolderInfo(\r\n    #ifdef _7Z_VOL\r\n    int volumeIndex, \r\n    #endif\r\n    CNum fileIndex, CNum folderIndex): \r\n    #ifdef _7Z_VOL\r\n    VolumeIndex(volumeIndex),\r\n    #endif\r\n    FileIndex(fileIndex),\r\n    FolderIndex(folderIndex), \r\n    UnPackSize(0) \r\n  {\r\n    if (fileIndex != kNumNoIndex)\r\n    {\r\n      ExtractStatuses.Reserve(1);\r\n      ExtractStatuses.Add(true);\r\n    }\r\n  };\r\n};\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool testMode = (testModeSpec != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;\r\n  UInt64 importantTotalUnPacked = 0;\r\n\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (allFilesMode)\r\n    numItems = \r\n    #ifdef _7Z_VOL\r\n    _refs.Size();\r\n    #else\r\n    _database.Files.Size();\r\n    #endif\r\n\r\n  if(numItems == 0)\r\n    return S_OK;\r\n\r\n  /*\r\n  if(_volumes.Size() != 1)\r\n    return E_FAIL;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_database = volume.Database;\r\n  IInStream *_inStream = volume.Stream;\r\n  */\r\n  \r\n  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;\r\n  for(UInt32 ii = 0; ii < numItems; ii++)\r\n  {\r\n    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];\r\n    UInt32 ref2Index = allFilesMode ? ii : indices[ii];\r\n    // const CRef2 &ref2 = _refs[ref2Index];\r\n\r\n    // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)\r\n    {\r\n      #ifdef _7Z_VOL\r\n      // const CRef &ref = ref2.Refs[ri];\r\n      const CRef &ref = _refs[ref2Index];\r\n\r\n      int volumeIndex = ref.VolumeIndex;\r\n      const CVolume &volume = _volumes[volumeIndex];\r\n      const CArchiveDatabaseEx &database = volume.Database;\r\n      UInt32 fileIndex = ref.ItemIndex;\r\n      #else\r\n      const CArchiveDatabaseEx &database = _database;\r\n      UInt32 fileIndex = ref2Index;\r\n      #endif\r\n\r\n      CNum folderIndex = database.FileIndexToFolderIndexMap[fileIndex];\r\n      if (folderIndex == kNumNoIndex)\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex, \r\n            #endif\r\n            fileIndex, kNumNoIndex));\r\n        continue;\r\n      }\r\n      if (extractFolderInfoVector.IsEmpty() || \r\n        folderIndex != extractFolderInfoVector.Back().FolderIndex \r\n        #ifdef _7Z_VOL\r\n        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex\r\n        #endif\r\n        )\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex, \r\n            #endif\r\n            kNumNoIndex, folderIndex));\r\n        const CFolder &folderInfo = database.Folders[folderIndex];\r\n        UInt64 unPackSize = folderInfo.GetUnPackSize();\r\n        importantTotalUnPacked += unPackSize;\r\n        extractFolderInfoVector.Back().UnPackSize = unPackSize;\r\n      }\r\n      \r\n      CExtractFolderInfo &efi = extractFolderInfoVector.Back();\r\n      \r\n      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];\r\n      CNum startIndex = database.FolderStartFileIndex[folderIndex];\r\n      for (CNum index = efi.ExtractStatuses.Size();\r\n          index <= fileIndex - startIndex; index++)\r\n      {\r\n        // UInt64 unPackSize = _database.Files[startIndex + index].UnPackSize;\r\n        // Count partial_folder_size\r\n        // efi.UnPackSize += unPackSize;\r\n        // importantTotalUnPacked += unPackSize;\r\n        efi.ExtractStatuses.Add(index == fileIndex - startIndex);\r\n      }\r\n    }\r\n  }\r\n\r\n  extractCallback->SetTotal(importantTotalUnPacked);\r\n\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  // CDecoder1 decoder;\r\n\r\n  UInt64 currentTotalPacked = 0;\r\n  UInt64 currentTotalUnPacked = 0;\r\n  UInt64 totalFolderUnPacked;\r\n  UInt64 totalFolderPacked;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for(int i = 0; i < extractFolderInfoVector.Size(); i++, \r\n      currentTotalUnPacked += totalFolderUnPacked,\r\n      currentTotalPacked += totalFolderPacked)\r\n  {\r\n    lps->OutSize = currentTotalUnPacked;\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    const CExtractFolderInfo &efi = extractFolderInfoVector[i];\r\n    totalFolderUnPacked = efi.UnPackSize;\r\n\r\n    totalFolderPacked = 0;\r\n\r\n    CFolderOutStream *folderOutStream = new CFolderOutStream;\r\n    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);\r\n\r\n    #ifdef _7Z_VOL\r\n    const CVolume &volume = _volumes[efi.VolumeIndex];\r\n    const CArchiveDatabaseEx &database = volume.Database;\r\n    #else\r\n    const CArchiveDatabaseEx &database = _database;\r\n    #endif\r\n\r\n    CNum startIndex;\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      startIndex = efi.FileIndex;\r\n    else\r\n      startIndex = database.FolderStartFileIndex[efi.FolderIndex];\r\n\r\n\r\n    HRESULT result = folderOutStream->Init(&database, \r\n        #ifdef _7Z_VOL\r\n        volume.StartRef2Index, \r\n        #else\r\n        0,\r\n        #endif\r\n        startIndex, \r\n        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);\r\n\r\n    RINOK(result);\r\n\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      continue;\r\n\r\n    CNum folderIndex = efi.FolderIndex;\r\n    const CFolder &folderInfo = database.Folders[folderIndex];\r\n\r\n    totalFolderPacked = _database.GetFolderFullPackSize(folderIndex);\r\n\r\n    CNum packStreamIndex = database.FolderStartPackStreamIndex[folderIndex];\r\n    UInt64 folderStartPackPos = database.GetFolderStreamPos(folderIndex, 0);\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (extractCallback)\r\n      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    #endif\r\n\r\n    try\r\n    {\r\n      HRESULT result = decoder.Decode(\r\n          EXTERNAL_CODECS_VARS\r\n          #ifdef _7Z_VOL\r\n          volume.Stream,\r\n          #else\r\n          _inStream,\r\n          #endif\r\n          folderStartPackPos, \r\n          &database.PackSizes[packStreamIndex],\r\n          folderInfo,\r\n          outStream,\r\n          progress\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword\r\n          #endif\r\n          #ifdef COMPRESS_MT\r\n          , true, _numThreads\r\n          #endif\r\n          );\r\n\r\n      if (result == S_FALSE)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));\r\n        continue;\r\n      }\r\n      if (result != S_OK)\r\n        return result;\r\n      if (folderOutStream->WasWritingFinished() != S_OK)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n      continue;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zFolderInStream.cpp",
    "content": "// 7zFolderInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderInStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderInStream::CFolderInStream()\r\n{\r\n  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;\r\n  _inStreamWithHash = _inStreamWithHashSpec;\r\n}\r\n\r\nvoid CFolderInStream::Init(IArchiveUpdateCallback *updateCallback, \r\n    const UInt32 *fileIndices, UInt32 numFiles)\r\n{\r\n  _updateCallback = updateCallback;\r\n  _numFiles = numFiles;\r\n  _fileIndex = 0;\r\n  _fileIndices = fileIndices;\r\n  Processed.Clear();\r\n  CRCs.Clear();\r\n  Sizes.Clear();\r\n  _fileIsOpen = false;\r\n  _currentSizeIsDefined = false;\r\n}\r\n\r\nHRESULT CFolderInStream::OpenStream()\r\n{\r\n  _filePos = 0;\r\n  while (_fileIndex < _numFiles)\r\n  {\r\n    _currentSizeIsDefined = false;\r\n    CMyComPtr<ISequentialInStream> stream;\r\n    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);\r\n    if (result != S_OK && result != S_FALSE)\r\n      return result;\r\n    _fileIndex++;\r\n    _inStreamWithHashSpec->SetStream(stream);\r\n    _inStreamWithHashSpec->Init();\r\n    if (!stream)\r\n    {\r\n      RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n      Sizes.Add(0);\r\n      Processed.Add(result == S_OK);\r\n      AddDigest();\r\n      continue;\r\n    }\r\n    CMyComPtr<IStreamGetSize> streamGetSize;\r\n    if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)\r\n    {\r\n      if(streamGetSize)\r\n      {\r\n        _currentSizeIsDefined = true;\r\n        RINOK(streamGetSize->GetSize(&_currentSize));\r\n      }\r\n    }\r\n\r\n    _fileIsOpen = true;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFolderInStream::AddDigest()\r\n{\r\n  CRCs.Add(_inStreamWithHashSpec->GetCRC());\r\n}\r\n\r\nHRESULT CFolderInStream::CloseStream()\r\n{\r\n  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n  _inStreamWithHashSpec->ReleaseStream();\r\n  _fileIsOpen = false;\r\n  Processed.Add(true);\r\n  Sizes.Add(_filePos);\r\n  AddDigest();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 localProcessedSize;\r\n      RINOK(_inStreamWithHash->Read(\r\n          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));\r\n      if (localProcessedSize == 0)\r\n      {\r\n        RINOK(CloseStream());\r\n        continue;\r\n      }\r\n      realProcessedSize += localProcessedSize;\r\n      _filePos += localProcessedSize;\r\n      size -= localProcessedSize;\r\n      break;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenStream());\r\n    }\r\n  }\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)\r\n{\r\n  *value = 0;\r\n  int subStreamIndex = (int)subStream;\r\n  if (subStreamIndex < 0 || subStream > Sizes.Size())\r\n    return E_FAIL;\r\n  if (subStreamIndex < Sizes.Size())\r\n  {\r\n    *value= Sizes[subStreamIndex];\r\n    return S_OK;\r\n  }\r\n  if (!_currentSizeIsDefined)\r\n    return S_FALSE;\r\n  *value = _currentSize;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zFolderInStream.h",
    "content": "// 7z/FolderInStream.h\r\n\r\n#ifndef __7Z_FOLDERINSTREAM_H\r\n#define __7Z_FOLDERINSTREAM_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zHeader.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../Common/InStreamWithCRC.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderInStream: \r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  CFolderInStream();\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\nprivate:\r\n  CSequentialInStreamWithCRC *_inStreamWithHashSpec;\r\n  CMyComPtr<ISequentialInStream> _inStreamWithHash;\r\n  CMyComPtr<IArchiveUpdateCallback> _updateCallback;\r\n\r\n  bool _currentSizeIsDefined;\r\n  UInt64 _currentSize;\r\n\r\n  bool _fileIsOpen;\r\n  UInt64 _filePos;\r\n\r\n  const UInt32 *_fileIndices;\r\n  UInt32 _numFiles;\r\n  UInt32 _fileIndex;\r\n\r\n  HRESULT OpenStream();\r\n  HRESULT CloseStream();\r\n  void AddDigest();\r\npublic:\r\n  void Init(IArchiveUpdateCallback *updateCallback, \r\n      const UInt32 *fileIndices, UInt32 numFiles);\r\n  CRecordVector<bool> Processed;\r\n  CRecordVector<UInt32> CRCs;\r\n  CRecordVector<UInt64> Sizes;\r\n  UInt64 GetFullSize() const\r\n  {\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < Sizes.Size(); i++)      \r\n      size += Sizes[i];\r\n    return size;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zFolderOutStream.cpp",
    "content": "// 7zFolderOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderOutStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderOutStream::CFolderOutStream()\r\n{\r\n  _outStreamWithHashSpec = new COutStreamWithCRC;\r\n  _outStreamWithHash = _outStreamWithHashSpec;\r\n}\r\n\r\nHRESULT CFolderOutStream::Init(\r\n    const CArchiveDatabaseEx *archiveDatabase,\r\n    UInt32 ref2Offset,\r\n    UInt32 startIndex,\r\n    const CBoolVector *extractStatuses, \r\n    IArchiveExtractCallback *extractCallback,\r\n    bool testMode,\r\n    bool checkCrc)\r\n{\r\n  _archiveDatabase = archiveDatabase;\r\n  _ref2Offset = ref2Offset;\r\n  _startIndex = startIndex;\r\n\r\n  _extractStatuses = extractStatuses;\r\n  _extractCallback = extractCallback;\r\n  _testMode = testMode;\r\n\r\n  _checkCrc = checkCrc;\r\n\r\n  _currentIndex = 0;\r\n  _fileIsOpen = false;\r\n  return WriteEmptyFiles();\r\n}\r\n\r\nHRESULT CFolderOutStream::OpenFile()\r\n{\r\n  Int32 askMode;\r\n  if((*_extractStatuses)[_currentIndex])\r\n    askMode = _testMode ? \r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n  else\r\n    askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n\r\n  UInt32 index = _startIndex + _currentIndex;\r\n  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));\r\n\r\n  _outStreamWithHashSpec->SetStream(realOutStream);\r\n  _outStreamWithHashSpec->Init(_checkCrc);\r\n  if (askMode == NArchive::NExtract::NAskMode::kExtract &&\r\n      (!realOutStream)) \r\n  {\r\n    const CFileItem &fileInfo = _archiveDatabase->Files[index];\r\n    if (!fileInfo.IsAnti && !fileInfo.IsDirectory)\r\n      askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  }\r\n  return _extractCallback->PrepareOperation(askMode);\r\n}\r\n\r\nHRESULT CFolderOutStream::WriteEmptyFiles()\r\n{\r\n  for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)\r\n  {\r\n    UInt32 index = _startIndex + _currentIndex;\r\n    const CFileItem &fileInfo = _archiveDatabase->Files[index];\r\n    if (!fileInfo.IsAnti && !fileInfo.IsDirectory && fileInfo.UnPackSize != 0)\r\n      return S_OK;\r\n    RINOK(OpenFile());\r\n    RINOK(_extractCallback->SetOperationResult(\r\n        NArchive::NExtract::NOperationResult::kOK));\r\n    _outStreamWithHashSpec->ReleaseStream();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderOutStream::Write(const void *data, \r\n    UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 index = _startIndex + _currentIndex;\r\n      const CFileItem &fileInfo = _archiveDatabase->Files[index];\r\n      UInt64 fileSize = fileInfo.UnPackSize;\r\n      \r\n      UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos, \r\n          UInt64(size - realProcessedSize));\r\n      \r\n      UInt32 processedSizeLocal;\r\n      RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize, \r\n            numBytesToWrite, &processedSizeLocal));\r\n\r\n      _filePos += processedSizeLocal;\r\n      realProcessedSize += processedSizeLocal;\r\n      if (_filePos == fileSize)\r\n      {\r\n        bool digestsAreEqual;\r\n        if (fileInfo.IsFileCRCDefined && _checkCrc)\r\n          digestsAreEqual = fileInfo.FileCRC == _outStreamWithHashSpec->GetCRC();\r\n        else\r\n          digestsAreEqual = true;\r\n\r\n        RINOK(_extractCallback->SetOperationResult(\r\n            digestsAreEqual ? \r\n            NArchive::NExtract::NOperationResult::kOK :\r\n            NArchive::NExtract::NOperationResult::kCRCError));\r\n        _outStreamWithHashSpec->ReleaseStream();\r\n        _fileIsOpen = false;\r\n        _currentIndex++;\r\n      }\r\n      if (realProcessedSize == size)\r\n      {\r\n        if (processedSize != NULL)\r\n          *processedSize = realProcessedSize;\r\n        return WriteEmptyFiles();\r\n      }\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n      _filePos = 0;\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)\r\n{\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      RINOK(_extractCallback->SetOperationResult(resultEOperationResult));\r\n      _outStreamWithHashSpec->ReleaseStream();\r\n      _fileIsOpen = false;\r\n      _currentIndex++;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::WasWritingFinished()\r\n{\r\n  if (_currentIndex == _extractStatuses->Size())\r\n    return S_OK;\r\n  return E_FAIL;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zFolderOutStream.h",
    "content": "// 7zFolderOutStream.h\r\n\r\n#ifndef __7Z_FOLDEROUTSTREAM_H\r\n#define __7Z_FOLDEROUTSTREAM_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../IArchive.h\"\r\n#include \"../Common/OutStreamWithCRC.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  \r\n  CFolderOutStream();\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n\r\n  COutStreamWithCRC *_outStreamWithHashSpec;\r\n  CMyComPtr<ISequentialOutStream> _outStreamWithHash;\r\n  const CArchiveDatabaseEx *_archiveDatabase;\r\n  const CBoolVector *_extractStatuses;\r\n  UInt32 _startIndex;\r\n  UInt32 _ref2Offset;\r\n  int _currentIndex;\r\n  // UInt64 _currentDataPos;\r\n  CMyComPtr<IArchiveExtractCallback> _extractCallback;\r\n  bool _testMode;\r\n\r\n  bool _fileIsOpen;\r\n\r\n  bool _checkCrc;\r\n  UInt64 _filePos;\r\n\r\n  HRESULT OpenFile();\r\n  HRESULT WriteEmptyFiles();\r\npublic:\r\n  HRESULT Init(\r\n      const CArchiveDatabaseEx *archiveDatabase,\r\n      UInt32 ref2Offset,\r\n      UInt32 startIndex,\r\n      const CBoolVector *extractStatuses, \r\n      IArchiveExtractCallback *extractCallback,\r\n      bool testMode,\r\n      bool checkCrc);\r\n  HRESULT FlushCorrupted(Int32 resultEOperationResult);\r\n  HRESULT WasWritingFinished();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zHandler.cpp",
    "content": "// 7zHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zProperties.h\"\r\n\r\n#include \"../../../Common/IntToString.h\"\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Windows/Defs.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#ifdef _7Z_VOL\r\n#include \"../Common/MultiStream.h\"\r\n#endif\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n#include \"../Common/ParseProperties.h\"\r\n#endif\r\n#endif\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nextern UString ConvertMethodIdToString(UInt64 id);\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCHandler::CHandler()\r\n{\r\n  _crcSize = 4;\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  #else\r\n  Init();\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = \r\n  #ifdef _7Z_VOL\r\n  _refs.Size();\r\n  #else\r\n  *numItems = _database.Files.Size();\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _SFX\r\n\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,     \r\n      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\n\r\n#else\r\n\r\nSTATPROPSTG kArcProps[] = \r\n{\r\n  { NULL, kpidMethod, VT_BSTR},\r\n  { NULL, kpidSolid, VT_BOOL},\r\n  { NULL, kpidNumBlocks, VT_UI4}\r\n};\r\n\r\nSTDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidMethod:\r\n    {\r\n      UString resString;\r\n      CRecordVector<UInt64> ids;\r\n      int i;\r\n      for (i = 0; i < _database.Folders.Size(); i++)\r\n      {\r\n        const CFolder &f = _database.Folders[i];\r\n        for (int j = f.Coders.Size() - 1; j >= 0; j--)\r\n          ids.AddToUniqueSorted(f.Coders[j].MethodID);\r\n      }\r\n\r\n      for (i = 0; i < ids.Size(); i++)\r\n      {\r\n        UInt64 id = ids[i];\r\n        UString methodName;\r\n        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);\r\n        if (methodName.IsEmpty())\r\n          methodName = ConvertMethodIdToString(id);\r\n        if (!resString.IsEmpty())\r\n          resString += L' ';\r\n        resString += methodName;\r\n      }\r\n      prop = resString; \r\n      break;\r\n    }\r\n    case kpidSolid: prop = _database.IsSolid(); break;\r\n    case kpidNumBlocks: prop = (UInt32)_database.Folders.Size(); break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nIMP_IInArchive_ArcProps\r\n\r\n#endif\r\n\r\nstatic void MySetFileTime(bool timeDefined, FILETIME unixTime, NWindows::NCOM::CPropVariant &prop)\r\n{\r\n  if (timeDefined)\r\n    prop = unixTime;\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString GetStringForSizeValue(UInt32 value)\r\n{\r\n  for (int i = 31; i >= 0; i--)\r\n    if ((UInt32(1) << i) == value)\r\n      return ConvertUInt32ToString(i);\r\n  UString result;\r\n  if (value % (1 << 20) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 20);\r\n    result += L\"m\";\r\n  }\r\n  else if (value % (1 << 10) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 10);\r\n    result += L\"k\";\r\n  }\r\n  else\r\n  {\r\n    result += ConvertUInt32ToString(value);\r\n    result += L\"b\";\r\n  }\r\n  return result;\r\n}\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_PPMD  = 0x030401;\r\n\r\nstatic wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));\r\n}\r\nstatic inline UString GetHex2(Byte value)\r\n{\r\n  UString result;\r\n  result += GetHex((Byte)(value >> 4));\r\n  result += GetHex((Byte)(value & 0xF));\r\n  return result;\r\n}\r\n\r\n#endif\r\n\r\nstatic const UInt64 k_AES  = 0x06F10701;\r\n\r\n#ifndef _SFX\r\nstatic inline UInt32 GetUInt32FromMemLE(const Byte *p)\r\n{\r\n  return p[0] | (((UInt32)p[1]) << 8) | (((UInt32)p[2]) << 16) | (((UInt32)p[3]) << 24);\r\n}\r\n#endif\r\n\r\nbool CHandler::IsEncrypted(UInt32 index2) const\r\n{\r\n  CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n  if (folderIndex != kNumNoIndex)\r\n  {\r\n    const CFolder &folderInfo = _database.Folders[folderIndex];\r\n    for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n      if (folderInfo.Coders[i].MethodID == k_AES)\r\n        return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  /*\r\n  const CRef2 &ref2 = _refs[index];\r\n  if (ref2.Refs.IsEmpty())\r\n    return E_FAIL;\r\n  const CRef &ref = ref2.Refs.Front();\r\n  */\r\n  \r\n  #ifdef _7Z_VOL\r\n  const CRef &ref = _refs[index];\r\n  const CVolume &volume = _volumes[ref.VolumeIndex];\r\n  const CArchiveDatabaseEx &_database = volume.Database;\r\n  UInt32 index2 = ref.ItemIndex;\r\n  const CFileItem &item = _database.Files[index2];\r\n  #else\r\n  const CFileItem &item = _database.Files[index];\r\n  UInt32 index2 = index;\r\n  #endif\r\n\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n    {\r\n      if (!item.Name.IsEmpty())\r\n        prop = NItemName::GetOSName(item.Name);\r\n      break;\r\n    }\r\n    case kpidIsFolder:\r\n      prop = item.IsDirectory;\r\n      break;\r\n    case kpidSize:\r\n    {\r\n      prop = item.UnPackSize;\r\n      // prop = ref2.UnPackSize;\r\n      break;\r\n    }\r\n    case kpidPosition:\r\n    {\r\n      /*\r\n      if (ref2.Refs.Size() > 1)\r\n        prop = ref2.StartPos;\r\n      else\r\n      */\r\n        if (item.IsStartPosDefined)\r\n          prop = item.StartPos;\r\n      break;\r\n    }\r\n    case kpidPackedSize:\r\n    {\r\n      // prop = ref2.PackSize;\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          if (_database.FolderStartFileIndex[folderIndex] == (CNum)index2)\r\n            prop = _database.GetFolderFullPackSize(folderIndex);\r\n          /*\r\n          else\r\n            prop = (UInt64)0;\r\n          */\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    }\r\n    case kpidLastAccessTime:\r\n      MySetFileTime(item.IsLastAccessTimeDefined, item.LastAccessTime, prop);\r\n      break;\r\n    case kpidCreationTime:\r\n      MySetFileTime(item.IsCreationTimeDefined, item.CreationTime, prop);\r\n      break;\r\n    case kpidLastWriteTime:\r\n      MySetFileTime(item.IsLastWriteTimeDefined, item.LastWriteTime, prop);\r\n      break;\r\n    case kpidAttributes:\r\n      if (item.AreAttributesDefined)\r\n        prop = item.Attributes;\r\n      break;\r\n    case kpidCRC:\r\n      if (item.IsFileCRCDefined)\r\n        prop = item.FileCRC;\r\n      break;\r\n    case kpidEncrypted:\r\n    {\r\n      prop = IsEncrypted(index2);\r\n      break;\r\n    }\r\n    #ifndef _SFX\r\n    case kpidMethod:\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _database.Folders[folderIndex];\r\n          UString methodsString;\r\n          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n          {\r\n            const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n            if (!methodsString.IsEmpty())\r\n              methodsString += L' ';\r\n\r\n            {\r\n              UString methodName;\r\n              bool methodIsKnown = FindMethod(\r\n                  EXTERNAL_CODECS_VARS \r\n                  coderInfo.MethodID, methodName);\r\n\r\n              if (methodIsKnown)\r\n              {\r\n                methodsString += methodName;\r\n                if (coderInfo.MethodID == k_LZMA)\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() >= 5)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    UInt32 dicSize = GetUInt32FromMemLE(\r\n                      ((const Byte *)coderInfo.Properties + 1));\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_PPMD)\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() >= 5)\r\n                  {\r\n                    Byte order = *(const Byte *)coderInfo.Properties;\r\n                    methodsString += L\":o\";\r\n                    methodsString += ConvertUInt32ToString(order);\r\n                    methodsString += L\":mem\";\r\n                    UInt32 dicSize = GetUInt32FromMemLE(\r\n                      ((const Byte *)coderInfo.Properties + 1));\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_AES)\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() >= 1)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    const Byte *data = (const Byte *)coderInfo.Properties;\r\n                    Byte firstByte = *data++;\r\n                    UInt32 numCyclesPower = firstByte & 0x3F;\r\n                    methodsString += ConvertUInt32ToString(numCyclesPower);\r\n                    /*\r\n                    if ((firstByte & 0xC0) != 0)\r\n                    {\r\n                      methodsString += L\":\";\r\n                      return S_OK;\r\n                      UInt32 saltSize = (firstByte >> 7) & 1;\r\n                      UInt32 ivSize = (firstByte >> 6) & 1;\r\n                      if (coderInfo.Properties.GetCapacity() >= 2)\r\n                      {\r\n                        Byte secondByte = *data++;\r\n                        saltSize += (secondByte >> 4);\r\n                        ivSize += (secondByte & 0x0F);\r\n                      }\r\n                    }\r\n                    */\r\n                  }\r\n                }\r\n                else\r\n                {\r\n                  if (coderInfo.Properties.GetCapacity() > 0)\r\n                  {\r\n                    methodsString += L\":[\";\r\n                    for (size_t bi = 0; bi < coderInfo.Properties.GetCapacity(); bi++)\r\n                    {\r\n                      if (bi > 5 && bi + 1 < coderInfo.Properties.GetCapacity())\r\n                      {\r\n                        methodsString += L\"..\";\r\n                        break;\r\n                      }\r\n                      else\r\n                        methodsString += GetHex2(coderInfo.Properties[bi]);\r\n                    }\r\n                    methodsString += L\"]\";\r\n                  }\r\n                }\r\n              }\r\n              else\r\n              {\r\n                methodsString += ConvertMethodIdToString(coderInfo.MethodID);\r\n              }\r\n            }\r\n          }\r\n          prop = methodsString;\r\n        }\r\n      }\r\n      break;\r\n    case kpidBlock:\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n          prop = (UInt32)folderIndex;\r\n      }\r\n      break;\r\n    case kpidPackedSize0:\r\n    case kpidPackedSize1:\r\n    case kpidPackedSize2:\r\n    case kpidPackedSize3:\r\n    case kpidPackedSize4:\r\n      {\r\n        CNum folderIndex = _database.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _database.Folders[folderIndex];\r\n          if (_database.FolderStartFileIndex[folderIndex] == (CNum)index2 &&\r\n              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))\r\n          {\r\n            prop = _database.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);\r\n          }\r\n          else\r\n            prop = (UInt64)0;\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    #endif\r\n    case kpidIsAnti:\r\n      prop = item.IsAnti;\r\n      break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef _7Z_VOL\r\n\r\nstatic const wchar_t *kExt = L\"7z\";\r\nstatic const wchar_t *kAfterPart = L\".7z\";\r\n\r\nclass CVolumeName\r\n{\r\n  bool _first;\r\n  UString _unchangedPart;\r\n  UString _changedPart;    \r\n  UString _afterPart;    \r\npublic:\r\n  bool InitName(const UString &name)\r\n  {\r\n    _first = true;\r\n    int dotPos = name.ReverseFind('.');\r\n    UString basePart = name;\r\n    if (dotPos >= 0)\r\n    {\r\n      UString ext = name.Mid(dotPos + 1);\r\n      if (ext.CompareNoCase(kExt)==0 || \r\n        ext.CompareNoCase(L\"EXE\") == 0)\r\n      {\r\n        _afterPart = kAfterPart;\r\n        basePart = name.Left(dotPos);\r\n      }\r\n    }\r\n\r\n    int numLetters = 1;\r\n    bool splitStyle = false;\r\n    if (basePart.Right(numLetters) == L\"1\")\r\n    {\r\n      while (numLetters < basePart.Length())\r\n      {\r\n        if (basePart[basePart.Length() - numLetters - 1] != '0')\r\n          break;\r\n        numLetters++;\r\n      }\r\n    }\r\n    else \r\n      return false;\r\n    _unchangedPart = basePart.Left(basePart.Length() - numLetters);\r\n    _changedPart = basePart.Right(numLetters);\r\n    return true;\r\n  }\r\n\r\n  UString GetNextName()\r\n  {\r\n    UString newName; \r\n    // if (_newStyle || !_first)\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == L'9')\r\n        {\r\n          c = L'0';\r\n          newName = c + newName;\r\n          if (i == 0)\r\n            newName = UString(L'1') + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        newName = UString(c) + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n      _changedPart = newName;\r\n    }\r\n    _first = false;\r\n    return _unchangedPart + _changedPart + _afterPart;\r\n  }\r\n};\r\n\r\n#endif\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 *maxCheckStartPosition, \r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Clear();\r\n  #endif\r\n  try\r\n  {\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;\r\n    #ifdef _7Z_VOL\r\n    CVolumeName seqName;\r\n\r\n    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(\r\n          IID_ICryptoGetTextPassword, &getTextPassword);\r\n    }\r\n    #endif\r\n    #ifdef _7Z_VOL\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback);\r\n    }\r\n    for (;;)\r\n    {\r\n      CMyComPtr<IInStream> inStream;\r\n      if (!_volumes.IsEmpty())\r\n      {\r\n        if (!openVolumeCallback)\r\n          break;\r\n        if(_volumes.Size() == 1)\r\n        {\r\n          UString baseName;\r\n          {\r\n            NCOM::CPropVariant prop;\r\n            RINOK(openVolumeCallback->GetProperty(kpidName, &prop));\r\n            if (prop.vt != VT_BSTR)\r\n              break;\r\n            baseName = prop.bstrVal;\r\n          }\r\n          seqName.InitName(baseName);\r\n        }\r\n\r\n        UString fullName = seqName.GetNextName();\r\n        HRESULT result = openVolumeCallback->GetStream(fullName, &inStream);\r\n        if (result == S_FALSE)\r\n          break;\r\n        if (result != S_OK)\r\n          return result;\r\n        if (!stream)\r\n          break;\r\n      }\r\n      else\r\n        inStream = stream;\r\n\r\n      CInArchive archive;\r\n      RINOK(archive.Open(inStream, maxCheckStartPosition));\r\n\r\n      _volumes.Add(CVolume());\r\n      CVolume &volume = _volumes.Back();\r\n      CArchiveDatabaseEx &database = volume.Database;\r\n      volume.Stream = inStream;\r\n      volume.StartRef2Index = _refs.Size();\r\n\r\n      HRESULT result = archive.ReadDatabase(database\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword\r\n          #endif\r\n          );\r\n      if (result != S_OK)\r\n      {\r\n        _volumes.Clear();\r\n        return result;\r\n      }\r\n      database.Fill();\r\n      for(int i = 0; i < database.Files.Size(); i++)\r\n      {\r\n        CRef refNew;\r\n        refNew.VolumeIndex = _volumes.Size() - 1;\r\n        refNew.ItemIndex = i;\r\n        _refs.Add(refNew);\r\n        /*\r\n        const CFileItem &file = database.Files[i];\r\n        int j;\r\n        */\r\n        /*\r\n        for (j = _refs.Size() - 1; j >= 0; j--)\r\n        {\r\n          CRef2 &ref2 = _refs[j];\r\n          const CRef &ref = ref2.Refs.Back();\r\n          const CVolume &volume2 = _volumes[ref.VolumeIndex];\r\n          const CArchiveDatabaseEx &database2 = volume2.Database;\r\n          const CFileItem &file2 = database2.Files[ref.ItemIndex];\r\n          if (file2.Name.CompareNoCase(file.Name) == 0)\r\n          {\r\n            if (!file.IsStartPosDefined)\r\n              continue;\r\n            if (file.StartPos != ref2.StartPos + ref2.UnPackSize)\r\n              continue;\r\n            ref2.Refs.Add(refNew);\r\n            break;\r\n          }\r\n        }\r\n        */\r\n        /*\r\n        j = -1;\r\n        if (j < 0)\r\n        {\r\n          CRef2 ref2New;\r\n          ref2New.Refs.Add(refNew);\r\n          j = _refs.Add(ref2New);\r\n        }\r\n        CRef2 &ref2 = _refs[j];\r\n        ref2.UnPackSize += file.UnPackSize;\r\n        ref2.PackSize += database.GetFilePackSize(i);\r\n        if (ref2.Refs.Size() == 1 && file.IsStartPosDefined)\r\n          ref2.StartPos = file.StartPos;\r\n        */\r\n      }\r\n      if (database.Files.Size() != 1)\r\n        break;\r\n      const CFileItem &file = database.Files.Front();\r\n      if (!file.IsStartPosDefined)\r\n        break;\r\n    }\r\n    #else\r\n    CInArchive archive;\r\n    RINOK(archive.Open(stream, maxCheckStartPosition));\r\n    HRESULT result = archive.ReadDatabase(\r\n      EXTERNAL_CODECS_VARS\r\n      _database\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    _database.Fill();\r\n    _inStream = stream;\r\n    #endif\r\n  }\r\n  catch(...)\r\n  {\r\n    Close();\r\n    return S_FALSE;\r\n  }\r\n  // _inStream = stream;\r\n  #ifndef _SFX\r\n  FillPopIDs();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef _7Z_VOL\r\n  _volumes.Clear();\r\n  _refs.Clear();\r\n  #else\r\n  _inStream.Release();\r\n  _database.Clear();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nSTDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  *stream = 0;\r\n  CMultiStream *streamSpec = new CMultiStream;\r\n  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;\r\n  \r\n  UInt64 pos = 0;\r\n  const UString *fileName;\r\n  for (int i = 0; i < _refs.Size(); i++)\r\n  {\r\n    const CRef &ref = _refs[i];\r\n    const CVolume &volume = _volumes[ref.VolumeIndex];\r\n    const CArchiveDatabaseEx &database = volume.Database;\r\n    const CFileItem &file = database.Files[ref.ItemIndex];\r\n    if (i == 0)\r\n      fileName = &file.Name;\r\n    else\r\n      if (fileName->Compare(file.Name) != 0)\r\n        return S_FALSE;\r\n    if (!file.IsStartPosDefined)\r\n      return S_FALSE;\r\n    if (file.StartPos != pos)\r\n      return S_FALSE;\r\n    CNum folderIndex = database.FileIndexToFolderIndexMap[ref.ItemIndex];\r\n    if (folderIndex == kNumNoIndex)\r\n    {\r\n      if (file.UnPackSize != 0)\r\n        return E_FAIL;\r\n      continue;\r\n    }\r\n    if (database.NumUnPackStreamsVector[folderIndex] != 1)\r\n      return S_FALSE;\r\n    const CFolder &folder = database.Folders[folderIndex];\r\n    if (folder.Coders.Size() != 1)\r\n      return S_FALSE;\r\n    const CCoderInfo &coder = folder.Coders.Front();\r\n    if (coder.NumInStreams != 1 || coder.NumOutStreams != 1)\r\n      return S_FALSE;\r\n    if (coder.MethodID != k_Copy)\r\n      return S_FALSE;\r\n\r\n    pos += file.UnPackSize;\r\n    CMultiStream::CSubStreamInfo subStreamInfo;\r\n    subStreamInfo.Stream = volume.Stream;\r\n    subStreamInfo.Pos = database.GetFolderStreamPos(folderIndex, 0);\r\n    subStreamInfo.Size = file.UnPackSize;\r\n    streamSpec->Streams.Add(subStreamInfo);\r\n  }\r\n  streamSpec->Init();\r\n  *stream = streamTemp.Detach();\r\n  return S_OK;\r\n}\r\n#endif\r\n\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef COMPRESS_MT\r\n  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();\r\n  _numThreads = numProcessors;\r\n  #endif\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    const PROPVARIANT &value = values[i];\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index == 0)\r\n    {\r\n      if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n      {\r\n        #ifdef COMPRESS_MT\r\n        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n        #endif\r\n        continue;\r\n      }\r\n      else\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}  \r\n\r\n#endif\r\n#endif\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zHandler.h",
    "content": "// 7z/Handler.h\r\n\r\n#ifndef __7Z_HANDLER_H\r\n#define __7Z_HANDLER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../IArchive.h\"\r\n#include \"7zIn.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#ifndef EXTRACT_ONLY\r\n#include \"../Common/HandlerOut.h\"\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\n#ifdef _7Z_VOL\r\nstruct CRef\r\n{\r\n  int VolumeIndex;\r\n  int ItemIndex;\r\n};\r\n\r\nstruct CVolume\r\n{\r\n  int StartRef2Index;\r\n  CMyComPtr<IInStream> Stream;\r\n  CArchiveDatabaseEx Database;\r\n};\r\n#endif\r\n\r\n#ifndef __7Z_SET_PROPERTIES\r\n\r\n#ifdef EXTRACT_ONLY\r\n#ifdef COMPRESS_MT\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n#else \r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n\r\n#endif\r\n\r\n\r\nclass CHandler: \r\n  #ifndef EXTRACT_ONLY\r\n  public NArchive::COutHandler,\r\n  #endif\r\n  public IInArchive,\r\n  #ifdef _7Z_VOL\r\n  public IInArchiveGetStream,\r\n  #endif\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  public ISetProperties, \r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public IOutArchive, \r\n  #endif\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IInArchive)\r\n  #ifdef _7Z_VOL\r\n  MY_QUERYINTERFACE_ENTRY(IInArchiveGetStream)\r\n  #endif\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  MY_QUERYINTERFACE_ENTRY(ISetProperties)\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  MY_QUERYINTERFACE_ENTRY(IOutArchive)\r\n  #endif\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  #ifdef _7Z_VOL\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);  \r\n  #endif\r\n\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);\r\n  #endif\r\n\r\n  #ifndef EXTRACT_ONLY\r\n  INTERFACE_IOutArchive(;)\r\n  #endif\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n  CHandler();\r\n\r\nprivate:\r\n  #ifdef _7Z_VOL\r\n  CObjectVector<CVolume> _volumes;\r\n  CObjectVector<CRef> _refs;\r\n  #else\r\n  CMyComPtr<IInStream> _inStream;\r\n  NArchive::N7z::CArchiveDatabaseEx _database;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  \r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  #else\r\n  \r\n  CRecordVector<CBind> _binds;\r\n\r\n  HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);\r\n\r\n  HRESULT SetCompressionMethod(CCompressionMethodMode &method,\r\n      CObjectVector<COneMethodInfo> &methodsInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  HRESULT SetCompressionMethod(\r\n      CCompressionMethodMode &method,\r\n      CCompressionMethodMode &headerMethod);\r\n\r\n  #endif\r\n\r\n  bool IsEncrypted(UInt32 index2) const;\r\n  #ifndef _SFX\r\n\r\n  CRecordVector<UInt64> _fileInfoPopIDs;\r\n  void FillPopIDs();\r\n\r\n  #endif\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zHandlerOut.cpp",
    "content": "// 7zHandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const UInt32 kLzmaAlgorithmX5 = 1;\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5;\r\n\r\nstatic inline bool IsCopyMethod(const UString &methodName)\r\n  { return (methodName.CompareNoCase(kCopyMethod) == 0); }\r\n\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  CMyComPtr<ICryptoGetTextPassword2> getTextPassword;\r\n  if (!getTextPassword)\r\n  {\r\n    CMyComPtr<IArchiveUpdateCallback> udateCallback2(updateCallback);\r\n    udateCallback2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);\r\n  }\r\n  \r\n  if (getTextPassword)\r\n  {\r\n    CMyComBSTR password;\r\n    Int32 passwordIsDefined;\r\n    RINOK(getTextPassword->CryptoGetTextPassword2(\r\n        &passwordIsDefined, &password));\r\n    methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);\r\n    if (methodMode.PasswordIsDefined)\r\n      methodMode.Password = password;\r\n  }\r\n  else\r\n    methodMode.PasswordIsDefined = false;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CCompressionMethodMode &headerMethod)\r\n{\r\n  HRESULT res = SetCompressionMethod(methodMode, _methods\r\n  #ifdef COMPRESS_MT\r\n  , _numThreads\r\n  #endif\r\n  );\r\n  RINOK(res);\r\n  methodMode.Binds = _binds;\r\n\r\n  if (_compressHeaders)\r\n  {\r\n    // headerMethod.Methods.Add(methodMode.Methods.Back());\r\n\r\n    CObjectVector<COneMethodInfo> headerMethodInfoVector;\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = kLZMAMethodName;\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kMatchFinder;\r\n      property.Value = kLzmaMatchFinderForHeaders;\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kAlgorithm;\r\n      property.Value = kAlgorithmForHeaders;\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kNumFastBytes;\r\n      property.Value = UInt32(kNumFastBytesForHeaders);\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n      property.Value = UInt32(kDictionaryForHeaders);\r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n    headerMethodInfoVector.Add(oneMethodInfo);\r\n    HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector\r\n      #ifdef COMPRESS_MT\r\n      ,1\r\n      #endif\r\n    );\r\n    RINOK(res);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CObjectVector<COneMethodInfo> &methodsInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  \r\n  if (methodsInfo.IsEmpty())\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = ((level == 0) ? kCopyMethod : kDefaultMethodName);\r\n    methodsInfo.Add(oneMethodInfo);\r\n  }\r\n\r\n  bool needSolid = false;\r\n  for(int i = 0; i < methodsInfo.Size(); i++)\r\n  {\r\n    COneMethodInfo &oneMethodInfo = methodsInfo[i];\r\n    SetCompressionMethod2(oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , numThreads\r\n      #endif\r\n      );\r\n\r\n    if (!IsCopyMethod(oneMethodInfo.MethodName))\r\n      needSolid = true;\r\n\r\n    CMethodFull methodFull;\r\n\r\n    if (!FindMethod(\r\n        EXTERNAL_CODECS_VARS\r\n        oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams))\r\n      return E_INVALIDARG;\r\n    methodFull.Properties = oneMethodInfo.Properties;\r\n    methodMode.Methods.Add(methodFull);\r\n\r\n    if (!_numSolidBytesDefined)\r\n    {\r\n      for (int j = 0; j < methodFull.Properties.Size(); j++)\r\n      {\r\n        const CProp &prop = methodFull.Properties[j];\r\n        if ((prop.Id == NCoderPropID::kDictionarySize || \r\n             prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4)\r\n        {\r\n          _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7;\r\n          const UInt64 kMinSize = (1 << 24);\r\n          if (_numSolidBytes < kMinSize)\r\n            _numSolidBytes = kMinSize;\r\n          _numSolidBytesDefined = true;\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (!needSolid && !_numSolidBytesDefined)\r\n  {\r\n    _numSolidBytesDefined = true;\r\n    _numSolidBytes  = 0;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, PROPID propID, CArchiveFileTime &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant propVariant;\r\n  RINOK(updateCallback->GetProperty(index, propID, &propVariant));\r\n  if (propVariant.vt == VT_FILETIME)\r\n  {\r\n    filetime = propVariant.filetime;\r\n    filetimeIsDefined = true;\r\n  }\r\n  else if (propVariant.vt != VT_EMPTY)\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  const CArchiveDatabaseEx *database = 0;\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() > 1)\r\n    return E_FAIL;\r\n  const CVolume *volume = 0;\r\n  if (_volumes.Size() == 1)\r\n  {\r\n    volume = &_volumes.Front();\r\n    database = &volume->Database;\r\n  }\r\n  #else\r\n  if (_inStream != 0)\r\n    database = &_database;\r\n  #endif\r\n\r\n  // CRecordVector<bool> compressStatuses;\r\n  CObjectVector<CUpdateItem> updateItems;\r\n  // CRecordVector<UInt32> copyIndices;\r\n  \r\n  // CMyComPtr<IUpdateCallback2> updateCallback2;\r\n  // updateCallback->QueryInterface(&updateCallback2);\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    Int32 newData;\r\n    Int32 newProperties;\r\n    UInt32 indexInArchive;\r\n    if (!updateCallback)\r\n      return E_FAIL;\r\n    RINOK(updateCallback->GetUpdateItemInfo(i,\r\n        &newData, &newProperties, &indexInArchive));\r\n    CUpdateItem updateItem;\r\n    updateItem.NewProperties = IntToBool(newProperties);\r\n    updateItem.NewData = IntToBool(newData);\r\n    updateItem.IndexInArchive = indexInArchive;\r\n    updateItem.IndexInClient = i;\r\n    updateItem.IsAnti = false;\r\n    updateItem.Size = 0;\r\n\r\n    if (updateItem.IndexInArchive != -1)\r\n    {\r\n      const CFileItem &fileItem = database->Files[updateItem.IndexInArchive];\r\n      updateItem.Name = fileItem.Name;\r\n      updateItem.IsDirectory = fileItem.IsDirectory;\r\n      updateItem.Size = fileItem.UnPackSize;\r\n      updateItem.IsAnti = fileItem.IsAnti;\r\n      \r\n      updateItem.CreationTime = fileItem.CreationTime;\r\n      updateItem.IsCreationTimeDefined = fileItem.IsCreationTimeDefined;\r\n      updateItem.LastWriteTime = fileItem.LastWriteTime;\r\n      updateItem.IsLastWriteTimeDefined = fileItem.IsLastWriteTimeDefined;\r\n      updateItem.LastAccessTime = fileItem.LastAccessTime;\r\n      updateItem.IsLastAccessTimeDefined = fileItem.IsLastAccessTimeDefined;\r\n    }\r\n\r\n    if (updateItem.NewProperties)\r\n    {\r\n      bool nameIsDefined;\r\n      bool folderStatusIsDefined;\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidAttributes, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          updateItem.AttributesAreDefined = false;\r\n        else if (propVariant.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          updateItem.Attributes = propVariant.ulVal;\r\n          updateItem.AttributesAreDefined = true;\r\n        }\r\n      }\r\n      \r\n      RINOK(GetTime(updateCallback, i, kpidCreationTime, updateItem.CreationTime, updateItem.IsCreationTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, kpidLastWriteTime, updateItem.LastWriteTime , updateItem.IsLastWriteTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, kpidLastAccessTime, updateItem.LastAccessTime, updateItem.IsLastAccessTimeDefined));\r\n\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidPath, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          nameIsDefined = false;\r\n        else if (propVariant.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          updateItem.Name = NItemName::MakeLegalName(propVariant.bstrVal);\r\n          nameIsDefined = true;\r\n        }\r\n      }\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsFolder, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          folderStatusIsDefined = false;\r\n        else if (propVariant.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          updateItem.IsDirectory = (propVariant.boolVal != VARIANT_FALSE);\r\n          folderStatusIsDefined = true;\r\n        }\r\n      }\r\n\r\n      {\r\n        NCOM::CPropVariant propVariant;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsAnti, &propVariant));\r\n        if (propVariant.vt == VT_EMPTY)\r\n          updateItem.IsAnti = false;\r\n        else if (propVariant.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n          updateItem.IsAnti = (propVariant.boolVal != VARIANT_FALSE);\r\n      }\r\n\r\n      if (updateItem.IsAnti)\r\n      {\r\n        updateItem.AttributesAreDefined = false;\r\n\r\n        updateItem.IsCreationTimeDefined = false;\r\n        updateItem.IsLastWriteTimeDefined = false;\r\n        updateItem.IsLastAccessTimeDefined = false;\r\n        \r\n        updateItem.Size = 0;\r\n      }\r\n\r\n      if (!folderStatusIsDefined && updateItem.AttributesAreDefined)\r\n        updateItem.SetDirectoryStatusFromAttributes();\r\n    }\r\n\r\n    if (updateItem.NewData)\r\n    {\r\n      NCOM::CPropVariant propVariant;\r\n      RINOK(updateCallback->GetProperty(i, kpidSize, &propVariant));\r\n      if (propVariant.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      updateItem.Size = (UInt64)propVariant.uhVal.QuadPart;\r\n      if (updateItem.Size != 0 && updateItem.IsAnti)\r\n        return E_INVALIDARG;\r\n    }\r\n    updateItems.Add(updateItem);\r\n  }\r\n\r\n  CCompressionMethodMode methodMode, headerMethod;\r\n  RINOK(SetCompressionMethod(methodMode, headerMethod));\r\n  #ifdef COMPRESS_MT\r\n  methodMode.NumThreads = _numThreads;\r\n  headerMethod.NumThreads = 1;\r\n  #endif\r\n\r\n  RINOK(SetPassword(methodMode, updateCallback));\r\n\r\n  bool compressMainHeader = _compressHeaders;  // check it\r\n\r\n  if (methodMode.PasswordIsDefined)\r\n  {\r\n    compressMainHeader = true; \r\n    if(_encryptHeaders)\r\n      RINOK(SetPassword(headerMethod, updateCallback));\r\n  }\r\n\r\n  if (numItems < 2)\r\n    compressMainHeader = false;\r\n\r\n  CUpdateOptions options;\r\n  options.Method = &methodMode;\r\n  options.HeaderMethod = (_compressHeaders || \r\n      (methodMode.PasswordIsDefined && _encryptHeaders)) ? \r\n      &headerMethod : 0;\r\n  options.UseFilters = _level != 0 && _autoFilter;\r\n  options.MaxFilter = _level >= 8;\r\n\r\n  options.HeaderOptions.CompressMainHeader = compressMainHeader;\r\n  options.HeaderOptions.WriteModified = WriteModified;\r\n  options.HeaderOptions.WriteCreated = WriteCreated;\r\n  options.HeaderOptions.WriteAccessed = WriteAccessed;\r\n  \r\n  options.NumSolidFiles = _numSolidFiles;\r\n  options.NumSolidBytes = _numSolidBytes;\r\n  options.SolidExtension = _solidExtension;\r\n  options.RemoveSfxBlock = _removeSfxBlock;\r\n  options.VolumeMode = _volumeMode;\r\n  return Update(\r\n      EXTERNAL_CODECS_VARS\r\n      #ifdef _7Z_VOL\r\n      volume ? volume->Stream: 0, \r\n      volume ? database: 0, \r\n      #else\r\n      _inStream, \r\n      database,\r\n      #endif\r\n      updateItems, outStream, updateCallback, options);\r\n  COM_TRY_END\r\n}\r\n\r\nstatic HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)\r\n{\r\n  stream = 0;\r\n  int index = ParseStringToUInt32(srcString, coder);\r\n  if (index == 0)\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0, index);\r\n  if (srcString[0] == 'S')\r\n  {\r\n    srcString.Delete(0);\r\n    int index = ParseStringToUInt32(srcString, stream);\r\n    if (index == 0)\r\n      return E_INVALIDARG;\r\n    srcString.Delete(0, index);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetBindInfo(UString &srcString, CBind &bind)\r\n{\r\n  RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream));\r\n  if (srcString[0] != ':')\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0);\r\n  RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream));\r\n  if (!srcString.IsEmpty())\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  _binds.Clear();\r\n  BeforeSetProperty();\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n\r\n    const PROPVARIANT &value = values[i];\r\n\r\n    if (name[0] == 'B')\r\n    {\r\n      name.Delete(0);\r\n      CBind bind;\r\n      RINOK(GetBindInfo(name, bind));\r\n      _binds.Add(bind);\r\n      continue;\r\n    }\r\n\r\n    RINOK(SetProperty(name, value));\r\n  }\r\n\r\n  return S_OK;\r\n  COM_TRY_END\r\n}  \r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zHeader.cpp",
    "content": "// 7z/Header.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nByte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n#ifdef _7Z_VOL\r\nByte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};\r\n#endif\r\n\r\nclass SignatureInitializer\r\n{\r\npublic:\r\n  SignatureInitializer() \r\n  { \r\n    kSignature[0]--; \r\n    #ifdef _7Z_VOL\r\n    kFinishSignature[0]--;\r\n    #endif\r\n  };\r\n} g_SignatureInitializer;\r\n\r\n}}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zHeader.h",
    "content": "// 7z/7zHeader.h\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nconst int kSignatureSize = 6;\r\nextern Byte kSignature[kSignatureSize];\r\n\r\n// #define _7Z_VOL\r\n// 7z-MultiVolume is not finished yet.\r\n// It can work already, but I still do not like some \r\n// things of that new multivolume format.\r\n// So please keep it commented.\r\n\r\n#ifdef _7Z_VOL\r\nextern Byte kFinishSignature[kSignatureSize];\r\n#endif\r\n\r\nstruct CArchiveVersion\r\n{\r\n  Byte Major;\r\n  Byte Minor;\r\n};\r\n\r\nconst Byte kMajorVersion = 0;\r\n\r\nstruct CStartHeader\r\n{\r\n  UInt64 NextHeaderOffset;\r\n  UInt64 NextHeaderSize;\r\n  UInt32 NextHeaderCRC;\r\n};\r\n\r\nconst UInt32 kStartHeaderSize = 20;\r\n\r\n#ifdef _7Z_VOL\r\nstruct CFinishHeader: public CStartHeader\r\n{\r\n  UInt64 ArchiveStartOffset;  // data offset from end if that struct\r\n  UInt64 AdditionalStartBlockSize; // start  signature & start header size\r\n};\r\n\r\nconst UInt32 kFinishHeaderSize = kStartHeaderSize + 16;\r\n#endif\r\n\r\nnamespace NID\r\n{\r\n  enum EEnum\r\n  {\r\n    kEnd,\r\n\r\n    kHeader,\r\n\r\n    kArchiveProperties,\r\n    \r\n    kAdditionalStreamsInfo,\r\n    kMainStreamsInfo,\r\n    kFilesInfo,\r\n    \r\n    kPackInfo,\r\n    kUnPackInfo,\r\n    kSubStreamsInfo,\r\n\r\n    kSize,\r\n    kCRC,\r\n\r\n    kFolder,\r\n\r\n    kCodersUnPackSize,\r\n    kNumUnPackStream,\r\n\r\n    kEmptyStream,\r\n    kEmptyFile,\r\n    kAnti,\r\n\r\n    kName,\r\n    kCreationTime,\r\n    kLastAccessTime,\r\n    kLastWriteTime,\r\n    kWinAttributes,\r\n    kComment,\r\n\r\n    kEncodedHeader,\r\n\r\n    kStartPos\r\n  };\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zIn.cpp",
    "content": "// 7zIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zDecode.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\n// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader \r\n#ifndef _SFX\r\n#define FORMAT_7Z_RECOVERY\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CInArchiveException {};\r\n\r\nstatic void ThrowException() { throw CInArchiveException(); }\r\nstatic inline void ThrowEndOfData()   { ThrowException(); }\r\nstatic inline void ThrowUnsupported() { ThrowException(); }\r\nstatic inline void ThrowIncorrect()   { ThrowException(); }\r\nstatic inline void ThrowUnsupportedVersion() { ThrowException(); }\r\n\r\n/*\r\nclass CInArchiveException\r\n{\r\npublic:\r\n  enum CCauseType\r\n  {\r\n    kUnsupportedVersion = 0,\r\n    kUnsupported,\r\n    kIncorrect, \r\n    kEndOfData,\r\n  } Cause;\r\n  CInArchiveException(CCauseType cause): Cause(cause) {};\r\n};\r\n\r\nstatic void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }\r\nstatic void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }\r\nstatic void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }\r\nstatic void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }\r\nstatic void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }\r\n*/\r\n\r\nclass CStreamSwitch\r\n{\r\n  CInArchive *_archive;\r\n  bool _needRemove;\r\npublic:\r\n  CStreamSwitch(): _needRemove(false) {}\r\n  ~CStreamSwitch() { Remove(); }\r\n  void Remove();\r\n  void Set(CInArchive *archive, const Byte *data, size_t size);\r\n  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);\r\n  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);\r\n};\r\n\r\nvoid CStreamSwitch::Remove()\r\n{\r\n  if (_needRemove)\r\n  {\r\n    _archive->DeleteByteStream();\r\n    _needRemove = false;\r\n  }\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)\r\n{\r\n  Remove();\r\n  _archive = archive;\r\n  _archive->AddByteStream(data, size);\r\n  _needRemove = true;\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)\r\n{\r\n  Set(archive, byteBuffer, byteBuffer.GetCapacity());\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)\r\n{\r\n  Remove();\r\n  Byte external = archive->ReadByte();\r\n  if (external != 0)\r\n  {\r\n    int dataIndex = (int)archive->ReadNum();\r\n    if (dataIndex < 0 || dataIndex >= dataVector->Size())\r\n      ThrowIncorrect();\r\n    Set(archive, (*dataVector)[dataIndex]);\r\n  }\r\n}\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define SZ_LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#ifdef SZ_LITTLE_ENDIAN_UNALIGN\r\nstatic inline UInt16 GetUInt16FromMem(const Byte *p) { return *(const UInt16 *)p; }\r\nstatic inline UInt32 GetUInt32FromMem(const Byte *p) { return *(const UInt32 *)p; }\r\nstatic inline UInt64 GetUInt64FromMem(const Byte *p) { return *(const UInt64 *)p; }\r\n#else\r\nstatic inline UInt16 GetUInt16FromMem(const Byte *p) { return p[0] | ((UInt16)p[1] << 8); }\r\nstatic inline UInt32 GetUInt32FromMem(const Byte *p) { return p[0] | ((UInt32)p[1] << 8) | ((UInt32)p[2] << 16) | ((UInt32)p[3] << 24); }\r\nstatic inline UInt64 GetUInt64FromMem(const Byte *p) { return GetUInt32FromMem(p) | ((UInt64)GetUInt32FromMem(p + 4) << 32); }\r\n#endif\r\n\r\nByte CInByte2::ReadByte()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  return _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::ReadBytes(Byte *data, size_t size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  for (size_t i = 0; i < size; i++)\r\n    data[i] = _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::SkeepData(UInt64 size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n}\r\n\r\nvoid CInByte2::SkeepData()\r\n{\r\n  SkeepData(ReadNumber());\r\n}\r\n\r\nUInt64 CInByte2::ReadNumber()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  Byte firstByte = _buffer[_pos++];\r\n  Byte mask = 0x80;\r\n  UInt64 value = 0;\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      value += (highPart << (i * 8));\r\n      return value;\r\n    }\r\n    if (_pos >= _size)\r\n      ThrowEndOfData();\r\n    value |= ((UInt64)_buffer[_pos++] << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return value;\r\n}\r\n\r\nCNum CInByte2::ReadNum()\r\n{ \r\n  UInt64 value = ReadNumber(); \r\n  if (value > kNumMax)\r\n    ThrowUnsupported();\r\n  return (CNum)value;\r\n}\r\n\r\nUInt32 CInByte2::ReadUInt32()\r\n{\r\n  if (_pos + 4 > _size)\r\n    ThrowEndOfData();\r\n  UInt32 res = GetUInt32FromMem(_buffer + _pos);\r\n  _pos += 4;\r\n  return res;\r\n}\r\n\r\nUInt64 CInByte2::ReadUInt64()\r\n{\r\n  if (_pos + 8 > _size)\r\n    ThrowEndOfData();\r\n  UInt64 res = GetUInt64FromMem(_buffer + _pos);\r\n  _pos += 8;\r\n  return res;\r\n}\r\n\r\nvoid CInByte2::ReadString(UString &s)\r\n{\r\n  const Byte *buf = _buffer + _pos;\r\n  size_t rem = (_size - _pos) / 2 * 2;\r\n  {\r\n    size_t i;\r\n    for (i = 0; i < rem; i += 2)\r\n      if (buf[i] == 0 && buf[i + 1] == 0)\r\n        break;\r\n    if (i == rem)\r\n      ThrowEndOfData();\r\n    rem = i;\r\n  }\r\n  int len = (int)(rem / 2);\r\n  if (len < 0 || (size_t)len * 2 != rem)\r\n    ThrowUnsupported();\r\n  wchar_t *p = s.GetBuffer(len);\r\n  int i;\r\n  for (i = 0; i < len; i++, buf += 2) \r\n    p[i] = (wchar_t)GetUInt16FromMem(buf);\r\n  p[i] = 0;\r\n  s.ReleaseBuffer(len);\r\n  _pos += rem + 2;\r\n}\r\n\r\nstatic inline bool TestSignatureCandidate(const Byte *p)\r\n{\r\n  for (int i = 0; i < kSignatureSize; i++)\r\n    if (p[i] != kSignature[i])\r\n      return false;\r\n  return (p[0x1A] == 0 && p[0x1B] == 0);\r\n}\r\n\r\nHRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  UInt32 processedSize; \r\n  RINOK(ReadStream(stream, _header, kHeaderSize, &processedSize));\r\n  if (processedSize != kHeaderSize)\r\n    return S_FALSE;\r\n  if (TestSignatureCandidate(_header))\r\n    return S_OK;\r\n\r\n  CByteBuffer byteBuffer;\r\n  const UInt32 kBufferSize = (1 << 16);\r\n  byteBuffer.SetCapacity(kBufferSize);\r\n  Byte *buffer = byteBuffer;\r\n  UInt32 numPrevBytes = kHeaderSize - 1;\r\n  memcpy(buffer, _header + 1, numPrevBytes);\r\n  UInt64 curTestPos = _arhiveBeginStreamPosition + 1;\r\n  for (;;)\r\n  {\r\n    if (searchHeaderSizeLimit != NULL)\r\n      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)\r\n        break;\r\n    UInt32 numReadBytes = kBufferSize - numPrevBytes;\r\n    RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));\r\n    UInt32 numBytesInBuffer = numPrevBytes + processedSize;\r\n    if (numBytesInBuffer < kHeaderSize)\r\n      break;\r\n    UInt32 numTests = numBytesInBuffer - kHeaderSize + 1;\r\n    for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++)\r\n    { \r\n      if (TestSignatureCandidate(buffer + pos))\r\n      {\r\n        memcpy(_header, buffer + pos, kHeaderSize);\r\n        _arhiveBeginStreamPosition = curTestPos;\r\n        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);\r\n      }\r\n    }\r\n    numPrevBytes = numBytesInBuffer - numTests;\r\n    memmove(buffer, buffer + numTests, numPrevBytes);\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\n// S_FALSE means that file is not archive\r\nHRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  Close();\r\n  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))\r\n  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));\r\n  _stream = stream;\r\n  return S_OK;\r\n}\r\n  \r\nvoid CInArchive::Close()\r\n{\r\n  _stream.Release();\r\n}\r\n\r\nvoid CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)\r\n{\r\n  for (;;)\r\n  {\r\n    if (ReadID() == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::GetNextFolderItem(CFolder &folder)\r\n{\r\n  CNum numCoders = ReadNum();\r\n\r\n  folder.Coders.Clear();\r\n  folder.Coders.Reserve((int)numCoders);\r\n  CNum numInStreams = 0;\r\n  CNum numOutStreams = 0;\r\n  CNum i;\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    folder.Coders.Add(CCoderInfo());\r\n    CCoderInfo &coder = folder.Coders.Back();\r\n\r\n    {\r\n      Byte mainByte = ReadByte();\r\n      int idSize = (mainByte & 0xF);\r\n      Byte longID[15];\r\n      ReadBytes(longID, idSize);\r\n      if (idSize > 8)\r\n        ThrowUnsupported();\r\n      UInt64 id = 0;\r\n      for (int j = 0; j < idSize; j++)\r\n        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n      coder.MethodID = id;\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        coder.NumInStreams = ReadNum();\r\n        coder.NumOutStreams = ReadNum();\r\n      }\r\n      else\r\n      {\r\n        coder.NumInStreams = 1;\r\n        coder.NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        CNum propertiesSize = ReadNum();\r\n        coder.Properties.SetCapacity((size_t)propertiesSize);\r\n        ReadBytes((Byte *)coder.Properties, (size_t)propertiesSize);\r\n      }\r\n      if ((mainByte & 0x80) != 0)\r\n        ThrowUnsupported();\r\n    }\r\n    numInStreams += coder.NumInStreams;\r\n    numOutStreams += coder.NumOutStreams;\r\n  }\r\n\r\n  CNum numBindPairs;\r\n  numBindPairs = numOutStreams - 1;\r\n  folder.BindPairs.Clear();\r\n  folder.BindPairs.Reserve(numBindPairs);\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = ReadNum();\r\n    bindPair.OutIndex = ReadNum(); \r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n\r\n  CNum numPackedStreams = numInStreams - numBindPairs;\r\n  folder.PackStreams.Reserve(numPackedStreams);\r\n  if (numPackedStreams == 1)\r\n  {\r\n    for (CNum j = 0; j < numInStreams; j++)\r\n      if (folder.FindBindPairForInStream(j) < 0)\r\n      {\r\n        folder.PackStreams.Add(j);\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n      folder.PackStreams.Add(ReadNum());\r\n}\r\n\r\nvoid CInArchive::WaitAttribute(UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == attribute)\r\n      return;\r\n    if (type == NID::kEnd)\r\n      ThrowIncorrect();\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadHashDigests(int numItems,\r\n    CRecordVector<bool> &digestsDefined, \r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  ReadBoolVector2(numItems, digestsDefined);\r\n  digests.Clear();\r\n  digests.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 crc = 0;\r\n    if (digestsDefined[i])\r\n      crc = ReadUInt32();\r\n    digests.Add(crc);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadPackInfo(\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CRecordVector<bool> &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs)\r\n{\r\n  dataOffset = ReadNumber();\r\n  CNum numPackStreams = ReadNum();\r\n\r\n  WaitAttribute(NID::kSize);\r\n  packSizes.Clear();\r\n  packSizes.Reserve(numPackStreams);\r\n  for (CNum i = 0; i < numPackStreams; i++)\r\n    packSizes.Add(ReadNumber());\r\n\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    if (type == NID::kCRC)\r\n    {\r\n      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs); \r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n  if (packCRCsDefined.IsEmpty())\r\n  {\r\n    packCRCsDefined.Reserve(numPackStreams);\r\n    packCRCsDefined.Clear();\r\n    packCRCs.Reserve(numPackStreams);\r\n    packCRCs.Clear();\r\n    for(CNum i = 0; i < numPackStreams; i++)\r\n    {\r\n      packCRCsDefined.Add(false);\r\n      packCRCs.Add(0);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadUnPackInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    CObjectVector<CFolder> &folders)\r\n{\r\n  WaitAttribute(NID::kFolder);\r\n  CNum numFolders = ReadNum();\r\n\r\n  {\r\n    CStreamSwitch streamSwitch;\r\n    streamSwitch.Set(this, dataVector);\r\n    folders.Clear();\r\n    folders.Reserve(numFolders);\r\n    for(CNum i = 0; i < numFolders; i++)\r\n    {\r\n      folders.Add(CFolder());\r\n      GetNextFolderItem(folders.Back());\r\n    }\r\n  }\r\n\r\n  WaitAttribute(NID::kCodersUnPackSize);\r\n\r\n  CNum i;\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    CFolder &folder = folders[i];\r\n    CNum numOutStreams = folder.GetNumOutStreams();\r\n    folder.UnPackSizes.Reserve(numOutStreams);\r\n    for (CNum j = 0; j < numOutStreams; j++)\r\n      folder.UnPackSizes.Add(ReadNumber());\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      return;\r\n    if (type == NID::kCRC)\r\n    {\r\n      CRecordVector<bool> crcsDefined;\r\n      CRecordVector<UInt32> crcs;\r\n      ReadHashDigests(numFolders, crcsDefined, crcs); \r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        CFolder &folder = folders[i];\r\n        folder.UnPackCRCDefined = crcsDefined[i];\r\n        folder.UnPackCRC = crcs[i];\r\n      }\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n    CRecordVector<UInt64> &unPackSizes,\r\n    CRecordVector<bool> &digestsDefined, \r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  numUnPackStreamsInFolders.Clear();\r\n  numUnPackStreamsInFolders.Reserve(folders.Size());\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kNumUnPackStream)\r\n    {\r\n      for(int i = 0; i < folders.Size(); i++)\r\n        numUnPackStreamsInFolders.Add(ReadNum());\r\n      continue;\r\n    }\r\n    if (type == NID::kCRC || type == NID::kSize)\r\n      break;\r\n    if (type == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n\r\n  if (numUnPackStreamsInFolders.IsEmpty())\r\n    for(int i = 0; i < folders.Size(); i++)\r\n      numUnPackStreamsInFolders.Add(1);\r\n\r\n  int i;\r\n  for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n  {\r\n    // v3.13 incorrectly worked with empty folders\r\n    // v4.07: we check that folder is empty\r\n    CNum numSubstreams = numUnPackStreamsInFolders[i];\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    UInt64 sum = 0;\r\n    for (CNum j = 1; j < numSubstreams; j++)\r\n      if (type == NID::kSize)\r\n      {\r\n        UInt64 size = ReadNumber();\r\n        unPackSizes.Add(size);\r\n        sum += size;\r\n      }\r\n    unPackSizes.Add(folders[i].GetUnPackSize() - sum);\r\n  }\r\n  if (type == NID::kSize)\r\n    type = ReadID();\r\n\r\n  int numDigests = 0;\r\n  int numDigestsTotal = 0;\r\n  for(i = 0; i < folders.Size(); i++)\r\n  {\r\n    CNum numSubstreams = numUnPackStreamsInFolders[i];\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n    numDigestsTotal += numSubstreams;\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    if (type == NID::kCRC)\r\n    {\r\n      CRecordVector<bool> digestsDefined2; \r\n      CRecordVector<UInt32> digests2;\r\n      ReadHashDigests(numDigests, digestsDefined2, digests2);\r\n      int digestIndex = 0;\r\n      for (i = 0; i < folders.Size(); i++)\r\n      {\r\n        CNum numSubstreams = numUnPackStreamsInFolders[i];\r\n        const CFolder &folder = folders[i];\r\n        if (numSubstreams == 1 && folder.UnPackCRCDefined)\r\n        {\r\n          digestsDefined.Add(true);\r\n          digests.Add(folder.UnPackCRC);\r\n        }\r\n        else\r\n          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)\r\n          {\r\n            digestsDefined.Add(digestsDefined2[digestIndex]);\r\n            digests.Add(digests2[digestIndex]);\r\n          }\r\n      }\r\n    }\r\n    else if (type == NID::kEnd)\r\n    {\r\n      if (digestsDefined.IsEmpty())\r\n      {\r\n        digestsDefined.Clear();\r\n        digests.Clear();\r\n        for (int i = 0; i < numDigestsTotal; i++)\r\n        {\r\n          digestsDefined.Add(false);\r\n          digests.Add(0);\r\n        }\r\n      }\r\n      return;\r\n    }\r\n    else\r\n      SkeepData();\r\n    type = ReadID();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadStreamsInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CRecordVector<bool> &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs,\r\n    CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n    CRecordVector<UInt64> &unPackSizes,\r\n    CRecordVector<bool> &digestsDefined, \r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type > ((UInt32)1 << 30))\r\n      ThrowIncorrect();\r\n    switch((UInt32)type)\r\n    {\r\n      case NID::kEnd:\r\n        return;\r\n      case NID::kPackInfo:\r\n      {\r\n        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);\r\n        break;\r\n      }\r\n      case NID::kUnPackInfo:\r\n      {\r\n        ReadUnPackInfo(dataVector, folders);\r\n        break;\r\n      }\r\n      case NID::kSubStreamsInfo:\r\n      {\r\n        ReadSubStreamsInfo(folders, numUnPackStreamsInFolders,\r\n            unPackSizes, digestsDefined, digests);\r\n        break;\r\n      }\r\n      default:\r\n        ThrowIncorrect();\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector(int numItems, CBoolVector &v)\r\n{\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  for(int i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      b = ReadByte();\r\n      mask = 0x80;\r\n    }\r\n    v.Add((b & mask) != 0);\r\n    mask >>= 1;\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)\r\n{\r\n  Byte allAreDefined = ReadByte();\r\n  if (allAreDefined == 0)\r\n  {\r\n    ReadBoolVector(numItems, v);\r\n    return;\r\n  }\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n    v.Add(true);\r\n}\r\n\r\nvoid CInArchive::ReadTime(const CObjectVector<CByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt32 type)\r\n{\r\n  CBoolVector boolVector;\r\n  ReadBoolVector2(files.Size(), boolVector);\r\n\r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, &dataVector);\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    fileTime.dwLowDateTime = 0;\r\n    fileTime.dwHighDateTime = 0;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      fileTime.dwLowDateTime = ReadUInt32();\r\n      fileTime.dwHighDateTime = ReadUInt32();\r\n    }\r\n    switch(type)\r\n    {\r\n      case NID::kCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case NID::kLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case NID::kLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadAndDecodePackedStreams(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    UInt64 baseOffset, \r\n    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  CRecordVector<UInt64> packSizes;\r\n  CRecordVector<bool> packCRCsDefined;\r\n  CRecordVector<UInt32> packCRCs;\r\n  CObjectVector<CFolder> folders;\r\n  \r\n  CRecordVector<CNum> numUnPackStreamsInFolders;\r\n  CRecordVector<UInt64> unPackSizes;\r\n  CRecordVector<bool> digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  ReadStreamsInfo(NULL, \r\n    dataOffset,\r\n    packSizes, \r\n    packCRCsDefined, \r\n    packCRCs, \r\n    folders,\r\n    numUnPackStreamsInFolders,\r\n    unPackSizes,\r\n    digestsDefined, \r\n    digests);\r\n  \r\n  // database.ArchiveInfo.DataStartPosition2 += database.ArchiveInfo.StartPositionAfterHeader;\r\n  \r\n  CNum packIndex = 0;\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  UInt64 dataStartPos = baseOffset + dataOffset;\r\n  for(int i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    dataVector.Add(CByteBuffer());\r\n    CByteBuffer &data = dataVector.Back();\r\n    UInt64 unPackSize64 = folder.GetUnPackSize();\r\n    size_t unPackSize = (size_t)unPackSize64;\r\n    if (unPackSize != unPackSize64)\r\n      ThrowUnsupported();\r\n    data.SetCapacity(unPackSize);\r\n    \r\n    CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    outStreamSpec->Init(data, unPackSize);\r\n    \r\n    HRESULT result = decoder.Decode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      _stream, dataStartPos, \r\n      &packSizes[packIndex], folder, outStream, NULL\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , false, 1\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    \r\n    if (folder.UnPackCRCDefined)\r\n      if (CrcCalc(data, unPackSize) != folder.UnPackCRC)\r\n        ThrowIncorrect();\r\n      for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n        dataStartPos += packSizes[packIndex++];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CInArchive::ReadHeader(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &database\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  UInt64 type = ReadID();\r\n\r\n  if (type == NID::kArchiveProperties)\r\n  {\r\n    ReadArchiveProperties(database.ArchiveInfo);\r\n    type = ReadID();\r\n  }\r\n \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  if (type == NID::kAdditionalStreamsInfo)\r\n  {\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        database.ArchiveInfo.StartPositionAfterHeader, \r\n        database.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    database.ArchiveInfo.DataStartPosition2 += database.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n\r\n  CRecordVector<UInt64> unPackSizes;\r\n  CRecordVector<bool> digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  if (type == NID::kMainStreamsInfo)\r\n  {\r\n    ReadStreamsInfo(&dataVector,\r\n        database.ArchiveInfo.DataStartPosition,\r\n        database.PackSizes, \r\n        database.PackCRCsDefined, \r\n        database.PackCRCs, \r\n        database.Folders,\r\n        database.NumUnPackStreamsVector,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    database.ArchiveInfo.DataStartPosition += database.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n  else\r\n  {\r\n    for(int i = 0; i < database.Folders.Size(); i++)\r\n    {\r\n      database.NumUnPackStreamsVector.Add(1);\r\n      CFolder &folder = database.Folders[i];\r\n      unPackSizes.Add(folder.GetUnPackSize());\r\n      digestsDefined.Add(folder.UnPackCRCDefined);\r\n      digests.Add(folder.UnPackCRC);\r\n    }\r\n  }\r\n\r\n  database.Files.Clear();\r\n\r\n  if (type == NID::kEnd)\r\n    return S_OK;\r\n  if (type != NID::kFilesInfo)\r\n    ThrowIncorrect();\r\n  \r\n  CNum numFiles = ReadNum();\r\n  database.Files.Reserve(numFiles);\r\n  CNum i;\r\n  for(i = 0; i < numFiles; i++)\r\n    database.Files.Add(CFileItem());\r\n\r\n  database.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);\r\n  if (!database.PackSizes.IsEmpty())\r\n    database.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);\r\n  if (numFiles > 0  && !digests.IsEmpty())\r\n    database.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);\r\n\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve((int)numFiles);\r\n  for(i = 0; i < numFiles; i++)\r\n    emptyStreamVector.Add(false);\r\n  CBoolVector emptyFileVector;\r\n  CBoolVector antiFileVector;\r\n  CNum numEmptyStreams = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    UInt64 size = ReadNumber();\r\n    bool isKnownType = true;\r\n    if (type > ((UInt32)1 << 30))\r\n      isKnownType = false;\r\n    else switch((UInt32)type)\r\n    {\r\n      case NID::kName:\r\n      {\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for(int i = 0; i < database.Files.Size(); i++)\r\n          _inByteBack->ReadString(database.Files[i].Name);\r\n        break;\r\n      }\r\n      case NID::kWinAttributes:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(database.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for(i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = database.Files[i];\r\n          file.AreAttributesDefined = boolVector[i];\r\n          if (file.AreAttributesDefined)\r\n            file.Attributes = ReadUInt32();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kStartPos:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(database.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for(i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = database.Files[i];\r\n          file.IsStartPosDefined = boolVector[i];\r\n          if (file.IsStartPosDefined)\r\n            file.StartPos = ReadUInt64();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyStream:\r\n      {\r\n        ReadBoolVector(numFiles, emptyStreamVector);\r\n        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)\r\n          if (emptyStreamVector[i])\r\n            numEmptyStreams++;\r\n        emptyFileVector.Reserve(numEmptyStreams);\r\n        antiFileVector.Reserve(numEmptyStreams);\r\n        for (i = 0; i < numEmptyStreams; i++)\r\n        {\r\n          emptyFileVector.Add(false);\r\n          antiFileVector.Add(false);\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyFile:\r\n      {\r\n        ReadBoolVector(numEmptyStreams, emptyFileVector);\r\n        break;\r\n      }\r\n      case NID::kAnti:\r\n      {\r\n        ReadBoolVector(numEmptyStreams, antiFileVector);\r\n        break;\r\n      }\r\n      case NID::kCreationTime:\r\n      case NID::kLastWriteTime:\r\n      case NID::kLastAccessTime:\r\n      {\r\n        ReadTime(dataVector, database.Files, (UInt32)type);\r\n        break;\r\n      }\r\n      default:\r\n        isKnownType = false;\r\n    }\r\n    if (isKnownType)\r\n      database.ArchiveInfo.FileInfoPopIDs.Add(type);\r\n    else\r\n      SkeepData(size);\r\n  }\r\n\r\n  CNum emptyFileIndex = 0;\r\n  CNum sizeIndex = 0;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    CFileItem &file = database.Files[i];\r\n    file.HasStream = !emptyStreamVector[i];\r\n    if(file.HasStream)\r\n    {\r\n      file.IsDirectory = false;\r\n      file.IsAnti = false;\r\n      file.UnPackSize = unPackSizes[sizeIndex];\r\n      file.FileCRC = digests[sizeIndex];\r\n      file.IsFileCRCDefined = digestsDefined[sizeIndex];\r\n      sizeIndex++;\r\n    }\r\n    else\r\n    {\r\n      file.IsDirectory = !emptyFileVector[emptyFileIndex];\r\n      file.IsAnti = antiFileVector[emptyFileIndex];\r\n      emptyFileIndex++;\r\n      file.UnPackSize = 0;\r\n      file.IsFileCRCDefined = false;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartPackStream()\r\n{\r\n  FolderStartPackStreamIndex.Clear();\r\n  FolderStartPackStreamIndex.Reserve(Folders.Size());\r\n  CNum startPos = 0;\r\n  for(int i = 0; i < Folders.Size(); i++)\r\n  {\r\n    FolderStartPackStreamIndex.Add(startPos);\r\n    startPos += (CNum)Folders[i].PackStreams.Size();\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillStartPos()\r\n{\r\n  PackStreamStartPositions.Clear();\r\n  PackStreamStartPositions.Reserve(PackSizes.Size());\r\n  UInt64 startPos = 0;\r\n  for(int i = 0; i < PackSizes.Size(); i++)\r\n  {\r\n    PackStreamStartPositions.Add(startPos);\r\n    startPos += PackSizes[i];\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartFileIndex()\r\n{\r\n  FolderStartFileIndex.Clear();\r\n  FolderStartFileIndex.Reserve(Folders.Size());\r\n  FileIndexToFolderIndexMap.Clear();\r\n  FileIndexToFolderIndexMap.Reserve(Files.Size());\r\n  \r\n  int folderIndex = 0;\r\n  CNum indexInFolder = 0;\r\n  for (int i = 0; i < Files.Size(); i++)\r\n  {\r\n    const CFileItem &file = Files[i];\r\n    bool emptyStream = !file.HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      FileIndexToFolderIndexMap.Add(kNumNoIndex);\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      // v3.13 incorrectly worked with empty folders\r\n      // v4.07: Loop for skipping empty folders\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= Folders.Size())\r\n          ThrowIncorrect();\r\n        FolderStartFileIndex.Add(i); // check it\r\n        if (NumUnPackStreamsVector[folderIndex] != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    FileIndexToFolderIndexMap.Add(folderIndex);\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= NumUnPackStreamsVector[folderIndex])\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &database\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  database.Clear();\r\n  database.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n\r\n  database.ArchiveInfo.Version.Major = _header[6];\r\n  database.ArchiveInfo.Version.Minor = _header[7];\r\n\r\n  if (database.ArchiveInfo.Version.Major != kMajorVersion)\r\n    ThrowUnsupportedVersion();\r\n\r\n  UInt32 crcFromArchive = GetUInt32FromMem(_header + 8);\r\n  UInt64 nextHeaderOffset = GetUInt64FromMem(_header + 0xC);\r\n  UInt64 nextHeaderSize = GetUInt64FromMem(_header + 0x14);\r\n  UInt32 nextHeaderCRC =  GetUInt32FromMem(_header + 0x1C);\r\n  UInt32 crc = CrcCalc(_header + 0xC, 20);\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)\r\n  {\r\n    UInt64 cur, cur2;\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));\r\n    const int kCheckSize = 500;\r\n    Byte buf[kCheckSize];\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));\r\n    int checkSize = kCheckSize;\r\n    if (cur2 - cur < kCheckSize)\r\n      checkSize = (int)(cur2 - cur);\r\n    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));\r\n    \r\n    UInt32 realProcessedSize;\r\n    RINOK(_stream->Read(buf, (UInt32)kCheckSize, &realProcessedSize));\r\n\r\n    int i;\r\n    for (i = (int)realProcessedSize - 2; i >= 0; i--)\r\n      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)\r\n        break;\r\n    if (i < 0)\r\n      return S_FALSE;\r\n    nextHeaderSize = realProcessedSize - i;\r\n    nextHeaderOffset = cur2 - cur + i;\r\n    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);\r\n    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));\r\n  }\r\n  #endif\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  crcFromArchive = crc;\r\n  #endif\r\n\r\n  database.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;\r\n\r\n  if (crc != crcFromArchive)\r\n    ThrowIncorrect();\r\n\r\n  if (nextHeaderSize == 0)\r\n    return S_OK;\r\n\r\n  if (nextHeaderSize > (UInt64)0xFFFFFFFF)\r\n    return S_FALSE;\r\n\r\n  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));\r\n\r\n  CByteBuffer buffer2;\r\n  buffer2.SetCapacity((size_t)nextHeaderSize);\r\n\r\n  UInt32 realProcessedSize;\r\n  RINOK(_stream->Read(buffer2, (UInt32)nextHeaderSize, &realProcessedSize));\r\n  if (realProcessedSize != (UInt32)nextHeaderSize)\r\n    return S_FALSE;\r\n  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)\r\n    ThrowIncorrect();\r\n  \r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, buffer2);\r\n  \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kHeader)\r\n      break;\r\n    if (type != NID::kEncodedHeader)\r\n      ThrowIncorrect();\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        database.ArchiveInfo.StartPositionAfterHeader, \r\n        database.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    if (dataVector.Size() == 0)\r\n      return S_OK;\r\n    if (dataVector.Size() > 1)\r\n      ThrowIncorrect();\r\n    streamSwitch.Remove();\r\n    streamSwitch.Set(this, dataVector.Front());\r\n  }\r\n\r\n  return ReadHeader(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    database\r\n    #ifndef _NO_CRYPTO\r\n    , getTextPassword\r\n    #endif\r\n    );\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &database\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword\r\n    #endif\r\n    )\r\n{\r\n  try\r\n  {\r\n    return ReadDatabase2(\r\n      EXTERNAL_CODECS_LOC_VARS database\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword\r\n      #endif\r\n      );\r\n  }\r\n  catch(CInArchiveException &) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zIn.h",
    "content": "// 7zIn.h\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/InBuffer.h\"\r\n\r\n#include \"7zItem.h\"\r\n \r\nnamespace NArchive {\r\nnamespace N7z {\r\n  \r\nstruct CInArchiveInfo\r\n{\r\n  CArchiveVersion Version;\r\n  UInt64 StartPosition;\r\n  UInt64 StartPositionAfterHeader;\r\n  UInt64 DataStartPosition;\r\n  UInt64 DataStartPosition2;\r\n  CRecordVector<UInt64> FileInfoPopIDs;\r\n  void Clear()\r\n  {\r\n    FileInfoPopIDs.Clear();\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabaseEx: public CArchiveDatabase\r\n{\r\n  CInArchiveInfo ArchiveInfo;\r\n  CRecordVector<UInt64> PackStreamStartPositions;\r\n  CRecordVector<CNum> FolderStartPackStreamIndex;\r\n  CRecordVector<CNum> FolderStartFileIndex;\r\n  CRecordVector<CNum> FileIndexToFolderIndexMap;\r\n\r\n  void Clear()\r\n  {\r\n    CArchiveDatabase::Clear();\r\n    ArchiveInfo.Clear();\r\n    PackStreamStartPositions.Clear();\r\n    FolderStartPackStreamIndex.Clear();\r\n    FolderStartFileIndex.Clear();\r\n    FileIndexToFolderIndexMap.Clear();\r\n  }\r\n\r\n  void FillFolderStartPackStream();\r\n  void FillStartPos();\r\n  void FillFolderStartFileIndex();\r\n\r\n  void Fill()\r\n  {\r\n    FillFolderStartPackStream();\r\n    FillStartPos();\r\n    FillFolderStartFileIndex();\r\n  }\r\n  \r\n  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const\r\n  {\r\n    return ArchiveInfo.DataStartPosition +\r\n        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n  }\r\n  \r\n  UInt64 GetFolderFullPackSize(int folderIndex) const \r\n  {\r\n    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];\r\n    const CFolder &folder = Folders[folderIndex];\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < folder.PackStreams.Size(); i++)\r\n      size += PackSizes[packStreamIndex + i];\r\n    return size;\r\n  }\r\n  \r\n  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n  {\r\n    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n  }\r\n\r\n  UInt64 GetFilePackSize(CNum fileIndex) const\r\n  {\r\n    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n    if (folderIndex != kNumNoIndex)\r\n      if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n        return GetFolderFullPackSize(folderIndex);\r\n    return 0;\r\n  }\r\n};\r\n\r\nclass CInByte2\r\n{\r\n  const Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  void Init(const Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  Byte ReadByte();\r\n  void ReadBytes(Byte *data, size_t size);\r\n  void SkeepData(UInt64 size);\r\n  void SkeepData();\r\n  UInt64 ReadNumber();\r\n  CNum ReadNum();\r\n  UInt32 ReadUInt32();\r\n  UInt64 ReadUInt64();\r\n  void ReadString(UString &s);\r\n};\r\n\r\nclass CStreamSwitch;\r\n\r\nconst UInt32 kHeaderSize = 32;\r\n\r\nclass CInArchive\r\n{\r\n  friend class CStreamSwitch;\r\n\r\n  CMyComPtr<IInStream> _stream;\r\n\r\n  CObjectVector<CInByte2> _inByteVector;\r\n  CInByte2 *_inByteBack;\r\n \r\n  UInt64 _arhiveBeginStreamPosition;\r\n\r\n  Byte _header[kHeaderSize];\r\n\r\n  void AddByteStream(const Byte *buffer, size_t size)\r\n  {\r\n    _inByteVector.Add(CInByte2());\r\n    _inByteBack = &_inByteVector.Back();\r\n    _inByteBack->Init(buffer, size);\r\n  }\r\n  \r\n  void DeleteByteStream()\r\n  {\r\n    _inByteVector.DeleteBack();\r\n    if (!_inByteVector.IsEmpty())\r\n      _inByteBack = &_inByteVector.Back();\r\n  }\r\n\r\nprivate:\r\n  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);\r\n  \r\n  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }\r\n  Byte ReadByte() { return _inByteBack->ReadByte(); }\r\n  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }\r\n  CNum ReadNum() { return _inByteBack->ReadNum(); }\r\n  UInt64 ReadID() { return _inByteBack->ReadNumber(); }\r\n  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }\r\n  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }\r\n  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }\r\n  void SkeepData() { _inByteBack->SkeepData(); }\r\n  void WaitAttribute(UInt64 attribute);\r\n\r\n  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);\r\n  void GetNextFolderItem(CFolder &itemInfo);\r\n  void ReadHashDigests(int numItems,\r\n      CRecordVector<bool> &digestsDefined, CRecordVector<UInt32> &digests);\r\n  \r\n  void ReadPackInfo(\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CRecordVector<bool> &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs);\r\n  \r\n  void ReadUnPackInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      CObjectVector<CFolder> &folders);\r\n  \r\n  void ReadSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      CRecordVector<UInt64> &unPackSizes,\r\n      CRecordVector<bool> &digestsDefined, \r\n      CRecordVector<UInt32> &digests);\r\n\r\n  void ReadStreamsInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CRecordVector<bool> &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs,\r\n      CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      CRecordVector<UInt64> &unPackSizes,\r\n      CRecordVector<bool> &digestsDefined, \r\n      CRecordVector<UInt32> &digests);\r\n\r\n\r\n  void ReadBoolVector(int numItems, CBoolVector &v);\r\n  void ReadBoolVector2(int numItems, CBoolVector &v);\r\n  void ReadTime(const CObjectVector<CByteBuffer> &dataVector,\r\n      CObjectVector<CFileItem> &files, UInt32 type);\r\n  HRESULT ReadAndDecodePackedStreams(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      UInt64 baseOffset, UInt64 &dataOffset,\r\n      CObjectVector<CByteBuffer> &dataVector\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\n  HRESULT ReadHeader(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &database\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\n  HRESULT ReadDatabase2(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &database \r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\npublic:\r\n  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive\r\n  void Close();\r\n\r\n  HRESULT ReadDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &database \r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword\r\n      #endif\r\n      );\r\n};\r\n  \r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zItem.h",
    "content": "// 7zItem.h\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../Common/MethodId.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\ntypedef UInt32 CNum;\r\nconst CNum kNumMax     = 0x7FFFFFFF;\r\nconst CNum kNumNoIndex = 0xFFFFFFFF;\r\n\r\nstruct CCoderInfo\r\n{\r\n  CMethodId MethodID;\r\n  CByteBuffer Properties;\r\n  CNum NumInStreams;\r\n  CNum NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBindPair\r\n{\r\n  CNum InIndex;\r\n  CNum OutIndex;\r\n};\r\n\r\nstruct CFolder\r\n{\r\n  CObjectVector<CCoderInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<CNum> PackStreams;\r\n  CRecordVector<UInt64> UnPackSizes;\r\n  UInt32 UnPackCRC;\r\n  bool UnPackCRCDefined;\r\n\r\n  CFolder(): UnPackCRCDefined(false) {}\r\n\r\n  UInt64 GetUnPackSize() const // test it\r\n  { \r\n    if (UnPackSizes.IsEmpty())\r\n      return 0;\r\n    for (int i = UnPackSizes.Size() - 1; i >= 0; i--)\r\n      if (FindBindPairForOutStream(i) < 0)\r\n        return UnPackSizes[i];\r\n    throw 1;\r\n  }\r\n\r\n  CNum GetNumOutStreams() const\r\n  {\r\n    CNum result = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n      result += Coders[i].NumOutStreams;\r\n    return result;\r\n  }\r\n\r\n  int FindBindPairForInStream(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBindPairForOutStream(CNum outStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindPackStreamArrayIndex(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < PackStreams.Size(); i++)\r\n      if (PackStreams[i] == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n};\r\n\r\ntypedef FILETIME CArchiveFileTime;\r\n\r\nclass CFileItem\r\n{\r\npublic:\r\n  CArchiveFileTime CreationTime;\r\n  CArchiveFileTime LastWriteTime;\r\n  CArchiveFileTime LastAccessTime;\r\n  UInt64 UnPackSize;\r\n  UInt64 StartPos;\r\n  UInt32 Attributes;\r\n  UInt32 FileCRC;\r\n  UString Name;\r\n\r\n  bool HasStream; // Test it !!! it means that there is \r\n                  // stream in some folder. It can be empty stream\r\n  bool IsDirectory;\r\n  bool IsAnti;\r\n  bool IsFileCRCDefined;\r\n  bool AreAttributesDefined;\r\n  bool IsCreationTimeDefined;\r\n  bool IsLastWriteTimeDefined;\r\n  bool IsLastAccessTimeDefined;\r\n  bool IsStartPosDefined;\r\n\r\n  /*\r\n  const bool HasStream() const { \r\n      return !IsDirectory && !IsAnti && UnPackSize != 0; }\r\n  */\r\n  CFileItem(): \r\n    HasStream(true),\r\n    IsDirectory(false),\r\n    IsAnti(false),\r\n    IsFileCRCDefined(false),\r\n    AreAttributesDefined(false), \r\n    IsCreationTimeDefined(false), \r\n    IsLastWriteTimeDefined(false), \r\n    IsLastAccessTimeDefined(false),\r\n    IsStartPosDefined(false)\r\n      {}\r\n  void SetAttributes(UInt32 attributes) \r\n  { \r\n    AreAttributesDefined = true;\r\n    Attributes = attributes;\r\n  }\r\n  void SetCreationTime(const CArchiveFileTime &creationTime) \r\n  { \r\n    IsCreationTimeDefined = true;\r\n    CreationTime = creationTime;\r\n  }\r\n  void SetLastWriteTime(const CArchiveFileTime &lastWriteTime) \r\n  {\r\n    IsLastWriteTimeDefined = true;\r\n    LastWriteTime = lastWriteTime;\r\n  }\r\n  void SetLastAccessTime(const CArchiveFileTime &lastAccessTime) \r\n  { \r\n    IsLastAccessTimeDefined = true;\r\n    LastAccessTime = lastAccessTime;\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabase\r\n{\r\n  CRecordVector<UInt64> PackSizes;\r\n  CRecordVector<bool> PackCRCsDefined;\r\n  CRecordVector<UInt32> PackCRCs;\r\n  CObjectVector<CFolder> Folders;\r\n  CRecordVector<CNum> NumUnPackStreamsVector;\r\n  CObjectVector<CFileItem> Files;\r\n  void Clear()\r\n  {\r\n    PackSizes.Clear();\r\n    PackCRCsDefined.Clear();\r\n    PackCRCs.Clear();\r\n    Folders.Clear();\r\n    NumUnPackStreamsVector.Clear();\r\n    Files.Clear();\r\n  }\r\n  bool IsEmpty() const\r\n  {\r\n    return (PackSizes.IsEmpty() && \r\n      PackCRCsDefined.IsEmpty() && \r\n      PackCRCs.IsEmpty() && \r\n      Folders.IsEmpty() && \r\n      NumUnPackStreamsVector.IsEmpty() && \r\n      Files.IsEmpty());\r\n  }\r\n  bool IsSolid() const\r\n  {\r\n    for (int i = 0; i < NumUnPackStreamsVector.Size(); i++)\r\n      if (NumUnPackStreamsVector[i] > 1)\r\n        return true;\r\n    return false;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zOut.cpp",
    "content": "// 7zOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/AutoPtr.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zOut.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nstatic HRESULT WriteBytes(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size > 0)\r\n  {\r\n    UInt32 curSize = (UInt32)MyMin(size, (size_t)0xFFFFFFFF);\r\n    UInt32 processedSize;\r\n    RINOK(stream->Write(data, curSize, &processedSize));\r\n    if(processedSize == 0)\r\n      return E_FAIL;\r\n    data = (const void *)((const Byte *)data + processedSize);\r\n    size -= processedSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nHRESULT COutArchive::WriteDirect(const void *data, UInt32 size)\r\n{\r\n  return ::WriteBytes(SeqStream, data, size);\r\n}\r\n\r\nUInt32 CrcUpdateUInt32(UInt32 crc, UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++, value >>= 8)\r\n    crc = CRC_UPDATE_BYTE(crc, (Byte)value);\r\n  return crc;\r\n}\r\n\r\nUInt32 CrcUpdateUInt64(UInt32 crc, UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++, value >>= 8)\r\n    crc = CRC_UPDATE_BYTE(crc, (Byte)value);\r\n  return crc;\r\n}\r\n\r\nHRESULT COutArchive::WriteDirectUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    RINOK(WriteDirectByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteDirectUInt64(UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    RINOK(WriteDirectByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteSignature()\r\n{\r\n  RINOK(WriteDirect(kSignature, kSignatureSize));\r\n  RINOK(WriteDirectByte(kMajorVersion));\r\n  return WriteDirectByte(2);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishSignature()\r\n{\r\n  RINOK(WriteDirect(kFinishSignature, kSignatureSize));\r\n  CArchiveVersion av;\r\n  av.Major = kMajorVersion;\r\n  av.Minor = 2;\r\n  RINOK(WriteDirectByte(av.Major));\r\n  return WriteDirectByte(av.Minor);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::WriteStartHeader(const CStartHeader &h)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;\r\n  crc = CrcUpdateUInt64(crc, h.NextHeaderOffset);\r\n  crc = CrcUpdateUInt64(crc, h.NextHeaderSize);\r\n  crc = CrcUpdateUInt32(crc, h.NextHeaderCRC);\r\n  RINOK(WriteDirectUInt32(CRC_GET_DIGEST(crc)));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  return WriteDirectUInt32(h.NextHeaderCRC);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)\r\n{\r\n  CCRC crc;\r\n  crc.UpdateUInt64(h.NextHeaderOffset);\r\n  crc.UpdateUInt64(h.NextHeaderSize);\r\n  crc.UpdateUInt32(h.NextHeaderCRC);\r\n  crc.UpdateUInt64(h.ArchiveStartOffset);\r\n  crc.UpdateUInt64(h.AdditionalStartBlockSize);\r\n  RINOK(WriteDirectUInt32(crc.GetDigest()));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  RINOK(WriteDirectUInt32(h.NextHeaderCRC));\r\n  RINOK(WriteDirectUInt64(h.ArchiveStartOffset));\r\n  return WriteDirectUInt64(h.AdditionalStartBlockSize);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)\r\n{\r\n  Close();\r\n  #ifdef _7Z_VOL\r\n  // endMarker = false;\r\n  _endMarker = endMarker;\r\n  #endif\r\n  SeqStream = stream;\r\n  if (!endMarker)\r\n  {\r\n    SeqStream.QueryInterface(IID_IOutStream, &Stream);\r\n    if (!Stream)\r\n    {\r\n      return E_NOTIMPL;\r\n      // endMarker = true;\r\n    }\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (endMarker)\r\n  {\r\n    /*\r\n    CStartHeader sh;\r\n    sh.NextHeaderOffset = (UInt32)(Int32)-1;\r\n    sh.NextHeaderSize = (UInt32)(Int32)-1;\r\n    sh.NextHeaderCRC = 0;\r\n    WriteStartHeader(sh);\r\n    */\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!Stream)\r\n      return E_FAIL;\r\n    RINOK(WriteSignature());\r\n    RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutArchive::Close()\r\n{\r\n  SeqStream.Release();\r\n  Stream.Release();\r\n}\r\n\r\nHRESULT COutArchive::SkeepPrefixArchiveHeader()\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n    return S_OK;\r\n  #endif\r\n  return Stream->Seek(24, STREAM_SEEK_CUR, NULL);\r\n}\r\n\r\nHRESULT COutArchive::WriteBytes(const void *data, size_t size)\r\n{\r\n  if (_mainMode)\r\n  {\r\n    if (_dynamicMode)\r\n      _dynamicBuffer.Write(data, size);\r\n    else\r\n      _outByte.WriteBytes(data, size);\r\n    _crc = CrcUpdate(_crc, data, size);\r\n  }\r\n  else\r\n  {\r\n    if (_countMode)\r\n      _countSize += size;\r\n    else\r\n      RINOK(_outByte2.Write(data, size));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteBytes(const CByteBuffer &data)\r\n{\r\n  return WriteBytes(data, data.GetCapacity());\r\n}\r\n\r\nHRESULT COutArchive::WriteByte(Byte b)\r\n{\r\n  return WriteBytes(&b, 1);\r\n}\r\n\r\nHRESULT COutArchive::WriteUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    RINOK(WriteByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteNumber(UInt64 value)\r\n{\r\n  Byte firstByte = 0;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n    {\r\n      firstByte |= Byte(value >> (8 * i));\r\n      break;\r\n    }\r\n    firstByte |= mask;\r\n    mask >>= 1;\r\n  }\r\n  RINOK(WriteByte(firstByte));\r\n  for (;i > 0; i--)\r\n  {\r\n    RINOK(WriteByte((Byte)value));\r\n    value >>= 8;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nstatic UInt32 GetBigNumberSize(UInt64 value)\r\n{\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n      break;\r\n  return 1 + i;\r\n}\r\n\r\nUInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)\r\n{\r\n  UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;\r\n  if (nameLength != 0)\r\n  {\r\n    nameLength = (nameLength + 1) * 2;\r\n    result += nameLength + GetBigNumberSize(nameLength) + 2;\r\n  }\r\n  if (props)\r\n  {\r\n    result += 20;\r\n  }\r\n  if (result >= 128)\r\n    result++;\r\n  result += kSignatureSize + 2 + kFinishHeaderSize;\r\n  return result;\r\n}\r\n\r\nUInt64 COutArchive::GetVolPureSize(UInt64 volSize, int nameLength, bool props)\r\n{\r\n  UInt32 headersSizeBase = COutArchive::GetVolHeadersSize(1, nameLength, props);\r\n  int testSize;\r\n  if (volSize > headersSizeBase)\r\n    testSize = volSize - headersSizeBase;\r\n  else\r\n    testSize = 1;\r\n  UInt32 headersSize = COutArchive::GetVolHeadersSize(testSize, nameLength, props);\r\n  UInt64 pureSize = 1;\r\n  if (volSize > headersSize)\r\n    pureSize = volSize - headersSize;\r\n  return pureSize;\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::WriteFolder(const CFolder &folder)\r\n{\r\n  RINOK(WriteNumber(folder.Coders.Size()));\r\n  int i;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    const CCoderInfo &coder = folder.Coders[i];\r\n    {\r\n      size_t propertiesSize = coder.Properties.GetCapacity();\r\n      \r\n      UInt64 id = coder.MethodID; \r\n      int idSize;\r\n      for (idSize = 1; idSize < sizeof(id); idSize++)\r\n        if ((id >> (8 * idSize)) == 0)\r\n          break;\r\n      BYTE longID[15];\r\n      for (int t = idSize - 1; t >= 0 ; t--, id >>= 8)\r\n        longID[t] = (Byte)(id & 0xFF);\r\n      Byte b;\r\n      b = (Byte)(idSize & 0xF);\r\n      bool isComplex = !coder.IsSimpleCoder();\r\n      b |= (isComplex ? 0x10 : 0);\r\n      b |= ((propertiesSize != 0) ? 0x20 : 0 );\r\n      RINOK(WriteByte(b));\r\n      RINOK(WriteBytes(longID, idSize));\r\n      if (isComplex)\r\n      {\r\n        RINOK(WriteNumber(coder.NumInStreams));\r\n        RINOK(WriteNumber(coder.NumOutStreams));\r\n      }\r\n      if (propertiesSize == 0)\r\n        continue;\r\n      RINOK(WriteNumber(propertiesSize));\r\n      RINOK(WriteBytes(coder.Properties, propertiesSize));\r\n    }\r\n  }\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = folder.BindPairs[i];\r\n    RINOK(WriteNumber(bindPair.InIndex));\r\n    RINOK(WriteNumber(bindPair.OutIndex));\r\n  }\r\n  if (folder.PackStreams.Size() > 1)\r\n    for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    {\r\n      RINOK(WriteNumber(folder.PackStreams[i]));\r\n    }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WriteBoolVector(const CBoolVector &boolVector)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0x80;\r\n  for(int i = 0; i < boolVector.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n      b |= mask;\r\n    mask >>= 1;\r\n    if (mask == 0)\r\n    {\r\n      RINOK(WriteByte(b));\r\n      mask = 0x80;\r\n      b = 0;\r\n    }\r\n  }\r\n  if (mask != 0x80)\r\n  {\r\n    RINOK(WriteByte(b));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nHRESULT COutArchive::WriteHashDigests(\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  int numDefined = 0;\r\n  int i;\r\n  for(i = 0; i < digestsDefined.Size(); i++)\r\n    if (digestsDefined[i])\r\n      numDefined++;\r\n  if (numDefined == 0)\r\n    return S_OK;\r\n\r\n  RINOK(WriteByte(NID::kCRC));\r\n  if (numDefined == digestsDefined.Size())\r\n  {\r\n    RINOK(WriteByte(1));\r\n  }\r\n  else\r\n  {\r\n    RINOK(WriteByte(0));\r\n    RINOK(WriteBoolVector(digestsDefined));\r\n  }\r\n  for(i = 0; i < digests.Size(); i++)\r\n  {\r\n    if(digestsDefined[i])\r\n      RINOK(WriteUInt32(digests[i]));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::WritePackInfo(\r\n    UInt64 dataOffset,\r\n    const CRecordVector<UInt64> &packSizes,\r\n    const CRecordVector<bool> &packCRCsDefined,\r\n    const CRecordVector<UInt32> &packCRCs)\r\n{\r\n  if (packSizes.IsEmpty())\r\n    return S_OK;\r\n  RINOK(WriteByte(NID::kPackInfo));\r\n  RINOK(WriteNumber(dataOffset));\r\n  RINOK(WriteNumber(packSizes.Size()));\r\n  RINOK(WriteByte(NID::kSize));\r\n  for(int i = 0; i < packSizes.Size(); i++)\r\n    RINOK(WriteNumber(packSizes[i]));\r\n\r\n  RINOK(WriteHashDigests(packCRCsDefined, packCRCs));\r\n  \r\n  return WriteByte(NID::kEnd);\r\n}\r\n\r\nHRESULT COutArchive::WriteUnPackInfo(const CObjectVector<CFolder> &folders)\r\n{\r\n  if (folders.IsEmpty())\r\n    return S_OK;\r\n\r\n  RINOK(WriteByte(NID::kUnPackInfo));\r\n\r\n  RINOK(WriteByte(NID::kFolder));\r\n  RINOK(WriteNumber(folders.Size()));\r\n  {\r\n    RINOK(WriteByte(0));\r\n    for(int i = 0; i < folders.Size(); i++)\r\n      RINOK(WriteFolder(folders[i]));\r\n  }\r\n  \r\n  RINOK(WriteByte(NID::kCodersUnPackSize));\r\n  int i;\r\n  for(i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    for (int j = 0; j < folder.UnPackSizes.Size(); j++)\r\n      RINOK(WriteNumber(folder.UnPackSizes[j]));\r\n  }\r\n\r\n  CRecordVector<bool> unPackCRCsDefined;\r\n  CRecordVector<UInt32> unPackCRCs;\r\n  for(i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    unPackCRCsDefined.Add(folder.UnPackCRCDefined);\r\n    unPackCRCs.Add(folder.UnPackCRC);\r\n  }\r\n  RINOK(WriteHashDigests(unPackCRCsDefined, unPackCRCs));\r\n\r\n  return WriteByte(NID::kEnd);\r\n}\r\n\r\nHRESULT COutArchive::WriteSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    const CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n    const CRecordVector<UInt64> &unPackSizes,\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  RINOK(WriteByte(NID::kSubStreamsInfo));\r\n\r\n  int i;\r\n  for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n  {\r\n    if (numUnPackStreamsInFolders[i] != 1)\r\n    {\r\n      RINOK(WriteByte(NID::kNumUnPackStream));\r\n      for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n        RINOK(WriteNumber(numUnPackStreamsInFolders[i]));\r\n      break;\r\n    }\r\n  }\r\n \r\n\r\n  bool needFlag = true;\r\n  CNum index = 0;\r\n  for(i = 0; i < numUnPackStreamsInFolders.Size(); i++)\r\n    for (CNum j = 0; j < numUnPackStreamsInFolders[i]; j++)\r\n    {\r\n      if (j + 1 != numUnPackStreamsInFolders[i])\r\n      {\r\n        if (needFlag)\r\n          RINOK(WriteByte(NID::kSize));\r\n        needFlag = false;\r\n        RINOK(WriteNumber(unPackSizes[index]));\r\n      }\r\n      index++;\r\n    }\r\n\r\n  CRecordVector<bool> digestsDefined2;\r\n  CRecordVector<UInt32> digests2;\r\n\r\n  int digestIndex = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    int numSubStreams = (int)numUnPackStreamsInFolders[i];\r\n    if (numSubStreams == 1 && folders[i].UnPackCRCDefined)\r\n      digestIndex++;\r\n    else\r\n      for (int j = 0; j < numSubStreams; j++, digestIndex++)\r\n      {\r\n        digestsDefined2.Add(digestsDefined[digestIndex]);\r\n        digests2.Add(digests[digestIndex]);\r\n      }\r\n  }\r\n  RINOK(WriteHashDigests(digestsDefined2, digests2));\r\n  return WriteByte(NID::kEnd);\r\n}\r\n\r\nHRESULT COutArchive::WriteTime(\r\n    const CObjectVector<CFileItem> &files, Byte type)\r\n{\r\n  /////////////////////////////////////////////////\r\n  // CreationTime\r\n  CBoolVector boolVector;\r\n  boolVector.Reserve(files.Size());\r\n  bool thereAreDefined = false;\r\n  bool allDefined = true;\r\n  int i;\r\n  for(i = 0; i < files.Size(); i++)\r\n  {\r\n    const CFileItem &item = files[i];\r\n    bool defined;\r\n    switch(type)\r\n    {\r\n      case NID::kCreationTime:\r\n        defined = item.IsCreationTimeDefined;\r\n        break;\r\n      case NID::kLastWriteTime:\r\n        defined = item.IsLastWriteTimeDefined;\r\n        break;\r\n      case NID::kLastAccessTime:\r\n        defined = item.IsLastAccessTimeDefined;\r\n        break;\r\n      default:\r\n        throw 1;\r\n    }\r\n    boolVector.Add(defined);\r\n    thereAreDefined = (thereAreDefined || defined);\r\n    allDefined = (allDefined && defined);\r\n  }\r\n  if (!thereAreDefined)\r\n    return S_OK;\r\n  RINOK(WriteByte(type));\r\n  size_t dataSize = 1 + 1;\r\n    dataSize += files.Size() * 8;\r\n  if (allDefined)\r\n  {\r\n    RINOK(WriteNumber(dataSize));\r\n    WriteByte(1);\r\n  }\r\n  else\r\n  {\r\n    RINOK(WriteNumber(1 + (boolVector.Size() + 7) / 8 + dataSize));\r\n    WriteByte(0);\r\n    RINOK(WriteBoolVector(boolVector));\r\n  }\r\n  RINOK(WriteByte(0));\r\n  for(i = 0; i < files.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n    {\r\n      const CFileItem &item = files[i];\r\n      CArchiveFileTime timeValue;\r\n      timeValue.dwLowDateTime = 0;\r\n      timeValue.dwHighDateTime = 0;\r\n      switch(type)\r\n      {\r\n        case NID::kCreationTime:\r\n          timeValue = item.CreationTime;\r\n          break;\r\n        case NID::kLastWriteTime:\r\n          timeValue = item.LastWriteTime;\r\n          break;\r\n        case NID::kLastAccessTime:\r\n          timeValue = item.LastAccessTime;\r\n          break;\r\n      }\r\n      RINOK(WriteUInt32(timeValue.dwLowDateTime));\r\n      RINOK(WriteUInt32(timeValue.dwHighDateTime));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const Byte *data, size_t dataSize,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  CSequentialInStreamImp *streamSpec = new CSequentialInStreamImp;\r\n  CMyComPtr<ISequentialInStream> stream = streamSpec;\r\n  streamSpec->Init(data, dataSize);\r\n  CFolder folderItem;\r\n  folderItem.UnPackCRCDefined = true;\r\n  folderItem.UnPackCRC = CrcCalc(data, dataSize);\r\n  UInt64 dataSize64 = dataSize;\r\n  RINOK(encoder.Encode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      stream, NULL, &dataSize64, folderItem, SeqStream, packSizes, NULL))\r\n  folders.Add(folderItem);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const CByteBuffer &data, \r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  return EncodeStream(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      encoder, data, data.GetCapacity(), packSizes, folders);\r\n}\r\n\r\nstatic void WriteUInt32ToBuffer(Byte *data, UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    *data++ = (Byte)value;\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nstatic void WriteUInt64ToBuffer(Byte *data, UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    *data++ = (Byte)value;\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\n\r\nHRESULT COutArchive::WriteHeader(\r\n    const CArchiveDatabase &database,\r\n    const CHeaderOptions &headerOptions,\r\n    UInt64 &headerOffset)\r\n{\r\n  int i;\r\n  \r\n  /////////////////////////////////\r\n  // Names\r\n\r\n  CNum numDefinedNames = 0;\r\n  size_t namesDataSize = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n  {\r\n    const UString &name = database.Files[i].Name;\r\n    if (!name.IsEmpty())\r\n      numDefinedNames++;\r\n    namesDataSize += (name.Length() + 1) * 2;\r\n  }\r\n\r\n  CByteBuffer namesData;\r\n  if (numDefinedNames > 0)\r\n  {\r\n    namesData.SetCapacity((size_t)namesDataSize);\r\n    size_t pos = 0;\r\n    for(int i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const UString &name = database.Files[i].Name;\r\n      for (int t = 0; t < name.Length(); t++)\r\n      {\r\n        wchar_t c = name[t];\r\n        namesData[pos++] = Byte(c);\r\n        namesData[pos++] = Byte(c >> 8);\r\n      }\r\n      namesData[pos++] = 0;\r\n      namesData[pos++] = 0;\r\n    }\r\n  }\r\n\r\n  /////////////////////////////////\r\n  // Write Attributes\r\n  CBoolVector attributesBoolVector;\r\n  attributesBoolVector.Reserve(database.Files.Size());\r\n  int numDefinedAttributes = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n  {\r\n    bool defined = database.Files[i].AreAttributesDefined;\r\n    attributesBoolVector.Add(defined);\r\n    if (defined)\r\n      numDefinedAttributes++;\r\n  }\r\n\r\n  CByteBuffer attributesData;\r\n  if (numDefinedAttributes > 0)\r\n  {\r\n    attributesData.SetCapacity(numDefinedAttributes * 4);\r\n    size_t pos = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (file.AreAttributesDefined)\r\n      {\r\n        WriteUInt32ToBuffer(attributesData + pos, file.Attributes);\r\n        pos += 4;\r\n      }\r\n    }\r\n  }\r\n\r\n  /////////////////////////////////\r\n  // Write StartPos\r\n  CBoolVector startsBoolVector;\r\n  startsBoolVector.Reserve(database.Files.Size());\r\n  int numDefinedStarts = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n  {\r\n    bool defined = database.Files[i].IsStartPosDefined;\r\n    startsBoolVector.Add(defined);\r\n    if (defined)\r\n      numDefinedStarts++;\r\n  }\r\n\r\n  CByteBuffer startsData;\r\n  if (numDefinedStarts > 0)\r\n  {\r\n    startsData.SetCapacity(numDefinedStarts * 8);\r\n    size_t pos = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (file.IsStartPosDefined)\r\n      {\r\n        WriteUInt64ToBuffer(startsData + pos, file.StartPos);\r\n        pos += 8;\r\n      }\r\n    }\r\n  }\r\n  \r\n  /////////////////////////////////\r\n  // Write Last Write Time\r\n  // /*\r\n  CNum numDefinedLastWriteTimes = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n    if (database.Files[i].IsLastWriteTimeDefined)\r\n      numDefinedLastWriteTimes++;\r\n\r\n  if (numDefinedLastWriteTimes > 0)\r\n  {\r\n    CByteBuffer lastWriteTimeData;\r\n    lastWriteTimeData.SetCapacity(numDefinedLastWriteTimes * 8);\r\n    size_t pos = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (file.IsLastWriteTimeDefined)\r\n      {\r\n        WriteUInt32ToBuffer(lastWriteTimeData + pos, file.LastWriteTime.dwLowDateTime);\r\n        pos += 4;\r\n        WriteUInt32ToBuffer(lastWriteTimeData + pos, file.LastWriteTime.dwHighDateTime);\r\n        pos += 4;\r\n      }\r\n    }\r\n  }\r\n  // */\r\n  \r\n\r\n  UInt64 packedSize = 0;\r\n  for(i = 0; i < database.PackSizes.Size(); i++)\r\n    packedSize += database.PackSizes[i];\r\n\r\n  headerOffset = packedSize;\r\n\r\n  _mainMode = true;\r\n\r\n  _outByte.SetStream(SeqStream);\r\n  _outByte.Init();\r\n  _crc = CRC_INIT_VAL;\r\n\r\n\r\n  RINOK(WriteByte(NID::kHeader));\r\n\r\n  // Archive Properties\r\n\r\n  if (database.Folders.Size() > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kMainStreamsInfo));\r\n    RINOK(WritePackInfo(0, database.PackSizes, \r\n        database.PackCRCsDefined,\r\n        database.PackCRCs));\r\n\r\n    RINOK(WriteUnPackInfo(database.Folders));\r\n\r\n    CRecordVector<UInt64> unPackSizes;\r\n    CRecordVector<bool> digestsDefined;\r\n    CRecordVector<UInt32> digests;\r\n    for (i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (!file.HasStream)\r\n        continue;\r\n      unPackSizes.Add(file.UnPackSize);\r\n      digestsDefined.Add(file.IsFileCRCDefined);\r\n      digests.Add(file.FileCRC);\r\n    }\r\n\r\n    RINOK(WriteSubStreamsInfo(\r\n        database.Folders,\r\n        database.NumUnPackStreamsVector,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests));\r\n    RINOK(WriteByte(NID::kEnd));\r\n  }\r\n\r\n  if (database.Files.IsEmpty())\r\n  {\r\n    RINOK(WriteByte(NID::kEnd));\r\n    return _outByte.Flush();\r\n  }\r\n\r\n  RINOK(WriteByte(NID::kFilesInfo));\r\n  RINOK(WriteNumber(database.Files.Size()));\r\n\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve(database.Files.Size());\r\n  int numEmptyStreams = 0;\r\n  for(i = 0; i < database.Files.Size(); i++)\r\n    if (database.Files[i].HasStream)\r\n      emptyStreamVector.Add(false);\r\n    else\r\n    {\r\n      emptyStreamVector.Add(true);\r\n      numEmptyStreams++;\r\n    }\r\n  if (numEmptyStreams > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kEmptyStream));\r\n    RINOK(WriteNumber((emptyStreamVector.Size() + 7) / 8));\r\n    RINOK(WriteBoolVector(emptyStreamVector));\r\n\r\n    CBoolVector emptyFileVector, antiVector;\r\n    emptyFileVector.Reserve(numEmptyStreams);\r\n    antiVector.Reserve(numEmptyStreams);\r\n    CNum numEmptyFiles = 0, numAntiItems = 0;\r\n    for(i = 0; i < database.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = database.Files[i];\r\n      if (!file.HasStream)\r\n      {\r\n        emptyFileVector.Add(!file.IsDirectory);\r\n        if (!file.IsDirectory)\r\n          numEmptyFiles++;\r\n        antiVector.Add(file.IsAnti);\r\n        if (file.IsAnti)\r\n          numAntiItems++;\r\n      }\r\n    }\r\n\r\n    if (numEmptyFiles > 0)\r\n    {\r\n      RINOK(WriteByte(NID::kEmptyFile));\r\n      RINOK(WriteNumber((emptyFileVector.Size() + 7) / 8));\r\n      RINOK(WriteBoolVector(emptyFileVector));\r\n    }\r\n\r\n    if (numAntiItems > 0)\r\n    {\r\n      RINOK(WriteByte(NID::kAnti));\r\n      RINOK(WriteNumber((antiVector.Size() + 7) / 8));\r\n      RINOK(WriteBoolVector(antiVector));\r\n    }\r\n  }\r\n\r\n  if (numDefinedNames > 0)\r\n  {\r\n    /////////////////////////////////////////////////\r\n    RINOK(WriteByte(NID::kName));\r\n    {\r\n      RINOK(WriteNumber(1 + namesData.GetCapacity()));\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBytes(namesData));\r\n    }\r\n\r\n  }\r\n\r\n  if (headerOptions.WriteCreated)\r\n  {\r\n    RINOK(WriteTime(database.Files, NID::kCreationTime));\r\n  }\r\n  if (headerOptions.WriteModified)\r\n  {\r\n    RINOK(WriteTime(database.Files, NID::kLastWriteTime));\r\n  }\r\n  if (headerOptions.WriteAccessed)\r\n  {\r\n    RINOK(WriteTime(database.Files, NID::kLastAccessTime));\r\n  }\r\n\r\n  if (numDefinedAttributes > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kWinAttributes));\r\n    size_t size = 2;\r\n    if (numDefinedAttributes != database.Files.Size())\r\n      size += (attributesBoolVector.Size() + 7) / 8 + 1;\r\n      size += attributesData.GetCapacity();\r\n\r\n    RINOK(WriteNumber(size));\r\n    if (numDefinedAttributes == database.Files.Size())\r\n    {\r\n      RINOK(WriteByte(1));\r\n    }\r\n    else\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBoolVector(attributesBoolVector));\r\n    }\r\n\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBytes(attributesData));\r\n    }\r\n  }\r\n\r\n  if (numDefinedStarts > 0)\r\n  {\r\n    RINOK(WriteByte(NID::kStartPos));\r\n    size_t size = 2;\r\n    if (numDefinedStarts != database.Files.Size())\r\n      size += (startsBoolVector.Size() + 7) / 8 + 1;\r\n      size += startsData.GetCapacity();\r\n\r\n    RINOK(WriteNumber(size));\r\n    if (numDefinedStarts == database.Files.Size())\r\n    {\r\n      RINOK(WriteByte(1));\r\n    }\r\n    else\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBoolVector(startsBoolVector));\r\n    }\r\n\r\n    {\r\n      RINOK(WriteByte(0));\r\n      RINOK(WriteBytes(startsData));\r\n    }\r\n  }\r\n\r\n  RINOK(WriteByte(NID::kEnd)); // for files\r\n  RINOK(WriteByte(NID::kEnd)); // for headers\r\n\r\n  return _outByte.Flush();\r\n}\r\n\r\nHRESULT COutArchive::WriteDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CArchiveDatabase &database,\r\n    const CCompressionMethodMode *options, \r\n    const CHeaderOptions &headerOptions)\r\n{\r\n  UInt64 headerOffset;\r\n  UInt32 headerCRC;\r\n  UInt64 headerSize;\r\n  if (database.IsEmpty())\r\n  {\r\n    headerSize = 0;\r\n    headerOffset = 0;\r\n    headerCRC = CrcCalc(0, 0);\r\n  }\r\n  else\r\n  {\r\n    _dynamicBuffer.Init();\r\n    _dynamicMode = false;\r\n\r\n    if (options != 0)\r\n      if (options->IsEmpty())\r\n        options = 0;\r\n    if (options != 0)\r\n      if (options->PasswordIsDefined || headerOptions.CompressMainHeader)\r\n        _dynamicMode = true;\r\n    RINOK(WriteHeader(database, headerOptions, headerOffset));\r\n\r\n    if (_dynamicMode)\r\n    {\r\n      CCompressionMethodMode encryptOptions;\r\n      encryptOptions.PasswordIsDefined = options->PasswordIsDefined;\r\n      encryptOptions.Password = options->Password;\r\n      CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions);\r\n      CRecordVector<UInt64> packSizes;\r\n      CObjectVector<CFolder> folders;\r\n      RINOK(EncodeStream(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          encoder, _dynamicBuffer, \r\n          _dynamicBuffer.GetSize(), packSizes, folders));\r\n      _dynamicMode = false;\r\n      _mainMode = true;\r\n      \r\n      _outByte.SetStream(SeqStream);\r\n      _outByte.Init();\r\n      _crc = CRC_INIT_VAL;\r\n      \r\n      if (folders.Size() == 0)\r\n        throw 1;\r\n\r\n      RINOK(WriteID(NID::kEncodedHeader));\r\n      RINOK(WritePackInfo(headerOffset, packSizes, \r\n        CRecordVector<bool>(), CRecordVector<UInt32>()));\r\n      RINOK(WriteUnPackInfo(folders));\r\n      RINOK(WriteByte(NID::kEnd));\r\n      for (int i = 0; i < packSizes.Size(); i++)\r\n        headerOffset += packSizes[i];\r\n      RINOK(_outByte.Flush());\r\n    }\r\n    headerCRC = CRC_GET_DIGEST(_crc);\r\n    headerSize = _outByte.GetProcessedSize();\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n  {\r\n    CFinishHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = \r\n        UInt64(0) - (headerSize + \r\n        4 + kFinishHeaderSize);\r\n    h.ArchiveStartOffset = h.NextHeaderOffset - headerOffset;\r\n    h.AdditionalStartBlockSize = 0;\r\n    RINOK(WriteFinishHeader(h));\r\n    return WriteFinishSignature();\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    CStartHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = headerOffset;\r\n    RINOK(Stream->Seek(_prefixHeaderPos, STREAM_SEEK_SET, NULL));\r\n    return WriteStartHeader(h);\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zOut.h",
    "content": "// 7z/Out.h\r\n\r\n#ifndef __7Z_OUT_H\r\n#define __7Z_OUT_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zCompressionMode.h\"\r\n#include \"7zEncode.h\"\r\n\r\n#include \"../../Common/OutBuffer.h\"\r\n#include \"../../../Common/DynamicBuffer.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CWriteBufferLoc\r\n{\r\n  Byte *_data;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  CWriteBufferLoc(): _size(0), _pos(0) {}\r\n  void Init(Byte *data, size_t size)  \r\n  { \r\n    _pos = 0;\r\n    _data = data;\r\n    _size = size; \r\n  }\r\n  HRESULT Write(const void *data, size_t size)\r\n  {\r\n    if (_pos + size > _size)\r\n      return E_FAIL;\r\n    memmove(_data + _pos, data, size);\r\n    _pos += size;\r\n    return S_OK; \r\n  }\r\n};\r\n\r\nclass CWriteDynamicBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _pos;\r\npublic:\r\n  CWriteDynamicBuffer(): _pos(0) {}\r\n  void Init()  \r\n  { \r\n    _pos = 0;\r\n  }\r\n  void Write(const void *data, size_t size)\r\n  {\r\n    if (_pos + size > _buffer.GetCapacity())\r\n      _buffer.EnsureCapacity(_pos + size);\r\n    memmove(((Byte *)_buffer) +_pos, data, size);\r\n    _pos += size;\r\n  }\r\n  operator Byte *() { return (Byte *)_buffer; };\r\n  operator const Byte *() const { return (const Byte *)_buffer; };\r\n  size_t GetSize() const { return _pos; }\r\n};\r\n\r\nstruct CHeaderOptions\r\n{\r\n  // bool UseAdditionalHeaderStreams;\r\n  bool CompressMainHeader;\r\n  bool WriteModified;\r\n  bool WriteCreated;\r\n  bool WriteAccessed;\r\n\r\n  CHeaderOptions(): \r\n      // UseAdditionalHeaderStreams(false), \r\n      CompressMainHeader(true),\r\n      WriteModified(true),\r\n      WriteCreated(false),\r\n      WriteAccessed(false) {} \r\n};\r\n\r\nclass COutArchive\r\n{\r\n  UInt64 _prefixHeaderPos;\r\n\r\n  HRESULT WriteDirect(const void *data, UInt32 size);\r\n  HRESULT WriteDirectByte(Byte b) { return WriteDirect(&b, 1); }\r\n  HRESULT WriteDirectUInt32(UInt32 value);\r\n  HRESULT WriteDirectUInt64(UInt64 value);\r\n  \r\n  HRESULT WriteBytes(const void *data, size_t size);\r\n  HRESULT WriteBytes(const CByteBuffer &data);\r\n  HRESULT WriteByte(Byte b);\r\n  HRESULT WriteUInt32(UInt32 value);\r\n  HRESULT WriteNumber(UInt64 value);\r\n  HRESULT WriteID(UInt64 value) { return WriteNumber(value); }\r\n\r\n  HRESULT WriteFolder(const CFolder &folder);\r\n  HRESULT WriteFileHeader(const CFileItem &itemInfo);\r\n  HRESULT WriteBoolVector(const CBoolVector &boolVector);\r\n  HRESULT WriteHashDigests(\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  HRESULT WritePackInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs);\r\n\r\n  HRESULT WriteUnPackInfo(const CObjectVector<CFolder> &folders);\r\n\r\n  HRESULT WriteSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unPackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  /*\r\n  HRESULT WriteStreamsInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs,\r\n      bool externalFolders,\r\n      UInt64 externalFoldersStreamIndex,\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnPackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unPackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n  */\r\n\r\n\r\n  HRESULT WriteTime(const CObjectVector<CFileItem> &files, Byte type);\r\n\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const Byte *data, size_t dataSize,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const CByteBuffer &data, \r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT WriteHeader(\r\n      const CArchiveDatabase &database,\r\n      const CHeaderOptions &headerOptions,\r\n      UInt64 &headerOffset);\r\n  \r\n  bool _mainMode;\r\n\r\n  bool _dynamicMode;\r\n\r\n  bool _countMode;\r\n  size_t _countSize;\r\n  COutBuffer _outByte;\r\n  CWriteBufferLoc _outByte2;\r\n  CWriteDynamicBuffer _dynamicBuffer;\r\n  UInt32 _crc;\r\n\r\n  #ifdef _7Z_VOL\r\n  bool _endMarker;\r\n  #endif\r\n\r\n  HRESULT WriteSignature();\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishSignature();\r\n  #endif\r\n  HRESULT WriteStartHeader(const CStartHeader &h);\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishHeader(const CFinishHeader &h);\r\n  #endif\r\n  CMyComPtr<IOutStream> Stream;\r\npublic:\r\n\r\n  COutArchive() { _outByte.Create(1 << 16); }\r\n  CMyComPtr<ISequentialOutStream> SeqStream;\r\n  HRESULT Create(ISequentialOutStream *stream, bool endMarker);\r\n  void Close();\r\n  HRESULT SkeepPrefixArchiveHeader();\r\n  HRESULT WriteDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CArchiveDatabase &database,\r\n      const CCompressionMethodMode *options, \r\n      const CHeaderOptions &headerOptions);\r\n\r\n  #ifdef _7Z_VOL\r\n  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);\r\n  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);\r\n  #endif\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zProperties.cpp",
    "content": "// 7zProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zProperties.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zHandler.h\"\r\n\r\n// #define _MULTI_PACK\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CPropMap\r\n{\r\n  UInt64 FilePropID;\r\n  STATPROPSTG StatPROPSTG;\r\n};\r\n\r\nCPropMap kPropMap[] = \r\n{\r\n  { NID::kName, NULL, kpidPath, VT_BSTR},\r\n  { NID::kSize, NULL, kpidSize, VT_UI8},\r\n  { NID::kPackInfo, NULL, kpidPackedSize, VT_UI8},\r\n  \r\n  #ifdef _MULTI_PACK\r\n  { 100, L\"Pack0\", kpidPackedSize0, VT_UI8},\r\n  { 101, L\"Pack1\", kpidPackedSize1, VT_UI8},\r\n  { 102, L\"Pack2\", kpidPackedSize2, VT_UI8},\r\n  { 103, L\"Pack3\", kpidPackedSize3, VT_UI8},\r\n  { 104, L\"Pack4\", kpidPackedSize4, VT_UI8},\r\n  #endif\r\n\r\n  { NID::kCreationTime, NULL, kpidCreationTime, VT_FILETIME},\r\n  { NID::kLastWriteTime, NULL, kpidLastWriteTime, VT_FILETIME},\r\n  { NID::kLastAccessTime, NULL, kpidLastAccessTime, VT_FILETIME},\r\n  { NID::kWinAttributes, NULL, kpidAttributes, VT_UI4},\r\n  { NID::kStartPos, NULL, kpidPosition, VT_UI4},\r\n\r\n  { NID::kCRC, NULL, kpidCRC, VT_UI4},\r\n  \r\n  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},\r\n  // { 97, NULL, kpidSolid, VT_BOOL},\r\n  #ifndef _SFX\r\n  { 98, NULL, kpidMethod, VT_BSTR},\r\n  { 99, NULL, kpidBlock, VT_UI4}\r\n  #endif\r\n};\r\n\r\nstatic const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);\r\n\r\nstatic int FindPropInMap(UInt64 filePropID)\r\n{\r\n  for (int i = 0; i < kPropMapSize; i++)\r\n    if (kPropMap[i].FilePropID == filePropID)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void CopyOneItem(CRecordVector<UInt64> &src, \r\n    CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      dest.Add(item);\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < dest.Size(); i++)\r\n    if (dest[i] == item)\r\n    {\r\n      dest.Delete(i);\r\n      break;\r\n    }\r\n  dest.Insert(0, item);\r\n}\r\n\r\nvoid CHandler::FillPopIDs()\r\n{ \r\n  _fileInfoPopIDs.Clear();\r\n\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() < 1)\r\n    return;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_database = volume.Database;\r\n  #endif\r\n\r\n  CRecordVector<UInt64> fileInfoPopIDs = _database.ArchiveInfo.FileInfoPopIDs;\r\n\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);\r\n\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCreationTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastWriteTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kLastAccessTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);\r\n  _fileInfoPopIDs += fileInfoPopIDs; \r\n \r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Add(98);\r\n  _fileInfoPopIDs.Add(99);\r\n  #endif\r\n  #ifdef _MULTI_PACK\r\n  _fileInfoPopIDs.Add(100);\r\n  _fileInfoPopIDs.Add(101);\r\n  _fileInfoPopIDs.Add(102);\r\n  _fileInfoPopIDs.Add(103);\r\n  _fileInfoPopIDs.Add(104);\r\n  #endif\r\n\r\n  #ifndef _SFX\r\n  InsertToHead(_fileInfoPopIDs, NID::kLastWriteTime);\r\n  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);\r\n  InsertToHead(_fileInfoPopIDs, NID::kSize);\r\n  InsertToHead(_fileInfoPopIDs, NID::kName);\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)\r\n{\r\n  *numProperties = _fileInfoPopIDs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 index,     \r\n      BSTR *name, PROPID *propID, VARTYPE *varType)\r\n{\r\n  if((int)index >= _fileInfoPopIDs.Size())\r\n    return E_INVALIDARG;\r\n  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);\r\n  if (indexInMap == -1)\r\n    return E_INVALIDARG;\r\n  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;\r\n  *propID = srcItem.propid;\r\n  *varType = srcItem.vt;\r\n  *name = 0;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zProperties.h",
    "content": "// 7zProperties.h\r\n\r\n#ifndef __7Z_PROPERTIES_H\r\n#define __7Z_PROPERTIES_H\r\n\r\n#include \"../../PropID.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nenum\r\n{\r\n  kpidPackedSize0 = kpidUserDefined,\r\n  kpidPackedSize1, \r\n  kpidPackedSize2,\r\n  kpidPackedSize3,\r\n  kpidPackedSize4\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zRegister.cpp",
    "content": "// 7zRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"7zHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::N7z::CHandler;  }\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"7z\", L\"7z\", 0, 7, {'7' + 1 , 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };\r\n\r\nREGISTER_ARC_DEC_SIG(7z)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zSpecStream.cpp",
    "content": "// 7zSpecStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zSpecStream.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result; \r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(\r\n    UInt64 subStream, UInt64 *value)\r\n{\r\n  if (_getSubStreamSize == NULL)\r\n    return E_NOTIMPL;\r\n  return  _getSubStreamSize->GetSubStreamSize(subStream, value);\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zSpecStream.h",
    "content": "// 7zSpecStream.h\r\n\r\n#ifndef __7Z_SPEC_STREAM_H\r\n#define __7Z_SPEC_STREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CSequentialInStreamSizeCount2: \r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _getSubStreamSize = 0;\r\n    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zUpdate.cpp",
    "content": "// UpdateMain.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zUpdate.h\"\r\n#include \"7zFolderInStream.h\"\r\n#include \"7zEncode.h\"\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n\r\n#include \"../../Compress/Copy/CopyCoder.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kMatchFinderForBCJ2_LZMA = L\"BT2\";\r\nstatic const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;\r\nstatic const UInt32 kAlgorithmForBCJ2_LZMA = 1;\r\nstatic const UInt32 kNumFastBytesForBCJ2_LZMA = 64;\r\n\r\nstatic HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream, \r\n    UInt64 position, UInt64 size, ICompressProgressInfo *progress)\r\n{\r\n  RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));\r\n  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;\r\n  CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);\r\n  streamSpec->SetStream(inStream);\r\n  streamSpec->Init(size);\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n  RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));\r\n  return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);\r\n}\r\n\r\nstatic int GetReverseSlashPos(const UString &name)\r\n{\r\n  int slashPos = name.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = name.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n  return slashPos;\r\n}\r\n\r\nint CUpdateItem::GetExtensionPos() const\r\n{\r\n  int slashPos = GetReverseSlashPos(Name);\r\n  int dotPos = Name.ReverseFind(L'.');\r\n  if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n    return Name.Length();\r\n  return dotPos + 1;\r\n}\r\n\r\nUString CUpdateItem::GetExtension() const\r\n{\r\n  return Name.Mid(GetExtensionPos());\r\n}\r\n\r\n#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }\r\n\r\nstatic int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)\r\n{\r\n  size_t c1 = a1.GetCapacity();\r\n  size_t c2 = a2.GetCapacity();\r\n  RINOZ(MyCompare(c1, c2));\r\n  for (size_t i = 0; i < c1; i++)\r\n    RINOZ(MyCompare(a1[i], a2[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareCoders(const CCoderInfo &c1, const CCoderInfo &c2)\r\n{\r\n  RINOZ(MyCompare(c1.NumInStreams, c2.NumInStreams));\r\n  RINOZ(MyCompare(c1.NumOutStreams, c2.NumOutStreams));\r\n  RINOZ(MyCompare(c1.MethodID, c2.MethodID));\r\n  return CompareBuffers(c1.Properties, c2.Properties);\r\n}\r\n\r\nstatic int CompareBindPairs(const CBindPair &b1, const CBindPair &b2)\r\n{\r\n  RINOZ(MyCompare(b1.InIndex, b2.InIndex));\r\n  return MyCompare(b1.OutIndex, b2.OutIndex);\r\n}\r\n\r\nstatic int CompareFolders(const CFolder &f1, const CFolder &f2)\r\n{\r\n  int s1 = f1.Coders.Size();\r\n  int s2 = f2.Coders.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  int i;\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareCoders(f1.Coders[i], f2.Coders[i]));\r\n  s1 = f1.BindPairs.Size();\r\n  s2 = f2.BindPairs.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareBindPairs(f1.BindPairs[i], f2.BindPairs[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareFiles(const CFileItem &f1, const CFileItem &f2)\r\n{\r\n  return MyStringCompareNoCase(f1.Name, f2.Name);\r\n}\r\n\r\nstatic int CompareFolderRefs(const int *p1, const int *p2, void *param)\r\n{\r\n  int i1 = *p1;\r\n  int i2 = *p2;\r\n  const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param;\r\n  RINOZ(CompareFolders(\r\n      db.Folders[i1],\r\n      db.Folders[i2]));\r\n  RINOZ(MyCompare(\r\n      db.NumUnPackStreamsVector[i1],\r\n      db.NumUnPackStreamsVector[i2]));\r\n  if (db.NumUnPackStreamsVector[i1] == 0)\r\n    return 0;\r\n  return CompareFiles(\r\n      db.Files[db.FolderStartFileIndex[i1]],\r\n      db.Files[db.FolderStartFileIndex[i2]]);\r\n}\r\n\r\n////////////////////////////////////////////////////////////\r\n\r\nstatic int CompareEmptyItems(const int *p1, const int *p2, void *param)\r\n{\r\n  const CObjectVector<CUpdateItem> &updateItems = *(const CObjectVector<CUpdateItem> *)param;\r\n  const CUpdateItem &u1 = updateItems[*p1];\r\n  const CUpdateItem &u2 = updateItems[*p2];\r\n  if (u1.IsDirectory != u2.IsDirectory)\r\n    return (u1.IsDirectory) ? 1 : -1;\r\n  if (u1.IsDirectory)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    int n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  if (u1.IsAnti != u2.IsAnti)\r\n    return (u1.IsAnti ? 1 : -1);\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstatic const char *g_Exts = \r\n  \" lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo\" \r\n  \" zip jar ear war msi\"\r\n  \" 3gp avi mov mpeg mpg mpe wmv\"\r\n  \" aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav\"\r\n  \" swf \"\r\n  \" chm hxi hxs\"\r\n  \" gif jpeg jpg jp2 png tiff  bmp ico psd psp\"\r\n  \" awg ps eps cgm dxf svg vrml wmf emf ai md\"\r\n  \" cad dwg pps key sxi\"\r\n  \" max 3ds\"\r\n  \" iso bin nrg mdf img pdi tar cpio xpi\"\r\n  \" vfd vhd vud vmc vsv\"\r\n  \" vmdk dsk nvram vmem vmsd vmsn vmss vmtm\"\r\n  \" inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def\" \r\n  \" f77 f f90 f95\"\r\n  \" asm sql manifest dep \"\r\n  \" mak clw csproj vcproj sln dsp dsw \"\r\n  \" class \"\r\n  \" bat cmd\"\r\n  \" xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml\"\r\n  \" awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs\"\r\n  \" text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf\"\r\n  \" sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf\"\r\n  \" abw afp cwk lwp wpd wps wpt wrf wri\"\r\n  \" abf afm bdf fon mgf otf pcf pfa snf ttf\"\r\n  \" dbf mdb nsf ntf wdb db fdb gdb\"\r\n  \" exe dll ocx vbx sfx sys tlb awx com obj lib out o so \"\r\n  \" pdb pch idb ncb opt\";\r\n\r\nint GetExtIndex(const char *ext)\r\n{\r\n  int extIndex = 1;\r\n  const char *p = g_Exts;\r\n  for (;;)\r\n  {\r\n    char c = *p++;\r\n    if (c == 0)\r\n      return extIndex;\r\n    if (c == ' ')\r\n      continue;\r\n    int pos = 0;\r\n    for (;;)\r\n    {\r\n      char c2 = ext[pos++];\r\n      if (c2 == 0 && (c == 0 || c == ' '))\r\n        return extIndex;\r\n      if (c != c2)\r\n        break;\r\n      c = *p++;\r\n    }\r\n    extIndex++;\r\n    for (;;)\r\n    {\r\n      if (c == 0)\r\n        return extIndex;\r\n      if (c == ' ')\r\n        break;\r\n      c = *p++;\r\n    }\r\n  }\r\n}\r\n\r\nstruct CRefItem\r\n{\r\n  UInt32 Index;\r\n  const CUpdateItem *UpdateItem;\r\n  UInt32 ExtensionPos;\r\n  UInt32 NamePos;\r\n  int ExtensionIndex;\r\n  CRefItem(UInt32 index, const CUpdateItem &updateItem, bool sortByType):\r\n    Index(index),\r\n    UpdateItem(&updateItem),\r\n    ExtensionPos(0),\r\n    NamePos(0),\r\n    ExtensionIndex(0)\r\n  {\r\n    if (sortByType)\r\n    {\r\n      int slashPos = GetReverseSlashPos(updateItem.Name);\r\n      NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0);\r\n      int dotPos = updateItem.Name.ReverseFind(L'.');\r\n      if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n        ExtensionPos = updateItem.Name.Length();\r\n      else \r\n      {\r\n        ExtensionPos = dotPos + 1;\r\n        UString us = updateItem.Name.Mid(ExtensionPos);\r\n        if (!us.IsEmpty())\r\n        {\r\n          us.MakeLower();\r\n          int i;\r\n          AString s;\r\n          for (i = 0; i < us.Length(); i++)\r\n          {\r\n            wchar_t c = us[i];\r\n            if (c >= 0x80)\r\n              break;\r\n            s += (char)c;\r\n          }\r\n          if (i == us.Length())\r\n            ExtensionIndex = GetExtIndex(s);\r\n          else\r\n            ExtensionIndex = 0;\r\n        }\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nstatic int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *param)\r\n{\r\n  const CRefItem &a1 = *p1;\r\n  const CRefItem &a2 = *p2;\r\n  const CUpdateItem &u1 = *a1.UpdateItem;\r\n  const CUpdateItem &u2 = *a2.UpdateItem;\r\n  int n;\r\n  if (u1.IsDirectory != u2.IsDirectory)\r\n    return (u1.IsDirectory) ? 1 : -1;\r\n  if (u1.IsDirectory)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  bool sortByType = *(bool *)param;\r\n  if (sortByType)\r\n  {\r\n    RINOZ(MyCompare(a1.ExtensionIndex, a2.ExtensionIndex))\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos));\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos));\r\n    if (u1.IsLastWriteTimeDefined && u2.IsLastWriteTimeDefined)\r\n      RINOZ(CompareFileTime(&u1.LastWriteTime, &u2.LastWriteTime));\r\n    RINOZ(MyCompare(u1.Size, u2.Size))\r\n  }\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstruct CSolidGroup\r\n{\r\n  CCompressionMethodMode Method;\r\n  CRecordVector<UInt32> Indices;\r\n};\r\n\r\nstatic wchar_t *g_ExeExts[] =\r\n{\r\n  L\"dll\",\r\n  L\"exe\",\r\n  L\"ocx\",\r\n  L\"sfx\",\r\n  L\"sys\"\r\n};\r\n\r\nstatic bool IsExeFile(const UString &ext)\r\n{\r\n  for (int i = 0; i < sizeof(g_ExeExts) / sizeof(g_ExeExts[0]); i++)\r\n    if (ext.CompareNoCase(g_ExeExts[i]) == 0)\r\n      return true;\r\n  return false;\r\n}\r\n\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_BCJ   = 0x03030103;\r\nstatic const UInt64 k_BCJ2  = 0x0303011B;\r\n\r\nstatic bool GetMethodFull(UInt64 methodID, \r\n    UInt32 numInStreams, CMethodFull &methodResult)\r\n{\r\n  methodResult.Id = methodID;\r\n  methodResult.NumInStreams = numInStreams;\r\n  methodResult.NumOutStreams = 1;\r\n  return true;\r\n}\r\n\r\nstatic bool MakeExeMethod(const CCompressionMethodMode &method, \r\n    bool bcj2Filter, CCompressionMethodMode &exeMethod)\r\n{\r\n  exeMethod = method;\r\n  if (bcj2Filter)\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ2, 4, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    if (!GetMethodFull(k_LZMA, 1, methodFull))\r\n      return false;\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kAlgorithm;\r\n      property.Value = kAlgorithmForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kMatchFinder;\r\n      property.Value = kMatchFinderForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n      property.Value = kDictionaryForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n    {\r\n      CProp property;\r\n      property.Id = NCoderPropID::kNumFastBytes;\r\n      property.Value = kNumFastBytesForBCJ2_LZMA;\r\n      methodFull.Properties.Add(property);\r\n    }\r\n\r\n    exeMethod.Methods.Add(methodFull);\r\n    exeMethod.Methods.Add(methodFull);\r\n    CBind bind;\r\n\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 2;\r\n    bind.OutStream = 1;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 3;\r\n    bind.OutStream = 2;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  else\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ, 1, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    CBind bind;\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  return true;\r\n}   \r\n\r\nstatic void SplitFilesToGroups(\r\n    const CCompressionMethodMode &method, \r\n    bool useFilters, bool maxFilter,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    CObjectVector<CSolidGroup> &groups)\r\n{\r\n  if (method.Methods.Size() != 1 || method.Binds.Size() != 0)\r\n    useFilters = false;\r\n  groups.Clear();\r\n  groups.Add(CSolidGroup());\r\n  groups.Add(CSolidGroup());\r\n  CSolidGroup &generalGroup = groups[0];\r\n  CSolidGroup &exeGroup = groups[1];\r\n  generalGroup.Method = method;\r\n  int i;\r\n  for (i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &updateItem = updateItems[i];\r\n    if (!updateItem.NewData)\r\n      continue;\r\n    if (!updateItem.HasStream())\r\n      continue;\r\n    if (useFilters)\r\n    {\r\n      const UString name = updateItem.Name;\r\n      int dotPos = name.ReverseFind(L'.');\r\n      if (dotPos >= 0)\r\n      {\r\n        UString ext = name.Mid(dotPos + 1);\r\n        if (IsExeFile(ext))\r\n        {\r\n          exeGroup.Indices.Add(i);\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    generalGroup.Indices.Add(i);\r\n  }\r\n  if (exeGroup.Indices.Size() > 0)\r\n    if (!MakeExeMethod(method, maxFilter, exeGroup.Method))\r\n      exeGroup.Method = method;\r\n  for (i = 0; i < groups.Size();)\r\n    if (groups[i].Indices.Size() == 0)\r\n      groups.Delete(i);\r\n    else\r\n      i++;\r\n}\r\n\r\nstatic void FromUpdateItemToFileItem(const CUpdateItem &updateItem, \r\n    CFileItem &file)\r\n{\r\n  file.Name = NItemName::MakeLegalName(updateItem.Name);\r\n  if (updateItem.AttributesAreDefined)\r\n    file.SetAttributes(updateItem.Attributes);\r\n  \r\n  if (updateItem.IsCreationTimeDefined)\r\n    file.SetCreationTime(updateItem.CreationTime);\r\n  if (updateItem.IsLastWriteTimeDefined)\r\n    file.SetLastWriteTime(updateItem.LastWriteTime);\r\n  if (updateItem.IsLastAccessTimeDefined)\r\n    file.SetLastAccessTime(updateItem.LastAccessTime);\r\n  \r\n  file.UnPackSize = updateItem.Size;\r\n  file.IsDirectory = updateItem.IsDirectory;\r\n  file.IsAnti = updateItem.IsAnti;\r\n  file.HasStream = updateItem.HasStream();\r\n}\r\n\r\nstatic HRESULT Update2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  UInt64 numSolidFiles = options.NumSolidFiles;\r\n  if (numSolidFiles == 0)\r\n    numSolidFiles = 1;\r\n  /*\r\n  CMyComPtr<IOutStream> outStream;\r\n  RINOK(seqOutStream->QueryInterface(IID_IOutStream, (void **)&outStream));\r\n  if (!outStream)\r\n    return E_NOTIMPL;\r\n  */\r\n\r\n  UInt64 startBlockSize = database != 0 ? database->ArchiveInfo.StartPosition: 0;\r\n  if (startBlockSize > 0 && !options.RemoveSfxBlock)\r\n  {\r\n    RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));\r\n  }\r\n\r\n  CRecordVector<int> fileIndexToUpdateIndexMap;\r\n  if (database != 0)\r\n  {\r\n    fileIndexToUpdateIndexMap.Reserve(database->Files.Size());\r\n    for (int i = 0; i < database->Files.Size(); i++)\r\n      fileIndexToUpdateIndexMap.Add(-1);\r\n  }\r\n  int i;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    int index = updateItems[i].IndexInArchive;\r\n    if (index != -1)\r\n      fileIndexToUpdateIndexMap[index] = i;\r\n  }\r\n\r\n  CRecordVector<int> folderRefs;\r\n  if (database != 0)\r\n  {\r\n    for(i = 0; i < database->Folders.Size(); i++)\r\n    {\r\n      CNum indexInFolder = 0;\r\n      CNum numCopyItems = 0;\r\n      CNum numUnPackStreams = database->NumUnPackStreamsVector[i];\r\n      for (CNum fileIndex = database->FolderStartFileIndex[i];\r\n      indexInFolder < numUnPackStreams; fileIndex++)\r\n      {\r\n        if (database->Files[fileIndex].HasStream)\r\n        {\r\n          indexInFolder++;\r\n          int updateIndex = fileIndexToUpdateIndexMap[fileIndex];\r\n          if (updateIndex >= 0)\r\n            if (!updateItems[updateIndex].NewData)\r\n              numCopyItems++;\r\n        }\r\n      }\r\n      if (numCopyItems != numUnPackStreams && numCopyItems != 0)\r\n        return E_NOTIMPL; // It needs repacking !!!\r\n      if (numCopyItems > 0)\r\n        folderRefs.Add(i);\r\n    }\r\n    folderRefs.Sort(CompareFolderRefs, (void *)database);\r\n  }\r\n\r\n  CArchiveDatabase newDatabase;\r\n\r\n  ////////////////////////////\r\n\r\n  COutArchive archive;\r\n  RINOK(archive.Create(seqOutStream, false));\r\n  RINOK(archive.SkeepPrefixArchiveHeader());\r\n  UInt64 complexity = 0;\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n    complexity += database->GetFolderFullPackSize(folderRefs[i]);\r\n  UInt64 inSizeForReduce = 0;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &updateItem = updateItems[i];\r\n    if (updateItem.NewData)\r\n    {\r\n      complexity += updateItem.Size;\r\n      if (numSolidFiles == 1)\r\n      {\r\n        if (updateItem.Size > inSizeForReduce)\r\n          inSizeForReduce = updateItem.Size;\r\n      }\r\n      else\r\n        inSizeForReduce += updateItem.Size;\r\n    }\r\n  }\r\n  RINOK(updateCallback->SetTotal(complexity));\r\n  complexity = 0;\r\n  RINOK(updateCallback->SetCompleted(&complexity));\r\n\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(updateCallback, true);\r\n\r\n  /////////////////////////////////////////\r\n  // Write Copy Items\r\n\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n  {\r\n    int folderIndex = folderRefs[i];\r\n    \r\n    lps->ProgressOffset = complexity;\r\n    UInt64 packSize = database->GetFolderFullPackSize(folderIndex);\r\n    RINOK(WriteRange(inStream, archive.SeqStream,\r\n        database->GetFolderStreamPos(folderIndex, 0), packSize, progress));\r\n    complexity += packSize;\r\n    \r\n    const CFolder &folder = database->Folders[folderIndex];\r\n    CNum startIndex = database->FolderStartPackStreamIndex[folderIndex];\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      newDatabase.PackSizes.Add(database->PackSizes[startIndex + j]);\r\n      // newDatabase.PackCRCsDefined.Add(database.PackCRCsDefined[startIndex + j]);\r\n      // newDatabase.PackCRCs.Add(database.PackCRCs[startIndex + j]);\r\n    }\r\n    newDatabase.Folders.Add(folder);\r\n\r\n    CNum numUnPackStreams = database->NumUnPackStreamsVector[folderIndex];\r\n    newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);\r\n\r\n    CNum indexInFolder = 0;\r\n    for (CNum fi = database->FolderStartFileIndex[folderIndex];\r\n        indexInFolder < numUnPackStreams; fi++)\r\n    {\r\n      CFileItem file = database->Files[fi];\r\n      if (file.HasStream)\r\n      {\r\n        indexInFolder++;\r\n        int updateIndex = fileIndexToUpdateIndexMap[fi];\r\n        if (updateIndex >= 0)\r\n        {\r\n          const CUpdateItem &updateItem = updateItems[updateIndex];\r\n          if (updateItem.NewProperties)\r\n          {\r\n            CFileItem file2;\r\n            FromUpdateItemToFileItem(updateItem, file2);\r\n            file2.UnPackSize = file.UnPackSize;\r\n            file2.FileCRC = file.FileCRC;\r\n            file2.IsFileCRCDefined = file.IsFileCRCDefined;\r\n            file2.HasStream = file.HasStream;\r\n            file = file2;\r\n          }\r\n        }\r\n        newDatabase.Files.Add(file);\r\n      }\r\n    }\r\n  }\r\n\r\n  /////////////////////////////////////////\r\n  // Compress New Files\r\n\r\n  CObjectVector<CSolidGroup> groups;\r\n  SplitFilesToGroups(*options.Method, options.UseFilters, options.MaxFilter, \r\n      updateItems, groups);\r\n\r\n  const UInt32 kMinReduceSize = (1 << 16);\r\n  if (inSizeForReduce < kMinReduceSize)\r\n    inSizeForReduce = kMinReduceSize;\r\n\r\n  for (int groupIndex = 0; groupIndex < groups.Size(); groupIndex++)\r\n  {\r\n    const CSolidGroup &group = groups[groupIndex];\r\n    int numFiles = group.Indices.Size();\r\n    if (numFiles == 0)\r\n      continue;\r\n    CRecordVector<CRefItem> refItems;\r\n    refItems.Reserve(numFiles);\r\n    bool sortByType = (numSolidFiles > 1);\r\n    for (i = 0; i < numFiles; i++)\r\n      refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType));\r\n    refItems.Sort(CompareUpdateItems, (void *)&sortByType);\r\n    \r\n    CRecordVector<UInt32> indices;\r\n    indices.Reserve(numFiles);\r\n\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      UInt32 index = refItems[i].Index;\r\n      indices.Add(index);\r\n      /*\r\n      const CUpdateItem &updateItem = updateItems[index];\r\n      CFileItem file;\r\n      if (updateItem.NewProperties)\r\n        FromUpdateItemToFileItem(updateItem, file);\r\n      else\r\n        file = database.Files[updateItem.IndexInArchive];\r\n      if (file.IsAnti || file.IsDirectory)\r\n        return E_FAIL;\r\n      newDatabase.Files.Add(file);\r\n      */\r\n    }\r\n    \r\n    CEncoder encoder(group.Method);\r\n\r\n    for (i = 0; i < numFiles;)\r\n    {\r\n      UInt64 totalSize = 0;\r\n      int numSubFiles;\r\n      UString prevExtension;\r\n      for (numSubFiles = 0; i + numSubFiles < numFiles && \r\n          numSubFiles < numSolidFiles; numSubFiles++)\r\n      {\r\n        const CUpdateItem &updateItem = updateItems[indices[i + numSubFiles]];\r\n        totalSize += updateItem.Size;\r\n        if (totalSize > options.NumSolidBytes)\r\n          break;\r\n        if (options.SolidExtension)\r\n        {\r\n          UString ext = updateItem.GetExtension();\r\n          if (numSubFiles == 0)\r\n            prevExtension = ext;\r\n          else\r\n            if (ext.CompareNoCase(prevExtension) != 0)\r\n              break;\r\n        }\r\n      }\r\n      if (numSubFiles < 1)\r\n        numSubFiles = 1;\r\n\r\n      CFolderInStream *inStreamSpec = new CFolderInStream;\r\n      CMyComPtr<ISequentialInStream> solidInStream(inStreamSpec);\r\n      inStreamSpec->Init(updateCallback, &indices[i], numSubFiles);\r\n      \r\n      CFolder folderItem;\r\n\r\n      int startPackIndex = newDatabase.PackSizes.Size();\r\n      RINOK(encoder.Encode(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          solidInStream, NULL, &inSizeForReduce, folderItem, \r\n          archive.SeqStream, newDatabase.PackSizes, progress));\r\n\r\n      for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)\r\n        lps->OutSize += newDatabase.PackSizes[startPackIndex];\r\n\r\n      lps->InSize += folderItem.GetUnPackSize();\r\n      // for()\r\n      // newDatabase.PackCRCsDefined.Add(false);\r\n      // newDatabase.PackCRCs.Add(0);\r\n      \r\n      newDatabase.Folders.Add(folderItem);\r\n      \r\n      CNum numUnPackStreams = 0;\r\n      for (int subIndex = 0; subIndex < numSubFiles; subIndex++)\r\n      {\r\n        const CUpdateItem &updateItem = updateItems[indices[i + subIndex]];\r\n        CFileItem file;\r\n        if (updateItem.NewProperties)\r\n          FromUpdateItemToFileItem(updateItem, file);\r\n        else\r\n          file = database->Files[updateItem.IndexInArchive];\r\n        if (file.IsAnti || file.IsDirectory)\r\n          return E_FAIL;\r\n        \r\n        /*\r\n        CFileItem &file = newDatabase.Files[\r\n              startFileIndexInDatabase + i + subIndex];\r\n        */\r\n        if (!inStreamSpec->Processed[subIndex])\r\n        {\r\n          continue;\r\n          // file.Name += L\".locked\";\r\n        }\r\n\r\n        file.FileCRC = inStreamSpec->CRCs[subIndex];\r\n        file.UnPackSize = inStreamSpec->Sizes[subIndex];\r\n        if (file.UnPackSize != 0)\r\n        {\r\n          file.IsFileCRCDefined = true;\r\n          file.HasStream = true;\r\n          numUnPackStreams++;\r\n        }\r\n        else\r\n        {\r\n          file.IsFileCRCDefined = false;\r\n          file.HasStream = false;\r\n        }\r\n        newDatabase.Files.Add(file);\r\n      }\r\n      // numUnPackStreams = 0 is very bad case for locked files\r\n      // v3.13 doesn't understand it.\r\n      newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);\r\n      i += numSubFiles;\r\n    }\r\n  }\r\n\r\n  {\r\n    /////////////////////////////////////////\r\n    // Write Empty Files & Folders\r\n    \r\n    CRecordVector<int> emptyRefs;\r\n    for(i = 0; i < updateItems.Size(); i++)\r\n    {\r\n      const CUpdateItem &updateItem = updateItems[i];\r\n      if (updateItem.NewData)\r\n      {\r\n        if (updateItem.HasStream())\r\n          continue;\r\n      }\r\n      else\r\n        if (updateItem.IndexInArchive != -1)\r\n          if (database->Files[updateItem.IndexInArchive].HasStream)\r\n            continue;\r\n      emptyRefs.Add(i);\r\n    }\r\n    emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);\r\n    for(i = 0; i < emptyRefs.Size(); i++)\r\n    {\r\n      const CUpdateItem &updateItem = updateItems[emptyRefs[i]];\r\n      CFileItem file;\r\n      if (updateItem.NewProperties)\r\n        FromUpdateItemToFileItem(updateItem, file);\r\n      else\r\n        file = database->Files[updateItem.IndexInArchive];\r\n      newDatabase.Files.Add(file);\r\n    }\r\n  }\r\n    \r\n  /*\r\n  if (newDatabase.Files.Size() != updateItems.Size())\r\n    return E_FAIL;\r\n  */\r\n\r\n  return archive.WriteDatabase(EXTERNAL_CODECS_LOC_VARS\r\n      newDatabase, options.HeaderMethod, options.HeaderOptions);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\n\r\nstatic HRESULT WriteVolumeHeader(COutArchive &archive, CFileItem &file, const CUpdateOptions &options)\r\n{\r\n  CCoderInfo coder;\r\n  coder.NumInStreams = coder.NumOutStreams = 1;\r\n  coder.MethodID = k_Copy;\r\n  \r\n  CFolder folder;\r\n  folder.Coders.Add(coder);\r\n  folder.PackStreams.Add(0);\r\n  \r\n  CNum numUnPackStreams = 0;\r\n  if (file.UnPackSize != 0)\r\n  {\r\n    file.IsFileCRCDefined = true;\r\n    file.HasStream = true;\r\n    numUnPackStreams++;\r\n  }\r\n  else\r\n  {\r\n    throw 1;\r\n    file.IsFileCRCDefined = false;\r\n    file.HasStream = false;\r\n  }\r\n  folder.UnPackSizes.Add(file.UnPackSize);\r\n  \r\n  CArchiveDatabase newDatabase;\r\n  newDatabase.Files.Add(file);\r\n  newDatabase.Folders.Add(folder);\r\n  newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);\r\n  newDatabase.PackSizes.Add(file.UnPackSize);\r\n  newDatabase.PackCRCsDefined.Add(false);\r\n  newDatabase.PackCRCs.Add(file.FileCRC);\r\n  \r\n  return archive.WriteDatabase(newDatabase, \r\n      options.HeaderMethod, \r\n      false, \r\n      false);\r\n}\r\n\r\nHRESULT UpdateVolume(\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  if (updateItems.Size() != 1)\r\n    return E_NOTIMPL;\r\n\r\n  CMyComPtr<IArchiveUpdateCallback2> volumeCallback;\r\n  RINOK(updateCallback->QueryInterface(IID_IArchiveUpdateCallback2, (void **)&volumeCallback));\r\n  if (!volumeCallback)\r\n    return E_NOTIMPL;\r\n\r\n  CMyComPtr<ISequentialInStream> fileStream;\r\n  HRESULT result = updateCallback->GetStream(0, &fileStream);\r\n  if (result != S_OK && result != S_FALSE)\r\n    return result;\r\n  if (result == S_FALSE)\r\n    return E_FAIL;\r\n  \r\n  CFileItem file;\r\n  \r\n  const CUpdateItem &updateItem = updateItems[0];\r\n  if (updateItem.NewProperties)\r\n    FromUpdateItemToFileItem(updateItem, file);\r\n  else\r\n    file = database->Files[updateItem.IndexInArchive];\r\n  if (file.IsAnti || file.IsDirectory)\r\n    return E_FAIL;\r\n\r\n  UInt64 complexity = 0;\r\n  file.IsStartPosDefined = true;\r\n  file.StartPos = 0;\r\n  for (UInt64 volumeIndex = 0; true; volumeIndex++)\r\n  { \r\n    UInt64 volSize;\r\n    RINOK(volumeCallback->GetVolumeSize(volumeIndex, &volSize));\r\n    UInt64 pureSize = COutArchive::GetVolPureSize(volSize, file.Name.Length(), true);\r\n    CMyComPtr<ISequentialOutStream> volumeStream;\r\n    RINOK(volumeCallback->GetVolumeStream(volumeIndex, &volumeStream));\r\n   \r\n    COutArchive archive;\r\n    RINOK(archive.Create(volumeStream, true));\r\n    RINOK(archive.SkeepPrefixArchiveHeader());\r\n        \r\n    CSequentialInStreamWithCRC *inCrcStreamSpec = new CSequentialInStreamWithCRC;\r\n    CMyComPtr<ISequentialInStream> inCrcStream = inCrcStreamSpec;\r\n    inCrcStreamSpec->Init(fileStream);\r\n\r\n    RINOK(WriteRange(inCrcStream, volumeStream, pureSize, updateCallback, complexity));\r\n    file.UnPackSize = inCrcStreamSpec->GetSize();\r\n    if (file.UnPackSize == 0)\r\n      break;\r\n    file.FileCRC = inCrcStreamSpec->GetCRC();\r\n    RINOK(WriteVolumeHeader(archive, file, options));\r\n    file.StartPos += file.UnPackSize;\r\n    if (file.UnPackSize < pureSize)\r\n      break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nclass COutVolumeStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback, \r\n      const UString &name)  \r\n  { \r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutVolumeStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (!_volumeStream)\r\n    {\r\n      RINOK(VolumeCallback->GetVolumeSize(_volIndex, &_volSize));\r\n      RINOK(VolumeCallback->GetVolumeStream(_volIndex, &_volumeStream));\r\n      _volIndex++;\r\n      _curPos = 0;\r\n      RINOK(_archive.Create(_volumeStream, true));\r\n      RINOK(_archive.SkeepPrefixArchiveHeader());\r\n      _crc.Init();\r\n      continue;\r\n    }\r\n    UInt64 pureSize = COutArchive::GetVolPureSize(_volSize, _file.Name.Length());\r\n    UInt32 curSize = (UInt32)MyMin(UInt64(size), pureSize - _curPos);\r\n\r\n    _crc.Update(data, curSize);\r\n    UInt32 realProcessed;\r\n    RINOK(_volumeStream->Write(data, curSize, &realProcessed))\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _curPos += realProcessed;\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n    if (_curPos == pureSize)\r\n    {\r\n      RINOK(Flush());\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (seqOutStream)\r\n  #endif\r\n    return Update2(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        inStream, database, updateItems,\r\n        seqOutStream, updateCallback, options);\r\n  #ifdef _7Z_VOL\r\n  if (options.VolumeMode)\r\n    return UpdateVolume(inStream, database, updateItems,\r\n      seqOutStream, updateCallback, options);\r\n  COutVolumeStream *volStreamSpec = new COutVolumeStream;\r\n  CMyComPtr<ISequentialOutStream> volStream = volStreamSpec;\r\n  CMyComPtr<IArchiveUpdateCallback2> volumeCallback;\r\n  RINOK(updateCallback->QueryInterface(IID_IArchiveUpdateCallback2, (void **)&volumeCallback));\r\n  if (!volumeCallback)\r\n    return E_NOTIMPL;\r\n  volStreamSpec->Init(volumeCallback, L\"a.7z\");\r\n  volStreamSpec->_options = options;\r\n  RINOK(Update2(inStream, database, updateItems,\r\n    volStream, updateCallback, options));\r\n  return volStreamSpec->Flush();\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/7zUpdate.h",
    "content": "// 7zUpdate.h\r\n\r\n#ifndef __7Z_UPDATE_H\r\n#define __7Z_UPDATE_H\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CUpdateItem\r\n{\r\n  bool NewData;\r\n  bool NewProperties;\r\n  int IndexInArchive;\r\n  int IndexInClient;\r\n  \r\n  UInt32 Attributes;\r\n  FILETIME CreationTime;\r\n  FILETIME LastWriteTime;\r\n  FILETIME LastAccessTime;\r\n\r\n  UInt64 Size;\r\n  UString Name;\r\n  \r\n  bool IsAnti;\r\n  bool IsDirectory;\r\n\r\n  bool IsCreationTimeDefined;\r\n  bool IsLastWriteTimeDefined;\r\n  bool IsLastAccessTimeDefined;\r\n  bool AttributesAreDefined;\r\n\r\n  bool HasStream() const \r\n    { return !IsDirectory && !IsAnti && Size != 0; }\r\n  CUpdateItem():  \r\n      IsAnti(false), \r\n      AttributesAreDefined(false), \r\n      IsCreationTimeDefined(false), \r\n      IsLastWriteTimeDefined(false), \r\n      IsLastAccessTimeDefined(false)\r\n      {}\r\n  void SetDirectoryStatusFromAttributes()\r\n    { IsDirectory = ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0); };\r\n\r\n  int GetExtensionPos() const;\r\n  UString GetExtension() const;\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  const CCompressionMethodMode *Method;\r\n  const CCompressionMethodMode *HeaderMethod;\r\n  bool UseFilters;\r\n  bool MaxFilter;\r\n\r\n  CHeaderOptions HeaderOptions;\r\n\r\n  UInt64 NumSolidFiles;\r\n  UInt64 NumSolidBytes;\r\n  bool SolidExtension;\r\n  bool RemoveSfxBlock;\r\n  bool VolumeMode;\r\n};\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *database,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options);\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Archive.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Archive2.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n  GetNumberOfMethods PRIVATE\r\n  GetMethodProperty PRIVATE\r\n  SetLargePageMode PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/ArchiveExports.cpp",
    "content": "// ArchiveExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterArc.h\"\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax]; \r\nvoid RegisterArc(const CArcInfo *arcInfo) \r\n{ \r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo; \r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler, \r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\n#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nint FindFormatCalssId(const GUID *clsID)\r\n{\r\n  GUID cls = *clsID;\r\n  CLS_ARC_ID_ITEM(cls) = 0;\r\n  if (cls != CLSID_CArchiveHandler)\r\n    return -1;\r\n  Byte id = CLS_ARC_ID_ITEM(*clsID);\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n    if (g_Arcs[i]->ClassId == id)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nSTDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  {\r\n    int needIn = (*iid == IID_IInArchive);\r\n    int needOut = (*iid == IID_IOutArchive);\r\n    if (!needIn && !needOut)\r\n      return E_NOINTERFACE;\r\n    int formatIndex = FindFormatCalssId(clsid);\r\n    if (formatIndex < 0)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    \r\n    const CArcInfo &arc = *g_Arcs[formatIndex];\r\n    if (needIn)\r\n    {\r\n      *outObject = arc.CreateInArchive();\r\n      ((IInArchive *)*outObject)->AddRef();\r\n    }\r\n    else\r\n    {\r\n      if (!arc.CreateOutArchive)\r\n        return CLASS_E_CLASSNOTAVAILABLE;\r\n      *outObject = arc.CreateOutArchive();\r\n      ((IOutArchive *)*outObject)->AddRef();\r\n    }\r\n  }\r\n  COM_TRY_END\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  if (formatIndex >= g_NumArcs)\r\n    return E_INVALIDARG;\r\n  const CArcInfo &arc = *g_Arcs[formatIndex];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case NArchive::kName:\r\n      prop = arc.Name;\r\n      break;\r\n    case NArchive::kClassID:\r\n    {\r\n      GUID clsId = CLSID_CArchiveHandler;\r\n      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;\r\n      return SetPropGUID(clsId, value);\r\n    }\r\n    case NArchive::kExtension:\r\n      if (arc.Ext != 0)\r\n        prop = arc.Ext;\r\n      break;\r\n    case NArchive::kAddExtension:\r\n      if (arc.AddExt != 0)\r\n        prop = arc.AddExt;\r\n      break;\r\n    case NArchive::kUpdate:\r\n      prop = (bool)(arc.CreateOutArchive != 0);\r\n      break;\r\n    case NArchive::kKeepName:\r\n      prop = arc.KeepName;\r\n      break;\r\n    case NArchive::kStartSignature:\r\n      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  return GetHandlerProperty2(0, propID, value);\r\n}\r\n\r\nSTDAPI GetNumberOfFormats(UINT32 *numFormats)\r\n{\r\n  *numFormats = g_NumArcs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/CoderMixer2.cpp",
    "content": "// CoderMixer2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):\r\n  _srcBindInfo(srcBindInfo)\r\n{\r\n  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);\r\n\r\n  UInt32  j;\r\n  for (j = 0; j < NumSrcInStreams; j++)\r\n  {\r\n    _srcInToDestOutMap.Add(0);\r\n    DestOutToSrcInMap.Add(0);\r\n  }\r\n  for (j = 0; j < _numSrcOutStreams; j++)\r\n  {\r\n    _srcOutToDestInMap.Add(0);\r\n    _destInToSrcOutMap.Add(0);\r\n  }\r\n\r\n  UInt32 destInOffset = 0;\r\n  UInt32 destOutOffset = 0;\r\n  UInt32 srcInOffset = NumSrcInStreams;\r\n  UInt32 srcOutOffset = _numSrcOutStreams;\r\n\r\n  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];\r\n\r\n    srcInOffset -= srcCoderInfo.NumInStreams;\r\n    srcOutOffset -= srcCoderInfo.NumOutStreams;\r\n    \r\n    UInt32 j;\r\n    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)\r\n    {\r\n      UInt32 index = srcInOffset + j;\r\n      _srcInToDestOutMap[index] = destOutOffset;\r\n      DestOutToSrcInMap[destOutOffset] = index;\r\n    }\r\n    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)\r\n    {\r\n      UInt32 index = srcOutOffset + j;\r\n      _srcOutToDestInMap[index] = destInOffset;\r\n      _destInToSrcOutMap[destInOffset] = index;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)\r\n{\r\n  destBindInfo.Coders.Clear();\r\n  destBindInfo.BindPairs.Clear();\r\n  destBindInfo.InStreams.Clear();\r\n  destBindInfo.OutStreams.Clear();\r\n\r\n  int i;\r\n  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];\r\n    CCoderStreamsInfo destCoderInfo;\r\n    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;\r\n    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;\r\n    destBindInfo.Coders.Add(destCoderInfo);\r\n  }\r\n  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];\r\n    CBindPair destBindPair;\r\n    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];\r\n    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];\r\n    destBindInfo.BindPairs.Add(destBindPair);\r\n  }\r\n  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)\r\n    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);\r\n  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)\r\n    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);\r\n}\r\n\r\nCCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams): \r\n    NumInStreams(numInStreams),\r\n    NumOutStreams(numOutStreams)\r\n{\r\n  InSizes.Reserve(NumInStreams);\r\n  InSizePointers.Reserve(NumInStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes, \r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\nvoid CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,\r\n      const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n}  \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/CoderMixer2.h",
    "content": "// CoderMixer2.h\r\n\r\n#ifndef __CODER_MIXER2_H\r\n#define __CODER_MIXER2_H\r\n\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n};\r\n\r\nstruct CCoderStreamsInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n};\r\n\r\nstruct CBindInfo\r\n{\r\n  CRecordVector<CCoderStreamsInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<UInt32> InStreams;\r\n  CRecordVector<UInt32> OutStreams;\r\n\r\n  void Clear()\r\n  {\r\n    Coders.Clear();\r\n    BindPairs.Clear();\r\n    InStreams.Clear();\r\n    OutStreams.Clear();\r\n  }\r\n\r\n  /*\r\n  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const\r\n  {\r\n    UInt32 numOutStreams = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      numOutStreams += Coders[i].NumOutStreams;\r\n    return numOutStreams;\r\n  }\r\n  */\r\n\r\n\r\n  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const\r\n  {\r\n    numInStreams = 0;\r\n    numOutStreams = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n    {\r\n      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];\r\n      numInStreams += coderStreamsInfo.NumInStreams;\r\n      numOutStreams += coderStreamsInfo.NumOutStreams;\r\n    }\r\n  }\r\n\r\n  int FindBinderForInStream(UInt32 inStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBinderForOutStream(UInt32 outStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumInStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumOutStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n\r\n  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex, \r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumInStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex, \r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumOutStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n};\r\n\r\nclass CBindReverseConverter\r\n{\r\n  UInt32 _numSrcOutStreams;\r\n  NCoderMixer::CBindInfo _srcBindInfo;\r\n  CRecordVector<UInt32> _srcInToDestOutMap;\r\n  CRecordVector<UInt32> _srcOutToDestInMap;\r\n  CRecordVector<UInt32> _destInToSrcOutMap;\r\npublic:\r\n  UInt32 NumSrcInStreams;\r\n  CRecordVector<UInt32> DestOutToSrcInMap;\r\n\r\n  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);\r\n  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);\r\n};\r\n\r\nstruct CCoderInfo2\r\n{\r\n  CMyComPtr<ICompressCoder> Coder;\r\n  CMyComPtr<ICompressCoder2> Coder2;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n\r\n  CRecordVector<UInt64> InSizes;\r\n  CRecordVector<UInt64> OutSizes;\r\n  CRecordVector<const UInt64 *> InSizePointers;\r\n  CRecordVector<const UInt64 *> OutSizePointers;\r\n\r\n  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n\r\n  HRESULT QueryInterface(REFGUID iid, void** pp) const\r\n  {\r\n    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;\r\n    return p->QueryInterface(iid, pp);\r\n  }\r\n};\r\n\r\nclass CCoderMixer2\r\n{\r\npublic:\r\n  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;\r\n  virtual void ReInit() = 0;\r\n  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;\r\n};\r\n\r\n}\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/CoderMixer2MT.cpp",
    "content": "// CoderMixer2MT.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2MT.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams): \r\n    CCoderInfo2(numInStreams, numOutStreams)\r\n{\r\n  InStreams.Reserve(NumInStreams);\r\n  InStreamPointers.Reserve(NumInStreams);\r\n  OutStreams.Reserve(NumOutStreams);\r\n  OutStreamPointers.Reserve(NumOutStreams);\r\n}\r\n\r\nvoid CCoder2::Execute() { Code(NULL); }\r\n\r\nvoid CCoder2::Code(ICompressProgressInfo *progress)\r\n{\r\n  InStreamPointers.Clear();\r\n  OutStreamPointers.Clear();\r\n  UInt32 i;\r\n  for (i = 0; i < NumInStreams; i++)\r\n  {\r\n    if (InSizePointers[i] != NULL)\r\n      InSizePointers[i] = &InSizes[i];\r\n    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);\r\n  }\r\n  for (i = 0; i < NumOutStreams; i++)\r\n  {\r\n    if (OutSizePointers[i] != NULL)\r\n      OutSizePointers[i] = &OutSizes[i];\r\n    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);\r\n  }\r\n  if (Coder)\r\n    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0], \r\n        InSizePointers[0], OutSizePointers[0], progress);\r\n  else\r\n    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,\r\n      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);\r\n  {\r\n    int i;\r\n    for (i = 0; i < InStreams.Size(); i++)\r\n      InStreams[i].Release();\r\n    for (i = 0; i < OutStreams.Size(); i++)\r\n      OutStreams[i].Release();\r\n  }\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes, \r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\n\r\nvoid CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n//////////////////////////////////////\r\n// CCoderMixer2MT\r\n\r\nHRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)\r\n{  \r\n  _bindInfo = bindInfo; \r\n  _streamBinders.Clear();\r\n  for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    _streamBinders.Add(CStreamBinder());\r\n    RINOK(_streamBinders.Back().CreateEvents());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoderCommon()\r\n{\r\n  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];\r\n  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);\r\n  _coders.Add(threadCoderInfo);\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder(ICompressCoder *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder = coder;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder2 = coder;\r\n}\r\n\r\n\r\nvoid CCoderMixer2MT::ReInit()\r\n{\r\n  for(int i = 0; i < _streamBinders.Size(); i++)\r\n    _streamBinders[i].ReInit();\r\n}\r\n\r\n\r\nHRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams) \r\n{\r\n  /*\r\n  if (_coders.Size() != _bindInfo.Coders.Size())\r\n    throw 0;\r\n  */\r\n  int i;\r\n  for(i = 0; i < _coders.Size(); i++)\r\n  {\r\n    CCoder2 &coderInfo = _coders[i];\r\n    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];\r\n    coderInfo.InStreams.Clear();\r\n    UInt32 j;\r\n    for(j = 0; j < coderStreamsInfo.NumInStreams; j++)\r\n      coderInfo.InStreams.Add(NULL);\r\n    coderInfo.OutStreams.Clear();\r\n    for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)\r\n      coderInfo.OutStreams.Add(NULL);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = _bindInfo.BindPairs[i];\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);\r\n    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);\r\n\r\n    _streamBinders[i].CreateStreams(\r\n        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],\r\n        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.InStreams.Size(); i++)\r\n  {\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);\r\n    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];\r\n  }\r\n  \r\n  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);\r\n    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)\r\n{\r\n  for (int i = 0; i < _coders.Size(); i++)\r\n    if (_coders[i].Result == code)\r\n      return code;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||\r\n      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())\r\n    return E_INVALIDARG;\r\n\r\n  Init(inStreams, outStreams);\r\n\r\n  int i;\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n    {\r\n      RINOK(_coders[i].Create());\r\n    }\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].Start();\r\n\r\n  _coders[_progressCoderIndex].Code(progress);\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].WaitFinish();\r\n\r\n  RINOK(ReturnIfError(E_ABORT));\r\n  RINOK(ReturnIfError(E_OUTOFMEMORY));\r\n  RINOK(ReturnIfError(S_FALSE));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK && result != E_FAIL)\r\n      return result;\r\n  }\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}  \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/CoderMixer2MT.h",
    "content": "// CoderMixer2MT.h\r\n\r\n#ifndef __CODER_MIXER2_MT_H\r\n#define __CODER_MIXER2_MT_H\r\n\r\n#include \"CoderMixer2.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../Common/StreamBinder.h\"\r\n#include \"../../Common/VirtThread.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CCoder2: public CCoderInfo2, public CVirtThread\r\n{\r\n  HRESULT Result;\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;\r\n  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;\r\n  CRecordVector<ISequentialInStream*> InStreamPointers;\r\n  CRecordVector<ISequentialOutStream*> OutStreamPointers;\r\n\r\n  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n  virtual void Execute();\r\n  void Code(ICompressProgressInfo *progress);\r\n};\r\n\r\n\r\n/*\r\n  SetBindInfo()\r\n  for each coder\r\n    AddCoder[2]()\r\n  SetProgressIndex(UInt32 coderIndex);\r\n \r\n  for each file\r\n  {\r\n    ReInit()\r\n    for each coder\r\n      SetCoderInfo  \r\n    Code\r\n  }\r\n*/\r\n\r\nclass CCoderMixer2MT:\r\n  public ICompressCoder2,\r\n  public CCoderMixer2,\r\n  public CMyUnknownImp\r\n{\r\n  CBindInfo _bindInfo;\r\n  CObjectVector<CStreamBinder> _streamBinders;\r\n  int _progressCoderIndex;\r\n\r\n  void AddCoderCommon();\r\n  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);\r\n  HRESULT ReturnIfError(HRESULT code);\r\npublic:\r\n  CObjectVector<CCoder2> _coders;\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n\r\n  HRESULT SetBindInfo(const CBindInfo &bindInfo);\r\n  void AddCoder(ICompressCoder *coder);\r\n  void AddCoder2(ICompressCoder2 *coder);\r\n  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }\r\n\r\n  void ReInit();\r\n  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)\r\n    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }\r\n  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const\r\n    {  return _streamBinders[binderIndex].ProcessedSize; }\r\n};\r\n\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/CrossThreadProgress.cpp",
    "content": "// CrossThreadProgress.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CrossThreadProgress.h\"\r\n\r\nSTDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  InSize = inSize;\r\n  OutSize = outSize;\r\n  ProgressEvent.Set();\r\n  WaitEvent.Lock();\r\n  return Result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/CrossThreadProgress.h",
    "content": "// CrossThreadProgress.h\r\n\r\n#ifndef __CROSSTHREADPROGRESS_H\r\n#define __CROSSTHREADPROGRESS_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CCrossThreadProgress: \r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  const UInt64 *InSize;\r\n  const UInt64 *OutSize;\r\n  HRESULT Result;\r\n  NWindows::NSynchronization::CAutoResetEvent ProgressEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent WaitEvent;\r\n\r\n  HRes Create()\r\n  {\r\n    RINOK(ProgressEvent.CreateIfNotCreated());\r\n    return WaitEvent.CreateIfNotCreated();\r\n  }\r\n  void Init()\r\n  {\r\n    ProgressEvent.Reset();\r\n    WaitEvent.Reset();\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/DummyOutStream.cpp",
    "content": "// DummyOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DummyOutStream.h\"\r\n\r\nSTDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/DummyOutStream.h",
    "content": "// DummyOutStream.h\r\n\r\n#ifndef __DUMMYOUTSTREAM_H\r\n#define __DUMMYOUTSTREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nclass CDummyOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }\r\n  void Init() { _size = 0; }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/HandlerOut.cpp",
    "content": "// HandlerOutCommon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"HandlerOut.h\"\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\n\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kLZMA2MethodName = L\"LZMA2\";\r\nstatic const wchar_t *kBZip2MethodName = L\"BZip2\";\r\nstatic const wchar_t *kPpmdMethodName = L\"PPMd\";\r\nstatic const wchar_t *kDeflateMethodName = L\"Deflate\";\r\nstatic const wchar_t *kDeflate64MethodName = L\"Deflate64\";\r\n\r\nstatic const wchar_t *kLzmaMatchFinderX1 = L\"HC4\";\r\nstatic const wchar_t *kLzmaMatchFinderX5 = L\"BT4\";\r\n\r\nstatic const UInt32 kLzmaAlgoX1 = 0;\r\nstatic const UInt32 kLzmaAlgoX5 = 1;\r\n\r\nstatic const UInt32 kLzmaDicSizeX1 = 1 << 16;\r\nstatic const UInt32 kLzmaDicSizeX3 = 1 << 20;\r\nstatic const UInt32 kLzmaDicSizeX5 = 1 << 24;\r\nstatic const UInt32 kLzmaDicSizeX7 = 1 << 25;\r\nstatic const UInt32 kLzmaDicSizeX9 = 1 << 26;\r\n\r\nstatic const UInt32 kLzmaFastBytesX1 = 32;\r\nstatic const UInt32 kLzmaFastBytesX7 = 64;\r\n\r\nstatic const UInt32 kPpmdMemSizeX1 = (1 << 22);\r\nstatic const UInt32 kPpmdMemSizeX5 = (1 << 24);\r\nstatic const UInt32 kPpmdMemSizeX7 = (1 << 26);\r\nstatic const UInt32 kPpmdMemSizeX9 = (192 << 20);\r\n\r\nstatic const UInt32 kPpmdOrderX1 = 4;\r\nstatic const UInt32 kPpmdOrderX5 = 6;\r\nstatic const UInt32 kPpmdOrderX7 = 16;\r\nstatic const UInt32 kPpmdOrderX9 = 32;\r\n\r\nstatic const UInt32 kDeflateAlgoX1 = 0;\r\nstatic const UInt32 kDeflateAlgoX5 = 1;\r\n\r\nstatic const UInt32 kDeflateFastBytesX1 = 32;\r\nstatic const UInt32 kDeflateFastBytesX7 = 64;\r\nstatic const UInt32 kDeflateFastBytesX9 = 128;\r\n\r\nstatic const UInt32 kDeflatePassesX1 = 1;\r\nstatic const UInt32 kDeflatePassesX7 = 3;\r\nstatic const UInt32 kDeflatePassesX9 = 10;\r\n\r\nstatic const UInt32 kBZip2NumPassesX1 = 1;\r\nstatic const UInt32 kBZip2NumPassesX7 = 2;\r\nstatic const UInt32 kBZip2NumPassesX9 = 7;\r\n\r\nstatic const UInt32 kBZip2DicSizeX1 = 100000;\r\nstatic const UInt32 kBZip2DicSizeX3 = 500000;\r\nstatic const UInt32 kBZip2DicSizeX5 = 900000;\r\n\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5;\r\n\r\nstatic bool AreEqual(const UString &methodName, const wchar_t *s)\r\n  { return (methodName.CompareNoCase(s) == 0); }\r\n\r\nstatic inline bool IsLZMAMethod(const UString &methodName)\r\n{ \r\n  return \r\n    AreEqual(methodName, kLZMAMethodName) || \r\n    AreEqual(methodName, kLZMA2MethodName); \r\n}\r\n\r\nstatic inline bool IsBZip2Method(const UString &methodName)\r\n  { return AreEqual(methodName, kBZip2MethodName); }\r\n\r\nstatic inline bool IsPpmdMethod(const UString &methodName)\r\n  { return AreEqual(methodName, kPpmdMethodName); }\r\n\r\nstatic inline bool IsDeflateMethod(const UString &methodName)\r\n{ \r\n  return \r\n    AreEqual(methodName, kDeflateMethodName) || \r\n    AreEqual(methodName, kDeflate64MethodName); \r\n}\r\n\r\nstruct CNameToPropID\r\n{\r\n  PROPID PropID;\r\n  VARTYPE VarType;\r\n  const wchar_t *Name;\r\n};\r\n\r\nCNameToPropID g_NameToPropID[] = \r\n{\r\n  { NCoderPropID::kOrder, VT_UI4, L\"O\" },\r\n  { NCoderPropID::kPosStateBits, VT_UI4, L\"PB\" },\r\n  { NCoderPropID::kLitContextBits, VT_UI4, L\"LC\" },\r\n  { NCoderPropID::kLitPosBits, VT_UI4, L\"LP\" },\r\n  { NCoderPropID::kEndMarker, VT_BOOL, L\"eos\" },\r\n\r\n  { NCoderPropID::kNumPasses, VT_UI4, L\"Pass\" },\r\n  { NCoderPropID::kNumFastBytes, VT_UI4, L\"fb\" },\r\n  { NCoderPropID::kMatchFinderCycles, VT_UI4, L\"mc\" },\r\n  { NCoderPropID::kAlgorithm, VT_UI4, L\"a\" },\r\n  { NCoderPropID::kMatchFinder, VT_BSTR, L\"mf\" },\r\n  { NCoderPropID::kNumThreads, VT_UI4, L\"mt\" }\r\n};\r\n\r\nstatic bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp)\r\n{\r\n  if (varType == srcProp.vt)\r\n  {\r\n    destProp = srcProp;\r\n    return true;\r\n  }\r\n  if (varType == VT_UI1)\r\n  {\r\n    if (srcProp.vt == VT_UI4)\r\n    {\r\n      UInt32 value = srcProp.ulVal;\r\n      if (value > 0xFF)\r\n        return false;\r\n      destProp = (Byte)value;\r\n      return true;\r\n    }\r\n  }\r\n  else if (varType == VT_BOOL)\r\n  {\r\n    bool res;\r\n    if (SetBoolProperty(res, srcProp) != S_OK)\r\n      return false;\r\n    destProp = res;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n    \r\nstatic int FindPropIdFromStringName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)\r\n    if (name.CompareNoCase(g_NameToPropID[i].Name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID, \r\n    const NWindows::NCOM::CPropVariant &value)\r\n{\r\n  for (int j = 0; j < oneMethodInfo.Properties.Size(); j++)\r\n    if (oneMethodInfo.Properties[j].Id == propID)\r\n      return;\r\n  CProp property;\r\n  property.Id = propID;\r\n  property.Value = value;\r\n  oneMethodInfo.Properties.Add(property);\r\n}\r\n\r\nvoid COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  if (oneMethodInfo.MethodName.IsEmpty())\r\n    oneMethodInfo.MethodName = kDefaultMethodName;\r\n  \r\n  if (IsLZMAMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 dicSize = \r\n      (level >= 9 ? kLzmaDicSizeX9 : \r\n      (level >= 7 ? kLzmaDicSizeX7 : \r\n      (level >= 5 ? kLzmaDicSizeX5 : \r\n      (level >= 3 ? kLzmaDicSizeX3 : \r\n                    kLzmaDicSizeX1)))); \r\n    \r\n    UInt32 algo = \r\n      (level >= 5 ? kLzmaAlgoX5 : \r\n                    kLzmaAlgoX1); \r\n    \r\n    UInt32 fastBytes = \r\n      (level >= 7 ? kLzmaFastBytesX7 : \r\n                    kLzmaFastBytesX1); \r\n    \r\n    const wchar_t *matchFinder = \r\n      (level >= 5 ? kLzmaMatchFinderX5 : \r\n                    kLzmaMatchFinderX1); \r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsDeflateMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 fastBytes = \r\n      (level >= 9 ? kDeflateFastBytesX9 : \r\n      (level >= 7 ? kDeflateFastBytesX7 : \r\n                    kDeflateFastBytesX1));\r\n    \r\n    UInt32 numPasses = \r\n      (level >= 9 ? kDeflatePassesX9 :  \r\n      (level >= 7 ? kDeflatePassesX7 : \r\n                    kDeflatePassesX1));\r\n    \r\n    UInt32 algo = \r\n      (level >= 5 ? kDeflateAlgoX5 : \r\n                    kDeflateAlgoX1); \r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n  }\r\n  else if (IsBZip2Method(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 numPasses = \r\n      (level >= 9 ? kBZip2NumPassesX9 : \r\n      (level >= 7 ? kBZip2NumPassesX7 :  \r\n                    kBZip2NumPassesX1));\r\n    \r\n    UInt32 dicSize = \r\n      (level >= 5 ? kBZip2DicSizeX5 : \r\n      (level >= 3 ? kBZip2DicSizeX3 : \r\n                    kBZip2DicSizeX1));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsPpmdMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 useMemSize = \r\n      (level >= 9 ? kPpmdMemSizeX9 : \r\n      (level >= 7 ? kPpmdMemSizeX7 : \r\n      (level >= 5 ? kPpmdMemSizeX5 : \r\n                    kPpmdMemSizeX1)));\r\n    \r\n    UInt32 order = \r\n      (level >= 9 ? kPpmdOrderX9 : \r\n      (level >= 7 ? kPpmdOrderX7 : \r\n      (level >= 5 ? kPpmdOrderX5 : \r\n                    kPpmdOrderX1)));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order);\r\n  }\r\n}\r\n\r\nstatic void SplitParams(const UString &srcString, UStringVector &subStrings)\r\n{\r\n  subStrings.Clear();\r\n  UString name;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L':')\r\n    {\r\n      subStrings.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  subStrings.Add(name);\r\n}\r\n\r\nstatic void SplitParam(const UString &param, UString &name, UString &value)\r\n{\r\n  int eqPos = param.Find(L'=');\r\n  if (eqPos >= 0)\r\n  {\r\n    name = param.Left(eqPos);\r\n    value = param.Mid(eqPos + 1);\r\n    return;\r\n  }\r\n  for(int i = 0; i < param.Length(); i++)\r\n  {\r\n    wchar_t c = param[i];\r\n    if (c >= L'0' && c <= L'9')\r\n    {\r\n      name = param.Left(i);\r\n      value = param.Mid(i);\r\n      return;\r\n    }\r\n  }\r\n  name = param;\r\n}\r\n\r\nHRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value)\r\n{\r\n  CProp property;\r\n  if (\r\n    name.CompareNoCase(L\"D\") == 0 || \r\n    name.CompareNoCase(L\"MEM\") == 0)\r\n  {\r\n    UInt32 dicSize;\r\n    RINOK(ParsePropDictionaryValue(value, dicSize));\r\n    if (name.CompareNoCase(L\"D\") == 0)\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n    else\r\n      property.Id = NCoderPropID::kUsedMemorySize;\r\n    property.Value = dicSize;\r\n    oneMethodInfo.Properties.Add(property);\r\n  }\r\n  else\r\n  {\r\n    int index = FindPropIdFromStringName(name);\r\n    if (index < 0)\r\n      return E_INVALIDARG;\r\n    \r\n    const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n    property.Id = nameToPropID.PropID;\r\n    \r\n    NCOM::CPropVariant propValue;\r\n    \r\n    if (nameToPropID.VarType == VT_BSTR)\r\n      propValue = value;\r\n    else if (nameToPropID.VarType == VT_BOOL)\r\n    {\r\n      bool res;\r\n      if (!StringToBool(value, res))\r\n        return E_INVALIDARG;\r\n      propValue = res;\r\n    }\r\n    else\r\n    {\r\n      UInt32 number;\r\n      if (ParseStringToUInt32(value, number) == value.Length())\r\n        propValue = number;\r\n      else\r\n        propValue = value;\r\n    }\r\n    \r\n    if (!ConvertProperty(propValue, nameToPropID.VarType, property.Value))\r\n      return E_INVALIDARG;\r\n    \r\n    oneMethodInfo.Properties.Add(property);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString)\r\n{\r\n  UStringVector params;\r\n  SplitParams(srcString, params);\r\n  if (params.Size() > 0)\r\n    oneMethodInfo.MethodName = params[0];\r\n  for (int i = 1; i < params.Size(); i++)\r\n  {\r\n    const UString &param = params[i];\r\n    UString name, value;\r\n    SplitParam(param, name, value);\r\n    RINOK(SetParam(oneMethodInfo, name, value));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const UString &s)\r\n{\r\n  bool res;\r\n  if (StringToBool(s, res))\r\n  {\r\n    if (res)\r\n      InitSolid();\r\n    else\r\n      _numSolidFiles = 1;\r\n    return S_OK;\r\n  }\r\n  UString s2 = s;\r\n  s2.MakeUpper();\r\n  for (int i = 0; i < s2.Length();)\r\n  {\r\n    const wchar_t *start = ((const wchar_t *)s2) + i;\r\n    const wchar_t *end;\r\n    UInt64 v = ConvertStringToUInt64(start, &end);\r\n    if (start == end)\r\n    {\r\n      if (s2[i++] != 'E')\r\n        return E_INVALIDARG;\r\n      _solidExtension = true;\r\n      continue;\r\n    }\r\n    i += (int)(end - start);\r\n    if (i == s2.Length())\r\n      return E_INVALIDARG;\r\n    wchar_t c = s2[i++];\r\n    switch(c)\r\n    {\r\n      case 'F':\r\n        if (v < 1)\r\n          v = 1;\r\n        _numSolidFiles = v;\r\n        break;\r\n      case 'B':\r\n        _numSolidBytes = v;\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'K':\r\n        _numSolidBytes = (v << 10);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'M':\r\n        _numSolidBytes = (v << 20);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'G':\r\n        _numSolidBytes = (v << 30);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      InitSolid();\r\n      return S_OK;\r\n    case VT_BSTR:\r\n      return SetSolidSettings(value.bstrVal);\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n}\r\n\r\nvoid COutHandler::Init()\r\n{\r\n  _removeSfxBlock = false;\r\n  _compressHeaders = true;\r\n  _encryptHeaders = false;\r\n  \r\n  WriteModified = true;\r\n  WriteCreated = false;\r\n  WriteAccessed = false;\r\n  \r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  \r\n  _level = 5;\r\n  _autoFilter = true;\r\n  _volumeMode = false;\r\n  _crcSize = 4;\r\n  InitSolid();\r\n}\r\n\r\nvoid COutHandler::BeforeSetProperty()\r\n{\r\n  Init();\r\n  #ifdef COMPRESS_MT\r\n  numProcessors = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n\r\n  mainDicSize = 0xFFFFFFFF;\r\n  mainDicMethodIndex = 0xFFFFFFFF;\r\n  minNumber = 0;\r\n  _crcSize = 4;\r\n}\r\n\r\nHRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)\r\n{\r\n  UString name = nameSpec;\r\n  name.MakeUpper();\r\n  if (name.IsEmpty())\r\n    return E_INVALIDARG;\r\n  \r\n  if (name[0] == 'X')\r\n  {\r\n    name.Delete(0);\r\n    _level = 9;\r\n    return ParsePropValue(name, value, _level);\r\n  }\r\n  \r\n  if (name[0] == L'S')\r\n  {\r\n    name.Delete(0);\r\n    if (name.IsEmpty())\r\n      return SetSolidSettings(value);\r\n    if (value.vt != VT_EMPTY)\r\n      return E_INVALIDARG;\r\n    return SetSolidSettings(name);\r\n  }\r\n  \r\n  if (name == L\"CRC\")\r\n  {\r\n    _crcSize = 4;\r\n    name.Delete(0, 3);\r\n    return ParsePropValue(name, value, _crcSize);\r\n  }\r\n  \r\n  UInt32 number;\r\n  int index = ParseStringToUInt32(name, number);\r\n  UString realName = name.Mid(index);\r\n  if (index == 0)\r\n  {\r\n    if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n    {\r\n      #ifdef COMPRESS_MT\r\n      RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n      #endif\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"RSFX\") == 0)\r\n      return SetBoolProperty(_removeSfxBlock, value);\r\n    if (name.CompareNoCase(L\"F\") == 0)\r\n      return SetBoolProperty(_autoFilter, value);\r\n    if (name.CompareNoCase(L\"HC\") == 0)\r\n      return SetBoolProperty(_compressHeaders, value);\r\n    if (name.CompareNoCase(L\"HCF\") == 0)\r\n    {\r\n      bool compressHeadersFull = true;\r\n      RINOK(SetBoolProperty(compressHeadersFull, value));\r\n      if (!compressHeadersFull)\r\n        return E_INVALIDARG;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"HE\") == 0)\r\n      return SetBoolProperty(_encryptHeaders, value);\r\n    if (name.CompareNoCase(L\"TM\") == 0)\r\n      return SetBoolProperty(WriteModified, value);\r\n    if (name.CompareNoCase(L\"TC\") == 0)\r\n      return SetBoolProperty(WriteCreated, value);\r\n    if (name.CompareNoCase(L\"TA\") == 0)\r\n      return SetBoolProperty(WriteAccessed, value);\r\n    if (name.CompareNoCase(L\"V\") == 0)\r\n      return SetBoolProperty(_volumeMode, value);\r\n    number = 0;\r\n  }\r\n  if (number > 10000)\r\n    return E_FAIL;\r\n  if (number < minNumber)\r\n    return E_INVALIDARG;\r\n  number -= minNumber;\r\n  for(int j = _methods.Size(); j <= (int)number; j++)\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    _methods.Add(oneMethodInfo);\r\n  }\r\n  \r\n  COneMethodInfo &oneMethodInfo = _methods[number];\r\n  \r\n  if (realName.Length() == 0)\r\n  {\r\n    if (value.vt != VT_BSTR)\r\n      return E_INVALIDARG;\r\n    \r\n    RINOK(SetParams(oneMethodInfo, value.bstrVal));\r\n  }\r\n  else\r\n  {\r\n    CProp property;\r\n    if (realName.Left(1).CompareNoCase(L\"D\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize));\r\n      property.Id = NCoderPropID::kDictionarySize;\r\n      property.Value = dicSize;\r\n      oneMethodInfo.Properties.Add(property);\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else if (realName.Left(3).CompareNoCase(L\"MEM\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize));\r\n      property.Id = NCoderPropID::kUsedMemorySize;\r\n      property.Value = dicSize;\r\n      oneMethodInfo.Properties.Add(property);\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else\r\n    {\r\n      int index = FindPropIdFromStringName(realName);\r\n      if (index < 0)\r\n        return E_INVALIDARG;\r\n      \r\n      const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n      property.Id = nameToPropID.PropID;\r\n      \r\n      if (!ConvertProperty(value, nameToPropID.VarType, property.Value))\r\n        return E_INVALIDARG;\r\n      \r\n      oneMethodInfo.Properties.Add(property);\r\n    }\r\n  }\r\n  return S_OK;\r\n}  \r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/HandlerOut.h",
    "content": "// HandlerOut.h\r\n\r\n#ifndef __HANDLER_OUT_H\r\n#define __HANDLER_OUT_H\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\n\r\nstruct COneMethodInfo\r\n{\r\n  CObjectVector<CProp> Properties;\r\n  UString MethodName;\r\n};\r\n\r\nclass COutHandler\r\n{\r\npublic:\r\n  HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);\r\n  \r\n  HRESULT SetSolidSettings(const UString &s);\r\n  HRESULT SetSolidSettings(const PROPVARIANT &value);\r\n\r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  CObjectVector<COneMethodInfo> _methods;\r\n  bool _removeSfxBlock;\r\n  \r\n  UInt64 _numSolidFiles; \r\n  UInt64 _numSolidBytes;\r\n  bool _numSolidBytesDefined;\r\n  bool _solidExtension;\r\n\r\n  bool _compressHeaders;\r\n  bool _encryptHeaders;\r\n\r\n  bool WriteModified;\r\n  bool WriteCreated;\r\n  bool WriteAccessed;\r\n\r\n  bool _autoFilter;\r\n  UInt32 _level;\r\n\r\n  bool _volumeMode;\r\n\r\n  HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value);\r\n  HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);\r\n\r\n  void SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }\r\n  void InitSolidSize()  { _numSolidBytes = (UInt64)(Int64)(-1); }\r\n  void InitSolid()\r\n  {\r\n    InitSolidFiles();\r\n    InitSolidSize();\r\n    _solidExtension = false;\r\n    _numSolidBytesDefined = false;\r\n  }\r\n\r\n  void Init();\r\n\r\n  COutHandler() { Init(); }\r\n\r\n  void BeforeSetProperty();\r\n\r\n  UInt32 minNumber;\r\n  UInt32 numProcessors;\r\n  UInt32 mainDicSize;\r\n  UInt32 mainDicMethodIndex;\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/InStreamWithCRC.cpp",
    "content": "// InStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _size += realProcessedSize;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if (seekOrigin != STREAM_SEEK_SET || offset != 0)\r\n    return E_FAIL;\r\n  _size = 0;\r\n  _crc = CRC_INIT_VAL;\r\n  return _stream->Seek(offset, seekOrigin, newPosition);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/InStreamWithCRC.h",
    "content": "// InStreamWithCRC.h\r\n\r\n#ifndef __INSTREAMWITHCRC_H\r\n#define __INSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass CSequentialInStreamWithCRC: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CInStreamWithCRC: \r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\nprivate:\r\n  CMyComPtr<IInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(IInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/ItemNameUtils.cpp",
    "content": "// Archive/Common/ItemNameUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\nstatic const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;\r\nstatic const wchar_t kDirDelimiter = L'/';\r\n\r\nUString MakeLegalName(const UString &name)\r\n{\r\n  UString zipName = name;\r\n  zipName.Replace(kOSDirDelimiter, kDirDelimiter);\r\n  return zipName;\r\n}\r\n\r\nUString GetOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(kDirDelimiter, kOSDirDelimiter);\r\n  return newName;\r\n}\r\n\r\nUString GetOSName2(const UString &name)\r\n{\r\n  if (name.IsEmpty())\r\n    return UString();\r\n  UString newName = GetOSName(name);\r\n  if (newName[newName.Length() - 1] == kOSDirDelimiter)\r\n    newName.Delete(newName.Length() - 1);\r\n  return newName;\r\n}\r\n\r\nbool HasTailSlash(const AString &name, UINT codePage)\r\n{\r\n  if (name.IsEmpty())\r\n    return false;\r\n  LPCSTR prev = \r\n  #ifdef _WIN32\r\n    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);\r\n  #else\r\n    (LPCSTR)(name) + (name.Length() - 1);\r\n  #endif\r\n  return (*prev == '/');\r\n}\r\n\r\n#ifndef _WIN32\r\nUString WinNameToOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(L'\\\\', kOSDirDelimiter);\r\n  return newName;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/ItemNameUtils.h",
    "content": "// Archive/Common/ItemNameUtils.h\r\n\r\n#ifndef __ARCHIVE_ITEMNAMEUTILS_H\r\n#define __ARCHIVE_ITEMNAMEUTILS_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\n  UString MakeLegalName(const UString &name);\r\n  UString GetOSName(const UString &name);\r\n  UString GetOSName2(const UString &name);\r\n  bool HasTailSlash(const AString &name, UINT codePage);\r\n\r\n  #ifdef _WIN32\r\n  inline UString WinNameToOSName(const UString &name)  { return name; }\r\n  #else\r\n  UString WinNameToOSName(const UString &name);\r\n  #endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/MultiStream.cpp",
    "content": "// MultiStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MultiStream.h\"\r\n\r\nSTDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(_streamIndex < Streams.Size() && size > 0)\r\n  {\r\n    CSubStreamInfo &s = Streams[_streamIndex];\r\n    if (_pos == s.Size)\r\n    {\r\n      _streamIndex++;\r\n      _pos = 0;\r\n      continue;\r\n    }\r\n    RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));\r\n    UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));\r\n    UInt32 realProcessed;\r\n    HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _pos += realProcessed;\r\n    _seekPos += realProcessed;\r\n    RINOK(result);\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 newPos;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      newPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      newPos = _seekPos + offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      newPos = _totalLength + offset;\r\n      break;\r\n    default:\r\n      return STG_E_INVALIDFUNCTION;\r\n  }\r\n  _seekPos = 0;\r\n  for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)\r\n  {\r\n    UInt64 size = Streams[_streamIndex].Size;\r\n    if (newPos < _seekPos + size)\r\n    {\r\n      _pos = newPos - _seekPos;\r\n      _seekPos += _pos;\r\n      if (newPosition != 0)\r\n        *newPosition = newPos;\r\n      return S_OK;\r\n    }\r\n    _seekPos += size;\r\n  }\r\n  if (newPos == _seekPos)\r\n  {\r\n    if (newPosition != 0)\r\n      *newPosition = newPos;\r\n    return S_OK;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\n\r\n/*\r\nclass COutVolumeStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback, \r\n      const UString &name)  \r\n  { \r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n*/\r\n\r\n/*\r\nSTDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));\r\n      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));\r\n      subStream.Pos = 0;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n    if (_offsetPos >= subStream.Size)\r\n    {\r\n      _offsetPos -= subStream.Size;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      CMyComPtr<IOutStream> outStream;\r\n      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == subStream.Size)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/MultiStream.h",
    "content": "// MultiStream.h\r\n\r\n#ifndef __MULTISTREAM_H\r\n#define __MULTISTREAM_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nclass CMultiStream: \r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex;\r\n  UInt64 _pos;\r\n  UInt64 _seekPos;\r\n  UInt64 _totalLength;\r\npublic:\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<IInStream> Stream;\r\n    UInt64 Pos;\r\n    UInt64 Size;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _pos = 0;\r\n    _seekPos = 0;\r\n    _totalLength = 0;\r\n    for (int i = 0; i < Streams.Size(); i++)\r\n      _totalLength += Streams[i].Size;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n\r\n/*\r\nclass COutMultiStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<ISequentialOutStream> Stream;\r\n    UInt64 Size;\r\n    UInt64 Pos;\r\n };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp",
    "content": "// OutStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  if (_calculate)\r\n    _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.h",
    "content": "// OutStreamWithCRC.h\r\n\r\n#ifndef __OUTSTREAMWITHCRC_H\r\n#define __OUTSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass COutStreamWithCRC: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _calculate;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(bool calculate = true)\r\n  {\r\n    _size = 0;\r\n    _calculate = calculate;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void InitCRC() { _crc = CRC_INIT_VAL; }\r\n  UInt64 GetSize() const { return _size; }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/ParseProperties.cpp",
    "content": "// ParseProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ParseProperties.h\"\r\n\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (prop.vt == VT_UI4)\r\n  {\r\n    if (!name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    resValue = prop.ulVal;\r\n  }\r\n  else if (prop.vt == VT_EMPTY)\r\n  {\r\n    if(!name.IsEmpty())\r\n    {\r\n      const wchar_t *start = name;\r\n      const wchar_t *end;\r\n      UInt64 v = ConvertStringToUInt64(start, &end);\r\n      if (end - start != name.Length())\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)v;\r\n    }\r\n  }\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kLogarithmicSizeLimit = 32;\r\nstatic const wchar_t kByteSymbol = L'B';\r\nstatic const wchar_t kKiloByteSymbol = L'K';\r\nstatic const wchar_t kMegaByteSymbol = L'M';\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)\r\n{\r\n  UString srcString = srcStringSpec;\r\n  srcString.MakeUpper();\r\n\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || srcString.Length() > numDigits + 1)\r\n    return E_INVALIDARG;\r\n  if (srcString.Length() == numDigits)\r\n  {\r\n    if (number >= kLogarithmicSizeLimit)\r\n      return E_INVALIDARG;\r\n    dicSize = (UInt32)1 << (int)number;\r\n    return S_OK;\r\n  }\r\n  switch (srcString[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      if (number >= ((UInt64)1 << kLogarithmicSizeLimit))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)number;\r\n      break;\r\n    case kKiloByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 10);\r\n      break;\r\n    case kMegaByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 20);\r\n      break;\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    if (prop.vt == VT_UI4)\r\n    {\r\n      UInt32 logDicSize = prop.ulVal;\r\n      if (logDicSize >= 32)\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)1 << logDicSize;\r\n      return S_OK;\r\n    }\r\n    if (prop.vt == VT_BSTR)\r\n      return ParsePropDictionaryValue(prop.bstrVal, resValue);\r\n    return E_INVALIDARG;\r\n  }\r\n  return ParsePropDictionaryValue(name, resValue);\r\n}\r\n\r\nbool StringToBool(const UString &s, bool &res)\r\n{\r\n  if (s.IsEmpty() || s.CompareNoCase(L\"ON\") == 0)\r\n  {\r\n    res = true;\r\n    return true;\r\n  }\r\n  if (s.CompareNoCase(L\"OFF\") == 0)\r\n  {\r\n    res = false;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      dest = true;\r\n      return S_OK;\r\n    /*\r\n    case VT_UI4:\r\n      dest = (value.ulVal != 0);\r\n      break;\r\n    */\r\n    case VT_BSTR:\r\n      return StringToBool(value.bstrVal, dest) ?  S_OK : E_INVALIDARG;\r\n  }\r\n  return E_INVALIDARG;\r\n}\r\n\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number)\r\n{\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number64 = ConvertStringToUInt64(start, &end);\r\n  if (number64 > 0xFFFFFFFF) \r\n  {\r\n    number = 0;\r\n    return 0;\r\n  }\r\n  number = (UInt32)number64;\r\n  return (int)(end - start);\r\n}\r\n\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    switch(prop.vt)\r\n    {\r\n      case VT_UI4:\r\n        numThreads = prop.ulVal;\r\n        break;\r\n      default:\r\n      {\r\n        bool val; \r\n        RINOK(SetBoolProperty(val, prop));\r\n        numThreads = (val ? defaultNumThreads : 1);\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index != name.Length())\r\n      return E_INVALIDARG;\r\n    numThreads = number;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/Common/ParseProperties.h",
    "content": "// ParseProperties.h\r\n\r\n#ifndef __PARSEPROPERTIES_H\r\n#define __PARSEPROPERTIES_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\n\r\nbool StringToBool(const UString &s, bool &res);\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number);\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/DllExports2.cpp",
    "content": "// DLLExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyInitGuid.h\"\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\nextern \"C\" \r\n{ \r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nHINSTANCE g_hInstance;\r\n#ifndef _UNICODE\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)\r\n{\r\n  if (dwReason == DLL_PROCESS_ATTACH)\r\n  {\r\n    g_hInstance = hInstance;\r\n    #ifndef _UNICODE\r\n    #ifdef _WIN32\r\n    g_IsNT = IsItWindowsNT();\r\n    #endif\r\n    #endif\r\n  }\r\n  return TRUE;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler, \r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec, \r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);\r\nSTDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);\r\n\r\nSTDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  // COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)\r\n  {\r\n    return CreateCoder(clsid, iid, outObject);\r\n  }\r\n  else\r\n  {\r\n    return CreateArchiver(clsid, iid, outObject);\r\n  }\r\n  // COM_TRY_END\r\n}\r\n\r\nSTDAPI SetLargePageMode()\r\n{\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  SetLargePageSize();\r\n  #endif\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Archive/IArchive.h",
    "content": "// IArchive.h\r\n\r\n#ifndef __IARCHIVE_H\r\n#define __IARCHIVE_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../IProgress.h\"\r\n#include \"../PropID.h\"\r\n\r\n#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)\r\n#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nnamespace NFileTimeType\r\n{\r\n  enum EEnum\r\n  {\r\n    kWindows,\r\n    kUnix,\r\n    kDOS\r\n  };\r\n}\r\n\r\nnamespace NArchive\r\n{\r\n  enum \r\n  {\r\n    kName = 0,\r\n    kClassID,\r\n    kExtension,\r\n    kAddExtension,\r\n    kUpdate,\r\n    kKeepName,\r\n    kStartSignature,\r\n    kFinishSignature,\r\n    kAssociate\r\n  };\r\n\r\n  namespace NExtract\r\n  {\r\n    namespace NAskMode\r\n    {\r\n      enum \r\n      {\r\n        kExtract = 0,\r\n        kTest,\r\n        kSkip\r\n      };\r\n    }\r\n    namespace NOperationResult\r\n    {\r\n      enum \r\n      {\r\n        kOK = 0,\r\n        kUnSupportedMethod,\r\n        kDataError,\r\n        kCRCError\r\n      };\r\n    }\r\n  }\r\n  namespace NUpdate\r\n  {\r\n    namespace NOperationResult\r\n    {\r\n      enum \r\n      {\r\n        kOK = 0,\r\n        kError\r\n      };\r\n    }\r\n  }\r\n}\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)\r\n{\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, \r\n      Int32 askExtractMode) PURE;\r\n  // GetStream OUT: S_OK - OK, S_FALSE - skeep this file\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)\r\n{\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;  \r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)\r\n{\r\n  STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;\r\n};\r\n\r\n\r\n/*\r\nIInArchive::Extract:\r\n  indices must be sorted \r\n  numItems = 0xFFFFFFFF means \"all files\"\r\n  testMode != 0 means \"test files without writing to outStream\"\r\n*/\r\n\r\n#define INTERFACE_IInArchive(x) \\\r\n  STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \\\r\n  STDMETHOD(Close)() x; \\\r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \\\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \\\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;\r\n\r\nARCHIVE_INTERFACE(IInArchive, 0x60)\r\n{\r\n  INTERFACE_IInArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)\r\n{\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index, \r\n      Int32 *newData, // 1 - new data, 0 - old data\r\n      Int32 *newProperties, // 1 - new properties, 0 - old properties\r\n      UInt32 *indexInArchive // -1 if there is no in archive, or if doesn't matter\r\n      ) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)\r\n{\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) PURE;\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) PURE;\r\n};\r\n\r\n\r\n#define INTERFACE_IOutArchive(x) \\\r\n  STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \\\r\n  STDMETHOD(GetFileTimeType)(UInt32 *type) x;\r\n\r\nARCHIVE_INTERFACE(IOutArchive, 0xA0)\r\n{\r\n  INTERFACE_IOutArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(ISetProperties, 0x03)\r\n{\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;\r\n};\r\n\r\n\r\n#define IMP_IInArchive_GetProp(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \\\r\n\r\n#define IMP_IInArchive_GetProp_WITH_NAME(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; \\\r\n    if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \\\r\n\r\n#define IMP_IInArchive_Props \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)\r\n\r\n#define IMP_IInArchive_Props_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)\r\n\r\n\r\n#define IMP_IInArchive_ArcProps \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_NO \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = 0; return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \\\r\n    { return E_NOTIMPL; } \\\r\n  STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \\\r\n    { value->vt = VT_EMPTY; return S_OK; } \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Alone7z/Alone.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Alone\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Alone - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\" CFG=\"Alone - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Alone - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Alone - Win32 Release\"\r\n# Name \"Alone - Win32 Debug\"\r\n# Name \"Alone - Win32 ReleaseU\"\r\n# Name \"Alone - Win32 DebugU\"\r\n# Begin Group \"Console\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ArError.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\CompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\Main.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\MainAr.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\AutoPtr.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Buffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ComTry.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\DynamicBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyException.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyGuidDef.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyInitGuid.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Device.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Handle.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LSBFEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MSBFDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MSBFEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterArc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterCodec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\BranchCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\Coder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86_2.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Branch\\x86_2.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Copy\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Copy\\CopyCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Copy\\CopyCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Copy\\CopyRegister.cpp\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZ\\LZOutWindow.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMADecoder.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMAEncoder.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA\\LZMARegister.cpp\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderBit.cpp\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# ADD CPP /O1\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_Alone\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Archive\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"7z\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zExtract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"split\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"UI Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Property.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7-zip\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IMyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IPassword.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\PropID.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"C Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARM.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARM.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARMThumb.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchARMThumb.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchIA64.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchIA64.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchPPC.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchPPC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchSPARC.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchSPARC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Alone7z/Alone.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Alone\"=.\\Alone.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Alone7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Alone7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Alone7z/makefile",
    "content": "PROG = 7za.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib Advapi32.lib\r\n\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -D_NO_CRYPTO \\\r\n  -DWIN_LONG_PATH \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OffsetStream.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\DummyOutStream.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\MultiStream.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n\r\n\r\nBRANCH_OPT_OBJS = \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\x86.obj \\\r\n  $O\\x86_2.obj \\\r\n  $O\\ARM.obj \\\r\n  $O\\ARMThumb.obj \\\r\n  $O\\IA64.obj \\\r\n  $O\\PPC.obj \\\r\n  $O\\SPARC.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\BCJRegister.obj \\\r\n  $O\\BCJ2Register.obj \\\r\n\r\nSWAP_OPT_OBJS = \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n\r\nCOPY_OBJS = \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n  $O\\LZMARegister.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Sort.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZ_OBJS = \\\r\n  $O\\MatchFinder.obj \\\r\n  $O\\MatchFinderMt.obj \\\r\n\r\nC_BRANCH_OBJS = \\\r\n  $O\\BranchARM.obj \\\r\n  $O\\BranchARMThumb.obj \\\r\n  $O\\BranchIA64.obj \\\r\n  $O\\BranchPPC.obj \\\r\n  $O\\BranchSPARC.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(BRANCH_OPT_OBJS) \\\r\n  $(SWAP_OPT_OBJS) \\\r\n  $(COPY_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZ_OBJS) \\\r\n  $(C_BRANCH_OBJS) \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): ../../UI/Console/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../../UI/Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Alone7z/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_APP(\"7-Zip Standalone Console\", \"7za\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Format7zExtractR/makefile",
    "content": "PROG = 7zxr.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DEXTRACT_ONLY \\\r\n  -DCOMPRESS_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n\r\nSWAP_OPT_OBJS = \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n\r\nBRANCH_OPT_OBJS = \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\x86.obj \\\r\n  $O\\x86_2.obj \\\r\n  $O\\ARM.obj \\\r\n  $O\\ARMThumb.obj \\\r\n  $O\\IA64.obj \\\r\n  $O\\PPC.obj \\\r\n  $O\\SPARC.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\BCJRegister.obj \\\r\n  $O\\BCJ2Register.obj \\\r\n\r\nCOPY_OBJS = \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMARegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_BRANCH_OBJS = \\\r\n  $O\\BranchARM.obj \\\r\n  $O\\BranchARMThumb.obj \\\r\n  $O\\BranchIA64.obj \\\r\n  $O\\BranchPPC.obj \\\r\n  $O\\BranchSPARC.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(BRANCH_OPT_OBJS) \\\r\n  $(SWAP_OPT_OBJS) \\\r\n  $(COPY_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_BRANCH_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Format7zExtractR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Extracting Plugin\", \"7zxr\")\r\n\r\n101  ICON  \"../../Archive/7z/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Format7zR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Format7zR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Format7zR/makefile",
    "content": "PROG = 7zra.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n\r\nBRANCH_OPT_OBJS = \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\x86.obj \\\r\n  $O\\x86_2.obj \\\r\n  $O\\ARM.obj \\\r\n  $O\\ARMThumb.obj \\\r\n  $O\\IA64.obj \\\r\n  $O\\PPC.obj \\\r\n  $O\\SPARC.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\BCJRegister.obj \\\r\n  $O\\BCJ2Register.obj \\\r\n\r\nSWAP_OPT_OBJS = \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n\r\nCOPY_OBJS = \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n  $O\\LZMARegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Sort.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZ_OBJS = \\\r\n  $O\\MatchFinder.obj \\\r\n  $O\\MatchFinderMt.obj \\\r\n\r\nC_BRANCH_OBJS = \\\r\n  $O\\BranchARM.obj \\\r\n  $O\\BranchARMThumb.obj \\\r\n  $O\\BranchIA64.obj \\\r\n  $O\\BranchPPC.obj \\\r\n  $O\\BranchSPARC.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(BZIP2_OBJS) \\\r\n  $(BZIP2_OPT_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(BRANCH_OPT_OBJS) \\\r\n  $(SWAP_OPT_OBJS) \\\r\n  $(COPY_OBJS) \\\r\n  $(DEFLATE_OPT_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(PPMD_OPT_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZ_OBJS) \\\r\n  $(C_BRANCH_OBJS) \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(BRANCH_OPT_OBJS): ../../Compress/Branch/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(SWAP_OPT_OBJS): ../../Compress/ByteSwap/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COPY_OBJS): ../../Compress/Copy/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../../Compress/LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../../Compress/LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$O\\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Bundles/Format7zR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Plugin\", \"7zr\")\r\n\r\n101  ICON  \"../../Archive/7z/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/CreateCoder.cpp",
    "content": "// CreateCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CreateCoder.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Windows/Defs.h\"\r\n#include \"FilterCoder.h\"\r\n#include \"RegisterCodec.h\"\r\n\r\nstatic const unsigned int kNumCodecsMax = 64;\r\nunsigned int g_NumCodecs = 0;\r\nconst CCodecInfo *g_Codecs[kNumCodecsMax]; \r\nvoid RegisterCodec(const CCodecInfo *codecInfo) \r\n{ \r\n  if (g_NumCodecs < kNumCodecsMax)\r\n    g_Codecs[g_NumCodecs++] = codecInfo; \r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = 1;\r\n  else if (prop.vt == VT_UI4)\r\n    res = prop.ulVal;\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = true;\r\n  else if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs)\r\n{\r\n  UInt32 num;\r\n  RINOK(codecsInfo->GetNumberOfMethods(&num));\r\n  for (UInt32 i = 0; i < num; i++)\r\n  {\r\n    CCodecInfoEx info;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kID, &prop));\r\n    // if (prop.vt != VT_BSTR)\r\n    // info.Id.IDSize = (Byte)SysStringByteLen(prop.bstrVal);\r\n    // memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);\r\n    if (prop.vt != VT_UI8)\r\n    {\r\n      continue; // old Interface \r\n      // return E_INVALIDARG;\r\n    }\r\n    info.Id = prop.uhVal.QuadPart;\r\n    prop.Clear();\r\n    \r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      info.Name = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_INVALIDARG;;\r\n    \r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kInStreams, info.NumInStreams));\r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kOutStreams, info.NumOutStreams));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned));\r\n    \r\n    externalCodecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  const UString &name,\r\n  CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i]; \r\n    if (name.CompareNoCase(codec.Name) == 0)\r\n    {\r\n      methodId = codec.Id;\r\n      numInStreams = codec.NumInStreams;\r\n      numOutStreams = 1;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i]; \r\n      if (codec.Name.CompareNoCase(name) == 0)\r\n      {\r\n        methodId = codec.Id;\r\n        numInStreams = codec.NumInStreams;\r\n        numOutStreams = codec.NumOutStreams;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  CMethodId methodId, UString &name)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i]; \r\n    if (methodId == codec.Id)\r\n    {\r\n      name = codec.Name;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i]; \r\n      if (methodId == codec.Id)\r\n      {\r\n        name = codec.Name;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder)\r\n{\r\n  bool created = false;\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i]; \r\n    if (codec.Id == methodId)\r\n    {\r\n      if (encode)\r\n      {\r\n        if (codec.CreateEncoder)\r\n        {\r\n          void *p = codec.CreateEncoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n      }\r\n      else\r\n        if (codec.CreateDecoder)\r\n        {\r\n          void *p = codec.CreateDecoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  if (!created && externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i]; \r\n      if (codec.Id == methodId)\r\n      {\r\n        if (encode)\r\n        {\r\n          if (codec.EncoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE) \r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n        }\r\n        else\r\n          if (codec.DecoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE) \r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n      }\r\n    }\r\n  #endif\r\n\r\n  if (onlyCoder && filter)\r\n  {\r\n    CFilterCoder *coderSpec = new CFilterCoder;\r\n    coder = coderSpec;\r\n    coderSpec->Filter = filter;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, \r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, true);\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    coder, coder2, encode);\r\n}\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressCoder> coder;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, false);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/CreateCoder.h",
    "content": "// CreateCoder.h\r\n\r\n#ifndef __CREATECODER_H\r\n#define __CREATECODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nstruct CCodecInfoEx\r\n{\r\n  UString Name;\r\n  CMethodId Id;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }\r\n  CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}\r\n};\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)\r\n#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);\r\n#define IMPL_ISetCompressCodecsInfo2(x) \\\r\nSTDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \\\r\n  COM_TRY_BEGIN _codecsInfo = compressCodecsInfo;  return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }\r\n#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)\r\n\r\n#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs\r\n#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,\r\n#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,\r\n\r\n#else\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo\r\n#define DECL_ISetCompressCodecsInfo\r\n#define IMPL_ISetCompressCodecsInfo\r\n#define EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_VARS\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2\r\n#define EXTERNAL_CODECS_LOC_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS\r\n#define EXTERNAL_CODECS_LOC_VARS\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, UString &name);\r\n\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, \r\n  CMyComPtr<ICompressCoder> &coder, bool encode);\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/FilePathAutoRename.cpp",
    "content": "// FilePathAutoRename.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"FilePathAutoRename.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic bool MakeAutoName(const UString &name, \r\n    const UString &extension, int value, UString &path)\r\n{\r\n  wchar_t number[32];\r\n  ConvertUInt64ToString(value, number);\r\n  path = name;\r\n  path += number;\r\n  path += extension;\r\n  return NFile::NFind::DoesFileExist(path);\r\n}\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath)\r\n{\r\n  UString path;\r\n  int dotPos = fullProcessedPath.ReverseFind(L'.');\r\n\r\n  int slashPos = fullProcessedPath.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = fullProcessedPath.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n\r\n  UString name, extension;\r\n  if (dotPos > slashPos &&  dotPos > 0)\r\n  {\r\n    name = fullProcessedPath.Left(dotPos);\r\n    extension = fullProcessedPath.Mid(dotPos);\r\n  }\r\n  else\r\n    name = fullProcessedPath;\r\n  name += L'_';\r\n  int indexLeft = 1, indexRight = (1 << 30);\r\n  while (indexLeft != indexRight)\r\n  {\r\n    int indexMid = (indexLeft + indexRight) / 2;\r\n    if (MakeAutoName(name, extension, indexMid, path))\r\n      indexLeft = indexMid + 1;\r\n    else\r\n      indexRight = indexMid;\r\n  }\r\n  if (MakeAutoName(name, extension, indexRight, fullProcessedPath))\r\n    return false;\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/FilePathAutoRename.h",
    "content": "// Util/FilePathAutoRename.h\r\n\r\n#ifndef __FILEPATHAUTORENAME_H\r\n#define __FILEPATHAUTORENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  #ifdef _WIN32\r\n  if (result)\r\n    return S_OK;\r\n  DWORD lastError = ::GetLastError();\r\n  if (lastError == 0)\r\n    return E_FAIL;\r\n  return lastError;\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nbool CInFileStream::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), \r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nHRESULT COutFileStream::Close()\r\n{\r\n  return ConvertBoolToHRESULT(File.Close());\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  ProcessedSize += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  ProcessedSize += res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15); \r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), \r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WIN_FILE\r\n#endif\r\n\r\n#ifdef USE_WIN_FILE\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\npublic:\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #endif\r\n  #endif\r\n\r\n  HRESULT Close();\r\n  \r\n  UInt64 ProcessedSize;\r\n\r\n  #ifdef USE_WIN_FILE\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  {\r\n    return File.SetTime(creationTime, lastAccessTime, lastWriteTime);\r\n  }\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {\r\n    return File.SetLastWriteTime(lastWriteTime);\r\n  }\r\n  #endif\r\n\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/FilterCoder.cpp",
    "content": "// FilterCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FilterCoder.h\"\r\nextern \"C\" \r\n{ \r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#include \"../../Common/Defs.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCFilterCoder::CFilterCoder()\r\n{ \r\n  _buffer = (Byte *)::MidAlloc(kBufferSize); \r\n}\r\n\r\nCFilterCoder::~CFilterCoder() \r\n{ \r\n  ::MidFree(_buffer); \r\n}\r\n\r\nHRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)\r\n{\r\n  if (_outSizeIsDefined)\r\n  {\r\n    UInt64 remSize = _outSize - _nowPos64;\r\n    if (size > remSize)\r\n      size = (UInt32)remSize;\r\n  }\r\n  UInt32 processedSize = 0;\r\n  RINOK(WriteStream(outStream, _buffer, size, &processedSize));\r\n  if (size != processedSize)\r\n    return E_FAIL;\r\n  _nowPos64 += processedSize;\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  RINOK(Init());\r\n  UInt32 bufferPos = 0;\r\n  _outSizeIsDefined = (outSize != 0);\r\n  if (_outSizeIsDefined)\r\n    _outSize = *outSize;\r\n\r\n  while(NeedMore())\r\n  {\r\n    UInt32 processedSize;\r\n    \r\n    // Change it: It can be optimized using ReadPart\r\n    RINOK(ReadStream(inStream, _buffer + bufferPos, kBufferSize - bufferPos, &processedSize));\r\n    \r\n    UInt32 endPos = bufferPos + processedSize;\r\n\r\n    bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (bufferPos > endPos)\r\n    {\r\n      for (; endPos< bufferPos; endPos++)\r\n        _buffer[endPos] = 0;\r\n      bufferPos = Filter->Filter(_buffer, endPos);\r\n    }\r\n\r\n    if (bufferPos == 0)\r\n    {\r\n      if (endPos > 0)\r\n        return WriteWithLimit(outStream, endPos);\r\n      return S_OK;\r\n    }\r\n    RINOK(WriteWithLimit(outStream, bufferPos));\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));\r\n    }\r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n// #ifdef _ST_MODE\r\nSTDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _bufferPos = 0;\r\n  _outStream = outStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseOutStream()\r\n{\r\n  _outStream.Release();\r\n  return S_OK;\r\n};\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    UInt32 sizeMax = kBufferSize - _bufferPos;\r\n    UInt32 sizeTemp = size;\r\n    if (sizeTemp > sizeMax)\r\n      sizeTemp = sizeMax;\r\n    memmove(_buffer + _bufferPos, data, sizeTemp);\r\n    size -= sizeTemp;\r\n    processedSizeTotal += sizeTemp;\r\n    data = (const Byte *)data + sizeTemp;\r\n    UInt32 endPos = _bufferPos + sizeTemp;\r\n    _bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (_bufferPos == 0)\r\n    {\r\n      _bufferPos = endPos;\r\n      break;\r\n    }\r\n    if (_bufferPos > endPos)\r\n    {\r\n      if (size != 0)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    RINOK(WriteWithLimit(_outStream, _bufferPos));\r\n    UInt32 i = 0;\r\n    while(_bufferPos < endPos)\r\n      _buffer[i++] = _buffer[_bufferPos++];\r\n    _bufferPos = i;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::Flush()\r\n{\r\n  if (_bufferPos != 0)\r\n  {\r\n    UInt32 endPos = Filter->Filter(_buffer, _bufferPos);\r\n    if (endPos > _bufferPos)\r\n    {\r\n      for (; _bufferPos < endPos; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      if (Filter->Filter(_buffer, endPos) != endPos)\r\n        return E_FAIL;\r\n    }\r\n    UInt32 processedSize;\r\n    RINOK(WriteStream(_outStream, _buffer, _bufferPos, &processedSize));\r\n    if (_bufferPos != processedSize)\r\n      return E_FAIL;\r\n    _bufferPos = 0;\r\n  }\r\n  CMyComPtr<IOutStreamFlush> flush;\r\n  _outStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n  if (flush)\r\n    return  flush->Flush();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _convertedPosBegin = _convertedPosEnd = _bufferPos = 0;\r\n  _inStream = inStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseInStream()\r\n{\r\n  _inStream.Release();\r\n  return S_OK;\r\n};\r\n\r\nSTDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_convertedPosBegin != _convertedPosEnd)\r\n    {\r\n      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);\r\n      memmove(data, _buffer + _convertedPosBegin, sizeTemp);\r\n      _convertedPosBegin += sizeTemp;\r\n      data = (void *)((Byte *)data + sizeTemp);\r\n      size -= sizeTemp;\r\n      processedSizeTotal += sizeTemp;\r\n      break;\r\n    }\r\n    int i;\r\n    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)\r\n      _buffer[i] = _buffer[i + _convertedPosEnd];\r\n    _bufferPos = i;\r\n    _convertedPosBegin = _convertedPosEnd = 0;\r\n    UInt32 processedSizeTemp;\r\n    UInt32 size0 = kBufferSize - _bufferPos;\r\n    // Optimize it:\r\n    RINOK(ReadStream(_inStream, _buffer + _bufferPos, size0, &processedSizeTemp));\r\n    _bufferPos = _bufferPos + processedSizeTemp;\r\n    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    if (_convertedPosEnd == 0)\r\n    {\r\n      if (_bufferPos == 0)\r\n        break;\r\n      else\r\n      {\r\n        _convertedPosEnd = _bufferPos; // check it\r\n        continue;\r\n      }\r\n    }\r\n    if (_convertedPosEnd > _bufferPos)\r\n    {\r\n      for (; _bufferPos < _convertedPosEnd; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\n// #endif // _ST_MODE\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)\r\n{\r\n  return _setPassword->CryptoSetPassword(data, size);\r\n}\r\n#endif\r\n\r\n#ifndef EXTRACT_ONLY\r\nSTDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  return _writeCoderProperties->WriteCoderProperties(outStream);\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CFilterCoder::ResetSalt()\r\n{\r\n  return _CryptoResetSalt->ResetSalt();\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CFilterCoder::ResetInitVector()\r\n{\r\n  return _CryptoResetInitVector->ResetInitVector();\r\n}\r\n#endif\r\n\r\nSTDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)\r\n{\r\n  return _setDecoderProperties->SetDecoderProperties2(data, size);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/FilterCoder.h",
    "content": "// FilterCoder.h\r\n\r\n#ifndef __FILTERCODER_H\r\n#define __FILTERCODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \\\r\n{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \\\r\n*outObject = (void *)(i *)this; AddRef(); return S_OK; } \r\n\r\nclass CFilterCoder:\r\n  public ICompressCoder,\r\n  // #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ISequentialInStream,\r\n  public ICompressSetOutStream,\r\n  public ISequentialOutStream,\r\n  public IOutStreamFlush,\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoSetPassword,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  // public ICryptoResetSalt,\r\n  public ICryptoResetInitVector,\r\n  #endif\r\n  public ICompressSetDecoderProperties2,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  // #ifdef _ST_MODE\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  CMyComPtr<ISequentialOutStream> _outStream;\r\n  UInt32 _bufferPos;\r\n  UInt32 _convertedPosBegin;\r\n  UInt32 _convertedPosEnd;\r\n  // #endif\r\n  bool _outSizeIsDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _nowPos64;\r\n\r\n  HRESULT Init() \r\n  { \r\n    _nowPos64 = 0;\r\n    _outSizeIsDefined = false;\r\n    return Filter->Init(); \r\n  }\r\n\r\n  CMyComPtr<ICryptoSetPassword> _setPassword;\r\n  #ifndef EXTRACT_ONLY\r\n  CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;\r\n  CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;\r\n  // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;\r\n  CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;\r\n  #endif\r\n  CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;\r\npublic:\r\n  CMyComPtr<ICompressFilter> Filter;\r\n\r\n  CFilterCoder();\r\n  ~CFilterCoder();\r\n  HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);\r\n  bool NeedMore() const  \r\n    { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }\r\n\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n    MY_QUERYINTERFACE_ENTRY(ICompressCoder)\r\n    // #ifdef _ST_MODE\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialInStream)\r\n\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)\r\n    // #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)\r\n    #endif\r\n\r\n    #ifndef EXTRACT_ONLY\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)\r\n    // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)\r\n    #endif\r\n\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  // #ifdef _ST_MODE\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \\\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Flush)();\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  // STDMETHOD(ResetSalt)();\r\n  STDMETHOD(ResetInitVector)();\r\n  #endif\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n};\r\n\r\n// #ifdef _ST_MODE\r\nclass CInStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  CInStreamReleaser(): FilterCoder(0) {}\r\n  ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }\r\n};\r\n\r\nclass COutStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  COutStreamReleaser(): FilterCoder(0) {}\r\n  ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }\r\n};\r\n// #endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nCInBuffer::CInBuffer(): \r\n  _buffer(0), \r\n  _bufferLimit(0), \r\n  _bufferBase(0), \r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct CInBufferException: public CSystemException \r\n{\r\n  CInBufferException(HRESULT errorCode): CSystemException(errorCode) {} \r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      if(!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)\r\n  {\r\n    for(processedSize = 0; processedSize < size; processedSize++)\r\n      if (!ReadByte(((Byte *)data)[processedSize]))\r\n        return;\r\n  }\r\n  bool ReadBytes(void *data, UInt32 size)\r\n  {\r\n    UInt32 processedSize;\r\n    ReadBytes(data, size, processedSize);\r\n    return (processedSize == size);\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/InOutTempBuffer.cpp",
    "content": "// InOutTempBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InOutTempBuffer.h\"\r\n#include \"../../Common/Defs.h\"\r\n// #include \"Windows/Defs.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic UInt32 kTmpBufferMemorySize = (1 << 20);\r\n\r\nstatic LPCTSTR kTempFilePrefixString = TEXT(\"iot\");\r\n\r\nCInOutTempBuffer::CInOutTempBuffer():\r\n  _buffer(NULL)\r\n{\r\n}\r\n\r\nvoid CInOutTempBuffer::Create()\r\n{\r\n  _buffer = new Byte[kTmpBufferMemorySize];\r\n}\r\n\r\nCInOutTempBuffer::~CInOutTempBuffer()\r\n{\r\n  delete []_buffer;\r\n}\r\nvoid CInOutTempBuffer::InitWriting()\r\n{\r\n  _bufferPosition = 0;\r\n  _tmpFileCreated = false;\r\n  _fileSize = 0;\r\n}\r\n\r\nbool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)\r\n{\r\n  if (size == 0)\r\n    return true;\r\n  if(!_tmpFileCreated)\r\n  {\r\n    CSysString tempDirPath;\r\n    if(!MyGetTempPath(tempDirPath))\r\n      return false;\r\n    if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)\r\n      return false;\r\n    // _outFile.SetOpenCreationDispositionCreateAlways();\r\n    if(!_outFile.Create(_tmpFileName, true))\r\n      return false;\r\n    _tmpFileCreated = true;\r\n  }\r\n  UInt32 processedSize;\r\n  if(!_outFile.Write(data, size, processedSize))\r\n    return false;\r\n  _fileSize += processedSize;\r\n  return (processedSize == size);\r\n}\r\n\r\nbool CInOutTempBuffer::FlushWrite()\r\n{\r\n  return _outFile.Close();\r\n}\r\n\r\nbool CInOutTempBuffer::Write(const void *data, UInt32 size)\r\n{\r\n  if(_bufferPosition < kTmpBufferMemorySize)\r\n  {\r\n    UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);\r\n    memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);\r\n    _bufferPosition += curSize;\r\n    size -= curSize;\r\n    data = ((const Byte *)data) + curSize;\r\n    _fileSize += curSize;\r\n  }\r\n  return WriteToFile(data, size);\r\n}\r\n\r\nbool CInOutTempBuffer::InitReading()\r\n{\r\n  _currentPositionInBuffer = 0;\r\n  if(_tmpFileCreated)\r\n    return _inFile.Open(_tmpFileName);\r\n  return true;\r\n}\r\n\r\nHRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)\r\n{\r\n  if (_currentPositionInBuffer < _bufferPosition)\r\n  {\r\n    UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;\r\n    RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite, NULL));\r\n    _currentPositionInBuffer += sizeToWrite;\r\n  }\r\n  if (!_tmpFileCreated)\r\n    return true;\r\n  for (;;)\r\n  {\r\n    UInt32 localProcessedSize;\r\n    if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))\r\n      return E_FAIL;\r\n    if (localProcessedSize == 0)\r\n      return S_OK;\r\n    RINOK(WriteStream(stream, _buffer, localProcessedSize, NULL));\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (!_buffer->Write(data, size))\r\n  {\r\n    if (processedSize != NULL)\r\n      *processedSize = 0;\r\n    return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/InOutTempBuffer.h",
    "content": "// Util/InOutTempBuffer.h\r\n\r\n#ifndef __IN_OUT_TEMP_BUFFER_H\r\n#define __IN_OUT_TEMP_BUFFER_H\r\n\r\n#include \"../../Windows/FileIO.h\"\r\n#include \"../../Windows/FileDir.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../IStream.h\"\r\n\r\nclass CInOutTempBuffer\r\n{\r\n  NWindows::NFile::NDirectory::CTempFile _tempFile;\r\n  NWindows::NFile::NIO::COutFile _outFile;\r\n  NWindows::NFile::NIO::CInFile _inFile;\r\n  Byte *_buffer;\r\n  UInt32 _bufferPosition;\r\n  UInt32 _currentPositionInBuffer;\r\n  CSysString _tmpFileName;\r\n  bool _tmpFileCreated;\r\n\r\n  UInt64 _fileSize;\r\n\r\n  bool WriteToFile(const void *data, UInt32 size);\r\npublic:\r\n  CInOutTempBuffer();\r\n  ~CInOutTempBuffer();\r\n  void Create();\r\n\r\n  void InitWriting();\r\n  bool Write(const void *data, UInt32 size);\r\n  UInt64 GetDataSize() const { return _fileSize; }\r\n  bool FlushWrite();\r\n  bool InitReading();\r\n  HRESULT WriteToStream(ISequentialOutStream *stream);\r\n};\r\n\r\nclass CSequentialOutTempBufferImp: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CInOutTempBuffer *_buffer;\r\npublic:\r\n  // CSequentialOutStreamImp(): _size(0) {}\r\n  // UInt32 _size;\r\n  void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }\r\n  // UInt32 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/LimitedStreams.cpp",
    "content": "// LimitedStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LimitedStreams.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\nSTDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size);\r\n  HRESULT result = S_OK;\r\n  if (sizeToRead > 0)\r\n  {\r\n    result = _stream->Read(data, sizeToRead, &realProcessedSize);\r\n    _pos += realProcessedSize;\r\n    if (realProcessedSize == 0)\r\n      _wasFinished = true;\r\n  }\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/LimitedStreams.h",
    "content": "// LimitedStreams.h\r\n\r\n#ifndef __LIMITEDSTREAMS_H\r\n#define __LIMITEDSTREAMS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLimitedSequentialInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt64 _pos;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream; }\r\n  void Init(UInt64 streamSize)  \r\n  { \r\n    _size = streamSize; \r\n    _pos = 0; \r\n    _wasFinished = false; \r\n  }\r\n \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _pos; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/LockedStream.cpp",
    "content": "// LockedStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LockedStream.h\"\r\n\r\nHRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size, \r\n  UInt32 *processedSize)\r\n{\r\n  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);\r\n  RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));\r\n  return _stream->Read(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);\r\n  _pos += realProcessedSize;\r\n  if (processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/LockedStream.h",
    "content": "// LockedStream.h\r\n\r\n#ifndef __LOCKEDSTREAM_H\r\n#define __LOCKEDSTREAM_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLockedInStream\r\n{\r\n  CMyComPtr<IInStream> _stream;\r\n  NWindows::NSynchronization::CCriticalSection _criticalSection;\r\npublic:\r\n  void Init(IInStream *stream)\r\n    { _stream = stream; }\r\n  HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CLockedSequentialInStreamImp: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CLockedInStream *_lockedInStream;\r\n  UInt64 _pos;\r\npublic:\r\n  void Init(CLockedInStream *lockedInStream, UInt64 startPos)\r\n  {\r\n    _lockedInStream = lockedInStream;\r\n    _pos = startPos;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/MethodId.cpp",
    "content": "// MethodId.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodId.h\"\r\n#include \"../../Common/MyString.h\"\r\n\r\nstatic inline wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nUString ConvertMethodIdToString(UInt64 id)\r\n{\r\n  wchar_t s[32];\r\n  int len = 32;\r\n  s[--len] = 0;\r\n  do\r\n  {\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n  }\r\n  while (id != 0);\r\n  return s + len;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/MethodId.h",
    "content": "// MethodId.h\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Common/Types.h\"\r\n\r\ntypedef UInt64 CMethodId;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/MethodProps.cpp",
    "content": "// MethodProps.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodProps.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nstatic UInt64 k_LZMA = 0x030101;\r\n// static UInt64 k_LZMA2 = 0x030102;\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)\r\n{\r\n  bool tryReduce = false;\r\n  UInt32 reducedDictionarySize = 1 << 10;\r\n  if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))\r\n  {\r\n    for (;;)\r\n    {\r\n      const UInt32 step = (reducedDictionarySize >> 1);\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      reducedDictionarySize += step;\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      if (reducedDictionarySize >= ((UInt32)3 << 30))\r\n        break;\r\n      reducedDictionarySize += step;\r\n    }\r\n  }\r\n\r\n  {\r\n    int numProperties = method.Properties.Size();\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n    if (setCoderProperties == NULL)\r\n    {\r\n      if (numProperties != 0)\r\n        return E_INVALIDARG;\r\n    }\r\n    else\r\n    {\r\n      CRecordVector<PROPID> propIDs;\r\n      NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties];\r\n      HRESULT res = S_OK;\r\n      try\r\n      {\r\n        for (int i = 0; i < numProperties; i++)\r\n        {\r\n          const CProp &prop = method.Properties[i];\r\n          propIDs.Add(prop.Id);\r\n          NWindows::NCOM::CPropVariant &value = values[i];\r\n          value = prop.Value;\r\n          // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)\r\n          if (tryReduce)\r\n            if (prop.Id == NCoderPropID::kDictionarySize)\r\n              if (value.vt == VT_UI4)\r\n                if (reducedDictionarySize < value.ulVal)\r\n            value.ulVal = reducedDictionarySize;\r\n        }\r\n        CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n        coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n        res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties);\r\n      }\r\n      catch(...)\r\n      {\r\n        delete []values;\r\n        throw;\r\n      }\r\n      delete []values;\r\n      RINOK(res);\r\n    }\r\n  }\r\n \r\n  /*\r\n  CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n  coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n  if (writeCoderProperties != NULL)\r\n  {\r\n    CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n    outStreamSpec->Init();\r\n    RINOK(writeCoderProperties->WriteCoderProperties(outStream));\r\n    size_t size = outStreamSpec->GetSize();\r\n    filterProps.SetCapacity(size);\r\n    memmove(filterProps, outStreamSpec->GetBuffer(), size);\r\n  }\r\n  */\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/MethodProps.h",
    "content": "// MethodProps.h\r\n\r\n#ifndef __7Z_METHOD_PROPS_H\r\n#define __7Z_METHOD_PROPS_H\r\n\r\n#include \"MethodId.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Common/MyVector.h\"\r\n#include \"../ICoder.h\"\r\n\r\nstruct CProp\r\n{\r\n  PROPID Id;\r\n  NWindows::NCOM::CPropVariant Value;\r\n};\r\n\r\nstruct CMethod\r\n{\r\n  CMethodId Id;\r\n  CObjectVector<CProp> Properties;\r\n};\r\n\r\nstruct CMethodsMode\r\n{\r\n  CObjectVector<CMethod> Methods;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n\r\n  CMethodsMode()\r\n      #ifdef COMPRESS_MT\r\n      : NumThreads(1) \r\n      #endif\r\n  {}\r\n  bool IsEmpty() const { return Methods.IsEmpty() ; }\r\n};\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/OffsetStream.cpp",
    "content": "// OffsetStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"OffsetStream.h\"\r\n\r\nHRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)\r\n{\r\n  _offset = offset;\r\n  _stream = stream;\r\n  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return _stream->Write(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 absoluteNewPosition;\r\n  if (seekOrigin == STREAM_SEEK_SET)\r\n    offset += _offset;\r\n  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);\r\n  if (newPosition != NULL)\r\n    *newPosition = absoluteNewPosition - _offset;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)\r\n{\r\n  return _stream->SetSize(_offset + newSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/OffsetStream.h",
    "content": "// OffsetStream.h\r\n\r\n#ifndef __OFFSETSTREAM_H\r\n#define __OFFSETSTREAM_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass COffsetOutStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 _offset;\r\n  CMyComPtr<IOutStream> _stream;\r\npublic:\r\n  HRESULT Init(IOutStream *stream, UInt64 offset);\r\n  \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{ \r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos) \r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode == S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = Flush();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException: public CSystemException \r\n{ \r\n  COutBufferException(HRESULT errorCode): CSystemException(errorCode) {} \r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void FlushWithCheck();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/ProgressUtils.cpp",
    "content": "// ProgressUtils.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ProgressUtils.h\"\r\n\r\nCLocalProgress::CLocalProgress()\r\n{\r\n  ProgressOffset = InSize = OutSize = 0;\r\n  SendRatio = SendProgress = true;\r\n}\r\n\r\nvoid CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)\r\n{\r\n  _ratioProgress.Release();\r\n  _progress = progress;\r\n  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);\r\n  _inSizeIsMain = inSizeIsMain;\r\n}\r\n\r\nSTDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  UInt64 inSizeNew = InSize, outSizeNew = OutSize;\r\n  if (inSize)\r\n    inSizeNew += (*inSize);\r\n  if (outSize)\r\n    outSizeNew += (*outSize);\r\n  if (SendRatio && _ratioProgress)\r\n  {\r\n    RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));\r\n  }\r\n  inSizeNew += ProgressOffset;\r\n  outSizeNew += ProgressOffset;\r\n  if (SendProgress)\r\n    return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CLocalProgress::SetCur()\r\n{\r\n  return SetRatioInfo(NULL, NULL);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/ProgressUtils.h",
    "content": "// ProgressUtils.h\r\n\r\n#ifndef __PROGRESSUTILS_H\r\n#define __PROGRESSUTILS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n#include \"../IProgress.h\"\r\n\r\nclass CLocalProgress: \r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<IProgress> _progress;\r\n  CMyComPtr<ICompressProgressInfo> _ratioProgress;\r\n  bool _inSizeIsMain;\r\npublic:\r\n  UInt64 ProgressOffset;\r\n  UInt64 InSize;\r\n  UInt64 OutSize;\r\n  bool SendRatio;\r\n  bool SendProgress;\r\n\r\n  CLocalProgress();\r\n  void Init(IProgress *progress, bool inSizeIsMain);\r\n  HRESULT SetCur();\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/RegisterArc.h",
    "content": "// RegisterArc.h\r\n\r\n#ifndef __REGISTERARC_H\r\n#define __REGISTERARC_H\r\n\r\n#include \"../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcInfo\r\n{\r\n  const wchar_t *Name;\r\n  const wchar_t *Ext;\r\n  const wchar_t *AddExt;\r\n  Byte ClassId;\r\n  Byte Signature[16];\r\n  int SignatureSize;\r\n  bool KeepName;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n};\r\n\r\nvoid RegisterArc(const CArcInfo *arcInfo);\r\n\r\n#define REGISTER_ARC_NAME(x) CRegister ## x \r\n\r\n#define REGISTER_ARC_DEC_SIG(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { g_ArcInfo.Signature[0]--; RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#define REGISTER_ARC(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/RegisterCodec.h",
    "content": "// RegisterCodec.h\r\n\r\n#ifndef __REGISTERCODEC_H\r\n#define __REGISTERCODEC_H\r\n\r\n#include \"../Common/MethodId.h\"\r\n\r\ntypedef void * (*CreateCodecP)();\r\nstruct CCodecInfo\r\n{\r\n  CreateCodecP CreateDecoder;\r\n  CreateCodecP CreateEncoder;\r\n  CMethodId Id;\r\n  const wchar_t *Name;\r\n  UInt32 NumInStreams;\r\n  bool IsFilter;\r\n};\r\n\r\nvoid RegisterCodec(const CCodecInfo *codecInfo);\r\n\r\n#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x \r\n\r\n#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \\\r\n    REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \\\r\n    static REGISTER_CODEC_NAME(x) g_RegisterCodec;\r\n\r\n#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x \r\n#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \\\r\n    REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \\\r\n    RegisterCodec(&g_CodecsInfo[i]); }}; \\\r\n    static REGISTER_CODECS_NAME(x) g_RegisterCodecs;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/StreamBinder.cpp",
    "content": "// StreamBinder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamBinder.h\"\r\n#include \"../../Common/Defs.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NSynchronization;\r\n\r\nclass CSequentialInStreamForBinder: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Read(data, size, processedSize); }\r\n\r\nclass CSequentialOutStreamForBinder: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialOutStreamForBinder() {  m_StreamBinder->CloseWrite(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Write(data, size, processedSize); }\r\n\r\n\r\n//////////////////////////\r\n// CStreamBinder\r\n// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.\r\n\r\nHRes CStreamBinder::CreateEvents()\r\n{\r\n  RINOK(_allBytesAreWritenEvent.Create(true));\r\n  RINOK(_thereAreBytesToReadEvent.Create());\r\n  return _readStreamIsClosedEvent.Create();\r\n}\r\n\r\nvoid CStreamBinder::ReInit()\r\n{\r\n  _thereAreBytesToReadEvent.Reset();\r\n  _readStreamIsClosedEvent.Reset();\r\n  ProcessedSize = 0;\r\n}\r\n\r\n\r\n  \r\nvoid CStreamBinder::CreateStreams(ISequentialInStream **inStream, \r\n      ISequentialOutStream **outStream)\r\n{\r\n  CSequentialInStreamForBinder *inStreamSpec = new \r\n      CSequentialInStreamForBinder;\r\n  CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n  inStreamSpec->SetBinder(this);\r\n  *inStream = inStreamLoc.Detach();\r\n\r\n  CSequentialOutStreamForBinder *outStreamSpec = new \r\n      CSequentialOutStreamForBinder;\r\n  CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);\r\n  outStreamSpec->SetBinder(this);\r\n  *outStream = outStreamLoc.Detach();\r\n\r\n  _buffer = NULL;\r\n  _bufferSize= 0;\r\n  ProcessedSize = 0;\r\n}\r\n\r\nHRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 sizeToRead = size;\r\n  if (size > 0)\r\n  {\r\n    RINOK(_thereAreBytesToReadEvent.Lock());\r\n    sizeToRead = MyMin(_bufferSize, size);\r\n    if (_bufferSize > 0)\r\n    {\r\n      MoveMemory(data, _buffer, sizeToRead);\r\n      _buffer = ((const Byte *)_buffer) + sizeToRead;\r\n      _bufferSize -= sizeToRead;\r\n      if (_bufferSize == 0)\r\n      {\r\n        _thereAreBytesToReadEvent.Reset();\r\n        _allBytesAreWritenEvent.Set();\r\n      }\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = sizeToRead;\r\n  ProcessedSize += sizeToRead;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseRead()\r\n{\r\n  _readStreamIsClosedEvent.Set();\r\n}\r\n\r\nHRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > 0)\r\n  {\r\n    _buffer = data;\r\n    _bufferSize = size;\r\n    _allBytesAreWritenEvent.Reset();\r\n    _thereAreBytesToReadEvent.Set();\r\n\r\n    HANDLE events[2]; \r\n    events[0] = _allBytesAreWritenEvent;\r\n    events[1] = _readStreamIsClosedEvent; \r\n    DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);\r\n    if (waitResult != WAIT_OBJECT_0 + 0)\r\n    {\r\n      // ReadingWasClosed = true;\r\n      return S_FALSE;\r\n    }\r\n    // if(!_allBytesAreWritenEvent.Lock())\r\n    //   return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseWrite()\r\n{\r\n  // _bufferSize must be = 0\r\n  _thereAreBytesToReadEvent.Set();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/StreamBinder.h",
    "content": "// StreamBinder.h\r\n\r\n#ifndef __STREAMBINDER_H\r\n#define __STREAMBINDER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Windows/Synchronization.h\"\r\n\r\nclass CStreamBinder\r\n{\r\n  NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent;\r\n  UInt32 _bufferSize;\r\n  const void *_buffer;\r\npublic:\r\n  // bool ReadingWasClosed;\r\n  UInt64 ProcessedSize;\r\n  CStreamBinder() {}\r\n  HRes CreateEvents();\r\n\r\n  void CreateStreams(ISequentialInStream **inStream, \r\n      ISequentialOutStream **outStream);\r\n  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseRead();\r\n\r\n  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseWrite();\r\n  void ReInit();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/StreamObjects.cpp",
    "content": "// StreamObjects.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamObjects.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\n\r\nSTDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 numBytesToRead = (UInt32)(MyMin(_pos + size, _size) - _pos);\r\n  memmove(data, _dataPointer + _pos, numBytesToRead);\r\n  _pos += numBytesToRead;\r\n  if(processedSize != NULL)\r\n    *processedSize = numBytesToRead;\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CWriteBuffer::Write(const void *data, size_t size)\r\n{\r\n  size_t newCapacity = _size + size;\r\n  _buffer.EnsureCapacity(newCapacity);\r\n  memmove(_buffer + _size, data, size);\r\n  _size += size;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  _writeBuffer.Write(data, size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK; \r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 newSize = size;\r\n  if (_pos + size > _size)\r\n    newSize = (UInt32)(_size - _pos);\r\n  memmove(_buffer + _pos, data, newSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = newSize;\r\n  _pos += newSize;\r\n  if (newSize != size)\r\n    return E_FAIL;\r\n  return S_OK; \r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result; \r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result; \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/StreamObjects.h",
    "content": "// StreamObjects.h\r\n\r\n#ifndef __STREAMOBJECTS_H\r\n#define __STREAMOBJECTS_H\r\n\r\n#include \"../../Common/DynamicBuffer.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CSequentialInStreamImp: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *_dataPointer;\r\n  size_t _size;\r\n  size_t _pos;\r\n\r\npublic:\r\n  void Init(const Byte *dataPointer, size_t size)\r\n  {\r\n    _dataPointer = dataPointer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n\r\nclass CWriteBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _size;\r\npublic:\r\n  CWriteBuffer(): _size(0) {}\r\n  void Init() { _size = 0;  }\r\n  void Write(const void *data, size_t size);\r\n  size_t GetSize() const { return _size; }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _buffer; }\r\n};\r\n\r\nclass CSequentialOutStreamImp: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CWriteBuffer _writeBuffer;\r\npublic:\r\n  void Init() { _writeBuffer.Init(); }\r\n  size_t GetSize() const { return _writeBuffer.GetSize(); }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamImp2: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n\r\n  void Init(Byte *buffer, size_t size)  \r\n  { \r\n    _buffer = buffer;\r\n    _pos = 0;\r\n    _size = size; \r\n  }\r\n\r\n  size_t GetPos() const { return _pos; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialInStreamSizeCount: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamSizeCount: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void Init() { _size = 0; }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Read(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (Byte *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Write(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/VirtThread.cpp",
    "content": "// VirtThread.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"VirtThread.h\"\r\n\r\nstatic THREAD_FUNC_DECL CoderThread(void *p)\r\n{\r\n  for (;;)\r\n  {\r\n    CVirtThread *t = (CVirtThread *)p;\r\n    t->StartEvent.Lock();\r\n    if (t->ExitEvent)\r\n      return 0;\r\n    t->Execute();\r\n    t->FinishedEvent.Set();\r\n  }\r\n}\r\n\r\nHRes CVirtThread::Create()\r\n{\r\n  RINOK(StartEvent.CreateIfNotCreated());\r\n  RINOK(FinishedEvent.CreateIfNotCreated());\r\n  StartEvent.Reset();\r\n  FinishedEvent.Reset();\r\n  ExitEvent = false;\r\n  if (Thread.IsCreated())\r\n    return S_OK;\r\n  return Thread.Create(CoderThread, this);\r\n}\r\n\r\nvoid CVirtThread::Start()\r\n{\r\n  ExitEvent = false;\r\n  StartEvent.Set();\r\n}\r\n\r\nCVirtThread::~CVirtThread()\r\n{\r\n  ExitEvent = true;\r\n  if (StartEvent.IsCreated())\r\n    StartEvent.Set();\r\n  Thread.Wait();\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Common/VirtThread.h",
    "content": "// VirtThread.h\r\n\r\n#ifndef __VIRTTHREAD_H\r\n#define __VIRTTHREAD_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Windows/Thread.h\"\r\n\r\nstruct CVirtThread\r\n{\r\n  NWindows::NSynchronization::CAutoResetEvent StartEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent FinishedEvent;\r\n  NWindows::CThread Thread;\r\n  bool ExitEvent;\r\n\r\n  ~CVirtThread();\r\n  HRes Create();\r\n  void Start();\r\n  void WaitFinish() { FinishedEvent.Lock(); } \r\n  virtual void Execute() = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/ARM.cpp",
    "content": "// ARM.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARM.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchARM.h\"\r\n}\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/ARM.h",
    "content": "// ARM.h\r\n\r\n#ifndef __ARM_H\r\n#define __ARM_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM, 0x05, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/ARMThumb.cpp",
    "content": "// ARMThumb.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ARMThumb.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchARMThumb.h\"\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/ARMThumb.h",
    "content": "// ARMThumb.h\r\n\r\n#ifndef __ARMTHUMB_H\r\n#define __ARMTHUMB_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARMThumb, 0x07, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/BCJ2Register.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"x86_2.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x0303011B, L\"BCJ2\", 4, false };\r\n\r\nREGISTER_CODEC(BCJ2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/BCJRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"x86.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x03030103, L\"BCJ\", 1, true };\r\n\r\nREGISTER_CODEC(BCJ)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __BRANCH_CODER_H\r\n#define __BRANCH_CODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/Types.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/BranchRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"PPC.h\"\r\n#include \"IA64.h\"\r\n#include \"ARM.h\"\r\n#include \"ARMThumb.h\"\r\n#include \"SPARC.h\"\r\n\r\n#define CREATE_CODEC(x) \\\r\n  static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \\\r\n  static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }\r\n\r\nCREATE_CODEC(BC_PPC_B)\r\nCREATE_CODEC(BC_IA64)\r\nCREATE_CODEC(BC_ARM)\r\nCREATE_CODEC(BC_ARMThumb)\r\nCREATE_CODEC(BC_SPARC)\r\n\r\n#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true  }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  METHOD_ITEM(BC_PPC_B,   0x02, 0x05, L\"BC_PPC_B\"),\r\n  METHOD_ITEM(BC_IA64,    0x04, 1, L\"BC_IA64\"),\r\n  METHOD_ITEM(BC_ARM,     0x05, 1, L\"BC_ARM\"),\r\n  METHOD_ITEM(BC_ARMThumb,0x07, 1, L\"BC_ARMThumb\"),\r\n  METHOD_ITEM(BC_SPARC,   0x08, 0x05, L\"BC_SPARC\")\r\n};\r\n\r\nREGISTER_CODECS(Branch)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/IA64.cpp",
    "content": "// IA64.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"IA64.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchIA64.h\"\r\n}\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/IA64.h",
    "content": "// IA64.h\r\n\r\n#ifndef __IA64_H\r\n#define __IA64_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_IA64, 0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/PPC.cpp",
    "content": "// PPC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"PPC.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchPPC.h\"\r\n}\r\n\r\nUInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/PPC.h",
    "content": "// PPC.h\r\n\r\n#ifndef __PPC_H\r\n#define __PPC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_PPC_B, 0x02, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/SPARC.cpp",
    "content": "// SPARC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"SPARC.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchSPARC.h\"\r\n}\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/SPARC.h",
    "content": "// SPARC.h\r\n\r\n#ifndef __SPARC_H\r\n#define __SPARC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_SPARC, 0x08, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/x86.cpp",
    "content": "// x86.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86.h\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/x86.h",
    "content": "// x86.h\r\n\r\n#ifndef __X86_H\r\n#define __X86_H\r\n\r\n#include \"BranchCoder.h\"\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Compress/Branch/BranchX86.h\"\r\n}\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  void x86Init() { x86_Convert_Init(_prevMask); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 , \r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/x86_2.cpp",
    "content": "// x86_2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86_2.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\ninline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }\r\ninline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }\r\ninline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CEncoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CEncoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize = 0;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusEncoder[i].Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    for (;;)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it \r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        UInt32 index;\r\n        if (b == 0xE8)\r\n          index = prevByte;\r\n        else if (b == 0xE9)\r\n          index = 256;\r\n        else if (IsJcc(prevByte, b))\r\n          index = 257;\r\n        else\r\n        {\r\n          prevByte = b;\r\n          continue;\r\n        }\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (!IsJ(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src = \r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;          \r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;          \r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      unsigned index = GetIndex(prevByte, b);\r\n      if (convert)\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 1);\r\n        bufferPos += 5;\r\n        COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n        for (int i = 24; i >= 0; i -= 8)\r\n          s.WriteByte((Byte)(dest >> i));\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize = \r\n        _mainStream.GetProcessedSize() + \r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeEncoder.GetProcessedSize();\r\n      */\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusDecoder[i].Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  for (;;)\r\n  {\r\n    if (processedBytes >= (1 << 20) && progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize = \r\n        _mainInStream.GetProcessedSize() + \r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeDecoder.GetProcessedSize();\r\n      */\r\n      const UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    UInt32 i;\r\n    Byte b = 0;\r\n    const UInt32 kBurstSize = (1 << 18);\r\n    for (i = 0; i < kBurstSize; i++)\r\n    {\r\n      if (!_mainInStream.ReadByte(b))\r\n        return Flush();\r\n      _outStream.WriteByte(b);\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      prevByte = b;\r\n    }\r\n    processedBytes += i;\r\n    if (i == kBurstSize)\r\n      continue;\r\n    unsigned index = GetIndex(prevByte, b);\r\n    if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)\r\n    {\r\n      UInt32 src = 0;\r\n      CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n      for (int i = 0; i < 4; i++)\r\n      {\r\n        Byte b0;\r\n        if(!s.ReadByte(b0))\r\n          return S_FALSE;\r\n        src <<= 8;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (Byte)(dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const CInBufferException &e) { return e.ErrorCode; }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Branch/x86_2.h",
    "content": "// x86_2.h\r\n\r\n#ifndef __BRANCH_X86_2_H\r\n#define __BRANCH_X86_2_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../RangeCoder/RangeCoderBit.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CEncoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CEncoder(): _buffer(0) {};\r\n  ~CEncoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n\r\nclass CDecoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{ \r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CDecoder *_coder;\r\n  public:\r\n    CCoderReleaser(CDecoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/ByteSwap/ByteSwap.cpp",
    "content": "// ByteSwap.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nSTDMETHODIMP CByteSwap2::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 2;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b = data[i];\r\n    data[i] = data[i + 1];\r\n    data[i + 1] = b;\r\n  }\r\n  return i;\r\n}\r\n\r\nSTDMETHODIMP CByteSwap4::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 4;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b0 = data[i];\r\n    Byte b1 = data[i + 1];\r\n    data[i] = data[i + 3];\r\n    data[i + 1] = data[i + 2];\r\n    data[i + 2] = b1;\r\n    data[i + 3] = b0;\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/ByteSwap/ByteSwap.h",
    "content": "// ByteSwap.h\r\n\r\n#ifndef __BYTESWAP_H\r\n#define __BYTESWAP_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n// {23170F69-40C1-278B-0203-020000000000}\r\nDEFINE_GUID(CLSID_CCompressConvertByteSwap2, \r\n0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\n// {23170F69-40C1-278B-0203-040000000000}\r\nDEFINE_GUID(CLSID_CCompressConvertByteSwap4, \r\n0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nclass CByteSwap2: \r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\nclass CByteSwap4: \r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/ByteSwap/ByteSwapRegister.cpp",
    "content": "// ByteSwapRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"ByteSwap.h\"\r\nstatic void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }\r\nstatic void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  { CreateCodec2, CreateCodec4, 0x020302, L\"Swap2\", 1, true },\r\n  { CreateCodec4, CreateCodec4, 0x020304, L\"Swap4\", 1, true }\r\n};\r\n\r\nREGISTER_CODECS(ByteSwap)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/ByteSwap/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/ByteSwap/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/CodecExports.cpp",
    "content": "// CodecExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterCodec.h\"\r\n#include \"../ICoder.h\"\r\n\r\nextern unsigned int g_NumCodecs;\r\nextern const CCodecInfo *g_Codecs[]; \r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec, \r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nstatic HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)\r\n{\r\n  GUID clsId = CLSID_CCodec;\r\n  for (int i = 0; i < sizeof(id); i++, id >>= 8)\r\n    clsId.Data4[i] = (Byte)(id & 0xFF);\r\n  if (encode)\r\n    clsId.Data3++;\r\n  return SetPropGUID(clsId, value);\r\n}\r\n\r\nstatic HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)\r\n{\r\n  index = -1;\r\n  if (clsID->Data1 != CLSID_CCodec.Data1 || \r\n      clsID->Data2 != CLSID_CCodec.Data2 ||\r\n      (clsID->Data3 & ~1) != kDecodeId)\r\n    return S_OK;\r\n  encode = (clsID->Data3 != kDecodeId);\r\n  UInt64 id = 0;\r\n  for (int j = 0; j < 8; j++)\r\n    id |= ((UInt64)clsID->Data4[j]) << (8 * j);\r\n  for (UInt32 i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)\r\n      continue;\r\n    if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n        codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n      return E_NOINTERFACE;\r\n    index = i;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  const CCodecInfo &codec = *g_Codecs[index];\r\n  if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n      codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n    return E_NOINTERFACE;\r\n  if (encode)\r\n  {\r\n    if (!codec.CreateEncoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateEncoder();\r\n  }\r\n  else\r\n  {\r\n    if (!codec.CreateDecoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateDecoder();\r\n  }\r\n  if (isCoder)\r\n    ((ICompressCoder *)*outObject)->AddRef();\r\n  else if (isCoder2)\r\n    ((ICompressCoder2 *)*outObject)->AddRef();\r\n  else\r\n    ((ICompressFilter *)*outObject)->AddRef();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  if (!isCoder && !isCoder2 && !isFilter)\r\n    return E_NOINTERFACE;\r\n  bool encode;\r\n  int codecIndex;\r\n  HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);\r\n  if (res != S_OK)\r\n    return res;\r\n  if (codecIndex < 0)\r\n    return CLASS_E_CLASSNOTAVAILABLE;\r\n  return CreateCoder2(encode, codecIndex, iid, outObject);\r\n}\r\n\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  ::VariantClear((VARIANTARG *)value);\r\n  const CCodecInfo &codec = *g_Codecs[codecIndex];\r\n  switch(propID)\r\n  {\r\n    case NMethodPropID::kID:\r\n    {\r\n      value->uhVal.QuadPart = (UInt64)codec.Id;\r\n      value->vt = VT_UI8;\r\n      break;\r\n    }\r\n    case NMethodPropID::kName:\r\n      if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)\r\n        value->vt = VT_BSTR;\r\n      break;\r\n    case NMethodPropID::kDecoder:\r\n      if (codec.CreateDecoder)\r\n        return SetClassID(codec.Id, false, value);\r\n      break;\r\n    case NMethodPropID::kEncoder:\r\n      if (codec.CreateEncoder)\r\n        return SetClassID(codec.Id, true, value);\r\n      break;\r\n    case NMethodPropID::kInStreams:\r\n    {\r\n      if (codec.NumInStreams != 1)\r\n      {\r\n        value->vt = VT_UI4;\r\n        value->ulVal = codec.NumInStreams;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetNumberOfMethods(UINT32 *numCodecs)\r\n{\r\n  *numCodecs = g_NumCodecs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Copy/CopyCoder.cpp",
    "content": "// Compress/CopyCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"CopyCoder.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\nnamespace NCompress {\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCCopyCoder::~CCopyCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 * /* inSize */, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  TotalSize = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 realProcessedSize;\r\n    UInt32 size = kBufferSize;\r\n    if (outSize != 0)\r\n      if (size > *outSize - TotalSize)\r\n        size = (UInt32)(*outSize - TotalSize);\r\n    RINOK(inStream->Read(_buffer, size, &realProcessedSize));\r\n    if (realProcessedSize == 0)\r\n      break;\r\n    RINOK(WriteStream(outStream, _buffer, realProcessedSize, NULL));\r\n    TotalSize += realProcessedSize;\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = TotalSize;\r\n  return S_OK;\r\n}\r\n\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Copy/CopyCoder.h",
    "content": "// Compress/CopyCoder.h\r\n\r\n#ifndef __COMPRESS_COPYCODER_H\r\n#define __COMPRESS_COPYCODER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nnamespace NCompress {\r\n\r\nclass CCopyCoder: \r\n  public ICompressCoder,\r\n  public ICompressGetInStreamProcessedSize,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  UInt64 TotalSize;\r\n  CCopyCoder(): TotalSize(0) , _buffer(0) {};\r\n  ~CCopyCoder();\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Copy/CopyRegister.cpp",
    "content": "// LZMARegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"CopyCoder.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n{ CreateCodec, CreateCodec, 0x00, L\"Copy\", 1, false };\r\n\r\nREGISTER_CODEC(Copy)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Copy/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/Copy/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZ/LZOutWindow.cpp",
    "content": "// LZOutWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZOutWindow.h\"\r\n\r\nvoid CLZOutWindow::Init(bool solid)\r\n{\r\n  if(!solid)\r\n    COutBuffer::Init();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZ/LZOutWindow.h",
    "content": "// LZOutWindow.h\r\n\r\n#ifndef __LZ_OUT_WINDOW_H\r\n#define __LZ_OUT_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\ntypedef COutBufferException CLZOutWindowException;\r\n#endif\r\n\r\nclass CLZOutWindow: public COutBuffer\r\n{\r\npublic:\r\n  void Init(bool solid = false);\r\n  \r\n  // distance >= 0, len > 0, \r\n  bool CopyBlock(UInt32 distance, UInt32 len)\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (distance >= _pos)\r\n    {\r\n      if (!_overDict || distance >= _bufferSize)\r\n        return false;\r\n      pos += _bufferSize;\r\n    }\r\n    if (_limitPos - _pos > len && _bufferSize - pos > len)\r\n    {\r\n      const Byte *src = _buffer + pos;\r\n      Byte *dest = _buffer + _pos;\r\n      _pos += len;\r\n      do\r\n        *dest++ = *src++;\r\n      while(--len != 0);\r\n    }\r\n    else do\r\n    {\r\n      if (pos == _bufferSize)\r\n        pos = 0;\r\n      _buffer[_pos++] = _buffer[pos++];\r\n      if (_pos == _limitPos)\r\n        FlushWithCheck();  \r\n    }\r\n    while(--len != 0);\r\n    return true;\r\n  }\r\n  \r\n  void PutByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if (_pos == _limitPos)\r\n      FlushWithCheck();  \r\n  }\r\n  \r\n  Byte GetByte(UInt32 distance) const\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n      pos += _bufferSize;\r\n    return _buffer[pos]; \r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZ/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA/LZMA.h",
    "content": "// LZMA.h\r\n\r\n#ifndef __LZMA_H\r\n#define __LZMA_H\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst UInt32 kNumRepDistances = 4;\r\n\r\nconst int kNumStates = 12;\r\n\r\nconst Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nconst Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nconst Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nconst Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\nclass CState\r\n{\r\npublic:\r\n  Byte Index;\r\n  void Init() { Index = 0; }\r\n  void UpdateChar() { Index = kLiteralNextStates[Index]; }\r\n  void UpdateMatch() { Index = kMatchNextStates[Index]; }\r\n  void UpdateRep() { Index = kRepNextStates[Index]; }\r\n  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }\r\n  bool IsCharState() const { return Index < 7; }\r\n};\r\n\r\nconst int kNumPosSlotBits = 6; \r\nconst int kDicLogSizeMin = 0; \r\nconst int kDicLogSizeMax = 32; \r\nconst int kDistTableSizeMax = kDicLogSizeMax * 2; \r\n\r\nconst UInt32 kNumLenToPosStates = 4;\r\n\r\ninline UInt32 GetLenToPosState(UInt32 len)\r\n{\r\n  len -= 2;\r\n  if (len < kNumLenToPosStates)\r\n    return len;\r\n  return kNumLenToPosStates - 1;\r\n}\r\n\r\nnamespace NLength {\r\n\r\nconst int kNumPosStatesBitsMax = 4;\r\nconst UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\r\nconst int kNumPosStatesBitsEncodingMax = 4;\r\nconst UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\nconst int kNumLowBits = 3;\r\nconst int kNumMidBits = 3;\r\nconst int kNumHighBits = 8;\r\nconst UInt32 kNumLowSymbols = 1 << kNumLowBits;\r\nconst UInt32 kNumMidSymbols = 1 << kNumMidBits;\r\nconst UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\r\n\r\n}\r\n\r\nconst UInt32 kMatchMinLen = 2;\r\nconst UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\r\n\r\nconst int kNumAlignBits = 4;\r\nconst UInt32 kAlignTableSize = 1 << kNumAlignBits;\r\nconst UInt32 kAlignMask = (kAlignTableSize - 1);\r\n\r\nconst UInt32 kStartPosModelIndex = 4;\r\nconst UInt32 kEndPosModelIndex = 14;\r\nconst UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\nconst UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\r\nconst int kNumLitPosStatesBitsEncodingMax = 4;\r\nconst int kNumLitContextBitsMax = 8;\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA/LZMADecoder.cpp",
    "content": "// LZMADecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\n#include \"../../../Common/Defs.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kLenIdFinished = -1;\r\nconst int kLenIdNeedInit = -2;\r\n\r\nvoid CDecoder::Init()\r\n{\r\n  { \r\n    for(int i = 0; i < kNumStates; i++)\r\n    {\r\n      for (UInt32 j = 0; j <= _posStateMask; j++)\r\n      {\r\n        _isMatch[i][j].Init();\r\n        _isRep0Long[i][j].Init();\r\n      }\r\n      _isRep[i].Init();\r\n      _isRepG0[i].Init();\r\n      _isRepG1[i].Init();\r\n      _isRepG2[i].Init();\r\n    }\r\n  }\r\n  { \r\n    for (UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n    _posSlotDecoder[i].Init();\r\n  }\r\n  { \r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posDecoders[i].Init();\r\n  }\r\n  _posAlignDecoder.Init();\r\n  _lenDecoder.Init(_posStateMask + 1);\r\n  _repMatchLenDecoder.Init(_posStateMask + 1);\r\n  _literalDecoder.Init();\r\n\r\n  _state.Init();\r\n  _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0;\r\n}\r\n\r\nHRESULT CDecoder::CodeSpec(UInt32 curSize)\r\n{\r\n  if (_outSizeDefined)\r\n  {\r\n    const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize();\r\n    if (curSize > rem)\r\n      curSize = (UInt32)rem;\r\n  }\r\n\r\n  if (_remainLen == kLenIdFinished)\r\n    return S_OK;\r\n  if (_remainLen == kLenIdNeedInit)\r\n  {\r\n    _rangeDecoder.Init();\r\n    Init();\r\n    _remainLen = 0;\r\n  }\r\n  if (curSize == 0)\r\n    return S_OK;\r\n\r\n  UInt32 rep0 = _reps[0];\r\n  UInt32 rep1 = _reps[1];\r\n  UInt32 rep2 = _reps[2];\r\n  UInt32 rep3 = _reps[3];\r\n  CState state = _state;\r\n  Byte previousByte;\r\n\r\n  while(_remainLen > 0 && curSize > 0)\r\n  {\r\n    previousByte = _outWindowStream.GetByte(rep0);\r\n    _outWindowStream.PutByte(previousByte);\r\n    _remainLen--;\r\n    curSize--;\r\n  }\r\n  UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n  if (nowPos64 == 0)\r\n    previousByte = 0;\r\n  else\r\n    previousByte = _outWindowStream.GetByte(0);\r\n\r\n  while(curSize > 0)\r\n  {\r\n    {\r\n      #ifdef _NO_EXCEPTIONS\r\n      if (_rangeDecoder.Stream.ErrorCode != S_OK)\r\n        return _rangeDecoder.Stream.ErrorCode;\r\n      #endif\r\n      if (_rangeDecoder.Stream.WasFinished())\r\n        return S_FALSE;\r\n      UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n      if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n      {\r\n        if(!state.IsCharState())\r\n          previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte, _outWindowStream.GetByte(rep0));\r\n        else\r\n          previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte);\r\n        _outWindowStream.PutByte(previousByte);\r\n        state.UpdateChar();\r\n        curSize--;\r\n        nowPos64++;\r\n      }\r\n      else             \r\n      {\r\n        UInt32 len;\r\n        if(_isRep[state.Index].Decode(&_rangeDecoder) == 1)\r\n        {\r\n          len = 0;\r\n          if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0)\r\n          {\r\n            if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n            {\r\n              state.UpdateShortRep();\r\n              len = 1;\r\n            }\r\n          }\r\n          else\r\n          {\r\n            UInt32 distance;\r\n            if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0)\r\n              distance = rep1;\r\n            else \r\n            {\r\n              if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0)\r\n                distance = rep2;\r\n              else\r\n              {\r\n                distance = rep3;\r\n                rep3 = rep2;\r\n              }\r\n              rep2 = rep1;\r\n            }\r\n            rep1 = rep0;\r\n            rep0 = distance;\r\n          }\r\n          if (len == 0)\r\n          {\r\n            len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;\r\n            state.UpdateRep();\r\n          }\r\n        }\r\n        else\r\n        {\r\n          rep3 = rep2;\r\n          rep2 = rep1;\r\n          rep1 = rep0;\r\n          len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);\r\n          state.UpdateMatch();\r\n          UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);\r\n          if (posSlot >= kStartPosModelIndex)\r\n          {\r\n            UInt32 numDirectBits = (posSlot >> 1) - 1;\r\n            rep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\r\n            if (posSlot < kEndPosModelIndex)\r\n              rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders + \r\n                  rep0 - posSlot - 1, &_rangeDecoder, numDirectBits);\r\n            else\r\n            {\r\n              rep0 += (_rangeDecoder.DecodeDirectBits(\r\n                  numDirectBits - kNumAlignBits) << kNumAlignBits);\r\n              rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder);\r\n              if (rep0 == 0xFFFFFFFF)\r\n              {\r\n                _remainLen = kLenIdFinished;\r\n                return S_OK;\r\n              }\r\n            }\r\n          }\r\n          else\r\n            rep0 = posSlot;\r\n        }\r\n        UInt32 locLen = len;\r\n        if (len > curSize)\r\n          locLen = (UInt32)curSize;\r\n        if (!_outWindowStream.CopyBlock(rep0, locLen))\r\n          return S_FALSE;\r\n        previousByte = _outWindowStream.GetByte(0);\r\n        curSize -= locLen;\r\n        nowPos64 += locLen;\r\n        len -= locLen;\r\n        if (len != 0)\r\n        {\r\n          _remainLen = (Int32)len;\r\n          break;\r\n        }\r\n\r\n        #ifdef _NO_EXCEPTIONS\r\n        if (_outWindowStream.ErrorCode != S_OK)\r\n          return _outWindowStream.ErrorCode;\r\n        #endif\r\n      }\r\n    }\r\n  }\r\n  if (_rangeDecoder.Stream.WasFinished())\r\n    return S_FALSE;\r\n  _reps[0] = rep0;\r\n  _reps[1] = rep1;\r\n  _reps[2] = rep2;\r\n  _reps[3] = rep3;\r\n  _state = state;\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 *, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  SetInStream(inStream);\r\n  _outWindowStream.SetStream(outStream);\r\n  SetOutStreamSize(outSize);\r\n  CDecoderFlusher flusher(this);\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 curSize = 1 << 18;\r\n    RINOK(CodeSpec(curSize));\r\n    if (_remainLen == kLenIdFinished)\r\n      break;\r\n    if (progress != NULL)\r\n    {\r\n      UInt64 inSize = _rangeDecoder.GetProcessedSize();\r\n      UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(&inSize, &nowPos64));\r\n    }\r\n    if (_outSizeDefined)\r\n      if (_outWindowStream.GetProcessedSize() >= _outSize)\r\n        break;\r\n  } \r\n  flusher.NeedFlush = false;\r\n  return Flush();\r\n}\r\n\r\n\r\n#ifdef _NO_EXCEPTIONS\r\n\r\n#define LZMA_TRY_BEGIN\r\n#define LZMA_TRY_END\r\n\r\n#else\r\n\r\n#define LZMA_TRY_BEGIN try { \r\n#define LZMA_TRY_END } \\\r\n  catch(const CInBufferException &e)  { return e.ErrorCode; } \\\r\n  catch(const CLZOutWindowException &e)  { return e.ErrorCode; } \\\r\n  catch(...) { return S_FALSE; }\r\n\r\n#endif\r\n\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  LZMA_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size)\r\n{\r\n  if (size < 5)\r\n    return E_INVALIDARG;\r\n  int lc = properties[0] % 9;\r\n  Byte remainder = (Byte)(properties[0] / 9);\r\n  int lp = remainder % 5;\r\n  int pb = remainder / 5;\r\n  if (pb > NLength::kNumPosStatesBitsMax)\r\n    return E_INVALIDARG;\r\n  _posStateMask = (1 << pb) - 1;\r\n  UInt32 dictionarySize = 0;\r\n  for (int i = 0; i < 4; i++)\r\n    dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n  if (!_outWindowStream.Create(dictionarySize))\r\n    return E_OUTOFMEMORY;\r\n  if (!_literalDecoder.Create(lp, lc))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = _rangeDecoder.GetProcessedSize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _rangeDecoder.SetStream(inStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::ReleaseInStream()\r\n{\r\n  _rangeDecoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  _outSizeDefined = (outSize != NULL);\r\n  if (_outSizeDefined)\r\n    _outSize = *outSize;\r\n  _remainLen = kLenIdNeedInit;\r\n  _outWindowStream.Init();\r\n  return S_OK;\r\n}\r\n\r\n#ifndef NO_READ_FROM_CODER\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  const UInt64 startPos = _outWindowStream.GetProcessedSize();\r\n  _outWindowStream.SetMemStream((Byte *)data);\r\n  RINOK(CodeSpec(size));\r\n  if (processedSize)\r\n    *processedSize = (UInt32)(_outWindowStream.GetProcessedSize() - startPos);\r\n  return Flush();\r\n  LZMA_TRY_END\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA/LZMADecoder.h",
    "content": "// LZMA/Decoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/LZOutWindow.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;\r\n\r\nclass CLiteralDecoder2\r\n{\r\n  CMyBitDecoder _decoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _decoders[i].Init();\r\n  }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n      RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, Byte matchByte)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      UInt32 matchBit = (matchByte >> 7) & 1;\r\n      matchByte <<= 1;\r\n      // UInt32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);\r\n      // symbol = (symbol << 1) | bit;\r\n      UInt32 bit;\r\n      RC_GETBIT2(kNumMoveBits, _decoders[0x100 + (matchBit << 8) + symbol].Prob, symbol, \r\n          bit = 0, bit = 1)\r\n      if (matchBit != bit)\r\n      {\r\n        while (symbol < 0x100)\r\n        {\r\n          // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n          RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n        }\r\n        break;\r\n      }\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n};\r\n\r\nclass CLiteralDecoder\r\n{\r\n  CLiteralDecoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralDecoder(): _coders(0) {}\r\n  ~CLiteralDecoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte, Byte matchByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CDecoder\r\n{\r\n  CMyBitDecoder _choice;\r\n  CMyBitDecoder _choice2;\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder; \r\npublic:\r\n  void Init(UInt32 numPosStates)\r\n  {\r\n    _choice.Init();\r\n    _choice2.Init();\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n    {\r\n      _lowCoder[posState].Init();\r\n      _midCoder[posState].Init();\r\n    }\r\n    _highCoder.Init();\r\n  }\r\n  UInt32 Decode(NRangeCoder::CDecoder *rangeDecoder, UInt32 posState)\r\n  {\r\n    if(_choice.Decode(rangeDecoder) == 0)\r\n      return _lowCoder[posState].Decode(rangeDecoder);\r\n    if(_choice2.Decode(rangeDecoder) == 0)\r\n      return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);\r\n    return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CDecoder: \r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  public ICompressGetInStreamProcessedSize,\r\n  #ifndef NO_READ_FROM_CODER\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CLZOutWindow _outWindowStream;\r\n  NRangeCoder::CDecoder _rangeDecoder;\r\n\r\n  CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax];\r\n  CMyBitDecoder _isRep[kNumStates];\r\n  CMyBitDecoder _isRepG0[kNumStates];\r\n  CMyBitDecoder _isRepG1[kNumStates];\r\n  CMyBitDecoder _isRepG2[kNumStates];\r\n  CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax];\r\n\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];\r\n\r\n  CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;\r\n  \r\n  NLength::CDecoder _lenDecoder;\r\n  NLength::CDecoder _repMatchLenDecoder;\r\n\r\n  CLiteralDecoder _literalDecoder;\r\n\r\n  UInt32 _posStateMask;\r\n\r\n  ///////////////////\r\n  // State\r\n  UInt32 _reps[4];\r\n  CState _state;\r\n  Int32 _remainLen; // -1 means end of stream. // -2 means need Init\r\n  UInt64 _outSize;\r\n  bool _outSizeDefined;\r\n\r\n  void Init();\r\n  HRESULT CodeSpec(UInt32 size);\r\npublic:\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  MY_UNKNOWN_IMP5(\r\n      ICompressSetDecoderProperties2, \r\n      ICompressGetInStreamProcessedSize,\r\n      ICompressSetInStream, \r\n      ICompressSetOutStreamSize, \r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize)\r\n  #endif\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _outWindowStream.ReleaseStream();\r\n    ReleaseInStream();\r\n  }\r\n\r\n  class CDecoderFlusher\r\n  {\r\n    CDecoder *_decoder;\r\n  public:\r\n    bool NeedFlush;\r\n    CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}\r\n    ~CDecoderFlusher() \r\n    { \r\n      if (NeedFlush)\r\n        _decoder->Flush();\r\n      _decoder->ReleaseStreams(); \r\n    }\r\n  };\r\n\r\n  HRESULT Flush() {  return _outWindowStream.Flush(); }  \r\n\r\n  STDMETHOD(CodeReal)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  \r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  CDecoder(): _outSizeDefined(false) {}\r\n  virtual ~CDecoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp",
    "content": "// LZMA/Encoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\n#include \"../../../Common/Defs.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"LZMAEncoder.h\"\r\n\r\n// extern \"C\" { #include \"../../../../C/7zCrc.h\" }\r\n\r\n// #define SHOW_STAT\r\n\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\n// struct CCrcInit { CCrcInit() { InitCrcTable(); } } g_CrcInit;\r\n\r\nconst int kDefaultDictionaryLogSize = 22;\r\nconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n#ifndef LZMA_LOG_BSR\r\nByte g_FastPos[1 << kNumLogBits];\r\n\r\nclass CFastPosInit\r\n{\r\npublic:\r\n  CFastPosInit() { Init(); }\r\n  void Init()\r\n  {\r\n    const Byte kFastSlots = kNumLogBits * 2;\r\n    int c = 2;\r\n    g_FastPos[0] = 0;\r\n    g_FastPos[1] = 1;\r\n\r\n    for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n    {\r\n      UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n      for (UInt32 j = 0; j < k; j++, c++)\r\n        g_FastPos[c] = slotFast;\r\n    }\r\n  }\r\n} g_FastPosInit;\r\n#endif\r\n\r\nvoid CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    _encoders[context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nvoid CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, \r\n    Byte matchByte, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    UInt32 matchBit = (matchByte >> i) & 1;\r\n    _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n    if (matchBit != bit)\r\n    {\r\n      while(i != 0)\r\n      {\r\n        i--;\r\n        UInt32 bit = (symbol >> i) & 1;\r\n        _encoders[context].Encode(rangeEncoder, bit);\r\n        context = (context << 1) | bit;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nUInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  if (matchMode)\r\n  {\r\n    do \r\n    {\r\n      i--;\r\n      UInt32 matchBit = (matchByte >> i) & 1;\r\n      UInt32 bit = (symbol >> i) & 1;\r\n      price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit);\r\n      context = (context << 1) | bit;\r\n      if (matchBit != bit)\r\n        break;\r\n    }\r\n    while (i != 0);\r\n  }\r\n  while(i != 0)\r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    price += _encoders[context].GetPrice(bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  return price;\r\n};\r\n\r\n\r\nnamespace NLength {\r\n\r\nvoid CEncoder::Init(UInt32 numPosStates)\r\n{\r\n  _choice.Init();\r\n  _choice2.Init();\r\n  for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n  {\r\n    _lowCoder[posState].Init();\r\n    _midCoder[posState].Init();\r\n  }\r\n  _highCoder.Init();\r\n}\r\n\r\nvoid CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n  {\r\n    _choice.Encode(rangeEncoder, 0);\r\n    _lowCoder[posState].Encode(rangeEncoder, symbol);\r\n  }\r\n  else\r\n  {\r\n    _choice.Encode(rangeEncoder, 1);\r\n    if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n    {\r\n      _choice2.Encode(rangeEncoder, 0);\r\n      _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      _choice2.Encode(rangeEncoder, 1);\r\n      _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CEncoder::SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const\r\n{\r\n  UInt32 a0 = _choice.GetPrice0();\r\n  UInt32 a1 = _choice.GetPrice1();\r\n  UInt32 b0 = a1 + _choice2.GetPrice0();\r\n  UInt32 b1 = a1 + _choice2.GetPrice1();\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + _lowCoder[posState].GetPrice(i);\r\n  }\r\n  for (; i < kNumLowSymbols + kNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + _midCoder[posState].GetPrice(i - kNumLowSymbols);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + _highCoder.GetPrice(i - kNumLowSymbols - kNumMidSymbols);\r\n}\r\n\r\n}\r\n\r\nCEncoder::CEncoder():\r\n  _numFastBytes(kNumFastBytesDefault),\r\n  _distTableSize(kDefaultDictionaryLogSize * 2),\r\n  _posStateBits(2),\r\n  _posStateMask(4 - 1),\r\n  _numLiteralPosStateBits(0),\r\n  _numLiteralContextBits(3),\r\n  _dictionarySize(1 << kDefaultDictionaryLogSize),\r\n  _matchFinderCycles(0),\r\n  #ifdef COMPRESS_MF_MT\r\n  _multiThread(false),\r\n  #endif\r\n  _writeEndMark(false)\r\n{\r\n  MatchFinder_Construct(&_matchFinderBase);\r\n  // _maxMode = false;\r\n  _fastMode = false;\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Construct(&_matchFinderMt);\r\n  _matchFinderMt.MatchFinder = &_matchFinderBase;\r\n  #endif\r\n}\r\n\r\n\r\nstatic void *SzAlloc(size_t size) { return BigAlloc(size); }\r\nstatic void SzFree(void *address) { BigFree(address); }\r\nISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Destruct(&_matchFinderMt, &g_Alloc);\r\n  #endif\r\n  MatchFinder_Free(&_matchFinderBase, &g_Alloc);\r\n}\r\n\r\nstatic const UInt32 kBigHashDicLimit = (UInt32)1 << 24;\r\n\r\nHRESULT CEncoder::Create()\r\n{\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  bool btMode = (_matchFinderBase.btMode != 0);\r\n  #ifdef COMPRESS_MF_MT\r\n  _mtMode = (_multiThread && !_fastMode && btMode);\r\n  #endif\r\n  \r\n  if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _matchFinderBase.bigHash = (_dictionarySize > kBigHashDicLimit);\r\n\r\n  UInt32 numCycles = 16 + (_numFastBytes >> 1);\r\n  if (!btMode)\r\n    numCycles >>= 1;\r\n  if (_matchFinderCycles != 0)\r\n    numCycles = _matchFinderCycles;\r\n  _matchFinderBase.cutValue = numCycles;\r\n  #ifdef COMPRESS_MF_MT\r\n  if (_mtMode)\r\n  {\r\n    RINOK(MatchFinderMt_Create(&_matchFinderMt, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc));\r\n    _matchFinderObj = &_matchFinderMt;\r\n    MatchFinderMt_CreateVTable(&_matchFinderMt, &_matchFinder);\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!MatchFinder_Create(&_matchFinderBase, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc))\r\n      return E_OUTOFMEMORY;\r\n    _matchFinderObj = &_matchFinderBase;\r\n    MatchFinder_CreateVTable(&_matchFinderBase, &_matchFinder);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\ninline wchar_t GetUpperChar(wchar_t c)\r\n{\r\n  if (c >= 'a' && c <= 'z')\r\n    c -= 0x20;\r\n  return c;\r\n}\r\n\r\nstatic int ParseMatchFinder(const wchar_t *s, int *btMode, UInt32 *numHashBytes /* , int *skipModeBits */)\r\n{\r\n  wchar_t c = GetUpperChar(*s++);\r\n  if (c == L'H')\r\n  {\r\n    if (GetUpperChar(*s++) != L'C')\r\n      return 0;\r\n    int numHashBytesLoc = (int)(*s++ - L'0');\r\n    if (numHashBytesLoc < 4 || numHashBytesLoc > 4)\r\n      return 0;\r\n    if (*s++ != 0)\r\n      return 0;\r\n    *btMode = 0;\r\n    *numHashBytes = numHashBytesLoc;\r\n    return 1;\r\n  }\r\n  if (c != L'B')\r\n    return 0;\r\n\r\n  if (GetUpperChar(*s++) != L'T')\r\n    return 0;\r\n  int numHashBytesLoc = (int)(*s++ - L'0');\r\n  if (numHashBytesLoc < 2 || numHashBytesLoc > 4)\r\n    return 0;\r\n  c = GetUpperChar(*s++);\r\n  /*\r\n  int skipModeBitsLoc = 0;\r\n  if (c == L'D')\r\n  {\r\n    skipModeBitsLoc = 2;\r\n    c = GetUpperChar(*s++);\r\n  }\r\n  */\r\n  if (c != L'\\0')\r\n    return 0;\r\n  *btMode = 1;\r\n  *numHashBytes = numHashBytesLoc;\r\n  // *skipModeBits = skipModeBitsLoc;\r\n  return 1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, \r\n    const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  for (UInt32 i = 0; i < numProperties; i++)\r\n  {\r\n    const PROPVARIANT &prop = properties[i];\r\n    switch(propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 numFastBytes = prop.ulVal;\r\n        if(numFastBytes < 5 || numFastBytes > kMatchMaxLen)\r\n          return E_INVALIDARG;\r\n        _numFastBytes = numFastBytes;\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinderCycles:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        _matchFinderCycles = prop.ulVal;\r\n        break;\r\n      }\r\n      case NCoderPropID::kAlgorithm:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 maximize = prop.ulVal;\r\n        _fastMode = (maximize == 0); \r\n        // _maxMode = (maximize >= 2);\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinder:\r\n      {\r\n        if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        if (!ParseMatchFinder(prop.bstrVal, &_matchFinderBase.btMode, &_matchFinderBase.numHashBytes /* , &_matchFinderBase.skipModeBits */))\r\n          return E_INVALIDARG;\r\n        break;\r\n      }\r\n      case NCoderPropID::kMultiThread:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        #ifdef COMPRESS_MF_MT\r\n        Bool newMultiThread = (prop.boolVal == VARIANT_TRUE);\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          ReleaseMatchFinder();\r\n          _multiThread = newMultiThread;\r\n        }\r\n        #endif\r\n        break;\r\n      }\r\n      case NCoderPropID::kNumThreads:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        #ifdef COMPRESS_MF_MT\r\n        Bool newMultiThread = (prop.ulVal > 1) ? True : False;\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          ReleaseMatchFinder();\r\n          _multiThread = newMultiThread;\r\n        }\r\n        #endif\r\n        break;\r\n      }\r\n      case NCoderPropID::kDictionarySize:\r\n      {\r\n        const int kDicLogSizeMaxCompress = 30; // must be <= ((kNumLogBits - 1) * 2) + 7 = 31;\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 dictionarySize = prop.ulVal;\r\n        if (dictionarySize < UInt32(1 << kDicLogSizeMin) ||\r\n            dictionarySize > UInt32(1 << kDicLogSizeMaxCompress))\r\n          return E_INVALIDARG;\r\n        _dictionarySize = dictionarySize;\r\n        UInt32 dicLogSize;\r\n        for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n          if (dictionarySize <= (UInt32(1) << dicLogSize))\r\n            break;\r\n        _distTableSize = dicLogSize * 2;\r\n        break;\r\n      }\r\n      case NCoderPropID::kPosStateBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _posStateBits = value;\r\n        _posStateMask = (1 << _posStateBits) - 1;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitPosBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralPosStateBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitContextBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitContextBitsMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralContextBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kEndMarker:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE);\r\n        break;\r\n      }\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{ \r\n  const UInt32 kPropSize = 5;\r\n  Byte properties[kPropSize];\r\n  properties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n  for (int i = 0; i < 4; i++)\r\n    properties[1 + i] = Byte(_dictionarySize >> (8 * i));\r\n  return WriteStream(outStream, properties, kPropSize, NULL);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _rangeEncoder.SetStream(outStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _rangeEncoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Init()\r\n{\r\n  CBaseState::Init();\r\n\r\n  _rangeEncoder.Init();\r\n\r\n  for(int i = 0; i < kNumStates; i++)\r\n  {\r\n    for (UInt32 j = 0; j <= _posStateMask; j++)\r\n    {\r\n      _isMatch[i][j].Init();\r\n      _isRep0Long[i][j].Init();\r\n    }\r\n    _isRep[i].Init();\r\n    _isRepG0[i].Init();\r\n    _isRepG1[i].Init();\r\n    _isRepG2[i].Init();\r\n  }\r\n\r\n  _literalEncoder.Init();\r\n\r\n  {\r\n    for(UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n      _posSlotEncoder[i].Init();\r\n  }\r\n  {\r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posEncoders[i].Init();\r\n  }\r\n\r\n  _lenEncoder.Init(1 << _posStateBits);\r\n  _repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n  _posAlignEncoder.Init();\r\n\r\n  _longestMatchWasFound = false;\r\n  _optimumEndIndex = 0;\r\n  _optimumCurrentIndex = 0;\r\n  _additionalOffset = 0;\r\n\r\n  return S_OK;\r\n}\r\n\r\n#ifdef SHOW_STAT\r\nstatic int ttt = 0;\r\n#endif\r\n\r\nvoid CEncoder::MovePos(UInt32 num)\r\n{\r\n  #ifdef SHOW_STAT\r\n  ttt += num;\r\n  printf(\"\\n MovePos %d\", num);\r\n  #endif\r\n  if (num != 0)\r\n  {\r\n    _additionalOffset += num;\r\n    _matchFinder.Skip(_matchFinderObj, num);\r\n  }\r\n}\r\n\r\nUInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)\r\n{\r\n  _optimumEndIndex = cur;\r\n  UInt32 posMem = _optimum[cur].PosPrev;\r\n  UInt32 backMem = _optimum[cur].BackPrev;\r\n  do\r\n  {\r\n    if (_optimum[cur].Prev1IsChar)\r\n    {\r\n      _optimum[posMem].MakeAsChar();\r\n      _optimum[posMem].PosPrev = posMem - 1;\r\n      if (_optimum[cur].Prev2)\r\n      {\r\n        _optimum[posMem - 1].Prev1IsChar = false;\r\n        _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n        _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n      }\r\n    }\r\n    UInt32 posPrev = posMem;\r\n    UInt32 backCur = backMem;\r\n\r\n    backMem = _optimum[posPrev].BackPrev;\r\n    posMem = _optimum[posPrev].PosPrev;\r\n\r\n    _optimum[posPrev].BackPrev = backCur;\r\n    _optimum[posPrev].PosPrev = cur;\r\n    cur = posPrev;\r\n  }\r\n  while(cur != 0);\r\n  backRes = _optimum[0].BackPrev;\r\n  _optimumCurrentIndex  = _optimum[0].PosPrev;\r\n  return _optimumCurrentIndex; \r\n}\r\n\r\n/*\r\nOut:\r\n  (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal\r\n*/\r\n\r\nUInt32 CEncoder::GetOptimum(UInt32 position, UInt32 &backRes)\r\n{\r\n  if(_optimumEndIndex != _optimumCurrentIndex)\r\n  {\r\n    const COptimal &optimum = _optimum[_optimumCurrentIndex];\r\n    UInt32 lenRes = optimum.PosPrev - _optimumCurrentIndex;\r\n    backRes = optimum.BackPrev;\r\n    _optimumCurrentIndex = optimum.PosPrev;\r\n    return lenRes;\r\n  }\r\n  _optimumCurrentIndex = _optimumEndIndex = 0;\r\n  \r\n  UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n\r\n  UInt32 lenMain, numDistancePairs;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    lenMain = ReadMatchDistances(numDistancePairs);\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    numDistancePairs = _numDistancePairs;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n  const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n  if (numAvailableBytes < 2)\r\n  {\r\n    backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n  if (numAvailableBytes > kMatchMaxLen)\r\n    numAvailableBytes = kMatchMaxLen;\r\n\r\n  UInt32 reps[kNumRepDistances];\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  UInt32 i;\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    reps[i] = _repDistances[i];\r\n    const Byte *data2 = data - (reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    UInt32 lenTest;\r\n    for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    UInt32 lenRes = repLens[repMaxIndex];\r\n    MovePos(lenRes - 1);\r\n    return lenRes;\r\n  }\r\n\r\n  UInt32 *matchDistances = _matchDistances;\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; \r\n    MovePos(lenMain - 1);\r\n    return lenMain;\r\n  }\r\n  Byte currentByte = *data;\r\n  Byte matchByte = *(data - (reps[0] + 1));\r\n\r\n  if(lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    backRes = (UInt32)-1;\r\n    return 1;\r\n  }\r\n\r\n  _optimum[0].State = _state;\r\n\r\n  UInt32 posState = (position & _posStateMask);\r\n\r\n  _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() + \r\n      _literalEncoder.GetSubCoder(position, _previousByte)->GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n  _optimum[1].MakeAsChar();\r\n\r\n  UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1();\r\n  UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n  if(matchByte == currentByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n    if(shortRepPrice < _optimum[1].Price)\r\n    {\r\n      _optimum[1].Price = shortRepPrice;\r\n      _optimum[1].MakeAsShortRep();\r\n    }\r\n  }\r\n  UInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n  if(lenEnd < 2)\r\n  {\r\n    backRes = _optimum[1].BackPrev;\r\n    return 1;\r\n  }\r\n\r\n  _optimum[1].PosPrev = 0;\r\n  for (i = 0; i < kNumRepDistances; i++)\r\n    _optimum[0].Backs[i] = reps[i];\r\n\r\n  UInt32 len = lenEnd;\r\n  do\r\n    _optimum[len--].Price = kIfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    if (repLen < 2)\r\n      continue;\r\n    UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n      COptimal &optimum = _optimum[repLen];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = i;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n    }\r\n    while(--repLen >= 2);\r\n  }\r\n\r\n  UInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= lenMain)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matchDistances[offs])\r\n      offs += 2;\r\n    for(; ; len++)\r\n    {\r\n      UInt32 distance = matchDistances[offs + 1];\r\n      UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n      COptimal &optimum = _optimum[len];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = distance + kNumRepDistances;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n      if (len == matchDistances[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numDistancePairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  UInt32 cur = 0;\r\n\r\n  for (;;)\r\n  {\r\n    cur++;\r\n    if(cur == lenEnd)\r\n    {\r\n      return Backward(backRes, cur);\r\n    }\r\n    UInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n    UInt32 newLen, numDistancePairs;\r\n    newLen = ReadMatchDistances(numDistancePairs);\r\n    if(newLen >= _numFastBytes)\r\n    {\r\n      _numDistancePairs = numDistancePairs;\r\n      _longestMatchLength = newLen;\r\n      _longestMatchWasFound = true;\r\n      return Backward(backRes, cur);\r\n    }\r\n    position++;\r\n    COptimal &curOptimum = _optimum[cur];\r\n    UInt32 posPrev = curOptimum.PosPrev;\r\n    CState state;\r\n    if (curOptimum.Prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOptimum.Prev2)\r\n      {\r\n        state = _optimum[curOptimum.PosPrev2].State;\r\n        if (curOptimum.BackPrev2 < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      else\r\n        state = _optimum[posPrev].State;\r\n      state.UpdateChar();\r\n    }\r\n    else\r\n      state = _optimum[posPrev].State;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (curOptimum.IsShortRep())\r\n        state.UpdateShortRep();\r\n      else\r\n        state.UpdateChar();\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      if (curOptimum.Prev1IsChar && curOptimum.Prev2)\r\n      {\r\n        posPrev = curOptimum.PosPrev2;\r\n        pos = curOptimum.BackPrev2;\r\n        state.UpdateRep();\r\n      }\r\n      else\r\n      {\r\n        pos = curOptimum.BackPrev;\r\n        if (pos < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      const COptimal &prevOptimum = _optimum[posPrev];\r\n      if (pos < kNumRepDistances)\r\n      {\r\n        reps[0] = prevOptimum.Backs[pos];\r\n        UInt32 i;\r\n        for(i = 1; i <= pos; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n        for(; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i];\r\n      }\r\n      else\r\n      {\r\n        reps[0] = (pos - kNumRepDistances);\r\n        for(UInt32 i = 1; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n      }\r\n    }\r\n    curOptimum.State = state;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n      curOptimum.Backs[i] = reps[i];\r\n    UInt32 curPrice = curOptimum.Price; \r\n    const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n    const Byte currentByte = *data;\r\n    const Byte matchByte = *(data - (reps[0] + 1));\r\n\r\n    UInt32 posState = (position & _posStateMask);\r\n\r\n    UInt32 curAnd1Price = curPrice +\r\n        _isMatch[state.Index][posState].GetPrice0() +\r\n        _literalEncoder.GetSubCoder(position, *(data - 1))->GetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n    COptimal &nextOptimum = _optimum[cur + 1];\r\n\r\n    bool nextIsChar = false;\r\n    if (curAnd1Price < nextOptimum.Price) \r\n    {\r\n      nextOptimum.Price = curAnd1Price;\r\n      nextOptimum.PosPrev = cur;\r\n      nextOptimum.MakeAsChar();\r\n      nextIsChar = true;\r\n    }\r\n\r\n    UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();\r\n    UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n    \r\n    if(matchByte == currentByte &&\r\n        !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n      if(shortRepPrice <= nextOptimum.Price)\r\n      {\r\n        nextOptimum.Price = shortRepPrice;\r\n        nextOptimum.PosPrev = cur;\r\n        nextOptimum.MakeAsShortRep();\r\n        nextIsChar = true;\r\n      }\r\n    }\r\n    /*\r\n    if(newLen == 2 && matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n      continue;\r\n    */\r\n\r\n    numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n    UInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n    if (numAvailableBytes < 2)\r\n      continue;\r\n    if (numAvailableBytes > _numFastBytes)\r\n      numAvailableBytes = _numFastBytes;\r\n    if (!nextIsChar && matchByte != currentByte) // speed optimization\r\n    {\r\n      // try Literal + rep0\r\n      const Byte *data2 = data - (reps[0] + 1);\r\n      UInt32 limit = MyMin(numAvailableBytesFull, _numFastBytes + 1);\r\n      UInt32 temp;\r\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r\n      UInt32 lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        CState state2 = state;\r\n        state2.UpdateChar();\r\n        UInt32 posStateNext = (position + 1) & _posStateMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price + \r\n            _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n            _isRep[state2.Index].GetPrice1();\r\n        // for (; lenTest2 >= 2; lenTest2--)\r\n        {\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while(lenEnd < offset)\r\n            _optimum[++lenEnd].Price = kIfinityPrice;\r\n          UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n              0, lenTest2, state2, posStateNext);\r\n          COptimal &optimum = _optimum[offset];\r\n          if (curAndLenPrice < optimum.Price) \r\n          {\r\n            optimum.Price = curAndLenPrice;\r\n            optimum.PosPrev = cur + 1;\r\n            optimum.BackPrev = 0;\r\n            optimum.Prev1IsChar = true;\r\n            optimum.Prev2 = false;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    UInt32 startLen = 2; // speed optimization \r\n    for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)\r\n    {\r\n      // UInt32 repLen = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n      const Byte *data2 = data - (reps[repIndex] + 1);\r\n      if (data[0] != data2[0] || data[1] != data2[1])\r\n        continue;\r\n      UInt32 lenTest;\r\n      for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);\r\n      while(lenEnd < cur + lenTest)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n      UInt32 lenTestTemp = lenTest;\r\n      UInt32 price = repMatchPrice + GetPureRepPrice(repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = repIndex;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n      }\r\n      while(--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      // if (_maxMode)\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateRep();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = \r\n                price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState) + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice(\r\n                true, data2[lenTest], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextRepMatchPrice = curAndLenCharPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n                _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while(lenEnd < offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    \r\n    //    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n    if (newLen > numAvailableBytes)\r\n    {\r\n      newLen = numAvailableBytes;\r\n      for (numDistancePairs = 0; newLen > matchDistances[numDistancePairs]; numDistancePairs += 2);\r\n      matchDistances[numDistancePairs] = newLen;\r\n      numDistancePairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n      while(lenEnd < cur + newLen)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n      UInt32 offs = 0;\r\n      while(startLen > matchDistances[offs])\r\n        offs += 2;\r\n      UInt32 curBack = matchDistances[offs + 1];\r\n      UInt32 posSlot = GetPosSlot2(curBack);\r\n      for(UInt32 lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice;\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += _distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += _posSlotPrices[lenToPosState][posSlot] + _alignPrices[curBack & kAlignMask];\r\n  \r\n        curAndLenPrice += _lenEncoder.GetPrice(lenTest - kMatchMinLen, posState);\r\n        \r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = curBack + kNumRepDistances;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matchDistances[offs])\r\n        {\r\n          // Try Match + Literal + Rep0\r\n          const Byte *data2 = data - (curBack + 1);\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateMatch();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice( \r\n                true, data2[lenTest], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (posStateNext + 1) & _posStateMask;\r\n            UInt32 nextRepMatchPrice = curAndLenCharPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n                _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while(lenEnd < offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = curBack + kNumRepDistances;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numDistancePairs)\r\n            break;\r\n          curBack = matchDistances[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            posSlot = GetPosSlot2(curBack);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n{\r\n  return ((bigDist >> 7) > smallDist);\r\n}\r\n\r\nUInt32 CEncoder::ReadMatchDistances(UInt32 &numDistancePairs)\r\n{\r\n  UInt32 lenRes = 0;\r\n  numDistancePairs = _matchFinder.GetMatches(_matchFinderObj, _matchDistances);\r\n  #ifdef SHOW_STAT\r\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numDistancePairs / 2);\r\n  if (ttt >= 61994)\r\n    ttt = ttt;\r\n\r\n  ttt++;\r\n  for (UInt32 i = 0; i < numDistancePairs; i += 2)\r\n    printf(\"%2d %6d   | \", _matchDistances[i], _matchDistances[i + 1]);\r\n  #endif\r\n  if (numDistancePairs > 0)\r\n  {\r\n    lenRes = _matchDistances[numDistancePairs - 2];\r\n    if (lenRes == _numFastBytes)\r\n    {\r\n      UInt32 numAvail = _matchFinder.GetNumAvailableBytes(_matchFinderObj) + 1;\r\n      const Byte *pby = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n      UInt32 distance = _matchDistances[numDistancePairs - 1] + 1;\r\n      if (numAvail > kMatchMaxLen)\r\n        numAvail = kMatchMaxLen;\r\n\r\n      const Byte *pby2 = pby - distance;\r\n      for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r\n    }\r\n  }\r\n  _additionalOffset++;\r\n  return lenRes;\r\n}\r\n\r\nUInt32 CEncoder::GetOptimumFast(UInt32 &backRes)\r\n{\r\n  UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n  UInt32 lenMain, numDistancePairs;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    lenMain = ReadMatchDistances(numDistancePairs);\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    numDistancePairs = _numDistancePairs;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n  const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n  if (numAvailableBytes > kMatchMaxLen)\r\n    numAvailableBytes = kMatchMaxLen;\r\n  if (numAvailableBytes < 2)\r\n  {\r\n    backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n\r\n  for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    const Byte *data2 = data - (_repDistances[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    UInt32 len;\r\n    for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);\r\n    if(len >= _numFastBytes)\r\n    {\r\n      backRes = i;\r\n      MovePos(len - 1);\r\n      return len;\r\n    }\r\n    repLens[i] = len;\r\n    if (len > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  UInt32 *matchDistances = _matchDistances;\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; \r\n    MovePos(lenMain - 1);\r\n    return lenMain;\r\n  }\r\n\r\n  UInt32 backMain = 0; // for GCC\r\n  if (lenMain >= 2)\r\n  {\r\n    backMain = matchDistances[numDistancePairs - 1];\r\n    while (numDistancePairs > 2 && lenMain == matchDistances[numDistancePairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matchDistances[numDistancePairs - 3], backMain))\r\n        break;\r\n      numDistancePairs -= 2;\r\n      lenMain = matchDistances[numDistancePairs - 2];\r\n      backMain = matchDistances[numDistancePairs - 1];\r\n    }\r\n    if (lenMain == 2 && backMain >= 0x80)\r\n      lenMain = 1;\r\n  }\r\n\r\n  if (repLens[repMaxIndex] >= 2)\r\n  {\r\n    if (repLens[repMaxIndex] + 1 >= lenMain || \r\n        repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9)) ||\r\n        repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15)))\r\n    {\r\n      backRes = repMaxIndex;\r\n      UInt32 lenRes = repLens[repMaxIndex];\r\n      MovePos(lenRes - 1);\r\n      return lenRes;\r\n    }\r\n  }\r\n  \r\n  if (lenMain >= 2 && numAvailableBytes > 2)\r\n  {\r\n    numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj);\r\n    _longestMatchLength = ReadMatchDistances(_numDistancePairs);\r\n    if (_longestMatchLength >= 2)\r\n    {\r\n      UInt32 newDistance = matchDistances[_numDistancePairs - 1];\r\n      if (_longestMatchLength >= lenMain && newDistance < backMain || \r\n          _longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance) ||\r\n          _longestMatchLength > lenMain + 1 ||\r\n          _longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain))\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        return 1;\r\n      }\r\n    }\r\n    data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n    {\r\n      const Byte *data2 = data - (_repDistances[i] + 1);\r\n      if (data[1] != data2[1] || data[2] != data2[2])\r\n      {\r\n        repLens[i] = 0;\r\n        continue;\r\n      }\r\n      UInt32 len;\r\n      for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);\r\n      if (len + 1 >= lenMain)\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        return 1;\r\n      }\r\n    }\r\n    backRes = backMain + kNumRepDistances; \r\n    MovePos(lenMain - 2);\r\n    return lenMain;\r\n  }\r\n  backRes = UInt32(-1);\r\n  return 1;\r\n}\r\n\r\nHRESULT CEncoder::Flush(UInt32 nowPos)\r\n{\r\n  // ReleaseMFStream();\r\n  if (_matchFinderBase.result != SZ_OK)\r\n    return _matchFinderBase.result;\r\n  WriteEndMarker(nowPos & _posStateMask);\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nvoid CEncoder::WriteEndMarker(UInt32 posState)\r\n{\r\n  // This function for writing End Mark for stream version of LZMA. \r\n  // In current version this feature is not used.\r\n  if (!_writeEndMark)\r\n    return;\r\n\r\n  _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n  _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n  _state.UpdateMatch();\r\n  UInt32 len = kMatchMinLen; // kMatchMaxLen;\r\n  _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n  UInt32 posSlot = (1 << kNumPosSlotBits)  - 1;\r\n  UInt32 lenToPosState = GetLenToPosState(len);\r\n  _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n  UInt32 footerBits = 30;\r\n  UInt32 posReduced = (UInt32(1) << footerBits) - 1;\r\n  _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n  _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n}\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  // _needReleaseMFStream = false;\r\n  #ifdef COMPRESS_MF_MT\r\n  #ifdef USE_ALLOCA\r\n  alloca(0x300);\r\n  #endif\r\n  #endif\r\n  CCoderReleaser coderReleaser(this);\r\n  RINOK(SetStreams(inStream, outStream, inSize, outSize));\r\n  for (;;)\r\n  {\r\n    UInt64 processedInSize;\r\n    UInt64 processedOutSize;\r\n    Int32 finished;\r\n    RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished));\r\n    if (finished != 0)\r\n      break;\r\n    if (progress != 0)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  _inStream = inStream;\r\n  _finished = false;\r\n  RINOK(Create());\r\n  RINOK(SetOutStream(outStream));\r\n  RINOK(Init());\r\n  \r\n  if (!_fastMode)\r\n  {\r\n    FillDistancesPrices();\r\n    FillAlignPrices();\r\n  }\r\n\r\n  _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _lenEncoder.UpdateTables(1 << _posStateBits);\r\n  _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n  nowPos64 = 0;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRes MyRead(void *object, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return (HRes)((CSeqInStream *)object)->RealStream->Read(data, size, processedSize);\r\n}\r\n\r\nHRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)\r\n{\r\n  if (_inStream != 0)\r\n  {\r\n    _seqInStream.RealStream = _inStream;\r\n    _seqInStream.SeqInStream.Read = MyRead;\r\n    _matchFinderBase.stream = &_seqInStream.SeqInStream;\r\n    _matchFinder.Init(_matchFinderObj);\r\n    _needReleaseMFStream = true;\r\n    _inStream = 0;\r\n  }\r\n\r\n\r\n  *finished = 1;\r\n  if (_finished)\r\n    return _matchFinderBase.result;\r\n  _finished = true;\r\n\r\n  if (nowPos64 == 0)\r\n  {\r\n    if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)\r\n      return Flush((UInt32)nowPos64);\r\n    UInt32 len, numDistancePairs;\r\n    len = ReadMatchDistances(numDistancePairs);\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n    _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n    _state.UpdateChar();\r\n    Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset);\r\n    _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte);\r\n    _previousByte = curByte;\r\n    _additionalOffset--;\r\n    nowPos64++;\r\n  }\r\n\r\n  UInt32 nowPos32 = (UInt32)nowPos64;\r\n  UInt32 progressPosValuePrev = nowPos32;\r\n\r\n  if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)\r\n    return Flush(nowPos32);\r\n\r\n  for (;;)\r\n  {\r\n    #ifdef _NO_EXCEPTIONS\r\n    if (_rangeEncoder.Stream.ErrorCode != S_OK)\r\n      return _rangeEncoder.Stream.ErrorCode;\r\n    #endif\r\n    UInt32 pos, len;\r\n\r\n    if (_fastMode)\r\n      len = GetOptimumFast(pos);\r\n    else\r\n      len = GetOptimum(nowPos32, pos);\r\n\r\n    UInt32 posState = nowPos32 & _posStateMask;\r\n    if(len == 1 && pos == 0xFFFFFFFF)\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n      Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset);\r\n      CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(nowPos32, _previousByte);\r\n      if(_state.IsCharState())\r\n        subCoder->Encode(&_rangeEncoder, curByte);\r\n      else\r\n      {\r\n        Byte matchByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _repDistances[0] - 1 - _additionalOffset);\r\n        subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);\r\n      }\r\n      _state.UpdateChar();\r\n      _previousByte = curByte;\r\n    }\r\n    else\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n      if(pos < kNumRepDistances)\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 1);\r\n        if(pos == 0)\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 0);\r\n          _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = _repDistances[pos];\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 1);\r\n          if (pos == 1)\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 0);\r\n          else\r\n          {\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 1);\r\n            _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);\r\n            if (pos == 3)\r\n              _repDistances[3] = _repDistances[2];\r\n            _repDistances[2] = _repDistances[1];\r\n          }\r\n          _repDistances[1] = _repDistances[0];\r\n          _repDistances[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          _state.UpdateShortRep();\r\n        else\r\n        {\r\n          _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n          _state.UpdateRep();\r\n        }\r\n      }\r\n      else\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n        _state.UpdateMatch();\r\n        _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode);\r\n        pos -= kNumRepDistances;\r\n        UInt32 posSlot = GetPosSlot(pos);\r\n        _posSlotEncoder[GetLenToPosState(len)].Encode(&_rangeEncoder, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1, \r\n                &_rangeEncoder, footerBits, posReduced);\r\n          else\r\n          {\r\n            _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n            _alignPriceCount++;\r\n          }\r\n        }\r\n        _repDistances[3] = _repDistances[2];\r\n        _repDistances[2] = _repDistances[1];\r\n        _repDistances[1] = _repDistances[0];\r\n        _repDistances[0] = pos;\r\n        _matchPriceCount++;\r\n      }\r\n      _previousByte = _matchFinder.GetIndexByte(_matchFinderObj, len - 1 - _additionalOffset);\r\n    }\r\n    _additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (_additionalOffset == 0)\r\n    {\r\n      if (!_fastMode)\r\n      {\r\n        if (_matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices();\r\n        if (_alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices();\r\n      }\r\n      if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0)\r\n        return Flush(nowPos32);\r\n      if (nowPos32 - progressPosValuePrev >= (1 << 14))\r\n      {\r\n        nowPos64 += nowPos32 - progressPosValuePrev;\r\n        *inSize = nowPos64;\r\n        *outSize = _rangeEncoder.GetProcessedSize();\r\n        _finished = false;\r\n        *finished = 0;\r\n        return _matchFinderBase.result;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try \r\n  { \r\n  #endif\r\n    return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  #ifndef _NO_EXCEPTIONS\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return E_FAIL; }\r\n  #endif\r\n}\r\n  \r\nvoid CEncoder::FillDistancesPrices()\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  for (UInt32 i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  { \r\n    UInt32 posSlot = GetPosSlot(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = NRangeCoder::ReverseBitTreeGetPrice(_posEncoders + \r\n      base - posSlot - 1, footerBits, i - base);\r\n  }\r\n\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n    UInt32 posSlot;\r\n    NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> &encoder = _posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = _posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = encoder.GetPrice(posSlot);\r\n    for (posSlot = kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);\r\n\r\n    UInt32 *distancesPrices = _distancesPrices[lenToPosState];\r\n    UInt32 i;\r\n    for (i = 0; i < kStartPosModelIndex; i++)\r\n      distancesPrices[i] = posSlotPrices[i];\r\n    for (; i < kNumFullDistances; i++)\r\n      distancesPrices[i] = posSlotPrices[GetPosSlot(i)] + tempPrices[i];\r\n  }\r\n  _matchPriceCount = 0;\r\n}\r\n\r\nvoid CEncoder::FillAlignPrices()\r\n{\r\n  for (UInt32 i = 0; i < kAlignTableSize; i++)\r\n    _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n  _alignPriceCount = 0;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.h",
    "content": "// LZMA/Encoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/Alloc.h\"\r\n  #include \"../../../../C/Compress/Lz/MatchFinder.h\"\r\n  #ifdef COMPRESS_MF_MT\r\n  #include \"../../../../C/Compress/Lz/MatchFinderMt.h\"\r\n  #endif\r\n}\r\n\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;\r\n\r\nclass CBaseState\r\n{\r\nprotected:\r\n  CState _state;\r\n  Byte _previousByte;\r\n  UInt32 _repDistances[kNumRepDistances];\r\n  void Init()\r\n  {\r\n    _state.Init();\r\n    _previousByte = 0;\r\n    for(UInt32 i = 0 ; i < kNumRepDistances; i++)\r\n      _repDistances[i] = 0;\r\n  }\r\n};\r\n\r\nstruct COptimal\r\n{\r\n  CState State;\r\n\r\n  bool Prev1IsChar;\r\n  bool Prev2;\r\n\r\n  UInt32 PosPrev2;\r\n  UInt32 BackPrev2;     \r\n\r\n  UInt32 Price;    \r\n  UInt32 PosPrev;         // posNext;\r\n  UInt32 BackPrev;     \r\n  UInt32 Backs[kNumRepDistances];\r\n  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }\r\n  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n  bool IsShortRep() { return (BackPrev == 0); }\r\n};\r\n\r\n\r\n// #define LZMA_LOG_BRANCH\r\n\r\n#if _MSC_VER >= 1400\r\n// Must give gain in core 2. but slower ~2% on k8.\r\n// #define LZMA_LOG_BSR\r\n#endif\r\n\r\n#ifndef LZMA_LOG_BSR\r\nstatic const int kNumLogBits = 13; // don't change it !\r\nextern Byte g_FastPos[];\r\n#endif\r\ninline UInt32 GetPosSlot(UInt32 pos)\r\n{\r\n  #ifdef LZMA_LOG_BSR\r\n  if (pos < 2)\r\n    return pos;\r\n  unsigned long index;\r\n  _BitScanReverse(&index, pos);\r\n  return (index + index) + ((pos >> (index - 1)) & 1);\r\n  #else\r\n  if (pos < (1 << kNumLogBits))\r\n    return g_FastPos[pos];\r\n  if (pos < (1 << (kNumLogBits * 2 - 1)))\r\n    return g_FastPos[pos >> (kNumLogBits - 1)] + (kNumLogBits - 1) * 2;\r\n  return g_FastPos[pos >> (kNumLogBits - 1) * 2] + (kNumLogBits - 1) * 4;\r\n  #endif\r\n}\r\n\r\ninline UInt32 GetPosSlot2(UInt32 pos)\r\n{\r\n  #ifdef LZMA_LOG_BSR\r\n  unsigned long index;\r\n  _BitScanReverse(&index, pos);\r\n  return (index + index) + ((pos >> (index - 1)) & 1);\r\n  #else\r\n  #ifdef LZMA_LOG_BRANCH\r\n  if (pos < (1 << (kNumLogBits + 6)))\r\n    return g_FastPos[pos >> 6] + 12;\r\n  if (pos < (1 << (kNumLogBits * 2 + 5)))\r\n    return g_FastPos[pos >> (kNumLogBits + 5)] + (kNumLogBits + 5) * 2;\r\n  return g_FastPos[pos >> (kNumLogBits * 2 + 4)] + (kNumLogBits * 2 + 4) * 2;\r\n  #else\r\n  // it's faster with VC6-32bit.\r\n  UInt32 s = 6 + ((kNumLogBits - 1) & (UInt32)((Int32)(((1 << (kNumLogBits + 6)) - 1) -  pos) >> 31));\r\n  return g_FastPos[pos >> s] + (s * 2);\r\n  #endif\r\n  #endif\r\n}\r\n\r\nconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\nconst UInt32 kNumOpts = 1 << 12;\r\n\r\n\r\nclass CLiteralEncoder2\r\n{\r\n  CMyBitEncoder _encoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _encoders[i].Init();\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);\r\n  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;\r\n};\r\n\r\nclass CLiteralEncoder\r\n{\r\n  CLiteralEncoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralEncoder(): _coders(0) {}\r\n  ~CLiteralEncoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)\r\n    { return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CEncoder\r\n{\r\n  CMyBitEncoder _choice;\r\n  CMyBitEncoder _choice2;\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;\r\npublic:\r\n  void Init(UInt32 numPosStates);\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);\r\n  void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;\r\n};\r\n\r\nconst UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\r\n\r\nclass CPriceTableEncoder: public CEncoder\r\n{\r\n  UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];\r\n  UInt32 _tableSize;\r\n  UInt32 _counters[kNumPosStatesEncodingMax];\r\npublic:\r\n  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }\r\n  void UpdateTable(UInt32 posState)\r\n  {\r\n    SetPrices(posState, _tableSize, _prices[posState]);\r\n    _counters[posState] = _tableSize;\r\n  }\r\n  void UpdateTables(UInt32 numPosStates)\r\n  {\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n      UpdateTable(posState);\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)\r\n  {\r\n    CEncoder::Encode(rangeEncoder, symbol, posState);\r\n    if (updatePrice)\r\n      if (--_counters[posState] == 0)\r\n        UpdateTable(posState);\r\n  }\r\n};\r\n\r\n}\r\n\r\ntypedef struct _CSeqInStream\r\n{\r\n  ISeqInStream SeqInStream;\r\n  CMyComPtr<ISequentialInStream> RealStream;\r\n} CSeqInStream;\r\n\r\n\r\nclass CEncoder : \r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CBaseState,\r\n  public CMyUnknownImp\r\n{\r\n  NRangeCoder::CEncoder _rangeEncoder;\r\n\r\n  IMatchFinder _matchFinder;\r\n  void *_matchFinderObj;\r\n  \r\n  #ifdef COMPRESS_MF_MT\r\n  Bool _multiThread;\r\n  Bool _mtMode;\r\n  CMatchFinderMt _matchFinderMt;\r\n  #endif\r\n\r\n  CMatchFinder _matchFinderBase;\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte _pad1[kMtCacheLineDummy];\r\n  #endif\r\n\r\n  COptimal _optimum[kNumOpts];\r\n\r\n  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n  CMyBitEncoder _isRep[kNumStates];\r\n  CMyBitEncoder _isRepG0[kNumStates];\r\n  CMyBitEncoder _isRepG1[kNumStates];\r\n  CMyBitEncoder _isRepG2[kNumStates];\r\n  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];\r\n\r\n  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;\r\n  \r\n  NLength::CPriceTableEncoder _lenEncoder;\r\n  NLength::CPriceTableEncoder _repMatchLenEncoder;\r\n\r\n  CLiteralEncoder _literalEncoder;\r\n\r\n  UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];\r\n\r\n  bool _fastMode;\r\n  // bool _maxMode;\r\n  UInt32 _numFastBytes;\r\n  UInt32 _longestMatchLength;    \r\n  UInt32 _numDistancePairs;\r\n\r\n  UInt32 _additionalOffset;\r\n\r\n  UInt32 _optimumEndIndex;\r\n  UInt32 _optimumCurrentIndex;\r\n\r\n  bool _longestMatchWasFound;\r\n\r\n  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  \r\n  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n\r\n  UInt32 _alignPrices[kAlignTableSize];\r\n  UInt32 _alignPriceCount;\r\n\r\n  UInt32 _distTableSize;\r\n\r\n  UInt32 _posStateBits;\r\n  UInt32 _posStateMask;\r\n  UInt32 _numLiteralPosStateBits;\r\n  UInt32 _numLiteralContextBits;\r\n\r\n  UInt32 _dictionarySize;\r\n\r\n  UInt32 _matchPriceCount;\r\n  UInt64 nowPos64;\r\n  bool _finished;\r\n  ISequentialInStream *_inStream;\r\n\r\n  CSeqInStream _seqInStream;\r\n\r\n  UInt32 _matchFinderCycles;\r\n  // int _numSkip\r\n\r\n  bool _writeEndMark;\r\n\r\n  bool _needReleaseMFStream;\r\n\r\n  void ReleaseMatchFinder()\r\n  {\r\n    _matchFinder.Init = 0;\r\n    _seqInStream.RealStream.Release();\r\n  }\r\n\r\n  void ReleaseMFStream()\r\n  {\r\n    if (_matchFinderObj && _needReleaseMFStream)\r\n    {\r\n      #ifdef COMPRESS_MF_MT\r\n      if (_mtMode)\r\n        MatchFinderMt_ReleaseStream(&_matchFinderMt);\r\n      #endif\r\n      _needReleaseMFStream = false;\r\n    }\r\n    _seqInStream.RealStream.Release();\r\n  }\r\n  \r\n  UInt32 ReadMatchDistances(UInt32 &numDistancePairs);\r\n\r\n  void MovePos(UInt32 num);\r\n  UInt32 GetRepLen1Price(CState state, UInt32 posState) const\r\n  {\r\n    return _isRepG0[state.Index].GetPrice0() +\r\n        _isRep0Long[state.Index][posState].GetPrice0();\r\n  }\r\n  \r\n  UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    if(repIndex == 0)\r\n    {\r\n      price = _isRepG0[state.Index].GetPrice0();\r\n      price += _isRep0Long[state.Index][posState].GetPrice1();\r\n    }\r\n    else\r\n    {\r\n      price = _isRepG0[state.Index].GetPrice1();\r\n      if (repIndex == 1)\r\n        price += _isRepG1[state.Index].GetPrice0();\r\n      else\r\n      {\r\n        price += _isRepG1[state.Index].GetPrice1();\r\n        price += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n      }\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const\r\n  {\r\n    return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +\r\n        GetPureRepPrice(repIndex, state, posState);\r\n  }\r\n  /*\r\n  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const\r\n  {\r\n    if (pos >= kNumFullDistances)\r\n      return kIfinityPrice;\r\n    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);\r\n  }\r\n  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n  */\r\n  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n\r\n  UInt32 Backward(UInt32 &backRes, UInt32 cur);\r\n  UInt32 GetOptimum(UInt32 position, UInt32 &backRes);\r\n  UInt32 GetOptimumFast(UInt32 &backRes);\r\n\r\n  void FillDistancesPrices();\r\n  void FillAlignPrices();\r\n    \r\n  void ReleaseStreams()\r\n  {\r\n    ReleaseMFStream();\r\n    ReleaseOutStream();\r\n  }\r\n\r\n  HRESULT Flush(UInt32 nowPos);\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() { _coder->ReleaseStreams(); }\r\n  };\r\n  friend class CCoderReleaser;\r\n\r\n  void WriteEndMarker(UInt32 posState);\r\n\r\npublic:\r\n  CEncoder();\r\n  void SetWriteEndMarkerMode(bool writeEndMarker)\r\n    { _writeEndMark= writeEndMarker; }\r\n\r\n  HRESULT Create();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  HRESULT Init();\r\n  \r\n  // ICompressCoder interface\r\n  HRESULT SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize);\r\n  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);\r\n\r\n  HRESULT CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressCoder interface\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressSetCoderProperties2\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  \r\n  // ICompressWriteCoderProperties\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA/LZMARegister.cpp",
    "content": "// LZMARegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterCodec.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLZMA::CDecoder); }\r\n#ifndef EXTRACT_ONLY\r\n#include \"LZMAEncoder.h\"\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLZMA::CEncoder);  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x030101, L\"LZMA\", 1, false };\r\n\r\nREGISTER_CODEC(LZMA)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /FAcs /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"C-Lz\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\MatchFinderMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lzma\\LzmaDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lzma\\LzmaDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lzma\\LzmaTypes.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchTypes.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#include \"LzmaBenchCon.h\"\r\n#include \"LzmaRam.h\"\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"LzmaRamDecode.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kMode,\r\n  kDictionary,\r\n  kFastBytes,\r\n  kMatchFinderCycles,\r\n  kLitContext,\r\n  kLitPos,\r\n  kPosBits,\r\n  kMatchFinder,\r\n  kMultiThread,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MT\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kPostChar, false, 0, 0, L\"+\" }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\"\r\n    \"  -d{N}:  set dictionary - [0,30], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -mc{N}: set number of cycles for match finder\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\\n\"\r\n    \"  -mt{N}: set number of CPU threads\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[], \r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);\r\n  if (unsupportedTypes)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }   \r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++]; \r\n\r\n  bool dictionaryIsDefined = false;\r\n  UInt32 dictionary = (UInt32)-1;\r\n  if(parser[NKey::kDictionary].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dictionary = 1 << dicLog;\r\n    dictionaryIsDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  UInt32 numThreads = (UInt32)-1;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (parser[NKey::kMultiThread].ThereIs)\r\n  {\r\n    UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n    const UString &s = parser[NKey::kMultiThread].PostStrings[0];\r\n    if (s.IsEmpty())\r\n      numThreads = numCPUs;\r\n    else\r\n      if (!GetNumber(s, numThreads))\r\n        IncorrectCommand();\r\n  }\r\n  #endif\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 1;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchCon(stderr, numIterations, numThreads, dictionary);\r\n  }\r\n\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = 1;\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++]; \r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\", \r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  COutFileStream *outStreamSpec = NULL;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++]; \r\n    outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\", \r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    UInt32 inSize = (UInt32)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize); \r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)\r\n      throw \"Can not read\";\r\n    if ((UInt32)inSize != processedSize)\r\n      throw \"Read size error\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSizeProcessed;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictionaryIsDefined)\r\n        dictionary = 1 << 23;\r\n      int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, \r\n          dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      size_t outSize;\r\n      if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)\r\n        throw \"data error\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictionaryIsDefined)\r\n      dictionary = 1 << 23;\r\n\r\n    UInt32 posStateBits = 2;\r\n    UInt32 litContextBits = 3; // for normal files\r\n    // UInt32 litContextBits = 0; // for 32-bit data\r\n    UInt32 litPosBits = 0;\r\n    // UInt32 litPosBits = 2; // for 32-bit data\r\n    UInt32 algorithm = 1;\r\n    UInt32 numFastBytes = 128;\r\n    UInt32 matchFinderCycles = 16 + numFastBytes / 2;\r\n    bool matchFinderCyclesDefined = false;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    if(parser[NKey::kMode].ThereIs)\r\n      if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))\r\n        IncorrectCommand();\r\n\r\n    if(parser[NKey::kFastBytes].ThereIs)\r\n      if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))\r\n        IncorrectCommand();\r\n    matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs;\r\n    if (matchFinderCyclesDefined)\r\n      if (!GetNumber(parser[NKey::kMatchFinderCycles].PostStrings[0], matchFinderCycles))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitContext].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitPos].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kPosBits].ThereIs)\r\n      if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))\r\n        IncorrectCommand();\r\n\r\n    PROPID propIDs[] = \r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker,\r\n      NCoderPropID::kNumThreads,\r\n      NCoderPropID::kMatchFinderCycles,\r\n    };\r\n    const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\r\n    PROPVARIANT properties[kNumPropsMax];\r\n    for (int p = 0; p < 6; p++)\r\n      properties[p].vt = VT_UI4;\r\n\r\n    properties[0].ulVal = (UInt32)dictionary;\r\n    properties[1].ulVal = (UInt32)posStateBits;\r\n    properties[2].ulVal = (UInt32)litContextBits;\r\n    properties[3].ulVal = (UInt32)litPosBits;\r\n    properties[4].ulVal = (UInt32)algorithm;\r\n    properties[5].ulVal = (UInt32)numFastBytes;\r\n\r\n    properties[6].vt = VT_BSTR;\r\n    properties[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    properties[7].vt = VT_BOOL;\r\n    properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    properties[8].vt = VT_UI4;\r\n    properties[8].ulVal = (UInt32)numThreads;\r\n\r\n    // it must be last in property list\r\n    properties[9].vt = VT_UI4;\r\n    properties[9].ulVal = (UInt32)matchFinderCycles;\r\n\r\n    int numProps = kNumPropsMax;\r\n    if (!matchFinderCyclesDefined)\r\n      numProps--;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }   \r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }   \r\n  }\r\n  else\r\n  {\r\n    NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte properties[kPropertiesSize];\r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, properties, kPropertiesSize, &processedSize) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (processedSize != kPropertiesSize)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b;\r\n      if (inStream->Read(&b, 1, &processedSize) != S_OK)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      if (processedSize != 1)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      fileSize |= ((UInt64)b) << (8 * i);\r\n    }\r\n    if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }   \r\n  }\r\n  if (outStreamSpec != NULL)\r\n  {\r\n    if (outStreamSpec->Close() != S_OK)\r\n    {\r\n      fprintf(stderr, \"File closing error\");\r\n      return 1;\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n\r\nint main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s) \r\n  { \r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1; \r\n  }\r\n  catch(...) \r\n  { \r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1; \r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#define USE_POSIX_TIME\r\n#define USE_POSIX_TIME2\r\n#endif\r\n\r\n#ifdef USE_POSIX_TIME\r\n#include <time.h>\r\n#ifdef USE_POSIX_TIME2\r\n#include <sys/time.h>\r\n#endif\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef BENCH_MT\r\n#include \"../../../Windows/Thread.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#endif\r\n\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../../Windows/PropVariant.h\"\r\n#else\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#endif\r\n\r\nstatic const UInt32 kUncompressMinBlockSize = 1 << 26;\r\nstatic const UInt32 kAdditionalSize = (1 << 16);\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 5;\r\n\r\nclass CBaseRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CBaseRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd() \r\n  {\r\n    return \r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBenchBuffer\r\n{\r\npublic:\r\n  size_t BufferSize;\r\n  Byte *Buffer;\r\n  CBenchBuffer(): Buffer(0) {} \r\n  virtual ~CBenchBuffer() { Free(); }\r\n  void Free() \r\n  { \r\n    ::MidFree(Buffer);\r\n    Buffer = 0;\r\n  }\r\n  bool Alloc(size_t bufferSize) \r\n  {\r\n    if (Buffer != 0 && BufferSize == bufferSize)\r\n      return true;\r\n    Free();\r\n    Buffer = (Byte *)::MidAlloc(bufferSize);\r\n    BufferSize = bufferSize;\r\n    return (Buffer != 0);\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator: public CBenchBuffer\r\n{\r\n  CBaseRandomGenerator *RG;\r\npublic:\r\n  void Set(CBaseRandomGenerator *rg) { RG = rg; }\r\n  UInt32 GetVal(UInt32 &res, int numBits) \r\n  {\r\n    UInt32 val = res & (((UInt32)1 << numBits) - 1);\r\n    res >>= numBits;\r\n    return val;\r\n  }\r\n  UInt32 GetLen(UInt32 &res) \r\n  { \r\n    UInt32 len = GetVal(res, 2);\r\n    return GetVal(res, 1 + len);\r\n  }\r\n  void Generate()\r\n  {\r\n    UInt32 pos = 0;\r\n    UInt32 rep0 = 1;\r\n    while (pos < BufferSize)\r\n    {\r\n      UInt32 res = RG->GetRnd();\r\n      res >>= 1;\r\n      if (GetVal(res, 1) == 0 || pos < 1024)\r\n        Buffer[pos++] = (Byte)(res & 0xFF);\r\n      else\r\n      {\r\n        UInt32 len;\r\n        len = 1 + GetLen(res);\r\n        if (GetVal(res, 3) != 0)\r\n        {\r\n          len += GetLen(res);\r\n          do\r\n          {\r\n            UInt32 ppp = GetVal(res, 5) + 6;\r\n            res = RG->GetRnd();\r\n            if (ppp > 30)\r\n              continue;\r\n            rep0 = /* (1 << ppp) +*/  GetVal(res, ppp);\r\n            res = RG->GetRnd();\r\n          }\r\n          while (rep0 >= pos);\r\n          rep0++;\r\n        }\r\n\r\n        for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)\r\n          Buffer[pos] = Buffer[pos - rep0];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\n\r\nclass CBenchmarkInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Pos;\r\n  size_t Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t remain = Size - Pos;\r\n  UInt32 kMaxBlockSize = (1 << 20);\r\n  if (size > kMaxBlockSize)\r\n    size = kMaxBlockSize;\r\n  if (size > remain)\r\n    size = (UInt32)remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream: \r\n  public ISequentialOutStream,\r\n  public CBenchBuffer,\r\n  public CMyUnknownImp\r\n{\r\n  // bool _overflow;\r\npublic:\r\n  UInt32 Pos;\r\n  // CBenchmarkOutStream(): _overflow(false) {} \r\n  void Init() \r\n  {\r\n    // _overflow = false;\r\n    Pos = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t curSize = BufferSize - Pos;\r\n  if (curSize > size)\r\n    curSize = size;\r\n  memcpy(Buffer + Pos, data, curSize);\r\n  Pos += (UInt32)curSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)curSize;\r\n  if (curSize != size)\r\n  {\r\n    // _overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  UInt32 Crc;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { Crc = CRC_INIT_VAL; }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  Crc = CrcUpdate(Crc, data, size);\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  timeval v;\r\n  if (gettimeofday(&v, 0) == 0)\r\n    return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;\r\n  return (UInt64)time(NULL) * 1000000;\r\n  #else\r\n  return time(NULL);\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return GetTickCount();\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  return 1000000;\r\n  #else\r\n  return 1;\r\n  #endif \r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return 1000;\r\n  #endif \r\n}\r\n\r\n#ifndef USE_POSIX_TIME\r\nstatic inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }\r\n#endif\r\nstatic UInt64 GetUserTime()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return clock();\r\n  #else\r\n  FILETIME creationTime, exitTime, kernelTime, userTime;\r\n  if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)\r\n    return GetTime64(userTime) + GetTime64(kernelTime);\r\n  return (UInt64)GetTickCount() * 10000;\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetUserFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return CLOCKS_PER_SEC;\r\n  #else\r\n  return 10000000;\r\n  #endif \r\n}\r\n\r\nclass CBenchProgressStatus\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::NSynchronization::CCriticalSection CS;  \r\n  #endif\r\npublic:\r\n  HRESULT Res;\r\n  bool EncodeMode;\r\n  void SetResult(HRESULT res) \r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    Res = res;\r\n  }\r\n  HRESULT GetResult()\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    return Res;\r\n  }\r\n};\r\n\r\nclass CBenchProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CBenchProgressStatus *Status;\r\n  CBenchInfo BenchInfo;\r\n  HRESULT Res;\r\n  IBenchCallback *callback;\r\n  CBenchProgressInfo(): callback(0) {}\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nvoid SetStartTime(CBenchInfo &bi)\r\n{\r\n  bi.GlobalFreq = GetFreq();\r\n  bi.UserFreq = GetUserFreq();\r\n  bi.GlobalTime = ::GetTimeCount();\r\n  bi.UserTime = ::GetUserTime();\r\n}\r\n\r\nvoid SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)\r\n{\r\n  dest.GlobalFreq = GetFreq();\r\n  dest.UserFreq = GetUserFreq();\r\n  dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;\r\n  dest.UserTime = ::GetUserTime() - biStart.UserTime;\r\n}\r\n\r\nSTDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  HRESULT res = Status->GetResult();\r\n  if (res != S_OK)\r\n    return res;\r\n  if (!callback)\r\n    return res;\r\n  CBenchInfo info = BenchInfo;\r\n  SetFinishTime(BenchInfo, info);\r\n  if (Status->EncodeMode)\r\n  {\r\n    info.UnpackSize = *inSize;\r\n    info.PackSize = *outSize;\r\n    res = callback->SetEncodeResult(info, false);\r\n  }\r\n  else\r\n  {\r\n    info.PackSize = BenchInfo.PackSize + *inSize;\r\n    info.UnpackSize = BenchInfo.UnpackSize + *outSize;\r\n    res = callback->SetDecodeResult(info, false);\r\n  }\r\n  if (res != S_OK)\r\n    Status->SetResult(res);\r\n  return res;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nUInt64 GetUsage(const CBenchInfo &info)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userTime, userFreq);\r\n  NormalizeVals(globalFreq, globalTime);\r\n  if (userFreq == 0)\r\n    userFreq = 1;\r\n  if (globalTime == 0)\r\n    globalTime = 1;\r\n  return userTime * globalFreq * 1000000 / userFreq / globalTime;\r\n}\r\n\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userFreq, userTime);\r\n  NormalizeVals(globalTime, globalFreq);\r\n  if (globalFreq == 0)\r\n    globalFreq = 1;\r\n  if (userTime == 0)\r\n    userTime = 1;\r\n  return userFreq * globalTime / globalFreq *  rating / userTime;\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)\r\n{\r\n  UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);\r\n  // UInt64 numCommandsForOne = 1000 + ((t * t * 7) >> (2 * kSubBits)); // AMD K8\r\n  UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits)); // Intel Core2\r\n\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)\r\n{\r\n  // UInt64 numCommands = (inSize * 216 + outSize * 14) * numIterations; // AMD K8\r\n  UInt64 numCommands = (inSize * 220 + outSize * 8) * numIterations; // Intel Core2\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\n#ifdef EXTERNAL_LZMA\r\ntypedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID, \r\n    const GUID *interfaceID, void **outObject);\r\n#endif\r\n\r\nstruct CEncoderInfo;\r\n\r\nstruct CEncoderInfo\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::CThread thread[2];\r\n  #endif\r\n  CMyComPtr<ICompressCoder> encoder;\r\n  CBenchProgressInfo *progressInfoSpec[2];\r\n  CMyComPtr<ICompressProgressInfo> progressInfo[2];\r\n  UInt32 NumIterations;\r\n  #ifdef USE_ALLOCA\r\n  size_t AllocaSize;\r\n  #endif\r\n\r\n  struct CDecoderInfo\r\n  {\r\n    CEncoderInfo *Encoder;\r\n    UInt32 DecoderIndex;\r\n    #ifdef USE_ALLOCA\r\n    size_t AllocaSize;\r\n    #endif\r\n    bool CallbackMode;\r\n  };\r\n  CDecoderInfo decodersInfo[2];\r\n\r\n  CMyComPtr<ICompressCoder> decoders[2];\r\n  HRESULT Results[2];\r\n  CBenchmarkOutStream *outStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  IBenchCallback *callback;\r\n  UInt32 crc;\r\n  UInt32 kBufferSize;\r\n  UInt32 compressedSize;\r\n  CBenchRandomGenerator rg;\r\n  CBenchmarkOutStream *propStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> propStream;\r\n  HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);\r\n  HRESULT Encode();\r\n  HRESULT Decode(UInt32 decoderIndex);\r\n\r\n  CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}\r\n\r\n  #ifdef BENCH_MT\r\n  static THREAD_FUNC_DECL EncodeThreadFunction(void *param)\r\n  {\r\n    CEncoderInfo *encoder = (CEncoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(encoder->AllocaSize);\r\n    #endif\r\n    HRESULT res = encoder->Encode();\r\n    encoder->Results[0] = res;\r\n    if (res != S_OK)\r\n      encoder->progressInfoSpec[0]->Status->SetResult(res);\r\n\r\n    return 0;\r\n  }\r\n  static THREAD_FUNC_DECL DecodeThreadFunction(void *param)\r\n  {\r\n    CDecoderInfo *decoder = (CDecoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(decoder->AllocaSize);\r\n    #endif\r\n    CEncoderInfo *encoder = decoder->Encoder;\r\n    encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);\r\n    return 0;\r\n  }\r\n\r\n  HRESULT CreateEncoderThread()\r\n  {\r\n    return thread[0].Create(EncodeThreadFunction, this);\r\n  }\r\n\r\n  HRESULT CreateDecoderThread(int index, bool callbackMode\r\n      #ifdef USE_ALLOCA\r\n      , size_t allocaSize\r\n      #endif\r\n      )\r\n  {\r\n    CDecoderInfo &decoder = decodersInfo[index];\r\n    decoder.DecoderIndex = index;\r\n    decoder.Encoder = this;\r\n    #ifdef USE_ALLOCA\r\n    decoder.AllocaSize = allocaSize;\r\n    #endif\r\n    decoder.CallbackMode = callbackMode;\r\n    return thread[index].Create(DecodeThreadFunction, &decoder);\r\n  }\r\n  #endif\r\n};\r\n\r\nHRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)\r\n{\r\n  rg.Set(rgLoc);\r\n  kBufferSize = dictionarySize + kAdditionalSize;\r\n  UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n  if (!rg.Alloc(kBufferSize))\r\n    return E_OUTOFMEMORY;\r\n  rg.Generate();\r\n  crc = CrcCalc(rg.Buffer, rg.BufferSize);\r\n\r\n  outStreamSpec = new CBenchmarkOutStream;\r\n  if (!outStreamSpec->Alloc(kCompressedBufferSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  outStream = outStreamSpec;\r\n\r\n  propStreamSpec = 0;\r\n  if (!propStream)\r\n  {\r\n    propStreamSpec = new CBenchmarkOutStream;\r\n    propStream = propStreamSpec;\r\n  }\r\n  if (!propStreamSpec->Alloc(kMaxLzmaPropSize))\r\n    return E_OUTOFMEMORY;\r\n  propStreamSpec->Init();\r\n  \r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kDictionarySize, \r\n    NCoderPropID::kMultiThread\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)dictionarySize;\r\n\r\n  properties[1].vt = VT_BOOL;\r\n  properties[1].boolVal = (numThreads > 1) ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n  {\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));\r\n    if (!setCoderProperties)\r\n      return E_FAIL;\r\n    RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, kNumProps));\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);\r\n    if (writeCoderProperties)\r\n    {\r\n      RINOK(writeCoderProperties->WriteCoderProperties(propStream));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Encode()\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n  outStreamSpec->Init();\r\n\r\n  RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));\r\n  compressedSize = outStreamSpec->Pos;\r\n  encoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Decode(UInt32 decoderIndex)\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];\r\n\r\n  CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;\r\n  decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);\r\n  if (!compressSetDecoderProperties)\r\n    return E_FAIL;\r\n\r\n  CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n  CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n  CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];\r\n  pi->BenchInfo.UnpackSize = 0;\r\n  pi->BenchInfo.PackSize = 0;\r\n\r\n  for (UInt32 j = 0; j < NumIterations; j++)\r\n  {\r\n    inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n    crcOutStreamSpec->Init();\r\n    \r\n    RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));\r\n    UInt64 outSize = kBufferSize;\r\n    RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));\r\n    if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)\r\n      return S_FALSE;\r\n    pi->BenchInfo.UnpackSize += kBufferSize;\r\n    pi->BenchInfo.PackSize += compressedSize;\r\n  }\r\n  decoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nstatic const UInt32 kNumThreadsMax = (1 << 16);\r\n\r\nstruct CBenchEncoders\r\n{\r\n  CEncoderInfo *encoders;\r\n  CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }\r\n  ~CBenchEncoders() { delete []encoders; }\r\n};\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)\r\n{\r\n  UInt32 numEncoderThreads = \r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? numThreads / 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  UInt32 numSubDecoderThreads = \r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)\r\n  {\r\n    return E_INVALIDARG;\r\n  }\r\n\r\n  CBenchEncoders encodersSpec(numEncoderThreads);\r\n  CEncoderInfo *encoders = encodersSpec.encoders;\r\n\r\n  #ifdef EXTERNAL_LZMA\r\n  UString name = L\"LZMA\";\r\n  #endif\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.callback = (i == 0) ? callback : 0;\r\n\r\n    #ifdef EXTERNAL_LZMA\r\n    RINOK(codecs->CreateCoder(name, true, encoder.encoder));\r\n    #else\r\n    encoder.encoder = new NCompress::NLZMA::CEncoder;\r\n    #endif\r\n    for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n    {\r\n      #ifdef EXTERNAL_LZMA\r\n      RINOK(codecs->CreateCoder(name, false, encoder.decoders[j]));\r\n      #else\r\n      encoder.decoders[j] = new NCompress::NLZMA::CDecoder;\r\n      #endif\r\n    }\r\n  }\r\n\r\n  CBaseRandomGenerator rg;\r\n  rg.Init();\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));\r\n  }\r\n\r\n  CBenchProgressStatus status;\r\n  status.Res = S_OK;\r\n  status.EncodeMode = true;\r\n\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;\r\n      encoder.progressInfoSpec[j]->Status = &status;\r\n    }\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numEncoderThreads > 1)\r\n    {\r\n      #ifdef USE_ALLOCA\r\n      encoder.AllocaSize = (i * 16 * 21) & 0x7FF;\r\n      #endif\r\n      RINOK(encoder.CreateEncoderThread())\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Encode());\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  if (numEncoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      encoders[i].thread[0].Wait();\r\n  #endif\r\n\r\n  RINOK(status.Res);\r\n\r\n  CBenchInfo info;\r\n\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = 1; // progressInfoSpec->NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetEncodeResult(info, true));\r\n\r\n\r\n  status.Res = S_OK;\r\n  status.EncodeMode = false;\r\n\r\n  UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;\r\n\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numDecoderThreads > 1)\r\n    {\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        size_t allocaSize = ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF;\r\n        HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)\r\n            #ifdef USE_ALLOCA\r\n            , allocaSize\r\n            #endif\r\n            );\r\n        RINOK(res);\r\n      }\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Decode(0));\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  HRESULT res = S_OK;\r\n  if (numDecoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        CEncoderInfo &encoder = encoders[i];\r\n        encoder.thread[j].Wait();\r\n        if (encoder.Results[j] != S_OK)\r\n          res = encoder.Results[j];\r\n      }\r\n  RINOK(res);\r\n  #endif\r\n  RINOK(status.Res);\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetDecodeResult(info, false));\r\n  RINOK(callback->SetDecodeResult(info, true));\r\n  return S_OK;\r\n}\r\n\r\n\r\ninline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)\r\n{ \r\n  UInt32 hs = dictionary - 1;\r\n  hs |= (hs >> 1);\r\n  hs |= (hs >> 2);\r\n  hs |= (hs >> 4);\r\n  hs |= (hs >> 8);\r\n  hs >>= 1;\r\n  hs |= 0xFFFF;\r\n  if (hs > (1 << 24))\r\n    hs >>= 1;\r\n  hs++;\r\n  return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 + \r\n      (1 << 20) + (multiThread ? (6 << 20) : 0);\r\n}\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  const UInt32 kBufferSize = dictionary;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2);\r\n  UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;\r\n  UInt32 numBigThreads = numThreads / numSubThreads;\r\n  return (kBufferSize + kCompressedBufferSize +\r\n    GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;\r\n}\r\n\r\nstatic bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)\r\n{\r\n  for (UInt32 i = 0; i < numCycles; i++)\r\n    if (CrcCalc(data, size) != crcBase)\r\n      return false;\r\n  return true;\r\n}\r\n\r\n#ifdef BENCH_MT\r\nstruct CCrcInfo\r\n{\r\n  NWindows::CThread Thread;\r\n  const Byte *Data;\r\n  UInt32 Size;\r\n  UInt32 NumCycles;\r\n  UInt32 Crc;\r\n  bool Res;\r\n  void Wait()\r\n  {\r\n    Thread.Wait();\r\n    Thread.Close();\r\n  }\r\n};\r\n\r\nstatic THREAD_FUNC_DECL CrcThreadFunction(void *param)\r\n{\r\n  CCrcInfo *p = (CCrcInfo *)param;\r\n  p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);\r\n  return 0;\r\n}\r\n\r\nstruct CCrcThreads\r\n{\r\n  UInt32 NumThreads;\r\n  CCrcInfo *Items;\r\n  CCrcThreads(): Items(0), NumThreads(0) {}\r\n  void WaitAll()\r\n  {\r\n    for (UInt32 i = 0; i < NumThreads; i++)\r\n      Items[i].Wait();\r\n    NumThreads = 0;\r\n  }\r\n  ~CCrcThreads() \r\n  { \r\n    WaitAll();\r\n    delete []Items; \r\n  }\r\n};\r\n#endif\r\n\r\nstatic UInt32 CrcCalc1(const Byte *buf, UInt32 size)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    crc = CRC_UPDATE_BYTE(crc, buf[i]);\r\n  return CRC_GET_DIGEST(crc);\r\n}\r\n\r\nstatic void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  for (UInt32 i = 0; i < size; i++)\r\n    buf[i] = (Byte)RG.GetRnd();\r\n}\r\n\r\nstatic UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  RandGen(buf, size, RG);\r\n  return CrcCalc1(buf, size);\r\n}\r\n\r\nbool CrcInternalTest()\r\n{\r\n  CBenchBuffer buffer;\r\n  const UInt32 kBufferSize0 = (1 << 8);\r\n  const UInt32 kBufferSize1 = (1 << 10);\r\n  const UInt32 kCheckSize = (1 << 5);\r\n  if (!buffer.Alloc(kBufferSize0 + kBufferSize1))\r\n    return false;\r\n  Byte *buf = buffer.Buffer;\r\n  UInt32 i;\r\n  for (i = 0; i < kBufferSize0; i++)\r\n    buf[i] = (Byte)i;\r\n  UInt32 crc1 = CrcCalc1(buf, kBufferSize0);\r\n  if (crc1 != 0x29058C73)\r\n    return false;\r\n  CBaseRandomGenerator RG;\r\n  RandGen(buf + kBufferSize0, kBufferSize1, RG);\r\n  for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)\r\n    for (UInt32 j = 0; j < kCheckSize; j++)\r\n      if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))\r\n        return false;\r\n  return true;\r\n}\r\n\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)\r\n{\r\n  if (numThreads == 0)\r\n    numThreads = 1;\r\n\r\n  CBenchBuffer buffer;\r\n  size_t totalSize = (size_t)bufferSize * numThreads;\r\n  if (totalSize / numThreads != bufferSize)\r\n    return E_OUTOFMEMORY;\r\n  if (!buffer.Alloc(totalSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  Byte *buf = buffer.Buffer;\r\n  CBaseRandomGenerator RG;\r\n  UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;\r\n\r\n  UInt64 timeVal;\r\n  #ifdef BENCH_MT\r\n  CCrcThreads threads;\r\n  if (numThreads > 1)\r\n  {\r\n    threads.Items = new CCrcInfo[numThreads];\r\n    UInt32 i;\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      Byte *data = buf + (size_t)bufferSize * i;\r\n      info.Data = data;\r\n      info.NumCycles = numCycles;\r\n      info.Size = bufferSize;\r\n      info.Crc = RandGenCrc(data, bufferSize, RG);\r\n    }\r\n    timeVal = GetTimeCount();\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      RINOK(info.Thread.Create(CrcThreadFunction, &info));\r\n      threads.NumThreads++;\r\n    }\r\n    threads.WaitAll();\r\n    for (i = 0; i < numThreads; i++)\r\n      if (!threads.Items[i].Res)\r\n        return S_FALSE;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 crc = RandGenCrc(buf, bufferSize, RG);\r\n    timeVal = GetTimeCount();\r\n    if (!CrcBig(buf, bufferSize, numCycles, crc))\r\n      return S_FALSE;\r\n  }\r\n  timeVal = GetTimeCount() - timeVal;\r\n  if (timeVal == 0)\r\n    timeVal = 1;\r\n\r\n  UInt64 size = (UInt64)numCycles * totalSize;\r\n  speed = MyMultDiv64(size, timeVal, GetFreq());\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LZMABENCH_H\r\n#define __LZMABENCH_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\n\r\nstruct CBenchInfo\r\n{\r\n  UInt64 GlobalTime;\r\n  UInt64 GlobalFreq; \r\n  UInt64 UserTime; \r\n  UInt64 UserFreq;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt32 NumIterations;\r\n  CBenchInfo(): NumIterations(0) {}\r\n};\r\n\r\nstruct IBenchCallback\r\n{\r\n  virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;\r\n  virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;\r\n};\r\n\r\nUInt64 GetUsage(const CBenchInfo &benchOnfo);\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);\r\n\r\nconst int kBenchMinDicLogSize = 18;\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);\r\n\r\nbool CrcInternalTest();\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp",
    "content": "// LzmaBenchCon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaBenchCon.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#if defined(BENCH_MT) || defined(_WIN32)\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#ifdef BREAK_HANDLER\r\n#include \"../../UI/Console/ConsoleClose.h\"\r\n#endif\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nstruct CTotalBenchRes\r\n{\r\n  UInt64 NumIterations;\r\n  UInt64 Rating;\r\n  UInt64 Usage;\r\n  UInt64 RPU;\r\n  void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }\r\n  void Normalize() \r\n  { \r\n    if (NumIterations == 0) \r\n      return;\r\n    Rating /= NumIterations; \r\n    Usage /= NumIterations; \r\n    RPU /= NumIterations; \r\n    NumIterations = 1;\r\n  }\r\n  void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2) \r\n  { \r\n    Rating = (r1.Rating + r2.Rating) / 2; \r\n    Usage = (r1.Usage + r2.Usage) / 2;\r\n    RPU = (r1.RPU + r2.RPU) / 2;\r\n    NumIterations = (r1.NumIterations + r2.NumIterations) / 2;\r\n  }\r\n};\r\n\r\nstruct CBenchCallback: public IBenchCallback\r\n{\r\n  CTotalBenchRes EncodeRes;\r\n  CTotalBenchRes DecodeRes;\r\n  FILE *f;\r\n  void Init() { EncodeRes.Init(); DecodeRes.Init(); }\r\n  void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }\r\n  UInt32 dictionarySize;\r\n  HRESULT SetEncodeResult(const CBenchInfo &info, bool final);\r\n  HRESULT SetDecodeResult(const CBenchInfo &info, bool final);\r\n};\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic void PrintNumber(FILE *f, UInt64 value, int size)\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(value, s);\r\n  fprintf(f, \" \");\r\n  for (int len = (int)strlen(s); len < size; len++)\r\n    fprintf(f, \" \");\r\n  fprintf(f, \"%s\", s);\r\n}\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  PrintNumber(f, rating / 1000000, 6);\r\n}\r\n\r\nstatic void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)\r\n{\r\n  PrintNumber(f, (usage + 5000) / 10000, 5);\r\n  PrintRating(f, rpu);\r\n  PrintRating(f, rating);\r\n}\r\n\r\n\r\nstatic void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)\r\n{\r\n  UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);\r\n  PrintNumber(f, speed / 1024, 7);\r\n  UInt64 usage = GetUsage(info);\r\n  UInt64 rpu = GetRatingPerUsage(info, rating);\r\n  PrintResults(f, usage, rpu, rating);\r\n  res.NumIterations++;\r\n  res.RPU += rpu;\r\n  res.Rating += rating;\r\n  res.Usage += usage;\r\n}\r\n\r\nstatic void PrintTotals(FILE *f, const CTotalBenchRes &res)\r\n{\r\n  fprintf(f, \"       \");\r\n  PrintResults(f, res.Usage, res.RPU, res.Rating);\r\n}\r\n\r\n\r\nHRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);\r\n    PrintResults(f, info, rating, EncodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const char *kSep = \"  | \";\r\n\r\n\r\nHRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);\r\n    fprintf(f, kSep);\r\n    CBenchInfo info2 = info;\r\n    info2.UnpackSize *= info2.NumIterations;\r\n    info2.PackSize *= info2.NumIterations;\r\n    info2.NumIterations = 1;\r\n    PrintResults(f, info2, rating, DecodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)\r\n{\r\n  fprintf(f, \"\\nRAM %s \", sizeString);\r\n  PrintNumber(f, (size >> 20), 5);\r\n  fprintf(f, \" MB,  # %s %3d\", threadsString, (unsigned int)numThreads);\r\n}\r\n\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();  // \r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  if (numThreads > 1)\r\n    numThreads &= ~1;\r\n  if (dictionary == (UInt32)-1)\r\n  {\r\n    int dicSizeLog;\r\n    for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)\r\n      if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)\r\n        break;\r\n    dictionary = (1 << dicSizeLog);\r\n  }\r\n  #else\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 22);\r\n  numThreads = 1;\r\n  #endif\r\n\r\n  PrintRequirements(f, \"usage:\", GetBenchMemoryUsage(numThreads, dictionary), \"Benchmark threads:   \", numThreads);\r\n\r\n  CBenchCallback callback;\r\n  callback.Init();\r\n  callback.f = f;\r\n  \r\n  fprintf(f, \"\\n\\nDict        Compressing          |        Decompressing\\n   \");\r\n  int j;\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"   Speed Usage    R/U Rating\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n   \");\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"    KB/s     %%   MIPS   MIPS\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    const int kStartDicLog = 22;\r\n    int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;\r\n    while (((UInt32)1 << pow) > dictionary)\r\n      pow--;\r\n    for (; ((UInt32)1 << pow) <= dictionary; pow++)\r\n    {\r\n      fprintf(f, \"%2d:\", pow);\r\n      callback.dictionarySize = (UInt32)1 << pow;\r\n      HRESULT res = LzmaBench(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        numThreads, callback.dictionarySize, &callback);\r\n      fprintf(f, \"\\n\");\r\n      RINOK(res);\r\n    }\r\n  }\r\n  callback.Normalize();\r\n  fprintf(f, \"----------------------------------------------------------------\\nAvr:\");\r\n  PrintTotals(f, callback.EncodeRes);\r\n  fprintf(f, \"     \");\r\n  PrintTotals(f, callback.DecodeRes);\r\n  fprintf(f, \"\\nTot:\");\r\n  CTotalBenchRes midRes;\r\n  midRes.SetMid(callback.EncodeRes, callback.DecodeRes);\r\n  PrintTotals(f, midRes);\r\n  fprintf(f, \"\\n\");\r\n  return S_OK;\r\n}\r\n\r\nstruct CTempValues\r\n{\r\n  UInt64 *Values;\r\n  CTempValues(UInt32 num) { Values = new UInt64[num]; }\r\n  ~CTempValues() { delete []Values; }\r\n};\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  #else\r\n  numThreads = 1;\r\n  #endif\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 24);\r\n\r\n  CTempValues speedTotals(numThreads);\r\n  fprintf(f, \"\\n\\nSize\");\r\n  for (UInt32 ti = 0; ti < numThreads; ti++)\r\n  {\r\n    fprintf(f, \" %5d\", ti + 1);\r\n    speedTotals.Values[ti] = 0;\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n\r\n  UInt64 numSteps = 0;\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    for (int pow = 10; pow < 32; pow++)\r\n    {\r\n      UInt32 bufSize = (UInt32)1 << pow;\r\n      if (bufSize > dictionary)\r\n        break;\r\n      fprintf(f, \"%2d: \", pow);\r\n      UInt64 speed;\r\n      for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      {\r\n        #ifdef BREAK_HANDLER\r\n        if (NConsoleClose::TestBreakSignal())\r\n          return E_ABORT;\r\n        #endif\r\n        RINOK(CrcBench(ti + 1, bufSize, speed));\r\n        PrintNumber(f, (speed >> 20), 5);\r\n        speedTotals.Values[ti] += speed;\r\n      }\r\n      fprintf(f, \"\\n\");\r\n      numSteps++;\r\n    }\r\n  }\r\n  if (numSteps != 0)\r\n  {\r\n    fprintf(f, \"\\nAvg:\");\r\n    for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);\r\n    fprintf(f, \"\\n\");\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h",
    "content": "// LzmaBenchCon.h\r\n\r\n#ifndef __LZMABENCHCON_H\r\n#define __LZMABENCHCON_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp",
    "content": "// LzmaRam.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/Compress/Branch/BranchX86.h\"\r\n}\r\n\r\nclass CInStreamRam: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Size;\r\n  size_t Pos;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > (Size - Pos))\r\n    size = (UInt32)(Size - Pos);\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass COutStreamRam: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  size_t Size;\r\npublic:\r\n  Byte *Data;\r\n  size_t Pos;\r\n  bool Overflow;\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n    Overflow = false;\r\n  }\r\n  void SetPos(size_t pos)\r\n  {\r\n    Overflow = false;\r\n    Pos = pos;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  HRESULT WriteByte(Byte b)\r\n  {\r\n    if (Pos >= Size)\r\n    {\r\n      Overflow = true;\r\n      return E_FAIL;\r\n    }\r\n    Data[Pos++] = b;\r\n    return S_OK;\r\n  }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < Size; i++)\r\n    Data[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    Overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\n#define SZ_RAM_E_FAIL (1)\r\n#define SZ_RAM_E_OUTOFMEMORY (2)\r\n#define SZE_OUT_OVERFLOW (3)\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try { \r\n  #endif\r\n\r\n  *outSizeProcessed = 0;\r\n  const size_t kIdSize = 1;\r\n  const size_t kLzmaPropsSize = 5;\r\n  const size_t kMinDestSize = kIdSize + kLzmaPropsSize + 8;\r\n  if (outSize < kMinDestSize)\r\n    return SZE_OUT_OVERFLOW;\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kAlgorithm,\r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kNumFastBytes,\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[1].vt = VT_UI4;\r\n  properties[2].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)2;\r\n  properties[1].ulVal = (UInt32)dictionarySize;\r\n  properties[2].ulVal = (UInt32)64;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n    return 1;\r\n  \r\n  COutStreamRam *outStreamSpec = new COutStreamRam;\r\n  if (outStreamSpec == 0)\r\n    return SZ_RAM_E_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n  CInStreamRam *inStreamSpec = new CInStreamRam;\r\n  if (inStreamSpec == 0)\r\n    return SZ_RAM_E_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\r\n  outStreamSpec->Init(outBuffer, outSize);\r\n  if (outStreamSpec->WriteByte(0) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n\r\n  if (encoderSpec->WriteCoderProperties(outStream) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n  if (outStreamSpec->Pos != kIdSize + kLzmaPropsSize)\r\n    return 1;\r\n  \r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    UInt64 t = (UInt64)(inSize);\r\n    if (outStreamSpec->WriteByte((Byte)((t) >> (8 * i))) != S_OK)\r\n      return SZE_OUT_OVERFLOW;\r\n  }\r\n\r\n  Byte *filteredStream = 0;\r\n\r\n  bool useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (inSize != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(inSize);\r\n      if (filteredStream == 0)\r\n        return SZ_RAM_E_OUTOFMEMORY;\r\n      memmove(filteredStream, inBuffer, inSize);\r\n    }\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(filteredStream, (SizeT)inSize, 0, &x86State, 1);\r\n  }\r\n  \r\n  size_t minSize = 0;\r\n  int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n  bool bestIsFiltered = false;\r\n  int mainResult = 0;\r\n  size_t startPos = outStreamSpec->Pos;\r\n  for (i = 0; i < numPasses; i++)\r\n  {\r\n    if (numPasses > 1 && i == numPasses - 1 && !bestIsFiltered)\r\n      break;\r\n    outStreamSpec->SetPos(startPos);\r\n    bool curModeIsFiltered = false;\r\n    if (useFilter && i == 0)\r\n      curModeIsFiltered = true;\r\n    if (numPasses > 1 && i == numPasses - 1)\r\n      curModeIsFiltered = true;\r\n\r\n    inStreamSpec->Init(curModeIsFiltered ? filteredStream : inBuffer, inSize);\r\n    \r\n    HRESULT lzmaResult = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    \r\n    mainResult = 0;\r\n    if (lzmaResult == E_OUTOFMEMORY)\r\n    {\r\n      mainResult = SZ_RAM_E_OUTOFMEMORY;\r\n      break;\r\n    } \r\n    if (i == 0 || outStreamSpec->Pos <= minSize)\r\n    {\r\n      minSize = outStreamSpec->Pos;\r\n      bestIsFiltered = curModeIsFiltered;\r\n    }\r\n    if (outStreamSpec->Overflow)\r\n      mainResult = SZE_OUT_OVERFLOW;\r\n    else if (lzmaResult != S_OK)\r\n    {\r\n      mainResult = SZ_RAM_E_FAIL;\r\n      break;\r\n    } \r\n  }\r\n  *outSizeProcessed = outStreamSpec->Pos;\r\n  if (bestIsFiltered)\r\n    outBuffer[0] = 1;\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n  \r\n  #ifndef _NO_EXCEPTIONS\r\n  } catch(...) { return SZ_RAM_E_OUTOFMEMORY; }\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h",
    "content": "// LzmaRam.h\r\n\r\n#ifndef __LzmaRam_h\r\n#define __LzmaRam_h\r\n\r\n#include <stdlib.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\n/*\r\nLzmaRamEncode: BCJ + LZMA RAM->RAM compressing.\r\nIt uses .lzma format, but it writes one additional byte to .lzma file:\r\n  0: - no filter\r\n  1: - x86(BCJ) filter.\r\n\r\nTo provide best compression ratio dictionarySize mustbe >= inSize\r\n\r\nLzmaRamEncode allocates Data with MyAlloc/BigAlloc functions.\r\nRAM Requirements:\r\n  RamSize = dictionarySize * 9.5 + 6MB + FilterBlockSize \r\n    FilterBlockSize = 0, if useFilter == false\r\n    FilterBlockSize = inSize, if useFilter == true\r\n\r\n  Return code:\r\n    0 - OK\r\n    1 - Unspecified Error\r\n    2 - Memory allocating error\r\n    3 - Output buffer OVERFLOW\r\n\r\nIf you use SZ_FILTER_AUTO mode, then encoder will use 2 or 3 passes:\r\n  2 passes when FILTER_NO provides better compression.\r\n  3 passes when FILTER_YES provides better compression.\r\n*/\r\n\r\nenum ESzFilterMode \r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c",
    "content": "/* LzmaRamDecode.c */\r\n\r\n#include \"LzmaRamDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#include \"BranchX86.h\"\r\n#else\r\n#include \"../../../../C/Compress/Lzma/LzmaDecode.h\"\r\n#include \"../../../../C/Compress/Branch/BranchX86.h\"\r\n#endif\r\n\r\n#define LZMA_PROPS_SIZE 14\r\n#define LZMA_SIZE_OFFSET 6\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize, \r\n    size_t *outSize)\r\n{\r\n  unsigned int i;\r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  *outSize = 0;\r\n  for(i = 0; i < sizeof(size_t); i++)\r\n    *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);\r\n  for(; i < 8; i++)\r\n    if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)\r\n      return 1;\r\n  return 0;\r\n}\r\n\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *))\r\n{\r\n  CLzmaDecoderState state;  /* it's about 24 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  SizeT inProcessed;\r\n  int useFilter;\r\n  \r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  useFilter = inBuffer[0];\r\n\r\n  *outSizeProcessed = 0;\r\n  if (useFilter > 1)\r\n    return 1;\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return 1;\r\n  state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  result = LzmaDecode(&state,\r\n    inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed,\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  freeFunc(state.Probs);\r\n  if (result != LZMA_RESULT_OK)\r\n    return 1;\r\n  *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(outBuffer, (SizeT)outSizeProcessedLoc, 0, &x86State, 0);\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h",
    "content": "/* LzmaRamDecode.h */\r\n\r\n#ifndef __LzmaRamDecode_h\r\n#define __LzmaRamDecode_h\r\n\r\n#include <stdlib.h>\r\n\r\n/*\r\nLzmaRamGetUncompressedSize:\r\n  In: \r\n    inBuffer - input data\r\n    inSize   - input data size\r\n  Out: \r\n    outSize  - uncompressed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers\r\n*/\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    size_t *outSize);\r\n\r\n\r\n/*\r\nLzmaRamDecompress:\r\n  In: \r\n    inBuffer  - input data\r\n    inSize    - input data size\r\n    outBuffer - output data\r\n    outSize   - output size\r\n    allocFunc - alloc function (can be malloc)\r\n    freeFunc  - free function (can be free)\r\n  Out: \r\n    outSizeProcessed - processed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers / data stream\r\n    2 - Memory allocating error\r\n\r\nMemory requirements depend from properties of LZMA stream.\r\nWith default lzma settings it's about 16 KB.\r\n*/\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/comp.cc",
    "content": "/*\n * Copyright (C) 2006-2007 Junjiro Okajima\n * Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: comp.cc,v 1.3 2007-11-13 13:27:23 jro Exp $ */\n\n// extract some parts from lzma443/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <assert.h>\n#include <errno.h>\n\n#include \"StdAfx.h\"\n#include \"../../../Common/MyInitGuid.h\"\n//#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/StringConvert.h\"\n//#include \"../../../Common/StringToInt.h\"\n//#include \"../../Common/StreamUtils.h\"\n#include \"../LZMA/LZMAEncoder.h\"\n\n#include <pthread.h>\n#include <zlib.h>\n#include \"sqlzma.h\"\n\n//////////////////////////////////////////////////////////////////////\n\nclass CMemoryStream {\nprotected:\n\tBytef *m_data;\n\tUInt64 m_limit;\n\tUInt64 m_pos;\n\npublic:\n\tCMemoryStream(Bytef *data, UInt64 size)\n\t\t: m_data(data), m_limit(size), m_pos(0) {}\n\n\tvirtual ~CMemoryStream() {}\n};\n\nclass CInMemoryStream : public CMemoryStream, public IInStream,\n\t\t\tpublic CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialInStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IInStream);\n\n\tCInMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~CInMemoryStream() {}\n\n\tSTDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\n\t{\n\t\tUInt64 room = m_limit - m_pos;\n\t\tif (size > room)\n\t\t\tsize = room;\n\t\tif (size) {\n\t\t\tmemcpy(data, m_data + m_pos, size);\n\t\t\tm_pos += size;\n\t\t}\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\nclass COutMemoryStream : public CMemoryStream, public IOutStream,\n\t\t\t public CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialOutStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IOutStream);\n\n\tCOutMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~COutMemoryStream() {}\n\n\tUInt32 GetSize() {return m_pos;}\n\n\tSTDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) {\n\t\tif (m_pos + size > m_limit)\n\t\t\treturn -ENOSPC;\n\t\tmemcpy(m_data + m_pos, data, size);\n\t\tm_pos += size;\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n\tSTDMETHOD(SetSize)(Int64 newSize) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\n//////////////////////////////////////////////////////////////////////\n\nstatic int\nLzmaCompress(Bytef *next_in, uInt avail_in, Bytef *next_out, uInt avail_out,\n\t     struct sqlzma_opts *opts, uLong *total_out)\n{\n\tint err;\n\tHRESULT res;\n\tconst Byte a[] = {\n\t\tavail_in, avail_in >> 8, avail_in >> 16, avail_in >> 24,\n\t\t0, 0, 0, 0\n\t};\n\n\tNCompress::NLZMA::CEncoder encoderSpec;\n\tCMyComPtr<ICompressCoder> encoder = &encoderSpec;\n\tencoder->AddRef();\n\tCInMemoryStream inStreamSpec(next_in, avail_in);\n\tCMyComPtr<ISequentialInStream> inStream = &inStreamSpec;\n\tinStream->AddRef();\n\tCOutMemoryStream outStreamSpec(next_out, avail_out);\n\tCMyComPtr<ISequentialOutStream> outStream = &outStreamSpec;\n\toutStream->AddRef();\n\n\t// these values are dpending upon is_lzma() macro in sqlzma.h\n\tconst UInt32 dictionary = opts->dicsize;\n\t//fprintf(stderr, \"dic %u\\n\", dictionary);\n\tconst UString mf = L\"BT4\";\n\tconst UInt32 posStateBits = 2;\n\tconst UInt32 litContextBits = 3; // for normal files\n\t// UInt32 litContextBits = 0; // for 32-bit data\n\tconst UInt32 litPosBits = 0;\n\t// UInt32 litPosBits = 2; // for 32-bit data\n\t//const UInt32 algorithm = 2;\n\tconst UInt32 algorithm = 1;\n\tconst UInt32 numFastBytes = 128;\n\tconst UInt32 matchFinderCycles = 16 + numFastBytes / 2;\n\t//const bool matchFinderCyclesDefined = false;\n\tconst PROPID propIDs[] = {\n\t\tNCoderPropID::kDictionarySize,\n\t\tNCoderPropID::kPosStateBits,\n\t\tNCoderPropID::kLitContextBits,\n\t\tNCoderPropID::kLitPosBits,\n\t\tNCoderPropID::kAlgorithm,\n\t\tNCoderPropID::kNumFastBytes,\n\t\tNCoderPropID::kMatchFinder,\n\t\tNCoderPropID::kEndMarker,\n\t\tNCoderPropID::kNumThreads,\n\t\tNCoderPropID::kMatchFinderCycles\n\t};\n\tconst int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\n\tPROPVARIANT properties[kNumPropsMax];\n\tfor (int p = 0; p < 6; p++)\n\t\tproperties[p].vt = VT_UI4;\n\tproperties[0].ulVal = UInt32(dictionary);\n\tproperties[1].ulVal = UInt32(posStateBits);\n\tproperties[2].ulVal = UInt32(litContextBits);\n\tproperties[3].ulVal = UInt32(litPosBits);\n\tproperties[4].ulVal = UInt32(algorithm);\n\tproperties[5].ulVal = UInt32(numFastBytes);\n\n\tproperties[6].vt = VT_BSTR;\n\tproperties[6].bstrVal = (BSTR)(const wchar_t *)mf;\n\tproperties[7].vt = VT_BOOL;\n\tproperties[7].boolVal = VARIANT_FALSE;\t// EOS\n\tproperties[8].vt = VT_UI4;\n\tproperties[8].ulVal = 1; // numThreads\n\tproperties[9].vt = VT_UI4;\n\tproperties[9].ulVal = UInt32(matchFinderCycles);\n\n\terr = -EINVAL;\n\tres = encoderSpec.SetCoderProperties(propIDs, properties,\n\t\t\t\t\t     kNumPropsMax - 1);\n\tif (res)\n\t\tgoto out;\n\tres = encoderSpec.WriteCoderProperties(outStream);\n\tif (res)\n\t\tgoto out;\n\n\tUInt32 r;\n\tres = outStream->Write(a, sizeof(a), &r);\n\tif (res || r != sizeof(a))\n\t\tgoto out;\n\n\terr = encoder->Code(inStream, outStream, 0, /*broken*/0, 0);\n\tif (err)\n\t\tgoto out;\n\t*total_out = outStreamSpec.GetSize();\n\n out:\n\treturn err;\n}\n\n//////////////////////////////////////////////////////////////////////\n\n#define Failure(p) do { \\\n\tfprintf(stderr, \"%s:%d: please report to jro \" \\\n\t\t\"{%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x}\\n\", \\\n\t\t__func__, __LINE__, \\\n\t\tp[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); \\\n\tabort(); \\\n} while(0)\n\nextern \"C\" int\nsqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in, uInt\n\t  avail_in, Bytef *next_out, uInt avail_out)\n{\n\tint err;\n\tBytef *p = next_out;\n\tuInt l = avail_out;\n\n\tstream->next_in = next_in;\n\tstream->avail_in = avail_in;\n\tstream->next_out = p;\n\tstream->avail_out = l;\n\terr = deflate(stream, Z_FINISH);\n\tif (err != Z_STREAM_END && err != Z_OK)\n\t\tgoto out_err;\n\tif (avail_in < stream->total_out)\n\t\treturn err;\n\tif (is_lzma(*p))\n\t\tFailure(p);\n\n\tif (opts->try_lzma) {\n\t\tunsigned char a[stream->total_out];\n\t\tuLong processed;\n\n\t\tmemcpy(a, p, stream->total_out);\n\n\t\t// malloc family in glibc and stdc++ seems to be thread-safe\n\t\terr = LzmaCompress(next_in, avail_in, p, l, opts, &processed);\n\t\tif (!err && processed <= stream->total_out) {\n\t\t\tif (!is_lzma(*next_out))\n\t\t\t\tFailure(next_out);\n\t\t\tstream->total_out = processed;\n\t\t\terr = Z_STREAM_END;\n\t\t} else {\n\t\t\t//puts(\"by zlib\");\n\t\t\tmemcpy(p, a, stream->total_out);\n\t\t\terr = Z_STREAM_END;\n\t\t}\n\t}\n\treturn err;\n\n out_err:\n\tfprintf(stderr, \"%s: ZLIB err %s\\n\", __func__, zError(err));\n\treturn err;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -DBENCH_MT \\\r\n\r\nLIBS = $(LIBS) oleaut32.lib user32.lib\r\n\r\n!IFDEF CPU\r\nLIBS = $(LIBS) bufferoverflowU.lib \r\nCFLAGS = $(CFLAGS) -GS- -Zc:forScope -W4 -Wp64 -DUNICODE -D_UNICODE\r\n!ENDIF\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n  $O\\LzmaRam.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj\r\n\r\nWIN_OBJS = \\\r\n  $O\\System.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZ_OBJS = \\\r\n  $O\\MatchFinder.obj \\\r\n  $O\\MatchFinderMt.obj \\\r\n\r\nOBJS = \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZ_OBJS) \\\r\n  $O\\LzmaRamDecode.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\LzmaRamDecode.obj: LzmaRamDecode.c\r\n\t$(COMPL_O1)\r\n$O\\LzmaDecode.obj: ../../../../C/Compress/Lzma/LzmaDecode.c\r\n\t$(COMPL_O2)\r\n$O\\BranchX86.obj: ../../../../C/Compress/Branch/BranchX86.c\r\n\t$(COMPL_O2)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c\r\n\r\nifdef SystemDrive\r\nIS_MINGW = 1\r\nendif\r\n\r\nifdef IS_MINGW\r\nFILE_IO =FileIO\r\nFILE_IO_2 =Windows/$(FILE_IO)\r\nLIB2 = -luuid \r\nelse\r\nFILE_IO =C_FileIO\r\nFILE_IO_2 =Common/$(FILE_IO)\r\nendif\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaBenchCon.o \\\r\n  LzmaRam.o \\\r\n  LZMADecoder.o \\\r\n  LZMAEncoder.o \\\r\n  LZOutWindow.o \\\r\n  RangeCoderBit.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  $(FILE_IO).o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  IntToString.o \\\r\n  MyString.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  MyVector.o \\\r\n  7zCrc.o \\\r\n  Alloc.o \\\r\n  BranchX86.o \\\r\n  MatchFinder.o \\\r\n  LzmaDecode.o \\\r\n  LzmaRamDecode.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaBenchCon.o: LzmaBenchCon.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBenchCon.cpp\r\n\r\nLzmaRam.o: LzmaRam.cpp\r\n\t$(CXX) $(CFLAGS) LzmaRam.cpp\r\n\r\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\r\n\r\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\r\n\r\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\r\n\r\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\r\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\n$(FILE_IO).o: ../../../$(FILE_IO_2).cpp\r\n\t$(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp\r\n\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nIntToString.o: ../../../Common/IntToString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp\r\n\r\nMyString.o: ../../../Common/MyString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyString.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nMyVector.o: ../../../Common/MyVector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyVector.cpp\r\n\r\n7zCrc.o: ../../../../C/7zCrc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c\r\n\r\nAlloc.o: ../../../../C/Alloc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c\r\n\r\nBranchX86.o: ../../../../C/Compress/Branch/BranchX86.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c\r\n\r\nMatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c\r\n\r\nLzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c\r\n\r\nLzmaRamDecode.o: LzmaRamDecode.c\r\n\t$(CXX_C) $(CFLAGS) LzmaRamDecode.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/LZMA_Alone/sqlzma.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\ninclude makefile.gcc\n\nifdef UseDebugFlags\nDebugFlags = -Wall -O0 -g -UNDEBUG\nendif\n# -pthread\nCXXFLAGS = ${CFLAGS} -D_REENTRANT -include pthread.h -DNDEBUG ${DebugFlags}\nTgt = liblzma_r.a\n\nall: ${Tgt}\n\nRObjs = LZMAEncoder_r.o Alloc_r.o StreamUtils_r.o MatchFinder_r.o \\\n\tRangeCoderBit_r.o OutBuffer_r.o 7zCrc_r.o\n\n%_r.cc: ../LZMA/%.cpp\n\tln $< $@\n%_r.c: ../../../../C/%.c\n\tln $< $@\n%_r.c: ../../../../C/Compress/Lz/%.c\n\tln $< $@\n%_r.cc: ../../Common/%.cpp\n\tln $< $@\n%_r.cc: ../RangeCoder/%.cpp\n\tln $< $@\nLZMAEncoder_r.o: CXXFLAGS += -I../LZMA\nAlloc_r.o: CFLAGS += -I../../../../C\nStreamUtils_r.o: CXXFLAGS += -I../../Common\nMatchFinder_r.o: CFLAGS += -I../../../../C/Compress/Lz\nRangeCoderBit_r.o: CXXFLAGS += -I../RangeCoder\nOutBuffer_r.o: CXXFLAGS += -I../../Common\n7zCrc_r.o: CFLAGS += -I../../../../C\n\ncomp.o: CXXFLAGS += -I${Sqlzma}\ncomp.o: comp.cc ${Sqlzma}/sqlzma.h\n\nliblzma_r.a: ${RObjs} comp.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) comp.o *_r.o ${Tgt} *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/RangeCoder/RangeCoder.h",
    "content": "// Compress/RangeCoder/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_H\r\n#define __COMPRESS_RANGECODER_H\r\n\r\n#include \"../../Common/InBuffer.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1; \r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) \r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);                      \r\n    } \r\n    _cacheSize++;                               \r\n    Low = (UInt32)Low << 8;                           \r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numTotalBits)\r\n  {\r\n    for (int i = numTotalBits - 1; i >= 0; i--)\r\n    {\r\n      Range >>= 1;\r\n      if (((value >> i) & 1) == 1)\r\n        Low += Range;\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;        \r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8; \r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp",
    "content": "// Compress/RangeCoder/RangeCoderBit.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nUInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\nstatic CPriceTables g_PriceTables;\r\n\r\nCPriceTables::CPriceTables() { Init(); }\r\n\r\nvoid CPriceTables::Init()\r\n{\r\n  const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n  for(int i = kNumBits - 1; i >= 0; i--)\r\n  {\r\n    UInt32 start = 1 << (kNumBits - i - 1);\r\n    UInt32 end = 1 << (kNumBits - i);\r\n    for (UInt32 j = start; j < end; j++)\r\n      ProbPrices[j] = (i << kNumBitPriceShiftBits) + \r\n          (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n  }\r\n\r\n  /*\r\n  // simplest: bad solution\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = kBitPrice;\r\n  */\r\n  \r\n  /*\r\n  const double kDummyMultMid = (1.0 / kBitPrice) / 2;\r\n  const double kDummyMultMid = 0;\r\n  // float solution\r\n  double ln2 = log(double(2));\r\n  double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);\r\n  */\r\n  \r\n  /*\r\n  // experimental, slow, solution:\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n  {\r\n    const int kCyclesBits = 5;\r\n    const UInt32 kCycles = (1 << kCyclesBits);\r\n\r\n    UInt32 range = UInt32(-1);\r\n    UInt32 bitCount = 0;\r\n    for (UInt32 j = 0; j < kCycles; j++)\r\n    {\r\n      range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n      range *= i;\r\n      while(range < (1 << 31))\r\n      {\r\n        range <<= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    bitCount <<= kNumBitPriceShiftBits;\r\n    range -= (1 << 31);\r\n    for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)\r\n    {\r\n      range <<= 1;\r\n      if (range > (1 << 31))\r\n      {\r\n        bitCount += (1 << k);\r\n        range -= (1 << 31);\r\n      }\r\n    }\r\n    ProbPrices[i] = (bitCount \r\n      // + (1 << (kCyclesBits - 1))\r\n      ) >> kCyclesBits;\r\n  }\r\n  */\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h",
    "content": "// Compress/RangeCoder/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_H\r\n#define __COMPRESS_RANGECODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 2;\r\n\r\nconst int kNumBitPriceShiftBits = 6;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nclass CPriceTables\r\n{\r\npublic:\r\n  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  static void Init();\r\n  CPriceTables();\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return CPriceTables::ProbPrices[\r\n      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h",
    "content": "// Compress/RangeCoder/RangeCoderBitTree.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_TREE_H\r\n#define __COMPRESS_RANGECODER_BIT_TREE_H\r\n\r\n#include \"RangeCoderBit.h\"\r\n#include \"RangeCoderOpt.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeEncoder\r\n{\r\n  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  void Encode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int bitIndex = NumBitLevels; bitIndex != 0 ;)\r\n    {\r\n      bitIndex--;\r\n      UInt32 bit = (symbol >> bitIndex) & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n  };\r\n  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int i = 0; i < NumBitLevels; i++)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n      symbol >>= 1;\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    symbol |= (1 << NumBitLevels);\r\n    UInt32 price = 0;\r\n    while (symbol != 1)\r\n    {\r\n      price += Models[symbol >> 1].GetPrice(symbol & 1);\r\n      symbol >>= 1;\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 ReverseGetPrice(UInt32 symbol) const\r\n  {\r\n    UInt32 price = 0;\r\n    UInt32 modelIndex = 1;\r\n    for (int i = NumBitLevels; i != 0; i--)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      symbol >>= 1;\r\n      price += Models[modelIndex].GetPrice(bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n    return price;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeDecoder\r\n{\r\n  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  UInt32 Decode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n    {\r\n      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);\r\n      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)\r\n    }\r\n    RC_FLUSH_VAR\r\n    return modelIndex - (1 << NumBitLevels);\r\n  };\r\n  UInt32 ReverseDecode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    UInt32 symbol = 0;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n    {\r\n      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n      // modelIndex <<= 1;\r\n      // modelIndex += bit;\r\n      // symbol |= (bit << bitIndex);\r\n      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n    }\r\n    RC_FLUSH_VAR\r\n    return symbol;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nvoid ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models, \r\n    CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  for (int i = 0; i < NumBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    Models[modelIndex].Encode(rangeEncoder, bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models, \r\n    UInt32 NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 modelIndex = 1;\r\n  for (int i = NumBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += Models[modelIndex].GetPrice(bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models, \r\n    CDecoder *rangeDecoder, int NumBitLevels)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  UInt32 symbol = 0;\r\n  RC_INIT_VAR\r\n  for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n  {\r\n    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n    // modelIndex <<= 1;\r\n    // modelIndex += bit;\r\n    // symbol |= (bit << bitIndex);\r\n    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n  }\r\n  RC_FLUSH_VAR\r\n  return symbol;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/RangeCoder/RangeCoderOpt.h",
    "content": "// Compress/RangeCoder/RangeCoderOpt.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_OPT_H\r\n#define __COMPRESS_RANGECODER_OPT_H\r\n\r\n#define RC_INIT_VAR \\\r\n  UInt32 range = rangeDecoder->Range; \\\r\n  UInt32 code = rangeDecoder->Code;        \r\n\r\n#define RC_FLUSH_VAR \\\r\n  rangeDecoder->Range = range; \\\r\n  rangeDecoder->Code = code;\r\n\r\n#define RC_NORMALIZE \\\r\n  if (range < NCompress::NRangeCoder::kTopValue) \\\r\n    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }\r\n\r\n#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \\\r\n  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \\\r\n  if (code < bound) \\\r\n  { A0; range = bound; \\\r\n    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \\\r\n    mi <<= 1; } \\\r\n  else \\\r\n  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \\\r\n    mi = (mi + mi) + 1; }} \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/Compress/RangeCoder/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, \r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kMatchFinderCycles,\r\n    kNumPasses = 0x460, \r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kNumThreads,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetCoderMt, 0x25)\r\n{\r\n  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block \r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICompressCodecsInfo, 0x60)\r\n{\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n};\r\nCODER_INTERFACE(ISetCompressCodecsInfo, 0x61)\r\n{\r\n  STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICryptoResetSalt, 0x88)\r\n{\r\n  STDMETHOD(ResetSalt)() PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICryptoResetInitVector, 0x8C)\r\n{\r\n  STDMETHOD(ResetInitVector)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription,\r\n    kDecoderIsAssigned,\r\n    kEncoderIsAssigned\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/IDecl.h",
    "content": "// IDecl.h\r\n\r\n#ifndef __IDECL_H\r\n#define __IDECL_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n\r\n#define DECL_INTERFACE_SUB(i, base, groupId, subId) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \\\r\nstruct i: public base\r\n\r\n#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/IPassword.h",
    "content": "// IPassword.h\r\n\r\n#ifndef __IPASSWORD_H\r\n#define __IPASSWORD_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;\r\n};\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;\r\n};\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/IProgress.h",
    "content": "// Interface/IProgress.h\r\n\r\n#ifndef __IPROGRESS_H\r\n#define __IPROGRESS_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\nDECL_INTERFACE(IProgress, 0, 5)\r\n{\r\n  STDMETHOD(SetTotal)(UInt64 total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000000050002}\r\nDEFINE_GUID(IID_IProgress2, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000050002\")\r\nIProgress2: public IUnknown\r\n{\r\npublic:\r\n  STDMETHOD(SetTotal)(const UInt64 *total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream, \r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/MyVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 57\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.57\"\r\n#define MY_7ZIP_VERSION \"7-Zip 4.57\"\r\n#define MY_DATE \"2007-12-06\"\r\n#define MY_COPYRIGHT \"Copyright (c) 1999-2007 Igor Pavlov\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \"  \" MY_COPYRIGHT \"  \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/MyVersionInfo.rc",
    "content": "#include <WinVer.h>\r\n#include \"MyVersion.h\"\r\n\r\n#define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0\r\n\r\n#ifdef DEBUG\r\n#define DBG_FL VS_FF_DEBUG\r\n#else\r\n#define DBG_FL 0\r\n#endif\r\n\r\n#define MY_VERSION_INFO(fileType, descr, intName, origName)  \\\r\nLANGUAGE 9, 1 \\\r\n1 VERSIONINFO \\\r\n  FILEVERSION MY_VER \\\r\n  PRODUCTVERSION MY_VER \\\r\n  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK \\\r\n  FILEFLAGS DBG_FL \\\r\n  FILEOS VOS_NT_WINDOWS32 \\\r\n  FILETYPE fileType \\\r\n  FILESUBTYPE 0x0L \\\r\nBEGIN \\\r\n    BLOCK \"StringFileInfo\" \\\r\n    BEGIN  \\\r\n        BLOCK \"040904b0\" \\\r\n        BEGIN \\\r\n            VALUE \"CompanyName\", \"Igor Pavlov\" \\\r\n            VALUE \"FileDescription\", descr \\\r\n            VALUE \"FileVersion\", MY_VERSION  \\\r\n            VALUE \"InternalName\", intName \\\r\n            VALUE \"LegalCopyright\", MY_COPYRIGHT \\\r\n            VALUE \"OriginalFilename\", origName \\\r\n            VALUE \"ProductName\", \"7-Zip\" \\\r\n            VALUE \"ProductVersion\", MY_VERSION \\\r\n        END \\\r\n    END \\\r\n    BLOCK \"VarFileInfo\" \\\r\n    BEGIN \\\r\n        VALUE \"Translation\", 0x409, 1200 \\\r\n    END \\\r\nEND\r\n\r\n#define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(VFT_APP, descr, intName, intName \".exe\")\r\n\r\n#define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(VFT_DLL, descr, intName, intName \".dll\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/PropID.h",
    "content": "// Interface/PropID.h\r\n\r\n#ifndef __INTERFACE_PROPID_H\r\n#define __INTERFACE_PROPID_H\r\n\r\nenum\r\n{\r\n  kpidNoProperty = 0,\r\n  \r\n  kpidHandlerItemIndex = 2,\r\n  kpidPath,\r\n  kpidName,\r\n  kpidExtension,\r\n  kpidIsFolder,\r\n  kpidSize,\r\n  kpidPackedSize,\r\n  kpidAttributes,\r\n  kpidCreationTime,\r\n  kpidLastAccessTime,\r\n  kpidLastWriteTime,\r\n  kpidSolid, \r\n  kpidCommented, \r\n  kpidEncrypted, \r\n  kpidSplitBefore, \r\n  kpidSplitAfter, \r\n  kpidDictionarySize, \r\n  kpidCRC, \r\n  kpidType,\r\n  kpidIsAnti,\r\n  kpidMethod,\r\n  kpidHostOS,\r\n  kpidFileSystem,\r\n  kpidUser,\r\n  kpidGroup,\r\n  kpidBlock,\r\n  kpidComment,\r\n  kpidPosition,\r\n  kpidPrefix,\r\n  kpidNumSubFolders,\r\n  kpidNumSubFiles,\r\n  kpidUnpackVer,\r\n  kpidVolume,\r\n  kpidIsVolume,\r\n  kpidOffset,\r\n  kpidLinks,\r\n  kpidNumBlocks,\r\n  kpidNumVolumes,\r\n\r\n  kpidTotalSize = 0x1100,\r\n  kpidFreeSpace, \r\n  kpidClusterSize,\r\n  kpidVolumeName,\r\n\r\n  kpidLocalName = 0x1200,\r\n  kpidProvider,\r\n\r\n  kpidUserDefined = 0x10000\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Client7z/Client7z.cpp",
    "content": "// Client7z.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/DLL.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../MyVersion.h\"\r\n\r\n\r\n// {23170F69-40C1-278A-1000-000110070000}\r\nDEFINE_GUID(CLSID_CFormat7z, \r\n  0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);\r\n\r\nusing namespace NWindows;\r\n\r\n#define kDllName \"7z.dll\"\r\n\r\nstatic const char *kCopyrightString = MY_7ZIP_VERSION\r\n\" (\"  kDllName \" client) \"  \r\nMY_COPYRIGHT \" \" MY_DATE;\r\n\r\nstatic const char *kHelpString = \r\n\"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\\n\"\r\n\"Examples:\\n\"\r\n\"  Client7z.exe a archive.7z f1.txt f2.txt  : compress two files to archive.7z\\n\"\r\n\"  Client7z.exe l archive.7z   : List contents of archive.7z\\n\"\r\n\"  Client7z.exe x archive.7z   : eXtract files from archive.7z\\n\";\r\n\r\n\r\ntypedef UINT32 (WINAPI * CreateObjectFunc)(\r\n    const GUID *clsID, \r\n    const GUID *interfaceID, \r\n    void **outObject);\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nvoid PrintString(const UString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)GetOemString(s));\r\n}\r\n\r\nvoid PrintString(const AString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)s);\r\n}\r\n\r\nvoid PrintNewLine()\r\n{\r\n  PrintString(\"\\n\");\r\n}\r\n\r\nvoid PrintStringLn(const AString &s)\r\n{\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nvoid PrintError(const AString &s)\r\n{\r\n  PrintNewLine();\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nstatic HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsFolder, result);\r\n}\r\n\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Open callback class\r\n\r\n\r\nclass CArchiveOpenCallback: \r\n  public IArchiveOpenCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveOpenCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream); \r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Extracting callback class\r\n\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCRCFailed = \"CRC Failed\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nclass CArchiveExtractCallback: \r\n  public IArchiveExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IArchiveExtractCallback\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  UString _directoryPath;  // Output directory\r\n  UString _filePath;       // name inside arcvhive\r\n  UString _diskFilePath;   // full path to file on disk\r\n  bool _extractMode;\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME UTCLastWriteTime;\r\n    UInt32 Attributes;\r\n    bool IsDirectory;\r\n    bool AttributesAreDefined;\r\n    bool UTCLastWriteTimeIsDefined;\r\n  } _processedFileInfo;\r\n\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n\r\npublic:\r\n  void Init(IInArchive *archiveHandler, const UString &directoryPath);\r\n\r\n  UInt64 NumErrors;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveExtractCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nvoid CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)\r\n{\r\n  NumErrors = 0;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, \r\n    ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  {\r\n    // Get Name\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPath, &propVariant));\r\n    \r\n    UString fullPath;\r\n    if(propVariant.vt == VT_EMPTY)\r\n      fullPath = kEmptyFileAlias;\r\n    else \r\n    {\r\n      if(propVariant.vt != VT_BSTR)\r\n        return E_FAIL;\r\n      fullPath = propVariant.bstrVal;\r\n    }\r\n    _filePath = fullPath;\r\n  }\r\n\r\n  if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)\r\n    return S_OK;\r\n\r\n  {\r\n    // Get Attributes\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &propVariant));\r\n    if (propVariant.vt == VT_EMPTY)\r\n    {\r\n      _processedFileInfo.Attributes = 0;\r\n      _processedFileInfo.AttributesAreDefined = false;\r\n    }\r\n    else\r\n    {\r\n      if (propVariant.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      _processedFileInfo.Attributes = propVariant.ulVal;\r\n      _processedFileInfo.AttributesAreDefined = true;\r\n    }\r\n  }\r\n\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDirectory));\r\n\r\n  {\r\n    // Get Modified Time\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidLastWriteTime, &propVariant));\r\n    _processedFileInfo.UTCLastWriteTimeIsDefined = false;\r\n    switch(propVariant.vt)\r\n    {\r\n      case VT_EMPTY:\r\n        // _processedFileInfo.UTCLastWriteTime = _utcLastWriteTimeDefault;\r\n        break;\r\n      case VT_FILETIME:\r\n        _processedFileInfo.UTCLastWriteTime = propVariant.filetime;\r\n        _processedFileInfo.UTCLastWriteTimeIsDefined = true;\r\n        break;\r\n      default:\r\n        return E_FAIL;\r\n    }\r\n\r\n  }\r\n  {\r\n    // Get Size\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &propVariant));\r\n    bool newFileSizeDefined = (propVariant.vt != VT_EMPTY);\r\n    UInt64 newFileSize;\r\n    if (newFileSizeDefined)\r\n      newFileSize = ConvertPropVariantToUInt64(propVariant);\r\n  }\r\n\r\n  \r\n  {\r\n    // Create folders for file\r\n    int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (slashPos >= 0)\r\n      NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));\r\n  }\r\n\r\n  UString fullProcessedPath = _directoryPath + _filePath;\r\n  _diskFilePath = fullProcessedPath;\r\n\r\n  if (_processedFileInfo.IsDirectory)\r\n  {\r\n    NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n      {\r\n        PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath);\r\n        return E_ABORT;\r\n      }\r\n    }\r\n    \r\n    _outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n    if (!_outFileStreamSpec->Open(fullProcessedPath, CREATE_ALWAYS))\r\n    {\r\n      PrintString((UString)L\"can not open output file \" + fullProcessedPath);\r\n      return E_ABORT;\r\n    }\r\n    _outFileStream = outStreamLoc;\r\n    *outStream = outStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      PrintString(kExtractingString);\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kTest:\r\n      PrintString(kTestingString);\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kSkip:\r\n      PrintString(kSkippingString);\r\n      break;\r\n  };\r\n  PrintString(_filePath);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumErrors++;\r\n      PrintString(\"     \");\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          PrintString(kUnsupportedMethod);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          PrintString(kCRCFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          PrintString(kDataError);\r\n          break;\r\n        default:\r\n          PrintString(kUnknownError);\r\n      }\r\n    }\r\n  }\r\n\r\n  if (_outFileStream != NULL)\r\n  {\r\n    if (_processedFileInfo.UTCLastWriteTimeIsDefined)\r\n      _outFileStreamSpec->SetLastWriteTime(&_processedFileInfo.UTCLastWriteTime);\r\n    RINOK(_outFileStreamSpec->Close());\r\n  }\r\n  _outFileStream.Release();\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream); \r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Creating callback class\r\n\r\nstruct CDirItem\r\n{ \r\n  UInt32 Attributes;\r\n  FILETIME CreationTime;\r\n  FILETIME LastAccessTime;\r\n  FILETIME LastWriteTime;\r\n  UInt64 Size;\r\n  UString Name;\r\n  UString FullPath;\r\n  bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CArchiveUpdateCallback: \r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IUpdateCallback2\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);  \r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  UString DirPrefix;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n  bool m_NeedBeClosed;\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {};\r\n\r\n  ~CArchiveUpdateCallback() { Finilize(); }\r\n  HRESULT Finilize();\r\n\r\n  void Init(const CObjectVector<CDirItem> *dirItems)\r\n  {\r\n    DirItems = dirItems;\r\n    m_NeedBeClosed = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  if(newData != NULL)\r\n    *newData = BoolToInt(true);\r\n  if(newProperties != NULL)\r\n    *newProperties = BoolToInt(true);\r\n  if(indexInArchive != NULL)\r\n    *indexInArchive = UInt32(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    propVariant = false;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[index];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:\r\n        propVariant = dirItem.Name;\r\n        break;\r\n      case kpidIsFolder:\r\n        propVariant = dirItem.IsDirectory();\r\n        break;\r\n      case kpidSize:\r\n        propVariant = dirItem.Size;\r\n        break;\r\n      case kpidAttributes:\r\n        propVariant = dirItem.Attributes;\r\n        break;\r\n      case kpidLastAccessTime:\r\n        propVariant = dirItem.LastAccessTime;\r\n        break;\r\n      case kpidCreationTime:\r\n        propVariant = dirItem.CreationTime;\r\n        break;\r\n      case kpidLastWriteTime:\r\n        propVariant = dirItem.LastWriteTime;\r\n        break;\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveUpdateCallback::Finilize()\r\n{\r\n  if (m_NeedBeClosed)\r\n  {\r\n    PrintNewLine();\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void GetStream2(const wchar_t *name)\r\n{\r\n  PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  PrintString(name);\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  RINOK(Finilize());\r\n\r\n  const CDirItem &dirItem = (*DirItems)[index];\r\n  GetStream2(dirItem.Name);\r\n \r\n  if(dirItem.IsDirectory())\r\n    return S_OK;\r\n\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if(!inStreamSpec->Open(path))\r\n    {\r\n      DWORD sysError = ::GetLastError();\r\n      FailedCodes.Add(sysError);\r\n      FailedFiles.Add(path);\r\n      // if (systemError == ERROR_SHARING_VIOLATION)\r\n      {\r\n        PrintNewLine();\r\n        PrintError(\"WARNING: can't open file\");\r\n        // PrintString(NError::MyFormatMessageW(systemError));\r\n        return S_FALSE;\r\n      }\r\n      // return sysError;\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */)\r\n{\r\n  m_NeedBeClosed = true;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if(!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined) \r\n  {\r\n    if (AskPassword)\r\n    {\r\n      // You can ask real password here from user\r\n      // Password = GetPassword(OutStream); \r\n      // PasswordIsDefined = true;\r\n      PrintError(\"Password is not defined\");\r\n      return E_ABORT;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////////////////\r\n// Main function\r\n\r\nint \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\nmain(int argc, char* argv[])\r\n{\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  #endif\r\n\r\n  PrintStringLn(kCopyrightString);\r\n\r\n  if (argc < 3)\r\n  {\r\n    PrintStringLn(kHelpString);\r\n    return 1;\r\n  }\r\n  NWindows::NDLL::CLibrary library;\r\n  if (!library.Load(TEXT(kDllName)))\r\n  {\r\n    PrintError(\"Can not load library\");\r\n    return 1;\r\n  }\r\n  CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress(\"CreateObject\");\r\n  if (createObjectFunc == 0)\r\n  {\r\n    PrintError(\"Can not get CreateObject\");\r\n    return 1;\r\n  }\r\n\r\n  AString command = argv[1];\r\n  UString archiveName = GetUnicodeString(argv[2], CP_OEMCP);\r\n  if (command.CompareNoCase(\"a\") == 0)\r\n  {\r\n    // create archive command\r\n    if (argc < 4)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n    CObjectVector<CDirItem> dirItems;\r\n    int i;\r\n    for (i = 3; i < argc; i++)\r\n    {\r\n      CDirItem item;\r\n      UString name = GetUnicodeString(argv[i], CP_OEMCP);\r\n      \r\n      NFile::NFind::CFileInfoW fileInfo;\r\n      if (!NFile::NFind::FindFile(name, fileInfo))\r\n      {\r\n        PrintString(UString(L\"Can't find file\") + name);\r\n        return 1;\r\n      }\r\n\r\n      item.Attributes = fileInfo.Attributes;\r\n      item.Size = fileInfo.Size;\r\n      item.CreationTime = fileInfo.CreationTime;\r\n      item.LastAccessTime = fileInfo.LastAccessTime;\r\n      item.LastWriteTime = fileInfo.LastWriteTime;\r\n      item.Name = name;\r\n      item.FullPath = name;\r\n      dirItems.Add(item);\r\n    }\r\n    COutFileStream *outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;\r\n    if (!outFileStreamSpec->Create(archiveName, false))\r\n    {\r\n      PrintError(\"can't create archive file\");\r\n      return 1;\r\n    }\r\n\r\n    CMyComPtr<IOutArchive> outArchive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n\r\n    CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n    CMyComPtr<IArchiveUpdateCallback2> updateCallback(updateCallbackSpec);\r\n    updateCallbackSpec->Init(&dirItems);\r\n    // updateCallbackSpec->PasswordIsDefined = true;\r\n    // updateCallbackSpec->Password = L\"1\";\r\n\r\n    HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);\r\n    updateCallbackSpec->Finilize();\r\n    if (result != S_OK)\r\n    {\r\n      PrintError(\"Update Error\");\r\n      return 1;\r\n    }\r\n    for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)\r\n    {\r\n      PrintNewLine();\r\n      PrintString((UString)L\"Error for file: \" + updateCallbackSpec->FailedFiles[i]);\r\n    }\r\n    if (updateCallbackSpec->FailedFiles.Size() != 0)\r\n      return 1;\r\n  }\r\n  else\r\n  {\r\n    if (argc != 3)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n\r\n    bool listCommand;\r\n    if (command.CompareNoCase(\"l\") == 0)\r\n      listCommand = true;\r\n    else if (command.CompareNoCase(\"x\") == 0)\r\n      listCommand = false;\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      return 1;\r\n    }\r\n  \r\n    CMyComPtr<IInArchive> archive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n    \r\n    CInFileStream *fileSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> file = fileSpec;\r\n    \r\n    if (!fileSpec->Open(archiveName))\r\n    {\r\n      PrintError(\"Can not open archive file\");\r\n      return 1;\r\n    }\r\n\r\n    {\r\n      CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;\r\n      CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);\r\n      openCallbackSpec->PasswordIsDefined = false;\r\n      // openCallbackSpec->PasswordIsDefined = true;\r\n      // openCallbackSpec->Password = L\"1\";\r\n      \r\n      if (archive->Open(file, 0, openCallback) != S_OK)\r\n      {\r\n        PrintError(\"Can not open archive\");\r\n        return 1;\r\n      }\r\n    }\r\n    \r\n    if (listCommand)\r\n    {\r\n      // List command\r\n      UInt32 numItems = 0;\r\n      archive->GetNumberOfItems(&numItems);  \r\n      for (UInt32 i = 0; i < numItems; i++)\r\n      {\r\n        {\r\n          // Get uncompressed size of file\r\n          NWindows::NCOM::CPropVariant propVariant;\r\n          archive->GetProperty(i, kpidSize, &propVariant);\r\n          UString s = ConvertPropVariantToString(propVariant);\r\n          PrintString(s);\r\n          PrintString(\"  \");\r\n        }\r\n        {\r\n          // Get name of file\r\n          NWindows::NCOM::CPropVariant propVariant;\r\n          archive->GetProperty(i, kpidPath, &propVariant);\r\n          UString s = ConvertPropVariantToString(propVariant);\r\n          PrintString(s);\r\n        }\r\n        PrintString(\"\\n\");\r\n      }\r\n    }\r\n    else\r\n    {\r\n      // Extract command\r\n      CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n      CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);\r\n      extractCallbackSpec->Init(archive, L\"\"); // second parameter is output folder path\r\n      extractCallbackSpec->PasswordIsDefined = false;\r\n      // extractCallbackSpec->PasswordIsDefined = true;\r\n      // extractCallbackSpec->Password = L\"1\";\r\n      HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);\r\n      if (result != S_OK)\r\n      {\r\n        PrintError(\"Extract Error\");\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Client7z/Client7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Client7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Client7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\" CFG=\"Client7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Client7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Client7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Client7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Client7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Client7z - Win32 Release\"\r\n# Name \"Client7z - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"stdafx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\Client7z.cpp\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Client7z/Client7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Client7z\"=.\\Client7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Client7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Client7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include <windows.h>\r\n#include <stdio.h>\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Client7z/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\Client7z.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FileStreams.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp",
    "content": "// ArchiveCommandLine.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <io.h>\r\n#endif\r\n#include <stdio.h>\r\n\r\n#include \"Common/ListFileUtils.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/FileMapping.h\"\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ArchiveCommandLine.h\"\r\n#include \"UpdateAction.h\"\r\n#include \"Update.h\"\r\n#include \"SortUtils.h\"\r\n#include \"EnumDirItems.h\"\r\n\r\nextern bool g_CaseSensitive;\r\n\r\n#if _MSC_VER >= 1400\r\n#define MY_isatty_fileno(x) _isatty(_fileno(x))\r\n#else\r\n#define MY_isatty_fileno(x) isatty(fileno(x))\r\n#endif\r\n\r\n#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0); \r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kHelp3,\r\n  kDisableHeaders,\r\n  kDisablePercents,\r\n  kArchiveType,\r\n  kYes,\r\n  kPassword,\r\n  kProperty,\r\n  kOutputDir,\r\n  kWorkingDir,\r\n  kInclude,\r\n  kExclude,\r\n  kArInclude,\r\n  kArExclude,\r\n  kNoArName,\r\n  kUpdate,\r\n  kVolume,\r\n  kRecursed,\r\n  kSfx,\r\n  kStdIn,\r\n  kStdOut,\r\n  kOverwrite,\r\n  kEmail,\r\n  kShowDialog,\r\n  kLargePages,\r\n  kCharSet,\r\n  kTechMode,\r\n  kShareForWrite,\r\n  kCaseSensitive\r\n};\r\n\r\n}\r\n\r\n\r\nstatic const wchar_t kRecursedIDChar = 'R';\r\nstatic const wchar_t *kRecursedPostCharSet = L\"0-\";\r\n\r\nnamespace NRecursedPostCharIndex {\r\n  enum EEnum \r\n  {\r\n    kWildCardRecursionOnly = 0, \r\n    kNoRecursion = 1\r\n  };\r\n}\r\n\r\nstatic const char kImmediateNameID = '!';\r\nstatic const char kMapNameID = '#';\r\nstatic const char kFileListID = '@';\r\n\r\nstatic const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be\r\nstatic const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be\r\n\r\nstatic const wchar_t *kOverwritePostCharSet = L\"asut\";\r\n\r\nNExtract::NOverwriteMode::EEnum k_OverwriteModes[] =\r\n{\r\n  NExtract::NOverwriteMode::kWithoutPrompt,\r\n  NExtract::NOverwriteMode::kSkipExisting,\r\n  NExtract::NOverwriteMode::kAutoRename,\r\n  NExtract::NOverwriteMode::kAutoRenameExisting\r\n};\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n  {\r\n    { L\"?\",  NSwitchType::kSimple, false },\r\n    { L\"H\",  NSwitchType::kSimple, false },\r\n    { L\"-HELP\",  NSwitchType::kSimple, false },\r\n    { L\"BA\", NSwitchType::kSimple, false },\r\n    { L\"BD\", NSwitchType::kSimple, false },\r\n    { L\"T\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"Y\",  NSwitchType::kSimple, false },\r\n    { L\"P\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"M\",  NSwitchType::kUnLimitedPostString, true, 1 },\r\n    { L\"O\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"W\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"I\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"X\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AI\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AX\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AN\", NSwitchType::kSimple, false },\r\n    { L\"U\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"V\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"R\",  NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },\r\n    { L\"SFX\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SI\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SO\", NSwitchType::kSimple, false, 0 },\r\n    { L\"AO\", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},\r\n    { L\"SEML\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"AD\",  NSwitchType::kSimple, false },\r\n    { L\"SLP\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SCS\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SLT\", NSwitchType::kSimple, false },\r\n    { L\"SSW\", NSwitchType::kSimple, false },\r\n    { L\"SSC\", NSwitchType::kPostChar, false, 0, 0, L\"-\" }\r\n  };\r\n\r\nstatic const CCommandForm g_CommandForms[] = \r\n{\r\n  { L\"A\", false },\r\n  { L\"U\", false },\r\n  { L\"D\", false },\r\n  { L\"T\", false },\r\n  { L\"E\", false },\r\n  { L\"X\", false },\r\n  { L\"L\", false },\r\n  { L\"B\", false },\r\n  { L\"I\", false }\r\n};\r\n\r\nstatic const int kNumCommandForms = sizeof(g_CommandForms) /  sizeof(g_CommandForms[0]);\r\n\r\nstatic const wchar_t *kUniversalWildcard = L\"*\";\r\nstatic const int kMinNonSwitchWords = 1;\r\nstatic const int kCommandIndex = 0;\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\";\r\nstatic const char *kIncorrectListFile = \"Incorrect item in listfile.\\nCheck charset encoding and -scs switch.\";\r\nstatic const char *kIncorrectWildCardInListFile = \"Incorrect wildcard in listfile\";\r\nstatic const char *kIncorrectWildCardInCommandLine  = \"Incorrect wildcard in command line\";\r\nstatic const char *kTerminalOutError = \"I won't write compressed data to a terminal\";\r\nstatic const char *kSameTerminalError = \"I won't write data and program's messages to same terminal\";\r\n\r\nstatic void ThrowException(const char *errorMessage)\r\n{\r\n  throw CArchiveCommandLineException(errorMessage);\r\n};\r\n\r\nstatic void ThrowUserErrorException()\r\n{\r\n  ThrowException(kUserErrorMessage);\r\n};\r\n\r\n// ---------------------------\r\n\r\nbool CArchiveCommand::IsFromExtractGroup() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kExtract:\r\n    case NCommandType::kFullExtract:\r\n      return true;\r\n    default:\r\n      return false;\r\n  }\r\n}\r\n\r\nNExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kFullExtract:\r\n      return NExtract::NPathMode::kFullPathnames;\r\n    default:\r\n      return NExtract::NPathMode::kNoPathnames;\r\n  }\r\n}\r\n\r\nbool CArchiveCommand::IsFromUpdateGroup() const\r\n{\r\n  return (CommandType == NCommandType::kAdd || \r\n    CommandType == NCommandType::kUpdate ||\r\n    CommandType == NCommandType::kDelete);\r\n}\r\n\r\nstatic NRecursedType::EEnum GetRecursedTypeFromIndex(int index)\r\n{\r\n  switch (index)\r\n  {\r\n    case NRecursedPostCharIndex::kWildCardRecursionOnly: \r\n      return NRecursedType::kWildCardOnlyRecursed;\r\n    case NRecursedPostCharIndex::kNoRecursion: \r\n      return NRecursedType::kNonRecursed;\r\n    default:\r\n      return NRecursedType::kRecursed;\r\n  }\r\n}\r\n\r\nstatic bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)\r\n{\r\n  UString commandStringUpper = commandString;\r\n  commandStringUpper.MakeUpper();\r\n  UString postString;\r\n  int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper, \r\n      postString) ;\r\n  if (commandIndex < 0)\r\n    return false;\r\n  command.CommandType = (NCommandType::EEnum)commandIndex;\r\n  return true;\r\n}\r\n\r\n// ------------------------------------------------------------------\r\n// filenames functions\r\n\r\nstatic bool AddNameToCensor(NWildcard::CCensor &wildcardCensor, \r\n    const UString &name, bool include, NRecursedType::EEnum type)\r\n{\r\n  bool isWildCard = DoesNameContainWildCard(name);\r\n  bool recursed = false;\r\n\r\n  switch (type)\r\n  {\r\n    case NRecursedType::kWildCardOnlyRecursed:\r\n      recursed = isWildCard;\r\n      break;\r\n    case NRecursedType::kRecursed:\r\n      recursed = true;\r\n      break;\r\n    case NRecursedType::kNonRecursed:\r\n      recursed = false;\r\n      break;\r\n  }\r\n  wildcardCensor.AddItem(include, name, recursed);\r\n  return true;\r\n}\r\n\r\nstatic void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor, \r\n    LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)\r\n{\r\n  UStringVector names;\r\n  if (!ReadNamesFromListFile(fileName, names, codePage))\r\n    throw kIncorrectListFile;\r\n  for (int i = 0; i < names.Size(); i++)\r\n    if (!AddNameToCensor(wildcardCensor, names[i], include, type))\r\n      throw kIncorrectWildCardInListFile;\r\n}\r\n\r\nstatic void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor, \r\n    const UString &name, bool include, NRecursedType::EEnum recursedType)\r\n{\r\n  if (!AddNameToCensor(wildcardCensor, name, include, recursedType))\r\n    throw kIncorrectWildCardInCommandLine;\r\n}\r\n\r\nstatic void AddToCensorFromNonSwitchesStrings(\r\n    int startIndex,\r\n    NWildcard::CCensor &wildcardCensor, \r\n    const UStringVector &nonSwitchStrings, NRecursedType::EEnum type, \r\n    bool thereAreSwitchIncludes, UINT codePage)\r\n{\r\n  if(nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes)) \r\n    AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);\r\n  for(int i = startIndex; i < nonSwitchStrings.Size(); i++)\r\n  {\r\n    const UString &s = nonSwitchStrings[i];\r\n    if (s[0] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);\r\n    else\r\n      AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor, \r\n    const UString &switchParam, bool include, \r\n    NRecursedType::EEnum commonRecursedType)\r\n{\r\n  int splitPos = switchParam.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  UString mappingName = switchParam.Left(splitPos);\r\n  \r\n  UString switchParam2 = switchParam.Mid(splitPos + 1);\r\n  splitPos = switchParam2.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  \r\n  UString mappingSize = switchParam2.Left(splitPos);\r\n  UString eventName = switchParam2.Mid(splitPos + 1);\r\n  \r\n  UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);\r\n  UInt32 dataSize = (UInt32)dataSize64;\r\n  {\r\n    CFileMapping fileMapping;\r\n    if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName)))\r\n      ThrowException(\"Can not open mapping\");\r\n    LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize);\r\n    if (data == NULL)\r\n      ThrowException(\"MapViewOfFile error\");\r\n    try\r\n    {\r\n      const wchar_t *curData = (const wchar_t *)data;\r\n      if (*curData != 0)\r\n        ThrowException(\"Incorrect mapping data\");\r\n      UInt32 numChars = dataSize / sizeof(wchar_t);\r\n      UString name;\r\n      for (UInt32 i = 1; i < numChars; i++)\r\n      {\r\n        wchar_t c = curData[i];\r\n        if (c == L'\\0')\r\n        {\r\n          AddCommandLineWildCardToCensr(wildcardCensor, \r\n              name, include, commonRecursedType);\r\n          name.Empty();\r\n        }\r\n        else\r\n          name += c;\r\n      }\r\n      if (!name.IsEmpty())\r\n        ThrowException(\"data error\");\r\n    }\r\n    catch(...)\r\n    {\r\n      UnmapViewOfFile(data);\r\n      throw;\r\n    }\r\n    UnmapViewOfFile(data);\r\n  }\r\n  \r\n  {\r\n    NSynchronization::CManualResetEvent event;\r\n    if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)\r\n      event.Set();\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor, \r\n    const UStringVector &strings, bool include, \r\n    NRecursedType::EEnum commonRecursedType, UINT codePage)\r\n{\r\n  for(int i = 0; i < strings.Size(); i++)\r\n  {\r\n    const UString &name = strings[i];\r\n    NRecursedType::EEnum recursedType;\r\n    int pos = 0;\r\n    if (name.Length() < kSomeCludePostStringMinSize)\r\n      ThrowUserErrorException();\r\n    if (::MyCharUpper(name[pos]) == kRecursedIDChar)\r\n    {\r\n      pos++;\r\n      int index = UString(kRecursedPostCharSet).Find(name[pos]);\r\n      recursedType = GetRecursedTypeFromIndex(index);\r\n      if (index >= 0)\r\n        pos++;\r\n    }\r\n    else\r\n      recursedType = commonRecursedType;\r\n    if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)\r\n      ThrowUserErrorException();\r\n    UString tail = name.Mid(pos + 1);\r\n    if (name[pos] == kImmediateNameID)\r\n      AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);\r\n    else if (name[pos] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);\r\n    #ifdef _WIN32\r\n    else if (name[pos] == kMapNameID)\r\n      ParseMapWithPaths(wildcardCensor, tail, include, recursedType);\r\n    #endif\r\n    else\r\n      ThrowUserErrorException();\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\n// This code converts all short file names to long file names.\r\n\r\nstatic void ConvertToLongName(const UString &prefix, UString &name)\r\n{\r\n  if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n    return;\r\n  NFind::CFileInfoW fileInfo;\r\n  if (NFind::FindFile(prefix + name, fileInfo))\r\n    name = fileInfo.Name;\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)\r\n{\r\n  for (int i = 0; i < items.Size(); i++)\r\n  {\r\n    NWildcard::CItem &item = items[i];\r\n    if (item.Recursive || item.PathParts.Size() != 1)\r\n      continue;\r\n    ConvertToLongName(prefix, item.PathParts.Front());\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)\r\n{\r\n  ConvertToLongNames(prefix, node.IncludeItems);\r\n  ConvertToLongNames(prefix, node.ExcludeItems);\r\n  int i;\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n    ConvertToLongName(prefix, node.SubNodes[i].Name);\r\n  // mix folders with same name\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];\r\n    for (int j = i + 1; j < node.SubNodes.Size();)\r\n    {\r\n      const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];\r\n      if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)\r\n      {\r\n        nextNode1.IncludeItems += nextNode2.IncludeItems;\r\n        nextNode1.ExcludeItems += nextNode2.ExcludeItems;\r\n        node.SubNodes.Delete(j);\r\n      }\r\n      else\r\n        j++;\r\n    }\r\n  }\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode = node.SubNodes[i];\r\n    ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode); \r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(NWildcard::CCensor &censor)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    NWildcard::CPair &pair = censor.Pairs[i];\r\n    ConvertToLongNames(pair.Prefix, pair.Head);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\nstatic NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)\r\n{\r\n  switch(i)\r\n  {\r\n    case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;\r\n    case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;\r\n    case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;\r\n    case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;\r\n  }\r\n  throw 98111603;\r\n}\r\n\r\nconst UString kUpdatePairStateIDSet = L\"PQRXYZW\";\r\nconst int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};\r\n\r\nconst UString kUpdatePairActionIDSet = L\"0123\"; //Ignore, Copy, Compress, Create Anti\r\n\r\nconst wchar_t *kUpdateIgnoreItselfPostStringID = L\"-\"; \r\nconst wchar_t kUpdateNewArchivePostCharID = '!'; \r\n\r\n\r\nstatic bool ParseUpdateCommandString2(const UString &command, \r\n    NUpdateArchive::CActionSet &actionSet, UString &postString)\r\n{\r\n  for(int i = 0; i < command.Length();)\r\n  {\r\n    wchar_t c = MyCharUpper(command[i]);\r\n    int statePos = kUpdatePairStateIDSet.Find(c);\r\n    if (statePos < 0)\r\n    {\r\n      postString = command.Mid(i);\r\n      return true;\r\n    }\r\n    i++;\r\n    if (i >= command.Length())\r\n      return false;\r\n    int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));\r\n    if (actionPos < 0)\r\n      return false;\r\n    actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);\r\n    if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)\r\n      return false;\r\n    i++;\r\n  }\r\n  postString.Empty();\r\n  return true;\r\n}\r\n\r\nstatic void ParseUpdateCommandString(CUpdateOptions &options, \r\n    const UStringVector &updatePostStrings, \r\n    const NUpdateArchive::CActionSet &defaultActionSet)\r\n{\r\n  for(int i = 0; i < updatePostStrings.Size(); i++)\r\n  {\r\n    const UString &updateString = updatePostStrings[i];\r\n    if(updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)\r\n    {\r\n      if(options.UpdateArchiveItself)\r\n      {\r\n        options.UpdateArchiveItself = false;\r\n        options.Commands.Delete(0);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      NUpdateArchive::CActionSet actionSet = defaultActionSet;\r\n\r\n      UString postString;\r\n      if (!ParseUpdateCommandString2(updateString, actionSet, postString))\r\n        ThrowUserErrorException();\r\n      if(postString.IsEmpty())\r\n      {\r\n        if(options.UpdateArchiveItself)\r\n          options.Commands[0].ActionSet = actionSet;\r\n      }\r\n      else\r\n      {\r\n        if(MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)\r\n          ThrowUserErrorException();\r\n        CUpdateArchiveCommand uc;\r\n        UString archivePath = postString.Mid(1);\r\n        if (archivePath.IsEmpty())\r\n          ThrowUserErrorException();\r\n        uc.UserArchivePath = archivePath;\r\n        uc.ActionSet = actionSet;\r\n        options.Commands.Add(uc);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic const char kByteSymbol = 'B';\r\nstatic const char kKiloSymbol = 'K';\r\nstatic const char kMegaSymbol = 'M';\r\nstatic const char kGigaSymbol = 'G';\r\n\r\nstatic bool ParseComplexSize(const UString &src, UInt64 &result)\r\n{\r\n  UString s = src;\r\n  s.MakeUpper();\r\n\r\n  const wchar_t *start = s;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || s.Length() > numDigits + 1)\r\n    return false;\r\n  if (s.Length() == numDigits)\r\n  {\r\n    result = number;\r\n    return true;\r\n  }\r\n  int numBits;\r\n  switch (s[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      result = number;\r\n      return true;\r\n    case kKiloSymbol:\r\n      numBits = 10;\r\n      break;\r\n    case kMegaSymbol:\r\n      numBits = 20;\r\n      break;\r\n    case kGigaSymbol:\r\n      numBits = 30;\r\n      break;\r\n    default:\r\n      return false;\r\n  }\r\n  if (number >= ((UInt64)1 << (64 - numBits)))\r\n    return false;\r\n  result = number << numBits;\r\n  return true;\r\n}\r\n\r\nstatic void SetAddCommandOptions(\r\n    NCommandType::EEnum commandType, \r\n    const CParser &parser, \r\n    CUpdateOptions &options)\r\n{\r\n  NUpdateArchive::CActionSet defaultActionSet;\r\n  switch(commandType)\r\n  {\r\n    case NCommandType::kAdd: \r\n      defaultActionSet = NUpdateArchive::kAddActionSet;\r\n      break;\r\n    case NCommandType::kDelete: \r\n      defaultActionSet = NUpdateArchive::kDeleteActionSet;\r\n      break;\r\n    default: \r\n      defaultActionSet = NUpdateArchive::kUpdateActionSet;\r\n  }\r\n  \r\n  options.UpdateArchiveItself = true;\r\n  \r\n  options.Commands.Clear();\r\n  CUpdateArchiveCommand updateMainCommand;\r\n  updateMainCommand.ActionSet = defaultActionSet;\r\n  options.Commands.Add(updateMainCommand);\r\n  if(parser[NKey::kUpdate].ThereIs)\r\n    ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings, \r\n        defaultActionSet);\r\n  if(parser[NKey::kWorkingDir].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];\r\n    if (postString.IsEmpty())\r\n      NDirectory::MyGetTempPath(options.WorkingDir);\r\n    else\r\n      options.WorkingDir = postString;\r\n  }\r\n  options.SfxMode = parser[NKey::kSfx].ThereIs;\r\n  if (options.SfxMode)\r\n    options.SfxModule = parser[NKey::kSfx].PostStrings[0];\r\n\r\n  if (parser[NKey::kVolume].ThereIs)\r\n  {\r\n    const UStringVector &sv = parser[NKey::kVolume].PostStrings;\r\n    for (int i = 0; i < sv.Size(); i++)\r\n    {\r\n      UInt64 size;\r\n      if (!ParseComplexSize(sv[i], size))\r\n        ThrowException(\"Incorrect volume size\");\r\n      options.VolumesSizes.Add(size);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)\r\n{\r\n  if (parser[NKey::kProperty].ThereIs)\r\n  {\r\n    // options.MethodMode.Properties.Clear();\r\n    for(int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      CProperty property;\r\n      const UString &postString = parser[NKey::kProperty].PostStrings[i];\r\n      int index = postString.Find(L'=');\r\n      if (index < 0)\r\n        property.Name = postString;\r\n      else\r\n      {\r\n        property.Name = postString.Left(index);\r\n        property.Value = postString.Mid(index + 1);\r\n      }\r\n      properties.Add(property);\r\n    }\r\n  }\r\n}\r\n\r\nCArchiveCommandLineParser::CArchiveCommandLineParser(): \r\n  parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}\r\n\r\nvoid CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,\r\n    CArchiveCommandLineOptions &options)\r\n{\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    ThrowUserErrorException();\r\n  }\r\n\r\n  options.IsInTerminal = MY_IS_TERMINAL(stdin);\r\n  options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);\r\n  options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);\r\n  options.StdOutMode = parser[NKey::kStdOut].ThereIs;\r\n  options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;\r\n  options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs  || parser[NKey::kHelp3].ThereIs;\r\n\r\n  #ifdef _WIN32\r\n  options.LargePages = false;\r\n  if (parser[NKey::kLargePages].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kLargePages].PostStrings.Front();\r\n    if (postString.IsEmpty())\r\n      options.LargePages = true;\r\n  }\r\n  #endif\r\n}\r\n\r\nstruct CCodePagePair\r\n{\r\n  const wchar_t *Name;\r\n  UINT CodePage;\r\n};\r\n\r\nstatic CCodePagePair g_CodePagePairs[] = \r\n{\r\n  { L\"UTF-8\", CP_UTF8 },\r\n  { L\"WIN\",   CP_ACP },\r\n  { L\"DOS\",   CP_OEMCP }\r\n};\r\n\r\nstatic const int kNumCodePages = sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]);\r\n\r\nstatic bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)\r\n{\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(s, &end);\r\n  if (*end != 0)\r\n    return false;\r\n  if (number > (UInt32)0xFFFFFFFF)\r\n    return false;\r\n  v = (UInt32)number;\r\n  return true;\r\n}\r\n\r\nvoid CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)\r\n{\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n  int numNonSwitchStrings = nonSwitchStrings.Size();\r\n  if(numNonSwitchStrings < kMinNonSwitchWords)  \r\n    ThrowUserErrorException();\r\n\r\n  if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))\r\n    ThrowUserErrorException();\r\n\r\n  options.TechMode = parser[NKey::kTechMode].ThereIs;\r\n\r\n  if (parser[NKey::kCaseSensitive].ThereIs)\r\n    g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);\r\n\r\n  NRecursedType::EEnum recursedType;\r\n  if (parser[NKey::kRecursed].ThereIs)\r\n    recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);\r\n  else\r\n    recursedType = NRecursedType::kNonRecursed;\r\n\r\n  UINT codePage = CP_UTF8;\r\n  if (parser[NKey::kCharSet].ThereIs)\r\n  {\r\n    UString name = parser[NKey::kCharSet].PostStrings.Front();\r\n    name.MakeUpper();\r\n    int i;\r\n    for (i = 0; i < kNumCodePages; i++)\r\n    {\r\n      const CCodePagePair &pair = g_CodePagePairs[i];\r\n      if (name.Compare(pair.Name) == 0)\r\n      {\r\n        codePage = pair.CodePage;\r\n        break;\r\n      }\r\n    }\r\n    if (i >= kNumCodePages)\r\n      ThrowUserErrorException();\r\n  }\r\n\r\n  bool thereAreSwitchIncludes = false;\r\n  if (parser[NKey::kInclude].ThereIs)\r\n  {\r\n    thereAreSwitchIncludes = true;\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor, \r\n        parser[NKey::kInclude].PostStrings, true, recursedType, codePage);\r\n  }\r\n  if (parser[NKey::kExclude].ThereIs)\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor, \r\n        parser[NKey::kExclude].PostStrings, false, recursedType, codePage);\r\n \r\n  int curCommandIndex = kCommandIndex + 1;\r\n  bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs && \r\n      options.Command.CommandType != NCommandType::kBenchmark && \r\n      options.Command.CommandType != NCommandType::kInfo;\r\n  if (thereIsArchiveName)\r\n  {\r\n    if(curCommandIndex >= numNonSwitchStrings)  \r\n      ThrowUserErrorException();\r\n    options.ArchiveName = nonSwitchStrings[curCommandIndex++];\r\n  }\r\n\r\n  AddToCensorFromNonSwitchesStrings(\r\n      curCommandIndex, options.WildcardCensor, \r\n      nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);\r\n\r\n  options.YesToAll = parser[NKey::kYes].ThereIs;\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  options.PasswordEnabled = parser[NKey::kPassword].ThereIs;\r\n\r\n  if(options.PasswordEnabled)\r\n    options.Password = parser[NKey::kPassword].PostStrings[0];\r\n\r\n  options.StdInMode = parser[NKey::kStdIn].ThereIs;\r\n  options.ShowDialog = parser[NKey::kShowDialog].ThereIs;\r\n\r\n  if(isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if (options.StdInMode)\r\n      ThrowException(\"Reading archives from stdin is not implemented\");\r\n    if (!options.WildcardCensor.AllAreRelative())\r\n      ThrowException(\"Cannot use absolute pathnames for this command\");\r\n\r\n    NWildcard::CCensor archiveWildcardCensor;\r\n\r\n    if (parser[NKey::kArInclude].ThereIs)\r\n    {\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor, \r\n        parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);\r\n    }\r\n    if (parser[NKey::kArExclude].ThereIs)\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor, \r\n      parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);\r\n\r\n    if (thereIsArchiveName)\r\n      AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(archiveWildcardCensor);\r\n    #endif\r\n\r\n    archiveWildcardCensor.ExtendExclude();\r\n\r\n    CObjectVector<CDirItem> dirItems;\r\n    {\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);\r\n      if (res != S_OK || errorPaths.Size() > 0)\r\n        throw \"cannot find archive\";\r\n    }\r\n    UStringVector archivePaths;\r\n    int i;\r\n    for (i = 0; i < dirItems.Size(); i++)\r\n    {\r\n      const CDirItem &dirItem = dirItems[i];\r\n      if (!dirItem.IsDirectory())\r\n        archivePaths.Add(dirItem.FullPath);\r\n    }\r\n\r\n    if (archivePaths.Size() == 0)\r\n      throw \"there is no such archive\";\r\n\r\n    UStringVector archivePathsFull;\r\n\r\n    for (i = 0; i < archivePaths.Size(); i++)\r\n    {\r\n      UString fullPath;\r\n      NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);\r\n      archivePathsFull.Add(fullPath);\r\n    }\r\n    CIntVector indices;\r\n    SortFileNames(archivePathsFull, indices);\r\n    options.ArchivePathsSorted.Reserve(indices.Size());\r\n    options.ArchivePathsFullSorted.Reserve(indices.Size());\r\n    for (i = 0; i < indices.Size(); i++)\r\n    {\r\n      options.ArchivePathsSorted.Add(archivePaths[indices[i]]);\r\n      options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);\r\n    }\r\n\r\n    if (isExtractGroupCommand)\r\n    {\r\n      SetMethodOptions(parser, options.ExtractProperties); \r\n      if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)\r\n        throw kSameTerminalError;\r\n      if(parser[NKey::kOutputDir].ThereIs)\r\n      {\r\n        options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];\r\n        NFile::NName::NormalizeDirPathPrefix(options.OutputDir);\r\n      }\r\n\r\n      options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;\r\n      if(parser[NKey::kOverwrite].ThereIs)\r\n        options.OverwriteMode = \r\n            k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];\r\n      else if (options.YesToAll)\r\n        options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    CUpdateOptions &updateOptions = options.UpdateOptions;\r\n\r\n    if(parser[NKey::kArchiveType].ThereIs)\r\n      options.ArcType = parser[NKey::kArchiveType].PostStrings[0];\r\n\r\n    SetAddCommandOptions(options.Command.CommandType, parser, updateOptions); \r\n    \r\n    SetMethodOptions(parser, updateOptions.MethodMode.Properties); \r\n\r\n    if (parser[NKey::kShareForWrite].ThereIs)\r\n      updateOptions.OpenShareForWrite = true;\r\n\r\n    options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;\r\n\r\n    if (options.EnablePercents)\r\n    {\r\n      if ((options.StdOutMode && !options.IsStdErrTerminal) || \r\n         (!options.StdOutMode && !options.IsStdOutTerminal))  \r\n        options.EnablePercents = false;\r\n    }\r\n\r\n    updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;\r\n    if (updateOptions.EMailMode)\r\n    {\r\n      updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();\r\n      if (updateOptions.EMailAddress.Length() > 0)\r\n        if (updateOptions.EMailAddress[0] == L'.')\r\n        {\r\n          updateOptions.EMailRemoveAfter = true;\r\n          updateOptions.EMailAddress.Delete(0);\r\n        }\r\n    }\r\n\r\n    updateOptions.StdOutMode = options.StdOutMode;\r\n    updateOptions.StdInMode = options.StdInMode;\r\n\r\n    if (updateOptions.StdOutMode && updateOptions.EMailMode)\r\n      throw \"stdout mode and email mode cannot be combined\";\r\n    if (updateOptions.StdOutMode && options.IsStdOutTerminal)\r\n      throw kTerminalOutError;\r\n    if(updateOptions.StdInMode)\r\n      updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(options.WildcardCensor);\r\n    #endif\r\n  }\r\n  else if(options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    options.NumThreads = (UInt32)-1;\r\n    options.DictionarySize = (UInt32)-1;\r\n    options.NumIterations = 1;\r\n    if (curCommandIndex < numNonSwitchStrings)  \r\n    {\r\n      if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))\r\n        ThrowUserErrorException();\r\n    }\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      UString postString = parser[NKey::kProperty].PostStrings[i];\r\n      postString.MakeUpper();\r\n      if (postString.Length() < 2)\r\n        ThrowUserErrorException();\r\n      if (postString[0] == 'D')\r\n      {\r\n        int pos = 1;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        UInt32 logSize;\r\n        if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))\r\n          ThrowUserErrorException();\r\n        if (logSize > 31)\r\n          ThrowUserErrorException();\r\n        options.DictionarySize = 1 << logSize;\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == 'T' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        if (postString[pos] != 0)\r\n          if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))\r\n            ThrowUserErrorException();\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == '=' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] != 0)\r\n          options.Method = postString.Mid(2);\r\n      }\r\n      else\r\n        ThrowUserErrorException();\r\n    }\r\n  }\r\n  else if(options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n  }\r\n  else \r\n    ThrowUserErrorException();\r\n  options.WildcardCensor.ExtendExclude();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h",
    "content": "// ArchiveCommandLine.h\r\n\r\n#ifndef __ARCHIVECOMMANDLINE_H\r\n#define __ARCHIVECOMMANDLINE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#include \"Extract.h\"\r\n#include \"Update.h\"\r\n\r\nstruct CArchiveCommandLineException: public AString\r\n{\r\n  CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {}\r\n};\r\n\r\nnamespace NCommandType { enum EEnum\r\n{\r\n  kAdd = 0,\r\n  kUpdate,\r\n  kDelete,\r\n  kTest,\r\n  kExtract,\r\n  kFullExtract,\r\n  kList,\r\n  kBenchmark,\r\n  kInfo\r\n};}\r\n\r\nnamespace NRecursedType { enum EEnum\r\n{\r\n  kRecursed,\r\n  kWildCardOnlyRecursed,\r\n  kNonRecursed\r\n};}\r\n\r\nstruct CArchiveCommand\r\n{\r\n  NCommandType::EEnum CommandType;\r\n  bool IsFromExtractGroup() const;\r\n  bool IsFromUpdateGroup() const;\r\n  bool IsTestMode() const { return CommandType == NCommandType::kTest; }\r\n  NExtract::NPathMode::EEnum GetPathMode() const;\r\n};\r\n\r\nstruct CArchiveCommandLineOptions\r\n{\r\n  bool HelpMode;\r\n\r\n  #ifdef _WIN32\r\n  bool LargePages;\r\n  #endif\r\n\r\n  bool IsInTerminal;\r\n  bool IsStdOutTerminal;\r\n  bool IsStdErrTerminal;\r\n  bool StdInMode;\r\n  bool StdOutMode;\r\n  bool EnableHeaders;\r\n\r\n  bool YesToAll;\r\n  bool ShowDialog;\r\n  // NWildcard::CCensor ArchiveWildcardCensor;\r\n  NWildcard::CCensor WildcardCensor;\r\n\r\n  CArchiveCommand Command; \r\n  UString ArchiveName;\r\n\r\n  bool PasswordEnabled;\r\n  UString Password;\r\n\r\n  bool TechMode;\r\n  // Extract\r\n  bool AppendName;\r\n  UString OutputDir;\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n  UStringVector ArchivePathsSorted;\r\n  UStringVector ArchivePathsFullSorted;\r\n  CObjectVector<CProperty> ExtractProperties;\r\n\r\n  CUpdateOptions UpdateOptions;\r\n  UString ArcType;\r\n  bool EnablePercents;\r\n\r\n  // Benchmark \r\n  UInt32 NumIterations;\r\n  UInt32 NumThreads;\r\n  UInt32 DictionarySize;\r\n  UString Method;\r\n\r\n\r\n  CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};\r\n};\r\n\r\nclass CArchiveCommandLineParser\r\n{\r\n  NCommandLineParser::CParser parser;\r\npublic:\r\n  CArchiveCommandLineParser();\r\n  void Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options);\r\n  void Parse2(CArchiveCommandLineOptions &options);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp",
    "content": "// ArchiveExtractCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n#include \"OpenArchive.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic const wchar_t *kCantAutoRename = L\"ERROR: Can not create file with auto name\";\r\nstatic const wchar_t *kCantRenameFile = L\"ERROR: Can not rename existing file \";\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\n\r\nvoid CArchiveExtractCallback::Init(\r\n    IInArchive *archiveHandler,\r\n    IFolderArchiveExtractCallback *extractCallback2,\r\n    bool stdOutMode,\r\n    const UString &directoryPath, \r\n    const UStringVector &removePathParts,\r\n    const UString &itemDefaultName,\r\n    const FILETIME &utcLastWriteTimeDefault,\r\n    UInt32 attributesDefault,\r\n    UInt64 packSize)\r\n{\r\n  _stdOutMode = stdOutMode;\r\n  _numErrors = 0;\r\n  _unpTotal = 1;\r\n  _packTotal = packSize;\r\n\r\n  _extractCallback2 = extractCallback2;\r\n  _compressProgress.Release();\r\n  _extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);\r\n\r\n  LocalProgressSpec->Init(extractCallback2, true);\r\n  LocalProgressSpec->SendProgress = false;\r\n\r\n  _itemDefaultName = itemDefaultName;\r\n  _utcLastWriteTimeDefault = utcLastWriteTimeDefault;\r\n  _attributesDefault = attributesDefault;\r\n  _removePathParts = removePathParts;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  _unpTotal = size;\r\n  if (!_multiArchives && _extractCallback2)\r\n    return _extractCallback2->SetTotal(size);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  const UInt64 kMax = (UInt64)1 << 31;\r\n  while (v1 > kMax)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)\r\n{\r\n  NormalizeVals(packTotal, unpTotal);\r\n  NormalizeVals(unpCur, unpTotal);\r\n  if (unpTotal == 0)\r\n    unpTotal = 1;\r\n  return unpCur * packTotal / unpTotal;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_extractCallback2)\r\n    return S_OK;\r\n\r\n  if (_multiArchives)\r\n  {\r\n    if (completeValue != NULL)\r\n    {\r\n      UInt64 packCur = LocalProgressSpec->InSize + MyMultDiv64(*completeValue, _unpTotal, _packTotal);\r\n      return _extractCallback2->SetCompleted(&packCur);\r\n    }\r\n  }\r\n  return _extractCallback2->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return _localProgress->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\nvoid CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)\r\n{\r\n  fullPath = _directoryPath;\r\n  for(int i = 0; i < dirPathParts.Size(); i++)\r\n  {\r\n    if (i > 0)\r\n      fullPath += wchar_t(NFile::NName::kDirDelimiter);\r\n    fullPath += dirPathParts[i];\r\n    NFile::NDirectory::MyCreateDirectory(fullPath);\r\n  }\r\n}\r\n\r\nstatic UString MakePathNameFromParts(const UStringVector &parts)\r\n{\r\n  UString result;\r\n  for(int i = 0; i < parts.Size(); i++)\r\n  {\r\n    if(i != 0)\r\n      result += wchar_t(NFile::NName::kDirDelimiter);\r\n    result += parts[i];\r\n  }\r\n  return result;\r\n}\r\n\r\n\r\nHRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(_archiveHandler->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    filetime = prop.filetime;\r\n    filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  _encrypted = false;\r\n  _isSplit = false;\r\n  _curSize = 0;\r\n\r\n  UString fullPath;\r\n\r\n  RINOK(GetArchiveItemPath(_archiveHandler, index, _itemDefaultName, fullPath));\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDirectory));\r\n\r\n  _filePath = fullPath;\r\n\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPosition, &prop));\r\n    if (prop.vt != VT_EMPTY)\r\n    {\r\n      if (prop.vt != VT_UI8)\r\n        return E_FAIL;\r\n      _position = prop.uhVal.QuadPart;\r\n      _isSplit = true;\r\n    }\r\n  }\r\n    \r\n  RINOK(IsArchiveItemProp(_archiveHandler, index, kpidEncrypted, _encrypted));\r\n\r\n  bool newFileSizeDefined;\r\n  UInt64 newFileSize;\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    if (newFileSizeDefined)\r\n    {\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n      _curSize = newFileSize;\r\n    }\r\n  }\r\n\r\n  if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)\r\n  {\r\n    if (_stdOutMode)\r\n    {\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc = new CStdOutFileStream;\r\n      *outStream = outStreamLoc.Detach();\r\n      return S_OK;\r\n    }\r\n\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n        _processedFileInfo.Attributes = _attributesDefault;\r\n        _processedFileInfo.AttributesAreDefined = false;\r\n      }\r\n      else\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_FAIL;\r\n        _processedFileInfo.Attributes = prop.ulVal;\r\n        _processedFileInfo.AttributesAreDefined = true;\r\n      }\r\n    }\r\n\r\n    RINOK(GetTime(index, kpidCreationTime, _processedFileInfo.CreationTime,\r\n        _processedFileInfo.IsCreationTimeDefined));\r\n    RINOK(GetTime(index, kpidLastWriteTime, _processedFileInfo.LastWriteTime, \r\n        _processedFileInfo.IsLastWriteTimeDefined));\r\n    RINOK(GetTime(index, kpidLastAccessTime, _processedFileInfo.LastAccessTime,\r\n        _processedFileInfo.IsLastAccessTimeDefined));\r\n\r\n    bool isAnti = false;\r\n    RINOK(IsArchiveItemProp(_archiveHandler, index, kpidIsAnti, isAnti));\r\n\r\n    UStringVector pathParts; \r\n    SplitPathToParts(fullPath, pathParts);\r\n    \r\n    if(pathParts.IsEmpty())\r\n      return E_FAIL;\r\n    int numRemovePathParts = 0;\r\n    switch(_pathMode)\r\n    {\r\n      case NExtract::NPathMode::kFullPathnames:\r\n        break;\r\n      case NExtract::NPathMode::kCurrentPathnames:\r\n      {\r\n        numRemovePathParts = _removePathParts.Size();\r\n        if (pathParts.Size() <= numRemovePathParts)\r\n          return E_FAIL;\r\n        for (int i = 0; i < numRemovePathParts; i++)\r\n          if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0)\r\n            return E_FAIL;\r\n        break;\r\n      }\r\n      case NExtract::NPathMode::kNoPathnames:\r\n      {\r\n        numRemovePathParts = pathParts.Size() - 1;\r\n        break;\r\n      }\r\n    }\r\n    pathParts.Delete(0, numRemovePathParts);\r\n    MakeCorrectPath(pathParts);\r\n    UString processedPath = MakePathNameFromParts(pathParts);\r\n    if (!isAnti)\r\n    {\r\n      if (!_processedFileInfo.IsDirectory)\r\n      {\r\n        if (!pathParts.IsEmpty())\r\n          pathParts.DeleteBack();\r\n      }\r\n    \r\n      if (!pathParts.IsEmpty())\r\n      {\r\n        UString fullPathNew;\r\n        CreateComplexDirectory(pathParts, fullPathNew);\r\n        if (_processedFileInfo.IsDirectory)\r\n          NFile::NDirectory::SetDirTime(fullPathNew, \r\n            (WriteCreated && _processedFileInfo.IsCreationTimeDefined) ? &_processedFileInfo.CreationTime : NULL, \r\n            (WriteAccessed && _processedFileInfo.IsLastAccessTimeDefined) ? &_processedFileInfo.LastAccessTime : NULL, \r\n            (WriteModified && _processedFileInfo.IsLastWriteTimeDefined) ? &_processedFileInfo.LastWriteTime : &_utcLastWriteTimeDefault);\r\n      }\r\n    }\r\n\r\n\r\n    UString fullProcessedPath = _directoryPath + processedPath;\r\n\r\n    if(_processedFileInfo.IsDirectory)\r\n    {\r\n      _diskFilePath = fullProcessedPath;\r\n      if (isAnti)\r\n        NFile::NDirectory::MyRemoveDirectory(_diskFilePath);\r\n      return S_OK;\r\n    }\r\n\r\n    if (!_isSplit)\r\n    {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      switch(_overwriteMode)\r\n      {\r\n        case NExtract::NOverwriteMode::kSkipExisting:\r\n          return S_OK;\r\n        case NExtract::NOverwriteMode::kAskBefore:\r\n        {\r\n          Int32 overwiteResult;\r\n          RINOK(_extractCallback2->AskOverwrite(\r\n              fullProcessedPath, &fileInfo.LastWriteTime, &fileInfo.Size, fullPath, \r\n              _processedFileInfo.IsLastWriteTimeDefined ? &_processedFileInfo.LastWriteTime : NULL, \r\n              newFileSizeDefined ? &newFileSize : NULL, \r\n              &overwiteResult))\r\n\r\n          switch(overwiteResult)\r\n          {\r\n            case NOverwriteAnswer::kCancel:\r\n              return E_ABORT;\r\n            case NOverwriteAnswer::kNo:\r\n              return S_OK;\r\n            case NOverwriteAnswer::kNoToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kSkipExisting;\r\n              return S_OK;\r\n            case NOverwriteAnswer::kYesToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n              break;\r\n            case NOverwriteAnswer::kYes:\r\n              break;\r\n            case NOverwriteAnswer::kAutoRename:\r\n              _overwriteMode = NExtract::NOverwriteMode::kAutoRename;\r\n              break;\r\n            default:\r\n              return E_FAIL;\r\n          }\r\n        }\r\n      }\r\n      if (_overwriteMode == NExtract::NOverwriteMode::kAutoRename)\r\n      {\r\n        if (!AutoRenamePath(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantAutoRename) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)\r\n      {\r\n        UString existPath = fullProcessedPath;\r\n        if (!AutoRenamePath(existPath))\r\n        {\r\n          UString message = kCantAutoRename + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n        if(!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))\r\n        {\r\n          UString message = UString(kCantRenameFile) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else\r\n        if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantDeleteOutputFile) +  fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n          // return E_FAIL;\r\n        }\r\n    }\r\n    }\r\n    if (!isAnti)\r\n    {\r\n      _outFileStreamSpec = new COutFileStream;\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n      if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))\r\n      {\r\n        // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)\r\n        {\r\n          UString message = L\"can not open output file \" + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n        }\r\n      }\r\n      if (_isSplit)\r\n      {\r\n        RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));\r\n      }\r\n      _outFileStream = outStreamLoc;\r\n      *outStream = outStreamLoc.Detach();\r\n    }\r\n    _diskFilePath = fullProcessedPath;\r\n  }\r\n  else\r\n  {\r\n    *outStream = NULL;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  return _extractCallback2->PrepareOperation(_filePath, _processedFileInfo.IsDirectory, \r\n      askExtractMode, _isSplit ? &_position: 0);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n    case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n    case NArchive::NExtract::NOperationResult::kCRCError:\r\n    case NArchive::NExtract::NOperationResult::kDataError:\r\n      break;\r\n    default:\r\n      _outFileStream.Release();\r\n      return E_FAIL;\r\n  }\r\n  if (_outFileStream != NULL)\r\n  {\r\n    _outFileStreamSpec->SetTime(\r\n        (WriteCreated && _processedFileInfo.IsCreationTimeDefined) ? &_processedFileInfo.CreationTime : NULL, \r\n        (WriteAccessed && _processedFileInfo.IsLastAccessTimeDefined) ? &_processedFileInfo.LastAccessTime : NULL, \r\n        (WriteModified && _processedFileInfo.IsLastWriteTimeDefined) ? &_processedFileInfo.LastWriteTime : &_utcLastWriteTimeDefault);\r\n    _curSize = _outFileStreamSpec->ProcessedSize;\r\n    RINOK(_outFileStreamSpec->Close());\r\n    _outFileStream.Release();\r\n  }\r\n  UnpackSize += _curSize;\r\n  if (_processedFileInfo.IsDirectory)\r\n    NumFolders++;\r\n  else\r\n    NumFiles++;\r\n\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CArchiveExtractCallback::GetInStream(\r\n    const wchar_t *name, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  CInFileStream *inFile = new CInFileStream;\r\n  CMyComPtr<ISequentialInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(_srcDirectoryPrefix + name))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_cryptoGetTextPassword)\r\n  {\r\n    RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword, \r\n        &_cryptoGetTextPassword));\r\n  }\r\n  return _cryptoGetTextPassword->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h",
    "content": "// ArchiveExtractCallback.h\r\n\r\n#ifndef __ARCHIVEEXTRACTCALLBACK_H\r\n#define __ARCHIVEEXTRACTCALLBACK_H\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"IFileExtractCallback.h\"\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"ExtractMode.h\"\r\n\r\nclass CArchiveExtractCallback: \r\n  public IArchiveExtractCallback,\r\n  // public IArchiveVolumeExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(ICryptoGetTextPassword, ICompressProgressInfo)\r\n  // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IExtractCallBack\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // IArchiveVolumeExtractCallback\r\n  // STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;\r\n  CMyComPtr<ICompressProgressInfo> _compressProgress;\r\n  CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;\r\n  UString _directoryPath;\r\n  NExtract::NPathMode::EEnum _pathMode;\r\n  NExtract::NOverwriteMode::EEnum _overwriteMode;\r\n\r\n  UString _filePath;\r\n  UInt64 _position;\r\n  bool _isSplit;\r\n\r\n  UString _diskFilePath;\r\n\r\n  bool _extractMode;\r\n\r\n  bool WriteModified;\r\n  bool WriteCreated;\r\n  bool WriteAccessed;\r\n\r\n  bool _encrypted;\r\n\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME CreationTime;\r\n    FILETIME LastWriteTime;\r\n    FILETIME LastAccessTime;\r\n    UInt32 Attributes;\r\n  \r\n    bool IsCreationTimeDefined;\r\n    bool IsLastWriteTimeDefined;\r\n    bool IsLastAccessTimeDefined;\r\n\r\n    bool IsDirectory;\r\n    bool AttributesAreDefined;\r\n  } _processedFileInfo;\r\n\r\n  UInt64 _curSize;\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n  UStringVector _removePathParts;\r\n\r\n  UString _itemDefaultName;\r\n  FILETIME _utcLastWriteTimeDefault;\r\n  UInt32 _attributesDefault;\r\n  bool _stdOutMode;\r\n\r\n  void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);\r\n  HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);\r\npublic:\r\n  CArchiveExtractCallback():\r\n      WriteModified(true),\r\n      WriteCreated(false),\r\n      WriteAccessed(false),\r\n      _multiArchives(false)\r\n  {\r\n    LocalProgressSpec = new CLocalProgress();\r\n    _localProgress = LocalProgressSpec;\r\n  }\r\n\r\n  CLocalProgress *LocalProgressSpec;\r\n  CMyComPtr<ICompressProgressInfo> _localProgress;\r\n  UInt64 _packTotal;\r\n  UInt64 _unpTotal;\r\n\r\n  bool _multiArchives;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  UInt64 UnpackSize;\r\n  \r\n  void InitForMulti(bool multiArchives, \r\n      NExtract::NPathMode::EEnum pathMode,\r\n      NExtract::NOverwriteMode::EEnum overwriteMode) \r\n  { \r\n    _multiArchives = multiArchives; NumFolders = NumFiles = UnpackSize = 0; \r\n    _pathMode = pathMode;\r\n    _overwriteMode = overwriteMode;\r\n  }\r\n\r\n  void Init(\r\n      IInArchive *archiveHandler, \r\n      IFolderArchiveExtractCallback *extractCallback2,\r\n      bool stdOutMode,\r\n      const UString &directoryPath,\r\n      const UStringVector &removePathParts,\r\n      const UString &itemDefaultName,\r\n      const FILETIME &utcLastWriteTimeDefault, \r\n      UInt32 attributesDefault,\r\n      UInt64 packSize);\r\n\r\n  UInt64 _numErrors;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ArchiveName.cpp",
    "content": "// ArchiveName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)\r\n{\r\n  UString resultName = L\"Archive\";\r\n  if (fromPrev)\r\n  {\r\n    UString dirPrefix;\r\n    if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))\r\n    {\r\n      if (dirPrefix.Length() > 0)\r\n        if (dirPrefix[dirPrefix.Length() - 1] == '\\\\')\r\n        {\r\n          dirPrefix.Delete(dirPrefix.Length() - 1);\r\n          NFile::NFind::CFileInfoW fileInfo;\r\n          if (NFile::NFind::FindFile(dirPrefix, fileInfo))\r\n            resultName = fileInfo.Name;\r\n        }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if (!NFile::NFind::FindFile(srcName, fileInfo))\r\n      return resultName;\r\n    resultName = fileInfo.Name;\r\n    if (!fileInfo.IsDirectory() && !keepName)\r\n    {\r\n      int dotPos = resultName.ReverseFind('.');\r\n      if (dotPos > 0)\r\n      {\r\n        UString archiveName2 = resultName.Left(dotPos);\r\n        if (archiveName2.ReverseFind('.') < 0)\r\n          resultName = archiveName2;\r\n      }\r\n    }\r\n  }\r\n  return resultName;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ArchiveName.h",
    "content": "// ArchiveName.h\r\n\r\n#ifndef __ARCHIVENAME_H\r\n#define __ARCHIVENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp",
    "content": "// ArchiveOpenCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n  \r\nSTDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant propVariant;\r\n  if (_subArchiveMode)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidName:\r\n        propVariant = _subArchiveName;\r\n        break;\r\n    }\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  switch(propID)\r\n  {\r\n    case kpidName:\r\n      propVariant = _fileInfo.Name;\r\n      break;\r\n    case kpidIsFolder:\r\n      propVariant = _fileInfo.IsDirectory();\r\n      break;\r\n    case kpidSize:\r\n      propVariant = _fileInfo.Size;\r\n      break;\r\n    case kpidAttributes:\r\n      propVariant = (UInt32)_fileInfo.Attributes;\r\n      break;\r\n    case kpidLastAccessTime:\r\n      propVariant = _fileInfo.LastAccessTime;\r\n      break;\r\n    case kpidCreationTime:\r\n      propVariant = _fileInfo.CreationTime;\r\n      break;\r\n    case kpidLastWriteTime:\r\n      propVariant = _fileInfo.LastWriteTime;\r\n      break;\r\n    }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nint COpenCallbackImp::FindName(const UString &name)\r\n{\r\n  for (int i = 0; i < FileNames.Size(); i++)\r\n    if (name.CompareNoCase(FileNames[i]) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstruct CInFileStreamVol: public CInFileStream\r\n{\r\n  UString Name;\r\n  COpenCallbackImp *OpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;\r\n  ~CInFileStreamVol()\r\n  {\r\n    int index = OpenCallbackImp->FindName(Name);\r\n    if (index >= 0)\r\n      OpenCallbackImp->FileNames.Delete(index);\r\n  }\r\n};\r\n\r\nSTDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (_subArchiveMode)\r\n    return S_FALSE;\r\n  if (Callback)\r\n  {\r\n    RINOK(Callback->CheckBreak());\r\n  }\r\n  *inStream = NULL;\r\n  UString fullPath = _folderPrefix + name;\r\n  if (!NFile::NFind::FindFile(fullPath, _fileInfo))\r\n    return S_FALSE;\r\n  if (_fileInfo.IsDirectory())\r\n    return S_FALSE;\r\n  CInFileStreamVol *inFile = new CInFileStreamVol;\r\n  CMyComPtr<IInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(fullPath))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  inFile->Name = name;\r\n  inFile->OpenCallbackImp = this;\r\n  inFile->OpenCallbackRef = this;\r\n  FileNames.Add(name);\r\n  TotalSize += _fileInfo.Size;\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!Callback)\r\n    return E_NOTIMPL;\r\n  return Callback->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n#endif\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h",
    "content": "// ArchiveOpenCallback.h\r\n\r\n#ifndef __ARCHIVE_OPEN_CALLBACK_H\r\n#define __ARCHIVE_OPEN_CALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#ifndef _NO_CRYPTO\r\n#include \"../../IPassword.h\"\r\n#endif  \r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct IOpenCallbackUI\r\n{\r\n  virtual HRESULT CheckBreak() = 0;\r\n  virtual HRESULT SetTotal(const UInt64 *files, const UInt64 *bytes) = 0;\r\n  virtual HRESULT SetCompleted(const UInt64 *files, const UInt64 *bytes) = 0;\r\n  #ifndef _NO_CRYPTO\r\n  virtual HRESULT CryptoGetTextPassword(BSTR *password) = 0;\r\n  virtual HRESULT GetPasswordIfAny(UString &password) = 0;\r\n  virtual bool WasPasswordAsked() = 0;\r\n  virtual void ClearPasswordWasAskedFlag() = 0;\r\n  #endif  \r\n};\r\n\r\nclass COpenCallbackImp: \r\n  public IArchiveOpenCallback,\r\n  public IArchiveOpenVolumeCallback,\r\n  public IArchiveOpenSetSubArchiveName,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif  \r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifndef _NO_CRYPTO\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveOpenVolumeCallback, \r\n      ICryptoGetTextPassword,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      IArchiveOpenVolumeCallback, \r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #endif\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  // IArchiveOpenVolumeCallback\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream);\r\n\r\n  #ifndef _NO_CRYPTO\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n  #endif\r\n\r\n  STDMETHOD(SetSubArchiveName(const wchar_t *name))\r\n  {\r\n    _subArchiveMode = true;\r\n    _subArchiveName = name;\r\n    return  S_OK;\r\n  }\r\n\r\nprivate:\r\n  UString _folderPrefix;\r\n  NWindows::NFile::NFind::CFileInfoW _fileInfo;\r\n  bool _subArchiveMode;\r\n  UString _subArchiveName;\r\npublic:\r\n  UStringVector FileNames;\r\n  IOpenCallbackUI *Callback;\r\n  UInt64 TotalSize;\r\n\r\n  COpenCallbackImp(): Callback(NULL) {}\r\n  void Init(const UString &folderPrefix,  const UString &fileName)\r\n  {\r\n    _folderPrefix = folderPrefix;\r\n    if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))\r\n      throw 1;\r\n    FileNames.Clear();\r\n    _subArchiveMode = false;\r\n    TotalSize = 0;\r\n  }\r\n  int FindName(const UString &name);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/DefaultName.cpp",
    "content": "// DefaultName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nUString GetDefaultName2(const UString &fileName, \r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  int extLength = extension.Length();\r\n  int fileNameLength = fileName.Length();\r\n  if (fileNameLength > extLength + 1)\r\n  {\r\n    int dotPos = fileNameLength - (extLength + 1);\r\n    if (fileName[dotPos] == '.')\r\n      if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)\r\n        return fileName.Left(dotPos) + addSubExtension;\r\n  }\r\n  int dotPos = fileName.ReverseFind(L'.');\r\n  if (dotPos > 0)\r\n    return fileName.Left(dotPos) + addSubExtension;\r\n  return kEmptyFileAlias;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/DefaultName.h",
    "content": "// DefaultName.h\r\n\r\n#ifndef __DEFAULTNAME_H\r\n#define __DEFAULTNAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString GetDefaultName2(const UString &fileName, \r\n    const UString &extension, const UString &addSubExtension);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/DirItem.h",
    "content": "// DirItem.h\r\n\r\n#ifndef __DIR_ITEM_H\r\n#define __DIR_ITEM_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nstruct CDirItem\r\n{ \r\n  UInt32 Attributes;\r\n  FILETIME CreationTime;\r\n  FILETIME LastAccessTime;\r\n  FILETIME LastWriteTime;\r\n  UInt64 Size;\r\n  UString Name;\r\n  UString FullPath;\r\n  bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nstruct CArchiveItem\r\n{ \r\n  bool IsDirectory;\r\n  // DWORD Attributes;\r\n  // NWindows::NCOM::CPropVariant LastWriteTime;\r\n  FILETIME LastWriteTime;\r\n  bool SizeIsDefined;\r\n  UInt64 Size;\r\n  UString Name;\r\n  bool Censored;\r\n  int IndexInServer;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/EnumDirItems.cpp",
    "content": "// EnumDirItems.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nvoid AddDirFileInfo(\r\n    const UString &prefix,        // prefix for logical path\r\n    const UString &fullPathName,  // path on disk: can be relative to some basePrefix\r\n    const NFind::CFileInfoW &fileInfo, \r\n    CObjectVector<CDirItem> &dirItems)\r\n{\r\n  CDirItem item;\r\n  item.Attributes = fileInfo.Attributes;\r\n  item.Size = fileInfo.Size;\r\n  item.CreationTime = fileInfo.CreationTime;\r\n  item.LastAccessTime = fileInfo.LastAccessTime;\r\n  item.LastWriteTime = fileInfo.LastWriteTime;\r\n  item.Name = prefix + fileInfo.Name;\r\n  item.FullPath = fullPathName;\r\n  dirItems.Add(item);\r\n}\r\n\r\nstatic void EnumerateDirectory(\r\n    const UString &baseFolderPrefix,  // base (disk) prefix for scanning  \r\n    const UString &directory,         // additional disk prefix starting from baseFolderPrefix\r\n    const UString &prefix,            // logical prefix\r\n    CObjectVector<CDirItem> &dirItems,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  NFind::CEnumeratorW enumerator(baseFolderPrefix + directory + wchar_t(kAnyStringWildcard));\r\n  for (;;)\r\n  { \r\n    NFind::CFileInfoW fileInfo;\r\n    bool found;\r\n    if (!enumerator.Next(fileInfo, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(baseFolderPrefix + directory);\r\n      return;\r\n    }\r\n    if (!found)\r\n      break;\r\n    AddDirFileInfo(prefix, directory + fileInfo.Name, fileInfo, dirItems);\r\n    if (fileInfo.IsDirectory())\r\n    {\r\n      EnumerateDirectory(baseFolderPrefix, directory + fileInfo.Name + wchar_t(kDirDelimiter), \r\n          prefix + fileInfo.Name + wchar_t(kDirDelimiter), dirItems, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nvoid EnumerateDirItems(\r\n    const UString &baseFolderPrefix,   // base (disk) prefix for scanning  \r\n    const UStringVector &fileNames,    // names relative to baseFolderPrefix\r\n    const UString &archiveNamePrefix, \r\n    CObjectVector<CDirItem> &dirItems,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for(int i = 0; i < fileNames.Size(); i++)\r\n  {\r\n    const UString &fileName = fileNames[i];\r\n    NFind::CFileInfoW fileInfo;\r\n    if (!NFind::FindFile(baseFolderPrefix + fileName, fileInfo))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(baseFolderPrefix + fileName);\r\n      continue;\r\n    }\r\n    AddDirFileInfo(archiveNamePrefix, fileName, fileInfo, dirItems);\r\n    if (fileInfo.IsDirectory())\r\n    {\r\n      EnumerateDirectory(baseFolderPrefix, fileName + wchar_t(kDirDelimiter), \r\n          archiveNamePrefix + fileInfo.Name +  wchar_t(kDirDelimiter), \r\n          dirItems, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nstatic HRESULT EnumerateDirItems(\r\n    const NWildcard::CCensorNode &curNode, \r\n    const UString &diskPrefix,        // full disk path prefix \r\n    const UString &archivePrefix,     // prefix from root\r\n    const UStringVector &addArchivePrefix,  // prefix from curNode\r\n    CObjectVector<CDirItem> &dirItems, \r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  if (!enterToSubFolders)\r\n    if (curNode.NeedCheckSubDirs())\r\n      enterToSubFolders = true;\r\n  if (callback)\r\n    RINOK(callback->CheckBreak());\r\n\r\n  // try direct_names case at first\r\n  if (addArchivePrefix.IsEmpty() && !enterToSubFolders)\r\n  {\r\n    // check that all names are direct\r\n    int i;\r\n    for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n    {\r\n      const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n      if (item.Recursive || item.PathParts.Size() != 1)\r\n        break;\r\n      const UString &name = item.PathParts.Front();\r\n      if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n        break;\r\n    }\r\n    if (i == curNode.IncludeItems.Size())\r\n    {\r\n      // all names are direct (no wildcards)\r\n      // so we don't need file_system's dir enumerator\r\n      CRecordVector<bool> needEnterVector;\r\n      for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n      {\r\n        const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n        const UString &name = item.PathParts.Front();\r\n        const UString fullPath = diskPrefix + name;\r\n        NFind::CFileInfoW fileInfo;\r\n        if (!NFind::FindFile(fullPath, fileInfo))\r\n        {\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        bool isDir = fileInfo.IsDirectory();\r\n        if (isDir && !item.ForDir || !isDir && !item.ForFile)\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        const UString realName = fileInfo.Name;\r\n        const UString realDiskPath = diskPrefix + realName;\r\n        {\r\n          UStringVector pathParts;\r\n          pathParts.Add(fileInfo.Name);\r\n          if (curNode.CheckPathToRoot(false, pathParts, !isDir))\r\n            continue;\r\n        }\r\n        AddDirFileInfo(archivePrefix, realDiskPath, fileInfo, dirItems);\r\n        if (!isDir)\r\n          continue;\r\n        \r\n        UStringVector addArchivePrefixNew;\r\n        const NWildcard::CCensorNode *nextNode = 0;\r\n        int index = curNode.FindSubNode(name);\r\n        if (index >= 0)\r\n        {\r\n          for (int t = needEnterVector.Size(); t <= index; t++)\r\n            needEnterVector.Add(true);\r\n          needEnterVector[index] = false;\r\n          nextNode = &curNode.SubNodes[index];\r\n        }\r\n        else\r\n        {\r\n          nextNode = &curNode;\r\n          addArchivePrefixNew.Add(name); // don't change it to realName. It's for shortnames support\r\n        }\r\n        RINOK(EnumerateDirItems(*nextNode,   \r\n            realDiskPath + wchar_t(kDirDelimiter), \r\n            archivePrefix + realName + wchar_t(kDirDelimiter), \r\n            addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes));\r\n      }\r\n      for (i = 0; i < curNode.SubNodes.Size(); i++)\r\n      {\r\n        if (i < needEnterVector.Size())\r\n          if (!needEnterVector[i])\r\n            continue;\r\n        const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];\r\n        const UString fullPath = diskPrefix + nextNode.Name;\r\n        NFind::CFileInfoW fileInfo;\r\n        if (!NFind::FindFile(fullPath, fileInfo))\r\n        {\r\n          if (!nextNode.AreThereIncludeItems())\r\n            continue;\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        if (!fileInfo.IsDirectory())\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        RINOK(EnumerateDirItems(nextNode, \r\n            diskPrefix + fileInfo.Name + wchar_t(kDirDelimiter), \r\n            archivePrefix + fileInfo.Name + wchar_t(kDirDelimiter), \r\n            UStringVector(), dirItems, false, callback, errorPaths, errorCodes));\r\n      }\r\n      return S_OK;\r\n    }\r\n  }\r\n\r\n\r\n  NFind::CEnumeratorW enumerator(diskPrefix + wchar_t(kAnyStringWildcard));\r\n  for (;;)\r\n  {\r\n    NFind::CFileInfoW fileInfo;\r\n    bool found;\r\n    if (!enumerator.Next(fileInfo, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(diskPrefix);\r\n      break;\r\n    }\r\n    if (!found)\r\n      break;\r\n\r\n    if (callback)\r\n      RINOK(callback->CheckBreak());\r\n    const UString &name = fileInfo.Name;\r\n    bool enterToSubFolders2 = enterToSubFolders;\r\n    UStringVector addArchivePrefixNew = addArchivePrefix;\r\n    addArchivePrefixNew.Add(name);\r\n    {\r\n      UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);\r\n      if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fileInfo.IsDirectory()))\r\n        continue;\r\n    }\r\n    if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fileInfo.IsDirectory()))\r\n    {\r\n      AddDirFileInfo(archivePrefix, diskPrefix + name, fileInfo, dirItems);\r\n      if (fileInfo.IsDirectory())\r\n        enterToSubFolders2 = true;\r\n    }\r\n    if (!fileInfo.IsDirectory())\r\n      continue;\r\n\r\n    const NWildcard::CCensorNode *nextNode = 0;\r\n    if (addArchivePrefix.IsEmpty())\r\n    {\r\n      int index = curNode.FindSubNode(name);\r\n      if (index >= 0)\r\n        nextNode = &curNode.SubNodes[index];\r\n    }\r\n    if (!enterToSubFolders2 && nextNode == 0)\r\n      continue;\r\n\r\n    addArchivePrefixNew = addArchivePrefix;\r\n    if (nextNode == 0)\r\n    {\r\n      nextNode = &curNode;\r\n      addArchivePrefixNew.Add(name);\r\n    }\r\n    RINOK(EnumerateDirItems(*nextNode,   \r\n        diskPrefix + name + wchar_t(kDirDelimiter), \r\n        archivePrefix + name + wchar_t(kDirDelimiter), \r\n        addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor, \r\n    CObjectVector<CDirItem> &dirItems, \r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    const NWildcard::CPair &pair = censor.Pairs[i];\r\n    RINOK(EnumerateDirItems(pair.Head, pair.Prefix, L\"\", UStringVector(), dirItems, false, \r\n        callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/EnumDirItems.h",
    "content": "// EnumDirItems.h\r\n\r\n#ifndef __ENUM_DIR_ITEMS_H\r\n#define __ENUM_DIR_ITEMS_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"DirItem.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n\r\nvoid AddDirFileInfo(\r\n    const UString &prefix, \r\n    const UString &fullPathName,\r\n    const NWindows::NFile::NFind::CFileInfoW &fileInfo, \r\n    CObjectVector<CDirItem> &dirItems);\r\n\r\n\r\nvoid EnumerateDirItems(\r\n    const UString &baseFolderPrefix,\r\n    const UStringVector &fileNames,\r\n    const UString &archiveNamePrefix, \r\n    CObjectVector<CDirItem> &dirItems, \r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\nstruct IEnumDirItemCallback\r\n{\r\n  virtual HRESULT CheckBreak() { return  S_OK; }\r\n};\r\n\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor, \r\n    CObjectVector<CDirItem> &dirItems, \r\n    IEnumDirItemCallback *callback, \r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ExitCode.h",
    "content": "// ExitCode.h\r\n\r\n#ifndef __EXIT_CODE_H\r\n#define __EXIT_CODE_H\r\n\r\nnamespace NExitCode {\r\n\r\nenum EEnum {\r\n\r\n  kSuccess       = 0,     // Successful operation\r\n  kWarning       = 1,     // Non fatal error(s) occurred\r\n  kFatalError    = 2,     // A fatal error occurred\r\n  // kCRCError      = 3,     // A CRC error occurred when unpacking     \r\n  // kLockedArchive = 4,     // Attempt to modify an archive previously locked\r\n  // kWriteError    = 5,     // Write to disk error\r\n  // kOpenError     = 6,     // Open file error\r\n  kUserError     = 7,     // Command line option error\r\n  kMemoryError   = 8,     // Not enough memory for operation\r\n  // kCreateFileError = 9,     // Create file error\r\n  \r\n  kUserBreak     = 255   // User stopped the process\r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/Extract.cpp",
    "content": "// Extract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Extract.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n#include \"SetProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT DecompressArchive(\r\n    IInArchive *archive,\r\n    UInt64 packSize,\r\n    const UString &defaultName,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IExtractCallbackUI *callback,\r\n    CArchiveExtractCallback *extractCallbackSpec,\r\n    UString &errorMessage)\r\n{\r\n  CRecordVector<UInt32> realIndices;\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UString filePath;\r\n    RINOK(GetArchiveItemPath(archive, i, options.DefaultItemName, filePath));\r\n    bool isFolder;\r\n    RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n    if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n      continue;\r\n    realIndices.Add(i);\r\n  }\r\n  if (realIndices.Size() == 0)\r\n  {\r\n    callback->ThereAreNoFiles();\r\n    return S_OK;\r\n  }\r\n\r\n  UStringVector removePathParts;\r\n\r\n  UString outDir = options.OutputDir;\r\n  outDir.Replace(L\"*\", defaultName);\r\n  if(!outDir.IsEmpty())\r\n    if(!NFile::NDirectory::CreateComplexDirectory(outDir))\r\n    {\r\n      HRESULT res = ::GetLastError();\r\n      if (res == S_OK)\r\n        res = E_FAIL;\r\n      errorMessage = ((UString)L\"Can not create output directory \") + outDir;\r\n      return res;\r\n    }\r\n\r\n  extractCallbackSpec->Init(\r\n      archive, \r\n      callback,\r\n      options.StdOutMode,\r\n      outDir, \r\n      removePathParts, \r\n      options.DefaultItemName, \r\n      options.ArchiveFileInfo.LastWriteTime,\r\n      options.ArchiveFileInfo.Attributes,\r\n      packSize);\r\n\r\n  #ifdef COMPRESS_MT\r\n  RINOK(SetProperties(archive, options.Properties));\r\n  #endif\r\n\r\n  HRESULT result = archive->Extract(&realIndices.Front(), \r\n    realIndices.Size(), options.TestMode? 1: 0, extractCallbackSpec);\r\n\r\n  return callback->ExtractResult(result);\r\n}\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,    \r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &optionsSpec,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback, \r\n    UString &errorMessage, \r\n    CDecompressStat &stat)\r\n{\r\n  stat.Clear();\r\n  CExtractOptions options = optionsSpec;\r\n  int i;\r\n  UInt64 totalPackSize = 0;\r\n  CRecordVector<UInt64> archiveSizes;\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW archiveFileInfo;\r\n    if (!NFile::NFind::FindFile(archivePath, archiveFileInfo))\r\n      throw \"there is no such archive\";\r\n    if (archiveFileInfo.IsDirectory())\r\n      throw \"can't decompress folder\";\r\n    archiveSizes.Add(archiveFileInfo.Size);\r\n    totalPackSize += archiveFileInfo.Size;\r\n  }\r\n  CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n  CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);\r\n  bool multi = (archivePaths.Size() > 1);\r\n  extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);\r\n  if (multi)\r\n  {\r\n    RINOK(extractCallback->SetTotal(totalPackSize));  \r\n  }\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW archiveFileInfo;\r\n    if (!NFile::NFind::FindFile(archivePath, archiveFileInfo))\r\n      throw \"there is no such archive\";\r\n\r\n    if (archiveFileInfo.IsDirectory())\r\n      throw \"there is no such archive\";\r\n\r\n    options.ArchiveFileInfo = archiveFileInfo;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    openCallback->ClearPasswordWasAskedFlag();\r\n    #endif\r\n\r\n    RINOK(extractCallback->BeforeOpen(archivePath));\r\n    CArchiveLink archiveLink;\r\n    HRESULT result = MyOpenArchive(codecs, archivePath, archiveLink, openCallback);\r\n\r\n    bool crypted = false;\r\n    #ifndef _NO_CRYPTO\r\n    crypted = openCallback->WasPasswordAsked();\r\n    #endif\r\n\r\n    RINOK(extractCallback->OpenResult(archivePath, result, crypted));\r\n    if (result != S_OK)\r\n      continue;\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n        totalPackSize -= archiveSizes[index];\r\n        archiveSizes.Delete(index);\r\n      }\r\n    }\r\n    if (archiveLink.VolumePaths.Size() != 0)\r\n    {\r\n      totalPackSize += archiveLink.VolumesSize;\r\n      RINOK(extractCallback->SetTotal(totalPackSize));  \r\n    }\r\n\r\n    #ifndef _NO_CRYPTO\r\n    UString password;\r\n    RINOK(openCallback->GetPasswordIfAny(password));\r\n    if (!password.IsEmpty())\r\n    {\r\n      RINOK(extractCallback->SetPassword(password));\r\n    }\r\n    #endif\r\n\r\n    options.DefaultItemName = archiveLink.GetDefaultItemName();\r\n    RINOK(DecompressArchive(\r\n        archiveLink.GetArchive(), \r\n        archiveFileInfo.Size + archiveLink.VolumesSize,\r\n        archiveLink.GetDefaultItemName(),\r\n        wildcardCensor, options, extractCallback, extractCallbackSpec, errorMessage));\r\n    extractCallbackSpec->LocalProgressSpec->InSize += archiveFileInfo.Size + \r\n        archiveLink.VolumesSize;\r\n    extractCallbackSpec->LocalProgressSpec->OutSize = extractCallbackSpec->UnpackSize;\r\n    if (!errorMessage.IsEmpty())\r\n      return E_FAIL;\r\n  }\r\n  stat.NumFolders = extractCallbackSpec->NumFolders;\r\n  stat.NumFiles = extractCallbackSpec->NumFiles;\r\n  stat.UnpackSize = extractCallbackSpec->UnpackSize;\r\n  stat.NumArchives = archivePaths.Size();\r\n  stat.PackSize = extractCallbackSpec->LocalProgressSpec->InSize;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/Extract.h",
    "content": "// Extract.h\r\n\r\n#ifndef __EXTRACT_H\r\n#define __EXTRACT_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"ExtractMode.h\"\r\n#include \"Property.h\"\r\n\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nclass CExtractOptions\r\n{\r\npublic:\r\n  bool StdOutMode;\r\n  bool TestMode;\r\n  NExtract::NPathMode::EEnum PathMode;\r\n\r\n  UString OutputDir;\r\n  bool YesToAll;\r\n  UString DefaultItemName;\r\n  NWindows::NFile::NFind::CFileInfoW ArchiveFileInfo;\r\n  \r\n  // bool ShowDialog;\r\n  // bool PasswordEnabled;\r\n  // UString Password;\r\n  #ifdef COMPRESS_MT\r\n  CObjectVector<CProperty> Properties;\r\n  #endif\r\n\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  CCodecs *Codecs;\r\n  #endif\r\n\r\n  CExtractOptions(): \r\n      StdOutMode(false), \r\n      YesToAll(false), \r\n      TestMode(false),\r\n      PathMode(NExtract::NPathMode::kFullPathnames),\r\n      OverwriteMode(NExtract::NOverwriteMode::kAskBefore)\r\n      {}\r\n\r\n  /*\r\n    bool FullPathMode() const { return (ExtractMode == NExtractMode::kTest) || \r\n    (ExtractMode == NExtractMode::kFullPath); }\r\n  */\r\n};\r\n\r\nstruct CDecompressStat\r\n{\r\n  UInt64 NumArchives;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  void Clear() { NumArchives = PackSize = UnpackSize = NumFolders = NumFiles = 0; }\r\n};\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage, \r\n    CDecompressStat &stat);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ExtractMode.h",
    "content": "// ExtractMode.h\r\n\r\n#ifndef __EXTRACT_MODE_H\r\n#define __EXTRACT_MODE_H\r\n\r\nnamespace NExtract {\r\n  \r\n  namespace NPathMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kFullPathnames,\r\n      kCurrentPathnames,\r\n      kNoPathnames\r\n    };\r\n  }\r\n  \r\n  namespace NOverwriteMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kAskBefore,\r\n      kWithoutPrompt,\r\n      kSkipExisting,\r\n      kAutoRename,\r\n      kAutoRenameExisting\r\n    };\r\n  }\r\n}  \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp",
    "content": "// ExtractingFilePath.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ExtractingFilePath.h\"\r\n\r\nstatic UString ReplaceIncorrectChars(const UString &s)\r\n{\r\n  #ifdef _WIN32\r\n  UString res;\r\n  for (int i = 0; i < s.Length(); i++)\r\n  {\r\n    wchar_t c = s[i];\r\n    if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>'  || c == '|' || c == ':' || c == '\"')\r\n      c = '_';\r\n    res += c;\r\n  }\r\n  return res;\r\n  #else\r\n  return s;\r\n  #endif\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t *g_ReservedNames[] =\r\n{\r\n  L\"CON\", L\"PRN\", L\"AUX\", L\"NUL\"\r\n};\r\n\r\nstatic bool CheckTail(const UString &name, int len)\r\n{\r\n  int dotPos = name.Find(L'.');\r\n  if (dotPos < 0)\r\n    dotPos = name.Length();\r\n  UString s = name.Left(dotPos);\r\n  s.TrimRight();\r\n  return (s.Length() != len);\r\n}\r\n\r\nstatic bool CheckNameNum(const UString &name, const wchar_t *reservedName)\r\n{\r\n  int len = MyStringLen(reservedName);\r\n  if (name.Length() <= len)\r\n    return true;\r\n  if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n    return true;\r\n  wchar_t c = name[len];\r\n  if (c < L'0' || c > L'9')\r\n    return true;\r\n  return CheckTail(name, len + 1);\r\n}\r\n\r\nstatic bool IsSupportedName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++)\r\n  {\r\n    const wchar_t *reservedName = g_ReservedNames[i];\r\n    int len = MyStringLen(reservedName);\r\n    if (name.Length() < len)\r\n      continue;\r\n    if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n      continue;\r\n    if (!CheckTail(name, len))\r\n      return false;\r\n  }\r\n  if (!CheckNameNum(name, L\"COM\"))\r\n    return false;\r\n  return CheckNameNum(name, L\"LPT\");\r\n}\r\n#endif\r\n\r\nstatic UString GetCorrectFileName(const UString &path)\r\n{\r\n  if (path == L\"..\" || path == L\".\")\r\n    return UString();\r\n  return ReplaceIncorrectChars(path);\r\n}\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts)\r\n{\r\n  for (int i = 0; i < pathParts.Size();)\r\n  {\r\n    UString &s = pathParts[i];\r\n    s = GetCorrectFileName(s);\r\n    if (s.IsEmpty())\r\n      pathParts.Delete(i);\r\n    else\r\n    {\r\n      #ifdef _WIN32\r\n      if (!IsSupportedName(s))\r\n        s = (UString)L\"_\" + s;\r\n      #endif\r\n      i++;\r\n    }\r\n  }\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ExtractingFilePath.h",
    "content": "// ExtractingFilePath.h\r\n\r\n#ifndef __EXTRACTINGFILEPATH_H\r\n#define __EXTRACTINGFILEPATH_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/IFileExtractCallback.h",
    "content": "// IFileExtractCallback.h\r\n\r\n#ifndef __IFILEEXTRACTCALLBACK_H\r\n#define __IFILEEXTRACTCALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"../../IDecl.h\"\r\n\r\nnamespace NOverwriteAnswer\r\n{\r\n  enum EEnum\r\n  {\r\n    kYes,\r\n    kYesToAll,\r\n    kNo,\r\n    kNoToAll,\r\n    kAutoRename,\r\n    kCancel\r\n  };\r\n}\r\n\r\nDECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)\r\n{\r\npublic:\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer) PURE;\r\n  STDMETHOD(PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position) PURE;\r\n  STDMETHOD(MessageError)(const wchar_t *message) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE;\r\n};\r\n\r\nstruct IExtractCallbackUI: IFolderArchiveExtractCallback\r\n{\r\n  virtual HRESULT BeforeOpen(const wchar_t *name) = 0;\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted) = 0;\r\n  virtual HRESULT ThereAreNoFiles() = 0;\r\n  virtual HRESULT ExtractResult(HRESULT result) = 0;\r\n  virtual HRESULT SetPassword(const UString &password) = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/LoadCodecs.cpp",
    "content": "// LoadCodecs.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LoadCodecs.h\"\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Common/StringToInt.h\"\r\n#endif\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/FileFind.h\"\r\n#include \"../../../Windows/DLL.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Windows/ResourceString.h\"\r\nstatic const UINT kIconTypesResId = 100;\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/Registry.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\n#ifdef _WIN32\r\nextern HINSTANCE g_hInstance;\r\n#endif\r\n\r\nstatic CSysString GetLibraryFolderPrefix()\r\n{\r\n  #ifdef _WIN32\r\n  TCHAR fullPath[MAX_PATH + 1];\r\n  ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);\r\n  CSysString path = fullPath;\r\n  int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  return path.Left(pos + 1);\r\n  #else\r\n  return CSysString(); // FIX IT\r\n  #endif\r\n}\r\n\r\n#define kCodecsFolderName TEXT(\"Codecs\")\r\n#define kFormatsFolderName TEXT(\"Formats\")\r\nstatic TCHAR *kMainDll = TEXT(\"7z.dll\");\r\n\r\n#ifdef _WIN32\r\nstatic LPCTSTR kRegistryPath = TEXT(\"Software\\\\7-zip\");\r\nstatic LPCTSTR kProgramPathValue = TEXT(\"Path\");\r\nstatic bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)\r\n{\r\n  NRegistry::CKey key;\r\n  if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)\r\n    if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)\r\n    {\r\n      NName::NormalizeDirPathPrefix(path);\r\n      return true;\r\n    }\r\n  return false;\r\n}\r\n\r\n#endif\r\n\r\nCSysString GetBaseFolderPrefixFromRegistry()\r\n{\r\n  CSysString moduleFolderPrefix = GetLibraryFolderPrefix();\r\n  NFind::CFileInfo fileInfo;\r\n  if (NFind::FindFile(moduleFolderPrefix + kMainDll, fileInfo))\r\n    if (!fileInfo.IsDirectory())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fileInfo))\r\n    if (fileInfo.IsDirectory())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fileInfo))\r\n    if (fileInfo.IsDirectory())\r\n      return moduleFolderPrefix;\r\n  #ifdef _WIN32\r\n  CSysString path;\r\n  if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))\r\n    return path;\r\n  if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))\r\n    return path;\r\n  #endif\r\n  return moduleFolderPrefix;\r\n}\r\n\r\ntypedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);\r\ntypedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, void **outObject);\r\ntypedef UInt32 (WINAPI *SetLargePageModeFunc)();\r\n\r\n\r\nstatic HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 index, \r\n    PROPID propId, CLSID &clsId, bool &isAssigned)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  isAssigned = false;\r\n  RINOK(getMethodProperty(index, propId, &prop));\r\n  if (prop.vt == VT_BSTR)\r\n  {\r\n    isAssigned = true;\r\n    clsId = *(const GUID *)prop.bstrVal;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::LoadCodecs()\r\n{\r\n  CCodecLib &lib = Libs.Back();\r\n  lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress(\"GetMethodProperty\");\r\n  if (lib.GetMethodProperty == NULL)\r\n    return S_OK;\r\n\r\n  UInt32 numMethods = 1;\r\n  GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProcAddress(\"GetNumberOfMethods\");\r\n  if (getNumberOfMethodsFunc != NULL)\r\n  {\r\n    RINOK(getNumberOfMethodsFunc(&numMethods));\r\n  }\r\n\r\n  for(UInt32 i = 0; i < numMethods; i++)\r\n  {\r\n    CDllCodecInfo info;\r\n    info.LibIndex = Libs.Size() - 1;\r\n    info.CodecIndex = i;\r\n\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));\r\n\r\n    Codecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadProp(\r\n    GetHandlerPropertyFunc getProp, \r\n    GetHandlerPropertyFunc2 getProp2, \r\n    UInt32 index, PROPID propID, NCOM::CPropVariant &prop)\r\n{\r\n  if (getProp2)\r\n    return getProp2(index, propID, &prop);;\r\n  return getProp(propID, &prop);\r\n}\r\n\r\nstatic HRESULT ReadBoolProp(\r\n    GetHandlerPropertyFunc getProp, \r\n    GetHandlerPropertyFunc2 getProp2, \r\n    UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadStringProp(\r\n    GetHandlerPropertyFunc getProp, \r\n    GetHandlerPropertyFunc2 getProp2, \r\n    UInt32 index, PROPID propID, UString &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BSTR)\r\n    res = prop.bstrVal;\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax]; \r\nvoid RegisterArc(const CArcInfo *arcInfo) \r\n{ \r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo; \r\n}\r\n\r\nstatic void SplitString(const UString &srcString, UStringVector &destStrings)\r\n{\r\n  destStrings.Clear();\r\n  UString s;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L' ')\r\n    {\r\n      if (!s.IsEmpty())\r\n      {\r\n        destStrings.Add(s);\r\n        s.Empty();\r\n      }\r\n    }\r\n    else\r\n      s += c;\r\n  }\r\n  if (!s.IsEmpty())\r\n    destStrings.Add(s);\r\n}\r\n\r\nvoid CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt)\r\n{\r\n  UStringVector exts, addExts;\r\n  SplitString(ext, exts);\r\n  if (addExt != 0)\r\n    SplitString(addExt, addExts);\r\n  for (int i = 0; i < exts.Size(); i++)\r\n  {\r\n    CArcExtInfo extInfo;\r\n    extInfo.Ext = exts[i];\r\n    if (i < addExts.Size())\r\n    {\r\n      extInfo.AddExt = addExts[i];\r\n      if (extInfo.AddExt == L\"*\")\r\n        extInfo.AddExt.Empty();\r\n    }\r\n    Exts.Add(extInfo);\r\n  }\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nHRESULT CCodecs::LoadFormats()\r\n{\r\n  const NDLL::CLibrary &lib = Libs.Back().Lib;\r\n  GetHandlerPropertyFunc getProp = 0;\r\n  GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)\r\n      lib.GetProcAddress(\"GetHandlerProperty2\");\r\n  if (getProp2 == NULL)\r\n  {\r\n    getProp = (GetHandlerPropertyFunc)\r\n        lib.GetProcAddress(\"GetHandlerProperty\");\r\n    if (getProp == NULL)\r\n      return S_OK;\r\n  }\r\n\r\n  UInt32 numFormats = 1;\r\n  GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)\r\n    lib.GetProcAddress(\"GetNumberOfFormats\");\r\n  if (getNumberOfFormats != NULL)\r\n  {\r\n    RINOK(getNumberOfFormats(&numFormats));\r\n  }\r\n  if (getProp2 == NULL)\r\n    numFormats = 1;\r\n\r\n  for(UInt32 i = 0; i < numFormats; i++)\r\n  {\r\n    CArcInfoEx item;\r\n    item.LibIndex = Libs.Size() - 1;\r\n    item.FormatIndex = i;\r\n\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)\r\n      continue;\r\n    if (prop.vt != VT_BSTR)\r\n      continue;\r\n    item.ClassID = *(const GUID *)prop.bstrVal;\r\n    prop.Clear();\r\n\r\n    UString ext, addExt;\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));\r\n    item.AddExts(ext, addExt);\r\n\r\n    ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);\r\n    if (item.UpdateEnabled)\r\n      ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);\r\n    \r\n    if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)\r\n      if (prop.vt == VT_BSTR)\r\n      {\r\n        UINT len = ::SysStringByteLen(prop.bstrVal);\r\n        item.StartSignature.SetCapacity(len);\r\n        memmove(item.StartSignature, prop.bstrVal, len);\r\n      }\r\n    Formats.Add(item);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef NEW_FOLDER_INTERFACE\r\nvoid CCodecLib::LoadIcons()\r\n{\r\n  UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId);\r\n  UStringVector pairs;\r\n  SplitString(iconTypes, pairs);\r\n  for (int i = 0; i < pairs.Size(); i++)\r\n  {\r\n    const UString &s = pairs[i];\r\n    int pos = s.Find(L':');\r\n    if (pos < 0)\r\n      continue;\r\n    CIconPair iconPair;\r\n    const wchar_t *end;\r\n    UString num = s.Mid(pos + 1);\r\n    iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);\r\n    if (*end != L'\\0')\r\n      continue;\r\n    iconPair.Ext = s.Left(pos);\r\n    IconPairs.Add(iconPair);\r\n  }\r\n}\r\n\r\nint CCodecLib::FindIconIndex(const UString &ext) const\r\n{\r\n  for (int i = 0; i < IconPairs.Size(); i++)\r\n  {\r\n    const CIconPair &pair = IconPairs[i];\r\n    if (ext.CompareNoCase(pair.Ext) == 0)\r\n      return pair.IconIndex;\r\n  }\r\n  return -1;\r\n}\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nextern \"C\" \r\n{\r\n  extern SIZE_T g_LargePageSize;\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::LoadDll(const CSysString &dllPath)\r\n{\r\n  {\r\n    NDLL::CLibrary library;\r\n    if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))\r\n      return S_OK;\r\n  }\r\n  Libs.Add(CCodecLib());\r\n  CCodecLib &lib = Libs.Back();\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  lib.Path = dllPath;\r\n  #endif\r\n  bool used = false;\r\n  HRESULT res = S_OK;\r\n  if (lib.Lib.Load(dllPath))\r\n  {\r\n    #ifdef NEW_FOLDER_INTERFACE\r\n    lib.LoadIcons();\r\n    #endif\r\n\r\n    #ifdef _7ZIP_LARGE_PAGES\r\n    if (g_LargePageSize != 0)\r\n    {\r\n      SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProcAddress(\"SetLargePageMode\");\r\n      if (setLargePageMode != 0)\r\n        setLargePageMode();\r\n    }\r\n    #endif\r\n\r\n    lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress(\"CreateObject\");\r\n    if (lib.CreateObject != 0)\r\n    {\r\n      int startSize = Codecs.Size();\r\n      res = LoadCodecs();\r\n      used = (Codecs.Size() != startSize);\r\n      if (res == S_OK)\r\n      {\r\n        startSize = Formats.Size();\r\n        res = LoadFormats();\r\n        used = used || (Formats.Size() != startSize);\r\n      }\r\n    }\r\n  }\r\n  if (!used)\r\n    Libs.DeleteBack();\r\n  return res;\r\n}\r\n\r\nHRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)\r\n{\r\n  NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT(\"*\")));\r\n  NFile::NFind::CFileInfo fileInfo;\r\n  while (enumerator.Next(fileInfo))\r\n  {\r\n    if (fileInfo.IsDirectory())\r\n      continue;\r\n    RINOK(LoadDll(folderPrefix + fileInfo.Name));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n#ifndef _SFX\r\nstatic inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)\r\n{\r\n  bb.SetCapacity(size);\r\n  memmove((Byte *)bb, data, size);\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::Load()\r\n{\r\n  Formats.Clear();\r\n  #ifdef EXTERNAL_CODECS\r\n  Codecs.Clear();\r\n  #endif\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n  {\r\n    const CArcInfo &arc = *g_Arcs[i];\r\n    CArcInfoEx item;\r\n    item.Name = arc.Name;\r\n    item.CreateInArchive = arc.CreateInArchive;\r\n    item.CreateOutArchive = arc.CreateOutArchive;\r\n    item.AddExts(arc.Ext, arc.AddExt);\r\n    item.UpdateEnabled = (arc.CreateOutArchive != 0);\r\n    item.KeepName = arc.KeepName;\r\n\r\n    #ifndef _SFX\r\n    SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);\r\n    #endif\r\n    Formats.Add(item);\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();\r\n  RINOK(LoadDll(baseFolder + kMainDll));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveName(const UString &archivePath) const\r\n{\r\n  int slashPos1 = archivePath.ReverseFind(L'\\\\');\r\n  int slashPos2 = archivePath.ReverseFind(L'.');\r\n  int dotPos = archivePath.ReverseFind(L'.');\r\n  if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)\r\n    return -1;\r\n  UString ext = archivePath.Mid(dotPos + 1);\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    // if (arc.FindExtension(ext) >= 0)\r\n    UString mainExt = arc.GetMainExt();\r\n    if (!mainExt.IsEmpty() && ext.CompareNoCase(mainExt) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveType(const UString &arcType) const\r\n{\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    if (arc.Name.CompareNoCase(arcType) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\n#ifdef EXPORT_CODECS\r\nextern unsigned int g_NumCodecs;\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);\r\n// STDAPI GetNumberOfMethods(UINT32 *numCodecs);\r\n#endif\r\n\r\nSTDMETHODIMP CCodecs::GetNumberOfMethods(UINT32 *numMethods)\r\n{\r\n  *numMethods = \r\n      #ifdef EXPORT_CODECS\r\n      g_NumCodecs + \r\n      #endif\r\n      Codecs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::GetProperty(UINT32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return GetMethodProperty(index, propID, value);\r\n  #endif\r\n\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n\r\n  if (propID == NMethodPropID::kDecoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.DecoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  if (propID == NMethodPropID::kEncoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.EncoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateDecoder(UINT32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(false, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.DecoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateEncoder(UINT32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(true, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.EncoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const\r\n{ \r\n  for (int i = 0; i < Codecs.Size(); i++)\r\n  {\r\n    const CDllCodecInfo &codec = Codecs[i];\r\n    if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigned)\r\n      continue;\r\n    const CCodecLib &lib = Libs[codec.LibIndex];\r\n    UString res;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      res = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      continue;\r\n    if (name.CompareNoCase(res) == 0)\r\n      return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICompressCoder, (void **)&coder);\r\n  }\r\n  return CLASS_E_CLASSNOTAVAILABLE;\r\n}\r\n\r\nint CCodecs::GetCodecLibIndex(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return -1;\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.LibIndex;\r\n  #else\r\n  return -1;\r\n  #endif\r\n}\r\n\r\nbool CCodecs::GetCodecEncoderIsAssigned(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n  {\r\n    NWindows::NCOM::CPropVariant prop;\r\n    if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK)\r\n      if (prop.vt != VT_EMPTY)\r\n        return true;\r\n    return false;\r\n  }\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index \r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.EncoderIsAssigned;\r\n  #else\r\n  return false;\r\n  #endif\r\n}\r\n\r\nHRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(GetProperty(index, NMethodPropID::kID, &prop));\r\n  if (prop.vt != VT_UI8)\r\n    return E_INVALIDARG;\r\n  id = prop.uhVal.QuadPart;\r\n  return S_OK;\r\n}\r\n\r\nUString CCodecs::GetCodecName(UInt32 index)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK)\r\n    if (prop.vt == VT_BSTR)\r\n      s = prop.bstrVal;\r\n  return s;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/LoadCodecs.h",
    "content": "// LoadCodecs.h\r\n\r\n#ifndef __LOADCODECS_H\r\n#define __LOADCODECS_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/DLL.h\"\r\n#endif\r\n\r\nstruct CDllCodecInfo\r\n{\r\n  CLSID Encoder;\r\n  CLSID Decoder;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  int LibIndex;\r\n  UInt32 CodecIndex;\r\n};\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcExtInfo\r\n{\r\n  UString Ext;\r\n  UString AddExt;\r\n  CArcExtInfo() {}\r\n  CArcExtInfo(const UString &ext): Ext(ext) {}\r\n  CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}\r\n};\r\n\r\n\r\nstruct CArcInfoEx\r\n{\r\n  #ifdef EXTERNAL_CODECS\r\n  int LibIndex;\r\n  UInt32 FormatIndex;\r\n  CLSID ClassID;\r\n  #endif\r\n  bool UpdateEnabled;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n  UString Name;\r\n  CObjectVector<CArcExtInfo> Exts;\r\n  #ifndef _SFX\r\n  CByteBuffer StartSignature;\r\n  // CByteBuffer FinishSignature;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  UStringVector AssociateExts;\r\n  #endif\r\n  #endif\r\n  bool KeepName;\r\n  UString GetMainExt() const\r\n  {\r\n    if (Exts.IsEmpty())\r\n      return UString();\r\n    return Exts[0].Ext;\r\n  }\r\n  int FindExtension(const UString &ext) const\r\n  {\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n      if (ext.CompareNoCase(Exts[i].Ext) == 0)\r\n        return i;\r\n    return -1;\r\n  }\r\n  UString GetAllExtensions() const\r\n  {\r\n    UString s;\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n    {\r\n      if (i > 0)\r\n        s += ' ';\r\n      s += Exts[i].Ext;\r\n    }\r\n    return s;\r\n  }\r\n\r\n  void AddExts(const wchar_t* ext, const wchar_t* addExt);\r\n\r\n  CArcInfoEx(): \r\n    #ifdef EXTERNAL_CODECS\r\n    LibIndex(-1),\r\n    #endif\r\n    UpdateEnabled(false),\r\n    CreateInArchive(0), CreateOutArchive(0),\r\n    KeepName(false)\r\n    #ifndef _SFX\r\n    #endif\r\n  {}\r\n};\r\n\r\n#ifdef EXTERNAL_CODECS\r\ntypedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);\r\n\r\n\r\nstruct CCodecLib\r\n{\r\n  NWindows::NDLL::CLibrary Lib;\r\n  GetMethodPropertyFunc GetMethodProperty;\r\n  CreateObjectFunc CreateObject;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  struct CIconPair\r\n  {\r\n    UString Ext;\r\n    UInt32 IconIndex;\r\n  };\r\n  CSysString Path;\r\n  CObjectVector<CIconPair> IconPairs;\r\n  void LoadIcons();\r\n  int FindIconIndex(const UString &ext) const;\r\n  #endif\r\n  CCodecLib(): GetMethodProperty(0) {}\r\n};\r\n#endif\r\n\r\nclass CCodecs:\r\n  #ifdef EXTERNAL_CODECS\r\n  public ICompressCodecsInfo,\r\n  #else\r\n  public IUnknown,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:  \r\n  #ifdef EXTERNAL_CODECS\r\n  CObjectVector<CCodecLib> Libs;\r\n  CObjectVector<CDllCodecInfo> Codecs;\r\n  HRESULT LoadCodecs();\r\n  HRESULT LoadFormats();\r\n  HRESULT LoadDll(const CSysString &path);\r\n  HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);\r\n\r\n  HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const\r\n  {\r\n    return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);\r\n  }\r\n  #endif\r\n\r\npublic:\r\n  CObjectVector<CArcInfoEx> Formats;\r\n  HRESULT Load();\r\n  int FindFormatForArchiveName(const UString &archivePath) const;\r\n  int FindFormatForArchiveType(const UString &arcType) const;\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  STDMETHOD(GetNumberOfMethods)(UINT32 *numMethods);\r\n  STDMETHOD(GetProperty)(UINT32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(CreateDecoder)(UINT32 index, const GUID *interfaceID, void **coder);\r\n  STDMETHOD(CreateEncoder)(UINT32 index, const GUID *interfaceID, void **coder);\r\n  #endif\r\n\r\n  int GetCodecLibIndex(UInt32 index);\r\n  bool GetCodecEncoderIsAssigned(UInt32 index);\r\n  HRESULT GetCodecId(UInt32 index, UInt64 &id);\r\n  UString GetCodecName(UInt32 index);\r\n\r\n  HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const\r\n  { \r\n    const CArcInfoEx &ai = Formats[formatIndex]; \r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateInArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, false); \r\n    #endif\r\n  }\r\n  HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const\r\n  { \r\n    const CArcInfoEx &ai = Formats[formatIndex]; \r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateOutArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, true); \r\n    #endif\r\n  }\r\n  int FindOutFormatFromName(const UString &name) const\r\n  {\r\n    for (int i = 0; i < Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = Formats[i];\r\n      if (!arc.UpdateEnabled)\r\n        continue;\r\n      if (arc.Name.CompareNoCase(name) == 0)\r\n        return i;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;\r\n  #endif\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/OpenArchive.cpp",
    "content": "// OpenArchive.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidPath, &prop));\r\n  if(prop.vt == VT_BSTR)\r\n    result = prop.bstrVal;\r\n  else if (prop.vt == VT_EMPTY)\r\n    result.Empty();\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result)\r\n{\r\n  RINOK(GetArchiveItemPath(archive, index, result));\r\n  if (result.IsEmpty())\r\n    result = defaultName;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index, \r\n    const FILETIME &defaultFileTime, FILETIME &fileTime)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidLastWriteTime, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n    fileTime = prop.filetime;\r\n  else if (prop.vt == VT_EMPTY)\r\n    fileTime = defaultFileTime;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsFolder, result);\r\n}\r\n\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsAnti, result);\r\n}\r\n\r\n// Static-SFX (for Linux) can be big.\r\nconst UInt64 kMaxCheckStartPosition = 1 << 22;\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  inStreamSpec->Open(fileName);\r\n  return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n}\r\n\r\n#ifndef _SFX\r\nstatic inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)\r\n{\r\n  for (size_t i = 0; i < size; i++)\r\n    if (p1[i] != p2[i])\r\n      return false;\r\n  return true;\r\n}\r\n#endif\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    IInStream *inStream,\r\n    const UString &fileName, \r\n    IInArchive **archiveResult, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  *archiveResult = NULL;\r\n  UString extension;\r\n  {\r\n    int dotPos = fileName.ReverseFind(L'.');\r\n    if (dotPos >= 0)\r\n      extension = fileName.Mid(dotPos + 1);\r\n  }\r\n  CIntVector orderIndices;\r\n  int i;\r\n  int numFinded = 0;\r\n  for (i = 0; i < codecs->Formats.Size(); i++)\r\n    if (codecs->Formats[i].FindExtension(extension) >= 0)\r\n      orderIndices.Insert(numFinded++, i);\r\n    else\r\n      orderIndices.Add(i);\r\n  \r\n  #ifndef _SFX\r\n  if (numFinded != 1)\r\n  {\r\n    CIntVector orderIndices2;\r\n    CByteBuffer byteBuffer;\r\n    const UInt32 kBufferSize = (200 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    UInt32 processedSize;\r\n    RINOK(ReadStream(inStream, buffer, kBufferSize, &processedSize));\r\n    for (UInt32 pos = 0; pos < processedSize; pos++)\r\n    {\r\n      for (int i = 0; i < orderIndices.Size(); i++)\r\n      {\r\n        int index = orderIndices[i];\r\n        const CArcInfoEx &ai = codecs->Formats[index];\r\n        const CByteBuffer &sig = ai.StartSignature;\r\n        if (sig.GetCapacity() == 0)\r\n          continue;\r\n        if (pos + sig.GetCapacity() > processedSize)\r\n          continue;\r\n        if (TestSignature(buffer + pos, sig, sig.GetCapacity()))\r\n        {\r\n          orderIndices2.Add(index);\r\n          orderIndices.Delete(i--);\r\n        }\r\n      }\r\n    }\r\n    orderIndices2 += orderIndices;\r\n    orderIndices = orderIndices2;\r\n  }\r\n  else if (extension == L\"000\" || extension == L\"001\")\r\n  {\r\n    CByteBuffer byteBuffer;\r\n    const UInt32 kBufferSize = (1 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    UInt32 processedSize;\r\n    RINOK(ReadStream(inStream, buffer, kBufferSize, &processedSize));\r\n    if (processedSize >= 16)\r\n    {\r\n      Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};\r\n      if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] && 1) != 0)\r\n      {\r\n        for (int i = 0; i < orderIndices.Size(); i++)\r\n        {\r\n          int index = orderIndices[i];\r\n          const CArcInfoEx &ai = codecs->Formats[index];\r\n          if (ai.Name.CompareNoCase(L\"rar\") != 0)\r\n            continue;\r\n          orderIndices.Delete(i--);\r\n          orderIndices.Insert(0, index);\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  HRESULT badResult = S_OK;\r\n  for(i = 0; i < orderIndices.Size(); i++)\r\n  {\r\n    inStream->Seek(0, STREAM_SEEK_SET, NULL);\r\n\r\n    CMyComPtr<IInArchive> archive;\r\n\r\n    formatIndex = orderIndices[i];\r\n    RINOK(codecs->CreateInArchive(formatIndex, archive));\r\n    if (!archive)\r\n      continue;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    HRESULT result = archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n    if (result == S_FALSE)\r\n      continue;\r\n    if(result != S_OK)\r\n    {\r\n      badResult = result;\r\n      if(result == E_ABORT)\r\n        break;\r\n      continue;\r\n    }\r\n    *archiveResult = archive.Detach();\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex];\r\n    if (format.Exts.Size() == 0)\r\n    {\r\n      defaultItemName = GetDefaultName2(fileName, L\"\", L\"\");\r\n    }\r\n    else\r\n    {\r\n      int subExtIndex = format.FindExtension(extension);\r\n      if (subExtIndex < 0)\r\n        subExtIndex = 0;\r\n      defaultItemName = GetDefaultName2(fileName, \r\n          format.Exts[subExtIndex].Ext, \r\n          format.Exts[subExtIndex].AddExt);\r\n    }\r\n    return S_OK;\r\n  }\r\n  if (badResult != S_OK)\r\n    return badResult;\r\n  return S_FALSE;\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &filePath, \r\n    IInArchive **archiveResult, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  if (!inStreamSpec->Open(filePath))\r\n    return GetLastError();\r\n  return OpenArchive(codecs, inStream, ExtractFileNameFromPath(filePath),\r\n    archiveResult, formatIndex,\r\n    defaultItemName, openArchiveCallback);\r\n}\r\n\r\nstatic void MakeDefaultName(UString &name)\r\n{\r\n  int dotPos = name.ReverseFind(L'.');\r\n  if (dotPos < 0)\r\n    return;\r\n  UString ext = name.Mid(dotPos + 1);\r\n  if (ext.IsEmpty())\r\n    return;\r\n  for (int pos = 0; pos < ext.Length(); pos++)\r\n    if (ext[pos] < L'0' || ext[pos] > L'9')\r\n      return;\r\n  name = name.Left(dotPos);\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &fileName, \r\n    IInArchive **archive0, \r\n    IInArchive **archive1, \r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  HRESULT result = OpenArchive(codecs, fileName, \r\n      archive0, formatIndex0, defaultItemName0, openArchiveCallback);\r\n  RINOK(result);\r\n  CMyComPtr<IInArchiveGetStream> getStream;\r\n  result = (*archive0)->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream);\r\n  if (result != S_OK || getStream == 0)\r\n    return S_OK;\r\n\r\n  CMyComPtr<ISequentialInStream> subSeqStream;\r\n  result = getStream->GetStream(0, &subSeqStream);\r\n  if (result != S_OK)\r\n    return S_OK;\r\n\r\n  CMyComPtr<IInStream> subStream;\r\n  if (subSeqStream.QueryInterface(IID_IInStream, &subStream) != S_OK)\r\n    return S_OK;\r\n  if (!subStream)\r\n    return S_OK;\r\n\r\n  UInt32 numItems;\r\n  RINOK((*archive0)->GetNumberOfItems(&numItems));\r\n  if (numItems < 1)\r\n    return S_OK;\r\n\r\n  UString subPath;\r\n  RINOK(GetArchiveItemPath(*archive0, 0, subPath))\r\n  if (subPath.IsEmpty())\r\n  {\r\n    MakeDefaultName(defaultItemName0);\r\n    subPath = defaultItemName0;\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex0];\r\n    if (format.Name.CompareNoCase(L\"7z\") == 0)\r\n    {\r\n      if (subPath.Right(3).CompareNoCase(L\".7z\") != 0)\r\n        subPath += L\".7z\";\r\n    }\r\n  }\r\n  else\r\n    subPath = ExtractFileNameFromPath(subPath);\r\n\r\n  CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;\r\n  openArchiveCallback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);\r\n  if (setSubArchiveName)\r\n    setSubArchiveName->SetSubArchiveName(subPath);\r\n\r\n  result = OpenArchive(codecs, subStream, subPath,\r\n      archive1, formatIndex1, defaultItemName1, openArchiveCallback);\r\n  return S_OK;\r\n}\r\n\r\nstatic void SetCallback(const UString &archiveName,\r\n    IOpenCallbackUI *openCallbackUI, CMyComPtr<IArchiveOpenCallback> &openCallback)\r\n{\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  openCallbackSpec->Init(\r\n      fullName.Left(fileNamePartStartIndex), \r\n      fullName.Mid(fileNamePartStartIndex));\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs, \r\n    const UString &archiveName,\r\n    IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI)\r\n{\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(archiveName, openCallbackUI, openCallback);\r\n  int formatInfo;\r\n  return OpenArchive(codecs, archiveName, archive, formatInfo, defaultItemName, openCallback);\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  volumesSize = 0;\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  UString prefix = fullName.Left(fileNamePartStartIndex);\r\n  UString name = fullName.Mid(fileNamePartStartIndex);\r\n  openCallbackSpec->Init(prefix, name);\r\n\r\n  int formatIndex0, formatIndex1;\r\n  RINOK(OpenArchive(codecs, archiveName,\r\n      archive0, \r\n      archive1, \r\n      formatIndex0, \r\n      formatIndex1, \r\n      defaultItemName0,\r\n      defaultItemName1,\r\n      openCallback));\r\n  volumePaths.Add(prefix + name);\r\n  for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)\r\n    volumePaths.Add(prefix + openCallbackSpec->FileNames[i]);\r\n  volumesSize = openCallbackSpec->TotalSize;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveLink::Close()\r\n{\r\n  if (Archive1 != 0)\r\n    RINOK(Archive1->Close());\r\n  if (Archive0 != 0)\r\n    RINOK(Archive0->Close());\r\n  IsOpen = false;\r\n  return S_OK;\r\n}\r\n\r\nvoid CArchiveLink::Release()\r\n{\r\n  IsOpen = false;\r\n  Archive1.Release();\r\n  Archive0.Release();\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  HRESULT res = OpenArchive(codecs, archiveName, \r\n    &archiveLink.Archive0, &archiveLink.Archive1, \r\n    archiveLink.FormatIndex0, archiveLink.FormatIndex1, \r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1, \r\n    openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT MyOpenArchive(CCodecs *codecs,\r\n    const UString &archiveName, \r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  HRESULT res = MyOpenArchive(codecs, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1, \r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1, \r\n    archiveLink.VolumePaths,\r\n    archiveLink.VolumesSize,\r\n    openCallbackUI);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT ReOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, const UString &fileName)\r\n{\r\n  if (archiveLink.GetNumLevels() > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (archiveLink.GetNumLevels() == 0)\r\n    return MyOpenArchive(codecs, fileName, archiveLink, 0);\r\n\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(fileName, NULL, openCallback);\r\n\r\n  HRESULT res = ReOpenArchive(archiveLink.GetArchive(), fileName, openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/OpenArchive.h",
    "content": "// OpenArchive.h\r\n\r\n#ifndef __OPENARCHIVE_H\r\n#define __OPENARCHIVE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"LoadCodecs.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result);\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result);\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index, \r\n    const FILETIME &defaultFileTime, FILETIME &fileTime);\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result);\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result);\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result);\r\n\r\nstruct ISetSubArchiveName\r\n{\r\n  virtual void SetSubArchiveName(const wchar_t *name) = 0;\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    IInStream *inStream,\r\n    const UString &fileName, \r\n    IInArchive **archiveResult, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &filePath, \r\n    IInArchive **archive, \r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &filePath, \r\n    IInArchive **archive0, \r\n    IInArchive **archive1, \r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    IInArchive **archive,\r\n    UString &defaultItemName,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nstruct CArchiveLink\r\n{\r\n  CMyComPtr<IInArchive> Archive0;\r\n  CMyComPtr<IInArchive> Archive1;\r\n  UString DefaultItemName0;\r\n  UString DefaultItemName1;\r\n\r\n  int FormatIndex0;\r\n  int FormatIndex1;\r\n  \r\n  UStringVector VolumePaths;\r\n\r\n  UInt64 VolumesSize;\r\n\r\n  int GetNumLevels() const\r\n  { \r\n    int result = 0;\r\n    if (Archive0)\r\n    {\r\n      result++;\r\n      if (Archive1)\r\n        result++;\r\n    }\r\n    return result;\r\n  }\r\n\r\n  bool IsOpen;\r\n\r\n  CArchiveLink(): IsOpen(false), VolumesSize(0) {};\r\n\r\n  IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; }\r\n  UString GetDefaultItemName()  { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; }\r\n  int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; }\r\n  HRESULT Close();\r\n  void Release();\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const UString &archiveName, \r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT ReOpenArchive(\r\n    CCodecs *codecs,\r\n    CArchiveLink &archiveLink, \r\n    const UString &fileName);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/PropIDUtils.cpp",
    "content": "// PropIDUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropIDUtils.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../PropID.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic void ConvertUInt32ToHex(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    int t = value & 0xF;\r\n    value >>= 4;\r\n    s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));\r\n  }\r\n  s[8] = L'\\0';\r\n}\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full)\r\n{\r\n  switch(propID)\r\n  {\r\n    case kpidCreationTime:\r\n    case kpidLastWriteTime:\r\n    case kpidLastAccessTime:\r\n    {\r\n      if (propVariant.vt != VT_FILETIME)\r\n        return UString(); // It is error;\r\n      FILETIME localFileTime;\r\n      if (propVariant.filetime.dwHighDateTime == 0 && \r\n          propVariant.filetime.dwLowDateTime == 0)\r\n        return UString();\r\n      if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n        return UString(); // It is error;\r\n      return ConvertFileTimeToString(localFileTime, true, full);\r\n    }\r\n    case kpidCRC:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      wchar_t temp[12];\r\n      ConvertUInt32ToHex(propVariant.ulVal, temp);\r\n      return temp;\r\n    }\r\n    case kpidAttributes:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UString result;\r\n      UInt32 attributes = propVariant.ulVal;\r\n      if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';\r\n      if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';\r\n      if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';\r\n      if (NFile::NFind::NAttributes::IsDirectory(attributes)) result += L'D';\r\n      if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';\r\n      if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';\r\n      if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';\r\n      return result;\r\n    }\r\n    case kpidDictionarySize:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UInt32 size = propVariant.ulVal;\r\n      if (size % (1 << 20) == 0)\r\n        return ConvertUInt32ToString(size >> 20) + L\"MB\";\r\n      if (size % (1 << 10) == 0)\r\n        return ConvertUInt32ToString(size >> 10) + L\"KB\";\r\n      return ConvertUInt32ToString(size);\r\n    }\r\n  }\r\n  return ConvertPropVariantToString(propVariant);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/PropIDUtils.h",
    "content": "// PropIDUtils.h\r\n\r\n#ifndef __PROPIDUTILS_H\r\n#define __PROPIDUTILS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/Property.h",
    "content": "// Property.h\r\n\r\n#ifndef __PROPERTY_H\r\n#define __PROPERTY_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nstruct CProperty\r\n{\r\n  UString Name;\r\n  UString Value;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/SetProperties.cpp",
    "content": "// SetProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SetProperties.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\n\r\nstatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)\r\n{\r\n  const wchar_t *endPtr;\r\n  UInt64 result = ConvertStringToUInt64(s, &endPtr);\r\n  if (endPtr - (const wchar_t *)s != s.Length())\r\n    prop = s;\r\n  else if (result <= 0xFFFFFFFF)\r\n    prop = (UInt32)result;\r\n  else \r\n    prop = result;\r\n}\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)\r\n{\r\n  if (properties.IsEmpty())\r\n    return S_OK;\r\n  CMyComPtr<ISetProperties> setProperties;\r\n  unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);\r\n  if (!setProperties)\r\n    return S_OK;\r\n\r\n  UStringVector realNames;\r\n  CPropVariant *values = new CPropVariant[properties.Size()];\r\n  try\r\n  {\r\n    int i;\r\n    for(i = 0; i < properties.Size(); i++)\r\n    {\r\n      const CProperty &property = properties[i];\r\n      NCOM::CPropVariant propVariant;\r\n      if (!property.Value.IsEmpty())\r\n        ParseNumberString(property.Value, propVariant);\r\n      realNames.Add(property.Name);\r\n      values[i] = propVariant;\r\n    }\r\n    CRecordVector<const wchar_t *> names;\r\n    for(i = 0; i < realNames.Size(); i++)\r\n      names.Add((const wchar_t *)realNames[i]);\r\n    \r\n    RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));\r\n  }\r\n  catch(...)\r\n  {\r\n    delete []values;\r\n    throw;\r\n  }\r\n  delete []values;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/SetProperties.h",
    "content": "// SetProperties.h\r\n\r\n#ifndef __SETPROPERTIES_H\r\n#define __SETPROPERTIES_H\r\n\r\n#include \"Property.h\"\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/SortUtils.cpp",
    "content": "// SortUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SortUtils.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nstatic int CompareStrings(const int *p1, const int *p2, void *param)\r\n{\r\n  const UStringVector &strings = *(const UStringVector *)param;\r\n  return CompareFileNames(strings[*p1], strings[*p2]);\r\n}\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numItems = strings.Size();\r\n  indices.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n    indices.Add(i);\r\n  indices.Sort(CompareStrings, (void *)&strings);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/SortUtils.h",
    "content": "// SortUtils.h\r\n\r\n#ifndef __SORTUTLS_H\r\n#define __SORTUTLS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/TempFiles.cpp",
    "content": "// TempFiles.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"TempFiles.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileIO.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nvoid CTempFiles::Clear()\r\n{\r\n  while(!Paths.IsEmpty())\r\n  {\r\n    NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());\r\n    Paths.DeleteBack();\r\n  }\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/TempFiles.h",
    "content": "// TempFiles.h\r\n\r\n#ifndef __TEMPFILES_H\r\n#define __TEMPFILES_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nclass CTempFiles\r\n{\r\n  void Clear();\r\npublic:\r\n  UStringVector Paths;\r\n  ~CTempFiles() { Clear(); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/Update.cpp",
    "content": "// Update.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <mapi.h>\r\n#endif\r\n\r\n#include \"Update.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/DLL.h\"\r\n#endif\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n// #include \"Windows/Synchronization.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Compress/Copy/CopyCoder.h\"\r\n\r\n#include \"../Common/DirItem.h\"\r\n#include \"../Common/EnumDirItems.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"TempFiles.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"EnumDirItems.h\"\r\n#include \"SetProperties.h\"\r\n\r\nstatic const char *kUpdateIsNotSupoorted = \r\n  \"update operations are not supported for this archive\";\r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nstatic const wchar_t *kTempFolderPrefix = L\"7zE\";\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)\r\n{\r\n  CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;\r\n  return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);\r\n}\r\n\r\nclass COutMultiVolStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    COutFileStream *StreamSpec;\r\n    CMyComPtr<IOutStream> Stream;\r\n    UString Name;\r\n    UInt64 Pos;\r\n    UInt64 RealSize;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  // CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  CRecordVector<UInt64> Sizes;\r\n  UString Prefix;\r\n  CTempFiles *TempFiles;\r\n\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  HRESULT Close(); \r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n// static NSynchronization::CCriticalSection g_TempPathsCS;\r\n\r\nHRESULT COutMultiVolStream::Close()\r\n{\r\n  HRESULT res = S_OK;\r\n  for (int i = 0; i < Streams.Size(); i++)\r\n  {\r\n    CSubStreamInfo &s = Streams[i];\r\n    if (s.StreamSpec)\r\n    {\r\n      HRESULT res2 = s.StreamSpec->Close();\r\n      if (res2 != S_OK)\r\n        res = res2;\r\n    }\r\n  }\r\n  return res;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n\r\n      wchar_t temp[32];\r\n      ConvertUInt64ToString(_streamIndex + 1, temp);\r\n      UString res = temp;\r\n      while (res.Length() < 3)\r\n        res = UString(L'0') + res;\r\n      UString name = Prefix + res;\r\n      subStream.StreamSpec = new COutFileStream;\r\n      subStream.Stream = subStream.StreamSpec;\r\n      if(!subStream.StreamSpec->Create(name, false))\r\n        return ::GetLastError();\r\n      {\r\n        // NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);\r\n        TempFiles->Paths.Add(name);\r\n      }\r\n\r\n      subStream.Pos = 0;\r\n      subStream.RealSize = 0;\r\n      subStream.Name = name;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n\r\n    int index = _streamIndex;\r\n    if (index >= Sizes.Size())\r\n      index = Sizes.Size() - 1;\r\n    UInt64 volSize = Sizes[index];\r\n\r\n    if (_offsetPos >= volSize)\r\n    {\r\n      _offsetPos -= volSize;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      // CMyComPtr<IOutStream> outStream;\r\n      // RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(subStream.Stream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, volSize - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if (_offsetPos > subStream.RealSize)\r\n      subStream.RealSize = _offsetPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == volSize)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed == 0 && curSize != 0)\r\n      return E_FAIL;\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  if (newPosition != NULL)\r\n    *newPosition = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::SetSize(Int64 newSize)\r\n{\r\n  if (newSize < 0)\r\n    return E_INVALIDARG;\r\n  int i = 0;\r\n  while (i < Streams.Size())\r\n  {\r\n    CSubStreamInfo &subStream = Streams[i++];\r\n    if ((UInt64)newSize < subStream.RealSize)\r\n    {\r\n      RINOK(subStream.Stream->SetSize(newSize));\r\n      subStream.RealSize = newSize;\r\n      break;\r\n    }\r\n    newSize -= subStream.RealSize;\r\n  }\r\n  while (i < Streams.Size())\r\n  {\r\n    {\r\n      CSubStreamInfo &subStream = Streams.Back();\r\n      subStream.Stream.Release();\r\n      NDirectory::DeleteFileAlways(subStream.Name);\r\n    }\r\n    Streams.DeleteBack();\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  _length = newSize;\r\n  return S_OK;\r\n}\r\n\r\nstatic const wchar_t *kDefaultArchiveType = L\"7z\";\r\nstatic const wchar_t *kSFXExtension =\r\n  #ifdef _WIN32\r\n    L\"exe\";\r\n  #else\r\n    L\"\";\r\n  #endif\r\n\r\nbool CUpdateOptions::Init(const CCodecs *codecs, const UString &arcPath, const UString &arcType)\r\n{\r\n  if (!arcType.IsEmpty())\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveType(arcType);\r\n  else\r\n  {\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveName(arcPath);\r\n    if (MethodMode.FormatIndex < 0)\r\n      MethodMode.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArchiveType);\r\n  }\r\n  if (MethodMode.FormatIndex < 0)\r\n    return false;\r\n  const CArcInfoEx &arcInfo = codecs->Formats[MethodMode.FormatIndex];\r\n  UString typeExt = arcInfo.GetMainExt();\r\n  UString ext = typeExt;\r\n  if (SfxMode)\r\n    ext = kSFXExtension;\r\n  ArchivePath.BaseExtension = ext;\r\n  ArchivePath.VolExtension = typeExt;\r\n  ArchivePath.ParseFromPath(arcPath);\r\n  for (int i = 0; i < Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &uc = Commands[i];\r\n    uc.ArchivePath.BaseExtension = ext;\r\n    uc.ArchivePath.VolExtension = typeExt;\r\n    uc.ArchivePath.ParseFromPath(uc.UserArchivePath);\r\n  }\r\n  return true;\r\n}\r\n\r\n\r\nstatic HRESULT Compress(\r\n    CCodecs *codecs,\r\n    const CActionSet &actionSet, \r\n    IInArchive *archive,\r\n    const CCompressionMethodMode &compressionMethod,\r\n    CArchivePath &archivePath, \r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    bool shareForWrite,\r\n    bool stdInMode,\r\n    /* const UString & stdInFileName, */\r\n    bool stdOutMode,\r\n    const CObjectVector<CDirItem> &dirItems,\r\n    bool sfxMode,\r\n    const UString &sfxModule,\r\n    const CRecordVector<UInt64> &volumesSizes,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI *callback)\r\n{\r\n  CMyComPtr<IOutArchive> outArchive;\r\n  if(archive != NULL)\r\n  {\r\n    CMyComPtr<IInArchive> archive2 = archive;\r\n    HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);\r\n    if(result != S_OK)\r\n      throw kUpdateIsNotSupoorted;\r\n  }\r\n  else\r\n  {\r\n    RINOK(codecs->CreateOutArchive(compressionMethod.FormatIndex, outArchive));\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n  }\r\n  if (outArchive == 0)\r\n    throw kUpdateIsNotSupoorted;\r\n  \r\n  NFileTimeType::EEnum fileTimeType;\r\n  UInt32 value;\r\n  RINOK(outArchive->GetFileTimeType(&value));\r\n\r\n  switch(value)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n    case NFileTimeType::kDOS:\r\n    case NFileTimeType::kUnix:\r\n      fileTimeType = NFileTimeType::EEnum(value);\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n\r\n  CObjectVector<CUpdatePair> updatePairs;\r\n  GetUpdatePairInfoList(dirItems, archiveItems, fileTimeType, updatePairs); // must be done only once!!!\r\n  \r\n  CObjectVector<CUpdatePair2> updatePairs2;\r\n  UpdateProduce(updatePairs, actionSet, updatePairs2);\r\n\r\n  UInt32 numFiles = 0;\r\n  for (int i = 0; i < updatePairs2.Size(); i++)\r\n    if (updatePairs2[i].NewData)\r\n      numFiles++;\r\n  \r\n  RINOK(callback->SetNumFiles(numFiles));\r\n\r\n  \r\n  CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n  CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);\r\n  \r\n  updateCallbackSpec->ShareForWrite = shareForWrite;\r\n  updateCallbackSpec->StdInMode = stdInMode;\r\n  updateCallbackSpec->Callback = callback;\r\n  updateCallbackSpec->DirItems = &dirItems;\r\n  updateCallbackSpec->ArchiveItems = &archiveItems;\r\n  updateCallbackSpec->UpdatePairs = &updatePairs2;\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n\r\n  const UString &archiveName = archivePath.GetFinalPath();\r\n  if (!stdOutMode)\r\n  {\r\n    UString resultPath;\r\n    int pos;\r\n    if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))\r\n      throw 1417161;\r\n    NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));\r\n  }\r\n\r\n  COutFileStream *outStreamSpec = NULL;\r\n  COutMultiVolStream *volStreamSpec = NULL;\r\n\r\n  if (volumesSizes.Size() == 0)\r\n  {\r\n    if (stdOutMode)\r\n      outStream = new CStdOutFileStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      outStream = outStreamSpec;\r\n      bool isOK = false;\r\n      UString realPath;\r\n      for (int i = 0; i < (1 << 16); i++)\r\n      {\r\n        if (archivePath.Temp)\r\n        {\r\n          if (i > 0)\r\n          {\r\n            wchar_t s[32];\r\n            ConvertUInt64ToString(i, s);\r\n            archivePath.TempPostfix = s;\r\n          }\r\n          realPath = archivePath.GetTempPath();\r\n        }\r\n        else\r\n          realPath = archivePath.GetFinalPath();\r\n        if (outStreamSpec->Create(realPath, false))\r\n        {\r\n          tempFiles.Paths.Add(realPath);\r\n          isOK = true;\r\n          break;\r\n        }\r\n        if (::GetLastError() != ERROR_FILE_EXISTS)\r\n          break;\r\n        if (!archivePath.Temp)\r\n          break;\r\n      }\r\n      if (!isOK)\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (stdOutMode)\r\n      return E_FAIL;\r\n    volStreamSpec = new COutMultiVolStream;\r\n    outStream = volStreamSpec;\r\n    volStreamSpec->Sizes = volumesSizes;\r\n    volStreamSpec->Prefix = archivePath.GetFinalPath() + UString(L\".\");\r\n    volStreamSpec->TempFiles = &tempFiles;\r\n    volStreamSpec->Init();\r\n\r\n    /*\r\n    updateCallbackSpec->VolumesSizes = volumesSizes;\r\n    updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;\r\n    if (!archivePath.VolExtension.IsEmpty())\r\n      updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;\r\n    */\r\n  }\r\n\r\n  RINOK(SetProperties(outArchive, compressionMethod.Properties));\r\n\r\n  if (sfxMode)\r\n  {\r\n    CInFileStream *sfxStreamSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> sfxStream(sfxStreamSpec);\r\n    if (!sfxStreamSpec->Open(sfxModule))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"Can't open sfx module\";\r\n      errorInfo.FileName = sfxModule;\r\n      return E_FAIL;\r\n    }\r\n\r\n    CMyComPtr<ISequentialOutStream> sfxOutStream;\r\n    COutFileStream *outStreamSpec = NULL;\r\n    if (volumesSizes.Size() == 0)\r\n      sfxOutStream = outStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      sfxOutStream = outStreamSpec;\r\n      UString realPath = archivePath.GetFinalPath();\r\n      if (!outStreamSpec->Create(realPath, false))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    RINOK(CopyBlock(sfxStream, sfxOutStream));\r\n    if (outStreamSpec)\r\n    {\r\n      RINOK(outStreamSpec->Close());\r\n    }\r\n  }\r\n\r\n  HRESULT result = outArchive->UpdateItems(outStream, updatePairs2.Size(), updateCallback);\r\n  callback->Finilize();\r\n  RINOK(result);\r\n  if (outStreamSpec)\r\n    result = outStreamSpec->Close();\r\n  else if (volStreamSpec)\r\n    result = volStreamSpec->Close();\r\n  return result;\r\n}\r\n\r\nHRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,\r\n    IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    CObjectVector<CArchiveItem> &archiveItems)\r\n{\r\n  archiveItems.Clear();\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n  archiveItems.Reserve(numItems);\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    CArchiveItem ai;\r\n\r\n    RINOK(GetArchiveItemPath(archive, i, ai.Name));\r\n    RINOK(IsArchiveItemFolder(archive, i, ai.IsDirectory));\r\n    ai.Censored = censor.CheckPath(ai.Name.IsEmpty() ? defaultItemName : ai.Name, !ai.IsDirectory);\r\n    RINOK(GetArchiveItemFileTime(archive, i, \r\n        archiveFileInfo.LastWriteTime, ai.LastWriteTime));\r\n\r\n    CPropVariant propertySize;\r\n    RINOK(archive->GetProperty(i, kpidSize, &propertySize));\r\n    ai.SizeIsDefined = (propertySize.vt != VT_EMPTY);\r\n    if (ai.SizeIsDefined)\r\n      ai.Size = ConvertPropVariantToUInt64(propertySize);\r\n\r\n    ai.IndexInServer = i;\r\n    archiveItems.Add(ai);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nstatic HRESULT UpdateWithItemLists(\r\n    CCodecs *codecs,\r\n    CUpdateOptions &options,\r\n    IInArchive *archive, \r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    const CObjectVector<CDirItem> &dirItems,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &command = options.Commands[i];\r\n    if (options.StdOutMode)\r\n    {\r\n      RINOK(callback->StartArchive(0, archive != 0));\r\n    }\r\n    else\r\n    {\r\n      RINOK(callback->StartArchive(command.ArchivePath.GetFinalPath(), \r\n          i == 0 && options.UpdateArchiveItself && archive != 0));\r\n    }\r\n\r\n    RINOK(Compress(\r\n        codecs,\r\n        command.ActionSet, archive,\r\n        options.MethodMode, \r\n        command.ArchivePath, \r\n        archiveItems, \r\n        options.OpenShareForWrite,\r\n        options.StdInMode, \r\n        /* options.StdInFileName, */\r\n        options.StdOutMode,\r\n        dirItems, \r\n        options.SfxMode, options.SfxModule, \r\n        options.VolumesSizes,\r\n        tempFiles,\r\n        errorInfo, callback));\r\n\r\n    RINOK(callback->FinishArchive());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _WIN32\r\nclass CCurrentDirRestorer\r\n{\r\n  UString m_CurrentDirectory;\r\npublic:\r\n  CCurrentDirRestorer()\r\n    { NFile::NDirectory::MyGetCurrentDirectory(m_CurrentDirectory); }\r\n  ~CCurrentDirRestorer()\r\n    { RestoreDirectory();}\r\n  bool RestoreDirectory()\r\n    { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(m_CurrentDirectory)); }\r\n};\r\n#endif\r\n\r\nstruct CEnumDirItemUpdateCallback: public IEnumDirItemCallback\r\n{\r\n  IUpdateCallbackUI2 *Callback;\r\n  HRESULT CheckBreak() { return Callback->CheckBreak(); }\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor, \r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  if (options.StdOutMode && options.EMailMode)\r\n    return E_FAIL;\r\n\r\n  if (options.VolumesSizes.Size() > 0 && (options.EMailMode || options.SfxMode))\r\n    return E_NOTIMPL;\r\n\r\n  if (options.SfxMode)\r\n  {\r\n    CProperty property;\r\n    property.Name = L\"rsfx\";\r\n    property.Value = L\"on\";\r\n    options.MethodMode.Properties.Add(property);\r\n    if (options.SfxModule.IsEmpty())\r\n    {\r\n      errorInfo.Message = L\"sfx file is not specified\";\r\n      return E_FAIL;\r\n    }\r\n    UString name = options.SfxModule;\r\n    if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))\r\n    {\r\n      errorInfo.Message = L\"can't find specified sfx module\";\r\n      return E_FAIL;\r\n    }\r\n  }\r\n\r\n  const UString archiveName = options.ArchivePath.GetFinalPath();\r\n\r\n  UString defaultItemName;\r\n  NFind::CFileInfoW archiveFileInfo;\r\n\r\n  CArchiveLink archiveLink;\r\n  IInArchive *archive = 0;\r\n  if (NFind::FindFile(archiveName, archiveFileInfo))\r\n  {\r\n    if (archiveFileInfo.IsDirectory())\r\n      throw \"there is no such archive\";\r\n    if (options.VolumesSizes.Size() > 0)\r\n      return E_NOTIMPL;\r\n    HRESULT result = MyOpenArchive(codecs, archiveName, archiveLink, openCallback);\r\n    RINOK(callback->OpenResult(archiveName, result));\r\n    RINOK(result);\r\n    if (archiveLink.VolumePaths.Size() > 1)\r\n    {\r\n      errorInfo.SystemError = (DWORD)E_NOTIMPL;\r\n      errorInfo.Message = L\"Updating for multivolume archives is not implemented\";\r\n      return E_NOTIMPL;\r\n    }\r\n    archive = archiveLink.GetArchive();\r\n    defaultItemName = archiveLink.GetDefaultItemName();\r\n  }\r\n  else\r\n  {\r\n    /*\r\n    if (archiveType.IsEmpty())\r\n      throw \"type of archive is not specified\";\r\n    */\r\n  }\r\n\r\n  CObjectVector<CDirItem> dirItems;\r\n  if (options.StdInMode)\r\n  {\r\n    CDirItem item;\r\n    item.FullPath = item.Name = options.StdInFileName;\r\n    item.Size = (UInt64)(Int64)-1;\r\n    item.Attributes = 0;\r\n    SYSTEMTIME st;\r\n    FILETIME ft;\r\n    GetSystemTime(&st);\r\n    SystemTimeToFileTime(&st, &ft);\r\n    item.CreationTime = item.LastAccessTime = item.LastWriteTime = ft;\r\n    dirItems.Add(item);\r\n  }\r\n  else\r\n  {\r\n    bool needScanning = false;\r\n    for(int i = 0; i < options.Commands.Size(); i++)\r\n      if (options.Commands[i].ActionSet.NeedScanning())\r\n        needScanning = true;\r\n    if (needScanning)\r\n    {\r\n      CEnumDirItemUpdateCallback enumCallback;\r\n      enumCallback.Callback = callback;\r\n      RINOK(callback->StartScanning());\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(censor, dirItems, &enumCallback, errorPaths, errorCodes);\r\n      for (int i = 0; i < errorPaths.Size(); i++)\r\n      {\r\n        RINOK(callback->CanNotFindError(errorPaths[i], errorCodes[i]));\r\n      }\r\n      if(res != S_OK) \r\n      {\r\n        errorInfo.Message = L\"Scanning error\";\r\n        // errorInfo.FileName = errorPath;\r\n        return res;\r\n      }\r\n      RINOK(callback->FinishScanning());\r\n    }\r\n  }\r\n\r\n  UString tempDirPrefix;\r\n  bool usesTempDir = false;\r\n  \r\n  #ifdef _WIN32\r\n  NDirectory::CTempDirectoryW tempDirectory;\r\n  if (options.EMailMode && options.EMailRemoveAfter)\r\n  {\r\n    tempDirectory.Create(kTempFolderPrefix);\r\n    tempDirPrefix = tempDirectory.GetPath();\r\n    NormalizeDirPathPrefix(tempDirPrefix);\r\n    usesTempDir = true;\r\n  }\r\n  #endif\r\n\r\n  CTempFiles tempFiles;\r\n\r\n  bool createTempFile = false;\r\n  if(!options.StdOutMode && options.UpdateArchiveItself)\r\n  {\r\n    CArchivePath &ap = options.Commands[0].ArchivePath;\r\n    ap = options.ArchivePath;\r\n    // if ((archive != 0 && !usesTempDir) || !options.WorkingDir.IsEmpty())\r\n    if ((archive != 0 || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)\r\n    {\r\n      createTempFile = true;\r\n      ap.Temp = true;\r\n      if (!options.WorkingDir.IsEmpty())\r\n      {\r\n        ap.TempPrefix = options.WorkingDir;\r\n        NormalizeDirPathPrefix(ap.TempPrefix);\r\n      }\r\n    }\r\n  }\r\n\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CArchivePath &ap = options.Commands[i].ArchivePath;\r\n    if (usesTempDir)\r\n    {\r\n      // Check it\r\n      ap.Prefix = tempDirPrefix;\r\n      // ap.Temp = true;\r\n      // ap.TempPrefix = tempDirPrefix;\r\n    }\r\n    if (i > 0 || !createTempFile)\r\n    {\r\n      const UString &path = ap.GetFinalPath();\r\n      if (NFind::DoesFileExist(path))\r\n      {\r\n        errorInfo.SystemError = 0;\r\n        errorInfo.Message = L\"File already exists\";\r\n        errorInfo.FileName = path;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n\r\n  CObjectVector<CArchiveItem> archiveItems;\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(EnumerateInArchiveItems(censor, \r\n        archive, defaultItemName, archiveFileInfo, archiveItems));\r\n  }\r\n\r\n  RINOK(UpdateWithItemLists(codecs, options, archive, archiveItems, dirItems, \r\n      tempFiles, errorInfo, callback));\r\n\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(archiveLink.Close());\r\n    archiveLink.Release();\r\n  }\r\n\r\n  tempFiles.Paths.Clear();\r\n  if(createTempFile)\r\n  {\r\n    try\r\n    {\r\n      CArchivePath &ap = options.Commands[0].ArchivePath;\r\n      const UString &tempPath = ap.GetTempPath();\r\n      if (archive != NULL)\r\n        if (!NDirectory::DeleteFileAlways(archiveName))\r\n        {\r\n          errorInfo.SystemError = ::GetLastError();\r\n          errorInfo.Message = L\"delete file error\";\r\n          errorInfo.FileName = archiveName;\r\n          return E_FAIL;\r\n        }\r\n      if (!NDirectory::MyMoveFile(tempPath, archiveName))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.Message = L\"move file error\";\r\n        errorInfo.FileName = tempPath;\r\n        errorInfo.FileName2 = archiveName;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      throw;\r\n    }\r\n  }\r\n\r\n  #ifdef _WIN32\r\n  if (options.EMailMode)\r\n  {\r\n    NDLL::CLibrary mapiLib;\r\n    if (!mapiLib.Load(TEXT(\"Mapi32.dll\")))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not load Mapi32.dll\";\r\n      return E_FAIL;\r\n    }\r\n    LPMAPISENDDOCUMENTS fnSend = (LPMAPISENDDOCUMENTS)\r\n        mapiLib.GetProcAddress(\"MAPISendDocuments\");\r\n    if (fnSend == 0)\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not find MAPISendDocuments function\";\r\n      return E_FAIL;\r\n    }\r\n    UStringVector fullPaths;\r\n    int i;\r\n    for(i = 0; i < options.Commands.Size(); i++)\r\n    {\r\n      CArchivePath &ap = options.Commands[i].ArchivePath;\r\n      UString arcPath;\r\n      if(!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        return E_FAIL;\r\n      }\r\n      fullPaths.Add(arcPath);\r\n    }\r\n    CCurrentDirRestorer curDirRestorer;\r\n    for(i = 0; i < fullPaths.Size(); i++)\r\n    {\r\n      UString arcPath = fullPaths[i];\r\n      UString fileName = ExtractFileNameFromPath(arcPath);\r\n      AString path = GetAnsiString(arcPath);\r\n      AString name = GetAnsiString(fileName);\r\n      // Warning!!! MAPISendDocuments function changes Current directory\r\n      fnSend(0, \";\", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0); \r\n    }\r\n  }\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/Update.h",
    "content": "// Update.h\r\n\r\n#ifndef __UPDATE_H\r\n#define __UPDATE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"Property.h\"\r\n#include \"LoadCodecs.h\"\r\n\r\nstruct CArchivePath\r\n{\r\n  UString Prefix;   // path(folder) prefix including slash\r\n  UString Name; // base name\r\n  UString BaseExtension; // archive type extension or \"exe\" extension \r\n  UString VolExtension;  // archive type extension for volumes\r\n\r\n  bool Temp;\r\n  UString TempPrefix;  // path(folder) for temp location\r\n  UString TempPostfix;\r\n\r\n  CArchivePath(): Temp(false) {};\r\n  \r\n  void ParseFromPath(const UString &path)\r\n  {\r\n    SplitPathToParts(path, Prefix, Name);\r\n    if (Name.IsEmpty())\r\n      return;\r\n    int dotPos = Name.ReverseFind(L'.');\r\n    if (dotPos <= 0)\r\n      return;\r\n    if (dotPos == Name.Length() - 1)\r\n    {\r\n      Name = Name.Left(dotPos);\r\n      BaseExtension.Empty();\r\n      return;\r\n    }\r\n    if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0)\r\n    {\r\n      BaseExtension = Name.Mid(dotPos + 1);\r\n      Name = Name.Left(dotPos);\r\n    }\r\n    else\r\n      BaseExtension.Empty();\r\n  }\r\n\r\n  UString GetPathWithoutExt() const\r\n  {\r\n    return Prefix + Name;\r\n  }\r\n\r\n  UString GetFinalPath() const\r\n  {\r\n    UString path = GetPathWithoutExt();\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    return path;\r\n  }\r\n\r\n  \r\n  UString GetTempPath() const\r\n  {\r\n    UString path = TempPrefix + Name;\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    path += L\".tmp\";\r\n    path += TempPostfix;\r\n    return path; \r\n  }\r\n};\r\n\r\nstruct CUpdateArchiveCommand\r\n{\r\n  UString UserArchivePath;\r\n  CArchivePath ArchivePath;\r\n  NUpdateArchive::CActionSet ActionSet;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  int FormatIndex;\r\n  CObjectVector<CProperty> Properties;\r\n  CCompressionMethodMode(): FormatIndex(-1) {}\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  CCompressionMethodMode MethodMode;\r\n\r\n  CObjectVector<CUpdateArchiveCommand> Commands;\r\n  bool UpdateArchiveItself;\r\n  CArchivePath ArchivePath;\r\n  \r\n  bool SfxMode;\r\n  UString SfxModule;\r\n  \r\n  bool OpenShareForWrite;\r\n\r\n  bool StdInMode;\r\n  UString StdInFileName;\r\n  bool StdOutMode;\r\n  \r\n  bool EMailMode;\r\n  bool EMailRemoveAfter;\r\n  UString EMailAddress;\r\n\r\n  UString WorkingDir;\r\n\r\n  bool Init(const CCodecs *codecs, const UString &arcPath, const UString &arcType);\r\n\r\n  CUpdateOptions():\r\n    UpdateArchiveItself(true),\r\n    SfxMode(false),\r\n    StdInMode(false),\r\n    StdOutMode(false),\r\n    EMailMode(false),\r\n    EMailRemoveAfter(false),\r\n    OpenShareForWrite(false)\r\n      {};\r\n  CRecordVector<UInt64> VolumesSizes;\r\n};\r\n\r\nstruct CErrorInfo\r\n{\r\n  DWORD SystemError;\r\n  UString FileName;\r\n  UString FileName2;\r\n  UString Message;\r\n  // UStringVector ErrorPaths;\r\n  // CRecordVector<DWORD> ErrorCodes;\r\n  CErrorInfo(): SystemError(0) {};\r\n};\r\n\r\nstruct CUpdateErrorInfo: public CErrorInfo\r\n{\r\n};\r\n\r\n#define INTERFACE_IUpdateCallbackUI2(x) \\\r\n  INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \\\r\n  virtual HRESULT StartScanning() x; \\\r\n  virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT FinishScanning() x; \\\r\n  virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \\\r\n  virtual HRESULT FinishArchive() x; \\\r\n\r\nstruct IUpdateCallbackUI2: public IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI2(=0)\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor, \r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/UpdateAction.cpp",
    "content": "// UpdateAction.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n\r\nnamespace NUpdateArchive {\r\n\r\nconst CActionSet kAddActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kUpdateActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kFreshActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kSynchronizeActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n};\r\n\r\nconst CActionSet kDeleteActionSet = \r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/UpdateAction.h",
    "content": "// UpdateAction.h\r\n\r\n#ifndef __UPDATE_ACTION_H\r\n#define __UPDATE_ACTION_H\r\n\r\nnamespace NUpdateArchive {\r\n\r\n  namespace NPairState \r\n  {\r\n    const int kNumValues = 7;\r\n    enum EEnum\r\n    {\r\n      kNotMasked = 0,\r\n      kOnlyInArchive,\r\n      kOnlyOnDisk,\r\n      kNewInArchive,\r\n      kOldInArchive,\r\n      kSameFiles,\r\n      kUnknowNewerFiles\r\n    };\r\n  }\r\n  namespace NPairAction\r\n  {\r\n    enum EEnum\r\n    {\r\n      kIgnore = 0,\r\n      kCopy,\r\n      kCompress,\r\n      kCompressAsAnti\r\n    };\r\n  }\r\n  struct CActionSet\r\n  {\r\n    NPairAction::EEnum StateActions[NPairState::kNumValues];\r\n    bool NeedScanning() const\r\n    {\r\n      int i;\r\n      for (i = 0; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] == NPairAction::kCompress)\r\n          return true;\r\n      for (i = 1; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] != NPairAction::kIgnore)\r\n          return true;\r\n      return false;\r\n    }\r\n  };\r\n  extern const CActionSet kAddActionSet;\r\n  extern const CActionSet kUpdateActionSet;\r\n  extern const CActionSet kFreshActionSet;\r\n  extern const CActionSet kSynchronizeActionSet;\r\n  extern const CActionSet kDeleteActionSet;\r\n};\r\n\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/UpdateCallback.cpp",
    "content": "// UpdateCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCArchiveUpdateCallback::CArchiveUpdateCallback():\r\n  Callback(0),\r\n  ShareForWrite(false),\r\n  StdInMode(false),\r\n  DirItems(0),\r\n  ArchiveItems(0),\r\n  UpdatePairs(0)\r\n  {}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetTotal(size);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\n\r\n/*\r\nSTATPROPSTG kProperties[] = \r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidIsFolder, VT_BOOL},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidLastAccessTime, VT_FILETIME},\r\n  { NULL, kpidCreationTime, VT_FILETIME},\r\n  { NULL, kpidLastWriteTime, VT_FILETIME},\r\n  { NULL, kpidAttributes, VT_UI4},\r\n  { NULL, kpidIsAnti, VT_BOOL}\r\n};\r\n*/\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)\r\n{\r\n  return E_NOTIMPL;\r\n  /*\r\n  return CStatPropEnumerator::CreateEnumerator(kProperties, \r\n      sizeof(kProperties) / sizeof(kProperties[0]), enumerator);\r\n  */\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  COM_TRY_BEGIN\r\n  RINOK(Callback->CheckBreak());\r\n  const CUpdatePair2 &updatePair = (*UpdatePairs)[index];\r\n  if(newData != NULL)\r\n    *newData = BoolToInt(updatePair.NewData);\r\n  if(newProperties != NULL)\r\n    *newProperties = BoolToInt(updatePair.NewProperties);\r\n  if(indexInArchive != NULL)\r\n  {\r\n    if (updatePair.ExistInArchive)\r\n    {\r\n      if (ArchiveItems == 0)\r\n        *indexInArchive = updatePair.ArchiveItemIndex;\r\n      else\r\n        *indexInArchive = (*ArchiveItems)[updatePair.ArchiveItemIndex].IndexInServer;\r\n    }\r\n    else\r\n      *indexInArchive = UInt32(-1);\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &updatePair = (*UpdatePairs)[index];\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    propVariant = updatePair.IsAnti;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  if (updatePair.IsAnti)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidIsFolder:\r\n      case kpidPath:\r\n        break;\r\n      case kpidSize:\r\n        propVariant = (UInt64)0;\r\n        propVariant.Detach(value);\r\n        return S_OK;\r\n      default:\r\n        propVariant.Detach(value);\r\n        return S_OK;\r\n    }\r\n  }\r\n  \r\n  if(updatePair.ExistOnDisk)\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[updatePair.DirItemIndex];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:\r\n        propVariant = dirItem.Name;\r\n        break;\r\n      case kpidIsFolder:\r\n        propVariant = dirItem.IsDirectory();\r\n        break;\r\n      case kpidSize:\r\n        propVariant = dirItem.Size;\r\n        break;\r\n      case kpidAttributes:\r\n        propVariant = dirItem.Attributes;\r\n        break;\r\n      case kpidLastAccessTime:\r\n        propVariant = dirItem.LastAccessTime;\r\n        break;\r\n      case kpidCreationTime:\r\n        propVariant = dirItem.CreationTime;\r\n        break;\r\n      case kpidLastWriteTime:\r\n        propVariant = dirItem.LastWriteTime;\r\n        break;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (propID == kpidPath)\r\n    {\r\n      if (updatePair.NewNameIsDefined)\r\n      {\r\n        propVariant = updatePair.NewName;\r\n        propVariant.Detach(value);\r\n        return S_OK;\r\n      }\r\n    }\r\n    if (updatePair.ExistInArchive && Archive)\r\n    {\r\n      UInt32 indexInArchive;\r\n      if (ArchiveItems == 0)\r\n        indexInArchive = updatePair.ArchiveItemIndex;\r\n      else\r\n        indexInArchive = (*ArchiveItems)[updatePair.ArchiveItemIndex].IndexInServer;\r\n      return Archive->GetProperty(indexInArchive, propID, value);\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &updatePair = (*UpdatePairs)[index];\r\n  if(!updatePair.NewData)\r\n    return E_FAIL;\r\n  \r\n  RINOK(Callback->CheckBreak());\r\n  RINOK(Callback->Finilize());\r\n\r\n  if(updatePair.IsAnti)\r\n  {\r\n    return Callback->GetStream((*ArchiveItems)[updatePair.ArchiveItemIndex].Name, true);\r\n  }\r\n  const CDirItem &dirItem = (*DirItems)[updatePair.DirItemIndex];\r\n  RINOK(Callback->GetStream(dirItem.Name, false));\r\n \r\n  if(dirItem.IsDirectory())\r\n    return S_OK;\r\n\r\n  if (StdInMode)\r\n  {\r\n    CStdInFileStream *inStreamSpec = new CStdInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  else\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if(!inStreamSpec->OpenShared(path, ShareForWrite))\r\n    {\r\n      return Callback->OpenFileError(path, ::GetLastError());\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetOperationResult(operationResult);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if(!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->CryptoGetTextPassword2(passwordIsDefined, password);\r\n  COM_TRY_END\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/UpdateCallback.h",
    "content": "// UpdateCallback.h\r\n\r\n#ifndef __UPDATECALLBACK_H\r\n#define __UPDATECALLBACK_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/UpdatePair.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#define INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT SetTotal(UInt64 size) x; \\\r\n  virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \\\r\n  virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x; \\\r\n  virtual HRESULT CheckBreak() x; \\\r\n  virtual HRESULT Finilize() x; \\\r\n  virtual HRESULT SetNumFiles(UInt64 numFiles) x; \\\r\n  virtual HRESULT GetStream(const wchar_t *name, bool isAnti) x; \\\r\n  virtual HRESULT OpenFileError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT SetOperationResult(Int32 operationResult) x; \\\r\n  virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x; \\\r\n\r\n  // virtual HRESULT CloseProgress() { return S_OK; };\r\n\r\nstruct IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI(=0)\r\n};\r\n\r\nclass CArchiveUpdateCallback: \r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveUpdateCallback2, \r\n      ICryptoGetTextPassword2,\r\n      ICompressProgressInfo)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IUpdateCallback\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);  \r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index, \r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  IUpdateCallbackUI *Callback;\r\n\r\n  UString DirPrefix;\r\n  bool ShareForWrite;\r\n  bool StdInMode;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n  const CObjectVector<CArchiveItem> *ArchiveItems;\r\n  const CObjectVector<CUpdatePair2> *UpdatePairs;\r\n  CMyComPtr<IInArchive> Archive;\r\n\r\n  CArchiveUpdateCallback();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/UpdatePair.cpp",
    "content": "// UpdatePair.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <time.h>\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"UpdatePair.h\"\r\n#include \"SortUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nstatic int MyCompareTime(NFileTimeType::EEnum fileTimeType, \r\n    const FILETIME &time1, const FILETIME &time2)\r\n{\r\n  switch(fileTimeType)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n      return ::CompareFileTime(&time1, &time2);\r\n    case NFileTimeType::kUnix:\r\n      {\r\n        UInt32 unixTime1, unixTime2;\r\n        if (!FileTimeToUnixTime(time1, unixTime1))\r\n        {\r\n          unixTime1 = 0;\r\n          // throw 4191614;\r\n        }\r\n        if (!FileTimeToUnixTime(time2, unixTime2))\r\n        {\r\n          unixTime2 = 0;\r\n          // throw 4191615;\r\n        }\r\n        return MyCompare(unixTime1, unixTime2);\r\n      }\r\n    case NFileTimeType::kDOS:\r\n      {\r\n        UInt32 dosTime1, dosTime2;\r\n        FileTimeToDosTime(time1, dosTime1);\r\n        FileTimeToDosTime(time2, dosTime2);\r\n        /*\r\n        if (!FileTimeToDosTime(time1, dosTime1))\r\n          throw 4191616;\r\n        if (!FileTimeToDosTime(time2, dosTime2))\r\n          throw 4191617;\r\n        */\r\n        return MyCompare(dosTime1, dosTime2);\r\n      }\r\n  }\r\n  throw 4191618;\r\n}\r\n\r\nstatic const wchar_t *kDuplicateFileNameMessage = L\"Duplicate filename:\";\r\n\r\n/*\r\nstatic const char *kNotCensoredCollisionMessaged = \"Internal file name collision:\\n\";\r\nstatic const char *kSameTimeChangedSizeCollisionMessaged = \r\n    \"Collision between files with same date/time and different sizes:\\n\";\r\n*/\r\n\r\nstatic void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)\r\n{\r\n  for(int i = 0; i + 1 < indices.Size(); i++)\r\n    if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)\r\n    {\r\n      UString message = kDuplicateFileNameMessage;\r\n      message += L\"\\n\";\r\n      message += strings[indices[i]];\r\n      message += L\"\\n\";\r\n      message += strings[indices[i + 1]];\r\n      throw message;\r\n    }\r\n}\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CObjectVector<CDirItem> &dirItems, \r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CObjectVector<CUpdatePair> &updatePairs)\r\n{\r\n  CIntVector dirIndices, archiveIndices;\r\n  UStringVector dirNames, archiveNames;\r\n  \r\n  int numDirItems = dirItems.Size(); \r\n  int i;\r\n  for(i = 0; i < numDirItems; i++)\r\n    dirNames.Add(dirItems[i].Name);\r\n  SortFileNames(dirNames, dirIndices);\r\n  TestDuplicateString(dirNames, dirIndices);\r\n\r\n  int numArchiveItems = archiveItems.Size(); \r\n  for(i = 0; i < numArchiveItems; i++)\r\n    archiveNames.Add(archiveItems[i].Name);\r\n  SortFileNames(archiveNames, archiveIndices);\r\n  TestDuplicateString(archiveNames, archiveIndices);\r\n  \r\n  int dirItemIndex = 0, archiveItemIndex = 0; \r\n  CUpdatePair pair;\r\n  while(dirItemIndex < numDirItems && archiveItemIndex < numArchiveItems)\r\n  {\r\n    int dirItemIndex2 = dirIndices[dirItemIndex],\r\n        archiveItemIndex2 = archiveIndices[archiveItemIndex]; \r\n    const CDirItem &dirItem = dirItems[dirItemIndex2];\r\n    const CArchiveItem &archiveItem = archiveItems[archiveItemIndex2];\r\n    int compareResult = CompareFileNames(dirItem.Name, archiveItem.Name);\r\n    if (compareResult < 0)\r\n    {\r\n        pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n        pair.DirItemIndex = dirItemIndex2;\r\n        dirItemIndex++;\r\n    }\r\n    else if (compareResult > 0)\r\n    {\r\n      pair.State = archiveItem.Censored ? \r\n        NUpdateArchive::NPairState::kOnlyInArchive: NUpdateArchive::NPairState::kNotMasked;\r\n      pair.ArchiveItemIndex = archiveItemIndex2;\r\n      archiveItemIndex++;\r\n    }\r\n    else\r\n    {\r\n      if (!archiveItem.Censored)\r\n        throw 1082022;; // TTString(kNotCensoredCollisionMessaged + dirItem.Name);\r\n      pair.DirItemIndex = dirItemIndex2;\r\n      pair.ArchiveItemIndex = archiveItemIndex2;\r\n      switch (MyCompareTime(fileTimeType, dirItem.LastWriteTime, archiveItem.LastWriteTime))\r\n      {\r\n        case -1:\r\n          pair.State = NUpdateArchive::NPairState::kNewInArchive;\r\n          break;\r\n        case 1:\r\n          pair.State = NUpdateArchive::NPairState::kOldInArchive;\r\n          break;\r\n        default:\r\n          if (archiveItem.SizeIsDefined)\r\n            if (dirItem.Size != archiveItem.Size)\r\n              // throw 1082034; // kSameTimeChangedSizeCollisionMessaged;\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n            else\r\n              pair.State = NUpdateArchive::NPairState::kSameFiles;\r\n          else\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n      }\r\n      dirItemIndex++;\r\n      archiveItemIndex++;\r\n    }\r\n    updatePairs.Add(pair);\r\n  }\r\n  for(;dirItemIndex < numDirItems; dirItemIndex++)\r\n  {\r\n    pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n    pair.DirItemIndex = dirIndices[dirItemIndex];\r\n    updatePairs.Add(pair);\r\n  }\r\n  for(;archiveItemIndex < numArchiveItems; archiveItemIndex++)\r\n  {\r\n    int archiveItemIndex2 = archiveIndices[archiveItemIndex]; \r\n    const CArchiveItem &archiveItem = archiveItems[archiveItemIndex2];\r\n    pair.State = archiveItem.Censored ?  \r\n        NUpdateArchive::NPairState::kOnlyInArchive: NUpdateArchive::NPairState::kNotMasked;\r\n    pair.ArchiveItemIndex = archiveItemIndex2;\r\n    updatePairs.Add(pair);\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/UpdatePair.h",
    "content": "// UpdatePair.h\r\n\r\n#ifndef __UPDATE_PAIR_H\r\n#define __UPDATE_PAIR_H\r\n\r\n#include \"DirItem.h\"\r\n#include \"UpdateAction.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CUpdatePair\r\n{\r\n  NUpdateArchive::NPairState::EEnum State;\r\n  int ArchiveItemIndex;\r\n  int DirItemIndex;\r\n};\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CObjectVector<CDirItem> &dirItems,\r\n    const CObjectVector<CArchiveItem> &archiveItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CObjectVector<CUpdatePair> &updatePairs);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/UpdateProduce.cpp",
    "content": "// UpdateProduce.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateProduce.h\"\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic const char *kUpdateActionSetCollision =\r\n    \"Internal collision in update action set\";\r\n\r\nvoid UpdateProduce(\r\n    const CObjectVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CObjectVector<CUpdatePair2> &operationChain)\r\n{\r\n  for(int i = 0; i < updatePairs.Size(); i++)\r\n  {\r\n    // CUpdateArchiveRange aRange;\r\n    const CUpdatePair &pair = updatePairs[i];\r\n\r\n    CUpdatePair2 pair2;\r\n    pair2.IsAnti = false;\r\n    pair2.ArchiveItemIndex = pair.ArchiveItemIndex;\r\n    pair2.DirItemIndex = pair.DirItemIndex;\r\n    pair2.ExistInArchive = (pair.State != NPairState::kOnlyOnDisk);\r\n    pair2.ExistOnDisk = (pair.State != NPairState::kOnlyInArchive && pair.State != NPairState::kNotMasked);\r\n    switch(actionSet.StateActions[pair.State])\r\n    {\r\n      case NPairAction::kIgnore:\r\n        /*\r\n        if (pair.State != NPairState::kOnlyOnDisk)\r\n          IgnoreArchiveItem(m_ArchiveItems[pair.ArchiveItemIndex]);\r\n        // cout << \"deleting\";\r\n        */\r\n        break;\r\n      case NPairAction::kCopy:\r\n        {\r\n          if (pair.State == NPairState::kOnlyOnDisk)\r\n            throw kUpdateActionSetCollision;\r\n          pair2.NewData = pair2.NewProperties = false;\r\n          operationChain.Add(pair2);\r\n          break;\r\n        }\r\n      case NPairAction::kCompress:\r\n        {\r\n          if (pair.State == NPairState::kOnlyInArchive || \r\n            pair.State == NPairState::kNotMasked)\r\n            throw kUpdateActionSetCollision;\r\n          pair2.NewData = pair2.NewProperties = true;\r\n          operationChain.Add(pair2);\r\n          break;\r\n        }\r\n      case NPairAction::kCompressAsAnti:\r\n        {\r\n          pair2.IsAnti = true;\r\n          pair2.NewData = pair2.NewProperties = true;\r\n          operationChain.Add(pair2);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/UpdateProduce.h",
    "content": "// UpdateProduce.h\r\n\r\n#ifndef __UPDATE_PRODUCE_H\r\n#define __UPDATE_PRODUCE_H\r\n\r\n#include \"UpdatePair.h\"\r\n\r\nstruct CUpdatePair2\r\n{\r\n  // bool OperationIsCompress;\r\n  bool NewData;\r\n  bool NewProperties;\r\n\r\n  bool ExistInArchive;\r\n  bool ExistOnDisk;\r\n  bool IsAnti;\r\n  int ArchiveItemIndex;\r\n  int DirItemIndex;\r\n\r\n  bool NewNameIsDefined;\r\n  UString NewName;\r\n\r\n  CUpdatePair2(): NewNameIsDefined(false) {}\r\n};\r\n\r\nvoid UpdateProduce(\r\n    const CObjectVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CObjectVector<CUpdatePair2> &operationChain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/WorkDir.cpp",
    "content": "// WorkDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"WorkDir.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nstatic inline UINT GetCurrentCodePage() \r\n  { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)\r\n{\r\n  NWorkDir::NMode::EEnum mode = workDirInfo.Mode;\r\n  if (workDirInfo.ForRemovableOnly)\r\n  {\r\n    mode = NWorkDir::NMode::kCurrent;\r\n    UString prefix = path.Left(3);\r\n    if (prefix[1] == L':' && prefix[2] == L'\\\\')\r\n    {\r\n      UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));\r\n      if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)\r\n        mode = workDirInfo.Mode;\r\n    }\r\n    /*\r\n    CParsedPath parsedPath;\r\n    parsedPath.ParsePath(archiveName);\r\n    UINT driveType = GetDriveType(parsedPath.Prefix);\r\n    if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))\r\n      mode = NZipSettings::NWorkDir::NMode::kCurrent;\r\n    */\r\n  }\r\n  switch(mode)\r\n  {\r\n    case NWorkDir::NMode::kCurrent:\r\n    {\r\n      return ExtractDirPrefixFromPath(path);\r\n    }\r\n    case NWorkDir::NMode::kSpecified:\r\n    {\r\n      UString tempDir = workDirInfo.Path;\r\n      NormalizeDirPathPrefix(tempDir);\r\n      return tempDir;\r\n    }\r\n    default:\r\n    {\r\n      UString tempDir;\r\n      if(!NFile::NDirectory::MyGetTempPath(tempDir))\r\n        throw 141717;\r\n      return tempDir;\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/WorkDir.h",
    "content": "// WorkDir.h\r\n\r\n#ifndef __WORKDIR_H\r\n#define __WORKDIR_H\r\n\r\n#include \"ZipRegistry.h\"\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Common/ZipRegistry.h",
    "content": "// ZipRegistry.h\r\n\r\n#ifndef __ZIPREGISTRY_H\r\n#define __ZIPREGISTRY_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"ExtractMode.h\"\r\n\r\nnamespace NExtract\r\n{\r\n  struct CInfo\r\n  {\r\n    NPathMode::EEnum PathMode;\r\n    NOverwriteMode::EEnum OverwriteMode;\r\n    UStringVector Paths;\r\n    bool ShowPassword;\r\n  };\r\n}\r\n\r\nnamespace NCompression {\r\n  \r\n  struct CFormatOptions\r\n  {\r\n    CSysString FormatID;\r\n    UString Options;\r\n    UString Method;\r\n    UString EncryptionMethod;\r\n    UInt32 Level;\r\n    UInt32 Dictionary;\r\n    UInt32 Order;\r\n    UInt32 BlockLogSize;\r\n    UInt32 NumThreads;\r\n    void ResetForLevelChange() \r\n    { \r\n      BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1); \r\n      Method.Empty();\r\n      // EncryptionMethod.Empty();\r\n      // Options.Empty();\r\n    }\r\n    CFormatOptions() { ResetForLevelChange(); }\r\n  };\r\n\r\n  struct CInfo\r\n  {\r\n    UStringVector HistoryArchives;\r\n    UInt32 Level;\r\n    UString ArchiveType;\r\n\r\n    CObjectVector<CFormatOptions> FormatOptionsVector;\r\n\r\n    bool ShowPassword;\r\n    bool EncryptHeaders;\r\n  };\r\n}\r\n\r\nnamespace NWorkDir{\r\n  \r\n  namespace NMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kSystem,\r\n      kCurrent,\r\n      kSpecified\r\n    };\r\n  }\r\n  struct CInfo\r\n  {\r\n    NMode::EEnum Mode;\r\n    UString Path;\r\n    bool ForRemovableOnly;\r\n    void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }\r\n    void SetDefault()\r\n    {\r\n      Mode = NMode::kSystem;\r\n      Path.Empty();\r\n      SetForRemovableOnlyDefault();\r\n    }\r\n  };\r\n}\r\n\r\nvoid SaveExtractionInfo(const NExtract::CInfo &info);\r\nvoid ReadExtractionInfo(NExtract::CInfo &info);\r\n\r\nvoid SaveCompressionInfo(const NCompression::CInfo &info);\r\nvoid ReadCompressionInfo(NCompression::CInfo &info);\r\n\r\nvoid SaveWorkDirInfo(const NWorkDir::CInfo &info);\r\nvoid ReadWorkDirInfo(NWorkDir::CInfo &info);\r\n\r\nvoid SaveCascadedMenu(bool enabled);\r\nbool ReadCascadedMenu();\r\n\r\nvoid SaveContextMenuStatus(UInt32 value);\r\nbool ReadContextMenuStatus(UInt32 &value);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/ConsoleClose.cpp",
    "content": "// ConsoleClose.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n\r\nstatic int g_BreakCounter = 0;\r\nstatic const int kBreakAbortThreshold = 2;\r\n\r\nnamespace NConsoleClose {\r\n\r\nstatic BOOL WINAPI HandlerRoutine(DWORD ctrlType)\r\n{\r\n  if (ctrlType == CTRL_LOGOFF_EVENT)\r\n  {\r\n    // printf(\"\\nCTRL_LOGOFF_EVENT\\n\");\r\n    return TRUE;\r\n  }\r\n\r\n  g_BreakCounter++;\r\n  if (g_BreakCounter < kBreakAbortThreshold)\r\n    return TRUE;\r\n  return FALSE;\r\n  /*\r\n  switch(ctrlType)\r\n  {\r\n    case CTRL_C_EVENT:\r\n    case CTRL_BREAK_EVENT:\r\n      if (g_BreakCounter < kBreakAbortThreshold)\r\n      return TRUE;\r\n  }\r\n  return FALSE;\r\n  */\r\n}\r\n\r\nbool TestBreakSignal()\r\n{\r\n  /*\r\n  if (g_BreakCounter > 0)\r\n    return true;\r\n  */\r\n  return (g_BreakCounter > 0);\r\n}\r\n\r\nvoid CheckCtrlBreak()\r\n{\r\n  if (TestBreakSignal())\r\n    throw CCtrlBreakException();\r\n}\r\n\r\nCCtrlHandlerSetter::CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\nCCtrlHandlerSetter::~CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/ConsoleClose.h",
    "content": "// ConsoleCloseUtils.h\r\n\r\n#ifndef __CONSOLECLOSEUTILS_H\r\n#define __CONSOLECLOSEUTILS_H\r\n\r\nnamespace NConsoleClose {\r\n\r\nbool TestBreakSignal();\r\n\r\nclass CCtrlHandlerSetter\r\n{\r\npublic:\r\n  CCtrlHandlerSetter();\r\n  virtual ~CCtrlHandlerSetter();\r\n};\r\n\r\nclass CCtrlBreakException \r\n{};\r\n\r\nvoid CheckCtrlBreak();\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UserInputUtils.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Error.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\n// static const char *kCantAutoRename = \"can not create file with auto name\\n\";\r\n// static const char *kCantRenameFile = \"can not rename existing file\\n\";\r\n// static const char *kCantDeleteOutputFile = \"can not delete output file \";\r\nstatic const char *kError = \"ERROR: \";\r\nstatic const char *kMemoryExceptionMessage = \"Can't allocate required memory!\";\r\n\r\nstatic const char *kProcessing = \"Processing archive: \";\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kNoFiles = \"No files to process\";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCrcFailed = \"CRC Failed\";\r\nstatic const char *kCrcFailedEncrypted = \"CRC Failed in encrypted file. Wrong password?\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kDataErrorEncrypted = \"Data Error in encrypted file. Wrong password?\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::AskOverwrite(\r\n    const wchar_t *existName, const FILETIME *, const UInt64 *,\r\n    const wchar_t *newName, const FILETIME *, const UInt64 *,\r\n    Int32 *answer)\r\n{\r\n  (*OutStream) << \"file \" << existName << \r\n    \"\\nalready exists. Overwrite with \" << endl;\r\n  (*OutStream) << newName;\r\n  \r\n  NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);\r\n  \r\n  switch(overwriteAnswer)\r\n  {\r\n    case NUserAnswerMode::kQuit:\r\n      return E_ABORT;\r\n    case NUserAnswerMode::kNo:\r\n      *answer = NOverwriteAnswer::kNo;\r\n      break;\r\n    case NUserAnswerMode::kNoAll:\r\n      *answer = NOverwriteAnswer::kNoToAll;\r\n      break;\r\n    case NUserAnswerMode::kYesAll:\r\n      *answer = NOverwriteAnswer::kYesToAll;\r\n      break;\r\n    case NUserAnswerMode::kYes:\r\n      *answer = NOverwriteAnswer::kYes;\r\n      break;\r\n    case NUserAnswerMode::kAutoRename:\r\n      *answer = NOverwriteAnswer::kAutoRename;\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position)\r\n{\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      (*OutStream) << kExtractingString;\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kTest:\r\n      (*OutStream) << kTestingString;\r\n      break;\r\n    case NArchive::NExtract::NAskMode::kSkip:\r\n      (*OutStream) << kSkippingString;\r\n      break;\r\n  };\r\n  (*OutStream) << name;\r\n  if (position != 0)\r\n    (*OutStream) << \" <\" << *position << \">\";\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)\r\n{\r\n  (*OutStream) << message << endl;\r\n  NumFileErrorsInCurrentArchive++;\r\n  NumFileErrors++;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumFileErrorsInCurrentArchive++;\r\n      NumFileErrors++;\r\n      (*OutStream) << \"     \";\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          (*OutStream) << kUnsupportedMethod;\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError);\r\n          break;\r\n        default:\r\n          (*OutStream) << kUnknownError;\r\n      }\r\n    }\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream); \r\n    PasswordIsDefined = true;\r\n  }\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)\r\n{\r\n  NumArchives++;\r\n  NumFileErrorsInCurrentArchive = 0;\r\n  (*OutStream) << endl << kProcessing << name << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT result, bool encrypted)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n  {\r\n    (*OutStream) << \"Error: \";\r\n    if (encrypted)\r\n      (*OutStream) << \"Can not open encrypted archive. Wrong password?\";\r\n    else\r\n      (*OutStream) << \"Can not open file as archive\";\r\n    (*OutStream) << endl;\r\n    NumArchiveErrors++;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nHRESULT CExtractCallbackConsole::ThereAreNoFiles()\r\n{\r\n  (*OutStream) << endl << kNoFiles << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)\r\n{\r\n  if (result == S_OK)\r\n  {\r\n    (*OutStream) << endl;\r\n    if (NumFileErrorsInCurrentArchive == 0)\r\n      (*OutStream) << kEverythingIsOk << endl;\r\n    else \r\n    {\r\n      NumArchiveErrors++;\r\n      (*OutStream) << \"Sub items Errors: \" << NumFileErrorsInCurrentArchive << endl;\r\n    }\r\n  }\r\n  if (result == S_OK)\r\n    return result;\r\n  NumArchiveErrors++;\r\n  if (result == E_ABORT || result == ERROR_DISK_FULL)\r\n    return result;\r\n  (*OutStream) << endl << kError;\r\n  if (result == E_OUTOFMEMORY)\r\n    (*OutStream) << kMemoryExceptionMessage;\r\n  else\r\n  {\r\n    UString message;\r\n    NError::MyFormatMessage(result, message);\r\n    (*OutStream) << message;\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::SetPassword(const UString &password)\r\n{\r\n  PasswordIsDefined = true;\r\n  Password = password;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.h",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#ifndef __EXTRACTCALLBACKCONSOLE_H\r\n#define __EXTRACTCALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../Common/ArchiveExtractCallback.h\"\r\n\r\nclass CExtractCallbackConsole: \r\n  public IExtractCallbackUI,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IFolderArchiveExtractCallback, ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(UInt64 total);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IFolderArchiveExtractCallback\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer);\r\n  STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position);\r\n\r\n  STDMETHOD(MessageError)(const wchar_t *message);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  HRESULT BeforeOpen(const wchar_t *name);\r\n  HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);\r\n  HRESULT ThereAreNoFiles();\r\n  HRESULT ExtractResult(HRESULT result);\r\n\r\n  HRESULT SetPassword(const UString &password);\r\n\r\npublic:\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  \r\n  UInt64 NumArchives;\r\n  UInt64 NumArchiveErrors;\r\n  UInt64 NumFileErrors;\r\n  UInt64 NumFileErrorsInCurrentArchive;\r\n\r\n  CStdOutStream *OutStream;\r\n\r\n  void Init()\r\n  {\r\n    NumArchives = 0;\r\n    NumArchiveErrors = 0;\r\n    NumFileErrors = 0;\r\n    NumFileErrorsInCurrentArchive = 0;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/List.cpp",
    "content": "// List.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"List.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../Common/PropIDUtils.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstruct CPropIdToName\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n};\r\n\r\nstatic CPropIdToName kPropIdToName[] =  \r\n{\r\n  { kpidPath, L\"Path\" },\r\n  { kpidName, L\"Name\" },\r\n  { kpidIsFolder, L\"Folder\" }, \r\n  { kpidSize, L\"Size\" },\r\n  { kpidPackedSize, L\"Packed Size\" },\r\n  { kpidAttributes, L\"Attributes\" },\r\n  { kpidCreationTime, L\"Created\" },\r\n  { kpidLastAccessTime, L\"Accessed\" },\r\n  { kpidLastWriteTime, L\"Modified\" },\r\n  { kpidSolid, L\"Solid\" },\r\n  { kpidCommented, L\"Commented\" },\r\n  { kpidEncrypted, L\"Encrypted\" },\r\n  { kpidSplitBefore, L\"Split Before\" },\r\n  { kpidSplitAfter, L\"Split After\" },\r\n  { kpidDictionarySize, L\"Dictionary Size\" },\r\n  { kpidCRC, L\"CRC\" },\r\n  { kpidType, L\"Type\" },\r\n  { kpidIsAnti, L\"Anti\" },\r\n  { kpidMethod, L\"Method\" },\r\n  { kpidHostOS, L\"Host OS\" },\r\n  { kpidFileSystem, L\"File System\" },\r\n  { kpidUser, L\"User\" },\r\n  { kpidGroup, L\"Group\" },\r\n  { kpidBlock, L\"Block\" },\r\n  { kpidComment, L\"Comment\" },\r\n  { kpidPosition, L\"Position\" },\r\n  { kpidPrefix, L\"Prefix\" },\r\n  { kpidNumSubFolders, L\"Folders\" },\r\n  { kpidNumSubFiles, L\"Files\" },\r\n  { kpidUnpackVer, L\"Version\" },\r\n  { kpidVolume, L\"Volume\" },\r\n  { kpidIsVolume, L\"Multivolume\" },\r\n  { kpidOffset, L\"Offset\" },\r\n  { kpidLinks, L\"Links\" },\r\n  { kpidNumBlocks, L\"Blocks\" },\r\n  { kpidNumVolumes, L\"Volumes\" }\r\n};\r\n\r\nstatic const char kEmptyAttributeChar = '.';\r\nstatic const char kDirectoryAttributeChar = 'D';\r\nstatic const char kReadonlyAttributeChar  = 'R';\r\nstatic const char kHiddenAttributeChar    = 'H';\r\nstatic const char kSystemAttributeChar    = 'S';\r\nstatic const char kArchiveAttributeChar   = 'A';\r\n\r\nstatic const char *kListing = \"Listing archive: \";\r\nstatic const wchar_t *kFilesMessage = L\"files\";\r\nstatic const wchar_t *kDirsMessage = L\"folders\";\r\n\r\nstatic void GetAttributesString(DWORD wa, bool directory, char *s)\r\n{\r\n  s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || directory) ? \r\n      kDirectoryAttributeChar: kEmptyAttributeChar;\r\n  s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0)? \r\n      kReadonlyAttributeChar: kEmptyAttributeChar;\r\n  s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? \r\n      kHiddenAttributeChar: kEmptyAttributeChar;\r\n  s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? \r\n      kSystemAttributeChar: kEmptyAttributeChar;\r\n  s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? \r\n      kArchiveAttributeChar: kEmptyAttributeChar;\r\n  s[5] = '\\0';\r\n}\r\n\r\nenum EAdjustment\r\n{\r\n  kLeft,\r\n  kCenter,\r\n  kRight\r\n};\r\n\r\nstruct CFieldInfo\r\n{\r\n  PROPID PropID;\r\n  UString Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nstruct CFieldInfoInit\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nCFieldInfoInit kStandardFieldTable[] = \r\n{\r\n  { kpidLastWriteTime, L\"   Date      Time\", kLeft, kLeft, 0, 19 },\r\n  { kpidAttributes, L\"Attr\", kRight, kCenter, 1, 5 },\r\n  { kpidSize, L\"Size\", kRight, kRight, 1, 12 },\r\n  { kpidPackedSize, L\"Compressed\", kRight, kRight, 1, 12 },\r\n  { kpidPath, L\"Name\", kLeft, kLeft, 2, 24 }\r\n};\r\n\r\nvoid PrintSpaces(int numSpaces)\r\n{\r\n  for (int i = 0; i < numSpaces; i++)\r\n    g_StdOut << ' ';\r\n}\r\n\r\nvoid PrintString(EAdjustment adjustment, int width, const UString &textString)\r\n{\r\n  const int numSpaces = width - textString.Length();\r\n  int numLeftSpaces = 0;\r\n  switch (adjustment)\r\n  {\r\n    case kLeft:\r\n      numLeftSpaces = 0;\r\n      break;\r\n    case kCenter:\r\n      numLeftSpaces = numSpaces / 2;\r\n      break;\r\n    case kRight:\r\n      numLeftSpaces = numSpaces;\r\n      break;\r\n  }\r\n  PrintSpaces(numLeftSpaces);\r\n  g_StdOut << textString;\r\n  PrintSpaces(numSpaces - numLeftSpaces);\r\n}\r\n\r\nclass CFieldPrinter\r\n{\r\n  CObjectVector<CFieldInfo> _fields;\r\npublic:\r\n  void Clear() { _fields.Clear(); }\r\n  void Init(const CFieldInfoInit *standardFieldTable, int numItems);\r\n  HRESULT Init(IInArchive *archive);\r\n  void PrintTitle();\r\n  void PrintTitleLines();\r\n  HRESULT PrintItemInfo(IInArchive *archive, \r\n      const UString &defaultItemName,\r\n      const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n      UInt32 index,\r\n      bool techMode);\r\n  HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs, \r\n      const UInt64 *size, const UInt64 *compressedSize);\r\n};\r\n\r\nvoid CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)\r\n{\r\n  Clear();\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    CFieldInfo fieldInfo;\r\n    const CFieldInfoInit &fieldInfoInit = standardFieldTable[i];\r\n    fieldInfo.PropID = fieldInfoInit.PropID;\r\n    fieldInfo.Name = fieldInfoInit.Name;\r\n    fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment;\r\n    fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment;\r\n    fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth;\r\n    fieldInfo.Width = fieldInfoInit.Width;\r\n    _fields.Add(fieldInfo);\r\n  }\r\n}\r\n\r\nstatic UString GetPropName(PROPID propID, BSTR name)\r\n{\r\n  for (int i = 0; i < sizeof(kPropIdToName) / sizeof(kPropIdToName[0]); i++)\r\n  {\r\n    const CPropIdToName &propIdToName = kPropIdToName[i];\r\n    if (propIdToName.PropID == propID)\r\n      return propIdToName.Name;\r\n  }\r\n  if (name)\r\n    return name;\r\n  return L\"?\";\r\n}\r\n\r\nHRESULT CFieldPrinter::Init(IInArchive *archive)\r\n{\r\n  Clear();\r\n  UInt32 numProps;\r\n  RINOK(archive->GetNumberOfProperties(&numProps));\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    CMyComBSTR name;\r\n    PROPID propID;\r\n    VARTYPE vt;\r\n    RINOK(archive->GetPropertyInfo(i, &name, &propID, &vt));\r\n    CFieldInfo fieldInfo;\r\n    fieldInfo.PropID = propID;\r\n    fieldInfo.Name = GetPropName(propID, name);\r\n    _fields.Add(fieldInfo);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitle()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    PrintString(fieldInfo.TitleAdjustment, \r\n      ((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);\r\n  }\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitleLines()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    for (int i = 0; i < fieldInfo.Width; i++)\r\n      g_StdOut << '-';\r\n  }\r\n}\r\n\r\n\r\nBOOL IsFileTimeZero(CONST FILETIME *lpFileTime)\r\n{\r\n  return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);\r\n}\r\n\r\nstatic const char *kEmptyTimeString = \"                   \";\r\nvoid PrintTime(const NCOM::CPropVariant &propVariant)\r\n{\r\n  if (propVariant.vt != VT_FILETIME)\r\n    throw \"incorrect item\";\r\n  if (IsFileTimeZero(&propVariant.filetime))\r\n    g_StdOut << kEmptyTimeString;\r\n  else\r\n  {\r\n    FILETIME localFileTime;\r\n    if (!FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n      throw \"FileTimeToLocalFileTime error\";\r\n    char s[32];\r\n    if (ConvertFileTimeToString(localFileTime, s, true, true))\r\n      g_StdOut << s;\r\n    else\r\n      g_StdOut << kEmptyTimeString;\r\n  }\r\n}\r\n\r\nHRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive, \r\n    const UString &defaultItemName, \r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    UInt32 index,\r\n    bool techMode)\r\n{\r\n  /*\r\n  if (techMode)\r\n  {\r\n    g_StdOut << \"Index = \";\r\n    g_StdOut << (UInt64)index;\r\n    g_StdOut << endl;\r\n  }\r\n  */\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    if (!techMode)\r\n      PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n\r\n    NCOM::CPropVariant propVariant;\r\n    RINOK(archive->GetProperty(index, fieldInfo.PropID, &propVariant));\r\n    if (techMode)\r\n    {\r\n      g_StdOut << fieldInfo.Name << \" = \";\r\n    }\r\n    int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;\r\n    if (propVariant.vt == VT_EMPTY)\r\n    {\r\n      switch(fieldInfo.PropID)\r\n      {\r\n        case kpidPath:\r\n          propVariant = defaultItemName;\r\n          break;\r\n        case kpidLastWriteTime:\r\n          propVariant = archiveFileInfo.LastWriteTime;\r\n          break;\r\n        default:\r\n          if (techMode)\r\n            g_StdOut << endl;\r\n          else\r\n            PrintSpaces(width);\r\n          continue;\r\n      }\r\n    }\r\n    if (fieldInfo.PropID == kpidLastWriteTime)\r\n    {\r\n      PrintTime(propVariant);\r\n    }\r\n    else if (fieldInfo.PropID == kpidAttributes)\r\n    {\r\n      if (propVariant.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      UInt32 attributes = propVariant.ulVal;\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, index, isFolder));\r\n      char s[8];\r\n      GetAttributesString(attributes, isFolder, s);\r\n      g_StdOut << s;\r\n    }\r\n    else if (propVariant.vt == VT_BSTR)\r\n    {\r\n      if (techMode)\r\n        g_StdOut << propVariant.bstrVal;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, propVariant.bstrVal);\r\n    }\r\n    else\r\n    {\r\n      UString s = ConvertPropertyToString(propVariant, fieldInfo.PropID);\r\n      s.Replace(wchar_t(0xA), L' '); \r\n      s.Replace(wchar_t(0xD), L' '); \r\n\r\n      if (techMode)\r\n        g_StdOut << s;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, s);\r\n    }\r\n    if (techMode)\r\n      g_StdOut << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)\r\n{\r\n  wchar_t textString[32] = { 0 };\r\n  if (value != NULL)\r\n    ConvertUInt64ToString(*value, textString);\r\n  PrintString(adjustment, width, textString);\r\n}\r\n\r\n\r\nHRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs, \r\n    const UInt64 *size, const UInt64 *compressedSize)\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    NCOM::CPropVariant propVariant;\r\n    if (fieldInfo.PropID == kpidSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);\r\n    else if (fieldInfo.PropID == kpidPackedSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);\r\n    else if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      wchar_t textString[32];\r\n      ConvertUInt64ToString(numFiles, textString);\r\n      UString temp = textString;\r\n      temp += L\" \";\r\n      temp += kFilesMessage;\r\n      temp += L\", \";\r\n      ConvertUInt64ToString(numDirs, textString);\r\n      temp += textString;\r\n      temp += L\" \";\r\n      temp += kDirsMessage;\r\n      PrintString(fieldInfo.TextAdjustment, 0, temp);\r\n    }\r\n    else \r\n      PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L\"\");\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nbool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)\r\n{\r\n  NCOM::CPropVariant propVariant;\r\n  if (archive->GetProperty(index, propID, &propVariant) != S_OK)\r\n    throw \"GetPropertyValue error\";\r\n  if (propVariant.vt == VT_EMPTY)\r\n    return false;\r\n  value = ConvertPropVariantToUInt64(propVariant);\r\n  return true;\r\n}\r\n\r\nHRESULT ListArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &numErrors)\r\n{\r\n  numErrors = 0;\r\n  CFieldPrinter fieldPrinter;\r\n  if (!techMode)\r\n    fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));\r\n\r\n  UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;\r\n  UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;\r\n  for (int i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archiveName = archivePaths[i];\r\n    NFile::NFind::CFileInfoW archiveFileInfo;\r\n    if (!NFile::NFind::FindFile(archiveName, archiveFileInfo) || archiveFileInfo.IsDirectory())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not archive\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n    if (archiveFileInfo.IsDirectory())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not file\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    CArchiveLink archiveLink;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &g_StdOut;\r\n    openCallback.PasswordIsDefined = passwordEnabled;\r\n    openCallback.Password = password;\r\n\r\n    HRESULT result = MyOpenArchive(codecs, archiveName, archiveLink, &openCallback);\r\n    if (result != S_OK)\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not supported archive\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n      }\r\n    }\r\n\r\n    IInArchive *archive = archiveLink.GetArchive();\r\n    const UString defaultItemName = archiveLink.GetDefaultItemName();\r\n\r\n    if (enableHeaders)\r\n    {\r\n      g_StdOut << endl << kListing << archiveName << endl << endl;\r\n\r\n      UInt32 numProps;\r\n      if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)\r\n      {\r\n        for (UInt32 i = 0; i < numProps; i++)\r\n        {\r\n          CMyComBSTR name;\r\n          PROPID propID;\r\n          VARTYPE vt;\r\n          if (archive->GetArchivePropertyInfo(i, &name, &propID, &vt) != S_OK)\r\n            continue;\r\n          NCOM::CPropVariant prop;\r\n          if (archive->GetArchiveProperty(propID, &prop) != S_OK)\r\n            continue;\r\n          UString s = ConvertPropertyToString(prop, propID);\r\n          if (!s.IsEmpty())\r\n            g_StdOut << GetPropName(propID, name) << \" = \" << s << endl;\r\n        }\r\n      }\r\n      if (techMode)\r\n        g_StdOut << \"----------\\n\";\r\n      if (numProps > 0)\r\n        g_StdOut << endl;\r\n    }\r\n\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitle();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n    }\r\n\r\n    if (techMode)\r\n    {\r\n      RINOK(fieldPrinter.Init(archive));\r\n    }\r\n    UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0;\r\n    UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;\r\n    UInt32 numItems;\r\n    RINOK(archive->GetNumberOfItems(&numItems));\r\n    for(UInt32 i = 0; i < numItems; i++)\r\n    {\r\n      if (NConsoleClose::TestBreakSignal())\r\n        return E_ABORT;\r\n\r\n      UString filePath;\r\n      RINOK(GetArchiveItemPath(archive, i, defaultItemName, filePath));\r\n\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n      if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n        continue;\r\n      \r\n      fieldPrinter.PrintItemInfo(archive, defaultItemName, archiveFileInfo, i, techMode);\r\n      \r\n      UInt64 packSize, unpackSize;\r\n      if (!GetUInt64Value(archive, i, kpidSize, unpackSize))\r\n        unpackSize = 0;\r\n      else\r\n        totalUnPackSizePointer = &totalUnPackSize;\r\n      if (!GetUInt64Value(archive, i, kpidPackedSize, packSize))\r\n        packSize = 0;\r\n      else\r\n        totalPackSizePointer = &totalPackSize;\r\n      \r\n      g_StdOut << endl;\r\n\r\n      if (isFolder)\r\n        numDirs++;\r\n      else\r\n        numFiles++;\r\n      totalPackSize += packSize;\r\n      totalUnPackSize += unpackSize;\r\n    }\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintSummaryInfo(numFiles, numDirs, totalUnPackSizePointer, totalPackSizePointer);\r\n      g_StdOut << endl;\r\n    }\r\n    if (totalPackSizePointer != 0)\r\n    {\r\n      totalPackSizePointer2 = &totalPackSize2;\r\n      totalPackSize2 += totalPackSize;\r\n    }\r\n    if (totalUnPackSizePointer != 0)\r\n    {\r\n      totalUnPackSizePointer2 = &totalUnPackSize2;\r\n      totalUnPackSize2 += totalUnPackSize;\r\n    }\r\n    numFiles2 += numFiles;\r\n    numDirs2 += numDirs;\r\n  }\r\n  if (enableHeaders && !techMode && archivePaths.Size() > 1)\r\n  {\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintTitleLines();\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintSummaryInfo(numFiles2, numDirs2, totalUnPackSizePointer2, totalPackSizePointer2);\r\n    g_StdOut << endl;\r\n    g_StdOut << \"Archives: \" << archivePaths.Size() << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/List.h",
    "content": "// List.h\r\n\r\n#ifndef __LIST_H\r\n#define __LIST_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nHRESULT ListArchives(\r\n    CCodecs *codecs,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &errors);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/Main.cpp",
    "content": "// Main.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n\r\n#include \"Common/CommandLineParser.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/Error.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/MemoryLock.h\"\r\n#endif\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/UpdateAction.h\"\r\n#include \"../Common/Update.h\"\r\n#include \"../Common/Extract.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"../Common/ExitCode.h\"\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../Common/LoadCodecs.h\"\r\n#endif\r\n\r\n#include \"../../Compress/LZMA_Alone/LzmaBenchCon.h\"\r\n\r\n#include \"List.h\"\r\n#include \"OpenCallbackConsole.h\"\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\n#if defined( _WIN32) && defined( _7ZIP_LARGE_PAGES)\r\nextern \"C\" \r\n{ \r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NCommandLineParser;\r\n\r\nHINSTANCE g_hInstance = 0;\r\nextern CStdOutStream *g_StdStream;\r\n\r\nstatic const char *kCopyrightString = \"\\n7-Zip\"\r\n#ifndef EXTERNAL_CODECS\r\n\" (A)\"\r\n#endif\r\n\r\n#ifdef _WIN64\r\n\" [64]\"\r\n#endif\r\n\r\n\" \" MY_VERSION_COPYRIGHT_DATE \"\\n\";\r\n\r\nstatic const char *kHelpString = \r\n    \"\\nUsage: 7z\"\r\n#ifdef _NO_CRYPTO\r\n    \"r\"\r\n#else\r\n#ifndef EXTERNAL_CODECS\r\n    \"a\"\r\n#endif\r\n#endif\r\n    \" <command> [<switches>...] <archive_name> [<file_names>...]\\n\"\r\n    \"       [<@listfiles...>]\\n\"\r\n    \"\\n\"\r\n    \"<Commands>\\n\"\r\n    \"  a: Add files to archive\\n\"\r\n    \"  b: Benchmark\\n\"\r\n    \"  d: Delete files from archive\\n\"\r\n    \"  e: Extract files from archive (without using directory names)\\n\"\r\n    \"  l: List contents of archive\\n\"\r\n//    \"  l[a|t][f]: List contents of archive\\n\"\r\n//    \"    a - with Additional fields\\n\"\r\n//    \"    t - with all fields\\n\"\r\n//    \"    f - with Full pathnames\\n\"\r\n    \"  t: Test integrity of archive\\n\"\r\n    \"  u: Update files to archive\\n\"\r\n    \"  x: eXtract files with full paths\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -ai[r[-|0]]{@listfile|!wildcard}: Include archives\\n\"\r\n    \"  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives\\n\"\r\n    \"  -bd: Disable percentage indicator\\n\"\r\n    \"  -i[r[-|0]]{@listfile|!wildcard}: Include filenames\\n\"\r\n    \"  -m{Parameters}: set compression Method\\n\"\r\n    \"  -o{Directory}: set Output directory\\n\"\r\n    \"  -p{Password}: set Password\\n\"\r\n    \"  -r[-|0]: Recurse subdirectories\\n\"\r\n    \"  -scs{UTF-8 | WIN | DOS}: set charset for list files\\n\"\r\n    \"  -sfx[{name}]: Create SFX archive\\n\"\r\n    \"  -si[{name}]: read data from stdin\\n\"\r\n    \"  -slt: show technical information for l (List) command\\n\"\r\n    \"  -so: write data to stdout\\n\"\r\n    \"  -ssc[-]: set sensitive case mode\\n\"\r\n    \"  -ssw: compress shared files\\n\"\r\n    \"  -t{Type}: Set type of archive\\n\"\r\n    \"  -v{Size}[b|k|m|g]: Create volumes\\n\"\r\n    \"  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\\n\"\r\n    \"  -w[{path}]: assign Work directory. Empty path means a temporary directory\\n\"\r\n    \"  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\\n\"\r\n    \"  -y: assume Yes on all queries\\n\";\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\"; // NExitCode::kUserError\r\n\r\nstatic const wchar_t *kDefaultSfxModule = L\"7zCon.sfx\";\r\n\r\nstatic void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code)\r\n{\r\n  s << message << endl;\r\n  throw code;\r\n}\r\n\r\nstatic void PrintHelpAndExit(CStdOutStream &s) // yyy\r\n{\r\n  s << kHelpString;\r\n  ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError);\r\n}\r\n\r\n#ifndef _WIN32\r\nstatic void GetArguments(int numArguments, const char *arguments[], UStringVector &parts)\r\n{\r\n  parts.Clear();\r\n  for(int i = 0; i < numArguments; i++)\r\n  {\r\n    UString s = MultiByteToUnicodeString(arguments[i]);\r\n    parts.Add(s);\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp)\r\n{\r\n  s << kCopyrightString;\r\n  // s << \"# CPUs: \" << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << \"\\n\";\r\n  if (needHelp) \r\n    s << kHelpString;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic void PrintString(CStdOutStream &stdStream, const AString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n#endif\r\n\r\nstatic void PrintString(CStdOutStream &stdStream, const UString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n\r\nstatic inline char GetHex(Byte value)\r\n{\r\n  return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nint Main2(\r\n  #ifndef _WIN32  \r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n)\r\n{\r\n  #ifdef _WIN32  \r\n  SetFileApisToOEM();\r\n  #endif\r\n  \r\n  UStringVector commandStrings;\r\n  #ifdef _WIN32  \r\n  NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);\r\n  #else\r\n  GetArguments(numArguments, arguments, commandStrings);\r\n  #endif\r\n\r\n  if(commandStrings.Size() == 1)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n  commandStrings.Delete(0);\r\n\r\n  CArchiveCommandLineOptions options;\r\n\r\n  CArchiveCommandLineParser parser;\r\n\r\n  parser.Parse1(commandStrings, options);\r\n\r\n  if(options.HelpMode)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  if (options.LargePages)\r\n  {\r\n    SetLargePageSize();\r\n    NSecurity::EnableLockMemoryPrivilege();\r\n  }\r\n  #endif\r\n\r\n  CStdOutStream &stdStream = options.StdOutMode ? g_StdErr : g_StdOut;\r\n  g_StdStream = &stdStream;\r\n\r\n  if (options.EnableHeaders)\r\n    ShowCopyrightAndHelp(stdStream, false);\r\n\r\n  parser.Parse2(options);\r\n\r\n  CCodecs *codecs = new CCodecs;\r\n  CMyComPtr<\r\n    #ifdef EXTERNAL_CODECS\r\n    ICompressCodecsInfo\r\n    #else\r\n    IUnknown\r\n    #endif\r\n    > compressCodecsInfo = codecs;\r\n  HRESULT result = codecs->Load();\r\n  if (result != S_OK)\r\n    throw CSystemException(result);\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n  if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n    stdStream << endl << \"Formats:\" << endl;\r\n    int i;\r\n    for (i = 0; i < codecs->Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = codecs->Formats[i];\r\n      #ifdef EXTERNAL_CODECS\r\n      if (arc.LibIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(arc.LibIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n      #endif\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(arc.UpdateEnabled ? 'C' : ' ');\r\n      stdStream << (char)(arc.KeepName ? 'K' : ' ');\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, arc.Name, 6);\r\n      stdStream << \"  \";\r\n      UString s;\r\n      for (int t = 0; t < arc.Exts.Size(); t++)\r\n      {\r\n        const CArcExtInfo &ext = arc.Exts[t];\r\n        s += ext.Ext;\r\n        if (!ext.AddExt.IsEmpty())\r\n        {\r\n          s += L\" (\";\r\n          s += ext.AddExt;\r\n          s += L')';\r\n        }\r\n        s += L' ';\r\n      }\r\n      PrintString(stdStream, s, 14);\r\n      stdStream << \"  \";\r\n      const CByteBuffer &sig = arc.StartSignature;\r\n      for (size_t j = 0; j < sig.GetCapacity(); j++)\r\n      {\r\n        Byte b = sig[j];\r\n        if (b > 0x20 && b < 0x80)\r\n        {\r\n          stdStream << (char)b;\r\n        }\r\n        else\r\n        {\r\n          stdStream << GetHex((Byte)((b >> 4) & 0xF));\r\n          stdStream << GetHex((Byte)(b & 0xF));\r\n        }\r\n        stdStream << ' ';\r\n      }\r\n      stdStream << endl;\r\n    }\r\n    stdStream << endl << \"Codecs:\" << endl;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    UINT32 numMethods;\r\n    if (codecs->GetNumberOfMethods(&numMethods) == S_OK)\r\n    for (UInt32 j = 0; j < numMethods; j++)\r\n    {\r\n      int libIndex = codecs->GetCodecLibIndex(j);\r\n      if (libIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(libIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(codecs->GetCodecEncoderIsAssigned(j) ? 'C' : ' ');\r\n      UInt64 id;\r\n      stdStream << \"  \";\r\n      HRESULT res = codecs->GetCodecId(j, id);\r\n      if (res != S_OK)\r\n        id = (UInt64)(Int64)-1;\r\n      char s[32];\r\n      ConvertUInt64ToString(id, s, 16);\r\n      PrintString(stdStream, s, 8);\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, codecs->GetCodecName(j), 11);\r\n      stdStream << endl;\r\n      /*\r\n      if (res != S_OK)\r\n        throw \"incorrect Codec ID\";\r\n      */\r\n    }\r\n    #endif\r\n    return S_OK;\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    if (options.Method.CompareNoCase(L\"CRC\") == 0)\r\n    {\r\n      HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nCRC Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      HRESULT res = LzmaBenchCon(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        (FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nDecoding Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n  }\r\n  else if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if(isExtractGroupCommand)\r\n    {\r\n      CExtractCallbackConsole *ecs = new CExtractCallbackConsole;\r\n      CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;\r\n\r\n      ecs->OutStream = &stdStream;\r\n      ecs->PasswordIsDefined = options.PasswordEnabled;\r\n      ecs->Password = options.Password;\r\n      ecs->Init();\r\n\r\n      COpenCallbackConsole openCallback;\r\n      openCallback.OutStream = &stdStream;\r\n      openCallback.PasswordIsDefined = options.PasswordEnabled;\r\n      openCallback.Password = options.Password;\r\n\r\n      CExtractOptions eo;\r\n      eo.StdOutMode = options.StdOutMode;\r\n      eo.PathMode = options.Command.GetPathMode();\r\n      eo.TestMode = options.Command.IsTestMode();\r\n      eo.OverwriteMode = options.OverwriteMode;\r\n      eo.OutputDir = options.OutputDir;\r\n      eo.YesToAll = options.YesToAll;\r\n      #ifdef COMPRESS_MT\r\n      eo.Properties = options.ExtractProperties;\r\n      #endif\r\n      UString errorMessage;\r\n      CDecompressStat stat;\r\n      HRESULT result = DecompressArchives(\r\n          codecs,\r\n          options.ArchivePathsSorted, \r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head, \r\n          eo, &openCallback, ecs, errorMessage, stat);\r\n      if (!errorMessage.IsEmpty())\r\n      {\r\n        stdStream << endl << \"Error: \" << errorMessage;\r\n        if (result == S_OK)\r\n          result = E_FAIL;\r\n      }\r\n\r\n      stdStream << endl;\r\n      if (ecs->NumArchives > 1)\r\n        stdStream << \"Archives: \" << ecs->NumArchives << endl;\r\n      if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0)\r\n      {\r\n        if (ecs->NumArchives > 1)\r\n        {\r\n          stdStream << endl;\r\n          if (ecs->NumArchiveErrors != 0)\r\n            stdStream << \"Archive Errors: \" << ecs->NumArchiveErrors << endl;\r\n          if (ecs->NumFileErrors != 0)\r\n            stdStream << \"Sub items Errors: \" << ecs->NumFileErrors << endl;\r\n        }\r\n        if (result != S_OK)\r\n          throw CSystemException(result);\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n      if (stat.NumFolders != 0)\r\n        stdStream << \"Folders: \" << stat.NumFolders << endl;\r\n      if (stat.NumFiles != 1 || stat.NumFolders != 0)\r\n          stdStream << \"Files: \" << stat.NumFiles << endl;\r\n      stdStream \r\n           << \"Size:       \" << stat.UnpackSize << endl\r\n           << \"Compressed: \" << stat.PackSize << endl;\r\n    }\r\n    else\r\n    {\r\n      UInt64 numErrors = 0;\r\n      HRESULT result = ListArchives(\r\n          codecs,\r\n          options.ArchivePathsSorted, \r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head, \r\n          options.EnableHeaders, \r\n          options.TechMode,\r\n          options.PasswordEnabled, \r\n          options.Password, numErrors);\r\n      if (numErrors > 0)\r\n      {\r\n        g_StdOut << endl << \"Errors: \" << numErrors;\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    UString workingDir;\r\n\r\n    CUpdateOptions &uo = options.UpdateOptions;\r\n    if (uo.SfxMode && uo.SfxModule.IsEmpty())\r\n      uo.SfxModule = kDefaultSfxModule;\r\n\r\n    bool passwordIsDefined = \r\n        options.PasswordEnabled && !options.Password.IsEmpty();\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &stdStream;\r\n    openCallback.PasswordIsDefined = passwordIsDefined;\r\n    openCallback.Password = options.Password;\r\n\r\n    CUpdateCallbackConsole callback;\r\n    callback.EnablePercents = options.EnablePercents;\r\n    callback.PasswordIsDefined = passwordIsDefined;\r\n    callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty();\r\n    callback.Password = options.Password;\r\n    callback.StdOutMode = uo.StdOutMode;\r\n    callback.Init(&stdStream);\r\n\r\n    CUpdateErrorInfo errorInfo;\r\n\r\n    if (!uo.Init(codecs, options.ArchiveName, options.ArcType))\r\n      throw \"Unsupported archive type\";\r\n    HRESULT result = UpdateArchive(codecs, \r\n        options.WildcardCensor, uo, \r\n        errorInfo, &openCallback, &callback);\r\n\r\n    int exitCode = NExitCode::kSuccess;\r\n    if (callback.CantFindFiles.Size() > 0)\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      int numErrors = callback.CantFindFiles.Size();\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.CantFindFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.CantFindCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot find \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n\r\n    if (result != S_OK)\r\n    {\r\n      UString message;\r\n      if (!errorInfo.Message.IsEmpty())\r\n      {\r\n        message += errorInfo.Message;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName2.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName2;\r\n        message += L\"\\n\";\r\n      }\r\n      if (errorInfo.SystemError != 0)\r\n      {\r\n        message += NError::MyFormatMessageW(errorInfo.SystemError);\r\n        message += L\"\\n\";\r\n      }\r\n      if (!message.IsEmpty())\r\n        stdStream << L\"\\nError:\\n\" << message;\r\n      throw CSystemException(result);\r\n    }\r\n    int numErrors = callback.FailedFiles.Size();\r\n    if (numErrors == 0)\r\n    {\r\n      if (callback.CantFindFiles.Size() == 0)\r\n        stdStream << kEverythingIsOk << endl;\r\n    }\r\n    else\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.FailedFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.FailedCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot open \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n    return exitCode;\r\n  }\r\n  else \r\n    PrintHelpAndExit(stdStream);\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/MainAr.cpp",
    "content": "// MainAr.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <locale.h>\r\n\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"../Common/ExitCode.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCStdOutStream *g_StdStream = 0;\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\n#endif\r\n#if !defined(_UNICODE) || !defined(_WIN64)\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern int Main2(\r\n  #ifndef _WIN32  \r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n);\r\n\r\nstatic const char *kExceptionErrorMessage = \"\\n\\nError:\\n\";\r\nstatic const char *kUserBreak  = \"\\nBreak signaled\\n\";\r\n\r\nstatic const char *kMemoryExceptionMessage = \"\\n\\nERROR: Can't allocate required memory!\\n\";\r\nstatic const char *kUnknownExceptionMessage = \"\\n\\nUnknown Error\\n\";\r\nstatic const char *kInternalExceptionMessage = \"\\n\\nInternal Error #\";\r\n\r\nint \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\nmain\r\n(\r\n#ifndef _WIN32  \r\nint numArguments, const char *arguments[]\r\n#endif\r\n)\r\n{\r\n  g_StdStream = &g_StdOut;\r\n  #ifdef _WIN32\r\n  \r\n  #ifdef _UNICODE\r\n  #ifndef _WIN64\r\n  if (!IsItWindowsNT())\r\n  {\r\n    (*g_StdStream) << \"This program requires Windows NT/2000/XP/2003/Vista\";\r\n    return NExitCode::kFatalError;\r\n  }\r\n  #endif\r\n  #else\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  \r\n  #endif\r\n\r\n  // setlocale(LC_COLLATE, \".OCP\");\r\n  NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;\r\n  int res = 0;\r\n  try\r\n  {\r\n    res = Main2(\r\n#ifndef _WIN32\r\n      numArguments, arguments\r\n#endif\r\n    );\r\n  }\r\n  catch(const CNewException &)\r\n  {\r\n    (*g_StdStream) << kMemoryExceptionMessage;\r\n    return (NExitCode::kMemoryError);\r\n  }\r\n  catch(const NConsoleClose::CCtrlBreakException &)\r\n  {\r\n    (*g_StdStream) << endl << kUserBreak;\r\n    return (NExitCode::kUserBreak);\r\n  }\r\n  catch(const CArchiveCommandLineException &e)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << e << endl;\r\n    return (NExitCode::kUserError);\r\n  }\r\n  catch(const CSystemException &systemError)\r\n  {\r\n    if (systemError.ErrorCode == E_OUTOFMEMORY)\r\n    {\r\n      (*g_StdStream) << kMemoryExceptionMessage;\r\n      return (NExitCode::kMemoryError);\r\n    }\r\n    if (systemError.ErrorCode == E_ABORT)\r\n    {\r\n      (*g_StdStream) << endl << kUserBreak;\r\n      return (NExitCode::kUserBreak);\r\n    }\r\n    UString message;\r\n    NError::MyFormatMessage(systemError.ErrorCode, message);\r\n    (*g_StdStream) << endl << endl << \"System error:\" << endl << \r\n        message << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(NExitCode::EEnum &exitCode)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << exitCode << endl;\r\n    return (exitCode);\r\n  }\r\n  /*\r\n  catch(const NExitCode::CMultipleErrors &multipleErrors)\r\n  {\r\n    (*g_StdStream) << endl << multipleErrors.NumErrors << \" errors\" << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  */\r\n  catch(const UString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const AString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const char *s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(int t)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << t << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(...)\r\n  {\r\n    (*g_StdStream) << kUnknownExceptionMessage;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  return  res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/OpenCallbackConsole.cpp",
    "content": "// OpenCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nHRESULT COpenCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::SetTotal(const UInt64 *, const UInt64 *)\r\n{\r\n  return CheckBreak();\r\n}\r\n\r\nHRESULT COpenCallbackConsole::SetCompleted(const UInt64 *, const UInt64 *)\r\n{\r\n  return CheckBreak();\r\n}\r\n \r\nHRESULT COpenCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  PasswordWasAsked = true;\r\n  RINOK(CheckBreak());\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream); \r\n    PasswordIsDefined = true;\r\n  }\r\n  CMyComBSTR temp(Password);\r\n  *password = temp.Detach();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::GetPasswordIfAny(UString &password)\r\n{\r\n  if (PasswordIsDefined)\r\n    password = Password;\r\n  return S_OK;\r\n}\r\n\r\nbool COpenCallbackConsole::WasPasswordAsked()\r\n{\r\n  return PasswordWasAsked;\r\n}\r\n\r\nvoid COpenCallbackConsole::ClearPasswordWasAskedFlag()\r\n{\r\n  PasswordWasAsked = false;\r\n}\r\n\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/OpenCallbackConsole.h",
    "content": "// OpenCallbackConsole.h\r\n\r\n#ifndef __OPENCALLBACKCONSOLE_H\r\n#define __OPENCALLBACKCONSOLE_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../Common/ArchiveOpenCallback.h\"\r\n\r\nclass COpenCallbackConsole: public IOpenCallbackUI\r\n{\r\npublic:\r\n  HRESULT CheckBreak();\r\n  HRESULT SetTotal(const UInt64 *files, const UInt64 *bytes);\r\n  HRESULT SetCompleted(const UInt64 *files, const UInt64 *bytes);\r\n  HRESULT CryptoGetTextPassword(BSTR *password);\r\n  HRESULT GetPasswordIfAny(UString &password);\r\n  bool WasPasswordAsked();\r\n  void ClearPasswordWasAskedFlag();\r\n  \r\n  CStdOutStream *OutStream;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool PasswordWasAsked;\r\n  COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/PercentPrinter.cpp",
    "content": "// PercentPrinter.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"PercentPrinter.h\"\r\n\r\nconst int kPaddingSize = 2;\r\nconst int kPercentsSize = 4;\r\nconst int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;\r\n\r\nstatic void ClearPrev(char *p, int num)\r\n{\r\n  int i;\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  for (i = 0; i < num; i++) *p++ = ' ';\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  *p = '\\0';\r\n}\r\n\r\nvoid CPercentPrinter::ClosePrint()\r\n{\r\n  if (m_NumExtraChars == 0)\r\n    return;\r\n  char s[kMaxExtraSize * 3 + 1];\r\n  ClearPrev(s, m_NumExtraChars);\r\n  (*OutStream) << s;\r\n  m_NumExtraChars = 0;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const char *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const wchar_t *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintNewLine()\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << \"\\n\";\r\n}\r\n\r\nvoid CPercentPrinter::RePrintRatio()\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s);\r\n  int size = (int)strlen(s);\r\n  s[size++] = '%';\r\n  s[size] = '\\0';\r\n\r\n  int extraSize = kPaddingSize + MyMax(size, kPercentsSize);\r\n  if (extraSize < m_NumExtraChars)\r\n    extraSize = m_NumExtraChars;\r\n\r\n  char fullString[kMaxExtraSize * 3];\r\n  char *p = fullString;\r\n  int i;\r\n  if (m_NumExtraChars == 0)\r\n  {\r\n    for (i = 0; i < extraSize; i++) \r\n      *p++ = ' ';\r\n    m_NumExtraChars = extraSize;\r\n  }\r\n\r\n  for (i = 0; i < m_NumExtraChars; i++) \r\n    *p++ = '\\b';\r\n  m_NumExtraChars = extraSize;\r\n  for (; size < m_NumExtraChars; size++)\r\n    *p++ = ' ';\r\n  MyStringCopy(p, s);\r\n  (*OutStream) << fullString;\r\n  OutStream->Flush(); \r\n  m_PrevValue = m_CurValue;\r\n}\r\n\r\nvoid CPercentPrinter::PrintRatio()\r\n{\r\n  if (m_CurValue < m_PrevValue + m_MinStepSize && \r\n      m_CurValue + m_MinStepSize > m_PrevValue && m_NumExtraChars != 0)\r\n    return;\r\n  RePrintRatio();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/PercentPrinter.h",
    "content": "// PercentPrinter.h\r\n\r\n#ifndef __PERCENTPRINTER_H\r\n#define __PERCENTPRINTER_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/StdOutStream.h\"\r\n\r\nclass CPercentPrinter\r\n{\r\n  UInt64 m_MinStepSize;\r\n  UInt64 m_PrevValue;\r\n  UInt64 m_CurValue;\r\n  UInt64 m_Total;\r\n  int m_NumExtraChars;\r\npublic:\r\n  CStdOutStream *OutStream;\r\n\r\n  CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize), \r\n      m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}\r\n  void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }\r\n  void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }\r\n  void PrintString(const char *s);\r\n  void PrintString(const wchar_t *s);\r\n  void PrintNewLine();\r\n  void ClosePrint();\r\n  void RePrintRatio();\r\n  void PrintRatio();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp",
    "content": "// UpdateCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifdef COMPRESS_MT\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nusing namespace NWindows;\r\n\r\n#ifdef COMPRESS_MT\r\nstatic NSynchronization::CCriticalSection g_CriticalSection;\r\n#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);\r\n#else\r\n#define MT_LOCK\r\n#endif\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nstatic const char *kCreatingArchiveMessage = \"Creating archive \";\r\nstatic const char *kUpdatingArchiveMessage = \"Updating archive \";\r\nstatic const char *kScanningMessage = \"Scanning\";\r\n\r\n\r\nHRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n    (*OutStream) << \"Error: \" << name << \" is not supported archive\" << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartScanning()\r\n{\r\n  (*OutStream) << kScanningMessage;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)\r\n{\r\n  CantFindFiles.Add(name);\r\n  CantFindCodes.Add(systemError);\r\n  // m_PercentPrinter.ClosePrint();\r\n  if (!m_WarningsMode)\r\n  {\r\n    (*OutStream) << endl << endl;\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_WarningsMode = true;\r\n  }\r\n  m_PercentPrinter.PrintString(name);\r\n  m_PercentPrinter.PrintString(\":  WARNING: \");\r\n  m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n  m_PercentPrinter.PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishScanning()\r\n{\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)\r\n{\r\n  if(updating)\r\n    (*OutStream) << kUpdatingArchiveMessage;\r\n  else\r\n    (*OutStream) << kCreatingArchiveMessage; \r\n  if (name != 0)\r\n    (*OutStream) << name;\r\n  else\r\n    (*OutStream) << \"StdOut\";\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishArchive()\r\n{\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::Finilize()\r\n{\r\n  MT_LOCK\r\n  if (m_NeedBeClosed)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.ClosePrint();\r\n    }\r\n    if (!StdOutMode && m_NeedNewLine)\r\n    {\r\n      m_PercentPrinter.PrintNewLine();\r\n      m_NeedNewLine = false;\r\n    }\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)\r\n{\r\n  MT_LOCK\r\n  if (EnablePercents)\r\n    m_PercentPrinter.SetTotal(size);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  MT_LOCK\r\n  if (completeValue != NULL)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.SetRatio(*completeValue);\r\n      m_PercentPrinter.PrintRatio();\r\n      m_NeedBeClosed = true;\r\n    }\r\n  }\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  /*\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  */\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)\r\n{\r\n  MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  if(isAnti)\r\n    m_PercentPrinter.PrintString(\"Anti item    \");\r\n  else\r\n    m_PercentPrinter.PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)\r\n{\r\n  MT_LOCK\r\n  FailedCodes.Add(systemError);\r\n  FailedFiles.Add(name);\r\n  // if (systemError == ERROR_SHARING_VIOLATION)\r\n  {\r\n    m_PercentPrinter.ClosePrint();\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_PercentPrinter.PrintString(\"WARNING: \");\r\n    m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n    return S_FALSE;\r\n  }\r\n  // return systemError;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )\r\n{\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;  \r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined) \r\n  {\r\n    if (AskPassword)\r\n    {\r\n      Password = GetPassword(OutStream); \r\n      PasswordIsDefined = true;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  CMyComBSTR tempName(Password);\r\n  *password = tempName.Detach();\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.h",
    "content": "// UpdateCallbackConsole.h\r\n\r\n#ifndef __UPDATECALLBACKCONSOLE_H\r\n#define __UPDATECALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"PercentPrinter.h\"\r\n#include \"../Common/Update.h\"\r\n\r\nclass CUpdateCallbackConsole: public IUpdateCallbackUI2\r\n{\r\n  CPercentPrinter m_PercentPrinter;\r\n  bool m_NeedBeClosed;\r\n  bool m_NeedNewLine;\r\n\r\n  bool m_WarningsMode;\r\n\r\n  CStdOutStream *OutStream;\r\npublic:\r\n  bool EnablePercents;\r\n  bool StdOutMode;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n\r\n  CUpdateCallbackConsole(): \r\n      m_PercentPrinter(1 << 16),\r\n      PasswordIsDefined(false),\r\n      AskPassword(false),\r\n      StdOutMode(false),\r\n      EnablePercents(true),\r\n      m_WarningsMode(false)\r\n      {}\r\n  \r\n  ~CUpdateCallbackConsole() { Finilize(); }\r\n  void Init(CStdOutStream *outStream)\r\n  {\r\n    m_NeedBeClosed = false;\r\n    m_NeedNewLine = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n    OutStream = outStream;\r\n    m_PercentPrinter.OutStream = outStream;\r\n  }\r\n\r\n  INTERFACE_IUpdateCallbackUI2(;)\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  UStringVector CantFindFiles;\r\n  CRecordVector<HRESULT> CantFindCodes;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/UserInputUtils.cpp",
    "content": "// UserInputUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StdInStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"UserInputUtils.h\"\r\n\r\nstatic const char kYes = 'Y';\r\nstatic const char kNo = 'N';\r\nstatic const char kYesAll = 'A';\r\nstatic const char kNoAll = 'S';\r\nstatic const char kAutoRename = 'U';\r\nstatic const char kQuit = 'Q';\r\n\r\nstatic const char *kFirstQuestionMessage = \"?\\n\";\r\nstatic const char *kHelpQuestionMessage = \r\n  \"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename / (Q)uit? \";\r\n\r\n// return true if pressed Quite;\r\n// in: anAll\r\n// out: anAll, anYes;\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << kFirstQuestionMessage;\r\n  for(;;)\r\n  {\r\n    (*outStream) << kHelpQuestionMessage;\r\n    AString scannedString = g_StdIn.ScanStringUntilNewLine();\r\n    scannedString.Trim();\r\n    if(!scannedString.IsEmpty())\r\n      switch(::MyCharUpper(scannedString[0]))\r\n      {\r\n        case kYes:\r\n          return NUserAnswerMode::kYes;\r\n        case kNo:\r\n          return NUserAnswerMode::kNo;\r\n        case kYesAll:\r\n          return NUserAnswerMode::kYesAll;\r\n        case kNoAll:\r\n          return NUserAnswerMode::kNoAll;\r\n        case kAutoRename:\r\n          return NUserAnswerMode::kAutoRename;\r\n        case kQuit:\r\n          return NUserAnswerMode::kQuit;\r\n      }\r\n  }\r\n}\r\n\r\nUString GetPassword(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << \"\\nEnter password:\";\r\n  outStream->Flush();\r\n  AString oemPassword = g_StdIn.ScanStringUntilNewLine();\r\n  return MultiByteToUnicodeString(oemPassword, CP_OEMCP); \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/UserInputUtils.h",
    "content": "// UserInputUtils.h\r\n\r\n#ifndef __USERINPUTUTILS_H\r\n#define __USERINPUTUTILS_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n\r\nnamespace NUserAnswerMode {\r\n\r\nenum EEnum\r\n{\r\n  kYes,\r\n  kNo,\r\n  kYesAll,\r\n  kNoAll,\r\n  kAutoRename,\r\n  kQuit\r\n};\r\n}\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);\r\nUString GetPassword(CStdOutStream *outStream);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/7zip/UI/Console/afxres.h",
    "content": "#include <winresrc.h>\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Build.mak",
    "content": "!IFDEF CPU\r\nLIBS = $(LIBS) bufferoverflowU.lib \r\nCFLAGS = $(CFLAGS) -GS- -Zc:forScope\r\n!ENDIF\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IF \"$(CPU)\" != \"IA64\"\r\n!IF \"$(CPU)\" != \"AMD64\"\r\nMY_ML = ml\r\n!ELSE\r\nMY_ML = ml64\r\n!ENDIF\r\n!ENDIF\r\n\r\nCOMPL_ASM = $(MY_ML) -c -Fo$O/ $**\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -EHsc -Gz -WX -Gy\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\n!IFDEF NEW_COMPILER\r\nCFLAGS_O1 = $(CFLAGS) -O1 -W4 -Wp64\r\nCFLAGS_O2 = $(CFLAGS) -O2 -W4 -Wp64\r\n!ELSE\r\nCFLAGS_O1 = $(CFLAGS) -O1 -W3\r\nCFLAGS_O2 = $(CFLAGS) -O2 -W3\r\n!ENDIF\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF \r\n\r\n!IFDEF DEF_FILE\r\nLFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)\r\n!ENDIF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL_PCH  = $(CPP) $(CFLAGS_O1) -Yc\"StdAfx.h\" -Fp$O/a.pch $** \r\nCOMPL      = $(CPP) $(CFLAGS_O1) -Yu\"StdAfx.h\" -Fp$O/a.pch $**\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS) $(DEF_FILE)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n$O\\resource.res: $(*B).rc\r\n\trc -fo$@ $**\r\n$O\\StdAfx.obj: $(*B).cpp\r\n\t$(COMPL_PCH)\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/AutoPtr.h",
    "content": "// Common/AutoPtr.h\r\n\r\n#ifndef __COMMON_AUTOPTR_H\r\n#define __COMMON_AUTOPTR_H\r\n\r\ntemplate<class T> class CMyAutoPtr\r\n{\r\n  T *_p;\r\npublic:\r\n  CMyAutoPtr(T *p = 0) : _p(p) {}\r\n  CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {}\r\n  CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p) \r\n  {\r\n    reset(p.release());\r\n    return (*this);\r\n  }\r\n  ~CMyAutoPtr() { delete _p; }\r\n  T& operator*() const { return *_p; }\r\n  // T* operator->() const { return (&**this); }\r\n  T* get() const { return _p; }\r\n  T* release()\r\n  {\r\n    T *tmp = _p;\r\n    _p = 0;\r\n    return tmp;\r\n  }\r\n  void reset(T* p = 0)\r\n  {\r\n    if (p != _p)\r\n      delete _p;\r\n    _p = p;\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/Buffer.h",
    "content": "// Common/Buffer.h\r\n\r\n#ifndef __COMMON_BUFFER_H\r\n#define __COMMON_BUFFER_H\r\n\r\n#include \"Defs.h\"\r\n\r\ntemplate <class T> class CBuffer\r\n{    \r\nprotected:\r\n  size_t _capacity;\r\n  T *_items;\r\npublic:\r\n  void Free()\r\n  {\r\n    delete []_items;\r\n    _items = 0;\r\n    _capacity = 0;\r\n  }\r\n  CBuffer(): _capacity(0), _items(0) {};\r\n  CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }\r\n  CBuffer(size_t size): _items(0),  _capacity(0) {  SetCapacity(size); }\r\n  virtual ~CBuffer() { delete []_items; }\r\n  operator T *() { return _items; };\r\n  operator const T *() const { return _items; };\r\n  size_t GetCapacity() const { return  _capacity; }\r\n  void SetCapacity(size_t newCapacity)\r\n  {\r\n    if (newCapacity == _capacity)\r\n      return;\r\n    T *newBuffer;\r\n    if (newCapacity > 0)\r\n    {\r\n      newBuffer = new T[newCapacity];\r\n      if(_capacity > 0)\r\n        memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));\r\n    }\r\n    else\r\n      newBuffer = 0;\r\n    delete []_items;\r\n    _items = newBuffer;\r\n    _capacity = newCapacity;\r\n  }\r\n  CBuffer& operator=(const CBuffer &buffer)\r\n  {\r\n    Free();\r\n    if(buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nbool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  if (b1.GetCapacity() != b2.GetCapacity())\r\n    return false;\r\n  for (size_t i = 0; i < b1.GetCapacity(); i++)\r\n    if (b1[i] != b2[i])\r\n      return false;\r\n  return true;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  return !(b1 == b2);\r\n}\r\n\r\ntypedef CBuffer<char> CCharBuffer;\r\ntypedef CBuffer<wchar_t> CWCharBuffer;\r\ntypedef CBuffer<unsigned char> CByteBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../C/7zCrc.h\"\r\n}\r\n\r\nclass CCRCTableInit\r\n{\r\npublic:\r\n  CCRCTableInit() { CrcGenerateTable(); }\r\n} g_CRCTableInit;\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nbool CInFile::OpenShared(const char *name, bool)\r\n{\r\n  return Open(name);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nbool COutFile::Open(const char *name, DWORD creationDisposition)\r\n{\r\n  return Create(name, false);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  bool OpenShared(const char *name, bool shareForWrite);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  bool Open(const char *name, DWORD creationDisposition);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else \r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  for (;;)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      break;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{ \r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */); \r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms, \r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0) \r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while(pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len) \r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString: \r\n      case NSwitchType::kUnLimitedPostString: \r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for(int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString)\r\n{\r\n  for(int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if(commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"MyString.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  { \r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms); \r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms, \r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/DynamicBuffer.h",
    "content": "// Common/DynamicBuffer.h\r\n\r\n#ifndef __COMMON_DYNAMICBUFFER_H\r\n#define __COMMON_DYNAMICBUFFER_H\r\n\r\n#include \"Buffer.h\"\r\n\r\ntemplate <class T> class CDynamicBuffer: public CBuffer<T>\r\n{    \r\n  void GrowLength(size_t size)\r\n  {\r\n    size_t delta;\r\n    if (this->_capacity > 64)\r\n      delta = this->_capacity / 4;\r\n    else if (this->_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    delta = MyMax(delta, size);\r\n    SetCapacity(this->_capacity + delta);\r\n  }\r\npublic:\r\n  CDynamicBuffer(): CBuffer<T>() {};\r\n  CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};\r\n  CDynamicBuffer(size_t size): CBuffer<T>(size) {};\r\n  CDynamicBuffer& operator=(const CDynamicBuffer &buffer)\r\n  {\r\n    this->Free();\r\n    if(buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n  void EnsureCapacity(size_t capacity)\r\n  {\r\n    if (this->_capacity < capacity)\r\n      GrowLength(capacity - this->_capacity);\r\n  }\r\n};\r\n\r\ntypedef CDynamicBuffer<char> CCharDynamicBuffer;\r\ntypedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;\r\ntypedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/IntToString.cpp",
    "content": "// Common/IntToString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"IntToString.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)\r\n{\r\n  if (base < 2 || base > 36)\r\n  {\r\n    *s = '\\0';\r\n    return;\r\n  }\r\n  char temp[72];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    int delta = (int)(value % base);\r\n    temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));\r\n    value /= base;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while(pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s)\r\n{\r\n  wchar_t temp[32];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do \r\n    *s++ = temp[--pos];\r\n  while(pos > 0);\r\n  *s = L'\\0';\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = '-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = L'-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/IntToString.h",
    "content": "// Common/IntToString.h\r\n\r\n#ifndef __COMMON_INTTOSTRING_H\r\n#define __COMMON_INTTOSTRING_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s);\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s);\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/ListFileUtils.cpp",
    "content": "// Common/ListFileUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Windows/FileIO.h\"\r\n\r\n#include \"ListFileUtils.h\"\r\n#include \"StringConvert.h\"\r\n#include \"UTFConvert.h\"\r\n\r\nstatic const char kQuoteChar     = '\\\"';\r\nstatic void RemoveQuote(UString &s)\r\n{\r\n  if (s.Length() >= 2)\r\n    if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)\r\n      s = s.Mid(1, s.Length() - 2);\r\n}\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)\r\n{\r\n  NWindows::NFile::NIO::CInFile file;\r\n  if (!file.Open(fileName))\r\n    return false;\r\n  UInt64 length;\r\n  if (!file.GetLength(length))\r\n    return false;\r\n  if (length > ((UInt32)1 << 31))\r\n    return false;\r\n  AString s;\r\n  char *p = s.GetBuffer((int)length + 1);\r\n  UInt32 processed;\r\n  if (!file.Read(p, (UInt32)length, processed))\r\n    return false;\r\n  p[(UInt32)length] = 0;\r\n  s.ReleaseBuffer();\r\n  file.Close();\r\n\r\n  UString u;\r\n  #ifdef CP_UTF8\r\n  if (codePage == CP_UTF8)\r\n  {\r\n    if (!ConvertUTF8ToUnicode(s, u))\r\n      return false;\r\n  }\r\n  else\r\n  #endif\r\n    u = MultiByteToUnicodeString(s, codePage);\r\n  if (!u.IsEmpty())\r\n  {\r\n    if (u[0] == 0xFEFF)\r\n      u.Delete(0);\r\n  }\r\n\r\n  UString t;\r\n  for(int i = 0; i < u.Length(); i++)\r\n  {\r\n    wchar_t c = u[i];\r\n    if (c == L'\\n' || c == 0xD)\r\n    {\r\n      t.Trim();\r\n      RemoveQuote(t);\r\n      if (!t.IsEmpty())\r\n        resultStrings.Add(t);\r\n      t.Empty();\r\n    }\r\n    else\r\n      t += c;\r\n  }\r\n  t.Trim();\r\n  RemoveQuote(t);\r\n  if (!t.IsEmpty())\r\n    resultStrings.Add(t);\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/ListFileUtils.h",
    "content": "// Common/ListFileUtils.h\r\n\r\n#ifndef __COMMON_LISTFILEUTILS_H\r\n#define __COMMON_LISTFILEUTILS_H\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }\r\n#endif\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p) \r\n  { \r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p) \r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR() { m_str = NULL; }\r\n  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR pSrc)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(pSrc);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const \r\n  { \r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memmove(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  void Attach(BSTR src) {  m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) { \r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \\\r\n    { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \\\r\n    MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n    MY_QUERYINTERFACE_ENTRY(i)\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyException.h",
    "content": "// Common/Exception.h\r\n\r\n#ifndef __COMMON_EXCEPTION_H\r\n#define __COMMON_EXCEPTION_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\nstruct CSystemException\r\n{\r\n  HRESULT ErrorCode;\r\n  CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline int operator==(REFGUID g1, REFGUID g2)\r\n{ \r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return 0;\r\n  return 1;\r\n}\r\ninline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyString.cpp",
    "content": "// Common/MyString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"StringConvert.h\"\r\n#else\r\n#include <ctype.h>\r\n#endif\r\n\r\n#include \"MyString.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{ \r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1), \r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), \r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{ \r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyString.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{ \r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{ \r\n  T *destStart = dest;\r\n  while((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char  *s2);\r\n#endif\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex, \r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n  int _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if(realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if(newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if(_capacity > 0)\r\n    {\r\n      for (int i = 0; i < (_length + 1); i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n      _chars = newBuffer;\r\n    }\r\n    else\r\n    {\r\n      _chars = newBuffer;\r\n      _chars[0] = 0;\r\n    }\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize) \r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0)\r\n    { SetCapacity(16 - 1); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;} \r\n\r\n  // The minimum size of the character buffer in characters. \r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if(minBufLength >= _capacity)\r\n      SetCapacity(minBufLength + 1);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if(newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length; \r\n    return *this;\r\n  }  \r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if(&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int Compare(const T *s) const\r\n    { return MyStringCompare(_chars, s); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const T *s) const\r\n    { return MyStringCompareNoCase(_chars, s); }\r\n\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for(int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    charSet += (T)' ';\r\n    charSet += (T)'\\n';\r\n    charSet += (T)'\\t';\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for(int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0) \r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0) \r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct \r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else \r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyVector.cpp",
    "content": "// Common/MyVector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector() { Free(); }\r\n\r\nvoid CBaseRecordVector::Free()\r\n{ \r\n  delete []((unsigned char *)_items); \r\n  _capacity = 0;\r\n  _size = 0;\r\n  _items = 0;\r\n}\r\n\r\nvoid CBaseRecordVector::Clear() { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index) { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if (_size != _capacity)\r\n    return;\r\n  int delta;\r\n  if (_capacity > 64)\r\n    delta = _capacity / 2;\r\n  else if (_capacity > 8)\r\n    delta = 8;\r\n  else\r\n    delta = 4;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  if (newCapacity <= _capacity)\r\n    return;\r\n  if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))\r\n    throw 1052353;\r\n  size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;\r\n  if (newSize / _itemSize != (size_t)(unsigned)newCapacity)\r\n    throw 1052354;\r\n  unsigned char *p = new unsigned char[newSize];\r\n  if (p == 0)\r\n    throw 1052355;\r\n  int numRecordsToMove = _capacity;\r\n  memmove(p, _items, _itemSize * numRecordsToMove);\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize, \r\n    ((unsigned char  *)_items) + srcIndex * _itemSize, \r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyVector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n  int _capacity;\r\n  int _size;\r\n  void *_items;\r\n  size_t _itemSize;\r\n  \r\n  void ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; } \r\npublic:\r\n  CBaseRecordVector(size_t itemSize):\r\n      _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n  virtual ~CBaseRecordVector();\r\n  void Free();\r\n  int Size() const { return _size; }\r\n  bool IsEmpty() const { return (_size == 0); }\r\n  void Reserve(int newCapacity);\r\n  virtual void Delete(int index, int num = 1);\r\n  void Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector():CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v):\r\n    CBaseRecordVector(sizeof(T)) { *this = v;}\r\n  CRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  int Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n  void Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n  T& operator[](int index) { return ((T *)_items)[index]; }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Front()   { return operator[](0); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  T& Back()   { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  int AddToUniqueSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)\r\n  { \r\n    T temp = p[k];\r\n    for (;;)\r\n    {\r\n      int s = (k << 1);\r\n      if (s > size)\r\n        break;\r\n      if (s < size && compare(p + s + 1, p + s, param) > 0)\r\n        s++;\r\n      if (compare(&temp, p + s, param) >= 0)\r\n        break;\r\n      p[k] = p[s]; \r\n      k = s;\r\n    } \r\n    p[k] = temp; \r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    int size = _size;\r\n    if (size <= 1)\r\n      return;\r\n    T* p = (&Front()) - 1;\r\n    {\r\n      int i = size / 2;\r\n      do\r\n        SortRefDown(p, i, size, compare, param);\r\n      while(--i != 0);\r\n    }\r\n    do\r\n    {\r\n      T temp = p[size];\r\n      p[size--] = p[1];\r\n      p[1] = temp;\r\n      SortRefDown(p, 1, size, compare, param);\r\n    }\r\n    while (size > 1);\r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector(){};\r\n  ~CObjectVector() { Clear(); }\r\n  CObjectVector(const CObjectVector &objectVector)\r\n    { *this = objectVector; }\r\n  CObjectVector& operator=(const CObjectVector &objectVector)\r\n  {\r\n    Clear();\r\n    return (*this += objectVector);\r\n  }\r\n  CObjectVector& operator+=(const CObjectVector &objectVector)\r\n  {\r\n    int size = objectVector.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(objectVector[i]);\r\n    return *this;\r\n  }\r\n  const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n  T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Back() { return operator[](_size - 1); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  int Add(const T& item)\r\n    { return CPointerVector::Add(new T(item)); }\r\n  void Insert(int index, const T& item)\r\n    { CPointerVector::Insert(index, new T(item)); }\r\n  virtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for(int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for(int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n      return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param) \r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#define CHAR_PATH_SEPARATOR '\\\\'\r\n#define WCHAR_PATH_SEPARATOR L'\\\\'\r\n#define STRING_PATH_SEPARATOR \"\\\\\"\r\n#define WSTRING_PATH_SEPARATOR L\"\\\\\"\r\n\r\n#else\r\n\r\n#define CHAR_PATH_SEPARATOR '/'\r\n#define WCHAR_PATH_SEPARATOR L'/'\r\n#define STRING_PATH_SEPARATOR \"/\"\r\n#define WSTRING_PATH_SEPARATOR L\"/\"\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\n\r\n#undef BYTE\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\n\r\n#undef WORD\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\n\r\n#undef DWORD\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOTIMPL ((HRESULT)0x80004001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall \r\n#else\r\n#define STDMETHODCALLTYPE \r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct \r\n\r\n#ifdef __cplusplus\r\n\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n  #ifndef _WIN32\r\n  virtual ~IUnknown() {}\r\n  #endif\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#endif\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\r\n  VT_EMPTY = 0,\r\n  VT_NULL = 1,\r\n  VT_I2 = 2,\r\n  VT_I4 = 3,\r\n  VT_R4 = 4,\r\n  VT_R8 = 5,\r\n  VT_CY = 6,\r\n  VT_DATE = 7,\r\n  VT_BSTR = 8,\r\n  VT_DISPATCH = 9,\r\n  VT_ERROR = 10,\r\n  VT_BOOL = 11,\r\n  VT_VARIANT = 12,\r\n  VT_UNKNOWN = 13,\r\n  VT_DECIMAL = 14,\r\n  VT_I1 = 16,\r\n  VT_UI1 = 17,\r\n  VT_UI2 = 18,\r\n  VT_UI4 = 19,\r\n  VT_I8 = 20,\r\n  VT_UI8 = 21,\r\n  VT_INT = 22,\r\n  VT_UINT = 23,\r\n  VT_VOID = 24,\r\n  VT_HRESULT = 25,\r\n  VT_FILETIME = 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\n#ifdef __cplusplus\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union \r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\n\r\n#endif\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\r\n  STREAM_SEEK_SET = 0,\r\n  STREAM_SEEK_CUR = 1,\r\n  STREAM_SEEK_END = 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\n#ifdef _WIN32\r\nvoid * \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n#endif\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\n#ifdef _WIN32\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw();\r\n#endif \r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/StdInStream.cpp",
    "content": "// Common/StdInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n#include \"StdInStream.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kIllegalChar = '\\0';\r\nstatic const char kNewLineChar = '\\n';\r\n\r\nstatic const char *kEOFMessage = \"Unexpected end of input stream\";\r\nstatic const char *kReadErrorMessage  =\"Error reading input stream\"; \r\nstatic const char *kIllegalCharMessage = \"Illegal character in input stream\";\r\n\r\nstatic LPCTSTR kFileOpenMode = TEXT(\"r\");\r\n\r\nCStdInStream g_StdIn(stdin);\r\n\r\nbool CStdInStream::Open(LPCTSTR fileName)\r\n{\r\n  Close();\r\n  _stream = _tfopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdInStream::Close()\r\n{\r\n  if(!_streamIsOpen)\r\n    return true;\r\n  _streamIsOpen = (fclose(_stream) != 0);\r\n  return !_streamIsOpen;\r\n}\r\n\r\nCStdInStream::~CStdInStream()\r\n{\r\n  Close();\r\n}\r\n\r\nAString CStdInStream::ScanStringUntilNewLine()\r\n{\r\n  AString s;\r\n  for (;;)\r\n  {\r\n    int intChar = GetChar();\r\n    if(intChar == EOF)\r\n      throw kEOFMessage;\r\n    char c = char(intChar);\r\n    if (c == kIllegalChar)\r\n      throw kIllegalCharMessage;\r\n    if(c == kNewLineChar)\r\n      break;\r\n    s += c;\r\n  }\r\n  return s;\r\n}\r\n\r\nvoid CStdInStream::ReadToString(AString &resultString)\r\n{\r\n  resultString.Empty();\r\n  int c;\r\n  while((c = GetChar()) != EOF)\r\n    resultString += char(c);\r\n}\r\n\r\nbool CStdInStream::Eof()\r\n{\r\n  return (feof(_stream) != 0);\r\n}\r\n\r\nint CStdInStream::GetChar()\r\n{\r\n  int c = fgetc(_stream); // getc() doesn't work in BeOS?\r\n  if(c == EOF && !Eof())\r\n    throw kReadErrorMessage;\r\n  return c;\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/StdInStream.h",
    "content": "// Common/StdInStream.h\r\n\r\n#ifndef __COMMON_STDINSTREAM_H\r\n#define __COMMON_STDINSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nclass CStdInStream \r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdInStream(): _streamIsOpen(false) {};\r\n  CStdInStream(FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdInStream();\r\n  bool Open(LPCTSTR fileName);\r\n  bool Close();\r\n\r\n  AString ScanStringUntilNewLine();\r\n  void ReadToString(AString &resultString);\r\n\r\n  bool Eof();\r\n  int GetChar();\r\n};\r\n\r\nextern CStdInStream g_StdIn;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/StdOutStream.cpp",
    "content": "// Common/StdOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n\r\n#include \"StdOutStream.h\"\r\n#include \"IntToString.h\"\r\n#include \"StringConvert.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kNewLineChar =  '\\n';\r\n\r\nstatic const char *kFileOpenMode = \"wt\";\r\n\r\nCStdOutStream  g_StdOut(stdout);\r\nCStdOutStream  g_StdErr(stderr);\r\n\r\nbool CStdOutStream::Open(const char *fileName)\r\n{\r\n  Close();\r\n  _stream = fopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdOutStream::Close()\r\n{\r\n  if(!_streamIsOpen)\r\n    return true;\r\n  if (fclose(_stream) != 0)\r\n    return false;\r\n  _stream = 0;\r\n  _streamIsOpen = false;\r\n  return true;\r\n}\r\n\r\nbool CStdOutStream::Flush()\r\n{\r\n  return (fflush(_stream) == 0);\r\n}\r\n\r\nCStdOutStream::~CStdOutStream ()\r\n{\r\n  Close();\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream  &))\r\n{\r\n  (*aFunction)(*this);    \r\n  return *this;\r\n}\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream)\r\n{\r\n  return outStream << kNewLineChar;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const char *string)\r\n{\r\n  fputs(string, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const wchar_t *string)\r\n{\r\n  *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(char c)\r\n{\r\n  fputc(c, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(int number)\r\n{\r\n  char textString[32];\r\n  ConvertInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(UInt64 number)\r\n{\r\n  char textString[32];\r\n  ConvertUInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/StdOutStream.h",
    "content": "// Common/StdOutStream.h\r\n\r\n#ifndef __COMMON_STDOUTSTREAM_H\r\n#define __COMMON_STDOUTSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Types.h\"\r\n\r\nclass CStdOutStream \r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdOutStream (): _streamIsOpen(false), _stream(0) {};\r\n  CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdOutStream ();\r\n  operator FILE *() { return _stream; }\r\n  bool Open(const char *fileName);\r\n  bool Close();\r\n  bool Flush();\r\n  CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream  &));\r\n  CStdOutStream & operator<<(const char *string);\r\n  CStdOutStream & operator<<(const wchar_t *string);\r\n  CStdOutStream & operator<<(char c);\r\n  CStdOutStream & operator<<(int number);\r\n  CStdOutStream & operator<<(UInt64 number);\r\n};\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream);\r\n\r\nextern CStdOutStream g_StdOut;\r\nextern CStdOutStream g_StdErr;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()), \r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 2;\r\n    char defaultChar = '_';\r\n    int numChars = WideCharToMultiByte(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(numRequiredBytes), \r\n      numRequiredBytes + 1, &defaultChar, NULL);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\n#ifndef _7ZIP_BYTE_DEFINED\r\n#define _7ZIP_BYTE_DEFINED\r\ntypedef unsigned char Byte;\r\n#endif \r\n\r\n#ifndef _7ZIP_INT16_DEFINED\r\n#define _7ZIP_INT16_DEFINED\r\ntypedef short Int16;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT16_DEFINED\r\n#define _7ZIP_UINT16_DEFINED\r\ntypedef unsigned short UInt16;\r\n#endif \r\n\r\n#ifndef _7ZIP_INT32_DEFINED\r\n#define _7ZIP_INT32_DEFINED\r\ntypedef int Int32;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT32_DEFINED\r\n#define _7ZIP_UINT32_DEFINED\r\ntypedef unsigned int UInt32;\r\n#endif \r\n\r\n#ifdef _MSC_VER\r\n\r\n#ifndef _7ZIP_INT64_DEFINED\r\n#define _7ZIP_INT64_DEFINED\r\ntypedef __int64 Int64;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\ntypedef unsigned __int64 UInt64;\r\n#endif \r\n\r\n#else\r\n\r\n#ifndef _7ZIP_INT64_DEFINED\r\n#define _7ZIP_INT64_DEFINED\r\ntypedef long long int Int64;\r\n#endif \r\n\r\n#ifndef _7ZIP_UINT64_DEFINED\r\n#define _7ZIP_UINT64_DEFINED\r\ntypedef unsigned long long int UInt64;\r\n#endif \r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/UTFConvert.cpp",
    "content": "// UTFConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UTFConvert.h\"\r\n#include \"Types.h\"\r\n\r\nstatic Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\n// These functions are for UTF8 <-> UTF16 conversion.\r\n\r\nbool ConvertUTF8ToUnicode(const AString &src, UString &dest)\r\n{\r\n  dest.Empty();\r\n  for(int i = 0; i < src.Length();)\r\n  {\r\n    Byte c = (Byte)src[i++];\r\n    if (c < 0x80)\r\n    {\r\n      dest += (wchar_t)c;\r\n      continue;\r\n    }\r\n    if(c < 0xC0)\r\n      return false;\r\n    int numAdds;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (c < kUtf8Limits[numAdds])\r\n        break;\r\n    UInt32 value = (c - kUtf8Limits[numAdds - 1]);\r\n    do\r\n    {\r\n      if (i >= src.Length())\r\n        return false;\r\n      Byte c2 = (Byte)src[i++];\r\n      if (c2 < 0x80 || c2 >= 0xC0)\r\n        return false;\r\n      value <<= 6;\r\n      value |= (c2 - 0x80);\r\n      numAdds--;\r\n    }\r\n    while(numAdds > 0);\r\n    if (value < 0x10000)\r\n      dest += (wchar_t)(value);\r\n    else\r\n    {\r\n      value -= 0x10000;\r\n      if (value >= 0x100000)\r\n        return false;\r\n      dest += (wchar_t)(0xD800 + (value >> 10));\r\n      dest += (wchar_t)(0xDC00 + (value & 0x3FF));\r\n    }\r\n  }\r\n  return true; \r\n}\r\n\r\nbool ConvertUnicodeToUTF8(const UString &src, AString &dest)\r\n{\r\n  dest.Empty();\r\n  for(int i = 0; i < src.Length();)\r\n  {\r\n    UInt32 value = (UInt32)src[i++];\r\n    if (value < 0x80)\r\n    {\r\n      dest += (char)value;\r\n      continue;\r\n    }\r\n    if (value >= 0xD800 && value < 0xE000)\r\n    {\r\n      if (value >= 0xDC00)\r\n        return false;\r\n      if (i >= src.Length())\r\n        return false;\r\n      UInt32 c2 = (UInt32)src[i++];\r\n      if (c2 < 0xDC00 || c2 >= 0xE000)\r\n        return false;\r\n      value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n    }\r\n    int numAdds;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n        break;\r\n    dest += (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n    do\r\n    {\r\n      numAdds--;\r\n      dest += (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n    }\r\n    while(numAdds > 0);\r\n  }\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/UTFConvert.h",
    "content": "// Common/UTFConvert.h\r\n\r\n#ifndef __COMMON_UTFCONVERT_H\r\n#define __COMMON_UTFCONVERT_H\r\n\r\n#include \"MyString.h\"\r\n\r\nbool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);\r\nbool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/Wildcard.cpp",
    "content": "// Common/Wildcard.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Wildcard.h\"\r\n\r\nbool g_CaseSensitive = \r\n  #ifdef _WIN32\r\n    false;\r\n  #else\r\n    true;\r\n  #endif\r\n\r\nstatic const wchar_t kAnyCharsChar = L'*';\r\nstatic const wchar_t kAnyCharChar = L'?';\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t kDirDelimiter1 = L'\\\\';\r\n#endif\r\nstatic const wchar_t kDirDelimiter2 = L'/';\r\n\r\nstatic const UString kWildCardCharSet = L\"?*\";\r\n\r\nstatic const UString kIllegalWildCardFileNameChars=\r\n  L\"\\x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\xA\\xB\\xC\\xD\\xE\\xF\"\r\n  L\"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F\"\r\n  L\"\\\"/:<>\\\\|\";\r\n\r\n\r\nstatic inline bool IsCharDirLimiter(wchar_t c)\r\n{\r\n  return (\r\n    #ifdef _WIN32\r\n    c == kDirDelimiter1 || \r\n    #endif\r\n    c == kDirDelimiter2);\r\n}\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2)\r\n{\r\n  if (g_CaseSensitive)\r\n    return s1.Compare(s2);\r\n  return s1.CompareNoCase(s2);\r\n}\r\n\r\n// -----------------------------------------\r\n// this function compares name with mask\r\n// ? - any char\r\n// * - any char or empty\r\n\r\nstatic bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t m = *mask;\r\n    wchar_t c = *name;\r\n    if (m == 0) \r\n      return (c == 0);\r\n    if (m == kAnyCharsChar)\r\n    {\r\n      if (EnhancedMaskTest(mask + 1, name))\r\n        return true;\r\n      if (c == 0) \r\n        return false;\r\n    }\r\n    else\r\n    {\r\n      if (m == kAnyCharChar)\r\n      {\r\n        if (c == 0) \r\n          return false;\r\n      }\r\n      else if (m != c)\r\n        if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))\r\n          return false;\r\n      mask++;\r\n    }\r\n    name++;\r\n  }\r\n}\r\n\r\n// --------------------------------------------------\r\n// Splits path to strings\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts)\r\n{\r\n  pathParts.Clear();\r\n  UString name;\r\n  int len = path.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = path[i];\r\n    if (IsCharDirLimiter(c))\r\n    {\r\n      pathParts.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  pathParts.Add(name);\r\n}\r\n\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)\r\n{\r\n  int i;\r\n  for(i = path.Length() - 1; i >= 0; i--)\r\n    if(IsCharDirLimiter(path[i]))\r\n      break;\r\n  dirPrefix = path.Left(i + 1);\r\n  name = path.Mid(i + 1);\r\n}\r\n\r\nUString ExtractDirPrefixFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for(i = path.Length() - 1; i >= 0; i--)\r\n    if(IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Left(i + 1);\r\n}\r\n\r\nUString ExtractFileNameFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for(i = path.Length() - 1; i >= 0; i--)\r\n    if(IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Mid(i + 1);\r\n}\r\n\r\n\r\nbool CompareWildCardWithName(const UString &mask, const UString &name)\r\n{\r\n  return EnhancedMaskTest(mask, name);\r\n}\r\n\r\nbool DoesNameContainWildCard(const UString &path)\r\n{\r\n  return (path.FindOneOf(kWildCardCharSet) >= 0);\r\n}\r\n\r\n\r\n// ----------------------------------------------------------'\r\n// NWildcard\r\n\r\nnamespace NWildcard {\r\n\r\n\r\n/*\r\nM = MaskParts.Size();\r\nN = TestNameParts.Size();\r\n\r\n                           File                          Dir\r\nForFile     req   M<=N  [N-M, N)                          -\r\n         nonreq   M=N   [0, M)                            -  \r\n \r\nForDir      req   M<N   [0, M) ... [N-M-1, N-1)  same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\nForBoth     req   m<=N  [0, M) ... [N-M, N)      same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\n*/\r\n\r\nbool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (!isFile && !ForDir)\r\n    return false;\r\n  int delta = (int)pathParts.Size() - (int)PathParts.Size();\r\n  if (delta < 0)\r\n    return false;\r\n  int start = 0;\r\n  int finish = 0;\r\n  if (isFile)\r\n  {\r\n    if (!ForDir && !Recursive && delta !=0)\r\n      return false;\r\n    if (!ForFile && delta == 0)\r\n      return false;\r\n    if (!ForDir && Recursive)\r\n      start = delta;\r\n  }\r\n  if (Recursive)\r\n  {\r\n    finish = delta;\r\n    if (isFile && !ForFile)\r\n      finish = delta - 1;\r\n  }\r\n  for (int d = start; d <= finish; d++)\r\n  {\r\n    int i;\r\n    for (i = 0; i < PathParts.Size(); i++)\r\n      if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))\r\n        break;\r\n    if (i == PathParts.Size())\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nint CCensorNode::FindSubNode(const UString &name) const\r\n{\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (CompareFileNames(SubNodes[i].Name, name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensorNode::AddItemSimple(bool include, CItem &item)\r\n{\r\n  if (include)\r\n    IncludeItems.Add(item);\r\n  else\r\n    ExcludeItems.Add(item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, CItem &item)\r\n{\r\n  if (item.PathParts.Size() <= 1)\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  const UString &front = item.PathParts.Front();\r\n  if (DoesNameContainWildCard(front))\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  int index = FindSubNode(front);\r\n  if (index < 0)\r\n    index = SubNodes.Add(CCensorNode(front, this));\r\n  item.PathParts.Delete(0);\r\n  SubNodes[index].AddItem(include, item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)\r\n{\r\n  CItem item;\r\n  SplitPathToParts(path, item.PathParts);\r\n  item.Recursive = recursive;\r\n  item.ForFile = forFile;\r\n  item.ForDir = forDir;\r\n  AddItem(include, item);\r\n}\r\n\r\nbool CCensorNode::NeedCheckSubDirs() const\r\n{\r\n  for (int i = 0; i < IncludeItems.Size(); i++)\r\n  {\r\n    const CItem &item = IncludeItems[i];\r\n    if (item.Recursive || item.PathParts.Size() > 1)\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::AreThereIncludeItems() const\r\n{\r\n  if (IncludeItems.Size() > 0)\r\n    return true;\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (SubNodes[i].AreThereIncludeItems())\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const\r\n{\r\n  const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;\r\n  for (int i = 0; i < items.Size(); i++)\r\n    if (items[i].CheckPath(pathParts, isFile))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const\r\n{\r\n  if (CheckPathCurrent(false, pathParts, isFile))\r\n  {\r\n    include = false;\r\n    return true;\r\n  }\r\n  include = true;\r\n  bool finded = CheckPathCurrent(true, pathParts, isFile);\r\n  if (pathParts.Size() == 1)\r\n    return finded;\r\n  int index = FindSubNode(pathParts.Front());\r\n  if (index >= 0)\r\n  {\r\n    UStringVector pathParts2 = pathParts;\r\n    pathParts2.Delete(0);\r\n    if (SubNodes[index].CheckPath(pathParts2, isFile, include))\r\n      return true;\r\n  }\r\n  return finded;\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const\r\n{\r\n  UStringVector pathParts; \r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPath(pathParts, isFile, include);\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool include;\r\n  if(CheckPath(path, isFile, include))\r\n    return include;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (CheckPathCurrent(include, pathParts, isFile))\r\n    return true;\r\n  if (Parent == 0)\r\n    return false;\r\n  pathParts.Insert(0, Name);\r\n  return Parent->CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n\r\n/*\r\nbool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const\r\n{\r\n  UStringVector pathParts; \r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n*/\r\n\r\nvoid CCensorNode::AddItem2(bool include, const UString &path, bool recursive)\r\n{\r\n  if (path.IsEmpty())\r\n    return;\r\n  bool forFile = true;\r\n  bool forFolder = true;\r\n  UString path2 = path;\r\n  if (IsCharDirLimiter(path[path.Length() - 1]))\r\n  {\r\n    path2.Delete(path.Length() - 1);\r\n    forFile = false;\r\n  }\r\n  AddItem(include, path2, recursive, forFile, forFolder);\r\n}\r\n\r\nvoid CCensorNode::ExtendExclude(const CCensorNode &fromNodes)\r\n{\r\n  ExcludeItems += fromNodes.ExcludeItems;\r\n  for (int i = 0; i < fromNodes.SubNodes.Size(); i++)\r\n  {\r\n    const CCensorNode &node = fromNodes.SubNodes[i];\r\n    int subNodeIndex = FindSubNode(node.Name);\r\n    if (subNodeIndex < 0)\r\n      subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));\r\n    SubNodes[subNodeIndex].ExtendExclude(node);\r\n  }\r\n}\r\n\r\nint CCensor::FindPrefix(const UString &prefix) const\r\n{\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n    if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensor::AddItem(bool include, const UString &path, bool recursive)\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  bool forFile = true;\r\n  if (pathParts.Back().IsEmpty())\r\n  {\r\n    forFile = false;\r\n    pathParts.DeleteBack();\r\n  }\r\n  const UString &front = pathParts.Front();\r\n  bool isAbs = false;\r\n  if (front.IsEmpty())\r\n    isAbs = true;\r\n  else if (front.Length() == 2 && front[1] == L':')\r\n    isAbs = true;\r\n  else\r\n  {\r\n    for (int i = 0; i < pathParts.Size(); i++)\r\n    {\r\n      const UString &part = pathParts[i];\r\n      if (part == L\"..\" || part == L\".\")\r\n      {\r\n        isAbs = true;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  int numAbsParts = 0;\r\n  if (isAbs)\r\n    if (pathParts.Size() > 1)\r\n      numAbsParts = pathParts.Size() - 1;\r\n    else\r\n      numAbsParts = 1;\r\n  UString prefix;\r\n  for (int i = 0; i < numAbsParts; i++)\r\n  {\r\n    const UString &front = pathParts.Front();\r\n    if (DoesNameContainWildCard(front))\r\n      break;\r\n    prefix += front;\r\n    prefix += WCHAR_PATH_SEPARATOR;\r\n    pathParts.Delete(0);\r\n  }\r\n  int index = FindPrefix(prefix);\r\n  if (index < 0)\r\n    index = Pairs.Add(CPair(prefix));\r\n\r\n  CItem item;\r\n  item.PathParts = pathParts;\r\n  item.ForDir = true;\r\n  item.ForFile = forFile;\r\n  item.Recursive = recursive;\r\n  Pairs[index].Head.AddItem(include, item);\r\n}\r\n\r\nbool CCensor::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool finded = false;\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n  {\r\n    bool include;\r\n    if (Pairs[i].Head.CheckPath(path, isFile, include))\r\n    {\r\n      if (!include)\r\n        return false;\r\n      finded = true;\r\n    }\r\n  }\r\n  return finded;\r\n}\r\n\r\nvoid CCensor::ExtendExclude()\r\n{\r\n  int i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (Pairs[i].Prefix.IsEmpty())\r\n      break;\r\n  if (i == Pairs.Size())\r\n    return;\r\n  int index = i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (index != i)\r\n      Pairs[i].Head.ExtendExclude(Pairs[index].Head);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Common/Wildcard.h",
    "content": "// Common/Wildcard.h\r\n\r\n#ifndef __COMMON_WILDCARD_H\r\n#define __COMMON_WILDCARD_H\r\n\r\n#include \"MyString.h\"\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2);\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts);\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);\r\nUString ExtractDirPrefixFromPath(const UString &path);\r\nUString ExtractFileNameFromPath(const UString &path);\r\nbool DoesNameContainWildCard(const UString &path);\r\nbool CompareWildCardWithName(const UString &mask, const UString &name);\r\n\r\nnamespace NWildcard {\r\n\r\nstruct CItem\r\n{\r\n  UStringVector PathParts;\r\n  bool Recursive;\r\n  bool ForFile;\r\n  bool ForDir;\r\n  bool CheckPath(const UStringVector &pathParts, bool isFile) const;\r\n};\r\n\r\nclass CCensorNode\r\n{\r\n  CCensorNode *Parent;\r\n  bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;\r\n  void AddItemSimple(bool include, CItem &item);\r\n  bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;\r\npublic:\r\n  CCensorNode(): Parent(0) { };\r\n  CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };\r\n  UString Name;\r\n  CObjectVector<CCensorNode> SubNodes;\r\n  CObjectVector<CItem> IncludeItems;\r\n  CObjectVector<CItem> ExcludeItems;\r\n\r\n  int FindSubNode(const UString &path) const;\r\n\r\n  void AddItem(bool include, CItem &item);\r\n  void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);\r\n  void AddItem2(bool include, const UString &path, bool recursive);\r\n\r\n  bool NeedCheckSubDirs() const;\r\n  bool AreThereIncludeItems() const;\r\n\r\n  bool CheckPath(const UString &path, bool isFile, bool &include) const;\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n\r\n  bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;\r\n  // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;\r\n  void ExtendExclude(const CCensorNode &fromNodes);\r\n};\r\n\r\nstruct CPair\r\n{\r\n  UString Prefix;\r\n  CCensorNode Head;\r\n  CPair(const UString &prefix): Prefix(prefix) { };\r\n};\r\n\r\nclass CCensor\r\n{\r\n  int FindPrefix(const UString &prefix) const;\r\npublic:\r\n  CObjectVector<CPair> Pairs;\r\n  bool AllAreRelative() const\r\n    { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }\r\n  void AddItem(bool include, const UString &path, bool recursive);\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n  void ExtendExclude();\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/DLL.cpp",
    "content": "// Windows/DLL.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DLL.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nCLibrary::~CLibrary()\r\n{\r\n  Free();\r\n}\r\n\r\nbool CLibrary::Free()\r\n{\r\n  if (_module == 0)\r\n    return true;\r\n  // MessageBox(0, TEXT(\"\"), TEXT(\"Free\"), 0);\r\n  // Sleep(5000);\r\n  if (!::FreeLibrary(_module))\r\n    return false;\r\n  _module = 0;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadOperations(HMODULE newModule)\r\n{\r\n  if (newModule == NULL)\r\n    return false;\r\n  if(!Free())\r\n    return false;\r\n  _module = newModule;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"LoadEx\"), 0);\r\n  return LoadOperations(::LoadLibraryEx(fileName, NULL, flags));\r\n}\r\n\r\nbool CLibrary::Load(LPCTSTR fileName)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"Load\"), 0);\r\n  // Sleep(5000);\r\n  // OutputDebugString(fileName);\r\n  // OutputDebugString(TEXT(\"\\n\"));\r\n  return LoadOperations(::LoadLibrary(fileName));\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\nCSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n\r\nbool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));\r\n  return LoadEx(GetSysPath(fileName), flags);\r\n}\r\nbool CLibrary::Load(LPCWSTR fileName)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryW(fileName));\r\n  return Load(GetSysPath(fileName));\r\n}\r\n#endif\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result)\r\n{\r\n  result.Empty();\r\n  TCHAR fullPath[MAX_PATH + 2];\r\n  DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1);\r\n  if (size <= MAX_PATH && size != 0)\r\n  {\r\n    result = fullPath;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result)\r\n{\r\n  result.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    wchar_t fullPath[MAX_PATH + 2];\r\n    DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);\r\n    if (size <= MAX_PATH && size != 0)\r\n    {\r\n      result = fullPath;\r\n      return true;\r\n    }\r\n    return false;\r\n  }\r\n  CSysString resultSys;\r\n  if (!MyGetModuleFileName(hModule, resultSys))\r\n    return false;\r\n  result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());\r\n  return true;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/DLL.h",
    "content": "// Windows/DLL.h\r\n\r\n#ifndef __WINDOWS_DLL_H\r\n#define __WINDOWS_DLL_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nclass CLibrary\r\n{\r\n  bool LoadOperations(HMODULE newModule);\r\nprotected:\r\n  HMODULE _module;\r\npublic:\r\n  operator HMODULE() const { return _module; }\r\n  HMODULE* operator&() { return &_module; }\r\n\r\n  CLibrary():_module(NULL) {};\r\n  ~CLibrary();\r\n  void Attach(HMODULE m)\r\n  {\r\n    Free();\r\n    _module = m;\r\n  }\r\n  HMODULE Detach()\r\n  {\r\n    HMODULE m = _module;\r\n    _module = NULL;\r\n    return m;\r\n  }\r\n\r\n  // operator HMODULE() const { return _module; };\r\n  bool IsLoaded() const { return (_module != NULL); };\r\n  bool Free();\r\n  bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCWSTR fileName);\r\n  #endif\r\n  FARPROC GetProcAddress(LPCSTR procName) const\r\n    { return ::GetProcAddress(_module, procName); }\r\n};\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result);\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result);\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\n#ifdef _WIN32\r\ninline bool LRESULTToBool(LRESULT value)\r\n  { return (value != FALSE); }\r\n#endif\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/Error.cpp",
    "content": "// Windows/Error.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifndef _UNICODE\r\n#include \"Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message)\r\n{\r\n  LPVOID msgBuf;\r\n  if(::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r\n      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n      NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)\r\n    return false;\r\n  message = (LPCTSTR)msgBuf;\r\n  ::LocalFree(msgBuf);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyFormatMessage(DWORD messageID, UString &message)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPVOID msgBuf;\r\n    if(::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | \r\n        FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n        NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)\r\n      return false;\r\n    message = (LPCWSTR)msgBuf;\r\n    ::LocalFree(msgBuf);\r\n    return true;\r\n  }\r\n  CSysString messageSys;\r\n  bool result = MyFormatMessage(messageID, messageSys);\r\n  message = GetUnicodeString(messageSys);\r\n  return result;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/Error.h",
    "content": "// Windows/Error.h\r\n\r\n#ifndef __WINDOWS_ERROR_H\r\n#define __WINDOWS_ERROR_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message);\r\ninline CSysString MyFormatMessage(DWORD messageID)\r\n{\r\n  CSysString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#ifdef _UNICODE\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n  { return MyFormatMessage(messageID); }\r\n#else\r\nbool MyFormatMessage(DWORD messageID, UString &message);\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n{\r\n  UString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileDir.cpp",
    "content": "// Windows/FileDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileDir.h\"\r\n#include \"FileName.h\"\r\n#include \"FileFind.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n// SetCurrentDirectory doesn't support \\\\?\\ prefix\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR fileName, UString &res);\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n#endif\r\n\r\nnamespace NDirectory {\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\nstatic UString GetUnicodePath(const CSysString &sysPath)\r\n  { return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }\r\nstatic CSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\nbool MyGetSystemDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetWindowsDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n\r\nbool MyGetSystemDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetSystemDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n{\r\n  #ifndef _UNICODE\r\n  if (!g_IsNT)\r\n  {\r\n    ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\r\n    return false;\r\n  }\r\n  #endif \r\n  HANDLE hDir = ::CreateFileW(fileName, GENERIC_WRITE,\r\n      FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n      NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (hDir == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      hDir = ::CreateFileW(longPath, GENERIC_WRITE,\r\n        FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  }\r\n  #endif\r\n\r\n  bool res = false;\r\n  if (hDir != INVALID_HANDLE_VALUE)\r\n  {\r\n    res = BOOLToBool(::SetFileTime(hDir, creationTime, lastAccessTime, lastWriteTime));\r\n    ::CloseHandle(hDir);\r\n  }\r\n  return res;\r\n}\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (::SetFileAttributes(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyRemoveDirectory(LPCTSTR pathName)\r\n{ \r\n  if (::RemoveDirectory(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2)\r\n{\r\n  if (!GetLongPathBase(s1, d1) || !GetLongPathBase(s2, d2))\r\n    return false;\r\n  if (d1.IsEmpty() && d2.IsEmpty()) return false;\r\n  if (d1.IsEmpty()) d1 = s1;\r\n  if (d2.IsEmpty()) d2 = s2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName)\r\n{ \r\n  if (::MoveFile(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2)) \r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)\r\n{  \r\n  if (!g_IsNT)\r\n    return MySetFileAttributes(GetSysPath(fileName), fileAttributes);\r\n  if (::SetFileAttributesW(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n\r\nbool MyRemoveDirectory(LPCWSTR pathName)\r\n{  \r\n  if (!g_IsNT)\r\n    return MyRemoveDirectory(GetSysPath(pathName));\r\n  if (::RemoveDirectoryW(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)\r\n{  \r\n  if (!g_IsNT)\r\n    return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));\r\n  if (::MoveFileW(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2)) \r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nbool MyCreateDirectory(LPCTSTR pathName) \r\n{ \r\n  if (::CreateDirectory(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyCreateDirectory(LPCWSTR pathName)\r\n{  \r\n  if (!g_IsNT)\r\n    return MyCreateDirectory(GetSysPath(pathName));\r\n  if (::CreateDirectoryW(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\n/*\r\nbool CreateComplexDirectory(LPCTSTR pathName)\r\n{\r\n  NName::CParsedPath path;\r\n  path.ParsePath(pathName);\r\n  CSysString fullPath = path.Prefix;\r\n  DWORD errorCode = ERROR_SUCCESS;\r\n  for(int i = 0; i < path.PathParts.Size(); i++)\r\n  {\r\n    const CSysString &string = path.PathParts[i];\r\n    if(string.IsEmpty())\r\n    {\r\n      if(i != path.PathParts.Size() - 1)\r\n        return false;\r\n      return true;\r\n    }\r\n    fullPath += path.PathParts[i];\r\n    if (!MyCreateDirectory(fullPath))\r\n    {\r\n      DWORD errorCode = GetLastError();\r\n      if(errorCode != ERROR_ALREADY_EXISTS)\r\n        return false;\r\n    }\r\n    fullPath += NName::kDirDelimiter;\r\n  }\r\n  return true;\r\n}\r\n*/\r\n\r\nbool CreateComplexDirectory(LPCTSTR _aPathName)\r\n{\r\n  CSysString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == ':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  CSysString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if(MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfo fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDirectory())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == ':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while(pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateComplexDirectory(LPCWSTR _aPathName)\r\n{\r\n  UString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == L':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  UString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if(MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfoW fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDirectory())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == L':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while(pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\nbool DeleteFileAlways(LPCTSTR name)\r\n{\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFile(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DeleteFileAlways(LPCWSTR name)\r\n{  \r\n  if (!g_IsNT)\r\n    return DeleteFileAlways(GetSysPath(name));\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFileW(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nstatic bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)\r\n{\r\n  if(fileInfo.IsDirectory())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\n\r\nbool RemoveDirectoryWithSubItems(const CSysString &path)\r\n{\r\n  NFind::CFileInfo fileInfo;\r\n  CSysString pathPrefix = path + NName::kDirDelimiter;\r\n  {\r\n    NFind::CEnumerator enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));\r\n    while(enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)\r\n{\r\n  if(fileInfo.IsDirectory())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\nbool RemoveDirectoryWithSubItems(const UString &path)\r\n{\r\n  NFind::CFileInfoW fileInfo;\r\n  UString pathPrefix = path + UString(NName::kDirDelimiter);\r\n  {\r\n    NFind::CEnumeratorW enumerator(pathPrefix + UString(NName::kAnyStringWildcard));\r\n    while(enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\n\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)\r\n{\r\n  DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  shortPath.ReleaseBuffer();\r\n  return (needLength > 0 && needLength < MAX_PATH);\r\n}\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  LPTSTR fileNamePointer = 0;\r\n  LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n  DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n  resultPath.ReleaseBuffer();\r\n  if (needLength == 0)\r\n    return false;\r\n  if (needLength >= MAX_PATH)\r\n  {\r\n    #ifdef WIN_LONG_PATH2\r\n    needLength++;\r\n    buffer = resultPath.GetBuffer(needLength + 1);\r\n    DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength2 == 0 || needLength2 > needLength)\r\n    #endif\r\n      return false;\r\n  }\r\n  if (fileNamePointer == 0)\r\n    fileNamePartStartIndex = lstrlen(fileName);\r\n  else\r\n    fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR fileNamePointer = 0;\r\n    LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n    DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength == 0)\r\n      return false;\r\n    if (needLength >= MAX_PATH)\r\n    {\r\n      #ifdef WIN_LONG_PATH\r\n      needLength++;\r\n      buffer = resultPath.GetBuffer(needLength + 1);\r\n      DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n      resultPath.ReleaseBuffer();\r\n      if (needLength2 == 0 || needLength2 > needLength)\r\n      #endif\r\n        return false;\r\n    }\r\n    if (fileNamePointer == 0)\r\n      fileNamePartStartIndex = MyStringLen(fileName);\r\n    else\r\n      fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  }\r\n  else\r\n  {\r\n    CSysString sysPath;\r\n    if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))\r\n      return false;\r\n    UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));\r\n    UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));\r\n    fileNamePartStartIndex = resultPath1.Length();\r\n    resultPath = resultPath1 + resultPath2;\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n#endif\r\n\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetCurrentDirectory(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path)\r\n{\r\n  if (g_IsNT)\r\n    return BOOLToBool(::SetCurrentDirectoryW(path));\r\n  return MySetCurrentDirectory(GetSysPath(path));\r\n}\r\nbool MyGetCurrentDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetCurrentDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, \r\n  CSysString &resultPath, UINT32 &filePart)\r\n{\r\n  LPTSTR filePartPointer;\r\n  DWORD value = ::SearchPath(path, fileName, extension, \r\n    MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n  filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);\r\n  resultPath.ReleaseBuffer();\r\n  return (value > 0 && value <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, \r\n  UString &resultPath, UINT32 &filePart)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR filePartPointer = 0;\r\n    DWORD value = ::SearchPathW(path, fileName, extension, \r\n        MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n    filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);\r\n    resultPath.ReleaseBuffer();\r\n    return (value > 0 && value <= MAX_PATH);\r\n  }\r\n  \r\n  CSysString sysPath;\r\n  if (!MySearchPath(\r\n      path != 0 ? (LPCTSTR)GetSysPath(path): 0,\r\n      fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,\r\n      extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,\r\n      sysPath, filePart))\r\n    return false;\r\n  UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));\r\n  UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));\r\n  filePart = resultPath1.Length();\r\n  resultPath = resultPath1 + resultPath2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &path)\r\n{\r\n  path.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetTempPath(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)\r\n{\r\n  UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return number;\r\n}\r\n\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));\r\n    path.ReleaseBuffer();\r\n    return number;\r\n  }\r\n  CSysString sysPath;\r\n  UINT number = MyGetTempFileName(\r\n      dirPath ? (LPCTSTR)GetSysPath(dirPath): 0, \r\n      prefix ? (LPCTSTR)GetSysPath(prefix): 0, \r\n      sysPath);\r\n  path = GetUnicodePath(sysPath);\r\n  return number;\r\n}\r\n#endif\r\n\r\nUINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if(number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  CSysString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFile::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nUINT CTempFileW::Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if(number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFileW::Create(LPCWSTR prefix, UString &resultPath)\r\n{\r\n  UString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFileW::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFile tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!::DeleteFile(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if(NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectory::Create(LPCTSTR prefix)\r\n{ \r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir)); \r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateTempDirectory(LPCWSTR prefix, UString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFileW tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!DeleteFileAlways(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if(NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectoryW::Create(LPCWSTR prefix)\r\n{ \r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir)); \r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileDir.h",
    "content": "// Windows/FileDir.h\r\n\r\n#ifndef __WINDOWS_FILEDIR_H\r\n#define __WINDOWS_FILEDIR_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NDirectory {\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path);\r\nbool MyGetSystemDirectory(CSysString &path);\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path);\r\nbool MyGetSystemDirectory(UString &path);\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);\r\nbool MyRemoveDirectory(LPCTSTR pathName);\r\nbool MyCreateDirectory(LPCTSTR pathName);\r\nbool CreateComplexDirectory(LPCTSTR pathName);\r\nbool DeleteFileAlways(LPCTSTR name);\r\nbool RemoveDirectoryWithSubItems(const CSysString &path);\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);\r\nbool MyRemoveDirectory(LPCWSTR pathName);\r\nbool MyCreateDirectory(LPCWSTR pathName);\r\nbool CreateComplexDirectory(LPCWSTR pathName);\r\nbool DeleteFileAlways(LPCWSTR name);\r\nbool RemoveDirectoryWithSubItems(const UString &path);\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, \r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName);\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, \r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName);\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);\r\n#endif\r\n\r\ninline bool MySetCurrentDirectory(LPCTSTR path)\r\n  { return BOOLToBool(::SetCurrentDirectory(path)); }\r\nbool MyGetCurrentDirectory(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path);\r\nbool MyGetCurrentDirectory(UString &resultPath);\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, \r\n  CSysString &resultPath, UINT32 &filePart);\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, \r\n  UString &resultPath, UINT32 &filePart);\r\n#endif\r\n\r\ninline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, \r\n  CSysString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n\r\n#ifndef _UNICODE\r\ninline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, \r\n  UString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &resultPath);\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n#endif\r\n\r\nclass CTempFile\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _fileName;\r\npublic:\r\n  CTempFile(): _mustBeDeleted(false) {}\r\n  ~CTempFile() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n  bool Create(LPCTSTR prefix, CSysString &resultPath);\r\n  bool Remove();\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempFile CTempFileW;\r\n#else\r\nclass CTempFileW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _fileName;\r\npublic:\r\n  CTempFileW(): _mustBeDeleted(false) {}\r\n  ~CTempFileW() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n  bool Create(LPCWSTR prefix, UString &resultPath);\r\n  bool Remove();\r\n};\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);\r\n\r\nclass CTempDirectory\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _tempDir;\r\npublic:\r\n  const CSysString &GetPath() const { return _tempDir; }\r\n  CTempDirectory(): _mustBeDeleted(false) {}\r\n  ~CTempDirectory() { Remove();  }\r\n  bool Create(LPCTSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempDirectory CTempDirectoryW;\r\n#else\r\nclass CTempDirectoryW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _tempDir;\r\npublic:\r\n  const UString &GetPath() const { return _tempDir; }\r\n  CTempDirectoryW(): _mustBeDeleted(false) {}\r\n  ~CTempDirectoryW() { Remove();  }\r\n  bool Create(LPCWSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileFind.cpp",
    "content": "// Windows/FileFind.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileFind.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n\r\nnamespace NFind {\r\n\r\nstatic const TCHAR kDot = TEXT('.');\r\n\r\nbool CFileInfo::IsDots() const\r\n{ \r\n  if (!IsDirectory() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileInfoW::IsDots() const\r\n{ \r\n  if (!IsDirectory() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n#endif\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(\r\n    const WIN32_FIND_DATA &findData,\r\n    CFileInfo &fileInfo)\r\n{\r\n  fileInfo.Attributes = findData.dwFileAttributes; \r\n  fileInfo.CreationTime = findData.ftCreationTime;  \r\n  fileInfo.LastAccessTime = findData.ftLastAccessTime; \r\n  fileInfo.LastWriteTime = findData.ftLastWriteTime;\r\n  fileInfo.Size  = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow; \r\n  fileInfo.Name = findData.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fileInfo.ReparseTag = findData.dwReserved0;\r\n  #else\r\n  fileInfo.ObjectID = findData.dwOID;\r\n  #endif\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; } \r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(\r\n    const WIN32_FIND_DATAW &findData,\r\n    CFileInfoW &fileInfo)\r\n{\r\n  fileInfo.Attributes = findData.dwFileAttributes; \r\n  fileInfo.CreationTime = findData.ftCreationTime;  \r\n  fileInfo.LastAccessTime = findData.ftLastAccessTime; \r\n  fileInfo.LastWriteTime = findData.ftLastWriteTime;\r\n  fileInfo.Size  = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow; \r\n  fileInfo.Name = findData.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fileInfo.ReparseTag = findData.dwReserved0;\r\n  #else\r\n  fileInfo.ObjectID = findData.dwOID;\r\n  #endif\r\n}\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(\r\n    const WIN32_FIND_DATA &findData,\r\n    CFileInfoW &fileInfo)\r\n{\r\n  fileInfo.Attributes = findData.dwFileAttributes; \r\n  fileInfo.CreationTime = findData.ftCreationTime;  \r\n  fileInfo.LastAccessTime = findData.ftLastAccessTime; \r\n  fileInfo.LastWriteTime = findData.ftLastWriteTime;\r\n  fileInfo.Size  = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow; \r\n  fileInfo.Name = GetUnicodeString(findData.cFileName, GetCurrentCodePage());\r\n  #ifndef _WIN32_WCE\r\n  fileInfo.ReparseTag = findData.dwReserved0;\r\n  #else\r\n  fileInfo.ObjectID = findData.dwOID;\r\n  #endif\r\n}\r\n#endif\r\n  \r\n////////////////////////////////\r\n// CFindFile\r\n\r\nbool CFindFile::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::FindClose(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\n          \r\nbool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  WIN32_FIND_DATA findData;\r\n  _handle = ::FindFirstFile(wildcard, &findData);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(wildcard, longPath))\r\n      _handle = ::FindFirstFileW(longPath, &findData);\r\n  }\r\n  #endif\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return false;\r\n  ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW findData;\r\n    _handle = ::FindFirstFileW(wildcard, &findData);\r\n    #ifdef WIN_LONG_PATH\r\n    if (_handle == INVALID_HANDLE_VALUE)\r\n    {\r\n      UString longPath;\r\n      if (GetLongPath(wildcard, longPath))\r\n        _handle = ::FindFirstFileW(longPath, &findData);\r\n    }\r\n    #endif\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA findData;\r\n    _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard, \r\n        GetCurrentCodePage()), &findData);\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFindFile::FindNext(CFileInfo &fileInfo)\r\n{\r\n  WIN32_FIND_DATA findData;\r\n  bool result = BOOLToBool(::FindNextFile(_handle, &findData));\r\n  if (result)\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  return result;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindNext(CFileInfoW &fileInfo)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW findData;\r\n    if (!::FindNextFileW(_handle, &findData))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA findData;\r\n    if (!::FindNextFileA(_handle, &findData))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n#endif\r\n\r\nbool DoesFileExist(LPCTSTR name)\r\n{\r\n  CFileInfo fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DoesFileExist(LPCWSTR name)\r\n{\r\n  CFileInfoW fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n#endif\r\n\r\n/////////////////////////////////////\r\n// CEnumerator\r\n\r\nbool CEnumerator::NextAny(CFileInfo &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CEnumeratorW::NextAny(CFileInfoW &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#endif\r\n\r\n////////////////////////////////\r\n// CFindChangeNotification\r\n// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.\r\n\r\nbool CFindChangeNotification::Close()\r\n{\r\n  if (!IsHandleAllocated())\r\n    return true;\r\n  if (!::FindCloseChangeNotification(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n           \r\nHANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  _handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n\r\n#ifndef _UNICODE\r\nHANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  if (!g_IsNT)\r\n    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);\r\n  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  UINT32 size = GetLogicalDriveStrings(0, NULL); \r\n  if (size == 0)\r\n    return false;\r\n  CSysString buffer;\r\n  UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size)); \r\n  if (newSize == 0)\r\n    return false;\r\n  if (newSize > size)\r\n    return false;\r\n  CSysString string;\r\n  for(UINT32 i = 0; i < newSize; i++)\r\n  {\r\n    TCHAR c = buffer[i];\r\n    if (c == TEXT('\\0'))\r\n    {\r\n      driveStrings.Add(string);\r\n      string.Empty();\r\n    }\r\n    else\r\n      string += c;\r\n  }\r\n  if (!string.IsEmpty())\r\n    return false;\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  if (g_IsNT)\r\n  {\r\n    UINT32 size = GetLogicalDriveStringsW(0, NULL); \r\n    if (size == 0)\r\n      return false;\r\n    UString buffer;\r\n    UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size)); \r\n    if (newSize == 0)\r\n      return false;\r\n    if (newSize > size)\r\n      return false;\r\n    UString string;\r\n    for(UINT32 i = 0; i < newSize; i++)\r\n    {\r\n      WCHAR c = buffer[i];\r\n      if (c == L'\\0')\r\n      {\r\n        driveStrings.Add(string);\r\n        string.Empty();\r\n      }\r\n      else\r\n        string += c;\r\n    }\r\n    return string.IsEmpty();\r\n  }\r\n  CSysStringVector driveStringsA;\r\n  bool res = MyGetLogicalDriveStrings(driveStringsA);\r\n  for (int i = 0; i < driveStringsA.Size(); i++)\r\n    driveStrings.Add(GetUnicodeString(driveStringsA[i]));\r\n  return res;\r\n}\r\n#endif\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileFind.h",
    "content": "// Windows/FileFind.h\r\n\r\n#ifndef __WINDOWS_FILEFIND_H\r\n#define __WINDOWS_FILEFIND_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"../Common/Types.h\"\r\n#include \"FileName.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NFind {\r\n\r\nnamespace NAttributes\r\n{\r\n  inline bool IsReadOnly(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_READONLY) != 0; }\r\n  inline bool IsHidden(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_HIDDEN) != 0; }\r\n  inline bool IsSystem(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_SYSTEM) != 0; }\r\n  inline bool IsDirectory(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }\r\n  inline bool IsArchived(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ARCHIVE) != 0; }\r\n  inline bool IsCompressed(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_COMPRESSED) != 0; }\r\n  inline bool IsEncrypted(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ENCRYPTED) != 0; }\r\n}\r\n\r\nclass CFileInfoBase\r\n{ \r\n  bool MatchesMask(UINT32 mask) const  { return ((Attributes & mask) != 0); }\r\npublic:\r\n  DWORD Attributes;\r\n  FILETIME CreationTime;  \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime;\r\n  UInt64 Size;\r\n  \r\n  #ifndef _WIN32_WCE\r\n  UINT32 ReparseTag;\r\n  #else\r\n  DWORD ObjectID; \r\n  #endif\r\n\r\n  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }\r\n  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }\r\n  bool IsDirectory() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }\r\n  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }\r\n  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }\r\n  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }\r\n  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }\r\n  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }\r\n  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }\r\n  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }\r\n  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }\r\n  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }\r\n};\r\n\r\nclass CFileInfo: public CFileInfoBase\r\n{ \r\npublic:\r\n  CSysString Name;\r\n  bool IsDots() const;\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CFileInfo CFileInfoW;\r\n#else\r\nclass CFileInfoW: public CFileInfoBase\r\n{ \r\npublic:\r\n  UString Name;\r\n  bool IsDots() const;\r\n};\r\n#endif\r\n\r\nclass CFindFile\r\n{\r\n  friend class CEnumerator;\r\n  HANDLE _handle;\r\npublic:\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }\r\n  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindFile() {  Close(); }\r\n  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n  bool FindNext(CFileInfo &fileInfo);\r\n  #ifndef _UNICODE\r\n  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\n  bool FindNext(CFileInfoW &fileInfo);\r\n  #endif\r\n  bool Close();\r\n};\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n\r\nbool DoesFileExist(LPCTSTR name);\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\nbool DoesFileExist(LPCWSTR name);\r\n#endif\r\n\r\nclass CEnumerator\r\n{\r\n  CFindFile _findFile;\r\n  CSysString _wildcard;\r\n  bool NextAny(CFileInfo &fileInfo);\r\npublic:\r\n  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfo &fileInfo);\r\n  bool Next(CFileInfo &fileInfo, bool &found);\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CEnumerator CEnumeratorW;\r\n#else\r\nclass CEnumeratorW\r\n{\r\n  CFindFile _findFile;\r\n  UString _wildcard;\r\n  bool NextAny(CFileInfoW &fileInfo);\r\npublic:\r\n  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfoW &fileInfo);\r\n  bool Next(CFileInfoW &fileInfo, bool &found);\r\n};\r\n#endif\r\n\r\nclass CFindChangeNotification\r\n{\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE () { return _handle; }\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }\r\n  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindChangeNotification() { Close(); }\r\n  bool Close();\r\n  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #ifndef _UNICODE\r\n  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #endif\r\n  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings);\r\n#endif\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifdef WIN_LONG_PATH\r\n#include \"../Common/MyString.h\"\r\n#endif\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR s, UString &res)\r\n{\r\n  res.Empty();\r\n  int len = MyStringLen(s);\r\n  wchar_t c = s[0];\r\n  if (len < 1 || c == L'\\\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))\r\n    return true;\r\n  UString curDir;\r\n  bool isAbs = false;\r\n  if (len > 3)\r\n    isAbs = (s[1] == L':' && s[2] == L'\\\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));\r\n\r\n  if (!isAbs)\r\n    {\r\n      DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));\r\n      curDir.ReleaseBuffer();\r\n      if (needLength == 0 || needLength > MAX_PATH)\r\n        return false;\r\n      if (curDir[curDir.Length() - 1] != L'\\\\')\r\n        curDir += L'\\\\';\r\n    }\r\n  res = UString(L\"\\\\\\\\?\\\\\") + curDir + s;\r\n  return true;\r\n}\r\n\r\nbool GetLongPath(LPCWSTR path, UString &longPath)\r\n{\r\n  if (GetLongPathBase(path, longPath)) \r\n    return !longPath.IsEmpty();\r\n  return false;\r\n}\r\n#endif\r\n\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode, \r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP), \r\n      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFileW(fileName, desiredAccess, shareMode, \r\n    (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n    flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode, \r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::CloseHandle(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if(sizeLow == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR) \r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if(!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CreationTime = winFileInfo.ftCreationTime;\r\n  fileInfo.LastAccessTime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.LastWriteTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes; \r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\n// Probably in some version of Windows there are problems with other sizes: \r\n// for 32 MB (maybe also for 16 MB). \r\n// And message can be \"Network connection was lost\"\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 22);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, creationTime, lastAccessTime, lastWriteTime)); }\r\n\r\nbool COutFile::SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {  return SetTime(NULL, NULL, lastWriteTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if(!Seek(length, newPosition))\r\n    return false;\r\n  if(newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{ \r\n  DWORD    Attributes; \r\n  FILETIME CreationTime; \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime; \r\n  DWORD    VolumeSerialNumber; \r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks; \r\n  UInt64   FileIndex; \r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _handle(INVALID_HANDLE_VALUE){};\r\n  ~CFileBase();\r\n\r\n  bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition); \r\n  bool SeekToBegin(); \r\n  bool SeekToEnd(UInt64 &newPosition); \r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileMapping.cpp",
    "content": "// Windows/FileMapping.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileMapping.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NMapping {\r\n\r\n\r\n\r\n\r\n}}}"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileMapping.h",
    "content": "// Windows/FileMapping.h\r\n\r\n#ifndef __WINDOWS_FILEMAPPING_H\r\n#define __WINDOWS_FILEMAPPING_H\r\n\r\n#include \"Windows/Handle.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\n// namespace NFile {\r\n// namespace NMapping {\r\n\r\nclass CFileMapping: public CHandle\r\n{\r\npublic:\r\n  bool Create(HANDLE file, LPSECURITY_ATTRIBUTES attributes,\r\n    DWORD protect, UINT64 maximumSize, LPCTSTR name)\r\n  {\r\n    _handle = ::CreateFileMapping(file, attributes,\r\n      protect, DWORD(maximumSize >> 32), DWORD(maximumSize), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenFileMapping(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  LPVOID MapViewOfFile(DWORD desiredAccess, UINT64 fileOffset, \r\n      SIZE_T numberOfBytesToMap)\r\n  {\r\n    return ::MapViewOfFile(_handle, desiredAccess, \r\n        DWORD(fileOffset >> 32), DWORD(fileOffset), numberOfBytesToMap);\r\n  }\r\n\r\n  LPVOID MapViewOfFileEx(DWORD desiredAccess, UINT64 fileOffset, \r\n      SIZE_T numberOfBytesToMap, LPVOID baseAddress)\r\n  {\r\n    return ::MapViewOfFileEx(_handle, desiredAccess, \r\n      DWORD(fileOffset >> 32), DWORD(fileOffset), \r\n      numberOfBytesToMap, baseAddress);\r\n  }\r\n  \r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileName.cpp",
    "content": "// Windows/FileName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)\r\n    dirPath += kDirDelimiter;\r\n}\r\n\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)\r\n    dirPath += wchar_t(kDirDelimiter);\r\n}\r\n#endif\r\n\r\n#ifdef _WIN32\r\n\r\nconst wchar_t kExtensionDelimiter = L'.';\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName, \r\n    UString &pureName, UString &extensionDelimiter, UString &extension)\r\n{\r\n  int index = fullName.ReverseFind(kExtensionDelimiter);\r\n  if (index < 0)\r\n  {\r\n    pureName = fullName;\r\n    extensionDelimiter.Empty();\r\n    extension.Empty();\r\n  }\r\n  else\r\n  {\r\n    pureName = fullName.Left(index);\r\n    extensionDelimiter = kExtensionDelimiter;\r\n    extension = fullName.Mid(index + 1);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/FileName.h",
    "content": "// Windows/FileName.h\r\n\r\n#ifndef __WINDOWS_FILENAME_H\r\n#define __WINDOWS_FILENAME_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nconst TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;\r\nconst TCHAR kAnyStringWildcard = '*';\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\\\'\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\\\'\r\n#endif\r\n\r\n#ifdef _WIN32\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName, \r\n    UString &pureName, UString &extensionDelimiter, UString &extension); \r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/Handle.h",
    "content": "// Windows/Handle.h\r\n\r\n#ifndef __WINDOWS_HANDLE_H\r\n#define __WINDOWS_HANDLE_H\r\n\r\nnamespace NWindows {\r\n\r\nclass CHandle\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE() { return _handle; }\r\n  CHandle(): _handle(NULL) {}\r\n  ~CHandle() { Close(); }\r\n  bool Close()\r\n  {\r\n    if (_handle == NULL)\r\n      return true;\r\n    if (!::CloseHandle(_handle))\r\n      return false;\r\n    _handle = NULL;\r\n    return true;\r\n  }\r\n  void Attach(HANDLE handle) \r\n    { _handle = handle; }\r\n  HANDLE Detach() \r\n  { \r\n    HANDLE handle = _handle;\r\n    _handle = NULL; \r\n    return handle;\r\n  }\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/MemoryLock.cpp",
    "content": "// Common/MemoryLock.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\n#ifndef _UNICODE\r\ntypedef BOOL (WINAPI * OpenProcessTokenP)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);\r\ntypedef BOOL (WINAPI * LookupPrivilegeValueP)(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID  lpLuid);\r\ntypedef BOOL (WINAPI * AdjustTokenPrivilegesP)(HANDLE TokenHandle, BOOL DisableAllPrivileges,\r\n    PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength);\r\n#endif\r\n\r\n#ifdef _UNICODE\r\nbool EnableLockMemoryPrivilege(\r\n#else\r\nstatic bool EnableLockMemoryPrivilege2(HMODULE hModule,\r\n#endif\r\nbool enable)\r\n{\r\n  #ifndef _UNICODE\r\n  if (hModule == NULL)\r\n    return false;\r\n  OpenProcessTokenP openProcessToken = (OpenProcessTokenP)GetProcAddress(hModule, \"OpenProcessToken\");\r\n  LookupPrivilegeValueP lookupPrivilegeValue = (LookupPrivilegeValueP)GetProcAddress(hModule, \"LookupPrivilegeValueA\" );\r\n  AdjustTokenPrivilegesP adjustTokenPrivileges = (AdjustTokenPrivilegesP)GetProcAddress(hModule, \"AdjustTokenPrivileges\");\r\n  if (openProcessToken == NULL || adjustTokenPrivileges == NULL || lookupPrivilegeValue == NULL)\r\n    return false;\r\n  #endif\r\n\r\n  HANDLE token;\r\n  if (!\r\n    #ifdef _UNICODE\r\n    ::OpenProcessToken\r\n    #else\r\n    openProcessToken\r\n    #endif\r\n    (::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))\r\n    return false;\r\n  TOKEN_PRIVILEGES tp;\r\n  bool res = false;\r\n  if (\r\n    #ifdef _UNICODE\r\n    ::LookupPrivilegeValue\r\n    #else\r\n    lookupPrivilegeValue\r\n    #endif\r\n    (NULL, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)))\r\n  {\r\n    tp.PrivilegeCount = 1;\r\n    tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED: 0;\r\n    if (\r\n      #ifdef _UNICODE\r\n      ::AdjustTokenPrivileges\r\n      #else\r\n      adjustTokenPrivileges\r\n      #endif\r\n      (token, FALSE, &tp, 0, NULL, NULL))\r\n      res = (GetLastError() == ERROR_SUCCESS);\r\n  }\r\n  ::CloseHandle(token);\r\n  return res;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool EnableLockMemoryPrivilege(bool enable)\r\n{\r\n  HMODULE hModule = LoadLibrary(TEXT(\"Advapi32.dll\"));\r\n  if(hModule == NULL)\r\n    return false;\r\n  bool res = EnableLockMemoryPrivilege2(hModule, enable);\r\n  ::FreeLibrary(hModule);\r\n  return res;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/MemoryLock.h",
    "content": "// Windows/MemoryLock.h\r\n\r\n#ifndef __WINDOWS_MEMORYLOCK_H\r\n#define __WINDOWS_MEMORYLOCK_H\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\nbool EnableLockMemoryPrivilege(bool enable = true);\r\n\r\n}}\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/PropVariant.cpp",
    "content": "// Windows/PropVariant.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariant.h\"\r\n\r\n#include \"../Common/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nCPropVariant::CPropVariant(const PROPVARIANT& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(const CPropVariant& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(BSTR bstrSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = bstrSrc;\r\n}\r\n\r\nCPropVariant::CPropVariant(LPCOLESTR lpszSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = lpszSrc;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const CPropVariant& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\nCPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(BSTR bstrSrc)\r\n{\r\n  *this = (LPCOLESTR)bstrSrc;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)\r\n{\r\n  InternalClear();\r\n  vt = VT_BSTR;\r\n  wReserved1 = 0;\r\n  bstrVal = ::SysAllocString(lpszSrc);\r\n  if (bstrVal == NULL && lpszSrc != NULL)\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = E_OUTOFMEMORY;\r\n  }\r\n  return *this;\r\n}\r\n\r\n\r\nCPropVariant& CPropVariant::operator=(bool bSrc)\r\n{\r\n  if (vt != VT_BOOL)\r\n  {\r\n    InternalClear();\r\n    vt = VT_BOOL;\r\n  }\r\n  boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt32 value)\r\n{\r\n  if (vt != VT_UI4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI4;\r\n  }\r\n  ulVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt64 value)\r\n{\r\n  if (vt != VT_UI8)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI8;\r\n  }\r\n  uhVal.QuadPart = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const FILETIME &value)\r\n{\r\n  if (vt != VT_FILETIME)\r\n  {\r\n    InternalClear();\r\n    vt = VT_FILETIME;\r\n  }\r\n  filetime = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int32 value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  \r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Byte value)\r\n{\r\n  if (vt != VT_UI1)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI1;\r\n  }\r\n  bVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int16 value)\r\n{\r\n  if (vt != VT_I2)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I2;\r\n  }\r\n  iVal = value;\r\n  return *this;\r\n}\r\n\r\n/*\r\nCPropVariant& CPropVariant::operator=(LONG value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  return *this;\r\n}\r\n*/\r\n\r\nstatic HRESULT MyPropVariantClear(PROPVARIANT *propVariant) \r\n{ \r\n  switch(propVariant->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      propVariant->vt = VT_EMPTY;\r\n      propVariant->wReserved1 = 0; \r\n      return S_OK;\r\n  }\r\n  return ::VariantClear((VARIANTARG *)propVariant); \r\n}\r\n\r\nHRESULT CPropVariant::Clear() \r\n{ \r\n  return MyPropVariantClear(this);\r\n}\r\n\r\nHRESULT CPropVariant::Copy(const PROPVARIANT* pSrc) \r\n{ \r\n  ::VariantClear((tagVARIANT *)this); \r\n  switch(pSrc->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));\r\n      return S_OK;\r\n  }\r\n  return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc)); \r\n}\r\n\r\n\r\nHRESULT CPropVariant::Attach(PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(this, pSrc, sizeof(PROPVARIANT));\r\n  pSrc->vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::Detach(PROPVARIANT* pDest)\r\n{\r\n  HRESULT hr = MyPropVariantClear(pDest);\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(pDest, this, sizeof(PROPVARIANT));\r\n  vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::InternalClear()\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n  return hr;\r\n}\r\n\r\nvoid CPropVariant::InternalCopy(const PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Copy(pSrc);\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n}\r\n\r\nint CPropVariant::Compare(const CPropVariant &a)\r\n{\r\n  if(vt != a.vt)\r\n    return 0; // it's mean some bug\r\n  switch (vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return 0;\r\n    \r\n    /*\r\n    case VT_I1:\r\n      return MyCompare(cVal, a.cVal);\r\n    */\r\n    case VT_UI1:\r\n      return MyCompare(bVal, a.bVal);\r\n\r\n    case VT_I2:\r\n      return MyCompare(iVal, a.iVal);\r\n    case VT_UI2:\r\n      return MyCompare(uiVal, a.uiVal);\r\n    \r\n    case VT_I4:\r\n      return MyCompare(lVal, a.lVal);\r\n    /*\r\n    case VT_INT:\r\n      return MyCompare(intVal, a.intVal);\r\n    */\r\n    case VT_UI4:\r\n      return MyCompare(ulVal, a.ulVal);\r\n    /*\r\n    case VT_UINT:\r\n      return MyCompare(uintVal, a.uintVal);\r\n    */\r\n    case VT_I8:\r\n      return MyCompare(hVal.QuadPart, a.hVal.QuadPart);\r\n    case VT_UI8:\r\n      return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);\r\n\r\n    case VT_BOOL:    \r\n      return -MyCompare(boolVal, a.boolVal);\r\n\r\n    case VT_FILETIME:\r\n      return ::CompareFileTime(&filetime, &a.filetime);\r\n    case VT_BSTR:\r\n      return 0; // Not implemented \r\n      // return MyCompare(aPropVarint.cVal);\r\n\r\n    default:\r\n      return 0;\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/PropVariant.h",
    "content": "// Windows/PropVariant.h\r\n\r\n#ifndef __WINDOWS_PROPVARIANT_H\r\n#define __WINDOWS_PROPVARIANT_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nclass CPropVariant : public tagPROPVARIANT\r\n{\r\npublic:\r\n  CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }\r\n  ~CPropVariant() { Clear(); }\r\n  CPropVariant(const PROPVARIANT& varSrc);\r\n  CPropVariant(const CPropVariant& varSrc);\r\n  CPropVariant(BSTR bstrSrc);\r\n  CPropVariant(LPCOLESTR lpszSrc);\r\n  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };\r\n  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }\r\n  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal = *(ULARGE_INTEGER*)&value; }\r\n  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }\r\n  CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }\r\n  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }\r\n  CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }\r\n  // CPropVariant(LONG value, VARTYPE vtSrc = VT_I4) { vt = vtSrc; lVal = value; }\r\n\r\n  CPropVariant& operator=(const CPropVariant& varSrc);\r\n  CPropVariant& operator=(const PROPVARIANT& varSrc);\r\n  CPropVariant& operator=(BSTR bstrSrc);\r\n  CPropVariant& operator=(LPCOLESTR lpszSrc);\r\n  CPropVariant& operator=(bool bSrc);\r\n  CPropVariant& operator=(UInt32 value);\r\n  CPropVariant& operator=(UInt64 value);\r\n  CPropVariant& operator=(const FILETIME &value);\r\n\r\n  CPropVariant& operator=(Int32 value);\r\n  CPropVariant& operator=(Byte value);\r\n  CPropVariant& operator=(Int16 value);\r\n  // CPropVariant& operator=(LONG  value);\r\n\r\n  HRESULT Clear();\r\n  HRESULT Copy(const PROPVARIANT* pSrc);\r\n  HRESULT Attach(PROPVARIANT* pSrc);\r\n  HRESULT Detach(PROPVARIANT* pDest);\r\n\r\n  HRESULT InternalClear();\r\n  void InternalCopy(const PROPVARIANT* pSrc);\r\n\r\n  int Compare(const CPropVariant &a1);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/PropVariantConversions.cpp",
    "content": "// PropVariantConversions.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <stdio.h>\r\n\r\n#include \"PropVariantConversions.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\nstatic UString ConvertUInt64ToString(UInt64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString ConvertInt64ToString(Int64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic char *UIntToStringSpec(UInt32 value, char *s, int numPos)\r\n{\r\n  char temp[16];\r\n  int pos = 0;\r\n  do \r\n  {\r\n    temp[pos++] = (char)('0' + value % 10);\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  int i;\r\n  for (i = 0; i < numPos - pos; i++)\r\n    *s++ = '0';\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n  return s;\r\n}\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)\r\n{\r\n  s[0] = '\\0';\r\n  SYSTEMTIME st;\r\n  if(!BOOLToBool(FileTimeToSystemTime(&ft, &st)))\r\n    return false;\r\n  s = UIntToStringSpec(st.wYear, s, 4);\r\n  *s++ = '-';\r\n  s = UIntToStringSpec(st.wMonth, s, 2);\r\n  *s++ = '-';\r\n  s = UIntToStringSpec(st.wDay, s, 2);\r\n  if (includeTime)\r\n  {\r\n    *s++ = ' ';\r\n    s = UIntToStringSpec(st.wHour, s, 2);\r\n    *s++ = ':';\r\n    s = UIntToStringSpec(st.wMinute, s, 2);\r\n    if (includeSeconds)\r\n    {\r\n      *s++ = ':';\r\n      UIntToStringSpec(st.wSecond, s, 2);\r\n    }\r\n  }\r\n  /*\r\n  sprintf(s, \"%04d-%02d-%02d\", st.wYear, st.wMonth, st.wDay);\r\n  if (includeTime)\r\n  {\r\n    sprintf(s + strlen(s), \" %02d:%02d\", st.wHour, st.wMinute);\r\n    if (includeSeconds)\r\n      sprintf(s + strlen(s), \":%02d\", st.wSecond);\r\n  }\r\n  */\r\n  return true;\r\n}\r\n\r\nUString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds)\r\n{\r\n  char s[32];\r\n  ConvertFileTimeToString(fileTime, s,  includeTime, includeSeconds);\r\n  return GetUnicodeString(s);\r\n}\r\n \r\n\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant)\r\n{\r\n  switch (propVariant.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return UString();\r\n    case VT_BSTR:\r\n      return propVariant.bstrVal;\r\n    case VT_UI1:\r\n      return ConvertUInt64ToString(propVariant.bVal);\r\n    case VT_UI2:\r\n      return ConvertUInt64ToString(propVariant.uiVal);\r\n    case VT_UI4:\r\n      return ConvertUInt64ToString(propVariant.ulVal);\r\n    case VT_UI8:\r\n      return ConvertUInt64ToString(propVariant.uhVal.QuadPart);\r\n    case VT_FILETIME:\r\n      return ConvertFileTimeToString(propVariant.filetime, true, true);\r\n    /*\r\n    case VT_I1:\r\n      return ConvertInt64ToString(propVariant.cVal);\r\n    */\r\n    case VT_I2:\r\n      return ConvertInt64ToString(propVariant.iVal);\r\n    case VT_I4:\r\n      return ConvertInt64ToString(propVariant.lVal);\r\n    case VT_I8:\r\n      return ConvertInt64ToString(propVariant.hVal.QuadPart);\r\n\r\n    case VT_BOOL:\r\n      return VARIANT_BOOLToBool(propVariant.boolVal) ? L\"+\" : L\"-\";\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 150245;\r\n      #else\r\n      return UString();\r\n      #endif\r\n  }\r\n}\r\n\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant)\r\n{\r\n  switch (propVariant.vt)\r\n  {\r\n    case VT_UI1:\r\n      return propVariant.bVal;\r\n    case VT_UI2:\r\n      return propVariant.uiVal;\r\n    case VT_UI4:\r\n      return propVariant.ulVal;\r\n    case VT_UI8:\r\n      return (UInt64)propVariant.uhVal.QuadPart;\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 151199;\r\n      #else\r\n      return 0;\r\n      #endif\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/PropVariantConversions.h",
    "content": "// Windows/PropVariantConversions.h\r\n\r\n#ifndef __PROPVARIANTCONVERSIONS_H\r\n#define __PROPVARIANTCONVERSIONS_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/MyString.h\"\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant);\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/Synchronization.cpp",
    "content": "// Windows/Synchronization.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Synchronization.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/Synchronization.h",
    "content": "// Windows/Synchronization.h\r\n\r\n#ifndef __WINDOWS_SYNCHRONIZATION_H\r\n#define __WINDOWS_SYNCHRONIZATION_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\n#ifdef _WIN32\r\n#include \"Handle.h\"\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\nclass CBaseEvent\r\n{\r\nprotected:\r\n  ::CEvent _object;\r\npublic:\r\n  bool IsCreated() { return Event_IsCreated(&_object) != 0; }\r\n  operator HANDLE() { return _object.handle; }\r\n  CBaseEvent() { Event_Construct(&_object); }\r\n  ~CBaseEvent() { Close(); }\r\n  HRes Close() { return Event_Close(&_object); }\r\n  #ifdef _WIN32\r\n  HRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),\r\n        BoolToBOOL(initiallyOwn), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  #endif\r\n\r\n  HRes Set() { return Event_Set(&_object); }\r\n  // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }\r\n  HRes Reset() { return Event_Reset(&_object); }\r\n  HRes Lock() { return Event_Wait(&_object); }\r\n};\r\n\r\nclass CManualResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  HRes Create(bool initiallyOwn = false)\r\n  {\r\n    return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);\r\n  }\r\n  HRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return ManualResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  #ifdef _WIN32\r\n  HRes CreateWithName(bool initiallyOwn, LPCTSTR name)\r\n  {\r\n    return CBaseEvent::Create(true, initiallyOwn, name);\r\n  }\r\n  #endif\r\n};\r\n\r\nclass CAutoResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  HRes Create()\r\n  {\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  HRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\nclass CObject: public CHandle\r\n{\r\npublic:\r\n  HRes Lock(DWORD timeoutInterval = INFINITE)\r\n    { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }\r\n};\r\nclass CMutex: public CObject\r\n{\r\npublic:\r\n  HRes Create(bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  HRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  HRes Release() \r\n  { \r\n    return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();\r\n  }\r\n};\r\nclass CMutexLock\r\n{\r\n  CMutex *_object;\r\npublic:\r\n  CMutexLock(CMutex &object): _object(&object) { _object->Lock(); } \r\n  ~CMutexLock() { _object->Release(); }\r\n};\r\n#endif\r\n\r\nclass CSemaphore\r\n{\r\n  ::CSemaphore _object;\r\npublic:\r\n  CSemaphore() { Semaphore_Construct(&_object); }\r\n  ~CSemaphore() { Close(); }\r\n  HRes Close() {  return Semaphore_Close(&_object); }\r\n  operator HANDLE() { return _object.handle; }\r\n  HRes Create(UInt32 initiallyCount, UInt32 maxCount)\r\n  {\r\n    return Semaphore_Create(&_object, initiallyCount, maxCount);\r\n  }\r\n  HRes Release() { return Semaphore_Release1(&_object); }\r\n  HRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }\r\n  HRes Lock() { return Semaphore_Wait(&_object); }\r\n};\r\n\r\nclass CCriticalSection\r\n{\r\n  ::CCriticalSection _object;\r\npublic:\r\n  CCriticalSection() { CriticalSection_Init(&_object); }\r\n  ~CCriticalSection() { CriticalSection_Delete(&_object); }\r\n  void Enter() { CriticalSection_Enter(&_object); }\r\n  void Leave() { CriticalSection_Leave(&_object); }\r\n};\r\n\r\nclass CCriticalSectionLock\r\n{\r\n  CCriticalSection *_object;\r\n  void Unlock()  { _object->Leave(); }\r\npublic:\r\n  CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); } \r\n  ~CCriticalSectionLock() { Unlock(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/System.cpp",
    "content": "// Windows/System.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"System.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors()\r\n{\r\n  SYSTEM_INFO systemInfo;\r\n  GetSystemInfo(&systemInfo);\r\n  return (UInt32)systemInfo.dwNumberOfProcessors;\r\n}\r\n\r\n#if !defined(_WIN64) && defined(__GNUC__)\r\n\r\ntypedef struct _MY_MEMORYSTATUSEX {\r\n  DWORD dwLength;\r\n  DWORD dwMemoryLoad;\r\n  DWORDLONG ullTotalPhys;\r\n  DWORDLONG ullAvailPhys;\r\n  DWORDLONG ullTotalPageFile;\r\n  DWORDLONG ullAvailPageFile;\r\n  DWORDLONG ullTotalVirtual;\r\n  DWORDLONG ullAvailVirtual;\r\n  DWORDLONG ullAvailExtendedVirtual;\r\n} MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX;\r\n\r\n#else\r\n\r\n#define MY_MEMORYSTATUSEX MEMORYSTATUSEX\r\n#define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX\r\n\r\n#endif\r\n\r\ntypedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);\r\n\r\nUInt64 GetRamSize()\r\n{\r\n  MY_MEMORYSTATUSEX stat;\r\n  stat.dwLength = sizeof(stat);\r\n  #ifdef _WIN64\r\n  if (!::GlobalMemoryStatusEx(&stat))\r\n    return 0;\r\n  return stat.ullTotalPhys;\r\n  #else\r\n  GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")),\r\n        \"GlobalMemoryStatusEx\");\r\n  if (globalMemoryStatusEx != 0)\r\n    if (globalMemoryStatusEx(&stat))\r\n      return stat.ullTotalPhys;\r\n  {\r\n    MEMORYSTATUS stat;\r\n    stat.dwLength = sizeof(stat);\r\n    GlobalMemoryStatus(&stat);\r\n    return stat.dwTotalPhys;\r\n  }\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/System.h",
    "content": "// Windows/System.h\r\n\r\n#ifndef __WINDOWS_SYSTEM_H\r\n#define __WINDOWS_SYSTEM_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors();\r\nUInt64 GetRamSize();\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/Thread.h",
    "content": "// Windows/Thread.h\r\n\r\n#ifndef __WINDOWS_THREAD_H\r\n#define __WINDOWS_THREAD_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\" \r\n{ \r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\nnamespace NWindows {\r\n\r\nclass CThread\r\n{\r\n  ::CThread thread;\r\npublic:\r\n  CThread() { Thread_Construct(&thread); }\r\n  ~CThread() { Close(); }\r\n  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }\r\n  HRes Close()  { return Thread_Close(&thread); }\r\n  HRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n    { return Thread_Create(&thread, startAddress, parameter); }\r\n  HRes Wait() { return Thread_Wait(&thread); }\r\n  \r\n  #ifdef _WIN32\r\n  DWORD Resume() { return ::ResumeThread(thread.handle); }\r\n  DWORD Suspend() { return ::SuspendThread(thread.handle); }\r\n  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }\r\n  int GetPriority() { return ::GetThreadPriority(thread.handle); }\r\n  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }\r\n  #endif\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/CPP/Windows/Time.h",
    "content": "// Windows/Time.h\r\n\r\n#ifndef __WINDOWS_TIME_H\r\n#define __WINDOWS_TIME_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\ninline bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)\r\n{\r\n  return BOOLToBool(::DosDateTimeToFileTime(UInt16(dosTime >> 16), \r\n      UInt16(dosTime & 0xFFFF), &fileTime));\r\n}\r\n\r\nconst UInt32 kHighDosTime = 0xFF9FBF7D;\r\nconst UInt32 kLowDosTime = 0x210000;\r\n\r\ninline bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)\r\n{\r\n  WORD datePart, timePart;\r\n  if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))\r\n  {\r\n    if (fileTime.dwHighDateTime >= 0x01C00000) // 2000\r\n      dosTime = kHighDosTime;\r\n    else\r\n      dosTime = kLowDosTime;\r\n    return false;\r\n  }\r\n  dosTime = (((UInt32)datePart) << 16) + timePart;\r\n  return true;\r\n}\r\n\r\nconst UInt32 kNumTimeQuantumsInSecond = 10000000;\r\nconst UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;\r\n\r\ninline void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)\r\n{\r\n  UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;\r\n  fileTime.dwLowDateTime = (DWORD)v;\r\n  fileTime.dwHighDateTime = (DWORD)(v >> 32);\r\n}\r\n\r\ninline bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)\r\n{\r\n  UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;\r\n  if (winTime < kUnixTimeStartValue)\r\n  {\r\n    unixTime = 0;\r\n    return false;\r\n  }\r\n  winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;\r\n  if (winTime > 0xFFFFFFFF)\r\n  {\r\n    unixTime = 0xFFFFFFFF;\r\n    return false;\r\n  }\r\n  unixTime = (UInt32)winTime;\r\n  return true;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/Makefile",
    "content": "\n# Copyright (C) 2006-2008 Junjiro Okajima\n# Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described ones in lzma and squashfs.\n\n# $Id: Makefile,v 1.30 2008-03-12 16:24:54 jro Exp $\n\n# paths\nSqlzma = ${CURDIR}\n\nLzmaVer =  \nLzma = ${Sqlzma}/${LzmaVer}\nSqVer = squashfs3.3\nSquashfs = ${Sqlzma}/${SqVer}\n#KVer = linux-2.6.24.3\nSqFs = ${Squashfs}/kernel-patches/${KVer}/fs/squashfs\n#KDir = /lib/modules/$(shell uname -r)/build\n\nLzmaC = ${Lzma}/C/Compress/Lzma\nLzmaAlone = ${Lzma}/CPP/7zip/Compress/LZMA_Alone\n\nSqTools = ${Squashfs}/squashfs-tools\n\n# enable it if you want to add -g option when compiling\nUseDebugFlags =\n# disable it if you don't want to compile squashfs kernel module here\nBuildSquashfs = 1\n\nexport\n\nall:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\nclean:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\t${RM} *~\n\n########################################\n\n#-include priv.mk\n\n#ifdef BuildSquashfs\n#CONFIG_SQUASHFS = m\n#CONFIG_SQUASHFS_EMBEDDED =\n#CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE = 3\n#EXTRA_CFLAGS = -I${Sqlzma} -I${SqFs}/../../include -Wall -Werror\n#EXTRA_CFLAGS += -DCONFIG_SQUASHFS_MODULE -UCONFIG_SQUASHFS\n#EXTRA_CFLAGS += -UCONFIG_SQUASHFS_EMBEDDED -DCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3\n# if you enabled CONFIG_PREEMPT, but want CPU to try concentrating\n# the uncompression, then define UnsquashNoPreempt.\n# if you don't define UnsquashNoPreempt, the behaviour follows\n# the CONFIG_PREEMPT.\n#EXTRA_CFLAGS += -DUnsquashNoPreempt\n#export\n\n# the environment variables are not inherited since 2.6.23\n#MAKE += SQLZMA_EXTRA_CFLAGS=\"$(shell echo ${EXTRA_CFLAGS} | sed -e 's/\\\"/\\\\\\\\\\\\\"/g')\"\n#\n#all: all_sq\n#\n#FORCE:\n#all_sq:\n#\t${MAKE} -C ${KDir} M=${SqFs} modules\n\n#clean: clean_sq\n#clean_sq:\n#\t${MAKE} -C ${KDir} M=${SqFs} clean\n#endif\n\n########################################\n#\n#load:\n#\tfor i in ${LzmaC}/kmod/unlzma.ko ${LzmaC}/kmod/sqlzma.ko \\\n#\t\t${SqFs}/squashfs.ko; \\\n#\tdo sudo insmod $$i; done\n#\n#unload:\n#\t-sudo rmmod squashfs sqlzma unlzma\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/sqlzma.h",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.\n */\n\n/* $Id: sqlzma.h,v 1.20 2008-03-12 16:58:34 jro Exp $ */\n\n#ifndef __sqlzma_h__\n#define __sqlzma_h__\n\n#ifndef __KERNEL__\n#include <stdlib.h>\n#include <string.h>\n#include <zlib.h>\n#ifdef _REENTRANT\n#include <pthread.h>\n#endif\n#else\n#include <linux/zlib.h>\n#endif\n#define _7ZIP_BYTE_DEFINED\n\n/*\n * detect the compression method automatically by the first byte of compressed\n * data.\n * according to rfc1950, the first byte of zlib compression must be 0x?8.\n */\n#define is_lzma(c)\t(c == 0x5d)\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#ifndef __KERNEL__\n/* for mksquashfs only */\nstruct sqlzma_opts {\n\tunsigned int\ttry_lzma;\n\tunsigned int \tdicsize;\n};\nint sqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in,\n\t      uInt avail_in, Bytef *next_out, uInt avail_out);\n#endif\n\n/* ---------------------------------------------------------------------- */\n/*\n * Three patterns for sqlzma uncompression. very dirty code.\n * - kernel space (squashfs kernel module)\n * - user space with pthread (mksquashfs)\n * - user space without pthread (unsquashfs)\n */\n\nstruct sized_buf {\n\tunsigned int\tsz;\n\tunsigned char\t*buf;\n};\n\nenum {SQUN_PROB, SQUN_RESULT, SQUN_LAST};\nstruct sqlzma_un {\n\tint\t\t\tun_lzma;\n\tstruct sized_buf\tun_a[SQUN_LAST];\n\tunsigned char           un_prob[31960]; /* unlzma 64KB - 1MB */\n\tz_stream\t\tun_stream;\n#define un_cmbuf\tun_stream.next_in\n#define un_cmlen\tun_stream.avail_in\n#define un_resbuf\tun_stream.next_out\n#define un_resroom\tun_stream.avail_out\n#define un_reslen\tun_stream.total_out\n};\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz);\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst);\nvoid sqlzma_fin(struct sqlzma_un *un);\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\n};\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/sqmagic.h",
    "content": "/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE must follow the one in squashfs.\n */\n\n/* $Id: sqmagic.h,v 1.2 2006-11-27 03:54:58 jro Exp $ */\n\n#ifndef __sqmagic_h__\n#define __sqmagic_h__\n\n/* see SQUASHFS_MAGIC in squashfs_fs.h */\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/Makefile",
    "content": "\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\nINCLUDEDIR = .\n\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\nifdef UseDebugFlags\nDebugFlags = -g -Wall -Wno-unused-variable -O0 -UNDEBUG\nendif\nCFLAGS += -I${Sqlzma} -D_REENTRANT -DNDEBUG ${DebugFlags}\nLDLIBS += -lz -lm -L${LzmaAlone} -L${LzmaC}\nTgt = mksquashfs unsquashfs\n\nall: ${Tgt}\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h \\\n\t${LzmaAlone}/liblzma_r.a ${LzmaC}/libunlzma_r.a\nmksquashfs: LDLIBS += -lpthread -lunlzma_r -llzma_r -lstdc++\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\nunsquashfs.o: CFLAGS += -U_REENTRANT\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h ${LzmaC}/libunlzma.a\nunsquashfs: LDLIBS += -lunlzma\nunsquashfs: unsquashfs.o\n\t$(CC) unsquashfs.o -o unsquashfs $(LDLIBS) -lz\n\nclean:\n\t${RM} *~ *.o ${Tgt}\n\n-include test.mk\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\ntypedef union squashfs_inode_header_1 squashfs_inode_header_1;\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\nint sparse_files = TRUE;\nint old_exclude = TRUE;\nint use_regex = FALSE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\nstruct sqlzma_un un;\nstruct sqlzma_opts sqlzma_opts = {\n\t.try_lzma\t= 1,\n\t.dicsize\t= SQUASHFS_FILE_SIZE\n};\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* exclude file handling */\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint old_excluded(char *filename, struct stat *buf);\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nstruct pathnames *paths = NULL;\nstruct pathname *path = NULL;\nstruct pathname *stickypath = NULL;\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* recovery file for abnormal exit on appending */\nchar recovery_file[1024] = \"\";\nint recover = TRUE;\n\n/* data allocator status struct.  Allocators are used to keep\n  track of memory buffers passed between different threads */\nstruct allocator {\n\tint\t\tmax_buffers;\n\tint\t\tcount;\n\tint\t\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t\twait;\n};\n\n/* struct describing a memory buffer passed between threads */\nstruct file_buffer {\n\tlong long\t\tfile_size;\n\tstruct allocator\t*allocator;\n\tvoid\t\t\t(*release)(int);\n\tint\t\t\trelease_data;\n\tlong long\t\tblock;\n\tint\t\t\tsize;\n\tint\t\t\tc_byte;\n\tunsigned int\t\tblock_order;\n\tint\t\t\tfragment;\n\tint\t\t\terror;\n\tstruct file_buffer\t*next;\n\tchar\t\t\tdata[0];\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n/* describes the list of blocks in a file which is a possible\n   duplicate.  For each block, it indicates whether the block is\n   in memory or on disk */\nstruct buffer_list {\n\tlong long start;\n\tint size;\n\tstruct file_buffer *read_buffer;\n};\n\nstruct allocator *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *, char *, struct dir_info *));\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\nextern struct priority_entry *priority_list[65536];\n\n\nstruct allocator *alloc_init(int buffer_size, int max_buffers)\n{\n\tstruct allocator *allocator = malloc(sizeof(struct allocator));\n\n\tif(allocator == NULL)\n\t\treturn NULL;\n\n\tallocator->max_buffers = max_buffers;\n\tallocator->buffer_size = buffer_size;\n\tallocator->count = 0;\n\tpthread_mutex_init(&allocator->mutex, NULL);\n\tpthread_cond_init(&allocator->wait, NULL);\n\n\treturn allocator;\n}\n\n\nstruct file_buffer *alloc_get(struct allocator *allocator)\n{\n\tstruct file_buffer *file_buffer;\n\t\n\tpthread_mutex_lock(&allocator->mutex);\n\n\twhile(allocator->count == allocator->max_buffers)\n\t\tpthread_cond_wait(&allocator->wait, &allocator->mutex);\n\n\tif((file_buffer = malloc(sizeof(struct file_buffer) + allocator->buffer_size)) == NULL)\n\t\tgoto failed;\n\n\tfile_buffer->release = NULL;\n\tfile_buffer->allocator = allocator;\n\tallocator->count ++;\n\nfailed:\n\tpthread_mutex_unlock(&allocator->mutex);\n\treturn file_buffer;\n}\n\n\nstruct file_buffer *alloc_get_2(struct allocator *allocator, void (*release)(int), int release_data)\n{\n\tstruct file_buffer *file_buffer = alloc_get(allocator);\n\n\tif(file_buffer) {\n\t\tfile_buffer->release = release;\n\t\tfile_buffer->release_data = release_data;\n\t}\n\treturn file_buffer;\n}\n\n\nvoid alloc_free(struct file_buffer *file_buffer)\n{\n\tstruct allocator *allocator;\n\n\tif(file_buffer == NULL)\n\t\treturn;\n\n\tallocator = file_buffer->allocator;\n\n\tif(file_buffer->release)\n\t\tfile_buffer->release(file_buffer->release_data);\n\n\tpthread_mutex_lock(&allocator->mutex);\n\tfree(file_buffer);\n\tif(allocator->count == 0)\n\t\tERROR(\"alloc_free: freeing buffer for empty allocator!\\n\");\n\telse\n\t\tallocator->count --;\n\tpthread_cond_signal(&allocator->wait);\n\tpthread_mutex_unlock(&allocator->mutex);\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tif(thread[i])\n\t\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, &thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\n\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t}\n\n\tres = sqlzma_cm(&sqlzma_opts, stream, (void *)s, size, (void *)d,\n\t\t\tblock_size);\n\tc_byte = stream->total_out;\n\n\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %lld, start_block 0x%llx, blocks %d, fragment %d, offset %d, size %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block 0x%llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %lld, start_block 0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %lld, start_block 0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir)\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir);\n\telse\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL);\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment, int *cached_fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\n\tif(fragment->index == *cached_fragment || fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn buffer + fragment->offset;\n\n\tif(fragment_data && fragment->index == fragments)\n\t\treturn fragment_data->data + fragment->offset;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragment_table[fragment->index].pending)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)cbuffer, .sz = size},\n\t\t\t{.buf = (void *)buffer, .sz = bytes}\n\t\t};\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tBAD_ERROR(\"%s:%d: res %d\\n\", __func__, __LINE__, res);\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\t*cached_fragment = fragment->index;\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid ensure_fragments_flushed()\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(fragments_outstanding)\n\t\tpthread_cond_wait(&fragment_waiting, &fragment_mutex);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].pending = TRUE;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\nvoid frag_release(int block)\n{\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragment_table[block].pending = FALSE;\n\tpthread_cond_signal(&fragment_waiting);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = alloc_get(fragment_buffer);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tlong long slist[meta_blocks];\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block 0x%llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_buffer(struct buffer_list *buffer_list, unsigned int blocks)\n{\n\tunsigned short chksum = 0;\n\tint block;\n\n\tfor(block = 0; block < blocks; block ++) {\n\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\tif(b->read_buffer)\n\t\t\tchksum = get_checksum(b->read_buffer->data, b->read_buffer->size, chksum);\n\t\telse if(b->size != 0)\n\t\t\tchksum = get_checksum(read_from_disk(b->start, b->size), b->size, chksum);\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\nint cached_frag = -1;\nchar fragdata[SQUASHFS_FILE_MAX_SIZE];\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\nchar cached_fragment[SQUASHFS_FILE_MAX_SIZE];\nint cached_frag1 = -1;\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), file_size);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nchar buffer2[SQUASHFS_FILE_MAX_SIZE];\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tchar *buffer;\n\t\t\tint block;\n\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks * sizeof(unsigned int)) != 0)\n\t\t\t\tcontinue;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_buffer(buffer_list, blocks);\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1), frag_bytes);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\n\n\t\t\t\tif(b->read_buffer)\n\t\t\t\t\tbuffer = b->read_buffer->data;\n\t\t\t\telse if(b->size)\n\t\t\t\t\tbuffer = read_from_disk(b->start, b->size);\n\t\t\t\telse\n\t\t\t\t\tcontinue;\n\n\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\n\t\t\t\tif(memcmp(buffer, buffer2, b->size) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_start += b->size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tchar *fragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment, &cached_frag1);\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\n\tstruct file_buffer *file_buffer;\n\tstatic int block_order = 0;\n\tint blocks, byte, count, expected, file, frag_block;\n\tlong long bytes, read_size;\n\n\tif(dir_ent->inode->read)\n\t\treturn;\n\n\tdir_ent->inode->read = TRUE;\nagain:\n\tbytes = 0;\n\tcount = 0;\n\tfile_buffer = NULL;\n\tread_size = buf->st_size;\n\tblocks = (read_size + block_size - 1) >> block_log;\n\tfrag_block = !no_fragments && (always_use_fragments ||\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\texpected = read_size - ((long long) count * block_size) > block_size ? block_size : read_size - ((long long) count * block_size);\n\n\t\tif(file_buffer)\n\t\t\tqueue_put(from_reader, file_buffer);\n\t\tfile_buffer = alloc_get(reader_buffer);\n\n\t\tbyte = file_buffer->size = read(file, file_buffer->data, block_size);\n\n\t\tfile_buffer->block_order = block_order ++;\n\t\tfile_buffer->file_size = read_size;\n\n\t\tif(byte != expected)\n\t\t\tgoto restat;\n\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->error = FALSE;\n\n\t\tbytes += byte;\n\t\tcount ++;\n\t} while(count < blocks);\n\n\tif(read_size != bytes)\n\t\tgoto restat;\n\n\tif(expected == block_size) {\n\t\tchar buffer;\n\n\t\tif(read(file, &buffer, 1) == 1)\n\t\t\tgoto restat;\n\t}\n\n\tfile_buffer->fragment = (file_buffer->block == frag_block);\n\n\tif(file_buffer->fragment)\n\t\tqueue_put(from_deflate, file_buffer);\n\telse\n\t\tqueue_put(from_reader, file_buffer);\n\n\tclose(file);\n\n\treturn;\n\nread_err:\n\tfile_buffer = alloc_get(reader_buffer);\n\tfile_buffer->block_order = block_order ++;\nread_err2:\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n\treturn;\nrestat:\n\tfstat(file, &buf2);\n\tclose(file);\n\tif(read_size != buf2.st_size) {\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\n\t\tfile_buffer->error = 2;\n\t\tqueue_put(from_deflate, file_buffer);\n\t\tgoto again;\n\t}\n\tgoto read_err2;\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\tthread[0] = 0;\n\n\tpthread_exit(NULL);\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tperror(\"Lseek on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n\t\t\tperror(\"Write on destination failed\");\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\nint all_zero(struct file_buffer *file_buffer)\n{\n\tint i;\n\tlong entries = file_buffer->size / sizeof(long);\n\tlong *p = (long *) file_buffer->data;\n\n\tfor(i = 0; i < entries && p[i] == 0; i++);\n\n\tif(i == entries) {\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1); i < file_buffer->size &&\n\t\t\t\t\t\tfile_buffer->data[i] == 0; i++);\n\n\t\treturn i == file_buffer->size;\n\t}\n\n\treturn 0;\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer = alloc_get(writer_buffer);\n\n\t\tif(sparse_files && all_zero(file_buffer)) \n\t\t\twrite_buffer->c_byte = 0;\n\t\telse\n\t\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\n\t\twrite_buffer->file_size = file_buffer->file_size;\n\t\twrite_buffer->block = file_buffer->block;\n\t\twrite_buffer->block_order = file_buffer->block_order;\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\n\t\twrite_buffer->fragment = FALSE;\n\t\twrite_buffer->error = FALSE;\n\t\talloc_free(file_buffer);\n\t\tqueue_put(from_deflate, write_buffer);\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer = alloc_get_2(writer_buffer, frag_release, file_buffer->block);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\twrite_buffer->size = compressed_size;\n\t\twrite_buffer->block = bytes;\n\t\tqueue_put(to_writer, write_buffer);\n\t\tbytes += compressed_size;\n\t\ttotal_uncompressed += file_buffer->size;\n\t\ttotal_compressed += compressed_size;\n\t\tTRACE(\"Writing fragment %lld, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\n\t\tfragments_outstanding --;\n\t\tpthread_cond_signal(&fragment_waiting);\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\talloc_free(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->block_order);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int block_order = 0;\n\tint hash = BLOCK_HASH(block_order);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->block_order == block_order)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->block_order == block_order)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tblock_order ++;\n\n\treturn file_buffer;\n}\n\n\nint progress_bar(long long current, long long max, int columns)\n{\n\tint max_digits = ceil(log10(max));\n\tint used = max_digits * 2 + 10;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(!progress || columns - used < 0)\n\t\treturn 0;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n\treturn 0;\n}\n\n\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n}\n\n\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\talloc_free(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, struct file_buffer *file_buffer, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum)) {\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\n\t\treturn;\n\t}\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\talloc_free(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n\n\treturn;\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\n{\n\tint block;\n\tunsigned int frag_bytes;\n\tlong long file_bytes, start;\n\tstruct fragment *fragment;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list;\n\tstruct file_buffer *read_buffer;\n\tint status;\n\n\t*duplicate_file = FALSE;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tif(reader_buffer) {\n\t\t\tread_buffer = reader_buffer;\n\t\t\treader_buffer = NULL;\n\t\t} else {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tif(read_buffer->c_byte) {\n\t\t\tread_buffer->block = bytes;\n\t\t\tbytes += read_buffer->size;\n\t\t\tfile_bytes += read_buffer->size;\n\t\t\tqueue_put(to_writer, read_buffer);\n\t\t} else\n\t\t\talloc_free(read_buffer);\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t} else\n\t\tread_buffer = NULL;\n\n\tfragment = get_and_fill_fragment(read_buffer);\n\talloc_free(read_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tif(block) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\n{\n\tint block, thresh;\n\tunsigned int frag_bytes;\n\tlong long file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer *read_buffer;\n\tstruct buffer_list *buffer_list;\n\tint status;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tensure_fragments_flushed();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tthresh = blocks > (writer_buffer_size - processors) ? blocks - (writer_buffer_size - processors): 0;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tif(reader_buffer) {\n\t\t\tread_buffer = reader_buffer;\n\t\t\treader_buffer = NULL;\n\t\t } else {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tbuffer_list[block].start = bytes;\n\t\tbuffer_list[block].size = read_buffer->size;\n\n\t\tif(read_buffer->c_byte) {\n\t\t\tread_buffer->block = bytes;\n\t\t\tbytes += read_buffer->size;\n\t\t\tfile_bytes += read_buffer->size;\n\t\t\tif(block < thresh) {\n\t\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else\n\t\t\t\tbuffer_list[block].read_buffer = read_buffer;\n\t\t} else {\n\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\talloc_free(read_buffer);\n\t\t}\n\t\tprogress_bar(++cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t} else\n\t\tread_buffer = NULL;\n\n\tqueue_put(to_writer, NULL);\n\tif(queue_get(from_writer) != 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tif(buffer_list[block].read_buffer)\n\t\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\n\t\tfragment = get_and_fill_fragment(read_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\talloc_free(buffer_list[block].read_buffer);\n\t\tbytes = buffer_list[0].start;\n\t\tif(thresh && !block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\n\talloc_free(read_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tif(block && thresh) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tbytes = start;\n\t\tif(!block_device)\n\t\t\tftruncate(fd, bytes);\n\t}\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\talloc_free(buffer_list[blocks].read_buffer);\n\tfree(buffer_list);\n\tfree(block_list);\n\talloc_free(read_buffer);\n\treturn status;\n}\n\n\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tint status;\n\tstruct file_buffer *read_buffer;\n\tlong long read_size;\n\nagain:\n\tread_buffer = get_file_buffer(from_deflate);\n\tstatus = read_buffer->error;\n\tif(status) {\n\t\talloc_free(read_buffer);\n\t\tgoto file_err;\n\t}\n\t\n\tread_size = read_buffer->file_size;\n\n\tif(read_size == 0) {\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t\talloc_free(read_buffer);\n\t} else if(!no_fragments && (read_size < block_size))\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\telse if(pre_duplicate(read_size))\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\telse\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\nfile_err:\n\tif(status == 2) {\n\t\tERROR(\"File %s changed size while reading filesystem, attempting to re-read\\n\", dir_ent->pathname);\n\t\tgoto again;\n\t} else if(status == 1) {\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\", dir_ent->pathname);\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t}\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\n\tif((buf->st_mode & S_IFMT) == S_IFREG)\n\t\testimated_uncompressed += (buf->st_size + block_size - 1) >> block_log;\n\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\tstruct pathnames *new;\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", filename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\\n\", filename, buf.st_mode & S_IFMT);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(old_exclude) {\n\t\t\tif(old_excluded(filename, &buf))\n\t\t\t\tcontinue;\n\t\t} else {\n\t\t\tif(excluded(paths, dir_name, &new))\n\t\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, new, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type = -1;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\twrite_file(inode, dir_ent, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tdir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tBAD_ERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t}\n\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\twrite_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 20; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint old_excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint old_add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(processors * 2);\n\treader_buffer = alloc_init(block_size, reader_buffer_size);\n\twriter_buffer = alloc_init(block_size, writer_buffer_size);\n\tfragment_buffer = alloc_init(block_size, processors * 2);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\n\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\n}\n\n\t\t\t\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing exclude which subsumes the exclude currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific excludes, delete as they're subsumed by this exclude\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\t\n\t\nvoid add_exclude(char *target)\n{\n\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 || strncmp(target, \"../\", 3) == 0)\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with -wildcards or -regex options\\n\");\t\n\telse if(strncmp(target, \"... \", 4) == 0)\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\n\telse\t\n\t\tpath = add_path(path, target, target);\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n, res;\n\t\t\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\n\t*new = init_subdir();\n\tif(stickypath)\n\t\t*new = add_subdir(*new, stickypath);\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\n\t\t\tif(match && path->name[i].paths == NULL) {\n\t\t\t\t/* match on a leaf component, any subdirectories in the\n\t\t\t\t * filesystem should be excluded */\n\t\t\t\tres = TRUE;\n\t\t\t\tgoto empty_set;\n\t\t\t}\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t\t/* no matching names found, return empty new search set */\n\t\t\tres = FALSE;\n\t\t\tgoto empty_set;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches).\n\t * Return new set */\n\treturn FALSE;\n\nempty_set:\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn res;\n}\n\n\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\n#define RECOVER_ID_SIZE 28\n\nvoid write_recovery_data(squashfs_super_block *sBlk)\n{\n\tint recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\n\tpid_t pid = getpid();\n\tchar *metadata;\n\tchar header[] = RECOVER_ID;\n\n\tif(recover == FALSE) {\n\t\tprintf(\"No recovery data option specified.\\n\");\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\n\t\treturn;\n\t}\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in write_recovery_data\\n\");\n\n\tread_bytes(fd, sBlk->inode_table_start, bytes, metadata);\n\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\", getbase(destination_file), pid);\n\tif((recoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1)\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  Aborting\\n\", strerror(errno));\n\t\t\n\tif(write(recoverfd, header, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tif(write(recoverfd, sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tif(write(recoverfd, metadata, bytes) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tclose(recoverfd);\n\tfree(metadata);\n\t\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file, recovery_file);\n\tprintf(\"to restore filesystem\\n\\n\");\n}\n\n\nvoid read_recovery_data(char *recovery_file, char *destination_file)\n{\n\tint fd, recoverfd, bytes;\n\tsquashfs_super_block orig_sBlk, sBlk;\n\tchar *metadata;\n\tint readbytes;\n\tstruct stat buf;\n\tchar header[] = RECOVER_ID;\n\tchar header2[RECOVER_ID_SIZE];\n\n\tif((recoverfd = open(recovery_file, O_RDONLY)) == -1)\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\", strerror(errno));\n\n\tif(stat(destination_file, &buf) == -1)\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\", strerror(errno));\n\n\tif((fd = open(destination_file, O_RDWR)) == -1)\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\", strerror(errno));\n\n\tif(read(recoverfd, header2, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\n\n\tif(read(recoverfd, &sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\n\tread_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &orig_sBlk);\n\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4, sizeof(squashfs_super_block) - 4) != 0)\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to match\\n\");\n\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in read_recovery_data\\n\");\n\n\tif((readbytes = read(recoverfd, metadata, bytes)) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\n\tif(readbytes != bytes)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\twrite_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\twrite_bytes(fd, sBlk.inode_table_start, bytes, metadata);\n\n\tclose(recoverfd);\n\tclose(fd);\n\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\", recovery_file);\n\t\n\texit(0);\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.3-CVS (2007/12/04)\\n\");\\\n \tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n     \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n \tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\\\n\tprintf(\"and LZMA support for slax.org by jro.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct winsize winsize;\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT;\n\tint s_minor;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tun.un_lzma = 1;\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-recover\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\n\t\t\trecover = FALSE;\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = FALSE;\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\n\t\t\tsparse_files = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0\n\t\t\t|| strcmp(argv[i], \"-lzmadic\") == 0) {\n\t\t\tlong bs;\n\t\t\tunsigned int bl;\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -b|-lzmadic missing block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tbs = strtol(argv[i], &b, 10);\n\t\t\tif(*b == 'm' || *b == 'M')\n\t\t\t\tbs *= 1048576;\n\t\t\telse if(*b == 'k' || *b == 'K')\n\t\t\t\tbs *= 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tERROR(\"%s: -b|-lzmadic invalid size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tbl = slog(bs);\n\t\t\tif(bl == 0) {\n\t\t\t\tERROR(\"%s: -b|-lzmadic size not power of two or not between 4096 and 1Mbyte\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif (!strcmp(argv[i - 1], \"-b\")) {\n\t\t\t\tblock_size = bs;\n\t\t\t\tblock_log = bl;\n\t\t\t}\n\t\t\tsqlzma_opts.dicsize = bs;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n\t\t\tun.un_lzma = 0;\n\t\t\tsqlzma_opts.try_lzma = 0;\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data using recovery file <name>\\n\");\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery file\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards (globbing) to be used in\\n\\t\\t\\texclude dirs/files\\n\");\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n\t\t\tERROR(\"-lzmadic <dic_size>\\tset the LZMA dictionary\"\n\t\t\t      \" size to <dic_size>\\n\"\n\t\t\t      \"\\t\\t\\tDefault value always follow the block\"\n\t\t\t      \" size\\n\"\n\t\t\t      \"\\t\\t\\tUse this alone or AFTER -b option\\n\");\n\t\t\tERROR(\"-nolzma\\t\\t\\tnever try LZMA compression\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n\tif(block_size <= 65536 && sparse_files == FALSE)\n\t\ts_minor = 0;\n\telse\n\t\ts_minor = SQUASHFS_MINOR;\n\n        for(i = 0; i < source; i++)\n                if(lstat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tsignal(SIGTERM, sighandler2);\n\tsignal(SIGINT, sighandler2);\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\t\tif(old_exclude)\n\t\t\t\t\t\told_add_exclude(filename);\n\t\t\t\t\telse\n\t\t\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc)\n\t\t\tif(old_exclude)\n\t\t\t\told_add_exclude(argv[i++]);\n\t\t\telse\n\t\t\t\tadd_exclude(argv[i++]);\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\t//sqlzma_opts.dicsize = block_size;\n\t\ts_minor = sBlk.s_minor;\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t}\n\n\tinitialise_threads();\n\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tERROR(\"%s:%d: %d\\n\", __func__, __LINE__, i);\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t\tif (sqlzma_opts.try_lzma)\n\t\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tif (sqlzma_opts.try_lzma)\n\t\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = (inode_dir_offset + inode_dir_file_size) & ~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = (inode_dir_offset + inode_dir_file_size) & (SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tscache_bytes = root_inode_offset + root_inode_size;\n\t\tsdirectory_cache_bytes = uncompressed_data;\n\t\tsdata_cache = (char *)malloc(scache_bytes);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\twrite_recovery_data(&sBlk);\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(progress) {\n\t\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\t\tcolumns = 80;\n\t\t} else\n\t\t\tcolumns = winsize.ws_col;\n\t\tsignal(SIGWINCH, sigwinch_handler);\n\t}\n\n\tif(path || stickypath) {\n\t\tpaths = init_subdir();\n\t\tif(path)\n\t\t\tpaths = add_subdir(paths, path);\n\t\tif(stickypath)\n\t\t\tpaths = add_subdir(paths, stickypath);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n\tif (!un.un_lzma)\n\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = s_minor;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tensure_fragments_flushed();\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\n\n\tsBlk.no_uids = uid_count;\n\tif(sBlk.no_uids) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tsBlk.no_guids = guid_count;\n\tif(sBlk.no_guids) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\tclose(fd);\n\n\tif(recovery_file[0] != '\\0')\n\t\tunlink(recovery_file);\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n\tif (sqlzma_opts.try_lzma)\n\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tint uid = uids[i];\n\t\tstruct passwd *user = getpwuid(uid);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\nextern struct sqlzma_un un;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)buffer},\n\t\t\t{.buf = (void *)block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %d, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk->s_magic) {\n\t\tsquashfs_super_block sblk;\n\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\tbreak;\n\tcase SQUASHFS_MAGIC:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\n\tbad:\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Filesystem on %s is %d.%d, which is a later filesystem version than I support\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %llx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block = start; \n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tlong long sindex[indexes];\n\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_inode_t sinode;\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\n\t\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\twrite_file(&inode, entry->dir, &duplicate_file);\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t1\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n \t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n \t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/squashfs3.3/squashfs-tools/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n *  Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_1_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <unistd.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#include <stdlib.h>\n#include <time.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(char *pathname, unsigned int block_start, unsigned int offset);\n\tchar *(*read_fragment)(unsigned int fragment);\n\tvoid (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, char *block_ptr, int blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar symlink[65536];\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n};\n\t\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE, use_regex = FALSE;\nchar **created_inode;\nint root_process;\nstruct sqlzma_un un;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0} };\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\t/* printf(\"i%d \", inode->inode_number); */\n\n\tif((user = getpwuid(inode->uid)) == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tif((group = getgrgid(inode->gid)) == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0, inode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \", (int) inode->data >> 8, (int) inode->data & 0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)buffer},\n\t\t\t{.buf = (void *)block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)data, .sz = c_byte},\n\t\t\t{.buf = (void *)block, .sz = bytes}\n\t\t};\n\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid read_block_list(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nvoid read_block_list_1(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) | (SQUASHFS_COMPRESSED(block_size) ? 0 : SQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time, unsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%x, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_1()\n{\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nchar *read_fragment_2(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data;\nlong long hole;\n\nint write_block(int file_fd, char *buffer, int size)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(lseek_broken == FALSE && lseek(file_fd, off, SEEK_CUR) == -1) {\n\t\t\t/* failed to seek beyond end of file */\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t\tlseek_broken = TRUE;\n\t\t}\n\t\tif(lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size : hole;\n\t\t\t\tif(write(file_fd, zero_data, avail_bytes) < avail_bytes)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t\thole = 0;\n\t}\n\n\tif(write(file_fd, buffer, size) < size)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\t\nint write_file(long long file_size, char *pathname, unsigned int fragment, unsigned int frag_bytes,\nunsigned int offset, int blocks, long long start, char *block_ptr,\nunsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\tint file_end = file_size / block_size;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\thole = 0;\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\ts_ops.read_block_list(block_list, block_ptr, blocks);\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif(block_list[i] == 0) { /* sparse file */\n\t\t\thole += i == file_end ? file_size & (block_size - 1) : block_size;\n\t\t\tcontinue;\n\t\t}\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write_block(file_fd, file_data, bytes) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = s_ops.read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write_block(file_fd, fragment_data + offset, frag_bytes) == FALSE) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tif(hole) {\n\t\t/* corner case for hole extending to end of file */\n\t\tif(lseek(file_fd, hole, SEEK_CUR) == -1) {\n\t\t\t/* for broken lseeks which cannot seek beyond end of\n \t\t\t * file, write_block will do the right thing */\n\t\t\thole --;\n\t\t\tif(write_block(file_fd, \"\\0\", 1) == FALSE) {\n\t\t\t\tERROR(\"write_file: failed to write sparse data block\\n\");\n\t\t\t\tgoto failure;\n\t\t\t}\n\t\t} else if(ftruncate(file_fd, file_size) == -1) {\n\t\t\tERROR(\"write_file: failed to write sparse data block\\n\");\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\tfree(block_list);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\n\nstatic struct inode *read_inode(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i->data, pathname, i->fragment, i->frag_bytes,\n\t\t\t\t\ti->offset, i->blocks, i->start, i->block_ptr, i->mode)) {\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, force);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %lld\\n\", i->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%llx\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\tmakedev((i->data >> 8) & 0xff, i->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser! %s\\n\",\n\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", i->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_2 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[header.base.uid];\n    i.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_2!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_1 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode, sizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[(header.base.inode_type - 1) / SQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) % SQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n    i.gid = header.base.guid == 15 ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_1), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_1!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(char *pathname, unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tstruct inode *i;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + i->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(pathname, i);\n\n\tbytes += i->offset;\n\tsize = i->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = i->mode;\n\tdir->uid = i->uid;\n\tdir->guid = i->gid;\n\tdir->mtime = i->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(char *pathname, unsigned int block_start, unsigned int offset)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tstruct inode *i;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + i->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(pathname, i);\n\n\tbytes += i->offset;\n\tsize = i->data + bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = i->mode;\n\tdir->uid = i->uid;\n\tdir->guid = i->gid;\n\tdir->mtime = i->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\t*target ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing extract which subsumes the extract currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific extracts, delete as they're subsumed by this extract\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/* match on a leaf component, any subdirectories will\n\t\t\t\t * implicitly match, therefore return an empty new search set */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/* no matching names found, delete empty search set, and return\n        * FALSE */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches),\n     * return new search set and return TRUE */\n\treturn TRUE;\n\nempty_set:\n   /* found matching leaf exclude, return empty search set and return TRUE */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, struct pathnames *paths)\n{\n\tstruct dir *dir = s_ops.squashfs_opendir(parent_name, start_block, offset);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly)\n\t\t\t\tcreate_inode(pathname, i);\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str : \"failed to get time\\n\");\n\tprintf(\"Filesystem is %sexportable via NFS\\n\", SQUASHFS_EXPORTABLE(sBlk.flags) ? \"\" : \"not \");\n\n\tprintf(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tif(sBlk.s_major > 1 && !SQUASHFS_NO_FRAGMENTS(sBlk.flags))\n\t\tprintf(\"Fragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Check data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not \");\n\tif(sBlk.s_major > 1) {\n\t\tprintf(\"Fragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not \" : \"\");\n\t\tprintf(\"Always_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not \");\n\t} else\n\t\tprintf(\"Fragments are not supported by the filesystem\\n\");\n\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tprintf(\"Block size %d\\n\", sBlk.block_size);\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.fragments);\n\tprintf(\"Number of inodes %d\\n\", sBlk.inodes);\n\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tif(sBlk.s_major > 1)\n\t\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n}\n\n\nint read_super(char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tun.un_lzma = 1;\n\tswap = 0;\n\tswitch (sBlk.s_magic) {\n\t\tsquashfs_super_block sblk;\n\tcase SQUASHFS_MAGIC:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 1 || sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s_major == 1) {\n\t\t\tsBlk.block_size = sBlk.block_size_1;\n\t\t\tsBlk.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t} else {\n\t\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t}\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor <= 1) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.read_block_list = read_block_list;\n\t\ts_ops.read_inode = read_inode;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tif((fd = fopen(filename, \"r\")) == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename, strerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.5-CVS (2007/01/25)\\n\");\\\n\tprintf(\"copyright (C) 2007 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\\\n\tprintf(\"and LZMA support for slax.org by jro.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tint n;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\n\troot_process = geteuid() == 0;\n\tif(root_process)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 || strcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 || strcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 || strcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 || strcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 || strcmp(argv[i], \"-r\") == 0)\n\t\t\tuse_regex = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are unsquashed with file\\n\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file attributes (like\\n\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX regular expressions\\n\\t\\t\\t\\trather than use the default shell wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tblock_size = sBlk.block_size;\n\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tfputs(\"sqlzma_init failed\", stderr);\n\t\tabort();\n\t}\n\n\tread_uids_guids();\n\n\ts_ops.read_fragment_table();\n\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid SetStream(System.IO.Stream inStream);\r\n\t\tvoid Init();\r\n\t\tvoid ReleaseStream();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetMatches(UInt32[] distances);\r\n\t\tvoid Skip(UInt32 num);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize = 0;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\tUInt32[] _son;\r\n\t\tUInt32[] _hash;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\t\tUInt32 _hashMask;\r\n\t\tUInt32 _hashSizeSum = 0;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\r\n\t\tconst UInt32 kHash2Size = 1 << 10;\r\n\t\tconst UInt32 kHash3Size = 1 << 16;\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kStartMaxLen = 1;\r\n\t\tconst UInt32 kHash3Offset = kHash2Size;\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\t\r\n\t\tUInt32 kNumHashDirectBytes = 0;\r\n\t\tUInt32 kMinMatchCheck = 4;\r\n\t\tUInt32 kFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\r\n\t\tpublic void SetType(int numHashBytes)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\t\tkMinMatchCheck = 4;\r\n\t\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\t\tkFixHashSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic new void SetStream(System.IO.Stream stream) { base.SetStream(stream); }\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\t\t\r\n\t\tpublic new void Init()\r\n\t\t{\r\n\t\t\tbase.Init();\r\n\t\t\tfor (UInt32 i = 0; i < _hashSizeSum; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\t\tthrow new Exception();\r\n\t\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\t\t\t\t\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\tUInt32 cyclicBufferSize = historySize + 1;\r\n\t\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t\t_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\t\tUInt32 hs = kBT2HashSize;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\ths = historySize - 1;\r\n\t\t\t\ths |= (hs >> 1);\r\n\t\t\t\ths |= (hs >> 2);\r\n\t\t\t\ths |= (hs >> 4);\r\n\t\t\t\ths |= (hs >> 8);\r\n\t\t\t\ths >>= 1;\r\n\t\t\t\ths |= 0xFFFF;\r\n\t\t\t\tif (hs > (1 << 24))\r\n\t\t\t\t\ths >>= 1;\r\n\t\t\t\t_hashMask = hs;\r\n\t\t\t\ths++;\r\n\t\t\t\ths += kFixHashSize;\r\n\t\t\t}\r\n\t\t\tif (hs != _hashSizeSum)\r\n\t\t\t\t_hash = new UInt32[_hashSizeSum = hs];\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetMatches(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 offset = 0;\r\n\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\t\t\tUInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 curMatch2 = _hash[hash2Value];\r\n\t\t\t\tUInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t\t{\r\n\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\t\t\t\r\n\t\t\tif (kNumHashDirectBytes != 0)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\r\n\t\t\twhile(true)\r\n\t\t\t{\r\n\t\t\t\tif(curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (maxLen < len)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t\treturn offset;\r\n\t\t}\r\n\r\n\t\tpublic void Skip(UInt32 num)\r\n\t\t{\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenLimit;\r\n\t\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tMovePos();\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\t\tUInt32 hashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\t\tUInt32 hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\t\tUInt32 hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\t\tUInt32 len0, len1;\r\n\t\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\t\tlen1 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\t\tlen0 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tMovePos();\r\n\t\t\t}\r\n\t\t\twhile (--num != 0);\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 subValue = _pos - _cyclicBufferSize;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize; // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos; // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos\r\n\t\tpublic UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\t\tif (offset > 0)\r\n\t\t\t\toffset--;\r\n\t\t\t\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { _stream = stream; }\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic uint TrainSize = 0;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t\tTrainSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tlong len = stream.Length;\r\n\t\t\tuint size = (len < _windowSize) ? (uint)len : _windowSize;\r\n\t\t\tTrainSize = size;\r\n\t\t\tstream.Position = len - size;\r\n\t\t\t_streamPos = _pos = 0;\r\n\t\t\twhile (size > 0)\r\n\t\t\t{\r\n\t\t\t\tuint curSize = _windowSize - _pos;\r\n\t\t\t\tif (size < curSize)\r\n\t\t\t\t\tcurSize = size;\r\n\t\t\t\tint numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tsize -= (uint)numReadBytes;\r\n\t\t\t\t_pos += (uint)numReadBytes;\r\n\t\t\t\t_streamPos += (uint)numReadBytes;\r\n\t\t\t\tif (_pos == _windowSize)\r\n\t\t\t\t\t_streamPos = _pos = 0;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t\tpublic bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\t// public const int kDicLogSizeMax = 30;\r\n\t\t// public const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tbool _solid = false;\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream, _solid);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t_solid = true;\r\n\t\t\treturn m_OutWindow.Train(stream);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get { return 0; }}\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t};\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1 << 11];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 22;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 11))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 21))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 10] + 20);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 20] + 40);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 17))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 27))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 16] + 32);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 26] + 52);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 22;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32[] prices, UInt32 st)\r\n\t\t\t{\r\n\t\t\t\tUInt32 a0 = _choice.GetPrice0();\r\n\t\t\t\tUInt32 a1 = _choice.GetPrice1();\r\n\t\t\t\tUInt32 b0 = a1 + _choice2.GetPrice0();\r\n\t\t\t\tUInt32 b1 = a1 + _choice2.GetPrice1();\r\n\t\t\t\tUInt32 i = 0;\r\n\t\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\tLZ.IMatchFinder _matchFinder = null;\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates];\r\n\t\t\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];\r\n\t\t\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _numDistancePairs;\r\n\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\t\tSystem.IO.Stream _inStream;\r\n\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark = false;\r\n\t\t\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tif (_matchFinderType == EMatchFinderType.BT2)\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs)\r\n\t\t{\r\n\t\t\tlenRes = 0;\r\n\t\t\tnumDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\t\tif (numDistancePairs > 0)\r\n\t\t\t{\r\n\t\t\t\tlenRes = _matchDistances[numDistancePairs - 2];\r\n\t\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t}\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tif (num > 0)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Skip(num);\r\n\t\t\t\t_additionalOffset += num;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t\t}\r\n\t\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\t\tUInt32 lenMain, numDistancePairs;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain, out numDistancePairs);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\t\t\t\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = (UInt32)0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\t\tif(lenEnd < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\t\tUInt32 len = lenEnd;\r\n\t\t\tdo\r\n\t\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\t\twhile (len >= 2);\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tif (repLen < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tUInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--repLen >= 2);\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\t\t\t\r\n\t\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\t\tif (len <= lenMain)\r\n\t\t\t{\r\n\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\tfor (; ; len++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 distance = _matchDistances[offs + 1];\r\n\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen, out numDistancePairs);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_numDistancePairs = numDistancePairs;\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t\t{\r\n\t\t\t\t\t// try Literal + rep0\r\n\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 startLen = 2; // speed optimization \r\n\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t\t// if (_maxMode)\r\n\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, reps[repIndex], t);\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)(reps[repIndex] + 1))), \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t\t}\r\n\t\t\t\tif (newLen >= startLen)\r\n\t\t\t\t{\r\n\t\t\t\t\tnormalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = startLen; ; lenTest++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t);\r\n\t\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)(curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t\t_matchFinder.Init();\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t\tif (_trainSize > 0)\r\n\t\t\t\t\t_matchFinder.Skip(_trainSize);\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len, numDistancePairs; // it's not used\r\n\t\t\t\tReadMatchDistances(out len, out numDistancePairs);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 len = GetOptimum((UInt32)nowPos64, out pos);\r\n\t\t\t\t\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t// if (!_fastMode)\r\n\t\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// if (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\t\t\r\n\t\tUInt32[] tempPrices = new UInt32[Base.kNumFullDistances];\r\n\t\tUInt32 _matchPriceCount;\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t\t{ \r\n\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, \r\n\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tRangeCoder.BitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\t\t\t\r\n\t\t\t\tUInt32 st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\t\tUInt32 st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t\t}\r\n\t\t\t_matchPriceCount = 0;\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = 0;\r\n\t\t}\r\n\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t/*\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t*/\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 30;\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _trainSize = 0;\r\n\t\tpublic void SetTrainSize(uint trainSize)\r\n\t\t{\r\n\t\t\t_trainSize = trainSize;\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\t\r\n\tpublic class CDoubleStream: Stream\r\n\t{\r\n\t\tpublic System.IO.Stream s1;\r\n\t\tpublic System.IO.Stream s2;\r\n\t\tpublic int fileIndex;\r\n\t\tpublic long skipSize;\r\n\t\t\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return false; }}\r\n\t\tpublic override bool CanSeek { get { return false; }}\r\n\t\tpublic override long Length { get { return s1.Length + s2.Length - skipSize; } }\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\tint numTotal = 0;\r\n\t\t\twhile (count > 0)\r\n\t\t\t{\r\n\t\t\t\tif (fileIndex == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tint num = s1.Read(buffer, offset, count);\r\n\t\t\t\t\toffset += num;\r\n\t\t\t\t\tcount -= num;\r\n\t\t\t\t\tnumTotal += num;\r\n\t\t\t\t\tif (num == 0)\r\n\t\t\t\t\t\tfileIndex++;\r\n\t\t\t\t}\r\n\t\t\t\tif (fileIndex == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tnumTotal += s2.Read(buffer, offset, count);\r\n\t\t\t\t\treturn numTotal;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn numTotal;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Write\"));\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Seek\"));\r\n\t\t}\r\n\t\tpublic override void SetLength(long value)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't SetLength\"));\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut,\r\n\t\t\tTrain\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0, 29], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.49 Copyright (c) 1999-2007 Igor Pavlov  2006-07-05\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[13];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"T\", SwitchType.UnLimitedPostString, false, 1);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary);\r\n\t\t\t}\r\n\r\n\t\t\tstring train = \"\";\r\n\t\t\tif (parser[(int)Key.Train].ThereIs)\r\n\t\t\t\ttrain = (string)parser[(int)Key.Train].PostStrings[0];\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream trainStream = null;\r\n\t\t\tif (train.Length != 0)\r\n\t\t\t\ttrainStream = new FileStream(train, FileMode.Open, FileAccess.Read);\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tCDoubleStream doubleStream = new CDoubleStream();\r\n\t\t\t\t\tdoubleStream.s1 = trainStream;\r\n\t\t\t\t\tdoubleStream.s2 = inStream;\r\n\t\t\t\t\tdoubleStream.fileIndex = 0;\r\n\t\t\t\t\tinStream = doubleStream;\r\n\t\t\t\t\tlong trainFileSize = trainStream.Length;\r\n\t\t\t\t\tdoubleStream.skipSize = 0;\r\n\t\t\t\t\tif (trainFileSize > dictionary)\r\n\t\t\t\t\t\tdoubleStream.skipSize = trainFileSize - dictionary;\r\n\t\t\t\t\ttrainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);\r\n\t\t\t\t\tencoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));\r\n\t\t\t\t}\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!decoder.Train(trainStream))\r\n\t\t\t\t\t\tthrow (new Exception(\"can't train\"));\r\n\t\t\t\t}\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.50727</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tUInt32 Rep0;\r\n\t\t\t\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\t\tUInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\tRG.Init();\r\n\t\t\t\tRep0 = 1;\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)RG.GetRnd(8);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 len;\r\n\t\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\t\tUInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 220 + outSize * 20;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 18))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "// LZ.BinTree\r\n\r\npackage SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\r\n\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize = 0;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\tint[] _hash;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\tint _hashMask;\r\n\tint _hashSizeSum = 0;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\r\n\tstatic final int kHash2Size = 1 << 10;\r\n\tstatic final int kHash3Size = 1 << 16;\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kStartMaxLen = 1;\r\n\tstatic final int kHash3Offset = kHash2Size;\r\n\tstatic final int kEmptyHashValue = 0;\r\n\tstatic final int kMaxValForNormalize = (1 << 30) - 1;\r\n\t\r\n\tint kNumHashDirectBytes = 0;\r\n\tint kMinMatchCheck = 4;\r\n\tint kFixHashSize = kHash2Size + kHash3Size;\r\n\r\n\tpublic void SetType(int numHashBytes)\r\n\t{\r\n\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\tkMinMatchCheck = 4;\r\n\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\tkFixHashSize = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tfor (int i = 0; i < _hashSizeSum; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\treturn false;\r\n\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\tint cyclicBufferSize = historySize + 1;\r\n\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t_son = new int[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\tint hs = kBT2HashSize;\r\n\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\ths = historySize - 1;\r\n\t\t\ths |= (hs >> 1);\r\n\t\t\ths |= (hs >> 2);\r\n\t\t\ths |= (hs >> 4);\r\n\t\t\ths |= (hs >> 8);\r\n\t\t\ths >>= 1;\r\n\t\t\ths |= 0xFFFF;\r\n\t\t\tif (hs > (1 << 24))\r\n\t\t\t\ths >>= 1;\r\n\t\t\t_hashMask = hs;\r\n\t\t\ths++;\r\n\t\t\ths += kFixHashSize;\r\n\t\t}\r\n\t\tif (hs != _hashSizeSum)\r\n\t\t\t_hash = new int [_hashSizeSum = hs];\r\n\t\treturn true;\r\n\t}\r\n\tpublic int GetMatches(int[] distances) throws IOException\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t{\r\n\t\t\t\tMovePos();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint offset = 0;\r\n\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\tint maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint curMatch2 = _hash[hash2Value];\r\n\t\t\tint curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t}\r\n\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t}\r\n\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t{\r\n\t\t\t\toffset -= 2;\r\n\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\tint len0, len1;\r\n\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\tif (kNumHashDirectBytes != 0)\r\n\t\t{\r\n\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint count = _cutValue;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint len = Math.min(len0, len1);\r\n\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t{\r\n\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tif (maxLen < len)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t{\r\n\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\tlen1 = len;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\tlen0 = len;\r\n\t\t\t}\r\n\t\t}\r\n\t\tMovePos();\r\n\t\treturn offset;\r\n\t}\r\n\r\n\tpublic void Skip(int num) throws IOException\r\n\t{\r\n\t\tdo\r\n\t\t{\r\n\t\t\tint lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tint cur = _bufferOffset + _pos;\r\n\t\t\t\r\n\t\t\tint hashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\t\tint hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\t\tint hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tint len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\tint count = _cutValue;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tint len = Math.min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t}\r\n\t\twhile (--num != 0);\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint subValue = _pos - _cyclicBufferSize;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue) { _cutValue = cutValue; }\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\tif (offset > 0)\r\n\t\t\toffset--;\r\n\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free() { _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream) { _stream = stream; \t}\r\n\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\t// public static final int kDicLogSizeMax = 28;\r\n\t// public static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\r\n\r\n\r\n\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\r\n\tstatic byte[] g_FastPos = new byte[1 << 11];\r\n\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 22;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 11))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 21))\r\n\t\t\treturn (g_FastPos[pos >> 10] + 20);\r\n\t\treturn (g_FastPos[pos >> 20] + 40);\r\n\t}\r\n\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 17))\r\n\t\t\treturn (g_FastPos[pos >> 6] + 12);\r\n\t\tif (pos < (1 << 27))\r\n\t\t\treturn (g_FastPos[pos >> 16] + 32);\r\n\t\treturn (g_FastPos[pos >> 26] + 52);\r\n\t}\r\n\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\r\n\tstatic final int kDefaultDictionaryLogSize = 22;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\r\n\t\t\tpublic void Init() { SevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders); }\r\n\r\n\r\n\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetPrices(int posState, int numSymbols, int[] prices, int st)\r\n\t\t{\r\n\t\t\tint a0 = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\tint a1 = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\tint b0 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\tint b1 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\tint i = 0;\r\n\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t}\r\n\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t}\r\n\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t}\r\n\t};\r\n\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols<<Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\tpublic void SetTableSize(int tableSize) { _tableSize = tableSize; }\r\n\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t}\r\n\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\r\n\tstatic final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;\r\n\t\tpublic int BackPrev;\r\n\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\r\n\t\tpublic void MakeAsChar() { BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep() { return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null;\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\r\n\tshort[] _isMatch = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances-Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen*2+2];\r\n\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _numDistancePairs;\r\n\r\n\tint _additionalOffset;\r\n\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\r\n\tboolean _longestMatchWasFound;\r\n\r\n\tint[] _posSlotPrices = new int[1<<(Base.kNumPosSlotBits+Base.kNumLenToPosStatesBits)];\r\n\tint[] _distancesPrices = new int[Base.kNumFullDistances<<Base.kNumLenToPosStatesBits];\r\n\tint[] _alignPrices = new int[Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\tjava.io.InputStream _inStream;\r\n\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\r\n\tboolean _needReleaseMFStream = false;\r\n\r\n\tvoid Create()\r\n\t{\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tif (_matchFinderType == EMatchFinderTypeBT2)\r\n\t\t\t\tnumHashBytes = 2;\r\n\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\r\n\tvoid SetWriteEndMarkerMode(boolean writeEndMarker)\r\n\t{\r\n\t\t_writeEndMark = writeEndMarker;\r\n\t}\r\n\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\r\n\r\n\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n\t\t_posAlignEncoder.Init();\r\n\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = 0;\r\n\t\t_numDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\tif (_numDistancePairs > 0)\r\n\t\t{\r\n\t\t\tlenRes = _matchDistances[_numDistancePairs - 2];\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[_numDistancePairs - 1],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t}\r\n\t\t_additionalOffset++;\r\n\t\treturn lenRes;\r\n\t}\r\n\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tif (num > 0)\r\n\t\t{\r\n\t\t\t_matchFinder.Skip(num);\r\n\t\t\t_additionalOffset += num;\r\n\t\t}\r\n\t}\r\n\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\r\n\tint GetPureRepPrice(int repIndex, int state, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t}\r\n\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\r\n\tint Backward(int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\tint backRes;\r\n\r\n\tint GetOptimum(int position) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\tint lenMain, numDistancePairs;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tnumDistancePairs = _numDistancePairs;\r\n\r\n\t\tint numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\tif (numAvailableBytes < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\tbyte matchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[0].State = _state;\r\n\r\n\t\tint posState = (position & _posStateMask);\r\n\r\n\t\t_optimum[1].Price = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\tif (lenEnd < 2)\r\n\t\t{\r\n\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\tint len = lenEnd;\r\n\t\tdo\r\n\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\twhile (len >= 2);\r\n\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tif (repLen < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tint price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twhile (--repLen >= 2);\r\n\t\t}\r\n\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\r\n\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\tif (len <= lenMain)\r\n\t\t{\r\n\t\t\tint offs = 0;\r\n\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\toffs += 2;\r\n\t\t\tfor (; ; len++)\r\n\t\t\t{\r\n\t\t\t\tint distance = _matchDistances[offs + 1];\r\n\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t{\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint cur = 0;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\r\n\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t{\r\n\t\t\t\t// try Literal + rep0\r\n\t\t\t\tint t = Math.min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint startLen = 2; // speed optimization \r\n\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\tint lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t// if (_maxMode)\r\n\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t{\r\n\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, reps[repIndex], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - (reps[repIndex] + 1)),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t{\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t}\r\n\t\t\tif (newLen >= startLen)\r\n\t\t\t{\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\tint offs = 0;\r\n\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\tfor (int lenTest = startLen; ; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, curBack, t);\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\r\n\t\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - (curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\r\n\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\r\n\t\t\tint len = GetOptimum((int)nowPos64);\r\n\t\t\tint pos = backRes;\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\t// if (!_fastMode)\r\n\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\r\n\t\t// if (!_fastMode)\r\n\t\t{\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\r\n\tlong[] processedInSize = new long[1]; long[] processedOutSize = new long[1]; boolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\r\n\r\n\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\r\n\tint[] tempPrices = new int[Base.kNumFullDistances];\r\n\tint _matchPriceCount;\r\n\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t{\r\n\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t}\r\n\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tBitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\r\n\t\t\tint st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\tint st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t}\r\n\t\t_matchPriceCount = 0;\r\n\t}\r\n\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = 0;\r\n\t}\r\n\r\n\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\t/*\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\t*/\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = 29;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++) ;\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SeNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.42 Copyright (c) 1999-2006 Igor Pavlov  2006-05-15\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SeNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.3-lzma/unuse/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator() { Init(); }\r\n\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tint Rep0;\r\n\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\r\n\t\tpublic CBenchRandomGenerator() { }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit() { return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\tint GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\tRG.Init();\r\n\t\t\tRep0 = 1;\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint len;\r\n\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, long elapsedTime, long size)\r\n\t{\r\n\t\tlong t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\tlong numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime, long outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 220 + outSize * 20;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 18))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 18 (256 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/Makefile",
    "content": "SQDIR=squashfs-tools\n\nall:\n\tmake -C $(SQDIR)\n\tcp $(SQDIR)/unsquashfs .\n\tcp $(SQDIR)/mksquashfs .\n\nclean:\n\tmake -C $(SQDIR) clean\n\trm -f unsquashfs mksquashfs\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/7zC.txt",
    "content": "7z ANSI-C Decoder 4.62\r\n----------------------\r\n\r\n7z ANSI-C provides 7z/LZMA decoding.\r\n7z ANSI-C version is simplified version ported from C++ code.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\n7z ANSI-C Decoder is part of the LZMA SDK.\r\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\r\n\r\nFiles\r\n---------------------\r\n\r\n7zDecode.*   - Low level 7z decoding\r\n7zExtract.*  - High level 7z decoding\r\n7zHeader.*   - .7z format constants\r\n7zIn.*       - .7z archive opening\r\n7zItem.*     - .7z structures\r\n7zMain.c     - Test application\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nYou must download 7-Zip program from www.7-zip.org.\r\n\r\nYou can create .7z archive with 7z.exe or 7za.exe:\r\n\r\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255\r\n\r\nIf you have big number of files in archive, and you need fast extracting, \r\nyou can use partly-solid archives:\r\n  \r\n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\r\n\r\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r\n512KB for extracting one file from such archive.\r\n\r\n\r\nLimitations of current version of 7z ANSI-C Decoder\r\n---------------------------------------------------\r\n\r\n - It reads only \"FileName\", \"Size\", \"LastWriteTime\" and \"CRC\" information for each file in archive.\r\n - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.\r\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r\n \r\nThese limitations will be fixed in future versions.\r\n\r\n\r\nUsing 7z ANSI-C Decoder Test application:\r\n-----------------------------------------\r\n\r\nUsage: 7zDec <command> <archive_name>\r\n\r\n<Command>:\r\n  e: Extract files from archive\r\n  l: List contents of archive\r\n  t: Test integrity of archive\r\n\r\nExample: \r\n\r\n  7zDec l archive.7z\r\n\r\nlists contents of archive.7z\r\n\r\n  7zDec e archive.7z\r\n\r\nextracts files from archive.7z to current folder.\r\n\r\n\r\nHow to use .7z Decoder\r\n----------------------\r\n\r\nMemory allocation\r\n~~~~~~~~~~~~~~~~~\r\n\r\n7z Decoder uses two memory pools:\r\n1) Temporary pool\r\n2) Main pool\r\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\r\n\r\n\r\nSteps for using 7z decoder\r\n--------------------------\r\n\r\nUse code at 7zMain.c as example.\r\n\r\n1) Declare variables:\r\n  inStream                 /* implements ILookInStream interface */\r\n  CSzArEx db;              /* 7z archive database structure */\r\n  ISzAlloc allocImp;       /* memory functions for main pool */\r\n  ISzAlloc allocTempImp;   /* memory functions for temporary pool */\r\n\r\n2) call CrcGenerateTable(); function to initialize CRC structures.\r\n\r\n3) call SzArEx_Init(&db); function to initialize db structures.\r\n\r\n4) call SzArEx_Open(&db, inStream, &allocMain, &allocTemp) to open archive\r\n\r\nThis function opens archive \"inStream\" and reads headers to \"db\".\r\nAll items in \"db\" will be allocated with \"allocMain\" functions.\r\nSzArEx_Open function allocates and frees temporary structures by \"allocTemp\" functions.\r\n\r\n5) List items or Extract items\r\n\r\n  Listing code:\r\n  ~~~~~~~~~~~~~\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.db.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n\r\n  Extracting code:\r\n  ~~~~~~~~~~~~~~~~\r\n\r\n  SZ_RESULT SzAr_Extract(\r\n    CArchiveDatabaseEx *db,\r\n    ILookInStream *inStream, \r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n  If you need to decompress more than one file, you can send these values from previous call:\r\n    blockIndex, \r\n    outBuffer, \r\n    outBufferSize,\r\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \r\n  it will increase decompression speed.\r\n\r\n  After decompressing you must free \"outBuffer\":\r\n  allocImp.Free(outBuffer);\r\n\r\n6) call SzArEx_Free(&db, allocImp.Free) to free allocated items in \"db\".\r\n\r\n\r\n\r\n\r\nMemory requirements for .7z decoding \r\n------------------------------------\r\n\r\nMemory usage for Archive opening:\r\n  - Temporary pool:\r\n     - Memory for uncompressed .7z headers\r\n     - some other temporary blocks\r\n  - Main pool:\r\n     - Memory for database: \r\n       Estimated size of one file structures in solid archive:\r\n         - Size (4 or 8 Bytes)\r\n         - CRC32 (4 bytes)\r\n         - LastWriteTime (8 bytes)\r\n         - Some file information (4 bytes)\r\n         - File Name (variable length) + pointer + allocation structures\r\n\r\nMemory usage for archive Decompressing:\r\n  - Temporary pool:\r\n     - Memory for LZMA decompressing structures\r\n  - Main pool:\r\n     - Memory for decompressed solid block\r\n     - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these \r\n       temprorary buffers can be about 15% of solid block size. \r\n  \r\n\r\n7z Decoder doesn't allocate memory for compressed blocks. \r\nInstead of this, you must allocate buffer with desired \r\nsize before calling 7z Decoder. Use 7zMain.c as example.\r\n\r\n\r\nDefines\r\n-------\r\n\r\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/sdk.html\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\r\n-----------------------------------\r\n\r\nThis file contains description of 7z archive format. \r\n7z archive can contain files compressed with any method.\r\nSee \"Methods.txt\" for description for defined compressing methods.\r\n\r\n\r\nFormat structure Overview\r\n-------------------------\r\n\r\nSome fields can be optional.\r\n\r\nArchive structure\r\n~~~~~~~~~~~~~~~~~  \r\nSignatureHeader\r\n[PackedStreams]\r\n[PackedStreamsForHeaders]\r\n[\r\n  Header \r\n  or \r\n  {\r\n    Packed Header\r\n    HeaderInfo\r\n  }\r\n]\r\n\r\n\r\n\r\nHeader structure\r\n~~~~~~~~~~~~~~~~  \r\n{\r\n  ArchiveProperties\r\n  AdditionalStreams\r\n  {\r\n    PackInfo\r\n    {\r\n      PackPos\r\n      NumPackStreams\r\n      Sizes[NumPackStreams]\r\n      CRCs[NumPackStreams]\r\n    }\r\n    CodersInfo\r\n    {\r\n      NumFolders\r\n      Folders[NumFolders]\r\n      {\r\n        NumCoders\r\n        CodersInfo[NumCoders]\r\n        {\r\n          ID\r\n          NumInStreams;\r\n          NumOutStreams;\r\n          PropertiesSize\r\n          Properties[PropertiesSize]\r\n        }\r\n        NumBindPairs\r\n        BindPairsInfo[NumBindPairs]\r\n        {\r\n          InIndex;\r\n          OutIndex;\r\n        }\r\n        PackedIndices\r\n      }\r\n      UnPackSize[Folders][Folders.NumOutstreams]\r\n      CRCs[NumFolders]\r\n    }\r\n    SubStreamsInfo\r\n    {\r\n      NumUnPackStreamsInFolders[NumFolders];\r\n      UnPackSizes[]\r\n      CRCs[]\r\n    }\r\n  }\r\n  MainStreamsInfo\r\n  {\r\n    (Same as in AdditionalStreams)\r\n  }\r\n  FilesInfo\r\n  {\r\n    NumFiles\r\n    Properties[]\r\n    {\r\n      ID\r\n      Size\r\n      Data\r\n    }\r\n  }\r\n}\r\n\r\nHeaderInfo structure\r\n~~~~~~~~~~~~~~~~~~~~\r\n{\r\n  (Same as in AdditionalStreams)\r\n}\r\n\r\n\r\n\r\nNotes about Notation and encoding\r\n---------------------------------\r\n\r\n7z uses little endian encoding.\r\n\r\n7z archive format has optional headers that are marked as\r\n[]\r\nHeader\r\n[]\r\n\r\nREAL_UINT64 means real UINT64.\r\n\r\nUINT64 means real UINT64 encoded with the following scheme:\r\n\r\n  Size of encoding sequence depends from first byte:\r\n  First_Byte  Extra_Bytes        Value\r\n  (binary)   \r\n  0xxxxxxx               : ( xxxxxxx           )\r\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r\n  ...\r\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r\n  11111110    BYTE y[7]  :                         y\r\n  11111111    BYTE y[8]  :                         y\r\n\r\n\r\n\r\nProperty IDs\r\n------------\r\n\r\n0x00 = kEnd,\r\n\r\n0x01 = kHeader,\r\n\r\n0x02 = kArchiveProperties,\r\n    \r\n0x03 = kAdditionalStreamsInfo,\r\n0x04 = kMainStreamsInfo,\r\n0x05 = kFilesInfo,\r\n    \r\n0x06 = kPackInfo,\r\n0x07 = kUnPackInfo,\r\n0x08 = kSubStreamsInfo,\r\n\r\n0x09 = kSize,\r\n0x0A = kCRC,\r\n\r\n0x0B = kFolder,\r\n\r\n0x0C = kCodersUnPackSize,\r\n0x0D = kNumUnPackStream,\r\n\r\n0x0E = kEmptyStream,\r\n0x0F = kEmptyFile,\r\n0x10 = kAnti,\r\n\r\n0x11 = kName,\r\n0x12 = kCreationTime,\r\n0x13 = kLastAccessTime,\r\n0x14 = kLastWriteTime,\r\n0x15 = kWinAttributes,\r\n0x16 = kComment,\r\n\r\n0x17 = kEncodedHeader,\r\n\r\n\r\n7z format headers\r\n-----------------\r\n\r\nSignatureHeader\r\n~~~~~~~~~~~~~~~\r\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n\r\n  ArchiveVersion\r\n  {\r\n    BYTE Major;   // now = 0\r\n    BYTE Minor;   // now = 2\r\n  };\r\n\r\n  UINT32 StartHeaderCRC;\r\n\r\n  StartHeader\r\n  {\r\n    REAL_UINT64 NextHeaderOffset\r\n    REAL_UINT64 NextHeaderSize\r\n    UINT32 NextHeaderCRC\r\n  }\r\n\r\n\r\n...........................\r\n\r\n\r\nArchiveProperties\r\n~~~~~~~~~~~~~~~~~\r\nBYTE NID::kArchiveProperties (0x02)\r\nfor (;;)\r\n{\r\n  BYTE PropertyType;\r\n  if (aType == 0)\r\n    break;\r\n  UINT64 PropertySize;\r\n  BYTE PropertyData[PropertySize];\r\n}\r\n\r\n\r\nDigests (NumStreams)\r\n~~~~~~~~~~~~~~~~~~~~~\r\n  BYTE AllAreDefined\r\n  if (AllAreDefined == 0)\r\n  {\r\n    for(NumStreams)\r\n      BIT Defined\r\n  }\r\n  UINT32 CRCs[NumDefined]\r\n\r\n\r\nPackInfo\r\n~~~~~~~~~~~~\r\n  BYTE NID::kPackInfo  (0x06)\r\n  UINT64 PackPos\r\n  UINT64 NumPackStreams\r\n\r\n  []\r\n  BYTE NID::kSize    (0x09)\r\n  UINT64 PackSizes[NumPackStreams]\r\n  []\r\n\r\n  []\r\n  BYTE NID::kCRC      (0x0A)\r\n  PackStreamDigests[NumPackStreams]\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFolder\r\n~~~~~~\r\n  UINT64 NumCoders;\r\n  for (NumCoders)\r\n  {\r\n    BYTE \r\n    {\r\n      0:3 DecompressionMethod.IDSize\r\n      4:\r\n        0 - IsSimple\r\n        1 - Is not simple\r\n      5:\r\n        0 - No Attributes\r\n        1 - There Are Attributes\r\n      7:\r\n        0 - Last Method in Alternative_Method_List\r\n        1 - There are more alternative methods\r\n    } \r\n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\r\n    if (!IsSimple)\r\n    {\r\n      UINT64 NumInStreams;\r\n      UINT64 NumOutStreams;\r\n    }\r\n    if (DecompressionMethod[0] != 0)\r\n    {\r\n      UINT64 PropertiesSize\r\n      BYTE Properties[PropertiesSize]\r\n    }\r\n  }\r\n    \r\n  NumBindPairs = NumOutStreamsTotal - 1;\r\n\r\n  for (NumBindPairs)\r\n  {\r\n    UINT64 InIndex;\r\n    UINT64 OutIndex;\r\n  }\r\n\r\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r\n  if (NumPackedStreams > 1)\r\n    for(NumPackedStreams)\r\n    {\r\n      UINT64 Index;\r\n    };\r\n\r\n\r\n\r\n\r\nCoders Info\r\n~~~~~~~~~~~\r\n\r\n  BYTE NID::kUnPackInfo  (0x07)\r\n\r\n\r\n  BYTE NID::kFolder  (0x0B)\r\n  UINT64 NumFolders\r\n  BYTE External\r\n  switch(External)\r\n  {\r\n    case 0:\r\n      Folders[NumFolders]\r\n    case 1:\r\n      UINT64 DataStreamIndex\r\n  }\r\n\r\n\r\n  BYTE ID::kCodersUnPackSize  (0x0C)\r\n  for(Folders)\r\n    for(Folder.NumOutStreams)\r\n     UINT64 UnPackSize;\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC   (0x0A)\r\n  UnPackDigests[NumFolders]\r\n  []\r\n\r\n  \r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\n\r\nSubStreams Info\r\n~~~~~~~~~~~~~~\r\n  BYTE NID::kSubStreamsInfo; (0x08)\r\n\r\n  []\r\n  BYTE NID::kNumUnPackStream; (0x0D)\r\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kSize  (0x09)\r\n  UINT64 UnPackSizes[]\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC  (0x0A)\r\n  Digests[Number of streams with unknown CRC]\r\n  []\r\n\r\n  \r\n  BYTE NID::kEnd\r\n\r\n\r\nStreams Info\r\n~~~~~~~~~~~~\r\n\r\n  []\r\n  PackInfo\r\n  []\r\n\r\n\r\n  []\r\n  CodersInfo\r\n  []\r\n\r\n\r\n  []\r\n  SubStreamsInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFilesInfo\r\n~~~~~~~~~\r\n  BYTE NID::kFilesInfo;  (0x05)\r\n  UINT64 NumFiles\r\n\r\n  for (;;)\r\n  {\r\n    BYTE PropertyType;\r\n    if (aType == 0)\r\n      break;\r\n\r\n    UINT64 Size;\r\n\r\n    switch(PropertyType)\r\n    {\r\n      kEmptyStream:   (0x0E)\r\n        for(NumFiles)\r\n          BIT IsEmptyStream\r\n\r\n      kEmptyFile:     (0x0F)\r\n        for(EmptyStreams)\r\n          BIT IsEmptyFile\r\n\r\n      kAnti:          (0x10)\r\n        for(EmptyStreams)\r\n          BIT IsAntiFile\r\n      \r\n      case kCreationTime:   (0x12)\r\n      case kLastAccessTime: (0x13)\r\n      case kLastWriteTime:  (0x14)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT TimeDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Items)\r\n          UINT32 Time\r\n        []\r\n      \r\n      kNames:     (0x11)\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Files)\r\n        {\r\n          wchar_t Names[NameSize];\r\n          wchar_t 0;\r\n        }\r\n        []\r\n\r\n      kAttributes:  (0x15)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT AttributesAreDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Attributes)\r\n          UINT32 Attributes\r\n        []\r\n    }\r\n  }\r\n\r\n\r\nHeader\r\n~~~~~~\r\n  BYTE NID::kHeader (0x01)\r\n\r\n  []\r\n  ArchiveProperties\r\n  []\r\n\r\n  []\r\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  BYTE NID::kMainStreamsInfo;    (0x04)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  FilesInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nHeaderInfo\r\n~~~~~~~~~~\r\n  []\r\n  BYTE NID::kEncodedHeader; (0x17)\r\n  StreamsInfo for Encoded Header\r\n  []\r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/7zBuf.c",
    "content": "/* 7zBuf.c -- Byte Buffer\r\n2008-03-28\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"7zBuf.h\"\r\n\r\nvoid Buf_Init(CBuf *p)\r\n{\r\n  p->data = 0;\r\n  p->size = 0;\r\n}\r\n\r\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)\r\n{\r\n  p->size = 0;\r\n  if (size == 0)\r\n  {\r\n    p->data = 0;\r\n    return 1;\r\n  }\r\n  p->data = (Byte *)alloc->Alloc(alloc, size);\r\n  if (p->data != 0)\r\n  {\r\n    p->size = size;\r\n    return 1;\r\n  }\r\n  return 0;\r\n}\r\n\r\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->data);\r\n  p->data = 0;\r\n  p->size = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/7zBuf.h",
    "content": "/* 7zBuf.h -- Byte Buffer\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_BUF_H\r\n#define __7Z_BUF_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct\r\n{\r\n  Byte *data;\r\n  size_t size;\r\n} CBuf;\r\n\r\nvoid Buf_Init(CBuf *p);\r\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);\r\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc);\r\n\r\ntypedef struct\r\n{\r\n  Byte *data;\r\n  size_t size;\r\n  size_t pos;\r\n} CDynBuf;\r\n\r\nvoid DynBuf_Construct(CDynBuf *p);\r\nvoid DynBuf_SeekToBeg(CDynBuf *p);\r\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);\r\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/7zBuf2.c",
    "content": "/* 7zBuf2.c -- Byte Buffer\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n#include \"7zBuf.h\"\r\n\r\nvoid DynBuf_Construct(CDynBuf *p)\r\n{\r\n  p->data = 0;\r\n  p->size = 0;\r\n  p->pos = 0;\r\n}\r\n\r\nvoid DynBuf_SeekToBeg(CDynBuf *p)\r\n{\r\n  p->pos = 0;\r\n}\r\n\r\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)\r\n{\r\n  if (size > p->size - p->pos)\r\n  {\r\n    size_t newSize = p->pos + size;\r\n    Byte *data;\r\n    newSize += newSize / 4;\r\n    data = (Byte *)alloc->Alloc(alloc, newSize);\r\n    if (data == 0)\r\n      return 0;\r\n    p->size = newSize;\r\n    memcpy(data, p->data, p->pos);\r\n    alloc->Free(alloc, p->data);\r\n    p->data = data;\r\n  }\r\n  memcpy(p->data + p->pos, buf, size);\r\n  p->pos += size;\r\n  return 1;\r\n}\r\n\r\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->data);\r\n  p->data = 0;\r\n  p->size = 0;\r\n  p->pos = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/7zCrc.c",
    "content": "/* 7zCrc.c -- CRC32 calculation\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = CRC_UPDATE_BYTE(v, *p);\r\n  return v;\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/7zCrc.h",
    "content": "/* 7zCrc.h -- CRC32 calculation\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"Types.h\"\r\n\r\nextern UInt32 g_CrcTable[];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void);\r\n\r\n#define CRC_INIT_VAL 0xFFFFFFFF\r\n#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)\r\n#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/7zFile.c",
    "content": "/* 7zFile.c -- File IO\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zFile.h\"\r\n\r\n#ifndef USE_WINDOWS_FILE\r\n\r\n#include <errno.h>\r\n\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FILE\r\n\r\n/*\r\n   ReadFile and WriteFile functions in Windows have BUG:\r\n   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r\n   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r\n   (Insufficient system resources exist to complete the requested service).\r\n   Probably in some version of Windows there are problems with other sizes:\r\n   for 32 MB (maybe also for 16 MB).\r\n   And message can be \"Network connection was lost\"\r\n*/\r\n\r\n#define kChunkSizeMax (1 << 22)\r\n\r\n#endif\r\n\r\nvoid File_Construct(CSzFile *p)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  p->handle = INVALID_HANDLE_VALUE;\r\n  #else\r\n  p->file = NULL;\r\n  #endif\r\n}\r\n\r\nstatic WRes File_Open(CSzFile *p, const char *name, int writeMode)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  p->handle = CreateFileA(name,\r\n      writeMode ? GENERIC_WRITE : GENERIC_READ,\r\n      FILE_SHARE_READ, NULL,\r\n      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\r\n      FILE_ATTRIBUTE_NORMAL, NULL);\r\n  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r\n  #else\r\n  p->file = fopen(name, writeMode ? \"wb+\" : \"rb\");\r\n  return (p->file != 0) ? 0 : errno;\r\n  #endif\r\n}\r\n\r\nWRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }\r\nWRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }\r\n\r\nWRes File_Close(CSzFile *p)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  if (p->handle != INVALID_HANDLE_VALUE)\r\n  {\r\n    if (!CloseHandle(p->handle))\r\n      return GetLastError();\r\n    p->handle = INVALID_HANDLE_VALUE;\r\n  }\r\n  #else\r\n  if (p->file != NULL)\r\n  {\r\n    int res = fclose(p->file);\r\n    if (res != 0)\r\n      return res;\r\n    p->file = NULL;\r\n  }\r\n  #endif\r\n  return 0;\r\n}\r\n\r\nWRes File_Read(CSzFile *p, void *data, size_t *size)\r\n{\r\n  size_t originalSize = *size;\r\n  if (originalSize == 0)\r\n    return 0;\r\n\r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  *size = 0;\r\n  do\r\n  {\r\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r\n    DWORD processed = 0;\r\n    BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);\r\n    data = (void *)((Byte *)data + processed);\r\n    originalSize -= processed;\r\n    *size += processed;\r\n    if (!res)\r\n      return GetLastError();\r\n    if (processed == 0)\r\n      break;\r\n  }\r\n  while (originalSize > 0);\r\n  return 0;\r\n\r\n  #else\r\n  \r\n  *size = fread(data, 1, originalSize, p->file);\r\n  if (*size == originalSize)\r\n    return 0;\r\n  return ferror(p->file);\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_Write(CSzFile *p, const void *data, size_t *size)\r\n{\r\n  size_t originalSize = *size;\r\n  if (originalSize == 0)\r\n    return 0;\r\n  \r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  *size = 0;\r\n  do\r\n  {\r\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r\n    DWORD processed = 0;\r\n    BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);\r\n    data = (void *)((Byte *)data + processed);\r\n    originalSize -= processed;\r\n    *size += processed;\r\n    if (!res)\r\n      return GetLastError();\r\n    if (processed == 0)\r\n      break;\r\n  }\r\n  while (originalSize > 0);\r\n  return 0;\r\n\r\n  #else\r\n\r\n  *size = fwrite(data, 1, originalSize, p->file);\r\n  if (*size == originalSize)\r\n    return 0;\r\n  return ferror(p->file);\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  LARGE_INTEGER value;\r\n  DWORD moveMethod;\r\n  value.LowPart = (DWORD)*pos;\r\n  value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */\r\n  switch (origin)\r\n  {\r\n    case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;\r\n    case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;\r\n    case SZ_SEEK_END: moveMethod = FILE_END; break;\r\n    default: return ERROR_INVALID_PARAMETER;\r\n  }\r\n  value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n  {\r\n    WRes res = GetLastError();\r\n    if (res != NO_ERROR)\r\n      return res;\r\n  }\r\n  *pos = ((Int64)value.HighPart << 32) | value.LowPart;\r\n  return 0;\r\n\r\n  #else\r\n  \r\n  int moveMethod;\r\n  int res;\r\n  switch (origin)\r\n  {\r\n    case SZ_SEEK_SET: moveMethod = SEEK_SET; break;\r\n    case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;\r\n    case SZ_SEEK_END: moveMethod = SEEK_END; break;\r\n    default: return 1;\r\n  }\r\n  res = fseek(p->file, (long)*pos, moveMethod);\r\n  *pos = ftell(p->file);\r\n  return res;\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_GetLength(CSzFile *p, UInt64 *length)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  \r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);\r\n  if (sizeLow == 0xFFFFFFFF)\r\n  {\r\n    DWORD res = GetLastError();\r\n    if (res != NO_ERROR)\r\n      return res;\r\n  }\r\n  *length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return 0;\r\n  \r\n  #else\r\n  \r\n  long pos = ftell(p->file);\r\n  int res = fseek(p->file, 0, SEEK_END);\r\n  *length = ftell(p->file);\r\n  fseek(p->file, pos, SEEK_SET);\r\n  return res;\r\n  \r\n  #endif\r\n}\r\n\r\n\r\n/* ---------- FileSeqInStream ---------- */\r\n\r\nstatic SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CFileSeqInStream *p = (CFileSeqInStream *)pp;\r\n  return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;\r\n}\r\n\r\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p)\r\n{\r\n  p->s.Read = FileSeqInStream_Read;\r\n}\r\n\r\n\r\n/* ---------- FileInStream ---------- */\r\n\r\nstatic SRes FileInStream_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CFileInStream *p = (CFileInStream *)pp;\r\n  return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;\r\n}\r\n\r\nstatic SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)\r\n{\r\n  CFileInStream *p = (CFileInStream *)pp;\r\n  return File_Seek(&p->file, pos, origin);\r\n}\r\n\r\nvoid FileInStream_CreateVTable(CFileInStream *p)\r\n{\r\n  p->s.Read = FileInStream_Read;\r\n  p->s.Seek = FileInStream_Seek;\r\n}\r\n\r\n\r\n/* ---------- FileOutStream ---------- */\r\n\r\nstatic size_t FileOutStream_Write(void *pp, const void *data, size_t size)\r\n{\r\n  CFileOutStream *p = (CFileOutStream *)pp;\r\n  File_Write(&p->file, data, &size);\r\n  return size;\r\n}\r\n\r\nvoid FileOutStream_CreateVTable(CFileOutStream *p)\r\n{\r\n  p->s.Write = FileOutStream_Write;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/7zFile.h",
    "content": "/* 7zFile.h -- File IO\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_FILE_H\r\n#define __7Z_FILE_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WINDOWS_FILE\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FILE\r\n#include <windows.h>\r\n#else\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"Types.h\"\r\n\r\n\r\n/* ---------- File ---------- */\r\n\r\ntypedef struct\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  HANDLE handle;\r\n  #else\r\n  FILE *file;\r\n  #endif\r\n} CSzFile;\r\n\r\nvoid File_Construct(CSzFile *p);\r\nWRes InFile_Open(CSzFile *p, const char *name);\r\nWRes OutFile_Open(CSzFile *p, const char *name);\r\nWRes File_Close(CSzFile *p);\r\n\r\n/* reads max(*size, remain file's size) bytes */\r\nWRes File_Read(CSzFile *p, void *data, size_t *size);\r\n\r\n/* writes *size bytes */\r\nWRes File_Write(CSzFile *p, const void *data, size_t *size);\r\n\r\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);\r\nWRes File_GetLength(CSzFile *p, UInt64 *length);\r\n\r\n\r\n/* ---------- FileInStream ---------- */\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  CSzFile file;\r\n} CFileSeqInStream;\r\n\r\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p);\r\n\r\n\r\ntypedef struct\r\n{\r\n  ISeekInStream s;\r\n  CSzFile file;\r\n} CFileInStream;\r\n\r\nvoid FileInStream_CreateVTable(CFileInStream *p);\r\n\r\n\r\ntypedef struct\r\n{\r\n  ISeqOutStream s;\r\n  CSzFile file;\r\n} CFileOutStream;\r\n\r\nvoid FileOutStream_CreateVTable(CFileOutStream *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/7zStream.c",
    "content": "/* 7zStream.c -- 7z Stream functions\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"Types.h\"\r\n\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)\r\n{\r\n  while (size != 0)\r\n  {\r\n    size_t processed = size;\r\n    RINOK(stream->Read(stream, buf, &processed));\r\n    if (processed == 0)\r\n      return errorType;\r\n    buf = (void *)((Byte *)buf + processed);\r\n    size -= processed;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)\r\n{\r\n  return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r\n}\r\n\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)\r\n{\r\n  size_t processed = 1;\r\n  RINOK(stream->Read(stream, buf, &processed));\r\n  return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;\r\n}\r\n\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)\r\n{\r\n  Int64 t = offset;\r\n  return stream->Seek(stream, &t, SZ_SEEK_SET);\r\n}\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)\r\n{\r\n  void *lookBuf;\r\n  if (*size == 0)\r\n    return SZ_OK;\r\n  RINOK(stream->Look(stream, &lookBuf, size));\r\n  memcpy(buf, lookBuf, *size);\r\n  return stream->Skip(stream, *size);\r\n}\r\n\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)\r\n{\r\n  while (size != 0)\r\n  {\r\n    size_t processed = size;\r\n    RINOK(stream->Read(stream, buf, &processed));\r\n    if (processed == 0)\r\n      return errorType;\r\n    buf = (void *)((Byte *)buf + processed);\r\n    size -= processed;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)\r\n{\r\n  return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r\n}\r\n\r\nstatic SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)\r\n{\r\n  SRes res = SZ_OK;\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t size2 = p->size - p->pos;\r\n  if (size2 == 0 && *size > 0)\r\n  {\r\n    p->pos = 0;\r\n    size2 = LookToRead_BUF_SIZE;\r\n    res = p->realStream->Read(p->realStream, p->buf, &size2);\r\n    p->size = size2;\r\n  }\r\n  if (size2 < *size)\r\n    *size = size2;\r\n  *buf = p->buf + p->pos;\r\n  return res;\r\n}\r\n\r\nstatic SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)\r\n{\r\n  SRes res = SZ_OK;\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t size2 = p->size - p->pos;\r\n  if (size2 == 0 && *size > 0)\r\n  {\r\n    p->pos = 0;\r\n    if (*size > LookToRead_BUF_SIZE)\r\n      *size = LookToRead_BUF_SIZE;\r\n    res = p->realStream->Read(p->realStream, p->buf, size);\r\n    size2 = p->size = *size;\r\n  }\r\n  if (size2 < *size)\r\n    *size = size2;\r\n  *buf = p->buf + p->pos;\r\n  return res;\r\n}\r\n\r\nstatic SRes LookToRead_Skip(void *pp, size_t offset)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  p->pos += offset;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LookToRead_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t rem = p->size - p->pos;\r\n  if (rem == 0)\r\n    return p->realStream->Read(p->realStream, buf, size);\r\n  if (rem > *size)\r\n    rem = *size;\r\n  memcpy(buf, p->buf + p->pos, rem);\r\n  p->pos += rem;\r\n  *size = rem;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  p->pos = p->size = 0;\r\n  return p->realStream->Seek(p->realStream, pos, origin);\r\n}\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead)\r\n{\r\n  p->s.Look = lookahead ?\r\n      LookToRead_Look_Lookahead :\r\n      LookToRead_Look_Exact;\r\n  p->s.Skip = LookToRead_Skip;\r\n  p->s.Read = LookToRead_Read;\r\n  p->s.Seek = LookToRead_Seek;\r\n}\r\n\r\nvoid LookToRead_Init(CLookToRead *p)\r\n{\r\n  p->pos = p->size = 0;\r\n}\r\n\r\nstatic SRes SecToLook_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CSecToLook *p = (CSecToLook *)pp;\r\n  return LookInStream_LookRead(p->realStream, buf, size);\r\n}\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p)\r\n{\r\n  p->s.Read = SecToLook_Read;\r\n}\r\n\r\nstatic SRes SecToRead_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CSecToRead *p = (CSecToRead *)pp;\r\n  return p->realStream->Read(p->realStream, buf, size);\r\n}\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p)\r\n{\r\n  p->s.Read = SecToRead_Read;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/7zVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 65\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.65\"\r\n#define MY_DATE \"2009-02-03\"\r\n#define MY_COPYRIGHT \": Igor Pavlov : Public domain\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \" \" MY_COPYRIGHT \" : \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Alloc.c",
    "content": "/* Alloc.c -- Memory allocation functions\r\n2008-09-24\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdlib.h>\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  {\r\n    void *p = malloc(size);\r\n    fprintf(stderr, \"\\nAlloc %10d bytes, count = %10d,  addr = %8X\", size, g_allocCount++, (unsigned)p);\r\n    return p;\r\n  }\r\n  #else\r\n  return malloc(size);\r\n  #endif\r\n}\r\n\r\nvoid MyFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d,  addr = %8X\", --g_allocCount, (unsigned)address);\r\n  #endif\r\n  free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#ifndef MEM_LARGE_PAGES\r\n#undef _7ZIP_LARGE_PAGES\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nSIZE_T g_LargePageSize = 0;\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n#endif\r\n\r\nvoid SetLargePageSize()\r\n{\r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  SIZE_T size = 0;\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        GetProcAddress(GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return;\r\n  size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return;\r\n  g_LargePageSize = size;\r\n  #endif\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))\r\n  {\r\n    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),\r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Alloc.h",
    "content": "/* Alloc.h -- Memory allocation functions\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size);\r\nvoid MyFree(void *address);\r\n\r\n#ifdef _WIN32\r\n\r\nvoid SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size);\r\nvoid MidFree(void *address);\r\nvoid *BigAlloc(size_t size);\r\nvoid BigFree(void *address);\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z.mak\" CFG=\"7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /FAs /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_SZ_ALLOC_DEBUG2\" /D \"_SZ_NO_INT_64_A\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z - Win32 Release\"\r\n# Name \"7z - Win32 Debug\"\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zBuf.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zBuf.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zFile.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zFile.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zStream.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bcj2.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bcj2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bra86.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z\"=.\\7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zAlloc.c",
    "content": "/* 7zAlloc.c -- Allocation functions\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n\r\n#endif\r\n\r\nvoid *SzAlloc(void *p, size_t size)\r\n{\r\n  p = p;\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *p, void *address)\r\n{\r\n  p = p;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(void *p, size_t size)\r\n{\r\n  p = p;\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *p, void *address)\r\n{\r\n  p = p;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zAlloc.h",
    "content": "/* 7zAlloc.h -- Allocation functions\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *SzAlloc(void *p, size_t size);\r\nvoid SzFree(void *p, void *address);\r\n\r\nvoid *SzAllocTemp(void *p, size_t size);\r\nvoid SzFreeTemp(void *p, void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zDecode.c",
    "content": "/* 7zDecode.c -- Decoding from 7z folder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"../../Bcj2.h\"\r\n#include \"../../Bra.h\"\r\n#include \"../../LzmaDec.h\"\r\n#include \"7zDecode.h\"\r\n\r\n#define k_Copy 0\r\n#define k_LZMA 0x30101\r\n#define k_BCJ 0x03030103\r\n#define k_BCJ2 0x0303011B\r\n\r\nstatic SRes SzDecodeLzma(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,\r\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)\r\n{\r\n  CLzmaDec state;\r\n  SRes res = SZ_OK;\r\n\r\n  LzmaDec_Construct(&state);\r\n  RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));\r\n  state.dic = outBuffer;\r\n  state.dicBufSize = outSize;\r\n  LzmaDec_Init(&state);\r\n\r\n  for (;;)\r\n  {\r\n    Byte *inBuf = NULL;\r\n    size_t lookahead = (1 << 18);\r\n    if (lookahead > inSize)\r\n      lookahead = (size_t)inSize;\r\n    res = inStream->Look((void *)inStream, (void **)&inBuf, &lookahead);\r\n    if (res != SZ_OK)\r\n      break;\r\n\r\n    {\r\n      SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;\r\n      ELzmaStatus status;\r\n      res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);\r\n      lookahead -= inProcessed;\r\n      inSize -= inProcessed;\r\n      if (res != SZ_OK)\r\n        break;\r\n      if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))\r\n      {\r\n        if (state.dicBufSize != outSize || lookahead != 0 ||\r\n            (status != LZMA_STATUS_FINISHED_WITH_MARK &&\r\n             status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))\r\n          res = SZ_ERROR_DATA;\r\n        break;\r\n      }\r\n      res = inStream->Skip((void *)inStream, inProcessed);\r\n      if (res != SZ_OK)\r\n        break;\r\n    }\r\n  }\r\n\r\n  LzmaDec_FreeProbs(&state, allocMain);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)\r\n{\r\n  while (inSize > 0)\r\n  {\r\n    void *inBuf;\r\n    size_t curSize = (1 << 18);\r\n    if (curSize > inSize)\r\n      curSize = (size_t)inSize;\r\n    RINOK(inStream->Look((void *)inStream, (void **)&inBuf, &curSize));\r\n    if (curSize == 0)\r\n      return SZ_ERROR_INPUT_EOF;\r\n    memcpy(outBuffer, inBuf, curSize);\r\n    outBuffer += curSize;\r\n    inSize -= curSize;\r\n    RINOK(inStream->Skip((void *)inStream, curSize));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)\r\n#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)\r\n\r\nSRes CheckSupportedFolder(const CSzFolder *f)\r\n{\r\n  if (f->NumCoders < 1 || f->NumCoders > 4)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (IS_UNSUPPORTED_CODER(f->Coders[0]))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (f->NumCoders == 1)\r\n  {\r\n    if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 2)\r\n  {\r\n    if (IS_NO_BCJ(f->Coders[1]) ||\r\n        f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||\r\n        f->NumBindPairs != 1 ||\r\n        f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 4)\r\n  {\r\n    if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||\r\n        IS_UNSUPPORTED_CODER(f->Coders[2]) ||\r\n        IS_NO_BCJ2(f->Coders[3]))\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    if (f->NumPackStreams != 4 ||\r\n        f->PackStreams[0] != 2 ||\r\n        f->PackStreams[1] != 6 ||\r\n        f->PackStreams[2] != 1 ||\r\n        f->PackStreams[3] != 0 ||\r\n        f->NumBindPairs != 3 ||\r\n        f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||\r\n        f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||\r\n        f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  return SZ_ERROR_UNSUPPORTED;\r\n}\r\n\r\nUInt64 GetSum(const UInt64 *values, UInt32 index)\r\n{\r\n  UInt64 sum = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < index; i++)\r\n    sum += values[i];\r\n  return sum;\r\n}\r\n\r\nSRes SzDecode2(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *inStream, UInt64 startPos,\r\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,\r\n    Byte *tempBuf[])\r\n{\r\n  UInt32 ci;\r\n  SizeT tempSizes[3] = { 0, 0, 0};\r\n  SizeT tempSize3 = 0;\r\n  Byte *tempBuf3 = 0;\r\n\r\n  RINOK(CheckSupportedFolder(folder));\r\n\r\n  for (ci = 0; ci < folder->NumCoders; ci++)\r\n  {\r\n    CSzCoderInfo *coder = &folder->Coders[ci];\r\n\r\n    if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)\r\n    {\r\n      UInt32 si = 0;\r\n      UInt64 offset;\r\n      UInt64 inSize;\r\n      Byte *outBufCur = outBuffer;\r\n      SizeT outSizeCur = outSize;\r\n      if (folder->NumCoders == 4)\r\n      {\r\n        UInt32 indices[] = { 3, 2, 0 };\r\n        UInt64 unpackSize = folder->UnpackSizes[ci];\r\n        si = indices[ci];\r\n        if (ci < 2)\r\n        {\r\n          Byte *temp;\r\n          outSizeCur = (SizeT)unpackSize;\r\n          if (outSizeCur != unpackSize)\r\n            return SZ_ERROR_MEM;\r\n          temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);\r\n          if (temp == 0 && outSizeCur != 0)\r\n            return SZ_ERROR_MEM;\r\n          outBufCur = tempBuf[1 - ci] = temp;\r\n          tempSizes[1 - ci] = outSizeCur;\r\n        }\r\n        else if (ci == 2)\r\n        {\r\n          if (unpackSize > outSize) /* check it */\r\n            return SZ_ERROR_PARAM;\r\n          tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);\r\n          tempSize3 = outSizeCur = (SizeT)unpackSize;\r\n        }\r\n        else\r\n          return SZ_ERROR_UNSUPPORTED;\r\n      }\r\n      offset = GetSum(packSizes, si);\r\n      inSize = packSizes[si];\r\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r\n\r\n      if (coder->MethodID == k_Copy)\r\n      {\r\n        if (inSize != outSizeCur) /* check it */\r\n          return SZ_ERROR_DATA;\r\n        RINOK(SzDecodeCopy(inSize, inStream, outBufCur));\r\n      }\r\n      else\r\n      {\r\n        RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));\r\n      }\r\n    }\r\n    else if (coder->MethodID == k_BCJ)\r\n    {\r\n      UInt32 state;\r\n      if (ci != 1)\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      x86_Convert_Init(state);\r\n      x86_Convert(outBuffer, outSize, 0, &state, 0);\r\n    }\r\n    else if (coder->MethodID == k_BCJ2)\r\n    {\r\n      UInt64 offset = GetSum(packSizes, 1);\r\n      UInt64 s3Size = packSizes[1];\r\n      SRes res;\r\n      if (ci != 3)\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r\n      tempSizes[2] = (SizeT)s3Size;\r\n      if (tempSizes[2] != s3Size)\r\n        return SZ_ERROR_MEM;\r\n      tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);\r\n      if (tempBuf[2] == 0 && tempSizes[2] != 0)\r\n        return SZ_ERROR_MEM;\r\n      res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);\r\n      RINOK(res)\r\n\r\n      res = Bcj2_Decode(\r\n          tempBuf3, tempSize3,\r\n          tempBuf[0], tempSizes[0],\r\n          tempBuf[1], tempSizes[1],\r\n          tempBuf[2], tempSizes[2],\r\n          outBuffer, outSize);\r\n      RINOK(res)\r\n    }\r\n    else\r\n      return SZ_ERROR_UNSUPPORTED;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *inStream, UInt64 startPos,\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  Byte *tempBuf[3] = { 0, 0, 0};\r\n  int i;\r\n  SRes res = SzDecode2(packSizes, folder, inStream, startPos,\r\n      outBuffer, (SizeT)outSize, allocMain, tempBuf);\r\n  for (i = 0; i < 3; i++)\r\n    IAlloc_Free(allocMain, tempBuf[i]);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zDecode.h",
    "content": "/* 7zDecode.h -- Decoding from 7z folder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n\r\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *stream, UInt64 startPos,\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zExtract.c",
    "content": "/* 7zExtract.c -- Extracting from 7z archive\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"7zDecode.h\"\r\n#include \"7zExtract.h\"\r\n\r\nSRes SzAr_Extract(\r\n    const CSzArEx *p,\r\n    ILookInStream *inStream,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer,\r\n    size_t *outBufferSize,\r\n    size_t *offset,\r\n    size_t *outSizeProcessed,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = p->FileIndexToFolderIndexMap[fileIndex];\r\n  SRes res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    IAlloc_Free(allocMain, *outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CSzFolder *folder = p->db.Folders + folderIndex;\r\n    UInt64 unpackSizeSpec = SzFolder_GetUnpackSize(folder);\r\n    size_t unpackSize = (size_t)unpackSizeSpec;\r\n    UInt64 startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);\r\n\r\n    if (unpackSize != unpackSizeSpec)\r\n      return SZ_ERROR_MEM;\r\n    *blockIndex = folderIndex;\r\n    IAlloc_Free(allocMain, *outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(LookInStream_SeekTo(inStream, startOffset));\r\n    \r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = unpackSize;\r\n      if (unpackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unpackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZ_ERROR_MEM;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        res = SzDecode(p->db.PackSizes +\r\n          p->FolderStartPackStreamIndex[folderIndex], folder,\r\n          inStream, startOffset,\r\n          *outBuffer, unpackSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (folder->UnpackCRCDefined)\r\n          {\r\n            if (CrcCalc(*outBuffer, unpackSize) != folder->UnpackCRC)\r\n              res = SZ_ERROR_CRC;\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i;\r\n    CSzFileItem *fileItem = p->db.Files + fileIndex;\r\n    *offset = 0;\r\n    for (i = p->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)p->db.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZ_ERROR_FAIL;\r\n    {\r\n      if (fileItem->FileCRCDefined)\r\n      {\r\n        if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)\r\n          res = SZ_ERROR_CRC;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zExtract.h",
    "content": "/* 7zExtract.h -- Extracting from 7z archive\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive.\r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send\r\n    these values from previous call:\r\n      *blockIndex,\r\n      *outBuffer,\r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid,\r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables\r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSRes SzAr_Extract(\r\n    const CSzArEx *db,\r\n    ILookInStream *inStream,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zHeader.c",
    "content": "/*  7zHeader.c -- 7z Headers\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zHeader.h",
    "content": "/* 7zHeader.h -- 7z Headers\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnpackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnpackSize,\r\n  k7zIdNumUnpackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCTime,\r\n  k7zIdATime,\r\n  k7zIdMTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos,\r\n  k7zIdDummy\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zIn.c",
    "content": "/* 7zIn.c -- 7z Input functions\r\n2008-12-31 : Igor Pavlov : Public domain */\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"../../CpuArch.h\"\r\n\r\n#include \"7zDecode.h\"\r\n#include \"7zIn.h\"\r\n\r\n#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }\r\n\r\n#define NUM_FOLDER_CODERS_MAX 32\r\n#define NUM_CODER_STREAMS_MAX 32\r\n\r\nvoid SzArEx_Init(CSzArEx *p)\r\n{\r\n  SzAr_Init(&p->db);\r\n  p->FolderStartPackStreamIndex = 0;\r\n  p->PackStreamStartPositions = 0;\r\n  p->FolderStartFileIndex = 0;\r\n  p->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)\r\n{\r\n  IAlloc_Free(alloc, p->FolderStartPackStreamIndex);\r\n  IAlloc_Free(alloc, p->PackStreamStartPositions);\r\n  IAlloc_Free(alloc, p->FolderStartFileIndex);\r\n  IAlloc_Free(alloc, p->FileIndexToFolderIndexMap);\r\n  SzAr_Free(&p->db, alloc);\r\n  SzArEx_Init(p);\r\n}\r\n\r\n/*\r\nUInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nUInt64 GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CSzFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n#define MY_ALLOC(T, p, size, alloc) { if ((size) == 0) p = 0; else \\\r\n  if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == 0) return SZ_ERROR_MEM; }\r\n\r\nstatic SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 startPos = 0;\r\n  UInt64 startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  MY_ALLOC(UInt32, p->FolderStartPackStreamIndex, p->db.NumFolders, alloc);\r\n  for (i = 0; i < p->db.NumFolders; i++)\r\n  {\r\n    p->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += p->db.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  MY_ALLOC(UInt64, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);\r\n\r\n  for (i = 0; i < p->db.NumPackStreams; i++)\r\n  {\r\n    p->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += p->db.PackSizes[i];\r\n  }\r\n\r\n  MY_ALLOC(UInt32, p->FolderStartFileIndex, p->db.NumFolders, alloc);\r\n  MY_ALLOC(UInt32, p->FileIndexToFolderIndexMap, p->db.NumFiles, alloc);\r\n\r\n  for (i = 0; i < p->db.NumFiles; i++)\r\n  {\r\n    CSzFileItem *file = p->db.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      p->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= p->db.NumFolders)\r\n          return SZ_ERROR_ARCHIVE;\r\n        p->FolderStartFileIndex[folderIndex] = i;\r\n        if (p->db.Folders[folderIndex].NumUnpackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    p->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= p->db.Folders[folderIndex].NumUnpackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return p->dataPos +\r\n    p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize)\r\n{\r\n  UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];\r\n  CSzFolder *folder = p->db.Folders + folderIndex;\r\n  UInt64 size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n  {\r\n    UInt64 t = size + p->db.PackSizes[packStreamIndex + i];\r\n    if (t < size) /* check it */\r\n      return SZ_ERROR_FAIL;\r\n    size = t;\r\n  }\r\n  *resSize = size;\r\n  return SZ_OK;\r\n}\r\n\r\n\r\n/*\r\nSRes SzReadTime(const CObjectVector<CBuf> &dataVector,\r\n    CObjectVector<CSzFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for (int i = 0; i < files.Size(); i++)\r\n  {\r\n    CSzFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCTime: file.IsCTimeDefined = defined; if (defined) file.CTime = fileTime; break;\r\n      case k7zIdATime: file.IsATimeDefined = defined; if (defined) file.ATime = fileTime; break;\r\n      case k7zIdMTime: file.IsMTimeDefined = defined; if (defined) file.MTime = fileTime; break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nstatic int TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nstatic SRes SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZ_ERROR_ARCHIVE;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadID(CSzData *sd, UInt64 *value)\r\n{\r\n  return SzReadNumber(sd, value);\r\n}\r\n\r\nstatic SRes SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZ_ERROR_ARCHIVE;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nstatic SRes SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZ_ERROR_ARCHIVE;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nstatic SRes SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  MY_ALLOC(Byte, *v, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, alloc);\r\n  MY_ALLOC(Byte, *v, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadHashDigests(\r\n    CSzData *sd,\r\n    size_t numItems,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *alloc)\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, alloc));\r\n  MY_ALLOC(UInt32, *digests, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadPackInfo(\r\n    CSzData *sd,\r\n    UInt64 *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    UInt64 **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadNumber(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  MY_ALLOC(UInt64, *packSizes, (size_t)*numPackStreams, alloc);\r\n\r\n  for (i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadNumber(sd, (*packSizes) + i));\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, alloc);\r\n    MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, alloc);\r\n    for (i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZ_ERROR_UNSUPPORTED;\r\n}\r\n\r\nstatic SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)\r\n{\r\n  UInt32 numCoders, numBindPairs, numPackStreams, i;\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  if (numCoders > NUM_FOLDER_CODERS_MAX)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  folder->NumCoders = numCoders;\r\n  \r\n  MY_ALLOC(CSzCoderInfo, folder->Coders, (size_t)numCoders, alloc);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfo_Init(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CSzCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      unsigned idSize, j;\r\n      Byte longID[15];\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      idSize = (unsigned)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, longID, idSize));\r\n      if (idSize > sizeof(coder->MethodID))\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      coder->MethodID = 0;\r\n      for (j = 0; j < idSize; j++)\r\n        coder->MethodID |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n        if (coder->NumInStreams > NUM_CODER_STREAMS_MAX ||\r\n            coder->NumOutStreams > NUM_CODER_STREAMS_MAX)\r\n          return SZ_ERROR_UNSUPPORTED;\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!Buf_Create(&coder->Props, (size_t)propertiesSize, alloc))\r\n          return SZ_ERROR_MEM;\r\n        RINOK(SzReadBytes(sd, coder->Props.data, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += coder->NumInStreams;\r\n    numOutStreams += coder->NumOutStreams;\r\n  }\r\n\r\n  if (numOutStreams == 0)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  folder->NumBindPairs = numBindPairs = numOutStreams - 1;\r\n  MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, alloc);\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bp = folder->BindPairs + i;\r\n    RINOK(SzReadNumber32(sd, &bp->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bp->OutIndex));\r\n  }\r\n\r\n  if (numInStreams < numBindPairs)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  folder->NumPackStreams = numPackStreams = numInStreams - numBindPairs;\r\n  MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackStreams, alloc);\r\n\r\n  if (numPackStreams == 1)\r\n  {\r\n    for (i = 0; i < numInStreams ; i++)\r\n      if (SzFolder_FindBindPairForInStream(folder, i) < 0)\r\n        break;\r\n    if (i == numInStreams)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    folder->PackStreams[0] = i;\r\n  }\r\n  else\r\n    for (i = 0; i < numPackStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadUnpackInfo(\r\n    CSzData *sd,\r\n    UInt32 *numFolders,\r\n    CSzFolder **folders,  /* for alloc */\r\n    ISzAlloc *alloc,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n    MY_ALLOC(CSzFolder, *folders, (size_t)*numFolders, alloc);\r\n\r\n    for (i = 0; i < *numFolders; i++)\r\n      SzFolder_Init((*folders) + i);\r\n\r\n    for (i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, alloc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnpackSize));\r\n\r\n  for (i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CSzFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);\r\n\r\n    MY_ALLOC(UInt64, folder->UnpackSizes, (size_t)numOutStreams, alloc);\r\n\r\n    for (j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadNumber(sd, folder->UnpackSizes + j));\r\n    }\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SRes res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < *numFolders; i++)\r\n        {\r\n          CSzFolder *folder = (*folders) + i;\r\n          folder->UnpackCRCDefined = crcsDefined[i];\r\n          folder->UnpackCRC = crcs[i];\r\n        }\r\n      }\r\n      IAlloc_Free(allocTemp, crcs);\r\n      IAlloc_Free(allocTemp, crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nstatic SRes SzReadSubStreamsInfo(\r\n    CSzData *sd,\r\n    UInt32 numFolders,\r\n    CSzFolder *folders,\r\n    UInt32 *numUnpackStreams,\r\n    UInt64 **unpackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n    folders[i].NumUnpackStreams = 1;\r\n  *numUnpackStreams = numFolders;\r\n\r\n  for (;;)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnpackStream)\r\n    {\r\n      *numUnpackStreams = 0;\r\n      for (i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnpackStreams = numStreams;\r\n        *numUnpackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnpackStreams == 0)\r\n  {\r\n    *unpackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unpackSizes = (UInt64 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt64));\r\n    RINOM(*unpackSizes);\r\n    *digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    UInt64 sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      UInt64 size;\r\n      RINOK(SzReadNumber(sd, &size));\r\n      (*unpackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unpackSizes)[si++] = SzFolder_GetUnpackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for (i = 0; i < *numUnpackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  for (;;)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0;\r\n      UInt32 *digests2 = 0;\r\n      SRes res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CSzFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnpackStreams;\r\n          if (numSubstreams == 1 && folder->UnpackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnpackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      IAlloc_Free(allocTemp, digestsDefined2);\r\n      IAlloc_Free(allocTemp, digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nstatic SRes SzReadStreamsInfo(\r\n    CSzData *sd,\r\n    UInt64 *dataOffset,\r\n    CSzAr *p,\r\n    UInt32 *numUnpackStreams,\r\n    UInt64 **unpackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    ISzAlloc *alloc,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,\r\n            &p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc));\r\n        break;\r\n      }\r\n      case k7zIdUnpackInfo:\r\n      {\r\n        RINOK(SzReadUnpackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,\r\n            numUnpackStreams, unpackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZ_ERROR_UNSUPPORTED;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nstatic SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CSzFileItem *file = files + i;\r\n    while (pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZ_ERROR_ARCHIVE;\r\n        if (pos + 2 > sd->Size)\r\n          return SZ_ERROR_ARCHIVE;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZ_ERROR_ARCHIVE;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    MY_ALLOC(char, file->Name, (size_t)len, alloc);\r\n\r\n    len = 0;\r\n    while (2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while (numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadHeader2(\r\n    CSzArEx *p,   /* allocMain */\r\n    CSzData *sd,\r\n    UInt64 **unpackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    Byte **lwtVector,         /* allocTemp */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnpackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CSzFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &p->dataPos,\r\n        &p->db,\r\n        &numUnpackStreams,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests, allocMain, allocTemp));\r\n    p->dataPos += p->startPosAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZ_ERROR_ARCHIVE;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  p->db.NumFiles = numFiles;\r\n\r\n  MY_ALLOC(CSzFileItem, files, (size_t)numFiles, allocMain);\r\n\r\n  p->db.Files = files;\r\n  for (i = 0; i < numFiles; i++)\r\n    SzFile_Init(files + i);\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdMTime:\r\n      {\r\n        RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));\r\n        RINOK(SzReadSwitch(sd));\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CSzFileItem *f = &files[i];\r\n          Byte defined = (*lwtVector)[i];\r\n          f->MTimeDefined = defined;\r\n          f->MTime.Low = f->MTime.High = 0;\r\n          if (defined)\r\n          {\r\n            RINOK(SzReadUInt32(sd, &f->MTime.Low));\r\n            RINOK(SzReadUInt32(sd, &f->MTime.High));\r\n          }\r\n        }\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      CSzFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if (file->HasStream)\r\n      {\r\n        file->IsDir = 0;\r\n        file->Size = (*unpackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->FileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDir = 1;\r\n        else\r\n          file->IsDir = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->FileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArEx_Fill(p, allocMain);\r\n}\r\n\r\nstatic SRes SzReadHeader(\r\n    CSzArEx *p,\r\n    CSzData *sd,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 *unpackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  Byte *lwtVector = 0;\r\n  SRes res = SzReadHeader2(p, sd,\r\n      &unpackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector, &lwtVector,\r\n      allocMain, allocTemp);\r\n  IAlloc_Free(allocTemp, unpackSizes);\r\n  IAlloc_Free(allocTemp, digestsDefined);\r\n  IAlloc_Free(allocTemp, digests);\r\n  IAlloc_Free(allocTemp, emptyStreamVector);\r\n  IAlloc_Free(allocTemp, emptyFileVector);\r\n  IAlloc_Free(allocTemp, lwtVector);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzReadAndDecodePackedStreams2(\r\n    ILookInStream *inStream,\r\n    CSzData *sd,\r\n    CBuf *outBuffer,\r\n    UInt64 baseOffset,\r\n    CSzAr *p,\r\n    UInt64 **unpackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnpackStreams = 0;\r\n  UInt64 dataStartPos;\r\n  CSzFolder *folder;\r\n  UInt64 unpackSize;\r\n  SRes res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,\r\n      &numUnpackStreams,  unpackSizes, digestsDefined, digests,\r\n      allocTemp, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (p->NumFolders != 1)\r\n    return SZ_ERROR_ARCHIVE;\r\n\r\n  folder = p->Folders;\r\n  unpackSize = SzFolder_GetUnpackSize(folder);\r\n  \r\n  RINOK(LookInStream_SeekTo(inStream, dataStartPos));\r\n\r\n  if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))\r\n    return SZ_ERROR_MEM;\r\n  \r\n  res = SzDecode(p->PackSizes, folder,\r\n          inStream, dataStartPos,\r\n          outBuffer->data, (size_t)unpackSize, allocTemp);\r\n  RINOK(res);\r\n  if (folder->UnpackCRCDefined)\r\n    if (CrcCalc(outBuffer->data, (size_t)unpackSize) != folder->UnpackCRC)\r\n      return SZ_ERROR_CRC;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadAndDecodePackedStreams(\r\n    ILookInStream *inStream,\r\n    CSzData *sd,\r\n    CBuf *outBuffer,\r\n    UInt64 baseOffset,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  CSzAr p;\r\n  UInt64 *unpackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  SRes res;\r\n  SzAr_Init(&p);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,\r\n    &p, &unpackSizes, &digestsDefined, &digests,\r\n    allocTemp);\r\n  SzAr_Free(&p, allocTemp);\r\n  IAlloc_Free(allocTemp, unpackSizes);\r\n  IAlloc_Free(allocTemp, digestsDefined);\r\n  IAlloc_Free(allocTemp, digests);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzArEx_Open2(\r\n    CSzArEx *p,\r\n    ILookInStream *inStream,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte header[k7zStartHeaderSize];\r\n  UInt64 nextHeaderOffset, nextHeaderSize;\r\n  size_t nextHeaderSizeT;\r\n  UInt32 nextHeaderCRC;\r\n  CBuf buffer;\r\n  SRes res;\r\n\r\n  RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));\r\n\r\n  if (!TestSignatureCandidate(header))\r\n    return SZ_ERROR_NO_ARCHIVE;\r\n  if (header[6] != k7zMajorVersion)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  nextHeaderOffset = GetUi64(header + 12);\r\n  nextHeaderSize = GetUi64(header + 20);\r\n  nextHeaderCRC = GetUi32(header + 28);\r\n\r\n  p->startPosAfterHeader = k7zStartHeaderSize;\r\n  \r\n  if (CrcCalc(header + 12, 20) != GetUi32(header + 8))\r\n    return SZ_ERROR_CRC;\r\n\r\n  nextHeaderSizeT = (size_t)nextHeaderSize;\r\n  if (nextHeaderSizeT != nextHeaderSize)\r\n    return SZ_ERROR_MEM;\r\n  if (nextHeaderSizeT == 0)\r\n    return SZ_OK;\r\n  if (nextHeaderOffset > nextHeaderOffset + nextHeaderSize ||\r\n      nextHeaderOffset > nextHeaderOffset + nextHeaderSize + k7zStartHeaderSize)\r\n    return SZ_ERROR_NO_ARCHIVE;\r\n\r\n  {\r\n    Int64 pos = 0;\r\n    RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));\r\n    if ((UInt64)pos < nextHeaderOffset ||\r\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset ||\r\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)\r\n      return SZ_ERROR_INPUT_EOF;\r\n  }\r\n\r\n  RINOK(LookInStream_SeekTo(inStream, k7zStartHeaderSize + nextHeaderOffset));\r\n\r\n  if (!Buf_Create(&buffer, nextHeaderSizeT, allocTemp))\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LookInStream_Read(inStream, buffer.data, nextHeaderSizeT);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = SZ_ERROR_ARCHIVE;\r\n    if (CrcCalc(buffer.data, nextHeaderSizeT) == nextHeaderCRC)\r\n    {\r\n      CSzData sd;\r\n      UInt64 type;\r\n      sd.Data = buffer.data;\r\n      sd.Size = buffer.size;\r\n      res = SzReadID(&sd, &type);\r\n      if (res == SZ_OK)\r\n      {\r\n        if (type == k7zIdEncodedHeader)\r\n        {\r\n          CBuf outBuffer;\r\n          Buf_Init(&outBuffer);\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, p->startPosAfterHeader, allocTemp);\r\n          if (res != SZ_OK)\r\n            Buf_Free(&outBuffer, allocTemp);\r\n          else\r\n          {\r\n            Buf_Free(&buffer, allocTemp);\r\n            buffer.data = outBuffer.data;\r\n            buffer.size = outBuffer.size;\r\n            sd.Data = buffer.data;\r\n            sd.Size = buffer.size;\r\n            res = SzReadID(&sd, &type);\r\n          }\r\n        }\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        if (type == k7zIdHeader)\r\n          res = SzReadHeader(p, &sd, allocMain, allocTemp);\r\n        else\r\n          res = SZ_ERROR_UNSUPPORTED;\r\n      }\r\n    }\r\n  }\r\n  Buf_Free(&buffer, allocTemp);\r\n  return res;\r\n}\r\n\r\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)\r\n{\r\n  SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArEx_Free(p, allocMain);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zIn.h",
    "content": "/* 7zIn.h -- 7z Input functions\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n\r\ntypedef struct\r\n{\r\n  CSzAr db;\r\n  \r\n  UInt64 startPosAfterHeader;\r\n  UInt64 dataPos;\r\n\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  UInt64 *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n} CSzArEx;\r\n\r\nvoid SzArEx_Init(CSzArEx *p);\r\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);\r\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);\r\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);\r\n\r\n/*\r\nErrors:\r\nSZ_ERROR_NO_ARCHIVE\r\nSZ_ERROR_ARCHIVE\r\nSZ_ERROR_UNSUPPORTED\r\nSZ_ERROR_MEM\r\nSZ_ERROR_CRC\r\nSZ_ERROR_INPUT_EOF\r\nSZ_ERROR_FAIL\r\n*/\r\n\r\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zItem.c",
    "content": "/* 7zItem.c -- 7z Items\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zItem.h\"\r\n\r\nvoid SzCoderInfo_Init(CSzCoderInfo *p)\r\n{\r\n  Buf_Init(&p->Props);\r\n}\r\n\r\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc)\r\n{\r\n  Buf_Free(&p->Props, alloc);\r\n  SzCoderInfo_Init(p);\r\n}\r\n\r\nvoid SzFolder_Init(CSzFolder *p)\r\n{\r\n  p->Coders = 0;\r\n  p->BindPairs = 0;\r\n  p->PackStreams = 0;\r\n  p->UnpackSizes = 0;\r\n  p->NumCoders = 0;\r\n  p->NumBindPairs = 0;\r\n  p->NumPackStreams = 0;\r\n  p->UnpackCRCDefined = 0;\r\n  p->UnpackCRC = 0;\r\n  p->NumUnpackStreams = 0;\r\n}\r\n\r\nvoid SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  if (p->Coders)\r\n    for (i = 0; i < p->NumCoders; i++)\r\n      SzCoderInfo_Free(&p->Coders[i], alloc);\r\n  IAlloc_Free(alloc, p->Coders);\r\n  IAlloc_Free(alloc, p->BindPairs);\r\n  IAlloc_Free(alloc, p->PackStreams);\r\n  IAlloc_Free(alloc, p->UnpackSizes);\r\n  SzFolder_Init(p);\r\n}\r\n\r\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumCoders; i++)\r\n    result += p->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumBindPairs; i++)\r\n    if (p->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumBindPairs; i++)\r\n    if (p->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p)\r\n{\r\n  int i = (int)SzFolder_GetNumOutStreams(p);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolder_FindBindPairForOutStream(p, i) < 0)\r\n      return p->UnpackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\nvoid SzFile_Init(CSzFileItem *p)\r\n{\r\n  p->HasStream = 1;\r\n  p->IsDir = 0;\r\n  p->IsAnti = 0;\r\n  p->FileCRCDefined = 0;\r\n  p->MTimeDefined = 0;\r\n  p->Name = 0;\r\n}\r\n\r\nstatic void SzFile_Free(CSzFileItem *p, ISzAlloc *alloc)\r\n{\r\n  IAlloc_Free(alloc, p->Name);\r\n  SzFile_Init(p);\r\n}\r\n\r\nvoid SzAr_Init(CSzAr *p)\r\n{\r\n  p->PackSizes = 0;\r\n  p->PackCRCsDefined = 0;\r\n  p->PackCRCs = 0;\r\n  p->Folders = 0;\r\n  p->Files = 0;\r\n  p->NumPackStreams = 0;\r\n  p->NumFolders = 0;\r\n  p->NumFiles = 0;\r\n}\r\n\r\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  if (p->Folders)\r\n    for (i = 0; i < p->NumFolders; i++)\r\n      SzFolder_Free(&p->Folders[i], alloc);\r\n  if (p->Files)\r\n    for (i = 0; i < p->NumFiles; i++)\r\n      SzFile_Free(&p->Files[i], alloc);\r\n  IAlloc_Free(alloc, p->PackSizes);\r\n  IAlloc_Free(alloc, p->PackCRCsDefined);\r\n  IAlloc_Free(alloc, p->PackCRCs);\r\n  IAlloc_Free(alloc, p->Folders);\r\n  IAlloc_Free(alloc, p->Files);\r\n  SzAr_Init(p);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zItem.h",
    "content": "/* 7zItem.h -- 7z Items\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../7zBuf.h\"\r\n\r\ntypedef struct\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  UInt64 MethodID;\r\n  CBuf Props;\r\n} CSzCoderInfo;\r\n\r\nvoid SzCoderInfo_Init(CSzCoderInfo *p);\r\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc);\r\n\r\ntypedef struct\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n} CBindPair;\r\n\r\ntypedef struct\r\n{\r\n  CSzCoderInfo *Coders;\r\n  CBindPair *BindPairs;\r\n  UInt32 *PackStreams;\r\n  UInt64 *UnpackSizes;\r\n  UInt32 NumCoders;\r\n  UInt32 NumBindPairs;\r\n  UInt32 NumPackStreams;\r\n  int UnpackCRCDefined;\r\n  UInt32 UnpackCRC;\r\n\r\n  UInt32 NumUnpackStreams;\r\n} CSzFolder;\r\n\r\nvoid SzFolder_Init(CSzFolder *p);\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);\r\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p);\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r\n\r\ntypedef struct\r\n{\r\n  UInt32 Low;\r\n  UInt32 High;\r\n} CNtfsFileTime;\r\n\r\ntypedef struct\r\n{\r\n  CNtfsFileTime MTime;\r\n  UInt64 Size;\r\n  char *Name;\r\n  UInt32 FileCRC;\r\n\r\n  Byte HasStream;\r\n  Byte IsDir;\r\n  Byte IsAnti;\r\n  Byte FileCRCDefined;\r\n  Byte MTimeDefined;\r\n} CSzFileItem;\r\n\r\nvoid SzFile_Init(CSzFileItem *p);\r\n\r\ntypedef struct\r\n{\r\n  UInt64 *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  CSzFolder *Folders;\r\n  CSzFileItem *Files;\r\n  UInt32 NumPackStreams;\r\n  UInt32 NumFolders;\r\n  UInt32 NumFiles;\r\n} CSzAr;\r\n\r\nvoid SzAr_Init(CSzAr *p);\r\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/7zMain.c",
    "content": "/* 7zMain.c - Test application for 7z Decoder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <stdlib.h>\r\n#include <stdio.h>\r\n#include <string.h>\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"../../7zFile.h\"\r\n#include \"../../7zVersion.h\"\r\n\r\n#include \"7zAlloc.h\"\r\n#include \"7zExtract.h\"\r\n#include \"7zIn.h\"\r\n\r\nstatic void ConvertNumberToString(UInt64 value, char *s)\r\n{\r\n  char temp[32];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (char)('0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\n#define PERIOD_4 (4 * 365 + 1)\r\n#define PERIOD_100 (PERIOD_4 * 25 - 1)\r\n#define PERIOD_400 (PERIOD_100 * 4 + 1)\r\n\r\nstatic void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)\r\n{\r\n  unsigned year, mon, day, hour, min, sec;\r\n  UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  unsigned temp;\r\n  UInt32 v;\r\n  v64 /= 10000000;\r\n  sec = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  min = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  hour = (unsigned)(v64 % 24);\r\n  v64 /= 24;\r\n\r\n  v = (UInt32)v64;\r\n\r\n  year = (unsigned)(1601 + v / PERIOD_400 * 400);\r\n  v %= PERIOD_400;\r\n\r\n  temp = (unsigned)(v / PERIOD_100);\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp * 100;\r\n  v -= temp * PERIOD_100;\r\n\r\n  temp = v / PERIOD_4;\r\n  if (temp == 25)\r\n    temp = 24;\r\n  year += temp * 4;\r\n  v -= temp * PERIOD_4;\r\n\r\n  temp = v / 365;\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp;\r\n  v -= temp * 365;\r\n\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  for (mon = 1; mon <= 12; mon++)\r\n  {\r\n    unsigned s = ms[mon - 1];\r\n    if (v < s)\r\n      break;\r\n    v -= s;\r\n  }\r\n  day = (unsigned)v + 1;\r\n  sprintf(s, \"%04d-%02d-%02d %02d:%02d:%02d\", year, mon, day, hour, min, sec);\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint MY_CDECL main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CLookToRead lookStream;\r\n  CSzArEx db;\r\n  SRes res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  if (InFile_Open(&archiveStream.file, args[2]))\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  \r\n  FileInStream_CreateVTable(&archiveStream);\r\n  LookToRead_CreateVTable(&lookStream, False);\r\n  \r\n  lookStream.realStream = &archiveStream.s;\r\n  LookToRead_Init(&lookStream);\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  CrcGenerateTable();\r\n\r\n  SzArEx_Init(&db);\r\n  res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0, testCommand = 0, extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0) listCommand = 1;\r\n    else if (strcmp(command, \"t\") == 0) testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0) extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        CSzFileItem *f = db.db.Files + i;\r\n        char s[32], t[32];\r\n        ConvertNumberToString(f->Size, s);\r\n        if (f->MTimeDefined)\r\n          ConvertFileTimeToString(&f->MTime, t);\r\n        else\r\n          strcpy(t, \"                   \");\r\n\r\n        printf(\"%s %10s  %s\\n\", t, s, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      /*\r\n      if you need cache, use these 3 variables.\r\n      if you use external function, you can make these variable as static.\r\n      */\r\n      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r\n      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r\n      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CSzFileItem *f = db.db.Files + i;\r\n        if (f->IsDir)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ?\r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDir)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzAr_Extract(&db, &lookStream.s, i,\r\n            &blockIndex, &outBuffer, &outBufferSize,\r\n            &offset, &outSizeProcessed,\r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          CSzFile outFile;\r\n          size_t processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          if (OutFile_Open(&outFile, fileName))\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n          processedSize = outSizeProcessed;\r\n          if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 ||\r\n              processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n          if (File_Close(&outFile))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      IAlloc_Free(&allocImp, outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZ_ERROR_FAIL;\r\n    }\r\n  }\r\n  SzArEx_Free(&db, &allocImp);\r\n\r\n  File_Close(&archiveStream.file);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == SZ_ERROR_UNSUPPORTED)\r\n    PrintError(\"decoder doesn't support this archive\");\r\n  else if (res == SZ_ERROR_MEM)\r\n    PrintError(\"can not allocate memory\");\r\n  else if (res == SZ_ERROR_CRC)\r\n    PrintError(\"CRC error\");\r\n  else\r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/makefile",
    "content": "MY_STATIC_LINK=1\r\n\r\nPROG = 7zDec.exe\r\n\r\nC_OBJS = \\\r\n  $O\\7zBuf.obj \\\r\n  $O\\7zBuf2.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\Bcj2.obj \\\r\n  $O\\7zFile.obj \\\r\n  $O\\7zStream.obj \\\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $(C_OBJS) \\\r\n\r\n!include \"../../../CPP/Build.mak\"\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL_O1)\r\n$(C_OBJS): ../../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Archive/7z/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB =\r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = 7zAlloc.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o 7zFile.o 7zStream.o\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuf.o: ../../7zBuf.c\r\n\t$(CXX) $(CFLAGS) ../../7zBuf.c\r\n\r\n7zBuf2.o: ../../7zBuf2.c\r\n\t$(CXX) $(CFLAGS) ../../7zBuf2.c\r\n\r\n7zCrc.o: ../../7zCrc.c\r\n\t$(CXX) $(CFLAGS) ../../7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\nLzmaDec.o: ../../LzmaDec.c\r\n\t$(CXX) $(CFLAGS) ../../LzmaDec.c\r\n\r\nBra86.o: ../../Bra86.c\r\n\t$(CXX) $(CFLAGS) ../../Bra86.c\r\n\r\nBcj2.o: ../../Bcj2.c\r\n\t$(CXX) $(CFLAGS) ../../Bcj2.c\r\n\r\n7zFile.o: ../../7zFile.c\r\n\t$(CXX) $(CFLAGS) ../../7zFile.c\r\n\r\n7zStream.o: ../../7zStream.c\r\n\t$(CXX) $(CFLAGS) ../../7zStream.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Bcj2.c",
    "content": "/* Bcj2.c -- Converter for x86 code (BCJ2)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bcj2.h\"\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)\r\n#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*buffer++)\r\n#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }\r\n#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \\\r\n  { int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }}\r\n\r\n#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;\r\n\r\nint Bcj2_Decode(\r\n    const Byte *buf0, SizeT size0,\r\n    const Byte *buf1, SizeT size1,\r\n    const Byte *buf2, SizeT size2,\r\n    const Byte *buf3, SizeT size3,\r\n    Byte *outBuf, SizeT outSize)\r\n{\r\n  CProb p[256 + 2];\r\n  SizeT inPos = 0, outPos = 0;\r\n\r\n  const Byte *buffer, *bufferLim;\r\n  UInt32 range, code;\r\n  Byte prevByte = 0;\r\n\r\n  unsigned int i;\r\n  for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)\r\n    p[i] = kBitModelTotal >> 1;\r\n\r\n  buffer = buf3;\r\n  bufferLim = buffer + size3;\r\n  RC_INIT2\r\n\r\n  if (outSize == 0)\r\n    return SZ_OK;\r\n\r\n  for (;;)\r\n  {\r\n    Byte b;\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    UInt32 ttt;\r\n\r\n    SizeT limit = size0 - inPos;\r\n    if (outSize - outPos < limit)\r\n      limit = outSize - outPos;\r\n    while (limit != 0)\r\n    {\r\n      Byte b = buf0[inPos];\r\n      outBuf[outPos++] = b;\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      inPos++;\r\n      prevByte = b;\r\n      limit--;\r\n    }\r\n\r\n    if (limit == 0 || outPos == outSize)\r\n      break;\r\n\r\n    b = buf0[inPos++];\r\n\r\n    if (b == 0xE8)\r\n      prob = p + prevByte;\r\n    else if (b == 0xE9)\r\n      prob = p + 256;\r\n    else\r\n      prob = p + 257;\r\n\r\n    IF_BIT_0(prob)\r\n    {\r\n      UPDATE_0(prob)\r\n      prevByte = b;\r\n    }\r\n    else\r\n    {\r\n      UInt32 dest;\r\n      const Byte *v;\r\n      UPDATE_1(prob)\r\n      if (b == 0xE8)\r\n      {\r\n        v = buf1;\r\n        if (size1 < 4)\r\n          return SZ_ERROR_DATA;\r\n        buf1 += 4;\r\n        size1 -= 4;\r\n      }\r\n      else\r\n      {\r\n        v = buf2;\r\n        if (size2 < 4)\r\n          return SZ_ERROR_DATA;\r\n        buf2 += 4;\r\n        size2 -= 4;\r\n      }\r\n      dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |\r\n          ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);\r\n      outBuf[outPos++] = (Byte)dest;\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 8);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 16);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = prevByte = (Byte)(dest >> 24);\r\n    }\r\n  }\r\n  return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Bcj2.h",
    "content": "/* Bcj2.h -- Converter for x86 code (BCJ2)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __BCJ2_H\r\n#define __BCJ2_H\r\n\r\n#include \"Types.h\"\r\n\r\n/*\r\nConditions:\r\n  outSize <= FullOutputSize,\r\n  where FullOutputSize is full size of output stream of x86_2 filter.\r\n\r\nIf buf0 overlaps outBuf, there are two required conditions:\r\n  1) (buf0 >= outBuf)\r\n  2) (buf0 + size0 >= outBuf + FullOutputSize).\r\n\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nint Bcj2_Decode(\r\n    const Byte *buf0, SizeT size0,\r\n    const Byte *buf1, SizeT size1,\r\n    const Byte *buf2, SizeT size2,\r\n    const Byte *buf3, SizeT size3,\r\n    Byte *outBuf, SizeT outSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Bra.c",
    "content": "/* Bra.c -- Converters for RISC code\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  ip += 8;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      dest >>= 2;\r\n      data[i + 2] = (Byte)(dest >> 16);\r\n      data[i + 1] = (Byte)(dest >> 8);\r\n      data[i + 0] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  ip += 4;\r\n  for (i = 0; i <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 &&\r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src =\r\n        (((UInt32)data[i + 1] & 0x7) << 19) |\r\n        ((UInt32)data[i + 0] << 11) |\r\n        (((UInt32)data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));\r\n      data[i + 0] = (Byte)(dest >> 11);\r\n      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));\r\n      data[i + 2] = (Byte)dest;\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)\r\n    {\r\n      UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  UInt32 i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||\r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src =\r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      UInt32 dest;\r\n      \r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = ip + i + src;\r\n      else\r\n        dest = src - (ip + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Bra.h",
    "content": "/* Bra.h -- Branch converters for executables\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __BRA_H\r\n#define __BRA_H\r\n\r\n#include \"Types.h\"\r\n\r\n/*\r\nThese functions convert relative addresses to absolute addresses\r\nin CALL instructions to increase the compression ratio.\r\n  \r\n  In:\r\n    data     - data buffer\r\n    size     - size of data\r\n    ip       - current virtual Instruction Pinter (IP) value\r\n    state    - state variable for x86 converter\r\n    encoding - 0 (for decoding), 1 (for encoding)\r\n  \r\n  Out:\r\n    state    - state variable for x86 converter\r\n\r\n  Returns:\r\n    The number of processed bytes. If you call these functions with multiple calls,\r\n    you must start next call with first byte after block of processed bytes.\r\n  \r\n  Type   Endian  Alignment  LookAhead\r\n  \r\n  x86    little      1          4\r\n  ARMT   little      2          2\r\n  ARM    little      4          0\r\n  PPC     big        4          0\r\n  SPARC   big        4          0\r\n  IA64   little     16          0\r\n\r\n  size must be >= Alignment + LookAhead, if it's not last block.\r\n  If (size < Alignment + LookAhead), converter returns 0.\r\n\r\n  Example:\r\n\r\n    UInt32 ip = 0;\r\n    for ()\r\n    {\r\n      ; size must be >= Alignment + LookAhead, if it's not last block\r\n      SizeT processed = Convert(data, size, ip, 1);\r\n      data += processed;\r\n      size -= processed;\r\n      ip += processed;\r\n    }\r\n*/\r\n\r\n#define x86_Convert_Init(state) { state = 0; }\r\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);\r\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Bra86.c",
    "content": "/* Bra86.c -- Converter for x86 code (BCJ)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)\r\n{\r\n  SizeT bufferPos = 0, prevPosT;\r\n  UInt32 prevMask = *state & 0x7;\r\n  if (size < 5)\r\n    return 0;\r\n  ip += 5;\r\n  prevPosT = (SizeT)0 - 1;\r\n\r\n  for (;;)\r\n  {\r\n    Byte *p = data + bufferPos;\r\n    Byte *limit = data + size - 4;\r\n    for (; p < limit; p++)\r\n      if ((*p & 0xFE) == 0xE8)\r\n        break;\r\n    bufferPos = (SizeT)(p - data);\r\n    if (p >= limit)\r\n      break;\r\n    prevPosT = bufferPos - prevPosT;\r\n    if (prevPosT > 3)\r\n      prevMask = 0;\r\n    else\r\n    {\r\n      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r\n      if (prevMask != 0)\r\n      {\r\n        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r\n        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r\n        {\r\n          prevPosT = bufferPos;\r\n          prevMask = ((prevMask << 1) & 0x7) | 1;\r\n          bufferPos++;\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    prevPosT = bufferPos;\r\n\r\n    if (Test86MSByte(p[4]))\r\n    {\r\n      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r\n      UInt32 dest;\r\n      for (;;)\r\n      {\r\n        Byte b;\r\n        int index;\r\n        if (encoding)\r\n          dest = (ip + (UInt32)bufferPos) + src;\r\n        else\r\n          dest = src - (ip + (UInt32)bufferPos);\r\n        if (prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[prevMask] * 8;\r\n        b = (Byte)(dest >> (24 - index));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index)) - 1);\r\n      }\r\n      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      p[3] = (Byte)(dest >> 16);\r\n      p[2] = (Byte)(dest >> 8);\r\n      p[1] = (Byte)dest;\r\n      bufferPos += 5;\r\n    }\r\n    else\r\n    {\r\n      prevMask = ((prevMask << 1) & 0x7) | 1;\r\n      bufferPos++;\r\n    }\r\n  }\r\n  prevPosT = bufferPos - prevPosT;\r\n  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/BraIA64.c",
    "content": "/* BraIA64.c -- Converter for IA-64 code\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\nstatic const Byte kBranchTable[32] =\r\n{\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0\r\n};\r\n\r\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 16)\r\n    return 0;\r\n  size -= 16;\r\n  for (i = 0; i <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    int slot;\r\n    for (slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      UInt32 bytePos, bitRes;\r\n      UInt64 instruction, instNorm;\r\n      int j;\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      bytePos = (bitPos >> 3);\r\n      bitRes = bitPos & 0x7;\r\n      instruction = 0;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)data[i + j + bytePos] << (8 * j);\r\n\r\n      instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)\r\n      {\r\n        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);\r\n        UInt32 dest;\r\n        src |= ((UInt32)(instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        if (encoding)\r\n          dest = ip + (UInt32)i + src;\r\n        else\r\n          dest = src - (ip + (UInt32)i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~((UInt64)(0x8FFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/CpuArch.h",
    "content": "/* CpuArch.h\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __CPUARCH_H\r\n#define __CPUARCH_H\r\n\r\n/*\r\nLITTLE_ENDIAN_UNALIGN means:\r\n  1) CPU is LITTLE_ENDIAN\r\n  2) it's allowed to make unaligned memory accesses\r\nif LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know\r\nabout these properties of platform.\r\n*/\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#ifdef LITTLE_ENDIAN_UNALIGN\r\n\r\n#define GetUi16(p) (*(const UInt16 *)(p))\r\n#define GetUi32(p) (*(const UInt32 *)(p))\r\n#define GetUi64(p) (*(const UInt64 *)(p))\r\n#define SetUi32(p, d) *(UInt32 *)(p) = (d);\r\n\r\n#else\r\n\r\n#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))\r\n\r\n#define GetUi32(p) ( \\\r\n             ((const Byte *)(p))[0]        | \\\r\n    ((UInt32)((const Byte *)(p))[1] <<  8) | \\\r\n    ((UInt32)((const Byte *)(p))[2] << 16) | \\\r\n    ((UInt32)((const Byte *)(p))[3] << 24))\r\n\r\n#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))\r\n\r\n#define SetUi32(p, d) { UInt32 _x_ = (d); \\\r\n    ((Byte *)(p))[0] = (Byte)_x_; \\\r\n    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \\\r\n    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \\\r\n    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }\r\n\r\n#endif\r\n\r\n#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)\r\n\r\n#pragma intrinsic(_byteswap_ulong)\r\n#pragma intrinsic(_byteswap_uint64)\r\n#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))\r\n#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))\r\n\r\n#else\r\n\r\n#define GetBe32(p) ( \\\r\n    ((UInt32)((const Byte *)(p))[0] << 24) | \\\r\n    ((UInt32)((const Byte *)(p))[1] << 16) | \\\r\n    ((UInt32)((const Byte *)(p))[2] <<  8) | \\\r\n             ((const Byte *)(p))[3] )\r\n\r\n#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))\r\n\r\n#endif\r\n\r\n#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzFind.c",
    "content": "/* LzFind.c -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"LzFind.h\"\r\n#include \"LzHash.h\"\r\n\r\n#define kEmptyHashValue 0\r\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\r\n#define kMaxHistorySize ((UInt32)3 << 30)\r\n\r\n#define kStartMaxLen 3\r\n\r\nstatic void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  if (!p->directInput)\r\n  {\r\n    alloc->Free(alloc, p->bufferBase);\r\n    p->bufferBase = 0;\r\n  }\r\n}\r\n\r\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r\n\r\nstatic int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r\n{\r\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r\n  if (p->directInput)\r\n  {\r\n    p->blockSize = blockSize;\r\n    return 1;\r\n  }\r\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\r\n  {\r\n    LzInWindow_Free(p, alloc);\r\n    p->blockSize = blockSize;\r\n    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r\n  }\r\n  return (p->bufferBase != 0);\r\n}\r\n\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r\n\r\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r\n\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r\n{\r\n  p->posLimit -= subValue;\r\n  p->pos -= subValue;\r\n  p->streamPos -= subValue;\r\n}\r\n\r\nstatic void MatchFinder_ReadBlock(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached || p->result != SZ_OK)\r\n    return;\r\n  for (;;)\r\n  {\r\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\r\n    size_t size = (p->bufferBase + p->blockSize - dest);\r\n    if (size == 0)\r\n      return;\r\n    p->result = p->stream->Read(p->stream, dest, &size);\r\n    if (p->result != SZ_OK)\r\n      return;\r\n    if (size == 0)\r\n    {\r\n      p->streamEndWasReached = 1;\r\n      return;\r\n    }\r\n    p->streamPos += (UInt32)size;\r\n    if (p->streamPos - p->pos > p->keepSizeAfter)\r\n      return;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\r\n{\r\n  memmove(p->bufferBase,\r\n    p->buffer - p->keepSizeBefore,\r\n    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\r\n  p->buffer = p->bufferBase + p->keepSizeBefore;\r\n}\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p)\r\n{\r\n  /* if (p->streamEndWasReached) return 0; */\r\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r\n}\r\n\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached)\r\n    return;\r\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\r\n    MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r\n{\r\n  if (MatchFinder_NeedMove(p))\r\n    MatchFinder_MoveBlock(p);\r\n  MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_SetDefaultSettings(CMatchFinder *p)\r\n{\r\n  p->cutValue = 32;\r\n  p->btMode = 1;\r\n  p->numHashBytes = 4;\r\n  /* p->skipModeBits = 0; */\r\n  p->directInput = 0;\r\n  p->bigHash = 0;\r\n}\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  p->bufferBase = 0;\r\n  p->directInput = 0;\r\n  p->hash = 0;\r\n  MatchFinder_SetDefaultSettings(p);\r\n\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    p->crc[i] = r;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hash);\r\n  p->hash = 0;\r\n}\r\n\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  MatchFinder_FreeThisClassMemory(p, alloc);\r\n  LzInWindow_Free(p, alloc);\r\n}\r\n\r\nstatic CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r\n{\r\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r\n  if (sizeInBytes / sizeof(CLzRef) != num)\r\n    return 0;\r\n  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r\n}\r\n\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 sizeReserv;\r\n  if (historySize > kMaxHistorySize)\r\n  {\r\n    MatchFinder_Free(p, alloc);\r\n    return 0;\r\n  }\r\n  sizeReserv = historySize >> 1;\r\n  if (historySize > ((UInt32)2 << 30))\r\n    sizeReserv = historySize >> 2;\r\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r\n\r\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r\n  if (LzInWindow_Create(p, sizeReserv, alloc))\r\n  {\r\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r\n    UInt32 hs;\r\n    p->matchMaxLen = matchMaxLen;\r\n    {\r\n      p->fixedHashSize = 0;\r\n      if (p->numHashBytes == 2)\r\n        hs = (1 << 16) - 1;\r\n      else\r\n      {\r\n        hs = historySize - 1;\r\n        hs |= (hs >> 1);\r\n        hs |= (hs >> 2);\r\n        hs |= (hs >> 4);\r\n        hs |= (hs >> 8);\r\n        hs >>= 1;\r\n        /* hs >>= p->skipModeBits; */\r\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r\n        if (hs > (1 << 24))\r\n        {\r\n          if (p->numHashBytes == 3)\r\n            hs = (1 << 24) - 1;\r\n          else\r\n            hs >>= 1;\r\n        }\r\n      }\r\n      p->hashMask = hs;\r\n      hs++;\r\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r\n      hs += p->fixedHashSize;\r\n    }\r\n\r\n    {\r\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\r\n      UInt32 newSize;\r\n      p->historySize = historySize;\r\n      p->hashSizeSum = hs;\r\n      p->cyclicBufferSize = newCyclicBufferSize;\r\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r\n      newSize = p->hashSizeSum + p->numSons;\r\n      if (p->hash != 0 && prevSize == newSize)\r\n        return 1;\r\n      MatchFinder_FreeThisClassMemory(p, alloc);\r\n      p->hash = AllocRefs(newSize, alloc);\r\n      if (p->hash != 0)\r\n      {\r\n        p->son = p->hash + p->hashSizeSum;\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  MatchFinder_Free(p, alloc);\r\n  return 0;\r\n}\r\n\r\nstatic void MatchFinder_SetLimits(CMatchFinder *p)\r\n{\r\n  UInt32 limit = kMaxValForNormalize - p->pos;\r\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  limit2 = p->streamPos - p->pos;\r\n  if (limit2 <= p->keepSizeAfter)\r\n  {\r\n    if (limit2 > 0)\r\n      limit2 = 1;\r\n  }\r\n  else\r\n    limit2 -= p->keepSizeAfter;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  {\r\n    UInt32 lenLimit = p->streamPos - p->pos;\r\n    if (lenLimit > p->matchMaxLen)\r\n      lenLimit = p->matchMaxLen;\r\n    p->lenLimit = lenLimit;\r\n  }\r\n  p->posLimit = p->pos + limit;\r\n}\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->hashSizeSum; i++)\r\n    p->hash[i] = kEmptyHashValue;\r\n  p->cyclicBufferPos = 0;\r\n  p->buffer = p->bufferBase;\r\n  p->pos = p->streamPos = p->cyclicBufferSize;\r\n  p->result = SZ_OK;\r\n  p->streamEndWasReached = 0;\r\n  MatchFinder_ReadBlock(p);\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r\n{\r\n  return (p->pos - p->historySize - 1) & kNormalizeMask;\r\n}\r\n\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_Normalize(CMatchFinder *p)\r\n{\r\n  UInt32 subValue = MatchFinder_GetSubValue(p);\r\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r\n  MatchFinder_ReduceOffsets(p, subValue);\r\n}\r\n\r\nstatic void MatchFinder_CheckLimits(CMatchFinder *p)\r\n{\r\n  if (p->pos == kMaxValForNormalize)\r\n    MatchFinder_Normalize(p);\r\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r\n    MatchFinder_CheckAndMoveAndRead(p);\r\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\r\n    p->cyclicBufferPos = 0;\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  son[_cyclicBufferPos] = curMatch;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n      return distances;\r\n    {\r\n      const Byte *pb = cur - delta;\r\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r\n      {\r\n        UInt32 len = 0;\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n            return distances;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return distances;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return distances;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        {\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define MOVE_POS \\\r\n  ++p->cyclicBufferPos; \\\r\n  p->buffer++; \\\r\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r\n\r\n#define MOVE_POS_RET MOVE_POS return offset;\r\n\r\nstatic void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r\n\r\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\r\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\r\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\r\n  cur = p->buffer;\r\n\r\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r\n\r\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r\n\r\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\r\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\r\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\r\n\r\n#define SKIP_FOOTER \\\r\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r\n\r\nstatic UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(2)\r\n  HASH2_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 1)\r\n}\r\n\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 2)\r\n}\r\n\r\nstatic UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, delta2, maxLen, offset;\r\n  GET_MATCHES_HEADER(3)\r\n\r\n  HASH3_CALC;\r\n\r\n  delta2 = p->pos - p->hash[hash2Value];\r\n  curMatch = p->hash[kFix3HashSize + hashValue];\r\n  \r\n  p->hash[hash2Value] =\r\n  p->hash[kFix3HashSize + hashValue] = p->pos;\r\n\r\n\r\n  maxLen = 2;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[0] = maxLen;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n  \r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n\r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      p->son[p->cyclicBufferPos] = curMatch;\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances + offset, maxLen) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances, 2) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nstatic void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(2)\r\n    HASH2_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value;\r\n    SKIP_HEADER(3)\r\n    HASH3_CALC;\r\n    curMatch = p->hash[kFix3HashSize + hashValue];\r\n    p->hash[hash2Value] =\r\n    p->hash[kFix3HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] =\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r\n  if (!p->btMode)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 2)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 3)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r\n  }\r\n  else\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzFind.h",
    "content": "/* LzFind.h -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFIND_H\r\n#define __LZFIND_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef UInt32 CLzRef;\r\n\r\ntypedef struct _CMatchFinder\r\n{\r\n  Byte *buffer;\r\n  UInt32 pos;\r\n  UInt32 posLimit;\r\n  UInt32 streamPos;\r\n  UInt32 lenLimit;\r\n\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r\n\r\n  UInt32 matchMaxLen;\r\n  CLzRef *hash;\r\n  CLzRef *son;\r\n  UInt32 hashMask;\r\n  UInt32 cutValue;\r\n\r\n  Byte *bufferBase;\r\n  ISeqInStream *stream;\r\n  int streamEndWasReached;\r\n\r\n  UInt32 blockSize;\r\n  UInt32 keepSizeBefore;\r\n  UInt32 keepSizeAfter;\r\n\r\n  UInt32 numHashBytes;\r\n  int directInput;\r\n  int btMode;\r\n  /* int skipModeBits; */\r\n  int bigHash;\r\n  UInt32 historySize;\r\n  UInt32 fixedHashSize;\r\n  UInt32 hashSizeSum;\r\n  UInt32 numSons;\r\n  SRes result;\r\n  UInt32 crc[256];\r\n} CMatchFinder;\r\n\r\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r\n\r\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p);\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p);\r\n\r\n/* Conditions:\r\n     historySize <= 3 GB\r\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r\n*/\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc);\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *distances, UInt32 maxLen);\r\n\r\n/*\r\nConditions:\r\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r\n*/\r\n\r\ntypedef void (*Mf_Init_Func)(void *object);\r\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\r\n\r\ntypedef struct _IMatchFinder\r\n{\r\n  Mf_Init_Func Init;\r\n  Mf_GetIndexByte_Func GetIndexByte;\r\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r\n  Mf_GetMatches_Func GetMatches;\r\n  Mf_Skip_Func Skip;\r\n} IMatchFinder;\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p);\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzFindMt.c",
    "content": "/* LzFindMt.c -- multithreaded Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzHash.h\"\r\n\r\n#include \"LzFindMt.h\"\r\n\r\nvoid MtSync_Construct(CMtSync *p)\r\n{\r\n  p->wasCreated = False;\r\n  p->csWasInitialized = False;\r\n  p->csWasEntered = False;\r\n  Thread_Construct(&p->thread);\r\n  Event_Construct(&p->canStart);\r\n  Event_Construct(&p->wasStarted);\r\n  Event_Construct(&p->wasStopped);\r\n  Semaphore_Construct(&p->freeSemaphore);\r\n  Semaphore_Construct(&p->filledSemaphore);\r\n}\r\n\r\nvoid MtSync_GetNextBlock(CMtSync *p)\r\n{\r\n  if (p->needStart)\r\n  {\r\n    p->numProcessedBlocks = 1;\r\n    p->needStart = False;\r\n    p->stopWriting = False;\r\n    p->exit = False;\r\n    Event_Reset(&p->wasStarted);\r\n    Event_Reset(&p->wasStopped);\r\n\r\n    Event_Set(&p->canStart);\r\n    Event_Wait(&p->wasStarted);\r\n  }\r\n  else\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n    p->numProcessedBlocks++;\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  Semaphore_Wait(&p->filledSemaphore);\r\n  CriticalSection_Enter(&p->cs);\r\n  p->csWasEntered = True;\r\n}\r\n\r\n/* MtSync_StopWriting must be called if Writing was started */\r\n\r\nvoid MtSync_StopWriting(CMtSync *p)\r\n{\r\n  UInt32 myNumBlocks = p->numProcessedBlocks;\r\n  if (!Thread_WasCreated(&p->thread) || p->needStart)\r\n    return;\r\n  p->stopWriting = True;\r\n  if (p->csWasEntered)\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n  }\r\n  Semaphore_Release1(&p->freeSemaphore);\r\n \r\n  Event_Wait(&p->wasStopped);\r\n\r\n  while (myNumBlocks++ != p->numProcessedBlocks)\r\n  {\r\n    Semaphore_Wait(&p->filledSemaphore);\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  p->needStart = True;\r\n}\r\n\r\nvoid MtSync_Destruct(CMtSync *p)\r\n{\r\n  if (Thread_WasCreated(&p->thread))\r\n  {\r\n    MtSync_StopWriting(p);\r\n    p->exit = True;\r\n    if (p->needStart)\r\n      Event_Set(&p->canStart);\r\n    Thread_Wait(&p->thread);\r\n    Thread_Close(&p->thread);\r\n  }\r\n  if (p->csWasInitialized)\r\n  {\r\n    CriticalSection_Delete(&p->cs);\r\n    p->csWasInitialized = False;\r\n  }\r\n\r\n  Event_Close(&p->canStart);\r\n  Event_Close(&p->wasStarted);\r\n  Event_Close(&p->wasStopped);\r\n  Semaphore_Close(&p->freeSemaphore);\r\n  Semaphore_Close(&p->filledSemaphore);\r\n\r\n  p->wasCreated = False;\r\n}\r\n\r\n#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }\r\n\r\nstatic SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  if (p->wasCreated)\r\n    return SZ_OK;\r\n\r\n  RINOK_THREAD(CriticalSection_Init(&p->cs));\r\n  p->csWasInitialized = True;\r\n\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));\r\n  \r\n  RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));\r\n  RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));\r\n\r\n  p->needStart = True;\r\n  \r\n  RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));\r\n  p->wasCreated = True;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\r\n  if (res != SZ_OK)\r\n    MtSync_Destruct(p);\r\n  return res;\r\n}\r\n\r\nvoid MtSync_Init(CMtSync *p) { p->needStart = True; }\r\n\r\n#define kMtMaxValForNormalize 0xFFFFFFFF\r\n\r\n#define DEF_GetHeads2(name, v, action) \\\r\nstatic void GetHeads ## name(const Byte *p, UInt32 pos, \\\r\nUInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \\\r\n{ action; for (; numHeads != 0; numHeads--) { \\\r\nconst UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r\n\r\n#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)\r\n\r\nDEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )\r\nDEF_GetHeads(3,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\r\nDEF_GetHeads(4,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)\r\nDEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\r\nDEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)\r\n\r\nvoid HashThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->hashSync;\r\n  for (;;)\r\n  {\r\n    UInt32 numProcessedBlocks = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = numProcessedBlocks;\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n\r\n      {\r\n        CMatchFinder *mf = mt->MatchFinder;\r\n        if (MatchFinder_NeedMove(mf))\r\n        {\r\n          CriticalSection_Enter(&mt->btSync.cs);\r\n          CriticalSection_Enter(&mt->hashSync.cs);\r\n          {\r\n            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            const Byte *afterPtr;\r\n            MatchFinder_MoveBlock(mf);\r\n            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            mt->pointerToCurPos -= beforePtr - afterPtr;\r\n            mt->buffer -= beforePtr - afterPtr;\r\n          }\r\n          CriticalSection_Leave(&mt->btSync.cs);\r\n          CriticalSection_Leave(&mt->hashSync.cs);\r\n          continue;\r\n        }\r\n\r\n        Semaphore_Wait(&p->freeSemaphore);\r\n\r\n        MatchFinder_ReadIfRequired(mf);\r\n        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))\r\n        {\r\n          UInt32 subValue = (mf->pos - mf->historySize - 1);\r\n          MatchFinder_ReduceOffsets(mf, subValue);\r\n          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);\r\n        }\r\n        {\r\n          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n          UInt32 num = mf->streamPos - mf->pos;\r\n          heads[0] = 2;\r\n          heads[1] = num;\r\n          if (num >= mf->numHashBytes)\r\n          {\r\n            num = num - mf->numHashBytes + 1;\r\n            if (num > kMtHashBlockSize - 2)\r\n              num = kMtHashBlockSize - 2;\r\n            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);\r\n            heads[0] += num;\r\n          }\r\n          mf->pos += num;\r\n          mf->buffer += num;\r\n        }\r\n      }\r\n\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r\n{\r\n  MtSync_GetNextBlock(&p->hashSync);\r\n  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];\r\n  p->hashNumAvail = p->hashBuf[p->hashBufPos++];\r\n}\r\n\r\n#define kEmptyHashValue 0\r\n\r\n/* #define MFMT_GM_INLINE */\r\n\r\n#ifdef MFMT_GM_INLINE\r\n\r\n#define NO_INLINE MY_FAST_CALL\r\n\r\nInt32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\r\n{\r\n  do\r\n  {\r\n  UInt32 *distances = _distances + 1;\r\n  UInt32 curMatch = pos - *hash++;\r\n\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  UInt32 cutValue = _cutValue;\r\n  UInt32 maxLen = _maxLen;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      break;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            break;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n  pos++;\r\n  _cyclicBufferPos++;\r\n  cur++;\r\n  {\r\n    UInt32 num = (UInt32)(distances - _distances);\r\n    *_distances = num - 1;\r\n    _distances += num;\r\n    limit -= num;\r\n  }\r\n  }\r\n  while (limit > 0 && --size != 0);\r\n  *posRes = pos;\r\n  return limit;\r\n}\r\n\r\n#endif\r\n\r\nvoid BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  UInt32 numProcessed = 0;\r\n  UInt32 curPos = 2;\r\n  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\r\n  distances[1] = p->hashNumAvail;\r\n  while (curPos < limit)\r\n  {\r\n    if (p->hashBufPos == p->hashBufPosLimit)\r\n    {\r\n      MatchFinderMt_GetNextBlock_Hash(p);\r\n      distances[1] = numProcessed + p->hashNumAvail;\r\n      if (p->hashNumAvail >= p->numHashBytes)\r\n        continue;\r\n      for (; p->hashNumAvail != 0; p->hashNumAvail--)\r\n        distances[curPos++] = 0;\r\n      break;\r\n    }\r\n    {\r\n      UInt32 size = p->hashBufPosLimit - p->hashBufPos;\r\n      UInt32 lenLimit = p->matchMaxLen;\r\n      UInt32 pos = p->pos;\r\n      UInt32 cyclicBufferPos = p->cyclicBufferPos;\r\n      if (lenLimit >= p->hashNumAvail)\r\n        lenLimit = p->hashNumAvail;\r\n      {\r\n        UInt32 size2 = p->hashNumAvail - lenLimit + 1;\r\n        if (size2 < size)\r\n          size = size2;\r\n        size2 = p->cyclicBufferSize - cyclicBufferPos;\r\n        if (size2 < size)\r\n          size = size2;\r\n      }\r\n      #ifndef MFMT_GM_INLINE\r\n      while (curPos < limit && size-- != 0)\r\n      {\r\n        UInt32 *startDistances = distances + curPos;\r\n        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],\r\n          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r\n          startDistances + 1, p->numHashBytes - 1) - startDistances);\r\n        *startDistances = num - 1;\r\n        curPos += num;\r\n        cyclicBufferPos++;\r\n        pos++;\r\n        p->buffer++;\r\n      }\r\n      #else\r\n      {\r\n        UInt32 posRes;\r\n        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r\n          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);\r\n        p->hashBufPos += posRes - pos;\r\n        cyclicBufferPos += posRes - pos;\r\n        p->buffer += posRes - pos;\r\n        pos = posRes;\r\n      }\r\n      #endif\r\n\r\n      numProcessed += pos - p->pos;\r\n      p->hashNumAvail -= pos - p->pos;\r\n      p->pos = pos;\r\n      if (cyclicBufferPos == p->cyclicBufferSize)\r\n        cyclicBufferPos = 0;\r\n      p->cyclicBufferPos = cyclicBufferPos;\r\n    }\r\n  }\r\n  distances[0] = curPos;\r\n}\r\n\r\nvoid BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r\n{\r\n  CMtSync *sync = &p->hashSync;\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Enter(&sync->cs);\r\n    sync->csWasEntered = True;\r\n  }\r\n  \r\n  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);\r\n\r\n  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\r\n  {\r\n    UInt32 subValue = p->pos - p->cyclicBufferSize;\r\n    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);\r\n    p->pos -= subValue;\r\n  }\r\n\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Leave(&sync->cs);\r\n    sync->csWasEntered = False;\r\n  }\r\n}\r\n\r\nvoid BtThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->btSync;\r\n  for (;;)\r\n  {\r\n    UInt32 blockIndex = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = blockIndex;\r\n        MtSync_StopWriting(&mt->hashSync);\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n      Semaphore_Wait(&p->freeSemaphore);\r\n      BtFillBlock(mt, blockIndex++);\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p)\r\n{\r\n  p->hashBuf = 0;\r\n  MtSync_Construct(&p->hashSync);\r\n  MtSync_Construct(&p->btSync);\r\n}\r\n\r\nvoid MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hashBuf);\r\n  p->hashBuf = 0;\r\n}\r\n\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  MtSync_Destruct(&p->hashSync);\r\n  MtSync_Destruct(&p->btSync);\r\n  MatchFinderMt_FreeMem(p, alloc);\r\n}\r\n\r\n#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\r\n#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\r\n\r\nstatic unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r\nstatic unsigned MY_STD_CALL BtThreadFunc2(void *p)\r\n{\r\n  Byte allocaDummy[0x180];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  BtThreadFunc((CMatchFinderMt *)p);\r\n  return 0;\r\n}\r\n\r\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\r\n{\r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->historySize = historySize;\r\n  if (kMtBtBlockSize <= matchMaxLen * 4)\r\n    return SZ_ERROR_PARAM;\r\n  if (p->hashBuf == 0)\r\n  {\r\n    p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r\n    if (p->hashBuf == 0)\r\n      return SZ_ERROR_MEM;\r\n    p->btBuf = p->hashBuf + kHashBufferSize;\r\n  }\r\n  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);\r\n  keepAddBufferAfter += kMtHashBlockSize;\r\n  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))\r\n    return SZ_ERROR_MEM;\r\n\r\n  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));\r\n  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));\r\n  return SZ_OK;\r\n}\r\n\r\n/* Call it after ReleaseStream / SetStream */\r\nvoid MatchFinderMt_Init(CMatchFinderMt *p)\r\n{\r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->btBufPos = p->btBufPosLimit = 0;\r\n  p->hashBufPos = p->hashBufPosLimit = 0;\r\n  MatchFinder_Init(mf);\r\n  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);\r\n  p->btNumAvailBytes = 0;\r\n  p->lzPos = p->historySize + 1;\r\n\r\n  p->hash = mf->hash;\r\n  p->fixedHashSize = mf->fixedHashSize;\r\n  p->crc = mf->crc;\r\n\r\n  p->son = mf->son;\r\n  p->matchMaxLen = mf->matchMaxLen;\r\n  p->numHashBytes = mf->numHashBytes;\r\n  p->pos = mf->pos;\r\n  p->buffer = mf->buffer;\r\n  p->cyclicBufferPos = mf->cyclicBufferPos;\r\n  p->cyclicBufferSize = mf->cyclicBufferSize;\r\n  p->cutValue = mf->cutValue;\r\n}\r\n\r\n/* ReleaseStream is required to finish multithreading */\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p)\r\n{\r\n  MtSync_StopWriting(&p->btSync);\r\n  /* p->MatchFinder->ReleaseStream(); */\r\n}\r\n\r\nvoid MatchFinderMt_Normalize(CMatchFinderMt *p)\r\n{\r\n  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\r\n  p->lzPos = p->historySize + 1;\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r\n{\r\n  UInt32 blockIndex;\r\n  MtSync_GetNextBlock(&p->btSync);\r\n  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);\r\n  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;\r\n  p->btBufPosLimit += p->btBuf[p->btBufPos++];\r\n  p->btNumAvailBytes = p->btBuf[p->btBufPos++];\r\n  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)\r\n    MatchFinderMt_Normalize(p);\r\n}\r\n\r\nconst Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r\n{\r\n  return p->pointerToCurPos;\r\n}\r\n\r\n#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\r\n\r\nUInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r\n{\r\n  GET_NEXT_BLOCK_IF_REQUIRED;\r\n  return p->btNumAvailBytes;\r\n}\r\n\r\nByte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)\r\n{\r\n  return p->pointerToCurPos[index];\r\n}\r\n\r\nUInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, curMatch2;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH2_CALC\r\n      \r\n  curMatch2 = hash[hash2Value];\r\n  hash[hash2Value] = lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos)\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n    {\r\n      *distances++ = 2;\r\n      *distances++ = lzPos - curMatch2 - 1;\r\n    }\r\n  return distances;\r\n}\r\n\r\nUInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH3_CALC\r\n\r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  \r\n  hash[                hash2Value] =\r\n  hash[kFix3HashSize + hash3Value] =\r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] = 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    *distances++ = 3;\r\n    *distances++ = lzPos - curMatch3 - 1;\r\n  }\r\n  return distances;\r\n}\r\n\r\n/*\r\nUInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH4_CALC\r\n      \r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  curMatch4 = hash[kFix4HashSize + hash4Value];\r\n  \r\n  hash[                hash2Value] =\r\n  hash[kFix3HashSize + hash3Value] =\r\n  hash[kFix4HashSize + hash4Value] =\r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch3 - 1;\r\n    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])\r\n    {\r\n      distances[0] = 4;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 3;\r\n    distances += 2;\r\n  }\r\n\r\n  if (curMatch4 >= matchMinPos)\r\n    if (\r\n      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&\r\n      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]\r\n      )\r\n    {\r\n      *distances++ = 4;\r\n      *distances++ = lzPos - curMatch4 - 1;\r\n    }\r\n  return distances;\r\n}\r\n*/\r\n\r\n#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\r\n\r\nUInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n  p->btNumAvailBytes--;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < len; i += 2)\r\n    {\r\n      *distances++ = *btBuf++;\r\n      *distances++ = *btBuf++;\r\n    }\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\nUInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n\r\n  if (len == 0)\r\n  {\r\n    if (p->btNumAvailBytes-- >= 4)\r\n      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\r\n  }\r\n  else\r\n  {\r\n    /* Condition: there are matches in btBuf with length < p->numHashBytes */\r\n    UInt32 *distances2;\r\n    p->btNumAvailBytes--;\r\n    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\r\n    do\r\n    {\r\n      *distances2++ = *btBuf++;\r\n      *distances2++ = *btBuf++;\r\n    }\r\n    while ((len -= 2) != 0);\r\n    len  = (UInt32)(distances2 - (distances));\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\n#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED\r\n#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r\n#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);\r\n\r\nvoid MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER2 { p->btNumAvailBytes--;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(2)\r\n      UInt32 hash2Value;\r\n      MT_HASH2_CALC\r\n      hash[hash2Value] = p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(3)\r\n      UInt32 hash2Value, hash3Value;\r\n      MT_HASH3_CALC\r\n      hash[kFix3HashSize + hash3Value] =\r\n      hash[                hash2Value] =\r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\n/*\r\nvoid MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(4)\r\n      UInt32 hash2Value, hash3Value, hash4Value;\r\n      MT_HASH4_CALC\r\n      hash[kFix4HashSize + hash4Value] =\r\n      hash[kFix3HashSize + hash3Value] =\r\n      hash[                hash2Value] =\r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n*/\r\n\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\r\n  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\r\n  switch(p->MatchFinder->numHashBytes)\r\n  {\r\n    case 2:\r\n      p->GetHeadsFunc = GetHeads2;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)0;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\r\n      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\r\n      break;\r\n    case 3:\r\n      p->GetHeadsFunc = GetHeads3;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;\r\n      break;\r\n    default:\r\n    /* case 4: */\r\n      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\r\n      /* p->GetHeadsFunc = GetHeads4; */\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\r\n      break;\r\n    /*\r\n    default:\r\n      p->GetHeadsFunc = GetHeads5;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;\r\n      break;\r\n    */\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzFindMt.h",
    "content": "/* LzFindMt.h -- multithreaded Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFINDMT_H\r\n#define __LZFINDMT_H\r\n\r\n#include \"Threads.h\"\r\n#include \"LzFind.h\"\r\n\r\n#define kMtHashBlockSize (1 << 13)\r\n#define kMtHashNumBlocks (1 << 3)\r\n#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)\r\n\r\n#define kMtBtBlockSize (1 << 14)\r\n#define kMtBtNumBlocks (1 << 6)\r\n#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)\r\n\r\ntypedef struct _CMtSync\r\n{\r\n  Bool wasCreated;\r\n  Bool needStart;\r\n  Bool exit;\r\n  Bool stopWriting;\r\n\r\n  CThread thread;\r\n  CAutoResetEvent canStart;\r\n  CAutoResetEvent wasStarted;\r\n  CAutoResetEvent wasStopped;\r\n  CSemaphore freeSemaphore;\r\n  CSemaphore filledSemaphore;\r\n  Bool csWasInitialized;\r\n  Bool csWasEntered;\r\n  CCriticalSection cs;\r\n  UInt32 numProcessedBlocks;\r\n} CMtSync;\r\n\r\ntypedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);\r\n\r\n/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */\r\n#define kMtCacheLineDummy 128\r\n\r\ntypedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,\r\n  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);\r\n\r\ntypedef struct _CMatchFinderMt\r\n{\r\n  /* LZ */\r\n  const Byte *pointerToCurPos;\r\n  UInt32 *btBuf;\r\n  UInt32 btBufPos;\r\n  UInt32 btBufPosLimit;\r\n  UInt32 lzPos;\r\n  UInt32 btNumAvailBytes;\r\n\r\n  UInt32 *hash;\r\n  UInt32 fixedHashSize;\r\n  UInt32 historySize;\r\n  const UInt32 *crc;\r\n\r\n  Mf_Mix_Matches MixMatchesFunc;\r\n  \r\n  /* LZ + BT */\r\n  CMtSync btSync;\r\n  Byte btDummy[kMtCacheLineDummy];\r\n\r\n  /* BT */\r\n  UInt32 *hashBuf;\r\n  UInt32 hashBufPos;\r\n  UInt32 hashBufPosLimit;\r\n  UInt32 hashNumAvail;\r\n\r\n  CLzRef *son;\r\n  UInt32 matchMaxLen;\r\n  UInt32 numHashBytes;\r\n  UInt32 pos;\r\n  Byte *buffer;\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be historySize + 1 */\r\n  UInt32 cutValue;\r\n\r\n  /* BT + Hash */\r\n  CMtSync hashSync;\r\n  /* Byte hashDummy[kMtCacheLineDummy]; */\r\n  \r\n  /* Hash */\r\n  Mf_GetHeads GetHeadsFunc;\r\n  CMatchFinder *MatchFinder;\r\n} CMatchFinderMt;\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p);\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);\r\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzHash.h",
    "content": "/* LzHash.h -- HASH functions for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZHASH_H\r\n#define __LZHASH_H\r\n\r\n#define kHash2Size (1 << 10)\r\n#define kHash3Size (1 << 16)\r\n#define kHash4Size (1 << 20)\r\n\r\n#define kFix3HashSize (kHash2Size)\r\n#define kFix4HashSize (kHash2Size + kHash3Size)\r\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r\n\r\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r\n\r\n#define HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r\n\r\n#define HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r\n\r\n#define HASH5_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\\r\n  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\\r\n  hash4Value &= (kHash4Size - 1); }\r\n\r\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r\n\r\n\r\n#define MT_HASH2_CALC \\\r\n  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r\n\r\n#define MT_HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r\n\r\n#define MT_HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaDec.c",
    "content": "/* LzmaDec.c -- LZMA Decoder\r\n2008-11-06 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzmaDec.h\"\r\n\r\n#include <string.h>\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_INIT_SIZE 5\r\n\r\n#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));\r\n#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \\\r\n  { UPDATE_0(p); i = (i + i); A0; } else \\\r\n  { UPDATE_1(p); i = (i + i) + 1; A1; }\r\n#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)\r\n\r\n#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }\r\n#define TREE_DECODE(probs, limit, i) \\\r\n  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }\r\n\r\n/* #define _LZMA_SIZE_OPT */\r\n\r\n#ifdef _LZMA_SIZE_OPT\r\n#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)\r\n#else\r\n#define TREE_6_DECODE(probs, i) \\\r\n  { i = 1; \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  i -= 0x40; }\r\n#endif\r\n\r\n#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0_CHECK range = bound;\r\n#define UPDATE_1_CHECK range -= bound; code -= bound;\r\n#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \\\r\n  { UPDATE_0_CHECK; i = (i + i); A0; } else \\\r\n  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }\r\n#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)\r\n#define TREE_DECODE_CHECK(probs, limit, i) \\\r\n  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols)\r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nstatic const Byte kLiteralNextStates[kNumStates * 2] =\r\n{\r\n  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\r\n  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\r\n};\r\n\r\n#define LZMA_DIC_MIN (1 << 12)\r\n\r\n/* First LZMA-symbol is always decoded.\r\nAnd it decodes new LZMA-symbols while (buf < bufLimit), but \"buf\" is without last normalization\r\nOut:\r\n  Result:\r\n    SZ_OK - OK\r\n    SZ_ERROR_DATA - Error\r\n  p->remainLen:\r\n    < kMatchSpecLenStart : normal remain\r\n    = kMatchSpecLenStart : finished\r\n    = kMatchSpecLenStart + 1 : Flush marker\r\n    = kMatchSpecLenStart + 2 : State Init Marker\r\n*/\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  CLzmaProb *probs = p->probs;\r\n\r\n  unsigned state = p->state;\r\n  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];\r\n  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;\r\n  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;\r\n  unsigned lc = p->prop.lc;\r\n\r\n  Byte *dic = p->dic;\r\n  SizeT dicBufSize = p->dicBufSize;\r\n  SizeT dicPos = p->dicPos;\r\n  \r\n  UInt32 processedPos = p->processedPos;\r\n  UInt32 checkDicSize = p->checkDicSize;\r\n  unsigned len = 0;\r\n\r\n  const Byte *buf = p->buf;\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n\r\n  do\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = processedPos & pbMask;\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0(prob)\r\n    {\r\n      unsigned symbol;\r\n      UPDATE_0(prob);\r\n      prob = probs + Literal;\r\n      if (checkDicSize != 0 || processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r\n        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        symbol = 1;\r\n        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      dic[dicPos++] = (Byte)symbol;\r\n      processedPos++;\r\n\r\n      state = kLiteralNextStates[state];\r\n      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\r\n      continue;\r\n    }\r\n    else\r\n    {\r\n      UPDATE_1(prob);\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0(prob)\r\n      {\r\n        UPDATE_0(prob);\r\n        state += kNumStates;\r\n        prob = probs + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1(prob);\r\n        if (checkDicSize == 0 && processedPos == 0)\r\n          return SZ_ERROR_DATA;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0(prob)\r\n        {\r\n          UPDATE_0(prob);\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n            dicPos++;\r\n            processedPos++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            continue;\r\n          }\r\n          UPDATE_1(prob);\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UPDATE_1(prob);\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            distance = rep1;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(prob);\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0(prob)\r\n            {\r\n              UPDATE_0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0(probLen)\r\n        {\r\n          UPDATE_0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = (1 << kLenNumLowBits);\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0(probLen)\r\n          {\r\n            UPDATE_0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = (1 << kLenNumMidBits);\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = (1 << kLenNumHighBits);\r\n          }\r\n        }\r\n        TREE_DECODE(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state >= kNumStates)\r\n      {\r\n        UInt32 distance;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);\r\n        TREE_6_DECODE(prob, distance);\r\n        if (distance >= kStartPosModelIndex)\r\n        {\r\n          unsigned posSlot = (unsigned)distance;\r\n          int numDirectBits = (int)(((distance >> 1) - 1));\r\n          distance = (2 | (distance & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            distance <<= numDirectBits;\r\n            prob = probs + SpecPos + distance - posSlot - 1;\r\n            {\r\n              UInt32 mask = 1;\r\n              unsigned i = 1;\r\n              do\r\n              {\r\n                GET_BIT2(prob + i, i, ; , distance |= mask);\r\n                mask <<= 1;\r\n              }\r\n              while (--numDirectBits != 0);\r\n            }\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE\r\n              range >>= 1;\r\n              \r\n              {\r\n                UInt32 t;\r\n                code -= range;\r\n                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */\r\n                distance = (distance << 1) + (t + 1);\r\n                code += range & t;\r\n              }\r\n              /*\r\n              distance <<= 1;\r\n              if (code >= range)\r\n              {\r\n                code -= range;\r\n                distance |= 1;\r\n              }\r\n              */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            distance <<= kNumAlignBits;\r\n            {\r\n              unsigned i = 1;\r\n              GET_BIT2(prob + i, i, ; , distance |= 1);\r\n              GET_BIT2(prob + i, i, ; , distance |= 2);\r\n              GET_BIT2(prob + i, i, ; , distance |= 4);\r\n              GET_BIT2(prob + i, i, ; , distance |= 8);\r\n            }\r\n            if (distance == (UInt32)0xFFFFFFFF)\r\n            {\r\n              len += kMatchSpecLenStart;\r\n              state -= kNumStates;\r\n              break;\r\n            }\r\n          }\r\n        }\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        rep0 = distance + 1;\r\n        if (checkDicSize == 0)\r\n        {\r\n          if (distance >= processedPos)\r\n            return SZ_ERROR_DATA;\r\n        }\r\n        else if (distance >= checkDicSize)\r\n          return SZ_ERROR_DATA;\r\n        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r\n        /* state = kLiteralNextStates[state]; */\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n\r\n      if (limit == dicPos)\r\n        return SZ_ERROR_DATA;\r\n      {\r\n        SizeT rem = limit - dicPos;\r\n        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\r\n        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\r\n\r\n        processedPos += curLen;\r\n\r\n        len -= curLen;\r\n        if (pos + curLen <= dicBufSize)\r\n        {\r\n          Byte *dest = dic + dicPos;\r\n          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;\r\n          const Byte *lim = dest + curLen;\r\n          dicPos += curLen;\r\n          do\r\n            *(dest) = (Byte)*(dest + src);\r\n          while (++dest != lim);\r\n        }\r\n        else\r\n        {\r\n          do\r\n          {\r\n            dic[dicPos++] = dic[pos];\r\n            if (++pos == dicBufSize)\r\n              pos = 0;\r\n          }\r\n          while (--curLen != 0);\r\n        }\r\n      }\r\n    }\r\n  }\r\n  while (dicPos < limit && buf < bufLimit);\r\n  NORMALIZE;\r\n  p->buf = buf;\r\n  p->range = range;\r\n  p->code = code;\r\n  p->remainLen = len;\r\n  p->dicPos = dicPos;\r\n  p->processedPos = processedPos;\r\n  p->reps[0] = rep0;\r\n  p->reps[1] = rep1;\r\n  p->reps[2] = rep2;\r\n  p->reps[3] = rep3;\r\n  p->state = state;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\r\n{\r\n  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\r\n  {\r\n    Byte *dic = p->dic;\r\n    SizeT dicPos = p->dicPos;\r\n    SizeT dicBufSize = p->dicBufSize;\r\n    unsigned len = p->remainLen;\r\n    UInt32 rep0 = p->reps[0];\r\n    if (limit - dicPos < len)\r\n      len = (unsigned)(limit - dicPos);\r\n\r\n    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r\n      p->checkDicSize = p->prop.dicSize;\r\n\r\n    p->processedPos += len;\r\n    p->remainLen -= len;\r\n    while (len-- != 0)\r\n    {\r\n      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n      dicPos++;\r\n    }\r\n    p->dicPos = dicPos;\r\n  }\r\n}\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  do\r\n  {\r\n    SizeT limit2 = limit;\r\n    if (p->checkDicSize == 0)\r\n    {\r\n      UInt32 rem = p->prop.dicSize - p->processedPos;\r\n      if (limit - p->dicPos > rem)\r\n        limit2 = p->dicPos + rem;\r\n    }\r\n    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r\n    if (p->processedPos >= p->prop.dicSize)\r\n      p->checkDicSize = p->prop.dicSize;\r\n    LzmaDec_WriteRem(p, limit);\r\n  }\r\n  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r\n\r\n  if (p->remainLen > kMatchSpecLenStart)\r\n  {\r\n    p->remainLen = kMatchSpecLenStart;\r\n  }\r\n  return 0;\r\n}\r\n\r\ntypedef enum\r\n{\r\n  DUMMY_ERROR, /* unexpected end of input stream */\r\n  DUMMY_LIT,\r\n  DUMMY_MATCH,\r\n  DUMMY_REP\r\n} ELzmaDummy;\r\n\r\nstatic ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\r\n{\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n  const Byte *bufLimit = buf + inSize;\r\n  CLzmaProb *probs = p->probs;\r\n  unsigned state = p->state;\r\n  ELzmaDummy res;\r\n\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0_CHECK(prob)\r\n    {\r\n      UPDATE_0_CHECK\r\n\r\n      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\r\n\r\n      prob = probs + Literal;\r\n      if (p->checkDicSize != 0 || p->processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE *\r\n          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r\n          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        unsigned symbol = 1;\r\n        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r\n            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        unsigned symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      res = DUMMY_LIT;\r\n    }\r\n    else\r\n    {\r\n      unsigned len;\r\n      UPDATE_1_CHECK;\r\n\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0_CHECK(prob)\r\n      {\r\n        UPDATE_0_CHECK;\r\n        state = 0;\r\n        prob = probs + LenCoder;\r\n        res = DUMMY_MATCH;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1_CHECK;\r\n        res = DUMMY_REP;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0_CHECK(prob)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            NORMALIZE_CHECK;\r\n            return DUMMY_REP;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0_CHECK(prob)\r\n            {\r\n              UPDATE_0_CHECK;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1_CHECK;\r\n            }\r\n          }\r\n        }\r\n        state = kNumStates;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0_CHECK(probLen)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = 1 << kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0_CHECK(probLen)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = 1 << kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = 1 << kLenNumHighBits;\r\n          }\r\n        }\r\n        TREE_DECODE_CHECK(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        unsigned posSlot;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<\r\n            kNumPosSlotBits);\r\n        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n\r\n          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE_CHECK\r\n              range >>= 1;\r\n              code -= range & (((code - range) >> 31) - 1);\r\n              /* if (code >= range) code -= range; */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            unsigned i = 1;\r\n            do\r\n            {\r\n              GET_BIT_CHECK(prob + i, i);\r\n            }\r\n            while (--numDirectBits != 0);\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  NORMALIZE_CHECK;\r\n  return res;\r\n}\r\n\r\n\r\nstatic void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\r\n{\r\n  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\r\n  p->range = 0xFFFFFFFF;\r\n  p->needFlush = 0;\r\n}\r\n\r\nvoid LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r\n{\r\n  p->needFlush = 1;\r\n  p->remainLen = 0;\r\n  p->tempBufSize = 0;\r\n\r\n  if (initDic)\r\n  {\r\n    p->processedPos = 0;\r\n    p->checkDicSize = 0;\r\n    p->needInitState = 1;\r\n  }\r\n  if (initState)\r\n    p->needInitState = 1;\r\n}\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p)\r\n{\r\n  p->dicPos = 0;\r\n  LzmaDec_InitDicAndState(p, True, True);\r\n}\r\n\r\nstatic void LzmaDec_InitStateReal(CLzmaDec *p)\r\n{\r\n  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\r\n  UInt32 i;\r\n  CLzmaProb *probs = p->probs;\r\n  for (i = 0; i < numProbs; i++)\r\n    probs[i] = kBitModelTotal >> 1;\r\n  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;\r\n  p->state = 0;\r\n  p->needInitState = 0;\r\n}\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\r\n    ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT inSize = *srcLen;\r\n  (*srcLen) = 0;\r\n  LzmaDec_WriteRem(p, dicLimit);\r\n  \r\n  *status = LZMA_STATUS_NOT_SPECIFIED;\r\n\r\n  while (p->remainLen != kMatchSpecLenStart)\r\n  {\r\n      int checkEndMarkNow;\r\n\r\n      if (p->needFlush != 0)\r\n      {\r\n        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r\n          p->tempBuf[p->tempBufSize++] = *src++;\r\n        if (p->tempBufSize < RC_INIT_SIZE)\r\n        {\r\n          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n          return SZ_OK;\r\n        }\r\n        if (p->tempBuf[0] != 0)\r\n          return SZ_ERROR_DATA;\r\n\r\n        LzmaDec_InitRc(p, p->tempBuf);\r\n        p->tempBufSize = 0;\r\n      }\r\n\r\n      checkEndMarkNow = 0;\r\n      if (p->dicPos >= dicLimit)\r\n      {\r\n        if (p->remainLen == 0 && p->code == 0)\r\n        {\r\n          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;\r\n          return SZ_OK;\r\n        }\r\n        if (finishMode == LZMA_FINISH_ANY)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_OK;\r\n        }\r\n        if (p->remainLen != 0)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_ERROR_DATA;\r\n        }\r\n        checkEndMarkNow = 1;\r\n      }\r\n\r\n      if (p->needInitState)\r\n        LzmaDec_InitStateReal(p);\r\n  \r\n      if (p->tempBufSize == 0)\r\n      {\r\n        SizeT processed;\r\n        const Byte *bufLimit;\r\n        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            memcpy(p->tempBuf, src, inSize);\r\n            p->tempBufSize = (unsigned)inSize;\r\n            (*srcLen) += inSize;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n          bufLimit = src;\r\n        }\r\n        else\r\n          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\r\n        p->buf = src;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\r\n          return SZ_ERROR_DATA;\r\n        processed = (SizeT)(p->buf - src);\r\n        (*srcLen) += processed;\r\n        src += processed;\r\n        inSize -= processed;\r\n      }\r\n      else\r\n      {\r\n        unsigned rem = p->tempBufSize, lookAhead = 0;\r\n        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\r\n          p->tempBuf[rem++] = src[lookAhead++];\r\n        p->tempBufSize = rem;\r\n        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            (*srcLen) += lookAhead;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n        }\r\n        p->buf = p->tempBuf;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r\n          return SZ_ERROR_DATA;\r\n        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\r\n        (*srcLen) += lookAhead;\r\n        src += lookAhead;\r\n        inSize -= lookAhead;\r\n        p->tempBufSize = 0;\r\n      }\r\n  }\r\n  if (p->code == 0)\r\n    *status = LZMA_STATUS_FINISHED_WITH_MARK;\r\n  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT outSize = *destLen;\r\n  SizeT inSize = *srcLen;\r\n  *srcLen = *destLen = 0;\r\n  for (;;)\r\n  {\r\n    SizeT inSizeCur = inSize, outSizeCur, dicPos;\r\n    ELzmaFinishMode curFinishMode;\r\n    SRes res;\r\n    if (p->dicPos == p->dicBufSize)\r\n      p->dicPos = 0;\r\n    dicPos = p->dicPos;\r\n    if (outSize > p->dicBufSize - dicPos)\r\n    {\r\n      outSizeCur = p->dicBufSize;\r\n      curFinishMode = LZMA_FINISH_ANY;\r\n    }\r\n    else\r\n    {\r\n      outSizeCur = dicPos + outSize;\r\n      curFinishMode = finishMode;\r\n    }\r\n\r\n    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);\r\n    src += inSizeCur;\r\n    inSize -= inSizeCur;\r\n    *srcLen += inSizeCur;\r\n    outSizeCur = p->dicPos - dicPos;\r\n    memcpy(dest, p->dic + dicPos, outSizeCur);\r\n    dest += outSizeCur;\r\n    outSize -= outSizeCur;\r\n    *destLen += outSizeCur;\r\n    if (res != 0)\r\n      return res;\r\n    if (outSizeCur == 0 || outSize == 0)\r\n      return SZ_OK;\r\n  }\r\n}\r\n\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->probs);\r\n  p->probs = 0;\r\n}\r\n\r\nstatic void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->dic);\r\n  p->dic = 0;\r\n}\r\n\r\nvoid LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  LzmaDec_FreeProbs(p, alloc);\r\n  LzmaDec_FreeDict(p, alloc);\r\n}\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)\r\n{\r\n  UInt32 dicSize;\r\n  Byte d;\r\n  \r\n  if (size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  else\r\n    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);\r\n \r\n  if (dicSize < LZMA_DIC_MIN)\r\n    dicSize = LZMA_DIC_MIN;\r\n  p->dicSize = dicSize;\r\n\r\n  d = data[0];\r\n  if (d >= (9 * 5 * 5))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  p->lc = d % 9;\r\n  d /= 9;\r\n  p->pb = d / 5;\r\n  p->lp = d % 5;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r\n{\r\n  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r\n  if (p->probs == 0 || numProbs != p->numProbs)\r\n  {\r\n    LzmaDec_FreeProbs(p, alloc);\r\n    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r\n    p->numProbs = numProbs;\r\n    if (p->probs == 0)\r\n      return SZ_ERROR_MEM;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  SizeT dicBufSize;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  dicBufSize = propNew.dicSize;\r\n  if (p->dic == 0 || dicBufSize != p->dicBufSize)\r\n  {\r\n    LzmaDec_FreeDict(p, alloc);\r\n    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r\n    if (p->dic == 0)\r\n    {\r\n      LzmaDec_FreeProbs(p, alloc);\r\n      return SZ_ERROR_MEM;\r\n    }\r\n  }\r\n  p->dicBufSize = dicBufSize;\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc)\r\n{\r\n  CLzmaDec p;\r\n  SRes res;\r\n  SizeT inSize = *srcLen;\r\n  SizeT outSize = *destLen;\r\n  *srcLen = *destLen = 0;\r\n  if (inSize < RC_INIT_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  LzmaDec_Construct(&p);\r\n  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\r\n  if (res != 0)\r\n    return res;\r\n  p.dic = dest;\r\n  p.dicBufSize = outSize;\r\n\r\n  LzmaDec_Init(&p);\r\n  \r\n  *srcLen = inSize;\r\n  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r\n\r\n  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r\n    res = SZ_ERROR_INPUT_EOF;\r\n\r\n  (*destLen) = p.dicPos;\r\n  LzmaDec_FreeProbs(&p, alloc);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaDec.h",
    "content": "/* LzmaDec.h -- LZMA Decoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMADEC_H\r\n#define __LZMADEC_H\r\n\r\n#include \"Types.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* _LZMA_PROB32 can increase the speed on some CPUs,\r\n   but memory usage for CLzmaDec::probs will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n\r\n/* ---------- LZMA Properties ---------- */\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaProps\r\n{\r\n  unsigned lc, lp, pb;\r\n  UInt32 dicSize;\r\n} CLzmaProps;\r\n\r\n/* LzmaProps_Decode - decodes properties\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);\r\n\r\n\r\n/* ---------- LZMA Decoder state ---------- */\r\n\r\n/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.\r\n   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */\r\n\r\n#define LZMA_REQUIRED_INPUT_MAX 20\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProps prop;\r\n  CLzmaProb *probs;\r\n  Byte *dic;\r\n  const Byte *buf;\r\n  UInt32 range, code;\r\n  SizeT dicPos;\r\n  SizeT dicBufSize;\r\n  UInt32 processedPos;\r\n  UInt32 checkDicSize;\r\n  unsigned state;\r\n  UInt32 reps[4];\r\n  unsigned remainLen;\r\n  int needFlush;\r\n  int needInitState;\r\n  UInt32 numProbs;\r\n  unsigned tempBufSize;\r\n  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];\r\n} CLzmaDec;\r\n\r\n#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p);\r\n\r\n/* There are two types of LZMA streams:\r\n     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.\r\n     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_FINISH_ANY,   /* finish at any point */\r\n  LZMA_FINISH_END    /* block must be finished at the end */\r\n} ELzmaFinishMode;\r\n\r\n/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!\r\n\r\n   You must use LZMA_FINISH_END, when you know that current output buffer\r\n   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.\r\n\r\n   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,\r\n   and output value of destLen will be less than output buffer size limit.\r\n   You can check status result also.\r\n\r\n   You can use multiple checks to test data integrity after full decompression:\r\n     1) Check Result and \"status\" variable.\r\n     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.\r\n        You must use correct finish mode in that case. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */\r\n  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\r\n  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */\r\n  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */\r\n  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */\r\n} ELzmaStatus;\r\n\r\n/* ELzmaStatus is used only as output value for function call */\r\n\r\n\r\n/* ---------- Interfaces ---------- */\r\n\r\n/* There are 3 levels of interfaces:\r\n     1) Dictionary Interface\r\n     2) Buffer Interface\r\n     3) One Call Interface\r\n   You can select any of these interfaces, but don't mix functions from different\r\n   groups for same object. */\r\n\r\n\r\n/* There are two variants to allocate state for Dictionary Interface:\r\n     1) LzmaDec_Allocate / LzmaDec_Free\r\n     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs\r\n   You can use variant 2, if you set dictionary buffer manually.\r\n   For Buffer Interface you must always use variant 1.\r\n\r\nLzmaDec_Allocate* can return:\r\n  SZ_OK\r\n  SZ_ERROR_MEM         - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n   \r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);\r\n\r\n/* ---------- Dictionary Interface ---------- */\r\n\r\n/* You can use it, if you want to eliminate the overhead for data copying from\r\n   dictionary to some other external buffer.\r\n   You must work with CLzmaDec variables directly in this interface.\r\n\r\n   STEPS:\r\n     LzmaDec_Constr()\r\n     LzmaDec_Allocate()\r\n     for (each new stream)\r\n     {\r\n       LzmaDec_Init()\r\n       while (it needs more decompression)\r\n       {\r\n         LzmaDec_DecodeToDic()\r\n         use data from CLzmaDec::dic and update CLzmaDec::dicPos\r\n       }\r\n     }\r\n     LzmaDec_Free()\r\n*/\r\n\r\n/* LzmaDec_DecodeToDic\r\n   \r\n   The decoding to internal dictionary buffer (CLzmaDec::dic).\r\n   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (dicLimit).\r\n  LZMA_FINISH_ANY - Decode just dicLimit bytes.\r\n  LZMA_FINISH_END - Stream must be finished after dicLimit.\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_NEEDS_MORE_INPUT\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- Buffer Interface ---------- */\r\n\r\n/* It's zlib-like interface.\r\n   See LzmaDec_DecodeToDic description for information about STEPS and return results,\r\n   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need\r\n   to work with CLzmaDec variables manually.\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n*/\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaDecode\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n  SZ_ERROR_MEM  - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n*/\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaEnc.c",
    "content": "/* LzmaEnc.c -- LZMA Encoder\r\n2009-02-02 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n/* #define SHOW_STAT */\r\n/* #define SHOW_STAT2 */\r\n\r\n#if defined(SHOW_STAT) || defined(SHOW_STAT2)\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"LzmaEnc.h\"\r\n\r\n#include \"LzFind.h\"\r\n#ifdef COMPRESS_MF_MT\r\n#include \"LzFindMt.h\"\r\n#endif\r\n\r\n#ifdef SHOW_STAT\r\nstatic int ttt = 0;\r\n#endif\r\n\r\n#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)\r\n\r\n#define kBlockSize (9 << 10)\r\n#define kUnpackBlockSize (1 << 18)\r\n#define kMatchArraySize (1 << 21)\r\n#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)\r\n\r\n#define kNumMaxDirectBits (31)\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n#define kProbInitValue (kBitModelTotal >> 1)\r\n\r\n#define kNumMoveReducingBits 4\r\n#define kNumBitPriceShiftBits 4\r\n#define kBitPrice (1 << kNumBitPriceShiftBits)\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p)\r\n{\r\n  p->level = 5;\r\n  p->dictSize = p->mc = 0;\r\n  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\r\n  p->writeEndMark = 0;\r\n}\r\n\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p)\r\n{\r\n  int level = p->level;\r\n  if (level < 0) level = 5;\r\n  p->level = level;\r\n  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));\r\n  if (p->lc < 0) p->lc = 3;\r\n  if (p->lp < 0) p->lp = 0;\r\n  if (p->pb < 0) p->pb = 2;\r\n  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);\r\n  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);\r\n  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);\r\n  if (p->numHashBytes < 0) p->numHashBytes = 4;\r\n  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\r\n  if (p->numThreads < 0)\r\n    p->numThreads =\r\n      #ifdef COMPRESS_MF_MT\r\n      ((p->btMode && p->algo) ? 2 : 1);\r\n      #else\r\n      1;\r\n      #endif\r\n}\r\n\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n  return props.dictSize;\r\n}\r\n\r\n/* #define LZMA_LOG_BSR */\r\n/* Define it for Intel's CPU */\r\n\r\n\r\n#ifdef LZMA_LOG_BSR\r\n\r\n#define kDicLogSizeMaxCompress 30\r\n\r\n#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }\r\n\r\nUInt32 GetPosSlot1(UInt32 pos)\r\n{\r\n  UInt32 res;\r\n  BSR2_RET(pos, res);\r\n  return res;\r\n}\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }\r\n\r\n#else\r\n\r\n#define kNumLogBits (9 + (int)sizeof(size_t) / 2)\r\n#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)\r\n\r\nvoid LzmaEnc_FastPosInit(Byte *g_FastPos)\r\n{\r\n  int c = 2, slotFast;\r\n  g_FastPos[0] = 0;\r\n  g_FastPos[1] = 1;\r\n  \r\n  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)\r\n  {\r\n    UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n    UInt32 j;\r\n    for (j = 0; j < k; j++, c++)\r\n      g_FastPos[c] = (Byte)slotFast;\r\n  }\r\n}\r\n\r\n#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \\\r\n  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \\\r\n  res = p->g_FastPos[pos >> i] + (i * 2); }\r\n/*\r\n#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \\\r\n  p->g_FastPos[pos >> 6] + 12 : \\\r\n  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }\r\n*/\r\n\r\n#define GetPosSlot1(pos) p->g_FastPos[pos]\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }\r\n\r\n#endif\r\n\r\n\r\n#define LZMA_NUM_REPS 4\r\n\r\ntypedef unsigned CState;\r\n\r\ntypedef struct _COptimal\r\n{\r\n  UInt32 price;\r\n\r\n  CState state;\r\n  int prev1IsChar;\r\n  int prev2;\r\n\r\n  UInt32 posPrev2;\r\n  UInt32 backPrev2;\r\n\r\n  UInt32 posPrev;\r\n  UInt32 backPrev;\r\n  UInt32 backs[LZMA_NUM_REPS];\r\n} COptimal;\r\n\r\n#define kNumOpts (1 << 12)\r\n\r\n#define kNumLenToPosStates 4\r\n#define kNumPosSlotBits 6\r\n#define kDicLogSizeMin 0\r\n#define kDicLogSizeMax 32\r\n#define kDistTableSizeMax (kDicLogSizeMax * 2)\r\n\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n#define kAlignMask (kAlignTableSize - 1)\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)\r\n\r\n#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n#define LZMA_PB_MAX 4\r\n#define LZMA_LC_MAX 8\r\n#define LZMA_LP_MAX 4\r\n\r\n#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)\r\n\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define LZMA_MATCH_LEN_MIN 2\r\n#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)\r\n\r\n#define kNumStates 12\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb choice;\r\n  CLzmaProb choice2;\r\n  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];\r\n  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];\r\n  CLzmaProb high[kLenNumHighSymbols];\r\n} CLenEnc;\r\n\r\ntypedef struct\r\n{\r\n  CLenEnc p;\r\n  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\r\n  UInt32 tableSize;\r\n  UInt32 counters[LZMA_NUM_PB_STATES_MAX];\r\n} CLenPriceEnc;\r\n\r\ntypedef struct _CRangeEnc\r\n{\r\n  UInt32 range;\r\n  Byte cache;\r\n  UInt64 low;\r\n  UInt64 cacheSize;\r\n  Byte *buf;\r\n  Byte *bufLim;\r\n  Byte *bufBase;\r\n  ISeqOutStream *outStream;\r\n  UInt64 processed;\r\n  SRes res;\r\n} CRangeEnc;\r\n\r\ntypedef struct _CSeqInStreamBuf\r\n{\r\n  ISeqInStream funcTable;\r\n  const Byte *data;\r\n  SizeT rem;\r\n} CSeqInStreamBuf;\r\n\r\nstatic SRes MyRead(void *pp, void *data, size_t *size)\r\n{\r\n  size_t curSize = *size;\r\n  CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;\r\n  if (p->rem < curSize)\r\n    curSize = p->rem;\r\n  memcpy(data, p->data, curSize);\r\n  p->rem -= curSize;\r\n  p->data += curSize;\r\n  *size = curSize;\r\n  return SZ_OK;\r\n}\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n} CSaveState;\r\n\r\ntypedef struct _CLzmaEnc\r\n{\r\n  IMatchFinder matchFinder;\r\n  void *matchFinderObj;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Bool mtMode;\r\n  CMatchFinderMt matchFinderMt;\r\n  #endif\r\n\r\n  CMatchFinder matchFinderBase;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte pad[128];\r\n  #endif\r\n  \r\n  UInt32 optimumEndIndex;\r\n  UInt32 optimumCurrentIndex;\r\n\r\n  UInt32 longestMatchLength;\r\n  UInt32 numPairs;\r\n  UInt32 numAvail;\r\n  COptimal opt[kNumOpts];\r\n  \r\n  #ifndef LZMA_LOG_BSR\r\n  Byte g_FastPos[1 << kNumLogBits];\r\n  #endif\r\n\r\n  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];\r\n  UInt32 numFastBytes;\r\n  UInt32 additionalOffset;\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n\r\n  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n  UInt32 alignPrices[kAlignTableSize];\r\n  UInt32 alignPriceCount;\r\n\r\n  UInt32 distTableSize;\r\n\r\n  unsigned lc, lp, pb;\r\n  unsigned lpMask, pbMask;\r\n\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  unsigned lclp;\r\n\r\n  Bool fastMode;\r\n  \r\n  CRangeEnc rc;\r\n\r\n  Bool writeEndMark;\r\n  UInt64 nowPos64;\r\n  UInt32 matchPriceCount;\r\n  Bool finished;\r\n  Bool multiThread;\r\n\r\n  SRes result;\r\n  UInt32 dictSize;\r\n  UInt32 matchFinderCycles;\r\n\r\n  ISeqInStream *inStream;\r\n  CSeqInStreamBuf seqBufInStream;\r\n\r\n  CSaveState saveState;\r\n} CLzmaEnc;\r\n\r\nvoid LzmaEnc_SaveState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CSaveState *dest = &p->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nvoid LzmaEnc_RestoreState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *dest = (CLzmaEnc *)pp;\r\n  const CSaveState *p = &dest->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n\r\n  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||\r\n      props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))\r\n    return SZ_ERROR_PARAM;\r\n  p->dictSize = props.dictSize;\r\n  p->matchFinderCycles = props.mc;\r\n  {\r\n    unsigned fb = props.fb;\r\n    if (fb < 5)\r\n      fb = 5;\r\n    if (fb > LZMA_MATCH_LEN_MAX)\r\n      fb = LZMA_MATCH_LEN_MAX;\r\n    p->numFastBytes = fb;\r\n  }\r\n  p->lc = props.lc;\r\n  p->lp = props.lp;\r\n  p->pb = props.pb;\r\n  p->fastMode = (props.algo == 0);\r\n  p->matchFinderBase.btMode = props.btMode;\r\n  {\r\n    UInt32 numHashBytes = 4;\r\n    if (props.btMode)\r\n    {\r\n      if (props.numHashBytes < 2)\r\n        numHashBytes = 2;\r\n      else if (props.numHashBytes < 4)\r\n        numHashBytes = props.numHashBytes;\r\n    }\r\n    p->matchFinderBase.numHashBytes = numHashBytes;\r\n  }\r\n\r\n  p->matchFinderBase.cutValue = props.mc;\r\n\r\n  p->writeEndMark = props.writeEndMark;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  /*\r\n  if (newMultiThread != _multiThread)\r\n  {\r\n    ReleaseMatchFinder();\r\n    _multiThread = newMultiThread;\r\n  }\r\n  */\r\n  p->multiThread = (props.numThreads > 1);\r\n  #endif\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nstatic const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nstatic const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nstatic const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n#define IsCharState(s) ((s) < 7)\r\n\r\n#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)\r\n\r\n#define kInfinityPrice (1 << 30)\r\n\r\nstatic void RangeEnc_Construct(CRangeEnc *p)\r\n{\r\n  p->outStream = 0;\r\n  p->bufBase = 0;\r\n}\r\n\r\n#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)\r\n\r\n#define RC_BUF_SIZE (1 << 16)\r\nstatic int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  if (p->bufBase == 0)\r\n  {\r\n    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);\r\n    if (p->bufBase == 0)\r\n      return 0;\r\n    p->bufLim = p->bufBase + RC_BUF_SIZE;\r\n  }\r\n  return 1;\r\n}\r\n\r\nstatic void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->bufBase);\r\n  p->bufBase = 0;\r\n}\r\n\r\nstatic void RangeEnc_Init(CRangeEnc *p)\r\n{\r\n  /* Stream.Init(); */\r\n  p->low = 0;\r\n  p->range = 0xFFFFFFFF;\r\n  p->cacheSize = 1;\r\n  p->cache = 0;\r\n\r\n  p->buf = p->bufBase;\r\n\r\n  p->processed = 0;\r\n  p->res = SZ_OK;\r\n}\r\n\r\nstatic void RangeEnc_FlushStream(CRangeEnc *p)\r\n{\r\n  size_t num;\r\n  if (p->res != SZ_OK)\r\n    return;\r\n  num = p->buf - p->bufBase;\r\n  if (num != p->outStream->Write(p->outStream, p->bufBase, num))\r\n    p->res = SZ_ERROR_WRITE;\r\n  p->processed += num;\r\n  p->buf = p->bufBase;\r\n}\r\n\r\nstatic void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)\r\n{\r\n  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)\r\n  {\r\n    Byte temp = p->cache;\r\n    do\r\n    {\r\n      Byte *buf = p->buf;\r\n      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));\r\n      p->buf = buf;\r\n      if (buf == p->bufLim)\r\n        RangeEnc_FlushStream(p);\r\n      temp = 0xFF;\r\n    }\r\n    while (--p->cacheSize != 0);\r\n    p->cache = (Byte)((UInt32)p->low >> 24);\r\n  }\r\n  p->cacheSize++;\r\n  p->low = (UInt32)p->low << 8;\r\n}\r\n\r\nstatic void RangeEnc_FlushData(CRangeEnc *p)\r\n{\r\n  int i;\r\n  for (i = 0; i < 5; i++)\r\n    RangeEnc_ShiftLow(p);\r\n}\r\n\r\nstatic void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)\r\n{\r\n  do\r\n  {\r\n    p->range >>= 1;\r\n    p->low += p->range & (0 - ((value >> --numBits) & 1));\r\n    if (p->range < kTopValue)\r\n    {\r\n      p->range <<= 8;\r\n      RangeEnc_ShiftLow(p);\r\n    }\r\n  }\r\n  while (numBits != 0);\r\n}\r\n\r\nstatic void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)\r\n{\r\n  UInt32 ttt = *prob;\r\n  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;\r\n  if (symbol == 0)\r\n  {\r\n    p->range = newBound;\r\n    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;\r\n  }\r\n  else\r\n  {\r\n    p->low += newBound;\r\n    p->range -= newBound;\r\n    ttt -= ttt >> kNumMoveBits;\r\n  }\r\n  *prob = (CLzmaProb)ttt;\r\n  if (p->range < kTopValue)\r\n  {\r\n    p->range <<= 8;\r\n    RangeEnc_ShiftLow(p);\r\n  }\r\n}\r\n\r\nstatic void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)\r\n{\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nstatic void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)\r\n{\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nvoid LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\r\n{\r\n  UInt32 i;\r\n  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))\r\n  {\r\n    const int kCyclesBits = kNumBitPriceShiftBits;\r\n    UInt32 w = i;\r\n    UInt32 bitCount = 0;\r\n    int j;\r\n    for (j = 0; j < kCyclesBits; j++)\r\n    {\r\n      w = w * w;\r\n      bitCount <<= 1;\r\n      while (w >= ((UInt32)1 << 16))\r\n      {\r\n        w >>= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);\r\n  }\r\n}\r\n\r\n\r\n#define GET_PRICE(prob, symbol) \\\r\n  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICEa(prob, symbol) \\\r\n  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\n#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\nstatic UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\nstatic UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\n\r\nstatic void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0;)\r\n  {\r\n    UInt32 bit;\r\n    i--;\r\n    bit = (symbol >> i) & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n}\r\n\r\nstatic void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = 0; i < numBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= (1 << numBitLevels);\r\n  while (symbol != 1)\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);\r\n    symbol >>= 1;\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += GET_PRICEa(probs[m], bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\n\r\nstatic void LenEnc_Init(CLenEnc *p)\r\n{\r\n  unsigned i;\r\n  p->choice = p->choice2 = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)\r\n    p->low[i] = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)\r\n    p->mid[i] = kProbInitValue;\r\n  for (i = 0; i < kLenNumHighSymbols; i++)\r\n    p->high[i] = kProbInitValue;\r\n}\r\n\r\nstatic void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)\r\n{\r\n  if (symbol < kLenNumLowSymbols)\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 0);\r\n    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);\r\n  }\r\n  else\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 1);\r\n    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 0);\r\n      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 1);\r\n      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)\r\n{\r\n  UInt32 a0 = GET_PRICE_0a(p->choice);\r\n  UInt32 a1 = GET_PRICE_1a(p->choice);\r\n  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);\r\n  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kLenNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);\r\n  }\r\n  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);\r\n}\r\n\r\nstatic void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);\r\n  p->counters[posState] = p->tableSize;\r\n}\r\n\r\nstatic void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)\r\n{\r\n  UInt32 posState;\r\n  for (posState = 0; posState < numPosStates; posState++)\r\n    LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\nstatic void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_Encode(&p->p, rc, symbol, posState);\r\n  if (updatePrice)\r\n    if (--p->counters[posState] == 0)\r\n      LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\n\r\n\r\n\r\nstatic void MovePos(CLzmaEnc *p, UInt32 num)\r\n{\r\n  #ifdef SHOW_STAT\r\n  ttt += num;\r\n  printf(\"\\n MovePos %d\", num);\r\n  #endif\r\n  if (num != 0)\r\n  {\r\n    p->additionalOffset += num;\r\n    p->matchFinder.Skip(p->matchFinderObj, num);\r\n  }\r\n}\r\n\r\nstatic UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)\r\n{\r\n  UInt32 lenRes = 0, numPairs;\r\n  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);\r\n  #ifdef SHOW_STAT\r\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numPairs / 2);\r\n  ttt++;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < numPairs; i += 2)\r\n      printf(\"%2d %6d   | \", p->matches[i], p->matches[i + 1]);\r\n  }\r\n  #endif\r\n  if (numPairs > 0)\r\n  {\r\n    lenRes = p->matches[numPairs - 2];\r\n    if (lenRes == p->numFastBytes)\r\n    {\r\n      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n      UInt32 distance = p->matches[numPairs - 1] + 1;\r\n      UInt32 numAvail = p->numAvail;\r\n      if (numAvail > LZMA_MATCH_LEN_MAX)\r\n        numAvail = LZMA_MATCH_LEN_MAX;\r\n      {\r\n        const Byte *pby2 = pby - distance;\r\n        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r\n      }\r\n    }\r\n  }\r\n  p->additionalOffset++;\r\n  *numDistancePairsRes = numPairs;\r\n  return lenRes;\r\n}\r\n\r\n\r\n#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;\r\n#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;\r\n#define IsShortRep(p) ((p)->backPrev == 0)\r\n\r\nstatic UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)\r\n{\r\n  return\r\n    GET_PRICE_0(p->isRepG0[state]) +\r\n    GET_PRICE_0(p->isRep0Long[state][posState]);\r\n}\r\n\r\nstatic UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)\r\n{\r\n  UInt32 price;\r\n  if (repIndex == 0)\r\n  {\r\n    price = GET_PRICE_0(p->isRepG0[state]);\r\n    price += GET_PRICE_1(p->isRep0Long[state][posState]);\r\n  }\r\n  else\r\n  {\r\n    price = GET_PRICE_1(p->isRepG0[state]);\r\n    if (repIndex == 1)\r\n      price += GET_PRICE_0(p->isRepG1[state]);\r\n    else\r\n    {\r\n      price += GET_PRICE_1(p->isRepG1[state]);\r\n      price += GET_PRICE(p->isRepG2[state], repIndex - 2);\r\n    }\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)\r\n{\r\n  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +\r\n    GetPureRepPrice(p, repIndex, state, posState);\r\n}\r\n\r\nstatic UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)\r\n{\r\n  UInt32 posMem = p->opt[cur].posPrev;\r\n  UInt32 backMem = p->opt[cur].backPrev;\r\n  p->optimumEndIndex = cur;\r\n  do\r\n  {\r\n    if (p->opt[cur].prev1IsChar)\r\n    {\r\n      MakeAsChar(&p->opt[posMem])\r\n      p->opt[posMem].posPrev = posMem - 1;\r\n      if (p->opt[cur].prev2)\r\n      {\r\n        p->opt[posMem - 1].prev1IsChar = False;\r\n        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;\r\n        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;\r\n      }\r\n    }\r\n    {\r\n      UInt32 posPrev = posMem;\r\n      UInt32 backCur = backMem;\r\n      \r\n      backMem = p->opt[posPrev].backPrev;\r\n      posMem = p->opt[posPrev].posPrev;\r\n      \r\n      p->opt[posPrev].backPrev = backCur;\r\n      p->opt[posPrev].posPrev = cur;\r\n      cur = posPrev;\r\n    }\r\n  }\r\n  while (cur != 0);\r\n  *backRes = p->opt[0].backPrev;\r\n  p->optimumCurrentIndex  = p->opt[0].posPrev;\r\n  return p->optimumCurrentIndex;\r\n}\r\n\r\n#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)\r\n\r\nstatic UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;\r\n  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\r\n  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];\r\n  UInt32 *matches;\r\n  const Byte *data;\r\n  Byte curByte, matchByte;\r\n  if (p->optimumEndIndex != p->optimumCurrentIndex)\r\n  {\r\n    const COptimal *opt = &p->opt[p->optimumCurrentIndex];\r\n    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;\r\n    *backRes = opt->backPrev;\r\n    p->optimumCurrentIndex = opt->posPrev;\r\n    return lenRes;\r\n  }\r\n  p->optimumCurrentIndex = p->optimumEndIndex = 0;\r\n  \r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  if (numAvail < 2)\r\n  {\r\n    *backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  repMaxIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 lenTest;\r\n    const Byte *data2;\r\n    reps[i] = p->reps[i];\r\n    data2 = data - (reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if (repLens[repMaxIndex] >= p->numFastBytes)\r\n  {\r\n    UInt32 lenRes;\r\n    *backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    MovePos(p, lenRes - 1);\r\n    return lenRes;\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n  curByte = *data;\r\n  matchByte = *(data - (reps[0] + 1));\r\n\r\n  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    *backRes = (UInt32)-1;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[0].state = (CState)p->state;\r\n\r\n  posState = (position & p->pbMask);\r\n\r\n  {\r\n    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +\r\n        (!IsCharState(p->state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n  }\r\n\r\n  MakeAsChar(&p->opt[1]);\r\n\r\n  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);\r\n  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);\r\n\r\n  if (matchByte == curByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);\r\n    if (shortRepPrice < p->opt[1].price)\r\n    {\r\n      p->opt[1].price = shortRepPrice;\r\n      MakeAsShortRep(&p->opt[1]);\r\n    }\r\n  }\r\n  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);\r\n\r\n  if (lenEnd < 2)\r\n  {\r\n    *backRes = p->opt[1].backPrev;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[1].posPrev = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n    p->opt[0].backs[i] = reps[i];\r\n\r\n  len = lenEnd;\r\n  do\r\n    p->opt[len--].price = kInfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    UInt32 price;\r\n    if (repLen < 2)\r\n      continue;\r\n    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];\r\n      COptimal *opt = &p->opt[repLen];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = i;\r\n        opt->prev1IsChar = False;\r\n      }\r\n    }\r\n    while (--repLen >= 2);\r\n  }\r\n\r\n  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= mainLen)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matches[offs])\r\n      offs += 2;\r\n    for (; ; len++)\r\n    {\r\n      COptimal *opt;\r\n      UInt32 distance = matches[offs + 1];\r\n\r\n      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];\r\n      UInt32 lenToPosState = GetLenToPosState(len);\r\n      if (distance < kNumFullDistances)\r\n        curAndLenPrice += p->distancesPrices[lenToPosState][distance];\r\n      else\r\n      {\r\n        UInt32 slot;\r\n        GetPosSlot2(distance, slot);\r\n        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];\r\n      }\r\n      opt = &p->opt[len];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = distance + LZMA_NUM_REPS;\r\n        opt->prev1IsChar = False;\r\n      }\r\n      if (len == matches[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numPairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  cur = 0;\r\n\r\n    #ifdef SHOW_STAT2\r\n    if (position >= 0)\r\n    {\r\n      unsigned i;\r\n      printf(\"\\n pos = %4X\", position);\r\n      for (i = cur; i <= lenEnd; i++)\r\n      printf(\"\\nprice[%4X] = %d\", position - cur + i, p->opt[i].price);\r\n    }\r\n    #endif\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;\r\n    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;\r\n    Bool nextIsChar;\r\n    Byte curByte, matchByte;\r\n    const Byte *data;\r\n    COptimal *curOpt;\r\n    COptimal *nextOpt;\r\n\r\n    cur++;\r\n    if (cur == lenEnd)\r\n      return Backward(p, backRes, cur);\r\n\r\n    newLen = ReadMatchDistances(p, &numPairs);\r\n    if (newLen >= p->numFastBytes)\r\n    {\r\n      p->numPairs = numPairs;\r\n      p->longestMatchLength = newLen;\r\n      return Backward(p, backRes, cur);\r\n    }\r\n    position++;\r\n    curOpt = &p->opt[cur];\r\n    posPrev = curOpt->posPrev;\r\n    if (curOpt->prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOpt->prev2)\r\n      {\r\n        state = p->opt[curOpt->posPrev2].state;\r\n        if (curOpt->backPrev2 < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      else\r\n        state = p->opt[posPrev].state;\r\n      state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n      state = p->opt[posPrev].state;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (IsShortRep(curOpt))\r\n        state = kShortRepNextStates[state];\r\n      else\r\n        state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      const COptimal *prevOpt;\r\n      if (curOpt->prev1IsChar && curOpt->prev2)\r\n      {\r\n        posPrev = curOpt->posPrev2;\r\n        pos = curOpt->backPrev2;\r\n        state = kRepNextStates[state];\r\n      }\r\n      else\r\n      {\r\n        pos = curOpt->backPrev;\r\n        if (pos < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      prevOpt = &p->opt[posPrev];\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        UInt32 i;\r\n        reps[0] = prevOpt->backs[pos];\r\n        for (i = 1; i <= pos; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n        for (; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i];\r\n      }\r\n      else\r\n      {\r\n        UInt32 i;\r\n        reps[0] = (pos - LZMA_NUM_REPS);\r\n        for (i = 1; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n      }\r\n    }\r\n    curOpt->state = (CState)state;\r\n\r\n    curOpt->backs[0] = reps[0];\r\n    curOpt->backs[1] = reps[1];\r\n    curOpt->backs[2] = reps[2];\r\n    curOpt->backs[3] = reps[3];\r\n\r\n    curPrice = curOpt->price;\r\n    nextIsChar = False;\r\n    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n    curByte = *data;\r\n    matchByte = *(data - (reps[0] + 1));\r\n\r\n    posState = (position & p->pbMask);\r\n\r\n    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);\r\n    {\r\n      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n      curAnd1Price +=\r\n        (!IsCharState(state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n    }\r\n\r\n    nextOpt = &p->opt[cur + 1];\r\n\r\n    if (curAnd1Price < nextOpt->price)\r\n    {\r\n      nextOpt->price = curAnd1Price;\r\n      nextOpt->posPrev = cur;\r\n      MakeAsChar(nextOpt);\r\n      nextIsChar = True;\r\n    }\r\n\r\n    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);\r\n    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);\r\n    \r\n    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);\r\n      if (shortRepPrice <= nextOpt->price)\r\n      {\r\n        nextOpt->price = shortRepPrice;\r\n        nextOpt->posPrev = cur;\r\n        MakeAsShortRep(nextOpt);\r\n        nextIsChar = True;\r\n      }\r\n    }\r\n    numAvailFull = p->numAvail;\r\n    {\r\n      UInt32 temp = kNumOpts - 1 - cur;\r\n      if (temp < numAvailFull)\r\n        numAvailFull = temp;\r\n    }\r\n\r\n    if (numAvailFull < 2)\r\n      continue;\r\n    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);\r\n\r\n    if (!nextIsChar && matchByte != curByte) /* speed optimization */\r\n    {\r\n      /* try Literal + rep0 */\r\n      UInt32 temp;\r\n      UInt32 lenTest2;\r\n      const Byte *data2 = data - (reps[0] + 1);\r\n      UInt32 limit = p->numFastBytes + 1;\r\n      if (limit > numAvailFull)\r\n        limit = numAvailFull;\r\n\r\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r\n      lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        UInt32 state2 = kLiteralNextStates[state];\r\n        UInt32 posStateNext = (position + 1) & p->pbMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price +\r\n            GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n            GET_PRICE_1(p->isRep[state2]);\r\n        /* for (; lenTest2 >= 2; lenTest2--) */\r\n        {\r\n          UInt32 curAndLenPrice;\r\n          COptimal *opt;\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while (lenEnd < offset)\r\n            p->opt[++lenEnd].price = kInfinityPrice;\r\n          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n          opt = &p->opt[offset];\r\n          if (curAndLenPrice < opt->price)\r\n          {\r\n            opt->price = curAndLenPrice;\r\n            opt->posPrev = cur + 1;\r\n            opt->backPrev = 0;\r\n            opt->prev1IsChar = True;\r\n            opt->prev2 = False;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    startLen = 2; /* speed optimization */\r\n    {\r\n    UInt32 repIndex;\r\n    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)\r\n    {\r\n      UInt32 lenTest;\r\n      UInt32 lenTestTemp;\r\n      UInt32 price;\r\n      const Byte *data2 = data - (reps[repIndex] + 1);\r\n      if (data[0] != data2[0] || data[1] != data2[1])\r\n        continue;\r\n      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n      while (lenEnd < cur + lenTest)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n      lenTestTemp = lenTest;\r\n      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];\r\n        COptimal *opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = repIndex;\r\n          opt->prev1IsChar = False;\r\n        }\r\n      }\r\n      while (--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      /* if (_maxMode) */\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kRepNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice =\r\n                price + p->repLenEnc.prices[posState][lenTest - 2] +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (position + lenTest + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n    }\r\n    }\r\n    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */\r\n    if (newLen > numAvail)\r\n    {\r\n      newLen = numAvail;\r\n      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);\r\n      matches[numPairs] = newLen;\r\n      numPairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\r\n      UInt32 offs, curBack, posSlot;\r\n      UInt32 lenTest;\r\n      while (lenEnd < cur + newLen)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n\r\n      offs = 0;\r\n      while (startLen > matches[offs])\r\n        offs += 2;\r\n      curBack = matches[offs + 1];\r\n      GetPosSlot2(curBack, posSlot);\r\n      for (lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        COptimal *opt;\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];\r\n        \r\n        opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = curBack + LZMA_NUM_REPS;\r\n          opt->prev1IsChar = False;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matches[offs])\r\n        {\r\n          /* Try Match + Literal + Rep0 */\r\n          const Byte *data2 = data - (curBack + 1);\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kMatchNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (posStateNext + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = curBack + LZMA_NUM_REPS;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numPairs)\r\n            break;\r\n          curBack = matches[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            GetPosSlot2(curBack, posSlot);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))\r\n\r\nstatic UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;\r\n  const Byte *data;\r\n  const UInt32 *matches;\r\n\r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  *backRes = (UInt32)-1;\r\n  if (numAvail < 2)\r\n    return 1;\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n\r\n  repLen = repIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    for (len = 2; len < numAvail && data[len] == data2[len]; len++);\r\n    if (len >= p->numFastBytes)\r\n    {\r\n      *backRes = i;\r\n      MovePos(p, len - 1);\r\n      return len;\r\n    }\r\n    if (len > repLen)\r\n    {\r\n      repIndex = i;\r\n      repLen = len;\r\n    }\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n\r\n  mainDist = 0; /* for GCC */\r\n  if (mainLen >= 2)\r\n  {\r\n    mainDist = matches[numPairs - 1];\r\n    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matches[numPairs - 3], mainDist))\r\n        break;\r\n      numPairs -= 2;\r\n      mainLen = matches[numPairs - 2];\r\n      mainDist = matches[numPairs - 1];\r\n    }\r\n    if (mainLen == 2 && mainDist >= 0x80)\r\n      mainLen = 1;\r\n  }\r\n\r\n  if (repLen >= 2 && (\r\n        (repLen + 1 >= mainLen) ||\r\n        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||\r\n        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))\r\n  {\r\n    *backRes = repIndex;\r\n    MovePos(p, repLen - 1);\r\n    return repLen;\r\n  }\r\n  \r\n  if (mainLen < 2 || numAvail <= 2)\r\n    return 1;\r\n\r\n  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);\r\n  if (p->longestMatchLength >= 2)\r\n  {\r\n    UInt32 newDistance = matches[p->numPairs - 1];\r\n    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||\r\n        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||\r\n        (p->longestMatchLength > mainLen + 1) ||\r\n        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))\r\n      return 1;\r\n  }\r\n  \r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len, limit;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    limit = mainLen - 1;\r\n    for (len = 2; len < limit && data[len] == data2[len]; len++);\r\n    if (len >= limit)\r\n      return 1;\r\n  }\r\n  *backRes = mainDist + LZMA_NUM_REPS;\r\n  MovePos(p, mainLen - 2);\r\n  return mainLen;\r\n}\r\n\r\nstatic void WriteEndMarker(CLzmaEnc *p, UInt32 posState)\r\n{\r\n  UInt32 len;\r\n  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n  p->state = kMatchNextStates[p->state];\r\n  len = LZMA_MATCH_LEN_MIN;\r\n  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);\r\n  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);\r\n  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);\r\n}\r\n\r\nstatic SRes CheckErrors(CLzmaEnc *p)\r\n{\r\n  if (p->result != SZ_OK)\r\n    return p->result;\r\n  if (p->rc.res != SZ_OK)\r\n    p->result = SZ_ERROR_WRITE;\r\n  if (p->matchFinderBase.result != SZ_OK)\r\n    p->result = SZ_ERROR_READ;\r\n  if (p->result != SZ_OK)\r\n    p->finished = True;\r\n  return p->result;\r\n}\r\n\r\nstatic SRes Flush(CLzmaEnc *p, UInt32 nowPos)\r\n{\r\n  /* ReleaseMFStream(); */\r\n  p->finished = True;\r\n  if (p->writeEndMark)\r\n    WriteEndMarker(p, nowPos & p->pbMask);\r\n  RangeEnc_FlushData(&p->rc);\r\n  RangeEnc_FlushStream(&p->rc);\r\n  return CheckErrors(p);\r\n}\r\n\r\nstatic void FillAlignPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < kAlignTableSize; i++)\r\n    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);\r\n  p->alignPriceCount = 0;\r\n}\r\n\r\nstatic void FillDistancesPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  UInt32 i, lenToPosState;\r\n  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  {\r\n    UInt32 posSlot = GetPosSlot1(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);\r\n  }\r\n\r\n  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n    UInt32 posSlot;\r\n    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);\r\n    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);\r\n\r\n    {\r\n      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];\r\n      UInt32 i;\r\n      for (i = 0; i < kStartPosModelIndex; i++)\r\n        distancesPrices[i] = posSlotPrices[i];\r\n      for (; i < kNumFullDistances; i++)\r\n        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];\r\n    }\r\n  }\r\n  p->matchPriceCount = 0;\r\n}\r\n\r\nvoid LzmaEnc_Construct(CLzmaEnc *p)\r\n{\r\n  RangeEnc_Construct(&p->rc);\r\n  MatchFinder_Construct(&p->matchFinderBase);\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Construct(&p->matchFinderMt);\r\n  p->matchFinderMt.MatchFinder = &p->matchFinderBase;\r\n  #endif\r\n\r\n  {\r\n    CLzmaEncProps props;\r\n    LzmaEncProps_Init(&props);\r\n    LzmaEnc_SetProps(p, &props);\r\n  }\r\n\r\n  #ifndef LZMA_LOG_BSR\r\n  LzmaEnc_FastPosInit(p->g_FastPos);\r\n  #endif\r\n\r\n  LzmaEnc_InitPriceTables(p->ProbPrices);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)\r\n{\r\n  void *p;\r\n  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));\r\n  if (p != 0)\r\n    LzmaEnc_Construct((CLzmaEnc *)p);\r\n  return p;\r\n}\r\n\r\nvoid LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->litProbs);\r\n  alloc->Free(alloc, p->saveState.litProbs);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nvoid LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);\r\n  #endif\r\n  MatchFinder_Free(&p->matchFinderBase, allocBig);\r\n  LzmaEnc_FreeLits(p, alloc);\r\n  RangeEnc_Free(&p->rc, alloc);\r\n}\r\n\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);\r\n  alloc->Free(alloc, p);\r\n}\r\n\r\nstatic SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)\r\n{\r\n  UInt32 nowPos32, startPos32;\r\n  if (p->inStream != 0)\r\n  {\r\n    p->matchFinderBase.stream = p->inStream;\r\n    p->matchFinder.Init(p->matchFinderObj);\r\n    p->inStream = 0;\r\n  }\r\n\r\n  if (p->finished)\r\n    return p->result;\r\n  RINOK(CheckErrors(p));\r\n\r\n  nowPos32 = (UInt32)p->nowPos64;\r\n  startPos32 = nowPos32;\r\n\r\n  if (p->nowPos64 == 0)\r\n  {\r\n    UInt32 numPairs;\r\n    Byte curByte;\r\n    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n      return Flush(p, nowPos32);\r\n    ReadMatchDistances(p, &numPairs);\r\n    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);\r\n    p->state = kLiteralNextStates[p->state];\r\n    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);\r\n    LitEnc_Encode(&p->rc, p->litProbs, curByte);\r\n    p->additionalOffset--;\r\n    nowPos32++;\r\n  }\r\n\r\n  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)\r\n  for (;;)\r\n  {\r\n    UInt32 pos, len, posState;\r\n\r\n    if (p->fastMode)\r\n      len = GetOptimumFast(p, &pos);\r\n    else\r\n      len = GetOptimum(p, nowPos32, &pos);\r\n\r\n    #ifdef SHOW_STAT2\r\n    printf(\"\\n pos = %4X,   len = %d   pos = %d\", nowPos32, len, pos);\r\n    #endif\r\n\r\n    posState = nowPos32 & p->pbMask;\r\n    if (len == 1 && pos == (UInt32)-1)\r\n    {\r\n      Byte curByte;\r\n      CLzmaProb *probs;\r\n      const Byte *data;\r\n\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);\r\n      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n      curByte = *data;\r\n      probs = LIT_PROBS(nowPos32, *(data - 1));\r\n      if (IsCharState(p->state))\r\n        LitEnc_Encode(&p->rc, probs, curByte);\r\n      else\r\n        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));\r\n      p->state = kLiteralNextStates[p->state];\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);\r\n        if (pos == 0)\r\n        {\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = p->reps[pos];\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);\r\n          if (pos == 1)\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);\r\n          else\r\n          {\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);\r\n            if (pos == 3)\r\n              p->reps[3] = p->reps[2];\r\n            p->reps[2] = p->reps[1];\r\n          }\r\n          p->reps[1] = p->reps[0];\r\n          p->reps[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          p->state = kShortRepNextStates[p->state];\r\n        else\r\n        {\r\n          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n          p->state = kRepNextStates[p->state];\r\n        }\r\n      }\r\n      else\r\n      {\r\n        UInt32 posSlot;\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n        p->state = kMatchNextStates[p->state];\r\n        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n        pos -= LZMA_NUM_REPS;\r\n        GetPosSlot(pos, posSlot);\r\n        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);\r\n          else\r\n          {\r\n            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);\r\n            p->alignPriceCount++;\r\n          }\r\n        }\r\n        p->reps[3] = p->reps[2];\r\n        p->reps[2] = p->reps[1];\r\n        p->reps[1] = p->reps[0];\r\n        p->reps[0] = pos;\r\n        p->matchPriceCount++;\r\n      }\r\n    }\r\n    p->additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (p->additionalOffset == 0)\r\n    {\r\n      UInt32 processed;\r\n      if (!p->fastMode)\r\n      {\r\n        if (p->matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices(p);\r\n        if (p->alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices(p);\r\n      }\r\n      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n        break;\r\n      processed = nowPos32 - startPos32;\r\n      if (useLimits)\r\n      {\r\n        if (processed + kNumOpts + 300 >= maxUnpackSize ||\r\n            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)\r\n          break;\r\n      }\r\n      else if (processed >= (1 << 15))\r\n      {\r\n        p->nowPos64 += nowPos32 - startPos32;\r\n        return CheckErrors(p);\r\n      }\r\n    }\r\n  }\r\n  p->nowPos64 += nowPos32 - startPos32;\r\n  return Flush(p, nowPos32);\r\n}\r\n\r\n#define kBigHashDicLimit ((UInt32)1 << 24)\r\n\r\nstatic SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 beforeSize = kNumOpts;\r\n  Bool btMode;\r\n  if (!RangeEnc_Alloc(&p->rc, alloc))\r\n    return SZ_ERROR_MEM;\r\n  btMode = (p->matchFinderBase.btMode != 0);\r\n  #ifdef COMPRESS_MF_MT\r\n  p->mtMode = (p->multiThread && !p->fastMode && btMode);\r\n  #endif\r\n\r\n  {\r\n    unsigned lclp = p->lc + p->lp;\r\n    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)\r\n    {\r\n      LzmaEnc_FreeLits(p, alloc);\r\n      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      if (p->litProbs == 0 || p->saveState.litProbs == 0)\r\n      {\r\n        LzmaEnc_FreeLits(p, alloc);\r\n        return SZ_ERROR_MEM;\r\n      }\r\n      p->lclp = lclp;\r\n    }\r\n  }\r\n\r\n  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);\r\n\r\n  if (beforeSize + p->dictSize < keepWindowSize)\r\n    beforeSize = keepWindowSize - p->dictSize;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (p->mtMode)\r\n  {\r\n    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));\r\n    p->matchFinderObj = &p->matchFinderMt;\r\n    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))\r\n      return SZ_ERROR_MEM;\r\n    p->matchFinderObj = &p->matchFinderBase;\r\n    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nvoid LzmaEnc_Init(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  p->state = 0;\r\n  for (i = 0 ; i < LZMA_NUM_REPS; i++)\r\n    p->reps[i] = 0;\r\n\r\n  RangeEnc_Init(&p->rc);\r\n\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    UInt32 j;\r\n    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)\r\n    {\r\n      p->isMatch[i][j] = kProbInitValue;\r\n      p->isRep0Long[i][j] = kProbInitValue;\r\n    }\r\n    p->isRep[i] = kProbInitValue;\r\n    p->isRepG0[i] = kProbInitValue;\r\n    p->isRepG1[i] = kProbInitValue;\r\n    p->isRepG2[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    UInt32 num = 0x300 << (p->lp + p->lc);\r\n    for (i = 0; i < num; i++)\r\n      p->litProbs[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    for (i = 0; i < kNumLenToPosStates; i++)\r\n    {\r\n      CLzmaProb *probs = p->posSlotEncoder[i];\r\n      UInt32 j;\r\n      for (j = 0; j < (1 << kNumPosSlotBits); j++)\r\n        probs[j] = kProbInitValue;\r\n    }\r\n  }\r\n  {\r\n    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      p->posEncoders[i] = kProbInitValue;\r\n  }\r\n\r\n  LenEnc_Init(&p->lenEnc.p);\r\n  LenEnc_Init(&p->repLenEnc.p);\r\n\r\n  for (i = 0; i < (1 << kNumAlignBits); i++)\r\n    p->posAlignEncoder[i] = kProbInitValue;\r\n\r\n  p->optimumEndIndex = 0;\r\n  p->optimumCurrentIndex = 0;\r\n  p->additionalOffset = 0;\r\n\r\n  p->pbMask = (1 << p->pb) - 1;\r\n  p->lpMask = (1 << p->lp) - 1;\r\n}\r\n\r\nvoid LzmaEnc_InitPrices(CLzmaEnc *p)\r\n{\r\n  if (!p->fastMode)\r\n  {\r\n    FillDistancesPrices(p);\r\n    FillAlignPrices(p);\r\n  }\r\n\r\n  p->lenEnc.tableSize =\r\n  p->repLenEnc.tableSize =\r\n      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;\r\n  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);\r\n  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);\r\n}\r\n\r\nstatic SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)\r\n    if (p->dictSize <= ((UInt32)1 << i))\r\n      break;\r\n  p->distTableSize = i * 2;\r\n\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));\r\n  LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  p->nowPos64 = 0;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  p->rc.outStream = outStream;\r\n  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);\r\n}\r\n\r\nSRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,\r\n    ISeqInStream *inStream, UInt32 keepWindowSize,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nstatic void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)\r\n{\r\n  p->seqBufInStream.funcTable.Read = MyRead;\r\n  p->seqBufInStream.data = src;\r\n  p->seqBufInStream.rem = srcLen;\r\n}\r\n\r\nSRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\r\n    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n  p->inStream = &p->seqBufInStream.funcTable;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nvoid LzmaEnc_Finish(CLzmaEncHandle pp)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  if (p->mtMode)\r\n    MatchFinderMt_ReleaseStream(&p->matchFinderMt);\r\n  #else\r\n  pp = pp;\r\n  #endif\r\n}\r\n\r\ntypedef struct _CSeqOutStreamBuf\r\n{\r\n  ISeqOutStream funcTable;\r\n  Byte *data;\r\n  SizeT rem;\r\n  Bool overflow;\r\n} CSeqOutStreamBuf;\r\n\r\nstatic size_t MyWrite(void *pp, const void *data, size_t size)\r\n{\r\n  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;\r\n  if (p->rem < size)\r\n  {\r\n    size = p->rem;\r\n    p->overflow = True;\r\n  }\r\n  memcpy(p->data, data, size);\r\n  p->rem -= size;\r\n  p->data += size;\r\n  return size;\r\n}\r\n\r\n\r\nUInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n}\r\n\r\nconst Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n}\r\n\r\nSRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\r\n    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  UInt64 nowPos64;\r\n  SRes res;\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = False;\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n\r\n  if (reInit)\r\n    LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  nowPos64 = p->nowPos64;\r\n  RangeEnc_Init(&p->rc);\r\n  p->rc.outStream = &outStream.funcTable;\r\n\r\n  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);\r\n  \r\n  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  SRes res = SZ_OK;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte allocaDummy[0x300];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  #endif\r\n\r\n  RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));\r\n\r\n  for (;;)\r\n  {\r\n    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);\r\n    if (res != SZ_OK || p->finished != 0)\r\n      break;\r\n    if (progress != 0)\r\n    {\r\n      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));\r\n      if (res != SZ_OK)\r\n      {\r\n        res = SZ_ERROR_PROGRESS;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  LzmaEnc_Finish(pp);\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  int i;\r\n  UInt32 dictSize = p->dictSize;\r\n  if (*size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_PARAM;\r\n  *size = LZMA_PROPS_SIZE;\r\n  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);\r\n\r\n  for (i = 11; i <= 30; i++)\r\n  {\r\n    if (dictSize <= ((UInt32)2 << i))\r\n    {\r\n      dictSize = (2 << i);\r\n      break;\r\n    }\r\n    if (dictSize <= ((UInt32)3 << i))\r\n    {\r\n      dictSize = (3 << i);\r\n      break;\r\n    }\r\n  }\r\n\r\n  for (i = 0; i < 4; i++)\r\n    props[1 + i] = (Byte)(dictSize >> (8 * i));\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  SRes res;\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = writeEndMark;\r\n  res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,\r\n      progress, alloc, allocBig);\r\n\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n  return res;\r\n}\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);\r\n  SRes res;\r\n  if (p == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LzmaEnc_SetProps(p, props);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);\r\n    if (res == SZ_OK)\r\n      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,\r\n          writeEndMark, progress, alloc, allocBig);\r\n  }\r\n\r\n  LzmaEnc_Destroy(p, alloc, allocBig);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaEnc.h",
    "content": "/*  LzmaEnc.h -- LZMA Encoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMAENC_H\r\n#define __LZMAENC_H\r\n\r\n#include \"Types.h\"\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaEncProps\r\n{\r\n  int level;       /*  0 <= level <= 9 */\r\n  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version\r\n                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version\r\n                       default = (1 << 24) */\r\n  int lc;          /* 0 <= lc <= 8, default = 3 */\r\n  int lp;          /* 0 <= lp <= 4, default = 0 */\r\n  int pb;          /* 0 <= pb <= 4, default = 2 */\r\n  int algo;        /* 0 - fast, 1 - normal, default = 1 */\r\n  int fb;          /* 5 <= fb <= 273, default = 32 */\r\n  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */\r\n  int numHashBytes; /* 2, 3 or 4, default = 4 */\r\n  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */\r\n  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */\r\n  int numThreads;  /* 1 or 2, default = 2 */\r\n} CLzmaEncProps;\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p);\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p);\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);\r\n\r\n\r\n/* ---------- CLzmaEncHandle Interface ---------- */\r\n\r\n/* LzmaEnc_* functions can return the following exit codes:\r\nReturns:\r\n  SZ_OK           - OK\r\n  SZ_ERROR_MEM    - Memory allocation error\r\n  SZ_ERROR_PARAM  - Incorrect paramater in props\r\n  SZ_ERROR_WRITE  - Write callback error.\r\n  SZ_ERROR_PROGRESS - some break from progress callback\r\n  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\ntypedef void * CLzmaEncHandle;\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);\r\nSRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaEncode\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaLib/LzmaLib.def",
    "content": "EXPORTS\r\n  LzmaCompress\r\n  LzmaUncompress\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaLib/LzmaLib.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaLib\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n\r\nCFG=LzmaLib - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaLib.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaLib.mak\" CFG=\"LzmaLib - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"LzmaLib - Win32 Release\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n!MESSAGE \"LzmaLib - Win32 Debug\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nMTL=midl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"LzmaLib - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /c\r\n# ADD CPP /nologo /Gr /MT /W3 /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"LzmaLib - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /GZ /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"LzmaLib - Win32 Release\"\r\n# Name \"LzmaLib - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaLib.def\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaLibExports.c\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaLib.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaLib.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Types.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaLib/LzmaLib.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"LzmaLib\"=.\\LzmaLib.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaLib/LzmaLibExports.c",
    "content": "/* LzmaLibExports.c -- LZMA library DLL Entry point\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <windows.h>\r\n\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r\n{\r\n  hInstance = hInstance;\r\n  dwReason = dwReason;\r\n  lpReserved = lpReserved;\r\n  return TRUE;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaLib/makefile",
    "content": "MY_STATIC_LINK=1\r\nSLIB = sLZMA.lib\r\nPROG = LZMA.dll\r\nSLIBPATH = $O\\$(SLIB)\r\n\r\nDEF_FILE = LzmaLib.def\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n\r\nLIBS = $(LIBS) oleaut32.lib\r\n\r\nLIB_OBJS = \\\r\n  $O\\LzmaLibExports.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\LzmaLib.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $(LIB_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n!include \"../../CPP/Build.mak\"\r\n\r\n$(SLIBPATH): $O $(OBJS)\r\n\tlib -out:$(SLIBPATH) $(OBJS) $(LIBS)\r\n\r\n$(LIB_OBJS): $(*B).c\r\n\t$(COMPL_O2)\r\n$(C_OBJS): ../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaLib/resource.rc",
    "content": "#include \"../../CPP/7zip/MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"LZMA library\", \"LZMA\")\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaLib.c",
    "content": "/* LzmaLib.c -- LZMA library wrapper\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"LzmaEnc.h\"\r\n#include \"LzmaDec.h\"\r\n#include \"Alloc.h\"\r\n#include \"LzmaLib.h\"\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  srcLen,\r\n  unsigned char *outProps, size_t *outPropsSize,\r\n  int level, /* 0 <= level <= 9, default = 5 */\r\n  unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */\r\n  int lc, /* 0 <= lc <= 8, default = 3  */\r\n  int lp, /* 0 <= lp <= 4, default = 0  */\r\n  int pb, /* 0 <= pb <= 4, default = 2  */\r\n  int fb,  /* 5 <= fb <= 273, default = 32 */\r\n  int numThreads /* 1 or 2, default = 2 */\r\n)\r\n{\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n  props.level = level;\r\n  props.dictSize = dictSize;\r\n  props.lc = lc;\r\n  props.lp = lp;\r\n  props.pb = pb;\r\n  props.fb = fb;\r\n  props.numThreads = numThreads;\r\n\r\n  return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,\r\n      NULL, &g_Alloc, &g_Alloc);\r\n}\r\n\r\n\r\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  *srcLen,\r\n  const unsigned char *props, size_t propsSize)\r\n{\r\n  ELzmaStatus status;\r\n  return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaLib.h",
    "content": "/* LzmaLib.h -- LZMA library interface\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMALIB_H\r\n#define __LZMALIB_H\r\n\r\n#include \"Types.h\"\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\n/*\r\nRAM requirements for LZMA:\r\n  for compression:   (dictSize * 11.5 + 6 MB) + state_size\r\n  for decompression: dictSize + state_size\r\n    state_size = (4 + (1.5 << (lc + lp))) KB\r\n    by default (lc=3, lp=0), state_size = 16 KB.\r\n\r\nLZMA properties (5 bytes) format\r\n    Offset Size  Description\r\n      0     1    lc, lp and pb in encoded form.\r\n      1     4    dictSize (little endian).\r\n*/\r\n\r\n/*\r\nLzmaCompress\r\n------------\r\n\r\noutPropsSize -\r\n     In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r\n     Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r\n\r\n  LZMA Encoder will use defult values for any parameter, if it is\r\n  -1  for any from: level, loc, lp, pb, fb, numThreads\r\n   0  for dictSize\r\n  \r\nlevel - compression level: 0 <= level <= 9;\r\n\r\n  level dictSize algo  fb\r\n    0:    16 KB   0    32\r\n    1:    64 KB   0    32\r\n    2:   256 KB   0    32\r\n    3:     1 MB   0    32\r\n    4:     4 MB   0    32\r\n    5:    16 MB   1    32\r\n    6:    32 MB   1    32\r\n    7+:   64 MB   1    64\r\n \r\n  The default value for \"level\" is 5.\r\n\r\n  algo = 0 means fast method\r\n  algo = 1 means normal method\r\n\r\ndictSize - The dictionary size in bytes. The maximum value is\r\n        128 MB = (1 << 27) bytes for 32-bit version\r\n          1 GB = (1 << 30) bytes for 64-bit version\r\n     The default value is 16 MB = (1 << 24) bytes.\r\n     It's recommended to use the dictionary that is larger than 4 KB and\r\n     that can be calculated as (1 << N) or (3 << N) sizes.\r\n\r\nlc - The number of literal context bits (high bits of previous literal).\r\n     It can be in the range from 0 to 8. The default value is 3.\r\n     Sometimes lc=4 gives the gain for big files.\r\n\r\nlp - The number of literal pos bits (low bits of current position for literals).\r\n     It can be in the range from 0 to 4. The default value is 0.\r\n     The lp switch is intended for periodical data when the period is equal to 2^lp.\r\n     For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's\r\n     better to set lc=0, if you change lp switch.\r\n\r\npb - The number of pos bits (low bits of current position).\r\n     It can be in the range from 0 to 4. The default value is 2.\r\n     The pb switch is intended for periodical data when the period is equal 2^pb.\r\n\r\nfb - Word size (the number of fast bytes).\r\n     It can be in the range from 5 to 273. The default value is 32.\r\n     Usually, a big number gives a little bit better compression ratio and\r\n     slower compression process.\r\n\r\nnumThreads - The number of thereads. 1 or 2. The default value is 2.\r\n     Fast mode (algo = 0) can use only 1 thread.\r\n\r\nOut:\r\n  destLen  - processed output size\r\nReturns:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,\r\n  unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */\r\n  int level,      /* 0 <= level <= 9, default = 5 */\r\n  unsigned dictSize,  /* default = (1 << 24) */\r\n  int lc,        /* 0 <= lc <= 8, default = 3  */\r\n  int lp,        /* 0 <= lp <= 4, default = 0  */\r\n  int pb,        /* 0 <= pb <= 4, default = 2  */\r\n  int fb,        /* 5 <= fb <= 273, default = 32 */\r\n  int numThreads /* 1 or 2, default = 2 */\r\n  );\r\n\r\n/*\r\nLzmaUncompress\r\n--------------\r\nIn:\r\n  dest     - output data\r\n  destLen  - output data size\r\n  src      - input data\r\n  srcLen   - input data size\r\nOut:\r\n  destLen  - processed output size\r\n  srcLen   - processed input size\r\nReturns:\r\n  SZ_OK                - OK\r\n  SZ_ERROR_DATA        - Data error\r\n  SZ_ERROR_MEM         - Memory allocation arror\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)\r\n*/\r\n\r\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,\r\n  const unsigned char *props, size_t propsSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaUtil/Lzma86Dec.c",
    "content": "/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder\r\n2008-04-07\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"Lzma86Dec.h\"\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../Bra.h\"\r\n#include \"../LzmaDec.h\"\r\n\r\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\r\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)\r\n{\r\n  unsigned i;\r\n  if (srcLen < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n  *unpackSize = 0;\r\n  for (i = 0; i < sizeof(UInt64); i++)\r\n    *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);\r\n  return SZ_OK;\r\n}\r\n\r\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)\r\n{\r\n  SRes res;\r\n  int useFilter;\r\n  SizeT inSizePure;\r\n  ELzmaStatus status;\r\n\r\n  if (*srcLen < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  useFilter = src[0];\r\n\r\n  if (useFilter > 1)\r\n  {\r\n    *destLen = 0;\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  }\r\n\r\n  inSizePure = *srcLen - LZMA86_HEADER_SIZE;\r\n  res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,\r\n      src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);\r\n  *srcLen = inSizePure + LZMA86_HEADER_SIZE;\r\n  if (res != SZ_OK)\r\n    return res;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(dest, *destLen, 0, &x86State, 0);\r\n  }\r\n  return SZ_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaUtil/Lzma86Dec.h",
    "content": "/* Lzma86Dec.h -- LZMA + x86 (BCJ) Filter Decoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMA86DEC_H\r\n#define __LZMA86DEC_H\r\n\r\n#include \"../Types.h\"\r\n\r\n/*\r\nLzma86_GetUnpackSize:\r\n  In:\r\n    src      - input data\r\n    srcLen   - input data size\r\n  Out:\r\n    unpackSize - size of uncompressed stream\r\n  Return code:\r\n    SZ_OK               - OK\r\n    SZ_ERROR_INPUT_EOF  - Error in headers\r\n*/\r\n\r\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);\r\n\r\n/*\r\nLzma86_Decode:\r\n  In:\r\n    dest     - output data\r\n    destLen  - output data size\r\n    src      - input data\r\n    srcLen   - input data size\r\n  Out:\r\n    destLen  - processed output size\r\n    srcLen   - processed input size\r\n  Return code:\r\n    SZ_OK           - OK\r\n    SZ_ERROR_DATA  - Data error\r\n    SZ_ERROR_MEM   - Memory allocation error\r\n    SZ_ERROR_UNSUPPORTED - unsupported file\r\n    SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer\r\n*/\r\n\r\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaUtil/Lzma86Enc.c",
    "content": "/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"Lzma86Enc.h\"\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../Bra.h\"\r\n#include \"../LzmaEnc.h\"\r\n\r\n#define SZE_OUT_OVERFLOW SZE_DATA_ERROR\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\r\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\r\n\r\nint Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r\n    int level, UInt32 dictSize, int filterMode)\r\n{\r\n  size_t outSize2 = *destLen;\r\n  Byte *filteredStream;\r\n  Bool useFilter;\r\n  int mainResult = SZ_ERROR_OUTPUT_EOF;\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n  props.level = level;\r\n  props.dictSize = dictSize;\r\n  \r\n  *destLen = 0;\r\n  if (outSize2 < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  {\r\n    int i;\r\n    UInt64 t = srcLen;\r\n    for (i = 0; i < 8; i++, t >>= 8)\r\n      dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;\r\n  }\r\n\r\n  filteredStream = 0;\r\n  useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (srcLen != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(srcLen);\r\n      if (filteredStream == 0)\r\n        return SZ_ERROR_MEM;\r\n      memcpy(filteredStream, src, srcLen);\r\n    }\r\n    {\r\n      UInt32 x86State;\r\n      x86_Convert_Init(x86State);\r\n      x86_Convert(filteredStream, srcLen, 0, &x86State, 1);\r\n    }\r\n  }\r\n\r\n  {\r\n    size_t minSize = 0;\r\n    Bool bestIsFiltered = False;\r\n\r\n    /* passes for SZ_FILTER_AUTO:\r\n        0 - BCJ + LZMA\r\n        1 - LZMA\r\n        2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.\r\n    */\r\n    int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n\r\n    int i;\r\n    for (i = 0; i < numPasses; i++)\r\n    {\r\n      size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;\r\n      size_t outPropsSize = 5;\r\n      SRes curRes;\r\n      Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);\r\n      if (curModeIsFiltered && !bestIsFiltered)\r\n        break;\r\n      if (useFilter && i == 0)\r\n        curModeIsFiltered = True;\r\n      \r\n      curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,\r\n          curModeIsFiltered ? filteredStream : src, srcLen,\r\n          &props, dest + 1, &outPropsSize, 0,\r\n          NULL, &g_Alloc, &g_Alloc);\r\n      \r\n      if (curRes != SZ_ERROR_OUTPUT_EOF)\r\n      {\r\n        if (curRes != SZ_OK)\r\n        {\r\n          mainResult = curRes;\r\n          break;\r\n        }\r\n        if (outSizeProcessed <= minSize || mainResult != SZ_OK)\r\n        {\r\n          minSize = outSizeProcessed;\r\n          bestIsFiltered = curModeIsFiltered;\r\n          mainResult = SZ_OK;\r\n        }\r\n      }\r\n    }\r\n    dest[0] = (bestIsFiltered ? 1 : 0);\r\n    *destLen = LZMA86_HEADER_SIZE + minSize;\r\n  }\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaUtil/Lzma86Enc.h",
    "content": "/* Lzma86Enc.h -- LZMA + x86 (BCJ) Filter Encoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMA86ENC_H\r\n#define __LZMA86ENC_H\r\n\r\n#include \"../Types.h\"\r\n\r\n/*\r\nIt's an example for LZMA + x86 Filter use.\r\nYou can use .lzma86 extension, if you write that stream to file.\r\n.lzma86 header adds one additional byte to standard .lzma header.\r\n.lzma86 header (14 bytes):\r\n  Offset Size  Description\r\n    0     1    = 0 - no filter,\r\n               = 1 - x86 filter\r\n    1     1    lc, lp and pb in encoded form\r\n    2     4    dictSize (little endian)\r\n    6     8    uncompressed size (little endian)\r\n\r\n\r\nLzma86_Encode\r\n-------------\r\nlevel - compression level: 0 <= level <= 9, the default value for \"level\" is 5.\r\n\r\n\r\ndictSize - The dictionary size in bytes. The maximum value is\r\n        128 MB = (1 << 27) bytes for 32-bit version\r\n          1 GB = (1 << 30) bytes for 64-bit version\r\n     The default value is 16 MB = (1 << 24) bytes, for level = 5.\r\n     It's recommended to use the dictionary that is larger than 4 KB and\r\n     that can be calculated as (1 << N) or (3 << N) sizes.\r\n     For better compression ratio dictSize must be >= inSize.\r\n\r\nfilterMode:\r\n    SZ_FILTER_NO   - no Filter\r\n    SZ_FILTER_YES  - x86 Filter\r\n    SZ_FILTER_AUTO - it tries both alternatives to select best.\r\n              Encoder will use 2 or 3 passes:\r\n              2 passes when FILTER_NO provides better compression.\r\n              3 passes when FILTER_YES provides better compression.\r\n\r\nLzma86Encode allocates Data with MyAlloc functions.\r\nRAM Requirements for compressing:\r\n  RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize\r\n      filterMode     FilterBlockSize\r\n     SZ_FILTER_NO         0\r\n     SZ_FILTER_YES      inSize\r\n     SZ_FILTER_AUTO     inSize\r\n\r\n\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nenum ESzFilterMode\r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nSRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r\n    int level, UInt32 dictSize, int filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaUtil/LzmaUtil.c",
    "content": "/* LzmaUtil.c -- Test application for LZMA compression\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#define _CRT_SECURE_NO_WARNINGS\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../7zFile.h\"\r\n#include \"../7zVersion.h\"\r\n#include \"../LzmaDec.h\"\r\n#include \"../LzmaEnc.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\nconst char *kDataErrorMessage = \"Data error\";\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nvoid PrintHelp(char *buffer)\r\n{\r\n  strcat(buffer, \"\\nLZMA Utility \" MY_VERSION_COPYRIGHT_DATE \"\\n\"\r\n      \"\\nUsage:  lzma <e|d> inputFile outputFile\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\");\r\n}\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  strcat(buffer, \"\\nError: \");\r\n  strcat(buffer, message);\r\n  strcat(buffer, \"\\n\");\r\n  return 1;\r\n}\r\n\r\nint PrintErrorNumber(char *buffer, SRes val)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError code: %x\\n\", (unsigned)val);\r\n  return 1;\r\n}\r\n\r\nint PrintUserError(char *buffer)\r\n{\r\n  return PrintError(buffer, \"Incorrect command\");\r\n}\r\n\r\n#define IN_BUF_SIZE (1 << 16)\r\n#define OUT_BUF_SIZE (1 << 16)\r\n\r\nstatic SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    UInt64 unpackSize)\r\n{\r\n  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);\r\n  Byte inBuf[IN_BUF_SIZE];\r\n  Byte outBuf[OUT_BUF_SIZE];\r\n  size_t inPos = 0, inSize = 0, outPos = 0;\r\n  LzmaDec_Init(state);\r\n  for (;;)\r\n  {\r\n    if (inPos == inSize)\r\n    {\r\n      inSize = IN_BUF_SIZE;\r\n      RINOK(inStream->Read(inStream, inBuf, &inSize));\r\n      inPos = 0;\r\n    }\r\n    {\r\n      SRes res;\r\n      SizeT inProcessed = inSize - inPos;\r\n      SizeT outProcessed = OUT_BUF_SIZE - outPos;\r\n      ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\r\n      ELzmaStatus status;\r\n      if (thereIsSize && outProcessed > unpackSize)\r\n      {\r\n        outProcessed = (SizeT)unpackSize;\r\n        finishMode = LZMA_FINISH_END;\r\n      }\r\n      \r\n      res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,\r\n        inBuf + inPos, &inProcessed, finishMode, &status);\r\n      inPos += inProcessed;\r\n      outPos += outProcessed;\r\n      unpackSize -= outProcessed;\r\n      \r\n      if (outStream)\r\n        if (outStream->Write(outStream, outBuf, outPos) != outPos)\r\n          return SZ_ERROR_WRITE;\r\n        \r\n      outPos = 0;\r\n      \r\n      if (res != SZ_OK || thereIsSize && unpackSize == 0)\r\n        return res;\r\n      \r\n      if (inProcessed == 0 && outProcessed == 0)\r\n      {\r\n        if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)\r\n          return SZ_ERROR_DATA;\r\n        return res;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)\r\n{\r\n  UInt64 unpackSize;\r\n  int i;\r\n  SRes res = 0;\r\n\r\n  CLzmaDec state;\r\n\r\n  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */\r\n  unsigned char header[LZMA_PROPS_SIZE + 8];\r\n\r\n  /* Read and parse header */\r\n\r\n  RINOK(SeqInStream_Read(inStream, header, sizeof(header)));\r\n\r\n  unpackSize = 0;\r\n  for (i = 0; i < 8; i++)\r\n    unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);\r\n\r\n  LzmaDec_Construct(&state);\r\n  RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));\r\n  res = Decode2(&state, outStream, inStream, unpackSize);\r\n  LzmaDec_Free(&state, &g_Alloc);\r\n  return res;\r\n}\r\n\r\nstatic SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)\r\n{\r\n  CLzmaEncHandle enc;\r\n  SRes res;\r\n  CLzmaEncProps props;\r\n\r\n  rs = rs;\r\n\r\n  enc = LzmaEnc_Create(&g_Alloc);\r\n  if (enc == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  LzmaEncProps_Init(&props);\r\n  res = LzmaEnc_SetProps(enc, &props);\r\n\r\n  if (res == SZ_OK)\r\n  {\r\n    Byte header[LZMA_PROPS_SIZE + 8];\r\n    size_t headerSize = LZMA_PROPS_SIZE;\r\n    int i;\r\n\r\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r\n    for (i = 0; i < 8; i++)\r\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r\n    if (outStream->Write(outStream, header, headerSize) != headerSize)\r\n      res = SZ_ERROR_WRITE;\r\n    else\r\n    {\r\n      if (res == SZ_OK)\r\n        res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);\r\n    }\r\n  }\r\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  CFileSeqInStream inStream;\r\n  CFileOutStream outStream;\r\n  char c;\r\n  int res;\r\n  int encodeMode;\r\n  Bool useOutFile = False;\r\n\r\n  FileSeqInStream_CreateVTable(&inStream);\r\n  File_Construct(&inStream.file);\r\n\r\n  FileOutStream_CreateVTable(&outStream);\r\n  File_Construct(&outStream.file);\r\n\r\n  if (numArgs == 1)\r\n  {\r\n    PrintHelp(rs);\r\n    return 0;\r\n  }\r\n\r\n  if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1)\r\n    return PrintUserError(rs);\r\n\r\n  c = args[1][0];\r\n  encodeMode = (c == 'e' || c == 'E');\r\n  if (!encodeMode && c != 'd' && c != 'D')\r\n    return PrintUserError(rs);\r\n\r\n  {\r\n    size_t t4 = sizeof(UInt32);\r\n    size_t t8 = sizeof(UInt64);\r\n    if (t4 != 4 || t8 != 8)\r\n      return PrintError(rs, \"Incorrect UInt32 or UInt64\");\r\n  }\r\n\r\n  if (InFile_Open(&inStream.file, args[2]) != 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 3)\r\n  {\r\n    useOutFile = True;\r\n    if (OutFile_Open(&outStream.file, args[3]) != 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n  else if (encodeMode)\r\n    PrintUserError(rs);\r\n\r\n  if (encodeMode)\r\n  {\r\n    UInt64 fileSize;\r\n    File_GetLength(&inStream.file, &fileSize);\r\n    res = Encode(&outStream.s, &inStream.s, fileSize, rs);\r\n  }\r\n  else\r\n  {\r\n    res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL);\r\n  }\r\n\r\n  if (useOutFile)\r\n    File_Close(&outStream.file);\r\n  File_Close(&inStream.file);\r\n\r\n  if (res != SZ_OK)\r\n  {\r\n    if (res == SZ_ERROR_MEM)\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    else if (res == SZ_ERROR_DATA)\r\n      return PrintError(rs, kDataErrorMessage);\r\n    else if (res == SZ_ERROR_WRITE)\r\n      return PrintError(rs, kCantWriteMessage);\r\n    else if (res == SZ_ERROR_READ)\r\n      return PrintError(rs, kCantReadMessage);\r\n    return PrintErrorNumber(rs, res);\r\n  }\r\n  return 0;\r\n}\r\n\r\nint MY_CDECL main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaUtil/LzmaUtil.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaUtil\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=LzmaUtil - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaUtil.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaUtil.mak\" CFG=\"LzmaUtil - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"LzmaUtil - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"LzmaUtil - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"LzmaUtil - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\util\\lzmac.exe\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"LzmaUtil - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /GZ /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\util\\lzmac.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"LzmaUtil - Win32 Release\"\r\n# Name \"LzmaUtil - Win32 Debug\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zFile.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zFile.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zStream.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zVersion.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\CpuArch.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaUtil.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Types.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaUtil/LzmaUtil.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"LzmaUtil\"=.\\LzmaUtil.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaUtil/makefile",
    "content": "MY_STATIC_LINK=1\r\nPROG = LZMAc.exe\r\n\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n\r\nLIB_OBJS = \\\r\n  $O\\LzmaUtil.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\7zFile.obj \\\r\n  $O\\7zStream.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $(LIB_OBJS) \\\r\n  $(C_OBJS) \\\r\n\r\n!include \"../../CPP/Build.mak\"\r\n\r\n$(LIB_OBJS): $(*B).c\r\n\t$(COMPL_O2)\r\n$(C_OBJS): ../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/LzmaUtil/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++\r\nLIB =\r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = \\\r\n  LzmaUtil.o \\\r\n  Alloc.o \\\r\n  LzFind.o \\\r\n  LzmaDec.o \\\r\n  LzmaEnc.o \\\r\n  7zFile.o \\\r\n  7zStream.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r\n\r\nLzmaUtil.o: LzmaUtil.c\r\n\t$(CXX) $(CFLAGS) LzmaUtil.c\r\n\r\nAlloc.o: ../Alloc.c\r\n\t$(CXX) $(CFLAGS) ../Alloc.c\r\n\r\nLzFind.o: ../LzFind.c\r\n\t$(CXX) $(CFLAGS) ../LzFind.c\r\n\r\nLzmaDec.o: ../LzmaDec.c\r\n\t$(CXX) $(CFLAGS) ../LzmaDec.c\r\n\r\nLzmaEnc.o: ../LzmaEnc.c\r\n\t$(CXX) $(CFLAGS) ../LzmaEnc.c\r\n\r\n7zFile.o: ../7zFile.c\r\n\t$(CXX) $(CFLAGS) ../7zFile.c\r\n\r\n7zStream.o: ../7zStream.c\r\n\t$(CXX) $(CFLAGS) ../7zStream.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Threads.c",
    "content": "/* Threads.c -- multithreading library\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"Threads.h\"\r\n#include <process.h>\r\n\r\nstatic WRes GetError()\r\n{\r\n  DWORD res = GetLastError();\r\n  return (res) ? (WRes)(res) : 1;\r\n}\r\n\r\nWRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }\r\nWRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }\r\n\r\nstatic WRes MyCloseHandle(HANDLE *h)\r\n{\r\n  if (*h != NULL)\r\n    if (!CloseHandle(*h))\r\n      return GetError();\r\n  *h = NULL;\r\n  return 0;\r\n}\r\n\r\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n{\r\n  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r\n  thread->handle =\r\n    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */\r\n    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);\r\n    /* maybe we must use errno here, but probably GetLastError() is also OK. */\r\n  return HandleToWRes(thread->handle);\r\n}\r\n\r\nWRes WaitObject(HANDLE h)\r\n{\r\n  return (WRes)WaitForSingleObject(h, INFINITE);\r\n}\r\n\r\nWRes Thread_Wait(CThread *thread)\r\n{\r\n  if (thread->handle == NULL)\r\n    return 1;\r\n  return WaitObject(thread->handle);\r\n}\r\n\r\nWRes Thread_Close(CThread *thread)\r\n{\r\n  return MyCloseHandle(&thread->handle);\r\n}\r\n\r\nWRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)\r\n{\r\n  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);\r\n  return HandleToWRes(p->handle);\r\n}\r\n\r\nWRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, TRUE, initialSignaled); }\r\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)\r\n  { return ManualResetEvent_Create(p, 0); }\r\n\r\nWRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, FALSE, initialSignaled); }\r\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)\r\n  { return AutoResetEvent_Create(p, 0); }\r\n\r\nWRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }\r\nWRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }\r\nWRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }\r\nWRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }\r\n\r\n\r\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)\r\n{\r\n  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);\r\n  return HandleToWRes(p->handle);\r\n}\r\n\r\nWRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)\r\n{\r\n  return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));\r\n}\r\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)\r\n{\r\n  return Semaphore_Release(p, (LONG)releaseCount, NULL);\r\n}\r\nWRes Semaphore_Release1(CSemaphore *p)\r\n{\r\n  return Semaphore_ReleaseN(p, 1);\r\n}\r\n\r\nWRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }\r\nWRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }\r\n\r\nWRes CriticalSection_Init(CCriticalSection *p)\r\n{\r\n  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\r\n  __try\r\n  {\r\n    InitializeCriticalSection(p);\r\n    /* InitializeCriticalSectionAndSpinCount(p, 0); */\r\n  }\r\n  __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }\r\n  return 0;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Threads.h",
    "content": "/* Threads.h -- multithreading library\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_THRESDS_H\r\n#define __7Z_THRESDS_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _CThread\r\n{\r\n  HANDLE handle;\r\n} CThread;\r\n\r\n#define Thread_Construct(thread) (thread)->handle = NULL\r\n#define Thread_WasCreated(thread) ((thread)->handle != NULL)\r\n \r\ntypedef unsigned THREAD_FUNC_RET_TYPE;\r\n#define THREAD_FUNC_CALL_TYPE MY_STD_CALL\r\n#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r\n\r\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);\r\nWRes Thread_Wait(CThread *thread);\r\nWRes Thread_Close(CThread *thread);\r\n\r\ntypedef struct _CEvent\r\n{\r\n  HANDLE handle;\r\n} CEvent;\r\n\r\ntypedef CEvent CAutoResetEvent;\r\ntypedef CEvent CManualResetEvent;\r\n\r\n#define Event_Construct(event) (event)->handle = NULL\r\n#define Event_IsCreated(event) ((event)->handle != NULL)\r\n\r\nWRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);\r\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);\r\nWRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);\r\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);\r\nWRes Event_Set(CEvent *event);\r\nWRes Event_Reset(CEvent *event);\r\nWRes Event_Wait(CEvent *event);\r\nWRes Event_Close(CEvent *event);\r\n\r\n\r\ntypedef struct _CSemaphore\r\n{\r\n  HANDLE handle;\r\n} CSemaphore;\r\n\r\n#define Semaphore_Construct(p) (p)->handle = NULL\r\n\r\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);\r\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\r\nWRes Semaphore_Release1(CSemaphore *p);\r\nWRes Semaphore_Wait(CSemaphore *p);\r\nWRes Semaphore_Close(CSemaphore *p);\r\n\r\n\r\ntypedef CRITICAL_SECTION CCriticalSection;\r\n\r\nWRes CriticalSection_Init(CCriticalSection *p);\r\n#define CriticalSection_Delete(p) DeleteCriticalSection(p)\r\n#define CriticalSection_Enter(p) EnterCriticalSection(p)\r\n#define CriticalSection_Leave(p) LeaveCriticalSection(p)\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/C/Types.h",
    "content": "/* Types.h -- Basic types\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_TYPES_H\r\n#define __7Z_TYPES_H\r\n\r\n#include <stddef.h>\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#define SZ_OK 0\r\n\r\n#define SZ_ERROR_DATA 1\r\n#define SZ_ERROR_MEM 2\r\n#define SZ_ERROR_CRC 3\r\n#define SZ_ERROR_UNSUPPORTED 4\r\n#define SZ_ERROR_PARAM 5\r\n#define SZ_ERROR_INPUT_EOF 6\r\n#define SZ_ERROR_OUTPUT_EOF 7\r\n#define SZ_ERROR_READ 8\r\n#define SZ_ERROR_WRITE 9\r\n#define SZ_ERROR_PROGRESS 10\r\n#define SZ_ERROR_FAIL 11\r\n#define SZ_ERROR_THREAD 12\r\n\r\n#define SZ_ERROR_ARCHIVE 16\r\n#define SZ_ERROR_NO_ARCHIVE 17\r\n\r\ntypedef int SRes;\r\n\r\n#ifdef _WIN32\r\ntypedef DWORD WRes;\r\n#else\r\ntypedef int WRes;\r\n#endif\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r\n#endif\r\n\r\ntypedef unsigned char Byte;\r\ntypedef short Int16;\r\ntypedef unsigned short UInt16;\r\n\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef long Int32;\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef int Int32;\r\ntypedef unsigned int UInt32;\r\n#endif\r\n\r\n#ifdef _SZ_NO_INT_64\r\n\r\n/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r\n   NOTES: Some code will work incorrectly in that case! */\r\n\r\ntypedef long Int64;\r\ntypedef unsigned long UInt64;\r\n\r\n#else\r\n\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef __int64 Int64;\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef long long int Int64;\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\ntypedef size_t SizeT;\r\n#endif\r\n\r\ntypedef int Bool;\r\n#define True 1\r\n#define False 0\r\n\r\n\r\n#ifdef _MSC_VER\r\n\r\n#if _MSC_VER >= 1300\r\n#define MY_NO_INLINE __declspec(noinline)\r\n#else\r\n#define MY_NO_INLINE\r\n#endif\r\n\r\n#define MY_CDECL __cdecl\r\n#define MY_STD_CALL __stdcall\r\n#define MY_FAST_CALL MY_NO_INLINE __fastcall\r\n\r\n#else\r\n\r\n#define MY_CDECL\r\n#define MY_STD_CALL\r\n#define MY_FAST_CALL\r\n\r\n#endif\r\n\r\n\r\n/* The following interfaces use first parameter as pointer to structure */\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) < input(*size)) is allowed */\r\n} ISeqInStream;\r\n\r\n/* it can return SZ_ERROR_INPUT_EOF */\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r\n\r\ntypedef struct\r\n{\r\n  size_t (*Write)(void *p, const void *buf, size_t size);\r\n    /* Returns: result - the number of actually written bytes.\r\n       (result < size) means error */\r\n} ISeqOutStream;\r\n\r\ntypedef enum\r\n{\r\n  SZ_SEEK_SET = 0,\r\n  SZ_SEEK_CUR = 1,\r\n  SZ_SEEK_END = 2\r\n} ESzSeek;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ISeekInStream;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Look)(void *p, void **buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) > input(*size)) is not allowed\r\n       (output(*size) < input(*size)) is allowed */\r\n  SRes (*Skip)(void *p, size_t offset);\r\n    /* offset must be <= output(*size) of Look */\r\n\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ILookInStream;\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r\n\r\n/* reads via ILookInStream::Read */\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r\n\r\n#define LookToRead_BUF_SIZE (1 << 14)\r\n\r\ntypedef struct\r\n{\r\n  ILookInStream s;\r\n  ISeekInStream *realStream;\r\n  size_t pos;\r\n  size_t size;\r\n  Byte buf[LookToRead_BUF_SIZE];\r\n} CLookToRead;\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r\nvoid LookToRead_Init(CLookToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToLook;\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToRead;\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r\n    /* Returns: result. (result != SZ_OK) means break.\r\n       Value (UInt64)(Int64)-1 for size means unknown value. */\r\n} ICompressProgress;\r\n\r\ntypedef struct\r\n{\r\n  void *(*Alloc)(void *p, size_t size);\r\n  void (*Free)(void *p, void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\n#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r\n#define IAlloc_Free(p, a) (p)->Free((p), a)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zCompressionMode.cpp",
    "content": "// CompressionMethod.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zCompressionMode.h",
    "content": "// 7zCompressionMode.h\r\n\r\n#ifndef __7Z_COMPRESSION_MODE_H\r\n#define __7Z_COMPRESSION_MODE_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CMethodFull: public CMethod\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBind\r\n{\r\n  UInt32 InCoder;\r\n  UInt32 InStream;\r\n  UInt32 OutCoder;\r\n  UInt32 OutStream;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  CObjectVector<CMethodFull> Methods;\r\n  CRecordVector<CBind> Binds;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }\r\n  CCompressionMethodMode(): PasswordIsDefined(false)\r\n      #ifdef COMPRESS_MT\r\n      , NumThreads(1)\r\n      #endif\r\n  {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zDecode.cpp",
    "content": "// 7zDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/LockedStream.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertFolderItemInfoToBindInfo(const CFolder &folder,\r\n    CBindInfoEx &bindInfo)\r\n{\r\n  bindInfo.Clear();\r\n  int i;\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    NCoderMixer::CBindPair bindPair;\r\n    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;\r\n    bindInfo.BindPairs.Add(bindPair);\r\n  }\r\n  UInt32 outStreamIndex = 0;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    const CCoderInfo &coderInfo = folder.Coders[i];\r\n    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;\r\n    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    bindInfo.Coders.Add(coderStreamsInfo);\r\n    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);\r\n    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)\r\n      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)\r\n        bindInfo.OutStreams.Add(outStreamIndex);\r\n  }\r\n  for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);\r\n}\r\n\r\nstatic bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1,\r\n    const NCoderMixer::CCoderStreamsInfo &a2)\r\n{\r\n  return (a1.NumInStreams == a2.NumInStreams) &&\r\n    (a1.NumOutStreams == a2.NumOutStreams);\r\n}\r\n\r\nstatic bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)\r\n{\r\n  return (a1.InIndex == a2.InIndex) &&\r\n    (a1.OutIndex == a2.OutIndex);\r\n}\r\n\r\nstatic bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)\r\n{\r\n  if (a1.Coders.Size() != a2.Coders.Size())\r\n    return false;\r\n  int i;\r\n  for (i = 0; i < a1.Coders.Size(); i++)\r\n    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))\r\n      return false;\r\n  if (a1.BindPairs.Size() != a2.BindPairs.Size())\r\n    return false;\r\n  for (i = 0; i < a1.BindPairs.Size(); i++)\r\n    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))\r\n      return false;\r\n  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)\r\n    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])\r\n      return false;\r\n  if (a1.InStreams.Size() != a2.InStreams.Size())\r\n    return false;\r\n  if (a1.OutStreams.Size() != a2.OutStreams.Size())\r\n    return false;\r\n  return true;\r\n}\r\n\r\nCDecoder::CDecoder(bool multiThread)\r\n{\r\n  #ifndef _ST_MODE\r\n  multiThread = true;\r\n  #endif\r\n  _multiThread = multiThread;\r\n  _bindInfoExPrevIsDefined = false;\r\n}\r\n\r\nHRESULT CDecoder::Decode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    UInt64 startPos,\r\n    const UInt64 *packSizes,\r\n    const CFolder &folderInfo,\r\n    ISequentialOutStream *outStream,\r\n    ICompressProgressInfo *compressProgress\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    #ifdef COMPRESS_MT\r\n    , bool mtMode, UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  if (!folderInfo.CheckStructure())\r\n    return E_NOTIMPL;\r\n  #ifndef _NO_CRYPTO\r\n  passwordIsDefined = false;\r\n  #endif\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;\r\n  \r\n  CLockedInStream lockedInStream;\r\n  lockedInStream.Init(inStream);\r\n  \r\n  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)\r\n  {\r\n    CLockedSequentialInStreamImp *lockedStreamImpSpec = new\r\n        CLockedSequentialInStreamImp;\r\n    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;\r\n    lockedStreamImpSpec->Init(&lockedInStream, startPos);\r\n    startPos += packSizes[j];\r\n    \r\n    CLimitedSequentialInStream *streamSpec = new\r\n        CLimitedSequentialInStream;\r\n    CMyComPtr<ISequentialInStream> inStream = streamSpec;\r\n    streamSpec->SetStream(lockedStreamImp);\r\n    streamSpec->Init(packSizes[j]);\r\n    inStreams.Add(inStream);\r\n  }\r\n  \r\n  int numCoders = folderInfo.Coders.Size();\r\n  \r\n  CBindInfoEx bindInfo;\r\n  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);\r\n  bool createNewCoders;\r\n  if (!_bindInfoExPrevIsDefined)\r\n    createNewCoders = true;\r\n  else\r\n    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);\r\n  if (createNewCoders)\r\n  {\r\n    int i;\r\n    _decoders.Clear();\r\n    // _decoders2.Clear();\r\n    \r\n    _mixerCoder.Release();\r\n\r\n    if (_multiThread)\r\n    {\r\n      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;\r\n      _mixerCoder = _mixerCoderMTSpec;\r\n      _mixerCoderCommon = _mixerCoderMTSpec;\r\n    }\r\n    else\r\n    {\r\n      #ifdef _ST_MODE\r\n      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;\r\n      _mixerCoder = _mixerCoderSTSpec;\r\n      _mixerCoderCommon = _mixerCoderSTSpec;\r\n      #endif\r\n    }\r\n    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));\r\n    \r\n    for (i = 0; i < numCoders; i++)\r\n    {\r\n      const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n\r\n  \r\n      CMyComPtr<ICompressCoder> decoder;\r\n      CMyComPtr<ICompressCoder2> decoder2;\r\n      RINOK(CreateCoder(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          coderInfo.MethodID, decoder, decoder2, false));\r\n      CMyComPtr<IUnknown> decoderUnknown;\r\n      if (coderInfo.IsSimpleCoder())\r\n      {\r\n        if (decoder == 0)\r\n          return E_NOTIMPL;\r\n\r\n        decoderUnknown = (IUnknown *)decoder;\r\n        \r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder(decoder);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder(decoder, false);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        if (decoder2 == 0)\r\n          return E_NOTIMPL;\r\n        decoderUnknown = (IUnknown *)decoder2;\r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder2(decoder2);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder2(decoder2, false);\r\n        #endif\r\n      }\r\n      _decoders.Add(decoderUnknown);\r\n      #ifdef EXTERNAL_CODECS\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n      }\r\n      #endif\r\n    }\r\n    _bindInfoExPrev = bindInfo;\r\n    _bindInfoExPrevIsDefined = true;\r\n  }\r\n  int i;\r\n  _mixerCoderCommon->ReInit();\r\n  \r\n  UInt32 packStreamIndex = 0, unpackStreamIndex = 0;\r\n  UInt32 coderIndex = 0;\r\n  // UInt32 coder2Index = 0;\r\n  \r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];\r\n    \r\n    {\r\n      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n      if (setDecoderProperties)\r\n      {\r\n        const CByteBuffer &props = coderInfo.Props;\r\n        size_t size = props.GetCapacity();\r\n        if (size > 0xFFFFFFFF)\r\n          return E_NOTIMPL;\r\n        if (size > 0)\r\n        {\r\n          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)props, (UInt32)size));\r\n        }\r\n      }\r\n    }\r\n\r\n    #ifdef COMPRESS_MT\r\n    if (mtMode)\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(numThreads));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    {\r\n      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n      if (cryptoSetPassword)\r\n      {\r\n        if (getTextPassword == 0)\r\n          return E_FAIL;\r\n        CMyComBSTR passwordBSTR;\r\n        RINOK(getTextPassword->CryptoGetTextPassword(&passwordBSTR));\r\n        CByteBuffer buffer;\r\n        passwordIsDefined = true;\r\n        const UString password(passwordBSTR);\r\n        const UInt32 sizeInBytes = password.Length() * 2;\r\n        buffer.SetCapacity(sizeInBytes);\r\n        for (int i = 0; i < password.Length(); i++)\r\n        {\r\n          wchar_t c = password[i];\r\n          ((Byte *)buffer)[i * 2] = (Byte)c;\r\n          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n        }\r\n        RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    coderIndex++;\r\n    \r\n    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;\r\n    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    CRecordVector<const UInt64 *> packSizesPointers;\r\n    CRecordVector<const UInt64 *> unpackSizesPointers;\r\n    packSizesPointers.Reserve(numInStreams);\r\n    unpackSizesPointers.Reserve(numOutStreams);\r\n    UInt32 j;\r\n    for (j = 0; j < numOutStreams; j++, unpackStreamIndex++)\r\n      unpackSizesPointers.Add(&folderInfo.UnpackSizes[unpackStreamIndex]);\r\n    \r\n    for (j = 0; j < numInStreams; j++, packStreamIndex++)\r\n    {\r\n      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);\r\n      if (bindPairIndex >= 0)\r\n        packSizesPointers.Add(\r\n        &folderInfo.UnpackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);\r\n      else\r\n      {\r\n        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);\r\n        if (index < 0)\r\n          return E_FAIL;\r\n        packSizesPointers.Add(&packSizes[index]);\r\n      }\r\n    }\r\n    \r\n    _mixerCoderCommon->SetCoderInfo(i,\r\n        &packSizesPointers.Front(),\r\n        &unpackSizesPointers.Front());\r\n  }\r\n  UInt32 mainCoder, temp;\r\n  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);\r\n\r\n  if (_multiThread)\r\n    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);\r\n  /*\r\n  else\r\n    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;\r\n  */\r\n  \r\n  if (numCoders == 0)\r\n    return 0;\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  inStreamPointers.Reserve(inStreams.Size());\r\n  for (i = 0; i < inStreams.Size(); i++)\r\n    inStreamPointers.Add(inStreams[i]);\r\n  ISequentialOutStream *outStreamPointer = outStream;\r\n  return _mixerCoder->Code(&inStreamPointers.Front(), NULL,\r\n    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zDecode.h",
    "content": "// 7zDecode.h\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"7zItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CBindInfoEx: public NCoderMixer::CBindInfo\r\n{\r\n  CRecordVector<CMethodId> CoderMethodIDs;\r\n  void Clear()\r\n  {\r\n    CBindInfo::Clear();\r\n    CoderMethodIDs.Clear();\r\n  }\r\n};\r\n\r\nclass CDecoder\r\n{\r\n  bool _bindInfoExPrevIsDefined;\r\n  CBindInfoEx _bindInfoExPrev;\r\n  \r\n  bool _multiThread;\r\n  #ifdef _ST_MODE\r\n  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;\r\n  #endif\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;\r\n  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;\r\n  \r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n  CObjectVector<CMyComPtr<IUnknown> > _decoders;\r\n  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;\r\npublic:\r\n  CDecoder(bool multiThread);\r\n  HRESULT Decode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      IInStream *inStream,\r\n      UInt64 startPos,\r\n      const UInt64 *packSizes,\r\n      const CFolder &folder,\r\n      ISequentialOutStream *outStream,\r\n      ICompressProgressInfo *compressProgress\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , bool mtMode, UInt32 numThreads\r\n      #endif\r\n      );\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zEncode.cpp",
    "content": "// Encode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zSpecStream.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/InOutTempBuffer.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nstatic const UInt64 k_AES = 0x06F10701;\r\nstatic const UInt64 k_BCJ  = 0x03030103;\r\nstatic const UInt64 k_BCJ2 = 0x0303011B;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,\r\n    const CRecordVector<CMethodId> decompressionMethods,\r\n    CFolder &folder)\r\n{\r\n  folder.Coders.Clear();\r\n  // bindInfo.CoderMethodIDs.Clear();\r\n  // folder.OutStreams.Clear();\r\n  folder.PackStreams.Clear();\r\n  folder.BindPairs.Clear();\r\n  int i;\r\n  for (i = 0; i < bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = bindInfo.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = bindInfo.BindPairs[i].OutIndex;\r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n  for (i = 0; i < bindInfo.Coders.Size(); i++)\r\n  {\r\n    CCoderInfo coderInfo;\r\n    const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];\r\n    coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;\r\n    coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;\r\n    coderInfo.MethodID = decompressionMethods[i];\r\n    folder.Coders.Add(coderInfo);\r\n  }\r\n  for (i = 0; i < bindInfo.InStreams.Size(); i++)\r\n    folder.PackStreams.Add(bindInfo.InStreams[i]);\r\n}\r\n\r\nHRESULT CEncoder::CreateMixerCoder(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const UInt64 *inSizeForReduce)\r\n{\r\n  _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;\r\n  _mixerCoder = _mixerCoderSpec;\r\n  RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));\r\n  for (int i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _codersInfo.Add(CCoderInfo());\r\n    CCoderInfo &encodingInfo = _codersInfo.Back();\r\n    encodingInfo.MethodID = methodFull.Id;\r\n    CMyComPtr<ICompressCoder> encoder;\r\n    CMyComPtr<ICompressCoder2> encoder2;\r\n    \r\n\r\n    RINOK(CreateCoder(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        methodFull.Id, encoder, encoder2, true));\r\n\r\n    if (!encoder && !encoder2)\r\n      return E_FAIL;\r\n\r\n    CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;\r\n   \r\n    #ifdef COMPRESS_MT\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));\r\n      }\r\n    }\r\n    #endif\r\n        \r\n\r\n    RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon));\r\n\r\n    /*\r\n    CMyComPtr<ICryptoResetSalt> resetSalt;\r\n    encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);\r\n    if (resetSalt != NULL)\r\n    {\r\n      resetSalt->ResetSalt();\r\n    }\r\n    */\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n    encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n    if (setCompressCodecsInfo)\r\n    {\r\n      RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n    }\r\n    #endif\r\n    \r\n    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n    encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n\r\n    if (cryptoSetPassword)\r\n    {\r\n      CByteBuffer buffer;\r\n      const UInt32 sizeInBytes = _options.Password.Length() * 2;\r\n      buffer.SetCapacity(sizeInBytes);\r\n      for (int i = 0; i < _options.Password.Length(); i++)\r\n      {\r\n        wchar_t c = _options.Password[i];\r\n        ((Byte *)buffer)[i * 2] = (Byte)c;\r\n        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n      }\r\n      RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n    }\r\n\r\n    if (encoder)\r\n      _mixerCoderSpec->AddCoder(encoder);\r\n    else\r\n      _mixerCoderSpec->AddCoder2(encoder2);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Encode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    ISequentialInStream *inStream,\r\n    const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n    CFolder &folderItem,\r\n    ISequentialOutStream *outStream,\r\n    CRecordVector<UInt64> &packSizes,\r\n    ICompressProgressInfo *compressProgress)\r\n{\r\n  RINOK(EncoderConstr());\r\n\r\n  if (_mixerCoderSpec == NULL)\r\n  {\r\n    RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));\r\n  }\r\n  _mixerCoderSpec->ReInit();\r\n  // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);\r\n\r\n  CObjectVector<CInOutTempBuffer> inOutTempBuffers;\r\n  CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;\r\n  CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;\r\n  int numMethods = _bindInfo.Coders.Size();\r\n  int i;\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    inOutTempBuffers.Add(CInOutTempBuffer());\r\n    inOutTempBuffers.Back().Create();\r\n    inOutTempBuffers.Back().InitWriting();\r\n  }\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CSequentialOutTempBufferImp *tempBufferSpec =\r\n        new CSequentialOutTempBufferImp;\r\n    CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;\r\n    tempBufferSpec->Init(&inOutTempBuffers[i - 1]);\r\n    tempBuffers.Add(tempBuffer);\r\n    tempBufferSpecs.Add(tempBufferSpec);\r\n  }\r\n\r\n  for (i = 0; i < numMethods; i++)\r\n    _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    return E_FAIL;\r\n  UInt32 mainCoderIndex, mainStreamIndex;\r\n  _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);\r\n  \r\n  if (inStreamSize != NULL)\r\n  {\r\n    CRecordVector<const UInt64 *> sizePointers;\r\n    for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)\r\n      if (i == mainStreamIndex)\r\n        sizePointers.Add(inStreamSize);\r\n      else\r\n        sizePointers.Add(NULL);\r\n    _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);\r\n  }\r\n\r\n  \r\n  // UInt64 outStreamStartPos;\r\n  // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));\r\n  \r\n  CSequentialInStreamSizeCount2 *inStreamSizeCountSpec =\r\n      new CSequentialInStreamSizeCount2;\r\n  CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;\r\n  CSequentialOutStreamSizeCount *outStreamSizeCountSpec =\r\n      new CSequentialOutStreamSizeCount;\r\n  CMyComPtr<ISequentialOutStream> outStreamSizeCount = outStreamSizeCountSpec;\r\n\r\n  inStreamSizeCountSpec->Init(inStream);\r\n  outStreamSizeCountSpec->SetStream(outStream);\r\n  outStreamSizeCountSpec->Init();\r\n\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  CRecordVector<ISequentialOutStream *> outStreamPointers;\r\n  inStreamPointers.Add(inStreamSizeCount);\r\n  outStreamPointers.Add(outStreamSizeCount);\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n    outStreamPointers.Add(tempBuffers[i - 1]);\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    CCoderInfo &encodingInfo = _codersInfo[i];\r\n    \r\n    CMyComPtr<ICryptoResetInitVector> resetInitVector;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);\r\n    if (resetInitVector != NULL)\r\n    {\r\n      resetInitVector->ResetInitVector();\r\n    }\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n    if (writeCoderProperties != NULL)\r\n    {\r\n      CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n      outStreamSpec->Init();\r\n      writeCoderProperties->WriteCoderProperties(outStream);\r\n      size_t size = outStreamSpec->GetSize();\r\n      encodingInfo.Props.SetCapacity(size);\r\n      memmove(encodingInfo.Props, outStreamSpec->GetBuffer(), size);\r\n    }\r\n  }\r\n\r\n  UInt32 progressIndex = mainCoderIndex;\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    const CCoderInfo &e = _codersInfo[i];\r\n    if ((e.MethodID == k_BCJ || e.MethodID == k_BCJ2) && i + 1 < _codersInfo.Size())\r\n      progressIndex = i + 1;\r\n  }\r\n\r\n  _mixerCoderSpec->SetProgressCoderIndex(progressIndex);\r\n  \r\n  RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,\r\n    &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));\r\n  \r\n  ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods,\r\n      folderItem);\r\n  \r\n  packSizes.Add(outStreamSizeCountSpec->GetSize());\r\n  \r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];\r\n    inOutTempBuffer.FlushWrite();\r\n    inOutTempBuffer.InitReading();\r\n    inOutTempBuffer.WriteToStream(outStream);\r\n    packSizes.Add(inOutTempBuffer.GetDataSize());\r\n  }\r\n  \r\n  for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)\r\n  {\r\n    int binder = _bindInfo.FindBinderForInStream(\r\n        _bindReverseConverter->DestOutToSrcInMap[i]);\r\n    UInt64 streamSize;\r\n    if (binder < 0)\r\n      streamSize = inStreamSizeCountSpec->GetSize();\r\n    else\r\n      streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);\r\n    folderItem.UnpackSizes.Add(streamSize);\r\n  }\r\n  for (i = numMethods - 1; i >= 0; i--)\r\n    folderItem.Coders[numMethods - 1 - i].Props = _codersInfo[i].Props;\r\n  return S_OK;\r\n}\r\n\r\n\r\nCEncoder::CEncoder(const CCompressionMethodMode &options):\r\n  _bindReverseConverter(0),\r\n  _constructed(false)\r\n{\r\n  if (options.IsEmpty())\r\n    throw 1;\r\n\r\n  _options = options;\r\n  _mixerCoderSpec = NULL;\r\n}\r\n\r\nHRESULT CEncoder::EncoderConstr()\r\n{\r\n  if (_constructed)\r\n    return S_OK;\r\n  if (_options.Methods.IsEmpty())\r\n  {\r\n    // it has only password method;\r\n    if (!_options.PasswordIsDefined)\r\n      throw 1;\r\n    if (!_options.Binds.IsEmpty())\r\n      throw 1;\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    CMethodFull method;\r\n    \r\n    method.NumInStreams = 1;\r\n    method.NumOutStreams = 1;\r\n    coderStreamsInfo.NumInStreams = 1;\r\n    coderStreamsInfo.NumOutStreams = 1;\r\n    method.Id = k_AES;\r\n    \r\n    _options.Methods.Add(method);\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  \r\n    _bindInfo.InStreams.Add(0);\r\n    _bindInfo.OutStreams.Add(0);\r\n  }\r\n  else\r\n  {\r\n\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  int i;\r\n  for (i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;\r\n    coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;\r\n    if (_options.Binds.IsEmpty())\r\n    {\r\n      if (i < _options.Methods.Size() - 1)\r\n      {\r\n        NCoderMixer::CBindPair bindPair;\r\n        bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;\r\n        bindPair.OutIndex = numOutStreams;\r\n        _bindInfo.BindPairs.Add(bindPair);\r\n      }\r\n      else\r\n        _bindInfo.OutStreams.Insert(0, numOutStreams);\r\n      for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)\r\n        _bindInfo.OutStreams.Add(numOutStreams + j);\r\n    }\r\n    \r\n    numInStreams += coderStreamsInfo.NumInStreams;\r\n    numOutStreams += coderStreamsInfo.NumOutStreams;\r\n\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  }\r\n\r\n  if (!_options.Binds.IsEmpty())\r\n  {\r\n    for (i = 0; i < _options.Binds.Size(); i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      const CBind &bind = _options.Binds[i];\r\n      bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;\r\n      bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    for (i = 0; i < (int)numOutStreams; i++)\r\n      if (_bindInfo.FindBinderForOutStream(i) == -1)\r\n        _bindInfo.OutStreams.Add(i);\r\n  }\r\n\r\n  for (i = 0; i < (int)numInStreams; i++)\r\n    if (_bindInfo.FindBinderForInStream(i) == -1)\r\n      _bindInfo.InStreams.Add(i);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    throw 1; // this is error\r\n\r\n  // Make main stream first in list\r\n  int inIndex = _bindInfo.InStreams[0];\r\n  for (;;)\r\n  {\r\n    UInt32 coderIndex, coderStreamIndex;\r\n    _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);\r\n    UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);\r\n    int binder = _bindInfo.FindBinderForOutStream(outIndex);\r\n    if (binder >= 0)\r\n    {\r\n      inIndex = _bindInfo.BindPairs[binder].InIndex;\r\n      continue;\r\n    }\r\n    for (i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n      if (_bindInfo.OutStreams[i] == outIndex)\r\n      {\r\n        _bindInfo.OutStreams.Delete(i);\r\n        _bindInfo.OutStreams.Insert(0, outIndex);\r\n        break;\r\n      }\r\n    break;\r\n  }\r\n\r\n  if (_options.PasswordIsDefined)\r\n  {\r\n    int numCryptoStreams = _bindInfo.OutStreams.Size();\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      bindPair.InIndex = numInStreams + i;\r\n      bindPair.OutIndex = _bindInfo.OutStreams[i];\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    _bindInfo.OutStreams.Clear();\r\n\r\n    /*\r\n    if (numCryptoStreams == 0)\r\n      numCryptoStreams = 1;\r\n    */\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n      CMethodFull method;\r\n      method.NumInStreams = 1;\r\n      method.NumOutStreams = 1;\r\n      coderStreamsInfo.NumInStreams = method.NumOutStreams;\r\n      coderStreamsInfo.NumOutStreams = method.NumInStreams;\r\n      method.Id = k_AES;\r\n\r\n      _options.Methods.Add(method);\r\n      _bindInfo.Coders.Add(coderStreamsInfo);\r\n      _bindInfo.OutStreams.Add(numOutStreams + i);\r\n    }\r\n  }\r\n\r\n  }\r\n\r\n  for (int i = _options.Methods.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _decompressionMethods.Add(methodFull.Id);\r\n  }\r\n\r\n  _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);\r\n  _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);\r\n  _constructed = true;\r\n  return S_OK;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  delete _bindReverseConverter;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zEncode.h",
    "content": "// 7zEncode.h\r\n\r\n#ifndef __7Z_ENCODE_H\r\n#define __7Z_ENCODE_H\r\n\r\n// #include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n#include \"7zItem.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CEncoder\r\n{\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;\r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n\r\n  CObjectVector<CCoderInfo> _codersInfo;\r\n\r\n  CCompressionMethodMode _options;\r\n  NCoderMixer::CBindInfo _bindInfo;\r\n  NCoderMixer::CBindInfo _decompressBindInfo;\r\n  NCoderMixer::CBindReverseConverter *_bindReverseConverter;\r\n  CRecordVector<CMethodId> _decompressionMethods;\r\n\r\n  HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const UInt64 *inSizeForReduce);\r\n\r\n  bool _constructed;\r\npublic:\r\n  CEncoder(const CCompressionMethodMode &options);\r\n  ~CEncoder();\r\n  HRESULT EncoderConstr();\r\n  HRESULT Encode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      ISequentialInStream *inStream,\r\n      const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n      CFolder &folderItem,\r\n      ISequentialOutStream *outStream,\r\n      CRecordVector<UInt64> &packSizes,\r\n      ICompressProgressInfo *compressProgress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zExtract.cpp",
    "content": "// 7zExtract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zFolderOutStream.h\"\r\n#include \"7zDecode.h\"\r\n// #include \"7z1Decode.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CExtractFolderInfo\r\n{\r\n  #ifdef _7Z_VOL\r\n  int VolumeIndex;\r\n  #endif\r\n  CNum FileIndex;\r\n  CNum FolderIndex;\r\n  CBoolVector ExtractStatuses;\r\n  UInt64 UnpackSize;\r\n  CExtractFolderInfo(\r\n    #ifdef _7Z_VOL\r\n    int volumeIndex,\r\n    #endif\r\n    CNum fileIndex, CNum folderIndex):\r\n    #ifdef _7Z_VOL\r\n    VolumeIndex(volumeIndex),\r\n    #endif\r\n    FileIndex(fileIndex),\r\n    FolderIndex(folderIndex),\r\n    UnpackSize(0)\r\n  {\r\n    if (fileIndex != kNumNoIndex)\r\n    {\r\n      ExtractStatuses.Reserve(1);\r\n      ExtractStatuses.Add(true);\r\n    }\r\n  };\r\n};\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool testMode = (testModeSpec != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;\r\n  UInt64 importantTotalUnpacked = 0;\r\n\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (allFilesMode)\r\n    numItems =\r\n    #ifdef _7Z_VOL\r\n    _refs.Size();\r\n    #else\r\n    _db.Files.Size();\r\n    #endif\r\n\r\n  if(numItems == 0)\r\n    return S_OK;\r\n\r\n  /*\r\n  if(_volumes.Size() != 1)\r\n    return E_FAIL;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_db = volume.Database;\r\n  IInStream *_inStream = volume.Stream;\r\n  */\r\n  \r\n  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;\r\n  for(UInt32 ii = 0; ii < numItems; ii++)\r\n  {\r\n    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];\r\n    UInt32 ref2Index = allFilesMode ? ii : indices[ii];\r\n    // const CRef2 &ref2 = _refs[ref2Index];\r\n\r\n    // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)\r\n    {\r\n      #ifdef _7Z_VOL\r\n      // const CRef &ref = ref2.Refs[ri];\r\n      const CRef &ref = _refs[ref2Index];\r\n\r\n      int volumeIndex = ref.VolumeIndex;\r\n      const CVolume &volume = _volumes[volumeIndex];\r\n      const CArchiveDatabaseEx &db = volume.Database;\r\n      UInt32 fileIndex = ref.ItemIndex;\r\n      #else\r\n      const CArchiveDatabaseEx &db = _db;\r\n      UInt32 fileIndex = ref2Index;\r\n      #endif\r\n\r\n      CNum folderIndex = db.FileIndexToFolderIndexMap[fileIndex];\r\n      if (folderIndex == kNumNoIndex)\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex,\r\n            #endif\r\n            fileIndex, kNumNoIndex));\r\n        continue;\r\n      }\r\n      if (extractFolderInfoVector.IsEmpty() ||\r\n        folderIndex != extractFolderInfoVector.Back().FolderIndex\r\n        #ifdef _7Z_VOL\r\n        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex\r\n        #endif\r\n        )\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex,\r\n            #endif\r\n            kNumNoIndex, folderIndex));\r\n        const CFolder &folderInfo = db.Folders[folderIndex];\r\n        UInt64 unpackSize = folderInfo.GetUnpackSize();\r\n        importantTotalUnpacked += unpackSize;\r\n        extractFolderInfoVector.Back().UnpackSize = unpackSize;\r\n      }\r\n      \r\n      CExtractFolderInfo &efi = extractFolderInfoVector.Back();\r\n      \r\n      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];\r\n      CNum startIndex = db.FolderStartFileIndex[folderIndex];\r\n      for (CNum index = efi.ExtractStatuses.Size();\r\n          index <= fileIndex - startIndex; index++)\r\n      {\r\n        // UInt64 unpackSize = _db.Files[startIndex + index].UnpackSize;\r\n        // Count partial_folder_size\r\n        // efi.UnpackSize += unpackSize;\r\n        // importantTotalUnpacked += unpackSize;\r\n        efi.ExtractStatuses.Add(index == fileIndex - startIndex);\r\n      }\r\n    }\r\n  }\r\n\r\n  extractCallback->SetTotal(importantTotalUnpacked);\r\n\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  // CDecoder1 decoder;\r\n\r\n  UInt64 currentTotalPacked = 0;\r\n  UInt64 currentTotalUnpacked = 0;\r\n  UInt64 totalFolderUnpacked;\r\n  UInt64 totalFolderPacked;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for(int i = 0; i < extractFolderInfoVector.Size(); i++,\r\n      currentTotalUnpacked += totalFolderUnpacked,\r\n      currentTotalPacked += totalFolderPacked)\r\n  {\r\n    lps->OutSize = currentTotalUnpacked;\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    const CExtractFolderInfo &efi = extractFolderInfoVector[i];\r\n    totalFolderUnpacked = efi.UnpackSize;\r\n\r\n    totalFolderPacked = 0;\r\n\r\n    CFolderOutStream *folderOutStream = new CFolderOutStream;\r\n    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);\r\n\r\n    #ifdef _7Z_VOL\r\n    const CVolume &volume = _volumes[efi.VolumeIndex];\r\n    const CArchiveDatabaseEx &db = volume.Database;\r\n    #else\r\n    const CArchiveDatabaseEx &db = _db;\r\n    #endif\r\n\r\n    CNum startIndex;\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      startIndex = efi.FileIndex;\r\n    else\r\n      startIndex = db.FolderStartFileIndex[efi.FolderIndex];\r\n\r\n\r\n    HRESULT result = folderOutStream->Init(&db,\r\n        #ifdef _7Z_VOL\r\n        volume.StartRef2Index,\r\n        #else\r\n        0,\r\n        #endif\r\n        startIndex,\r\n        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);\r\n\r\n    RINOK(result);\r\n\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      continue;\r\n\r\n    CNum folderIndex = efi.FolderIndex;\r\n    const CFolder &folderInfo = db.Folders[folderIndex];\r\n\r\n    totalFolderPacked = _db.GetFolderFullPackSize(folderIndex);\r\n\r\n    CNum packStreamIndex = db.FolderStartPackStreamIndex[folderIndex];\r\n    UInt64 folderStartPackPos = db.GetFolderStreamPos(folderIndex, 0);\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (extractCallback)\r\n      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    #endif\r\n\r\n    try\r\n    {\r\n      #ifndef _NO_CRYPTO\r\n      bool passwordIsDefined;\r\n      #endif\r\n\r\n      HRESULT result = decoder.Decode(\r\n          EXTERNAL_CODECS_VARS\r\n          #ifdef _7Z_VOL\r\n          volume.Stream,\r\n          #else\r\n          _inStream,\r\n          #endif\r\n          folderStartPackPos,\r\n          &db.PackSizes[packStreamIndex],\r\n          folderInfo,\r\n          outStream,\r\n          progress\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword, passwordIsDefined\r\n          #endif\r\n          #ifdef COMPRESS_MT\r\n          , true, _numThreads\r\n          #endif\r\n          );\r\n\r\n      if (result == S_FALSE)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));\r\n        continue;\r\n      }\r\n      if (result != S_OK)\r\n        return result;\r\n      if (folderOutStream->WasWritingFinished() != S_OK)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n      continue;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zFolderInStream.cpp",
    "content": "// 7zFolderInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderInStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderInStream::CFolderInStream()\r\n{\r\n  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;\r\n  _inStreamWithHash = _inStreamWithHashSpec;\r\n}\r\n\r\nvoid CFolderInStream::Init(IArchiveUpdateCallback *updateCallback,\r\n    const UInt32 *fileIndices, UInt32 numFiles)\r\n{\r\n  _updateCallback = updateCallback;\r\n  _numFiles = numFiles;\r\n  _fileIndex = 0;\r\n  _fileIndices = fileIndices;\r\n  Processed.Clear();\r\n  CRCs.Clear();\r\n  Sizes.Clear();\r\n  _fileIsOpen = false;\r\n  _currentSizeIsDefined = false;\r\n}\r\n\r\nHRESULT CFolderInStream::OpenStream()\r\n{\r\n  _filePos = 0;\r\n  while (_fileIndex < _numFiles)\r\n  {\r\n    _currentSizeIsDefined = false;\r\n    CMyComPtr<ISequentialInStream> stream;\r\n    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);\r\n    if (result != S_OK && result != S_FALSE)\r\n      return result;\r\n    _fileIndex++;\r\n    _inStreamWithHashSpec->SetStream(stream);\r\n    _inStreamWithHashSpec->Init();\r\n    if (!stream)\r\n    {\r\n      RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n      Sizes.Add(0);\r\n      Processed.Add(result == S_OK);\r\n      AddDigest();\r\n      continue;\r\n    }\r\n    CMyComPtr<IStreamGetSize> streamGetSize;\r\n    if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)\r\n    {\r\n      if(streamGetSize)\r\n      {\r\n        _currentSizeIsDefined = true;\r\n        RINOK(streamGetSize->GetSize(&_currentSize));\r\n      }\r\n    }\r\n\r\n    _fileIsOpen = true;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFolderInStream::AddDigest()\r\n{\r\n  CRCs.Add(_inStreamWithHashSpec->GetCRC());\r\n}\r\n\r\nHRESULT CFolderInStream::CloseStream()\r\n{\r\n  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n  _inStreamWithHashSpec->ReleaseStream();\r\n  _fileIsOpen = false;\r\n  Processed.Add(true);\r\n  Sizes.Add(_filePos);\r\n  AddDigest();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 localProcessedSize;\r\n      RINOK(_inStreamWithHash->Read(\r\n          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));\r\n      if (localProcessedSize == 0)\r\n      {\r\n        RINOK(CloseStream());\r\n        continue;\r\n      }\r\n      realProcessedSize += localProcessedSize;\r\n      _filePos += localProcessedSize;\r\n      size -= localProcessedSize;\r\n      break;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenStream());\r\n    }\r\n  }\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)\r\n{\r\n  *value = 0;\r\n  int subStreamIndex = (int)subStream;\r\n  if (subStreamIndex < 0 || subStream > Sizes.Size())\r\n    return E_FAIL;\r\n  if (subStreamIndex < Sizes.Size())\r\n  {\r\n    *value= Sizes[subStreamIndex];\r\n    return S_OK;\r\n  }\r\n  if (!_currentSizeIsDefined)\r\n    return S_FALSE;\r\n  *value = _currentSize;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zFolderInStream.h",
    "content": "// 7z/FolderInStream.h\r\n\r\n#ifndef __7Z_FOLDERINSTREAM_H\r\n#define __7Z_FOLDERINSTREAM_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zHeader.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../Common/InStreamWithCRC.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderInStream:\r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  CFolderInStream();\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\nprivate:\r\n  CSequentialInStreamWithCRC *_inStreamWithHashSpec;\r\n  CMyComPtr<ISequentialInStream> _inStreamWithHash;\r\n  CMyComPtr<IArchiveUpdateCallback> _updateCallback;\r\n\r\n  bool _currentSizeIsDefined;\r\n  UInt64 _currentSize;\r\n\r\n  bool _fileIsOpen;\r\n  UInt64 _filePos;\r\n\r\n  const UInt32 *_fileIndices;\r\n  UInt32 _numFiles;\r\n  UInt32 _fileIndex;\r\n\r\n  HRESULT OpenStream();\r\n  HRESULT CloseStream();\r\n  void AddDigest();\r\npublic:\r\n  void Init(IArchiveUpdateCallback *updateCallback,\r\n      const UInt32 *fileIndices, UInt32 numFiles);\r\n  CRecordVector<bool> Processed;\r\n  CRecordVector<UInt32> CRCs;\r\n  CRecordVector<UInt64> Sizes;\r\n  UInt64 GetFullSize() const\r\n  {\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < Sizes.Size(); i++)\r\n      size += Sizes[i];\r\n    return size;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zFolderOutStream.cpp",
    "content": "// 7zFolderOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderOutStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderOutStream::CFolderOutStream()\r\n{\r\n  _outStreamWithHashSpec = new COutStreamWithCRC;\r\n  _outStreamWithHash = _outStreamWithHashSpec;\r\n}\r\n\r\nHRESULT CFolderOutStream::Init(\r\n    const CArchiveDatabaseEx *archiveDatabase,\r\n    UInt32 ref2Offset,\r\n    UInt32 startIndex,\r\n    const CBoolVector *extractStatuses,\r\n    IArchiveExtractCallback *extractCallback,\r\n    bool testMode,\r\n    bool checkCrc)\r\n{\r\n  _archiveDatabase = archiveDatabase;\r\n  _ref2Offset = ref2Offset;\r\n  _startIndex = startIndex;\r\n\r\n  _extractStatuses = extractStatuses;\r\n  _extractCallback = extractCallback;\r\n  _testMode = testMode;\r\n\r\n  _checkCrc = checkCrc;\r\n\r\n  _currentIndex = 0;\r\n  _fileIsOpen = false;\r\n  return WriteEmptyFiles();\r\n}\r\n\r\nHRESULT CFolderOutStream::OpenFile()\r\n{\r\n  Int32 askMode;\r\n  if((*_extractStatuses)[_currentIndex])\r\n    askMode = _testMode ?\r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n  else\r\n    askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n\r\n  UInt32 index = _startIndex + _currentIndex;\r\n  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));\r\n\r\n  _outStreamWithHashSpec->SetStream(realOutStream);\r\n  _outStreamWithHashSpec->Init(_checkCrc);\r\n  if (askMode == NArchive::NExtract::NAskMode::kExtract &&\r\n      (!realOutStream))\r\n  {\r\n    const CFileItem &fi = _archiveDatabase->Files[index];\r\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir)\r\n      askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  }\r\n  return _extractCallback->PrepareOperation(askMode);\r\n}\r\n\r\nHRESULT CFolderOutStream::WriteEmptyFiles()\r\n{\r\n  for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)\r\n  {\r\n    UInt32 index = _startIndex + _currentIndex;\r\n    const CFileItem &fi = _archiveDatabase->Files[index];\r\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir && fi.Size != 0)\r\n      return S_OK;\r\n    RINOK(OpenFile());\r\n    RINOK(_extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\r\n    _outStreamWithHashSpec->ReleaseStream();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderOutStream::Write(const void *data,\r\n    UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 index = _startIndex + _currentIndex;\r\n      const CFileItem &fi = _archiveDatabase->Files[index];\r\n      UInt64 fileSize = fi.Size;\r\n      \r\n      UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos,\r\n          UInt64(size - realProcessedSize));\r\n      \r\n      UInt32 processedSizeLocal;\r\n      RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize,\r\n            numBytesToWrite, &processedSizeLocal));\r\n\r\n      _filePos += processedSizeLocal;\r\n      realProcessedSize += processedSizeLocal;\r\n      if (_filePos == fileSize)\r\n      {\r\n        bool digestsAreEqual;\r\n        if (fi.CrcDefined && _checkCrc)\r\n          digestsAreEqual = fi.Crc == _outStreamWithHashSpec->GetCRC();\r\n        else\r\n          digestsAreEqual = true;\r\n\r\n        RINOK(_extractCallback->SetOperationResult(\r\n            digestsAreEqual ?\r\n            NArchive::NExtract::NOperationResult::kOK :\r\n            NArchive::NExtract::NOperationResult::kCRCError));\r\n        _outStreamWithHashSpec->ReleaseStream();\r\n        _fileIsOpen = false;\r\n        _currentIndex++;\r\n      }\r\n      if (realProcessedSize == size)\r\n      {\r\n        if (processedSize != NULL)\r\n          *processedSize = realProcessedSize;\r\n        return WriteEmptyFiles();\r\n      }\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n      _filePos = 0;\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)\r\n{\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      RINOK(_extractCallback->SetOperationResult(resultEOperationResult));\r\n      _outStreamWithHashSpec->ReleaseStream();\r\n      _fileIsOpen = false;\r\n      _currentIndex++;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::WasWritingFinished()\r\n{\r\n  if (_currentIndex == _extractStatuses->Size())\r\n    return S_OK;\r\n  return E_FAIL;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zFolderOutStream.h",
    "content": "// 7zFolderOutStream.h\r\n\r\n#ifndef __7Z_FOLDEROUTSTREAM_H\r\n#define __7Z_FOLDEROUTSTREAM_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../IArchive.h\"\r\n#include \"../Common/OutStreamWithCRC.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  \r\n  CFolderOutStream();\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n\r\n  COutStreamWithCRC *_outStreamWithHashSpec;\r\n  CMyComPtr<ISequentialOutStream> _outStreamWithHash;\r\n  const CArchiveDatabaseEx *_archiveDatabase;\r\n  const CBoolVector *_extractStatuses;\r\n  UInt32 _startIndex;\r\n  UInt32 _ref2Offset;\r\n  int _currentIndex;\r\n  // UInt64 _currentDataPos;\r\n  CMyComPtr<IArchiveExtractCallback> _extractCallback;\r\n  bool _testMode;\r\n\r\n  bool _fileIsOpen;\r\n\r\n  bool _checkCrc;\r\n  UInt64 _filePos;\r\n\r\n  HRESULT OpenFile();\r\n  HRESULT WriteEmptyFiles();\r\npublic:\r\n  HRESULT Init(\r\n      const CArchiveDatabaseEx *archiveDatabase,\r\n      UInt32 ref2Offset,\r\n      UInt32 startIndex,\r\n      const CBoolVector *extractStatuses,\r\n      IArchiveExtractCallback *extractCallback,\r\n      bool testMode,\r\n      bool checkCrc);\r\n  HRESULT FlushCorrupted(Int32 resultEOperationResult);\r\n  HRESULT WasWritingFinished();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zHandler.cpp",
    "content": "// 7zHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/CpuArch.h\"\r\n}\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zProperties.h\"\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n#include \"../Common/ParseProperties.h\"\r\n#endif\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nextern UString ConvertMethodIdToString(UInt64 id);\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCHandler::CHandler()\r\n{\r\n  _crcSize = 4;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  _passwordIsDefined = false;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  #else\r\n  Init();\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = _db.Files.Size();\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _SFX\r\n\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,\r\n      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\n\r\n#else\r\n\r\nSTATPROPSTG kArcProps[] =\r\n{\r\n  { NULL, kpidMethod, VT_BSTR},\r\n  { NULL, kpidSolid, VT_BOOL},\r\n  { NULL, kpidNumBlocks, VT_UI4},\r\n  { NULL, kpidPhySize, VT_UI8},\r\n  { NULL, kpidHeadersSize, VT_UI8},\r\n  { NULL, kpidOffset, VT_UI8}\r\n};\r\n\r\nSTDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidMethod:\r\n    {\r\n      UString resString;\r\n      CRecordVector<UInt64> ids;\r\n      int i;\r\n      for (i = 0; i < _db.Folders.Size(); i++)\r\n      {\r\n        const CFolder &f = _db.Folders[i];\r\n        for (int j = f.Coders.Size() - 1; j >= 0; j--)\r\n          ids.AddToUniqueSorted(f.Coders[j].MethodID);\r\n      }\r\n\r\n      for (i = 0; i < ids.Size(); i++)\r\n      {\r\n        UInt64 id = ids[i];\r\n        UString methodName;\r\n        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);\r\n        if (methodName.IsEmpty())\r\n          methodName = ConvertMethodIdToString(id);\r\n        if (!resString.IsEmpty())\r\n          resString += L' ';\r\n        resString += methodName;\r\n      }\r\n      prop = resString;\r\n      break;\r\n    }\r\n    case kpidSolid: prop = _db.IsSolid(); break;\r\n    case kpidNumBlocks: prop = (UInt32)_db.Folders.Size(); break;\r\n    case kpidHeadersSize:  prop = _db.HeadersSize; break;\r\n    case kpidPhySize:  prop = _db.PhySize; break;\r\n    case kpidOffset: if (_db.ArchiveInfo.StartPosition != 0) prop = _db.ArchiveInfo.StartPosition; break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nIMP_IInArchive_ArcProps\r\n\r\n#endif\r\n\r\nstatic void SetPropFromUInt64Def(CUInt64DefVector &v, int index, NCOM::CPropVariant &prop)\r\n{\r\n  UInt64 value;\r\n  if (v.GetItem(index, value))\r\n  {\r\n    FILETIME ft;\r\n    ft.dwLowDateTime = (DWORD)value;\r\n    ft.dwHighDateTime = (DWORD)(value >> 32);\r\n    prop = ft;\r\n  }\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString GetStringForSizeValue(UInt32 value)\r\n{\r\n  for (int i = 31; i >= 0; i--)\r\n    if ((UInt32(1) << i) == value)\r\n      return ConvertUInt32ToString(i);\r\n  UString result;\r\n  if (value % (1 << 20) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 20);\r\n    result += L\"m\";\r\n  }\r\n  else if (value % (1 << 10) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 10);\r\n    result += L\"k\";\r\n  }\r\n  else\r\n  {\r\n    result += ConvertUInt32ToString(value);\r\n    result += L\"b\";\r\n  }\r\n  return result;\r\n}\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_PPMD  = 0x030401;\r\n\r\nstatic wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));\r\n}\r\nstatic inline UString GetHex2(Byte value)\r\n{\r\n  UString result;\r\n  result += GetHex((Byte)(value >> 4));\r\n  result += GetHex((Byte)(value & 0xF));\r\n  return result;\r\n}\r\n\r\n#endif\r\n\r\nstatic const UInt64 k_AES  = 0x06F10701;\r\n\r\nbool CHandler::IsEncrypted(UInt32 index2) const\r\n{\r\n  CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n  if (folderIndex != kNumNoIndex)\r\n  {\r\n    const CFolder &folderInfo = _db.Folders[folderIndex];\r\n    for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n      if (folderInfo.Coders[i].MethodID == k_AES)\r\n        return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  \r\n  /*\r\n  const CRef2 &ref2 = _refs[index];\r\n  if (ref2.Refs.IsEmpty())\r\n    return E_FAIL;\r\n  const CRef &ref = ref2.Refs.Front();\r\n  */\r\n  \r\n  const CFileItem &item = _db.Files[index];\r\n  UInt32 index2 = index;\r\n\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n      if (!item.Name.IsEmpty())\r\n        prop = NItemName::GetOSName(item.Name);\r\n      break;\r\n    case kpidIsDir:  prop = item.IsDir; break;\r\n    case kpidSize:\r\n    {\r\n      prop = item.Size;\r\n      // prop = ref2.Size;\r\n      break;\r\n    }\r\n    case kpidPackSize:\r\n    {\r\n      // prop = ref2.PackSize;\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2)\r\n            prop = _db.GetFolderFullPackSize(folderIndex);\r\n          /*\r\n          else\r\n            prop = (UInt64)0;\r\n          */\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    }\r\n    case kpidPosition:  { UInt64 v; if (_db.StartPos.GetItem(index2, v)) prop = v; break; }\r\n    case kpidCTime:  SetPropFromUInt64Def(_db.CTime, index2, prop); break;\r\n    case kpidATime:  SetPropFromUInt64Def(_db.ATime, index2, prop); break;\r\n    case kpidMTime:  SetPropFromUInt64Def(_db.MTime, index2, prop); break;\r\n    case kpidAttrib:  if (item.AttribDefined) prop = item.Attrib; break;\r\n    case kpidCRC:  if (item.CrcDefined) prop = item.Crc; break;\r\n    case kpidEncrypted:  prop = IsEncrypted(index2); break;\r\n    case kpidIsAnti:  prop = _db.IsItemAnti(index2); break;\r\n    #ifndef _SFX\r\n    case kpidMethod:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _db.Folders[folderIndex];\r\n          UString methodsString;\r\n          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n          {\r\n            const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n            if (!methodsString.IsEmpty())\r\n              methodsString += L' ';\r\n\r\n            {\r\n              UString methodName;\r\n              bool methodIsKnown = FindMethod(\r\n                  EXTERNAL_CODECS_VARS\r\n                  coderInfo.MethodID, methodName);\r\n\r\n              if (methodIsKnown)\r\n              {\r\n                methodsString += methodName;\r\n                if (coderInfo.MethodID == k_LZMA)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 5)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_PPMD)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 5)\r\n                  {\r\n                    Byte order = *(const Byte *)coderInfo.Props;\r\n                    methodsString += L\":o\";\r\n                    methodsString += ConvertUInt32ToString(order);\r\n                    methodsString += L\":mem\";\r\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_AES)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 1)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    const Byte *data = (const Byte *)coderInfo.Props;\r\n                    Byte firstByte = *data++;\r\n                    UInt32 numCyclesPower = firstByte & 0x3F;\r\n                    methodsString += ConvertUInt32ToString(numCyclesPower);\r\n                    /*\r\n                    if ((firstByte & 0xC0) != 0)\r\n                    {\r\n                      methodsString += L\":\";\r\n                      return S_OK;\r\n                      UInt32 saltSize = (firstByte >> 7) & 1;\r\n                      UInt32 ivSize = (firstByte >> 6) & 1;\r\n                      if (coderInfo.Props.GetCapacity() >= 2)\r\n                      {\r\n                        Byte secondByte = *data++;\r\n                        saltSize += (secondByte >> 4);\r\n                        ivSize += (secondByte & 0x0F);\r\n                      }\r\n                    }\r\n                    */\r\n                  }\r\n                }\r\n                else\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() > 0)\r\n                  {\r\n                    methodsString += L\":[\";\r\n                    for (size_t bi = 0; bi < coderInfo.Props.GetCapacity(); bi++)\r\n                    {\r\n                      if (bi > 5 && bi + 1 < coderInfo.Props.GetCapacity())\r\n                      {\r\n                        methodsString += L\"..\";\r\n                        break;\r\n                      }\r\n                      else\r\n                        methodsString += GetHex2(coderInfo.Props[bi]);\r\n                    }\r\n                    methodsString += L\"]\";\r\n                  }\r\n                }\r\n              }\r\n              else\r\n              {\r\n                methodsString += ConvertMethodIdToString(coderInfo.MethodID);\r\n              }\r\n            }\r\n          }\r\n          prop = methodsString;\r\n        }\r\n      }\r\n      break;\r\n    case kpidBlock:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n          prop = (UInt32)folderIndex;\r\n      }\r\n      break;\r\n    case kpidPackedSize0:\r\n    case kpidPackedSize1:\r\n    case kpidPackedSize2:\r\n    case kpidPackedSize3:\r\n    case kpidPackedSize4:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _db.Folders[folderIndex];\r\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 &&\r\n              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))\r\n          {\r\n            prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);\r\n          }\r\n          else\r\n            prop = (UInt64)0;\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    #endif\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 *maxCheckStartPosition,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Clear();\r\n  #endif\r\n  try\r\n  {\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(\r\n          IID_ICryptoGetTextPassword, &getTextPassword);\r\n    }\r\n    #endif\r\n    CInArchive archive;\r\n    RINOK(archive.Open(stream, maxCheckStartPosition));\r\n    #ifndef _NO_CRYPTO\r\n    _passwordIsDefined = false;\r\n    UString password;\r\n    #endif\r\n    HRESULT result = archive.ReadDatabase(\r\n      EXTERNAL_CODECS_VARS\r\n      _db\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, _passwordIsDefined\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    _db.Fill();\r\n    _inStream = stream;\r\n  }\r\n  catch(...)\r\n  {\r\n    Close();\r\n    return S_FALSE;\r\n  }\r\n  // _inStream = stream;\r\n  #ifndef _SFX\r\n  FillPopIDs();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  COM_TRY_BEGIN\r\n  _inStream.Release();\r\n  _db.Clear();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef COMPRESS_MT\r\n  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();\r\n  _numThreads = numProcessors;\r\n  #endif\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    const PROPVARIANT &value = values[i];\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index == 0)\r\n    {\r\n      if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n      {\r\n        #ifdef COMPRESS_MT\r\n        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n        #endif\r\n        continue;\r\n      }\r\n      else\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#endif\r\n#endif\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zHandler.h",
    "content": "// 7z/Handler.h\r\n\r\n#ifndef __7Z_HANDLER_H\r\n#define __7Z_HANDLER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../IArchive.h\"\r\n#include \"7zIn.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#ifndef EXTRACT_ONLY\r\n#include \"../Common/HandlerOut.h\"\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\n#ifndef __7Z_SET_PROPERTIES\r\n\r\n#ifdef EXTRACT_ONLY\r\n#ifdef COMPRESS_MT\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n#else\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n\r\n#endif\r\n\r\n\r\nclass CHandler:\r\n  #ifndef EXTRACT_ONLY\r\n  public NArchive::COutHandler,\r\n  #endif\r\n  public IInArchive,\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  public ISetProperties,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public IOutArchive,\r\n  #endif\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IInArchive)\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  MY_QUERYINTERFACE_ENTRY(ISetProperties)\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  MY_QUERYINTERFACE_ENTRY(IOutArchive)\r\n  #endif\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);\r\n  #endif\r\n\r\n  #ifndef EXTRACT_ONLY\r\n  INTERFACE_IOutArchive(;)\r\n  #endif\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n  CHandler();\r\n\r\nprivate:\r\n  CMyComPtr<IInStream> _inStream;\r\n  NArchive::N7z::CArchiveDatabaseEx _db;\r\n  #ifndef _NO_CRYPTO\r\n  bool _passwordIsDefined;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  \r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  #else\r\n  \r\n  CRecordVector<CBind> _binds;\r\n\r\n  HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);\r\n\r\n  HRESULT SetCompressionMethod(CCompressionMethodMode &method,\r\n      CObjectVector<COneMethodInfo> &methodsInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  HRESULT SetCompressionMethod(\r\n      CCompressionMethodMode &method,\r\n      CCompressionMethodMode &headerMethod);\r\n\r\n  #endif\r\n\r\n  bool IsEncrypted(UInt32 index2) const;\r\n  #ifndef _SFX\r\n\r\n  CRecordVector<UInt64> _fileInfoPopIDs;\r\n  void FillPopIDs();\r\n\r\n  #endif\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zHandlerOut.cpp",
    "content": "// 7zHandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const UInt32 kLzmaAlgorithmX5 = 1;\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5;\r\n\r\nstatic inline bool IsCopyMethod(const UString &methodName)\r\n  { return (methodName.CompareNoCase(kCopyMethod) == 0); }\r\n\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  CMyComPtr<ICryptoGetTextPassword2> getTextPassword;\r\n  if (!getTextPassword)\r\n  {\r\n    CMyComPtr<IArchiveUpdateCallback> udateCallback2(updateCallback);\r\n    udateCallback2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);\r\n  }\r\n  \r\n  if (getTextPassword)\r\n  {\r\n    CMyComBSTR password;\r\n    Int32 passwordIsDefined;\r\n    RINOK(getTextPassword->CryptoGetTextPassword2(\r\n        &passwordIsDefined, &password));\r\n    methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);\r\n    if (methodMode.PasswordIsDefined)\r\n      methodMode.Password = password;\r\n  }\r\n  else\r\n    methodMode.PasswordIsDefined = false;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CCompressionMethodMode &headerMethod)\r\n{\r\n  HRESULT res = SetCompressionMethod(methodMode, _methods\r\n  #ifdef COMPRESS_MT\r\n  , _numThreads\r\n  #endif\r\n  );\r\n  RINOK(res);\r\n  methodMode.Binds = _binds;\r\n\r\n  if (_compressHeaders)\r\n  {\r\n    // headerMethod.Methods.Add(methodMode.Methods.Back());\r\n\r\n    CObjectVector<COneMethodInfo> headerMethodInfoVector;\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = kLZMAMethodName;\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kMatchFinder;\r\n      prop.Value = kLzmaMatchFinderForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kAlgorithm;\r\n      prop.Value = kAlgorithmForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kNumFastBytes;\r\n      prop.Value = (UInt32)kNumFastBytesForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = (UInt32)kDictionaryForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    headerMethodInfoVector.Add(oneMethodInfo);\r\n    HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector\r\n      #ifdef COMPRESS_MT\r\n      ,1\r\n      #endif\r\n    );\r\n    RINOK(res);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CObjectVector<COneMethodInfo> &methodsInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  \r\n  if (methodsInfo.IsEmpty())\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = ((level == 0) ? kCopyMethod : kDefaultMethodName);\r\n    methodsInfo.Add(oneMethodInfo);\r\n  }\r\n\r\n  bool needSolid = false;\r\n  for(int i = 0; i < methodsInfo.Size(); i++)\r\n  {\r\n    COneMethodInfo &oneMethodInfo = methodsInfo[i];\r\n    SetCompressionMethod2(oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , numThreads\r\n      #endif\r\n      );\r\n\r\n    if (!IsCopyMethod(oneMethodInfo.MethodName))\r\n      needSolid = true;\r\n\r\n    CMethodFull methodFull;\r\n\r\n    if (!FindMethod(\r\n        EXTERNAL_CODECS_VARS\r\n        oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams))\r\n      return E_INVALIDARG;\r\n    methodFull.Props = oneMethodInfo.Props;\r\n    methodMode.Methods.Add(methodFull);\r\n\r\n    if (!_numSolidBytesDefined)\r\n    {\r\n      for (int j = 0; j < methodFull.Props.Size(); j++)\r\n      {\r\n        const CProp &prop = methodFull.Props[j];\r\n        if ((prop.Id == NCoderPropID::kDictionarySize ||\r\n             prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4)\r\n        {\r\n          _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7;\r\n          const UInt64 kMinSize = (1 << 24);\r\n          if (_numSolidBytes < kMinSize)\r\n            _numSolidBytes = kMinSize;\r\n          _numSolidBytesDefined = true;\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (!needSolid && !_numSolidBytesDefined)\r\n  {\r\n    _numSolidBytesDefined = true;\r\n    _numSolidBytes  = 0;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, bool writeTime, PROPID propID, UInt64 &ft, bool &ftDefined)\r\n{\r\n  ft = 0;\r\n  ftDefined = false;\r\n  if (!writeTime)\r\n    return S_OK;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(updateCallback->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    ft = prop.filetime.dwLowDateTime | ((UInt64)prop.filetime.dwHighDateTime << 32);\r\n    ftDefined = true;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  const CArchiveDatabaseEx *db = 0;\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() > 1)\r\n    return E_FAIL;\r\n  const CVolume *volume = 0;\r\n  if (_volumes.Size() == 1)\r\n  {\r\n    volume = &_volumes.Front();\r\n    db = &volume->Database;\r\n  }\r\n  #else\r\n  if (_inStream != 0)\r\n    db = &_db;\r\n  #endif\r\n\r\n  CObjectVector<CUpdateItem> updateItems;\r\n  \r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    Int32 newData;\r\n    Int32 newProperties;\r\n    UInt32 indexInArchive;\r\n    if (!updateCallback)\r\n      return E_FAIL;\r\n    RINOK(updateCallback->GetUpdateItemInfo(i, &newData, &newProperties, &indexInArchive));\r\n    CUpdateItem ui;\r\n    ui.NewProperties = IntToBool(newProperties);\r\n    ui.NewData = IntToBool(newData);\r\n    ui.IndexInArchive = indexInArchive;\r\n    ui.IndexInClient = i;\r\n    ui.IsAnti = false;\r\n    ui.Size = 0;\r\n\r\n    if (ui.IndexInArchive != -1)\r\n    {\r\n      const CFileItem &fi = db->Files[ui.IndexInArchive];\r\n      ui.Name = fi.Name;\r\n      ui.IsDir = fi.IsDir;\r\n      ui.Size = fi.Size;\r\n      ui.IsAnti = db->IsItemAnti(ui.IndexInArchive);\r\n      \r\n      ui.CTimeDefined = db->CTime.GetItem(ui.IndexInArchive, ui.CTime);\r\n      ui.ATimeDefined = db->ATime.GetItem(ui.IndexInArchive, ui.ATime);\r\n      ui.MTimeDefined = db->MTime.GetItem(ui.IndexInArchive, ui.MTime);\r\n    }\r\n\r\n    if (ui.NewProperties)\r\n    {\r\n      bool nameIsDefined;\r\n      bool folderStatusIsDefined;\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidAttrib, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          ui.AttribDefined = false;\r\n        else if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.Attrib = prop.ulVal;\r\n          ui.AttribDefined = true;\r\n        }\r\n      }\r\n      \r\n      // we need MTime to sort files.\r\n      RINOK(GetTime(updateCallback, i, WriteCTime, kpidCTime, ui.CTime, ui.CTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, WriteATime, kpidATime, ui.ATime, ui.ATimeDefined));\r\n      RINOK(GetTime(updateCallback, i, true,       kpidMTime, ui.MTime, ui.MTimeDefined));\r\n\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidPath, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          nameIsDefined = false;\r\n        else if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.Name = NItemName::MakeLegalName(prop.bstrVal);\r\n          nameIsDefined = true;\r\n        }\r\n      }\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsDir, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          folderStatusIsDefined = false;\r\n        else if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.IsDir = (prop.boolVal != VARIANT_FALSE);\r\n          folderStatusIsDefined = true;\r\n        }\r\n      }\r\n\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsAnti, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          ui.IsAnti = false;\r\n        else if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n          ui.IsAnti = (prop.boolVal != VARIANT_FALSE);\r\n      }\r\n\r\n      if (ui.IsAnti)\r\n      {\r\n        ui.AttribDefined = false;\r\n\r\n        ui.CTimeDefined = false;\r\n        ui.ATimeDefined = false;\r\n        ui.MTimeDefined = false;\r\n        \r\n        ui.Size = 0;\r\n      }\r\n\r\n      if (!folderStatusIsDefined && ui.AttribDefined)\r\n        ui.SetDirStatusFromAttrib();\r\n    }\r\n\r\n    if (ui.NewData)\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(i, kpidSize, &prop));\r\n      if (prop.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      ui.Size = (UInt64)prop.uhVal.QuadPart;\r\n      if (ui.Size != 0 && ui.IsAnti)\r\n        return E_INVALIDARG;\r\n    }\r\n    updateItems.Add(ui);\r\n  }\r\n\r\n  CCompressionMethodMode methodMode, headerMethod;\r\n  RINOK(SetCompressionMethod(methodMode, headerMethod));\r\n  #ifdef COMPRESS_MT\r\n  methodMode.NumThreads = _numThreads;\r\n  headerMethod.NumThreads = 1;\r\n  #endif\r\n\r\n  RINOK(SetPassword(methodMode, updateCallback));\r\n\r\n  bool compressMainHeader = _compressHeaders;  // check it\r\n\r\n  bool encryptHeaders = false;\r\n\r\n  if (methodMode.PasswordIsDefined)\r\n  {\r\n    if (_encryptHeadersSpecified)\r\n      encryptHeaders = _encryptHeaders;\r\n    #ifndef _NO_CRYPTO\r\n    else\r\n      encryptHeaders = _passwordIsDefined;\r\n    #endif\r\n    compressMainHeader = true;\r\n    if(encryptHeaders)\r\n      RINOK(SetPassword(headerMethod, updateCallback));\r\n  }\r\n\r\n  if (numItems < 2)\r\n    compressMainHeader = false;\r\n\r\n  CUpdateOptions options;\r\n  options.Method = &methodMode;\r\n  options.HeaderMethod = (_compressHeaders || encryptHeaders) ? &headerMethod : 0;\r\n  options.UseFilters = _level != 0 && _autoFilter;\r\n  options.MaxFilter = _level >= 8;\r\n\r\n  options.HeaderOptions.CompressMainHeader = compressMainHeader;\r\n  options.HeaderOptions.WriteCTime = WriteCTime;\r\n  options.HeaderOptions.WriteATime = WriteATime;\r\n  options.HeaderOptions.WriteMTime = WriteMTime;\r\n  \r\n  options.NumSolidFiles = _numSolidFiles;\r\n  options.NumSolidBytes = _numSolidBytes;\r\n  options.SolidExtension = _solidExtension;\r\n  options.RemoveSfxBlock = _removeSfxBlock;\r\n  options.VolumeMode = _volumeMode;\r\n\r\n  COutArchive archive;\r\n  CArchiveDatabase newDatabase;\r\n  HRESULT res = Update(\r\n      EXTERNAL_CODECS_VARS\r\n      #ifdef _7Z_VOL\r\n      volume ? volume->Stream: 0,\r\n      volume ? db : 0,\r\n      #else\r\n      _inStream,\r\n      db,\r\n      #endif\r\n      updateItems,\r\n      archive, newDatabase, outStream, updateCallback, options);\r\n\r\n  RINOK(res);\r\n\r\n  updateItems.ClearAndFree();\r\n\r\n  return archive.WriteDatabase(EXTERNAL_CODECS_VARS\r\n      newDatabase, options.HeaderMethod, options.HeaderOptions);\r\n\r\n  COM_TRY_END\r\n}\r\n\r\nstatic HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)\r\n{\r\n  stream = 0;\r\n  int index = ParseStringToUInt32(srcString, coder);\r\n  if (index == 0)\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0, index);\r\n  if (srcString[0] == 'S')\r\n  {\r\n    srcString.Delete(0);\r\n    int index = ParseStringToUInt32(srcString, stream);\r\n    if (index == 0)\r\n      return E_INVALIDARG;\r\n    srcString.Delete(0, index);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetBindInfo(UString &srcString, CBind &bind)\r\n{\r\n  RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream));\r\n  if (srcString[0] != ':')\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0);\r\n  RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream));\r\n  if (!srcString.IsEmpty())\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  _binds.Clear();\r\n  BeforeSetProperty();\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n\r\n    const PROPVARIANT &value = values[i];\r\n\r\n    if (name[0] == 'B')\r\n    {\r\n      name.Delete(0);\r\n      CBind bind;\r\n      RINOK(GetBindInfo(name, bind));\r\n      _binds.Add(bind);\r\n      continue;\r\n    }\r\n\r\n    RINOK(SetProperty(name, value));\r\n  }\r\n\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zHeader.cpp",
    "content": "// 7z/Header.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nByte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n#ifdef _7Z_VOL\r\nByte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};\r\n#endif\r\n\r\nclass SignatureInitializer\r\n{\r\npublic:\r\n  SignatureInitializer()\r\n  {\r\n    kSignature[0]--;\r\n    #ifdef _7Z_VOL\r\n    kFinishSignature[0]--;\r\n    #endif\r\n  };\r\n} g_SignatureInitializer;\r\n\r\n}}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zHeader.h",
    "content": "// 7z/7zHeader.h\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nconst int kSignatureSize = 6;\r\nextern Byte kSignature[kSignatureSize];\r\n\r\n// #define _7Z_VOL\r\n// 7z-MultiVolume is not finished yet.\r\n// It can work already, but I still do not like some\r\n// things of that new multivolume format.\r\n// So please keep it commented.\r\n\r\n#ifdef _7Z_VOL\r\nextern Byte kFinishSignature[kSignatureSize];\r\n#endif\r\n\r\nstruct CArchiveVersion\r\n{\r\n  Byte Major;\r\n  Byte Minor;\r\n};\r\n\r\nconst Byte kMajorVersion = 0;\r\n\r\nstruct CStartHeader\r\n{\r\n  UInt64 NextHeaderOffset;\r\n  UInt64 NextHeaderSize;\r\n  UInt32 NextHeaderCRC;\r\n};\r\n\r\nconst UInt32 kStartHeaderSize = 20;\r\n\r\n#ifdef _7Z_VOL\r\nstruct CFinishHeader: public CStartHeader\r\n{\r\n  UInt64 ArchiveStartOffset;  // data offset from end if that struct\r\n  UInt64 AdditionalStartBlockSize; // start  signature & start header size\r\n};\r\n\r\nconst UInt32 kFinishHeaderSize = kStartHeaderSize + 16;\r\n#endif\r\n\r\nnamespace NID\r\n{\r\n  enum EEnum\r\n  {\r\n    kEnd,\r\n\r\n    kHeader,\r\n\r\n    kArchiveProperties,\r\n    \r\n    kAdditionalStreamsInfo,\r\n    kMainStreamsInfo,\r\n    kFilesInfo,\r\n    \r\n    kPackInfo,\r\n    kUnpackInfo,\r\n    kSubStreamsInfo,\r\n\r\n    kSize,\r\n    kCRC,\r\n\r\n    kFolder,\r\n\r\n    kCodersUnpackSize,\r\n    kNumUnpackStream,\r\n\r\n    kEmptyStream,\r\n    kEmptyFile,\r\n    kAnti,\r\n\r\n    kName,\r\n    kCTime,\r\n    kATime,\r\n    kMTime,\r\n    kWinAttributes,\r\n    kComment,\r\n\r\n    kEncodedHeader,\r\n\r\n    kStartPos,\r\n    kDummy\r\n  };\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zIn.cpp",
    "content": "// 7zIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/7zCrc.h\"\r\n  #include \"../../../../C/CpuArch.h\"\r\n}\r\n\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"7zDecode.h\"\r\n#include \"7zIn.h\"\r\n\r\n#define Get16(p) GetUi16(p)\r\n#define Get32(p) GetUi32(p)\r\n#define Get64(p) GetUi64(p)\r\n\r\n// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader\r\n#ifndef _SFX\r\n#define FORMAT_7Z_RECOVERY\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void BoolVector_Fill_False(CBoolVector &v, int size)\r\n{\r\n  v.Clear();\r\n  v.Reserve(size);\r\n  for (int i = 0; i < size; i++)\r\n    v.Add(false);\r\n}\r\n\r\nstatic bool BoolVector_GetAndSet(CBoolVector &v, UInt32 index)\r\n{\r\n  if (index >= (UInt32)v.Size())\r\n    return true;\r\n  bool res = v[index];\r\n  v[index] = true;\r\n  return res;\r\n}\r\n\r\nbool CFolder::CheckStructure() const\r\n{\r\n  const int kNumCodersMax = sizeof(UInt32) * 8; // don't change it\r\n  const int kMaskSize = sizeof(UInt32) * 8; // it must be >= kNumCodersMax\r\n  const int kNumBindsMax = 32;\r\n\r\n  if (Coders.Size() > kNumCodersMax || BindPairs.Size() > kNumBindsMax)\r\n    return false;\r\n\r\n  {\r\n    CBoolVector v;\r\n    BoolVector_Fill_False(v, BindPairs.Size() + PackStreams.Size());\r\n    \r\n    int i;\r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, BindPairs[i].InIndex))\r\n        return false;\r\n    for (i = 0; i < PackStreams.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, PackStreams[i]))\r\n        return false;\r\n    \r\n    BoolVector_Fill_False(v, UnpackSizes.Size());\r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, BindPairs[i].OutIndex))\r\n        return false;\r\n  }\r\n  \r\n  UInt32 mask[kMaskSize];\r\n  int i;\r\n  for (i = 0; i < kMaskSize; i++)\r\n    mask[i] = 0;\r\n\r\n  {\r\n    CIntVector inStreamToCoder, outStreamToCoder;\r\n    for (i = 0; i < Coders.Size(); i++)\r\n    {\r\n      CNum j;\r\n      const CCoderInfo &coder = Coders[i];\r\n      for (j = 0; j < coder.NumInStreams; j++)\r\n        inStreamToCoder.Add(i);\r\n      for (j = 0; j < coder.NumOutStreams; j++)\r\n        outStreamToCoder.Add(i);\r\n    }\r\n    \r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n    {\r\n      const CBindPair &bp = BindPairs[i];\r\n      mask[inStreamToCoder[bp.InIndex]] |= (1 << outStreamToCoder[bp.OutIndex]);\r\n    }\r\n  }\r\n  \r\n  for (i = 0; i < kMaskSize; i++)\r\n    for (int j = 0; j < kMaskSize; j++)\r\n      if (((1 << j) & mask[i]) != 0)\r\n        mask[i] |= mask[j];\r\n\r\n  for (i = 0; i < kMaskSize; i++)\r\n    if (((1 << i) & mask[i]) != 0)\r\n      return false;\r\n\r\n  return true;\r\n}\r\n\r\nclass CInArchiveException {};\r\n\r\nstatic void ThrowException() { throw CInArchiveException(); }\r\nstatic inline void ThrowEndOfData()   { ThrowException(); }\r\nstatic inline void ThrowUnsupported() { ThrowException(); }\r\nstatic inline void ThrowIncorrect()   { ThrowException(); }\r\nstatic inline void ThrowUnsupportedVersion() { ThrowException(); }\r\n\r\n/*\r\nclass CInArchiveException\r\n{\r\npublic:\r\n  enum CCauseType\r\n  {\r\n    kUnsupportedVersion = 0,\r\n    kUnsupported,\r\n    kIncorrect,\r\n    kEndOfData,\r\n  } Cause;\r\n  CInArchiveException(CCauseType cause): Cause(cause) {};\r\n};\r\n\r\nstatic void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }\r\nstatic void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }\r\nstatic void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }\r\nstatic void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }\r\nstatic void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }\r\n*/\r\n\r\nclass CStreamSwitch\r\n{\r\n  CInArchive *_archive;\r\n  bool _needRemove;\r\npublic:\r\n  CStreamSwitch(): _needRemove(false) {}\r\n  ~CStreamSwitch() { Remove(); }\r\n  void Remove();\r\n  void Set(CInArchive *archive, const Byte *data, size_t size);\r\n  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);\r\n  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);\r\n};\r\n\r\nvoid CStreamSwitch::Remove()\r\n{\r\n  if (_needRemove)\r\n  {\r\n    _archive->DeleteByteStream();\r\n    _needRemove = false;\r\n  }\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)\r\n{\r\n  Remove();\r\n  _archive = archive;\r\n  _archive->AddByteStream(data, size);\r\n  _needRemove = true;\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)\r\n{\r\n  Set(archive, byteBuffer, byteBuffer.GetCapacity());\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)\r\n{\r\n  Remove();\r\n  Byte external = archive->ReadByte();\r\n  if (external != 0)\r\n  {\r\n    int dataIndex = (int)archive->ReadNum();\r\n    if (dataIndex < 0 || dataIndex >= dataVector->Size())\r\n      ThrowIncorrect();\r\n    Set(archive, (*dataVector)[dataIndex]);\r\n  }\r\n}\r\n\r\nByte CInByte2::ReadByte()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  return _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::ReadBytes(Byte *data, size_t size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  for (size_t i = 0; i < size; i++)\r\n    data[i] = _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::SkeepData(UInt64 size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  _pos += (size_t)size;\r\n}\r\n\r\nvoid CInByte2::SkeepData()\r\n{\r\n  SkeepData(ReadNumber());\r\n}\r\n\r\nUInt64 CInByte2::ReadNumber()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  Byte firstByte = _buffer[_pos++];\r\n  Byte mask = 0x80;\r\n  UInt64 value = 0;\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      value += (highPart << (i * 8));\r\n      return value;\r\n    }\r\n    if (_pos >= _size)\r\n      ThrowEndOfData();\r\n    value |= ((UInt64)_buffer[_pos++] << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return value;\r\n}\r\n\r\nCNum CInByte2::ReadNum()\r\n{\r\n  UInt64 value = ReadNumber();\r\n  if (value > kNumMax)\r\n    ThrowUnsupported();\r\n  return (CNum)value;\r\n}\r\n\r\nUInt32 CInByte2::ReadUInt32()\r\n{\r\n  if (_pos + 4 > _size)\r\n    ThrowEndOfData();\r\n  UInt32 res = Get32(_buffer + _pos);\r\n  _pos += 4;\r\n  return res;\r\n}\r\n\r\nUInt64 CInByte2::ReadUInt64()\r\n{\r\n  if (_pos + 8 > _size)\r\n    ThrowEndOfData();\r\n  UInt64 res = Get64(_buffer + _pos);\r\n  _pos += 8;\r\n  return res;\r\n}\r\n\r\nvoid CInByte2::ReadString(UString &s)\r\n{\r\n  const Byte *buf = _buffer + _pos;\r\n  size_t rem = (_size - _pos) / 2 * 2;\r\n  {\r\n    size_t i;\r\n    for (i = 0; i < rem; i += 2)\r\n      if (buf[i] == 0 && buf[i + 1] == 0)\r\n        break;\r\n    if (i == rem)\r\n      ThrowEndOfData();\r\n    rem = i;\r\n  }\r\n  int len = (int)(rem / 2);\r\n  if (len < 0 || (size_t)len * 2 != rem)\r\n    ThrowUnsupported();\r\n  wchar_t *p = s.GetBuffer(len);\r\n  int i;\r\n  for (i = 0; i < len; i++, buf += 2)\r\n    p[i] = (wchar_t)Get16(buf);\r\n  s.ReleaseBuffer(len);\r\n  _pos += rem + 2;\r\n}\r\n\r\nstatic inline bool TestSignatureCandidate(const Byte *p)\r\n{\r\n  for (int i = 0; i < kSignatureSize; i++)\r\n    if (p[i] != kSignature[i])\r\n      return false;\r\n  return (p[0x1A] == 0 && p[0x1B] == 0);\r\n}\r\n\r\nHRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));\r\n\r\n  if (TestSignatureCandidate(_header))\r\n    return S_OK;\r\n\r\n  CByteBuffer byteBuffer;\r\n  const UInt32 kBufferSize = (1 << 16);\r\n  byteBuffer.SetCapacity(kBufferSize);\r\n  Byte *buffer = byteBuffer;\r\n  UInt32 numPrevBytes = kHeaderSize - 1;\r\n  memcpy(buffer, _header + 1, numPrevBytes);\r\n  UInt64 curTestPos = _arhiveBeginStreamPosition + 1;\r\n  for (;;)\r\n  {\r\n    if (searchHeaderSizeLimit != NULL)\r\n      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)\r\n        break;\r\n    do\r\n    {\r\n      UInt32 numReadBytes = kBufferSize - numPrevBytes;\r\n      UInt32 processedSize;\r\n      RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));\r\n      numPrevBytes += processedSize;\r\n      if (processedSize == 0)\r\n        return S_FALSE;\r\n    }\r\n    while (numPrevBytes < kHeaderSize);\r\n    UInt32 numTests = numPrevBytes - kHeaderSize + 1;\r\n    for (UInt32 pos = 0; pos < numTests; pos++)\r\n    {\r\n      for (; buffer[pos] != '7' && pos < numTests; pos++);\r\n      if (pos == numTests)\r\n        break;\r\n      if (TestSignatureCandidate(buffer + pos))\r\n      {\r\n        memcpy(_header, buffer + pos, kHeaderSize);\r\n        curTestPos += pos;\r\n        _arhiveBeginStreamPosition = curTestPos;\r\n        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);\r\n      }\r\n    }\r\n    curTestPos += numTests;\r\n    numPrevBytes -= numTests;\r\n    memmove(buffer, buffer + numTests, numPrevBytes);\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\n// S_FALSE means that file is not archive\r\nHRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  HeadersSize = 0;\r\n  Close();\r\n  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))\r\n  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));\r\n  _stream = stream;\r\n  return S_OK;\r\n}\r\n  \r\nvoid CInArchive::Close()\r\n{\r\n  _stream.Release();\r\n}\r\n\r\nvoid CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)\r\n{\r\n  for (;;)\r\n  {\r\n    if (ReadID() == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::GetNextFolderItem(CFolder &folder)\r\n{\r\n  CNum numCoders = ReadNum();\r\n\r\n  folder.Coders.Clear();\r\n  folder.Coders.Reserve((int)numCoders);\r\n  CNum numInStreams = 0;\r\n  CNum numOutStreams = 0;\r\n  CNum i;\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    folder.Coders.Add(CCoderInfo());\r\n    CCoderInfo &coder = folder.Coders.Back();\r\n\r\n    {\r\n      Byte mainByte = ReadByte();\r\n      int idSize = (mainByte & 0xF);\r\n      Byte longID[15];\r\n      ReadBytes(longID, idSize);\r\n      if (idSize > 8)\r\n        ThrowUnsupported();\r\n      UInt64 id = 0;\r\n      for (int j = 0; j < idSize; j++)\r\n        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n      coder.MethodID = id;\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        coder.NumInStreams = ReadNum();\r\n        coder.NumOutStreams = ReadNum();\r\n      }\r\n      else\r\n      {\r\n        coder.NumInStreams = 1;\r\n        coder.NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        CNum propsSize = ReadNum();\r\n        coder.Props.SetCapacity((size_t)propsSize);\r\n        ReadBytes((Byte *)coder.Props, (size_t)propsSize);\r\n      }\r\n      if ((mainByte & 0x80) != 0)\r\n        ThrowUnsupported();\r\n    }\r\n    numInStreams += coder.NumInStreams;\r\n    numOutStreams += coder.NumOutStreams;\r\n  }\r\n\r\n  CNum numBindPairs = numOutStreams - 1;\r\n  folder.BindPairs.Clear();\r\n  folder.BindPairs.Reserve(numBindPairs);\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair bp;\r\n    bp.InIndex = ReadNum();\r\n    bp.OutIndex = ReadNum();\r\n    folder.BindPairs.Add(bp);\r\n  }\r\n\r\n  if (numInStreams < numBindPairs)\r\n    ThrowUnsupported();\r\n  CNum numPackStreams = numInStreams - numBindPairs;\r\n  folder.PackStreams.Reserve(numPackStreams);\r\n  if (numPackStreams == 1)\r\n  {\r\n    for (i = 0; i < numInStreams; i++)\r\n      if (folder.FindBindPairForInStream(i) < 0)\r\n      {\r\n        folder.PackStreams.Add(i);\r\n        break;\r\n      }\r\n    if (folder.PackStreams.Size() != 1)\r\n      ThrowUnsupported();\r\n  }\r\n  else\r\n    for (i = 0; i < numPackStreams; i++)\r\n      folder.PackStreams.Add(ReadNum());\r\n}\r\n\r\nvoid CInArchive::WaitAttribute(UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == attribute)\r\n      return;\r\n    if (type == NID::kEnd)\r\n      ThrowIncorrect();\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadHashDigests(int numItems,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  ReadBoolVector2(numItems, digestsDefined);\r\n  digests.Clear();\r\n  digests.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 crc = 0;\r\n    if (digestsDefined[i])\r\n      crc = ReadUInt32();\r\n    digests.Add(crc);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadPackInfo(\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CBoolVector &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs)\r\n{\r\n  dataOffset = ReadNumber();\r\n  CNum numPackStreams = ReadNum();\r\n\r\n  WaitAttribute(NID::kSize);\r\n  packSizes.Clear();\r\n  packSizes.Reserve(numPackStreams);\r\n  for (CNum i = 0; i < numPackStreams; i++)\r\n    packSizes.Add(ReadNumber());\r\n\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    if (type == NID::kCRC)\r\n    {\r\n      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs);\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n  if (packCRCsDefined.IsEmpty())\r\n  {\r\n    BoolVector_Fill_False(packCRCsDefined, numPackStreams);\r\n    packCRCs.Reserve(numPackStreams);\r\n    packCRCs.Clear();\r\n    for (CNum i = 0; i < numPackStreams; i++)\r\n      packCRCs.Add(0);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadUnpackInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    CObjectVector<CFolder> &folders)\r\n{\r\n  WaitAttribute(NID::kFolder);\r\n  CNum numFolders = ReadNum();\r\n\r\n  {\r\n    CStreamSwitch streamSwitch;\r\n    streamSwitch.Set(this, dataVector);\r\n    folders.Clear();\r\n    folders.Reserve(numFolders);\r\n    for (CNum i = 0; i < numFolders; i++)\r\n    {\r\n      folders.Add(CFolder());\r\n      GetNextFolderItem(folders.Back());\r\n    }\r\n  }\r\n\r\n  WaitAttribute(NID::kCodersUnpackSize);\r\n\r\n  CNum i;\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    CFolder &folder = folders[i];\r\n    CNum numOutStreams = folder.GetNumOutStreams();\r\n    folder.UnpackSizes.Reserve(numOutStreams);\r\n    for (CNum j = 0; j < numOutStreams; j++)\r\n      folder.UnpackSizes.Add(ReadNumber());\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      return;\r\n    if (type == NID::kCRC)\r\n    {\r\n      CBoolVector crcsDefined;\r\n      CRecordVector<UInt32> crcs;\r\n      ReadHashDigests(numFolders, crcsDefined, crcs);\r\n      for (i = 0; i < numFolders; i++)\r\n      {\r\n        CFolder &folder = folders[i];\r\n        folder.UnpackCRCDefined = crcsDefined[i];\r\n        folder.UnpackCRC = crcs[i];\r\n      }\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    CRecordVector<UInt64> &unpackSizes,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  numUnpackStreamsInFolders.Clear();\r\n  numUnpackStreamsInFolders.Reserve(folders.Size());\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kNumUnpackStream)\r\n    {\r\n      for (int i = 0; i < folders.Size(); i++)\r\n        numUnpackStreamsInFolders.Add(ReadNum());\r\n      continue;\r\n    }\r\n    if (type == NID::kCRC || type == NID::kSize)\r\n      break;\r\n    if (type == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n\r\n  if (numUnpackStreamsInFolders.IsEmpty())\r\n    for (int i = 0; i < folders.Size(); i++)\r\n      numUnpackStreamsInFolders.Add(1);\r\n\r\n  int i;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n  {\r\n    // v3.13 incorrectly worked with empty folders\r\n    // v4.07: we check that folder is empty\r\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    UInt64 sum = 0;\r\n    for (CNum j = 1; j < numSubstreams; j++)\r\n      if (type == NID::kSize)\r\n      {\r\n        UInt64 size = ReadNumber();\r\n        unpackSizes.Add(size);\r\n        sum += size;\r\n      }\r\n    unpackSizes.Add(folders[i].GetUnpackSize() - sum);\r\n  }\r\n  if (type == NID::kSize)\r\n    type = ReadID();\r\n\r\n  int numDigests = 0;\r\n  int numDigestsTotal = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\r\n      numDigests += numSubstreams;\r\n    numDigestsTotal += numSubstreams;\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    if (type == NID::kCRC)\r\n    {\r\n      CBoolVector digestsDefined2;\r\n      CRecordVector<UInt32> digests2;\r\n      ReadHashDigests(numDigests, digestsDefined2, digests2);\r\n      int digestIndex = 0;\r\n      for (i = 0; i < folders.Size(); i++)\r\n      {\r\n        CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n        const CFolder &folder = folders[i];\r\n        if (numSubstreams == 1 && folder.UnpackCRCDefined)\r\n        {\r\n          digestsDefined.Add(true);\r\n          digests.Add(folder.UnpackCRC);\r\n        }\r\n        else\r\n          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)\r\n          {\r\n            digestsDefined.Add(digestsDefined2[digestIndex]);\r\n            digests.Add(digests2[digestIndex]);\r\n          }\r\n      }\r\n    }\r\n    else if (type == NID::kEnd)\r\n    {\r\n      if (digestsDefined.IsEmpty())\r\n      {\r\n        BoolVector_Fill_False(digestsDefined, numDigestsTotal);\r\n        digests.Clear();\r\n        for (int i = 0; i < numDigestsTotal; i++)\r\n          digests.Add(0);\r\n      }\r\n      return;\r\n    }\r\n    else\r\n      SkeepData();\r\n    type = ReadID();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadStreamsInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CBoolVector &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs,\r\n    CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    CRecordVector<UInt64> &unpackSizes,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type > ((UInt32)1 << 30))\r\n      ThrowIncorrect();\r\n    switch((UInt32)type)\r\n    {\r\n      case NID::kEnd:\r\n        return;\r\n      case NID::kPackInfo:\r\n      {\r\n        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);\r\n        break;\r\n      }\r\n      case NID::kUnpackInfo:\r\n      {\r\n        ReadUnpackInfo(dataVector, folders);\r\n        break;\r\n      }\r\n      case NID::kSubStreamsInfo:\r\n      {\r\n        ReadSubStreamsInfo(folders, numUnpackStreamsInFolders,\r\n            unpackSizes, digestsDefined, digests);\r\n        break;\r\n      }\r\n      default:\r\n        ThrowIncorrect();\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector(int numItems, CBoolVector &v)\r\n{\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      b = ReadByte();\r\n      mask = 0x80;\r\n    }\r\n    v.Add((b & mask) != 0);\r\n    mask >>= 1;\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)\r\n{\r\n  Byte allAreDefined = ReadByte();\r\n  if (allAreDefined == 0)\r\n  {\r\n    ReadBoolVector(numItems, v);\r\n    return;\r\n  }\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n    v.Add(true);\r\n}\r\n\r\nvoid CInArchive::ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\r\n    CUInt64DefVector &v, int numFiles)\r\n{\r\n  ReadBoolVector2(numFiles, v.Defined);\r\n\r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, &dataVector);\r\n  v.Values.Reserve(numFiles);\r\n\r\n  for (int i = 0; i < numFiles; i++)\r\n  {\r\n    UInt64 t = 0;\r\n    if (v.Defined[i])\r\n      t = ReadUInt64();\r\n    v.Values.Add(t);\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadAndDecodePackedStreams(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    UInt64 baseOffset,\r\n    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  CRecordVector<UInt64> packSizes;\r\n  CBoolVector packCRCsDefined;\r\n  CRecordVector<UInt32> packCRCs;\r\n  CObjectVector<CFolder> folders;\r\n  \r\n  CRecordVector<CNum> numUnpackStreamsInFolders;\r\n  CRecordVector<UInt64> unpackSizes;\r\n  CBoolVector digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  ReadStreamsInfo(NULL,\r\n    dataOffset,\r\n    packSizes,\r\n    packCRCsDefined,\r\n    packCRCs,\r\n    folders,\r\n    numUnpackStreamsInFolders,\r\n    unpackSizes,\r\n    digestsDefined,\r\n    digests);\r\n  \r\n  // db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\r\n  \r\n  CNum packIndex = 0;\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  UInt64 dataStartPos = baseOffset + dataOffset;\r\n  for (int i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    dataVector.Add(CByteBuffer());\r\n    CByteBuffer &data = dataVector.Back();\r\n    UInt64 unpackSize64 = folder.GetUnpackSize();\r\n    size_t unpackSize = (size_t)unpackSize64;\r\n    if (unpackSize != unpackSize64)\r\n      ThrowUnsupported();\r\n    data.SetCapacity(unpackSize);\r\n    \r\n    CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    outStreamSpec->Init(data, unpackSize);\r\n    \r\n    HRESULT result = decoder.Decode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      _stream, dataStartPos,\r\n      &packSizes[packIndex], folder, outStream, NULL\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, passwordIsDefined\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , false, 1\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    \r\n    if (folder.UnpackCRCDefined)\r\n      if (CrcCalc(data, unpackSize) != folder.UnpackCRC)\r\n        ThrowIncorrect();\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      UInt64 packSize = packSizes[packIndex++];\r\n      dataStartPos += packSize;\r\n      HeadersSize += packSize;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CInArchive::ReadHeader(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  UInt64 type = ReadID();\r\n\r\n  if (type == NID::kArchiveProperties)\r\n  {\r\n    ReadArchiveProperties(db.ArchiveInfo);\r\n    type = ReadID();\r\n  }\r\n \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  if (type == NID::kAdditionalStreamsInfo)\r\n  {\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        db.ArchiveInfo.StartPositionAfterHeader,\r\n        db.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword, passwordIsDefined\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n\r\n  CRecordVector<UInt64> unpackSizes;\r\n  CBoolVector digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  if (type == NID::kMainStreamsInfo)\r\n  {\r\n    ReadStreamsInfo(&dataVector,\r\n        db.ArchiveInfo.DataStartPosition,\r\n        db.PackSizes,\r\n        db.PackCRCsDefined,\r\n        db.PackCRCs,\r\n        db.Folders,\r\n        db.NumUnpackStreamsVector,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    db.ArchiveInfo.DataStartPosition += db.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n  else\r\n  {\r\n    for (int i = 0; i < db.Folders.Size(); i++)\r\n    {\r\n      db.NumUnpackStreamsVector.Add(1);\r\n      CFolder &folder = db.Folders[i];\r\n      unpackSizes.Add(folder.GetUnpackSize());\r\n      digestsDefined.Add(folder.UnpackCRCDefined);\r\n      digests.Add(folder.UnpackCRC);\r\n    }\r\n  }\r\n\r\n  db.Files.Clear();\r\n\r\n  if (type == NID::kEnd)\r\n    return S_OK;\r\n  if (type != NID::kFilesInfo)\r\n    ThrowIncorrect();\r\n  \r\n  CNum numFiles = ReadNum();\r\n  db.Files.Reserve(numFiles);\r\n  CNum i;\r\n  for (i = 0; i < numFiles; i++)\r\n    db.Files.Add(CFileItem());\r\n\r\n  db.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);\r\n  if (!db.PackSizes.IsEmpty())\r\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);\r\n  if (numFiles > 0  && !digests.IsEmpty())\r\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);\r\n\r\n  CBoolVector emptyStreamVector;\r\n  BoolVector_Fill_False(emptyStreamVector, (int)numFiles);\r\n  CBoolVector emptyFileVector;\r\n  CBoolVector antiFileVector;\r\n  CNum numEmptyStreams = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    UInt64 size = ReadNumber();\r\n    size_t ppp = _inByteBack->_pos;\r\n    bool addPropIdToList = true;\r\n    bool isKnownType = true;\r\n    if (type > ((UInt32)1 << 30))\r\n      isKnownType = false;\r\n    else switch((UInt32)type)\r\n    {\r\n      case NID::kName:\r\n      {\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for (int i = 0; i < db.Files.Size(); i++)\r\n          _inByteBack->ReadString(db.Files[i].Name);\r\n        break;\r\n      }\r\n      case NID::kWinAttributes:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(db.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = db.Files[i];\r\n          file.AttribDefined = boolVector[i];\r\n          if (file.AttribDefined)\r\n            file.Attrib = ReadUInt32();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyStream:\r\n      {\r\n        ReadBoolVector(numFiles, emptyStreamVector);\r\n        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)\r\n          if (emptyStreamVector[i])\r\n            numEmptyStreams++;\r\n\r\n        BoolVector_Fill_False(emptyFileVector, numEmptyStreams);\r\n        BoolVector_Fill_False(antiFileVector, numEmptyStreams);\r\n\r\n        break;\r\n      }\r\n      case NID::kEmptyFile:  ReadBoolVector(numEmptyStreams, emptyFileVector); break;\r\n      case NID::kAnti:  ReadBoolVector(numEmptyStreams, antiFileVector); break;\r\n      case NID::kStartPos:  ReadUInt64DefVector(dataVector, db.StartPos, (int)numFiles); break;\r\n      case NID::kCTime:  ReadUInt64DefVector(dataVector, db.CTime, (int)numFiles); break;\r\n      case NID::kATime:  ReadUInt64DefVector(dataVector, db.ATime, (int)numFiles); break;\r\n      case NID::kMTime:  ReadUInt64DefVector(dataVector, db.MTime, (int)numFiles); break;\r\n      case NID::kDummy:\r\n      {\r\n        for (UInt64 j = 0; j < size; j++)\r\n          if (ReadByte() != 0)\r\n            ThrowIncorrect();\r\n        addPropIdToList = false;\r\n        break;\r\n      }\r\n      default:\r\n        addPropIdToList = isKnownType = false;\r\n    }\r\n    if (isKnownType)\r\n    {\r\n      if(addPropIdToList)\r\n        db.ArchiveInfo.FileInfoPopIDs.Add(type);\r\n    }\r\n    else\r\n      SkeepData(size);\r\n    bool checkRecordsSize = (db.ArchiveInfo.Version.Major > 0 ||\r\n        db.ArchiveInfo.Version.Minor > 2);\r\n    if (checkRecordsSize && _inByteBack->_pos - ppp != size)\r\n      ThrowIncorrect();\r\n  }\r\n\r\n  CNum emptyFileIndex = 0;\r\n  CNum sizeIndex = 0;\r\n\r\n  CNum numAntiItems = 0;\r\n  for (i = 0; i < numEmptyStreams; i++)\r\n    if (antiFileVector[i])\r\n      numAntiItems++;\r\n    \r\n  for (i = 0; i < numFiles; i++)\r\n  {\r\n    CFileItem &file = db.Files[i];\r\n    bool isAnti;\r\n    file.HasStream = !emptyStreamVector[i];\r\n    if (file.HasStream)\r\n    {\r\n      file.IsDir = false;\r\n      isAnti = false;\r\n      file.Size = unpackSizes[sizeIndex];\r\n      file.Crc = digests[sizeIndex];\r\n      file.CrcDefined = digestsDefined[sizeIndex];\r\n      sizeIndex++;\r\n    }\r\n    else\r\n    {\r\n      file.IsDir = !emptyFileVector[emptyFileIndex];\r\n      isAnti = antiFileVector[emptyFileIndex];\r\n      emptyFileIndex++;\r\n      file.Size = 0;\r\n      file.CrcDefined = false;\r\n    }\r\n    if (numAntiItems != 0)\r\n      db.IsAnti.Add(isAnti);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartPackStream()\r\n{\r\n  FolderStartPackStreamIndex.Clear();\r\n  FolderStartPackStreamIndex.Reserve(Folders.Size());\r\n  CNum startPos = 0;\r\n  for (int i = 0; i < Folders.Size(); i++)\r\n  {\r\n    FolderStartPackStreamIndex.Add(startPos);\r\n    startPos += (CNum)Folders[i].PackStreams.Size();\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillStartPos()\r\n{\r\n  PackStreamStartPositions.Clear();\r\n  PackStreamStartPositions.Reserve(PackSizes.Size());\r\n  UInt64 startPos = 0;\r\n  for (int i = 0; i < PackSizes.Size(); i++)\r\n  {\r\n    PackStreamStartPositions.Add(startPos);\r\n    startPos += PackSizes[i];\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartFileIndex()\r\n{\r\n  FolderStartFileIndex.Clear();\r\n  FolderStartFileIndex.Reserve(Folders.Size());\r\n  FileIndexToFolderIndexMap.Clear();\r\n  FileIndexToFolderIndexMap.Reserve(Files.Size());\r\n  \r\n  int folderIndex = 0;\r\n  CNum indexInFolder = 0;\r\n  for (int i = 0; i < Files.Size(); i++)\r\n  {\r\n    const CFileItem &file = Files[i];\r\n    bool emptyStream = !file.HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      FileIndexToFolderIndexMap.Add(kNumNoIndex);\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      // v3.13 incorrectly worked with empty folders\r\n      // v4.07: Loop for skipping empty folders\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= Folders.Size())\r\n          ThrowIncorrect();\r\n        FolderStartFileIndex.Add(i); // check it\r\n        if (NumUnpackStreamsVector[folderIndex] != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    FileIndexToFolderIndexMap.Add(folderIndex);\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= NumUnpackStreamsVector[folderIndex])\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n\r\n  db.ArchiveInfo.Version.Major = _header[6];\r\n  db.ArchiveInfo.Version.Minor = _header[7];\r\n\r\n  if (db.ArchiveInfo.Version.Major != kMajorVersion)\r\n    ThrowUnsupportedVersion();\r\n\r\n  UInt32 crcFromArchive = Get32(_header + 8);\r\n  UInt64 nextHeaderOffset = Get64(_header + 0xC);\r\n  UInt64 nextHeaderSize = Get64(_header + 0x14);\r\n  UInt32 nextHeaderCRC = Get32(_header + 0x1C);\r\n  UInt32 crc = CrcCalc(_header + 0xC, 20);\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)\r\n  {\r\n    UInt64 cur, cur2;\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));\r\n    const int kCheckSize = 500;\r\n    Byte buf[kCheckSize];\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));\r\n    int checkSize = kCheckSize;\r\n    if (cur2 - cur < kCheckSize)\r\n      checkSize = (int)(cur2 - cur);\r\n    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));\r\n    \r\n    RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));\r\n\r\n    int i;\r\n    for (i = (int)checkSize - 2; i >= 0; i--)\r\n      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)\r\n        break;\r\n    if (i < 0)\r\n      return S_FALSE;\r\n    nextHeaderSize = checkSize - i;\r\n    nextHeaderOffset = cur2 - cur + i;\r\n    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);\r\n    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));\r\n  }\r\n  #endif\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  crcFromArchive = crc;\r\n  #endif\r\n\r\n  db.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;\r\n\r\n  if (crc != crcFromArchive)\r\n    ThrowIncorrect();\r\n\r\n  if (nextHeaderSize == 0)\r\n    return S_OK;\r\n\r\n  if (nextHeaderSize > (UInt64)0xFFFFFFFF)\r\n    return S_FALSE;\r\n\r\n  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));\r\n\r\n  CByteBuffer buffer2;\r\n  buffer2.SetCapacity((size_t)nextHeaderSize);\r\n\r\n  RINOK(ReadStream_FALSE(_stream, buffer2, (size_t)nextHeaderSize));\r\n  HeadersSize += kHeaderSize + nextHeaderSize;\r\n  db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;\r\n\r\n  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)\r\n    ThrowIncorrect();\r\n  \r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, buffer2);\r\n  \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  UInt64 type = ReadID();\r\n  if (type != NID::kHeader)\r\n  {\r\n    if (type != NID::kEncodedHeader)\r\n      ThrowIncorrect();\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        db.ArchiveInfo.StartPositionAfterHeader,\r\n        db.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword, passwordIsDefined\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    if (dataVector.Size() == 0)\r\n      return S_OK;\r\n    if (dataVector.Size() > 1)\r\n      ThrowIncorrect();\r\n    streamSwitch.Remove();\r\n    streamSwitch.Set(this, dataVector.Front());\r\n    if (ReadID() != NID::kHeader)\r\n      ThrowIncorrect();\r\n  }\r\n\r\n  db.HeadersSize = HeadersSize;\r\n\r\n  return ReadHeader(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    db\r\n    #ifndef _NO_CRYPTO\r\n    , getTextPassword, passwordIsDefined\r\n    #endif\r\n    );\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  try\r\n  {\r\n    return ReadDatabase2(\r\n      EXTERNAL_CODECS_LOC_VARS db\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, passwordIsDefined\r\n      #endif\r\n      );\r\n  }\r\n  catch(CInArchiveException &) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zIn.h",
    "content": "// 7zIn.h\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../IStream.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/InBuffer.h\"\r\n\r\n#include \"7zItem.h\"\r\n \r\nnamespace NArchive {\r\nnamespace N7z {\r\n  \r\nstruct CInArchiveInfo\r\n{\r\n  CArchiveVersion Version;\r\n  UInt64 StartPosition;\r\n  UInt64 StartPositionAfterHeader;\r\n  UInt64 DataStartPosition;\r\n  UInt64 DataStartPosition2;\r\n  CRecordVector<UInt64> FileInfoPopIDs;\r\n  void Clear()\r\n  {\r\n    FileInfoPopIDs.Clear();\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabaseEx: public CArchiveDatabase\r\n{\r\n  CInArchiveInfo ArchiveInfo;\r\n  CRecordVector<UInt64> PackStreamStartPositions;\r\n  CRecordVector<CNum> FolderStartPackStreamIndex;\r\n  CRecordVector<CNum> FolderStartFileIndex;\r\n  CRecordVector<CNum> FileIndexToFolderIndexMap;\r\n\r\n  UInt64 HeadersSize;\r\n  UInt64 PhySize;\r\n\r\n  void Clear()\r\n  {\r\n    CArchiveDatabase::Clear();\r\n    ArchiveInfo.Clear();\r\n    PackStreamStartPositions.Clear();\r\n    FolderStartPackStreamIndex.Clear();\r\n    FolderStartFileIndex.Clear();\r\n    FileIndexToFolderIndexMap.Clear();\r\n\r\n    HeadersSize = 0;\r\n    PhySize = 0;\r\n  }\r\n\r\n  void FillFolderStartPackStream();\r\n  void FillStartPos();\r\n  void FillFolderStartFileIndex();\r\n\r\n  void Fill()\r\n  {\r\n    FillFolderStartPackStream();\r\n    FillStartPos();\r\n    FillFolderStartFileIndex();\r\n  }\r\n  \r\n  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const\r\n  {\r\n    return ArchiveInfo.DataStartPosition +\r\n        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n  }\r\n  \r\n  UInt64 GetFolderFullPackSize(int folderIndex) const\r\n  {\r\n    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];\r\n    const CFolder &folder = Folders[folderIndex];\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < folder.PackStreams.Size(); i++)\r\n      size += PackSizes[packStreamIndex + i];\r\n    return size;\r\n  }\r\n  \r\n  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\r\n  {\r\n    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n  }\r\n\r\n  UInt64 GetFilePackSize(CNum fileIndex) const\r\n  {\r\n    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n    if (folderIndex != kNumNoIndex)\r\n      if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n        return GetFolderFullPackSize(folderIndex);\r\n    return 0;\r\n  }\r\n};\r\n\r\nclass CInByte2\r\n{\r\n  const Byte *_buffer;\r\n  size_t _size;\r\npublic:\r\n  size_t _pos;\r\n  void Init(const Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  Byte ReadByte();\r\n  void ReadBytes(Byte *data, size_t size);\r\n  void SkeepData(UInt64 size);\r\n  void SkeepData();\r\n  UInt64 ReadNumber();\r\n  CNum ReadNum();\r\n  UInt32 ReadUInt32();\r\n  UInt64 ReadUInt64();\r\n  void ReadString(UString &s);\r\n};\r\n\r\nclass CStreamSwitch;\r\n\r\nconst UInt32 kHeaderSize = 32;\r\n\r\nclass CInArchive\r\n{\r\n  friend class CStreamSwitch;\r\n\r\n  CMyComPtr<IInStream> _stream;\r\n\r\n  CObjectVector<CInByte2> _inByteVector;\r\n  CInByte2 *_inByteBack;\r\n \r\n  UInt64 _arhiveBeginStreamPosition;\r\n\r\n  Byte _header[kHeaderSize];\r\n\r\n  UInt64 HeadersSize;\r\n\r\n  void AddByteStream(const Byte *buffer, size_t size)\r\n  {\r\n    _inByteVector.Add(CInByte2());\r\n    _inByteBack = &_inByteVector.Back();\r\n    _inByteBack->Init(buffer, size);\r\n  }\r\n  \r\n  void DeleteByteStream()\r\n  {\r\n    _inByteVector.DeleteBack();\r\n    if (!_inByteVector.IsEmpty())\r\n      _inByteBack = &_inByteVector.Back();\r\n  }\r\n\r\nprivate:\r\n  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);\r\n  \r\n  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }\r\n  Byte ReadByte() { return _inByteBack->ReadByte(); }\r\n  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }\r\n  CNum ReadNum() { return _inByteBack->ReadNum(); }\r\n  UInt64 ReadID() { return _inByteBack->ReadNumber(); }\r\n  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }\r\n  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }\r\n  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }\r\n  void SkeepData() { _inByteBack->SkeepData(); }\r\n  void WaitAttribute(UInt64 attribute);\r\n\r\n  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);\r\n  void GetNextFolderItem(CFolder &itemInfo);\r\n  void ReadHashDigests(int numItems,\r\n      CBoolVector &digestsDefined, CRecordVector<UInt32> &digests);\r\n  \r\n  void ReadPackInfo(\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CBoolVector &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs);\r\n  \r\n  void ReadUnpackInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      CObjectVector<CFolder> &folders);\r\n  \r\n  void ReadSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      CRecordVector<UInt64> &unpackSizes,\r\n      CBoolVector &digestsDefined,\r\n      CRecordVector<UInt32> &digests);\r\n\r\n  void ReadStreamsInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CBoolVector &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs,\r\n      CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      CRecordVector<UInt64> &unpackSizes,\r\n      CBoolVector &digestsDefined,\r\n      CRecordVector<UInt32> &digests);\r\n\r\n\r\n  void ReadBoolVector(int numItems, CBoolVector &v);\r\n  void ReadBoolVector2(int numItems, CBoolVector &v);\r\n  void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\r\n      CUInt64DefVector &v, int numFiles);\r\n  HRESULT ReadAndDecodePackedStreams(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      UInt64 baseOffset, UInt64 &dataOffset,\r\n      CObjectVector<CByteBuffer> &dataVector\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n  HRESULT ReadHeader(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n  HRESULT ReadDatabase2(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\npublic:\r\n  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive\r\n  void Close();\r\n\r\n  HRESULT ReadDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n};\r\n  \r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zItem.h",
    "content": "// 7zItem.h\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../Common/MethodId.h\"\r\n\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\ntypedef UInt32 CNum;\r\nconst CNum kNumMax     = 0x7FFFFFFF;\r\nconst CNum kNumNoIndex = 0xFFFFFFFF;\r\n\r\nstruct CCoderInfo\r\n{\r\n  CMethodId MethodID;\r\n  CByteBuffer Props;\r\n  CNum NumInStreams;\r\n  CNum NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBindPair\r\n{\r\n  CNum InIndex;\r\n  CNum OutIndex;\r\n};\r\n\r\nstruct CFolder\r\n{\r\n  CObjectVector<CCoderInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<CNum> PackStreams;\r\n  CRecordVector<UInt64> UnpackSizes;\r\n  UInt32 UnpackCRC;\r\n  bool UnpackCRCDefined;\r\n\r\n  CFolder(): UnpackCRCDefined(false) {}\r\n\r\n  UInt64 GetUnpackSize() const // test it\r\n  {\r\n    if (UnpackSizes.IsEmpty())\r\n      return 0;\r\n    for (int i = UnpackSizes.Size() - 1; i >= 0; i--)\r\n      if (FindBindPairForOutStream(i) < 0)\r\n        return UnpackSizes[i];\r\n    throw 1;\r\n  }\r\n\r\n  CNum GetNumOutStreams() const\r\n  {\r\n    CNum result = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n      result += Coders[i].NumOutStreams;\r\n    return result;\r\n  }\r\n\r\n  int FindBindPairForInStream(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBindPairForOutStream(CNum outStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindPackStreamArrayIndex(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < PackStreams.Size(); i++)\r\n      if (PackStreams[i] == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  bool CheckStructure() const;\r\n};\r\n\r\nstruct CUInt64DefVector\r\n{\r\n  CRecordVector<UInt64> Values;\r\n  CRecordVector<bool> Defined;\r\n  \r\n  void Clear()\r\n  {\r\n    Values.Clear();\r\n    Defined.Clear();\r\n  }\r\n  \r\n  void ReserveDown()\r\n  {\r\n    Values.ReserveDown();\r\n    Values.ReserveDown();\r\n  }\r\n\r\n  bool GetItem(int index, UInt64 &value) const\r\n  {\r\n    if (index < Defined.Size() && Defined[index])\r\n    {\r\n      value = Values[index];\r\n      return true;\r\n    }\r\n    value = 0;\r\n    return false;\r\n  }\r\n  \r\n  void SetItem(int index, bool defined, UInt64 value)\r\n  {\r\n    while (index >= Defined.Size())\r\n      Defined.Add(false);\r\n    Defined[index] = defined;\r\n    if (!defined)\r\n      return;\r\n    while (index >= Values.Size())\r\n      Values.Add(0);\r\n    Values[index] = value;\r\n  }\r\n\r\n  bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }\r\n};\r\n\r\nstruct CFileItem\r\n{\r\n  UInt64 Size;\r\n  UInt32 Attrib;\r\n  UInt32 Crc;\r\n  UString Name;\r\n\r\n  bool HasStream; // Test it !!! it means that there is\r\n                  // stream in some folder. It can be empty stream\r\n  bool IsDir;\r\n  bool CrcDefined;\r\n  bool AttribDefined;\r\n\r\n  CFileItem():\r\n    HasStream(true),\r\n    IsDir(false),\r\n    CrcDefined(false),\r\n    AttribDefined(false)\r\n      {}\r\n  void SetAttrib(UInt32 attrib)\r\n  {\r\n    AttribDefined = true;\r\n    Attrib = attrib;\r\n  }\r\n};\r\n\r\nstruct CFileItem2\r\n{\r\n  UInt64 CTime;\r\n  UInt64 ATime;\r\n  UInt64 MTime;\r\n  UInt64 StartPos;\r\n  bool CTimeDefined;\r\n  bool ATimeDefined;\r\n  bool MTimeDefined;\r\n  bool StartPosDefined;\r\n  bool IsAnti;\r\n};\r\n\r\nstruct CArchiveDatabase\r\n{\r\n  CRecordVector<UInt64> PackSizes;\r\n  CRecordVector<bool> PackCRCsDefined;\r\n  CRecordVector<UInt32> PackCRCs;\r\n  CObjectVector<CFolder> Folders;\r\n  CRecordVector<CNum> NumUnpackStreamsVector;\r\n  CObjectVector<CFileItem> Files;\r\n\r\n  CUInt64DefVector CTime;\r\n  CUInt64DefVector ATime;\r\n  CUInt64DefVector MTime;\r\n  CUInt64DefVector StartPos;\r\n  CRecordVector<bool> IsAnti;\r\n\r\n  void Clear()\r\n  {\r\n    PackSizes.Clear();\r\n    PackCRCsDefined.Clear();\r\n    PackCRCs.Clear();\r\n    Folders.Clear();\r\n    NumUnpackStreamsVector.Clear();\r\n    Files.Clear();\r\n    CTime.Clear();\r\n    ATime.Clear();\r\n    MTime.Clear();\r\n    StartPos.Clear();\r\n    IsAnti.Clear();\r\n  }\r\n\r\n  void ReserveDown()\r\n  {\r\n    PackSizes.ReserveDown();\r\n    PackCRCsDefined.ReserveDown();\r\n    PackCRCs.ReserveDown();\r\n    Folders.ReserveDown();\r\n    NumUnpackStreamsVector.ReserveDown();\r\n    Files.ReserveDown();\r\n    CTime.ReserveDown();\r\n    ATime.ReserveDown();\r\n    MTime.ReserveDown();\r\n    StartPos.ReserveDown();\r\n    IsAnti.ReserveDown();\r\n  }\r\n\r\n  bool IsEmpty() const\r\n  {\r\n    return (PackSizes.IsEmpty() &&\r\n      PackCRCsDefined.IsEmpty() &&\r\n      PackCRCs.IsEmpty() &&\r\n      Folders.IsEmpty() &&\r\n      NumUnpackStreamsVector.IsEmpty() &&\r\n      Files.IsEmpty());\r\n  }\r\n\r\n  bool CheckNumFiles() const\r\n  {\r\n    int size = Files.Size();\r\n    return (\r\n      CTime.CheckSize(size) &&\r\n      ATime.CheckSize(size) &&\r\n      MTime.CheckSize(size) &&\r\n      StartPos.CheckSize(size) &&\r\n      (size == IsAnti.Size() || IsAnti.Size() == 0));\r\n  }\r\n\r\n  bool IsSolid() const\r\n  {\r\n    for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)\r\n      if (NumUnpackStreamsVector[i] > 1)\r\n        return true;\r\n    return false;\r\n  }\r\n  bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }\r\n  void SetItemAnti(int index, bool isAnti)\r\n  {\r\n    while (index >= IsAnti.Size())\r\n      IsAnti.Add(false);\r\n    IsAnti[index] = isAnti;\r\n  }\r\n\r\n  void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;\r\n  void AddFile(const CFileItem &file, const CFileItem2 &file2);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zOut.cpp",
    "content": "// 7zOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/AutoPtr.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zOut.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nstatic HRESULT WriteBytes(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size > 0)\r\n  {\r\n    UInt32 curSize = (UInt32)MyMin(size, (size_t)0xFFFFFFFF);\r\n    UInt32 processedSize;\r\n    RINOK(stream->Write(data, curSize, &processedSize));\r\n    if (processedSize == 0)\r\n      return E_FAIL;\r\n    data = (const void *)((const Byte *)data + processedSize);\r\n    size -= processedSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nHRESULT COutArchive::WriteDirect(const void *data, UInt32 size)\r\n{\r\n  return ::WriteBytes(SeqStream, data, size);\r\n}\r\n\r\nHRESULT COutArchive::WriteSignature()\r\n{\r\n  Byte buf[8];\r\n  memcpy(buf, kSignature, kSignatureSize);\r\n  buf[kSignatureSize] = kMajorVersion;\r\n  buf[kSignatureSize + 1] = 3;\r\n  return WriteDirect(buf, 8);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishSignature()\r\n{\r\n  RINOK(WriteDirect(kFinishSignature, kSignatureSize));\r\n  CArchiveVersion av;\r\n  av.Major = kMajorVersion;\r\n  av.Minor = 2;\r\n  RINOK(WriteDirectByte(av.Major));\r\n  return WriteDirectByte(av.Minor);\r\n}\r\n#endif\r\n\r\nstatic void SetUInt32(Byte *p, UInt32 d)\r\n{\r\n  for (int i = 0; i < 4; i++, d >>= 8)\r\n    p[i] = (Byte)d;\r\n}\r\n\r\nstatic void SetUInt64(Byte *p, UInt64 d)\r\n{\r\n  for (int i = 0; i < 8; i++, d >>= 8)\r\n    p[i] = (Byte)d;\r\n}\r\n\r\nHRESULT COutArchive::WriteStartHeader(const CStartHeader &h)\r\n{\r\n  Byte buf[24];\r\n  SetUInt64(buf + 4, h.NextHeaderOffset);\r\n  SetUInt64(buf + 12, h.NextHeaderSize);\r\n  SetUInt32(buf + 20, h.NextHeaderCRC);\r\n  SetUInt32(buf, CrcCalc(buf + 4, 20));\r\n  return WriteDirect(buf, 24);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)\r\n{\r\n  CCRC crc;\r\n  crc.UpdateUInt64(h.NextHeaderOffset);\r\n  crc.UpdateUInt64(h.NextHeaderSize);\r\n  crc.UpdateUInt32(h.NextHeaderCRC);\r\n  crc.UpdateUInt64(h.ArchiveStartOffset);\r\n  crc.UpdateUInt64(h.AdditionalStartBlockSize);\r\n  RINOK(WriteDirectUInt32(crc.GetDigest()));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  RINOK(WriteDirectUInt32(h.NextHeaderCRC));\r\n  RINOK(WriteDirectUInt64(h.ArchiveStartOffset));\r\n  return WriteDirectUInt64(h.AdditionalStartBlockSize);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)\r\n{\r\n  Close();\r\n  #ifdef _7Z_VOL\r\n  // endMarker = false;\r\n  _endMarker = endMarker;\r\n  #endif\r\n  SeqStream = stream;\r\n  if (!endMarker)\r\n  {\r\n    SeqStream.QueryInterface(IID_IOutStream, &Stream);\r\n    if (!Stream)\r\n    {\r\n      return E_NOTIMPL;\r\n      // endMarker = true;\r\n    }\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (endMarker)\r\n  {\r\n    /*\r\n    CStartHeader sh;\r\n    sh.NextHeaderOffset = (UInt32)(Int32)-1;\r\n    sh.NextHeaderSize = (UInt32)(Int32)-1;\r\n    sh.NextHeaderCRC = 0;\r\n    WriteStartHeader(sh);\r\n    */\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!Stream)\r\n      return E_FAIL;\r\n    RINOK(WriteSignature());\r\n    RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutArchive::Close()\r\n{\r\n  SeqStream.Release();\r\n  Stream.Release();\r\n}\r\n\r\nHRESULT COutArchive::SkeepPrefixArchiveHeader()\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n    return S_OK;\r\n  #endif\r\n  return Stream->Seek(24, STREAM_SEEK_CUR, NULL);\r\n}\r\n\r\nUInt64 COutArchive::GetPos() const\r\n{\r\n  if (_countMode)\r\n    return _countSize;\r\n  if (_writeToStream)\r\n    return _outByte.GetProcessedSize();\r\n  return _outByte2.GetPos();\r\n}\r\n\r\nvoid COutArchive::WriteBytes(const void *data, size_t size)\r\n{\r\n  if (_countMode)\r\n    _countSize += size;\r\n  else if (_writeToStream)\r\n  {\r\n    _outByte.WriteBytes(data, size);\r\n    _crc = CrcUpdate(_crc, data, size);\r\n  }\r\n  else\r\n    _outByte2.WriteBytes(data, size);\r\n}\r\n\r\nvoid COutArchive::WriteByte(Byte b)\r\n{\r\n  if (_countMode)\r\n    _countSize++;\r\n  else if (_writeToStream)\r\n  {\r\n    _outByte.WriteByte(b);\r\n    _crc = CRC_UPDATE_BYTE(_crc, b);\r\n  }\r\n  else\r\n    _outByte2.WriteByte(b);\r\n}\r\n\r\nvoid COutArchive::WriteUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nvoid COutArchive::WriteUInt64(UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nvoid COutArchive::WriteNumber(UInt64 value)\r\n{\r\n  Byte firstByte = 0;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n    {\r\n      firstByte |= Byte(value >> (8 * i));\r\n      break;\r\n    }\r\n    firstByte |= mask;\r\n    mask >>= 1;\r\n  }\r\n  WriteByte(firstByte);\r\n  for (;i > 0; i--)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nstatic UInt32 GetBigNumberSize(UInt64 value)\r\n{\r\n  int i;\r\n  for (i = 1; i < 9; i++)\r\n    if (value < (((UInt64)1 << (i * 7))))\r\n      break;\r\n  return i;\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nUInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)\r\n{\r\n  UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;\r\n  if (nameLength != 0)\r\n  {\r\n    nameLength = (nameLength + 1) * 2;\r\n    result += nameLength + GetBigNumberSize(nameLength) + 2;\r\n  }\r\n  if (props)\r\n  {\r\n    result += 20;\r\n  }\r\n  if (result >= 128)\r\n    result++;\r\n  result += kSignatureSize + 2 + kFinishHeaderSize;\r\n  return result;\r\n}\r\n\r\nUInt64 COutArchive::GetVolPureSize(UInt64 volSize, int nameLength, bool props)\r\n{\r\n  UInt32 headersSizeBase = COutArchive::GetVolHeadersSize(1, nameLength, props);\r\n  int testSize;\r\n  if (volSize > headersSizeBase)\r\n    testSize = volSize - headersSizeBase;\r\n  else\r\n    testSize = 1;\r\n  UInt32 headersSize = COutArchive::GetVolHeadersSize(testSize, nameLength, props);\r\n  UInt64 pureSize = 1;\r\n  if (volSize > headersSize)\r\n    pureSize = volSize - headersSize;\r\n  return pureSize;\r\n}\r\n#endif\r\n\r\nvoid COutArchive::WriteFolder(const CFolder &folder)\r\n{\r\n  WriteNumber(folder.Coders.Size());\r\n  int i;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    const CCoderInfo &coder = folder.Coders[i];\r\n    {\r\n      size_t propsSize = coder.Props.GetCapacity();\r\n      \r\n      UInt64 id = coder.MethodID;\r\n      int idSize;\r\n      for (idSize = 1; idSize < sizeof(id); idSize++)\r\n        if ((id >> (8 * idSize)) == 0)\r\n          break;\r\n      BYTE longID[15];\r\n      for (int t = idSize - 1; t >= 0 ; t--, id >>= 8)\r\n        longID[t] = (Byte)(id & 0xFF);\r\n      Byte b;\r\n      b = (Byte)(idSize & 0xF);\r\n      bool isComplex = !coder.IsSimpleCoder();\r\n      b |= (isComplex ? 0x10 : 0);\r\n      b |= ((propsSize != 0) ? 0x20 : 0 );\r\n      WriteByte(b);\r\n      WriteBytes(longID, idSize);\r\n      if (isComplex)\r\n      {\r\n        WriteNumber(coder.NumInStreams);\r\n        WriteNumber(coder.NumOutStreams);\r\n      }\r\n      if (propsSize == 0)\r\n        continue;\r\n      WriteNumber(propsSize);\r\n      WriteBytes(coder.Props, propsSize);\r\n    }\r\n  }\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = folder.BindPairs[i];\r\n    WriteNumber(bindPair.InIndex);\r\n    WriteNumber(bindPair.OutIndex);\r\n  }\r\n  if (folder.PackStreams.Size() > 1)\r\n    for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    {\r\n      WriteNumber(folder.PackStreams[i]);\r\n    }\r\n}\r\n\r\nvoid COutArchive::WriteBoolVector(const CBoolVector &boolVector)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0x80;\r\n  for (int i = 0; i < boolVector.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n      b |= mask;\r\n    mask >>= 1;\r\n    if (mask == 0)\r\n    {\r\n      WriteByte(b);\r\n      mask = 0x80;\r\n      b = 0;\r\n    }\r\n  }\r\n  if (mask != 0x80)\r\n    WriteByte(b);\r\n}\r\n\r\n\r\nvoid COutArchive::WriteHashDigests(\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  int numDefined = 0;\r\n  int i;\r\n  for (i = 0; i < digestsDefined.Size(); i++)\r\n    if (digestsDefined[i])\r\n      numDefined++;\r\n  if (numDefined == 0)\r\n    return;\r\n\r\n  WriteByte(NID::kCRC);\r\n  if (numDefined == digestsDefined.Size())\r\n    WriteByte(1);\r\n  else\r\n  {\r\n    WriteByte(0);\r\n    WriteBoolVector(digestsDefined);\r\n  }\r\n  for (i = 0; i < digests.Size(); i++)\r\n    if (digestsDefined[i])\r\n      WriteUInt32(digests[i]);\r\n}\r\n\r\nvoid COutArchive::WritePackInfo(\r\n    UInt64 dataOffset,\r\n    const CRecordVector<UInt64> &packSizes,\r\n    const CRecordVector<bool> &packCRCsDefined,\r\n    const CRecordVector<UInt32> &packCRCs)\r\n{\r\n  if (packSizes.IsEmpty())\r\n    return;\r\n  WriteByte(NID::kPackInfo);\r\n  WriteNumber(dataOffset);\r\n  WriteNumber(packSizes.Size());\r\n  WriteByte(NID::kSize);\r\n  for (int i = 0; i < packSizes.Size(); i++)\r\n    WriteNumber(packSizes[i]);\r\n\r\n  WriteHashDigests(packCRCsDefined, packCRCs);\r\n  \r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::WriteUnpackInfo(const CObjectVector<CFolder> &folders)\r\n{\r\n  if (folders.IsEmpty())\r\n    return;\r\n\r\n  WriteByte(NID::kUnpackInfo);\r\n\r\n  WriteByte(NID::kFolder);\r\n  WriteNumber(folders.Size());\r\n  {\r\n    WriteByte(0);\r\n    for (int i = 0; i < folders.Size(); i++)\r\n      WriteFolder(folders[i]);\r\n  }\r\n  \r\n  WriteByte(NID::kCodersUnpackSize);\r\n  int i;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    for (int j = 0; j < folder.UnpackSizes.Size(); j++)\r\n      WriteNumber(folder.UnpackSizes[j]);\r\n  }\r\n\r\n  CRecordVector<bool> unpackCRCsDefined;\r\n  CRecordVector<UInt32> unpackCRCs;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    unpackCRCsDefined.Add(folder.UnpackCRCDefined);\r\n    unpackCRCs.Add(folder.UnpackCRC);\r\n  }\r\n  WriteHashDigests(unpackCRCsDefined, unpackCRCs);\r\n\r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::WriteSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    const CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    const CRecordVector<UInt64> &unpackSizes,\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  WriteByte(NID::kSubStreamsInfo);\r\n\r\n  int i;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n  {\r\n    if (numUnpackStreamsInFolders[i] != 1)\r\n    {\r\n      WriteByte(NID::kNumUnpackStream);\r\n      for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n        WriteNumber(numUnpackStreamsInFolders[i]);\r\n      break;\r\n    }\r\n  }\r\n \r\n\r\n  bool needFlag = true;\r\n  CNum index = 0;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n    for (CNum j = 0; j < numUnpackStreamsInFolders[i]; j++)\r\n    {\r\n      if (j + 1 != numUnpackStreamsInFolders[i])\r\n      {\r\n        if (needFlag)\r\n          WriteByte(NID::kSize);\r\n        needFlag = false;\r\n        WriteNumber(unpackSizes[index]);\r\n      }\r\n      index++;\r\n    }\r\n\r\n  CRecordVector<bool> digestsDefined2;\r\n  CRecordVector<UInt32> digests2;\r\n\r\n  int digestIndex = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    int numSubStreams = (int)numUnpackStreamsInFolders[i];\r\n    if (numSubStreams == 1 && folders[i].UnpackCRCDefined)\r\n      digestIndex++;\r\n    else\r\n      for (int j = 0; j < numSubStreams; j++, digestIndex++)\r\n      {\r\n        digestsDefined2.Add(digestsDefined[digestIndex]);\r\n        digests2.Add(digests[digestIndex]);\r\n      }\r\n  }\r\n  WriteHashDigests(digestsDefined2, digests2);\r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::SkipAlign(unsigned /* pos */, unsigned /* alignSize */)\r\n{\r\n  return;\r\n}\r\n\r\n/*\r\n7-Zip 4.50 - 4.58 contain BUG, so they do not support .7z archives with Unknown field.\r\n\r\nvoid COutArchive::SkipAlign(unsigned pos, unsigned alignSize)\r\n{\r\n  pos += (unsigned)GetPos();\r\n  pos &= (alignSize - 1);\r\n  if (pos == 0)\r\n    return;\r\n  unsigned skip = alignSize - pos;\r\n  if (skip < 2)\r\n    skip += alignSize;\r\n  skip -= 2;\r\n  WriteByte(NID::kDummy);\r\n  WriteByte((Byte)skip);\r\n  for (unsigned i = 0; i < skip; i++)\r\n    WriteByte(0);\r\n}\r\n*/\r\n\r\nvoid COutArchive::WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize)\r\n{\r\n  const UInt64 bvSize = (numDefined == v.Size()) ? 0 : (v.Size() + 7) / 8;\r\n  const UInt64 dataSize = (UInt64)numDefined * itemSize + bvSize + 2;\r\n  SkipAlign(3 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), itemSize);\r\n\r\n  WriteByte(type);\r\n  WriteNumber(dataSize);\r\n  if (numDefined == v.Size())\r\n    WriteByte(1);\r\n  else\r\n  {\r\n    WriteByte(0);\r\n    WriteBoolVector(v);\r\n  }\r\n  WriteByte(0);\r\n}\r\n\r\nvoid COutArchive::WriteUInt64DefVector(const CUInt64DefVector &v, Byte type)\r\n{\r\n  int numDefined = 0;\r\n\r\n  int i;\r\n  for (i = 0; i < v.Defined.Size(); i++)\r\n    if (v.Defined[i])\r\n      numDefined++;\r\n\r\n  if (numDefined == 0)\r\n    return;\r\n\r\n  WriteAlignedBoolHeader(v.Defined, numDefined, type, 8);\r\n  \r\n  for (i = 0; i < v.Defined.Size(); i++)\r\n    if (v.Defined[i])\r\n      WriteUInt64(v.Values[i]);\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const Byte *data, size_t dataSize,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  CSequentialInStreamImp *streamSpec = new CSequentialInStreamImp;\r\n  CMyComPtr<ISequentialInStream> stream = streamSpec;\r\n  streamSpec->Init(data, dataSize);\r\n  CFolder folderItem;\r\n  folderItem.UnpackCRCDefined = true;\r\n  folderItem.UnpackCRC = CrcCalc(data, dataSize);\r\n  UInt64 dataSize64 = dataSize;\r\n  RINOK(encoder.Encode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      stream, NULL, &dataSize64, folderItem, SeqStream, packSizes, NULL))\r\n  folders.Add(folderItem);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const CByteBuffer &data,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  return EncodeStream(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      encoder, data, data.GetCapacity(), packSizes, folders);\r\n}\r\n\r\nvoid COutArchive::WriteHeader(\r\n    const CArchiveDatabase &db,\r\n    const CHeaderOptions &headerOptions,\r\n    UInt64 &headerOffset)\r\n{\r\n  int i;\r\n  \r\n  UInt64 packedSize = 0;\r\n  for (i = 0; i < db.PackSizes.Size(); i++)\r\n    packedSize += db.PackSizes[i];\r\n\r\n  headerOffset = packedSize;\r\n\r\n  WriteByte(NID::kHeader);\r\n\r\n  // Archive Properties\r\n\r\n  if (db.Folders.Size() > 0)\r\n  {\r\n    WriteByte(NID::kMainStreamsInfo);\r\n    WritePackInfo(0, db.PackSizes,\r\n        db.PackCRCsDefined,\r\n        db.PackCRCs);\r\n\r\n    WriteUnpackInfo(db.Folders);\r\n\r\n    CRecordVector<UInt64> unpackSizes;\r\n    CRecordVector<bool> digestsDefined;\r\n    CRecordVector<UInt32> digests;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = db.Files[i];\r\n      if (!file.HasStream)\r\n        continue;\r\n      unpackSizes.Add(file.Size);\r\n      digestsDefined.Add(file.CrcDefined);\r\n      digests.Add(file.Crc);\r\n    }\r\n\r\n    WriteSubStreamsInfo(\r\n        db.Folders,\r\n        db.NumUnpackStreamsVector,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    WriteByte(NID::kEnd);\r\n  }\r\n\r\n  if (db.Files.IsEmpty())\r\n  {\r\n    WriteByte(NID::kEnd);\r\n    return;\r\n  }\r\n\r\n  WriteByte(NID::kFilesInfo);\r\n  WriteNumber(db.Files.Size());\r\n\r\n  {\r\n  /* ---------- Empty Streams ---------- */\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve(db.Files.Size());\r\n  int numEmptyStreams = 0;\r\n  for (i = 0; i < db.Files.Size(); i++)\r\n    if (db.Files[i].HasStream)\r\n      emptyStreamVector.Add(false);\r\n    else\r\n    {\r\n      emptyStreamVector.Add(true);\r\n      numEmptyStreams++;\r\n    }\r\n  if (numEmptyStreams > 0)\r\n  {\r\n    WriteByte(NID::kEmptyStream);\r\n    WriteNumber((emptyStreamVector.Size() + 7) / 8);\r\n    WriteBoolVector(emptyStreamVector);\r\n\r\n    CBoolVector emptyFileVector, antiVector;\r\n    emptyFileVector.Reserve(numEmptyStreams);\r\n    antiVector.Reserve(numEmptyStreams);\r\n    CNum numEmptyFiles = 0, numAntiItems = 0;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = db.Files[i];\r\n      if (!file.HasStream)\r\n      {\r\n        emptyFileVector.Add(!file.IsDir);\r\n        if (!file.IsDir)\r\n          numEmptyFiles++;\r\n        bool isAnti = db.IsItemAnti(i);\r\n        antiVector.Add(isAnti);\r\n        if (isAnti)\r\n          numAntiItems++;\r\n      }\r\n    }\r\n\r\n    if (numEmptyFiles > 0)\r\n    {\r\n      WriteByte(NID::kEmptyFile);\r\n      WriteNumber((emptyFileVector.Size() + 7) / 8);\r\n      WriteBoolVector(emptyFileVector);\r\n    }\r\n\r\n    if (numAntiItems > 0)\r\n    {\r\n      WriteByte(NID::kAnti);\r\n      WriteNumber((antiVector.Size() + 7) / 8);\r\n      WriteBoolVector(antiVector);\r\n    }\r\n  }\r\n  }\r\n\r\n\r\n  {\r\n    /* ---------- Names ---------- */\r\n    \r\n    int numDefined = 0;\r\n    size_t namesDataSize = 0;\r\n    for (int i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const UString &name = db.Files[i].Name;\r\n      if (!name.IsEmpty())\r\n        numDefined++;\r\n      namesDataSize += (name.Length() + 1) * 2;\r\n    }\r\n    \r\n    if (numDefined > 0)\r\n    {\r\n      namesDataSize++;\r\n      SkipAlign(2 + GetBigNumberSize(namesDataSize), 2);\r\n\r\n      WriteByte(NID::kName);\r\n      WriteNumber(namesDataSize);\r\n      WriteByte(0);\r\n      for (int i = 0; i < db.Files.Size(); i++)\r\n      {\r\n        const UString &name = db.Files[i].Name;\r\n        for (int t = 0; t <= name.Length(); t++)\r\n        {\r\n          wchar_t c = name[t];\r\n          WriteByte((Byte)c);\r\n          WriteByte((Byte)(c >> 8));\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (headerOptions.WriteCTime) WriteUInt64DefVector(db.CTime, NID::kCTime);\r\n  if (headerOptions.WriteATime) WriteUInt64DefVector(db.ATime, NID::kATime);\r\n  if (headerOptions.WriteMTime) WriteUInt64DefVector(db.MTime, NID::kMTime);\r\n  WriteUInt64DefVector(db.StartPos, NID::kStartPos);\r\n  \r\n  {\r\n    /* ---------- Write Attrib ---------- */\r\n    CBoolVector boolVector;\r\n    boolVector.Reserve(db.Files.Size());\r\n    int numDefined = 0;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      bool defined = db.Files[i].AttribDefined;\r\n      boolVector.Add(defined);\r\n      if (defined)\r\n        numDefined++;\r\n    }\r\n    if (numDefined > 0)\r\n    {\r\n      WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttributes, 4);\r\n      for (i = 0; i < db.Files.Size(); i++)\r\n      {\r\n        const CFileItem &file = db.Files[i];\r\n        if (file.AttribDefined)\r\n          WriteUInt32(file.Attrib);\r\n      }\r\n    }\r\n  }\r\n\r\n  WriteByte(NID::kEnd); // for files\r\n  WriteByte(NID::kEnd); // for headers\r\n}\r\n\r\nHRESULT COutArchive::WriteDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CArchiveDatabase &db,\r\n    const CCompressionMethodMode *options,\r\n    const CHeaderOptions &headerOptions)\r\n{\r\n  if (!db.CheckNumFiles())\r\n    return E_FAIL;\r\n\r\n  UInt64 headerOffset;\r\n  UInt32 headerCRC;\r\n  UInt64 headerSize;\r\n  if (db.IsEmpty())\r\n  {\r\n    headerSize = 0;\r\n    headerOffset = 0;\r\n    headerCRC = CrcCalc(0, 0);\r\n  }\r\n  else\r\n  {\r\n    bool encodeHeaders = false;\r\n    if (options != 0)\r\n      if (options->IsEmpty())\r\n        options = 0;\r\n    if (options != 0)\r\n      if (options->PasswordIsDefined || headerOptions.CompressMainHeader)\r\n        encodeHeaders = true;\r\n\r\n    _outByte.SetStream(SeqStream);\r\n    _outByte.Init();\r\n    _crc = CRC_INIT_VAL;\r\n    _countMode = encodeHeaders;\r\n    _writeToStream = true;\r\n    _countSize = 0;\r\n    WriteHeader(db, headerOptions, headerOffset);\r\n\r\n    if (encodeHeaders)\r\n    {\r\n      CByteBuffer buf;\r\n      buf.SetCapacity(_countSize);\r\n      _outByte2.Init((Byte *)buf, _countSize);\r\n      \r\n      _countMode = false;\r\n      _writeToStream = false;\r\n      WriteHeader(db, headerOptions, headerOffset);\r\n      \r\n      if (_countSize != _outByte2.GetPos())\r\n        return E_FAIL;\r\n\r\n      CCompressionMethodMode encryptOptions;\r\n      encryptOptions.PasswordIsDefined = options->PasswordIsDefined;\r\n      encryptOptions.Password = options->Password;\r\n      CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions);\r\n      CRecordVector<UInt64> packSizes;\r\n      CObjectVector<CFolder> folders;\r\n      RINOK(EncodeStream(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          encoder, (const Byte *)buf,\r\n          _countSize, packSizes, folders));\r\n\r\n      _writeToStream = true;\r\n      \r\n      if (folders.Size() == 0)\r\n        throw 1;\r\n\r\n      WriteID(NID::kEncodedHeader);\r\n      WritePackInfo(headerOffset, packSizes,\r\n        CRecordVector<bool>(), CRecordVector<UInt32>());\r\n      WriteUnpackInfo(folders);\r\n      WriteByte(NID::kEnd);\r\n      for (int i = 0; i < packSizes.Size(); i++)\r\n        headerOffset += packSizes[i];\r\n    }\r\n    RINOK(_outByte.Flush());\r\n    headerCRC = CRC_GET_DIGEST(_crc);\r\n    headerSize = _outByte.GetProcessedSize();\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n  {\r\n    CFinishHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset =\r\n        UInt64(0) - (headerSize +\r\n        4 + kFinishHeaderSize);\r\n    h.ArchiveStartOffset = h.NextHeaderOffset - headerOffset;\r\n    h.AdditionalStartBlockSize = 0;\r\n    RINOK(WriteFinishHeader(h));\r\n    return WriteFinishSignature();\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    CStartHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = headerOffset;\r\n    RINOK(Stream->Seek(_prefixHeaderPos, STREAM_SEEK_SET, NULL));\r\n    return WriteStartHeader(h);\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabase::GetFile(int index, CFileItem &file, CFileItem2 &file2) const\r\n{\r\n  file = Files[index];\r\n  file2.CTimeDefined = CTime.GetItem(index, file2.CTime);\r\n  file2.ATimeDefined = ATime.GetItem(index, file2.ATime);\r\n  file2.MTimeDefined = MTime.GetItem(index, file2.MTime);\r\n  file2.StartPosDefined = StartPos.GetItem(index, file2.StartPos);\r\n  file2.IsAnti = IsItemAnti(index);\r\n}\r\n\r\nvoid CArchiveDatabase::AddFile(const CFileItem &file, const CFileItem2 &file2)\r\n{\r\n  int index = Files.Size();\r\n  CTime.SetItem(index, file2.CTimeDefined, file2.CTime);\r\n  ATime.SetItem(index, file2.ATimeDefined, file2.ATime);\r\n  MTime.SetItem(index, file2.MTimeDefined, file2.MTime);\r\n  StartPos.SetItem(index, file2.StartPosDefined, file2.StartPos);\r\n  SetItemAnti(index, file2.IsAnti);\r\n  Files.Add(file);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zOut.h",
    "content": "// 7z/Out.h\r\n\r\n#ifndef __7Z_OUT_H\r\n#define __7Z_OUT_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zCompressionMode.h\"\r\n#include \"7zEncode.h\"\r\n\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CWriteBufferLoc\r\n{\r\n  Byte *_data;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  CWriteBufferLoc(): _size(0), _pos(0) {}\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    _data = data;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    if (size > _size - _pos)\r\n      throw 1;\r\n    memcpy(_data + _pos, data, size);\r\n    _pos += size;\r\n  }\r\n  void WriteByte(Byte b)\r\n  {\r\n    if (_size == _pos)\r\n      throw 1;\r\n    _data[_pos++] = b;\r\n  }\r\n  size_t GetPos() const { return _pos; }\r\n};\r\n\r\nstruct CHeaderOptions\r\n{\r\n  bool CompressMainHeader;\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  CHeaderOptions():\r\n      CompressMainHeader(true),\r\n      WriteCTime(false),\r\n      WriteATime(false),\r\n      WriteMTime(true)\r\n      {}\r\n};\r\n\r\nclass COutArchive\r\n{\r\n  UInt64 _prefixHeaderPos;\r\n\r\n  HRESULT WriteDirect(const void *data, UInt32 size);\r\n  \r\n  UInt64 GetPos() const;\r\n  void WriteBytes(const void *data, size_t size);\r\n  void WriteBytes(const CByteBuffer &data) { WriteBytes(data, data.GetCapacity()); }\r\n  void WriteByte(Byte b);\r\n  void WriteUInt32(UInt32 value);\r\n  void WriteUInt64(UInt64 value);\r\n  void WriteNumber(UInt64 value);\r\n  void WriteID(UInt64 value) { WriteNumber(value); }\r\n\r\n  void WriteFolder(const CFolder &folder);\r\n  HRESULT WriteFileHeader(const CFileItem &itemInfo);\r\n  void WriteBoolVector(const CBoolVector &boolVector);\r\n  void WriteHashDigests(\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  void WritePackInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs);\r\n\r\n  void WriteUnpackInfo(const CObjectVector<CFolder> &folders);\r\n\r\n  void WriteSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unpackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  void SkipAlign(unsigned pos, unsigned alignSize);\r\n  void WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize);\r\n  void WriteUInt64DefVector(const CUInt64DefVector &v, Byte type);\r\n\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const Byte *data, size_t dataSize,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const CByteBuffer &data,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  void WriteHeader(\r\n      const CArchiveDatabase &db,\r\n      const CHeaderOptions &headerOptions,\r\n      UInt64 &headerOffset);\r\n  \r\n  bool _countMode;\r\n  bool _writeToStream;\r\n  size_t _countSize;\r\n  UInt32 _crc;\r\n  COutBuffer _outByte;\r\n  CWriteBufferLoc _outByte2;\r\n\r\n  #ifdef _7Z_VOL\r\n  bool _endMarker;\r\n  #endif\r\n\r\n  HRESULT WriteSignature();\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishSignature();\r\n  #endif\r\n  HRESULT WriteStartHeader(const CStartHeader &h);\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishHeader(const CFinishHeader &h);\r\n  #endif\r\n  CMyComPtr<IOutStream> Stream;\r\npublic:\r\n\r\n  COutArchive() { _outByte.Create(1 << 16); }\r\n  CMyComPtr<ISequentialOutStream> SeqStream;\r\n  HRESULT Create(ISequentialOutStream *stream, bool endMarker);\r\n  void Close();\r\n  HRESULT SkeepPrefixArchiveHeader();\r\n  HRESULT WriteDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CArchiveDatabase &db,\r\n      const CCompressionMethodMode *options,\r\n      const CHeaderOptions &headerOptions);\r\n\r\n  #ifdef _7Z_VOL\r\n  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);\r\n  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);\r\n  #endif\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zProperties.cpp",
    "content": "// 7zProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zProperties.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zHandler.h\"\r\n\r\n// #define _MULTI_PACK\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CPropMap\r\n{\r\n  UInt64 FilePropID;\r\n  STATPROPSTG StatPROPSTG;\r\n};\r\n\r\nCPropMap kPropMap[] =\r\n{\r\n  { NID::kName, NULL, kpidPath, VT_BSTR},\r\n  { NID::kSize, NULL, kpidSize, VT_UI8},\r\n  { NID::kPackInfo, NULL, kpidPackSize, VT_UI8},\r\n  \r\n  #ifdef _MULTI_PACK\r\n  { 100, L\"Pack0\", kpidPackedSize0, VT_UI8},\r\n  { 101, L\"Pack1\", kpidPackedSize1, VT_UI8},\r\n  { 102, L\"Pack2\", kpidPackedSize2, VT_UI8},\r\n  { 103, L\"Pack3\", kpidPackedSize3, VT_UI8},\r\n  { 104, L\"Pack4\", kpidPackedSize4, VT_UI8},\r\n  #endif\r\n\r\n  { NID::kCTime, NULL, kpidCTime, VT_FILETIME},\r\n  { NID::kMTime, NULL, kpidMTime, VT_FILETIME},\r\n  { NID::kATime, NULL, kpidATime, VT_FILETIME},\r\n  { NID::kWinAttributes, NULL, kpidAttrib, VT_UI4},\r\n  { NID::kStartPos, NULL, kpidPosition, VT_UI4},\r\n\r\n  { NID::kCRC, NULL, kpidCRC, VT_UI4},\r\n  \r\n  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},\r\n\r\n  #ifndef _SFX\r\n  { 97, NULL, kpidEncrypted, VT_BOOL},\r\n  { 98, NULL, kpidMethod, VT_BSTR},\r\n  { 99, NULL, kpidBlock, VT_UI4}\r\n  #endif\r\n};\r\n\r\nstatic const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);\r\n\r\nstatic int FindPropInMap(UInt64 filePropID)\r\n{\r\n  for (int i = 0; i < kPropMapSize; i++)\r\n    if (kPropMap[i].FilePropID == filePropID)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void CopyOneItem(CRecordVector<UInt64> &src,\r\n    CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      dest.Add(item);\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < dest.Size(); i++)\r\n    if (dest[i] == item)\r\n    {\r\n      dest.Delete(i);\r\n      break;\r\n    }\r\n  dest.Insert(0, item);\r\n}\r\n\r\nvoid CHandler::FillPopIDs()\r\n{\r\n  _fileInfoPopIDs.Clear();\r\n\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() < 1)\r\n    return;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_db = volume.Database;\r\n  #endif\r\n\r\n  CRecordVector<UInt64> fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;\r\n\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);\r\n\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);\r\n  _fileInfoPopIDs += fileInfoPopIDs;\r\n \r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Add(97);\r\n  _fileInfoPopIDs.Add(98);\r\n  _fileInfoPopIDs.Add(99);\r\n  #endif\r\n  #ifdef _MULTI_PACK\r\n  _fileInfoPopIDs.Add(100);\r\n  _fileInfoPopIDs.Add(101);\r\n  _fileInfoPopIDs.Add(102);\r\n  _fileInfoPopIDs.Add(103);\r\n  _fileInfoPopIDs.Add(104);\r\n  #endif\r\n\r\n  #ifndef _SFX\r\n  InsertToHead(_fileInfoPopIDs, NID::kMTime);\r\n  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);\r\n  InsertToHead(_fileInfoPopIDs, NID::kSize);\r\n  InsertToHead(_fileInfoPopIDs, NID::kName);\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)\r\n{\r\n  *numProperties = _fileInfoPopIDs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)\r\n{\r\n  if ((int)index >= _fileInfoPopIDs.Size())\r\n    return E_INVALIDARG;\r\n  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);\r\n  if (indexInMap == -1)\r\n    return E_INVALIDARG;\r\n  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;\r\n  *propID = srcItem.propid;\r\n  *varType = srcItem.vt;\r\n  *name = 0;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zProperties.h",
    "content": "// 7zProperties.h\r\n\r\n#ifndef __7Z_PROPERTIES_H\r\n#define __7Z_PROPERTIES_H\r\n\r\n#include \"../../PropID.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nenum\r\n{\r\n  kpidPackedSize0 = kpidUserDefined,\r\n  kpidPackedSize1,\r\n  kpidPackedSize2,\r\n  kpidPackedSize3,\r\n  kpidPackedSize4\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zRegister.cpp",
    "content": "// 7zRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"7zHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::N7z::CHandler;  }\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"7z\", L\"7z\", 0, 7, {'7' + 1 , 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };\r\n\r\nREGISTER_ARC_DEC_SIG(7z)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zSpecStream.cpp",
    "content": "// 7zSpecStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zSpecStream.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(\r\n    UInt64 subStream, UInt64 *value)\r\n{\r\n  if (_getSubStreamSize == NULL)\r\n    return E_NOTIMPL;\r\n  return  _getSubStreamSize->GetSubStreamSize(subStream, value);\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zSpecStream.h",
    "content": "// 7zSpecStream.h\r\n\r\n#ifndef __7Z_SPEC_STREAM_H\r\n#define __7Z_SPEC_STREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CSequentialInStreamSizeCount2:\r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _getSubStreamSize = 0;\r\n    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zUpdate.cpp",
    "content": "// 7zUpdate.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zFolderInStream.h\"\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kMatchFinderForBCJ2_LZMA = L\"BT2\";\r\nstatic const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;\r\nstatic const UInt32 kAlgorithmForBCJ2_LZMA = 1;\r\nstatic const UInt32 kNumFastBytesForBCJ2_LZMA = 64;\r\n\r\nstatic HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream,\r\n    UInt64 position, UInt64 size, ICompressProgressInfo *progress)\r\n{\r\n  RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));\r\n  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;\r\n  CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);\r\n  streamSpec->SetStream(inStream);\r\n  streamSpec->Init(size);\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n  RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));\r\n  return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);\r\n}\r\n\r\nstatic int GetReverseSlashPos(const UString &name)\r\n{\r\n  int slashPos = name.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = name.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n  return slashPos;\r\n}\r\n\r\nint CUpdateItem::GetExtensionPos() const\r\n{\r\n  int slashPos = GetReverseSlashPos(Name);\r\n  int dotPos = Name.ReverseFind(L'.');\r\n  if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n    return Name.Length();\r\n  return dotPos + 1;\r\n}\r\n\r\nUString CUpdateItem::GetExtension() const\r\n{\r\n  return Name.Mid(GetExtensionPos());\r\n}\r\n\r\n#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }\r\n\r\nstatic int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)\r\n{\r\n  size_t c1 = a1.GetCapacity();\r\n  size_t c2 = a2.GetCapacity();\r\n  RINOZ(MyCompare(c1, c2));\r\n  for (size_t i = 0; i < c1; i++)\r\n    RINOZ(MyCompare(a1[i], a2[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareCoders(const CCoderInfo &c1, const CCoderInfo &c2)\r\n{\r\n  RINOZ(MyCompare(c1.NumInStreams, c2.NumInStreams));\r\n  RINOZ(MyCompare(c1.NumOutStreams, c2.NumOutStreams));\r\n  RINOZ(MyCompare(c1.MethodID, c2.MethodID));\r\n  return CompareBuffers(c1.Props, c2.Props);\r\n}\r\n\r\nstatic int CompareBindPairs(const CBindPair &b1, const CBindPair &b2)\r\n{\r\n  RINOZ(MyCompare(b1.InIndex, b2.InIndex));\r\n  return MyCompare(b1.OutIndex, b2.OutIndex);\r\n}\r\n\r\nstatic int CompareFolders(const CFolder &f1, const CFolder &f2)\r\n{\r\n  int s1 = f1.Coders.Size();\r\n  int s2 = f2.Coders.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  int i;\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareCoders(f1.Coders[i], f2.Coders[i]));\r\n  s1 = f1.BindPairs.Size();\r\n  s2 = f2.BindPairs.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareBindPairs(f1.BindPairs[i], f2.BindPairs[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareFiles(const CFileItem &f1, const CFileItem &f2)\r\n{\r\n  return MyStringCompareNoCase(f1.Name, f2.Name);\r\n}\r\n\r\nstatic int CompareFolderRefs(const int *p1, const int *p2, void *param)\r\n{\r\n  int i1 = *p1;\r\n  int i2 = *p2;\r\n  const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param;\r\n  RINOZ(CompareFolders(\r\n      db.Folders[i1],\r\n      db.Folders[i2]));\r\n  RINOZ(MyCompare(\r\n      db.NumUnpackStreamsVector[i1],\r\n      db.NumUnpackStreamsVector[i2]));\r\n  if (db.NumUnpackStreamsVector[i1] == 0)\r\n    return 0;\r\n  return CompareFiles(\r\n      db.Files[db.FolderStartFileIndex[i1]],\r\n      db.Files[db.FolderStartFileIndex[i2]]);\r\n}\r\n\r\n////////////////////////////////////////////////////////////\r\n\r\nstatic int CompareEmptyItems(const int *p1, const int *p2, void *param)\r\n{\r\n  const CObjectVector<CUpdateItem> &updateItems = *(const CObjectVector<CUpdateItem> *)param;\r\n  const CUpdateItem &u1 = updateItems[*p1];\r\n  const CUpdateItem &u2 = updateItems[*p2];\r\n  if (u1.IsDir != u2.IsDir)\r\n    return (u1.IsDir) ? 1 : -1;\r\n  if (u1.IsDir)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    int n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  if (u1.IsAnti != u2.IsAnti)\r\n    return (u1.IsAnti ? 1 : -1);\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstatic const char *g_Exts =\r\n  \" lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo\"\r\n  \" zip jar ear war msi\"\r\n  \" 3gp avi mov mpeg mpg mpe wmv\"\r\n  \" aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav\"\r\n  \" swf \"\r\n  \" chm hxi hxs\"\r\n  \" gif jpeg jpg jp2 png tiff  bmp ico psd psp\"\r\n  \" awg ps eps cgm dxf svg vrml wmf emf ai md\"\r\n  \" cad dwg pps key sxi\"\r\n  \" max 3ds\"\r\n  \" iso bin nrg mdf img pdi tar cpio xpi\"\r\n  \" vfd vhd vud vmc vsv\"\r\n  \" vmdk dsk nvram vmem vmsd vmsn vmss vmtm\"\r\n  \" inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def\"\r\n  \" f77 f f90 f95\"\r\n  \" asm sql manifest dep \"\r\n  \" mak clw csproj vcproj sln dsp dsw \"\r\n  \" class \"\r\n  \" bat cmd\"\r\n  \" xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml\"\r\n  \" awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs\"\r\n  \" text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf\"\r\n  \" sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf\"\r\n  \" abw afp cwk lwp wpd wps wpt wrf wri\"\r\n  \" abf afm bdf fon mgf otf pcf pfa snf ttf\"\r\n  \" dbf mdb nsf ntf wdb db fdb gdb\"\r\n  \" exe dll ocx vbx sfx sys tlb awx com obj lib out o so \"\r\n  \" pdb pch idb ncb opt\";\r\n\r\nint GetExtIndex(const char *ext)\r\n{\r\n  int extIndex = 1;\r\n  const char *p = g_Exts;\r\n  for (;;)\r\n  {\r\n    char c = *p++;\r\n    if (c == 0)\r\n      return extIndex;\r\n    if (c == ' ')\r\n      continue;\r\n    int pos = 0;\r\n    for (;;)\r\n    {\r\n      char c2 = ext[pos++];\r\n      if (c2 == 0 && (c == 0 || c == ' '))\r\n        return extIndex;\r\n      if (c != c2)\r\n        break;\r\n      c = *p++;\r\n    }\r\n    extIndex++;\r\n    for (;;)\r\n    {\r\n      if (c == 0)\r\n        return extIndex;\r\n      if (c == ' ')\r\n        break;\r\n      c = *p++;\r\n    }\r\n  }\r\n}\r\n\r\nstruct CRefItem\r\n{\r\n  const CUpdateItem *UpdateItem;\r\n  UInt32 Index;\r\n  UInt32 ExtensionPos;\r\n  UInt32 NamePos;\r\n  int ExtensionIndex;\r\n  CRefItem(UInt32 index, const CUpdateItem &ui, bool sortByType):\r\n    UpdateItem(&ui),\r\n    Index(index),\r\n    ExtensionPos(0),\r\n    NamePos(0),\r\n    ExtensionIndex(0)\r\n  {\r\n    if (sortByType)\r\n    {\r\n      int slashPos = GetReverseSlashPos(ui.Name);\r\n      NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0);\r\n      int dotPos = ui.Name.ReverseFind(L'.');\r\n      if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n        ExtensionPos = ui.Name.Length();\r\n      else\r\n      {\r\n        ExtensionPos = dotPos + 1;\r\n        UString us = ui.Name.Mid(ExtensionPos);\r\n        if (!us.IsEmpty())\r\n        {\r\n          us.MakeLower();\r\n          int i;\r\n          AString s;\r\n          for (i = 0; i < us.Length(); i++)\r\n          {\r\n            wchar_t c = us[i];\r\n            if (c >= 0x80)\r\n              break;\r\n            s += (char)c;\r\n          }\r\n          if (i == us.Length())\r\n            ExtensionIndex = GetExtIndex(s);\r\n          else\r\n            ExtensionIndex = 0;\r\n        }\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nstatic int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *param)\r\n{\r\n  const CRefItem &a1 = *p1;\r\n  const CRefItem &a2 = *p2;\r\n  const CUpdateItem &u1 = *a1.UpdateItem;\r\n  const CUpdateItem &u2 = *a2.UpdateItem;\r\n  int n;\r\n  if (u1.IsDir != u2.IsDir)\r\n    return (u1.IsDir) ? 1 : -1;\r\n  if (u1.IsDir)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  bool sortByType = *(bool *)param;\r\n  if (sortByType)\r\n  {\r\n    RINOZ(MyCompare(a1.ExtensionIndex, a2.ExtensionIndex))\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos));\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos));\r\n    if (!u1.MTimeDefined && u2.MTimeDefined) return 1;\r\n    if (u1.MTimeDefined && !u2.MTimeDefined) return -1;\r\n    if (u1.MTimeDefined && u2.MTimeDefined) RINOZ(MyCompare(u1.MTime, u2.MTime));\r\n    RINOZ(MyCompare(u1.Size, u2.Size))\r\n  }\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstruct CSolidGroup\r\n{\r\n  CCompressionMethodMode Method;\r\n  CRecordVector<UInt32> Indices;\r\n};\r\n\r\nstatic wchar_t *g_ExeExts[] =\r\n{\r\n  L\"dll\",\r\n  L\"exe\",\r\n  L\"ocx\",\r\n  L\"sfx\",\r\n  L\"sys\"\r\n};\r\n\r\nstatic bool IsExeFile(const UString &ext)\r\n{\r\n  for (int i = 0; i < sizeof(g_ExeExts) / sizeof(g_ExeExts[0]); i++)\r\n    if (ext.CompareNoCase(g_ExeExts[i]) == 0)\r\n      return true;\r\n  return false;\r\n}\r\n\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_BCJ   = 0x03030103;\r\nstatic const UInt64 k_BCJ2  = 0x0303011B;\r\n\r\nstatic bool GetMethodFull(UInt64 methodID,\r\n    UInt32 numInStreams, CMethodFull &methodResult)\r\n{\r\n  methodResult.Id = methodID;\r\n  methodResult.NumInStreams = numInStreams;\r\n  methodResult.NumOutStreams = 1;\r\n  return true;\r\n}\r\n\r\nstatic bool MakeExeMethod(const CCompressionMethodMode &method,\r\n    bool bcj2Filter, CCompressionMethodMode &exeMethod)\r\n{\r\n  exeMethod = method;\r\n  if (bcj2Filter)\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ2, 4, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    if (!GetMethodFull(k_LZMA, 1, methodFull))\r\n      return false;\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kAlgorithm;\r\n      prop.Value = kAlgorithmForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kMatchFinder;\r\n      prop.Value = kMatchFinderForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = kDictionaryForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kNumFastBytes;\r\n      prop.Value = kNumFastBytesForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n\r\n    exeMethod.Methods.Add(methodFull);\r\n    exeMethod.Methods.Add(methodFull);\r\n    CBind bind;\r\n\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 2;\r\n    bind.OutStream = 1;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 3;\r\n    bind.OutStream = 2;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  else\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ, 1, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    CBind bind;\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  return true;\r\n}\r\n\r\nstatic void SplitFilesToGroups(\r\n    const CCompressionMethodMode &method,\r\n    bool useFilters, bool maxFilter,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    CObjectVector<CSolidGroup> &groups)\r\n{\r\n  if (method.Methods.Size() != 1 || method.Binds.Size() != 0)\r\n    useFilters = false;\r\n  groups.Clear();\r\n  groups.Add(CSolidGroup());\r\n  groups.Add(CSolidGroup());\r\n  CSolidGroup &generalGroup = groups[0];\r\n  CSolidGroup &exeGroup = groups[1];\r\n  generalGroup.Method = method;\r\n  int i;\r\n  for (i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &ui = updateItems[i];\r\n    if (!ui.NewData)\r\n      continue;\r\n    if (!ui.HasStream())\r\n      continue;\r\n    if (useFilters)\r\n    {\r\n      const UString name = ui.Name;\r\n      int dotPos = name.ReverseFind(L'.');\r\n      if (dotPos >= 0)\r\n      {\r\n        UString ext = name.Mid(dotPos + 1);\r\n        if (IsExeFile(ext))\r\n        {\r\n          exeGroup.Indices.Add(i);\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    generalGroup.Indices.Add(i);\r\n  }\r\n  if (exeGroup.Indices.Size() > 0)\r\n    if (!MakeExeMethod(method, maxFilter, exeGroup.Method))\r\n      exeGroup.Method = method;\r\n  for (i = 0; i < groups.Size();)\r\n    if (groups[i].Indices.Size() == 0)\r\n      groups.Delete(i);\r\n    else\r\n      i++;\r\n}\r\n\r\nstatic void FromUpdateItemToFileItem(const CUpdateItem &ui,\r\n    CFileItem &file, CFileItem2 &file2)\r\n{\r\n  file.Name = NItemName::MakeLegalName(ui.Name);\r\n  if (ui.AttribDefined)\r\n    file.SetAttrib(ui.Attrib);\r\n  \r\n  file2.CTime = ui.CTime;  file2.CTimeDefined = ui.CTimeDefined;\r\n  file2.ATime = ui.ATime;  file2.ATimeDefined = ui.ATimeDefined;\r\n  file2.MTime = ui.MTime;  file2.MTimeDefined = ui.MTimeDefined;\r\n  file2.IsAnti = ui.IsAnti;\r\n  file2.StartPosDefined = false;\r\n\r\n  file.Size = ui.Size;\r\n  file.IsDir = ui.IsDir;\r\n  file.HasStream = ui.HasStream();\r\n}\r\n\r\nstatic HRESULT Update2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  UInt64 numSolidFiles = options.NumSolidFiles;\r\n  if (numSolidFiles == 0)\r\n    numSolidFiles = 1;\r\n  /*\r\n  CMyComPtr<IOutStream> outStream;\r\n  RINOK(seqOutStream->QueryInterface(IID_IOutStream, (void **)&outStream));\r\n  if (!outStream)\r\n    return E_NOTIMPL;\r\n  */\r\n\r\n  UInt64 startBlockSize = db != 0 ? db->ArchiveInfo.StartPosition: 0;\r\n  if (startBlockSize > 0 && !options.RemoveSfxBlock)\r\n  {\r\n    RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));\r\n  }\r\n\r\n  CRecordVector<int> fileIndexToUpdateIndexMap;\r\n  if (db != 0)\r\n  {\r\n    fileIndexToUpdateIndexMap.Reserve(db->Files.Size());\r\n    for (int i = 0; i < db->Files.Size(); i++)\r\n      fileIndexToUpdateIndexMap.Add(-1);\r\n  }\r\n  int i;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    int index = updateItems[i].IndexInArchive;\r\n    if (index != -1)\r\n      fileIndexToUpdateIndexMap[index] = i;\r\n  }\r\n\r\n  CRecordVector<int> folderRefs;\r\n  if (db != 0)\r\n  {\r\n    for(i = 0; i < db->Folders.Size(); i++)\r\n    {\r\n      CNum indexInFolder = 0;\r\n      CNum numCopyItems = 0;\r\n      CNum numUnpackStreams = db->NumUnpackStreamsVector[i];\r\n      for (CNum fileIndex = db->FolderStartFileIndex[i];\r\n      indexInFolder < numUnpackStreams; fileIndex++)\r\n      {\r\n        if (db->Files[fileIndex].HasStream)\r\n        {\r\n          indexInFolder++;\r\n          int updateIndex = fileIndexToUpdateIndexMap[fileIndex];\r\n          if (updateIndex >= 0)\r\n            if (!updateItems[updateIndex].NewData)\r\n              numCopyItems++;\r\n        }\r\n      }\r\n      if (numCopyItems != numUnpackStreams && numCopyItems != 0)\r\n        return E_NOTIMPL; // It needs repacking !!!\r\n      if (numCopyItems > 0)\r\n        folderRefs.Add(i);\r\n    }\r\n    folderRefs.Sort(CompareFolderRefs, (void *)db);\r\n  }\r\n\r\n  ////////////////////////////\r\n\r\n  RINOK(archive.Create(seqOutStream, false));\r\n  RINOK(archive.SkeepPrefixArchiveHeader());\r\n  UInt64 complexity = 0;\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n    complexity += db->GetFolderFullPackSize(folderRefs[i]);\r\n  UInt64 inSizeForReduce = 0;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &ui = updateItems[i];\r\n    if (ui.NewData)\r\n    {\r\n      complexity += ui.Size;\r\n      if (numSolidFiles == 1)\r\n      {\r\n        if (ui.Size > inSizeForReduce)\r\n          inSizeForReduce = ui.Size;\r\n      }\r\n      else\r\n        inSizeForReduce += ui.Size;\r\n    }\r\n  }\r\n  RINOK(updateCallback->SetTotal(complexity));\r\n  complexity = 0;\r\n  RINOK(updateCallback->SetCompleted(&complexity));\r\n\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(updateCallback, true);\r\n\r\n  /////////////////////////////////////////\r\n  // Write Copy Items\r\n\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n  {\r\n    int folderIndex = folderRefs[i];\r\n    \r\n    lps->ProgressOffset = complexity;\r\n    UInt64 packSize = db->GetFolderFullPackSize(folderIndex);\r\n    RINOK(WriteRange(inStream, archive.SeqStream,\r\n        db->GetFolderStreamPos(folderIndex, 0), packSize, progress));\r\n    complexity += packSize;\r\n    \r\n    const CFolder &folder = db->Folders[folderIndex];\r\n    CNum startIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      newDatabase.PackSizes.Add(db->PackSizes[startIndex + j]);\r\n      // newDatabase.PackCRCsDefined.Add(db.PackCRCsDefined[startIndex + j]);\r\n      // newDatabase.PackCRCs.Add(db.PackCRCs[startIndex + j]);\r\n    }\r\n    newDatabase.Folders.Add(folder);\r\n\r\n    CNum numUnpackStreams = db->NumUnpackStreamsVector[folderIndex];\r\n    newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\r\n\r\n    CNum indexInFolder = 0;\r\n    for (CNum fi = db->FolderStartFileIndex[folderIndex];\r\n        indexInFolder < numUnpackStreams; fi++)\r\n    {\r\n      CFileItem file;\r\n      CFileItem2 file2;\r\n      db->GetFile(fi, file, file2);\r\n      if (file.HasStream)\r\n      {\r\n        indexInFolder++;\r\n        int updateIndex = fileIndexToUpdateIndexMap[fi];\r\n        if (updateIndex >= 0)\r\n        {\r\n          const CUpdateItem &ui = updateItems[updateIndex];\r\n          if (ui.NewProperties)\r\n          {\r\n            CFileItem uf;\r\n            FromUpdateItemToFileItem(ui, uf, file2);\r\n            uf.Size = file.Size;\r\n            uf.Crc = file.Crc;\r\n            uf.CrcDefined = file.CrcDefined;\r\n            uf.HasStream = file.HasStream;\r\n            file = uf;\r\n          }\r\n        }\r\n        newDatabase.AddFile(file, file2);\r\n      }\r\n    }\r\n  }\r\n\r\n  folderRefs.ClearAndFree();\r\n  fileIndexToUpdateIndexMap.ClearAndFree();\r\n\r\n  /////////////////////////////////////////\r\n  // Compress New Files\r\n\r\n  CObjectVector<CSolidGroup> groups;\r\n  SplitFilesToGroups(*options.Method, options.UseFilters, options.MaxFilter,\r\n      updateItems, groups);\r\n\r\n  const UInt32 kMinReduceSize = (1 << 16);\r\n  if (inSizeForReduce < kMinReduceSize)\r\n    inSizeForReduce = kMinReduceSize;\r\n\r\n  for (int groupIndex = 0; groupIndex < groups.Size(); groupIndex++)\r\n  {\r\n    const CSolidGroup &group = groups[groupIndex];\r\n    int numFiles = group.Indices.Size();\r\n    if (numFiles == 0)\r\n      continue;\r\n    CRecordVector<CRefItem> refItems;\r\n    refItems.Reserve(numFiles);\r\n    bool sortByType = (numSolidFiles > 1);\r\n    for (i = 0; i < numFiles; i++)\r\n      refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType));\r\n    refItems.Sort(CompareUpdateItems, (void *)&sortByType);\r\n    \r\n    CRecordVector<UInt32> indices;\r\n    indices.Reserve(numFiles);\r\n\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      UInt32 index = refItems[i].Index;\r\n      indices.Add(index);\r\n      /*\r\n      const CUpdateItem &ui = updateItems[index];\r\n      CFileItem file;\r\n      if (ui.NewProperties)\r\n        FromUpdateItemToFileItem(ui, file);\r\n      else\r\n        file = db.Files[ui.IndexInArchive];\r\n      if (file.IsAnti || file.IsDir)\r\n        return E_FAIL;\r\n      newDatabase.Files.Add(file);\r\n      */\r\n    }\r\n    \r\n    CEncoder encoder(group.Method);\r\n\r\n    for (i = 0; i < numFiles;)\r\n    {\r\n      UInt64 totalSize = 0;\r\n      int numSubFiles;\r\n      UString prevExtension;\r\n      for (numSubFiles = 0; i + numSubFiles < numFiles &&\r\n          numSubFiles < numSolidFiles; numSubFiles++)\r\n      {\r\n        const CUpdateItem &ui = updateItems[indices[i + numSubFiles]];\r\n        totalSize += ui.Size;\r\n        if (totalSize > options.NumSolidBytes)\r\n          break;\r\n        if (options.SolidExtension)\r\n        {\r\n          UString ext = ui.GetExtension();\r\n          if (numSubFiles == 0)\r\n            prevExtension = ext;\r\n          else\r\n            if (ext.CompareNoCase(prevExtension) != 0)\r\n              break;\r\n        }\r\n      }\r\n      if (numSubFiles < 1)\r\n        numSubFiles = 1;\r\n\r\n      CFolderInStream *inStreamSpec = new CFolderInStream;\r\n      CMyComPtr<ISequentialInStream> solidInStream(inStreamSpec);\r\n      inStreamSpec->Init(updateCallback, &indices[i], numSubFiles);\r\n      \r\n      CFolder folderItem;\r\n\r\n      int startPackIndex = newDatabase.PackSizes.Size();\r\n      RINOK(encoder.Encode(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          solidInStream, NULL, &inSizeForReduce, folderItem,\r\n          archive.SeqStream, newDatabase.PackSizes, progress));\r\n\r\n      for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)\r\n        lps->OutSize += newDatabase.PackSizes[startPackIndex];\r\n\r\n      lps->InSize += folderItem.GetUnpackSize();\r\n      // for()\r\n      // newDatabase.PackCRCsDefined.Add(false);\r\n      // newDatabase.PackCRCs.Add(0);\r\n      \r\n      newDatabase.Folders.Add(folderItem);\r\n      \r\n      CNum numUnpackStreams = 0;\r\n      for (int subIndex = 0; subIndex < numSubFiles; subIndex++)\r\n      {\r\n        const CUpdateItem &ui = updateItems[indices[i + subIndex]];\r\n        CFileItem file;\r\n        CFileItem2 file2;\r\n        if (ui.NewProperties)\r\n          FromUpdateItemToFileItem(ui, file, file2);\r\n        else\r\n          db->GetFile(ui.IndexInArchive, file, file2);\r\n        if (file2.IsAnti || file.IsDir)\r\n          return E_FAIL;\r\n        \r\n        /*\r\n        CFileItem &file = newDatabase.Files[\r\n              startFileIndexInDatabase + i + subIndex];\r\n        */\r\n        if (!inStreamSpec->Processed[subIndex])\r\n        {\r\n          continue;\r\n          // file.Name += L\".locked\";\r\n        }\r\n\r\n        file.Crc = inStreamSpec->CRCs[subIndex];\r\n        file.Size = inStreamSpec->Sizes[subIndex];\r\n        if (file.Size != 0)\r\n        {\r\n          file.CrcDefined = true;\r\n          file.HasStream = true;\r\n          numUnpackStreams++;\r\n        }\r\n        else\r\n        {\r\n          file.CrcDefined = false;\r\n          file.HasStream = false;\r\n        }\r\n        newDatabase.AddFile(file, file2);\r\n      }\r\n      // numUnpackStreams = 0 is very bad case for locked files\r\n      // v3.13 doesn't understand it.\r\n      newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\r\n      i += numSubFiles;\r\n    }\r\n  }\r\n\r\n  groups.ClearAndFree();\r\n\r\n  {\r\n    /////////////////////////////////////////\r\n    // Write Empty Files & Folders\r\n    \r\n    CRecordVector<int> emptyRefs;\r\n    for(i = 0; i < updateItems.Size(); i++)\r\n    {\r\n      const CUpdateItem &ui = updateItems[i];\r\n      if (ui.NewData)\r\n      {\r\n        if (ui.HasStream())\r\n          continue;\r\n      }\r\n      else\r\n        if (ui.IndexInArchive != -1)\r\n          if (db->Files[ui.IndexInArchive].HasStream)\r\n            continue;\r\n      emptyRefs.Add(i);\r\n    }\r\n    emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);\r\n    for (i = 0; i < emptyRefs.Size(); i++)\r\n    {\r\n      const CUpdateItem &ui = updateItems[emptyRefs[i]];\r\n      CFileItem file;\r\n      CFileItem2 file2;\r\n      if (ui.NewProperties)\r\n        FromUpdateItemToFileItem(ui, file, file2);\r\n      else\r\n        db->GetFile(ui.IndexInArchive, file, file2);\r\n      newDatabase.AddFile(file, file2);\r\n    }\r\n  }\r\n    \r\n  newDatabase.ReserveDown();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  return Update2(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        inStream, db, updateItems,\r\n        archive, newDatabase, seqOutStream, updateCallback, options);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/7zUpdate.h",
    "content": "// 7zUpdate.h\r\n\r\n#ifndef __7Z_UPDATE_H\r\n#define __7Z_UPDATE_H\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CUpdateItem\r\n{\r\n  int IndexInArchive;\r\n  int IndexInClient;\r\n  \r\n  UInt64 CTime;\r\n  UInt64 ATime;\r\n  UInt64 MTime;\r\n\r\n  UInt64 Size;\r\n  UString Name;\r\n\r\n  UInt32 Attrib;\r\n  \r\n  bool NewData;\r\n  bool NewProperties;\r\n\r\n  bool IsAnti;\r\n  bool IsDir;\r\n\r\n  bool AttribDefined;\r\n  bool CTimeDefined;\r\n  bool ATimeDefined;\r\n  bool MTimeDefined;\r\n\r\n  bool HasStream() const { return !IsDir && !IsAnti && Size != 0; }\r\n\r\n  CUpdateItem():\r\n      IsAnti(false),\r\n      IsDir(false),\r\n      AttribDefined(false),\r\n      CTimeDefined(false),\r\n      ATimeDefined(false),\r\n      MTimeDefined(false)\r\n      {}\r\n  void SetDirStatusFromAttrib() { IsDir = ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0); };\r\n\r\n  int GetExtensionPos() const;\r\n  UString GetExtension() const;\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  const CCompressionMethodMode *Method;\r\n  const CCompressionMethodMode *HeaderMethod;\r\n  bool UseFilters;\r\n  bool MaxFilter;\r\n\r\n  CHeaderOptions HeaderOptions;\r\n\r\n  UInt64 NumSolidFiles;\r\n  UInt64 NumSolidBytes;\r\n  bool SolidExtension;\r\n  bool RemoveSfxBlock;\r\n  bool VolumeMode;\r\n};\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options);\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Archive.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Archive2.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n  GetNumberOfMethods PRIVATE\r\n  GetMethodProperty PRIVATE\r\n  SetLargePageMode PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/ArchiveExports.cpp",
    "content": "// ArchiveExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterArc.h\"\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\r\nvoid RegisterArc(const CArcInfo *arcInfo)\r\n{\r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler,\r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\n#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nint FindFormatCalssId(const GUID *clsID)\r\n{\r\n  GUID cls = *clsID;\r\n  CLS_ARC_ID_ITEM(cls) = 0;\r\n  if (cls != CLSID_CArchiveHandler)\r\n    return -1;\r\n  Byte id = CLS_ARC_ID_ITEM(*clsID);\r\n  for (unsigned i = 0; i < g_NumArcs; i++)\r\n    if (g_Arcs[i]->ClassId == id)\r\n      return (int)i;\r\n  return -1;\r\n}\r\n\r\nSTDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  {\r\n    int needIn = (*iid == IID_IInArchive);\r\n    int needOut = (*iid == IID_IOutArchive);\r\n    if (!needIn && !needOut)\r\n      return E_NOINTERFACE;\r\n    int formatIndex = FindFormatCalssId(clsid);\r\n    if (formatIndex < 0)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    \r\n    const CArcInfo &arc = *g_Arcs[formatIndex];\r\n    if (needIn)\r\n    {\r\n      *outObject = arc.CreateInArchive();\r\n      ((IInArchive *)*outObject)->AddRef();\r\n    }\r\n    else\r\n    {\r\n      if (!arc.CreateOutArchive)\r\n        return CLASS_E_CLASSNOTAVAILABLE;\r\n      *outObject = arc.CreateOutArchive();\r\n      ((IOutArchive *)*outObject)->AddRef();\r\n    }\r\n  }\r\n  COM_TRY_END\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  if (formatIndex >= g_NumArcs)\r\n    return E_INVALIDARG;\r\n  const CArcInfo &arc = *g_Arcs[formatIndex];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case NArchive::kName:\r\n      prop = arc.Name;\r\n      break;\r\n    case NArchive::kClassID:\r\n    {\r\n      GUID clsId = CLSID_CArchiveHandler;\r\n      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;\r\n      return SetPropGUID(clsId, value);\r\n    }\r\n    case NArchive::kExtension:\r\n      if (arc.Ext != 0)\r\n        prop = arc.Ext;\r\n      break;\r\n    case NArchive::kAddExtension:\r\n      if (arc.AddExt != 0)\r\n        prop = arc.AddExt;\r\n      break;\r\n    case NArchive::kUpdate:\r\n      prop = (bool)(arc.CreateOutArchive != 0);\r\n      break;\r\n    case NArchive::kKeepName:\r\n      prop = arc.KeepName;\r\n      break;\r\n    case NArchive::kStartSignature:\r\n      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  return GetHandlerProperty2(0, propID, value);\r\n}\r\n\r\nSTDAPI GetNumberOfFormats(UINT32 *numFormats)\r\n{\r\n  *numFormats = g_NumArcs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/CoderMixer2.cpp",
    "content": "// CoderMixer2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):\r\n  _srcBindInfo(srcBindInfo)\r\n{\r\n  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);\r\n\r\n  UInt32  j;\r\n  for (j = 0; j < NumSrcInStreams; j++)\r\n  {\r\n    _srcInToDestOutMap.Add(0);\r\n    DestOutToSrcInMap.Add(0);\r\n  }\r\n  for (j = 0; j < _numSrcOutStreams; j++)\r\n  {\r\n    _srcOutToDestInMap.Add(0);\r\n    _destInToSrcOutMap.Add(0);\r\n  }\r\n\r\n  UInt32 destInOffset = 0;\r\n  UInt32 destOutOffset = 0;\r\n  UInt32 srcInOffset = NumSrcInStreams;\r\n  UInt32 srcOutOffset = _numSrcOutStreams;\r\n\r\n  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];\r\n\r\n    srcInOffset -= srcCoderInfo.NumInStreams;\r\n    srcOutOffset -= srcCoderInfo.NumOutStreams;\r\n    \r\n    UInt32 j;\r\n    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)\r\n    {\r\n      UInt32 index = srcInOffset + j;\r\n      _srcInToDestOutMap[index] = destOutOffset;\r\n      DestOutToSrcInMap[destOutOffset] = index;\r\n    }\r\n    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)\r\n    {\r\n      UInt32 index = srcOutOffset + j;\r\n      _srcOutToDestInMap[index] = destInOffset;\r\n      _destInToSrcOutMap[destInOffset] = index;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)\r\n{\r\n  destBindInfo.Coders.Clear();\r\n  destBindInfo.BindPairs.Clear();\r\n  destBindInfo.InStreams.Clear();\r\n  destBindInfo.OutStreams.Clear();\r\n\r\n  int i;\r\n  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];\r\n    CCoderStreamsInfo destCoderInfo;\r\n    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;\r\n    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;\r\n    destBindInfo.Coders.Add(destCoderInfo);\r\n  }\r\n  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];\r\n    CBindPair destBindPair;\r\n    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];\r\n    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];\r\n    destBindInfo.BindPairs.Add(destBindPair);\r\n  }\r\n  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)\r\n    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);\r\n  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)\r\n    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);\r\n}\r\n\r\nCCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams):\r\n    NumInStreams(numInStreams),\r\n    NumOutStreams(numOutStreams)\r\n{\r\n  InSizes.Reserve(NumInStreams);\r\n  InSizePointers.Reserve(NumInStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\nvoid CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,\r\n      const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/CoderMixer2.h",
    "content": "// CoderMixer2.h\r\n\r\n#ifndef __CODER_MIXER2_H\r\n#define __CODER_MIXER2_H\r\n\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n};\r\n\r\nstruct CCoderStreamsInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n};\r\n\r\nstruct CBindInfo\r\n{\r\n  CRecordVector<CCoderStreamsInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<UInt32> InStreams;\r\n  CRecordVector<UInt32> OutStreams;\r\n\r\n  void Clear()\r\n  {\r\n    Coders.Clear();\r\n    BindPairs.Clear();\r\n    InStreams.Clear();\r\n    OutStreams.Clear();\r\n  }\r\n\r\n  /*\r\n  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const\r\n  {\r\n    UInt32 numOutStreams = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      numOutStreams += Coders[i].NumOutStreams;\r\n    return numOutStreams;\r\n  }\r\n  */\r\n\r\n\r\n  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const\r\n  {\r\n    numInStreams = 0;\r\n    numOutStreams = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n    {\r\n      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];\r\n      numInStreams += coderStreamsInfo.NumInStreams;\r\n      numOutStreams += coderStreamsInfo.NumOutStreams;\r\n    }\r\n  }\r\n\r\n  int FindBinderForInStream(UInt32 inStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBinderForOutStream(UInt32 outStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumInStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumOutStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n\r\n  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,\r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumInStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,\r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumOutStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n};\r\n\r\nclass CBindReverseConverter\r\n{\r\n  UInt32 _numSrcOutStreams;\r\n  NCoderMixer::CBindInfo _srcBindInfo;\r\n  CRecordVector<UInt32> _srcInToDestOutMap;\r\n  CRecordVector<UInt32> _srcOutToDestInMap;\r\n  CRecordVector<UInt32> _destInToSrcOutMap;\r\npublic:\r\n  UInt32 NumSrcInStreams;\r\n  CRecordVector<UInt32> DestOutToSrcInMap;\r\n\r\n  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);\r\n  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);\r\n};\r\n\r\nstruct CCoderInfo2\r\n{\r\n  CMyComPtr<ICompressCoder> Coder;\r\n  CMyComPtr<ICompressCoder2> Coder2;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n\r\n  CRecordVector<UInt64> InSizes;\r\n  CRecordVector<UInt64> OutSizes;\r\n  CRecordVector<const UInt64 *> InSizePointers;\r\n  CRecordVector<const UInt64 *> OutSizePointers;\r\n\r\n  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n\r\n  HRESULT QueryInterface(REFGUID iid, void** pp) const\r\n  {\r\n    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;\r\n    return p->QueryInterface(iid, pp);\r\n  }\r\n};\r\n\r\nclass CCoderMixer2\r\n{\r\npublic:\r\n  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;\r\n  virtual void ReInit() = 0;\r\n  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;\r\n};\r\n\r\n}\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/CoderMixer2MT.cpp",
    "content": "// CoderMixer2MT.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2MT.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams):\r\n    CCoderInfo2(numInStreams, numOutStreams)\r\n{\r\n  InStreams.Reserve(NumInStreams);\r\n  InStreamPointers.Reserve(NumInStreams);\r\n  OutStreams.Reserve(NumOutStreams);\r\n  OutStreamPointers.Reserve(NumOutStreams);\r\n}\r\n\r\nvoid CCoder2::Execute() { Code(NULL); }\r\n\r\nvoid CCoder2::Code(ICompressProgressInfo *progress)\r\n{\r\n  InStreamPointers.Clear();\r\n  OutStreamPointers.Clear();\r\n  UInt32 i;\r\n  for (i = 0; i < NumInStreams; i++)\r\n  {\r\n    if (InSizePointers[i] != NULL)\r\n      InSizePointers[i] = &InSizes[i];\r\n    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);\r\n  }\r\n  for (i = 0; i < NumOutStreams; i++)\r\n  {\r\n    if (OutSizePointers[i] != NULL)\r\n      OutSizePointers[i] = &OutSizes[i];\r\n    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);\r\n  }\r\n  if (Coder)\r\n    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],\r\n        InSizePointers[0], OutSizePointers[0], progress);\r\n  else\r\n    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,\r\n      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);\r\n  {\r\n    int i;\r\n    for (i = 0; i < InStreams.Size(); i++)\r\n      InStreams[i].Release();\r\n    for (i = 0; i < OutStreams.Size(); i++)\r\n      OutStreams[i].Release();\r\n  }\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\n\r\nvoid CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n//////////////////////////////////////\r\n// CCoderMixer2MT\r\n\r\nHRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)\r\n{\r\n  _bindInfo = bindInfo;\r\n  _streamBinders.Clear();\r\n  for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    _streamBinders.Add(CStreamBinder());\r\n    RINOK(_streamBinders.Back().CreateEvents());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoderCommon()\r\n{\r\n  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];\r\n  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);\r\n  _coders.Add(threadCoderInfo);\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder(ICompressCoder *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder = coder;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder2 = coder;\r\n}\r\n\r\n\r\nvoid CCoderMixer2MT::ReInit()\r\n{\r\n  for(int i = 0; i < _streamBinders.Size(); i++)\r\n    _streamBinders[i].ReInit();\r\n}\r\n\r\n\r\nHRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams)\r\n{\r\n  /*\r\n  if (_coders.Size() != _bindInfo.Coders.Size())\r\n    throw 0;\r\n  */\r\n  int i;\r\n  for(i = 0; i < _coders.Size(); i++)\r\n  {\r\n    CCoder2 &coderInfo = _coders[i];\r\n    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];\r\n    coderInfo.InStreams.Clear();\r\n    UInt32 j;\r\n    for(j = 0; j < coderStreamsInfo.NumInStreams; j++)\r\n      coderInfo.InStreams.Add(NULL);\r\n    coderInfo.OutStreams.Clear();\r\n    for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)\r\n      coderInfo.OutStreams.Add(NULL);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = _bindInfo.BindPairs[i];\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);\r\n    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);\r\n\r\n    _streamBinders[i].CreateStreams(\r\n        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],\r\n        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.InStreams.Size(); i++)\r\n  {\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);\r\n    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];\r\n  }\r\n  \r\n  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);\r\n    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)\r\n{\r\n  for (int i = 0; i < _coders.Size(); i++)\r\n    if (_coders[i].Result == code)\r\n      return code;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||\r\n      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())\r\n    return E_INVALIDARG;\r\n\r\n  Init(inStreams, outStreams);\r\n\r\n  int i;\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n    {\r\n      RINOK(_coders[i].Create());\r\n    }\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].Start();\r\n\r\n  _coders[_progressCoderIndex].Code(progress);\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].WaitFinish();\r\n\r\n  RINOK(ReturnIfError(E_ABORT));\r\n  RINOK(ReturnIfError(E_OUTOFMEMORY));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK && result != E_FAIL && result != S_FALSE)\r\n      return result;\r\n  }\r\n\r\n  RINOK(ReturnIfError(S_FALSE));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/CoderMixer2MT.h",
    "content": "// CoderMixer2MT.h\r\n\r\n#ifndef __CODER_MIXER2_MT_H\r\n#define __CODER_MIXER2_MT_H\r\n\r\n#include \"CoderMixer2.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../Common/StreamBinder.h\"\r\n#include \"../../Common/VirtThread.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CCoder2: public CCoderInfo2, public CVirtThread\r\n{\r\n  HRESULT Result;\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;\r\n  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;\r\n  CRecordVector<ISequentialInStream*> InStreamPointers;\r\n  CRecordVector<ISequentialOutStream*> OutStreamPointers;\r\n\r\n  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n  virtual void Execute();\r\n  void Code(ICompressProgressInfo *progress);\r\n};\r\n\r\n\r\n/*\r\n  SetBindInfo()\r\n  for each coder\r\n    AddCoder[2]()\r\n  SetProgressIndex(UInt32 coderIndex);\r\n \r\n  for each file\r\n  {\r\n    ReInit()\r\n    for each coder\r\n      SetCoderInfo\r\n    Code\r\n  }\r\n*/\r\n\r\nclass CCoderMixer2MT:\r\n  public ICompressCoder2,\r\n  public CCoderMixer2,\r\n  public CMyUnknownImp\r\n{\r\n  CBindInfo _bindInfo;\r\n  CObjectVector<CStreamBinder> _streamBinders;\r\n  int _progressCoderIndex;\r\n\r\n  void AddCoderCommon();\r\n  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);\r\n  HRESULT ReturnIfError(HRESULT code);\r\npublic:\r\n  CObjectVector<CCoder2> _coders;\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n\r\n  HRESULT SetBindInfo(const CBindInfo &bindInfo);\r\n  void AddCoder(ICompressCoder *coder);\r\n  void AddCoder2(ICompressCoder2 *coder);\r\n  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }\r\n\r\n  void ReInit();\r\n  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)\r\n    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }\r\n  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const\r\n    {  return _streamBinders[binderIndex].ProcessedSize; }\r\n};\r\n\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/CrossThreadProgress.cpp",
    "content": "// CrossThreadProgress.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CrossThreadProgress.h\"\r\n\r\nSTDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  InSize = inSize;\r\n  OutSize = outSize;\r\n  ProgressEvent.Set();\r\n  WaitEvent.Lock();\r\n  return Result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/CrossThreadProgress.h",
    "content": "// CrossThreadProgress.h\r\n\r\n#ifndef __CROSSTHREADPROGRESS_H\r\n#define __CROSSTHREADPROGRESS_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CCrossThreadProgress:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  const UInt64 *InSize;\r\n  const UInt64 *OutSize;\r\n  HRESULT Result;\r\n  NWindows::NSynchronization::CAutoResetEvent ProgressEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent WaitEvent;\r\n\r\n  HRes Create()\r\n  {\r\n    RINOK(ProgressEvent.CreateIfNotCreated());\r\n    return WaitEvent.CreateIfNotCreated();\r\n  }\r\n  void Init()\r\n  {\r\n    ProgressEvent.Reset();\r\n    WaitEvent.Reset();\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/DummyOutStream.cpp",
    "content": "// DummyOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DummyOutStream.h\"\r\n\r\nSTDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/DummyOutStream.h",
    "content": "// DummyOutStream.h\r\n\r\n#ifndef __DUMMYOUTSTREAM_H\r\n#define __DUMMYOUTSTREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nclass CDummyOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init() { _size = 0; }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/HandlerOut.cpp",
    "content": "// HandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#include \"HandlerOut.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\n\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kLZMA2MethodName = L\"LZMA2\";\r\nstatic const wchar_t *kBZip2MethodName = L\"BZip2\";\r\nstatic const wchar_t *kPpmdMethodName = L\"PPMd\";\r\nstatic const wchar_t *kDeflateMethodName = L\"Deflate\";\r\nstatic const wchar_t *kDeflate64MethodName = L\"Deflate64\";\r\n\r\nstatic const wchar_t *kLzmaMatchFinderX1 = L\"HC4\";\r\nstatic const wchar_t *kLzmaMatchFinderX5 = L\"BT4\";\r\n\r\nstatic const UInt32 kLzmaAlgoX1 = 0;\r\nstatic const UInt32 kLzmaAlgoX5 = 1;\r\n\r\nstatic const UInt32 kLzmaDicSizeX1 = 1 << 16;\r\nstatic const UInt32 kLzmaDicSizeX3 = 1 << 20;\r\nstatic const UInt32 kLzmaDicSizeX5 = 1 << 24;\r\nstatic const UInt32 kLzmaDicSizeX7 = 1 << 25;\r\nstatic const UInt32 kLzmaDicSizeX9 = 1 << 26;\r\n\r\nstatic const UInt32 kLzmaFastBytesX1 = 32;\r\nstatic const UInt32 kLzmaFastBytesX7 = 64;\r\n\r\nstatic const UInt32 kPpmdMemSizeX1 = (1 << 22);\r\nstatic const UInt32 kPpmdMemSizeX5 = (1 << 24);\r\nstatic const UInt32 kPpmdMemSizeX7 = (1 << 26);\r\nstatic const UInt32 kPpmdMemSizeX9 = (192 << 20);\r\n\r\nstatic const UInt32 kPpmdOrderX1 = 4;\r\nstatic const UInt32 kPpmdOrderX5 = 6;\r\nstatic const UInt32 kPpmdOrderX7 = 16;\r\nstatic const UInt32 kPpmdOrderX9 = 32;\r\n\r\nstatic const UInt32 kDeflateAlgoX1 = 0;\r\nstatic const UInt32 kDeflateAlgoX5 = 1;\r\n\r\nstatic const UInt32 kDeflateFastBytesX1 = 32;\r\nstatic const UInt32 kDeflateFastBytesX7 = 64;\r\nstatic const UInt32 kDeflateFastBytesX9 = 128;\r\n\r\nstatic const UInt32 kDeflatePassesX1 = 1;\r\nstatic const UInt32 kDeflatePassesX7 = 3;\r\nstatic const UInt32 kDeflatePassesX9 = 10;\r\n\r\nstatic const UInt32 kBZip2NumPassesX1 = 1;\r\nstatic const UInt32 kBZip2NumPassesX7 = 2;\r\nstatic const UInt32 kBZip2NumPassesX9 = 7;\r\n\r\nstatic const UInt32 kBZip2DicSizeX1 = 100000;\r\nstatic const UInt32 kBZip2DicSizeX3 = 500000;\r\nstatic const UInt32 kBZip2DicSizeX5 = 900000;\r\n\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5;\r\n\r\nstatic bool AreEqual(const UString &methodName, const wchar_t *s)\r\n  { return (methodName.CompareNoCase(s) == 0); }\r\n\r\nstatic inline bool IsLZMAMethod(const UString &methodName)\r\n{\r\n  return\r\n    AreEqual(methodName, kLZMAMethodName) ||\r\n    AreEqual(methodName, kLZMA2MethodName);\r\n}\r\n\r\nstatic inline bool IsBZip2Method(const UString &methodName)\r\n  { return AreEqual(methodName, kBZip2MethodName); }\r\n\r\nstatic inline bool IsPpmdMethod(const UString &methodName)\r\n  { return AreEqual(methodName, kPpmdMethodName); }\r\n\r\nstatic inline bool IsDeflateMethod(const UString &methodName)\r\n{\r\n  return\r\n    AreEqual(methodName, kDeflateMethodName) ||\r\n    AreEqual(methodName, kDeflate64MethodName);\r\n}\r\n\r\nstruct CNameToPropID\r\n{\r\n  PROPID PropID;\r\n  VARTYPE VarType;\r\n  const wchar_t *Name;\r\n};\r\n\r\nCNameToPropID g_NameToPropID[] =\r\n{\r\n  { NCoderPropID::kOrder, VT_UI4, L\"O\" },\r\n  { NCoderPropID::kPosStateBits, VT_UI4, L\"PB\" },\r\n  { NCoderPropID::kLitContextBits, VT_UI4, L\"LC\" },\r\n  { NCoderPropID::kLitPosBits, VT_UI4, L\"LP\" },\r\n  { NCoderPropID::kEndMarker, VT_BOOL, L\"eos\" },\r\n\r\n  { NCoderPropID::kNumPasses, VT_UI4, L\"Pass\" },\r\n  { NCoderPropID::kNumFastBytes, VT_UI4, L\"fb\" },\r\n  { NCoderPropID::kMatchFinderCycles, VT_UI4, L\"mc\" },\r\n  { NCoderPropID::kAlgorithm, VT_UI4, L\"a\" },\r\n  { NCoderPropID::kMatchFinder, VT_BSTR, L\"mf\" },\r\n  { NCoderPropID::kNumThreads, VT_UI4, L\"mt\" }\r\n};\r\n\r\nstatic bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp)\r\n{\r\n  if (varType == srcProp.vt)\r\n  {\r\n    destProp = srcProp;\r\n    return true;\r\n  }\r\n  if (varType == VT_UI1)\r\n  {\r\n    if (srcProp.vt == VT_UI4)\r\n    {\r\n      UInt32 value = srcProp.ulVal;\r\n      if (value > 0xFF)\r\n        return false;\r\n      destProp = (Byte)value;\r\n      return true;\r\n    }\r\n  }\r\n  else if (varType == VT_BOOL)\r\n  {\r\n    bool res;\r\n    if (SetBoolProperty(res, srcProp) != S_OK)\r\n      return false;\r\n    destProp = res;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n    \r\nstatic int FindPropIdFromStringName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)\r\n    if (name.CompareNoCase(g_NameToPropID[i].Name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID,\r\n    const NWindows::NCOM::CPropVariant &value)\r\n{\r\n  for (int j = 0; j < oneMethodInfo.Props.Size(); j++)\r\n    if (oneMethodInfo.Props[j].Id == propID)\r\n      return;\r\n  CProp prop;\r\n  prop.Id = propID;\r\n  prop.Value = value;\r\n  oneMethodInfo.Props.Add(prop);\r\n}\r\n\r\nvoid COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  if (oneMethodInfo.MethodName.IsEmpty())\r\n    oneMethodInfo.MethodName = kDefaultMethodName;\r\n  \r\n  if (IsLZMAMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 dicSize =\r\n      (level >= 9 ? kLzmaDicSizeX9 :\r\n      (level >= 7 ? kLzmaDicSizeX7 :\r\n      (level >= 5 ? kLzmaDicSizeX5 :\r\n      (level >= 3 ? kLzmaDicSizeX3 :\r\n                    kLzmaDicSizeX1))));\r\n    \r\n    UInt32 algo =\r\n      (level >= 5 ? kLzmaAlgoX5 :\r\n                    kLzmaAlgoX1);\r\n    \r\n    UInt32 fastBytes =\r\n      (level >= 7 ? kLzmaFastBytesX7 :\r\n                    kLzmaFastBytesX1);\r\n    \r\n    const wchar_t *matchFinder =\r\n      (level >= 5 ? kLzmaMatchFinderX5 :\r\n                    kLzmaMatchFinderX1);\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsDeflateMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 fastBytes =\r\n      (level >= 9 ? kDeflateFastBytesX9 :\r\n      (level >= 7 ? kDeflateFastBytesX7 :\r\n                    kDeflateFastBytesX1));\r\n    \r\n    UInt32 numPasses =\r\n      (level >= 9 ? kDeflatePassesX9 :\r\n      (level >= 7 ? kDeflatePassesX7 :\r\n                    kDeflatePassesX1));\r\n    \r\n    UInt32 algo =\r\n      (level >= 5 ? kDeflateAlgoX5 :\r\n                    kDeflateAlgoX1);\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n  }\r\n  else if (IsBZip2Method(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 numPasses =\r\n      (level >= 9 ? kBZip2NumPassesX9 :\r\n      (level >= 7 ? kBZip2NumPassesX7 :\r\n                    kBZip2NumPassesX1));\r\n    \r\n    UInt32 dicSize =\r\n      (level >= 5 ? kBZip2DicSizeX5 :\r\n      (level >= 3 ? kBZip2DicSizeX3 :\r\n                    kBZip2DicSizeX1));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsPpmdMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 useMemSize =\r\n      (level >= 9 ? kPpmdMemSizeX9 :\r\n      (level >= 7 ? kPpmdMemSizeX7 :\r\n      (level >= 5 ? kPpmdMemSizeX5 :\r\n                    kPpmdMemSizeX1)));\r\n    \r\n    UInt32 order =\r\n      (level >= 9 ? kPpmdOrderX9 :\r\n      (level >= 7 ? kPpmdOrderX7 :\r\n      (level >= 5 ? kPpmdOrderX5 :\r\n                    kPpmdOrderX1)));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order);\r\n  }\r\n}\r\n\r\nstatic void SplitParams(const UString &srcString, UStringVector &subStrings)\r\n{\r\n  subStrings.Clear();\r\n  UString name;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L':')\r\n    {\r\n      subStrings.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  subStrings.Add(name);\r\n}\r\n\r\nstatic void SplitParam(const UString &param, UString &name, UString &value)\r\n{\r\n  int eqPos = param.Find(L'=');\r\n  if (eqPos >= 0)\r\n  {\r\n    name = param.Left(eqPos);\r\n    value = param.Mid(eqPos + 1);\r\n    return;\r\n  }\r\n  for(int i = 0; i < param.Length(); i++)\r\n  {\r\n    wchar_t c = param[i];\r\n    if (c >= L'0' && c <= L'9')\r\n    {\r\n      name = param.Left(i);\r\n      value = param.Mid(i);\r\n      return;\r\n    }\r\n  }\r\n  name = param;\r\n}\r\n\r\nHRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value)\r\n{\r\n  CProp prop;\r\n  if (name.CompareNoCase(L\"D\") == 0 ||\r\n      name.CompareNoCase(L\"MEM\") == 0)\r\n  {\r\n    UInt32 dicSize;\r\n    RINOK(ParsePropDictionaryValue(value, dicSize));\r\n    prop.Id = (name.CompareNoCase(L\"D\") == 0) ?\r\n        NCoderPropID::kDictionarySize :\r\n        NCoderPropID::kUsedMemorySize;\r\n    prop.Value = dicSize;\r\n  }\r\n  else\r\n  {\r\n    int index = FindPropIdFromStringName(name);\r\n    if (index < 0)\r\n      return E_INVALIDARG;\r\n    \r\n    const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n    prop.Id = nameToPropID.PropID;\r\n    \r\n    NCOM::CPropVariant propValue;\r\n    \r\n    if (nameToPropID.VarType == VT_BSTR)\r\n      propValue = value;\r\n    else if (nameToPropID.VarType == VT_BOOL)\r\n    {\r\n      bool res;\r\n      if (!StringToBool(value, res))\r\n        return E_INVALIDARG;\r\n      propValue = res;\r\n    }\r\n    else\r\n    {\r\n      UInt32 number;\r\n      if (ParseStringToUInt32(value, number) == value.Length())\r\n        propValue = number;\r\n      else\r\n        propValue = value;\r\n    }\r\n    \r\n    if (!ConvertProperty(propValue, nameToPropID.VarType, prop.Value))\r\n      return E_INVALIDARG;\r\n  }\r\n  oneMethodInfo.Props.Add(prop);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString)\r\n{\r\n  UStringVector params;\r\n  SplitParams(srcString, params);\r\n  if (params.Size() > 0)\r\n    oneMethodInfo.MethodName = params[0];\r\n  for (int i = 1; i < params.Size(); i++)\r\n  {\r\n    const UString &param = params[i];\r\n    UString name, value;\r\n    SplitParam(param, name, value);\r\n    RINOK(SetParam(oneMethodInfo, name, value));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const UString &s)\r\n{\r\n  UString s2 = s;\r\n  s2.MakeUpper();\r\n  for (int i = 0; i < s2.Length();)\r\n  {\r\n    const wchar_t *start = ((const wchar_t *)s2) + i;\r\n    const wchar_t *end;\r\n    UInt64 v = ConvertStringToUInt64(start, &end);\r\n    if (start == end)\r\n    {\r\n      if (s2[i++] != 'E')\r\n        return E_INVALIDARG;\r\n      _solidExtension = true;\r\n      continue;\r\n    }\r\n    i += (int)(end - start);\r\n    if (i == s2.Length())\r\n      return E_INVALIDARG;\r\n    wchar_t c = s2[i++];\r\n    switch(c)\r\n    {\r\n      case 'F':\r\n        if (v < 1)\r\n          v = 1;\r\n        _numSolidFiles = v;\r\n        break;\r\n      case 'B':\r\n        _numSolidBytes = v;\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'K':\r\n        _numSolidBytes = (v << 10);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'M':\r\n        _numSolidBytes = (v << 20);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'G':\r\n        _numSolidBytes = (v << 30);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)\r\n{\r\n  bool isSolid;\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      isSolid = true;\r\n      break;\r\n    case VT_BOOL:\r\n      isSolid = (value.boolVal != VARIANT_FALSE);\r\n      break;\r\n    case VT_BSTR:\r\n      if (StringToBool(value.bstrVal, isSolid))\r\n        break;\r\n      return SetSolidSettings(value.bstrVal);\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  if (isSolid)\r\n    InitSolid();\r\n  else\r\n    _numSolidFiles = 1;\r\n  return S_OK;\r\n}\r\n\r\nvoid COutHandler::Init()\r\n{\r\n  _removeSfxBlock = false;\r\n  _compressHeaders = true;\r\n  _encryptHeadersSpecified = false;\r\n  _encryptHeaders = false;\r\n  \r\n  WriteCTime = false;\r\n  WriteATime = false;\r\n  WriteMTime = true;\r\n  \r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  \r\n  _level = 5;\r\n  _autoFilter = true;\r\n  _volumeMode = false;\r\n  _crcSize = 4;\r\n  InitSolid();\r\n}\r\n\r\nvoid COutHandler::BeforeSetProperty()\r\n{\r\n  Init();\r\n  #ifdef COMPRESS_MT\r\n  numProcessors = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n\r\n  mainDicSize = 0xFFFFFFFF;\r\n  mainDicMethodIndex = 0xFFFFFFFF;\r\n  minNumber = 0;\r\n  _crcSize = 4;\r\n}\r\n\r\nHRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)\r\n{\r\n  UString name = nameSpec;\r\n  name.MakeUpper();\r\n  if (name.IsEmpty())\r\n    return E_INVALIDARG;\r\n  \r\n  if (name[0] == 'X')\r\n  {\r\n    name.Delete(0);\r\n    _level = 9;\r\n    return ParsePropValue(name, value, _level);\r\n  }\r\n  \r\n  if (name[0] == L'S')\r\n  {\r\n    name.Delete(0);\r\n    if (name.IsEmpty())\r\n      return SetSolidSettings(value);\r\n    if (value.vt != VT_EMPTY)\r\n      return E_INVALIDARG;\r\n    return SetSolidSettings(name);\r\n  }\r\n  \r\n  if (name == L\"CRC\")\r\n  {\r\n    _crcSize = 4;\r\n    name.Delete(0, 3);\r\n    return ParsePropValue(name, value, _crcSize);\r\n  }\r\n  \r\n  UInt32 number;\r\n  int index = ParseStringToUInt32(name, number);\r\n  UString realName = name.Mid(index);\r\n  if (index == 0)\r\n  {\r\n    if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n    {\r\n      #ifdef COMPRESS_MT\r\n      RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n      #endif\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"RSFX\") == 0)  return SetBoolProperty(_removeSfxBlock, value);\r\n    if (name.CompareNoCase(L\"F\") == 0) return SetBoolProperty(_autoFilter, value);\r\n    if (name.CompareNoCase(L\"HC\") == 0) return SetBoolProperty(_compressHeaders, value);\r\n    if (name.CompareNoCase(L\"HCF\") == 0)\r\n    {\r\n      bool compressHeadersFull = true;\r\n      RINOK(SetBoolProperty(compressHeadersFull, value));\r\n      if (!compressHeadersFull)\r\n        return E_INVALIDARG;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"HE\") == 0)\r\n    {\r\n      RINOK(SetBoolProperty(_encryptHeaders, value));\r\n      _encryptHeadersSpecified = true;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"TC\") == 0) return SetBoolProperty(WriteCTime, value);\r\n    if (name.CompareNoCase(L\"TA\") == 0) return SetBoolProperty(WriteATime, value);\r\n    if (name.CompareNoCase(L\"TM\") == 0) return SetBoolProperty(WriteMTime, value);\r\n    if (name.CompareNoCase(L\"V\") == 0) return SetBoolProperty(_volumeMode, value);\r\n    number = 0;\r\n  }\r\n  if (number > 10000)\r\n    return E_FAIL;\r\n  if (number < minNumber)\r\n    return E_INVALIDARG;\r\n  number -= minNumber;\r\n  for(int j = _methods.Size(); j <= (int)number; j++)\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    _methods.Add(oneMethodInfo);\r\n  }\r\n  \r\n  COneMethodInfo &oneMethodInfo = _methods[number];\r\n  \r\n  if (realName.Length() == 0)\r\n  {\r\n    if (value.vt != VT_BSTR)\r\n      return E_INVALIDARG;\r\n    \r\n    RINOK(SetParams(oneMethodInfo, value.bstrVal));\r\n  }\r\n  else\r\n  {\r\n    CProp prop;\r\n    if (realName.Left(1).CompareNoCase(L\"D\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize));\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = dicSize;\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else if (realName.Left(1).CompareNoCase(L\"C\") == 0)\r\n    {\r\n      UInt32 blockSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, blockSize));\r\n      prop.Id = NCoderPropID::kBlockSize;\r\n      prop.Value = blockSize;\r\n    }\r\n    else if (realName.Left(3).CompareNoCase(L\"MEM\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize));\r\n      prop.Id = NCoderPropID::kUsedMemorySize;\r\n      prop.Value = dicSize;\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else\r\n    {\r\n      int index = FindPropIdFromStringName(realName);\r\n      if (index < 0)\r\n        return E_INVALIDARG;\r\n      const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n      prop.Id = nameToPropID.PropID;\r\n      if (!ConvertProperty(value, nameToPropID.VarType, prop.Value))\r\n        return E_INVALIDARG;\r\n    }\r\n    oneMethodInfo.Props.Add(prop);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/HandlerOut.h",
    "content": "// HandlerOut.h\r\n\r\n#ifndef __HANDLER_OUT_H\r\n#define __HANDLER_OUT_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\n\r\nstruct COneMethodInfo\r\n{\r\n  CObjectVector<CProp> Props;\r\n  UString MethodName;\r\n};\r\n\r\nclass COutHandler\r\n{\r\npublic:\r\n  HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);\r\n  \r\n  HRESULT SetSolidSettings(const UString &s);\r\n  HRESULT SetSolidSettings(const PROPVARIANT &value);\r\n\r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  CObjectVector<COneMethodInfo> _methods;\r\n  bool _removeSfxBlock;\r\n  \r\n  UInt64 _numSolidFiles;\r\n  UInt64 _numSolidBytes;\r\n  bool _numSolidBytesDefined;\r\n  bool _solidExtension;\r\n\r\n  bool _compressHeaders;\r\n  bool _encryptHeadersSpecified;\r\n  bool _encryptHeaders;\r\n\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  bool _autoFilter;\r\n  UInt32 _level;\r\n\r\n  bool _volumeMode;\r\n\r\n  HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value);\r\n  HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);\r\n\r\n  void SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }\r\n  void InitSolidSize()  { _numSolidBytes = (UInt64)(Int64)(-1); }\r\n  void InitSolid()\r\n  {\r\n    InitSolidFiles();\r\n    InitSolidSize();\r\n    _solidExtension = false;\r\n    _numSolidBytesDefined = false;\r\n  }\r\n\r\n  void Init();\r\n\r\n  COutHandler() { Init(); }\r\n\r\n  void BeforeSetProperty();\r\n\r\n  UInt32 minNumber;\r\n  UInt32 numProcessors;\r\n  UInt32 mainDicSize;\r\n  UInt32 mainDicMethodIndex;\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.cpp",
    "content": "// InStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _size += realProcessedSize;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if (seekOrigin != STREAM_SEEK_SET || offset != 0)\r\n    return E_FAIL;\r\n  _size = 0;\r\n  _crc = CRC_INIT_VAL;\r\n  return _stream->Seek(offset, seekOrigin, newPosition);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.h",
    "content": "// InStreamWithCRC.h\r\n\r\n#ifndef __INSTREAMWITHCRC_H\r\n#define __INSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass CSequentialInStreamWithCRC:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CInStreamWithCRC:\r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\nprivate:\r\n  CMyComPtr<IInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(IInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/ItemNameUtils.cpp",
    "content": "// Archive/Common/ItemNameUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\nstatic const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;\r\nstatic const wchar_t kDirDelimiter = L'/';\r\n\r\nUString MakeLegalName(const UString &name)\r\n{\r\n  UString zipName = name;\r\n  zipName.Replace(kOSDirDelimiter, kDirDelimiter);\r\n  return zipName;\r\n}\r\n\r\nUString GetOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(kDirDelimiter, kOSDirDelimiter);\r\n  return newName;\r\n}\r\n\r\nUString GetOSName2(const UString &name)\r\n{\r\n  if (name.IsEmpty())\r\n    return UString();\r\n  UString newName = GetOSName(name);\r\n  if (newName[newName.Length() - 1] == kOSDirDelimiter)\r\n    newName.Delete(newName.Length() - 1);\r\n  return newName;\r\n}\r\n\r\nbool HasTailSlash(const AString &name, UINT codePage)\r\n{\r\n  if (name.IsEmpty())\r\n    return false;\r\n  LPCSTR prev =\r\n  #ifdef _WIN32\r\n    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);\r\n  #else\r\n    (LPCSTR)(name) + (name.Length() - 1);\r\n  #endif\r\n  return (*prev == '/');\r\n}\r\n\r\n#ifndef _WIN32\r\nUString WinNameToOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(L'\\\\', kOSDirDelimiter);\r\n  return newName;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/ItemNameUtils.h",
    "content": "// Archive/Common/ItemNameUtils.h\r\n\r\n#ifndef __ARCHIVE_ITEMNAMEUTILS_H\r\n#define __ARCHIVE_ITEMNAMEUTILS_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\n  UString MakeLegalName(const UString &name);\r\n  UString GetOSName(const UString &name);\r\n  UString GetOSName2(const UString &name);\r\n  bool HasTailSlash(const AString &name, UINT codePage);\r\n\r\n  #ifdef _WIN32\r\n  inline UString WinNameToOSName(const UString &name)  { return name; }\r\n  #else\r\n  UString WinNameToOSName(const UString &name);\r\n  #endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/MultiStream.cpp",
    "content": "// MultiStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MultiStream.h\"\r\n\r\nSTDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(_streamIndex < Streams.Size() && size > 0)\r\n  {\r\n    CSubStreamInfo &s = Streams[_streamIndex];\r\n    if (_pos == s.Size)\r\n    {\r\n      _streamIndex++;\r\n      _pos = 0;\r\n      continue;\r\n    }\r\n    RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));\r\n    UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));\r\n    UInt32 realProcessed;\r\n    HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _pos += realProcessed;\r\n    _seekPos += realProcessed;\r\n    RINOK(result);\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 newPos;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      newPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      newPos = _seekPos + offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      newPos = _totalLength + offset;\r\n      break;\r\n    default:\r\n      return STG_E_INVALIDFUNCTION;\r\n  }\r\n  _seekPos = 0;\r\n  for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)\r\n  {\r\n    UInt64 size = Streams[_streamIndex].Size;\r\n    if (newPos < _seekPos + size)\r\n    {\r\n      _pos = newPos - _seekPos;\r\n      _seekPos += _pos;\r\n      if (newPosition != 0)\r\n        *newPosition = newPos;\r\n      return S_OK;\r\n    }\r\n    _seekPos += size;\r\n  }\r\n  if (newPos == _seekPos)\r\n  {\r\n    if (newPosition != 0)\r\n      *newPosition = newPos;\r\n    return S_OK;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\n\r\n/*\r\nclass COutVolumeStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback,\r\n      const UString &name)\r\n  {\r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n*/\r\n\r\n/*\r\nSTDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));\r\n      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));\r\n      subStream.Pos = 0;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n    if (_offsetPos >= subStream.Size)\r\n    {\r\n      _offsetPos -= subStream.Size;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      CMyComPtr<IOutStream> outStream;\r\n      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == subStream.Size)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/MultiStream.h",
    "content": "// MultiStream.h\r\n\r\n#ifndef __MULTISTREAM_H\r\n#define __MULTISTREAM_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nclass CMultiStream:\r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex;\r\n  UInt64 _pos;\r\n  UInt64 _seekPos;\r\n  UInt64 _totalLength;\r\npublic:\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<IInStream> Stream;\r\n    UInt64 Pos;\r\n    UInt64 Size;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _pos = 0;\r\n    _seekPos = 0;\r\n    _totalLength = 0;\r\n    for (int i = 0; i < Streams.Size(); i++)\r\n      _totalLength += Streams[i].Size;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n\r\n/*\r\nclass COutMultiStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<ISequentialOutStream> Stream;\r\n    UInt64 Size;\r\n    UInt64 Pos;\r\n };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp",
    "content": "// OutStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  if (_calculate)\r\n    _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.h",
    "content": "// OutStreamWithCRC.h\r\n\r\n#ifndef __OUT_STREAM_WITH_CRC_H\r\n#define __OUT_STREAM_WITH_CRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass COutStreamWithCRC:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _calculate;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(bool calculate = true)\r\n  {\r\n    _size = 0;\r\n    _calculate = calculate;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void InitCRC() { _crc = CRC_INIT_VAL; }\r\n  UInt64 GetSize() const { return _size; }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/ParseProperties.cpp",
    "content": "// ParseProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ParseProperties.h\"\r\n\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (prop.vt == VT_UI4)\r\n  {\r\n    if (!name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    resValue = prop.ulVal;\r\n  }\r\n  else if (prop.vt == VT_EMPTY)\r\n  {\r\n    if(!name.IsEmpty())\r\n    {\r\n      const wchar_t *start = name;\r\n      const wchar_t *end;\r\n      UInt64 v = ConvertStringToUInt64(start, &end);\r\n      if (end - start != name.Length())\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)v;\r\n    }\r\n  }\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kLogarithmicSizeLimit = 32;\r\nstatic const wchar_t kByteSymbol = L'B';\r\nstatic const wchar_t kKiloByteSymbol = L'K';\r\nstatic const wchar_t kMegaByteSymbol = L'M';\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)\r\n{\r\n  UString srcString = srcStringSpec;\r\n  srcString.MakeUpper();\r\n\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || srcString.Length() > numDigits + 1)\r\n    return E_INVALIDARG;\r\n  if (srcString.Length() == numDigits)\r\n  {\r\n    if (number >= kLogarithmicSizeLimit)\r\n      return E_INVALIDARG;\r\n    dicSize = (UInt32)1 << (int)number;\r\n    return S_OK;\r\n  }\r\n  switch (srcString[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      if (number >= ((UInt64)1 << kLogarithmicSizeLimit))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)number;\r\n      break;\r\n    case kKiloByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 10);\r\n      break;\r\n    case kMegaByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 20);\r\n      break;\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    if (prop.vt == VT_UI4)\r\n    {\r\n      UInt32 logDicSize = prop.ulVal;\r\n      if (logDicSize >= 32)\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)1 << logDicSize;\r\n      return S_OK;\r\n    }\r\n    if (prop.vt == VT_BSTR)\r\n      return ParsePropDictionaryValue(prop.bstrVal, resValue);\r\n    return E_INVALIDARG;\r\n  }\r\n  return ParsePropDictionaryValue(name, resValue);\r\n}\r\n\r\nbool StringToBool(const UString &s, bool &res)\r\n{\r\n  if (s.IsEmpty() || s.CompareNoCase(L\"ON\") == 0 || s.Compare(L\"+\") == 0)\r\n  {\r\n    res = true;\r\n    return true;\r\n  }\r\n  if (s.CompareNoCase(L\"OFF\") == 0 || s.Compare(L\"-\") == 0)\r\n  {\r\n    res = false;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      dest = true;\r\n      return S_OK;\r\n    case VT_BOOL:\r\n      dest = (value.boolVal != VARIANT_FALSE);\r\n      return S_OK;\r\n    /*\r\n    case VT_UI4:\r\n      dest = (value.ulVal != 0);\r\n      break;\r\n    */\r\n    case VT_BSTR:\r\n      return StringToBool(value.bstrVal, dest) ?  S_OK : E_INVALIDARG;\r\n  }\r\n  return E_INVALIDARG;\r\n}\r\n\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number)\r\n{\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number64 = ConvertStringToUInt64(start, &end);\r\n  if (number64 > 0xFFFFFFFF)\r\n  {\r\n    number = 0;\r\n    return 0;\r\n  }\r\n  number = (UInt32)number64;\r\n  return (int)(end - start);\r\n}\r\n\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    switch(prop.vt)\r\n    {\r\n      case VT_UI4:\r\n        numThreads = prop.ulVal;\r\n        break;\r\n      default:\r\n      {\r\n        bool val;\r\n        RINOK(SetBoolProperty(val, prop));\r\n        numThreads = (val ? defaultNumThreads : 1);\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index != name.Length())\r\n      return E_INVALIDARG;\r\n    numThreads = number;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/ParseProperties.h",
    "content": "// ParseProperties.h\r\n\r\n#ifndef __PARSEPROPERTIES_H\r\n#define __PARSEPROPERTIES_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\n\r\nbool StringToBool(const UString &s, bool &res);\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number);\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/DllExports2.cpp",
    "content": "// DLLExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyInitGuid.h\"\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nHINSTANCE g_hInstance;\r\n#ifndef _UNICODE\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)\r\n{\r\n  if (dwReason == DLL_PROCESS_ATTACH)\r\n  {\r\n    g_hInstance = hInstance;\r\n    #ifndef _UNICODE\r\n    #ifdef _WIN32\r\n    g_IsNT = IsItWindowsNT();\r\n    #endif\r\n    #endif\r\n  }\r\n  return TRUE;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler,\r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec,\r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);\r\nSTDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);\r\n\r\nSTDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  // COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)\r\n  {\r\n    return CreateCoder(clsid, iid, outObject);\r\n  }\r\n  else\r\n  {\r\n    return CreateArchiver(clsid, iid, outObject);\r\n  }\r\n  // COM_TRY_END\r\n}\r\n\r\nSTDAPI SetLargePageMode()\r\n{\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  SetLargePageSize();\r\n  #endif\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/IArchive.h",
    "content": "// IArchive.h\r\n\r\n#ifndef __IARCHIVE_H\r\n#define __IARCHIVE_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../IProgress.h\"\r\n#include \"../PropID.h\"\r\n\r\n#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)\r\n#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nnamespace NFileTimeType\r\n{\r\n  enum EEnum\r\n  {\r\n    kWindows,\r\n    kUnix,\r\n    kDOS\r\n  };\r\n}\r\n\r\nnamespace NArchive\r\n{\r\n  enum\r\n  {\r\n    kName = 0,\r\n    kClassID,\r\n    kExtension,\r\n    kAddExtension,\r\n    kUpdate,\r\n    kKeepName,\r\n    kStartSignature,\r\n    kFinishSignature,\r\n    kAssociate\r\n  };\r\n\r\n  namespace NExtract\r\n  {\r\n    namespace NAskMode\r\n    {\r\n      enum\r\n      {\r\n        kExtract = 0,\r\n        kTest,\r\n        kSkip\r\n      };\r\n    }\r\n    namespace NOperationResult\r\n    {\r\n      enum\r\n      {\r\n        kOK = 0,\r\n        kUnSupportedMethod,\r\n        kDataError,\r\n        kCRCError\r\n      };\r\n    }\r\n  }\r\n  namespace NUpdate\r\n  {\r\n    namespace NOperationResult\r\n    {\r\n      enum\r\n      {\r\n        kOK = 0,\r\n        kError\r\n      };\r\n    }\r\n  }\r\n}\r\n\r\n#define INTERFACE_IArchiveOpenCallback(x) \\\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) x; \\\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)\r\n{\r\n  INTERFACE_IArchiveOpenCallback(PURE);\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveExtractCallback(x) \\\r\n  INTERFACE_IProgress(x) \\\r\n  /* GetStream OUT: S_OK - OK, S_FALSE - skeep this file */ \\\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream,  Int32 askExtractMode) x; \\\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode) x; \\\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)\r\n{\r\n  INTERFACE_IArchiveExtractCallback(PURE)\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveOpenVolumeCallback(x) \\\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) x; \\\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)\r\n{\r\n  INTERFACE_IArchiveOpenVolumeCallback(PURE);\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)\r\n{\r\n  STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;\r\n};\r\n\r\n\r\n/*\r\nIInArchive::Extract:\r\n  indices must be sorted\r\n  numItems = 0xFFFFFFFF means \"all files\"\r\n  testMode != 0 means \"test files without writing to outStream\"\r\n*/\r\n\r\n#define INTERFACE_IInArchive(x) \\\r\n  STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \\\r\n  STDMETHOD(Close)() x; \\\r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \\\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \\\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;\r\n\r\nARCHIVE_INTERFACE(IInArchive, 0x60)\r\n{\r\n  INTERFACE_IInArchive(PURE)\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveUpdateCallback(x) \\\r\n  INTERFACE_IProgress(x); \\\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,  \\\r\n      Int32 *newData, /*1 - new data, 0 - old data */ \\\r\n      Int32 *newProperties, /* 1 - new properties, 0 - old properties */ \\\r\n      UInt32 *indexInArchive /* -1 if there is no in archive, or if doesn't matter */ \\\r\n      )  x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) x; \\\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)\r\n{\r\n  INTERFACE_IArchiveUpdateCallback(PURE);\r\n};\r\n\r\n#define INTERFACE_IArchiveUpdateCallback2(x) \\\r\n  INTERFACE_IArchiveUpdateCallback(x) \\\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) x; \\\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)\r\n{\r\n  INTERFACE_IArchiveUpdateCallback2(PURE);\r\n};\r\n\r\n\r\n#define INTERFACE_IOutArchive(x) \\\r\n  STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \\\r\n  STDMETHOD(GetFileTimeType)(UInt32 *type) x;\r\n\r\nARCHIVE_INTERFACE(IOutArchive, 0xA0)\r\n{\r\n  INTERFACE_IOutArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(ISetProperties, 0x03)\r\n{\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;\r\n};\r\n\r\n\r\n#define IMP_IInArchive_GetProp(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \\\r\n\r\n#define IMP_IInArchive_GetProp_WITH_NAME(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; \\\r\n    if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \\\r\n\r\n#define IMP_IInArchive_Props \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)\r\n\r\n#define IMP_IInArchive_Props_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)\r\n\r\n\r\n#define IMP_IInArchive_ArcProps \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_NO \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = 0; return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \\\r\n    { return E_NOTIMPL; } \\\r\n  STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \\\r\n    { value->vt = VT_EMPTY; return S_OK; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp",
    "content": "// LzmaArcRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"LzmaHandler.h\"\r\n\r\nstatic IInArchive *CreateArc() { return new NArchive::NLzma::CHandler;  }\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"Lzma\", L\"lzma lzma86\", 0, 0xA, {0 }, 0, true, CreateArc, NULL };\r\n\r\nREGISTER_ARC(Lzma)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp",
    "content": "// LzmaFiltersDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaFiltersDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nstatic const UInt64 k_LZMA = 0x030101;\r\nstatic const UInt64 k_BCJ = 0x03030103;\r\n  \r\nHRESULT CDecoder::Code(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CHeader &block,\r\n    ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    UInt64 *inProcessedSize, ICompressProgressInfo *progress)\r\n{\r\n  *inProcessedSize = (UInt64)(Int64)-1;\r\n\r\n  if (block.FilterMethod > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (!_lzmaDecoder)\r\n  {\r\n    RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_LZMA, _lzmaDecoder, false));\r\n    if (_lzmaDecoder == 0)\r\n      return E_NOTIMPL;\r\n  }\r\n\r\n  {\r\n    CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n    _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n    if (!setDecoderProperties)\r\n      return E_NOTIMPL;\r\n    RINOK(setDecoderProperties->SetDecoderProperties2(block.LzmaProps, 5));\r\n  }\r\n\r\n  bool filteredMode = (block.FilterMethod == 1);\r\n\r\n  CMyComPtr<ICompressSetOutStream> setOutStream;\r\n\r\n  if (filteredMode)\r\n  {\r\n    if (!_bcjStream)\r\n    {\r\n      CMyComPtr<ICompressCoder> coder;\r\n      RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_BCJ, coder, false));\r\n      if (!coder)\r\n        return E_NOTIMPL;\r\n      coder.QueryInterface(IID_ISequentialOutStream, &_bcjStream);\r\n      if (!_bcjStream)\r\n        return E_NOTIMPL;\r\n    }\r\n\r\n    _bcjStream.QueryInterface(IID_ICompressSetOutStream, &setOutStream);\r\n    if (!setOutStream)\r\n      return E_NOTIMPL;\r\n    RINOK(setOutStream->SetOutStream(outStream));\r\n    outStream = _bcjStream;\r\n  }\r\n\r\n  const UInt64 *unpackSize = block.HasUnpackSize() ? &block.UnpackSize : NULL;\r\n  RINOK(_lzmaDecoder->Code(inStream, outStream, NULL, unpackSize, progress));\r\n\r\n  if (filteredMode)\r\n  {\r\n    CMyComPtr<IOutStreamFlush> flush;\r\n    _bcjStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n    if (flush)\r\n    {\r\n      RINOK(flush->Flush());\r\n    }\r\n    RINOK(setOutStream->ReleaseOutStream());\r\n  }\r\n\r\n  CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;\r\n  _lzmaDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);\r\n  if (getInStreamProcessedSize)\r\n  {\r\n    RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(inProcessedSize));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h",
    "content": "// LzmaFiltersDecode.h\r\n\r\n#ifndef __LZMA_FILTERS_DECODE_H\r\n#define __LZMA_FILTERS_DECODE_H\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"LzmaItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nclass CDecoder\r\n{\r\n  CMyComPtr<ICompressCoder> _lzmaDecoder;\r\n  CMyComPtr<ISequentialOutStream> _bcjStream;\r\npublic:\r\n  HRESULT Code(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CHeader &block,\r\n      ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      UInt64 *inProcessedSize, ICompressProgressInfo *progress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Lzma/LzmaHandler.cpp",
    "content": "// LzmaHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaHandler.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n#include \"../Common/DummyOutStream.h\"\r\n\r\n#include \"LzmaFiltersDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nSTATPROPSTG kProps[] =\r\n{\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidPackSize, VT_UI8},\r\n  { NULL, kpidMethod, VT_UI1}\r\n};\r\n\r\nIMP_IInArchive_Props\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = 1;\r\n  return S_OK;\r\n}\r\n\r\nstatic void ConvertUInt32ToString(UInt32 value, wchar_t *s)\r\n{\r\n  ConvertUInt64ToString(value, s + MyStringLen(s));\r\n}\r\n\r\nstatic void DictSizeToString(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i <= 31; i++)\r\n    if ((UInt32(1) << i) == value)\r\n    {\r\n      ConvertUInt32ToString(i, s);\r\n      return;\r\n    }\r\n  wchar_t c = L'b';\r\n  if ((value & ((1 << 20) - 1)) == 0)\r\n  {\r\n    value >>= 20;\r\n    c = L'm';\r\n  }\r\n  else if ((value & ((1 << 10) - 1)) == 0)\r\n  {\r\n    value >>= 10;\r\n    c = L'k';\r\n  }\r\n  ConvertUInt32ToString(value, s);\r\n  int p = MyStringLen(s);\r\n  s[p++] = c;\r\n  s[p++] = L'\\0';\r\n}\r\n\r\nstatic void MyStrCat(wchar_t *d, const wchar_t *s)\r\n{\r\n  MyStringCopy(d + MyStringLen(d), s);\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  switch(propID)\r\n  {\r\n    case kpidSize:\r\n      if (m_StreamInfo.HasUnpackSize())\r\n        propVariant = (UInt64)m_StreamInfo.UnpackSize;\r\n      break;\r\n    case kpidPackSize:\r\n      propVariant = (UInt64)m_PackSize;\r\n      break;\r\n    case kpidMethod:\r\n    {\r\n      wchar_t s[64];\r\n      s[0] = '\\0';\r\n      if (m_StreamInfo.IsThereFilter)\r\n      {\r\n        const wchar_t *f;\r\n        if (m_StreamInfo.FilterMethod == 0)\r\n          f = L\"Copy\";\r\n        else if (m_StreamInfo.FilterMethod == 1)\r\n          f = L\"BCJ\";\r\n        else\r\n          f = L\"Unknown\";\r\n        MyStrCat(s, f);\r\n        MyStrCat(s, L\" \");\r\n      }\r\n      MyStrCat(s, L\"LZMA:\");\r\n      DictSizeToString(m_StreamInfo.GetDicSize(), s);\r\n      propVariant = s;\r\n      break;\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *inStream,\r\n    const UInt64 * /* maxCheckStartPosition */,\r\n    IArchiveOpenCallback * /* openArchiveCallback */)\r\n{\r\n  {\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));\r\n\r\n    HRESULT res = ReadStreamHeader(inStream, m_StreamInfo);\r\n    if (res != S_OK)\r\n      return S_FALSE;\r\n    \r\n    Byte b;\r\n    RINOK(ReadStream_FALSE(inStream, &b, 1));\r\n    if (b != 0)\r\n      return S_FALSE;\r\n\r\n    UInt64 endPos;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));\r\n    m_PackSize = endPos - m_StreamStartPosition - m_StreamInfo.GetHeaderSize();\r\n\r\n    m_Stream = inStream;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  m_Stream.Release();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 _aTestMode, IArchiveExtractCallback *extractCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (!allFilesMode)\r\n  {\r\n    if (numItems == 0)\r\n      return S_OK;\r\n    if (numItems != 1)\r\n      return E_INVALIDARG;\r\n    if (indices[0] != 0)\r\n      return E_INVALIDARG;\r\n  }\r\n\r\n  bool testMode = (_aTestMode != 0);\r\n\r\n  RINOK(extractCallback->SetTotal(m_PackSize));\r\n    \r\n  UInt64 currentTotalPacked = 0;\r\n\r\n  CDummyOutStream *outStreamSpec = new CDummyOutStream;\r\n  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n\r\n  {\r\n    CMyComPtr<ISequentialOutStream> realOutStream;\r\n    Int32 askMode = testMode ?\r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n    \r\n    RINOK(extractCallback->GetStream(0, &realOutStream, askMode));\r\n\r\n    outStreamSpec->SetStream(realOutStream);\r\n    outStreamSpec->Init();\r\n    if(!testMode && !realOutStream)\r\n      return S_OK;\r\n    extractCallback->PrepareOperation(askMode);\r\n  }\r\n  \r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, true);\r\n\r\n  CDecoder decoder;\r\n  RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));\r\n  UInt64 streamPos = m_StreamStartPosition;\r\n  Int32 opRes = NArchive::NExtract::NOperationResult::kOK;\r\n  bool firstItem = true;\r\n  for (;;)\r\n  {\r\n    CHeader st;\r\n    HRESULT result = ReadStreamHeader(m_Stream, st);\r\n    if (result != S_OK)\r\n    {\r\n      if (firstItem)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    firstItem = false;\r\n\r\n    lps->OutSize = outStreamSpec->GetSize();\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    streamPos += st.GetHeaderSize();\r\n    UInt64 packProcessed;\r\n\r\n    {\r\n      result = decoder.Code(\r\n          EXTERNAL_CODECS_VARS\r\n          st, m_Stream, outStream, &packProcessed, progress);\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;\r\n        break;\r\n      }\r\n      if (result == S_FALSE)\r\n      {\r\n        opRes = NArchive::NExtract::NOperationResult::kDataError;\r\n        break;\r\n      }\r\n      RINOK(result);\r\n    }\r\n\r\n    if (packProcessed == (UInt64)(Int64)-1)\r\n      break;\r\n    RINOK(m_Stream->Seek(streamPos + packProcessed, STREAM_SEEK_SET, NULL));\r\n    currentTotalPacked += packProcessed;\r\n    streamPos += packProcessed;\r\n  }\r\n  outStream.Release();\r\n  return extractCallback->SetOperationResult(opRes);\r\n  COM_TRY_END\r\n}\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Lzma/LzmaHandler.h",
    "content": "// Lzma/Handler.h\r\n\r\n#ifndef __GZIP_HANDLER_H\r\n#define __GZIP_HANDLER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"LzmaIn.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\n// const UInt64 k_LZMA = 0x030101;\r\n\r\nclass CHandler:\r\n  public IInArchive,\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n  MY_QUERYINTERFACE_ENTRY(IInArchive)\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  STDMETHOD(Open)(IInStream *inStream,\r\n      const UInt64 *maxCheckStartPosition,\r\n      IArchiveOpenCallback *openArchiveCallback);\r\n  STDMETHOD(Close)();\r\n  \r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID,  PROPVARIANT *value);\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems,\r\n      Int32 testMode, IArchiveExtractCallback *extractCallback);\r\n\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);\r\n\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties);\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index,\r\n      BSTR *name, PROPID *propID, VARTYPE *varType);\r\n\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties);\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index,\r\n      BSTR *name, PROPID *propID, VARTYPE *varType);\r\n\r\n  UString GetMethodString();\r\npublic:\r\n  CHandler() {  }\r\n\r\nprivate:\r\n  CHeader m_StreamInfo;\r\n  UInt64 m_StreamStartPosition;\r\n  UInt64 m_PackSize;\r\n\r\n  CMyComPtr<IInStream> m_Stream;\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Lzma/LzmaIn.cpp",
    "content": "// Archive/LzmaIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaIn.h\"\r\n\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n \r\nstatic bool CheckDictSize(const Byte *p)\r\n{\r\n  UInt32 dicSize = GetUi32(p);\r\n  int i;\r\n  for (i = 1; i <= 30; i++)\r\n    if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block)\r\n{\r\n  Byte sig[5 + 9];\r\n  RINOK(ReadStream_FALSE(inStream, sig, 5 + 8));\r\n\r\n  const Byte kMaxProp0Val = 5 * 5 * 9 - 1;\r\n  if (sig[0] > kMaxProp0Val)\r\n    return S_FALSE;\r\n\r\n  for (int i = 0; i < 5; i++)\r\n    block.LzmaProps[i] = sig[i];\r\n  \r\n  block.IsThereFilter = false;\r\n  block.FilterMethod = 0;\r\n\r\n  if (!CheckDictSize(sig + 1))\r\n  {\r\n    if (sig[0] > 1 || sig[1] > kMaxProp0Val)\r\n      return S_FALSE;\r\n    block.IsThereFilter = true;\r\n    block.FilterMethod = sig[0];\r\n    for (int i = 0; i < 5; i++)\r\n      block.LzmaProps[i] = sig[i + 1];\r\n    if (!CheckDictSize(block.LzmaProps + 1))\r\n      return S_FALSE;\r\n    RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1));\r\n  }\r\n  UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0);\r\n  block.UnpackSize = GetUi64(sig + unpOffset);\r\n  if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56))\r\n    return S_FALSE;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Lzma/LzmaIn.h",
    "content": "// Archive/LzmaIn.h\r\n\r\n#ifndef __ARCHIVE_LZMA_IN_H\r\n#define __ARCHIVE_LZMA_IN_H\r\n\r\n#include \"LzmaItem.h\"\r\n#include \"../../IStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &st);\r\n\r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Lzma/LzmaItem.h",
    "content": "// Archive/LzmaItem.h\r\n\r\n#ifndef __ARCHIVE_LZMA_ITEM_H\r\n#define __ARCHIVE_LZMA_ITEM_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\n#include \"../../../../C/CpuArch.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nstruct CHeader\r\n{\r\n  UInt64 UnpackSize;\r\n  bool IsThereFilter;\r\n  Byte FilterMethod;\r\n  Byte LzmaProps[5];\r\n\r\n  UInt32 GetDicSize() const { return GetUi32(LzmaProps + 1); }\r\n  bool HasUnpackSize() const { return (UnpackSize != (UInt64)(Int64)-1);  }\r\n  unsigned GetHeaderSize() const { return 5 + 8 + (IsThereFilter ? 1 : 0); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Lzma/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Split/SplitHandler.cpp",
    "content": "// SplitHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/ComTry.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"../../Common/ProgressUtils.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/MultiStream.h\"\r\n\r\n#include \"SplitHandler.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\nSTATPROPSTG kProps[] =\r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidPackSize, VT_UI8},\r\n};\r\n\r\nIMP_IInArchive_Props\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nclass CSeqName\r\n{\r\npublic:\r\n  UString _unchangedPart;\r\n  UString _changedPart;\r\n  bool _splitStyle;\r\n  UString GetNextName()\r\n  {\r\n    UString newName;\r\n    if (_splitStyle)\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == 'z')\r\n        {\r\n          c = 'a';\r\n          newName = c + newName;\r\n          continue;\r\n        }\r\n        else if (c == 'Z')\r\n        {\r\n          c = 'A';\r\n          newName = c + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        if ((c == 'z' || c == 'Z') && i == 0)\r\n        {\r\n          _unchangedPart += c;\r\n          wchar_t newChar = (c == 'z') ? L'a' : L'A';\r\n          newName.Empty();\r\n          numLetters++;\r\n          for (int k = 0; k < numLetters; k++)\r\n            newName += newChar;\r\n          break;\r\n        }\r\n        newName = c + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == L'9')\r\n        {\r\n          c = L'0';\r\n          newName = c + newName;\r\n          if (i == 0)\r\n            newName = UString(L'1') + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        newName = c + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n    }\r\n    _changedPart = newName;\r\n    return _unchangedPart + _changedPart;\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 * /* maxCheckStartPosition */,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  if (openArchiveCallback == 0)\r\n    return S_FALSE;\r\n  // try\r\n  {\r\n    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openArchiveCallback;\r\n    if (openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback,\r\n        &openVolumeCallback) != S_OK)\r\n      return S_FALSE;\r\n    \r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(openVolumeCallback->GetProperty(kpidName, &prop));\r\n      if (prop.vt != VT_BSTR)\r\n        return S_FALSE;\r\n      _name = prop.bstrVal;\r\n    }\r\n    \r\n    int dotPos = _name.ReverseFind('.');\r\n    UString prefix, ext;\r\n    if (dotPos >= 0)\r\n    {\r\n      prefix = _name.Left(dotPos + 1);\r\n      ext = _name.Mid(dotPos + 1);\r\n    }\r\n    else\r\n      ext = _name;\r\n    UString extBig = ext;\r\n    extBig.MakeUpper();\r\n\r\n    CSeqName seqName;\r\n\r\n    int numLetters = 2;\r\n    bool splitStyle = false;\r\n    if (extBig.Right(2) == L\"AA\")\r\n    {\r\n      splitStyle = true;\r\n      while (numLetters < extBig.Length())\r\n      {\r\n        if (extBig[extBig.Length() - numLetters - 1] != 'A')\r\n          break;\r\n        numLetters++;\r\n      }\r\n    }\r\n    else if (ext.Right(2) == L\"01\")\r\n    {\r\n      while (numLetters < extBig.Length())\r\n      {\r\n        if (extBig[extBig.Length() - numLetters - 1] != '0')\r\n          break;\r\n        numLetters++;\r\n      }\r\n      if (numLetters != ext.Length())\r\n        return S_FALSE;\r\n    }\r\n    else\r\n      return S_FALSE;\r\n\r\n    _streams.Add(stream);\r\n\r\n    seqName._unchangedPart = prefix + ext.Left(extBig.Length() - numLetters);\r\n    seqName._changedPart = ext.Right(numLetters);\r\n    seqName._splitStyle = splitStyle;\r\n\r\n    if (prefix.Length() < 1)\r\n      _subName = L\"file\";\r\n    else\r\n      _subName = prefix.Left(prefix.Length() - 1);\r\n\r\n    _totalSize = 0;\r\n    UInt64 size;\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\r\n      if (prop.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      size = prop.uhVal.QuadPart;\r\n    }\r\n    _totalSize += size;\r\n    _sizes.Add(size);\r\n    \r\n    if (openArchiveCallback != NULL)\r\n    {\r\n      UInt64 numFiles = _streams.Size();\r\n      RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\r\n    }\r\n\r\n    for (;;)\r\n    {\r\n      UString fullName = seqName.GetNextName();\r\n      CMyComPtr<IInStream> nextStream;\r\n      HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);\r\n      if (result == S_FALSE)\r\n        break;\r\n      if (result != S_OK)\r\n        return result;\r\n      if (!stream)\r\n        break;\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\r\n        if (prop.vt != VT_UI8)\r\n          return E_INVALIDARG;\r\n        size = prop.uhVal.QuadPart;\r\n      }\r\n      _totalSize += size;\r\n      _sizes.Add(size);\r\n      _streams.Add(nextStream);\r\n      if (openArchiveCallback != NULL)\r\n      {\r\n        UInt64 numFiles = _streams.Size();\r\n        RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\r\n      }\r\n    }\r\n  }\r\n  /*\r\n  catch(...)\r\n  {\r\n    return S_FALSE;\r\n  }\r\n  */\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  _sizes.Clear();\r\n  _streams.Clear();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = _streams.IsEmpty() ? 0 : 1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n      prop = _subName;\r\n      break;\r\n    case kpidSize:\r\n    case kpidPackSize:\r\n      prop = _totalSize;\r\n      break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  if (numItems != UInt32(-1))\r\n  {\r\n    if (numItems != 1)\r\n      return E_INVALIDARG;\r\n    if (indices[0] != 0)\r\n      return E_INVALIDARG;\r\n  }\r\n  bool testMode = (_aTestMode != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = _anExtractCallback;\r\n  extractCallback->SetTotal(_totalSize);\r\n  \r\n  /*\r\n  CMyComPtr<IArchiveVolumeExtractCallback> volumeExtractCallback;\r\n  if (extractCallback.QueryInterface(&volumeExtractCallback) != S_OK)\r\n    return E_FAIL;\r\n  */\r\n\r\n  UInt64 currentTotalSize = 0;\r\n  UInt64 currentItemSize;\r\n\r\n  RINOK(extractCallback->SetCompleted(&currentTotalSize));\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n  Int32 askMode;\r\n  askMode = testMode ? NArchive::NExtract::NAskMode::kTest :\r\n  NArchive::NExtract::NAskMode::kExtract;\r\n  Int32 index = 0;\r\n  RINOK(extractCallback->GetStream(index, &realOutStream, askMode));\r\n  \r\n  RINOK(extractCallback->PrepareOperation(askMode));\r\n  if (testMode)\r\n  {\r\n    RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\r\n    return S_OK;\r\n  }\r\n  \r\n  if (!testMode && (!realOutStream))\r\n    return S_OK;\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for (int i = 0; i < _streams.Size(); i++, currentTotalSize += currentItemSize)\r\n  {\r\n    lps->InSize = lps->OutSize = currentTotalSize;\r\n    RINOK(lps->SetCur());\r\n    IInStream *inStream = _streams[i];\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));\r\n    currentItemSize = copyCoderSpec->TotalSize;\r\n  }\r\n  realOutStream.Release();\r\n  return extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  *stream = 0;\r\n  CMultiStream *streamSpec = new CMultiStream;\r\n  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;\r\n  for (int i = 0; i < _streams.Size(); i++)\r\n  {\r\n    CMultiStream::CSubStreamInfo subStreamInfo;\r\n    subStreamInfo.Stream = _streams[i];\r\n    subStreamInfo.Pos = 0;\r\n    subStreamInfo.Size = _sizes[i];\r\n    streamSpec->Streams.Add(subStreamInfo);\r\n  }\r\n  streamSpec->Init();\r\n  *stream = streamTemp.Detach();\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Split/SplitHandler.h",
    "content": "// Split/Handler.h\r\n\r\n#ifndef __SPLIT_HANDLER_H\r\n#define __SPLIT_HANDLER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\nclass CHandler:\r\n  public IInArchive,\r\n  public IInArchiveGetStream,\r\n  // public IOutArchive,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);\r\n\r\nprivate:\r\n  UString _subName;\r\n  UString _name;\r\n  CObjectVector<CMyComPtr<IInStream> > _streams;\r\n  CRecordVector<UInt64> _sizes;\r\n\r\n  UInt64 _totalSize;\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Split/SplitHandlerOut.cpp",
    "content": "// Split/OutHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SplitHandler.h\"\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\n/*\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  if (numItems != 1)\r\n    return E_INVALIDARG;\r\n\r\n  UInt64 volumeSize = 0;\r\n\r\n  CMyComPtr<IArchiveUpdateCallback2> callback2;\r\n  updateCallback->QueryInterface(IID_IArchiveUpdateCallback2,\r\n      (void **)&callback2);\r\n\r\n  RINOK(callback2->GetVolumeSize(0, &volumeSize));\r\n\r\n  Int32 newData;\r\n  Int32 newProperties;\r\n  UInt32 indexInArchive;\r\n  if (!updateCallback)\r\n    return E_FAIL;\r\n\r\n  UInt32 fileIndex = 0;\r\n  RINOK(updateCallback->GetUpdateItemInfo(fileIndex,\r\n    &newData, &newProperties, &indexInArchive));\r\n\r\n  if (newProperties != 0)\r\n  {\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsFolder, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n      }\r\n      else if (prop.vt != VT_BOOL)\r\n        return E_INVALIDARG;\r\n      else\r\n      {\r\n        if (prop.boolVal != VARIANT_FALSE)\r\n          return E_INVALIDARG;\r\n      }\r\n    }\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsAnti, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n      }\r\n      else if (prop.vt != VT_BOOL)\r\n        return E_INVALIDARG;\r\n      else\r\n      {\r\n        if (prop.boolVal != VARIANT_FALSE)\r\n          return E_INVALIDARG;\r\n      }\r\n    }\r\n  }\r\n  UInt64 newSize;\r\n  bool thereIsCopyData = false;\r\n  if (newData != 0)\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(updateCallback->GetProperty(fileIndex, kpidSize, &prop));\r\n    if (prop.vt != VT_UI8)\r\n      return E_INVALIDARG;\r\n    newSize = prop.uhVal.QuadPart;\r\n  }\r\n  else\r\n    thereIsCopyData = true;\r\n\r\n  UInt64 pos = 0;\r\n  while(pos < newSize)\r\n  {\r\n\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Split/SplitRegister.cpp",
    "content": "// SplitRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"SplitHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::NSplit::CHandler;  }\r\n/*\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::NSplit::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n*/\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n{ L\"Split\", L\"001\", 0, 0xEA, { 0 }, 0, false, CreateArc, 0 };\r\n\r\nREGISTER_ARC(Split)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/Split/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Archive/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Alone\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Alone - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\" CFG=\"Alone - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Alone - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Alone - Win32 Release\"\r\n# Name \"Alone - Win32 Debug\"\r\n# Name \"Alone - Win32 ReleaseU\"\r\n# Name \"Alone - Win32 DebugU\"\r\n# Begin Group \"Console\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ArError.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\CompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\Main.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\MainAr.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\AutoPtr.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Buffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ComTry.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\DynamicBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyException.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyGuidDef.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyInitGuid.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Device.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Handle.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterArc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterCodec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA_Alone\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Coder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Coder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Register.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchMisc.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchMisc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwap.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwap.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwapRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"7z\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zExtract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"split\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZM\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaArcRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaItem.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"UI Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Property.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7-zip\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IMyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IPassword.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\PropID.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\BraIA64.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Alone\"=.\\Alone.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Alone7z/makefile",
    "content": "PROG = 7za.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib Advapi32.lib\r\n\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -D_NO_CRYPTO \\\r\n  -DWIN_LONG_PATH \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n  $O\\Time.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OffsetStream.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\DummyOutStream.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\MultiStream.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n\r\nLZM_OBJS = \\\r\n  $O\\LzmaArcRegister.obj \\\r\n  $O\\LzmaFiltersDecode.obj \\\r\n  $O\\LzmaHandler.obj \\\r\n  $O\\LzmaIn.obj \\\r\n\r\nSPLIT_OBJS = \\\r\n  $O\\SplitHandler.obj \\\r\n  $O\\SplitHandlerOut.obj \\\r\n  $O\\SplitRegister.obj \\\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(LZM_OBJS) \\\r\n  $(SPLIT_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): ../../UI/Console/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../../UI/Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZM_OBJS): ../../Archive/Lzma/$(*B).cpp\r\n\t$(COMPL)\r\n$(SPLIT_OBJS): ../../Archive/Split/$(*B).cpp\r\n\t$(COMPL)\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Alone7z/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_APP(\"7-Zip Standalone Console\", \"7za\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Format7zExtractR/makefile",
    "content": "PROG = 7zxr.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DEXTRACT_ONLY \\\r\n  -DCOMPRESS_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Format7zExtractR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Extracting Plugin\", \"7zxr\")\r\n\r\n101  ICON  \"../../Archive/Icons/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Format7zR/makefile",
    "content": "PROG = 7zra.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Bundles/Format7zR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Plugin\", \"7zr\")\r\n\r\n101  ICON  \"../../Archive/Icons/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/CreateCoder.cpp",
    "content": "// CreateCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CreateCoder.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Windows/Defs.h\"\r\n#include \"FilterCoder.h\"\r\n#include \"RegisterCodec.h\"\r\n\r\nstatic const unsigned int kNumCodecsMax = 64;\r\nunsigned int g_NumCodecs = 0;\r\nconst CCodecInfo *g_Codecs[kNumCodecsMax];\r\nvoid RegisterCodec(const CCodecInfo *codecInfo)\r\n{\r\n  if (g_NumCodecs < kNumCodecsMax)\r\n    g_Codecs[g_NumCodecs++] = codecInfo;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = 1;\r\n  else if (prop.vt == VT_UI4)\r\n    res = prop.ulVal;\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = true;\r\n  else if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs)\r\n{\r\n  UInt32 num;\r\n  RINOK(codecsInfo->GetNumberOfMethods(&num));\r\n  for (UInt32 i = 0; i < num; i++)\r\n  {\r\n    CCodecInfoEx info;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kID, &prop));\r\n    // if (prop.vt != VT_BSTR)\r\n    // info.Id.IDSize = (Byte)SysStringByteLen(prop.bstrVal);\r\n    // memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);\r\n    if (prop.vt != VT_UI8)\r\n    {\r\n      continue; // old Interface\r\n      // return E_INVALIDARG;\r\n    }\r\n    info.Id = prop.uhVal.QuadPart;\r\n    prop.Clear();\r\n    \r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      info.Name = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_INVALIDARG;;\r\n    \r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kInStreams, info.NumInStreams));\r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kOutStreams, info.NumOutStreams));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned));\r\n    \r\n    externalCodecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  const UString &name,\r\n  CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (name.CompareNoCase(codec.Name) == 0)\r\n    {\r\n      methodId = codec.Id;\r\n      numInStreams = codec.NumInStreams;\r\n      numOutStreams = 1;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (codec.Name.CompareNoCase(name) == 0)\r\n      {\r\n        methodId = codec.Id;\r\n        numInStreams = codec.NumInStreams;\r\n        numOutStreams = codec.NumOutStreams;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  CMethodId methodId, UString &name)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (methodId == codec.Id)\r\n    {\r\n      name = codec.Name;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (methodId == codec.Id)\r\n      {\r\n        name = codec.Name;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder)\r\n{\r\n  bool created = false;\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (codec.Id == methodId)\r\n    {\r\n      if (encode)\r\n      {\r\n        if (codec.CreateEncoder)\r\n        {\r\n          void *p = codec.CreateEncoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n      }\r\n      else\r\n        if (codec.CreateDecoder)\r\n        {\r\n          void *p = codec.CreateDecoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  if (!created && externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (codec.Id == methodId)\r\n      {\r\n        if (encode)\r\n        {\r\n          if (codec.EncoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n        }\r\n        else\r\n          if (codec.DecoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n      }\r\n    }\r\n  #endif\r\n\r\n  if (onlyCoder && filter)\r\n  {\r\n    CFilterCoder *coderSpec = new CFilterCoder;\r\n    coder = coderSpec;\r\n    coderSpec->Filter = filter;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, true);\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    coder, coder2, encode);\r\n}\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressCoder> coder;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, false);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/CreateCoder.h",
    "content": "// CreateCoder.h\r\n\r\n#ifndef __CREATECODER_H\r\n#define __CREATECODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nstruct CCodecInfoEx\r\n{\r\n  UString Name;\r\n  CMethodId Id;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }\r\n  CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}\r\n};\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)\r\n#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);\r\n#define IMPL_ISetCompressCodecsInfo2(x) \\\r\nSTDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \\\r\n  COM_TRY_BEGIN _codecsInfo = compressCodecsInfo;  return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }\r\n#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)\r\n\r\n#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs\r\n#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,\r\n#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,\r\n\r\n#else\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo\r\n#define DECL_ISetCompressCodecsInfo\r\n#define IMPL_ISetCompressCodecsInfo\r\n#define EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_VARS\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2\r\n#define EXTERNAL_CODECS_LOC_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS\r\n#define EXTERNAL_CODECS_LOC_VARS\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, UString &name);\r\n\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode);\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/FilePathAutoRename.cpp",
    "content": "// FilePathAutoRename.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"FilePathAutoRename.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic bool MakeAutoName(const UString &name,\r\n    const UString &extension, int value, UString &path)\r\n{\r\n  wchar_t number[32];\r\n  ConvertUInt64ToString(value, number);\r\n  path = name;\r\n  path += number;\r\n  path += extension;\r\n  return NFile::NFind::DoesFileExist(path);\r\n}\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath)\r\n{\r\n  UString path;\r\n  int dotPos = fullProcessedPath.ReverseFind(L'.');\r\n\r\n  int slashPos = fullProcessedPath.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = fullProcessedPath.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n\r\n  UString name, extension;\r\n  if (dotPos > slashPos &&  dotPos > 0)\r\n  {\r\n    name = fullProcessedPath.Left(dotPos);\r\n    extension = fullProcessedPath.Mid(dotPos);\r\n  }\r\n  else\r\n    name = fullProcessedPath;\r\n  name += L'_';\r\n  int indexLeft = 1, indexRight = (1 << 30);\r\n  while (indexLeft != indexRight)\r\n  {\r\n    int indexMid = (indexLeft + indexRight) / 2;\r\n    if (MakeAutoName(name, extension, indexMid, path))\r\n      indexLeft = indexMid + 1;\r\n    else\r\n      indexRight = indexMid;\r\n  }\r\n  if (MakeAutoName(name, extension, indexRight, fullProcessedPath))\r\n    return false;\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/FilePathAutoRename.h",
    "content": "// Util/FilePathAutoRename.h\r\n\r\n#ifndef __FILEPATHAUTORENAME_H\r\n#define __FILEPATHAUTORENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  #ifdef _WIN32\r\n  if (result)\r\n    return S_OK;\r\n  DWORD lastError = ::GetLastError();\r\n  if (lastError == 0)\r\n    return E_FAIL;\r\n  return HRESULT_FROM_WIN32(lastError);\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nbool CInFileStream::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE),\r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do\r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  }\r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nHRESULT COutFileStream::Close()\r\n{\r\n  return ConvertBoolToHRESULT(File.Close());\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  ProcessedSize += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  ProcessedSize += res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15);\r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),\r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do\r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  }\r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WIN_FILE\r\n#endif\r\n\r\n#ifdef USE_WIN_FILE\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream:\r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\npublic:\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #endif\r\n  #endif\r\n\r\n  HRESULT Close();\r\n  \r\n  UInt64 ProcessedSize;\r\n\r\n  #ifdef USE_WIN_FILE\r\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n  {\r\n    return File.SetTime(cTime, aTime, mTime);\r\n  }\r\n  bool SetMTime(const FILETIME *mTime) {  return File.SetMTime(mTime); }\r\n  #endif\r\n\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/FilterCoder.cpp",
    "content": "// FilterCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FilterCoder.h\"\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#include \"../../Common/Defs.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCFilterCoder::CFilterCoder()\r\n{\r\n  _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n}\r\n\r\nCFilterCoder::~CFilterCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)\r\n{\r\n  if (_outSizeIsDefined)\r\n  {\r\n    UInt64 remSize = _outSize - _nowPos64;\r\n    if (size > remSize)\r\n      size = (UInt32)remSize;\r\n  }\r\n  RINOK(WriteStream(outStream, _buffer, size));\r\n  _nowPos64 += size;\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  RINOK(Init());\r\n  UInt32 bufferPos = 0;\r\n  _outSizeIsDefined = (outSize != 0);\r\n  if (_outSizeIsDefined)\r\n    _outSize = *outSize;\r\n\r\n  while(NeedMore())\r\n  {\r\n    size_t processedSize = kBufferSize - bufferPos;\r\n    \r\n    // Change it: It can be optimized using ReadPart\r\n    RINOK(ReadStream(inStream, _buffer + bufferPos, &processedSize));\r\n    \r\n    UInt32 endPos = bufferPos + (UInt32)processedSize;\r\n\r\n    bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (bufferPos > endPos)\r\n    {\r\n      for (; endPos< bufferPos; endPos++)\r\n        _buffer[endPos] = 0;\r\n      bufferPos = Filter->Filter(_buffer, endPos);\r\n    }\r\n\r\n    if (bufferPos == 0)\r\n    {\r\n      if (endPos > 0)\r\n        return WriteWithLimit(outStream, endPos);\r\n      return S_OK;\r\n    }\r\n    RINOK(WriteWithLimit(outStream, bufferPos));\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));\r\n    }\r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n// #ifdef _ST_MODE\r\nSTDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _bufferPos = 0;\r\n  _outStream = outStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseOutStream()\r\n{\r\n  _outStream.Release();\r\n  return S_OK;\r\n};\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    UInt32 sizeMax = kBufferSize - _bufferPos;\r\n    UInt32 sizeTemp = size;\r\n    if (sizeTemp > sizeMax)\r\n      sizeTemp = sizeMax;\r\n    memmove(_buffer + _bufferPos, data, sizeTemp);\r\n    size -= sizeTemp;\r\n    processedSizeTotal += sizeTemp;\r\n    data = (const Byte *)data + sizeTemp;\r\n    UInt32 endPos = _bufferPos + sizeTemp;\r\n    _bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (_bufferPos == 0)\r\n    {\r\n      _bufferPos = endPos;\r\n      break;\r\n    }\r\n    if (_bufferPos > endPos)\r\n    {\r\n      if (size != 0)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    RINOK(WriteWithLimit(_outStream, _bufferPos));\r\n    UInt32 i = 0;\r\n    while(_bufferPos < endPos)\r\n      _buffer[i++] = _buffer[_bufferPos++];\r\n    _bufferPos = i;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::Flush()\r\n{\r\n  if (_bufferPos != 0)\r\n  {\r\n    UInt32 endPos = Filter->Filter(_buffer, _bufferPos);\r\n    if (endPos > _bufferPos)\r\n    {\r\n      for (; _bufferPos < endPos; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      if (Filter->Filter(_buffer, endPos) != endPos)\r\n        return E_FAIL;\r\n    }\r\n    RINOK(WriteStream(_outStream, _buffer, _bufferPos));\r\n    _bufferPos = 0;\r\n  }\r\n  CMyComPtr<IOutStreamFlush> flush;\r\n  _outStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n  if (flush)\r\n    return  flush->Flush();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _convertedPosBegin = _convertedPosEnd = _bufferPos = 0;\r\n  _inStream = inStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseInStream()\r\n{\r\n  _inStream.Release();\r\n  return S_OK;\r\n};\r\n\r\nSTDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_convertedPosBegin != _convertedPosEnd)\r\n    {\r\n      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);\r\n      memmove(data, _buffer + _convertedPosBegin, sizeTemp);\r\n      _convertedPosBegin += sizeTemp;\r\n      data = (void *)((Byte *)data + sizeTemp);\r\n      size -= sizeTemp;\r\n      processedSizeTotal += sizeTemp;\r\n      break;\r\n    }\r\n    int i;\r\n    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)\r\n      _buffer[i] = _buffer[i + _convertedPosEnd];\r\n    _bufferPos = i;\r\n    _convertedPosBegin = _convertedPosEnd = 0;\r\n    size_t processedSizeTemp = kBufferSize - _bufferPos;\r\n    RINOK(ReadStream(_inStream, _buffer + _bufferPos, &processedSizeTemp));\r\n    _bufferPos = _bufferPos + (UInt32)processedSizeTemp;\r\n    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    if (_convertedPosEnd == 0)\r\n    {\r\n      if (_bufferPos == 0)\r\n        break;\r\n      else\r\n      {\r\n        _convertedPosEnd = _bufferPos; // check it\r\n        continue;\r\n      }\r\n    }\r\n    if (_convertedPosEnd > _bufferPos)\r\n    {\r\n      for (; _bufferPos < _convertedPosEnd; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\n// #endif // _ST_MODE\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)\r\n{\r\n  return _setPassword->CryptoSetPassword(data, size);\r\n}\r\n#endif\r\n\r\n#ifndef EXTRACT_ONLY\r\nSTDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  return _writeCoderProperties->WriteCoderProperties(outStream);\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CFilterCoder::ResetSalt()\r\n{\r\n  return _CryptoResetSalt->ResetSalt();\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CFilterCoder::ResetInitVector()\r\n{\r\n  return _CryptoResetInitVector->ResetInitVector();\r\n}\r\n#endif\r\n\r\nSTDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)\r\n{\r\n  return _setDecoderProperties->SetDecoderProperties2(data, size);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/FilterCoder.h",
    "content": "// FilterCoder.h\r\n\r\n#ifndef __FILTERCODER_H\r\n#define __FILTERCODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \\\r\n{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \\\r\n*outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\nclass CFilterCoder:\r\n  public ICompressCoder,\r\n  // #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ISequentialInStream,\r\n  public ICompressSetOutStream,\r\n  public ISequentialOutStream,\r\n  public IOutStreamFlush,\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoSetPassword,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  // public ICryptoResetSalt,\r\n  public ICryptoResetInitVector,\r\n  #endif\r\n  public ICompressSetDecoderProperties2,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  // #ifdef _ST_MODE\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  CMyComPtr<ISequentialOutStream> _outStream;\r\n  UInt32 _bufferPos;\r\n  UInt32 _convertedPosBegin;\r\n  UInt32 _convertedPosEnd;\r\n  // #endif\r\n  bool _outSizeIsDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _nowPos64;\r\n\r\n  HRESULT Init()\r\n  {\r\n    _nowPos64 = 0;\r\n    _outSizeIsDefined = false;\r\n    return Filter->Init();\r\n  }\r\n\r\n  CMyComPtr<ICryptoSetPassword> _setPassword;\r\n  #ifndef EXTRACT_ONLY\r\n  CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;\r\n  CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;\r\n  // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;\r\n  CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;\r\n  #endif\r\n  CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;\r\npublic:\r\n  CMyComPtr<ICompressFilter> Filter;\r\n\r\n  CFilterCoder();\r\n  ~CFilterCoder();\r\n  HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);\r\n  bool NeedMore() const\r\n    { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }\r\n\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n    MY_QUERYINTERFACE_ENTRY(ICompressCoder)\r\n    // #ifdef _ST_MODE\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialInStream)\r\n\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)\r\n    // #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)\r\n    #endif\r\n\r\n    #ifndef EXTRACT_ONLY\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)\r\n    // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)\r\n    #endif\r\n\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  // #ifdef _ST_MODE\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \\\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Flush)();\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  // STDMETHOD(ResetSalt)();\r\n  STDMETHOD(ResetInitVector)();\r\n  #endif\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n};\r\n\r\n// #ifdef _ST_MODE\r\nclass CInStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  CInStreamReleaser(): FilterCoder(0) {}\r\n  ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }\r\n};\r\n\r\nclass COutStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  COutStreamReleaser(): FilterCoder(0) {}\r\n  ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }\r\n};\r\n// #endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nCInBuffer::CInBuffer():\r\n  _buffer(0),\r\n  _bufferLimit(0),\r\n  _bufferBase(0),\r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct CInBufferException: public CSystemException\r\n{\r\n  CInBufferException(HRESULT errorCode): CSystemException(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if (_buffer >= _bufferLimit)\r\n      if (!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if (_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  UInt32 ReadBytes(Byte *buf, UInt32 size)\r\n  {\r\n    if ((UInt32)(_bufferLimit - _buffer) >= size)\r\n    {\r\n      for (UInt32 i = 0; i < size; i++)\r\n        buf[i] = _buffer[i];\r\n      _buffer += size;\r\n      return size;\r\n    }\r\n    for (UInt32 i = 0; i < size; i++)\r\n    {\r\n      if (_buffer >= _bufferLimit)\r\n        if (!ReadBlock())\r\n          return i;\r\n      buf[i] = *_buffer++;\r\n    }\r\n    return size;\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/InOutTempBuffer.cpp",
    "content": "// InOutTempBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InOutTempBuffer.h\"\r\n#include \"../../Common/Defs.h\"\r\n// #include \"Windows/Defs.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic UInt32 kTmpBufferMemorySize = (1 << 20);\r\n\r\nstatic LPCTSTR kTempFilePrefixString = TEXT(\"iot\");\r\n\r\nCInOutTempBuffer::CInOutTempBuffer():\r\n  _buffer(NULL)\r\n{\r\n}\r\n\r\nvoid CInOutTempBuffer::Create()\r\n{\r\n  _buffer = new Byte[kTmpBufferMemorySize];\r\n}\r\n\r\nCInOutTempBuffer::~CInOutTempBuffer()\r\n{\r\n  delete []_buffer;\r\n}\r\nvoid CInOutTempBuffer::InitWriting()\r\n{\r\n  _bufferPosition = 0;\r\n  _tmpFileCreated = false;\r\n  _fileSize = 0;\r\n}\r\n\r\nbool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)\r\n{\r\n  if (size == 0)\r\n    return true;\r\n  if(!_tmpFileCreated)\r\n  {\r\n    CSysString tempDirPath;\r\n    if(!MyGetTempPath(tempDirPath))\r\n      return false;\r\n    if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)\r\n      return false;\r\n    // _outFile.SetOpenCreationDispositionCreateAlways();\r\n    if(!_outFile.Create(_tmpFileName, true))\r\n      return false;\r\n    _tmpFileCreated = true;\r\n  }\r\n  UInt32 processedSize;\r\n  if(!_outFile.Write(data, size, processedSize))\r\n    return false;\r\n  _fileSize += processedSize;\r\n  return (processedSize == size);\r\n}\r\n\r\nbool CInOutTempBuffer::FlushWrite()\r\n{\r\n  return _outFile.Close();\r\n}\r\n\r\nbool CInOutTempBuffer::Write(const void *data, UInt32 size)\r\n{\r\n  if(_bufferPosition < kTmpBufferMemorySize)\r\n  {\r\n    UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);\r\n    memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);\r\n    _bufferPosition += curSize;\r\n    size -= curSize;\r\n    data = ((const Byte *)data) + curSize;\r\n    _fileSize += curSize;\r\n  }\r\n  return WriteToFile(data, size);\r\n}\r\n\r\nbool CInOutTempBuffer::InitReading()\r\n{\r\n  _currentPositionInBuffer = 0;\r\n  if(_tmpFileCreated)\r\n    return _inFile.Open(_tmpFileName);\r\n  return true;\r\n}\r\n\r\nHRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)\r\n{\r\n  if (_currentPositionInBuffer < _bufferPosition)\r\n  {\r\n    UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;\r\n    RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite));\r\n    _currentPositionInBuffer += sizeToWrite;\r\n  }\r\n  if (!_tmpFileCreated)\r\n    return true;\r\n  for (;;)\r\n  {\r\n    UInt32 localProcessedSize;\r\n    if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))\r\n      return E_FAIL;\r\n    if (localProcessedSize == 0)\r\n      return S_OK;\r\n    RINOK(WriteStream(stream, _buffer, localProcessedSize));\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (!_buffer->Write(data, size))\r\n  {\r\n    if (processedSize != NULL)\r\n      *processedSize = 0;\r\n    return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/InOutTempBuffer.h",
    "content": "// Util/InOutTempBuffer.h\r\n\r\n#ifndef __IN_OUT_TEMP_BUFFER_H\r\n#define __IN_OUT_TEMP_BUFFER_H\r\n\r\n#include \"../../Windows/FileIO.h\"\r\n#include \"../../Windows/FileDir.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../IStream.h\"\r\n\r\nclass CInOutTempBuffer\r\n{\r\n  NWindows::NFile::NDirectory::CTempFile _tempFile;\r\n  NWindows::NFile::NIO::COutFile _outFile;\r\n  NWindows::NFile::NIO::CInFile _inFile;\r\n  Byte *_buffer;\r\n  UInt32 _bufferPosition;\r\n  UInt32 _currentPositionInBuffer;\r\n  CSysString _tmpFileName;\r\n  bool _tmpFileCreated;\r\n\r\n  UInt64 _fileSize;\r\n\r\n  bool WriteToFile(const void *data, UInt32 size);\r\npublic:\r\n  CInOutTempBuffer();\r\n  ~CInOutTempBuffer();\r\n  void Create();\r\n\r\n  void InitWriting();\r\n  bool Write(const void *data, UInt32 size);\r\n  UInt64 GetDataSize() const { return _fileSize; }\r\n  bool FlushWrite();\r\n  bool InitReading();\r\n  HRESULT WriteToStream(ISequentialOutStream *stream);\r\n};\r\n\r\nclass CSequentialOutTempBufferImp:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CInOutTempBuffer *_buffer;\r\npublic:\r\n  // CSequentialOutStreamImp(): _size(0) {}\r\n  // UInt32 _size;\r\n  void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }\r\n  // UInt32 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/LimitedStreams.cpp",
    "content": "// LimitedStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LimitedStreams.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\nSTDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size);\r\n  HRESULT result = S_OK;\r\n  if (sizeToRead > 0)\r\n  {\r\n    result = _stream->Read(data, sizeToRead, &realProcessedSize);\r\n    _pos += realProcessedSize;\r\n    if (realProcessedSize == 0)\r\n      _wasFinished = true;\r\n  }\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  HRESULT result = S_OK;\r\n  if (processedSize != NULL)\r\n    *processedSize = 0;\r\n  if (size > _size)\r\n  {\r\n    size = (UInt32)_size;\r\n    if (size == 0)\r\n    {\r\n      _overflow = true;\r\n      return E_FAIL;\r\n    }\r\n  }\r\n  if (_stream)\r\n    result = _stream->Write(data, size, &size);\r\n  _size -= size;\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/LimitedStreams.h",
    "content": "// LimitedStreams.h\r\n\r\n#ifndef __LIMITEDSTREAMS_H\r\n#define __LIMITEDSTREAMS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLimitedSequentialInStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt64 _pos;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream; }\r\n  void Init(UInt64 streamSize)\r\n  {\r\n    _size = streamSize;\r\n    _pos = 0;\r\n    _wasFinished = false;\r\n  }\r\n \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _pos; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CLimitedSequentialOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  bool _overflow;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(UInt64 size)\r\n  {\r\n    _size = size;\r\n    _overflow = false;\r\n  }\r\n  bool IsFinishedOK() const { return (_size == 0 && !_overflow); }\r\n  UInt64 GetRem() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/LockedStream.cpp",
    "content": "// LockedStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LockedStream.h\"\r\n\r\nHRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size,\r\n  UInt32 *processedSize)\r\n{\r\n  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);\r\n  RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));\r\n  return _stream->Read(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);\r\n  _pos += realProcessedSize;\r\n  if (processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/LockedStream.h",
    "content": "// LockedStream.h\r\n\r\n#ifndef __LOCKEDSTREAM_H\r\n#define __LOCKEDSTREAM_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLockedInStream\r\n{\r\n  CMyComPtr<IInStream> _stream;\r\n  NWindows::NSynchronization::CCriticalSection _criticalSection;\r\npublic:\r\n  void Init(IInStream *stream)\r\n    { _stream = stream; }\r\n  HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CLockedSequentialInStreamImp:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CLockedInStream *_lockedInStream;\r\n  UInt64 _pos;\r\npublic:\r\n  void Init(CLockedInStream *lockedInStream, UInt64 startPos)\r\n  {\r\n    _lockedInStream = lockedInStream;\r\n    _pos = startPos;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/MethodId.cpp",
    "content": "// MethodId.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodId.h\"\r\n#include \"../../Common/MyString.h\"\r\n\r\nstatic inline wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nUString ConvertMethodIdToString(UInt64 id)\r\n{\r\n  wchar_t s[32];\r\n  int len = 32;\r\n  s[--len] = 0;\r\n  do\r\n  {\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n  }\r\n  while (id != 0);\r\n  return s + len;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/MethodId.h",
    "content": "// MethodId.h\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Common/Types.h\"\r\n\r\ntypedef UInt64 CMethodId;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/MethodProps.cpp",
    "content": "// MethodProps.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodProps.h\"\r\n\r\nstatic UInt64 k_LZMA = 0x030101;\r\n// static UInt64 k_LZMA2 = 0x030102;\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)\r\n{\r\n  bool tryReduce = false;\r\n  UInt32 reducedDictionarySize = 1 << 10;\r\n  if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))\r\n  {\r\n    for (;;)\r\n    {\r\n      const UInt32 step = (reducedDictionarySize >> 1);\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      reducedDictionarySize += step;\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      if (reducedDictionarySize >= ((UInt32)3 << 30))\r\n        break;\r\n      reducedDictionarySize += step;\r\n    }\r\n  }\r\n\r\n  {\r\n    int numProps = method.Props.Size();\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n    if (setCoderProperties == NULL)\r\n    {\r\n      if (numProps != 0)\r\n        return E_INVALIDARG;\r\n    }\r\n    else\r\n    {\r\n      CRecordVector<PROPID> propIDs;\r\n      NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps];\r\n      HRESULT res = S_OK;\r\n      try\r\n      {\r\n        for (int i = 0; i < numProps; i++)\r\n        {\r\n          const CProp &prop = method.Props[i];\r\n          propIDs.Add(prop.Id);\r\n          NWindows::NCOM::CPropVariant &value = values[i];\r\n          value = prop.Value;\r\n          // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)\r\n          if (tryReduce)\r\n            if (prop.Id == NCoderPropID::kDictionarySize)\r\n              if (value.vt == VT_UI4)\r\n                if (reducedDictionarySize < value.ulVal)\r\n            value.ulVal = reducedDictionarySize;\r\n        }\r\n        CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n        coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n        res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps);\r\n      }\r\n      catch(...)\r\n      {\r\n        delete []values;\r\n        throw;\r\n      }\r\n      delete []values;\r\n      RINOK(res);\r\n    }\r\n  }\r\n \r\n  /*\r\n  CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n  coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n  if (writeCoderProperties != NULL)\r\n  {\r\n    CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n    outStreamSpec->Init();\r\n    RINOK(writeCoderProperties->WriteCoderProperties(outStream));\r\n    size_t size = outStreamSpec->GetSize();\r\n    filterProps.SetCapacity(size);\r\n    memmove(filterProps, outStreamSpec->GetBuffer(), size);\r\n  }\r\n  */\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/MethodProps.h",
    "content": "// MethodProps.h\r\n\r\n#ifndef __7Z_METHOD_PROPS_H\r\n#define __7Z_METHOD_PROPS_H\r\n\r\n#include \"../../Common/MyVector.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\nstruct CProp\r\n{\r\n  PROPID Id;\r\n  NWindows::NCOM::CPropVariant Value;\r\n};\r\n\r\nstruct CMethod\r\n{\r\n  CMethodId Id;\r\n  CObjectVector<CProp> Props;\r\n};\r\n\r\nstruct CMethodsMode\r\n{\r\n  CObjectVector<CMethod> Methods;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n\r\n  CMethodsMode()\r\n      #ifdef COMPRESS_MT\r\n      : NumThreads(1)\r\n      #endif\r\n  {}\r\n  bool IsEmpty() const { return Methods.IsEmpty() ; }\r\n};\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/OffsetStream.cpp",
    "content": "// OffsetStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"OffsetStream.h\"\r\n\r\nHRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)\r\n{\r\n  _offset = offset;\r\n  _stream = stream;\r\n  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return _stream->Write(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 absoluteNewPosition;\r\n  if (seekOrigin == STREAM_SEEK_SET)\r\n    offset += _offset;\r\n  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);\r\n  if (newPosition != NULL)\r\n    *newPosition = absoluteNewPosition - _offset;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)\r\n{\r\n  return _stream->SetSize(_offset + newSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/OffsetStream.h",
    "content": "// OffsetStream.h\r\n\r\n#ifndef __OFFSETSTREAM_H\r\n#define __OFFSETSTREAM_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass COffsetOutStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 _offset;\r\n  CMyComPtr<IOutStream> _stream;\r\npublic:\r\n  HRESULT Init(IOutStream *stream, UInt64 offset);\r\n  \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{\r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos)\r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode == S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = Flush();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException: public CSystemException\r\n{\r\n  COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void FlushWithCheck();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/ProgressUtils.cpp",
    "content": "// ProgressUtils.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ProgressUtils.h\"\r\n\r\nCLocalProgress::CLocalProgress()\r\n{\r\n  ProgressOffset = InSize = OutSize = 0;\r\n  SendRatio = SendProgress = true;\r\n}\r\n\r\nvoid CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)\r\n{\r\n  _ratioProgress.Release();\r\n  _progress = progress;\r\n  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);\r\n  _inSizeIsMain = inSizeIsMain;\r\n}\r\n\r\nSTDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  UInt64 inSizeNew = InSize, outSizeNew = OutSize;\r\n  if (inSize)\r\n    inSizeNew += (*inSize);\r\n  if (outSize)\r\n    outSizeNew += (*outSize);\r\n  if (SendRatio && _ratioProgress)\r\n  {\r\n    RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));\r\n  }\r\n  inSizeNew += ProgressOffset;\r\n  outSizeNew += ProgressOffset;\r\n  if (SendProgress)\r\n    return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CLocalProgress::SetCur()\r\n{\r\n  return SetRatioInfo(NULL, NULL);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/ProgressUtils.h",
    "content": "// ProgressUtils.h\r\n\r\n#ifndef __PROGRESSUTILS_H\r\n#define __PROGRESSUTILS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n#include \"../IProgress.h\"\r\n\r\nclass CLocalProgress:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<IProgress> _progress;\r\n  CMyComPtr<ICompressProgressInfo> _ratioProgress;\r\n  bool _inSizeIsMain;\r\npublic:\r\n  UInt64 ProgressOffset;\r\n  UInt64 InSize;\r\n  UInt64 OutSize;\r\n  bool SendRatio;\r\n  bool SendProgress;\r\n\r\n  CLocalProgress();\r\n  void Init(IProgress *progress, bool inSizeIsMain);\r\n  HRESULT SetCur();\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/RegisterArc.h",
    "content": "// RegisterArc.h\r\n\r\n#ifndef __REGISTERARC_H\r\n#define __REGISTERARC_H\r\n\r\n#include \"../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcInfo\r\n{\r\n  const wchar_t *Name;\r\n  const wchar_t *Ext;\r\n  const wchar_t *AddExt;\r\n  Byte ClassId;\r\n  Byte Signature[16];\r\n  int SignatureSize;\r\n  bool KeepName;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n};\r\n\r\nvoid RegisterArc(const CArcInfo *arcInfo);\r\n\r\n#define REGISTER_ARC_NAME(x) CRegister ## x\r\n\r\n#define REGISTER_ARC_DEC_SIG(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { g_ArcInfo.Signature[0]--; RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#define REGISTER_ARC(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/RegisterCodec.h",
    "content": "// RegisterCodec.h\r\n\r\n#ifndef __REGISTERCODEC_H\r\n#define __REGISTERCODEC_H\r\n\r\n#include \"../Common/MethodId.h\"\r\n\r\ntypedef void * (*CreateCodecP)();\r\nstruct CCodecInfo\r\n{\r\n  CreateCodecP CreateDecoder;\r\n  CreateCodecP CreateEncoder;\r\n  CMethodId Id;\r\n  const wchar_t *Name;\r\n  UInt32 NumInStreams;\r\n  bool IsFilter;\r\n};\r\n\r\nvoid RegisterCodec(const CCodecInfo *codecInfo);\r\n\r\n#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x\r\n\r\n#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \\\r\n    REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \\\r\n    static REGISTER_CODEC_NAME(x) g_RegisterCodec;\r\n\r\n#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x\r\n#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \\\r\n    REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \\\r\n    RegisterCodec(&g_CodecsInfo[i]); }}; \\\r\n    static REGISTER_CODECS_NAME(x) g_RegisterCodecs;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/StreamBinder.cpp",
    "content": "// StreamBinder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamBinder.h\"\r\n#include \"../../Common/Defs.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NSynchronization;\r\n\r\nclass CSequentialInStreamForBinder:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Read(data, size, processedSize); }\r\n\r\nclass CSequentialOutStreamForBinder:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialOutStreamForBinder() {  m_StreamBinder->CloseWrite(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Write(data, size, processedSize); }\r\n\r\n\r\n//////////////////////////\r\n// CStreamBinder\r\n// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.\r\n\r\nHRes CStreamBinder::CreateEvents()\r\n{\r\n  RINOK(_allBytesAreWritenEvent.Create(true));\r\n  RINOK(_thereAreBytesToReadEvent.Create());\r\n  return _readStreamIsClosedEvent.Create();\r\n}\r\n\r\nvoid CStreamBinder::ReInit()\r\n{\r\n  _thereAreBytesToReadEvent.Reset();\r\n  _readStreamIsClosedEvent.Reset();\r\n  ProcessedSize = 0;\r\n}\r\n\r\n\r\n  \r\nvoid CStreamBinder::CreateStreams(ISequentialInStream **inStream,\r\n      ISequentialOutStream **outStream)\r\n{\r\n  CSequentialInStreamForBinder *inStreamSpec = new\r\n      CSequentialInStreamForBinder;\r\n  CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n  inStreamSpec->SetBinder(this);\r\n  *inStream = inStreamLoc.Detach();\r\n\r\n  CSequentialOutStreamForBinder *outStreamSpec = new\r\n      CSequentialOutStreamForBinder;\r\n  CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);\r\n  outStreamSpec->SetBinder(this);\r\n  *outStream = outStreamLoc.Detach();\r\n\r\n  _buffer = NULL;\r\n  _bufferSize= 0;\r\n  ProcessedSize = 0;\r\n}\r\n\r\nHRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 sizeToRead = size;\r\n  if (size > 0)\r\n  {\r\n    RINOK(_thereAreBytesToReadEvent.Lock());\r\n    sizeToRead = MyMin(_bufferSize, size);\r\n    if (_bufferSize > 0)\r\n    {\r\n      memcpy(data, _buffer, sizeToRead);\r\n      _buffer = ((const Byte *)_buffer) + sizeToRead;\r\n      _bufferSize -= sizeToRead;\r\n      if (_bufferSize == 0)\r\n      {\r\n        _thereAreBytesToReadEvent.Reset();\r\n        _allBytesAreWritenEvent.Set();\r\n      }\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = sizeToRead;\r\n  ProcessedSize += sizeToRead;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseRead()\r\n{\r\n  _readStreamIsClosedEvent.Set();\r\n}\r\n\r\nHRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > 0)\r\n  {\r\n    _buffer = data;\r\n    _bufferSize = size;\r\n    _allBytesAreWritenEvent.Reset();\r\n    _thereAreBytesToReadEvent.Set();\r\n\r\n    HANDLE events[2];\r\n    events[0] = _allBytesAreWritenEvent;\r\n    events[1] = _readStreamIsClosedEvent;\r\n    DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);\r\n    if (waitResult != WAIT_OBJECT_0 + 0)\r\n    {\r\n      // ReadingWasClosed = true;\r\n      return S_FALSE;\r\n    }\r\n    // if(!_allBytesAreWritenEvent.Lock())\r\n    //   return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseWrite()\r\n{\r\n  // _bufferSize must be = 0\r\n  _thereAreBytesToReadEvent.Set();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/StreamBinder.h",
    "content": "// StreamBinder.h\r\n\r\n#ifndef __STREAMBINDER_H\r\n#define __STREAMBINDER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Windows/Synchronization.h\"\r\n\r\nclass CStreamBinder\r\n{\r\n  NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent;\r\n  UInt32 _bufferSize;\r\n  const void *_buffer;\r\npublic:\r\n  // bool ReadingWasClosed;\r\n  UInt64 ProcessedSize;\r\n  CStreamBinder() {}\r\n  HRes CreateEvents();\r\n\r\n  void CreateStreams(ISequentialInStream **inStream,\r\n      ISequentialOutStream **outStream);\r\n  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseRead();\r\n\r\n  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseWrite();\r\n  void ReInit();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/StreamObjects.cpp",
    "content": "// StreamObjects.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamObjects.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\n\r\nSTDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t rem = _size - _pos;\r\n  if (size < rem)\r\n    rem = (size_t)size;\r\n  memcpy(data, _dataPointer + _pos, rem);\r\n  _pos += rem;\r\n  if (processedSize != NULL)\r\n    *processedSize = (UInt32)rem;\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CWriteBuffer::Write(const void *data, size_t size)\r\n{\r\n  size_t newCapacity = _size + size;\r\n  _buffer.EnsureCapacity(newCapacity);\r\n  memcpy(_buffer + _size, data, size);\r\n  _size += size;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  _writeBuffer.Write(data, (size_t)size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t rem = _size - _pos;\r\n  if (size < rem)\r\n    rem = (size_t)size;\r\n  memcpy(_buffer + _pos, data, rem);\r\n  _pos += rem;\r\n  if (processedSize != NULL)\r\n    *processedSize = (UInt32)rem;\r\n  return (rem == size ? S_OK : E_FAIL);\r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/StreamObjects.h",
    "content": "// StreamObjects.h\r\n\r\n#ifndef __STREAMOBJECTS_H\r\n#define __STREAMOBJECTS_H\r\n\r\n#include \"../../Common/DynamicBuffer.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CSequentialInStreamImp:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *_dataPointer;\r\n  size_t _size;\r\n  size_t _pos;\r\n\r\npublic:\r\n  void Init(const Byte *dataPointer, size_t size)\r\n  {\r\n    _dataPointer = dataPointer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n\r\nclass CWriteBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _size;\r\npublic:\r\n  CWriteBuffer(): _size(0) {}\r\n  void Init() { _size = 0;  }\r\n  void Write(const void *data, size_t size);\r\n  size_t GetSize() const { return _size; }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _buffer; }\r\n};\r\n\r\nclass CSequentialOutStreamImp:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CWriteBuffer _writeBuffer;\r\npublic:\r\n  void Init() { _writeBuffer.Init(); }\r\n  size_t GetSize() const { return _writeBuffer.GetSize(); }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamImp2:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n\r\n  void Init(Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _pos = 0;\r\n    _size = size;\r\n  }\r\n\r\n  size_t GetPos() const { return _pos; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialInStreamSizeCount:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamSizeCount:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void Init() { _size = 0; }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBlockSize = ((UInt32)1 << 31);\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSize)\r\n{\r\n  size_t size = *processedSize;\r\n  *processedSize = 0;\r\n  while (size != 0)\r\n  {\r\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\r\n    UInt32 processedSizeLoc;\r\n    HRESULT res = stream->Read(data, curSize, &processedSizeLoc);\r\n    *processedSize += processedSizeLoc;\r\n    data = (void *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size)\r\n{\r\n  size_t processedSize = size;\r\n  RINOK(ReadStream(stream, data, &processedSize));\r\n  return (size == processedSize) ? S_OK : S_FALSE;\r\n}\r\n\r\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size)\r\n{\r\n  size_t processedSize = size;\r\n  RINOK(ReadStream(stream, data, &processedSize));\r\n  return (size == processedSize) ? S_OK : E_FAIL;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size != 0)\r\n  {\r\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\r\n    UInt32 processedSizeLoc;\r\n    HRESULT res = stream->Write(data, curSize, &processedSizeLoc);\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *size);\r\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size);\r\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/VirtThread.cpp",
    "content": "// VirtThread.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"VirtThread.h\"\r\n\r\nstatic THREAD_FUNC_DECL CoderThread(void *p)\r\n{\r\n  for (;;)\r\n  {\r\n    CVirtThread *t = (CVirtThread *)p;\r\n    t->StartEvent.Lock();\r\n    if (t->ExitEvent)\r\n      return 0;\r\n    t->Execute();\r\n    t->FinishedEvent.Set();\r\n  }\r\n}\r\n\r\nWRes CVirtThread::Create()\r\n{\r\n  RINOK(StartEvent.CreateIfNotCreated());\r\n  RINOK(FinishedEvent.CreateIfNotCreated());\r\n  StartEvent.Reset();\r\n  FinishedEvent.Reset();\r\n  ExitEvent = false;\r\n  if (Thread.IsCreated())\r\n    return S_OK;\r\n  return Thread.Create(CoderThread, this);\r\n}\r\n\r\nvoid CVirtThread::Start()\r\n{\r\n  ExitEvent = false;\r\n  StartEvent.Set();\r\n}\r\n\r\nCVirtThread::~CVirtThread()\r\n{\r\n  ExitEvent = true;\r\n  if (StartEvent.IsCreated())\r\n    StartEvent.Set();\r\n  Thread.Wait();\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Common/VirtThread.h",
    "content": "// VirtThread.h\r\n\r\n#ifndef __VIRTTHREAD_H\r\n#define __VIRTTHREAD_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Windows/Thread.h\"\r\n\r\nstruct CVirtThread\r\n{\r\n  NWindows::NSynchronization::CAutoResetEvent StartEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent FinishedEvent;\r\n  NWindows::CThread Thread;\r\n  bool ExitEvent;\r\n\r\n  ~CVirtThread();\r\n  WRes Create();\r\n  void Start();\r\n  void WaitFinish() { FinishedEvent.Lock(); }\r\n  virtual void Execute() = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/Bcj2Coder.cpp",
    "content": "// Bcj2Coder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"Bcj2Coder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\ninline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }\r\ninline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }\r\ninline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CEncoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CEncoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize = 0;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusEncoder[i].Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    for (;;)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it\r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        UInt32 index;\r\n        if (b == 0xE8)\r\n          index = prevByte;\r\n        else if (b == 0xE9)\r\n          index = 256;\r\n        else if (IsJcc(prevByte, b))\r\n          index = 257;\r\n        else\r\n        {\r\n          prevByte = b;\r\n          continue;\r\n        }\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (!IsJ(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src =\r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;\r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;\r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      unsigned index = GetIndex(prevByte, b);\r\n      if (convert)\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 1);\r\n        bufferPos += 5;\r\n        COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n        for (int i = 24; i >= 0; i -= 8)\r\n          s.WriteByte((Byte)(dest >> i));\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize =\r\n        _mainStream.GetProcessedSize() +\r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeEncoder.GetProcessedSize();\r\n      */\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusDecoder[i].Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  for (;;)\r\n  {\r\n    if (processedBytes >= (1 << 20) && progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize =\r\n        _mainInStream.GetProcessedSize() +\r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeDecoder.GetProcessedSize();\r\n      */\r\n      const UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    UInt32 i;\r\n    Byte b = 0;\r\n    const UInt32 kBurstSize = (1 << 18);\r\n    for (i = 0; i < kBurstSize; i++)\r\n    {\r\n      if (!_mainInStream.ReadByte(b))\r\n        return Flush();\r\n      _outStream.WriteByte(b);\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      prevByte = b;\r\n    }\r\n    processedBytes += i;\r\n    if (i == kBurstSize)\r\n      continue;\r\n    unsigned index = GetIndex(prevByte, b);\r\n    if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)\r\n    {\r\n      UInt32 src = 0;\r\n      CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n      for (int i = 0; i < 4; i++)\r\n      {\r\n        Byte b0;\r\n        if(!s.ReadByte(b0))\r\n          return S_FALSE;\r\n        src <<= 8;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (Byte)(dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const CInBufferException &e) { return e.ErrorCode; }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/Bcj2Coder.h",
    "content": "// Bcj2Coder.h\r\n\r\n#ifndef __COMPRESS_BCJ2_CODER_H\r\n#define __COMPRESS_BCJ2_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CEncoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CEncoder(): _buffer(0) {};\r\n  ~CEncoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n};\r\n\r\n#endif\r\n\r\nclass CDecoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CDecoder *_coder;\r\n  public:\r\n    CCoderReleaser(CDecoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/Bcj2Register.cpp",
    "content": "// Bcj2Register.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"Bcj2Coder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x0303011B, L\"BCJ2\", 4, false };\r\n\r\nREGISTER_CODEC(BCJ2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/BcjCoder.cpp",
    "content": "// BcjCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"BcjCoder.h\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/BcjCoder.h",
    "content": "// BcjCoder.h\r\n\r\n#ifndef __COMPRESS_BCJ_CODER_H\r\n#define __COMPRESS_BCJ_CODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Bra.h\"\r\n}\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  void x86Init() { x86_Convert_Init(_prevMask); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 ,\r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/BcjRegister.cpp",
    "content": "// BcjRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"BcjCoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x03030103, L\"BCJ\", 1, true };\r\n\r\nREGISTER_CODEC(BCJ)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __COMPRESS_BRANCH_CODER_H\r\n#define __COMPRESS_BRANCH_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/BranchMisc.cpp",
    "content": "// BranchMisc.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Bra.h\"\r\n}\r\n\r\n#include \"BranchMisc.h\"\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  {  return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); }\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/BranchMisc.h",
    "content": "// BranchMisc.h\r\n\r\n#ifndef __COMPRESS_BRANCH_MISC_H\r\n#define __COMPRESS_BRANCH_MISC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM,   0x05, 1)\r\nMyClassA(BC_ARMT,  0x07, 1)\r\nMyClassA(BC_PPC,   0x02, 5)\r\nMyClassA(BC_SPARC, 0x08, 5)\r\nMyClassA(BC_IA64,  0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/BranchRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"BranchMisc.h\"\r\n\r\n#define CREATE_CODEC(x) \\\r\n  static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \\\r\n  static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }\r\n\r\nCREATE_CODEC(BC_PPC)\r\nCREATE_CODEC(BC_IA64)\r\nCREATE_CODEC(BC_ARM)\r\nCREATE_CODEC(BC_ARMT)\r\nCREATE_CODEC(BC_SPARC)\r\n\r\n#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true  }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  METHOD_ITEM(BC_PPC,   0x02, 0x05, L\"PPC\"),\r\n  METHOD_ITEM(BC_IA64,  0x04, 1, L\"IA64\"),\r\n  METHOD_ITEM(BC_ARM,   0x05, 1, L\"ARM\"),\r\n  METHOD_ITEM(BC_ARMT,  0x07, 1, L\"ARMT\"),\r\n  METHOD_ITEM(BC_SPARC, 0x08, 0x05, L\"SPARC\")\r\n};\r\n\r\nREGISTER_CODECS(Branch)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/ByteSwap.cpp",
    "content": "// ByteSwap.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nSTDMETHODIMP CByteSwap2::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 2;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b = data[i];\r\n    data[i] = data[i + 1];\r\n    data[i + 1] = b;\r\n  }\r\n  return i;\r\n}\r\n\r\nSTDMETHODIMP CByteSwap4::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 4;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b0 = data[i];\r\n    Byte b1 = data[i + 1];\r\n    data[i] = data[i + 3];\r\n    data[i + 1] = data[i + 2];\r\n    data[i + 2] = b1;\r\n    data[i + 3] = b0;\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/ByteSwap.h",
    "content": "// ByteSwap.h\r\n\r\n#ifndef __COMPRESS_BYTE_SWAP_H\r\n#define __COMPRESS_BYTE_SWAP_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nclass CByteSwap2:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\nclass CByteSwap4:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/ByteSwapRegister.cpp",
    "content": "// ByteSwapRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nstatic void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }\r\nstatic void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  { CreateCodec2, CreateCodec4, 0x020302, L\"Swap2\", 1, true },\r\n  { CreateCodec4, CreateCodec4, 0x020304, L\"Swap4\", 1, true }\r\n};\r\n\r\nREGISTER_CODECS(ByteSwap)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/CodecExports.cpp",
    "content": "// CodecExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterCodec.h\"\r\n#include \"../ICoder.h\"\r\n\r\nextern unsigned int g_NumCodecs;\r\nextern const CCodecInfo *g_Codecs[];\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec,\r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nstatic HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)\r\n{\r\n  GUID clsId = CLSID_CCodec;\r\n  for (int i = 0; i < sizeof(id); i++, id >>= 8)\r\n    clsId.Data4[i] = (Byte)(id & 0xFF);\r\n  if (encode)\r\n    clsId.Data3++;\r\n  return SetPropGUID(clsId, value);\r\n}\r\n\r\nstatic HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)\r\n{\r\n  index = -1;\r\n  if (clsID->Data1 != CLSID_CCodec.Data1 ||\r\n      clsID->Data2 != CLSID_CCodec.Data2 ||\r\n      (clsID->Data3 & ~1) != kDecodeId)\r\n    return S_OK;\r\n  encode = (clsID->Data3 != kDecodeId);\r\n  UInt64 id = 0;\r\n  for (int j = 0; j < 8; j++)\r\n    id |= ((UInt64)clsID->Data4[j]) << (8 * j);\r\n  for (unsigned i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)\r\n      continue;\r\n    if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n        codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n      return E_NOINTERFACE;\r\n    index = i;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  const CCodecInfo &codec = *g_Codecs[index];\r\n  if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n      codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n    return E_NOINTERFACE;\r\n  if (encode)\r\n  {\r\n    if (!codec.CreateEncoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateEncoder();\r\n  }\r\n  else\r\n  {\r\n    if (!codec.CreateDecoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateDecoder();\r\n  }\r\n  if (isCoder)\r\n    ((ICompressCoder *)*outObject)->AddRef();\r\n  else if (isCoder2)\r\n    ((ICompressCoder2 *)*outObject)->AddRef();\r\n  else\r\n    ((ICompressFilter *)*outObject)->AddRef();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  if (!isCoder && !isCoder2 && !isFilter)\r\n    return E_NOINTERFACE;\r\n  bool encode;\r\n  int codecIndex;\r\n  HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);\r\n  if (res != S_OK)\r\n    return res;\r\n  if (codecIndex < 0)\r\n    return CLASS_E_CLASSNOTAVAILABLE;\r\n  return CreateCoder2(encode, codecIndex, iid, outObject);\r\n}\r\n\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  ::VariantClear((VARIANTARG *)value);\r\n  const CCodecInfo &codec = *g_Codecs[codecIndex];\r\n  switch(propID)\r\n  {\r\n    case NMethodPropID::kID:\r\n    {\r\n      value->uhVal.QuadPart = (UInt64)codec.Id;\r\n      value->vt = VT_UI8;\r\n      break;\r\n    }\r\n    case NMethodPropID::kName:\r\n      if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)\r\n        value->vt = VT_BSTR;\r\n      break;\r\n    case NMethodPropID::kDecoder:\r\n      if (codec.CreateDecoder)\r\n        return SetClassID(codec.Id, false, value);\r\n      break;\r\n    case NMethodPropID::kEncoder:\r\n      if (codec.CreateEncoder)\r\n        return SetClassID(codec.Id, true, value);\r\n      break;\r\n    case NMethodPropID::kInStreams:\r\n    {\r\n      if (codec.NumInStreams != 1)\r\n      {\r\n        value->vt = VT_UI4;\r\n        value->ulVal = (ULONG)codec.NumInStreams;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetNumberOfMethods(UINT32 *numCodecs)\r\n{\r\n  *numCodecs = g_NumCodecs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/CopyCoder.cpp",
    "content": "// Compress/CopyCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"CopyCoder.h\"\r\n\r\nnamespace NCompress {\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCCopyCoder::~CCopyCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  TotalSize = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 realProcessedSize;\r\n    UInt32 size = kBufferSize;\r\n    if (outSize != 0)\r\n      if (size > *outSize - TotalSize)\r\n        size = (UInt32)(*outSize - TotalSize);\r\n    RINOK(inStream->Read(_buffer, size, &realProcessedSize));\r\n    if (realProcessedSize == 0)\r\n      break;\r\n    RINOK(WriteStream(outStream, _buffer, realProcessedSize));\r\n    TotalSize += realProcessedSize;\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = TotalSize;\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/CopyCoder.h",
    "content": "// Compress/CopyCoder.h\r\n\r\n#ifndef __COMPRESS_COPY_CODER_H\r\n#define __COMPRESS_COPY_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\n\r\nclass CCopyCoder:\r\n  public ICompressCoder,\r\n  public ICompressGetInStreamProcessedSize,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  UInt64 TotalSize;\r\n  CCopyCoder(): TotalSize(0) , _buffer(0) {};\r\n  ~CCopyCoder();\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/CopyRegister.cpp",
    "content": "// CopyRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"CopyCoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n{ CreateCodec, CreateCodec, 0x00, L\"Copy\", 1, false };\r\n\r\nREGISTER_CODEC(Copy)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /FAcs /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEncoder.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LzmaUtil\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LzmaDecoder.h\"\r\n#include \"../LzmaEncoder.h\"\r\n\r\n#include \"LzmaBenchCon.h\"\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/7zVersion.h\"\r\n  #include \"../../../../C/Alloc.h\"\r\n  #include \"../../../../C/LzmaUtil/Lzma86Dec.h\"\r\n  #include \"../../../../C/LzmaUtil/Lzma86Enc.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kAlgo,\r\n  kDict,\r\n  kFb,\r\n  kMc,\r\n  kLc,\r\n  kLp,\r\n  kPb,\r\n  kMatchFinder,\r\n  kMultiThread,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] =\r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MT\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kPostChar, false, 0, 0, L\"+\" }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\"\r\n    \"  -d{N}:  set dictionary size - [12, 30], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -mc{N}: set number of cycles for match finder\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\\n\"\r\n    \"  -mt{N}: set number of CPU threads\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[],\r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nstatic void ParseUInt32(const CParser &parser, int index, UInt32 &res)\r\n{\r\n  if (parser[index].ThereIs)\r\n    if (!GetNumber(parser[index].PostStrings[0], res))\r\n      IncorrectCommand();\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);\r\n  if (unsupportedTypes)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }\r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...)\r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++];\r\n\r\n  bool dictDefined = false;\r\n  UInt32 dict = (UInt32)-1;\r\n  if(parser[NKey::kDict].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDict].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dict = 1 << dicLog;\r\n    dictDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  UInt32 numThreads = (UInt32)-1;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (parser[NKey::kMultiThread].ThereIs)\r\n  {\r\n    UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n    const UString &s = parser[NKey::kMultiThread].PostStrings[0];\r\n    if (s.IsEmpty())\r\n      numThreads = numCPUs;\r\n    else\r\n      if (!GetNumber(s, numThreads))\r\n        IncorrectCommand();\r\n  }\r\n  #endif\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 1;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchCon(stderr, numIterations, numThreads, dict);\r\n  }\r\n\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = 1;\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++];\r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\",\r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  COutFileStream *outStreamSpec = NULL;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++];\r\n    outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\",\r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    size_t inSize = (size_t)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize);\r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    if (ReadStream_FAIL(inStream, inBuffer, inSize) != S_OK)\r\n      throw \"Can not read\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSize;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize);\r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictDefined)\r\n        dict = 1 << 23;\r\n      int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,\r\n          5, dict, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      UInt64 outSize64;\r\n      if (Lzma86_GetUnpackSize(inBuffer, inSize, &outSize64) != 0)\r\n        throw \"data error\";\r\n      outSize = (size_t)outSize64;\r\n      if (outSize != outSize64)\r\n        throw \"too big\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize);\r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = Lzma86_Decode(outBuffer, &outSize, inBuffer, &inSize);\r\n      if (inSize != (size_t)fileSize)\r\n        throw \"incorrect processed size\";\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, outSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLzma::CEncoder *encoderSpec = new NCompress::NLzma::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictDefined)\r\n      dict = 1 << 23;\r\n\r\n    UInt32 pb = 2;\r\n    UInt32 lc = 3; // = 0; for 32-bit data\r\n    UInt32 lp = 0; // = 2; for 32-bit data\r\n    UInt32 algo = 1;\r\n    UInt32 fb = 128;\r\n    UInt32 mc = 16 + fb / 2;\r\n    bool mcDefined = false;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    ParseUInt32(parser, NKey::kAlgo, algo);\r\n    ParseUInt32(parser, NKey::kFb, fb);\r\n    ParseUInt32(parser, NKey::kLc, lc);\r\n    ParseUInt32(parser, NKey::kLp, lp);\r\n    ParseUInt32(parser, NKey::kPb, pb);\r\n\r\n    mcDefined = parser[NKey::kMc].ThereIs;\r\n    if (mcDefined)\r\n      if (!GetNumber(parser[NKey::kMc].PostStrings[0], mc))\r\n        IncorrectCommand();\r\n    \r\n    PROPID propIDs[] =\r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker,\r\n      NCoderPropID::kNumThreads,\r\n      NCoderPropID::kMatchFinderCycles,\r\n    };\r\n    const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\r\n    PROPVARIANT props[kNumPropsMax];\r\n    for (int p = 0; p < 6; p++)\r\n      props[p].vt = VT_UI4;\r\n\r\n    props[0].ulVal = (UInt32)dict;\r\n    props[1].ulVal = (UInt32)pb;\r\n    props[2].ulVal = (UInt32)lc;\r\n    props[3].ulVal = (UInt32)lp;\r\n    props[4].ulVal = (UInt32)algo;\r\n    props[5].ulVal = (UInt32)fb;\r\n\r\n    props[6].vt = VT_BSTR;\r\n    props[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    props[7].vt = VT_BOOL;\r\n    props[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    props[8].vt = VT_UI4;\r\n    props[8].ulVal = (UInt32)numThreads;\r\n\r\n    // it must be last in property list\r\n    props[9].vt = VT_UI4;\r\n    props[9].ulVal = (UInt32)mc;\r\n\r\n    int numProps = kNumPropsMax;\r\n    if (!mcDefined)\r\n      numProps--;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, props, numProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }\r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NCompress::NLzma::CDecoder *decoderSpec = new NCompress::NLzma::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    decoderSpec->FinishStream = true;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte header[kPropertiesSize + 8];\r\n    if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(header, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n      fileSize |= ((UInt64)header[kPropertiesSize + i]) << (8 * i);\r\n\r\n    if (decoder->Code(inStream, outStream, 0, (fileSize == (UInt64)(Int64)-1) ? 0 : &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }\r\n  }\r\n  if (outStreamSpec != NULL)\r\n  {\r\n    if (outStreamSpec->Close() != S_OK)\r\n    {\r\n      fprintf(stderr, \"File closing error\");\r\n      return 1;\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n\r\nint MY_CDECL main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s)\r\n  {\r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1;\r\n  }\r\n  catch(...)\r\n  {\r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#define USE_POSIX_TIME\r\n#define USE_POSIX_TIME2\r\n#endif\r\n\r\n#ifdef USE_POSIX_TIME\r\n#include <time.h>\r\n#ifdef USE_POSIX_TIME2\r\n#include <sys/time.h>\r\n#endif\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n\r\n#ifdef BENCH_MT\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Windows/Thread.h\"\r\n#endif\r\n\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../ICoder.h\"\r\n#else\r\n#include \"../LzmaDecoder.h\"\r\n#include \"../LzmaEncoder.h\"\r\n#endif\r\n\r\nstatic const UInt32 kUncompressMinBlockSize = 1 << 26;\r\nstatic const UInt32 kAdditionalSize = (1 << 16);\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 5;\r\n\r\nclass CBaseRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CBaseRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd()\r\n  {\r\n    return\r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBenchBuffer\r\n{\r\npublic:\r\n  size_t BufferSize;\r\n  Byte *Buffer;\r\n  CBenchBuffer(): Buffer(0) {}\r\n  virtual ~CBenchBuffer() { Free(); }\r\n  void Free()\r\n  {\r\n    ::MidFree(Buffer);\r\n    Buffer = 0;\r\n  }\r\n  bool Alloc(size_t bufferSize)\r\n  {\r\n    if (Buffer != 0 && BufferSize == bufferSize)\r\n      return true;\r\n    Free();\r\n    Buffer = (Byte *)::MidAlloc(bufferSize);\r\n    BufferSize = bufferSize;\r\n    return (Buffer != 0);\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator: public CBenchBuffer\r\n{\r\n  CBaseRandomGenerator *RG;\r\npublic:\r\n  void Set(CBaseRandomGenerator *rg) { RG = rg; }\r\n  UInt32 GetVal(UInt32 &res, int numBits)\r\n  {\r\n    UInt32 val = res & (((UInt32)1 << numBits) - 1);\r\n    res >>= numBits;\r\n    return val;\r\n  }\r\n  UInt32 GetLen(UInt32 &res)\r\n  {\r\n    UInt32 len = GetVal(res, 2);\r\n    return GetVal(res, 1 + len);\r\n  }\r\n  void Generate()\r\n  {\r\n    UInt32 pos = 0;\r\n    UInt32 rep0 = 1;\r\n    while (pos < BufferSize)\r\n    {\r\n      UInt32 res = RG->GetRnd();\r\n      res >>= 1;\r\n      if (GetVal(res, 1) == 0 || pos < 1024)\r\n        Buffer[pos++] = (Byte)(res & 0xFF);\r\n      else\r\n      {\r\n        UInt32 len;\r\n        len = 1 + GetLen(res);\r\n        if (GetVal(res, 3) != 0)\r\n        {\r\n          len += GetLen(res);\r\n          do\r\n          {\r\n            UInt32 ppp = GetVal(res, 5) + 6;\r\n            res = RG->GetRnd();\r\n            if (ppp > 30)\r\n              continue;\r\n            rep0 = /* (1 << ppp) +*/  GetVal(res, ppp);\r\n            res = RG->GetRnd();\r\n          }\r\n          while (rep0 >= pos);\r\n          rep0++;\r\n        }\r\n\r\n        for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)\r\n          Buffer[pos] = Buffer[pos - rep0];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\n\r\nclass CBenchmarkInStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Pos;\r\n  size_t Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t remain = Size - Pos;\r\n  UInt32 kMaxBlockSize = (1 << 20);\r\n  if (size > kMaxBlockSize)\r\n    size = kMaxBlockSize;\r\n  if (size > remain)\r\n    size = (UInt32)remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream:\r\n  public ISequentialOutStream,\r\n  public CBenchBuffer,\r\n  public CMyUnknownImp\r\n{\r\n  // bool _overflow;\r\npublic:\r\n  UInt32 Pos;\r\n  // CBenchmarkOutStream(): _overflow(false) {}\r\n  void Init()\r\n  {\r\n    // _overflow = false;\r\n    Pos = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t curSize = BufferSize - Pos;\r\n  if (curSize > size)\r\n    curSize = size;\r\n  memcpy(Buffer + Pos, data, curSize);\r\n  Pos += (UInt32)curSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)curSize;\r\n  if (curSize != size)\r\n  {\r\n    // _overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  UInt32 Crc;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { Crc = CRC_INIT_VAL; }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  Crc = CrcUpdate(Crc, data, size);\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  timeval v;\r\n  if (gettimeofday(&v, 0) == 0)\r\n    return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;\r\n  return (UInt64)time(NULL) * 1000000;\r\n  #else\r\n  return time(NULL);\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return GetTickCount();\r\n  #endif\r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  return 1000000;\r\n  #else\r\n  return 1;\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return 1000;\r\n  #endif\r\n}\r\n\r\n#ifndef USE_POSIX_TIME\r\nstatic inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }\r\n#endif\r\nstatic UInt64 GetUserTime()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return clock();\r\n  #else\r\n  FILETIME creationTime, exitTime, kernelTime, userTime;\r\n  if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)\r\n    return GetTime64(userTime) + GetTime64(kernelTime);\r\n  return (UInt64)GetTickCount() * 10000;\r\n  #endif\r\n}\r\n\r\nstatic UInt64 GetUserFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return CLOCKS_PER_SEC;\r\n  #else\r\n  return 10000000;\r\n  #endif\r\n}\r\n\r\nclass CBenchProgressStatus\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::NSynchronization::CCriticalSection CS;\r\n  #endif\r\npublic:\r\n  HRESULT Res;\r\n  bool EncodeMode;\r\n  void SetResult(HRESULT res)\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    Res = res;\r\n  }\r\n  HRESULT GetResult()\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    return Res;\r\n  }\r\n};\r\n\r\nclass CBenchProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CBenchProgressStatus *Status;\r\n  CBenchInfo BenchInfo;\r\n  HRESULT Res;\r\n  IBenchCallback *callback;\r\n  CBenchProgressInfo(): callback(0) {}\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nvoid SetStartTime(CBenchInfo &bi)\r\n{\r\n  bi.GlobalFreq = GetFreq();\r\n  bi.UserFreq = GetUserFreq();\r\n  bi.GlobalTime = ::GetTimeCount();\r\n  bi.UserTime = ::GetUserTime();\r\n}\r\n\r\nvoid SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)\r\n{\r\n  dest.GlobalFreq = GetFreq();\r\n  dest.UserFreq = GetUserFreq();\r\n  dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;\r\n  dest.UserTime = ::GetUserTime() - biStart.UserTime;\r\n}\r\n\r\nSTDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  HRESULT res = Status->GetResult();\r\n  if (res != S_OK)\r\n    return res;\r\n  if (!callback)\r\n    return res;\r\n  CBenchInfo info = BenchInfo;\r\n  SetFinishTime(BenchInfo, info);\r\n  if (Status->EncodeMode)\r\n  {\r\n    info.UnpackSize = *inSize;\r\n    info.PackSize = *outSize;\r\n    res = callback->SetEncodeResult(info, false);\r\n  }\r\n  else\r\n  {\r\n    info.PackSize = BenchInfo.PackSize + *inSize;\r\n    info.UnpackSize = BenchInfo.UnpackSize + *outSize;\r\n    res = callback->SetDecodeResult(info, false);\r\n  }\r\n  if (res != S_OK)\r\n    Status->SetResult(res);\r\n  return res;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nUInt64 GetUsage(const CBenchInfo &info)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userTime, userFreq);\r\n  NormalizeVals(globalFreq, globalTime);\r\n  if (userFreq == 0)\r\n    userFreq = 1;\r\n  if (globalTime == 0)\r\n    globalTime = 1;\r\n  return userTime * globalFreq * 1000000 / userFreq / globalTime;\r\n}\r\n\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userFreq, userTime);\r\n  NormalizeVals(globalTime, globalFreq);\r\n  if (globalFreq == 0)\r\n    globalFreq = 1;\r\n  if (userTime == 0)\r\n    userTime = 1;\r\n  return userFreq * globalTime / globalFreq *  rating / userTime;\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)\r\n{\r\n  UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);\r\n  UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits));\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)\r\n{\r\n  UInt64 numCommands = (inSize * 200 + outSize * 4) * numIterations;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\n#ifdef EXTERNAL_LZMA\r\ntypedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID,\r\n    const GUID *interfaceID, void **outObject);\r\n#endif\r\n\r\nstruct CEncoderInfo;\r\n\r\nstruct CEncoderInfo\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::CThread thread[2];\r\n  #endif\r\n  CMyComPtr<ICompressCoder> encoder;\r\n  CBenchProgressInfo *progressInfoSpec[2];\r\n  CMyComPtr<ICompressProgressInfo> progressInfo[2];\r\n  UInt32 NumIterations;\r\n  #ifdef USE_ALLOCA\r\n  size_t AllocaSize;\r\n  #endif\r\n\r\n  struct CDecoderInfo\r\n  {\r\n    CEncoderInfo *Encoder;\r\n    UInt32 DecoderIndex;\r\n    #ifdef USE_ALLOCA\r\n    size_t AllocaSize;\r\n    #endif\r\n    bool CallbackMode;\r\n  };\r\n  CDecoderInfo decodersInfo[2];\r\n\r\n  CMyComPtr<ICompressCoder> decoders[2];\r\n  HRESULT Results[2];\r\n  CBenchmarkOutStream *outStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  IBenchCallback *callback;\r\n  UInt32 crc;\r\n  UInt32 kBufferSize;\r\n  UInt32 compressedSize;\r\n  CBenchRandomGenerator rg;\r\n  CBenchmarkOutStream *propStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> propStream;\r\n  HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);\r\n  HRESULT Encode();\r\n  HRESULT Decode(UInt32 decoderIndex);\r\n\r\n  CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}\r\n\r\n  #ifdef BENCH_MT\r\n  static THREAD_FUNC_DECL EncodeThreadFunction(void *param)\r\n  {\r\n    CEncoderInfo *encoder = (CEncoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(encoder->AllocaSize);\r\n    #endif\r\n    HRESULT res = encoder->Encode();\r\n    encoder->Results[0] = res;\r\n    if (res != S_OK)\r\n      encoder->progressInfoSpec[0]->Status->SetResult(res);\r\n\r\n    return 0;\r\n  }\r\n  static THREAD_FUNC_DECL DecodeThreadFunction(void *param)\r\n  {\r\n    CDecoderInfo *decoder = (CDecoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(decoder->AllocaSize);\r\n    #endif\r\n    CEncoderInfo *encoder = decoder->Encoder;\r\n    encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);\r\n    return 0;\r\n  }\r\n\r\n  HRESULT CreateEncoderThread()\r\n  {\r\n    return thread[0].Create(EncodeThreadFunction, this);\r\n  }\r\n\r\n  HRESULT CreateDecoderThread(int index, bool callbackMode\r\n      #ifdef USE_ALLOCA\r\n      , size_t allocaSize\r\n      #endif\r\n      )\r\n  {\r\n    CDecoderInfo &decoder = decodersInfo[index];\r\n    decoder.DecoderIndex = index;\r\n    decoder.Encoder = this;\r\n    #ifdef USE_ALLOCA\r\n    decoder.AllocaSize = allocaSize;\r\n    #endif\r\n    decoder.CallbackMode = callbackMode;\r\n    return thread[index].Create(DecodeThreadFunction, &decoder);\r\n  }\r\n  #endif\r\n};\r\n\r\nHRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)\r\n{\r\n  rg.Set(rgLoc);\r\n  kBufferSize = dictionarySize + kAdditionalSize;\r\n  UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n  if (!rg.Alloc(kBufferSize))\r\n    return E_OUTOFMEMORY;\r\n  rg.Generate();\r\n  crc = CrcCalc(rg.Buffer, rg.BufferSize);\r\n\r\n  outStreamSpec = new CBenchmarkOutStream;\r\n  if (!outStreamSpec->Alloc(kCompressedBufferSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  outStream = outStreamSpec;\r\n\r\n  propStreamSpec = 0;\r\n  if (!propStream)\r\n  {\r\n    propStreamSpec = new CBenchmarkOutStream;\r\n    propStream = propStreamSpec;\r\n  }\r\n  if (!propStreamSpec->Alloc(kMaxLzmaPropSize))\r\n    return E_OUTOFMEMORY;\r\n  propStreamSpec->Init();\r\n  \r\n  PROPID propIDs[] =\r\n  {\r\n    NCoderPropID::kDictionarySize,\r\n    NCoderPropID::kMultiThread\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)dictionarySize;\r\n\r\n  properties[1].vt = VT_BOOL;\r\n  properties[1].boolVal = (numThreads > 1) ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n  {\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));\r\n    if (!setCoderProperties)\r\n      return E_FAIL;\r\n    RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, kNumProps));\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);\r\n    if (writeCoderProperties)\r\n    {\r\n      RINOK(writeCoderProperties->WriteCoderProperties(propStream));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Encode()\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n  outStreamSpec->Init();\r\n\r\n  RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));\r\n  compressedSize = outStreamSpec->Pos;\r\n  encoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Decode(UInt32 decoderIndex)\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];\r\n\r\n  CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;\r\n  decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);\r\n  if (!compressSetDecoderProperties)\r\n    return E_FAIL;\r\n\r\n  CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n  CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n  CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];\r\n  pi->BenchInfo.UnpackSize = 0;\r\n  pi->BenchInfo.PackSize = 0;\r\n\r\n  for (UInt32 j = 0; j < NumIterations; j++)\r\n  {\r\n    inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n    crcOutStreamSpec->Init();\r\n    \r\n    RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));\r\n    UInt64 outSize = kBufferSize;\r\n    RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));\r\n    if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)\r\n      return S_FALSE;\r\n    pi->BenchInfo.UnpackSize += kBufferSize;\r\n    pi->BenchInfo.PackSize += compressedSize;\r\n  }\r\n  decoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nstatic const UInt32 kNumThreadsMax = (1 << 16);\r\n\r\nstruct CBenchEncoders\r\n{\r\n  CEncoderInfo *encoders;\r\n  CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }\r\n  ~CBenchEncoders() { delete []encoders; }\r\n};\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)\r\n{\r\n  UInt32 numEncoderThreads =\r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? numThreads / 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  UInt32 numSubDecoderThreads =\r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)\r\n  {\r\n    return E_INVALIDARG;\r\n  }\r\n\r\n  CBenchEncoders encodersSpec(numEncoderThreads);\r\n  CEncoderInfo *encoders = encodersSpec.encoders;\r\n\r\n  #ifdef EXTERNAL_LZMA\r\n  UString name = L\"LZMA\";\r\n  #endif\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.callback = (i == 0) ? callback : 0;\r\n\r\n    #ifdef EXTERNAL_LZMA\r\n    RINOK(codecs->CreateCoder(name, true, encoder.encoder));\r\n    #else\r\n    encoder.encoder = new NCompress::NLzma::CEncoder;\r\n    #endif\r\n    for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n    {\r\n      #ifdef EXTERNAL_LZMA\r\n      RINOK(codecs->CreateCoder(name, false, encoder.decoders[j]));\r\n      #else\r\n      encoder.decoders[j] = new NCompress::NLzma::CDecoder;\r\n      #endif\r\n    }\r\n  }\r\n\r\n  CBaseRandomGenerator rg;\r\n  rg.Init();\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));\r\n  }\r\n\r\n  CBenchProgressStatus status;\r\n  status.Res = S_OK;\r\n  status.EncodeMode = true;\r\n\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;\r\n      encoder.progressInfoSpec[j]->Status = &status;\r\n    }\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numEncoderThreads > 1)\r\n    {\r\n      #ifdef USE_ALLOCA\r\n      encoder.AllocaSize = (i * 16 * 21) & 0x7FF;\r\n      #endif\r\n      RINOK(encoder.CreateEncoderThread())\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Encode());\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  if (numEncoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      encoders[i].thread[0].Wait();\r\n  #endif\r\n\r\n  RINOK(status.Res);\r\n\r\n  CBenchInfo info;\r\n\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = 1; // progressInfoSpec->NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetEncodeResult(info, true));\r\n\r\n\r\n  status.Res = S_OK;\r\n  status.EncodeMode = false;\r\n\r\n  UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;\r\n\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numDecoderThreads > 1)\r\n    {\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)\r\n            #ifdef USE_ALLOCA\r\n            , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF\r\n            #endif\r\n            );\r\n        RINOK(res);\r\n      }\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Decode(0));\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  HRESULT res = S_OK;\r\n  if (numDecoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        CEncoderInfo &encoder = encoders[i];\r\n        encoder.thread[j].Wait();\r\n        if (encoder.Results[j] != S_OK)\r\n          res = encoder.Results[j];\r\n      }\r\n  RINOK(res);\r\n  #endif\r\n  RINOK(status.Res);\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetDecodeResult(info, false));\r\n  RINOK(callback->SetDecodeResult(info, true));\r\n  return S_OK;\r\n}\r\n\r\n\r\ninline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)\r\n{\r\n  UInt32 hs = dictionary - 1;\r\n  hs |= (hs >> 1);\r\n  hs |= (hs >> 2);\r\n  hs |= (hs >> 4);\r\n  hs |= (hs >> 8);\r\n  hs >>= 1;\r\n  hs |= 0xFFFF;\r\n  if (hs > (1 << 24))\r\n    hs >>= 1;\r\n  hs++;\r\n  return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +\r\n      (1 << 20) + (multiThread ? (6 << 20) : 0);\r\n}\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  const UInt32 kBufferSize = dictionary;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2);\r\n  UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;\r\n  UInt32 numBigThreads = numThreads / numSubThreads;\r\n  return (kBufferSize + kCompressedBufferSize +\r\n    GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;\r\n}\r\n\r\nstatic bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)\r\n{\r\n  for (UInt32 i = 0; i < numCycles; i++)\r\n    if (CrcCalc(data, size) != crcBase)\r\n      return false;\r\n  return true;\r\n}\r\n\r\n#ifdef BENCH_MT\r\nstruct CCrcInfo\r\n{\r\n  NWindows::CThread Thread;\r\n  const Byte *Data;\r\n  UInt32 Size;\r\n  UInt32 NumCycles;\r\n  UInt32 Crc;\r\n  bool Res;\r\n  void Wait()\r\n  {\r\n    Thread.Wait();\r\n    Thread.Close();\r\n  }\r\n};\r\n\r\nstatic THREAD_FUNC_DECL CrcThreadFunction(void *param)\r\n{\r\n  CCrcInfo *p = (CCrcInfo *)param;\r\n  p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);\r\n  return 0;\r\n}\r\n\r\nstruct CCrcThreads\r\n{\r\n  UInt32 NumThreads;\r\n  CCrcInfo *Items;\r\n  CCrcThreads(): Items(0), NumThreads(0) {}\r\n  void WaitAll()\r\n  {\r\n    for (UInt32 i = 0; i < NumThreads; i++)\r\n      Items[i].Wait();\r\n    NumThreads = 0;\r\n  }\r\n  ~CCrcThreads()\r\n  {\r\n    WaitAll();\r\n    delete []Items;\r\n  }\r\n};\r\n#endif\r\n\r\nstatic UInt32 CrcCalc1(const Byte *buf, UInt32 size)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    crc = CRC_UPDATE_BYTE(crc, buf[i]);\r\n  return CRC_GET_DIGEST(crc);\r\n}\r\n\r\nstatic void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  for (UInt32 i = 0; i < size; i++)\r\n    buf[i] = (Byte)RG.GetRnd();\r\n}\r\n\r\nstatic UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  RandGen(buf, size, RG);\r\n  return CrcCalc1(buf, size);\r\n}\r\n\r\nbool CrcInternalTest()\r\n{\r\n  CBenchBuffer buffer;\r\n  const UInt32 kBufferSize0 = (1 << 8);\r\n  const UInt32 kBufferSize1 = (1 << 10);\r\n  const UInt32 kCheckSize = (1 << 5);\r\n  if (!buffer.Alloc(kBufferSize0 + kBufferSize1))\r\n    return false;\r\n  Byte *buf = buffer.Buffer;\r\n  UInt32 i;\r\n  for (i = 0; i < kBufferSize0; i++)\r\n    buf[i] = (Byte)i;\r\n  UInt32 crc1 = CrcCalc1(buf, kBufferSize0);\r\n  if (crc1 != 0x29058C73)\r\n    return false;\r\n  CBaseRandomGenerator RG;\r\n  RandGen(buf + kBufferSize0, kBufferSize1, RG);\r\n  for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)\r\n    for (UInt32 j = 0; j < kCheckSize; j++)\r\n      if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))\r\n        return false;\r\n  return true;\r\n}\r\n\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)\r\n{\r\n  if (numThreads == 0)\r\n    numThreads = 1;\r\n\r\n  CBenchBuffer buffer;\r\n  size_t totalSize = (size_t)bufferSize * numThreads;\r\n  if (totalSize / numThreads != bufferSize)\r\n    return E_OUTOFMEMORY;\r\n  if (!buffer.Alloc(totalSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  Byte *buf = buffer.Buffer;\r\n  CBaseRandomGenerator RG;\r\n  UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;\r\n\r\n  UInt64 timeVal;\r\n  #ifdef BENCH_MT\r\n  CCrcThreads threads;\r\n  if (numThreads > 1)\r\n  {\r\n    threads.Items = new CCrcInfo[numThreads];\r\n    UInt32 i;\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      Byte *data = buf + (size_t)bufferSize * i;\r\n      info.Data = data;\r\n      info.NumCycles = numCycles;\r\n      info.Size = bufferSize;\r\n      info.Crc = RandGenCrc(data, bufferSize, RG);\r\n    }\r\n    timeVal = GetTimeCount();\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      RINOK(info.Thread.Create(CrcThreadFunction, &info));\r\n      threads.NumThreads++;\r\n    }\r\n    threads.WaitAll();\r\n    for (i = 0; i < numThreads; i++)\r\n      if (!threads.Items[i].Res)\r\n        return S_FALSE;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 crc = RandGenCrc(buf, bufferSize, RG);\r\n    timeVal = GetTimeCount();\r\n    if (!CrcBig(buf, bufferSize, numCycles, crc))\r\n      return S_FALSE;\r\n  }\r\n  timeVal = GetTimeCount() - timeVal;\r\n  if (timeVal == 0)\r\n    timeVal = 1;\r\n\r\n  UInt64 size = (UInt64)numCycles * totalSize;\r\n  speed = MyMultDiv64(size, timeVal, GetFreq());\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LZMABENCH_H\r\n#define __LZMABENCH_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\n\r\nstruct CBenchInfo\r\n{\r\n  UInt64 GlobalTime;\r\n  UInt64 GlobalFreq;\r\n  UInt64 UserTime;\r\n  UInt64 UserFreq;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt32 NumIterations;\r\n  CBenchInfo(): NumIterations(0) {}\r\n};\r\n\r\nstruct IBenchCallback\r\n{\r\n  virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;\r\n  virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;\r\n};\r\n\r\nUInt64 GetUsage(const CBenchInfo &benchOnfo);\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);\r\n\r\nconst int kBenchMinDicLogSize = 18;\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);\r\n\r\nbool CrcInternalTest();\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp",
    "content": "// LzmaBenchCon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaBenchCon.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#if defined(BENCH_MT) || defined(_WIN32)\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#ifdef BREAK_HANDLER\r\n#include \"../../UI/Console/ConsoleClose.h\"\r\n#endif\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nstruct CTotalBenchRes\r\n{\r\n  UInt64 NumIterations;\r\n  UInt64 Rating;\r\n  UInt64 Usage;\r\n  UInt64 RPU;\r\n  void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }\r\n  void Normalize()\r\n  {\r\n    if (NumIterations == 0)\r\n      return;\r\n    Rating /= NumIterations;\r\n    Usage /= NumIterations;\r\n    RPU /= NumIterations;\r\n    NumIterations = 1;\r\n  }\r\n  void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)\r\n  {\r\n    Rating = (r1.Rating + r2.Rating) / 2;\r\n    Usage = (r1.Usage + r2.Usage) / 2;\r\n    RPU = (r1.RPU + r2.RPU) / 2;\r\n    NumIterations = (r1.NumIterations + r2.NumIterations) / 2;\r\n  }\r\n};\r\n\r\nstruct CBenchCallback: public IBenchCallback\r\n{\r\n  CTotalBenchRes EncodeRes;\r\n  CTotalBenchRes DecodeRes;\r\n  FILE *f;\r\n  void Init() { EncodeRes.Init(); DecodeRes.Init(); }\r\n  void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }\r\n  UInt32 dictionarySize;\r\n  HRESULT SetEncodeResult(const CBenchInfo &info, bool final);\r\n  HRESULT SetDecodeResult(const CBenchInfo &info, bool final);\r\n};\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic void PrintNumber(FILE *f, UInt64 value, int size)\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(value, s);\r\n  fprintf(f, \" \");\r\n  for (int len = (int)strlen(s); len < size; len++)\r\n    fprintf(f, \" \");\r\n  fprintf(f, \"%s\", s);\r\n}\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  PrintNumber(f, rating / 1000000, 6);\r\n}\r\n\r\nstatic void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)\r\n{\r\n  PrintNumber(f, (usage + 5000) / 10000, 5);\r\n  PrintRating(f, rpu);\r\n  PrintRating(f, rating);\r\n}\r\n\r\n\r\nstatic void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)\r\n{\r\n  UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);\r\n  PrintNumber(f, speed / 1024, 7);\r\n  UInt64 usage = GetUsage(info);\r\n  UInt64 rpu = GetRatingPerUsage(info, rating);\r\n  PrintResults(f, usage, rpu, rating);\r\n  res.NumIterations++;\r\n  res.RPU += rpu;\r\n  res.Rating += rating;\r\n  res.Usage += usage;\r\n}\r\n\r\nstatic void PrintTotals(FILE *f, const CTotalBenchRes &res)\r\n{\r\n  fprintf(f, \"       \");\r\n  PrintResults(f, res.Usage, res.RPU, res.Rating);\r\n}\r\n\r\n\r\nHRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);\r\n    PrintResults(f, info, rating, EncodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const char *kSep = \"  | \";\r\n\r\n\r\nHRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);\r\n    fprintf(f, kSep);\r\n    CBenchInfo info2 = info;\r\n    info2.UnpackSize *= info2.NumIterations;\r\n    info2.PackSize *= info2.NumIterations;\r\n    info2.NumIterations = 1;\r\n    PrintResults(f, info2, rating, DecodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)\r\n{\r\n  fprintf(f, \"\\nRAM %s \", sizeString);\r\n  PrintNumber(f, (size >> 20), 5);\r\n  fprintf(f, \" MB,  # %s %3d\", threadsString, (unsigned int)numThreads);\r\n}\r\n\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();  //\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  if (numThreads > 1)\r\n    numThreads &= ~1;\r\n  if (dictionary == (UInt32)-1)\r\n  {\r\n    int dicSizeLog;\r\n    for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)\r\n      if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)\r\n        break;\r\n    dictionary = (1 << dicSizeLog);\r\n  }\r\n  #else\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 22);\r\n  numThreads = 1;\r\n  #endif\r\n\r\n  PrintRequirements(f, \"usage:\", GetBenchMemoryUsage(numThreads, dictionary), \"Benchmark threads:   \", numThreads);\r\n\r\n  CBenchCallback callback;\r\n  callback.Init();\r\n  callback.f = f;\r\n  \r\n  fprintf(f, \"\\n\\nDict        Compressing          |        Decompressing\\n   \");\r\n  int j;\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"   Speed Usage    R/U Rating\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n   \");\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"    KB/s     %%   MIPS   MIPS\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    const int kStartDicLog = 22;\r\n    int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;\r\n    while (((UInt32)1 << pow) > dictionary)\r\n      pow--;\r\n    for (; ((UInt32)1 << pow) <= dictionary; pow++)\r\n    {\r\n      fprintf(f, \"%2d:\", pow);\r\n      callback.dictionarySize = (UInt32)1 << pow;\r\n      HRESULT res = LzmaBench(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        numThreads, callback.dictionarySize, &callback);\r\n      fprintf(f, \"\\n\");\r\n      RINOK(res);\r\n    }\r\n  }\r\n  callback.Normalize();\r\n  fprintf(f, \"----------------------------------------------------------------\\nAvr:\");\r\n  PrintTotals(f, callback.EncodeRes);\r\n  fprintf(f, \"     \");\r\n  PrintTotals(f, callback.DecodeRes);\r\n  fprintf(f, \"\\nTot:\");\r\n  CTotalBenchRes midRes;\r\n  midRes.SetMid(callback.EncodeRes, callback.DecodeRes);\r\n  PrintTotals(f, midRes);\r\n  fprintf(f, \"\\n\");\r\n  return S_OK;\r\n}\r\n\r\nstruct CTempValues\r\n{\r\n  UInt64 *Values;\r\n  CTempValues(UInt32 num) { Values = new UInt64[num]; }\r\n  ~CTempValues() { delete []Values; }\r\n};\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  #else\r\n  numThreads = 1;\r\n  #endif\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 24);\r\n\r\n  CTempValues speedTotals(numThreads);\r\n  fprintf(f, \"\\n\\nSize\");\r\n  for (UInt32 ti = 0; ti < numThreads; ti++)\r\n  {\r\n    fprintf(f, \" %5d\", ti + 1);\r\n    speedTotals.Values[ti] = 0;\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n\r\n  UInt64 numSteps = 0;\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    for (int pow = 10; pow < 32; pow++)\r\n    {\r\n      UInt32 bufSize = (UInt32)1 << pow;\r\n      if (bufSize > dictionary)\r\n        break;\r\n      fprintf(f, \"%2d: \", pow);\r\n      UInt64 speed;\r\n      for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      {\r\n        #ifdef BREAK_HANDLER\r\n        if (NConsoleClose::TestBreakSignal())\r\n          return E_ABORT;\r\n        #endif\r\n        RINOK(CrcBench(ti + 1, bufSize, speed));\r\n        PrintNumber(f, (speed >> 20), 5);\r\n        speedTotals.Values[ti] += speed;\r\n      }\r\n      fprintf(f, \"\\n\");\r\n      numSteps++;\r\n    }\r\n  }\r\n  if (numSteps != 0)\r\n  {\r\n    fprintf(f, \"\\nAvg:\");\r\n    for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);\r\n    fprintf(f, \"\\n\");\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h",
    "content": "// LzmaBenchCon.h\r\n\r\n#ifndef __LZMABENCHCON_H\r\n#define __LZMABENCHCON_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nLIBS = $(LIBS) user32.lib\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -DBENCH_MT \\\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj\r\n\r\nWIN_OBJS = \\\r\n  $O\\System.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZMAUTIL_OBJS = \\\r\n  $O\\Lzma86Dec.obj \\\r\n  $O\\Lzma86Enc.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZMAUTIL_OBJS) \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZMAUTIL_OBJS): ../../../../C/LzmaUtil/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c\r\n\r\nifdef SystemDrive\r\nIS_MINGW = 1\r\nendif\r\n\r\nifdef IS_MINGW\r\nFILE_IO =FileIO\r\nFILE_IO_2 =Windows/$(FILE_IO)\r\nLIB2 = -luuid\r\nelse\r\nFILE_IO =C_FileIO\r\nFILE_IO_2 =Common/$(FILE_IO)\r\nendif\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaBenchCon.o \\\r\n  LzmaDecoder.o \\\r\n  LzmaEncoder.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  $(FILE_IO).o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  IntToString.o \\\r\n  MyString.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  MyVector.o \\\r\n  7zCrc.o \\\r\n  Alloc.o \\\r\n  Bra86.o \\\r\n  LzFind.o \\\r\n  LzmaDec.o \\\r\n  LzmaEnc.o \\\r\n  Lzma86Dec.o \\\r\n  Lzma86Enc.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaBenchCon.o: LzmaBenchCon.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBenchCon.cpp\r\n\r\nLzmaDecoder.o: ../LzmaDecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LzmaDecoder.cpp\r\n\r\nLzmaEncoder.o: ../LzmaEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LzmaEncoder.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\n$(FILE_IO).o: ../../../$(FILE_IO_2).cpp\r\n\t$(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp\r\n\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nIntToString.o: ../../../Common/IntToString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp\r\n\r\nMyString.o: ../../../Common/MyString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyString.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nMyVector.o: ../../../Common/MyVector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyVector.cpp\r\n\r\n7zCrc.o: ../../../../C/7zCrc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c\r\n\r\nAlloc.o: ../../../../C/Alloc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c\r\n\r\nBra86.o: ../../../../C/Bra86.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Bra86.c\r\n\r\nLzFind.o: ../../../../C/LzFind.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzFind.c\r\n\r\nLzmaDec.o: ../../../../C/LzmaDec.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaDec.c\r\n\r\nLzmaEnc.o: ../../../../C/LzmaEnc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaEnc.c\r\n\r\nLzma86Dec.o: ../../../../C/LzmaUtil/Lzma86Dec.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Dec.c\r\n\r\nLzma86Enc.o: ../../../../C/LzmaUtil/Lzma86Enc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LzmaDecoder.cpp",
    "content": "// LzmaDecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"LzmaDecoder.h\"\r\n\r\nstatic HRESULT SResToHRESULT(SRes res)\r\n{\r\n  switch(res)\r\n  {\r\n    case SZ_OK: return S_OK;\r\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\r\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\r\n    case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;\r\n    // case SZ_ERROR_PROGRESS: return E_ABORT;\r\n    case SZ_ERROR_DATA: return S_FALSE;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstatic const UInt32 kInBufSize = 1 << 20;\r\n\r\nCDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false), FinishStream(false)\r\n{\r\n  LzmaDec_Construct(&_state);\r\n}\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCDecoder::~CDecoder()\r\n{\r\n  LzmaDec_Free(&_state, &g_Alloc);\r\n  MyFree(_inBuf);\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)\r\n{\r\n  RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc)));\r\n\r\n  if (_inBuf == 0)\r\n  {\r\n    _inBuf = (Byte *)MyAlloc(kInBufSize);\r\n    if (_inBuf == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) { *value = _inSizeProcessed; return S_OK; }\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; }\r\nSTDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; }\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  _outSizeDefined = (outSize != NULL);\r\n  if (_outSizeDefined)\r\n    _outSize = *outSize;\r\n\r\n  LzmaDec_Init(&_state);\r\n  \r\n  _inPos = _inSize = 0;\r\n  _inSizeProcessed = _outSizeProcessed = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)\r\n{\r\n  if (_inBuf == 0)\r\n    return S_FALSE;\r\n  SetOutStreamSize(outSize);\r\n\r\n  for (;;)\r\n  {\r\n    if (_inPos == _inSize)\r\n    {\r\n      _inPos = _inSize = 0;\r\n      RINOK(inStream->Read(_inBuf, kInBufSize, &_inSize));\r\n    }\r\n\r\n    SizeT dicPos = _state.dicPos;\r\n    SizeT curSize = _state.dicBufSize - dicPos;\r\n    const UInt32 kStepSize = ((UInt32)1 << 22);\r\n    if (curSize > kStepSize)\r\n      curSize = (SizeT)kStepSize;\r\n    \r\n    ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\r\n    if (_outSizeDefined)\r\n    {\r\n      const UInt64 rem = _outSize - _outSizeProcessed;\r\n      if (rem < curSize)\r\n      {\r\n        curSize = (SizeT)rem;\r\n        if (FinishStream)\r\n          finishMode = LZMA_FINISH_END;\r\n      }\r\n    }\r\n\r\n    SizeT inSizeProcessed = _inSize - _inPos;\r\n    ELzmaStatus status;\r\n    SRes res = LzmaDec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status);\r\n\r\n    _inPos += (UInt32)inSizeProcessed;\r\n    _inSizeProcessed += inSizeProcessed;\r\n    SizeT outSizeProcessed = _state.dicPos - dicPos;\r\n    _outSizeProcessed += outSizeProcessed;\r\n\r\n    bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0);\r\n    bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize);\r\n\r\n    if (res != 0 || _state.dicPos == _state.dicBufSize || finished || stopDecoding)\r\n    {\r\n      HRESULT res2 = WriteStream(outStream, _state.dic, _state.dicPos);\r\n      if (res != 0)\r\n        return S_FALSE;\r\n      RINOK(res2);\r\n      if (stopDecoding)\r\n        return S_OK;\r\n      if (finished)\r\n        return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE);\r\n    }\r\n    if (_state.dicPos == _state.dicBufSize)\r\n      _state.dicPos = 0;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed));\r\n    }\r\n  }\r\n}\r\n\r\n#ifndef NO_READ_FROM_CODER\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  do\r\n  {\r\n    if (_inPos == _inSize)\r\n    {\r\n      _inPos = _inSize = 0;\r\n      RINOK(_inStream->Read(_inBuf, kInBufSize, &_inSize));\r\n    }\r\n    {\r\n      SizeT inProcessed = _inSize - _inPos;\r\n\r\n      if (_outSizeDefined)\r\n      {\r\n        const UInt64 rem = _outSize - _outSizeProcessed;\r\n        if (rem < size)\r\n          size = (UInt32)rem;\r\n      }\r\n\r\n      SizeT outProcessed = size;\r\n      ELzmaStatus status;\r\n      SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,\r\n          _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);\r\n      _inPos += (UInt32)inProcessed;\r\n      _inSizeProcessed += inProcessed;\r\n      _outSizeProcessed += outProcessed;\r\n      size -= (UInt32)outProcessed;\r\n      data = (Byte *)data + outProcessed;\r\n      if (processedSize)\r\n        *processedSize += (UInt32)outProcessed;\r\n      RINOK(SResToHRESULT(res));\r\n      if (inProcessed == 0 && outProcessed == 0)\r\n        return S_OK;\r\n    }\r\n  }\r\n  while (size != 0);\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LzmaDecoder.h",
    "content": "// LzmaDecoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/LzmaDec.h\"\r\n}\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nclass CDecoder:\r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  public ICompressGetInStreamProcessedSize,\r\n  #ifndef NO_READ_FROM_CODER\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  Byte *_inBuf;\r\n  UInt32 _inPos;\r\n  UInt32 _inSize;\r\n  CLzmaDec _state;\r\n  bool _outSizeDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _inSizeProcessed;\r\n  UInt64 _outSizeProcessed;\r\npublic:\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  MY_UNKNOWN_IMP5(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize,\r\n      ICompressSetInStream,\r\n      ICompressSetOutStreamSize,\r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize)\r\n  #endif\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  bool FinishStream;\r\n\r\n  CDecoder();\r\n  virtual ~CDecoder();\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LzmaEncoder.cpp",
    "content": "// LzmaEncoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"LzmaEncoder.h\"\r\n\r\nstatic HRESULT SResToHRESULT(SRes res)\r\n{\r\n  switch(res)\r\n  {\r\n    case SZ_OK: return S_OK;\r\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\r\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\r\n    // case SZ_ERROR_THREAD: return E_FAIL;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstatic const UInt32 kStreamStepSize = (UInt32)1 << 31;\r\n\r\nstatic SRes MyRead(void *object, void *data, size_t *size)\r\n{\r\n  UInt32 curSize = ((*size < kStreamStepSize) ? (UInt32)*size : kStreamStepSize);\r\n  HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize);\r\n  *size = curSize;\r\n  return (SRes)res;\r\n}\r\n\r\nstatic size_t MyWrite(void *object, const void *data, size_t size)\r\n{\r\n  CSeqOutStream *p = (CSeqOutStream *)object;\r\n  p->Res = WriteStream(p->RealStream, data, size);\r\n  if (p->Res != 0)\r\n    return 0;\r\n  return size;\r\n}\r\n\r\nstatic void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }\r\nstatic void SzBigFree(void *, void *address) { BigFree(address); }\r\nstatic ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };\r\n\r\nstatic void *SzAlloc(void *, size_t size) { return MyAlloc(size); }\r\nstatic void SzFree(void *, void *address) { MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCEncoder::CEncoder()\r\n{\r\n  _seqInStream.SeqInStream.Read = MyRead;\r\n  _seqOutStream.SeqOutStream.Write = MyWrite;\r\n  _encoder = 0;\r\n  _encoder = LzmaEnc_Create(&g_Alloc);\r\n  if (_encoder == 0)\r\n    throw 1;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  if (_encoder != 0)\r\n    LzmaEnc_Destroy(_encoder, &g_Alloc, &g_BigAlloc);\r\n}\r\n\r\ninline wchar_t GetUpperChar(wchar_t c)\r\n{\r\n  if (c >= 'a' && c <= 'z')\r\n    c -= 0x20;\r\n  return c;\r\n}\r\n\r\nstatic int ParseMatchFinder(const wchar_t *s, int *btMode, int *numHashBytes)\r\n{\r\n  wchar_t c = GetUpperChar(*s++);\r\n  if (c == L'H')\r\n  {\r\n    if (GetUpperChar(*s++) != L'C')\r\n      return 0;\r\n    int numHashBytesLoc = (int)(*s++ - L'0');\r\n    if (numHashBytesLoc < 4 || numHashBytesLoc > 4)\r\n      return 0;\r\n    if (*s++ != 0)\r\n      return 0;\r\n    *btMode = 0;\r\n    *numHashBytes = numHashBytesLoc;\r\n    return 1;\r\n  }\r\n  if (c != L'B')\r\n    return 0;\r\n\r\n  if (GetUpperChar(*s++) != L'T')\r\n    return 0;\r\n  int numHashBytesLoc = (int)(*s++ - L'0');\r\n  if (numHashBytesLoc < 2 || numHashBytesLoc > 4)\r\n    return 0;\r\n  c = GetUpperChar(*s++);\r\n  if (c != L'\\0')\r\n    return 0;\r\n  *btMode = 1;\r\n  *numHashBytes = numHashBytesLoc;\r\n  return 1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,\r\n    const PROPVARIANT *coderProps, UInt32 numProps)\r\n{\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    const PROPVARIANT &prop = coderProps[i];\r\n    switch (propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.fb = prop.ulVal; break;\r\n      case NCoderPropID::kMatchFinderCycles:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.mc = prop.ulVal; break;\r\n      case NCoderPropID::kAlgorithm:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.algo = prop.ulVal; break;\r\n      case NCoderPropID::kDictionarySize:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.dictSize = prop.ulVal; break;\r\n      case NCoderPropID::kPosStateBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.pb = prop.ulVal; break;\r\n      case NCoderPropID::kLitPosBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lp = prop.ulVal; break;\r\n      case NCoderPropID::kLitContextBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lc = prop.ulVal; break;\r\n      case NCoderPropID::kNumThreads:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.numThreads = prop.ulVal; break;\r\n      case NCoderPropID::kMultiThread:\r\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.numThreads = ((prop.boolVal == VARIANT_TRUE) ? 2 : 1); break;\r\n      case NCoderPropID::kEndMarker:\r\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.writeEndMark = (prop.boolVal == VARIANT_TRUE); break;\r\n      case NCoderPropID::kMatchFinder:\r\n        if (prop.vt != VT_BSTR) return E_INVALIDARG;\r\n        if (!ParseMatchFinder(prop.bstrVal, &props.btMode, &props.numHashBytes /* , &_matchFinderBase.skipModeBits */))\r\n          return E_INVALIDARG; break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return SResToHRESULT(LzmaEnc_SetProps(_encoder, &props));\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  Byte props[LZMA_PROPS_SIZE];\r\n  size_t size = LZMA_PROPS_SIZE;\r\n  RINOK(LzmaEnc_WriteProperties(_encoder, props, &size));\r\n  return WriteStream(outStream, props, size);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _seqOutStream.RealStream = outStream;\r\n  _seqOutStream.Res = S_OK;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _seqOutStream.RealStream.Release();\r\n  return S_OK;\r\n}\r\n\r\ntypedef struct _CCompressProgressImp\r\n{\r\n  ICompressProgress p;\r\n  ICompressProgressInfo *Progress;\r\n  HRESULT Res;\r\n} CCompressProgressImp;\r\n\r\n#define PROGRESS_UNKNOWN_VALUE ((UInt64)(Int64)-1)\r\n\r\n#define CONVERT_PR_VAL(x) (x == PROGRESS_UNKNOWN_VALUE ? NULL : &x)\r\n\r\nSRes CompressProgress(void *pp, UInt64 inSize, UInt64 outSize)\r\n{\r\n  CCompressProgressImp *p = (CCompressProgressImp *)pp;\r\n  p->Res = p->Progress->SetRatioInfo(CONVERT_PR_VAL(inSize), CONVERT_PR_VAL(outSize));\r\n  return (SRes)p->Res;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)\r\n{\r\n  CCompressProgressImp progressImp;\r\n  progressImp.p.Progress = CompressProgress;\r\n  progressImp.Progress = progress;\r\n  progressImp.Res = SZ_OK;\r\n\r\n  _seqInStream.RealStream = inStream;\r\n  SetOutStream(outStream);\r\n  SRes res = LzmaEnc_Encode(_encoder, &_seqOutStream.SeqOutStream, &_seqInStream.SeqInStream, progress ? &progressImp.p : NULL, &g_Alloc, &g_BigAlloc);\r\n  ReleaseOutStream();\r\n  if (res == SZ_ERROR_WRITE && _seqOutStream.Res != S_OK)\r\n    return _seqOutStream.Res;\r\n  if (res == SZ_ERROR_PROGRESS && progressImp.Res != S_OK)\r\n    return progressImp.Res;\r\n  return SResToHRESULT(res);\r\n}\r\n  \r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LzmaEncoder.h",
    "content": "// LzmaEncoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/LzmaEnc.h\"\r\n}\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstruct CSeqInStream\r\n{\r\n  ISeqInStream SeqInStream;\r\n  ISequentialInStream *RealStream;\r\n};\r\n\r\nstruct CSeqOutStream\r\n{\r\n  ISeqOutStream SeqOutStream;\r\n  CMyComPtr<ISequentialOutStream> RealStream;\r\n  HRESULT Res;\r\n};\r\n\r\nclass CEncoder :\r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CMyUnknownImp\r\n{\r\n  CLzmaEncHandle _encoder;\r\n \r\n  CSeqInStream _seqInStream;\r\n  CSeqOutStream _seqOutStream;\r\n\r\npublic:\r\n  CEncoder();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/LzmaRegister.cpp",
    "content": "// LzmaRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"LzmaDecoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CDecoder); }\r\n#ifndef EXTRACT_ONLY\r\n#include \"LzmaEncoder.h\"\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CEncoder);  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x030101, L\"LZMA\", 1, false };\r\n\r\nREGISTER_CODEC(LZMA)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/RangeCoder.h",
    "content": "// Compress/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGE_CODER_H\r\n#define __COMPRESS_RANGE_CODER_H\r\n\r\n#include \"../Common/InBuffer.h\"\r\n#include \"../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1;\r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)\r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);\r\n    }\r\n    _cacheSize++;\r\n    Low = (UInt32)Low << 8;\r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numBits)\r\n  {\r\n    for (numBits--; numBits >= 0; numBits--)\r\n    {\r\n      Range >>= 1;\r\n      Low += Range & (0 - ((value >> numBits) & 1));\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;\r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8;\r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/RangeCoderBit.h",
    "content": "// Compress/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGE_CODER_BIT_H\r\n#define __COMPRESS_RANGE_CODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 4;\r\n\r\nconst int kNumBitPriceShiftBits = 4;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nextern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/Compress/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize,\r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kBlockSize,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kMatchFinderCycles,\r\n    kNumPasses = 0x460,\r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kNumThreads,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetCoderMt, 0x25)\r\n{\r\n  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block\r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICompressCodecsInfo, 0x60)\r\n{\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n};\r\nCODER_INTERFACE(ISetCompressCodecsInfo, 0x61)\r\n{\r\n  STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICryptoResetSalt, 0x88)\r\n{\r\n  STDMETHOD(ResetSalt)() PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICryptoResetInitVector, 0x8C)\r\n{\r\n  STDMETHOD(ResetInitVector)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription,\r\n    kDecoderIsAssigned,\r\n    kEncoderIsAssigned\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/IDecl.h",
    "content": "// IDecl.h\r\n\r\n#ifndef __IDECL_H\r\n#define __IDECL_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n\r\n#define DECL_INTERFACE_SUB(i, base, groupId, subId) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \\\r\nstruct i: public base\r\n\r\n#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/IPassword.h",
    "content": "// IPassword.h\r\n\r\n#ifndef __IPASSWORD_H\r\n#define __IPASSWORD_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;\r\n};\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;\r\n};\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/IProgress.h",
    "content": "// Interface/IProgress.h\r\n\r\n#ifndef __IPROGRESS_H\r\n#define __IPROGRESS_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define INTERFACE_IProgress(x) \\\r\n  STDMETHOD(SetTotal)(UInt64 total) x; \\\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) x; \\\r\n\r\nDECL_INTERFACE(IProgress, 0, 5)\r\n{\r\n  INTERFACE_IProgress(PURE)\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000000050002}\r\nDEFINE_GUID(IID_IProgress2,\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000050002\")\r\nIProgress2: public IUnknown\r\n{\r\npublic:\r\n  STDMETHOD(SetTotal)(const UInt64 *total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream,\r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/MyVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 65\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.65\"\r\n#define MY_7ZIP_VERSION \"7-Zip 4.65\"\r\n#define MY_DATE \"2009-02-03\"\r\n#define MY_COPYRIGHT \"Copyright (c) 1999-2009 Igor Pavlov\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \"  \" MY_COPYRIGHT \"  \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/MyVersionInfo.rc",
    "content": "#include <WinVer.h>\r\n#include \"MyVersion.h\"\r\n\r\n#define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0\r\n\r\n#ifdef DEBUG\r\n#define DBG_FL VS_FF_DEBUG\r\n#else\r\n#define DBG_FL 0\r\n#endif\r\n\r\n#define MY_VERSION_INFO(fileType, descr, intName, origName)  \\\r\nLANGUAGE 9, 1 \\\r\n1 VERSIONINFO \\\r\n  FILEVERSION MY_VER \\\r\n  PRODUCTVERSION MY_VER \\\r\n  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK \\\r\n  FILEFLAGS DBG_FL \\\r\n  FILEOS VOS_NT_WINDOWS32 \\\r\n  FILETYPE fileType \\\r\n  FILESUBTYPE 0x0L \\\r\nBEGIN \\\r\n    BLOCK \"StringFileInfo\" \\\r\n    BEGIN  \\\r\n        BLOCK \"040904b0\" \\\r\n        BEGIN \\\r\n            VALUE \"CompanyName\", \"Igor Pavlov\" \\\r\n            VALUE \"FileDescription\", descr \\\r\n            VALUE \"FileVersion\", MY_VERSION  \\\r\n            VALUE \"InternalName\", intName \\\r\n            VALUE \"LegalCopyright\", MY_COPYRIGHT \\\r\n            VALUE \"OriginalFilename\", origName \\\r\n            VALUE \"ProductName\", \"7-Zip\" \\\r\n            VALUE \"ProductVersion\", MY_VERSION \\\r\n        END \\\r\n    END \\\r\n    BLOCK \"VarFileInfo\" \\\r\n    BEGIN \\\r\n        VALUE \"Translation\", 0x409, 1200 \\\r\n    END \\\r\nEND\r\n\r\n#define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(VFT_APP, descr, intName, intName \".exe\")\r\n\r\n#define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(VFT_DLL, descr, intName, intName \".dll\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/PropID.h",
    "content": "// PropID.h\r\n\r\n#ifndef __7ZIP_PROPID_H\r\n#define __7ZIP_PROPID_H\r\n\r\nenum\r\n{\r\n  kpidNoProperty = 0,\r\n  \r\n  kpidHandlerItemIndex = 2,\r\n  kpidPath,\r\n  kpidName,\r\n  kpidExtension,\r\n  kpidIsDir,\r\n  kpidSize,\r\n  kpidPackSize,\r\n  kpidAttrib,\r\n  kpidCTime,\r\n  kpidATime,\r\n  kpidMTime,\r\n  kpidSolid,\r\n  kpidCommented,\r\n  kpidEncrypted,\r\n  kpidSplitBefore,\r\n  kpidSplitAfter,\r\n  kpidDictionarySize,\r\n  kpidCRC,\r\n  kpidType,\r\n  kpidIsAnti,\r\n  kpidMethod,\r\n  kpidHostOS,\r\n  kpidFileSystem,\r\n  kpidUser,\r\n  kpidGroup,\r\n  kpidBlock,\r\n  kpidComment,\r\n  kpidPosition,\r\n  kpidPrefix,\r\n  kpidNumSubDirs,\r\n  kpidNumSubFiles,\r\n  kpidUnpackVer,\r\n  kpidVolume,\r\n  kpidIsVolume,\r\n  kpidOffset,\r\n  kpidLinks,\r\n  kpidNumBlocks,\r\n  kpidNumVolumes,\r\n  kpidTimeType,\r\n  kpidBit64,\r\n  kpidBigEndian,\r\n  kpidCpu,\r\n  kpidPhySize,\r\n  kpidHeadersSize,\r\n  kpidChecksum,\r\n  kpidCharacts,\r\n  kpidVa,\r\n\r\n  kpidTotalSize = 0x1100,\r\n  kpidFreeSpace,\r\n  kpidClusterSize,\r\n  kpidVolumeName,\r\n\r\n  kpidLocalName = 0x1200,\r\n  kpidProvider,\r\n\r\n  kpidUserDefined = 0x10000\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Client7z/Client7z.cpp",
    "content": "// Client7z.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyInitGuid.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/DLL.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../MyVersion.h\"\r\n\r\n// use another CLSIDs, if you want to support other formats (zip, rar, ...).\r\n// {23170F69-40C1-278A-1000-000110070000}\r\nDEFINE_GUID(CLSID_CFormat7z,\r\n  0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);\r\n\r\nusing namespace NWindows;\r\n\r\n#define kDllName \"7z.dll\"\r\n\r\nstatic const char *kCopyrightString = MY_7ZIP_VERSION\r\n\" (\"  kDllName \" client) \"\r\nMY_COPYRIGHT \" \" MY_DATE;\r\n\r\nstatic const char *kHelpString =\r\n\"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\\n\"\r\n\"Examples:\\n\"\r\n\"  Client7z.exe a archive.7z f1.txt f2.txt  : compress two files to archive.7z\\n\"\r\n\"  Client7z.exe l archive.7z   : List contents of archive.7z\\n\"\r\n\"  Client7z.exe x archive.7z   : eXtract files from archive.7z\\n\";\r\n\r\n\r\ntypedef UINT32 (WINAPI * CreateObjectFunc)(\r\n    const GUID *clsID,\r\n    const GUID *interfaceID,\r\n    void **outObject);\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nvoid PrintString(const UString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)GetOemString(s));\r\n}\r\n\r\nvoid PrintString(const AString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)s);\r\n}\r\n\r\nvoid PrintNewLine()\r\n{\r\n  PrintString(\"\\n\");\r\n}\r\n\r\nvoid PrintStringLn(const AString &s)\r\n{\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nvoid PrintError(const AString &s)\r\n{\r\n  PrintNewLine();\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nstatic HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\r\n}\r\n\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Open callback class\r\n\r\n\r\nclass CArchiveOpenCallback:\r\n  public IArchiveOpenCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveOpenCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream);\r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Extracting callback class\r\n\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCRCFailed = \"CRC Failed\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nclass CArchiveExtractCallback:\r\n  public IArchiveExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IArchiveExtractCallback\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  UString _directoryPath;  // Output directory\r\n  UString _filePath;       // name inside arcvhive\r\n  UString _diskFilePath;   // full path to file on disk\r\n  bool _extractMode;\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME MTime;\r\n    UInt32 Attrib;\r\n    bool isDir;\r\n    bool AttribDefined;\r\n    bool MTimeDefined;\r\n  } _processedFileInfo;\r\n\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n\r\npublic:\r\n  void Init(IInArchive *archiveHandler, const UString &directoryPath);\r\n\r\n  UInt64 NumErrors;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveExtractCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nvoid CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)\r\n{\r\n  NumErrors = 0;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,\r\n    ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  {\r\n    // Get Name\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));\r\n    \r\n    UString fullPath;\r\n    if (prop.vt == VT_EMPTY)\r\n      fullPath = kEmptyFileAlias;\r\n    else\r\n    {\r\n      if (prop.vt != VT_BSTR)\r\n        return E_FAIL;\r\n      fullPath = prop.bstrVal;\r\n    }\r\n    _filePath = fullPath;\r\n  }\r\n\r\n  if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)\r\n    return S_OK;\r\n\r\n  {\r\n    // Get Attrib\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\r\n    if (prop.vt == VT_EMPTY)\r\n    {\r\n      _processedFileInfo.Attrib = 0;\r\n      _processedFileInfo.AttribDefined = false;\r\n    }\r\n    else\r\n    {\r\n      if (prop.vt != VT_UI4)\r\n        return E_FAIL;\r\n      _processedFileInfo.Attrib = prop.ulVal;\r\n      _processedFileInfo.AttribDefined = true;\r\n    }\r\n  }\r\n\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir));\r\n\r\n  {\r\n    // Get Modified Time\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));\r\n    _processedFileInfo.MTimeDefined = false;\r\n    switch(prop.vt)\r\n    {\r\n      case VT_EMPTY:\r\n        // _processedFileInfo.MTime = _utcMTimeDefault;\r\n        break;\r\n      case VT_FILETIME:\r\n        _processedFileInfo.MTime = prop.filetime;\r\n        _processedFileInfo.MTimeDefined = true;\r\n        break;\r\n      default:\r\n        return E_FAIL;\r\n    }\r\n\r\n  }\r\n  {\r\n    // Get Size\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    bool newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    UInt64 newFileSize;\r\n    if (newFileSizeDefined)\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n  }\r\n\r\n  \r\n  {\r\n    // Create folders for file\r\n    int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (slashPos >= 0)\r\n      NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));\r\n  }\r\n\r\n  UString fullProcessedPath = _directoryPath + _filePath;\r\n  _diskFilePath = fullProcessedPath;\r\n\r\n  if (_processedFileInfo.isDir)\r\n  {\r\n    NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (NFile::NFind::FindFile(fullProcessedPath, fi))\r\n    {\r\n      if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n      {\r\n        PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath);\r\n        return E_ABORT;\r\n      }\r\n    }\r\n    \r\n    _outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n    if (!_outFileStreamSpec->Open(fullProcessedPath, CREATE_ALWAYS))\r\n    {\r\n      PrintString((UString)L\"can not open output file \" + fullProcessedPath);\r\n      return E_ABORT;\r\n    }\r\n    _outFileStream = outStreamLoc;\r\n    *outStream = outStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:  _extractMode = true; break;\r\n  };\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:  PrintString(kExtractingString); break;\r\n    case NArchive::NExtract::NAskMode::kTest:  PrintString(kTestingString); break;\r\n    case NArchive::NExtract::NAskMode::kSkip:  PrintString(kSkippingString); break;\r\n  };\r\n  PrintString(_filePath);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumErrors++;\r\n      PrintString(\"     \");\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          PrintString(kUnsupportedMethod);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          PrintString(kCRCFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          PrintString(kDataError);\r\n          break;\r\n        default:\r\n          PrintString(kUnknownError);\r\n      }\r\n    }\r\n  }\r\n\r\n  if (_outFileStream != NULL)\r\n  {\r\n    if (_processedFileInfo.MTimeDefined)\r\n      _outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);\r\n    RINOK(_outFileStreamSpec->Close());\r\n  }\r\n  _outFileStream.Release();\r\n  if (_extractMode && _processedFileInfo.AttribDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);\r\n  PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream);\r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Creating callback class\r\n\r\nstruct CDirItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  UString FullPath;\r\n  UInt32 Attrib;\r\n\r\n  bool isDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CArchiveUpdateCallback:\r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IUpdateCallback2\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,\r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  UString DirPrefix;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n  bool m_NeedBeClosed;\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {};\r\n\r\n  ~CArchiveUpdateCallback() { Finilize(); }\r\n  HRESULT Finilize();\r\n\r\n  void Init(const CObjectVector<CDirItem> *dirItems)\r\n  {\r\n    DirItems = dirItems;\r\n    m_NeedBeClosed = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */,\r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  if (newData != NULL)\r\n    *newData = BoolToInt(true);\r\n  if (newProperties != NULL)\r\n    *newProperties = BoolToInt(true);\r\n  if (indexInArchive != NULL)\r\n    *indexInArchive = (UInt32)-1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    prop = false;\r\n    prop.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[index];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:  prop = dirItem.Name; break;\r\n      case kpidIsDir:  prop = dirItem.isDir(); break;\r\n      case kpidSize:  prop = dirItem.Size; break;\r\n      case kpidAttrib:  prop = dirItem.Attrib; break;\r\n      case kpidCTime:  prop = dirItem.CTime; break;\r\n      case kpidATime:  prop = dirItem.ATime; break;\r\n      case kpidMTime:  prop = dirItem.MTime; break;\r\n    }\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveUpdateCallback::Finilize()\r\n{\r\n  if (m_NeedBeClosed)\r\n  {\r\n    PrintNewLine();\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void GetStream2(const wchar_t *name)\r\n{\r\n  PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  PrintString(name);\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  RINOK(Finilize());\r\n\r\n  const CDirItem &dirItem = (*DirItems)[index];\r\n  GetStream2(dirItem.Name);\r\n \r\n  if (dirItem.isDir())\r\n    return S_OK;\r\n\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if (!inStreamSpec->Open(path))\r\n    {\r\n      DWORD sysError = ::GetLastError();\r\n      FailedCodes.Add(sysError);\r\n      FailedFiles.Add(path);\r\n      // if (systemError == ERROR_SHARING_VIOLATION)\r\n      {\r\n        PrintNewLine();\r\n        PrintError(\"WARNING: can't open file\");\r\n        // PrintString(NError::MyFormatMessageW(systemError));\r\n        return S_FALSE;\r\n      }\r\n      // return sysError;\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */)\r\n{\r\n  m_NeedBeClosed = true;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if (!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    if (AskPassword)\r\n    {\r\n      // You can ask real password here from user\r\n      // Password = GetPassword(OutStream);\r\n      // PasswordIsDefined = true;\r\n      PrintError(\"Password is not defined\");\r\n      return E_ABORT;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////////////////\r\n// Main function\r\n\r\nint MY_CDECL main(int argc, char* argv[])\r\n{\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  #endif\r\n\r\n  PrintStringLn(kCopyrightString);\r\n\r\n  if (argc < 3)\r\n  {\r\n    PrintStringLn(kHelpString);\r\n    return 1;\r\n  }\r\n  NWindows::NDLL::CLibrary library;\r\n  if (!library.Load(TEXT(kDllName)))\r\n  {\r\n    PrintError(\"Can not load library\");\r\n    return 1;\r\n  }\r\n  CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress(\"CreateObject\");\r\n  if (createObjectFunc == 0)\r\n  {\r\n    PrintError(\"Can not get CreateObject\");\r\n    return 1;\r\n  }\r\n\r\n  AString command = argv[1];\r\n  command.MakeLower();\r\n  UString archiveName = GetUnicodeString(argv[2], CP_OEMCP);\r\n  if (command.Compare(\"a\") == 0)\r\n  {\r\n    // create archive command\r\n    if (argc < 4)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n    CObjectVector<CDirItem> dirItems;\r\n    int i;\r\n    for (i = 3; i < argc; i++)\r\n    {\r\n      CDirItem di;\r\n      UString name = GetUnicodeString(argv[i], CP_OEMCP);\r\n      \r\n      NFile::NFind::CFileInfoW fi;\r\n      if (!NFile::NFind::FindFile(name, fi))\r\n      {\r\n        PrintString(UString(L\"Can't find file\") + name);\r\n        return 1;\r\n      }\r\n\r\n      di.Attrib = fi.Attrib;\r\n      di.Size = fi.Size;\r\n      di.CTime = fi.CTime;\r\n      di.ATime = fi.ATime;\r\n      di.MTime = fi.MTime;\r\n      di.Name = name;\r\n      di.FullPath = name;\r\n      dirItems.Add(di);\r\n    }\r\n    COutFileStream *outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;\r\n    if (!outFileStreamSpec->Create(archiveName, false))\r\n    {\r\n      PrintError(\"can't create archive file\");\r\n      return 1;\r\n    }\r\n\r\n    CMyComPtr<IOutArchive> outArchive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n\r\n    CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n    CMyComPtr<IArchiveUpdateCallback2> updateCallback(updateCallbackSpec);\r\n    updateCallbackSpec->Init(&dirItems);\r\n    // updateCallbackSpec->PasswordIsDefined = true;\r\n    // updateCallbackSpec->Password = L\"1\";\r\n\r\n    HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);\r\n    updateCallbackSpec->Finilize();\r\n    if (result != S_OK)\r\n    {\r\n      PrintError(\"Update Error\");\r\n      return 1;\r\n    }\r\n    for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)\r\n    {\r\n      PrintNewLine();\r\n      PrintString((UString)L\"Error for file: \" + updateCallbackSpec->FailedFiles[i]);\r\n    }\r\n    if (updateCallbackSpec->FailedFiles.Size() != 0)\r\n      return 1;\r\n  }\r\n  else\r\n  {\r\n    if (argc != 3)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n\r\n    bool listCommand;\r\n    if (command.Compare(\"l\") == 0)\r\n      listCommand = true;\r\n    else if (command.Compare(\"x\") == 0)\r\n      listCommand = false;\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      return 1;\r\n    }\r\n  \r\n    CMyComPtr<IInArchive> archive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n    \r\n    CInFileStream *fileSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> file = fileSpec;\r\n    \r\n    if (!fileSpec->Open(archiveName))\r\n    {\r\n      PrintError(\"Can not open archive file\");\r\n      return 1;\r\n    }\r\n\r\n    {\r\n      CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;\r\n      CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);\r\n      openCallbackSpec->PasswordIsDefined = false;\r\n      // openCallbackSpec->PasswordIsDefined = true;\r\n      // openCallbackSpec->Password = L\"1\";\r\n      \r\n      if (archive->Open(file, 0, openCallback) != S_OK)\r\n      {\r\n        PrintError(\"Can not open archive\");\r\n        return 1;\r\n      }\r\n    }\r\n    \r\n    if (listCommand)\r\n    {\r\n      // List command\r\n      UInt32 numItems = 0;\r\n      archive->GetNumberOfItems(&numItems);\r\n      for (UInt32 i = 0; i < numItems; i++)\r\n      {\r\n        {\r\n          // Get uncompressed size of file\r\n          NWindows::NCOM::CPropVariant prop;\r\n          archive->GetProperty(i, kpidSize, &prop);\r\n          UString s = ConvertPropVariantToString(prop);\r\n          PrintString(s);\r\n          PrintString(\"  \");\r\n        }\r\n        {\r\n          // Get name of file\r\n          NWindows::NCOM::CPropVariant prop;\r\n          archive->GetProperty(i, kpidPath, &prop);\r\n          UString s = ConvertPropVariantToString(prop);\r\n          PrintString(s);\r\n        }\r\n        PrintString(\"\\n\");\r\n      }\r\n    }\r\n    else\r\n    {\r\n      // Extract command\r\n      CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n      CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);\r\n      extractCallbackSpec->Init(archive, L\"\"); // second parameter is output folder path\r\n      extractCallbackSpec->PasswordIsDefined = false;\r\n      // extractCallbackSpec->PasswordIsDefined = true;\r\n      // extractCallbackSpec->Password = L\"1\";\r\n      HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);\r\n      if (result != S_OK)\r\n      {\r\n        PrintError(\"Extract Error\");\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Client7z/Client7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Client7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Client7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\" CFG=\"Client7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Client7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Client7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Client7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Client7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Client7z - Win32 Release\"\r\n# Name \"Client7z - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"stdafx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\Client7z.cpp\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Client7z/Client7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Client7z\"=.\\Client7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Client7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Client7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include <windows.h>\r\n#include <stdio.h>\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Client7z/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\Client7z.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FileStreams.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp",
    "content": "// ArchiveCommandLine.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <io.h>\r\n#endif\r\n#include <stdio.h>\r\n\r\n#include \"Common/ListFileUtils.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/FileMapping.h\"\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ArchiveCommandLine.h\"\r\n#include \"UpdateAction.h\"\r\n#include \"Update.h\"\r\n#include \"SortUtils.h\"\r\n#include \"EnumDirItems.h\"\r\n\r\nextern bool g_CaseSensitive;\r\n\r\n#if _MSC_VER >= 1400\r\n#define MY_isatty_fileno(x) _isatty(_fileno(x))\r\n#else\r\n#define MY_isatty_fileno(x) isatty(fileno(x))\r\n#endif\r\n\r\n#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);\r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kHelp3,\r\n  kDisableHeaders,\r\n  kDisablePercents,\r\n  kArchiveType,\r\n  kYes,\r\n  #ifndef _NO_CRYPTO\r\n  kPassword,\r\n  #endif\r\n  kProperty,\r\n  kOutputDir,\r\n  kWorkingDir,\r\n  kInclude,\r\n  kExclude,\r\n  kArInclude,\r\n  kArExclude,\r\n  kNoArName,\r\n  kUpdate,\r\n  kVolume,\r\n  kRecursed,\r\n  kSfx,\r\n  kStdIn,\r\n  kStdOut,\r\n  kOverwrite,\r\n  kEmail,\r\n  kShowDialog,\r\n  kLargePages,\r\n  kCharSet,\r\n  kTechMode,\r\n  kShareForWrite,\r\n  kCaseSensitive\r\n};\r\n\r\n}\r\n\r\n\r\nstatic const wchar_t kRecursedIDChar = 'R';\r\nstatic const wchar_t *kRecursedPostCharSet = L\"0-\";\r\n\r\nnamespace NRecursedPostCharIndex {\r\n  enum EEnum\r\n  {\r\n    kWildCardRecursionOnly = 0,\r\n    kNoRecursion = 1\r\n  };\r\n}\r\n\r\nstatic const char kImmediateNameID = '!';\r\nstatic const char kMapNameID = '#';\r\nstatic const char kFileListID = '@';\r\n\r\nstatic const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be\r\nstatic const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be\r\n\r\nstatic const wchar_t *kOverwritePostCharSet = L\"asut\";\r\n\r\nNExtract::NOverwriteMode::EEnum k_OverwriteModes[] =\r\n{\r\n  NExtract::NOverwriteMode::kWithoutPrompt,\r\n  NExtract::NOverwriteMode::kSkipExisting,\r\n  NExtract::NOverwriteMode::kAutoRename,\r\n  NExtract::NOverwriteMode::kAutoRenameExisting\r\n};\r\n\r\nstatic const CSwitchForm kSwitchForms[] =\r\n  {\r\n    { L\"?\",  NSwitchType::kSimple, false },\r\n    { L\"H\",  NSwitchType::kSimple, false },\r\n    { L\"-HELP\",  NSwitchType::kSimple, false },\r\n    { L\"BA\", NSwitchType::kSimple, false },\r\n    { L\"BD\", NSwitchType::kSimple, false },\r\n    { L\"T\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"Y\",  NSwitchType::kSimple, false },\r\n    #ifndef _NO_CRYPTO\r\n    { L\"P\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    #endif\r\n    { L\"M\",  NSwitchType::kUnLimitedPostString, true, 1 },\r\n    { L\"O\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"W\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"I\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"X\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AI\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AX\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AN\", NSwitchType::kSimple, false },\r\n    { L\"U\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"V\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"R\",  NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },\r\n    { L\"SFX\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SI\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SO\", NSwitchType::kSimple, false, 0 },\r\n    { L\"AO\", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},\r\n    { L\"SEML\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"AD\",  NSwitchType::kSimple, false },\r\n    { L\"SLP\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SCS\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SLT\", NSwitchType::kSimple, false },\r\n    { L\"SSW\", NSwitchType::kSimple, false },\r\n    { L\"SSC\", NSwitchType::kPostChar, false, 0, 0, L\"-\" }\r\n  };\r\n\r\nstatic const CCommandForm g_CommandForms[] =\r\n{\r\n  { L\"A\", false },\r\n  { L\"U\", false },\r\n  { L\"D\", false },\r\n  { L\"T\", false },\r\n  { L\"E\", false },\r\n  { L\"X\", false },\r\n  { L\"L\", false },\r\n  { L\"B\", false },\r\n  { L\"I\", false }\r\n};\r\n\r\nstatic const int kNumCommandForms = sizeof(g_CommandForms) /  sizeof(g_CommandForms[0]);\r\n\r\nstatic const wchar_t *kUniversalWildcard = L\"*\";\r\nstatic const int kMinNonSwitchWords = 1;\r\nstatic const int kCommandIndex = 0;\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\";\r\nstatic const char *kIncorrectListFile = \"Incorrect item in listfile.\\nCheck charset encoding and -scs switch.\";\r\nstatic const char *kIncorrectWildCardInListFile = \"Incorrect wildcard in listfile\";\r\nstatic const char *kIncorrectWildCardInCommandLine  = \"Incorrect wildcard in command line\";\r\nstatic const char *kTerminalOutError = \"I won't write compressed data to a terminal\";\r\nstatic const char *kSameTerminalError = \"I won't write data and program's messages to same terminal\";\r\n\r\nstatic void ThrowException(const char *errorMessage)\r\n{\r\n  throw CArchiveCommandLineException(errorMessage);\r\n};\r\n\r\nstatic void ThrowUserErrorException()\r\n{\r\n  ThrowException(kUserErrorMessage);\r\n};\r\n\r\n// ---------------------------\r\n\r\nbool CArchiveCommand::IsFromExtractGroup() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kExtract:\r\n    case NCommandType::kFullExtract:\r\n      return true;\r\n    default:\r\n      return false;\r\n  }\r\n}\r\n\r\nNExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kFullExtract:\r\n      return NExtract::NPathMode::kFullPathnames;\r\n    default:\r\n      return NExtract::NPathMode::kNoPathnames;\r\n  }\r\n}\r\n\r\nbool CArchiveCommand::IsFromUpdateGroup() const\r\n{\r\n  return (CommandType == NCommandType::kAdd ||\r\n    CommandType == NCommandType::kUpdate ||\r\n    CommandType == NCommandType::kDelete);\r\n}\r\n\r\nstatic NRecursedType::EEnum GetRecursedTypeFromIndex(int index)\r\n{\r\n  switch (index)\r\n  {\r\n    case NRecursedPostCharIndex::kWildCardRecursionOnly:\r\n      return NRecursedType::kWildCardOnlyRecursed;\r\n    case NRecursedPostCharIndex::kNoRecursion:\r\n      return NRecursedType::kNonRecursed;\r\n    default:\r\n      return NRecursedType::kRecursed;\r\n  }\r\n}\r\n\r\nstatic bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)\r\n{\r\n  UString commandStringUpper = commandString;\r\n  commandStringUpper.MakeUpper();\r\n  UString postString;\r\n  int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper,\r\n      postString) ;\r\n  if (commandIndex < 0)\r\n    return false;\r\n  command.CommandType = (NCommandType::EEnum)commandIndex;\r\n  return true;\r\n}\r\n\r\n// ------------------------------------------------------------------\r\n// filenames functions\r\n\r\nstatic bool AddNameToCensor(NWildcard::CCensor &wildcardCensor,\r\n    const UString &name, bool include, NRecursedType::EEnum type)\r\n{\r\n  bool isWildCard = DoesNameContainWildCard(name);\r\n  bool recursed = false;\r\n\r\n  switch (type)\r\n  {\r\n    case NRecursedType::kWildCardOnlyRecursed:\r\n      recursed = isWildCard;\r\n      break;\r\n    case NRecursedType::kRecursed:\r\n      recursed = true;\r\n      break;\r\n    case NRecursedType::kNonRecursed:\r\n      recursed = false;\r\n      break;\r\n  }\r\n  wildcardCensor.AddItem(include, name, recursed);\r\n  return true;\r\n}\r\n\r\nstatic void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,\r\n    LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)\r\n{\r\n  UStringVector names;\r\n  if (!ReadNamesFromListFile(fileName, names, codePage))\r\n    throw kIncorrectListFile;\r\n  for (int i = 0; i < names.Size(); i++)\r\n    if (!AddNameToCensor(wildcardCensor, names[i], include, type))\r\n      throw kIncorrectWildCardInListFile;\r\n}\r\n\r\nstatic void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor,\r\n    const UString &name, bool include, NRecursedType::EEnum recursedType)\r\n{\r\n  if (!AddNameToCensor(wildcardCensor, name, include, recursedType))\r\n    throw kIncorrectWildCardInCommandLine;\r\n}\r\n\r\nstatic void AddToCensorFromNonSwitchesStrings(\r\n    int startIndex,\r\n    NWildcard::CCensor &wildcardCensor,\r\n    const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,\r\n    bool thereAreSwitchIncludes, UINT codePage)\r\n{\r\n  if (nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes))\r\n    AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);\r\n  for (int i = startIndex; i < nonSwitchStrings.Size(); i++)\r\n  {\r\n    const UString &s = nonSwitchStrings[i];\r\n    if (s[0] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);\r\n    else\r\n      AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor,\r\n    const UString &switchParam, bool include,\r\n    NRecursedType::EEnum commonRecursedType)\r\n{\r\n  int splitPos = switchParam.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  UString mappingName = switchParam.Left(splitPos);\r\n  \r\n  UString switchParam2 = switchParam.Mid(splitPos + 1);\r\n  splitPos = switchParam2.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  \r\n  UString mappingSize = switchParam2.Left(splitPos);\r\n  UString eventName = switchParam2.Mid(splitPos + 1);\r\n  \r\n  UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);\r\n  UInt32 dataSize = (UInt32)dataSize64;\r\n  {\r\n    CFileMapping fileMapping;\r\n    if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName)))\r\n      ThrowException(\"Can not open mapping\");\r\n    LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize);\r\n    if (data == NULL)\r\n      ThrowException(\"MapViewOfFile error\");\r\n    try\r\n    {\r\n      const wchar_t *curData = (const wchar_t *)data;\r\n      if (*curData != 0)\r\n        ThrowException(\"Incorrect mapping data\");\r\n      UInt32 numChars = dataSize / sizeof(wchar_t);\r\n      UString name;\r\n      for (UInt32 i = 1; i < numChars; i++)\r\n      {\r\n        wchar_t c = curData[i];\r\n        if (c == L'\\0')\r\n        {\r\n          AddCommandLineWildCardToCensr(wildcardCensor,\r\n              name, include, commonRecursedType);\r\n          name.Empty();\r\n        }\r\n        else\r\n          name += c;\r\n      }\r\n      if (!name.IsEmpty())\r\n        ThrowException(\"data error\");\r\n    }\r\n    catch(...)\r\n    {\r\n      UnmapViewOfFile(data);\r\n      throw;\r\n    }\r\n    UnmapViewOfFile(data);\r\n  }\r\n  \r\n  {\r\n    NSynchronization::CManualResetEvent event;\r\n    if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)\r\n      event.Set();\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,\r\n    const UStringVector &strings, bool include,\r\n    NRecursedType::EEnum commonRecursedType, UINT codePage)\r\n{\r\n  for (int i = 0; i < strings.Size(); i++)\r\n  {\r\n    const UString &name = strings[i];\r\n    NRecursedType::EEnum recursedType;\r\n    int pos = 0;\r\n    if (name.Length() < kSomeCludePostStringMinSize)\r\n      ThrowUserErrorException();\r\n    if (::MyCharUpper(name[pos]) == kRecursedIDChar)\r\n    {\r\n      pos++;\r\n      int index = UString(kRecursedPostCharSet).Find(name[pos]);\r\n      recursedType = GetRecursedTypeFromIndex(index);\r\n      if (index >= 0)\r\n        pos++;\r\n    }\r\n    else\r\n      recursedType = commonRecursedType;\r\n    if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)\r\n      ThrowUserErrorException();\r\n    UString tail = name.Mid(pos + 1);\r\n    if (name[pos] == kImmediateNameID)\r\n      AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);\r\n    else if (name[pos] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);\r\n    #ifdef _WIN32\r\n    else if (name[pos] == kMapNameID)\r\n      ParseMapWithPaths(wildcardCensor, tail, include, recursedType);\r\n    #endif\r\n    else\r\n      ThrowUserErrorException();\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\n// This code converts all short file names to long file names.\r\n\r\nstatic void ConvertToLongName(const UString &prefix, UString &name)\r\n{\r\n  if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n    return;\r\n  NFind::CFileInfoW fileInfo;\r\n  if (NFind::FindFile(prefix + name, fileInfo))\r\n    name = fileInfo.Name;\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)\r\n{\r\n  for (int i = 0; i < items.Size(); i++)\r\n  {\r\n    NWildcard::CItem &item = items[i];\r\n    if (item.Recursive || item.PathParts.Size() != 1)\r\n      continue;\r\n    ConvertToLongName(prefix, item.PathParts.Front());\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)\r\n{\r\n  ConvertToLongNames(prefix, node.IncludeItems);\r\n  ConvertToLongNames(prefix, node.ExcludeItems);\r\n  int i;\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n    ConvertToLongName(prefix, node.SubNodes[i].Name);\r\n  // mix folders with same name\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];\r\n    for (int j = i + 1; j < node.SubNodes.Size();)\r\n    {\r\n      const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];\r\n      if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)\r\n      {\r\n        nextNode1.IncludeItems += nextNode2.IncludeItems;\r\n        nextNode1.ExcludeItems += nextNode2.ExcludeItems;\r\n        node.SubNodes.Delete(j);\r\n      }\r\n      else\r\n        j++;\r\n    }\r\n  }\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode = node.SubNodes[i];\r\n    ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode);\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(NWildcard::CCensor &censor)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    NWildcard::CPair &pair = censor.Pairs[i];\r\n    ConvertToLongNames(pair.Prefix, pair.Head);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\nstatic NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)\r\n{\r\n  switch(i)\r\n  {\r\n    case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;\r\n    case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;\r\n    case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;\r\n    case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;\r\n  }\r\n  throw 98111603;\r\n}\r\n\r\nconst UString kUpdatePairStateIDSet = L\"PQRXYZW\";\r\nconst int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};\r\n\r\nconst UString kUpdatePairActionIDSet = L\"0123\"; //Ignore, Copy, Compress, Create Anti\r\n\r\nconst wchar_t *kUpdateIgnoreItselfPostStringID = L\"-\";\r\nconst wchar_t kUpdateNewArchivePostCharID = '!';\r\n\r\n\r\nstatic bool ParseUpdateCommandString2(const UString &command,\r\n    NUpdateArchive::CActionSet &actionSet, UString &postString)\r\n{\r\n  for (int i = 0; i < command.Length();)\r\n  {\r\n    wchar_t c = MyCharUpper(command[i]);\r\n    int statePos = kUpdatePairStateIDSet.Find(c);\r\n    if (statePos < 0)\r\n    {\r\n      postString = command.Mid(i);\r\n      return true;\r\n    }\r\n    i++;\r\n    if (i >= command.Length())\r\n      return false;\r\n    int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));\r\n    if (actionPos < 0)\r\n      return false;\r\n    actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);\r\n    if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)\r\n      return false;\r\n    i++;\r\n  }\r\n  postString.Empty();\r\n  return true;\r\n}\r\n\r\nstatic void ParseUpdateCommandString(CUpdateOptions &options,\r\n    const UStringVector &updatePostStrings,\r\n    const NUpdateArchive::CActionSet &defaultActionSet)\r\n{\r\n  for (int i = 0; i < updatePostStrings.Size(); i++)\r\n  {\r\n    const UString &updateString = updatePostStrings[i];\r\n    if (updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)\r\n    {\r\n      if (options.UpdateArchiveItself)\r\n      {\r\n        options.UpdateArchiveItself = false;\r\n        options.Commands.Delete(0);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      NUpdateArchive::CActionSet actionSet = defaultActionSet;\r\n\r\n      UString postString;\r\n      if (!ParseUpdateCommandString2(updateString, actionSet, postString))\r\n        ThrowUserErrorException();\r\n      if (postString.IsEmpty())\r\n      {\r\n        if (options.UpdateArchiveItself)\r\n          options.Commands[0].ActionSet = actionSet;\r\n      }\r\n      else\r\n      {\r\n        if (MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)\r\n          ThrowUserErrorException();\r\n        CUpdateArchiveCommand uc;\r\n        UString archivePath = postString.Mid(1);\r\n        if (archivePath.IsEmpty())\r\n          ThrowUserErrorException();\r\n        uc.UserArchivePath = archivePath;\r\n        uc.ActionSet = actionSet;\r\n        options.Commands.Add(uc);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic const char kByteSymbol = 'B';\r\nstatic const char kKiloSymbol = 'K';\r\nstatic const char kMegaSymbol = 'M';\r\nstatic const char kGigaSymbol = 'G';\r\n\r\nstatic bool ParseComplexSize(const UString &src, UInt64 &result)\r\n{\r\n  UString s = src;\r\n  s.MakeUpper();\r\n\r\n  const wchar_t *start = s;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || s.Length() > numDigits + 1)\r\n    return false;\r\n  if (s.Length() == numDigits)\r\n  {\r\n    result = number;\r\n    return true;\r\n  }\r\n  int numBits;\r\n  switch (s[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      result = number;\r\n      return true;\r\n    case kKiloSymbol:\r\n      numBits = 10;\r\n      break;\r\n    case kMegaSymbol:\r\n      numBits = 20;\r\n      break;\r\n    case kGigaSymbol:\r\n      numBits = 30;\r\n      break;\r\n    default:\r\n      return false;\r\n  }\r\n  if (number >= ((UInt64)1 << (64 - numBits)))\r\n    return false;\r\n  result = number << numBits;\r\n  return true;\r\n}\r\n\r\nstatic void SetAddCommandOptions(\r\n    NCommandType::EEnum commandType,\r\n    const CParser &parser,\r\n    CUpdateOptions &options)\r\n{\r\n  NUpdateArchive::CActionSet defaultActionSet;\r\n  switch(commandType)\r\n  {\r\n    case NCommandType::kAdd:\r\n      defaultActionSet = NUpdateArchive::kAddActionSet;\r\n      break;\r\n    case NCommandType::kDelete:\r\n      defaultActionSet = NUpdateArchive::kDeleteActionSet;\r\n      break;\r\n    default:\r\n      defaultActionSet = NUpdateArchive::kUpdateActionSet;\r\n  }\r\n  \r\n  options.UpdateArchiveItself = true;\r\n  \r\n  options.Commands.Clear();\r\n  CUpdateArchiveCommand updateMainCommand;\r\n  updateMainCommand.ActionSet = defaultActionSet;\r\n  options.Commands.Add(updateMainCommand);\r\n  if (parser[NKey::kUpdate].ThereIs)\r\n    ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings,\r\n        defaultActionSet);\r\n  if (parser[NKey::kWorkingDir].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];\r\n    if (postString.IsEmpty())\r\n      NDirectory::MyGetTempPath(options.WorkingDir);\r\n    else\r\n      options.WorkingDir = postString;\r\n  }\r\n  options.SfxMode = parser[NKey::kSfx].ThereIs;\r\n  if (options.SfxMode)\r\n    options.SfxModule = parser[NKey::kSfx].PostStrings[0];\r\n\r\n  if (parser[NKey::kVolume].ThereIs)\r\n  {\r\n    const UStringVector &sv = parser[NKey::kVolume].PostStrings;\r\n    for (int i = 0; i < sv.Size(); i++)\r\n    {\r\n      UInt64 size;\r\n      if (!ParseComplexSize(sv[i], size))\r\n        ThrowException(\"Incorrect volume size\");\r\n      options.VolumesSizes.Add(size);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)\r\n{\r\n  if (parser[NKey::kProperty].ThereIs)\r\n  {\r\n    // options.MethodMode.Properties.Clear();\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      CProperty property;\r\n      const UString &postString = parser[NKey::kProperty].PostStrings[i];\r\n      int index = postString.Find(L'=');\r\n      if (index < 0)\r\n        property.Name = postString;\r\n      else\r\n      {\r\n        property.Name = postString.Left(index);\r\n        property.Value = postString.Mid(index + 1);\r\n      }\r\n      properties.Add(property);\r\n    }\r\n  }\r\n}\r\n\r\nCArchiveCommandLineParser::CArchiveCommandLineParser():\r\n  parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}\r\n\r\nvoid CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,\r\n    CArchiveCommandLineOptions &options)\r\n{\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...)\r\n  {\r\n    ThrowUserErrorException();\r\n  }\r\n\r\n  options.IsInTerminal = MY_IS_TERMINAL(stdin);\r\n  options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);\r\n  options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);\r\n  options.StdOutMode = parser[NKey::kStdOut].ThereIs;\r\n  options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;\r\n  options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs  || parser[NKey::kHelp3].ThereIs;\r\n\r\n  #ifdef _WIN32\r\n  options.LargePages = false;\r\n  if (parser[NKey::kLargePages].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kLargePages].PostStrings.Front();\r\n    if (postString.IsEmpty())\r\n      options.LargePages = true;\r\n  }\r\n  #endif\r\n}\r\n\r\nstruct CCodePagePair\r\n{\r\n  const wchar_t *Name;\r\n  UINT CodePage;\r\n};\r\n\r\nstatic CCodePagePair g_CodePagePairs[] =\r\n{\r\n  { L\"UTF-8\", CP_UTF8 },\r\n  { L\"WIN\",   CP_ACP },\r\n  { L\"DOS\",   CP_OEMCP }\r\n};\r\n\r\nstatic const int kNumCodePages = sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]);\r\n\r\nstatic bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)\r\n{\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(s, &end);\r\n  if (*end != 0)\r\n    return false;\r\n  if (number > (UInt32)0xFFFFFFFF)\r\n    return false;\r\n  v = (UInt32)number;\r\n  return true;\r\n}\r\n\r\nvoid CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)\r\n{\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n  int numNonSwitchStrings = nonSwitchStrings.Size();\r\n  if (numNonSwitchStrings < kMinNonSwitchWords)\r\n    ThrowUserErrorException();\r\n\r\n  if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))\r\n    ThrowUserErrorException();\r\n\r\n  options.TechMode = parser[NKey::kTechMode].ThereIs;\r\n\r\n  if (parser[NKey::kCaseSensitive].ThereIs)\r\n    g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);\r\n\r\n  NRecursedType::EEnum recursedType;\r\n  if (parser[NKey::kRecursed].ThereIs)\r\n    recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);\r\n  else\r\n    recursedType = NRecursedType::kNonRecursed;\r\n\r\n  UINT codePage = CP_UTF8;\r\n  if (parser[NKey::kCharSet].ThereIs)\r\n  {\r\n    UString name = parser[NKey::kCharSet].PostStrings.Front();\r\n    name.MakeUpper();\r\n    int i;\r\n    for (i = 0; i < kNumCodePages; i++)\r\n    {\r\n      const CCodePagePair &pair = g_CodePagePairs[i];\r\n      if (name.Compare(pair.Name) == 0)\r\n      {\r\n        codePage = pair.CodePage;\r\n        break;\r\n      }\r\n    }\r\n    if (i >= kNumCodePages)\r\n      ThrowUserErrorException();\r\n  }\r\n\r\n  bool thereAreSwitchIncludes = false;\r\n  if (parser[NKey::kInclude].ThereIs)\r\n  {\r\n    thereAreSwitchIncludes = true;\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\r\n        parser[NKey::kInclude].PostStrings, true, recursedType, codePage);\r\n  }\r\n  if (parser[NKey::kExclude].ThereIs)\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\r\n        parser[NKey::kExclude].PostStrings, false, recursedType, codePage);\r\n \r\n  int curCommandIndex = kCommandIndex + 1;\r\n  bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs &&\r\n      options.Command.CommandType != NCommandType::kBenchmark &&\r\n      options.Command.CommandType != NCommandType::kInfo;\r\n  if (thereIsArchiveName)\r\n  {\r\n    if (curCommandIndex >= numNonSwitchStrings)\r\n      ThrowUserErrorException();\r\n    options.ArchiveName = nonSwitchStrings[curCommandIndex++];\r\n  }\r\n\r\n  AddToCensorFromNonSwitchesStrings(\r\n      curCommandIndex, options.WildcardCensor,\r\n      nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);\r\n\r\n  options.YesToAll = parser[NKey::kYes].ThereIs;\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  #ifndef _NO_CRYPTO\r\n  options.PasswordEnabled = parser[NKey::kPassword].ThereIs;\r\n  if (options.PasswordEnabled)\r\n    options.Password = parser[NKey::kPassword].PostStrings[0];\r\n  #endif\r\n\r\n  options.StdInMode = parser[NKey::kStdIn].ThereIs;\r\n  options.ShowDialog = parser[NKey::kShowDialog].ThereIs;\r\n\r\n  if (parser[NKey::kArchiveType].ThereIs)\r\n    options.ArcType = parser[NKey::kArchiveType].PostStrings[0];\r\n\r\n  if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if (options.StdInMode)\r\n      ThrowException(\"Reading archives from stdin is not implemented\");\r\n    if (!options.WildcardCensor.AllAreRelative())\r\n      ThrowException(\"Cannot use absolute pathnames for this command\");\r\n\r\n    NWildcard::CCensor archiveWildcardCensor;\r\n\r\n    if (parser[NKey::kArInclude].ThereIs)\r\n    {\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\r\n        parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);\r\n    }\r\n    if (parser[NKey::kArExclude].ThereIs)\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\r\n      parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);\r\n\r\n    if (thereIsArchiveName)\r\n      AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(archiveWildcardCensor);\r\n    #endif\r\n\r\n    archiveWildcardCensor.ExtendExclude();\r\n\r\n    UStringVector archivePaths;\r\n\r\n    {\r\n      CDirItems dirItems;\r\n      {\r\n        UStringVector errorPaths;\r\n        CRecordVector<DWORD> errorCodes;\r\n        HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);\r\n        if (res != S_OK || errorPaths.Size() > 0)\r\n          throw \"cannot find archive\";\r\n      }\r\n      for (int i = 0; i < dirItems.Items.Size(); i++)\r\n      {\r\n        const CDirItem &dirItem = dirItems.Items[i];\r\n        if (!dirItem.IsDir())\r\n          archivePaths.Add(dirItems.GetPhyPath(i));\r\n      }\r\n    }\r\n\r\n    if (archivePaths.Size() == 0)\r\n      throw \"there is no such archive\";\r\n\r\n    UStringVector archivePathsFull;\r\n\r\n    int i;\r\n    for (i = 0; i < archivePaths.Size(); i++)\r\n    {\r\n      UString fullPath;\r\n      NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);\r\n      archivePathsFull.Add(fullPath);\r\n    }\r\n    CIntVector indices;\r\n    SortFileNames(archivePathsFull, indices);\r\n    options.ArchivePathsSorted.Reserve(indices.Size());\r\n    options.ArchivePathsFullSorted.Reserve(indices.Size());\r\n    for (i = 0; i < indices.Size(); i++)\r\n    {\r\n      options.ArchivePathsSorted.Add(archivePaths[indices[i]]);\r\n      options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);\r\n    }\r\n\r\n    if (isExtractGroupCommand)\r\n    {\r\n      SetMethodOptions(parser, options.ExtractProperties);\r\n      if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)\r\n        throw kSameTerminalError;\r\n      if (parser[NKey::kOutputDir].ThereIs)\r\n      {\r\n        options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];\r\n        NFile::NName::NormalizeDirPathPrefix(options.OutputDir);\r\n      }\r\n\r\n      options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;\r\n      if (parser[NKey::kOverwrite].ThereIs)\r\n        options.OverwriteMode =\r\n            k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];\r\n      else if (options.YesToAll)\r\n        options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n    }\r\n  }\r\n  else if (options.Command.IsFromUpdateGroup())\r\n  {\r\n    CUpdateOptions &updateOptions = options.UpdateOptions;\r\n\r\n    SetAddCommandOptions(options.Command.CommandType, parser, updateOptions);\r\n    \r\n    SetMethodOptions(parser, updateOptions.MethodMode.Properties);\r\n\r\n    if (parser[NKey::kShareForWrite].ThereIs)\r\n      updateOptions.OpenShareForWrite = true;\r\n\r\n    options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;\r\n\r\n    if (options.EnablePercents)\r\n    {\r\n      if ((options.StdOutMode && !options.IsStdErrTerminal) ||\r\n         (!options.StdOutMode && !options.IsStdOutTerminal))\r\n        options.EnablePercents = false;\r\n    }\r\n\r\n    updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;\r\n    if (updateOptions.EMailMode)\r\n    {\r\n      updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();\r\n      if (updateOptions.EMailAddress.Length() > 0)\r\n        if (updateOptions.EMailAddress[0] == L'.')\r\n        {\r\n          updateOptions.EMailRemoveAfter = true;\r\n          updateOptions.EMailAddress.Delete(0);\r\n        }\r\n    }\r\n\r\n    updateOptions.StdOutMode = options.StdOutMode;\r\n    updateOptions.StdInMode = options.StdInMode;\r\n\r\n    if (updateOptions.StdOutMode && updateOptions.EMailMode)\r\n      throw \"stdout mode and email mode cannot be combined\";\r\n    if (updateOptions.StdOutMode && options.IsStdOutTerminal)\r\n      throw kTerminalOutError;\r\n    if (updateOptions.StdInMode)\r\n      updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(options.WildcardCensor);\r\n    #endif\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    options.NumThreads = (UInt32)-1;\r\n    options.DictionarySize = (UInt32)-1;\r\n    options.NumIterations = 1;\r\n    if (curCommandIndex < numNonSwitchStrings)\r\n    {\r\n      if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))\r\n        ThrowUserErrorException();\r\n    }\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      UString postString = parser[NKey::kProperty].PostStrings[i];\r\n      postString.MakeUpper();\r\n      if (postString.Length() < 2)\r\n        ThrowUserErrorException();\r\n      if (postString[0] == 'D')\r\n      {\r\n        int pos = 1;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        UInt32 logSize;\r\n        if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))\r\n          ThrowUserErrorException();\r\n        if (logSize > 31)\r\n          ThrowUserErrorException();\r\n        options.DictionarySize = 1 << logSize;\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == 'T' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        if (postString[pos] != 0)\r\n          if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))\r\n            ThrowUserErrorException();\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == '=' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] != 0)\r\n          options.Method = postString.Mid(2);\r\n      }\r\n      else\r\n        ThrowUserErrorException();\r\n    }\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n  }\r\n  else\r\n    ThrowUserErrorException();\r\n  options.WildcardCensor.ExtendExclude();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h",
    "content": "// ArchiveCommandLine.h\r\n\r\n#ifndef __ARCHIVECOMMANDLINE_H\r\n#define __ARCHIVECOMMANDLINE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#include \"Extract.h\"\r\n#include \"Update.h\"\r\n\r\nstruct CArchiveCommandLineException: public AString\r\n{\r\n  CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {}\r\n};\r\n\r\nnamespace NCommandType { enum EEnum\r\n{\r\n  kAdd = 0,\r\n  kUpdate,\r\n  kDelete,\r\n  kTest,\r\n  kExtract,\r\n  kFullExtract,\r\n  kList,\r\n  kBenchmark,\r\n  kInfo\r\n};}\r\n\r\nnamespace NRecursedType { enum EEnum\r\n{\r\n  kRecursed,\r\n  kWildCardOnlyRecursed,\r\n  kNonRecursed\r\n};}\r\n\r\nstruct CArchiveCommand\r\n{\r\n  NCommandType::EEnum CommandType;\r\n  bool IsFromExtractGroup() const;\r\n  bool IsFromUpdateGroup() const;\r\n  bool IsTestMode() const { return CommandType == NCommandType::kTest; }\r\n  NExtract::NPathMode::EEnum GetPathMode() const;\r\n};\r\n\r\nstruct CArchiveCommandLineOptions\r\n{\r\n  bool HelpMode;\r\n\r\n  #ifdef _WIN32\r\n  bool LargePages;\r\n  #endif\r\n\r\n  bool IsInTerminal;\r\n  bool IsStdOutTerminal;\r\n  bool IsStdErrTerminal;\r\n  bool StdInMode;\r\n  bool StdOutMode;\r\n  bool EnableHeaders;\r\n\r\n  bool YesToAll;\r\n  bool ShowDialog;\r\n  // NWildcard::CCensor ArchiveWildcardCensor;\r\n  NWildcard::CCensor WildcardCensor;\r\n\r\n  CArchiveCommand Command;\r\n  UString ArchiveName;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordEnabled;\r\n  UString Password;\r\n  #endif\r\n\r\n  bool TechMode;\r\n  // Extract\r\n  bool AppendName;\r\n  UString OutputDir;\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n  UStringVector ArchivePathsSorted;\r\n  UStringVector ArchivePathsFullSorted;\r\n  CObjectVector<CProperty> ExtractProperties;\r\n\r\n  CUpdateOptions UpdateOptions;\r\n  UString ArcType;\r\n  bool EnablePercents;\r\n\r\n  // Benchmark\r\n  UInt32 NumIterations;\r\n  UInt32 NumThreads;\r\n  UInt32 DictionarySize;\r\n  UString Method;\r\n\r\n\r\n  CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};\r\n};\r\n\r\nclass CArchiveCommandLineParser\r\n{\r\n  NCommandLineParser::CParser parser;\r\npublic:\r\n  CArchiveCommandLineParser();\r\n  void Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options);\r\n  void Parse2(CArchiveCommandLineOptions &options);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp",
    "content": "// ArchiveExtractCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n#include \"OpenArchive.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic const wchar_t *kCantAutoRename = L\"ERROR: Can not create file with auto name\";\r\nstatic const wchar_t *kCantRenameFile = L\"ERROR: Can not rename existing file \";\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\n\r\nvoid CArchiveExtractCallback::Init(\r\n    IInArchive *archiveHandler,\r\n    IFolderArchiveExtractCallback *extractCallback2,\r\n    bool stdOutMode,\r\n    const UString &directoryPath,\r\n    const UStringVector &removePathParts,\r\n    const UString &itemDefaultName,\r\n    const FILETIME &utcMTimeDefault,\r\n    UInt32 attributesDefault,\r\n    UInt64 packSize)\r\n{\r\n  _stdOutMode = stdOutMode;\r\n  _numErrors = 0;\r\n  _unpTotal = 1;\r\n  _packTotal = packSize;\r\n\r\n  _extractCallback2 = extractCallback2;\r\n  _compressProgress.Release();\r\n  _extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);\r\n\r\n  LocalProgressSpec->Init(extractCallback2, true);\r\n  LocalProgressSpec->SendProgress = false;\r\n\r\n  _itemDefaultName = itemDefaultName;\r\n  _utcMTimeDefault = utcMTimeDefault;\r\n  _attributesDefault = attributesDefault;\r\n  _removePathParts = removePathParts;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  _unpTotal = size;\r\n  if (!_multiArchives && _extractCallback2)\r\n    return _extractCallback2->SetTotal(size);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  const UInt64 kMax = (UInt64)1 << 31;\r\n  while (v1 > kMax)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)\r\n{\r\n  NormalizeVals(packTotal, unpTotal);\r\n  NormalizeVals(unpCur, unpTotal);\r\n  if (unpTotal == 0)\r\n    unpTotal = 1;\r\n  return unpCur * packTotal / unpTotal;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_extractCallback2)\r\n    return S_OK;\r\n\r\n  if (_multiArchives)\r\n  {\r\n    if (completeValue != NULL)\r\n    {\r\n      UInt64 packCur = LocalProgressSpec->InSize + MyMultDiv64(*completeValue, _unpTotal, _packTotal);\r\n      return _extractCallback2->SetCompleted(&packCur);\r\n    }\r\n  }\r\n  return _extractCallback2->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return _localProgress->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\nvoid CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)\r\n{\r\n  fullPath = _directoryPath;\r\n  for(int i = 0; i < dirPathParts.Size(); i++)\r\n  {\r\n    if (i > 0)\r\n      fullPath += wchar_t(NFile::NName::kDirDelimiter);\r\n    fullPath += dirPathParts[i];\r\n    NFile::NDirectory::MyCreateDirectory(fullPath);\r\n  }\r\n}\r\n\r\nstatic UString MakePathNameFromParts(const UStringVector &parts)\r\n{\r\n  UString result;\r\n  for(int i = 0; i < parts.Size(); i++)\r\n  {\r\n    if(i != 0)\r\n      result += wchar_t(NFile::NName::kDirDelimiter);\r\n    result += parts[i];\r\n  }\r\n  return result;\r\n}\r\n\r\n\r\nHRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(_archiveHandler->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    filetime = prop.filetime;\r\n    filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  _encrypted = false;\r\n  _isSplit = false;\r\n  _curSize = 0;\r\n\r\n  UString fullPath;\r\n\r\n  RINOK(GetArchiveItemPath(_archiveHandler, index, _itemDefaultName, fullPath));\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDir));\r\n\r\n  _filePath = fullPath;\r\n\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPosition, &prop));\r\n    if (prop.vt != VT_EMPTY)\r\n    {\r\n      if (prop.vt != VT_UI8)\r\n        return E_FAIL;\r\n      _position = prop.uhVal.QuadPart;\r\n      _isSplit = true;\r\n    }\r\n  }\r\n    \r\n  RINOK(IsArchiveItemProp(_archiveHandler, index, kpidEncrypted, _encrypted));\r\n\r\n  bool newFileSizeDefined;\r\n  UInt64 newFileSize;\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    if (newFileSizeDefined)\r\n    {\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n      _curSize = newFileSize;\r\n    }\r\n  }\r\n\r\n  if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)\r\n  {\r\n    if (_stdOutMode)\r\n    {\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc = new CStdOutFileStream;\r\n      *outStream = outStreamLoc.Detach();\r\n      return S_OK;\r\n    }\r\n\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n        _processedFileInfo.Attributes = _attributesDefault;\r\n        _processedFileInfo.AttributesAreDefined = false;\r\n      }\r\n      else\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_FAIL;\r\n        _processedFileInfo.Attributes = prop.ulVal;\r\n        _processedFileInfo.AttributesAreDefined = true;\r\n      }\r\n    }\r\n\r\n    RINOK(GetTime(index, kpidCTime, _processedFileInfo.CTime, _processedFileInfo.CTimeDefined));\r\n    RINOK(GetTime(index, kpidATime, _processedFileInfo.ATime, _processedFileInfo.ATimeDefined));\r\n    RINOK(GetTime(index, kpidMTime, _processedFileInfo.MTime, _processedFileInfo.MTimeDefined));\r\n\r\n    bool isAnti = false;\r\n    RINOK(IsArchiveItemProp(_archiveHandler, index, kpidIsAnti, isAnti));\r\n\r\n    UStringVector pathParts;\r\n    SplitPathToParts(fullPath, pathParts);\r\n    \r\n    if(pathParts.IsEmpty())\r\n      return E_FAIL;\r\n    int numRemovePathParts = 0;\r\n    switch(_pathMode)\r\n    {\r\n      case NExtract::NPathMode::kFullPathnames:\r\n        break;\r\n      case NExtract::NPathMode::kCurrentPathnames:\r\n      {\r\n        numRemovePathParts = _removePathParts.Size();\r\n        if (pathParts.Size() <= numRemovePathParts)\r\n          return E_FAIL;\r\n        for (int i = 0; i < numRemovePathParts; i++)\r\n          if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0)\r\n            return E_FAIL;\r\n        break;\r\n      }\r\n      case NExtract::NPathMode::kNoPathnames:\r\n      {\r\n        numRemovePathParts = pathParts.Size() - 1;\r\n        break;\r\n      }\r\n    }\r\n    pathParts.Delete(0, numRemovePathParts);\r\n    MakeCorrectPath(pathParts);\r\n    UString processedPath = MakePathNameFromParts(pathParts);\r\n    if (!isAnti)\r\n    {\r\n      if (!_processedFileInfo.IsDir)\r\n      {\r\n        if (!pathParts.IsEmpty())\r\n          pathParts.DeleteBack();\r\n      }\r\n    \r\n      if (!pathParts.IsEmpty())\r\n      {\r\n        UString fullPathNew;\r\n        CreateComplexDirectory(pathParts, fullPathNew);\r\n        if (_processedFileInfo.IsDir)\r\n          NFile::NDirectory::SetDirTime(fullPathNew,\r\n            (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\r\n            (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\r\n            (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\r\n      }\r\n    }\r\n\r\n\r\n    UString fullProcessedPath = _directoryPath + processedPath;\r\n\r\n    if(_processedFileInfo.IsDir)\r\n    {\r\n      _diskFilePath = fullProcessedPath;\r\n      if (isAnti)\r\n        NFile::NDirectory::MyRemoveDirectory(_diskFilePath);\r\n      return S_OK;\r\n    }\r\n\r\n    if (!_isSplit)\r\n    {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      switch(_overwriteMode)\r\n      {\r\n        case NExtract::NOverwriteMode::kSkipExisting:\r\n          return S_OK;\r\n        case NExtract::NOverwriteMode::kAskBefore:\r\n        {\r\n          Int32 overwiteResult;\r\n          RINOK(_extractCallback2->AskOverwrite(\r\n              fullProcessedPath, &fileInfo.MTime, &fileInfo.Size, fullPath,\r\n              _processedFileInfo.MTimeDefined ? &_processedFileInfo.MTime : NULL,\r\n              newFileSizeDefined ? &newFileSize : NULL,\r\n              &overwiteResult))\r\n\r\n          switch(overwiteResult)\r\n          {\r\n            case NOverwriteAnswer::kCancel:\r\n              return E_ABORT;\r\n            case NOverwriteAnswer::kNo:\r\n              return S_OK;\r\n            case NOverwriteAnswer::kNoToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kSkipExisting;\r\n              return S_OK;\r\n            case NOverwriteAnswer::kYesToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n              break;\r\n            case NOverwriteAnswer::kYes:\r\n              break;\r\n            case NOverwriteAnswer::kAutoRename:\r\n              _overwriteMode = NExtract::NOverwriteMode::kAutoRename;\r\n              break;\r\n            default:\r\n              return E_FAIL;\r\n          }\r\n        }\r\n      }\r\n      if (_overwriteMode == NExtract::NOverwriteMode::kAutoRename)\r\n      {\r\n        if (!AutoRenamePath(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantAutoRename) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)\r\n      {\r\n        UString existPath = fullProcessedPath;\r\n        if (!AutoRenamePath(existPath))\r\n        {\r\n          UString message = kCantAutoRename + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n        if(!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))\r\n        {\r\n          UString message = UString(kCantRenameFile) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else\r\n        if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantDeleteOutputFile) +  fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n          // return E_FAIL;\r\n        }\r\n    }\r\n    }\r\n    if (!isAnti)\r\n    {\r\n      _outFileStreamSpec = new COutFileStream;\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n      if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))\r\n      {\r\n        // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)\r\n        {\r\n          UString message = L\"can not open output file \" + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n        }\r\n      }\r\n      if (_isSplit)\r\n      {\r\n        RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));\r\n      }\r\n      _outFileStream = outStreamLoc;\r\n      *outStream = outStreamLoc.Detach();\r\n    }\r\n    _diskFilePath = fullProcessedPath;\r\n  }\r\n  else\r\n  {\r\n    *outStream = NULL;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  return _extractCallback2->PrepareOperation(_filePath, _processedFileInfo.IsDir,\r\n      askExtractMode, _isSplit ? &_position: 0);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n    case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n    case NArchive::NExtract::NOperationResult::kCRCError:\r\n    case NArchive::NExtract::NOperationResult::kDataError:\r\n      break;\r\n    default:\r\n      _outFileStream.Release();\r\n      return E_FAIL;\r\n  }\r\n  if (_outFileStream != NULL)\r\n  {\r\n    _outFileStreamSpec->SetTime(\r\n        (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\r\n        (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\r\n        (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\r\n    _curSize = _outFileStreamSpec->ProcessedSize;\r\n    RINOK(_outFileStreamSpec->Close());\r\n    _outFileStream.Release();\r\n  }\r\n  UnpackSize += _curSize;\r\n  if (_processedFileInfo.IsDir)\r\n    NumFolders++;\r\n  else\r\n    NumFiles++;\r\n\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CArchiveExtractCallback::GetInStream(\r\n    const wchar_t *name, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  CInFileStream *inFile = new CInFileStream;\r\n  CMyComPtr<ISequentialInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(_srcDirectoryPrefix + name))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_cryptoGetTextPassword)\r\n  {\r\n    RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword,\r\n        &_cryptoGetTextPassword));\r\n  }\r\n  return _cryptoGetTextPassword->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h",
    "content": "// ArchiveExtractCallback.h\r\n\r\n#ifndef __ARCHIVEEXTRACTCALLBACK_H\r\n#define __ARCHIVEEXTRACTCALLBACK_H\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"IFileExtractCallback.h\"\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"ExtractMode.h\"\r\n\r\nclass CArchiveExtractCallback:\r\n  public IArchiveExtractCallback,\r\n  // public IArchiveVolumeExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(ICryptoGetTextPassword, ICompressProgressInfo)\r\n  // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)\r\n\r\n  INTERFACE_IArchiveExtractCallback(;)\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IArchiveVolumeExtractCallback\r\n  // STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;\r\n  CMyComPtr<ICompressProgressInfo> _compressProgress;\r\n  CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;\r\n  UString _directoryPath;\r\n  NExtract::NPathMode::EEnum _pathMode;\r\n  NExtract::NOverwriteMode::EEnum _overwriteMode;\r\n\r\n  UString _filePath;\r\n  UInt64 _position;\r\n  bool _isSplit;\r\n\r\n  UString _diskFilePath;\r\n\r\n  bool _extractMode;\r\n\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  bool _encrypted;\r\n\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME CTime;\r\n    FILETIME ATime;\r\n    FILETIME MTime;\r\n    UInt32 Attributes;\r\n  \r\n    bool CTimeDefined;\r\n    bool ATimeDefined;\r\n    bool MTimeDefined;\r\n\r\n    bool IsDir;\r\n    bool AttributesAreDefined;\r\n  } _processedFileInfo;\r\n\r\n  UInt64 _curSize;\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n  UStringVector _removePathParts;\r\n\r\n  UString _itemDefaultName;\r\n  FILETIME _utcMTimeDefault;\r\n  UInt32 _attributesDefault;\r\n  bool _stdOutMode;\r\n\r\n  void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);\r\n  HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);\r\npublic:\r\n  CArchiveExtractCallback():\r\n      WriteCTime(true),\r\n      WriteATime(true),\r\n      WriteMTime(true),\r\n      _multiArchives(false)\r\n  {\r\n    LocalProgressSpec = new CLocalProgress();\r\n    _localProgress = LocalProgressSpec;\r\n  }\r\n\r\n  CLocalProgress *LocalProgressSpec;\r\n  CMyComPtr<ICompressProgressInfo> _localProgress;\r\n  UInt64 _packTotal;\r\n  UInt64 _unpTotal;\r\n\r\n  bool _multiArchives;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  UInt64 UnpackSize;\r\n  \r\n  void InitForMulti(bool multiArchives,\r\n      NExtract::NPathMode::EEnum pathMode,\r\n      NExtract::NOverwriteMode::EEnum overwriteMode)\r\n  {\r\n    _multiArchives = multiArchives; NumFolders = NumFiles = UnpackSize = 0;\r\n    _pathMode = pathMode;\r\n    _overwriteMode = overwriteMode;\r\n  }\r\n\r\n  void Init(\r\n      IInArchive *archiveHandler,\r\n      IFolderArchiveExtractCallback *extractCallback2,\r\n      bool stdOutMode,\r\n      const UString &directoryPath,\r\n      const UStringVector &removePathParts,\r\n      const UString &itemDefaultName,\r\n      const FILETIME &utcMTimeDefault,\r\n      UInt32 attributesDefault,\r\n      UInt64 packSize);\r\n\r\n  UInt64 _numErrors;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ArchiveName.cpp",
    "content": "// ArchiveName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)\r\n{\r\n  UString resultName = L\"Archive\";\r\n  if (fromPrev)\r\n  {\r\n    UString dirPrefix;\r\n    if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))\r\n    {\r\n      if (dirPrefix.Length() > 0)\r\n        if (dirPrefix[dirPrefix.Length() - 1] == WCHAR_PATH_SEPARATOR)\r\n        {\r\n          dirPrefix.Delete(dirPrefix.Length() - 1);\r\n          NFile::NFind::CFileInfoW fileInfo;\r\n          if (NFile::NFind::FindFile(dirPrefix, fileInfo))\r\n            resultName = fileInfo.Name;\r\n        }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if (!NFile::NFind::FindFile(srcName, fileInfo))\r\n      return resultName;\r\n    resultName = fileInfo.Name;\r\n    if (!fileInfo.IsDir() && !keepName)\r\n    {\r\n      int dotPos = resultName.ReverseFind('.');\r\n      if (dotPos > 0)\r\n      {\r\n        UString archiveName2 = resultName.Left(dotPos);\r\n        if (archiveName2.ReverseFind('.') < 0)\r\n          resultName = archiveName2;\r\n      }\r\n    }\r\n  }\r\n  return resultName;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ArchiveName.h",
    "content": "// ArchiveName.h\r\n\r\n#ifndef __ARCHIVENAME_H\r\n#define __ARCHIVENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp",
    "content": "// ArchiveOpenCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n    return ReOpenCallback->SetTotal(files, bytes);\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->Open_SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n    return ReOpenCallback->SetCompleted(files, bytes);\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->Open_SetCompleted(files, bytes);\r\n  COM_TRY_END\r\n}\r\n  \r\nSTDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  if (_subArchiveMode)\r\n    switch(propID)\r\n    {\r\n      case kpidName: prop = _subArchiveName; break;\r\n    }\r\n  else\r\n    switch(propID)\r\n    {\r\n      case kpidName:  prop = _fileInfo.Name; break;\r\n      case kpidIsDir:  prop = _fileInfo.IsDir(); break;\r\n      case kpidSize:  prop = _fileInfo.Size; break;\r\n      case kpidAttrib:  prop = (UInt32)_fileInfo.Attrib; break;\r\n      case kpidCTime:  prop = _fileInfo.CTime; break;\r\n      case kpidATime:  prop = _fileInfo.ATime; break;\r\n      case kpidMTime:  prop = _fileInfo.MTime; break;\r\n    }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nint COpenCallbackImp::FindName(const UString &name)\r\n{\r\n  for (int i = 0; i < FileNames.Size(); i++)\r\n    if (name.CompareNoCase(FileNames[i]) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstruct CInFileStreamVol: public CInFileStream\r\n{\r\n  UString Name;\r\n  COpenCallbackImp *OpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;\r\n  ~CInFileStreamVol()\r\n  {\r\n    int index = OpenCallbackImp->FindName(Name);\r\n    if (index >= 0)\r\n      OpenCallbackImp->FileNames.Delete(index);\r\n  }\r\n};\r\n\r\nSTDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (_subArchiveMode)\r\n    return S_FALSE;\r\n  if (Callback)\r\n  {\r\n    RINOK(Callback->Open_CheckBreak());\r\n  }\r\n  *inStream = NULL;\r\n  UString fullPath = _folderPrefix + name;\r\n  if (!NFile::NFind::FindFile(fullPath, _fileInfo))\r\n    return S_FALSE;\r\n  if (_fileInfo.IsDir())\r\n    return S_FALSE;\r\n  CInFileStreamVol *inFile = new CInFileStreamVol;\r\n  CMyComPtr<IInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(fullPath))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  inFile->Name = name;\r\n  inFile->OpenCallbackImp = this;\r\n  inFile->OpenCallbackRef = this;\r\n  FileNames.Add(name);\r\n  TotalSize += _fileInfo.Size;\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n  {\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    ReOpenCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    if (getTextPassword)\r\n      return getTextPassword->CryptoGetTextPassword(password);\r\n  }\r\n  if (!Callback)\r\n    return E_NOTIMPL;\r\n  return Callback->Open_CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n#endif\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h",
    "content": "// ArchiveOpenCallback.h\r\n\r\n#ifndef __ARCHIVE_OPEN_CALLBACK_H\r\n#define __ARCHIVE_OPEN_CALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#ifndef _NO_CRYPTO\r\n#include \"../../IPassword.h\"\r\n#endif\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#ifdef _NO_CRYPTO\r\n\r\n#define INTERFACE_IOpenCallbackUI_Crypto(x)\r\n\r\n#else\r\n\r\n#define INTERFACE_IOpenCallbackUI_Crypto(x) \\\r\n  virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x; \\\r\n  virtual HRESULT Open_GetPasswordIfAny(UString &password) x; \\\r\n  virtual bool Open_WasPasswordAsked() x; \\\r\n  virtual void Open_ClearPasswordWasAskedFlag() x; \\\r\n  \r\n#endif\r\n\r\n#define INTERFACE_IOpenCallbackUI(x) \\\r\n  virtual HRESULT Open_CheckBreak() x; \\\r\n  virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  INTERFACE_IOpenCallbackUI_Crypto(x)\r\n\r\nstruct IOpenCallbackUI\r\n{\r\n  INTERFACE_IOpenCallbackUI(=0)\r\n};\r\n\r\nclass COpenCallbackImp:\r\n  public IArchiveOpenCallback,\r\n  public IArchiveOpenVolumeCallback,\r\n  public IArchiveOpenSetSubArchiveName,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifndef _NO_CRYPTO\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveOpenVolumeCallback,\r\n      ICryptoGetTextPassword,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      IArchiveOpenVolumeCallback,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #endif\r\n\r\n  INTERFACE_IArchiveOpenCallback(;)\r\n  INTERFACE_IArchiveOpenVolumeCallback(;)\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n  #endif\r\n\r\n  STDMETHOD(SetSubArchiveName(const wchar_t *name))\r\n  {\r\n    _subArchiveMode = true;\r\n    _subArchiveName = name;\r\n    return  S_OK;\r\n  }\r\n\r\nprivate:\r\n  UString _folderPrefix;\r\n  NWindows::NFile::NFind::CFileInfoW _fileInfo;\r\n  bool _subArchiveMode;\r\n  UString _subArchiveName;\r\npublic:\r\n  UStringVector FileNames;\r\n  IOpenCallbackUI *Callback;\r\n  CMyComPtr<IArchiveOpenCallback> ReOpenCallback;\r\n  UInt64 TotalSize;\r\n\r\n  COpenCallbackImp(): Callback(NULL) {}\r\n  void Init(const UString &folderPrefix,  const UString &fileName)\r\n  {\r\n    _folderPrefix = folderPrefix;\r\n    if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))\r\n      throw 1;\r\n    FileNames.Clear();\r\n    _subArchiveMode = false;\r\n    TotalSize = 0;\r\n  }\r\n  int FindName(const UString &name);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/DefaultName.cpp",
    "content": "// DefaultName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nstatic UString GetDefaultName3(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  int extLength = extension.Length();\r\n  int fileNameLength = fileName.Length();\r\n  if (fileNameLength > extLength + 1)\r\n  {\r\n    int dotPos = fileNameLength - (extLength + 1);\r\n    if (fileName[dotPos] == '.')\r\n      if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)\r\n        return fileName.Left(dotPos) + addSubExtension;\r\n  }\r\n  int dotPos = fileName.ReverseFind(L'.');\r\n  if (dotPos > 0)\r\n    return fileName.Left(dotPos) + addSubExtension;\r\n\r\n  if (addSubExtension.IsEmpty())\r\n    return fileName + L\"~\";\r\n  else\r\n    return fileName + addSubExtension;\r\n}\r\n\r\nUString GetDefaultName2(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  UString name = GetDefaultName3(fileName, extension, addSubExtension);\r\n  name.TrimRight();\r\n  return name;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/DefaultName.h",
    "content": "// DefaultName.h\r\n\r\n#ifndef __DEFAULTNAME_H\r\n#define __DEFAULTNAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString GetDefaultName2(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/DirItem.h",
    "content": "// DirItem.h\r\n\r\n#ifndef __DIR_ITEM_H\r\n#define __DIR_ITEM_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CDirItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  UInt32 Attrib;\r\n  int PhyParent;\r\n  int LogParent;\r\n  \r\n  CDirItem(): PhyParent(-1), LogParent(-1) {}\r\n  bool IsDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CDirItems\r\n{\r\n  UStringVector Prefixes;\r\n  CIntVector PhyParents;\r\n  CIntVector LogParents;\r\n\r\n  UString GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const;\r\npublic:\r\n  CObjectVector<CDirItem> Items;\r\n\r\n  int GetNumFolders() const { return Prefixes.Size(); }\r\n  UString GetPhyPath(int index) const;\r\n  UString GetLogPath(int index) const;\r\n\r\n  int AddPrefix(int phyParent, int logParent, const UString &prefix);\r\n  void DeleteLastPrefix();\r\n\r\n  void EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\r\n\r\n  void EnumerateDirItems2(\r\n    const UString &phyPrefix,\r\n    const UString &logPrefix,\r\n    const UStringVector &filePaths,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\r\n\r\n  void ReserveDown();\r\n};\r\n\r\nstruct CArcItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  bool IsDir;\r\n  bool SizeDefined;\r\n  bool Censored;\r\n  UInt32 IndexInServer;\r\n  int TimeType;\r\n  \r\n  CArcItem(): IsDir(false), SizeDefined(false), Censored(false), TimeType(-1) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp",
    "content": "// EnumDirItems.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nvoid AddDirFileInfo(int phyParent, int logParent,\r\n    const NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems)\r\n{\r\n  CDirItem di;\r\n  di.Size = fi.Size;\r\n  di.CTime = fi.CTime;\r\n  di.ATime = fi.ATime;\r\n  di.MTime = fi.MTime;\r\n  di.Attrib = fi.Attrib;\r\n  di.PhyParent = phyParent;\r\n  di.LogParent = logParent;\r\n  di.Name = fi.Name;\r\n  dirItems.Add(di);\r\n}\r\n\r\nUString CDirItems::GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const\r\n{\r\n  UString path;\r\n  int len = name.Length();\r\n  int i;\r\n  for (i = index; i >= 0; i = parents[i])\r\n    len += Prefixes[i].Length();\r\n  int totalLen = len;\r\n  wchar_t *p = path.GetBuffer(len);\r\n  p[len] = 0;\r\n  len -= name.Length();\r\n  memcpy(p + len, (const wchar_t *)name, name.Length() * sizeof(wchar_t));\r\n  for (i = index; i >= 0; i = parents[i])\r\n  {\r\n    const UString &s = Prefixes[i];\r\n    len -= s.Length();\r\n    memcpy(p + len, (const wchar_t *)s, s.Length() * sizeof(wchar_t));\r\n  }\r\n  path.ReleaseBuffer(totalLen);\r\n  return path;\r\n}\r\n\r\nUString CDirItems::GetPhyPath(int index) const\r\n{\r\n  const CDirItem &di = Items[index];\r\n  return GetPrefixesPath(PhyParents, di.PhyParent, di.Name);\r\n}\r\n\r\nUString CDirItems::GetLogPath(int index) const\r\n{\r\n  const CDirItem &di = Items[index];\r\n  return GetPrefixesPath(LogParents, di.LogParent, di.Name);\r\n}\r\n\r\nvoid CDirItems::ReserveDown()\r\n{\r\n  Prefixes.ReserveDown();\r\n  PhyParents.ReserveDown();\r\n  LogParents.ReserveDown();\r\n  Items.ReserveDown();\r\n}\r\n\r\nint CDirItems::AddPrefix(int phyParent, int logParent, const UString &prefix)\r\n{\r\n  PhyParents.Add(phyParent);\r\n  LogParents.Add(logParent);\r\n  return Prefixes.Add(prefix);\r\n}\r\n\r\nvoid CDirItems::DeleteLastPrefix()\r\n{\r\n  PhyParents.DeleteBack();\r\n  LogParents.DeleteBack();\r\n  Prefixes.DeleteBack();\r\n}\r\n\r\nvoid CDirItems::EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\r\n{\r\n  NFind::CEnumeratorW enumerator(phyPrefix + (wchar_t)kAnyStringWildcard);\r\n  for (;;)\r\n  {\r\n    NFind::CFileInfoW fi;\r\n    bool found;\r\n    if (!enumerator.Next(fi, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPrefix);\r\n      return;\r\n    }\r\n    if (!found)\r\n      break;\r\n    AddDirFileInfo(phyParent, logParent, fi, Items);\r\n    if (fi.IsDir())\r\n    {\r\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\r\n      int parent = AddPrefix(phyParent, logParent, name2);\r\n      EnumerateDirectory(parent, parent, phyPrefix + name2, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CDirItems::EnumerateDirItems2(const UString &phyPrefix, const UString &logPrefix,\r\n    const UStringVector &filePaths, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\r\n{\r\n  int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, phyPrefix);\r\n  int logParent = logPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, logPrefix);\r\n\r\n  for (int i = 0; i < filePaths.Size(); i++)\r\n  {\r\n    const UString &filePath = filePaths[i];\r\n    NFind::CFileInfoW fi;\r\n    const UString phyPath = phyPrefix + filePath;\r\n    if (!NFind::FindFile(phyPath, fi))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPath);\r\n      continue;\r\n    }\r\n    int delimiter = filePath.ReverseFind((wchar_t)kDirDelimiter);\r\n    UString phyPrefixCur;\r\n    int phyParentCur = phyParent;\r\n    if (delimiter >= 0)\r\n    {\r\n      phyPrefixCur = filePath.Left(delimiter + 1);\r\n      phyParentCur = AddPrefix(phyParent, logParent, phyPrefixCur);\r\n    }\r\n    AddDirFileInfo(phyParentCur, logParent, fi, Items);\r\n    if (fi.IsDir())\r\n    {\r\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\r\n      int parent = AddPrefix(phyParentCur, logParent, name2);\r\n      EnumerateDirectory(parent, parent, phyPrefix + phyPrefixCur + name2, errorPaths, errorCodes);\r\n    }\r\n  }\r\n  ReserveDown();\r\n}\r\n\r\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\nstatic HRESULT EnumerateDirItems_Spec(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &curFolderName,\r\n    const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n  \r\n{\r\n  const UString name2 = curFolderName + (wchar_t)kDirDelimiter;\r\n  int parent = dirItems.AddPrefix(phyParent, logParent, name2);\r\n  int numItems = dirItems.Items.Size();\r\n  HRESULT res = EnumerateDirItems(curNode, parent, parent, phyPrefix + name2,\r\n    addArchivePrefix, dirItems, enterToSubFolders, callback, errorPaths, errorCodes);\r\n  if (numItems == dirItems.Items.Size())\r\n    dirItems.DeleteLastPrefix();\r\n  return res;\r\n}\r\n\r\n\r\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,  // prefix from curNode\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  if (!enterToSubFolders)\r\n    if (curNode.NeedCheckSubDirs())\r\n      enterToSubFolders = true;\r\n  if (callback)\r\n    RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\r\n\r\n  // try direct_names case at first\r\n  if (addArchivePrefix.IsEmpty() && !enterToSubFolders)\r\n  {\r\n    // check that all names are direct\r\n    int i;\r\n    for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n    {\r\n      const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n      if (item.Recursive || item.PathParts.Size() != 1)\r\n        break;\r\n      const UString &name = item.PathParts.Front();\r\n      if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n        break;\r\n    }\r\n    if (i == curNode.IncludeItems.Size())\r\n    {\r\n      // all names are direct (no wildcards)\r\n      // so we don't need file_system's dir enumerator\r\n      CRecordVector<bool> needEnterVector;\r\n      for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n      {\r\n        const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n        const UString &name = item.PathParts.Front();\r\n        const UString fullPath = phyPrefix + name;\r\n        NFind::CFileInfoW fi;\r\n        if (!NFind::FindFile(fullPath, fi))\r\n        {\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        bool isDir = fi.IsDir();\r\n        if (isDir && !item.ForDir || !isDir && !item.ForFile)\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        {\r\n          UStringVector pathParts;\r\n          pathParts.Add(fi.Name);\r\n          if (curNode.CheckPathToRoot(false, pathParts, !isDir))\r\n            continue;\r\n        }\r\n        AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\r\n        if (!isDir)\r\n          continue;\r\n        \r\n        UStringVector addArchivePrefixNew;\r\n        const NWildcard::CCensorNode *nextNode = 0;\r\n        int index = curNode.FindSubNode(name);\r\n        if (index >= 0)\r\n        {\r\n          for (int t = needEnterVector.Size(); t <= index; t++)\r\n            needEnterVector.Add(true);\r\n          needEnterVector[index] = false;\r\n          nextNode = &curNode.SubNodes[index];\r\n        }\r\n        else\r\n        {\r\n          nextNode = &curNode;\r\n          addArchivePrefixNew.Add(name); // don't change it to fi.Name. It's for shortnames support\r\n        }\r\n\r\n        RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix,\r\n            addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes));\r\n      }\r\n      for (i = 0; i < curNode.SubNodes.Size(); i++)\r\n      {\r\n        if (i < needEnterVector.Size())\r\n          if (!needEnterVector[i])\r\n            continue;\r\n        const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];\r\n        const UString fullPath = phyPrefix + nextNode.Name;\r\n        NFind::CFileInfoW fi;\r\n        if (!NFind::FindFile(fullPath, fi))\r\n        {\r\n          if (!nextNode.AreThereIncludeItems())\r\n            continue;\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        if (!fi.IsDir())\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n\r\n        RINOK(EnumerateDirItems_Spec(nextNode, phyParent, logParent, fi.Name, phyPrefix,\r\n            UStringVector(), dirItems, false, callback, errorPaths, errorCodes));\r\n      }\r\n      return S_OK;\r\n    }\r\n  }\r\n\r\n\r\n  NFind::CEnumeratorW enumerator(phyPrefix + wchar_t(kAnyStringWildcard));\r\n  for (int ttt = 0; ; ttt++)\r\n  {\r\n    NFind::CFileInfoW fi;\r\n    bool found;\r\n    if (!enumerator.Next(fi, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPrefix);\r\n      break;\r\n    }\r\n    if (!found)\r\n      break;\r\n\r\n    if (callback && (ttt & 0xFF) == 0xFF)\r\n      RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\r\n    const UString &name = fi.Name;\r\n    bool enterToSubFolders2 = enterToSubFolders;\r\n    UStringVector addArchivePrefixNew = addArchivePrefix;\r\n    addArchivePrefixNew.Add(name);\r\n    {\r\n      UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);\r\n      if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fi.IsDir()))\r\n        continue;\r\n    }\r\n    if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir()))\r\n    {\r\n      AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\r\n      if (fi.IsDir())\r\n        enterToSubFolders2 = true;\r\n    }\r\n    if (!fi.IsDir())\r\n      continue;\r\n\r\n    const NWildcard::CCensorNode *nextNode = 0;\r\n    if (addArchivePrefix.IsEmpty())\r\n    {\r\n      int index = curNode.FindSubNode(name);\r\n      if (index >= 0)\r\n        nextNode = &curNode.SubNodes[index];\r\n    }\r\n    if (!enterToSubFolders2 && nextNode == 0)\r\n      continue;\r\n\r\n    addArchivePrefixNew = addArchivePrefix;\r\n    if (nextNode == 0)\r\n    {\r\n      nextNode = &curNode;\r\n      addArchivePrefixNew.Add(name);\r\n    }\r\n\r\n    RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, name, phyPrefix,\r\n        addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor,\r\n    CDirItems &dirItems,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    const NWildcard::CPair &pair = censor.Pairs[i];\r\n    int phyParent = pair.Prefix.IsEmpty() ? -1 : dirItems.AddPrefix(-1, -1, pair.Prefix);\r\n    RINOK(EnumerateDirItems(pair.Head, phyParent, -1, pair.Prefix, UStringVector(), dirItems, false,\r\n        callback, errorPaths, errorCodes));\r\n  }\r\n  dirItems.ReserveDown();\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/EnumDirItems.h",
    "content": "// EnumDirItems.h\r\n\r\n#ifndef __ENUM_DIR_ITEMS_H\r\n#define __ENUM_DIR_ITEMS_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"DirItem.h\"\r\n\r\nvoid AddDirFileInfo(int phyParent, int logParent,\r\n    const NWindows::NFile::NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems);\r\n\r\nstruct IEnumDirItemCallback\r\n{\r\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) = 0;\r\n};\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor,\r\n    CDirItems &dirItems,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ExitCode.h",
    "content": "// ExitCode.h\r\n\r\n#ifndef __EXIT_CODE_H\r\n#define __EXIT_CODE_H\r\n\r\nnamespace NExitCode {\r\n\r\nenum EEnum {\r\n\r\n  kSuccess       = 0,     // Successful operation\r\n  kWarning       = 1,     // Non fatal error(s) occurred\r\n  kFatalError    = 2,     // A fatal error occurred\r\n  // kCRCError      = 3,     // A CRC error occurred when unpacking\r\n  // kLockedArchive = 4,     // Attempt to modify an archive previously locked\r\n  // kWriteError    = 5,     // Write to disk error\r\n  // kOpenError     = 6,     // Open file error\r\n  kUserError     = 7,     // Command line option error\r\n  kMemoryError   = 8,     // Not enough memory for operation\r\n  // kCreateFileError = 9,     // Create file error\r\n  \r\n  kUserBreak     = 255   // User stopped the process\r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/Extract.cpp",
    "content": "// Extract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Extract.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n#include \"SetProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic HRESULT DecompressArchive(\r\n    IInArchive *archive,\r\n    UInt64 packSize,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IExtractCallbackUI *callback,\r\n    CArchiveExtractCallback *extractCallbackSpec,\r\n    UString &errorMessage)\r\n{\r\n  CRecordVector<UInt32> realIndices;\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UString filePath;\r\n    RINOK(GetArchiveItemPath(archive, i, options.DefaultItemName, filePath));\r\n    bool isFolder;\r\n    RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n    if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n      continue;\r\n    realIndices.Add(i);\r\n  }\r\n  if (realIndices.Size() == 0)\r\n  {\r\n    callback->ThereAreNoFiles();\r\n    return S_OK;\r\n  }\r\n\r\n  UStringVector removePathParts;\r\n\r\n  UString outDir = options.OutputDir;\r\n  outDir.Replace(L\"*\", options.DefaultItemName);\r\n  #ifdef _WIN32\r\n  outDir.TrimRight();\r\n  #endif\r\n\r\n  if(!outDir.IsEmpty())\r\n    if(!NFile::NDirectory::CreateComplexDirectory(outDir))\r\n    {\r\n      HRESULT res = ::GetLastError();\r\n      if (res == S_OK)\r\n        res = E_FAIL;\r\n      errorMessage = ((UString)L\"Can not create output directory \") + outDir;\r\n      return res;\r\n    }\r\n\r\n  extractCallbackSpec->Init(\r\n      archive,\r\n      callback,\r\n      options.StdOutMode,\r\n      outDir,\r\n      removePathParts,\r\n      options.DefaultItemName,\r\n      options.ArchiveFileInfo.MTime,\r\n      options.ArchiveFileInfo.Attrib,\r\n      packSize);\r\n\r\n  #ifdef COMPRESS_MT\r\n  RINOK(SetProperties(archive, options.Properties));\r\n  #endif\r\n\r\n  HRESULT result = archive->Extract(&realIndices.Front(),\r\n    realIndices.Size(), options.TestMode? 1: 0, extractCallbackSpec);\r\n\r\n  return callback->ExtractResult(result);\r\n}\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &optionsSpec,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage,\r\n    CDecompressStat &stat)\r\n{\r\n  stat.Clear();\r\n  CExtractOptions options = optionsSpec;\r\n  int i;\r\n  UInt64 totalPackSize = 0;\r\n  CRecordVector<UInt64> archiveSizes;\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archivePath, fi))\r\n      throw \"there is no such archive\";\r\n    if (fi.IsDir())\r\n      throw \"can't decompress folder\";\r\n    archiveSizes.Add(fi.Size);\r\n    totalPackSize += fi.Size;\r\n  }\r\n  CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n  CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);\r\n  bool multi = (archivePaths.Size() > 1);\r\n  extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);\r\n  if (multi)\r\n  {\r\n    RINOK(extractCallback->SetTotal(totalPackSize));\r\n  }\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archivePath, fi))\r\n      throw \"there is no such archive\";\r\n\r\n    if (fi.IsDir())\r\n      throw \"there is no such archive\";\r\n\r\n    options.ArchiveFileInfo = fi;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    openCallback->Open_ClearPasswordWasAskedFlag();\r\n    #endif\r\n\r\n    RINOK(extractCallback->BeforeOpen(archivePath));\r\n    CArchiveLink archiveLink;\r\n\r\n    CIntVector formatIndices2 = formatIndices;\r\n    #ifndef _SFX\r\n    if (formatIndices.IsEmpty())\r\n    {\r\n      int pos = archivePath.ReverseFind(L'.');\r\n      if (pos >= 0)\r\n      {\r\n        UString s = archivePath.Mid(pos + 1);\r\n        int index = codecs->FindFormatForExtension(s);\r\n        if (index >= 0 && s == L\"001\")\r\n        {\r\n          s = archivePath.Left(pos);\r\n          pos = s.ReverseFind(L'.');\r\n          if (pos >= 0)\r\n          {\r\n            int index2 = codecs->FindFormatForExtension(s.Mid(pos + 1));\r\n            if (index2 >= 0 && s.CompareNoCase(L\"rar\") != 0)\r\n            {\r\n              formatIndices2.Add(index2);\r\n              formatIndices2.Add(index);\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n    #endif\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices2, archivePath, archiveLink, openCallback);\r\n    if (result == E_ABORT)\r\n      return result;\r\n\r\n    bool crypted = false;\r\n    #ifndef _NO_CRYPTO\r\n    crypted = openCallback->Open_WasPasswordAsked();\r\n    #endif\r\n\r\n    RINOK(extractCallback->OpenResult(archivePath, result, crypted));\r\n    if (result != S_OK)\r\n      continue;\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n        totalPackSize -= archiveSizes[index];\r\n        archiveSizes.Delete(index);\r\n      }\r\n    }\r\n    if (archiveLink.VolumePaths.Size() != 0)\r\n    {\r\n      totalPackSize += archiveLink.VolumesSize;\r\n      RINOK(extractCallback->SetTotal(totalPackSize));\r\n    }\r\n\r\n    #ifndef _NO_CRYPTO\r\n    UString password;\r\n    RINOK(openCallback->Open_GetPasswordIfAny(password));\r\n    if (!password.IsEmpty())\r\n    {\r\n      RINOK(extractCallback->SetPassword(password));\r\n    }\r\n    #endif\r\n\r\n    options.DefaultItemName = archiveLink.GetDefaultItemName();\r\n    RINOK(DecompressArchive(\r\n        archiveLink.GetArchive(),\r\n        fi.Size + archiveLink.VolumesSize,\r\n        wildcardCensor, options, extractCallback, extractCallbackSpec, errorMessage));\r\n    extractCallbackSpec->LocalProgressSpec->InSize += fi.Size +\r\n        archiveLink.VolumesSize;\r\n    extractCallbackSpec->LocalProgressSpec->OutSize = extractCallbackSpec->UnpackSize;\r\n    if (!errorMessage.IsEmpty())\r\n      return E_FAIL;\r\n  }\r\n  stat.NumFolders = extractCallbackSpec->NumFolders;\r\n  stat.NumFiles = extractCallbackSpec->NumFiles;\r\n  stat.UnpackSize = extractCallbackSpec->UnpackSize;\r\n  stat.NumArchives = archivePaths.Size();\r\n  stat.PackSize = extractCallbackSpec->LocalProgressSpec->InSize;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/Extract.h",
    "content": "// Extract.h\r\n\r\n#ifndef __EXTRACT_H\r\n#define __EXTRACT_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"ExtractMode.h\"\r\n#include \"Property.h\"\r\n\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nclass CExtractOptions\r\n{\r\npublic:\r\n  bool StdOutMode;\r\n  bool TestMode;\r\n  NExtract::NPathMode::EEnum PathMode;\r\n\r\n  UString OutputDir;\r\n  bool YesToAll;\r\n  UString DefaultItemName;\r\n  NWindows::NFile::NFind::CFileInfoW ArchiveFileInfo;\r\n  \r\n  // bool ShowDialog;\r\n  // bool PasswordEnabled;\r\n  // UString Password;\r\n  #ifdef COMPRESS_MT\r\n  CObjectVector<CProperty> Properties;\r\n  #endif\r\n\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  CCodecs *Codecs;\r\n  #endif\r\n\r\n  CExtractOptions():\r\n      StdOutMode(false),\r\n      YesToAll(false),\r\n      TestMode(false),\r\n      PathMode(NExtract::NPathMode::kFullPathnames),\r\n      OverwriteMode(NExtract::NOverwriteMode::kAskBefore)\r\n      {}\r\n\r\n  /*\r\n    bool FullPathMode() const { return (ExtractMode == NExtractMode::kTest) ||\r\n    (ExtractMode == NExtractMode::kFullPath); }\r\n  */\r\n};\r\n\r\nstruct CDecompressStat\r\n{\r\n  UInt64 NumArchives;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  void Clear() { NumArchives = PackSize = UnpackSize = NumFolders = NumFiles = 0; }\r\n};\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage,\r\n    CDecompressStat &stat);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ExtractMode.h",
    "content": "// ExtractMode.h\r\n\r\n#ifndef __EXTRACT_MODE_H\r\n#define __EXTRACT_MODE_H\r\n\r\nnamespace NExtract {\r\n  \r\n  namespace NPathMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kFullPathnames,\r\n      kCurrentPathnames,\r\n      kNoPathnames\r\n    };\r\n  }\r\n  \r\n  namespace NOverwriteMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kAskBefore,\r\n      kWithoutPrompt,\r\n      kSkipExisting,\r\n      kAutoRename,\r\n      kAutoRenameExisting\r\n    };\r\n  }\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp",
    "content": "// ExtractingFilePath.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ExtractingFilePath.h\"\r\n\r\nstatic UString ReplaceIncorrectChars(const UString &s)\r\n{\r\n  #ifdef _WIN32\r\n  UString res;\r\n  for (int i = 0; i < s.Length(); i++)\r\n  {\r\n    wchar_t c = s[i];\r\n    if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>'  || c == '|' || c == ':' || c == '\"')\r\n      c = '_';\r\n    res += c;\r\n  }\r\n  res.TrimRight();\r\n  return res;\r\n  #else\r\n  return s;\r\n  #endif\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t *g_ReservedNames[] =\r\n{\r\n  L\"CON\", L\"PRN\", L\"AUX\", L\"NUL\"\r\n};\r\n\r\nstatic bool CheckTail(const UString &name, int len)\r\n{\r\n  int dotPos = name.Find(L'.');\r\n  if (dotPos < 0)\r\n    dotPos = name.Length();\r\n  UString s = name.Left(dotPos);\r\n  s.TrimRight();\r\n  return (s.Length() != len);\r\n}\r\n\r\nstatic bool CheckNameNum(const UString &name, const wchar_t *reservedName)\r\n{\r\n  int len = MyStringLen(reservedName);\r\n  if (name.Length() <= len)\r\n    return true;\r\n  if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n    return true;\r\n  wchar_t c = name[len];\r\n  if (c < L'0' || c > L'9')\r\n    return true;\r\n  return CheckTail(name, len + 1);\r\n}\r\n\r\nstatic bool IsSupportedName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++)\r\n  {\r\n    const wchar_t *reservedName = g_ReservedNames[i];\r\n    int len = MyStringLen(reservedName);\r\n    if (name.Length() < len)\r\n      continue;\r\n    if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n      continue;\r\n    if (!CheckTail(name, len))\r\n      return false;\r\n  }\r\n  if (!CheckNameNum(name, L\"COM\"))\r\n    return false;\r\n  return CheckNameNum(name, L\"LPT\");\r\n}\r\n#endif\r\n\r\nstatic UString GetCorrectFileName(const UString &path)\r\n{\r\n  if (path == L\"..\" || path == L\".\")\r\n    return UString();\r\n  return ReplaceIncorrectChars(path);\r\n}\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts)\r\n{\r\n  for (int i = 0; i < pathParts.Size();)\r\n  {\r\n    UString &s = pathParts[i];\r\n    s = GetCorrectFileName(s);\r\n    if (s.IsEmpty())\r\n      pathParts.Delete(i);\r\n    else\r\n    {\r\n      #ifdef _WIN32\r\n      if (!IsSupportedName(s))\r\n        s = (UString)L\"_\" + s;\r\n      #endif\r\n      i++;\r\n    }\r\n  }\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h",
    "content": "// ExtractingFilePath.h\r\n\r\n#ifndef __EXTRACTINGFILEPATH_H\r\n#define __EXTRACTINGFILEPATH_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h",
    "content": "// IFileExtractCallback.h\r\n\r\n#ifndef __IFILEEXTRACTCALLBACK_H\r\n#define __IFILEEXTRACTCALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"../../IDecl.h\"\r\n\r\nnamespace NOverwriteAnswer\r\n{\r\n  enum EEnum\r\n  {\r\n    kYes,\r\n    kYesToAll,\r\n    kNo,\r\n    kNoToAll,\r\n    kAutoRename,\r\n    kCancel\r\n  };\r\n}\r\n\r\nDECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)\r\n{\r\npublic:\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer) PURE;\r\n  STDMETHOD(PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position) PURE;\r\n  STDMETHOD(MessageError)(const wchar_t *message) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE;\r\n};\r\n\r\nstruct IExtractCallbackUI: IFolderArchiveExtractCallback\r\n{\r\n  virtual HRESULT BeforeOpen(const wchar_t *name) = 0;\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted) = 0;\r\n  virtual HRESULT ThereAreNoFiles() = 0;\r\n  virtual HRESULT ExtractResult(HRESULT result) = 0;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  virtual HRESULT SetPassword(const UString &password) = 0;\r\n  #endif\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp",
    "content": "// LoadCodecs.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LoadCodecs.h\"\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Common/StringToInt.h\"\r\n#endif\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/FileFind.h\"\r\n#include \"../../../Windows/DLL.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Windows/ResourceString.h\"\r\nstatic const UINT kIconTypesResId = 100;\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/Registry.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\n#ifdef _WIN32\r\nextern HINSTANCE g_hInstance;\r\n#endif\r\n\r\nstatic CSysString GetLibraryFolderPrefix()\r\n{\r\n  #ifdef _WIN32\r\n  TCHAR fullPath[MAX_PATH + 1];\r\n  ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);\r\n  CSysString path = fullPath;\r\n  int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  return path.Left(pos + 1);\r\n  #else\r\n  return CSysString(); // FIX IT\r\n  #endif\r\n}\r\n\r\n#define kCodecsFolderName TEXT(\"Codecs\")\r\n#define kFormatsFolderName TEXT(\"Formats\")\r\nstatic const TCHAR *kMainDll = TEXT(\"7z.dll\");\r\n\r\n#ifdef _WIN32\r\nstatic LPCTSTR kRegistryPath = TEXT(\"Software\") TEXT(STRING_PATH_SEPARATOR) TEXT(\"7-zip\");\r\nstatic LPCTSTR kProgramPathValue = TEXT(\"Path\");\r\nstatic bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)\r\n{\r\n  NRegistry::CKey key;\r\n  if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)\r\n    if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)\r\n    {\r\n      NName::NormalizeDirPathPrefix(path);\r\n      return true;\r\n    }\r\n  return false;\r\n}\r\n\r\n#endif\r\n\r\nCSysString GetBaseFolderPrefixFromRegistry()\r\n{\r\n  CSysString moduleFolderPrefix = GetLibraryFolderPrefix();\r\n  NFind::CFileInfo fi;\r\n  if (NFind::FindFile(moduleFolderPrefix + kMainDll, fi))\r\n    if (!fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fi))\r\n    if (fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fi))\r\n    if (fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  #ifdef _WIN32\r\n  CSysString path;\r\n  if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))\r\n    return path;\r\n  if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))\r\n    return path;\r\n  #endif\r\n  return moduleFolderPrefix;\r\n}\r\n\r\ntypedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);\r\ntypedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, void **outObject);\r\ntypedef UInt32 (WINAPI *SetLargePageModeFunc)();\r\n\r\n\r\nstatic HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 index,\r\n    PROPID propId, CLSID &clsId, bool &isAssigned)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  isAssigned = false;\r\n  RINOK(getMethodProperty(index, propId, &prop));\r\n  if (prop.vt == VT_BSTR)\r\n  {\r\n    isAssigned = true;\r\n    clsId = *(const GUID *)prop.bstrVal;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::LoadCodecs()\r\n{\r\n  CCodecLib &lib = Libs.Back();\r\n  lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress(\"GetMethodProperty\");\r\n  if (lib.GetMethodProperty == NULL)\r\n    return S_OK;\r\n\r\n  UInt32 numMethods = 1;\r\n  GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProcAddress(\"GetNumberOfMethods\");\r\n  if (getNumberOfMethodsFunc != NULL)\r\n  {\r\n    RINOK(getNumberOfMethodsFunc(&numMethods));\r\n  }\r\n\r\n  for(UInt32 i = 0; i < numMethods; i++)\r\n  {\r\n    CDllCodecInfo info;\r\n    info.LibIndex = Libs.Size() - 1;\r\n    info.CodecIndex = i;\r\n\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));\r\n\r\n    Codecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, NCOM::CPropVariant &prop)\r\n{\r\n  if (getProp2)\r\n    return getProp2(index, propID, &prop);;\r\n  return getProp(propID, &prop);\r\n}\r\n\r\nstatic HRESULT ReadBoolProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadStringProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, UString &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BSTR)\r\n    res = prop.bstrVal;\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\r\nvoid RegisterArc(const CArcInfo *arcInfo)\r\n{\r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo;\r\n}\r\n\r\nstatic void SplitString(const UString &srcString, UStringVector &destStrings)\r\n{\r\n  destStrings.Clear();\r\n  UString s;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L' ')\r\n    {\r\n      if (!s.IsEmpty())\r\n      {\r\n        destStrings.Add(s);\r\n        s.Empty();\r\n      }\r\n    }\r\n    else\r\n      s += c;\r\n  }\r\n  if (!s.IsEmpty())\r\n    destStrings.Add(s);\r\n}\r\n\r\nvoid CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt)\r\n{\r\n  UStringVector exts, addExts;\r\n  SplitString(ext, exts);\r\n  if (addExt != 0)\r\n    SplitString(addExt, addExts);\r\n  for (int i = 0; i < exts.Size(); i++)\r\n  {\r\n    CArcExtInfo extInfo;\r\n    extInfo.Ext = exts[i];\r\n    if (i < addExts.Size())\r\n    {\r\n      extInfo.AddExt = addExts[i];\r\n      if (extInfo.AddExt == L\"*\")\r\n        extInfo.AddExt.Empty();\r\n    }\r\n    Exts.Add(extInfo);\r\n  }\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nHRESULT CCodecs::LoadFormats()\r\n{\r\n  const NDLL::CLibrary &lib = Libs.Back().Lib;\r\n  GetHandlerPropertyFunc getProp = 0;\r\n  GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)\r\n      lib.GetProcAddress(\"GetHandlerProperty2\");\r\n  if (getProp2 == NULL)\r\n  {\r\n    getProp = (GetHandlerPropertyFunc)\r\n        lib.GetProcAddress(\"GetHandlerProperty\");\r\n    if (getProp == NULL)\r\n      return S_OK;\r\n  }\r\n\r\n  UInt32 numFormats = 1;\r\n  GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)\r\n    lib.GetProcAddress(\"GetNumberOfFormats\");\r\n  if (getNumberOfFormats != NULL)\r\n  {\r\n    RINOK(getNumberOfFormats(&numFormats));\r\n  }\r\n  if (getProp2 == NULL)\r\n    numFormats = 1;\r\n\r\n  for(UInt32 i = 0; i < numFormats; i++)\r\n  {\r\n    CArcInfoEx item;\r\n    item.LibIndex = Libs.Size() - 1;\r\n    item.FormatIndex = i;\r\n\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)\r\n      continue;\r\n    if (prop.vt != VT_BSTR)\r\n      continue;\r\n    item.ClassID = *(const GUID *)prop.bstrVal;\r\n    prop.Clear();\r\n\r\n    UString ext, addExt;\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));\r\n    item.AddExts(ext, addExt);\r\n\r\n    ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);\r\n    if (item.UpdateEnabled)\r\n      ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);\r\n    \r\n    if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)\r\n      if (prop.vt == VT_BSTR)\r\n      {\r\n        UINT len = ::SysStringByteLen(prop.bstrVal);\r\n        item.StartSignature.SetCapacity(len);\r\n        memmove(item.StartSignature, prop.bstrVal, len);\r\n      }\r\n    Formats.Add(item);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef NEW_FOLDER_INTERFACE\r\nvoid CCodecLib::LoadIcons()\r\n{\r\n  UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId);\r\n  UStringVector pairs;\r\n  SplitString(iconTypes, pairs);\r\n  for (int i = 0; i < pairs.Size(); i++)\r\n  {\r\n    const UString &s = pairs[i];\r\n    int pos = s.Find(L':');\r\n    if (pos < 0)\r\n      continue;\r\n    CIconPair iconPair;\r\n    const wchar_t *end;\r\n    UString num = s.Mid(pos + 1);\r\n    iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);\r\n    if (*end != L'\\0')\r\n      continue;\r\n    iconPair.Ext = s.Left(pos);\r\n    IconPairs.Add(iconPair);\r\n  }\r\n}\r\n\r\nint CCodecLib::FindIconIndex(const UString &ext) const\r\n{\r\n  for (int i = 0; i < IconPairs.Size(); i++)\r\n  {\r\n    const CIconPair &pair = IconPairs[i];\r\n    if (ext.CompareNoCase(pair.Ext) == 0)\r\n      return pair.IconIndex;\r\n  }\r\n  return -1;\r\n}\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nextern \"C\"\r\n{\r\n  extern SIZE_T g_LargePageSize;\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::LoadDll(const CSysString &dllPath)\r\n{\r\n  {\r\n    NDLL::CLibrary library;\r\n    if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))\r\n      return S_OK;\r\n  }\r\n  Libs.Add(CCodecLib());\r\n  CCodecLib &lib = Libs.Back();\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  lib.Path = dllPath;\r\n  #endif\r\n  bool used = false;\r\n  HRESULT res = S_OK;\r\n  if (lib.Lib.Load(dllPath))\r\n  {\r\n    #ifdef NEW_FOLDER_INTERFACE\r\n    lib.LoadIcons();\r\n    #endif\r\n\r\n    #ifdef _7ZIP_LARGE_PAGES\r\n    if (g_LargePageSize != 0)\r\n    {\r\n      SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProcAddress(\"SetLargePageMode\");\r\n      if (setLargePageMode != 0)\r\n        setLargePageMode();\r\n    }\r\n    #endif\r\n\r\n    lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress(\"CreateObject\");\r\n    if (lib.CreateObject != 0)\r\n    {\r\n      int startSize = Codecs.Size();\r\n      res = LoadCodecs();\r\n      used = (Codecs.Size() != startSize);\r\n      if (res == S_OK)\r\n      {\r\n        startSize = Formats.Size();\r\n        res = LoadFormats();\r\n        used = used || (Formats.Size() != startSize);\r\n      }\r\n    }\r\n  }\r\n  if (!used)\r\n    Libs.DeleteBack();\r\n  return res;\r\n}\r\n\r\nHRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)\r\n{\r\n  NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT(\"*\")));\r\n  NFile::NFind::CFileInfo fi;\r\n  while (enumerator.Next(fi))\r\n  {\r\n    if (fi.IsDir())\r\n      continue;\r\n    RINOK(LoadDll(folderPrefix + fi.Name));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n#ifndef _SFX\r\nstatic inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)\r\n{\r\n  bb.SetCapacity(size);\r\n  memmove((Byte *)bb, data, size);\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::Load()\r\n{\r\n  Formats.Clear();\r\n  #ifdef EXTERNAL_CODECS\r\n  Codecs.Clear();\r\n  #endif\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n  {\r\n    const CArcInfo &arc = *g_Arcs[i];\r\n    CArcInfoEx item;\r\n    item.Name = arc.Name;\r\n    item.CreateInArchive = arc.CreateInArchive;\r\n    item.CreateOutArchive = arc.CreateOutArchive;\r\n    item.AddExts(arc.Ext, arc.AddExt);\r\n    item.UpdateEnabled = (arc.CreateOutArchive != 0);\r\n    item.KeepName = arc.KeepName;\r\n\r\n    #ifndef _SFX\r\n    SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);\r\n    #endif\r\n    Formats.Add(item);\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();\r\n  RINOK(LoadDll(baseFolder + kMainDll));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nint CCodecs::FindFormatForArchiveName(const UString &arcPath) const\r\n{\r\n  int slashPos1 = arcPath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  int slashPos2 = arcPath.ReverseFind(L'.');\r\n  int dotPos = arcPath.ReverseFind(L'.');\r\n  if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)\r\n    return -1;\r\n  UString ext = arcPath.Mid(dotPos + 1);\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    // if (arc.FindExtension(ext) >= 0)\r\n    UString mainExt = arc.GetMainExt();\r\n    if (!mainExt.IsEmpty() && ext.CompareNoCase(mainExt) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForExtension(const UString &ext) const\r\n{\r\n  if (ext.IsEmpty())\r\n    return -1;\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n    if (Formats[i].FindExtension(ext) >= 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveType(const UString &arcType) const\r\n{\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n    if (Formats[i].Name.CompareNoCase(arcType) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nbool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const\r\n{\r\n  formatIndices.Clear();\r\n  for (int pos = 0; pos < arcType.Length();)\r\n  {\r\n    int pos2 = arcType.Find('.', pos);\r\n    if (pos2 < 0)\r\n      pos2 = arcType.Length();\r\n    const UString name = arcType.Mid(pos, pos2 - pos);\r\n    int index = FindFormatForArchiveType(name);\r\n    if (index < 0 && name != L\"*\")\r\n    {\r\n      formatIndices.Clear();\r\n      return false;\r\n    }\r\n    formatIndices.Add(index);\r\n    pos = pos2 + 1;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\n#ifdef EXPORT_CODECS\r\nextern unsigned int g_NumCodecs;\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);\r\n// STDAPI GetNumberOfMethods(UInt32 *numCodecs);\r\n#endif\r\n\r\nSTDMETHODIMP CCodecs::GetNumberOfMethods(UInt32 *numMethods)\r\n{\r\n  *numMethods =\r\n      #ifdef EXPORT_CODECS\r\n      g_NumCodecs +\r\n      #endif\r\n      Codecs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return GetMethodProperty(index, propID, value);\r\n  #endif\r\n\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n\r\n  if (propID == NMethodPropID::kDecoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.DecoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  if (propID == NMethodPropID::kEncoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.EncoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(false, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.DecoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(true, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.EncoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const\r\n{\r\n  for (int i = 0; i < Codecs.Size(); i++)\r\n  {\r\n    const CDllCodecInfo &codec = Codecs[i];\r\n    if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigned)\r\n      continue;\r\n    const CCodecLib &lib = Libs[codec.LibIndex];\r\n    UString res;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      res = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      continue;\r\n    if (name.CompareNoCase(res) == 0)\r\n      return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICompressCoder, (void **)&coder);\r\n  }\r\n  return CLASS_E_CLASSNOTAVAILABLE;\r\n}\r\n\r\nint CCodecs::GetCodecLibIndex(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return -1;\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.LibIndex;\r\n  #else\r\n  return -1;\r\n  #endif\r\n}\r\n\r\nbool CCodecs::GetCodecEncoderIsAssigned(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n  {\r\n    NWindows::NCOM::CPropVariant prop;\r\n    if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK)\r\n      if (prop.vt != VT_EMPTY)\r\n        return true;\r\n    return false;\r\n  }\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.EncoderIsAssigned;\r\n  #else\r\n  return false;\r\n  #endif\r\n}\r\n\r\nHRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(GetProperty(index, NMethodPropID::kID, &prop));\r\n  if (prop.vt != VT_UI8)\r\n    return E_INVALIDARG;\r\n  id = prop.uhVal.QuadPart;\r\n  return S_OK;\r\n}\r\n\r\nUString CCodecs::GetCodecName(UInt32 index)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK)\r\n    if (prop.vt == VT_BSTR)\r\n      s = prop.bstrVal;\r\n  return s;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/LoadCodecs.h",
    "content": "// LoadCodecs.h\r\n\r\n#ifndef __LOADCODECS_H\r\n#define __LOADCODECS_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/DLL.h\"\r\n#endif\r\n\r\nstruct CDllCodecInfo\r\n{\r\n  CLSID Encoder;\r\n  CLSID Decoder;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  int LibIndex;\r\n  UInt32 CodecIndex;\r\n};\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcExtInfo\r\n{\r\n  UString Ext;\r\n  UString AddExt;\r\n  CArcExtInfo() {}\r\n  CArcExtInfo(const UString &ext): Ext(ext) {}\r\n  CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}\r\n};\r\n\r\n\r\nstruct CArcInfoEx\r\n{\r\n  #ifdef EXTERNAL_CODECS\r\n  int LibIndex;\r\n  UInt32 FormatIndex;\r\n  CLSID ClassID;\r\n  #endif\r\n  bool UpdateEnabled;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n  UString Name;\r\n  CObjectVector<CArcExtInfo> Exts;\r\n  #ifndef _SFX\r\n  CByteBuffer StartSignature;\r\n  // CByteBuffer FinishSignature;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  UStringVector AssociateExts;\r\n  #endif\r\n  #endif\r\n  bool KeepName;\r\n  UString GetMainExt() const\r\n  {\r\n    if (Exts.IsEmpty())\r\n      return UString();\r\n    return Exts[0].Ext;\r\n  }\r\n  int FindExtension(const UString &ext) const\r\n  {\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n      if (ext.CompareNoCase(Exts[i].Ext) == 0)\r\n        return i;\r\n    return -1;\r\n  }\r\n  UString GetAllExtensions() const\r\n  {\r\n    UString s;\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n    {\r\n      if (i > 0)\r\n        s += ' ';\r\n      s += Exts[i].Ext;\r\n    }\r\n    return s;\r\n  }\r\n\r\n  void AddExts(const wchar_t* ext, const wchar_t* addExt);\r\n\r\n  CArcInfoEx():\r\n    #ifdef EXTERNAL_CODECS\r\n    LibIndex(-1),\r\n    #endif\r\n    UpdateEnabled(false),\r\n    CreateInArchive(0), CreateOutArchive(0),\r\n    KeepName(false)\r\n    #ifndef _SFX\r\n    #endif\r\n  {}\r\n};\r\n\r\n#ifdef EXTERNAL_CODECS\r\ntypedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);\r\n\r\n\r\nstruct CCodecLib\r\n{\r\n  NWindows::NDLL::CLibrary Lib;\r\n  GetMethodPropertyFunc GetMethodProperty;\r\n  CreateObjectFunc CreateObject;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  struct CIconPair\r\n  {\r\n    UString Ext;\r\n    UInt32 IconIndex;\r\n  };\r\n  CSysString Path;\r\n  CObjectVector<CIconPair> IconPairs;\r\n  void LoadIcons();\r\n  int FindIconIndex(const UString &ext) const;\r\n  #endif\r\n  CCodecLib(): GetMethodProperty(0) {}\r\n};\r\n#endif\r\n\r\nclass CCodecs:\r\n  #ifdef EXTERNAL_CODECS\r\n  public ICompressCodecsInfo,\r\n  #else\r\n  public IUnknown,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef EXTERNAL_CODECS\r\n  CObjectVector<CCodecLib> Libs;\r\n  CObjectVector<CDllCodecInfo> Codecs;\r\n  HRESULT LoadCodecs();\r\n  HRESULT LoadFormats();\r\n  HRESULT LoadDll(const CSysString &path);\r\n  HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);\r\n\r\n  HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const\r\n  {\r\n    return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);\r\n  }\r\n  #endif\r\n\r\npublic:\r\n  CObjectVector<CArcInfoEx> Formats;\r\n  HRESULT Load();\r\n  \r\n  #ifndef _SFX\r\n  int FindFormatForArchiveName(const UString &arcPath) const;\r\n  int FindFormatForExtension(const UString &ext) const;\r\n  int FindFormatForArchiveType(const UString &arcType) const;\r\n  bool FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const;\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder);\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder);\r\n  #endif\r\n\r\n  int GetCodecLibIndex(UInt32 index);\r\n  bool GetCodecEncoderIsAssigned(UInt32 index);\r\n  HRESULT GetCodecId(UInt32 index, UInt64 &id);\r\n  UString GetCodecName(UInt32 index);\r\n\r\n  HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const\r\n  {\r\n    const CArcInfoEx &ai = Formats[formatIndex];\r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateInArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, false);\r\n    #endif\r\n  }\r\n  HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const\r\n  {\r\n    const CArcInfoEx &ai = Formats[formatIndex];\r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateOutArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, true);\r\n    #endif\r\n  }\r\n  int FindOutFormatFromName(const UString &name) const\r\n  {\r\n    for (int i = 0; i < Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = Formats[i];\r\n      if (!arc.UpdateEnabled)\r\n        continue;\r\n      if (arc.Name.CompareNoCase(name) == 0)\r\n        return i;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;\r\n  #endif\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/OpenArchive.cpp",
    "content": "// OpenArchive.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidPath, &prop));\r\n  if(prop.vt == VT_BSTR)\r\n    result = prop.bstrVal;\r\n  else if (prop.vt == VT_EMPTY)\r\n    result.Empty();\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result)\r\n{\r\n  RINOK(GetArchiveItemPath(archive, index, result));\r\n  if (result.IsEmpty())\r\n  {\r\n    result = defaultName;\r\n    NCOM::CPropVariant prop;\r\n    RINOK(archive->GetProperty(index, kpidExtension, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n    {\r\n      result += L'.';\r\n      result += prop.bstrVal;\r\n    }\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\r\n    const FILETIME &defaultFileTime, FILETIME &fileTime)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidMTime, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n    fileTime = prop.filetime;\r\n  else if (prop.vt == VT_EMPTY)\r\n    fileTime = defaultFileTime;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\r\n}\r\n\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsAnti, result);\r\n}\r\n\r\n// Static-SFX (for Linux) can be big.\r\nconst UInt64 kMaxCheckStartPosition = 1 << 22;\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  inStreamSpec->Open(fileName);\r\n  return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n}\r\n\r\n#ifndef _SFX\r\nstatic inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)\r\n{\r\n  for (size_t i = 0; i < size; i++)\r\n    if (p1[i] != p2[i])\r\n      return false;\r\n  return true;\r\n}\r\n#endif\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    IInStream *inStream,\r\n    const UString &fileName,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  *archiveResult = NULL;\r\n  UString extension;\r\n  {\r\n    int dotPos = fileName.ReverseFind(L'.');\r\n    if (dotPos >= 0)\r\n      extension = fileName.Mid(dotPos + 1);\r\n  }\r\n  CIntVector orderIndices;\r\n  if (arcTypeIndex >= 0)\r\n    orderIndices.Add(arcTypeIndex);\r\n  else\r\n  {\r\n\r\n  int i;\r\n  int numFinded = 0;\r\n  for (i = 0; i < codecs->Formats.Size(); i++)\r\n    if (codecs->Formats[i].FindExtension(extension) >= 0)\r\n      orderIndices.Insert(numFinded++, i);\r\n    else\r\n      orderIndices.Add(i);\r\n  \r\n  #ifndef _SFX\r\n  if (numFinded != 1)\r\n  {\r\n    CIntVector orderIndices2;\r\n    CByteBuffer byteBuffer;\r\n    const size_t kBufferSize = (1 << 21);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    size_t processedSize = kBufferSize;\r\n    RINOK(ReadStream(inStream, byteBuffer, &processedSize));\r\n    if (processedSize == 0)\r\n      return S_FALSE;\r\n\r\n    const Byte *buf = byteBuffer;\r\n    Byte hash[1 << 16];\r\n    memset(hash, 0xFF, 1 << 16);\r\n    Byte prevs[256];\r\n    if (orderIndices.Size() > 255)\r\n      return S_FALSE;\r\n    int i;\r\n    for (i = 0; i < orderIndices.Size(); i++)\r\n    {\r\n      const CArcInfoEx &ai = codecs->Formats[orderIndices[i]];\r\n      const CByteBuffer &sig = ai.StartSignature;\r\n      if (sig.GetCapacity() < 2)\r\n        continue;\r\n      UInt32 v = sig[0] | ((UInt32)sig[1] << 8);\r\n      prevs[i] = hash[v];\r\n      hash[v] = (Byte)i;\r\n    }\r\n\r\n    processedSize--;\r\n    for (UInt32 pos = 0; pos < processedSize; pos++)\r\n    {\r\n      for (; pos < processedSize && hash[buf[pos] | ((UInt32)buf[pos + 1] << 8)] == 0xFF; pos++);\r\n      if (pos == processedSize)\r\n        break;\r\n      UInt32 v = buf[pos] | ((UInt32)buf[pos + 1] << 8);\r\n      Byte *ptr = &hash[v];\r\n      int i = *ptr;\r\n      do\r\n      {\r\n        int index = orderIndices[i];\r\n        const CArcInfoEx &ai = codecs->Formats[index];\r\n        const CByteBuffer &sig = ai.StartSignature;\r\n        if (sig.GetCapacity() != 0 && pos + sig.GetCapacity() <= processedSize + 1)\r\n          if (TestSignature(buf + pos, sig, sig.GetCapacity()))\r\n          {\r\n            orderIndices2.Add(index);\r\n            orderIndices[i] = 0xFF;\r\n            *ptr = prevs[i];\r\n          }\r\n        ptr = &prevs[i];\r\n        i = *ptr;\r\n      }\r\n      while (i != 0xFF);\r\n    }\r\n    \r\n    for (i = 0; i < orderIndices.Size(); i++)\r\n    {\r\n      int val = orderIndices[i];\r\n      if (val != 0xFF)\r\n        orderIndices2.Add(val);\r\n    }\r\n    orderIndices = orderIndices2;\r\n\r\n    if (orderIndices.Size() >= 2)\r\n    {\r\n      int isoIndex = codecs->FindFormatForArchiveType(L\"iso\");\r\n      int udfIndex = codecs->FindFormatForArchiveType(L\"udf\");\r\n      int iIso = -1;\r\n      int iUdf = -1;\r\n      for (int i = 0; i < orderIndices.Size(); i++)\r\n      {\r\n        if (orderIndices[i] == isoIndex) iIso = i;\r\n        if (orderIndices[i] == udfIndex) iUdf = i;\r\n      }\r\n      if (iUdf == iIso + 1)\r\n      {\r\n        orderIndices[iUdf] = isoIndex;\r\n        orderIndices[iIso] = udfIndex;\r\n      }\r\n    }\r\n  }\r\n  else if (extension == L\"000\" || extension == L\"001\")\r\n  {\r\n    CByteBuffer byteBuffer;\r\n    const size_t kBufferSize = (1 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    size_t processedSize = kBufferSize;\r\n    RINOK(ReadStream(inStream, buffer, &processedSize));\r\n    if (processedSize >= 16)\r\n    {\r\n      Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};\r\n      if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] & 1) != 0)\r\n      {\r\n        for (int i = 0; i < orderIndices.Size(); i++)\r\n        {\r\n          int index = orderIndices[i];\r\n          const CArcInfoEx &ai = codecs->Formats[index];\r\n          if (ai.Name.CompareNoCase(L\"rar\") != 0)\r\n            continue;\r\n          orderIndices.Delete(i--);\r\n          orderIndices.Insert(0, index);\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n  }\r\n\r\n  for(int i = 0; i < orderIndices.Size(); i++)\r\n  {\r\n    inStream->Seek(0, STREAM_SEEK_SET, NULL);\r\n\r\n    CMyComPtr<IInArchive> archive;\r\n\r\n    formatIndex = orderIndices[i];\r\n    RINOK(codecs->CreateInArchive(formatIndex, archive));\r\n    if (!archive)\r\n      continue;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    HRESULT result = archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n    if (result == S_FALSE)\r\n      continue;\r\n    RINOK(result);\r\n    *archiveResult = archive.Detach();\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex];\r\n    if (format.Exts.Size() == 0)\r\n    {\r\n      defaultItemName = GetDefaultName2(fileName, L\"\", L\"\");\r\n    }\r\n    else\r\n    {\r\n      int subExtIndex = format.FindExtension(extension);\r\n      if (subExtIndex < 0)\r\n        subExtIndex = 0;\r\n      defaultItemName = GetDefaultName2(fileName,\r\n          format.Exts[subExtIndex].Ext,\r\n          format.Exts[subExtIndex].AddExt);\r\n    }\r\n    return S_OK;\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &filePath,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  if (!inStreamSpec->Open(filePath))\r\n    return GetLastError();\r\n  return OpenArchive(codecs, arcTypeIndex, inStream, ExtractFileNameFromPath(filePath),\r\n    archiveResult, formatIndex,\r\n    defaultItemName, openArchiveCallback);\r\n}\r\n\r\nstatic void MakeDefaultName(UString &name)\r\n{\r\n  int dotPos = name.ReverseFind(L'.');\r\n  if (dotPos < 0)\r\n    return;\r\n  UString ext = name.Mid(dotPos + 1);\r\n  if (ext.IsEmpty())\r\n    return;\r\n  for (int pos = 0; pos < ext.Length(); pos++)\r\n    if (ext[pos] < L'0' || ext[pos] > L'9')\r\n      return;\r\n  name = name.Left(dotPos);\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &fileName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  if (formatIndices.Size() >= 3)\r\n    return E_NOTIMPL;\r\n  \r\n  int arcTypeIndex = -1;\r\n  if (formatIndices.Size() >= 1)\r\n    arcTypeIndex = formatIndices[formatIndices.Size() - 1];\r\n  \r\n  HRESULT result = OpenArchive(codecs, arcTypeIndex, fileName,\r\n    archive0, formatIndex0, defaultItemName0, openArchiveCallback);\r\n  RINOK(result);\r\n\r\n  if (formatIndices.Size() == 1)\r\n    return S_OK;\r\n  arcTypeIndex = -1;\r\n  if (formatIndices.Size() >= 2)\r\n    arcTypeIndex = formatIndices[formatIndices.Size() - 2];\r\n\r\n  HRESULT resSpec = (formatIndices.Size() == 0 ? S_OK : E_NOTIMPL);\r\n\r\n  CMyComPtr<IInArchiveGetStream> getStream;\r\n  result = (*archive0)->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream);\r\n  if (result != S_OK || !getStream)\r\n    return resSpec;\r\n\r\n  CMyComPtr<ISequentialInStream> subSeqStream;\r\n  result = getStream->GetStream(0, &subSeqStream);\r\n  if (result != S_OK || !subSeqStream)\r\n    return resSpec;\r\n\r\n  CMyComPtr<IInStream> subStream;\r\n  result = subSeqStream.QueryInterface(IID_IInStream, &subStream);\r\n  if (result != S_OK || !subStream)\r\n    return resSpec;\r\n\r\n  UInt32 numItems;\r\n  RINOK((*archive0)->GetNumberOfItems(&numItems));\r\n  if (numItems < 1)\r\n    return resSpec;\r\n\r\n  UString subPath;\r\n  RINOK(GetArchiveItemPath(*archive0, 0, subPath))\r\n  if (subPath.IsEmpty())\r\n  {\r\n    MakeDefaultName(defaultItemName0);\r\n    subPath = defaultItemName0;\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex0];\r\n    if (format.Name.CompareNoCase(L\"7z\") == 0)\r\n    {\r\n      if (subPath.Right(3).CompareNoCase(L\".7z\") != 0)\r\n        subPath += L\".7z\";\r\n    }\r\n  }\r\n  else\r\n    subPath = ExtractFileNameFromPath(subPath);\r\n\r\n  CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;\r\n  openArchiveCallback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);\r\n  if (setSubArchiveName)\r\n    setSubArchiveName->SetSubArchiveName(subPath);\r\n\r\n  result = OpenArchive(codecs, arcTypeIndex, subStream, subPath,\r\n      archive1, formatIndex1, defaultItemName1, openArchiveCallback);\r\n  resSpec = (formatIndices.Size() == 0 ? S_OK : S_FALSE);\r\n  if (result != S_OK)\r\n    return resSpec;\r\n  return S_OK;\r\n}\r\n\r\nstatic void SetCallback(const UString &archiveName,\r\n    IOpenCallbackUI *openCallbackUI,\r\n    IArchiveOpenCallback *reOpenCallback,\r\n    CMyComPtr<IArchiveOpenCallback> &openCallback)\r\n{\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n  openCallbackSpec->ReOpenCallback = reOpenCallback;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  openCallbackSpec->Init(\r\n      fullName.Left(fileNamePartStartIndex),\r\n      fullName.Mid(fileNamePartStartIndex));\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &archiveName,\r\n    IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI)\r\n{\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(archiveName, openCallbackUI, NULL, openCallback);\r\n  int formatInfo;\r\n  return OpenArchive(codecs, arcTypeIndex, archiveName, archive, formatInfo, defaultItemName, openCallback);\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  volumesSize = 0;\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  UString prefix = fullName.Left(fileNamePartStartIndex);\r\n  UString name = fullName.Mid(fileNamePartStartIndex);\r\n  openCallbackSpec->Init(prefix, name);\r\n\r\n  int formatIndex0, formatIndex1;\r\n  RINOK(OpenArchive(codecs, formatIndices, archiveName,\r\n      archive0,\r\n      archive1,\r\n      formatIndex0,\r\n      formatIndex1,\r\n      defaultItemName0,\r\n      defaultItemName1,\r\n      openCallback));\r\n  volumePaths.Add(prefix + name);\r\n  for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)\r\n    volumePaths.Add(prefix + openCallbackSpec->FileNames[i]);\r\n  volumesSize = openCallbackSpec->TotalSize;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveLink::Close()\r\n{\r\n  if (Archive1 != 0)\r\n    RINOK(Archive1->Close());\r\n  if (Archive0 != 0)\r\n    RINOK(Archive0->Close());\r\n  IsOpen = false;\r\n  return S_OK;\r\n}\r\n\r\nvoid CArchiveLink::Release()\r\n{\r\n  IsOpen = false;\r\n  Archive1.Release();\r\n  Archive0.Release();\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  HRESULT res = OpenArchive(codecs, formatIndices, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1,\r\n    archiveLink.FormatIndex0, archiveLink.FormatIndex1,\r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\r\n    openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT MyOpenArchive(CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  HRESULT res = MyOpenArchive(codecs, formatIndices, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1,\r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\r\n    archiveLink.VolumePaths,\r\n    archiveLink.VolumesSize,\r\n    openCallbackUI);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT ReOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, const UString &fileName,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  if (archiveLink.GetNumLevels() > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (archiveLink.GetNumLevels() == 0)\r\n    return MyOpenArchive(codecs, CIntVector(), fileName, archiveLink, 0);\r\n\r\n  CMyComPtr<IArchiveOpenCallback> openCallbackNew;\r\n  SetCallback(fileName, NULL, openCallback, openCallbackNew);\r\n\r\n  HRESULT res = ReOpenArchive(archiveLink.GetArchive(), fileName, openCallbackNew);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/OpenArchive.h",
    "content": "// OpenArchive.h\r\n\r\n#ifndef __OPENARCHIVE_H\r\n#define __OPENARCHIVE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"LoadCodecs.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result);\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result);\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\r\n    const FILETIME &defaultFileTime, FILETIME &fileTime);\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result);\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result);\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result);\r\n\r\nstruct ISetSubArchiveName\r\n{\r\n  virtual void SetSubArchiveName(const wchar_t *name) = 0;\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    IInStream *inStream,\r\n    const UString &fileName,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &filePath,\r\n    IInArchive **archive,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &filePath,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback);\r\n\r\nstruct CArchiveLink\r\n{\r\n  CMyComPtr<IInArchive> Archive0;\r\n  CMyComPtr<IInArchive> Archive1;\r\n  UString DefaultItemName0;\r\n  UString DefaultItemName1;\r\n\r\n  int FormatIndex0;\r\n  int FormatIndex1;\r\n  \r\n  UStringVector VolumePaths;\r\n\r\n  bool IsOpen;\r\n  UInt64 VolumesSize;\r\n\r\n  int GetNumLevels() const\r\n  {\r\n    int result = 0;\r\n    if (Archive0)\r\n    {\r\n      result++;\r\n      if (Archive1)\r\n        result++;\r\n    }\r\n    return result;\r\n  }\r\n\r\n  CArchiveLink(): IsOpen(false), VolumesSize(0) {};\r\n\r\n  IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; }\r\n  UString GetDefaultItemName()  { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; }\r\n  int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; }\r\n  HRESULT Close();\r\n  void Release();\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT ReOpenArchive(\r\n    CCodecs *codecs,\r\n    CArchiveLink &archiveLink,\r\n    const UString &fileName,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp",
    "content": "// PropIDUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropIDUtils.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../PropID.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic void ConvertUInt32ToHex(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    int t = value & 0xF;\r\n    value >>= 4;\r\n    s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));\r\n  }\r\n  s[8] = L'\\0';\r\n}\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full)\r\n{\r\n  switch(propID)\r\n  {\r\n    case kpidCTime:\r\n    case kpidATime:\r\n    case kpidMTime:\r\n    {\r\n      if (propVariant.vt != VT_FILETIME)\r\n        return UString(); // It is error;\r\n      FILETIME localFileTime;\r\n      if (propVariant.filetime.dwHighDateTime == 0 &&\r\n          propVariant.filetime.dwLowDateTime == 0)\r\n        return UString();\r\n      if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n        return UString(); // It is error;\r\n      return ConvertFileTimeToString(localFileTime, true, full);\r\n    }\r\n    case kpidCRC:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      wchar_t temp[12];\r\n      ConvertUInt32ToHex(propVariant.ulVal, temp);\r\n      return temp;\r\n    }\r\n    case kpidAttrib:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UString result;\r\n      UInt32 attributes = propVariant.ulVal;\r\n      if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';\r\n      if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';\r\n      if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';\r\n      if (NFile::NFind::NAttributes::IsDir(attributes)) result += L'D';\r\n      if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';\r\n      if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';\r\n      if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';\r\n      return result;\r\n    }\r\n    case kpidDictionarySize:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UInt32 size = propVariant.ulVal;\r\n      if (size % (1 << 20) == 0)\r\n        return ConvertUInt32ToString(size >> 20) + L\"MB\";\r\n      if (size % (1 << 10) == 0)\r\n        return ConvertUInt32ToString(size >> 10) + L\"KB\";\r\n      return ConvertUInt32ToString(size);\r\n    }\r\n  }\r\n  return ConvertPropVariantToString(propVariant);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/PropIDUtils.h",
    "content": "// PropIDUtils.h\r\n\r\n#ifndef __PROPIDUTILS_H\r\n#define __PROPIDUTILS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/Property.h",
    "content": "// Property.h\r\n\r\n#ifndef __PROPERTY_H\r\n#define __PROPERTY_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nstruct CProperty\r\n{\r\n  UString Name;\r\n  UString Value;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/SetProperties.cpp",
    "content": "// SetProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SetProperties.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\n\r\nstatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)\r\n{\r\n  const wchar_t *endPtr;\r\n  UInt64 result = ConvertStringToUInt64(s, &endPtr);\r\n  if (endPtr - (const wchar_t *)s != s.Length())\r\n    prop = s;\r\n  else if (result <= 0xFFFFFFFF)\r\n    prop = (UInt32)result;\r\n  else\r\n    prop = result;\r\n}\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)\r\n{\r\n  if (properties.IsEmpty())\r\n    return S_OK;\r\n  CMyComPtr<ISetProperties> setProperties;\r\n  unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);\r\n  if (!setProperties)\r\n    return S_OK;\r\n\r\n  UStringVector realNames;\r\n  CPropVariant *values = new CPropVariant[properties.Size()];\r\n  try\r\n  {\r\n    int i;\r\n    for(i = 0; i < properties.Size(); i++)\r\n    {\r\n      const CProperty &property = properties[i];\r\n      NCOM::CPropVariant propVariant;\r\n      UString name = property.Name;\r\n      if (property.Value.IsEmpty())\r\n      {\r\n        if (!name.IsEmpty())\r\n        {\r\n          wchar_t c = name[name.Length() - 1];\r\n          if (c == L'-')\r\n            propVariant = false;\r\n          else if (c == L'+')\r\n            propVariant = true;\r\n          if (propVariant.vt != VT_EMPTY)\r\n            name = name.Left(name.Length() - 1);\r\n        }\r\n      }\r\n      else\r\n        ParseNumberString(property.Value, propVariant);\r\n      realNames.Add(name);\r\n      values[i] = propVariant;\r\n    }\r\n    CRecordVector<const wchar_t *> names;\r\n    for(i = 0; i < realNames.Size(); i++)\r\n      names.Add((const wchar_t *)realNames[i]);\r\n    \r\n    RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));\r\n  }\r\n  catch(...)\r\n  {\r\n    delete []values;\r\n    throw;\r\n  }\r\n  delete []values;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/SetProperties.h",
    "content": "// SetProperties.h\r\n\r\n#ifndef __SETPROPERTIES_H\r\n#define __SETPROPERTIES_H\r\n\r\n#include \"Property.h\"\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/SortUtils.cpp",
    "content": "// SortUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SortUtils.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nstatic int CompareStrings(const int *p1, const int *p2, void *param)\r\n{\r\n  const UStringVector &strings = *(const UStringVector *)param;\r\n  return CompareFileNames(strings[*p1], strings[*p2]);\r\n}\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numItems = strings.Size();\r\n  indices.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n    indices.Add(i);\r\n  indices.Sort(CompareStrings, (void *)&strings);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/SortUtils.h",
    "content": "// SortUtils.h\r\n\r\n#ifndef __SORTUTLS_H\r\n#define __SORTUTLS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/StdAfx.h",
    "content": "// stdafx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/TempFiles.cpp",
    "content": "// TempFiles.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"TempFiles.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileIO.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nvoid CTempFiles::Clear()\r\n{\r\n  while(!Paths.IsEmpty())\r\n  {\r\n    NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());\r\n    Paths.DeleteBack();\r\n  }\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/TempFiles.h",
    "content": "// TempFiles.h\r\n\r\n#ifndef __TEMPFILES_H\r\n#define __TEMPFILES_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nclass CTempFiles\r\n{\r\n  void Clear();\r\npublic:\r\n  UStringVector Paths;\r\n  ~CTempFiles() { Clear(); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/Update.cpp",
    "content": "// Update.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Update.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/DLL.h\"\r\n#endif\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/DirItem.h\"\r\n#include \"../Common/EnumDirItems.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n#include \"SetProperties.h\"\r\n#include \"TempFiles.h\"\r\n#include \"UpdateCallback.h\"\r\n\r\nstatic const char *kUpdateIsNotSupoorted =\r\n  \"update operations are not supported for this archive\";\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nstatic const wchar_t *kTempFolderPrefix = L\"7zE\";\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)\r\n{\r\n  CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;\r\n  return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);\r\n}\r\n\r\nclass COutMultiVolStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    COutFileStream *StreamSpec;\r\n    CMyComPtr<IOutStream> Stream;\r\n    UString Name;\r\n    UInt64 Pos;\r\n    UInt64 RealSize;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  // CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  CRecordVector<UInt64> Sizes;\r\n  UString Prefix;\r\n  CTempFiles *TempFiles;\r\n\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  HRESULT Close();\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n// static NSynchronization::CCriticalSection g_TempPathsCS;\r\n\r\nHRESULT COutMultiVolStream::Close()\r\n{\r\n  HRESULT res = S_OK;\r\n  for (int i = 0; i < Streams.Size(); i++)\r\n  {\r\n    CSubStreamInfo &s = Streams[i];\r\n    if (s.StreamSpec)\r\n    {\r\n      HRESULT res2 = s.StreamSpec->Close();\r\n      if (res2 != S_OK)\r\n        res = res2;\r\n    }\r\n  }\r\n  return res;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n\r\n      wchar_t temp[32];\r\n      ConvertUInt64ToString(_streamIndex + 1, temp);\r\n      UString res = temp;\r\n      while (res.Length() < 3)\r\n        res = UString(L'0') + res;\r\n      UString name = Prefix + res;\r\n      subStream.StreamSpec = new COutFileStream;\r\n      subStream.Stream = subStream.StreamSpec;\r\n      if(!subStream.StreamSpec->Create(name, false))\r\n        return ::GetLastError();\r\n      {\r\n        // NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);\r\n        TempFiles->Paths.Add(name);\r\n      }\r\n\r\n      subStream.Pos = 0;\r\n      subStream.RealSize = 0;\r\n      subStream.Name = name;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n\r\n    int index = _streamIndex;\r\n    if (index >= Sizes.Size())\r\n      index = Sizes.Size() - 1;\r\n    UInt64 volSize = Sizes[index];\r\n\r\n    if (_offsetPos >= volSize)\r\n    {\r\n      _offsetPos -= volSize;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      // CMyComPtr<IOutStream> outStream;\r\n      // RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(subStream.Stream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, volSize - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if (_offsetPos > subStream.RealSize)\r\n      subStream.RealSize = _offsetPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == volSize)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed == 0 && curSize != 0)\r\n      return E_FAIL;\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  if (newPosition != NULL)\r\n    *newPosition = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::SetSize(Int64 newSize)\r\n{\r\n  if (newSize < 0)\r\n    return E_INVALIDARG;\r\n  int i = 0;\r\n  while (i < Streams.Size())\r\n  {\r\n    CSubStreamInfo &subStream = Streams[i++];\r\n    if ((UInt64)newSize < subStream.RealSize)\r\n    {\r\n      RINOK(subStream.Stream->SetSize(newSize));\r\n      subStream.RealSize = newSize;\r\n      break;\r\n    }\r\n    newSize -= subStream.RealSize;\r\n  }\r\n  while (i < Streams.Size())\r\n  {\r\n    {\r\n      CSubStreamInfo &subStream = Streams.Back();\r\n      subStream.Stream.Release();\r\n      NDirectory::DeleteFileAlways(subStream.Name);\r\n    }\r\n    Streams.DeleteBack();\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  _length = newSize;\r\n  return S_OK;\r\n}\r\n\r\nstatic const wchar_t *kDefaultArchiveType = L\"7z\";\r\nstatic const wchar_t *kSFXExtension =\r\n  #ifdef _WIN32\r\n    L\"exe\";\r\n  #else\r\n    L\"\";\r\n  #endif\r\n\r\nbool CUpdateOptions::Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath)\r\n{\r\n  if (formatIndices.Size() > 1)\r\n    return false;\r\n  int arcTypeIndex = -1;\r\n  if (formatIndices.Size() != 0)\r\n    arcTypeIndex = formatIndices[0];\r\n  if (arcTypeIndex >= 0)\r\n    MethodMode.FormatIndex = arcTypeIndex;\r\n  else\r\n  {\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveName(arcPath);\r\n    if (MethodMode.FormatIndex < 0)\r\n      MethodMode.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArchiveType);\r\n  }\r\n  if (MethodMode.FormatIndex < 0)\r\n    return false;\r\n  const CArcInfoEx &arcInfo = codecs->Formats[MethodMode.FormatIndex];\r\n  if (!arcInfo.UpdateEnabled)\r\n    return false;\r\n  UString typeExt = arcInfo.GetMainExt();\r\n  UString ext = typeExt;\r\n  if (SfxMode)\r\n    ext = kSFXExtension;\r\n  ArchivePath.BaseExtension = ext;\r\n  ArchivePath.VolExtension = typeExt;\r\n  ArchivePath.ParseFromPath(arcPath);\r\n  for (int i = 0; i < Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &uc = Commands[i];\r\n    uc.ArchivePath.BaseExtension = ext;\r\n    uc.ArchivePath.VolExtension = typeExt;\r\n    uc.ArchivePath.ParseFromPath(uc.UserArchivePath);\r\n  }\r\n  return true;\r\n}\r\n\r\n/*\r\nstruct CUpdateProduceCallbackImp: public IUpdateProduceCallback\r\n{\r\n  const CObjectVector<CArcItem> *_arcItems;\r\n  IUpdateCallbackUI *_callback;\r\n  \r\n  CUpdateProduceCallbackImp(const CObjectVector<CArcItem> *a, \r\n      IUpdateCallbackUI *callback): _arcItems(a), _callback(callback) {}\r\n  virtual HRESULT ShowDeleteFile(int arcIndex);\r\n};\r\n\r\nHRESULT CUpdateProduceCallbackImp::ShowDeleteFile(int arcIndex)\r\n{\r\n  return _callback->ShowDeleteFile((*_arcItems)[arcIndex].Name);\r\n}\r\n*/\r\n\r\nstatic HRESULT Compress(\r\n    CCodecs *codecs,\r\n    const CActionSet &actionSet,\r\n    IInArchive *archive,\r\n    const CCompressionMethodMode &compressionMethod,\r\n    CArchivePath &archivePath,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    bool shareForWrite,\r\n    bool stdInMode,\r\n    /* const UString & stdInFileName, */\r\n    bool stdOutMode,\r\n    const CDirItems &dirItems,\r\n    bool sfxMode,\r\n    const UString &sfxModule,\r\n    const CRecordVector<UInt64> &volumesSizes,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI *callback)\r\n{\r\n  CMyComPtr<IOutArchive> outArchive;\r\n  if(archive != NULL)\r\n  {\r\n    CMyComPtr<IInArchive> archive2 = archive;\r\n    HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);\r\n    if(result != S_OK)\r\n      throw kUpdateIsNotSupoorted;\r\n  }\r\n  else\r\n  {\r\n    RINOK(codecs->CreateOutArchive(compressionMethod.FormatIndex, outArchive));\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n  }\r\n  if (outArchive == 0)\r\n    throw kUpdateIsNotSupoorted;\r\n  \r\n  NFileTimeType::EEnum fileTimeType;\r\n  UInt32 value;\r\n  RINOK(outArchive->GetFileTimeType(&value));\r\n\r\n  switch(value)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n    case NFileTimeType::kUnix:\r\n    case NFileTimeType::kDOS:\r\n      fileTimeType = (NFileTimeType::EEnum)value;\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n\r\n  CRecordVector<CUpdatePair2> updatePairs2;\r\n\r\n  {\r\n    CRecordVector<CUpdatePair> updatePairs;\r\n    GetUpdatePairInfoList(dirItems, arcItems, fileTimeType, updatePairs); // must be done only once!!!\r\n    // CUpdateProduceCallbackImp upCallback(&arcItems, callback);\r\n    UpdateProduce(updatePairs, actionSet, updatePairs2, NULL /* &upCallback */);\r\n  }\r\n\r\n  UInt32 numFiles = 0;\r\n  for (int i = 0; i < updatePairs2.Size(); i++)\r\n    if (updatePairs2[i].NewData)\r\n      numFiles++;\r\n  \r\n  RINOK(callback->SetNumFiles(numFiles));\r\n\r\n  \r\n  CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n  CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);\r\n  \r\n  updateCallbackSpec->ShareForWrite = shareForWrite;\r\n  updateCallbackSpec->StdInMode = stdInMode;\r\n  updateCallbackSpec->Callback = callback;\r\n  updateCallbackSpec->DirItems = &dirItems;\r\n  updateCallbackSpec->ArcItems = &arcItems;\r\n  updateCallbackSpec->UpdatePairs = &updatePairs2;\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n\r\n  const UString &archiveName = archivePath.GetFinalPath();\r\n  if (!stdOutMode)\r\n  {\r\n    UString resultPath;\r\n    int pos;\r\n    if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))\r\n      throw 1417161;\r\n    NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));\r\n  }\r\n\r\n  COutFileStream *outStreamSpec = NULL;\r\n  COutMultiVolStream *volStreamSpec = NULL;\r\n\r\n  if (volumesSizes.Size() == 0)\r\n  {\r\n    if (stdOutMode)\r\n      outStream = new CStdOutFileStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      outStream = outStreamSpec;\r\n      bool isOK = false;\r\n      UString realPath;\r\n      for (int i = 0; i < (1 << 16); i++)\r\n      {\r\n        if (archivePath.Temp)\r\n        {\r\n          if (i > 0)\r\n          {\r\n            wchar_t s[32];\r\n            ConvertUInt64ToString(i, s);\r\n            archivePath.TempPostfix = s;\r\n          }\r\n          realPath = archivePath.GetTempPath();\r\n        }\r\n        else\r\n          realPath = archivePath.GetFinalPath();\r\n        if (outStreamSpec->Create(realPath, false))\r\n        {\r\n          tempFiles.Paths.Add(realPath);\r\n          isOK = true;\r\n          break;\r\n        }\r\n        if (::GetLastError() != ERROR_FILE_EXISTS)\r\n          break;\r\n        if (!archivePath.Temp)\r\n          break;\r\n      }\r\n      if (!isOK)\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (stdOutMode)\r\n      return E_FAIL;\r\n    volStreamSpec = new COutMultiVolStream;\r\n    outStream = volStreamSpec;\r\n    volStreamSpec->Sizes = volumesSizes;\r\n    volStreamSpec->Prefix = archivePath.GetFinalPath() + UString(L\".\");\r\n    volStreamSpec->TempFiles = &tempFiles;\r\n    volStreamSpec->Init();\r\n\r\n    /*\r\n    updateCallbackSpec->VolumesSizes = volumesSizes;\r\n    updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;\r\n    if (!archivePath.VolExtension.IsEmpty())\r\n      updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;\r\n    */\r\n  }\r\n\r\n  RINOK(SetProperties(outArchive, compressionMethod.Properties));\r\n\r\n  if (sfxMode)\r\n  {\r\n    CInFileStream *sfxStreamSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> sfxStream(sfxStreamSpec);\r\n    if (!sfxStreamSpec->Open(sfxModule))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"Can't open sfx module\";\r\n      errorInfo.FileName = sfxModule;\r\n      return E_FAIL;\r\n    }\r\n\r\n    CMyComPtr<ISequentialOutStream> sfxOutStream;\r\n    COutFileStream *outStreamSpec = NULL;\r\n    if (volumesSizes.Size() == 0)\r\n      sfxOutStream = outStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      sfxOutStream = outStreamSpec;\r\n      UString realPath = archivePath.GetFinalPath();\r\n      if (!outStreamSpec->Create(realPath, false))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    RINOK(CopyBlock(sfxStream, sfxOutStream));\r\n    if (outStreamSpec)\r\n    {\r\n      RINOK(outStreamSpec->Close());\r\n    }\r\n  }\r\n\r\n  HRESULT result = outArchive->UpdateItems(outStream, updatePairs2.Size(), updateCallback);\r\n  callback->Finilize();\r\n  RINOK(result);\r\n  if (outStreamSpec)\r\n    result = outStreamSpec->Close();\r\n  else if (volStreamSpec)\r\n    result = volStreamSpec->Close();\r\n  return result;\r\n}\r\n\r\nHRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,\r\n    IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    CObjectVector<CArcItem> &arcItems)\r\n{\r\n  arcItems.Clear();\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n  arcItems.Reserve(numItems);\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    CArcItem ai;\r\n\r\n    RINOK(GetArchiveItemPath(archive, i, ai.Name));\r\n    // check it: defaultItemName !!!\r\n    if (ai.Name.IsEmpty())\r\n      ai.Name = defaultItemName;\r\n    RINOK(IsArchiveItemFolder(archive, i, ai.IsDir));\r\n    ai.Censored = censor.CheckPath(ai.Name, !ai.IsDir);\r\n    RINOK(GetArchiveItemFileTime(archive, i, archiveFileInfo.MTime, ai.MTime));\r\n\r\n    {\r\n      CPropVariant prop;\r\n      RINOK(archive->GetProperty(i, kpidSize, &prop));\r\n      ai.SizeDefined = (prop.vt != VT_EMPTY);\r\n      if (ai.SizeDefined)\r\n        ai.Size = ConvertPropVariantToUInt64(prop);\r\n    }\r\n\r\n    {\r\n      CPropVariant prop;\r\n      RINOK(archive->GetProperty(i, kpidTimeType, &prop));\r\n      if (prop.vt == VT_UI4)\r\n      {\r\n        ai.TimeType = (int)(NFileTimeType::EEnum)prop.ulVal;\r\n        switch(ai.TimeType)\r\n        {\r\n          case NFileTimeType::kWindows:\r\n          case NFileTimeType::kUnix:\r\n          case NFileTimeType::kDOS:\r\n            break;\r\n          default:\r\n            return E_FAIL;\r\n        }\r\n      }\r\n    }\r\n\r\n    ai.IndexInServer = i;\r\n    arcItems.Add(ai);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nstatic HRESULT UpdateWithItemLists(\r\n    CCodecs *codecs,\r\n    CUpdateOptions &options,\r\n    IInArchive *archive,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    CDirItems &dirItems,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &command = options.Commands[i];\r\n    if (options.StdOutMode)\r\n    {\r\n      RINOK(callback->StartArchive(0, archive != 0));\r\n    }\r\n    else\r\n    {\r\n      RINOK(callback->StartArchive(command.ArchivePath.GetFinalPath(),\r\n          i == 0 && options.UpdateArchiveItself && archive != 0));\r\n    }\r\n\r\n    RINOK(Compress(\r\n        codecs,\r\n        command.ActionSet, archive,\r\n        options.MethodMode,\r\n        command.ArchivePath,\r\n        arcItems,\r\n        options.OpenShareForWrite,\r\n        options.StdInMode,\r\n        /* options.StdInFileName, */\r\n        options.StdOutMode,\r\n        dirItems,\r\n        options.SfxMode, options.SfxModule,\r\n        options.VolumesSizes,\r\n        tempFiles,\r\n        errorInfo, callback));\r\n\r\n    RINOK(callback->FinishArchive());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _WIN32\r\nclass CCurrentDirRestorer\r\n{\r\n  UString m_CurrentDirectory;\r\npublic:\r\n  CCurrentDirRestorer()\r\n    { NFile::NDirectory::MyGetCurrentDirectory(m_CurrentDirectory); }\r\n  ~CCurrentDirRestorer()\r\n    { RestoreDirectory();}\r\n  bool RestoreDirectory()\r\n    { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(m_CurrentDirectory)); }\r\n};\r\n#endif\r\n\r\nstruct CEnumDirItemUpdateCallback: public IEnumDirItemCallback\r\n{\r\n  IUpdateCallbackUI2 *Callback;\r\n  HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path)\r\n  {\r\n    return Callback->ScanProgress(numFolders, numFiles, path);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\ntypedef ULONG (FAR PASCAL MY_MAPISENDDOCUMENTS)(\r\n  ULONG_PTR ulUIParam,\r\n  LPSTR lpszDelimChar,\r\n  LPSTR lpszFilePaths,\r\n  LPSTR lpszFileNames,\r\n  ULONG ulReserved\r\n);\r\ntypedef MY_MAPISENDDOCUMENTS FAR *MY_LPMAPISENDDOCUMENTS;\r\n#endif\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor,\r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  if (options.StdOutMode && options.EMailMode)\r\n    return E_FAIL;\r\n\r\n  if (options.VolumesSizes.Size() > 0 && (options.EMailMode || options.SfxMode))\r\n    return E_NOTIMPL;\r\n\r\n  if (options.SfxMode)\r\n  {\r\n    CProperty property;\r\n    property.Name = L\"rsfx\";\r\n    property.Value = L\"on\";\r\n    options.MethodMode.Properties.Add(property);\r\n    if (options.SfxModule.IsEmpty())\r\n    {\r\n      errorInfo.Message = L\"sfx file is not specified\";\r\n      return E_FAIL;\r\n    }\r\n    UString name = options.SfxModule;\r\n    if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))\r\n    {\r\n      errorInfo.Message = L\"can't find specified sfx module\";\r\n      return E_FAIL;\r\n    }\r\n  }\r\n\r\n  const UString archiveName = options.ArchivePath.GetFinalPath();\r\n\r\n  UString defaultItemName;\r\n  NFind::CFileInfoW archiveFileInfo;\r\n\r\n  CArchiveLink archiveLink;\r\n  IInArchive *archive = 0;\r\n  if (NFind::FindFile(archiveName, archiveFileInfo))\r\n  {\r\n    if (archiveFileInfo.IsDir())\r\n      throw \"there is no such archive\";\r\n    if (options.VolumesSizes.Size() > 0)\r\n      return E_NOTIMPL;\r\n    CIntVector formatIndices;\r\n    if (options.MethodMode.FormatIndex >= 0)\r\n      formatIndices.Add(options.MethodMode.FormatIndex);\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, openCallback);\r\n    if (result == E_ABORT)\r\n      return result;\r\n    RINOK(callback->OpenResult(archiveName, result));\r\n    RINOK(result);\r\n    if (archiveLink.VolumePaths.Size() > 1)\r\n    {\r\n      errorInfo.SystemError = (DWORD)E_NOTIMPL;\r\n      errorInfo.Message = L\"Updating for multivolume archives is not implemented\";\r\n      return E_NOTIMPL;\r\n    }\r\n    archive = archiveLink.GetArchive();\r\n    defaultItemName = archiveLink.GetDefaultItemName();\r\n  }\r\n  else\r\n  {\r\n    /*\r\n    if (archiveType.IsEmpty())\r\n      throw \"type of archive is not specified\";\r\n    */\r\n  }\r\n\r\n  CDirItems dirItems;\r\n  if (options.StdInMode)\r\n  {\r\n    CDirItem di;\r\n    di.Name = options.StdInFileName;\r\n    di.Size = (UInt64)(Int64)-1;\r\n    di.Attrib = 0;\r\n    NTime::GetCurUtcFileTime(di.MTime);\r\n    di.CTime = di.ATime = di.MTime;\r\n    dirItems.Items.Add(di);\r\n  }\r\n  else\r\n  {\r\n    bool needScanning = false;\r\n    for(int i = 0; i < options.Commands.Size(); i++)\r\n      if (options.Commands[i].ActionSet.NeedScanning())\r\n        needScanning = true;\r\n    if (needScanning)\r\n    {\r\n      CEnumDirItemUpdateCallback enumCallback;\r\n      enumCallback.Callback = callback;\r\n      RINOK(callback->StartScanning());\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(censor, dirItems, &enumCallback, errorPaths, errorCodes);\r\n      for (int i = 0; i < errorPaths.Size(); i++)\r\n      {\r\n        RINOK(callback->CanNotFindError(errorPaths[i], errorCodes[i]));\r\n      }\r\n      if (res != S_OK)\r\n      {\r\n        if (res != E_ABORT)\r\n          errorInfo.Message = L\"Scanning error\";\r\n        // errorInfo.FileName = errorPath;\r\n        return res;\r\n      }\r\n      RINOK(callback->FinishScanning());\r\n    }\r\n  }\r\n\r\n  UString tempDirPrefix;\r\n  bool usesTempDir = false;\r\n  \r\n  #ifdef _WIN32\r\n  NDirectory::CTempDirectoryW tempDirectory;\r\n  if (options.EMailMode && options.EMailRemoveAfter)\r\n  {\r\n    tempDirectory.Create(kTempFolderPrefix);\r\n    tempDirPrefix = tempDirectory.GetPath();\r\n    NormalizeDirPathPrefix(tempDirPrefix);\r\n    usesTempDir = true;\r\n  }\r\n  #endif\r\n\r\n  CTempFiles tempFiles;\r\n\r\n  bool createTempFile = false;\r\n  if(!options.StdOutMode && options.UpdateArchiveItself)\r\n  {\r\n    CArchivePath &ap = options.Commands[0].ArchivePath;\r\n    ap = options.ArchivePath;\r\n    // if ((archive != 0 && !usesTempDir) || !options.WorkingDir.IsEmpty())\r\n    if ((archive != 0 || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)\r\n    {\r\n      createTempFile = true;\r\n      ap.Temp = true;\r\n      if (!options.WorkingDir.IsEmpty())\r\n      {\r\n        ap.TempPrefix = options.WorkingDir;\r\n        NormalizeDirPathPrefix(ap.TempPrefix);\r\n      }\r\n    }\r\n  }\r\n\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CArchivePath &ap = options.Commands[i].ArchivePath;\r\n    if (usesTempDir)\r\n    {\r\n      // Check it\r\n      ap.Prefix = tempDirPrefix;\r\n      // ap.Temp = true;\r\n      // ap.TempPrefix = tempDirPrefix;\r\n    }\r\n    if (i > 0 || !createTempFile)\r\n    {\r\n      const UString &path = ap.GetFinalPath();\r\n      if (NFind::DoesFileExist(path))\r\n      {\r\n        errorInfo.SystemError = 0;\r\n        errorInfo.Message = L\"File already exists\";\r\n        errorInfo.FileName = path;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n\r\n  CObjectVector<CArcItem> arcItems;\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(EnumerateInArchiveItems(censor,\r\n        archive, defaultItemName, archiveFileInfo, arcItems));\r\n  }\r\n\r\n  RINOK(UpdateWithItemLists(codecs, options, archive, arcItems, dirItems,\r\n      tempFiles, errorInfo, callback));\r\n\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(archiveLink.Close());\r\n    archiveLink.Release();\r\n  }\r\n\r\n  tempFiles.Paths.Clear();\r\n  if(createTempFile)\r\n  {\r\n    try\r\n    {\r\n      CArchivePath &ap = options.Commands[0].ArchivePath;\r\n      const UString &tempPath = ap.GetTempPath();\r\n      if (archive != NULL)\r\n        if (!NDirectory::DeleteFileAlways(archiveName))\r\n        {\r\n          errorInfo.SystemError = ::GetLastError();\r\n          errorInfo.Message = L\"delete file error\";\r\n          errorInfo.FileName = archiveName;\r\n          return E_FAIL;\r\n        }\r\n      if (!NDirectory::MyMoveFile(tempPath, archiveName))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.Message = L\"move file error\";\r\n        errorInfo.FileName = tempPath;\r\n        errorInfo.FileName2 = archiveName;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      throw;\r\n    }\r\n  }\r\n\r\n  #ifdef _WIN32\r\n  if (options.EMailMode)\r\n  {\r\n    NDLL::CLibrary mapiLib;\r\n    if (!mapiLib.Load(TEXT(\"Mapi32.dll\")))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not load Mapi32.dll\";\r\n      return E_FAIL;\r\n    }\r\n    MY_LPMAPISENDDOCUMENTS fnSend = (MY_LPMAPISENDDOCUMENTS)\r\n        mapiLib.GetProcAddress(\"MAPISendDocuments\");\r\n    if (fnSend == 0)\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not find MAPISendDocuments function\";\r\n      return E_FAIL;\r\n    }\r\n    UStringVector fullPaths;\r\n    int i;\r\n    for(i = 0; i < options.Commands.Size(); i++)\r\n    {\r\n      CArchivePath &ap = options.Commands[i].ArchivePath;\r\n      UString arcPath;\r\n      if(!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        return E_FAIL;\r\n      }\r\n      fullPaths.Add(arcPath);\r\n    }\r\n    CCurrentDirRestorer curDirRestorer;\r\n    for(i = 0; i < fullPaths.Size(); i++)\r\n    {\r\n      UString arcPath = fullPaths[i];\r\n      UString fileName = ExtractFileNameFromPath(arcPath);\r\n      AString path = GetAnsiString(arcPath);\r\n      AString name = GetAnsiString(fileName);\r\n      // Warning!!! MAPISendDocuments function changes Current directory\r\n      fnSend(0, \";\", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0);\r\n    }\r\n  }\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/Update.h",
    "content": "// Update.h\r\n\r\n#ifndef __UPDATE_H\r\n#define __UPDATE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"Property.h\"\r\n#include \"LoadCodecs.h\"\r\n\r\nstruct CArchivePath\r\n{\r\n  UString Prefix;   // path(folder) prefix including slash\r\n  UString Name; // base name\r\n  UString BaseExtension; // archive type extension or \"exe\" extension\r\n  UString VolExtension;  // archive type extension for volumes\r\n\r\n  bool Temp;\r\n  UString TempPrefix;  // path(folder) for temp location\r\n  UString TempPostfix;\r\n\r\n  CArchivePath(): Temp(false) {};\r\n  \r\n  void ParseFromPath(const UString &path)\r\n  {\r\n    SplitPathToParts(path, Prefix, Name);\r\n    if (Name.IsEmpty())\r\n      return;\r\n    int dotPos = Name.ReverseFind(L'.');\r\n    if (dotPos <= 0)\r\n      return;\r\n    if (dotPos == Name.Length() - 1)\r\n    {\r\n      Name = Name.Left(dotPos);\r\n      BaseExtension.Empty();\r\n      return;\r\n    }\r\n    if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0)\r\n    {\r\n      BaseExtension = Name.Mid(dotPos + 1);\r\n      Name = Name.Left(dotPos);\r\n    }\r\n    else\r\n      BaseExtension.Empty();\r\n  }\r\n\r\n  UString GetPathWithoutExt() const\r\n  {\r\n    return Prefix + Name;\r\n  }\r\n\r\n  UString GetFinalPath() const\r\n  {\r\n    UString path = GetPathWithoutExt();\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    return path;\r\n  }\r\n\r\n  \r\n  UString GetTempPath() const\r\n  {\r\n    UString path = TempPrefix + Name;\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    path += L\".tmp\";\r\n    path += TempPostfix;\r\n    return path;\r\n  }\r\n};\r\n\r\nstruct CUpdateArchiveCommand\r\n{\r\n  UString UserArchivePath;\r\n  CArchivePath ArchivePath;\r\n  NUpdateArchive::CActionSet ActionSet;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  int FormatIndex;\r\n  CObjectVector<CProperty> Properties;\r\n  CCompressionMethodMode(): FormatIndex(-1) {}\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  CCompressionMethodMode MethodMode;\r\n\r\n  CObjectVector<CUpdateArchiveCommand> Commands;\r\n  bool UpdateArchiveItself;\r\n  CArchivePath ArchivePath;\r\n  \r\n  bool SfxMode;\r\n  UString SfxModule;\r\n  \r\n  bool OpenShareForWrite;\r\n\r\n  bool StdInMode;\r\n  UString StdInFileName;\r\n  bool StdOutMode;\r\n  \r\n  bool EMailMode;\r\n  bool EMailRemoveAfter;\r\n  UString EMailAddress;\r\n\r\n  UString WorkingDir;\r\n\r\n  bool Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath);\r\n\r\n  CUpdateOptions():\r\n    UpdateArchiveItself(true),\r\n    SfxMode(false),\r\n    StdInMode(false),\r\n    StdOutMode(false),\r\n    EMailMode(false),\r\n    EMailRemoveAfter(false),\r\n    OpenShareForWrite(false)\r\n      {};\r\n  CRecordVector<UInt64> VolumesSizes;\r\n};\r\n\r\nstruct CErrorInfo\r\n{\r\n  DWORD SystemError;\r\n  UString FileName;\r\n  UString FileName2;\r\n  UString Message;\r\n  // UStringVector ErrorPaths;\r\n  // CRecordVector<DWORD> ErrorCodes;\r\n  CErrorInfo(): SystemError(0) {};\r\n};\r\n\r\nstruct CUpdateErrorInfo: public CErrorInfo\r\n{\r\n};\r\n\r\n#define INTERFACE_IUpdateCallbackUI2(x) \\\r\n  INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \\\r\n  virtual HRESULT StartScanning() x; \\\r\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) x; \\\r\n  virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT FinishScanning() x; \\\r\n  virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \\\r\n  virtual HRESULT FinishArchive() x; \\\r\n\r\nstruct IUpdateCallbackUI2: public IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI2(=0)\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor,\r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/UpdateAction.cpp",
    "content": "// UpdateAction.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n\r\nnamespace NUpdateArchive {\r\n\r\nconst CActionSet kAddActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kUpdateActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kFreshActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kSynchronizeActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n};\r\n\r\nconst CActionSet kDeleteActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/UpdateAction.h",
    "content": "// UpdateAction.h\r\n\r\n#ifndef __UPDATE_ACTION_H\r\n#define __UPDATE_ACTION_H\r\n\r\nnamespace NUpdateArchive {\r\n\r\n  namespace NPairState\r\n  {\r\n    const int kNumValues = 7;\r\n    enum EEnum\r\n    {\r\n      kNotMasked = 0,\r\n      kOnlyInArchive,\r\n      kOnlyOnDisk,\r\n      kNewInArchive,\r\n      kOldInArchive,\r\n      kSameFiles,\r\n      kUnknowNewerFiles\r\n    };\r\n  }\r\n  namespace NPairAction\r\n  {\r\n    enum EEnum\r\n    {\r\n      kIgnore = 0,\r\n      kCopy,\r\n      kCompress,\r\n      kCompressAsAnti\r\n    };\r\n  }\r\n  struct CActionSet\r\n  {\r\n    NPairAction::EEnum StateActions[NPairState::kNumValues];\r\n    bool NeedScanning() const\r\n    {\r\n      int i;\r\n      for (i = 0; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] == NPairAction::kCompress)\r\n          return true;\r\n      for (i = 1; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] != NPairAction::kIgnore)\r\n          return true;\r\n      return false;\r\n    }\r\n  };\r\n  extern const CActionSet kAddActionSet;\r\n  extern const CActionSet kUpdateActionSet;\r\n  extern const CActionSet kFreshActionSet;\r\n  extern const CActionSet kSynchronizeActionSet;\r\n  extern const CActionSet kDeleteActionSet;\r\n};\r\n\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp",
    "content": "// UpdateCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCArchiveUpdateCallback::CArchiveUpdateCallback():\r\n  Callback(0),\r\n  ShareForWrite(false),\r\n  StdInMode(false),\r\n  DirItems(0),\r\n  ArcItems(0),\r\n  UpdatePairs(0),\r\n  NewNames(0)\r\n  {}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetTotal(size);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\n\r\n/*\r\nSTATPROPSTG kProperties[] =\r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidIsDir, VT_BOOL},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidCTime, VT_FILETIME},\r\n  { NULL, kpidATime, VT_FILETIME},\r\n  { NULL, kpidMTime, VT_FILETIME},\r\n  { NULL, kpidAttrib, VT_UI4},\r\n  { NULL, kpidIsAnti, VT_BOOL}\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)\r\n{\r\n  return CStatPropEnumerator::CreateEnumerator(kProperties, sizeof(kProperties) / sizeof(kProperties[0]), enumerator);\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,\r\n      Int32 *newData, Int32 *newProps, UInt32 *indexInArchive)\r\n{\r\n  COM_TRY_BEGIN\r\n  RINOK(Callback->CheckBreak());\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  if (newData != NULL) *newData = BoolToInt(up.NewData);\r\n  if (newProps != NULL) *newProps = BoolToInt(up.NewProps);\r\n  if (indexInArchive != NULL)\r\n  {\r\n    *indexInArchive = (UInt32)-1;\r\n    if (up.ExistInArchive())\r\n      *indexInArchive = (ArcItems == 0) ? up.ArcIndex : (*ArcItems)[up.ArcIndex].IndexInServer;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    prop = up.IsAnti;\r\n    prop.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  if (up.IsAnti)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidIsDir:\r\n      case kpidPath:\r\n        break;\r\n      case kpidSize:\r\n        prop = (UInt64)0;\r\n        prop.Detach(value);\r\n        return S_OK;\r\n      default:\r\n        prop.Detach(value);\r\n        return S_OK;\r\n    }\r\n  }\r\n  \r\n  if (up.ExistOnDisk())\r\n  {\r\n    const CDirItem &di = DirItems->Items[up.DirIndex];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:  prop = DirItems->GetLogPath(up.DirIndex); break;\r\n      case kpidIsDir:  prop = di.IsDir(); break;\r\n      case kpidSize:  prop = di.Size; break;\r\n      case kpidAttrib:  prop = di.Attrib; break;\r\n      case kpidCTime:  prop = di.CTime; break;\r\n      case kpidATime:  prop = di.ATime; break;\r\n      case kpidMTime:  prop = di.MTime; break;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (propID == kpidPath)\r\n    {\r\n      if (up.NewNameIndex >= 0)\r\n      {\r\n        prop = (*NewNames)[up.NewNameIndex];\r\n        prop.Detach(value);\r\n        return S_OK;\r\n      }\r\n    }\r\n    if (up.ExistInArchive() && Archive)\r\n    {\r\n      UInt32 indexInArchive;\r\n      if (ArcItems == 0)\r\n        indexInArchive = up.ArcIndex;\r\n      else\r\n        indexInArchive = (*ArcItems)[up.ArcIndex].IndexInServer;\r\n      return Archive->GetProperty(indexInArchive, propID, value);\r\n    }\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  if (!up.NewData)\r\n    return E_FAIL;\r\n  \r\n  RINOK(Callback->CheckBreak());\r\n  RINOK(Callback->Finilize());\r\n\r\n  if (up.IsAnti)\r\n  {\r\n    return Callback->GetStream((*ArcItems)[up.ArcIndex].Name, true);\r\n  }\r\n  const CDirItem &di = DirItems->Items[up.DirIndex];\r\n  RINOK(Callback->GetStream(DirItems->GetLogPath(up.DirIndex), false));\r\n \r\n  if (di.IsDir())\r\n    return S_OK;\r\n\r\n  if (StdInMode)\r\n  {\r\n    CStdInFileStream *inStreamSpec = new CStdInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  else\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    const UString path = DirItems->GetPhyPath(up.DirIndex);\r\n    if (!inStreamSpec->OpenShared(path, ShareForWrite))\r\n    {\r\n      return Callback->OpenFileError(path, ::GetLastError());\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetOperationResult(operationResult);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if (!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->CryptoGetTextPassword2(passwordIsDefined, password);\r\n  COM_TRY_END\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/UpdateCallback.h",
    "content": "// UpdateCallback.h\r\n\r\n#ifndef __UPDATECALLBACK_H\r\n#define __UPDATECALLBACK_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/UpdatePair.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#define INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT SetTotal(UInt64 size) x; \\\r\n  virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \\\r\n  virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x; \\\r\n  virtual HRESULT CheckBreak() x; \\\r\n  virtual HRESULT Finilize() x; \\\r\n  virtual HRESULT SetNumFiles(UInt64 numFiles) x; \\\r\n  virtual HRESULT GetStream(const wchar_t *name, bool isAnti) x; \\\r\n  virtual HRESULT OpenFileError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT SetOperationResult(Int32 operationResult) x; \\\r\n  virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x; \\\r\n  // virtual HRESULT ShowDeleteFile(const wchar_t *name) x; \\\r\n  // virtual HRESULT CloseProgress() { return S_OK; };\r\n\r\nstruct IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI(=0)\r\n};\r\n\r\nclass CArchiveUpdateCallback:\r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveUpdateCallback2,\r\n      ICryptoGetTextPassword2,\r\n      ICompressProgressInfo)\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  INTERFACE_IArchiveUpdateCallback2(;)\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  IUpdateCallbackUI *Callback;\r\n\r\n  bool ShareForWrite;\r\n  bool StdInMode;\r\n  const CDirItems *DirItems;\r\n  const CObjectVector<CArcItem> *ArcItems;\r\n  const CRecordVector<CUpdatePair2> *UpdatePairs;\r\n  const UStringVector *NewNames;\r\n  CMyComPtr<IInArchive> Archive;\r\n\r\n  CArchiveUpdateCallback();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/UpdatePair.cpp",
    "content": "// UpdatePair.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <time.h>\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"UpdatePair.h\"\r\n#include \"SortUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nstatic int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time1, const FILETIME &time2)\r\n{\r\n  switch(fileTimeType)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n      return ::CompareFileTime(&time1, &time2);\r\n    case NFileTimeType::kUnix:\r\n      {\r\n        UInt32 unixTime1, unixTime2;\r\n        FileTimeToUnixTime(time1, unixTime1);\r\n        FileTimeToUnixTime(time2, unixTime2);\r\n        return MyCompare(unixTime1, unixTime2);\r\n      }\r\n    case NFileTimeType::kDOS:\r\n      {\r\n        UInt32 dosTime1, dosTime2;\r\n        FileTimeToDosTime(time1, dosTime1);\r\n        FileTimeToDosTime(time2, dosTime2);\r\n        return MyCompare(dosTime1, dosTime2);\r\n      }\r\n  }\r\n  throw 4191618;\r\n}\r\n\r\nstatic const wchar_t *kDuplicateFileNameMessage = L\"Duplicate filename:\";\r\nstatic const wchar_t *kNotCensoredCollisionMessaged = L\"Internal file name collision (file on disk, file in archive):\";\r\n\r\nstatic void ThrowError(const UString &message, const UString &s1, const UString &s2)\r\n{\r\n  UString m = message;\r\n  m += L'\\n';\r\n  m += s1;\r\n  m += L'\\n';\r\n  m += s2;\r\n  throw m;\r\n}\r\n\r\nstatic void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)\r\n{\r\n  for(int i = 0; i + 1 < indices.Size(); i++)\r\n    if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)\r\n      ThrowError(kDuplicateFileNameMessage, strings[indices[i]], strings[indices[i + 1]]);\r\n}\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CDirItems &dirItems,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CRecordVector<CUpdatePair> &updatePairs)\r\n{\r\n  CIntVector dirIndices, arcIndices;\r\n  \r\n  int numDirItems = dirItems.Items.Size();\r\n  int numArcItems = arcItems.Size();\r\n  \r\n  \r\n  {\r\n    UStringVector arcNames;\r\n    arcNames.Reserve(numArcItems);\r\n    for (int i = 0; i < numArcItems; i++)\r\n      arcNames.Add(arcItems[i].Name);\r\n    SortFileNames(arcNames, arcIndices);\r\n    TestDuplicateString(arcNames, arcIndices);\r\n  }\r\n\r\n  UStringVector dirNames;\r\n  {\r\n    dirNames.Reserve(numDirItems);\r\n    for (int i = 0; i < numDirItems; i++)\r\n      dirNames.Add(dirItems.GetLogPath(i));\r\n    SortFileNames(dirNames, dirIndices);\r\n    TestDuplicateString(dirNames, dirIndices);\r\n  }\r\n  \r\n  int dirIndex = 0, arcIndex = 0;\r\n  while (dirIndex < numDirItems && arcIndex < numArcItems)\r\n  {\r\n    CUpdatePair pair;\r\n    int dirIndex2 = dirIndices[dirIndex];\r\n    int arcIndex2 = arcIndices[arcIndex];\r\n    const CDirItem &di = dirItems.Items[dirIndex2];\r\n    const CArcItem &ai = arcItems[arcIndex2];\r\n    int compareResult = CompareFileNames(dirNames[dirIndex2], ai.Name);\r\n    if (compareResult < 0)\r\n    {\r\n      pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n      pair.DirIndex = dirIndex2;\r\n      dirIndex++;\r\n    }\r\n    else if (compareResult > 0)\r\n    {\r\n      pair.State = ai.Censored ?\r\n          NUpdateArchive::NPairState::kOnlyInArchive:\r\n          NUpdateArchive::NPairState::kNotMasked;\r\n      pair.ArcIndex = arcIndex2;\r\n      arcIndex++;\r\n    }\r\n    else\r\n    {\r\n      if (!ai.Censored)\r\n        ThrowError(kNotCensoredCollisionMessaged, dirNames[dirIndex2], ai.Name);\r\n      pair.DirIndex = dirIndex2;\r\n      pair.ArcIndex = arcIndex2;\r\n      switch (MyCompareTime(\r\n          ai.TimeType != - 1 ? (NFileTimeType::EEnum)ai.TimeType : fileTimeType,\r\n          di.MTime, ai.MTime))\r\n      {\r\n        case -1: pair.State = NUpdateArchive::NPairState::kNewInArchive; break;\r\n        case 1:  pair.State = NUpdateArchive::NPairState::kOldInArchive; break;\r\n        default:\r\n          if (ai.SizeDefined)\r\n            if (di.Size != ai.Size)\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n            else\r\n              pair.State = NUpdateArchive::NPairState::kSameFiles;\r\n          else\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n      }\r\n      dirIndex++;\r\n      arcIndex++;\r\n    }\r\n    updatePairs.Add(pair);\r\n  }\r\n\r\n  for (; dirIndex < numDirItems; dirIndex++)\r\n  {\r\n    CUpdatePair pair;\r\n    pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n    pair.DirIndex = dirIndices[dirIndex];\r\n    updatePairs.Add(pair);\r\n  }\r\n  \r\n  for (; arcIndex < numArcItems; arcIndex++)\r\n  {\r\n    CUpdatePair pair;\r\n    int arcIndex2 = arcIndices[arcIndex];\r\n    pair.State = arcItems[arcIndex2].Censored ?\r\n        NUpdateArchive::NPairState::kOnlyInArchive:\r\n        NUpdateArchive::NPairState::kNotMasked;\r\n    pair.ArcIndex = arcIndex2;\r\n    updatePairs.Add(pair);\r\n  }\r\n\r\n  updatePairs.ReserveDown();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/UpdatePair.h",
    "content": "// UpdatePair.h\r\n\r\n#ifndef __UPDATE_PAIR_H\r\n#define __UPDATE_PAIR_H\r\n\r\n#include \"DirItem.h\"\r\n#include \"UpdateAction.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CUpdatePair\r\n{\r\n  NUpdateArchive::NPairState::EEnum State;\r\n  int ArcIndex;\r\n  int DirIndex;\r\n  CUpdatePair(): ArcIndex(-1), DirIndex(-1) {}\r\n};\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CDirItems &dirItems,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CRecordVector<CUpdatePair> &updatePairs);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp",
    "content": "// UpdateProduce.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateProduce.h\"\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic const char *kUpdateActionSetCollision = \"Internal collision in update action set\";\r\n\r\nvoid UpdateProduce(\r\n    const CRecordVector<CUpdatePair> &updatePairs,\r\n    const CActionSet &actionSet,\r\n    CRecordVector<CUpdatePair2> &operationChain,\r\n    IUpdateProduceCallback *callback)\r\n{\r\n  for (int i = 0; i < updatePairs.Size(); i++)\r\n  {\r\n    const CUpdatePair &pair = updatePairs[i];\r\n\r\n    CUpdatePair2 up2;\r\n    up2.IsAnti = false;\r\n    up2.DirIndex = pair.DirIndex;\r\n    up2.ArcIndex = pair.ArcIndex;\r\n    up2.NewData = up2.NewProps = true;\r\n    \r\n    switch(actionSet.StateActions[pair.State])\r\n    {\r\n      case NPairAction::kIgnore:\r\n        /*\r\n        if (pair.State != NPairState::kOnlyOnDisk)\r\n          IgnoreArchiveItem(m_ArchiveItems[pair.ArcIndex]);\r\n        // cout << \"deleting\";\r\n        */\r\n        if (callback)\r\n          callback->ShowDeleteFile(pair.ArcIndex);\r\n        continue;\r\n\r\n      case NPairAction::kCopy:\r\n        if (pair.State == NPairState::kOnlyOnDisk)\r\n          throw kUpdateActionSetCollision;\r\n        up2.NewData = up2.NewProps = false;\r\n        break;\r\n      \r\n      case NPairAction::kCompress:\r\n        if (pair.State == NPairState::kOnlyInArchive ||\r\n            pair.State == NPairState::kNotMasked)\r\n          throw kUpdateActionSetCollision;\r\n        break;\r\n      \r\n      case NPairAction::kCompressAsAnti:\r\n        up2.IsAnti = true;\r\n        break;\r\n    }\r\n    operationChain.Add(up2);\r\n  }\r\n  operationChain.ReserveDown();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/UpdateProduce.h",
    "content": "// UpdateProduce.h\r\n\r\n#ifndef __UPDATE_PRODUCE_H\r\n#define __UPDATE_PRODUCE_H\r\n\r\n#include \"UpdatePair.h\"\r\n\r\nstruct CUpdatePair2\r\n{\r\n  bool NewData;\r\n  bool NewProps;\r\n  bool IsAnti;\r\n  \r\n  int DirIndex;\r\n  int ArcIndex;\r\n  int NewNameIndex;\r\n\r\n  bool ExistOnDisk() const { return DirIndex != -1; }\r\n  bool ExistInArchive() const { return ArcIndex != -1; }\r\n\r\n  CUpdatePair2(): IsAnti(false), DirIndex(-1), ArcIndex(-1), NewNameIndex(-1) {}\r\n};\r\n\r\nstruct IUpdateProduceCallback\r\n{\r\n  virtual HRESULT ShowDeleteFile(int arcIndex) = 0;\r\n};\r\n\r\nvoid UpdateProduce(\r\n    const CRecordVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CRecordVector<CUpdatePair2> &operationChain,\r\n    IUpdateProduceCallback *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/WorkDir.cpp",
    "content": "// WorkDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"WorkDir.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nstatic inline UINT GetCurrentCodePage()\r\n  { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)\r\n{\r\n  NWorkDir::NMode::EEnum mode = workDirInfo.Mode;\r\n  if (workDirInfo.ForRemovableOnly)\r\n  {\r\n    mode = NWorkDir::NMode::kCurrent;\r\n    UString prefix = path.Left(3);\r\n    if (prefix[1] == L':' && prefix[2] == L'\\\\')\r\n    {\r\n      UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));\r\n      if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)\r\n        mode = workDirInfo.Mode;\r\n    }\r\n    /*\r\n    CParsedPath parsedPath;\r\n    parsedPath.ParsePath(archiveName);\r\n    UINT driveType = GetDriveType(parsedPath.Prefix);\r\n    if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))\r\n      mode = NZipSettings::NWorkDir::NMode::kCurrent;\r\n    */\r\n  }\r\n  switch(mode)\r\n  {\r\n    case NWorkDir::NMode::kCurrent:\r\n    {\r\n      return ExtractDirPrefixFromPath(path);\r\n    }\r\n    case NWorkDir::NMode::kSpecified:\r\n    {\r\n      UString tempDir = workDirInfo.Path;\r\n      NormalizeDirPathPrefix(tempDir);\r\n      return tempDir;\r\n    }\r\n    default:\r\n    {\r\n      UString tempDir;\r\n      if(!NFile::NDirectory::MyGetTempPath(tempDir))\r\n        throw 141717;\r\n      return tempDir;\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/WorkDir.h",
    "content": "// WorkDir.h\r\n\r\n#ifndef __WORKDIR_H\r\n#define __WORKDIR_H\r\n\r\n#include \"ZipRegistry.h\"\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Common/ZipRegistry.h",
    "content": "// ZipRegistry.h\r\n\r\n#ifndef __ZIPREGISTRY_H\r\n#define __ZIPREGISTRY_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"ExtractMode.h\"\r\n\r\nnamespace NExtract\r\n{\r\n  struct CInfo\r\n  {\r\n    NPathMode::EEnum PathMode;\r\n    NOverwriteMode::EEnum OverwriteMode;\r\n    UStringVector Paths;\r\n    bool ShowPassword;\r\n  };\r\n}\r\n\r\nnamespace NCompression {\r\n  \r\n  struct CFormatOptions\r\n  {\r\n    CSysString FormatID;\r\n    UString Options;\r\n    UString Method;\r\n    UString EncryptionMethod;\r\n    UInt32 Level;\r\n    UInt32 Dictionary;\r\n    UInt32 Order;\r\n    UInt32 BlockLogSize;\r\n    UInt32 NumThreads;\r\n    void ResetForLevelChange()\r\n    {\r\n      BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1);\r\n      Method.Empty();\r\n      // EncryptionMethod.Empty();\r\n      // Options.Empty();\r\n    }\r\n    CFormatOptions() { ResetForLevelChange(); }\r\n  };\r\n\r\n  struct CInfo\r\n  {\r\n    UStringVector HistoryArchives;\r\n    UInt32 Level;\r\n    UString ArchiveType;\r\n\r\n    CObjectVector<CFormatOptions> FormatOptionsVector;\r\n\r\n    bool ShowPassword;\r\n    bool EncryptHeaders;\r\n  };\r\n}\r\n\r\nnamespace NWorkDir{\r\n  \r\n  namespace NMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kSystem,\r\n      kCurrent,\r\n      kSpecified\r\n    };\r\n  }\r\n  struct CInfo\r\n  {\r\n    NMode::EEnum Mode;\r\n    UString Path;\r\n    bool ForRemovableOnly;\r\n    void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }\r\n    void SetDefault()\r\n    {\r\n      Mode = NMode::kSystem;\r\n      Path.Empty();\r\n      SetForRemovableOnlyDefault();\r\n    }\r\n  };\r\n}\r\n\r\nvoid SaveExtractionInfo(const NExtract::CInfo &info);\r\nvoid ReadExtractionInfo(NExtract::CInfo &info);\r\n\r\nvoid SaveCompressionInfo(const NCompression::CInfo &info);\r\nvoid ReadCompressionInfo(NCompression::CInfo &info);\r\n\r\nvoid SaveWorkDirInfo(const NWorkDir::CInfo &info);\r\nvoid ReadWorkDirInfo(NWorkDir::CInfo &info);\r\n\r\nvoid SaveCascadedMenu(bool enabled);\r\nbool ReadCascadedMenu();\r\n\r\nvoid SaveContextMenuStatus(UInt32 value);\r\nbool ReadContextMenuStatus(UInt32 &value);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/ConsoleClose.cpp",
    "content": "// ConsoleClose.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n\r\nstatic int g_BreakCounter = 0;\r\nstatic const int kBreakAbortThreshold = 2;\r\n\r\nnamespace NConsoleClose {\r\n\r\nstatic BOOL WINAPI HandlerRoutine(DWORD ctrlType)\r\n{\r\n  if (ctrlType == CTRL_LOGOFF_EVENT)\r\n  {\r\n    // printf(\"\\nCTRL_LOGOFF_EVENT\\n\");\r\n    return TRUE;\r\n  }\r\n\r\n  g_BreakCounter++;\r\n  if (g_BreakCounter < kBreakAbortThreshold)\r\n    return TRUE;\r\n  return FALSE;\r\n  /*\r\n  switch(ctrlType)\r\n  {\r\n    case CTRL_C_EVENT:\r\n    case CTRL_BREAK_EVENT:\r\n      if (g_BreakCounter < kBreakAbortThreshold)\r\n      return TRUE;\r\n  }\r\n  return FALSE;\r\n  */\r\n}\r\n\r\nbool TestBreakSignal()\r\n{\r\n  /*\r\n  if (g_BreakCounter > 0)\r\n    return true;\r\n  */\r\n  return (g_BreakCounter > 0);\r\n}\r\n\r\nvoid CheckCtrlBreak()\r\n{\r\n  if (TestBreakSignal())\r\n    throw CCtrlBreakException();\r\n}\r\n\r\nCCtrlHandlerSetter::CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\nCCtrlHandlerSetter::~CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/ConsoleClose.h",
    "content": "// ConsoleCloseUtils.h\r\n\r\n#ifndef __CONSOLECLOSEUTILS_H\r\n#define __CONSOLECLOSEUTILS_H\r\n\r\nnamespace NConsoleClose {\r\n\r\nbool TestBreakSignal();\r\n\r\nclass CCtrlHandlerSetter\r\n{\r\npublic:\r\n  CCtrlHandlerSetter();\r\n  virtual ~CCtrlHandlerSetter();\r\n};\r\n\r\nclass CCtrlBreakException\r\n{};\r\n\r\nvoid CheckCtrlBreak();\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UserInputUtils.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Error.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic const char *kTestString    =  \"Testing     \";\r\nstatic const char *kExtractString =  \"Extracting  \";\r\nstatic const char *kSkipString   =  \"Skipping    \";\r\n\r\n// static const char *kCantAutoRename = \"can not create file with auto name\\n\";\r\n// static const char *kCantRenameFile = \"can not rename existing file\\n\";\r\n// static const char *kCantDeleteOutputFile = \"can not delete output file \";\r\nstatic const char *kError = \"ERROR: \";\r\nstatic const char *kMemoryExceptionMessage = \"Can't allocate required memory!\";\r\n\r\nstatic const char *kProcessing = \"Processing archive: \";\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kNoFiles = \"No files to process\";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCrcFailed = \"CRC Failed\";\r\nstatic const char *kCrcFailedEncrypted = \"CRC Failed in encrypted file. Wrong password?\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kDataErrorEncrypted = \"Data Error in encrypted file. Wrong password?\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::AskOverwrite(\r\n    const wchar_t *existName, const FILETIME *, const UInt64 *,\r\n    const wchar_t *newName, const FILETIME *, const UInt64 *,\r\n    Int32 *answer)\r\n{\r\n  (*OutStream) << \"file \" << existName <<\r\n    \"\\nalready exists. Overwrite with \" << endl;\r\n  (*OutStream) << newName;\r\n  \r\n  NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);\r\n  \r\n  switch(overwriteAnswer)\r\n  {\r\n    case NUserAnswerMode::kQuit:  return E_ABORT;\r\n    case NUserAnswerMode::kNo:     *answer = NOverwriteAnswer::kNo; break;\r\n    case NUserAnswerMode::kNoAll:  *answer = NOverwriteAnswer::kNoToAll; break;\r\n    case NUserAnswerMode::kYesAll: *answer = NOverwriteAnswer::kYesToAll; break;\r\n    case NUserAnswerMode::kYes:    *answer = NOverwriteAnswer::kYes; break;\r\n    case NUserAnswerMode::kAutoRenameAll: *answer = NOverwriteAnswer::kAutoRename; break;\r\n    default: return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position)\r\n{\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract: (*OutStream) << kExtractString; break;\r\n    case NArchive::NExtract::NAskMode::kTest:    (*OutStream) << kTestString; break;\r\n    case NArchive::NExtract::NAskMode::kSkip:    (*OutStream) << kSkipString; break;\r\n  };\r\n  (*OutStream) << name;\r\n  if (position != 0)\r\n    (*OutStream) << \" <\" << *position << \">\";\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)\r\n{\r\n  (*OutStream) << message << endl;\r\n  NumFileErrorsInCurrentArchive++;\r\n  NumFileErrors++;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumFileErrorsInCurrentArchive++;\r\n      NumFileErrors++;\r\n      (*OutStream) << \"     \";\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          (*OutStream) << kUnsupportedMethod;\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError);\r\n          break;\r\n        default:\r\n          (*OutStream) << kUnknownError;\r\n      }\r\n    }\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\n\r\nHRESULT CExtractCallbackConsole::SetPassword(const UString &password)\r\n{\r\n  PasswordIsDefined = true;\r\n  Password = password;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream);\r\n    PasswordIsDefined = true;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)\r\n{\r\n  NumArchives++;\r\n  NumFileErrorsInCurrentArchive = 0;\r\n  (*OutStream) << endl << kProcessing << name << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT result, bool encrypted)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n  {\r\n    (*OutStream) << \"Error: \";\r\n    if (result == S_FALSE)\r\n    {\r\n      (*OutStream) << (encrypted ?\r\n        \"Can not open encrypted archive. Wrong password?\" :\r\n        \"Can not open file as archive\");\r\n    }\r\n    else\r\n    {\r\n      if (result == E_OUTOFMEMORY)\r\n        (*OutStream) << \"Can't allocate required memory\";\r\n      else\r\n        (*OutStream) << NError::MyFormatMessage(result);\r\n    }\r\n    (*OutStream) << endl;\r\n    NumArchiveErrors++;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nHRESULT CExtractCallbackConsole::ThereAreNoFiles()\r\n{\r\n  (*OutStream) << endl << kNoFiles << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)\r\n{\r\n  if (result == S_OK)\r\n  {\r\n    (*OutStream) << endl;\r\n    if (NumFileErrorsInCurrentArchive == 0)\r\n      (*OutStream) << kEverythingIsOk << endl;\r\n    else\r\n    {\r\n      NumArchiveErrors++;\r\n      (*OutStream) << \"Sub items Errors: \" << NumFileErrorsInCurrentArchive << endl;\r\n    }\r\n  }\r\n  if (result == S_OK)\r\n    return result;\r\n  NumArchiveErrors++;\r\n  if (result == E_ABORT || result == ERROR_DISK_FULL)\r\n    return result;\r\n  (*OutStream) << endl << kError;\r\n  if (result == E_OUTOFMEMORY)\r\n    (*OutStream) << kMemoryExceptionMessage;\r\n  else\r\n  {\r\n    UString message;\r\n    NError::MyFormatMessage(result, message);\r\n    (*OutStream) << message;\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.h",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#ifndef __EXTRACTCALLBACKCONSOLE_H\r\n#define __EXTRACTCALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../Common/ArchiveExtractCallback.h\"\r\n\r\nclass CExtractCallbackConsole:\r\n  public IExtractCallbackUI,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IFolderArchiveExtractCallback)\r\n  #ifndef _NO_CRYPTO\r\n  MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)\r\n  #endif\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  STDMETHOD(SetTotal)(UInt64 total);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IFolderArchiveExtractCallback\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer);\r\n  STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position);\r\n\r\n  STDMETHOD(MessageError)(const wchar_t *message);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);\r\n\r\n  HRESULT BeforeOpen(const wchar_t *name);\r\n  HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);\r\n  HRESULT ThereAreNoFiles();\r\n  HRESULT ExtractResult(HRESULT result);\r\n\r\n \r\n  #ifndef _NO_CRYPTO\r\n  HRESULT SetPassword(const UString &password);\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  #endif\r\n  \r\n  UInt64 NumArchives;\r\n  UInt64 NumArchiveErrors;\r\n  UInt64 NumFileErrors;\r\n  UInt64 NumFileErrorsInCurrentArchive;\r\n\r\n  CStdOutStream *OutStream;\r\n\r\n  void Init()\r\n  {\r\n    NumArchives = 0;\r\n    NumArchiveErrors = 0;\r\n    NumFileErrors = 0;\r\n    NumFileErrorsInCurrentArchive = 0;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/List.cpp",
    "content": "// List.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"List.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../Common/PropIDUtils.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstruct CPropIdToName\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n};\r\n\r\nstatic CPropIdToName kPropIdToName[] =\r\n{\r\n  { kpidPath, L\"Path\" },\r\n  { kpidName, L\"Name\" },\r\n  { kpidIsDir, L\"Folder\" },\r\n  { kpidSize, L\"Size\" },\r\n  { kpidPackSize, L\"Packed Size\" },\r\n  { kpidAttrib, L\"Attributes\" },\r\n  { kpidCTime, L\"Created\" },\r\n  { kpidATime, L\"Accessed\" },\r\n  { kpidMTime, L\"Modified\" },\r\n  { kpidSolid, L\"Solid\" },\r\n  { kpidCommented, L\"Commented\" },\r\n  { kpidEncrypted, L\"Encrypted\" },\r\n  { kpidSplitBefore, L\"Split Before\" },\r\n  { kpidSplitAfter, L\"Split After\" },\r\n  { kpidDictionarySize, L\"Dictionary Size\" },\r\n  { kpidCRC, L\"CRC\" },\r\n  { kpidType, L\"Type\" },\r\n  { kpidIsAnti, L\"Anti\" },\r\n  { kpidMethod, L\"Method\" },\r\n  { kpidHostOS, L\"Host OS\" },\r\n  { kpidFileSystem, L\"File System\" },\r\n  { kpidUser, L\"User\" },\r\n  { kpidGroup, L\"Group\" },\r\n  { kpidBlock, L\"Block\" },\r\n  { kpidComment, L\"Comment\" },\r\n  { kpidPosition, L\"Position\" },\r\n  { kpidPrefix, L\"Prefix\" },\r\n  { kpidNumSubDirs, L\"Folders\" },\r\n  { kpidNumSubFiles, L\"Files\" },\r\n  { kpidUnpackVer, L\"Version\" },\r\n  { kpidVolume, L\"Volume\" },\r\n  { kpidIsVolume, L\"Multivolume\" },\r\n  { kpidOffset, L\"Offset\" },\r\n  { kpidLinks, L\"Links\" },\r\n  { kpidNumBlocks, L\"Blocks\" },\r\n  { kpidNumVolumes, L\"Volumes\" },\r\n\r\n  { kpidBit64, L\"64-bit\" },\r\n  { kpidBigEndian, L\"Big-endian\" },\r\n  { kpidCpu, L\"CPU\" },\r\n  { kpidPhySize, L\"Physical Size\" },\r\n  { kpidHeadersSize, L\"Headers Size\" },\r\n  { kpidChecksum, L\"Checksum\" },\r\n  { kpidCharacts, L\"Characteristics\" },\r\n  { kpidVa, L\"Virtual Address\" },\r\n  { kpidFreeSpace, L\"Free Space\" },\r\n  { kpidClusterSize, L\"Cluster Size\" }\r\n};\r\n\r\nstatic const char kEmptyAttribChar = '.';\r\n\r\nstatic const char *kListing = \"Listing archive: \";\r\nstatic const wchar_t *kFilesMessage = L\"files\";\r\nstatic const wchar_t *kDirsMessage = L\"folders\";\r\n\r\nstatic void GetAttribString(DWORD wa, bool isDir, char *s)\r\n{\r\n  s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : kEmptyAttribChar;\r\n  s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0) ? 'R': kEmptyAttribChar;\r\n  s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? 'H': kEmptyAttribChar;\r\n  s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? 'S': kEmptyAttribChar;\r\n  s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? 'A': kEmptyAttribChar;\r\n  s[5] = '\\0';\r\n}\r\n\r\nenum EAdjustment\r\n{\r\n  kLeft,\r\n  kCenter,\r\n  kRight\r\n};\r\n\r\nstruct CFieldInfo\r\n{\r\n  PROPID PropID;\r\n  UString Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nstruct CFieldInfoInit\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nCFieldInfoInit kStandardFieldTable[] =\r\n{\r\n  { kpidMTime, L\"   Date      Time\", kLeft, kLeft, 0, 19 },\r\n  { kpidAttrib, L\"Attr\", kRight, kCenter, 1, 5 },\r\n  { kpidSize, L\"Size\", kRight, kRight, 1, 12 },\r\n  { kpidPackSize, L\"Compressed\", kRight, kRight, 1, 12 },\r\n  { kpidPath, L\"Name\", kLeft, kLeft, 2, 24 }\r\n};\r\n\r\nvoid PrintSpaces(int numSpaces)\r\n{\r\n  for (int i = 0; i < numSpaces; i++)\r\n    g_StdOut << ' ';\r\n}\r\n\r\nvoid PrintString(EAdjustment adjustment, int width, const UString &textString)\r\n{\r\n  const int numSpaces = width - textString.Length();\r\n  int numLeftSpaces = 0;\r\n  switch (adjustment)\r\n  {\r\n    case kLeft:\r\n      numLeftSpaces = 0;\r\n      break;\r\n    case kCenter:\r\n      numLeftSpaces = numSpaces / 2;\r\n      break;\r\n    case kRight:\r\n      numLeftSpaces = numSpaces;\r\n      break;\r\n  }\r\n  PrintSpaces(numLeftSpaces);\r\n  g_StdOut << textString;\r\n  PrintSpaces(numSpaces - numLeftSpaces);\r\n}\r\n\r\nclass CFieldPrinter\r\n{\r\n  CObjectVector<CFieldInfo> _fields;\r\npublic:\r\n  void Clear() { _fields.Clear(); }\r\n  void Init(const CFieldInfoInit *standardFieldTable, int numItems);\r\n  HRESULT Init(IInArchive *archive);\r\n  void PrintTitle();\r\n  void PrintTitleLines();\r\n  HRESULT PrintItemInfo(IInArchive *archive,\r\n      const UString &defaultItemName,\r\n      UInt32 index,\r\n      bool techMode);\r\n  HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\r\n      const UInt64 *size, const UInt64 *compressedSize);\r\n};\r\n\r\nvoid CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)\r\n{\r\n  Clear();\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    CFieldInfo fieldInfo;\r\n    const CFieldInfoInit &fieldInfoInit = standardFieldTable[i];\r\n    fieldInfo.PropID = fieldInfoInit.PropID;\r\n    fieldInfo.Name = fieldInfoInit.Name;\r\n    fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment;\r\n    fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment;\r\n    fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth;\r\n    fieldInfo.Width = fieldInfoInit.Width;\r\n    _fields.Add(fieldInfo);\r\n  }\r\n}\r\n\r\nstatic UString GetPropName(PROPID propID, BSTR name)\r\n{\r\n  for (int i = 0; i < sizeof(kPropIdToName) / sizeof(kPropIdToName[0]); i++)\r\n  {\r\n    const CPropIdToName &propIdToName = kPropIdToName[i];\r\n    if (propIdToName.PropID == propID)\r\n      return propIdToName.Name;\r\n  }\r\n  if (name)\r\n    return name;\r\n  wchar_t s[32];\r\n  ConvertUInt64ToString(propID, s);\r\n  return s;\r\n}\r\n\r\nHRESULT CFieldPrinter::Init(IInArchive *archive)\r\n{\r\n  Clear();\r\n  UInt32 numProps;\r\n  RINOK(archive->GetNumberOfProperties(&numProps));\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    CMyComBSTR name;\r\n    PROPID propID;\r\n    VARTYPE vt;\r\n    RINOK(archive->GetPropertyInfo(i, &name, &propID, &vt));\r\n    CFieldInfo fieldInfo;\r\n    fieldInfo.PropID = propID;\r\n    fieldInfo.Name = GetPropName(propID, name);\r\n    _fields.Add(fieldInfo);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitle()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    PrintString(fieldInfo.TitleAdjustment,\r\n      ((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);\r\n  }\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitleLines()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    for (int i = 0; i < fieldInfo.Width; i++)\r\n      g_StdOut << '-';\r\n  }\r\n}\r\n\r\n\r\nBOOL IsFileTimeZero(CONST FILETIME *lpFileTime)\r\n{\r\n  return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);\r\n}\r\n\r\nstatic const char *kEmptyTimeString = \"                   \";\r\nvoid PrintTime(const NCOM::CPropVariant &prop)\r\n{\r\n  if (prop.vt != VT_FILETIME)\r\n    throw \"incorrect item\";\r\n  if (IsFileTimeZero(&prop.filetime))\r\n    g_StdOut << kEmptyTimeString;\r\n  else\r\n  {\r\n    FILETIME localFileTime;\r\n    if (!FileTimeToLocalFileTime(&prop.filetime, &localFileTime))\r\n      throw \"FileTimeToLocalFileTime error\";\r\n    char s[32];\r\n    if (ConvertFileTimeToString(localFileTime, s, true, true))\r\n      g_StdOut << s;\r\n    else\r\n      g_StdOut << kEmptyTimeString;\r\n  }\r\n}\r\n\r\nHRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    UInt32 index,\r\n    bool techMode)\r\n{\r\n  /*\r\n  if (techMode)\r\n  {\r\n    g_StdOut << \"Index = \";\r\n    g_StdOut << (UInt64)index;\r\n    g_StdOut << endl;\r\n  }\r\n  */\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    if (!techMode)\r\n      PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      UString s;\r\n      RINOK(GetArchiveItemPath(archive, index, defaultItemName, s));\r\n      prop = s;\r\n    }\r\n    else\r\n    {\r\n      RINOK(archive->GetProperty(index, fieldInfo.PropID, &prop));\r\n    }\r\n    if (techMode)\r\n    {\r\n      g_StdOut << fieldInfo.Name << \" = \";\r\n    }\r\n    int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;\r\n    if (prop.vt == VT_EMPTY)\r\n    {\r\n      switch(fieldInfo.PropID)\r\n      {\r\n        case kpidPath:  prop = defaultItemName; break;\r\n        default:\r\n          if (techMode)\r\n            g_StdOut << endl;\r\n          else\r\n            PrintSpaces(width);\r\n          continue;\r\n      }\r\n    }\r\n    if (fieldInfo.PropID == kpidMTime)\r\n    {\r\n      PrintTime(prop);\r\n    }\r\n    else if (fieldInfo.PropID == kpidAttrib)\r\n    {\r\n      if (prop.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      UInt32 attributes = prop.ulVal;\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, index, isFolder));\r\n      char s[8];\r\n      GetAttribString(attributes, isFolder, s);\r\n      g_StdOut << s;\r\n    }\r\n    else if (prop.vt == VT_BSTR)\r\n    {\r\n      if (techMode)\r\n        g_StdOut << prop.bstrVal;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, prop.bstrVal);\r\n    }\r\n    else\r\n    {\r\n      UString s = ConvertPropertyToString(prop, fieldInfo.PropID);\r\n      s.Replace(wchar_t(0xA), L' ');\r\n      s.Replace(wchar_t(0xD), L' ');\r\n\r\n      if (techMode)\r\n        g_StdOut << s;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, s);\r\n    }\r\n    if (techMode)\r\n      g_StdOut << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)\r\n{\r\n  wchar_t textString[32] = { 0 };\r\n  if (value != NULL)\r\n    ConvertUInt64ToString(*value, textString);\r\n  PrintString(adjustment, width, textString);\r\n}\r\n\r\n\r\nHRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\r\n    const UInt64 *size, const UInt64 *compressedSize)\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    NCOM::CPropVariant prop;\r\n    if (fieldInfo.PropID == kpidSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);\r\n    else if (fieldInfo.PropID == kpidPackSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);\r\n    else if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      wchar_t textString[32];\r\n      ConvertUInt64ToString(numFiles, textString);\r\n      UString temp = textString;\r\n      temp += L\" \";\r\n      temp += kFilesMessage;\r\n      temp += L\", \";\r\n      ConvertUInt64ToString(numDirs, textString);\r\n      temp += textString;\r\n      temp += L\" \";\r\n      temp += kDirsMessage;\r\n      PrintString(fieldInfo.TextAdjustment, 0, temp);\r\n    }\r\n    else\r\n      PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L\"\");\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nbool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  if (archive->GetProperty(index, propID, &prop) != S_OK)\r\n    throw \"GetPropertyValue error\";\r\n  if (prop.vt == VT_EMPTY)\r\n    return false;\r\n  value = ConvertPropVariantToUInt64(prop);\r\n  return true;\r\n}\r\n\r\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode,\r\n    #ifndef _NO_CRYPTO\r\n    bool &passwordEnabled, UString &password,\r\n    #endif\r\n    UInt64 &numErrors)\r\n{\r\n  numErrors = 0;\r\n  CFieldPrinter fieldPrinter;\r\n  if (!techMode)\r\n    fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));\r\n\r\n  UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;\r\n  UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;\r\n  for (int i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archiveName = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archiveName, fi) || fi.IsDir())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not file\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    CArchiveLink archiveLink;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &g_StdOut;\r\n\r\n    #ifndef _NO_CRYPTO\r\n\r\n    openCallback.PasswordIsDefined = passwordEnabled;\r\n    openCallback.Password = password;\r\n\r\n    #endif\r\n\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, &openCallback);\r\n    if (result != S_OK)\r\n    {\r\n      if (result == E_ABORT)\r\n        return result;\r\n      g_StdOut << endl << \"Error: \" << archiveName << \": \";\r\n      if (result == S_FALSE)\r\n        g_StdOut << \"is not supported archive\";\r\n      else if (result == E_OUTOFMEMORY)\r\n        g_StdOut << \"Can't allocate required memory\";\r\n      else\r\n        g_StdOut << NError::MyFormatMessage(result);\r\n      g_StdOut << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n      }\r\n    }\r\n\r\n    IInArchive *archive = archiveLink.GetArchive();\r\n    const UString defaultItemName = archiveLink.GetDefaultItemName();\r\n\r\n    if (enableHeaders)\r\n    {\r\n      g_StdOut << endl << kListing << archiveName << endl << endl;\r\n\r\n      UInt32 numProps;\r\n      if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)\r\n      {\r\n        for (UInt32 i = 0; i < numProps; i++)\r\n        {\r\n          CMyComBSTR name;\r\n          PROPID propID;\r\n          VARTYPE vt;\r\n          if (archive->GetArchivePropertyInfo(i, &name, &propID, &vt) != S_OK)\r\n            continue;\r\n          NCOM::CPropVariant prop;\r\n          if (archive->GetArchiveProperty(propID, &prop) != S_OK)\r\n            continue;\r\n          UString s = ConvertPropertyToString(prop, propID);\r\n          if (!s.IsEmpty())\r\n            g_StdOut << GetPropName(propID, name) << \" = \" << s << endl;\r\n        }\r\n      }\r\n      if (techMode)\r\n        g_StdOut << \"----------\\n\";\r\n      if (numProps > 0)\r\n        g_StdOut << endl;\r\n    }\r\n\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitle();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n    }\r\n\r\n    if (techMode)\r\n    {\r\n      RINOK(fieldPrinter.Init(archive));\r\n    }\r\n    UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0;\r\n    UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;\r\n    UInt32 numItems;\r\n    RINOK(archive->GetNumberOfItems(&numItems));\r\n    for(UInt32 i = 0; i < numItems; i++)\r\n    {\r\n      if (NConsoleClose::TestBreakSignal())\r\n        return E_ABORT;\r\n\r\n      UString filePath;\r\n      RINOK(GetArchiveItemPath(archive, i, defaultItemName, filePath));\r\n\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n      if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n        continue;\r\n      \r\n      fieldPrinter.PrintItemInfo(archive, defaultItemName, i, techMode);\r\n      \r\n      UInt64 packSize, unpackSize;\r\n      if (!GetUInt64Value(archive, i, kpidSize, unpackSize))\r\n        unpackSize = 0;\r\n      else\r\n        totalUnPackSizePointer = &totalUnPackSize;\r\n      if (!GetUInt64Value(archive, i, kpidPackSize, packSize))\r\n        packSize = 0;\r\n      else\r\n        totalPackSizePointer = &totalPackSize;\r\n      \r\n      g_StdOut << endl;\r\n\r\n      if (isFolder)\r\n        numDirs++;\r\n      else\r\n        numFiles++;\r\n      totalPackSize += packSize;\r\n      totalUnPackSize += unpackSize;\r\n    }\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintSummaryInfo(numFiles, numDirs, totalUnPackSizePointer, totalPackSizePointer);\r\n      g_StdOut << endl;\r\n    }\r\n    if (totalPackSizePointer != 0)\r\n    {\r\n      totalPackSizePointer2 = &totalPackSize2;\r\n      totalPackSize2 += totalPackSize;\r\n    }\r\n    if (totalUnPackSizePointer != 0)\r\n    {\r\n      totalUnPackSizePointer2 = &totalUnPackSize2;\r\n      totalUnPackSize2 += totalUnPackSize;\r\n    }\r\n    numFiles2 += numFiles;\r\n    numDirs2 += numDirs;\r\n  }\r\n  if (enableHeaders && !techMode && archivePaths.Size() > 1)\r\n  {\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintTitleLines();\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintSummaryInfo(numFiles2, numDirs2, totalUnPackSizePointer2, totalPackSizePointer2);\r\n    g_StdOut << endl;\r\n    g_StdOut << \"Archives: \" << archivePaths.Size() << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/List.h",
    "content": "// List.h\r\n\r\n#ifndef __LIST_H\r\n#define __LIST_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode,\r\n    #ifndef _NO_CRYPTO\r\n    bool &passwordEnabled, UString &password,\r\n    #endif\r\n    UInt64 &errors);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/Main.cpp",
    "content": "// Main.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n\r\n#include \"Common/CommandLineParser.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/Error.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/MemoryLock.h\"\r\n#endif\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/UpdateAction.h\"\r\n#include \"../Common/Update.h\"\r\n#include \"../Common/Extract.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"../Common/ExitCode.h\"\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../Common/LoadCodecs.h\"\r\n#endif\r\n\r\n#include \"../../Compress/LZMA_Alone/LzmaBenchCon.h\"\r\n\r\n#include \"List.h\"\r\n#include \"OpenCallbackConsole.h\"\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\n#if defined( _WIN32) && defined( _7ZIP_LARGE_PAGES)\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NCommandLineParser;\r\n\r\nHINSTANCE g_hInstance = 0;\r\nextern CStdOutStream *g_StdStream;\r\n\r\nstatic const char *kCopyrightString = \"\\n7-Zip\"\r\n#ifndef EXTERNAL_CODECS\r\n\" (A)\"\r\n#endif\r\n\r\n#ifdef _WIN64\r\n\" [64]\"\r\n#endif\r\n\r\n\" \" MY_VERSION_COPYRIGHT_DATE \"\\n\";\r\n\r\nstatic const char *kHelpString =\r\n    \"\\nUsage: 7z\"\r\n#ifdef _NO_CRYPTO\r\n    \"r\"\r\n#else\r\n#ifndef EXTERNAL_CODECS\r\n    \"a\"\r\n#endif\r\n#endif\r\n    \" <command> [<switches>...] <archive_name> [<file_names>...]\\n\"\r\n    \"       [<@listfiles...>]\\n\"\r\n    \"\\n\"\r\n    \"<Commands>\\n\"\r\n    \"  a: Add files to archive\\n\"\r\n    \"  b: Benchmark\\n\"\r\n    \"  d: Delete files from archive\\n\"\r\n    \"  e: Extract files from archive (without using directory names)\\n\"\r\n    \"  l: List contents of archive\\n\"\r\n//    \"  l[a|t][f]: List contents of archive\\n\"\r\n//    \"    a - with Additional fields\\n\"\r\n//    \"    t - with all fields\\n\"\r\n//    \"    f - with Full pathnames\\n\"\r\n    \"  t: Test integrity of archive\\n\"\r\n    \"  u: Update files to archive\\n\"\r\n    \"  x: eXtract files with full paths\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -ai[r[-|0]]{@listfile|!wildcard}: Include archives\\n\"\r\n    \"  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives\\n\"\r\n    \"  -bd: Disable percentage indicator\\n\"\r\n    \"  -i[r[-|0]]{@listfile|!wildcard}: Include filenames\\n\"\r\n    \"  -m{Parameters}: set compression Method\\n\"\r\n    \"  -o{Directory}: set Output directory\\n\"\r\n    #ifndef _NO_CRYPTO\r\n    \"  -p{Password}: set Password\\n\"\r\n    #endif\r\n    \"  -r[-|0]: Recurse subdirectories\\n\"\r\n    \"  -scs{UTF-8 | WIN | DOS}: set charset for list files\\n\"\r\n    \"  -sfx[{name}]: Create SFX archive\\n\"\r\n    \"  -si[{name}]: read data from stdin\\n\"\r\n    \"  -slt: show technical information for l (List) command\\n\"\r\n    \"  -so: write data to stdout\\n\"\r\n    \"  -ssc[-]: set sensitive case mode\\n\"\r\n    \"  -ssw: compress shared files\\n\"\r\n    \"  -t{Type}: Set type of archive\\n\"\r\n    \"  -v{Size}[b|k|m|g]: Create volumes\\n\"\r\n    \"  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\\n\"\r\n    \"  -w[{path}]: assign Work directory. Empty path means a temporary directory\\n\"\r\n    \"  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\\n\"\r\n    \"  -y: assume Yes on all queries\\n\";\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\"; // NExitCode::kUserError\r\nstatic const char *kNoFormats = \"7-Zip cannot find the code that works with archives.\";\r\n\r\nstatic const wchar_t *kDefaultSfxModule = L\"7zCon.sfx\";\r\n\r\nstatic void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code)\r\n{\r\n  s << message << endl;\r\n  throw code;\r\n}\r\n\r\nstatic void PrintHelpAndExit(CStdOutStream &s) // yyy\r\n{\r\n  s << kHelpString;\r\n  ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError);\r\n}\r\n\r\n#ifndef _WIN32\r\nstatic void GetArguments(int numArguments, const char *arguments[], UStringVector &parts)\r\n{\r\n  parts.Clear();\r\n  for(int i = 0; i < numArguments; i++)\r\n  {\r\n    UString s = MultiByteToUnicodeString(arguments[i]);\r\n    parts.Add(s);\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp)\r\n{\r\n  s << kCopyrightString;\r\n  // s << \"# CPUs: \" << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << \"\\n\";\r\n  if (needHelp)\r\n    s << kHelpString;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic void PrintString(CStdOutStream &stdStream, const AString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n#endif\r\n\r\nstatic void PrintString(CStdOutStream &stdStream, const UString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n\r\nstatic inline char GetHex(Byte value)\r\n{\r\n  return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nconst char *kUnsupportedArcTypeMessage = \"Unsupported archive type\";\r\n\r\nint Main2(\r\n  #ifndef _WIN32\r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n)\r\n{\r\n  #ifdef _WIN32\r\n  SetFileApisToOEM();\r\n  #endif\r\n  \r\n  UStringVector commandStrings;\r\n  #ifdef _WIN32\r\n  NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);\r\n  #else\r\n  GetArguments(numArguments, arguments, commandStrings);\r\n  #endif\r\n\r\n  if(commandStrings.Size() == 1)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n  commandStrings.Delete(0);\r\n\r\n  CArchiveCommandLineOptions options;\r\n\r\n  CArchiveCommandLineParser parser;\r\n\r\n  parser.Parse1(commandStrings, options);\r\n\r\n  if(options.HelpMode)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  if (options.LargePages)\r\n  {\r\n    SetLargePageSize();\r\n    NSecurity::EnableLockMemoryPrivilege();\r\n  }\r\n  #endif\r\n\r\n  CStdOutStream &stdStream = options.StdOutMode ? g_StdErr : g_StdOut;\r\n  g_StdStream = &stdStream;\r\n\r\n  if (options.EnableHeaders)\r\n    ShowCopyrightAndHelp(stdStream, false);\r\n\r\n  parser.Parse2(options);\r\n\r\n  CCodecs *codecs = new CCodecs;\r\n  CMyComPtr<\r\n    #ifdef EXTERNAL_CODECS\r\n    ICompressCodecsInfo\r\n    #else\r\n    IUnknown\r\n    #endif\r\n    > compressCodecsInfo = codecs;\r\n  HRESULT result = codecs->Load();\r\n  if (result != S_OK)\r\n    throw CSystemException(result);\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  if (codecs->Formats.Size() == 0 &&\r\n        (isExtractGroupCommand ||\r\n        options.Command.CommandType == NCommandType::kList ||\r\n        options.Command.IsFromUpdateGroup()))\r\n    throw kNoFormats;\r\n\r\n  CIntVector formatIndices;\r\n  if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices))\r\n    throw kUnsupportedArcTypeMessage;\r\n\r\n  if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n    stdStream << endl << \"Formats:\" << endl;\r\n    int i;\r\n    for (i = 0; i < codecs->Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = codecs->Formats[i];\r\n      #ifdef EXTERNAL_CODECS\r\n      if (arc.LibIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(arc.LibIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n      #endif\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(arc.UpdateEnabled ? 'C' : ' ');\r\n      stdStream << (char)(arc.KeepName ? 'K' : ' ');\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, arc.Name, 6);\r\n      stdStream << \"  \";\r\n      UString s;\r\n      for (int t = 0; t < arc.Exts.Size(); t++)\r\n      {\r\n        const CArcExtInfo &ext = arc.Exts[t];\r\n        s += ext.Ext;\r\n        if (!ext.AddExt.IsEmpty())\r\n        {\r\n          s += L\" (\";\r\n          s += ext.AddExt;\r\n          s += L')';\r\n        }\r\n        s += L' ';\r\n      }\r\n      PrintString(stdStream, s, 14);\r\n      stdStream << \"  \";\r\n      const CByteBuffer &sig = arc.StartSignature;\r\n      for (size_t j = 0; j < sig.GetCapacity(); j++)\r\n      {\r\n        Byte b = sig[j];\r\n        if (b > 0x20 && b < 0x80)\r\n        {\r\n          stdStream << (char)b;\r\n        }\r\n        else\r\n        {\r\n          stdStream << GetHex((Byte)((b >> 4) & 0xF));\r\n          stdStream << GetHex((Byte)(b & 0xF));\r\n        }\r\n        stdStream << ' ';\r\n      }\r\n      stdStream << endl;\r\n    }\r\n    stdStream << endl << \"Codecs:\" << endl;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    UInt32 numMethods;\r\n    if (codecs->GetNumberOfMethods(&numMethods) == S_OK)\r\n    for (UInt32 j = 0; j < numMethods; j++)\r\n    {\r\n      int libIndex = codecs->GetCodecLibIndex(j);\r\n      if (libIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(libIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(codecs->GetCodecEncoderIsAssigned(j) ? 'C' : ' ');\r\n      UInt64 id;\r\n      stdStream << \"  \";\r\n      HRESULT res = codecs->GetCodecId(j, id);\r\n      if (res != S_OK)\r\n        id = (UInt64)(Int64)-1;\r\n      char s[32];\r\n      ConvertUInt64ToString(id, s, 16);\r\n      PrintString(stdStream, s, 8);\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, codecs->GetCodecName(j), 11);\r\n      stdStream << endl;\r\n      /*\r\n      if (res != S_OK)\r\n        throw \"incorrect Codec ID\";\r\n      */\r\n    }\r\n    #endif\r\n    return S_OK;\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    if (options.Method.CompareNoCase(L\"CRC\") == 0)\r\n    {\r\n      HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nCRC Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      HRESULT res = LzmaBenchCon(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        (FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nDecoding Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n  }\r\n  else if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if(isExtractGroupCommand)\r\n    {\r\n      CExtractCallbackConsole *ecs = new CExtractCallbackConsole;\r\n      CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;\r\n\r\n      ecs->OutStream = &stdStream;\r\n\r\n      #ifndef _NO_CRYPTO\r\n      ecs->PasswordIsDefined = options.PasswordEnabled;\r\n      ecs->Password = options.Password;\r\n      #endif\r\n\r\n      ecs->Init();\r\n\r\n      COpenCallbackConsole openCallback;\r\n      openCallback.OutStream = &stdStream;\r\n\r\n      #ifndef _NO_CRYPTO\r\n      openCallback.PasswordIsDefined = options.PasswordEnabled;\r\n      openCallback.Password = options.Password;\r\n      #endif\r\n\r\n      CExtractOptions eo;\r\n      eo.StdOutMode = options.StdOutMode;\r\n      eo.PathMode = options.Command.GetPathMode();\r\n      eo.TestMode = options.Command.IsTestMode();\r\n      eo.OverwriteMode = options.OverwriteMode;\r\n      eo.OutputDir = options.OutputDir;\r\n      eo.YesToAll = options.YesToAll;\r\n      #ifdef COMPRESS_MT\r\n      eo.Properties = options.ExtractProperties;\r\n      #endif\r\n      UString errorMessage;\r\n      CDecompressStat stat;\r\n      HRESULT result = DecompressArchives(\r\n          codecs,\r\n          formatIndices,\r\n          options.ArchivePathsSorted,\r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head,\r\n          eo, &openCallback, ecs, errorMessage, stat);\r\n      if (!errorMessage.IsEmpty())\r\n      {\r\n        stdStream << endl << \"Error: \" << errorMessage;\r\n        if (result == S_OK)\r\n          result = E_FAIL;\r\n      }\r\n\r\n      stdStream << endl;\r\n      if (ecs->NumArchives > 1)\r\n        stdStream << \"Archives: \" << ecs->NumArchives << endl;\r\n      if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0)\r\n      {\r\n        if (ecs->NumArchives > 1)\r\n        {\r\n          stdStream << endl;\r\n          if (ecs->NumArchiveErrors != 0)\r\n            stdStream << \"Archive Errors: \" << ecs->NumArchiveErrors << endl;\r\n          if (ecs->NumFileErrors != 0)\r\n            stdStream << \"Sub items Errors: \" << ecs->NumFileErrors << endl;\r\n        }\r\n        if (result != S_OK)\r\n          throw CSystemException(result);\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n      if (stat.NumFolders != 0)\r\n        stdStream << \"Folders: \" << stat.NumFolders << endl;\r\n      if (stat.NumFiles != 1 || stat.NumFolders != 0)\r\n          stdStream << \"Files: \" << stat.NumFiles << endl;\r\n      stdStream\r\n           << \"Size:       \" << stat.UnpackSize << endl\r\n           << \"Compressed: \" << stat.PackSize << endl;\r\n    }\r\n    else\r\n    {\r\n      UInt64 numErrors = 0;\r\n      HRESULT result = ListArchives(\r\n          codecs,\r\n          formatIndices,\r\n          options.ArchivePathsSorted,\r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head,\r\n          options.EnableHeaders,\r\n          options.TechMode,\r\n          #ifndef _NO_CRYPTO\r\n          options.PasswordEnabled,\r\n          options.Password,\r\n          #endif\r\n          numErrors);\r\n      if (numErrors > 0)\r\n      {\r\n        g_StdOut << endl << \"Errors: \" << numErrors;\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    UString workingDir;\r\n\r\n    CUpdateOptions &uo = options.UpdateOptions;\r\n    if (uo.SfxMode && uo.SfxModule.IsEmpty())\r\n      uo.SfxModule = kDefaultSfxModule;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &stdStream;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    bool passwordIsDefined =\r\n        options.PasswordEnabled && !options.Password.IsEmpty();\r\n    openCallback.PasswordIsDefined = passwordIsDefined;\r\n    openCallback.Password = options.Password;\r\n    #endif\r\n\r\n    CUpdateCallbackConsole callback;\r\n    callback.EnablePercents = options.EnablePercents;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    callback.PasswordIsDefined = passwordIsDefined;\r\n    callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty();\r\n    callback.Password = options.Password;\r\n    #endif\r\n    callback.StdOutMode = uo.StdOutMode;\r\n    callback.Init(&stdStream);\r\n\r\n    CUpdateErrorInfo errorInfo;\r\n\r\n    if (!uo.Init(codecs, formatIndices, options.ArchiveName))\r\n      throw kUnsupportedArcTypeMessage;\r\n    HRESULT result = UpdateArchive(codecs,\r\n        options.WildcardCensor, uo,\r\n        errorInfo, &openCallback, &callback);\r\n\r\n    int exitCode = NExitCode::kSuccess;\r\n    if (callback.CantFindFiles.Size() > 0)\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      int numErrors = callback.CantFindFiles.Size();\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.CantFindFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.CantFindCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot find \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n\r\n    if (result != S_OK)\r\n    {\r\n      UString message;\r\n      if (!errorInfo.Message.IsEmpty())\r\n      {\r\n        message += errorInfo.Message;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName2.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName2;\r\n        message += L\"\\n\";\r\n      }\r\n      if (errorInfo.SystemError != 0)\r\n      {\r\n        message += NError::MyFormatMessageW(errorInfo.SystemError);\r\n        message += L\"\\n\";\r\n      }\r\n      if (!message.IsEmpty())\r\n        stdStream << L\"\\nError:\\n\" << message;\r\n      throw CSystemException(result);\r\n    }\r\n    int numErrors = callback.FailedFiles.Size();\r\n    if (numErrors == 0)\r\n    {\r\n      if (callback.CantFindFiles.Size() == 0)\r\n        stdStream << kEverythingIsOk << endl;\r\n    }\r\n    else\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.FailedFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.FailedCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot open \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n    return exitCode;\r\n  }\r\n  else\r\n    PrintHelpAndExit(stdStream);\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/MainAr.cpp",
    "content": "// MainAr.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <locale.h>\r\n\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"../Common/ExitCode.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCStdOutStream *g_StdStream = 0;\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\n#endif\r\n#if !defined(_UNICODE) || !defined(_WIN64)\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern int Main2(\r\n  #ifndef _WIN32\r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n);\r\n\r\nstatic const char *kExceptionErrorMessage = \"\\n\\nError:\\n\";\r\nstatic const char *kUserBreak  = \"\\nBreak signaled\\n\";\r\n\r\nstatic const char *kMemoryExceptionMessage = \"\\n\\nERROR: Can't allocate required memory!\\n\";\r\nstatic const char *kUnknownExceptionMessage = \"\\n\\nUnknown Error\\n\";\r\nstatic const char *kInternalExceptionMessage = \"\\n\\nInternal Error #\";\r\n\r\nint MY_CDECL main\r\n(\r\n#ifndef _WIN32\r\nint numArguments, const char *arguments[]\r\n#endif\r\n)\r\n{\r\n  g_StdStream = &g_StdOut;\r\n  #ifdef _WIN32\r\n  \r\n  #ifdef _UNICODE\r\n  #ifndef _WIN64\r\n  if (!IsItWindowsNT())\r\n  {\r\n    (*g_StdStream) << \"This program requires Windows NT/2000/2003/2008/XP/Vista\";\r\n    return NExitCode::kFatalError;\r\n  }\r\n  #endif\r\n  #else\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  \r\n  #endif\r\n\r\n  // setlocale(LC_COLLATE, \".OCP\");\r\n  NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;\r\n  int res = 0;\r\n  try\r\n  {\r\n    res = Main2(\r\n#ifndef _WIN32\r\n      numArguments, arguments\r\n#endif\r\n    );\r\n  }\r\n  catch(const CNewException &)\r\n  {\r\n    (*g_StdStream) << kMemoryExceptionMessage;\r\n    return (NExitCode::kMemoryError);\r\n  }\r\n  catch(const NConsoleClose::CCtrlBreakException &)\r\n  {\r\n    (*g_StdStream) << endl << kUserBreak;\r\n    return (NExitCode::kUserBreak);\r\n  }\r\n  catch(const CArchiveCommandLineException &e)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << e << endl;\r\n    return (NExitCode::kUserError);\r\n  }\r\n  catch(const CSystemException &systemError)\r\n  {\r\n    if (systemError.ErrorCode == E_OUTOFMEMORY)\r\n    {\r\n      (*g_StdStream) << kMemoryExceptionMessage;\r\n      return (NExitCode::kMemoryError);\r\n    }\r\n    if (systemError.ErrorCode == E_ABORT)\r\n    {\r\n      (*g_StdStream) << endl << kUserBreak;\r\n      return (NExitCode::kUserBreak);\r\n    }\r\n    UString message;\r\n    NError::MyFormatMessage(systemError.ErrorCode, message);\r\n    (*g_StdStream) << endl << endl << \"System error:\" << endl <<\r\n        message << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(NExitCode::EEnum &exitCode)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << exitCode << endl;\r\n    return (exitCode);\r\n  }\r\n  /*\r\n  catch(const NExitCode::CMultipleErrors &multipleErrors)\r\n  {\r\n    (*g_StdStream) << endl << multipleErrors.NumErrors << \" errors\" << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  */\r\n  catch(const UString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const AString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const char *s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(int t)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << t << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(...)\r\n  {\r\n    (*g_StdStream) << kUnknownExceptionMessage;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  return  res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.cpp",
    "content": "// OpenCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nHRESULT COpenCallbackConsole::Open_CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_SetTotal(const UInt64 *, const UInt64 *)\r\n{\r\n  return Open_CheckBreak();\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_SetCompleted(const UInt64 *, const UInt64 *)\r\n{\r\n  return Open_CheckBreak();\r\n}\r\n \r\n#ifndef _NO_CRYPTO\r\n\r\nHRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password)\r\n{\r\n  PasswordWasAsked = true;\r\n  RINOK(Open_CheckBreak());\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream);\r\n    PasswordIsDefined = true;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_GetPasswordIfAny(UString &password)\r\n{\r\n  if (PasswordIsDefined)\r\n    password = Password;\r\n  return S_OK;\r\n}\r\n\r\nbool COpenCallbackConsole::Open_WasPasswordAsked()\r\n{\r\n  return PasswordWasAsked;\r\n}\r\n\r\nvoid COpenCallbackConsole::Open_ClearPasswordWasAskedFlag()\r\n{\r\n  PasswordWasAsked = false;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.h",
    "content": "// OpenCallbackConsole.h\r\n\r\n#ifndef __OPENCALLBACKCONSOLE_H\r\n#define __OPENCALLBACKCONSOLE_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../Common/ArchiveOpenCallback.h\"\r\n\r\nclass COpenCallbackConsole: public IOpenCallbackUI\r\n{\r\npublic:\r\n  INTERFACE_IOpenCallbackUI(;)\r\n  \r\n  CStdOutStream *OutStream;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordIsDefined;\r\n  bool PasswordWasAsked;\r\n  UString Password;\r\n  COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {}\r\n  #endif\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/PercentPrinter.cpp",
    "content": "// PercentPrinter.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"PercentPrinter.h\"\r\n\r\nconst int kPaddingSize = 2;\r\nconst int kPercentsSize = 4;\r\nconst int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;\r\n\r\nstatic void ClearPrev(char *p, int num)\r\n{\r\n  int i;\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  for (i = 0; i < num; i++) *p++ = ' ';\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  *p = '\\0';\r\n}\r\n\r\nvoid CPercentPrinter::ClosePrint()\r\n{\r\n  if (m_NumExtraChars == 0)\r\n    return;\r\n  char s[kMaxExtraSize * 3 + 1];\r\n  ClearPrev(s, m_NumExtraChars);\r\n  (*OutStream) << s;\r\n  m_NumExtraChars = 0;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const char *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const wchar_t *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintNewLine()\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << \"\\n\";\r\n}\r\n\r\nvoid CPercentPrinter::RePrintRatio()\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s);\r\n  int size = (int)strlen(s);\r\n  s[size++] = '%';\r\n  s[size] = '\\0';\r\n\r\n  int extraSize = kPaddingSize + MyMax(size, kPercentsSize);\r\n  if (extraSize < m_NumExtraChars)\r\n    extraSize = m_NumExtraChars;\r\n\r\n  char fullString[kMaxExtraSize * 3];\r\n  char *p = fullString;\r\n  int i;\r\n  if (m_NumExtraChars == 0)\r\n  {\r\n    for (i = 0; i < extraSize; i++)\r\n      *p++ = ' ';\r\n    m_NumExtraChars = extraSize;\r\n  }\r\n\r\n  for (i = 0; i < m_NumExtraChars; i++)\r\n    *p++ = '\\b';\r\n  m_NumExtraChars = extraSize;\r\n  for (; size < m_NumExtraChars; size++)\r\n    *p++ = ' ';\r\n  MyStringCopy(p, s);\r\n  (*OutStream) << fullString;\r\n  OutStream->Flush();\r\n  m_PrevValue = m_CurValue;\r\n}\r\n\r\nvoid CPercentPrinter::PrintRatio()\r\n{\r\n  if (m_CurValue < m_PrevValue + m_MinStepSize &&\r\n      m_CurValue + m_MinStepSize > m_PrevValue && m_NumExtraChars != 0)\r\n    return;\r\n  RePrintRatio();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/PercentPrinter.h",
    "content": "// PercentPrinter.h\r\n\r\n#ifndef __PERCENTPRINTER_H\r\n#define __PERCENTPRINTER_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/StdOutStream.h\"\r\n\r\nclass CPercentPrinter\r\n{\r\n  UInt64 m_MinStepSize;\r\n  UInt64 m_PrevValue;\r\n  UInt64 m_CurValue;\r\n  UInt64 m_Total;\r\n  int m_NumExtraChars;\r\npublic:\r\n  CStdOutStream *OutStream;\r\n\r\n  CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize),\r\n      m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}\r\n  void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }\r\n  void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }\r\n  void PrintString(const char *s);\r\n  void PrintString(const wchar_t *s);\r\n  void PrintNewLine();\r\n  void ClosePrint();\r\n  void RePrintRatio();\r\n  void PrintRatio();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp",
    "content": "// UpdateCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifdef COMPRESS_MT\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nusing namespace NWindows;\r\n\r\n#ifdef COMPRESS_MT\r\nstatic NSynchronization::CCriticalSection g_CriticalSection;\r\n#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);\r\n#else\r\n#define MT_LOCK\r\n#endif\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nstatic const char *kCreatingArchiveMessage = \"Creating archive \";\r\nstatic const char *kUpdatingArchiveMessage = \"Updating archive \";\r\nstatic const char *kScanningMessage = \"Scanning\";\r\n\r\n\r\nHRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n    (*OutStream) << \"Error: \" << name << \" is not supported archive\" << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartScanning()\r\n{\r\n  (*OutStream) << kScanningMessage;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::ScanProgress(UInt64 /* numFolders */, UInt64 /* numFiles */, const wchar_t * /* path */)\r\n{\r\n  return CheckBreak();\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)\r\n{\r\n  CantFindFiles.Add(name);\r\n  CantFindCodes.Add(systemError);\r\n  // m_PercentPrinter.ClosePrint();\r\n  if (!m_WarningsMode)\r\n  {\r\n    (*OutStream) << endl << endl;\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_WarningsMode = true;\r\n  }\r\n  m_PercentPrinter.PrintString(name);\r\n  m_PercentPrinter.PrintString(\":  WARNING: \");\r\n  m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n  m_PercentPrinter.PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishScanning()\r\n{\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)\r\n{\r\n  if(updating)\r\n    (*OutStream) << kUpdatingArchiveMessage;\r\n  else\r\n    (*OutStream) << kCreatingArchiveMessage;\r\n  if (name != 0)\r\n    (*OutStream) << name;\r\n  else\r\n    (*OutStream) << \"StdOut\";\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishArchive()\r\n{\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::Finilize()\r\n{\r\n  MT_LOCK\r\n  if (m_NeedBeClosed)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.ClosePrint();\r\n    }\r\n    if (!StdOutMode && m_NeedNewLine)\r\n    {\r\n      m_PercentPrinter.PrintNewLine();\r\n      m_NeedNewLine = false;\r\n    }\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)\r\n{\r\n  MT_LOCK\r\n  if (EnablePercents)\r\n    m_PercentPrinter.SetTotal(size);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  MT_LOCK\r\n  if (completeValue != NULL)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.SetRatio(*completeValue);\r\n      m_PercentPrinter.PrintRatio();\r\n      m_NeedBeClosed = true;\r\n    }\r\n  }\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)\r\n{\r\n  MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  if(isAnti)\r\n    m_PercentPrinter.PrintString(\"Anti item    \");\r\n  else\r\n    m_PercentPrinter.PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)\r\n{\r\n  MT_LOCK\r\n  FailedCodes.Add(systemError);\r\n  FailedFiles.Add(name);\r\n  // if (systemError == ERROR_SHARING_VIOLATION)\r\n  {\r\n    m_PercentPrinter.ClosePrint();\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_PercentPrinter.PrintString(\"WARNING: \");\r\n    m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n    return S_FALSE;\r\n  }\r\n  // return systemError;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )\r\n{\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  #ifdef _NO_CRYPTO\r\n\r\n  *passwordIsDefined = false;\r\n  return StringToBstr(L\"\", password);\r\n  \r\n  #else\r\n  \r\n  if (!PasswordIsDefined)\r\n  {\r\n    if (AskPassword)\r\n    {\r\n      Password = GetPassword(OutStream);\r\n      PasswordIsDefined = true;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  return StringToBstr(Password, password);\r\n  \r\n  #endif\r\n  \r\n}\r\n\r\n/*\r\nHRESULT CUpdateCallbackConsole::ShowDeleteFile(const wchar_t *name)\r\n{\r\n  // MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  RINOK(Finilize());\r\n  m_PercentPrinter.PrintString(\"Deleting  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.h",
    "content": "// UpdateCallbackConsole.h\r\n\r\n#ifndef __UPDATECALLBACKCONSOLE_H\r\n#define __UPDATECALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"PercentPrinter.h\"\r\n#include \"../Common/Update.h\"\r\n\r\nclass CUpdateCallbackConsole: public IUpdateCallbackUI2\r\n{\r\n  CPercentPrinter m_PercentPrinter;\r\n  bool m_NeedBeClosed;\r\n  bool m_NeedNewLine;\r\n\r\n  bool m_WarningsMode;\r\n\r\n  CStdOutStream *OutStream;\r\npublic:\r\n  bool EnablePercents;\r\n  bool StdOutMode;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n  #endif\r\n\r\n  CUpdateCallbackConsole():\r\n      m_PercentPrinter(1 << 16),\r\n      #ifndef _NO_CRYPTO\r\n      PasswordIsDefined(false),\r\n      AskPassword(false),\r\n      #endif\r\n      StdOutMode(false),\r\n      EnablePercents(true),\r\n      m_WarningsMode(false)\r\n      {}\r\n  \r\n  ~CUpdateCallbackConsole() { Finilize(); }\r\n  void Init(CStdOutStream *outStream)\r\n  {\r\n    m_NeedBeClosed = false;\r\n    m_NeedNewLine = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n    OutStream = outStream;\r\n    m_PercentPrinter.OutStream = outStream;\r\n  }\r\n\r\n  INTERFACE_IUpdateCallbackUI2(;)\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  UStringVector CantFindFiles;\r\n  CRecordVector<HRESULT> CantFindCodes;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp",
    "content": "// UserInputUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StdInStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"UserInputUtils.h\"\r\n\r\nstatic const char kYes = 'Y';\r\nstatic const char kNo = 'N';\r\nstatic const char kYesAll = 'A';\r\nstatic const char kNoAll = 'S';\r\nstatic const char kAutoRenameAll = 'U';\r\nstatic const char kQuit = 'Q';\r\n\r\nstatic const char *kFirstQuestionMessage = \"?\\n\";\r\nstatic const char *kHelpQuestionMessage =\r\n  \"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? \";\r\n\r\n// return true if pressed Quite;\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << kFirstQuestionMessage;\r\n  for(;;)\r\n  {\r\n    (*outStream) << kHelpQuestionMessage;\r\n    AString scannedString = g_StdIn.ScanStringUntilNewLine();\r\n    scannedString.Trim();\r\n    if(!scannedString.IsEmpty())\r\n      switch(::MyCharUpper(scannedString[0]))\r\n      {\r\n        case kYes:\r\n          return NUserAnswerMode::kYes;\r\n        case kNo:\r\n          return NUserAnswerMode::kNo;\r\n        case kYesAll:\r\n          return NUserAnswerMode::kYesAll;\r\n        case kNoAll:\r\n          return NUserAnswerMode::kNoAll;\r\n        case kAutoRenameAll:\r\n          return NUserAnswerMode::kAutoRenameAll;\r\n        case kQuit:\r\n          return NUserAnswerMode::kQuit;\r\n      }\r\n  }\r\n}\r\n\r\nUString GetPassword(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << \"\\nEnter password:\";\r\n  outStream->Flush();\r\n  AString oemPassword = g_StdIn.ScanStringUntilNewLine();\r\n  return MultiByteToUnicodeString(oemPassword, CP_OEMCP);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/UserInputUtils.h",
    "content": "// UserInputUtils.h\r\n\r\n#ifndef __USERINPUTUTILS_H\r\n#define __USERINPUTUTILS_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n\r\nnamespace NUserAnswerMode {\r\n\r\nenum EEnum\r\n{\r\n  kYes,\r\n  kNo,\r\n  kYesAll,\r\n  kNoAll,\r\n  kAutoRenameAll,\r\n  kQuit\r\n};\r\n}\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);\r\nUString GetPassword(CStdOutStream *outStream);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/7zip/UI/Console/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../  \\\r\n  -DCOMPRESS_MT \\\r\n  -DWIN_LONG_PATH \\\r\n  -DEXTERNAL_LZMA \\\r\n  -DEXTERNAL_CODECS \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n  -D_7ZIP_LARGE_PAGES \\\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Registry.obj \\\r\n  $O\\System.obj \\\r\n  $O\\Time.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\n!include \"../../Crc2.mak\"\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $O\\CopyCoder.obj \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\CopyCoder.obj: ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n!include \"../../Crc.mak\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Build.mak",
    "content": "!IFDEF CPU\r\n!IFNDEF NO_BUFFEROVERFLOWU\r\nLIBS = $(LIBS) bufferoverflowU.lib\r\n!ENDIF\r\n!ENDIF\r\n\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IF \"$(CPU)\" != \"IA64\"\r\n!IF \"$(CPU)\" != \"AMD64\"\r\nMY_ML = ml\r\n!ELSE\r\nMY_ML = ml64\r\n!ENDIF\r\n!ENDIF\r\n\r\nCOMPL_ASM = $(MY_ML) -c -Fo$O/ $**\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -WX -EHsc -Gr -Gy -GR-\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\n!IFDEF NEW_COMPILER\r\nCFLAGS = $(CFLAGS) -W4 -GS- -Zc:forScope\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -W3\r\n!ENDIF\r\n\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF -OPT:ICF\r\n\r\n!IFDEF DEF_FILE\r\nLFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)\r\n!ENDIF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL_PCH  = $(CPP) $(CFLAGS_O1) -Yc\"StdAfx.h\" -Fp$O/a.pch $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) -Yu\"StdAfx.h\" -Fp$O/a.pch $**\r\n\r\nall: $(PROGPATH)\r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch\r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS) $(DEF_FILE)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n$O\\resource.res: $(*B).rc\r\n\trc -fo$@ $**\r\n$O\\StdAfx.obj: $(*B).cpp\r\n\t$(COMPL_PCH)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/AutoPtr.h",
    "content": "// Common/AutoPtr.h\r\n\r\n#ifndef __COMMON_AUTOPTR_H\r\n#define __COMMON_AUTOPTR_H\r\n\r\ntemplate<class T> class CMyAutoPtr\r\n{\r\n  T *_p;\r\npublic:\r\n  CMyAutoPtr(T *p = 0) : _p(p) {}\r\n  CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {}\r\n  CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p)\r\n  {\r\n    reset(p.release());\r\n    return (*this);\r\n  }\r\n  ~CMyAutoPtr() { delete _p; }\r\n  T& operator*() const { return *_p; }\r\n  // T* operator->() const { return (&**this); }\r\n  T* get() const { return _p; }\r\n  T* release()\r\n  {\r\n    T *tmp = _p;\r\n    _p = 0;\r\n    return tmp;\r\n  }\r\n  void reset(T* p = 0)\r\n  {\r\n    if (p != _p)\r\n      delete _p;\r\n    _p = p;\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/Buffer.h",
    "content": "// Common/Buffer.h\r\n\r\n#ifndef __COMMON_BUFFER_H\r\n#define __COMMON_BUFFER_H\r\n\r\n#include \"Defs.h\"\r\n\r\ntemplate <class T> class CBuffer\r\n{\r\nprotected:\r\n  size_t _capacity;\r\n  T *_items;\r\npublic:\r\n  void Free()\r\n  {\r\n    delete []_items;\r\n    _items = 0;\r\n    _capacity = 0;\r\n  }\r\n  CBuffer(): _capacity(0), _items(0) {};\r\n  CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }\r\n  CBuffer(size_t size): _items(0),  _capacity(0) {  SetCapacity(size); }\r\n  virtual ~CBuffer() { delete []_items; }\r\n  operator T *() { return _items; };\r\n  operator const T *() const { return _items; };\r\n  size_t GetCapacity() const { return  _capacity; }\r\n  void SetCapacity(size_t newCapacity)\r\n  {\r\n    if (newCapacity == _capacity)\r\n      return;\r\n    T *newBuffer;\r\n    if (newCapacity > 0)\r\n    {\r\n      newBuffer = new T[newCapacity];\r\n      if (_capacity > 0)\r\n        memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));\r\n    }\r\n    else\r\n      newBuffer = 0;\r\n    delete []_items;\r\n    _items = newBuffer;\r\n    _capacity = newCapacity;\r\n  }\r\n  CBuffer& operator=(const CBuffer &buffer)\r\n  {\r\n    Free();\r\n    if (buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nbool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  if (b1.GetCapacity() != b2.GetCapacity())\r\n    return false;\r\n  for (size_t i = 0; i < b1.GetCapacity(); i++)\r\n    if (b1[i] != b2[i])\r\n      return false;\r\n  return true;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  return !(b1 == b2);\r\n}\r\n\r\ntypedef CBuffer<char> CCharBuffer;\r\ntypedef CBuffer<wchar_t> CWCharBuffer;\r\ntypedef CBuffer<unsigned char> CByteBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/7zCrc.h\"\r\n}\r\n\r\nstruct CCRCTableInit { CCRCTableInit() { CrcGenerateTable(); } } g_CRCTableInit;\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nbool CInFile::OpenShared(const char *name, bool)\r\n{\r\n  return Open(name);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nbool COutFile::Open(const char *name, DWORD creationDisposition)\r\n{\r\n  return Create(name, false);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  bool OpenShared(const char *name, bool shareForWrite);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  bool Open(const char *name, DWORD creationDisposition);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else\r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  for (;;)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      break;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{\r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */);\r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms,\r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0)\r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while (pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for (int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len)\r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if (temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if (_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString:\r\n      case NSwitchType::kUnLimitedPostString:\r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for (int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\r\n    const UString &commandString, UString &postString)\r\n{\r\n  for (int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if (commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"MyString.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  {\r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms);\r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms,\r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\r\n    const UString &commandString, UString &postString);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/DynamicBuffer.h",
    "content": "// Common/DynamicBuffer.h\r\n\r\n#ifndef __COMMON_DYNAMICBUFFER_H\r\n#define __COMMON_DYNAMICBUFFER_H\r\n\r\n#include \"Buffer.h\"\r\n\r\ntemplate <class T> class CDynamicBuffer: public CBuffer<T>\r\n{\r\n  void GrowLength(size_t size)\r\n  {\r\n    size_t delta;\r\n    if (this->_capacity > 64)\r\n      delta = this->_capacity / 4;\r\n    else if (this->_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    delta = MyMax(delta, size);\r\n    SetCapacity(this->_capacity + delta);\r\n  }\r\npublic:\r\n  CDynamicBuffer(): CBuffer<T>() {};\r\n  CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};\r\n  CDynamicBuffer(size_t size): CBuffer<T>(size) {};\r\n  CDynamicBuffer& operator=(const CDynamicBuffer &buffer)\r\n  {\r\n    this->Free();\r\n    if (buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n  void EnsureCapacity(size_t capacity)\r\n  {\r\n    if (this->_capacity < capacity)\r\n      GrowLength(capacity - this->_capacity);\r\n  }\r\n};\r\n\r\ntypedef CDynamicBuffer<char> CCharDynamicBuffer;\r\ntypedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;\r\ntypedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/IntToString.cpp",
    "content": "// Common/IntToString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"IntToString.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)\r\n{\r\n  if (base < 2 || base > 36)\r\n  {\r\n    *s = '\\0';\r\n    return;\r\n  }\r\n  char temp[72];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    int delta = (int)(value % base);\r\n    temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));\r\n    value /= base;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s)\r\n{\r\n  wchar_t temp[32];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = L'\\0';\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = '-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = L'-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/IntToString.h",
    "content": "// Common/IntToString.h\r\n\r\n#ifndef __COMMON_INTTOSTRING_H\r\n#define __COMMON_INTTOSTRING_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s);\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s);\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/ListFileUtils.cpp",
    "content": "// Common/ListFileUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MyWindows.h\"\r\n#include \"../Windows/FileIO.h\"\r\n\r\n#include \"ListFileUtils.h\"\r\n#include \"StringConvert.h\"\r\n#include \"UTFConvert.h\"\r\n\r\nstatic const char kQuoteChar     = '\\\"';\r\nstatic void RemoveQuote(UString &s)\r\n{\r\n  if (s.Length() >= 2)\r\n    if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)\r\n      s = s.Mid(1, s.Length() - 2);\r\n}\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)\r\n{\r\n  NWindows::NFile::NIO::CInFile file;\r\n  if (!file.Open(fileName))\r\n    return false;\r\n  UInt64 length;\r\n  if (!file.GetLength(length))\r\n    return false;\r\n  if (length > ((UInt32)1 << 31))\r\n    return false;\r\n  AString s;\r\n  char *p = s.GetBuffer((int)length + 1);\r\n  UInt32 processed;\r\n  if (!file.Read(p, (UInt32)length, processed))\r\n    return false;\r\n  p[(UInt32)length] = 0;\r\n  s.ReleaseBuffer();\r\n  file.Close();\r\n\r\n  UString u;\r\n  #ifdef CP_UTF8\r\n  if (codePage == CP_UTF8)\r\n  {\r\n    if (!ConvertUTF8ToUnicode(s, u))\r\n      return false;\r\n  }\r\n  else\r\n  #endif\r\n    u = MultiByteToUnicodeString(s, codePage);\r\n  if (!u.IsEmpty())\r\n  {\r\n    if (u[0] == 0xFEFF)\r\n      u.Delete(0);\r\n  }\r\n\r\n  UString t;\r\n  for (int i = 0; i < u.Length(); i++)\r\n  {\r\n    wchar_t c = u[i];\r\n    if (c == L'\\n' || c == 0xD)\r\n    {\r\n      t.Trim();\r\n      RemoveQuote(t);\r\n      if (!t.IsEmpty())\r\n        resultStrings.Add(t);\r\n      t.Empty();\r\n    }\r\n    else\r\n      t += c;\r\n  }\r\n  t.Trim();\r\n  RemoveQuote(t);\r\n  if (!t.IsEmpty())\r\n    resultStrings.Add(t);\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/ListFileUtils.h",
    "content": "// Common/ListFileUtils.h\r\n\r\n#ifndef __COMMON_LISTFILEUTILS_H\r\n#define __COMMON_LISTFILEUTILS_H\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRESULT __result_ = (x); if (__result_ != S_OK) return __result_; }\r\n#endif\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p)\r\n  {\r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p)\r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\ninline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr)\r\n{\r\n  *bstr = ::SysAllocString(src);\r\n  return (*bstr != 0) ? S_OK : E_OUTOFMEMORY;\r\n}\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR(): m_str(NULL) {}\r\n  CMyComBSTR(LPCOLESTR src) { m_str = ::SysAllocString(src); }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR src)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(src);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const\r\n  {\r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memcpy(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  /*\r\n  void Attach(BSTR src) { m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  */\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) {\r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \\\r\n    { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \\\r\n    MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n    MY_QUERYINTERFACE_ENTRY(i)\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyException.h",
    "content": "// Common/Exception.h\r\n\r\n#ifndef __COMMON_EXCEPTION_H\r\n#define __COMMON_EXCEPTION_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\nstruct CSystemException\r\n{\r\n  HRESULT ErrorCode;\r\n  CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline int operator==(REFGUID g1, REFGUID g2)\r\n{\r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return 0;\r\n  return 1;\r\n}\r\ninline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyString.cpp",
    "content": "// Common/MyString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <ctype.h>\r\n#endif\r\n\r\n#ifndef _UNICODE\r\n#include \"StringConvert.h\"\r\n#endif\r\n\r\n#include \"MyString.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1);\r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1),\r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{\r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1));\r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{\r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1));\r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1);\r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1),\r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n/*\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{\r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyString.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{\r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{\r\n  T *destStart = dest;\r\n  while ((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n// int MyStringCompareNoCase(const char *s1, const char  *s2);\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if (pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex,\r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n  int _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if (realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if (newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if (_capacity > 0)\r\n    {\r\n      for (int i = 0; i < _length; i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n    }\r\n    _chars = newBuffer;\r\n    _chars[_length] = 0;\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize)\r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0) { SetCapacity(3); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;}\r\n\r\n  // The minimum size of the character buffer in characters.\r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if (minBufLength >= _capacity)\r\n      SetCapacity(minBufLength);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if (newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if (&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int Compare(const T *s) const\r\n    { return MyStringCompare(_chars, s); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const T *s) const\r\n    { return MyStringCompareNoCase(_chars, s); }\r\n\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for (int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    charSet += (T)' ';\r\n    charSet += (T)'\\n';\r\n    charSet += (T)'\\t';\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if (pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for (int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0)\r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0)\r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct\r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else\r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyVector.cpp",
    "content": "// Common/MyVector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector() { ClearAndFree(); }\r\n\r\nvoid CBaseRecordVector::ClearAndFree()\r\n{\r\n  Clear();\r\n  delete []((unsigned char *)_items);\r\n  _capacity = 0;\r\n  _size = 0;\r\n  _items = 0;\r\n}\r\n\r\nvoid CBaseRecordVector::Clear() { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index) { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if (_size != _capacity)\r\n    return;\r\n  int delta = 1;\r\n  if (_capacity >= 64)\r\n    delta = _capacity / 4;\r\n  else if (_capacity >= 8)\r\n    delta = 8;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  // if (newCapacity <= _capacity)\r\n  if (newCapacity == _capacity)\r\n    return;\r\n  if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))\r\n    throw 1052353;\r\n  size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;\r\n  if (newSize / _itemSize != (size_t)(unsigned)newCapacity)\r\n    throw 1052354;\r\n  unsigned char *p = NULL;\r\n  if (newSize > 0)\r\n  {\r\n    p = new unsigned char[newSize];\r\n    if (p == 0)\r\n      throw 1052355;\r\n    int numRecordsToMove = (_size < newCapacity ? _size : newCapacity);\r\n    memcpy(p, _items, _itemSize * numRecordsToMove);\r\n  }\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::ReserveDown()\r\n{\r\n  Reserve(_size);\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize,\r\n    ((unsigned char  *)_items) + srcIndex * _itemSize,\r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyVector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n  int _capacity;\r\n  int _size;\r\n  void *_items;\r\n  size_t _itemSize;\r\n  \r\n  void ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; }\r\npublic:\r\n  CBaseRecordVector(size_t itemSize): _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n  virtual ~CBaseRecordVector();\r\n  void ClearAndFree();\r\n  int Size() const { return _size; }\r\n  bool IsEmpty() const { return (_size == 0); }\r\n  void Reserve(int newCapacity);\r\n  void ReserveDown();\r\n  virtual void Delete(int index, int num = 1);\r\n  void Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector(): CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v): CBaseRecordVector(sizeof(T)) { *this = v; }\r\n  CRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for (int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  int Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n  void Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n  T& operator[](int index) { return ((T *)_items)[index]; }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  T& Back() { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  int AddToUniqueSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    T temp = p[k];\r\n    for (;;)\r\n    {\r\n      int s = (k << 1);\r\n      if (s > size)\r\n        break;\r\n      if (s < size && compare(p + s + 1, p + s, param) > 0)\r\n        s++;\r\n      if (compare(&temp, p + s, param) >= 0)\r\n        break;\r\n      p[k] = p[s];\r\n      k = s;\r\n    }\r\n    p[k] = temp;\r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    int size = _size;\r\n    if (size <= 1)\r\n      return;\r\n    T* p = (&Front()) - 1;\r\n    {\r\n      int i = size / 2;\r\n      do\r\n        SortRefDown(p, i, size, compare, param);\r\n      while (--i != 0);\r\n    }\r\n    do\r\n    {\r\n      T temp = p[size];\r\n      p[size--] = p[1];\r\n      p[1] = temp;\r\n      SortRefDown(p, 1, size, compare, param);\r\n    }\r\n    while (size > 1);\r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector() {};\r\n  ~CObjectVector() { Clear(); };\r\n  CObjectVector(const CObjectVector &v) { *this = v; }\r\n  CObjectVector& operator=(const CObjectVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CObjectVector& operator+=(const CObjectVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for (int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n  T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Back() { return operator[](_size - 1); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  int Add(const T& item) { return CPointerVector::Add(new T(item)); }\r\n  void Insert(int index, const T& item) { CPointerVector::Insert(index, new T(item)); }\r\n  virtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for (int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for (int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param)\r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#define CHAR_PATH_SEPARATOR '\\\\'\r\n#define WCHAR_PATH_SEPARATOR L'\\\\'\r\n#define STRING_PATH_SEPARATOR \"\\\\\"\r\n#define WSTRING_PATH_SEPARATOR L\"\\\\\"\r\n\r\n#else\r\n\r\n#define CHAR_PATH_SEPARATOR '/'\r\n#define WCHAR_PATH_SEPARATOR L'/'\r\n#define STRING_PATH_SEPARATOR \"/\"\r\n#define WSTRING_PATH_SEPARATOR L\"/\"\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\n\r\n#undef BYTE\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\n\r\n#undef WORD\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\n\r\n#undef DWORD\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOTIMPL ((HRESULT)0x80004001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall\r\n#else\r\n#define STDMETHODCALLTYPE\r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct\r\n\r\n#ifdef __cplusplus\r\n\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n  #ifndef _WIN32\r\n  virtual ~IUnknown() {}\r\n  #endif\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#endif\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\r\n  VT_EMPTY = 0,\r\n  VT_NULL = 1,\r\n  VT_I2 = 2,\r\n  VT_I4 = 3,\r\n  VT_R4 = 4,\r\n  VT_R8 = 5,\r\n  VT_CY = 6,\r\n  VT_DATE = 7,\r\n  VT_BSTR = 8,\r\n  VT_DISPATCH = 9,\r\n  VT_ERROR = 10,\r\n  VT_BOOL = 11,\r\n  VT_VARIANT = 12,\r\n  VT_UNKNOWN = 13,\r\n  VT_DECIMAL = 14,\r\n  VT_I1 = 16,\r\n  VT_UI1 = 17,\r\n  VT_UI2 = 18,\r\n  VT_UI4 = 19,\r\n  VT_I8 = 20,\r\n  VT_UI8 = 21,\r\n  VT_INT = 22,\r\n  VT_UINT = 23,\r\n  VT_VOID = 24,\r\n  VT_HRESULT = 25,\r\n  VT_FILETIME = 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\n#ifdef __cplusplus\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union\r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\n\r\n#endif\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\r\n  STREAM_SEEK_SET = 0,\r\n  STREAM_SEEK_CUR = 1,\r\n  STREAM_SEEK_END = 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\n#ifdef _WIN32\r\nvoid *\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n#endif\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\n#ifdef _WIN32\r\nvoid\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator delete(void *p) throw();\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/StdInStream.cpp",
    "content": "// Common/StdInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n#include \"StdInStream.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kIllegalChar = '\\0';\r\nstatic const char kNewLineChar = '\\n';\r\n\r\nstatic const char *kEOFMessage = \"Unexpected end of input stream\";\r\nstatic const char *kReadErrorMessage  =\"Error reading input stream\";\r\nstatic const char *kIllegalCharMessage = \"Illegal character in input stream\";\r\n\r\nstatic LPCTSTR kFileOpenMode = TEXT(\"r\");\r\n\r\nCStdInStream g_StdIn(stdin);\r\n\r\nbool CStdInStream::Open(LPCTSTR fileName)\r\n{\r\n  Close();\r\n  _stream = _tfopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdInStream::Close()\r\n{\r\n  if (!_streamIsOpen)\r\n    return true;\r\n  _streamIsOpen = (fclose(_stream) != 0);\r\n  return !_streamIsOpen;\r\n}\r\n\r\nCStdInStream::~CStdInStream()\r\n{\r\n  Close();\r\n}\r\n\r\nAString CStdInStream::ScanStringUntilNewLine()\r\n{\r\n  AString s;\r\n  for (;;)\r\n  {\r\n    int intChar = GetChar();\r\n    if (intChar == EOF)\r\n      throw kEOFMessage;\r\n    char c = char(intChar);\r\n    if (c == kIllegalChar)\r\n      throw kIllegalCharMessage;\r\n    if (c == kNewLineChar)\r\n      break;\r\n    s += c;\r\n  }\r\n  return s;\r\n}\r\n\r\nvoid CStdInStream::ReadToString(AString &resultString)\r\n{\r\n  resultString.Empty();\r\n  int c;\r\n  while ((c = GetChar()) != EOF)\r\n    resultString += char(c);\r\n}\r\n\r\nbool CStdInStream::Eof()\r\n{\r\n  return (feof(_stream) != 0);\r\n}\r\n\r\nint CStdInStream::GetChar()\r\n{\r\n  int c = fgetc(_stream); // getc() doesn't work in BeOS?\r\n  if (c == EOF && !Eof())\r\n    throw kReadErrorMessage;\r\n  return c;\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/StdInStream.h",
    "content": "// Common/StdInStream.h\r\n\r\n#ifndef __COMMON_STDINSTREAM_H\r\n#define __COMMON_STDINSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nclass CStdInStream\r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdInStream(): _streamIsOpen(false) {};\r\n  CStdInStream(FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdInStream();\r\n  bool Open(LPCTSTR fileName);\r\n  bool Close();\r\n\r\n  AString ScanStringUntilNewLine();\r\n  void ReadToString(AString &resultString);\r\n\r\n  bool Eof();\r\n  int GetChar();\r\n};\r\n\r\nextern CStdInStream g_StdIn;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/StdOutStream.cpp",
    "content": "// Common/StdOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n\r\n#include \"StdOutStream.h\"\r\n#include \"IntToString.h\"\r\n#include \"StringConvert.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kNewLineChar =  '\\n';\r\n\r\nstatic const char *kFileOpenMode = \"wt\";\r\n\r\nCStdOutStream  g_StdOut(stdout);\r\nCStdOutStream  g_StdErr(stderr);\r\n\r\nbool CStdOutStream::Open(const char *fileName)\r\n{\r\n  Close();\r\n  _stream = fopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdOutStream::Close()\r\n{\r\n  if (!_streamIsOpen)\r\n    return true;\r\n  if (fclose(_stream) != 0)\r\n    return false;\r\n  _stream = 0;\r\n  _streamIsOpen = false;\r\n  return true;\r\n}\r\n\r\nbool CStdOutStream::Flush()\r\n{\r\n  return (fflush(_stream) == 0);\r\n}\r\n\r\nCStdOutStream::~CStdOutStream ()\r\n{\r\n  Close();\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream  &))\r\n{\r\n  (*aFunction)(*this);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream)\r\n{\r\n  return outStream << kNewLineChar;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const char *string)\r\n{\r\n  fputs(string, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const wchar_t *string)\r\n{\r\n  *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(char c)\r\n{\r\n  fputc(c, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(int number)\r\n{\r\n  char textString[32];\r\n  ConvertInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(UInt64 number)\r\n{\r\n  char textString[32];\r\n  ConvertUInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/StdOutStream.h",
    "content": "// Common/StdOutStream.h\r\n\r\n#ifndef __COMMON_STDOUTSTREAM_H\r\n#define __COMMON_STDOUTSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Types.h\"\r\n\r\nclass CStdOutStream\r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdOutStream (): _streamIsOpen(false), _stream(0) {};\r\n  CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdOutStream ();\r\n  operator FILE *() { return _stream; }\r\n  bool Open(const char *fileName);\r\n  bool Close();\r\n  bool Flush();\r\n  CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream  &));\r\n  CStdOutStream & operator<<(const char *string);\r\n  CStdOutStream & operator<<(const wchar_t *string);\r\n  CStdOutStream & operator<<(char c);\r\n  CStdOutStream & operator<<(int number);\r\n  CStdOutStream & operator<<(UInt64 number);\r\n};\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream);\r\n\r\nextern CStdOutStream g_StdOut;\r\nextern CStdOutStream g_StdErr;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString,\r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()),\r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if (numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed)\r\n{\r\n  AString dest;\r\n  defaultCharWasUsed = false;\r\n  if (!s.IsEmpty())\r\n  {\r\n    int numRequiredBytes = s.Length() * 2;\r\n    BOOL defUsed;\r\n    int numChars = WideCharToMultiByte(codePage, 0, s, s.Length(),\r\n        dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1,\r\n        &defaultChar, &defUsed);\r\n    defaultCharWasUsed = (defUsed != FALSE);\r\n    #ifndef _WIN32_WCE\r\n    if (numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    dest.ReleaseBuffer(numChars);\r\n  }\r\n  return dest;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  bool defaultCharWasUsed;\r\n  return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed);\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage, char defaultChar, bool &defaultCharWasUsed);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    UInt32 v;\r\n    if (c >= '0' && c <= '9') v = (c - '0');\r\n    else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A');\r\n    else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a');\r\n    else\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 4;\r\n    result |= v;\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Types.h\"\r\n}\r\n\r\ntypedef int HRes;\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/UTFConvert.cpp",
    "content": "// UTFConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UTFConvert.h\"\r\n#include \"Types.h\"\r\n\r\nstatic const Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nstatic Bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, size_t srcLen)\r\n{\r\n  size_t destPos = 0, srcPos = 0;\r\n  for (;;)\r\n  {\r\n    Byte c;\r\n    int numAdds;\r\n    if (srcPos == srcLen)\r\n    {\r\n      *destLen = destPos;\r\n      return True;\r\n    }\r\n    c = (Byte)src[srcPos++];\r\n\r\n    if (c < 0x80)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (wchar_t)c;\r\n      destPos++;\r\n      continue;\r\n    }\r\n    if (c < 0xC0)\r\n      break;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (c < kUtf8Limits[numAdds])\r\n        break;\r\n    UInt32 value = (c - kUtf8Limits[numAdds - 1]);\r\n\r\n    do\r\n    {\r\n      Byte c2;\r\n      if (srcPos == srcLen)\r\n        break;\r\n      c2 = (Byte)src[srcPos++];\r\n      if (c2 < 0x80 || c2 >= 0xC0)\r\n        break;\r\n      value <<= 6;\r\n      value |= (c2 - 0x80);\r\n    }\r\n    while (--numAdds != 0);\r\n    \r\n    if (value < 0x10000)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (wchar_t)value;\r\n      destPos++;\r\n    }\r\n    else\r\n    {\r\n      value -= 0x10000;\r\n      if (value >= 0x100000)\r\n        break;\r\n      if (dest)\r\n      {\r\n        dest[destPos + 0] = (wchar_t)(0xD800 + (value >> 10));\r\n        dest[destPos + 1] = (wchar_t)(0xDC00 + (value & 0x3FF));\r\n      }\r\n      destPos += 2;\r\n    }\r\n  }\r\n  *destLen = destPos;\r\n  return False;\r\n}\r\n\r\nstatic Bool Utf16_To_Utf8(char *dest, size_t *destLen, const wchar_t *src, size_t srcLen)\r\n{\r\n  size_t destPos = 0, srcPos = 0;\r\n  for (;;)\r\n  {\r\n    unsigned numAdds;\r\n    UInt32 value;\r\n    if (srcPos == srcLen)\r\n    {\r\n      *destLen = destPos;\r\n      return True;\r\n    }\r\n    value = src[srcPos++];\r\n    if (value < 0x80)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (char)value;\r\n      destPos++;\r\n      continue;\r\n    }\r\n    if (value >= 0xD800 && value < 0xE000)\r\n    {\r\n      UInt32 c2;\r\n      if (value >= 0xDC00 || srcPos == srcLen)\r\n        break;\r\n      c2 = src[srcPos++];\r\n      if (c2 < 0xDC00 || c2 >= 0xE000)\r\n        break;\r\n      value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n    }\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n        break;\r\n    if (dest)\r\n      dest[destPos] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n    destPos++;\r\n    do\r\n    {\r\n      numAdds--;\r\n      if (dest)\r\n        dest[destPos] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      destPos++;\r\n    }\r\n    while (numAdds != 0);\r\n  }\r\n  *destLen = destPos;\r\n  return False;\r\n}\r\n\r\nbool ConvertUTF8ToUnicode(const AString &src, UString &dest)\r\n{\r\n  dest.Empty();\r\n  size_t destLen = 0;\r\n  Utf8_To_Utf16(NULL, &destLen, src, src.Length());\r\n  wchar_t *p = dest.GetBuffer((int)destLen);\r\n  Bool res = Utf8_To_Utf16(p, &destLen, src, src.Length());\r\n  p[destLen] = 0;\r\n  dest.ReleaseBuffer();\r\n  return res ? true : false;\r\n}\r\n\r\nbool ConvertUnicodeToUTF8(const UString &src, AString &dest)\r\n{\r\n  dest.Empty();\r\n  size_t destLen = 0;\r\n  Utf16_To_Utf8(NULL, &destLen, src, src.Length());\r\n  char *p = dest.GetBuffer((int)destLen);\r\n  Bool res = Utf16_To_Utf8(p, &destLen, src, src.Length());\r\n  p[destLen] = 0;\r\n  dest.ReleaseBuffer();\r\n  return res ? true : false;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/UTFConvert.h",
    "content": "// Common/UTFConvert.h\r\n\r\n#ifndef __COMMON_UTFCONVERT_H\r\n#define __COMMON_UTFCONVERT_H\r\n\r\n#include \"MyString.h\"\r\n\r\nbool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);\r\nbool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/Wildcard.cpp",
    "content": "// Common/Wildcard.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Wildcard.h\"\r\n\r\nbool g_CaseSensitive =\r\n  #ifdef _WIN32\r\n    false;\r\n  #else\r\n    true;\r\n  #endif\r\n\r\nstatic const wchar_t kAnyCharsChar = L'*';\r\nstatic const wchar_t kAnyCharChar = L'?';\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t kDirDelimiter1 = L'\\\\';\r\n#endif\r\nstatic const wchar_t kDirDelimiter2 = L'/';\r\n\r\nstatic const UString kWildCardCharSet = L\"?*\";\r\n\r\nstatic const UString kIllegalWildCardFileNameChars=\r\n  L\"\\x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\xA\\xB\\xC\\xD\\xE\\xF\"\r\n  L\"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F\"\r\n  L\"\\\"/:<>\\\\|\";\r\n\r\n\r\nstatic inline bool IsCharDirLimiter(wchar_t c)\r\n{\r\n  return (\r\n    #ifdef _WIN32\r\n    c == kDirDelimiter1 ||\r\n    #endif\r\n    c == kDirDelimiter2);\r\n}\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2)\r\n{\r\n  if (g_CaseSensitive)\r\n    return s1.Compare(s2);\r\n  return s1.CompareNoCase(s2);\r\n}\r\n\r\n// -----------------------------------------\r\n// this function compares name with mask\r\n// ? - any char\r\n// * - any char or empty\r\n\r\nstatic bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t m = *mask;\r\n    wchar_t c = *name;\r\n    if (m == 0)\r\n      return (c == 0);\r\n    if (m == kAnyCharsChar)\r\n    {\r\n      if (EnhancedMaskTest(mask + 1, name))\r\n        return true;\r\n      if (c == 0)\r\n        return false;\r\n    }\r\n    else\r\n    {\r\n      if (m == kAnyCharChar)\r\n      {\r\n        if (c == 0)\r\n          return false;\r\n      }\r\n      else if (m != c)\r\n        if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))\r\n          return false;\r\n      mask++;\r\n    }\r\n    name++;\r\n  }\r\n}\r\n\r\n// --------------------------------------------------\r\n// Splits path to strings\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts)\r\n{\r\n  pathParts.Clear();\r\n  UString name;\r\n  int len = path.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = path[i];\r\n    if (IsCharDirLimiter(c))\r\n    {\r\n      pathParts.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  pathParts.Add(name);\r\n}\r\n\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  dirPrefix = path.Left(i + 1);\r\n  name = path.Mid(i + 1);\r\n}\r\n\r\nUString ExtractDirPrefixFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Left(i + 1);\r\n}\r\n\r\nUString ExtractFileNameFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Mid(i + 1);\r\n}\r\n\r\n\r\nbool CompareWildCardWithName(const UString &mask, const UString &name)\r\n{\r\n  return EnhancedMaskTest(mask, name);\r\n}\r\n\r\nbool DoesNameContainWildCard(const UString &path)\r\n{\r\n  return (path.FindOneOf(kWildCardCharSet) >= 0);\r\n}\r\n\r\n\r\n// ----------------------------------------------------------'\r\n// NWildcard\r\n\r\nnamespace NWildcard {\r\n\r\n\r\n/*\r\nM = MaskParts.Size();\r\nN = TestNameParts.Size();\r\n\r\n                           File                          Dir\r\nForFile     req   M<=N  [N-M, N)                          -\r\n         nonreq   M=N   [0, M)                            -\r\n \r\nForDir      req   M<N   [0, M) ... [N-M-1, N-1)  same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\nForBoth     req   m<=N  [0, M) ... [N-M, N)      same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\n*/\r\n\r\nbool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (!isFile && !ForDir)\r\n    return false;\r\n  int delta = (int)pathParts.Size() - (int)PathParts.Size();\r\n  if (delta < 0)\r\n    return false;\r\n  int start = 0;\r\n  int finish = 0;\r\n  if (isFile)\r\n  {\r\n    if (!ForDir && !Recursive && delta !=0)\r\n      return false;\r\n    if (!ForFile && delta == 0)\r\n      return false;\r\n    if (!ForDir && Recursive)\r\n      start = delta;\r\n  }\r\n  if (Recursive)\r\n  {\r\n    finish = delta;\r\n    if (isFile && !ForFile)\r\n      finish = delta - 1;\r\n  }\r\n  for (int d = start; d <= finish; d++)\r\n  {\r\n    int i;\r\n    for (i = 0; i < PathParts.Size(); i++)\r\n      if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))\r\n        break;\r\n    if (i == PathParts.Size())\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nint CCensorNode::FindSubNode(const UString &name) const\r\n{\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (CompareFileNames(SubNodes[i].Name, name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensorNode::AddItemSimple(bool include, CItem &item)\r\n{\r\n  if (include)\r\n    IncludeItems.Add(item);\r\n  else\r\n    ExcludeItems.Add(item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, CItem &item)\r\n{\r\n  if (item.PathParts.Size() <= 1)\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  const UString &front = item.PathParts.Front();\r\n  if (DoesNameContainWildCard(front))\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  int index = FindSubNode(front);\r\n  if (index < 0)\r\n    index = SubNodes.Add(CCensorNode(front, this));\r\n  item.PathParts.Delete(0);\r\n  SubNodes[index].AddItem(include, item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)\r\n{\r\n  CItem item;\r\n  SplitPathToParts(path, item.PathParts);\r\n  item.Recursive = recursive;\r\n  item.ForFile = forFile;\r\n  item.ForDir = forDir;\r\n  AddItem(include, item);\r\n}\r\n\r\nbool CCensorNode::NeedCheckSubDirs() const\r\n{\r\n  for (int i = 0; i < IncludeItems.Size(); i++)\r\n  {\r\n    const CItem &item = IncludeItems[i];\r\n    if (item.Recursive || item.PathParts.Size() > 1)\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::AreThereIncludeItems() const\r\n{\r\n  if (IncludeItems.Size() > 0)\r\n    return true;\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (SubNodes[i].AreThereIncludeItems())\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const\r\n{\r\n  const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;\r\n  for (int i = 0; i < items.Size(); i++)\r\n    if (items[i].CheckPath(pathParts, isFile))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const\r\n{\r\n  if (CheckPathCurrent(false, pathParts, isFile))\r\n  {\r\n    include = false;\r\n    return true;\r\n  }\r\n  include = true;\r\n  bool finded = CheckPathCurrent(true, pathParts, isFile);\r\n  if (pathParts.Size() == 1)\r\n    return finded;\r\n  int index = FindSubNode(pathParts.Front());\r\n  if (index >= 0)\r\n  {\r\n    UStringVector pathParts2 = pathParts;\r\n    pathParts2.Delete(0);\r\n    if (SubNodes[index].CheckPath(pathParts2, isFile, include))\r\n      return true;\r\n  }\r\n  return finded;\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPath(pathParts, isFile, include);\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool include;\r\n  if (CheckPath(path, isFile, include))\r\n    return include;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (CheckPathCurrent(include, pathParts, isFile))\r\n    return true;\r\n  if (Parent == 0)\r\n    return false;\r\n  pathParts.Insert(0, Name);\r\n  return Parent->CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n\r\n/*\r\nbool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n*/\r\n\r\nvoid CCensorNode::AddItem2(bool include, const UString &path, bool recursive)\r\n{\r\n  if (path.IsEmpty())\r\n    return;\r\n  bool forFile = true;\r\n  bool forFolder = true;\r\n  UString path2 = path;\r\n  if (IsCharDirLimiter(path[path.Length() - 1]))\r\n  {\r\n    path2.Delete(path.Length() - 1);\r\n    forFile = false;\r\n  }\r\n  AddItem(include, path2, recursive, forFile, forFolder);\r\n}\r\n\r\nvoid CCensorNode::ExtendExclude(const CCensorNode &fromNodes)\r\n{\r\n  ExcludeItems += fromNodes.ExcludeItems;\r\n  for (int i = 0; i < fromNodes.SubNodes.Size(); i++)\r\n  {\r\n    const CCensorNode &node = fromNodes.SubNodes[i];\r\n    int subNodeIndex = FindSubNode(node.Name);\r\n    if (subNodeIndex < 0)\r\n      subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));\r\n    SubNodes[subNodeIndex].ExtendExclude(node);\r\n  }\r\n}\r\n\r\nint CCensor::FindPrefix(const UString &prefix) const\r\n{\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n    if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensor::AddItem(bool include, const UString &path, bool recursive)\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  bool forFile = true;\r\n  if (pathParts.Back().IsEmpty())\r\n  {\r\n    forFile = false;\r\n    pathParts.DeleteBack();\r\n  }\r\n  const UString &front = pathParts.Front();\r\n  bool isAbs = false;\r\n  if (front.IsEmpty())\r\n    isAbs = true;\r\n  else if (front.Length() == 2 && front[1] == L':')\r\n    isAbs = true;\r\n  else\r\n  {\r\n    for (int i = 0; i < pathParts.Size(); i++)\r\n    {\r\n      const UString &part = pathParts[i];\r\n      if (part == L\"..\" || part == L\".\")\r\n      {\r\n        isAbs = true;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  int numAbsParts = 0;\r\n  if (isAbs)\r\n    if (pathParts.Size() > 1)\r\n      numAbsParts = pathParts.Size() - 1;\r\n    else\r\n      numAbsParts = 1;\r\n  UString prefix;\r\n  for (int i = 0; i < numAbsParts; i++)\r\n  {\r\n    const UString &front = pathParts.Front();\r\n    if (DoesNameContainWildCard(front))\r\n      break;\r\n    prefix += front;\r\n    prefix += WCHAR_PATH_SEPARATOR;\r\n    pathParts.Delete(0);\r\n  }\r\n  int index = FindPrefix(prefix);\r\n  if (index < 0)\r\n    index = Pairs.Add(CPair(prefix));\r\n\r\n  CItem item;\r\n  item.PathParts = pathParts;\r\n  item.ForDir = true;\r\n  item.ForFile = forFile;\r\n  item.Recursive = recursive;\r\n  Pairs[index].Head.AddItem(include, item);\r\n}\r\n\r\nbool CCensor::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool finded = false;\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n  {\r\n    bool include;\r\n    if (Pairs[i].Head.CheckPath(path, isFile, include))\r\n    {\r\n      if (!include)\r\n        return false;\r\n      finded = true;\r\n    }\r\n  }\r\n  return finded;\r\n}\r\n\r\nvoid CCensor::ExtendExclude()\r\n{\r\n  int i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (Pairs[i].Prefix.IsEmpty())\r\n      break;\r\n  if (i == Pairs.Size())\r\n    return;\r\n  int index = i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (index != i)\r\n      Pairs[i].Head.ExtendExclude(Pairs[index].Head);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Common/Wildcard.h",
    "content": "// Common/Wildcard.h\r\n\r\n#ifndef __COMMON_WILDCARD_H\r\n#define __COMMON_WILDCARD_H\r\n\r\n#include \"MyString.h\"\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2);\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts);\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);\r\nUString ExtractDirPrefixFromPath(const UString &path);\r\nUString ExtractFileNameFromPath(const UString &path);\r\nbool DoesNameContainWildCard(const UString &path);\r\nbool CompareWildCardWithName(const UString &mask, const UString &name);\r\n\r\nnamespace NWildcard {\r\n\r\nstruct CItem\r\n{\r\n  UStringVector PathParts;\r\n  bool Recursive;\r\n  bool ForFile;\r\n  bool ForDir;\r\n  bool CheckPath(const UStringVector &pathParts, bool isFile) const;\r\n};\r\n\r\nclass CCensorNode\r\n{\r\n  CCensorNode *Parent;\r\n  bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;\r\n  void AddItemSimple(bool include, CItem &item);\r\n  bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;\r\npublic:\r\n  CCensorNode(): Parent(0) { };\r\n  CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };\r\n  UString Name;\r\n  CObjectVector<CCensorNode> SubNodes;\r\n  CObjectVector<CItem> IncludeItems;\r\n  CObjectVector<CItem> ExcludeItems;\r\n\r\n  int FindSubNode(const UString &path) const;\r\n\r\n  void AddItem(bool include, CItem &item);\r\n  void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);\r\n  void AddItem2(bool include, const UString &path, bool recursive);\r\n\r\n  bool NeedCheckSubDirs() const;\r\n  bool AreThereIncludeItems() const;\r\n\r\n  bool CheckPath(const UString &path, bool isFile, bool &include) const;\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n\r\n  bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;\r\n  // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;\r\n  void ExtendExclude(const CCensorNode &fromNodes);\r\n};\r\n\r\nstruct CPair\r\n{\r\n  UString Prefix;\r\n  CCensorNode Head;\r\n  CPair(const UString &prefix): Prefix(prefix) { };\r\n};\r\n\r\nclass CCensor\r\n{\r\n  int FindPrefix(const UString &prefix) const;\r\npublic:\r\n  CObjectVector<CPair> Pairs;\r\n  bool AllAreRelative() const\r\n    { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }\r\n  void AddItem(bool include, const UString &path, bool recursive);\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n  void ExtendExclude();\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/DLL.cpp",
    "content": "// Windows/DLL.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DLL.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nCLibrary::~CLibrary()\r\n{\r\n  Free();\r\n}\r\n\r\nbool CLibrary::Free()\r\n{\r\n  if (_module == 0)\r\n    return true;\r\n  // MessageBox(0, TEXT(\"\"), TEXT(\"Free\"), 0);\r\n  // Sleep(5000);\r\n  if (!::FreeLibrary(_module))\r\n    return false;\r\n  _module = 0;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadOperations(HMODULE newModule)\r\n{\r\n  if (newModule == NULL)\r\n    return false;\r\n  if (!Free())\r\n    return false;\r\n  _module = newModule;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"LoadEx\"), 0);\r\n  return LoadOperations(::LoadLibraryEx(fileName, NULL, flags));\r\n}\r\n\r\nbool CLibrary::Load(LPCTSTR fileName)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"Load\"), 0);\r\n  // Sleep(5000);\r\n  // OutputDebugString(fileName);\r\n  // OutputDebugString(TEXT(\"\\n\"));\r\n  return LoadOperations(::LoadLibrary(fileName));\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\nCSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n\r\nbool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));\r\n  return LoadEx(GetSysPath(fileName), flags);\r\n}\r\nbool CLibrary::Load(LPCWSTR fileName)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryW(fileName));\r\n  return Load(GetSysPath(fileName));\r\n}\r\n#endif\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result)\r\n{\r\n  result.Empty();\r\n  TCHAR fullPath[MAX_PATH + 2];\r\n  DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1);\r\n  if (size <= MAX_PATH && size != 0)\r\n  {\r\n    result = fullPath;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result)\r\n{\r\n  result.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    wchar_t fullPath[MAX_PATH + 2];\r\n    DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);\r\n    if (size <= MAX_PATH && size != 0)\r\n    {\r\n      result = fullPath;\r\n      return true;\r\n    }\r\n    return false;\r\n  }\r\n  CSysString resultSys;\r\n  if (!MyGetModuleFileName(hModule, resultSys))\r\n    return false;\r\n  result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());\r\n  return true;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/DLL.h",
    "content": "// Windows/DLL.h\r\n\r\n#ifndef __WINDOWS_DLL_H\r\n#define __WINDOWS_DLL_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nclass CLibrary\r\n{\r\n  bool LoadOperations(HMODULE newModule);\r\nprotected:\r\n  HMODULE _module;\r\npublic:\r\n  operator HMODULE() const { return _module; }\r\n  HMODULE* operator&() { return &_module; }\r\n\r\n  CLibrary():_module(NULL) {};\r\n  ~CLibrary();\r\n  void Attach(HMODULE m)\r\n  {\r\n    Free();\r\n    _module = m;\r\n  }\r\n  HMODULE Detach()\r\n  {\r\n    HMODULE m = _module;\r\n    _module = NULL;\r\n    return m;\r\n  }\r\n\r\n  // operator HMODULE() const { return _module; };\r\n  bool IsLoaded() const { return (_module != NULL); };\r\n  bool Free();\r\n  bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCWSTR fileName);\r\n  #endif\r\n  FARPROC GetProcAddress(LPCSTR procName) const\r\n    { return ::GetProcAddress(_module, procName); }\r\n};\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result);\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result);\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\n#ifdef _WIN32\r\ninline bool LRESULTToBool(LRESULT value)\r\n  { return (value != FALSE); }\r\n#endif\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/Error.cpp",
    "content": "// Windows/Error.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifndef _UNICODE\r\n#include \"Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message)\r\n{\r\n  LPVOID msgBuf;\r\n  if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r\n      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n      NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)\r\n    return false;\r\n  message = (LPCTSTR)msgBuf;\r\n  ::LocalFree(msgBuf);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyFormatMessage(DWORD messageID, UString &message)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPVOID msgBuf;\r\n    if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r\n        FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n        NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)\r\n      return false;\r\n    message = (LPCWSTR)msgBuf;\r\n    ::LocalFree(msgBuf);\r\n    return true;\r\n  }\r\n  CSysString messageSys;\r\n  bool result = MyFormatMessage(messageID, messageSys);\r\n  message = GetUnicodeString(messageSys);\r\n  return result;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/Error.h",
    "content": "// Windows/Error.h\r\n\r\n#ifndef __WINDOWS_ERROR_H\r\n#define __WINDOWS_ERROR_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message);\r\ninline CSysString MyFormatMessage(DWORD messageID)\r\n{\r\n  CSysString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#ifdef _UNICODE\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n  { return MyFormatMessage(messageID); }\r\n#else\r\nbool MyFormatMessage(DWORD messageID, UString &message);\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n{\r\n  UString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileDir.cpp",
    "content": "// Windows/FileDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileDir.h\"\r\n#include \"FileName.h\"\r\n#include \"FileFind.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n// SetCurrentDirectory doesn't support \\\\?\\ prefix\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR fileName, UString &res);\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n#endif\r\n\r\nnamespace NDirectory {\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\nstatic UString GetUnicodePath(const CSysString &sysPath)\r\n  { return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }\r\nstatic CSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\nbool MyGetSystemDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetWindowsDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n\r\nbool MyGetSystemDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetSystemDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n{\r\n  #ifndef _UNICODE\r\n  if (!g_IsNT)\r\n  {\r\n    ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\r\n    return false;\r\n  }\r\n  #endif\r\n  HANDLE hDir = ::CreateFileW(fileName, GENERIC_WRITE,\r\n      FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n      NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (hDir == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      hDir = ::CreateFileW(longPath, GENERIC_WRITE,\r\n        FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  }\r\n  #endif\r\n\r\n  bool res = false;\r\n  if (hDir != INVALID_HANDLE_VALUE)\r\n  {\r\n    res = BOOLToBool(::SetFileTime(hDir, cTime, aTime, mTime));\r\n    ::CloseHandle(hDir);\r\n  }\r\n  return res;\r\n}\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (::SetFileAttributes(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyRemoveDirectory(LPCTSTR pathName)\r\n{\r\n  if (::RemoveDirectory(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2)\r\n{\r\n  if (!GetLongPathBase(s1, d1) || !GetLongPathBase(s2, d2))\r\n    return false;\r\n  if (d1.IsEmpty() && d2.IsEmpty()) return false;\r\n  if (d1.IsEmpty()) d1 = s1;\r\n  if (d2.IsEmpty()) d2 = s2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName)\r\n{\r\n  if (::MoveFile(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return MySetFileAttributes(GetSysPath(fileName), fileAttributes);\r\n  if (::SetFileAttributesW(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n\r\nbool MyRemoveDirectory(LPCWSTR pathName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyRemoveDirectory(GetSysPath(pathName));\r\n  if (::RemoveDirectoryW(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));\r\n  if (::MoveFileW(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nbool MyCreateDirectory(LPCTSTR pathName)\r\n{\r\n  if (::CreateDirectory(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyCreateDirectory(LPCWSTR pathName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyCreateDirectory(GetSysPath(pathName));\r\n  if (::CreateDirectoryW(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\n/*\r\nbool CreateComplexDirectory(LPCTSTR pathName)\r\n{\r\n  NName::CParsedPath path;\r\n  path.ParsePath(pathName);\r\n  CSysString fullPath = path.Prefix;\r\n  DWORD errorCode = ERROR_SUCCESS;\r\n  for (int i = 0; i < path.PathParts.Size(); i++)\r\n  {\r\n    const CSysString &string = path.PathParts[i];\r\n    if (string.IsEmpty())\r\n    {\r\n      if (i != path.PathParts.Size() - 1)\r\n        return false;\r\n      return true;\r\n    }\r\n    fullPath += path.PathParts[i];\r\n    if (!MyCreateDirectory(fullPath))\r\n    {\r\n      DWORD errorCode = GetLastError();\r\n      if (errorCode != ERROR_ALREADY_EXISTS)\r\n        return false;\r\n    }\r\n    fullPath += NName::kDirDelimiter;\r\n  }\r\n  return true;\r\n}\r\n*/\r\n\r\nbool CreateComplexDirectory(LPCTSTR _aPathName)\r\n{\r\n  CSysString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == ':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  CSysString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if (MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfo fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDir())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == ':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while (pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateComplexDirectory(LPCWSTR _aPathName)\r\n{\r\n  UString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == L':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  UString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if (MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfoW fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDir())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == L':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while (pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\nbool DeleteFileAlways(LPCTSTR name)\r\n{\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFile(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DeleteFileAlways(LPCWSTR name)\r\n{\r\n  if (!g_IsNT)\r\n    return DeleteFileAlways(GetSysPath(name));\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFileW(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nstatic bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)\r\n{\r\n  if (fileInfo.IsDir())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\n\r\nbool RemoveDirectoryWithSubItems(const CSysString &path)\r\n{\r\n  NFind::CFileInfo fileInfo;\r\n  CSysString pathPrefix = path + NName::kDirDelimiter;\r\n  {\r\n    NFind::CEnumerator enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));\r\n    while (enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)\r\n{\r\n  if (fileInfo.IsDir())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\nbool RemoveDirectoryWithSubItems(const UString &path)\r\n{\r\n  NFind::CFileInfoW fileInfo;\r\n  UString pathPrefix = path + UString(NName::kDirDelimiter);\r\n  {\r\n    NFind::CEnumeratorW enumerator(pathPrefix + UString(NName::kAnyStringWildcard));\r\n    while (enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\n\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)\r\n{\r\n  DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  shortPath.ReleaseBuffer();\r\n  return (needLength > 0 && needLength < MAX_PATH);\r\n}\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  LPTSTR fileNamePointer = 0;\r\n  LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n  DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n  resultPath.ReleaseBuffer();\r\n  if (needLength == 0)\r\n    return false;\r\n  if (needLength >= MAX_PATH)\r\n  {\r\n    #ifdef WIN_LONG_PATH2\r\n    needLength++;\r\n    buffer = resultPath.GetBuffer(needLength + 1);\r\n    DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength2 == 0 || needLength2 > needLength)\r\n    #endif\r\n      return false;\r\n  }\r\n  if (fileNamePointer == 0)\r\n    fileNamePartStartIndex = lstrlen(fileName);\r\n  else\r\n    fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR fileNamePointer = 0;\r\n    LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n    DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength == 0)\r\n      return false;\r\n    if (needLength >= MAX_PATH)\r\n    {\r\n      #ifdef WIN_LONG_PATH\r\n      needLength++;\r\n      buffer = resultPath.GetBuffer(needLength + 1);\r\n      DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n      resultPath.ReleaseBuffer();\r\n      if (needLength2 == 0 || needLength2 > needLength)\r\n      #endif\r\n        return false;\r\n    }\r\n    if (fileNamePointer == 0)\r\n      fileNamePartStartIndex = MyStringLen(fileName);\r\n    else\r\n      fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  }\r\n  else\r\n  {\r\n    CSysString sysPath;\r\n    if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))\r\n      return false;\r\n    UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));\r\n    UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));\r\n    fileNamePartStartIndex = resultPath1.Length();\r\n    resultPath = resultPath1 + resultPath2;\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n#endif\r\n\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetCurrentDirectory(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path)\r\n{\r\n  if (g_IsNT)\r\n    return BOOLToBool(::SetCurrentDirectoryW(path));\r\n  return MySetCurrentDirectory(GetSysPath(path));\r\n}\r\nbool MyGetCurrentDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetCurrentDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath, UINT32 &filePart)\r\n{\r\n  LPTSTR filePartPointer;\r\n  DWORD value = ::SearchPath(path, fileName, extension,\r\n    MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n  filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);\r\n  resultPath.ReleaseBuffer();\r\n  return (value > 0 && value <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath, UINT32 &filePart)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR filePartPointer = 0;\r\n    DWORD value = ::SearchPathW(path, fileName, extension,\r\n        MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n    filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);\r\n    resultPath.ReleaseBuffer();\r\n    return (value > 0 && value <= MAX_PATH);\r\n  }\r\n  \r\n  CSysString sysPath;\r\n  if (!MySearchPath(\r\n      path != 0 ? (LPCTSTR)GetSysPath(path): 0,\r\n      fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,\r\n      extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,\r\n      sysPath, filePart))\r\n    return false;\r\n  UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));\r\n  UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));\r\n  filePart = resultPath1.Length();\r\n  resultPath = resultPath1 + resultPath2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &path)\r\n{\r\n  path.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetTempPath(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)\r\n{\r\n  UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return number;\r\n}\r\n\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));\r\n    path.ReleaseBuffer();\r\n    return number;\r\n  }\r\n  CSysString sysPath;\r\n  UINT number = MyGetTempFileName(\r\n      dirPath ? (LPCTSTR)GetSysPath(dirPath): 0,\r\n      prefix ? (LPCTSTR)GetSysPath(prefix): 0,\r\n      sysPath);\r\n  path = GetUnicodePath(sysPath);\r\n  return number;\r\n}\r\n#endif\r\n\r\nUINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if (number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  CSysString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFile::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nUINT CTempFileW::Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if (number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFileW::Create(LPCWSTR prefix, UString &resultPath)\r\n{\r\n  UString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFileW::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFile tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!::DeleteFile(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if (NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectory::Create(LPCTSTR prefix)\r\n{\r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateTempDirectory(LPCWSTR prefix, UString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFileW tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!DeleteFileAlways(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if (NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectoryW::Create(LPCWSTR prefix)\r\n{\r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileDir.h",
    "content": "// Windows/FileDir.h\r\n\r\n#ifndef __WINDOWS_FILEDIR_H\r\n#define __WINDOWS_FILEDIR_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NDirectory {\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path);\r\nbool MyGetSystemDirectory(CSysString &path);\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path);\r\nbool MyGetSystemDirectory(UString &path);\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);\r\nbool MyRemoveDirectory(LPCTSTR pathName);\r\nbool MyCreateDirectory(LPCTSTR pathName);\r\nbool CreateComplexDirectory(LPCTSTR pathName);\r\nbool DeleteFileAlways(LPCTSTR name);\r\nbool RemoveDirectoryWithSubItems(const CSysString &path);\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);\r\nbool MyRemoveDirectory(LPCWSTR pathName);\r\nbool MyCreateDirectory(LPCWSTR pathName);\r\nbool CreateComplexDirectory(LPCWSTR pathName);\r\nbool DeleteFileAlways(LPCWSTR name);\r\nbool RemoveDirectoryWithSubItems(const UString &path);\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,\r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName);\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,\r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName);\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);\r\n#endif\r\n\r\ninline bool MySetCurrentDirectory(LPCTSTR path)\r\n  { return BOOLToBool(::SetCurrentDirectory(path)); }\r\nbool MyGetCurrentDirectory(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path);\r\nbool MyGetCurrentDirectory(UString &resultPath);\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath, UINT32 &filePart);\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath, UINT32 &filePart);\r\n#endif\r\n\r\ninline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n\r\n#ifndef _UNICODE\r\ninline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &resultPath);\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n#endif\r\n\r\nclass CTempFile\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _fileName;\r\npublic:\r\n  CTempFile(): _mustBeDeleted(false) {}\r\n  ~CTempFile() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n  bool Create(LPCTSTR prefix, CSysString &resultPath);\r\n  bool Remove();\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempFile CTempFileW;\r\n#else\r\nclass CTempFileW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _fileName;\r\npublic:\r\n  CTempFileW(): _mustBeDeleted(false) {}\r\n  ~CTempFileW() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n  bool Create(LPCWSTR prefix, UString &resultPath);\r\n  bool Remove();\r\n};\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);\r\n\r\nclass CTempDirectory\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _tempDir;\r\npublic:\r\n  const CSysString &GetPath() const { return _tempDir; }\r\n  CTempDirectory(): _mustBeDeleted(false) {}\r\n  ~CTempDirectory() { Remove();  }\r\n  bool Create(LPCTSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempDirectory CTempDirectoryW;\r\n#else\r\nclass CTempDirectoryW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _tempDir;\r\npublic:\r\n  const UString &GetPath() const { return _tempDir; }\r\n  CTempDirectoryW(): _mustBeDeleted(false) {}\r\n  ~CTempDirectoryW() { Remove();  }\r\n  bool Create(LPCWSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileFind.cpp",
    "content": "// Windows/FileFind.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileFind.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n\r\nnamespace NFind {\r\n\r\nstatic const TCHAR kDot = TEXT('.');\r\n\r\nbool CFileInfo::IsDots() const\r\n{\r\n  if (!IsDir() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileInfoW::IsDots() const\r\n{\r\n  if (!IsDir() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n#endif\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = fd.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfoW &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = fd.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage());\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n#endif\r\n  \r\n////////////////////////////////\r\n// CFindFile\r\n\r\nbool CFindFile::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::FindClose(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\n          \r\nbool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  WIN32_FIND_DATA fd;\r\n  _handle = ::FindFirstFile(wildcard, &fd);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(wildcard, longPath))\r\n      _handle = ::FindFirstFileW(longPath, &fd);\r\n  }\r\n  #endif\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return false;\r\n  ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW fd;\r\n    _handle = ::FindFirstFileW(wildcard, &fd);\r\n    #ifdef WIN_LONG_PATH\r\n    if (_handle == INVALID_HANDLE_VALUE)\r\n    {\r\n      UString longPath;\r\n      if (GetLongPath(wildcard, longPath))\r\n        _handle = ::FindFirstFileW(longPath, &fd);\r\n    }\r\n    #endif\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA fd;\r\n    _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard,\r\n        GetCurrentCodePage()), &fd);\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFindFile::FindNext(CFileInfo &fileInfo)\r\n{\r\n  WIN32_FIND_DATA fd;\r\n  bool result = BOOLToBool(::FindNextFile(_handle, &fd));\r\n  if (result)\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  return result;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindNext(CFileInfoW &fileInfo)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW fd;\r\n    if (!::FindNextFileW(_handle, &fd))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA fd;\r\n    if (!::FindNextFileA(_handle, &fd))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n#endif\r\n\r\nbool DoesFileExist(LPCTSTR name)\r\n{\r\n  CFileInfo fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DoesFileExist(LPCWSTR name)\r\n{\r\n  CFileInfoW fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n#endif\r\n\r\n/////////////////////////////////////\r\n// CEnumerator\r\n\r\nbool CEnumerator::NextAny(CFileInfo &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CEnumeratorW::NextAny(CFileInfoW &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#endif\r\n\r\n////////////////////////////////\r\n// CFindChangeNotification\r\n// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.\r\n\r\nbool CFindChangeNotification::Close()\r\n{\r\n  if (!IsHandleAllocated())\r\n    return true;\r\n  if (!::FindCloseChangeNotification(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n           \r\nHANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  _handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n\r\n#ifndef _UNICODE\r\nHANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  if (!g_IsNT)\r\n    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);\r\n  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  UINT32 size = GetLogicalDriveStrings(0, NULL);\r\n  if (size == 0)\r\n    return false;\r\n  CSysString buffer;\r\n  UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size));\r\n  if (newSize == 0)\r\n    return false;\r\n  if (newSize > size)\r\n    return false;\r\n  CSysString string;\r\n  for (UINT32 i = 0; i < newSize; i++)\r\n  {\r\n    TCHAR c = buffer[i];\r\n    if (c == TEXT('\\0'))\r\n    {\r\n      driveStrings.Add(string);\r\n      string.Empty();\r\n    }\r\n    else\r\n      string += c;\r\n  }\r\n  if (!string.IsEmpty())\r\n    return false;\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  if (g_IsNT)\r\n  {\r\n    UINT32 size = GetLogicalDriveStringsW(0, NULL);\r\n    if (size == 0)\r\n      return false;\r\n    UString buffer;\r\n    UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size));\r\n    if (newSize == 0)\r\n      return false;\r\n    if (newSize > size)\r\n      return false;\r\n    UString string;\r\n    for (UINT32 i = 0; i < newSize; i++)\r\n    {\r\n      WCHAR c = buffer[i];\r\n      if (c == L'\\0')\r\n      {\r\n        driveStrings.Add(string);\r\n        string.Empty();\r\n      }\r\n      else\r\n        string += c;\r\n    }\r\n    return string.IsEmpty();\r\n  }\r\n  CSysStringVector driveStringsA;\r\n  bool res = MyGetLogicalDriveStrings(driveStringsA);\r\n  for (int i = 0; i < driveStringsA.Size(); i++)\r\n    driveStrings.Add(GetUnicodeString(driveStringsA[i]));\r\n  return res;\r\n}\r\n#endif\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileFind.h",
    "content": "// Windows/FileFind.h\r\n\r\n#ifndef __WINDOWS_FILEFIND_H\r\n#define __WINDOWS_FILEFIND_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"../Common/Types.h\"\r\n#include \"FileName.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NFind {\r\n\r\nnamespace NAttributes\r\n{\r\n  inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }\r\n  inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; }\r\n  inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; }\r\n  inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; }\r\n  inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }\r\n  inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }\r\n  inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }\r\n}\r\n\r\nclass CFileInfoBase\r\n{\r\n  bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }\r\npublic:\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  DWORD Attrib;\r\n  \r\n  #ifndef _WIN32_WCE\r\n  UINT32 ReparseTag;\r\n  #else\r\n  DWORD ObjectID;\r\n  #endif\r\n\r\n  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }\r\n  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }\r\n  bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }\r\n  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }\r\n  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }\r\n  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }\r\n  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }\r\n  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }\r\n  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }\r\n  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }\r\n  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }\r\n  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }\r\n};\r\n\r\nclass CFileInfo: public CFileInfoBase\r\n{\r\npublic:\r\n  CSysString Name;\r\n  bool IsDots() const;\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CFileInfo CFileInfoW;\r\n#else\r\nclass CFileInfoW: public CFileInfoBase\r\n{\r\npublic:\r\n  UString Name;\r\n  bool IsDots() const;\r\n};\r\n#endif\r\n\r\nclass CFindFile\r\n{\r\n  friend class CEnumerator;\r\n  HANDLE _handle;\r\npublic:\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }\r\n  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindFile() {  Close(); }\r\n  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n  bool FindNext(CFileInfo &fileInfo);\r\n  #ifndef _UNICODE\r\n  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\n  bool FindNext(CFileInfoW &fileInfo);\r\n  #endif\r\n  bool Close();\r\n};\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n\r\nbool DoesFileExist(LPCTSTR name);\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\nbool DoesFileExist(LPCWSTR name);\r\n#endif\r\n\r\nclass CEnumerator\r\n{\r\n  CFindFile _findFile;\r\n  CSysString _wildcard;\r\n  bool NextAny(CFileInfo &fileInfo);\r\npublic:\r\n  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfo &fileInfo);\r\n  bool Next(CFileInfo &fileInfo, bool &found);\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CEnumerator CEnumeratorW;\r\n#else\r\nclass CEnumeratorW\r\n{\r\n  CFindFile _findFile;\r\n  UString _wildcard;\r\n  bool NextAny(CFileInfoW &fileInfo);\r\npublic:\r\n  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfoW &fileInfo);\r\n  bool Next(CFileInfoW &fileInfo, bool &found);\r\n};\r\n#endif\r\n\r\nclass CFindChangeNotification\r\n{\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE () { return _handle; }\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }\r\n  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindChangeNotification() { Close(); }\r\n  bool Close();\r\n  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #ifndef _UNICODE\r\n  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #endif\r\n  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings);\r\n#endif\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifdef WIN_LONG_PATH\r\n#include \"../Common/MyString.h\"\r\n#endif\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR s, UString &res)\r\n{\r\n  res.Empty();\r\n  int len = MyStringLen(s);\r\n  wchar_t c = s[0];\r\n  if (len < 1 || c == L'\\\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))\r\n    return true;\r\n  UString curDir;\r\n  bool isAbs = false;\r\n  if (len > 3)\r\n    isAbs = (s[1] == L':' && s[2] == L'\\\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));\r\n\r\n  if (!isAbs)\r\n    {\r\n      DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));\r\n      curDir.ReleaseBuffer();\r\n      if (needLength == 0 || needLength > MAX_PATH)\r\n        return false;\r\n      if (curDir[curDir.Length() - 1] != L'\\\\')\r\n        curDir += L'\\\\';\r\n    }\r\n  res = UString(L\"\\\\\\\\?\\\\\") + curDir + s;\r\n  return true;\r\n}\r\n\r\nbool GetLongPath(LPCWSTR path, UString &longPath)\r\n{\r\n  if (GetLongPathBase(path, longPath))\r\n    return !longPath.IsEmpty();\r\n  return false;\r\n}\r\n#endif\r\n\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode,\r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n      flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP),\r\n      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFileW(fileName, desiredAccess, shareMode,\r\n    (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n    flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::CloseHandle(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if (sizeLow == 0xFFFFFFFF)\r\n    if (::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if (::GetLastError() != NO_ERROR)\r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if (!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CTime = winFileInfo.ftCreationTime;\r\n  fileInfo.ATime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.MTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes;\r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\n// Probably in some version of Windows there are problems with other sizes:\r\n// for 32 MB (maybe also for 16 MB).\r\n// And message can be \"Network connection was lost\"\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 22);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, cTime, aTime, mTime)); }\r\n\r\nbool COutFile::SetMTime(const FILETIME *mTime) {  return SetTime(NULL, NULL, mTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if (!Seek(length, newPosition))\r\n    return false;\r\n  if (newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{\r\n  DWORD    Attributes;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  DWORD    VolumeSerialNumber;\r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks;\r\n  UInt64   FileIndex;\r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _handle(INVALID_HANDLE_VALUE){};\r\n  ~CFileBase();\r\n\r\n  bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition);\r\n  bool SeekToBegin();\r\n  bool SeekToEnd(UInt64 &newPosition);\r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\r\n  bool SetMTime(const FILETIME *mTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileMapping.cpp",
    "content": "// Windows/FileMapping.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileMapping.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NMapping {\r\n\r\n\r\n\r\n\r\n}}}"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileMapping.h",
    "content": "// Windows/FileMapping.h\r\n\r\n#ifndef __WINDOWS_FILEMAPPING_H\r\n#define __WINDOWS_FILEMAPPING_H\r\n\r\n#include \"Windows/Handle.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\n// namespace NFile {\r\n// namespace NMapping {\r\n\r\nclass CFileMapping: public CHandle\r\n{\r\npublic:\r\n  bool Create(HANDLE file, LPSECURITY_ATTRIBUTES attributes,\r\n    DWORD protect, UINT64 maximumSize, LPCTSTR name)\r\n  {\r\n    _handle = ::CreateFileMapping(file, attributes,\r\n      protect, DWORD(maximumSize >> 32), DWORD(maximumSize), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenFileMapping(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  LPVOID MapViewOfFile(DWORD desiredAccess, UINT64 fileOffset,\r\n      SIZE_T numberOfBytesToMap)\r\n  {\r\n    return ::MapViewOfFile(_handle, desiredAccess,\r\n        DWORD(fileOffset >> 32), DWORD(fileOffset), numberOfBytesToMap);\r\n  }\r\n\r\n  LPVOID MapViewOfFileEx(DWORD desiredAccess, UINT64 fileOffset,\r\n      SIZE_T numberOfBytesToMap, LPVOID baseAddress)\r\n  {\r\n    return ::MapViewOfFileEx(_handle, desiredAccess,\r\n      DWORD(fileOffset >> 32), DWORD(fileOffset),\r\n      numberOfBytesToMap, baseAddress);\r\n  }\r\n  \r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileName.cpp",
    "content": "// Windows/FileName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)\r\n    dirPath += kDirDelimiter;\r\n}\r\n\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)\r\n    dirPath += wchar_t(kDirDelimiter);\r\n}\r\n#endif\r\n\r\nconst wchar_t kExtensionDelimiter = L'.';\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\r\n    UString &pureName, UString &extensionDelimiter, UString &extension)\r\n{\r\n  int index = fullName.ReverseFind(kExtensionDelimiter);\r\n  if (index < 0)\r\n  {\r\n    pureName = fullName;\r\n    extensionDelimiter.Empty();\r\n    extension.Empty();\r\n  }\r\n  else\r\n  {\r\n    pureName = fullName.Left(index);\r\n    extensionDelimiter = kExtensionDelimiter;\r\n    extension = fullName.Mid(index + 1);\r\n  }\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/FileName.h",
    "content": "// Windows/FileName.h\r\n\r\n#ifndef __WINDOWS_FILENAME_H\r\n#define __WINDOWS_FILENAME_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nconst TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;\r\nconst TCHAR kAnyStringWildcard = '*';\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\\\'\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\\\'\r\n#endif\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\r\n    UString &pureName, UString &extensionDelimiter, UString &extension);\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/Handle.h",
    "content": "// Windows/Handle.h\r\n\r\n#ifndef __WINDOWS_HANDLE_H\r\n#define __WINDOWS_HANDLE_H\r\n\r\nnamespace NWindows {\r\n\r\nclass CHandle\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE() { return _handle; }\r\n  CHandle(): _handle(NULL) {}\r\n  ~CHandle() { Close(); }\r\n  bool Close()\r\n  {\r\n    if (_handle == NULL)\r\n      return true;\r\n    if (!::CloseHandle(_handle))\r\n      return false;\r\n    _handle = NULL;\r\n    return true;\r\n  }\r\n  void Attach(HANDLE handle)\r\n    { _handle = handle; }\r\n  HANDLE Detach()\r\n  {\r\n    HANDLE handle = _handle;\r\n    _handle = NULL;\r\n    return handle;\r\n  }\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/MemoryLock.cpp",
    "content": "// Common/MemoryLock.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\n#ifndef _UNICODE\r\ntypedef BOOL (WINAPI * OpenProcessTokenP)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);\r\ntypedef BOOL (WINAPI * LookupPrivilegeValueP)(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID  lpLuid);\r\ntypedef BOOL (WINAPI * AdjustTokenPrivilegesP)(HANDLE TokenHandle, BOOL DisableAllPrivileges,\r\n    PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength);\r\n#endif\r\n\r\n#ifdef _UNICODE\r\nbool EnableLockMemoryPrivilege(\r\n#else\r\nstatic bool EnableLockMemoryPrivilege2(HMODULE hModule,\r\n#endif\r\nbool enable)\r\n{\r\n  #ifndef _UNICODE\r\n  if (hModule == NULL)\r\n    return false;\r\n  OpenProcessTokenP openProcessToken = (OpenProcessTokenP)GetProcAddress(hModule, \"OpenProcessToken\");\r\n  LookupPrivilegeValueP lookupPrivilegeValue = (LookupPrivilegeValueP)GetProcAddress(hModule, \"LookupPrivilegeValueA\" );\r\n  AdjustTokenPrivilegesP adjustTokenPrivileges = (AdjustTokenPrivilegesP)GetProcAddress(hModule, \"AdjustTokenPrivileges\");\r\n  if (openProcessToken == NULL || adjustTokenPrivileges == NULL || lookupPrivilegeValue == NULL)\r\n    return false;\r\n  #endif\r\n\r\n  HANDLE token;\r\n  if (!\r\n    #ifdef _UNICODE\r\n    ::OpenProcessToken\r\n    #else\r\n    openProcessToken\r\n    #endif\r\n    (::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))\r\n    return false;\r\n  TOKEN_PRIVILEGES tp;\r\n  bool res = false;\r\n  if (\r\n    #ifdef _UNICODE\r\n    ::LookupPrivilegeValue\r\n    #else\r\n    lookupPrivilegeValue\r\n    #endif\r\n    (NULL, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)))\r\n  {\r\n    tp.PrivilegeCount = 1;\r\n    tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED: 0;\r\n    if (\r\n      #ifdef _UNICODE\r\n      ::AdjustTokenPrivileges\r\n      #else\r\n      adjustTokenPrivileges\r\n      #endif\r\n      (token, FALSE, &tp, 0, NULL, NULL))\r\n      res = (GetLastError() == ERROR_SUCCESS);\r\n  }\r\n  ::CloseHandle(token);\r\n  return res;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool EnableLockMemoryPrivilege(bool enable)\r\n{\r\n  HMODULE hModule = LoadLibrary(TEXT(\"Advapi32.dll\"));\r\n  if (hModule == NULL)\r\n    return false;\r\n  bool res = EnableLockMemoryPrivilege2(hModule, enable);\r\n  ::FreeLibrary(hModule);\r\n  return res;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/MemoryLock.h",
    "content": "// Windows/MemoryLock.h\r\n\r\n#ifndef __WINDOWS_MEMORYLOCK_H\r\n#define __WINDOWS_MEMORYLOCK_H\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\nbool EnableLockMemoryPrivilege(bool enable = true);\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/PropVariant.cpp",
    "content": "// Windows/PropVariant.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariant.h\"\r\n\r\n#include \"../Common/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nCPropVariant::CPropVariant(const PROPVARIANT& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(const CPropVariant& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(BSTR bstrSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = bstrSrc;\r\n}\r\n\r\nCPropVariant::CPropVariant(LPCOLESTR lpszSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = lpszSrc;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const CPropVariant& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\nCPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(BSTR bstrSrc)\r\n{\r\n  *this = (LPCOLESTR)bstrSrc;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)\r\n{\r\n  InternalClear();\r\n  vt = VT_BSTR;\r\n  wReserved1 = 0;\r\n  bstrVal = ::SysAllocString(lpszSrc);\r\n  if (bstrVal == NULL && lpszSrc != NULL)\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = E_OUTOFMEMORY;\r\n  }\r\n  return *this;\r\n}\r\n\r\n\r\nCPropVariant& CPropVariant::operator=(bool bSrc)\r\n{\r\n  if (vt != VT_BOOL)\r\n  {\r\n    InternalClear();\r\n    vt = VT_BOOL;\r\n  }\r\n  boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt32 value)\r\n{\r\n  if (vt != VT_UI4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI4;\r\n  }\r\n  ulVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt64 value)\r\n{\r\n  if (vt != VT_UI8)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI8;\r\n  }\r\n  uhVal.QuadPart = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const FILETIME &value)\r\n{\r\n  if (vt != VT_FILETIME)\r\n  {\r\n    InternalClear();\r\n    vt = VT_FILETIME;\r\n  }\r\n  filetime = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int32 value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  \r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Byte value)\r\n{\r\n  if (vt != VT_UI1)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI1;\r\n  }\r\n  bVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int16 value)\r\n{\r\n  if (vt != VT_I2)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I2;\r\n  }\r\n  iVal = value;\r\n  return *this;\r\n}\r\n\r\n/*\r\nCPropVariant& CPropVariant::operator=(LONG value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  return *this;\r\n}\r\n*/\r\n\r\nstatic HRESULT MyPropVariantClear(PROPVARIANT *propVariant)\r\n{\r\n  switch(propVariant->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      propVariant->vt = VT_EMPTY;\r\n      propVariant->wReserved1 = 0;\r\n      return S_OK;\r\n  }\r\n  return ::VariantClear((VARIANTARG *)propVariant);\r\n}\r\n\r\nHRESULT CPropVariant::Clear()\r\n{\r\n  return MyPropVariantClear(this);\r\n}\r\n\r\nHRESULT CPropVariant::Copy(const PROPVARIANT* pSrc)\r\n{\r\n  ::VariantClear((tagVARIANT *)this);\r\n  switch(pSrc->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));\r\n      return S_OK;\r\n  }\r\n  return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc));\r\n}\r\n\r\n\r\nHRESULT CPropVariant::Attach(PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(this, pSrc, sizeof(PROPVARIANT));\r\n  pSrc->vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::Detach(PROPVARIANT* pDest)\r\n{\r\n  HRESULT hr = MyPropVariantClear(pDest);\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(pDest, this, sizeof(PROPVARIANT));\r\n  vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::InternalClear()\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n  return hr;\r\n}\r\n\r\nvoid CPropVariant::InternalCopy(const PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Copy(pSrc);\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n}\r\n\r\nint CPropVariant::Compare(const CPropVariant &a)\r\n{\r\n  if (vt != a.vt)\r\n    return 0; // it's mean some bug\r\n  switch (vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return 0;\r\n    \r\n    /*\r\n    case VT_I1:\r\n      return MyCompare(cVal, a.cVal);\r\n    */\r\n    case VT_UI1:\r\n      return MyCompare(bVal, a.bVal);\r\n\r\n    case VT_I2:\r\n      return MyCompare(iVal, a.iVal);\r\n    case VT_UI2:\r\n      return MyCompare(uiVal, a.uiVal);\r\n    \r\n    case VT_I4:\r\n      return MyCompare(lVal, a.lVal);\r\n    /*\r\n    case VT_INT:\r\n      return MyCompare(intVal, a.intVal);\r\n    */\r\n    case VT_UI4:\r\n      return MyCompare(ulVal, a.ulVal);\r\n    /*\r\n    case VT_UINT:\r\n      return MyCompare(uintVal, a.uintVal);\r\n    */\r\n    case VT_I8:\r\n      return MyCompare(hVal.QuadPart, a.hVal.QuadPart);\r\n    case VT_UI8:\r\n      return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);\r\n\r\n    case VT_BOOL:\r\n      return -MyCompare(boolVal, a.boolVal);\r\n\r\n    case VT_FILETIME:\r\n      return ::CompareFileTime(&filetime, &a.filetime);\r\n    case VT_BSTR:\r\n      return 0; // Not implemented\r\n      // return MyCompare(aPropVarint.cVal);\r\n\r\n    default:\r\n      return 0;\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/PropVariant.h",
    "content": "// Windows/PropVariant.h\r\n\r\n#ifndef __WINDOWS_PROPVARIANT_H\r\n#define __WINDOWS_PROPVARIANT_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nclass CPropVariant : public tagPROPVARIANT\r\n{\r\npublic:\r\n  CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }\r\n  ~CPropVariant() { Clear(); }\r\n  CPropVariant(const PROPVARIANT& varSrc);\r\n  CPropVariant(const CPropVariant& varSrc);\r\n  CPropVariant(BSTR bstrSrc);\r\n  CPropVariant(LPCOLESTR lpszSrc);\r\n  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };\r\n  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }\r\n  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal = *(ULARGE_INTEGER*)&value; }\r\n  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }\r\n  CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }\r\n  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }\r\n  CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }\r\n  // CPropVariant(LONG value, VARTYPE vtSrc = VT_I4) { vt = vtSrc; lVal = value; }\r\n\r\n  CPropVariant& operator=(const CPropVariant& varSrc);\r\n  CPropVariant& operator=(const PROPVARIANT& varSrc);\r\n  CPropVariant& operator=(BSTR bstrSrc);\r\n  CPropVariant& operator=(LPCOLESTR lpszSrc);\r\n  CPropVariant& operator=(bool bSrc);\r\n  CPropVariant& operator=(UInt32 value);\r\n  CPropVariant& operator=(UInt64 value);\r\n  CPropVariant& operator=(const FILETIME &value);\r\n\r\n  CPropVariant& operator=(Int32 value);\r\n  CPropVariant& operator=(Byte value);\r\n  CPropVariant& operator=(Int16 value);\r\n  // CPropVariant& operator=(LONG  value);\r\n\r\n  HRESULT Clear();\r\n  HRESULT Copy(const PROPVARIANT* pSrc);\r\n  HRESULT Attach(PROPVARIANT* pSrc);\r\n  HRESULT Detach(PROPVARIANT* pDest);\r\n\r\n  HRESULT InternalClear();\r\n  void InternalCopy(const PROPVARIANT* pSrc);\r\n\r\n  int Compare(const CPropVariant &a1);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/PropVariantConversions.cpp",
    "content": "// PropVariantConversions.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariantConversions.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\nstatic UString ConvertUInt64ToString(UInt64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString ConvertInt64ToString(Int64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic char *UIntToStringSpec(char c, UInt32 value, char *s, int numPos)\r\n{\r\n  if (c != 0)\r\n    *s++ = c;\r\n  char temp[16];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (char)('0' + value % 10);\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  int i;\r\n  for (i = 0; i < numPos - pos; i++)\r\n    *s++ = '0';\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n  return s;\r\n}\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)\r\n{\r\n  s[0] = '\\0';\r\n  SYSTEMTIME st;\r\n  if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))\r\n    return false;\r\n  s = UIntToStringSpec(0, st.wYear, s, 4);\r\n  s = UIntToStringSpec('-', st.wMonth, s, 2);\r\n  s = UIntToStringSpec('-', st.wDay, s, 2);\r\n  if (includeTime)\r\n  {\r\n    s = UIntToStringSpec(' ', st.wHour, s, 2);\r\n    s = UIntToStringSpec(':', st.wMinute, s, 2);\r\n    if (includeSeconds)\r\n      UIntToStringSpec(':', st.wSecond, s, 2);\r\n  }\r\n  return true;\r\n}\r\n\r\nUString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds)\r\n{\r\n  char s[32];\r\n  ConvertFileTimeToString(fileTime, s,  includeTime, includeSeconds);\r\n  return GetUnicodeString(s);\r\n}\r\n \r\n\r\nUString ConvertPropVariantToString(const PROPVARIANT &prop)\r\n{\r\n  switch (prop.vt)\r\n  {\r\n    case VT_EMPTY: return UString();\r\n    case VT_BSTR: return prop.bstrVal;\r\n    case VT_UI1: return ConvertUInt64ToString(prop.bVal);\r\n    case VT_UI2: return ConvertUInt64ToString(prop.uiVal);\r\n    case VT_UI4: return ConvertUInt64ToString(prop.ulVal);\r\n    case VT_UI8: return ConvertUInt64ToString(prop.uhVal.QuadPart);\r\n    case VT_FILETIME: return ConvertFileTimeToString(prop.filetime, true, true);\r\n    // case VT_I1: return ConvertInt64ToString(prop.cVal);\r\n    case VT_I2: return ConvertInt64ToString(prop.iVal);\r\n    case VT_I4: return ConvertInt64ToString(prop.lVal);\r\n    case VT_I8: return ConvertInt64ToString(prop.hVal.QuadPart);\r\n    case VT_BOOL: return VARIANT_BOOLToBool(prop.boolVal) ? L\"+\" : L\"-\";\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 150245;\r\n      #else\r\n      return UString();\r\n      #endif\r\n  }\r\n}\r\n\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &prop)\r\n{\r\n  switch (prop.vt)\r\n  {\r\n    case VT_UI1: return prop.bVal;\r\n    case VT_UI2: return prop.uiVal;\r\n    case VT_UI4: return prop.ulVal;\r\n    case VT_UI8: return (UInt64)prop.uhVal.QuadPart;\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 151199;\r\n      #else\r\n      return 0;\r\n      #endif\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/PropVariantConversions.h",
    "content": "// Windows/PropVariantConversions.h\r\n\r\n#ifndef __PROPVARIANTCONVERSIONS_H\r\n#define __PROPVARIANTCONVERSIONS_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/MyString.h\"\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant);\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/Synchronization.cpp",
    "content": "// Windows/Synchronization.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Synchronization.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/Synchronization.h",
    "content": "// Windows/Synchronization.h\r\n\r\n#ifndef __WINDOWS_SYNCHRONIZATION_H\r\n#define __WINDOWS_SYNCHRONIZATION_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\n#ifdef _WIN32\r\n#include \"Handle.h\"\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\nclass CBaseEvent\r\n{\r\nprotected:\r\n  ::CEvent _object;\r\npublic:\r\n  bool IsCreated() { return Event_IsCreated(&_object) != 0; }\r\n  operator HANDLE() { return _object.handle; }\r\n  CBaseEvent() { Event_Construct(&_object); }\r\n  ~CBaseEvent() { Close(); }\r\n  WRes Close() { return Event_Close(&_object); }\r\n  #ifdef _WIN32\r\n  WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),\r\n        BoolToBOOL(initiallyOwn), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  #endif\r\n\r\n  WRes Set() { return Event_Set(&_object); }\r\n  // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }\r\n  WRes Reset() { return Event_Reset(&_object); }\r\n  WRes Lock() { return Event_Wait(&_object); }\r\n};\r\n\r\nclass CManualResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  WRes Create(bool initiallyOwn = false)\r\n  {\r\n    return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);\r\n  }\r\n  WRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return ManualResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  #ifdef _WIN32\r\n  WRes CreateWithName(bool initiallyOwn, LPCTSTR name)\r\n  {\r\n    return CBaseEvent::Create(true, initiallyOwn, name);\r\n  }\r\n  #endif\r\n};\r\n\r\nclass CAutoResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  WRes Create()\r\n  {\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  WRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\nclass CObject: public CHandle\r\n{\r\npublic:\r\n  WRes Lock(DWORD timeoutInterval = INFINITE)\r\n    { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }\r\n};\r\nclass CMutex: public CObject\r\n{\r\npublic:\r\n  WRes Create(bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Release()\r\n  {\r\n    return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();\r\n  }\r\n};\r\nclass CMutexLock\r\n{\r\n  CMutex *_object;\r\npublic:\r\n  CMutexLock(CMutex &object): _object(&object) { _object->Lock(); }\r\n  ~CMutexLock() { _object->Release(); }\r\n};\r\n#endif\r\n\r\nclass CSemaphore\r\n{\r\n  ::CSemaphore _object;\r\npublic:\r\n  CSemaphore() { Semaphore_Construct(&_object); }\r\n  ~CSemaphore() { Close(); }\r\n  WRes Close() {  return Semaphore_Close(&_object); }\r\n  operator HANDLE() { return _object.handle; }\r\n  WRes Create(UInt32 initiallyCount, UInt32 maxCount)\r\n  {\r\n    return Semaphore_Create(&_object, initiallyCount, maxCount);\r\n  }\r\n  WRes Release() { return Semaphore_Release1(&_object); }\r\n  WRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }\r\n  WRes Lock() { return Semaphore_Wait(&_object); }\r\n};\r\n\r\nclass CCriticalSection\r\n{\r\n  ::CCriticalSection _object;\r\npublic:\r\n  CCriticalSection() { CriticalSection_Init(&_object); }\r\n  ~CCriticalSection() { CriticalSection_Delete(&_object); }\r\n  void Enter() { CriticalSection_Enter(&_object); }\r\n  void Leave() { CriticalSection_Leave(&_object); }\r\n};\r\n\r\nclass CCriticalSectionLock\r\n{\r\n  CCriticalSection *_object;\r\n  void Unlock()  { _object->Leave(); }\r\npublic:\r\n  CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); }\r\n  ~CCriticalSectionLock() { Unlock(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/System.cpp",
    "content": "// Windows/System.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"System.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors()\r\n{\r\n  SYSTEM_INFO systemInfo;\r\n  GetSystemInfo(&systemInfo);\r\n  return (UInt32)systemInfo.dwNumberOfProcessors;\r\n}\r\n\r\n#if !defined(_WIN64) && defined(__GNUC__)\r\n\r\ntypedef struct _MY_MEMORYSTATUSEX {\r\n  DWORD dwLength;\r\n  DWORD dwMemoryLoad;\r\n  DWORDLONG ullTotalPhys;\r\n  DWORDLONG ullAvailPhys;\r\n  DWORDLONG ullTotalPageFile;\r\n  DWORDLONG ullAvailPageFile;\r\n  DWORDLONG ullTotalVirtual;\r\n  DWORDLONG ullAvailVirtual;\r\n  DWORDLONG ullAvailExtendedVirtual;\r\n} MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX;\r\n\r\n#else\r\n\r\n#define MY_MEMORYSTATUSEX MEMORYSTATUSEX\r\n#define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX\r\n\r\n#endif\r\n\r\ntypedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);\r\n\r\nUInt64 GetRamSize()\r\n{\r\n  MY_MEMORYSTATUSEX stat;\r\n  stat.dwLength = sizeof(stat);\r\n  #ifdef _WIN64\r\n  if (!::GlobalMemoryStatusEx(&stat))\r\n    return 0;\r\n  return stat.ullTotalPhys;\r\n  #else\r\n  GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")),\r\n        \"GlobalMemoryStatusEx\");\r\n  if (globalMemoryStatusEx != 0)\r\n    if (globalMemoryStatusEx(&stat))\r\n      return stat.ullTotalPhys;\r\n  {\r\n    MEMORYSTATUS stat;\r\n    stat.dwLength = sizeof(stat);\r\n    GlobalMemoryStatus(&stat);\r\n    return stat.dwTotalPhys;\r\n  }\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/System.h",
    "content": "// Windows/System.h\r\n\r\n#ifndef __WINDOWS_SYSTEM_H\r\n#define __WINDOWS_SYSTEM_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors();\r\nUInt64 GetRamSize();\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/Thread.h",
    "content": "// Windows/Thread.h\r\n\r\n#ifndef __WINDOWS_THREAD_H\r\n#define __WINDOWS_THREAD_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\nnamespace NWindows {\r\n\r\nclass CThread\r\n{\r\n  ::CThread thread;\r\npublic:\r\n  CThread() { Thread_Construct(&thread); }\r\n  ~CThread() { Close(); }\r\n  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }\r\n  WRes Close()  { return Thread_Close(&thread); }\r\n  WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n    { return Thread_Create(&thread, startAddress, parameter); }\r\n  WRes Wait() { return Thread_Wait(&thread); }\r\n  \r\n  #ifdef _WIN32\r\n  operator HANDLE() { return thread.handle; }\r\n  void Attach(HANDLE handle) { thread.handle = handle; }\r\n  HANDLE Detach() { HANDLE h = thread.handle; thread.handle = NULL; return h; }\r\n  DWORD Resume() { return ::ResumeThread(thread.handle); }\r\n  DWORD Suspend() { return ::SuspendThread(thread.handle); }\r\n  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }\r\n  int GetPriority() { return ::GetThreadPriority(thread.handle); }\r\n  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }\r\n  #endif\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/Time.cpp",
    "content": "// Windows/Time.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Time.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)\r\n{\r\n  return BOOLToBool(::DosDateTimeToFileTime((UInt16)(dosTime >> 16), (UInt16)(dosTime & 0xFFFF), &fileTime));\r\n}\r\n\r\nstatic const UInt32 kHighDosTime = 0xFF9FBF7D;\r\nstatic const UInt32 kLowDosTime = 0x210000;\r\n\r\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)\r\n{\r\n  WORD datePart, timePart;\r\n  if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))\r\n  {\r\n    dosTime = (fileTime.dwHighDateTime >= 0x01C00000) ? kHighDosTime : kLowDosTime;\r\n    return false;\r\n  }\r\n  dosTime = (((UInt32)datePart) << 16) + timePart;\r\n  return true;\r\n}\r\n\r\nstatic const UInt32 kNumTimeQuantumsInSecond = 10000000;\r\nstatic const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;\r\n\r\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)\r\n{\r\n  UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;\r\n  fileTime.dwLowDateTime = (DWORD)v;\r\n  fileTime.dwHighDateTime = (DWORD)(v >> 32);\r\n}\r\n\r\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)\r\n{\r\n  UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;\r\n  if (winTime < kUnixTimeStartValue)\r\n  {\r\n    unixTime = 0;\r\n    return false;\r\n  }\r\n  winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;\r\n  if (winTime > 0xFFFFFFFF)\r\n  {\r\n    unixTime = 0xFFFFFFFF;\r\n    return false;\r\n  }\r\n  unixTime = (UInt32)winTime;\r\n  return true;\r\n}\r\n\r\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\r\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds)\r\n{\r\n  resSeconds = 0;\r\n  if (year < 1601 || year >= 10000 || month < 1 || month > 12 ||\r\n      day < 1 || day > 31 || hour > 23 || min > 59 || sec > 59)\r\n    return false;\r\n  UInt32 numYears = year - 1601;\r\n  UInt32 numDays = numYears * 365 + numYears / 4 - numYears / 100 + numYears / 400;\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  month--;\r\n  for (unsigned i = 0; i < month; i++)\r\n    numDays += ms[i];\r\n  numDays += day - 1;\r\n  resSeconds = ((UInt64)(numDays * 24 + hour) * 60 + min) * 60 + sec;\r\n  return true;\r\n}\r\n\r\nvoid GetCurUtcFileTime(FILETIME &ft)\r\n{\r\n  SYSTEMTIME st;\r\n  GetSystemTime(&st);\r\n  SystemTimeToFileTime(&st, &ft);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CPP/Windows/Time.h",
    "content": "// Windows/Time.h\r\n\r\n#ifndef __WINDOWS_TIME_H\r\n#define __WINDOWS_TIME_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime);\r\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime);\r\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime);\r\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime);\r\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\r\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds);\r\nvoid GetCurUtcFileTime(FILETIME &ft);\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid SetStream(System.IO.Stream inStream);\r\n\t\tvoid Init();\r\n\t\tvoid ReleaseStream();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetMatches(UInt32[] distances);\r\n\t\tvoid Skip(UInt32 num);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize = 0;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\tUInt32[] _son;\r\n\t\tUInt32[] _hash;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\t\tUInt32 _hashMask;\r\n\t\tUInt32 _hashSizeSum = 0;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\r\n\t\tconst UInt32 kHash2Size = 1 << 10;\r\n\t\tconst UInt32 kHash3Size = 1 << 16;\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kStartMaxLen = 1;\r\n\t\tconst UInt32 kHash3Offset = kHash2Size;\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\t\r\n\t\tUInt32 kNumHashDirectBytes = 0;\r\n\t\tUInt32 kMinMatchCheck = 4;\r\n\t\tUInt32 kFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\r\n\t\tpublic void SetType(int numHashBytes)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\t\tkMinMatchCheck = 4;\r\n\t\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\t\tkFixHashSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic new void SetStream(System.IO.Stream stream) { base.SetStream(stream); }\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\t\t\r\n\t\tpublic new void Init()\r\n\t\t{\r\n\t\t\tbase.Init();\r\n\t\t\tfor (UInt32 i = 0; i < _hashSizeSum; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\t\tthrow new Exception();\r\n\t\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\t\t\t\t\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\tUInt32 cyclicBufferSize = historySize + 1;\r\n\t\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t\t_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\t\tUInt32 hs = kBT2HashSize;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\ths = historySize - 1;\r\n\t\t\t\ths |= (hs >> 1);\r\n\t\t\t\ths |= (hs >> 2);\r\n\t\t\t\ths |= (hs >> 4);\r\n\t\t\t\ths |= (hs >> 8);\r\n\t\t\t\ths >>= 1;\r\n\t\t\t\ths |= 0xFFFF;\r\n\t\t\t\tif (hs > (1 << 24))\r\n\t\t\t\t\ths >>= 1;\r\n\t\t\t\t_hashMask = hs;\r\n\t\t\t\ths++;\r\n\t\t\t\ths += kFixHashSize;\r\n\t\t\t}\r\n\t\t\tif (hs != _hashSizeSum)\r\n\t\t\t\t_hash = new UInt32[_hashSizeSum = hs];\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetMatches(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 offset = 0;\r\n\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\t\t\tUInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 curMatch2 = _hash[hash2Value];\r\n\t\t\t\tUInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t\t{\r\n\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\t\t\t\r\n\t\t\tif (kNumHashDirectBytes != 0)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\r\n\t\t\twhile(true)\r\n\t\t\t{\r\n\t\t\t\tif(curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (maxLen < len)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t\treturn offset;\r\n\t\t}\r\n\r\n\t\tpublic void Skip(UInt32 num)\r\n\t\t{\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenLimit;\r\n\t\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tMovePos();\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\t\tUInt32 hashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\t\tUInt32 hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\t\tUInt32 hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\t\tUInt32 len0, len1;\r\n\t\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\t\tlen1 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\t\tlen0 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tMovePos();\r\n\t\t\t}\r\n\t\t\twhile (--num != 0);\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 subValue = _pos - _cyclicBufferSize;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize; // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos; // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos\r\n\t\tpublic UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\t\tif (offset > 0)\r\n\t\t\t\toffset--;\r\n\t\t\t\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { _stream = stream; }\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic uint TrainSize = 0;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t\tTrainSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tlong len = stream.Length;\r\n\t\t\tuint size = (len < _windowSize) ? (uint)len : _windowSize;\r\n\t\t\tTrainSize = size;\r\n\t\t\tstream.Position = len - size;\r\n\t\t\t_streamPos = _pos = 0;\r\n\t\t\twhile (size > 0)\r\n\t\t\t{\r\n\t\t\t\tuint curSize = _windowSize - _pos;\r\n\t\t\t\tif (size < curSize)\r\n\t\t\t\t\tcurSize = size;\r\n\t\t\t\tint numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tsize -= (uint)numReadBytes;\r\n\t\t\t\t_pos += (uint)numReadBytes;\r\n\t\t\t\t_streamPos += (uint)numReadBytes;\r\n\t\t\t\tif (_pos == _windowSize)\r\n\t\t\t\t\t_streamPos = _pos = 0;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t\tpublic bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\t// public const int kDicLogSizeMax = 30;\r\n\t\t// public const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tbool _solid = false;\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream, _solid);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t_solid = true;\r\n\t\t\treturn m_OutWindow.Train(stream);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get { return 0; }}\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t};\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1 << 11];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 22;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 11))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 21))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 10] + 20);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 20] + 40);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 17))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 27))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 16] + 32);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 26] + 52);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 22;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32[] prices, UInt32 st)\r\n\t\t\t{\r\n\t\t\t\tUInt32 a0 = _choice.GetPrice0();\r\n\t\t\t\tUInt32 a1 = _choice.GetPrice1();\r\n\t\t\t\tUInt32 b0 = a1 + _choice2.GetPrice0();\r\n\t\t\t\tUInt32 b1 = a1 + _choice2.GetPrice1();\r\n\t\t\t\tUInt32 i = 0;\r\n\t\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\tLZ.IMatchFinder _matchFinder = null;\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates];\r\n\t\t\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];\r\n\t\t\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _numDistancePairs;\r\n\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\t\tSystem.IO.Stream _inStream;\r\n\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark = false;\r\n\t\t\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tif (_matchFinderType == EMatchFinderType.BT2)\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs)\r\n\t\t{\r\n\t\t\tlenRes = 0;\r\n\t\t\tnumDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\t\tif (numDistancePairs > 0)\r\n\t\t\t{\r\n\t\t\t\tlenRes = _matchDistances[numDistancePairs - 2];\r\n\t\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t}\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tif (num > 0)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Skip(num);\r\n\t\t\t\t_additionalOffset += num;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t\t}\r\n\t\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\t\tUInt32 lenMain, numDistancePairs;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain, out numDistancePairs);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\t\t\t\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = (UInt32)0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\t\tif(lenEnd < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\t\tUInt32 len = lenEnd;\r\n\t\t\tdo\r\n\t\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\t\twhile (len >= 2);\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tif (repLen < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tUInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--repLen >= 2);\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\t\t\t\r\n\t\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\t\tif (len <= lenMain)\r\n\t\t\t{\r\n\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\tfor (; ; len++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 distance = _matchDistances[offs + 1];\r\n\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen, out numDistancePairs);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_numDistancePairs = numDistancePairs;\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t\t{\r\n\t\t\t\t\t// try Literal + rep0\r\n\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 startLen = 2; // speed optimization \r\n\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t\t// if (_maxMode)\r\n\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, reps[repIndex], t);\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)(reps[repIndex] + 1))), \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t\t}\r\n\t\t\t\tif (newLen >= startLen)\r\n\t\t\t\t{\r\n\t\t\t\t\tnormalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = startLen; ; lenTest++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t);\r\n\t\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)(curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t\t_matchFinder.Init();\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t\tif (_trainSize > 0)\r\n\t\t\t\t\t_matchFinder.Skip(_trainSize);\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len, numDistancePairs; // it's not used\r\n\t\t\t\tReadMatchDistances(out len, out numDistancePairs);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 len = GetOptimum((UInt32)nowPos64, out pos);\r\n\t\t\t\t\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t// if (!_fastMode)\r\n\t\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// if (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\t\t\r\n\t\tUInt32[] tempPrices = new UInt32[Base.kNumFullDistances];\r\n\t\tUInt32 _matchPriceCount;\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t\t{ \r\n\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, \r\n\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tRangeCoder.BitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\t\t\t\r\n\t\t\t\tUInt32 st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\t\tUInt32 st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t\t}\r\n\t\t\t_matchPriceCount = 0;\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = 0;\r\n\t\t}\r\n\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t/*\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t*/\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 30;\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _trainSize = 0;\r\n\t\tpublic void SetTrainSize(uint trainSize)\r\n\t\t{\r\n\t\t\t_trainSize = trainSize;\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\t\r\n\tpublic class CDoubleStream: Stream\r\n\t{\r\n\t\tpublic System.IO.Stream s1;\r\n\t\tpublic System.IO.Stream s2;\r\n\t\tpublic int fileIndex;\r\n\t\tpublic long skipSize;\r\n\t\t\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return false; }}\r\n\t\tpublic override bool CanSeek { get { return false; }}\r\n\t\tpublic override long Length { get { return s1.Length + s2.Length - skipSize; } }\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\tint numTotal = 0;\r\n\t\t\twhile (count > 0)\r\n\t\t\t{\r\n\t\t\t\tif (fileIndex == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tint num = s1.Read(buffer, offset, count);\r\n\t\t\t\t\toffset += num;\r\n\t\t\t\t\tcount -= num;\r\n\t\t\t\t\tnumTotal += num;\r\n\t\t\t\t\tif (num == 0)\r\n\t\t\t\t\t\tfileIndex++;\r\n\t\t\t\t}\r\n\t\t\t\tif (fileIndex == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tnumTotal += s2.Read(buffer, offset, count);\r\n\t\t\t\t\treturn numTotal;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn numTotal;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Write\"));\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Seek\"));\r\n\t\t}\r\n\t\tpublic override void SetLength(long value)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't SetLength\"));\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut,\r\n\t\t\tTrain\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0, 29], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.61  2008-11-23\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[13];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"T\", SwitchType.UnLimitedPostString, false, 1);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary);\r\n\t\t\t}\r\n\r\n\t\t\tstring train = \"\";\r\n\t\t\tif (parser[(int)Key.Train].ThereIs)\r\n\t\t\t\ttrain = (string)parser[(int)Key.Train].PostStrings[0];\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream trainStream = null;\r\n\t\t\tif (train.Length != 0)\r\n\t\t\t\ttrainStream = new FileStream(train, FileMode.Open, FileAccess.Read);\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tCDoubleStream doubleStream = new CDoubleStream();\r\n\t\t\t\t\tdoubleStream.s1 = trainStream;\r\n\t\t\t\t\tdoubleStream.s2 = inStream;\r\n\t\t\t\t\tdoubleStream.fileIndex = 0;\r\n\t\t\t\t\tinStream = doubleStream;\r\n\t\t\t\t\tlong trainFileSize = trainStream.Length;\r\n\t\t\t\t\tdoubleStream.skipSize = 0;\r\n\t\t\t\t\tif (trainFileSize > dictionary)\r\n\t\t\t\t\t\tdoubleStream.skipSize = trainFileSize - dictionary;\r\n\t\t\t\t\ttrainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);\r\n\t\t\t\t\tencoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));\r\n\t\t\t\t}\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!decoder.Train(trainStream))\r\n\t\t\t\t\t\tthrow (new Exception(\"can't train\"));\r\n\t\t\t\t}\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.50727</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tUInt32 Rep0;\r\n\t\t\t\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\t\tUInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\tRG.Init();\r\n\t\t\t\tRep0 = 1;\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)RG.GetRnd(8);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 len;\r\n\t\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\t\tUInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 220 + outSize * 20;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 18))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "// LZ.BinTree\r\n\r\npackage SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\r\n\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize = 0;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\tint[] _hash;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\tint _hashMask;\r\n\tint _hashSizeSum = 0;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\r\n\tstatic final int kHash2Size = 1 << 10;\r\n\tstatic final int kHash3Size = 1 << 16;\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kStartMaxLen = 1;\r\n\tstatic final int kHash3Offset = kHash2Size;\r\n\tstatic final int kEmptyHashValue = 0;\r\n\tstatic final int kMaxValForNormalize = (1 << 30) - 1;\r\n\t\r\n\tint kNumHashDirectBytes = 0;\r\n\tint kMinMatchCheck = 4;\r\n\tint kFixHashSize = kHash2Size + kHash3Size;\r\n\r\n\tpublic void SetType(int numHashBytes)\r\n\t{\r\n\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\tkMinMatchCheck = 4;\r\n\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\tkFixHashSize = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tfor (int i = 0; i < _hashSizeSum; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\treturn false;\r\n\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\tint cyclicBufferSize = historySize + 1;\r\n\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t_son = new int[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\tint hs = kBT2HashSize;\r\n\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\ths = historySize - 1;\r\n\t\t\ths |= (hs >> 1);\r\n\t\t\ths |= (hs >> 2);\r\n\t\t\ths |= (hs >> 4);\r\n\t\t\ths |= (hs >> 8);\r\n\t\t\ths >>= 1;\r\n\t\t\ths |= 0xFFFF;\r\n\t\t\tif (hs > (1 << 24))\r\n\t\t\t\ths >>= 1;\r\n\t\t\t_hashMask = hs;\r\n\t\t\ths++;\r\n\t\t\ths += kFixHashSize;\r\n\t\t}\r\n\t\tif (hs != _hashSizeSum)\r\n\t\t\t_hash = new int [_hashSizeSum = hs];\r\n\t\treturn true;\r\n\t}\r\n\tpublic int GetMatches(int[] distances) throws IOException\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t{\r\n\t\t\t\tMovePos();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint offset = 0;\r\n\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\tint maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint curMatch2 = _hash[hash2Value];\r\n\t\t\tint curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t}\r\n\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t}\r\n\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t{\r\n\t\t\t\toffset -= 2;\r\n\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\tint len0, len1;\r\n\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\tif (kNumHashDirectBytes != 0)\r\n\t\t{\r\n\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint count = _cutValue;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint len = Math.min(len0, len1);\r\n\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t{\r\n\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tif (maxLen < len)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t{\r\n\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\tlen1 = len;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\tlen0 = len;\r\n\t\t\t}\r\n\t\t}\r\n\t\tMovePos();\r\n\t\treturn offset;\r\n\t}\r\n\r\n\tpublic void Skip(int num) throws IOException\r\n\t{\r\n\t\tdo\r\n\t\t{\r\n\t\t\tint lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tint cur = _bufferOffset + _pos;\r\n\t\t\t\r\n\t\t\tint hashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\t\tint hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\t\tint hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tint len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\tint count = _cutValue;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tint len = Math.min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t}\r\n\t\twhile (--num != 0);\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint subValue = _pos - _cyclicBufferSize;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue) { _cutValue = cutValue; }\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\tif (offset > 0)\r\n\t\t\toffset--;\r\n\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free() { _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream) { _stream = stream; \t}\r\n\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\t// public static final int kDicLogSizeMax = 28;\r\n\t// public static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\r\n\r\n\r\n\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\r\n\tstatic byte[] g_FastPos = new byte[1 << 11];\r\n\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 22;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 11))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 21))\r\n\t\t\treturn (g_FastPos[pos >> 10] + 20);\r\n\t\treturn (g_FastPos[pos >> 20] + 40);\r\n\t}\r\n\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 17))\r\n\t\t\treturn (g_FastPos[pos >> 6] + 12);\r\n\t\tif (pos < (1 << 27))\r\n\t\t\treturn (g_FastPos[pos >> 16] + 32);\r\n\t\treturn (g_FastPos[pos >> 26] + 52);\r\n\t}\r\n\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\r\n\tstatic final int kDefaultDictionaryLogSize = 22;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\r\n\t\t\tpublic void Init() { SevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders); }\r\n\r\n\r\n\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetPrices(int posState, int numSymbols, int[] prices, int st)\r\n\t\t{\r\n\t\t\tint a0 = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\tint a1 = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\tint b0 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\tint b1 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\tint i = 0;\r\n\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t}\r\n\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t}\r\n\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t}\r\n\t};\r\n\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols<<Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\tpublic void SetTableSize(int tableSize) { _tableSize = tableSize; }\r\n\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t}\r\n\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\r\n\tstatic final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;\r\n\t\tpublic int BackPrev;\r\n\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\r\n\t\tpublic void MakeAsChar() { BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep() { return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null;\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\r\n\tshort[] _isMatch = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances-Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen*2+2];\r\n\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _numDistancePairs;\r\n\r\n\tint _additionalOffset;\r\n\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\r\n\tboolean _longestMatchWasFound;\r\n\r\n\tint[] _posSlotPrices = new int[1<<(Base.kNumPosSlotBits+Base.kNumLenToPosStatesBits)];\r\n\tint[] _distancesPrices = new int[Base.kNumFullDistances<<Base.kNumLenToPosStatesBits];\r\n\tint[] _alignPrices = new int[Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\tjava.io.InputStream _inStream;\r\n\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\r\n\tboolean _needReleaseMFStream = false;\r\n\r\n\tvoid Create()\r\n\t{\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tif (_matchFinderType == EMatchFinderTypeBT2)\r\n\t\t\t\tnumHashBytes = 2;\r\n\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\r\n\tvoid SetWriteEndMarkerMode(boolean writeEndMarker)\r\n\t{\r\n\t\t_writeEndMark = writeEndMarker;\r\n\t}\r\n\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\r\n\r\n\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n\t\t_posAlignEncoder.Init();\r\n\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = 0;\r\n\t\t_numDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\tif (_numDistancePairs > 0)\r\n\t\t{\r\n\t\t\tlenRes = _matchDistances[_numDistancePairs - 2];\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[_numDistancePairs - 1],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t}\r\n\t\t_additionalOffset++;\r\n\t\treturn lenRes;\r\n\t}\r\n\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tif (num > 0)\r\n\t\t{\r\n\t\t\t_matchFinder.Skip(num);\r\n\t\t\t_additionalOffset += num;\r\n\t\t}\r\n\t}\r\n\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\r\n\tint GetPureRepPrice(int repIndex, int state, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t}\r\n\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\r\n\tint Backward(int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\tint backRes;\r\n\r\n\tint GetOptimum(int position) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\tint lenMain, numDistancePairs;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tnumDistancePairs = _numDistancePairs;\r\n\r\n\t\tint numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\tif (numAvailableBytes < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\tbyte matchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[0].State = _state;\r\n\r\n\t\tint posState = (position & _posStateMask);\r\n\r\n\t\t_optimum[1].Price = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\tif (lenEnd < 2)\r\n\t\t{\r\n\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\tint len = lenEnd;\r\n\t\tdo\r\n\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\twhile (len >= 2);\r\n\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tif (repLen < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tint price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twhile (--repLen >= 2);\r\n\t\t}\r\n\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\r\n\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\tif (len <= lenMain)\r\n\t\t{\r\n\t\t\tint offs = 0;\r\n\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\toffs += 2;\r\n\t\t\tfor (; ; len++)\r\n\t\t\t{\r\n\t\t\t\tint distance = _matchDistances[offs + 1];\r\n\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t{\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint cur = 0;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\r\n\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t{\r\n\t\t\t\t// try Literal + rep0\r\n\t\t\t\tint t = Math.min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint startLen = 2; // speed optimization \r\n\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\tint lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t// if (_maxMode)\r\n\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t{\r\n\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, reps[repIndex], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - (reps[repIndex] + 1)),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t{\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t}\r\n\t\t\tif (newLen >= startLen)\r\n\t\t\t{\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\tint offs = 0;\r\n\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\tfor (int lenTest = startLen; ; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, curBack, t);\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\r\n\t\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - (curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\r\n\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\r\n\t\t\tint len = GetOptimum((int)nowPos64);\r\n\t\t\tint pos = backRes;\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\t// if (!_fastMode)\r\n\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\r\n\t\t// if (!_fastMode)\r\n\t\t{\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\r\n\tlong[] processedInSize = new long[1]; long[] processedOutSize = new long[1]; boolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\r\n\r\n\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\r\n\tint[] tempPrices = new int[Base.kNumFullDistances];\r\n\tint _matchPriceCount;\r\n\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t{\r\n\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t}\r\n\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tBitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\r\n\t\t\tint st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\tint st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t}\r\n\t\t_matchPriceCount = 0;\r\n\t}\r\n\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = 0;\r\n\t}\r\n\r\n\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\t/*\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\t*/\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = 29;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++) ;\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.61  2008-11-23\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SetNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator() { Init(); }\r\n\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tint Rep0;\r\n\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\r\n\t\tpublic CBenchRandomGenerator() { }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit() { return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\tint GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\tRG.Init();\r\n\t\t\tRep0 = 1;\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint len;\r\n\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, long elapsedTime, long size)\r\n\t{\r\n\t\tlong t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\tlong numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime, long outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 220 + outSize * 20;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 18))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 18 (256 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/Methods.txt",
    "content": "7-Zip method IDs (4.65)\r\n-----------------------\r\n\r\nEach compression or crypto method in 7z has unique binary value (ID).\r\nThe length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).\r\n\r\nIf you want to add some new ID, you have two ways:\r\n1) Write request for allocating IDs to 7-zip developers.\r\n2) Generate 8-bytes ID:\r\n\r\n    3F ZZ ZZ ZZ ZZ ZZ MM MM \r\n\r\n    3F              - Prefix for random IDs (1 byte)\r\n    ZZ ZZ ZZ ZZ ZZ  - Developer ID (5 bytes). Use real random bytes. \r\n                      \r\n    MM MM           - Method ID (2 bytes)\r\n\r\n    You can notify 7-Zip developers about your Developer ID / Method ID.\r\n\r\n    Note: Use new ID only if old codec can not decode data encoded with new version.\r\n\r\n\r\nList of defined IDs\r\n-------------------\r\n      \r\n00 - Copy\r\n\r\n02 - Common\r\n   03 Swap\r\n      - 2 Swap2\r\n      - 4 Swap4\r\n\r\n03 - 7z\r\n   01 - LZMA\r\n      01 - Version\r\n  \r\n   03 - Branch\r\n      01 - x86\r\n         03  - BCJ\r\n         1B  - BCJ2\r\n      02 - PPC\r\n         05 - PPC (Big Endian)\r\n      03 - Alpha\r\n         01 - Alpha\r\n      04 - IA64\r\n         01 - IA64\r\n      05 - ARM\r\n         01 - ARM\r\n      06 - M68\r\n         05 - M68 (Big Endian)\r\n      07 - ARM Thumb\r\n         01 - ARMT\r\n      08 - SPARC\r\n         05 - SPARC\r\n\r\n   04 - PPMD\r\n      01 - Version\r\n\r\n   7F -\r\n      01 - experimental methods.\r\n\r\n\r\n04 - Misc\r\n   00 - Reserved\r\n   01 - Zip\r\n      00 - Copy (not used). Use {00} instead\r\n      01 - Shrink\r\n      06 - Implode\r\n      08 - Deflate\r\n      09 - Deflate64\r\n      12 - BZip2 (not used). Use {04 02 02} instead\r\n   02 - BZip\r\n      02 - BZip2\r\n   03 - Rar\r\n      01 - Rar15\r\n      02 - Rar20\r\n      03 - Rar29\r\n   04 - Arj\r\n      01 - Arj (1,2,3)\r\n      02 - Arj 4\r\n   05 - Z\r\n   06 - Lzh\r\n   07 - Reserved for 7z\r\n   08 - Cab\r\n   09 - NSIS\r\n      01 - DeflateNSIS\r\n      02 - BZip2NSIS\r\n\r\n\r\n06 - Crypto \r\n   00 - \r\n   01 - AES\r\n      0x - AES-128\r\n      4x - AES-192\r\n      8x - AES-256\r\n      Cx - AES\r\n\r\n      x0 - ECB\r\n      x1 - CBC\r\n      x2 - CFB\r\n      x3 - OFB\r\n\r\n   07 - Reserved\r\n   0F - Reserved\r\n\r\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\r\n\r\n   F1 - Misc Ciphers (Combine)\r\n      01 - Zip\r\n         01 - Main Zip crypto algo\r\n      03 - RAR\r\n         02 - \r\n         03 - Rar29 AES-128 + (modified SHA-1)\r\n      07 - 7z\r\n         01 - AES-256 + SHA-256\r\n\r\n07 - Hash (subject to change)\r\n   00 - \r\n   01 - CRC\r\n   02 - SHA-1\r\n   03 - SHA-256\r\n   04 - SHA-384\r\n   05 - SHA-512\r\n\r\n   F0 - Misc Hash\r\n\r\n   F1 - Misc\r\n      03 - RAR\r\n         03 - Rar29 Password Hashing (modified SHA1)\r\n      07 - 7z \r\n         01 - SHA-256 Password Hashing\r\n    \r\n   \r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/history.txt",
    "content": "HISTORY of the LZMA SDK\r\n-----------------------\r\n\r\n4.65           2009-02-03\r\n-------------------------\r\n- Some minor fixes\r\n\r\n\r\n4.63           2008-12-31\r\n-------------------------\r\n- Some minor fixes\r\n\r\n\r\n4.61 beta      2008-11-23\r\n-------------------------\r\n- The bug in ANSI-C LZMA Decoder was fixed:\r\n    If encoded stream was corrupted, decoder could access memory \r\n    outside of allocated range.\r\n- Some changes in ANSI-C 7z Decoder interfaces.\r\n- LZMA SDK is placed in the public domain.\r\n\r\n\r\n4.60 beta      2008-08-19\r\n-------------------------\r\n- Some minor fixes.\r\n\r\n\r\n4.59 beta      2008-08-13\r\n-------------------------\r\n- The bug was fixed:\r\n    LZMA Encoder in fast compression mode could access memory outside of \r\n    allocated range in some rare cases.\r\n\r\n\r\n4.58 beta      2008-05-05\r\n-------------------------\r\n- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r\n- ANSI-C LZMA Encoder was included to LZMA SDK.\r\n- C++ LZMA code now is just wrapper over ANSI-C code.\r\n\r\n\r\n4.57           2007-12-12\r\n-------------------------\r\n- Speed optimizations in ++ LZMA Decoder. \r\n- Small changes for more compatibility with some C/C++ compilers.\r\n\r\n\r\n4.49 beta      2007-07-05\r\n-------------------------\r\n- .7z ANSI-C Decoder:\r\n     - now it supports BCJ and BCJ2 filters\r\n     - now it supports files larger than 4 GB.\r\n     - now it supports \"Last Write Time\" field for files.\r\n- C++ code for .7z archives compressing/decompressing from 7-zip \r\n  was included to LZMA SDK.\r\n  \r\n\r\n4.43           2006-06-04\r\n-------------------------\r\n- Small changes for more compatibility with some C/C++ compilers.\r\n  \r\n\r\n4.42           2006-05-15\r\n-------------------------\r\n- Small changes in .h files in ANSI-C version.\r\n  \r\n\r\n4.39 beta      2006-04-14\r\n-------------------------\r\n- The bug in versions 4.33b:4.38b was fixed:\r\n  C++ version of LZMA encoder could not correctly compress \r\n  files larger than 2 GB with HC4 match finder (-mfhc4).\r\n  \r\n\r\n4.37 beta      2005-04-06\r\n-------------------------\r\n- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r\n\r\n\r\n4.35 beta      2005-03-02\r\n-------------------------\r\n- The bug was fixed in C++ version of LZMA Decoder:\r\n    If encoded stream was corrupted, decoder could access memory \r\n    outside of allocated range.\r\n\r\n\r\n4.34 beta      2006-02-27\r\n-------------------------\r\n- Compressing speed and memory requirements for compressing were increased\r\n- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r\n\r\n\r\n4.32           2005-12-09\r\n-------------------------\r\n- Java version of LZMA SDK was included\r\n\r\n\r\n4.30           2005-11-20\r\n-------------------------\r\n- Compression ratio was improved in -a2 mode\r\n- Speed optimizations for compressing in -a2 mode\r\n- -fb switch now supports values up to 273\r\n- The bug in 7z_C (7zIn.c) was fixed:\r\n  It used Alloc/Free functions from different memory pools.\r\n  So if program used two memory pools, it worked incorrectly.\r\n- 7z_C: .7z format supporting was improved\r\n- LZMA# SDK (C#.NET version) was included\r\n\r\n\r\n4.27 (Updated) 2005-09-21\r\n-------------------------\r\n- Some GUIDs/interfaces in C++ were changed.\r\n IStream.h:\r\n   ISequentialInStream::Read now works as old ReadPart\r\n   ISequentialOutStream::Write now works as old WritePart\r\n\r\n\r\n4.27           2005-08-07\r\n-------------------------\r\n- The bug in LzmaDecodeSize.c was fixed:\r\n   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r\n   decompressing worked incorrectly.\r\n\r\n\r\n4.26           2005-08-05\r\n-------------------------\r\n- Fixes in 7z_C code and LzmaTest.c:\r\n  previous versions could work incorrectly,\r\n  if malloc(0) returns 0\r\n\r\n\r\n4.23           2005-06-29\r\n-------------------------\r\n- Small fixes in C++ code\r\n\r\n\r\n4.22           2005-06-10\r\n-------------------------\r\n- Small fixes\r\n\r\n\r\n4.21           2005-06-08\r\n-------------------------\r\n- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r\n- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r\n    - LzmaStateDecode.h\r\n    - LzmaStateDecode.c\r\n    - LzmaStateTest.c\r\n- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r\n\r\n\r\n4.17           2005-04-18\r\n-------------------------\r\n- New example for RAM->RAM compressing/decompressing: \r\n  LZMA + BCJ (filter for x86 code):\r\n    - LzmaRam.h\r\n    - LzmaRam.cpp\r\n    - LzmaRamDecode.h\r\n    - LzmaRamDecode.c\r\n    - -f86 switch for lzma.exe\r\n\r\n\r\n4.16           2005-03-29\r\n-------------------------\r\n- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r\n   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r\n   decoder could access memory outside of allocated range.\r\n- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r\n  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r\n  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r\n- Small speed optimization in LZMA C++ code\r\n- filter for SPARC's code was added\r\n- Simplified version of .7z ANSI-C Decoder was included\r\n\r\n\r\n4.06           2004-09-05\r\n-------------------------\r\n- The bug in v4.05 was fixed:\r\n    LZMA-Encoder didn't release output stream in some cases.\r\n\r\n\r\n4.05           2004-08-25\r\n-------------------------\r\n- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r\n  and PowerPC code was included to SDK\r\n- Some internal minor changes\r\n\r\n\r\n4.04           2004-07-28\r\n-------------------------\r\n- More compatibility with some C++ compilers\r\n\r\n\r\n4.03           2004-06-18\r\n-------------------------\r\n- \"Benchmark\" command was added. It measures compressing \r\n  and decompressing speed and shows rating values. \r\n  Also it checks hardware errors.\r\n\r\n\r\n4.02           2004-06-10\r\n-------------------------\r\n- C++ LZMA Encoder/Decoder code now is more portable\r\n  and it can be compiled by GCC on Linux.\r\n\r\n\r\n4.01           2004-02-15\r\n-------------------------\r\n- Some detection of data corruption was enabled.\r\n    LzmaDecode.c / RangeDecoderReadByte\r\n    .....\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n\r\n\r\n4.00           2004-02-13\r\n-------------------------\r\n- Original version of LZMA SDK\r\n\r\n\r\n\r\nHISTORY of the LZMA\r\n-------------------\r\n  2001-2008:  Improvements to LZMA compressing/decompressing code, \r\n              keeping compatibility with original LZMA format\r\n  1996-2001:  Development of LZMA compression format\r\n\r\n  Some milestones:\r\n\r\n  2001-08-30: LZMA compression was added to 7-Zip\r\n  1999-01-02: First version of 7-Zip was released\r\n  \r\n\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/lzma.txt",
    "content": "LZMA SDK 4.65\r\n-------------\r\n\r\nLZMA SDK provides the documentation, samples, header files, libraries, \r\nand tools you need to develop applications that use LZMA compression.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\nLZMA is an improved version of famous LZ77 compression algorithm. \r\nIt was improved in way of maximum increasing of compression ratio,\r\nkeeping high decompression speed and low memory requirements for \r\ndecompressing.\r\n\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\r\n\r\n\r\nLZMA SDK Contents\r\n-----------------\r\n\r\nLZMA SDK includes:\r\n\r\n  - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing\r\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\r\n\r\n\r\nUNIX/Linux version \r\n------------------\r\nTo compile C++ version of file->file LZMA encoding, go to directory\r\nC++/7zip/Compress/LZMA_Alone \r\nand call make to recompile it:\r\n  make -f makefile.gcc clean all\r\n\r\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\r\nTo compile with static libraries, you can use \r\nLIB = -lm -static\r\n\r\n\r\nFiles\r\n---------------------\r\nlzma.txt     - LZMA SDK description (this file)\r\n7zFormat.txt - 7z Format description\r\n7zC.txt      - 7z ANSI-C Decoder description\r\nmethods.txt  - Compression method IDs for .7z\r\nlzma.exe     - Compiled file->file LZMA encoder/decoder for Windows\r\nhistory.txt  - history of the LZMA SDK\r\n\r\n\r\nSource code structure\r\n---------------------\r\n\r\nC/  - C files\r\n        7zCrc*.*   - CRC code\r\n        Alloc.*    - Memory allocation functions\r\n        Bra*.*     - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n        LzFind.*   - Match finder for LZ (LZMA) encoders \r\n        LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding\r\n        LzHash.h   - Additional file for LZ match finder\r\n        LzmaDec.*  - LZMA decoding\r\n        LzmaEnc.*  - LZMA encoding\r\n        LzmaLib.*  - LZMA Library for DLL calling\r\n        Types.h    - Basic types for another .c files\r\n\tThreads.*  - The code for multithreading.\r\n\r\n    LzmaLib  - LZMA Library (.DLL for Windows)\r\n    \r\n    LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).\r\n\r\n    Archive - files related to archiving\r\n      7z     - 7z ANSI-C Decoder\r\n\r\nCPP/ -- CPP files\r\n\r\n  Common  - common files for C++ projects\r\n  Windows - common files for Windows related code\r\n\r\n  7zip    - files related to 7-Zip Project\r\n\r\n    Common   - common files for 7-Zip\r\n\r\n    Compress - files related to compression/decompression\r\n\r\n      Copy         - Copy coder\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n      LZMA         - LZMA compression/decompression on C++\r\n      LZMA_Alone   - file->file LZMA compression/decompression\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n\r\n    Archive - files related to archiving\r\n\r\n      Common   - common files for archive handling\r\n      7z       - 7z C++ Encoder/Decoder\r\n\r\n    Bundles    - Modules that are bundles of other modules\r\n  \r\n      Alone7z           - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2\r\n      Format7zR         - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r\n      Format7zExtractR  - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.\r\n\r\n    UI        - User Interface files\r\n         \r\n      Client7z - Test application for 7za.dll,  7zr.dll, 7zxr.dll\r\n      Common   - Common UI files\r\n      Console  - Code for console archiver\r\n\r\n\r\n\r\nCS/ - C# files\r\n  7zip\r\n    Common   - some common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      LzmaAlone    - file->file LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nJava/  - Java files\r\n  SevenZip\r\n    Compression    - files related to compression/decompression\r\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\n\r\nC/C++ source code of LZMA SDK is part of 7-Zip project.\r\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r\n\r\n  http://sourceforge.net/projects/sevenzip/\r\n\r\n\r\n\r\nLZMA features\r\n-------------\r\n  - Variable dictionary size (up to 1 GB)\r\n  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r\n  - Estimated decompressing speed: \r\n      - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64\r\n      - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC\r\n  - Small memory requirements for decompressing (16 KB + DictionarySize)\r\n  - Small code size for decompressing: 5-8 KB\r\n\r\nLZMA decoder uses only integer operations and can be \r\nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r\n\r\nSome critical operations that affect the speed of LZMA decompression:\r\n  1) 32*16 bit integer multiply\r\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\r\n  3) 32-bit shift and arithmetic operations\r\n\r\nThe speed of LZMA decompressing mostly depends from CPU speed.\r\nMemory speed has no big meaning. But if your CPU has small data cache, \r\noverall weight of memory speed will slightly increase.\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nUsing LZMA encoder/decoder executable\r\n--------------------------------------\r\n\r\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\r\n\r\n  e: encode file\r\n\r\n  d: decode file\r\n\r\n  b: Benchmark. There are two tests: compressing and decompressing \r\n     with LZMA method. Benchmark shows rating in MIPS (million \r\n     instructions per second). Rating value is calculated from \r\n     measured speed and it is normalized with Intel's Core 2 results.\r\n     Also Benchmark checks possible hardware errors (RAM \r\n     errors in most cases). Benchmark uses these settings:\r\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r\n     Also you can change the number of iterations. Example for 30 iterations:\r\n       LZMA b 30\r\n     Default number of iterations is 10.\r\n\r\n<Switches>\r\n  \r\n\r\n  -a{N}:  set compression mode 0 = fast, 1 = normal\r\n          default: 1 (normal)\r\n\r\n  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r\n          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \r\n          For decompressing file compressed by LZMA method with dictionary \r\n          size D = 2^N you need about D bytes of memory (RAM).\r\n\r\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\r\n          Usually big number gives a little bit better compression ratio \r\n          and slower compression process.\r\n\r\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\r\n          Sometimes lc=4 gives gain for big files.\r\n\r\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r\n          lp switch is intended for periodical data when period is \r\n          equal 2^N. For example, for 32-bit (4 bytes) \r\n          periodical data you can use lp=2. Often it's better to set lc0, \r\n          if you change lp switch.\r\n\r\n  -pb{N}: set number of pos bits - [0, 4], default: 2\r\n          pb switch is intended for periodical data \r\n          when period is equal 2^N.\r\n\r\n  -mf{MF_ID}: set Match Finder. Default: bt4. \r\n              Algorithms from hc* group doesn't provide good compression \r\n              ratio, but they often works pretty fast in combination with \r\n              fast mode (-a0).\r\n\r\n              Memory requirements depend from dictionary size \r\n              (parameter \"d\" in table below). \r\n\r\n               MF_ID     Memory                   Description\r\n\r\n                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r\n                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r\n                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r\n                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r\n\r\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \r\n          eos marker, since LZMA decoder knows uncompressed size \r\n          stored in .lzma file header.\r\n\r\n  -si:    Read data from stdin (it will write End Of Stream marker).\r\n  -so:    Write data to stdout\r\n\r\n\r\nExamples:\r\n\r\n1) LZMA e file.bin file.lzma -d16 -lc0 \r\n\r\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r\nand 0 literal context bits. -lc0 allows to reduce memory requirements \r\nfor decompression.\r\n\r\n\r\n2) LZMA e file.bin file.lzma -lc0 -lp2\r\n\r\ncompresses file.bin to file.lzma with settings suitable \r\nfor 32-bit periodical data (for example, ARM or MIPS code).\r\n\r\n3) LZMA d file.lzma file.bin\r\n\r\ndecompresses file.lzma to file.bin.\r\n\r\n\r\nCompression ratio hints\r\n-----------------------\r\n\r\nRecommendations\r\n---------------\r\n\r\nTo increase the compression ratio for LZMA compressing it's desirable \r\nto have aligned data (if it's possible) and also it's desirable to locate\r\ndata in such order, where code is grouped in one place and data is \r\ngrouped in other place (it's better than such mixing: code, data, code,\r\ndata, ...).\r\n\r\n\r\nFilters\r\n-------\r\nYou can increase the compression ratio for some data types, using\r\nspecial filters before compressing. For example, it's possible to \r\nincrease the compression ratio on 5-10% for code for those CPU ISAs: \r\nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r\n\r\nYou can find C source code of such filters in C/Bra*.* files\r\n\r\nYou can check the compression ratio gain of these filters with such \r\n7-Zip commands (example for ARM code):\r\nNo filter:\r\n  7z a a1.7z a.bin -m0=lzma\r\n\r\nWith filter for little-endian ARM code:\r\n  7z a a2.7z a.bin -m0=arm -m1=lzma        \r\n\r\nIt works in such manner:\r\nCompressing    = Filter_encoding + LZMA_encoding\r\nDecompressing  = LZMA_decoding + Filter_decoding\r\n\r\nCompressing and decompressing speed of such filters is very high,\r\nso it will not increase decompressing time too much.\r\nMoreover, it reduces decompression time for LZMA_decoding, \r\nsince compression ratio with filtering is higher.\r\n\r\nThese filters convert CALL (calling procedure) instructions \r\nfrom relative offsets to absolute addresses, so such data becomes more \r\ncompressible.\r\n\r\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r\n\r\n\r\nLZMA compressed file format\r\n---------------------------\r\nOffset Size Description\r\n  0     1   Special LZMA properties (lc,lp, pb in encoded form)\r\n  1     4   Dictionary size (little endian)\r\n  5     8   Uncompressed size (little endian). -1 means unknown size\r\n 13         Compressed data\r\n\r\n\r\nANSI-C LZMA Decoder\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nPlease note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.\r\nIf you want to use old interfaces you can download previous version of LZMA SDK\r\nfrom sourceforge.net site.\r\n\r\nTo use ANSI-C LZMA Decoder you need the following files:\r\n1) LzmaDec.h + LzmaDec.c + Types.h\r\nLzmaUtil/LzmaUtil.c is example application that uses these files.\r\n\r\n\r\nMemory requirements for LZMA decoding\r\n-------------------------------------\r\n\r\nStack usage of LZMA decoding function for local variables is not \r\nlarger than 200-400 bytes.\r\n\r\nLZMA Decoder uses dictionary buffer and internal state structure.\r\nInternal state structure consumes\r\n  state_size = (4 + (1.5 << (lc + lp))) KB\r\nby default (lc=3, lp=0), state_size = 16 KB.\r\n\r\n\r\nHow To decompress data\r\n----------------------\r\n\r\nLZMA Decoder (ANSI-C version) now supports 2 interfaces:\r\n1) Single-call Decompressing\r\n2) Multi-call State Decompressing (zlib-like interface)\r\n\r\nYou must use external allocator:\r\nExample:\r\nvoid *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\r\nvoid SzFree(void *p, void *address) { p = p; free(address); }\r\nISzAlloc alloc = { SzAlloc, SzFree };\r\n\r\nYou can use p = p; operator to disable compiler warnings.\r\n\r\n\r\nSingle-call Decompressing\r\n-------------------------\r\nWhen to use: RAM->RAM decompressing\r\nCompile files: LzmaDec.h + LzmaDec.c + Types.h\r\nCompile defines: no defines\r\nMemory Requirements:\r\n  - Input buffer: compressed size\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures: state_size (16 KB for default settings) \r\n\r\nInterface:\r\n  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, \r\n      ELzmaStatus *status, ISzAlloc *alloc);\r\n  In: \r\n    dest     - output data\r\n    destLen  - output data size\r\n    src      - input data\r\n    srcLen   - input data size\r\n    propData - LZMA properties  (5 bytes)\r\n    propSize - size of propData buffer (5 bytes)\r\n    finishMode - It has meaning only if the decoding reaches output limit (*destLen).\r\n\t LZMA_FINISH_ANY - Decode just destLen bytes.\r\n\t LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n                           You can use LZMA_FINISH_END, when you know that \r\n                           current output buffer covers last bytes of stream. \r\n    alloc    - Memory allocator.\r\n\r\n  Out: \r\n    destLen  - processed output size \r\n    srcLen   - processed input size \r\n\r\n  Output:\r\n    SZ_OK\r\n      status:\r\n        LZMA_STATUS_FINISHED_WITH_MARK\r\n        LZMA_STATUS_NOT_FINISHED \r\n        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n    SZ_ERROR_DATA - Data error\r\n    SZ_ERROR_MEM  - Memory allocation error\r\n    SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n\r\n  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,\r\n  and output value of destLen will be less than output buffer size limit.\r\n\r\n  You can use multiple checks to test data integrity after full decompression:\r\n    1) Check Result and \"status\" variable.\r\n    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. \r\n       You must use correct finish mode in that case. */ \r\n\r\n\r\nMulti-call State Decompressing (zlib-like interface)\r\n----------------------------------------------------\r\n\r\nWhen to use: file->file decompressing \r\nCompile files: LzmaDec.h + LzmaDec.c + Types.h\r\n\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures: state_size (16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in LZMA properties header)\r\n\r\n1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:\r\n   unsigned char header[LZMA_PROPS_SIZE + 8];\r\n   ReadFile(inFile, header, sizeof(header)\r\n\r\n2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties\r\n\r\n  CLzmaDec state;\r\n  LzmaDec_Constr(&state);\r\n  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);\r\n  if (res != SZ_OK)\r\n    return res;\r\n\r\n3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop\r\n\r\n  LzmaDec_Init(&state);\r\n  for (;;)\r\n  {\r\n    ... \r\n    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, \r\n    \tconst Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);\r\n    ...\r\n  }\r\n\r\n\r\n4) Free all allocated structures\r\n  LzmaDec_Free(&state, &g_Alloc);\r\n\r\nFor full code example, look at C/LzmaUtil/LzmaUtil.c code.\r\n\r\n\r\nHow To compress data\r\n--------------------\r\n\r\nCompile files: LzmaEnc.h + LzmaEnc.c + Types.h +\r\nLzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h\r\n\r\nMemory Requirements:\r\n  - (dictSize * 11.5 + 6 MB) + state_size\r\n\r\nLzma Encoder can use two memory allocators:\r\n1) alloc - for small arrays.\r\n2) allocBig - for big arrays.\r\n\r\nFor example, you can use Large RAM Pages (2 MB) in allocBig allocator for \r\nbetter compression speed. Note that Windows has bad implementation for \r\nLarge RAM Pages. \r\nIt's OK to use same allocator for alloc and allocBig.\r\n\r\n\r\nSingle-call Compression with callbacks\r\n--------------------------------------\r\n\r\nCheck C/LzmaUtil/LzmaUtil.c as example, \r\n\r\nWhen to use: file->file decompressing \r\n\r\n1) you must implement callback structures for interfaces:\r\nISeqInStream\r\nISeqOutStream\r\nICompressProgress\r\nISzAlloc\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) {  p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\n  CFileSeqInStream inStream;\r\n  CFileSeqOutStream outStream;\r\n\r\n  inStream.funcTable.Read = MyRead;\r\n  inStream.file = inFile;\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.file = outFile;\r\n\r\n\r\n2) Create CLzmaEncHandle object;\r\n\r\n  CLzmaEncHandle enc;\r\n\r\n  enc = LzmaEnc_Create(&g_Alloc);\r\n  if (enc == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n\r\n3) initialize CLzmaEncProps properties;\r\n\r\n  LzmaEncProps_Init(&props);\r\n\r\n  Then you can change some properties in that structure.\r\n\r\n4) Send LZMA properties to LZMA Encoder\r\n\r\n  res = LzmaEnc_SetProps(enc, &props);\r\n\r\n5) Write encoded properties to header\r\n\r\n    Byte header[LZMA_PROPS_SIZE + 8];\r\n    size_t headerSize = LZMA_PROPS_SIZE;\r\n    UInt64 fileSize;\r\n    int i;\r\n\r\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r\n    fileSize = MyGetFileLength(inFile);\r\n    for (i = 0; i < 8; i++)\r\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r\n    MyWriteFileAndCheck(outFile, header, headerSize)\r\n\r\n6) Call encoding function:\r\n      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, \r\n        NULL, &g_Alloc, &g_Alloc);\r\n\r\n7) Destroy LZMA Encoder Object\r\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r\n\r\n\r\nIf callback function return some error code, LzmaEnc_Encode also returns that code.\r\n\r\n\r\nSingle-call RAM->RAM Compression\r\n--------------------------------\r\n\r\nSingle-call RAM->RAM Compression is similar to Compression with callbacks,\r\nbut you provide pointers to buffers instead of pointers to stream callbacks:\r\n\r\nHRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, \r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error \r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.\r\n\r\n_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for \r\n                 some structures will be doubled in that case.\r\n\r\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.\r\n\r\n_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.\r\n\r\n\r\nC++ LZMA Encoder/Decoder \r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nC++ LZMA code use COM-like interfaces. So if you want to use it, \r\nyou can study basics of COM/OLE.\r\nC++ LZMA code is just wrapper over ANSI-C code.\r\n\r\n\r\nC++ Notes\r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nIf you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),\r\nyou must check that you correctly work with \"new\" operator.\r\n7-Zip can be compiled with MSVC 6.0 that doesn't throw \"exception\" from \"new\" operator.\r\nSo 7-Zip uses \"CPP\\Common\\NewHandler.cpp\" that redefines \"new\" operator:\r\noperator new(size_t size)\r\n{\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\nIf you use MSCV that throws exception for \"new\" operator, you can compile without \r\n\"NewHandler.cpp\". So standard exception will be used. Actually some code of \r\n7-Zip catches any exception in internal code and converts it to HRESULT code.\r\nSo you don't need to catch CNewException, if you call COM interfaces of 7-Zip.\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/sdk.html\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/lzma/patches/lzma465-squashfs.patch",
    "content": "diff -rNu lzma/C/LzmaDec.c lzmanew/C/LzmaDec.c\n--- lzma/C/LzmaDec.c\t2008-11-06 02:31:07.000000000 -0500\n+++ lzmanew/C/LzmaDec.c\t2010-02-25 15:09:16.000000000 -0500\n@@ -2,8 +2,10 @@\n 2008-11-06 : Igor Pavlov : Public domain */\r\n \r\n #include \"LzmaDec.h\"\r\n-\r\n+\n+#ifndef LINKSYSLZMA\r\n #include <string.h>\r\n+#endif\n \r\n #define kNumTopBits 24\r\n #define kTopValue ((UInt32)1 << kNumTopBits)\r\ndiff -rNu lzma/C/LzmaEnc.c lzmanew/C/LzmaEnc.c\n--- lzma/C/LzmaEnc.c\t2009-02-02 02:34:23.000000000 -0500\n+++ lzmanew/C/LzmaEnc.c\t2010-02-25 06:05:58.000000000 -0500\n@@ -1,7 +1,8 @@\n /* LzmaEnc.c -- LZMA Encoder\r\n 2009-02-02 : Igor Pavlov : Public domain */\r\n-\r\n+#ifndef LINKSYSLZMA\r\n #include <string.h>\r\n+#endif\n \r\n /* #define SHOW_STAT */\r\n /* #define SHOW_STAT2 */\r\n@@ -44,7 +45,10 @@\n \r\n void LzmaEncProps_Init(CLzmaEncProps *p)\r\n {\r\n-  p->level = 5;\r\n+/* The default dictionary size is 16M, The lzma_compression_level is from 1 to 5 \r\n+    and dictionary size is  (1<< (lzma_compression_level*2+14)). */\r\n+\r\n+  p->level = 1;\r\n   p->dictSize = p->mc = 0;\r\n   p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\r\n   p->writeEndMark = 0;\r\ndiff -rNu lzma/C/Types.h lzmanew/C/Types.h\n--- lzma/C/Types.h\t2008-11-22 23:45:56.000000000 -0500\n+++ lzmanew/C/Types.h\t2010-02-25 06:09:40.000000000 -0500\n@@ -4,7 +4,9 @@\n #ifndef __7Z_TYPES_H\r\n #define __7Z_TYPES_H\r\n \r\n+#ifndef LINKSYSLZMA\r\n #include <stddef.h>\r\n+#endif\r\n \r\n #ifdef _WIN32\r\n #include <windows.h>\r\n@@ -40,7 +42,10 @@\n #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r\n #endif\r\n \r\n+#ifndef Byte\r\n typedef unsigned char Byte;\r\n+#endif\r\n+\r\n typedef short Int16;\r\n typedef unsigned short UInt16;\r\n \r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/Makefile",
    "content": "# Modifications were made by Cisco Systems, Inc. on or before Thu Feb 16 11:28:44 PST 2012\nCC = gcc\n\nLZMADIR = ../lzma/C\n\nCFLAGS := -I $(LZMADIR)  -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\n\nLZMAOBJS = LzmaEnc.o LzFind.o LzmaDec.o\nMKOBJS = mksquashfs.o read_fs.o sort.o lzmainterface.o\n\nall: mksquashfs unsquashfs\n\n$(LZMAOBJS): %.o: $(LZMADIR)/%.c\n\t$(CC) -c $(CFLAGS) $(CPPFLAGS) $^ -o $@\n\nmksquashfs: $(MKOBJS) $(LZMAOBJS)\n\t$(CC) $(MKOBJS) $(LZMAOBJS) -lz -lpthread -lm -lstdc++ -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\nunsquashfs: unsquashfs.o $(LZMAOBJS)\n\t$(CC) unsquashfs.o  lzmainterface.o $(LZMAOBJS) -lz -lpthread -lm -o $@\n\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h\nclean:\n\t-rm -f *.o mksquashfs unsquashfs\n\ninstall: mksquashfs unsquashfs\n\tmkdir -p $(INSTALL_DIR)\n\tcp mksquashfs unsquashfs $(INSTALL_DIR)\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\ntypedef union squashfs_inode_header_1 squashfs_inode_header_1;\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/lzmainterface.c",
    "content": "/* Modifications were made by Cisco Systems, Inc. on or before Thu Feb 16 11:28:44 PST 2012 */\n/*\r\n * Squashfs -lzma for Linux\r\n * This program is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU General Public License\r\n * as published by the Free Software Foundation; either version 2,\r\n * or (at your option) any later version.\r\n */\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n#include <errno.h>\r\n#include \"LzmaDec.h\"\r\n#include \"LzmaEnc.h\"\r\n#include \"lzmainterface.h\"\r\n\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; free(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nint LzmaCompress(char *in_data, int in_size, char *out_data, int out_size, unsigned long *total_out)\r\n{\r\n\tCLzmaEncProps encProps;\r\n\tsize_t headerSize = LZMA_PROPS_SIZE;\r\n\tint ret;\r\n\tSizeT outProcess;\r\n\r\n\tLzmaEncProps_Init(&encProps);\r\n\tencProps.algo = 1;\r\n\toutProcess = out_size - LZMA_PROPS_SIZE;\r\n\tret = LzmaEncode(out_data+LZMA_PROPS_SIZE, &outProcess, in_data, in_size, &encProps, out_data, \r\n\t\t\t\t\t\t&headerSize, 0, NULL, &g_Alloc, &g_Alloc);\r\n\t*total_out = outProcess + LZMA_PROPS_SIZE;\r\n\treturn ret;\r\n}\r\n\r\nint LzmaUncompress(char *dst, unsigned long * dstlen, char *src, int srclen)\r\n{\r\n\tint res;\r\n\tSizeT inSizePure;\r\n\tELzmaStatus status;\r\n\r\n\tif (srclen < LZMA_PROPS_SIZE)\r\n\t{\r\n\t\tmemcpy(dst, src, srclen);\r\n\t\treturn srclen;\r\n\t}\r\n\tinSizePure = srclen - LZMA_PROPS_SIZE;\r\n\tres = LzmaDecode(dst, dstlen, src + LZMA_PROPS_SIZE, &inSizePure,\r\n\t                 src, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);\r\n\tsrclen = inSizePure ;\r\n\r\n\tif ((res == SZ_OK) ||\r\n\t\t((res == SZ_ERROR_INPUT_EOF) && (srclen == inSizePure)))\r\n\t\tres = 0;\r\n\tif (res != SZ_OK)\r\n\t\tprintf(\"In LzmaUncompress: return error (%d)\\n\", res);\r\n\treturn res;\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/lzmainterface.h",
    "content": "/* Modifications were made by Cisco Systems, Inc. on or before Thu Feb 16 11:28:44 PST 2012 */\n/*\n * squashfs with lzma compression\n *\n * Copyright (C) 2008, Broadcom Corporation\n * All Rights Reserved.\n * \n * THIS SOFTWARE IS OFFERED \"AS IS\", AND BROADCOM GRANTS NO WARRANTIES OF ANY\n * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM\n * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.\n *\n * $Id: sqlzma.h,v 1.3 2009/03/10 08:42:14 Exp $\n */\n#ifndef __lzmainterface_h__\n#define __lzmainterface_h__\n\n#ifndef __KERNEL__\n#include <stdlib.h>\n#include <string.h>\n#endif\n\n/* detect the compression method automatically by the first byte of compressed data.*/\n#define is_lzma(p)\t(p == 0x5d)\n\nint LzmaUncompress(char *dst, unsigned long * dstlen, char *src, int srclen);\nint LzmaCompress(char *in_data, int in_size, char *out_data, int out_size, unsigned long *total_out);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/mksquashfs.c",
    "content": "/* Modifications were made by Cisco Systems, Inc. on or before Thu Feb 16 11:28:44 PST 2012 */\n/*\r\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\r\n *\r\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\r\n * Phillip Lougher <phillip@lougher.demon.co.uk>\r\n *\r\n * This program is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU General Public License\r\n * as published by the Free Software Foundation; either version 2,\r\n * or (at your option) any later version.\r\n *\r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n * GNU General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU General Public License\r\n * along with this program; if not, write to the Free Software\r\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r\n *\r\n * mksquashfs.c\r\n */\r\n\r\n#define FALSE 0\r\n#define TRUE 1\r\n\r\n#include <pwd.h>\r\n#include <grp.h>\r\n#include <time.h>\r\n#include <unistd.h>\r\n#include <stdio.h>\r\n#include <sys/time.h>\r\n#include <sys/types.h>\r\n#include <sys/stat.h>\r\n#include <fcntl.h>\r\n#include <errno.h>\r\n#include <dirent.h>\r\n#include <string.h>\r\n#include <zlib.h>\r\n#include <stdlib.h>\r\n#include <signal.h>\r\n#include <setjmp.h>\r\n#include <sys/ioctl.h>\r\n#include <sys/types.h>\r\n#include <sys/mman.h>\r\n#include <pthread.h>\r\n#include <math.h>\r\n#include <regex.h>\r\n#include <fnmatch.h>\r\n\r\n#include \"LzmaEnc.h\"\r\n#include \"Alloc.h\"\r\n#include \"lzmainterface.h\"\r\n\r\n\r\n\r\n#ifndef linux\r\n#define __BYTE_ORDER BYTE_ORDER\r\n#define __BIG_ENDIAN BIG_ENDIAN\r\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\r\n#include <sys/sysctl.h>\r\n#else\r\n#include <endian.h>\r\n#include <sys/sysinfo.h>\r\n#endif\r\n\r\n//#include <linux/squashfs_fs.h>\n#include \"squashfs_fs.h\"\r\n#include \"mksquashfs.h\"\r\n#include \"global.h\"\r\n#include \"sort.h\"\r\n\r\n#ifdef SQUASHFS_TRACE\r\n#define TRACE(s, args...)\tdo { \\\r\n\t\t\t\t\tif(progress_enabled) \\\r\n\t\t\t\t\t\tprintf(\"\\n\"); \\\r\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\r\n\t\t\t\t} while(0)\r\n#else\r\n#define TRACE(s, args...)\r\n#endif\r\n\r\n#define INFO(s, args...)\tdo {\\\r\n\t\t\t\t\t if(!silent)\\\r\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\r\n\t\t\t\t} while(0)\r\n#define ERROR(s, args...)\tdo {\\\r\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\r\n\t\t\t\t\tif(progress_enabled) \\\r\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\r\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\r\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\r\n\t\t\t\t} while(0)\r\n#define EXIT_MKSQUASHFS()\tdo {\\\r\n\t\t\t\t\tif(restore)\\\r\n\t\t\t\t\t\trestorefs();\\\r\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\r\n\t\t\t\t\t\tunlink(destination_file);\\\r\n\t\t\t\t\texit(1);\\\r\n\t\t\t\t} while(0)\r\n#define BAD_ERROR(s, args...)\tdo {\\\r\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\r\n\t\t\t\t\tif(progress_enabled) \\\r\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\r\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\r\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\r\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\r\n\t\t\t\t} while(0)\r\n\r\nint delete = FALSE;\r\nint fd;\r\nint cur_uncompressed = 0, estimated_uncompressed = 0;\r\nint columns;\r\n\r\nint gLzmaEnable=1;\r\n\r\n/* filesystem flags for building */\r\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\r\nint noI = 0, noD = 0, check_data = 0;\r\nint swap, silent = TRUE;\r\nlong long global_uid = -1, global_gid = -1;\r\nint exportable = TRUE;\r\nint progress = TRUE;\r\nint progress_enabled = FALSE;\r\nint sparse_files = TRUE;\r\nint old_exclude = TRUE;\r\nint use_regex = FALSE;\r\n\r\n/* superblock attributes */\r\nint block_size = SQUASHFS_FILE_SIZE, block_log;\r\nunsigned short uid_count = 0, guid_count = 0;\r\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\r\nint block_offset;\r\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\r\n\r\n/* write position within data section */\r\nlong long bytes = 0, total_bytes = 0;\r\n\r\n/* in memory directory table - possibly compressed */\r\nchar *directory_table = NULL;\r\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\r\n\r\n/* cached directory table */\r\nchar *directory_data_cache = NULL;\r\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\r\n\r\n/* in memory inode table - possibly compressed */\r\nchar *inode_table = NULL;\r\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\r\n\r\n/* cached inode table */\r\nchar *data_cache = NULL;\r\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\r\n\r\n/* inode lookup table */\r\nsquashfs_inode *inode_lookup_table = NULL;\r\n\r\n/* in memory directory data */\r\n#define I_COUNT_SIZE\t\t128\r\n#define DIR_ENTRIES\t\t32\r\n#define INODE_HASH_SIZE\t\t65536\r\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\r\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\r\n\r\nstruct cached_dir_index {\r\n\tsquashfs_dir_index\tindex;\r\n\tchar\t\t\t*name;\r\n};\r\n\r\nstruct directory {\r\n\tunsigned int\t\tstart_block;\r\n\tunsigned int\t\tsize;\r\n\tunsigned char\t\t*buff;\r\n\tunsigned char\t\t*p;\r\n\tunsigned int\t\tentry_count;\r\n\tunsigned char\t\t*entry_count_p;\r\n\tunsigned int\t\ti_count;\r\n\tunsigned int\t\ti_size;\r\n\tstruct cached_dir_index\t*index;\r\n\tunsigned char\t\t*index_count_p;\r\n\tunsigned int\t\tinode_number;\r\n};\r\n\r\nstruct inode_info *inode_info[INODE_HASH_SIZE];\r\n\r\n/* hash tables used to do fast duplicate searches in duplicate check */\r\nstruct file_info *dupl[65536];\r\nint dup_files = 0;\r\n\r\n/* exclude file handling */\r\n/* list of exclude dirs/files */\r\nstruct exclude_info {\r\n\tdev_t\t\t\tst_dev;\r\n\tino_t\t\t\tst_ino;\r\n};\r\n\r\n#define EXCLUDE_SIZE 8192\r\nint exclude = 0;\r\nstruct exclude_info *exclude_paths = NULL;\r\nint old_excluded(char *filename, struct stat *buf);\r\n\r\nstruct path_entry {\r\n\tchar *name;\r\n\tregex_t *preg;\r\n\tstruct pathname *paths;\r\n};\r\n\r\nstruct pathname {\r\n\tint names;\r\n\tstruct path_entry *name;\r\n};\r\n\r\nstruct pathnames {\r\n\tint count;\r\n\tstruct pathname *path[0];\r\n};\r\n#define PATHS_ALLOC_SIZE 10\r\n\r\nstruct pathnames *paths = NULL;\r\nstruct pathname *path = NULL;\r\nstruct pathname *stickypath = NULL;\r\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\r\n\r\n/* fragment block data structures */\r\nint fragments = 0;\r\nstruct file_buffer *fragment_data = NULL;\r\nint fragment_size = 0;\r\n\r\nstruct fragment {\r\n\tunsigned int\t\tindex;\r\n\tint\t\t\toffset;\r\n\tint\t\t\tsize;\r\n};\r\n\r\n#define FRAG_SIZE 32768\r\n#define FRAG_INDEX (1LL << 32)\r\n\r\nsquashfs_fragment_entry *fragment_table = NULL;\r\nint fragments_outstanding = 0;\r\n\r\n/* current inode number for directories and non directories */\r\nunsigned int dir_inode_no = 1;\r\nunsigned int inode_no = 0;\r\nunsigned int root_inode_number = 0;\r\n\r\n/* list of source dirs/files */\r\nint source = 0;\r\nchar **source_path;\r\n\r\n/* list of root directory entries read from original filesystem */\r\nint old_root_entries = 0;\r\nstruct old_root_entry_info {\r\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\r\n\tsquashfs_inode\t\tinode;\r\n\tint\t\t\ttype;\r\n\tint\t\t\tinode_number;\r\n};\r\nstruct old_root_entry_info *old_root_entry;\r\n\r\n/* in memory file info */\r\nstruct file_info {\r\n\tlong long\t\tfile_size;\r\n\tlong long\t\tbytes;\r\n\tunsigned short\t\tchecksum;\r\n\tunsigned short\t\tfragment_checksum;\r\n\tlong long\t\tstart;\r\n\tunsigned int\t\t*block_list;\r\n\tstruct file_info\t*next;\r\n\tstruct fragment\t\t*fragment;\r\n\tchar\t\t\tchecksum_flag;\r\n};\r\n\r\n/* count of how many times SIGINT or SIGQUIT has been sent */\r\nint interrupted = 0;\r\n\r\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\r\njmp_buf env;\r\nchar *sdata_cache, *sdirectory_data_cache, *sdirectory_compressed;\r\n\r\nlong long sbytes, stotal_bytes;\r\n\r\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\r\n\tsdirectory_cache_bytes, sdirectory_compressed_bytes, suid_count, sguid_count,\r\n\tstotal_inode_bytes, stotal_directory_bytes,\r\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\r\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\r\nint sfragments;\r\nint restore = 0;\r\nint threads;\r\n\r\n/* flag whether destination file is a block device */\r\nint block_device = 0;\r\n\r\n/* flag indicating whether files are sorted using sort list(s) */\r\nint sorted = 0;\r\n\r\n/* save destination file name for deleting on error */\r\nchar *destination_file = NULL;\r\n\r\n/* recovery file for abnormal exit on appending */\r\nchar recovery_file[1024] = \"\";\r\nint recover = TRUE;\r\n\r\n/* struct describing a cache entry passed between threads */\r\nstruct file_buffer {\r\n\tstruct cache *cache;\r\n\tint keep;\r\n\tlong long file_size;\r\n\tlong long index;\r\n\tlong long block;\r\n\tlong long sequence;\r\n\tint size;\r\n\tint c_byte;\r\n\tint used;\r\n\tint\tfragment;\r\n\tint error;\r\n\tstruct file_buffer *hash_next;\r\n\tstruct file_buffer *hash_prev;\r\n\tstruct file_buffer *free_next;\r\n\tstruct file_buffer *free_prev;\r\n\tstruct file_buffer *next;\r\n\tchar data[0];\r\n};\r\n\r\n\r\n/* struct describing queues used to pass data between threads */\r\nstruct queue {\r\n\tint\t\t\tsize;\r\n\tint\t\t\treadp;\r\n\tint\t\t\twritep;\r\n\tpthread_mutex_t\t\tmutex;\r\n\tpthread_cond_t\t\tempty;\r\n\tpthread_cond_t\t\tfull;\r\n\tvoid\t\t\t**data;\r\n};\r\n\r\n/* describes the list of blocks in a file which is a possible\r\n   duplicate.  For each block, it indicates whether the block is\r\n   in memory or on disk */\r\nstruct buffer_list {\r\n\tlong long start;\r\n\tint size;\r\n\tstruct file_buffer *read_buffer;\r\n};\r\n\r\nstruct cache *reader_buffer, *writer_buffer, *fragment_buffer;\r\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\r\npthread_t *thread, *deflator_thread, *frag_deflator_thread, progress_thread;\r\npthread_mutex_t\tfragment_mutex;\r\npthread_cond_t fragment_waiting;\r\npthread_mutex_t\tpos_mutex;\r\npthread_mutex_t progress_mutex;\r\npthread_cond_t progress_wait;\r\nint rotate = 0;\r\n\r\n/* user options that control parallelisation */\r\nint processors = -1;\r\n/* default size of output buffer in Mbytes */\r\n#define WRITER_BUFFER_DEFAULT 512\r\n/* default size of input buffer in Mbytes */\r\n#define READER_BUFFER_DEFAULT 64\r\n/* default size of fragment buffer in Mbytes */\r\n#define FRAGMENT_BUFFER_DEFAULT 64\r\nint writer_buffer_size;\r\nint reader_buffer_size;\r\nint fragment_buffer_size;\r\n\r\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\r\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\r\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\r\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\r\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\r\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\r\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\r\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\r\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\r\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\r\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\r\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\r\nextern int read_sort_file(char *filename, int source, char *source_path[]);\r\nextern void sort_files_and_write(struct dir_info *dir);\r\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\r\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *, char *, struct dir_info *));\r\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\r\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\r\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\r\nextern struct priority_entry *priority_list[65536];\r\nvoid progress_bar(long long current, long long max, int columns);\r\n\r\n\r\nstruct queue *queue_init(int size)\r\n{\r\n\tstruct queue *queue = malloc(sizeof(struct queue));\r\n\r\n\tif(queue == NULL)\r\n\t\treturn NULL;\r\n\r\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\r\n\t\tfree(queue);\r\n\t\treturn NULL;\r\n\t}\r\n\r\n\tqueue->size = size + 1;\r\n\tqueue->readp = queue->writep = 0;\r\n\tpthread_mutex_init(&queue->mutex, NULL);\r\n\tpthread_cond_init(&queue->empty, NULL);\r\n\tpthread_cond_init(&queue->full, NULL);\r\n\r\n\treturn queue;\r\n}\r\n\r\n\r\nvoid queue_put(struct queue *queue, void *data)\r\n{\r\n\tint nextp;\r\n\r\n\tpthread_mutex_lock(&queue->mutex);\r\n\r\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\r\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\r\n\r\n\tqueue->data[queue->writep] = data;\r\n\tqueue->writep = nextp;\r\n\tpthread_cond_signal(&queue->empty);\r\n\tpthread_mutex_unlock(&queue->mutex);\r\n}\r\n\r\n\r\nvoid *queue_get(struct queue *queue)\r\n{\r\n\tvoid *data;\r\n\tpthread_mutex_lock(&queue->mutex);\r\n\r\n\twhile(queue->readp == queue->writep)\r\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\r\n\r\n\tdata = queue->data[queue->readp];\r\n\tqueue->readp = (queue->readp + 1) % queue->size;\r\n\tpthread_cond_signal(&queue->full);\r\n\tpthread_mutex_unlock(&queue->mutex);\r\n\r\n\treturn data;\r\n}\r\n\r\n\r\n/* Cache status struct.  Caches are used to keep\r\n  track of memory buffers passed between different threads */\r\nstruct cache {\r\n\tint\tmax_buffers;\r\n\tint\tcount;\r\n\tint\tbuffer_size;\r\n\tpthread_mutex_t\tmutex;\r\n\tpthread_cond_t wait_for_free;\r\n\tstruct file_buffer *free_list;\r\n\tstruct file_buffer *hash_table[65536];\r\n};\r\n\r\n\r\n#define INSERT_LIST(NAME, TYPE) \\\r\nvoid insert_##NAME##_list(TYPE **list, TYPE *entry) { \\\r\n\tif(*list) { \\\r\n\t\tentry->NAME##_next = *list; \\\r\n\t\tentry->NAME##_prev = (*list)->NAME##_prev; \\\r\n\t\t(*list)->NAME##_prev->NAME##_next = entry; \\\r\n\t\t(*list)->NAME##_prev = entry; \\\r\n\t} else { \\\r\n\t\t*list = entry; \\\r\n\t\tentry->NAME##_prev = entry->NAME##_next = entry; \\\r\n\t} \\\r\n}\r\n\r\n\r\n#define REMOVE_LIST(NAME, TYPE) \\\r\nvoid remove_##NAME##_list(TYPE **list, TYPE *entry) { \\\r\n\tif(entry->NAME##_prev == entry && entry->NAME##_next == entry) { \\\r\n\t\t/* only this entry in the list */ \\\r\n\t\t*list = NULL; \\\r\n\t} else if(entry->NAME##_prev != NULL && entry->NAME##_next != NULL) { \\\r\n\t\t/* more than one entry in the list */ \\\r\n\t\tentry->NAME##_next->NAME##_prev = entry->NAME##_prev; \\\r\n\t\tentry->NAME##_prev->NAME##_next = entry->NAME##_next; \\\r\n\t\tif(*list == entry) \\\r\n\t\t\t*list = entry->NAME##_next; \\\r\n\t} \\\r\n\tentry->NAME##_prev = entry->NAME##_next = NULL; \\\r\n}\r\n\r\n\r\n#define CALCULATE_HASH(start)\t(start & 0xffff) \\\r\n\r\n\r\n/* Called with the cache mutex held */\r\nvoid insert_hash_table(struct cache *cache, struct file_buffer *entry)\r\n{\r\n\tint hash = CALCULATE_HASH(entry->index);\r\n\r\n\tentry->hash_next = cache->hash_table[hash];\r\n\tcache->hash_table[hash] = entry;\r\n\tentry->hash_prev = NULL;\r\n\tif(entry->hash_next)\r\n\t\tentry->hash_next->hash_prev = entry;\r\n}\r\n\r\n\r\n/* Called with the cache mutex held */\r\nvoid remove_hash_table(struct cache *cache, struct file_buffer *entry)\r\n{\r\n\tif(entry->hash_prev)\r\n\t\tentry->hash_prev->hash_next = entry->hash_next;\r\n\telse\r\n\t\tcache->hash_table[CALCULATE_HASH(entry->index)] = entry->hash_next;\r\n\tif(entry->hash_next)\r\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\r\n\r\n\tentry->hash_prev = entry->hash_next = NULL;\r\n}\r\n\r\n\r\n/* Called with the cache mutex held */\r\nINSERT_LIST(free, struct file_buffer)\r\n\r\n/* Called with the cache mutex held */\r\nREMOVE_LIST(free, struct file_buffer)\r\n\r\n\r\nstruct cache *cache_init(int buffer_size, int max_buffers)\r\n{\r\n\tstruct cache *cache = malloc(sizeof(struct cache));\r\n\r\n\tif(cache == NULL)\r\n\t\treturn NULL;\r\n\r\n\tcache->max_buffers = max_buffers;\r\n\tcache->buffer_size = buffer_size;\r\n\tcache->count = 0;\r\n\tcache->free_list = NULL;\r\n\tmemset(cache->hash_table, 0, sizeof(struct file_buffer *) * 65536);\r\n\tpthread_mutex_init(&cache->mutex, NULL);\r\n\tpthread_cond_init(&cache->wait_for_free, NULL);\r\n\r\n\treturn cache;\r\n}\r\n\r\n\r\nstruct file_buffer *cache_lookup(struct cache *cache, long long index)\r\n{\r\n\t/* Lookup block in the cache, if found return with usage count\r\n \t * incremented, if not found return NULL */\r\n\tint hash = CALCULATE_HASH(index);\r\n\tstruct file_buffer *entry;\r\n\r\n\tpthread_mutex_lock(&cache->mutex);\r\n\r\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\r\n\t\tif(entry->index == index)\r\n\t\t\tbreak;\r\n\r\n\tif(entry) {\r\n\t\t/* found the block in the cache, increment used count and\r\n \t\t * if necessary remove from free list so it won't disappear\r\n \t\t */\r\n\t\tentry->used ++;\r\n\t\tremove_free_list(&cache->free_list, entry);\r\n\t}\r\n\r\n\tpthread_mutex_unlock(&cache->mutex);\r\n\r\n\treturn entry;\r\n}\r\n\r\n\r\n#define GET_FREELIST 1\r\n\r\nstruct file_buffer *cache_get(struct cache *cache, long long index, int keep)\r\n{\r\n\t/* Get a free block out of the cache indexed on index. */\r\n\tstruct file_buffer *entry;\r\n\r\n\tpthread_mutex_lock(&cache->mutex);\r\n\r\n\twhile(1) {\r\n\t\t/* first try to get a block from the free list */\r\n#ifdef GET_FREELIST\r\n\t\tif(cache->free_list) {\r\n\t\t\t/* a block on the free_list is a \"keep\" block */\r\n\t\t\tentry = cache->free_list;\r\n\t\t\tremove_free_list(&cache->free_list, entry);\r\n\t\t\tremove_hash_table(cache, entry);\r\n\t\t\tbreak;\r\n\t\t} else\r\n#endif\r\n\t\tif(cache->count < cache->max_buffers) {\r\n\t\t\t/* next try to allocate new block */\r\n\t\t\tentry = malloc(sizeof(struct file_buffer) + cache->buffer_size);\r\n\t\t\tif(entry == NULL)\r\n\t\t\t\tgoto failed;\r\n\t\t\tentry->cache = cache;\r\n\t\t\tentry->free_prev = entry->free_next = NULL;\r\n\t\t\tcache->count ++;\r\n\t\t\tbreak;\r\n\t\t} else\r\n#ifndef GET_FREELIST\r\n\t\tif(cache->free_list) {\r\n\t\t\t/* a block on the free_list is a \"keep\" block */\r\n\t\t\tentry = cache->free_list;\r\n\t\t\tremove_free_list(&cache->free_list, entry);\r\n\t\t\tremove_hash_table(cache, entry);\r\n\t\t\tbreak;\r\n\t\t}\r\n#endif\r\n\t\t\t/* wait for a block */\r\n\t\t\tpthread_cond_wait(&cache->wait_for_free, &cache->mutex);\r\n\t}\r\n\r\n\t/* initialise block and if a keep block insert into the hash table */\r\n\tentry->used = 1;\r\n\tentry->error = FALSE;\r\n\tentry->keep = keep;\r\n\tif(keep) {\r\n\t\tentry->index = index;\r\n\t\tinsert_hash_table(cache, entry);\r\n\t}\r\n\tpthread_mutex_unlock(&cache->mutex);\r\n\r\n\treturn entry;\r\n\r\nfailed:\r\n\tpthread_mutex_unlock(&cache->mutex);\r\n\treturn NULL;\r\n}\r\n\r\n\r\nvoid cache_rehash(struct file_buffer *entry, long long index)\r\n{\r\n\tstruct cache *cache = entry->cache;\r\n\r\n\tpthread_mutex_lock(&cache->mutex);\r\n\tif(entry->keep)\r\n\t\tremove_hash_table(cache, entry);\r\n\tentry->keep = TRUE;\r\n\tentry->index = index;\r\n\tinsert_hash_table(cache, entry);\r\n\tpthread_mutex_unlock(&cache->mutex);\r\n}\r\n\r\n\r\nvoid cache_block_put(struct file_buffer *entry)\r\n{\r\n\tstruct cache *cache;\r\n\r\n\t/* finished with this cache entry, once the usage count reaches zero it\r\n \t * can be reused and if a keep block put onto the free list.  As keep\r\n \t * blocks remain accessible via the hash table they can be found getting a\r\n \t * new lease of life before they are reused. */\r\n\r\n\tif(entry == NULL)\r\n\t\treturn;\r\n\r\n\tcache = entry->cache;\r\n\r\n\tpthread_mutex_lock(&cache->mutex);\r\n\r\n\tentry->used --;\r\n\tif(entry->used == 0) {\r\n\t\tif(entry->keep)\r\n\t\t\tinsert_free_list(&cache->free_list, entry);\r\n\t\telse {\r\n\t\t\tfree(entry);\r\n\t\t\tcache->count --;\r\n\t\t}\r\n\r\n\t\t/* One or more threads may be waiting on this block */\r\n\t\tpthread_cond_signal(&cache->wait_for_free);\r\n\t}\r\n\r\n\tpthread_mutex_unlock(&cache->mutex);\r\n}\r\n\r\n\r\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\r\n\r\n\r\ninline void inc_progress_bar()\r\n{\r\n\tcur_uncompressed ++;\r\n}\r\n\r\n\r\ninline void update_progress_bar()\r\n{\r\n\tpthread_mutex_lock(&progress_mutex);\r\n\tpthread_cond_signal(&progress_wait);\r\n\tpthread_mutex_unlock(&progress_mutex);\r\n}\r\n\r\n\r\ninline void waitforthread(int i)\r\n{\r\n\tTRACE(\"Waiting for thread %d\\n\", i);\r\n\twhile(thread[i] != 0)\r\n\t\tsched_yield();\r\n}\r\n\r\n\r\nvoid restorefs()\r\n{\r\n\tint i;\r\n\r\n\tif(thread == NULL || thread[0] == 0)\r\n\t\treturn;\r\n\r\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\r\n\r\n\tfor(i = 0; i < 2 + processors * 2; i++)\r\n\t\tif(thread[i])\r\n\t\t\tpthread_kill(thread[i], SIGUSR1);\r\n\tfor(i = 0; i < 2 + processors * 2; i++)\r\n\t\twaitforthread(i);\r\n\tTRACE(\"All threads in signal handler\\n\");\r\n\tbytes = sbytes;\r\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\r\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\r\n\tinode_bytes = sinode_bytes;\r\n\tdirectory_bytes = sdirectory_bytes;\r\n\tmemcpy(directory_table + directory_bytes, sdirectory_compressed, sdirectory_compressed_bytes);\r\n\tdirectory_bytes += sdirectory_compressed_bytes;\r\n\tuid_count = suid_count;\r\n\tguid_count = sguid_count;\r\n\ttotal_bytes = stotal_bytes;\r\n\ttotal_inode_bytes = stotal_inode_bytes;\r\n\ttotal_directory_bytes = stotal_directory_bytes;\r\n\tinode_count = sinode_count;\r\n\tfile_count = sfile_count;\r\n\tsym_count = ssym_count;\r\n\tdev_count = sdev_count;\r\n\tdir_count = sdir_count;\r\n\tfifo_count = sfifo_count;\r\n\tsock_count = ssock_count;\r\n\tdup_files = sdup_files;\r\n\tfragments = sfragments;\r\n\tfragment_size = 0;\r\n\tlongjmp(env, 1);\r\n}\r\n\r\n\r\nvoid sighandler()\r\n{\r\n\tif(++interrupted > 2)\r\n\t\treturn;\r\n\tif(interrupted == 2)\r\n\t\trestorefs();\r\n\telse {\r\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\r\n\t\tERROR(\"Interrupt again to quit\\n\");\r\n\t}\r\n}\r\n\r\n\r\nvoid sighandler2()\r\n{\r\n\tEXIT_MKSQUASHFS();\r\n}\r\n\r\n\r\nvoid sigusr1_handler()\r\n{\r\n\tint i;\r\n\tsigset_t sigmask;\r\n\tpthread_t thread_id = pthread_self();\r\n\r\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\r\n\tthread[i] = (pthread_t) 0;\r\n\r\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, &thread_id);\r\n\r\n\tsigemptyset(&sigmask);\r\n\tsigaddset(&sigmask, SIGINT);\r\n\tsigaddset(&sigmask, SIGQUIT);\r\n\tsigaddset(&sigmask, SIGUSR1);\r\n\twhile(1) {\r\n\t\tsigsuspend(&sigmask);\r\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\r\n\t}\r\n}\r\n\r\n\r\nvoid sigwinch_handler()\r\n{\r\n\tstruct winsize winsize;\r\n\r\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\r\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\r\n\t\tcolumns = 80;\r\n\t} else\r\n\t\tcolumns = winsize.ws_col;\r\n}\r\n\r\n\r\nvoid sigalrm_handler()\r\n{\r\n\trotate = (rotate + 1) % 4;\r\n}\r\n\r\n\r\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\r\n{\r\n\tunsigned long c_byte;\r\n\tunsigned int res;\r\n\tz_stream *stream = *strm;\r\n\r\n\tif(uncompressed)\r\n\t\tgoto notcompressed;\r\n\r\n    if(!gLzmaEnable ){\r\n    \tif(stream == NULL) {\r\n    \t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\r\n    \t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\r\n\r\n    \t\tstream->zalloc = Z_NULL;\r\n    \t\tstream->zfree = Z_NULL;\r\n    \t\tstream->opaque = 0;\r\n\r\n    \t\tif((res = deflateInit(stream, 9)) != Z_OK) {\r\n    \t\t\tif(res == Z_MEM_ERROR)\r\n    \t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\r\n    \t\t\telse if(res == Z_STREAM_ERROR)\r\n    \t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\r\n    \t\t\telse if(res == Z_VERSION_ERROR)\r\n    \t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\r\n    \t\t\telse\r\n    \t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\r\n    \t\t}\r\n    \t} else if((res = deflateReset(stream)) != Z_OK) {\r\n    \t\tif(res == Z_STREAM_ERROR)\r\n    \t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\r\n    \t\telse\r\n    \t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\r\n    \t}\r\n\r\n    \tstream->next_in = (unsigned char *) s;\r\n    \tstream->avail_in = size;\r\n    \tstream->next_out = (unsigned char *) d;\r\n    \tstream->avail_out = block_size;\r\n\r\n    \tres = deflate(stream, Z_FINISH);\r\n    \tif(res != Z_STREAM_END && res != Z_OK) {\r\n    \t\tif(res == Z_STREAM_ERROR)\r\n    \t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\r\n    \t\telse if(res == Z_BUF_ERROR)\r\n    \t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\\n\");\r\n    \t\telse\r\n    \t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\r\n    \t}\r\n\r\n    \tc_byte = stream->total_out;\r\n\r\n    \tif(res != Z_STREAM_END || c_byte >= size) {\r\n    notcompressed:\r\n    \t\tmemcpy(d, s, size);\r\n    \t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\r\n    \t}\r\n    }else {/*Start:Added @2010-02-25 to suporrt lzma*/\r\n\t\tres = LzmaCompress(s, size, d, block_size, &c_byte);\r\n\t    if (res) {\r\n\t\t\tmemcpy(d, s, size);\r\n\t\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\r\n\t\t}\r\n\t}/*End:Added @2010-02-25 to suporrt lzma*/\r\n    \r\n\treturn (unsigned int) c_byte;\r\n}\r\n\r\n\r\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\r\n{\r\n\tstatic z_stream *stream = NULL;\r\n\r\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\r\n}\r\n\r\n\r\nsquashfs_base_inode_header *get_inode(int req_size)\r\n{\r\n\tint data_space;\r\n\tunsigned short c_byte;\r\n\r\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\r\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\r\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\r\n\t\t\t\t\t== NULL) {\r\n\t\t\t\tgoto failed;\r\n\t\t\t}\r\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\r\n\t\t}\r\n\r\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\r\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\r\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\r\n\t\tif(check_data)\r\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\r\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\r\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\r\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\r\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\r\n\t}\r\n\r\n\tdata_space = (cache_size - cache_bytes);\r\n\tif(data_space < req_size) {\r\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\r\n\r\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\r\n\t\t\t\tgoto failed;\r\n\t\t\t}\r\n\t\t\tcache_size += realloc_size;\r\n\t}\r\n\r\n\tcache_bytes += req_size;\r\n\r\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\r\n\r\nfailed:\r\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\r\n}\r\n\r\n\r\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\r\n{\r\n\toff_t off = byte;\r\n\r\n\tpthread_mutex_lock(&pos_mutex);\r\n\tif(lseek(fd, off, SEEK_SET) == -1)\r\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\", strerror(errno));\r\n\r\n\tif(read(fd, buff, bytes) == -1)\r\n\t\tBAD_ERROR(\"Read on destination failed because %s\\n\", strerror(errno));\r\n\tpthread_mutex_unlock(&pos_mutex);\r\n}\r\n\r\n\r\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\r\n{\r\n\toff_t off = byte;\r\n\r\n\tif(interrupted < 2)\r\n\t\tpthread_mutex_lock(&pos_mutex);\r\n\r\n\tif(lseek(fd, off, SEEK_SET) == -1)\r\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\", strerror(errno));\r\n\r\n\tif(write(fd, buff, bytes) == -1)\r\n\t\tBAD_ERROR(\"Write on destination failed because %s\\n\", strerror(errno));\r\n\t\r\n\tif(interrupted < 2)\r\n\t\tpthread_mutex_unlock(&pos_mutex);\r\n}\r\n\r\n\r\nlong long write_inodes()\r\n{\r\n\tunsigned short c_byte;\r\n\tint avail_bytes;\r\n\tchar *datap = data_cache;\r\n\tlong long start_bytes = bytes;\r\n\r\n\twhile(cache_bytes) {\r\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\r\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\r\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\r\n\t\t\t}\r\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\r\n\t\t}\r\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\r\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\r\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \r\n\t\tif(check_data)\r\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\r\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\r\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\r\n\t\tdatap += avail_bytes;\r\n\t\tcache_bytes -= avail_bytes;\r\n\t}\r\n\r\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\r\n\tbytes += inode_bytes;\r\n\r\n\treturn start_bytes;\r\n}\r\n\r\n\r\nlong long write_directories()\r\n{\r\n\tunsigned short c_byte;\r\n\tint avail_bytes;\r\n\tchar *directoryp = directory_data_cache;\r\n\tlong long start_bytes = bytes;\r\n\r\n\twhile(directory_cache_bytes) {\r\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\r\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\r\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\r\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\r\n\t\t\t}\r\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\r\n\t\t}\r\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\r\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\r\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes, c_byte);\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\r\n\t\tif(check_data)\r\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\r\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\r\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\r\n\t\tdirectoryp += avail_bytes;\r\n\t\tdirectory_cache_bytes -= avail_bytes;\r\n\t}\r\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\r\n\tbytes += directory_bytes;\r\n\r\n\treturn start_bytes;\r\n}\r\n\r\n\r\nunsigned int get_uid(squashfs_uid uid)\r\n{\r\n\tint i;\r\n\r\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\r\n\tif(i == uid_count) {\r\n\t\tif(uid_count == SQUASHFS_UIDS) {\r\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\r\n\t\t\ti = 0;\r\n\t\t} else\r\n\t\t\tuids[uid_count++] = uid;\r\n\t}\r\n\r\n\treturn i;\r\n}\r\n\r\n\r\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\r\n{\r\n\tint i;\r\n\r\n\tif(uid == guid)\r\n\t\treturn SQUASHFS_GUIDS;\r\n\r\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\r\n\tif(i == guid_count) {\r\n\t\tif(guid_count == SQUASHFS_GUIDS) {\r\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\r\n\t\t\treturn SQUASHFS_GUIDS;\r\n\t\t} else\r\n\t\t\tguids[guid_count++] = guid;\r\n\t}\r\n\r\n\treturn i;\r\n}\r\n\r\n\r\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\r\n{\r\n\tstruct stat *buf = &dir_ent->inode->buf;\r\n\tsquashfs_inode_header inode_header;\r\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\r\n\tchar *filename = dir_ent->pathname;\r\n\tint nlink = dir_ent->inode->nlink;\r\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\r\n\r\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\r\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\r\n\tbase->inode_type = type;\r\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\r\n\tbase->mtime = buf->st_mtime;\r\n\tbase->inode_number = inode_number;\r\n\r\n\tif(type == SQUASHFS_FILE_TYPE) {\r\n\t\tint i;\r\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\r\n\r\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\r\n\t\tinodep = (squashfs_reg_inode_header *) inode;\r\n\t\treg->file_size = byte_size;\r\n\t\treg->start_block = start_block;\r\n\t\treg->fragment = fragment->index;\r\n\t\treg->offset = fragment->offset;\r\n\t\tif(!swap) {\r\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\r\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\r\n\t\t} else {\r\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\r\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\r\n\t\t}\r\n\t\tTRACE(\"File inode, file_size %lld, start_block 0x%llx, blocks %d, fragment %d, offset %d, size %d\\n\", byte_size,\r\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\r\n\t\tfor(i = 0; i < offset; i++)\r\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\r\n\t}\r\n\telse if(type == SQUASHFS_LREG_TYPE) {\r\n\t\tint i;\r\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\r\n\r\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\r\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\r\n\t\treg->nlink = nlink;\r\n\t\treg->file_size = byte_size;\r\n\t\treg->start_block = start_block;\r\n\t\treg->fragment = fragment->index;\r\n\t\treg->offset = fragment->offset;\r\n\t\tif(!swap) {\r\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\r\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\r\n\t\t} else {\r\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\r\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\r\n\t\t}\r\n\t\tTRACE(\"Long file inode, file_size %lld, start_block 0x%llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\r\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\r\n\t\tfor(i = 0; i < offset; i++)\r\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\r\n\t}\r\n\telse if(type == SQUASHFS_LDIR_TYPE) {\r\n\t\tint i;\r\n\t\tunsigned char *p;\r\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\r\n\t\tstruct cached_dir_index *index = dir_in->index;\r\n\t\tunsigned int i_count = dir_in->i_count;\r\n\t\tunsigned int i_size = dir_in->i_size;\r\n\r\n\t\tif(byte_size >= 1 << 27)\r\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\r\n\r\n\t\tinode = get_inode(sizeof(*dir) + i_size);\r\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\r\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\r\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\r\n\t\tdir->file_size = byte_size;\r\n\t\tdir->offset = offset;\r\n\t\tdir->start_block = start_block;\r\n\t\tdir->i_count = i_count;\r\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\r\n\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\r\n\t\tp = (unsigned char *) inodep->index;\r\n\t\tfor(i = 0; i < i_count; i++) {\r\n\t\t\tif(!swap)\r\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\r\n\t\t\telse\r\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\r\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\r\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\r\n\t\t}\r\n\t\tTRACE(\"Long directory inode, file_size %lld, start_block 0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\r\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\r\n\t}\r\n\telse if(type == SQUASHFS_DIR_TYPE) {\r\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\r\n\r\n\t\tinode = get_inode(sizeof(*dir));\r\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\r\n\t\tdir->file_size = byte_size;\r\n\t\tdir->offset = offset;\r\n\t\tdir->start_block = start_block;\r\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\r\n\t\tTRACE(\"Directory inode, file_size %lld, start_block 0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\r\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\r\n\t}\r\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\r\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\r\n\r\n\t\tinode = get_inode(sizeof(*dev));\r\n\t\tdev->nlink = nlink;\r\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\r\n\t\t\t(minor(buf->st_rdev) & 0xff));\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\r\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\r\n\t}\r\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\r\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\r\n\t\tint byte;\r\n\t\tchar buff[65536];\r\n\r\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\r\n\t\t\tERROR(\"Failed to read symlink %s, creating empty symlink\\n\", filename);\r\n\t\t\tbyte = 0;\r\n\t\t}\r\n\r\n\t\tif(byte == 65536) {\r\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! Creating empty symlink\\n\", filename);\r\n\t\t\tbyte = 0;\r\n\t\t}\r\n\r\n\t\tinode = get_inode(sizeof(*symlink) + byte);\r\n\t\tsymlink->nlink = nlink;\r\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\r\n\t\tsymlink->symlink_size = byte;\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\r\n\t\tstrncpy(inodep->symlink, buff, byte);\r\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\r\n\t}\r\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\r\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\r\n\r\n\t\tinode = get_inode(sizeof(*ipc));\r\n\t\tipc->nlink = nlink;\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\r\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\r\n\t} else\r\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\r\n\r\n\t*i_no = MKINODE(inode);\r\n\tinode_count ++;\r\n\r\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\r\n\r\n\treturn TRUE;\r\n}\r\n\r\n\r\nvoid scan2_init_dir(struct directory *dir)\r\n{\r\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\r\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\r\n\t}\r\n\r\n\tdir->size = SQUASHFS_METADATA_SIZE;\r\n\tdir->p = dir->index_count_p = dir->buff;\r\n\tdir->entry_count = 256;\r\n\tdir->entry_count_p = NULL;\r\n\tdir->index = NULL;\r\n\tdir->i_count = dir->i_size = 0;\r\n}\r\n\r\n\r\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\r\n{\r\n\tunsigned char *buff;\r\n\tsquashfs_dir_entry idir, *idirp;\r\n\tunsigned int start_block = inode >> 16;\r\n\tunsigned int offset = inode & 0xffff;\r\n\tunsigned int size;\r\n\r\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\r\n\t\tsize = SQUASHFS_NAME_LEN;\r\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\r\n\t}\r\n\r\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\r\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\r\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\r\n\t\t}\r\n\r\n\t\tdir->p = (dir->p - dir->buff) + buff;\r\n\t\tif(dir->entry_count_p) \r\n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\r\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\r\n\t\tdir->buff = buff;\r\n\t}\r\n\r\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\r\n\t\tif(dir->entry_count_p) {\r\n\t\t\tsquashfs_dir_header dir_header;\r\n\r\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\r\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\r\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\r\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\r\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\r\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\r\n\t\t\t\tdir->index[dir->i_count++].name = name;\r\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\r\n\t\t\t\tdir->index_count_p = dir->p;\r\n\t\t\t}\r\n\r\n\t\t\tdir_header.count = dir->entry_count - 1;\r\n\t\t\tdir_header.start_block = dir->start_block;\r\n\t\t\tdir_header.inode_number = dir->inode_number;\r\n\t\t\tif(!swap)\r\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\r\n\t\t\telse\r\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\r\n\r\n\t\t}\r\n\r\n\r\n\t\tdir->entry_count_p = dir->p;\r\n\t\tdir->start_block = start_block;\r\n\t\tdir->entry_count = 0;\r\n\t\tdir->inode_number = inode_number;\r\n\t\tdir->p += sizeof(squashfs_dir_header);\r\n\t}\r\n\r\n\tidirp = (squashfs_dir_entry *) dir->p;\r\n\tidir.offset = offset;\r\n\tidir.type = type;\r\n\tidir.size = size - 1;\r\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\r\n\tif(!swap)\r\n\t\tmemcpy(idirp, &idir, sizeof(idir));\r\n\telse\r\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\r\n\tstrncpy(idirp->name, name, size);\r\n\tdir->p += sizeof(squashfs_dir_entry) + size;\r\n\tdir->entry_count ++;\r\n}\r\n\r\n\r\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\r\n{\r\n\tunsigned int dir_size = dir->p - dir->buff;\r\n\tint data_space = (directory_cache_size - directory_cache_bytes);\r\n\tunsigned int directory_block, directory_offset, i_count, index;\r\n\tunsigned short c_byte;\r\n\r\n\tif(data_space < dir_size) {\r\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\r\n\r\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\r\n\t\t\tgoto failed;\r\n\t\t}\r\n\t\tdirectory_cache_size += realloc_size;\r\n\t}\r\n\r\n\tif(dir_size) {\r\n\t\tsquashfs_dir_header dir_header;\r\n\r\n\t\tdir_header.count = dir->entry_count - 1;\r\n\t\tdir_header.start_block = dir->start_block;\r\n\t\tdir_header.inode_number = dir->inode_number;\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\r\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\r\n\t}\r\n\tdirectory_offset = directory_cache_bytes;\r\n\tdirectory_block = directory_bytes;\r\n\tdirectory_cache_bytes += dir_size;\r\n\ti_count = 0;\r\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\r\n\r\n\twhile(1) {\r\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\r\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\r\n\t\tindex += SQUASHFS_METADATA_SIZE;\r\n\r\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\r\n\t\t\tbreak;\r\n\r\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\r\n\t\t\tif((directory_table = (char *) realloc(directory_table,\r\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\r\n\t\t\t\tgoto failed;\r\n\t\t\t}\r\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\r\n\t\t}\r\n\r\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\r\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\r\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes, c_byte);\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\r\n\t\tif(check_data)\r\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\r\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\r\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\r\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\r\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\r\n\t}\r\n\r\n\tif(dir_info->dir_is_ldir)\r\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir);\r\n\telse\r\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL);\r\n\r\n#ifdef SQUASHFS_TRACE\r\n\tif(!swap) {\r\n\t\tunsigned char *dirp;\r\n\t\tint count;\r\n\r\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\r\n\t\tdirp = dir->buff;\r\n\t\twhile(dirp < dir->p) {\r\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\r\n\t\t\tsquashfs_dir_entry idir, *idirp;\r\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\r\n\t\t\tcount = dirh->count + 1;\r\n\t\t\tdirp += sizeof(squashfs_dir_header);\r\n\r\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\r\n\r\n\t\t\twhile(count--) {\r\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\r\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\r\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\r\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\r\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\r\n\t\t\t\t\t\t  idir.offset, idir.type);\r\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n#endif\r\n\tdir_count ++;\r\n\r\n\treturn;\r\n\r\nfailed:\r\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\r\n}\r\n\r\n\r\nstruct file_buffer *get_fragment(struct fragment *fragment)\r\n{\r\n\tsquashfs_fragment_entry *disk_fragment;\r\n\tint size;\r\n\tlong long start_block;\r\n\tstruct file_buffer *buffer, *compressed_buffer;\r\n\r\n\tif(fragment->index == SQUASHFS_INVALID_FRAG)\r\n\t\treturn NULL;\r\n\r\n\tbuffer = cache_lookup(fragment_buffer, fragment->index);\r\n\tif(buffer)\r\n\t\treturn buffer;\r\n\r\n\tcompressed_buffer = cache_lookup(writer_buffer, fragment->index + FRAG_INDEX);\r\n\r\n\tbuffer = cache_get(fragment_buffer, fragment->index, 1);\r\n\r\n\tpthread_mutex_lock(&fragment_mutex);\r\n\tdisk_fragment = &fragment_table[fragment->index];\r\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\r\n\tstart_block = disk_fragment->start_block;\r\n\tpthread_mutex_unlock(&fragment_mutex);\r\n\r\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\r\n\t\tint res;\r\n\t\tunsigned long bytes = block_size;\r\n\t\tchar *data;\r\n\t\tchar cbuffer[block_size];\r\n\r\n\t\tif(compressed_buffer)\r\n\t\t\tdata = compressed_buffer->data;\r\n\t\telse {\r\n\t\t\tdata = cbuffer;\r\n\t\t\tread_bytes(fd, start_block, size, data);\r\n\t\t}\r\n\r\n        if(!gLzmaEnable){\r\n    \t\tif((res = uncompress((unsigned char *) buffer->data, &bytes, (const unsigned char *) data, size)) != Z_OK) {\r\n    \t\t\tif(res == Z_MEM_ERROR)\r\n    \t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\r\n    \t\t\telse if(res == Z_BUF_ERROR)\r\n    \t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\r\n    \t\t\telse\r\n    \t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\r\n    \t\t}\r\n        }else{/*Start:Added @2010-02-25 to suporrt lzma*/\r\n            if((res = LzmaUncompress((unsigned char *) buffer->data, &bytes, (const unsigned char *) data, size)) != SZ_OK)\r\n\t\t\t\tBAD_ERROR(\"LzmaUncompress: error (%d)\\n\", res);              \r\n        }\r\n        /*End:Added @2010-02-25 to suporrt lzma*/\r\n\t} else if(compressed_buffer)\r\n\t\tmemcpy(buffer->data, compressed_buffer->data, size);\r\n\telse\r\n\t\tread_bytes(fd, start_block, size, buffer->data);\r\n\r\n\treturn buffer;\r\n}\r\n\r\n\r\nstruct frag_locked {\r\n\tstruct file_buffer *buffer;\r\n\tint c_byte;\r\n\tint fragment;\r\n\tstruct frag_locked *fragment_prev;\r\n\tstruct frag_locked *fragment_next;\r\n};\r\n\r\nint fragments_locked = FALSE;\r\nstruct frag_locked *frag_locked_list = NULL;\r\n\r\nINSERT_LIST(fragment, struct frag_locked)\r\nREMOVE_LIST(fragment, struct frag_locked)\r\n\r\nint lock_fragments()\r\n{\r\n\tint count;\r\n\tpthread_mutex_lock(&fragment_mutex);\r\n\tfragments_locked = TRUE;\r\n\tcount = fragments_outstanding;\r\n\tpthread_mutex_unlock(&fragment_mutex);\r\n\treturn count;\r\n}\r\n\r\n\r\nvoid unlock_fragments()\r\n{\r\n\tstruct frag_locked *entry;\r\n\tint compressed_size;\r\n\r\n\tpthread_mutex_lock(&fragment_mutex);\r\n\twhile(frag_locked_list) {\r\n\t\tentry = frag_locked_list;\r\n\t\tremove_fragment_list(&frag_locked_list, entry);\r\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->c_byte);\r\n\t\tfragment_table[entry->fragment].size = entry->c_byte;\r\n\t\tfragment_table[entry->fragment].start_block = bytes;\r\n\t\tentry->buffer->block = bytes;\r\n\t\tbytes += compressed_size;\r\n\t\tfragments_outstanding --;\r\n\t\tpthread_mutex_unlock(&fragment_mutex);\r\n\t\tqueue_put(to_writer, entry->buffer);\r\n\t\tpthread_mutex_lock(&fragment_mutex);\r\n\t\tTRACE(\"fragment_locked writing fragment %d, compressed size %d\\n\", entry->fragment, compressed_size);\r\n\t\tfree(entry);\r\n\t}\r\n\tfragments_locked = FALSE;\r\n\tpthread_mutex_unlock(&fragment_mutex);\r\n}\r\n\r\n\r\nint add_pending_fragment(struct file_buffer *write_buffer, int c_byte, int fragment)\r\n{\r\n\tstruct frag_locked *entry = malloc(sizeof(struct frag_locked));\r\n\tif(entry == NULL)\r\n\t\treturn FALSE;\r\n\tentry->buffer = write_buffer;\r\n\tentry->c_byte = c_byte;\r\n\tentry->fragment = fragment;\r\n\tentry->fragment_prev = entry->fragment_next = NULL;\r\n\tpthread_mutex_lock(&fragment_mutex);\r\n\tinsert_fragment_list(&frag_locked_list, entry);\r\n\tpthread_mutex_unlock(&fragment_mutex);\r\n}\r\n\r\n\r\nvoid write_fragment()\r\n{\r\n\tif(fragment_size == 0)\r\n\t\treturn;\r\n\r\n\tpthread_mutex_lock(&fragment_mutex);\r\n\tif(fragments % FRAG_SIZE == 0) {\r\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\r\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\r\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\r\n\t\t}\r\n\t}\r\n\tfragment_data->size = fragment_size;\r\n\tfragment_data->block = fragments;\r\n\tfragment_table[fragments].unused = 0;\r\n\tfragments_outstanding ++;\r\n\tqueue_put(to_frag, fragment_data);\r\n\tfragments ++;\r\n\tfragment_size = 0;\r\n\tpthread_mutex_unlock(&fragment_mutex);\r\n}\r\n\r\n\r\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\r\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\r\n{\r\n\tstruct fragment *ffrg;\r\n\t\r\n\r\n\tif(file_buffer == NULL || file_buffer->size == 0)\r\n\t\treturn &empty_fragment;\r\n\r\n\tif(fragment_size + file_buffer->size > block_size)\r\n\t\twrite_fragment();\r\n\r\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\r\n\r\n\tif(fragment_size == 0)\r\n\t\tfragment_data = cache_get(fragment_buffer, fragments, 1);\r\n\r\n\tffrg->index = fragments;\r\n\tffrg->offset = fragment_size;\r\n\tffrg->size = file_buffer->size;\r\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\r\n\tfragment_size += file_buffer->size;\r\n\r\n\treturn ffrg;\r\n}\r\n\r\n\r\nlong long generic_write_table(int length, char *buffer, int uncompressed)\r\n{\r\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\r\n\tlong long list[meta_blocks], start_bytes;\r\n\tint compressed_size, i;\r\n\tunsigned short c_byte;\r\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\r\n\t\r\n\tlong long obytes = bytes;\r\n\r\n\tfor(i = 0; i < meta_blocks; i++) {\r\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\r\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\r\n\t\tif(check_data)\r\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\r\n\t\tlist[i] = bytes;\r\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\r\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\r\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\r\n\t\tbytes += compressed_size;\r\n\t\tlength -= avail_bytes;\r\n\t}\r\n\r\n\tif(!swap)\r\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\r\n\telse {\r\n\t\tlong long slist[meta_blocks];\r\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\r\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\r\n\t}\r\n\r\n\tstart_bytes = bytes;\r\n\tbytes += sizeof(list);\r\n\r\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\r\n\r\n\treturn start_bytes;\r\n}\r\n\r\n\r\nlong long write_fragment_table()\r\n{\r\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\r\n\tchar buffer[frag_bytes];\r\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\r\n\tint i;\r\n\r\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\r\n\tfor(i = 0; i < fragments; i++, p++) {\r\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block 0x%llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\r\n\t\tif(!swap)\r\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\r\n\t\telse\r\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\r\n\t}\r\n\r\n\treturn generic_write_table(frag_bytes, buffer, noF);\r\n}\r\n\r\n\r\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\r\nchar *read_from_disk(long long start, unsigned int avail_bytes)\r\n{\r\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\r\n\treturn read_from_file_buffer;\r\n}\r\n\r\n\r\n/*\r\n * Compute 16 bit BSD checksum over the data\r\n */\r\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\r\n{\r\n\tunsigned char *b = (unsigned char *) buff;\r\n\r\n\twhile(bytes --) {\r\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\r\n\t\tchksum += *b++;\r\n\t}\r\n\r\n\treturn chksum;\r\n}\r\n\r\n\r\nunsigned short get_checksum_disk(long long start, long long l, unsigned int *blocks)\r\n{\r\n\tunsigned short chksum = 0;\r\n\tunsigned int bytes;\r\n\tstruct file_buffer *write_buffer;\r\n\tint i;\r\n\r\n\tfor(i = 0; l; i++)  {\r\n\t\tbytes = SQUASHFS_COMPRESSED_SIZE_BLOCK(blocks[i]);\r\n\t\tif(bytes == 0) /* sparse block */\r\n\t\t\tcontinue;\r\n\t\twrite_buffer = cache_lookup(writer_buffer, start);\r\n\t\tif(write_buffer) {\r\n\t\t\tchksum = get_checksum(write_buffer->data, bytes, chksum);\r\n\t\t\tcache_block_put(write_buffer);\r\n\t\t} else\r\n\t\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\r\n\t\tl -= bytes;\r\n\t\tstart += bytes;\r\n\t}\r\n\r\n\treturn chksum;\r\n}\r\n\r\n\r\nunsigned short get_checksum_mem(char *buff, int bytes)\r\n{\r\n\treturn get_checksum(buff, bytes, 0);\r\n}\r\n\r\n\r\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\r\n{\r\n\tif(file_buffer == NULL)\r\n\t\treturn 0;\r\n\telse\r\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\r\n}\r\n\r\n\r\n#define DUP_HASH(a) (a & 0xffff)\r\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\r\n{\r\n\tstruct fragment *frg;\r\n\tunsigned int *block_list = block_listp;\r\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\r\n\r\n\tif(!duplicate_checking || file_size == 0)\r\n\t\treturn;\r\n\r\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\r\n\t\tif(file_size != dupl_ptr->file_size)\r\n\t\t\tcontinue;\r\n\t\tif(blocks != 0 && start != dupl_ptr->start)\r\n\t\t\tcontinue;\r\n\t\tif(fragment != dupl_ptr->fragment->index)\r\n\t\t\tcontinue;\r\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\r\n\t\t\tcontinue;\r\n\t\treturn;\r\n\t}\r\n\r\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\r\n\r\n\tfrg->index = fragment;\r\n\tfrg->offset = offset;\r\n\tfrg->size = bytes;\r\n\r\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\r\n}\r\n\r\n\r\nint pre_duplicate(long long file_size)\r\n{\r\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\r\n\r\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\r\n\t\tif(dupl_ptr->file_size == file_size)\r\n\t\t\treturn TRUE;\r\n\r\n\treturn FALSE;\r\n}\r\n\r\n\r\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\r\n{\r\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\r\n\r\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\r\n\t\tif(dupl_ptr->file_size == file_size) {\r\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\r\n\t\t\t\tstruct file_buffer *frag_buffer = get_fragment(dupl_ptr->fragment);\r\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes, dupl_ptr->block_list);\r\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(frag_buffer->data + dupl_ptr->fragment->offset, file_size);\r\n\t\t\t\tcache_block_put(frag_buffer);\r\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\r\n\t\t\t}\r\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\r\n\t\t\t\treturn TRUE;\r\n\t\t}\r\n\r\n\treturn FALSE;\r\n}\r\n\r\n\r\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\r\n{\r\n\tstruct file_info *dupl_ptr;\r\n\r\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\r\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\r\n\t}\r\n\r\n\tdupl_ptr->file_size = file_size;\r\n\tdupl_ptr->bytes = bytes;\r\n\tdupl_ptr->block_list = block_list;\r\n\tdupl_ptr->start = start;\r\n\tdupl_ptr->fragment = fragment;\r\n\tdupl_ptr->checksum = checksum;\r\n\tdupl_ptr->fragment_checksum = fragment_checksum;\r\n\tdupl_ptr->checksum_flag = checksum_flag;\r\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\r\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\r\n\tdup_files ++;\r\n\r\n\treturn dupl_ptr;\r\n}\r\n\r\n\r\nchar buffer2[SQUASHFS_FILE_MAX_SIZE];\r\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\r\n{\r\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\r\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\r\n\r\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\r\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\r\n\t\t\tlong long dup_start = dupl_ptr->start;\r\n\t\t\tint block;\r\n\r\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks * sizeof(unsigned int)) != 0)\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tif(checksum_flag == FALSE) {\r\n\t\t\t\tchecksum = get_checksum_disk(*start, bytes, *block_list);\r\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\r\n\t\t\t\tchecksum_flag = TRUE;\r\n\t\t\t}\r\n\r\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\r\n\t\t\t\tstruct file_buffer *frag_buffer = get_fragment(dupl_ptr->fragment);\r\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes, dupl_ptr->block_list);\r\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(frag_buffer->data + dupl_ptr->fragment->offset, frag_bytes);\r\n\t\t\t\tcache_block_put(frag_buffer);\r\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\r\n\t\t\t}\r\n\r\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\r\n\t\t\t\tcontinue;\r\n\r\n\t\t\tfor(block = 0; block < blocks; block ++) {\r\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\r\n\t\t\t\tstruct file_buffer *target_buffer = NULL;\r\n\t\t\t\tstruct file_buffer *dup_buffer = NULL;\r\n\t\t\t\tchar *target_data, *dup_data;\r\n\t\t\t\tint res;\r\n\r\n\t\t\t\tif(b->read_buffer)\r\n\t\t\t\t\ttarget_data = b->read_buffer->data;\r\n\t\t\t\telse if(b->size) {\r\n\t\t\t\t\ttarget_buffer = cache_lookup(writer_buffer, b->start);\r\n\t\t\t\t\tif(target_buffer)\r\n\t\t\t\t\t\ttarget_data = target_buffer->data;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\ttarget_data = read_from_disk(b->start, b->size);\r\n\t\t\t\t} else\r\n\t\t\t\t\tcontinue;\r\n\r\n\t\t\t\tdup_buffer = cache_lookup(writer_buffer, dup_start);\r\n\t\t\t\tif(dup_buffer)\r\n\t\t\t\t\tdup_data = dup_buffer->data;\r\n\t\t\t\telse {\r\n\t\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\r\n\t\t\t\t\tdup_data = buffer2;\r\n\t\t\t\t}\r\n\t\t\t\tres = memcmp(target_data, dup_data, b->size);\r\n\t\t\t\tif(target_buffer)\r\n\t\t\t\t\tcache_block_put(target_buffer);\r\n\t\t\t\tif(dup_buffer)\r\n\t\t\t\t\tcache_block_put(dup_buffer);\r\n\t\t\t\tif(res != 0)\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdup_start += b->size;\r\n\t\t\t}\r\n\t\t\tif(block == blocks) {\r\n\t\t\t\tstruct file_buffer *frag_buffer = get_fragment(dupl_ptr->fragment);\r\n\r\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, frag_buffer->data + dupl_ptr->fragment->offset, frag_bytes) == 0) {\r\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\r\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\r\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\r\n\t\t\t\t\t*start = dupl_ptr->start;\r\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\r\n\t\t\t\t\tcache_block_put(frag_buffer);\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\t\tcache_block_put(frag_buffer);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\r\n}\r\n\r\n\r\nvoid reader_read_file(struct dir_ent *dir_ent)\r\n{\r\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\r\n\tstruct file_buffer *file_buffer;\r\n\tstatic int index = 0;\r\n\tint blocks, byte, count, expected, file, frag_block;\r\n\tlong long bytes, read_size;\r\n\r\n\tif(dir_ent->inode->read)\r\n\t\treturn;\r\n\r\n\tdir_ent->inode->read = TRUE;\r\nagain:\r\n\tbytes = 0;\r\n\tcount = 0;\r\n\tfile_buffer = NULL;\r\n\tread_size = buf->st_size;\r\n\tblocks = (read_size + block_size - 1) >> block_log;\r\n\tfrag_block = !no_fragments && (always_use_fragments ||\r\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\r\n\r\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\r\n\t\tgoto read_err;\r\n\r\n\tdo {\r\n\t\texpected = read_size - ((long long) count * block_size) > block_size ? block_size : read_size - ((long long) count * block_size);\r\n\r\n\t\tif(file_buffer)\r\n\t\t\tqueue_put(from_reader, file_buffer);\r\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\r\n\t\tfile_buffer->sequence = index ++;\r\n\r\n\t\tbyte = file_buffer->size = read(file, file_buffer->data, block_size);\r\n\r\n\t\tfile_buffer->file_size = read_size;\r\n\r\n\t\tif(byte != expected)\r\n\t\t\tgoto restat;\r\n\r\n\t\tfile_buffer->block = count;\r\n\t\tfile_buffer->error = FALSE;\r\n\r\n\t\tbytes += byte;\r\n\t\tcount ++;\r\n\t} while(count < blocks);\r\n\r\n\tif(read_size != bytes)\r\n\t\tgoto restat;\r\n\r\n\tif(expected == block_size) {\r\n\t\tchar buffer;\r\n\r\n\t\tif(read(file, &buffer, 1) == 1)\r\n\t\t\tgoto restat;\r\n\t}\r\n\r\n\tfile_buffer->fragment = (file_buffer->block == frag_block);\r\n\r\n\tif(file_buffer->fragment)\r\n\t\tqueue_put(from_deflate, file_buffer);\r\n\telse\r\n\t\tqueue_put(from_reader, file_buffer);\r\n\r\n\tclose(file);\r\n\r\n\treturn;\r\n\r\nread_err:\r\n\tfile_buffer = cache_get(reader_buffer, 0, 0);\r\n\tfile_buffer->sequence = index ++;\r\nread_err2:\r\n\tfile_buffer->error = TRUE;\r\n\tqueue_put(from_deflate, file_buffer);\r\n\treturn;\r\nrestat:\r\n\tfstat(file, &buf2);\r\n\tclose(file);\r\n\tif(read_size != buf2.st_size) {\r\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\r\n\t\tfile_buffer->error = 2;\r\n\t\tqueue_put(from_deflate, file_buffer);\r\n\t\tgoto again;\r\n\t}\r\n\tgoto read_err2;\r\n}\r\n\r\n\r\nvoid reader_scan(struct dir_info *dir) {\r\n\tint i;\r\n\r\n\tfor(i = 0; i < dir->count; i++) {\r\n\t\tstruct dir_ent *dir_ent = dir->list[i];\r\n\t\tstruct stat *buf = &dir_ent->inode->buf;\r\n\t\tif(dir_ent->data)\r\n\t\t\tcontinue;\r\n\r\n\t\tswitch(buf->st_mode & S_IFMT) {\r\n\t\t\tcase S_IFREG:\r\n\t\t\t\treader_read_file(dir_ent);\r\n\t\t\t\tbreak;\r\n\t\t\tcase S_IFDIR:\r\n\t\t\t\treader_scan(dir_ent->dir);\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\r\nvoid *reader(void *arg)\r\n{\r\n\tint oldstate;\r\n\r\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\r\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\r\n\r\n\tif(!sorted)\r\n\t\treader_scan(queue_get(to_reader));\r\n\telse {\r\n\t\tint i;\r\n\t\tstruct priority_entry *entry;\r\n\r\n\t\tqueue_get(to_reader);\r\n\t\tfor(i = 65535; i >= 0; i--)\r\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\r\n\t\t\t\treader_read_file(entry->dir);\r\n\t}\r\n\r\n\tthread[0] = 0;\r\n\r\n\tpthread_exit(NULL);\r\n}\r\n\r\n\r\nvoid *writer(void *arg)\r\n{\r\n\tint write_error = FALSE;\r\n\tint oldstate;\r\n\r\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\r\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\r\n\r\n\twhile(1) {\r\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\r\n\t\toff_t off;\r\n\r\n\t\tif(file_buffer == NULL) {\r\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\toff = file_buffer->block;\r\n\r\n\t\tpthread_mutex_lock(&pos_mutex);\r\n\r\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\r\n\t\t\tERROR(\"Lseek on destination failed because %s\\n\", strerror(errno));\r\n\t\t\twrite_error = TRUE;\r\n\t\t}\r\n\r\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\r\n\t\t\tERROR(\"Write on destination failed because %s\\n\", strerror(errno));\r\n\t\t\twrite_error = TRUE;\r\n\t\t}\r\n\t\tpthread_mutex_unlock(&pos_mutex);\r\n\r\n\t\tcache_block_put(file_buffer);\r\n\t}\r\n}\r\n\r\n\r\nint all_zero(struct file_buffer *file_buffer)\r\n{\r\n\tint i;\r\n\tlong entries = file_buffer->size / sizeof(long);\r\n\tlong *p = (long *) file_buffer->data;\r\n\r\n\tfor(i = 0; i < entries && p[i] == 0; i++);\r\n\r\n\tif(i == entries) {\r\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1); i < file_buffer->size &&\r\n\t\t\t\t\t\tfile_buffer->data[i] == 0; i++);\r\n\r\n\t\treturn i == file_buffer->size;\r\n\t}\r\n\r\n\treturn 0;\r\n}\r\n\r\n\r\nvoid *deflator(void *arg)\r\n{\r\n\tz_stream *stream = NULL;\r\n\tint oldstate;\r\n\r\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\r\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\r\n\r\n\twhile(1) {\r\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\r\n\t\tstruct file_buffer *write_buffer = cache_get(writer_buffer, 0, 0);\r\n\r\n\t\tif(sparse_files && all_zero(file_buffer)) \r\n\t\t\twrite_buffer->c_byte = 0;\r\n\t\telse\r\n\t\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\r\n\t\twrite_buffer->sequence = file_buffer->sequence;\r\n\t\twrite_buffer->file_size = file_buffer->file_size;\r\n\t\twrite_buffer->block = file_buffer->block;\r\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\r\n\t\twrite_buffer->fragment = FALSE;\r\n\t\twrite_buffer->error = FALSE;\r\n\t\tcache_block_put(file_buffer);\r\n\t\tqueue_put(from_deflate, write_buffer);\r\n\t}\r\n}\r\n\r\n\r\nvoid *frag_deflator(void *arg)\r\n{\r\n\tz_stream *stream = NULL;\r\n\tint oldstate;\r\n\r\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\r\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\r\n\r\n\twhile(1) {\r\n\t\tint c_byte, compressed_size;\r\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\r\n\t\tstruct file_buffer *write_buffer = cache_get(writer_buffer, file_buffer->block + FRAG_INDEX, 1);\r\n\r\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\r\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\r\n\t\twrite_buffer->size = compressed_size;\r\n\t\tpthread_mutex_lock(&fragment_mutex);\r\n\t\tif(fragments_locked == FALSE) {\r\n\t\t\tfragment_table[file_buffer->block].size = c_byte;\r\n\t\t\tfragment_table[file_buffer->block].start_block = bytes;\r\n\t\t\twrite_buffer->block = bytes;\r\n\t\t\tbytes += compressed_size;\r\n\t\t\tfragments_outstanding --;\r\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\r\n\t\t\tqueue_put(to_writer, write_buffer);\r\n\t\t\tTRACE(\"Writing fragment %lld, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\r\n\t\t} else {\r\n\t\t\t\tpthread_mutex_unlock(&fragment_mutex);\r\n\t\t\t\tadd_pending_fragment(write_buffer, c_byte, file_buffer->block);\r\n\t\t}\r\n\t\tcache_block_put(file_buffer);\r\n\t}\r\n}\r\n\r\n\r\n#define HASH_ENTRIES\t\t256\r\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\r\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\r\n\r\nvoid push_buffer(struct file_buffer *file_buffer)\r\n{\r\n\tint hash = BLOCK_HASH(file_buffer->sequence);\r\n\r\n\tfile_buffer->next = block_hash[hash];\r\n\tblock_hash[hash] = file_buffer;\r\n}\r\n\r\n\r\nstruct file_buffer *get_file_buffer(struct queue *queue)\r\n{\r\n\tstatic unsigned int sequence = 0;\r\n\tint hash = BLOCK_HASH(sequence);\r\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\r\n\r\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\r\n\t\tif(file_buffer->sequence == sequence)\r\n\t\t\tbreak;\r\n\r\n\tif(file_buffer) {\r\n\t\tif(prev)\r\n\t\t\tprev->next = file_buffer->next;\r\n\t\telse\r\n\t\t\tblock_hash[hash] = file_buffer->next;\r\n\t} else {\r\n\t\twhile(1) {\r\n\t\t\tfile_buffer = queue_get(queue);\r\n\t\t\tif(file_buffer->sequence == sequence)\r\n\t\t\t\tbreak;\r\n\t\t\tpush_buffer(file_buffer);\r\n\t\t}\r\n\t}\r\n\r\n\tsequence ++;\r\n\r\n\treturn file_buffer;\r\n}\r\n\r\n\r\nvoid *progress_thrd(void *arg)\r\n{\r\n\tstruct timeval timeval;\r\n\tstruct timespec timespec;\r\n\tstruct itimerval itimerval;\r\n\tstruct winsize winsize;\r\n\r\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\r\n\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\r\n\t\tcolumns = 80;\r\n\t} else\r\n\t\tcolumns = winsize.ws_col;\r\n\tsignal(SIGWINCH, sigwinch_handler);\r\n\tsignal(SIGALRM, sigalrm_handler);\r\n\r\n\titimerval.it_value.tv_sec = 0;\r\n\titimerval.it_value.tv_usec = 250000;\r\n\titimerval.it_interval.tv_sec = 0;\r\n\titimerval.it_interval.tv_usec = 250000;\r\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\r\n\r\n\tpthread_cond_init(&progress_wait, NULL);\r\n\r\n\tpthread_mutex_lock(&progress_mutex);\r\n\r\n\twhile(1) {\r\n\t\tgettimeofday(&timeval, NULL);\r\n\t\ttimespec.tv_sec = timeval.tv_sec;\r\n\t\tif(timeval.tv_usec + 250000 > 999999)\r\n\t\t\ttimespec.tv_sec++;\r\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) * 1000;\r\n\t\tpthread_cond_timedwait(&progress_wait, &progress_mutex, &timespec);\r\n\t\tif(progress_enabled && estimated_uncompressed)\r\n\t\t\tprogress_bar(cur_uncompressed, estimated_uncompressed, columns);\r\n\t}\r\n}\r\n\r\n\r\nvoid enable_progress_bar()\r\n{\r\n\tpthread_mutex_lock(&progress_mutex);\r\n\tprogress_enabled = TRUE;\r\n\tpthread_mutex_unlock(&progress_mutex);\r\n}\r\n\r\n\r\nvoid disable_progress_bar()\r\n{\r\n\tpthread_mutex_lock(&progress_mutex);\r\n\tprogress_enabled = FALSE;\r\n\tpthread_mutex_unlock(&progress_mutex);\r\n}\r\n\r\n\r\nvoid progress_bar(long long current, long long max, int columns)\r\n{\r\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\r\n\tint max_digits = floor(log10(max)) + 1;\r\n\tint used = max_digits * 2 + 11;\r\n\tint hashes = (current * (columns - used)) / max;\r\n\tint spaces = columns - used - hashes;\r\n\r\n\tif(current > max) {\r\n\t\tprintf(\"%lld %lld\\n\", current, max);\r\n\t\treturn;\r\n\t}\r\n\r\n\tif(columns - used < 0)\r\n\t\treturn;\r\n\r\n\tprintf(\"\\r[\");\r\n\r\n\twhile (hashes --)\r\n\t\tputchar('=');\r\n\r\n\tputchar(rotate_list[rotate]);\r\n\r\n\twhile(spaces --)\r\n\t\tputchar(' ');\r\n\r\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\r\n\tprintf(\" %3lld%%\", current * 100 / max);\r\n\tfflush(stdout);\r\n}\r\n\r\n\r\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\r\n{\r\n\tfile_count ++;\r\n\t*duplicate_file = FALSE;\r\n\tif(dir_ent->inode->nlink == 1)\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\r\n\telse\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\r\n}\r\n\r\n\r\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\r\n{\r\n\tstruct file_info *dupl_ptr;\r\n\tstruct fragment *fragment;\r\n\tunsigned int *block_listp = NULL;\r\n\tlong long start = 0;\r\n\r\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\r\n\r\n\tif(dupl_ptr) {\r\n\t\t*duplicate_file = FALSE;\r\n\t\tfragment = get_and_fill_fragment(file_buffer);\r\n\t\tdupl_ptr->fragment = fragment;\r\n\t} else\r\n\t\t*duplicate_file = TRUE;\r\n\r\n\tcache_block_put(file_buffer);\r\n\r\n\ttotal_bytes += size;\r\n\tfile_count ++;\r\n\r\n\tinc_progress_bar();\r\n\r\n\tif(dir_ent->inode->nlink == 1)\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\r\n\telse\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\r\n}\r\n\r\n\r\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, struct file_buffer *file_buffer, int *duplicate_file)\r\n{\r\n\tstruct fragment *fragment;\r\n\tunsigned short checksum;\r\n\r\n\tchecksum = get_checksum_mem_buffer(file_buffer);\r\n\r\n\tif(pre_duplicate_frag(size, checksum)) {\r\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\r\n\t\treturn;\r\n\t}\r\n\t\t\r\n\tfragment = get_and_fill_fragment(file_buffer);\r\n\r\n\tcache_block_put(file_buffer);\r\n\r\n\tif(duplicate_checking)\r\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\r\n\r\n\ttotal_bytes += size;\r\n\tfile_count ++;\r\n\r\n\t*duplicate_file = FALSE;\r\n\r\n\tinc_progress_bar();\r\n\r\n\tif(dir_ent->inode->nlink == 1)\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\r\n\telse\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\r\n\r\n\treturn;\r\n}\r\n\r\n\r\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\r\n{\r\n\tint block;\r\n\tunsigned int frag_bytes;\r\n\tlong long file_bytes, start;\r\n\tstruct fragment *fragment;\r\n\tint blocks = (read_size + block_size - 1) >> block_log;\r\n\tunsigned int *block_list;\r\n\tstruct file_buffer *read_buffer;\r\n\tint status;\r\n\r\n\t*duplicate_file = FALSE;\r\n\r\n\tif(!no_fragments && always_use_fragments) {\r\n\t\tblocks = read_size >> block_log;\r\n\t\tfrag_bytes = read_size % block_size;\r\n\t} else\r\n\t\tfrag_bytes = 0;\r\n\r\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\r\n\r\n\tlock_fragments();\r\n\r\n\tfile_bytes = 0;\r\n\tstart = bytes;\r\n\tfor(block = 0; block < blocks; block ++) {\r\n\t\tif(reader_buffer) {\r\n\t\t\tread_buffer = reader_buffer;\r\n\t\t\treader_buffer = NULL;\r\n\t\t} else {\r\n\t\t\tread_buffer = get_file_buffer(from_deflate);\r\n\t\t\tif(read_buffer->error)\r\n\t\t\t\tgoto read_err;\r\n\t\t}\r\n\r\n\t\tblock_list[block] = read_buffer->c_byte;\r\n\t\tif(read_buffer->c_byte) {\r\n\t\t\tread_buffer->block = bytes;\r\n\t\t\tbytes += read_buffer->size;\r\n\t\t\tcache_rehash(read_buffer, read_buffer->block);\r\n\t\t\tfile_bytes += read_buffer->size;\r\n\t\t\tqueue_put(to_writer, read_buffer);\r\n\t\t} else\r\n\t\t\tcache_block_put(read_buffer);\r\n\t\tinc_progress_bar();\r\n\t}\r\n\r\n\tif(frag_bytes != 0) {\r\n\t\tread_buffer = get_file_buffer(from_deflate);\r\n\t\tif(read_buffer->error)\r\n\t\t\tgoto read_err;\r\n\t\tinc_progress_bar();\r\n\t} else\r\n\t\tread_buffer = NULL;\r\n\r\n\tunlock_fragments();\r\n\tfragment = get_and_fill_fragment(read_buffer);\r\n\tcache_block_put(read_buffer);\r\n\r\n\tif(duplicate_checking)\r\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\r\n\tfile_count ++;\r\n\ttotal_bytes += read_size;\r\n\r\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\r\n\telse\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\r\n\r\n\tif(duplicate_checking == FALSE)\r\n\t\tfree(block_list);\r\n\r\n\treturn 0;\r\n\r\nread_err:\r\n\tcur_uncompressed -= block;\r\n\tstatus = read_buffer->error;\r\n\tbytes = start;\r\n\tif(!block_device) {\r\n\t\tqueue_put(to_writer, NULL);\r\n\t\tif(queue_get(from_writer) != 0)\r\n\t\t\tEXIT_MKSQUASHFS();\r\n\t\tftruncate(fd, bytes);\r\n\t}\r\n\tunlock_fragments();\r\n\tfree(block_list);\r\n\tcache_block_put(read_buffer);\r\n\treturn status;\r\n}\r\n\r\n\r\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\r\n{\r\n\tint block, thresh;\r\n\tunsigned int frag_bytes;\r\n\tlong long file_bytes, start;\r\n\tstruct fragment *fragment;\r\n\tstruct file_info *dupl_ptr;\r\n\tint blocks = (read_size + block_size - 1) >> block_log;\r\n\tunsigned int *block_list, *block_listp;\r\n\tstruct file_buffer *read_buffer;\r\n\tstruct buffer_list *buffer_list;\r\n\tint status, num_locked_fragments;\r\n\r\n\tif(!no_fragments && always_use_fragments) {\r\n\t\tblocks = read_size >> block_log;\r\n\t\tfrag_bytes = read_size % block_size;\r\n\t} else\r\n\t\tfrag_bytes = 0;\r\n\r\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\r\n\tblock_listp = block_list;\r\n\r\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\r\n\r\n\tnum_locked_fragments = lock_fragments();\r\n\r\n\tfile_bytes = 0;\r\n\tstart = bytes;\r\n\tthresh = blocks > (writer_buffer_size - num_locked_fragments) ? blocks - (writer_buffer_size - num_locked_fragments): 0;\r\n\tfor(block = 0; block < blocks; block ++) {\r\n\t\tif(reader_buffer) {\r\n\t\t\tread_buffer = reader_buffer;\r\n\t\t\treader_buffer = NULL;\r\n\t\t } else {\r\n\t\t\tread_buffer = get_file_buffer(from_deflate);\r\n\t\t\tif(read_buffer->error)\r\n\t\t\t\tgoto read_err;\r\n\t\t}\r\n\r\n\t\tblock_list[block] = read_buffer->c_byte;\r\n\t\tbuffer_list[block].start = bytes;\r\n\t\tbuffer_list[block].size = read_buffer->size;\r\n\r\n\t\tif(read_buffer->c_byte) {\r\n\t\t\tread_buffer->block = bytes;\r\n\t\t\tbytes += read_buffer->size;\r\n\t\t\tcache_rehash(read_buffer, read_buffer->block);\r\n\t\t\tfile_bytes += read_buffer->size;\r\n\t\t\tif(block < thresh) {\r\n\t\t\t\tbuffer_list[block].read_buffer = NULL;\r\n\t\t\t\tqueue_put(to_writer, read_buffer);\r\n\t\t\t} else\r\n\t\t\t\tbuffer_list[block].read_buffer = read_buffer;\r\n\t\t} else {\r\n\t\t\tbuffer_list[block].read_buffer = NULL;\r\n\t\t\tcache_block_put(read_buffer);\r\n\t\t}\r\n\t\tinc_progress_bar();\r\n\t}\r\n\r\n\tif(frag_bytes != 0) {\r\n\t\tread_buffer = get_file_buffer(from_deflate);\r\n\t\tif(read_buffer->error)\r\n\t\t\tgoto read_err;\r\n\t} else\r\n\t\tread_buffer = NULL;\r\n\r\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\r\n\r\n\tif(dupl_ptr) {\r\n\t\t*duplicate_file = FALSE;\r\n\t\tfor(block = thresh; block < blocks; block ++)\r\n\t\t\tif(buffer_list[block].read_buffer)\r\n\t\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\r\n\t\tfragment = get_and_fill_fragment(read_buffer);\r\n\t\tdupl_ptr->fragment = fragment;\r\n\t} else {\r\n\t\t*duplicate_file = TRUE;\r\n\t\tfor(block = thresh; block < blocks; block ++)\r\n\t\t\tcache_block_put(buffer_list[block].read_buffer);\r\n\t\tbytes = buffer_list[0].start;\r\n\t\tif(thresh && !block_device) {\r\n\t\t\tqueue_put(to_writer, NULL);\r\n\t\t\tif(queue_get(from_writer) != 0)\r\n\t\t\t\tEXIT_MKSQUASHFS();\r\n\t\t\tftruncate(fd, bytes);\r\n\t\t}\r\n\t}\r\n\r\n\tunlock_fragments();\r\n\tcache_block_put(read_buffer);\r\n\tfree(buffer_list);\r\n\tfile_count ++;\r\n\ttotal_bytes += read_size;\r\n\r\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\r\n\telse\r\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\r\n\r\n\tif(*duplicate_file == TRUE)\r\n\t\tfree(block_list);\r\n\r\n\treturn 0;\r\n\r\nread_err:\r\n\tcur_uncompressed -= block;\r\n\tstatus = read_buffer->error;\r\n\tbytes = start;\r\n\tif(thresh && !block_device) {\r\n\t\tqueue_put(to_writer, NULL);\r\n\t\tif(queue_get(from_writer) != 0)\r\n\t\t\tEXIT_MKSQUASHFS();\r\n\t\tftruncate(fd, bytes);\r\n\t}\r\n\tunlock_fragments();\r\n\tfor(blocks = thresh; blocks < block; blocks ++)\r\n\t\tcache_block_put(buffer_list[blocks].read_buffer);\r\n\tfree(buffer_list);\r\n\tfree(block_list);\r\n\tcache_block_put(read_buffer);\r\n\treturn status;\r\n}\r\n\r\n\r\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\r\n{\r\n\tint status;\r\n\tstruct file_buffer *read_buffer;\r\n\tlong long read_size;\r\n\r\nagain:\r\n\tread_buffer = get_file_buffer(from_deflate);\r\n\tstatus = read_buffer->error;\r\n\tif(status) {\r\n\t\tcache_block_put(read_buffer);\r\n\t\tgoto file_err;\r\n\t}\r\n\t\r\n\tread_size = read_buffer->file_size;\r\n\r\n\tif(read_size == 0) {\r\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\r\n\t\tcache_block_put(read_buffer);\r\n\t} else if(!no_fragments && (read_size < block_size))\r\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer, duplicate_file);\r\n\telse if(pre_duplicate(read_size))\r\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size, read_buffer, duplicate_file);\r\n\telse\r\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size, read_buffer, duplicate_file);\r\n\r\nfile_err:\r\n\tif(status == 2) {\r\n\t\tERROR(\"File %s changed size while reading filesystem, attempting to re-read\\n\", dir_ent->pathname);\r\n\t\tgoto again;\r\n\t} else if(status == 1) {\r\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\", dir_ent->pathname);\r\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\r\n\t}\r\n}\r\n\r\n\r\nchar b_buffer[8192];\r\nchar *name;\r\nchar *basename_r();\r\n\r\nchar *getbase(char *pathname)\r\n{\r\n\tchar *result;\r\n\r\n\tif(*pathname != '/') {\r\n\t\tresult = getenv(\"PWD\");\r\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\r\n\t} else\r\n\t\tstrcpy(b_buffer, pathname);\r\n\tname = b_buffer;\r\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\r\n\t\treturn NULL;\r\n\telse\r\n\t\treturn result;\r\n}\r\n\r\n\r\nchar *basename_r()\r\n{\r\n\tchar *s;\r\n\tchar *p;\r\n\tint n = 1;\r\n\r\n\tfor(;;) {\r\n\t\ts = name;\r\n\t\tif(*name == '\\0')\r\n\t\t\treturn NULL;\r\n\t\tif(*name != '/') {\r\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\r\n\t\t\tn = name - s;\r\n\t\t}\r\n\t\twhile(*name == '/') name++;\r\n\t\tif(strncmp(s, \".\", n) == 0)\r\n\t\t\tcontinue;\r\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\r\n\t\t\ts[n] = '\\0';\r\n\t\t\treturn s;\r\n\t\t}\r\n\t\tif(strcmp(p, \"..\") == 0)\r\n\t\t\tcontinue;\r\n\t\treturn p;\r\n\t}\r\n}\r\n\r\n\r\nstruct inode_info *lookup_inode(struct stat *buf)\r\n{\r\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\r\n\tstruct inode_info *inode = inode_info[inode_hash];\r\n\r\n\twhile(inode != NULL) {\r\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\r\n\t\t\tinode->nlink ++;\r\n\t\t\treturn inode;\r\n\t\t}\r\n\t\tinode = inode->next;\r\n\t}\r\n\r\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\r\n\r\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\r\n\tinode->read = FALSE;\r\n\tinode->inode = SQUASHFS_INVALID_BLK;\r\n\tinode->nlink = 1;\r\n\r\n\tif((buf->st_mode & S_IFMT) == S_IFREG)\r\n\t\testimated_uncompressed += (buf->st_size + block_size - 1) >> block_log;\r\n\r\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\r\n\t\tinode->inode_number = dir_inode_no ++;\r\n\telse\r\n\t\tinode->inode_number = inode_no ++;\r\n\r\n\tinode->next = inode_info[inode_hash];\r\n\tinode_info[inode_hash] = inode;\r\n\r\n\treturn inode;\r\n}\r\n\r\n\r\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\r\n{\r\n\tif((dir->count % DIR_ENTRIES) == 0)\r\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\r\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\r\n\r\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\r\n\r\n\tif(sub_dir)\r\n\t\tsub_dir->dir_ent = dir->list[dir->count];\r\n\tdir->list[dir->count]->name = strdup(name);\r\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\r\n\tdir->list[dir->count]->inode = inode_info;\r\n\tdir->list[dir->count]->dir = sub_dir;\r\n\tdir->list[dir->count]->our_dir = dir;\r\n\tdir->list[dir->count++]->data = data;\r\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\r\n}\r\n\r\n\r\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\r\n{\r\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\r\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\r\n\r\n\treturn strcmp(ent1->name, ent2->name);\r\n}\r\n\r\n\r\nvoid sort_directory(struct dir_info *dir)\r\n{\r\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\r\n\r\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\r\n\t\tdir->dir_is_ldir = FALSE;\r\n}\r\n\r\n\r\nstruct dir_info *scan1_opendir(char *pathname)\r\n{\r\n\tstruct dir_info *dir;\r\n\r\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\r\n\t\treturn NULL;\r\n\r\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\r\n\t\tfree(dir);\r\n\t\treturn NULL;\r\n\t}\r\n\tdir->pathname = strdup(pathname);\r\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\r\n\tdir->dir_is_ldir = TRUE;\r\n\tdir->list = NULL;\r\n\r\n\treturn dir;\r\n}\r\n\r\n\r\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\r\n{\r\n\tint i, n, pass;\r\n\tchar *basename;\r\n\tstatic int index = 0;\r\n\r\n\tif(dir->count < old_root_entries)\r\n\t\tfor(i = 0; i < old_root_entries; i++) {\r\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\r\n\t\t\t\tdir->directory_count ++;\r\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\r\n\t\t}\r\n\r\n\twhile(index < source) {\r\n\t\tif((basename = getbase(source_path[index])) == NULL) {\r\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\r\n\t\t\tindex ++;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tstrcpy(dir_name, basename);\r\n\t\tpass = 1;\r\n\t\tfor(;;) {\r\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\r\n\t\t\tif(n == dir->count)\r\n\t\t\t\tbreak;\r\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\r\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\r\n\t\t\tERROR(\"%s\\n\", dir_name);\r\n\t\t}\r\n\t\tstrcpy(pathname, source_path[index ++]);\r\n\t\treturn 1;\r\n\t}\r\n\treturn 0;\r\n}\r\n\r\n\r\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\r\n{\r\n\tstruct dirent *d_name;\r\n\tint i, pass;\r\n\r\n\tif(dir->count < old_root_entries)\r\n\t\tfor(i = 0; i < old_root_entries; i++) {\r\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\r\n\t\t\t\tdir->directory_count ++;\r\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\r\n\t\t}\r\n\r\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\r\n\t\tstrcpy(dir_name, d_name->d_name);\r\n\t\tpass = 1;\r\n\t\tfor(;;) {\r\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\r\n\t\t\tif(i == dir->count)\r\n\t\t\t\tbreak;\r\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\r\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\r\n\t\t\tERROR(\"%s\\n\", dir_name);\r\n\t\t}\r\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\r\n\t\treturn 1;\r\n\t}\r\n\r\n\treturn 0;\r\n}\r\n\r\n\r\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\r\n{\r\n\tstruct dirent *d_name;\r\n\r\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\r\n\t\tstrcpy(dir_name, d_name->d_name);\r\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\r\n\t\treturn 1;\r\n\t}\r\n\r\n\treturn 0;\r\n}\r\n\r\n\r\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\r\n{\r\n\tint current_count;\r\n\r\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\r\n\t\tif(dir_info->list[current_count]->data)\r\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\r\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\r\n\t\telse \r\n\t\t\treturn dir_info->list[current_count];\r\n\treturn FALSE;\t\r\n}\r\n\r\n\r\nvoid scan1_freedir(struct dir_info *dir)\r\n{\r\n\tif(dir->pathname[0] != '\\0')\r\n\t\tclosedir(dir->linuxdir);\r\n}\r\n\r\n\r\nvoid scan2_freedir(struct directory *dir)\r\n{\r\n\tif(dir->index)\r\n\t\tfree(dir->index);\r\n\tfree(dir->buff);\r\n}\r\n\r\n\r\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\r\n{\r\n\tstruct stat buf;\r\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\r\n\tstruct dir_ent *dir_ent;\r\n\t\r\n\tif(dir_info == NULL)\r\n\t\treturn;\r\n\r\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\r\n\r\n\tif(pathname[0] == '\\0') {\r\n\t\t/* dummy top level directory, if multiple sources specified on command line */\r\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\r\n\t\tbuf.st_uid = getuid();\r\n\t\tbuf.st_gid = getgid();\r\n\t\tbuf.st_mtime = time(NULL);\r\n\t\tbuf.st_dev = 0;\r\n\t\tbuf.st_ino = 0;\r\n\t} else if(lstat(pathname, &buf) == -1) {\r\n\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", pathname, strerror(errno));\r\n\t\treturn;\r\n\t}\r\n\r\n\tdir_ent->inode = lookup_inode(&buf);\r\n\tif(root_inode_number) {\r\n\t\tdir_ent->inode->inode_number = root_inode_number;\r\n\t\tdir_inode_no --;\r\n\t}\r\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\r\n\tdir_ent->dir = dir_info;\r\n\tdir_ent->our_dir = NULL;\r\n\tdir_ent->data = NULL;\r\n\tdir_info->dir_ent = dir_ent;\r\n\r\n\tif(sorted)\r\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\r\n\tqueue_put(to_reader, dir_info);\r\n\tif(sorted)\r\n\t\tsort_files_and_write(dir_info);\r\n\tif(progress)\r\n\t\tenable_progress_bar();\r\n\tdir_scan2(inode, dir_info);\r\n\tdir_ent->inode->inode = *inode;\r\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\r\n}\r\n\r\n\r\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths, int (_readdir)(char *, char *, struct dir_info *))\r\n{\r\n\tstruct dir_info *dir, *sub_dir;\r\n\tstruct stat buf;\r\n\tchar filename[8192], dir_name[8192];\r\n\tstruct pathnames *new;\r\n\r\n\tif((dir = scan1_opendir(pathname)) == NULL) {\r\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\r\n\t\tgoto error;\r\n\t}\r\n\r\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\r\n\r\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\r\n\t\t\tcontinue;\r\n\r\n\t\tif(lstat(filename, &buf) == -1) {\r\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", filename, strerror(errno));\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\r\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\r\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\r\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\r\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\r\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\r\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\r\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\\n\", filename, buf.st_mode & S_IFMT);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif(old_exclude) {\r\n\t\t\tif(old_excluded(filename, &buf))\r\n\t\t\t\tcontinue;\r\n\t\t} else {\r\n\t\t\tif(excluded(paths, dir_name, &new))\r\n\t\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\r\n\t\t\tif((sub_dir = dir_scan1(filename, new, scan1_readdir)) == NULL)\r\n\t\t\t\tcontinue;\r\n\t\t\tdir->directory_count ++;\r\n\t\t} else\r\n\t\t\tsub_dir = NULL;\r\n\r\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\r\n\t}\r\n\r\n\tscan1_freedir(dir);\r\n\tsort_directory(dir);\r\n\r\nerror:\r\n\treturn dir;\r\n}\r\n\r\n\r\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\r\n{\r\n\tint squashfs_type;\r\n\tint duplicate_file;\r\n\tchar *pathname = dir_info->pathname;\r\n\tstruct directory dir;\r\n\tstruct dir_ent *dir_ent;\r\n\t\r\n\tscan2_init_dir(&dir);\r\n\t\r\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\r\n\t\tstruct inode_info *inode_info = dir_ent->inode;\r\n\t\tstruct stat *buf = &inode_info->buf;\r\n\t\tchar *filename = dir_ent->pathname;\r\n\t\tchar *dir_name = dir_ent->name;\r\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\r\n\r\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\r\n\t\t\tswitch(buf->st_mode & S_IFMT) {\r\n\t\t\t\tcase S_IFREG:\r\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\r\n\t\t\t\t\twrite_file(inode, dir_ent, &duplicate_file);\r\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase S_IFDIR:\r\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\r\n\t\t\t\t\tdir_scan2(inode, dir_ent->dir);\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase S_IFLNK:\r\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\r\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\r\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\r\n\t\t\t\t\tsym_count ++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase S_IFCHR:\r\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\r\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\r\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\r\n\t\t\t\t\tdev_count ++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase S_IFBLK:\r\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\r\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\r\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\r\n\t\t\t\t\tdev_count ++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase S_IFIFO:\r\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\r\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\r\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\r\n\t\t\t\t\tfifo_count ++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase S_IFSOCK:\r\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\r\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\r\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\r\n\t\t\t\t\tsock_count ++;\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tBAD_ERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\r\n\t\t\t}\r\n\t\t\tdir_ent->inode->inode = *inode;\r\n\t\t\tdir_ent->inode->type = squashfs_type;\r\n\t\t } else {\r\n\t\t\t*inode = dir_ent->inode->inode;\r\n\t\t\tsquashfs_type = dir_ent->inode->type;\r\n\t\t\tswitch(squashfs_type) {\r\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\r\n\t\t\t\t\tif(!sorted)\r\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\r\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\r\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\r\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\r\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\r\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\r\n\t\tupdate_progress_bar();\r\n\t}\r\n\r\n\twrite_dir(inode, dir_info, &dir);\r\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\r\n\r\n\tscan2_freedir(&dir);\r\n}\r\n\r\n\r\nunsigned int slog(unsigned int block)\r\n{\r\n\tint i;\r\n\r\n\tfor(i = 12; i <= 20; i++)\r\n\t\tif(block == (1 << i))\r\n\t\t\treturn i;\r\n\treturn 0;\r\n}\r\n\r\n\r\nint old_excluded(char *filename, struct stat *buf)\r\n{\r\n\tint i;\r\n\r\n\tfor(i = 0; i < exclude; i++)\r\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\r\n\t\t\treturn TRUE;\r\n\treturn FALSE;\r\n}\r\n\r\n\r\n#define ADD_ENTRY(buf) \\\r\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\r\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\r\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\r\n\t}\\\r\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\r\n\texclude_paths[exclude++].st_ino = buf.st_ino;\r\nint old_add_exclude(char *path)\r\n{\r\n\tint i;\r\n\tchar filename[4096];\r\n\tstruct stat buf;\r\n\r\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\r\n\t\tif(lstat(path, &buf) == -1) {\r\n\t\t\tERROR(\"Cannot stat exclude dir/file %s because %s, ignoring\", path, strerror(errno));\r\n\t\t\treturn TRUE;\r\n\t\t}\r\n\t\tADD_ENTRY(buf);\r\n\t\treturn TRUE;\r\n\t}\r\n\r\n\tfor(i = 0; i < source; i++) {\r\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\r\n\t\tif(lstat(filename, &buf) == -1) {\r\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\r\n\t\t\t\tERROR(\"Cannot stat exclude dir/file %s because %s, ignoring\", filename, strerror(errno));\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tADD_ENTRY(buf);\r\n\t}\r\n\treturn TRUE;\r\n}\r\n\r\n\r\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\r\n{\r\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\r\n\t\t\t\t* (old_root_entries + 1))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\r\n\r\n\tstrcpy(old_root_entry[old_root_entries].name, name);\r\n\told_root_entry[old_root_entries].inode = inode;\r\n\told_root_entry[old_root_entries].inode_number = inode_number;\r\n\told_root_entry[old_root_entries++].type = type;\r\n}\r\n\r\n\r\nvoid initialise_threads()\r\n{\r\n\tint i;\r\n\tsigset_t sigmask, old_mask;\r\n\r\n\tsigemptyset(&sigmask);\r\n\tsigaddset(&sigmask, SIGINT);\r\n\tsigaddset(&sigmask, SIGQUIT);\r\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\r\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\r\n\r\n\tsignal(SIGUSR1, sigusr1_handler);\r\n\r\n\tif(processors == -1) {\r\n#ifndef linux\r\n\t\tint mib[2];\r\n\t\tsize_t len = sizeof(processors);\r\n\r\n\t\tmib[0] = CTL_HW;\r\n#ifdef HW_AVAILCPU\r\n\t\tmib[1] = HW_AVAILCPU;\r\n#else\r\n\t\tmib[1] = HW_NCPU;\r\n#endif\r\n\r\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\r\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\r\n\t\t\tprocessors = 1;\r\n\t\t}\r\n#else\r\n\t\tprocessors = get_nprocs();\r\n#endif\r\n\t}\r\n\r\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\r\n\tdeflator_thread = &thread[2];\r\n\tfrag_deflator_thread = &deflator_thread[processors];\r\n\r\n\tto_reader = queue_init(1);\r\n\tfrom_reader = queue_init(reader_buffer_size);\r\n\tto_writer = queue_init(writer_buffer_size);\r\n\tfrom_writer = queue_init(1);\r\n\tfrom_deflate = queue_init(reader_buffer_size);\r\n\tto_frag = queue_init(fragment_buffer_size);\r\n\treader_buffer = cache_init(block_size, reader_buffer_size);\r\n\twriter_buffer = cache_init(block_size, writer_buffer_size);\r\n\tfragment_buffer = cache_init(block_size, fragment_buffer_size);\r\n\tpthread_create(&thread[0], NULL, reader, NULL);\r\n\tpthread_create(&thread[1], NULL, writer, NULL);\r\n\tpthread_create(&progress_thread, NULL, progress_thrd, NULL);\r\n\tpthread_mutex_init(&fragment_mutex, NULL);\r\n\tpthread_cond_init(&fragment_waiting, NULL);\r\n\r\n\tfor(i = 0; i < processors; i++) {\r\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\r\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\r\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\r\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\r\n\t}\r\n\r\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\r\n\t\t\tprocessors == 1 ? \"\" : \"s\");\r\n\r\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\r\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\r\n}\r\n\r\n\r\nlong long write_inode_lookup_table()\r\n{\r\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\r\n\r\n\tif(inode_count == sinode_count)\r\n\t\tgoto skip_inode_hash_table;\r\n\r\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\r\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\r\n\r\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\r\n\t\tstruct inode_info *inode = inode_info[i];\r\n\r\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\r\n\r\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\r\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\r\n\r\n\t\t\tif(!swap)\r\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\r\n\t\t\telse\r\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\r\n\r\n\t\t}\r\n\t}\r\n\r\nskip_inode_hash_table:\r\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\r\n}\r\n\r\n\r\nchar *get_component(char *target, char *targname)\r\n{\r\n\twhile(*target == '/')\r\n\t\ttarget ++;\r\n\r\n\twhile(*target != '/' && *target!= '\\0')\r\n\t\t*targname ++ = *target ++;\r\n\r\n\t*targname = '\\0';\r\n\r\n\treturn target;\r\n}\r\n\r\n\r\nvoid free_path(struct pathname *paths)\r\n{\r\n\tint i;\r\n\r\n\tfor(i = 0; i < paths->names; i++) {\r\n\t\tif(paths->name[i].paths)\r\n\t\t\tfree_path(paths->name[i].paths);\r\n\t\tfree(paths->name[i].name);\r\n\t\tif(paths->name[i].preg) {\r\n\t\t\tregfree(paths->name[i].preg);\r\n\t\t\tfree(paths->name[i].preg);\r\n\t\t}\r\n\t}\r\n\r\n\tfree(paths);\r\n}\r\n\r\n\r\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\r\n{\r\n\tchar targname[1024];\r\n\tint i, error;\r\n\r\n\ttarget = get_component(target, targname);\r\n\r\n\tif(paths == NULL) {\r\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\r\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\r\n\r\n\t\tpaths->names = 0;\r\n\t\tpaths->name = NULL;\r\n\t}\r\n\r\n\tfor(i = 0; i < paths->names; i++)\r\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\r\n\t\t\tbreak;\r\n\r\n\tif(i == paths->names) {\r\n\t\t/* allocate new name entry */\r\n\t\tpaths->names ++;\r\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\r\n\t\tpaths->name[i].name = strdup(targname);\r\n\t\tpaths->name[i].paths = NULL;\r\n\t\tif(use_regex) {\r\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\r\n\t\t\terror = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB);\r\n\t\t\tif(error) {\r\n\t\t\t\tchar str[1024];\r\n\r\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\r\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\r\n\t\t\t}\r\n\t\t} else\r\n\t\t\tpaths->name[i].preg = NULL;\r\n\r\n\t\tif(target[0] == '\\0')\r\n\t\t\t/* at leaf pathname component */\r\n\t\t\tpaths->name[i].paths = NULL;\r\n\t\telse\r\n\t\t\t/* recurse adding child components */\r\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\r\n\t} else {\r\n\t\t/* existing matching entry */\r\n\t\tif(paths->name[i].paths == NULL) {\r\n\t\t\t/* No sub-directory which means this is the leaf component of a\r\n\t\t   \t   pre-existing exclude which subsumes the exclude currently\r\n\t\t   \t   being added, in which case stop adding components */\r\n\t\t} else if(target[0] == '\\0') {\r\n\t\t\t/* at leaf pathname component and child components exist from more\r\n\t\t       specific excludes, delete as they're subsumed by this exclude\r\n\t\t\t*/\r\n\t\t\tfree_path(paths->name[i].paths);\r\n\t\t\tpaths->name[i].paths = NULL;\r\n\t\t} else\r\n\t\t\t/* recurse adding child components */\r\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\r\n\t}\r\n\r\n\treturn paths;\r\n}\r\n\r\n\r\nvoid add_exclude(char *target)\r\n{\r\n\r\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 || strncmp(target, \"../\", 3) == 0)\r\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with -wildcards or -regex options\\n\");\t\r\n\telse if(strncmp(target, \"... \", 4) == 0)\r\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\r\n\telse\t\r\n\t\tpath = add_path(path, target, target);\r\n}\r\n\r\n\r\nvoid display_path(int depth, struct pathname *paths)\r\n{\r\n\tint i, n;\r\n\r\n\tif(paths == NULL)\r\n\t\treturn;\r\n\r\n\tfor(i = 0; i < paths->names; i++) {\r\n\t\tfor(n = 0; n < depth; n++)\r\n\t\t\tprintf(\"\\t\");\r\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\r\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\r\n\t}\r\n}\r\n\r\n\r\nvoid display_path2(struct pathname *paths, char *string)\r\n{\r\n\tint i;\r\n\tchar path[1024];\r\n\r\n\tif(paths == NULL) {\r\n\t\tprintf(\"%s\\n\", string);\r\n\t\treturn;\r\n\t}\r\n\r\n\tfor(i = 0; i < paths->names; i++) {\r\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\r\n\t\tdisplay_path2(paths->name[i].paths, path);\r\n\t}\r\n}\r\n\r\n\r\nstruct pathnames *init_subdir()\r\n{\r\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\r\n\tnew->count = 0;\r\n\treturn new;\r\n}\r\n\r\n\r\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\r\n{\r\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\r\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\r\n\r\n\tpaths->path[paths->count++] = path;\r\n\treturn paths;\r\n}\r\n\r\n\r\nvoid free_subdir(struct pathnames *paths)\r\n{\r\n\tfree(paths);\r\n}\r\n\r\n\r\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\r\n{\r\n\tint i, n, res;\r\n\t\t\r\n\tif(paths == NULL) {\r\n\t\t*new = NULL;\r\n\t\treturn FALSE;\r\n\t}\r\n\r\n\r\n\t*new = init_subdir();\r\n\tif(stickypath)\r\n\t\t*new = add_subdir(*new, stickypath);\r\n\r\n\tfor(n = 0; n < paths->count; n++) {\r\n\t\tstruct pathname *path = paths->path[n];\r\n\r\n\t\tfor(i = 0; i < path->names; i++) {\r\n\t\t\tint match = use_regex ?\r\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\r\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\r\n\r\n\t\t\tif(match && path->name[i].paths == NULL) {\r\n\t\t\t\t/* match on a leaf component, any subdirectories in the\r\n\t\t\t\t * filesystem should be excluded */\r\n\t\t\t\tres = TRUE;\r\n\t\t\t\tgoto empty_set;\r\n\t\t\t}\r\n\r\n\t\t\tif(match)\r\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\r\n\t\t\t\t * the new set of subdirectories to scan for this name */\r\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\r\n\t\t}\r\n\t}\r\n\r\n\tif((*new)->count == 0) {\r\n\t\t\t/* no matching names found, return empty new search set */\r\n\t\t\tres = FALSE;\r\n\t\t\tgoto empty_set;\r\n\t}\r\n\r\n\t/* one or more matches with sub-directories found (no leaf matches).\r\n\t * Return new set */\r\n\treturn FALSE;\r\n\r\nempty_set:\r\n\tfree_subdir(*new);\r\n\t*new = NULL;\r\n\treturn res;\r\n}\r\n\r\n\r\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\r\n#define RECOVER_ID_SIZE 28\r\n\r\nvoid write_recovery_data(squashfs_super_block *sBlk)\r\n{\r\n\tint recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\r\n\tpid_t pid = getpid();\r\n\tchar *metadata;\r\n\tchar header[] = RECOVER_ID;\r\n\r\n\tif(recover == FALSE) {\r\n\t\tprintf(\"No recovery data option specified.\\n\");\r\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\r\n\t\treturn;\r\n\t}\r\n\r\n\tif((metadata = malloc(bytes)) == NULL)\r\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in write_recovery_data\\n\");\r\n\r\n\tread_bytes(fd, sBlk->inode_table_start, bytes, metadata);\r\n\r\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\", getbase(destination_file), pid);\r\n\tif((recoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1)\r\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  Aborting\\n\", strerror(errno));\r\n\t\t\r\n\tif(write(recoverfd, header, RECOVER_ID_SIZE) == -1)\r\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\r\n\r\n\tif(write(recoverfd, sBlk, sizeof(squashfs_super_block)) == -1)\r\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\r\n\r\n\tif(write(recoverfd, metadata, bytes) == -1)\r\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\r\n\r\n\tclose(recoverfd);\r\n\tfree(metadata);\r\n\t\r\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\r\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\r\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file, recovery_file);\r\n\tprintf(\"to restore filesystem\\n\\n\");\r\n}\r\n\r\n\r\nvoid read_recovery_data(char *recovery_file, char *destination_file)\r\n{\r\n\tint fd, recoverfd, bytes;\r\n\tsquashfs_super_block orig_sBlk, sBlk;\r\n\tchar *metadata;\r\n\tint readbytes;\r\n\tstruct stat buf;\r\n\tchar header[] = RECOVER_ID;\r\n\tchar header2[RECOVER_ID_SIZE];\r\n\r\n\tif((recoverfd = open(recovery_file, O_RDONLY)) == -1)\r\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\", strerror(errno));\r\n\r\n\tif(stat(destination_file, &buf) == -1)\r\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\", strerror(errno));\r\n\r\n\tif((fd = open(destination_file, O_RDWR)) == -1)\r\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\", strerror(errno));\r\n\r\n\tif(read(recoverfd, header2, RECOVER_ID_SIZE) == -1)\r\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\r\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\r\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\r\n\r\n\tif(read(recoverfd, &sBlk, sizeof(squashfs_super_block)) == -1)\r\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\r\n\r\n\tread_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &orig_sBlk);\r\n\r\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4, sizeof(squashfs_super_block) - 4) != 0)\r\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to match\\n\");\r\n\r\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\r\n\r\n\tif((metadata = malloc(bytes)) == NULL)\r\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in read_recovery_data\\n\");\r\n\r\n\tif((readbytes = read(recoverfd, metadata, bytes)) == -1)\r\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\r\n\r\n\tif(readbytes != bytes)\r\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\r\n\r\n\twrite_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &sBlk);\r\n\r\n\twrite_bytes(fd, sBlk.inode_table_start, bytes, metadata);\r\n\r\n\tclose(recoverfd);\r\n\tclose(fd);\r\n\r\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\", recovery_file);\r\n\t\r\n\texit(0);\r\n}\r\n\r\n\r\n#define VERSION() \\\r\n\tprintf(\"mksquashfs version 3.4 (2008/08/26)\\n\");\\\r\n\tprintf(\"copyright (C) 2008 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\r\n\tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\r\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\r\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\r\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\r\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\r\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\r\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\r\n\tprintf(\"GNU General Public License for more details.\\n\");\r\nint main(int argc, char *argv[])\r\n{\r\n\tstruct stat buf, source_buf;\r\n\tint i;\r\n\tsquashfs_super_block sBlk;\r\n\tchar *b, *root_name = NULL;\r\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\r\n\tsquashfs_inode inode;\r\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT, fragmentb_mbytes = FRAGMENT_BUFFER_DEFAULT;\r\n\tint s_minor;\r\n\r\n#if __BYTE_ORDER == __BIG_ENDIAN\r\n\tbe = TRUE;\r\n#else\r\n\tbe = FALSE;\r\n#endif\r\n\r\n\tpthread_mutex_init(&progress_mutex, NULL);\r\n\tblock_log = slog(block_size);\r\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\r\n\t\tVERSION();\r\n\t\texit(0);\r\n\t}\r\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\r\n\tif(i < 3)\r\n\t\tgoto printOptions;\r\n\tsource_path = argv + 1;\r\n\tsource = i - 2;\r\n\tfor(; i < argc; i++) {\r\n\t\tif(strcmp(argv[i], \"-recover\") == 0) {\r\n\t\t\tif(++i == argc) {\r\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\r\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\r\n\t\t\trecover = FALSE;\r\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\r\n\t\t\told_exclude = FALSE;\r\n\t\t\tuse_regex = FALSE;\r\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\r\n\t\t\told_exclude = FALSE;\r\n\t\t\tuse_regex = TRUE;\r\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\r\n\t\t\tsparse_files = FALSE;\r\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\r\n\t\t\tprogress = FALSE;\r\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\r\n\t\t\texportable = FALSE;\r\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\r\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\r\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tif(processors < 1) {\r\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\r\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\r\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tif(readb_mbytes < 1) {\r\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\r\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\r\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tif(writeb_mbytes < 1) {\r\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t} else if(strcmp(argv[i], \"-fragment-queue\") == 0) {\r\n\t\t\tif((++i == argc) || (fragmentb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\r\n\t\t\t\tERROR(\"%s: -fragment-queue missing or invalid queue size\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tif(fragmentb_mbytes < 1) {\r\n\t\t\t\tERROR(\"%s: -fragment-queue should be 1 megabyte or larger\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\r\n\t\t\tif(++i == argc) {\r\n\t\t\t\tERROR(\"%s: -b missing block size\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tblock_size = strtol(argv[i], &b, 10);\r\n\t\t\tif(*b == 'm' || *b == 'M')\r\n\t\t\t\tblock_size *= 1048576;\r\n\t\t\telse if(*b == 'k' || *b == 'K')\r\n\t\t\t\tblock_size *= 1024;\r\n\t\t\telse if(*b != '\\0') {\r\n\t\t\t\tERROR(\"%s: -b invalid block size\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tif((block_log = slog(block_size)) == 0) {\r\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 1Mbyte\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\r\n\t\t\tif(++i == argc) {\r\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\r\n\t\t\tduplicate_checking = FALSE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\r\n\t\t\tno_fragments = TRUE;\r\n\r\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\r\n\t\t\talways_use_fragments = TRUE;\r\n\r\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\r\n\t\t\tif(++i == argc) {\r\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\r\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\r\n\t\t\tglobal_uid = global_gid = 0;\r\n\r\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\r\n\t\t\tif(++i == argc) {\r\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\r\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\r\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\r\n\t\t\t\t\texit(1);\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\r\n\t\t\t\tif(uid)\r\n\t\t\t\t\tglobal_uid = uid->pw_uid;\r\n\t\t\t\telse {\r\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\r\n\t\t\t\t\texit(1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\r\n\t\t\tif(++i == argc) {\r\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\r\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\r\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\r\n\t\t\t\t\texit(1);\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\r\n\t\t\t\tif(gid)\r\n\t\t\t\t\tglobal_gid = gid->gr_gid;\r\n\t\t\t\telse {\r\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\r\n\t\t\t\t\texit(1);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\r\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\r\n\t\t\tnoI = TRUE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\r\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\r\n\t\t\tnoD = TRUE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\r\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\r\n\t\t\tnoF = TRUE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\r\n\t\t\tnopad = TRUE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\r\n\t\t\tcheck_data = TRUE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-info\") == 0) {\r\n\t\t\tsilent = FALSE;\r\n\t\t\tprogress = FALSE;\r\n\t\t}\r\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\r\n\t\t\tbe = TRUE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\r\n\t\t\tbe = FALSE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\r\n\t\t\tbreak;\r\n\r\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\r\n\t\t\tdelete = TRUE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\r\n\t\t\tkeep_as_directory = TRUE;\r\n\r\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\r\n\t\t\tif(++i == argc) {\r\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\r\n\t\t\t\texit(1);\r\n\t\t\t}\t\r\n\t\t\troot_name = argv[i];\r\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\r\n\t\t\tVERSION();\r\n\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\r\n\t\t\tgLzmaEnable= 0;\r\n\t\t}else {\r\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\r\nprintOptions:\r\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\r\n\t\t\tERROR(\"\\nOptions are\\n\");\r\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\r\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data using recovery file <name>\\n\");\r\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery file\\n\");\r\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\r\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\r\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\r\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\r\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\r\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\r\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\r\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\r\n\t\t\tERROR(\"-fragment-queue <size>\\tSet fagment queue to <size> Mbytes.  Default %d Mbytes\\n\", FRAGMENT_BUFFER_DEFAULT);\r\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\r\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\r\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\r\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\r\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\r\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\r\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\r\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\r\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\r\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\r\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\r\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\r\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\r\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\r\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\r\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\r\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\r\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\r\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\r\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\r\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\r\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\r\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\r\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\r\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\r\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\r\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\r\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\r\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\r\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards (globbing) to be used in\\n\\t\\t\\texclude dirs/files\\n\");\r\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to be used in exclude\\n\\t\\t\\tdirs/files\\n\");\r\n\t\t\texit(1);\r\n\t\t}\r\n\t}\r\n\r\n\treader_buffer_size = readb_mbytes << (20 - block_log);\r\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\r\n\tfragment_buffer_size = fragmentb_mbytes << (20 - block_log);\r\n\r\n\tif(block_size <= 65536 && sparse_files == FALSE)\r\n\t\ts_minor = 0;\r\n\telse\r\n\t\ts_minor = SQUASHFS_MINOR;\r\n\r\n\tfor(i = 0; i < source; i++)\r\n\t\tif(lstat(source_path[i], &source_buf) == -1) {\r\n\t\t\tfprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\r\n\t\t\tEXIT_MKSQUASHFS();\r\n\t\t}\r\n\r\n\tdestination_file = argv[source + 1];\r\n\tif(stat(argv[source + 1], &buf) == -1) {\r\n\t\tif(errno == ENOENT) { /* Does not exist */\r\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\r\n\t\t\t\tperror(\"Could not create destination file\");\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tdelete = TRUE;\r\n\t\t} else {\r\n\t\t\tperror(\"Could not stat destination file\");\r\n\t\t\texit(1);\r\n\t\t}\r\n\r\n\t} else {\r\n\t\tif(S_ISBLK(buf.st_mode)) {\r\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\r\n\t\t\t\tperror(\"Could not open block device as destination\");\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t\tblock_device = 1;\r\n\r\n\t\t} else if(S_ISREG(buf.st_mode))\t {\r\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\r\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\r\n\t\t\t\texit(1);\r\n\t\t\t}\r\n\t\t}\r\n\t\telse {\r\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\r\n\t\t\texit(1);\r\n\t\t}\r\n\r\n\t}\r\n\r\n\tsignal(SIGTERM, sighandler2);\r\n\tsignal(SIGINT, sighandler2);\r\n\r\n\t/* process the exclude files - must be done afer destination file has been possibly created */\r\n\tfor(i = source + 2; i < argc; i++)\r\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\r\n\t\t\tFILE *fd;\r\n\t\t\tchar filename[16385];\r\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\r\n\t\t\t\tperror(\"Could not open exclude file...\");\r\n\t\t\t\tEXIT_MKSQUASHFS();\r\n\t\t\t}\r\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\r\n\t\t\t\t\tif(old_exclude)\r\n\t\t\t\t\t\told_add_exclude(filename);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tadd_exclude(filename);\r\n\t\t\tfclose(fd);\r\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\r\n\t\t\tbreak;\r\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\r\n\t\t\ti++;\r\n\r\n\tif(i != argc) {\r\n\t\tif(++i == argc) {\r\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\r\n\t\t\tEXIT_MKSQUASHFS();\r\n\t\t}\r\n\t\twhile(i < argc)\r\n\t\t\tif(old_exclude)\r\n\t\t\t\told_add_exclude(argv[i++]);\r\n\t\t\telse\r\n\t\t\t\tadd_exclude(argv[i++]);\r\n\t}\r\n\r\n\t/* process the sort files - must be done afer the exclude files  */\r\n\tfor(i = source + 2; i < argc; i++)\r\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\r\n\t\t\tread_sort_file(argv[++i], source, source_path);\r\n\t\t\tsorted ++;\r\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\r\n\t\t\tbreak;\r\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\r\n\t\t\ti++;\r\n\r\n#ifdef SQUASHFS_TRACE\r\n\tprogress = FALSE;\r\n#endif\r\n\r\n\tif(!delete) {\r\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\r\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\r\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\r\n\t\t\tEXIT_MKSQUASHFS();\r\n\t\t}\r\n\r\n\t\tbe = orig_be;\r\n\t\tblock_log = slog(block_size = sBlk.block_size);\r\n\t\ts_minor = sBlk.s_minor;\r\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\r\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\r\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\r\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\r\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\r\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\r\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\r\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\r\n\t}\r\n\r\n\tinitialise_threads();\r\n\r\n\tif(delete) {\r\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\r\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\r\n\t\tbytes = sizeof(squashfs_super_block);\r\n\t} else {\r\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\r\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\r\n\t\tinode_dir_parent_inode;\r\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\r\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\r\n\r\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\r\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\r\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\r\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\r\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\r\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\r\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\r\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\r\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\r\n\t\t\tEXIT_MKSQUASHFS();\r\n\t\t}\r\n\t\tif((fragments = sBlk.fragments))\r\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \r\n\r\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\r\n\t\t\t\"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\r\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\r\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\r\n\r\n\t\tcompressed_data = (inode_dir_offset + inode_dir_file_size) & ~(SQUASHFS_METADATA_SIZE - 1);\r\n\t\tuncompressed_data = (inode_dir_offset + inode_dir_file_size) & (SQUASHFS_METADATA_SIZE - 1);\r\n\t\t\r\n\t\t/* save original filesystem state for restoring ... */\r\n\t\tsfragments = fragments;\r\n\t\tsbytes = bytes;\r\n\t\tsinode_count = sBlk.inodes;\r\n\t\tscache_bytes = root_inode_offset + root_inode_size;\r\n\t\tsdirectory_cache_bytes = uncompressed_data;\r\n\t\tsdata_cache = (char *)malloc(scache_bytes);\r\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes);\r\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\r\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\r\n\t\tsinode_bytes = root_inode_start;\r\n\t\tsuid_count = uid_count;\r\n\t\tsguid_count = guid_count;\r\n\t\tstotal_bytes = total_bytes;\r\n\t\tstotal_inode_bytes = total_inode_bytes;\r\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\r\n\t\tsfile_count = file_count;\r\n\t\tssym_count = sym_count;\r\n\t\tsdev_count = dev_count;\r\n\t\tsdir_count = dir_count + 1;\r\n\t\tsfifo_count = fifo_count;\r\n\t\tssock_count = sock_count;\r\n\t\tsdup_files = dup_files;\r\n\t\twrite_recovery_data(&sBlk);\r\n\t\trestore = TRUE;\r\n\t\tif(setjmp(env))\r\n\t\t\tgoto restore_filesystem;\r\n\t\tsignal(SIGTERM, sighandler);\r\n\t\tsignal(SIGINT, sighandler);\r\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\r\n\r\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\r\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\r\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\r\n\t\t */\r\n\t\tinode_bytes = inode_size = root_inode_start;\r\n\t\tdirectory_size = last_directory_block;\r\n\t\tcache_size = root_inode_offset + root_inode_size;\r\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\r\n\t\tif(root_name) {\r\n\t\t\tsdirectory_bytes = last_directory_block;\r\n\t\t\tsdirectory_compressed_bytes = 0;\r\n\t\t\troot_inode_number = inode_dir_parent_inode;\r\n\t\t\tdir_inode_no = sBlk.inodes + 2;\r\n\t\t\tdirectory_bytes = last_directory_block;\r\n\t\t\tdirectory_cache_bytes = uncompressed_data;\r\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\r\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\r\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\r\n\t\t\ttotal_directory_bytes += compressed_data;\r\n\t\t\tdir_count ++;\r\n\t\t} else {\r\n\t\t\tsdirectory_compressed_bytes = last_directory_block - inode_dir_start_block;\r\n\t\t\tsdirectory_compressed = malloc(sdirectory_compressed_bytes);\r\n\t\t\tmemcpy(sdirectory_compressed, directory_table + inode_dir_start_block, sdirectory_compressed_bytes); \r\n\t\t\tsdirectory_bytes = inode_dir_start_block;\r\n\t\t\troot_inode_number = inode_dir_inode_number;\r\n\t\t\tdir_inode_no = sBlk.inodes + 1;\r\n\t\t\tdirectory_bytes = inode_dir_start_block;\r\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\r\n\t\t\tcache_bytes = root_inode_offset;\r\n\t\t}\r\n\r\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\r\n\t}\r\n\r\n#if __BYTE_ORDER == __BIG_ENDIAN\r\n\tswap = !be;\r\n#else\r\n\tswap = be;\r\n#endif\r\n\r\n\tblock_offset = check_data ? 3 : 2;\r\n\r\n\tif(path || stickypath) {\r\n\t\tpaths = init_subdir();\r\n\t\tif(path)\r\n\t\t\tpaths = add_subdir(paths, path);\r\n\t\tif(stickypath)\r\n\t\t\tpaths = add_subdir(paths, stickypath);\r\n\t}\r\n\r\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\r\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\r\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\r\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\r\n\telse\r\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\r\n\tsBlk.root_inode = inode;\r\n\tsBlk.inodes = inode_count;\r\n//\tsBlk.s_magic = SQUASHFS_MAGIC;\r\n\tif (gLzmaEnable)\r\n\t\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\r\n\telse\r\n\t\tsBlk.s_magic = SQUASHFS_MAGIC;\r\n    \r\n\tsBlk.s_major = SQUASHFS_MAJOR;\r\n\tsBlk.s_minor = s_minor;\r\n\tsBlk.block_size = block_size;\r\n\tsBlk.block_log = block_log;\r\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\r\n\tsBlk.mkfs_time = time(NULL);\r\n\r\nrestore_filesystem:\r\n\tif(progress && estimated_uncompressed) {\r\n\t\tdisable_progress_bar();\r\n\t\tprogress_bar(cur_uncompressed, estimated_uncompressed, columns);\r\n\t}\r\n\r\n\twrite_fragment();\r\n\tsBlk.fragments = fragments;\r\n\tif(interrupted < 2) {\r\n\t\tunlock_fragments();\r\n\t\tpthread_mutex_lock(&fragment_mutex);\r\n\t\twhile(fragments_outstanding) {\r\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\r\n\t\t\tsched_yield();\r\n\t\t\tpthread_mutex_lock(&fragment_mutex);\r\n\t\t}\r\n\t\tqueue_put(to_writer, NULL);\r\n\t\tif(queue_get(from_writer) != 0)\r\n\t\t\tEXIT_MKSQUASHFS();\r\n\t}\r\n\r\n\tsBlk.inode_table_start = write_inodes();\r\n\tsBlk.directory_table_start = write_directories();\r\n\tsBlk.fragment_table_start = write_fragment_table();\r\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\r\n\r\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\r\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\r\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\r\n\tif(exportable)\r\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\r\n\r\n\tsBlk.no_uids = uid_count;\r\n\tif(sBlk.no_uids) {\r\n\t\tif(!swap)\r\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\r\n\t\telse {\r\n\t\t\tsquashfs_uid uids_copy[uid_count];\r\n\r\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\r\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\r\n\t\t}\r\n\t\tsBlk.uid_start = bytes;\r\n\t\tbytes += uid_count * sizeof(squashfs_uid);\r\n\t} else\r\n\t\tsBlk.uid_start = 0;\r\n\r\n\tsBlk.no_guids = guid_count;\r\n\tif(sBlk.no_guids) {\r\n\t\tif(!swap)\r\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\r\n\t\telse {\r\n\t\t\tsquashfs_uid guids_copy[guid_count];\r\n\r\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\r\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\r\n\t\t}\r\n\t\tsBlk.guid_start = bytes;\r\n\t\tbytes += guid_count * sizeof(squashfs_uid);\r\n\t} else\r\n\t\tsBlk.guid_start = 0;\r\n\r\n\tsBlk.bytes_used = bytes;\r\n\r\n\tif(!swap)\r\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\r\n\telse {\r\n\t\tsquashfs_super_block sBlk_copy;\r\n\r\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \r\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\r\n\t}\r\n\r\n\tif(!nopad && (i = bytes & (4096 - 1))) {\r\n\t\tchar temp[4096] = {0};\r\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\r\n\t}\r\n\r\n\tclose(fd);\r\n\r\n\tif(recovery_file[0] != '\\0')\r\n\t\tunlink(recovery_file);\r\n\r\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\r\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\r\n\t\tsizeof(squashfs_super_block);\r\n\r\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\r\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\r\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\r\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\r\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\r\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\r\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\r\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\r\n\t\tinode_bytes, inode_bytes / 1024.0);\r\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\r\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\r\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\r\n\t\tdirectory_bytes, directory_bytes / 1024.0);\r\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\r\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\r\n\tif(duplicate_checking)\r\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\r\n\telse\r\n\t\tprintf(\"No duplicate files removed\\n\");\r\n\tprintf(\"Number of inodes %d\\n\", inode_count);\r\n\tprintf(\"Number of files %d\\n\", file_count);\r\n\tif(!no_fragments)\r\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\r\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\r\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\r\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\r\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\r\n\tprintf(\"Number of directories %d\\n\", dir_count);\r\n\tprintf(\"Number of uids %d\\n\", uid_count);\r\n\r\n\tfor(i = 0; i < uid_count; i++) {\r\n\t\tint uid = uids[i];\r\n\t\tstruct passwd *user = getpwuid(uid);\r\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\r\n\t}\r\n\r\n\tprintf(\"Number of gids %d\\n\", guid_count);\r\n\r\n\tfor(i = 0; i < guid_count; i++) {\r\n\t\tstruct group *group = getgrgid(guids[i]);\r\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\r\n\t}\r\n\r\n\treturn 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/read_fs.c",
    "content": "/* Modifications were made by Cisco Systems, Inc. on or before Thu Feb 16 11:28:44 PST 2012 */\n/*\r\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\r\n *\r\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\r\n * Phillip Lougher <phillip@lougher.demon.co.uk>\r\n *\r\n * This program is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU General Public License\r\n * as published by the Free Software Foundation; either version 2,\r\n * or (at your option) any later version.\r\n *\r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n * GNU General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU General Public License\r\n * along with this program; if not, write to the Free Software\r\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r\n *\r\n * read_fs.c\r\n */\r\n\r\nextern void read_bytes(int, long long, int, char *);\r\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\r\n\r\n#define TRUE 1\r\n#define FALSE 0\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n#include <sys/stat.h>\r\n#include <fcntl.h>\r\n#include <errno.h>\r\n#include <string.h>\r\n#include <zlib.h>\r\n#include <sys/mman.h>\r\n\r\n#include \"LzmaDec.h\"\r\n#include \"lzmainterface.h\"\r\n\r\n#ifndef linux\r\n#define __BYTE_ORDER BYTE_ORDER\r\n#define __BIG_ENDIAN BIG_ENDIAN\r\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\r\n#else\r\n#include <endian.h>\r\n#endif\r\n\r\n//#include <linux/squashfs_fs.h>\n#include \"squashfs_fs.h\"\r\n#include \"read_fs.h\"\r\n#include \"global.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#ifdef SQUASHFS_TRACE\r\n#define TRACE(s, args...)\t\tdo { \\\r\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\r\n\t\t\t\t\t} while(0)\r\n#else\r\n#define TRACE(s, args...)\r\n#endif\r\n\r\n#define ERROR(s, args...)\t\tdo { \\\r\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\r\n\t\t\t\t\t} while(0)\r\n\r\nint swap;\r\nextern int gLzmaEnable;\r\n\r\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\r\n{\r\n\tunsigned short c_byte;\r\n\tint offset = 2;\r\n\t\r\n\tif(swap) {\r\n\t\tread_bytes(fd, start, 2, (char *) block);\r\n\t\t((unsigned char *) &c_byte)[1] = block[0];\r\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \r\n\t} else \r\n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\r\n\r\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\r\n\t\toffset = 3;\r\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\r\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\r\n\t\tint res;\r\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\r\n\r\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\r\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\r\n\r\n        if(!gLzmaEnable){\r\n    \t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\r\n    \t\t\tif(res == Z_MEM_ERROR)\r\n    \t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\r\n    \t\t\telse if(res == Z_BUF_ERROR)\r\n    \t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\r\n    \t\t\telse\r\n    \t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\r\n    \t\t\treturn 0;\r\n    \t\t}\r\n        }else{\r\n            /*Start:Added @2010-02-25 to suporrt lzma*/\r\n\t\t\tif((res = LzmaUncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != SZ_OK)\r\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\r\n\r\n        }\r\n        /*End:Added @2010-02-25 to suporrt lzma*/\r\n        \r\n\t\tif(next)\r\n\t\t\t*next = start + offset + c_byte;\r\n\t\treturn bytes;\r\n\t} else {\r\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\r\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\r\n\t\tif(next)\r\n\t\t\t*next = start + offset + c_byte;\r\n\t\treturn c_byte;\r\n\t}\r\n}\r\n\r\n\r\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\r\n\t\tsquashfs_super_block *sBlk,\r\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\r\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\r\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\r\n{\r\n\tunsigned char *cur_ptr;\r\n\tint byte, bytes = 0, size = 0, files = 0;\r\n\tsquashfs_reg_inode_header inode;\r\n\tunsigned int directory_start_block;\r\n\r\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\r\n\twhile(start < end) {\r\n\t\tif(start == root_inode_start) {\r\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\r\n\t\t\t*root_inode_block = bytes;\r\n\t\t}\r\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\r\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\r\n\t\t\treturn FALSE;\r\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\r\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\r\n\t\t\tfree(*inode_table);\r\n\t\t\treturn FALSE;\r\n\t\t}\r\n\t\tbytes += byte;\r\n\t}\r\n\r\n\t/*\r\n\t * Read last inode entry which is the root directory inode, and obtain the last\r\n\t * directory start block index.  This is used when calculating the total uncompressed\r\n\t * directory size.  The directory bytes in the last block will be counted as normal.\r\n\t *\r\n\t * The root inode is ignored in the inode scan.  This ensures there is\r\n\t * always enough bytes left to read a regular file inode entry\r\n\t */\r\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\r\n\tbytes = *root_inode_block + root_inode_offset;\r\n\tif(swap) {\r\n\t\tsquashfs_base_inode_header sinode;\r\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\r\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\r\n\t} else\r\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\r\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\r\n\t\tif(swap) {\r\n\t\t\tsquashfs_dir_inode_header sinode;\r\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\r\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\r\n\t\t} else\r\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\r\n\t\tdirectory_start_block = dir_inode->dir.start_block;\r\n\t} else {\r\n\t\tif(swap) {\r\n\t\t\tsquashfs_ldir_inode_header sinode;\r\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\r\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\r\n\t\t} else\r\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\r\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\r\n\t}\r\n\r\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\r\n\t\tif(swap) {\r\n\t\t\tsquashfs_reg_inode_header sinode;\r\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\r\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\r\n\t\t} else\r\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\r\n\r\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\r\n\t\t\t\tinode.inode_type);\r\n\t\tswitch(inode.inode_type) {\r\n\t\t\tcase SQUASHFS_FILE_TYPE: {\r\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\r\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\r\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\r\n\t\t\t\t\tsBlk->block_log;\r\n\t\t\t\tlong long file_bytes = 0;\r\n\t\t\t\tint i;\r\n\t\t\t\tlong long start = inode.start_block;\r\n\t\t\t\tunsigned int *block_list;\r\n\r\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %d, blocks %d\\n\", inode.file_size, blocks);\r\n\r\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\r\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\r\n\t\t\t\t\tgoto failed;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tcur_ptr += sizeof(inode);\r\n\t\t\t\tif(swap) {\r\n\t\t\t\t\tunsigned int sblock_list[blocks];\r\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\r\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\r\n\t\t\t\t} else\r\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\r\n\r\n\t\t\t\t*uncompressed_file += inode.file_size;\r\n\t\t\t\t(*file_count) ++;\r\n\r\n\t\t\t\tfor(i = 0; i < blocks; i++)\r\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\r\n\r\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\r\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\r\n\t\t\t\tbreak;\r\n\t\t\t}\t\r\n\t\t\tcase SQUASHFS_LREG_TYPE: {\r\n\t\t\t\tsquashfs_lreg_inode_header inode;\r\n\t\t\t\tint frag_bytes;\r\n\t\t\t\tint blocks;\r\n\t\t\t\tlong long file_bytes = 0;\r\n\t\t\t\tint i;\r\n\t\t\t\tlong long start;\r\n\t\t\t\tunsigned int *block_list;\r\n\r\n\t\t\t\tif(swap) {\r\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\r\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\r\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\r\n\t\t\t\t} else\r\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\r\n\r\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\r\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\r\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\r\n\t\t\t\t\tsBlk->block_log;\r\n\t\t\t\tstart = inode.start_block;\r\n\r\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\r\n\r\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\r\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\r\n\t\t\t\t\tgoto failed;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tcur_ptr += sizeof(inode);\r\n\t\t\t\tif(swap) {\r\n\t\t\t\t\tunsigned int sblock_list[blocks];\r\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\r\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\r\n\t\t\t\t} else\r\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\r\n\r\n\t\t\t\t*uncompressed_file += inode.file_size;\r\n\t\t\t\t(*file_count) ++;\r\n\r\n\t\t\t\tfor(i = 0; i < blocks; i++)\r\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\r\n\r\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\r\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\r\n\t\t\t\tbreak;\r\n\t\t\t}\t\r\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\r\n\t\t\t\tsquashfs_symlink_inode_header inodep;\r\n\t\r\n\t\t\t\tif(swap) {\r\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\r\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\r\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\r\n\t\t\t\t} else\r\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\r\n\t\t\t\t(*sym_count) ++;\r\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tcase SQUASHFS_DIR_TYPE: {\r\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\r\n\r\n\t\t\t\tif(swap) {\r\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\r\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\r\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\r\n\t\t\t\t} else\r\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\r\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\r\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\r\n\t\t\t\t(*dir_count) ++;\r\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\r\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\r\n\t\t\t\tint i;\r\n\r\n\t\t\t\tif(swap) {\r\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\r\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\r\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\r\n\t\t\t\t} else\r\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\r\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\r\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\r\n\t\t\t\t(*dir_count) ++;\r\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\r\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\r\n\t\t\t\t\tsquashfs_dir_index index;\r\n\t\t\t\t\tif(swap) {\r\n\t\t\t\t\t\tsquashfs_dir_index sindex;\r\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\r\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\r\n\t\t\t\t\t} else\r\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\r\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\r\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\r\n\t\t\t\t(*dev_count) ++;\r\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase SQUASHFS_FIFO_TYPE:\r\n\t\t\t\t(*fifo_count) ++;\r\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\r\n\t\t\t\tbreak;\r\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\r\n\t\t\t\t(*sock_count) ++;\r\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\r\n\t\t\t\tbreak;\r\n\t\t \tdefault:\r\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\r\n\t\t\t\tgoto failed;\r\n\t\t}\r\n\t}\r\n\t\r\n\treturn files;\r\n\r\n\r\nfailed:\r\n\tfree(*inode_table);\r\n\treturn FALSE;\r\n}\r\n\r\n\r\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\r\n{\r\n    /*Start:Changed @2010-02-25 to suporrt lzma*/\r\n\tsquashfs_super_block sblk;\r\n\r\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\r\n\r\n\t/* Check it is a SQUASHFS superblock */\r\n\tswap = 0;\r\n\tswitch (sBlk->s_magic) {\r\n\tcase SQUASHFS_MAGIC_LZMA:\r\n\t\tif (!gLzmaEnable)\r\n\t\t\tgoto bad;\r\n\t\tbreak;\r\n\tcase SQUASHFS_MAGIC:\r\n\t\tbreak;\r\n\tcase SQUASHFS_MAGIC_SWAP:\r\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\r\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\r\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\r\n\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\r\n\t\tswap = 1;\r\n\t\tbreak;\r\n\tbad:\r\n\tdefault:\r\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\r\n\t\tgoto failed_mount;\r\n \t}\r\n\r\n    /*End:Changed @2010-02-25 to suporrt lzma*/\r\n\r\n\t/* Check the MAJOR & MINOR versions */\r\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\r\n\t\tif(sBlk->s_major < 3)\r\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\r\n\t\telse\r\n\t\t\tERROR(\"Filesystem on %s is %d.%d, which is a later filesystem version than I support\\n\",\r\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\r\n\t\tgoto failed_mount;\r\n\t}\r\n\r\n#if __BYTE_ORDER == __BIG_ENDIAN\r\n\t*be = !swap;\r\n#else\r\n\t*be = swap;\r\n#endif\r\n\r\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\r\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\r\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\r\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\r\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\r\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\r\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\r\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\r\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\r\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\r\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\r\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\r\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\r\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\r\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\r\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\r\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\r\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\r\n\tTRACE(\"sBlk->lookup_table_start %llx\\n\", sBlk->lookup_table_start);\r\n\tprintf(\"\\n\");\r\n\r\n\treturn TRUE;\r\n\r\nfailed_mount:\r\n\treturn FALSE;\r\n}\r\n\r\n\r\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\r\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\r\n{\r\n\tsquashfs_dir_header dirh;\r\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\r\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\r\n\tunsigned char *directory_table = NULL;\r\n\tint byte, bytes = 0, dir_count;\r\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block = start; \r\n\r\n\tsize += offset;\r\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\r\n\t\treturn NULL;\r\n\twhile(bytes < size) {\r\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\r\n\t\tlast_start_block = start;\r\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\r\n\t\t\tfree(directory_table);\r\n\t\t\treturn NULL;\r\n\t\t}\r\n\t\tbytes += byte;\r\n\t}\r\n\r\n\tif(!root_entries)\r\n\t\tgoto all_done;\r\n\r\n\tbytes = offset;\r\n \twhile(bytes < size) {\t\t\t\r\n\t\tif(swap) {\r\n\t\t\tsquashfs_dir_header sdirh;\r\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\r\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\r\n\t\t} else\r\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\r\n\r\n\t\tdir_count = dirh.count + 1;\r\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\r\n\t\tbytes += sizeof(dirh);\r\n\r\n\t\twhile(dir_count--) {\r\n\t\t\tif(swap) {\r\n\t\t\t\tsquashfs_dir_entry sdire;\r\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\r\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\r\n\t\t\t} else\r\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\r\n\t\t\tbytes += sizeof(*dire);\r\n\r\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\r\n\t\t\tdire->name[dire->size + 1] = '\\0';\r\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\r\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\r\n\t\t\tbytes += dire->size + 1;\r\n\t\t}\r\n\t}\r\n\r\nall_done:\r\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\r\n\treturn directory_table;\r\n}\r\n\r\n\r\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\r\n{\r\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\r\n\tsquashfs_fragment_index fragment_table_index[indexes];\r\n\r\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\r\n\tif(sBlk->fragments == 0)\r\n\t\treturn 1;\r\n\r\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\r\n\t\tERROR(\"Failed to allocate fragment table\\n\");\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tif(swap) {\r\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\r\n\r\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\r\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\r\n\t} else\r\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\r\n\r\n\tfor(i = 0; i < indexes; i++) {\r\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\r\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\r\n\t}\r\n\r\n\tif(swap) {\r\n\t\tsquashfs_fragment_entry sfragment;\r\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\r\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\r\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\r\n\t\t}\r\n\t}\r\n\r\n\treturn 1;\r\n}\r\n\r\n\r\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\r\n{\r\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\r\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\r\n\tlong long index[indexes];\r\n\tint i;\r\n\r\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\r\n\t\treturn 1;\r\n\r\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\r\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tif(swap) {\r\n\t\tlong long sindex[indexes];\r\n\r\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\r\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\r\n\t} else\r\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\r\n\r\n\tfor(i = 0; i <  indexes; i++) {\r\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\r\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\r\n\t}\r\n\r\n\tif(swap) {\r\n\t\tsquashfs_inode_t sinode;\r\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\r\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\r\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\r\n\t\t}\r\n\t}\r\n\r\n\treturn 1;\r\n}\r\n\r\n\r\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\r\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\r\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\r\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\r\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\r\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\r\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\r\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\r\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\r\n\t\tsquashfs_inode **inode_lookup_table)\r\n{\r\n\tunsigned char *inode_table = NULL, *directory_table;\r\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\r\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\r\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\r\n\tsquashfs_inode_header inode;\r\n\r\n\tprintf(\"Scanning existing filesystem...\\n\");\r\n\r\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\r\n\t\tgoto error;\r\n\r\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\r\n\t\tgoto error;\r\n\r\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\r\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\r\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\r\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\r\n\t\tgoto error;\r\n\t}\r\n\r\n\t*uncompressed_inode = root_inode_block;\r\n\r\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\r\n\r\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\r\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\r\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\r\n\t\t\t*inode_dir_offset = inode.dir.offset;\r\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\r\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\r\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\r\n\t\t} else {\r\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\r\n\t\t\t*inode_dir_offset = inode.ldir.offset;\r\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\r\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\r\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\r\n\t\t}\r\n\r\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\r\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\r\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\r\n\t\t\tgoto error;\r\n\t\t}\r\n\r\n\t\troot_inode_start -= start;\r\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\r\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\r\n\t\t\tgoto error;\r\n\t\t}\r\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\r\n\r\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\r\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\r\n\t\t\tgoto error;\r\n\t\t}\r\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\r\n\r\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\r\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\r\n\t\t\tgoto error;\r\n\t\t}\r\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\r\n\r\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\r\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\r\n\t\t\tgoto error;\r\n\t\t}\r\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\r\n\r\n\t\tif(!swap)\r\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\r\n\t\telse {\r\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\r\n\r\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\r\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\r\n\t\t}\r\n\r\n\t\tif(!swap)\r\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\r\n\t\telse {\r\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\r\n\r\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\r\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\r\n\t\t}\r\n\t\t*uid_count = sBlk->no_uids;\r\n\t\t*guid_count = sBlk->no_guids;\r\n\r\n\t\tfree(inode_table);\r\n\t\tfree(directory_table);\r\n\t\treturn sBlk->inode_table_start;\r\n\t}\r\n\r\nerror:\r\n\treturn 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/sort.c",
    "content": "/* Modifications were made by Cisco Systems, Inc. on or before Thu Feb 16 11:28:44 PST 2012 */\n/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n//#include <linux/squashfs_fs.h>\n#include \"squashfs_fs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\twrite_file(&inode, entry->dir, &duplicate_file);\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/squashfs_fs.h",
    "content": "/* Modifications were made by Cisco Systems, Inc. on or before Thu Feb 16 11:28:44 PST 2012 */\n#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t1\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tunused;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-cisco/squashfs-tools/unsquashfs.c",
    "content": "/* Modifications were made by Cisco Systems, Inc. on or before Thu Feb 16 11:28:44 PST 2012 */\n/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_1_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n#include <signal.h>\n#include <pthread.h>\n#include <math.h>\n#include <sys/ioctl.h>\n#include <sys/time.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include \"lzmainterface.h\"\n#include \"LzmaDec.h\"\n\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\t\tprintf(\"\\n\"); \\\n\t\t\t\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar symlink[65536];\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(unsigned int block_start, unsigned int offset, struct inode **i);\n\tvoid (*read_fragment)(unsigned int fragment, long long *start_block, int *size);\n\tvoid (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, char *block_ptr, int blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tint\twait_free;\n\tint\twait_pending;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tpthread_cond_t wait_for_pending;\n\tstruct cache_entry *free_list;\n\tstruct cache_entry *hash_table[65536];\n};\n\n/* struct describing a cache entry passed between threads */\nstruct cache_entry {\n\tstruct cache *cache;\n\tlong long block;\n\tint\tsize;\n\tint\tused;\n\tint error;\n\tint\tpending;\n\tstruct cache_entry *hash_next;\n\tstruct cache_entry *hash_prev;\n\tstruct cache_entry *free_next;\n\tstruct cache_entry *free_prev;\n\tchar *data;\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\tsize;\n\tint\treadp;\n\tint\twritep;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t empty;\n\tpthread_cond_t full;\n\tvoid **data;\n};\n\nstruct cache *fragment_cache, *data_cache;\nstruct queue *to_reader, *to_deflate, *to_writer, *from_writer;\npthread_t *thread, *deflator_thread;\npthread_mutex_t\tfragment_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 256\n/* default size of data buffer in Mbytes */\n#define DATA_BUFFER_DEFAULT 256\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nunsigned int block_log;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE, use_regex = FALSE;\nchar **created_inode;\nint root_process;\nint columns;\nint rotate = 0;\npthread_mutex_t\tscreen_mutex;\npthread_cond_t progress_wait;\nint progress = TRUE, progress_enabled = FALSE;\nunsigned int total_blocks = 0, total_files = 0, total_inodes = 0;\nunsigned int cur_blocks = 0;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0}\n};\n\nvoid progress_bar(long long current, long long max, int columns);\nvoid update_progress_bar();\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tint hash = CALCULATE_HASH(entry->block);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->block)] = entry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(cache->free_list) {\n\t\tentry->free_next = cache->free_list;\n\t\tentry->free_prev = cache->free_list->free_prev;\n\t\tcache->free_list->free_prev->free_next = entry;\n\t\tcache->free_list->free_prev = entry;\n\t} else {\n\t\tcache->free_list = entry;\n\t\tentry->free_prev = entry->free_next = entry;\n\t}\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->free_prev == NULL && entry->free_next == NULL)\n\t\t/* not in free list */\n\t\treturn;\n\telse if(entry->free_prev == entry && entry->free_next == entry) {\n\t\t/* only this entry in the free list */\n\t\tcache->free_list = NULL;\n\t} else {\n\t\t/* more than one entry in the free list */\n\t\tentry->free_next->free_prev = entry->free_prev;\n\t\tentry->free_prev->free_next = entry->free_next;\n\t\tif(cache->free_list == entry)\n\t\t\tcache->free_list = entry->free_next;\n\t}\n\n\tentry->free_prev = entry->free_next = NULL;\n}\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\treturn NULL;\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct cache_entry *) * 65536);\n\tcache->wait_free = FALSE;\n\tcache->wait_pending = FALSE;\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\tpthread_cond_init(&cache->wait_for_pending, NULL);\n\n\treturn cache;\n}\n\n\nstruct cache_entry *cache_get(struct cache *cache, long long block, int size)\n{\n\t/* Get a block out of the cache.  If the block isn't in the cache\n \t * it is added and queued to the reader() and deflate() threads for reading\n \t * off disk and decompression.  The cache grows until max_blocks is reached,\n \t * once this occurs existing discarded blocks on the free list are reused */\n\tint hash = CALCULATE_HASH(block);\n\tstruct cache_entry *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->block == block)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/* found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(cache, entry);\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t} else {\n\t\t/* not in the cache */\n\t\t\n\t\t/* first try to allocate new block */\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\tentry = malloc(sizeof(struct cache_entry));\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->data = malloc(cache->buffer_size);\n\t\t\tif(entry->data == NULL) {\n\t\t\t\tfree(entry);\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t} else {\n\t\t\t/* try to get from free list */\n\t\t\twhile(cache->free_list == NULL) {\n\t\t\t\tcache->wait_free = TRUE;\n\t\t\t\tpthread_cond_wait(&cache->wait_for_free, &cache->mutex);\n\t\t\t}\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(cache, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t}\n\n\t\t/* initialise block and insert into the hash table */\n\t\tentry->block = block;\n\t\tentry->size = size;\n\t\tentry->used = 1;\n\t\tentry->error = FALSE;\n\t\tentry->pending = TRUE;\n\t\tinsert_hash_table(cache, entry);\n\n\t\t/* queue to read thread to read and ultimately (via the decompress\n \t\t * threads) decompress the buffer\n \t\t */\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t\tqueue_put(to_reader, entry);\n\t}\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\treturn NULL;\n}\n\n\t\nvoid cache_block_ready(struct cache_entry *entry, int error)\n{\n\t/* mark cache entry as being complete, reading and (if necessary)\n \t * decompression has taken place, and the buffer is valid for use.\n \t * If an error occurs reading or decompressing, the buffer also \n \t * becomes ready but with an error... */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\tentry->pending = FALSE;\n\tentry->error = error;\n\n\t/* if the wait_pending flag is set, one or more threads may be waiting on\n \t * this buffer */\n\tif(entry->cache->wait_pending) {\n\t\tentry->cache->wait_pending = FALSE;\n\t\tpthread_cond_broadcast(&entry->cache->wait_for_pending);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_wait(struct cache_entry *entry)\n{\n\t/* wait for this cache entry to become ready, when reading and (if necessary)\n \t * decompression has taken place */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\twhile(entry->pending) {\n\t\tentry->cache->wait_pending = TRUE;\n\t\tpthread_cond_wait(&entry->cache->wait_for_pending, &entry->cache->mutex);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_put(struct cache_entry *entry)\n{\n\t/* finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and is put onto the free list.  As it remains accessible\n \t * via the hash table it can be found getting a new lease of life before it\n \t * is reused. */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tinsert_free_list(entry->cache, entry);\n\n\t\t/* if the wait_free flag is set, one or more threads may be waiting on\n \t \t * this buffer */\n\t\tif(entry->cache->wait_free) {\n\t\t\tentry->cache->wait_free = FALSE;\n\t\t\tpthread_cond_broadcast(&entry->cache->wait_for_free);\n\t\t}\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\tif((user = getpwuid(inode->uid)) == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tif((group = getgrgid(inode->gid)) == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0, inode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \", (int) inode->data >> 8, (int) inode->data & 0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n   \t\tif (!is_lzma(buffer[0])) {\n    \t\tres = uncompress((unsigned char *) block, &bytes, (const unsigned char *) buffer, c_byte);\n\n    \t\tif(res != Z_OK) {\n    \t\t\tif(res == Z_MEM_ERROR)\n    \t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n    \t\t\telse if(res == Z_BUF_ERROR)\n    \t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n    \t\t\telse\n    \t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n    \t\t\tgoto failed;\n    \t\t}\n\n        }else{\n            /*Start:Added @2010-02-25 to suporrt lzma*/\n\t\t\tif((res = LzmaUncompress((unsigned char *) block, &bytes, (const unsigned char *) buffer, c_byte)) != SZ_OK)\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\n            /*End:Added @2010-02-25 to suporrt lzma*/\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tif (!is_lzma(data[0])) {\n\n    \t\tres = uncompress((unsigned char *) block, &bytes, (const unsigned char *) data, c_byte);\n\n    \t\tif(res != Z_OK) {\n    \t\t\tif(res == Z_MEM_ERROR)\n    \t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n    \t\t\telse if(res == Z_BUF_ERROR)\n    \t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n    \t\t\telse\n    \t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n    \t\t\treturn 0;\n    \t\t}\n        }else{ \n            /*Start:Added @2010-02-25 to suporrt lzma*/\n\t\t\tif((res = LzmaUncompress((unsigned char *) block, &bytes, (const unsigned char *) data, c_byte)) != SZ_OK)\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\n            /*End:Added @2010-02-25 to suporrt lzma*/\n\t\t}\n        \n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid read_block_list(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nvoid read_block_list_1(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) | (SQUASHFS_COMPRESSED(block_size) ? 0 : SQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time, unsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%x, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_1()\n{\n}\n\n\nvoid read_fragment(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nvoid read_fragment_2(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data;\n\nint write_block(int file_fd, char *buffer, int size, int hole)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(lseek_broken == FALSE && lseek(file_fd, off, SEEK_CUR) == -1) {\n\t\t\t/* failed to seek beyond end of file */\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t\tlseek_broken = TRUE;\n\t\t}\n\t\tif(lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size : hole;\n\t\t\t\tif(write(file_fd, zero_data, avail_bytes) < avail_bytes)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t}\n\n\tif(write(file_fd, buffer, size) < size)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\nstruct file_entry {\n\tint offset;\n\tint size;\n\tstruct cache_entry *buffer;\n};\n\n\nstruct squashfs_file {\n\tint fd;\n\tint blocks;\n\tlong long file_size;\n\tint mode;\n\tuid_t uid;\n\tgid_t gid;\n\ttime_t time;\n\tchar *pathname;\n};\n\n\nint write_file(struct inode *inode, char *pathname)\n{\n\tunsigned int file_fd, i;\n\tunsigned int *block_list;\n\tint file_end = inode->data / block_size;\n\tlong long start = inode->start;\n\tstruct squashfs_file *file;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", inode->blocks);\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) inode->mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif((block_list = malloc(inode->blocks * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc block list\\n\");\n\n\ts_ops.read_block_list(block_list, inode->block_ptr, inode->blocks);\n\n\tif((file = malloc(sizeof(struct squashfs_file))) == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\n\t/* the writer thread is queued a squashfs_file structure describing the\n \t * file.  If the file has one or more blocks or a fragments they are queued\n \t * separately (references to blocks in the cache). */\n\tfile->fd = file_fd;\n\tfile->file_size = inode->data;\n\tfile->mode = inode->mode;\n\tfile->gid = inode->gid;\n\tfile->uid = inode->uid;\n\tfile->time = inode->time;\n\tfile->pathname = strdup(pathname);\n\tfile->blocks = inode->blocks + (inode->frag_bytes > 0);\n\tqueue_put(to_writer, file);\n\n\tfor(i = 0; i < inode->blocks; i++) {\n\t\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry *));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\tblock->offset = 0;\n\t\tblock->size = i == file_end ? inode->data & (block_size - 1) : block_size;\n\t\tif(block_list[i] == 0) /* sparse file */\n\t\t\tblock->buffer = NULL;\n\t\telse {\n\t\t\tblock->buffer = cache_get(data_cache, start, block_list[i]);\n\t\t\tif(block->buffer == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_file: cache_get failed\\n\");\n\t\t\tstart += c_byte;\n\t\t}\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tif(inode->frag_bytes) {\n\t\tint size;\n\t\tlong long start;\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry *));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\ts_ops.read_fragment(inode->fragment, &start, &size);\n\t\tblock->buffer = cache_get(fragment_cache, start, size);\n\t\tif(block->buffer == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: cache_get failed\\n\");\n\t\tblock->offset = inode->offset;\n\t\tblock->size = inode->frag_bytes;\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tfree(block_list);\n\treturn TRUE;\n}\n\n\nstatic struct inode *read_inode(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i, pathname))\n\t\t\t\tfile_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %lld\\n\", i->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%llx\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\tmakedev((i->data >> 8) & 0xff, i->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", i->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_2 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[header.base.uid];\n    i.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_2!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_1 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode, sizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[(header.base.inode_type - 1) / SQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) % SQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n    i.gid = header.base.guid == 15 ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_1), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_1!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(unsigned int block_start, unsigned int offset, struct inode **i)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((*i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(unsigned int block_start, unsigned int offset, struct inode **i)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(((*i) = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing extract which subsumes the extract currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific extracts, delete as they're subsumed by this extract\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/* match on a leaf component, any subdirectories will\n\t\t\t\t * implicitly match, therefore return an empty new search set */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/* no matching names found, delete empty search set, and return\n        * FALSE */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches),\n     * return new search set and return TRUE */\n\treturn TRUE;\n\nempty_set:\n   /* found matching leaf exclude, return empty search set and return TRUE */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nint pre_scan(char *parent_name, unsigned int start_block, unsigned int offset, struct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(dir == NULL) {\n\t\tERROR(\"pre_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"pre_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tpre_scan(parent_name, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif(type == SQUASHFS_FILE_TYPE || type == SQUASHFS_LREG_TYPE) {\n\t\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(created_inode[i->inode_number - 1] == NULL) {\n\t\t\t\t\tcreated_inode[i->inode_number - 1] = (char *) i;\n\t\t\t\t\ttotal_blocks += (i->data + (block_size - 1)) >> block_log;\n\t\t\t\t}\n\t\t\t\ttotal_files ++;\n\t\t\t}\n\t\t\ttotal_inodes ++;\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tsquashfs_closedir(dir);\n\n\treturn TRUE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, struct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(parent_name, i);\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly) {\n\t\t\t\tcreate_inode(pathname, i);\n\t\t\t\tupdate_progress_bar();\n\t\t\t\t}\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tif(!lsonly)\n\t\tset_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str : \"failed to get time\\n\");\n\tprintf(\"Filesystem is %sexportable via NFS\\n\", SQUASHFS_EXPORTABLE(sBlk.flags) ? \"\" : \"not \");\n\n\tprintf(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tif(sBlk.s_major > 1 && !SQUASHFS_NO_FRAGMENTS(sBlk.flags))\n\t\tprintf(\"Fragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Check data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not \");\n\tif(sBlk.s_major > 1) {\n\t\tprintf(\"Fragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not \" : \"\");\n\t\tprintf(\"Always_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not \");\n\t} else\n\t\tprintf(\"Fragments are not supported by the filesystem\\n\");\n\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tprintf(\"Block size %d\\n\", sBlk.block_size);\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.fragments);\n\tprintf(\"Number of inodes %d\\n\", sBlk.inodes);\n\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tif(sBlk.s_major > 1)\n\t\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n}\n\n\nint read_super(char *source)\n{\n    /*Start:Changed @2010-02-25 to suporrt lzma*/\n\tsquashfs_super_block sblk;\n\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk.s_magic) {\n\tcase SQUASHFS_MAGIC:\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n\t}\n    /*End:Changed @2010-02-25 to suporrt lzma*/\n\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 1 || sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s_major == 1) {\n\t\t\tsBlk.block_size = sBlk.block_size_1;\n\t\t\tsBlk.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t} else {\n\t\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t}\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor <= 1) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.read_block_list = read_block_list;\n\t\ts_ops.read_inode = read_inode;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tif((fd = fopen(filename, \"r\")) == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename, strerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n/* reader thread.  This thread processes read requests queued by the\n * cache_get() routine. */\nvoid *reader(void *arg)\n{\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_reader);\n\t\tint res = read_bytes(entry->block,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size),\n\t\t\tentry->data);\n\n\t\tif(res && SQUASHFS_COMPRESSED_BLOCK(entry->size))\n\t\t\t/* queue successfully read block to the deflate thread(s)\n \t\t\t * for further processing */\n\t\t\tqueue_put(to_deflate, entry);\n\t\telse\n\t\t\t/* block has either been successfully read and is uncompressed,\n \t\t\t * or an error has occurred, clear pending flag, set\n \t\t\t * error appropriately, and wake up any threads waiting on\n \t\t\t * this buffer */\n\t\t\tcache_block_ready(entry, !res);\n\t}\n}\n\n\n/* writer thread.  This processes file write requests queued by the\n * write_file() routine. */\nvoid *writer(void *arg)\n{\n\tint i;\n\n\twhile(1) {\n\t\tstruct squashfs_file *file = queue_get(to_writer);\n\t\tint file_fd;\n\t\tint hole = 0;\n\t\tint failed = FALSE;\n\n\t\tif(file == NULL) {\n\t\t\tqueue_put(from_writer, NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\tTRACE(\"writer: regular file, blocks %d\\n\", file->blocks);\n\n\t\tfile_fd = file->fd;\n\n\t\tfor(i = 0; i < file->blocks; i++, cur_blocks ++) {\n\t\t\tstruct file_entry *block = queue_get(to_writer);\n\n\t\t\tif(block->buffer == 0) { /* sparse file */\n\t\t\t\thole += block->size;\n\t\t\t\tfree(block);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcache_block_wait(block->buffer);\n\n\t\t\tif(block->buffer->error)\n\t\t\t\tfailed = TRUE;\n\n\t\t\tif(failed == FALSE && write_block(file_fd, block->buffer->data + block->offset, block->size, hole) == FALSE) {\n\t\t\t\tERROR(\"writer: failed to write data block %d\\n\", i);\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\t\t\thole = 0;\n\t\t\tcache_block_put(block->buffer);\n\t\t\tfree(block);\n\t\t}\n\n\t\tif(hole && failed == FALSE) {\n\t\t\t/* corner case for hole extending to end of file */\n\t\t\tif(lseek(file_fd, hole, SEEK_CUR) == -1) {\n\t\t\t\t/* for broken lseeks which cannot seek beyond end of\n \t\t\t \t* file, write_block will do the right thing */\n\t\t\t\thole --;\n\t\t\t\tif(write_block(file_fd, \"\\0\", 1, hole) == FALSE) {\n\t\t\t\t\tERROR(\"writer: failed to write sparse data block\\n\");\n\t\t\t\t\tfailed = TRUE;\n\t\t\t\t}\n\t\t\t} else if(ftruncate(file_fd, file->file_size) == -1) {\n\t\t\t\tERROR(\"writer: failed to write sparse data block\\n\");\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\t\t}\n\n\t\tclose(file_fd);\n\t\tif(failed == FALSE)\n\t\t\tset_attributes(file->pathname, file->mode, file->uid, file->gid, file->time, force);\n\t\telse {\n\t\t\tERROR(\"Failed to write %s, skipping\\n\", file->pathname);\n\t\t\tunlink(file->pathname);\n\t\t}\n\t\tfree(file->pathname);\n\t\tfree(file);\n\n\t}\n}\n\n\n/* decompress thread.  This decompresses buffers queued by the read thread */\nvoid *deflator(void *arg)\n{\n\tchar tmp[block_size];\n\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_deflate);\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\n\t\tif(!is_lzma(((unsigned char *)entry->data)[0])){\n\n\t\t\tres = uncompress((unsigned char *) tmp, &bytes, (const unsigned char *) entry->data, SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size));\n\n    \t\tif(res != Z_OK) {\n    \t\t\tif(res == Z_MEM_ERROR)\n    \t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n    \t\t\telse if(res == Z_BUF_ERROR)\n    \t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n    \t\t\telse\n    \t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n    \t\t} else\n    \t\t\tmemcpy(entry->data, tmp, bytes);\n        }else{        \t    \n                /*Start:Added @2010-02-25 to suporrt lzma*/\n\t\t\tif((res = LzmaUncompress((unsigned char *) tmp, &bytes, (const unsigned char *) entry->data, SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size))) != SZ_OK)\n\t\t\t\tERROR(\"LzmaUncompress: error (%d)\\n\", res);\n\t\t\telse\n\t\t\t\tmemcpy(entry->data, tmp, bytes);\n        \t    /*End:Added @2010-02-25 to suporrt lzma*/\n\n\t\t}\n\t\t/* block has been either successfully decompressed, or an error\n \t\t * occurred, clear pending flag, set error appropriately and\n \t\t * wake up any threads waiting on this block */ \n\t\tcache_block_ready(entry, res != Z_OK);\n\t}\n}\n\n\nvoid *progress_thread(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tERROR(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&screen_mutex);\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) * 1000;\n\t\tpthread_cond_timedwait(&progress_wait, &screen_mutex, &timespec);\n\t\tif(progress_enabled)\n\t\t\tprogress_bar(sym_count + dev_count +\n\t\t\t\tfifo_count + cur_blocks, total_inodes - total_files +\n\t\t\t\ttotal_blocks, columns);\n\t}\n}\n\n\nvoid initialise_threads(int fragment_buffer_size, int data_buffer_size)\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\tint all_buffers_size = fragment_buffer_size + data_buffer_size;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((3 + processors) * sizeof(pthread_t))) == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[3];\n\n\tto_reader = queue_init(all_buffers_size);\n\tto_deflate = queue_init(all_buffers_size);\n\tto_writer = queue_init(1000);\n\tfrom_writer = queue_init(1);\n\tfragment_cache = cache_init(block_size, fragment_buffer_size);\n\tdata_cache = cache_init(block_size, data_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&thread[2], NULL, progress_thread, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tEXIT_UNSQUASH(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel unsquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid update_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits = floor(log10(max)) + 1;\n\tint used = max_digits * 2 + 11;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(current > max) {\n\t\tprintf(\"%lld %lld\\n\", current, max);\n\t\treturn;\n\t}\n\n\tif(columns - used < 0)\n\t\treturn;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 3.4 (2008/08/26)\\n\");\\\n\tprintf(\"copyright (C) 2008 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tint n;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\tint fragment_buffer_size = FRAGMENT_BUFFER_DEFAULT;\n\tint data_buffer_size = DATA_BUFFER_DEFAULT;\n\tchar *b;\n\tstruct winsize winsize;\n\n\tpthread_mutex_init(&screen_mutex, NULL);\n\troot_process = geteuid() == 0;\n\tif(root_process)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0 || strcmp(argv[i], \"-n\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-processors\") == 0 || strcmp(argv[i], \"-p\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-data-queue\") == 0 || strcmp(argv[i], \"-da\") == 0) {\n\t\t\tif((++i == argc) || (data_buffer_size = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -data-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(data_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -data-queue should be 1 Mbyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-frag-queue\") == 0 || strcmp(argv[i], \"-fr\") == 0) {\n\t\t\tif((++i == argc) || (fragment_buffer_size = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -frag-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragment_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -frag-queue should be 1 Mbyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 || strcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 || strcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 || strcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 || strcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 || strcmp(argv[i], \"-r\") == 0)\n\t\t\tuse_regex = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(lsonly || info)\n\t\tprogress = FALSE;\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-n[o-progress]\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"\\t-p[rocessors] <number>\\tuse <number> processors.  By default will use\\n\\t\\t\\t\\tnumber of processors available\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are unsquashed with file\\n\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file attributes (like\\n\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-da[ta-queue] <size>\\tSet data queue to <size> Mbytes.  Default %d\\n\\t\\t\\t\\tMbytes\\n\", DATA_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-fr[ag-queue] <size>\\tSet fagment queue to <size> Mbytes.  Default %d\\n\\t\\t\\t\\tMbytes\\n\", FRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX regular expressions\\n\\t\\t\\t\\trather than use the default shell wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tblock_size = sBlk.block_size;\n\tblock_log = sBlk.block_log;\n\n\tfragment_buffer_size <<= 20 - block_log;\n\tdata_buffer_size <<= 20 - block_log;\n\tinitialise_threads(fragment_buffer_size, data_buffer_size);\n\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate data\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids();\n\n\ts_ops.read_fragment_table();\n\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tpre_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tprintf(\"%d inodes (%d blocks) to write\\n\\n\", total_inodes, total_inodes - total_files + total_blocks);\n\n\tif(progress)\n\t\tenable_progress_bar();\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tqueue_put(to_writer, NULL);\n\tqueue_get(from_writer);\n\n\tif(progress) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(sym_count + dev_count + fifo_count + cur_blocks,\n\t\t\ttotal_inodes - total_files + total_blocks, columns);\n\t}\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/Makefile",
    "content": "\n# Copyright (C) 2006-2008 Junjiro Okajima\n# Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described ones in lzma and squashfs.\n\n# $Id: Makefile,v 1.30 2008-03-12 16:24:54 jro Exp $\n\n# paths\nSqlzma = ${CURDIR}\n\nLzmaVer = lzma465\nLzma = ${Sqlzma}/${LzmaVer}\nSqVer = squashfs3.4\nSquashfs = ${Sqlzma}/${SqVer}\nKVer = linux-2.6.27.4\nSqFs = ${Squashfs}/kernel-patches/${KVer}/fs/squashfs\n#KDir = /lib/modules/$(shell uname -r)/build\n#KDir = ${SqFs}/../..\n\nifeq (${LzmaVer}, lzma443)\nLzmaC = ${Lzma}/C/7zip/Compress/LZMA_C\nLzmaAlone = ${Lzma}/C/7zip/Compress/LZMA_Alone\nendif\nifeq (${LzmaVer}, lzma465)\nLzmaC = ${Lzma}/C\nLzmaAlone = ${Lzma}/CPP/7zip/Compress/LZMA_Alone\nelse\nLzmaC = ${Lzma}/C/Compress/Lzma\nLzmaAlone = ${Lzma}/CPP/7zip/Compress/LZMA_Alone\nendif\nSqTools = ${Squashfs}/squashfs-tools\n\n# enable it if you want to add -g option when compiling\n#UseDebugFlags = 1\n#MyDebugFlags = -DSQUASHFS_TRACE\n# disable it if you don't want to compile squashfs kernel module here\n# BuildSquashfs = 1\n\nexport\n\nall:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\tcp ${SqTools}/mksquashfs ./mksquashfs-lzma\n\tcp ${SqTools}/unsquashfs ./unsquashfs\nclean:\n\t${MAKE} -C ${LzmaC} -f sqlzma.mk $@\n\t${MAKE} -C ${LzmaAlone} -f sqlzma.mk $@\n\t${MAKE} -C ${SqTools} $@\n\t${RM} *~ \n\trm -f ./mksquashfs-lzma ./unsquashfs\n\n########################################\n\n-include priv.mk\n\nifdef BuildSquashfs\nCONFIG_SQUASHFS = m\nCONFIG_SQUASHFS_EMBEDDED =\nCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE = 3\nEXTRA_CFLAGS = -I${Sqlzma} -I${SqFs}/../../include -Wall -Werror\nEXTRA_CFLAGS += -DCONFIG_SQUASHFS_MODULE -UCONFIG_SQUASHFS\nEXTRA_CFLAGS += -UCONFIG_SQUASHFS_EMBEDDED -DCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3\n# if you enabled CONFIG_PREEMPT, but want CPU to try concentrating\n# the uncompression, then define UnsquashNoPreempt.\n# if you don't define UnsquashNoPreempt, the behaviour follows\n# the CONFIG_PREEMPT.\nEXTRA_CFLAGS += -DUnsquashNoPreempt\nexport\n\n# the environment variables are not inherited since 2.6.23\nMAKE += SQLZMA_EXTRA_CFLAGS=\"$(shell echo ${EXTRA_CFLAGS} | sed -e 's/\\\"/\\\\\\\\\\\\\"/g')\"\n\nall: all_sq\n\nFORCE:\nall_sq:\n\t${MAKE} -C ${KDir} M=${SqFs} modules\n\nclean: clean_sq\nclean_sq:\n\t${MAKE} -C ${KDir} M=${SqFs} clean\nendif\n\n########################################\n\nload:\n\tfor i in ${LzmaC}/kmod/unlzma.ko ${LzmaC}/kmod/sqlzma.ko \\\n\t\t${SqFs}/squashfs.ko; \\\n\tdo sudo insmod $$i; done\n\nunload:\n\t-sudo rmmod squashfs sqlzma unlzma\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/README.txt",
    "content": "Adaptation squashfs3.4 pour utilisation lzma4.65\n\nAdaptation nécessaire pour les firmware 2.x.x de la neufbox4\n\nAdaptation réalisée d'après la recette de SGDA (http://www.neufbox4.org/forum/viewtopic.php?pid=12691#p12691)\n\n\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/7zC.txt",
    "content": "7z ANSI-C Decoder 4.62\r\n----------------------\r\n\r\n7z ANSI-C provides 7z/LZMA decoding.\r\n7z ANSI-C version is simplified version ported from C++ code.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\n7z ANSI-C Decoder is part of the LZMA SDK.\r\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\r\n\r\nFiles\r\n---------------------\r\n\r\n7zDecode.*   - Low level 7z decoding\r\n7zExtract.*  - High level 7z decoding\r\n7zHeader.*   - .7z format constants\r\n7zIn.*       - .7z archive opening\r\n7zItem.*     - .7z structures\r\n7zMain.c     - Test application\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nYou must download 7-Zip program from www.7-zip.org.\r\n\r\nYou can create .7z archive with 7z.exe or 7za.exe:\r\n\r\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255\r\n\r\nIf you have big number of files in archive, and you need fast extracting, \r\nyou can use partly-solid archives:\r\n  \r\n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\r\n\r\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r\n512KB for extracting one file from such archive.\r\n\r\n\r\nLimitations of current version of 7z ANSI-C Decoder\r\n---------------------------------------------------\r\n\r\n - It reads only \"FileName\", \"Size\", \"LastWriteTime\" and \"CRC\" information for each file in archive.\r\n - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.\r\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r\n \r\nThese limitations will be fixed in future versions.\r\n\r\n\r\nUsing 7z ANSI-C Decoder Test application:\r\n-----------------------------------------\r\n\r\nUsage: 7zDec <command> <archive_name>\r\n\r\n<Command>:\r\n  e: Extract files from archive\r\n  l: List contents of archive\r\n  t: Test integrity of archive\r\n\r\nExample: \r\n\r\n  7zDec l archive.7z\r\n\r\nlists contents of archive.7z\r\n\r\n  7zDec e archive.7z\r\n\r\nextracts files from archive.7z to current folder.\r\n\r\n\r\nHow to use .7z Decoder\r\n----------------------\r\n\r\nMemory allocation\r\n~~~~~~~~~~~~~~~~~\r\n\r\n7z Decoder uses two memory pools:\r\n1) Temporary pool\r\n2) Main pool\r\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\r\n\r\n\r\nSteps for using 7z decoder\r\n--------------------------\r\n\r\nUse code at 7zMain.c as example.\r\n\r\n1) Declare variables:\r\n  inStream                 /* implements ILookInStream interface */\r\n  CSzArEx db;              /* 7z archive database structure */\r\n  ISzAlloc allocImp;       /* memory functions for main pool */\r\n  ISzAlloc allocTempImp;   /* memory functions for temporary pool */\r\n\r\n2) call CrcGenerateTable(); function to initialize CRC structures.\r\n\r\n3) call SzArEx_Init(&db); function to initialize db structures.\r\n\r\n4) call SzArEx_Open(&db, inStream, &allocMain, &allocTemp) to open archive\r\n\r\nThis function opens archive \"inStream\" and reads headers to \"db\".\r\nAll items in \"db\" will be allocated with \"allocMain\" functions.\r\nSzArEx_Open function allocates and frees temporary structures by \"allocTemp\" functions.\r\n\r\n5) List items or Extract items\r\n\r\n  Listing code:\r\n  ~~~~~~~~~~~~~\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.db.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n\r\n  Extracting code:\r\n  ~~~~~~~~~~~~~~~~\r\n\r\n  SZ_RESULT SzAr_Extract(\r\n    CArchiveDatabaseEx *db,\r\n    ILookInStream *inStream, \r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n  If you need to decompress more than one file, you can send these values from previous call:\r\n    blockIndex, \r\n    outBuffer, \r\n    outBufferSize,\r\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \r\n  it will increase decompression speed.\r\n\r\n  After decompressing you must free \"outBuffer\":\r\n  allocImp.Free(outBuffer);\r\n\r\n6) call SzArEx_Free(&db, allocImp.Free) to free allocated items in \"db\".\r\n\r\n\r\n\r\n\r\nMemory requirements for .7z decoding \r\n------------------------------------\r\n\r\nMemory usage for Archive opening:\r\n  - Temporary pool:\r\n     - Memory for uncompressed .7z headers\r\n     - some other temporary blocks\r\n  - Main pool:\r\n     - Memory for database: \r\n       Estimated size of one file structures in solid archive:\r\n         - Size (4 or 8 Bytes)\r\n         - CRC32 (4 bytes)\r\n         - LastWriteTime (8 bytes)\r\n         - Some file information (4 bytes)\r\n         - File Name (variable length) + pointer + allocation structures\r\n\r\nMemory usage for archive Decompressing:\r\n  - Temporary pool:\r\n     - Memory for LZMA decompressing structures\r\n  - Main pool:\r\n     - Memory for decompressed solid block\r\n     - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these \r\n       temprorary buffers can be about 15% of solid block size. \r\n  \r\n\r\n7z Decoder doesn't allocate memory for compressed blocks. \r\nInstead of this, you must allocate buffer with desired \r\nsize before calling 7z Decoder. Use 7zMain.c as example.\r\n\r\n\r\nDefines\r\n-------\r\n\r\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/sdk.html\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\r\n-----------------------------------\r\n\r\nThis file contains description of 7z archive format. \r\n7z archive can contain files compressed with any method.\r\nSee \"Methods.txt\" for description for defined compressing methods.\r\n\r\n\r\nFormat structure Overview\r\n-------------------------\r\n\r\nSome fields can be optional.\r\n\r\nArchive structure\r\n~~~~~~~~~~~~~~~~~  \r\nSignatureHeader\r\n[PackedStreams]\r\n[PackedStreamsForHeaders]\r\n[\r\n  Header \r\n  or \r\n  {\r\n    Packed Header\r\n    HeaderInfo\r\n  }\r\n]\r\n\r\n\r\n\r\nHeader structure\r\n~~~~~~~~~~~~~~~~  \r\n{\r\n  ArchiveProperties\r\n  AdditionalStreams\r\n  {\r\n    PackInfo\r\n    {\r\n      PackPos\r\n      NumPackStreams\r\n      Sizes[NumPackStreams]\r\n      CRCs[NumPackStreams]\r\n    }\r\n    CodersInfo\r\n    {\r\n      NumFolders\r\n      Folders[NumFolders]\r\n      {\r\n        NumCoders\r\n        CodersInfo[NumCoders]\r\n        {\r\n          ID\r\n          NumInStreams;\r\n          NumOutStreams;\r\n          PropertiesSize\r\n          Properties[PropertiesSize]\r\n        }\r\n        NumBindPairs\r\n        BindPairsInfo[NumBindPairs]\r\n        {\r\n          InIndex;\r\n          OutIndex;\r\n        }\r\n        PackedIndices\r\n      }\r\n      UnPackSize[Folders][Folders.NumOutstreams]\r\n      CRCs[NumFolders]\r\n    }\r\n    SubStreamsInfo\r\n    {\r\n      NumUnPackStreamsInFolders[NumFolders];\r\n      UnPackSizes[]\r\n      CRCs[]\r\n    }\r\n  }\r\n  MainStreamsInfo\r\n  {\r\n    (Same as in AdditionalStreams)\r\n  }\r\n  FilesInfo\r\n  {\r\n    NumFiles\r\n    Properties[]\r\n    {\r\n      ID\r\n      Size\r\n      Data\r\n    }\r\n  }\r\n}\r\n\r\nHeaderInfo structure\r\n~~~~~~~~~~~~~~~~~~~~\r\n{\r\n  (Same as in AdditionalStreams)\r\n}\r\n\r\n\r\n\r\nNotes about Notation and encoding\r\n---------------------------------\r\n\r\n7z uses little endian encoding.\r\n\r\n7z archive format has optional headers that are marked as\r\n[]\r\nHeader\r\n[]\r\n\r\nREAL_UINT64 means real UINT64.\r\n\r\nUINT64 means real UINT64 encoded with the following scheme:\r\n\r\n  Size of encoding sequence depends from first byte:\r\n  First_Byte  Extra_Bytes        Value\r\n  (binary)   \r\n  0xxxxxxx               : ( xxxxxxx           )\r\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r\n  ...\r\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r\n  11111110    BYTE y[7]  :                         y\r\n  11111111    BYTE y[8]  :                         y\r\n\r\n\r\n\r\nProperty IDs\r\n------------\r\n\r\n0x00 = kEnd,\r\n\r\n0x01 = kHeader,\r\n\r\n0x02 = kArchiveProperties,\r\n    \r\n0x03 = kAdditionalStreamsInfo,\r\n0x04 = kMainStreamsInfo,\r\n0x05 = kFilesInfo,\r\n    \r\n0x06 = kPackInfo,\r\n0x07 = kUnPackInfo,\r\n0x08 = kSubStreamsInfo,\r\n\r\n0x09 = kSize,\r\n0x0A = kCRC,\r\n\r\n0x0B = kFolder,\r\n\r\n0x0C = kCodersUnPackSize,\r\n0x0D = kNumUnPackStream,\r\n\r\n0x0E = kEmptyStream,\r\n0x0F = kEmptyFile,\r\n0x10 = kAnti,\r\n\r\n0x11 = kName,\r\n0x12 = kCreationTime,\r\n0x13 = kLastAccessTime,\r\n0x14 = kLastWriteTime,\r\n0x15 = kWinAttributes,\r\n0x16 = kComment,\r\n\r\n0x17 = kEncodedHeader,\r\n\r\n\r\n7z format headers\r\n-----------------\r\n\r\nSignatureHeader\r\n~~~~~~~~~~~~~~~\r\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n\r\n  ArchiveVersion\r\n  {\r\n    BYTE Major;   // now = 0\r\n    BYTE Minor;   // now = 2\r\n  };\r\n\r\n  UINT32 StartHeaderCRC;\r\n\r\n  StartHeader\r\n  {\r\n    REAL_UINT64 NextHeaderOffset\r\n    REAL_UINT64 NextHeaderSize\r\n    UINT32 NextHeaderCRC\r\n  }\r\n\r\n\r\n...........................\r\n\r\n\r\nArchiveProperties\r\n~~~~~~~~~~~~~~~~~\r\nBYTE NID::kArchiveProperties (0x02)\r\nfor (;;)\r\n{\r\n  BYTE PropertyType;\r\n  if (aType == 0)\r\n    break;\r\n  UINT64 PropertySize;\r\n  BYTE PropertyData[PropertySize];\r\n}\r\n\r\n\r\nDigests (NumStreams)\r\n~~~~~~~~~~~~~~~~~~~~~\r\n  BYTE AllAreDefined\r\n  if (AllAreDefined == 0)\r\n  {\r\n    for(NumStreams)\r\n      BIT Defined\r\n  }\r\n  UINT32 CRCs[NumDefined]\r\n\r\n\r\nPackInfo\r\n~~~~~~~~~~~~\r\n  BYTE NID::kPackInfo  (0x06)\r\n  UINT64 PackPos\r\n  UINT64 NumPackStreams\r\n\r\n  []\r\n  BYTE NID::kSize    (0x09)\r\n  UINT64 PackSizes[NumPackStreams]\r\n  []\r\n\r\n  []\r\n  BYTE NID::kCRC      (0x0A)\r\n  PackStreamDigests[NumPackStreams]\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFolder\r\n~~~~~~\r\n  UINT64 NumCoders;\r\n  for (NumCoders)\r\n  {\r\n    BYTE \r\n    {\r\n      0:3 DecompressionMethod.IDSize\r\n      4:\r\n        0 - IsSimple\r\n        1 - Is not simple\r\n      5:\r\n        0 - No Attributes\r\n        1 - There Are Attributes\r\n      7:\r\n        0 - Last Method in Alternative_Method_List\r\n        1 - There are more alternative methods\r\n    } \r\n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\r\n    if (!IsSimple)\r\n    {\r\n      UINT64 NumInStreams;\r\n      UINT64 NumOutStreams;\r\n    }\r\n    if (DecompressionMethod[0] != 0)\r\n    {\r\n      UINT64 PropertiesSize\r\n      BYTE Properties[PropertiesSize]\r\n    }\r\n  }\r\n    \r\n  NumBindPairs = NumOutStreamsTotal - 1;\r\n\r\n  for (NumBindPairs)\r\n  {\r\n    UINT64 InIndex;\r\n    UINT64 OutIndex;\r\n  }\r\n\r\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r\n  if (NumPackedStreams > 1)\r\n    for(NumPackedStreams)\r\n    {\r\n      UINT64 Index;\r\n    };\r\n\r\n\r\n\r\n\r\nCoders Info\r\n~~~~~~~~~~~\r\n\r\n  BYTE NID::kUnPackInfo  (0x07)\r\n\r\n\r\n  BYTE NID::kFolder  (0x0B)\r\n  UINT64 NumFolders\r\n  BYTE External\r\n  switch(External)\r\n  {\r\n    case 0:\r\n      Folders[NumFolders]\r\n    case 1:\r\n      UINT64 DataStreamIndex\r\n  }\r\n\r\n\r\n  BYTE ID::kCodersUnPackSize  (0x0C)\r\n  for(Folders)\r\n    for(Folder.NumOutStreams)\r\n     UINT64 UnPackSize;\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC   (0x0A)\r\n  UnPackDigests[NumFolders]\r\n  []\r\n\r\n  \r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\n\r\nSubStreams Info\r\n~~~~~~~~~~~~~~\r\n  BYTE NID::kSubStreamsInfo; (0x08)\r\n\r\n  []\r\n  BYTE NID::kNumUnPackStream; (0x0D)\r\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kSize  (0x09)\r\n  UINT64 UnPackSizes[]\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC  (0x0A)\r\n  Digests[Number of streams with unknown CRC]\r\n  []\r\n\r\n  \r\n  BYTE NID::kEnd\r\n\r\n\r\nStreams Info\r\n~~~~~~~~~~~~\r\n\r\n  []\r\n  PackInfo\r\n  []\r\n\r\n\r\n  []\r\n  CodersInfo\r\n  []\r\n\r\n\r\n  []\r\n  SubStreamsInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFilesInfo\r\n~~~~~~~~~\r\n  BYTE NID::kFilesInfo;  (0x05)\r\n  UINT64 NumFiles\r\n\r\n  for (;;)\r\n  {\r\n    BYTE PropertyType;\r\n    if (aType == 0)\r\n      break;\r\n\r\n    UINT64 Size;\r\n\r\n    switch(PropertyType)\r\n    {\r\n      kEmptyStream:   (0x0E)\r\n        for(NumFiles)\r\n          BIT IsEmptyStream\r\n\r\n      kEmptyFile:     (0x0F)\r\n        for(EmptyStreams)\r\n          BIT IsEmptyFile\r\n\r\n      kAnti:          (0x10)\r\n        for(EmptyStreams)\r\n          BIT IsAntiFile\r\n      \r\n      case kCreationTime:   (0x12)\r\n      case kLastAccessTime: (0x13)\r\n      case kLastWriteTime:  (0x14)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT TimeDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Items)\r\n          UINT32 Time\r\n        []\r\n      \r\n      kNames:     (0x11)\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Files)\r\n        {\r\n          wchar_t Names[NameSize];\r\n          wchar_t 0;\r\n        }\r\n        []\r\n\r\n      kAttributes:  (0x15)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT AttributesAreDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Attributes)\r\n          UINT32 Attributes\r\n        []\r\n    }\r\n  }\r\n\r\n\r\nHeader\r\n~~~~~~\r\n  BYTE NID::kHeader (0x01)\r\n\r\n  []\r\n  ArchiveProperties\r\n  []\r\n\r\n  []\r\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  BYTE NID::kMainStreamsInfo;    (0x04)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  FilesInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nHeaderInfo\r\n~~~~~~~~~~\r\n  []\r\n  BYTE NID::kEncodedHeader; (0x17)\r\n  StreamsInfo for Encoded Header\r\n  []\r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/7zBuf.c",
    "content": "/* 7zBuf.c -- Byte Buffer\r\n2008-03-28\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"7zBuf.h\"\r\n\r\nvoid Buf_Init(CBuf *p)\r\n{\r\n  p->data = 0;\r\n  p->size = 0;\r\n}\r\n\r\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)\r\n{\r\n  p->size = 0;\r\n  if (size == 0)\r\n  {\r\n    p->data = 0;\r\n    return 1;\r\n  }\r\n  p->data = (Byte *)alloc->Alloc(alloc, size);\r\n  if (p->data != 0)\r\n  {\r\n    p->size = size;\r\n    return 1;\r\n  }\r\n  return 0;\r\n}\r\n\r\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->data);\r\n  p->data = 0;\r\n  p->size = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/7zBuf.h",
    "content": "/* 7zBuf.h -- Byte Buffer\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_BUF_H\r\n#define __7Z_BUF_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct\r\n{\r\n  Byte *data;\r\n  size_t size;\r\n} CBuf;\r\n\r\nvoid Buf_Init(CBuf *p);\r\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);\r\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc);\r\n\r\ntypedef struct\r\n{\r\n  Byte *data;\r\n  size_t size;\r\n  size_t pos;\r\n} CDynBuf;\r\n\r\nvoid DynBuf_Construct(CDynBuf *p);\r\nvoid DynBuf_SeekToBeg(CDynBuf *p);\r\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);\r\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/7zBuf2.c",
    "content": "/* 7zBuf2.c -- Byte Buffer\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n#include \"7zBuf.h\"\r\n\r\nvoid DynBuf_Construct(CDynBuf *p)\r\n{\r\n  p->data = 0;\r\n  p->size = 0;\r\n  p->pos = 0;\r\n}\r\n\r\nvoid DynBuf_SeekToBeg(CDynBuf *p)\r\n{\r\n  p->pos = 0;\r\n}\r\n\r\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)\r\n{\r\n  if (size > p->size - p->pos)\r\n  {\r\n    size_t newSize = p->pos + size;\r\n    Byte *data;\r\n    newSize += newSize / 4;\r\n    data = (Byte *)alloc->Alloc(alloc, newSize);\r\n    if (data == 0)\r\n      return 0;\r\n    p->size = newSize;\r\n    memcpy(data, p->data, p->pos);\r\n    alloc->Free(alloc, p->data);\r\n    p->data = data;\r\n  }\r\n  memcpy(p->data + p->pos, buf, size);\r\n  p->pos += size;\r\n  return 1;\r\n}\r\n\r\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->data);\r\n  p->data = 0;\r\n  p->size = 0;\r\n  p->pos = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/7zCrc.c",
    "content": "/* 7zCrc.c -- CRC32 calculation\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = CRC_UPDATE_BYTE(v, *p);\r\n  return v;\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/7zCrc.h",
    "content": "/* 7zCrc.h -- CRC32 calculation\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"Types.h\"\r\n\r\nextern UInt32 g_CrcTable[];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void);\r\n\r\n#define CRC_INIT_VAL 0xFFFFFFFF\r\n#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)\r\n#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/7zFile.c",
    "content": "/* 7zFile.c -- File IO\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zFile.h\"\r\n\r\n#ifndef USE_WINDOWS_FILE\r\n\r\n#include <errno.h>\r\n\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FILE\r\n\r\n/*\r\n   ReadFile and WriteFile functions in Windows have BUG:\r\n   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r\n   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r\n   (Insufficient system resources exist to complete the requested service).\r\n   Probably in some version of Windows there are problems with other sizes:\r\n   for 32 MB (maybe also for 16 MB).\r\n   And message can be \"Network connection was lost\"\r\n*/\r\n\r\n#define kChunkSizeMax (1 << 22)\r\n\r\n#endif\r\n\r\nvoid File_Construct(CSzFile *p)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  p->handle = INVALID_HANDLE_VALUE;\r\n  #else\r\n  p->file = NULL;\r\n  #endif\r\n}\r\n\r\nstatic WRes File_Open(CSzFile *p, const char *name, int writeMode)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  p->handle = CreateFileA(name,\r\n      writeMode ? GENERIC_WRITE : GENERIC_READ,\r\n      FILE_SHARE_READ, NULL,\r\n      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\r\n      FILE_ATTRIBUTE_NORMAL, NULL);\r\n  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r\n  #else\r\n  p->file = fopen(name, writeMode ? \"wb+\" : \"rb\");\r\n  return (p->file != 0) ? 0 : errno;\r\n  #endif\r\n}\r\n\r\nWRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }\r\nWRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }\r\n\r\nWRes File_Close(CSzFile *p)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  if (p->handle != INVALID_HANDLE_VALUE)\r\n  {\r\n    if (!CloseHandle(p->handle))\r\n      return GetLastError();\r\n    p->handle = INVALID_HANDLE_VALUE;\r\n  }\r\n  #else\r\n  if (p->file != NULL)\r\n  {\r\n    int res = fclose(p->file);\r\n    if (res != 0)\r\n      return res;\r\n    p->file = NULL;\r\n  }\r\n  #endif\r\n  return 0;\r\n}\r\n\r\nWRes File_Read(CSzFile *p, void *data, size_t *size)\r\n{\r\n  size_t originalSize = *size;\r\n  if (originalSize == 0)\r\n    return 0;\r\n\r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  *size = 0;\r\n  do\r\n  {\r\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r\n    DWORD processed = 0;\r\n    BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);\r\n    data = (void *)((Byte *)data + processed);\r\n    originalSize -= processed;\r\n    *size += processed;\r\n    if (!res)\r\n      return GetLastError();\r\n    if (processed == 0)\r\n      break;\r\n  }\r\n  while (originalSize > 0);\r\n  return 0;\r\n\r\n  #else\r\n  \r\n  *size = fread(data, 1, originalSize, p->file);\r\n  if (*size == originalSize)\r\n    return 0;\r\n  return ferror(p->file);\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_Write(CSzFile *p, const void *data, size_t *size)\r\n{\r\n  size_t originalSize = *size;\r\n  if (originalSize == 0)\r\n    return 0;\r\n  \r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  *size = 0;\r\n  do\r\n  {\r\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r\n    DWORD processed = 0;\r\n    BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);\r\n    data = (void *)((Byte *)data + processed);\r\n    originalSize -= processed;\r\n    *size += processed;\r\n    if (!res)\r\n      return GetLastError();\r\n    if (processed == 0)\r\n      break;\r\n  }\r\n  while (originalSize > 0);\r\n  return 0;\r\n\r\n  #else\r\n\r\n  *size = fwrite(data, 1, originalSize, p->file);\r\n  if (*size == originalSize)\r\n    return 0;\r\n  return ferror(p->file);\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  LARGE_INTEGER value;\r\n  DWORD moveMethod;\r\n  value.LowPart = (DWORD)*pos;\r\n  value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */\r\n  switch (origin)\r\n  {\r\n    case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;\r\n    case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;\r\n    case SZ_SEEK_END: moveMethod = FILE_END; break;\r\n    default: return ERROR_INVALID_PARAMETER;\r\n  }\r\n  value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n  {\r\n    WRes res = GetLastError();\r\n    if (res != NO_ERROR)\r\n      return res;\r\n  }\r\n  *pos = ((Int64)value.HighPart << 32) | value.LowPart;\r\n  return 0;\r\n\r\n  #else\r\n  \r\n  int moveMethod;\r\n  int res;\r\n  switch (origin)\r\n  {\r\n    case SZ_SEEK_SET: moveMethod = SEEK_SET; break;\r\n    case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;\r\n    case SZ_SEEK_END: moveMethod = SEEK_END; break;\r\n    default: return 1;\r\n  }\r\n  res = fseek(p->file, (long)*pos, moveMethod);\r\n  *pos = ftell(p->file);\r\n  return res;\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_GetLength(CSzFile *p, UInt64 *length)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  \r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);\r\n  if (sizeLow == 0xFFFFFFFF)\r\n  {\r\n    DWORD res = GetLastError();\r\n    if (res != NO_ERROR)\r\n      return res;\r\n  }\r\n  *length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return 0;\r\n  \r\n  #else\r\n  \r\n  long pos = ftell(p->file);\r\n  int res = fseek(p->file, 0, SEEK_END);\r\n  *length = ftell(p->file);\r\n  fseek(p->file, pos, SEEK_SET);\r\n  return res;\r\n  \r\n  #endif\r\n}\r\n\r\n\r\n/* ---------- FileSeqInStream ---------- */\r\n\r\nstatic SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CFileSeqInStream *p = (CFileSeqInStream *)pp;\r\n  return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;\r\n}\r\n\r\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p)\r\n{\r\n  p->s.Read = FileSeqInStream_Read;\r\n}\r\n\r\n\r\n/* ---------- FileInStream ---------- */\r\n\r\nstatic SRes FileInStream_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CFileInStream *p = (CFileInStream *)pp;\r\n  return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;\r\n}\r\n\r\nstatic SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)\r\n{\r\n  CFileInStream *p = (CFileInStream *)pp;\r\n  return File_Seek(&p->file, pos, origin);\r\n}\r\n\r\nvoid FileInStream_CreateVTable(CFileInStream *p)\r\n{\r\n  p->s.Read = FileInStream_Read;\r\n  p->s.Seek = FileInStream_Seek;\r\n}\r\n\r\n\r\n/* ---------- FileOutStream ---------- */\r\n\r\nstatic size_t FileOutStream_Write(void *pp, const void *data, size_t size)\r\n{\r\n  CFileOutStream *p = (CFileOutStream *)pp;\r\n  File_Write(&p->file, data, &size);\r\n  return size;\r\n}\r\n\r\nvoid FileOutStream_CreateVTable(CFileOutStream *p)\r\n{\r\n  p->s.Write = FileOutStream_Write;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/7zFile.h",
    "content": "/* 7zFile.h -- File IO\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_FILE_H\r\n#define __7Z_FILE_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WINDOWS_FILE\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FILE\r\n#include <windows.h>\r\n#else\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"Types.h\"\r\n\r\n\r\n/* ---------- File ---------- */\r\n\r\ntypedef struct\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  HANDLE handle;\r\n  #else\r\n  FILE *file;\r\n  #endif\r\n} CSzFile;\r\n\r\nvoid File_Construct(CSzFile *p);\r\nWRes InFile_Open(CSzFile *p, const char *name);\r\nWRes OutFile_Open(CSzFile *p, const char *name);\r\nWRes File_Close(CSzFile *p);\r\n\r\n/* reads max(*size, remain file's size) bytes */\r\nWRes File_Read(CSzFile *p, void *data, size_t *size);\r\n\r\n/* writes *size bytes */\r\nWRes File_Write(CSzFile *p, const void *data, size_t *size);\r\n\r\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);\r\nWRes File_GetLength(CSzFile *p, UInt64 *length);\r\n\r\n\r\n/* ---------- FileInStream ---------- */\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  CSzFile file;\r\n} CFileSeqInStream;\r\n\r\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p);\r\n\r\n\r\ntypedef struct\r\n{\r\n  ISeekInStream s;\r\n  CSzFile file;\r\n} CFileInStream;\r\n\r\nvoid FileInStream_CreateVTable(CFileInStream *p);\r\n\r\n\r\ntypedef struct\r\n{\r\n  ISeqOutStream s;\r\n  CSzFile file;\r\n} CFileOutStream;\r\n\r\nvoid FileOutStream_CreateVTable(CFileOutStream *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/7zStream.c",
    "content": "/* 7zStream.c -- 7z Stream functions\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"Types.h\"\r\n\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)\r\n{\r\n  while (size != 0)\r\n  {\r\n    size_t processed = size;\r\n    RINOK(stream->Read(stream, buf, &processed));\r\n    if (processed == 0)\r\n      return errorType;\r\n    buf = (void *)((Byte *)buf + processed);\r\n    size -= processed;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)\r\n{\r\n  return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r\n}\r\n\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)\r\n{\r\n  size_t processed = 1;\r\n  RINOK(stream->Read(stream, buf, &processed));\r\n  return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;\r\n}\r\n\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)\r\n{\r\n  Int64 t = offset;\r\n  return stream->Seek(stream, &t, SZ_SEEK_SET);\r\n}\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)\r\n{\r\n  void *lookBuf;\r\n  if (*size == 0)\r\n    return SZ_OK;\r\n  RINOK(stream->Look(stream, &lookBuf, size));\r\n  memcpy(buf, lookBuf, *size);\r\n  return stream->Skip(stream, *size);\r\n}\r\n\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)\r\n{\r\n  while (size != 0)\r\n  {\r\n    size_t processed = size;\r\n    RINOK(stream->Read(stream, buf, &processed));\r\n    if (processed == 0)\r\n      return errorType;\r\n    buf = (void *)((Byte *)buf + processed);\r\n    size -= processed;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)\r\n{\r\n  return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r\n}\r\n\r\nstatic SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)\r\n{\r\n  SRes res = SZ_OK;\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t size2 = p->size - p->pos;\r\n  if (size2 == 0 && *size > 0)\r\n  {\r\n    p->pos = 0;\r\n    size2 = LookToRead_BUF_SIZE;\r\n    res = p->realStream->Read(p->realStream, p->buf, &size2);\r\n    p->size = size2;\r\n  }\r\n  if (size2 < *size)\r\n    *size = size2;\r\n  *buf = p->buf + p->pos;\r\n  return res;\r\n}\r\n\r\nstatic SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)\r\n{\r\n  SRes res = SZ_OK;\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t size2 = p->size - p->pos;\r\n  if (size2 == 0 && *size > 0)\r\n  {\r\n    p->pos = 0;\r\n    if (*size > LookToRead_BUF_SIZE)\r\n      *size = LookToRead_BUF_SIZE;\r\n    res = p->realStream->Read(p->realStream, p->buf, size);\r\n    size2 = p->size = *size;\r\n  }\r\n  if (size2 < *size)\r\n    *size = size2;\r\n  *buf = p->buf + p->pos;\r\n  return res;\r\n}\r\n\r\nstatic SRes LookToRead_Skip(void *pp, size_t offset)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  p->pos += offset;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LookToRead_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t rem = p->size - p->pos;\r\n  if (rem == 0)\r\n    return p->realStream->Read(p->realStream, buf, size);\r\n  if (rem > *size)\r\n    rem = *size;\r\n  memcpy(buf, p->buf + p->pos, rem);\r\n  p->pos += rem;\r\n  *size = rem;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  p->pos = p->size = 0;\r\n  return p->realStream->Seek(p->realStream, pos, origin);\r\n}\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead)\r\n{\r\n  p->s.Look = lookahead ?\r\n      LookToRead_Look_Lookahead :\r\n      LookToRead_Look_Exact;\r\n  p->s.Skip = LookToRead_Skip;\r\n  p->s.Read = LookToRead_Read;\r\n  p->s.Seek = LookToRead_Seek;\r\n}\r\n\r\nvoid LookToRead_Init(CLookToRead *p)\r\n{\r\n  p->pos = p->size = 0;\r\n}\r\n\r\nstatic SRes SecToLook_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CSecToLook *p = (CSecToLook *)pp;\r\n  return LookInStream_LookRead(p->realStream, buf, size);\r\n}\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p)\r\n{\r\n  p->s.Read = SecToLook_Read;\r\n}\r\n\r\nstatic SRes SecToRead_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CSecToRead *p = (CSecToRead *)pp;\r\n  return p->realStream->Read(p->realStream, buf, size);\r\n}\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p)\r\n{\r\n  p->s.Read = SecToRead_Read;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/7zVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 65\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.65\"\r\n#define MY_DATE \"2009-02-03\"\r\n#define MY_COPYRIGHT \": Igor Pavlov : Public domain\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \" \" MY_COPYRIGHT \" : \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Alloc.c",
    "content": "/* Alloc.c -- Memory allocation functions\r\n2008-09-24\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdlib.h>\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  {\r\n    void *p = malloc(size);\r\n    fprintf(stderr, \"\\nAlloc %10d bytes, count = %10d,  addr = %8X\", size, g_allocCount++, (unsigned)p);\r\n    return p;\r\n  }\r\n  #else\r\n  return malloc(size);\r\n  #endif\r\n}\r\n\r\nvoid MyFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d,  addr = %8X\", --g_allocCount, (unsigned)address);\r\n  #endif\r\n  free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#ifndef MEM_LARGE_PAGES\r\n#undef _7ZIP_LARGE_PAGES\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nSIZE_T g_LargePageSize = 0;\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n#endif\r\n\r\nvoid SetLargePageSize()\r\n{\r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  SIZE_T size = 0;\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        GetProcAddress(GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return;\r\n  size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return;\r\n  g_LargePageSize = size;\r\n  #endif\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))\r\n  {\r\n    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),\r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Alloc.h",
    "content": "/* Alloc.h -- Memory allocation functions\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size);\r\nvoid MyFree(void *address);\r\n\r\n#ifdef _WIN32\r\n\r\nvoid SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size);\r\nvoid MidFree(void *address);\r\nvoid *BigAlloc(size_t size);\r\nvoid BigFree(void *address);\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z.mak\" CFG=\"7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /FAs /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_SZ_ALLOC_DEBUG2\" /D \"_SZ_NO_INT_64_A\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z - Win32 Release\"\r\n# Name \"7z - Win32 Debug\"\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zBuf.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zBuf.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zFile.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zFile.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zStream.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bcj2.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bcj2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bra86.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z\"=.\\7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zAlloc.c",
    "content": "/* 7zAlloc.c -- Allocation functions\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n\r\n#endif\r\n\r\nvoid *SzAlloc(void *p, size_t size)\r\n{\r\n  p = p;\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *p, void *address)\r\n{\r\n  p = p;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(void *p, size_t size)\r\n{\r\n  p = p;\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *p, void *address)\r\n{\r\n  p = p;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zAlloc.h",
    "content": "/* 7zAlloc.h -- Allocation functions\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *SzAlloc(void *p, size_t size);\r\nvoid SzFree(void *p, void *address);\r\n\r\nvoid *SzAllocTemp(void *p, size_t size);\r\nvoid SzFreeTemp(void *p, void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zDecode.c",
    "content": "/* 7zDecode.c -- Decoding from 7z folder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"../../Bcj2.h\"\r\n#include \"../../Bra.h\"\r\n#include \"../../LzmaDec.h\"\r\n#include \"7zDecode.h\"\r\n\r\n#define k_Copy 0\r\n#define k_LZMA 0x30101\r\n#define k_BCJ 0x03030103\r\n#define k_BCJ2 0x0303011B\r\n\r\nstatic SRes SzDecodeLzma(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,\r\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)\r\n{\r\n  CLzmaDec state;\r\n  SRes res = SZ_OK;\r\n\r\n  LzmaDec_Construct(&state);\r\n  RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));\r\n  state.dic = outBuffer;\r\n  state.dicBufSize = outSize;\r\n  LzmaDec_Init(&state);\r\n\r\n  for (;;)\r\n  {\r\n    Byte *inBuf = NULL;\r\n    size_t lookahead = (1 << 18);\r\n    if (lookahead > inSize)\r\n      lookahead = (size_t)inSize;\r\n    res = inStream->Look((void *)inStream, (void **)&inBuf, &lookahead);\r\n    if (res != SZ_OK)\r\n      break;\r\n\r\n    {\r\n      SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;\r\n      ELzmaStatus status;\r\n      res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);\r\n      lookahead -= inProcessed;\r\n      inSize -= inProcessed;\r\n      if (res != SZ_OK)\r\n        break;\r\n      if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))\r\n      {\r\n        if (state.dicBufSize != outSize || lookahead != 0 ||\r\n            (status != LZMA_STATUS_FINISHED_WITH_MARK &&\r\n             status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))\r\n          res = SZ_ERROR_DATA;\r\n        break;\r\n      }\r\n      res = inStream->Skip((void *)inStream, inProcessed);\r\n      if (res != SZ_OK)\r\n        break;\r\n    }\r\n  }\r\n\r\n  LzmaDec_FreeProbs(&state, allocMain);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)\r\n{\r\n  while (inSize > 0)\r\n  {\r\n    void *inBuf;\r\n    size_t curSize = (1 << 18);\r\n    if (curSize > inSize)\r\n      curSize = (size_t)inSize;\r\n    RINOK(inStream->Look((void *)inStream, (void **)&inBuf, &curSize));\r\n    if (curSize == 0)\r\n      return SZ_ERROR_INPUT_EOF;\r\n    memcpy(outBuffer, inBuf, curSize);\r\n    outBuffer += curSize;\r\n    inSize -= curSize;\r\n    RINOK(inStream->Skip((void *)inStream, curSize));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)\r\n#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)\r\n\r\nSRes CheckSupportedFolder(const CSzFolder *f)\r\n{\r\n  if (f->NumCoders < 1 || f->NumCoders > 4)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (IS_UNSUPPORTED_CODER(f->Coders[0]))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (f->NumCoders == 1)\r\n  {\r\n    if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 2)\r\n  {\r\n    if (IS_NO_BCJ(f->Coders[1]) ||\r\n        f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||\r\n        f->NumBindPairs != 1 ||\r\n        f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 4)\r\n  {\r\n    if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||\r\n        IS_UNSUPPORTED_CODER(f->Coders[2]) ||\r\n        IS_NO_BCJ2(f->Coders[3]))\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    if (f->NumPackStreams != 4 ||\r\n        f->PackStreams[0] != 2 ||\r\n        f->PackStreams[1] != 6 ||\r\n        f->PackStreams[2] != 1 ||\r\n        f->PackStreams[3] != 0 ||\r\n        f->NumBindPairs != 3 ||\r\n        f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||\r\n        f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||\r\n        f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  return SZ_ERROR_UNSUPPORTED;\r\n}\r\n\r\nUInt64 GetSum(const UInt64 *values, UInt32 index)\r\n{\r\n  UInt64 sum = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < index; i++)\r\n    sum += values[i];\r\n  return sum;\r\n}\r\n\r\nSRes SzDecode2(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *inStream, UInt64 startPos,\r\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,\r\n    Byte *tempBuf[])\r\n{\r\n  UInt32 ci;\r\n  SizeT tempSizes[3] = { 0, 0, 0};\r\n  SizeT tempSize3 = 0;\r\n  Byte *tempBuf3 = 0;\r\n\r\n  RINOK(CheckSupportedFolder(folder));\r\n\r\n  for (ci = 0; ci < folder->NumCoders; ci++)\r\n  {\r\n    CSzCoderInfo *coder = &folder->Coders[ci];\r\n\r\n    if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)\r\n    {\r\n      UInt32 si = 0;\r\n      UInt64 offset;\r\n      UInt64 inSize;\r\n      Byte *outBufCur = outBuffer;\r\n      SizeT outSizeCur = outSize;\r\n      if (folder->NumCoders == 4)\r\n      {\r\n        UInt32 indices[] = { 3, 2, 0 };\r\n        UInt64 unpackSize = folder->UnpackSizes[ci];\r\n        si = indices[ci];\r\n        if (ci < 2)\r\n        {\r\n          Byte *temp;\r\n          outSizeCur = (SizeT)unpackSize;\r\n          if (outSizeCur != unpackSize)\r\n            return SZ_ERROR_MEM;\r\n          temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);\r\n          if (temp == 0 && outSizeCur != 0)\r\n            return SZ_ERROR_MEM;\r\n          outBufCur = tempBuf[1 - ci] = temp;\r\n          tempSizes[1 - ci] = outSizeCur;\r\n        }\r\n        else if (ci == 2)\r\n        {\r\n          if (unpackSize > outSize) /* check it */\r\n            return SZ_ERROR_PARAM;\r\n          tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);\r\n          tempSize3 = outSizeCur = (SizeT)unpackSize;\r\n        }\r\n        else\r\n          return SZ_ERROR_UNSUPPORTED;\r\n      }\r\n      offset = GetSum(packSizes, si);\r\n      inSize = packSizes[si];\r\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r\n\r\n      if (coder->MethodID == k_Copy)\r\n      {\r\n        if (inSize != outSizeCur) /* check it */\r\n          return SZ_ERROR_DATA;\r\n        RINOK(SzDecodeCopy(inSize, inStream, outBufCur));\r\n      }\r\n      else\r\n      {\r\n        RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));\r\n      }\r\n    }\r\n    else if (coder->MethodID == k_BCJ)\r\n    {\r\n      UInt32 state;\r\n      if (ci != 1)\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      x86_Convert_Init(state);\r\n      x86_Convert(outBuffer, outSize, 0, &state, 0);\r\n    }\r\n    else if (coder->MethodID == k_BCJ2)\r\n    {\r\n      UInt64 offset = GetSum(packSizes, 1);\r\n      UInt64 s3Size = packSizes[1];\r\n      SRes res;\r\n      if (ci != 3)\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r\n      tempSizes[2] = (SizeT)s3Size;\r\n      if (tempSizes[2] != s3Size)\r\n        return SZ_ERROR_MEM;\r\n      tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);\r\n      if (tempBuf[2] == 0 && tempSizes[2] != 0)\r\n        return SZ_ERROR_MEM;\r\n      res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);\r\n      RINOK(res)\r\n\r\n      res = Bcj2_Decode(\r\n          tempBuf3, tempSize3,\r\n          tempBuf[0], tempSizes[0],\r\n          tempBuf[1], tempSizes[1],\r\n          tempBuf[2], tempSizes[2],\r\n          outBuffer, outSize);\r\n      RINOK(res)\r\n    }\r\n    else\r\n      return SZ_ERROR_UNSUPPORTED;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *inStream, UInt64 startPos,\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  Byte *tempBuf[3] = { 0, 0, 0};\r\n  int i;\r\n  SRes res = SzDecode2(packSizes, folder, inStream, startPos,\r\n      outBuffer, (SizeT)outSize, allocMain, tempBuf);\r\n  for (i = 0; i < 3; i++)\r\n    IAlloc_Free(allocMain, tempBuf[i]);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zDecode.h",
    "content": "/* 7zDecode.h -- Decoding from 7z folder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n\r\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *stream, UInt64 startPos,\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zExtract.c",
    "content": "/* 7zExtract.c -- Extracting from 7z archive\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"7zDecode.h\"\r\n#include \"7zExtract.h\"\r\n\r\nSRes SzAr_Extract(\r\n    const CSzArEx *p,\r\n    ILookInStream *inStream,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer,\r\n    size_t *outBufferSize,\r\n    size_t *offset,\r\n    size_t *outSizeProcessed,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = p->FileIndexToFolderIndexMap[fileIndex];\r\n  SRes res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    IAlloc_Free(allocMain, *outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CSzFolder *folder = p->db.Folders + folderIndex;\r\n    UInt64 unpackSizeSpec = SzFolder_GetUnpackSize(folder);\r\n    size_t unpackSize = (size_t)unpackSizeSpec;\r\n    UInt64 startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);\r\n\r\n    if (unpackSize != unpackSizeSpec)\r\n      return SZ_ERROR_MEM;\r\n    *blockIndex = folderIndex;\r\n    IAlloc_Free(allocMain, *outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(LookInStream_SeekTo(inStream, startOffset));\r\n    \r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = unpackSize;\r\n      if (unpackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unpackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZ_ERROR_MEM;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        res = SzDecode(p->db.PackSizes +\r\n          p->FolderStartPackStreamIndex[folderIndex], folder,\r\n          inStream, startOffset,\r\n          *outBuffer, unpackSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (folder->UnpackCRCDefined)\r\n          {\r\n            if (CrcCalc(*outBuffer, unpackSize) != folder->UnpackCRC)\r\n              res = SZ_ERROR_CRC;\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i;\r\n    CSzFileItem *fileItem = p->db.Files + fileIndex;\r\n    *offset = 0;\r\n    for (i = p->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)p->db.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZ_ERROR_FAIL;\r\n    {\r\n      if (fileItem->FileCRCDefined)\r\n      {\r\n        if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)\r\n          res = SZ_ERROR_CRC;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zExtract.h",
    "content": "/* 7zExtract.h -- Extracting from 7z archive\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive.\r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send\r\n    these values from previous call:\r\n      *blockIndex,\r\n      *outBuffer,\r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid,\r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables\r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSRes SzAr_Extract(\r\n    const CSzArEx *db,\r\n    ILookInStream *inStream,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zHeader.c",
    "content": "/*  7zHeader.c -- 7z Headers\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zHeader.h",
    "content": "/* 7zHeader.h -- 7z Headers\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnpackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnpackSize,\r\n  k7zIdNumUnpackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCTime,\r\n  k7zIdATime,\r\n  k7zIdMTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos,\r\n  k7zIdDummy\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zIn.c",
    "content": "/* 7zIn.c -- 7z Input functions\r\n2008-12-31 : Igor Pavlov : Public domain */\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"../../CpuArch.h\"\r\n\r\n#include \"7zDecode.h\"\r\n#include \"7zIn.h\"\r\n\r\n#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }\r\n\r\n#define NUM_FOLDER_CODERS_MAX 32\r\n#define NUM_CODER_STREAMS_MAX 32\r\n\r\nvoid SzArEx_Init(CSzArEx *p)\r\n{\r\n  SzAr_Init(&p->db);\r\n  p->FolderStartPackStreamIndex = 0;\r\n  p->PackStreamStartPositions = 0;\r\n  p->FolderStartFileIndex = 0;\r\n  p->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)\r\n{\r\n  IAlloc_Free(alloc, p->FolderStartPackStreamIndex);\r\n  IAlloc_Free(alloc, p->PackStreamStartPositions);\r\n  IAlloc_Free(alloc, p->FolderStartFileIndex);\r\n  IAlloc_Free(alloc, p->FileIndexToFolderIndexMap);\r\n  SzAr_Free(&p->db, alloc);\r\n  SzArEx_Init(p);\r\n}\r\n\r\n/*\r\nUInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nUInt64 GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CSzFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n#define MY_ALLOC(T, p, size, alloc) { if ((size) == 0) p = 0; else \\\r\n  if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == 0) return SZ_ERROR_MEM; }\r\n\r\nstatic SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 startPos = 0;\r\n  UInt64 startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  MY_ALLOC(UInt32, p->FolderStartPackStreamIndex, p->db.NumFolders, alloc);\r\n  for (i = 0; i < p->db.NumFolders; i++)\r\n  {\r\n    p->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += p->db.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  MY_ALLOC(UInt64, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);\r\n\r\n  for (i = 0; i < p->db.NumPackStreams; i++)\r\n  {\r\n    p->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += p->db.PackSizes[i];\r\n  }\r\n\r\n  MY_ALLOC(UInt32, p->FolderStartFileIndex, p->db.NumFolders, alloc);\r\n  MY_ALLOC(UInt32, p->FileIndexToFolderIndexMap, p->db.NumFiles, alloc);\r\n\r\n  for (i = 0; i < p->db.NumFiles; i++)\r\n  {\r\n    CSzFileItem *file = p->db.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      p->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= p->db.NumFolders)\r\n          return SZ_ERROR_ARCHIVE;\r\n        p->FolderStartFileIndex[folderIndex] = i;\r\n        if (p->db.Folders[folderIndex].NumUnpackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    p->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= p->db.Folders[folderIndex].NumUnpackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return p->dataPos +\r\n    p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize)\r\n{\r\n  UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];\r\n  CSzFolder *folder = p->db.Folders + folderIndex;\r\n  UInt64 size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n  {\r\n    UInt64 t = size + p->db.PackSizes[packStreamIndex + i];\r\n    if (t < size) /* check it */\r\n      return SZ_ERROR_FAIL;\r\n    size = t;\r\n  }\r\n  *resSize = size;\r\n  return SZ_OK;\r\n}\r\n\r\n\r\n/*\r\nSRes SzReadTime(const CObjectVector<CBuf> &dataVector,\r\n    CObjectVector<CSzFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for (int i = 0; i < files.Size(); i++)\r\n  {\r\n    CSzFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCTime: file.IsCTimeDefined = defined; if (defined) file.CTime = fileTime; break;\r\n      case k7zIdATime: file.IsATimeDefined = defined; if (defined) file.ATime = fileTime; break;\r\n      case k7zIdMTime: file.IsMTimeDefined = defined; if (defined) file.MTime = fileTime; break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nstatic int TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nstatic SRes SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZ_ERROR_ARCHIVE;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadID(CSzData *sd, UInt64 *value)\r\n{\r\n  return SzReadNumber(sd, value);\r\n}\r\n\r\nstatic SRes SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZ_ERROR_ARCHIVE;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nstatic SRes SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZ_ERROR_ARCHIVE;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nstatic SRes SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  MY_ALLOC(Byte, *v, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, alloc);\r\n  MY_ALLOC(Byte, *v, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadHashDigests(\r\n    CSzData *sd,\r\n    size_t numItems,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *alloc)\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, alloc));\r\n  MY_ALLOC(UInt32, *digests, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadPackInfo(\r\n    CSzData *sd,\r\n    UInt64 *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    UInt64 **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadNumber(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  MY_ALLOC(UInt64, *packSizes, (size_t)*numPackStreams, alloc);\r\n\r\n  for (i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadNumber(sd, (*packSizes) + i));\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, alloc);\r\n    MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, alloc);\r\n    for (i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZ_ERROR_UNSUPPORTED;\r\n}\r\n\r\nstatic SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)\r\n{\r\n  UInt32 numCoders, numBindPairs, numPackStreams, i;\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  if (numCoders > NUM_FOLDER_CODERS_MAX)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  folder->NumCoders = numCoders;\r\n  \r\n  MY_ALLOC(CSzCoderInfo, folder->Coders, (size_t)numCoders, alloc);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfo_Init(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CSzCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      unsigned idSize, j;\r\n      Byte longID[15];\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      idSize = (unsigned)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, longID, idSize));\r\n      if (idSize > sizeof(coder->MethodID))\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      coder->MethodID = 0;\r\n      for (j = 0; j < idSize; j++)\r\n        coder->MethodID |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n        if (coder->NumInStreams > NUM_CODER_STREAMS_MAX ||\r\n            coder->NumOutStreams > NUM_CODER_STREAMS_MAX)\r\n          return SZ_ERROR_UNSUPPORTED;\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!Buf_Create(&coder->Props, (size_t)propertiesSize, alloc))\r\n          return SZ_ERROR_MEM;\r\n        RINOK(SzReadBytes(sd, coder->Props.data, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += coder->NumInStreams;\r\n    numOutStreams += coder->NumOutStreams;\r\n  }\r\n\r\n  if (numOutStreams == 0)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  folder->NumBindPairs = numBindPairs = numOutStreams - 1;\r\n  MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, alloc);\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bp = folder->BindPairs + i;\r\n    RINOK(SzReadNumber32(sd, &bp->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bp->OutIndex));\r\n  }\r\n\r\n  if (numInStreams < numBindPairs)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  folder->NumPackStreams = numPackStreams = numInStreams - numBindPairs;\r\n  MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackStreams, alloc);\r\n\r\n  if (numPackStreams == 1)\r\n  {\r\n    for (i = 0; i < numInStreams ; i++)\r\n      if (SzFolder_FindBindPairForInStream(folder, i) < 0)\r\n        break;\r\n    if (i == numInStreams)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    folder->PackStreams[0] = i;\r\n  }\r\n  else\r\n    for (i = 0; i < numPackStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadUnpackInfo(\r\n    CSzData *sd,\r\n    UInt32 *numFolders,\r\n    CSzFolder **folders,  /* for alloc */\r\n    ISzAlloc *alloc,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n    MY_ALLOC(CSzFolder, *folders, (size_t)*numFolders, alloc);\r\n\r\n    for (i = 0; i < *numFolders; i++)\r\n      SzFolder_Init((*folders) + i);\r\n\r\n    for (i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, alloc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnpackSize));\r\n\r\n  for (i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CSzFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);\r\n\r\n    MY_ALLOC(UInt64, folder->UnpackSizes, (size_t)numOutStreams, alloc);\r\n\r\n    for (j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadNumber(sd, folder->UnpackSizes + j));\r\n    }\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SRes res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < *numFolders; i++)\r\n        {\r\n          CSzFolder *folder = (*folders) + i;\r\n          folder->UnpackCRCDefined = crcsDefined[i];\r\n          folder->UnpackCRC = crcs[i];\r\n        }\r\n      }\r\n      IAlloc_Free(allocTemp, crcs);\r\n      IAlloc_Free(allocTemp, crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nstatic SRes SzReadSubStreamsInfo(\r\n    CSzData *sd,\r\n    UInt32 numFolders,\r\n    CSzFolder *folders,\r\n    UInt32 *numUnpackStreams,\r\n    UInt64 **unpackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n    folders[i].NumUnpackStreams = 1;\r\n  *numUnpackStreams = numFolders;\r\n\r\n  for (;;)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnpackStream)\r\n    {\r\n      *numUnpackStreams = 0;\r\n      for (i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnpackStreams = numStreams;\r\n        *numUnpackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnpackStreams == 0)\r\n  {\r\n    *unpackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unpackSizes = (UInt64 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt64));\r\n    RINOM(*unpackSizes);\r\n    *digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    UInt64 sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      UInt64 size;\r\n      RINOK(SzReadNumber(sd, &size));\r\n      (*unpackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unpackSizes)[si++] = SzFolder_GetUnpackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for (i = 0; i < *numUnpackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  for (;;)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0;\r\n      UInt32 *digests2 = 0;\r\n      SRes res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CSzFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnpackStreams;\r\n          if (numSubstreams == 1 && folder->UnpackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnpackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      IAlloc_Free(allocTemp, digestsDefined2);\r\n      IAlloc_Free(allocTemp, digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nstatic SRes SzReadStreamsInfo(\r\n    CSzData *sd,\r\n    UInt64 *dataOffset,\r\n    CSzAr *p,\r\n    UInt32 *numUnpackStreams,\r\n    UInt64 **unpackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    ISzAlloc *alloc,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,\r\n            &p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc));\r\n        break;\r\n      }\r\n      case k7zIdUnpackInfo:\r\n      {\r\n        RINOK(SzReadUnpackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,\r\n            numUnpackStreams, unpackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZ_ERROR_UNSUPPORTED;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nstatic SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CSzFileItem *file = files + i;\r\n    while (pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZ_ERROR_ARCHIVE;\r\n        if (pos + 2 > sd->Size)\r\n          return SZ_ERROR_ARCHIVE;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZ_ERROR_ARCHIVE;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    MY_ALLOC(char, file->Name, (size_t)len, alloc);\r\n\r\n    len = 0;\r\n    while (2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while (numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadHeader2(\r\n    CSzArEx *p,   /* allocMain */\r\n    CSzData *sd,\r\n    UInt64 **unpackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    Byte **lwtVector,         /* allocTemp */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnpackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CSzFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &p->dataPos,\r\n        &p->db,\r\n        &numUnpackStreams,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests, allocMain, allocTemp));\r\n    p->dataPos += p->startPosAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZ_ERROR_ARCHIVE;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  p->db.NumFiles = numFiles;\r\n\r\n  MY_ALLOC(CSzFileItem, files, (size_t)numFiles, allocMain);\r\n\r\n  p->db.Files = files;\r\n  for (i = 0; i < numFiles; i++)\r\n    SzFile_Init(files + i);\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdMTime:\r\n      {\r\n        RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));\r\n        RINOK(SzReadSwitch(sd));\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CSzFileItem *f = &files[i];\r\n          Byte defined = (*lwtVector)[i];\r\n          f->MTimeDefined = defined;\r\n          f->MTime.Low = f->MTime.High = 0;\r\n          if (defined)\r\n          {\r\n            RINOK(SzReadUInt32(sd, &f->MTime.Low));\r\n            RINOK(SzReadUInt32(sd, &f->MTime.High));\r\n          }\r\n        }\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      CSzFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if (file->HasStream)\r\n      {\r\n        file->IsDir = 0;\r\n        file->Size = (*unpackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->FileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDir = 1;\r\n        else\r\n          file->IsDir = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->FileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArEx_Fill(p, allocMain);\r\n}\r\n\r\nstatic SRes SzReadHeader(\r\n    CSzArEx *p,\r\n    CSzData *sd,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 *unpackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  Byte *lwtVector = 0;\r\n  SRes res = SzReadHeader2(p, sd,\r\n      &unpackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector, &lwtVector,\r\n      allocMain, allocTemp);\r\n  IAlloc_Free(allocTemp, unpackSizes);\r\n  IAlloc_Free(allocTemp, digestsDefined);\r\n  IAlloc_Free(allocTemp, digests);\r\n  IAlloc_Free(allocTemp, emptyStreamVector);\r\n  IAlloc_Free(allocTemp, emptyFileVector);\r\n  IAlloc_Free(allocTemp, lwtVector);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzReadAndDecodePackedStreams2(\r\n    ILookInStream *inStream,\r\n    CSzData *sd,\r\n    CBuf *outBuffer,\r\n    UInt64 baseOffset,\r\n    CSzAr *p,\r\n    UInt64 **unpackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnpackStreams = 0;\r\n  UInt64 dataStartPos;\r\n  CSzFolder *folder;\r\n  UInt64 unpackSize;\r\n  SRes res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,\r\n      &numUnpackStreams,  unpackSizes, digestsDefined, digests,\r\n      allocTemp, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (p->NumFolders != 1)\r\n    return SZ_ERROR_ARCHIVE;\r\n\r\n  folder = p->Folders;\r\n  unpackSize = SzFolder_GetUnpackSize(folder);\r\n  \r\n  RINOK(LookInStream_SeekTo(inStream, dataStartPos));\r\n\r\n  if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))\r\n    return SZ_ERROR_MEM;\r\n  \r\n  res = SzDecode(p->PackSizes, folder,\r\n          inStream, dataStartPos,\r\n          outBuffer->data, (size_t)unpackSize, allocTemp);\r\n  RINOK(res);\r\n  if (folder->UnpackCRCDefined)\r\n    if (CrcCalc(outBuffer->data, (size_t)unpackSize) != folder->UnpackCRC)\r\n      return SZ_ERROR_CRC;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadAndDecodePackedStreams(\r\n    ILookInStream *inStream,\r\n    CSzData *sd,\r\n    CBuf *outBuffer,\r\n    UInt64 baseOffset,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  CSzAr p;\r\n  UInt64 *unpackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  SRes res;\r\n  SzAr_Init(&p);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,\r\n    &p, &unpackSizes, &digestsDefined, &digests,\r\n    allocTemp);\r\n  SzAr_Free(&p, allocTemp);\r\n  IAlloc_Free(allocTemp, unpackSizes);\r\n  IAlloc_Free(allocTemp, digestsDefined);\r\n  IAlloc_Free(allocTemp, digests);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzArEx_Open2(\r\n    CSzArEx *p,\r\n    ILookInStream *inStream,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte header[k7zStartHeaderSize];\r\n  UInt64 nextHeaderOffset, nextHeaderSize;\r\n  size_t nextHeaderSizeT;\r\n  UInt32 nextHeaderCRC;\r\n  CBuf buffer;\r\n  SRes res;\r\n\r\n  RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));\r\n\r\n  if (!TestSignatureCandidate(header))\r\n    return SZ_ERROR_NO_ARCHIVE;\r\n  if (header[6] != k7zMajorVersion)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  nextHeaderOffset = GetUi64(header + 12);\r\n  nextHeaderSize = GetUi64(header + 20);\r\n  nextHeaderCRC = GetUi32(header + 28);\r\n\r\n  p->startPosAfterHeader = k7zStartHeaderSize;\r\n  \r\n  if (CrcCalc(header + 12, 20) != GetUi32(header + 8))\r\n    return SZ_ERROR_CRC;\r\n\r\n  nextHeaderSizeT = (size_t)nextHeaderSize;\r\n  if (nextHeaderSizeT != nextHeaderSize)\r\n    return SZ_ERROR_MEM;\r\n  if (nextHeaderSizeT == 0)\r\n    return SZ_OK;\r\n  if (nextHeaderOffset > nextHeaderOffset + nextHeaderSize ||\r\n      nextHeaderOffset > nextHeaderOffset + nextHeaderSize + k7zStartHeaderSize)\r\n    return SZ_ERROR_NO_ARCHIVE;\r\n\r\n  {\r\n    Int64 pos = 0;\r\n    RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));\r\n    if ((UInt64)pos < nextHeaderOffset ||\r\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset ||\r\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)\r\n      return SZ_ERROR_INPUT_EOF;\r\n  }\r\n\r\n  RINOK(LookInStream_SeekTo(inStream, k7zStartHeaderSize + nextHeaderOffset));\r\n\r\n  if (!Buf_Create(&buffer, nextHeaderSizeT, allocTemp))\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LookInStream_Read(inStream, buffer.data, nextHeaderSizeT);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = SZ_ERROR_ARCHIVE;\r\n    if (CrcCalc(buffer.data, nextHeaderSizeT) == nextHeaderCRC)\r\n    {\r\n      CSzData sd;\r\n      UInt64 type;\r\n      sd.Data = buffer.data;\r\n      sd.Size = buffer.size;\r\n      res = SzReadID(&sd, &type);\r\n      if (res == SZ_OK)\r\n      {\r\n        if (type == k7zIdEncodedHeader)\r\n        {\r\n          CBuf outBuffer;\r\n          Buf_Init(&outBuffer);\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, p->startPosAfterHeader, allocTemp);\r\n          if (res != SZ_OK)\r\n            Buf_Free(&outBuffer, allocTemp);\r\n          else\r\n          {\r\n            Buf_Free(&buffer, allocTemp);\r\n            buffer.data = outBuffer.data;\r\n            buffer.size = outBuffer.size;\r\n            sd.Data = buffer.data;\r\n            sd.Size = buffer.size;\r\n            res = SzReadID(&sd, &type);\r\n          }\r\n        }\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        if (type == k7zIdHeader)\r\n          res = SzReadHeader(p, &sd, allocMain, allocTemp);\r\n        else\r\n          res = SZ_ERROR_UNSUPPORTED;\r\n      }\r\n    }\r\n  }\r\n  Buf_Free(&buffer, allocTemp);\r\n  return res;\r\n}\r\n\r\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)\r\n{\r\n  SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArEx_Free(p, allocMain);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zIn.h",
    "content": "/* 7zIn.h -- 7z Input functions\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n\r\ntypedef struct\r\n{\r\n  CSzAr db;\r\n  \r\n  UInt64 startPosAfterHeader;\r\n  UInt64 dataPos;\r\n\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  UInt64 *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n} CSzArEx;\r\n\r\nvoid SzArEx_Init(CSzArEx *p);\r\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);\r\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);\r\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);\r\n\r\n/*\r\nErrors:\r\nSZ_ERROR_NO_ARCHIVE\r\nSZ_ERROR_ARCHIVE\r\nSZ_ERROR_UNSUPPORTED\r\nSZ_ERROR_MEM\r\nSZ_ERROR_CRC\r\nSZ_ERROR_INPUT_EOF\r\nSZ_ERROR_FAIL\r\n*/\r\n\r\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zItem.c",
    "content": "/* 7zItem.c -- 7z Items\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zItem.h\"\r\n\r\nvoid SzCoderInfo_Init(CSzCoderInfo *p)\r\n{\r\n  Buf_Init(&p->Props);\r\n}\r\n\r\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc)\r\n{\r\n  Buf_Free(&p->Props, alloc);\r\n  SzCoderInfo_Init(p);\r\n}\r\n\r\nvoid SzFolder_Init(CSzFolder *p)\r\n{\r\n  p->Coders = 0;\r\n  p->BindPairs = 0;\r\n  p->PackStreams = 0;\r\n  p->UnpackSizes = 0;\r\n  p->NumCoders = 0;\r\n  p->NumBindPairs = 0;\r\n  p->NumPackStreams = 0;\r\n  p->UnpackCRCDefined = 0;\r\n  p->UnpackCRC = 0;\r\n  p->NumUnpackStreams = 0;\r\n}\r\n\r\nvoid SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  if (p->Coders)\r\n    for (i = 0; i < p->NumCoders; i++)\r\n      SzCoderInfo_Free(&p->Coders[i], alloc);\r\n  IAlloc_Free(alloc, p->Coders);\r\n  IAlloc_Free(alloc, p->BindPairs);\r\n  IAlloc_Free(alloc, p->PackStreams);\r\n  IAlloc_Free(alloc, p->UnpackSizes);\r\n  SzFolder_Init(p);\r\n}\r\n\r\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumCoders; i++)\r\n    result += p->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumBindPairs; i++)\r\n    if (p->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumBindPairs; i++)\r\n    if (p->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p)\r\n{\r\n  int i = (int)SzFolder_GetNumOutStreams(p);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolder_FindBindPairForOutStream(p, i) < 0)\r\n      return p->UnpackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\nvoid SzFile_Init(CSzFileItem *p)\r\n{\r\n  p->HasStream = 1;\r\n  p->IsDir = 0;\r\n  p->IsAnti = 0;\r\n  p->FileCRCDefined = 0;\r\n  p->MTimeDefined = 0;\r\n  p->Name = 0;\r\n}\r\n\r\nstatic void SzFile_Free(CSzFileItem *p, ISzAlloc *alloc)\r\n{\r\n  IAlloc_Free(alloc, p->Name);\r\n  SzFile_Init(p);\r\n}\r\n\r\nvoid SzAr_Init(CSzAr *p)\r\n{\r\n  p->PackSizes = 0;\r\n  p->PackCRCsDefined = 0;\r\n  p->PackCRCs = 0;\r\n  p->Folders = 0;\r\n  p->Files = 0;\r\n  p->NumPackStreams = 0;\r\n  p->NumFolders = 0;\r\n  p->NumFiles = 0;\r\n}\r\n\r\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  if (p->Folders)\r\n    for (i = 0; i < p->NumFolders; i++)\r\n      SzFolder_Free(&p->Folders[i], alloc);\r\n  if (p->Files)\r\n    for (i = 0; i < p->NumFiles; i++)\r\n      SzFile_Free(&p->Files[i], alloc);\r\n  IAlloc_Free(alloc, p->PackSizes);\r\n  IAlloc_Free(alloc, p->PackCRCsDefined);\r\n  IAlloc_Free(alloc, p->PackCRCs);\r\n  IAlloc_Free(alloc, p->Folders);\r\n  IAlloc_Free(alloc, p->Files);\r\n  SzAr_Init(p);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zItem.h",
    "content": "/* 7zItem.h -- 7z Items\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../7zBuf.h\"\r\n\r\ntypedef struct\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  UInt64 MethodID;\r\n  CBuf Props;\r\n} CSzCoderInfo;\r\n\r\nvoid SzCoderInfo_Init(CSzCoderInfo *p);\r\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc);\r\n\r\ntypedef struct\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n} CBindPair;\r\n\r\ntypedef struct\r\n{\r\n  CSzCoderInfo *Coders;\r\n  CBindPair *BindPairs;\r\n  UInt32 *PackStreams;\r\n  UInt64 *UnpackSizes;\r\n  UInt32 NumCoders;\r\n  UInt32 NumBindPairs;\r\n  UInt32 NumPackStreams;\r\n  int UnpackCRCDefined;\r\n  UInt32 UnpackCRC;\r\n\r\n  UInt32 NumUnpackStreams;\r\n} CSzFolder;\r\n\r\nvoid SzFolder_Init(CSzFolder *p);\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);\r\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p);\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r\n\r\ntypedef struct\r\n{\r\n  UInt32 Low;\r\n  UInt32 High;\r\n} CNtfsFileTime;\r\n\r\ntypedef struct\r\n{\r\n  CNtfsFileTime MTime;\r\n  UInt64 Size;\r\n  char *Name;\r\n  UInt32 FileCRC;\r\n\r\n  Byte HasStream;\r\n  Byte IsDir;\r\n  Byte IsAnti;\r\n  Byte FileCRCDefined;\r\n  Byte MTimeDefined;\r\n} CSzFileItem;\r\n\r\nvoid SzFile_Init(CSzFileItem *p);\r\n\r\ntypedef struct\r\n{\r\n  UInt64 *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  CSzFolder *Folders;\r\n  CSzFileItem *Files;\r\n  UInt32 NumPackStreams;\r\n  UInt32 NumFolders;\r\n  UInt32 NumFiles;\r\n} CSzAr;\r\n\r\nvoid SzAr_Init(CSzAr *p);\r\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/7zMain.c",
    "content": "/* 7zMain.c - Test application for 7z Decoder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <stdlib.h>\r\n#include <stdio.h>\r\n#include <string.h>\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"../../7zFile.h\"\r\n#include \"../../7zVersion.h\"\r\n\r\n#include \"7zAlloc.h\"\r\n#include \"7zExtract.h\"\r\n#include \"7zIn.h\"\r\n\r\nstatic void ConvertNumberToString(UInt64 value, char *s)\r\n{\r\n  char temp[32];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (char)('0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\n#define PERIOD_4 (4 * 365 + 1)\r\n#define PERIOD_100 (PERIOD_4 * 25 - 1)\r\n#define PERIOD_400 (PERIOD_100 * 4 + 1)\r\n\r\nstatic void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)\r\n{\r\n  unsigned year, mon, day, hour, min, sec;\r\n  UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  unsigned temp;\r\n  UInt32 v;\r\n  v64 /= 10000000;\r\n  sec = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  min = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  hour = (unsigned)(v64 % 24);\r\n  v64 /= 24;\r\n\r\n  v = (UInt32)v64;\r\n\r\n  year = (unsigned)(1601 + v / PERIOD_400 * 400);\r\n  v %= PERIOD_400;\r\n\r\n  temp = (unsigned)(v / PERIOD_100);\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp * 100;\r\n  v -= temp * PERIOD_100;\r\n\r\n  temp = v / PERIOD_4;\r\n  if (temp == 25)\r\n    temp = 24;\r\n  year += temp * 4;\r\n  v -= temp * PERIOD_4;\r\n\r\n  temp = v / 365;\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp;\r\n  v -= temp * 365;\r\n\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  for (mon = 1; mon <= 12; mon++)\r\n  {\r\n    unsigned s = ms[mon - 1];\r\n    if (v < s)\r\n      break;\r\n    v -= s;\r\n  }\r\n  day = (unsigned)v + 1;\r\n  sprintf(s, \"%04d-%02d-%02d %02d:%02d:%02d\", year, mon, day, hour, min, sec);\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint MY_CDECL main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CLookToRead lookStream;\r\n  CSzArEx db;\r\n  SRes res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  if (InFile_Open(&archiveStream.file, args[2]))\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  \r\n  FileInStream_CreateVTable(&archiveStream);\r\n  LookToRead_CreateVTable(&lookStream, False);\r\n  \r\n  lookStream.realStream = &archiveStream.s;\r\n  LookToRead_Init(&lookStream);\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  CrcGenerateTable();\r\n\r\n  SzArEx_Init(&db);\r\n  res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0, testCommand = 0, extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0) listCommand = 1;\r\n    else if (strcmp(command, \"t\") == 0) testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0) extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        CSzFileItem *f = db.db.Files + i;\r\n        char s[32], t[32];\r\n        ConvertNumberToString(f->Size, s);\r\n        if (f->MTimeDefined)\r\n          ConvertFileTimeToString(&f->MTime, t);\r\n        else\r\n          strcpy(t, \"                   \");\r\n\r\n        printf(\"%s %10s  %s\\n\", t, s, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      /*\r\n      if you need cache, use these 3 variables.\r\n      if you use external function, you can make these variable as static.\r\n      */\r\n      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r\n      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r\n      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CSzFileItem *f = db.db.Files + i;\r\n        if (f->IsDir)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ?\r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDir)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzAr_Extract(&db, &lookStream.s, i,\r\n            &blockIndex, &outBuffer, &outBufferSize,\r\n            &offset, &outSizeProcessed,\r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          CSzFile outFile;\r\n          size_t processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          if (OutFile_Open(&outFile, fileName))\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n          processedSize = outSizeProcessed;\r\n          if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 ||\r\n              processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n          if (File_Close(&outFile))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      IAlloc_Free(&allocImp, outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZ_ERROR_FAIL;\r\n    }\r\n  }\r\n  SzArEx_Free(&db, &allocImp);\r\n\r\n  File_Close(&archiveStream.file);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == SZ_ERROR_UNSUPPORTED)\r\n    PrintError(\"decoder doesn't support this archive\");\r\n  else if (res == SZ_ERROR_MEM)\r\n    PrintError(\"can not allocate memory\");\r\n  else if (res == SZ_ERROR_CRC)\r\n    PrintError(\"CRC error\");\r\n  else\r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/makefile",
    "content": "MY_STATIC_LINK=1\r\n\r\nPROG = 7zDec.exe\r\n\r\nC_OBJS = \\\r\n  $O\\7zBuf.obj \\\r\n  $O\\7zBuf2.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\Bcj2.obj \\\r\n  $O\\7zFile.obj \\\r\n  $O\\7zStream.obj \\\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $(C_OBJS) \\\r\n\r\n!include \"../../../CPP/Build.mak\"\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL_O1)\r\n$(C_OBJS): ../../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Archive/7z/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB =\r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = 7zAlloc.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o 7zFile.o 7zStream.o\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuf.o: ../../7zBuf.c\r\n\t$(CXX) $(CFLAGS) ../../7zBuf.c\r\n\r\n7zBuf2.o: ../../7zBuf2.c\r\n\t$(CXX) $(CFLAGS) ../../7zBuf2.c\r\n\r\n7zCrc.o: ../../7zCrc.c\r\n\t$(CXX) $(CFLAGS) ../../7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\nLzmaDec.o: ../../LzmaDec.c\r\n\t$(CXX) $(CFLAGS) ../../LzmaDec.c\r\n\r\nBra86.o: ../../Bra86.c\r\n\t$(CXX) $(CFLAGS) ../../Bra86.c\r\n\r\nBcj2.o: ../../Bcj2.c\r\n\t$(CXX) $(CFLAGS) ../../Bcj2.c\r\n\r\n7zFile.o: ../../7zFile.c\r\n\t$(CXX) $(CFLAGS) ../../7zFile.c\r\n\r\n7zStream.o: ../../7zStream.c\r\n\t$(CXX) $(CFLAGS) ../../7zStream.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Bcj2.c",
    "content": "/* Bcj2.c -- Converter for x86 code (BCJ2)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bcj2.h\"\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)\r\n#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*buffer++)\r\n#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }\r\n#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \\\r\n  { int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }}\r\n\r\n#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;\r\n\r\nint Bcj2_Decode(\r\n    const Byte *buf0, SizeT size0,\r\n    const Byte *buf1, SizeT size1,\r\n    const Byte *buf2, SizeT size2,\r\n    const Byte *buf3, SizeT size3,\r\n    Byte *outBuf, SizeT outSize)\r\n{\r\n  CProb p[256 + 2];\r\n  SizeT inPos = 0, outPos = 0;\r\n\r\n  const Byte *buffer, *bufferLim;\r\n  UInt32 range, code;\r\n  Byte prevByte = 0;\r\n\r\n  unsigned int i;\r\n  for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)\r\n    p[i] = kBitModelTotal >> 1;\r\n\r\n  buffer = buf3;\r\n  bufferLim = buffer + size3;\r\n  RC_INIT2\r\n\r\n  if (outSize == 0)\r\n    return SZ_OK;\r\n\r\n  for (;;)\r\n  {\r\n    Byte b;\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    UInt32 ttt;\r\n\r\n    SizeT limit = size0 - inPos;\r\n    if (outSize - outPos < limit)\r\n      limit = outSize - outPos;\r\n    while (limit != 0)\r\n    {\r\n      Byte b = buf0[inPos];\r\n      outBuf[outPos++] = b;\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      inPos++;\r\n      prevByte = b;\r\n      limit--;\r\n    }\r\n\r\n    if (limit == 0 || outPos == outSize)\r\n      break;\r\n\r\n    b = buf0[inPos++];\r\n\r\n    if (b == 0xE8)\r\n      prob = p + prevByte;\r\n    else if (b == 0xE9)\r\n      prob = p + 256;\r\n    else\r\n      prob = p + 257;\r\n\r\n    IF_BIT_0(prob)\r\n    {\r\n      UPDATE_0(prob)\r\n      prevByte = b;\r\n    }\r\n    else\r\n    {\r\n      UInt32 dest;\r\n      const Byte *v;\r\n      UPDATE_1(prob)\r\n      if (b == 0xE8)\r\n      {\r\n        v = buf1;\r\n        if (size1 < 4)\r\n          return SZ_ERROR_DATA;\r\n        buf1 += 4;\r\n        size1 -= 4;\r\n      }\r\n      else\r\n      {\r\n        v = buf2;\r\n        if (size2 < 4)\r\n          return SZ_ERROR_DATA;\r\n        buf2 += 4;\r\n        size2 -= 4;\r\n      }\r\n      dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |\r\n          ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);\r\n      outBuf[outPos++] = (Byte)dest;\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 8);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 16);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = prevByte = (Byte)(dest >> 24);\r\n    }\r\n  }\r\n  return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Bcj2.h",
    "content": "/* Bcj2.h -- Converter for x86 code (BCJ2)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __BCJ2_H\r\n#define __BCJ2_H\r\n\r\n#include \"Types.h\"\r\n\r\n/*\r\nConditions:\r\n  outSize <= FullOutputSize,\r\n  where FullOutputSize is full size of output stream of x86_2 filter.\r\n\r\nIf buf0 overlaps outBuf, there are two required conditions:\r\n  1) (buf0 >= outBuf)\r\n  2) (buf0 + size0 >= outBuf + FullOutputSize).\r\n\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nint Bcj2_Decode(\r\n    const Byte *buf0, SizeT size0,\r\n    const Byte *buf1, SizeT size1,\r\n    const Byte *buf2, SizeT size2,\r\n    const Byte *buf3, SizeT size3,\r\n    Byte *outBuf, SizeT outSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Bra.c",
    "content": "/* Bra.c -- Converters for RISC code\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  ip += 8;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      dest >>= 2;\r\n      data[i + 2] = (Byte)(dest >> 16);\r\n      data[i + 1] = (Byte)(dest >> 8);\r\n      data[i + 0] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  ip += 4;\r\n  for (i = 0; i <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 &&\r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src =\r\n        (((UInt32)data[i + 1] & 0x7) << 19) |\r\n        ((UInt32)data[i + 0] << 11) |\r\n        (((UInt32)data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));\r\n      data[i + 0] = (Byte)(dest >> 11);\r\n      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));\r\n      data[i + 2] = (Byte)dest;\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)\r\n    {\r\n      UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  UInt32 i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||\r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src =\r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      UInt32 dest;\r\n      \r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = ip + i + src;\r\n      else\r\n        dest = src - (ip + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Bra.h",
    "content": "/* Bra.h -- Branch converters for executables\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __BRA_H\r\n#define __BRA_H\r\n\r\n#include \"Types.h\"\r\n\r\n/*\r\nThese functions convert relative addresses to absolute addresses\r\nin CALL instructions to increase the compression ratio.\r\n  \r\n  In:\r\n    data     - data buffer\r\n    size     - size of data\r\n    ip       - current virtual Instruction Pinter (IP) value\r\n    state    - state variable for x86 converter\r\n    encoding - 0 (for decoding), 1 (for encoding)\r\n  \r\n  Out:\r\n    state    - state variable for x86 converter\r\n\r\n  Returns:\r\n    The number of processed bytes. If you call these functions with multiple calls,\r\n    you must start next call with first byte after block of processed bytes.\r\n  \r\n  Type   Endian  Alignment  LookAhead\r\n  \r\n  x86    little      1          4\r\n  ARMT   little      2          2\r\n  ARM    little      4          0\r\n  PPC     big        4          0\r\n  SPARC   big        4          0\r\n  IA64   little     16          0\r\n\r\n  size must be >= Alignment + LookAhead, if it's not last block.\r\n  If (size < Alignment + LookAhead), converter returns 0.\r\n\r\n  Example:\r\n\r\n    UInt32 ip = 0;\r\n    for ()\r\n    {\r\n      ; size must be >= Alignment + LookAhead, if it's not last block\r\n      SizeT processed = Convert(data, size, ip, 1);\r\n      data += processed;\r\n      size -= processed;\r\n      ip += processed;\r\n    }\r\n*/\r\n\r\n#define x86_Convert_Init(state) { state = 0; }\r\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);\r\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Bra86.c",
    "content": "/* Bra86.c -- Converter for x86 code (BCJ)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)\r\n{\r\n  SizeT bufferPos = 0, prevPosT;\r\n  UInt32 prevMask = *state & 0x7;\r\n  if (size < 5)\r\n    return 0;\r\n  ip += 5;\r\n  prevPosT = (SizeT)0 - 1;\r\n\r\n  for (;;)\r\n  {\r\n    Byte *p = data + bufferPos;\r\n    Byte *limit = data + size - 4;\r\n    for (; p < limit; p++)\r\n      if ((*p & 0xFE) == 0xE8)\r\n        break;\r\n    bufferPos = (SizeT)(p - data);\r\n    if (p >= limit)\r\n      break;\r\n    prevPosT = bufferPos - prevPosT;\r\n    if (prevPosT > 3)\r\n      prevMask = 0;\r\n    else\r\n    {\r\n      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r\n      if (prevMask != 0)\r\n      {\r\n        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r\n        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r\n        {\r\n          prevPosT = bufferPos;\r\n          prevMask = ((prevMask << 1) & 0x7) | 1;\r\n          bufferPos++;\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    prevPosT = bufferPos;\r\n\r\n    if (Test86MSByte(p[4]))\r\n    {\r\n      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r\n      UInt32 dest;\r\n      for (;;)\r\n      {\r\n        Byte b;\r\n        int index;\r\n        if (encoding)\r\n          dest = (ip + (UInt32)bufferPos) + src;\r\n        else\r\n          dest = src - (ip + (UInt32)bufferPos);\r\n        if (prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[prevMask] * 8;\r\n        b = (Byte)(dest >> (24 - index));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index)) - 1);\r\n      }\r\n      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      p[3] = (Byte)(dest >> 16);\r\n      p[2] = (Byte)(dest >> 8);\r\n      p[1] = (Byte)dest;\r\n      bufferPos += 5;\r\n    }\r\n    else\r\n    {\r\n      prevMask = ((prevMask << 1) & 0x7) | 1;\r\n      bufferPos++;\r\n    }\r\n  }\r\n  prevPosT = bufferPos - prevPosT;\r\n  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/BraIA64.c",
    "content": "/* BraIA64.c -- Converter for IA-64 code\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\nstatic const Byte kBranchTable[32] =\r\n{\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0\r\n};\r\n\r\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 16)\r\n    return 0;\r\n  size -= 16;\r\n  for (i = 0; i <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    int slot;\r\n    for (slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      UInt32 bytePos, bitRes;\r\n      UInt64 instruction, instNorm;\r\n      int j;\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      bytePos = (bitPos >> 3);\r\n      bitRes = bitPos & 0x7;\r\n      instruction = 0;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)data[i + j + bytePos] << (8 * j);\r\n\r\n      instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)\r\n      {\r\n        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);\r\n        UInt32 dest;\r\n        src |= ((UInt32)(instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        if (encoding)\r\n          dest = ip + (UInt32)i + src;\r\n        else\r\n          dest = src - (ip + (UInt32)i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~((UInt64)(0x8FFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/CpuArch.h",
    "content": "/* CpuArch.h\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __CPUARCH_H\r\n#define __CPUARCH_H\r\n\r\n/*\r\nLITTLE_ENDIAN_UNALIGN means:\r\n  1) CPU is LITTLE_ENDIAN\r\n  2) it's allowed to make unaligned memory accesses\r\nif LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know\r\nabout these properties of platform.\r\n*/\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#ifdef LITTLE_ENDIAN_UNALIGN\r\n\r\n#define GetUi16(p) (*(const UInt16 *)(p))\r\n#define GetUi32(p) (*(const UInt32 *)(p))\r\n#define GetUi64(p) (*(const UInt64 *)(p))\r\n#define SetUi32(p, d) *(UInt32 *)(p) = (d);\r\n\r\n#else\r\n\r\n#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))\r\n\r\n#define GetUi32(p) ( \\\r\n             ((const Byte *)(p))[0]        | \\\r\n    ((UInt32)((const Byte *)(p))[1] <<  8) | \\\r\n    ((UInt32)((const Byte *)(p))[2] << 16) | \\\r\n    ((UInt32)((const Byte *)(p))[3] << 24))\r\n\r\n#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))\r\n\r\n#define SetUi32(p, d) { UInt32 _x_ = (d); \\\r\n    ((Byte *)(p))[0] = (Byte)_x_; \\\r\n    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \\\r\n    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \\\r\n    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }\r\n\r\n#endif\r\n\r\n#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)\r\n\r\n#pragma intrinsic(_byteswap_ulong)\r\n#pragma intrinsic(_byteswap_uint64)\r\n#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))\r\n#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))\r\n\r\n#else\r\n\r\n#define GetBe32(p) ( \\\r\n    ((UInt32)((const Byte *)(p))[0] << 24) | \\\r\n    ((UInt32)((const Byte *)(p))[1] << 16) | \\\r\n    ((UInt32)((const Byte *)(p))[2] <<  8) | \\\r\n             ((const Byte *)(p))[3] )\r\n\r\n#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))\r\n\r\n#endif\r\n\r\n#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzFind.c",
    "content": "/* LzFind.c -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"LzFind.h\"\r\n#include \"LzHash.h\"\r\n\r\n#define kEmptyHashValue 0\r\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\r\n#define kMaxHistorySize ((UInt32)3 << 30)\r\n\r\n#define kStartMaxLen 3\r\n\r\nstatic void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  if (!p->directInput)\r\n  {\r\n    alloc->Free(alloc, p->bufferBase);\r\n    p->bufferBase = 0;\r\n  }\r\n}\r\n\r\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r\n\r\nstatic int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r\n{\r\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r\n  if (p->directInput)\r\n  {\r\n    p->blockSize = blockSize;\r\n    return 1;\r\n  }\r\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\r\n  {\r\n    LzInWindow_Free(p, alloc);\r\n    p->blockSize = blockSize;\r\n    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r\n  }\r\n  return (p->bufferBase != 0);\r\n}\r\n\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r\n\r\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r\n\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r\n{\r\n  p->posLimit -= subValue;\r\n  p->pos -= subValue;\r\n  p->streamPos -= subValue;\r\n}\r\n\r\nstatic void MatchFinder_ReadBlock(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached || p->result != SZ_OK)\r\n    return;\r\n  for (;;)\r\n  {\r\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\r\n    size_t size = (p->bufferBase + p->blockSize - dest);\r\n    if (size == 0)\r\n      return;\r\n    p->result = p->stream->Read(p->stream, dest, &size);\r\n    if (p->result != SZ_OK)\r\n      return;\r\n    if (size == 0)\r\n    {\r\n      p->streamEndWasReached = 1;\r\n      return;\r\n    }\r\n    p->streamPos += (UInt32)size;\r\n    if (p->streamPos - p->pos > p->keepSizeAfter)\r\n      return;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\r\n{\r\n  memmove(p->bufferBase,\r\n    p->buffer - p->keepSizeBefore,\r\n    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\r\n  p->buffer = p->bufferBase + p->keepSizeBefore;\r\n}\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p)\r\n{\r\n  /* if (p->streamEndWasReached) return 0; */\r\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r\n}\r\n\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached)\r\n    return;\r\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\r\n    MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r\n{\r\n  if (MatchFinder_NeedMove(p))\r\n    MatchFinder_MoveBlock(p);\r\n  MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_SetDefaultSettings(CMatchFinder *p)\r\n{\r\n  p->cutValue = 32;\r\n  p->btMode = 1;\r\n  p->numHashBytes = 4;\r\n  /* p->skipModeBits = 0; */\r\n  p->directInput = 0;\r\n  p->bigHash = 0;\r\n}\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  p->bufferBase = 0;\r\n  p->directInput = 0;\r\n  p->hash = 0;\r\n  MatchFinder_SetDefaultSettings(p);\r\n\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    p->crc[i] = r;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hash);\r\n  p->hash = 0;\r\n}\r\n\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  MatchFinder_FreeThisClassMemory(p, alloc);\r\n  LzInWindow_Free(p, alloc);\r\n}\r\n\r\nstatic CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r\n{\r\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r\n  if (sizeInBytes / sizeof(CLzRef) != num)\r\n    return 0;\r\n  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r\n}\r\n\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 sizeReserv;\r\n  if (historySize > kMaxHistorySize)\r\n  {\r\n    MatchFinder_Free(p, alloc);\r\n    return 0;\r\n  }\r\n  sizeReserv = historySize >> 1;\r\n  if (historySize > ((UInt32)2 << 30))\r\n    sizeReserv = historySize >> 2;\r\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r\n\r\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r\n  if (LzInWindow_Create(p, sizeReserv, alloc))\r\n  {\r\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r\n    UInt32 hs;\r\n    p->matchMaxLen = matchMaxLen;\r\n    {\r\n      p->fixedHashSize = 0;\r\n      if (p->numHashBytes == 2)\r\n        hs = (1 << 16) - 1;\r\n      else\r\n      {\r\n        hs = historySize - 1;\r\n        hs |= (hs >> 1);\r\n        hs |= (hs >> 2);\r\n        hs |= (hs >> 4);\r\n        hs |= (hs >> 8);\r\n        hs >>= 1;\r\n        /* hs >>= p->skipModeBits; */\r\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r\n        if (hs > (1 << 24))\r\n        {\r\n          if (p->numHashBytes == 3)\r\n            hs = (1 << 24) - 1;\r\n          else\r\n            hs >>= 1;\r\n        }\r\n      }\r\n      p->hashMask = hs;\r\n      hs++;\r\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r\n      hs += p->fixedHashSize;\r\n    }\r\n\r\n    {\r\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\r\n      UInt32 newSize;\r\n      p->historySize = historySize;\r\n      p->hashSizeSum = hs;\r\n      p->cyclicBufferSize = newCyclicBufferSize;\r\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r\n      newSize = p->hashSizeSum + p->numSons;\r\n      if (p->hash != 0 && prevSize == newSize)\r\n        return 1;\r\n      MatchFinder_FreeThisClassMemory(p, alloc);\r\n      p->hash = AllocRefs(newSize, alloc);\r\n      if (p->hash != 0)\r\n      {\r\n        p->son = p->hash + p->hashSizeSum;\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  MatchFinder_Free(p, alloc);\r\n  return 0;\r\n}\r\n\r\nstatic void MatchFinder_SetLimits(CMatchFinder *p)\r\n{\r\n  UInt32 limit = kMaxValForNormalize - p->pos;\r\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  limit2 = p->streamPos - p->pos;\r\n  if (limit2 <= p->keepSizeAfter)\r\n  {\r\n    if (limit2 > 0)\r\n      limit2 = 1;\r\n  }\r\n  else\r\n    limit2 -= p->keepSizeAfter;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  {\r\n    UInt32 lenLimit = p->streamPos - p->pos;\r\n    if (lenLimit > p->matchMaxLen)\r\n      lenLimit = p->matchMaxLen;\r\n    p->lenLimit = lenLimit;\r\n  }\r\n  p->posLimit = p->pos + limit;\r\n}\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->hashSizeSum; i++)\r\n    p->hash[i] = kEmptyHashValue;\r\n  p->cyclicBufferPos = 0;\r\n  p->buffer = p->bufferBase;\r\n  p->pos = p->streamPos = p->cyclicBufferSize;\r\n  p->result = SZ_OK;\r\n  p->streamEndWasReached = 0;\r\n  MatchFinder_ReadBlock(p);\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r\n{\r\n  return (p->pos - p->historySize - 1) & kNormalizeMask;\r\n}\r\n\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_Normalize(CMatchFinder *p)\r\n{\r\n  UInt32 subValue = MatchFinder_GetSubValue(p);\r\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r\n  MatchFinder_ReduceOffsets(p, subValue);\r\n}\r\n\r\nstatic void MatchFinder_CheckLimits(CMatchFinder *p)\r\n{\r\n  if (p->pos == kMaxValForNormalize)\r\n    MatchFinder_Normalize(p);\r\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r\n    MatchFinder_CheckAndMoveAndRead(p);\r\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\r\n    p->cyclicBufferPos = 0;\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  son[_cyclicBufferPos] = curMatch;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n      return distances;\r\n    {\r\n      const Byte *pb = cur - delta;\r\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r\n      {\r\n        UInt32 len = 0;\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n            return distances;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return distances;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return distances;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        {\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define MOVE_POS \\\r\n  ++p->cyclicBufferPos; \\\r\n  p->buffer++; \\\r\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r\n\r\n#define MOVE_POS_RET MOVE_POS return offset;\r\n\r\nstatic void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r\n\r\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\r\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\r\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\r\n  cur = p->buffer;\r\n\r\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r\n\r\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r\n\r\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\r\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\r\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\r\n\r\n#define SKIP_FOOTER \\\r\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r\n\r\nstatic UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(2)\r\n  HASH2_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 1)\r\n}\r\n\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 2)\r\n}\r\n\r\nstatic UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, delta2, maxLen, offset;\r\n  GET_MATCHES_HEADER(3)\r\n\r\n  HASH3_CALC;\r\n\r\n  delta2 = p->pos - p->hash[hash2Value];\r\n  curMatch = p->hash[kFix3HashSize + hashValue];\r\n  \r\n  p->hash[hash2Value] =\r\n  p->hash[kFix3HashSize + hashValue] = p->pos;\r\n\r\n\r\n  maxLen = 2;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[0] = maxLen;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n  \r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n\r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      p->son[p->cyclicBufferPos] = curMatch;\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances + offset, maxLen) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances, 2) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nstatic void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(2)\r\n    HASH2_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value;\r\n    SKIP_HEADER(3)\r\n    HASH3_CALC;\r\n    curMatch = p->hash[kFix3HashSize + hashValue];\r\n    p->hash[hash2Value] =\r\n    p->hash[kFix3HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] =\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r\n  if (!p->btMode)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 2)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 3)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r\n  }\r\n  else\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzFind.h",
    "content": "/* LzFind.h -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFIND_H\r\n#define __LZFIND_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef UInt32 CLzRef;\r\n\r\ntypedef struct _CMatchFinder\r\n{\r\n  Byte *buffer;\r\n  UInt32 pos;\r\n  UInt32 posLimit;\r\n  UInt32 streamPos;\r\n  UInt32 lenLimit;\r\n\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r\n\r\n  UInt32 matchMaxLen;\r\n  CLzRef *hash;\r\n  CLzRef *son;\r\n  UInt32 hashMask;\r\n  UInt32 cutValue;\r\n\r\n  Byte *bufferBase;\r\n  ISeqInStream *stream;\r\n  int streamEndWasReached;\r\n\r\n  UInt32 blockSize;\r\n  UInt32 keepSizeBefore;\r\n  UInt32 keepSizeAfter;\r\n\r\n  UInt32 numHashBytes;\r\n  int directInput;\r\n  int btMode;\r\n  /* int skipModeBits; */\r\n  int bigHash;\r\n  UInt32 historySize;\r\n  UInt32 fixedHashSize;\r\n  UInt32 hashSizeSum;\r\n  UInt32 numSons;\r\n  SRes result;\r\n  UInt32 crc[256];\r\n} CMatchFinder;\r\n\r\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r\n\r\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p);\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p);\r\n\r\n/* Conditions:\r\n     historySize <= 3 GB\r\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r\n*/\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc);\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *distances, UInt32 maxLen);\r\n\r\n/*\r\nConditions:\r\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r\n*/\r\n\r\ntypedef void (*Mf_Init_Func)(void *object);\r\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\r\n\r\ntypedef struct _IMatchFinder\r\n{\r\n  Mf_Init_Func Init;\r\n  Mf_GetIndexByte_Func GetIndexByte;\r\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r\n  Mf_GetMatches_Func GetMatches;\r\n  Mf_Skip_Func Skip;\r\n} IMatchFinder;\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p);\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzFindMt.c",
    "content": "/* LzFindMt.c -- multithreaded Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzHash.h\"\r\n\r\n#include \"LzFindMt.h\"\r\n\r\nvoid MtSync_Construct(CMtSync *p)\r\n{\r\n  p->wasCreated = False;\r\n  p->csWasInitialized = False;\r\n  p->csWasEntered = False;\r\n  Thread_Construct(&p->thread);\r\n  Event_Construct(&p->canStart);\r\n  Event_Construct(&p->wasStarted);\r\n  Event_Construct(&p->wasStopped);\r\n  Semaphore_Construct(&p->freeSemaphore);\r\n  Semaphore_Construct(&p->filledSemaphore);\r\n}\r\n\r\nvoid MtSync_GetNextBlock(CMtSync *p)\r\n{\r\n  if (p->needStart)\r\n  {\r\n    p->numProcessedBlocks = 1;\r\n    p->needStart = False;\r\n    p->stopWriting = False;\r\n    p->exit = False;\r\n    Event_Reset(&p->wasStarted);\r\n    Event_Reset(&p->wasStopped);\r\n\r\n    Event_Set(&p->canStart);\r\n    Event_Wait(&p->wasStarted);\r\n  }\r\n  else\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n    p->numProcessedBlocks++;\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  Semaphore_Wait(&p->filledSemaphore);\r\n  CriticalSection_Enter(&p->cs);\r\n  p->csWasEntered = True;\r\n}\r\n\r\n/* MtSync_StopWriting must be called if Writing was started */\r\n\r\nvoid MtSync_StopWriting(CMtSync *p)\r\n{\r\n  UInt32 myNumBlocks = p->numProcessedBlocks;\r\n  if (!Thread_WasCreated(&p->thread) || p->needStart)\r\n    return;\r\n  p->stopWriting = True;\r\n  if (p->csWasEntered)\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n  }\r\n  Semaphore_Release1(&p->freeSemaphore);\r\n \r\n  Event_Wait(&p->wasStopped);\r\n\r\n  while (myNumBlocks++ != p->numProcessedBlocks)\r\n  {\r\n    Semaphore_Wait(&p->filledSemaphore);\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  p->needStart = True;\r\n}\r\n\r\nvoid MtSync_Destruct(CMtSync *p)\r\n{\r\n  if (Thread_WasCreated(&p->thread))\r\n  {\r\n    MtSync_StopWriting(p);\r\n    p->exit = True;\r\n    if (p->needStart)\r\n      Event_Set(&p->canStart);\r\n    Thread_Wait(&p->thread);\r\n    Thread_Close(&p->thread);\r\n  }\r\n  if (p->csWasInitialized)\r\n  {\r\n    CriticalSection_Delete(&p->cs);\r\n    p->csWasInitialized = False;\r\n  }\r\n\r\n  Event_Close(&p->canStart);\r\n  Event_Close(&p->wasStarted);\r\n  Event_Close(&p->wasStopped);\r\n  Semaphore_Close(&p->freeSemaphore);\r\n  Semaphore_Close(&p->filledSemaphore);\r\n\r\n  p->wasCreated = False;\r\n}\r\n\r\n#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }\r\n\r\nstatic SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  if (p->wasCreated)\r\n    return SZ_OK;\r\n\r\n  RINOK_THREAD(CriticalSection_Init(&p->cs));\r\n  p->csWasInitialized = True;\r\n\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));\r\n  \r\n  RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));\r\n  RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));\r\n\r\n  p->needStart = True;\r\n  \r\n  RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));\r\n  p->wasCreated = True;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\r\n  if (res != SZ_OK)\r\n    MtSync_Destruct(p);\r\n  return res;\r\n}\r\n\r\nvoid MtSync_Init(CMtSync *p) { p->needStart = True; }\r\n\r\n#define kMtMaxValForNormalize 0xFFFFFFFF\r\n\r\n#define DEF_GetHeads2(name, v, action) \\\r\nstatic void GetHeads ## name(const Byte *p, UInt32 pos, \\\r\nUInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \\\r\n{ action; for (; numHeads != 0; numHeads--) { \\\r\nconst UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r\n\r\n#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)\r\n\r\nDEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )\r\nDEF_GetHeads(3,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\r\nDEF_GetHeads(4,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)\r\nDEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\r\nDEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)\r\n\r\nvoid HashThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->hashSync;\r\n  for (;;)\r\n  {\r\n    UInt32 numProcessedBlocks = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = numProcessedBlocks;\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n\r\n      {\r\n        CMatchFinder *mf = mt->MatchFinder;\r\n        if (MatchFinder_NeedMove(mf))\r\n        {\r\n          CriticalSection_Enter(&mt->btSync.cs);\r\n          CriticalSection_Enter(&mt->hashSync.cs);\r\n          {\r\n            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            const Byte *afterPtr;\r\n            MatchFinder_MoveBlock(mf);\r\n            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            mt->pointerToCurPos -= beforePtr - afterPtr;\r\n            mt->buffer -= beforePtr - afterPtr;\r\n          }\r\n          CriticalSection_Leave(&mt->btSync.cs);\r\n          CriticalSection_Leave(&mt->hashSync.cs);\r\n          continue;\r\n        }\r\n\r\n        Semaphore_Wait(&p->freeSemaphore);\r\n\r\n        MatchFinder_ReadIfRequired(mf);\r\n        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))\r\n        {\r\n          UInt32 subValue = (mf->pos - mf->historySize - 1);\r\n          MatchFinder_ReduceOffsets(mf, subValue);\r\n          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);\r\n        }\r\n        {\r\n          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n          UInt32 num = mf->streamPos - mf->pos;\r\n          heads[0] = 2;\r\n          heads[1] = num;\r\n          if (num >= mf->numHashBytes)\r\n          {\r\n            num = num - mf->numHashBytes + 1;\r\n            if (num > kMtHashBlockSize - 2)\r\n              num = kMtHashBlockSize - 2;\r\n            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);\r\n            heads[0] += num;\r\n          }\r\n          mf->pos += num;\r\n          mf->buffer += num;\r\n        }\r\n      }\r\n\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r\n{\r\n  MtSync_GetNextBlock(&p->hashSync);\r\n  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];\r\n  p->hashNumAvail = p->hashBuf[p->hashBufPos++];\r\n}\r\n\r\n#define kEmptyHashValue 0\r\n\r\n/* #define MFMT_GM_INLINE */\r\n\r\n#ifdef MFMT_GM_INLINE\r\n\r\n#define NO_INLINE MY_FAST_CALL\r\n\r\nInt32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\r\n{\r\n  do\r\n  {\r\n  UInt32 *distances = _distances + 1;\r\n  UInt32 curMatch = pos - *hash++;\r\n\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  UInt32 cutValue = _cutValue;\r\n  UInt32 maxLen = _maxLen;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      break;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            break;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n  pos++;\r\n  _cyclicBufferPos++;\r\n  cur++;\r\n  {\r\n    UInt32 num = (UInt32)(distances - _distances);\r\n    *_distances = num - 1;\r\n    _distances += num;\r\n    limit -= num;\r\n  }\r\n  }\r\n  while (limit > 0 && --size != 0);\r\n  *posRes = pos;\r\n  return limit;\r\n}\r\n\r\n#endif\r\n\r\nvoid BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  UInt32 numProcessed = 0;\r\n  UInt32 curPos = 2;\r\n  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\r\n  distances[1] = p->hashNumAvail;\r\n  while (curPos < limit)\r\n  {\r\n    if (p->hashBufPos == p->hashBufPosLimit)\r\n    {\r\n      MatchFinderMt_GetNextBlock_Hash(p);\r\n      distances[1] = numProcessed + p->hashNumAvail;\r\n      if (p->hashNumAvail >= p->numHashBytes)\r\n        continue;\r\n      for (; p->hashNumAvail != 0; p->hashNumAvail--)\r\n        distances[curPos++] = 0;\r\n      break;\r\n    }\r\n    {\r\n      UInt32 size = p->hashBufPosLimit - p->hashBufPos;\r\n      UInt32 lenLimit = p->matchMaxLen;\r\n      UInt32 pos = p->pos;\r\n      UInt32 cyclicBufferPos = p->cyclicBufferPos;\r\n      if (lenLimit >= p->hashNumAvail)\r\n        lenLimit = p->hashNumAvail;\r\n      {\r\n        UInt32 size2 = p->hashNumAvail - lenLimit + 1;\r\n        if (size2 < size)\r\n          size = size2;\r\n        size2 = p->cyclicBufferSize - cyclicBufferPos;\r\n        if (size2 < size)\r\n          size = size2;\r\n      }\r\n      #ifndef MFMT_GM_INLINE\r\n      while (curPos < limit && size-- != 0)\r\n      {\r\n        UInt32 *startDistances = distances + curPos;\r\n        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],\r\n          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r\n          startDistances + 1, p->numHashBytes - 1) - startDistances);\r\n        *startDistances = num - 1;\r\n        curPos += num;\r\n        cyclicBufferPos++;\r\n        pos++;\r\n        p->buffer++;\r\n      }\r\n      #else\r\n      {\r\n        UInt32 posRes;\r\n        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r\n          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);\r\n        p->hashBufPos += posRes - pos;\r\n        cyclicBufferPos += posRes - pos;\r\n        p->buffer += posRes - pos;\r\n        pos = posRes;\r\n      }\r\n      #endif\r\n\r\n      numProcessed += pos - p->pos;\r\n      p->hashNumAvail -= pos - p->pos;\r\n      p->pos = pos;\r\n      if (cyclicBufferPos == p->cyclicBufferSize)\r\n        cyclicBufferPos = 0;\r\n      p->cyclicBufferPos = cyclicBufferPos;\r\n    }\r\n  }\r\n  distances[0] = curPos;\r\n}\r\n\r\nvoid BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r\n{\r\n  CMtSync *sync = &p->hashSync;\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Enter(&sync->cs);\r\n    sync->csWasEntered = True;\r\n  }\r\n  \r\n  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);\r\n\r\n  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\r\n  {\r\n    UInt32 subValue = p->pos - p->cyclicBufferSize;\r\n    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);\r\n    p->pos -= subValue;\r\n  }\r\n\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Leave(&sync->cs);\r\n    sync->csWasEntered = False;\r\n  }\r\n}\r\n\r\nvoid BtThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->btSync;\r\n  for (;;)\r\n  {\r\n    UInt32 blockIndex = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = blockIndex;\r\n        MtSync_StopWriting(&mt->hashSync);\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n      Semaphore_Wait(&p->freeSemaphore);\r\n      BtFillBlock(mt, blockIndex++);\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p)\r\n{\r\n  p->hashBuf = 0;\r\n  MtSync_Construct(&p->hashSync);\r\n  MtSync_Construct(&p->btSync);\r\n}\r\n\r\nvoid MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hashBuf);\r\n  p->hashBuf = 0;\r\n}\r\n\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  MtSync_Destruct(&p->hashSync);\r\n  MtSync_Destruct(&p->btSync);\r\n  MatchFinderMt_FreeMem(p, alloc);\r\n}\r\n\r\n#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\r\n#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\r\n\r\nstatic unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r\nstatic unsigned MY_STD_CALL BtThreadFunc2(void *p)\r\n{\r\n  Byte allocaDummy[0x180];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  BtThreadFunc((CMatchFinderMt *)p);\r\n  return 0;\r\n}\r\n\r\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\r\n{\r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->historySize = historySize;\r\n  if (kMtBtBlockSize <= matchMaxLen * 4)\r\n    return SZ_ERROR_PARAM;\r\n  if (p->hashBuf == 0)\r\n  {\r\n    p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r\n    if (p->hashBuf == 0)\r\n      return SZ_ERROR_MEM;\r\n    p->btBuf = p->hashBuf + kHashBufferSize;\r\n  }\r\n  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);\r\n  keepAddBufferAfter += kMtHashBlockSize;\r\n  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))\r\n    return SZ_ERROR_MEM;\r\n\r\n  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));\r\n  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));\r\n  return SZ_OK;\r\n}\r\n\r\n/* Call it after ReleaseStream / SetStream */\r\nvoid MatchFinderMt_Init(CMatchFinderMt *p)\r\n{\r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->btBufPos = p->btBufPosLimit = 0;\r\n  p->hashBufPos = p->hashBufPosLimit = 0;\r\n  MatchFinder_Init(mf);\r\n  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);\r\n  p->btNumAvailBytes = 0;\r\n  p->lzPos = p->historySize + 1;\r\n\r\n  p->hash = mf->hash;\r\n  p->fixedHashSize = mf->fixedHashSize;\r\n  p->crc = mf->crc;\r\n\r\n  p->son = mf->son;\r\n  p->matchMaxLen = mf->matchMaxLen;\r\n  p->numHashBytes = mf->numHashBytes;\r\n  p->pos = mf->pos;\r\n  p->buffer = mf->buffer;\r\n  p->cyclicBufferPos = mf->cyclicBufferPos;\r\n  p->cyclicBufferSize = mf->cyclicBufferSize;\r\n  p->cutValue = mf->cutValue;\r\n}\r\n\r\n/* ReleaseStream is required to finish multithreading */\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p)\r\n{\r\n  MtSync_StopWriting(&p->btSync);\r\n  /* p->MatchFinder->ReleaseStream(); */\r\n}\r\n\r\nvoid MatchFinderMt_Normalize(CMatchFinderMt *p)\r\n{\r\n  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\r\n  p->lzPos = p->historySize + 1;\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r\n{\r\n  UInt32 blockIndex;\r\n  MtSync_GetNextBlock(&p->btSync);\r\n  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);\r\n  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;\r\n  p->btBufPosLimit += p->btBuf[p->btBufPos++];\r\n  p->btNumAvailBytes = p->btBuf[p->btBufPos++];\r\n  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)\r\n    MatchFinderMt_Normalize(p);\r\n}\r\n\r\nconst Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r\n{\r\n  return p->pointerToCurPos;\r\n}\r\n\r\n#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\r\n\r\nUInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r\n{\r\n  GET_NEXT_BLOCK_IF_REQUIRED;\r\n  return p->btNumAvailBytes;\r\n}\r\n\r\nByte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)\r\n{\r\n  return p->pointerToCurPos[index];\r\n}\r\n\r\nUInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, curMatch2;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH2_CALC\r\n      \r\n  curMatch2 = hash[hash2Value];\r\n  hash[hash2Value] = lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos)\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n    {\r\n      *distances++ = 2;\r\n      *distances++ = lzPos - curMatch2 - 1;\r\n    }\r\n  return distances;\r\n}\r\n\r\nUInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH3_CALC\r\n\r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  \r\n  hash[                hash2Value] =\r\n  hash[kFix3HashSize + hash3Value] =\r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] = 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    *distances++ = 3;\r\n    *distances++ = lzPos - curMatch3 - 1;\r\n  }\r\n  return distances;\r\n}\r\n\r\n/*\r\nUInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH4_CALC\r\n      \r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  curMatch4 = hash[kFix4HashSize + hash4Value];\r\n  \r\n  hash[                hash2Value] =\r\n  hash[kFix3HashSize + hash3Value] =\r\n  hash[kFix4HashSize + hash4Value] =\r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch3 - 1;\r\n    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])\r\n    {\r\n      distances[0] = 4;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 3;\r\n    distances += 2;\r\n  }\r\n\r\n  if (curMatch4 >= matchMinPos)\r\n    if (\r\n      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&\r\n      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]\r\n      )\r\n    {\r\n      *distances++ = 4;\r\n      *distances++ = lzPos - curMatch4 - 1;\r\n    }\r\n  return distances;\r\n}\r\n*/\r\n\r\n#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\r\n\r\nUInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n  p->btNumAvailBytes--;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < len; i += 2)\r\n    {\r\n      *distances++ = *btBuf++;\r\n      *distances++ = *btBuf++;\r\n    }\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\nUInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n\r\n  if (len == 0)\r\n  {\r\n    if (p->btNumAvailBytes-- >= 4)\r\n      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\r\n  }\r\n  else\r\n  {\r\n    /* Condition: there are matches in btBuf with length < p->numHashBytes */\r\n    UInt32 *distances2;\r\n    p->btNumAvailBytes--;\r\n    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\r\n    do\r\n    {\r\n      *distances2++ = *btBuf++;\r\n      *distances2++ = *btBuf++;\r\n    }\r\n    while ((len -= 2) != 0);\r\n    len  = (UInt32)(distances2 - (distances));\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\n#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED\r\n#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r\n#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);\r\n\r\nvoid MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER2 { p->btNumAvailBytes--;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(2)\r\n      UInt32 hash2Value;\r\n      MT_HASH2_CALC\r\n      hash[hash2Value] = p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(3)\r\n      UInt32 hash2Value, hash3Value;\r\n      MT_HASH3_CALC\r\n      hash[kFix3HashSize + hash3Value] =\r\n      hash[                hash2Value] =\r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\n/*\r\nvoid MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(4)\r\n      UInt32 hash2Value, hash3Value, hash4Value;\r\n      MT_HASH4_CALC\r\n      hash[kFix4HashSize + hash4Value] =\r\n      hash[kFix3HashSize + hash3Value] =\r\n      hash[                hash2Value] =\r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n*/\r\n\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\r\n  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\r\n  switch(p->MatchFinder->numHashBytes)\r\n  {\r\n    case 2:\r\n      p->GetHeadsFunc = GetHeads2;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)0;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\r\n      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\r\n      break;\r\n    case 3:\r\n      p->GetHeadsFunc = GetHeads3;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;\r\n      break;\r\n    default:\r\n    /* case 4: */\r\n      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\r\n      /* p->GetHeadsFunc = GetHeads4; */\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\r\n      break;\r\n    /*\r\n    default:\r\n      p->GetHeadsFunc = GetHeads5;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;\r\n      break;\r\n    */\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzFindMt.h",
    "content": "/* LzFindMt.h -- multithreaded Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFINDMT_H\r\n#define __LZFINDMT_H\r\n\r\n#include \"Threads.h\"\r\n#include \"LzFind.h\"\r\n\r\n#define kMtHashBlockSize (1 << 13)\r\n#define kMtHashNumBlocks (1 << 3)\r\n#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)\r\n\r\n#define kMtBtBlockSize (1 << 14)\r\n#define kMtBtNumBlocks (1 << 6)\r\n#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)\r\n\r\ntypedef struct _CMtSync\r\n{\r\n  Bool wasCreated;\r\n  Bool needStart;\r\n  Bool exit;\r\n  Bool stopWriting;\r\n\r\n  CThread thread;\r\n  CAutoResetEvent canStart;\r\n  CAutoResetEvent wasStarted;\r\n  CAutoResetEvent wasStopped;\r\n  CSemaphore freeSemaphore;\r\n  CSemaphore filledSemaphore;\r\n  Bool csWasInitialized;\r\n  Bool csWasEntered;\r\n  CCriticalSection cs;\r\n  UInt32 numProcessedBlocks;\r\n} CMtSync;\r\n\r\ntypedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);\r\n\r\n/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */\r\n#define kMtCacheLineDummy 128\r\n\r\ntypedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,\r\n  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);\r\n\r\ntypedef struct _CMatchFinderMt\r\n{\r\n  /* LZ */\r\n  const Byte *pointerToCurPos;\r\n  UInt32 *btBuf;\r\n  UInt32 btBufPos;\r\n  UInt32 btBufPosLimit;\r\n  UInt32 lzPos;\r\n  UInt32 btNumAvailBytes;\r\n\r\n  UInt32 *hash;\r\n  UInt32 fixedHashSize;\r\n  UInt32 historySize;\r\n  const UInt32 *crc;\r\n\r\n  Mf_Mix_Matches MixMatchesFunc;\r\n  \r\n  /* LZ + BT */\r\n  CMtSync btSync;\r\n  Byte btDummy[kMtCacheLineDummy];\r\n\r\n  /* BT */\r\n  UInt32 *hashBuf;\r\n  UInt32 hashBufPos;\r\n  UInt32 hashBufPosLimit;\r\n  UInt32 hashNumAvail;\r\n\r\n  CLzRef *son;\r\n  UInt32 matchMaxLen;\r\n  UInt32 numHashBytes;\r\n  UInt32 pos;\r\n  Byte *buffer;\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be historySize + 1 */\r\n  UInt32 cutValue;\r\n\r\n  /* BT + Hash */\r\n  CMtSync hashSync;\r\n  /* Byte hashDummy[kMtCacheLineDummy]; */\r\n  \r\n  /* Hash */\r\n  Mf_GetHeads GetHeadsFunc;\r\n  CMatchFinder *MatchFinder;\r\n} CMatchFinderMt;\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p);\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);\r\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzHash.h",
    "content": "/* LzHash.h -- HASH functions for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZHASH_H\r\n#define __LZHASH_H\r\n\r\n#define kHash2Size (1 << 10)\r\n#define kHash3Size (1 << 16)\r\n#define kHash4Size (1 << 20)\r\n\r\n#define kFix3HashSize (kHash2Size)\r\n#define kFix4HashSize (kHash2Size + kHash3Size)\r\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r\n\r\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r\n\r\n#define HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r\n\r\n#define HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r\n\r\n#define HASH5_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\\r\n  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\\r\n  hash4Value &= (kHash4Size - 1); }\r\n\r\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r\n\r\n\r\n#define MT_HASH2_CALC \\\r\n  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r\n\r\n#define MT_HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r\n\r\n#define MT_HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaDec.c",
    "content": "/* LzmaDec.c -- LZMA Decoder\r\n2008-11-06 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzmaDec.h\"\r\n\r\n#include <string.h>\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_INIT_SIZE 5\r\n\r\n#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));\r\n#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \\\r\n  { UPDATE_0(p); i = (i + i); A0; } else \\\r\n  { UPDATE_1(p); i = (i + i) + 1; A1; }\r\n#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)\r\n\r\n#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }\r\n#define TREE_DECODE(probs, limit, i) \\\r\n  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }\r\n\r\n/* #define _LZMA_SIZE_OPT */\r\n\r\n#ifdef _LZMA_SIZE_OPT\r\n#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)\r\n#else\r\n#define TREE_6_DECODE(probs, i) \\\r\n  { i = 1; \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  i -= 0x40; }\r\n#endif\r\n\r\n#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0_CHECK range = bound;\r\n#define UPDATE_1_CHECK range -= bound; code -= bound;\r\n#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \\\r\n  { UPDATE_0_CHECK; i = (i + i); A0; } else \\\r\n  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }\r\n#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)\r\n#define TREE_DECODE_CHECK(probs, limit, i) \\\r\n  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols)\r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nstatic const Byte kLiteralNextStates[kNumStates * 2] =\r\n{\r\n  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\r\n  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\r\n};\r\n\r\n#define LZMA_DIC_MIN (1 << 12)\r\n\r\n/* First LZMA-symbol is always decoded.\r\nAnd it decodes new LZMA-symbols while (buf < bufLimit), but \"buf\" is without last normalization\r\nOut:\r\n  Result:\r\n    SZ_OK - OK\r\n    SZ_ERROR_DATA - Error\r\n  p->remainLen:\r\n    < kMatchSpecLenStart : normal remain\r\n    = kMatchSpecLenStart : finished\r\n    = kMatchSpecLenStart + 1 : Flush marker\r\n    = kMatchSpecLenStart + 2 : State Init Marker\r\n*/\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  CLzmaProb *probs = p->probs;\r\n\r\n  unsigned state = p->state;\r\n  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];\r\n  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;\r\n  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;\r\n  unsigned lc = p->prop.lc;\r\n\r\n  Byte *dic = p->dic;\r\n  SizeT dicBufSize = p->dicBufSize;\r\n  SizeT dicPos = p->dicPos;\r\n  \r\n  UInt32 processedPos = p->processedPos;\r\n  UInt32 checkDicSize = p->checkDicSize;\r\n  unsigned len = 0;\r\n\r\n  const Byte *buf = p->buf;\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n\r\n  do\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = processedPos & pbMask;\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0(prob)\r\n    {\r\n      unsigned symbol;\r\n      UPDATE_0(prob);\r\n      prob = probs + Literal;\r\n      if (checkDicSize != 0 || processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r\n        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        symbol = 1;\r\n        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      dic[dicPos++] = (Byte)symbol;\r\n      processedPos++;\r\n\r\n      state = kLiteralNextStates[state];\r\n      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\r\n      continue;\r\n    }\r\n    else\r\n    {\r\n      UPDATE_1(prob);\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0(prob)\r\n      {\r\n        UPDATE_0(prob);\r\n        state += kNumStates;\r\n        prob = probs + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1(prob);\r\n        if (checkDicSize == 0 && processedPos == 0)\r\n          return SZ_ERROR_DATA;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0(prob)\r\n        {\r\n          UPDATE_0(prob);\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n            dicPos++;\r\n            processedPos++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            continue;\r\n          }\r\n          UPDATE_1(prob);\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UPDATE_1(prob);\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            distance = rep1;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(prob);\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0(prob)\r\n            {\r\n              UPDATE_0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0(probLen)\r\n        {\r\n          UPDATE_0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = (1 << kLenNumLowBits);\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0(probLen)\r\n          {\r\n            UPDATE_0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = (1 << kLenNumMidBits);\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = (1 << kLenNumHighBits);\r\n          }\r\n        }\r\n        TREE_DECODE(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state >= kNumStates)\r\n      {\r\n        UInt32 distance;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);\r\n        TREE_6_DECODE(prob, distance);\r\n        if (distance >= kStartPosModelIndex)\r\n        {\r\n          unsigned posSlot = (unsigned)distance;\r\n          int numDirectBits = (int)(((distance >> 1) - 1));\r\n          distance = (2 | (distance & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            distance <<= numDirectBits;\r\n            prob = probs + SpecPos + distance - posSlot - 1;\r\n            {\r\n              UInt32 mask = 1;\r\n              unsigned i = 1;\r\n              do\r\n              {\r\n                GET_BIT2(prob + i, i, ; , distance |= mask);\r\n                mask <<= 1;\r\n              }\r\n              while (--numDirectBits != 0);\r\n            }\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE\r\n              range >>= 1;\r\n              \r\n              {\r\n                UInt32 t;\r\n                code -= range;\r\n                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */\r\n                distance = (distance << 1) + (t + 1);\r\n                code += range & t;\r\n              }\r\n              /*\r\n              distance <<= 1;\r\n              if (code >= range)\r\n              {\r\n                code -= range;\r\n                distance |= 1;\r\n              }\r\n              */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            distance <<= kNumAlignBits;\r\n            {\r\n              unsigned i = 1;\r\n              GET_BIT2(prob + i, i, ; , distance |= 1);\r\n              GET_BIT2(prob + i, i, ; , distance |= 2);\r\n              GET_BIT2(prob + i, i, ; , distance |= 4);\r\n              GET_BIT2(prob + i, i, ; , distance |= 8);\r\n            }\r\n            if (distance == (UInt32)0xFFFFFFFF)\r\n            {\r\n              len += kMatchSpecLenStart;\r\n              state -= kNumStates;\r\n              break;\r\n            }\r\n          }\r\n        }\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        rep0 = distance + 1;\r\n        if (checkDicSize == 0)\r\n        {\r\n          if (distance >= processedPos)\r\n            return SZ_ERROR_DATA;\r\n        }\r\n        else if (distance >= checkDicSize)\r\n          return SZ_ERROR_DATA;\r\n        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r\n        /* state = kLiteralNextStates[state]; */\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n\r\n      if (limit == dicPos)\r\n        return SZ_ERROR_DATA;\r\n      {\r\n        SizeT rem = limit - dicPos;\r\n        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\r\n        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\r\n\r\n        processedPos += curLen;\r\n\r\n        len -= curLen;\r\n        if (pos + curLen <= dicBufSize)\r\n        {\r\n          Byte *dest = dic + dicPos;\r\n          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;\r\n          const Byte *lim = dest + curLen;\r\n          dicPos += curLen;\r\n          do\r\n            *(dest) = (Byte)*(dest + src);\r\n          while (++dest != lim);\r\n        }\r\n        else\r\n        {\r\n          do\r\n          {\r\n            dic[dicPos++] = dic[pos];\r\n            if (++pos == dicBufSize)\r\n              pos = 0;\r\n          }\r\n          while (--curLen != 0);\r\n        }\r\n      }\r\n    }\r\n  }\r\n  while (dicPos < limit && buf < bufLimit);\r\n  NORMALIZE;\r\n  p->buf = buf;\r\n  p->range = range;\r\n  p->code = code;\r\n  p->remainLen = len;\r\n  p->dicPos = dicPos;\r\n  p->processedPos = processedPos;\r\n  p->reps[0] = rep0;\r\n  p->reps[1] = rep1;\r\n  p->reps[2] = rep2;\r\n  p->reps[3] = rep3;\r\n  p->state = state;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\r\n{\r\n  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\r\n  {\r\n    Byte *dic = p->dic;\r\n    SizeT dicPos = p->dicPos;\r\n    SizeT dicBufSize = p->dicBufSize;\r\n    unsigned len = p->remainLen;\r\n    UInt32 rep0 = p->reps[0];\r\n    if (limit - dicPos < len)\r\n      len = (unsigned)(limit - dicPos);\r\n\r\n    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r\n      p->checkDicSize = p->prop.dicSize;\r\n\r\n    p->processedPos += len;\r\n    p->remainLen -= len;\r\n    while (len-- != 0)\r\n    {\r\n      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n      dicPos++;\r\n    }\r\n    p->dicPos = dicPos;\r\n  }\r\n}\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  do\r\n  {\r\n    SizeT limit2 = limit;\r\n    if (p->checkDicSize == 0)\r\n    {\r\n      UInt32 rem = p->prop.dicSize - p->processedPos;\r\n      if (limit - p->dicPos > rem)\r\n        limit2 = p->dicPos + rem;\r\n    }\r\n    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r\n    if (p->processedPos >= p->prop.dicSize)\r\n      p->checkDicSize = p->prop.dicSize;\r\n    LzmaDec_WriteRem(p, limit);\r\n  }\r\n  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r\n\r\n  if (p->remainLen > kMatchSpecLenStart)\r\n  {\r\n    p->remainLen = kMatchSpecLenStart;\r\n  }\r\n  return 0;\r\n}\r\n\r\ntypedef enum\r\n{\r\n  DUMMY_ERROR, /* unexpected end of input stream */\r\n  DUMMY_LIT,\r\n  DUMMY_MATCH,\r\n  DUMMY_REP\r\n} ELzmaDummy;\r\n\r\nstatic ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\r\n{\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n  const Byte *bufLimit = buf + inSize;\r\n  CLzmaProb *probs = p->probs;\r\n  unsigned state = p->state;\r\n  ELzmaDummy res;\r\n\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0_CHECK(prob)\r\n    {\r\n      UPDATE_0_CHECK\r\n\r\n      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\r\n\r\n      prob = probs + Literal;\r\n      if (p->checkDicSize != 0 || p->processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE *\r\n          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r\n          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        unsigned symbol = 1;\r\n        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r\n            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        unsigned symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      res = DUMMY_LIT;\r\n    }\r\n    else\r\n    {\r\n      unsigned len;\r\n      UPDATE_1_CHECK;\r\n\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0_CHECK(prob)\r\n      {\r\n        UPDATE_0_CHECK;\r\n        state = 0;\r\n        prob = probs + LenCoder;\r\n        res = DUMMY_MATCH;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1_CHECK;\r\n        res = DUMMY_REP;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0_CHECK(prob)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            NORMALIZE_CHECK;\r\n            return DUMMY_REP;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0_CHECK(prob)\r\n            {\r\n              UPDATE_0_CHECK;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1_CHECK;\r\n            }\r\n          }\r\n        }\r\n        state = kNumStates;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0_CHECK(probLen)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = 1 << kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0_CHECK(probLen)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = 1 << kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = 1 << kLenNumHighBits;\r\n          }\r\n        }\r\n        TREE_DECODE_CHECK(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        unsigned posSlot;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<\r\n            kNumPosSlotBits);\r\n        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n\r\n          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE_CHECK\r\n              range >>= 1;\r\n              code -= range & (((code - range) >> 31) - 1);\r\n              /* if (code >= range) code -= range; */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            unsigned i = 1;\r\n            do\r\n            {\r\n              GET_BIT_CHECK(prob + i, i);\r\n            }\r\n            while (--numDirectBits != 0);\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  NORMALIZE_CHECK;\r\n  return res;\r\n}\r\n\r\n\r\nstatic void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\r\n{\r\n  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\r\n  p->range = 0xFFFFFFFF;\r\n  p->needFlush = 0;\r\n}\r\n\r\nvoid LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r\n{\r\n  p->needFlush = 1;\r\n  p->remainLen = 0;\r\n  p->tempBufSize = 0;\r\n\r\n  if (initDic)\r\n  {\r\n    p->processedPos = 0;\r\n    p->checkDicSize = 0;\r\n    p->needInitState = 1;\r\n  }\r\n  if (initState)\r\n    p->needInitState = 1;\r\n}\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p)\r\n{\r\n  p->dicPos = 0;\r\n  LzmaDec_InitDicAndState(p, True, True);\r\n}\r\n\r\nstatic void LzmaDec_InitStateReal(CLzmaDec *p)\r\n{\r\n  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\r\n  UInt32 i;\r\n  CLzmaProb *probs = p->probs;\r\n  for (i = 0; i < numProbs; i++)\r\n    probs[i] = kBitModelTotal >> 1;\r\n  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;\r\n  p->state = 0;\r\n  p->needInitState = 0;\r\n}\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\r\n    ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT inSize = *srcLen;\r\n  (*srcLen) = 0;\r\n  LzmaDec_WriteRem(p, dicLimit);\r\n  \r\n  *status = LZMA_STATUS_NOT_SPECIFIED;\r\n\r\n  while (p->remainLen != kMatchSpecLenStart)\r\n  {\r\n      int checkEndMarkNow;\r\n\r\n      if (p->needFlush != 0)\r\n      {\r\n        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r\n          p->tempBuf[p->tempBufSize++] = *src++;\r\n        if (p->tempBufSize < RC_INIT_SIZE)\r\n        {\r\n          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n          return SZ_OK;\r\n        }\r\n        if (p->tempBuf[0] != 0)\r\n          return SZ_ERROR_DATA;\r\n\r\n        LzmaDec_InitRc(p, p->tempBuf);\r\n        p->tempBufSize = 0;\r\n      }\r\n\r\n      checkEndMarkNow = 0;\r\n      if (p->dicPos >= dicLimit)\r\n      {\r\n        if (p->remainLen == 0 && p->code == 0)\r\n        {\r\n          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;\r\n          return SZ_OK;\r\n        }\r\n        if (finishMode == LZMA_FINISH_ANY)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_OK;\r\n        }\r\n        if (p->remainLen != 0)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_ERROR_DATA;\r\n        }\r\n        checkEndMarkNow = 1;\r\n      }\r\n\r\n      if (p->needInitState)\r\n        LzmaDec_InitStateReal(p);\r\n  \r\n      if (p->tempBufSize == 0)\r\n      {\r\n        SizeT processed;\r\n        const Byte *bufLimit;\r\n        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            memcpy(p->tempBuf, src, inSize);\r\n            p->tempBufSize = (unsigned)inSize;\r\n            (*srcLen) += inSize;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n          bufLimit = src;\r\n        }\r\n        else\r\n          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\r\n        p->buf = src;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\r\n          return SZ_ERROR_DATA;\r\n        processed = (SizeT)(p->buf - src);\r\n        (*srcLen) += processed;\r\n        src += processed;\r\n        inSize -= processed;\r\n      }\r\n      else\r\n      {\r\n        unsigned rem = p->tempBufSize, lookAhead = 0;\r\n        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\r\n          p->tempBuf[rem++] = src[lookAhead++];\r\n        p->tempBufSize = rem;\r\n        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            (*srcLen) += lookAhead;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n        }\r\n        p->buf = p->tempBuf;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r\n          return SZ_ERROR_DATA;\r\n        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\r\n        (*srcLen) += lookAhead;\r\n        src += lookAhead;\r\n        inSize -= lookAhead;\r\n        p->tempBufSize = 0;\r\n      }\r\n  }\r\n  if (p->code == 0)\r\n    *status = LZMA_STATUS_FINISHED_WITH_MARK;\r\n  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT outSize = *destLen;\r\n  SizeT inSize = *srcLen;\r\n  *srcLen = *destLen = 0;\r\n  for (;;)\r\n  {\r\n    SizeT inSizeCur = inSize, outSizeCur, dicPos;\r\n    ELzmaFinishMode curFinishMode;\r\n    SRes res;\r\n    if (p->dicPos == p->dicBufSize)\r\n      p->dicPos = 0;\r\n    dicPos = p->dicPos;\r\n    if (outSize > p->dicBufSize - dicPos)\r\n    {\r\n      outSizeCur = p->dicBufSize;\r\n      curFinishMode = LZMA_FINISH_ANY;\r\n    }\r\n    else\r\n    {\r\n      outSizeCur = dicPos + outSize;\r\n      curFinishMode = finishMode;\r\n    }\r\n\r\n    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);\r\n    src += inSizeCur;\r\n    inSize -= inSizeCur;\r\n    *srcLen += inSizeCur;\r\n    outSizeCur = p->dicPos - dicPos;\r\n    memcpy(dest, p->dic + dicPos, outSizeCur);\r\n    dest += outSizeCur;\r\n    outSize -= outSizeCur;\r\n    *destLen += outSizeCur;\r\n    if (res != 0)\r\n      return res;\r\n    if (outSizeCur == 0 || outSize == 0)\r\n      return SZ_OK;\r\n  }\r\n}\r\n\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->probs);\r\n  p->probs = 0;\r\n}\r\n\r\nstatic void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->dic);\r\n  p->dic = 0;\r\n}\r\n\r\nvoid LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  LzmaDec_FreeProbs(p, alloc);\r\n  LzmaDec_FreeDict(p, alloc);\r\n}\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)\r\n{\r\n  UInt32 dicSize;\r\n  Byte d;\r\n  \r\n  if (size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  else\r\n    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);\r\n \r\n  if (dicSize < LZMA_DIC_MIN)\r\n    dicSize = LZMA_DIC_MIN;\r\n  p->dicSize = dicSize;\r\n\r\n  d = data[0];\r\n  if (d >= (9 * 5 * 5))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  p->lc = d % 9;\r\n  d /= 9;\r\n  p->pb = d / 5;\r\n  p->lp = d % 5;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r\n{\r\n  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r\n  if (p->probs == 0 || numProbs != p->numProbs)\r\n  {\r\n    LzmaDec_FreeProbs(p, alloc);\r\n    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r\n    p->numProbs = numProbs;\r\n    if (p->probs == 0)\r\n      return SZ_ERROR_MEM;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  SizeT dicBufSize;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  dicBufSize = propNew.dicSize;\r\n  if (p->dic == 0 || dicBufSize != p->dicBufSize)\r\n  {\r\n    LzmaDec_FreeDict(p, alloc);\r\n    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r\n    if (p->dic == 0)\r\n    {\r\n      LzmaDec_FreeProbs(p, alloc);\r\n      return SZ_ERROR_MEM;\r\n    }\r\n  }\r\n  p->dicBufSize = dicBufSize;\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc)\r\n{\r\n  CLzmaDec p;\r\n  SRes res;\r\n  SizeT inSize = *srcLen;\r\n  SizeT outSize = *destLen;\r\n  *srcLen = *destLen = 0;\r\n  if (inSize < RC_INIT_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  LzmaDec_Construct(&p);\r\n  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\r\n  if (res != 0)\r\n    return res;\r\n  p.dic = dest;\r\n  p.dicBufSize = outSize;\r\n\r\n  LzmaDec_Init(&p);\r\n  \r\n  *srcLen = inSize;\r\n  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r\n\r\n  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r\n    res = SZ_ERROR_INPUT_EOF;\r\n\r\n  (*destLen) = p.dicPos;\r\n  LzmaDec_FreeProbs(&p, alloc);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaDec.h",
    "content": "/* LzmaDec.h -- LZMA Decoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMADEC_H\r\n#define __LZMADEC_H\r\n\r\n#include \"Types.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* _LZMA_PROB32 can increase the speed on some CPUs,\r\n   but memory usage for CLzmaDec::probs will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n\r\n/* ---------- LZMA Properties ---------- */\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaProps\r\n{\r\n  unsigned lc, lp, pb;\r\n  UInt32 dicSize;\r\n} CLzmaProps;\r\n\r\n/* LzmaProps_Decode - decodes properties\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);\r\n\r\n\r\n/* ---------- LZMA Decoder state ---------- */\r\n\r\n/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.\r\n   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */\r\n\r\n#define LZMA_REQUIRED_INPUT_MAX 20\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProps prop;\r\n  CLzmaProb *probs;\r\n  Byte *dic;\r\n  const Byte *buf;\r\n  UInt32 range, code;\r\n  SizeT dicPos;\r\n  SizeT dicBufSize;\r\n  UInt32 processedPos;\r\n  UInt32 checkDicSize;\r\n  unsigned state;\r\n  UInt32 reps[4];\r\n  unsigned remainLen;\r\n  int needFlush;\r\n  int needInitState;\r\n  UInt32 numProbs;\r\n  unsigned tempBufSize;\r\n  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];\r\n} CLzmaDec;\r\n\r\n#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p);\r\n\r\n/* There are two types of LZMA streams:\r\n     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.\r\n     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_FINISH_ANY,   /* finish at any point */\r\n  LZMA_FINISH_END    /* block must be finished at the end */\r\n} ELzmaFinishMode;\r\n\r\n/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!\r\n\r\n   You must use LZMA_FINISH_END, when you know that current output buffer\r\n   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.\r\n\r\n   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,\r\n   and output value of destLen will be less than output buffer size limit.\r\n   You can check status result also.\r\n\r\n   You can use multiple checks to test data integrity after full decompression:\r\n     1) Check Result and \"status\" variable.\r\n     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.\r\n        You must use correct finish mode in that case. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */\r\n  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\r\n  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */\r\n  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */\r\n  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */\r\n} ELzmaStatus;\r\n\r\n/* ELzmaStatus is used only as output value for function call */\r\n\r\n\r\n/* ---------- Interfaces ---------- */\r\n\r\n/* There are 3 levels of interfaces:\r\n     1) Dictionary Interface\r\n     2) Buffer Interface\r\n     3) One Call Interface\r\n   You can select any of these interfaces, but don't mix functions from different\r\n   groups for same object. */\r\n\r\n\r\n/* There are two variants to allocate state for Dictionary Interface:\r\n     1) LzmaDec_Allocate / LzmaDec_Free\r\n     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs\r\n   You can use variant 2, if you set dictionary buffer manually.\r\n   For Buffer Interface you must always use variant 1.\r\n\r\nLzmaDec_Allocate* can return:\r\n  SZ_OK\r\n  SZ_ERROR_MEM         - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n   \r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);\r\n\r\n/* ---------- Dictionary Interface ---------- */\r\n\r\n/* You can use it, if you want to eliminate the overhead for data copying from\r\n   dictionary to some other external buffer.\r\n   You must work with CLzmaDec variables directly in this interface.\r\n\r\n   STEPS:\r\n     LzmaDec_Constr()\r\n     LzmaDec_Allocate()\r\n     for (each new stream)\r\n     {\r\n       LzmaDec_Init()\r\n       while (it needs more decompression)\r\n       {\r\n         LzmaDec_DecodeToDic()\r\n         use data from CLzmaDec::dic and update CLzmaDec::dicPos\r\n       }\r\n     }\r\n     LzmaDec_Free()\r\n*/\r\n\r\n/* LzmaDec_DecodeToDic\r\n   \r\n   The decoding to internal dictionary buffer (CLzmaDec::dic).\r\n   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (dicLimit).\r\n  LZMA_FINISH_ANY - Decode just dicLimit bytes.\r\n  LZMA_FINISH_END - Stream must be finished after dicLimit.\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_NEEDS_MORE_INPUT\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- Buffer Interface ---------- */\r\n\r\n/* It's zlib-like interface.\r\n   See LzmaDec_DecodeToDic description for information about STEPS and return results,\r\n   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need\r\n   to work with CLzmaDec variables manually.\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n*/\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaDecode\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n  SZ_ERROR_MEM  - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n*/\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaEnc.c",
    "content": "/* LzmaEnc.c -- LZMA Encoder\r\n2009-02-02 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n/* #define SHOW_STAT */\r\n/* #define SHOW_STAT2 */\r\n\r\n#if defined(SHOW_STAT) || defined(SHOW_STAT2)\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"LzmaEnc.h\"\r\n\r\n#include \"LzFind.h\"\r\n#ifdef COMPRESS_MF_MT\r\n#include \"LzFindMt.h\"\r\n#endif\r\n\r\n#ifdef SHOW_STAT\r\nstatic int ttt = 0;\r\n#endif\r\n\r\n#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)\r\n\r\n#define kBlockSize (9 << 10)\r\n#define kUnpackBlockSize (1 << 18)\r\n#define kMatchArraySize (1 << 21)\r\n#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)\r\n\r\n#define kNumMaxDirectBits (31)\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n#define kProbInitValue (kBitModelTotal >> 1)\r\n\r\n#define kNumMoveReducingBits 4\r\n#define kNumBitPriceShiftBits 4\r\n#define kBitPrice (1 << kNumBitPriceShiftBits)\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p)\r\n{\r\n  p->level = 5;\r\n  p->dictSize = p->mc = 0;\r\n  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\r\n  p->writeEndMark = 0;\r\n}\r\n\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p)\r\n{\r\n  int level = p->level;\r\n  if (level < 0) level = 5;\r\n  p->level = level;\r\n  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));\r\n  if (p->lc < 0) p->lc = 3;\r\n  if (p->lp < 0) p->lp = 0;\r\n  if (p->pb < 0) p->pb = 2;\r\n  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);\r\n  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);\r\n  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);\r\n  if (p->numHashBytes < 0) p->numHashBytes = 4;\r\n  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\r\n  if (p->numThreads < 0)\r\n    p->numThreads =\r\n      #ifdef COMPRESS_MF_MT\r\n      ((p->btMode && p->algo) ? 2 : 1);\r\n      #else\r\n      1;\r\n      #endif\r\n}\r\n\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n  return props.dictSize;\r\n}\r\n\r\n/* #define LZMA_LOG_BSR */\r\n/* Define it for Intel's CPU */\r\n\r\n\r\n#ifdef LZMA_LOG_BSR\r\n\r\n#define kDicLogSizeMaxCompress 30\r\n\r\n#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }\r\n\r\nUInt32 GetPosSlot1(UInt32 pos)\r\n{\r\n  UInt32 res;\r\n  BSR2_RET(pos, res);\r\n  return res;\r\n}\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }\r\n\r\n#else\r\n\r\n#define kNumLogBits (9 + (int)sizeof(size_t) / 2)\r\n#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)\r\n\r\nvoid LzmaEnc_FastPosInit(Byte *g_FastPos)\r\n{\r\n  int c = 2, slotFast;\r\n  g_FastPos[0] = 0;\r\n  g_FastPos[1] = 1;\r\n  \r\n  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)\r\n  {\r\n    UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n    UInt32 j;\r\n    for (j = 0; j < k; j++, c++)\r\n      g_FastPos[c] = (Byte)slotFast;\r\n  }\r\n}\r\n\r\n#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \\\r\n  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \\\r\n  res = p->g_FastPos[pos >> i] + (i * 2); }\r\n/*\r\n#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \\\r\n  p->g_FastPos[pos >> 6] + 12 : \\\r\n  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }\r\n*/\r\n\r\n#define GetPosSlot1(pos) p->g_FastPos[pos]\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }\r\n\r\n#endif\r\n\r\n\r\n#define LZMA_NUM_REPS 4\r\n\r\ntypedef unsigned CState;\r\n\r\ntypedef struct _COptimal\r\n{\r\n  UInt32 price;\r\n\r\n  CState state;\r\n  int prev1IsChar;\r\n  int prev2;\r\n\r\n  UInt32 posPrev2;\r\n  UInt32 backPrev2;\r\n\r\n  UInt32 posPrev;\r\n  UInt32 backPrev;\r\n  UInt32 backs[LZMA_NUM_REPS];\r\n} COptimal;\r\n\r\n#define kNumOpts (1 << 12)\r\n\r\n#define kNumLenToPosStates 4\r\n#define kNumPosSlotBits 6\r\n#define kDicLogSizeMin 0\r\n#define kDicLogSizeMax 32\r\n#define kDistTableSizeMax (kDicLogSizeMax * 2)\r\n\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n#define kAlignMask (kAlignTableSize - 1)\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)\r\n\r\n#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n#define LZMA_PB_MAX 4\r\n#define LZMA_LC_MAX 8\r\n#define LZMA_LP_MAX 4\r\n\r\n#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)\r\n\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define LZMA_MATCH_LEN_MIN 2\r\n#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)\r\n\r\n#define kNumStates 12\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb choice;\r\n  CLzmaProb choice2;\r\n  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];\r\n  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];\r\n  CLzmaProb high[kLenNumHighSymbols];\r\n} CLenEnc;\r\n\r\ntypedef struct\r\n{\r\n  CLenEnc p;\r\n  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\r\n  UInt32 tableSize;\r\n  UInt32 counters[LZMA_NUM_PB_STATES_MAX];\r\n} CLenPriceEnc;\r\n\r\ntypedef struct _CRangeEnc\r\n{\r\n  UInt32 range;\r\n  Byte cache;\r\n  UInt64 low;\r\n  UInt64 cacheSize;\r\n  Byte *buf;\r\n  Byte *bufLim;\r\n  Byte *bufBase;\r\n  ISeqOutStream *outStream;\r\n  UInt64 processed;\r\n  SRes res;\r\n} CRangeEnc;\r\n\r\ntypedef struct _CSeqInStreamBuf\r\n{\r\n  ISeqInStream funcTable;\r\n  const Byte *data;\r\n  SizeT rem;\r\n} CSeqInStreamBuf;\r\n\r\nstatic SRes MyRead(void *pp, void *data, size_t *size)\r\n{\r\n  size_t curSize = *size;\r\n  CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;\r\n  if (p->rem < curSize)\r\n    curSize = p->rem;\r\n  memcpy(data, p->data, curSize);\r\n  p->rem -= curSize;\r\n  p->data += curSize;\r\n  *size = curSize;\r\n  return SZ_OK;\r\n}\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n} CSaveState;\r\n\r\ntypedef struct _CLzmaEnc\r\n{\r\n  IMatchFinder matchFinder;\r\n  void *matchFinderObj;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Bool mtMode;\r\n  CMatchFinderMt matchFinderMt;\r\n  #endif\r\n\r\n  CMatchFinder matchFinderBase;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte pad[128];\r\n  #endif\r\n  \r\n  UInt32 optimumEndIndex;\r\n  UInt32 optimumCurrentIndex;\r\n\r\n  UInt32 longestMatchLength;\r\n  UInt32 numPairs;\r\n  UInt32 numAvail;\r\n  COptimal opt[kNumOpts];\r\n  \r\n  #ifndef LZMA_LOG_BSR\r\n  Byte g_FastPos[1 << kNumLogBits];\r\n  #endif\r\n\r\n  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];\r\n  UInt32 numFastBytes;\r\n  UInt32 additionalOffset;\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n\r\n  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n  UInt32 alignPrices[kAlignTableSize];\r\n  UInt32 alignPriceCount;\r\n\r\n  UInt32 distTableSize;\r\n\r\n  unsigned lc, lp, pb;\r\n  unsigned lpMask, pbMask;\r\n\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  unsigned lclp;\r\n\r\n  Bool fastMode;\r\n  \r\n  CRangeEnc rc;\r\n\r\n  Bool writeEndMark;\r\n  UInt64 nowPos64;\r\n  UInt32 matchPriceCount;\r\n  Bool finished;\r\n  Bool multiThread;\r\n\r\n  SRes result;\r\n  UInt32 dictSize;\r\n  UInt32 matchFinderCycles;\r\n\r\n  ISeqInStream *inStream;\r\n  CSeqInStreamBuf seqBufInStream;\r\n\r\n  CSaveState saveState;\r\n} CLzmaEnc;\r\n\r\nvoid LzmaEnc_SaveState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CSaveState *dest = &p->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nvoid LzmaEnc_RestoreState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *dest = (CLzmaEnc *)pp;\r\n  const CSaveState *p = &dest->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n\r\n  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||\r\n      props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))\r\n    return SZ_ERROR_PARAM;\r\n  p->dictSize = props.dictSize;\r\n  p->matchFinderCycles = props.mc;\r\n  {\r\n    unsigned fb = props.fb;\r\n    if (fb < 5)\r\n      fb = 5;\r\n    if (fb > LZMA_MATCH_LEN_MAX)\r\n      fb = LZMA_MATCH_LEN_MAX;\r\n    p->numFastBytes = fb;\r\n  }\r\n  p->lc = props.lc;\r\n  p->lp = props.lp;\r\n  p->pb = props.pb;\r\n  p->fastMode = (props.algo == 0);\r\n  p->matchFinderBase.btMode = props.btMode;\r\n  {\r\n    UInt32 numHashBytes = 4;\r\n    if (props.btMode)\r\n    {\r\n      if (props.numHashBytes < 2)\r\n        numHashBytes = 2;\r\n      else if (props.numHashBytes < 4)\r\n        numHashBytes = props.numHashBytes;\r\n    }\r\n    p->matchFinderBase.numHashBytes = numHashBytes;\r\n  }\r\n\r\n  p->matchFinderBase.cutValue = props.mc;\r\n\r\n  p->writeEndMark = props.writeEndMark;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  /*\r\n  if (newMultiThread != _multiThread)\r\n  {\r\n    ReleaseMatchFinder();\r\n    _multiThread = newMultiThread;\r\n  }\r\n  */\r\n  p->multiThread = (props.numThreads > 1);\r\n  #endif\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nstatic const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nstatic const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nstatic const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n#define IsCharState(s) ((s) < 7)\r\n\r\n#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)\r\n\r\n#define kInfinityPrice (1 << 30)\r\n\r\nstatic void RangeEnc_Construct(CRangeEnc *p)\r\n{\r\n  p->outStream = 0;\r\n  p->bufBase = 0;\r\n}\r\n\r\n#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)\r\n\r\n#define RC_BUF_SIZE (1 << 16)\r\nstatic int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  if (p->bufBase == 0)\r\n  {\r\n    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);\r\n    if (p->bufBase == 0)\r\n      return 0;\r\n    p->bufLim = p->bufBase + RC_BUF_SIZE;\r\n  }\r\n  return 1;\r\n}\r\n\r\nstatic void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->bufBase);\r\n  p->bufBase = 0;\r\n}\r\n\r\nstatic void RangeEnc_Init(CRangeEnc *p)\r\n{\r\n  /* Stream.Init(); */\r\n  p->low = 0;\r\n  p->range = 0xFFFFFFFF;\r\n  p->cacheSize = 1;\r\n  p->cache = 0;\r\n\r\n  p->buf = p->bufBase;\r\n\r\n  p->processed = 0;\r\n  p->res = SZ_OK;\r\n}\r\n\r\nstatic void RangeEnc_FlushStream(CRangeEnc *p)\r\n{\r\n  size_t num;\r\n  if (p->res != SZ_OK)\r\n    return;\r\n  num = p->buf - p->bufBase;\r\n  if (num != p->outStream->Write(p->outStream, p->bufBase, num))\r\n    p->res = SZ_ERROR_WRITE;\r\n  p->processed += num;\r\n  p->buf = p->bufBase;\r\n}\r\n\r\nstatic void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)\r\n{\r\n  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)\r\n  {\r\n    Byte temp = p->cache;\r\n    do\r\n    {\r\n      Byte *buf = p->buf;\r\n      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));\r\n      p->buf = buf;\r\n      if (buf == p->bufLim)\r\n        RangeEnc_FlushStream(p);\r\n      temp = 0xFF;\r\n    }\r\n    while (--p->cacheSize != 0);\r\n    p->cache = (Byte)((UInt32)p->low >> 24);\r\n  }\r\n  p->cacheSize++;\r\n  p->low = (UInt32)p->low << 8;\r\n}\r\n\r\nstatic void RangeEnc_FlushData(CRangeEnc *p)\r\n{\r\n  int i;\r\n  for (i = 0; i < 5; i++)\r\n    RangeEnc_ShiftLow(p);\r\n}\r\n\r\nstatic void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)\r\n{\r\n  do\r\n  {\r\n    p->range >>= 1;\r\n    p->low += p->range & (0 - ((value >> --numBits) & 1));\r\n    if (p->range < kTopValue)\r\n    {\r\n      p->range <<= 8;\r\n      RangeEnc_ShiftLow(p);\r\n    }\r\n  }\r\n  while (numBits != 0);\r\n}\r\n\r\nstatic void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)\r\n{\r\n  UInt32 ttt = *prob;\r\n  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;\r\n  if (symbol == 0)\r\n  {\r\n    p->range = newBound;\r\n    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;\r\n  }\r\n  else\r\n  {\r\n    p->low += newBound;\r\n    p->range -= newBound;\r\n    ttt -= ttt >> kNumMoveBits;\r\n  }\r\n  *prob = (CLzmaProb)ttt;\r\n  if (p->range < kTopValue)\r\n  {\r\n    p->range <<= 8;\r\n    RangeEnc_ShiftLow(p);\r\n  }\r\n}\r\n\r\nstatic void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)\r\n{\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nstatic void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)\r\n{\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nvoid LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\r\n{\r\n  UInt32 i;\r\n  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))\r\n  {\r\n    const int kCyclesBits = kNumBitPriceShiftBits;\r\n    UInt32 w = i;\r\n    UInt32 bitCount = 0;\r\n    int j;\r\n    for (j = 0; j < kCyclesBits; j++)\r\n    {\r\n      w = w * w;\r\n      bitCount <<= 1;\r\n      while (w >= ((UInt32)1 << 16))\r\n      {\r\n        w >>= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);\r\n  }\r\n}\r\n\r\n\r\n#define GET_PRICE(prob, symbol) \\\r\n  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICEa(prob, symbol) \\\r\n  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\n#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\nstatic UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\nstatic UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\n\r\nstatic void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0;)\r\n  {\r\n    UInt32 bit;\r\n    i--;\r\n    bit = (symbol >> i) & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n}\r\n\r\nstatic void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = 0; i < numBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= (1 << numBitLevels);\r\n  while (symbol != 1)\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);\r\n    symbol >>= 1;\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += GET_PRICEa(probs[m], bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\n\r\nstatic void LenEnc_Init(CLenEnc *p)\r\n{\r\n  unsigned i;\r\n  p->choice = p->choice2 = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)\r\n    p->low[i] = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)\r\n    p->mid[i] = kProbInitValue;\r\n  for (i = 0; i < kLenNumHighSymbols; i++)\r\n    p->high[i] = kProbInitValue;\r\n}\r\n\r\nstatic void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)\r\n{\r\n  if (symbol < kLenNumLowSymbols)\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 0);\r\n    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);\r\n  }\r\n  else\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 1);\r\n    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 0);\r\n      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 1);\r\n      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)\r\n{\r\n  UInt32 a0 = GET_PRICE_0a(p->choice);\r\n  UInt32 a1 = GET_PRICE_1a(p->choice);\r\n  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);\r\n  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kLenNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);\r\n  }\r\n  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);\r\n}\r\n\r\nstatic void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);\r\n  p->counters[posState] = p->tableSize;\r\n}\r\n\r\nstatic void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)\r\n{\r\n  UInt32 posState;\r\n  for (posState = 0; posState < numPosStates; posState++)\r\n    LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\nstatic void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_Encode(&p->p, rc, symbol, posState);\r\n  if (updatePrice)\r\n    if (--p->counters[posState] == 0)\r\n      LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\n\r\n\r\n\r\nstatic void MovePos(CLzmaEnc *p, UInt32 num)\r\n{\r\n  #ifdef SHOW_STAT\r\n  ttt += num;\r\n  printf(\"\\n MovePos %d\", num);\r\n  #endif\r\n  if (num != 0)\r\n  {\r\n    p->additionalOffset += num;\r\n    p->matchFinder.Skip(p->matchFinderObj, num);\r\n  }\r\n}\r\n\r\nstatic UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)\r\n{\r\n  UInt32 lenRes = 0, numPairs;\r\n  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);\r\n  #ifdef SHOW_STAT\r\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numPairs / 2);\r\n  ttt++;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < numPairs; i += 2)\r\n      printf(\"%2d %6d   | \", p->matches[i], p->matches[i + 1]);\r\n  }\r\n  #endif\r\n  if (numPairs > 0)\r\n  {\r\n    lenRes = p->matches[numPairs - 2];\r\n    if (lenRes == p->numFastBytes)\r\n    {\r\n      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n      UInt32 distance = p->matches[numPairs - 1] + 1;\r\n      UInt32 numAvail = p->numAvail;\r\n      if (numAvail > LZMA_MATCH_LEN_MAX)\r\n        numAvail = LZMA_MATCH_LEN_MAX;\r\n      {\r\n        const Byte *pby2 = pby - distance;\r\n        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r\n      }\r\n    }\r\n  }\r\n  p->additionalOffset++;\r\n  *numDistancePairsRes = numPairs;\r\n  return lenRes;\r\n}\r\n\r\n\r\n#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;\r\n#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;\r\n#define IsShortRep(p) ((p)->backPrev == 0)\r\n\r\nstatic UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)\r\n{\r\n  return\r\n    GET_PRICE_0(p->isRepG0[state]) +\r\n    GET_PRICE_0(p->isRep0Long[state][posState]);\r\n}\r\n\r\nstatic UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)\r\n{\r\n  UInt32 price;\r\n  if (repIndex == 0)\r\n  {\r\n    price = GET_PRICE_0(p->isRepG0[state]);\r\n    price += GET_PRICE_1(p->isRep0Long[state][posState]);\r\n  }\r\n  else\r\n  {\r\n    price = GET_PRICE_1(p->isRepG0[state]);\r\n    if (repIndex == 1)\r\n      price += GET_PRICE_0(p->isRepG1[state]);\r\n    else\r\n    {\r\n      price += GET_PRICE_1(p->isRepG1[state]);\r\n      price += GET_PRICE(p->isRepG2[state], repIndex - 2);\r\n    }\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)\r\n{\r\n  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +\r\n    GetPureRepPrice(p, repIndex, state, posState);\r\n}\r\n\r\nstatic UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)\r\n{\r\n  UInt32 posMem = p->opt[cur].posPrev;\r\n  UInt32 backMem = p->opt[cur].backPrev;\r\n  p->optimumEndIndex = cur;\r\n  do\r\n  {\r\n    if (p->opt[cur].prev1IsChar)\r\n    {\r\n      MakeAsChar(&p->opt[posMem])\r\n      p->opt[posMem].posPrev = posMem - 1;\r\n      if (p->opt[cur].prev2)\r\n      {\r\n        p->opt[posMem - 1].prev1IsChar = False;\r\n        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;\r\n        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;\r\n      }\r\n    }\r\n    {\r\n      UInt32 posPrev = posMem;\r\n      UInt32 backCur = backMem;\r\n      \r\n      backMem = p->opt[posPrev].backPrev;\r\n      posMem = p->opt[posPrev].posPrev;\r\n      \r\n      p->opt[posPrev].backPrev = backCur;\r\n      p->opt[posPrev].posPrev = cur;\r\n      cur = posPrev;\r\n    }\r\n  }\r\n  while (cur != 0);\r\n  *backRes = p->opt[0].backPrev;\r\n  p->optimumCurrentIndex  = p->opt[0].posPrev;\r\n  return p->optimumCurrentIndex;\r\n}\r\n\r\n#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)\r\n\r\nstatic UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;\r\n  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\r\n  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];\r\n  UInt32 *matches;\r\n  const Byte *data;\r\n  Byte curByte, matchByte;\r\n  if (p->optimumEndIndex != p->optimumCurrentIndex)\r\n  {\r\n    const COptimal *opt = &p->opt[p->optimumCurrentIndex];\r\n    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;\r\n    *backRes = opt->backPrev;\r\n    p->optimumCurrentIndex = opt->posPrev;\r\n    return lenRes;\r\n  }\r\n  p->optimumCurrentIndex = p->optimumEndIndex = 0;\r\n  \r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  if (numAvail < 2)\r\n  {\r\n    *backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  repMaxIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 lenTest;\r\n    const Byte *data2;\r\n    reps[i] = p->reps[i];\r\n    data2 = data - (reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if (repLens[repMaxIndex] >= p->numFastBytes)\r\n  {\r\n    UInt32 lenRes;\r\n    *backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    MovePos(p, lenRes - 1);\r\n    return lenRes;\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n  curByte = *data;\r\n  matchByte = *(data - (reps[0] + 1));\r\n\r\n  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    *backRes = (UInt32)-1;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[0].state = (CState)p->state;\r\n\r\n  posState = (position & p->pbMask);\r\n\r\n  {\r\n    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +\r\n        (!IsCharState(p->state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n  }\r\n\r\n  MakeAsChar(&p->opt[1]);\r\n\r\n  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);\r\n  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);\r\n\r\n  if (matchByte == curByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);\r\n    if (shortRepPrice < p->opt[1].price)\r\n    {\r\n      p->opt[1].price = shortRepPrice;\r\n      MakeAsShortRep(&p->opt[1]);\r\n    }\r\n  }\r\n  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);\r\n\r\n  if (lenEnd < 2)\r\n  {\r\n    *backRes = p->opt[1].backPrev;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[1].posPrev = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n    p->opt[0].backs[i] = reps[i];\r\n\r\n  len = lenEnd;\r\n  do\r\n    p->opt[len--].price = kInfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    UInt32 price;\r\n    if (repLen < 2)\r\n      continue;\r\n    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];\r\n      COptimal *opt = &p->opt[repLen];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = i;\r\n        opt->prev1IsChar = False;\r\n      }\r\n    }\r\n    while (--repLen >= 2);\r\n  }\r\n\r\n  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= mainLen)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matches[offs])\r\n      offs += 2;\r\n    for (; ; len++)\r\n    {\r\n      COptimal *opt;\r\n      UInt32 distance = matches[offs + 1];\r\n\r\n      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];\r\n      UInt32 lenToPosState = GetLenToPosState(len);\r\n      if (distance < kNumFullDistances)\r\n        curAndLenPrice += p->distancesPrices[lenToPosState][distance];\r\n      else\r\n      {\r\n        UInt32 slot;\r\n        GetPosSlot2(distance, slot);\r\n        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];\r\n      }\r\n      opt = &p->opt[len];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = distance + LZMA_NUM_REPS;\r\n        opt->prev1IsChar = False;\r\n      }\r\n      if (len == matches[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numPairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  cur = 0;\r\n\r\n    #ifdef SHOW_STAT2\r\n    if (position >= 0)\r\n    {\r\n      unsigned i;\r\n      printf(\"\\n pos = %4X\", position);\r\n      for (i = cur; i <= lenEnd; i++)\r\n      printf(\"\\nprice[%4X] = %d\", position - cur + i, p->opt[i].price);\r\n    }\r\n    #endif\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;\r\n    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;\r\n    Bool nextIsChar;\r\n    Byte curByte, matchByte;\r\n    const Byte *data;\r\n    COptimal *curOpt;\r\n    COptimal *nextOpt;\r\n\r\n    cur++;\r\n    if (cur == lenEnd)\r\n      return Backward(p, backRes, cur);\r\n\r\n    newLen = ReadMatchDistances(p, &numPairs);\r\n    if (newLen >= p->numFastBytes)\r\n    {\r\n      p->numPairs = numPairs;\r\n      p->longestMatchLength = newLen;\r\n      return Backward(p, backRes, cur);\r\n    }\r\n    position++;\r\n    curOpt = &p->opt[cur];\r\n    posPrev = curOpt->posPrev;\r\n    if (curOpt->prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOpt->prev2)\r\n      {\r\n        state = p->opt[curOpt->posPrev2].state;\r\n        if (curOpt->backPrev2 < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      else\r\n        state = p->opt[posPrev].state;\r\n      state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n      state = p->opt[posPrev].state;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (IsShortRep(curOpt))\r\n        state = kShortRepNextStates[state];\r\n      else\r\n        state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      const COptimal *prevOpt;\r\n      if (curOpt->prev1IsChar && curOpt->prev2)\r\n      {\r\n        posPrev = curOpt->posPrev2;\r\n        pos = curOpt->backPrev2;\r\n        state = kRepNextStates[state];\r\n      }\r\n      else\r\n      {\r\n        pos = curOpt->backPrev;\r\n        if (pos < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      prevOpt = &p->opt[posPrev];\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        UInt32 i;\r\n        reps[0] = prevOpt->backs[pos];\r\n        for (i = 1; i <= pos; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n        for (; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i];\r\n      }\r\n      else\r\n      {\r\n        UInt32 i;\r\n        reps[0] = (pos - LZMA_NUM_REPS);\r\n        for (i = 1; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n      }\r\n    }\r\n    curOpt->state = (CState)state;\r\n\r\n    curOpt->backs[0] = reps[0];\r\n    curOpt->backs[1] = reps[1];\r\n    curOpt->backs[2] = reps[2];\r\n    curOpt->backs[3] = reps[3];\r\n\r\n    curPrice = curOpt->price;\r\n    nextIsChar = False;\r\n    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n    curByte = *data;\r\n    matchByte = *(data - (reps[0] + 1));\r\n\r\n    posState = (position & p->pbMask);\r\n\r\n    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);\r\n    {\r\n      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n      curAnd1Price +=\r\n        (!IsCharState(state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n    }\r\n\r\n    nextOpt = &p->opt[cur + 1];\r\n\r\n    if (curAnd1Price < nextOpt->price)\r\n    {\r\n      nextOpt->price = curAnd1Price;\r\n      nextOpt->posPrev = cur;\r\n      MakeAsChar(nextOpt);\r\n      nextIsChar = True;\r\n    }\r\n\r\n    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);\r\n    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);\r\n    \r\n    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);\r\n      if (shortRepPrice <= nextOpt->price)\r\n      {\r\n        nextOpt->price = shortRepPrice;\r\n        nextOpt->posPrev = cur;\r\n        MakeAsShortRep(nextOpt);\r\n        nextIsChar = True;\r\n      }\r\n    }\r\n    numAvailFull = p->numAvail;\r\n    {\r\n      UInt32 temp = kNumOpts - 1 - cur;\r\n      if (temp < numAvailFull)\r\n        numAvailFull = temp;\r\n    }\r\n\r\n    if (numAvailFull < 2)\r\n      continue;\r\n    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);\r\n\r\n    if (!nextIsChar && matchByte != curByte) /* speed optimization */\r\n    {\r\n      /* try Literal + rep0 */\r\n      UInt32 temp;\r\n      UInt32 lenTest2;\r\n      const Byte *data2 = data - (reps[0] + 1);\r\n      UInt32 limit = p->numFastBytes + 1;\r\n      if (limit > numAvailFull)\r\n        limit = numAvailFull;\r\n\r\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r\n      lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        UInt32 state2 = kLiteralNextStates[state];\r\n        UInt32 posStateNext = (position + 1) & p->pbMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price +\r\n            GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n            GET_PRICE_1(p->isRep[state2]);\r\n        /* for (; lenTest2 >= 2; lenTest2--) */\r\n        {\r\n          UInt32 curAndLenPrice;\r\n          COptimal *opt;\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while (lenEnd < offset)\r\n            p->opt[++lenEnd].price = kInfinityPrice;\r\n          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n          opt = &p->opt[offset];\r\n          if (curAndLenPrice < opt->price)\r\n          {\r\n            opt->price = curAndLenPrice;\r\n            opt->posPrev = cur + 1;\r\n            opt->backPrev = 0;\r\n            opt->prev1IsChar = True;\r\n            opt->prev2 = False;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    startLen = 2; /* speed optimization */\r\n    {\r\n    UInt32 repIndex;\r\n    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)\r\n    {\r\n      UInt32 lenTest;\r\n      UInt32 lenTestTemp;\r\n      UInt32 price;\r\n      const Byte *data2 = data - (reps[repIndex] + 1);\r\n      if (data[0] != data2[0] || data[1] != data2[1])\r\n        continue;\r\n      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n      while (lenEnd < cur + lenTest)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n      lenTestTemp = lenTest;\r\n      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];\r\n        COptimal *opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = repIndex;\r\n          opt->prev1IsChar = False;\r\n        }\r\n      }\r\n      while (--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      /* if (_maxMode) */\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kRepNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice =\r\n                price + p->repLenEnc.prices[posState][lenTest - 2] +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (position + lenTest + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n    }\r\n    }\r\n    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */\r\n    if (newLen > numAvail)\r\n    {\r\n      newLen = numAvail;\r\n      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);\r\n      matches[numPairs] = newLen;\r\n      numPairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\r\n      UInt32 offs, curBack, posSlot;\r\n      UInt32 lenTest;\r\n      while (lenEnd < cur + newLen)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n\r\n      offs = 0;\r\n      while (startLen > matches[offs])\r\n        offs += 2;\r\n      curBack = matches[offs + 1];\r\n      GetPosSlot2(curBack, posSlot);\r\n      for (lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        COptimal *opt;\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];\r\n        \r\n        opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = curBack + LZMA_NUM_REPS;\r\n          opt->prev1IsChar = False;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matches[offs])\r\n        {\r\n          /* Try Match + Literal + Rep0 */\r\n          const Byte *data2 = data - (curBack + 1);\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kMatchNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (posStateNext + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = curBack + LZMA_NUM_REPS;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numPairs)\r\n            break;\r\n          curBack = matches[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            GetPosSlot2(curBack, posSlot);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))\r\n\r\nstatic UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;\r\n  const Byte *data;\r\n  const UInt32 *matches;\r\n\r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  *backRes = (UInt32)-1;\r\n  if (numAvail < 2)\r\n    return 1;\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n\r\n  repLen = repIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    for (len = 2; len < numAvail && data[len] == data2[len]; len++);\r\n    if (len >= p->numFastBytes)\r\n    {\r\n      *backRes = i;\r\n      MovePos(p, len - 1);\r\n      return len;\r\n    }\r\n    if (len > repLen)\r\n    {\r\n      repIndex = i;\r\n      repLen = len;\r\n    }\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n\r\n  mainDist = 0; /* for GCC */\r\n  if (mainLen >= 2)\r\n  {\r\n    mainDist = matches[numPairs - 1];\r\n    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matches[numPairs - 3], mainDist))\r\n        break;\r\n      numPairs -= 2;\r\n      mainLen = matches[numPairs - 2];\r\n      mainDist = matches[numPairs - 1];\r\n    }\r\n    if (mainLen == 2 && mainDist >= 0x80)\r\n      mainLen = 1;\r\n  }\r\n\r\n  if (repLen >= 2 && (\r\n        (repLen + 1 >= mainLen) ||\r\n        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||\r\n        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))\r\n  {\r\n    *backRes = repIndex;\r\n    MovePos(p, repLen - 1);\r\n    return repLen;\r\n  }\r\n  \r\n  if (mainLen < 2 || numAvail <= 2)\r\n    return 1;\r\n\r\n  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);\r\n  if (p->longestMatchLength >= 2)\r\n  {\r\n    UInt32 newDistance = matches[p->numPairs - 1];\r\n    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||\r\n        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||\r\n        (p->longestMatchLength > mainLen + 1) ||\r\n        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))\r\n      return 1;\r\n  }\r\n  \r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len, limit;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    limit = mainLen - 1;\r\n    for (len = 2; len < limit && data[len] == data2[len]; len++);\r\n    if (len >= limit)\r\n      return 1;\r\n  }\r\n  *backRes = mainDist + LZMA_NUM_REPS;\r\n  MovePos(p, mainLen - 2);\r\n  return mainLen;\r\n}\r\n\r\nstatic void WriteEndMarker(CLzmaEnc *p, UInt32 posState)\r\n{\r\n  UInt32 len;\r\n  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n  p->state = kMatchNextStates[p->state];\r\n  len = LZMA_MATCH_LEN_MIN;\r\n  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);\r\n  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);\r\n  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);\r\n}\r\n\r\nstatic SRes CheckErrors(CLzmaEnc *p)\r\n{\r\n  if (p->result != SZ_OK)\r\n    return p->result;\r\n  if (p->rc.res != SZ_OK)\r\n    p->result = SZ_ERROR_WRITE;\r\n  if (p->matchFinderBase.result != SZ_OK)\r\n    p->result = SZ_ERROR_READ;\r\n  if (p->result != SZ_OK)\r\n    p->finished = True;\r\n  return p->result;\r\n}\r\n\r\nstatic SRes Flush(CLzmaEnc *p, UInt32 nowPos)\r\n{\r\n  /* ReleaseMFStream(); */\r\n  p->finished = True;\r\n  if (p->writeEndMark)\r\n    WriteEndMarker(p, nowPos & p->pbMask);\r\n  RangeEnc_FlushData(&p->rc);\r\n  RangeEnc_FlushStream(&p->rc);\r\n  return CheckErrors(p);\r\n}\r\n\r\nstatic void FillAlignPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < kAlignTableSize; i++)\r\n    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);\r\n  p->alignPriceCount = 0;\r\n}\r\n\r\nstatic void FillDistancesPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  UInt32 i, lenToPosState;\r\n  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  {\r\n    UInt32 posSlot = GetPosSlot1(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);\r\n  }\r\n\r\n  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n    UInt32 posSlot;\r\n    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);\r\n    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);\r\n\r\n    {\r\n      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];\r\n      UInt32 i;\r\n      for (i = 0; i < kStartPosModelIndex; i++)\r\n        distancesPrices[i] = posSlotPrices[i];\r\n      for (; i < kNumFullDistances; i++)\r\n        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];\r\n    }\r\n  }\r\n  p->matchPriceCount = 0;\r\n}\r\n\r\nvoid LzmaEnc_Construct(CLzmaEnc *p)\r\n{\r\n  RangeEnc_Construct(&p->rc);\r\n  MatchFinder_Construct(&p->matchFinderBase);\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Construct(&p->matchFinderMt);\r\n  p->matchFinderMt.MatchFinder = &p->matchFinderBase;\r\n  #endif\r\n\r\n  {\r\n    CLzmaEncProps props;\r\n    LzmaEncProps_Init(&props);\r\n    LzmaEnc_SetProps(p, &props);\r\n  }\r\n\r\n  #ifndef LZMA_LOG_BSR\r\n  LzmaEnc_FastPosInit(p->g_FastPos);\r\n  #endif\r\n\r\n  LzmaEnc_InitPriceTables(p->ProbPrices);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)\r\n{\r\n  void *p;\r\n  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));\r\n  if (p != 0)\r\n    LzmaEnc_Construct((CLzmaEnc *)p);\r\n  return p;\r\n}\r\n\r\nvoid LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->litProbs);\r\n  alloc->Free(alloc, p->saveState.litProbs);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nvoid LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);\r\n  #endif\r\n  MatchFinder_Free(&p->matchFinderBase, allocBig);\r\n  LzmaEnc_FreeLits(p, alloc);\r\n  RangeEnc_Free(&p->rc, alloc);\r\n}\r\n\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);\r\n  alloc->Free(alloc, p);\r\n}\r\n\r\nstatic SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)\r\n{\r\n  UInt32 nowPos32, startPos32;\r\n  if (p->inStream != 0)\r\n  {\r\n    p->matchFinderBase.stream = p->inStream;\r\n    p->matchFinder.Init(p->matchFinderObj);\r\n    p->inStream = 0;\r\n  }\r\n\r\n  if (p->finished)\r\n    return p->result;\r\n  RINOK(CheckErrors(p));\r\n\r\n  nowPos32 = (UInt32)p->nowPos64;\r\n  startPos32 = nowPos32;\r\n\r\n  if (p->nowPos64 == 0)\r\n  {\r\n    UInt32 numPairs;\r\n    Byte curByte;\r\n    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n      return Flush(p, nowPos32);\r\n    ReadMatchDistances(p, &numPairs);\r\n    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);\r\n    p->state = kLiteralNextStates[p->state];\r\n    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);\r\n    LitEnc_Encode(&p->rc, p->litProbs, curByte);\r\n    p->additionalOffset--;\r\n    nowPos32++;\r\n  }\r\n\r\n  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)\r\n  for (;;)\r\n  {\r\n    UInt32 pos, len, posState;\r\n\r\n    if (p->fastMode)\r\n      len = GetOptimumFast(p, &pos);\r\n    else\r\n      len = GetOptimum(p, nowPos32, &pos);\r\n\r\n    #ifdef SHOW_STAT2\r\n    printf(\"\\n pos = %4X,   len = %d   pos = %d\", nowPos32, len, pos);\r\n    #endif\r\n\r\n    posState = nowPos32 & p->pbMask;\r\n    if (len == 1 && pos == (UInt32)-1)\r\n    {\r\n      Byte curByte;\r\n      CLzmaProb *probs;\r\n      const Byte *data;\r\n\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);\r\n      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n      curByte = *data;\r\n      probs = LIT_PROBS(nowPos32, *(data - 1));\r\n      if (IsCharState(p->state))\r\n        LitEnc_Encode(&p->rc, probs, curByte);\r\n      else\r\n        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));\r\n      p->state = kLiteralNextStates[p->state];\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);\r\n        if (pos == 0)\r\n        {\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = p->reps[pos];\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);\r\n          if (pos == 1)\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);\r\n          else\r\n          {\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);\r\n            if (pos == 3)\r\n              p->reps[3] = p->reps[2];\r\n            p->reps[2] = p->reps[1];\r\n          }\r\n          p->reps[1] = p->reps[0];\r\n          p->reps[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          p->state = kShortRepNextStates[p->state];\r\n        else\r\n        {\r\n          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n          p->state = kRepNextStates[p->state];\r\n        }\r\n      }\r\n      else\r\n      {\r\n        UInt32 posSlot;\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n        p->state = kMatchNextStates[p->state];\r\n        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n        pos -= LZMA_NUM_REPS;\r\n        GetPosSlot(pos, posSlot);\r\n        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);\r\n          else\r\n          {\r\n            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);\r\n            p->alignPriceCount++;\r\n          }\r\n        }\r\n        p->reps[3] = p->reps[2];\r\n        p->reps[2] = p->reps[1];\r\n        p->reps[1] = p->reps[0];\r\n        p->reps[0] = pos;\r\n        p->matchPriceCount++;\r\n      }\r\n    }\r\n    p->additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (p->additionalOffset == 0)\r\n    {\r\n      UInt32 processed;\r\n      if (!p->fastMode)\r\n      {\r\n        if (p->matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices(p);\r\n        if (p->alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices(p);\r\n      }\r\n      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n        break;\r\n      processed = nowPos32 - startPos32;\r\n      if (useLimits)\r\n      {\r\n        if (processed + kNumOpts + 300 >= maxUnpackSize ||\r\n            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)\r\n          break;\r\n      }\r\n      else if (processed >= (1 << 15))\r\n      {\r\n        p->nowPos64 += nowPos32 - startPos32;\r\n        return CheckErrors(p);\r\n      }\r\n    }\r\n  }\r\n  p->nowPos64 += nowPos32 - startPos32;\r\n  return Flush(p, nowPos32);\r\n}\r\n\r\n#define kBigHashDicLimit ((UInt32)1 << 24)\r\n\r\nstatic SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 beforeSize = kNumOpts;\r\n  Bool btMode;\r\n  if (!RangeEnc_Alloc(&p->rc, alloc))\r\n    return SZ_ERROR_MEM;\r\n  btMode = (p->matchFinderBase.btMode != 0);\r\n  #ifdef COMPRESS_MF_MT\r\n  p->mtMode = (p->multiThread && !p->fastMode && btMode);\r\n  #endif\r\n\r\n  {\r\n    unsigned lclp = p->lc + p->lp;\r\n    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)\r\n    {\r\n      LzmaEnc_FreeLits(p, alloc);\r\n      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      if (p->litProbs == 0 || p->saveState.litProbs == 0)\r\n      {\r\n        LzmaEnc_FreeLits(p, alloc);\r\n        return SZ_ERROR_MEM;\r\n      }\r\n      p->lclp = lclp;\r\n    }\r\n  }\r\n\r\n  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);\r\n\r\n  if (beforeSize + p->dictSize < keepWindowSize)\r\n    beforeSize = keepWindowSize - p->dictSize;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (p->mtMode)\r\n  {\r\n    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));\r\n    p->matchFinderObj = &p->matchFinderMt;\r\n    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))\r\n      return SZ_ERROR_MEM;\r\n    p->matchFinderObj = &p->matchFinderBase;\r\n    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nvoid LzmaEnc_Init(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  p->state = 0;\r\n  for (i = 0 ; i < LZMA_NUM_REPS; i++)\r\n    p->reps[i] = 0;\r\n\r\n  RangeEnc_Init(&p->rc);\r\n\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    UInt32 j;\r\n    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)\r\n    {\r\n      p->isMatch[i][j] = kProbInitValue;\r\n      p->isRep0Long[i][j] = kProbInitValue;\r\n    }\r\n    p->isRep[i] = kProbInitValue;\r\n    p->isRepG0[i] = kProbInitValue;\r\n    p->isRepG1[i] = kProbInitValue;\r\n    p->isRepG2[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    UInt32 num = 0x300 << (p->lp + p->lc);\r\n    for (i = 0; i < num; i++)\r\n      p->litProbs[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    for (i = 0; i < kNumLenToPosStates; i++)\r\n    {\r\n      CLzmaProb *probs = p->posSlotEncoder[i];\r\n      UInt32 j;\r\n      for (j = 0; j < (1 << kNumPosSlotBits); j++)\r\n        probs[j] = kProbInitValue;\r\n    }\r\n  }\r\n  {\r\n    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      p->posEncoders[i] = kProbInitValue;\r\n  }\r\n\r\n  LenEnc_Init(&p->lenEnc.p);\r\n  LenEnc_Init(&p->repLenEnc.p);\r\n\r\n  for (i = 0; i < (1 << kNumAlignBits); i++)\r\n    p->posAlignEncoder[i] = kProbInitValue;\r\n\r\n  p->optimumEndIndex = 0;\r\n  p->optimumCurrentIndex = 0;\r\n  p->additionalOffset = 0;\r\n\r\n  p->pbMask = (1 << p->pb) - 1;\r\n  p->lpMask = (1 << p->lp) - 1;\r\n}\r\n\r\nvoid LzmaEnc_InitPrices(CLzmaEnc *p)\r\n{\r\n  if (!p->fastMode)\r\n  {\r\n    FillDistancesPrices(p);\r\n    FillAlignPrices(p);\r\n  }\r\n\r\n  p->lenEnc.tableSize =\r\n  p->repLenEnc.tableSize =\r\n      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;\r\n  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);\r\n  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);\r\n}\r\n\r\nstatic SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)\r\n    if (p->dictSize <= ((UInt32)1 << i))\r\n      break;\r\n  p->distTableSize = i * 2;\r\n\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));\r\n  LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  p->nowPos64 = 0;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  p->rc.outStream = outStream;\r\n  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);\r\n}\r\n\r\nSRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,\r\n    ISeqInStream *inStream, UInt32 keepWindowSize,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nstatic void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)\r\n{\r\n  p->seqBufInStream.funcTable.Read = MyRead;\r\n  p->seqBufInStream.data = src;\r\n  p->seqBufInStream.rem = srcLen;\r\n}\r\n\r\nSRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\r\n    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n  p->inStream = &p->seqBufInStream.funcTable;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nvoid LzmaEnc_Finish(CLzmaEncHandle pp)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  if (p->mtMode)\r\n    MatchFinderMt_ReleaseStream(&p->matchFinderMt);\r\n  #else\r\n  pp = pp;\r\n  #endif\r\n}\r\n\r\ntypedef struct _CSeqOutStreamBuf\r\n{\r\n  ISeqOutStream funcTable;\r\n  Byte *data;\r\n  SizeT rem;\r\n  Bool overflow;\r\n} CSeqOutStreamBuf;\r\n\r\nstatic size_t MyWrite(void *pp, const void *data, size_t size)\r\n{\r\n  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;\r\n  if (p->rem < size)\r\n  {\r\n    size = p->rem;\r\n    p->overflow = True;\r\n  }\r\n  memcpy(p->data, data, size);\r\n  p->rem -= size;\r\n  p->data += size;\r\n  return size;\r\n}\r\n\r\n\r\nUInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n}\r\n\r\nconst Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n}\r\n\r\nSRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\r\n    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  UInt64 nowPos64;\r\n  SRes res;\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = False;\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n\r\n  if (reInit)\r\n    LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  nowPos64 = p->nowPos64;\r\n  RangeEnc_Init(&p->rc);\r\n  p->rc.outStream = &outStream.funcTable;\r\n\r\n  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);\r\n  \r\n  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  SRes res = SZ_OK;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte allocaDummy[0x300];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  #endif\r\n\r\n  RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));\r\n\r\n  for (;;)\r\n  {\r\n    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);\r\n    if (res != SZ_OK || p->finished != 0)\r\n      break;\r\n    if (progress != 0)\r\n    {\r\n      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));\r\n      if (res != SZ_OK)\r\n      {\r\n        res = SZ_ERROR_PROGRESS;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  LzmaEnc_Finish(pp);\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  int i;\r\n  UInt32 dictSize = p->dictSize;\r\n  if (*size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_PARAM;\r\n  *size = LZMA_PROPS_SIZE;\r\n  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);\r\n\r\n  for (i = 11; i <= 30; i++)\r\n  {\r\n    if (dictSize <= ((UInt32)2 << i))\r\n    {\r\n      dictSize = (2 << i);\r\n      break;\r\n    }\r\n    if (dictSize <= ((UInt32)3 << i))\r\n    {\r\n      dictSize = (3 << i);\r\n      break;\r\n    }\r\n  }\r\n\r\n  for (i = 0; i < 4; i++)\r\n    props[1 + i] = (Byte)(dictSize >> (8 * i));\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  SRes res;\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = writeEndMark;\r\n  res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,\r\n      progress, alloc, allocBig);\r\n\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n  return res;\r\n}\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);\r\n  SRes res;\r\n  if (p == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LzmaEnc_SetProps(p, props);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);\r\n    if (res == SZ_OK)\r\n      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,\r\n          writeEndMark, progress, alloc, allocBig);\r\n  }\r\n\r\n  LzmaEnc_Destroy(p, alloc, allocBig);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaEnc.h",
    "content": "/*  LzmaEnc.h -- LZMA Encoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMAENC_H\r\n#define __LZMAENC_H\r\n\r\n#include \"Types.h\"\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaEncProps\r\n{\r\n  int level;       /*  0 <= level <= 9 */\r\n  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version\r\n                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version\r\n                       default = (1 << 24) */\r\n  int lc;          /* 0 <= lc <= 8, default = 3 */\r\n  int lp;          /* 0 <= lp <= 4, default = 0 */\r\n  int pb;          /* 0 <= pb <= 4, default = 2 */\r\n  int algo;        /* 0 - fast, 1 - normal, default = 1 */\r\n  int fb;          /* 5 <= fb <= 273, default = 32 */\r\n  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */\r\n  int numHashBytes; /* 2, 3 or 4, default = 4 */\r\n  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */\r\n  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */\r\n  int numThreads;  /* 1 or 2, default = 2 */\r\n} CLzmaEncProps;\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p);\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p);\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);\r\n\r\n\r\n/* ---------- CLzmaEncHandle Interface ---------- */\r\n\r\n/* LzmaEnc_* functions can return the following exit codes:\r\nReturns:\r\n  SZ_OK           - OK\r\n  SZ_ERROR_MEM    - Memory allocation error\r\n  SZ_ERROR_PARAM  - Incorrect paramater in props\r\n  SZ_ERROR_WRITE  - Write callback error.\r\n  SZ_ERROR_PROGRESS - some break from progress callback\r\n  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\ntypedef void * CLzmaEncHandle;\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);\r\nSRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaEncode\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaLib/LzmaLib.def",
    "content": "EXPORTS\r\n  LzmaCompress\r\n  LzmaUncompress\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaLib/LzmaLib.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaLib\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n\r\nCFG=LzmaLib - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaLib.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaLib.mak\" CFG=\"LzmaLib - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"LzmaLib - Win32 Release\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n!MESSAGE \"LzmaLib - Win32 Debug\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nMTL=midl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"LzmaLib - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /c\r\n# ADD CPP /nologo /Gr /MT /W3 /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"LzmaLib - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /GZ /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"LzmaLib - Win32 Release\"\r\n# Name \"LzmaLib - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaLib.def\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaLibExports.c\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaLib.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaLib.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Types.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaLib/LzmaLib.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"LzmaLib\"=.\\LzmaLib.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaLib/LzmaLibExports.c",
    "content": "/* LzmaLibExports.c -- LZMA library DLL Entry point\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <windows.h>\r\n\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r\n{\r\n  hInstance = hInstance;\r\n  dwReason = dwReason;\r\n  lpReserved = lpReserved;\r\n  return TRUE;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaLib/makefile",
    "content": "MY_STATIC_LINK=1\r\nSLIB = sLZMA.lib\r\nPROG = LZMA.dll\r\nSLIBPATH = $O\\$(SLIB)\r\n\r\nDEF_FILE = LzmaLib.def\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n\r\nLIBS = $(LIBS) oleaut32.lib\r\n\r\nLIB_OBJS = \\\r\n  $O\\LzmaLibExports.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\LzmaLib.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $(LIB_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n!include \"../../CPP/Build.mak\"\r\n\r\n$(SLIBPATH): $O $(OBJS)\r\n\tlib -out:$(SLIBPATH) $(OBJS) $(LIBS)\r\n\r\n$(LIB_OBJS): $(*B).c\r\n\t$(COMPL_O2)\r\n$(C_OBJS): ../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaLib/resource.rc",
    "content": "#include \"../../CPP/7zip/MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"LZMA library\", \"LZMA\")\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaLib.c",
    "content": "/* LzmaLib.c -- LZMA library wrapper\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"LzmaEnc.h\"\r\n#include \"LzmaDec.h\"\r\n#include \"Alloc.h\"\r\n#include \"LzmaLib.h\"\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  srcLen,\r\n  unsigned char *outProps, size_t *outPropsSize,\r\n  int level, /* 0 <= level <= 9, default = 5 */\r\n  unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */\r\n  int lc, /* 0 <= lc <= 8, default = 3  */\r\n  int lp, /* 0 <= lp <= 4, default = 0  */\r\n  int pb, /* 0 <= pb <= 4, default = 2  */\r\n  int fb,  /* 5 <= fb <= 273, default = 32 */\r\n  int numThreads /* 1 or 2, default = 2 */\r\n)\r\n{\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n  props.level = level;\r\n  props.dictSize = dictSize;\r\n  props.lc = lc;\r\n  props.lp = lp;\r\n  props.pb = pb;\r\n  props.fb = fb;\r\n  props.numThreads = numThreads;\r\n\r\n  return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,\r\n      NULL, &g_Alloc, &g_Alloc);\r\n}\r\n\r\n\r\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  *srcLen,\r\n  const unsigned char *props, size_t propsSize)\r\n{\r\n  ELzmaStatus status;\r\n  return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaLib.h",
    "content": "/* LzmaLib.h -- LZMA library interface\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMALIB_H\r\n#define __LZMALIB_H\r\n\r\n#include \"Types.h\"\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\n/*\r\nRAM requirements for LZMA:\r\n  for compression:   (dictSize * 11.5 + 6 MB) + state_size\r\n  for decompression: dictSize + state_size\r\n    state_size = (4 + (1.5 << (lc + lp))) KB\r\n    by default (lc=3, lp=0), state_size = 16 KB.\r\n\r\nLZMA properties (5 bytes) format\r\n    Offset Size  Description\r\n      0     1    lc, lp and pb in encoded form.\r\n      1     4    dictSize (little endian).\r\n*/\r\n\r\n/*\r\nLzmaCompress\r\n------------\r\n\r\noutPropsSize -\r\n     In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r\n     Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r\n\r\n  LZMA Encoder will use defult values for any parameter, if it is\r\n  -1  for any from: level, loc, lp, pb, fb, numThreads\r\n   0  for dictSize\r\n  \r\nlevel - compression level: 0 <= level <= 9;\r\n\r\n  level dictSize algo  fb\r\n    0:    16 KB   0    32\r\n    1:    64 KB   0    32\r\n    2:   256 KB   0    32\r\n    3:     1 MB   0    32\r\n    4:     4 MB   0    32\r\n    5:    16 MB   1    32\r\n    6:    32 MB   1    32\r\n    7+:   64 MB   1    64\r\n \r\n  The default value for \"level\" is 5.\r\n\r\n  algo = 0 means fast method\r\n  algo = 1 means normal method\r\n\r\ndictSize - The dictionary size in bytes. The maximum value is\r\n        128 MB = (1 << 27) bytes for 32-bit version\r\n          1 GB = (1 << 30) bytes for 64-bit version\r\n     The default value is 16 MB = (1 << 24) bytes.\r\n     It's recommended to use the dictionary that is larger than 4 KB and\r\n     that can be calculated as (1 << N) or (3 << N) sizes.\r\n\r\nlc - The number of literal context bits (high bits of previous literal).\r\n     It can be in the range from 0 to 8. The default value is 3.\r\n     Sometimes lc=4 gives the gain for big files.\r\n\r\nlp - The number of literal pos bits (low bits of current position for literals).\r\n     It can be in the range from 0 to 4. The default value is 0.\r\n     The lp switch is intended for periodical data when the period is equal to 2^lp.\r\n     For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's\r\n     better to set lc=0, if you change lp switch.\r\n\r\npb - The number of pos bits (low bits of current position).\r\n     It can be in the range from 0 to 4. The default value is 2.\r\n     The pb switch is intended for periodical data when the period is equal 2^pb.\r\n\r\nfb - Word size (the number of fast bytes).\r\n     It can be in the range from 5 to 273. The default value is 32.\r\n     Usually, a big number gives a little bit better compression ratio and\r\n     slower compression process.\r\n\r\nnumThreads - The number of thereads. 1 or 2. The default value is 2.\r\n     Fast mode (algo = 0) can use only 1 thread.\r\n\r\nOut:\r\n  destLen  - processed output size\r\nReturns:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,\r\n  unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */\r\n  int level,      /* 0 <= level <= 9, default = 5 */\r\n  unsigned dictSize,  /* default = (1 << 24) */\r\n  int lc,        /* 0 <= lc <= 8, default = 3  */\r\n  int lp,        /* 0 <= lp <= 4, default = 0  */\r\n  int pb,        /* 0 <= pb <= 4, default = 2  */\r\n  int fb,        /* 5 <= fb <= 273, default = 32 */\r\n  int numThreads /* 1 or 2, default = 2 */\r\n  );\r\n\r\n/*\r\nLzmaUncompress\r\n--------------\r\nIn:\r\n  dest     - output data\r\n  destLen  - output data size\r\n  src      - input data\r\n  srcLen   - input data size\r\nOut:\r\n  destLen  - processed output size\r\n  srcLen   - processed input size\r\nReturns:\r\n  SZ_OK                - OK\r\n  SZ_ERROR_DATA        - Data error\r\n  SZ_ERROR_MEM         - Memory allocation arror\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)\r\n*/\r\n\r\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,\r\n  const unsigned char *props, size_t propsSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaUtil/Lzma86Dec.c",
    "content": "/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder\r\n2008-04-07\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"Lzma86Dec.h\"\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../Bra.h\"\r\n#include \"../LzmaDec.h\"\r\n\r\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\r\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)\r\n{\r\n  unsigned i;\r\n  if (srcLen < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n  *unpackSize = 0;\r\n  for (i = 0; i < sizeof(UInt64); i++)\r\n    *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);\r\n  return SZ_OK;\r\n}\r\n\r\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)\r\n{\r\n  SRes res;\r\n  int useFilter;\r\n  SizeT inSizePure;\r\n  ELzmaStatus status;\r\n\r\n  if (*srcLen < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  useFilter = src[0];\r\n\r\n  if (useFilter > 1)\r\n  {\r\n    *destLen = 0;\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  }\r\n\r\n  inSizePure = *srcLen - LZMA86_HEADER_SIZE;\r\n  res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,\r\n      src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);\r\n  *srcLen = inSizePure + LZMA86_HEADER_SIZE;\r\n  if (res != SZ_OK)\r\n    return res;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(dest, *destLen, 0, &x86State, 0);\r\n  }\r\n  return SZ_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaUtil/Lzma86Dec.h",
    "content": "/* Lzma86Dec.h -- LZMA + x86 (BCJ) Filter Decoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMA86DEC_H\r\n#define __LZMA86DEC_H\r\n\r\n#include \"../Types.h\"\r\n\r\n/*\r\nLzma86_GetUnpackSize:\r\n  In:\r\n    src      - input data\r\n    srcLen   - input data size\r\n  Out:\r\n    unpackSize - size of uncompressed stream\r\n  Return code:\r\n    SZ_OK               - OK\r\n    SZ_ERROR_INPUT_EOF  - Error in headers\r\n*/\r\n\r\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);\r\n\r\n/*\r\nLzma86_Decode:\r\n  In:\r\n    dest     - output data\r\n    destLen  - output data size\r\n    src      - input data\r\n    srcLen   - input data size\r\n  Out:\r\n    destLen  - processed output size\r\n    srcLen   - processed input size\r\n  Return code:\r\n    SZ_OK           - OK\r\n    SZ_ERROR_DATA  - Data error\r\n    SZ_ERROR_MEM   - Memory allocation error\r\n    SZ_ERROR_UNSUPPORTED - unsupported file\r\n    SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer\r\n*/\r\n\r\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaUtil/Lzma86Enc.c",
    "content": "/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"Lzma86Enc.h\"\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../Bra.h\"\r\n#include \"../LzmaEnc.h\"\r\n\r\n#define SZE_OUT_OVERFLOW SZE_DATA_ERROR\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\r\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\r\n\r\nint Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r\n    int level, UInt32 dictSize, int filterMode)\r\n{\r\n  size_t outSize2 = *destLen;\r\n  Byte *filteredStream;\r\n  Bool useFilter;\r\n  int mainResult = SZ_ERROR_OUTPUT_EOF;\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n  props.level = level;\r\n  props.dictSize = dictSize;\r\n  \r\n  *destLen = 0;\r\n  if (outSize2 < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  {\r\n    int i;\r\n    UInt64 t = srcLen;\r\n    for (i = 0; i < 8; i++, t >>= 8)\r\n      dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;\r\n  }\r\n\r\n  filteredStream = 0;\r\n  useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (srcLen != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(srcLen);\r\n      if (filteredStream == 0)\r\n        return SZ_ERROR_MEM;\r\n      memcpy(filteredStream, src, srcLen);\r\n    }\r\n    {\r\n      UInt32 x86State;\r\n      x86_Convert_Init(x86State);\r\n      x86_Convert(filteredStream, srcLen, 0, &x86State, 1);\r\n    }\r\n  }\r\n\r\n  {\r\n    size_t minSize = 0;\r\n    Bool bestIsFiltered = False;\r\n\r\n    /* passes for SZ_FILTER_AUTO:\r\n        0 - BCJ + LZMA\r\n        1 - LZMA\r\n        2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.\r\n    */\r\n    int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n\r\n    int i;\r\n    for (i = 0; i < numPasses; i++)\r\n    {\r\n      size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;\r\n      size_t outPropsSize = 5;\r\n      SRes curRes;\r\n      Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);\r\n      if (curModeIsFiltered && !bestIsFiltered)\r\n        break;\r\n      if (useFilter && i == 0)\r\n        curModeIsFiltered = True;\r\n      \r\n      curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,\r\n          curModeIsFiltered ? filteredStream : src, srcLen,\r\n          &props, dest + 1, &outPropsSize, 0,\r\n          NULL, &g_Alloc, &g_Alloc);\r\n      \r\n      if (curRes != SZ_ERROR_OUTPUT_EOF)\r\n      {\r\n        if (curRes != SZ_OK)\r\n        {\r\n          mainResult = curRes;\r\n          break;\r\n        }\r\n        if (outSizeProcessed <= minSize || mainResult != SZ_OK)\r\n        {\r\n          minSize = outSizeProcessed;\r\n          bestIsFiltered = curModeIsFiltered;\r\n          mainResult = SZ_OK;\r\n        }\r\n      }\r\n    }\r\n    dest[0] = (bestIsFiltered ? 1 : 0);\r\n    *destLen = LZMA86_HEADER_SIZE + minSize;\r\n  }\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaUtil/Lzma86Enc.h",
    "content": "/* Lzma86Enc.h -- LZMA + x86 (BCJ) Filter Encoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMA86ENC_H\r\n#define __LZMA86ENC_H\r\n\r\n#include \"../Types.h\"\r\n\r\n/*\r\nIt's an example for LZMA + x86 Filter use.\r\nYou can use .lzma86 extension, if you write that stream to file.\r\n.lzma86 header adds one additional byte to standard .lzma header.\r\n.lzma86 header (14 bytes):\r\n  Offset Size  Description\r\n    0     1    = 0 - no filter,\r\n               = 1 - x86 filter\r\n    1     1    lc, lp and pb in encoded form\r\n    2     4    dictSize (little endian)\r\n    6     8    uncompressed size (little endian)\r\n\r\n\r\nLzma86_Encode\r\n-------------\r\nlevel - compression level: 0 <= level <= 9, the default value for \"level\" is 5.\r\n\r\n\r\ndictSize - The dictionary size in bytes. The maximum value is\r\n        128 MB = (1 << 27) bytes for 32-bit version\r\n          1 GB = (1 << 30) bytes for 64-bit version\r\n     The default value is 16 MB = (1 << 24) bytes, for level = 5.\r\n     It's recommended to use the dictionary that is larger than 4 KB and\r\n     that can be calculated as (1 << N) or (3 << N) sizes.\r\n     For better compression ratio dictSize must be >= inSize.\r\n\r\nfilterMode:\r\n    SZ_FILTER_NO   - no Filter\r\n    SZ_FILTER_YES  - x86 Filter\r\n    SZ_FILTER_AUTO - it tries both alternatives to select best.\r\n              Encoder will use 2 or 3 passes:\r\n              2 passes when FILTER_NO provides better compression.\r\n              3 passes when FILTER_YES provides better compression.\r\n\r\nLzma86Encode allocates Data with MyAlloc functions.\r\nRAM Requirements for compressing:\r\n  RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize\r\n      filterMode     FilterBlockSize\r\n     SZ_FILTER_NO         0\r\n     SZ_FILTER_YES      inSize\r\n     SZ_FILTER_AUTO     inSize\r\n\r\n\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nenum ESzFilterMode\r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nSRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r\n    int level, UInt32 dictSize, int filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaUtil/LzmaUtil.c",
    "content": "/* LzmaUtil.c -- Test application for LZMA compression\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#define _CRT_SECURE_NO_WARNINGS\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../7zFile.h\"\r\n#include \"../7zVersion.h\"\r\n#include \"../LzmaDec.h\"\r\n#include \"../LzmaEnc.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\nconst char *kDataErrorMessage = \"Data error\";\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nvoid PrintHelp(char *buffer)\r\n{\r\n  strcat(buffer, \"\\nLZMA Utility \" MY_VERSION_COPYRIGHT_DATE \"\\n\"\r\n      \"\\nUsage:  lzma <e|d> inputFile outputFile\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\");\r\n}\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  strcat(buffer, \"\\nError: \");\r\n  strcat(buffer, message);\r\n  strcat(buffer, \"\\n\");\r\n  return 1;\r\n}\r\n\r\nint PrintErrorNumber(char *buffer, SRes val)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError code: %x\\n\", (unsigned)val);\r\n  return 1;\r\n}\r\n\r\nint PrintUserError(char *buffer)\r\n{\r\n  return PrintError(buffer, \"Incorrect command\");\r\n}\r\n\r\n#define IN_BUF_SIZE (1 << 16)\r\n#define OUT_BUF_SIZE (1 << 16)\r\n\r\nstatic SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    UInt64 unpackSize)\r\n{\r\n  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);\r\n  Byte inBuf[IN_BUF_SIZE];\r\n  Byte outBuf[OUT_BUF_SIZE];\r\n  size_t inPos = 0, inSize = 0, outPos = 0;\r\n  LzmaDec_Init(state);\r\n  for (;;)\r\n  {\r\n    if (inPos == inSize)\r\n    {\r\n      inSize = IN_BUF_SIZE;\r\n      RINOK(inStream->Read(inStream, inBuf, &inSize));\r\n      inPos = 0;\r\n    }\r\n    {\r\n      SRes res;\r\n      SizeT inProcessed = inSize - inPos;\r\n      SizeT outProcessed = OUT_BUF_SIZE - outPos;\r\n      ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\r\n      ELzmaStatus status;\r\n      if (thereIsSize && outProcessed > unpackSize)\r\n      {\r\n        outProcessed = (SizeT)unpackSize;\r\n        finishMode = LZMA_FINISH_END;\r\n      }\r\n      \r\n      res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,\r\n        inBuf + inPos, &inProcessed, finishMode, &status);\r\n      inPos += inProcessed;\r\n      outPos += outProcessed;\r\n      unpackSize -= outProcessed;\r\n      \r\n      if (outStream)\r\n        if (outStream->Write(outStream, outBuf, outPos) != outPos)\r\n          return SZ_ERROR_WRITE;\r\n        \r\n      outPos = 0;\r\n      \r\n      if (res != SZ_OK || thereIsSize && unpackSize == 0)\r\n        return res;\r\n      \r\n      if (inProcessed == 0 && outProcessed == 0)\r\n      {\r\n        if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)\r\n          return SZ_ERROR_DATA;\r\n        return res;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)\r\n{\r\n  UInt64 unpackSize;\r\n  int i;\r\n  SRes res = 0;\r\n\r\n  CLzmaDec state;\r\n\r\n  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */\r\n  unsigned char header[LZMA_PROPS_SIZE + 8];\r\n\r\n  /* Read and parse header */\r\n\r\n  RINOK(SeqInStream_Read(inStream, header, sizeof(header)));\r\n\r\n  unpackSize = 0;\r\n  for (i = 0; i < 8; i++)\r\n    unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);\r\n\r\n  LzmaDec_Construct(&state);\r\n  RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));\r\n  res = Decode2(&state, outStream, inStream, unpackSize);\r\n  LzmaDec_Free(&state, &g_Alloc);\r\n  return res;\r\n}\r\n\r\nstatic SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)\r\n{\r\n  CLzmaEncHandle enc;\r\n  SRes res;\r\n  CLzmaEncProps props;\r\n\r\n  rs = rs;\r\n\r\n  enc = LzmaEnc_Create(&g_Alloc);\r\n  if (enc == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  LzmaEncProps_Init(&props);\r\n  res = LzmaEnc_SetProps(enc, &props);\r\n\r\n  if (res == SZ_OK)\r\n  {\r\n    Byte header[LZMA_PROPS_SIZE + 8];\r\n    size_t headerSize = LZMA_PROPS_SIZE;\r\n    int i;\r\n\r\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r\n    for (i = 0; i < 8; i++)\r\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r\n    if (outStream->Write(outStream, header, headerSize) != headerSize)\r\n      res = SZ_ERROR_WRITE;\r\n    else\r\n    {\r\n      if (res == SZ_OK)\r\n        res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);\r\n    }\r\n  }\r\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  CFileSeqInStream inStream;\r\n  CFileOutStream outStream;\r\n  char c;\r\n  int res;\r\n  int encodeMode;\r\n  Bool useOutFile = False;\r\n\r\n  FileSeqInStream_CreateVTable(&inStream);\r\n  File_Construct(&inStream.file);\r\n\r\n  FileOutStream_CreateVTable(&outStream);\r\n  File_Construct(&outStream.file);\r\n\r\n  if (numArgs == 1)\r\n  {\r\n    PrintHelp(rs);\r\n    return 0;\r\n  }\r\n\r\n  if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1)\r\n    return PrintUserError(rs);\r\n\r\n  c = args[1][0];\r\n  encodeMode = (c == 'e' || c == 'E');\r\n  if (!encodeMode && c != 'd' && c != 'D')\r\n    return PrintUserError(rs);\r\n\r\n  {\r\n    size_t t4 = sizeof(UInt32);\r\n    size_t t8 = sizeof(UInt64);\r\n    if (t4 != 4 || t8 != 8)\r\n      return PrintError(rs, \"Incorrect UInt32 or UInt64\");\r\n  }\r\n\r\n  if (InFile_Open(&inStream.file, args[2]) != 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 3)\r\n  {\r\n    useOutFile = True;\r\n    if (OutFile_Open(&outStream.file, args[3]) != 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n  else if (encodeMode)\r\n    PrintUserError(rs);\r\n\r\n  if (encodeMode)\r\n  {\r\n    UInt64 fileSize;\r\n    File_GetLength(&inStream.file, &fileSize);\r\n    res = Encode(&outStream.s, &inStream.s, fileSize, rs);\r\n  }\r\n  else\r\n  {\r\n    res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL);\r\n  }\r\n\r\n  if (useOutFile)\r\n    File_Close(&outStream.file);\r\n  File_Close(&inStream.file);\r\n\r\n  if (res != SZ_OK)\r\n  {\r\n    if (res == SZ_ERROR_MEM)\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    else if (res == SZ_ERROR_DATA)\r\n      return PrintError(rs, kDataErrorMessage);\r\n    else if (res == SZ_ERROR_WRITE)\r\n      return PrintError(rs, kCantWriteMessage);\r\n    else if (res == SZ_ERROR_READ)\r\n      return PrintError(rs, kCantReadMessage);\r\n    return PrintErrorNumber(rs, res);\r\n  }\r\n  return 0;\r\n}\r\n\r\nint MY_CDECL main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaUtil/LzmaUtil.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaUtil\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=LzmaUtil - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaUtil.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaUtil.mak\" CFG=\"LzmaUtil - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"LzmaUtil - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"LzmaUtil - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"LzmaUtil - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\util\\lzmac.exe\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"LzmaUtil - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /GZ /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\util\\lzmac.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"LzmaUtil - Win32 Release\"\r\n# Name \"LzmaUtil - Win32 Debug\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zFile.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zFile.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zStream.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zVersion.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\CpuArch.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaUtil.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Types.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaUtil/LzmaUtil.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"LzmaUtil\"=.\\LzmaUtil.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaUtil/makefile",
    "content": "MY_STATIC_LINK=1\r\nPROG = LZMAc.exe\r\n\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n\r\nLIB_OBJS = \\\r\n  $O\\LzmaUtil.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\7zFile.obj \\\r\n  $O\\7zStream.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $(LIB_OBJS) \\\r\n  $(C_OBJS) \\\r\n\r\n!include \"../../CPP/Build.mak\"\r\n\r\n$(LIB_OBJS): $(*B).c\r\n\t$(COMPL_O2)\r\n$(C_OBJS): ../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/LzmaUtil/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++\r\nLIB =\r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = \\\r\n  LzmaUtil.o \\\r\n  Alloc.o \\\r\n  LzFind.o \\\r\n  LzmaDec.o \\\r\n  LzmaEnc.o \\\r\n  7zFile.o \\\r\n  7zStream.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r\n\r\nLzmaUtil.o: LzmaUtil.c\r\n\t$(CXX) $(CFLAGS) LzmaUtil.c\r\n\r\nAlloc.o: ../Alloc.c\r\n\t$(CXX) $(CFLAGS) ../Alloc.c\r\n\r\nLzFind.o: ../LzFind.c\r\n\t$(CXX) $(CFLAGS) ../LzFind.c\r\n\r\nLzmaDec.o: ../LzmaDec.c\r\n\t$(CXX) $(CFLAGS) ../LzmaDec.c\r\n\r\nLzmaEnc.o: ../LzmaEnc.c\r\n\t$(CXX) $(CFLAGS) ../LzmaEnc.c\r\n\r\n7zFile.o: ../7zFile.c\r\n\t$(CXX) $(CFLAGS) ../7zFile.c\r\n\r\n7zStream.o: ../7zStream.c\r\n\t$(CXX) $(CFLAGS) ../7zStream.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Threads.c",
    "content": "/* Threads.c -- multithreading library\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"Threads.h\"\r\n#include <process.h>\r\n\r\nstatic WRes GetError()\r\n{\r\n  DWORD res = GetLastError();\r\n  return (res) ? (WRes)(res) : 1;\r\n}\r\n\r\nWRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }\r\nWRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }\r\n\r\nstatic WRes MyCloseHandle(HANDLE *h)\r\n{\r\n  if (*h != NULL)\r\n    if (!CloseHandle(*h))\r\n      return GetError();\r\n  *h = NULL;\r\n  return 0;\r\n}\r\n\r\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n{\r\n  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r\n  thread->handle =\r\n    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */\r\n    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);\r\n    /* maybe we must use errno here, but probably GetLastError() is also OK. */\r\n  return HandleToWRes(thread->handle);\r\n}\r\n\r\nWRes WaitObject(HANDLE h)\r\n{\r\n  return (WRes)WaitForSingleObject(h, INFINITE);\r\n}\r\n\r\nWRes Thread_Wait(CThread *thread)\r\n{\r\n  if (thread->handle == NULL)\r\n    return 1;\r\n  return WaitObject(thread->handle);\r\n}\r\n\r\nWRes Thread_Close(CThread *thread)\r\n{\r\n  return MyCloseHandle(&thread->handle);\r\n}\r\n\r\nWRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)\r\n{\r\n  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);\r\n  return HandleToWRes(p->handle);\r\n}\r\n\r\nWRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, TRUE, initialSignaled); }\r\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)\r\n  { return ManualResetEvent_Create(p, 0); }\r\n\r\nWRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, FALSE, initialSignaled); }\r\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)\r\n  { return AutoResetEvent_Create(p, 0); }\r\n\r\nWRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }\r\nWRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }\r\nWRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }\r\nWRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }\r\n\r\n\r\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)\r\n{\r\n  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);\r\n  return HandleToWRes(p->handle);\r\n}\r\n\r\nWRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)\r\n{\r\n  return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));\r\n}\r\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)\r\n{\r\n  return Semaphore_Release(p, (LONG)releaseCount, NULL);\r\n}\r\nWRes Semaphore_Release1(CSemaphore *p)\r\n{\r\n  return Semaphore_ReleaseN(p, 1);\r\n}\r\n\r\nWRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }\r\nWRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }\r\n\r\nWRes CriticalSection_Init(CCriticalSection *p)\r\n{\r\n  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\r\n  __try\r\n  {\r\n    InitializeCriticalSection(p);\r\n    /* InitializeCriticalSectionAndSpinCount(p, 0); */\r\n  }\r\n  __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }\r\n  return 0;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Threads.h",
    "content": "/* Threads.h -- multithreading library\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_THRESDS_H\r\n#define __7Z_THRESDS_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _CThread\r\n{\r\n  HANDLE handle;\r\n} CThread;\r\n\r\n#define Thread_Construct(thread) (thread)->handle = NULL\r\n#define Thread_WasCreated(thread) ((thread)->handle != NULL)\r\n \r\ntypedef unsigned THREAD_FUNC_RET_TYPE;\r\n#define THREAD_FUNC_CALL_TYPE MY_STD_CALL\r\n#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r\n\r\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);\r\nWRes Thread_Wait(CThread *thread);\r\nWRes Thread_Close(CThread *thread);\r\n\r\ntypedef struct _CEvent\r\n{\r\n  HANDLE handle;\r\n} CEvent;\r\n\r\ntypedef CEvent CAutoResetEvent;\r\ntypedef CEvent CManualResetEvent;\r\n\r\n#define Event_Construct(event) (event)->handle = NULL\r\n#define Event_IsCreated(event) ((event)->handle != NULL)\r\n\r\nWRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);\r\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);\r\nWRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);\r\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);\r\nWRes Event_Set(CEvent *event);\r\nWRes Event_Reset(CEvent *event);\r\nWRes Event_Wait(CEvent *event);\r\nWRes Event_Close(CEvent *event);\r\n\r\n\r\ntypedef struct _CSemaphore\r\n{\r\n  HANDLE handle;\r\n} CSemaphore;\r\n\r\n#define Semaphore_Construct(p) (p)->handle = NULL\r\n\r\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);\r\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\r\nWRes Semaphore_Release1(CSemaphore *p);\r\nWRes Semaphore_Wait(CSemaphore *p);\r\nWRes Semaphore_Close(CSemaphore *p);\r\n\r\n\r\ntypedef CRITICAL_SECTION CCriticalSection;\r\n\r\nWRes CriticalSection_Init(CCriticalSection *p);\r\n#define CriticalSection_Delete(p) DeleteCriticalSection(p)\r\n#define CriticalSection_Enter(p) EnterCriticalSection(p)\r\n#define CriticalSection_Leave(p) LeaveCriticalSection(p)\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/Types.h",
    "content": "/* Types.h -- Basic types\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_TYPES_H\r\n#define __7Z_TYPES_H\r\n\r\n#include <stddef.h>\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#define SZ_OK 0\r\n\r\n#define SZ_ERROR_DATA 1\r\n#define SZ_ERROR_MEM 2\r\n#define SZ_ERROR_CRC 3\r\n#define SZ_ERROR_UNSUPPORTED 4\r\n#define SZ_ERROR_PARAM 5\r\n#define SZ_ERROR_INPUT_EOF 6\r\n#define SZ_ERROR_OUTPUT_EOF 7\r\n#define SZ_ERROR_READ 8\r\n#define SZ_ERROR_WRITE 9\r\n#define SZ_ERROR_PROGRESS 10\r\n#define SZ_ERROR_FAIL 11\r\n#define SZ_ERROR_THREAD 12\r\n\r\n#define SZ_ERROR_ARCHIVE 16\r\n#define SZ_ERROR_NO_ARCHIVE 17\r\n\r\ntypedef int SRes;\r\n\r\n#ifdef _WIN32\r\ntypedef DWORD WRes;\r\n#else\r\ntypedef int WRes;\r\n#endif\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r\n#endif\r\n\r\ntypedef unsigned char Byte;\r\ntypedef short Int16;\r\ntypedef unsigned short UInt16;\r\n\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef long Int32;\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef int Int32;\r\ntypedef unsigned int UInt32;\r\n#endif\r\n\r\n#ifdef _SZ_NO_INT_64\r\n\r\n/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r\n   NOTES: Some code will work incorrectly in that case! */\r\n\r\ntypedef long Int64;\r\ntypedef unsigned long UInt64;\r\n\r\n#else\r\n\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef __int64 Int64;\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef long long int Int64;\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\ntypedef size_t SizeT;\r\n#endif\r\n\r\ntypedef int Bool;\r\n#define True 1\r\n#define False 0\r\n\r\n\r\n#ifdef _MSC_VER\r\n\r\n#if _MSC_VER >= 1300\r\n#define MY_NO_INLINE __declspec(noinline)\r\n#else\r\n#define MY_NO_INLINE\r\n#endif\r\n\r\n#define MY_CDECL __cdecl\r\n#define MY_STD_CALL __stdcall\r\n#define MY_FAST_CALL MY_NO_INLINE __fastcall\r\n\r\n#else\r\n\r\n#define MY_CDECL\r\n#define MY_STD_CALL\r\n#define MY_FAST_CALL\r\n\r\n#endif\r\n\r\n\r\n/* The following interfaces use first parameter as pointer to structure */\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) < input(*size)) is allowed */\r\n} ISeqInStream;\r\n\r\n/* it can return SZ_ERROR_INPUT_EOF */\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r\n\r\ntypedef struct\r\n{\r\n  size_t (*Write)(void *p, const void *buf, size_t size);\r\n    /* Returns: result - the number of actually written bytes.\r\n       (result < size) means error */\r\n} ISeqOutStream;\r\n\r\ntypedef enum\r\n{\r\n  SZ_SEEK_SET = 0,\r\n  SZ_SEEK_CUR = 1,\r\n  SZ_SEEK_END = 2\r\n} ESzSeek;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ISeekInStream;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Look)(void *p, void **buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) > input(*size)) is not allowed\r\n       (output(*size) < input(*size)) is allowed */\r\n  SRes (*Skip)(void *p, size_t offset);\r\n    /* offset must be <= output(*size) of Look */\r\n\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ILookInStream;\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r\n\r\n/* reads via ILookInStream::Read */\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r\n\r\n#define LookToRead_BUF_SIZE (1 << 14)\r\n\r\ntypedef struct\r\n{\r\n  ILookInStream s;\r\n  ISeekInStream *realStream;\r\n  size_t pos;\r\n  size_t size;\r\n  Byte buf[LookToRead_BUF_SIZE];\r\n} CLookToRead;\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r\nvoid LookToRead_Init(CLookToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToLook;\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToRead;\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r\n    /* Returns: result. (result != SZ_OK) means break.\r\n       Value (UInt64)(Int64)-1 for size means unknown value. */\r\n} ICompressProgress;\r\n\r\ntypedef struct\r\n{\r\n  void *(*Alloc)(void *p, size_t size);\r\n  void (*Free)(void *p, void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\n#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r\n#define IAlloc_Free(p, a) (p)->Free((p), a)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/sqlzma.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\n#include makefile.gcc\nCFLAGS = -c -O2 -Wall -pedantic -D _LZMA_PROB32 -D _SZ_NO_INT_64\n\nifdef KDir\ninclude kmod.mk\nendif\n\nifdef UseDebugFlags\nDebugFlags = -O0 -g -UNDEBUG\nendif\nCFLAGS += -DNDEBUG ${DebugFlags}\nTgt = libunlzma.a libunlzma_r.a\n\nall: ${Tgt}\n\n%_r.c: %.c\n\tln $< $@\n# -pthread\n%_r.o: CFLAGS += -D_REENTRANT -include pthread.h\n\nuncomp.o uncomp_r.o: CFLAGS += -I${Sqlzma}\nuncomp.o: uncomp.c ${Sqlzma}/sqlzma.h\n\nlibunlzma.a: uncomp.o LzmaDec.o Alloc.o \n\t${AR} cr $@ $^\nlibunlzma_r.a: uncomp_r.o LzmaDec_r.o Alloc_r.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) ${Tgt} uncomp.o uncomp_r.o LzmaDec_r.o LzmaDec.o  \\\n\tAlloc.o Alloc_r.o *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/C/uncomp.c",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $ */\n\n/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */\n\n#ifndef __KERNEL__\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <assert.h>\n#include <pthread.h>\n#define unlikely(x)\t\t__builtin_expect(!!(x), 0)\n#define BUG_ON(x)\t\tassert(!(x))\n/* sqlzma buffers are always larger than a page. true? */\n#define kmalloc(sz,gfp)\t\tmalloc(sz)\n#define kfree(p)\t\tfree(p)\n#define zlib_inflate(s, f)\tinflate(s, f)\n#define zlib_inflateInit(s)\tinflateInit(s)\n#define zlib_inflateReset(s)\tinflateReset(s)\n#define zlib_inflateEnd(s)\tinflateEnd(s)\n#else\n#include <linux/init.h>\n#include <linux/module.h>\n#include <linux/kernel.h>\n#include <linux/vmalloc.h>\n#ifndef WARN_ON_ONCE\n#define WARN_ON_ONCE(b)\tWARN_ON(b)\n#endif\n#endif /* __KERNEL__ */\n\n#include \"sqlzma.h\"\n#include \"LzmaDec.h\"\n#include \"Alloc.h\"\n\n\n#define LZMA_BASE_SIZE 1846\n#define LZMA_LIT_SIZE 768\n#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\n\n\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\n\nstatic int LzmaUncompress(struct sqlzma_un *un)\n{\n\tint err, i;\n\tSizeT outSize, srclen;\n\t/* it's about 24-80 bytes structure, if int is 32-bit */\n\tCLzmaDec state;\n\tCLzmaProps props;\n\tunsigned char *dst, *src, a[8];\n\tstruct sized_buf *sbuf;\n\tELzmaStatus status;\n\n\t/* Decode LZMA properties and allocate memory */\n\terr = -EINVAL;\n\tsrc = (void *)un->un_cmbuf;\n\tsrc += LZMA_PROPS_SIZE;\n\ti = LzmaProps_GetNumProbs(&props);\n\tif (unlikely(i <= 0))\n\t\ti = 1;\n\ti *= sizeof(CLzmaProb);\n\tsbuf = un->un_a + SQUN_PROB;\n\tif (unlikely(sbuf->sz < i)) {\n\t\tif (sbuf->buf && sbuf->buf != un->un_prob)\n\t\t\tkfree(sbuf->buf);\n#ifdef __KERNEL__\n\t\tprintk(\"%s:%d: %d --> %d\\n\", __func__, __LINE__, sbuf->sz, i);\n#else\n\t\tprintf(\"%d --> %d\\n\", sbuf->sz, i);\n#endif\n\t\terr = -ENOMEM;\n\t\tsbuf->sz = 0;\n\t\tsbuf->buf = kmalloc(i, GFP_ATOMIC);\n\t\tif (unlikely(!sbuf->buf))\n\t\t\tgoto out;\n\t\tsbuf->sz = i;\n\t}\n\tstate.probs = (void *)sbuf->buf;\n\n\t/* Read uncompressed size */\n\tmemcpy(a, src, sizeof(a));\n\tsrc += sizeof(a);\n\toutSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);\n\n\terr = -EINVAL;\n\tdst = un->un_resbuf;\n\tif (unlikely(!dst || outSize > un->un_reslen))\n\t\tgoto out;\n\tun->un_reslen = outSize;\n\tsrclen = un->un_cmlen - (src - un->un_cmbuf);\n\n\t/* Decompress */\n/*\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\n    ELzmaStatus *status, ISzAlloc *alloc)\n*/\n\n\n\terr = LzmaDecode(dst, &outSize, src, &srclen, (void *)un->un_cmbuf, LZMA_PROPS_SIZE,  LZMA_FINISH_END, &status, &g_Alloc);\n\n\n\tif (unlikely(err!=SZ_OK))\n\t\terr = -EINVAL;\n\n out:\n#ifndef __KERNEL__\n\tif (err)\n\t\tfprintf(stderr, \"err %d\\n\", err);\n#endif\n\treturn err;\n}\n\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst)\n{\n\tint err, by_lzma = 1;\n\tif (un->un_lzma && is_lzma(*src->buf)) {\n\t\tun->un_cmbuf = src->buf;\n\t\tun->un_cmlen = src->sz;\n\t\tun->un_resbuf = dst->buf;\n\t\tun->un_reslen = dst->sz;\n\n\t\t/* this library is thread-safe */\n\t\terr = LzmaUncompress(un);\n\t\tgoto out;\n\t}\n\n\tby_lzma = 0;\n\terr = zlib_inflateReset(&un->un_stream);\n\tif (unlikely(err != Z_OK))\n\t\tgoto out;\n\tun->un_stream.next_in = src->buf;\n\tun->un_stream.avail_in = src->sz;\n\tun->un_stream.next_out = dst->buf;\n\tun->un_stream.avail_out = dst->sz;\n\terr = zlib_inflate(&un->un_stream, Z_FINISH);\n\tif (err == Z_STREAM_END)\n\t\terr = 0;\n\n out:\n\tif (unlikely(err)) {\n#ifdef __KERNEL__\n\t\tWARN_ON_ONCE(1);\n#else\n\t\tchar a[64] = \"ZLIB \";\n\t\tif (by_lzma) {\n\t\t\tstrcpy(a, \"LZMA \");\n#ifdef _REENTRANT\n\t\t\tstrerror_r(err, a + 5, sizeof(a) - 5);\n#else\n\t\t\tstrncat(a, strerror(err), sizeof(a) - 5);\n#endif\n\t\t} else\n\t\t\tstrncat(a, zError(err), sizeof(a) - 5);\n\t\tfprintf(stderr, \"%s: %.*s\\n\", __func__, sizeof(a), a);\n#endif\n\t}\n\treturn err;\n}\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)\n{\n\tint err;\n\n\terr = -ENOMEM;\n\tun->un_lzma = do_lzma;\n\tmemset(un->un_a, 0, sizeof(un->un_a));\n\tun->un_a[SQUN_PROB].buf = un->un_prob;\n\tun->un_a[SQUN_PROB].sz = sizeof(un->un_prob);\n\tif (res_sz) {\n\t\tun->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);\n\t\tif (unlikely(!un->un_a[SQUN_RESULT].buf))\n\t\t\treturn err;\n\t\tun->un_a[SQUN_RESULT].sz = res_sz;\n\t}\n\n\tun->un_stream.next_in = NULL;\n\tun->un_stream.avail_in = 0;\n#ifdef __KERNEL__\n\tun->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(),\n\t\t\t\t\t  GFP_KERNEL);\n\tif (unlikely(!un->un_stream.workspace))\n\t\treturn err;\n#else\n\tun->un_stream.opaque = NULL;\n\tun->un_stream.zalloc = Z_NULL;\n\tun->un_stream.zfree = Z_NULL;\n#endif\n\terr = zlib_inflateInit(&un->un_stream);\n\tif (unlikely(err == Z_MEM_ERROR))\n\t\treturn -ENOMEM;\n\tBUG_ON(err);\n\treturn err;\n}\n\nvoid sqlzma_fin(struct sqlzma_un *un)\n{\n\tint i;\n\tfor (i = 0; i < SQUN_LAST; i++)\n\t\tif (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)\n\t\t\tkfree(un->un_a[i].buf);\n\tBUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);\n}\n\n#ifdef __KERNEL__\nEXPORT_SYMBOL(sqlzma_un);\nEXPORT_SYMBOL(sqlzma_init);\nEXPORT_SYMBOL(sqlzma_fin);\n\n#if 0\nstatic int __init sqlzma_init(void)\n{\n\treturn 0;\n}\n\nstatic void __exit sqlzma_exit(void)\n{\n}\n\nmodule_init(sqlzma_init);\nmodule_exit(sqlzma_exit);\n#endif\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Junjiro Okajima <sfjro at users dot sf dot net>\");\nMODULE_VERSION(\"$Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $\");\nMODULE_DESCRIPTION(\"LZMA uncompress for squashfs. \"\n\t\t   \"Some functions for squashfs to support LZMA and \"\n\t\t   \"a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.\");\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zCompressionMode.cpp",
    "content": "// CompressionMethod.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zCompressionMode.h",
    "content": "// 7zCompressionMode.h\r\n\r\n#ifndef __7Z_COMPRESSION_MODE_H\r\n#define __7Z_COMPRESSION_MODE_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CMethodFull: public CMethod\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBind\r\n{\r\n  UInt32 InCoder;\r\n  UInt32 InStream;\r\n  UInt32 OutCoder;\r\n  UInt32 OutStream;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  CObjectVector<CMethodFull> Methods;\r\n  CRecordVector<CBind> Binds;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }\r\n  CCompressionMethodMode(): PasswordIsDefined(false)\r\n      #ifdef COMPRESS_MT\r\n      , NumThreads(1)\r\n      #endif\r\n  {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zDecode.cpp",
    "content": "// 7zDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/LockedStream.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertFolderItemInfoToBindInfo(const CFolder &folder,\r\n    CBindInfoEx &bindInfo)\r\n{\r\n  bindInfo.Clear();\r\n  int i;\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    NCoderMixer::CBindPair bindPair;\r\n    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;\r\n    bindInfo.BindPairs.Add(bindPair);\r\n  }\r\n  UInt32 outStreamIndex = 0;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    const CCoderInfo &coderInfo = folder.Coders[i];\r\n    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;\r\n    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    bindInfo.Coders.Add(coderStreamsInfo);\r\n    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);\r\n    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)\r\n      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)\r\n        bindInfo.OutStreams.Add(outStreamIndex);\r\n  }\r\n  for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);\r\n}\r\n\r\nstatic bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1,\r\n    const NCoderMixer::CCoderStreamsInfo &a2)\r\n{\r\n  return (a1.NumInStreams == a2.NumInStreams) &&\r\n    (a1.NumOutStreams == a2.NumOutStreams);\r\n}\r\n\r\nstatic bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)\r\n{\r\n  return (a1.InIndex == a2.InIndex) &&\r\n    (a1.OutIndex == a2.OutIndex);\r\n}\r\n\r\nstatic bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)\r\n{\r\n  if (a1.Coders.Size() != a2.Coders.Size())\r\n    return false;\r\n  int i;\r\n  for (i = 0; i < a1.Coders.Size(); i++)\r\n    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))\r\n      return false;\r\n  if (a1.BindPairs.Size() != a2.BindPairs.Size())\r\n    return false;\r\n  for (i = 0; i < a1.BindPairs.Size(); i++)\r\n    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))\r\n      return false;\r\n  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)\r\n    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])\r\n      return false;\r\n  if (a1.InStreams.Size() != a2.InStreams.Size())\r\n    return false;\r\n  if (a1.OutStreams.Size() != a2.OutStreams.Size())\r\n    return false;\r\n  return true;\r\n}\r\n\r\nCDecoder::CDecoder(bool multiThread)\r\n{\r\n  #ifndef _ST_MODE\r\n  multiThread = true;\r\n  #endif\r\n  _multiThread = multiThread;\r\n  _bindInfoExPrevIsDefined = false;\r\n}\r\n\r\nHRESULT CDecoder::Decode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    UInt64 startPos,\r\n    const UInt64 *packSizes,\r\n    const CFolder &folderInfo,\r\n    ISequentialOutStream *outStream,\r\n    ICompressProgressInfo *compressProgress\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    #ifdef COMPRESS_MT\r\n    , bool mtMode, UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  if (!folderInfo.CheckStructure())\r\n    return E_NOTIMPL;\r\n  #ifndef _NO_CRYPTO\r\n  passwordIsDefined = false;\r\n  #endif\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;\r\n  \r\n  CLockedInStream lockedInStream;\r\n  lockedInStream.Init(inStream);\r\n  \r\n  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)\r\n  {\r\n    CLockedSequentialInStreamImp *lockedStreamImpSpec = new\r\n        CLockedSequentialInStreamImp;\r\n    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;\r\n    lockedStreamImpSpec->Init(&lockedInStream, startPos);\r\n    startPos += packSizes[j];\r\n    \r\n    CLimitedSequentialInStream *streamSpec = new\r\n        CLimitedSequentialInStream;\r\n    CMyComPtr<ISequentialInStream> inStream = streamSpec;\r\n    streamSpec->SetStream(lockedStreamImp);\r\n    streamSpec->Init(packSizes[j]);\r\n    inStreams.Add(inStream);\r\n  }\r\n  \r\n  int numCoders = folderInfo.Coders.Size();\r\n  \r\n  CBindInfoEx bindInfo;\r\n  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);\r\n  bool createNewCoders;\r\n  if (!_bindInfoExPrevIsDefined)\r\n    createNewCoders = true;\r\n  else\r\n    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);\r\n  if (createNewCoders)\r\n  {\r\n    int i;\r\n    _decoders.Clear();\r\n    // _decoders2.Clear();\r\n    \r\n    _mixerCoder.Release();\r\n\r\n    if (_multiThread)\r\n    {\r\n      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;\r\n      _mixerCoder = _mixerCoderMTSpec;\r\n      _mixerCoderCommon = _mixerCoderMTSpec;\r\n    }\r\n    else\r\n    {\r\n      #ifdef _ST_MODE\r\n      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;\r\n      _mixerCoder = _mixerCoderSTSpec;\r\n      _mixerCoderCommon = _mixerCoderSTSpec;\r\n      #endif\r\n    }\r\n    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));\r\n    \r\n    for (i = 0; i < numCoders; i++)\r\n    {\r\n      const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n\r\n  \r\n      CMyComPtr<ICompressCoder> decoder;\r\n      CMyComPtr<ICompressCoder2> decoder2;\r\n      RINOK(CreateCoder(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          coderInfo.MethodID, decoder, decoder2, false));\r\n      CMyComPtr<IUnknown> decoderUnknown;\r\n      if (coderInfo.IsSimpleCoder())\r\n      {\r\n        if (decoder == 0)\r\n          return E_NOTIMPL;\r\n\r\n        decoderUnknown = (IUnknown *)decoder;\r\n        \r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder(decoder);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder(decoder, false);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        if (decoder2 == 0)\r\n          return E_NOTIMPL;\r\n        decoderUnknown = (IUnknown *)decoder2;\r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder2(decoder2);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder2(decoder2, false);\r\n        #endif\r\n      }\r\n      _decoders.Add(decoderUnknown);\r\n      #ifdef EXTERNAL_CODECS\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n      }\r\n      #endif\r\n    }\r\n    _bindInfoExPrev = bindInfo;\r\n    _bindInfoExPrevIsDefined = true;\r\n  }\r\n  int i;\r\n  _mixerCoderCommon->ReInit();\r\n  \r\n  UInt32 packStreamIndex = 0, unpackStreamIndex = 0;\r\n  UInt32 coderIndex = 0;\r\n  // UInt32 coder2Index = 0;\r\n  \r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];\r\n    \r\n    {\r\n      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n      if (setDecoderProperties)\r\n      {\r\n        const CByteBuffer &props = coderInfo.Props;\r\n        size_t size = props.GetCapacity();\r\n        if (size > 0xFFFFFFFF)\r\n          return E_NOTIMPL;\r\n        if (size > 0)\r\n        {\r\n          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)props, (UInt32)size));\r\n        }\r\n      }\r\n    }\r\n\r\n    #ifdef COMPRESS_MT\r\n    if (mtMode)\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(numThreads));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    {\r\n      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n      if (cryptoSetPassword)\r\n      {\r\n        if (getTextPassword == 0)\r\n          return E_FAIL;\r\n        CMyComBSTR passwordBSTR;\r\n        RINOK(getTextPassword->CryptoGetTextPassword(&passwordBSTR));\r\n        CByteBuffer buffer;\r\n        passwordIsDefined = true;\r\n        const UString password(passwordBSTR);\r\n        const UInt32 sizeInBytes = password.Length() * 2;\r\n        buffer.SetCapacity(sizeInBytes);\r\n        for (int i = 0; i < password.Length(); i++)\r\n        {\r\n          wchar_t c = password[i];\r\n          ((Byte *)buffer)[i * 2] = (Byte)c;\r\n          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n        }\r\n        RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    coderIndex++;\r\n    \r\n    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;\r\n    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    CRecordVector<const UInt64 *> packSizesPointers;\r\n    CRecordVector<const UInt64 *> unpackSizesPointers;\r\n    packSizesPointers.Reserve(numInStreams);\r\n    unpackSizesPointers.Reserve(numOutStreams);\r\n    UInt32 j;\r\n    for (j = 0; j < numOutStreams; j++, unpackStreamIndex++)\r\n      unpackSizesPointers.Add(&folderInfo.UnpackSizes[unpackStreamIndex]);\r\n    \r\n    for (j = 0; j < numInStreams; j++, packStreamIndex++)\r\n    {\r\n      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);\r\n      if (bindPairIndex >= 0)\r\n        packSizesPointers.Add(\r\n        &folderInfo.UnpackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);\r\n      else\r\n      {\r\n        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);\r\n        if (index < 0)\r\n          return E_FAIL;\r\n        packSizesPointers.Add(&packSizes[index]);\r\n      }\r\n    }\r\n    \r\n    _mixerCoderCommon->SetCoderInfo(i,\r\n        &packSizesPointers.Front(),\r\n        &unpackSizesPointers.Front());\r\n  }\r\n  UInt32 mainCoder, temp;\r\n  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);\r\n\r\n  if (_multiThread)\r\n    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);\r\n  /*\r\n  else\r\n    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;\r\n  */\r\n  \r\n  if (numCoders == 0)\r\n    return 0;\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  inStreamPointers.Reserve(inStreams.Size());\r\n  for (i = 0; i < inStreams.Size(); i++)\r\n    inStreamPointers.Add(inStreams[i]);\r\n  ISequentialOutStream *outStreamPointer = outStream;\r\n  return _mixerCoder->Code(&inStreamPointers.Front(), NULL,\r\n    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zDecode.h",
    "content": "// 7zDecode.h\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"7zItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CBindInfoEx: public NCoderMixer::CBindInfo\r\n{\r\n  CRecordVector<CMethodId> CoderMethodIDs;\r\n  void Clear()\r\n  {\r\n    CBindInfo::Clear();\r\n    CoderMethodIDs.Clear();\r\n  }\r\n};\r\n\r\nclass CDecoder\r\n{\r\n  bool _bindInfoExPrevIsDefined;\r\n  CBindInfoEx _bindInfoExPrev;\r\n  \r\n  bool _multiThread;\r\n  #ifdef _ST_MODE\r\n  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;\r\n  #endif\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;\r\n  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;\r\n  \r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n  CObjectVector<CMyComPtr<IUnknown> > _decoders;\r\n  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;\r\npublic:\r\n  CDecoder(bool multiThread);\r\n  HRESULT Decode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      IInStream *inStream,\r\n      UInt64 startPos,\r\n      const UInt64 *packSizes,\r\n      const CFolder &folder,\r\n      ISequentialOutStream *outStream,\r\n      ICompressProgressInfo *compressProgress\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , bool mtMode, UInt32 numThreads\r\n      #endif\r\n      );\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zEncode.cpp",
    "content": "// Encode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zSpecStream.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/InOutTempBuffer.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nstatic const UInt64 k_AES = 0x06F10701;\r\nstatic const UInt64 k_BCJ  = 0x03030103;\r\nstatic const UInt64 k_BCJ2 = 0x0303011B;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,\r\n    const CRecordVector<CMethodId> decompressionMethods,\r\n    CFolder &folder)\r\n{\r\n  folder.Coders.Clear();\r\n  // bindInfo.CoderMethodIDs.Clear();\r\n  // folder.OutStreams.Clear();\r\n  folder.PackStreams.Clear();\r\n  folder.BindPairs.Clear();\r\n  int i;\r\n  for (i = 0; i < bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = bindInfo.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = bindInfo.BindPairs[i].OutIndex;\r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n  for (i = 0; i < bindInfo.Coders.Size(); i++)\r\n  {\r\n    CCoderInfo coderInfo;\r\n    const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];\r\n    coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;\r\n    coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;\r\n    coderInfo.MethodID = decompressionMethods[i];\r\n    folder.Coders.Add(coderInfo);\r\n  }\r\n  for (i = 0; i < bindInfo.InStreams.Size(); i++)\r\n    folder.PackStreams.Add(bindInfo.InStreams[i]);\r\n}\r\n\r\nHRESULT CEncoder::CreateMixerCoder(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const UInt64 *inSizeForReduce)\r\n{\r\n  _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;\r\n  _mixerCoder = _mixerCoderSpec;\r\n  RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));\r\n  for (int i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _codersInfo.Add(CCoderInfo());\r\n    CCoderInfo &encodingInfo = _codersInfo.Back();\r\n    encodingInfo.MethodID = methodFull.Id;\r\n    CMyComPtr<ICompressCoder> encoder;\r\n    CMyComPtr<ICompressCoder2> encoder2;\r\n    \r\n\r\n    RINOK(CreateCoder(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        methodFull.Id, encoder, encoder2, true));\r\n\r\n    if (!encoder && !encoder2)\r\n      return E_FAIL;\r\n\r\n    CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;\r\n   \r\n    #ifdef COMPRESS_MT\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));\r\n      }\r\n    }\r\n    #endif\r\n        \r\n\r\n    RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon));\r\n\r\n    /*\r\n    CMyComPtr<ICryptoResetSalt> resetSalt;\r\n    encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);\r\n    if (resetSalt != NULL)\r\n    {\r\n      resetSalt->ResetSalt();\r\n    }\r\n    */\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n    encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n    if (setCompressCodecsInfo)\r\n    {\r\n      RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n    }\r\n    #endif\r\n    \r\n    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n    encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n\r\n    if (cryptoSetPassword)\r\n    {\r\n      CByteBuffer buffer;\r\n      const UInt32 sizeInBytes = _options.Password.Length() * 2;\r\n      buffer.SetCapacity(sizeInBytes);\r\n      for (int i = 0; i < _options.Password.Length(); i++)\r\n      {\r\n        wchar_t c = _options.Password[i];\r\n        ((Byte *)buffer)[i * 2] = (Byte)c;\r\n        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n      }\r\n      RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n    }\r\n\r\n    if (encoder)\r\n      _mixerCoderSpec->AddCoder(encoder);\r\n    else\r\n      _mixerCoderSpec->AddCoder2(encoder2);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Encode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    ISequentialInStream *inStream,\r\n    const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n    CFolder &folderItem,\r\n    ISequentialOutStream *outStream,\r\n    CRecordVector<UInt64> &packSizes,\r\n    ICompressProgressInfo *compressProgress)\r\n{\r\n  RINOK(EncoderConstr());\r\n\r\n  if (_mixerCoderSpec == NULL)\r\n  {\r\n    RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));\r\n  }\r\n  _mixerCoderSpec->ReInit();\r\n  // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);\r\n\r\n  CObjectVector<CInOutTempBuffer> inOutTempBuffers;\r\n  CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;\r\n  CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;\r\n  int numMethods = _bindInfo.Coders.Size();\r\n  int i;\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    inOutTempBuffers.Add(CInOutTempBuffer());\r\n    inOutTempBuffers.Back().Create();\r\n    inOutTempBuffers.Back().InitWriting();\r\n  }\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CSequentialOutTempBufferImp *tempBufferSpec =\r\n        new CSequentialOutTempBufferImp;\r\n    CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;\r\n    tempBufferSpec->Init(&inOutTempBuffers[i - 1]);\r\n    tempBuffers.Add(tempBuffer);\r\n    tempBufferSpecs.Add(tempBufferSpec);\r\n  }\r\n\r\n  for (i = 0; i < numMethods; i++)\r\n    _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    return E_FAIL;\r\n  UInt32 mainCoderIndex, mainStreamIndex;\r\n  _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);\r\n  \r\n  if (inStreamSize != NULL)\r\n  {\r\n    CRecordVector<const UInt64 *> sizePointers;\r\n    for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)\r\n      if (i == mainStreamIndex)\r\n        sizePointers.Add(inStreamSize);\r\n      else\r\n        sizePointers.Add(NULL);\r\n    _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);\r\n  }\r\n\r\n  \r\n  // UInt64 outStreamStartPos;\r\n  // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));\r\n  \r\n  CSequentialInStreamSizeCount2 *inStreamSizeCountSpec =\r\n      new CSequentialInStreamSizeCount2;\r\n  CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;\r\n  CSequentialOutStreamSizeCount *outStreamSizeCountSpec =\r\n      new CSequentialOutStreamSizeCount;\r\n  CMyComPtr<ISequentialOutStream> outStreamSizeCount = outStreamSizeCountSpec;\r\n\r\n  inStreamSizeCountSpec->Init(inStream);\r\n  outStreamSizeCountSpec->SetStream(outStream);\r\n  outStreamSizeCountSpec->Init();\r\n\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  CRecordVector<ISequentialOutStream *> outStreamPointers;\r\n  inStreamPointers.Add(inStreamSizeCount);\r\n  outStreamPointers.Add(outStreamSizeCount);\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n    outStreamPointers.Add(tempBuffers[i - 1]);\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    CCoderInfo &encodingInfo = _codersInfo[i];\r\n    \r\n    CMyComPtr<ICryptoResetInitVector> resetInitVector;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);\r\n    if (resetInitVector != NULL)\r\n    {\r\n      resetInitVector->ResetInitVector();\r\n    }\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n    if (writeCoderProperties != NULL)\r\n    {\r\n      CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n      outStreamSpec->Init();\r\n      writeCoderProperties->WriteCoderProperties(outStream);\r\n      size_t size = outStreamSpec->GetSize();\r\n      encodingInfo.Props.SetCapacity(size);\r\n      memmove(encodingInfo.Props, outStreamSpec->GetBuffer(), size);\r\n    }\r\n  }\r\n\r\n  UInt32 progressIndex = mainCoderIndex;\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    const CCoderInfo &e = _codersInfo[i];\r\n    if ((e.MethodID == k_BCJ || e.MethodID == k_BCJ2) && i + 1 < _codersInfo.Size())\r\n      progressIndex = i + 1;\r\n  }\r\n\r\n  _mixerCoderSpec->SetProgressCoderIndex(progressIndex);\r\n  \r\n  RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,\r\n    &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));\r\n  \r\n  ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods,\r\n      folderItem);\r\n  \r\n  packSizes.Add(outStreamSizeCountSpec->GetSize());\r\n  \r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];\r\n    inOutTempBuffer.FlushWrite();\r\n    inOutTempBuffer.InitReading();\r\n    inOutTempBuffer.WriteToStream(outStream);\r\n    packSizes.Add(inOutTempBuffer.GetDataSize());\r\n  }\r\n  \r\n  for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)\r\n  {\r\n    int binder = _bindInfo.FindBinderForInStream(\r\n        _bindReverseConverter->DestOutToSrcInMap[i]);\r\n    UInt64 streamSize;\r\n    if (binder < 0)\r\n      streamSize = inStreamSizeCountSpec->GetSize();\r\n    else\r\n      streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);\r\n    folderItem.UnpackSizes.Add(streamSize);\r\n  }\r\n  for (i = numMethods - 1; i >= 0; i--)\r\n    folderItem.Coders[numMethods - 1 - i].Props = _codersInfo[i].Props;\r\n  return S_OK;\r\n}\r\n\r\n\r\nCEncoder::CEncoder(const CCompressionMethodMode &options):\r\n  _bindReverseConverter(0),\r\n  _constructed(false)\r\n{\r\n  if (options.IsEmpty())\r\n    throw 1;\r\n\r\n  _options = options;\r\n  _mixerCoderSpec = NULL;\r\n}\r\n\r\nHRESULT CEncoder::EncoderConstr()\r\n{\r\n  if (_constructed)\r\n    return S_OK;\r\n  if (_options.Methods.IsEmpty())\r\n  {\r\n    // it has only password method;\r\n    if (!_options.PasswordIsDefined)\r\n      throw 1;\r\n    if (!_options.Binds.IsEmpty())\r\n      throw 1;\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    CMethodFull method;\r\n    \r\n    method.NumInStreams = 1;\r\n    method.NumOutStreams = 1;\r\n    coderStreamsInfo.NumInStreams = 1;\r\n    coderStreamsInfo.NumOutStreams = 1;\r\n    method.Id = k_AES;\r\n    \r\n    _options.Methods.Add(method);\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  \r\n    _bindInfo.InStreams.Add(0);\r\n    _bindInfo.OutStreams.Add(0);\r\n  }\r\n  else\r\n  {\r\n\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  int i;\r\n  for (i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;\r\n    coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;\r\n    if (_options.Binds.IsEmpty())\r\n    {\r\n      if (i < _options.Methods.Size() - 1)\r\n      {\r\n        NCoderMixer::CBindPair bindPair;\r\n        bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;\r\n        bindPair.OutIndex = numOutStreams;\r\n        _bindInfo.BindPairs.Add(bindPair);\r\n      }\r\n      else\r\n        _bindInfo.OutStreams.Insert(0, numOutStreams);\r\n      for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)\r\n        _bindInfo.OutStreams.Add(numOutStreams + j);\r\n    }\r\n    \r\n    numInStreams += coderStreamsInfo.NumInStreams;\r\n    numOutStreams += coderStreamsInfo.NumOutStreams;\r\n\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  }\r\n\r\n  if (!_options.Binds.IsEmpty())\r\n  {\r\n    for (i = 0; i < _options.Binds.Size(); i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      const CBind &bind = _options.Binds[i];\r\n      bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;\r\n      bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    for (i = 0; i < (int)numOutStreams; i++)\r\n      if (_bindInfo.FindBinderForOutStream(i) == -1)\r\n        _bindInfo.OutStreams.Add(i);\r\n  }\r\n\r\n  for (i = 0; i < (int)numInStreams; i++)\r\n    if (_bindInfo.FindBinderForInStream(i) == -1)\r\n      _bindInfo.InStreams.Add(i);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    throw 1; // this is error\r\n\r\n  // Make main stream first in list\r\n  int inIndex = _bindInfo.InStreams[0];\r\n  for (;;)\r\n  {\r\n    UInt32 coderIndex, coderStreamIndex;\r\n    _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);\r\n    UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);\r\n    int binder = _bindInfo.FindBinderForOutStream(outIndex);\r\n    if (binder >= 0)\r\n    {\r\n      inIndex = _bindInfo.BindPairs[binder].InIndex;\r\n      continue;\r\n    }\r\n    for (i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n      if (_bindInfo.OutStreams[i] == outIndex)\r\n      {\r\n        _bindInfo.OutStreams.Delete(i);\r\n        _bindInfo.OutStreams.Insert(0, outIndex);\r\n        break;\r\n      }\r\n    break;\r\n  }\r\n\r\n  if (_options.PasswordIsDefined)\r\n  {\r\n    int numCryptoStreams = _bindInfo.OutStreams.Size();\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      bindPair.InIndex = numInStreams + i;\r\n      bindPair.OutIndex = _bindInfo.OutStreams[i];\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    _bindInfo.OutStreams.Clear();\r\n\r\n    /*\r\n    if (numCryptoStreams == 0)\r\n      numCryptoStreams = 1;\r\n    */\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n      CMethodFull method;\r\n      method.NumInStreams = 1;\r\n      method.NumOutStreams = 1;\r\n      coderStreamsInfo.NumInStreams = method.NumOutStreams;\r\n      coderStreamsInfo.NumOutStreams = method.NumInStreams;\r\n      method.Id = k_AES;\r\n\r\n      _options.Methods.Add(method);\r\n      _bindInfo.Coders.Add(coderStreamsInfo);\r\n      _bindInfo.OutStreams.Add(numOutStreams + i);\r\n    }\r\n  }\r\n\r\n  }\r\n\r\n  for (int i = _options.Methods.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _decompressionMethods.Add(methodFull.Id);\r\n  }\r\n\r\n  _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);\r\n  _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);\r\n  _constructed = true;\r\n  return S_OK;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  delete _bindReverseConverter;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zEncode.h",
    "content": "// 7zEncode.h\r\n\r\n#ifndef __7Z_ENCODE_H\r\n#define __7Z_ENCODE_H\r\n\r\n// #include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n#include \"7zItem.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CEncoder\r\n{\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;\r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n\r\n  CObjectVector<CCoderInfo> _codersInfo;\r\n\r\n  CCompressionMethodMode _options;\r\n  NCoderMixer::CBindInfo _bindInfo;\r\n  NCoderMixer::CBindInfo _decompressBindInfo;\r\n  NCoderMixer::CBindReverseConverter *_bindReverseConverter;\r\n  CRecordVector<CMethodId> _decompressionMethods;\r\n\r\n  HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const UInt64 *inSizeForReduce);\r\n\r\n  bool _constructed;\r\npublic:\r\n  CEncoder(const CCompressionMethodMode &options);\r\n  ~CEncoder();\r\n  HRESULT EncoderConstr();\r\n  HRESULT Encode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      ISequentialInStream *inStream,\r\n      const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n      CFolder &folderItem,\r\n      ISequentialOutStream *outStream,\r\n      CRecordVector<UInt64> &packSizes,\r\n      ICompressProgressInfo *compressProgress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zExtract.cpp",
    "content": "// 7zExtract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zFolderOutStream.h\"\r\n#include \"7zDecode.h\"\r\n// #include \"7z1Decode.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CExtractFolderInfo\r\n{\r\n  #ifdef _7Z_VOL\r\n  int VolumeIndex;\r\n  #endif\r\n  CNum FileIndex;\r\n  CNum FolderIndex;\r\n  CBoolVector ExtractStatuses;\r\n  UInt64 UnpackSize;\r\n  CExtractFolderInfo(\r\n    #ifdef _7Z_VOL\r\n    int volumeIndex,\r\n    #endif\r\n    CNum fileIndex, CNum folderIndex):\r\n    #ifdef _7Z_VOL\r\n    VolumeIndex(volumeIndex),\r\n    #endif\r\n    FileIndex(fileIndex),\r\n    FolderIndex(folderIndex),\r\n    UnpackSize(0)\r\n  {\r\n    if (fileIndex != kNumNoIndex)\r\n    {\r\n      ExtractStatuses.Reserve(1);\r\n      ExtractStatuses.Add(true);\r\n    }\r\n  };\r\n};\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool testMode = (testModeSpec != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;\r\n  UInt64 importantTotalUnpacked = 0;\r\n\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (allFilesMode)\r\n    numItems =\r\n    #ifdef _7Z_VOL\r\n    _refs.Size();\r\n    #else\r\n    _db.Files.Size();\r\n    #endif\r\n\r\n  if(numItems == 0)\r\n    return S_OK;\r\n\r\n  /*\r\n  if(_volumes.Size() != 1)\r\n    return E_FAIL;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_db = volume.Database;\r\n  IInStream *_inStream = volume.Stream;\r\n  */\r\n  \r\n  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;\r\n  for(UInt32 ii = 0; ii < numItems; ii++)\r\n  {\r\n    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];\r\n    UInt32 ref2Index = allFilesMode ? ii : indices[ii];\r\n    // const CRef2 &ref2 = _refs[ref2Index];\r\n\r\n    // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)\r\n    {\r\n      #ifdef _7Z_VOL\r\n      // const CRef &ref = ref2.Refs[ri];\r\n      const CRef &ref = _refs[ref2Index];\r\n\r\n      int volumeIndex = ref.VolumeIndex;\r\n      const CVolume &volume = _volumes[volumeIndex];\r\n      const CArchiveDatabaseEx &db = volume.Database;\r\n      UInt32 fileIndex = ref.ItemIndex;\r\n      #else\r\n      const CArchiveDatabaseEx &db = _db;\r\n      UInt32 fileIndex = ref2Index;\r\n      #endif\r\n\r\n      CNum folderIndex = db.FileIndexToFolderIndexMap[fileIndex];\r\n      if (folderIndex == kNumNoIndex)\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex,\r\n            #endif\r\n            fileIndex, kNumNoIndex));\r\n        continue;\r\n      }\r\n      if (extractFolderInfoVector.IsEmpty() ||\r\n        folderIndex != extractFolderInfoVector.Back().FolderIndex\r\n        #ifdef _7Z_VOL\r\n        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex\r\n        #endif\r\n        )\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex,\r\n            #endif\r\n            kNumNoIndex, folderIndex));\r\n        const CFolder &folderInfo = db.Folders[folderIndex];\r\n        UInt64 unpackSize = folderInfo.GetUnpackSize();\r\n        importantTotalUnpacked += unpackSize;\r\n        extractFolderInfoVector.Back().UnpackSize = unpackSize;\r\n      }\r\n      \r\n      CExtractFolderInfo &efi = extractFolderInfoVector.Back();\r\n      \r\n      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];\r\n      CNum startIndex = db.FolderStartFileIndex[folderIndex];\r\n      for (CNum index = efi.ExtractStatuses.Size();\r\n          index <= fileIndex - startIndex; index++)\r\n      {\r\n        // UInt64 unpackSize = _db.Files[startIndex + index].UnpackSize;\r\n        // Count partial_folder_size\r\n        // efi.UnpackSize += unpackSize;\r\n        // importantTotalUnpacked += unpackSize;\r\n        efi.ExtractStatuses.Add(index == fileIndex - startIndex);\r\n      }\r\n    }\r\n  }\r\n\r\n  extractCallback->SetTotal(importantTotalUnpacked);\r\n\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  // CDecoder1 decoder;\r\n\r\n  UInt64 currentTotalPacked = 0;\r\n  UInt64 currentTotalUnpacked = 0;\r\n  UInt64 totalFolderUnpacked;\r\n  UInt64 totalFolderPacked;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for(int i = 0; i < extractFolderInfoVector.Size(); i++,\r\n      currentTotalUnpacked += totalFolderUnpacked,\r\n      currentTotalPacked += totalFolderPacked)\r\n  {\r\n    lps->OutSize = currentTotalUnpacked;\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    const CExtractFolderInfo &efi = extractFolderInfoVector[i];\r\n    totalFolderUnpacked = efi.UnpackSize;\r\n\r\n    totalFolderPacked = 0;\r\n\r\n    CFolderOutStream *folderOutStream = new CFolderOutStream;\r\n    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);\r\n\r\n    #ifdef _7Z_VOL\r\n    const CVolume &volume = _volumes[efi.VolumeIndex];\r\n    const CArchiveDatabaseEx &db = volume.Database;\r\n    #else\r\n    const CArchiveDatabaseEx &db = _db;\r\n    #endif\r\n\r\n    CNum startIndex;\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      startIndex = efi.FileIndex;\r\n    else\r\n      startIndex = db.FolderStartFileIndex[efi.FolderIndex];\r\n\r\n\r\n    HRESULT result = folderOutStream->Init(&db,\r\n        #ifdef _7Z_VOL\r\n        volume.StartRef2Index,\r\n        #else\r\n        0,\r\n        #endif\r\n        startIndex,\r\n        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);\r\n\r\n    RINOK(result);\r\n\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      continue;\r\n\r\n    CNum folderIndex = efi.FolderIndex;\r\n    const CFolder &folderInfo = db.Folders[folderIndex];\r\n\r\n    totalFolderPacked = _db.GetFolderFullPackSize(folderIndex);\r\n\r\n    CNum packStreamIndex = db.FolderStartPackStreamIndex[folderIndex];\r\n    UInt64 folderStartPackPos = db.GetFolderStreamPos(folderIndex, 0);\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (extractCallback)\r\n      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    #endif\r\n\r\n    try\r\n    {\r\n      #ifndef _NO_CRYPTO\r\n      bool passwordIsDefined;\r\n      #endif\r\n\r\n      HRESULT result = decoder.Decode(\r\n          EXTERNAL_CODECS_VARS\r\n          #ifdef _7Z_VOL\r\n          volume.Stream,\r\n          #else\r\n          _inStream,\r\n          #endif\r\n          folderStartPackPos,\r\n          &db.PackSizes[packStreamIndex],\r\n          folderInfo,\r\n          outStream,\r\n          progress\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword, passwordIsDefined\r\n          #endif\r\n          #ifdef COMPRESS_MT\r\n          , true, _numThreads\r\n          #endif\r\n          );\r\n\r\n      if (result == S_FALSE)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));\r\n        continue;\r\n      }\r\n      if (result != S_OK)\r\n        return result;\r\n      if (folderOutStream->WasWritingFinished() != S_OK)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n      continue;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zFolderInStream.cpp",
    "content": "// 7zFolderInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderInStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderInStream::CFolderInStream()\r\n{\r\n  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;\r\n  _inStreamWithHash = _inStreamWithHashSpec;\r\n}\r\n\r\nvoid CFolderInStream::Init(IArchiveUpdateCallback *updateCallback,\r\n    const UInt32 *fileIndices, UInt32 numFiles)\r\n{\r\n  _updateCallback = updateCallback;\r\n  _numFiles = numFiles;\r\n  _fileIndex = 0;\r\n  _fileIndices = fileIndices;\r\n  Processed.Clear();\r\n  CRCs.Clear();\r\n  Sizes.Clear();\r\n  _fileIsOpen = false;\r\n  _currentSizeIsDefined = false;\r\n}\r\n\r\nHRESULT CFolderInStream::OpenStream()\r\n{\r\n  _filePos = 0;\r\n  while (_fileIndex < _numFiles)\r\n  {\r\n    _currentSizeIsDefined = false;\r\n    CMyComPtr<ISequentialInStream> stream;\r\n    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);\r\n    if (result != S_OK && result != S_FALSE)\r\n      return result;\r\n    _fileIndex++;\r\n    _inStreamWithHashSpec->SetStream(stream);\r\n    _inStreamWithHashSpec->Init();\r\n    if (!stream)\r\n    {\r\n      RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n      Sizes.Add(0);\r\n      Processed.Add(result == S_OK);\r\n      AddDigest();\r\n      continue;\r\n    }\r\n    CMyComPtr<IStreamGetSize> streamGetSize;\r\n    if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)\r\n    {\r\n      if(streamGetSize)\r\n      {\r\n        _currentSizeIsDefined = true;\r\n        RINOK(streamGetSize->GetSize(&_currentSize));\r\n      }\r\n    }\r\n\r\n    _fileIsOpen = true;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFolderInStream::AddDigest()\r\n{\r\n  CRCs.Add(_inStreamWithHashSpec->GetCRC());\r\n}\r\n\r\nHRESULT CFolderInStream::CloseStream()\r\n{\r\n  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n  _inStreamWithHashSpec->ReleaseStream();\r\n  _fileIsOpen = false;\r\n  Processed.Add(true);\r\n  Sizes.Add(_filePos);\r\n  AddDigest();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 localProcessedSize;\r\n      RINOK(_inStreamWithHash->Read(\r\n          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));\r\n      if (localProcessedSize == 0)\r\n      {\r\n        RINOK(CloseStream());\r\n        continue;\r\n      }\r\n      realProcessedSize += localProcessedSize;\r\n      _filePos += localProcessedSize;\r\n      size -= localProcessedSize;\r\n      break;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenStream());\r\n    }\r\n  }\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)\r\n{\r\n  *value = 0;\r\n  int subStreamIndex = (int)subStream;\r\n  if (subStreamIndex < 0 || subStream > Sizes.Size())\r\n    return E_FAIL;\r\n  if (subStreamIndex < Sizes.Size())\r\n  {\r\n    *value= Sizes[subStreamIndex];\r\n    return S_OK;\r\n  }\r\n  if (!_currentSizeIsDefined)\r\n    return S_FALSE;\r\n  *value = _currentSize;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zFolderInStream.h",
    "content": "// 7z/FolderInStream.h\r\n\r\n#ifndef __7Z_FOLDERINSTREAM_H\r\n#define __7Z_FOLDERINSTREAM_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zHeader.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../Common/InStreamWithCRC.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderInStream:\r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  CFolderInStream();\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\nprivate:\r\n  CSequentialInStreamWithCRC *_inStreamWithHashSpec;\r\n  CMyComPtr<ISequentialInStream> _inStreamWithHash;\r\n  CMyComPtr<IArchiveUpdateCallback> _updateCallback;\r\n\r\n  bool _currentSizeIsDefined;\r\n  UInt64 _currentSize;\r\n\r\n  bool _fileIsOpen;\r\n  UInt64 _filePos;\r\n\r\n  const UInt32 *_fileIndices;\r\n  UInt32 _numFiles;\r\n  UInt32 _fileIndex;\r\n\r\n  HRESULT OpenStream();\r\n  HRESULT CloseStream();\r\n  void AddDigest();\r\npublic:\r\n  void Init(IArchiveUpdateCallback *updateCallback,\r\n      const UInt32 *fileIndices, UInt32 numFiles);\r\n  CRecordVector<bool> Processed;\r\n  CRecordVector<UInt32> CRCs;\r\n  CRecordVector<UInt64> Sizes;\r\n  UInt64 GetFullSize() const\r\n  {\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < Sizes.Size(); i++)\r\n      size += Sizes[i];\r\n    return size;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zFolderOutStream.cpp",
    "content": "// 7zFolderOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderOutStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderOutStream::CFolderOutStream()\r\n{\r\n  _outStreamWithHashSpec = new COutStreamWithCRC;\r\n  _outStreamWithHash = _outStreamWithHashSpec;\r\n}\r\n\r\nHRESULT CFolderOutStream::Init(\r\n    const CArchiveDatabaseEx *archiveDatabase,\r\n    UInt32 ref2Offset,\r\n    UInt32 startIndex,\r\n    const CBoolVector *extractStatuses,\r\n    IArchiveExtractCallback *extractCallback,\r\n    bool testMode,\r\n    bool checkCrc)\r\n{\r\n  _archiveDatabase = archiveDatabase;\r\n  _ref2Offset = ref2Offset;\r\n  _startIndex = startIndex;\r\n\r\n  _extractStatuses = extractStatuses;\r\n  _extractCallback = extractCallback;\r\n  _testMode = testMode;\r\n\r\n  _checkCrc = checkCrc;\r\n\r\n  _currentIndex = 0;\r\n  _fileIsOpen = false;\r\n  return WriteEmptyFiles();\r\n}\r\n\r\nHRESULT CFolderOutStream::OpenFile()\r\n{\r\n  Int32 askMode;\r\n  if((*_extractStatuses)[_currentIndex])\r\n    askMode = _testMode ?\r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n  else\r\n    askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n\r\n  UInt32 index = _startIndex + _currentIndex;\r\n  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));\r\n\r\n  _outStreamWithHashSpec->SetStream(realOutStream);\r\n  _outStreamWithHashSpec->Init(_checkCrc);\r\n  if (askMode == NArchive::NExtract::NAskMode::kExtract &&\r\n      (!realOutStream))\r\n  {\r\n    const CFileItem &fi = _archiveDatabase->Files[index];\r\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir)\r\n      askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  }\r\n  return _extractCallback->PrepareOperation(askMode);\r\n}\r\n\r\nHRESULT CFolderOutStream::WriteEmptyFiles()\r\n{\r\n  for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)\r\n  {\r\n    UInt32 index = _startIndex + _currentIndex;\r\n    const CFileItem &fi = _archiveDatabase->Files[index];\r\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir && fi.Size != 0)\r\n      return S_OK;\r\n    RINOK(OpenFile());\r\n    RINOK(_extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\r\n    _outStreamWithHashSpec->ReleaseStream();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderOutStream::Write(const void *data,\r\n    UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 index = _startIndex + _currentIndex;\r\n      const CFileItem &fi = _archiveDatabase->Files[index];\r\n      UInt64 fileSize = fi.Size;\r\n      \r\n      UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos,\r\n          UInt64(size - realProcessedSize));\r\n      \r\n      UInt32 processedSizeLocal;\r\n      RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize,\r\n            numBytesToWrite, &processedSizeLocal));\r\n\r\n      _filePos += processedSizeLocal;\r\n      realProcessedSize += processedSizeLocal;\r\n      if (_filePos == fileSize)\r\n      {\r\n        bool digestsAreEqual;\r\n        if (fi.CrcDefined && _checkCrc)\r\n          digestsAreEqual = fi.Crc == _outStreamWithHashSpec->GetCRC();\r\n        else\r\n          digestsAreEqual = true;\r\n\r\n        RINOK(_extractCallback->SetOperationResult(\r\n            digestsAreEqual ?\r\n            NArchive::NExtract::NOperationResult::kOK :\r\n            NArchive::NExtract::NOperationResult::kCRCError));\r\n        _outStreamWithHashSpec->ReleaseStream();\r\n        _fileIsOpen = false;\r\n        _currentIndex++;\r\n      }\r\n      if (realProcessedSize == size)\r\n      {\r\n        if (processedSize != NULL)\r\n          *processedSize = realProcessedSize;\r\n        return WriteEmptyFiles();\r\n      }\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n      _filePos = 0;\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)\r\n{\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      RINOK(_extractCallback->SetOperationResult(resultEOperationResult));\r\n      _outStreamWithHashSpec->ReleaseStream();\r\n      _fileIsOpen = false;\r\n      _currentIndex++;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::WasWritingFinished()\r\n{\r\n  if (_currentIndex == _extractStatuses->Size())\r\n    return S_OK;\r\n  return E_FAIL;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zFolderOutStream.h",
    "content": "// 7zFolderOutStream.h\r\n\r\n#ifndef __7Z_FOLDEROUTSTREAM_H\r\n#define __7Z_FOLDEROUTSTREAM_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../IArchive.h\"\r\n#include \"../Common/OutStreamWithCRC.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  \r\n  CFolderOutStream();\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n\r\n  COutStreamWithCRC *_outStreamWithHashSpec;\r\n  CMyComPtr<ISequentialOutStream> _outStreamWithHash;\r\n  const CArchiveDatabaseEx *_archiveDatabase;\r\n  const CBoolVector *_extractStatuses;\r\n  UInt32 _startIndex;\r\n  UInt32 _ref2Offset;\r\n  int _currentIndex;\r\n  // UInt64 _currentDataPos;\r\n  CMyComPtr<IArchiveExtractCallback> _extractCallback;\r\n  bool _testMode;\r\n\r\n  bool _fileIsOpen;\r\n\r\n  bool _checkCrc;\r\n  UInt64 _filePos;\r\n\r\n  HRESULT OpenFile();\r\n  HRESULT WriteEmptyFiles();\r\npublic:\r\n  HRESULT Init(\r\n      const CArchiveDatabaseEx *archiveDatabase,\r\n      UInt32 ref2Offset,\r\n      UInt32 startIndex,\r\n      const CBoolVector *extractStatuses,\r\n      IArchiveExtractCallback *extractCallback,\r\n      bool testMode,\r\n      bool checkCrc);\r\n  HRESULT FlushCorrupted(Int32 resultEOperationResult);\r\n  HRESULT WasWritingFinished();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zHandler.cpp",
    "content": "// 7zHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/CpuArch.h\"\r\n}\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zProperties.h\"\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n#include \"../Common/ParseProperties.h\"\r\n#endif\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nextern UString ConvertMethodIdToString(UInt64 id);\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCHandler::CHandler()\r\n{\r\n  _crcSize = 4;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  _passwordIsDefined = false;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  #else\r\n  Init();\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = _db.Files.Size();\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _SFX\r\n\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,\r\n      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\n\r\n#else\r\n\r\nSTATPROPSTG kArcProps[] =\r\n{\r\n  { NULL, kpidMethod, VT_BSTR},\r\n  { NULL, kpidSolid, VT_BOOL},\r\n  { NULL, kpidNumBlocks, VT_UI4},\r\n  { NULL, kpidPhySize, VT_UI8},\r\n  { NULL, kpidHeadersSize, VT_UI8},\r\n  { NULL, kpidOffset, VT_UI8}\r\n};\r\n\r\nSTDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidMethod:\r\n    {\r\n      UString resString;\r\n      CRecordVector<UInt64> ids;\r\n      int i;\r\n      for (i = 0; i < _db.Folders.Size(); i++)\r\n      {\r\n        const CFolder &f = _db.Folders[i];\r\n        for (int j = f.Coders.Size() - 1; j >= 0; j--)\r\n          ids.AddToUniqueSorted(f.Coders[j].MethodID);\r\n      }\r\n\r\n      for (i = 0; i < ids.Size(); i++)\r\n      {\r\n        UInt64 id = ids[i];\r\n        UString methodName;\r\n        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);\r\n        if (methodName.IsEmpty())\r\n          methodName = ConvertMethodIdToString(id);\r\n        if (!resString.IsEmpty())\r\n          resString += L' ';\r\n        resString += methodName;\r\n      }\r\n      prop = resString;\r\n      break;\r\n    }\r\n    case kpidSolid: prop = _db.IsSolid(); break;\r\n    case kpidNumBlocks: prop = (UInt32)_db.Folders.Size(); break;\r\n    case kpidHeadersSize:  prop = _db.HeadersSize; break;\r\n    case kpidPhySize:  prop = _db.PhySize; break;\r\n    case kpidOffset: if (_db.ArchiveInfo.StartPosition != 0) prop = _db.ArchiveInfo.StartPosition; break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nIMP_IInArchive_ArcProps\r\n\r\n#endif\r\n\r\nstatic void SetPropFromUInt64Def(CUInt64DefVector &v, int index, NCOM::CPropVariant &prop)\r\n{\r\n  UInt64 value;\r\n  if (v.GetItem(index, value))\r\n  {\r\n    FILETIME ft;\r\n    ft.dwLowDateTime = (DWORD)value;\r\n    ft.dwHighDateTime = (DWORD)(value >> 32);\r\n    prop = ft;\r\n  }\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString GetStringForSizeValue(UInt32 value)\r\n{\r\n  for (int i = 31; i >= 0; i--)\r\n    if ((UInt32(1) << i) == value)\r\n      return ConvertUInt32ToString(i);\r\n  UString result;\r\n  if (value % (1 << 20) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 20);\r\n    result += L\"m\";\r\n  }\r\n  else if (value % (1 << 10) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 10);\r\n    result += L\"k\";\r\n  }\r\n  else\r\n  {\r\n    result += ConvertUInt32ToString(value);\r\n    result += L\"b\";\r\n  }\r\n  return result;\r\n}\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_PPMD  = 0x030401;\r\n\r\nstatic wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));\r\n}\r\nstatic inline UString GetHex2(Byte value)\r\n{\r\n  UString result;\r\n  result += GetHex((Byte)(value >> 4));\r\n  result += GetHex((Byte)(value & 0xF));\r\n  return result;\r\n}\r\n\r\n#endif\r\n\r\nstatic const UInt64 k_AES  = 0x06F10701;\r\n\r\nbool CHandler::IsEncrypted(UInt32 index2) const\r\n{\r\n  CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n  if (folderIndex != kNumNoIndex)\r\n  {\r\n    const CFolder &folderInfo = _db.Folders[folderIndex];\r\n    for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n      if (folderInfo.Coders[i].MethodID == k_AES)\r\n        return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  \r\n  /*\r\n  const CRef2 &ref2 = _refs[index];\r\n  if (ref2.Refs.IsEmpty())\r\n    return E_FAIL;\r\n  const CRef &ref = ref2.Refs.Front();\r\n  */\r\n  \r\n  const CFileItem &item = _db.Files[index];\r\n  UInt32 index2 = index;\r\n\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n      if (!item.Name.IsEmpty())\r\n        prop = NItemName::GetOSName(item.Name);\r\n      break;\r\n    case kpidIsDir:  prop = item.IsDir; break;\r\n    case kpidSize:\r\n    {\r\n      prop = item.Size;\r\n      // prop = ref2.Size;\r\n      break;\r\n    }\r\n    case kpidPackSize:\r\n    {\r\n      // prop = ref2.PackSize;\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2)\r\n            prop = _db.GetFolderFullPackSize(folderIndex);\r\n          /*\r\n          else\r\n            prop = (UInt64)0;\r\n          */\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    }\r\n    case kpidPosition:  { UInt64 v; if (_db.StartPos.GetItem(index2, v)) prop = v; break; }\r\n    case kpidCTime:  SetPropFromUInt64Def(_db.CTime, index2, prop); break;\r\n    case kpidATime:  SetPropFromUInt64Def(_db.ATime, index2, prop); break;\r\n    case kpidMTime:  SetPropFromUInt64Def(_db.MTime, index2, prop); break;\r\n    case kpidAttrib:  if (item.AttribDefined) prop = item.Attrib; break;\r\n    case kpidCRC:  if (item.CrcDefined) prop = item.Crc; break;\r\n    case kpidEncrypted:  prop = IsEncrypted(index2); break;\r\n    case kpidIsAnti:  prop = _db.IsItemAnti(index2); break;\r\n    #ifndef _SFX\r\n    case kpidMethod:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _db.Folders[folderIndex];\r\n          UString methodsString;\r\n          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n          {\r\n            const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n            if (!methodsString.IsEmpty())\r\n              methodsString += L' ';\r\n\r\n            {\r\n              UString methodName;\r\n              bool methodIsKnown = FindMethod(\r\n                  EXTERNAL_CODECS_VARS\r\n                  coderInfo.MethodID, methodName);\r\n\r\n              if (methodIsKnown)\r\n              {\r\n                methodsString += methodName;\r\n                if (coderInfo.MethodID == k_LZMA)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 5)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_PPMD)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 5)\r\n                  {\r\n                    Byte order = *(const Byte *)coderInfo.Props;\r\n                    methodsString += L\":o\";\r\n                    methodsString += ConvertUInt32ToString(order);\r\n                    methodsString += L\":mem\";\r\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_AES)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 1)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    const Byte *data = (const Byte *)coderInfo.Props;\r\n                    Byte firstByte = *data++;\r\n                    UInt32 numCyclesPower = firstByte & 0x3F;\r\n                    methodsString += ConvertUInt32ToString(numCyclesPower);\r\n                    /*\r\n                    if ((firstByte & 0xC0) != 0)\r\n                    {\r\n                      methodsString += L\":\";\r\n                      return S_OK;\r\n                      UInt32 saltSize = (firstByte >> 7) & 1;\r\n                      UInt32 ivSize = (firstByte >> 6) & 1;\r\n                      if (coderInfo.Props.GetCapacity() >= 2)\r\n                      {\r\n                        Byte secondByte = *data++;\r\n                        saltSize += (secondByte >> 4);\r\n                        ivSize += (secondByte & 0x0F);\r\n                      }\r\n                    }\r\n                    */\r\n                  }\r\n                }\r\n                else\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() > 0)\r\n                  {\r\n                    methodsString += L\":[\";\r\n                    for (size_t bi = 0; bi < coderInfo.Props.GetCapacity(); bi++)\r\n                    {\r\n                      if (bi > 5 && bi + 1 < coderInfo.Props.GetCapacity())\r\n                      {\r\n                        methodsString += L\"..\";\r\n                        break;\r\n                      }\r\n                      else\r\n                        methodsString += GetHex2(coderInfo.Props[bi]);\r\n                    }\r\n                    methodsString += L\"]\";\r\n                  }\r\n                }\r\n              }\r\n              else\r\n              {\r\n                methodsString += ConvertMethodIdToString(coderInfo.MethodID);\r\n              }\r\n            }\r\n          }\r\n          prop = methodsString;\r\n        }\r\n      }\r\n      break;\r\n    case kpidBlock:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n          prop = (UInt32)folderIndex;\r\n      }\r\n      break;\r\n    case kpidPackedSize0:\r\n    case kpidPackedSize1:\r\n    case kpidPackedSize2:\r\n    case kpidPackedSize3:\r\n    case kpidPackedSize4:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _db.Folders[folderIndex];\r\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 &&\r\n              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))\r\n          {\r\n            prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);\r\n          }\r\n          else\r\n            prop = (UInt64)0;\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    #endif\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 *maxCheckStartPosition,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Clear();\r\n  #endif\r\n  try\r\n  {\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(\r\n          IID_ICryptoGetTextPassword, &getTextPassword);\r\n    }\r\n    #endif\r\n    CInArchive archive;\r\n    RINOK(archive.Open(stream, maxCheckStartPosition));\r\n    #ifndef _NO_CRYPTO\r\n    _passwordIsDefined = false;\r\n    UString password;\r\n    #endif\r\n    HRESULT result = archive.ReadDatabase(\r\n      EXTERNAL_CODECS_VARS\r\n      _db\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, _passwordIsDefined\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    _db.Fill();\r\n    _inStream = stream;\r\n  }\r\n  catch(...)\r\n  {\r\n    Close();\r\n    return S_FALSE;\r\n  }\r\n  // _inStream = stream;\r\n  #ifndef _SFX\r\n  FillPopIDs();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  COM_TRY_BEGIN\r\n  _inStream.Release();\r\n  _db.Clear();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef COMPRESS_MT\r\n  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();\r\n  _numThreads = numProcessors;\r\n  #endif\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    const PROPVARIANT &value = values[i];\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index == 0)\r\n    {\r\n      if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n      {\r\n        #ifdef COMPRESS_MT\r\n        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n        #endif\r\n        continue;\r\n      }\r\n      else\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#endif\r\n#endif\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zHandler.h",
    "content": "// 7z/Handler.h\r\n\r\n#ifndef __7Z_HANDLER_H\r\n#define __7Z_HANDLER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../IArchive.h\"\r\n#include \"7zIn.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#ifndef EXTRACT_ONLY\r\n#include \"../Common/HandlerOut.h\"\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\n#ifndef __7Z_SET_PROPERTIES\r\n\r\n#ifdef EXTRACT_ONLY\r\n#ifdef COMPRESS_MT\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n#else\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n\r\n#endif\r\n\r\n\r\nclass CHandler:\r\n  #ifndef EXTRACT_ONLY\r\n  public NArchive::COutHandler,\r\n  #endif\r\n  public IInArchive,\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  public ISetProperties,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public IOutArchive,\r\n  #endif\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IInArchive)\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  MY_QUERYINTERFACE_ENTRY(ISetProperties)\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  MY_QUERYINTERFACE_ENTRY(IOutArchive)\r\n  #endif\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);\r\n  #endif\r\n\r\n  #ifndef EXTRACT_ONLY\r\n  INTERFACE_IOutArchive(;)\r\n  #endif\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n  CHandler();\r\n\r\nprivate:\r\n  CMyComPtr<IInStream> _inStream;\r\n  NArchive::N7z::CArchiveDatabaseEx _db;\r\n  #ifndef _NO_CRYPTO\r\n  bool _passwordIsDefined;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  \r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  #else\r\n  \r\n  CRecordVector<CBind> _binds;\r\n\r\n  HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);\r\n\r\n  HRESULT SetCompressionMethod(CCompressionMethodMode &method,\r\n      CObjectVector<COneMethodInfo> &methodsInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  HRESULT SetCompressionMethod(\r\n      CCompressionMethodMode &method,\r\n      CCompressionMethodMode &headerMethod);\r\n\r\n  #endif\r\n\r\n  bool IsEncrypted(UInt32 index2) const;\r\n  #ifndef _SFX\r\n\r\n  CRecordVector<UInt64> _fileInfoPopIDs;\r\n  void FillPopIDs();\r\n\r\n  #endif\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zHandlerOut.cpp",
    "content": "// 7zHandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const UInt32 kLzmaAlgorithmX5 = 1;\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5;\r\n\r\nstatic inline bool IsCopyMethod(const UString &methodName)\r\n  { return (methodName.CompareNoCase(kCopyMethod) == 0); }\r\n\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  CMyComPtr<ICryptoGetTextPassword2> getTextPassword;\r\n  if (!getTextPassword)\r\n  {\r\n    CMyComPtr<IArchiveUpdateCallback> udateCallback2(updateCallback);\r\n    udateCallback2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);\r\n  }\r\n  \r\n  if (getTextPassword)\r\n  {\r\n    CMyComBSTR password;\r\n    Int32 passwordIsDefined;\r\n    RINOK(getTextPassword->CryptoGetTextPassword2(\r\n        &passwordIsDefined, &password));\r\n    methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);\r\n    if (methodMode.PasswordIsDefined)\r\n      methodMode.Password = password;\r\n  }\r\n  else\r\n    methodMode.PasswordIsDefined = false;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CCompressionMethodMode &headerMethod)\r\n{\r\n  HRESULT res = SetCompressionMethod(methodMode, _methods\r\n  #ifdef COMPRESS_MT\r\n  , _numThreads\r\n  #endif\r\n  );\r\n  RINOK(res);\r\n  methodMode.Binds = _binds;\r\n\r\n  if (_compressHeaders)\r\n  {\r\n    // headerMethod.Methods.Add(methodMode.Methods.Back());\r\n\r\n    CObjectVector<COneMethodInfo> headerMethodInfoVector;\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = kLZMAMethodName;\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kMatchFinder;\r\n      prop.Value = kLzmaMatchFinderForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kAlgorithm;\r\n      prop.Value = kAlgorithmForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kNumFastBytes;\r\n      prop.Value = (UInt32)kNumFastBytesForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = (UInt32)kDictionaryForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    headerMethodInfoVector.Add(oneMethodInfo);\r\n    HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector\r\n      #ifdef COMPRESS_MT\r\n      ,1\r\n      #endif\r\n    );\r\n    RINOK(res);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CObjectVector<COneMethodInfo> &methodsInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  \r\n  if (methodsInfo.IsEmpty())\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = ((level == 0) ? kCopyMethod : kDefaultMethodName);\r\n    methodsInfo.Add(oneMethodInfo);\r\n  }\r\n\r\n  bool needSolid = false;\r\n  for(int i = 0; i < methodsInfo.Size(); i++)\r\n  {\r\n    COneMethodInfo &oneMethodInfo = methodsInfo[i];\r\n    SetCompressionMethod2(oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , numThreads\r\n      #endif\r\n      );\r\n\r\n    if (!IsCopyMethod(oneMethodInfo.MethodName))\r\n      needSolid = true;\r\n\r\n    CMethodFull methodFull;\r\n\r\n    if (!FindMethod(\r\n        EXTERNAL_CODECS_VARS\r\n        oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams))\r\n      return E_INVALIDARG;\r\n    methodFull.Props = oneMethodInfo.Props;\r\n    methodMode.Methods.Add(methodFull);\r\n\r\n    if (!_numSolidBytesDefined)\r\n    {\r\n      for (int j = 0; j < methodFull.Props.Size(); j++)\r\n      {\r\n        const CProp &prop = methodFull.Props[j];\r\n        if ((prop.Id == NCoderPropID::kDictionarySize ||\r\n             prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4)\r\n        {\r\n          _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7;\r\n          const UInt64 kMinSize = (1 << 24);\r\n          if (_numSolidBytes < kMinSize)\r\n            _numSolidBytes = kMinSize;\r\n          _numSolidBytesDefined = true;\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (!needSolid && !_numSolidBytesDefined)\r\n  {\r\n    _numSolidBytesDefined = true;\r\n    _numSolidBytes  = 0;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, bool writeTime, PROPID propID, UInt64 &ft, bool &ftDefined)\r\n{\r\n  ft = 0;\r\n  ftDefined = false;\r\n  if (!writeTime)\r\n    return S_OK;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(updateCallback->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    ft = prop.filetime.dwLowDateTime | ((UInt64)prop.filetime.dwHighDateTime << 32);\r\n    ftDefined = true;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  const CArchiveDatabaseEx *db = 0;\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() > 1)\r\n    return E_FAIL;\r\n  const CVolume *volume = 0;\r\n  if (_volumes.Size() == 1)\r\n  {\r\n    volume = &_volumes.Front();\r\n    db = &volume->Database;\r\n  }\r\n  #else\r\n  if (_inStream != 0)\r\n    db = &_db;\r\n  #endif\r\n\r\n  CObjectVector<CUpdateItem> updateItems;\r\n  \r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    Int32 newData;\r\n    Int32 newProperties;\r\n    UInt32 indexInArchive;\r\n    if (!updateCallback)\r\n      return E_FAIL;\r\n    RINOK(updateCallback->GetUpdateItemInfo(i, &newData, &newProperties, &indexInArchive));\r\n    CUpdateItem ui;\r\n    ui.NewProperties = IntToBool(newProperties);\r\n    ui.NewData = IntToBool(newData);\r\n    ui.IndexInArchive = indexInArchive;\r\n    ui.IndexInClient = i;\r\n    ui.IsAnti = false;\r\n    ui.Size = 0;\r\n\r\n    if (ui.IndexInArchive != -1)\r\n    {\r\n      const CFileItem &fi = db->Files[ui.IndexInArchive];\r\n      ui.Name = fi.Name;\r\n      ui.IsDir = fi.IsDir;\r\n      ui.Size = fi.Size;\r\n      ui.IsAnti = db->IsItemAnti(ui.IndexInArchive);\r\n      \r\n      ui.CTimeDefined = db->CTime.GetItem(ui.IndexInArchive, ui.CTime);\r\n      ui.ATimeDefined = db->ATime.GetItem(ui.IndexInArchive, ui.ATime);\r\n      ui.MTimeDefined = db->MTime.GetItem(ui.IndexInArchive, ui.MTime);\r\n    }\r\n\r\n    if (ui.NewProperties)\r\n    {\r\n      bool nameIsDefined;\r\n      bool folderStatusIsDefined;\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidAttrib, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          ui.AttribDefined = false;\r\n        else if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.Attrib = prop.ulVal;\r\n          ui.AttribDefined = true;\r\n        }\r\n      }\r\n      \r\n      // we need MTime to sort files.\r\n      RINOK(GetTime(updateCallback, i, WriteCTime, kpidCTime, ui.CTime, ui.CTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, WriteATime, kpidATime, ui.ATime, ui.ATimeDefined));\r\n      RINOK(GetTime(updateCallback, i, true,       kpidMTime, ui.MTime, ui.MTimeDefined));\r\n\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidPath, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          nameIsDefined = false;\r\n        else if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.Name = NItemName::MakeLegalName(prop.bstrVal);\r\n          nameIsDefined = true;\r\n        }\r\n      }\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsDir, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          folderStatusIsDefined = false;\r\n        else if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.IsDir = (prop.boolVal != VARIANT_FALSE);\r\n          folderStatusIsDefined = true;\r\n        }\r\n      }\r\n\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsAnti, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          ui.IsAnti = false;\r\n        else if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n          ui.IsAnti = (prop.boolVal != VARIANT_FALSE);\r\n      }\r\n\r\n      if (ui.IsAnti)\r\n      {\r\n        ui.AttribDefined = false;\r\n\r\n        ui.CTimeDefined = false;\r\n        ui.ATimeDefined = false;\r\n        ui.MTimeDefined = false;\r\n        \r\n        ui.Size = 0;\r\n      }\r\n\r\n      if (!folderStatusIsDefined && ui.AttribDefined)\r\n        ui.SetDirStatusFromAttrib();\r\n    }\r\n\r\n    if (ui.NewData)\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(i, kpidSize, &prop));\r\n      if (prop.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      ui.Size = (UInt64)prop.uhVal.QuadPart;\r\n      if (ui.Size != 0 && ui.IsAnti)\r\n        return E_INVALIDARG;\r\n    }\r\n    updateItems.Add(ui);\r\n  }\r\n\r\n  CCompressionMethodMode methodMode, headerMethod;\r\n  RINOK(SetCompressionMethod(methodMode, headerMethod));\r\n  #ifdef COMPRESS_MT\r\n  methodMode.NumThreads = _numThreads;\r\n  headerMethod.NumThreads = 1;\r\n  #endif\r\n\r\n  RINOK(SetPassword(methodMode, updateCallback));\r\n\r\n  bool compressMainHeader = _compressHeaders;  // check it\r\n\r\n  bool encryptHeaders = false;\r\n\r\n  if (methodMode.PasswordIsDefined)\r\n  {\r\n    if (_encryptHeadersSpecified)\r\n      encryptHeaders = _encryptHeaders;\r\n    #ifndef _NO_CRYPTO\r\n    else\r\n      encryptHeaders = _passwordIsDefined;\r\n    #endif\r\n    compressMainHeader = true;\r\n    if(encryptHeaders)\r\n      RINOK(SetPassword(headerMethod, updateCallback));\r\n  }\r\n\r\n  if (numItems < 2)\r\n    compressMainHeader = false;\r\n\r\n  CUpdateOptions options;\r\n  options.Method = &methodMode;\r\n  options.HeaderMethod = (_compressHeaders || encryptHeaders) ? &headerMethod : 0;\r\n  options.UseFilters = _level != 0 && _autoFilter;\r\n  options.MaxFilter = _level >= 8;\r\n\r\n  options.HeaderOptions.CompressMainHeader = compressMainHeader;\r\n  options.HeaderOptions.WriteCTime = WriteCTime;\r\n  options.HeaderOptions.WriteATime = WriteATime;\r\n  options.HeaderOptions.WriteMTime = WriteMTime;\r\n  \r\n  options.NumSolidFiles = _numSolidFiles;\r\n  options.NumSolidBytes = _numSolidBytes;\r\n  options.SolidExtension = _solidExtension;\r\n  options.RemoveSfxBlock = _removeSfxBlock;\r\n  options.VolumeMode = _volumeMode;\r\n\r\n  COutArchive archive;\r\n  CArchiveDatabase newDatabase;\r\n  HRESULT res = Update(\r\n      EXTERNAL_CODECS_VARS\r\n      #ifdef _7Z_VOL\r\n      volume ? volume->Stream: 0,\r\n      volume ? db : 0,\r\n      #else\r\n      _inStream,\r\n      db,\r\n      #endif\r\n      updateItems,\r\n      archive, newDatabase, outStream, updateCallback, options);\r\n\r\n  RINOK(res);\r\n\r\n  updateItems.ClearAndFree();\r\n\r\n  return archive.WriteDatabase(EXTERNAL_CODECS_VARS\r\n      newDatabase, options.HeaderMethod, options.HeaderOptions);\r\n\r\n  COM_TRY_END\r\n}\r\n\r\nstatic HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)\r\n{\r\n  stream = 0;\r\n  int index = ParseStringToUInt32(srcString, coder);\r\n  if (index == 0)\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0, index);\r\n  if (srcString[0] == 'S')\r\n  {\r\n    srcString.Delete(0);\r\n    int index = ParseStringToUInt32(srcString, stream);\r\n    if (index == 0)\r\n      return E_INVALIDARG;\r\n    srcString.Delete(0, index);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetBindInfo(UString &srcString, CBind &bind)\r\n{\r\n  RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream));\r\n  if (srcString[0] != ':')\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0);\r\n  RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream));\r\n  if (!srcString.IsEmpty())\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  _binds.Clear();\r\n  BeforeSetProperty();\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n\r\n    const PROPVARIANT &value = values[i];\r\n\r\n    if (name[0] == 'B')\r\n    {\r\n      name.Delete(0);\r\n      CBind bind;\r\n      RINOK(GetBindInfo(name, bind));\r\n      _binds.Add(bind);\r\n      continue;\r\n    }\r\n\r\n    RINOK(SetProperty(name, value));\r\n  }\r\n\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zHeader.cpp",
    "content": "// 7z/Header.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nByte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n#ifdef _7Z_VOL\r\nByte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};\r\n#endif\r\n\r\nclass SignatureInitializer\r\n{\r\npublic:\r\n  SignatureInitializer()\r\n  {\r\n    kSignature[0]--;\r\n    #ifdef _7Z_VOL\r\n    kFinishSignature[0]--;\r\n    #endif\r\n  };\r\n} g_SignatureInitializer;\r\n\r\n}}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zHeader.h",
    "content": "// 7z/7zHeader.h\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nconst int kSignatureSize = 6;\r\nextern Byte kSignature[kSignatureSize];\r\n\r\n// #define _7Z_VOL\r\n// 7z-MultiVolume is not finished yet.\r\n// It can work already, but I still do not like some\r\n// things of that new multivolume format.\r\n// So please keep it commented.\r\n\r\n#ifdef _7Z_VOL\r\nextern Byte kFinishSignature[kSignatureSize];\r\n#endif\r\n\r\nstruct CArchiveVersion\r\n{\r\n  Byte Major;\r\n  Byte Minor;\r\n};\r\n\r\nconst Byte kMajorVersion = 0;\r\n\r\nstruct CStartHeader\r\n{\r\n  UInt64 NextHeaderOffset;\r\n  UInt64 NextHeaderSize;\r\n  UInt32 NextHeaderCRC;\r\n};\r\n\r\nconst UInt32 kStartHeaderSize = 20;\r\n\r\n#ifdef _7Z_VOL\r\nstruct CFinishHeader: public CStartHeader\r\n{\r\n  UInt64 ArchiveStartOffset;  // data offset from end if that struct\r\n  UInt64 AdditionalStartBlockSize; // start  signature & start header size\r\n};\r\n\r\nconst UInt32 kFinishHeaderSize = kStartHeaderSize + 16;\r\n#endif\r\n\r\nnamespace NID\r\n{\r\n  enum EEnum\r\n  {\r\n    kEnd,\r\n\r\n    kHeader,\r\n\r\n    kArchiveProperties,\r\n    \r\n    kAdditionalStreamsInfo,\r\n    kMainStreamsInfo,\r\n    kFilesInfo,\r\n    \r\n    kPackInfo,\r\n    kUnpackInfo,\r\n    kSubStreamsInfo,\r\n\r\n    kSize,\r\n    kCRC,\r\n\r\n    kFolder,\r\n\r\n    kCodersUnpackSize,\r\n    kNumUnpackStream,\r\n\r\n    kEmptyStream,\r\n    kEmptyFile,\r\n    kAnti,\r\n\r\n    kName,\r\n    kCTime,\r\n    kATime,\r\n    kMTime,\r\n    kWinAttributes,\r\n    kComment,\r\n\r\n    kEncodedHeader,\r\n\r\n    kStartPos,\r\n    kDummy\r\n  };\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zIn.cpp",
    "content": "// 7zIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/7zCrc.h\"\r\n  #include \"../../../../C/CpuArch.h\"\r\n}\r\n\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"7zDecode.h\"\r\n#include \"7zIn.h\"\r\n\r\n#define Get16(p) GetUi16(p)\r\n#define Get32(p) GetUi32(p)\r\n#define Get64(p) GetUi64(p)\r\n\r\n// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader\r\n#ifndef _SFX\r\n#define FORMAT_7Z_RECOVERY\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void BoolVector_Fill_False(CBoolVector &v, int size)\r\n{\r\n  v.Clear();\r\n  v.Reserve(size);\r\n  for (int i = 0; i < size; i++)\r\n    v.Add(false);\r\n}\r\n\r\nstatic bool BoolVector_GetAndSet(CBoolVector &v, UInt32 index)\r\n{\r\n  if (index >= (UInt32)v.Size())\r\n    return true;\r\n  bool res = v[index];\r\n  v[index] = true;\r\n  return res;\r\n}\r\n\r\nbool CFolder::CheckStructure() const\r\n{\r\n  const int kNumCodersMax = sizeof(UInt32) * 8; // don't change it\r\n  const int kMaskSize = sizeof(UInt32) * 8; // it must be >= kNumCodersMax\r\n  const int kNumBindsMax = 32;\r\n\r\n  if (Coders.Size() > kNumCodersMax || BindPairs.Size() > kNumBindsMax)\r\n    return false;\r\n\r\n  {\r\n    CBoolVector v;\r\n    BoolVector_Fill_False(v, BindPairs.Size() + PackStreams.Size());\r\n    \r\n    int i;\r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, BindPairs[i].InIndex))\r\n        return false;\r\n    for (i = 0; i < PackStreams.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, PackStreams[i]))\r\n        return false;\r\n    \r\n    BoolVector_Fill_False(v, UnpackSizes.Size());\r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, BindPairs[i].OutIndex))\r\n        return false;\r\n  }\r\n  \r\n  UInt32 mask[kMaskSize];\r\n  int i;\r\n  for (i = 0; i < kMaskSize; i++)\r\n    mask[i] = 0;\r\n\r\n  {\r\n    CIntVector inStreamToCoder, outStreamToCoder;\r\n    for (i = 0; i < Coders.Size(); i++)\r\n    {\r\n      CNum j;\r\n      const CCoderInfo &coder = Coders[i];\r\n      for (j = 0; j < coder.NumInStreams; j++)\r\n        inStreamToCoder.Add(i);\r\n      for (j = 0; j < coder.NumOutStreams; j++)\r\n        outStreamToCoder.Add(i);\r\n    }\r\n    \r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n    {\r\n      const CBindPair &bp = BindPairs[i];\r\n      mask[inStreamToCoder[bp.InIndex]] |= (1 << outStreamToCoder[bp.OutIndex]);\r\n    }\r\n  }\r\n  \r\n  for (i = 0; i < kMaskSize; i++)\r\n    for (int j = 0; j < kMaskSize; j++)\r\n      if (((1 << j) & mask[i]) != 0)\r\n        mask[i] |= mask[j];\r\n\r\n  for (i = 0; i < kMaskSize; i++)\r\n    if (((1 << i) & mask[i]) != 0)\r\n      return false;\r\n\r\n  return true;\r\n}\r\n\r\nclass CInArchiveException {};\r\n\r\nstatic void ThrowException() { throw CInArchiveException(); }\r\nstatic inline void ThrowEndOfData()   { ThrowException(); }\r\nstatic inline void ThrowUnsupported() { ThrowException(); }\r\nstatic inline void ThrowIncorrect()   { ThrowException(); }\r\nstatic inline void ThrowUnsupportedVersion() { ThrowException(); }\r\n\r\n/*\r\nclass CInArchiveException\r\n{\r\npublic:\r\n  enum CCauseType\r\n  {\r\n    kUnsupportedVersion = 0,\r\n    kUnsupported,\r\n    kIncorrect,\r\n    kEndOfData,\r\n  } Cause;\r\n  CInArchiveException(CCauseType cause): Cause(cause) {};\r\n};\r\n\r\nstatic void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }\r\nstatic void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }\r\nstatic void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }\r\nstatic void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }\r\nstatic void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }\r\n*/\r\n\r\nclass CStreamSwitch\r\n{\r\n  CInArchive *_archive;\r\n  bool _needRemove;\r\npublic:\r\n  CStreamSwitch(): _needRemove(false) {}\r\n  ~CStreamSwitch() { Remove(); }\r\n  void Remove();\r\n  void Set(CInArchive *archive, const Byte *data, size_t size);\r\n  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);\r\n  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);\r\n};\r\n\r\nvoid CStreamSwitch::Remove()\r\n{\r\n  if (_needRemove)\r\n  {\r\n    _archive->DeleteByteStream();\r\n    _needRemove = false;\r\n  }\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)\r\n{\r\n  Remove();\r\n  _archive = archive;\r\n  _archive->AddByteStream(data, size);\r\n  _needRemove = true;\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)\r\n{\r\n  Set(archive, byteBuffer, byteBuffer.GetCapacity());\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)\r\n{\r\n  Remove();\r\n  Byte external = archive->ReadByte();\r\n  if (external != 0)\r\n  {\r\n    int dataIndex = (int)archive->ReadNum();\r\n    if (dataIndex < 0 || dataIndex >= dataVector->Size())\r\n      ThrowIncorrect();\r\n    Set(archive, (*dataVector)[dataIndex]);\r\n  }\r\n}\r\n\r\nByte CInByte2::ReadByte()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  return _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::ReadBytes(Byte *data, size_t size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  for (size_t i = 0; i < size; i++)\r\n    data[i] = _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::SkeepData(UInt64 size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  _pos += (size_t)size;\r\n}\r\n\r\nvoid CInByte2::SkeepData()\r\n{\r\n  SkeepData(ReadNumber());\r\n}\r\n\r\nUInt64 CInByte2::ReadNumber()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  Byte firstByte = _buffer[_pos++];\r\n  Byte mask = 0x80;\r\n  UInt64 value = 0;\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      value += (highPart << (i * 8));\r\n      return value;\r\n    }\r\n    if (_pos >= _size)\r\n      ThrowEndOfData();\r\n    value |= ((UInt64)_buffer[_pos++] << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return value;\r\n}\r\n\r\nCNum CInByte2::ReadNum()\r\n{\r\n  UInt64 value = ReadNumber();\r\n  if (value > kNumMax)\r\n    ThrowUnsupported();\r\n  return (CNum)value;\r\n}\r\n\r\nUInt32 CInByte2::ReadUInt32()\r\n{\r\n  if (_pos + 4 > _size)\r\n    ThrowEndOfData();\r\n  UInt32 res = Get32(_buffer + _pos);\r\n  _pos += 4;\r\n  return res;\r\n}\r\n\r\nUInt64 CInByte2::ReadUInt64()\r\n{\r\n  if (_pos + 8 > _size)\r\n    ThrowEndOfData();\r\n  UInt64 res = Get64(_buffer + _pos);\r\n  _pos += 8;\r\n  return res;\r\n}\r\n\r\nvoid CInByte2::ReadString(UString &s)\r\n{\r\n  const Byte *buf = _buffer + _pos;\r\n  size_t rem = (_size - _pos) / 2 * 2;\r\n  {\r\n    size_t i;\r\n    for (i = 0; i < rem; i += 2)\r\n      if (buf[i] == 0 && buf[i + 1] == 0)\r\n        break;\r\n    if (i == rem)\r\n      ThrowEndOfData();\r\n    rem = i;\r\n  }\r\n  int len = (int)(rem / 2);\r\n  if (len < 0 || (size_t)len * 2 != rem)\r\n    ThrowUnsupported();\r\n  wchar_t *p = s.GetBuffer(len);\r\n  int i;\r\n  for (i = 0; i < len; i++, buf += 2)\r\n    p[i] = (wchar_t)Get16(buf);\r\n  s.ReleaseBuffer(len);\r\n  _pos += rem + 2;\r\n}\r\n\r\nstatic inline bool TestSignatureCandidate(const Byte *p)\r\n{\r\n  for (int i = 0; i < kSignatureSize; i++)\r\n    if (p[i] != kSignature[i])\r\n      return false;\r\n  return (p[0x1A] == 0 && p[0x1B] == 0);\r\n}\r\n\r\nHRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));\r\n\r\n  if (TestSignatureCandidate(_header))\r\n    return S_OK;\r\n\r\n  CByteBuffer byteBuffer;\r\n  const UInt32 kBufferSize = (1 << 16);\r\n  byteBuffer.SetCapacity(kBufferSize);\r\n  Byte *buffer = byteBuffer;\r\n  UInt32 numPrevBytes = kHeaderSize - 1;\r\n  memcpy(buffer, _header + 1, numPrevBytes);\r\n  UInt64 curTestPos = _arhiveBeginStreamPosition + 1;\r\n  for (;;)\r\n  {\r\n    if (searchHeaderSizeLimit != NULL)\r\n      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)\r\n        break;\r\n    do\r\n    {\r\n      UInt32 numReadBytes = kBufferSize - numPrevBytes;\r\n      UInt32 processedSize;\r\n      RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));\r\n      numPrevBytes += processedSize;\r\n      if (processedSize == 0)\r\n        return S_FALSE;\r\n    }\r\n    while (numPrevBytes < kHeaderSize);\r\n    UInt32 numTests = numPrevBytes - kHeaderSize + 1;\r\n    for (UInt32 pos = 0; pos < numTests; pos++)\r\n    {\r\n      for (; buffer[pos] != '7' && pos < numTests; pos++);\r\n      if (pos == numTests)\r\n        break;\r\n      if (TestSignatureCandidate(buffer + pos))\r\n      {\r\n        memcpy(_header, buffer + pos, kHeaderSize);\r\n        curTestPos += pos;\r\n        _arhiveBeginStreamPosition = curTestPos;\r\n        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);\r\n      }\r\n    }\r\n    curTestPos += numTests;\r\n    numPrevBytes -= numTests;\r\n    memmove(buffer, buffer + numTests, numPrevBytes);\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\n// S_FALSE means that file is not archive\r\nHRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  HeadersSize = 0;\r\n  Close();\r\n  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))\r\n  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));\r\n  _stream = stream;\r\n  return S_OK;\r\n}\r\n  \r\nvoid CInArchive::Close()\r\n{\r\n  _stream.Release();\r\n}\r\n\r\nvoid CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)\r\n{\r\n  for (;;)\r\n  {\r\n    if (ReadID() == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::GetNextFolderItem(CFolder &folder)\r\n{\r\n  CNum numCoders = ReadNum();\r\n\r\n  folder.Coders.Clear();\r\n  folder.Coders.Reserve((int)numCoders);\r\n  CNum numInStreams = 0;\r\n  CNum numOutStreams = 0;\r\n  CNum i;\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    folder.Coders.Add(CCoderInfo());\r\n    CCoderInfo &coder = folder.Coders.Back();\r\n\r\n    {\r\n      Byte mainByte = ReadByte();\r\n      int idSize = (mainByte & 0xF);\r\n      Byte longID[15];\r\n      ReadBytes(longID, idSize);\r\n      if (idSize > 8)\r\n        ThrowUnsupported();\r\n      UInt64 id = 0;\r\n      for (int j = 0; j < idSize; j++)\r\n        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n      coder.MethodID = id;\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        coder.NumInStreams = ReadNum();\r\n        coder.NumOutStreams = ReadNum();\r\n      }\r\n      else\r\n      {\r\n        coder.NumInStreams = 1;\r\n        coder.NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        CNum propsSize = ReadNum();\r\n        coder.Props.SetCapacity((size_t)propsSize);\r\n        ReadBytes((Byte *)coder.Props, (size_t)propsSize);\r\n      }\r\n      if ((mainByte & 0x80) != 0)\r\n        ThrowUnsupported();\r\n    }\r\n    numInStreams += coder.NumInStreams;\r\n    numOutStreams += coder.NumOutStreams;\r\n  }\r\n\r\n  CNum numBindPairs = numOutStreams - 1;\r\n  folder.BindPairs.Clear();\r\n  folder.BindPairs.Reserve(numBindPairs);\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair bp;\r\n    bp.InIndex = ReadNum();\r\n    bp.OutIndex = ReadNum();\r\n    folder.BindPairs.Add(bp);\r\n  }\r\n\r\n  if (numInStreams < numBindPairs)\r\n    ThrowUnsupported();\r\n  CNum numPackStreams = numInStreams - numBindPairs;\r\n  folder.PackStreams.Reserve(numPackStreams);\r\n  if (numPackStreams == 1)\r\n  {\r\n    for (i = 0; i < numInStreams; i++)\r\n      if (folder.FindBindPairForInStream(i) < 0)\r\n      {\r\n        folder.PackStreams.Add(i);\r\n        break;\r\n      }\r\n    if (folder.PackStreams.Size() != 1)\r\n      ThrowUnsupported();\r\n  }\r\n  else\r\n    for (i = 0; i < numPackStreams; i++)\r\n      folder.PackStreams.Add(ReadNum());\r\n}\r\n\r\nvoid CInArchive::WaitAttribute(UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == attribute)\r\n      return;\r\n    if (type == NID::kEnd)\r\n      ThrowIncorrect();\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadHashDigests(int numItems,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  ReadBoolVector2(numItems, digestsDefined);\r\n  digests.Clear();\r\n  digests.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 crc = 0;\r\n    if (digestsDefined[i])\r\n      crc = ReadUInt32();\r\n    digests.Add(crc);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadPackInfo(\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CBoolVector &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs)\r\n{\r\n  dataOffset = ReadNumber();\r\n  CNum numPackStreams = ReadNum();\r\n\r\n  WaitAttribute(NID::kSize);\r\n  packSizes.Clear();\r\n  packSizes.Reserve(numPackStreams);\r\n  for (CNum i = 0; i < numPackStreams; i++)\r\n    packSizes.Add(ReadNumber());\r\n\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    if (type == NID::kCRC)\r\n    {\r\n      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs);\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n  if (packCRCsDefined.IsEmpty())\r\n  {\r\n    BoolVector_Fill_False(packCRCsDefined, numPackStreams);\r\n    packCRCs.Reserve(numPackStreams);\r\n    packCRCs.Clear();\r\n    for (CNum i = 0; i < numPackStreams; i++)\r\n      packCRCs.Add(0);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadUnpackInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    CObjectVector<CFolder> &folders)\r\n{\r\n  WaitAttribute(NID::kFolder);\r\n  CNum numFolders = ReadNum();\r\n\r\n  {\r\n    CStreamSwitch streamSwitch;\r\n    streamSwitch.Set(this, dataVector);\r\n    folders.Clear();\r\n    folders.Reserve(numFolders);\r\n    for (CNum i = 0; i < numFolders; i++)\r\n    {\r\n      folders.Add(CFolder());\r\n      GetNextFolderItem(folders.Back());\r\n    }\r\n  }\r\n\r\n  WaitAttribute(NID::kCodersUnpackSize);\r\n\r\n  CNum i;\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    CFolder &folder = folders[i];\r\n    CNum numOutStreams = folder.GetNumOutStreams();\r\n    folder.UnpackSizes.Reserve(numOutStreams);\r\n    for (CNum j = 0; j < numOutStreams; j++)\r\n      folder.UnpackSizes.Add(ReadNumber());\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      return;\r\n    if (type == NID::kCRC)\r\n    {\r\n      CBoolVector crcsDefined;\r\n      CRecordVector<UInt32> crcs;\r\n      ReadHashDigests(numFolders, crcsDefined, crcs);\r\n      for (i = 0; i < numFolders; i++)\r\n      {\r\n        CFolder &folder = folders[i];\r\n        folder.UnpackCRCDefined = crcsDefined[i];\r\n        folder.UnpackCRC = crcs[i];\r\n      }\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    CRecordVector<UInt64> &unpackSizes,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  numUnpackStreamsInFolders.Clear();\r\n  numUnpackStreamsInFolders.Reserve(folders.Size());\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kNumUnpackStream)\r\n    {\r\n      for (int i = 0; i < folders.Size(); i++)\r\n        numUnpackStreamsInFolders.Add(ReadNum());\r\n      continue;\r\n    }\r\n    if (type == NID::kCRC || type == NID::kSize)\r\n      break;\r\n    if (type == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n\r\n  if (numUnpackStreamsInFolders.IsEmpty())\r\n    for (int i = 0; i < folders.Size(); i++)\r\n      numUnpackStreamsInFolders.Add(1);\r\n\r\n  int i;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n  {\r\n    // v3.13 incorrectly worked with empty folders\r\n    // v4.07: we check that folder is empty\r\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    UInt64 sum = 0;\r\n    for (CNum j = 1; j < numSubstreams; j++)\r\n      if (type == NID::kSize)\r\n      {\r\n        UInt64 size = ReadNumber();\r\n        unpackSizes.Add(size);\r\n        sum += size;\r\n      }\r\n    unpackSizes.Add(folders[i].GetUnpackSize() - sum);\r\n  }\r\n  if (type == NID::kSize)\r\n    type = ReadID();\r\n\r\n  int numDigests = 0;\r\n  int numDigestsTotal = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\r\n      numDigests += numSubstreams;\r\n    numDigestsTotal += numSubstreams;\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    if (type == NID::kCRC)\r\n    {\r\n      CBoolVector digestsDefined2;\r\n      CRecordVector<UInt32> digests2;\r\n      ReadHashDigests(numDigests, digestsDefined2, digests2);\r\n      int digestIndex = 0;\r\n      for (i = 0; i < folders.Size(); i++)\r\n      {\r\n        CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n        const CFolder &folder = folders[i];\r\n        if (numSubstreams == 1 && folder.UnpackCRCDefined)\r\n        {\r\n          digestsDefined.Add(true);\r\n          digests.Add(folder.UnpackCRC);\r\n        }\r\n        else\r\n          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)\r\n          {\r\n            digestsDefined.Add(digestsDefined2[digestIndex]);\r\n            digests.Add(digests2[digestIndex]);\r\n          }\r\n      }\r\n    }\r\n    else if (type == NID::kEnd)\r\n    {\r\n      if (digestsDefined.IsEmpty())\r\n      {\r\n        BoolVector_Fill_False(digestsDefined, numDigestsTotal);\r\n        digests.Clear();\r\n        for (int i = 0; i < numDigestsTotal; i++)\r\n          digests.Add(0);\r\n      }\r\n      return;\r\n    }\r\n    else\r\n      SkeepData();\r\n    type = ReadID();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadStreamsInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CBoolVector &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs,\r\n    CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    CRecordVector<UInt64> &unpackSizes,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type > ((UInt32)1 << 30))\r\n      ThrowIncorrect();\r\n    switch((UInt32)type)\r\n    {\r\n      case NID::kEnd:\r\n        return;\r\n      case NID::kPackInfo:\r\n      {\r\n        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);\r\n        break;\r\n      }\r\n      case NID::kUnpackInfo:\r\n      {\r\n        ReadUnpackInfo(dataVector, folders);\r\n        break;\r\n      }\r\n      case NID::kSubStreamsInfo:\r\n      {\r\n        ReadSubStreamsInfo(folders, numUnpackStreamsInFolders,\r\n            unpackSizes, digestsDefined, digests);\r\n        break;\r\n      }\r\n      default:\r\n        ThrowIncorrect();\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector(int numItems, CBoolVector &v)\r\n{\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      b = ReadByte();\r\n      mask = 0x80;\r\n    }\r\n    v.Add((b & mask) != 0);\r\n    mask >>= 1;\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)\r\n{\r\n  Byte allAreDefined = ReadByte();\r\n  if (allAreDefined == 0)\r\n  {\r\n    ReadBoolVector(numItems, v);\r\n    return;\r\n  }\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n    v.Add(true);\r\n}\r\n\r\nvoid CInArchive::ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\r\n    CUInt64DefVector &v, int numFiles)\r\n{\r\n  ReadBoolVector2(numFiles, v.Defined);\r\n\r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, &dataVector);\r\n  v.Values.Reserve(numFiles);\r\n\r\n  for (int i = 0; i < numFiles; i++)\r\n  {\r\n    UInt64 t = 0;\r\n    if (v.Defined[i])\r\n      t = ReadUInt64();\r\n    v.Values.Add(t);\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadAndDecodePackedStreams(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    UInt64 baseOffset,\r\n    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  CRecordVector<UInt64> packSizes;\r\n  CBoolVector packCRCsDefined;\r\n  CRecordVector<UInt32> packCRCs;\r\n  CObjectVector<CFolder> folders;\r\n  \r\n  CRecordVector<CNum> numUnpackStreamsInFolders;\r\n  CRecordVector<UInt64> unpackSizes;\r\n  CBoolVector digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  ReadStreamsInfo(NULL,\r\n    dataOffset,\r\n    packSizes,\r\n    packCRCsDefined,\r\n    packCRCs,\r\n    folders,\r\n    numUnpackStreamsInFolders,\r\n    unpackSizes,\r\n    digestsDefined,\r\n    digests);\r\n  \r\n  // db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\r\n  \r\n  CNum packIndex = 0;\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  UInt64 dataStartPos = baseOffset + dataOffset;\r\n  for (int i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    dataVector.Add(CByteBuffer());\r\n    CByteBuffer &data = dataVector.Back();\r\n    UInt64 unpackSize64 = folder.GetUnpackSize();\r\n    size_t unpackSize = (size_t)unpackSize64;\r\n    if (unpackSize != unpackSize64)\r\n      ThrowUnsupported();\r\n    data.SetCapacity(unpackSize);\r\n    \r\n    CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    outStreamSpec->Init(data, unpackSize);\r\n    \r\n    HRESULT result = decoder.Decode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      _stream, dataStartPos,\r\n      &packSizes[packIndex], folder, outStream, NULL\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, passwordIsDefined\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , false, 1\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    \r\n    if (folder.UnpackCRCDefined)\r\n      if (CrcCalc(data, unpackSize) != folder.UnpackCRC)\r\n        ThrowIncorrect();\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      UInt64 packSize = packSizes[packIndex++];\r\n      dataStartPos += packSize;\r\n      HeadersSize += packSize;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CInArchive::ReadHeader(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  UInt64 type = ReadID();\r\n\r\n  if (type == NID::kArchiveProperties)\r\n  {\r\n    ReadArchiveProperties(db.ArchiveInfo);\r\n    type = ReadID();\r\n  }\r\n \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  if (type == NID::kAdditionalStreamsInfo)\r\n  {\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        db.ArchiveInfo.StartPositionAfterHeader,\r\n        db.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword, passwordIsDefined\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n\r\n  CRecordVector<UInt64> unpackSizes;\r\n  CBoolVector digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  if (type == NID::kMainStreamsInfo)\r\n  {\r\n    ReadStreamsInfo(&dataVector,\r\n        db.ArchiveInfo.DataStartPosition,\r\n        db.PackSizes,\r\n        db.PackCRCsDefined,\r\n        db.PackCRCs,\r\n        db.Folders,\r\n        db.NumUnpackStreamsVector,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    db.ArchiveInfo.DataStartPosition += db.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n  else\r\n  {\r\n    for (int i = 0; i < db.Folders.Size(); i++)\r\n    {\r\n      db.NumUnpackStreamsVector.Add(1);\r\n      CFolder &folder = db.Folders[i];\r\n      unpackSizes.Add(folder.GetUnpackSize());\r\n      digestsDefined.Add(folder.UnpackCRCDefined);\r\n      digests.Add(folder.UnpackCRC);\r\n    }\r\n  }\r\n\r\n  db.Files.Clear();\r\n\r\n  if (type == NID::kEnd)\r\n    return S_OK;\r\n  if (type != NID::kFilesInfo)\r\n    ThrowIncorrect();\r\n  \r\n  CNum numFiles = ReadNum();\r\n  db.Files.Reserve(numFiles);\r\n  CNum i;\r\n  for (i = 0; i < numFiles; i++)\r\n    db.Files.Add(CFileItem());\r\n\r\n  db.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);\r\n  if (!db.PackSizes.IsEmpty())\r\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);\r\n  if (numFiles > 0  && !digests.IsEmpty())\r\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);\r\n\r\n  CBoolVector emptyStreamVector;\r\n  BoolVector_Fill_False(emptyStreamVector, (int)numFiles);\r\n  CBoolVector emptyFileVector;\r\n  CBoolVector antiFileVector;\r\n  CNum numEmptyStreams = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    UInt64 size = ReadNumber();\r\n    size_t ppp = _inByteBack->_pos;\r\n    bool addPropIdToList = true;\r\n    bool isKnownType = true;\r\n    if (type > ((UInt32)1 << 30))\r\n      isKnownType = false;\r\n    else switch((UInt32)type)\r\n    {\r\n      case NID::kName:\r\n      {\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for (int i = 0; i < db.Files.Size(); i++)\r\n          _inByteBack->ReadString(db.Files[i].Name);\r\n        break;\r\n      }\r\n      case NID::kWinAttributes:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(db.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = db.Files[i];\r\n          file.AttribDefined = boolVector[i];\r\n          if (file.AttribDefined)\r\n            file.Attrib = ReadUInt32();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyStream:\r\n      {\r\n        ReadBoolVector(numFiles, emptyStreamVector);\r\n        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)\r\n          if (emptyStreamVector[i])\r\n            numEmptyStreams++;\r\n\r\n        BoolVector_Fill_False(emptyFileVector, numEmptyStreams);\r\n        BoolVector_Fill_False(antiFileVector, numEmptyStreams);\r\n\r\n        break;\r\n      }\r\n      case NID::kEmptyFile:  ReadBoolVector(numEmptyStreams, emptyFileVector); break;\r\n      case NID::kAnti:  ReadBoolVector(numEmptyStreams, antiFileVector); break;\r\n      case NID::kStartPos:  ReadUInt64DefVector(dataVector, db.StartPos, (int)numFiles); break;\r\n      case NID::kCTime:  ReadUInt64DefVector(dataVector, db.CTime, (int)numFiles); break;\r\n      case NID::kATime:  ReadUInt64DefVector(dataVector, db.ATime, (int)numFiles); break;\r\n      case NID::kMTime:  ReadUInt64DefVector(dataVector, db.MTime, (int)numFiles); break;\r\n      case NID::kDummy:\r\n      {\r\n        for (UInt64 j = 0; j < size; j++)\r\n          if (ReadByte() != 0)\r\n            ThrowIncorrect();\r\n        addPropIdToList = false;\r\n        break;\r\n      }\r\n      default:\r\n        addPropIdToList = isKnownType = false;\r\n    }\r\n    if (isKnownType)\r\n    {\r\n      if(addPropIdToList)\r\n        db.ArchiveInfo.FileInfoPopIDs.Add(type);\r\n    }\r\n    else\r\n      SkeepData(size);\r\n    bool checkRecordsSize = (db.ArchiveInfo.Version.Major > 0 ||\r\n        db.ArchiveInfo.Version.Minor > 2);\r\n    if (checkRecordsSize && _inByteBack->_pos - ppp != size)\r\n      ThrowIncorrect();\r\n  }\r\n\r\n  CNum emptyFileIndex = 0;\r\n  CNum sizeIndex = 0;\r\n\r\n  CNum numAntiItems = 0;\r\n  for (i = 0; i < numEmptyStreams; i++)\r\n    if (antiFileVector[i])\r\n      numAntiItems++;\r\n    \r\n  for (i = 0; i < numFiles; i++)\r\n  {\r\n    CFileItem &file = db.Files[i];\r\n    bool isAnti;\r\n    file.HasStream = !emptyStreamVector[i];\r\n    if (file.HasStream)\r\n    {\r\n      file.IsDir = false;\r\n      isAnti = false;\r\n      file.Size = unpackSizes[sizeIndex];\r\n      file.Crc = digests[sizeIndex];\r\n      file.CrcDefined = digestsDefined[sizeIndex];\r\n      sizeIndex++;\r\n    }\r\n    else\r\n    {\r\n      file.IsDir = !emptyFileVector[emptyFileIndex];\r\n      isAnti = antiFileVector[emptyFileIndex];\r\n      emptyFileIndex++;\r\n      file.Size = 0;\r\n      file.CrcDefined = false;\r\n    }\r\n    if (numAntiItems != 0)\r\n      db.IsAnti.Add(isAnti);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartPackStream()\r\n{\r\n  FolderStartPackStreamIndex.Clear();\r\n  FolderStartPackStreamIndex.Reserve(Folders.Size());\r\n  CNum startPos = 0;\r\n  for (int i = 0; i < Folders.Size(); i++)\r\n  {\r\n    FolderStartPackStreamIndex.Add(startPos);\r\n    startPos += (CNum)Folders[i].PackStreams.Size();\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillStartPos()\r\n{\r\n  PackStreamStartPositions.Clear();\r\n  PackStreamStartPositions.Reserve(PackSizes.Size());\r\n  UInt64 startPos = 0;\r\n  for (int i = 0; i < PackSizes.Size(); i++)\r\n  {\r\n    PackStreamStartPositions.Add(startPos);\r\n    startPos += PackSizes[i];\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartFileIndex()\r\n{\r\n  FolderStartFileIndex.Clear();\r\n  FolderStartFileIndex.Reserve(Folders.Size());\r\n  FileIndexToFolderIndexMap.Clear();\r\n  FileIndexToFolderIndexMap.Reserve(Files.Size());\r\n  \r\n  int folderIndex = 0;\r\n  CNum indexInFolder = 0;\r\n  for (int i = 0; i < Files.Size(); i++)\r\n  {\r\n    const CFileItem &file = Files[i];\r\n    bool emptyStream = !file.HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      FileIndexToFolderIndexMap.Add(kNumNoIndex);\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      // v3.13 incorrectly worked with empty folders\r\n      // v4.07: Loop for skipping empty folders\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= Folders.Size())\r\n          ThrowIncorrect();\r\n        FolderStartFileIndex.Add(i); // check it\r\n        if (NumUnpackStreamsVector[folderIndex] != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    FileIndexToFolderIndexMap.Add(folderIndex);\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= NumUnpackStreamsVector[folderIndex])\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n\r\n  db.ArchiveInfo.Version.Major = _header[6];\r\n  db.ArchiveInfo.Version.Minor = _header[7];\r\n\r\n  if (db.ArchiveInfo.Version.Major != kMajorVersion)\r\n    ThrowUnsupportedVersion();\r\n\r\n  UInt32 crcFromArchive = Get32(_header + 8);\r\n  UInt64 nextHeaderOffset = Get64(_header + 0xC);\r\n  UInt64 nextHeaderSize = Get64(_header + 0x14);\r\n  UInt32 nextHeaderCRC = Get32(_header + 0x1C);\r\n  UInt32 crc = CrcCalc(_header + 0xC, 20);\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)\r\n  {\r\n    UInt64 cur, cur2;\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));\r\n    const int kCheckSize = 500;\r\n    Byte buf[kCheckSize];\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));\r\n    int checkSize = kCheckSize;\r\n    if (cur2 - cur < kCheckSize)\r\n      checkSize = (int)(cur2 - cur);\r\n    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));\r\n    \r\n    RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));\r\n\r\n    int i;\r\n    for (i = (int)checkSize - 2; i >= 0; i--)\r\n      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)\r\n        break;\r\n    if (i < 0)\r\n      return S_FALSE;\r\n    nextHeaderSize = checkSize - i;\r\n    nextHeaderOffset = cur2 - cur + i;\r\n    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);\r\n    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));\r\n  }\r\n  #endif\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  crcFromArchive = crc;\r\n  #endif\r\n\r\n  db.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;\r\n\r\n  if (crc != crcFromArchive)\r\n    ThrowIncorrect();\r\n\r\n  if (nextHeaderSize == 0)\r\n    return S_OK;\r\n\r\n  if (nextHeaderSize > (UInt64)0xFFFFFFFF)\r\n    return S_FALSE;\r\n\r\n  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));\r\n\r\n  CByteBuffer buffer2;\r\n  buffer2.SetCapacity((size_t)nextHeaderSize);\r\n\r\n  RINOK(ReadStream_FALSE(_stream, buffer2, (size_t)nextHeaderSize));\r\n  HeadersSize += kHeaderSize + nextHeaderSize;\r\n  db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;\r\n\r\n  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)\r\n    ThrowIncorrect();\r\n  \r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, buffer2);\r\n  \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  UInt64 type = ReadID();\r\n  if (type != NID::kHeader)\r\n  {\r\n    if (type != NID::kEncodedHeader)\r\n      ThrowIncorrect();\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        db.ArchiveInfo.StartPositionAfterHeader,\r\n        db.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword, passwordIsDefined\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    if (dataVector.Size() == 0)\r\n      return S_OK;\r\n    if (dataVector.Size() > 1)\r\n      ThrowIncorrect();\r\n    streamSwitch.Remove();\r\n    streamSwitch.Set(this, dataVector.Front());\r\n    if (ReadID() != NID::kHeader)\r\n      ThrowIncorrect();\r\n  }\r\n\r\n  db.HeadersSize = HeadersSize;\r\n\r\n  return ReadHeader(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    db\r\n    #ifndef _NO_CRYPTO\r\n    , getTextPassword, passwordIsDefined\r\n    #endif\r\n    );\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  try\r\n  {\r\n    return ReadDatabase2(\r\n      EXTERNAL_CODECS_LOC_VARS db\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, passwordIsDefined\r\n      #endif\r\n      );\r\n  }\r\n  catch(CInArchiveException &) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zIn.h",
    "content": "// 7zIn.h\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../IStream.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/InBuffer.h\"\r\n\r\n#include \"7zItem.h\"\r\n \r\nnamespace NArchive {\r\nnamespace N7z {\r\n  \r\nstruct CInArchiveInfo\r\n{\r\n  CArchiveVersion Version;\r\n  UInt64 StartPosition;\r\n  UInt64 StartPositionAfterHeader;\r\n  UInt64 DataStartPosition;\r\n  UInt64 DataStartPosition2;\r\n  CRecordVector<UInt64> FileInfoPopIDs;\r\n  void Clear()\r\n  {\r\n    FileInfoPopIDs.Clear();\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabaseEx: public CArchiveDatabase\r\n{\r\n  CInArchiveInfo ArchiveInfo;\r\n  CRecordVector<UInt64> PackStreamStartPositions;\r\n  CRecordVector<CNum> FolderStartPackStreamIndex;\r\n  CRecordVector<CNum> FolderStartFileIndex;\r\n  CRecordVector<CNum> FileIndexToFolderIndexMap;\r\n\r\n  UInt64 HeadersSize;\r\n  UInt64 PhySize;\r\n\r\n  void Clear()\r\n  {\r\n    CArchiveDatabase::Clear();\r\n    ArchiveInfo.Clear();\r\n    PackStreamStartPositions.Clear();\r\n    FolderStartPackStreamIndex.Clear();\r\n    FolderStartFileIndex.Clear();\r\n    FileIndexToFolderIndexMap.Clear();\r\n\r\n    HeadersSize = 0;\r\n    PhySize = 0;\r\n  }\r\n\r\n  void FillFolderStartPackStream();\r\n  void FillStartPos();\r\n  void FillFolderStartFileIndex();\r\n\r\n  void Fill()\r\n  {\r\n    FillFolderStartPackStream();\r\n    FillStartPos();\r\n    FillFolderStartFileIndex();\r\n  }\r\n  \r\n  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const\r\n  {\r\n    return ArchiveInfo.DataStartPosition +\r\n        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n  }\r\n  \r\n  UInt64 GetFolderFullPackSize(int folderIndex) const\r\n  {\r\n    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];\r\n    const CFolder &folder = Folders[folderIndex];\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < folder.PackStreams.Size(); i++)\r\n      size += PackSizes[packStreamIndex + i];\r\n    return size;\r\n  }\r\n  \r\n  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\r\n  {\r\n    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n  }\r\n\r\n  UInt64 GetFilePackSize(CNum fileIndex) const\r\n  {\r\n    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n    if (folderIndex != kNumNoIndex)\r\n      if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n        return GetFolderFullPackSize(folderIndex);\r\n    return 0;\r\n  }\r\n};\r\n\r\nclass CInByte2\r\n{\r\n  const Byte *_buffer;\r\n  size_t _size;\r\npublic:\r\n  size_t _pos;\r\n  void Init(const Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  Byte ReadByte();\r\n  void ReadBytes(Byte *data, size_t size);\r\n  void SkeepData(UInt64 size);\r\n  void SkeepData();\r\n  UInt64 ReadNumber();\r\n  CNum ReadNum();\r\n  UInt32 ReadUInt32();\r\n  UInt64 ReadUInt64();\r\n  void ReadString(UString &s);\r\n};\r\n\r\nclass CStreamSwitch;\r\n\r\nconst UInt32 kHeaderSize = 32;\r\n\r\nclass CInArchive\r\n{\r\n  friend class CStreamSwitch;\r\n\r\n  CMyComPtr<IInStream> _stream;\r\n\r\n  CObjectVector<CInByte2> _inByteVector;\r\n  CInByte2 *_inByteBack;\r\n \r\n  UInt64 _arhiveBeginStreamPosition;\r\n\r\n  Byte _header[kHeaderSize];\r\n\r\n  UInt64 HeadersSize;\r\n\r\n  void AddByteStream(const Byte *buffer, size_t size)\r\n  {\r\n    _inByteVector.Add(CInByte2());\r\n    _inByteBack = &_inByteVector.Back();\r\n    _inByteBack->Init(buffer, size);\r\n  }\r\n  \r\n  void DeleteByteStream()\r\n  {\r\n    _inByteVector.DeleteBack();\r\n    if (!_inByteVector.IsEmpty())\r\n      _inByteBack = &_inByteVector.Back();\r\n  }\r\n\r\nprivate:\r\n  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);\r\n  \r\n  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }\r\n  Byte ReadByte() { return _inByteBack->ReadByte(); }\r\n  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }\r\n  CNum ReadNum() { return _inByteBack->ReadNum(); }\r\n  UInt64 ReadID() { return _inByteBack->ReadNumber(); }\r\n  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }\r\n  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }\r\n  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }\r\n  void SkeepData() { _inByteBack->SkeepData(); }\r\n  void WaitAttribute(UInt64 attribute);\r\n\r\n  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);\r\n  void GetNextFolderItem(CFolder &itemInfo);\r\n  void ReadHashDigests(int numItems,\r\n      CBoolVector &digestsDefined, CRecordVector<UInt32> &digests);\r\n  \r\n  void ReadPackInfo(\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CBoolVector &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs);\r\n  \r\n  void ReadUnpackInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      CObjectVector<CFolder> &folders);\r\n  \r\n  void ReadSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      CRecordVector<UInt64> &unpackSizes,\r\n      CBoolVector &digestsDefined,\r\n      CRecordVector<UInt32> &digests);\r\n\r\n  void ReadStreamsInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CBoolVector &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs,\r\n      CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      CRecordVector<UInt64> &unpackSizes,\r\n      CBoolVector &digestsDefined,\r\n      CRecordVector<UInt32> &digests);\r\n\r\n\r\n  void ReadBoolVector(int numItems, CBoolVector &v);\r\n  void ReadBoolVector2(int numItems, CBoolVector &v);\r\n  void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\r\n      CUInt64DefVector &v, int numFiles);\r\n  HRESULT ReadAndDecodePackedStreams(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      UInt64 baseOffset, UInt64 &dataOffset,\r\n      CObjectVector<CByteBuffer> &dataVector\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n  HRESULT ReadHeader(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n  HRESULT ReadDatabase2(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\npublic:\r\n  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive\r\n  void Close();\r\n\r\n  HRESULT ReadDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n};\r\n  \r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zItem.h",
    "content": "// 7zItem.h\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../Common/MethodId.h\"\r\n\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\ntypedef UInt32 CNum;\r\nconst CNum kNumMax     = 0x7FFFFFFF;\r\nconst CNum kNumNoIndex = 0xFFFFFFFF;\r\n\r\nstruct CCoderInfo\r\n{\r\n  CMethodId MethodID;\r\n  CByteBuffer Props;\r\n  CNum NumInStreams;\r\n  CNum NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBindPair\r\n{\r\n  CNum InIndex;\r\n  CNum OutIndex;\r\n};\r\n\r\nstruct CFolder\r\n{\r\n  CObjectVector<CCoderInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<CNum> PackStreams;\r\n  CRecordVector<UInt64> UnpackSizes;\r\n  UInt32 UnpackCRC;\r\n  bool UnpackCRCDefined;\r\n\r\n  CFolder(): UnpackCRCDefined(false) {}\r\n\r\n  UInt64 GetUnpackSize() const // test it\r\n  {\r\n    if (UnpackSizes.IsEmpty())\r\n      return 0;\r\n    for (int i = UnpackSizes.Size() - 1; i >= 0; i--)\r\n      if (FindBindPairForOutStream(i) < 0)\r\n        return UnpackSizes[i];\r\n    throw 1;\r\n  }\r\n\r\n  CNum GetNumOutStreams() const\r\n  {\r\n    CNum result = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n      result += Coders[i].NumOutStreams;\r\n    return result;\r\n  }\r\n\r\n  int FindBindPairForInStream(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBindPairForOutStream(CNum outStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindPackStreamArrayIndex(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < PackStreams.Size(); i++)\r\n      if (PackStreams[i] == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  bool CheckStructure() const;\r\n};\r\n\r\nstruct CUInt64DefVector\r\n{\r\n  CRecordVector<UInt64> Values;\r\n  CRecordVector<bool> Defined;\r\n  \r\n  void Clear()\r\n  {\r\n    Values.Clear();\r\n    Defined.Clear();\r\n  }\r\n  \r\n  void ReserveDown()\r\n  {\r\n    Values.ReserveDown();\r\n    Values.ReserveDown();\r\n  }\r\n\r\n  bool GetItem(int index, UInt64 &value) const\r\n  {\r\n    if (index < Defined.Size() && Defined[index])\r\n    {\r\n      value = Values[index];\r\n      return true;\r\n    }\r\n    value = 0;\r\n    return false;\r\n  }\r\n  \r\n  void SetItem(int index, bool defined, UInt64 value)\r\n  {\r\n    while (index >= Defined.Size())\r\n      Defined.Add(false);\r\n    Defined[index] = defined;\r\n    if (!defined)\r\n      return;\r\n    while (index >= Values.Size())\r\n      Values.Add(0);\r\n    Values[index] = value;\r\n  }\r\n\r\n  bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }\r\n};\r\n\r\nstruct CFileItem\r\n{\r\n  UInt64 Size;\r\n  UInt32 Attrib;\r\n  UInt32 Crc;\r\n  UString Name;\r\n\r\n  bool HasStream; // Test it !!! it means that there is\r\n                  // stream in some folder. It can be empty stream\r\n  bool IsDir;\r\n  bool CrcDefined;\r\n  bool AttribDefined;\r\n\r\n  CFileItem():\r\n    HasStream(true),\r\n    IsDir(false),\r\n    CrcDefined(false),\r\n    AttribDefined(false)\r\n      {}\r\n  void SetAttrib(UInt32 attrib)\r\n  {\r\n    AttribDefined = true;\r\n    Attrib = attrib;\r\n  }\r\n};\r\n\r\nstruct CFileItem2\r\n{\r\n  UInt64 CTime;\r\n  UInt64 ATime;\r\n  UInt64 MTime;\r\n  UInt64 StartPos;\r\n  bool CTimeDefined;\r\n  bool ATimeDefined;\r\n  bool MTimeDefined;\r\n  bool StartPosDefined;\r\n  bool IsAnti;\r\n};\r\n\r\nstruct CArchiveDatabase\r\n{\r\n  CRecordVector<UInt64> PackSizes;\r\n  CRecordVector<bool> PackCRCsDefined;\r\n  CRecordVector<UInt32> PackCRCs;\r\n  CObjectVector<CFolder> Folders;\r\n  CRecordVector<CNum> NumUnpackStreamsVector;\r\n  CObjectVector<CFileItem> Files;\r\n\r\n  CUInt64DefVector CTime;\r\n  CUInt64DefVector ATime;\r\n  CUInt64DefVector MTime;\r\n  CUInt64DefVector StartPos;\r\n  CRecordVector<bool> IsAnti;\r\n\r\n  void Clear()\r\n  {\r\n    PackSizes.Clear();\r\n    PackCRCsDefined.Clear();\r\n    PackCRCs.Clear();\r\n    Folders.Clear();\r\n    NumUnpackStreamsVector.Clear();\r\n    Files.Clear();\r\n    CTime.Clear();\r\n    ATime.Clear();\r\n    MTime.Clear();\r\n    StartPos.Clear();\r\n    IsAnti.Clear();\r\n  }\r\n\r\n  void ReserveDown()\r\n  {\r\n    PackSizes.ReserveDown();\r\n    PackCRCsDefined.ReserveDown();\r\n    PackCRCs.ReserveDown();\r\n    Folders.ReserveDown();\r\n    NumUnpackStreamsVector.ReserveDown();\r\n    Files.ReserveDown();\r\n    CTime.ReserveDown();\r\n    ATime.ReserveDown();\r\n    MTime.ReserveDown();\r\n    StartPos.ReserveDown();\r\n    IsAnti.ReserveDown();\r\n  }\r\n\r\n  bool IsEmpty() const\r\n  {\r\n    return (PackSizes.IsEmpty() &&\r\n      PackCRCsDefined.IsEmpty() &&\r\n      PackCRCs.IsEmpty() &&\r\n      Folders.IsEmpty() &&\r\n      NumUnpackStreamsVector.IsEmpty() &&\r\n      Files.IsEmpty());\r\n  }\r\n\r\n  bool CheckNumFiles() const\r\n  {\r\n    int size = Files.Size();\r\n    return (\r\n      CTime.CheckSize(size) &&\r\n      ATime.CheckSize(size) &&\r\n      MTime.CheckSize(size) &&\r\n      StartPos.CheckSize(size) &&\r\n      (size == IsAnti.Size() || IsAnti.Size() == 0));\r\n  }\r\n\r\n  bool IsSolid() const\r\n  {\r\n    for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)\r\n      if (NumUnpackStreamsVector[i] > 1)\r\n        return true;\r\n    return false;\r\n  }\r\n  bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }\r\n  void SetItemAnti(int index, bool isAnti)\r\n  {\r\n    while (index >= IsAnti.Size())\r\n      IsAnti.Add(false);\r\n    IsAnti[index] = isAnti;\r\n  }\r\n\r\n  void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;\r\n  void AddFile(const CFileItem &file, const CFileItem2 &file2);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zOut.cpp",
    "content": "// 7zOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/AutoPtr.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zOut.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nstatic HRESULT WriteBytes(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size > 0)\r\n  {\r\n    UInt32 curSize = (UInt32)MyMin(size, (size_t)0xFFFFFFFF);\r\n    UInt32 processedSize;\r\n    RINOK(stream->Write(data, curSize, &processedSize));\r\n    if (processedSize == 0)\r\n      return E_FAIL;\r\n    data = (const void *)((const Byte *)data + processedSize);\r\n    size -= processedSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nHRESULT COutArchive::WriteDirect(const void *data, UInt32 size)\r\n{\r\n  return ::WriteBytes(SeqStream, data, size);\r\n}\r\n\r\nHRESULT COutArchive::WriteSignature()\r\n{\r\n  Byte buf[8];\r\n  memcpy(buf, kSignature, kSignatureSize);\r\n  buf[kSignatureSize] = kMajorVersion;\r\n  buf[kSignatureSize + 1] = 3;\r\n  return WriteDirect(buf, 8);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishSignature()\r\n{\r\n  RINOK(WriteDirect(kFinishSignature, kSignatureSize));\r\n  CArchiveVersion av;\r\n  av.Major = kMajorVersion;\r\n  av.Minor = 2;\r\n  RINOK(WriteDirectByte(av.Major));\r\n  return WriteDirectByte(av.Minor);\r\n}\r\n#endif\r\n\r\nstatic void SetUInt32(Byte *p, UInt32 d)\r\n{\r\n  for (int i = 0; i < 4; i++, d >>= 8)\r\n    p[i] = (Byte)d;\r\n}\r\n\r\nstatic void SetUInt64(Byte *p, UInt64 d)\r\n{\r\n  for (int i = 0; i < 8; i++, d >>= 8)\r\n    p[i] = (Byte)d;\r\n}\r\n\r\nHRESULT COutArchive::WriteStartHeader(const CStartHeader &h)\r\n{\r\n  Byte buf[24];\r\n  SetUInt64(buf + 4, h.NextHeaderOffset);\r\n  SetUInt64(buf + 12, h.NextHeaderSize);\r\n  SetUInt32(buf + 20, h.NextHeaderCRC);\r\n  SetUInt32(buf, CrcCalc(buf + 4, 20));\r\n  return WriteDirect(buf, 24);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)\r\n{\r\n  CCRC crc;\r\n  crc.UpdateUInt64(h.NextHeaderOffset);\r\n  crc.UpdateUInt64(h.NextHeaderSize);\r\n  crc.UpdateUInt32(h.NextHeaderCRC);\r\n  crc.UpdateUInt64(h.ArchiveStartOffset);\r\n  crc.UpdateUInt64(h.AdditionalStartBlockSize);\r\n  RINOK(WriteDirectUInt32(crc.GetDigest()));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  RINOK(WriteDirectUInt32(h.NextHeaderCRC));\r\n  RINOK(WriteDirectUInt64(h.ArchiveStartOffset));\r\n  return WriteDirectUInt64(h.AdditionalStartBlockSize);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)\r\n{\r\n  Close();\r\n  #ifdef _7Z_VOL\r\n  // endMarker = false;\r\n  _endMarker = endMarker;\r\n  #endif\r\n  SeqStream = stream;\r\n  if (!endMarker)\r\n  {\r\n    SeqStream.QueryInterface(IID_IOutStream, &Stream);\r\n    if (!Stream)\r\n    {\r\n      return E_NOTIMPL;\r\n      // endMarker = true;\r\n    }\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (endMarker)\r\n  {\r\n    /*\r\n    CStartHeader sh;\r\n    sh.NextHeaderOffset = (UInt32)(Int32)-1;\r\n    sh.NextHeaderSize = (UInt32)(Int32)-1;\r\n    sh.NextHeaderCRC = 0;\r\n    WriteStartHeader(sh);\r\n    */\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!Stream)\r\n      return E_FAIL;\r\n    RINOK(WriteSignature());\r\n    RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutArchive::Close()\r\n{\r\n  SeqStream.Release();\r\n  Stream.Release();\r\n}\r\n\r\nHRESULT COutArchive::SkeepPrefixArchiveHeader()\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n    return S_OK;\r\n  #endif\r\n  return Stream->Seek(24, STREAM_SEEK_CUR, NULL);\r\n}\r\n\r\nUInt64 COutArchive::GetPos() const\r\n{\r\n  if (_countMode)\r\n    return _countSize;\r\n  if (_writeToStream)\r\n    return _outByte.GetProcessedSize();\r\n  return _outByte2.GetPos();\r\n}\r\n\r\nvoid COutArchive::WriteBytes(const void *data, size_t size)\r\n{\r\n  if (_countMode)\r\n    _countSize += size;\r\n  else if (_writeToStream)\r\n  {\r\n    _outByte.WriteBytes(data, size);\r\n    _crc = CrcUpdate(_crc, data, size);\r\n  }\r\n  else\r\n    _outByte2.WriteBytes(data, size);\r\n}\r\n\r\nvoid COutArchive::WriteByte(Byte b)\r\n{\r\n  if (_countMode)\r\n    _countSize++;\r\n  else if (_writeToStream)\r\n  {\r\n    _outByte.WriteByte(b);\r\n    _crc = CRC_UPDATE_BYTE(_crc, b);\r\n  }\r\n  else\r\n    _outByte2.WriteByte(b);\r\n}\r\n\r\nvoid COutArchive::WriteUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nvoid COutArchive::WriteUInt64(UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nvoid COutArchive::WriteNumber(UInt64 value)\r\n{\r\n  Byte firstByte = 0;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n    {\r\n      firstByte |= Byte(value >> (8 * i));\r\n      break;\r\n    }\r\n    firstByte |= mask;\r\n    mask >>= 1;\r\n  }\r\n  WriteByte(firstByte);\r\n  for (;i > 0; i--)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nstatic UInt32 GetBigNumberSize(UInt64 value)\r\n{\r\n  int i;\r\n  for (i = 1; i < 9; i++)\r\n    if (value < (((UInt64)1 << (i * 7))))\r\n      break;\r\n  return i;\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nUInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)\r\n{\r\n  UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;\r\n  if (nameLength != 0)\r\n  {\r\n    nameLength = (nameLength + 1) * 2;\r\n    result += nameLength + GetBigNumberSize(nameLength) + 2;\r\n  }\r\n  if (props)\r\n  {\r\n    result += 20;\r\n  }\r\n  if (result >= 128)\r\n    result++;\r\n  result += kSignatureSize + 2 + kFinishHeaderSize;\r\n  return result;\r\n}\r\n\r\nUInt64 COutArchive::GetVolPureSize(UInt64 volSize, int nameLength, bool props)\r\n{\r\n  UInt32 headersSizeBase = COutArchive::GetVolHeadersSize(1, nameLength, props);\r\n  int testSize;\r\n  if (volSize > headersSizeBase)\r\n    testSize = volSize - headersSizeBase;\r\n  else\r\n    testSize = 1;\r\n  UInt32 headersSize = COutArchive::GetVolHeadersSize(testSize, nameLength, props);\r\n  UInt64 pureSize = 1;\r\n  if (volSize > headersSize)\r\n    pureSize = volSize - headersSize;\r\n  return pureSize;\r\n}\r\n#endif\r\n\r\nvoid COutArchive::WriteFolder(const CFolder &folder)\r\n{\r\n  WriteNumber(folder.Coders.Size());\r\n  int i;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    const CCoderInfo &coder = folder.Coders[i];\r\n    {\r\n      size_t propsSize = coder.Props.GetCapacity();\r\n      \r\n      UInt64 id = coder.MethodID;\r\n      int idSize;\r\n      for (idSize = 1; idSize < sizeof(id); idSize++)\r\n        if ((id >> (8 * idSize)) == 0)\r\n          break;\r\n      BYTE longID[15];\r\n      for (int t = idSize - 1; t >= 0 ; t--, id >>= 8)\r\n        longID[t] = (Byte)(id & 0xFF);\r\n      Byte b;\r\n      b = (Byte)(idSize & 0xF);\r\n      bool isComplex = !coder.IsSimpleCoder();\r\n      b |= (isComplex ? 0x10 : 0);\r\n      b |= ((propsSize != 0) ? 0x20 : 0 );\r\n      WriteByte(b);\r\n      WriteBytes(longID, idSize);\r\n      if (isComplex)\r\n      {\r\n        WriteNumber(coder.NumInStreams);\r\n        WriteNumber(coder.NumOutStreams);\r\n      }\r\n      if (propsSize == 0)\r\n        continue;\r\n      WriteNumber(propsSize);\r\n      WriteBytes(coder.Props, propsSize);\r\n    }\r\n  }\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = folder.BindPairs[i];\r\n    WriteNumber(bindPair.InIndex);\r\n    WriteNumber(bindPair.OutIndex);\r\n  }\r\n  if (folder.PackStreams.Size() > 1)\r\n    for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    {\r\n      WriteNumber(folder.PackStreams[i]);\r\n    }\r\n}\r\n\r\nvoid COutArchive::WriteBoolVector(const CBoolVector &boolVector)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0x80;\r\n  for (int i = 0; i < boolVector.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n      b |= mask;\r\n    mask >>= 1;\r\n    if (mask == 0)\r\n    {\r\n      WriteByte(b);\r\n      mask = 0x80;\r\n      b = 0;\r\n    }\r\n  }\r\n  if (mask != 0x80)\r\n    WriteByte(b);\r\n}\r\n\r\n\r\nvoid COutArchive::WriteHashDigests(\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  int numDefined = 0;\r\n  int i;\r\n  for (i = 0; i < digestsDefined.Size(); i++)\r\n    if (digestsDefined[i])\r\n      numDefined++;\r\n  if (numDefined == 0)\r\n    return;\r\n\r\n  WriteByte(NID::kCRC);\r\n  if (numDefined == digestsDefined.Size())\r\n    WriteByte(1);\r\n  else\r\n  {\r\n    WriteByte(0);\r\n    WriteBoolVector(digestsDefined);\r\n  }\r\n  for (i = 0; i < digests.Size(); i++)\r\n    if (digestsDefined[i])\r\n      WriteUInt32(digests[i]);\r\n}\r\n\r\nvoid COutArchive::WritePackInfo(\r\n    UInt64 dataOffset,\r\n    const CRecordVector<UInt64> &packSizes,\r\n    const CRecordVector<bool> &packCRCsDefined,\r\n    const CRecordVector<UInt32> &packCRCs)\r\n{\r\n  if (packSizes.IsEmpty())\r\n    return;\r\n  WriteByte(NID::kPackInfo);\r\n  WriteNumber(dataOffset);\r\n  WriteNumber(packSizes.Size());\r\n  WriteByte(NID::kSize);\r\n  for (int i = 0; i < packSizes.Size(); i++)\r\n    WriteNumber(packSizes[i]);\r\n\r\n  WriteHashDigests(packCRCsDefined, packCRCs);\r\n  \r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::WriteUnpackInfo(const CObjectVector<CFolder> &folders)\r\n{\r\n  if (folders.IsEmpty())\r\n    return;\r\n\r\n  WriteByte(NID::kUnpackInfo);\r\n\r\n  WriteByte(NID::kFolder);\r\n  WriteNumber(folders.Size());\r\n  {\r\n    WriteByte(0);\r\n    for (int i = 0; i < folders.Size(); i++)\r\n      WriteFolder(folders[i]);\r\n  }\r\n  \r\n  WriteByte(NID::kCodersUnpackSize);\r\n  int i;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    for (int j = 0; j < folder.UnpackSizes.Size(); j++)\r\n      WriteNumber(folder.UnpackSizes[j]);\r\n  }\r\n\r\n  CRecordVector<bool> unpackCRCsDefined;\r\n  CRecordVector<UInt32> unpackCRCs;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    unpackCRCsDefined.Add(folder.UnpackCRCDefined);\r\n    unpackCRCs.Add(folder.UnpackCRC);\r\n  }\r\n  WriteHashDigests(unpackCRCsDefined, unpackCRCs);\r\n\r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::WriteSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    const CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    const CRecordVector<UInt64> &unpackSizes,\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  WriteByte(NID::kSubStreamsInfo);\r\n\r\n  int i;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n  {\r\n    if (numUnpackStreamsInFolders[i] != 1)\r\n    {\r\n      WriteByte(NID::kNumUnpackStream);\r\n      for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n        WriteNumber(numUnpackStreamsInFolders[i]);\r\n      break;\r\n    }\r\n  }\r\n \r\n\r\n  bool needFlag = true;\r\n  CNum index = 0;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n    for (CNum j = 0; j < numUnpackStreamsInFolders[i]; j++)\r\n    {\r\n      if (j + 1 != numUnpackStreamsInFolders[i])\r\n      {\r\n        if (needFlag)\r\n          WriteByte(NID::kSize);\r\n        needFlag = false;\r\n        WriteNumber(unpackSizes[index]);\r\n      }\r\n      index++;\r\n    }\r\n\r\n  CRecordVector<bool> digestsDefined2;\r\n  CRecordVector<UInt32> digests2;\r\n\r\n  int digestIndex = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    int numSubStreams = (int)numUnpackStreamsInFolders[i];\r\n    if (numSubStreams == 1 && folders[i].UnpackCRCDefined)\r\n      digestIndex++;\r\n    else\r\n      for (int j = 0; j < numSubStreams; j++, digestIndex++)\r\n      {\r\n        digestsDefined2.Add(digestsDefined[digestIndex]);\r\n        digests2.Add(digests[digestIndex]);\r\n      }\r\n  }\r\n  WriteHashDigests(digestsDefined2, digests2);\r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::SkipAlign(unsigned /* pos */, unsigned /* alignSize */)\r\n{\r\n  return;\r\n}\r\n\r\n/*\r\n7-Zip 4.50 - 4.58 contain BUG, so they do not support .7z archives with Unknown field.\r\n\r\nvoid COutArchive::SkipAlign(unsigned pos, unsigned alignSize)\r\n{\r\n  pos += (unsigned)GetPos();\r\n  pos &= (alignSize - 1);\r\n  if (pos == 0)\r\n    return;\r\n  unsigned skip = alignSize - pos;\r\n  if (skip < 2)\r\n    skip += alignSize;\r\n  skip -= 2;\r\n  WriteByte(NID::kDummy);\r\n  WriteByte((Byte)skip);\r\n  for (unsigned i = 0; i < skip; i++)\r\n    WriteByte(0);\r\n}\r\n*/\r\n\r\nvoid COutArchive::WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize)\r\n{\r\n  const UInt64 bvSize = (numDefined == v.Size()) ? 0 : (v.Size() + 7) / 8;\r\n  const UInt64 dataSize = (UInt64)numDefined * itemSize + bvSize + 2;\r\n  SkipAlign(3 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), itemSize);\r\n\r\n  WriteByte(type);\r\n  WriteNumber(dataSize);\r\n  if (numDefined == v.Size())\r\n    WriteByte(1);\r\n  else\r\n  {\r\n    WriteByte(0);\r\n    WriteBoolVector(v);\r\n  }\r\n  WriteByte(0);\r\n}\r\n\r\nvoid COutArchive::WriteUInt64DefVector(const CUInt64DefVector &v, Byte type)\r\n{\r\n  int numDefined = 0;\r\n\r\n  int i;\r\n  for (i = 0; i < v.Defined.Size(); i++)\r\n    if (v.Defined[i])\r\n      numDefined++;\r\n\r\n  if (numDefined == 0)\r\n    return;\r\n\r\n  WriteAlignedBoolHeader(v.Defined, numDefined, type, 8);\r\n  \r\n  for (i = 0; i < v.Defined.Size(); i++)\r\n    if (v.Defined[i])\r\n      WriteUInt64(v.Values[i]);\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const Byte *data, size_t dataSize,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  CSequentialInStreamImp *streamSpec = new CSequentialInStreamImp;\r\n  CMyComPtr<ISequentialInStream> stream = streamSpec;\r\n  streamSpec->Init(data, dataSize);\r\n  CFolder folderItem;\r\n  folderItem.UnpackCRCDefined = true;\r\n  folderItem.UnpackCRC = CrcCalc(data, dataSize);\r\n  UInt64 dataSize64 = dataSize;\r\n  RINOK(encoder.Encode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      stream, NULL, &dataSize64, folderItem, SeqStream, packSizes, NULL))\r\n  folders.Add(folderItem);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const CByteBuffer &data,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  return EncodeStream(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      encoder, data, data.GetCapacity(), packSizes, folders);\r\n}\r\n\r\nvoid COutArchive::WriteHeader(\r\n    const CArchiveDatabase &db,\r\n    const CHeaderOptions &headerOptions,\r\n    UInt64 &headerOffset)\r\n{\r\n  int i;\r\n  \r\n  UInt64 packedSize = 0;\r\n  for (i = 0; i < db.PackSizes.Size(); i++)\r\n    packedSize += db.PackSizes[i];\r\n\r\n  headerOffset = packedSize;\r\n\r\n  WriteByte(NID::kHeader);\r\n\r\n  // Archive Properties\r\n\r\n  if (db.Folders.Size() > 0)\r\n  {\r\n    WriteByte(NID::kMainStreamsInfo);\r\n    WritePackInfo(0, db.PackSizes,\r\n        db.PackCRCsDefined,\r\n        db.PackCRCs);\r\n\r\n    WriteUnpackInfo(db.Folders);\r\n\r\n    CRecordVector<UInt64> unpackSizes;\r\n    CRecordVector<bool> digestsDefined;\r\n    CRecordVector<UInt32> digests;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = db.Files[i];\r\n      if (!file.HasStream)\r\n        continue;\r\n      unpackSizes.Add(file.Size);\r\n      digestsDefined.Add(file.CrcDefined);\r\n      digests.Add(file.Crc);\r\n    }\r\n\r\n    WriteSubStreamsInfo(\r\n        db.Folders,\r\n        db.NumUnpackStreamsVector,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    WriteByte(NID::kEnd);\r\n  }\r\n\r\n  if (db.Files.IsEmpty())\r\n  {\r\n    WriteByte(NID::kEnd);\r\n    return;\r\n  }\r\n\r\n  WriteByte(NID::kFilesInfo);\r\n  WriteNumber(db.Files.Size());\r\n\r\n  {\r\n  /* ---------- Empty Streams ---------- */\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve(db.Files.Size());\r\n  int numEmptyStreams = 0;\r\n  for (i = 0; i < db.Files.Size(); i++)\r\n    if (db.Files[i].HasStream)\r\n      emptyStreamVector.Add(false);\r\n    else\r\n    {\r\n      emptyStreamVector.Add(true);\r\n      numEmptyStreams++;\r\n    }\r\n  if (numEmptyStreams > 0)\r\n  {\r\n    WriteByte(NID::kEmptyStream);\r\n    WriteNumber((emptyStreamVector.Size() + 7) / 8);\r\n    WriteBoolVector(emptyStreamVector);\r\n\r\n    CBoolVector emptyFileVector, antiVector;\r\n    emptyFileVector.Reserve(numEmptyStreams);\r\n    antiVector.Reserve(numEmptyStreams);\r\n    CNum numEmptyFiles = 0, numAntiItems = 0;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = db.Files[i];\r\n      if (!file.HasStream)\r\n      {\r\n        emptyFileVector.Add(!file.IsDir);\r\n        if (!file.IsDir)\r\n          numEmptyFiles++;\r\n        bool isAnti = db.IsItemAnti(i);\r\n        antiVector.Add(isAnti);\r\n        if (isAnti)\r\n          numAntiItems++;\r\n      }\r\n    }\r\n\r\n    if (numEmptyFiles > 0)\r\n    {\r\n      WriteByte(NID::kEmptyFile);\r\n      WriteNumber((emptyFileVector.Size() + 7) / 8);\r\n      WriteBoolVector(emptyFileVector);\r\n    }\r\n\r\n    if (numAntiItems > 0)\r\n    {\r\n      WriteByte(NID::kAnti);\r\n      WriteNumber((antiVector.Size() + 7) / 8);\r\n      WriteBoolVector(antiVector);\r\n    }\r\n  }\r\n  }\r\n\r\n\r\n  {\r\n    /* ---------- Names ---------- */\r\n    \r\n    int numDefined = 0;\r\n    size_t namesDataSize = 0;\r\n    for (int i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const UString &name = db.Files[i].Name;\r\n      if (!name.IsEmpty())\r\n        numDefined++;\r\n      namesDataSize += (name.Length() + 1) * 2;\r\n    }\r\n    \r\n    if (numDefined > 0)\r\n    {\r\n      namesDataSize++;\r\n      SkipAlign(2 + GetBigNumberSize(namesDataSize), 2);\r\n\r\n      WriteByte(NID::kName);\r\n      WriteNumber(namesDataSize);\r\n      WriteByte(0);\r\n      for (int i = 0; i < db.Files.Size(); i++)\r\n      {\r\n        const UString &name = db.Files[i].Name;\r\n        for (int t = 0; t <= name.Length(); t++)\r\n        {\r\n          wchar_t c = name[t];\r\n          WriteByte((Byte)c);\r\n          WriteByte((Byte)(c >> 8));\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (headerOptions.WriteCTime) WriteUInt64DefVector(db.CTime, NID::kCTime);\r\n  if (headerOptions.WriteATime) WriteUInt64DefVector(db.ATime, NID::kATime);\r\n  if (headerOptions.WriteMTime) WriteUInt64DefVector(db.MTime, NID::kMTime);\r\n  WriteUInt64DefVector(db.StartPos, NID::kStartPos);\r\n  \r\n  {\r\n    /* ---------- Write Attrib ---------- */\r\n    CBoolVector boolVector;\r\n    boolVector.Reserve(db.Files.Size());\r\n    int numDefined = 0;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      bool defined = db.Files[i].AttribDefined;\r\n      boolVector.Add(defined);\r\n      if (defined)\r\n        numDefined++;\r\n    }\r\n    if (numDefined > 0)\r\n    {\r\n      WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttributes, 4);\r\n      for (i = 0; i < db.Files.Size(); i++)\r\n      {\r\n        const CFileItem &file = db.Files[i];\r\n        if (file.AttribDefined)\r\n          WriteUInt32(file.Attrib);\r\n      }\r\n    }\r\n  }\r\n\r\n  WriteByte(NID::kEnd); // for files\r\n  WriteByte(NID::kEnd); // for headers\r\n}\r\n\r\nHRESULT COutArchive::WriteDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CArchiveDatabase &db,\r\n    const CCompressionMethodMode *options,\r\n    const CHeaderOptions &headerOptions)\r\n{\r\n  if (!db.CheckNumFiles())\r\n    return E_FAIL;\r\n\r\n  UInt64 headerOffset;\r\n  UInt32 headerCRC;\r\n  UInt64 headerSize;\r\n  if (db.IsEmpty())\r\n  {\r\n    headerSize = 0;\r\n    headerOffset = 0;\r\n    headerCRC = CrcCalc(0, 0);\r\n  }\r\n  else\r\n  {\r\n    bool encodeHeaders = false;\r\n    if (options != 0)\r\n      if (options->IsEmpty())\r\n        options = 0;\r\n    if (options != 0)\r\n      if (options->PasswordIsDefined || headerOptions.CompressMainHeader)\r\n        encodeHeaders = true;\r\n\r\n    _outByte.SetStream(SeqStream);\r\n    _outByte.Init();\r\n    _crc = CRC_INIT_VAL;\r\n    _countMode = encodeHeaders;\r\n    _writeToStream = true;\r\n    _countSize = 0;\r\n    WriteHeader(db, headerOptions, headerOffset);\r\n\r\n    if (encodeHeaders)\r\n    {\r\n      CByteBuffer buf;\r\n      buf.SetCapacity(_countSize);\r\n      _outByte2.Init((Byte *)buf, _countSize);\r\n      \r\n      _countMode = false;\r\n      _writeToStream = false;\r\n      WriteHeader(db, headerOptions, headerOffset);\r\n      \r\n      if (_countSize != _outByte2.GetPos())\r\n        return E_FAIL;\r\n\r\n      CCompressionMethodMode encryptOptions;\r\n      encryptOptions.PasswordIsDefined = options->PasswordIsDefined;\r\n      encryptOptions.Password = options->Password;\r\n      CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions);\r\n      CRecordVector<UInt64> packSizes;\r\n      CObjectVector<CFolder> folders;\r\n      RINOK(EncodeStream(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          encoder, (const Byte *)buf,\r\n          _countSize, packSizes, folders));\r\n\r\n      _writeToStream = true;\r\n      \r\n      if (folders.Size() == 0)\r\n        throw 1;\r\n\r\n      WriteID(NID::kEncodedHeader);\r\n      WritePackInfo(headerOffset, packSizes,\r\n        CRecordVector<bool>(), CRecordVector<UInt32>());\r\n      WriteUnpackInfo(folders);\r\n      WriteByte(NID::kEnd);\r\n      for (int i = 0; i < packSizes.Size(); i++)\r\n        headerOffset += packSizes[i];\r\n    }\r\n    RINOK(_outByte.Flush());\r\n    headerCRC = CRC_GET_DIGEST(_crc);\r\n    headerSize = _outByte.GetProcessedSize();\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n  {\r\n    CFinishHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset =\r\n        UInt64(0) - (headerSize +\r\n        4 + kFinishHeaderSize);\r\n    h.ArchiveStartOffset = h.NextHeaderOffset - headerOffset;\r\n    h.AdditionalStartBlockSize = 0;\r\n    RINOK(WriteFinishHeader(h));\r\n    return WriteFinishSignature();\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    CStartHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = headerOffset;\r\n    RINOK(Stream->Seek(_prefixHeaderPos, STREAM_SEEK_SET, NULL));\r\n    return WriteStartHeader(h);\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabase::GetFile(int index, CFileItem &file, CFileItem2 &file2) const\r\n{\r\n  file = Files[index];\r\n  file2.CTimeDefined = CTime.GetItem(index, file2.CTime);\r\n  file2.ATimeDefined = ATime.GetItem(index, file2.ATime);\r\n  file2.MTimeDefined = MTime.GetItem(index, file2.MTime);\r\n  file2.StartPosDefined = StartPos.GetItem(index, file2.StartPos);\r\n  file2.IsAnti = IsItemAnti(index);\r\n}\r\n\r\nvoid CArchiveDatabase::AddFile(const CFileItem &file, const CFileItem2 &file2)\r\n{\r\n  int index = Files.Size();\r\n  CTime.SetItem(index, file2.CTimeDefined, file2.CTime);\r\n  ATime.SetItem(index, file2.ATimeDefined, file2.ATime);\r\n  MTime.SetItem(index, file2.MTimeDefined, file2.MTime);\r\n  StartPos.SetItem(index, file2.StartPosDefined, file2.StartPos);\r\n  SetItemAnti(index, file2.IsAnti);\r\n  Files.Add(file);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zOut.h",
    "content": "// 7z/Out.h\r\n\r\n#ifndef __7Z_OUT_H\r\n#define __7Z_OUT_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zCompressionMode.h\"\r\n#include \"7zEncode.h\"\r\n\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CWriteBufferLoc\r\n{\r\n  Byte *_data;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  CWriteBufferLoc(): _size(0), _pos(0) {}\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    _data = data;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    if (size > _size - _pos)\r\n      throw 1;\r\n    memcpy(_data + _pos, data, size);\r\n    _pos += size;\r\n  }\r\n  void WriteByte(Byte b)\r\n  {\r\n    if (_size == _pos)\r\n      throw 1;\r\n    _data[_pos++] = b;\r\n  }\r\n  size_t GetPos() const { return _pos; }\r\n};\r\n\r\nstruct CHeaderOptions\r\n{\r\n  bool CompressMainHeader;\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  CHeaderOptions():\r\n      CompressMainHeader(true),\r\n      WriteCTime(false),\r\n      WriteATime(false),\r\n      WriteMTime(true)\r\n      {}\r\n};\r\n\r\nclass COutArchive\r\n{\r\n  UInt64 _prefixHeaderPos;\r\n\r\n  HRESULT WriteDirect(const void *data, UInt32 size);\r\n  \r\n  UInt64 GetPos() const;\r\n  void WriteBytes(const void *data, size_t size);\r\n  void WriteBytes(const CByteBuffer &data) { WriteBytes(data, data.GetCapacity()); }\r\n  void WriteByte(Byte b);\r\n  void WriteUInt32(UInt32 value);\r\n  void WriteUInt64(UInt64 value);\r\n  void WriteNumber(UInt64 value);\r\n  void WriteID(UInt64 value) { WriteNumber(value); }\r\n\r\n  void WriteFolder(const CFolder &folder);\r\n  HRESULT WriteFileHeader(const CFileItem &itemInfo);\r\n  void WriteBoolVector(const CBoolVector &boolVector);\r\n  void WriteHashDigests(\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  void WritePackInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs);\r\n\r\n  void WriteUnpackInfo(const CObjectVector<CFolder> &folders);\r\n\r\n  void WriteSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unpackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  void SkipAlign(unsigned pos, unsigned alignSize);\r\n  void WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize);\r\n  void WriteUInt64DefVector(const CUInt64DefVector &v, Byte type);\r\n\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const Byte *data, size_t dataSize,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const CByteBuffer &data,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  void WriteHeader(\r\n      const CArchiveDatabase &db,\r\n      const CHeaderOptions &headerOptions,\r\n      UInt64 &headerOffset);\r\n  \r\n  bool _countMode;\r\n  bool _writeToStream;\r\n  size_t _countSize;\r\n  UInt32 _crc;\r\n  COutBuffer _outByte;\r\n  CWriteBufferLoc _outByte2;\r\n\r\n  #ifdef _7Z_VOL\r\n  bool _endMarker;\r\n  #endif\r\n\r\n  HRESULT WriteSignature();\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishSignature();\r\n  #endif\r\n  HRESULT WriteStartHeader(const CStartHeader &h);\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishHeader(const CFinishHeader &h);\r\n  #endif\r\n  CMyComPtr<IOutStream> Stream;\r\npublic:\r\n\r\n  COutArchive() { _outByte.Create(1 << 16); }\r\n  CMyComPtr<ISequentialOutStream> SeqStream;\r\n  HRESULT Create(ISequentialOutStream *stream, bool endMarker);\r\n  void Close();\r\n  HRESULT SkeepPrefixArchiveHeader();\r\n  HRESULT WriteDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CArchiveDatabase &db,\r\n      const CCompressionMethodMode *options,\r\n      const CHeaderOptions &headerOptions);\r\n\r\n  #ifdef _7Z_VOL\r\n  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);\r\n  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);\r\n  #endif\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zProperties.cpp",
    "content": "// 7zProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zProperties.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zHandler.h\"\r\n\r\n// #define _MULTI_PACK\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CPropMap\r\n{\r\n  UInt64 FilePropID;\r\n  STATPROPSTG StatPROPSTG;\r\n};\r\n\r\nCPropMap kPropMap[] =\r\n{\r\n  { NID::kName, NULL, kpidPath, VT_BSTR},\r\n  { NID::kSize, NULL, kpidSize, VT_UI8},\r\n  { NID::kPackInfo, NULL, kpidPackSize, VT_UI8},\r\n  \r\n  #ifdef _MULTI_PACK\r\n  { 100, L\"Pack0\", kpidPackedSize0, VT_UI8},\r\n  { 101, L\"Pack1\", kpidPackedSize1, VT_UI8},\r\n  { 102, L\"Pack2\", kpidPackedSize2, VT_UI8},\r\n  { 103, L\"Pack3\", kpidPackedSize3, VT_UI8},\r\n  { 104, L\"Pack4\", kpidPackedSize4, VT_UI8},\r\n  #endif\r\n\r\n  { NID::kCTime, NULL, kpidCTime, VT_FILETIME},\r\n  { NID::kMTime, NULL, kpidMTime, VT_FILETIME},\r\n  { NID::kATime, NULL, kpidATime, VT_FILETIME},\r\n  { NID::kWinAttributes, NULL, kpidAttrib, VT_UI4},\r\n  { NID::kStartPos, NULL, kpidPosition, VT_UI4},\r\n\r\n  { NID::kCRC, NULL, kpidCRC, VT_UI4},\r\n  \r\n  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},\r\n\r\n  #ifndef _SFX\r\n  { 97, NULL, kpidEncrypted, VT_BOOL},\r\n  { 98, NULL, kpidMethod, VT_BSTR},\r\n  { 99, NULL, kpidBlock, VT_UI4}\r\n  #endif\r\n};\r\n\r\nstatic const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);\r\n\r\nstatic int FindPropInMap(UInt64 filePropID)\r\n{\r\n  for (int i = 0; i < kPropMapSize; i++)\r\n    if (kPropMap[i].FilePropID == filePropID)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void CopyOneItem(CRecordVector<UInt64> &src,\r\n    CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      dest.Add(item);\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < dest.Size(); i++)\r\n    if (dest[i] == item)\r\n    {\r\n      dest.Delete(i);\r\n      break;\r\n    }\r\n  dest.Insert(0, item);\r\n}\r\n\r\nvoid CHandler::FillPopIDs()\r\n{\r\n  _fileInfoPopIDs.Clear();\r\n\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() < 1)\r\n    return;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_db = volume.Database;\r\n  #endif\r\n\r\n  CRecordVector<UInt64> fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;\r\n\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);\r\n\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);\r\n  _fileInfoPopIDs += fileInfoPopIDs;\r\n \r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Add(97);\r\n  _fileInfoPopIDs.Add(98);\r\n  _fileInfoPopIDs.Add(99);\r\n  #endif\r\n  #ifdef _MULTI_PACK\r\n  _fileInfoPopIDs.Add(100);\r\n  _fileInfoPopIDs.Add(101);\r\n  _fileInfoPopIDs.Add(102);\r\n  _fileInfoPopIDs.Add(103);\r\n  _fileInfoPopIDs.Add(104);\r\n  #endif\r\n\r\n  #ifndef _SFX\r\n  InsertToHead(_fileInfoPopIDs, NID::kMTime);\r\n  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);\r\n  InsertToHead(_fileInfoPopIDs, NID::kSize);\r\n  InsertToHead(_fileInfoPopIDs, NID::kName);\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)\r\n{\r\n  *numProperties = _fileInfoPopIDs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)\r\n{\r\n  if ((int)index >= _fileInfoPopIDs.Size())\r\n    return E_INVALIDARG;\r\n  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);\r\n  if (indexInMap == -1)\r\n    return E_INVALIDARG;\r\n  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;\r\n  *propID = srcItem.propid;\r\n  *varType = srcItem.vt;\r\n  *name = 0;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zProperties.h",
    "content": "// 7zProperties.h\r\n\r\n#ifndef __7Z_PROPERTIES_H\r\n#define __7Z_PROPERTIES_H\r\n\r\n#include \"../../PropID.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nenum\r\n{\r\n  kpidPackedSize0 = kpidUserDefined,\r\n  kpidPackedSize1,\r\n  kpidPackedSize2,\r\n  kpidPackedSize3,\r\n  kpidPackedSize4\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zRegister.cpp",
    "content": "// 7zRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"7zHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::N7z::CHandler;  }\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"7z\", L\"7z\", 0, 7, {'7' + 1 , 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };\r\n\r\nREGISTER_ARC_DEC_SIG(7z)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zSpecStream.cpp",
    "content": "// 7zSpecStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zSpecStream.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(\r\n    UInt64 subStream, UInt64 *value)\r\n{\r\n  if (_getSubStreamSize == NULL)\r\n    return E_NOTIMPL;\r\n  return  _getSubStreamSize->GetSubStreamSize(subStream, value);\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zSpecStream.h",
    "content": "// 7zSpecStream.h\r\n\r\n#ifndef __7Z_SPEC_STREAM_H\r\n#define __7Z_SPEC_STREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CSequentialInStreamSizeCount2:\r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _getSubStreamSize = 0;\r\n    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zUpdate.cpp",
    "content": "// 7zUpdate.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zFolderInStream.h\"\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kMatchFinderForBCJ2_LZMA = L\"BT2\";\r\nstatic const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;\r\nstatic const UInt32 kAlgorithmForBCJ2_LZMA = 1;\r\nstatic const UInt32 kNumFastBytesForBCJ2_LZMA = 64;\r\n\r\nstatic HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream,\r\n    UInt64 position, UInt64 size, ICompressProgressInfo *progress)\r\n{\r\n  RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));\r\n  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;\r\n  CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);\r\n  streamSpec->SetStream(inStream);\r\n  streamSpec->Init(size);\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n  RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));\r\n  return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);\r\n}\r\n\r\nstatic int GetReverseSlashPos(const UString &name)\r\n{\r\n  int slashPos = name.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = name.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n  return slashPos;\r\n}\r\n\r\nint CUpdateItem::GetExtensionPos() const\r\n{\r\n  int slashPos = GetReverseSlashPos(Name);\r\n  int dotPos = Name.ReverseFind(L'.');\r\n  if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n    return Name.Length();\r\n  return dotPos + 1;\r\n}\r\n\r\nUString CUpdateItem::GetExtension() const\r\n{\r\n  return Name.Mid(GetExtensionPos());\r\n}\r\n\r\n#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }\r\n\r\nstatic int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)\r\n{\r\n  size_t c1 = a1.GetCapacity();\r\n  size_t c2 = a2.GetCapacity();\r\n  RINOZ(MyCompare(c1, c2));\r\n  for (size_t i = 0; i < c1; i++)\r\n    RINOZ(MyCompare(a1[i], a2[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareCoders(const CCoderInfo &c1, const CCoderInfo &c2)\r\n{\r\n  RINOZ(MyCompare(c1.NumInStreams, c2.NumInStreams));\r\n  RINOZ(MyCompare(c1.NumOutStreams, c2.NumOutStreams));\r\n  RINOZ(MyCompare(c1.MethodID, c2.MethodID));\r\n  return CompareBuffers(c1.Props, c2.Props);\r\n}\r\n\r\nstatic int CompareBindPairs(const CBindPair &b1, const CBindPair &b2)\r\n{\r\n  RINOZ(MyCompare(b1.InIndex, b2.InIndex));\r\n  return MyCompare(b1.OutIndex, b2.OutIndex);\r\n}\r\n\r\nstatic int CompareFolders(const CFolder &f1, const CFolder &f2)\r\n{\r\n  int s1 = f1.Coders.Size();\r\n  int s2 = f2.Coders.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  int i;\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareCoders(f1.Coders[i], f2.Coders[i]));\r\n  s1 = f1.BindPairs.Size();\r\n  s2 = f2.BindPairs.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareBindPairs(f1.BindPairs[i], f2.BindPairs[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareFiles(const CFileItem &f1, const CFileItem &f2)\r\n{\r\n  return MyStringCompareNoCase(f1.Name, f2.Name);\r\n}\r\n\r\nstatic int CompareFolderRefs(const int *p1, const int *p2, void *param)\r\n{\r\n  int i1 = *p1;\r\n  int i2 = *p2;\r\n  const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param;\r\n  RINOZ(CompareFolders(\r\n      db.Folders[i1],\r\n      db.Folders[i2]));\r\n  RINOZ(MyCompare(\r\n      db.NumUnpackStreamsVector[i1],\r\n      db.NumUnpackStreamsVector[i2]));\r\n  if (db.NumUnpackStreamsVector[i1] == 0)\r\n    return 0;\r\n  return CompareFiles(\r\n      db.Files[db.FolderStartFileIndex[i1]],\r\n      db.Files[db.FolderStartFileIndex[i2]]);\r\n}\r\n\r\n////////////////////////////////////////////////////////////\r\n\r\nstatic int CompareEmptyItems(const int *p1, const int *p2, void *param)\r\n{\r\n  const CObjectVector<CUpdateItem> &updateItems = *(const CObjectVector<CUpdateItem> *)param;\r\n  const CUpdateItem &u1 = updateItems[*p1];\r\n  const CUpdateItem &u2 = updateItems[*p2];\r\n  if (u1.IsDir != u2.IsDir)\r\n    return (u1.IsDir) ? 1 : -1;\r\n  if (u1.IsDir)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    int n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  if (u1.IsAnti != u2.IsAnti)\r\n    return (u1.IsAnti ? 1 : -1);\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstatic const char *g_Exts =\r\n  \" lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo\"\r\n  \" zip jar ear war msi\"\r\n  \" 3gp avi mov mpeg mpg mpe wmv\"\r\n  \" aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav\"\r\n  \" swf \"\r\n  \" chm hxi hxs\"\r\n  \" gif jpeg jpg jp2 png tiff  bmp ico psd psp\"\r\n  \" awg ps eps cgm dxf svg vrml wmf emf ai md\"\r\n  \" cad dwg pps key sxi\"\r\n  \" max 3ds\"\r\n  \" iso bin nrg mdf img pdi tar cpio xpi\"\r\n  \" vfd vhd vud vmc vsv\"\r\n  \" vmdk dsk nvram vmem vmsd vmsn vmss vmtm\"\r\n  \" inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def\"\r\n  \" f77 f f90 f95\"\r\n  \" asm sql manifest dep \"\r\n  \" mak clw csproj vcproj sln dsp dsw \"\r\n  \" class \"\r\n  \" bat cmd\"\r\n  \" xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml\"\r\n  \" awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs\"\r\n  \" text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf\"\r\n  \" sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf\"\r\n  \" abw afp cwk lwp wpd wps wpt wrf wri\"\r\n  \" abf afm bdf fon mgf otf pcf pfa snf ttf\"\r\n  \" dbf mdb nsf ntf wdb db fdb gdb\"\r\n  \" exe dll ocx vbx sfx sys tlb awx com obj lib out o so \"\r\n  \" pdb pch idb ncb opt\";\r\n\r\nint GetExtIndex(const char *ext)\r\n{\r\n  int extIndex = 1;\r\n  const char *p = g_Exts;\r\n  for (;;)\r\n  {\r\n    char c = *p++;\r\n    if (c == 0)\r\n      return extIndex;\r\n    if (c == ' ')\r\n      continue;\r\n    int pos = 0;\r\n    for (;;)\r\n    {\r\n      char c2 = ext[pos++];\r\n      if (c2 == 0 && (c == 0 || c == ' '))\r\n        return extIndex;\r\n      if (c != c2)\r\n        break;\r\n      c = *p++;\r\n    }\r\n    extIndex++;\r\n    for (;;)\r\n    {\r\n      if (c == 0)\r\n        return extIndex;\r\n      if (c == ' ')\r\n        break;\r\n      c = *p++;\r\n    }\r\n  }\r\n}\r\n\r\nstruct CRefItem\r\n{\r\n  const CUpdateItem *UpdateItem;\r\n  UInt32 Index;\r\n  UInt32 ExtensionPos;\r\n  UInt32 NamePos;\r\n  int ExtensionIndex;\r\n  CRefItem(UInt32 index, const CUpdateItem &ui, bool sortByType):\r\n    UpdateItem(&ui),\r\n    Index(index),\r\n    ExtensionPos(0),\r\n    NamePos(0),\r\n    ExtensionIndex(0)\r\n  {\r\n    if (sortByType)\r\n    {\r\n      int slashPos = GetReverseSlashPos(ui.Name);\r\n      NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0);\r\n      int dotPos = ui.Name.ReverseFind(L'.');\r\n      if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n        ExtensionPos = ui.Name.Length();\r\n      else\r\n      {\r\n        ExtensionPos = dotPos + 1;\r\n        UString us = ui.Name.Mid(ExtensionPos);\r\n        if (!us.IsEmpty())\r\n        {\r\n          us.MakeLower();\r\n          int i;\r\n          AString s;\r\n          for (i = 0; i < us.Length(); i++)\r\n          {\r\n            wchar_t c = us[i];\r\n            if (c >= 0x80)\r\n              break;\r\n            s += (char)c;\r\n          }\r\n          if (i == us.Length())\r\n            ExtensionIndex = GetExtIndex(s);\r\n          else\r\n            ExtensionIndex = 0;\r\n        }\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nstatic int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *param)\r\n{\r\n  const CRefItem &a1 = *p1;\r\n  const CRefItem &a2 = *p2;\r\n  const CUpdateItem &u1 = *a1.UpdateItem;\r\n  const CUpdateItem &u2 = *a2.UpdateItem;\r\n  int n;\r\n  if (u1.IsDir != u2.IsDir)\r\n    return (u1.IsDir) ? 1 : -1;\r\n  if (u1.IsDir)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  bool sortByType = *(bool *)param;\r\n  if (sortByType)\r\n  {\r\n    RINOZ(MyCompare(a1.ExtensionIndex, a2.ExtensionIndex))\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos));\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos));\r\n    if (!u1.MTimeDefined && u2.MTimeDefined) return 1;\r\n    if (u1.MTimeDefined && !u2.MTimeDefined) return -1;\r\n    if (u1.MTimeDefined && u2.MTimeDefined) RINOZ(MyCompare(u1.MTime, u2.MTime));\r\n    RINOZ(MyCompare(u1.Size, u2.Size))\r\n  }\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstruct CSolidGroup\r\n{\r\n  CCompressionMethodMode Method;\r\n  CRecordVector<UInt32> Indices;\r\n};\r\n\r\nstatic wchar_t *g_ExeExts[] =\r\n{\r\n  L\"dll\",\r\n  L\"exe\",\r\n  L\"ocx\",\r\n  L\"sfx\",\r\n  L\"sys\"\r\n};\r\n\r\nstatic bool IsExeFile(const UString &ext)\r\n{\r\n  for (int i = 0; i < sizeof(g_ExeExts) / sizeof(g_ExeExts[0]); i++)\r\n    if (ext.CompareNoCase(g_ExeExts[i]) == 0)\r\n      return true;\r\n  return false;\r\n}\r\n\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_BCJ   = 0x03030103;\r\nstatic const UInt64 k_BCJ2  = 0x0303011B;\r\n\r\nstatic bool GetMethodFull(UInt64 methodID,\r\n    UInt32 numInStreams, CMethodFull &methodResult)\r\n{\r\n  methodResult.Id = methodID;\r\n  methodResult.NumInStreams = numInStreams;\r\n  methodResult.NumOutStreams = 1;\r\n  return true;\r\n}\r\n\r\nstatic bool MakeExeMethod(const CCompressionMethodMode &method,\r\n    bool bcj2Filter, CCompressionMethodMode &exeMethod)\r\n{\r\n  exeMethod = method;\r\n  if (bcj2Filter)\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ2, 4, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    if (!GetMethodFull(k_LZMA, 1, methodFull))\r\n      return false;\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kAlgorithm;\r\n      prop.Value = kAlgorithmForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kMatchFinder;\r\n      prop.Value = kMatchFinderForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = kDictionaryForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kNumFastBytes;\r\n      prop.Value = kNumFastBytesForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n\r\n    exeMethod.Methods.Add(methodFull);\r\n    exeMethod.Methods.Add(methodFull);\r\n    CBind bind;\r\n\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 2;\r\n    bind.OutStream = 1;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 3;\r\n    bind.OutStream = 2;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  else\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ, 1, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    CBind bind;\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  return true;\r\n}\r\n\r\nstatic void SplitFilesToGroups(\r\n    const CCompressionMethodMode &method,\r\n    bool useFilters, bool maxFilter,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    CObjectVector<CSolidGroup> &groups)\r\n{\r\n  if (method.Methods.Size() != 1 || method.Binds.Size() != 0)\r\n    useFilters = false;\r\n  groups.Clear();\r\n  groups.Add(CSolidGroup());\r\n  groups.Add(CSolidGroup());\r\n  CSolidGroup &generalGroup = groups[0];\r\n  CSolidGroup &exeGroup = groups[1];\r\n  generalGroup.Method = method;\r\n  int i;\r\n  for (i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &ui = updateItems[i];\r\n    if (!ui.NewData)\r\n      continue;\r\n    if (!ui.HasStream())\r\n      continue;\r\n    if (useFilters)\r\n    {\r\n      const UString name = ui.Name;\r\n      int dotPos = name.ReverseFind(L'.');\r\n      if (dotPos >= 0)\r\n      {\r\n        UString ext = name.Mid(dotPos + 1);\r\n        if (IsExeFile(ext))\r\n        {\r\n          exeGroup.Indices.Add(i);\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    generalGroup.Indices.Add(i);\r\n  }\r\n  if (exeGroup.Indices.Size() > 0)\r\n    if (!MakeExeMethod(method, maxFilter, exeGroup.Method))\r\n      exeGroup.Method = method;\r\n  for (i = 0; i < groups.Size();)\r\n    if (groups[i].Indices.Size() == 0)\r\n      groups.Delete(i);\r\n    else\r\n      i++;\r\n}\r\n\r\nstatic void FromUpdateItemToFileItem(const CUpdateItem &ui,\r\n    CFileItem &file, CFileItem2 &file2)\r\n{\r\n  file.Name = NItemName::MakeLegalName(ui.Name);\r\n  if (ui.AttribDefined)\r\n    file.SetAttrib(ui.Attrib);\r\n  \r\n  file2.CTime = ui.CTime;  file2.CTimeDefined = ui.CTimeDefined;\r\n  file2.ATime = ui.ATime;  file2.ATimeDefined = ui.ATimeDefined;\r\n  file2.MTime = ui.MTime;  file2.MTimeDefined = ui.MTimeDefined;\r\n  file2.IsAnti = ui.IsAnti;\r\n  file2.StartPosDefined = false;\r\n\r\n  file.Size = ui.Size;\r\n  file.IsDir = ui.IsDir;\r\n  file.HasStream = ui.HasStream();\r\n}\r\n\r\nstatic HRESULT Update2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  UInt64 numSolidFiles = options.NumSolidFiles;\r\n  if (numSolidFiles == 0)\r\n    numSolidFiles = 1;\r\n  /*\r\n  CMyComPtr<IOutStream> outStream;\r\n  RINOK(seqOutStream->QueryInterface(IID_IOutStream, (void **)&outStream));\r\n  if (!outStream)\r\n    return E_NOTIMPL;\r\n  */\r\n\r\n  UInt64 startBlockSize = db != 0 ? db->ArchiveInfo.StartPosition: 0;\r\n  if (startBlockSize > 0 && !options.RemoveSfxBlock)\r\n  {\r\n    RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));\r\n  }\r\n\r\n  CRecordVector<int> fileIndexToUpdateIndexMap;\r\n  if (db != 0)\r\n  {\r\n    fileIndexToUpdateIndexMap.Reserve(db->Files.Size());\r\n    for (int i = 0; i < db->Files.Size(); i++)\r\n      fileIndexToUpdateIndexMap.Add(-1);\r\n  }\r\n  int i;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    int index = updateItems[i].IndexInArchive;\r\n    if (index != -1)\r\n      fileIndexToUpdateIndexMap[index] = i;\r\n  }\r\n\r\n  CRecordVector<int> folderRefs;\r\n  if (db != 0)\r\n  {\r\n    for(i = 0; i < db->Folders.Size(); i++)\r\n    {\r\n      CNum indexInFolder = 0;\r\n      CNum numCopyItems = 0;\r\n      CNum numUnpackStreams = db->NumUnpackStreamsVector[i];\r\n      for (CNum fileIndex = db->FolderStartFileIndex[i];\r\n      indexInFolder < numUnpackStreams; fileIndex++)\r\n      {\r\n        if (db->Files[fileIndex].HasStream)\r\n        {\r\n          indexInFolder++;\r\n          int updateIndex = fileIndexToUpdateIndexMap[fileIndex];\r\n          if (updateIndex >= 0)\r\n            if (!updateItems[updateIndex].NewData)\r\n              numCopyItems++;\r\n        }\r\n      }\r\n      if (numCopyItems != numUnpackStreams && numCopyItems != 0)\r\n        return E_NOTIMPL; // It needs repacking !!!\r\n      if (numCopyItems > 0)\r\n        folderRefs.Add(i);\r\n    }\r\n    folderRefs.Sort(CompareFolderRefs, (void *)db);\r\n  }\r\n\r\n  ////////////////////////////\r\n\r\n  RINOK(archive.Create(seqOutStream, false));\r\n  RINOK(archive.SkeepPrefixArchiveHeader());\r\n  UInt64 complexity = 0;\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n    complexity += db->GetFolderFullPackSize(folderRefs[i]);\r\n  UInt64 inSizeForReduce = 0;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &ui = updateItems[i];\r\n    if (ui.NewData)\r\n    {\r\n      complexity += ui.Size;\r\n      if (numSolidFiles == 1)\r\n      {\r\n        if (ui.Size > inSizeForReduce)\r\n          inSizeForReduce = ui.Size;\r\n      }\r\n      else\r\n        inSizeForReduce += ui.Size;\r\n    }\r\n  }\r\n  RINOK(updateCallback->SetTotal(complexity));\r\n  complexity = 0;\r\n  RINOK(updateCallback->SetCompleted(&complexity));\r\n\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(updateCallback, true);\r\n\r\n  /////////////////////////////////////////\r\n  // Write Copy Items\r\n\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n  {\r\n    int folderIndex = folderRefs[i];\r\n    \r\n    lps->ProgressOffset = complexity;\r\n    UInt64 packSize = db->GetFolderFullPackSize(folderIndex);\r\n    RINOK(WriteRange(inStream, archive.SeqStream,\r\n        db->GetFolderStreamPos(folderIndex, 0), packSize, progress));\r\n    complexity += packSize;\r\n    \r\n    const CFolder &folder = db->Folders[folderIndex];\r\n    CNum startIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      newDatabase.PackSizes.Add(db->PackSizes[startIndex + j]);\r\n      // newDatabase.PackCRCsDefined.Add(db.PackCRCsDefined[startIndex + j]);\r\n      // newDatabase.PackCRCs.Add(db.PackCRCs[startIndex + j]);\r\n    }\r\n    newDatabase.Folders.Add(folder);\r\n\r\n    CNum numUnpackStreams = db->NumUnpackStreamsVector[folderIndex];\r\n    newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\r\n\r\n    CNum indexInFolder = 0;\r\n    for (CNum fi = db->FolderStartFileIndex[folderIndex];\r\n        indexInFolder < numUnpackStreams; fi++)\r\n    {\r\n      CFileItem file;\r\n      CFileItem2 file2;\r\n      db->GetFile(fi, file, file2);\r\n      if (file.HasStream)\r\n      {\r\n        indexInFolder++;\r\n        int updateIndex = fileIndexToUpdateIndexMap[fi];\r\n        if (updateIndex >= 0)\r\n        {\r\n          const CUpdateItem &ui = updateItems[updateIndex];\r\n          if (ui.NewProperties)\r\n          {\r\n            CFileItem uf;\r\n            FromUpdateItemToFileItem(ui, uf, file2);\r\n            uf.Size = file.Size;\r\n            uf.Crc = file.Crc;\r\n            uf.CrcDefined = file.CrcDefined;\r\n            uf.HasStream = file.HasStream;\r\n            file = uf;\r\n          }\r\n        }\r\n        newDatabase.AddFile(file, file2);\r\n      }\r\n    }\r\n  }\r\n\r\n  folderRefs.ClearAndFree();\r\n  fileIndexToUpdateIndexMap.ClearAndFree();\r\n\r\n  /////////////////////////////////////////\r\n  // Compress New Files\r\n\r\n  CObjectVector<CSolidGroup> groups;\r\n  SplitFilesToGroups(*options.Method, options.UseFilters, options.MaxFilter,\r\n      updateItems, groups);\r\n\r\n  const UInt32 kMinReduceSize = (1 << 16);\r\n  if (inSizeForReduce < kMinReduceSize)\r\n    inSizeForReduce = kMinReduceSize;\r\n\r\n  for (int groupIndex = 0; groupIndex < groups.Size(); groupIndex++)\r\n  {\r\n    const CSolidGroup &group = groups[groupIndex];\r\n    int numFiles = group.Indices.Size();\r\n    if (numFiles == 0)\r\n      continue;\r\n    CRecordVector<CRefItem> refItems;\r\n    refItems.Reserve(numFiles);\r\n    bool sortByType = (numSolidFiles > 1);\r\n    for (i = 0; i < numFiles; i++)\r\n      refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType));\r\n    refItems.Sort(CompareUpdateItems, (void *)&sortByType);\r\n    \r\n    CRecordVector<UInt32> indices;\r\n    indices.Reserve(numFiles);\r\n\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      UInt32 index = refItems[i].Index;\r\n      indices.Add(index);\r\n      /*\r\n      const CUpdateItem &ui = updateItems[index];\r\n      CFileItem file;\r\n      if (ui.NewProperties)\r\n        FromUpdateItemToFileItem(ui, file);\r\n      else\r\n        file = db.Files[ui.IndexInArchive];\r\n      if (file.IsAnti || file.IsDir)\r\n        return E_FAIL;\r\n      newDatabase.Files.Add(file);\r\n      */\r\n    }\r\n    \r\n    CEncoder encoder(group.Method);\r\n\r\n    for (i = 0; i < numFiles;)\r\n    {\r\n      UInt64 totalSize = 0;\r\n      int numSubFiles;\r\n      UString prevExtension;\r\n      for (numSubFiles = 0; i + numSubFiles < numFiles &&\r\n          numSubFiles < numSolidFiles; numSubFiles++)\r\n      {\r\n        const CUpdateItem &ui = updateItems[indices[i + numSubFiles]];\r\n        totalSize += ui.Size;\r\n        if (totalSize > options.NumSolidBytes)\r\n          break;\r\n        if (options.SolidExtension)\r\n        {\r\n          UString ext = ui.GetExtension();\r\n          if (numSubFiles == 0)\r\n            prevExtension = ext;\r\n          else\r\n            if (ext.CompareNoCase(prevExtension) != 0)\r\n              break;\r\n        }\r\n      }\r\n      if (numSubFiles < 1)\r\n        numSubFiles = 1;\r\n\r\n      CFolderInStream *inStreamSpec = new CFolderInStream;\r\n      CMyComPtr<ISequentialInStream> solidInStream(inStreamSpec);\r\n      inStreamSpec->Init(updateCallback, &indices[i], numSubFiles);\r\n      \r\n      CFolder folderItem;\r\n\r\n      int startPackIndex = newDatabase.PackSizes.Size();\r\n      RINOK(encoder.Encode(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          solidInStream, NULL, &inSizeForReduce, folderItem,\r\n          archive.SeqStream, newDatabase.PackSizes, progress));\r\n\r\n      for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)\r\n        lps->OutSize += newDatabase.PackSizes[startPackIndex];\r\n\r\n      lps->InSize += folderItem.GetUnpackSize();\r\n      // for()\r\n      // newDatabase.PackCRCsDefined.Add(false);\r\n      // newDatabase.PackCRCs.Add(0);\r\n      \r\n      newDatabase.Folders.Add(folderItem);\r\n      \r\n      CNum numUnpackStreams = 0;\r\n      for (int subIndex = 0; subIndex < numSubFiles; subIndex++)\r\n      {\r\n        const CUpdateItem &ui = updateItems[indices[i + subIndex]];\r\n        CFileItem file;\r\n        CFileItem2 file2;\r\n        if (ui.NewProperties)\r\n          FromUpdateItemToFileItem(ui, file, file2);\r\n        else\r\n          db->GetFile(ui.IndexInArchive, file, file2);\r\n        if (file2.IsAnti || file.IsDir)\r\n          return E_FAIL;\r\n        \r\n        /*\r\n        CFileItem &file = newDatabase.Files[\r\n              startFileIndexInDatabase + i + subIndex];\r\n        */\r\n        if (!inStreamSpec->Processed[subIndex])\r\n        {\r\n          continue;\r\n          // file.Name += L\".locked\";\r\n        }\r\n\r\n        file.Crc = inStreamSpec->CRCs[subIndex];\r\n        file.Size = inStreamSpec->Sizes[subIndex];\r\n        if (file.Size != 0)\r\n        {\r\n          file.CrcDefined = true;\r\n          file.HasStream = true;\r\n          numUnpackStreams++;\r\n        }\r\n        else\r\n        {\r\n          file.CrcDefined = false;\r\n          file.HasStream = false;\r\n        }\r\n        newDatabase.AddFile(file, file2);\r\n      }\r\n      // numUnpackStreams = 0 is very bad case for locked files\r\n      // v3.13 doesn't understand it.\r\n      newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\r\n      i += numSubFiles;\r\n    }\r\n  }\r\n\r\n  groups.ClearAndFree();\r\n\r\n  {\r\n    /////////////////////////////////////////\r\n    // Write Empty Files & Folders\r\n    \r\n    CRecordVector<int> emptyRefs;\r\n    for(i = 0; i < updateItems.Size(); i++)\r\n    {\r\n      const CUpdateItem &ui = updateItems[i];\r\n      if (ui.NewData)\r\n      {\r\n        if (ui.HasStream())\r\n          continue;\r\n      }\r\n      else\r\n        if (ui.IndexInArchive != -1)\r\n          if (db->Files[ui.IndexInArchive].HasStream)\r\n            continue;\r\n      emptyRefs.Add(i);\r\n    }\r\n    emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);\r\n    for (i = 0; i < emptyRefs.Size(); i++)\r\n    {\r\n      const CUpdateItem &ui = updateItems[emptyRefs[i]];\r\n      CFileItem file;\r\n      CFileItem2 file2;\r\n      if (ui.NewProperties)\r\n        FromUpdateItemToFileItem(ui, file, file2);\r\n      else\r\n        db->GetFile(ui.IndexInArchive, file, file2);\r\n      newDatabase.AddFile(file, file2);\r\n    }\r\n  }\r\n    \r\n  newDatabase.ReserveDown();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  return Update2(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        inStream, db, updateItems,\r\n        archive, newDatabase, seqOutStream, updateCallback, options);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/7zUpdate.h",
    "content": "// 7zUpdate.h\r\n\r\n#ifndef __7Z_UPDATE_H\r\n#define __7Z_UPDATE_H\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CUpdateItem\r\n{\r\n  int IndexInArchive;\r\n  int IndexInClient;\r\n  \r\n  UInt64 CTime;\r\n  UInt64 ATime;\r\n  UInt64 MTime;\r\n\r\n  UInt64 Size;\r\n  UString Name;\r\n\r\n  UInt32 Attrib;\r\n  \r\n  bool NewData;\r\n  bool NewProperties;\r\n\r\n  bool IsAnti;\r\n  bool IsDir;\r\n\r\n  bool AttribDefined;\r\n  bool CTimeDefined;\r\n  bool ATimeDefined;\r\n  bool MTimeDefined;\r\n\r\n  bool HasStream() const { return !IsDir && !IsAnti && Size != 0; }\r\n\r\n  CUpdateItem():\r\n      IsAnti(false),\r\n      IsDir(false),\r\n      AttribDefined(false),\r\n      CTimeDefined(false),\r\n      ATimeDefined(false),\r\n      MTimeDefined(false)\r\n      {}\r\n  void SetDirStatusFromAttrib() { IsDir = ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0); };\r\n\r\n  int GetExtensionPos() const;\r\n  UString GetExtension() const;\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  const CCompressionMethodMode *Method;\r\n  const CCompressionMethodMode *HeaderMethod;\r\n  bool UseFilters;\r\n  bool MaxFilter;\r\n\r\n  CHeaderOptions HeaderOptions;\r\n\r\n  UInt64 NumSolidFiles;\r\n  UInt64 NumSolidBytes;\r\n  bool SolidExtension;\r\n  bool RemoveSfxBlock;\r\n  bool VolumeMode;\r\n};\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options);\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Archive.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Archive2.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n  GetNumberOfMethods PRIVATE\r\n  GetMethodProperty PRIVATE\r\n  SetLargePageMode PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/ArchiveExports.cpp",
    "content": "// ArchiveExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterArc.h\"\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\r\nvoid RegisterArc(const CArcInfo *arcInfo)\r\n{\r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler,\r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\n#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nint FindFormatCalssId(const GUID *clsID)\r\n{\r\n  GUID cls = *clsID;\r\n  CLS_ARC_ID_ITEM(cls) = 0;\r\n  if (cls != CLSID_CArchiveHandler)\r\n    return -1;\r\n  Byte id = CLS_ARC_ID_ITEM(*clsID);\r\n  for (unsigned i = 0; i < g_NumArcs; i++)\r\n    if (g_Arcs[i]->ClassId == id)\r\n      return (int)i;\r\n  return -1;\r\n}\r\n\r\nSTDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  {\r\n    int needIn = (*iid == IID_IInArchive);\r\n    int needOut = (*iid == IID_IOutArchive);\r\n    if (!needIn && !needOut)\r\n      return E_NOINTERFACE;\r\n    int formatIndex = FindFormatCalssId(clsid);\r\n    if (formatIndex < 0)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    \r\n    const CArcInfo &arc = *g_Arcs[formatIndex];\r\n    if (needIn)\r\n    {\r\n      *outObject = arc.CreateInArchive();\r\n      ((IInArchive *)*outObject)->AddRef();\r\n    }\r\n    else\r\n    {\r\n      if (!arc.CreateOutArchive)\r\n        return CLASS_E_CLASSNOTAVAILABLE;\r\n      *outObject = arc.CreateOutArchive();\r\n      ((IOutArchive *)*outObject)->AddRef();\r\n    }\r\n  }\r\n  COM_TRY_END\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  if (formatIndex >= g_NumArcs)\r\n    return E_INVALIDARG;\r\n  const CArcInfo &arc = *g_Arcs[formatIndex];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case NArchive::kName:\r\n      prop = arc.Name;\r\n      break;\r\n    case NArchive::kClassID:\r\n    {\r\n      GUID clsId = CLSID_CArchiveHandler;\r\n      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;\r\n      return SetPropGUID(clsId, value);\r\n    }\r\n    case NArchive::kExtension:\r\n      if (arc.Ext != 0)\r\n        prop = arc.Ext;\r\n      break;\r\n    case NArchive::kAddExtension:\r\n      if (arc.AddExt != 0)\r\n        prop = arc.AddExt;\r\n      break;\r\n    case NArchive::kUpdate:\r\n      prop = (bool)(arc.CreateOutArchive != 0);\r\n      break;\r\n    case NArchive::kKeepName:\r\n      prop = arc.KeepName;\r\n      break;\r\n    case NArchive::kStartSignature:\r\n      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  return GetHandlerProperty2(0, propID, value);\r\n}\r\n\r\nSTDAPI GetNumberOfFormats(UINT32 *numFormats)\r\n{\r\n  *numFormats = g_NumArcs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/CoderMixer2.cpp",
    "content": "// CoderMixer2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):\r\n  _srcBindInfo(srcBindInfo)\r\n{\r\n  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);\r\n\r\n  UInt32  j;\r\n  for (j = 0; j < NumSrcInStreams; j++)\r\n  {\r\n    _srcInToDestOutMap.Add(0);\r\n    DestOutToSrcInMap.Add(0);\r\n  }\r\n  for (j = 0; j < _numSrcOutStreams; j++)\r\n  {\r\n    _srcOutToDestInMap.Add(0);\r\n    _destInToSrcOutMap.Add(0);\r\n  }\r\n\r\n  UInt32 destInOffset = 0;\r\n  UInt32 destOutOffset = 0;\r\n  UInt32 srcInOffset = NumSrcInStreams;\r\n  UInt32 srcOutOffset = _numSrcOutStreams;\r\n\r\n  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];\r\n\r\n    srcInOffset -= srcCoderInfo.NumInStreams;\r\n    srcOutOffset -= srcCoderInfo.NumOutStreams;\r\n    \r\n    UInt32 j;\r\n    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)\r\n    {\r\n      UInt32 index = srcInOffset + j;\r\n      _srcInToDestOutMap[index] = destOutOffset;\r\n      DestOutToSrcInMap[destOutOffset] = index;\r\n    }\r\n    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)\r\n    {\r\n      UInt32 index = srcOutOffset + j;\r\n      _srcOutToDestInMap[index] = destInOffset;\r\n      _destInToSrcOutMap[destInOffset] = index;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)\r\n{\r\n  destBindInfo.Coders.Clear();\r\n  destBindInfo.BindPairs.Clear();\r\n  destBindInfo.InStreams.Clear();\r\n  destBindInfo.OutStreams.Clear();\r\n\r\n  int i;\r\n  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];\r\n    CCoderStreamsInfo destCoderInfo;\r\n    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;\r\n    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;\r\n    destBindInfo.Coders.Add(destCoderInfo);\r\n  }\r\n  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];\r\n    CBindPair destBindPair;\r\n    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];\r\n    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];\r\n    destBindInfo.BindPairs.Add(destBindPair);\r\n  }\r\n  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)\r\n    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);\r\n  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)\r\n    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);\r\n}\r\n\r\nCCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams):\r\n    NumInStreams(numInStreams),\r\n    NumOutStreams(numOutStreams)\r\n{\r\n  InSizes.Reserve(NumInStreams);\r\n  InSizePointers.Reserve(NumInStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\nvoid CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,\r\n      const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/CoderMixer2.h",
    "content": "// CoderMixer2.h\r\n\r\n#ifndef __CODER_MIXER2_H\r\n#define __CODER_MIXER2_H\r\n\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n};\r\n\r\nstruct CCoderStreamsInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n};\r\n\r\nstruct CBindInfo\r\n{\r\n  CRecordVector<CCoderStreamsInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<UInt32> InStreams;\r\n  CRecordVector<UInt32> OutStreams;\r\n\r\n  void Clear()\r\n  {\r\n    Coders.Clear();\r\n    BindPairs.Clear();\r\n    InStreams.Clear();\r\n    OutStreams.Clear();\r\n  }\r\n\r\n  /*\r\n  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const\r\n  {\r\n    UInt32 numOutStreams = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      numOutStreams += Coders[i].NumOutStreams;\r\n    return numOutStreams;\r\n  }\r\n  */\r\n\r\n\r\n  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const\r\n  {\r\n    numInStreams = 0;\r\n    numOutStreams = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n    {\r\n      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];\r\n      numInStreams += coderStreamsInfo.NumInStreams;\r\n      numOutStreams += coderStreamsInfo.NumOutStreams;\r\n    }\r\n  }\r\n\r\n  int FindBinderForInStream(UInt32 inStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBinderForOutStream(UInt32 outStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumInStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumOutStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n\r\n  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,\r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumInStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,\r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumOutStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n};\r\n\r\nclass CBindReverseConverter\r\n{\r\n  UInt32 _numSrcOutStreams;\r\n  NCoderMixer::CBindInfo _srcBindInfo;\r\n  CRecordVector<UInt32> _srcInToDestOutMap;\r\n  CRecordVector<UInt32> _srcOutToDestInMap;\r\n  CRecordVector<UInt32> _destInToSrcOutMap;\r\npublic:\r\n  UInt32 NumSrcInStreams;\r\n  CRecordVector<UInt32> DestOutToSrcInMap;\r\n\r\n  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);\r\n  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);\r\n};\r\n\r\nstruct CCoderInfo2\r\n{\r\n  CMyComPtr<ICompressCoder> Coder;\r\n  CMyComPtr<ICompressCoder2> Coder2;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n\r\n  CRecordVector<UInt64> InSizes;\r\n  CRecordVector<UInt64> OutSizes;\r\n  CRecordVector<const UInt64 *> InSizePointers;\r\n  CRecordVector<const UInt64 *> OutSizePointers;\r\n\r\n  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n\r\n  HRESULT QueryInterface(REFGUID iid, void** pp) const\r\n  {\r\n    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;\r\n    return p->QueryInterface(iid, pp);\r\n  }\r\n};\r\n\r\nclass CCoderMixer2\r\n{\r\npublic:\r\n  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;\r\n  virtual void ReInit() = 0;\r\n  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;\r\n};\r\n\r\n}\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/CoderMixer2MT.cpp",
    "content": "// CoderMixer2MT.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2MT.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams):\r\n    CCoderInfo2(numInStreams, numOutStreams)\r\n{\r\n  InStreams.Reserve(NumInStreams);\r\n  InStreamPointers.Reserve(NumInStreams);\r\n  OutStreams.Reserve(NumOutStreams);\r\n  OutStreamPointers.Reserve(NumOutStreams);\r\n}\r\n\r\nvoid CCoder2::Execute() { Code(NULL); }\r\n\r\nvoid CCoder2::Code(ICompressProgressInfo *progress)\r\n{\r\n  InStreamPointers.Clear();\r\n  OutStreamPointers.Clear();\r\n  UInt32 i;\r\n  for (i = 0; i < NumInStreams; i++)\r\n  {\r\n    if (InSizePointers[i] != NULL)\r\n      InSizePointers[i] = &InSizes[i];\r\n    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);\r\n  }\r\n  for (i = 0; i < NumOutStreams; i++)\r\n  {\r\n    if (OutSizePointers[i] != NULL)\r\n      OutSizePointers[i] = &OutSizes[i];\r\n    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);\r\n  }\r\n  if (Coder)\r\n    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],\r\n        InSizePointers[0], OutSizePointers[0], progress);\r\n  else\r\n    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,\r\n      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);\r\n  {\r\n    int i;\r\n    for (i = 0; i < InStreams.Size(); i++)\r\n      InStreams[i].Release();\r\n    for (i = 0; i < OutStreams.Size(); i++)\r\n      OutStreams[i].Release();\r\n  }\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\n\r\nvoid CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n//////////////////////////////////////\r\n// CCoderMixer2MT\r\n\r\nHRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)\r\n{\r\n  _bindInfo = bindInfo;\r\n  _streamBinders.Clear();\r\n  for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    _streamBinders.Add(CStreamBinder());\r\n    RINOK(_streamBinders.Back().CreateEvents());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoderCommon()\r\n{\r\n  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];\r\n  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);\r\n  _coders.Add(threadCoderInfo);\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder(ICompressCoder *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder = coder;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder2 = coder;\r\n}\r\n\r\n\r\nvoid CCoderMixer2MT::ReInit()\r\n{\r\n  for(int i = 0; i < _streamBinders.Size(); i++)\r\n    _streamBinders[i].ReInit();\r\n}\r\n\r\n\r\nHRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams)\r\n{\r\n  /*\r\n  if (_coders.Size() != _bindInfo.Coders.Size())\r\n    throw 0;\r\n  */\r\n  int i;\r\n  for(i = 0; i < _coders.Size(); i++)\r\n  {\r\n    CCoder2 &coderInfo = _coders[i];\r\n    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];\r\n    coderInfo.InStreams.Clear();\r\n    UInt32 j;\r\n    for(j = 0; j < coderStreamsInfo.NumInStreams; j++)\r\n      coderInfo.InStreams.Add(NULL);\r\n    coderInfo.OutStreams.Clear();\r\n    for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)\r\n      coderInfo.OutStreams.Add(NULL);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = _bindInfo.BindPairs[i];\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);\r\n    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);\r\n\r\n    _streamBinders[i].CreateStreams(\r\n        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],\r\n        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.InStreams.Size(); i++)\r\n  {\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);\r\n    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];\r\n  }\r\n  \r\n  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);\r\n    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)\r\n{\r\n  for (int i = 0; i < _coders.Size(); i++)\r\n    if (_coders[i].Result == code)\r\n      return code;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||\r\n      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())\r\n    return E_INVALIDARG;\r\n\r\n  Init(inStreams, outStreams);\r\n\r\n  int i;\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n    {\r\n      RINOK(_coders[i].Create());\r\n    }\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].Start();\r\n\r\n  _coders[_progressCoderIndex].Code(progress);\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].WaitFinish();\r\n\r\n  RINOK(ReturnIfError(E_ABORT));\r\n  RINOK(ReturnIfError(E_OUTOFMEMORY));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK && result != E_FAIL && result != S_FALSE)\r\n      return result;\r\n  }\r\n\r\n  RINOK(ReturnIfError(S_FALSE));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/CoderMixer2MT.h",
    "content": "// CoderMixer2MT.h\r\n\r\n#ifndef __CODER_MIXER2_MT_H\r\n#define __CODER_MIXER2_MT_H\r\n\r\n#include \"CoderMixer2.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../Common/StreamBinder.h\"\r\n#include \"../../Common/VirtThread.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CCoder2: public CCoderInfo2, public CVirtThread\r\n{\r\n  HRESULT Result;\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;\r\n  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;\r\n  CRecordVector<ISequentialInStream*> InStreamPointers;\r\n  CRecordVector<ISequentialOutStream*> OutStreamPointers;\r\n\r\n  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n  virtual void Execute();\r\n  void Code(ICompressProgressInfo *progress);\r\n};\r\n\r\n\r\n/*\r\n  SetBindInfo()\r\n  for each coder\r\n    AddCoder[2]()\r\n  SetProgressIndex(UInt32 coderIndex);\r\n \r\n  for each file\r\n  {\r\n    ReInit()\r\n    for each coder\r\n      SetCoderInfo\r\n    Code\r\n  }\r\n*/\r\n\r\nclass CCoderMixer2MT:\r\n  public ICompressCoder2,\r\n  public CCoderMixer2,\r\n  public CMyUnknownImp\r\n{\r\n  CBindInfo _bindInfo;\r\n  CObjectVector<CStreamBinder> _streamBinders;\r\n  int _progressCoderIndex;\r\n\r\n  void AddCoderCommon();\r\n  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);\r\n  HRESULT ReturnIfError(HRESULT code);\r\npublic:\r\n  CObjectVector<CCoder2> _coders;\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n\r\n  HRESULT SetBindInfo(const CBindInfo &bindInfo);\r\n  void AddCoder(ICompressCoder *coder);\r\n  void AddCoder2(ICompressCoder2 *coder);\r\n  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }\r\n\r\n  void ReInit();\r\n  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)\r\n    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }\r\n  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const\r\n    {  return _streamBinders[binderIndex].ProcessedSize; }\r\n};\r\n\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/CrossThreadProgress.cpp",
    "content": "// CrossThreadProgress.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CrossThreadProgress.h\"\r\n\r\nSTDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  InSize = inSize;\r\n  OutSize = outSize;\r\n  ProgressEvent.Set();\r\n  WaitEvent.Lock();\r\n  return Result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/CrossThreadProgress.h",
    "content": "// CrossThreadProgress.h\r\n\r\n#ifndef __CROSSTHREADPROGRESS_H\r\n#define __CROSSTHREADPROGRESS_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CCrossThreadProgress:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  const UInt64 *InSize;\r\n  const UInt64 *OutSize;\r\n  HRESULT Result;\r\n  NWindows::NSynchronization::CAutoResetEvent ProgressEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent WaitEvent;\r\n\r\n  HRes Create()\r\n  {\r\n    RINOK(ProgressEvent.CreateIfNotCreated());\r\n    return WaitEvent.CreateIfNotCreated();\r\n  }\r\n  void Init()\r\n  {\r\n    ProgressEvent.Reset();\r\n    WaitEvent.Reset();\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/DummyOutStream.cpp",
    "content": "// DummyOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DummyOutStream.h\"\r\n\r\nSTDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/DummyOutStream.h",
    "content": "// DummyOutStream.h\r\n\r\n#ifndef __DUMMYOUTSTREAM_H\r\n#define __DUMMYOUTSTREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nclass CDummyOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init() { _size = 0; }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/HandlerOut.cpp",
    "content": "// HandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#include \"HandlerOut.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\n\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kLZMA2MethodName = L\"LZMA2\";\r\nstatic const wchar_t *kBZip2MethodName = L\"BZip2\";\r\nstatic const wchar_t *kPpmdMethodName = L\"PPMd\";\r\nstatic const wchar_t *kDeflateMethodName = L\"Deflate\";\r\nstatic const wchar_t *kDeflate64MethodName = L\"Deflate64\";\r\n\r\nstatic const wchar_t *kLzmaMatchFinderX1 = L\"HC4\";\r\nstatic const wchar_t *kLzmaMatchFinderX5 = L\"BT4\";\r\n\r\nstatic const UInt32 kLzmaAlgoX1 = 0;\r\nstatic const UInt32 kLzmaAlgoX5 = 1;\r\n\r\nstatic const UInt32 kLzmaDicSizeX1 = 1 << 16;\r\nstatic const UInt32 kLzmaDicSizeX3 = 1 << 20;\r\nstatic const UInt32 kLzmaDicSizeX5 = 1 << 24;\r\nstatic const UInt32 kLzmaDicSizeX7 = 1 << 25;\r\nstatic const UInt32 kLzmaDicSizeX9 = 1 << 26;\r\n\r\nstatic const UInt32 kLzmaFastBytesX1 = 32;\r\nstatic const UInt32 kLzmaFastBytesX7 = 64;\r\n\r\nstatic const UInt32 kPpmdMemSizeX1 = (1 << 22);\r\nstatic const UInt32 kPpmdMemSizeX5 = (1 << 24);\r\nstatic const UInt32 kPpmdMemSizeX7 = (1 << 26);\r\nstatic const UInt32 kPpmdMemSizeX9 = (192 << 20);\r\n\r\nstatic const UInt32 kPpmdOrderX1 = 4;\r\nstatic const UInt32 kPpmdOrderX5 = 6;\r\nstatic const UInt32 kPpmdOrderX7 = 16;\r\nstatic const UInt32 kPpmdOrderX9 = 32;\r\n\r\nstatic const UInt32 kDeflateAlgoX1 = 0;\r\nstatic const UInt32 kDeflateAlgoX5 = 1;\r\n\r\nstatic const UInt32 kDeflateFastBytesX1 = 32;\r\nstatic const UInt32 kDeflateFastBytesX7 = 64;\r\nstatic const UInt32 kDeflateFastBytesX9 = 128;\r\n\r\nstatic const UInt32 kDeflatePassesX1 = 1;\r\nstatic const UInt32 kDeflatePassesX7 = 3;\r\nstatic const UInt32 kDeflatePassesX9 = 10;\r\n\r\nstatic const UInt32 kBZip2NumPassesX1 = 1;\r\nstatic const UInt32 kBZip2NumPassesX7 = 2;\r\nstatic const UInt32 kBZip2NumPassesX9 = 7;\r\n\r\nstatic const UInt32 kBZip2DicSizeX1 = 100000;\r\nstatic const UInt32 kBZip2DicSizeX3 = 500000;\r\nstatic const UInt32 kBZip2DicSizeX5 = 900000;\r\n\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5;\r\n\r\nstatic bool AreEqual(const UString &methodName, const wchar_t *s)\r\n  { return (methodName.CompareNoCase(s) == 0); }\r\n\r\nstatic inline bool IsLZMAMethod(const UString &methodName)\r\n{\r\n  return\r\n    AreEqual(methodName, kLZMAMethodName) ||\r\n    AreEqual(methodName, kLZMA2MethodName);\r\n}\r\n\r\nstatic inline bool IsBZip2Method(const UString &methodName)\r\n  { return AreEqual(methodName, kBZip2MethodName); }\r\n\r\nstatic inline bool IsPpmdMethod(const UString &methodName)\r\n  { return AreEqual(methodName, kPpmdMethodName); }\r\n\r\nstatic inline bool IsDeflateMethod(const UString &methodName)\r\n{\r\n  return\r\n    AreEqual(methodName, kDeflateMethodName) ||\r\n    AreEqual(methodName, kDeflate64MethodName);\r\n}\r\n\r\nstruct CNameToPropID\r\n{\r\n  PROPID PropID;\r\n  VARTYPE VarType;\r\n  const wchar_t *Name;\r\n};\r\n\r\nCNameToPropID g_NameToPropID[] =\r\n{\r\n  { NCoderPropID::kOrder, VT_UI4, L\"O\" },\r\n  { NCoderPropID::kPosStateBits, VT_UI4, L\"PB\" },\r\n  { NCoderPropID::kLitContextBits, VT_UI4, L\"LC\" },\r\n  { NCoderPropID::kLitPosBits, VT_UI4, L\"LP\" },\r\n  { NCoderPropID::kEndMarker, VT_BOOL, L\"eos\" },\r\n\r\n  { NCoderPropID::kNumPasses, VT_UI4, L\"Pass\" },\r\n  { NCoderPropID::kNumFastBytes, VT_UI4, L\"fb\" },\r\n  { NCoderPropID::kMatchFinderCycles, VT_UI4, L\"mc\" },\r\n  { NCoderPropID::kAlgorithm, VT_UI4, L\"a\" },\r\n  { NCoderPropID::kMatchFinder, VT_BSTR, L\"mf\" },\r\n  { NCoderPropID::kNumThreads, VT_UI4, L\"mt\" }\r\n};\r\n\r\nstatic bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp)\r\n{\r\n  if (varType == srcProp.vt)\r\n  {\r\n    destProp = srcProp;\r\n    return true;\r\n  }\r\n  if (varType == VT_UI1)\r\n  {\r\n    if (srcProp.vt == VT_UI4)\r\n    {\r\n      UInt32 value = srcProp.ulVal;\r\n      if (value > 0xFF)\r\n        return false;\r\n      destProp = (Byte)value;\r\n      return true;\r\n    }\r\n  }\r\n  else if (varType == VT_BOOL)\r\n  {\r\n    bool res;\r\n    if (SetBoolProperty(res, srcProp) != S_OK)\r\n      return false;\r\n    destProp = res;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n    \r\nstatic int FindPropIdFromStringName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)\r\n    if (name.CompareNoCase(g_NameToPropID[i].Name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID,\r\n    const NWindows::NCOM::CPropVariant &value)\r\n{\r\n  for (int j = 0; j < oneMethodInfo.Props.Size(); j++)\r\n    if (oneMethodInfo.Props[j].Id == propID)\r\n      return;\r\n  CProp prop;\r\n  prop.Id = propID;\r\n  prop.Value = value;\r\n  oneMethodInfo.Props.Add(prop);\r\n}\r\n\r\nvoid COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  if (oneMethodInfo.MethodName.IsEmpty())\r\n    oneMethodInfo.MethodName = kDefaultMethodName;\r\n  \r\n  if (IsLZMAMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 dicSize =\r\n      (level >= 9 ? kLzmaDicSizeX9 :\r\n      (level >= 7 ? kLzmaDicSizeX7 :\r\n      (level >= 5 ? kLzmaDicSizeX5 :\r\n      (level >= 3 ? kLzmaDicSizeX3 :\r\n                    kLzmaDicSizeX1))));\r\n    \r\n    UInt32 algo =\r\n      (level >= 5 ? kLzmaAlgoX5 :\r\n                    kLzmaAlgoX1);\r\n    \r\n    UInt32 fastBytes =\r\n      (level >= 7 ? kLzmaFastBytesX7 :\r\n                    kLzmaFastBytesX1);\r\n    \r\n    const wchar_t *matchFinder =\r\n      (level >= 5 ? kLzmaMatchFinderX5 :\r\n                    kLzmaMatchFinderX1);\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsDeflateMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 fastBytes =\r\n      (level >= 9 ? kDeflateFastBytesX9 :\r\n      (level >= 7 ? kDeflateFastBytesX7 :\r\n                    kDeflateFastBytesX1));\r\n    \r\n    UInt32 numPasses =\r\n      (level >= 9 ? kDeflatePassesX9 :\r\n      (level >= 7 ? kDeflatePassesX7 :\r\n                    kDeflatePassesX1));\r\n    \r\n    UInt32 algo =\r\n      (level >= 5 ? kDeflateAlgoX5 :\r\n                    kDeflateAlgoX1);\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n  }\r\n  else if (IsBZip2Method(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 numPasses =\r\n      (level >= 9 ? kBZip2NumPassesX9 :\r\n      (level >= 7 ? kBZip2NumPassesX7 :\r\n                    kBZip2NumPassesX1));\r\n    \r\n    UInt32 dicSize =\r\n      (level >= 5 ? kBZip2DicSizeX5 :\r\n      (level >= 3 ? kBZip2DicSizeX3 :\r\n                    kBZip2DicSizeX1));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsPpmdMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 useMemSize =\r\n      (level >= 9 ? kPpmdMemSizeX9 :\r\n      (level >= 7 ? kPpmdMemSizeX7 :\r\n      (level >= 5 ? kPpmdMemSizeX5 :\r\n                    kPpmdMemSizeX1)));\r\n    \r\n    UInt32 order =\r\n      (level >= 9 ? kPpmdOrderX9 :\r\n      (level >= 7 ? kPpmdOrderX7 :\r\n      (level >= 5 ? kPpmdOrderX5 :\r\n                    kPpmdOrderX1)));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order);\r\n  }\r\n}\r\n\r\nstatic void SplitParams(const UString &srcString, UStringVector &subStrings)\r\n{\r\n  subStrings.Clear();\r\n  UString name;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L':')\r\n    {\r\n      subStrings.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  subStrings.Add(name);\r\n}\r\n\r\nstatic void SplitParam(const UString &param, UString &name, UString &value)\r\n{\r\n  int eqPos = param.Find(L'=');\r\n  if (eqPos >= 0)\r\n  {\r\n    name = param.Left(eqPos);\r\n    value = param.Mid(eqPos + 1);\r\n    return;\r\n  }\r\n  for(int i = 0; i < param.Length(); i++)\r\n  {\r\n    wchar_t c = param[i];\r\n    if (c >= L'0' && c <= L'9')\r\n    {\r\n      name = param.Left(i);\r\n      value = param.Mid(i);\r\n      return;\r\n    }\r\n  }\r\n  name = param;\r\n}\r\n\r\nHRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value)\r\n{\r\n  CProp prop;\r\n  if (name.CompareNoCase(L\"D\") == 0 ||\r\n      name.CompareNoCase(L\"MEM\") == 0)\r\n  {\r\n    UInt32 dicSize;\r\n    RINOK(ParsePropDictionaryValue(value, dicSize));\r\n    prop.Id = (name.CompareNoCase(L\"D\") == 0) ?\r\n        NCoderPropID::kDictionarySize :\r\n        NCoderPropID::kUsedMemorySize;\r\n    prop.Value = dicSize;\r\n  }\r\n  else\r\n  {\r\n    int index = FindPropIdFromStringName(name);\r\n    if (index < 0)\r\n      return E_INVALIDARG;\r\n    \r\n    const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n    prop.Id = nameToPropID.PropID;\r\n    \r\n    NCOM::CPropVariant propValue;\r\n    \r\n    if (nameToPropID.VarType == VT_BSTR)\r\n      propValue = value;\r\n    else if (nameToPropID.VarType == VT_BOOL)\r\n    {\r\n      bool res;\r\n      if (!StringToBool(value, res))\r\n        return E_INVALIDARG;\r\n      propValue = res;\r\n    }\r\n    else\r\n    {\r\n      UInt32 number;\r\n      if (ParseStringToUInt32(value, number) == value.Length())\r\n        propValue = number;\r\n      else\r\n        propValue = value;\r\n    }\r\n    \r\n    if (!ConvertProperty(propValue, nameToPropID.VarType, prop.Value))\r\n      return E_INVALIDARG;\r\n  }\r\n  oneMethodInfo.Props.Add(prop);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString)\r\n{\r\n  UStringVector params;\r\n  SplitParams(srcString, params);\r\n  if (params.Size() > 0)\r\n    oneMethodInfo.MethodName = params[0];\r\n  for (int i = 1; i < params.Size(); i++)\r\n  {\r\n    const UString &param = params[i];\r\n    UString name, value;\r\n    SplitParam(param, name, value);\r\n    RINOK(SetParam(oneMethodInfo, name, value));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const UString &s)\r\n{\r\n  UString s2 = s;\r\n  s2.MakeUpper();\r\n  for (int i = 0; i < s2.Length();)\r\n  {\r\n    const wchar_t *start = ((const wchar_t *)s2) + i;\r\n    const wchar_t *end;\r\n    UInt64 v = ConvertStringToUInt64(start, &end);\r\n    if (start == end)\r\n    {\r\n      if (s2[i++] != 'E')\r\n        return E_INVALIDARG;\r\n      _solidExtension = true;\r\n      continue;\r\n    }\r\n    i += (int)(end - start);\r\n    if (i == s2.Length())\r\n      return E_INVALIDARG;\r\n    wchar_t c = s2[i++];\r\n    switch(c)\r\n    {\r\n      case 'F':\r\n        if (v < 1)\r\n          v = 1;\r\n        _numSolidFiles = v;\r\n        break;\r\n      case 'B':\r\n        _numSolidBytes = v;\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'K':\r\n        _numSolidBytes = (v << 10);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'M':\r\n        _numSolidBytes = (v << 20);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'G':\r\n        _numSolidBytes = (v << 30);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)\r\n{\r\n  bool isSolid;\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      isSolid = true;\r\n      break;\r\n    case VT_BOOL:\r\n      isSolid = (value.boolVal != VARIANT_FALSE);\r\n      break;\r\n    case VT_BSTR:\r\n      if (StringToBool(value.bstrVal, isSolid))\r\n        break;\r\n      return SetSolidSettings(value.bstrVal);\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  if (isSolid)\r\n    InitSolid();\r\n  else\r\n    _numSolidFiles = 1;\r\n  return S_OK;\r\n}\r\n\r\nvoid COutHandler::Init()\r\n{\r\n  _removeSfxBlock = false;\r\n  _compressHeaders = true;\r\n  _encryptHeadersSpecified = false;\r\n  _encryptHeaders = false;\r\n  \r\n  WriteCTime = false;\r\n  WriteATime = false;\r\n  WriteMTime = true;\r\n  \r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  \r\n  _level = 5;\r\n  _autoFilter = true;\r\n  _volumeMode = false;\r\n  _crcSize = 4;\r\n  InitSolid();\r\n}\r\n\r\nvoid COutHandler::BeforeSetProperty()\r\n{\r\n  Init();\r\n  #ifdef COMPRESS_MT\r\n  numProcessors = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n\r\n  mainDicSize = 0xFFFFFFFF;\r\n  mainDicMethodIndex = 0xFFFFFFFF;\r\n  minNumber = 0;\r\n  _crcSize = 4;\r\n}\r\n\r\nHRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)\r\n{\r\n  UString name = nameSpec;\r\n  name.MakeUpper();\r\n  if (name.IsEmpty())\r\n    return E_INVALIDARG;\r\n  \r\n  if (name[0] == 'X')\r\n  {\r\n    name.Delete(0);\r\n    _level = 9;\r\n    return ParsePropValue(name, value, _level);\r\n  }\r\n  \r\n  if (name[0] == L'S')\r\n  {\r\n    name.Delete(0);\r\n    if (name.IsEmpty())\r\n      return SetSolidSettings(value);\r\n    if (value.vt != VT_EMPTY)\r\n      return E_INVALIDARG;\r\n    return SetSolidSettings(name);\r\n  }\r\n  \r\n  if (name == L\"CRC\")\r\n  {\r\n    _crcSize = 4;\r\n    name.Delete(0, 3);\r\n    return ParsePropValue(name, value, _crcSize);\r\n  }\r\n  \r\n  UInt32 number;\r\n  int index = ParseStringToUInt32(name, number);\r\n  UString realName = name.Mid(index);\r\n  if (index == 0)\r\n  {\r\n    if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n    {\r\n      #ifdef COMPRESS_MT\r\n      RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n      #endif\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"RSFX\") == 0)  return SetBoolProperty(_removeSfxBlock, value);\r\n    if (name.CompareNoCase(L\"F\") == 0) return SetBoolProperty(_autoFilter, value);\r\n    if (name.CompareNoCase(L\"HC\") == 0) return SetBoolProperty(_compressHeaders, value);\r\n    if (name.CompareNoCase(L\"HCF\") == 0)\r\n    {\r\n      bool compressHeadersFull = true;\r\n      RINOK(SetBoolProperty(compressHeadersFull, value));\r\n      if (!compressHeadersFull)\r\n        return E_INVALIDARG;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"HE\") == 0)\r\n    {\r\n      RINOK(SetBoolProperty(_encryptHeaders, value));\r\n      _encryptHeadersSpecified = true;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"TC\") == 0) return SetBoolProperty(WriteCTime, value);\r\n    if (name.CompareNoCase(L\"TA\") == 0) return SetBoolProperty(WriteATime, value);\r\n    if (name.CompareNoCase(L\"TM\") == 0) return SetBoolProperty(WriteMTime, value);\r\n    if (name.CompareNoCase(L\"V\") == 0) return SetBoolProperty(_volumeMode, value);\r\n    number = 0;\r\n  }\r\n  if (number > 10000)\r\n    return E_FAIL;\r\n  if (number < minNumber)\r\n    return E_INVALIDARG;\r\n  number -= minNumber;\r\n  for(int j = _methods.Size(); j <= (int)number; j++)\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    _methods.Add(oneMethodInfo);\r\n  }\r\n  \r\n  COneMethodInfo &oneMethodInfo = _methods[number];\r\n  \r\n  if (realName.Length() == 0)\r\n  {\r\n    if (value.vt != VT_BSTR)\r\n      return E_INVALIDARG;\r\n    \r\n    RINOK(SetParams(oneMethodInfo, value.bstrVal));\r\n  }\r\n  else\r\n  {\r\n    CProp prop;\r\n    if (realName.Left(1).CompareNoCase(L\"D\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize));\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = dicSize;\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else if (realName.Left(1).CompareNoCase(L\"C\") == 0)\r\n    {\r\n      UInt32 blockSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, blockSize));\r\n      prop.Id = NCoderPropID::kBlockSize;\r\n      prop.Value = blockSize;\r\n    }\r\n    else if (realName.Left(3).CompareNoCase(L\"MEM\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize));\r\n      prop.Id = NCoderPropID::kUsedMemorySize;\r\n      prop.Value = dicSize;\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else\r\n    {\r\n      int index = FindPropIdFromStringName(realName);\r\n      if (index < 0)\r\n        return E_INVALIDARG;\r\n      const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n      prop.Id = nameToPropID.PropID;\r\n      if (!ConvertProperty(value, nameToPropID.VarType, prop.Value))\r\n        return E_INVALIDARG;\r\n    }\r\n    oneMethodInfo.Props.Add(prop);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/HandlerOut.h",
    "content": "// HandlerOut.h\r\n\r\n#ifndef __HANDLER_OUT_H\r\n#define __HANDLER_OUT_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\n\r\nstruct COneMethodInfo\r\n{\r\n  CObjectVector<CProp> Props;\r\n  UString MethodName;\r\n};\r\n\r\nclass COutHandler\r\n{\r\npublic:\r\n  HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);\r\n  \r\n  HRESULT SetSolidSettings(const UString &s);\r\n  HRESULT SetSolidSettings(const PROPVARIANT &value);\r\n\r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  CObjectVector<COneMethodInfo> _methods;\r\n  bool _removeSfxBlock;\r\n  \r\n  UInt64 _numSolidFiles;\r\n  UInt64 _numSolidBytes;\r\n  bool _numSolidBytesDefined;\r\n  bool _solidExtension;\r\n\r\n  bool _compressHeaders;\r\n  bool _encryptHeadersSpecified;\r\n  bool _encryptHeaders;\r\n\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  bool _autoFilter;\r\n  UInt32 _level;\r\n\r\n  bool _volumeMode;\r\n\r\n  HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value);\r\n  HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);\r\n\r\n  void SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }\r\n  void InitSolidSize()  { _numSolidBytes = (UInt64)(Int64)(-1); }\r\n  void InitSolid()\r\n  {\r\n    InitSolidFiles();\r\n    InitSolidSize();\r\n    _solidExtension = false;\r\n    _numSolidBytesDefined = false;\r\n  }\r\n\r\n  void Init();\r\n\r\n  COutHandler() { Init(); }\r\n\r\n  void BeforeSetProperty();\r\n\r\n  UInt32 minNumber;\r\n  UInt32 numProcessors;\r\n  UInt32 mainDicSize;\r\n  UInt32 mainDicMethodIndex;\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/InStreamWithCRC.cpp",
    "content": "// InStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _size += realProcessedSize;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if (seekOrigin != STREAM_SEEK_SET || offset != 0)\r\n    return E_FAIL;\r\n  _size = 0;\r\n  _crc = CRC_INIT_VAL;\r\n  return _stream->Seek(offset, seekOrigin, newPosition);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/InStreamWithCRC.h",
    "content": "// InStreamWithCRC.h\r\n\r\n#ifndef __INSTREAMWITHCRC_H\r\n#define __INSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass CSequentialInStreamWithCRC:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CInStreamWithCRC:\r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\nprivate:\r\n  CMyComPtr<IInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(IInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/ItemNameUtils.cpp",
    "content": "// Archive/Common/ItemNameUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\nstatic const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;\r\nstatic const wchar_t kDirDelimiter = L'/';\r\n\r\nUString MakeLegalName(const UString &name)\r\n{\r\n  UString zipName = name;\r\n  zipName.Replace(kOSDirDelimiter, kDirDelimiter);\r\n  return zipName;\r\n}\r\n\r\nUString GetOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(kDirDelimiter, kOSDirDelimiter);\r\n  return newName;\r\n}\r\n\r\nUString GetOSName2(const UString &name)\r\n{\r\n  if (name.IsEmpty())\r\n    return UString();\r\n  UString newName = GetOSName(name);\r\n  if (newName[newName.Length() - 1] == kOSDirDelimiter)\r\n    newName.Delete(newName.Length() - 1);\r\n  return newName;\r\n}\r\n\r\nbool HasTailSlash(const AString &name, UINT codePage)\r\n{\r\n  if (name.IsEmpty())\r\n    return false;\r\n  LPCSTR prev =\r\n  #ifdef _WIN32\r\n    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);\r\n  #else\r\n    (LPCSTR)(name) + (name.Length() - 1);\r\n  #endif\r\n  return (*prev == '/');\r\n}\r\n\r\n#ifndef _WIN32\r\nUString WinNameToOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(L'\\\\', kOSDirDelimiter);\r\n  return newName;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/ItemNameUtils.h",
    "content": "// Archive/Common/ItemNameUtils.h\r\n\r\n#ifndef __ARCHIVE_ITEMNAMEUTILS_H\r\n#define __ARCHIVE_ITEMNAMEUTILS_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\n  UString MakeLegalName(const UString &name);\r\n  UString GetOSName(const UString &name);\r\n  UString GetOSName2(const UString &name);\r\n  bool HasTailSlash(const AString &name, UINT codePage);\r\n\r\n  #ifdef _WIN32\r\n  inline UString WinNameToOSName(const UString &name)  { return name; }\r\n  #else\r\n  UString WinNameToOSName(const UString &name);\r\n  #endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/MultiStream.cpp",
    "content": "// MultiStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MultiStream.h\"\r\n\r\nSTDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(_streamIndex < Streams.Size() && size > 0)\r\n  {\r\n    CSubStreamInfo &s = Streams[_streamIndex];\r\n    if (_pos == s.Size)\r\n    {\r\n      _streamIndex++;\r\n      _pos = 0;\r\n      continue;\r\n    }\r\n    RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));\r\n    UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));\r\n    UInt32 realProcessed;\r\n    HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _pos += realProcessed;\r\n    _seekPos += realProcessed;\r\n    RINOK(result);\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 newPos;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      newPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      newPos = _seekPos + offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      newPos = _totalLength + offset;\r\n      break;\r\n    default:\r\n      return STG_E_INVALIDFUNCTION;\r\n  }\r\n  _seekPos = 0;\r\n  for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)\r\n  {\r\n    UInt64 size = Streams[_streamIndex].Size;\r\n    if (newPos < _seekPos + size)\r\n    {\r\n      _pos = newPos - _seekPos;\r\n      _seekPos += _pos;\r\n      if (newPosition != 0)\r\n        *newPosition = newPos;\r\n      return S_OK;\r\n    }\r\n    _seekPos += size;\r\n  }\r\n  if (newPos == _seekPos)\r\n  {\r\n    if (newPosition != 0)\r\n      *newPosition = newPos;\r\n    return S_OK;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\n\r\n/*\r\nclass COutVolumeStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback,\r\n      const UString &name)\r\n  {\r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n*/\r\n\r\n/*\r\nSTDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));\r\n      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));\r\n      subStream.Pos = 0;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n    if (_offsetPos >= subStream.Size)\r\n    {\r\n      _offsetPos -= subStream.Size;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      CMyComPtr<IOutStream> outStream;\r\n      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == subStream.Size)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/MultiStream.h",
    "content": "// MultiStream.h\r\n\r\n#ifndef __MULTISTREAM_H\r\n#define __MULTISTREAM_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nclass CMultiStream:\r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex;\r\n  UInt64 _pos;\r\n  UInt64 _seekPos;\r\n  UInt64 _totalLength;\r\npublic:\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<IInStream> Stream;\r\n    UInt64 Pos;\r\n    UInt64 Size;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _pos = 0;\r\n    _seekPos = 0;\r\n    _totalLength = 0;\r\n    for (int i = 0; i < Streams.Size(); i++)\r\n      _totalLength += Streams[i].Size;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n\r\n/*\r\nclass COutMultiStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<ISequentialOutStream> Stream;\r\n    UInt64 Size;\r\n    UInt64 Pos;\r\n };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp",
    "content": "// OutStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  if (_calculate)\r\n    _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/OutStreamWithCRC.h",
    "content": "// OutStreamWithCRC.h\r\n\r\n#ifndef __OUT_STREAM_WITH_CRC_H\r\n#define __OUT_STREAM_WITH_CRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass COutStreamWithCRC:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _calculate;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(bool calculate = true)\r\n  {\r\n    _size = 0;\r\n    _calculate = calculate;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void InitCRC() { _crc = CRC_INIT_VAL; }\r\n  UInt64 GetSize() const { return _size; }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/ParseProperties.cpp",
    "content": "// ParseProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ParseProperties.h\"\r\n\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (prop.vt == VT_UI4)\r\n  {\r\n    if (!name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    resValue = prop.ulVal;\r\n  }\r\n  else if (prop.vt == VT_EMPTY)\r\n  {\r\n    if(!name.IsEmpty())\r\n    {\r\n      const wchar_t *start = name;\r\n      const wchar_t *end;\r\n      UInt64 v = ConvertStringToUInt64(start, &end);\r\n      if (end - start != name.Length())\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)v;\r\n    }\r\n  }\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kLogarithmicSizeLimit = 32;\r\nstatic const wchar_t kByteSymbol = L'B';\r\nstatic const wchar_t kKiloByteSymbol = L'K';\r\nstatic const wchar_t kMegaByteSymbol = L'M';\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)\r\n{\r\n  UString srcString = srcStringSpec;\r\n  srcString.MakeUpper();\r\n\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || srcString.Length() > numDigits + 1)\r\n    return E_INVALIDARG;\r\n  if (srcString.Length() == numDigits)\r\n  {\r\n    if (number >= kLogarithmicSizeLimit)\r\n      return E_INVALIDARG;\r\n    dicSize = (UInt32)1 << (int)number;\r\n    return S_OK;\r\n  }\r\n  switch (srcString[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      if (number >= ((UInt64)1 << kLogarithmicSizeLimit))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)number;\r\n      break;\r\n    case kKiloByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 10);\r\n      break;\r\n    case kMegaByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 20);\r\n      break;\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    if (prop.vt == VT_UI4)\r\n    {\r\n      UInt32 logDicSize = prop.ulVal;\r\n      if (logDicSize >= 32)\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)1 << logDicSize;\r\n      return S_OK;\r\n    }\r\n    if (prop.vt == VT_BSTR)\r\n      return ParsePropDictionaryValue(prop.bstrVal, resValue);\r\n    return E_INVALIDARG;\r\n  }\r\n  return ParsePropDictionaryValue(name, resValue);\r\n}\r\n\r\nbool StringToBool(const UString &s, bool &res)\r\n{\r\n  if (s.IsEmpty() || s.CompareNoCase(L\"ON\") == 0 || s.Compare(L\"+\") == 0)\r\n  {\r\n    res = true;\r\n    return true;\r\n  }\r\n  if (s.CompareNoCase(L\"OFF\") == 0 || s.Compare(L\"-\") == 0)\r\n  {\r\n    res = false;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      dest = true;\r\n      return S_OK;\r\n    case VT_BOOL:\r\n      dest = (value.boolVal != VARIANT_FALSE);\r\n      return S_OK;\r\n    /*\r\n    case VT_UI4:\r\n      dest = (value.ulVal != 0);\r\n      break;\r\n    */\r\n    case VT_BSTR:\r\n      return StringToBool(value.bstrVal, dest) ?  S_OK : E_INVALIDARG;\r\n  }\r\n  return E_INVALIDARG;\r\n}\r\n\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number)\r\n{\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number64 = ConvertStringToUInt64(start, &end);\r\n  if (number64 > 0xFFFFFFFF)\r\n  {\r\n    number = 0;\r\n    return 0;\r\n  }\r\n  number = (UInt32)number64;\r\n  return (int)(end - start);\r\n}\r\n\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    switch(prop.vt)\r\n    {\r\n      case VT_UI4:\r\n        numThreads = prop.ulVal;\r\n        break;\r\n      default:\r\n      {\r\n        bool val;\r\n        RINOK(SetBoolProperty(val, prop));\r\n        numThreads = (val ? defaultNumThreads : 1);\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index != name.Length())\r\n      return E_INVALIDARG;\r\n    numThreads = number;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/ParseProperties.h",
    "content": "// ParseProperties.h\r\n\r\n#ifndef __PARSEPROPERTIES_H\r\n#define __PARSEPROPERTIES_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\n\r\nbool StringToBool(const UString &s, bool &res);\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number);\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/DllExports2.cpp",
    "content": "// DLLExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyInitGuid.h\"\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nHINSTANCE g_hInstance;\r\n#ifndef _UNICODE\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)\r\n{\r\n  if (dwReason == DLL_PROCESS_ATTACH)\r\n  {\r\n    g_hInstance = hInstance;\r\n    #ifndef _UNICODE\r\n    #ifdef _WIN32\r\n    g_IsNT = IsItWindowsNT();\r\n    #endif\r\n    #endif\r\n  }\r\n  return TRUE;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler,\r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec,\r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);\r\nSTDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);\r\n\r\nSTDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  // COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)\r\n  {\r\n    return CreateCoder(clsid, iid, outObject);\r\n  }\r\n  else\r\n  {\r\n    return CreateArchiver(clsid, iid, outObject);\r\n  }\r\n  // COM_TRY_END\r\n}\r\n\r\nSTDAPI SetLargePageMode()\r\n{\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  SetLargePageSize();\r\n  #endif\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/IArchive.h",
    "content": "// IArchive.h\r\n\r\n#ifndef __IARCHIVE_H\r\n#define __IARCHIVE_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../IProgress.h\"\r\n#include \"../PropID.h\"\r\n\r\n#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)\r\n#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nnamespace NFileTimeType\r\n{\r\n  enum EEnum\r\n  {\r\n    kWindows,\r\n    kUnix,\r\n    kDOS\r\n  };\r\n}\r\n\r\nnamespace NArchive\r\n{\r\n  enum\r\n  {\r\n    kName = 0,\r\n    kClassID,\r\n    kExtension,\r\n    kAddExtension,\r\n    kUpdate,\r\n    kKeepName,\r\n    kStartSignature,\r\n    kFinishSignature,\r\n    kAssociate\r\n  };\r\n\r\n  namespace NExtract\r\n  {\r\n    namespace NAskMode\r\n    {\r\n      enum\r\n      {\r\n        kExtract = 0,\r\n        kTest,\r\n        kSkip\r\n      };\r\n    }\r\n    namespace NOperationResult\r\n    {\r\n      enum\r\n      {\r\n        kOK = 0,\r\n        kUnSupportedMethod,\r\n        kDataError,\r\n        kCRCError\r\n      };\r\n    }\r\n  }\r\n  namespace NUpdate\r\n  {\r\n    namespace NOperationResult\r\n    {\r\n      enum\r\n      {\r\n        kOK = 0,\r\n        kError\r\n      };\r\n    }\r\n  }\r\n}\r\n\r\n#define INTERFACE_IArchiveOpenCallback(x) \\\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) x; \\\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)\r\n{\r\n  INTERFACE_IArchiveOpenCallback(PURE);\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveExtractCallback(x) \\\r\n  INTERFACE_IProgress(x) \\\r\n  /* GetStream OUT: S_OK - OK, S_FALSE - skeep this file */ \\\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream,  Int32 askExtractMode) x; \\\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode) x; \\\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)\r\n{\r\n  INTERFACE_IArchiveExtractCallback(PURE)\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveOpenVolumeCallback(x) \\\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) x; \\\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)\r\n{\r\n  INTERFACE_IArchiveOpenVolumeCallback(PURE);\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)\r\n{\r\n  STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;\r\n};\r\n\r\n\r\n/*\r\nIInArchive::Extract:\r\n  indices must be sorted\r\n  numItems = 0xFFFFFFFF means \"all files\"\r\n  testMode != 0 means \"test files without writing to outStream\"\r\n*/\r\n\r\n#define INTERFACE_IInArchive(x) \\\r\n  STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \\\r\n  STDMETHOD(Close)() x; \\\r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \\\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \\\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;\r\n\r\nARCHIVE_INTERFACE(IInArchive, 0x60)\r\n{\r\n  INTERFACE_IInArchive(PURE)\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveUpdateCallback(x) \\\r\n  INTERFACE_IProgress(x); \\\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,  \\\r\n      Int32 *newData, /*1 - new data, 0 - old data */ \\\r\n      Int32 *newProperties, /* 1 - new properties, 0 - old properties */ \\\r\n      UInt32 *indexInArchive /* -1 if there is no in archive, or if doesn't matter */ \\\r\n      )  x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) x; \\\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)\r\n{\r\n  INTERFACE_IArchiveUpdateCallback(PURE);\r\n};\r\n\r\n#define INTERFACE_IArchiveUpdateCallback2(x) \\\r\n  INTERFACE_IArchiveUpdateCallback(x) \\\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) x; \\\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)\r\n{\r\n  INTERFACE_IArchiveUpdateCallback2(PURE);\r\n};\r\n\r\n\r\n#define INTERFACE_IOutArchive(x) \\\r\n  STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \\\r\n  STDMETHOD(GetFileTimeType)(UInt32 *type) x;\r\n\r\nARCHIVE_INTERFACE(IOutArchive, 0xA0)\r\n{\r\n  INTERFACE_IOutArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(ISetProperties, 0x03)\r\n{\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;\r\n};\r\n\r\n\r\n#define IMP_IInArchive_GetProp(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \\\r\n\r\n#define IMP_IInArchive_GetProp_WITH_NAME(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; \\\r\n    if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \\\r\n\r\n#define IMP_IInArchive_Props \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)\r\n\r\n#define IMP_IInArchive_Props_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)\r\n\r\n\r\n#define IMP_IInArchive_ArcProps \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_NO \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = 0; return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \\\r\n    { return E_NOTIMPL; } \\\r\n  STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \\\r\n    { value->vt = VT_EMPTY; return S_OK; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp",
    "content": "// LzmaArcRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"LzmaHandler.h\"\r\n\r\nstatic IInArchive *CreateArc() { return new NArchive::NLzma::CHandler;  }\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"Lzma\", L\"lzma lzma86\", 0, 0xA, {0 }, 0, true, CreateArc, NULL };\r\n\r\nREGISTER_ARC(Lzma)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp",
    "content": "// LzmaFiltersDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaFiltersDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nstatic const UInt64 k_LZMA = 0x030101;\r\nstatic const UInt64 k_BCJ = 0x03030103;\r\n  \r\nHRESULT CDecoder::Code(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CHeader &block,\r\n    ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    UInt64 *inProcessedSize, ICompressProgressInfo *progress)\r\n{\r\n  *inProcessedSize = (UInt64)(Int64)-1;\r\n\r\n  if (block.FilterMethod > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (!_lzmaDecoder)\r\n  {\r\n    RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_LZMA, _lzmaDecoder, false));\r\n    if (_lzmaDecoder == 0)\r\n      return E_NOTIMPL;\r\n  }\r\n\r\n  {\r\n    CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n    _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n    if (!setDecoderProperties)\r\n      return E_NOTIMPL;\r\n    RINOK(setDecoderProperties->SetDecoderProperties2(block.LzmaProps, 5));\r\n  }\r\n\r\n  bool filteredMode = (block.FilterMethod == 1);\r\n\r\n  CMyComPtr<ICompressSetOutStream> setOutStream;\r\n\r\n  if (filteredMode)\r\n  {\r\n    if (!_bcjStream)\r\n    {\r\n      CMyComPtr<ICompressCoder> coder;\r\n      RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_BCJ, coder, false));\r\n      if (!coder)\r\n        return E_NOTIMPL;\r\n      coder.QueryInterface(IID_ISequentialOutStream, &_bcjStream);\r\n      if (!_bcjStream)\r\n        return E_NOTIMPL;\r\n    }\r\n\r\n    _bcjStream.QueryInterface(IID_ICompressSetOutStream, &setOutStream);\r\n    if (!setOutStream)\r\n      return E_NOTIMPL;\r\n    RINOK(setOutStream->SetOutStream(outStream));\r\n    outStream = _bcjStream;\r\n  }\r\n\r\n  const UInt64 *unpackSize = block.HasUnpackSize() ? &block.UnpackSize : NULL;\r\n  RINOK(_lzmaDecoder->Code(inStream, outStream, NULL, unpackSize, progress));\r\n\r\n  if (filteredMode)\r\n  {\r\n    CMyComPtr<IOutStreamFlush> flush;\r\n    _bcjStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n    if (flush)\r\n    {\r\n      RINOK(flush->Flush());\r\n    }\r\n    RINOK(setOutStream->ReleaseOutStream());\r\n  }\r\n\r\n  CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;\r\n  _lzmaDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);\r\n  if (getInStreamProcessedSize)\r\n  {\r\n    RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(inProcessedSize));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h",
    "content": "// LzmaFiltersDecode.h\r\n\r\n#ifndef __LZMA_FILTERS_DECODE_H\r\n#define __LZMA_FILTERS_DECODE_H\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"LzmaItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nclass CDecoder\r\n{\r\n  CMyComPtr<ICompressCoder> _lzmaDecoder;\r\n  CMyComPtr<ISequentialOutStream> _bcjStream;\r\npublic:\r\n  HRESULT Code(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CHeader &block,\r\n      ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      UInt64 *inProcessedSize, ICompressProgressInfo *progress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Lzma/LzmaHandler.cpp",
    "content": "// LzmaHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaHandler.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n#include \"../Common/DummyOutStream.h\"\r\n\r\n#include \"LzmaFiltersDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nSTATPROPSTG kProps[] =\r\n{\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidPackSize, VT_UI8},\r\n  { NULL, kpidMethod, VT_UI1}\r\n};\r\n\r\nIMP_IInArchive_Props\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = 1;\r\n  return S_OK;\r\n}\r\n\r\nstatic void ConvertUInt32ToString(UInt32 value, wchar_t *s)\r\n{\r\n  ConvertUInt64ToString(value, s + MyStringLen(s));\r\n}\r\n\r\nstatic void DictSizeToString(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i <= 31; i++)\r\n    if ((UInt32(1) << i) == value)\r\n    {\r\n      ConvertUInt32ToString(i, s);\r\n      return;\r\n    }\r\n  wchar_t c = L'b';\r\n  if ((value & ((1 << 20) - 1)) == 0)\r\n  {\r\n    value >>= 20;\r\n    c = L'm';\r\n  }\r\n  else if ((value & ((1 << 10) - 1)) == 0)\r\n  {\r\n    value >>= 10;\r\n    c = L'k';\r\n  }\r\n  ConvertUInt32ToString(value, s);\r\n  int p = MyStringLen(s);\r\n  s[p++] = c;\r\n  s[p++] = L'\\0';\r\n}\r\n\r\nstatic void MyStrCat(wchar_t *d, const wchar_t *s)\r\n{\r\n  MyStringCopy(d + MyStringLen(d), s);\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  switch(propID)\r\n  {\r\n    case kpidSize:\r\n      if (m_StreamInfo.HasUnpackSize())\r\n        propVariant = (UInt64)m_StreamInfo.UnpackSize;\r\n      break;\r\n    case kpidPackSize:\r\n      propVariant = (UInt64)m_PackSize;\r\n      break;\r\n    case kpidMethod:\r\n    {\r\n      wchar_t s[64];\r\n      s[0] = '\\0';\r\n      if (m_StreamInfo.IsThereFilter)\r\n      {\r\n        const wchar_t *f;\r\n        if (m_StreamInfo.FilterMethod == 0)\r\n          f = L\"Copy\";\r\n        else if (m_StreamInfo.FilterMethod == 1)\r\n          f = L\"BCJ\";\r\n        else\r\n          f = L\"Unknown\";\r\n        MyStrCat(s, f);\r\n        MyStrCat(s, L\" \");\r\n      }\r\n      MyStrCat(s, L\"LZMA:\");\r\n      DictSizeToString(m_StreamInfo.GetDicSize(), s);\r\n      propVariant = s;\r\n      break;\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *inStream,\r\n    const UInt64 * /* maxCheckStartPosition */,\r\n    IArchiveOpenCallback * /* openArchiveCallback */)\r\n{\r\n  {\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));\r\n\r\n    HRESULT res = ReadStreamHeader(inStream, m_StreamInfo);\r\n    if (res != S_OK)\r\n      return S_FALSE;\r\n    \r\n    Byte b;\r\n    RINOK(ReadStream_FALSE(inStream, &b, 1));\r\n    if (b != 0)\r\n      return S_FALSE;\r\n\r\n    UInt64 endPos;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));\r\n    m_PackSize = endPos - m_StreamStartPosition - m_StreamInfo.GetHeaderSize();\r\n\r\n    m_Stream = inStream;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  m_Stream.Release();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 _aTestMode, IArchiveExtractCallback *extractCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (!allFilesMode)\r\n  {\r\n    if (numItems == 0)\r\n      return S_OK;\r\n    if (numItems != 1)\r\n      return E_INVALIDARG;\r\n    if (indices[0] != 0)\r\n      return E_INVALIDARG;\r\n  }\r\n\r\n  bool testMode = (_aTestMode != 0);\r\n\r\n  RINOK(extractCallback->SetTotal(m_PackSize));\r\n    \r\n  UInt64 currentTotalPacked = 0;\r\n\r\n  CDummyOutStream *outStreamSpec = new CDummyOutStream;\r\n  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n\r\n  {\r\n    CMyComPtr<ISequentialOutStream> realOutStream;\r\n    Int32 askMode = testMode ?\r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n    \r\n    RINOK(extractCallback->GetStream(0, &realOutStream, askMode));\r\n\r\n    outStreamSpec->SetStream(realOutStream);\r\n    outStreamSpec->Init();\r\n    if(!testMode && !realOutStream)\r\n      return S_OK;\r\n    extractCallback->PrepareOperation(askMode);\r\n  }\r\n  \r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, true);\r\n\r\n  CDecoder decoder;\r\n  RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));\r\n  UInt64 streamPos = m_StreamStartPosition;\r\n  Int32 opRes = NArchive::NExtract::NOperationResult::kOK;\r\n  bool firstItem = true;\r\n  for (;;)\r\n  {\r\n    CHeader st;\r\n    HRESULT result = ReadStreamHeader(m_Stream, st);\r\n    if (result != S_OK)\r\n    {\r\n      if (firstItem)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    firstItem = false;\r\n\r\n    lps->OutSize = outStreamSpec->GetSize();\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    streamPos += st.GetHeaderSize();\r\n    UInt64 packProcessed;\r\n\r\n    {\r\n      result = decoder.Code(\r\n          EXTERNAL_CODECS_VARS\r\n          st, m_Stream, outStream, &packProcessed, progress);\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;\r\n        break;\r\n      }\r\n      if (result == S_FALSE)\r\n      {\r\n        opRes = NArchive::NExtract::NOperationResult::kDataError;\r\n        break;\r\n      }\r\n      RINOK(result);\r\n    }\r\n\r\n    if (packProcessed == (UInt64)(Int64)-1)\r\n      break;\r\n    RINOK(m_Stream->Seek(streamPos + packProcessed, STREAM_SEEK_SET, NULL));\r\n    currentTotalPacked += packProcessed;\r\n    streamPos += packProcessed;\r\n  }\r\n  outStream.Release();\r\n  return extractCallback->SetOperationResult(opRes);\r\n  COM_TRY_END\r\n}\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Lzma/LzmaHandler.h",
    "content": "// Lzma/Handler.h\r\n\r\n#ifndef __GZIP_HANDLER_H\r\n#define __GZIP_HANDLER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"LzmaIn.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\n// const UInt64 k_LZMA = 0x030101;\r\n\r\nclass CHandler:\r\n  public IInArchive,\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n  MY_QUERYINTERFACE_ENTRY(IInArchive)\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  STDMETHOD(Open)(IInStream *inStream,\r\n      const UInt64 *maxCheckStartPosition,\r\n      IArchiveOpenCallback *openArchiveCallback);\r\n  STDMETHOD(Close)();\r\n  \r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID,  PROPVARIANT *value);\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems,\r\n      Int32 testMode, IArchiveExtractCallback *extractCallback);\r\n\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);\r\n\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties);\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index,\r\n      BSTR *name, PROPID *propID, VARTYPE *varType);\r\n\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties);\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index,\r\n      BSTR *name, PROPID *propID, VARTYPE *varType);\r\n\r\n  UString GetMethodString();\r\npublic:\r\n  CHandler() {  }\r\n\r\nprivate:\r\n  CHeader m_StreamInfo;\r\n  UInt64 m_StreamStartPosition;\r\n  UInt64 m_PackSize;\r\n\r\n  CMyComPtr<IInStream> m_Stream;\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Lzma/LzmaIn.cpp",
    "content": "// Archive/LzmaIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaIn.h\"\r\n\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n \r\nstatic bool CheckDictSize(const Byte *p)\r\n{\r\n  UInt32 dicSize = GetUi32(p);\r\n  int i;\r\n  for (i = 1; i <= 30; i++)\r\n    if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block)\r\n{\r\n  Byte sig[5 + 9];\r\n  RINOK(ReadStream_FALSE(inStream, sig, 5 + 8));\r\n\r\n  const Byte kMaxProp0Val = 5 * 5 * 9 - 1;\r\n  if (sig[0] > kMaxProp0Val)\r\n    return S_FALSE;\r\n\r\n  for (int i = 0; i < 5; i++)\r\n    block.LzmaProps[i] = sig[i];\r\n  \r\n  block.IsThereFilter = false;\r\n  block.FilterMethod = 0;\r\n\r\n  if (!CheckDictSize(sig + 1))\r\n  {\r\n    if (sig[0] > 1 || sig[1] > kMaxProp0Val)\r\n      return S_FALSE;\r\n    block.IsThereFilter = true;\r\n    block.FilterMethod = sig[0];\r\n    for (int i = 0; i < 5; i++)\r\n      block.LzmaProps[i] = sig[i + 1];\r\n    if (!CheckDictSize(block.LzmaProps + 1))\r\n      return S_FALSE;\r\n    RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1));\r\n  }\r\n  UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0);\r\n  block.UnpackSize = GetUi64(sig + unpOffset);\r\n  if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56))\r\n    return S_FALSE;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Lzma/LzmaIn.h",
    "content": "// Archive/LzmaIn.h\r\n\r\n#ifndef __ARCHIVE_LZMA_IN_H\r\n#define __ARCHIVE_LZMA_IN_H\r\n\r\n#include \"LzmaItem.h\"\r\n#include \"../../IStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &st);\r\n\r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Lzma/LzmaItem.h",
    "content": "// Archive/LzmaItem.h\r\n\r\n#ifndef __ARCHIVE_LZMA_ITEM_H\r\n#define __ARCHIVE_LZMA_ITEM_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\n#include \"../../../../C/CpuArch.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nstruct CHeader\r\n{\r\n  UInt64 UnpackSize;\r\n  bool IsThereFilter;\r\n  Byte FilterMethod;\r\n  Byte LzmaProps[5];\r\n\r\n  UInt32 GetDicSize() const { return GetUi32(LzmaProps + 1); }\r\n  bool HasUnpackSize() const { return (UnpackSize != (UInt64)(Int64)-1);  }\r\n  unsigned GetHeaderSize() const { return 5 + 8 + (IsThereFilter ? 1 : 0); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Lzma/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Split/SplitHandler.cpp",
    "content": "// SplitHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/ComTry.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"../../Common/ProgressUtils.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/MultiStream.h\"\r\n\r\n#include \"SplitHandler.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\nSTATPROPSTG kProps[] =\r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidPackSize, VT_UI8},\r\n};\r\n\r\nIMP_IInArchive_Props\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nclass CSeqName\r\n{\r\npublic:\r\n  UString _unchangedPart;\r\n  UString _changedPart;\r\n  bool _splitStyle;\r\n  UString GetNextName()\r\n  {\r\n    UString newName;\r\n    if (_splitStyle)\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == 'z')\r\n        {\r\n          c = 'a';\r\n          newName = c + newName;\r\n          continue;\r\n        }\r\n        else if (c == 'Z')\r\n        {\r\n          c = 'A';\r\n          newName = c + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        if ((c == 'z' || c == 'Z') && i == 0)\r\n        {\r\n          _unchangedPart += c;\r\n          wchar_t newChar = (c == 'z') ? L'a' : L'A';\r\n          newName.Empty();\r\n          numLetters++;\r\n          for (int k = 0; k < numLetters; k++)\r\n            newName += newChar;\r\n          break;\r\n        }\r\n        newName = c + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == L'9')\r\n        {\r\n          c = L'0';\r\n          newName = c + newName;\r\n          if (i == 0)\r\n            newName = UString(L'1') + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        newName = c + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n    }\r\n    _changedPart = newName;\r\n    return _unchangedPart + _changedPart;\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 * /* maxCheckStartPosition */,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  if (openArchiveCallback == 0)\r\n    return S_FALSE;\r\n  // try\r\n  {\r\n    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openArchiveCallback;\r\n    if (openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback,\r\n        &openVolumeCallback) != S_OK)\r\n      return S_FALSE;\r\n    \r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(openVolumeCallback->GetProperty(kpidName, &prop));\r\n      if (prop.vt != VT_BSTR)\r\n        return S_FALSE;\r\n      _name = prop.bstrVal;\r\n    }\r\n    \r\n    int dotPos = _name.ReverseFind('.');\r\n    UString prefix, ext;\r\n    if (dotPos >= 0)\r\n    {\r\n      prefix = _name.Left(dotPos + 1);\r\n      ext = _name.Mid(dotPos + 1);\r\n    }\r\n    else\r\n      ext = _name;\r\n    UString extBig = ext;\r\n    extBig.MakeUpper();\r\n\r\n    CSeqName seqName;\r\n\r\n    int numLetters = 2;\r\n    bool splitStyle = false;\r\n    if (extBig.Right(2) == L\"AA\")\r\n    {\r\n      splitStyle = true;\r\n      while (numLetters < extBig.Length())\r\n      {\r\n        if (extBig[extBig.Length() - numLetters - 1] != 'A')\r\n          break;\r\n        numLetters++;\r\n      }\r\n    }\r\n    else if (ext.Right(2) == L\"01\")\r\n    {\r\n      while (numLetters < extBig.Length())\r\n      {\r\n        if (extBig[extBig.Length() - numLetters - 1] != '0')\r\n          break;\r\n        numLetters++;\r\n      }\r\n      if (numLetters != ext.Length())\r\n        return S_FALSE;\r\n    }\r\n    else\r\n      return S_FALSE;\r\n\r\n    _streams.Add(stream);\r\n\r\n    seqName._unchangedPart = prefix + ext.Left(extBig.Length() - numLetters);\r\n    seqName._changedPart = ext.Right(numLetters);\r\n    seqName._splitStyle = splitStyle;\r\n\r\n    if (prefix.Length() < 1)\r\n      _subName = L\"file\";\r\n    else\r\n      _subName = prefix.Left(prefix.Length() - 1);\r\n\r\n    _totalSize = 0;\r\n    UInt64 size;\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\r\n      if (prop.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      size = prop.uhVal.QuadPart;\r\n    }\r\n    _totalSize += size;\r\n    _sizes.Add(size);\r\n    \r\n    if (openArchiveCallback != NULL)\r\n    {\r\n      UInt64 numFiles = _streams.Size();\r\n      RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\r\n    }\r\n\r\n    for (;;)\r\n    {\r\n      UString fullName = seqName.GetNextName();\r\n      CMyComPtr<IInStream> nextStream;\r\n      HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);\r\n      if (result == S_FALSE)\r\n        break;\r\n      if (result != S_OK)\r\n        return result;\r\n      if (!stream)\r\n        break;\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\r\n        if (prop.vt != VT_UI8)\r\n          return E_INVALIDARG;\r\n        size = prop.uhVal.QuadPart;\r\n      }\r\n      _totalSize += size;\r\n      _sizes.Add(size);\r\n      _streams.Add(nextStream);\r\n      if (openArchiveCallback != NULL)\r\n      {\r\n        UInt64 numFiles = _streams.Size();\r\n        RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\r\n      }\r\n    }\r\n  }\r\n  /*\r\n  catch(...)\r\n  {\r\n    return S_FALSE;\r\n  }\r\n  */\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  _sizes.Clear();\r\n  _streams.Clear();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = _streams.IsEmpty() ? 0 : 1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n      prop = _subName;\r\n      break;\r\n    case kpidSize:\r\n    case kpidPackSize:\r\n      prop = _totalSize;\r\n      break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  if (numItems != UInt32(-1))\r\n  {\r\n    if (numItems != 1)\r\n      return E_INVALIDARG;\r\n    if (indices[0] != 0)\r\n      return E_INVALIDARG;\r\n  }\r\n  bool testMode = (_aTestMode != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = _anExtractCallback;\r\n  extractCallback->SetTotal(_totalSize);\r\n  \r\n  /*\r\n  CMyComPtr<IArchiveVolumeExtractCallback> volumeExtractCallback;\r\n  if (extractCallback.QueryInterface(&volumeExtractCallback) != S_OK)\r\n    return E_FAIL;\r\n  */\r\n\r\n  UInt64 currentTotalSize = 0;\r\n  UInt64 currentItemSize;\r\n\r\n  RINOK(extractCallback->SetCompleted(&currentTotalSize));\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n  Int32 askMode;\r\n  askMode = testMode ? NArchive::NExtract::NAskMode::kTest :\r\n  NArchive::NExtract::NAskMode::kExtract;\r\n  Int32 index = 0;\r\n  RINOK(extractCallback->GetStream(index, &realOutStream, askMode));\r\n  \r\n  RINOK(extractCallback->PrepareOperation(askMode));\r\n  if (testMode)\r\n  {\r\n    RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\r\n    return S_OK;\r\n  }\r\n  \r\n  if (!testMode && (!realOutStream))\r\n    return S_OK;\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for (int i = 0; i < _streams.Size(); i++, currentTotalSize += currentItemSize)\r\n  {\r\n    lps->InSize = lps->OutSize = currentTotalSize;\r\n    RINOK(lps->SetCur());\r\n    IInStream *inStream = _streams[i];\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));\r\n    currentItemSize = copyCoderSpec->TotalSize;\r\n  }\r\n  realOutStream.Release();\r\n  return extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  *stream = 0;\r\n  CMultiStream *streamSpec = new CMultiStream;\r\n  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;\r\n  for (int i = 0; i < _streams.Size(); i++)\r\n  {\r\n    CMultiStream::CSubStreamInfo subStreamInfo;\r\n    subStreamInfo.Stream = _streams[i];\r\n    subStreamInfo.Pos = 0;\r\n    subStreamInfo.Size = _sizes[i];\r\n    streamSpec->Streams.Add(subStreamInfo);\r\n  }\r\n  streamSpec->Init();\r\n  *stream = streamTemp.Detach();\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Split/SplitHandler.h",
    "content": "// Split/Handler.h\r\n\r\n#ifndef __SPLIT_HANDLER_H\r\n#define __SPLIT_HANDLER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\nclass CHandler:\r\n  public IInArchive,\r\n  public IInArchiveGetStream,\r\n  // public IOutArchive,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);\r\n\r\nprivate:\r\n  UString _subName;\r\n  UString _name;\r\n  CObjectVector<CMyComPtr<IInStream> > _streams;\r\n  CRecordVector<UInt64> _sizes;\r\n\r\n  UInt64 _totalSize;\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Split/SplitHandlerOut.cpp",
    "content": "// Split/OutHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SplitHandler.h\"\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\n/*\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  if (numItems != 1)\r\n    return E_INVALIDARG;\r\n\r\n  UInt64 volumeSize = 0;\r\n\r\n  CMyComPtr<IArchiveUpdateCallback2> callback2;\r\n  updateCallback->QueryInterface(IID_IArchiveUpdateCallback2,\r\n      (void **)&callback2);\r\n\r\n  RINOK(callback2->GetVolumeSize(0, &volumeSize));\r\n\r\n  Int32 newData;\r\n  Int32 newProperties;\r\n  UInt32 indexInArchive;\r\n  if (!updateCallback)\r\n    return E_FAIL;\r\n\r\n  UInt32 fileIndex = 0;\r\n  RINOK(updateCallback->GetUpdateItemInfo(fileIndex,\r\n    &newData, &newProperties, &indexInArchive));\r\n\r\n  if (newProperties != 0)\r\n  {\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsFolder, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n      }\r\n      else if (prop.vt != VT_BOOL)\r\n        return E_INVALIDARG;\r\n      else\r\n      {\r\n        if (prop.boolVal != VARIANT_FALSE)\r\n          return E_INVALIDARG;\r\n      }\r\n    }\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsAnti, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n      }\r\n      else if (prop.vt != VT_BOOL)\r\n        return E_INVALIDARG;\r\n      else\r\n      {\r\n        if (prop.boolVal != VARIANT_FALSE)\r\n          return E_INVALIDARG;\r\n      }\r\n    }\r\n  }\r\n  UInt64 newSize;\r\n  bool thereIsCopyData = false;\r\n  if (newData != 0)\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(updateCallback->GetProperty(fileIndex, kpidSize, &prop));\r\n    if (prop.vt != VT_UI8)\r\n      return E_INVALIDARG;\r\n    newSize = prop.uhVal.QuadPart;\r\n  }\r\n  else\r\n    thereIsCopyData = true;\r\n\r\n  UInt64 pos = 0;\r\n  while(pos < newSize)\r\n  {\r\n\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Split/SplitRegister.cpp",
    "content": "// SplitRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"SplitHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::NSplit::CHandler;  }\r\n/*\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::NSplit::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n*/\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n{ L\"Split\", L\"001\", 0, 0xEA, { 0 }, 0, false, CreateArc, 0 };\r\n\r\nREGISTER_ARC(Split)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/Split/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Archive/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Alone7z/Alone.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Alone\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Alone - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\" CFG=\"Alone - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Alone - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Alone - Win32 Release\"\r\n# Name \"Alone - Win32 Debug\"\r\n# Name \"Alone - Win32 ReleaseU\"\r\n# Name \"Alone - Win32 DebugU\"\r\n# Begin Group \"Console\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ArError.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\CompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\Main.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\MainAr.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\AutoPtr.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Buffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ComTry.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\DynamicBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyException.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyGuidDef.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyInitGuid.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Device.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Handle.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterArc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterCodec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA_Alone\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Coder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Coder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Register.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchMisc.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchMisc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwap.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwap.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwapRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"7z\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zExtract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"split\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZM\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaArcRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaItem.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"UI Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Property.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7-zip\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IMyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IPassword.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\PropID.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\BraIA64.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Alone7z/Alone.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Alone\"=.\\Alone.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Alone7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Alone7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Alone7z/makefile",
    "content": "PROG = 7za.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib Advapi32.lib\r\n\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -D_NO_CRYPTO \\\r\n  -DWIN_LONG_PATH \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n  $O\\Time.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OffsetStream.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\DummyOutStream.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\MultiStream.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n\r\nLZM_OBJS = \\\r\n  $O\\LzmaArcRegister.obj \\\r\n  $O\\LzmaFiltersDecode.obj \\\r\n  $O\\LzmaHandler.obj \\\r\n  $O\\LzmaIn.obj \\\r\n\r\nSPLIT_OBJS = \\\r\n  $O\\SplitHandler.obj \\\r\n  $O\\SplitHandlerOut.obj \\\r\n  $O\\SplitRegister.obj \\\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(LZM_OBJS) \\\r\n  $(SPLIT_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): ../../UI/Console/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../../UI/Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZM_OBJS): ../../Archive/Lzma/$(*B).cpp\r\n\t$(COMPL)\r\n$(SPLIT_OBJS): ../../Archive/Split/$(*B).cpp\r\n\t$(COMPL)\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Alone7z/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_APP(\"7-Zip Standalone Console\", \"7za\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Format7zExtractR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Format7zExtractR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Format7zExtractR/makefile",
    "content": "PROG = 7zxr.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DEXTRACT_ONLY \\\r\n  -DCOMPRESS_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Format7zExtractR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Extracting Plugin\", \"7zxr\")\r\n\r\n101  ICON  \"../../Archive/Icons/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Format7zR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Format7zR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Format7zR/makefile",
    "content": "PROG = 7zra.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Bundles/Format7zR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Plugin\", \"7zr\")\r\n\r\n101  ICON  \"../../Archive/Icons/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/CreateCoder.cpp",
    "content": "// CreateCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CreateCoder.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Windows/Defs.h\"\r\n#include \"FilterCoder.h\"\r\n#include \"RegisterCodec.h\"\r\n\r\nstatic const unsigned int kNumCodecsMax = 64;\r\nunsigned int g_NumCodecs = 0;\r\nconst CCodecInfo *g_Codecs[kNumCodecsMax];\r\nvoid RegisterCodec(const CCodecInfo *codecInfo)\r\n{\r\n  if (g_NumCodecs < kNumCodecsMax)\r\n    g_Codecs[g_NumCodecs++] = codecInfo;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = 1;\r\n  else if (prop.vt == VT_UI4)\r\n    res = prop.ulVal;\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = true;\r\n  else if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs)\r\n{\r\n  UInt32 num;\r\n  RINOK(codecsInfo->GetNumberOfMethods(&num));\r\n  for (UInt32 i = 0; i < num; i++)\r\n  {\r\n    CCodecInfoEx info;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kID, &prop));\r\n    // if (prop.vt != VT_BSTR)\r\n    // info.Id.IDSize = (Byte)SysStringByteLen(prop.bstrVal);\r\n    // memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);\r\n    if (prop.vt != VT_UI8)\r\n    {\r\n      continue; // old Interface\r\n      // return E_INVALIDARG;\r\n    }\r\n    info.Id = prop.uhVal.QuadPart;\r\n    prop.Clear();\r\n    \r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      info.Name = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_INVALIDARG;;\r\n    \r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kInStreams, info.NumInStreams));\r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kOutStreams, info.NumOutStreams));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned));\r\n    \r\n    externalCodecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  const UString &name,\r\n  CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (name.CompareNoCase(codec.Name) == 0)\r\n    {\r\n      methodId = codec.Id;\r\n      numInStreams = codec.NumInStreams;\r\n      numOutStreams = 1;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (codec.Name.CompareNoCase(name) == 0)\r\n      {\r\n        methodId = codec.Id;\r\n        numInStreams = codec.NumInStreams;\r\n        numOutStreams = codec.NumOutStreams;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  CMethodId methodId, UString &name)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (methodId == codec.Id)\r\n    {\r\n      name = codec.Name;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (methodId == codec.Id)\r\n      {\r\n        name = codec.Name;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder)\r\n{\r\n  bool created = false;\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (codec.Id == methodId)\r\n    {\r\n      if (encode)\r\n      {\r\n        if (codec.CreateEncoder)\r\n        {\r\n          void *p = codec.CreateEncoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n      }\r\n      else\r\n        if (codec.CreateDecoder)\r\n        {\r\n          void *p = codec.CreateDecoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  if (!created && externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (codec.Id == methodId)\r\n      {\r\n        if (encode)\r\n        {\r\n          if (codec.EncoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n        }\r\n        else\r\n          if (codec.DecoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n      }\r\n    }\r\n  #endif\r\n\r\n  if (onlyCoder && filter)\r\n  {\r\n    CFilterCoder *coderSpec = new CFilterCoder;\r\n    coder = coderSpec;\r\n    coderSpec->Filter = filter;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, true);\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    coder, coder2, encode);\r\n}\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressCoder> coder;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, false);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/CreateCoder.h",
    "content": "// CreateCoder.h\r\n\r\n#ifndef __CREATECODER_H\r\n#define __CREATECODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nstruct CCodecInfoEx\r\n{\r\n  UString Name;\r\n  CMethodId Id;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }\r\n  CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}\r\n};\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)\r\n#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);\r\n#define IMPL_ISetCompressCodecsInfo2(x) \\\r\nSTDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \\\r\n  COM_TRY_BEGIN _codecsInfo = compressCodecsInfo;  return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }\r\n#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)\r\n\r\n#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs\r\n#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,\r\n#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,\r\n\r\n#else\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo\r\n#define DECL_ISetCompressCodecsInfo\r\n#define IMPL_ISetCompressCodecsInfo\r\n#define EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_VARS\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2\r\n#define EXTERNAL_CODECS_LOC_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS\r\n#define EXTERNAL_CODECS_LOC_VARS\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, UString &name);\r\n\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode);\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/FilePathAutoRename.cpp",
    "content": "// FilePathAutoRename.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"FilePathAutoRename.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic bool MakeAutoName(const UString &name,\r\n    const UString &extension, int value, UString &path)\r\n{\r\n  wchar_t number[32];\r\n  ConvertUInt64ToString(value, number);\r\n  path = name;\r\n  path += number;\r\n  path += extension;\r\n  return NFile::NFind::DoesFileExist(path);\r\n}\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath)\r\n{\r\n  UString path;\r\n  int dotPos = fullProcessedPath.ReverseFind(L'.');\r\n\r\n  int slashPos = fullProcessedPath.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = fullProcessedPath.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n\r\n  UString name, extension;\r\n  if (dotPos > slashPos &&  dotPos > 0)\r\n  {\r\n    name = fullProcessedPath.Left(dotPos);\r\n    extension = fullProcessedPath.Mid(dotPos);\r\n  }\r\n  else\r\n    name = fullProcessedPath;\r\n  name += L'_';\r\n  int indexLeft = 1, indexRight = (1 << 30);\r\n  while (indexLeft != indexRight)\r\n  {\r\n    int indexMid = (indexLeft + indexRight) / 2;\r\n    if (MakeAutoName(name, extension, indexMid, path))\r\n      indexLeft = indexMid + 1;\r\n    else\r\n      indexRight = indexMid;\r\n  }\r\n  if (MakeAutoName(name, extension, indexRight, fullProcessedPath))\r\n    return false;\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/FilePathAutoRename.h",
    "content": "// Util/FilePathAutoRename.h\r\n\r\n#ifndef __FILEPATHAUTORENAME_H\r\n#define __FILEPATHAUTORENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  #ifdef _WIN32\r\n  if (result)\r\n    return S_OK;\r\n  DWORD lastError = ::GetLastError();\r\n  if (lastError == 0)\r\n    return E_FAIL;\r\n  return HRESULT_FROM_WIN32(lastError);\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nbool CInFileStream::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE),\r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do\r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  }\r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nHRESULT COutFileStream::Close()\r\n{\r\n  return ConvertBoolToHRESULT(File.Close());\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  ProcessedSize += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  ProcessedSize += res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15);\r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),\r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do\r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  }\r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WIN_FILE\r\n#endif\r\n\r\n#ifdef USE_WIN_FILE\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream:\r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\npublic:\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #endif\r\n  #endif\r\n\r\n  HRESULT Close();\r\n  \r\n  UInt64 ProcessedSize;\r\n\r\n  #ifdef USE_WIN_FILE\r\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n  {\r\n    return File.SetTime(cTime, aTime, mTime);\r\n  }\r\n  bool SetMTime(const FILETIME *mTime) {  return File.SetMTime(mTime); }\r\n  #endif\r\n\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/FilterCoder.cpp",
    "content": "// FilterCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FilterCoder.h\"\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#include \"../../Common/Defs.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCFilterCoder::CFilterCoder()\r\n{\r\n  _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n}\r\n\r\nCFilterCoder::~CFilterCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)\r\n{\r\n  if (_outSizeIsDefined)\r\n  {\r\n    UInt64 remSize = _outSize - _nowPos64;\r\n    if (size > remSize)\r\n      size = (UInt32)remSize;\r\n  }\r\n  RINOK(WriteStream(outStream, _buffer, size));\r\n  _nowPos64 += size;\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  RINOK(Init());\r\n  UInt32 bufferPos = 0;\r\n  _outSizeIsDefined = (outSize != 0);\r\n  if (_outSizeIsDefined)\r\n    _outSize = *outSize;\r\n\r\n  while(NeedMore())\r\n  {\r\n    size_t processedSize = kBufferSize - bufferPos;\r\n    \r\n    // Change it: It can be optimized using ReadPart\r\n    RINOK(ReadStream(inStream, _buffer + bufferPos, &processedSize));\r\n    \r\n    UInt32 endPos = bufferPos + (UInt32)processedSize;\r\n\r\n    bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (bufferPos > endPos)\r\n    {\r\n      for (; endPos< bufferPos; endPos++)\r\n        _buffer[endPos] = 0;\r\n      bufferPos = Filter->Filter(_buffer, endPos);\r\n    }\r\n\r\n    if (bufferPos == 0)\r\n    {\r\n      if (endPos > 0)\r\n        return WriteWithLimit(outStream, endPos);\r\n      return S_OK;\r\n    }\r\n    RINOK(WriteWithLimit(outStream, bufferPos));\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));\r\n    }\r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n// #ifdef _ST_MODE\r\nSTDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _bufferPos = 0;\r\n  _outStream = outStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseOutStream()\r\n{\r\n  _outStream.Release();\r\n  return S_OK;\r\n};\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    UInt32 sizeMax = kBufferSize - _bufferPos;\r\n    UInt32 sizeTemp = size;\r\n    if (sizeTemp > sizeMax)\r\n      sizeTemp = sizeMax;\r\n    memmove(_buffer + _bufferPos, data, sizeTemp);\r\n    size -= sizeTemp;\r\n    processedSizeTotal += sizeTemp;\r\n    data = (const Byte *)data + sizeTemp;\r\n    UInt32 endPos = _bufferPos + sizeTemp;\r\n    _bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (_bufferPos == 0)\r\n    {\r\n      _bufferPos = endPos;\r\n      break;\r\n    }\r\n    if (_bufferPos > endPos)\r\n    {\r\n      if (size != 0)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    RINOK(WriteWithLimit(_outStream, _bufferPos));\r\n    UInt32 i = 0;\r\n    while(_bufferPos < endPos)\r\n      _buffer[i++] = _buffer[_bufferPos++];\r\n    _bufferPos = i;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::Flush()\r\n{\r\n  if (_bufferPos != 0)\r\n  {\r\n    UInt32 endPos = Filter->Filter(_buffer, _bufferPos);\r\n    if (endPos > _bufferPos)\r\n    {\r\n      for (; _bufferPos < endPos; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      if (Filter->Filter(_buffer, endPos) != endPos)\r\n        return E_FAIL;\r\n    }\r\n    RINOK(WriteStream(_outStream, _buffer, _bufferPos));\r\n    _bufferPos = 0;\r\n  }\r\n  CMyComPtr<IOutStreamFlush> flush;\r\n  _outStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n  if (flush)\r\n    return  flush->Flush();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _convertedPosBegin = _convertedPosEnd = _bufferPos = 0;\r\n  _inStream = inStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseInStream()\r\n{\r\n  _inStream.Release();\r\n  return S_OK;\r\n};\r\n\r\nSTDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_convertedPosBegin != _convertedPosEnd)\r\n    {\r\n      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);\r\n      memmove(data, _buffer + _convertedPosBegin, sizeTemp);\r\n      _convertedPosBegin += sizeTemp;\r\n      data = (void *)((Byte *)data + sizeTemp);\r\n      size -= sizeTemp;\r\n      processedSizeTotal += sizeTemp;\r\n      break;\r\n    }\r\n    int i;\r\n    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)\r\n      _buffer[i] = _buffer[i + _convertedPosEnd];\r\n    _bufferPos = i;\r\n    _convertedPosBegin = _convertedPosEnd = 0;\r\n    size_t processedSizeTemp = kBufferSize - _bufferPos;\r\n    RINOK(ReadStream(_inStream, _buffer + _bufferPos, &processedSizeTemp));\r\n    _bufferPos = _bufferPos + (UInt32)processedSizeTemp;\r\n    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    if (_convertedPosEnd == 0)\r\n    {\r\n      if (_bufferPos == 0)\r\n        break;\r\n      else\r\n      {\r\n        _convertedPosEnd = _bufferPos; // check it\r\n        continue;\r\n      }\r\n    }\r\n    if (_convertedPosEnd > _bufferPos)\r\n    {\r\n      for (; _bufferPos < _convertedPosEnd; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\n// #endif // _ST_MODE\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)\r\n{\r\n  return _setPassword->CryptoSetPassword(data, size);\r\n}\r\n#endif\r\n\r\n#ifndef EXTRACT_ONLY\r\nSTDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  return _writeCoderProperties->WriteCoderProperties(outStream);\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CFilterCoder::ResetSalt()\r\n{\r\n  return _CryptoResetSalt->ResetSalt();\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CFilterCoder::ResetInitVector()\r\n{\r\n  return _CryptoResetInitVector->ResetInitVector();\r\n}\r\n#endif\r\n\r\nSTDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)\r\n{\r\n  return _setDecoderProperties->SetDecoderProperties2(data, size);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/FilterCoder.h",
    "content": "// FilterCoder.h\r\n\r\n#ifndef __FILTERCODER_H\r\n#define __FILTERCODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \\\r\n{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \\\r\n*outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\nclass CFilterCoder:\r\n  public ICompressCoder,\r\n  // #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ISequentialInStream,\r\n  public ICompressSetOutStream,\r\n  public ISequentialOutStream,\r\n  public IOutStreamFlush,\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoSetPassword,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  // public ICryptoResetSalt,\r\n  public ICryptoResetInitVector,\r\n  #endif\r\n  public ICompressSetDecoderProperties2,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  // #ifdef _ST_MODE\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  CMyComPtr<ISequentialOutStream> _outStream;\r\n  UInt32 _bufferPos;\r\n  UInt32 _convertedPosBegin;\r\n  UInt32 _convertedPosEnd;\r\n  // #endif\r\n  bool _outSizeIsDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _nowPos64;\r\n\r\n  HRESULT Init()\r\n  {\r\n    _nowPos64 = 0;\r\n    _outSizeIsDefined = false;\r\n    return Filter->Init();\r\n  }\r\n\r\n  CMyComPtr<ICryptoSetPassword> _setPassword;\r\n  #ifndef EXTRACT_ONLY\r\n  CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;\r\n  CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;\r\n  // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;\r\n  CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;\r\n  #endif\r\n  CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;\r\npublic:\r\n  CMyComPtr<ICompressFilter> Filter;\r\n\r\n  CFilterCoder();\r\n  ~CFilterCoder();\r\n  HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);\r\n  bool NeedMore() const\r\n    { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }\r\n\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n    MY_QUERYINTERFACE_ENTRY(ICompressCoder)\r\n    // #ifdef _ST_MODE\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialInStream)\r\n\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)\r\n    // #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)\r\n    #endif\r\n\r\n    #ifndef EXTRACT_ONLY\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)\r\n    // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)\r\n    #endif\r\n\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  // #ifdef _ST_MODE\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \\\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Flush)();\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  // STDMETHOD(ResetSalt)();\r\n  STDMETHOD(ResetInitVector)();\r\n  #endif\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n};\r\n\r\n// #ifdef _ST_MODE\r\nclass CInStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  CInStreamReleaser(): FilterCoder(0) {}\r\n  ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }\r\n};\r\n\r\nclass COutStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  COutStreamReleaser(): FilterCoder(0) {}\r\n  ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }\r\n};\r\n// #endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nCInBuffer::CInBuffer():\r\n  _buffer(0),\r\n  _bufferLimit(0),\r\n  _bufferBase(0),\r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct CInBufferException: public CSystemException\r\n{\r\n  CInBufferException(HRESULT errorCode): CSystemException(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if (_buffer >= _bufferLimit)\r\n      if (!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if (_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  UInt32 ReadBytes(Byte *buf, UInt32 size)\r\n  {\r\n    if ((UInt32)(_bufferLimit - _buffer) >= size)\r\n    {\r\n      for (UInt32 i = 0; i < size; i++)\r\n        buf[i] = _buffer[i];\r\n      _buffer += size;\r\n      return size;\r\n    }\r\n    for (UInt32 i = 0; i < size; i++)\r\n    {\r\n      if (_buffer >= _bufferLimit)\r\n        if (!ReadBlock())\r\n          return i;\r\n      buf[i] = *_buffer++;\r\n    }\r\n    return size;\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/InOutTempBuffer.cpp",
    "content": "// InOutTempBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InOutTempBuffer.h\"\r\n#include \"../../Common/Defs.h\"\r\n// #include \"Windows/Defs.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic UInt32 kTmpBufferMemorySize = (1 << 20);\r\n\r\nstatic LPCTSTR kTempFilePrefixString = TEXT(\"iot\");\r\n\r\nCInOutTempBuffer::CInOutTempBuffer():\r\n  _buffer(NULL)\r\n{\r\n}\r\n\r\nvoid CInOutTempBuffer::Create()\r\n{\r\n  _buffer = new Byte[kTmpBufferMemorySize];\r\n}\r\n\r\nCInOutTempBuffer::~CInOutTempBuffer()\r\n{\r\n  delete []_buffer;\r\n}\r\nvoid CInOutTempBuffer::InitWriting()\r\n{\r\n  _bufferPosition = 0;\r\n  _tmpFileCreated = false;\r\n  _fileSize = 0;\r\n}\r\n\r\nbool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)\r\n{\r\n  if (size == 0)\r\n    return true;\r\n  if(!_tmpFileCreated)\r\n  {\r\n    CSysString tempDirPath;\r\n    if(!MyGetTempPath(tempDirPath))\r\n      return false;\r\n    if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)\r\n      return false;\r\n    // _outFile.SetOpenCreationDispositionCreateAlways();\r\n    if(!_outFile.Create(_tmpFileName, true))\r\n      return false;\r\n    _tmpFileCreated = true;\r\n  }\r\n  UInt32 processedSize;\r\n  if(!_outFile.Write(data, size, processedSize))\r\n    return false;\r\n  _fileSize += processedSize;\r\n  return (processedSize == size);\r\n}\r\n\r\nbool CInOutTempBuffer::FlushWrite()\r\n{\r\n  return _outFile.Close();\r\n}\r\n\r\nbool CInOutTempBuffer::Write(const void *data, UInt32 size)\r\n{\r\n  if(_bufferPosition < kTmpBufferMemorySize)\r\n  {\r\n    UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);\r\n    memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);\r\n    _bufferPosition += curSize;\r\n    size -= curSize;\r\n    data = ((const Byte *)data) + curSize;\r\n    _fileSize += curSize;\r\n  }\r\n  return WriteToFile(data, size);\r\n}\r\n\r\nbool CInOutTempBuffer::InitReading()\r\n{\r\n  _currentPositionInBuffer = 0;\r\n  if(_tmpFileCreated)\r\n    return _inFile.Open(_tmpFileName);\r\n  return true;\r\n}\r\n\r\nHRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)\r\n{\r\n  if (_currentPositionInBuffer < _bufferPosition)\r\n  {\r\n    UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;\r\n    RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite));\r\n    _currentPositionInBuffer += sizeToWrite;\r\n  }\r\n  if (!_tmpFileCreated)\r\n    return true;\r\n  for (;;)\r\n  {\r\n    UInt32 localProcessedSize;\r\n    if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))\r\n      return E_FAIL;\r\n    if (localProcessedSize == 0)\r\n      return S_OK;\r\n    RINOK(WriteStream(stream, _buffer, localProcessedSize));\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (!_buffer->Write(data, size))\r\n  {\r\n    if (processedSize != NULL)\r\n      *processedSize = 0;\r\n    return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/InOutTempBuffer.h",
    "content": "// Util/InOutTempBuffer.h\r\n\r\n#ifndef __IN_OUT_TEMP_BUFFER_H\r\n#define __IN_OUT_TEMP_BUFFER_H\r\n\r\n#include \"../../Windows/FileIO.h\"\r\n#include \"../../Windows/FileDir.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../IStream.h\"\r\n\r\nclass CInOutTempBuffer\r\n{\r\n  NWindows::NFile::NDirectory::CTempFile _tempFile;\r\n  NWindows::NFile::NIO::COutFile _outFile;\r\n  NWindows::NFile::NIO::CInFile _inFile;\r\n  Byte *_buffer;\r\n  UInt32 _bufferPosition;\r\n  UInt32 _currentPositionInBuffer;\r\n  CSysString _tmpFileName;\r\n  bool _tmpFileCreated;\r\n\r\n  UInt64 _fileSize;\r\n\r\n  bool WriteToFile(const void *data, UInt32 size);\r\npublic:\r\n  CInOutTempBuffer();\r\n  ~CInOutTempBuffer();\r\n  void Create();\r\n\r\n  void InitWriting();\r\n  bool Write(const void *data, UInt32 size);\r\n  UInt64 GetDataSize() const { return _fileSize; }\r\n  bool FlushWrite();\r\n  bool InitReading();\r\n  HRESULT WriteToStream(ISequentialOutStream *stream);\r\n};\r\n\r\nclass CSequentialOutTempBufferImp:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CInOutTempBuffer *_buffer;\r\npublic:\r\n  // CSequentialOutStreamImp(): _size(0) {}\r\n  // UInt32 _size;\r\n  void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }\r\n  // UInt32 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/LimitedStreams.cpp",
    "content": "// LimitedStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LimitedStreams.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\nSTDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size);\r\n  HRESULT result = S_OK;\r\n  if (sizeToRead > 0)\r\n  {\r\n    result = _stream->Read(data, sizeToRead, &realProcessedSize);\r\n    _pos += realProcessedSize;\r\n    if (realProcessedSize == 0)\r\n      _wasFinished = true;\r\n  }\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  HRESULT result = S_OK;\r\n  if (processedSize != NULL)\r\n    *processedSize = 0;\r\n  if (size > _size)\r\n  {\r\n    size = (UInt32)_size;\r\n    if (size == 0)\r\n    {\r\n      _overflow = true;\r\n      return E_FAIL;\r\n    }\r\n  }\r\n  if (_stream)\r\n    result = _stream->Write(data, size, &size);\r\n  _size -= size;\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/LimitedStreams.h",
    "content": "// LimitedStreams.h\r\n\r\n#ifndef __LIMITEDSTREAMS_H\r\n#define __LIMITEDSTREAMS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLimitedSequentialInStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt64 _pos;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream; }\r\n  void Init(UInt64 streamSize)\r\n  {\r\n    _size = streamSize;\r\n    _pos = 0;\r\n    _wasFinished = false;\r\n  }\r\n \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _pos; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CLimitedSequentialOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  bool _overflow;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(UInt64 size)\r\n  {\r\n    _size = size;\r\n    _overflow = false;\r\n  }\r\n  bool IsFinishedOK() const { return (_size == 0 && !_overflow); }\r\n  UInt64 GetRem() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/LockedStream.cpp",
    "content": "// LockedStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LockedStream.h\"\r\n\r\nHRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size,\r\n  UInt32 *processedSize)\r\n{\r\n  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);\r\n  RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));\r\n  return _stream->Read(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);\r\n  _pos += realProcessedSize;\r\n  if (processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/LockedStream.h",
    "content": "// LockedStream.h\r\n\r\n#ifndef __LOCKEDSTREAM_H\r\n#define __LOCKEDSTREAM_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLockedInStream\r\n{\r\n  CMyComPtr<IInStream> _stream;\r\n  NWindows::NSynchronization::CCriticalSection _criticalSection;\r\npublic:\r\n  void Init(IInStream *stream)\r\n    { _stream = stream; }\r\n  HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CLockedSequentialInStreamImp:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CLockedInStream *_lockedInStream;\r\n  UInt64 _pos;\r\npublic:\r\n  void Init(CLockedInStream *lockedInStream, UInt64 startPos)\r\n  {\r\n    _lockedInStream = lockedInStream;\r\n    _pos = startPos;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/MethodId.cpp",
    "content": "// MethodId.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodId.h\"\r\n#include \"../../Common/MyString.h\"\r\n\r\nstatic inline wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nUString ConvertMethodIdToString(UInt64 id)\r\n{\r\n  wchar_t s[32];\r\n  int len = 32;\r\n  s[--len] = 0;\r\n  do\r\n  {\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n  }\r\n  while (id != 0);\r\n  return s + len;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/MethodId.h",
    "content": "// MethodId.h\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Common/Types.h\"\r\n\r\ntypedef UInt64 CMethodId;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/MethodProps.cpp",
    "content": "// MethodProps.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodProps.h\"\r\n\r\nstatic UInt64 k_LZMA = 0x030101;\r\n// static UInt64 k_LZMA2 = 0x030102;\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)\r\n{\r\n  bool tryReduce = false;\r\n  UInt32 reducedDictionarySize = 1 << 10;\r\n  if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))\r\n  {\r\n    for (;;)\r\n    {\r\n      const UInt32 step = (reducedDictionarySize >> 1);\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      reducedDictionarySize += step;\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      if (reducedDictionarySize >= ((UInt32)3 << 30))\r\n        break;\r\n      reducedDictionarySize += step;\r\n    }\r\n  }\r\n\r\n  {\r\n    int numProps = method.Props.Size();\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n    if (setCoderProperties == NULL)\r\n    {\r\n      if (numProps != 0)\r\n        return E_INVALIDARG;\r\n    }\r\n    else\r\n    {\r\n      CRecordVector<PROPID> propIDs;\r\n      NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps];\r\n      HRESULT res = S_OK;\r\n      try\r\n      {\r\n        for (int i = 0; i < numProps; i++)\r\n        {\r\n          const CProp &prop = method.Props[i];\r\n          propIDs.Add(prop.Id);\r\n          NWindows::NCOM::CPropVariant &value = values[i];\r\n          value = prop.Value;\r\n          // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)\r\n          if (tryReduce)\r\n            if (prop.Id == NCoderPropID::kDictionarySize)\r\n              if (value.vt == VT_UI4)\r\n                if (reducedDictionarySize < value.ulVal)\r\n            value.ulVal = reducedDictionarySize;\r\n        }\r\n        CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n        coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n        res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps);\r\n      }\r\n      catch(...)\r\n      {\r\n        delete []values;\r\n        throw;\r\n      }\r\n      delete []values;\r\n      RINOK(res);\r\n    }\r\n  }\r\n \r\n  /*\r\n  CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n  coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n  if (writeCoderProperties != NULL)\r\n  {\r\n    CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n    outStreamSpec->Init();\r\n    RINOK(writeCoderProperties->WriteCoderProperties(outStream));\r\n    size_t size = outStreamSpec->GetSize();\r\n    filterProps.SetCapacity(size);\r\n    memmove(filterProps, outStreamSpec->GetBuffer(), size);\r\n  }\r\n  */\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/MethodProps.h",
    "content": "// MethodProps.h\r\n\r\n#ifndef __7Z_METHOD_PROPS_H\r\n#define __7Z_METHOD_PROPS_H\r\n\r\n#include \"../../Common/MyVector.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\nstruct CProp\r\n{\r\n  PROPID Id;\r\n  NWindows::NCOM::CPropVariant Value;\r\n};\r\n\r\nstruct CMethod\r\n{\r\n  CMethodId Id;\r\n  CObjectVector<CProp> Props;\r\n};\r\n\r\nstruct CMethodsMode\r\n{\r\n  CObjectVector<CMethod> Methods;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n\r\n  CMethodsMode()\r\n      #ifdef COMPRESS_MT\r\n      : NumThreads(1)\r\n      #endif\r\n  {}\r\n  bool IsEmpty() const { return Methods.IsEmpty() ; }\r\n};\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/OffsetStream.cpp",
    "content": "// OffsetStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"OffsetStream.h\"\r\n\r\nHRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)\r\n{\r\n  _offset = offset;\r\n  _stream = stream;\r\n  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return _stream->Write(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 absoluteNewPosition;\r\n  if (seekOrigin == STREAM_SEEK_SET)\r\n    offset += _offset;\r\n  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);\r\n  if (newPosition != NULL)\r\n    *newPosition = absoluteNewPosition - _offset;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)\r\n{\r\n  return _stream->SetSize(_offset + newSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/OffsetStream.h",
    "content": "// OffsetStream.h\r\n\r\n#ifndef __OFFSETSTREAM_H\r\n#define __OFFSETSTREAM_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass COffsetOutStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 _offset;\r\n  CMyComPtr<IOutStream> _stream;\r\npublic:\r\n  HRESULT Init(IOutStream *stream, UInt64 offset);\r\n  \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{\r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos)\r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode == S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = Flush();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException: public CSystemException\r\n{\r\n  COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void FlushWithCheck();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/ProgressUtils.cpp",
    "content": "// ProgressUtils.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ProgressUtils.h\"\r\n\r\nCLocalProgress::CLocalProgress()\r\n{\r\n  ProgressOffset = InSize = OutSize = 0;\r\n  SendRatio = SendProgress = true;\r\n}\r\n\r\nvoid CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)\r\n{\r\n  _ratioProgress.Release();\r\n  _progress = progress;\r\n  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);\r\n  _inSizeIsMain = inSizeIsMain;\r\n}\r\n\r\nSTDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  UInt64 inSizeNew = InSize, outSizeNew = OutSize;\r\n  if (inSize)\r\n    inSizeNew += (*inSize);\r\n  if (outSize)\r\n    outSizeNew += (*outSize);\r\n  if (SendRatio && _ratioProgress)\r\n  {\r\n    RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));\r\n  }\r\n  inSizeNew += ProgressOffset;\r\n  outSizeNew += ProgressOffset;\r\n  if (SendProgress)\r\n    return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CLocalProgress::SetCur()\r\n{\r\n  return SetRatioInfo(NULL, NULL);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/ProgressUtils.h",
    "content": "// ProgressUtils.h\r\n\r\n#ifndef __PROGRESSUTILS_H\r\n#define __PROGRESSUTILS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n#include \"../IProgress.h\"\r\n\r\nclass CLocalProgress:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<IProgress> _progress;\r\n  CMyComPtr<ICompressProgressInfo> _ratioProgress;\r\n  bool _inSizeIsMain;\r\npublic:\r\n  UInt64 ProgressOffset;\r\n  UInt64 InSize;\r\n  UInt64 OutSize;\r\n  bool SendRatio;\r\n  bool SendProgress;\r\n\r\n  CLocalProgress();\r\n  void Init(IProgress *progress, bool inSizeIsMain);\r\n  HRESULT SetCur();\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/RegisterArc.h",
    "content": "// RegisterArc.h\r\n\r\n#ifndef __REGISTERARC_H\r\n#define __REGISTERARC_H\r\n\r\n#include \"../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcInfo\r\n{\r\n  const wchar_t *Name;\r\n  const wchar_t *Ext;\r\n  const wchar_t *AddExt;\r\n  Byte ClassId;\r\n  Byte Signature[16];\r\n  int SignatureSize;\r\n  bool KeepName;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n};\r\n\r\nvoid RegisterArc(const CArcInfo *arcInfo);\r\n\r\n#define REGISTER_ARC_NAME(x) CRegister ## x\r\n\r\n#define REGISTER_ARC_DEC_SIG(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { g_ArcInfo.Signature[0]--; RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#define REGISTER_ARC(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/RegisterCodec.h",
    "content": "// RegisterCodec.h\r\n\r\n#ifndef __REGISTERCODEC_H\r\n#define __REGISTERCODEC_H\r\n\r\n#include \"../Common/MethodId.h\"\r\n\r\ntypedef void * (*CreateCodecP)();\r\nstruct CCodecInfo\r\n{\r\n  CreateCodecP CreateDecoder;\r\n  CreateCodecP CreateEncoder;\r\n  CMethodId Id;\r\n  const wchar_t *Name;\r\n  UInt32 NumInStreams;\r\n  bool IsFilter;\r\n};\r\n\r\nvoid RegisterCodec(const CCodecInfo *codecInfo);\r\n\r\n#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x\r\n\r\n#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \\\r\n    REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \\\r\n    static REGISTER_CODEC_NAME(x) g_RegisterCodec;\r\n\r\n#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x\r\n#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \\\r\n    REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \\\r\n    RegisterCodec(&g_CodecsInfo[i]); }}; \\\r\n    static REGISTER_CODECS_NAME(x) g_RegisterCodecs;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/StreamBinder.cpp",
    "content": "// StreamBinder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamBinder.h\"\r\n#include \"../../Common/Defs.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NSynchronization;\r\n\r\nclass CSequentialInStreamForBinder:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Read(data, size, processedSize); }\r\n\r\nclass CSequentialOutStreamForBinder:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialOutStreamForBinder() {  m_StreamBinder->CloseWrite(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Write(data, size, processedSize); }\r\n\r\n\r\n//////////////////////////\r\n// CStreamBinder\r\n// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.\r\n\r\nHRes CStreamBinder::CreateEvents()\r\n{\r\n  RINOK(_allBytesAreWritenEvent.Create(true));\r\n  RINOK(_thereAreBytesToReadEvent.Create());\r\n  return _readStreamIsClosedEvent.Create();\r\n}\r\n\r\nvoid CStreamBinder::ReInit()\r\n{\r\n  _thereAreBytesToReadEvent.Reset();\r\n  _readStreamIsClosedEvent.Reset();\r\n  ProcessedSize = 0;\r\n}\r\n\r\n\r\n  \r\nvoid CStreamBinder::CreateStreams(ISequentialInStream **inStream,\r\n      ISequentialOutStream **outStream)\r\n{\r\n  CSequentialInStreamForBinder *inStreamSpec = new\r\n      CSequentialInStreamForBinder;\r\n  CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n  inStreamSpec->SetBinder(this);\r\n  *inStream = inStreamLoc.Detach();\r\n\r\n  CSequentialOutStreamForBinder *outStreamSpec = new\r\n      CSequentialOutStreamForBinder;\r\n  CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);\r\n  outStreamSpec->SetBinder(this);\r\n  *outStream = outStreamLoc.Detach();\r\n\r\n  _buffer = NULL;\r\n  _bufferSize= 0;\r\n  ProcessedSize = 0;\r\n}\r\n\r\nHRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 sizeToRead = size;\r\n  if (size > 0)\r\n  {\r\n    RINOK(_thereAreBytesToReadEvent.Lock());\r\n    sizeToRead = MyMin(_bufferSize, size);\r\n    if (_bufferSize > 0)\r\n    {\r\n      memcpy(data, _buffer, sizeToRead);\r\n      _buffer = ((const Byte *)_buffer) + sizeToRead;\r\n      _bufferSize -= sizeToRead;\r\n      if (_bufferSize == 0)\r\n      {\r\n        _thereAreBytesToReadEvent.Reset();\r\n        _allBytesAreWritenEvent.Set();\r\n      }\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = sizeToRead;\r\n  ProcessedSize += sizeToRead;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseRead()\r\n{\r\n  _readStreamIsClosedEvent.Set();\r\n}\r\n\r\nHRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > 0)\r\n  {\r\n    _buffer = data;\r\n    _bufferSize = size;\r\n    _allBytesAreWritenEvent.Reset();\r\n    _thereAreBytesToReadEvent.Set();\r\n\r\n    HANDLE events[2];\r\n    events[0] = _allBytesAreWritenEvent;\r\n    events[1] = _readStreamIsClosedEvent;\r\n    DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);\r\n    if (waitResult != WAIT_OBJECT_0 + 0)\r\n    {\r\n      // ReadingWasClosed = true;\r\n      return S_FALSE;\r\n    }\r\n    // if(!_allBytesAreWritenEvent.Lock())\r\n    //   return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseWrite()\r\n{\r\n  // _bufferSize must be = 0\r\n  _thereAreBytesToReadEvent.Set();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/StreamBinder.h",
    "content": "// StreamBinder.h\r\n\r\n#ifndef __STREAMBINDER_H\r\n#define __STREAMBINDER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Windows/Synchronization.h\"\r\n\r\nclass CStreamBinder\r\n{\r\n  NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent;\r\n  UInt32 _bufferSize;\r\n  const void *_buffer;\r\npublic:\r\n  // bool ReadingWasClosed;\r\n  UInt64 ProcessedSize;\r\n  CStreamBinder() {}\r\n  HRes CreateEvents();\r\n\r\n  void CreateStreams(ISequentialInStream **inStream,\r\n      ISequentialOutStream **outStream);\r\n  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseRead();\r\n\r\n  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseWrite();\r\n  void ReInit();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/StreamObjects.cpp",
    "content": "// StreamObjects.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamObjects.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\n\r\nSTDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t rem = _size - _pos;\r\n  if (size < rem)\r\n    rem = (size_t)size;\r\n  memcpy(data, _dataPointer + _pos, rem);\r\n  _pos += rem;\r\n  if (processedSize != NULL)\r\n    *processedSize = (UInt32)rem;\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CWriteBuffer::Write(const void *data, size_t size)\r\n{\r\n  size_t newCapacity = _size + size;\r\n  _buffer.EnsureCapacity(newCapacity);\r\n  memcpy(_buffer + _size, data, size);\r\n  _size += size;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  _writeBuffer.Write(data, (size_t)size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t rem = _size - _pos;\r\n  if (size < rem)\r\n    rem = (size_t)size;\r\n  memcpy(_buffer + _pos, data, rem);\r\n  _pos += rem;\r\n  if (processedSize != NULL)\r\n    *processedSize = (UInt32)rem;\r\n  return (rem == size ? S_OK : E_FAIL);\r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/StreamObjects.h",
    "content": "// StreamObjects.h\r\n\r\n#ifndef __STREAMOBJECTS_H\r\n#define __STREAMOBJECTS_H\r\n\r\n#include \"../../Common/DynamicBuffer.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CSequentialInStreamImp:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *_dataPointer;\r\n  size_t _size;\r\n  size_t _pos;\r\n\r\npublic:\r\n  void Init(const Byte *dataPointer, size_t size)\r\n  {\r\n    _dataPointer = dataPointer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n\r\nclass CWriteBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _size;\r\npublic:\r\n  CWriteBuffer(): _size(0) {}\r\n  void Init() { _size = 0;  }\r\n  void Write(const void *data, size_t size);\r\n  size_t GetSize() const { return _size; }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _buffer; }\r\n};\r\n\r\nclass CSequentialOutStreamImp:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CWriteBuffer _writeBuffer;\r\npublic:\r\n  void Init() { _writeBuffer.Init(); }\r\n  size_t GetSize() const { return _writeBuffer.GetSize(); }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamImp2:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n\r\n  void Init(Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _pos = 0;\r\n    _size = size;\r\n  }\r\n\r\n  size_t GetPos() const { return _pos; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialInStreamSizeCount:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamSizeCount:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void Init() { _size = 0; }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBlockSize = ((UInt32)1 << 31);\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSize)\r\n{\r\n  size_t size = *processedSize;\r\n  *processedSize = 0;\r\n  while (size != 0)\r\n  {\r\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\r\n    UInt32 processedSizeLoc;\r\n    HRESULT res = stream->Read(data, curSize, &processedSizeLoc);\r\n    *processedSize += processedSizeLoc;\r\n    data = (void *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size)\r\n{\r\n  size_t processedSize = size;\r\n  RINOK(ReadStream(stream, data, &processedSize));\r\n  return (size == processedSize) ? S_OK : S_FALSE;\r\n}\r\n\r\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size)\r\n{\r\n  size_t processedSize = size;\r\n  RINOK(ReadStream(stream, data, &processedSize));\r\n  return (size == processedSize) ? S_OK : E_FAIL;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size != 0)\r\n  {\r\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\r\n    UInt32 processedSizeLoc;\r\n    HRESULT res = stream->Write(data, curSize, &processedSizeLoc);\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *size);\r\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size);\r\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/VirtThread.cpp",
    "content": "// VirtThread.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"VirtThread.h\"\r\n\r\nstatic THREAD_FUNC_DECL CoderThread(void *p)\r\n{\r\n  for (;;)\r\n  {\r\n    CVirtThread *t = (CVirtThread *)p;\r\n    t->StartEvent.Lock();\r\n    if (t->ExitEvent)\r\n      return 0;\r\n    t->Execute();\r\n    t->FinishedEvent.Set();\r\n  }\r\n}\r\n\r\nWRes CVirtThread::Create()\r\n{\r\n  RINOK(StartEvent.CreateIfNotCreated());\r\n  RINOK(FinishedEvent.CreateIfNotCreated());\r\n  StartEvent.Reset();\r\n  FinishedEvent.Reset();\r\n  ExitEvent = false;\r\n  if (Thread.IsCreated())\r\n    return S_OK;\r\n  return Thread.Create(CoderThread, this);\r\n}\r\n\r\nvoid CVirtThread::Start()\r\n{\r\n  ExitEvent = false;\r\n  StartEvent.Set();\r\n}\r\n\r\nCVirtThread::~CVirtThread()\r\n{\r\n  ExitEvent = true;\r\n  if (StartEvent.IsCreated())\r\n    StartEvent.Set();\r\n  Thread.Wait();\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Common/VirtThread.h",
    "content": "// VirtThread.h\r\n\r\n#ifndef __VIRTTHREAD_H\r\n#define __VIRTTHREAD_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Windows/Thread.h\"\r\n\r\nstruct CVirtThread\r\n{\r\n  NWindows::NSynchronization::CAutoResetEvent StartEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent FinishedEvent;\r\n  NWindows::CThread Thread;\r\n  bool ExitEvent;\r\n\r\n  ~CVirtThread();\r\n  WRes Create();\r\n  void Start();\r\n  void WaitFinish() { FinishedEvent.Lock(); }\r\n  virtual void Execute() = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/Bcj2Coder.cpp",
    "content": "// Bcj2Coder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"Bcj2Coder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\ninline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }\r\ninline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }\r\ninline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CEncoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CEncoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize = 0;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusEncoder[i].Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    for (;;)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it\r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        UInt32 index;\r\n        if (b == 0xE8)\r\n          index = prevByte;\r\n        else if (b == 0xE9)\r\n          index = 256;\r\n        else if (IsJcc(prevByte, b))\r\n          index = 257;\r\n        else\r\n        {\r\n          prevByte = b;\r\n          continue;\r\n        }\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (!IsJ(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src =\r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;\r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;\r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      unsigned index = GetIndex(prevByte, b);\r\n      if (convert)\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 1);\r\n        bufferPos += 5;\r\n        COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n        for (int i = 24; i >= 0; i -= 8)\r\n          s.WriteByte((Byte)(dest >> i));\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize =\r\n        _mainStream.GetProcessedSize() +\r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeEncoder.GetProcessedSize();\r\n      */\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusDecoder[i].Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  for (;;)\r\n  {\r\n    if (processedBytes >= (1 << 20) && progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize =\r\n        _mainInStream.GetProcessedSize() +\r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeDecoder.GetProcessedSize();\r\n      */\r\n      const UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    UInt32 i;\r\n    Byte b = 0;\r\n    const UInt32 kBurstSize = (1 << 18);\r\n    for (i = 0; i < kBurstSize; i++)\r\n    {\r\n      if (!_mainInStream.ReadByte(b))\r\n        return Flush();\r\n      _outStream.WriteByte(b);\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      prevByte = b;\r\n    }\r\n    processedBytes += i;\r\n    if (i == kBurstSize)\r\n      continue;\r\n    unsigned index = GetIndex(prevByte, b);\r\n    if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)\r\n    {\r\n      UInt32 src = 0;\r\n      CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n      for (int i = 0; i < 4; i++)\r\n      {\r\n        Byte b0;\r\n        if(!s.ReadByte(b0))\r\n          return S_FALSE;\r\n        src <<= 8;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (Byte)(dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const CInBufferException &e) { return e.ErrorCode; }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/Bcj2Coder.h",
    "content": "// Bcj2Coder.h\r\n\r\n#ifndef __COMPRESS_BCJ2_CODER_H\r\n#define __COMPRESS_BCJ2_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CEncoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CEncoder(): _buffer(0) {};\r\n  ~CEncoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n};\r\n\r\n#endif\r\n\r\nclass CDecoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CDecoder *_coder;\r\n  public:\r\n    CCoderReleaser(CDecoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/Bcj2Register.cpp",
    "content": "// Bcj2Register.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"Bcj2Coder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x0303011B, L\"BCJ2\", 4, false };\r\n\r\nREGISTER_CODEC(BCJ2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/BcjCoder.cpp",
    "content": "// BcjCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"BcjCoder.h\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/BcjCoder.h",
    "content": "// BcjCoder.h\r\n\r\n#ifndef __COMPRESS_BCJ_CODER_H\r\n#define __COMPRESS_BCJ_CODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Bra.h\"\r\n}\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  void x86Init() { x86_Convert_Init(_prevMask); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 ,\r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/BcjRegister.cpp",
    "content": "// BcjRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"BcjCoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x03030103, L\"BCJ\", 1, true };\r\n\r\nREGISTER_CODEC(BCJ)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __COMPRESS_BRANCH_CODER_H\r\n#define __COMPRESS_BRANCH_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/BranchMisc.cpp",
    "content": "// BranchMisc.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Bra.h\"\r\n}\r\n\r\n#include \"BranchMisc.h\"\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  {  return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); }\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/BranchMisc.h",
    "content": "// BranchMisc.h\r\n\r\n#ifndef __COMPRESS_BRANCH_MISC_H\r\n#define __COMPRESS_BRANCH_MISC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM,   0x05, 1)\r\nMyClassA(BC_ARMT,  0x07, 1)\r\nMyClassA(BC_PPC,   0x02, 5)\r\nMyClassA(BC_SPARC, 0x08, 5)\r\nMyClassA(BC_IA64,  0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/BranchRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"BranchMisc.h\"\r\n\r\n#define CREATE_CODEC(x) \\\r\n  static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \\\r\n  static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }\r\n\r\nCREATE_CODEC(BC_PPC)\r\nCREATE_CODEC(BC_IA64)\r\nCREATE_CODEC(BC_ARM)\r\nCREATE_CODEC(BC_ARMT)\r\nCREATE_CODEC(BC_SPARC)\r\n\r\n#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true  }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  METHOD_ITEM(BC_PPC,   0x02, 0x05, L\"PPC\"),\r\n  METHOD_ITEM(BC_IA64,  0x04, 1, L\"IA64\"),\r\n  METHOD_ITEM(BC_ARM,   0x05, 1, L\"ARM\"),\r\n  METHOD_ITEM(BC_ARMT,  0x07, 1, L\"ARMT\"),\r\n  METHOD_ITEM(BC_SPARC, 0x08, 0x05, L\"SPARC\")\r\n};\r\n\r\nREGISTER_CODECS(Branch)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/ByteSwap.cpp",
    "content": "// ByteSwap.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nSTDMETHODIMP CByteSwap2::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 2;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b = data[i];\r\n    data[i] = data[i + 1];\r\n    data[i + 1] = b;\r\n  }\r\n  return i;\r\n}\r\n\r\nSTDMETHODIMP CByteSwap4::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 4;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b0 = data[i];\r\n    Byte b1 = data[i + 1];\r\n    data[i] = data[i + 3];\r\n    data[i + 1] = data[i + 2];\r\n    data[i + 2] = b1;\r\n    data[i + 3] = b0;\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/ByteSwap.h",
    "content": "// ByteSwap.h\r\n\r\n#ifndef __COMPRESS_BYTE_SWAP_H\r\n#define __COMPRESS_BYTE_SWAP_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nclass CByteSwap2:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\nclass CByteSwap4:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/ByteSwapRegister.cpp",
    "content": "// ByteSwapRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nstatic void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }\r\nstatic void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  { CreateCodec2, CreateCodec4, 0x020302, L\"Swap2\", 1, true },\r\n  { CreateCodec4, CreateCodec4, 0x020304, L\"Swap4\", 1, true }\r\n};\r\n\r\nREGISTER_CODECS(ByteSwap)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/CodecExports.cpp",
    "content": "// CodecExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterCodec.h\"\r\n#include \"../ICoder.h\"\r\n\r\nextern unsigned int g_NumCodecs;\r\nextern const CCodecInfo *g_Codecs[];\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec,\r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nstatic HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)\r\n{\r\n  GUID clsId = CLSID_CCodec;\r\n  for (int i = 0; i < sizeof(id); i++, id >>= 8)\r\n    clsId.Data4[i] = (Byte)(id & 0xFF);\r\n  if (encode)\r\n    clsId.Data3++;\r\n  return SetPropGUID(clsId, value);\r\n}\r\n\r\nstatic HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)\r\n{\r\n  index = -1;\r\n  if (clsID->Data1 != CLSID_CCodec.Data1 ||\r\n      clsID->Data2 != CLSID_CCodec.Data2 ||\r\n      (clsID->Data3 & ~1) != kDecodeId)\r\n    return S_OK;\r\n  encode = (clsID->Data3 != kDecodeId);\r\n  UInt64 id = 0;\r\n  for (int j = 0; j < 8; j++)\r\n    id |= ((UInt64)clsID->Data4[j]) << (8 * j);\r\n  for (unsigned i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)\r\n      continue;\r\n    if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n        codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n      return E_NOINTERFACE;\r\n    index = i;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  const CCodecInfo &codec = *g_Codecs[index];\r\n  if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n      codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n    return E_NOINTERFACE;\r\n  if (encode)\r\n  {\r\n    if (!codec.CreateEncoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateEncoder();\r\n  }\r\n  else\r\n  {\r\n    if (!codec.CreateDecoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateDecoder();\r\n  }\r\n  if (isCoder)\r\n    ((ICompressCoder *)*outObject)->AddRef();\r\n  else if (isCoder2)\r\n    ((ICompressCoder2 *)*outObject)->AddRef();\r\n  else\r\n    ((ICompressFilter *)*outObject)->AddRef();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  if (!isCoder && !isCoder2 && !isFilter)\r\n    return E_NOINTERFACE;\r\n  bool encode;\r\n  int codecIndex;\r\n  HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);\r\n  if (res != S_OK)\r\n    return res;\r\n  if (codecIndex < 0)\r\n    return CLASS_E_CLASSNOTAVAILABLE;\r\n  return CreateCoder2(encode, codecIndex, iid, outObject);\r\n}\r\n\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  ::VariantClear((VARIANTARG *)value);\r\n  const CCodecInfo &codec = *g_Codecs[codecIndex];\r\n  switch(propID)\r\n  {\r\n    case NMethodPropID::kID:\r\n    {\r\n      value->uhVal.QuadPart = (UInt64)codec.Id;\r\n      value->vt = VT_UI8;\r\n      break;\r\n    }\r\n    case NMethodPropID::kName:\r\n      if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)\r\n        value->vt = VT_BSTR;\r\n      break;\r\n    case NMethodPropID::kDecoder:\r\n      if (codec.CreateDecoder)\r\n        return SetClassID(codec.Id, false, value);\r\n      break;\r\n    case NMethodPropID::kEncoder:\r\n      if (codec.CreateEncoder)\r\n        return SetClassID(codec.Id, true, value);\r\n      break;\r\n    case NMethodPropID::kInStreams:\r\n    {\r\n      if (codec.NumInStreams != 1)\r\n      {\r\n        value->vt = VT_UI4;\r\n        value->ulVal = (ULONG)codec.NumInStreams;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetNumberOfMethods(UINT32 *numCodecs)\r\n{\r\n  *numCodecs = g_NumCodecs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/CopyCoder.cpp",
    "content": "// Compress/CopyCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"CopyCoder.h\"\r\n\r\nnamespace NCompress {\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCCopyCoder::~CCopyCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  TotalSize = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 realProcessedSize;\r\n    UInt32 size = kBufferSize;\r\n    if (outSize != 0)\r\n      if (size > *outSize - TotalSize)\r\n        size = (UInt32)(*outSize - TotalSize);\r\n    RINOK(inStream->Read(_buffer, size, &realProcessedSize));\r\n    if (realProcessedSize == 0)\r\n      break;\r\n    RINOK(WriteStream(outStream, _buffer, realProcessedSize));\r\n    TotalSize += realProcessedSize;\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = TotalSize;\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/CopyCoder.h",
    "content": "// Compress/CopyCoder.h\r\n\r\n#ifndef __COMPRESS_COPY_CODER_H\r\n#define __COMPRESS_COPY_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\n\r\nclass CCopyCoder:\r\n  public ICompressCoder,\r\n  public ICompressGetInStreamProcessedSize,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  UInt64 TotalSize;\r\n  CCopyCoder(): TotalSize(0) , _buffer(0) {};\r\n  ~CCopyCoder();\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/CopyRegister.cpp",
    "content": "// CopyRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"CopyCoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n{ CreateCodec, CreateCodec, 0x00, L\"Copy\", 1, false };\r\n\r\nREGISTER_CODEC(Copy)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /FAcs /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEncoder.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LzmaUtil\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LzmaDecoder.h\"\r\n#include \"../LzmaEncoder.h\"\r\n\r\n#include \"LzmaBenchCon.h\"\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/7zVersion.h\"\r\n  #include \"../../../../C/Alloc.h\"\r\n  #include \"../../../../C/LzmaUtil/Lzma86Dec.h\"\r\n  #include \"../../../../C/LzmaUtil/Lzma86Enc.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kAlgo,\r\n  kDict,\r\n  kFb,\r\n  kMc,\r\n  kLc,\r\n  kLp,\r\n  kPb,\r\n  kMatchFinder,\r\n  kMultiThread,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] =\r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MT\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kPostChar, false, 0, 0, L\"+\" }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\"\r\n    \"  -d{N}:  set dictionary size - [12, 30], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -mc{N}: set number of cycles for match finder\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\\n\"\r\n    \"  -mt{N}: set number of CPU threads\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[],\r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nstatic void ParseUInt32(const CParser &parser, int index, UInt32 &res)\r\n{\r\n  if (parser[index].ThereIs)\r\n    if (!GetNumber(parser[index].PostStrings[0], res))\r\n      IncorrectCommand();\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);\r\n  if (unsupportedTypes)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }\r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...)\r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++];\r\n\r\n  bool dictDefined = false;\r\n  UInt32 dict = (UInt32)-1;\r\n  if(parser[NKey::kDict].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDict].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dict = 1 << dicLog;\r\n    dictDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  UInt32 numThreads = (UInt32)-1;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (parser[NKey::kMultiThread].ThereIs)\r\n  {\r\n    UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n    const UString &s = parser[NKey::kMultiThread].PostStrings[0];\r\n    if (s.IsEmpty())\r\n      numThreads = numCPUs;\r\n    else\r\n      if (!GetNumber(s, numThreads))\r\n        IncorrectCommand();\r\n  }\r\n  #endif\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 1;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchCon(stderr, numIterations, numThreads, dict);\r\n  }\r\n\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = 1;\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++];\r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\",\r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  COutFileStream *outStreamSpec = NULL;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++];\r\n    outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\",\r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    size_t inSize = (size_t)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize);\r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    if (ReadStream_FAIL(inStream, inBuffer, inSize) != S_OK)\r\n      throw \"Can not read\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSize;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize);\r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictDefined)\r\n        dict = 1 << 23;\r\n      int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,\r\n          5, dict, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      UInt64 outSize64;\r\n      if (Lzma86_GetUnpackSize(inBuffer, inSize, &outSize64) != 0)\r\n        throw \"data error\";\r\n      outSize = (size_t)outSize64;\r\n      if (outSize != outSize64)\r\n        throw \"too big\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize);\r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = Lzma86_Decode(outBuffer, &outSize, inBuffer, &inSize);\r\n      if (inSize != (size_t)fileSize)\r\n        throw \"incorrect processed size\";\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, outSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLzma::CEncoder *encoderSpec = new NCompress::NLzma::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictDefined)\r\n      dict = 1 << 23;\r\n\r\n    UInt32 pb = 2;\r\n    UInt32 lc = 3; // = 0; for 32-bit data\r\n    UInt32 lp = 0; // = 2; for 32-bit data\r\n    UInt32 algo = 1;\r\n    UInt32 fb = 128;\r\n    UInt32 mc = 16 + fb / 2;\r\n    bool mcDefined = false;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    ParseUInt32(parser, NKey::kAlgo, algo);\r\n    ParseUInt32(parser, NKey::kFb, fb);\r\n    ParseUInt32(parser, NKey::kLc, lc);\r\n    ParseUInt32(parser, NKey::kLp, lp);\r\n    ParseUInt32(parser, NKey::kPb, pb);\r\n\r\n    mcDefined = parser[NKey::kMc].ThereIs;\r\n    if (mcDefined)\r\n      if (!GetNumber(parser[NKey::kMc].PostStrings[0], mc))\r\n        IncorrectCommand();\r\n    \r\n    PROPID propIDs[] =\r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker,\r\n      NCoderPropID::kNumThreads,\r\n      NCoderPropID::kMatchFinderCycles,\r\n    };\r\n    const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\r\n    PROPVARIANT props[kNumPropsMax];\r\n    for (int p = 0; p < 6; p++)\r\n      props[p].vt = VT_UI4;\r\n\r\n    props[0].ulVal = (UInt32)dict;\r\n    props[1].ulVal = (UInt32)pb;\r\n    props[2].ulVal = (UInt32)lc;\r\n    props[3].ulVal = (UInt32)lp;\r\n    props[4].ulVal = (UInt32)algo;\r\n    props[5].ulVal = (UInt32)fb;\r\n\r\n    props[6].vt = VT_BSTR;\r\n    props[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    props[7].vt = VT_BOOL;\r\n    props[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    props[8].vt = VT_UI4;\r\n    props[8].ulVal = (UInt32)numThreads;\r\n\r\n    // it must be last in property list\r\n    props[9].vt = VT_UI4;\r\n    props[9].ulVal = (UInt32)mc;\r\n\r\n    int numProps = kNumPropsMax;\r\n    if (!mcDefined)\r\n      numProps--;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, props, numProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }\r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NCompress::NLzma::CDecoder *decoderSpec = new NCompress::NLzma::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    decoderSpec->FinishStream = true;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte header[kPropertiesSize + 8];\r\n    if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(header, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n      fileSize |= ((UInt64)header[kPropertiesSize + i]) << (8 * i);\r\n\r\n    if (decoder->Code(inStream, outStream, 0, (fileSize == (UInt64)(Int64)-1) ? 0 : &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }\r\n  }\r\n  if (outStreamSpec != NULL)\r\n  {\r\n    if (outStreamSpec->Close() != S_OK)\r\n    {\r\n      fprintf(stderr, \"File closing error\");\r\n      return 1;\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n\r\nint MY_CDECL main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s)\r\n  {\r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1;\r\n  }\r\n  catch(...)\r\n  {\r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#define USE_POSIX_TIME\r\n#define USE_POSIX_TIME2\r\n#endif\r\n\r\n#ifdef USE_POSIX_TIME\r\n#include <time.h>\r\n#ifdef USE_POSIX_TIME2\r\n#include <sys/time.h>\r\n#endif\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n\r\n#ifdef BENCH_MT\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Windows/Thread.h\"\r\n#endif\r\n\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../ICoder.h\"\r\n#else\r\n#include \"../LzmaDecoder.h\"\r\n#include \"../LzmaEncoder.h\"\r\n#endif\r\n\r\nstatic const UInt32 kUncompressMinBlockSize = 1 << 26;\r\nstatic const UInt32 kAdditionalSize = (1 << 16);\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 5;\r\n\r\nclass CBaseRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CBaseRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd()\r\n  {\r\n    return\r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBenchBuffer\r\n{\r\npublic:\r\n  size_t BufferSize;\r\n  Byte *Buffer;\r\n  CBenchBuffer(): Buffer(0) {}\r\n  virtual ~CBenchBuffer() { Free(); }\r\n  void Free()\r\n  {\r\n    ::MidFree(Buffer);\r\n    Buffer = 0;\r\n  }\r\n  bool Alloc(size_t bufferSize)\r\n  {\r\n    if (Buffer != 0 && BufferSize == bufferSize)\r\n      return true;\r\n    Free();\r\n    Buffer = (Byte *)::MidAlloc(bufferSize);\r\n    BufferSize = bufferSize;\r\n    return (Buffer != 0);\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator: public CBenchBuffer\r\n{\r\n  CBaseRandomGenerator *RG;\r\npublic:\r\n  void Set(CBaseRandomGenerator *rg) { RG = rg; }\r\n  UInt32 GetVal(UInt32 &res, int numBits)\r\n  {\r\n    UInt32 val = res & (((UInt32)1 << numBits) - 1);\r\n    res >>= numBits;\r\n    return val;\r\n  }\r\n  UInt32 GetLen(UInt32 &res)\r\n  {\r\n    UInt32 len = GetVal(res, 2);\r\n    return GetVal(res, 1 + len);\r\n  }\r\n  void Generate()\r\n  {\r\n    UInt32 pos = 0;\r\n    UInt32 rep0 = 1;\r\n    while (pos < BufferSize)\r\n    {\r\n      UInt32 res = RG->GetRnd();\r\n      res >>= 1;\r\n      if (GetVal(res, 1) == 0 || pos < 1024)\r\n        Buffer[pos++] = (Byte)(res & 0xFF);\r\n      else\r\n      {\r\n        UInt32 len;\r\n        len = 1 + GetLen(res);\r\n        if (GetVal(res, 3) != 0)\r\n        {\r\n          len += GetLen(res);\r\n          do\r\n          {\r\n            UInt32 ppp = GetVal(res, 5) + 6;\r\n            res = RG->GetRnd();\r\n            if (ppp > 30)\r\n              continue;\r\n            rep0 = /* (1 << ppp) +*/  GetVal(res, ppp);\r\n            res = RG->GetRnd();\r\n          }\r\n          while (rep0 >= pos);\r\n          rep0++;\r\n        }\r\n\r\n        for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)\r\n          Buffer[pos] = Buffer[pos - rep0];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\n\r\nclass CBenchmarkInStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Pos;\r\n  size_t Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t remain = Size - Pos;\r\n  UInt32 kMaxBlockSize = (1 << 20);\r\n  if (size > kMaxBlockSize)\r\n    size = kMaxBlockSize;\r\n  if (size > remain)\r\n    size = (UInt32)remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream:\r\n  public ISequentialOutStream,\r\n  public CBenchBuffer,\r\n  public CMyUnknownImp\r\n{\r\n  // bool _overflow;\r\npublic:\r\n  UInt32 Pos;\r\n  // CBenchmarkOutStream(): _overflow(false) {}\r\n  void Init()\r\n  {\r\n    // _overflow = false;\r\n    Pos = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t curSize = BufferSize - Pos;\r\n  if (curSize > size)\r\n    curSize = size;\r\n  memcpy(Buffer + Pos, data, curSize);\r\n  Pos += (UInt32)curSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)curSize;\r\n  if (curSize != size)\r\n  {\r\n    // _overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  UInt32 Crc;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { Crc = CRC_INIT_VAL; }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  Crc = CrcUpdate(Crc, data, size);\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  timeval v;\r\n  if (gettimeofday(&v, 0) == 0)\r\n    return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;\r\n  return (UInt64)time(NULL) * 1000000;\r\n  #else\r\n  return time(NULL);\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return GetTickCount();\r\n  #endif\r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  return 1000000;\r\n  #else\r\n  return 1;\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return 1000;\r\n  #endif\r\n}\r\n\r\n#ifndef USE_POSIX_TIME\r\nstatic inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }\r\n#endif\r\nstatic UInt64 GetUserTime()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return clock();\r\n  #else\r\n  FILETIME creationTime, exitTime, kernelTime, userTime;\r\n  if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)\r\n    return GetTime64(userTime) + GetTime64(kernelTime);\r\n  return (UInt64)GetTickCount() * 10000;\r\n  #endif\r\n}\r\n\r\nstatic UInt64 GetUserFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return CLOCKS_PER_SEC;\r\n  #else\r\n  return 10000000;\r\n  #endif\r\n}\r\n\r\nclass CBenchProgressStatus\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::NSynchronization::CCriticalSection CS;\r\n  #endif\r\npublic:\r\n  HRESULT Res;\r\n  bool EncodeMode;\r\n  void SetResult(HRESULT res)\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    Res = res;\r\n  }\r\n  HRESULT GetResult()\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    return Res;\r\n  }\r\n};\r\n\r\nclass CBenchProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CBenchProgressStatus *Status;\r\n  CBenchInfo BenchInfo;\r\n  HRESULT Res;\r\n  IBenchCallback *callback;\r\n  CBenchProgressInfo(): callback(0) {}\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nvoid SetStartTime(CBenchInfo &bi)\r\n{\r\n  bi.GlobalFreq = GetFreq();\r\n  bi.UserFreq = GetUserFreq();\r\n  bi.GlobalTime = ::GetTimeCount();\r\n  bi.UserTime = ::GetUserTime();\r\n}\r\n\r\nvoid SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)\r\n{\r\n  dest.GlobalFreq = GetFreq();\r\n  dest.UserFreq = GetUserFreq();\r\n  dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;\r\n  dest.UserTime = ::GetUserTime() - biStart.UserTime;\r\n}\r\n\r\nSTDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  HRESULT res = Status->GetResult();\r\n  if (res != S_OK)\r\n    return res;\r\n  if (!callback)\r\n    return res;\r\n  CBenchInfo info = BenchInfo;\r\n  SetFinishTime(BenchInfo, info);\r\n  if (Status->EncodeMode)\r\n  {\r\n    info.UnpackSize = *inSize;\r\n    info.PackSize = *outSize;\r\n    res = callback->SetEncodeResult(info, false);\r\n  }\r\n  else\r\n  {\r\n    info.PackSize = BenchInfo.PackSize + *inSize;\r\n    info.UnpackSize = BenchInfo.UnpackSize + *outSize;\r\n    res = callback->SetDecodeResult(info, false);\r\n  }\r\n  if (res != S_OK)\r\n    Status->SetResult(res);\r\n  return res;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nUInt64 GetUsage(const CBenchInfo &info)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userTime, userFreq);\r\n  NormalizeVals(globalFreq, globalTime);\r\n  if (userFreq == 0)\r\n    userFreq = 1;\r\n  if (globalTime == 0)\r\n    globalTime = 1;\r\n  return userTime * globalFreq * 1000000 / userFreq / globalTime;\r\n}\r\n\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userFreq, userTime);\r\n  NormalizeVals(globalTime, globalFreq);\r\n  if (globalFreq == 0)\r\n    globalFreq = 1;\r\n  if (userTime == 0)\r\n    userTime = 1;\r\n  return userFreq * globalTime / globalFreq *  rating / userTime;\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)\r\n{\r\n  UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);\r\n  UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits));\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)\r\n{\r\n  UInt64 numCommands = (inSize * 200 + outSize * 4) * numIterations;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\n#ifdef EXTERNAL_LZMA\r\ntypedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID,\r\n    const GUID *interfaceID, void **outObject);\r\n#endif\r\n\r\nstruct CEncoderInfo;\r\n\r\nstruct CEncoderInfo\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::CThread thread[2];\r\n  #endif\r\n  CMyComPtr<ICompressCoder> encoder;\r\n  CBenchProgressInfo *progressInfoSpec[2];\r\n  CMyComPtr<ICompressProgressInfo> progressInfo[2];\r\n  UInt32 NumIterations;\r\n  #ifdef USE_ALLOCA\r\n  size_t AllocaSize;\r\n  #endif\r\n\r\n  struct CDecoderInfo\r\n  {\r\n    CEncoderInfo *Encoder;\r\n    UInt32 DecoderIndex;\r\n    #ifdef USE_ALLOCA\r\n    size_t AllocaSize;\r\n    #endif\r\n    bool CallbackMode;\r\n  };\r\n  CDecoderInfo decodersInfo[2];\r\n\r\n  CMyComPtr<ICompressCoder> decoders[2];\r\n  HRESULT Results[2];\r\n  CBenchmarkOutStream *outStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  IBenchCallback *callback;\r\n  UInt32 crc;\r\n  UInt32 kBufferSize;\r\n  UInt32 compressedSize;\r\n  CBenchRandomGenerator rg;\r\n  CBenchmarkOutStream *propStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> propStream;\r\n  HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);\r\n  HRESULT Encode();\r\n  HRESULT Decode(UInt32 decoderIndex);\r\n\r\n  CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}\r\n\r\n  #ifdef BENCH_MT\r\n  static THREAD_FUNC_DECL EncodeThreadFunction(void *param)\r\n  {\r\n    CEncoderInfo *encoder = (CEncoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(encoder->AllocaSize);\r\n    #endif\r\n    HRESULT res = encoder->Encode();\r\n    encoder->Results[0] = res;\r\n    if (res != S_OK)\r\n      encoder->progressInfoSpec[0]->Status->SetResult(res);\r\n\r\n    return 0;\r\n  }\r\n  static THREAD_FUNC_DECL DecodeThreadFunction(void *param)\r\n  {\r\n    CDecoderInfo *decoder = (CDecoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(decoder->AllocaSize);\r\n    #endif\r\n    CEncoderInfo *encoder = decoder->Encoder;\r\n    encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);\r\n    return 0;\r\n  }\r\n\r\n  HRESULT CreateEncoderThread()\r\n  {\r\n    return thread[0].Create(EncodeThreadFunction, this);\r\n  }\r\n\r\n  HRESULT CreateDecoderThread(int index, bool callbackMode\r\n      #ifdef USE_ALLOCA\r\n      , size_t allocaSize\r\n      #endif\r\n      )\r\n  {\r\n    CDecoderInfo &decoder = decodersInfo[index];\r\n    decoder.DecoderIndex = index;\r\n    decoder.Encoder = this;\r\n    #ifdef USE_ALLOCA\r\n    decoder.AllocaSize = allocaSize;\r\n    #endif\r\n    decoder.CallbackMode = callbackMode;\r\n    return thread[index].Create(DecodeThreadFunction, &decoder);\r\n  }\r\n  #endif\r\n};\r\n\r\nHRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)\r\n{\r\n  rg.Set(rgLoc);\r\n  kBufferSize = dictionarySize + kAdditionalSize;\r\n  UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n  if (!rg.Alloc(kBufferSize))\r\n    return E_OUTOFMEMORY;\r\n  rg.Generate();\r\n  crc = CrcCalc(rg.Buffer, rg.BufferSize);\r\n\r\n  outStreamSpec = new CBenchmarkOutStream;\r\n  if (!outStreamSpec->Alloc(kCompressedBufferSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  outStream = outStreamSpec;\r\n\r\n  propStreamSpec = 0;\r\n  if (!propStream)\r\n  {\r\n    propStreamSpec = new CBenchmarkOutStream;\r\n    propStream = propStreamSpec;\r\n  }\r\n  if (!propStreamSpec->Alloc(kMaxLzmaPropSize))\r\n    return E_OUTOFMEMORY;\r\n  propStreamSpec->Init();\r\n  \r\n  PROPID propIDs[] =\r\n  {\r\n    NCoderPropID::kDictionarySize,\r\n    NCoderPropID::kMultiThread\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)dictionarySize;\r\n\r\n  properties[1].vt = VT_BOOL;\r\n  properties[1].boolVal = (numThreads > 1) ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n  {\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));\r\n    if (!setCoderProperties)\r\n      return E_FAIL;\r\n    RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, kNumProps));\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);\r\n    if (writeCoderProperties)\r\n    {\r\n      RINOK(writeCoderProperties->WriteCoderProperties(propStream));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Encode()\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n  outStreamSpec->Init();\r\n\r\n  RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));\r\n  compressedSize = outStreamSpec->Pos;\r\n  encoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Decode(UInt32 decoderIndex)\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];\r\n\r\n  CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;\r\n  decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);\r\n  if (!compressSetDecoderProperties)\r\n    return E_FAIL;\r\n\r\n  CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n  CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n  CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];\r\n  pi->BenchInfo.UnpackSize = 0;\r\n  pi->BenchInfo.PackSize = 0;\r\n\r\n  for (UInt32 j = 0; j < NumIterations; j++)\r\n  {\r\n    inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n    crcOutStreamSpec->Init();\r\n    \r\n    RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));\r\n    UInt64 outSize = kBufferSize;\r\n    RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));\r\n    if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)\r\n      return S_FALSE;\r\n    pi->BenchInfo.UnpackSize += kBufferSize;\r\n    pi->BenchInfo.PackSize += compressedSize;\r\n  }\r\n  decoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nstatic const UInt32 kNumThreadsMax = (1 << 16);\r\n\r\nstruct CBenchEncoders\r\n{\r\n  CEncoderInfo *encoders;\r\n  CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }\r\n  ~CBenchEncoders() { delete []encoders; }\r\n};\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)\r\n{\r\n  UInt32 numEncoderThreads =\r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? numThreads / 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  UInt32 numSubDecoderThreads =\r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)\r\n  {\r\n    return E_INVALIDARG;\r\n  }\r\n\r\n  CBenchEncoders encodersSpec(numEncoderThreads);\r\n  CEncoderInfo *encoders = encodersSpec.encoders;\r\n\r\n  #ifdef EXTERNAL_LZMA\r\n  UString name = L\"LZMA\";\r\n  #endif\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.callback = (i == 0) ? callback : 0;\r\n\r\n    #ifdef EXTERNAL_LZMA\r\n    RINOK(codecs->CreateCoder(name, true, encoder.encoder));\r\n    #else\r\n    encoder.encoder = new NCompress::NLzma::CEncoder;\r\n    #endif\r\n    for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n    {\r\n      #ifdef EXTERNAL_LZMA\r\n      RINOK(codecs->CreateCoder(name, false, encoder.decoders[j]));\r\n      #else\r\n      encoder.decoders[j] = new NCompress::NLzma::CDecoder;\r\n      #endif\r\n    }\r\n  }\r\n\r\n  CBaseRandomGenerator rg;\r\n  rg.Init();\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));\r\n  }\r\n\r\n  CBenchProgressStatus status;\r\n  status.Res = S_OK;\r\n  status.EncodeMode = true;\r\n\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;\r\n      encoder.progressInfoSpec[j]->Status = &status;\r\n    }\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numEncoderThreads > 1)\r\n    {\r\n      #ifdef USE_ALLOCA\r\n      encoder.AllocaSize = (i * 16 * 21) & 0x7FF;\r\n      #endif\r\n      RINOK(encoder.CreateEncoderThread())\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Encode());\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  if (numEncoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      encoders[i].thread[0].Wait();\r\n  #endif\r\n\r\n  RINOK(status.Res);\r\n\r\n  CBenchInfo info;\r\n\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = 1; // progressInfoSpec->NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetEncodeResult(info, true));\r\n\r\n\r\n  status.Res = S_OK;\r\n  status.EncodeMode = false;\r\n\r\n  UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;\r\n\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numDecoderThreads > 1)\r\n    {\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)\r\n            #ifdef USE_ALLOCA\r\n            , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF\r\n            #endif\r\n            );\r\n        RINOK(res);\r\n      }\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Decode(0));\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  HRESULT res = S_OK;\r\n  if (numDecoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        CEncoderInfo &encoder = encoders[i];\r\n        encoder.thread[j].Wait();\r\n        if (encoder.Results[j] != S_OK)\r\n          res = encoder.Results[j];\r\n      }\r\n  RINOK(res);\r\n  #endif\r\n  RINOK(status.Res);\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetDecodeResult(info, false));\r\n  RINOK(callback->SetDecodeResult(info, true));\r\n  return S_OK;\r\n}\r\n\r\n\r\ninline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)\r\n{\r\n  UInt32 hs = dictionary - 1;\r\n  hs |= (hs >> 1);\r\n  hs |= (hs >> 2);\r\n  hs |= (hs >> 4);\r\n  hs |= (hs >> 8);\r\n  hs >>= 1;\r\n  hs |= 0xFFFF;\r\n  if (hs > (1 << 24))\r\n    hs >>= 1;\r\n  hs++;\r\n  return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +\r\n      (1 << 20) + (multiThread ? (6 << 20) : 0);\r\n}\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  const UInt32 kBufferSize = dictionary;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2);\r\n  UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;\r\n  UInt32 numBigThreads = numThreads / numSubThreads;\r\n  return (kBufferSize + kCompressedBufferSize +\r\n    GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;\r\n}\r\n\r\nstatic bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)\r\n{\r\n  for (UInt32 i = 0; i < numCycles; i++)\r\n    if (CrcCalc(data, size) != crcBase)\r\n      return false;\r\n  return true;\r\n}\r\n\r\n#ifdef BENCH_MT\r\nstruct CCrcInfo\r\n{\r\n  NWindows::CThread Thread;\r\n  const Byte *Data;\r\n  UInt32 Size;\r\n  UInt32 NumCycles;\r\n  UInt32 Crc;\r\n  bool Res;\r\n  void Wait()\r\n  {\r\n    Thread.Wait();\r\n    Thread.Close();\r\n  }\r\n};\r\n\r\nstatic THREAD_FUNC_DECL CrcThreadFunction(void *param)\r\n{\r\n  CCrcInfo *p = (CCrcInfo *)param;\r\n  p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);\r\n  return 0;\r\n}\r\n\r\nstruct CCrcThreads\r\n{\r\n  UInt32 NumThreads;\r\n  CCrcInfo *Items;\r\n  CCrcThreads(): Items(0), NumThreads(0) {}\r\n  void WaitAll()\r\n  {\r\n    for (UInt32 i = 0; i < NumThreads; i++)\r\n      Items[i].Wait();\r\n    NumThreads = 0;\r\n  }\r\n  ~CCrcThreads()\r\n  {\r\n    WaitAll();\r\n    delete []Items;\r\n  }\r\n};\r\n#endif\r\n\r\nstatic UInt32 CrcCalc1(const Byte *buf, UInt32 size)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    crc = CRC_UPDATE_BYTE(crc, buf[i]);\r\n  return CRC_GET_DIGEST(crc);\r\n}\r\n\r\nstatic void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  for (UInt32 i = 0; i < size; i++)\r\n    buf[i] = (Byte)RG.GetRnd();\r\n}\r\n\r\nstatic UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  RandGen(buf, size, RG);\r\n  return CrcCalc1(buf, size);\r\n}\r\n\r\nbool CrcInternalTest()\r\n{\r\n  CBenchBuffer buffer;\r\n  const UInt32 kBufferSize0 = (1 << 8);\r\n  const UInt32 kBufferSize1 = (1 << 10);\r\n  const UInt32 kCheckSize = (1 << 5);\r\n  if (!buffer.Alloc(kBufferSize0 + kBufferSize1))\r\n    return false;\r\n  Byte *buf = buffer.Buffer;\r\n  UInt32 i;\r\n  for (i = 0; i < kBufferSize0; i++)\r\n    buf[i] = (Byte)i;\r\n  UInt32 crc1 = CrcCalc1(buf, kBufferSize0);\r\n  if (crc1 != 0x29058C73)\r\n    return false;\r\n  CBaseRandomGenerator RG;\r\n  RandGen(buf + kBufferSize0, kBufferSize1, RG);\r\n  for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)\r\n    for (UInt32 j = 0; j < kCheckSize; j++)\r\n      if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))\r\n        return false;\r\n  return true;\r\n}\r\n\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)\r\n{\r\n  if (numThreads == 0)\r\n    numThreads = 1;\r\n\r\n  CBenchBuffer buffer;\r\n  size_t totalSize = (size_t)bufferSize * numThreads;\r\n  if (totalSize / numThreads != bufferSize)\r\n    return E_OUTOFMEMORY;\r\n  if (!buffer.Alloc(totalSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  Byte *buf = buffer.Buffer;\r\n  CBaseRandomGenerator RG;\r\n  UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;\r\n\r\n  UInt64 timeVal;\r\n  #ifdef BENCH_MT\r\n  CCrcThreads threads;\r\n  if (numThreads > 1)\r\n  {\r\n    threads.Items = new CCrcInfo[numThreads];\r\n    UInt32 i;\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      Byte *data = buf + (size_t)bufferSize * i;\r\n      info.Data = data;\r\n      info.NumCycles = numCycles;\r\n      info.Size = bufferSize;\r\n      info.Crc = RandGenCrc(data, bufferSize, RG);\r\n    }\r\n    timeVal = GetTimeCount();\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      RINOK(info.Thread.Create(CrcThreadFunction, &info));\r\n      threads.NumThreads++;\r\n    }\r\n    threads.WaitAll();\r\n    for (i = 0; i < numThreads; i++)\r\n      if (!threads.Items[i].Res)\r\n        return S_FALSE;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 crc = RandGenCrc(buf, bufferSize, RG);\r\n    timeVal = GetTimeCount();\r\n    if (!CrcBig(buf, bufferSize, numCycles, crc))\r\n      return S_FALSE;\r\n  }\r\n  timeVal = GetTimeCount() - timeVal;\r\n  if (timeVal == 0)\r\n    timeVal = 1;\r\n\r\n  UInt64 size = (UInt64)numCycles * totalSize;\r\n  speed = MyMultDiv64(size, timeVal, GetFreq());\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LZMABENCH_H\r\n#define __LZMABENCH_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\n\r\nstruct CBenchInfo\r\n{\r\n  UInt64 GlobalTime;\r\n  UInt64 GlobalFreq;\r\n  UInt64 UserTime;\r\n  UInt64 UserFreq;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt32 NumIterations;\r\n  CBenchInfo(): NumIterations(0) {}\r\n};\r\n\r\nstruct IBenchCallback\r\n{\r\n  virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;\r\n  virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;\r\n};\r\n\r\nUInt64 GetUsage(const CBenchInfo &benchOnfo);\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);\r\n\r\nconst int kBenchMinDicLogSize = 18;\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);\r\n\r\nbool CrcInternalTest();\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp",
    "content": "// LzmaBenchCon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaBenchCon.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#if defined(BENCH_MT) || defined(_WIN32)\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#ifdef BREAK_HANDLER\r\n#include \"../../UI/Console/ConsoleClose.h\"\r\n#endif\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nstruct CTotalBenchRes\r\n{\r\n  UInt64 NumIterations;\r\n  UInt64 Rating;\r\n  UInt64 Usage;\r\n  UInt64 RPU;\r\n  void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }\r\n  void Normalize()\r\n  {\r\n    if (NumIterations == 0)\r\n      return;\r\n    Rating /= NumIterations;\r\n    Usage /= NumIterations;\r\n    RPU /= NumIterations;\r\n    NumIterations = 1;\r\n  }\r\n  void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)\r\n  {\r\n    Rating = (r1.Rating + r2.Rating) / 2;\r\n    Usage = (r1.Usage + r2.Usage) / 2;\r\n    RPU = (r1.RPU + r2.RPU) / 2;\r\n    NumIterations = (r1.NumIterations + r2.NumIterations) / 2;\r\n  }\r\n};\r\n\r\nstruct CBenchCallback: public IBenchCallback\r\n{\r\n  CTotalBenchRes EncodeRes;\r\n  CTotalBenchRes DecodeRes;\r\n  FILE *f;\r\n  void Init() { EncodeRes.Init(); DecodeRes.Init(); }\r\n  void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }\r\n  UInt32 dictionarySize;\r\n  HRESULT SetEncodeResult(const CBenchInfo &info, bool final);\r\n  HRESULT SetDecodeResult(const CBenchInfo &info, bool final);\r\n};\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic void PrintNumber(FILE *f, UInt64 value, int size)\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(value, s);\r\n  fprintf(f, \" \");\r\n  for (int len = (int)strlen(s); len < size; len++)\r\n    fprintf(f, \" \");\r\n  fprintf(f, \"%s\", s);\r\n}\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  PrintNumber(f, rating / 1000000, 6);\r\n}\r\n\r\nstatic void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)\r\n{\r\n  PrintNumber(f, (usage + 5000) / 10000, 5);\r\n  PrintRating(f, rpu);\r\n  PrintRating(f, rating);\r\n}\r\n\r\n\r\nstatic void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)\r\n{\r\n  UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);\r\n  PrintNumber(f, speed / 1024, 7);\r\n  UInt64 usage = GetUsage(info);\r\n  UInt64 rpu = GetRatingPerUsage(info, rating);\r\n  PrintResults(f, usage, rpu, rating);\r\n  res.NumIterations++;\r\n  res.RPU += rpu;\r\n  res.Rating += rating;\r\n  res.Usage += usage;\r\n}\r\n\r\nstatic void PrintTotals(FILE *f, const CTotalBenchRes &res)\r\n{\r\n  fprintf(f, \"       \");\r\n  PrintResults(f, res.Usage, res.RPU, res.Rating);\r\n}\r\n\r\n\r\nHRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);\r\n    PrintResults(f, info, rating, EncodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const char *kSep = \"  | \";\r\n\r\n\r\nHRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);\r\n    fprintf(f, kSep);\r\n    CBenchInfo info2 = info;\r\n    info2.UnpackSize *= info2.NumIterations;\r\n    info2.PackSize *= info2.NumIterations;\r\n    info2.NumIterations = 1;\r\n    PrintResults(f, info2, rating, DecodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)\r\n{\r\n  fprintf(f, \"\\nRAM %s \", sizeString);\r\n  PrintNumber(f, (size >> 20), 5);\r\n  fprintf(f, \" MB,  # %s %3d\", threadsString, (unsigned int)numThreads);\r\n}\r\n\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();  //\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  if (numThreads > 1)\r\n    numThreads &= ~1;\r\n  if (dictionary == (UInt32)-1)\r\n  {\r\n    int dicSizeLog;\r\n    for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)\r\n      if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)\r\n        break;\r\n    dictionary = (1 << dicSizeLog);\r\n  }\r\n  #else\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 22);\r\n  numThreads = 1;\r\n  #endif\r\n\r\n  PrintRequirements(f, \"usage:\", GetBenchMemoryUsage(numThreads, dictionary), \"Benchmark threads:   \", numThreads);\r\n\r\n  CBenchCallback callback;\r\n  callback.Init();\r\n  callback.f = f;\r\n  \r\n  fprintf(f, \"\\n\\nDict        Compressing          |        Decompressing\\n   \");\r\n  int j;\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"   Speed Usage    R/U Rating\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n   \");\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"    KB/s     %%   MIPS   MIPS\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    const int kStartDicLog = 22;\r\n    int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;\r\n    while (((UInt32)1 << pow) > dictionary)\r\n      pow--;\r\n    for (; ((UInt32)1 << pow) <= dictionary; pow++)\r\n    {\r\n      fprintf(f, \"%2d:\", pow);\r\n      callback.dictionarySize = (UInt32)1 << pow;\r\n      HRESULT res = LzmaBench(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        numThreads, callback.dictionarySize, &callback);\r\n      fprintf(f, \"\\n\");\r\n      RINOK(res);\r\n    }\r\n  }\r\n  callback.Normalize();\r\n  fprintf(f, \"----------------------------------------------------------------\\nAvr:\");\r\n  PrintTotals(f, callback.EncodeRes);\r\n  fprintf(f, \"     \");\r\n  PrintTotals(f, callback.DecodeRes);\r\n  fprintf(f, \"\\nTot:\");\r\n  CTotalBenchRes midRes;\r\n  midRes.SetMid(callback.EncodeRes, callback.DecodeRes);\r\n  PrintTotals(f, midRes);\r\n  fprintf(f, \"\\n\");\r\n  return S_OK;\r\n}\r\n\r\nstruct CTempValues\r\n{\r\n  UInt64 *Values;\r\n  CTempValues(UInt32 num) { Values = new UInt64[num]; }\r\n  ~CTempValues() { delete []Values; }\r\n};\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  #else\r\n  numThreads = 1;\r\n  #endif\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 24);\r\n\r\n  CTempValues speedTotals(numThreads);\r\n  fprintf(f, \"\\n\\nSize\");\r\n  for (UInt32 ti = 0; ti < numThreads; ti++)\r\n  {\r\n    fprintf(f, \" %5d\", ti + 1);\r\n    speedTotals.Values[ti] = 0;\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n\r\n  UInt64 numSteps = 0;\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    for (int pow = 10; pow < 32; pow++)\r\n    {\r\n      UInt32 bufSize = (UInt32)1 << pow;\r\n      if (bufSize > dictionary)\r\n        break;\r\n      fprintf(f, \"%2d: \", pow);\r\n      UInt64 speed;\r\n      for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      {\r\n        #ifdef BREAK_HANDLER\r\n        if (NConsoleClose::TestBreakSignal())\r\n          return E_ABORT;\r\n        #endif\r\n        RINOK(CrcBench(ti + 1, bufSize, speed));\r\n        PrintNumber(f, (speed >> 20), 5);\r\n        speedTotals.Values[ti] += speed;\r\n      }\r\n      fprintf(f, \"\\n\");\r\n      numSteps++;\r\n    }\r\n  }\r\n  if (numSteps != 0)\r\n  {\r\n    fprintf(f, \"\\nAvg:\");\r\n    for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);\r\n    fprintf(f, \"\\n\");\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h",
    "content": "// LzmaBenchCon.h\r\n\r\n#ifndef __LZMABENCHCON_H\r\n#define __LZMABENCHCON_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/comp.cc",
    "content": "/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.txt.\n */\n\n/* $Id: comp.cc,v 1.29 2006/11/27 03:54:58 jro Exp $ */\n\n// extract some parts from lzma443/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <assert.h>\n#include <errno.h>\n\n#include \"StdAfx.h\"\n#include \"../../../Common/MyInitGuid.h\"\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/StringConvert.h\"\n#include \"../LzmaEncoder.h\"\n\n#include <pthread.h>\n#include <zlib.h>\n#include \"sqlzma.h\"\n\n//////////////////////////////////////////////////////////////////////\n\nclass CMemoryStream {\nprotected:\n\tBytef *m_data;\n\tUInt64 m_limit;\n\tUInt64 m_pos;\n\npublic:\n\tCMemoryStream(Bytef *data, UInt64 size)\n\t\t: m_data(data), m_limit(size), m_pos(0) {}\n\n\tvirtual ~CMemoryStream() {}\n};\n\nclass CInMemoryStream : public CMemoryStream, public IInStream,\n\t\t\tpublic CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialInStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IInStream);\n\n\tCInMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~CInMemoryStream() {}\n\n\tSTDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\n\t{\n\t\tUInt64 room = m_limit - m_pos;\n\t\tif (size > room)\n\t\t\tsize = room;\n\t\tif (size) {\n\t\t\tmemcpy(data, m_data + m_pos, size);\n\t\t\tm_pos += size;\n\t\t}\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\nclass COutMemoryStream : public CMemoryStream, public IOutStream,\n\t\t\t public CMyUnknownImp {\n//protected:\n\tCMyComPtr<ISequentialOutStream> m_stream;\n\npublic:\n\tMY_UNKNOWN_IMP1(IOutStream);\n\n\tCOutMemoryStream(Bytef *data, UInt64 size)\n\t\t: CMemoryStream(data, size), m_stream(this) {}\n\n\tvirtual ~COutMemoryStream() {}\n\n\tUInt32 GetSize() {return m_pos;}\n\n\tSTDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) {\n\t\tif (m_pos + size > m_limit)\n\t\t\treturn -ENOSPC;\n\t\tmemcpy(m_data + m_pos, data, size);\n\t\tm_pos += size;\n\t\tif (processedSize)\n\t\t\t*processedSize = size;\n\t\treturn S_OK;\n\t}\n\n\t// disabled all\n\tSTDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n\tSTDMETHOD(SetSize)(Int64 newSize) {\n\t\tassert(0);\n\t\treturn E_NOTIMPL;\n\t}\n};\n\n//////////////////////////////////////////////////////////////////////\n\nstatic int\nLzmaCompress(Bytef *next_in, uInt avail_in, Bytef *next_out, uInt avail_out,\n\t     struct sqlzma_opts *opts, uLong *total_out)\n{\n\tint err;\n\tHRESULT res;\n\tconst Byte a[] = {\n\t\tavail_in, avail_in >> 8, avail_in >> 16, avail_in >> 24,\n\t\t0, 0, 0, 0\n\t};\n\n\tNCompress::NLzma::CEncoder encoderSpec;\n\tCMyComPtr<ICompressCoder> encoder = &encoderSpec;\n\tencoder->AddRef();\n\tCInMemoryStream inStreamSpec(next_in, avail_in);\n\tCMyComPtr<ISequentialInStream> inStream = &inStreamSpec;\n\tinStream->AddRef();\n\tCOutMemoryStream outStreamSpec(next_out, avail_out);\n\tCMyComPtr<ISequentialOutStream> outStream = &outStreamSpec;\n\toutStream->AddRef();\n\n\t// these values are dpending upon is_lzma() macro in sqlzma.h\n\tconst UInt32 dictionary = opts->dicsize;\n\tconst UString mf = L\"BT4\";\n\tconst UInt32 posStateBits = 2;\n\tconst UInt32 litContextBits = 3; // for normal files\n\t// UInt32 litContextBits = 0; // for 32-bit data\n\tconst UInt32 litPosBits = 0;\n\t// UInt32 litPosBits = 2; // for 32-bit data\n\tconst UInt32 algorithm = 2;\n\tconst UInt32 numFastBytes = 128;\n\tconst UInt32 matchFinderCycles = 16 + numFastBytes / 2;\n\t//const bool matchFinderCyclesDefined = false;\n\tconst PROPID propIDs[] = {\n\t\tNCoderPropID::kDictionarySize,\n\t\tNCoderPropID::kPosStateBits,\n\t\tNCoderPropID::kLitContextBits,\n\t\tNCoderPropID::kLitPosBits,\n\t\tNCoderPropID::kAlgorithm,\n\t\tNCoderPropID::kNumFastBytes,\n\t\tNCoderPropID::kMatchFinder,\n\t\tNCoderPropID::kEndMarker,\n\t\tNCoderPropID::kMatchFinderCycles\n\t};\n\tconst int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\n\tPROPVARIANT properties[kNumPropsMax];\n\tfor (int p = 0; p < 6; p++)\n\t\tproperties[p].vt = VT_UI4;\n\tproperties[0].ulVal = UInt32(dictionary);\n\tproperties[1].ulVal = UInt32(posStateBits);\n\tproperties[2].ulVal = UInt32(litContextBits);\n\tproperties[3].ulVal = UInt32(litPosBits);\n\tproperties[4].ulVal = UInt32(algorithm);\n\tproperties[5].ulVal = UInt32(numFastBytes);\n\n\tproperties[6].vt = VT_BSTR;\n\tproperties[6].bstrVal = (BSTR)(const wchar_t *)mf;\n\tproperties[7].vt = VT_BOOL;\n\tproperties[7].boolVal = VARIANT_FALSE;\t// EOS\n\tproperties[8].vt = VT_UI4;\n\tproperties[8].ulVal = UInt32(matchFinderCycles);\n\n\terr = -EINVAL;\n\tres = encoderSpec.SetCoderProperties(propIDs, properties,\n\t\t\t\t\t     kNumPropsMax - 1);\n\tif (res)\n\t\tgoto out;\n\tres = encoderSpec.WriteCoderProperties(outStream);\n\tif (res)\n\t\tgoto out;\n\n\tUInt32 r;\n\tres = outStream->Write(a, sizeof(a), &r);\n\tif (res || r != sizeof(a))\n\t\tgoto out;\n\n\terr = encoder->Code(inStream, outStream, 0, /*broken*/0, 0);\n\tif (err)\n\t\tgoto out;\n\t*total_out = outStreamSpec.GetSize();\n\n out:\n\treturn err;\n}\n\n//////////////////////////////////////////////////////////////////////\n\n#define Failure(p) do { \\\n\tfprintf(stderr, \"%s:%d: please report to jro \" \\\n\t\t\"{%02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x}\\n\", \\\n\t\t__func__, __LINE__, \\\n\t\tp[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); \\\n\tabort(); \\\n}while(0)\n\nextern \"C\" int\nsqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in,\n\t  uInt avail_in, Bytef *next_out, uInt avail_out)\n{\n\tint err;\n\tBytef *p = next_out;\n\tuInt l = avail_out;\n\n\tstream->next_in = next_in;\n\tstream->avail_in = avail_in;\n\tstream->next_out = p;\n\tstream->avail_out = l;\n\terr = deflate(stream, Z_FINISH);\n\tif (err != Z_STREAM_END && err != Z_OK)\n\t\tgoto out_err;\n\tif (avail_in < stream->total_out)\n\t\treturn err;\n\tif (is_lzma(*p))\n\t\tFailure(p);\n\n\tif (opts->try_lzma) {\n\t\tunsigned char a[stream->total_out];\n\t\tuLong processed;\n\n\t\tmemcpy(a, p, stream->total_out);\n\n\t\t// malloc family in glibc and stdc++ seems to be thread-safe\n\t\terr = LzmaCompress(next_in, avail_in, p, l, opts, &processed);\n\t\tif (!err && processed <= stream->total_out) {\n\t\t\tif (!is_lzma(*next_out))\n\t\t\t\tFailure(next_out);\n\t\t\tstream->total_out = processed;\n\t\t\terr = Z_STREAM_END;\n\t\t} else {\n\t\t\t//puts(\"by zlib\");\n\t\t\tmemcpy(p, a, stream->total_out);\n\t\t\terr = Z_STREAM_END;\n\t\t}\n\t}\n\treturn err;\n\n out_err:\n\tfprintf(stderr, \"%s: ZLIB err %s\\n\", __func__, zError(err));\n\treturn err;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nLIBS = $(LIBS) user32.lib\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -DBENCH_MT \\\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj\r\n\r\nWIN_OBJS = \\\r\n  $O\\System.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZMAUTIL_OBJS = \\\r\n  $O\\Lzma86Dec.obj \\\r\n  $O\\Lzma86Enc.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZMAUTIL_OBJS) \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZMAUTIL_OBJS): ../../../../C/LzmaUtil/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c\r\n\r\nifdef SystemDrive\r\nIS_MINGW = 1\r\nendif\r\n\r\nifdef IS_MINGW\r\nFILE_IO =FileIO\r\nFILE_IO_2 =Windows/$(FILE_IO)\r\nLIB2 = -luuid\r\nelse\r\nFILE_IO =C_FileIO\r\nFILE_IO_2 =Common/$(FILE_IO)\r\nendif\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaBenchCon.o \\\r\n  LzmaDecoder.o \\\r\n  LzmaEncoder.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  $(FILE_IO).o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  IntToString.o \\\r\n  MyString.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  MyVector.o \\\r\n  7zCrc.o \\\r\n  Alloc.o \\\r\n  Bra86.o \\\r\n  LzFind.o \\\r\n  LzmaDec.o \\\r\n  LzmaEnc.o \\\r\n  Lzma86Dec.o \\\r\n  Lzma86Enc.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaBenchCon.o: LzmaBenchCon.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBenchCon.cpp\r\n\r\nLzmaDecoder.o: ../LzmaDecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LzmaDecoder.cpp\r\n\r\nLzmaEncoder.o: ../LzmaEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LzmaEncoder.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\n$(FILE_IO).o: ../../../$(FILE_IO_2).cpp\r\n\t$(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp\r\n\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nIntToString.o: ../../../Common/IntToString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp\r\n\r\nMyString.o: ../../../Common/MyString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyString.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nMyVector.o: ../../../Common/MyVector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyVector.cpp\r\n\r\n7zCrc.o: ../../../../C/7zCrc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c\r\n\r\nAlloc.o: ../../../../C/Alloc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c\r\n\r\nBra86.o: ../../../../C/Bra86.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Bra86.c\r\n\r\nLzFind.o: ../../../../C/LzFind.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzFind.c\r\n\r\nLzmaDec.o: ../../../../C/LzmaDec.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaDec.c\r\n\r\nLzmaEnc.o: ../../../../C/LzmaEnc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaEnc.c\r\n\r\nLzma86Dec.o: ../../../../C/LzmaUtil/Lzma86Dec.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Dec.c\r\n\r\nLzma86Enc.o: ../../../../C/LzmaUtil/Lzma86Enc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LZMA_Alone/sqlzma.mk",
    "content": "\n# Copyright (C) 2006-2007 Junjiro Okajima\n# Copyright (C) 2006-2007 Tomas Matejicek, slax.org\n#\n# LICENSE follows the described one in lzma.txt.\n\n# $Id: sqlzma.mk,v 1.1 2007-11-05 05:43:36 jro Exp $\n\nifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\ninclude makefile.gcc\n\nifdef UseDebugFlags\nDebugFlags = -Wall -O0 -g -UNDEBUG\nendif\n# -pthread\nCXXFLAGS = ${CFLAGS} -D_REENTRANT -include pthread.h -DNDEBUG ${DebugFlags}\nTgt = liblzma_r.a\n\nall: ${Tgt}\n\nRObjs = LzmaEncoder_r.o LzmaEnc_r.o Alloc_r.o StreamUtils_r.o \\\n\tLzFind_r.o Bcj2Coder_r.o OutBuffer_r.o 7zCrc_r.o\n\n%_r.cc: ../%.cpp\n\tln $< $@\n%_r.c: ../../../../C/%.c\n\tln $< $@\n%_r.c: ../../../../C/Compress/Lz/%.c\n\tln $< $@\n%_r.cc: ../../Common/%.cpp\n\tln $< $@\n%_r.cc: ../RangeCoder/%.cpp\n\tln $< $@\nLzmaEncoder_r.o: CXXFLAGS += -I../\nLzmaEnc_r.o: CFLAGS += -I../../../../C\nLzFind_r.o: CFLAGS += -I../../../../C\nAlloc_r.o: CFLAGS += -I../../../../C\nStreamUtils_r.o: CXXFLAGS += -I../../Common\n# MatchFinder_r.o: CFLAGS += -I../../../../C/Compress/Lz\nLzFindMt_r.o: CFLAGS += -I../../../../C\nRangeCoderBit_r.o: CXXFLAGS += -I../RangeCoder\nBcj2Coder_r.o: CXXFLAGS += -I../\nOutBuffer_r.o: CXXFLAGS += -I../../Common\n7zCrc_r.o: CFLAGS += -I../../../../C\n\ncomp.o: CXXFLAGS += -I${Sqlzma}\ncomp.o: comp.cc ${Sqlzma}/sqlzma.h\n\nliblzma_r.a: ${RObjs} comp.o\n\t${AR} cr $@ $^\n\nclean: clean_sqlzma\nclean_sqlzma:\n\t$(RM) comp.o *_r.o ${Tgt} *~\n\n# Local variables: ;\n# compile-command: (concat \"make Sqlzma=../../../../.. -f \" (file-name-nondirectory (buffer-file-name)));\n# End: ;\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LzmaDecoder.cpp",
    "content": "// LzmaDecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"LzmaDecoder.h\"\r\n\r\nstatic HRESULT SResToHRESULT(SRes res)\r\n{\r\n  switch(res)\r\n  {\r\n    case SZ_OK: return S_OK;\r\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\r\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\r\n    case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;\r\n    // case SZ_ERROR_PROGRESS: return E_ABORT;\r\n    case SZ_ERROR_DATA: return S_FALSE;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstatic const UInt32 kInBufSize = 1 << 20;\r\n\r\nCDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false), FinishStream(false)\r\n{\r\n  LzmaDec_Construct(&_state);\r\n}\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCDecoder::~CDecoder()\r\n{\r\n  LzmaDec_Free(&_state, &g_Alloc);\r\n  MyFree(_inBuf);\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)\r\n{\r\n  RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc)));\r\n\r\n  if (_inBuf == 0)\r\n  {\r\n    _inBuf = (Byte *)MyAlloc(kInBufSize);\r\n    if (_inBuf == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) { *value = _inSizeProcessed; return S_OK; }\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; }\r\nSTDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; }\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  _outSizeDefined = (outSize != NULL);\r\n  if (_outSizeDefined)\r\n    _outSize = *outSize;\r\n\r\n  LzmaDec_Init(&_state);\r\n  \r\n  _inPos = _inSize = 0;\r\n  _inSizeProcessed = _outSizeProcessed = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)\r\n{\r\n  if (_inBuf == 0)\r\n    return S_FALSE;\r\n  SetOutStreamSize(outSize);\r\n\r\n  for (;;)\r\n  {\r\n    if (_inPos == _inSize)\r\n    {\r\n      _inPos = _inSize = 0;\r\n      RINOK(inStream->Read(_inBuf, kInBufSize, &_inSize));\r\n    }\r\n\r\n    SizeT dicPos = _state.dicPos;\r\n    SizeT curSize = _state.dicBufSize - dicPos;\r\n    const UInt32 kStepSize = ((UInt32)1 << 22);\r\n    if (curSize > kStepSize)\r\n      curSize = (SizeT)kStepSize;\r\n    \r\n    ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\r\n    if (_outSizeDefined)\r\n    {\r\n      const UInt64 rem = _outSize - _outSizeProcessed;\r\n      if (rem < curSize)\r\n      {\r\n        curSize = (SizeT)rem;\r\n        if (FinishStream)\r\n          finishMode = LZMA_FINISH_END;\r\n      }\r\n    }\r\n\r\n    SizeT inSizeProcessed = _inSize - _inPos;\r\n    ELzmaStatus status;\r\n    SRes res = LzmaDec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status);\r\n\r\n    _inPos += (UInt32)inSizeProcessed;\r\n    _inSizeProcessed += inSizeProcessed;\r\n    SizeT outSizeProcessed = _state.dicPos - dicPos;\r\n    _outSizeProcessed += outSizeProcessed;\r\n\r\n    bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0);\r\n    bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize);\r\n\r\n    if (res != 0 || _state.dicPos == _state.dicBufSize || finished || stopDecoding)\r\n    {\r\n      HRESULT res2 = WriteStream(outStream, _state.dic, _state.dicPos);\r\n      if (res != 0)\r\n        return S_FALSE;\r\n      RINOK(res2);\r\n      if (stopDecoding)\r\n        return S_OK;\r\n      if (finished)\r\n        return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE);\r\n    }\r\n    if (_state.dicPos == _state.dicBufSize)\r\n      _state.dicPos = 0;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed));\r\n    }\r\n  }\r\n}\r\n\r\n#ifndef NO_READ_FROM_CODER\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  do\r\n  {\r\n    if (_inPos == _inSize)\r\n    {\r\n      _inPos = _inSize = 0;\r\n      RINOK(_inStream->Read(_inBuf, kInBufSize, &_inSize));\r\n    }\r\n    {\r\n      SizeT inProcessed = _inSize - _inPos;\r\n\r\n      if (_outSizeDefined)\r\n      {\r\n        const UInt64 rem = _outSize - _outSizeProcessed;\r\n        if (rem < size)\r\n          size = (UInt32)rem;\r\n      }\r\n\r\n      SizeT outProcessed = size;\r\n      ELzmaStatus status;\r\n      SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,\r\n          _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);\r\n      _inPos += (UInt32)inProcessed;\r\n      _inSizeProcessed += inProcessed;\r\n      _outSizeProcessed += outProcessed;\r\n      size -= (UInt32)outProcessed;\r\n      data = (Byte *)data + outProcessed;\r\n      if (processedSize)\r\n        *processedSize += (UInt32)outProcessed;\r\n      RINOK(SResToHRESULT(res));\r\n      if (inProcessed == 0 && outProcessed == 0)\r\n        return S_OK;\r\n    }\r\n  }\r\n  while (size != 0);\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LzmaDecoder.h",
    "content": "// LzmaDecoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/LzmaDec.h\"\r\n}\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nclass CDecoder:\r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  public ICompressGetInStreamProcessedSize,\r\n  #ifndef NO_READ_FROM_CODER\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  Byte *_inBuf;\r\n  UInt32 _inPos;\r\n  UInt32 _inSize;\r\n  CLzmaDec _state;\r\n  bool _outSizeDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _inSizeProcessed;\r\n  UInt64 _outSizeProcessed;\r\npublic:\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  MY_UNKNOWN_IMP5(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize,\r\n      ICompressSetInStream,\r\n      ICompressSetOutStreamSize,\r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize)\r\n  #endif\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  bool FinishStream;\r\n\r\n  CDecoder();\r\n  virtual ~CDecoder();\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LzmaEncoder.cpp",
    "content": "// LzmaEncoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"LzmaEncoder.h\"\r\n\r\nstatic HRESULT SResToHRESULT(SRes res)\r\n{\r\n  switch(res)\r\n  {\r\n    case SZ_OK: return S_OK;\r\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\r\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\r\n    // case SZ_ERROR_THREAD: return E_FAIL;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstatic const UInt32 kStreamStepSize = (UInt32)1 << 31;\r\n\r\nstatic SRes MyRead(void *object, void *data, size_t *size)\r\n{\r\n  UInt32 curSize = ((*size < kStreamStepSize) ? (UInt32)*size : kStreamStepSize);\r\n  HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize);\r\n  *size = curSize;\r\n  return (SRes)res;\r\n}\r\n\r\nstatic size_t MyWrite(void *object, const void *data, size_t size)\r\n{\r\n  CSeqOutStream *p = (CSeqOutStream *)object;\r\n  p->Res = WriteStream(p->RealStream, data, size);\r\n  if (p->Res != 0)\r\n    return 0;\r\n  return size;\r\n}\r\n\r\nstatic void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }\r\nstatic void SzBigFree(void *, void *address) { BigFree(address); }\r\nstatic ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };\r\n\r\nstatic void *SzAlloc(void *, size_t size) { return MyAlloc(size); }\r\nstatic void SzFree(void *, void *address) { MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCEncoder::CEncoder()\r\n{\r\n  _seqInStream.SeqInStream.Read = MyRead;\r\n  _seqOutStream.SeqOutStream.Write = MyWrite;\r\n  _encoder = 0;\r\n  _encoder = LzmaEnc_Create(&g_Alloc);\r\n  if (_encoder == 0)\r\n    throw 1;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  if (_encoder != 0)\r\n    LzmaEnc_Destroy(_encoder, &g_Alloc, &g_BigAlloc);\r\n}\r\n\r\ninline wchar_t GetUpperChar(wchar_t c)\r\n{\r\n  if (c >= 'a' && c <= 'z')\r\n    c -= 0x20;\r\n  return c;\r\n}\r\n\r\nstatic int ParseMatchFinder(const wchar_t *s, int *btMode, int *numHashBytes)\r\n{\r\n  wchar_t c = GetUpperChar(*s++);\r\n  if (c == L'H')\r\n  {\r\n    if (GetUpperChar(*s++) != L'C')\r\n      return 0;\r\n    int numHashBytesLoc = (int)(*s++ - L'0');\r\n    if (numHashBytesLoc < 4 || numHashBytesLoc > 4)\r\n      return 0;\r\n    if (*s++ != 0)\r\n      return 0;\r\n    *btMode = 0;\r\n    *numHashBytes = numHashBytesLoc;\r\n    return 1;\r\n  }\r\n  if (c != L'B')\r\n    return 0;\r\n\r\n  if (GetUpperChar(*s++) != L'T')\r\n    return 0;\r\n  int numHashBytesLoc = (int)(*s++ - L'0');\r\n  if (numHashBytesLoc < 2 || numHashBytesLoc > 4)\r\n    return 0;\r\n  c = GetUpperChar(*s++);\r\n  if (c != L'\\0')\r\n    return 0;\r\n  *btMode = 1;\r\n  *numHashBytes = numHashBytesLoc;\r\n  return 1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,\r\n    const PROPVARIANT *coderProps, UInt32 numProps)\r\n{\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    const PROPVARIANT &prop = coderProps[i];\r\n    switch (propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.fb = prop.ulVal; break;\r\n      case NCoderPropID::kMatchFinderCycles:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.mc = prop.ulVal; break;\r\n      case NCoderPropID::kAlgorithm:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.algo = prop.ulVal; break;\r\n      case NCoderPropID::kDictionarySize:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.dictSize = prop.ulVal; break;\r\n      case NCoderPropID::kPosStateBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.pb = prop.ulVal; break;\r\n      case NCoderPropID::kLitPosBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lp = prop.ulVal; break;\r\n      case NCoderPropID::kLitContextBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lc = prop.ulVal; break;\r\n      case NCoderPropID::kNumThreads:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.numThreads = prop.ulVal; break;\r\n      case NCoderPropID::kMultiThread:\r\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.numThreads = ((prop.boolVal == VARIANT_TRUE) ? 2 : 1); break;\r\n      case NCoderPropID::kEndMarker:\r\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.writeEndMark = (prop.boolVal == VARIANT_TRUE); break;\r\n      case NCoderPropID::kMatchFinder:\r\n        if (prop.vt != VT_BSTR) return E_INVALIDARG;\r\n        if (!ParseMatchFinder(prop.bstrVal, &props.btMode, &props.numHashBytes /* , &_matchFinderBase.skipModeBits */))\r\n          return E_INVALIDARG; break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return SResToHRESULT(LzmaEnc_SetProps(_encoder, &props));\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  Byte props[LZMA_PROPS_SIZE];\r\n  size_t size = LZMA_PROPS_SIZE;\r\n  RINOK(LzmaEnc_WriteProperties(_encoder, props, &size));\r\n  return WriteStream(outStream, props, size);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _seqOutStream.RealStream = outStream;\r\n  _seqOutStream.Res = S_OK;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _seqOutStream.RealStream.Release();\r\n  return S_OK;\r\n}\r\n\r\ntypedef struct _CCompressProgressImp\r\n{\r\n  ICompressProgress p;\r\n  ICompressProgressInfo *Progress;\r\n  HRESULT Res;\r\n} CCompressProgressImp;\r\n\r\n#define PROGRESS_UNKNOWN_VALUE ((UInt64)(Int64)-1)\r\n\r\n#define CONVERT_PR_VAL(x) (x == PROGRESS_UNKNOWN_VALUE ? NULL : &x)\r\n\r\nSRes CompressProgress(void *pp, UInt64 inSize, UInt64 outSize)\r\n{\r\n  CCompressProgressImp *p = (CCompressProgressImp *)pp;\r\n  p->Res = p->Progress->SetRatioInfo(CONVERT_PR_VAL(inSize), CONVERT_PR_VAL(outSize));\r\n  return (SRes)p->Res;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)\r\n{\r\n  CCompressProgressImp progressImp;\r\n  progressImp.p.Progress = CompressProgress;\r\n  progressImp.Progress = progress;\r\n  progressImp.Res = SZ_OK;\r\n\r\n  _seqInStream.RealStream = inStream;\r\n  SetOutStream(outStream);\r\n  SRes res = LzmaEnc_Encode(_encoder, &_seqOutStream.SeqOutStream, &_seqInStream.SeqInStream, progress ? &progressImp.p : NULL, &g_Alloc, &g_BigAlloc);\r\n  ReleaseOutStream();\r\n  if (res == SZ_ERROR_WRITE && _seqOutStream.Res != S_OK)\r\n    return _seqOutStream.Res;\r\n  if (res == SZ_ERROR_PROGRESS && progressImp.Res != S_OK)\r\n    return progressImp.Res;\r\n  return SResToHRESULT(res);\r\n}\r\n  \r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LzmaEncoder.h",
    "content": "// LzmaEncoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/LzmaEnc.h\"\r\n}\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstruct CSeqInStream\r\n{\r\n  ISeqInStream SeqInStream;\r\n  ISequentialInStream *RealStream;\r\n};\r\n\r\nstruct CSeqOutStream\r\n{\r\n  ISeqOutStream SeqOutStream;\r\n  CMyComPtr<ISequentialOutStream> RealStream;\r\n  HRESULT Res;\r\n};\r\n\r\nclass CEncoder :\r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CMyUnknownImp\r\n{\r\n  CLzmaEncHandle _encoder;\r\n \r\n  CSeqInStream _seqInStream;\r\n  CSeqOutStream _seqOutStream;\r\n\r\npublic:\r\n  CEncoder();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/LzmaRegister.cpp",
    "content": "// LzmaRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"LzmaDecoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CDecoder); }\r\n#ifndef EXTRACT_ONLY\r\n#include \"LzmaEncoder.h\"\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CEncoder);  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x030101, L\"LZMA\", 1, false };\r\n\r\nREGISTER_CODEC(LZMA)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/RangeCoder.h",
    "content": "// Compress/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGE_CODER_H\r\n#define __COMPRESS_RANGE_CODER_H\r\n\r\n#include \"../Common/InBuffer.h\"\r\n#include \"../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1;\r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)\r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);\r\n    }\r\n    _cacheSize++;\r\n    Low = (UInt32)Low << 8;\r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numBits)\r\n  {\r\n    for (numBits--; numBits >= 0; numBits--)\r\n    {\r\n      Range >>= 1;\r\n      Low += Range & (0 - ((value >> numBits) & 1));\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;\r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8;\r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/RangeCoderBit.h",
    "content": "// Compress/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGE_CODER_BIT_H\r\n#define __COMPRESS_RANGE_CODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 4;\r\n\r\nconst int kNumBitPriceShiftBits = 4;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nextern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/Compress/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize,\r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kBlockSize,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kMatchFinderCycles,\r\n    kNumPasses = 0x460,\r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kNumThreads,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetCoderMt, 0x25)\r\n{\r\n  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block\r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICompressCodecsInfo, 0x60)\r\n{\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n};\r\nCODER_INTERFACE(ISetCompressCodecsInfo, 0x61)\r\n{\r\n  STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICryptoResetSalt, 0x88)\r\n{\r\n  STDMETHOD(ResetSalt)() PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICryptoResetInitVector, 0x8C)\r\n{\r\n  STDMETHOD(ResetInitVector)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription,\r\n    kDecoderIsAssigned,\r\n    kEncoderIsAssigned\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/IDecl.h",
    "content": "// IDecl.h\r\n\r\n#ifndef __IDECL_H\r\n#define __IDECL_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n\r\n#define DECL_INTERFACE_SUB(i, base, groupId, subId) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \\\r\nstruct i: public base\r\n\r\n#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/IPassword.h",
    "content": "// IPassword.h\r\n\r\n#ifndef __IPASSWORD_H\r\n#define __IPASSWORD_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;\r\n};\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;\r\n};\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/IProgress.h",
    "content": "// Interface/IProgress.h\r\n\r\n#ifndef __IPROGRESS_H\r\n#define __IPROGRESS_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define INTERFACE_IProgress(x) \\\r\n  STDMETHOD(SetTotal)(UInt64 total) x; \\\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) x; \\\r\n\r\nDECL_INTERFACE(IProgress, 0, 5)\r\n{\r\n  INTERFACE_IProgress(PURE)\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000000050002}\r\nDEFINE_GUID(IID_IProgress2,\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000050002\")\r\nIProgress2: public IUnknown\r\n{\r\npublic:\r\n  STDMETHOD(SetTotal)(const UInt64 *total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream,\r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/MyVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 65\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.65\"\r\n#define MY_7ZIP_VERSION \"7-Zip 4.65\"\r\n#define MY_DATE \"2009-02-03\"\r\n#define MY_COPYRIGHT \"Copyright (c) 1999-2009 Igor Pavlov\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \"  \" MY_COPYRIGHT \"  \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/MyVersionInfo.rc",
    "content": "#include <WinVer.h>\r\n#include \"MyVersion.h\"\r\n\r\n#define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0\r\n\r\n#ifdef DEBUG\r\n#define DBG_FL VS_FF_DEBUG\r\n#else\r\n#define DBG_FL 0\r\n#endif\r\n\r\n#define MY_VERSION_INFO(fileType, descr, intName, origName)  \\\r\nLANGUAGE 9, 1 \\\r\n1 VERSIONINFO \\\r\n  FILEVERSION MY_VER \\\r\n  PRODUCTVERSION MY_VER \\\r\n  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK \\\r\n  FILEFLAGS DBG_FL \\\r\n  FILEOS VOS_NT_WINDOWS32 \\\r\n  FILETYPE fileType \\\r\n  FILESUBTYPE 0x0L \\\r\nBEGIN \\\r\n    BLOCK \"StringFileInfo\" \\\r\n    BEGIN  \\\r\n        BLOCK \"040904b0\" \\\r\n        BEGIN \\\r\n            VALUE \"CompanyName\", \"Igor Pavlov\" \\\r\n            VALUE \"FileDescription\", descr \\\r\n            VALUE \"FileVersion\", MY_VERSION  \\\r\n            VALUE \"InternalName\", intName \\\r\n            VALUE \"LegalCopyright\", MY_COPYRIGHT \\\r\n            VALUE \"OriginalFilename\", origName \\\r\n            VALUE \"ProductName\", \"7-Zip\" \\\r\n            VALUE \"ProductVersion\", MY_VERSION \\\r\n        END \\\r\n    END \\\r\n    BLOCK \"VarFileInfo\" \\\r\n    BEGIN \\\r\n        VALUE \"Translation\", 0x409, 1200 \\\r\n    END \\\r\nEND\r\n\r\n#define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(VFT_APP, descr, intName, intName \".exe\")\r\n\r\n#define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(VFT_DLL, descr, intName, intName \".dll\")\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/PropID.h",
    "content": "// PropID.h\r\n\r\n#ifndef __7ZIP_PROPID_H\r\n#define __7ZIP_PROPID_H\r\n\r\nenum\r\n{\r\n  kpidNoProperty = 0,\r\n  \r\n  kpidHandlerItemIndex = 2,\r\n  kpidPath,\r\n  kpidName,\r\n  kpidExtension,\r\n  kpidIsDir,\r\n  kpidSize,\r\n  kpidPackSize,\r\n  kpidAttrib,\r\n  kpidCTime,\r\n  kpidATime,\r\n  kpidMTime,\r\n  kpidSolid,\r\n  kpidCommented,\r\n  kpidEncrypted,\r\n  kpidSplitBefore,\r\n  kpidSplitAfter,\r\n  kpidDictionarySize,\r\n  kpidCRC,\r\n  kpidType,\r\n  kpidIsAnti,\r\n  kpidMethod,\r\n  kpidHostOS,\r\n  kpidFileSystem,\r\n  kpidUser,\r\n  kpidGroup,\r\n  kpidBlock,\r\n  kpidComment,\r\n  kpidPosition,\r\n  kpidPrefix,\r\n  kpidNumSubDirs,\r\n  kpidNumSubFiles,\r\n  kpidUnpackVer,\r\n  kpidVolume,\r\n  kpidIsVolume,\r\n  kpidOffset,\r\n  kpidLinks,\r\n  kpidNumBlocks,\r\n  kpidNumVolumes,\r\n  kpidTimeType,\r\n  kpidBit64,\r\n  kpidBigEndian,\r\n  kpidCpu,\r\n  kpidPhySize,\r\n  kpidHeadersSize,\r\n  kpidChecksum,\r\n  kpidCharacts,\r\n  kpidVa,\r\n\r\n  kpidTotalSize = 0x1100,\r\n  kpidFreeSpace,\r\n  kpidClusterSize,\r\n  kpidVolumeName,\r\n\r\n  kpidLocalName = 0x1200,\r\n  kpidProvider,\r\n\r\n  kpidUserDefined = 0x10000\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Client7z/Client7z.cpp",
    "content": "// Client7z.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyInitGuid.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/DLL.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../MyVersion.h\"\r\n\r\n// use another CLSIDs, if you want to support other formats (zip, rar, ...).\r\n// {23170F69-40C1-278A-1000-000110070000}\r\nDEFINE_GUID(CLSID_CFormat7z,\r\n  0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);\r\n\r\nusing namespace NWindows;\r\n\r\n#define kDllName \"7z.dll\"\r\n\r\nstatic const char *kCopyrightString = MY_7ZIP_VERSION\r\n\" (\"  kDllName \" client) \"\r\nMY_COPYRIGHT \" \" MY_DATE;\r\n\r\nstatic const char *kHelpString =\r\n\"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\\n\"\r\n\"Examples:\\n\"\r\n\"  Client7z.exe a archive.7z f1.txt f2.txt  : compress two files to archive.7z\\n\"\r\n\"  Client7z.exe l archive.7z   : List contents of archive.7z\\n\"\r\n\"  Client7z.exe x archive.7z   : eXtract files from archive.7z\\n\";\r\n\r\n\r\ntypedef UINT32 (WINAPI * CreateObjectFunc)(\r\n    const GUID *clsID,\r\n    const GUID *interfaceID,\r\n    void **outObject);\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nvoid PrintString(const UString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)GetOemString(s));\r\n}\r\n\r\nvoid PrintString(const AString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)s);\r\n}\r\n\r\nvoid PrintNewLine()\r\n{\r\n  PrintString(\"\\n\");\r\n}\r\n\r\nvoid PrintStringLn(const AString &s)\r\n{\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nvoid PrintError(const AString &s)\r\n{\r\n  PrintNewLine();\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nstatic HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\r\n}\r\n\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Open callback class\r\n\r\n\r\nclass CArchiveOpenCallback:\r\n  public IArchiveOpenCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveOpenCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream);\r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Extracting callback class\r\n\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCRCFailed = \"CRC Failed\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nclass CArchiveExtractCallback:\r\n  public IArchiveExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IArchiveExtractCallback\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  UString _directoryPath;  // Output directory\r\n  UString _filePath;       // name inside arcvhive\r\n  UString _diskFilePath;   // full path to file on disk\r\n  bool _extractMode;\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME MTime;\r\n    UInt32 Attrib;\r\n    bool isDir;\r\n    bool AttribDefined;\r\n    bool MTimeDefined;\r\n  } _processedFileInfo;\r\n\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n\r\npublic:\r\n  void Init(IInArchive *archiveHandler, const UString &directoryPath);\r\n\r\n  UInt64 NumErrors;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveExtractCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nvoid CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)\r\n{\r\n  NumErrors = 0;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,\r\n    ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  {\r\n    // Get Name\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));\r\n    \r\n    UString fullPath;\r\n    if (prop.vt == VT_EMPTY)\r\n      fullPath = kEmptyFileAlias;\r\n    else\r\n    {\r\n      if (prop.vt != VT_BSTR)\r\n        return E_FAIL;\r\n      fullPath = prop.bstrVal;\r\n    }\r\n    _filePath = fullPath;\r\n  }\r\n\r\n  if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)\r\n    return S_OK;\r\n\r\n  {\r\n    // Get Attrib\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\r\n    if (prop.vt == VT_EMPTY)\r\n    {\r\n      _processedFileInfo.Attrib = 0;\r\n      _processedFileInfo.AttribDefined = false;\r\n    }\r\n    else\r\n    {\r\n      if (prop.vt != VT_UI4)\r\n        return E_FAIL;\r\n      _processedFileInfo.Attrib = prop.ulVal;\r\n      _processedFileInfo.AttribDefined = true;\r\n    }\r\n  }\r\n\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir));\r\n\r\n  {\r\n    // Get Modified Time\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));\r\n    _processedFileInfo.MTimeDefined = false;\r\n    switch(prop.vt)\r\n    {\r\n      case VT_EMPTY:\r\n        // _processedFileInfo.MTime = _utcMTimeDefault;\r\n        break;\r\n      case VT_FILETIME:\r\n        _processedFileInfo.MTime = prop.filetime;\r\n        _processedFileInfo.MTimeDefined = true;\r\n        break;\r\n      default:\r\n        return E_FAIL;\r\n    }\r\n\r\n  }\r\n  {\r\n    // Get Size\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    bool newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    UInt64 newFileSize;\r\n    if (newFileSizeDefined)\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n  }\r\n\r\n  \r\n  {\r\n    // Create folders for file\r\n    int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (slashPos >= 0)\r\n      NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));\r\n  }\r\n\r\n  UString fullProcessedPath = _directoryPath + _filePath;\r\n  _diskFilePath = fullProcessedPath;\r\n\r\n  if (_processedFileInfo.isDir)\r\n  {\r\n    NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (NFile::NFind::FindFile(fullProcessedPath, fi))\r\n    {\r\n      if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n      {\r\n        PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath);\r\n        return E_ABORT;\r\n      }\r\n    }\r\n    \r\n    _outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n    if (!_outFileStreamSpec->Open(fullProcessedPath, CREATE_ALWAYS))\r\n    {\r\n      PrintString((UString)L\"can not open output file \" + fullProcessedPath);\r\n      return E_ABORT;\r\n    }\r\n    _outFileStream = outStreamLoc;\r\n    *outStream = outStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:  _extractMode = true; break;\r\n  };\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:  PrintString(kExtractingString); break;\r\n    case NArchive::NExtract::NAskMode::kTest:  PrintString(kTestingString); break;\r\n    case NArchive::NExtract::NAskMode::kSkip:  PrintString(kSkippingString); break;\r\n  };\r\n  PrintString(_filePath);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumErrors++;\r\n      PrintString(\"     \");\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          PrintString(kUnsupportedMethod);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          PrintString(kCRCFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          PrintString(kDataError);\r\n          break;\r\n        default:\r\n          PrintString(kUnknownError);\r\n      }\r\n    }\r\n  }\r\n\r\n  if (_outFileStream != NULL)\r\n  {\r\n    if (_processedFileInfo.MTimeDefined)\r\n      _outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);\r\n    RINOK(_outFileStreamSpec->Close());\r\n  }\r\n  _outFileStream.Release();\r\n  if (_extractMode && _processedFileInfo.AttribDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);\r\n  PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream);\r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Creating callback class\r\n\r\nstruct CDirItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  UString FullPath;\r\n  UInt32 Attrib;\r\n\r\n  bool isDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CArchiveUpdateCallback:\r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IUpdateCallback2\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,\r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  UString DirPrefix;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n  bool m_NeedBeClosed;\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {};\r\n\r\n  ~CArchiveUpdateCallback() { Finilize(); }\r\n  HRESULT Finilize();\r\n\r\n  void Init(const CObjectVector<CDirItem> *dirItems)\r\n  {\r\n    DirItems = dirItems;\r\n    m_NeedBeClosed = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */,\r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  if (newData != NULL)\r\n    *newData = BoolToInt(true);\r\n  if (newProperties != NULL)\r\n    *newProperties = BoolToInt(true);\r\n  if (indexInArchive != NULL)\r\n    *indexInArchive = (UInt32)-1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    prop = false;\r\n    prop.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[index];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:  prop = dirItem.Name; break;\r\n      case kpidIsDir:  prop = dirItem.isDir(); break;\r\n      case kpidSize:  prop = dirItem.Size; break;\r\n      case kpidAttrib:  prop = dirItem.Attrib; break;\r\n      case kpidCTime:  prop = dirItem.CTime; break;\r\n      case kpidATime:  prop = dirItem.ATime; break;\r\n      case kpidMTime:  prop = dirItem.MTime; break;\r\n    }\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveUpdateCallback::Finilize()\r\n{\r\n  if (m_NeedBeClosed)\r\n  {\r\n    PrintNewLine();\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void GetStream2(const wchar_t *name)\r\n{\r\n  PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  PrintString(name);\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  RINOK(Finilize());\r\n\r\n  const CDirItem &dirItem = (*DirItems)[index];\r\n  GetStream2(dirItem.Name);\r\n \r\n  if (dirItem.isDir())\r\n    return S_OK;\r\n\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if (!inStreamSpec->Open(path))\r\n    {\r\n      DWORD sysError = ::GetLastError();\r\n      FailedCodes.Add(sysError);\r\n      FailedFiles.Add(path);\r\n      // if (systemError == ERROR_SHARING_VIOLATION)\r\n      {\r\n        PrintNewLine();\r\n        PrintError(\"WARNING: can't open file\");\r\n        // PrintString(NError::MyFormatMessageW(systemError));\r\n        return S_FALSE;\r\n      }\r\n      // return sysError;\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */)\r\n{\r\n  m_NeedBeClosed = true;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if (!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    if (AskPassword)\r\n    {\r\n      // You can ask real password here from user\r\n      // Password = GetPassword(OutStream);\r\n      // PasswordIsDefined = true;\r\n      PrintError(\"Password is not defined\");\r\n      return E_ABORT;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////////////////\r\n// Main function\r\n\r\nint MY_CDECL main(int argc, char* argv[])\r\n{\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  #endif\r\n\r\n  PrintStringLn(kCopyrightString);\r\n\r\n  if (argc < 3)\r\n  {\r\n    PrintStringLn(kHelpString);\r\n    return 1;\r\n  }\r\n  NWindows::NDLL::CLibrary library;\r\n  if (!library.Load(TEXT(kDllName)))\r\n  {\r\n    PrintError(\"Can not load library\");\r\n    return 1;\r\n  }\r\n  CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress(\"CreateObject\");\r\n  if (createObjectFunc == 0)\r\n  {\r\n    PrintError(\"Can not get CreateObject\");\r\n    return 1;\r\n  }\r\n\r\n  AString command = argv[1];\r\n  command.MakeLower();\r\n  UString archiveName = GetUnicodeString(argv[2], CP_OEMCP);\r\n  if (command.Compare(\"a\") == 0)\r\n  {\r\n    // create archive command\r\n    if (argc < 4)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n    CObjectVector<CDirItem> dirItems;\r\n    int i;\r\n    for (i = 3; i < argc; i++)\r\n    {\r\n      CDirItem di;\r\n      UString name = GetUnicodeString(argv[i], CP_OEMCP);\r\n      \r\n      NFile::NFind::CFileInfoW fi;\r\n      if (!NFile::NFind::FindFile(name, fi))\r\n      {\r\n        PrintString(UString(L\"Can't find file\") + name);\r\n        return 1;\r\n      }\r\n\r\n      di.Attrib = fi.Attrib;\r\n      di.Size = fi.Size;\r\n      di.CTime = fi.CTime;\r\n      di.ATime = fi.ATime;\r\n      di.MTime = fi.MTime;\r\n      di.Name = name;\r\n      di.FullPath = name;\r\n      dirItems.Add(di);\r\n    }\r\n    COutFileStream *outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;\r\n    if (!outFileStreamSpec->Create(archiveName, false))\r\n    {\r\n      PrintError(\"can't create archive file\");\r\n      return 1;\r\n    }\r\n\r\n    CMyComPtr<IOutArchive> outArchive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n\r\n    CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n    CMyComPtr<IArchiveUpdateCallback2> updateCallback(updateCallbackSpec);\r\n    updateCallbackSpec->Init(&dirItems);\r\n    // updateCallbackSpec->PasswordIsDefined = true;\r\n    // updateCallbackSpec->Password = L\"1\";\r\n\r\n    HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);\r\n    updateCallbackSpec->Finilize();\r\n    if (result != S_OK)\r\n    {\r\n      PrintError(\"Update Error\");\r\n      return 1;\r\n    }\r\n    for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)\r\n    {\r\n      PrintNewLine();\r\n      PrintString((UString)L\"Error for file: \" + updateCallbackSpec->FailedFiles[i]);\r\n    }\r\n    if (updateCallbackSpec->FailedFiles.Size() != 0)\r\n      return 1;\r\n  }\r\n  else\r\n  {\r\n    if (argc != 3)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n\r\n    bool listCommand;\r\n    if (command.Compare(\"l\") == 0)\r\n      listCommand = true;\r\n    else if (command.Compare(\"x\") == 0)\r\n      listCommand = false;\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      return 1;\r\n    }\r\n  \r\n    CMyComPtr<IInArchive> archive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n    \r\n    CInFileStream *fileSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> file = fileSpec;\r\n    \r\n    if (!fileSpec->Open(archiveName))\r\n    {\r\n      PrintError(\"Can not open archive file\");\r\n      return 1;\r\n    }\r\n\r\n    {\r\n      CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;\r\n      CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);\r\n      openCallbackSpec->PasswordIsDefined = false;\r\n      // openCallbackSpec->PasswordIsDefined = true;\r\n      // openCallbackSpec->Password = L\"1\";\r\n      \r\n      if (archive->Open(file, 0, openCallback) != S_OK)\r\n      {\r\n        PrintError(\"Can not open archive\");\r\n        return 1;\r\n      }\r\n    }\r\n    \r\n    if (listCommand)\r\n    {\r\n      // List command\r\n      UInt32 numItems = 0;\r\n      archive->GetNumberOfItems(&numItems);\r\n      for (UInt32 i = 0; i < numItems; i++)\r\n      {\r\n        {\r\n          // Get uncompressed size of file\r\n          NWindows::NCOM::CPropVariant prop;\r\n          archive->GetProperty(i, kpidSize, &prop);\r\n          UString s = ConvertPropVariantToString(prop);\r\n          PrintString(s);\r\n          PrintString(\"  \");\r\n        }\r\n        {\r\n          // Get name of file\r\n          NWindows::NCOM::CPropVariant prop;\r\n          archive->GetProperty(i, kpidPath, &prop);\r\n          UString s = ConvertPropVariantToString(prop);\r\n          PrintString(s);\r\n        }\r\n        PrintString(\"\\n\");\r\n      }\r\n    }\r\n    else\r\n    {\r\n      // Extract command\r\n      CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n      CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);\r\n      extractCallbackSpec->Init(archive, L\"\"); // second parameter is output folder path\r\n      extractCallbackSpec->PasswordIsDefined = false;\r\n      // extractCallbackSpec->PasswordIsDefined = true;\r\n      // extractCallbackSpec->Password = L\"1\";\r\n      HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);\r\n      if (result != S_OK)\r\n      {\r\n        PrintError(\"Extract Error\");\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Client7z/Client7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Client7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Client7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\" CFG=\"Client7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Client7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Client7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Client7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Client7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Client7z - Win32 Release\"\r\n# Name \"Client7z - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"stdafx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\Client7z.cpp\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Client7z/Client7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Client7z\"=.\\Client7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Client7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Client7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include <windows.h>\r\n#include <stdio.h>\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Client7z/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\Client7z.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FileStreams.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ArchiveCommandLine.cpp",
    "content": "// ArchiveCommandLine.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <io.h>\r\n#endif\r\n#include <stdio.h>\r\n\r\n#include \"Common/ListFileUtils.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/FileMapping.h\"\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ArchiveCommandLine.h\"\r\n#include \"UpdateAction.h\"\r\n#include \"Update.h\"\r\n#include \"SortUtils.h\"\r\n#include \"EnumDirItems.h\"\r\n\r\nextern bool g_CaseSensitive;\r\n\r\n#if _MSC_VER >= 1400\r\n#define MY_isatty_fileno(x) _isatty(_fileno(x))\r\n#else\r\n#define MY_isatty_fileno(x) isatty(fileno(x))\r\n#endif\r\n\r\n#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);\r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kHelp3,\r\n  kDisableHeaders,\r\n  kDisablePercents,\r\n  kArchiveType,\r\n  kYes,\r\n  #ifndef _NO_CRYPTO\r\n  kPassword,\r\n  #endif\r\n  kProperty,\r\n  kOutputDir,\r\n  kWorkingDir,\r\n  kInclude,\r\n  kExclude,\r\n  kArInclude,\r\n  kArExclude,\r\n  kNoArName,\r\n  kUpdate,\r\n  kVolume,\r\n  kRecursed,\r\n  kSfx,\r\n  kStdIn,\r\n  kStdOut,\r\n  kOverwrite,\r\n  kEmail,\r\n  kShowDialog,\r\n  kLargePages,\r\n  kCharSet,\r\n  kTechMode,\r\n  kShareForWrite,\r\n  kCaseSensitive\r\n};\r\n\r\n}\r\n\r\n\r\nstatic const wchar_t kRecursedIDChar = 'R';\r\nstatic const wchar_t *kRecursedPostCharSet = L\"0-\";\r\n\r\nnamespace NRecursedPostCharIndex {\r\n  enum EEnum\r\n  {\r\n    kWildCardRecursionOnly = 0,\r\n    kNoRecursion = 1\r\n  };\r\n}\r\n\r\nstatic const char kImmediateNameID = '!';\r\nstatic const char kMapNameID = '#';\r\nstatic const char kFileListID = '@';\r\n\r\nstatic const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be\r\nstatic const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be\r\n\r\nstatic const wchar_t *kOverwritePostCharSet = L\"asut\";\r\n\r\nNExtract::NOverwriteMode::EEnum k_OverwriteModes[] =\r\n{\r\n  NExtract::NOverwriteMode::kWithoutPrompt,\r\n  NExtract::NOverwriteMode::kSkipExisting,\r\n  NExtract::NOverwriteMode::kAutoRename,\r\n  NExtract::NOverwriteMode::kAutoRenameExisting\r\n};\r\n\r\nstatic const CSwitchForm kSwitchForms[] =\r\n  {\r\n    { L\"?\",  NSwitchType::kSimple, false },\r\n    { L\"H\",  NSwitchType::kSimple, false },\r\n    { L\"-HELP\",  NSwitchType::kSimple, false },\r\n    { L\"BA\", NSwitchType::kSimple, false },\r\n    { L\"BD\", NSwitchType::kSimple, false },\r\n    { L\"T\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"Y\",  NSwitchType::kSimple, false },\r\n    #ifndef _NO_CRYPTO\r\n    { L\"P\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    #endif\r\n    { L\"M\",  NSwitchType::kUnLimitedPostString, true, 1 },\r\n    { L\"O\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"W\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"I\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"X\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AI\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AX\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AN\", NSwitchType::kSimple, false },\r\n    { L\"U\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"V\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"R\",  NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },\r\n    { L\"SFX\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SI\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SO\", NSwitchType::kSimple, false, 0 },\r\n    { L\"AO\", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},\r\n    { L\"SEML\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"AD\",  NSwitchType::kSimple, false },\r\n    { L\"SLP\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SCS\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SLT\", NSwitchType::kSimple, false },\r\n    { L\"SSW\", NSwitchType::kSimple, false },\r\n    { L\"SSC\", NSwitchType::kPostChar, false, 0, 0, L\"-\" }\r\n  };\r\n\r\nstatic const CCommandForm g_CommandForms[] =\r\n{\r\n  { L\"A\", false },\r\n  { L\"U\", false },\r\n  { L\"D\", false },\r\n  { L\"T\", false },\r\n  { L\"E\", false },\r\n  { L\"X\", false },\r\n  { L\"L\", false },\r\n  { L\"B\", false },\r\n  { L\"I\", false }\r\n};\r\n\r\nstatic const int kNumCommandForms = sizeof(g_CommandForms) /  sizeof(g_CommandForms[0]);\r\n\r\nstatic const wchar_t *kUniversalWildcard = L\"*\";\r\nstatic const int kMinNonSwitchWords = 1;\r\nstatic const int kCommandIndex = 0;\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\";\r\nstatic const char *kIncorrectListFile = \"Incorrect item in listfile.\\nCheck charset encoding and -scs switch.\";\r\nstatic const char *kIncorrectWildCardInListFile = \"Incorrect wildcard in listfile\";\r\nstatic const char *kIncorrectWildCardInCommandLine  = \"Incorrect wildcard in command line\";\r\nstatic const char *kTerminalOutError = \"I won't write compressed data to a terminal\";\r\nstatic const char *kSameTerminalError = \"I won't write data and program's messages to same terminal\";\r\n\r\nstatic void ThrowException(const char *errorMessage)\r\n{\r\n  throw CArchiveCommandLineException(errorMessage);\r\n};\r\n\r\nstatic void ThrowUserErrorException()\r\n{\r\n  ThrowException(kUserErrorMessage);\r\n};\r\n\r\n// ---------------------------\r\n\r\nbool CArchiveCommand::IsFromExtractGroup() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kExtract:\r\n    case NCommandType::kFullExtract:\r\n      return true;\r\n    default:\r\n      return false;\r\n  }\r\n}\r\n\r\nNExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kFullExtract:\r\n      return NExtract::NPathMode::kFullPathnames;\r\n    default:\r\n      return NExtract::NPathMode::kNoPathnames;\r\n  }\r\n}\r\n\r\nbool CArchiveCommand::IsFromUpdateGroup() const\r\n{\r\n  return (CommandType == NCommandType::kAdd ||\r\n    CommandType == NCommandType::kUpdate ||\r\n    CommandType == NCommandType::kDelete);\r\n}\r\n\r\nstatic NRecursedType::EEnum GetRecursedTypeFromIndex(int index)\r\n{\r\n  switch (index)\r\n  {\r\n    case NRecursedPostCharIndex::kWildCardRecursionOnly:\r\n      return NRecursedType::kWildCardOnlyRecursed;\r\n    case NRecursedPostCharIndex::kNoRecursion:\r\n      return NRecursedType::kNonRecursed;\r\n    default:\r\n      return NRecursedType::kRecursed;\r\n  }\r\n}\r\n\r\nstatic bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)\r\n{\r\n  UString commandStringUpper = commandString;\r\n  commandStringUpper.MakeUpper();\r\n  UString postString;\r\n  int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper,\r\n      postString) ;\r\n  if (commandIndex < 0)\r\n    return false;\r\n  command.CommandType = (NCommandType::EEnum)commandIndex;\r\n  return true;\r\n}\r\n\r\n// ------------------------------------------------------------------\r\n// filenames functions\r\n\r\nstatic bool AddNameToCensor(NWildcard::CCensor &wildcardCensor,\r\n    const UString &name, bool include, NRecursedType::EEnum type)\r\n{\r\n  bool isWildCard = DoesNameContainWildCard(name);\r\n  bool recursed = false;\r\n\r\n  switch (type)\r\n  {\r\n    case NRecursedType::kWildCardOnlyRecursed:\r\n      recursed = isWildCard;\r\n      break;\r\n    case NRecursedType::kRecursed:\r\n      recursed = true;\r\n      break;\r\n    case NRecursedType::kNonRecursed:\r\n      recursed = false;\r\n      break;\r\n  }\r\n  wildcardCensor.AddItem(include, name, recursed);\r\n  return true;\r\n}\r\n\r\nstatic void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,\r\n    LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)\r\n{\r\n  UStringVector names;\r\n  if (!ReadNamesFromListFile(fileName, names, codePage))\r\n    throw kIncorrectListFile;\r\n  for (int i = 0; i < names.Size(); i++)\r\n    if (!AddNameToCensor(wildcardCensor, names[i], include, type))\r\n      throw kIncorrectWildCardInListFile;\r\n}\r\n\r\nstatic void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor,\r\n    const UString &name, bool include, NRecursedType::EEnum recursedType)\r\n{\r\n  if (!AddNameToCensor(wildcardCensor, name, include, recursedType))\r\n    throw kIncorrectWildCardInCommandLine;\r\n}\r\n\r\nstatic void AddToCensorFromNonSwitchesStrings(\r\n    int startIndex,\r\n    NWildcard::CCensor &wildcardCensor,\r\n    const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,\r\n    bool thereAreSwitchIncludes, UINT codePage)\r\n{\r\n  if (nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes))\r\n    AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);\r\n  for (int i = startIndex; i < nonSwitchStrings.Size(); i++)\r\n  {\r\n    const UString &s = nonSwitchStrings[i];\r\n    if (s[0] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);\r\n    else\r\n      AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor,\r\n    const UString &switchParam, bool include,\r\n    NRecursedType::EEnum commonRecursedType)\r\n{\r\n  int splitPos = switchParam.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  UString mappingName = switchParam.Left(splitPos);\r\n  \r\n  UString switchParam2 = switchParam.Mid(splitPos + 1);\r\n  splitPos = switchParam2.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  \r\n  UString mappingSize = switchParam2.Left(splitPos);\r\n  UString eventName = switchParam2.Mid(splitPos + 1);\r\n  \r\n  UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);\r\n  UInt32 dataSize = (UInt32)dataSize64;\r\n  {\r\n    CFileMapping fileMapping;\r\n    if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName)))\r\n      ThrowException(\"Can not open mapping\");\r\n    LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize);\r\n    if (data == NULL)\r\n      ThrowException(\"MapViewOfFile error\");\r\n    try\r\n    {\r\n      const wchar_t *curData = (const wchar_t *)data;\r\n      if (*curData != 0)\r\n        ThrowException(\"Incorrect mapping data\");\r\n      UInt32 numChars = dataSize / sizeof(wchar_t);\r\n      UString name;\r\n      for (UInt32 i = 1; i < numChars; i++)\r\n      {\r\n        wchar_t c = curData[i];\r\n        if (c == L'\\0')\r\n        {\r\n          AddCommandLineWildCardToCensr(wildcardCensor,\r\n              name, include, commonRecursedType);\r\n          name.Empty();\r\n        }\r\n        else\r\n          name += c;\r\n      }\r\n      if (!name.IsEmpty())\r\n        ThrowException(\"data error\");\r\n    }\r\n    catch(...)\r\n    {\r\n      UnmapViewOfFile(data);\r\n      throw;\r\n    }\r\n    UnmapViewOfFile(data);\r\n  }\r\n  \r\n  {\r\n    NSynchronization::CManualResetEvent event;\r\n    if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)\r\n      event.Set();\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,\r\n    const UStringVector &strings, bool include,\r\n    NRecursedType::EEnum commonRecursedType, UINT codePage)\r\n{\r\n  for (int i = 0; i < strings.Size(); i++)\r\n  {\r\n    const UString &name = strings[i];\r\n    NRecursedType::EEnum recursedType;\r\n    int pos = 0;\r\n    if (name.Length() < kSomeCludePostStringMinSize)\r\n      ThrowUserErrorException();\r\n    if (::MyCharUpper(name[pos]) == kRecursedIDChar)\r\n    {\r\n      pos++;\r\n      int index = UString(kRecursedPostCharSet).Find(name[pos]);\r\n      recursedType = GetRecursedTypeFromIndex(index);\r\n      if (index >= 0)\r\n        pos++;\r\n    }\r\n    else\r\n      recursedType = commonRecursedType;\r\n    if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)\r\n      ThrowUserErrorException();\r\n    UString tail = name.Mid(pos + 1);\r\n    if (name[pos] == kImmediateNameID)\r\n      AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);\r\n    else if (name[pos] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);\r\n    #ifdef _WIN32\r\n    else if (name[pos] == kMapNameID)\r\n      ParseMapWithPaths(wildcardCensor, tail, include, recursedType);\r\n    #endif\r\n    else\r\n      ThrowUserErrorException();\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\n// This code converts all short file names to long file names.\r\n\r\nstatic void ConvertToLongName(const UString &prefix, UString &name)\r\n{\r\n  if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n    return;\r\n  NFind::CFileInfoW fileInfo;\r\n  if (NFind::FindFile(prefix + name, fileInfo))\r\n    name = fileInfo.Name;\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)\r\n{\r\n  for (int i = 0; i < items.Size(); i++)\r\n  {\r\n    NWildcard::CItem &item = items[i];\r\n    if (item.Recursive || item.PathParts.Size() != 1)\r\n      continue;\r\n    ConvertToLongName(prefix, item.PathParts.Front());\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)\r\n{\r\n  ConvertToLongNames(prefix, node.IncludeItems);\r\n  ConvertToLongNames(prefix, node.ExcludeItems);\r\n  int i;\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n    ConvertToLongName(prefix, node.SubNodes[i].Name);\r\n  // mix folders with same name\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];\r\n    for (int j = i + 1; j < node.SubNodes.Size();)\r\n    {\r\n      const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];\r\n      if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)\r\n      {\r\n        nextNode1.IncludeItems += nextNode2.IncludeItems;\r\n        nextNode1.ExcludeItems += nextNode2.ExcludeItems;\r\n        node.SubNodes.Delete(j);\r\n      }\r\n      else\r\n        j++;\r\n    }\r\n  }\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode = node.SubNodes[i];\r\n    ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode);\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(NWildcard::CCensor &censor)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    NWildcard::CPair &pair = censor.Pairs[i];\r\n    ConvertToLongNames(pair.Prefix, pair.Head);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\nstatic NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)\r\n{\r\n  switch(i)\r\n  {\r\n    case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;\r\n    case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;\r\n    case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;\r\n    case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;\r\n  }\r\n  throw 98111603;\r\n}\r\n\r\nconst UString kUpdatePairStateIDSet = L\"PQRXYZW\";\r\nconst int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};\r\n\r\nconst UString kUpdatePairActionIDSet = L\"0123\"; //Ignore, Copy, Compress, Create Anti\r\n\r\nconst wchar_t *kUpdateIgnoreItselfPostStringID = L\"-\";\r\nconst wchar_t kUpdateNewArchivePostCharID = '!';\r\n\r\n\r\nstatic bool ParseUpdateCommandString2(const UString &command,\r\n    NUpdateArchive::CActionSet &actionSet, UString &postString)\r\n{\r\n  for (int i = 0; i < command.Length();)\r\n  {\r\n    wchar_t c = MyCharUpper(command[i]);\r\n    int statePos = kUpdatePairStateIDSet.Find(c);\r\n    if (statePos < 0)\r\n    {\r\n      postString = command.Mid(i);\r\n      return true;\r\n    }\r\n    i++;\r\n    if (i >= command.Length())\r\n      return false;\r\n    int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));\r\n    if (actionPos < 0)\r\n      return false;\r\n    actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);\r\n    if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)\r\n      return false;\r\n    i++;\r\n  }\r\n  postString.Empty();\r\n  return true;\r\n}\r\n\r\nstatic void ParseUpdateCommandString(CUpdateOptions &options,\r\n    const UStringVector &updatePostStrings,\r\n    const NUpdateArchive::CActionSet &defaultActionSet)\r\n{\r\n  for (int i = 0; i < updatePostStrings.Size(); i++)\r\n  {\r\n    const UString &updateString = updatePostStrings[i];\r\n    if (updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)\r\n    {\r\n      if (options.UpdateArchiveItself)\r\n      {\r\n        options.UpdateArchiveItself = false;\r\n        options.Commands.Delete(0);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      NUpdateArchive::CActionSet actionSet = defaultActionSet;\r\n\r\n      UString postString;\r\n      if (!ParseUpdateCommandString2(updateString, actionSet, postString))\r\n        ThrowUserErrorException();\r\n      if (postString.IsEmpty())\r\n      {\r\n        if (options.UpdateArchiveItself)\r\n          options.Commands[0].ActionSet = actionSet;\r\n      }\r\n      else\r\n      {\r\n        if (MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)\r\n          ThrowUserErrorException();\r\n        CUpdateArchiveCommand uc;\r\n        UString archivePath = postString.Mid(1);\r\n        if (archivePath.IsEmpty())\r\n          ThrowUserErrorException();\r\n        uc.UserArchivePath = archivePath;\r\n        uc.ActionSet = actionSet;\r\n        options.Commands.Add(uc);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic const char kByteSymbol = 'B';\r\nstatic const char kKiloSymbol = 'K';\r\nstatic const char kMegaSymbol = 'M';\r\nstatic const char kGigaSymbol = 'G';\r\n\r\nstatic bool ParseComplexSize(const UString &src, UInt64 &result)\r\n{\r\n  UString s = src;\r\n  s.MakeUpper();\r\n\r\n  const wchar_t *start = s;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || s.Length() > numDigits + 1)\r\n    return false;\r\n  if (s.Length() == numDigits)\r\n  {\r\n    result = number;\r\n    return true;\r\n  }\r\n  int numBits;\r\n  switch (s[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      result = number;\r\n      return true;\r\n    case kKiloSymbol:\r\n      numBits = 10;\r\n      break;\r\n    case kMegaSymbol:\r\n      numBits = 20;\r\n      break;\r\n    case kGigaSymbol:\r\n      numBits = 30;\r\n      break;\r\n    default:\r\n      return false;\r\n  }\r\n  if (number >= ((UInt64)1 << (64 - numBits)))\r\n    return false;\r\n  result = number << numBits;\r\n  return true;\r\n}\r\n\r\nstatic void SetAddCommandOptions(\r\n    NCommandType::EEnum commandType,\r\n    const CParser &parser,\r\n    CUpdateOptions &options)\r\n{\r\n  NUpdateArchive::CActionSet defaultActionSet;\r\n  switch(commandType)\r\n  {\r\n    case NCommandType::kAdd:\r\n      defaultActionSet = NUpdateArchive::kAddActionSet;\r\n      break;\r\n    case NCommandType::kDelete:\r\n      defaultActionSet = NUpdateArchive::kDeleteActionSet;\r\n      break;\r\n    default:\r\n      defaultActionSet = NUpdateArchive::kUpdateActionSet;\r\n  }\r\n  \r\n  options.UpdateArchiveItself = true;\r\n  \r\n  options.Commands.Clear();\r\n  CUpdateArchiveCommand updateMainCommand;\r\n  updateMainCommand.ActionSet = defaultActionSet;\r\n  options.Commands.Add(updateMainCommand);\r\n  if (parser[NKey::kUpdate].ThereIs)\r\n    ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings,\r\n        defaultActionSet);\r\n  if (parser[NKey::kWorkingDir].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];\r\n    if (postString.IsEmpty())\r\n      NDirectory::MyGetTempPath(options.WorkingDir);\r\n    else\r\n      options.WorkingDir = postString;\r\n  }\r\n  options.SfxMode = parser[NKey::kSfx].ThereIs;\r\n  if (options.SfxMode)\r\n    options.SfxModule = parser[NKey::kSfx].PostStrings[0];\r\n\r\n  if (parser[NKey::kVolume].ThereIs)\r\n  {\r\n    const UStringVector &sv = parser[NKey::kVolume].PostStrings;\r\n    for (int i = 0; i < sv.Size(); i++)\r\n    {\r\n      UInt64 size;\r\n      if (!ParseComplexSize(sv[i], size))\r\n        ThrowException(\"Incorrect volume size\");\r\n      options.VolumesSizes.Add(size);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)\r\n{\r\n  if (parser[NKey::kProperty].ThereIs)\r\n  {\r\n    // options.MethodMode.Properties.Clear();\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      CProperty property;\r\n      const UString &postString = parser[NKey::kProperty].PostStrings[i];\r\n      int index = postString.Find(L'=');\r\n      if (index < 0)\r\n        property.Name = postString;\r\n      else\r\n      {\r\n        property.Name = postString.Left(index);\r\n        property.Value = postString.Mid(index + 1);\r\n      }\r\n      properties.Add(property);\r\n    }\r\n  }\r\n}\r\n\r\nCArchiveCommandLineParser::CArchiveCommandLineParser():\r\n  parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}\r\n\r\nvoid CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,\r\n    CArchiveCommandLineOptions &options)\r\n{\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...)\r\n  {\r\n    ThrowUserErrorException();\r\n  }\r\n\r\n  options.IsInTerminal = MY_IS_TERMINAL(stdin);\r\n  options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);\r\n  options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);\r\n  options.StdOutMode = parser[NKey::kStdOut].ThereIs;\r\n  options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;\r\n  options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs  || parser[NKey::kHelp3].ThereIs;\r\n\r\n  #ifdef _WIN32\r\n  options.LargePages = false;\r\n  if (parser[NKey::kLargePages].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kLargePages].PostStrings.Front();\r\n    if (postString.IsEmpty())\r\n      options.LargePages = true;\r\n  }\r\n  #endif\r\n}\r\n\r\nstruct CCodePagePair\r\n{\r\n  const wchar_t *Name;\r\n  UINT CodePage;\r\n};\r\n\r\nstatic CCodePagePair g_CodePagePairs[] =\r\n{\r\n  { L\"UTF-8\", CP_UTF8 },\r\n  { L\"WIN\",   CP_ACP },\r\n  { L\"DOS\",   CP_OEMCP }\r\n};\r\n\r\nstatic const int kNumCodePages = sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]);\r\n\r\nstatic bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)\r\n{\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(s, &end);\r\n  if (*end != 0)\r\n    return false;\r\n  if (number > (UInt32)0xFFFFFFFF)\r\n    return false;\r\n  v = (UInt32)number;\r\n  return true;\r\n}\r\n\r\nvoid CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)\r\n{\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n  int numNonSwitchStrings = nonSwitchStrings.Size();\r\n  if (numNonSwitchStrings < kMinNonSwitchWords)\r\n    ThrowUserErrorException();\r\n\r\n  if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))\r\n    ThrowUserErrorException();\r\n\r\n  options.TechMode = parser[NKey::kTechMode].ThereIs;\r\n\r\n  if (parser[NKey::kCaseSensitive].ThereIs)\r\n    g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);\r\n\r\n  NRecursedType::EEnum recursedType;\r\n  if (parser[NKey::kRecursed].ThereIs)\r\n    recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);\r\n  else\r\n    recursedType = NRecursedType::kNonRecursed;\r\n\r\n  UINT codePage = CP_UTF8;\r\n  if (parser[NKey::kCharSet].ThereIs)\r\n  {\r\n    UString name = parser[NKey::kCharSet].PostStrings.Front();\r\n    name.MakeUpper();\r\n    int i;\r\n    for (i = 0; i < kNumCodePages; i++)\r\n    {\r\n      const CCodePagePair &pair = g_CodePagePairs[i];\r\n      if (name.Compare(pair.Name) == 0)\r\n      {\r\n        codePage = pair.CodePage;\r\n        break;\r\n      }\r\n    }\r\n    if (i >= kNumCodePages)\r\n      ThrowUserErrorException();\r\n  }\r\n\r\n  bool thereAreSwitchIncludes = false;\r\n  if (parser[NKey::kInclude].ThereIs)\r\n  {\r\n    thereAreSwitchIncludes = true;\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\r\n        parser[NKey::kInclude].PostStrings, true, recursedType, codePage);\r\n  }\r\n  if (parser[NKey::kExclude].ThereIs)\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\r\n        parser[NKey::kExclude].PostStrings, false, recursedType, codePage);\r\n \r\n  int curCommandIndex = kCommandIndex + 1;\r\n  bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs &&\r\n      options.Command.CommandType != NCommandType::kBenchmark &&\r\n      options.Command.CommandType != NCommandType::kInfo;\r\n  if (thereIsArchiveName)\r\n  {\r\n    if (curCommandIndex >= numNonSwitchStrings)\r\n      ThrowUserErrorException();\r\n    options.ArchiveName = nonSwitchStrings[curCommandIndex++];\r\n  }\r\n\r\n  AddToCensorFromNonSwitchesStrings(\r\n      curCommandIndex, options.WildcardCensor,\r\n      nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);\r\n\r\n  options.YesToAll = parser[NKey::kYes].ThereIs;\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  #ifndef _NO_CRYPTO\r\n  options.PasswordEnabled = parser[NKey::kPassword].ThereIs;\r\n  if (options.PasswordEnabled)\r\n    options.Password = parser[NKey::kPassword].PostStrings[0];\r\n  #endif\r\n\r\n  options.StdInMode = parser[NKey::kStdIn].ThereIs;\r\n  options.ShowDialog = parser[NKey::kShowDialog].ThereIs;\r\n\r\n  if (parser[NKey::kArchiveType].ThereIs)\r\n    options.ArcType = parser[NKey::kArchiveType].PostStrings[0];\r\n\r\n  if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if (options.StdInMode)\r\n      ThrowException(\"Reading archives from stdin is not implemented\");\r\n    if (!options.WildcardCensor.AllAreRelative())\r\n      ThrowException(\"Cannot use absolute pathnames for this command\");\r\n\r\n    NWildcard::CCensor archiveWildcardCensor;\r\n\r\n    if (parser[NKey::kArInclude].ThereIs)\r\n    {\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\r\n        parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);\r\n    }\r\n    if (parser[NKey::kArExclude].ThereIs)\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\r\n      parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);\r\n\r\n    if (thereIsArchiveName)\r\n      AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(archiveWildcardCensor);\r\n    #endif\r\n\r\n    archiveWildcardCensor.ExtendExclude();\r\n\r\n    UStringVector archivePaths;\r\n\r\n    {\r\n      CDirItems dirItems;\r\n      {\r\n        UStringVector errorPaths;\r\n        CRecordVector<DWORD> errorCodes;\r\n        HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);\r\n        if (res != S_OK || errorPaths.Size() > 0)\r\n          throw \"cannot find archive\";\r\n      }\r\n      for (int i = 0; i < dirItems.Items.Size(); i++)\r\n      {\r\n        const CDirItem &dirItem = dirItems.Items[i];\r\n        if (!dirItem.IsDir())\r\n          archivePaths.Add(dirItems.GetPhyPath(i));\r\n      }\r\n    }\r\n\r\n    if (archivePaths.Size() == 0)\r\n      throw \"there is no such archive\";\r\n\r\n    UStringVector archivePathsFull;\r\n\r\n    int i;\r\n    for (i = 0; i < archivePaths.Size(); i++)\r\n    {\r\n      UString fullPath;\r\n      NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);\r\n      archivePathsFull.Add(fullPath);\r\n    }\r\n    CIntVector indices;\r\n    SortFileNames(archivePathsFull, indices);\r\n    options.ArchivePathsSorted.Reserve(indices.Size());\r\n    options.ArchivePathsFullSorted.Reserve(indices.Size());\r\n    for (i = 0; i < indices.Size(); i++)\r\n    {\r\n      options.ArchivePathsSorted.Add(archivePaths[indices[i]]);\r\n      options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);\r\n    }\r\n\r\n    if (isExtractGroupCommand)\r\n    {\r\n      SetMethodOptions(parser, options.ExtractProperties);\r\n      if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)\r\n        throw kSameTerminalError;\r\n      if (parser[NKey::kOutputDir].ThereIs)\r\n      {\r\n        options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];\r\n        NFile::NName::NormalizeDirPathPrefix(options.OutputDir);\r\n      }\r\n\r\n      options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;\r\n      if (parser[NKey::kOverwrite].ThereIs)\r\n        options.OverwriteMode =\r\n            k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];\r\n      else if (options.YesToAll)\r\n        options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n    }\r\n  }\r\n  else if (options.Command.IsFromUpdateGroup())\r\n  {\r\n    CUpdateOptions &updateOptions = options.UpdateOptions;\r\n\r\n    SetAddCommandOptions(options.Command.CommandType, parser, updateOptions);\r\n    \r\n    SetMethodOptions(parser, updateOptions.MethodMode.Properties);\r\n\r\n    if (parser[NKey::kShareForWrite].ThereIs)\r\n      updateOptions.OpenShareForWrite = true;\r\n\r\n    options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;\r\n\r\n    if (options.EnablePercents)\r\n    {\r\n      if ((options.StdOutMode && !options.IsStdErrTerminal) ||\r\n         (!options.StdOutMode && !options.IsStdOutTerminal))\r\n        options.EnablePercents = false;\r\n    }\r\n\r\n    updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;\r\n    if (updateOptions.EMailMode)\r\n    {\r\n      updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();\r\n      if (updateOptions.EMailAddress.Length() > 0)\r\n        if (updateOptions.EMailAddress[0] == L'.')\r\n        {\r\n          updateOptions.EMailRemoveAfter = true;\r\n          updateOptions.EMailAddress.Delete(0);\r\n        }\r\n    }\r\n\r\n    updateOptions.StdOutMode = options.StdOutMode;\r\n    updateOptions.StdInMode = options.StdInMode;\r\n\r\n    if (updateOptions.StdOutMode && updateOptions.EMailMode)\r\n      throw \"stdout mode and email mode cannot be combined\";\r\n    if (updateOptions.StdOutMode && options.IsStdOutTerminal)\r\n      throw kTerminalOutError;\r\n    if (updateOptions.StdInMode)\r\n      updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(options.WildcardCensor);\r\n    #endif\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    options.NumThreads = (UInt32)-1;\r\n    options.DictionarySize = (UInt32)-1;\r\n    options.NumIterations = 1;\r\n    if (curCommandIndex < numNonSwitchStrings)\r\n    {\r\n      if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))\r\n        ThrowUserErrorException();\r\n    }\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      UString postString = parser[NKey::kProperty].PostStrings[i];\r\n      postString.MakeUpper();\r\n      if (postString.Length() < 2)\r\n        ThrowUserErrorException();\r\n      if (postString[0] == 'D')\r\n      {\r\n        int pos = 1;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        UInt32 logSize;\r\n        if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))\r\n          ThrowUserErrorException();\r\n        if (logSize > 31)\r\n          ThrowUserErrorException();\r\n        options.DictionarySize = 1 << logSize;\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == 'T' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        if (postString[pos] != 0)\r\n          if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))\r\n            ThrowUserErrorException();\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == '=' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] != 0)\r\n          options.Method = postString.Mid(2);\r\n      }\r\n      else\r\n        ThrowUserErrorException();\r\n    }\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n  }\r\n  else\r\n    ThrowUserErrorException();\r\n  options.WildcardCensor.ExtendExclude();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ArchiveCommandLine.h",
    "content": "// ArchiveCommandLine.h\r\n\r\n#ifndef __ARCHIVECOMMANDLINE_H\r\n#define __ARCHIVECOMMANDLINE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#include \"Extract.h\"\r\n#include \"Update.h\"\r\n\r\nstruct CArchiveCommandLineException: public AString\r\n{\r\n  CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {}\r\n};\r\n\r\nnamespace NCommandType { enum EEnum\r\n{\r\n  kAdd = 0,\r\n  kUpdate,\r\n  kDelete,\r\n  kTest,\r\n  kExtract,\r\n  kFullExtract,\r\n  kList,\r\n  kBenchmark,\r\n  kInfo\r\n};}\r\n\r\nnamespace NRecursedType { enum EEnum\r\n{\r\n  kRecursed,\r\n  kWildCardOnlyRecursed,\r\n  kNonRecursed\r\n};}\r\n\r\nstruct CArchiveCommand\r\n{\r\n  NCommandType::EEnum CommandType;\r\n  bool IsFromExtractGroup() const;\r\n  bool IsFromUpdateGroup() const;\r\n  bool IsTestMode() const { return CommandType == NCommandType::kTest; }\r\n  NExtract::NPathMode::EEnum GetPathMode() const;\r\n};\r\n\r\nstruct CArchiveCommandLineOptions\r\n{\r\n  bool HelpMode;\r\n\r\n  #ifdef _WIN32\r\n  bool LargePages;\r\n  #endif\r\n\r\n  bool IsInTerminal;\r\n  bool IsStdOutTerminal;\r\n  bool IsStdErrTerminal;\r\n  bool StdInMode;\r\n  bool StdOutMode;\r\n  bool EnableHeaders;\r\n\r\n  bool YesToAll;\r\n  bool ShowDialog;\r\n  // NWildcard::CCensor ArchiveWildcardCensor;\r\n  NWildcard::CCensor WildcardCensor;\r\n\r\n  CArchiveCommand Command;\r\n  UString ArchiveName;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordEnabled;\r\n  UString Password;\r\n  #endif\r\n\r\n  bool TechMode;\r\n  // Extract\r\n  bool AppendName;\r\n  UString OutputDir;\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n  UStringVector ArchivePathsSorted;\r\n  UStringVector ArchivePathsFullSorted;\r\n  CObjectVector<CProperty> ExtractProperties;\r\n\r\n  CUpdateOptions UpdateOptions;\r\n  UString ArcType;\r\n  bool EnablePercents;\r\n\r\n  // Benchmark\r\n  UInt32 NumIterations;\r\n  UInt32 NumThreads;\r\n  UInt32 DictionarySize;\r\n  UString Method;\r\n\r\n\r\n  CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};\r\n};\r\n\r\nclass CArchiveCommandLineParser\r\n{\r\n  NCommandLineParser::CParser parser;\r\npublic:\r\n  CArchiveCommandLineParser();\r\n  void Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options);\r\n  void Parse2(CArchiveCommandLineOptions &options);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp",
    "content": "// ArchiveExtractCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n#include \"OpenArchive.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic const wchar_t *kCantAutoRename = L\"ERROR: Can not create file with auto name\";\r\nstatic const wchar_t *kCantRenameFile = L\"ERROR: Can not rename existing file \";\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\n\r\nvoid CArchiveExtractCallback::Init(\r\n    IInArchive *archiveHandler,\r\n    IFolderArchiveExtractCallback *extractCallback2,\r\n    bool stdOutMode,\r\n    const UString &directoryPath,\r\n    const UStringVector &removePathParts,\r\n    const UString &itemDefaultName,\r\n    const FILETIME &utcMTimeDefault,\r\n    UInt32 attributesDefault,\r\n    UInt64 packSize)\r\n{\r\n  _stdOutMode = stdOutMode;\r\n  _numErrors = 0;\r\n  _unpTotal = 1;\r\n  _packTotal = packSize;\r\n\r\n  _extractCallback2 = extractCallback2;\r\n  _compressProgress.Release();\r\n  _extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);\r\n\r\n  LocalProgressSpec->Init(extractCallback2, true);\r\n  LocalProgressSpec->SendProgress = false;\r\n\r\n  _itemDefaultName = itemDefaultName;\r\n  _utcMTimeDefault = utcMTimeDefault;\r\n  _attributesDefault = attributesDefault;\r\n  _removePathParts = removePathParts;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  _unpTotal = size;\r\n  if (!_multiArchives && _extractCallback2)\r\n    return _extractCallback2->SetTotal(size);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  const UInt64 kMax = (UInt64)1 << 31;\r\n  while (v1 > kMax)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)\r\n{\r\n  NormalizeVals(packTotal, unpTotal);\r\n  NormalizeVals(unpCur, unpTotal);\r\n  if (unpTotal == 0)\r\n    unpTotal = 1;\r\n  return unpCur * packTotal / unpTotal;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_extractCallback2)\r\n    return S_OK;\r\n\r\n  if (_multiArchives)\r\n  {\r\n    if (completeValue != NULL)\r\n    {\r\n      UInt64 packCur = LocalProgressSpec->InSize + MyMultDiv64(*completeValue, _unpTotal, _packTotal);\r\n      return _extractCallback2->SetCompleted(&packCur);\r\n    }\r\n  }\r\n  return _extractCallback2->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return _localProgress->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\nvoid CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)\r\n{\r\n  fullPath = _directoryPath;\r\n  for(int i = 0; i < dirPathParts.Size(); i++)\r\n  {\r\n    if (i > 0)\r\n      fullPath += wchar_t(NFile::NName::kDirDelimiter);\r\n    fullPath += dirPathParts[i];\r\n    NFile::NDirectory::MyCreateDirectory(fullPath);\r\n  }\r\n}\r\n\r\nstatic UString MakePathNameFromParts(const UStringVector &parts)\r\n{\r\n  UString result;\r\n  for(int i = 0; i < parts.Size(); i++)\r\n  {\r\n    if(i != 0)\r\n      result += wchar_t(NFile::NName::kDirDelimiter);\r\n    result += parts[i];\r\n  }\r\n  return result;\r\n}\r\n\r\n\r\nHRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(_archiveHandler->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    filetime = prop.filetime;\r\n    filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  _encrypted = false;\r\n  _isSplit = false;\r\n  _curSize = 0;\r\n\r\n  UString fullPath;\r\n\r\n  RINOK(GetArchiveItemPath(_archiveHandler, index, _itemDefaultName, fullPath));\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDir));\r\n\r\n  _filePath = fullPath;\r\n\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPosition, &prop));\r\n    if (prop.vt != VT_EMPTY)\r\n    {\r\n      if (prop.vt != VT_UI8)\r\n        return E_FAIL;\r\n      _position = prop.uhVal.QuadPart;\r\n      _isSplit = true;\r\n    }\r\n  }\r\n    \r\n  RINOK(IsArchiveItemProp(_archiveHandler, index, kpidEncrypted, _encrypted));\r\n\r\n  bool newFileSizeDefined;\r\n  UInt64 newFileSize;\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    if (newFileSizeDefined)\r\n    {\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n      _curSize = newFileSize;\r\n    }\r\n  }\r\n\r\n  if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)\r\n  {\r\n    if (_stdOutMode)\r\n    {\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc = new CStdOutFileStream;\r\n      *outStream = outStreamLoc.Detach();\r\n      return S_OK;\r\n    }\r\n\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n        _processedFileInfo.Attributes = _attributesDefault;\r\n        _processedFileInfo.AttributesAreDefined = false;\r\n      }\r\n      else\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_FAIL;\r\n        _processedFileInfo.Attributes = prop.ulVal;\r\n        _processedFileInfo.AttributesAreDefined = true;\r\n      }\r\n    }\r\n\r\n    RINOK(GetTime(index, kpidCTime, _processedFileInfo.CTime, _processedFileInfo.CTimeDefined));\r\n    RINOK(GetTime(index, kpidATime, _processedFileInfo.ATime, _processedFileInfo.ATimeDefined));\r\n    RINOK(GetTime(index, kpidMTime, _processedFileInfo.MTime, _processedFileInfo.MTimeDefined));\r\n\r\n    bool isAnti = false;\r\n    RINOK(IsArchiveItemProp(_archiveHandler, index, kpidIsAnti, isAnti));\r\n\r\n    UStringVector pathParts;\r\n    SplitPathToParts(fullPath, pathParts);\r\n    \r\n    if(pathParts.IsEmpty())\r\n      return E_FAIL;\r\n    int numRemovePathParts = 0;\r\n    switch(_pathMode)\r\n    {\r\n      case NExtract::NPathMode::kFullPathnames:\r\n        break;\r\n      case NExtract::NPathMode::kCurrentPathnames:\r\n      {\r\n        numRemovePathParts = _removePathParts.Size();\r\n        if (pathParts.Size() <= numRemovePathParts)\r\n          return E_FAIL;\r\n        for (int i = 0; i < numRemovePathParts; i++)\r\n          if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0)\r\n            return E_FAIL;\r\n        break;\r\n      }\r\n      case NExtract::NPathMode::kNoPathnames:\r\n      {\r\n        numRemovePathParts = pathParts.Size() - 1;\r\n        break;\r\n      }\r\n    }\r\n    pathParts.Delete(0, numRemovePathParts);\r\n    MakeCorrectPath(pathParts);\r\n    UString processedPath = MakePathNameFromParts(pathParts);\r\n    if (!isAnti)\r\n    {\r\n      if (!_processedFileInfo.IsDir)\r\n      {\r\n        if (!pathParts.IsEmpty())\r\n          pathParts.DeleteBack();\r\n      }\r\n    \r\n      if (!pathParts.IsEmpty())\r\n      {\r\n        UString fullPathNew;\r\n        CreateComplexDirectory(pathParts, fullPathNew);\r\n        if (_processedFileInfo.IsDir)\r\n          NFile::NDirectory::SetDirTime(fullPathNew,\r\n            (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\r\n            (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\r\n            (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\r\n      }\r\n    }\r\n\r\n\r\n    UString fullProcessedPath = _directoryPath + processedPath;\r\n\r\n    if(_processedFileInfo.IsDir)\r\n    {\r\n      _diskFilePath = fullProcessedPath;\r\n      if (isAnti)\r\n        NFile::NDirectory::MyRemoveDirectory(_diskFilePath);\r\n      return S_OK;\r\n    }\r\n\r\n    if (!_isSplit)\r\n    {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      switch(_overwriteMode)\r\n      {\r\n        case NExtract::NOverwriteMode::kSkipExisting:\r\n          return S_OK;\r\n        case NExtract::NOverwriteMode::kAskBefore:\r\n        {\r\n          Int32 overwiteResult;\r\n          RINOK(_extractCallback2->AskOverwrite(\r\n              fullProcessedPath, &fileInfo.MTime, &fileInfo.Size, fullPath,\r\n              _processedFileInfo.MTimeDefined ? &_processedFileInfo.MTime : NULL,\r\n              newFileSizeDefined ? &newFileSize : NULL,\r\n              &overwiteResult))\r\n\r\n          switch(overwiteResult)\r\n          {\r\n            case NOverwriteAnswer::kCancel:\r\n              return E_ABORT;\r\n            case NOverwriteAnswer::kNo:\r\n              return S_OK;\r\n            case NOverwriteAnswer::kNoToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kSkipExisting;\r\n              return S_OK;\r\n            case NOverwriteAnswer::kYesToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n              break;\r\n            case NOverwriteAnswer::kYes:\r\n              break;\r\n            case NOverwriteAnswer::kAutoRename:\r\n              _overwriteMode = NExtract::NOverwriteMode::kAutoRename;\r\n              break;\r\n            default:\r\n              return E_FAIL;\r\n          }\r\n        }\r\n      }\r\n      if (_overwriteMode == NExtract::NOverwriteMode::kAutoRename)\r\n      {\r\n        if (!AutoRenamePath(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantAutoRename) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)\r\n      {\r\n        UString existPath = fullProcessedPath;\r\n        if (!AutoRenamePath(existPath))\r\n        {\r\n          UString message = kCantAutoRename + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n        if(!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))\r\n        {\r\n          UString message = UString(kCantRenameFile) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else\r\n        if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantDeleteOutputFile) +  fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n          // return E_FAIL;\r\n        }\r\n    }\r\n    }\r\n    if (!isAnti)\r\n    {\r\n      _outFileStreamSpec = new COutFileStream;\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n      if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))\r\n      {\r\n        // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)\r\n        {\r\n          UString message = L\"can not open output file \" + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n        }\r\n      }\r\n      if (_isSplit)\r\n      {\r\n        RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));\r\n      }\r\n      _outFileStream = outStreamLoc;\r\n      *outStream = outStreamLoc.Detach();\r\n    }\r\n    _diskFilePath = fullProcessedPath;\r\n  }\r\n  else\r\n  {\r\n    *outStream = NULL;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  return _extractCallback2->PrepareOperation(_filePath, _processedFileInfo.IsDir,\r\n      askExtractMode, _isSplit ? &_position: 0);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n    case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n    case NArchive::NExtract::NOperationResult::kCRCError:\r\n    case NArchive::NExtract::NOperationResult::kDataError:\r\n      break;\r\n    default:\r\n      _outFileStream.Release();\r\n      return E_FAIL;\r\n  }\r\n  if (_outFileStream != NULL)\r\n  {\r\n    _outFileStreamSpec->SetTime(\r\n        (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\r\n        (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\r\n        (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\r\n    _curSize = _outFileStreamSpec->ProcessedSize;\r\n    RINOK(_outFileStreamSpec->Close());\r\n    _outFileStream.Release();\r\n  }\r\n  UnpackSize += _curSize;\r\n  if (_processedFileInfo.IsDir)\r\n    NumFolders++;\r\n  else\r\n    NumFiles++;\r\n\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CArchiveExtractCallback::GetInStream(\r\n    const wchar_t *name, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  CInFileStream *inFile = new CInFileStream;\r\n  CMyComPtr<ISequentialInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(_srcDirectoryPrefix + name))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_cryptoGetTextPassword)\r\n  {\r\n    RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword,\r\n        &_cryptoGetTextPassword));\r\n  }\r\n  return _cryptoGetTextPassword->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ArchiveExtractCallback.h",
    "content": "// ArchiveExtractCallback.h\r\n\r\n#ifndef __ARCHIVEEXTRACTCALLBACK_H\r\n#define __ARCHIVEEXTRACTCALLBACK_H\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"IFileExtractCallback.h\"\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"ExtractMode.h\"\r\n\r\nclass CArchiveExtractCallback:\r\n  public IArchiveExtractCallback,\r\n  // public IArchiveVolumeExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(ICryptoGetTextPassword, ICompressProgressInfo)\r\n  // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)\r\n\r\n  INTERFACE_IArchiveExtractCallback(;)\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IArchiveVolumeExtractCallback\r\n  // STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;\r\n  CMyComPtr<ICompressProgressInfo> _compressProgress;\r\n  CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;\r\n  UString _directoryPath;\r\n  NExtract::NPathMode::EEnum _pathMode;\r\n  NExtract::NOverwriteMode::EEnum _overwriteMode;\r\n\r\n  UString _filePath;\r\n  UInt64 _position;\r\n  bool _isSplit;\r\n\r\n  UString _diskFilePath;\r\n\r\n  bool _extractMode;\r\n\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  bool _encrypted;\r\n\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME CTime;\r\n    FILETIME ATime;\r\n    FILETIME MTime;\r\n    UInt32 Attributes;\r\n  \r\n    bool CTimeDefined;\r\n    bool ATimeDefined;\r\n    bool MTimeDefined;\r\n\r\n    bool IsDir;\r\n    bool AttributesAreDefined;\r\n  } _processedFileInfo;\r\n\r\n  UInt64 _curSize;\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n  UStringVector _removePathParts;\r\n\r\n  UString _itemDefaultName;\r\n  FILETIME _utcMTimeDefault;\r\n  UInt32 _attributesDefault;\r\n  bool _stdOutMode;\r\n\r\n  void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);\r\n  HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);\r\npublic:\r\n  CArchiveExtractCallback():\r\n      WriteCTime(true),\r\n      WriteATime(true),\r\n      WriteMTime(true),\r\n      _multiArchives(false)\r\n  {\r\n    LocalProgressSpec = new CLocalProgress();\r\n    _localProgress = LocalProgressSpec;\r\n  }\r\n\r\n  CLocalProgress *LocalProgressSpec;\r\n  CMyComPtr<ICompressProgressInfo> _localProgress;\r\n  UInt64 _packTotal;\r\n  UInt64 _unpTotal;\r\n\r\n  bool _multiArchives;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  UInt64 UnpackSize;\r\n  \r\n  void InitForMulti(bool multiArchives,\r\n      NExtract::NPathMode::EEnum pathMode,\r\n      NExtract::NOverwriteMode::EEnum overwriteMode)\r\n  {\r\n    _multiArchives = multiArchives; NumFolders = NumFiles = UnpackSize = 0;\r\n    _pathMode = pathMode;\r\n    _overwriteMode = overwriteMode;\r\n  }\r\n\r\n  void Init(\r\n      IInArchive *archiveHandler,\r\n      IFolderArchiveExtractCallback *extractCallback2,\r\n      bool stdOutMode,\r\n      const UString &directoryPath,\r\n      const UStringVector &removePathParts,\r\n      const UString &itemDefaultName,\r\n      const FILETIME &utcMTimeDefault,\r\n      UInt32 attributesDefault,\r\n      UInt64 packSize);\r\n\r\n  UInt64 _numErrors;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ArchiveName.cpp",
    "content": "// ArchiveName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)\r\n{\r\n  UString resultName = L\"Archive\";\r\n  if (fromPrev)\r\n  {\r\n    UString dirPrefix;\r\n    if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))\r\n    {\r\n      if (dirPrefix.Length() > 0)\r\n        if (dirPrefix[dirPrefix.Length() - 1] == WCHAR_PATH_SEPARATOR)\r\n        {\r\n          dirPrefix.Delete(dirPrefix.Length() - 1);\r\n          NFile::NFind::CFileInfoW fileInfo;\r\n          if (NFile::NFind::FindFile(dirPrefix, fileInfo))\r\n            resultName = fileInfo.Name;\r\n        }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if (!NFile::NFind::FindFile(srcName, fileInfo))\r\n      return resultName;\r\n    resultName = fileInfo.Name;\r\n    if (!fileInfo.IsDir() && !keepName)\r\n    {\r\n      int dotPos = resultName.ReverseFind('.');\r\n      if (dotPos > 0)\r\n      {\r\n        UString archiveName2 = resultName.Left(dotPos);\r\n        if (archiveName2.ReverseFind('.') < 0)\r\n          resultName = archiveName2;\r\n      }\r\n    }\r\n  }\r\n  return resultName;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ArchiveName.h",
    "content": "// ArchiveName.h\r\n\r\n#ifndef __ARCHIVENAME_H\r\n#define __ARCHIVENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp",
    "content": "// ArchiveOpenCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n    return ReOpenCallback->SetTotal(files, bytes);\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->Open_SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n    return ReOpenCallback->SetCompleted(files, bytes);\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->Open_SetCompleted(files, bytes);\r\n  COM_TRY_END\r\n}\r\n  \r\nSTDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  if (_subArchiveMode)\r\n    switch(propID)\r\n    {\r\n      case kpidName: prop = _subArchiveName; break;\r\n    }\r\n  else\r\n    switch(propID)\r\n    {\r\n      case kpidName:  prop = _fileInfo.Name; break;\r\n      case kpidIsDir:  prop = _fileInfo.IsDir(); break;\r\n      case kpidSize:  prop = _fileInfo.Size; break;\r\n      case kpidAttrib:  prop = (UInt32)_fileInfo.Attrib; break;\r\n      case kpidCTime:  prop = _fileInfo.CTime; break;\r\n      case kpidATime:  prop = _fileInfo.ATime; break;\r\n      case kpidMTime:  prop = _fileInfo.MTime; break;\r\n    }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nint COpenCallbackImp::FindName(const UString &name)\r\n{\r\n  for (int i = 0; i < FileNames.Size(); i++)\r\n    if (name.CompareNoCase(FileNames[i]) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstruct CInFileStreamVol: public CInFileStream\r\n{\r\n  UString Name;\r\n  COpenCallbackImp *OpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;\r\n  ~CInFileStreamVol()\r\n  {\r\n    int index = OpenCallbackImp->FindName(Name);\r\n    if (index >= 0)\r\n      OpenCallbackImp->FileNames.Delete(index);\r\n  }\r\n};\r\n\r\nSTDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (_subArchiveMode)\r\n    return S_FALSE;\r\n  if (Callback)\r\n  {\r\n    RINOK(Callback->Open_CheckBreak());\r\n  }\r\n  *inStream = NULL;\r\n  UString fullPath = _folderPrefix + name;\r\n  if (!NFile::NFind::FindFile(fullPath, _fileInfo))\r\n    return S_FALSE;\r\n  if (_fileInfo.IsDir())\r\n    return S_FALSE;\r\n  CInFileStreamVol *inFile = new CInFileStreamVol;\r\n  CMyComPtr<IInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(fullPath))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  inFile->Name = name;\r\n  inFile->OpenCallbackImp = this;\r\n  inFile->OpenCallbackRef = this;\r\n  FileNames.Add(name);\r\n  TotalSize += _fileInfo.Size;\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n  {\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    ReOpenCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    if (getTextPassword)\r\n      return getTextPassword->CryptoGetTextPassword(password);\r\n  }\r\n  if (!Callback)\r\n    return E_NOTIMPL;\r\n  return Callback->Open_CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n#endif\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ArchiveOpenCallback.h",
    "content": "// ArchiveOpenCallback.h\r\n\r\n#ifndef __ARCHIVE_OPEN_CALLBACK_H\r\n#define __ARCHIVE_OPEN_CALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#ifndef _NO_CRYPTO\r\n#include \"../../IPassword.h\"\r\n#endif\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#ifdef _NO_CRYPTO\r\n\r\n#define INTERFACE_IOpenCallbackUI_Crypto(x)\r\n\r\n#else\r\n\r\n#define INTERFACE_IOpenCallbackUI_Crypto(x) \\\r\n  virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x; \\\r\n  virtual HRESULT Open_GetPasswordIfAny(UString &password) x; \\\r\n  virtual bool Open_WasPasswordAsked() x; \\\r\n  virtual void Open_ClearPasswordWasAskedFlag() x; \\\r\n  \r\n#endif\r\n\r\n#define INTERFACE_IOpenCallbackUI(x) \\\r\n  virtual HRESULT Open_CheckBreak() x; \\\r\n  virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  INTERFACE_IOpenCallbackUI_Crypto(x)\r\n\r\nstruct IOpenCallbackUI\r\n{\r\n  INTERFACE_IOpenCallbackUI(=0)\r\n};\r\n\r\nclass COpenCallbackImp:\r\n  public IArchiveOpenCallback,\r\n  public IArchiveOpenVolumeCallback,\r\n  public IArchiveOpenSetSubArchiveName,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifndef _NO_CRYPTO\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveOpenVolumeCallback,\r\n      ICryptoGetTextPassword,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      IArchiveOpenVolumeCallback,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #endif\r\n\r\n  INTERFACE_IArchiveOpenCallback(;)\r\n  INTERFACE_IArchiveOpenVolumeCallback(;)\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n  #endif\r\n\r\n  STDMETHOD(SetSubArchiveName(const wchar_t *name))\r\n  {\r\n    _subArchiveMode = true;\r\n    _subArchiveName = name;\r\n    return  S_OK;\r\n  }\r\n\r\nprivate:\r\n  UString _folderPrefix;\r\n  NWindows::NFile::NFind::CFileInfoW _fileInfo;\r\n  bool _subArchiveMode;\r\n  UString _subArchiveName;\r\npublic:\r\n  UStringVector FileNames;\r\n  IOpenCallbackUI *Callback;\r\n  CMyComPtr<IArchiveOpenCallback> ReOpenCallback;\r\n  UInt64 TotalSize;\r\n\r\n  COpenCallbackImp(): Callback(NULL) {}\r\n  void Init(const UString &folderPrefix,  const UString &fileName)\r\n  {\r\n    _folderPrefix = folderPrefix;\r\n    if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))\r\n      throw 1;\r\n    FileNames.Clear();\r\n    _subArchiveMode = false;\r\n    TotalSize = 0;\r\n  }\r\n  int FindName(const UString &name);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/DefaultName.cpp",
    "content": "// DefaultName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nstatic UString GetDefaultName3(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  int extLength = extension.Length();\r\n  int fileNameLength = fileName.Length();\r\n  if (fileNameLength > extLength + 1)\r\n  {\r\n    int dotPos = fileNameLength - (extLength + 1);\r\n    if (fileName[dotPos] == '.')\r\n      if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)\r\n        return fileName.Left(dotPos) + addSubExtension;\r\n  }\r\n  int dotPos = fileName.ReverseFind(L'.');\r\n  if (dotPos > 0)\r\n    return fileName.Left(dotPos) + addSubExtension;\r\n\r\n  if (addSubExtension.IsEmpty())\r\n    return fileName + L\"~\";\r\n  else\r\n    return fileName + addSubExtension;\r\n}\r\n\r\nUString GetDefaultName2(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  UString name = GetDefaultName3(fileName, extension, addSubExtension);\r\n  name.TrimRight();\r\n  return name;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/DefaultName.h",
    "content": "// DefaultName.h\r\n\r\n#ifndef __DEFAULTNAME_H\r\n#define __DEFAULTNAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString GetDefaultName2(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/DirItem.h",
    "content": "// DirItem.h\r\n\r\n#ifndef __DIR_ITEM_H\r\n#define __DIR_ITEM_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CDirItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  UInt32 Attrib;\r\n  int PhyParent;\r\n  int LogParent;\r\n  \r\n  CDirItem(): PhyParent(-1), LogParent(-1) {}\r\n  bool IsDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CDirItems\r\n{\r\n  UStringVector Prefixes;\r\n  CIntVector PhyParents;\r\n  CIntVector LogParents;\r\n\r\n  UString GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const;\r\npublic:\r\n  CObjectVector<CDirItem> Items;\r\n\r\n  int GetNumFolders() const { return Prefixes.Size(); }\r\n  UString GetPhyPath(int index) const;\r\n  UString GetLogPath(int index) const;\r\n\r\n  int AddPrefix(int phyParent, int logParent, const UString &prefix);\r\n  void DeleteLastPrefix();\r\n\r\n  void EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\r\n\r\n  void EnumerateDirItems2(\r\n    const UString &phyPrefix,\r\n    const UString &logPrefix,\r\n    const UStringVector &filePaths,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\r\n\r\n  void ReserveDown();\r\n};\r\n\r\nstruct CArcItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  bool IsDir;\r\n  bool SizeDefined;\r\n  bool Censored;\r\n  UInt32 IndexInServer;\r\n  int TimeType;\r\n  \r\n  CArcItem(): IsDir(false), SizeDefined(false), Censored(false), TimeType(-1) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/EnumDirItems.cpp",
    "content": "// EnumDirItems.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nvoid AddDirFileInfo(int phyParent, int logParent,\r\n    const NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems)\r\n{\r\n  CDirItem di;\r\n  di.Size = fi.Size;\r\n  di.CTime = fi.CTime;\r\n  di.ATime = fi.ATime;\r\n  di.MTime = fi.MTime;\r\n  di.Attrib = fi.Attrib;\r\n  di.PhyParent = phyParent;\r\n  di.LogParent = logParent;\r\n  di.Name = fi.Name;\r\n  dirItems.Add(di);\r\n}\r\n\r\nUString CDirItems::GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const\r\n{\r\n  UString path;\r\n  int len = name.Length();\r\n  int i;\r\n  for (i = index; i >= 0; i = parents[i])\r\n    len += Prefixes[i].Length();\r\n  int totalLen = len;\r\n  wchar_t *p = path.GetBuffer(len);\r\n  p[len] = 0;\r\n  len -= name.Length();\r\n  memcpy(p + len, (const wchar_t *)name, name.Length() * sizeof(wchar_t));\r\n  for (i = index; i >= 0; i = parents[i])\r\n  {\r\n    const UString &s = Prefixes[i];\r\n    len -= s.Length();\r\n    memcpy(p + len, (const wchar_t *)s, s.Length() * sizeof(wchar_t));\r\n  }\r\n  path.ReleaseBuffer(totalLen);\r\n  return path;\r\n}\r\n\r\nUString CDirItems::GetPhyPath(int index) const\r\n{\r\n  const CDirItem &di = Items[index];\r\n  return GetPrefixesPath(PhyParents, di.PhyParent, di.Name);\r\n}\r\n\r\nUString CDirItems::GetLogPath(int index) const\r\n{\r\n  const CDirItem &di = Items[index];\r\n  return GetPrefixesPath(LogParents, di.LogParent, di.Name);\r\n}\r\n\r\nvoid CDirItems::ReserveDown()\r\n{\r\n  Prefixes.ReserveDown();\r\n  PhyParents.ReserveDown();\r\n  LogParents.ReserveDown();\r\n  Items.ReserveDown();\r\n}\r\n\r\nint CDirItems::AddPrefix(int phyParent, int logParent, const UString &prefix)\r\n{\r\n  PhyParents.Add(phyParent);\r\n  LogParents.Add(logParent);\r\n  return Prefixes.Add(prefix);\r\n}\r\n\r\nvoid CDirItems::DeleteLastPrefix()\r\n{\r\n  PhyParents.DeleteBack();\r\n  LogParents.DeleteBack();\r\n  Prefixes.DeleteBack();\r\n}\r\n\r\nvoid CDirItems::EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\r\n{\r\n  NFind::CEnumeratorW enumerator(phyPrefix + (wchar_t)kAnyStringWildcard);\r\n  for (;;)\r\n  {\r\n    NFind::CFileInfoW fi;\r\n    bool found;\r\n    if (!enumerator.Next(fi, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPrefix);\r\n      return;\r\n    }\r\n    if (!found)\r\n      break;\r\n    AddDirFileInfo(phyParent, logParent, fi, Items);\r\n    if (fi.IsDir())\r\n    {\r\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\r\n      int parent = AddPrefix(phyParent, logParent, name2);\r\n      EnumerateDirectory(parent, parent, phyPrefix + name2, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CDirItems::EnumerateDirItems2(const UString &phyPrefix, const UString &logPrefix,\r\n    const UStringVector &filePaths, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\r\n{\r\n  int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, phyPrefix);\r\n  int logParent = logPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, logPrefix);\r\n\r\n  for (int i = 0; i < filePaths.Size(); i++)\r\n  {\r\n    const UString &filePath = filePaths[i];\r\n    NFind::CFileInfoW fi;\r\n    const UString phyPath = phyPrefix + filePath;\r\n    if (!NFind::FindFile(phyPath, fi))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPath);\r\n      continue;\r\n    }\r\n    int delimiter = filePath.ReverseFind((wchar_t)kDirDelimiter);\r\n    UString phyPrefixCur;\r\n    int phyParentCur = phyParent;\r\n    if (delimiter >= 0)\r\n    {\r\n      phyPrefixCur = filePath.Left(delimiter + 1);\r\n      phyParentCur = AddPrefix(phyParent, logParent, phyPrefixCur);\r\n    }\r\n    AddDirFileInfo(phyParentCur, logParent, fi, Items);\r\n    if (fi.IsDir())\r\n    {\r\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\r\n      int parent = AddPrefix(phyParentCur, logParent, name2);\r\n      EnumerateDirectory(parent, parent, phyPrefix + phyPrefixCur + name2, errorPaths, errorCodes);\r\n    }\r\n  }\r\n  ReserveDown();\r\n}\r\n\r\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\nstatic HRESULT EnumerateDirItems_Spec(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &curFolderName,\r\n    const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n  \r\n{\r\n  const UString name2 = curFolderName + (wchar_t)kDirDelimiter;\r\n  int parent = dirItems.AddPrefix(phyParent, logParent, name2);\r\n  int numItems = dirItems.Items.Size();\r\n  HRESULT res = EnumerateDirItems(curNode, parent, parent, phyPrefix + name2,\r\n    addArchivePrefix, dirItems, enterToSubFolders, callback, errorPaths, errorCodes);\r\n  if (numItems == dirItems.Items.Size())\r\n    dirItems.DeleteLastPrefix();\r\n  return res;\r\n}\r\n\r\n\r\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,  // prefix from curNode\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  if (!enterToSubFolders)\r\n    if (curNode.NeedCheckSubDirs())\r\n      enterToSubFolders = true;\r\n  if (callback)\r\n    RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\r\n\r\n  // try direct_names case at first\r\n  if (addArchivePrefix.IsEmpty() && !enterToSubFolders)\r\n  {\r\n    // check that all names are direct\r\n    int i;\r\n    for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n    {\r\n      const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n      if (item.Recursive || item.PathParts.Size() != 1)\r\n        break;\r\n      const UString &name = item.PathParts.Front();\r\n      if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n        break;\r\n    }\r\n    if (i == curNode.IncludeItems.Size())\r\n    {\r\n      // all names are direct (no wildcards)\r\n      // so we don't need file_system's dir enumerator\r\n      CRecordVector<bool> needEnterVector;\r\n      for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n      {\r\n        const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n        const UString &name = item.PathParts.Front();\r\n        const UString fullPath = phyPrefix + name;\r\n        NFind::CFileInfoW fi;\r\n        if (!NFind::FindFile(fullPath, fi))\r\n        {\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        bool isDir = fi.IsDir();\r\n        if (isDir && !item.ForDir || !isDir && !item.ForFile)\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        {\r\n          UStringVector pathParts;\r\n          pathParts.Add(fi.Name);\r\n          if (curNode.CheckPathToRoot(false, pathParts, !isDir))\r\n            continue;\r\n        }\r\n        AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\r\n        if (!isDir)\r\n          continue;\r\n        \r\n        UStringVector addArchivePrefixNew;\r\n        const NWildcard::CCensorNode *nextNode = 0;\r\n        int index = curNode.FindSubNode(name);\r\n        if (index >= 0)\r\n        {\r\n          for (int t = needEnterVector.Size(); t <= index; t++)\r\n            needEnterVector.Add(true);\r\n          needEnterVector[index] = false;\r\n          nextNode = &curNode.SubNodes[index];\r\n        }\r\n        else\r\n        {\r\n          nextNode = &curNode;\r\n          addArchivePrefixNew.Add(name); // don't change it to fi.Name. It's for shortnames support\r\n        }\r\n\r\n        RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix,\r\n            addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes));\r\n      }\r\n      for (i = 0; i < curNode.SubNodes.Size(); i++)\r\n      {\r\n        if (i < needEnterVector.Size())\r\n          if (!needEnterVector[i])\r\n            continue;\r\n        const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];\r\n        const UString fullPath = phyPrefix + nextNode.Name;\r\n        NFind::CFileInfoW fi;\r\n        if (!NFind::FindFile(fullPath, fi))\r\n        {\r\n          if (!nextNode.AreThereIncludeItems())\r\n            continue;\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        if (!fi.IsDir())\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n\r\n        RINOK(EnumerateDirItems_Spec(nextNode, phyParent, logParent, fi.Name, phyPrefix,\r\n            UStringVector(), dirItems, false, callback, errorPaths, errorCodes));\r\n      }\r\n      return S_OK;\r\n    }\r\n  }\r\n\r\n\r\n  NFind::CEnumeratorW enumerator(phyPrefix + wchar_t(kAnyStringWildcard));\r\n  for (int ttt = 0; ; ttt++)\r\n  {\r\n    NFind::CFileInfoW fi;\r\n    bool found;\r\n    if (!enumerator.Next(fi, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPrefix);\r\n      break;\r\n    }\r\n    if (!found)\r\n      break;\r\n\r\n    if (callback && (ttt & 0xFF) == 0xFF)\r\n      RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\r\n    const UString &name = fi.Name;\r\n    bool enterToSubFolders2 = enterToSubFolders;\r\n    UStringVector addArchivePrefixNew = addArchivePrefix;\r\n    addArchivePrefixNew.Add(name);\r\n    {\r\n      UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);\r\n      if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fi.IsDir()))\r\n        continue;\r\n    }\r\n    if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir()))\r\n    {\r\n      AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\r\n      if (fi.IsDir())\r\n        enterToSubFolders2 = true;\r\n    }\r\n    if (!fi.IsDir())\r\n      continue;\r\n\r\n    const NWildcard::CCensorNode *nextNode = 0;\r\n    if (addArchivePrefix.IsEmpty())\r\n    {\r\n      int index = curNode.FindSubNode(name);\r\n      if (index >= 0)\r\n        nextNode = &curNode.SubNodes[index];\r\n    }\r\n    if (!enterToSubFolders2 && nextNode == 0)\r\n      continue;\r\n\r\n    addArchivePrefixNew = addArchivePrefix;\r\n    if (nextNode == 0)\r\n    {\r\n      nextNode = &curNode;\r\n      addArchivePrefixNew.Add(name);\r\n    }\r\n\r\n    RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, name, phyPrefix,\r\n        addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor,\r\n    CDirItems &dirItems,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    const NWildcard::CPair &pair = censor.Pairs[i];\r\n    int phyParent = pair.Prefix.IsEmpty() ? -1 : dirItems.AddPrefix(-1, -1, pair.Prefix);\r\n    RINOK(EnumerateDirItems(pair.Head, phyParent, -1, pair.Prefix, UStringVector(), dirItems, false,\r\n        callback, errorPaths, errorCodes));\r\n  }\r\n  dirItems.ReserveDown();\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/EnumDirItems.h",
    "content": "// EnumDirItems.h\r\n\r\n#ifndef __ENUM_DIR_ITEMS_H\r\n#define __ENUM_DIR_ITEMS_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"DirItem.h\"\r\n\r\nvoid AddDirFileInfo(int phyParent, int logParent,\r\n    const NWindows::NFile::NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems);\r\n\r\nstruct IEnumDirItemCallback\r\n{\r\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) = 0;\r\n};\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor,\r\n    CDirItems &dirItems,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ExitCode.h",
    "content": "// ExitCode.h\r\n\r\n#ifndef __EXIT_CODE_H\r\n#define __EXIT_CODE_H\r\n\r\nnamespace NExitCode {\r\n\r\nenum EEnum {\r\n\r\n  kSuccess       = 0,     // Successful operation\r\n  kWarning       = 1,     // Non fatal error(s) occurred\r\n  kFatalError    = 2,     // A fatal error occurred\r\n  // kCRCError      = 3,     // A CRC error occurred when unpacking\r\n  // kLockedArchive = 4,     // Attempt to modify an archive previously locked\r\n  // kWriteError    = 5,     // Write to disk error\r\n  // kOpenError     = 6,     // Open file error\r\n  kUserError     = 7,     // Command line option error\r\n  kMemoryError   = 8,     // Not enough memory for operation\r\n  // kCreateFileError = 9,     // Create file error\r\n  \r\n  kUserBreak     = 255   // User stopped the process\r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/Extract.cpp",
    "content": "// Extract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Extract.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n#include \"SetProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic HRESULT DecompressArchive(\r\n    IInArchive *archive,\r\n    UInt64 packSize,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IExtractCallbackUI *callback,\r\n    CArchiveExtractCallback *extractCallbackSpec,\r\n    UString &errorMessage)\r\n{\r\n  CRecordVector<UInt32> realIndices;\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UString filePath;\r\n    RINOK(GetArchiveItemPath(archive, i, options.DefaultItemName, filePath));\r\n    bool isFolder;\r\n    RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n    if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n      continue;\r\n    realIndices.Add(i);\r\n  }\r\n  if (realIndices.Size() == 0)\r\n  {\r\n    callback->ThereAreNoFiles();\r\n    return S_OK;\r\n  }\r\n\r\n  UStringVector removePathParts;\r\n\r\n  UString outDir = options.OutputDir;\r\n  outDir.Replace(L\"*\", options.DefaultItemName);\r\n  #ifdef _WIN32\r\n  outDir.TrimRight();\r\n  #endif\r\n\r\n  if(!outDir.IsEmpty())\r\n    if(!NFile::NDirectory::CreateComplexDirectory(outDir))\r\n    {\r\n      HRESULT res = ::GetLastError();\r\n      if (res == S_OK)\r\n        res = E_FAIL;\r\n      errorMessage = ((UString)L\"Can not create output directory \") + outDir;\r\n      return res;\r\n    }\r\n\r\n  extractCallbackSpec->Init(\r\n      archive,\r\n      callback,\r\n      options.StdOutMode,\r\n      outDir,\r\n      removePathParts,\r\n      options.DefaultItemName,\r\n      options.ArchiveFileInfo.MTime,\r\n      options.ArchiveFileInfo.Attrib,\r\n      packSize);\r\n\r\n  #ifdef COMPRESS_MT\r\n  RINOK(SetProperties(archive, options.Properties));\r\n  #endif\r\n\r\n  HRESULT result = archive->Extract(&realIndices.Front(),\r\n    realIndices.Size(), options.TestMode? 1: 0, extractCallbackSpec);\r\n\r\n  return callback->ExtractResult(result);\r\n}\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &optionsSpec,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage,\r\n    CDecompressStat &stat)\r\n{\r\n  stat.Clear();\r\n  CExtractOptions options = optionsSpec;\r\n  int i;\r\n  UInt64 totalPackSize = 0;\r\n  CRecordVector<UInt64> archiveSizes;\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archivePath, fi))\r\n      throw \"there is no such archive\";\r\n    if (fi.IsDir())\r\n      throw \"can't decompress folder\";\r\n    archiveSizes.Add(fi.Size);\r\n    totalPackSize += fi.Size;\r\n  }\r\n  CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n  CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);\r\n  bool multi = (archivePaths.Size() > 1);\r\n  extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);\r\n  if (multi)\r\n  {\r\n    RINOK(extractCallback->SetTotal(totalPackSize));\r\n  }\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archivePath, fi))\r\n      throw \"there is no such archive\";\r\n\r\n    if (fi.IsDir())\r\n      throw \"there is no such archive\";\r\n\r\n    options.ArchiveFileInfo = fi;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    openCallback->Open_ClearPasswordWasAskedFlag();\r\n    #endif\r\n\r\n    RINOK(extractCallback->BeforeOpen(archivePath));\r\n    CArchiveLink archiveLink;\r\n\r\n    CIntVector formatIndices2 = formatIndices;\r\n    #ifndef _SFX\r\n    if (formatIndices.IsEmpty())\r\n    {\r\n      int pos = archivePath.ReverseFind(L'.');\r\n      if (pos >= 0)\r\n      {\r\n        UString s = archivePath.Mid(pos + 1);\r\n        int index = codecs->FindFormatForExtension(s);\r\n        if (index >= 0 && s == L\"001\")\r\n        {\r\n          s = archivePath.Left(pos);\r\n          pos = s.ReverseFind(L'.');\r\n          if (pos >= 0)\r\n          {\r\n            int index2 = codecs->FindFormatForExtension(s.Mid(pos + 1));\r\n            if (index2 >= 0 && s.CompareNoCase(L\"rar\") != 0)\r\n            {\r\n              formatIndices2.Add(index2);\r\n              formatIndices2.Add(index);\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n    #endif\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices2, archivePath, archiveLink, openCallback);\r\n    if (result == E_ABORT)\r\n      return result;\r\n\r\n    bool crypted = false;\r\n    #ifndef _NO_CRYPTO\r\n    crypted = openCallback->Open_WasPasswordAsked();\r\n    #endif\r\n\r\n    RINOK(extractCallback->OpenResult(archivePath, result, crypted));\r\n    if (result != S_OK)\r\n      continue;\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n        totalPackSize -= archiveSizes[index];\r\n        archiveSizes.Delete(index);\r\n      }\r\n    }\r\n    if (archiveLink.VolumePaths.Size() != 0)\r\n    {\r\n      totalPackSize += archiveLink.VolumesSize;\r\n      RINOK(extractCallback->SetTotal(totalPackSize));\r\n    }\r\n\r\n    #ifndef _NO_CRYPTO\r\n    UString password;\r\n    RINOK(openCallback->Open_GetPasswordIfAny(password));\r\n    if (!password.IsEmpty())\r\n    {\r\n      RINOK(extractCallback->SetPassword(password));\r\n    }\r\n    #endif\r\n\r\n    options.DefaultItemName = archiveLink.GetDefaultItemName();\r\n    RINOK(DecompressArchive(\r\n        archiveLink.GetArchive(),\r\n        fi.Size + archiveLink.VolumesSize,\r\n        wildcardCensor, options, extractCallback, extractCallbackSpec, errorMessage));\r\n    extractCallbackSpec->LocalProgressSpec->InSize += fi.Size +\r\n        archiveLink.VolumesSize;\r\n    extractCallbackSpec->LocalProgressSpec->OutSize = extractCallbackSpec->UnpackSize;\r\n    if (!errorMessage.IsEmpty())\r\n      return E_FAIL;\r\n  }\r\n  stat.NumFolders = extractCallbackSpec->NumFolders;\r\n  stat.NumFiles = extractCallbackSpec->NumFiles;\r\n  stat.UnpackSize = extractCallbackSpec->UnpackSize;\r\n  stat.NumArchives = archivePaths.Size();\r\n  stat.PackSize = extractCallbackSpec->LocalProgressSpec->InSize;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/Extract.h",
    "content": "// Extract.h\r\n\r\n#ifndef __EXTRACT_H\r\n#define __EXTRACT_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"ExtractMode.h\"\r\n#include \"Property.h\"\r\n\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nclass CExtractOptions\r\n{\r\npublic:\r\n  bool StdOutMode;\r\n  bool TestMode;\r\n  NExtract::NPathMode::EEnum PathMode;\r\n\r\n  UString OutputDir;\r\n  bool YesToAll;\r\n  UString DefaultItemName;\r\n  NWindows::NFile::NFind::CFileInfoW ArchiveFileInfo;\r\n  \r\n  // bool ShowDialog;\r\n  // bool PasswordEnabled;\r\n  // UString Password;\r\n  #ifdef COMPRESS_MT\r\n  CObjectVector<CProperty> Properties;\r\n  #endif\r\n\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  CCodecs *Codecs;\r\n  #endif\r\n\r\n  CExtractOptions():\r\n      StdOutMode(false),\r\n      YesToAll(false),\r\n      TestMode(false),\r\n      PathMode(NExtract::NPathMode::kFullPathnames),\r\n      OverwriteMode(NExtract::NOverwriteMode::kAskBefore)\r\n      {}\r\n\r\n  /*\r\n    bool FullPathMode() const { return (ExtractMode == NExtractMode::kTest) ||\r\n    (ExtractMode == NExtractMode::kFullPath); }\r\n  */\r\n};\r\n\r\nstruct CDecompressStat\r\n{\r\n  UInt64 NumArchives;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  void Clear() { NumArchives = PackSize = UnpackSize = NumFolders = NumFiles = 0; }\r\n};\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage,\r\n    CDecompressStat &stat);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ExtractMode.h",
    "content": "// ExtractMode.h\r\n\r\n#ifndef __EXTRACT_MODE_H\r\n#define __EXTRACT_MODE_H\r\n\r\nnamespace NExtract {\r\n  \r\n  namespace NPathMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kFullPathnames,\r\n      kCurrentPathnames,\r\n      kNoPathnames\r\n    };\r\n  }\r\n  \r\n  namespace NOverwriteMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kAskBefore,\r\n      kWithoutPrompt,\r\n      kSkipExisting,\r\n      kAutoRename,\r\n      kAutoRenameExisting\r\n    };\r\n  }\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ExtractingFilePath.cpp",
    "content": "// ExtractingFilePath.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ExtractingFilePath.h\"\r\n\r\nstatic UString ReplaceIncorrectChars(const UString &s)\r\n{\r\n  #ifdef _WIN32\r\n  UString res;\r\n  for (int i = 0; i < s.Length(); i++)\r\n  {\r\n    wchar_t c = s[i];\r\n    if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>'  || c == '|' || c == ':' || c == '\"')\r\n      c = '_';\r\n    res += c;\r\n  }\r\n  res.TrimRight();\r\n  return res;\r\n  #else\r\n  return s;\r\n  #endif\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t *g_ReservedNames[] =\r\n{\r\n  L\"CON\", L\"PRN\", L\"AUX\", L\"NUL\"\r\n};\r\n\r\nstatic bool CheckTail(const UString &name, int len)\r\n{\r\n  int dotPos = name.Find(L'.');\r\n  if (dotPos < 0)\r\n    dotPos = name.Length();\r\n  UString s = name.Left(dotPos);\r\n  s.TrimRight();\r\n  return (s.Length() != len);\r\n}\r\n\r\nstatic bool CheckNameNum(const UString &name, const wchar_t *reservedName)\r\n{\r\n  int len = MyStringLen(reservedName);\r\n  if (name.Length() <= len)\r\n    return true;\r\n  if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n    return true;\r\n  wchar_t c = name[len];\r\n  if (c < L'0' || c > L'9')\r\n    return true;\r\n  return CheckTail(name, len + 1);\r\n}\r\n\r\nstatic bool IsSupportedName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++)\r\n  {\r\n    const wchar_t *reservedName = g_ReservedNames[i];\r\n    int len = MyStringLen(reservedName);\r\n    if (name.Length() < len)\r\n      continue;\r\n    if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n      continue;\r\n    if (!CheckTail(name, len))\r\n      return false;\r\n  }\r\n  if (!CheckNameNum(name, L\"COM\"))\r\n    return false;\r\n  return CheckNameNum(name, L\"LPT\");\r\n}\r\n#endif\r\n\r\nstatic UString GetCorrectFileName(const UString &path)\r\n{\r\n  if (path == L\"..\" || path == L\".\")\r\n    return UString();\r\n  return ReplaceIncorrectChars(path);\r\n}\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts)\r\n{\r\n  for (int i = 0; i < pathParts.Size();)\r\n  {\r\n    UString &s = pathParts[i];\r\n    s = GetCorrectFileName(s);\r\n    if (s.IsEmpty())\r\n      pathParts.Delete(i);\r\n    else\r\n    {\r\n      #ifdef _WIN32\r\n      if (!IsSupportedName(s))\r\n        s = (UString)L\"_\" + s;\r\n      #endif\r\n      i++;\r\n    }\r\n  }\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ExtractingFilePath.h",
    "content": "// ExtractingFilePath.h\r\n\r\n#ifndef __EXTRACTINGFILEPATH_H\r\n#define __EXTRACTINGFILEPATH_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/IFileExtractCallback.h",
    "content": "// IFileExtractCallback.h\r\n\r\n#ifndef __IFILEEXTRACTCALLBACK_H\r\n#define __IFILEEXTRACTCALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"../../IDecl.h\"\r\n\r\nnamespace NOverwriteAnswer\r\n{\r\n  enum EEnum\r\n  {\r\n    kYes,\r\n    kYesToAll,\r\n    kNo,\r\n    kNoToAll,\r\n    kAutoRename,\r\n    kCancel\r\n  };\r\n}\r\n\r\nDECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)\r\n{\r\npublic:\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer) PURE;\r\n  STDMETHOD(PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position) PURE;\r\n  STDMETHOD(MessageError)(const wchar_t *message) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE;\r\n};\r\n\r\nstruct IExtractCallbackUI: IFolderArchiveExtractCallback\r\n{\r\n  virtual HRESULT BeforeOpen(const wchar_t *name) = 0;\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted) = 0;\r\n  virtual HRESULT ThereAreNoFiles() = 0;\r\n  virtual HRESULT ExtractResult(HRESULT result) = 0;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  virtual HRESULT SetPassword(const UString &password) = 0;\r\n  #endif\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/LoadCodecs.cpp",
    "content": "// LoadCodecs.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LoadCodecs.h\"\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Common/StringToInt.h\"\r\n#endif\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/FileFind.h\"\r\n#include \"../../../Windows/DLL.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Windows/ResourceString.h\"\r\nstatic const UINT kIconTypesResId = 100;\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/Registry.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\n#ifdef _WIN32\r\nextern HINSTANCE g_hInstance;\r\n#endif\r\n\r\nstatic CSysString GetLibraryFolderPrefix()\r\n{\r\n  #ifdef _WIN32\r\n  TCHAR fullPath[MAX_PATH + 1];\r\n  ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);\r\n  CSysString path = fullPath;\r\n  int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  return path.Left(pos + 1);\r\n  #else\r\n  return CSysString(); // FIX IT\r\n  #endif\r\n}\r\n\r\n#define kCodecsFolderName TEXT(\"Codecs\")\r\n#define kFormatsFolderName TEXT(\"Formats\")\r\nstatic const TCHAR *kMainDll = TEXT(\"7z.dll\");\r\n\r\n#ifdef _WIN32\r\nstatic LPCTSTR kRegistryPath = TEXT(\"Software\") TEXT(STRING_PATH_SEPARATOR) TEXT(\"7-zip\");\r\nstatic LPCTSTR kProgramPathValue = TEXT(\"Path\");\r\nstatic bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)\r\n{\r\n  NRegistry::CKey key;\r\n  if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)\r\n    if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)\r\n    {\r\n      NName::NormalizeDirPathPrefix(path);\r\n      return true;\r\n    }\r\n  return false;\r\n}\r\n\r\n#endif\r\n\r\nCSysString GetBaseFolderPrefixFromRegistry()\r\n{\r\n  CSysString moduleFolderPrefix = GetLibraryFolderPrefix();\r\n  NFind::CFileInfo fi;\r\n  if (NFind::FindFile(moduleFolderPrefix + kMainDll, fi))\r\n    if (!fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fi))\r\n    if (fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fi))\r\n    if (fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  #ifdef _WIN32\r\n  CSysString path;\r\n  if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))\r\n    return path;\r\n  if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))\r\n    return path;\r\n  #endif\r\n  return moduleFolderPrefix;\r\n}\r\n\r\ntypedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);\r\ntypedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, void **outObject);\r\ntypedef UInt32 (WINAPI *SetLargePageModeFunc)();\r\n\r\n\r\nstatic HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 index,\r\n    PROPID propId, CLSID &clsId, bool &isAssigned)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  isAssigned = false;\r\n  RINOK(getMethodProperty(index, propId, &prop));\r\n  if (prop.vt == VT_BSTR)\r\n  {\r\n    isAssigned = true;\r\n    clsId = *(const GUID *)prop.bstrVal;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::LoadCodecs()\r\n{\r\n  CCodecLib &lib = Libs.Back();\r\n  lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress(\"GetMethodProperty\");\r\n  if (lib.GetMethodProperty == NULL)\r\n    return S_OK;\r\n\r\n  UInt32 numMethods = 1;\r\n  GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProcAddress(\"GetNumberOfMethods\");\r\n  if (getNumberOfMethodsFunc != NULL)\r\n  {\r\n    RINOK(getNumberOfMethodsFunc(&numMethods));\r\n  }\r\n\r\n  for(UInt32 i = 0; i < numMethods; i++)\r\n  {\r\n    CDllCodecInfo info;\r\n    info.LibIndex = Libs.Size() - 1;\r\n    info.CodecIndex = i;\r\n\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));\r\n\r\n    Codecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, NCOM::CPropVariant &prop)\r\n{\r\n  if (getProp2)\r\n    return getProp2(index, propID, &prop);;\r\n  return getProp(propID, &prop);\r\n}\r\n\r\nstatic HRESULT ReadBoolProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadStringProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, UString &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BSTR)\r\n    res = prop.bstrVal;\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\r\nvoid RegisterArc(const CArcInfo *arcInfo)\r\n{\r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo;\r\n}\r\n\r\nstatic void SplitString(const UString &srcString, UStringVector &destStrings)\r\n{\r\n  destStrings.Clear();\r\n  UString s;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L' ')\r\n    {\r\n      if (!s.IsEmpty())\r\n      {\r\n        destStrings.Add(s);\r\n        s.Empty();\r\n      }\r\n    }\r\n    else\r\n      s += c;\r\n  }\r\n  if (!s.IsEmpty())\r\n    destStrings.Add(s);\r\n}\r\n\r\nvoid CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt)\r\n{\r\n  UStringVector exts, addExts;\r\n  SplitString(ext, exts);\r\n  if (addExt != 0)\r\n    SplitString(addExt, addExts);\r\n  for (int i = 0; i < exts.Size(); i++)\r\n  {\r\n    CArcExtInfo extInfo;\r\n    extInfo.Ext = exts[i];\r\n    if (i < addExts.Size())\r\n    {\r\n      extInfo.AddExt = addExts[i];\r\n      if (extInfo.AddExt == L\"*\")\r\n        extInfo.AddExt.Empty();\r\n    }\r\n    Exts.Add(extInfo);\r\n  }\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nHRESULT CCodecs::LoadFormats()\r\n{\r\n  const NDLL::CLibrary &lib = Libs.Back().Lib;\r\n  GetHandlerPropertyFunc getProp = 0;\r\n  GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)\r\n      lib.GetProcAddress(\"GetHandlerProperty2\");\r\n  if (getProp2 == NULL)\r\n  {\r\n    getProp = (GetHandlerPropertyFunc)\r\n        lib.GetProcAddress(\"GetHandlerProperty\");\r\n    if (getProp == NULL)\r\n      return S_OK;\r\n  }\r\n\r\n  UInt32 numFormats = 1;\r\n  GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)\r\n    lib.GetProcAddress(\"GetNumberOfFormats\");\r\n  if (getNumberOfFormats != NULL)\r\n  {\r\n    RINOK(getNumberOfFormats(&numFormats));\r\n  }\r\n  if (getProp2 == NULL)\r\n    numFormats = 1;\r\n\r\n  for(UInt32 i = 0; i < numFormats; i++)\r\n  {\r\n    CArcInfoEx item;\r\n    item.LibIndex = Libs.Size() - 1;\r\n    item.FormatIndex = i;\r\n\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)\r\n      continue;\r\n    if (prop.vt != VT_BSTR)\r\n      continue;\r\n    item.ClassID = *(const GUID *)prop.bstrVal;\r\n    prop.Clear();\r\n\r\n    UString ext, addExt;\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));\r\n    item.AddExts(ext, addExt);\r\n\r\n    ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);\r\n    if (item.UpdateEnabled)\r\n      ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);\r\n    \r\n    if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)\r\n      if (prop.vt == VT_BSTR)\r\n      {\r\n        UINT len = ::SysStringByteLen(prop.bstrVal);\r\n        item.StartSignature.SetCapacity(len);\r\n        memmove(item.StartSignature, prop.bstrVal, len);\r\n      }\r\n    Formats.Add(item);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef NEW_FOLDER_INTERFACE\r\nvoid CCodecLib::LoadIcons()\r\n{\r\n  UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId);\r\n  UStringVector pairs;\r\n  SplitString(iconTypes, pairs);\r\n  for (int i = 0; i < pairs.Size(); i++)\r\n  {\r\n    const UString &s = pairs[i];\r\n    int pos = s.Find(L':');\r\n    if (pos < 0)\r\n      continue;\r\n    CIconPair iconPair;\r\n    const wchar_t *end;\r\n    UString num = s.Mid(pos + 1);\r\n    iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);\r\n    if (*end != L'\\0')\r\n      continue;\r\n    iconPair.Ext = s.Left(pos);\r\n    IconPairs.Add(iconPair);\r\n  }\r\n}\r\n\r\nint CCodecLib::FindIconIndex(const UString &ext) const\r\n{\r\n  for (int i = 0; i < IconPairs.Size(); i++)\r\n  {\r\n    const CIconPair &pair = IconPairs[i];\r\n    if (ext.CompareNoCase(pair.Ext) == 0)\r\n      return pair.IconIndex;\r\n  }\r\n  return -1;\r\n}\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nextern \"C\"\r\n{\r\n  extern SIZE_T g_LargePageSize;\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::LoadDll(const CSysString &dllPath)\r\n{\r\n  {\r\n    NDLL::CLibrary library;\r\n    if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))\r\n      return S_OK;\r\n  }\r\n  Libs.Add(CCodecLib());\r\n  CCodecLib &lib = Libs.Back();\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  lib.Path = dllPath;\r\n  #endif\r\n  bool used = false;\r\n  HRESULT res = S_OK;\r\n  if (lib.Lib.Load(dllPath))\r\n  {\r\n    #ifdef NEW_FOLDER_INTERFACE\r\n    lib.LoadIcons();\r\n    #endif\r\n\r\n    #ifdef _7ZIP_LARGE_PAGES\r\n    if (g_LargePageSize != 0)\r\n    {\r\n      SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProcAddress(\"SetLargePageMode\");\r\n      if (setLargePageMode != 0)\r\n        setLargePageMode();\r\n    }\r\n    #endif\r\n\r\n    lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress(\"CreateObject\");\r\n    if (lib.CreateObject != 0)\r\n    {\r\n      int startSize = Codecs.Size();\r\n      res = LoadCodecs();\r\n      used = (Codecs.Size() != startSize);\r\n      if (res == S_OK)\r\n      {\r\n        startSize = Formats.Size();\r\n        res = LoadFormats();\r\n        used = used || (Formats.Size() != startSize);\r\n      }\r\n    }\r\n  }\r\n  if (!used)\r\n    Libs.DeleteBack();\r\n  return res;\r\n}\r\n\r\nHRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)\r\n{\r\n  NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT(\"*\")));\r\n  NFile::NFind::CFileInfo fi;\r\n  while (enumerator.Next(fi))\r\n  {\r\n    if (fi.IsDir())\r\n      continue;\r\n    RINOK(LoadDll(folderPrefix + fi.Name));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n#ifndef _SFX\r\nstatic inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)\r\n{\r\n  bb.SetCapacity(size);\r\n  memmove((Byte *)bb, data, size);\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::Load()\r\n{\r\n  Formats.Clear();\r\n  #ifdef EXTERNAL_CODECS\r\n  Codecs.Clear();\r\n  #endif\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n  {\r\n    const CArcInfo &arc = *g_Arcs[i];\r\n    CArcInfoEx item;\r\n    item.Name = arc.Name;\r\n    item.CreateInArchive = arc.CreateInArchive;\r\n    item.CreateOutArchive = arc.CreateOutArchive;\r\n    item.AddExts(arc.Ext, arc.AddExt);\r\n    item.UpdateEnabled = (arc.CreateOutArchive != 0);\r\n    item.KeepName = arc.KeepName;\r\n\r\n    #ifndef _SFX\r\n    SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);\r\n    #endif\r\n    Formats.Add(item);\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();\r\n  RINOK(LoadDll(baseFolder + kMainDll));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nint CCodecs::FindFormatForArchiveName(const UString &arcPath) const\r\n{\r\n  int slashPos1 = arcPath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  int slashPos2 = arcPath.ReverseFind(L'.');\r\n  int dotPos = arcPath.ReverseFind(L'.');\r\n  if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)\r\n    return -1;\r\n  UString ext = arcPath.Mid(dotPos + 1);\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    // if (arc.FindExtension(ext) >= 0)\r\n    UString mainExt = arc.GetMainExt();\r\n    if (!mainExt.IsEmpty() && ext.CompareNoCase(mainExt) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForExtension(const UString &ext) const\r\n{\r\n  if (ext.IsEmpty())\r\n    return -1;\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n    if (Formats[i].FindExtension(ext) >= 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveType(const UString &arcType) const\r\n{\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n    if (Formats[i].Name.CompareNoCase(arcType) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nbool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const\r\n{\r\n  formatIndices.Clear();\r\n  for (int pos = 0; pos < arcType.Length();)\r\n  {\r\n    int pos2 = arcType.Find('.', pos);\r\n    if (pos2 < 0)\r\n      pos2 = arcType.Length();\r\n    const UString name = arcType.Mid(pos, pos2 - pos);\r\n    int index = FindFormatForArchiveType(name);\r\n    if (index < 0 && name != L\"*\")\r\n    {\r\n      formatIndices.Clear();\r\n      return false;\r\n    }\r\n    formatIndices.Add(index);\r\n    pos = pos2 + 1;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\n#ifdef EXPORT_CODECS\r\nextern unsigned int g_NumCodecs;\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);\r\n// STDAPI GetNumberOfMethods(UInt32 *numCodecs);\r\n#endif\r\n\r\nSTDMETHODIMP CCodecs::GetNumberOfMethods(UInt32 *numMethods)\r\n{\r\n  *numMethods =\r\n      #ifdef EXPORT_CODECS\r\n      g_NumCodecs +\r\n      #endif\r\n      Codecs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return GetMethodProperty(index, propID, value);\r\n  #endif\r\n\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n\r\n  if (propID == NMethodPropID::kDecoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.DecoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  if (propID == NMethodPropID::kEncoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.EncoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(false, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.DecoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(true, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.EncoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const\r\n{\r\n  for (int i = 0; i < Codecs.Size(); i++)\r\n  {\r\n    const CDllCodecInfo &codec = Codecs[i];\r\n    if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigned)\r\n      continue;\r\n    const CCodecLib &lib = Libs[codec.LibIndex];\r\n    UString res;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      res = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      continue;\r\n    if (name.CompareNoCase(res) == 0)\r\n      return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICompressCoder, (void **)&coder);\r\n  }\r\n  return CLASS_E_CLASSNOTAVAILABLE;\r\n}\r\n\r\nint CCodecs::GetCodecLibIndex(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return -1;\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.LibIndex;\r\n  #else\r\n  return -1;\r\n  #endif\r\n}\r\n\r\nbool CCodecs::GetCodecEncoderIsAssigned(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n  {\r\n    NWindows::NCOM::CPropVariant prop;\r\n    if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK)\r\n      if (prop.vt != VT_EMPTY)\r\n        return true;\r\n    return false;\r\n  }\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.EncoderIsAssigned;\r\n  #else\r\n  return false;\r\n  #endif\r\n}\r\n\r\nHRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(GetProperty(index, NMethodPropID::kID, &prop));\r\n  if (prop.vt != VT_UI8)\r\n    return E_INVALIDARG;\r\n  id = prop.uhVal.QuadPart;\r\n  return S_OK;\r\n}\r\n\r\nUString CCodecs::GetCodecName(UInt32 index)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK)\r\n    if (prop.vt == VT_BSTR)\r\n      s = prop.bstrVal;\r\n  return s;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/LoadCodecs.h",
    "content": "// LoadCodecs.h\r\n\r\n#ifndef __LOADCODECS_H\r\n#define __LOADCODECS_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/DLL.h\"\r\n#endif\r\n\r\nstruct CDllCodecInfo\r\n{\r\n  CLSID Encoder;\r\n  CLSID Decoder;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  int LibIndex;\r\n  UInt32 CodecIndex;\r\n};\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcExtInfo\r\n{\r\n  UString Ext;\r\n  UString AddExt;\r\n  CArcExtInfo() {}\r\n  CArcExtInfo(const UString &ext): Ext(ext) {}\r\n  CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}\r\n};\r\n\r\n\r\nstruct CArcInfoEx\r\n{\r\n  #ifdef EXTERNAL_CODECS\r\n  int LibIndex;\r\n  UInt32 FormatIndex;\r\n  CLSID ClassID;\r\n  #endif\r\n  bool UpdateEnabled;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n  UString Name;\r\n  CObjectVector<CArcExtInfo> Exts;\r\n  #ifndef _SFX\r\n  CByteBuffer StartSignature;\r\n  // CByteBuffer FinishSignature;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  UStringVector AssociateExts;\r\n  #endif\r\n  #endif\r\n  bool KeepName;\r\n  UString GetMainExt() const\r\n  {\r\n    if (Exts.IsEmpty())\r\n      return UString();\r\n    return Exts[0].Ext;\r\n  }\r\n  int FindExtension(const UString &ext) const\r\n  {\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n      if (ext.CompareNoCase(Exts[i].Ext) == 0)\r\n        return i;\r\n    return -1;\r\n  }\r\n  UString GetAllExtensions() const\r\n  {\r\n    UString s;\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n    {\r\n      if (i > 0)\r\n        s += ' ';\r\n      s += Exts[i].Ext;\r\n    }\r\n    return s;\r\n  }\r\n\r\n  void AddExts(const wchar_t* ext, const wchar_t* addExt);\r\n\r\n  CArcInfoEx():\r\n    #ifdef EXTERNAL_CODECS\r\n    LibIndex(-1),\r\n    #endif\r\n    UpdateEnabled(false),\r\n    CreateInArchive(0), CreateOutArchive(0),\r\n    KeepName(false)\r\n    #ifndef _SFX\r\n    #endif\r\n  {}\r\n};\r\n\r\n#ifdef EXTERNAL_CODECS\r\ntypedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);\r\n\r\n\r\nstruct CCodecLib\r\n{\r\n  NWindows::NDLL::CLibrary Lib;\r\n  GetMethodPropertyFunc GetMethodProperty;\r\n  CreateObjectFunc CreateObject;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  struct CIconPair\r\n  {\r\n    UString Ext;\r\n    UInt32 IconIndex;\r\n  };\r\n  CSysString Path;\r\n  CObjectVector<CIconPair> IconPairs;\r\n  void LoadIcons();\r\n  int FindIconIndex(const UString &ext) const;\r\n  #endif\r\n  CCodecLib(): GetMethodProperty(0) {}\r\n};\r\n#endif\r\n\r\nclass CCodecs:\r\n  #ifdef EXTERNAL_CODECS\r\n  public ICompressCodecsInfo,\r\n  #else\r\n  public IUnknown,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef EXTERNAL_CODECS\r\n  CObjectVector<CCodecLib> Libs;\r\n  CObjectVector<CDllCodecInfo> Codecs;\r\n  HRESULT LoadCodecs();\r\n  HRESULT LoadFormats();\r\n  HRESULT LoadDll(const CSysString &path);\r\n  HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);\r\n\r\n  HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const\r\n  {\r\n    return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);\r\n  }\r\n  #endif\r\n\r\npublic:\r\n  CObjectVector<CArcInfoEx> Formats;\r\n  HRESULT Load();\r\n  \r\n  #ifndef _SFX\r\n  int FindFormatForArchiveName(const UString &arcPath) const;\r\n  int FindFormatForExtension(const UString &ext) const;\r\n  int FindFormatForArchiveType(const UString &arcType) const;\r\n  bool FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const;\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder);\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder);\r\n  #endif\r\n\r\n  int GetCodecLibIndex(UInt32 index);\r\n  bool GetCodecEncoderIsAssigned(UInt32 index);\r\n  HRESULT GetCodecId(UInt32 index, UInt64 &id);\r\n  UString GetCodecName(UInt32 index);\r\n\r\n  HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const\r\n  {\r\n    const CArcInfoEx &ai = Formats[formatIndex];\r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateInArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, false);\r\n    #endif\r\n  }\r\n  HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const\r\n  {\r\n    const CArcInfoEx &ai = Formats[formatIndex];\r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateOutArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, true);\r\n    #endif\r\n  }\r\n  int FindOutFormatFromName(const UString &name) const\r\n  {\r\n    for (int i = 0; i < Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = Formats[i];\r\n      if (!arc.UpdateEnabled)\r\n        continue;\r\n      if (arc.Name.CompareNoCase(name) == 0)\r\n        return i;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;\r\n  #endif\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/OpenArchive.cpp",
    "content": "// OpenArchive.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidPath, &prop));\r\n  if(prop.vt == VT_BSTR)\r\n    result = prop.bstrVal;\r\n  else if (prop.vt == VT_EMPTY)\r\n    result.Empty();\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result)\r\n{\r\n  RINOK(GetArchiveItemPath(archive, index, result));\r\n  if (result.IsEmpty())\r\n  {\r\n    result = defaultName;\r\n    NCOM::CPropVariant prop;\r\n    RINOK(archive->GetProperty(index, kpidExtension, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n    {\r\n      result += L'.';\r\n      result += prop.bstrVal;\r\n    }\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\r\n    const FILETIME &defaultFileTime, FILETIME &fileTime)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidMTime, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n    fileTime = prop.filetime;\r\n  else if (prop.vt == VT_EMPTY)\r\n    fileTime = defaultFileTime;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\r\n}\r\n\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsAnti, result);\r\n}\r\n\r\n// Static-SFX (for Linux) can be big.\r\nconst UInt64 kMaxCheckStartPosition = 1 << 22;\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  inStreamSpec->Open(fileName);\r\n  return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n}\r\n\r\n#ifndef _SFX\r\nstatic inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)\r\n{\r\n  for (size_t i = 0; i < size; i++)\r\n    if (p1[i] != p2[i])\r\n      return false;\r\n  return true;\r\n}\r\n#endif\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    IInStream *inStream,\r\n    const UString &fileName,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  *archiveResult = NULL;\r\n  UString extension;\r\n  {\r\n    int dotPos = fileName.ReverseFind(L'.');\r\n    if (dotPos >= 0)\r\n      extension = fileName.Mid(dotPos + 1);\r\n  }\r\n  CIntVector orderIndices;\r\n  if (arcTypeIndex >= 0)\r\n    orderIndices.Add(arcTypeIndex);\r\n  else\r\n  {\r\n\r\n  int i;\r\n  int numFinded = 0;\r\n  for (i = 0; i < codecs->Formats.Size(); i++)\r\n    if (codecs->Formats[i].FindExtension(extension) >= 0)\r\n      orderIndices.Insert(numFinded++, i);\r\n    else\r\n      orderIndices.Add(i);\r\n  \r\n  #ifndef _SFX\r\n  if (numFinded != 1)\r\n  {\r\n    CIntVector orderIndices2;\r\n    CByteBuffer byteBuffer;\r\n    const size_t kBufferSize = (1 << 21);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    size_t processedSize = kBufferSize;\r\n    RINOK(ReadStream(inStream, byteBuffer, &processedSize));\r\n    if (processedSize == 0)\r\n      return S_FALSE;\r\n\r\n    const Byte *buf = byteBuffer;\r\n    Byte hash[1 << 16];\r\n    memset(hash, 0xFF, 1 << 16);\r\n    Byte prevs[256];\r\n    if (orderIndices.Size() > 255)\r\n      return S_FALSE;\r\n    int i;\r\n    for (i = 0; i < orderIndices.Size(); i++)\r\n    {\r\n      const CArcInfoEx &ai = codecs->Formats[orderIndices[i]];\r\n      const CByteBuffer &sig = ai.StartSignature;\r\n      if (sig.GetCapacity() < 2)\r\n        continue;\r\n      UInt32 v = sig[0] | ((UInt32)sig[1] << 8);\r\n      prevs[i] = hash[v];\r\n      hash[v] = (Byte)i;\r\n    }\r\n\r\n    processedSize--;\r\n    for (UInt32 pos = 0; pos < processedSize; pos++)\r\n    {\r\n      for (; pos < processedSize && hash[buf[pos] | ((UInt32)buf[pos + 1] << 8)] == 0xFF; pos++);\r\n      if (pos == processedSize)\r\n        break;\r\n      UInt32 v = buf[pos] | ((UInt32)buf[pos + 1] << 8);\r\n      Byte *ptr = &hash[v];\r\n      int i = *ptr;\r\n      do\r\n      {\r\n        int index = orderIndices[i];\r\n        const CArcInfoEx &ai = codecs->Formats[index];\r\n        const CByteBuffer &sig = ai.StartSignature;\r\n        if (sig.GetCapacity() != 0 && pos + sig.GetCapacity() <= processedSize + 1)\r\n          if (TestSignature(buf + pos, sig, sig.GetCapacity()))\r\n          {\r\n            orderIndices2.Add(index);\r\n            orderIndices[i] = 0xFF;\r\n            *ptr = prevs[i];\r\n          }\r\n        ptr = &prevs[i];\r\n        i = *ptr;\r\n      }\r\n      while (i != 0xFF);\r\n    }\r\n    \r\n    for (i = 0; i < orderIndices.Size(); i++)\r\n    {\r\n      int val = orderIndices[i];\r\n      if (val != 0xFF)\r\n        orderIndices2.Add(val);\r\n    }\r\n    orderIndices = orderIndices2;\r\n\r\n    if (orderIndices.Size() >= 2)\r\n    {\r\n      int isoIndex = codecs->FindFormatForArchiveType(L\"iso\");\r\n      int udfIndex = codecs->FindFormatForArchiveType(L\"udf\");\r\n      int iIso = -1;\r\n      int iUdf = -1;\r\n      for (int i = 0; i < orderIndices.Size(); i++)\r\n      {\r\n        if (orderIndices[i] == isoIndex) iIso = i;\r\n        if (orderIndices[i] == udfIndex) iUdf = i;\r\n      }\r\n      if (iUdf == iIso + 1)\r\n      {\r\n        orderIndices[iUdf] = isoIndex;\r\n        orderIndices[iIso] = udfIndex;\r\n      }\r\n    }\r\n  }\r\n  else if (extension == L\"000\" || extension == L\"001\")\r\n  {\r\n    CByteBuffer byteBuffer;\r\n    const size_t kBufferSize = (1 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    size_t processedSize = kBufferSize;\r\n    RINOK(ReadStream(inStream, buffer, &processedSize));\r\n    if (processedSize >= 16)\r\n    {\r\n      Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};\r\n      if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] & 1) != 0)\r\n      {\r\n        for (int i = 0; i < orderIndices.Size(); i++)\r\n        {\r\n          int index = orderIndices[i];\r\n          const CArcInfoEx &ai = codecs->Formats[index];\r\n          if (ai.Name.CompareNoCase(L\"rar\") != 0)\r\n            continue;\r\n          orderIndices.Delete(i--);\r\n          orderIndices.Insert(0, index);\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n  }\r\n\r\n  for(int i = 0; i < orderIndices.Size(); i++)\r\n  {\r\n    inStream->Seek(0, STREAM_SEEK_SET, NULL);\r\n\r\n    CMyComPtr<IInArchive> archive;\r\n\r\n    formatIndex = orderIndices[i];\r\n    RINOK(codecs->CreateInArchive(formatIndex, archive));\r\n    if (!archive)\r\n      continue;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    HRESULT result = archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n    if (result == S_FALSE)\r\n      continue;\r\n    RINOK(result);\r\n    *archiveResult = archive.Detach();\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex];\r\n    if (format.Exts.Size() == 0)\r\n    {\r\n      defaultItemName = GetDefaultName2(fileName, L\"\", L\"\");\r\n    }\r\n    else\r\n    {\r\n      int subExtIndex = format.FindExtension(extension);\r\n      if (subExtIndex < 0)\r\n        subExtIndex = 0;\r\n      defaultItemName = GetDefaultName2(fileName,\r\n          format.Exts[subExtIndex].Ext,\r\n          format.Exts[subExtIndex].AddExt);\r\n    }\r\n    return S_OK;\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &filePath,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  if (!inStreamSpec->Open(filePath))\r\n    return GetLastError();\r\n  return OpenArchive(codecs, arcTypeIndex, inStream, ExtractFileNameFromPath(filePath),\r\n    archiveResult, formatIndex,\r\n    defaultItemName, openArchiveCallback);\r\n}\r\n\r\nstatic void MakeDefaultName(UString &name)\r\n{\r\n  int dotPos = name.ReverseFind(L'.');\r\n  if (dotPos < 0)\r\n    return;\r\n  UString ext = name.Mid(dotPos + 1);\r\n  if (ext.IsEmpty())\r\n    return;\r\n  for (int pos = 0; pos < ext.Length(); pos++)\r\n    if (ext[pos] < L'0' || ext[pos] > L'9')\r\n      return;\r\n  name = name.Left(dotPos);\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &fileName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  if (formatIndices.Size() >= 3)\r\n    return E_NOTIMPL;\r\n  \r\n  int arcTypeIndex = -1;\r\n  if (formatIndices.Size() >= 1)\r\n    arcTypeIndex = formatIndices[formatIndices.Size() - 1];\r\n  \r\n  HRESULT result = OpenArchive(codecs, arcTypeIndex, fileName,\r\n    archive0, formatIndex0, defaultItemName0, openArchiveCallback);\r\n  RINOK(result);\r\n\r\n  if (formatIndices.Size() == 1)\r\n    return S_OK;\r\n  arcTypeIndex = -1;\r\n  if (formatIndices.Size() >= 2)\r\n    arcTypeIndex = formatIndices[formatIndices.Size() - 2];\r\n\r\n  HRESULT resSpec = (formatIndices.Size() == 0 ? S_OK : E_NOTIMPL);\r\n\r\n  CMyComPtr<IInArchiveGetStream> getStream;\r\n  result = (*archive0)->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream);\r\n  if (result != S_OK || !getStream)\r\n    return resSpec;\r\n\r\n  CMyComPtr<ISequentialInStream> subSeqStream;\r\n  result = getStream->GetStream(0, &subSeqStream);\r\n  if (result != S_OK || !subSeqStream)\r\n    return resSpec;\r\n\r\n  CMyComPtr<IInStream> subStream;\r\n  result = subSeqStream.QueryInterface(IID_IInStream, &subStream);\r\n  if (result != S_OK || !subStream)\r\n    return resSpec;\r\n\r\n  UInt32 numItems;\r\n  RINOK((*archive0)->GetNumberOfItems(&numItems));\r\n  if (numItems < 1)\r\n    return resSpec;\r\n\r\n  UString subPath;\r\n  RINOK(GetArchiveItemPath(*archive0, 0, subPath))\r\n  if (subPath.IsEmpty())\r\n  {\r\n    MakeDefaultName(defaultItemName0);\r\n    subPath = defaultItemName0;\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex0];\r\n    if (format.Name.CompareNoCase(L\"7z\") == 0)\r\n    {\r\n      if (subPath.Right(3).CompareNoCase(L\".7z\") != 0)\r\n        subPath += L\".7z\";\r\n    }\r\n  }\r\n  else\r\n    subPath = ExtractFileNameFromPath(subPath);\r\n\r\n  CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;\r\n  openArchiveCallback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);\r\n  if (setSubArchiveName)\r\n    setSubArchiveName->SetSubArchiveName(subPath);\r\n\r\n  result = OpenArchive(codecs, arcTypeIndex, subStream, subPath,\r\n      archive1, formatIndex1, defaultItemName1, openArchiveCallback);\r\n  resSpec = (formatIndices.Size() == 0 ? S_OK : S_FALSE);\r\n  if (result != S_OK)\r\n    return resSpec;\r\n  return S_OK;\r\n}\r\n\r\nstatic void SetCallback(const UString &archiveName,\r\n    IOpenCallbackUI *openCallbackUI,\r\n    IArchiveOpenCallback *reOpenCallback,\r\n    CMyComPtr<IArchiveOpenCallback> &openCallback)\r\n{\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n  openCallbackSpec->ReOpenCallback = reOpenCallback;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  openCallbackSpec->Init(\r\n      fullName.Left(fileNamePartStartIndex),\r\n      fullName.Mid(fileNamePartStartIndex));\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &archiveName,\r\n    IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI)\r\n{\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(archiveName, openCallbackUI, NULL, openCallback);\r\n  int formatInfo;\r\n  return OpenArchive(codecs, arcTypeIndex, archiveName, archive, formatInfo, defaultItemName, openCallback);\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  volumesSize = 0;\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  UString prefix = fullName.Left(fileNamePartStartIndex);\r\n  UString name = fullName.Mid(fileNamePartStartIndex);\r\n  openCallbackSpec->Init(prefix, name);\r\n\r\n  int formatIndex0, formatIndex1;\r\n  RINOK(OpenArchive(codecs, formatIndices, archiveName,\r\n      archive0,\r\n      archive1,\r\n      formatIndex0,\r\n      formatIndex1,\r\n      defaultItemName0,\r\n      defaultItemName1,\r\n      openCallback));\r\n  volumePaths.Add(prefix + name);\r\n  for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)\r\n    volumePaths.Add(prefix + openCallbackSpec->FileNames[i]);\r\n  volumesSize = openCallbackSpec->TotalSize;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveLink::Close()\r\n{\r\n  if (Archive1 != 0)\r\n    RINOK(Archive1->Close());\r\n  if (Archive0 != 0)\r\n    RINOK(Archive0->Close());\r\n  IsOpen = false;\r\n  return S_OK;\r\n}\r\n\r\nvoid CArchiveLink::Release()\r\n{\r\n  IsOpen = false;\r\n  Archive1.Release();\r\n  Archive0.Release();\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  HRESULT res = OpenArchive(codecs, formatIndices, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1,\r\n    archiveLink.FormatIndex0, archiveLink.FormatIndex1,\r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\r\n    openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT MyOpenArchive(CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  HRESULT res = MyOpenArchive(codecs, formatIndices, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1,\r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\r\n    archiveLink.VolumePaths,\r\n    archiveLink.VolumesSize,\r\n    openCallbackUI);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT ReOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, const UString &fileName,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  if (archiveLink.GetNumLevels() > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (archiveLink.GetNumLevels() == 0)\r\n    return MyOpenArchive(codecs, CIntVector(), fileName, archiveLink, 0);\r\n\r\n  CMyComPtr<IArchiveOpenCallback> openCallbackNew;\r\n  SetCallback(fileName, NULL, openCallback, openCallbackNew);\r\n\r\n  HRESULT res = ReOpenArchive(archiveLink.GetArchive(), fileName, openCallbackNew);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/OpenArchive.h",
    "content": "// OpenArchive.h\r\n\r\n#ifndef __OPENARCHIVE_H\r\n#define __OPENARCHIVE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"LoadCodecs.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result);\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result);\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\r\n    const FILETIME &defaultFileTime, FILETIME &fileTime);\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result);\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result);\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result);\r\n\r\nstruct ISetSubArchiveName\r\n{\r\n  virtual void SetSubArchiveName(const wchar_t *name) = 0;\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    IInStream *inStream,\r\n    const UString &fileName,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &filePath,\r\n    IInArchive **archive,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &filePath,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback);\r\n\r\nstruct CArchiveLink\r\n{\r\n  CMyComPtr<IInArchive> Archive0;\r\n  CMyComPtr<IInArchive> Archive1;\r\n  UString DefaultItemName0;\r\n  UString DefaultItemName1;\r\n\r\n  int FormatIndex0;\r\n  int FormatIndex1;\r\n  \r\n  UStringVector VolumePaths;\r\n\r\n  bool IsOpen;\r\n  UInt64 VolumesSize;\r\n\r\n  int GetNumLevels() const\r\n  {\r\n    int result = 0;\r\n    if (Archive0)\r\n    {\r\n      result++;\r\n      if (Archive1)\r\n        result++;\r\n    }\r\n    return result;\r\n  }\r\n\r\n  CArchiveLink(): IsOpen(false), VolumesSize(0) {};\r\n\r\n  IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; }\r\n  UString GetDefaultItemName()  { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; }\r\n  int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; }\r\n  HRESULT Close();\r\n  void Release();\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT ReOpenArchive(\r\n    CCodecs *codecs,\r\n    CArchiveLink &archiveLink,\r\n    const UString &fileName,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/PropIDUtils.cpp",
    "content": "// PropIDUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropIDUtils.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../PropID.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic void ConvertUInt32ToHex(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    int t = value & 0xF;\r\n    value >>= 4;\r\n    s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));\r\n  }\r\n  s[8] = L'\\0';\r\n}\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full)\r\n{\r\n  switch(propID)\r\n  {\r\n    case kpidCTime:\r\n    case kpidATime:\r\n    case kpidMTime:\r\n    {\r\n      if (propVariant.vt != VT_FILETIME)\r\n        return UString(); // It is error;\r\n      FILETIME localFileTime;\r\n      if (propVariant.filetime.dwHighDateTime == 0 &&\r\n          propVariant.filetime.dwLowDateTime == 0)\r\n        return UString();\r\n      if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n        return UString(); // It is error;\r\n      return ConvertFileTimeToString(localFileTime, true, full);\r\n    }\r\n    case kpidCRC:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      wchar_t temp[12];\r\n      ConvertUInt32ToHex(propVariant.ulVal, temp);\r\n      return temp;\r\n    }\r\n    case kpidAttrib:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UString result;\r\n      UInt32 attributes = propVariant.ulVal;\r\n      if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';\r\n      if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';\r\n      if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';\r\n      if (NFile::NFind::NAttributes::IsDir(attributes)) result += L'D';\r\n      if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';\r\n      if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';\r\n      if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';\r\n      return result;\r\n    }\r\n    case kpidDictionarySize:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UInt32 size = propVariant.ulVal;\r\n      if (size % (1 << 20) == 0)\r\n        return ConvertUInt32ToString(size >> 20) + L\"MB\";\r\n      if (size % (1 << 10) == 0)\r\n        return ConvertUInt32ToString(size >> 10) + L\"KB\";\r\n      return ConvertUInt32ToString(size);\r\n    }\r\n  }\r\n  return ConvertPropVariantToString(propVariant);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/PropIDUtils.h",
    "content": "// PropIDUtils.h\r\n\r\n#ifndef __PROPIDUTILS_H\r\n#define __PROPIDUTILS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/Property.h",
    "content": "// Property.h\r\n\r\n#ifndef __PROPERTY_H\r\n#define __PROPERTY_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nstruct CProperty\r\n{\r\n  UString Name;\r\n  UString Value;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/SetProperties.cpp",
    "content": "// SetProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SetProperties.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\n\r\nstatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)\r\n{\r\n  const wchar_t *endPtr;\r\n  UInt64 result = ConvertStringToUInt64(s, &endPtr);\r\n  if (endPtr - (const wchar_t *)s != s.Length())\r\n    prop = s;\r\n  else if (result <= 0xFFFFFFFF)\r\n    prop = (UInt32)result;\r\n  else\r\n    prop = result;\r\n}\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)\r\n{\r\n  if (properties.IsEmpty())\r\n    return S_OK;\r\n  CMyComPtr<ISetProperties> setProperties;\r\n  unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);\r\n  if (!setProperties)\r\n    return S_OK;\r\n\r\n  UStringVector realNames;\r\n  CPropVariant *values = new CPropVariant[properties.Size()];\r\n  try\r\n  {\r\n    int i;\r\n    for(i = 0; i < properties.Size(); i++)\r\n    {\r\n      const CProperty &property = properties[i];\r\n      NCOM::CPropVariant propVariant;\r\n      UString name = property.Name;\r\n      if (property.Value.IsEmpty())\r\n      {\r\n        if (!name.IsEmpty())\r\n        {\r\n          wchar_t c = name[name.Length() - 1];\r\n          if (c == L'-')\r\n            propVariant = false;\r\n          else if (c == L'+')\r\n            propVariant = true;\r\n          if (propVariant.vt != VT_EMPTY)\r\n            name = name.Left(name.Length() - 1);\r\n        }\r\n      }\r\n      else\r\n        ParseNumberString(property.Value, propVariant);\r\n      realNames.Add(name);\r\n      values[i] = propVariant;\r\n    }\r\n    CRecordVector<const wchar_t *> names;\r\n    for(i = 0; i < realNames.Size(); i++)\r\n      names.Add((const wchar_t *)realNames[i]);\r\n    \r\n    RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));\r\n  }\r\n  catch(...)\r\n  {\r\n    delete []values;\r\n    throw;\r\n  }\r\n  delete []values;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/SetProperties.h",
    "content": "// SetProperties.h\r\n\r\n#ifndef __SETPROPERTIES_H\r\n#define __SETPROPERTIES_H\r\n\r\n#include \"Property.h\"\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/SortUtils.cpp",
    "content": "// SortUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SortUtils.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nstatic int CompareStrings(const int *p1, const int *p2, void *param)\r\n{\r\n  const UStringVector &strings = *(const UStringVector *)param;\r\n  return CompareFileNames(strings[*p1], strings[*p2]);\r\n}\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numItems = strings.Size();\r\n  indices.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n    indices.Add(i);\r\n  indices.Sort(CompareStrings, (void *)&strings);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/SortUtils.h",
    "content": "// SortUtils.h\r\n\r\n#ifndef __SORTUTLS_H\r\n#define __SORTUTLS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/StdAfx.h",
    "content": "// stdafx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/TempFiles.cpp",
    "content": "// TempFiles.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"TempFiles.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileIO.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nvoid CTempFiles::Clear()\r\n{\r\n  while(!Paths.IsEmpty())\r\n  {\r\n    NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());\r\n    Paths.DeleteBack();\r\n  }\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/TempFiles.h",
    "content": "// TempFiles.h\r\n\r\n#ifndef __TEMPFILES_H\r\n#define __TEMPFILES_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nclass CTempFiles\r\n{\r\n  void Clear();\r\npublic:\r\n  UStringVector Paths;\r\n  ~CTempFiles() { Clear(); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/Update.cpp",
    "content": "// Update.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Update.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/DLL.h\"\r\n#endif\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/DirItem.h\"\r\n#include \"../Common/EnumDirItems.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n#include \"SetProperties.h\"\r\n#include \"TempFiles.h\"\r\n#include \"UpdateCallback.h\"\r\n\r\nstatic const char *kUpdateIsNotSupoorted =\r\n  \"update operations are not supported for this archive\";\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nstatic const wchar_t *kTempFolderPrefix = L\"7zE\";\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)\r\n{\r\n  CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;\r\n  return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);\r\n}\r\n\r\nclass COutMultiVolStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    COutFileStream *StreamSpec;\r\n    CMyComPtr<IOutStream> Stream;\r\n    UString Name;\r\n    UInt64 Pos;\r\n    UInt64 RealSize;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  // CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  CRecordVector<UInt64> Sizes;\r\n  UString Prefix;\r\n  CTempFiles *TempFiles;\r\n\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  HRESULT Close();\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n// static NSynchronization::CCriticalSection g_TempPathsCS;\r\n\r\nHRESULT COutMultiVolStream::Close()\r\n{\r\n  HRESULT res = S_OK;\r\n  for (int i = 0; i < Streams.Size(); i++)\r\n  {\r\n    CSubStreamInfo &s = Streams[i];\r\n    if (s.StreamSpec)\r\n    {\r\n      HRESULT res2 = s.StreamSpec->Close();\r\n      if (res2 != S_OK)\r\n        res = res2;\r\n    }\r\n  }\r\n  return res;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n\r\n      wchar_t temp[32];\r\n      ConvertUInt64ToString(_streamIndex + 1, temp);\r\n      UString res = temp;\r\n      while (res.Length() < 3)\r\n        res = UString(L'0') + res;\r\n      UString name = Prefix + res;\r\n      subStream.StreamSpec = new COutFileStream;\r\n      subStream.Stream = subStream.StreamSpec;\r\n      if(!subStream.StreamSpec->Create(name, false))\r\n        return ::GetLastError();\r\n      {\r\n        // NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);\r\n        TempFiles->Paths.Add(name);\r\n      }\r\n\r\n      subStream.Pos = 0;\r\n      subStream.RealSize = 0;\r\n      subStream.Name = name;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n\r\n    int index = _streamIndex;\r\n    if (index >= Sizes.Size())\r\n      index = Sizes.Size() - 1;\r\n    UInt64 volSize = Sizes[index];\r\n\r\n    if (_offsetPos >= volSize)\r\n    {\r\n      _offsetPos -= volSize;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      // CMyComPtr<IOutStream> outStream;\r\n      // RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(subStream.Stream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, volSize - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if (_offsetPos > subStream.RealSize)\r\n      subStream.RealSize = _offsetPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == volSize)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed == 0 && curSize != 0)\r\n      return E_FAIL;\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  if (newPosition != NULL)\r\n    *newPosition = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::SetSize(Int64 newSize)\r\n{\r\n  if (newSize < 0)\r\n    return E_INVALIDARG;\r\n  int i = 0;\r\n  while (i < Streams.Size())\r\n  {\r\n    CSubStreamInfo &subStream = Streams[i++];\r\n    if ((UInt64)newSize < subStream.RealSize)\r\n    {\r\n      RINOK(subStream.Stream->SetSize(newSize));\r\n      subStream.RealSize = newSize;\r\n      break;\r\n    }\r\n    newSize -= subStream.RealSize;\r\n  }\r\n  while (i < Streams.Size())\r\n  {\r\n    {\r\n      CSubStreamInfo &subStream = Streams.Back();\r\n      subStream.Stream.Release();\r\n      NDirectory::DeleteFileAlways(subStream.Name);\r\n    }\r\n    Streams.DeleteBack();\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  _length = newSize;\r\n  return S_OK;\r\n}\r\n\r\nstatic const wchar_t *kDefaultArchiveType = L\"7z\";\r\nstatic const wchar_t *kSFXExtension =\r\n  #ifdef _WIN32\r\n    L\"exe\";\r\n  #else\r\n    L\"\";\r\n  #endif\r\n\r\nbool CUpdateOptions::Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath)\r\n{\r\n  if (formatIndices.Size() > 1)\r\n    return false;\r\n  int arcTypeIndex = -1;\r\n  if (formatIndices.Size() != 0)\r\n    arcTypeIndex = formatIndices[0];\r\n  if (arcTypeIndex >= 0)\r\n    MethodMode.FormatIndex = arcTypeIndex;\r\n  else\r\n  {\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveName(arcPath);\r\n    if (MethodMode.FormatIndex < 0)\r\n      MethodMode.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArchiveType);\r\n  }\r\n  if (MethodMode.FormatIndex < 0)\r\n    return false;\r\n  const CArcInfoEx &arcInfo = codecs->Formats[MethodMode.FormatIndex];\r\n  if (!arcInfo.UpdateEnabled)\r\n    return false;\r\n  UString typeExt = arcInfo.GetMainExt();\r\n  UString ext = typeExt;\r\n  if (SfxMode)\r\n    ext = kSFXExtension;\r\n  ArchivePath.BaseExtension = ext;\r\n  ArchivePath.VolExtension = typeExt;\r\n  ArchivePath.ParseFromPath(arcPath);\r\n  for (int i = 0; i < Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &uc = Commands[i];\r\n    uc.ArchivePath.BaseExtension = ext;\r\n    uc.ArchivePath.VolExtension = typeExt;\r\n    uc.ArchivePath.ParseFromPath(uc.UserArchivePath);\r\n  }\r\n  return true;\r\n}\r\n\r\n/*\r\nstruct CUpdateProduceCallbackImp: public IUpdateProduceCallback\r\n{\r\n  const CObjectVector<CArcItem> *_arcItems;\r\n  IUpdateCallbackUI *_callback;\r\n  \r\n  CUpdateProduceCallbackImp(const CObjectVector<CArcItem> *a, \r\n      IUpdateCallbackUI *callback): _arcItems(a), _callback(callback) {}\r\n  virtual HRESULT ShowDeleteFile(int arcIndex);\r\n};\r\n\r\nHRESULT CUpdateProduceCallbackImp::ShowDeleteFile(int arcIndex)\r\n{\r\n  return _callback->ShowDeleteFile((*_arcItems)[arcIndex].Name);\r\n}\r\n*/\r\n\r\nstatic HRESULT Compress(\r\n    CCodecs *codecs,\r\n    const CActionSet &actionSet,\r\n    IInArchive *archive,\r\n    const CCompressionMethodMode &compressionMethod,\r\n    CArchivePath &archivePath,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    bool shareForWrite,\r\n    bool stdInMode,\r\n    /* const UString & stdInFileName, */\r\n    bool stdOutMode,\r\n    const CDirItems &dirItems,\r\n    bool sfxMode,\r\n    const UString &sfxModule,\r\n    const CRecordVector<UInt64> &volumesSizes,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI *callback)\r\n{\r\n  CMyComPtr<IOutArchive> outArchive;\r\n  if(archive != NULL)\r\n  {\r\n    CMyComPtr<IInArchive> archive2 = archive;\r\n    HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);\r\n    if(result != S_OK)\r\n      throw kUpdateIsNotSupoorted;\r\n  }\r\n  else\r\n  {\r\n    RINOK(codecs->CreateOutArchive(compressionMethod.FormatIndex, outArchive));\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n  }\r\n  if (outArchive == 0)\r\n    throw kUpdateIsNotSupoorted;\r\n  \r\n  NFileTimeType::EEnum fileTimeType;\r\n  UInt32 value;\r\n  RINOK(outArchive->GetFileTimeType(&value));\r\n\r\n  switch(value)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n    case NFileTimeType::kUnix:\r\n    case NFileTimeType::kDOS:\r\n      fileTimeType = (NFileTimeType::EEnum)value;\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n\r\n  CRecordVector<CUpdatePair2> updatePairs2;\r\n\r\n  {\r\n    CRecordVector<CUpdatePair> updatePairs;\r\n    GetUpdatePairInfoList(dirItems, arcItems, fileTimeType, updatePairs); // must be done only once!!!\r\n    // CUpdateProduceCallbackImp upCallback(&arcItems, callback);\r\n    UpdateProduce(updatePairs, actionSet, updatePairs2, NULL /* &upCallback */);\r\n  }\r\n\r\n  UInt32 numFiles = 0;\r\n  for (int i = 0; i < updatePairs2.Size(); i++)\r\n    if (updatePairs2[i].NewData)\r\n      numFiles++;\r\n  \r\n  RINOK(callback->SetNumFiles(numFiles));\r\n\r\n  \r\n  CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n  CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);\r\n  \r\n  updateCallbackSpec->ShareForWrite = shareForWrite;\r\n  updateCallbackSpec->StdInMode = stdInMode;\r\n  updateCallbackSpec->Callback = callback;\r\n  updateCallbackSpec->DirItems = &dirItems;\r\n  updateCallbackSpec->ArcItems = &arcItems;\r\n  updateCallbackSpec->UpdatePairs = &updatePairs2;\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n\r\n  const UString &archiveName = archivePath.GetFinalPath();\r\n  if (!stdOutMode)\r\n  {\r\n    UString resultPath;\r\n    int pos;\r\n    if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))\r\n      throw 1417161;\r\n    NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));\r\n  }\r\n\r\n  COutFileStream *outStreamSpec = NULL;\r\n  COutMultiVolStream *volStreamSpec = NULL;\r\n\r\n  if (volumesSizes.Size() == 0)\r\n  {\r\n    if (stdOutMode)\r\n      outStream = new CStdOutFileStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      outStream = outStreamSpec;\r\n      bool isOK = false;\r\n      UString realPath;\r\n      for (int i = 0; i < (1 << 16); i++)\r\n      {\r\n        if (archivePath.Temp)\r\n        {\r\n          if (i > 0)\r\n          {\r\n            wchar_t s[32];\r\n            ConvertUInt64ToString(i, s);\r\n            archivePath.TempPostfix = s;\r\n          }\r\n          realPath = archivePath.GetTempPath();\r\n        }\r\n        else\r\n          realPath = archivePath.GetFinalPath();\r\n        if (outStreamSpec->Create(realPath, false))\r\n        {\r\n          tempFiles.Paths.Add(realPath);\r\n          isOK = true;\r\n          break;\r\n        }\r\n        if (::GetLastError() != ERROR_FILE_EXISTS)\r\n          break;\r\n        if (!archivePath.Temp)\r\n          break;\r\n      }\r\n      if (!isOK)\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (stdOutMode)\r\n      return E_FAIL;\r\n    volStreamSpec = new COutMultiVolStream;\r\n    outStream = volStreamSpec;\r\n    volStreamSpec->Sizes = volumesSizes;\r\n    volStreamSpec->Prefix = archivePath.GetFinalPath() + UString(L\".\");\r\n    volStreamSpec->TempFiles = &tempFiles;\r\n    volStreamSpec->Init();\r\n\r\n    /*\r\n    updateCallbackSpec->VolumesSizes = volumesSizes;\r\n    updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;\r\n    if (!archivePath.VolExtension.IsEmpty())\r\n      updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;\r\n    */\r\n  }\r\n\r\n  RINOK(SetProperties(outArchive, compressionMethod.Properties));\r\n\r\n  if (sfxMode)\r\n  {\r\n    CInFileStream *sfxStreamSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> sfxStream(sfxStreamSpec);\r\n    if (!sfxStreamSpec->Open(sfxModule))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"Can't open sfx module\";\r\n      errorInfo.FileName = sfxModule;\r\n      return E_FAIL;\r\n    }\r\n\r\n    CMyComPtr<ISequentialOutStream> sfxOutStream;\r\n    COutFileStream *outStreamSpec = NULL;\r\n    if (volumesSizes.Size() == 0)\r\n      sfxOutStream = outStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      sfxOutStream = outStreamSpec;\r\n      UString realPath = archivePath.GetFinalPath();\r\n      if (!outStreamSpec->Create(realPath, false))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    RINOK(CopyBlock(sfxStream, sfxOutStream));\r\n    if (outStreamSpec)\r\n    {\r\n      RINOK(outStreamSpec->Close());\r\n    }\r\n  }\r\n\r\n  HRESULT result = outArchive->UpdateItems(outStream, updatePairs2.Size(), updateCallback);\r\n  callback->Finilize();\r\n  RINOK(result);\r\n  if (outStreamSpec)\r\n    result = outStreamSpec->Close();\r\n  else if (volStreamSpec)\r\n    result = volStreamSpec->Close();\r\n  return result;\r\n}\r\n\r\nHRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,\r\n    IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    CObjectVector<CArcItem> &arcItems)\r\n{\r\n  arcItems.Clear();\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n  arcItems.Reserve(numItems);\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    CArcItem ai;\r\n\r\n    RINOK(GetArchiveItemPath(archive, i, ai.Name));\r\n    // check it: defaultItemName !!!\r\n    if (ai.Name.IsEmpty())\r\n      ai.Name = defaultItemName;\r\n    RINOK(IsArchiveItemFolder(archive, i, ai.IsDir));\r\n    ai.Censored = censor.CheckPath(ai.Name, !ai.IsDir);\r\n    RINOK(GetArchiveItemFileTime(archive, i, archiveFileInfo.MTime, ai.MTime));\r\n\r\n    {\r\n      CPropVariant prop;\r\n      RINOK(archive->GetProperty(i, kpidSize, &prop));\r\n      ai.SizeDefined = (prop.vt != VT_EMPTY);\r\n      if (ai.SizeDefined)\r\n        ai.Size = ConvertPropVariantToUInt64(prop);\r\n    }\r\n\r\n    {\r\n      CPropVariant prop;\r\n      RINOK(archive->GetProperty(i, kpidTimeType, &prop));\r\n      if (prop.vt == VT_UI4)\r\n      {\r\n        ai.TimeType = (int)(NFileTimeType::EEnum)prop.ulVal;\r\n        switch(ai.TimeType)\r\n        {\r\n          case NFileTimeType::kWindows:\r\n          case NFileTimeType::kUnix:\r\n          case NFileTimeType::kDOS:\r\n            break;\r\n          default:\r\n            return E_FAIL;\r\n        }\r\n      }\r\n    }\r\n\r\n    ai.IndexInServer = i;\r\n    arcItems.Add(ai);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nstatic HRESULT UpdateWithItemLists(\r\n    CCodecs *codecs,\r\n    CUpdateOptions &options,\r\n    IInArchive *archive,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    CDirItems &dirItems,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &command = options.Commands[i];\r\n    if (options.StdOutMode)\r\n    {\r\n      RINOK(callback->StartArchive(0, archive != 0));\r\n    }\r\n    else\r\n    {\r\n      RINOK(callback->StartArchive(command.ArchivePath.GetFinalPath(),\r\n          i == 0 && options.UpdateArchiveItself && archive != 0));\r\n    }\r\n\r\n    RINOK(Compress(\r\n        codecs,\r\n        command.ActionSet, archive,\r\n        options.MethodMode,\r\n        command.ArchivePath,\r\n        arcItems,\r\n        options.OpenShareForWrite,\r\n        options.StdInMode,\r\n        /* options.StdInFileName, */\r\n        options.StdOutMode,\r\n        dirItems,\r\n        options.SfxMode, options.SfxModule,\r\n        options.VolumesSizes,\r\n        tempFiles,\r\n        errorInfo, callback));\r\n\r\n    RINOK(callback->FinishArchive());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _WIN32\r\nclass CCurrentDirRestorer\r\n{\r\n  UString m_CurrentDirectory;\r\npublic:\r\n  CCurrentDirRestorer()\r\n    { NFile::NDirectory::MyGetCurrentDirectory(m_CurrentDirectory); }\r\n  ~CCurrentDirRestorer()\r\n    { RestoreDirectory();}\r\n  bool RestoreDirectory()\r\n    { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(m_CurrentDirectory)); }\r\n};\r\n#endif\r\n\r\nstruct CEnumDirItemUpdateCallback: public IEnumDirItemCallback\r\n{\r\n  IUpdateCallbackUI2 *Callback;\r\n  HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path)\r\n  {\r\n    return Callback->ScanProgress(numFolders, numFiles, path);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\ntypedef ULONG (FAR PASCAL MY_MAPISENDDOCUMENTS)(\r\n  ULONG_PTR ulUIParam,\r\n  LPSTR lpszDelimChar,\r\n  LPSTR lpszFilePaths,\r\n  LPSTR lpszFileNames,\r\n  ULONG ulReserved\r\n);\r\ntypedef MY_MAPISENDDOCUMENTS FAR *MY_LPMAPISENDDOCUMENTS;\r\n#endif\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor,\r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  if (options.StdOutMode && options.EMailMode)\r\n    return E_FAIL;\r\n\r\n  if (options.VolumesSizes.Size() > 0 && (options.EMailMode || options.SfxMode))\r\n    return E_NOTIMPL;\r\n\r\n  if (options.SfxMode)\r\n  {\r\n    CProperty property;\r\n    property.Name = L\"rsfx\";\r\n    property.Value = L\"on\";\r\n    options.MethodMode.Properties.Add(property);\r\n    if (options.SfxModule.IsEmpty())\r\n    {\r\n      errorInfo.Message = L\"sfx file is not specified\";\r\n      return E_FAIL;\r\n    }\r\n    UString name = options.SfxModule;\r\n    if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))\r\n    {\r\n      errorInfo.Message = L\"can't find specified sfx module\";\r\n      return E_FAIL;\r\n    }\r\n  }\r\n\r\n  const UString archiveName = options.ArchivePath.GetFinalPath();\r\n\r\n  UString defaultItemName;\r\n  NFind::CFileInfoW archiveFileInfo;\r\n\r\n  CArchiveLink archiveLink;\r\n  IInArchive *archive = 0;\r\n  if (NFind::FindFile(archiveName, archiveFileInfo))\r\n  {\r\n    if (archiveFileInfo.IsDir())\r\n      throw \"there is no such archive\";\r\n    if (options.VolumesSizes.Size() > 0)\r\n      return E_NOTIMPL;\r\n    CIntVector formatIndices;\r\n    if (options.MethodMode.FormatIndex >= 0)\r\n      formatIndices.Add(options.MethodMode.FormatIndex);\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, openCallback);\r\n    if (result == E_ABORT)\r\n      return result;\r\n    RINOK(callback->OpenResult(archiveName, result));\r\n    RINOK(result);\r\n    if (archiveLink.VolumePaths.Size() > 1)\r\n    {\r\n      errorInfo.SystemError = (DWORD)E_NOTIMPL;\r\n      errorInfo.Message = L\"Updating for multivolume archives is not implemented\";\r\n      return E_NOTIMPL;\r\n    }\r\n    archive = archiveLink.GetArchive();\r\n    defaultItemName = archiveLink.GetDefaultItemName();\r\n  }\r\n  else\r\n  {\r\n    /*\r\n    if (archiveType.IsEmpty())\r\n      throw \"type of archive is not specified\";\r\n    */\r\n  }\r\n\r\n  CDirItems dirItems;\r\n  if (options.StdInMode)\r\n  {\r\n    CDirItem di;\r\n    di.Name = options.StdInFileName;\r\n    di.Size = (UInt64)(Int64)-1;\r\n    di.Attrib = 0;\r\n    NTime::GetCurUtcFileTime(di.MTime);\r\n    di.CTime = di.ATime = di.MTime;\r\n    dirItems.Items.Add(di);\r\n  }\r\n  else\r\n  {\r\n    bool needScanning = false;\r\n    for(int i = 0; i < options.Commands.Size(); i++)\r\n      if (options.Commands[i].ActionSet.NeedScanning())\r\n        needScanning = true;\r\n    if (needScanning)\r\n    {\r\n      CEnumDirItemUpdateCallback enumCallback;\r\n      enumCallback.Callback = callback;\r\n      RINOK(callback->StartScanning());\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(censor, dirItems, &enumCallback, errorPaths, errorCodes);\r\n      for (int i = 0; i < errorPaths.Size(); i++)\r\n      {\r\n        RINOK(callback->CanNotFindError(errorPaths[i], errorCodes[i]));\r\n      }\r\n      if (res != S_OK)\r\n      {\r\n        if (res != E_ABORT)\r\n          errorInfo.Message = L\"Scanning error\";\r\n        // errorInfo.FileName = errorPath;\r\n        return res;\r\n      }\r\n      RINOK(callback->FinishScanning());\r\n    }\r\n  }\r\n\r\n  UString tempDirPrefix;\r\n  bool usesTempDir = false;\r\n  \r\n  #ifdef _WIN32\r\n  NDirectory::CTempDirectoryW tempDirectory;\r\n  if (options.EMailMode && options.EMailRemoveAfter)\r\n  {\r\n    tempDirectory.Create(kTempFolderPrefix);\r\n    tempDirPrefix = tempDirectory.GetPath();\r\n    NormalizeDirPathPrefix(tempDirPrefix);\r\n    usesTempDir = true;\r\n  }\r\n  #endif\r\n\r\n  CTempFiles tempFiles;\r\n\r\n  bool createTempFile = false;\r\n  if(!options.StdOutMode && options.UpdateArchiveItself)\r\n  {\r\n    CArchivePath &ap = options.Commands[0].ArchivePath;\r\n    ap = options.ArchivePath;\r\n    // if ((archive != 0 && !usesTempDir) || !options.WorkingDir.IsEmpty())\r\n    if ((archive != 0 || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)\r\n    {\r\n      createTempFile = true;\r\n      ap.Temp = true;\r\n      if (!options.WorkingDir.IsEmpty())\r\n      {\r\n        ap.TempPrefix = options.WorkingDir;\r\n        NormalizeDirPathPrefix(ap.TempPrefix);\r\n      }\r\n    }\r\n  }\r\n\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CArchivePath &ap = options.Commands[i].ArchivePath;\r\n    if (usesTempDir)\r\n    {\r\n      // Check it\r\n      ap.Prefix = tempDirPrefix;\r\n      // ap.Temp = true;\r\n      // ap.TempPrefix = tempDirPrefix;\r\n    }\r\n    if (i > 0 || !createTempFile)\r\n    {\r\n      const UString &path = ap.GetFinalPath();\r\n      if (NFind::DoesFileExist(path))\r\n      {\r\n        errorInfo.SystemError = 0;\r\n        errorInfo.Message = L\"File already exists\";\r\n        errorInfo.FileName = path;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n\r\n  CObjectVector<CArcItem> arcItems;\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(EnumerateInArchiveItems(censor,\r\n        archive, defaultItemName, archiveFileInfo, arcItems));\r\n  }\r\n\r\n  RINOK(UpdateWithItemLists(codecs, options, archive, arcItems, dirItems,\r\n      tempFiles, errorInfo, callback));\r\n\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(archiveLink.Close());\r\n    archiveLink.Release();\r\n  }\r\n\r\n  tempFiles.Paths.Clear();\r\n  if(createTempFile)\r\n  {\r\n    try\r\n    {\r\n      CArchivePath &ap = options.Commands[0].ArchivePath;\r\n      const UString &tempPath = ap.GetTempPath();\r\n      if (archive != NULL)\r\n        if (!NDirectory::DeleteFileAlways(archiveName))\r\n        {\r\n          errorInfo.SystemError = ::GetLastError();\r\n          errorInfo.Message = L\"delete file error\";\r\n          errorInfo.FileName = archiveName;\r\n          return E_FAIL;\r\n        }\r\n      if (!NDirectory::MyMoveFile(tempPath, archiveName))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.Message = L\"move file error\";\r\n        errorInfo.FileName = tempPath;\r\n        errorInfo.FileName2 = archiveName;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      throw;\r\n    }\r\n  }\r\n\r\n  #ifdef _WIN32\r\n  if (options.EMailMode)\r\n  {\r\n    NDLL::CLibrary mapiLib;\r\n    if (!mapiLib.Load(TEXT(\"Mapi32.dll\")))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not load Mapi32.dll\";\r\n      return E_FAIL;\r\n    }\r\n    MY_LPMAPISENDDOCUMENTS fnSend = (MY_LPMAPISENDDOCUMENTS)\r\n        mapiLib.GetProcAddress(\"MAPISendDocuments\");\r\n    if (fnSend == 0)\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not find MAPISendDocuments function\";\r\n      return E_FAIL;\r\n    }\r\n    UStringVector fullPaths;\r\n    int i;\r\n    for(i = 0; i < options.Commands.Size(); i++)\r\n    {\r\n      CArchivePath &ap = options.Commands[i].ArchivePath;\r\n      UString arcPath;\r\n      if(!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        return E_FAIL;\r\n      }\r\n      fullPaths.Add(arcPath);\r\n    }\r\n    CCurrentDirRestorer curDirRestorer;\r\n    for(i = 0; i < fullPaths.Size(); i++)\r\n    {\r\n      UString arcPath = fullPaths[i];\r\n      UString fileName = ExtractFileNameFromPath(arcPath);\r\n      AString path = GetAnsiString(arcPath);\r\n      AString name = GetAnsiString(fileName);\r\n      // Warning!!! MAPISendDocuments function changes Current directory\r\n      fnSend(0, \";\", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0);\r\n    }\r\n  }\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/Update.h",
    "content": "// Update.h\r\n\r\n#ifndef __UPDATE_H\r\n#define __UPDATE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"Property.h\"\r\n#include \"LoadCodecs.h\"\r\n\r\nstruct CArchivePath\r\n{\r\n  UString Prefix;   // path(folder) prefix including slash\r\n  UString Name; // base name\r\n  UString BaseExtension; // archive type extension or \"exe\" extension\r\n  UString VolExtension;  // archive type extension for volumes\r\n\r\n  bool Temp;\r\n  UString TempPrefix;  // path(folder) for temp location\r\n  UString TempPostfix;\r\n\r\n  CArchivePath(): Temp(false) {};\r\n  \r\n  void ParseFromPath(const UString &path)\r\n  {\r\n    SplitPathToParts(path, Prefix, Name);\r\n    if (Name.IsEmpty())\r\n      return;\r\n    int dotPos = Name.ReverseFind(L'.');\r\n    if (dotPos <= 0)\r\n      return;\r\n    if (dotPos == Name.Length() - 1)\r\n    {\r\n      Name = Name.Left(dotPos);\r\n      BaseExtension.Empty();\r\n      return;\r\n    }\r\n    if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0)\r\n    {\r\n      BaseExtension = Name.Mid(dotPos + 1);\r\n      Name = Name.Left(dotPos);\r\n    }\r\n    else\r\n      BaseExtension.Empty();\r\n  }\r\n\r\n  UString GetPathWithoutExt() const\r\n  {\r\n    return Prefix + Name;\r\n  }\r\n\r\n  UString GetFinalPath() const\r\n  {\r\n    UString path = GetPathWithoutExt();\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    return path;\r\n  }\r\n\r\n  \r\n  UString GetTempPath() const\r\n  {\r\n    UString path = TempPrefix + Name;\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    path += L\".tmp\";\r\n    path += TempPostfix;\r\n    return path;\r\n  }\r\n};\r\n\r\nstruct CUpdateArchiveCommand\r\n{\r\n  UString UserArchivePath;\r\n  CArchivePath ArchivePath;\r\n  NUpdateArchive::CActionSet ActionSet;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  int FormatIndex;\r\n  CObjectVector<CProperty> Properties;\r\n  CCompressionMethodMode(): FormatIndex(-1) {}\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  CCompressionMethodMode MethodMode;\r\n\r\n  CObjectVector<CUpdateArchiveCommand> Commands;\r\n  bool UpdateArchiveItself;\r\n  CArchivePath ArchivePath;\r\n  \r\n  bool SfxMode;\r\n  UString SfxModule;\r\n  \r\n  bool OpenShareForWrite;\r\n\r\n  bool StdInMode;\r\n  UString StdInFileName;\r\n  bool StdOutMode;\r\n  \r\n  bool EMailMode;\r\n  bool EMailRemoveAfter;\r\n  UString EMailAddress;\r\n\r\n  UString WorkingDir;\r\n\r\n  bool Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath);\r\n\r\n  CUpdateOptions():\r\n    UpdateArchiveItself(true),\r\n    SfxMode(false),\r\n    StdInMode(false),\r\n    StdOutMode(false),\r\n    EMailMode(false),\r\n    EMailRemoveAfter(false),\r\n    OpenShareForWrite(false)\r\n      {};\r\n  CRecordVector<UInt64> VolumesSizes;\r\n};\r\n\r\nstruct CErrorInfo\r\n{\r\n  DWORD SystemError;\r\n  UString FileName;\r\n  UString FileName2;\r\n  UString Message;\r\n  // UStringVector ErrorPaths;\r\n  // CRecordVector<DWORD> ErrorCodes;\r\n  CErrorInfo(): SystemError(0) {};\r\n};\r\n\r\nstruct CUpdateErrorInfo: public CErrorInfo\r\n{\r\n};\r\n\r\n#define INTERFACE_IUpdateCallbackUI2(x) \\\r\n  INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \\\r\n  virtual HRESULT StartScanning() x; \\\r\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) x; \\\r\n  virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT FinishScanning() x; \\\r\n  virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \\\r\n  virtual HRESULT FinishArchive() x; \\\r\n\r\nstruct IUpdateCallbackUI2: public IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI2(=0)\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor,\r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/UpdateAction.cpp",
    "content": "// UpdateAction.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n\r\nnamespace NUpdateArchive {\r\n\r\nconst CActionSet kAddActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kUpdateActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kFreshActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kSynchronizeActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n};\r\n\r\nconst CActionSet kDeleteActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/UpdateAction.h",
    "content": "// UpdateAction.h\r\n\r\n#ifndef __UPDATE_ACTION_H\r\n#define __UPDATE_ACTION_H\r\n\r\nnamespace NUpdateArchive {\r\n\r\n  namespace NPairState\r\n  {\r\n    const int kNumValues = 7;\r\n    enum EEnum\r\n    {\r\n      kNotMasked = 0,\r\n      kOnlyInArchive,\r\n      kOnlyOnDisk,\r\n      kNewInArchive,\r\n      kOldInArchive,\r\n      kSameFiles,\r\n      kUnknowNewerFiles\r\n    };\r\n  }\r\n  namespace NPairAction\r\n  {\r\n    enum EEnum\r\n    {\r\n      kIgnore = 0,\r\n      kCopy,\r\n      kCompress,\r\n      kCompressAsAnti\r\n    };\r\n  }\r\n  struct CActionSet\r\n  {\r\n    NPairAction::EEnum StateActions[NPairState::kNumValues];\r\n    bool NeedScanning() const\r\n    {\r\n      int i;\r\n      for (i = 0; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] == NPairAction::kCompress)\r\n          return true;\r\n      for (i = 1; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] != NPairAction::kIgnore)\r\n          return true;\r\n      return false;\r\n    }\r\n  };\r\n  extern const CActionSet kAddActionSet;\r\n  extern const CActionSet kUpdateActionSet;\r\n  extern const CActionSet kFreshActionSet;\r\n  extern const CActionSet kSynchronizeActionSet;\r\n  extern const CActionSet kDeleteActionSet;\r\n};\r\n\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/UpdateCallback.cpp",
    "content": "// UpdateCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCArchiveUpdateCallback::CArchiveUpdateCallback():\r\n  Callback(0),\r\n  ShareForWrite(false),\r\n  StdInMode(false),\r\n  DirItems(0),\r\n  ArcItems(0),\r\n  UpdatePairs(0),\r\n  NewNames(0)\r\n  {}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetTotal(size);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\n\r\n/*\r\nSTATPROPSTG kProperties[] =\r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidIsDir, VT_BOOL},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidCTime, VT_FILETIME},\r\n  { NULL, kpidATime, VT_FILETIME},\r\n  { NULL, kpidMTime, VT_FILETIME},\r\n  { NULL, kpidAttrib, VT_UI4},\r\n  { NULL, kpidIsAnti, VT_BOOL}\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)\r\n{\r\n  return CStatPropEnumerator::CreateEnumerator(kProperties, sizeof(kProperties) / sizeof(kProperties[0]), enumerator);\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,\r\n      Int32 *newData, Int32 *newProps, UInt32 *indexInArchive)\r\n{\r\n  COM_TRY_BEGIN\r\n  RINOK(Callback->CheckBreak());\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  if (newData != NULL) *newData = BoolToInt(up.NewData);\r\n  if (newProps != NULL) *newProps = BoolToInt(up.NewProps);\r\n  if (indexInArchive != NULL)\r\n  {\r\n    *indexInArchive = (UInt32)-1;\r\n    if (up.ExistInArchive())\r\n      *indexInArchive = (ArcItems == 0) ? up.ArcIndex : (*ArcItems)[up.ArcIndex].IndexInServer;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    prop = up.IsAnti;\r\n    prop.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  if (up.IsAnti)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidIsDir:\r\n      case kpidPath:\r\n        break;\r\n      case kpidSize:\r\n        prop = (UInt64)0;\r\n        prop.Detach(value);\r\n        return S_OK;\r\n      default:\r\n        prop.Detach(value);\r\n        return S_OK;\r\n    }\r\n  }\r\n  \r\n  if (up.ExistOnDisk())\r\n  {\r\n    const CDirItem &di = DirItems->Items[up.DirIndex];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:  prop = DirItems->GetLogPath(up.DirIndex); break;\r\n      case kpidIsDir:  prop = di.IsDir(); break;\r\n      case kpidSize:  prop = di.Size; break;\r\n      case kpidAttrib:  prop = di.Attrib; break;\r\n      case kpidCTime:  prop = di.CTime; break;\r\n      case kpidATime:  prop = di.ATime; break;\r\n      case kpidMTime:  prop = di.MTime; break;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (propID == kpidPath)\r\n    {\r\n      if (up.NewNameIndex >= 0)\r\n      {\r\n        prop = (*NewNames)[up.NewNameIndex];\r\n        prop.Detach(value);\r\n        return S_OK;\r\n      }\r\n    }\r\n    if (up.ExistInArchive() && Archive)\r\n    {\r\n      UInt32 indexInArchive;\r\n      if (ArcItems == 0)\r\n        indexInArchive = up.ArcIndex;\r\n      else\r\n        indexInArchive = (*ArcItems)[up.ArcIndex].IndexInServer;\r\n      return Archive->GetProperty(indexInArchive, propID, value);\r\n    }\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  if (!up.NewData)\r\n    return E_FAIL;\r\n  \r\n  RINOK(Callback->CheckBreak());\r\n  RINOK(Callback->Finilize());\r\n\r\n  if (up.IsAnti)\r\n  {\r\n    return Callback->GetStream((*ArcItems)[up.ArcIndex].Name, true);\r\n  }\r\n  const CDirItem &di = DirItems->Items[up.DirIndex];\r\n  RINOK(Callback->GetStream(DirItems->GetLogPath(up.DirIndex), false));\r\n \r\n  if (di.IsDir())\r\n    return S_OK;\r\n\r\n  if (StdInMode)\r\n  {\r\n    CStdInFileStream *inStreamSpec = new CStdInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  else\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    const UString path = DirItems->GetPhyPath(up.DirIndex);\r\n    if (!inStreamSpec->OpenShared(path, ShareForWrite))\r\n    {\r\n      return Callback->OpenFileError(path, ::GetLastError());\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetOperationResult(operationResult);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if (!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->CryptoGetTextPassword2(passwordIsDefined, password);\r\n  COM_TRY_END\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/UpdateCallback.h",
    "content": "// UpdateCallback.h\r\n\r\n#ifndef __UPDATECALLBACK_H\r\n#define __UPDATECALLBACK_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/UpdatePair.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#define INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT SetTotal(UInt64 size) x; \\\r\n  virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \\\r\n  virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x; \\\r\n  virtual HRESULT CheckBreak() x; \\\r\n  virtual HRESULT Finilize() x; \\\r\n  virtual HRESULT SetNumFiles(UInt64 numFiles) x; \\\r\n  virtual HRESULT GetStream(const wchar_t *name, bool isAnti) x; \\\r\n  virtual HRESULT OpenFileError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT SetOperationResult(Int32 operationResult) x; \\\r\n  virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x; \\\r\n  // virtual HRESULT ShowDeleteFile(const wchar_t *name) x; \\\r\n  // virtual HRESULT CloseProgress() { return S_OK; };\r\n\r\nstruct IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI(=0)\r\n};\r\n\r\nclass CArchiveUpdateCallback:\r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveUpdateCallback2,\r\n      ICryptoGetTextPassword2,\r\n      ICompressProgressInfo)\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  INTERFACE_IArchiveUpdateCallback2(;)\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  IUpdateCallbackUI *Callback;\r\n\r\n  bool ShareForWrite;\r\n  bool StdInMode;\r\n  const CDirItems *DirItems;\r\n  const CObjectVector<CArcItem> *ArcItems;\r\n  const CRecordVector<CUpdatePair2> *UpdatePairs;\r\n  const UStringVector *NewNames;\r\n  CMyComPtr<IInArchive> Archive;\r\n\r\n  CArchiveUpdateCallback();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/UpdatePair.cpp",
    "content": "// UpdatePair.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <time.h>\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"UpdatePair.h\"\r\n#include \"SortUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nstatic int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time1, const FILETIME &time2)\r\n{\r\n  switch(fileTimeType)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n      return ::CompareFileTime(&time1, &time2);\r\n    case NFileTimeType::kUnix:\r\n      {\r\n        UInt32 unixTime1, unixTime2;\r\n        FileTimeToUnixTime(time1, unixTime1);\r\n        FileTimeToUnixTime(time2, unixTime2);\r\n        return MyCompare(unixTime1, unixTime2);\r\n      }\r\n    case NFileTimeType::kDOS:\r\n      {\r\n        UInt32 dosTime1, dosTime2;\r\n        FileTimeToDosTime(time1, dosTime1);\r\n        FileTimeToDosTime(time2, dosTime2);\r\n        return MyCompare(dosTime1, dosTime2);\r\n      }\r\n  }\r\n  throw 4191618;\r\n}\r\n\r\nstatic const wchar_t *kDuplicateFileNameMessage = L\"Duplicate filename:\";\r\nstatic const wchar_t *kNotCensoredCollisionMessaged = L\"Internal file name collision (file on disk, file in archive):\";\r\n\r\nstatic void ThrowError(const UString &message, const UString &s1, const UString &s2)\r\n{\r\n  UString m = message;\r\n  m += L'\\n';\r\n  m += s1;\r\n  m += L'\\n';\r\n  m += s2;\r\n  throw m;\r\n}\r\n\r\nstatic void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)\r\n{\r\n  for(int i = 0; i + 1 < indices.Size(); i++)\r\n    if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)\r\n      ThrowError(kDuplicateFileNameMessage, strings[indices[i]], strings[indices[i + 1]]);\r\n}\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CDirItems &dirItems,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CRecordVector<CUpdatePair> &updatePairs)\r\n{\r\n  CIntVector dirIndices, arcIndices;\r\n  \r\n  int numDirItems = dirItems.Items.Size();\r\n  int numArcItems = arcItems.Size();\r\n  \r\n  \r\n  {\r\n    UStringVector arcNames;\r\n    arcNames.Reserve(numArcItems);\r\n    for (int i = 0; i < numArcItems; i++)\r\n      arcNames.Add(arcItems[i].Name);\r\n    SortFileNames(arcNames, arcIndices);\r\n    TestDuplicateString(arcNames, arcIndices);\r\n  }\r\n\r\n  UStringVector dirNames;\r\n  {\r\n    dirNames.Reserve(numDirItems);\r\n    for (int i = 0; i < numDirItems; i++)\r\n      dirNames.Add(dirItems.GetLogPath(i));\r\n    SortFileNames(dirNames, dirIndices);\r\n    TestDuplicateString(dirNames, dirIndices);\r\n  }\r\n  \r\n  int dirIndex = 0, arcIndex = 0;\r\n  while (dirIndex < numDirItems && arcIndex < numArcItems)\r\n  {\r\n    CUpdatePair pair;\r\n    int dirIndex2 = dirIndices[dirIndex];\r\n    int arcIndex2 = arcIndices[arcIndex];\r\n    const CDirItem &di = dirItems.Items[dirIndex2];\r\n    const CArcItem &ai = arcItems[arcIndex2];\r\n    int compareResult = CompareFileNames(dirNames[dirIndex2], ai.Name);\r\n    if (compareResult < 0)\r\n    {\r\n      pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n      pair.DirIndex = dirIndex2;\r\n      dirIndex++;\r\n    }\r\n    else if (compareResult > 0)\r\n    {\r\n      pair.State = ai.Censored ?\r\n          NUpdateArchive::NPairState::kOnlyInArchive:\r\n          NUpdateArchive::NPairState::kNotMasked;\r\n      pair.ArcIndex = arcIndex2;\r\n      arcIndex++;\r\n    }\r\n    else\r\n    {\r\n      if (!ai.Censored)\r\n        ThrowError(kNotCensoredCollisionMessaged, dirNames[dirIndex2], ai.Name);\r\n      pair.DirIndex = dirIndex2;\r\n      pair.ArcIndex = arcIndex2;\r\n      switch (MyCompareTime(\r\n          ai.TimeType != - 1 ? (NFileTimeType::EEnum)ai.TimeType : fileTimeType,\r\n          di.MTime, ai.MTime))\r\n      {\r\n        case -1: pair.State = NUpdateArchive::NPairState::kNewInArchive; break;\r\n        case 1:  pair.State = NUpdateArchive::NPairState::kOldInArchive; break;\r\n        default:\r\n          if (ai.SizeDefined)\r\n            if (di.Size != ai.Size)\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n            else\r\n              pair.State = NUpdateArchive::NPairState::kSameFiles;\r\n          else\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n      }\r\n      dirIndex++;\r\n      arcIndex++;\r\n    }\r\n    updatePairs.Add(pair);\r\n  }\r\n\r\n  for (; dirIndex < numDirItems; dirIndex++)\r\n  {\r\n    CUpdatePair pair;\r\n    pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n    pair.DirIndex = dirIndices[dirIndex];\r\n    updatePairs.Add(pair);\r\n  }\r\n  \r\n  for (; arcIndex < numArcItems; arcIndex++)\r\n  {\r\n    CUpdatePair pair;\r\n    int arcIndex2 = arcIndices[arcIndex];\r\n    pair.State = arcItems[arcIndex2].Censored ?\r\n        NUpdateArchive::NPairState::kOnlyInArchive:\r\n        NUpdateArchive::NPairState::kNotMasked;\r\n    pair.ArcIndex = arcIndex2;\r\n    updatePairs.Add(pair);\r\n  }\r\n\r\n  updatePairs.ReserveDown();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/UpdatePair.h",
    "content": "// UpdatePair.h\r\n\r\n#ifndef __UPDATE_PAIR_H\r\n#define __UPDATE_PAIR_H\r\n\r\n#include \"DirItem.h\"\r\n#include \"UpdateAction.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CUpdatePair\r\n{\r\n  NUpdateArchive::NPairState::EEnum State;\r\n  int ArcIndex;\r\n  int DirIndex;\r\n  CUpdatePair(): ArcIndex(-1), DirIndex(-1) {}\r\n};\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CDirItems &dirItems,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CRecordVector<CUpdatePair> &updatePairs);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/UpdateProduce.cpp",
    "content": "// UpdateProduce.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateProduce.h\"\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic const char *kUpdateActionSetCollision = \"Internal collision in update action set\";\r\n\r\nvoid UpdateProduce(\r\n    const CRecordVector<CUpdatePair> &updatePairs,\r\n    const CActionSet &actionSet,\r\n    CRecordVector<CUpdatePair2> &operationChain,\r\n    IUpdateProduceCallback *callback)\r\n{\r\n  for (int i = 0; i < updatePairs.Size(); i++)\r\n  {\r\n    const CUpdatePair &pair = updatePairs[i];\r\n\r\n    CUpdatePair2 up2;\r\n    up2.IsAnti = false;\r\n    up2.DirIndex = pair.DirIndex;\r\n    up2.ArcIndex = pair.ArcIndex;\r\n    up2.NewData = up2.NewProps = true;\r\n    \r\n    switch(actionSet.StateActions[pair.State])\r\n    {\r\n      case NPairAction::kIgnore:\r\n        /*\r\n        if (pair.State != NPairState::kOnlyOnDisk)\r\n          IgnoreArchiveItem(m_ArchiveItems[pair.ArcIndex]);\r\n        // cout << \"deleting\";\r\n        */\r\n        if (callback)\r\n          callback->ShowDeleteFile(pair.ArcIndex);\r\n        continue;\r\n\r\n      case NPairAction::kCopy:\r\n        if (pair.State == NPairState::kOnlyOnDisk)\r\n          throw kUpdateActionSetCollision;\r\n        up2.NewData = up2.NewProps = false;\r\n        break;\r\n      \r\n      case NPairAction::kCompress:\r\n        if (pair.State == NPairState::kOnlyInArchive ||\r\n            pair.State == NPairState::kNotMasked)\r\n          throw kUpdateActionSetCollision;\r\n        break;\r\n      \r\n      case NPairAction::kCompressAsAnti:\r\n        up2.IsAnti = true;\r\n        break;\r\n    }\r\n    operationChain.Add(up2);\r\n  }\r\n  operationChain.ReserveDown();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/UpdateProduce.h",
    "content": "// UpdateProduce.h\r\n\r\n#ifndef __UPDATE_PRODUCE_H\r\n#define __UPDATE_PRODUCE_H\r\n\r\n#include \"UpdatePair.h\"\r\n\r\nstruct CUpdatePair2\r\n{\r\n  bool NewData;\r\n  bool NewProps;\r\n  bool IsAnti;\r\n  \r\n  int DirIndex;\r\n  int ArcIndex;\r\n  int NewNameIndex;\r\n\r\n  bool ExistOnDisk() const { return DirIndex != -1; }\r\n  bool ExistInArchive() const { return ArcIndex != -1; }\r\n\r\n  CUpdatePair2(): IsAnti(false), DirIndex(-1), ArcIndex(-1), NewNameIndex(-1) {}\r\n};\r\n\r\nstruct IUpdateProduceCallback\r\n{\r\n  virtual HRESULT ShowDeleteFile(int arcIndex) = 0;\r\n};\r\n\r\nvoid UpdateProduce(\r\n    const CRecordVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CRecordVector<CUpdatePair2> &operationChain,\r\n    IUpdateProduceCallback *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/WorkDir.cpp",
    "content": "// WorkDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"WorkDir.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nstatic inline UINT GetCurrentCodePage()\r\n  { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)\r\n{\r\n  NWorkDir::NMode::EEnum mode = workDirInfo.Mode;\r\n  if (workDirInfo.ForRemovableOnly)\r\n  {\r\n    mode = NWorkDir::NMode::kCurrent;\r\n    UString prefix = path.Left(3);\r\n    if (prefix[1] == L':' && prefix[2] == L'\\\\')\r\n    {\r\n      UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));\r\n      if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)\r\n        mode = workDirInfo.Mode;\r\n    }\r\n    /*\r\n    CParsedPath parsedPath;\r\n    parsedPath.ParsePath(archiveName);\r\n    UINT driveType = GetDriveType(parsedPath.Prefix);\r\n    if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))\r\n      mode = NZipSettings::NWorkDir::NMode::kCurrent;\r\n    */\r\n  }\r\n  switch(mode)\r\n  {\r\n    case NWorkDir::NMode::kCurrent:\r\n    {\r\n      return ExtractDirPrefixFromPath(path);\r\n    }\r\n    case NWorkDir::NMode::kSpecified:\r\n    {\r\n      UString tempDir = workDirInfo.Path;\r\n      NormalizeDirPathPrefix(tempDir);\r\n      return tempDir;\r\n    }\r\n    default:\r\n    {\r\n      UString tempDir;\r\n      if(!NFile::NDirectory::MyGetTempPath(tempDir))\r\n        throw 141717;\r\n      return tempDir;\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/WorkDir.h",
    "content": "// WorkDir.h\r\n\r\n#ifndef __WORKDIR_H\r\n#define __WORKDIR_H\r\n\r\n#include \"ZipRegistry.h\"\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Common/ZipRegistry.h",
    "content": "// ZipRegistry.h\r\n\r\n#ifndef __ZIPREGISTRY_H\r\n#define __ZIPREGISTRY_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"ExtractMode.h\"\r\n\r\nnamespace NExtract\r\n{\r\n  struct CInfo\r\n  {\r\n    NPathMode::EEnum PathMode;\r\n    NOverwriteMode::EEnum OverwriteMode;\r\n    UStringVector Paths;\r\n    bool ShowPassword;\r\n  };\r\n}\r\n\r\nnamespace NCompression {\r\n  \r\n  struct CFormatOptions\r\n  {\r\n    CSysString FormatID;\r\n    UString Options;\r\n    UString Method;\r\n    UString EncryptionMethod;\r\n    UInt32 Level;\r\n    UInt32 Dictionary;\r\n    UInt32 Order;\r\n    UInt32 BlockLogSize;\r\n    UInt32 NumThreads;\r\n    void ResetForLevelChange()\r\n    {\r\n      BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1);\r\n      Method.Empty();\r\n      // EncryptionMethod.Empty();\r\n      // Options.Empty();\r\n    }\r\n    CFormatOptions() { ResetForLevelChange(); }\r\n  };\r\n\r\n  struct CInfo\r\n  {\r\n    UStringVector HistoryArchives;\r\n    UInt32 Level;\r\n    UString ArchiveType;\r\n\r\n    CObjectVector<CFormatOptions> FormatOptionsVector;\r\n\r\n    bool ShowPassword;\r\n    bool EncryptHeaders;\r\n  };\r\n}\r\n\r\nnamespace NWorkDir{\r\n  \r\n  namespace NMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kSystem,\r\n      kCurrent,\r\n      kSpecified\r\n    };\r\n  }\r\n  struct CInfo\r\n  {\r\n    NMode::EEnum Mode;\r\n    UString Path;\r\n    bool ForRemovableOnly;\r\n    void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }\r\n    void SetDefault()\r\n    {\r\n      Mode = NMode::kSystem;\r\n      Path.Empty();\r\n      SetForRemovableOnlyDefault();\r\n    }\r\n  };\r\n}\r\n\r\nvoid SaveExtractionInfo(const NExtract::CInfo &info);\r\nvoid ReadExtractionInfo(NExtract::CInfo &info);\r\n\r\nvoid SaveCompressionInfo(const NCompression::CInfo &info);\r\nvoid ReadCompressionInfo(NCompression::CInfo &info);\r\n\r\nvoid SaveWorkDirInfo(const NWorkDir::CInfo &info);\r\nvoid ReadWorkDirInfo(NWorkDir::CInfo &info);\r\n\r\nvoid SaveCascadedMenu(bool enabled);\r\nbool ReadCascadedMenu();\r\n\r\nvoid SaveContextMenuStatus(UInt32 value);\r\nbool ReadContextMenuStatus(UInt32 &value);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/ConsoleClose.cpp",
    "content": "// ConsoleClose.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n\r\nstatic int g_BreakCounter = 0;\r\nstatic const int kBreakAbortThreshold = 2;\r\n\r\nnamespace NConsoleClose {\r\n\r\nstatic BOOL WINAPI HandlerRoutine(DWORD ctrlType)\r\n{\r\n  if (ctrlType == CTRL_LOGOFF_EVENT)\r\n  {\r\n    // printf(\"\\nCTRL_LOGOFF_EVENT\\n\");\r\n    return TRUE;\r\n  }\r\n\r\n  g_BreakCounter++;\r\n  if (g_BreakCounter < kBreakAbortThreshold)\r\n    return TRUE;\r\n  return FALSE;\r\n  /*\r\n  switch(ctrlType)\r\n  {\r\n    case CTRL_C_EVENT:\r\n    case CTRL_BREAK_EVENT:\r\n      if (g_BreakCounter < kBreakAbortThreshold)\r\n      return TRUE;\r\n  }\r\n  return FALSE;\r\n  */\r\n}\r\n\r\nbool TestBreakSignal()\r\n{\r\n  /*\r\n  if (g_BreakCounter > 0)\r\n    return true;\r\n  */\r\n  return (g_BreakCounter > 0);\r\n}\r\n\r\nvoid CheckCtrlBreak()\r\n{\r\n  if (TestBreakSignal())\r\n    throw CCtrlBreakException();\r\n}\r\n\r\nCCtrlHandlerSetter::CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\nCCtrlHandlerSetter::~CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/ConsoleClose.h",
    "content": "// ConsoleCloseUtils.h\r\n\r\n#ifndef __CONSOLECLOSEUTILS_H\r\n#define __CONSOLECLOSEUTILS_H\r\n\r\nnamespace NConsoleClose {\r\n\r\nbool TestBreakSignal();\r\n\r\nclass CCtrlHandlerSetter\r\n{\r\npublic:\r\n  CCtrlHandlerSetter();\r\n  virtual ~CCtrlHandlerSetter();\r\n};\r\n\r\nclass CCtrlBreakException\r\n{};\r\n\r\nvoid CheckCtrlBreak();\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UserInputUtils.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Error.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic const char *kTestString    =  \"Testing     \";\r\nstatic const char *kExtractString =  \"Extracting  \";\r\nstatic const char *kSkipString   =  \"Skipping    \";\r\n\r\n// static const char *kCantAutoRename = \"can not create file with auto name\\n\";\r\n// static const char *kCantRenameFile = \"can not rename existing file\\n\";\r\n// static const char *kCantDeleteOutputFile = \"can not delete output file \";\r\nstatic const char *kError = \"ERROR: \";\r\nstatic const char *kMemoryExceptionMessage = \"Can't allocate required memory!\";\r\n\r\nstatic const char *kProcessing = \"Processing archive: \";\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kNoFiles = \"No files to process\";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCrcFailed = \"CRC Failed\";\r\nstatic const char *kCrcFailedEncrypted = \"CRC Failed in encrypted file. Wrong password?\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kDataErrorEncrypted = \"Data Error in encrypted file. Wrong password?\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::AskOverwrite(\r\n    const wchar_t *existName, const FILETIME *, const UInt64 *,\r\n    const wchar_t *newName, const FILETIME *, const UInt64 *,\r\n    Int32 *answer)\r\n{\r\n  (*OutStream) << \"file \" << existName <<\r\n    \"\\nalready exists. Overwrite with \" << endl;\r\n  (*OutStream) << newName;\r\n  \r\n  NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);\r\n  \r\n  switch(overwriteAnswer)\r\n  {\r\n    case NUserAnswerMode::kQuit:  return E_ABORT;\r\n    case NUserAnswerMode::kNo:     *answer = NOverwriteAnswer::kNo; break;\r\n    case NUserAnswerMode::kNoAll:  *answer = NOverwriteAnswer::kNoToAll; break;\r\n    case NUserAnswerMode::kYesAll: *answer = NOverwriteAnswer::kYesToAll; break;\r\n    case NUserAnswerMode::kYes:    *answer = NOverwriteAnswer::kYes; break;\r\n    case NUserAnswerMode::kAutoRenameAll: *answer = NOverwriteAnswer::kAutoRename; break;\r\n    default: return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position)\r\n{\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract: (*OutStream) << kExtractString; break;\r\n    case NArchive::NExtract::NAskMode::kTest:    (*OutStream) << kTestString; break;\r\n    case NArchive::NExtract::NAskMode::kSkip:    (*OutStream) << kSkipString; break;\r\n  };\r\n  (*OutStream) << name;\r\n  if (position != 0)\r\n    (*OutStream) << \" <\" << *position << \">\";\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)\r\n{\r\n  (*OutStream) << message << endl;\r\n  NumFileErrorsInCurrentArchive++;\r\n  NumFileErrors++;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumFileErrorsInCurrentArchive++;\r\n      NumFileErrors++;\r\n      (*OutStream) << \"     \";\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          (*OutStream) << kUnsupportedMethod;\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError);\r\n          break;\r\n        default:\r\n          (*OutStream) << kUnknownError;\r\n      }\r\n    }\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\n\r\nHRESULT CExtractCallbackConsole::SetPassword(const UString &password)\r\n{\r\n  PasswordIsDefined = true;\r\n  Password = password;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream);\r\n    PasswordIsDefined = true;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)\r\n{\r\n  NumArchives++;\r\n  NumFileErrorsInCurrentArchive = 0;\r\n  (*OutStream) << endl << kProcessing << name << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT result, bool encrypted)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n  {\r\n    (*OutStream) << \"Error: \";\r\n    if (result == S_FALSE)\r\n    {\r\n      (*OutStream) << (encrypted ?\r\n        \"Can not open encrypted archive. Wrong password?\" :\r\n        \"Can not open file as archive\");\r\n    }\r\n    else\r\n    {\r\n      if (result == E_OUTOFMEMORY)\r\n        (*OutStream) << \"Can't allocate required memory\";\r\n      else\r\n        (*OutStream) << NError::MyFormatMessage(result);\r\n    }\r\n    (*OutStream) << endl;\r\n    NumArchiveErrors++;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nHRESULT CExtractCallbackConsole::ThereAreNoFiles()\r\n{\r\n  (*OutStream) << endl << kNoFiles << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)\r\n{\r\n  if (result == S_OK)\r\n  {\r\n    (*OutStream) << endl;\r\n    if (NumFileErrorsInCurrentArchive == 0)\r\n      (*OutStream) << kEverythingIsOk << endl;\r\n    else\r\n    {\r\n      NumArchiveErrors++;\r\n      (*OutStream) << \"Sub items Errors: \" << NumFileErrorsInCurrentArchive << endl;\r\n    }\r\n  }\r\n  if (result == S_OK)\r\n    return result;\r\n  NumArchiveErrors++;\r\n  if (result == E_ABORT || result == ERROR_DISK_FULL)\r\n    return result;\r\n  (*OutStream) << endl << kError;\r\n  if (result == E_OUTOFMEMORY)\r\n    (*OutStream) << kMemoryExceptionMessage;\r\n  else\r\n  {\r\n    UString message;\r\n    NError::MyFormatMessage(result, message);\r\n    (*OutStream) << message;\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/ExtractCallbackConsole.h",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#ifndef __EXTRACTCALLBACKCONSOLE_H\r\n#define __EXTRACTCALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../Common/ArchiveExtractCallback.h\"\r\n\r\nclass CExtractCallbackConsole:\r\n  public IExtractCallbackUI,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IFolderArchiveExtractCallback)\r\n  #ifndef _NO_CRYPTO\r\n  MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)\r\n  #endif\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  STDMETHOD(SetTotal)(UInt64 total);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IFolderArchiveExtractCallback\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer);\r\n  STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position);\r\n\r\n  STDMETHOD(MessageError)(const wchar_t *message);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);\r\n\r\n  HRESULT BeforeOpen(const wchar_t *name);\r\n  HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);\r\n  HRESULT ThereAreNoFiles();\r\n  HRESULT ExtractResult(HRESULT result);\r\n\r\n \r\n  #ifndef _NO_CRYPTO\r\n  HRESULT SetPassword(const UString &password);\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  #endif\r\n  \r\n  UInt64 NumArchives;\r\n  UInt64 NumArchiveErrors;\r\n  UInt64 NumFileErrors;\r\n  UInt64 NumFileErrorsInCurrentArchive;\r\n\r\n  CStdOutStream *OutStream;\r\n\r\n  void Init()\r\n  {\r\n    NumArchives = 0;\r\n    NumArchiveErrors = 0;\r\n    NumFileErrors = 0;\r\n    NumFileErrorsInCurrentArchive = 0;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/List.cpp",
    "content": "// List.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"List.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../Common/PropIDUtils.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstruct CPropIdToName\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n};\r\n\r\nstatic CPropIdToName kPropIdToName[] =\r\n{\r\n  { kpidPath, L\"Path\" },\r\n  { kpidName, L\"Name\" },\r\n  { kpidIsDir, L\"Folder\" },\r\n  { kpidSize, L\"Size\" },\r\n  { kpidPackSize, L\"Packed Size\" },\r\n  { kpidAttrib, L\"Attributes\" },\r\n  { kpidCTime, L\"Created\" },\r\n  { kpidATime, L\"Accessed\" },\r\n  { kpidMTime, L\"Modified\" },\r\n  { kpidSolid, L\"Solid\" },\r\n  { kpidCommented, L\"Commented\" },\r\n  { kpidEncrypted, L\"Encrypted\" },\r\n  { kpidSplitBefore, L\"Split Before\" },\r\n  { kpidSplitAfter, L\"Split After\" },\r\n  { kpidDictionarySize, L\"Dictionary Size\" },\r\n  { kpidCRC, L\"CRC\" },\r\n  { kpidType, L\"Type\" },\r\n  { kpidIsAnti, L\"Anti\" },\r\n  { kpidMethod, L\"Method\" },\r\n  { kpidHostOS, L\"Host OS\" },\r\n  { kpidFileSystem, L\"File System\" },\r\n  { kpidUser, L\"User\" },\r\n  { kpidGroup, L\"Group\" },\r\n  { kpidBlock, L\"Block\" },\r\n  { kpidComment, L\"Comment\" },\r\n  { kpidPosition, L\"Position\" },\r\n  { kpidPrefix, L\"Prefix\" },\r\n  { kpidNumSubDirs, L\"Folders\" },\r\n  { kpidNumSubFiles, L\"Files\" },\r\n  { kpidUnpackVer, L\"Version\" },\r\n  { kpidVolume, L\"Volume\" },\r\n  { kpidIsVolume, L\"Multivolume\" },\r\n  { kpidOffset, L\"Offset\" },\r\n  { kpidLinks, L\"Links\" },\r\n  { kpidNumBlocks, L\"Blocks\" },\r\n  { kpidNumVolumes, L\"Volumes\" },\r\n\r\n  { kpidBit64, L\"64-bit\" },\r\n  { kpidBigEndian, L\"Big-endian\" },\r\n  { kpidCpu, L\"CPU\" },\r\n  { kpidPhySize, L\"Physical Size\" },\r\n  { kpidHeadersSize, L\"Headers Size\" },\r\n  { kpidChecksum, L\"Checksum\" },\r\n  { kpidCharacts, L\"Characteristics\" },\r\n  { kpidVa, L\"Virtual Address\" },\r\n  { kpidFreeSpace, L\"Free Space\" },\r\n  { kpidClusterSize, L\"Cluster Size\" }\r\n};\r\n\r\nstatic const char kEmptyAttribChar = '.';\r\n\r\nstatic const char *kListing = \"Listing archive: \";\r\nstatic const wchar_t *kFilesMessage = L\"files\";\r\nstatic const wchar_t *kDirsMessage = L\"folders\";\r\n\r\nstatic void GetAttribString(DWORD wa, bool isDir, char *s)\r\n{\r\n  s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : kEmptyAttribChar;\r\n  s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0) ? 'R': kEmptyAttribChar;\r\n  s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? 'H': kEmptyAttribChar;\r\n  s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? 'S': kEmptyAttribChar;\r\n  s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? 'A': kEmptyAttribChar;\r\n  s[5] = '\\0';\r\n}\r\n\r\nenum EAdjustment\r\n{\r\n  kLeft,\r\n  kCenter,\r\n  kRight\r\n};\r\n\r\nstruct CFieldInfo\r\n{\r\n  PROPID PropID;\r\n  UString Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nstruct CFieldInfoInit\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nCFieldInfoInit kStandardFieldTable[] =\r\n{\r\n  { kpidMTime, L\"   Date      Time\", kLeft, kLeft, 0, 19 },\r\n  { kpidAttrib, L\"Attr\", kRight, kCenter, 1, 5 },\r\n  { kpidSize, L\"Size\", kRight, kRight, 1, 12 },\r\n  { kpidPackSize, L\"Compressed\", kRight, kRight, 1, 12 },\r\n  { kpidPath, L\"Name\", kLeft, kLeft, 2, 24 }\r\n};\r\n\r\nvoid PrintSpaces(int numSpaces)\r\n{\r\n  for (int i = 0; i < numSpaces; i++)\r\n    g_StdOut << ' ';\r\n}\r\n\r\nvoid PrintString(EAdjustment adjustment, int width, const UString &textString)\r\n{\r\n  const int numSpaces = width - textString.Length();\r\n  int numLeftSpaces = 0;\r\n  switch (adjustment)\r\n  {\r\n    case kLeft:\r\n      numLeftSpaces = 0;\r\n      break;\r\n    case kCenter:\r\n      numLeftSpaces = numSpaces / 2;\r\n      break;\r\n    case kRight:\r\n      numLeftSpaces = numSpaces;\r\n      break;\r\n  }\r\n  PrintSpaces(numLeftSpaces);\r\n  g_StdOut << textString;\r\n  PrintSpaces(numSpaces - numLeftSpaces);\r\n}\r\n\r\nclass CFieldPrinter\r\n{\r\n  CObjectVector<CFieldInfo> _fields;\r\npublic:\r\n  void Clear() { _fields.Clear(); }\r\n  void Init(const CFieldInfoInit *standardFieldTable, int numItems);\r\n  HRESULT Init(IInArchive *archive);\r\n  void PrintTitle();\r\n  void PrintTitleLines();\r\n  HRESULT PrintItemInfo(IInArchive *archive,\r\n      const UString &defaultItemName,\r\n      UInt32 index,\r\n      bool techMode);\r\n  HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\r\n      const UInt64 *size, const UInt64 *compressedSize);\r\n};\r\n\r\nvoid CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)\r\n{\r\n  Clear();\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    CFieldInfo fieldInfo;\r\n    const CFieldInfoInit &fieldInfoInit = standardFieldTable[i];\r\n    fieldInfo.PropID = fieldInfoInit.PropID;\r\n    fieldInfo.Name = fieldInfoInit.Name;\r\n    fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment;\r\n    fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment;\r\n    fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth;\r\n    fieldInfo.Width = fieldInfoInit.Width;\r\n    _fields.Add(fieldInfo);\r\n  }\r\n}\r\n\r\nstatic UString GetPropName(PROPID propID, BSTR name)\r\n{\r\n  for (int i = 0; i < sizeof(kPropIdToName) / sizeof(kPropIdToName[0]); i++)\r\n  {\r\n    const CPropIdToName &propIdToName = kPropIdToName[i];\r\n    if (propIdToName.PropID == propID)\r\n      return propIdToName.Name;\r\n  }\r\n  if (name)\r\n    return name;\r\n  wchar_t s[32];\r\n  ConvertUInt64ToString(propID, s);\r\n  return s;\r\n}\r\n\r\nHRESULT CFieldPrinter::Init(IInArchive *archive)\r\n{\r\n  Clear();\r\n  UInt32 numProps;\r\n  RINOK(archive->GetNumberOfProperties(&numProps));\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    CMyComBSTR name;\r\n    PROPID propID;\r\n    VARTYPE vt;\r\n    RINOK(archive->GetPropertyInfo(i, &name, &propID, &vt));\r\n    CFieldInfo fieldInfo;\r\n    fieldInfo.PropID = propID;\r\n    fieldInfo.Name = GetPropName(propID, name);\r\n    _fields.Add(fieldInfo);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitle()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    PrintString(fieldInfo.TitleAdjustment,\r\n      ((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);\r\n  }\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitleLines()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    for (int i = 0; i < fieldInfo.Width; i++)\r\n      g_StdOut << '-';\r\n  }\r\n}\r\n\r\n\r\nBOOL IsFileTimeZero(CONST FILETIME *lpFileTime)\r\n{\r\n  return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);\r\n}\r\n\r\nstatic const char *kEmptyTimeString = \"                   \";\r\nvoid PrintTime(const NCOM::CPropVariant &prop)\r\n{\r\n  if (prop.vt != VT_FILETIME)\r\n    throw \"incorrect item\";\r\n  if (IsFileTimeZero(&prop.filetime))\r\n    g_StdOut << kEmptyTimeString;\r\n  else\r\n  {\r\n    FILETIME localFileTime;\r\n    if (!FileTimeToLocalFileTime(&prop.filetime, &localFileTime))\r\n      throw \"FileTimeToLocalFileTime error\";\r\n    char s[32];\r\n    if (ConvertFileTimeToString(localFileTime, s, true, true))\r\n      g_StdOut << s;\r\n    else\r\n      g_StdOut << kEmptyTimeString;\r\n  }\r\n}\r\n\r\nHRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    UInt32 index,\r\n    bool techMode)\r\n{\r\n  /*\r\n  if (techMode)\r\n  {\r\n    g_StdOut << \"Index = \";\r\n    g_StdOut << (UInt64)index;\r\n    g_StdOut << endl;\r\n  }\r\n  */\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    if (!techMode)\r\n      PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      UString s;\r\n      RINOK(GetArchiveItemPath(archive, index, defaultItemName, s));\r\n      prop = s;\r\n    }\r\n    else\r\n    {\r\n      RINOK(archive->GetProperty(index, fieldInfo.PropID, &prop));\r\n    }\r\n    if (techMode)\r\n    {\r\n      g_StdOut << fieldInfo.Name << \" = \";\r\n    }\r\n    int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;\r\n    if (prop.vt == VT_EMPTY)\r\n    {\r\n      switch(fieldInfo.PropID)\r\n      {\r\n        case kpidPath:  prop = defaultItemName; break;\r\n        default:\r\n          if (techMode)\r\n            g_StdOut << endl;\r\n          else\r\n            PrintSpaces(width);\r\n          continue;\r\n      }\r\n    }\r\n    if (fieldInfo.PropID == kpidMTime)\r\n    {\r\n      PrintTime(prop);\r\n    }\r\n    else if (fieldInfo.PropID == kpidAttrib)\r\n    {\r\n      if (prop.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      UInt32 attributes = prop.ulVal;\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, index, isFolder));\r\n      char s[8];\r\n      GetAttribString(attributes, isFolder, s);\r\n      g_StdOut << s;\r\n    }\r\n    else if (prop.vt == VT_BSTR)\r\n    {\r\n      if (techMode)\r\n        g_StdOut << prop.bstrVal;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, prop.bstrVal);\r\n    }\r\n    else\r\n    {\r\n      UString s = ConvertPropertyToString(prop, fieldInfo.PropID);\r\n      s.Replace(wchar_t(0xA), L' ');\r\n      s.Replace(wchar_t(0xD), L' ');\r\n\r\n      if (techMode)\r\n        g_StdOut << s;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, s);\r\n    }\r\n    if (techMode)\r\n      g_StdOut << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)\r\n{\r\n  wchar_t textString[32] = { 0 };\r\n  if (value != NULL)\r\n    ConvertUInt64ToString(*value, textString);\r\n  PrintString(adjustment, width, textString);\r\n}\r\n\r\n\r\nHRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\r\n    const UInt64 *size, const UInt64 *compressedSize)\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    NCOM::CPropVariant prop;\r\n    if (fieldInfo.PropID == kpidSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);\r\n    else if (fieldInfo.PropID == kpidPackSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);\r\n    else if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      wchar_t textString[32];\r\n      ConvertUInt64ToString(numFiles, textString);\r\n      UString temp = textString;\r\n      temp += L\" \";\r\n      temp += kFilesMessage;\r\n      temp += L\", \";\r\n      ConvertUInt64ToString(numDirs, textString);\r\n      temp += textString;\r\n      temp += L\" \";\r\n      temp += kDirsMessage;\r\n      PrintString(fieldInfo.TextAdjustment, 0, temp);\r\n    }\r\n    else\r\n      PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L\"\");\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nbool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  if (archive->GetProperty(index, propID, &prop) != S_OK)\r\n    throw \"GetPropertyValue error\";\r\n  if (prop.vt == VT_EMPTY)\r\n    return false;\r\n  value = ConvertPropVariantToUInt64(prop);\r\n  return true;\r\n}\r\n\r\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode,\r\n    #ifndef _NO_CRYPTO\r\n    bool &passwordEnabled, UString &password,\r\n    #endif\r\n    UInt64 &numErrors)\r\n{\r\n  numErrors = 0;\r\n  CFieldPrinter fieldPrinter;\r\n  if (!techMode)\r\n    fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));\r\n\r\n  UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;\r\n  UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;\r\n  for (int i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archiveName = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archiveName, fi) || fi.IsDir())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not file\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    CArchiveLink archiveLink;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &g_StdOut;\r\n\r\n    #ifndef _NO_CRYPTO\r\n\r\n    openCallback.PasswordIsDefined = passwordEnabled;\r\n    openCallback.Password = password;\r\n\r\n    #endif\r\n\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, &openCallback);\r\n    if (result != S_OK)\r\n    {\r\n      if (result == E_ABORT)\r\n        return result;\r\n      g_StdOut << endl << \"Error: \" << archiveName << \": \";\r\n      if (result == S_FALSE)\r\n        g_StdOut << \"is not supported archive\";\r\n      else if (result == E_OUTOFMEMORY)\r\n        g_StdOut << \"Can't allocate required memory\";\r\n      else\r\n        g_StdOut << NError::MyFormatMessage(result);\r\n      g_StdOut << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n      }\r\n    }\r\n\r\n    IInArchive *archive = archiveLink.GetArchive();\r\n    const UString defaultItemName = archiveLink.GetDefaultItemName();\r\n\r\n    if (enableHeaders)\r\n    {\r\n      g_StdOut << endl << kListing << archiveName << endl << endl;\r\n\r\n      UInt32 numProps;\r\n      if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)\r\n      {\r\n        for (UInt32 i = 0; i < numProps; i++)\r\n        {\r\n          CMyComBSTR name;\r\n          PROPID propID;\r\n          VARTYPE vt;\r\n          if (archive->GetArchivePropertyInfo(i, &name, &propID, &vt) != S_OK)\r\n            continue;\r\n          NCOM::CPropVariant prop;\r\n          if (archive->GetArchiveProperty(propID, &prop) != S_OK)\r\n            continue;\r\n          UString s = ConvertPropertyToString(prop, propID);\r\n          if (!s.IsEmpty())\r\n            g_StdOut << GetPropName(propID, name) << \" = \" << s << endl;\r\n        }\r\n      }\r\n      if (techMode)\r\n        g_StdOut << \"----------\\n\";\r\n      if (numProps > 0)\r\n        g_StdOut << endl;\r\n    }\r\n\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitle();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n    }\r\n\r\n    if (techMode)\r\n    {\r\n      RINOK(fieldPrinter.Init(archive));\r\n    }\r\n    UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0;\r\n    UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;\r\n    UInt32 numItems;\r\n    RINOK(archive->GetNumberOfItems(&numItems));\r\n    for(UInt32 i = 0; i < numItems; i++)\r\n    {\r\n      if (NConsoleClose::TestBreakSignal())\r\n        return E_ABORT;\r\n\r\n      UString filePath;\r\n      RINOK(GetArchiveItemPath(archive, i, defaultItemName, filePath));\r\n\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n      if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n        continue;\r\n      \r\n      fieldPrinter.PrintItemInfo(archive, defaultItemName, i, techMode);\r\n      \r\n      UInt64 packSize, unpackSize;\r\n      if (!GetUInt64Value(archive, i, kpidSize, unpackSize))\r\n        unpackSize = 0;\r\n      else\r\n        totalUnPackSizePointer = &totalUnPackSize;\r\n      if (!GetUInt64Value(archive, i, kpidPackSize, packSize))\r\n        packSize = 0;\r\n      else\r\n        totalPackSizePointer = &totalPackSize;\r\n      \r\n      g_StdOut << endl;\r\n\r\n      if (isFolder)\r\n        numDirs++;\r\n      else\r\n        numFiles++;\r\n      totalPackSize += packSize;\r\n      totalUnPackSize += unpackSize;\r\n    }\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintSummaryInfo(numFiles, numDirs, totalUnPackSizePointer, totalPackSizePointer);\r\n      g_StdOut << endl;\r\n    }\r\n    if (totalPackSizePointer != 0)\r\n    {\r\n      totalPackSizePointer2 = &totalPackSize2;\r\n      totalPackSize2 += totalPackSize;\r\n    }\r\n    if (totalUnPackSizePointer != 0)\r\n    {\r\n      totalUnPackSizePointer2 = &totalUnPackSize2;\r\n      totalUnPackSize2 += totalUnPackSize;\r\n    }\r\n    numFiles2 += numFiles;\r\n    numDirs2 += numDirs;\r\n  }\r\n  if (enableHeaders && !techMode && archivePaths.Size() > 1)\r\n  {\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintTitleLines();\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintSummaryInfo(numFiles2, numDirs2, totalUnPackSizePointer2, totalPackSizePointer2);\r\n    g_StdOut << endl;\r\n    g_StdOut << \"Archives: \" << archivePaths.Size() << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/List.h",
    "content": "// List.h\r\n\r\n#ifndef __LIST_H\r\n#define __LIST_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode,\r\n    #ifndef _NO_CRYPTO\r\n    bool &passwordEnabled, UString &password,\r\n    #endif\r\n    UInt64 &errors);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/Main.cpp",
    "content": "// Main.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n\r\n#include \"Common/CommandLineParser.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/Error.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/MemoryLock.h\"\r\n#endif\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/UpdateAction.h\"\r\n#include \"../Common/Update.h\"\r\n#include \"../Common/Extract.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"../Common/ExitCode.h\"\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../Common/LoadCodecs.h\"\r\n#endif\r\n\r\n#include \"../../Compress/LZMA_Alone/LzmaBenchCon.h\"\r\n\r\n#include \"List.h\"\r\n#include \"OpenCallbackConsole.h\"\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\n#if defined( _WIN32) && defined( _7ZIP_LARGE_PAGES)\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NCommandLineParser;\r\n\r\nHINSTANCE g_hInstance = 0;\r\nextern CStdOutStream *g_StdStream;\r\n\r\nstatic const char *kCopyrightString = \"\\n7-Zip\"\r\n#ifndef EXTERNAL_CODECS\r\n\" (A)\"\r\n#endif\r\n\r\n#ifdef _WIN64\r\n\" [64]\"\r\n#endif\r\n\r\n\" \" MY_VERSION_COPYRIGHT_DATE \"\\n\";\r\n\r\nstatic const char *kHelpString =\r\n    \"\\nUsage: 7z\"\r\n#ifdef _NO_CRYPTO\r\n    \"r\"\r\n#else\r\n#ifndef EXTERNAL_CODECS\r\n    \"a\"\r\n#endif\r\n#endif\r\n    \" <command> [<switches>...] <archive_name> [<file_names>...]\\n\"\r\n    \"       [<@listfiles...>]\\n\"\r\n    \"\\n\"\r\n    \"<Commands>\\n\"\r\n    \"  a: Add files to archive\\n\"\r\n    \"  b: Benchmark\\n\"\r\n    \"  d: Delete files from archive\\n\"\r\n    \"  e: Extract files from archive (without using directory names)\\n\"\r\n    \"  l: List contents of archive\\n\"\r\n//    \"  l[a|t][f]: List contents of archive\\n\"\r\n//    \"    a - with Additional fields\\n\"\r\n//    \"    t - with all fields\\n\"\r\n//    \"    f - with Full pathnames\\n\"\r\n    \"  t: Test integrity of archive\\n\"\r\n    \"  u: Update files to archive\\n\"\r\n    \"  x: eXtract files with full paths\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -ai[r[-|0]]{@listfile|!wildcard}: Include archives\\n\"\r\n    \"  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives\\n\"\r\n    \"  -bd: Disable percentage indicator\\n\"\r\n    \"  -i[r[-|0]]{@listfile|!wildcard}: Include filenames\\n\"\r\n    \"  -m{Parameters}: set compression Method\\n\"\r\n    \"  -o{Directory}: set Output directory\\n\"\r\n    #ifndef _NO_CRYPTO\r\n    \"  -p{Password}: set Password\\n\"\r\n    #endif\r\n    \"  -r[-|0]: Recurse subdirectories\\n\"\r\n    \"  -scs{UTF-8 | WIN | DOS}: set charset for list files\\n\"\r\n    \"  -sfx[{name}]: Create SFX archive\\n\"\r\n    \"  -si[{name}]: read data from stdin\\n\"\r\n    \"  -slt: show technical information for l (List) command\\n\"\r\n    \"  -so: write data to stdout\\n\"\r\n    \"  -ssc[-]: set sensitive case mode\\n\"\r\n    \"  -ssw: compress shared files\\n\"\r\n    \"  -t{Type}: Set type of archive\\n\"\r\n    \"  -v{Size}[b|k|m|g]: Create volumes\\n\"\r\n    \"  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\\n\"\r\n    \"  -w[{path}]: assign Work directory. Empty path means a temporary directory\\n\"\r\n    \"  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\\n\"\r\n    \"  -y: assume Yes on all queries\\n\";\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\"; // NExitCode::kUserError\r\nstatic const char *kNoFormats = \"7-Zip cannot find the code that works with archives.\";\r\n\r\nstatic const wchar_t *kDefaultSfxModule = L\"7zCon.sfx\";\r\n\r\nstatic void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code)\r\n{\r\n  s << message << endl;\r\n  throw code;\r\n}\r\n\r\nstatic void PrintHelpAndExit(CStdOutStream &s) // yyy\r\n{\r\n  s << kHelpString;\r\n  ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError);\r\n}\r\n\r\n#ifndef _WIN32\r\nstatic void GetArguments(int numArguments, const char *arguments[], UStringVector &parts)\r\n{\r\n  parts.Clear();\r\n  for(int i = 0; i < numArguments; i++)\r\n  {\r\n    UString s = MultiByteToUnicodeString(arguments[i]);\r\n    parts.Add(s);\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp)\r\n{\r\n  s << kCopyrightString;\r\n  // s << \"# CPUs: \" << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << \"\\n\";\r\n  if (needHelp)\r\n    s << kHelpString;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic void PrintString(CStdOutStream &stdStream, const AString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n#endif\r\n\r\nstatic void PrintString(CStdOutStream &stdStream, const UString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n\r\nstatic inline char GetHex(Byte value)\r\n{\r\n  return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nconst char *kUnsupportedArcTypeMessage = \"Unsupported archive type\";\r\n\r\nint Main2(\r\n  #ifndef _WIN32\r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n)\r\n{\r\n  #ifdef _WIN32\r\n  SetFileApisToOEM();\r\n  #endif\r\n  \r\n  UStringVector commandStrings;\r\n  #ifdef _WIN32\r\n  NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);\r\n  #else\r\n  GetArguments(numArguments, arguments, commandStrings);\r\n  #endif\r\n\r\n  if(commandStrings.Size() == 1)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n  commandStrings.Delete(0);\r\n\r\n  CArchiveCommandLineOptions options;\r\n\r\n  CArchiveCommandLineParser parser;\r\n\r\n  parser.Parse1(commandStrings, options);\r\n\r\n  if(options.HelpMode)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  if (options.LargePages)\r\n  {\r\n    SetLargePageSize();\r\n    NSecurity::EnableLockMemoryPrivilege();\r\n  }\r\n  #endif\r\n\r\n  CStdOutStream &stdStream = options.StdOutMode ? g_StdErr : g_StdOut;\r\n  g_StdStream = &stdStream;\r\n\r\n  if (options.EnableHeaders)\r\n    ShowCopyrightAndHelp(stdStream, false);\r\n\r\n  parser.Parse2(options);\r\n\r\n  CCodecs *codecs = new CCodecs;\r\n  CMyComPtr<\r\n    #ifdef EXTERNAL_CODECS\r\n    ICompressCodecsInfo\r\n    #else\r\n    IUnknown\r\n    #endif\r\n    > compressCodecsInfo = codecs;\r\n  HRESULT result = codecs->Load();\r\n  if (result != S_OK)\r\n    throw CSystemException(result);\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  if (codecs->Formats.Size() == 0 &&\r\n        (isExtractGroupCommand ||\r\n        options.Command.CommandType == NCommandType::kList ||\r\n        options.Command.IsFromUpdateGroup()))\r\n    throw kNoFormats;\r\n\r\n  CIntVector formatIndices;\r\n  if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices))\r\n    throw kUnsupportedArcTypeMessage;\r\n\r\n  if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n    stdStream << endl << \"Formats:\" << endl;\r\n    int i;\r\n    for (i = 0; i < codecs->Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = codecs->Formats[i];\r\n      #ifdef EXTERNAL_CODECS\r\n      if (arc.LibIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(arc.LibIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n      #endif\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(arc.UpdateEnabled ? 'C' : ' ');\r\n      stdStream << (char)(arc.KeepName ? 'K' : ' ');\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, arc.Name, 6);\r\n      stdStream << \"  \";\r\n      UString s;\r\n      for (int t = 0; t < arc.Exts.Size(); t++)\r\n      {\r\n        const CArcExtInfo &ext = arc.Exts[t];\r\n        s += ext.Ext;\r\n        if (!ext.AddExt.IsEmpty())\r\n        {\r\n          s += L\" (\";\r\n          s += ext.AddExt;\r\n          s += L')';\r\n        }\r\n        s += L' ';\r\n      }\r\n      PrintString(stdStream, s, 14);\r\n      stdStream << \"  \";\r\n      const CByteBuffer &sig = arc.StartSignature;\r\n      for (size_t j = 0; j < sig.GetCapacity(); j++)\r\n      {\r\n        Byte b = sig[j];\r\n        if (b > 0x20 && b < 0x80)\r\n        {\r\n          stdStream << (char)b;\r\n        }\r\n        else\r\n        {\r\n          stdStream << GetHex((Byte)((b >> 4) & 0xF));\r\n          stdStream << GetHex((Byte)(b & 0xF));\r\n        }\r\n        stdStream << ' ';\r\n      }\r\n      stdStream << endl;\r\n    }\r\n    stdStream << endl << \"Codecs:\" << endl;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    UInt32 numMethods;\r\n    if (codecs->GetNumberOfMethods(&numMethods) == S_OK)\r\n    for (UInt32 j = 0; j < numMethods; j++)\r\n    {\r\n      int libIndex = codecs->GetCodecLibIndex(j);\r\n      if (libIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(libIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(codecs->GetCodecEncoderIsAssigned(j) ? 'C' : ' ');\r\n      UInt64 id;\r\n      stdStream << \"  \";\r\n      HRESULT res = codecs->GetCodecId(j, id);\r\n      if (res != S_OK)\r\n        id = (UInt64)(Int64)-1;\r\n      char s[32];\r\n      ConvertUInt64ToString(id, s, 16);\r\n      PrintString(stdStream, s, 8);\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, codecs->GetCodecName(j), 11);\r\n      stdStream << endl;\r\n      /*\r\n      if (res != S_OK)\r\n        throw \"incorrect Codec ID\";\r\n      */\r\n    }\r\n    #endif\r\n    return S_OK;\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    if (options.Method.CompareNoCase(L\"CRC\") == 0)\r\n    {\r\n      HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nCRC Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      HRESULT res = LzmaBenchCon(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        (FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nDecoding Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n  }\r\n  else if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if(isExtractGroupCommand)\r\n    {\r\n      CExtractCallbackConsole *ecs = new CExtractCallbackConsole;\r\n      CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;\r\n\r\n      ecs->OutStream = &stdStream;\r\n\r\n      #ifndef _NO_CRYPTO\r\n      ecs->PasswordIsDefined = options.PasswordEnabled;\r\n      ecs->Password = options.Password;\r\n      #endif\r\n\r\n      ecs->Init();\r\n\r\n      COpenCallbackConsole openCallback;\r\n      openCallback.OutStream = &stdStream;\r\n\r\n      #ifndef _NO_CRYPTO\r\n      openCallback.PasswordIsDefined = options.PasswordEnabled;\r\n      openCallback.Password = options.Password;\r\n      #endif\r\n\r\n      CExtractOptions eo;\r\n      eo.StdOutMode = options.StdOutMode;\r\n      eo.PathMode = options.Command.GetPathMode();\r\n      eo.TestMode = options.Command.IsTestMode();\r\n      eo.OverwriteMode = options.OverwriteMode;\r\n      eo.OutputDir = options.OutputDir;\r\n      eo.YesToAll = options.YesToAll;\r\n      #ifdef COMPRESS_MT\r\n      eo.Properties = options.ExtractProperties;\r\n      #endif\r\n      UString errorMessage;\r\n      CDecompressStat stat;\r\n      HRESULT result = DecompressArchives(\r\n          codecs,\r\n          formatIndices,\r\n          options.ArchivePathsSorted,\r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head,\r\n          eo, &openCallback, ecs, errorMessage, stat);\r\n      if (!errorMessage.IsEmpty())\r\n      {\r\n        stdStream << endl << \"Error: \" << errorMessage;\r\n        if (result == S_OK)\r\n          result = E_FAIL;\r\n      }\r\n\r\n      stdStream << endl;\r\n      if (ecs->NumArchives > 1)\r\n        stdStream << \"Archives: \" << ecs->NumArchives << endl;\r\n      if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0)\r\n      {\r\n        if (ecs->NumArchives > 1)\r\n        {\r\n          stdStream << endl;\r\n          if (ecs->NumArchiveErrors != 0)\r\n            stdStream << \"Archive Errors: \" << ecs->NumArchiveErrors << endl;\r\n          if (ecs->NumFileErrors != 0)\r\n            stdStream << \"Sub items Errors: \" << ecs->NumFileErrors << endl;\r\n        }\r\n        if (result != S_OK)\r\n          throw CSystemException(result);\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n      if (stat.NumFolders != 0)\r\n        stdStream << \"Folders: \" << stat.NumFolders << endl;\r\n      if (stat.NumFiles != 1 || stat.NumFolders != 0)\r\n          stdStream << \"Files: \" << stat.NumFiles << endl;\r\n      stdStream\r\n           << \"Size:       \" << stat.UnpackSize << endl\r\n           << \"Compressed: \" << stat.PackSize << endl;\r\n    }\r\n    else\r\n    {\r\n      UInt64 numErrors = 0;\r\n      HRESULT result = ListArchives(\r\n          codecs,\r\n          formatIndices,\r\n          options.ArchivePathsSorted,\r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head,\r\n          options.EnableHeaders,\r\n          options.TechMode,\r\n          #ifndef _NO_CRYPTO\r\n          options.PasswordEnabled,\r\n          options.Password,\r\n          #endif\r\n          numErrors);\r\n      if (numErrors > 0)\r\n      {\r\n        g_StdOut << endl << \"Errors: \" << numErrors;\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    UString workingDir;\r\n\r\n    CUpdateOptions &uo = options.UpdateOptions;\r\n    if (uo.SfxMode && uo.SfxModule.IsEmpty())\r\n      uo.SfxModule = kDefaultSfxModule;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &stdStream;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    bool passwordIsDefined =\r\n        options.PasswordEnabled && !options.Password.IsEmpty();\r\n    openCallback.PasswordIsDefined = passwordIsDefined;\r\n    openCallback.Password = options.Password;\r\n    #endif\r\n\r\n    CUpdateCallbackConsole callback;\r\n    callback.EnablePercents = options.EnablePercents;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    callback.PasswordIsDefined = passwordIsDefined;\r\n    callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty();\r\n    callback.Password = options.Password;\r\n    #endif\r\n    callback.StdOutMode = uo.StdOutMode;\r\n    callback.Init(&stdStream);\r\n\r\n    CUpdateErrorInfo errorInfo;\r\n\r\n    if (!uo.Init(codecs, formatIndices, options.ArchiveName))\r\n      throw kUnsupportedArcTypeMessage;\r\n    HRESULT result = UpdateArchive(codecs,\r\n        options.WildcardCensor, uo,\r\n        errorInfo, &openCallback, &callback);\r\n\r\n    int exitCode = NExitCode::kSuccess;\r\n    if (callback.CantFindFiles.Size() > 0)\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      int numErrors = callback.CantFindFiles.Size();\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.CantFindFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.CantFindCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot find \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n\r\n    if (result != S_OK)\r\n    {\r\n      UString message;\r\n      if (!errorInfo.Message.IsEmpty())\r\n      {\r\n        message += errorInfo.Message;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName2.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName2;\r\n        message += L\"\\n\";\r\n      }\r\n      if (errorInfo.SystemError != 0)\r\n      {\r\n        message += NError::MyFormatMessageW(errorInfo.SystemError);\r\n        message += L\"\\n\";\r\n      }\r\n      if (!message.IsEmpty())\r\n        stdStream << L\"\\nError:\\n\" << message;\r\n      throw CSystemException(result);\r\n    }\r\n    int numErrors = callback.FailedFiles.Size();\r\n    if (numErrors == 0)\r\n    {\r\n      if (callback.CantFindFiles.Size() == 0)\r\n        stdStream << kEverythingIsOk << endl;\r\n    }\r\n    else\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.FailedFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.FailedCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot open \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n    return exitCode;\r\n  }\r\n  else\r\n    PrintHelpAndExit(stdStream);\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/MainAr.cpp",
    "content": "// MainAr.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <locale.h>\r\n\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"../Common/ExitCode.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCStdOutStream *g_StdStream = 0;\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\n#endif\r\n#if !defined(_UNICODE) || !defined(_WIN64)\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern int Main2(\r\n  #ifndef _WIN32\r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n);\r\n\r\nstatic const char *kExceptionErrorMessage = \"\\n\\nError:\\n\";\r\nstatic const char *kUserBreak  = \"\\nBreak signaled\\n\";\r\n\r\nstatic const char *kMemoryExceptionMessage = \"\\n\\nERROR: Can't allocate required memory!\\n\";\r\nstatic const char *kUnknownExceptionMessage = \"\\n\\nUnknown Error\\n\";\r\nstatic const char *kInternalExceptionMessage = \"\\n\\nInternal Error #\";\r\n\r\nint MY_CDECL main\r\n(\r\n#ifndef _WIN32\r\nint numArguments, const char *arguments[]\r\n#endif\r\n)\r\n{\r\n  g_StdStream = &g_StdOut;\r\n  #ifdef _WIN32\r\n  \r\n  #ifdef _UNICODE\r\n  #ifndef _WIN64\r\n  if (!IsItWindowsNT())\r\n  {\r\n    (*g_StdStream) << \"This program requires Windows NT/2000/2003/2008/XP/Vista\";\r\n    return NExitCode::kFatalError;\r\n  }\r\n  #endif\r\n  #else\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  \r\n  #endif\r\n\r\n  // setlocale(LC_COLLATE, \".OCP\");\r\n  NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;\r\n  int res = 0;\r\n  try\r\n  {\r\n    res = Main2(\r\n#ifndef _WIN32\r\n      numArguments, arguments\r\n#endif\r\n    );\r\n  }\r\n  catch(const CNewException &)\r\n  {\r\n    (*g_StdStream) << kMemoryExceptionMessage;\r\n    return (NExitCode::kMemoryError);\r\n  }\r\n  catch(const NConsoleClose::CCtrlBreakException &)\r\n  {\r\n    (*g_StdStream) << endl << kUserBreak;\r\n    return (NExitCode::kUserBreak);\r\n  }\r\n  catch(const CArchiveCommandLineException &e)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << e << endl;\r\n    return (NExitCode::kUserError);\r\n  }\r\n  catch(const CSystemException &systemError)\r\n  {\r\n    if (systemError.ErrorCode == E_OUTOFMEMORY)\r\n    {\r\n      (*g_StdStream) << kMemoryExceptionMessage;\r\n      return (NExitCode::kMemoryError);\r\n    }\r\n    if (systemError.ErrorCode == E_ABORT)\r\n    {\r\n      (*g_StdStream) << endl << kUserBreak;\r\n      return (NExitCode::kUserBreak);\r\n    }\r\n    UString message;\r\n    NError::MyFormatMessage(systemError.ErrorCode, message);\r\n    (*g_StdStream) << endl << endl << \"System error:\" << endl <<\r\n        message << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(NExitCode::EEnum &exitCode)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << exitCode << endl;\r\n    return (exitCode);\r\n  }\r\n  /*\r\n  catch(const NExitCode::CMultipleErrors &multipleErrors)\r\n  {\r\n    (*g_StdStream) << endl << multipleErrors.NumErrors << \" errors\" << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  */\r\n  catch(const UString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const AString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const char *s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(int t)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << t << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(...)\r\n  {\r\n    (*g_StdStream) << kUnknownExceptionMessage;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  return  res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/OpenCallbackConsole.cpp",
    "content": "// OpenCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nHRESULT COpenCallbackConsole::Open_CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_SetTotal(const UInt64 *, const UInt64 *)\r\n{\r\n  return Open_CheckBreak();\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_SetCompleted(const UInt64 *, const UInt64 *)\r\n{\r\n  return Open_CheckBreak();\r\n}\r\n \r\n#ifndef _NO_CRYPTO\r\n\r\nHRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password)\r\n{\r\n  PasswordWasAsked = true;\r\n  RINOK(Open_CheckBreak());\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream);\r\n    PasswordIsDefined = true;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_GetPasswordIfAny(UString &password)\r\n{\r\n  if (PasswordIsDefined)\r\n    password = Password;\r\n  return S_OK;\r\n}\r\n\r\nbool COpenCallbackConsole::Open_WasPasswordAsked()\r\n{\r\n  return PasswordWasAsked;\r\n}\r\n\r\nvoid COpenCallbackConsole::Open_ClearPasswordWasAskedFlag()\r\n{\r\n  PasswordWasAsked = false;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/OpenCallbackConsole.h",
    "content": "// OpenCallbackConsole.h\r\n\r\n#ifndef __OPENCALLBACKCONSOLE_H\r\n#define __OPENCALLBACKCONSOLE_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../Common/ArchiveOpenCallback.h\"\r\n\r\nclass COpenCallbackConsole: public IOpenCallbackUI\r\n{\r\npublic:\r\n  INTERFACE_IOpenCallbackUI(;)\r\n  \r\n  CStdOutStream *OutStream;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordIsDefined;\r\n  bool PasswordWasAsked;\r\n  UString Password;\r\n  COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {}\r\n  #endif\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/PercentPrinter.cpp",
    "content": "// PercentPrinter.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"PercentPrinter.h\"\r\n\r\nconst int kPaddingSize = 2;\r\nconst int kPercentsSize = 4;\r\nconst int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;\r\n\r\nstatic void ClearPrev(char *p, int num)\r\n{\r\n  int i;\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  for (i = 0; i < num; i++) *p++ = ' ';\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  *p = '\\0';\r\n}\r\n\r\nvoid CPercentPrinter::ClosePrint()\r\n{\r\n  if (m_NumExtraChars == 0)\r\n    return;\r\n  char s[kMaxExtraSize * 3 + 1];\r\n  ClearPrev(s, m_NumExtraChars);\r\n  (*OutStream) << s;\r\n  m_NumExtraChars = 0;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const char *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const wchar_t *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintNewLine()\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << \"\\n\";\r\n}\r\n\r\nvoid CPercentPrinter::RePrintRatio()\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s);\r\n  int size = (int)strlen(s);\r\n  s[size++] = '%';\r\n  s[size] = '\\0';\r\n\r\n  int extraSize = kPaddingSize + MyMax(size, kPercentsSize);\r\n  if (extraSize < m_NumExtraChars)\r\n    extraSize = m_NumExtraChars;\r\n\r\n  char fullString[kMaxExtraSize * 3];\r\n  char *p = fullString;\r\n  int i;\r\n  if (m_NumExtraChars == 0)\r\n  {\r\n    for (i = 0; i < extraSize; i++)\r\n      *p++ = ' ';\r\n    m_NumExtraChars = extraSize;\r\n  }\r\n\r\n  for (i = 0; i < m_NumExtraChars; i++)\r\n    *p++ = '\\b';\r\n  m_NumExtraChars = extraSize;\r\n  for (; size < m_NumExtraChars; size++)\r\n    *p++ = ' ';\r\n  MyStringCopy(p, s);\r\n  (*OutStream) << fullString;\r\n  OutStream->Flush();\r\n  m_PrevValue = m_CurValue;\r\n}\r\n\r\nvoid CPercentPrinter::PrintRatio()\r\n{\r\n  if (m_CurValue < m_PrevValue + m_MinStepSize &&\r\n      m_CurValue + m_MinStepSize > m_PrevValue && m_NumExtraChars != 0)\r\n    return;\r\n  RePrintRatio();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/PercentPrinter.h",
    "content": "// PercentPrinter.h\r\n\r\n#ifndef __PERCENTPRINTER_H\r\n#define __PERCENTPRINTER_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/StdOutStream.h\"\r\n\r\nclass CPercentPrinter\r\n{\r\n  UInt64 m_MinStepSize;\r\n  UInt64 m_PrevValue;\r\n  UInt64 m_CurValue;\r\n  UInt64 m_Total;\r\n  int m_NumExtraChars;\r\npublic:\r\n  CStdOutStream *OutStream;\r\n\r\n  CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize),\r\n      m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}\r\n  void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }\r\n  void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }\r\n  void PrintString(const char *s);\r\n  void PrintString(const wchar_t *s);\r\n  void PrintNewLine();\r\n  void ClosePrint();\r\n  void RePrintRatio();\r\n  void PrintRatio();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp",
    "content": "// UpdateCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifdef COMPRESS_MT\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nusing namespace NWindows;\r\n\r\n#ifdef COMPRESS_MT\r\nstatic NSynchronization::CCriticalSection g_CriticalSection;\r\n#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);\r\n#else\r\n#define MT_LOCK\r\n#endif\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nstatic const char *kCreatingArchiveMessage = \"Creating archive \";\r\nstatic const char *kUpdatingArchiveMessage = \"Updating archive \";\r\nstatic const char *kScanningMessage = \"Scanning\";\r\n\r\n\r\nHRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n    (*OutStream) << \"Error: \" << name << \" is not supported archive\" << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartScanning()\r\n{\r\n  (*OutStream) << kScanningMessage;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::ScanProgress(UInt64 /* numFolders */, UInt64 /* numFiles */, const wchar_t * /* path */)\r\n{\r\n  return CheckBreak();\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)\r\n{\r\n  CantFindFiles.Add(name);\r\n  CantFindCodes.Add(systemError);\r\n  // m_PercentPrinter.ClosePrint();\r\n  if (!m_WarningsMode)\r\n  {\r\n    (*OutStream) << endl << endl;\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_WarningsMode = true;\r\n  }\r\n  m_PercentPrinter.PrintString(name);\r\n  m_PercentPrinter.PrintString(\":  WARNING: \");\r\n  m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n  m_PercentPrinter.PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishScanning()\r\n{\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)\r\n{\r\n  if(updating)\r\n    (*OutStream) << kUpdatingArchiveMessage;\r\n  else\r\n    (*OutStream) << kCreatingArchiveMessage;\r\n  if (name != 0)\r\n    (*OutStream) << name;\r\n  else\r\n    (*OutStream) << \"StdOut\";\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishArchive()\r\n{\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::Finilize()\r\n{\r\n  MT_LOCK\r\n  if (m_NeedBeClosed)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.ClosePrint();\r\n    }\r\n    if (!StdOutMode && m_NeedNewLine)\r\n    {\r\n      m_PercentPrinter.PrintNewLine();\r\n      m_NeedNewLine = false;\r\n    }\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)\r\n{\r\n  MT_LOCK\r\n  if (EnablePercents)\r\n    m_PercentPrinter.SetTotal(size);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  MT_LOCK\r\n  if (completeValue != NULL)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.SetRatio(*completeValue);\r\n      m_PercentPrinter.PrintRatio();\r\n      m_NeedBeClosed = true;\r\n    }\r\n  }\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)\r\n{\r\n  MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  if(isAnti)\r\n    m_PercentPrinter.PrintString(\"Anti item    \");\r\n  else\r\n    m_PercentPrinter.PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)\r\n{\r\n  MT_LOCK\r\n  FailedCodes.Add(systemError);\r\n  FailedFiles.Add(name);\r\n  // if (systemError == ERROR_SHARING_VIOLATION)\r\n  {\r\n    m_PercentPrinter.ClosePrint();\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_PercentPrinter.PrintString(\"WARNING: \");\r\n    m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n    return S_FALSE;\r\n  }\r\n  // return systemError;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )\r\n{\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  #ifdef _NO_CRYPTO\r\n\r\n  *passwordIsDefined = false;\r\n  return StringToBstr(L\"\", password);\r\n  \r\n  #else\r\n  \r\n  if (!PasswordIsDefined)\r\n  {\r\n    if (AskPassword)\r\n    {\r\n      Password = GetPassword(OutStream);\r\n      PasswordIsDefined = true;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  return StringToBstr(Password, password);\r\n  \r\n  #endif\r\n  \r\n}\r\n\r\n/*\r\nHRESULT CUpdateCallbackConsole::ShowDeleteFile(const wchar_t *name)\r\n{\r\n  // MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  RINOK(Finilize());\r\n  m_PercentPrinter.PrintString(\"Deleting  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/UpdateCallbackConsole.h",
    "content": "// UpdateCallbackConsole.h\r\n\r\n#ifndef __UPDATECALLBACKCONSOLE_H\r\n#define __UPDATECALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"PercentPrinter.h\"\r\n#include \"../Common/Update.h\"\r\n\r\nclass CUpdateCallbackConsole: public IUpdateCallbackUI2\r\n{\r\n  CPercentPrinter m_PercentPrinter;\r\n  bool m_NeedBeClosed;\r\n  bool m_NeedNewLine;\r\n\r\n  bool m_WarningsMode;\r\n\r\n  CStdOutStream *OutStream;\r\npublic:\r\n  bool EnablePercents;\r\n  bool StdOutMode;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n  #endif\r\n\r\n  CUpdateCallbackConsole():\r\n      m_PercentPrinter(1 << 16),\r\n      #ifndef _NO_CRYPTO\r\n      PasswordIsDefined(false),\r\n      AskPassword(false),\r\n      #endif\r\n      StdOutMode(false),\r\n      EnablePercents(true),\r\n      m_WarningsMode(false)\r\n      {}\r\n  \r\n  ~CUpdateCallbackConsole() { Finilize(); }\r\n  void Init(CStdOutStream *outStream)\r\n  {\r\n    m_NeedBeClosed = false;\r\n    m_NeedNewLine = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n    OutStream = outStream;\r\n    m_PercentPrinter.OutStream = outStream;\r\n  }\r\n\r\n  INTERFACE_IUpdateCallbackUI2(;)\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  UStringVector CantFindFiles;\r\n  CRecordVector<HRESULT> CantFindCodes;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/UserInputUtils.cpp",
    "content": "// UserInputUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StdInStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"UserInputUtils.h\"\r\n\r\nstatic const char kYes = 'Y';\r\nstatic const char kNo = 'N';\r\nstatic const char kYesAll = 'A';\r\nstatic const char kNoAll = 'S';\r\nstatic const char kAutoRenameAll = 'U';\r\nstatic const char kQuit = 'Q';\r\n\r\nstatic const char *kFirstQuestionMessage = \"?\\n\";\r\nstatic const char *kHelpQuestionMessage =\r\n  \"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? \";\r\n\r\n// return true if pressed Quite;\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << kFirstQuestionMessage;\r\n  for(;;)\r\n  {\r\n    (*outStream) << kHelpQuestionMessage;\r\n    AString scannedString = g_StdIn.ScanStringUntilNewLine();\r\n    scannedString.Trim();\r\n    if(!scannedString.IsEmpty())\r\n      switch(::MyCharUpper(scannedString[0]))\r\n      {\r\n        case kYes:\r\n          return NUserAnswerMode::kYes;\r\n        case kNo:\r\n          return NUserAnswerMode::kNo;\r\n        case kYesAll:\r\n          return NUserAnswerMode::kYesAll;\r\n        case kNoAll:\r\n          return NUserAnswerMode::kNoAll;\r\n        case kAutoRenameAll:\r\n          return NUserAnswerMode::kAutoRenameAll;\r\n        case kQuit:\r\n          return NUserAnswerMode::kQuit;\r\n      }\r\n  }\r\n}\r\n\r\nUString GetPassword(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << \"\\nEnter password:\";\r\n  outStream->Flush();\r\n  AString oemPassword = g_StdIn.ScanStringUntilNewLine();\r\n  return MultiByteToUnicodeString(oemPassword, CP_OEMCP);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/UserInputUtils.h",
    "content": "// UserInputUtils.h\r\n\r\n#ifndef __USERINPUTUTILS_H\r\n#define __USERINPUTUTILS_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n\r\nnamespace NUserAnswerMode {\r\n\r\nenum EEnum\r\n{\r\n  kYes,\r\n  kNo,\r\n  kYesAll,\r\n  kNoAll,\r\n  kAutoRenameAll,\r\n  kQuit\r\n};\r\n}\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);\r\nUString GetPassword(CStdOutStream *outStream);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/7zip/UI/Console/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../  \\\r\n  -DCOMPRESS_MT \\\r\n  -DWIN_LONG_PATH \\\r\n  -DEXTERNAL_LZMA \\\r\n  -DEXTERNAL_CODECS \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n  -D_7ZIP_LARGE_PAGES \\\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Registry.obj \\\r\n  $O\\System.obj \\\r\n  $O\\Time.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\n!include \"../../Crc2.mak\"\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $O\\CopyCoder.obj \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\CopyCoder.obj: ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n!include \"../../Crc.mak\"\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Build.mak",
    "content": "!IFDEF CPU\r\n!IFNDEF NO_BUFFEROVERFLOWU\r\nLIBS = $(LIBS) bufferoverflowU.lib\r\n!ENDIF\r\n!ENDIF\r\n\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IF \"$(CPU)\" != \"IA64\"\r\n!IF \"$(CPU)\" != \"AMD64\"\r\nMY_ML = ml\r\n!ELSE\r\nMY_ML = ml64\r\n!ENDIF\r\n!ENDIF\r\n\r\nCOMPL_ASM = $(MY_ML) -c -Fo$O/ $**\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -WX -EHsc -Gr -Gy -GR-\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\n!IFDEF NEW_COMPILER\r\nCFLAGS = $(CFLAGS) -W4 -GS- -Zc:forScope\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -W3\r\n!ENDIF\r\n\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF -OPT:ICF\r\n\r\n!IFDEF DEF_FILE\r\nLFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)\r\n!ENDIF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL_PCH  = $(CPP) $(CFLAGS_O1) -Yc\"StdAfx.h\" -Fp$O/a.pch $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) -Yu\"StdAfx.h\" -Fp$O/a.pch $**\r\n\r\nall: $(PROGPATH)\r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch\r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS) $(DEF_FILE)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n$O\\resource.res: $(*B).rc\r\n\trc -fo$@ $**\r\n$O\\StdAfx.obj: $(*B).cpp\r\n\t$(COMPL_PCH)\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/AutoPtr.h",
    "content": "// Common/AutoPtr.h\r\n\r\n#ifndef __COMMON_AUTOPTR_H\r\n#define __COMMON_AUTOPTR_H\r\n\r\ntemplate<class T> class CMyAutoPtr\r\n{\r\n  T *_p;\r\npublic:\r\n  CMyAutoPtr(T *p = 0) : _p(p) {}\r\n  CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {}\r\n  CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p)\r\n  {\r\n    reset(p.release());\r\n    return (*this);\r\n  }\r\n  ~CMyAutoPtr() { delete _p; }\r\n  T& operator*() const { return *_p; }\r\n  // T* operator->() const { return (&**this); }\r\n  T* get() const { return _p; }\r\n  T* release()\r\n  {\r\n    T *tmp = _p;\r\n    _p = 0;\r\n    return tmp;\r\n  }\r\n  void reset(T* p = 0)\r\n  {\r\n    if (p != _p)\r\n      delete _p;\r\n    _p = p;\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/Buffer.h",
    "content": "// Common/Buffer.h\r\n\r\n#ifndef __COMMON_BUFFER_H\r\n#define __COMMON_BUFFER_H\r\n\r\n#include \"Defs.h\"\r\n\r\ntemplate <class T> class CBuffer\r\n{\r\nprotected:\r\n  size_t _capacity;\r\n  T *_items;\r\npublic:\r\n  void Free()\r\n  {\r\n    delete []_items;\r\n    _items = 0;\r\n    _capacity = 0;\r\n  }\r\n  CBuffer(): _capacity(0), _items(0) {};\r\n  CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }\r\n  CBuffer(size_t size): _items(0),  _capacity(0) {  SetCapacity(size); }\r\n  virtual ~CBuffer() { delete []_items; }\r\n  operator T *() { return _items; };\r\n  operator const T *() const { return _items; };\r\n  size_t GetCapacity() const { return  _capacity; }\r\n  void SetCapacity(size_t newCapacity)\r\n  {\r\n    if (newCapacity == _capacity)\r\n      return;\r\n    T *newBuffer;\r\n    if (newCapacity > 0)\r\n    {\r\n      newBuffer = new T[newCapacity];\r\n      if (_capacity > 0)\r\n        memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));\r\n    }\r\n    else\r\n      newBuffer = 0;\r\n    delete []_items;\r\n    _items = newBuffer;\r\n    _capacity = newCapacity;\r\n  }\r\n  CBuffer& operator=(const CBuffer &buffer)\r\n  {\r\n    Free();\r\n    if (buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nbool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  if (b1.GetCapacity() != b2.GetCapacity())\r\n    return false;\r\n  for (size_t i = 0; i < b1.GetCapacity(); i++)\r\n    if (b1[i] != b2[i])\r\n      return false;\r\n  return true;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  return !(b1 == b2);\r\n}\r\n\r\ntypedef CBuffer<char> CCharBuffer;\r\ntypedef CBuffer<wchar_t> CWCharBuffer;\r\ntypedef CBuffer<unsigned char> CByteBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/7zCrc.h\"\r\n}\r\n\r\nstruct CCRCTableInit { CCRCTableInit() { CrcGenerateTable(); } } g_CRCTableInit;\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nbool CInFile::OpenShared(const char *name, bool)\r\n{\r\n  return Open(name);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nbool COutFile::Open(const char *name, DWORD creationDisposition)\r\n{\r\n  return Create(name, false);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  bool OpenShared(const char *name, bool shareForWrite);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  bool Open(const char *name, DWORD creationDisposition);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else\r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  for (;;)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      break;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{\r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */);\r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms,\r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0)\r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while (pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for (int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len)\r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if (temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if (_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString:\r\n      case NSwitchType::kUnLimitedPostString:\r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for (int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\r\n    const UString &commandString, UString &postString)\r\n{\r\n  for (int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if (commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"MyString.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  {\r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms);\r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms,\r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\r\n    const UString &commandString, UString &postString);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/DynamicBuffer.h",
    "content": "// Common/DynamicBuffer.h\r\n\r\n#ifndef __COMMON_DYNAMICBUFFER_H\r\n#define __COMMON_DYNAMICBUFFER_H\r\n\r\n#include \"Buffer.h\"\r\n\r\ntemplate <class T> class CDynamicBuffer: public CBuffer<T>\r\n{\r\n  void GrowLength(size_t size)\r\n  {\r\n    size_t delta;\r\n    if (this->_capacity > 64)\r\n      delta = this->_capacity / 4;\r\n    else if (this->_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    delta = MyMax(delta, size);\r\n    SetCapacity(this->_capacity + delta);\r\n  }\r\npublic:\r\n  CDynamicBuffer(): CBuffer<T>() {};\r\n  CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};\r\n  CDynamicBuffer(size_t size): CBuffer<T>(size) {};\r\n  CDynamicBuffer& operator=(const CDynamicBuffer &buffer)\r\n  {\r\n    this->Free();\r\n    if (buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n  void EnsureCapacity(size_t capacity)\r\n  {\r\n    if (this->_capacity < capacity)\r\n      GrowLength(capacity - this->_capacity);\r\n  }\r\n};\r\n\r\ntypedef CDynamicBuffer<char> CCharDynamicBuffer;\r\ntypedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;\r\ntypedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/IntToString.cpp",
    "content": "// Common/IntToString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"IntToString.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)\r\n{\r\n  if (base < 2 || base > 36)\r\n  {\r\n    *s = '\\0';\r\n    return;\r\n  }\r\n  char temp[72];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    int delta = (int)(value % base);\r\n    temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));\r\n    value /= base;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s)\r\n{\r\n  wchar_t temp[32];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = L'\\0';\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = '-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = L'-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/IntToString.h",
    "content": "// Common/IntToString.h\r\n\r\n#ifndef __COMMON_INTTOSTRING_H\r\n#define __COMMON_INTTOSTRING_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s);\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s);\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/ListFileUtils.cpp",
    "content": "// Common/ListFileUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MyWindows.h\"\r\n#include \"../Windows/FileIO.h\"\r\n\r\n#include \"ListFileUtils.h\"\r\n#include \"StringConvert.h\"\r\n#include \"UTFConvert.h\"\r\n\r\nstatic const char kQuoteChar     = '\\\"';\r\nstatic void RemoveQuote(UString &s)\r\n{\r\n  if (s.Length() >= 2)\r\n    if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)\r\n      s = s.Mid(1, s.Length() - 2);\r\n}\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)\r\n{\r\n  NWindows::NFile::NIO::CInFile file;\r\n  if (!file.Open(fileName))\r\n    return false;\r\n  UInt64 length;\r\n  if (!file.GetLength(length))\r\n    return false;\r\n  if (length > ((UInt32)1 << 31))\r\n    return false;\r\n  AString s;\r\n  char *p = s.GetBuffer((int)length + 1);\r\n  UInt32 processed;\r\n  if (!file.Read(p, (UInt32)length, processed))\r\n    return false;\r\n  p[(UInt32)length] = 0;\r\n  s.ReleaseBuffer();\r\n  file.Close();\r\n\r\n  UString u;\r\n  #ifdef CP_UTF8\r\n  if (codePage == CP_UTF8)\r\n  {\r\n    if (!ConvertUTF8ToUnicode(s, u))\r\n      return false;\r\n  }\r\n  else\r\n  #endif\r\n    u = MultiByteToUnicodeString(s, codePage);\r\n  if (!u.IsEmpty())\r\n  {\r\n    if (u[0] == 0xFEFF)\r\n      u.Delete(0);\r\n  }\r\n\r\n  UString t;\r\n  for (int i = 0; i < u.Length(); i++)\r\n  {\r\n    wchar_t c = u[i];\r\n    if (c == L'\\n' || c == 0xD)\r\n    {\r\n      t.Trim();\r\n      RemoveQuote(t);\r\n      if (!t.IsEmpty())\r\n        resultStrings.Add(t);\r\n      t.Empty();\r\n    }\r\n    else\r\n      t += c;\r\n  }\r\n  t.Trim();\r\n  RemoveQuote(t);\r\n  if (!t.IsEmpty())\r\n    resultStrings.Add(t);\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/ListFileUtils.h",
    "content": "// Common/ListFileUtils.h\r\n\r\n#ifndef __COMMON_LISTFILEUTILS_H\r\n#define __COMMON_LISTFILEUTILS_H\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRESULT __result_ = (x); if (__result_ != S_OK) return __result_; }\r\n#endif\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p)\r\n  {\r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p)\r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\ninline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr)\r\n{\r\n  *bstr = ::SysAllocString(src);\r\n  return (*bstr != 0) ? S_OK : E_OUTOFMEMORY;\r\n}\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR(): m_str(NULL) {}\r\n  CMyComBSTR(LPCOLESTR src) { m_str = ::SysAllocString(src); }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR src)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(src);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const\r\n  {\r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memcpy(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  /*\r\n  void Attach(BSTR src) { m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  */\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) {\r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \\\r\n    { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \\\r\n    MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n    MY_QUERYINTERFACE_ENTRY(i)\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyException.h",
    "content": "// Common/Exception.h\r\n\r\n#ifndef __COMMON_EXCEPTION_H\r\n#define __COMMON_EXCEPTION_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\nstruct CSystemException\r\n{\r\n  HRESULT ErrorCode;\r\n  CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline int operator==(REFGUID g1, REFGUID g2)\r\n{\r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return 0;\r\n  return 1;\r\n}\r\ninline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyString.cpp",
    "content": "// Common/MyString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <ctype.h>\r\n#endif\r\n\r\n#ifndef _UNICODE\r\n#include \"StringConvert.h\"\r\n#endif\r\n\r\n#include \"MyString.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1);\r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1),\r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{\r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1));\r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{\r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1));\r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1);\r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1),\r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n/*\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{\r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyString.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{\r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{\r\n  T *destStart = dest;\r\n  while ((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n// int MyStringCompareNoCase(const char *s1, const char  *s2);\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if (pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex,\r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n  int _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if (realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if (newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if (_capacity > 0)\r\n    {\r\n      for (int i = 0; i < _length; i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n    }\r\n    _chars = newBuffer;\r\n    _chars[_length] = 0;\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize)\r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0) { SetCapacity(3); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;}\r\n\r\n  // The minimum size of the character buffer in characters.\r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if (minBufLength >= _capacity)\r\n      SetCapacity(minBufLength);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if (newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if (&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int Compare(const T *s) const\r\n    { return MyStringCompare(_chars, s); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const T *s) const\r\n    { return MyStringCompareNoCase(_chars, s); }\r\n\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for (int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    charSet += (T)' ';\r\n    charSet += (T)'\\n';\r\n    charSet += (T)'\\t';\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if (pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for (int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0)\r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0)\r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct\r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else\r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyVector.cpp",
    "content": "// Common/MyVector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector() { ClearAndFree(); }\r\n\r\nvoid CBaseRecordVector::ClearAndFree()\r\n{\r\n  Clear();\r\n  delete []((unsigned char *)_items);\r\n  _capacity = 0;\r\n  _size = 0;\r\n  _items = 0;\r\n}\r\n\r\nvoid CBaseRecordVector::Clear() { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index) { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if (_size != _capacity)\r\n    return;\r\n  int delta = 1;\r\n  if (_capacity >= 64)\r\n    delta = _capacity / 4;\r\n  else if (_capacity >= 8)\r\n    delta = 8;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  // if (newCapacity <= _capacity)\r\n  if (newCapacity == _capacity)\r\n    return;\r\n  if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))\r\n    throw 1052353;\r\n  size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;\r\n  if (newSize / _itemSize != (size_t)(unsigned)newCapacity)\r\n    throw 1052354;\r\n  unsigned char *p = NULL;\r\n  if (newSize > 0)\r\n  {\r\n    p = new unsigned char[newSize];\r\n    if (p == 0)\r\n      throw 1052355;\r\n    int numRecordsToMove = (_size < newCapacity ? _size : newCapacity);\r\n    memcpy(p, _items, _itemSize * numRecordsToMove);\r\n  }\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::ReserveDown()\r\n{\r\n  Reserve(_size);\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize,\r\n    ((unsigned char  *)_items) + srcIndex * _itemSize,\r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyVector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n  int _capacity;\r\n  int _size;\r\n  void *_items;\r\n  size_t _itemSize;\r\n  \r\n  void ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; }\r\npublic:\r\n  CBaseRecordVector(size_t itemSize): _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n  virtual ~CBaseRecordVector();\r\n  void ClearAndFree();\r\n  int Size() const { return _size; }\r\n  bool IsEmpty() const { return (_size == 0); }\r\n  void Reserve(int newCapacity);\r\n  void ReserveDown();\r\n  virtual void Delete(int index, int num = 1);\r\n  void Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector(): CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v): CBaseRecordVector(sizeof(T)) { *this = v; }\r\n  CRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for (int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  int Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n  void Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n  T& operator[](int index) { return ((T *)_items)[index]; }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  T& Back() { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  int AddToUniqueSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    T temp = p[k];\r\n    for (;;)\r\n    {\r\n      int s = (k << 1);\r\n      if (s > size)\r\n        break;\r\n      if (s < size && compare(p + s + 1, p + s, param) > 0)\r\n        s++;\r\n      if (compare(&temp, p + s, param) >= 0)\r\n        break;\r\n      p[k] = p[s];\r\n      k = s;\r\n    }\r\n    p[k] = temp;\r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    int size = _size;\r\n    if (size <= 1)\r\n      return;\r\n    T* p = (&Front()) - 1;\r\n    {\r\n      int i = size / 2;\r\n      do\r\n        SortRefDown(p, i, size, compare, param);\r\n      while (--i != 0);\r\n    }\r\n    do\r\n    {\r\n      T temp = p[size];\r\n      p[size--] = p[1];\r\n      p[1] = temp;\r\n      SortRefDown(p, 1, size, compare, param);\r\n    }\r\n    while (size > 1);\r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector() {};\r\n  ~CObjectVector() { Clear(); };\r\n  CObjectVector(const CObjectVector &v) { *this = v; }\r\n  CObjectVector& operator=(const CObjectVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CObjectVector& operator+=(const CObjectVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for (int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n  T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Back() { return operator[](_size - 1); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  int Add(const T& item) { return CPointerVector::Add(new T(item)); }\r\n  void Insert(int index, const T& item) { CPointerVector::Insert(index, new T(item)); }\r\n  virtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for (int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for (int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param)\r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#define CHAR_PATH_SEPARATOR '\\\\'\r\n#define WCHAR_PATH_SEPARATOR L'\\\\'\r\n#define STRING_PATH_SEPARATOR \"\\\\\"\r\n#define WSTRING_PATH_SEPARATOR L\"\\\\\"\r\n\r\n#else\r\n\r\n#define CHAR_PATH_SEPARATOR '/'\r\n#define WCHAR_PATH_SEPARATOR L'/'\r\n#define STRING_PATH_SEPARATOR \"/\"\r\n#define WSTRING_PATH_SEPARATOR L\"/\"\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\n\r\n#undef BYTE\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\n\r\n#undef WORD\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\n\r\n#undef DWORD\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOTIMPL ((HRESULT)0x80004001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall\r\n#else\r\n#define STDMETHODCALLTYPE\r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct\r\n\r\n#ifdef __cplusplus\r\n\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n  #ifndef _WIN32\r\n  virtual ~IUnknown() {}\r\n  #endif\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#endif\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\r\n  VT_EMPTY = 0,\r\n  VT_NULL = 1,\r\n  VT_I2 = 2,\r\n  VT_I4 = 3,\r\n  VT_R4 = 4,\r\n  VT_R8 = 5,\r\n  VT_CY = 6,\r\n  VT_DATE = 7,\r\n  VT_BSTR = 8,\r\n  VT_DISPATCH = 9,\r\n  VT_ERROR = 10,\r\n  VT_BOOL = 11,\r\n  VT_VARIANT = 12,\r\n  VT_UNKNOWN = 13,\r\n  VT_DECIMAL = 14,\r\n  VT_I1 = 16,\r\n  VT_UI1 = 17,\r\n  VT_UI2 = 18,\r\n  VT_UI4 = 19,\r\n  VT_I8 = 20,\r\n  VT_UI8 = 21,\r\n  VT_INT = 22,\r\n  VT_UINT = 23,\r\n  VT_VOID = 24,\r\n  VT_HRESULT = 25,\r\n  VT_FILETIME = 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\n#ifdef __cplusplus\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union\r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\n\r\n#endif\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\r\n  STREAM_SEEK_SET = 0,\r\n  STREAM_SEEK_CUR = 1,\r\n  STREAM_SEEK_END = 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\n#ifdef _WIN32\r\nvoid *\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n#endif\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\n#ifdef _WIN32\r\nvoid\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator delete(void *p) throw();\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/StdInStream.cpp",
    "content": "// Common/StdInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n#include \"StdInStream.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kIllegalChar = '\\0';\r\nstatic const char kNewLineChar = '\\n';\r\n\r\nstatic const char *kEOFMessage = \"Unexpected end of input stream\";\r\nstatic const char *kReadErrorMessage  =\"Error reading input stream\";\r\nstatic const char *kIllegalCharMessage = \"Illegal character in input stream\";\r\n\r\nstatic LPCTSTR kFileOpenMode = TEXT(\"r\");\r\n\r\nCStdInStream g_StdIn(stdin);\r\n\r\nbool CStdInStream::Open(LPCTSTR fileName)\r\n{\r\n  Close();\r\n  _stream = _tfopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdInStream::Close()\r\n{\r\n  if (!_streamIsOpen)\r\n    return true;\r\n  _streamIsOpen = (fclose(_stream) != 0);\r\n  return !_streamIsOpen;\r\n}\r\n\r\nCStdInStream::~CStdInStream()\r\n{\r\n  Close();\r\n}\r\n\r\nAString CStdInStream::ScanStringUntilNewLine()\r\n{\r\n  AString s;\r\n  for (;;)\r\n  {\r\n    int intChar = GetChar();\r\n    if (intChar == EOF)\r\n      throw kEOFMessage;\r\n    char c = char(intChar);\r\n    if (c == kIllegalChar)\r\n      throw kIllegalCharMessage;\r\n    if (c == kNewLineChar)\r\n      break;\r\n    s += c;\r\n  }\r\n  return s;\r\n}\r\n\r\nvoid CStdInStream::ReadToString(AString &resultString)\r\n{\r\n  resultString.Empty();\r\n  int c;\r\n  while ((c = GetChar()) != EOF)\r\n    resultString += char(c);\r\n}\r\n\r\nbool CStdInStream::Eof()\r\n{\r\n  return (feof(_stream) != 0);\r\n}\r\n\r\nint CStdInStream::GetChar()\r\n{\r\n  int c = fgetc(_stream); // getc() doesn't work in BeOS?\r\n  if (c == EOF && !Eof())\r\n    throw kReadErrorMessage;\r\n  return c;\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/StdInStream.h",
    "content": "// Common/StdInStream.h\r\n\r\n#ifndef __COMMON_STDINSTREAM_H\r\n#define __COMMON_STDINSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nclass CStdInStream\r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdInStream(): _streamIsOpen(false) {};\r\n  CStdInStream(FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdInStream();\r\n  bool Open(LPCTSTR fileName);\r\n  bool Close();\r\n\r\n  AString ScanStringUntilNewLine();\r\n  void ReadToString(AString &resultString);\r\n\r\n  bool Eof();\r\n  int GetChar();\r\n};\r\n\r\nextern CStdInStream g_StdIn;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/StdOutStream.cpp",
    "content": "// Common/StdOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n\r\n#include \"StdOutStream.h\"\r\n#include \"IntToString.h\"\r\n#include \"StringConvert.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kNewLineChar =  '\\n';\r\n\r\nstatic const char *kFileOpenMode = \"wt\";\r\n\r\nCStdOutStream  g_StdOut(stdout);\r\nCStdOutStream  g_StdErr(stderr);\r\n\r\nbool CStdOutStream::Open(const char *fileName)\r\n{\r\n  Close();\r\n  _stream = fopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdOutStream::Close()\r\n{\r\n  if (!_streamIsOpen)\r\n    return true;\r\n  if (fclose(_stream) != 0)\r\n    return false;\r\n  _stream = 0;\r\n  _streamIsOpen = false;\r\n  return true;\r\n}\r\n\r\nbool CStdOutStream::Flush()\r\n{\r\n  return (fflush(_stream) == 0);\r\n}\r\n\r\nCStdOutStream::~CStdOutStream ()\r\n{\r\n  Close();\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream  &))\r\n{\r\n  (*aFunction)(*this);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream)\r\n{\r\n  return outStream << kNewLineChar;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const char *string)\r\n{\r\n  fputs(string, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const wchar_t *string)\r\n{\r\n  *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(char c)\r\n{\r\n  fputc(c, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(int number)\r\n{\r\n  char textString[32];\r\n  ConvertInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(UInt64 number)\r\n{\r\n  char textString[32];\r\n  ConvertUInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/StdOutStream.h",
    "content": "// Common/StdOutStream.h\r\n\r\n#ifndef __COMMON_STDOUTSTREAM_H\r\n#define __COMMON_STDOUTSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Types.h\"\r\n\r\nclass CStdOutStream\r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdOutStream (): _streamIsOpen(false), _stream(0) {};\r\n  CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdOutStream ();\r\n  operator FILE *() { return _stream; }\r\n  bool Open(const char *fileName);\r\n  bool Close();\r\n  bool Flush();\r\n  CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream  &));\r\n  CStdOutStream & operator<<(const char *string);\r\n  CStdOutStream & operator<<(const wchar_t *string);\r\n  CStdOutStream & operator<<(char c);\r\n  CStdOutStream & operator<<(int number);\r\n  CStdOutStream & operator<<(UInt64 number);\r\n};\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream);\r\n\r\nextern CStdOutStream g_StdOut;\r\nextern CStdOutStream g_StdErr;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString,\r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()),\r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if (numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed)\r\n{\r\n  AString dest;\r\n  defaultCharWasUsed = false;\r\n  if (!s.IsEmpty())\r\n  {\r\n    int numRequiredBytes = s.Length() * 2;\r\n    BOOL defUsed;\r\n    int numChars = WideCharToMultiByte(codePage, 0, s, s.Length(),\r\n        dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1,\r\n        &defaultChar, &defUsed);\r\n    defaultCharWasUsed = (defUsed != FALSE);\r\n    #ifndef _WIN32_WCE\r\n    if (numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    dest.ReleaseBuffer(numChars);\r\n  }\r\n  return dest;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  bool defaultCharWasUsed;\r\n  return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed);\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage, char defaultChar, bool &defaultCharWasUsed);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    UInt32 v;\r\n    if (c >= '0' && c <= '9') v = (c - '0');\r\n    else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A');\r\n    else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a');\r\n    else\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 4;\r\n    result |= v;\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Types.h\"\r\n}\r\n\r\ntypedef int HRes;\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/UTFConvert.cpp",
    "content": "// UTFConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UTFConvert.h\"\r\n#include \"Types.h\"\r\n\r\nstatic const Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nstatic Bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, size_t srcLen)\r\n{\r\n  size_t destPos = 0, srcPos = 0;\r\n  for (;;)\r\n  {\r\n    Byte c;\r\n    int numAdds;\r\n    if (srcPos == srcLen)\r\n    {\r\n      *destLen = destPos;\r\n      return True;\r\n    }\r\n    c = (Byte)src[srcPos++];\r\n\r\n    if (c < 0x80)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (wchar_t)c;\r\n      destPos++;\r\n      continue;\r\n    }\r\n    if (c < 0xC0)\r\n      break;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (c < kUtf8Limits[numAdds])\r\n        break;\r\n    UInt32 value = (c - kUtf8Limits[numAdds - 1]);\r\n\r\n    do\r\n    {\r\n      Byte c2;\r\n      if (srcPos == srcLen)\r\n        break;\r\n      c2 = (Byte)src[srcPos++];\r\n      if (c2 < 0x80 || c2 >= 0xC0)\r\n        break;\r\n      value <<= 6;\r\n      value |= (c2 - 0x80);\r\n    }\r\n    while (--numAdds != 0);\r\n    \r\n    if (value < 0x10000)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (wchar_t)value;\r\n      destPos++;\r\n    }\r\n    else\r\n    {\r\n      value -= 0x10000;\r\n      if (value >= 0x100000)\r\n        break;\r\n      if (dest)\r\n      {\r\n        dest[destPos + 0] = (wchar_t)(0xD800 + (value >> 10));\r\n        dest[destPos + 1] = (wchar_t)(0xDC00 + (value & 0x3FF));\r\n      }\r\n      destPos += 2;\r\n    }\r\n  }\r\n  *destLen = destPos;\r\n  return False;\r\n}\r\n\r\nstatic Bool Utf16_To_Utf8(char *dest, size_t *destLen, const wchar_t *src, size_t srcLen)\r\n{\r\n  size_t destPos = 0, srcPos = 0;\r\n  for (;;)\r\n  {\r\n    unsigned numAdds;\r\n    UInt32 value;\r\n    if (srcPos == srcLen)\r\n    {\r\n      *destLen = destPos;\r\n      return True;\r\n    }\r\n    value = src[srcPos++];\r\n    if (value < 0x80)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (char)value;\r\n      destPos++;\r\n      continue;\r\n    }\r\n    if (value >= 0xD800 && value < 0xE000)\r\n    {\r\n      UInt32 c2;\r\n      if (value >= 0xDC00 || srcPos == srcLen)\r\n        break;\r\n      c2 = src[srcPos++];\r\n      if (c2 < 0xDC00 || c2 >= 0xE000)\r\n        break;\r\n      value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n    }\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n        break;\r\n    if (dest)\r\n      dest[destPos] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n    destPos++;\r\n    do\r\n    {\r\n      numAdds--;\r\n      if (dest)\r\n        dest[destPos] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      destPos++;\r\n    }\r\n    while (numAdds != 0);\r\n  }\r\n  *destLen = destPos;\r\n  return False;\r\n}\r\n\r\nbool ConvertUTF8ToUnicode(const AString &src, UString &dest)\r\n{\r\n  dest.Empty();\r\n  size_t destLen = 0;\r\n  Utf8_To_Utf16(NULL, &destLen, src, src.Length());\r\n  wchar_t *p = dest.GetBuffer((int)destLen);\r\n  Bool res = Utf8_To_Utf16(p, &destLen, src, src.Length());\r\n  p[destLen] = 0;\r\n  dest.ReleaseBuffer();\r\n  return res ? true : false;\r\n}\r\n\r\nbool ConvertUnicodeToUTF8(const UString &src, AString &dest)\r\n{\r\n  dest.Empty();\r\n  size_t destLen = 0;\r\n  Utf16_To_Utf8(NULL, &destLen, src, src.Length());\r\n  char *p = dest.GetBuffer((int)destLen);\r\n  Bool res = Utf16_To_Utf8(p, &destLen, src, src.Length());\r\n  p[destLen] = 0;\r\n  dest.ReleaseBuffer();\r\n  return res ? true : false;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/UTFConvert.h",
    "content": "// Common/UTFConvert.h\r\n\r\n#ifndef __COMMON_UTFCONVERT_H\r\n#define __COMMON_UTFCONVERT_H\r\n\r\n#include \"MyString.h\"\r\n\r\nbool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);\r\nbool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/Wildcard.cpp",
    "content": "// Common/Wildcard.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Wildcard.h\"\r\n\r\nbool g_CaseSensitive =\r\n  #ifdef _WIN32\r\n    false;\r\n  #else\r\n    true;\r\n  #endif\r\n\r\nstatic const wchar_t kAnyCharsChar = L'*';\r\nstatic const wchar_t kAnyCharChar = L'?';\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t kDirDelimiter1 = L'\\\\';\r\n#endif\r\nstatic const wchar_t kDirDelimiter2 = L'/';\r\n\r\nstatic const UString kWildCardCharSet = L\"?*\";\r\n\r\nstatic const UString kIllegalWildCardFileNameChars=\r\n  L\"\\x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\xA\\xB\\xC\\xD\\xE\\xF\"\r\n  L\"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F\"\r\n  L\"\\\"/:<>\\\\|\";\r\n\r\n\r\nstatic inline bool IsCharDirLimiter(wchar_t c)\r\n{\r\n  return (\r\n    #ifdef _WIN32\r\n    c == kDirDelimiter1 ||\r\n    #endif\r\n    c == kDirDelimiter2);\r\n}\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2)\r\n{\r\n  if (g_CaseSensitive)\r\n    return s1.Compare(s2);\r\n  return s1.CompareNoCase(s2);\r\n}\r\n\r\n// -----------------------------------------\r\n// this function compares name with mask\r\n// ? - any char\r\n// * - any char or empty\r\n\r\nstatic bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t m = *mask;\r\n    wchar_t c = *name;\r\n    if (m == 0)\r\n      return (c == 0);\r\n    if (m == kAnyCharsChar)\r\n    {\r\n      if (EnhancedMaskTest(mask + 1, name))\r\n        return true;\r\n      if (c == 0)\r\n        return false;\r\n    }\r\n    else\r\n    {\r\n      if (m == kAnyCharChar)\r\n      {\r\n        if (c == 0)\r\n          return false;\r\n      }\r\n      else if (m != c)\r\n        if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))\r\n          return false;\r\n      mask++;\r\n    }\r\n    name++;\r\n  }\r\n}\r\n\r\n// --------------------------------------------------\r\n// Splits path to strings\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts)\r\n{\r\n  pathParts.Clear();\r\n  UString name;\r\n  int len = path.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = path[i];\r\n    if (IsCharDirLimiter(c))\r\n    {\r\n      pathParts.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  pathParts.Add(name);\r\n}\r\n\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  dirPrefix = path.Left(i + 1);\r\n  name = path.Mid(i + 1);\r\n}\r\n\r\nUString ExtractDirPrefixFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Left(i + 1);\r\n}\r\n\r\nUString ExtractFileNameFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Mid(i + 1);\r\n}\r\n\r\n\r\nbool CompareWildCardWithName(const UString &mask, const UString &name)\r\n{\r\n  return EnhancedMaskTest(mask, name);\r\n}\r\n\r\nbool DoesNameContainWildCard(const UString &path)\r\n{\r\n  return (path.FindOneOf(kWildCardCharSet) >= 0);\r\n}\r\n\r\n\r\n// ----------------------------------------------------------'\r\n// NWildcard\r\n\r\nnamespace NWildcard {\r\n\r\n\r\n/*\r\nM = MaskParts.Size();\r\nN = TestNameParts.Size();\r\n\r\n                           File                          Dir\r\nForFile     req   M<=N  [N-M, N)                          -\r\n         nonreq   M=N   [0, M)                            -\r\n \r\nForDir      req   M<N   [0, M) ... [N-M-1, N-1)  same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\nForBoth     req   m<=N  [0, M) ... [N-M, N)      same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\n*/\r\n\r\nbool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (!isFile && !ForDir)\r\n    return false;\r\n  int delta = (int)pathParts.Size() - (int)PathParts.Size();\r\n  if (delta < 0)\r\n    return false;\r\n  int start = 0;\r\n  int finish = 0;\r\n  if (isFile)\r\n  {\r\n    if (!ForDir && !Recursive && delta !=0)\r\n      return false;\r\n    if (!ForFile && delta == 0)\r\n      return false;\r\n    if (!ForDir && Recursive)\r\n      start = delta;\r\n  }\r\n  if (Recursive)\r\n  {\r\n    finish = delta;\r\n    if (isFile && !ForFile)\r\n      finish = delta - 1;\r\n  }\r\n  for (int d = start; d <= finish; d++)\r\n  {\r\n    int i;\r\n    for (i = 0; i < PathParts.Size(); i++)\r\n      if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))\r\n        break;\r\n    if (i == PathParts.Size())\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nint CCensorNode::FindSubNode(const UString &name) const\r\n{\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (CompareFileNames(SubNodes[i].Name, name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensorNode::AddItemSimple(bool include, CItem &item)\r\n{\r\n  if (include)\r\n    IncludeItems.Add(item);\r\n  else\r\n    ExcludeItems.Add(item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, CItem &item)\r\n{\r\n  if (item.PathParts.Size() <= 1)\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  const UString &front = item.PathParts.Front();\r\n  if (DoesNameContainWildCard(front))\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  int index = FindSubNode(front);\r\n  if (index < 0)\r\n    index = SubNodes.Add(CCensorNode(front, this));\r\n  item.PathParts.Delete(0);\r\n  SubNodes[index].AddItem(include, item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)\r\n{\r\n  CItem item;\r\n  SplitPathToParts(path, item.PathParts);\r\n  item.Recursive = recursive;\r\n  item.ForFile = forFile;\r\n  item.ForDir = forDir;\r\n  AddItem(include, item);\r\n}\r\n\r\nbool CCensorNode::NeedCheckSubDirs() const\r\n{\r\n  for (int i = 0; i < IncludeItems.Size(); i++)\r\n  {\r\n    const CItem &item = IncludeItems[i];\r\n    if (item.Recursive || item.PathParts.Size() > 1)\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::AreThereIncludeItems() const\r\n{\r\n  if (IncludeItems.Size() > 0)\r\n    return true;\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (SubNodes[i].AreThereIncludeItems())\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const\r\n{\r\n  const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;\r\n  for (int i = 0; i < items.Size(); i++)\r\n    if (items[i].CheckPath(pathParts, isFile))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const\r\n{\r\n  if (CheckPathCurrent(false, pathParts, isFile))\r\n  {\r\n    include = false;\r\n    return true;\r\n  }\r\n  include = true;\r\n  bool finded = CheckPathCurrent(true, pathParts, isFile);\r\n  if (pathParts.Size() == 1)\r\n    return finded;\r\n  int index = FindSubNode(pathParts.Front());\r\n  if (index >= 0)\r\n  {\r\n    UStringVector pathParts2 = pathParts;\r\n    pathParts2.Delete(0);\r\n    if (SubNodes[index].CheckPath(pathParts2, isFile, include))\r\n      return true;\r\n  }\r\n  return finded;\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPath(pathParts, isFile, include);\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool include;\r\n  if (CheckPath(path, isFile, include))\r\n    return include;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (CheckPathCurrent(include, pathParts, isFile))\r\n    return true;\r\n  if (Parent == 0)\r\n    return false;\r\n  pathParts.Insert(0, Name);\r\n  return Parent->CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n\r\n/*\r\nbool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n*/\r\n\r\nvoid CCensorNode::AddItem2(bool include, const UString &path, bool recursive)\r\n{\r\n  if (path.IsEmpty())\r\n    return;\r\n  bool forFile = true;\r\n  bool forFolder = true;\r\n  UString path2 = path;\r\n  if (IsCharDirLimiter(path[path.Length() - 1]))\r\n  {\r\n    path2.Delete(path.Length() - 1);\r\n    forFile = false;\r\n  }\r\n  AddItem(include, path2, recursive, forFile, forFolder);\r\n}\r\n\r\nvoid CCensorNode::ExtendExclude(const CCensorNode &fromNodes)\r\n{\r\n  ExcludeItems += fromNodes.ExcludeItems;\r\n  for (int i = 0; i < fromNodes.SubNodes.Size(); i++)\r\n  {\r\n    const CCensorNode &node = fromNodes.SubNodes[i];\r\n    int subNodeIndex = FindSubNode(node.Name);\r\n    if (subNodeIndex < 0)\r\n      subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));\r\n    SubNodes[subNodeIndex].ExtendExclude(node);\r\n  }\r\n}\r\n\r\nint CCensor::FindPrefix(const UString &prefix) const\r\n{\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n    if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensor::AddItem(bool include, const UString &path, bool recursive)\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  bool forFile = true;\r\n  if (pathParts.Back().IsEmpty())\r\n  {\r\n    forFile = false;\r\n    pathParts.DeleteBack();\r\n  }\r\n  const UString &front = pathParts.Front();\r\n  bool isAbs = false;\r\n  if (front.IsEmpty())\r\n    isAbs = true;\r\n  else if (front.Length() == 2 && front[1] == L':')\r\n    isAbs = true;\r\n  else\r\n  {\r\n    for (int i = 0; i < pathParts.Size(); i++)\r\n    {\r\n      const UString &part = pathParts[i];\r\n      if (part == L\"..\" || part == L\".\")\r\n      {\r\n        isAbs = true;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  int numAbsParts = 0;\r\n  if (isAbs)\r\n    if (pathParts.Size() > 1)\r\n      numAbsParts = pathParts.Size() - 1;\r\n    else\r\n      numAbsParts = 1;\r\n  UString prefix;\r\n  for (int i = 0; i < numAbsParts; i++)\r\n  {\r\n    const UString &front = pathParts.Front();\r\n    if (DoesNameContainWildCard(front))\r\n      break;\r\n    prefix += front;\r\n    prefix += WCHAR_PATH_SEPARATOR;\r\n    pathParts.Delete(0);\r\n  }\r\n  int index = FindPrefix(prefix);\r\n  if (index < 0)\r\n    index = Pairs.Add(CPair(prefix));\r\n\r\n  CItem item;\r\n  item.PathParts = pathParts;\r\n  item.ForDir = true;\r\n  item.ForFile = forFile;\r\n  item.Recursive = recursive;\r\n  Pairs[index].Head.AddItem(include, item);\r\n}\r\n\r\nbool CCensor::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool finded = false;\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n  {\r\n    bool include;\r\n    if (Pairs[i].Head.CheckPath(path, isFile, include))\r\n    {\r\n      if (!include)\r\n        return false;\r\n      finded = true;\r\n    }\r\n  }\r\n  return finded;\r\n}\r\n\r\nvoid CCensor::ExtendExclude()\r\n{\r\n  int i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (Pairs[i].Prefix.IsEmpty())\r\n      break;\r\n  if (i == Pairs.Size())\r\n    return;\r\n  int index = i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (index != i)\r\n      Pairs[i].Head.ExtendExclude(Pairs[index].Head);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Common/Wildcard.h",
    "content": "// Common/Wildcard.h\r\n\r\n#ifndef __COMMON_WILDCARD_H\r\n#define __COMMON_WILDCARD_H\r\n\r\n#include \"MyString.h\"\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2);\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts);\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);\r\nUString ExtractDirPrefixFromPath(const UString &path);\r\nUString ExtractFileNameFromPath(const UString &path);\r\nbool DoesNameContainWildCard(const UString &path);\r\nbool CompareWildCardWithName(const UString &mask, const UString &name);\r\n\r\nnamespace NWildcard {\r\n\r\nstruct CItem\r\n{\r\n  UStringVector PathParts;\r\n  bool Recursive;\r\n  bool ForFile;\r\n  bool ForDir;\r\n  bool CheckPath(const UStringVector &pathParts, bool isFile) const;\r\n};\r\n\r\nclass CCensorNode\r\n{\r\n  CCensorNode *Parent;\r\n  bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;\r\n  void AddItemSimple(bool include, CItem &item);\r\n  bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;\r\npublic:\r\n  CCensorNode(): Parent(0) { };\r\n  CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };\r\n  UString Name;\r\n  CObjectVector<CCensorNode> SubNodes;\r\n  CObjectVector<CItem> IncludeItems;\r\n  CObjectVector<CItem> ExcludeItems;\r\n\r\n  int FindSubNode(const UString &path) const;\r\n\r\n  void AddItem(bool include, CItem &item);\r\n  void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);\r\n  void AddItem2(bool include, const UString &path, bool recursive);\r\n\r\n  bool NeedCheckSubDirs() const;\r\n  bool AreThereIncludeItems() const;\r\n\r\n  bool CheckPath(const UString &path, bool isFile, bool &include) const;\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n\r\n  bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;\r\n  // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;\r\n  void ExtendExclude(const CCensorNode &fromNodes);\r\n};\r\n\r\nstruct CPair\r\n{\r\n  UString Prefix;\r\n  CCensorNode Head;\r\n  CPair(const UString &prefix): Prefix(prefix) { };\r\n};\r\n\r\nclass CCensor\r\n{\r\n  int FindPrefix(const UString &prefix) const;\r\npublic:\r\n  CObjectVector<CPair> Pairs;\r\n  bool AllAreRelative() const\r\n    { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }\r\n  void AddItem(bool include, const UString &path, bool recursive);\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n  void ExtendExclude();\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/DLL.cpp",
    "content": "// Windows/DLL.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DLL.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nCLibrary::~CLibrary()\r\n{\r\n  Free();\r\n}\r\n\r\nbool CLibrary::Free()\r\n{\r\n  if (_module == 0)\r\n    return true;\r\n  // MessageBox(0, TEXT(\"\"), TEXT(\"Free\"), 0);\r\n  // Sleep(5000);\r\n  if (!::FreeLibrary(_module))\r\n    return false;\r\n  _module = 0;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadOperations(HMODULE newModule)\r\n{\r\n  if (newModule == NULL)\r\n    return false;\r\n  if (!Free())\r\n    return false;\r\n  _module = newModule;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"LoadEx\"), 0);\r\n  return LoadOperations(::LoadLibraryEx(fileName, NULL, flags));\r\n}\r\n\r\nbool CLibrary::Load(LPCTSTR fileName)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"Load\"), 0);\r\n  // Sleep(5000);\r\n  // OutputDebugString(fileName);\r\n  // OutputDebugString(TEXT(\"\\n\"));\r\n  return LoadOperations(::LoadLibrary(fileName));\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\nCSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n\r\nbool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));\r\n  return LoadEx(GetSysPath(fileName), flags);\r\n}\r\nbool CLibrary::Load(LPCWSTR fileName)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryW(fileName));\r\n  return Load(GetSysPath(fileName));\r\n}\r\n#endif\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result)\r\n{\r\n  result.Empty();\r\n  TCHAR fullPath[MAX_PATH + 2];\r\n  DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1);\r\n  if (size <= MAX_PATH && size != 0)\r\n  {\r\n    result = fullPath;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result)\r\n{\r\n  result.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    wchar_t fullPath[MAX_PATH + 2];\r\n    DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);\r\n    if (size <= MAX_PATH && size != 0)\r\n    {\r\n      result = fullPath;\r\n      return true;\r\n    }\r\n    return false;\r\n  }\r\n  CSysString resultSys;\r\n  if (!MyGetModuleFileName(hModule, resultSys))\r\n    return false;\r\n  result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());\r\n  return true;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/DLL.h",
    "content": "// Windows/DLL.h\r\n\r\n#ifndef __WINDOWS_DLL_H\r\n#define __WINDOWS_DLL_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nclass CLibrary\r\n{\r\n  bool LoadOperations(HMODULE newModule);\r\nprotected:\r\n  HMODULE _module;\r\npublic:\r\n  operator HMODULE() const { return _module; }\r\n  HMODULE* operator&() { return &_module; }\r\n\r\n  CLibrary():_module(NULL) {};\r\n  ~CLibrary();\r\n  void Attach(HMODULE m)\r\n  {\r\n    Free();\r\n    _module = m;\r\n  }\r\n  HMODULE Detach()\r\n  {\r\n    HMODULE m = _module;\r\n    _module = NULL;\r\n    return m;\r\n  }\r\n\r\n  // operator HMODULE() const { return _module; };\r\n  bool IsLoaded() const { return (_module != NULL); };\r\n  bool Free();\r\n  bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCWSTR fileName);\r\n  #endif\r\n  FARPROC GetProcAddress(LPCSTR procName) const\r\n    { return ::GetProcAddress(_module, procName); }\r\n};\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result);\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result);\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\n#ifdef _WIN32\r\ninline bool LRESULTToBool(LRESULT value)\r\n  { return (value != FALSE); }\r\n#endif\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/Error.cpp",
    "content": "// Windows/Error.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifndef _UNICODE\r\n#include \"Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message)\r\n{\r\n  LPVOID msgBuf;\r\n  if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r\n      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n      NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)\r\n    return false;\r\n  message = (LPCTSTR)msgBuf;\r\n  ::LocalFree(msgBuf);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyFormatMessage(DWORD messageID, UString &message)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPVOID msgBuf;\r\n    if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r\n        FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n        NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)\r\n      return false;\r\n    message = (LPCWSTR)msgBuf;\r\n    ::LocalFree(msgBuf);\r\n    return true;\r\n  }\r\n  CSysString messageSys;\r\n  bool result = MyFormatMessage(messageID, messageSys);\r\n  message = GetUnicodeString(messageSys);\r\n  return result;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/Error.h",
    "content": "// Windows/Error.h\r\n\r\n#ifndef __WINDOWS_ERROR_H\r\n#define __WINDOWS_ERROR_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message);\r\ninline CSysString MyFormatMessage(DWORD messageID)\r\n{\r\n  CSysString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#ifdef _UNICODE\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n  { return MyFormatMessage(messageID); }\r\n#else\r\nbool MyFormatMessage(DWORD messageID, UString &message);\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n{\r\n  UString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileDir.cpp",
    "content": "// Windows/FileDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileDir.h\"\r\n#include \"FileName.h\"\r\n#include \"FileFind.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n// SetCurrentDirectory doesn't support \\\\?\\ prefix\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR fileName, UString &res);\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n#endif\r\n\r\nnamespace NDirectory {\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\nstatic UString GetUnicodePath(const CSysString &sysPath)\r\n  { return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }\r\nstatic CSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\nbool MyGetSystemDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetWindowsDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n\r\nbool MyGetSystemDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetSystemDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n{\r\n  #ifndef _UNICODE\r\n  if (!g_IsNT)\r\n  {\r\n    ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\r\n    return false;\r\n  }\r\n  #endif\r\n  HANDLE hDir = ::CreateFileW(fileName, GENERIC_WRITE,\r\n      FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n      NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (hDir == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      hDir = ::CreateFileW(longPath, GENERIC_WRITE,\r\n        FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  }\r\n  #endif\r\n\r\n  bool res = false;\r\n  if (hDir != INVALID_HANDLE_VALUE)\r\n  {\r\n    res = BOOLToBool(::SetFileTime(hDir, cTime, aTime, mTime));\r\n    ::CloseHandle(hDir);\r\n  }\r\n  return res;\r\n}\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (::SetFileAttributes(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyRemoveDirectory(LPCTSTR pathName)\r\n{\r\n  if (::RemoveDirectory(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2)\r\n{\r\n  if (!GetLongPathBase(s1, d1) || !GetLongPathBase(s2, d2))\r\n    return false;\r\n  if (d1.IsEmpty() && d2.IsEmpty()) return false;\r\n  if (d1.IsEmpty()) d1 = s1;\r\n  if (d2.IsEmpty()) d2 = s2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName)\r\n{\r\n  if (::MoveFile(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return MySetFileAttributes(GetSysPath(fileName), fileAttributes);\r\n  if (::SetFileAttributesW(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n\r\nbool MyRemoveDirectory(LPCWSTR pathName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyRemoveDirectory(GetSysPath(pathName));\r\n  if (::RemoveDirectoryW(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));\r\n  if (::MoveFileW(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nbool MyCreateDirectory(LPCTSTR pathName)\r\n{\r\n  if (::CreateDirectory(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyCreateDirectory(LPCWSTR pathName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyCreateDirectory(GetSysPath(pathName));\r\n  if (::CreateDirectoryW(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\n/*\r\nbool CreateComplexDirectory(LPCTSTR pathName)\r\n{\r\n  NName::CParsedPath path;\r\n  path.ParsePath(pathName);\r\n  CSysString fullPath = path.Prefix;\r\n  DWORD errorCode = ERROR_SUCCESS;\r\n  for (int i = 0; i < path.PathParts.Size(); i++)\r\n  {\r\n    const CSysString &string = path.PathParts[i];\r\n    if (string.IsEmpty())\r\n    {\r\n      if (i != path.PathParts.Size() - 1)\r\n        return false;\r\n      return true;\r\n    }\r\n    fullPath += path.PathParts[i];\r\n    if (!MyCreateDirectory(fullPath))\r\n    {\r\n      DWORD errorCode = GetLastError();\r\n      if (errorCode != ERROR_ALREADY_EXISTS)\r\n        return false;\r\n    }\r\n    fullPath += NName::kDirDelimiter;\r\n  }\r\n  return true;\r\n}\r\n*/\r\n\r\nbool CreateComplexDirectory(LPCTSTR _aPathName)\r\n{\r\n  CSysString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == ':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  CSysString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if (MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfo fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDir())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == ':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while (pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateComplexDirectory(LPCWSTR _aPathName)\r\n{\r\n  UString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == L':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  UString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if (MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfoW fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDir())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == L':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while (pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\nbool DeleteFileAlways(LPCTSTR name)\r\n{\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFile(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DeleteFileAlways(LPCWSTR name)\r\n{\r\n  if (!g_IsNT)\r\n    return DeleteFileAlways(GetSysPath(name));\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFileW(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nstatic bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)\r\n{\r\n  if (fileInfo.IsDir())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\n\r\nbool RemoveDirectoryWithSubItems(const CSysString &path)\r\n{\r\n  NFind::CFileInfo fileInfo;\r\n  CSysString pathPrefix = path + NName::kDirDelimiter;\r\n  {\r\n    NFind::CEnumerator enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));\r\n    while (enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)\r\n{\r\n  if (fileInfo.IsDir())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\nbool RemoveDirectoryWithSubItems(const UString &path)\r\n{\r\n  NFind::CFileInfoW fileInfo;\r\n  UString pathPrefix = path + UString(NName::kDirDelimiter);\r\n  {\r\n    NFind::CEnumeratorW enumerator(pathPrefix + UString(NName::kAnyStringWildcard));\r\n    while (enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\n\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)\r\n{\r\n  DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  shortPath.ReleaseBuffer();\r\n  return (needLength > 0 && needLength < MAX_PATH);\r\n}\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  LPTSTR fileNamePointer = 0;\r\n  LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n  DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n  resultPath.ReleaseBuffer();\r\n  if (needLength == 0)\r\n    return false;\r\n  if (needLength >= MAX_PATH)\r\n  {\r\n    #ifdef WIN_LONG_PATH2\r\n    needLength++;\r\n    buffer = resultPath.GetBuffer(needLength + 1);\r\n    DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength2 == 0 || needLength2 > needLength)\r\n    #endif\r\n      return false;\r\n  }\r\n  if (fileNamePointer == 0)\r\n    fileNamePartStartIndex = lstrlen(fileName);\r\n  else\r\n    fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR fileNamePointer = 0;\r\n    LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n    DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength == 0)\r\n      return false;\r\n    if (needLength >= MAX_PATH)\r\n    {\r\n      #ifdef WIN_LONG_PATH\r\n      needLength++;\r\n      buffer = resultPath.GetBuffer(needLength + 1);\r\n      DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n      resultPath.ReleaseBuffer();\r\n      if (needLength2 == 0 || needLength2 > needLength)\r\n      #endif\r\n        return false;\r\n    }\r\n    if (fileNamePointer == 0)\r\n      fileNamePartStartIndex = MyStringLen(fileName);\r\n    else\r\n      fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  }\r\n  else\r\n  {\r\n    CSysString sysPath;\r\n    if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))\r\n      return false;\r\n    UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));\r\n    UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));\r\n    fileNamePartStartIndex = resultPath1.Length();\r\n    resultPath = resultPath1 + resultPath2;\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n#endif\r\n\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetCurrentDirectory(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path)\r\n{\r\n  if (g_IsNT)\r\n    return BOOLToBool(::SetCurrentDirectoryW(path));\r\n  return MySetCurrentDirectory(GetSysPath(path));\r\n}\r\nbool MyGetCurrentDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetCurrentDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath, UINT32 &filePart)\r\n{\r\n  LPTSTR filePartPointer;\r\n  DWORD value = ::SearchPath(path, fileName, extension,\r\n    MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n  filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);\r\n  resultPath.ReleaseBuffer();\r\n  return (value > 0 && value <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath, UINT32 &filePart)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR filePartPointer = 0;\r\n    DWORD value = ::SearchPathW(path, fileName, extension,\r\n        MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n    filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);\r\n    resultPath.ReleaseBuffer();\r\n    return (value > 0 && value <= MAX_PATH);\r\n  }\r\n  \r\n  CSysString sysPath;\r\n  if (!MySearchPath(\r\n      path != 0 ? (LPCTSTR)GetSysPath(path): 0,\r\n      fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,\r\n      extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,\r\n      sysPath, filePart))\r\n    return false;\r\n  UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));\r\n  UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));\r\n  filePart = resultPath1.Length();\r\n  resultPath = resultPath1 + resultPath2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &path)\r\n{\r\n  path.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetTempPath(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)\r\n{\r\n  UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return number;\r\n}\r\n\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));\r\n    path.ReleaseBuffer();\r\n    return number;\r\n  }\r\n  CSysString sysPath;\r\n  UINT number = MyGetTempFileName(\r\n      dirPath ? (LPCTSTR)GetSysPath(dirPath): 0,\r\n      prefix ? (LPCTSTR)GetSysPath(prefix): 0,\r\n      sysPath);\r\n  path = GetUnicodePath(sysPath);\r\n  return number;\r\n}\r\n#endif\r\n\r\nUINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if (number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  CSysString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFile::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nUINT CTempFileW::Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if (number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFileW::Create(LPCWSTR prefix, UString &resultPath)\r\n{\r\n  UString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFileW::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFile tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!::DeleteFile(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if (NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectory::Create(LPCTSTR prefix)\r\n{\r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateTempDirectory(LPCWSTR prefix, UString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFileW tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!DeleteFileAlways(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if (NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectoryW::Create(LPCWSTR prefix)\r\n{\r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileDir.h",
    "content": "// Windows/FileDir.h\r\n\r\n#ifndef __WINDOWS_FILEDIR_H\r\n#define __WINDOWS_FILEDIR_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NDirectory {\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path);\r\nbool MyGetSystemDirectory(CSysString &path);\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path);\r\nbool MyGetSystemDirectory(UString &path);\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);\r\nbool MyRemoveDirectory(LPCTSTR pathName);\r\nbool MyCreateDirectory(LPCTSTR pathName);\r\nbool CreateComplexDirectory(LPCTSTR pathName);\r\nbool DeleteFileAlways(LPCTSTR name);\r\nbool RemoveDirectoryWithSubItems(const CSysString &path);\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);\r\nbool MyRemoveDirectory(LPCWSTR pathName);\r\nbool MyCreateDirectory(LPCWSTR pathName);\r\nbool CreateComplexDirectory(LPCWSTR pathName);\r\nbool DeleteFileAlways(LPCWSTR name);\r\nbool RemoveDirectoryWithSubItems(const UString &path);\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,\r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName);\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,\r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName);\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);\r\n#endif\r\n\r\ninline bool MySetCurrentDirectory(LPCTSTR path)\r\n  { return BOOLToBool(::SetCurrentDirectory(path)); }\r\nbool MyGetCurrentDirectory(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path);\r\nbool MyGetCurrentDirectory(UString &resultPath);\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath, UINT32 &filePart);\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath, UINT32 &filePart);\r\n#endif\r\n\r\ninline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n\r\n#ifndef _UNICODE\r\ninline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &resultPath);\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n#endif\r\n\r\nclass CTempFile\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _fileName;\r\npublic:\r\n  CTempFile(): _mustBeDeleted(false) {}\r\n  ~CTempFile() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n  bool Create(LPCTSTR prefix, CSysString &resultPath);\r\n  bool Remove();\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempFile CTempFileW;\r\n#else\r\nclass CTempFileW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _fileName;\r\npublic:\r\n  CTempFileW(): _mustBeDeleted(false) {}\r\n  ~CTempFileW() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n  bool Create(LPCWSTR prefix, UString &resultPath);\r\n  bool Remove();\r\n};\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);\r\n\r\nclass CTempDirectory\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _tempDir;\r\npublic:\r\n  const CSysString &GetPath() const { return _tempDir; }\r\n  CTempDirectory(): _mustBeDeleted(false) {}\r\n  ~CTempDirectory() { Remove();  }\r\n  bool Create(LPCTSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempDirectory CTempDirectoryW;\r\n#else\r\nclass CTempDirectoryW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _tempDir;\r\npublic:\r\n  const UString &GetPath() const { return _tempDir; }\r\n  CTempDirectoryW(): _mustBeDeleted(false) {}\r\n  ~CTempDirectoryW() { Remove();  }\r\n  bool Create(LPCWSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileFind.cpp",
    "content": "// Windows/FileFind.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileFind.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n\r\nnamespace NFind {\r\n\r\nstatic const TCHAR kDot = TEXT('.');\r\n\r\nbool CFileInfo::IsDots() const\r\n{\r\n  if (!IsDir() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileInfoW::IsDots() const\r\n{\r\n  if (!IsDir() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n#endif\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = fd.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfoW &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = fd.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage());\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n#endif\r\n  \r\n////////////////////////////////\r\n// CFindFile\r\n\r\nbool CFindFile::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::FindClose(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\n          \r\nbool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  WIN32_FIND_DATA fd;\r\n  _handle = ::FindFirstFile(wildcard, &fd);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(wildcard, longPath))\r\n      _handle = ::FindFirstFileW(longPath, &fd);\r\n  }\r\n  #endif\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return false;\r\n  ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW fd;\r\n    _handle = ::FindFirstFileW(wildcard, &fd);\r\n    #ifdef WIN_LONG_PATH\r\n    if (_handle == INVALID_HANDLE_VALUE)\r\n    {\r\n      UString longPath;\r\n      if (GetLongPath(wildcard, longPath))\r\n        _handle = ::FindFirstFileW(longPath, &fd);\r\n    }\r\n    #endif\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA fd;\r\n    _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard,\r\n        GetCurrentCodePage()), &fd);\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFindFile::FindNext(CFileInfo &fileInfo)\r\n{\r\n  WIN32_FIND_DATA fd;\r\n  bool result = BOOLToBool(::FindNextFile(_handle, &fd));\r\n  if (result)\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  return result;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindNext(CFileInfoW &fileInfo)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW fd;\r\n    if (!::FindNextFileW(_handle, &fd))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA fd;\r\n    if (!::FindNextFileA(_handle, &fd))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n#endif\r\n\r\nbool DoesFileExist(LPCTSTR name)\r\n{\r\n  CFileInfo fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DoesFileExist(LPCWSTR name)\r\n{\r\n  CFileInfoW fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n#endif\r\n\r\n/////////////////////////////////////\r\n// CEnumerator\r\n\r\nbool CEnumerator::NextAny(CFileInfo &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CEnumeratorW::NextAny(CFileInfoW &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#endif\r\n\r\n////////////////////////////////\r\n// CFindChangeNotification\r\n// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.\r\n\r\nbool CFindChangeNotification::Close()\r\n{\r\n  if (!IsHandleAllocated())\r\n    return true;\r\n  if (!::FindCloseChangeNotification(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n           \r\nHANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  _handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n\r\n#ifndef _UNICODE\r\nHANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  if (!g_IsNT)\r\n    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);\r\n  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  UINT32 size = GetLogicalDriveStrings(0, NULL);\r\n  if (size == 0)\r\n    return false;\r\n  CSysString buffer;\r\n  UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size));\r\n  if (newSize == 0)\r\n    return false;\r\n  if (newSize > size)\r\n    return false;\r\n  CSysString string;\r\n  for (UINT32 i = 0; i < newSize; i++)\r\n  {\r\n    TCHAR c = buffer[i];\r\n    if (c == TEXT('\\0'))\r\n    {\r\n      driveStrings.Add(string);\r\n      string.Empty();\r\n    }\r\n    else\r\n      string += c;\r\n  }\r\n  if (!string.IsEmpty())\r\n    return false;\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  if (g_IsNT)\r\n  {\r\n    UINT32 size = GetLogicalDriveStringsW(0, NULL);\r\n    if (size == 0)\r\n      return false;\r\n    UString buffer;\r\n    UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size));\r\n    if (newSize == 0)\r\n      return false;\r\n    if (newSize > size)\r\n      return false;\r\n    UString string;\r\n    for (UINT32 i = 0; i < newSize; i++)\r\n    {\r\n      WCHAR c = buffer[i];\r\n      if (c == L'\\0')\r\n      {\r\n        driveStrings.Add(string);\r\n        string.Empty();\r\n      }\r\n      else\r\n        string += c;\r\n    }\r\n    return string.IsEmpty();\r\n  }\r\n  CSysStringVector driveStringsA;\r\n  bool res = MyGetLogicalDriveStrings(driveStringsA);\r\n  for (int i = 0; i < driveStringsA.Size(); i++)\r\n    driveStrings.Add(GetUnicodeString(driveStringsA[i]));\r\n  return res;\r\n}\r\n#endif\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileFind.h",
    "content": "// Windows/FileFind.h\r\n\r\n#ifndef __WINDOWS_FILEFIND_H\r\n#define __WINDOWS_FILEFIND_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"../Common/Types.h\"\r\n#include \"FileName.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NFind {\r\n\r\nnamespace NAttributes\r\n{\r\n  inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }\r\n  inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; }\r\n  inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; }\r\n  inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; }\r\n  inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }\r\n  inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }\r\n  inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }\r\n}\r\n\r\nclass CFileInfoBase\r\n{\r\n  bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }\r\npublic:\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  DWORD Attrib;\r\n  \r\n  #ifndef _WIN32_WCE\r\n  UINT32 ReparseTag;\r\n  #else\r\n  DWORD ObjectID;\r\n  #endif\r\n\r\n  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }\r\n  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }\r\n  bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }\r\n  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }\r\n  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }\r\n  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }\r\n  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }\r\n  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }\r\n  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }\r\n  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }\r\n  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }\r\n  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }\r\n};\r\n\r\nclass CFileInfo: public CFileInfoBase\r\n{\r\npublic:\r\n  CSysString Name;\r\n  bool IsDots() const;\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CFileInfo CFileInfoW;\r\n#else\r\nclass CFileInfoW: public CFileInfoBase\r\n{\r\npublic:\r\n  UString Name;\r\n  bool IsDots() const;\r\n};\r\n#endif\r\n\r\nclass CFindFile\r\n{\r\n  friend class CEnumerator;\r\n  HANDLE _handle;\r\npublic:\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }\r\n  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindFile() {  Close(); }\r\n  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n  bool FindNext(CFileInfo &fileInfo);\r\n  #ifndef _UNICODE\r\n  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\n  bool FindNext(CFileInfoW &fileInfo);\r\n  #endif\r\n  bool Close();\r\n};\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n\r\nbool DoesFileExist(LPCTSTR name);\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\nbool DoesFileExist(LPCWSTR name);\r\n#endif\r\n\r\nclass CEnumerator\r\n{\r\n  CFindFile _findFile;\r\n  CSysString _wildcard;\r\n  bool NextAny(CFileInfo &fileInfo);\r\npublic:\r\n  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfo &fileInfo);\r\n  bool Next(CFileInfo &fileInfo, bool &found);\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CEnumerator CEnumeratorW;\r\n#else\r\nclass CEnumeratorW\r\n{\r\n  CFindFile _findFile;\r\n  UString _wildcard;\r\n  bool NextAny(CFileInfoW &fileInfo);\r\npublic:\r\n  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfoW &fileInfo);\r\n  bool Next(CFileInfoW &fileInfo, bool &found);\r\n};\r\n#endif\r\n\r\nclass CFindChangeNotification\r\n{\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE () { return _handle; }\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }\r\n  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindChangeNotification() { Close(); }\r\n  bool Close();\r\n  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #ifndef _UNICODE\r\n  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #endif\r\n  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings);\r\n#endif\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifdef WIN_LONG_PATH\r\n#include \"../Common/MyString.h\"\r\n#endif\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR s, UString &res)\r\n{\r\n  res.Empty();\r\n  int len = MyStringLen(s);\r\n  wchar_t c = s[0];\r\n  if (len < 1 || c == L'\\\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))\r\n    return true;\r\n  UString curDir;\r\n  bool isAbs = false;\r\n  if (len > 3)\r\n    isAbs = (s[1] == L':' && s[2] == L'\\\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));\r\n\r\n  if (!isAbs)\r\n    {\r\n      DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));\r\n      curDir.ReleaseBuffer();\r\n      if (needLength == 0 || needLength > MAX_PATH)\r\n        return false;\r\n      if (curDir[curDir.Length() - 1] != L'\\\\')\r\n        curDir += L'\\\\';\r\n    }\r\n  res = UString(L\"\\\\\\\\?\\\\\") + curDir + s;\r\n  return true;\r\n}\r\n\r\nbool GetLongPath(LPCWSTR path, UString &longPath)\r\n{\r\n  if (GetLongPathBase(path, longPath))\r\n    return !longPath.IsEmpty();\r\n  return false;\r\n}\r\n#endif\r\n\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode,\r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n      flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP),\r\n      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFileW(fileName, desiredAccess, shareMode,\r\n    (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n    flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::CloseHandle(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if (sizeLow == 0xFFFFFFFF)\r\n    if (::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if (::GetLastError() != NO_ERROR)\r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if (!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CTime = winFileInfo.ftCreationTime;\r\n  fileInfo.ATime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.MTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes;\r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\n// Probably in some version of Windows there are problems with other sizes:\r\n// for 32 MB (maybe also for 16 MB).\r\n// And message can be \"Network connection was lost\"\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 22);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, cTime, aTime, mTime)); }\r\n\r\nbool COutFile::SetMTime(const FILETIME *mTime) {  return SetTime(NULL, NULL, mTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if (!Seek(length, newPosition))\r\n    return false;\r\n  if (newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{\r\n  DWORD    Attributes;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  DWORD    VolumeSerialNumber;\r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks;\r\n  UInt64   FileIndex;\r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _handle(INVALID_HANDLE_VALUE){};\r\n  ~CFileBase();\r\n\r\n  bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition);\r\n  bool SeekToBegin();\r\n  bool SeekToEnd(UInt64 &newPosition);\r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\r\n  bool SetMTime(const FILETIME *mTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileMapping.cpp",
    "content": "// Windows/FileMapping.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileMapping.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NMapping {\r\n\r\n\r\n\r\n\r\n}}}"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileMapping.h",
    "content": "// Windows/FileMapping.h\r\n\r\n#ifndef __WINDOWS_FILEMAPPING_H\r\n#define __WINDOWS_FILEMAPPING_H\r\n\r\n#include \"Windows/Handle.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\n// namespace NFile {\r\n// namespace NMapping {\r\n\r\nclass CFileMapping: public CHandle\r\n{\r\npublic:\r\n  bool Create(HANDLE file, LPSECURITY_ATTRIBUTES attributes,\r\n    DWORD protect, UINT64 maximumSize, LPCTSTR name)\r\n  {\r\n    _handle = ::CreateFileMapping(file, attributes,\r\n      protect, DWORD(maximumSize >> 32), DWORD(maximumSize), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenFileMapping(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  LPVOID MapViewOfFile(DWORD desiredAccess, UINT64 fileOffset,\r\n      SIZE_T numberOfBytesToMap)\r\n  {\r\n    return ::MapViewOfFile(_handle, desiredAccess,\r\n        DWORD(fileOffset >> 32), DWORD(fileOffset), numberOfBytesToMap);\r\n  }\r\n\r\n  LPVOID MapViewOfFileEx(DWORD desiredAccess, UINT64 fileOffset,\r\n      SIZE_T numberOfBytesToMap, LPVOID baseAddress)\r\n  {\r\n    return ::MapViewOfFileEx(_handle, desiredAccess,\r\n      DWORD(fileOffset >> 32), DWORD(fileOffset),\r\n      numberOfBytesToMap, baseAddress);\r\n  }\r\n  \r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileName.cpp",
    "content": "// Windows/FileName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)\r\n    dirPath += kDirDelimiter;\r\n}\r\n\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)\r\n    dirPath += wchar_t(kDirDelimiter);\r\n}\r\n#endif\r\n\r\nconst wchar_t kExtensionDelimiter = L'.';\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\r\n    UString &pureName, UString &extensionDelimiter, UString &extension)\r\n{\r\n  int index = fullName.ReverseFind(kExtensionDelimiter);\r\n  if (index < 0)\r\n  {\r\n    pureName = fullName;\r\n    extensionDelimiter.Empty();\r\n    extension.Empty();\r\n  }\r\n  else\r\n  {\r\n    pureName = fullName.Left(index);\r\n    extensionDelimiter = kExtensionDelimiter;\r\n    extension = fullName.Mid(index + 1);\r\n  }\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/FileName.h",
    "content": "// Windows/FileName.h\r\n\r\n#ifndef __WINDOWS_FILENAME_H\r\n#define __WINDOWS_FILENAME_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nconst TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;\r\nconst TCHAR kAnyStringWildcard = '*';\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\\\'\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\\\'\r\n#endif\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\r\n    UString &pureName, UString &extensionDelimiter, UString &extension);\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/Handle.h",
    "content": "// Windows/Handle.h\r\n\r\n#ifndef __WINDOWS_HANDLE_H\r\n#define __WINDOWS_HANDLE_H\r\n\r\nnamespace NWindows {\r\n\r\nclass CHandle\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE() { return _handle; }\r\n  CHandle(): _handle(NULL) {}\r\n  ~CHandle() { Close(); }\r\n  bool Close()\r\n  {\r\n    if (_handle == NULL)\r\n      return true;\r\n    if (!::CloseHandle(_handle))\r\n      return false;\r\n    _handle = NULL;\r\n    return true;\r\n  }\r\n  void Attach(HANDLE handle)\r\n    { _handle = handle; }\r\n  HANDLE Detach()\r\n  {\r\n    HANDLE handle = _handle;\r\n    _handle = NULL;\r\n    return handle;\r\n  }\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/MemoryLock.cpp",
    "content": "// Common/MemoryLock.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\n#ifndef _UNICODE\r\ntypedef BOOL (WINAPI * OpenProcessTokenP)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);\r\ntypedef BOOL (WINAPI * LookupPrivilegeValueP)(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID  lpLuid);\r\ntypedef BOOL (WINAPI * AdjustTokenPrivilegesP)(HANDLE TokenHandle, BOOL DisableAllPrivileges,\r\n    PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength);\r\n#endif\r\n\r\n#ifdef _UNICODE\r\nbool EnableLockMemoryPrivilege(\r\n#else\r\nstatic bool EnableLockMemoryPrivilege2(HMODULE hModule,\r\n#endif\r\nbool enable)\r\n{\r\n  #ifndef _UNICODE\r\n  if (hModule == NULL)\r\n    return false;\r\n  OpenProcessTokenP openProcessToken = (OpenProcessTokenP)GetProcAddress(hModule, \"OpenProcessToken\");\r\n  LookupPrivilegeValueP lookupPrivilegeValue = (LookupPrivilegeValueP)GetProcAddress(hModule, \"LookupPrivilegeValueA\" );\r\n  AdjustTokenPrivilegesP adjustTokenPrivileges = (AdjustTokenPrivilegesP)GetProcAddress(hModule, \"AdjustTokenPrivileges\");\r\n  if (openProcessToken == NULL || adjustTokenPrivileges == NULL || lookupPrivilegeValue == NULL)\r\n    return false;\r\n  #endif\r\n\r\n  HANDLE token;\r\n  if (!\r\n    #ifdef _UNICODE\r\n    ::OpenProcessToken\r\n    #else\r\n    openProcessToken\r\n    #endif\r\n    (::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))\r\n    return false;\r\n  TOKEN_PRIVILEGES tp;\r\n  bool res = false;\r\n  if (\r\n    #ifdef _UNICODE\r\n    ::LookupPrivilegeValue\r\n    #else\r\n    lookupPrivilegeValue\r\n    #endif\r\n    (NULL, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)))\r\n  {\r\n    tp.PrivilegeCount = 1;\r\n    tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED: 0;\r\n    if (\r\n      #ifdef _UNICODE\r\n      ::AdjustTokenPrivileges\r\n      #else\r\n      adjustTokenPrivileges\r\n      #endif\r\n      (token, FALSE, &tp, 0, NULL, NULL))\r\n      res = (GetLastError() == ERROR_SUCCESS);\r\n  }\r\n  ::CloseHandle(token);\r\n  return res;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool EnableLockMemoryPrivilege(bool enable)\r\n{\r\n  HMODULE hModule = LoadLibrary(TEXT(\"Advapi32.dll\"));\r\n  if (hModule == NULL)\r\n    return false;\r\n  bool res = EnableLockMemoryPrivilege2(hModule, enable);\r\n  ::FreeLibrary(hModule);\r\n  return res;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/MemoryLock.h",
    "content": "// Windows/MemoryLock.h\r\n\r\n#ifndef __WINDOWS_MEMORYLOCK_H\r\n#define __WINDOWS_MEMORYLOCK_H\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\nbool EnableLockMemoryPrivilege(bool enable = true);\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/PropVariant.cpp",
    "content": "// Windows/PropVariant.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariant.h\"\r\n\r\n#include \"../Common/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nCPropVariant::CPropVariant(const PROPVARIANT& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(const CPropVariant& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(BSTR bstrSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = bstrSrc;\r\n}\r\n\r\nCPropVariant::CPropVariant(LPCOLESTR lpszSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = lpszSrc;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const CPropVariant& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\nCPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(BSTR bstrSrc)\r\n{\r\n  *this = (LPCOLESTR)bstrSrc;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)\r\n{\r\n  InternalClear();\r\n  vt = VT_BSTR;\r\n  wReserved1 = 0;\r\n  bstrVal = ::SysAllocString(lpszSrc);\r\n  if (bstrVal == NULL && lpszSrc != NULL)\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = E_OUTOFMEMORY;\r\n  }\r\n  return *this;\r\n}\r\n\r\n\r\nCPropVariant& CPropVariant::operator=(bool bSrc)\r\n{\r\n  if (vt != VT_BOOL)\r\n  {\r\n    InternalClear();\r\n    vt = VT_BOOL;\r\n  }\r\n  boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt32 value)\r\n{\r\n  if (vt != VT_UI4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI4;\r\n  }\r\n  ulVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt64 value)\r\n{\r\n  if (vt != VT_UI8)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI8;\r\n  }\r\n  uhVal.QuadPart = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const FILETIME &value)\r\n{\r\n  if (vt != VT_FILETIME)\r\n  {\r\n    InternalClear();\r\n    vt = VT_FILETIME;\r\n  }\r\n  filetime = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int32 value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  \r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Byte value)\r\n{\r\n  if (vt != VT_UI1)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI1;\r\n  }\r\n  bVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int16 value)\r\n{\r\n  if (vt != VT_I2)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I2;\r\n  }\r\n  iVal = value;\r\n  return *this;\r\n}\r\n\r\n/*\r\nCPropVariant& CPropVariant::operator=(LONG value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  return *this;\r\n}\r\n*/\r\n\r\nstatic HRESULT MyPropVariantClear(PROPVARIANT *propVariant)\r\n{\r\n  switch(propVariant->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      propVariant->vt = VT_EMPTY;\r\n      propVariant->wReserved1 = 0;\r\n      return S_OK;\r\n  }\r\n  return ::VariantClear((VARIANTARG *)propVariant);\r\n}\r\n\r\nHRESULT CPropVariant::Clear()\r\n{\r\n  return MyPropVariantClear(this);\r\n}\r\n\r\nHRESULT CPropVariant::Copy(const PROPVARIANT* pSrc)\r\n{\r\n  ::VariantClear((tagVARIANT *)this);\r\n  switch(pSrc->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));\r\n      return S_OK;\r\n  }\r\n  return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc));\r\n}\r\n\r\n\r\nHRESULT CPropVariant::Attach(PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(this, pSrc, sizeof(PROPVARIANT));\r\n  pSrc->vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::Detach(PROPVARIANT* pDest)\r\n{\r\n  HRESULT hr = MyPropVariantClear(pDest);\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(pDest, this, sizeof(PROPVARIANT));\r\n  vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::InternalClear()\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n  return hr;\r\n}\r\n\r\nvoid CPropVariant::InternalCopy(const PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Copy(pSrc);\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n}\r\n\r\nint CPropVariant::Compare(const CPropVariant &a)\r\n{\r\n  if (vt != a.vt)\r\n    return 0; // it's mean some bug\r\n  switch (vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return 0;\r\n    \r\n    /*\r\n    case VT_I1:\r\n      return MyCompare(cVal, a.cVal);\r\n    */\r\n    case VT_UI1:\r\n      return MyCompare(bVal, a.bVal);\r\n\r\n    case VT_I2:\r\n      return MyCompare(iVal, a.iVal);\r\n    case VT_UI2:\r\n      return MyCompare(uiVal, a.uiVal);\r\n    \r\n    case VT_I4:\r\n      return MyCompare(lVal, a.lVal);\r\n    /*\r\n    case VT_INT:\r\n      return MyCompare(intVal, a.intVal);\r\n    */\r\n    case VT_UI4:\r\n      return MyCompare(ulVal, a.ulVal);\r\n    /*\r\n    case VT_UINT:\r\n      return MyCompare(uintVal, a.uintVal);\r\n    */\r\n    case VT_I8:\r\n      return MyCompare(hVal.QuadPart, a.hVal.QuadPart);\r\n    case VT_UI8:\r\n      return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);\r\n\r\n    case VT_BOOL:\r\n      return -MyCompare(boolVal, a.boolVal);\r\n\r\n    case VT_FILETIME:\r\n      return ::CompareFileTime(&filetime, &a.filetime);\r\n    case VT_BSTR:\r\n      return 0; // Not implemented\r\n      // return MyCompare(aPropVarint.cVal);\r\n\r\n    default:\r\n      return 0;\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/PropVariant.h",
    "content": "// Windows/PropVariant.h\r\n\r\n#ifndef __WINDOWS_PROPVARIANT_H\r\n#define __WINDOWS_PROPVARIANT_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nclass CPropVariant : public tagPROPVARIANT\r\n{\r\npublic:\r\n  CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }\r\n  ~CPropVariant() { Clear(); }\r\n  CPropVariant(const PROPVARIANT& varSrc);\r\n  CPropVariant(const CPropVariant& varSrc);\r\n  CPropVariant(BSTR bstrSrc);\r\n  CPropVariant(LPCOLESTR lpszSrc);\r\n  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };\r\n  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }\r\n  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal = *(ULARGE_INTEGER*)&value; }\r\n  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }\r\n  CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }\r\n  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }\r\n  CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }\r\n  // CPropVariant(LONG value, VARTYPE vtSrc = VT_I4) { vt = vtSrc; lVal = value; }\r\n\r\n  CPropVariant& operator=(const CPropVariant& varSrc);\r\n  CPropVariant& operator=(const PROPVARIANT& varSrc);\r\n  CPropVariant& operator=(BSTR bstrSrc);\r\n  CPropVariant& operator=(LPCOLESTR lpszSrc);\r\n  CPropVariant& operator=(bool bSrc);\r\n  CPropVariant& operator=(UInt32 value);\r\n  CPropVariant& operator=(UInt64 value);\r\n  CPropVariant& operator=(const FILETIME &value);\r\n\r\n  CPropVariant& operator=(Int32 value);\r\n  CPropVariant& operator=(Byte value);\r\n  CPropVariant& operator=(Int16 value);\r\n  // CPropVariant& operator=(LONG  value);\r\n\r\n  HRESULT Clear();\r\n  HRESULT Copy(const PROPVARIANT* pSrc);\r\n  HRESULT Attach(PROPVARIANT* pSrc);\r\n  HRESULT Detach(PROPVARIANT* pDest);\r\n\r\n  HRESULT InternalClear();\r\n  void InternalCopy(const PROPVARIANT* pSrc);\r\n\r\n  int Compare(const CPropVariant &a1);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/PropVariantConversions.cpp",
    "content": "// PropVariantConversions.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariantConversions.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\nstatic UString ConvertUInt64ToString(UInt64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString ConvertInt64ToString(Int64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic char *UIntToStringSpec(char c, UInt32 value, char *s, int numPos)\r\n{\r\n  if (c != 0)\r\n    *s++ = c;\r\n  char temp[16];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (char)('0' + value % 10);\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  int i;\r\n  for (i = 0; i < numPos - pos; i++)\r\n    *s++ = '0';\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n  return s;\r\n}\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)\r\n{\r\n  s[0] = '\\0';\r\n  SYSTEMTIME st;\r\n  if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))\r\n    return false;\r\n  s = UIntToStringSpec(0, st.wYear, s, 4);\r\n  s = UIntToStringSpec('-', st.wMonth, s, 2);\r\n  s = UIntToStringSpec('-', st.wDay, s, 2);\r\n  if (includeTime)\r\n  {\r\n    s = UIntToStringSpec(' ', st.wHour, s, 2);\r\n    s = UIntToStringSpec(':', st.wMinute, s, 2);\r\n    if (includeSeconds)\r\n      UIntToStringSpec(':', st.wSecond, s, 2);\r\n  }\r\n  return true;\r\n}\r\n\r\nUString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds)\r\n{\r\n  char s[32];\r\n  ConvertFileTimeToString(fileTime, s,  includeTime, includeSeconds);\r\n  return GetUnicodeString(s);\r\n}\r\n \r\n\r\nUString ConvertPropVariantToString(const PROPVARIANT &prop)\r\n{\r\n  switch (prop.vt)\r\n  {\r\n    case VT_EMPTY: return UString();\r\n    case VT_BSTR: return prop.bstrVal;\r\n    case VT_UI1: return ConvertUInt64ToString(prop.bVal);\r\n    case VT_UI2: return ConvertUInt64ToString(prop.uiVal);\r\n    case VT_UI4: return ConvertUInt64ToString(prop.ulVal);\r\n    case VT_UI8: return ConvertUInt64ToString(prop.uhVal.QuadPart);\r\n    case VT_FILETIME: return ConvertFileTimeToString(prop.filetime, true, true);\r\n    // case VT_I1: return ConvertInt64ToString(prop.cVal);\r\n    case VT_I2: return ConvertInt64ToString(prop.iVal);\r\n    case VT_I4: return ConvertInt64ToString(prop.lVal);\r\n    case VT_I8: return ConvertInt64ToString(prop.hVal.QuadPart);\r\n    case VT_BOOL: return VARIANT_BOOLToBool(prop.boolVal) ? L\"+\" : L\"-\";\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 150245;\r\n      #else\r\n      return UString();\r\n      #endif\r\n  }\r\n}\r\n\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &prop)\r\n{\r\n  switch (prop.vt)\r\n  {\r\n    case VT_UI1: return prop.bVal;\r\n    case VT_UI2: return prop.uiVal;\r\n    case VT_UI4: return prop.ulVal;\r\n    case VT_UI8: return (UInt64)prop.uhVal.QuadPart;\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 151199;\r\n      #else\r\n      return 0;\r\n      #endif\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/PropVariantConversions.h",
    "content": "// Windows/PropVariantConversions.h\r\n\r\n#ifndef __PROPVARIANTCONVERSIONS_H\r\n#define __PROPVARIANTCONVERSIONS_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/MyString.h\"\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant);\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/Synchronization.cpp",
    "content": "// Windows/Synchronization.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Synchronization.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/Synchronization.h",
    "content": "// Windows/Synchronization.h\r\n\r\n#ifndef __WINDOWS_SYNCHRONIZATION_H\r\n#define __WINDOWS_SYNCHRONIZATION_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\n#ifdef _WIN32\r\n#include \"Handle.h\"\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\nclass CBaseEvent\r\n{\r\nprotected:\r\n  ::CEvent _object;\r\npublic:\r\n  bool IsCreated() { return Event_IsCreated(&_object) != 0; }\r\n  operator HANDLE() { return _object.handle; }\r\n  CBaseEvent() { Event_Construct(&_object); }\r\n  ~CBaseEvent() { Close(); }\r\n  WRes Close() { return Event_Close(&_object); }\r\n  #ifdef _WIN32\r\n  WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),\r\n        BoolToBOOL(initiallyOwn), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  #endif\r\n\r\n  WRes Set() { return Event_Set(&_object); }\r\n  // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }\r\n  WRes Reset() { return Event_Reset(&_object); }\r\n  WRes Lock() { return Event_Wait(&_object); }\r\n};\r\n\r\nclass CManualResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  WRes Create(bool initiallyOwn = false)\r\n  {\r\n    return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);\r\n  }\r\n  WRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return ManualResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  #ifdef _WIN32\r\n  WRes CreateWithName(bool initiallyOwn, LPCTSTR name)\r\n  {\r\n    return CBaseEvent::Create(true, initiallyOwn, name);\r\n  }\r\n  #endif\r\n};\r\n\r\nclass CAutoResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  WRes Create()\r\n  {\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  WRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\nclass CObject: public CHandle\r\n{\r\npublic:\r\n  WRes Lock(DWORD timeoutInterval = INFINITE)\r\n    { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }\r\n};\r\nclass CMutex: public CObject\r\n{\r\npublic:\r\n  WRes Create(bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Release()\r\n  {\r\n    return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();\r\n  }\r\n};\r\nclass CMutexLock\r\n{\r\n  CMutex *_object;\r\npublic:\r\n  CMutexLock(CMutex &object): _object(&object) { _object->Lock(); }\r\n  ~CMutexLock() { _object->Release(); }\r\n};\r\n#endif\r\n\r\nclass CSemaphore\r\n{\r\n  ::CSemaphore _object;\r\npublic:\r\n  CSemaphore() { Semaphore_Construct(&_object); }\r\n  ~CSemaphore() { Close(); }\r\n  WRes Close() {  return Semaphore_Close(&_object); }\r\n  operator HANDLE() { return _object.handle; }\r\n  WRes Create(UInt32 initiallyCount, UInt32 maxCount)\r\n  {\r\n    return Semaphore_Create(&_object, initiallyCount, maxCount);\r\n  }\r\n  WRes Release() { return Semaphore_Release1(&_object); }\r\n  WRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }\r\n  WRes Lock() { return Semaphore_Wait(&_object); }\r\n};\r\n\r\nclass CCriticalSection\r\n{\r\n  ::CCriticalSection _object;\r\npublic:\r\n  CCriticalSection() { CriticalSection_Init(&_object); }\r\n  ~CCriticalSection() { CriticalSection_Delete(&_object); }\r\n  void Enter() { CriticalSection_Enter(&_object); }\r\n  void Leave() { CriticalSection_Leave(&_object); }\r\n};\r\n\r\nclass CCriticalSectionLock\r\n{\r\n  CCriticalSection *_object;\r\n  void Unlock()  { _object->Leave(); }\r\npublic:\r\n  CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); }\r\n  ~CCriticalSectionLock() { Unlock(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/System.cpp",
    "content": "// Windows/System.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"System.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors()\r\n{\r\n  SYSTEM_INFO systemInfo;\r\n  GetSystemInfo(&systemInfo);\r\n  return (UInt32)systemInfo.dwNumberOfProcessors;\r\n}\r\n\r\n#if !defined(_WIN64) && defined(__GNUC__)\r\n\r\ntypedef struct _MY_MEMORYSTATUSEX {\r\n  DWORD dwLength;\r\n  DWORD dwMemoryLoad;\r\n  DWORDLONG ullTotalPhys;\r\n  DWORDLONG ullAvailPhys;\r\n  DWORDLONG ullTotalPageFile;\r\n  DWORDLONG ullAvailPageFile;\r\n  DWORDLONG ullTotalVirtual;\r\n  DWORDLONG ullAvailVirtual;\r\n  DWORDLONG ullAvailExtendedVirtual;\r\n} MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX;\r\n\r\n#else\r\n\r\n#define MY_MEMORYSTATUSEX MEMORYSTATUSEX\r\n#define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX\r\n\r\n#endif\r\n\r\ntypedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);\r\n\r\nUInt64 GetRamSize()\r\n{\r\n  MY_MEMORYSTATUSEX stat;\r\n  stat.dwLength = sizeof(stat);\r\n  #ifdef _WIN64\r\n  if (!::GlobalMemoryStatusEx(&stat))\r\n    return 0;\r\n  return stat.ullTotalPhys;\r\n  #else\r\n  GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")),\r\n        \"GlobalMemoryStatusEx\");\r\n  if (globalMemoryStatusEx != 0)\r\n    if (globalMemoryStatusEx(&stat))\r\n      return stat.ullTotalPhys;\r\n  {\r\n    MEMORYSTATUS stat;\r\n    stat.dwLength = sizeof(stat);\r\n    GlobalMemoryStatus(&stat);\r\n    return stat.dwTotalPhys;\r\n  }\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/System.h",
    "content": "// Windows/System.h\r\n\r\n#ifndef __WINDOWS_SYSTEM_H\r\n#define __WINDOWS_SYSTEM_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors();\r\nUInt64 GetRamSize();\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/Thread.h",
    "content": "// Windows/Thread.h\r\n\r\n#ifndef __WINDOWS_THREAD_H\r\n#define __WINDOWS_THREAD_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\nnamespace NWindows {\r\n\r\nclass CThread\r\n{\r\n  ::CThread thread;\r\npublic:\r\n  CThread() { Thread_Construct(&thread); }\r\n  ~CThread() { Close(); }\r\n  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }\r\n  WRes Close()  { return Thread_Close(&thread); }\r\n  WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n    { return Thread_Create(&thread, startAddress, parameter); }\r\n  WRes Wait() { return Thread_Wait(&thread); }\r\n  \r\n  #ifdef _WIN32\r\n  operator HANDLE() { return thread.handle; }\r\n  void Attach(HANDLE handle) { thread.handle = handle; }\r\n  HANDLE Detach() { HANDLE h = thread.handle; thread.handle = NULL; return h; }\r\n  DWORD Resume() { return ::ResumeThread(thread.handle); }\r\n  DWORD Suspend() { return ::SuspendThread(thread.handle); }\r\n  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }\r\n  int GetPriority() { return ::GetThreadPriority(thread.handle); }\r\n  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }\r\n  #endif\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/Time.cpp",
    "content": "// Windows/Time.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Time.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)\r\n{\r\n  return BOOLToBool(::DosDateTimeToFileTime((UInt16)(dosTime >> 16), (UInt16)(dosTime & 0xFFFF), &fileTime));\r\n}\r\n\r\nstatic const UInt32 kHighDosTime = 0xFF9FBF7D;\r\nstatic const UInt32 kLowDosTime = 0x210000;\r\n\r\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)\r\n{\r\n  WORD datePart, timePart;\r\n  if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))\r\n  {\r\n    dosTime = (fileTime.dwHighDateTime >= 0x01C00000) ? kHighDosTime : kLowDosTime;\r\n    return false;\r\n  }\r\n  dosTime = (((UInt32)datePart) << 16) + timePart;\r\n  return true;\r\n}\r\n\r\nstatic const UInt32 kNumTimeQuantumsInSecond = 10000000;\r\nstatic const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;\r\n\r\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)\r\n{\r\n  UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;\r\n  fileTime.dwLowDateTime = (DWORD)v;\r\n  fileTime.dwHighDateTime = (DWORD)(v >> 32);\r\n}\r\n\r\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)\r\n{\r\n  UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;\r\n  if (winTime < kUnixTimeStartValue)\r\n  {\r\n    unixTime = 0;\r\n    return false;\r\n  }\r\n  winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;\r\n  if (winTime > 0xFFFFFFFF)\r\n  {\r\n    unixTime = 0xFFFFFFFF;\r\n    return false;\r\n  }\r\n  unixTime = (UInt32)winTime;\r\n  return true;\r\n}\r\n\r\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\r\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds)\r\n{\r\n  resSeconds = 0;\r\n  if (year < 1601 || year >= 10000 || month < 1 || month > 12 ||\r\n      day < 1 || day > 31 || hour > 23 || min > 59 || sec > 59)\r\n    return false;\r\n  UInt32 numYears = year - 1601;\r\n  UInt32 numDays = numYears * 365 + numYears / 4 - numYears / 100 + numYears / 400;\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  month--;\r\n  for (unsigned i = 0; i < month; i++)\r\n    numDays += ms[i];\r\n  numDays += day - 1;\r\n  resSeconds = ((UInt64)(numDays * 24 + hour) * 60 + min) * 60 + sec;\r\n  return true;\r\n}\r\n\r\nvoid GetCurUtcFileTime(FILETIME &ft)\r\n{\r\n  SYSTEMTIME st;\r\n  GetSystemTime(&st);\r\n  SystemTimeToFileTime(&st, &ft);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CPP/Windows/Time.h",
    "content": "// Windows/Time.h\r\n\r\n#ifndef __WINDOWS_TIME_H\r\n#define __WINDOWS_TIME_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime);\r\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime);\r\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime);\r\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime);\r\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\r\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds);\r\nvoid GetCurUtcFileTime(FILETIME &ft);\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid SetStream(System.IO.Stream inStream);\r\n\t\tvoid Init();\r\n\t\tvoid ReleaseStream();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetMatches(UInt32[] distances);\r\n\t\tvoid Skip(UInt32 num);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize = 0;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\tUInt32[] _son;\r\n\t\tUInt32[] _hash;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\t\tUInt32 _hashMask;\r\n\t\tUInt32 _hashSizeSum = 0;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\r\n\t\tconst UInt32 kHash2Size = 1 << 10;\r\n\t\tconst UInt32 kHash3Size = 1 << 16;\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kStartMaxLen = 1;\r\n\t\tconst UInt32 kHash3Offset = kHash2Size;\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\t\r\n\t\tUInt32 kNumHashDirectBytes = 0;\r\n\t\tUInt32 kMinMatchCheck = 4;\r\n\t\tUInt32 kFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\r\n\t\tpublic void SetType(int numHashBytes)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\t\tkMinMatchCheck = 4;\r\n\t\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\t\tkFixHashSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic new void SetStream(System.IO.Stream stream) { base.SetStream(stream); }\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\t\t\r\n\t\tpublic new void Init()\r\n\t\t{\r\n\t\t\tbase.Init();\r\n\t\t\tfor (UInt32 i = 0; i < _hashSizeSum; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\t\tthrow new Exception();\r\n\t\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\t\t\t\t\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\tUInt32 cyclicBufferSize = historySize + 1;\r\n\t\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t\t_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\t\tUInt32 hs = kBT2HashSize;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\ths = historySize - 1;\r\n\t\t\t\ths |= (hs >> 1);\r\n\t\t\t\ths |= (hs >> 2);\r\n\t\t\t\ths |= (hs >> 4);\r\n\t\t\t\ths |= (hs >> 8);\r\n\t\t\t\ths >>= 1;\r\n\t\t\t\ths |= 0xFFFF;\r\n\t\t\t\tif (hs > (1 << 24))\r\n\t\t\t\t\ths >>= 1;\r\n\t\t\t\t_hashMask = hs;\r\n\t\t\t\ths++;\r\n\t\t\t\ths += kFixHashSize;\r\n\t\t\t}\r\n\t\t\tif (hs != _hashSizeSum)\r\n\t\t\t\t_hash = new UInt32[_hashSizeSum = hs];\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetMatches(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 offset = 0;\r\n\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\t\t\tUInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 curMatch2 = _hash[hash2Value];\r\n\t\t\t\tUInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t\t{\r\n\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\t\t\t\r\n\t\t\tif (kNumHashDirectBytes != 0)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\r\n\t\t\twhile(true)\r\n\t\t\t{\r\n\t\t\t\tif(curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (maxLen < len)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t\treturn offset;\r\n\t\t}\r\n\r\n\t\tpublic void Skip(UInt32 num)\r\n\t\t{\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenLimit;\r\n\t\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tMovePos();\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\t\tUInt32 hashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\t\tUInt32 hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\t\tUInt32 hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\t\tUInt32 len0, len1;\r\n\t\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\t\tlen1 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\t\tlen0 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tMovePos();\r\n\t\t\t}\r\n\t\t\twhile (--num != 0);\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 subValue = _pos - _cyclicBufferSize;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize; // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos; // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos\r\n\t\tpublic UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\t\tif (offset > 0)\r\n\t\t\t\toffset--;\r\n\t\t\t\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { _stream = stream; }\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic uint TrainSize = 0;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t\tTrainSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tlong len = stream.Length;\r\n\t\t\tuint size = (len < _windowSize) ? (uint)len : _windowSize;\r\n\t\t\tTrainSize = size;\r\n\t\t\tstream.Position = len - size;\r\n\t\t\t_streamPos = _pos = 0;\r\n\t\t\twhile (size > 0)\r\n\t\t\t{\r\n\t\t\t\tuint curSize = _windowSize - _pos;\r\n\t\t\t\tif (size < curSize)\r\n\t\t\t\t\tcurSize = size;\r\n\t\t\t\tint numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tsize -= (uint)numReadBytes;\r\n\t\t\t\t_pos += (uint)numReadBytes;\r\n\t\t\t\t_streamPos += (uint)numReadBytes;\r\n\t\t\t\tif (_pos == _windowSize)\r\n\t\t\t\t\t_streamPos = _pos = 0;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t\tpublic bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\t// public const int kDicLogSizeMax = 30;\r\n\t\t// public const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tbool _solid = false;\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream, _solid);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t_solid = true;\r\n\t\t\treturn m_OutWindow.Train(stream);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get { return 0; }}\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t};\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1 << 11];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 22;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 11))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 21))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 10] + 20);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 20] + 40);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 17))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 27))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 16] + 32);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 26] + 52);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 22;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32[] prices, UInt32 st)\r\n\t\t\t{\r\n\t\t\t\tUInt32 a0 = _choice.GetPrice0();\r\n\t\t\t\tUInt32 a1 = _choice.GetPrice1();\r\n\t\t\t\tUInt32 b0 = a1 + _choice2.GetPrice0();\r\n\t\t\t\tUInt32 b1 = a1 + _choice2.GetPrice1();\r\n\t\t\t\tUInt32 i = 0;\r\n\t\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\tLZ.IMatchFinder _matchFinder = null;\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates];\r\n\t\t\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];\r\n\t\t\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _numDistancePairs;\r\n\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\t\tSystem.IO.Stream _inStream;\r\n\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark = false;\r\n\t\t\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tif (_matchFinderType == EMatchFinderType.BT2)\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs)\r\n\t\t{\r\n\t\t\tlenRes = 0;\r\n\t\t\tnumDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\t\tif (numDistancePairs > 0)\r\n\t\t\t{\r\n\t\t\t\tlenRes = _matchDistances[numDistancePairs - 2];\r\n\t\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t}\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tif (num > 0)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Skip(num);\r\n\t\t\t\t_additionalOffset += num;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t\t}\r\n\t\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\t\tUInt32 lenMain, numDistancePairs;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain, out numDistancePairs);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\t\t\t\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = (UInt32)0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\t\tif(lenEnd < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\t\tUInt32 len = lenEnd;\r\n\t\t\tdo\r\n\t\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\t\twhile (len >= 2);\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tif (repLen < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tUInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--repLen >= 2);\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\t\t\t\r\n\t\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\t\tif (len <= lenMain)\r\n\t\t\t{\r\n\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\tfor (; ; len++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 distance = _matchDistances[offs + 1];\r\n\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen, out numDistancePairs);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_numDistancePairs = numDistancePairs;\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t\t{\r\n\t\t\t\t\t// try Literal + rep0\r\n\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 startLen = 2; // speed optimization \r\n\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t\t// if (_maxMode)\r\n\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, reps[repIndex], t);\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)(reps[repIndex] + 1))), \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t\t}\r\n\t\t\t\tif (newLen >= startLen)\r\n\t\t\t\t{\r\n\t\t\t\t\tnormalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = startLen; ; lenTest++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t);\r\n\t\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)(curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t\t_matchFinder.Init();\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t\tif (_trainSize > 0)\r\n\t\t\t\t\t_matchFinder.Skip(_trainSize);\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len, numDistancePairs; // it's not used\r\n\t\t\t\tReadMatchDistances(out len, out numDistancePairs);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 len = GetOptimum((UInt32)nowPos64, out pos);\r\n\t\t\t\t\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t// if (!_fastMode)\r\n\t\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// if (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\t\t\r\n\t\tUInt32[] tempPrices = new UInt32[Base.kNumFullDistances];\r\n\t\tUInt32 _matchPriceCount;\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t\t{ \r\n\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, \r\n\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tRangeCoder.BitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\t\t\t\r\n\t\t\t\tUInt32 st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\t\tUInt32 st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t\t}\r\n\t\t\t_matchPriceCount = 0;\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = 0;\r\n\t\t}\r\n\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t/*\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t*/\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 30;\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _trainSize = 0;\r\n\t\tpublic void SetTrainSize(uint trainSize)\r\n\t\t{\r\n\t\t\t_trainSize = trainSize;\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\t\r\n\tpublic class CDoubleStream: Stream\r\n\t{\r\n\t\tpublic System.IO.Stream s1;\r\n\t\tpublic System.IO.Stream s2;\r\n\t\tpublic int fileIndex;\r\n\t\tpublic long skipSize;\r\n\t\t\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return false; }}\r\n\t\tpublic override bool CanSeek { get { return false; }}\r\n\t\tpublic override long Length { get { return s1.Length + s2.Length - skipSize; } }\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\tint numTotal = 0;\r\n\t\t\twhile (count > 0)\r\n\t\t\t{\r\n\t\t\t\tif (fileIndex == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tint num = s1.Read(buffer, offset, count);\r\n\t\t\t\t\toffset += num;\r\n\t\t\t\t\tcount -= num;\r\n\t\t\t\t\tnumTotal += num;\r\n\t\t\t\t\tif (num == 0)\r\n\t\t\t\t\t\tfileIndex++;\r\n\t\t\t\t}\r\n\t\t\t\tif (fileIndex == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tnumTotal += s2.Read(buffer, offset, count);\r\n\t\t\t\t\treturn numTotal;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn numTotal;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Write\"));\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Seek\"));\r\n\t\t}\r\n\t\tpublic override void SetLength(long value)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't SetLength\"));\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut,\r\n\t\t\tTrain\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0, 29], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.61  2008-11-23\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[13];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"T\", SwitchType.UnLimitedPostString, false, 1);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary);\r\n\t\t\t}\r\n\r\n\t\t\tstring train = \"\";\r\n\t\t\tif (parser[(int)Key.Train].ThereIs)\r\n\t\t\t\ttrain = (string)parser[(int)Key.Train].PostStrings[0];\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream trainStream = null;\r\n\t\t\tif (train.Length != 0)\r\n\t\t\t\ttrainStream = new FileStream(train, FileMode.Open, FileAccess.Read);\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tCDoubleStream doubleStream = new CDoubleStream();\r\n\t\t\t\t\tdoubleStream.s1 = trainStream;\r\n\t\t\t\t\tdoubleStream.s2 = inStream;\r\n\t\t\t\t\tdoubleStream.fileIndex = 0;\r\n\t\t\t\t\tinStream = doubleStream;\r\n\t\t\t\t\tlong trainFileSize = trainStream.Length;\r\n\t\t\t\t\tdoubleStream.skipSize = 0;\r\n\t\t\t\t\tif (trainFileSize > dictionary)\r\n\t\t\t\t\t\tdoubleStream.skipSize = trainFileSize - dictionary;\r\n\t\t\t\t\ttrainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);\r\n\t\t\t\t\tencoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));\r\n\t\t\t\t}\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!decoder.Train(trainStream))\r\n\t\t\t\t\t\tthrow (new Exception(\"can't train\"));\r\n\t\t\t\t}\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.50727</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tUInt32 Rep0;\r\n\t\t\t\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\t\tUInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\tRG.Init();\r\n\t\t\t\tRep0 = 1;\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)RG.GetRnd(8);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 len;\r\n\t\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\t\tUInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 220 + outSize * 20;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 18))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "// LZ.BinTree\r\n\r\npackage SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\r\n\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize = 0;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\tint[] _hash;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\tint _hashMask;\r\n\tint _hashSizeSum = 0;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\r\n\tstatic final int kHash2Size = 1 << 10;\r\n\tstatic final int kHash3Size = 1 << 16;\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kStartMaxLen = 1;\r\n\tstatic final int kHash3Offset = kHash2Size;\r\n\tstatic final int kEmptyHashValue = 0;\r\n\tstatic final int kMaxValForNormalize = (1 << 30) - 1;\r\n\t\r\n\tint kNumHashDirectBytes = 0;\r\n\tint kMinMatchCheck = 4;\r\n\tint kFixHashSize = kHash2Size + kHash3Size;\r\n\r\n\tpublic void SetType(int numHashBytes)\r\n\t{\r\n\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\tkMinMatchCheck = 4;\r\n\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\tkFixHashSize = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tfor (int i = 0; i < _hashSizeSum; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\treturn false;\r\n\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\tint cyclicBufferSize = historySize + 1;\r\n\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t_son = new int[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\tint hs = kBT2HashSize;\r\n\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\ths = historySize - 1;\r\n\t\t\ths |= (hs >> 1);\r\n\t\t\ths |= (hs >> 2);\r\n\t\t\ths |= (hs >> 4);\r\n\t\t\ths |= (hs >> 8);\r\n\t\t\ths >>= 1;\r\n\t\t\ths |= 0xFFFF;\r\n\t\t\tif (hs > (1 << 24))\r\n\t\t\t\ths >>= 1;\r\n\t\t\t_hashMask = hs;\r\n\t\t\ths++;\r\n\t\t\ths += kFixHashSize;\r\n\t\t}\r\n\t\tif (hs != _hashSizeSum)\r\n\t\t\t_hash = new int [_hashSizeSum = hs];\r\n\t\treturn true;\r\n\t}\r\n\tpublic int GetMatches(int[] distances) throws IOException\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t{\r\n\t\t\t\tMovePos();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint offset = 0;\r\n\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\tint maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint curMatch2 = _hash[hash2Value];\r\n\t\t\tint curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t}\r\n\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t}\r\n\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t{\r\n\t\t\t\toffset -= 2;\r\n\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\tint len0, len1;\r\n\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\tif (kNumHashDirectBytes != 0)\r\n\t\t{\r\n\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint count = _cutValue;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint len = Math.min(len0, len1);\r\n\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t{\r\n\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tif (maxLen < len)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t{\r\n\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\tlen1 = len;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\tlen0 = len;\r\n\t\t\t}\r\n\t\t}\r\n\t\tMovePos();\r\n\t\treturn offset;\r\n\t}\r\n\r\n\tpublic void Skip(int num) throws IOException\r\n\t{\r\n\t\tdo\r\n\t\t{\r\n\t\t\tint lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tint cur = _bufferOffset + _pos;\r\n\t\t\t\r\n\t\t\tint hashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\t\tint hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\t\tint hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tint len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\tint count = _cutValue;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tint len = Math.min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t}\r\n\t\twhile (--num != 0);\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint subValue = _pos - _cyclicBufferSize;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue) { _cutValue = cutValue; }\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\tif (offset > 0)\r\n\t\t\toffset--;\r\n\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free() { _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream) { _stream = stream; \t}\r\n\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\t// public static final int kDicLogSizeMax = 28;\r\n\t// public static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\r\n\r\n\r\n\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\r\n\tstatic byte[] g_FastPos = new byte[1 << 11];\r\n\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 22;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 11))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 21))\r\n\t\t\treturn (g_FastPos[pos >> 10] + 20);\r\n\t\treturn (g_FastPos[pos >> 20] + 40);\r\n\t}\r\n\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 17))\r\n\t\t\treturn (g_FastPos[pos >> 6] + 12);\r\n\t\tif (pos < (1 << 27))\r\n\t\t\treturn (g_FastPos[pos >> 16] + 32);\r\n\t\treturn (g_FastPos[pos >> 26] + 52);\r\n\t}\r\n\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\r\n\tstatic final int kDefaultDictionaryLogSize = 22;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\r\n\t\t\tpublic void Init() { SevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders); }\r\n\r\n\r\n\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetPrices(int posState, int numSymbols, int[] prices, int st)\r\n\t\t{\r\n\t\t\tint a0 = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\tint a1 = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\tint b0 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\tint b1 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\tint i = 0;\r\n\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t}\r\n\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t}\r\n\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t}\r\n\t};\r\n\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols<<Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\tpublic void SetTableSize(int tableSize) { _tableSize = tableSize; }\r\n\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t}\r\n\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\r\n\tstatic final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;\r\n\t\tpublic int BackPrev;\r\n\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\r\n\t\tpublic void MakeAsChar() { BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep() { return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null;\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\r\n\tshort[] _isMatch = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances-Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen*2+2];\r\n\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _numDistancePairs;\r\n\r\n\tint _additionalOffset;\r\n\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\r\n\tboolean _longestMatchWasFound;\r\n\r\n\tint[] _posSlotPrices = new int[1<<(Base.kNumPosSlotBits+Base.kNumLenToPosStatesBits)];\r\n\tint[] _distancesPrices = new int[Base.kNumFullDistances<<Base.kNumLenToPosStatesBits];\r\n\tint[] _alignPrices = new int[Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\tjava.io.InputStream _inStream;\r\n\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\r\n\tboolean _needReleaseMFStream = false;\r\n\r\n\tvoid Create()\r\n\t{\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tif (_matchFinderType == EMatchFinderTypeBT2)\r\n\t\t\t\tnumHashBytes = 2;\r\n\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\r\n\tvoid SetWriteEndMarkerMode(boolean writeEndMarker)\r\n\t{\r\n\t\t_writeEndMark = writeEndMarker;\r\n\t}\r\n\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\r\n\r\n\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n\t\t_posAlignEncoder.Init();\r\n\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = 0;\r\n\t\t_numDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\tif (_numDistancePairs > 0)\r\n\t\t{\r\n\t\t\tlenRes = _matchDistances[_numDistancePairs - 2];\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[_numDistancePairs - 1],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t}\r\n\t\t_additionalOffset++;\r\n\t\treturn lenRes;\r\n\t}\r\n\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tif (num > 0)\r\n\t\t{\r\n\t\t\t_matchFinder.Skip(num);\r\n\t\t\t_additionalOffset += num;\r\n\t\t}\r\n\t}\r\n\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\r\n\tint GetPureRepPrice(int repIndex, int state, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t}\r\n\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\r\n\tint Backward(int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\tint backRes;\r\n\r\n\tint GetOptimum(int position) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\tint lenMain, numDistancePairs;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tnumDistancePairs = _numDistancePairs;\r\n\r\n\t\tint numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\tif (numAvailableBytes < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\tbyte matchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[0].State = _state;\r\n\r\n\t\tint posState = (position & _posStateMask);\r\n\r\n\t\t_optimum[1].Price = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\tif (lenEnd < 2)\r\n\t\t{\r\n\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\tint len = lenEnd;\r\n\t\tdo\r\n\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\twhile (len >= 2);\r\n\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tif (repLen < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tint price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twhile (--repLen >= 2);\r\n\t\t}\r\n\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\r\n\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\tif (len <= lenMain)\r\n\t\t{\r\n\t\t\tint offs = 0;\r\n\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\toffs += 2;\r\n\t\t\tfor (; ; len++)\r\n\t\t\t{\r\n\t\t\t\tint distance = _matchDistances[offs + 1];\r\n\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t{\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint cur = 0;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\r\n\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t{\r\n\t\t\t\t// try Literal + rep0\r\n\t\t\t\tint t = Math.min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint startLen = 2; // speed optimization \r\n\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\tint lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t// if (_maxMode)\r\n\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t{\r\n\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, reps[repIndex], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - (reps[repIndex] + 1)),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t{\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t}\r\n\t\t\tif (newLen >= startLen)\r\n\t\t\t{\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\tint offs = 0;\r\n\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\tfor (int lenTest = startLen; ; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, curBack, t);\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\r\n\t\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - (curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\r\n\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\r\n\t\t\tint len = GetOptimum((int)nowPos64);\r\n\t\t\tint pos = backRes;\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\t// if (!_fastMode)\r\n\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\r\n\t\t// if (!_fastMode)\r\n\t\t{\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\r\n\tlong[] processedInSize = new long[1]; long[] processedOutSize = new long[1]; boolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\r\n\r\n\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\r\n\tint[] tempPrices = new int[Base.kNumFullDistances];\r\n\tint _matchPriceCount;\r\n\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t{\r\n\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t}\r\n\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tBitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\r\n\t\t\tint st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\tint st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t}\r\n\t\t_matchPriceCount = 0;\r\n\t}\r\n\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = 0;\r\n\t}\r\n\r\n\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\t/*\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\t*/\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = 29;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++) ;\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.61  2008-11-23\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SetNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator() { Init(); }\r\n\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tint Rep0;\r\n\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\r\n\t\tpublic CBenchRandomGenerator() { }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit() { return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\tint GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\tRG.Init();\r\n\t\t\tRep0 = 1;\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint len;\r\n\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, long elapsedTime, long size)\r\n\t{\r\n\t\tlong t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\tlong numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime, long outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 220 + outSize * 20;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 18))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 18 (256 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/Methods.txt",
    "content": "7-Zip method IDs (4.65)\r\n-----------------------\r\n\r\nEach compression or crypto method in 7z has unique binary value (ID).\r\nThe length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).\r\n\r\nIf you want to add some new ID, you have two ways:\r\n1) Write request for allocating IDs to 7-zip developers.\r\n2) Generate 8-bytes ID:\r\n\r\n    3F ZZ ZZ ZZ ZZ ZZ MM MM \r\n\r\n    3F              - Prefix for random IDs (1 byte)\r\n    ZZ ZZ ZZ ZZ ZZ  - Developer ID (5 bytes). Use real random bytes. \r\n                      \r\n    MM MM           - Method ID (2 bytes)\r\n\r\n    You can notify 7-Zip developers about your Developer ID / Method ID.\r\n\r\n    Note: Use new ID only if old codec can not decode data encoded with new version.\r\n\r\n\r\nList of defined IDs\r\n-------------------\r\n      \r\n00 - Copy\r\n\r\n02 - Common\r\n   03 Swap\r\n      - 2 Swap2\r\n      - 4 Swap4\r\n\r\n03 - 7z\r\n   01 - LZMA\r\n      01 - Version\r\n  \r\n   03 - Branch\r\n      01 - x86\r\n         03  - BCJ\r\n         1B  - BCJ2\r\n      02 - PPC\r\n         05 - PPC (Big Endian)\r\n      03 - Alpha\r\n         01 - Alpha\r\n      04 - IA64\r\n         01 - IA64\r\n      05 - ARM\r\n         01 - ARM\r\n      06 - M68\r\n         05 - M68 (Big Endian)\r\n      07 - ARM Thumb\r\n         01 - ARMT\r\n      08 - SPARC\r\n         05 - SPARC\r\n\r\n   04 - PPMD\r\n      01 - Version\r\n\r\n   7F -\r\n      01 - experimental methods.\r\n\r\n\r\n04 - Misc\r\n   00 - Reserved\r\n   01 - Zip\r\n      00 - Copy (not used). Use {00} instead\r\n      01 - Shrink\r\n      06 - Implode\r\n      08 - Deflate\r\n      09 - Deflate64\r\n      12 - BZip2 (not used). Use {04 02 02} instead\r\n   02 - BZip\r\n      02 - BZip2\r\n   03 - Rar\r\n      01 - Rar15\r\n      02 - Rar20\r\n      03 - Rar29\r\n   04 - Arj\r\n      01 - Arj (1,2,3)\r\n      02 - Arj 4\r\n   05 - Z\r\n   06 - Lzh\r\n   07 - Reserved for 7z\r\n   08 - Cab\r\n   09 - NSIS\r\n      01 - DeflateNSIS\r\n      02 - BZip2NSIS\r\n\r\n\r\n06 - Crypto \r\n   00 - \r\n   01 - AES\r\n      0x - AES-128\r\n      4x - AES-192\r\n      8x - AES-256\r\n      Cx - AES\r\n\r\n      x0 - ECB\r\n      x1 - CBC\r\n      x2 - CFB\r\n      x3 - OFB\r\n\r\n   07 - Reserved\r\n   0F - Reserved\r\n\r\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\r\n\r\n   F1 - Misc Ciphers (Combine)\r\n      01 - Zip\r\n         01 - Main Zip crypto algo\r\n      03 - RAR\r\n         02 - \r\n         03 - Rar29 AES-128 + (modified SHA-1)\r\n      07 - 7z\r\n         01 - AES-256 + SHA-256\r\n\r\n07 - Hash (subject to change)\r\n   00 - \r\n   01 - CRC\r\n   02 - SHA-1\r\n   03 - SHA-256\r\n   04 - SHA-384\r\n   05 - SHA-512\r\n\r\n   F0 - Misc Hash\r\n\r\n   F1 - Misc\r\n      03 - RAR\r\n         03 - Rar29 Password Hashing (modified SHA1)\r\n      07 - 7z \r\n         01 - SHA-256 Password Hashing\r\n    \r\n   \r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/history.txt",
    "content": "HISTORY of the LZMA SDK\r\n-----------------------\r\n\r\n4.65           2009-02-03\r\n-------------------------\r\n- Some minor fixes\r\n\r\n\r\n4.63           2008-12-31\r\n-------------------------\r\n- Some minor fixes\r\n\r\n\r\n4.61 beta      2008-11-23\r\n-------------------------\r\n- The bug in ANSI-C LZMA Decoder was fixed:\r\n    If encoded stream was corrupted, decoder could access memory \r\n    outside of allocated range.\r\n- Some changes in ANSI-C 7z Decoder interfaces.\r\n- LZMA SDK is placed in the public domain.\r\n\r\n\r\n4.60 beta      2008-08-19\r\n-------------------------\r\n- Some minor fixes.\r\n\r\n\r\n4.59 beta      2008-08-13\r\n-------------------------\r\n- The bug was fixed:\r\n    LZMA Encoder in fast compression mode could access memory outside of \r\n    allocated range in some rare cases.\r\n\r\n\r\n4.58 beta      2008-05-05\r\n-------------------------\r\n- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r\n- ANSI-C LZMA Encoder was included to LZMA SDK.\r\n- C++ LZMA code now is just wrapper over ANSI-C code.\r\n\r\n\r\n4.57           2007-12-12\r\n-------------------------\r\n- Speed optimizations in ++ LZMA Decoder. \r\n- Small changes for more compatibility with some C/C++ compilers.\r\n\r\n\r\n4.49 beta      2007-07-05\r\n-------------------------\r\n- .7z ANSI-C Decoder:\r\n     - now it supports BCJ and BCJ2 filters\r\n     - now it supports files larger than 4 GB.\r\n     - now it supports \"Last Write Time\" field for files.\r\n- C++ code for .7z archives compressing/decompressing from 7-zip \r\n  was included to LZMA SDK.\r\n  \r\n\r\n4.43           2006-06-04\r\n-------------------------\r\n- Small changes for more compatibility with some C/C++ compilers.\r\n  \r\n\r\n4.42           2006-05-15\r\n-------------------------\r\n- Small changes in .h files in ANSI-C version.\r\n  \r\n\r\n4.39 beta      2006-04-14\r\n-------------------------\r\n- The bug in versions 4.33b:4.38b was fixed:\r\n  C++ version of LZMA encoder could not correctly compress \r\n  files larger than 2 GB with HC4 match finder (-mfhc4).\r\n  \r\n\r\n4.37 beta      2005-04-06\r\n-------------------------\r\n- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r\n\r\n\r\n4.35 beta      2005-03-02\r\n-------------------------\r\n- The bug was fixed in C++ version of LZMA Decoder:\r\n    If encoded stream was corrupted, decoder could access memory \r\n    outside of allocated range.\r\n\r\n\r\n4.34 beta      2006-02-27\r\n-------------------------\r\n- Compressing speed and memory requirements for compressing were increased\r\n- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r\n\r\n\r\n4.32           2005-12-09\r\n-------------------------\r\n- Java version of LZMA SDK was included\r\n\r\n\r\n4.30           2005-11-20\r\n-------------------------\r\n- Compression ratio was improved in -a2 mode\r\n- Speed optimizations for compressing in -a2 mode\r\n- -fb switch now supports values up to 273\r\n- The bug in 7z_C (7zIn.c) was fixed:\r\n  It used Alloc/Free functions from different memory pools.\r\n  So if program used two memory pools, it worked incorrectly.\r\n- 7z_C: .7z format supporting was improved\r\n- LZMA# SDK (C#.NET version) was included\r\n\r\n\r\n4.27 (Updated) 2005-09-21\r\n-------------------------\r\n- Some GUIDs/interfaces in C++ were changed.\r\n IStream.h:\r\n   ISequentialInStream::Read now works as old ReadPart\r\n   ISequentialOutStream::Write now works as old WritePart\r\n\r\n\r\n4.27           2005-08-07\r\n-------------------------\r\n- The bug in LzmaDecodeSize.c was fixed:\r\n   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r\n   decompressing worked incorrectly.\r\n\r\n\r\n4.26           2005-08-05\r\n-------------------------\r\n- Fixes in 7z_C code and LzmaTest.c:\r\n  previous versions could work incorrectly,\r\n  if malloc(0) returns 0\r\n\r\n\r\n4.23           2005-06-29\r\n-------------------------\r\n- Small fixes in C++ code\r\n\r\n\r\n4.22           2005-06-10\r\n-------------------------\r\n- Small fixes\r\n\r\n\r\n4.21           2005-06-08\r\n-------------------------\r\n- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r\n- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r\n    - LzmaStateDecode.h\r\n    - LzmaStateDecode.c\r\n    - LzmaStateTest.c\r\n- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r\n\r\n\r\n4.17           2005-04-18\r\n-------------------------\r\n- New example for RAM->RAM compressing/decompressing: \r\n  LZMA + BCJ (filter for x86 code):\r\n    - LzmaRam.h\r\n    - LzmaRam.cpp\r\n    - LzmaRamDecode.h\r\n    - LzmaRamDecode.c\r\n    - -f86 switch for lzma.exe\r\n\r\n\r\n4.16           2005-03-29\r\n-------------------------\r\n- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r\n   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r\n   decoder could access memory outside of allocated range.\r\n- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r\n  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r\n  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r\n- Small speed optimization in LZMA C++ code\r\n- filter for SPARC's code was added\r\n- Simplified version of .7z ANSI-C Decoder was included\r\n\r\n\r\n4.06           2004-09-05\r\n-------------------------\r\n- The bug in v4.05 was fixed:\r\n    LZMA-Encoder didn't release output stream in some cases.\r\n\r\n\r\n4.05           2004-08-25\r\n-------------------------\r\n- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r\n  and PowerPC code was included to SDK\r\n- Some internal minor changes\r\n\r\n\r\n4.04           2004-07-28\r\n-------------------------\r\n- More compatibility with some C++ compilers\r\n\r\n\r\n4.03           2004-06-18\r\n-------------------------\r\n- \"Benchmark\" command was added. It measures compressing \r\n  and decompressing speed and shows rating values. \r\n  Also it checks hardware errors.\r\n\r\n\r\n4.02           2004-06-10\r\n-------------------------\r\n- C++ LZMA Encoder/Decoder code now is more portable\r\n  and it can be compiled by GCC on Linux.\r\n\r\n\r\n4.01           2004-02-15\r\n-------------------------\r\n- Some detection of data corruption was enabled.\r\n    LzmaDecode.c / RangeDecoderReadByte\r\n    .....\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n\r\n\r\n4.00           2004-02-13\r\n-------------------------\r\n- Original version of LZMA SDK\r\n\r\n\r\n\r\nHISTORY of the LZMA\r\n-------------------\r\n  2001-2008:  Improvements to LZMA compressing/decompressing code, \r\n              keeping compatibility with original LZMA format\r\n  1996-2001:  Development of LZMA compression format\r\n\r\n  Some milestones:\r\n\r\n  2001-08-30: LZMA compression was added to 7-Zip\r\n  1999-01-02: First version of 7-Zip was released\r\n  \r\n\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/lzma465/lzma.txt",
    "content": "LZMA SDK 4.65\r\n-------------\r\n\r\nLZMA SDK provides the documentation, samples, header files, libraries, \r\nand tools you need to develop applications that use LZMA compression.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\nLZMA is an improved version of famous LZ77 compression algorithm. \r\nIt was improved in way of maximum increasing of compression ratio,\r\nkeeping high decompression speed and low memory requirements for \r\ndecompressing.\r\n\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\r\n\r\n\r\nLZMA SDK Contents\r\n-----------------\r\n\r\nLZMA SDK includes:\r\n\r\n  - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing\r\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\r\n\r\n\r\nUNIX/Linux version \r\n------------------\r\nTo compile C++ version of file->file LZMA encoding, go to directory\r\nC++/7zip/Compress/LZMA_Alone \r\nand call make to recompile it:\r\n  make -f makefile.gcc clean all\r\n\r\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\r\nTo compile with static libraries, you can use \r\nLIB = -lm -static\r\n\r\n\r\nFiles\r\n---------------------\r\nlzma.txt     - LZMA SDK description (this file)\r\n7zFormat.txt - 7z Format description\r\n7zC.txt      - 7z ANSI-C Decoder description\r\nmethods.txt  - Compression method IDs for .7z\r\nlzma.exe     - Compiled file->file LZMA encoder/decoder for Windows\r\nhistory.txt  - history of the LZMA SDK\r\n\r\n\r\nSource code structure\r\n---------------------\r\n\r\nC/  - C files\r\n        7zCrc*.*   - CRC code\r\n        Alloc.*    - Memory allocation functions\r\n        Bra*.*     - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n        LzFind.*   - Match finder for LZ (LZMA) encoders \r\n        LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding\r\n        LzHash.h   - Additional file for LZ match finder\r\n        LzmaDec.*  - LZMA decoding\r\n        LzmaEnc.*  - LZMA encoding\r\n        LzmaLib.*  - LZMA Library for DLL calling\r\n        Types.h    - Basic types for another .c files\r\n\tThreads.*  - The code for multithreading.\r\n\r\n    LzmaLib  - LZMA Library (.DLL for Windows)\r\n    \r\n    LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).\r\n\r\n    Archive - files related to archiving\r\n      7z     - 7z ANSI-C Decoder\r\n\r\nCPP/ -- CPP files\r\n\r\n  Common  - common files for C++ projects\r\n  Windows - common files for Windows related code\r\n\r\n  7zip    - files related to 7-Zip Project\r\n\r\n    Common   - common files for 7-Zip\r\n\r\n    Compress - files related to compression/decompression\r\n\r\n      Copy         - Copy coder\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n      LZMA         - LZMA compression/decompression on C++\r\n      LZMA_Alone   - file->file LZMA compression/decompression\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n\r\n    Archive - files related to archiving\r\n\r\n      Common   - common files for archive handling\r\n      7z       - 7z C++ Encoder/Decoder\r\n\r\n    Bundles    - Modules that are bundles of other modules\r\n  \r\n      Alone7z           - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2\r\n      Format7zR         - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r\n      Format7zExtractR  - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.\r\n\r\n    UI        - User Interface files\r\n         \r\n      Client7z - Test application for 7za.dll,  7zr.dll, 7zxr.dll\r\n      Common   - Common UI files\r\n      Console  - Code for console archiver\r\n\r\n\r\n\r\nCS/ - C# files\r\n  7zip\r\n    Common   - some common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      LzmaAlone    - file->file LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nJava/  - Java files\r\n  SevenZip\r\n    Compression    - files related to compression/decompression\r\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\n\r\nC/C++ source code of LZMA SDK is part of 7-Zip project.\r\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r\n\r\n  http://sourceforge.net/projects/sevenzip/\r\n\r\n\r\n\r\nLZMA features\r\n-------------\r\n  - Variable dictionary size (up to 1 GB)\r\n  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r\n  - Estimated decompressing speed: \r\n      - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64\r\n      - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC\r\n  - Small memory requirements for decompressing (16 KB + DictionarySize)\r\n  - Small code size for decompressing: 5-8 KB\r\n\r\nLZMA decoder uses only integer operations and can be \r\nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r\n\r\nSome critical operations that affect the speed of LZMA decompression:\r\n  1) 32*16 bit integer multiply\r\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\r\n  3) 32-bit shift and arithmetic operations\r\n\r\nThe speed of LZMA decompressing mostly depends from CPU speed.\r\nMemory speed has no big meaning. But if your CPU has small data cache, \r\noverall weight of memory speed will slightly increase.\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nUsing LZMA encoder/decoder executable\r\n--------------------------------------\r\n\r\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\r\n\r\n  e: encode file\r\n\r\n  d: decode file\r\n\r\n  b: Benchmark. There are two tests: compressing and decompressing \r\n     with LZMA method. Benchmark shows rating in MIPS (million \r\n     instructions per second). Rating value is calculated from \r\n     measured speed and it is normalized with Intel's Core 2 results.\r\n     Also Benchmark checks possible hardware errors (RAM \r\n     errors in most cases). Benchmark uses these settings:\r\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r\n     Also you can change the number of iterations. Example for 30 iterations:\r\n       LZMA b 30\r\n     Default number of iterations is 10.\r\n\r\n<Switches>\r\n  \r\n\r\n  -a{N}:  set compression mode 0 = fast, 1 = normal\r\n          default: 1 (normal)\r\n\r\n  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r\n          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \r\n          For decompressing file compressed by LZMA method with dictionary \r\n          size D = 2^N you need about D bytes of memory (RAM).\r\n\r\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\r\n          Usually big number gives a little bit better compression ratio \r\n          and slower compression process.\r\n\r\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\r\n          Sometimes lc=4 gives gain for big files.\r\n\r\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r\n          lp switch is intended for periodical data when period is \r\n          equal 2^N. For example, for 32-bit (4 bytes) \r\n          periodical data you can use lp=2. Often it's better to set lc0, \r\n          if you change lp switch.\r\n\r\n  -pb{N}: set number of pos bits - [0, 4], default: 2\r\n          pb switch is intended for periodical data \r\n          when period is equal 2^N.\r\n\r\n  -mf{MF_ID}: set Match Finder. Default: bt4. \r\n              Algorithms from hc* group doesn't provide good compression \r\n              ratio, but they often works pretty fast in combination with \r\n              fast mode (-a0).\r\n\r\n              Memory requirements depend from dictionary size \r\n              (parameter \"d\" in table below). \r\n\r\n               MF_ID     Memory                   Description\r\n\r\n                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r\n                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r\n                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r\n                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r\n\r\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \r\n          eos marker, since LZMA decoder knows uncompressed size \r\n          stored in .lzma file header.\r\n\r\n  -si:    Read data from stdin (it will write End Of Stream marker).\r\n  -so:    Write data to stdout\r\n\r\n\r\nExamples:\r\n\r\n1) LZMA e file.bin file.lzma -d16 -lc0 \r\n\r\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r\nand 0 literal context bits. -lc0 allows to reduce memory requirements \r\nfor decompression.\r\n\r\n\r\n2) LZMA e file.bin file.lzma -lc0 -lp2\r\n\r\ncompresses file.bin to file.lzma with settings suitable \r\nfor 32-bit periodical data (for example, ARM or MIPS code).\r\n\r\n3) LZMA d file.lzma file.bin\r\n\r\ndecompresses file.lzma to file.bin.\r\n\r\n\r\nCompression ratio hints\r\n-----------------------\r\n\r\nRecommendations\r\n---------------\r\n\r\nTo increase the compression ratio for LZMA compressing it's desirable \r\nto have aligned data (if it's possible) and also it's desirable to locate\r\ndata in such order, where code is grouped in one place and data is \r\ngrouped in other place (it's better than such mixing: code, data, code,\r\ndata, ...).\r\n\r\n\r\nFilters\r\n-------\r\nYou can increase the compression ratio for some data types, using\r\nspecial filters before compressing. For example, it's possible to \r\nincrease the compression ratio on 5-10% for code for those CPU ISAs: \r\nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r\n\r\nYou can find C source code of such filters in C/Bra*.* files\r\n\r\nYou can check the compression ratio gain of these filters with such \r\n7-Zip commands (example for ARM code):\r\nNo filter:\r\n  7z a a1.7z a.bin -m0=lzma\r\n\r\nWith filter for little-endian ARM code:\r\n  7z a a2.7z a.bin -m0=arm -m1=lzma        \r\n\r\nIt works in such manner:\r\nCompressing    = Filter_encoding + LZMA_encoding\r\nDecompressing  = LZMA_decoding + Filter_decoding\r\n\r\nCompressing and decompressing speed of such filters is very high,\r\nso it will not increase decompressing time too much.\r\nMoreover, it reduces decompression time for LZMA_decoding, \r\nsince compression ratio with filtering is higher.\r\n\r\nThese filters convert CALL (calling procedure) instructions \r\nfrom relative offsets to absolute addresses, so such data becomes more \r\ncompressible.\r\n\r\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r\n\r\n\r\nLZMA compressed file format\r\n---------------------------\r\nOffset Size Description\r\n  0     1   Special LZMA properties (lc,lp, pb in encoded form)\r\n  1     4   Dictionary size (little endian)\r\n  5     8   Uncompressed size (little endian). -1 means unknown size\r\n 13         Compressed data\r\n\r\n\r\nANSI-C LZMA Decoder\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nPlease note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.\r\nIf you want to use old interfaces you can download previous version of LZMA SDK\r\nfrom sourceforge.net site.\r\n\r\nTo use ANSI-C LZMA Decoder you need the following files:\r\n1) LzmaDec.h + LzmaDec.c + Types.h\r\nLzmaUtil/LzmaUtil.c is example application that uses these files.\r\n\r\n\r\nMemory requirements for LZMA decoding\r\n-------------------------------------\r\n\r\nStack usage of LZMA decoding function for local variables is not \r\nlarger than 200-400 bytes.\r\n\r\nLZMA Decoder uses dictionary buffer and internal state structure.\r\nInternal state structure consumes\r\n  state_size = (4 + (1.5 << (lc + lp))) KB\r\nby default (lc=3, lp=0), state_size = 16 KB.\r\n\r\n\r\nHow To decompress data\r\n----------------------\r\n\r\nLZMA Decoder (ANSI-C version) now supports 2 interfaces:\r\n1) Single-call Decompressing\r\n2) Multi-call State Decompressing (zlib-like interface)\r\n\r\nYou must use external allocator:\r\nExample:\r\nvoid *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\r\nvoid SzFree(void *p, void *address) { p = p; free(address); }\r\nISzAlloc alloc = { SzAlloc, SzFree };\r\n\r\nYou can use p = p; operator to disable compiler warnings.\r\n\r\n\r\nSingle-call Decompressing\r\n-------------------------\r\nWhen to use: RAM->RAM decompressing\r\nCompile files: LzmaDec.h + LzmaDec.c + Types.h\r\nCompile defines: no defines\r\nMemory Requirements:\r\n  - Input buffer: compressed size\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures: state_size (16 KB for default settings) \r\n\r\nInterface:\r\n  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, \r\n      ELzmaStatus *status, ISzAlloc *alloc);\r\n  In: \r\n    dest     - output data\r\n    destLen  - output data size\r\n    src      - input data\r\n    srcLen   - input data size\r\n    propData - LZMA properties  (5 bytes)\r\n    propSize - size of propData buffer (5 bytes)\r\n    finishMode - It has meaning only if the decoding reaches output limit (*destLen).\r\n\t LZMA_FINISH_ANY - Decode just destLen bytes.\r\n\t LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n                           You can use LZMA_FINISH_END, when you know that \r\n                           current output buffer covers last bytes of stream. \r\n    alloc    - Memory allocator.\r\n\r\n  Out: \r\n    destLen  - processed output size \r\n    srcLen   - processed input size \r\n\r\n  Output:\r\n    SZ_OK\r\n      status:\r\n        LZMA_STATUS_FINISHED_WITH_MARK\r\n        LZMA_STATUS_NOT_FINISHED \r\n        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n    SZ_ERROR_DATA - Data error\r\n    SZ_ERROR_MEM  - Memory allocation error\r\n    SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n\r\n  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,\r\n  and output value of destLen will be less than output buffer size limit.\r\n\r\n  You can use multiple checks to test data integrity after full decompression:\r\n    1) Check Result and \"status\" variable.\r\n    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. \r\n       You must use correct finish mode in that case. */ \r\n\r\n\r\nMulti-call State Decompressing (zlib-like interface)\r\n----------------------------------------------------\r\n\r\nWhen to use: file->file decompressing \r\nCompile files: LzmaDec.h + LzmaDec.c + Types.h\r\n\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures: state_size (16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in LZMA properties header)\r\n\r\n1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:\r\n   unsigned char header[LZMA_PROPS_SIZE + 8];\r\n   ReadFile(inFile, header, sizeof(header)\r\n\r\n2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties\r\n\r\n  CLzmaDec state;\r\n  LzmaDec_Constr(&state);\r\n  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);\r\n  if (res != SZ_OK)\r\n    return res;\r\n\r\n3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop\r\n\r\n  LzmaDec_Init(&state);\r\n  for (;;)\r\n  {\r\n    ... \r\n    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, \r\n    \tconst Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);\r\n    ...\r\n  }\r\n\r\n\r\n4) Free all allocated structures\r\n  LzmaDec_Free(&state, &g_Alloc);\r\n\r\nFor full code example, look at C/LzmaUtil/LzmaUtil.c code.\r\n\r\n\r\nHow To compress data\r\n--------------------\r\n\r\nCompile files: LzmaEnc.h + LzmaEnc.c + Types.h +\r\nLzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h\r\n\r\nMemory Requirements:\r\n  - (dictSize * 11.5 + 6 MB) + state_size\r\n\r\nLzma Encoder can use two memory allocators:\r\n1) alloc - for small arrays.\r\n2) allocBig - for big arrays.\r\n\r\nFor example, you can use Large RAM Pages (2 MB) in allocBig allocator for \r\nbetter compression speed. Note that Windows has bad implementation for \r\nLarge RAM Pages. \r\nIt's OK to use same allocator for alloc and allocBig.\r\n\r\n\r\nSingle-call Compression with callbacks\r\n--------------------------------------\r\n\r\nCheck C/LzmaUtil/LzmaUtil.c as example, \r\n\r\nWhen to use: file->file decompressing \r\n\r\n1) you must implement callback structures for interfaces:\r\nISeqInStream\r\nISeqOutStream\r\nICompressProgress\r\nISzAlloc\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) {  p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\n  CFileSeqInStream inStream;\r\n  CFileSeqOutStream outStream;\r\n\r\n  inStream.funcTable.Read = MyRead;\r\n  inStream.file = inFile;\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.file = outFile;\r\n\r\n\r\n2) Create CLzmaEncHandle object;\r\n\r\n  CLzmaEncHandle enc;\r\n\r\n  enc = LzmaEnc_Create(&g_Alloc);\r\n  if (enc == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n\r\n3) initialize CLzmaEncProps properties;\r\n\r\n  LzmaEncProps_Init(&props);\r\n\r\n  Then you can change some properties in that structure.\r\n\r\n4) Send LZMA properties to LZMA Encoder\r\n\r\n  res = LzmaEnc_SetProps(enc, &props);\r\n\r\n5) Write encoded properties to header\r\n\r\n    Byte header[LZMA_PROPS_SIZE + 8];\r\n    size_t headerSize = LZMA_PROPS_SIZE;\r\n    UInt64 fileSize;\r\n    int i;\r\n\r\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r\n    fileSize = MyGetFileLength(inFile);\r\n    for (i = 0; i < 8; i++)\r\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r\n    MyWriteFileAndCheck(outFile, header, headerSize)\r\n\r\n6) Call encoding function:\r\n      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, \r\n        NULL, &g_Alloc, &g_Alloc);\r\n\r\n7) Destroy LZMA Encoder Object\r\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r\n\r\n\r\nIf callback function return some error code, LzmaEnc_Encode also returns that code.\r\n\r\n\r\nSingle-call RAM->RAM Compression\r\n--------------------------------\r\n\r\nSingle-call RAM->RAM Compression is similar to Compression with callbacks,\r\nbut you provide pointers to buffers instead of pointers to stream callbacks:\r\n\r\nHRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, \r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error \r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.\r\n\r\n_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for \r\n                 some structures will be doubled in that case.\r\n\r\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.\r\n\r\n_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.\r\n\r\n\r\nC++ LZMA Encoder/Decoder \r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nC++ LZMA code use COM-like interfaces. So if you want to use it, \r\nyou can study basics of COM/OLE.\r\nC++ LZMA code is just wrapper over ANSI-C code.\r\n\r\n\r\nC++ Notes\r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nIf you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),\r\nyou must check that you correctly work with \"new\" operator.\r\n7-Zip can be compiled with MSVC 6.0 that doesn't throw \"exception\" from \"new\" operator.\r\nSo 7-Zip uses \"CPP\\Common\\NewHandler.cpp\" that redefines \"new\" operator:\r\noperator new(size_t size)\r\n{\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\nIf you use MSCV that throws exception for \"new\" operator, you can compile without \r\n\"NewHandler.cpp\". So standard exception will be used. Actually some code of \r\n7-Zip catches any exception in internal code and converts it to HRESULT code.\r\nSo you don't need to catch CNewException, if you call COM interfaces of 7-Zip.\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/sdk.html\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/mksquashfs",
    "content": "#!/bin/bash\n\n./mksquashfs-lzma -nolzma $@\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/sqlzma.h",
    "content": "/*\n * Copyright (C) 2006-2008 Junjiro Okajima\n * Copyright (C) 2006-2008 Tomas Matejicek, slax.org\n *\n * LICENSE follows the described one in lzma.\n */\n\n/* $Id: sqlzma.h,v 1.20 2008-03-12 16:58:34 jro Exp $ */\n\n#ifndef __sqlzma_h__\n#define __sqlzma_h__\n\n#ifndef __KERNEL__\n#include <stdlib.h>\n#include <string.h>\n#include <zlib.h>\n#ifdef _REENTRANT\n#include <pthread.h>\n#endif\n#else\n#include <linux/zlib.h>\n#endif\n#define _7ZIP_BYTE_DEFINED\n\n#define LZMA_VERSION \"4.65\"\n/*\n * detect the compression method automatically by the first byte of compressed\n * data.\n * according to rfc1950, the first byte of zlib compression must be 0x?8.\n */\n#define is_lzma(c)\t(c == 0x5d)\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#ifndef __KERNEL__\n/* for mksquashfs only */\nstruct sqlzma_opts {\n\tunsigned int\ttry_lzma;\n\tunsigned int \tdicsize;\n};\nint sqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in,\n\t      uInt avail_in, Bytef *next_out, uInt avail_out);\n#endif\n\n/* ---------------------------------------------------------------------- */\n/*\n * Three patterns for sqlzma uncompression. very dirty code.\n * - kernel space (squashfs kernel module)\n * - user space with pthread (mksquashfs)\n * - user space without pthread (unsquashfs)\n */\n\nstruct sized_buf {\n\tunsigned int\tsz;\n\tunsigned char\t*buf;\n};\n\nenum {SQUN_PROB, SQUN_RESULT, SQUN_LAST};\nstruct sqlzma_un {\n\tint\t\t\tun_lzma;\n\tstruct sized_buf\tun_a[SQUN_LAST];\n\tunsigned char           un_prob[31960]; /* unlzma 64KB - 1MB */\n\tz_stream\t\tun_stream;\n#define un_cmbuf\tun_stream.next_in\n#define un_cmlen\tun_stream.avail_in\n#define un_resbuf\tun_stream.next_out\n#define un_resroom\tun_stream.avail_out\n#define un_reslen\tun_stream.total_out\n};\n\nint sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz);\nint sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,\n\t      struct sized_buf *dst);\nvoid sqlzma_fin(struct sqlzma_un *un);\n\n/* ---------------------------------------------------------------------- */\n\n#ifdef __cplusplus\n};\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/sqmagic.h",
    "content": "/*\n * Copyright (C) 2006 Junjiro Okajima\n * Copyright (C) 2006 Tomas Matejicek, slax.org\n *\n * LICENSE must follow the one in squashfs.\n */\n\n/* $Id: sqmagic.h,v 1.2 2006-11-27 03:54:58 jro Exp $ */\n\n#ifndef __sqmagic_h__\n#define __sqmagic_h__\n\n/* see SQUASHFS_MAGIC in squashfs_fs.h */\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/ACKNOWLEDGEMENTS",
    "content": "\t\t\tACKNOWLEDGEMENTS\n\nThanks to everyone who have download squashfs.  I appreciate people\nusing it, and any feedback you have.\n\nThe following have provided useful feedback, which has guided\nsome of the extra features in squashfs.  This is a randomly ordered\n(roughly in chronological order) list, which is updated when\nI remember...\n\nAcknowledgements for Squashfs-3.3\n------------------------------------\n\nPeter Korsgaard and others sent patches updating Squashfs to changes in the\nVFS interface for 2.6.22/2.6.23/2.6.24-rc1.  Peter also sent some small patches\nfor the Squashfs kernel code.\n\nVito Di Leo sent a patch extending Mksquashfs to support regex filters.\nWhile his patched worked, it unfortunately made it easy to make Mksquashfs\nperform unpredictably with poorly choosen regex expressions.  It, however,\nencouraged myself to add support for wildcard pattern matching and regex\nfilters in a different way.\n\nAcknowledgements for Squashfs-3.2-r2\n------------------------------------\n\nJunjiro Okajima discovered a couple of SMP issues, thanks.\n\nJunjiro Okajima and Tomas Matejicek have produced some good LZMA patches\nfor Squashfs.\n\nAcknowledgements for Squashfs-3.2\n---------------------------------\n\nPeter Korsgaard sent a patch updating Squashfs to changes in the VFS interface\nin Linux 2.6.20.\n\nAcknowledgements for Squashfs-3.1\n---------------------------------\n\nKenneth Duda and Ed Swierk of Arastra Inc. identified numerous bugs with\nSquashfs, and provided patches which were the basis for some of the\nfixes.  In particular they identified the fragment rounding bug, the\nNFS bug, the initrd bug, and helped identify the 4K stack overflow bug.\n\nScott James Remnant (Ubuntu) also identified the fragment rounding bug,\nand he also provided a patch.\n\nMing Zhang identified the Lseek bug in Mksquashfs.  His tests on the\nperformance of Mksquashfs on SMP systems encouraged the rewrite of\nMksquashfs.\n\nPeter Korsgaard, Daniel Olivera and Zilvinas Valinskas noticed\nSquashfs 3.0 didn't compile on Linux-2.6.18-rc[1-4] due to changes\nin the Linux VFS interfaces, and provided patches.\n\nTomas Matejicek (SLAX) suggested the -force option on Unsquashfs, and noticed\nUnsquashfs didn't return the correct exit status.\n\nYann Le Doare reported a kernel oops and provided a Qemu image that led\nto the identification of the simultaneously accessing multiply mounted Squashfs\nfilesystems bug.\n\n\nOlder acknowledgements\n----------------------\n\nMark Robson - pointed out early on that initrds didn't work\n\nAdam Warner - pointed out that greater than 2GB filesystems didn't work.\n\nJohn Sutton - raised the problem when archiving the entire filesystem\n(/) there was no way to prevent /proc being archived.  This prompted\nexclude files.\n\nMartin Mueller (LinuxTV) - noticed that the filesystem length in the\nsuperblock doesn't match the output filesystem length.  This is due to\npadding to a 4K boundary.  This prompted the addition of the -nopad option.\nHe also reported a problem where 32K block filesystems hung when used as\ninitrds.\n\nArkadiusz Patyk (Polish Linux Distribution - PLD) reported a problem where 32K\nblock filesystems hung when used as a root filesystem mounted as a loopback\ndevice.\n\nJoe Blow emailed me that I'd forgotten to put anything in the README about\nmounting the squashfs filesystem.\n\nDavid Fox (Lindows) noticed that the exit codes returned by Mksquashfs were\nwrong.  He also noticed that a lot of time was spent in the duplicate scan\nroutine.\n\nCameron Rich complained that Squashfs did not support FIFOs or sockets.\n\nSteve Chadsey and Thomas Weissmuller noticed that files larger than the\navailable memory could not be compressed by Mksquashfs.\n\n\"Ptwahyu\" and \"Hoan\" (I have no full names and I don't like giving people's\nemail addresses), noticed that Mksquashfs 1.3 SEGV'd occasionally.  Even though\nI had already noticed this bug, it is useful to be informed by other people.\n\nDon Elwell, Murray Jensen and Cameron Rich, have all sent in patches.  Thanks,\nI have not had time to do anything about them yet...\n\nDrew Scott Daniels has been a good advocate for Squashfs.\n\nErik Andersen has made some nice suggestions, unfortunately, I have\nnot had time to implement anything.\n\nArtemiy I. Pavlov has written a useful LDP mini-howto for Squashfs\n(http://linuxdoc.artemio.net/squashfs).\n\nYves Combe reported the Apple G5 bug, when using Squashfs for\nhis PPC Knoppix-mib livecd project.\n\nJaco Greeff (mklivecd project, and maintainer of the Mandrake\nsquashfs-tools package) suggested the new mksquashfs -ef option, and the\nstandalone build for mksquashfs.\n\nMike Schaudies made a donation.\n\nArkadiusz Patyk from the Polish Linux Distribution reported that Squashfs\ndidn't work on amd64 machines. He gave me an account on a PLD amd64 machine\nwhich allowed myself to track down these bugs.\n\nMiles Roper, Peter Kjellerstedt and Willy Tarreau reported that release 2.1 did\nnot compile with gcc < 3.x.\n\nMarcel J.E. Mol reported lack of kernel memory issues when using Squashfs\non small memory embedded systems.  This prompted the addition of the embedded\nsystem kernel configuration options.\n\nEra Scarecrow noticed that Mksquashfs had not been updated to reflect that\nsmaller than 4K blocks are no longer supported.\n\nKenichi Shima reported the Kconfig file had not been updated to 2.2.\n\nAaron Ten Clay made a donation!\n\nTomas Matejicek (SLAX) made a donation!\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/CHANGES",
    "content": "\t\t\tSQUASHFS CHANGE LOG\n\n3.4\t26 AUG 2008\tPerformance improvements to Unsquashfs, Mksquashfs\n\t\t\tand the kernel code.  Plus many small bug fixes.\n\n\t1. Kernel code improvements:\n\n\t    1.1 Internal Squashfs kernel metadata and fragment cache\n\t\timplementations have been merged and optimised.  Spinlocks are\n\t\tnow used, locks are held for smaller periods and wakeups have\n\t\tbeen minimised.  Small race condition fixed where if two or\n\t\tmore processes tried to read the same cache block\n\t\tsimultaneously they would both read and decompress it.  10-20%+\n\t\tspeed improvement has been seen on tests.\n\t    1.2 NFS export code rewritten following VFS changes in\n\t\tlinux-2.6.24.\n\t    1.3 New patches for linux-2.6.25, linux-2.6.26, and linux-2.6.27.\n\t\tFixed patch for linux-2.6.24.\n\t    1.4 Fixed small buffer_head leak in squashfs_read_data when\n\t\thandling badly corrupted filesystems.\n\t    1.5 Fixed bug in get_dir_index_using_offset.\n\n\t2. Unsquashfs improvements:\n\n\t    2.1 Unsquashfs has been parallelised.  Filesystem reading, writing\n\t\tand decompression is now multi-threaded.  Up to 40% speed\n\t\timprovement seen on tests.\n\t    2.2 Unsquashfs now has a progress bar.  Use -no-progress to\n\t\tdisable it.\n\t    2.3 Fixed small bug where unistd.h wasn't being included on\n\t\tsome distributions, leading to lseek being used rather than\n\t\tlseek64 - which meant on these distributions Unsquashfs\n\t\tcouldn't unsquash filesystems larger than 4GB.\n\n       3. Mksquashfs improvements:\n\n\t    3.1 Removed some small remaining parallelisation bottlenecks.\n\t\tDepending on source filesystem, up to 10%+ speed improvement.\n\t    3.2 Progress bar improved, and moved to separate thread.\n\t    3.3 Sparse file handling bug in Mksquashfs 3.3 fixed.\n\t    3.4 Two rare appending restore bugs fixed (when ^C hit twice).\n\n\n3.3\t1 NOV 2007\tIncrease in block size, sparse file support,\n\t\t\tMksquashfs and Unsquashfs extended to use\n\t\t\tpattern matching in exclude/extract files, plus\n\t\t\tmany more improvements and bug fixes.\n\n\t1. Filesystem improvements:\n\n\t     1.1. Maximum block size has been increased to 1Mbyte, and the\n\t    \t  default block size has been increased to 128 Kbytes.\n\t\t  This improves compression.\n\n\t     1.2. Sparse files are now supported.  Sparse files are files\n\t\t  which have large areas of unallocated data commonly called\n\t\t  holes.  These files are now detected by Squashfs and stored\n\t\t  more efficiently.  This improves compression and read\n\t\t  performance for sparse files.\n\n\t2. Mksquashfs improvements:\n\n\t   2.1.  Exclude files have been extended to use wildcard pattern\n\t\t matching and regular expressions.  Support has also been\n\t\t added for non-anchored excludes, which means it is\n\t\t now possible to specify excludes which match anywhere\n\t\t in the filesystem (i.e. leaf files), rather than always\n\t\t having to specify exclude files starting from the root\n\t\t directory (anchored excludes).\n\n\t   2.2.  Recovery files are now created when appending to existing\n\t\t Squashfs filesystems.  This allows the original filesystem\n\t\t to be recovered if Mksquashfs aborts unexpectedly\n\t\t (i.e. power failure).\n\n\t3. Unsquashfs improvements:\n\n\t    3.1. Multiple extract files can now be specified on the\n\t\t command line, and the files/directories to be extracted can\n\t\t now also be given in a file.\n\n\t    3.2. Extract files have been extended to use wildcard pattern\n\t\t matching and regular expressions.\n\n\t    3.3. Filename printing has been enhanced and Unquashfs can\n\t\t now display filenames with file attributes\n\t\t ('ls -l' style output).\n\n\t    3.4. A -stat option has been added which displays the filesystem\n\t\t superblock information.\n\n\t    3.5. Unsquashfs now supports 1.x filesystems.\n\n\t4. Miscellaneous improvements/bug fixes:\n\n\t    4.1. Squashfs kernel code improved to use SetPageError in\n\t\t squashfs_readpage() if I/O error occurs.\n\n\t    4.2. Fixed Squashfs kernel code bug preventing file\n\t\t seeking beyond 2GB.\n\n\t    4.3. Mksquashfs now detects file size changes between\n\t\t first phase directory scan and second phase filesystem create.\n\t\t It also deals better with file I/O errors.\n\n\n3.2-r2\t15 JAN 2007\tKernel patch update and progress bar bug fix\n\n\t1. Kernel patches 2.6.19/2.6.20 have been updated to use\n\t   const structures and mutexes rather than older semaphores.\n\t2. Minor SMP bug fixes.\n\t3. Progress bar broken on x86-64.  Fixed.\n\n3.2\t2 JAN 2007\tNFS support, improvements to the Squashfs-tools, major\n\t\t\tbug fixes, lots of small improvements/bug fixes, and new\n\t\t\tkernel patches.\n\n\tImprovements:\n\n\t1. Squashfs filesystems can now be exported via NFS.\n\t2. Unsquashfs now supports 2.x filesystems.\n\t3. Mksquashfs now displays a progress bar.\n\t4. Squashfs kernel code has been hardened against accidently or\n\t   maliciously corrupted Squashfs filesystems.\n\n\tBug fixes:\n\n\t5. Race condition occurring on S390 in readpage() fixed.\n\t6. Odd behaviour of MIPS memcpy in read_data() routine worked-around.\n\t7. Missing cache_flush in Squashfs symlink_readpage() added.\n\t\n\n3.1-r2\t30 AUG 2006\tMksquashfs -sort bug fix\n\n\t\t\tA code optimisation after testing unfortunately\n\t\t\tbroke sorting in Mksquashfs.  This has been fixed.\n\n3.1\t19 AUG 2006\tThis release has some major improvements to\n\t\t\tthe squashfs-tools, a couple of major bug\n\t\t\tfixes, lots of small improvements/bug fixes,\n\t\t\tand new kernel patches.\n\n\t\t\t\n\t1. Mksquashfs has been rewritten to be multi-threaded.  It\n\t   has the following improvements\n\n\t   1.1. Parallel compression.  By default as many compression and\n\t\tfragment compression threads are created as there are available\n\t\tprocessors.  This significantly speeds up performance on SMP\n\t\tsystems.\n\t   1.2. File input and filesystem output is peformed in parallel on\n\t\tseparate threads to maximise I/O performance.  Even on single\n\t\tprocessor systems this speeds up performance by at least 10%.\n\t   1.3. Appending has been significantly improved, and files within the\n\t\tfilesystem being appended to are no longer scanned and\n\t\tchecksummed.  This significantly improves append time for large\n\t\tfilesystems.\n\t   1.4. File duplicate checking has been optimised, and split into two\n\t\tseparate phases.  Only files which are considered possible\n\t\tduplicates after the first phase are checksummed and cached in\n\t\tmemory.\n\t   1.5\tThe use of swap memory was found to significantly impact\n\t\tperformance. The amount of memory used to cache files is now a\n\t\tcommand line option, by default this is 512 Mbytes.\n \n\t2. Unsquashfs has the following improvements\n\n\t   2.1  Unsquashfs now allows you to specify the filename or the\n\t\tdirectory within the Squashfs filesystem that is to be\n\t\textracted, rather than always extracting the entire filesystem.\n\t   2.2  A new -force option has been added which forces Unsquashfs to\n\t\toutput to the destination directory even if files and directories\n\t\talready exist in the destination directory.  This allows you to\n\t\tupdate an already existing directory tree, or to Unsquashfs to\n\t\ta partially filled directory tree.  Without the -force option\n\t\tUnsquashfs will refuse to output.\n\n\t3.  The following major bug fixes have been made\n\n\t  3.1  \tA fragment table rounding bug has been fixed in Mksquashfs.\n\t\tPreviously if the number of fragments in the filesystem\n\t\twere a multiple of 512, Mksquashfs would generate an\n\t\tincorrect filesystem.\n\t  3.2  \tA rare SMP bug which occurred when simultaneously acccessing\n\t\tmultiply mounted Squashfs filesystems has been fixed.\n\n\t4. Miscellaneous improvements/bug fixes\n\n\t  4.1\tKernel code stack usage has been reduced.  This is to ensure\n\t\tSquashfs works with 4K stacks.\n\t  4.2   Readdir (Squashfs kernel code) has been fixed to always\n\t\treturn 0, rather than the number of directories read.  Squashfs\n\t\tshould now interact better with NFS.\n\t  4.3\tLseek bug in Mksquashfs when appending to larger than 4GB\n\t\tfilesystems fixed.\n\t  4.4\tSquashfs 2.x initrds can now been mounted.\n\t  4.5\tUnsquashfs exit status fixed.\n\t  4.6\tNew patches for linux-2.6.18 and linux-2.4.33.\n\n\t\n3.0\t15 MAR 2006\tMajor filesystem improvements\n\n\t1. Filesystems are no longer limited to 4 GB.  In\n\t   theory 2^64 or 4 exabytes is now supported.\n\t2. Files are no longer limited to 4 GB.  In theory the maximum\n\t   file size is 4 exabytes.\n\t3. Metadata (inode table and directory tables) are no longer\n\t   restricted to 16 Mbytes.\n\t4. Hardlinks are now suppported.\n\t5. Nlink counts are now supported.\n\t6. Readdir now returns '.' and '..' entries.\n\t7. Special support for files larger than 256 MB has been added to\n\t   the Squashfs kernel code for faster read access.\n\t8. Inode numbers are now stored within the inode rather than being\n\t   computed from inode location on disk (this is not so much an\n\t   improvement, but a change forced by the previously listed\n\t   improvements).\n\n2.2-r2\t8 SEPT 2005\tSecond release of 2.2, this release fixes a couple\n\t\t\tof small bugs, a couple of small documentation\n\t\t\tmistakes, and adds a patch for kernel 2.6.13. \n\n\t1. Mksquashfs now deletes the output filesystem image file if an\n\t   error occurs whilst generating the filesystem.  Previously on\n\t   error the image file was left empty or partially written.\n\t2. Updated mksquashfs so that it doesn't allow you to generate\n\t   filesystems with block sizes smaller than 4K.  Squashfs hasn't\n\t   supported block sizes less than 4K since 2.0-alpha.\n\t3. Mksquashfs now ignores missing files/directories in sort files.\n\t   This was the original behaviour before 2.2.\n\t4. Fixed small mistake in fs/Kconfig where the version was still\n\t   listed as 2.0.\n\t5. Updated ACKNOWLEDGEMENTS file.\n\n\n2.2\t3 JUL 2005\tThis release has some small improvements, bug fixes\n\t\t\tand patches for new kernels.\n\n\t1. Sort routine re-worked and debugged from release 2.1.  It now allows\n\t   you to give Mkisofs style sort files and checks for filenames that\n\t   don't match anything.  Sort priority has also been changed to\n\t   conform to Mkisofs usage, highest priority files are now placed\n\t   at the start of the filesystem (this means they will be on the\n\t   inside of a CD or DVD).\n\t2. New Configure options for embedded systems (memory constrained\n\t   systems).  See INSTALL file for further details.\n\t3. Directory index bug fixed where chars were treated as signed on\n           some architectures.  A file would not be found in the rare case\n\t   that the filename started with a chracter greater than 127.\n\t4. Bug introduced into the read_data() routine when sped up to use data\n\t   block queueing fixed.  If the second or later block resulted in an\n\t   I/O error this was not checked.\n\t5. Append bug introduced in 2.1 fixed.  The code to compute the new\n\t   compressed and uncompressed directory parts after appending was\n\t   wrong.\n\t6. Metadata block length read routine altered to not perform a\n\t   misaligned short read.  This was to fix reading on an ARM7 running\n\t   uCLinux without a misaligned read interrupt handler.\n\t7. Checkdata bug introduced in 2.1 fixed.\n\t\n\n2.1-r2  15 DEC 2004\tCode changed so it can be compiled with gcc 2.x\n\n\t1.  In some of the code added for release 2.1 I unknowingly used some\n\t    gcc extensions only supported by 3.x compilers.  I have received\n\t    a couple of reports that the 2.1 release doesn't build on 2.x and so\n\t    people are clearly still using gcc 2.x.  The code has been\n\t    rewritten to remove these extensions.\n\n2.1\t10 DEC 2004\tSignificantly improved directory handling plus numerous\n\t\t\tother smaller improvements\n\n\t1.  Fast indexed directories implemented.  These speed up directory\n\t    operations (ls, file lookup etc.) significantly for directories\n\t    larger than 8 KB.\n\t2.  All directories are now sorted in alphabetical order.  This again\n\t    speeds up directory operations, and in some cases it also results in\n\t    a small compression improvement (greater data similarity between\n\t    files with alphabetically similar names).\n\t3.  Maximum directory size increased from 512 KB to 128 MB.\n\t4.  Duplicate fragment checking and appending optimised in mksquashfs,\n\t    depending on filesystem, this is now up to 25% faster.\n\t5.  Mksquashfs help information reformatted and reorganised.\n\t6.  The Squashfs version and release date is now printed at kernel\n\t    boot-time or module insertion.  This addition will hopefully help\n\t    to reduce the growing problem where the Squashfs version supported\n\t    by a kernel is unknown and the kernel source is unavailable.\n        7.  New PERFORMANCE.README file.\n\t8.  New -2.0 mksquashfs option.\n\t9.  CHANGES file reorganised.\n\t10. README file reorganised, clarified and updated to include the 2.0\n\t    mksquashfs options.\n\t11. New patch for Linux 2.6.9.\n\t12. New patch for Linux 2.4.28.\n\n2.0r2\t29 AUG 2004\tWorkaround for kernel bug in kernels 2.6.8 and newer\n\t\t\tadded\n\n\t1. New patch for kernel 2.6.8.1.  This includes a workaround for a\n\t   kernel bug introduced in 2.6.7bk14, which is present in all later\n\t   versions of the kernel.  \n\n\t   If you're using a 2.6.8 kernel or later then you must use this\n\t   2.6.8.1 patch.  If you've experienced hangs or oopses using Squashfs\n\t   with a 2.6.8 or later kernel then you've hit this bug, and this\n\t   patch will fix it.\n\n\t   It is worth mentioning that this kernel bug potentially affects\n\t   other filesystems.  If you receive odd results with other\n\t   filesystems you may be experiencing this bug with that filesystem.\n\t   I submitted a patch but this has not yet gone into the\n\t   kernel, hopefully the bug will be fixed in later kernels. \n\n2.0\t13 JULY 2004\tA couple of new options, and some bug fixes\n\n\t1. New mksquashfs -all-root, -root-owned, -force-uid, and -force-gid\n\t   options.  These allow the uids/gids of files in the generated\n\t   filesystem to be specified, overriding the uids/gids in the\n\t   source filesystem.\n\t2. Initrds are now supported for kernels 2.6.x.\n\t3. amd64 bug fixes.  If you use an amd64, please read the README-AMD64\n\t   file.\n\t4. Check-data and gid bug fixes.  With 2.0-alpha when mounting 1.x\n\t   filesystems in certain cases file gids were corrupted.\n\t5. New patch for Linux 2.6.7.\n\n2.0-ALPHA\t21 MAY 2004\tFilesystem changes and compression improvements\n\n\t1. Squashfs 2.0 has added the concept of fragment blocks.\n           Files smaller than the file block size and optionally the\n\t   remainder of files that do not fit fully into a block (i.e. the\n\t   last 32K in a 96K file) are packed into shared fragments and\n\t   compressed together.  This achieves on average 5 - 20% better\n\t   compression than Squashfs 1.x.\n\t2. The maximum block size has been increased to 64K (in the ALPHA\n\t   version of Squashfs 2.0).\n\t3. The maximum number of UIDs has been increased to 256 (from 48 in\n\t   1.x).\n\t4. The maximum number of GIDs has been increased to 256 (from 15 in\n\t   1.x).\n\t5. Removal of sleep_on() function call in 2.6.x patch, to allow Squashfs\n\t   to work on the Fedora rc2 kernel.\n\t6. Numerous small bug fixes have been made.\n\n1.3r3\t18 JAN 2004\tThird release of 1.3, this adds a new mksquashfs option,\n\t\t\tsome bug fixes, and extra patches for new kernels\n\n\t1. New mksquashfs -ef exclude option.  This option reads the exclude\n\t   dirs/files from an exclude file, one exclude dir/file per line.  This\n\t   avoids the command line size limit when using the -e exclude option,\n\t2. When appending to existing filesystems, if mksquashfs experiences a\n\t   fatal error (e.g. out of space when adding to the destination), the\n\t   original filesystem is restored,\n\t3. Mksquashfs now builds standalone, without the kernel needing to be\n\t   patched.\n\t4. Bug fix in the kernel squashfs filesystem, where the pages being\n\t   filled were not kmapped.  This seems to only have caused problems\n\t   on an Apple G5,\n\t5. New patch for Linux 2.4.24,\n\n\t6. New patch for Linux 2.6.1, this replaces the patch for 2.6.0-test7.\n\n1.3r2\t14 OCT 2003\tSecond release of 1.3, bug fixes and extra patches for\n\t\t        new kernels\n\n\t1. Bug fix in routine that adds files to the filesystem being\n\t   generated in mksquashfs.  This bug was introduced in 1.3\n\t   (not enough testing...) when I rewrote it to handle files larger\n\t   than available memory.  This bug caused a SEGV, so if you've ever\n\t   got that, it is now fixed,\n\t2. Long running bug where ls -s and du reported wrong block size\n\t   fixed.  I'm pretty sure this used to work many kernel versions ago\n\t   (2.4.7) but it broke somewhere along the line since then,\n\t3. New patch for Linux 2.4.22,\n\t4. New patch for 2.6.0-test7, this replaces the patch for 2.6.0-test1.\n\n1.3\t29 JUL 2003\tFIFO/Socket support added plus optimisations and\n\t\t        improvements\n\n\t1. FIFOs and Socket inodes are now supported,\n\t2. Mksquashfs can now compress files larger than available\n\t   memory,\n\t3. File duplicate check routine optimised,\n\t4. Exit codes fixed in Mksquashfs,\n\t5. Patch for Linux 2.4.21,\n\t6. Patch for Linux 2.6.0-test1.  Hopefully, this will work for\n\t   the next few releases of 2.6.0-testx, otherwise, I'll be\n\t   releasing a lot of updates to the 2.6.0 patch...\n\n1.2\t13 MAR 2003\tAppend feature and new mksquashfs options added\n\n\tMksquashfs can now add to existing squashfs filesystems.  Three extra\n\toptions \"-noappend\", \"-keep-as-directory\", and \"root-becomes\"\n\thave been added.\n\n\tThe append option with file duplicate detection, means squashfs can be\n\tused as a simple versioning archiving filesystem. A squashfs\n\tfilesystem can be created with for example the linux-2.4.19 source.\n\tAppending the linux-2.4.20 source will create a filesystem with the\n\ttwo source trees, but only the changed files will take extra room,\n\tthe unchanged files will be detected as duplicates.\n\n\tSee the README file for usage changes.\n\n1.1b\t16 JAN 2003\tBug fix release\n\n\tFixed readpage deadlock bug.  This was a rare deadlock bug that\n\thappened when pushing pages into the page cache when using greater\n\tthan 4K blocks.  I never got this bug when I tested the filesystem,\n\tbut two people emailed me on the same day about the problem!\n\tI fixed it by using a page cache function that wasn't there when\n\tI originally did the work, which was nice :-)\n\n1.1\t8 JAN 2003\tAdded features\n\n\t1. Kernel squashfs can now mount different byte order filesystems.\n\t2. Additional features added to mksquashfs.  Mksquashfs now supports\n\t   exclude files and multiple source files/directories can be\n\t   specified.  A nopad option has also been added, which\n\t   informs mksquashfs not to pad filesystems to a multiple of 4K.\n\t   See README for mksquashfs usage changes.\n\t3. Greater than 2GB filesystems bug fix.  Filesystems greater than 2GB\n\t   can now be created.\n\n1.0c \t14 NOV 2002\tBug fix release\n\n\tFixed bugs with initrds and device nodes\n\n1.0 \t23 OCT 2002\tInitial release\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/COPYING",
    "content": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n\t\t    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n\t    How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) 19yy  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) 19yy name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/INSTALL",
    "content": "\t\t\tINSTALLING SQUASHFS\n\nThe squashfs3.4.tar.gz file contains the kernel-patches directory containing\nthe squashfs patches, and the squashfs-tools directory containing mksquashfs\nand unsquashfs.\n\n1. Patching the kernel\n----------------------\n\nThere are twelve kernel patch directories depending on your linux kernel\nversion.  If your kernel version isn't there then try the patch for the nearest\nkernel.\n\nTo patch your kernel, cd into the top level directory, and run the \"patch\"\ncommand, e.g. assuming linux-2.6.22\n\n%cd /usr/src/linux-2.6.22\n%patch -p1 < location-of-squashfs/kernel-patches/linux-2.6.22/squashfs3.4-patch\n\nWhere \"location-of-squashfs\" is the path to the squashfs3.4 source directory.\n\nThe squashfs patches patch the relevant kernel files to add configure support,\ninitrd support, include files, and the squashfs directory under linux/fs/.\nOnce patched, the kernel must be reconfigured, with squashfs support turned on\n(either Y/M) to ensure that inflate support is built into the kernel.  The\nsquashfs kernel option can be found in the miscellaneous filesystems submenu\nnear the bottom of the filesystems submenu.\n\nThere are a set of options which are intended for use by embedded systems with\nlow memory.  At the \"Additional option for memory-constrained systems\" prompt,\nplease say NO unless you're using an embedded system!  Saying Y here allows you\nto specify cache sizes.\n\nThe \"Number of fragments cached\" prompt allows the number of fragments cached\nto be controlled.  By default SquashFS caches the last 3 fragments read from\nthe filesystem.  Increasing this amount may mean SquashFS has to re-read\nfragments less often from disk, at the expense of extra system memory.\nDecreasing this amount will mean SquashFS uses less memory at the expense of\nextra reads from disk.  Note there must be at least one cached fragment.\nAnything much more than three will probably not make much difference.\n\n2. Building squashfs tools\n--------------------------\n\nThe squashfs-tools directory contains the mksquashfs and unsquashfs programs.\nThese can be made by typing make.  The source files use a local copy of\nsquashfs_fs.h (included in the kernel patches) allowing the tools to be made\nwithout needing to patch the kernel.\n\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/OLD-READMEs/README-2.0",
    "content": "NOTE:  This the original README for version 2.0.  It is retained as it\ncontains information about the fragment design.  A description of the new 2.0\nmksquashfs options has been added to the main README file, and that\nfile should now be consulted for these.\n\n\tSQUASHFS 2.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2004 Phillip Lougher (plougher@users.sourceforge.net)\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to the final release of Squashfs version 2.0!  A lot of changes to the\nfilesystem have been made under the bonnet (hood).  Squashfs 2.0 uses fragment\nblocks and larger blocks (64K) to improve compression ratio by about 5 - 20%\nover Squashfs 1.0 depending on the files being compressed.  Using fragment\nblocks allows Squashfs 2.0 to achieve better compression than cloop and similar\ncompression to tgz files while retaining the I/O efficiency of a compressed\nfilesystem.\n\nDetailed changes:\n\n1. Squashfs 2.0 has added the concept of fragment blocks (see later discussion).\n   Files smaller than the file block size (64K in Squashfs 2.0) and optionally\n   the remainder of files that do not fit fully into a block (i.e. the last 32K\n   in a 96K file) are packed into shared fragments and compressed together.\n   This achieves on average 5 - 20% better compression than Squashfs 1.x.\n\n2. The maximum block size has been increased to 64K.\n\n3. The maximum number of UIDs has been increased to 256 (from 48 in 1.x).\n\n4. The maximum number of GIDs has been increased to 256 (from 15 in 1.x).\n\n5. New mksquashfs -all-root, -root-owned, -force-uid, and -force-gid\n   options.  These allow the uids/gids of files in the generated\n   filesystem to be specified, overriding the uids/gids in the\n   source filesystem.\n\n6. Initrds are now supported for kernels 2.6.x.\n\n7. Removal of sleep_on() function call in 2.6.x patch, to allow Squashfs\n   to work on the Fedora rc2 kernel.\n\n8. AMD64, check-data and gid bug fixes.\n\n9. Numerous small bug fixes have been made.\n\n10. New patch for Linux 2.6.7.\n\n\nNew Squashfs 2.0 options\n------------------------\n\n-noF or -noFragmentCompression\n\n\tDo not compress the fragments.  Added for compatibility with noI and\n\tnoD, probably not that useful.\n\n-no-fragments\n\n\tDo not use fragment blocks, and rather generate a filesystem\n\tsimilar to a Squashfs 1.x filesystem.  It will of course still\n\tbe a Squashfs 2.0 filesystem but without fragments, and so\n\tit won't be mountable on a Squashfs 1.x system.\n\n-always-use-fragments\n\n\tBy default only small files less than the block size are packed into\n\tfragment blocks.  The ends of files which do not fit fully into a block,\n\tare NOT by default packed into fragments.  To illustrate this, a\n\t100K file has an initial 64K block and a 36K remainder.  This\n\t36K remainder is not packed into a fragment by default.  This is\n\tbecause to do so leads to a 10 - 20% drop in sequential I/O\n\tperformance, as a disk head seek is needed to seek to the initial\n\tfile data and another disk seek is need to seek to the fragment\n\tblock.\n\n\tSpecify this option if you want file remainders to be packed into\n\tfragment blocks.  Doing so may increase the compression obtained\n\tBUT at the expense of I/O speed.\n\n-no-duplicates\n\n\tDo not detect duplicate files.\n\n-all-root\n-root-owned\n\n\tThese options (both do exactly the same thing), force all file\n\tuids/gids in the generated Squashfs filesystem to be root.\n\tThis allows root owned filesystems to be built without root access\n\ton the host machine.\n\n-force-uid uid\n\n\tThis option forces all files in the generated Squashfs filesystem to\n\tbe owned by the specified uid.  The uid can be specified either by\n\tname (i.e. \"root\") or by number.\n\n-force-gid gid\n\n\tThis option forces all files in the generated Squashfs filesystem to\n\tbe group owned by the specified gid.  The gid can be specified either by\n\tname (i.e. \"root\") or by number.\n\n\nCompression improvements example\n--------------------------------\n\nThe following is the compression results obtained compressing the 2.6.6\nlinux kernel source using CRAMFS, Cloop (with iso filesystem), Squashfs 1.3 and\nSquashfs 2.0 (results generated using big-endian filesystems).\n\nIn decreasing order of size:\n\n\tCRAMFS\t\t62791680 bytes (59.9M)\n\tSquashfs 1.x\t51351552 bytes (48.9M)\n\tCloop\t\t46118681 bytes (44.0M)\n\tSquashfs 2.0\t45604854 bytes (43.5M)\n\n\nThe Squashfs 1.x filesystem is 12.6% larger than the new 2.0 filesystem.\nThe cloop filesystem is 1.1% larger than the Squashfs 2.0 filesystem.\n\n\nFragment blocks in Squashfs 2.0\n-------------------------------\n\nSquashfs like all other compressed filesystems compresses files individually\non a block by block basis.  This is performed to allow mounting and\nde-compression of files on a block by block basis without requiring the entire\nfilesystem to be decompressed.  This is in contrast to data-based compression\nschemes which compress without understanding the underlying filesystem (i.e.\ncloop and tgz files) and which, therefore, do not compress files individually.\nEach approach has advantages and disadvantages, data-based systems have better\ncompression because compression is always performed at the maximum block size\n(64K in cloop) irrespective of the size of each file (which could be less than\nthe block size).  Compressed filesystems tend to be faster at I/O because\nthey understand the filesystem and therefore employ better caching stategies\nand read less un-needed data from the filesystem.\n\nFragment blocks in Squashfs 2.0 solves this problem by packing files (and\noptionally the ends of files) which are smaller than the block size into\nshared blocks, which are compressed together.  For example five files each of\n10K will be packed into one shared fragment of 50K and compressed together,\nrather than being compressed in five 10K blocks.\n\nThis scheme produces a hybrid filesystem, retaining the I/O efficiency\nof a compressed filesystem, while obtaining the compression efficiency\nof data-based schemes by compressing small files together.\n\n\nSquashfs 1.x and Squashfs 2.0 compatibility\n-------------------------------------------\n\nAppending to Squashfs 1.x filesystems is not supported.  If you wish to append\nto 1.x filesystems, then either use the original mksquashfs, or convert them\nto Squashfs 2.0 by mounting the filesystem and running the 2.0 mksquashfs\non the mounted filesystem.\n\nMounting Squashfs 1.x filesystems IS supported by the 2.0 kernel patch.\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/OLD-READMEs/README-2.1",
    "content": "\tSQUASHFS 2.1 - A squashed read-only filesystem for Linux\n\n\tCopyright 2004 Phillip Lougher (plougher@users.sourceforge.net)\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 2.1-r2.  Squashfs 2.1 introduces indexed\ndirectories which considerably speed up directory lookup (ls, find etc.) for\ndirectories which are greater than 8K in size.  All directories are now also\nsorted alphabetically which further speeds up directory lookup.  Many smaller\nimprovements have also been made to this release, please see the CHANGES file\nentry for detailed changes.\n\n1. DIRECTORY SPEED IMPROVEMENT EXAMPLES\n---------------------------------------\n\nTo give an indication of the directory speed improvements a number of test\nresults are shown here.  There is in addition a new PERFORMANCE.README file\nwhich gives details of I/O and lookup performance for Squashfs 2.1 against\nthe Zisofs, Cloop and CRAMFS filesystems.\n\nexample 1:\n\nFilesystems generated from a single directory of 72,784 files (2.6 MB\ndirectory size).  Each file is 10 bytes in size (the test is directory\nlookup and so the file size isn't an issue).  The ext3 uncompressed\ndirectory size is 288 MB (presumably because of one file per block).\n\nZisofs compressed size        153.50 MB\nCloop (isofs) compressed size 1.74 MB\nSquashfs2.1 compressed size   612 KB (0.60 MB)\n\nTime taken to perform \"ls -lR --color=always | cat > /dev/null\" on\nfilesystems mounted on hard disk.\n\nZisofs       35 minutes 7.895 seconds (User 7.868 secs, Sys 34 mins 5.621 secs)\nCloop        35 minutes 12.765 seconds (User 7.771 secs, Sys 34 mins 3.869 secs)\nSquashfs2.1  19 seconds (User 5.119 secs, Sys 14.547 secs)\n\nexample 2:\n\nFilesystems were generated from the Ubuntu Warty livecd (original uncompressed\nsize on ext3 is 1.4 GB).\n\nZisofs compressed size        589.81 MB\nCloop (isofs) compressed size 471.19 MB\nSquashfs2.0 compressed size   448.58 MB\nSquashfs2.1 compressed size   448.58 MB\n\nTime taken to perform \"ls -lR --color=always | cat > /dev/null\" on\nfilesystems mounted on hard disk.\n\nZisofs        49.875 seconds (User time 2.589 secs, Sys 11.194 secs)\nCloop         20.797 seconds (User time 2.706 secs, Sys 13.496 secs)\nSquashfs2.0   16.556 seconds (User time 2.424 secs, Sys 10.371 secs)\nSquashfs2.1   10.143 seconds (User time 2.475 secs, Sys 4.440 secs)\n\n\nNOTE: the usual warnings apply to these results, they are provided for\nillustrative purposes only, and due to different hardware and/or file data, you\nmay obtain different results.  As such the results are provided \"as is\" without\nany warranty (either express or implied) and you assume all risks as to their\nquality and accuracy.\n\n2. NEW MKSQUASHFS OPTIONS\n-------------------------\n\nThere is only one extra option \"-2.0\".  This tells mksquashfs to generate\na filesystem which is mountable with Squashfs version 2.0.\n\n3. APPENDING AND MOUNTING SQUASHFS 2.0 FILESYSTEMS\n--------------------------------------------------\n\nMounting 2.0 filesystems is supported by Squashfs 2.1.  In addition\nmksquashfs v2.1 can append to 2.0 filesystems, although the generated\nfilesystem will still be a 2.0 filesystem.\n\n4. DONATIONS\n------------\n\nIf you find Squashfs useful then please consider making a donation,\nparticularly if you use Squashfs in a commercial product.  Please consider\ngiving something back especially if you're making money from it.\n\nOff the Squashfs subject somewhat I'm currently looking for another\njob doing Linux kernel or filesystems work.  If you know of any such\nwork that can be performed from the UK then please get in touch.  Thanks.\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/OLD-READMEs/README-3.0",
    "content": "\tSQUASHFS 3.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2006 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to the first release of Squashfs version 3.0.  Squashfs 3.0 has the\nthe following improvements to 2.x.\n\n\t1. Filesystems are no longer limited to 4 GB.  In\n\t   theory 2^64 or 4 exabytes is now supported.\n\n\t2. Files are no longer limited to 4 GB.  In theory the maximum\n\t   file size is 4 exabytes.\n\n\t3. Metadata (inode table and directory tables) are no longer\n\t   restricted to 16 Mbytes.\n\n\t4. Hardlinks are now suppported.\n\n\t5. Nlink counts are now supported.\n\n\t6. Readdir now returns '.' and '..' entries.\n\n\t7. Special support for files larger than 256 MB has been added to\n\t   the Squashfs kernel code for faster read access.\n\n\t8. Inode numbers are now stored within the inode rather than being\n\t   computed from inode location on disk (this is not so much an\n\t   improvement, but a change forced by the previously listed\n\t   improvements).\n\nThere is a new Unsquashfs utility (in squashfs-tools) than can be used to\ndecompress a filesystem without mounting it.\n\nSquashfs 3.0 supports 2.x filesystems.  Support for 1.x filesystems\nwill be added in the future.\n\n1. UNSQUASHFS\n-------------\n\nUnsquashfs has the following options:\n\nSYNTAX: unsquashfs [-ls | -dest] filesystem\n\t-version\t\tprint version, licence and copyright information\n\t-info\t\t\tprint files as they are unsquashed\n\t-ls\t\t\tlist filesystem only\n\t-dest <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\nThe \"-ls\" option can be used to list the contents of a filesystem without\ndecompressing the filesystem data itself.\n\nThe \"-info\" option forces Unsquashfs to print each file as it is decompressed.\n\nThe \"-dest\" option specifies the directory that is used to decompress\nthe filesystem data.  If this option is not given then the filesystem is\ndecompressed to the directory \"squashfs-root\" in the current working directory.\n\nUnsquashfs can decompress 3.0 filesystems.  Support for 2.x and 1.x\nfilesystems will be added in the future.\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/OLD-READMEs/README-3.1",
    "content": "\tSQUASHFS 3.1 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2006 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.1-r2.  Squashfs 3.1 has major improvements to\nthe Squashfs tools (Mksquashfs and Unsquashfs), some major bug fixes, new\nkernel patches, and various other smaller improvements and bug fixes.\nPlease see the CHANGES file for a detailed list.\n\n1. MKSQUASHFS\n-------------\n\nMksquashfs has been rewritten and it is now multi-threaded.  It offers\nthe following improvements:\n\n1. Parallel compression.  By default as many compression and fragment\ncompression threads are created as there are available processors.\nThis significantly speeds up performance on SMP systems.\n\n2. File input and filesystem output is peformed in parallel on separate\nthreads to maximise I/O performance.  Even on single processor systems\nthis speeds up performance by at least 10%.\n\n3. Appending has been significantly improved, and files within the\nfilesystem being appended to are no longer scanned and checksummed.  This\nsignificantly improves append time for large filesystems.\n\n4. File duplicate checking has been optimised, and split into two separate\nphases.  Only files which are considered possible duplicates after the\nfirst phase are checksummed and cached in memory.\n\n5. The use of swap memory was found to significantly impact performance. The\namount of memory used to cache the file is now a command line option, by default\nthis is 512 Mbytes.\n\n1.1 NEW COMMAND LINE OPTIONS\n----------------------------\n\nThe new Mksquashfs program has a couple of extra command line options\nwhich can be used to control the new features:\n\n-processors <processors>\n\nThis specifies the number of processors used by Mksquashfs.\nBy default this is the number of available processors.\n\n-read_queue <size in Mbytes>\n\nThis specifies the size of the file input queue used by the reader thread.\nThis defaults to 64 Mbytes.\n\n-write_queue <size in Mbytes>\n\nThis specifies the size of the filesystem output queue used by the\nwriter thread.  It also specifies the maximum cache used in file\nduplicate detection (the output queue is shared between these tasks).\nThis defaults to 512 Mbytes.\n\n1.2 PERFORMANCE RESULTS\n-----------------------\n\nThe following results give an indication of the speed improvements.  Two\nexample filesystems were tested, a liveCD filesystem (about 1.8 Gbytes\nuncompressed), and my home directory consisting largely of text files\n(about 1.3 Gbytes uncompressed).  Tests were run on a single core\nand a dual core system.\n\nDual Core (AMDx2 3800+) system:\nSource directories on ext3.\n\nLiveCD, old mksquashfs:\n\nreal    11m48.401s\nuser    9m27.056s\nsys     0m15.281s\n\nLiveCD, new par_mksquashfs:\n\nreal    4m8.736s\nuser    7m11.771s\nsys     0m27.749s\n\n\"Home\", old mksquashfs:\n\nreal    4m34.360s\nuser    3m54.007s\nsys     0m32.155s\n\n\"Home\", new par_mksquashfs:\n\nreal    1m27.381s\nuser    2m7.304s\nsys     0m17.234s\n\nSingle Core PowerBook (PowerPC G4 1.5 GHz Ubuntu Linux)\nSource directories on ext3.\n\nLiveCD, old mksquashs:\n\nreal    11m38.472s\nuser    9m6.137s\nsys     0m23.799s\n\nLiveCD,  par_mksquashfs:\n\nreal    10m5.572s\nuser    8m59.921s\nsys     0m16.145s\n\n\"Home\", old mksquashfs:\n\nreal    3m42.298s\nuser    2m49.478s\nsys     0m13.675s\n\n\"Home\", new par_mksquashfs:\n\nreal    3m9.178s\nuser    2m50.699s\nsys     0m9.069s\n\nI'll be interested in any performance results obtained, especially from SMP\nmachines larger than my dual-core AMD box, as this will give an indication of\nthe scalability of the code.  Obviously, I'm also interested in any problems,\ndeadlocks, low performance etc.\n\n2. UNSQUASHFS\n-------------\n\nUnsquashfs now allows you to specify the filename or directory that is to be\nextracted from the Squashfs filesystem, rather than always extracting the\nentire filesystem.  It also has a new \"-force\" option, and all options can be\nspecified in a short form (-i rather than -info).\n\nThe Unsquashfs usage info is now:\n\nSYNTAX: ./unsquashfs [options] filesystem [directory or file to extract]\n\t-v[ersion]\t\tprint version, licence and copyright information\n\t-i[nfo]\t\t\tprint files as they are unsquashed\n\t-l[s]\t\t\tlist filesystem only\n\t-d[est] <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\t-f[orce]\t\tif file already exists then overwrite\n\nTo extract a subset of the filesystem, the filename or directory\ntree that is to be extracted can now be specified on the command line.  The\nfile/directory should be specified using the full path to the file/directory\nas it appears within the Squashfs filesystem.  The file/directory will also be\nextracted to that position within the specified destination directory.\n\nThe new \"-force\" option forces Unsquashfs to output to the destination\ndirectory even if files or directories already exist.  This allows you\nto update an existing directory tree, or to Unsquashfs to a partially\nfilled directory.  Without the \"-force\" option, Unsquashfs will\nrefuse to overwrite any existing files, or to create any directories if they\nalready exist.  This is done to protect data in case of mistakes, and\nso the \"-force\" option should be used with caution.\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/OLD-READMEs/README-3.2",
    "content": "\tSQUASHFS 3.2 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.2.  Squashfs 3.2 has support for NFS exporting,\nsome improvements to the Squashfs tools (Mksquashfs and Unsquashfs), some\nmajor bug fixes, new kernel patches, and various other smaller improvements\nand bug fixes.  Please see the CHANGES file for a detailed list.\n\n1. MKSQUASHFS\n-------------\n\nNew command line options:\n\n-no-exports\n\n\tSquashfs now supports NFS exports.  By default the additional\n\tinformation necessary is added to the filesystem by Mksquashfs.  If you\n\tdo not wish this extra information, then this option can be specified.\n\tThis will save a couple of bytes per file, and the filesystem\n\twill be identical to Squashfs 3.1.\n\n-no-progress\n\n\tMksquashfs by default now displays a progress bar. This option disables\n\tit.\n\n2. UNSQUASHFS\n-------------\n\n\tUnsquashfs now supports Squashfs 2.x filesystems.\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/OLD-READMEs/README-3.3",
    "content": "\tSQUASHFS 3.3 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to another release of Squashfs.  This is the 22nd release in just\nover five years of work.  Squashfs 3.3 has lots of nice improvements,\nboth to the filesystem itself (bigger blocks, and sparse files), but\nalso to the Squashfs-tools Mksquashfs and Unsquashfs.  As usual the\nCHANGES file has a detailed list of all the improvements.\n\nFollowing is a description of the changes to  the Squashfs tools, usage\nguides to the new options, and a summary of the new options.\n\n1. MKSQUASHFS - EXTENDED EXCLUDE FILE HANDLING\n----------------------------------------------\n\n1. Extended wildcard pattern matching now supported in exclude files\n\n  Enabled by specifying -wildcards option\n\n  Supports both anchored and non-anchored exclude files.\n\n1.1 Anchored excludes\n\n  Similar to existing exclude files except with wildcards.  Exclude\n  file matches from root of source directories.\n\n  Examples:\n\n  1. mksquashfs example image.sqsh -wildcards -e 'test/*.gz'\n\n     Exclude all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. mksquashfs example image.sqsh -wildcards -e '*/[Tt]est/example*'\n\n     Exclude all files beginning with \"example\" inside directories called\n     \"Test\" or \"test\", that occur inside any top level directory.\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -wildcards -e 'test/!(*data*).gz'\n\n     Exclude all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\n1.2 Non-anchored excludes\n\n  By default excludes match from the top level directory, but it is\n  often useful to exclude a file matching anywhere in the source directories.\n  For this non-anchored excludes can be used, specified by pre-fixing the\n  exclude with \"...\".\n\n  Examples:\n\n  1. mksquashfs example image.sqsh -wildcards -e '... *.gz'\n\n     Exclude files matching \"*.gz\" anywhere in the source directories.\n     For example this will match \"example.gz\", \"test/example.gz\", and\n     \"test/test/example.gz\".\n\n  2. mksquashfs example image.sqsh -wildcards -e '... [Tt]est/*.gz'\n\n     Exclude files matching \"*.gz\" inside directories called \"Test\" or\n     \"test\" that occur anywhere in the source directories.\n\n  Again, using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -wildcards -e '... !(*data*).gz'\n\n     Exclude all files matching \"*.gz\" anywhere in the source directories,\n     except those with \"data\" in the name.\n\n2. Regular expression pattern matching now supported in exclude files\n\n  Enabled by specifying -regex option.  Identical behaviour to wild\ncard pattern matching, except patterns are considered to be regular\nexpressions.\n\n  Supports both anchored and non-anchored exclude files.\n\n\n2. MKSQUASHFS - NEW RECOVERY FILE FEATURE\n-----------------------------------------\n\nRecovery files are now created when appending to existing Squashfs\nfilesystems.  This allows the original filesystem to be recovered\nif Mksquashfs aborts unexpectedly (i.e. power failure).\n\nThe recovery files are called squashfs_recovery_xxx_yyy, where\n\"xxx\" is the name of the filesystem being appended to, and \"yyy\" is a\nnumber to guarantee filename uniqueness (the PID of the parent Mksquashfs\nprocess).\n\nNormally if Mksquashfs exits correctly the recovery file is deleted to\navoid cluttering the filesystem.  If Mksquashfs aborts, the \"-recover\"\noption can be used to recover the filesystem, giving the previously\ncreated recovery file as a parameter, i.e.\n\nmksquashfs dummy image.sqsh -recover squashfs_recovery_image.sqsh_1234\n\nThe writing of the recovery file can be disabled by specifying the\n\"-no-recovery\" option.\n\n\n3. UNSQUASHFS - EXTENDED EXTRACT FILE HANDLING\n----------------------------------------------\n\n1. Multiple extract files can now be specified on the command line, and the\nfiles/directories to be extracted can now also be given in a file.\n\nTo specify a file containing the extract files use the \"-e[f]\" option.\n\n2. Extended wildcard pattern matching now supported in extract files\n\n  Enabled by default.  Similar to existing extract files except with\nwildcards.\n\n  Examples:\n\n  1. unsquashfs image.sqsh 'test/*.gz'\n\n     Extract all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. unsquashfs image.sqsh '[Tt]est/example*'\n\n     Extract all files beginning with \"example\" inside top level directories\n     called \"Test\" or \"test\".\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. unsquashfs image.sqsh 'test/!(*data*).gz'\n\n     Extract all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\n3. Regular expression pattern matching now supported in extract files\n\n  Enabled by specifying -r[egex] option.  Identical behaviour to wild\ncard pattern matching, except patterns are considered to be regular\nexpressions.\n\n4. UNSQUASHFS - EXTENDED FILENAME PRINTING\n------------------------------------------\n\nFilename printing has been enhanced and Unquashfs can now display filenames\nwith file attributes ('ls -l' style output).\n\nNew options:\n\n  -ll[s]\n\n   list filesystem with file attributes, but don't unsquash\n\n  -li[nfo]\n\n   print files as they are unsquashed with file attributes\n\n\n5. UNSQUASHFS - MISCELLANEOUS OPTIONS\n-------------------------------------\n\n   -s[tat]\n\n   Display the filesystem superblock information.  This is useful to\n   discover the filesystem version, byte ordering, whether it has an\n   NFS export table, and what options were used to compress\n   the filesystem.\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/OLD-READMEs/README-AMD64",
    "content": "Information for amd64 users\n---------------------------\n\nAll releases of Squashfs prior to 2.0 generate incorrect\nfilesystems on amd64 machines.  Filesystems created on amd64 machines work\ncorrectly on amd64 machines, but cannot be mounted on non-amd64 machines.\nLikewise, filesystems created on non-amd64 machines cannot be mounted on amd64\nmachines.  This bug is caused by the different size of the \"time_t\" definition\nused in SquashFS filesystem structures.\n\nThis bug is fixed in releases 2.0 and newer.  However, all amd64 filesystems\ngenerated by previous releases will not be mountable on amd64 machines\nwith newer releases.  If you have amd64 filesystems generated with mksquashfs\nversion 2.0-alpha or older, it is important that you recreate the filesystem.\nThis can be performed by mounting the filesystem using a kernel with the\noriginal patch (i.e. a 2.0-alpha or older patch) and running the NEW (i.e. this\nrelease) mksquashfs tool to create a new SquashFS filesystem.\n\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/PERFORMANCE.README",
    "content": "GENERAL INFORMATION ON PERFORMANCE TESTS\n----------------------------------------\n\nThe following performance tests were based on two file sets: the\nliveCD filesystem from the Ubuntu liveCD (Warty release), and the\nliveCD filesystem from the Damn Small Linux liveCD (release 0.8.4).\nThe Ubuntu liveCD filesystem was used to test filesystem performance\nfrom CDROM and hard disk for Zisofs, Cloop, Squashfs 2.0 and Squashfs2.1.\nCRAMFS filesystem performance could not be tested for this filesystem\nbacause it exceeds the maximum supported size of CRAMFS.  To test\nCRAMFS performance against Squashfs, the liveCD filesystem from\nDamn Small Linux was used.\n\nNOTE: the usual warnings apply to these results, they are provided for\nillustrative purposes only, and due to different hardware and/or file data, you\nmay obtain different results.  As such the results are provided \"as is\" without\nany warranty (either express or implied) and you assume all risks as to their\nquality and accuracy.\n\n1. Ubuntu liveCD performance tests\n\n   ext3 uncompressed size      1.4 GB\n   Zisofs compressed size      589.81 MB\n   Cloop compressed size       471.89 MB\n   Squashfs2.0 compressed size 448.58 MB\n   Squashfs2.1 compressed size 448.58 MB\n\n1.1 Performance tests from CDROM\n\n1.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  Zisofs       49.88 seconds (User 2.60 secs, Sys 11.19 secs)\n  Cloop        20.80 seconds (User 2.71 secs, Sys 13.50 secs)\n  Squashfs2.0  16.56 seconds (User 2.42 secs, Sys 10.37 secs)\n  Squashfs2.1  10.14 seconds (User 2.48 secs, Sys 4.44 secs)\n\n1.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  Zisofs       27 minutes 28.54 seconds (User 3.00 secs, Sys 1 min 4.80 secs)\n  Cloop        5 minutes 55.72 seconds (User 2.90 secs, Sys 3 min 37.90 secs)\n  Squashfs2.0  5 minutes 20.87 seconds (User 2.33 secs, Sys 56.98 secs)\n  Squashfs2.1  5 minutes 15.46 seconds (user 2.28 secs, Sys 51.12 secs)\n\n1.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n  Zisofs       101 minutes 29.65 seconds (User 5.33 secs, Sys  1 min 17.20 secs)\n  Cloop        35 minutes 27.51 seconds (user 5.93 secs, Sys 4 mins 30.23 secs)\n  Squashfs2.0  21 minutes 53.05 seconds (user 5.71 secs, Sys 2 mins 36.59 secs)\n  Squashfs2.1  21 minutes 46.99 seconds (User 5.80 secs, Sys 2 mins 31.88 secs)\n\n\n1.2 Performance tests from Hard disk\n\n1.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk \n\n  Zisofs       17.29 seconds (User 2.62 secs, Sys 11.08 secs)\n  Cloop        16.46 seconds (User 2.63 secs, Sys 13.41 secs)\n  Squashfs2.0  13.75 seconds (User 2.44 secs, Sys 11.00 secs)\n  Squashfs2.1  6.94 seconds (User 2.44 secs, Sys 4.48 secs)\n\n1.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk\n\n  Zisofs       1 minute 21.47 seconds (User 2.73 secs, Sys 54.44 secs)\n  Cloop        1 minute 34.06 seconds (user 2.85 secs, Sys 1 min 12.13 secs)\n  Squashfs2.0  1 minute 21.22 seconds (User 2.42 secs, Sys 56.21 secs)\n  Squashfs2.1  1 minute 15.46 seconds (User 2.36 secs, Sys 49.78 secs)\n\n1.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk\n\n  Zisofs       11 minutes 13.64 seconds (User 5.08 secs, Sys 52.62 secs)\n  Cloop        5 minutes 37.93 seconds (user 6 secs, Sys 2 mins 22.38 secs)\n  Squashfs2.0  5 minutes 7.11 seconds (user 5.63 secs, Sys 2 mins 35.23 secs)\n  Squashfs2.1  5 minutes 1.87 seconds (User 5.71 secs, Sys 2 mins 29.98 secs)\n\n\n2. Damn Small Linux liveCD performance tests\n\n   ext3 uncompressed size      126 MB\n   CRAMFS compressed size      52.19 MB\n   Squashfs2.0 compressed size 46.52 MB\n   Squashfs2.1 compressed size 46.52 MB\n\n2.1 Performance tests from CDROM\n\n2.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  CRAMFS       10.85 seconds (User 0.39 secs, Sys 0.98 secs)\n  Squashfs2.0  2.97 seconds (User 0.36 secs, Sys 2.15 secs)\n  Squashfs2.1  2.43 seconds (User 0.40 secs, Sys 1.42 secs)\n\n2.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  CRAMFS       55.38 seconds (User 0.34 secs, Sys 6.98 secs)\n  Squashfs2.0  35.99 seconds (User 0.30 secs, Sys 6.35 secs)\n  Squashfs2.1  33.83 seconds (User 0.26 secs, Sys 5.56 secs)\n\n2.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n\n  CRAMFS        3 minutes 1.68 seconds (User 0.54 secs, Sys 9.51 secs)\n  Squashfs2.0   1 minute 39.45 seconds (User 0.57 secs, Sys 13.14 secs)\n  Squashfs2.1   1 minute 38.41 seconds (User 0.58 secs, Sys 13.08 secs)\n\n2.2 Performance tests from Hard disk\n\n2.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk\n\n  CRAMFS       1.77 seconds (User 0.53 secs, Sys 1.21 secs)\n  Squashfs2.0  2.67 seconds (User 0.41 secs, Sys 2.25 secs)\n  Squashfs2.1  1.87 seconds (User 0.41 secs, Sys 1.46 secs)\n\n2.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk \n\n  CRAMFS       6.80 seconds (User 0.36 secs, Sys 6.02 secs)\n  Squashfs2.0  7.23 seconds (User 0.29 secs, Sys 6.62 secs)\n  Squashfs2.1  6.53 seconds (User 0.31 secs, Sys 5.82 secs)\n\n2.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk \n\n\n  CRAMFS       28.55 seconds (User 0.49 secs, Sys 6.49 secs)\n  Squashfs2.0  25.44 seconds (User 0.58 secs, Sys 13.17 secs)\n  Squashfs2.1  24.72 seconds (User 0.56 secs, Sys 13.15 secs)\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/README",
    "content": "\tSQUASHFS 3.4 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2008 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.4.  Please read the CHANGES file for details of\nchanges.\n\nSquashfs is a highly compressed read-only filesystem for Linux.\nIt uses zlib compression to compress both files, inodes and directories.\nInodes in the system are very small and all blocks are packed to minimise\ndata overhead. Block sizes greater than 4K are supported up to a maximum\nof 1Mbytes (default block size 128K).\n\nSquashfs is intended for general read-only filesystem use, for archival\nuse (i.e. in cases where a .tar.gz file may be used), and in constrained\nblock device/memory systems (e.g. embedded systems) where low overhead is\nneeded.\n\n1. SQUASHFS OVERVIEW\n--------------------\n\n1. Data, inodes and directories are compressed.\n\n2. Squashfs stores full uid/gids (32 bits), and file creation time.\n\n3. In theory files up to 2^64 bytes are supported.  In theory filesystems can\n   be up to 2^64 bytes.\n\n4. Inode and directory data are highly compacted, and packed on byte\n   boundaries.  Each compressed inode is on average 8 bytes in length\n   (the exact length varies on file type, i.e. regular file, directory,\n   symbolic link, and block/char device inodes have different sizes).\n\n5. Squashfs can use block sizes up to 1Mbyte (the default size is 128K).\n   Using 128K blocks achieves greater compression ratios than the normal\n   4K block size.\n\n6. File duplicates are detected and removed.\n\n7. Both big and little endian architectures are supported.  Squashfs can\n   mount filesystems created on different byte order machines.\n\n\n2. USING SQUASHFS\n-----------------\n\nSquashfs filesystems should be mounted with 'mount' with the filesystem type\n'squashfs'.  If the filesystem is on a block device, the filesystem can be\nmounted directly, e.g.\n\n%mount -t squashfs /dev/sda1 /mnt\n\nWill mount the squashfs filesystem on \"/dev/sda1\" under the directory \"/mnt\".\n\nIf the squashfs filesystem has been written to a file, the loopback device\ncan be used to mount it (loopback support must be in the kernel), e.g.\n\n%mount -t squashfs image /mnt -o loop\n\nWill mount the squashfs filesystem in the file \"image\" under\nthe directory \"/mnt\".\n\n\n3. MKSQUASHFS\n-------------\n\n3.1 Mksquashfs options and overview.\n------------------------------------\n\nAs squashfs is a read-only filesystem, the mksquashfs program must be used to\ncreate populated squashfs filesystems.\n\nSYNTAX:mksquashfs source1 source2 ...  dest [options] [-e list of exclude\ndirs/files]\n\nOptions are\n-version\t\tprint version, licence and copyright message\n-recover <name>\t\trecover filesystem data using recovery file <name>\n-no-recovery\t\tdon't generate a recovery file\n-info\t\t\tprint files written to filesystem\n-no-exports\t\tdon't make the filesystem exportable via NFS\n-no-progress\t\tdon't display the progress bar\n-no-sparse\t\tdon't detect sparse files\n-b <block_size>\t\tset data block to <block_size>.  Default 131072 bytes\n-processors <number>\tUse <number> processors.  By default will use number of\n\t\t\tprocessors available\n-read-queue <size>\tSet input queue to <size> Mbytes.  Default 64 Mbytes\n-write-queue <size>\tSet output queue to <size> Mbytes.  Default 512 Mbytes\n-fragment-queue <size>\tSet fagment queue to <size> Mbytes.  Default 64 Mbytes\n-noI\t\t\tdo not compress inode table\n-noD\t\t\tdo not compress data blocks\n-noF\t\t\tdo not compress fragment blocks\n-no-fragments\t\tdo not use fragments\n-always-use-fragments\tuse fragment blocks for files larger than block size\n-no-duplicates\t\tdo not perform duplicate checking\n-noappend\t\tdo not append to existing filesystem\n-keep-as-directory\tif one source directory is specified, create a root\n\t\t\tdirectory containing that directory, rather than the\n\t\t\tcontents of the directory\n-root-becomes <name>\twhen appending source files/directories, make the\n\t\t\toriginal root become a subdirectory in the new root\n\t\t\tcalled <name>, rather than adding the new source items\n\t\t\tto the original root\n-all-root\t\tmake all files owned by root\n-force-uid uid\t\tset all file uids to uid\n-force-gid gid\t\tset all file gids to gid\n-le\t\t\tcreate a little endian filesystem\n-be\t\t\tcreate a big endian filesystem\n-nopad\t\t\tdo not pad filesystem to a multiple of 4K\n-check_data\t\tadd checkdata for greater filesystem checks\n-root-owned\t\talternative name for -all-root\n-noInodeCompression\talternative name for -noI\n-noDataCompression\talternative name for -noD\n-noFragmentCompression\talternative name for -noF\n-sort <sort_file>\tsort files according to priorities in <sort_file>.  One\n\t\t\tfile or dir with priority per line.  Priority -32768 to\n\t\t\t32767, default priority 0\n-ef <exclude_file>\tlist of exclude dirs/files.  One per line\n-wildcards\t\tAllow extended shell wildcards (globbing) to be used in\n\t\t\texclude dirs/files\n-regex\t\t\tAllow POSIX regular expressions to be used in exclude\n\t\t\tdirs/files\n\nSource1 source2 ... are the source directories/files containing the\nfiles/directories that will form the squashfs filesystem.  If a single\ndirectory is specified (i.e. mksquashfs source output_fs) the squashfs\nfilesystem will consist of that directory, with the top-level root\ndirectory corresponding to the source directory.\n\nIf multiple source directories or files are specified, mksquashfs will merge\nthe specified sources into a single filesystem, with the root directory\ncontaining each of the source files/directories.  The name of each directory\nentry will be the basename of the source path.   If more than one source\nentry maps to the same name, the conflicts are named xxx_1, xxx_2, etc. where\nxxx is the original name.\n\nTo make this clear, take two example directories.  Source directory\n\"/home/phillip/test\" contains  \"file1\", \"file2\" and \"dir1\".\nSource directory \"goodies\" contains \"goodies1\", \"goodies2\" and \"goodies3\".\n\nusage example 1:\n\n%mksquashfs /home/phillip/test output_fs\n\nThis will generate a squashfs filesystem with root entries\n\"file1\", \"file2\" and \"dir1\".\n\nexample 2:\n\n%mksquashfs /home/phillip/test goodies output_fs\n\nThis will create a squashfs filesystem with the root containing\nentries \"test\" and \"goodies\" corresponding to the source\ndirectories \"/home/phillip/test\" and \"goodies\".\n\nexample 3:\n\n%mksquashfs /home/phillip/test goodies test output_fs\n\nThis is the same as the previous example, except a third\nsource directory \"test\" has been specified.  This conflicts\nwith the first directory named \"test\" and will be renamed \"test_1\".\n\nMultiple sources allow filesystems to be generated without needing to\ncopy all source files into a common directory.  This simplifies creating\nfilesystems.\n\nThe -keep-as-directory option can be used when only one source directory\nis specified, and you wish the root to contain that directory, rather than\nthe contents of the directory.  For example:\n\nexample 4:\n\n%mksquashfs /home/phillip/test output_fs -keep-as-directory\n\nThis is the same as example 1, except for -keep-as-directory.\nThis will generate a root directory containing directory \"test\",\nrather than the \"test\" directory contents \"file1\", \"file2\" and \"dir1\".\n\nThe Dest argument is the destination where the squashfs filesystem will be\nwritten.  This can either be a conventional file or a block device.  If the file\ndoesn't exist it will be created, if it does exist and a squashfs\nfilesystem exists on it, mksquashfs will append.  The -noappend option will\nwrite a new filesystem irrespective of whether an existing filesystem is\npresent.\n\n3.2 Changing compression defaults used in mksquashfs\n----------------------------------------------------\n\nThere are a large number of options that can be used to control the \ncompression in mksquashfs.  By and large the defaults are the most\noptimum settings and should only be changed in exceptional circumstances!\n\nThe -noI, -noD and -noF options (also -noInodeCompression, -noDataCompression\nand -noFragmentCompression) can be used to force mksquashfs to not compress\ninodes/directories, data and fragments respectively.  Giving all options\ngenerates an uncompressed filesystem.\n\nThe -no-fragments tells mksquashfs to not generate fragment blocks, and rather\ngenerate a filesystem similar to a Squashfs 1.x filesystem.  It will of course\nstill be a Squashfs 3.1 filesystem but without fragments, and so it won't be\nmountable on a Squashfs 1.x system.\n\nThe -always-use-fragments option tells mksquashfs to always generate\nfragments for files irrespective of the file length.  By default only small\nfiles less than the block size are packed into fragment blocks.  The ends of\nfiles which do not fit fully into a block, are NOT by default packed into\nfragments.  To illustrate this, a 100K file has an initial 64K block and a 36K\nremainder.  This 36K remainder is not packed into a fragment by default.  This\nis because to do so leads to a 10 - 20% drop in sequential I/O performance, as a\ndisk head seek is needed to seek to the initial file data and another disk seek\nis need to seek to the fragment block.  Specify this option if you want file\nremainders to be packed into fragment blocks.  Doing so may increase the\ncompression obtained BUT at the expense of I/O speed.\n\nThe -no-duplicates option tells mksquashfs to not check the files being\nadded to the filesystem for duplicates.  This can result in quicker filesystem\ngeneration and appending although obviously compression will suffer badly if\nthere is a lot of duplicate files.\n\nThe -b option allows the block size to be selected, both \"K\" and \"M\" postfixes\nare supported, this can be either 4K, 8K, 16K, 32K, 64K, 128K, 256K, 512K or\n1M bytes.\n\n3.3 Specifying the UIDs/GIDs used in the filesystem\n---------------------------------------------------\n\nBy default files in the generated filesystem inherit the UID and GID ownership\nof the original file.  However,  mksquashfs provides a number of options which\ncan be used to override the ownership.\n\nThe options -all-root and -root-owned (both do exactly the same thing) force all\nfile uids/gids in the generated Squashfs filesystem to be root.  This allows\nroot owned filesystems to be built without root access on the host machine.\n\nThe \"-force-uid uid\"  option forces all files in the generated Squashfs\nfilesystem to be owned by the specified uid.  The uid can be specified either by\nname (i.e. \"root\") or by number.\n\nThe \"-force-gid gid\" option forces all files in the generated Squashfs\nfilesystem to be group owned by the specified gid.  The gid can be specified\neither by name (i.e. \"root\") or by number.\n\n3.4 Excluding files from the filesystem\n---------------------------------------\n\nThe -e and -ef options allow files/directories to be specified which are\nexcluded from the output filesystem.  The -e option takes the exclude\nfiles/directories from the command line, the -ef option takes the\nexlude files/directories from the specified exclude file, one file/directory\nper line.\n\nTwo styles of exclude file matching are supported: basic exclude matching, and\nextended wildcard matching.  Basic exclude matching is a legacy feature\nretained for backwards compatibility with earlier versions of Mksquashfs.\nExtended wildcard matching should be used in preference.\n\n3.4.1 Basic exclude matching\n\nEach exclude file is treated as an exact match of a file/directory in\nthe source directories.  If an exclude file/directory is absolute (i.e.\nprefixed with /, ../, or ./) the entry is treated as absolute, however, if an\nexclude file/directory is relative, it is treated as being relative to each of\nthe sources in turn, i.e.\n\n%mksquashfs /tmp/source1 source2  output_fs -e ex1 /tmp/source1/ex2 out/ex3\n\nWill generate exclude files /tmp/source1/ex2, /tmp/source1/ex1, source2/ex1,\n/tmp/source1/out/ex3 and source2/out/ex3.\n\n3.4.2 Extended exclude file handling\n\nExtended exclude file matching treats each exclude file as a wildcard or\nregex expression.  To enable wildcard matching specify the -wildcards\noption, and to enable regex matching specify the -regex option.  In most\ncases the -wildcards option should be used rather than -regex because wildcard\nmatching behaviour is significantly easier to understand!\n\nIn addition to wildcards/regex expressions, exclude files can be \"anchored\" or\n\"non-anchored\".  An anchored exclude is one which matches from the root of the\ndirectory and nowhere else, a non-anchored exclude matches anywhere.  For\nexample given the directory hierarchy \"a/b/c/a/b\", the anchored exclude\n\"a/b\" will match \"a/b\" at the root of the directory hierarchy, but\nit will not match the \"/a/b\" sub-directory within directory \"c\", whereas a\nnon-anchored exclude would.\n\nA couple of examples should make this clearer.\n \nAnchored excludes\n\n  1. mksquashfs example image.sqsh -wildcards -e 'test/*.gz'\n\n     Exclude all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. mksquashfs example image.sqsh -wildcards -e '*/[Tt]est/example*'\n\n     Exclude all files beginning with \"example\" inside directories called\n     \"Test\" or \"test\", that occur inside any top level directory.\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -wildcards -e 'test/!(*data*).gz'\n\n     Exclude all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\nNon-anchored excludes\n\n  By default excludes match from the top level directory, but it is\n  often useful to exclude a file matching anywhere in the source directories.\n  For this non-anchored excludes can be used, specified by pre-fixing the\n  exclude with \"...\".\n\n  Examples:\n\n  1. mksquashfs example image.sqsh -wildcards -e '... *.gz'\n\n     Exclude files matching \"*.gz\" anywhere in the source directories.\n     For example this will match \"example.gz\", \"test/example.gz\", and\n     \"test/test/example.gz\".\n\n  2. mksquashfs example image.sqsh -wildcards -e '... [Tt]est/*.gz'\n\n     Exclude files matching \"*.gz\" inside directories called \"Test\" or\n     \"test\" that occur anywhere in the source directories.\n\n  Again, using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -wildcards -e '... !(*data*).gz'\n\n     Exclude all files matching \"*.gz\" anywhere in the source directories,\n     except those with \"data\" in the name.\n\n3.4.3 Exclude files summary\n\nThe -e and -ef exclude options are usefully used in archiving the entire\nfilesystem, where it is wished to avoid archiving /proc, and the filesystem\nbeing generated, i.e.\n\n%mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh\n\nMultiple -ef options can be specified on the command line, and the -ef\noption can be used in conjuction with the -e option.\n\n3.5 Appending to squashfs filesystems\n-------------------------------------\n\nRunning squashfs with the destination directory containing an existing\nfilesystem will add the source items to the existing filesystem.  By default,\nthe source items are added to the existing root directory.\n\nTo make this clear... An existing filesystem \"image\" contains root entries\n\"old1\", and \"old2\".  Source directory \"/home/phillip/test\" contains  \"file1\",\n\"file2\" and \"dir1\".\n\nexample 1:\n\n%mksquashfs /home/phillip/test image\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", \"file1\", \"file2\" and\n\"dir1\"\n\nexample 2:\n\n%mksquashfs /home/phillip/test image -keep-as-directory\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", and \"test\".\nAs shown in the previous section, for single source directories\n'-keep-as-directory' adds the source directory rather than the\ncontents of the directory.\n\nexample 3:\n\n%mksquashfs /home/phillip/test image -keep-as-directory -root-becomes\noriginal-root\n\nWill create a new \"image\" with root entries \"original-root\", and \"test\".  The\n'-root-becomes' option specifies that the original root becomes a subdirectory\nin the new root, with the specified name.\n\nThe append option with file duplicate detection, means squashfs can be\nused as a simple versioning archiving filesystem. A squashfs filesystem can\nbe created with for example the linux-2.4.19 source.  Appending the linux-2.4.20\nsource will create a filesystem with the two source trees, but only the\nchanged files will take extra room, the unchanged files will be detected as\nduplicates.\n\n3.6 Appending recovery file feature\n-----------------------------------\n\nRecovery files are created when appending to existing Squashfs\nfilesystems.  This allows the original filesystem to be recovered\nif Mksquashfs aborts unexpectedly (i.e. power failure).\n\nThe recovery files are called squashfs_recovery_xxx_yyy, where\n\"xxx\" is the name of the filesystem being appended to, and \"yyy\" is a\nnumber to guarantee filename uniqueness (the PID of the parent Mksquashfs\nprocess).\n\nNormally if Mksquashfs exits correctly the recovery file is deleted to\navoid cluttering the filesystem.  If Mksquashfs aborts, the \"-recover\"\noption can be used to recover the filesystem, giving the previously\ncreated recovery file as a parameter, i.e.\n\nmksquashfs dummy image.sqsh -recover squashfs_recovery_image.sqsh_1234\n\nThe writing of the recovery file can be disabled by specifying the\n\"-no-recovery\" option.\n\n3.7 Miscellaneous options\n-------------------------\n\nThe -info option displays the files/directories as they are compressed and\nadded to the filesystem.  The original uncompressed size of each file\nis printed, along with DUPLICATE if the file is a duplicate of a\nfile in the filesystem.\n\nThe -le and -be options can be used to force mksquashfs to generate a little\nendian or big endian filesystem.  Normally mksquashfs will generate a\nfilesystem in the host byte order.  Squashfs, for portability, will\nmount different ordered filesystems (i.e. it can mount big endian filesystems\nrunning on a little endian machine), but these options can be used for\ngreater optimisation.\n\nThe -nopad option informs mksquashfs to not pad the filesystem to a 4K multiple.\nThis is performed by default to enable the output filesystem file to be mounted\nby loopback, which requires files to be a 4K multiple.  If the filesystem is\nbeing written to a block device, or is to be stored in a bootimage, the extra\npad bytes are not needed.\n\n4. UNSQUASHFS\n-------------\n\nUnsquashfs allows you to decompress and extract a Squashfs filesystem without\nmounting it.  It can extract the entire filesystem, or a specific\nfile or directory.\n\nThe Unsquashfs usage info is:\n\nSYNTAX: unsquashfs [options] filesystem [directories or files to extract]\n\t-v[ersion]\t\tprint version, licence and copyright information\n\t-d[est] <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\t-n[o-progress]\t\tdon't display the progress bar\n\t-p[rocessors] <number>\tuse <number> processors.  By default will use\n\t\t\t\tnumber of processors available\n\t-i[nfo]\t\t\tprint files as they are unsquashed\n\t-li[nfo]\t\tprint files as they are unsquashed with file\n\t\t\t\tattributes (like ls -l output)\n\t-l[s]\t\t\tlist filesystem, but don't unsquash\n\t-ll[s]\t\t\tlist filesystem with file attributes (like\n\t\t\t\tls -l output), but don't unsquash\n\t-f[orce]\t\tif file already exists then overwrite\n\t-s[tat]\t\t\tdisplay filesystem superblock information\n\t-e[f] <extract file>\tlist of directories or files to extract.\n\t\t\t\tOne per line\n\t-da[ta-queue] <size>\tSet data queue to <size> Mbytes.  Default 256\n\t\t\t\tMbytes\n\t-fr[ag-queue] <size>\tSet fagment queue to <size> Mbytes.  Default 256\n\t\t\t\tMbytes\n\t-r[egex]\t\ttreat extract names as POSIX regular expressions\n\t\t\t\trather than use the default shell wildcard\n\t\t\t\texpansion (globbing)\n\nTo extract a subset of the filesystem, the filenames or directory\ntrees that are to be extracted can be specified on the command line.  The\nfiles/directories should be specified using the full path to the\nfiles/directories as they appear within the Squashfs filesystem.  The\nfiles/directories will also be extracted to those positions within the specified\ndestination directory.\n\nThe extract files can also be given in a file using the \"-e[f]\" option.\n\nSimilarly to Mksquashfs, wildcard matching is performed on the extract\nfiles.  Wildcard matching is enabled by default.\n\nExamples:\n\n  1. unsquashfs image.sqsh 'test/*.gz'\n\n     Extract all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. unsquashfs image.sqsh '[Tt]est/example*'\n\n     Extract all files beginning with \"example\" inside top level directories\n     called \"Test\" or \"test\".\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. unsquashfs image.sqsh 'test/!(*data*).gz'\n\n     Extract all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\n\n4.1 Unsquashfs options\n----------------------\n\nThe \"-ls\" option can be used to list the contents of a filesystem without\ndecompressing the filesystem data itself.  The \"-lls\" option is similar\nbut it also displays file attributes (ls -l style output).\n\nThe \"-info\" option forces Unsquashfs to print each file as it is decompressed.\nThe -\"linfo\" is similar but it also displays file attributes.\n\nThe \"-dest\" option specifies the directory that is used to decompress\nthe filesystem data.  If this option is not given then the filesystem is\ndecompressed to the directory \"squashfs-root\" in the current working directory.\n\nThe \"-force\" option forces Unsquashfs to output to the destination\ndirectory even if files or directories already exist.  This allows you\nto update an existing directory tree, or to Unsquashfs to a partially\nfilled directory.  Without the \"-force\" option, Unsquashfs will\nrefuse to overwrite any existing files, or to create any directories if they\nalready exist.  This is done to protect data in case of mistakes, and\nso the \"-force\" option should be used with caution.\n\nThe \"-stat\" option displays filesystem superblock information.  This is\nuseful to discover the filesystem version, byte ordering, whether it has a NFS\nexport table, and what options were used to compress the filesystem, etc.\n\nUnsquashfs can decompress all Squashfs filesystem versions, 1.x, 2.x and 3.x\nfilesystems.\n\n5. FILESYSTEM LAYOUT\n--------------------\n\nBrief filesystem design notes follow for the original 1.x filesystem\nlayout.  A description of the 2.x and 3.x filesystem layouts will be written\nsometime!\n\nA squashfs filesystem consists of five parts, packed together on a byte\nalignment:\n\n\t ---------------\n\t|  superblock \t|\n\t|---------------|\n\t|     data\t|\n\t|    blocks\t|\n\t|---------------|\n\t|    inodes\t|\n\t|---------------|\n\t|   directories\t|\n\t|---------------|\n\t|    uid/gid\t|\n\t|  lookup table\t|\n\t ---------------\n\nCompressed data blocks are written to the filesystem as files are read from\nthe source directory, and checked for duplicates.  Once all file data has been\nwritten the completed inode, directory and uid/gid lookup tables are written.\n\n5.1 Metadata\n------------\n\nMetadata (inodes and directories) are compressed in 8Kbyte blocks.  Each\ncompressed block is prefixed by a two byte length, the top bit is set if the\nblock is uncompressed.  A block will be uncompressed if the -noI option is set,\nor if the compressed block was larger than the uncompressed block.\n\nInodes are packed into the metadata blocks, and are not aligned to block\nboundaries, therefore inodes overlap compressed blocks.  An inode is\nidentified by a two field tuple <start address of compressed block : offset\ninto de-compressed block>.\n\nInode contents vary depending on the file type.  The base inode consists of:\n\n\tbase inode:\n\t\tInode type\n\t\tMode\n\t\tuid index\n\t\tgid index\n\nThe inode type is 4 bits in size, and the mode is 12 bits.\n\nThe uid and gid indexes are 4 bits in length.  Ordinarily, this will allow 16\nunique indexes into the uid table.  To minimise overhead, the uid index is\nused in conjunction with the spare bit in the file type to form a 48 entry\nindex as follows:\n\n\tinode type 1 - 5: uid index = uid\n\tinode type 5 -10: uid index = 16 + uid\n\tinode type 11 - 15: uid index = 32 + uid\n\nIn this way 48 unique uids are supported using 4 bits, minimising data inode\noverhead.  The 4 bit gid index is used to index into a 15 entry gid table.\nGid index 15 is used to indicate that the gid is the same as the uid.\nThis prevents the 15 entry gid table filling up with the common case where\nthe uid/gid is the same.\n\nThe data contents of symbolic links are stored immediately after the symbolic\nlink inode, inside the inode table.  This allows the normally small symbolic\nlink to be compressed as part of the inode table, achieving much greater\ncompression than if the symbolic link was compressed individually.\n\nSimilarly, the block index for regular files is stored immediately after the\nregular file inode.  The block index is a list of block lengths (two bytes\neach), rather than block addresses, saving two bytes per block.  The block\naddress for a given block is computed by the summation of the previous\nblock lengths.  This takes advantage of the fact that the blocks making up a\nfile are stored contiguously in the filesystem.  The top bit of each block\nlength is set if the block is uncompressed, either because the -noD option is\nset, or if the compressed block was larger than the uncompressed block.\n\n5.2 Directories\n---------------\n\nLike inodes, directories are packed into the metadata blocks, and are not\naligned on block boundaries, therefore directories can overlap compressed\nblocks.  A directory is, again, identified by a two field tuple\n<start address of compressed block containing directory start : offset\ninto de-compressed block>.\n\nDirectories are organised in a slightly complex way, and are not simply\na list of file names and inode tuples.  The organisation takes advantage of the\nobservation that in most cases, the inodes of the files in the directory\nwill be in the same compressed metadata block, and therefore, the\ninode tuples will have the same start block.\n\nDirectories are therefore organised in a two level list, a directory\nheader containing the shared start block value, and a sequence of\ndirectory entries, each of which share the shared start block.  A\nnew directory header is written once/if the inode start block\nchanges.  The directory header/directory entry list is repeated as many times\nas necessary.  The organisation is as follows:\n\n\tdirectory_header:\n\t\tcount (8 bits)\n\t\tinode start block (24 bits)\n\t\t\n\t\tdirectory entry: * count\n\t\t\tinode offset (13 bits)\n\t\t\tinode type (3 bits)\n\t\t\tfilename size (8 bits)\n\t\t\tfilename\n\t\t\t\nThis organisation saves on average 3 bytes per filename.\n\n5.3 File data\n-------------\n\nFile data is compressed on a block by block basis and written to the\nfilesystem.  The filesystem supports up to 32K blocks, which achieves\ngreater compression ratios than the Linux 4K page size.\n\nThe disadvantage with using greater than 4K blocks (and the reason why\nmost filesystems do not), is that the VFS reads data in 4K pages.\nThe filesystem reads and decompresses a larger block containing that page\n(e.g. 32K).  However, only 4K can be returned to the VFS, resulting in a\nvery inefficient filesystem, as 28K must be thrown away.   Squashfs,\nsolves this problem by explicitly pushing the extra pages into the page\ncache.\n\n\n6. AUTHOR INFO\n--------------\n\nSquashfs was written by Phillip Lougher, email phillip@lougher.demon.co.uk,\nin Chepstow, Wales, UK.   If you like the program, or have any problems,\nthen please email me, as it's nice to get feedback!\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/README",
    "content": "Readme for Linux-2.6.27 users.\n\nThe VFS interface in the rc candidates has not stabilised sufficiently to\nproduce one patch that is guaranteed to work once Linux-2.6.27 is released.\nLinux-2.6.27-rc4 has some minor VFS changes, but there are further up and\ncoming changes in the linux-next tree (linux-2.6.27-rc4-next) that probably\nwill make it into the final Linux 2.6.27 release.\n\nIf you're using Linux-2.6.27-rc4 use the linux-2.6.27-rc4 patch.  If you're\nusing a later rc candidate or the final release, first try the\nlinux-2.6.27-rc4-next patch.\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.12/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.12/fs/Kconfig linux-2.6.12-squashfs3.4/fs/Kconfig\n--- linux-2.6.12/fs/Kconfig\t2005-06-17 20:48:29.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/fs/Kconfig\t2008-08-19 05:12:27.000000000 +0100\n@@ -1171,6 +1171,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.12/fs/Makefile linux-2.6.12-squashfs3.4/fs/Makefile\n--- linux-2.6.12/fs/Makefile\t2005-06-17 20:48:29.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/fs/Makefile\t2008-08-18 02:48:54.000000000 +0100\n@@ -52,6 +52,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.12/fs/squashfs/inode.c linux-2.6.12-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.12/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:23:00.000000000 +0100\n@@ -0,0 +1,2170 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct super_block *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static struct super_block *squashfs_get_sb(struct file_system_type *,int, const char *, void *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static void *kzalloc(int size, int flags)\n+{\n+\tvoid *buff = kmalloc(size, flags);\n+\n+\tif(buff != NULL)\n+\t\tmemset(buff, 0, size);\n+\n+\treturn buff;\n+}\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tdown(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tup(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tup(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tinit_MUTEX(&msblk->read_data_mutex);\n+\tinit_MUTEX(&msblk->read_page_mutex);\n+\tinit_MUTEX(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tup(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tup(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tdown(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tup(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tup(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.12/fs/squashfs/Makefile linux-2.6.12-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.12/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/fs/squashfs/Makefile\t2008-08-18 02:48:54.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.12/fs/squashfs/squashfs2_0.c linux-2.6.12-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.12/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-19 04:57:36.000000000 +0100\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.12/fs/squashfs/squashfs.h linux-2.6.12-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.12/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-19 04:57:36.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern struct address_space_operations squashfs_symlink_aops;\n+extern struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.12/include/linux/squashfs_fs.h linux-2.6.12-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.12/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-19 04:57:36.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.12/include/linux/squashfs_fs_i.h linux-2.6.12-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.12/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-19 04:57:36.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.12/include/linux/squashfs_fs_sb.h linux-2.6.12-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.12/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-19 04:57:36.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct semaphore\t\tread_data_mutex;\n+\tstruct semaphore\t\tread_page_mutex;\n+\tstruct semaphore\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.12/init/do_mounts_rd.c linux-2.6.12-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.12/init/do_mounts_rd.c\t2005-06-17 20:48:29.000000000 +0100\n+++ linux-2.6.12-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 02:48:54.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.14/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.14/fs/Kconfig linux-2.6.14-squashfs3.4/fs/Kconfig\n--- linux-2.6.14/fs/Kconfig\t2005-10-28 01:02:08.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/fs/Kconfig\t2008-08-19 05:12:43.000000000 +0100\n@@ -1137,6 +1137,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.14/fs/Makefile linux-2.6.14-squashfs3.4/fs/Makefile\n--- linux-2.6.14/fs/Makefile\t2005-10-28 01:02:08.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/fs/Makefile\t2008-08-18 02:48:54.000000000 +0100\n@@ -55,6 +55,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.14/fs/squashfs/inode.c linux-2.6.14-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.14/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:23:14.000000000 +0100\n@@ -0,0 +1,2159 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct super_block *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static struct super_block *squashfs_get_sb(struct file_system_type *,int, const char *, void *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tdown(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tup(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tup(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tinit_MUTEX(&msblk->read_data_mutex);\n+\tinit_MUTEX(&msblk->read_page_mutex);\n+\tinit_MUTEX(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tup(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tdown(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tup(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tdown(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tup(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tup(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.14/fs/squashfs/Makefile linux-2.6.14-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.14/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/fs/squashfs/Makefile\t2008-08-19 04:48:39.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.14/fs/squashfs/squashfs2_0.c linux-2.6.14-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.14/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-19 04:48:39.000000000 +0100\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.14/fs/squashfs/squashfs.h linux-2.6.14-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.14/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-19 04:48:39.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern struct address_space_operations squashfs_symlink_aops;\n+extern struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.14/include/linux/squashfs_fs.h linux-2.6.14-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.14/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-19 04:49:11.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.14/include/linux/squashfs_fs_i.h linux-2.6.14-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.14/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-19 04:49:11.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.14/include/linux/squashfs_fs_sb.h linux-2.6.14-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.14/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-19 04:51:22.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct semaphore\t\tread_data_mutex;\n+\tstruct semaphore\t\tread_page_mutex;\n+\tstruct semaphore\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.14/init/do_mounts_rd.c linux-2.6.14-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.14/init/do_mounts_rd.c\t2005-10-28 01:02:08.000000000 +0100\n+++ linux-2.6.14-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 02:48:54.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.16/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.16/fs/Kconfig linux-2.6.16-squashfs3.4/fs/Kconfig\n--- linux-2.6.16/fs/Kconfig\t2006-03-20 05:53:29.000000000 +0000\n+++ linux-2.6.16-squashfs3.4/fs/Kconfig\t2008-08-18 17:12:49.000000000 +0100\n@@ -1193,6 +1193,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.16/fs/Makefile linux-2.6.16-squashfs3.4/fs/Makefile\n--- linux-2.6.16/fs/Makefile\t2006-03-20 05:53:29.000000000 +0000\n+++ linux-2.6.16-squashfs3.4/fs/Makefile\t2008-08-18 02:48:54.000000000 +0100\n@@ -55,6 +55,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.16/fs/squashfs/inode.c linux-2.6.16-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.16/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:23:31.000000000 +0100\n@@ -0,0 +1,2159 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct super_block *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static struct super_block *squashfs_get_sb(struct file_system_type *,int, const char *, void *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.16/fs/squashfs/Makefile linux-2.6.16-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.16/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.4/fs/squashfs/Makefile\t2008-08-18 02:48:54.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.16/fs/squashfs/squashfs2_0.c linux-2.6.16-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.16/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.16/fs/squashfs/squashfs.h linux-2.6.16-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.16/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern struct address_space_operations squashfs_symlink_aops;\n+extern struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.16/include/linux/squashfs_fs.h linux-2.6.16-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.16/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.16/include/linux/squashfs_fs_i.h linux-2.6.16-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.16/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.16/include/linux/squashfs_fs_sb.h linux-2.6.16-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.16/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.16-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.16/init/do_mounts_rd.c linux-2.6.16-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.16/init/do_mounts_rd.c\t2006-03-20 05:53:29.000000000 +0000\n+++ linux-2.6.16-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 02:48:54.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.18/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.18/fs/Kconfig linux-2.6.18-squashfs3.4/fs/Kconfig\n--- linux-2.6.18/fs/Kconfig\t2006-09-20 04:42:06.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/fs/Kconfig\t2008-08-18 17:12:49.000000000 +0100\n@@ -1249,6 +1249,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \thelp\ndiff -x .gitignore -Nurp linux-2.6.18/fs/Makefile linux-2.6.18-squashfs3.4/fs/Makefile\n--- linux-2.6.18/fs/Makefile\t2006-09-20 04:42:06.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/fs/Makefile\t2008-08-18 02:48:54.000000000 +0100\n@@ -57,6 +57,7 @@ obj-$(CONFIG_EXT3_FS)\t\t+= ext3/ # Before\n obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.18/fs/squashfs/inode.c linux-2.6.18-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.18/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:23:44.000000000 +0100\n@@ -0,0 +1,2161 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static kmem_cache_t * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tif (kmem_cache_destroy(squashfs_inode_cachep))\n+\t\tprintk(KERN_INFO \"squashfs_inode_cache: not all structures were freed\\n\");\n+\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.18/fs/squashfs/Makefile linux-2.6.18-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.18/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/fs/squashfs/Makefile\t2008-08-18 02:48:54.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.18/fs/squashfs/squashfs2_0.c linux-2.6.18-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.18/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,755 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/types.h>\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/errno.h>\n+#include <linux/slab.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/smp_lock.h>\n+#include <linux/slab.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/init.h>\n+#include <linux/dcache.h>\n+#include <linux/wait.h>\n+#include <linux/blkdev.h>\n+#include <linux/vmalloc.h>\n+#include <asm/uaccess.h>\n+#include <asm/semaphore.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\ti->i_blksize = PAGE_CACHE_SIZE;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.18/fs/squashfs/squashfs.h linux-2.6.18-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.18/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.18/include/linux/squashfs_fs.h linux-2.6.18-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.18/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.18/include/linux/squashfs_fs_i.h linux-2.6.18-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.18/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.18/include/linux/squashfs_fs_sb.h linux-2.6.18-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.18/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.18/init/do_mounts_rd.c linux-2.6.18-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.18/init/do_mounts_rd.c\t2006-09-20 04:42:06.000000000 +0100\n+++ linux-2.6.18-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 02:48:54.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.20/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.20/fs/Kconfig linux-2.6.20-squashfs3.4/fs/Kconfig\n--- linux-2.6.20/fs/Kconfig\t2007-02-04 18:44:54.000000000 +0000\n+++ linux-2.6.20-squashfs3.4/fs/Kconfig\t2008-08-18 17:12:49.000000000 +0100\n@@ -1404,6 +1404,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.20/fs/Makefile linux-2.6.20-squashfs3.4/fs/Makefile\n--- linux-2.6.20/fs/Makefile\t2007-02-04 18:44:54.000000000 +0000\n+++ linux-2.6.20-squashfs3.4/fs/Makefile\t2008-08-18 02:48:54.000000000 +0100\n@@ -68,6 +68,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/inode.c linux-2.6.20-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.20/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:23:57.000000000 +0100\n@@ -0,0 +1,2147 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <linux/smp_lock.h>\n+\n+#include \"squashfs.h\"\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tif ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR)\n+\t\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/Makefile linux-2.6.20-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.20/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.4/fs/squashfs/Makefile\t2008-08-18 02:48:54.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/squashfs2_0.c linux-2.6.20-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.20/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/squashfs.h linux-2.6.20-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.20/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.20/include/linux/squashfs_fs.h linux-2.6.20-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.20/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.20/include/linux/squashfs_fs_i.h linux-2.6.20-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.20/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.20/include/linux/squashfs_fs_sb.h linux-2.6.20-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.20/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.20-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-18 17:12:49.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.20/init/do_mounts_rd.c linux-2.6.20-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.20/init/do_mounts_rd.c\t2007-02-04 18:44:54.000000000 +0000\n+++ linux-2.6.20-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 02:48:54.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.22/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.22/fs/Kconfig linux-2.6.22-squashfs3.4/fs/Kconfig\n--- linux-2.6.22/fs/Kconfig\t2007-07-09 00:32:17.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/fs/Kconfig\t2008-08-18 17:01:29.000000000 +0100\n@@ -1367,6 +1367,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.22/fs/Makefile linux-2.6.22-squashfs3.4/fs/Makefile\n--- linux-2.6.22/fs/Makefile\t2007-07-09 00:32:17.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/fs/Makefile\t2008-08-18 17:02:26.000000000 +0100\n@@ -72,6 +72,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.22/fs/squashfs/inode.c linux-2.6.22-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.22/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:24:09.000000000 +0100\n@@ -0,0 +1,2146 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <linux/smp_lock.h>\n+\n+#include \"squashfs.h\"\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once, NULL);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.22/fs/squashfs/Makefile linux-2.6.22-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.22/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/fs/squashfs/Makefile\t2008-08-18 17:01:29.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.22/fs/squashfs/squashfs2_0.c linux-2.6.22-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.22/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-18 17:01:29.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.22/fs/squashfs/squashfs.h linux-2.6.22-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.22/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-18 17:01:29.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.22/include/linux/squashfs_fs.h linux-2.6.22-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.22/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-18 17:01:29.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.22/include/linux/squashfs_fs_i.h linux-2.6.22-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.22/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-18 17:01:29.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.22/include/linux/squashfs_fs_sb.h linux-2.6.22-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.22/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-18 17:01:29.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.22/init/do_mounts_rd.c linux-2.6.22-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.22/init/do_mounts_rd.c\t2007-07-09 00:32:17.000000000 +0100\n+++ linux-2.6.22-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 17:01:29.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.23/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.23/fs/Kconfig linux-2.6.23-squashfs3.4/fs/Kconfig\n--- linux-2.6.23/fs/Kconfig\t2007-10-09 21:31:38.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/fs/Kconfig\t2008-08-18 16:47:40.000000000 +0100\n@@ -1364,6 +1364,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.23/fs/Makefile linux-2.6.23-squashfs3.4/fs/Makefile\n--- linux-2.6.23/fs/Makefile\t2007-10-09 21:31:38.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/fs/Makefile\t2008-08-18 16:49:22.000000000 +0100\n@@ -72,6 +72,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-$(CONFIG_RAMFS)\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.23/fs/squashfs/inode.c linux-2.6.23-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.23/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:24:19.000000000 +0100\n@@ -0,0 +1,2147 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/exportfs.h>\n+#include <linux/spinlock.h>\n+#include <linux/smp_lock.h>\n+\n+#include \"squashfs.h\"\n+\n+static void vfs_read_inode(struct inode *i);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct super_operations squashfs_export_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.read_inode = vfs_read_inode\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\t\n+\n+static void vfs_read_inode(struct inode *i)\n+{\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tsquashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);\n+\n+\tTRACE(\"Entered vfs_read_inode\\n\");\n+\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\t(msblk->read_inode)(i, inode);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\tstruct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+\tstruct dentry *rv;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\tif(parent == NULL) {\n+\t\trv = ERR_PTR(-EACCES);\n+\t\tgoto out;\n+\t}\n+\n+\trv = d_alloc_anon(parent);\n+\tif(rv == NULL)\n+\t\trv = ERR_PTR(-ENOMEM);\n+\n+out:\n+\treturn rv;\n+}\n+\n+\t\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_op = &squashfs_export_super_ops;\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.23/fs/squashfs/Makefile linux-2.6.23-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.23/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/fs/squashfs/Makefile\t2008-08-18 16:47:40.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.23/fs/squashfs/squashfs2_0.c linux-2.6.23-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.23/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-18 16:47:40.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.23/fs/squashfs/squashfs.h linux-2.6.23-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.23/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-18 16:47:40.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.23/include/linux/squashfs_fs.h linux-2.6.23-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.23/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-18 16:47:40.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.23/include/linux/squashfs_fs_i.h linux-2.6.23-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.23/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-18 16:47:40.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.23/include/linux/squashfs_fs_sb.h linux-2.6.23-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.23/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-18 16:47:40.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.23/init/do_mounts_rd.c linux-2.6.23-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.23/init/do_mounts_rd.c\t2007-10-09 21:31:38.000000000 +0100\n+++ linux-2.6.23-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 16:47:40.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.24/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.24/fs/Kconfig linux-2.6.24-squashfs3.4/fs/Kconfig\n--- linux-2.6.24/fs/Kconfig\t2008-01-24 22:58:37.000000000 +0000\n+++ linux-2.6.24-squashfs3.4/fs/Kconfig\t2008-08-18 16:58:05.000000000 +0100\n@@ -1405,6 +1405,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.24/fs/Makefile linux-2.6.24-squashfs3.4/fs/Makefile\n--- linux-2.6.24/fs/Makefile\t2008-01-24 22:58:37.000000000 +0000\n+++ linux-2.6.24-squashfs3.4/fs/Makefile\t2008-08-18 16:58:05.000000000 +0100\n@@ -72,6 +72,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-y\t\t\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/inode.c linux-2.6.24-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.24/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:24:31.000000000 +0100\n@@ -0,0 +1,2173 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <linux/smp_lock.h>\n+#include <linux/exportfs.h>\n+\n+#include \"squashfs.h\"\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.fh_to_dentry = squashfs_fh_to_dentry,\n+\t.fh_to_parent = squashfs_fh_to_parent,\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\n+\n+\n+static struct dentry *squashfs_export_iget(struct super_block *s,\n+\tunsigned int inode_number)\n+{\n+\tsquashfs_inode_t inode;\n+\tstruct inode *i;\n+\tstruct dentry *dentry;\n+\n+\tTRACE(\"Entered squashfs_export_iget\\n\");\n+\n+\tinode = squashfs_inode_lookup(s, inode_number);\n+\tif(inode == SQUASHFS_INVALID_BLK) {\n+\t\tdentry = ERR_PTR(-ENOENT);\n+\t\tgoto failure;\n+\t}\n+\n+\ti = squashfs_iget(s, inode, inode_number);\n+\tif(i == NULL) {\n+\t\tdentry = ERR_PTR(-EACCES);\n+\t\tgoto failure;\n+\t}\n+\n+\tdentry = d_alloc_anon(i);\n+\tif (dentry == NULL) {\n+\t\tiput(i);\n+\t\tdentry = ERR_PTR(-ENOMEM);\n+\t}\n+\n+failure:\n+\treturn dentry;\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif((fh_type != FILEID_INO32_GEN && fh_type != FILEID_INO32_GEN_PARENT) ||\n+\t\t\tfh_len < 2)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.ino);\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif(fh_type != FILEID_INO32_GEN_PARENT || fh_len < 4)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.parent_ino);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\treturn squashfs_export_iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+}\n+\n+\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(struct kmem_cache *cachep, void *foo)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/Makefile linux-2.6.24-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.24/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.4/fs/squashfs/Makefile\t2008-08-18 16:58:05.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs2_0.c linux-2.6.24-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.24/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-18 16:58:05.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs.h linux-2.6.24-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.24/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-18 16:58:05.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs.h linux-2.6.24-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.24/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-18 16:58:06.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs_i.h linux-2.6.24-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.24/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-18 16:58:06.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs_sb.h linux-2.6.24-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.24/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.24-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-18 16:58:06.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.24/init/do_mounts_rd.c linux-2.6.24-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.24/init/do_mounts_rd.c\t2008-01-24 22:58:37.000000000 +0000\n+++ linux-2.6.24-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 16:58:06.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.25/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.25/fs/Kconfig linux-2.6.25-squashfs3.4/fs/Kconfig\n--- linux-2.6.25/fs/Kconfig\t2008-04-17 03:49:44.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/fs/Kconfig\t2008-08-18 16:44:29.000000000 +0100\n@@ -1367,6 +1367,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.25/fs/Makefile linux-2.6.25-squashfs3.4/fs/Makefile\n--- linux-2.6.25/fs/Makefile\t2008-04-17 03:49:44.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/fs/Makefile\t2008-08-18 16:44:29.000000000 +0100\n@@ -73,6 +73,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-y\t\t\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.25/fs/squashfs/inode.c linux-2.6.25-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.25/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:24:58.000000000 +0100\n@@ -0,0 +1,2173 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <linux/smp_lock.h>\n+#include <linux/exportfs.h>\n+\n+#include \"squashfs.h\"\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.fh_to_dentry = squashfs_fh_to_dentry,\n+\t.fh_to_parent = squashfs_fh_to_parent,\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\n+\n+\n+static struct dentry *squashfs_export_iget(struct super_block *s,\n+\tunsigned int inode_number)\n+{\n+\tsquashfs_inode_t inode;\n+\tstruct inode *i;\n+\tstruct dentry *dentry;\n+\n+\tTRACE(\"Entered squashfs_export_iget\\n\");\n+\n+\tinode = squashfs_inode_lookup(s, inode_number);\n+\tif(inode == SQUASHFS_INVALID_BLK) {\n+\t\tdentry = ERR_PTR(-ENOENT);\n+\t\tgoto failure;\n+\t}\n+\n+\ti = squashfs_iget(s, inode, inode_number);\n+\tif(i == NULL) {\n+\t\tdentry = ERR_PTR(-EACCES);\n+\t\tgoto failure;\n+\t}\n+\n+\tdentry = d_alloc_anon(i);\n+\tif (dentry == NULL) {\n+\t\tiput(i);\n+\t\tdentry = ERR_PTR(-ENOMEM);\n+\t}\n+\n+failure:\n+\treturn dentry;\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif((fh_type != FILEID_INO32_GEN && fh_type != FILEID_INO32_GEN_PARENT) ||\n+\t\t\tfh_len < 2)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.ino);\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif(fh_type != FILEID_INO32_GEN_PARENT || fh_len < 4)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.parent_ino);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\treturn squashfs_export_iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+}\n+\n+\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(struct kmem_cache *cachep, void *foo)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.25/fs/squashfs/Makefile linux-2.6.25-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.25/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/fs/squashfs/Makefile\t2008-08-18 16:44:29.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.25/fs/squashfs/squashfs2_0.c linux-2.6.25-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.25/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-18 16:44:29.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.25/fs/squashfs/squashfs.h linux-2.6.25-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.25/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-18 16:44:29.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.25/include/linux/squashfs_fs.h linux-2.6.25-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.25/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-18 16:44:29.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.25/include/linux/squashfs_fs_i.h linux-2.6.25-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.25/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-18 16:44:29.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.25/include/linux/squashfs_fs_sb.h linux-2.6.25-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.25/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-18 16:44:29.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.25/init/do_mounts_rd.c linux-2.6.25-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.25/init/do_mounts_rd.c\t2008-04-17 03:49:44.000000000 +0100\n+++ linux-2.6.25-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 16:44:29.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.26/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.26/fs/Kconfig linux-2.6.26-squashfs3.4/fs/Kconfig\n--- linux-2.6.26/fs/Kconfig\t2008-07-13 22:51:29.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/fs/Kconfig\t2008-08-18 16:44:36.000000000 +0100\n@@ -1395,6 +1395,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.26/fs/Makefile linux-2.6.26-squashfs3.4/fs/Makefile\n--- linux-2.6.26/fs/Makefile\t2008-07-13 22:51:29.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/fs/Makefile\t2008-08-18 16:44:36.000000000 +0100\n@@ -73,6 +73,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-y\t\t\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.26/fs/squashfs/inode.c linux-2.6.26-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.26/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:25:10.000000000 +0100\n@@ -0,0 +1,2173 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <linux/smp_lock.h>\n+#include <linux/exportfs.h>\n+\n+#include \"squashfs.h\"\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.fh_to_dentry = squashfs_fh_to_dentry,\n+\t.fh_to_parent = squashfs_fh_to_parent,\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\n+\n+\n+static struct dentry *squashfs_export_iget(struct super_block *s,\n+\tunsigned int inode_number)\n+{\n+\tsquashfs_inode_t inode;\n+\tstruct inode *i;\n+\tstruct dentry *dentry;\n+\n+\tTRACE(\"Entered squashfs_export_iget\\n\");\n+\n+\tinode = squashfs_inode_lookup(s, inode_number);\n+\tif(inode == SQUASHFS_INVALID_BLK) {\n+\t\tdentry = ERR_PTR(-ENOENT);\n+\t\tgoto failure;\n+\t}\n+\n+\ti = squashfs_iget(s, inode, inode_number);\n+\tif(i == NULL) {\n+\t\tdentry = ERR_PTR(-EACCES);\n+\t\tgoto failure;\n+\t}\n+\n+\tdentry = d_alloc_anon(i);\n+\tif (dentry == NULL) {\n+\t\tiput(i);\n+\t\tdentry = ERR_PTR(-ENOMEM);\n+\t}\n+\n+failure:\n+\treturn dentry;\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif((fh_type != FILEID_INO32_GEN && fh_type != FILEID_INO32_GEN_PARENT) ||\n+\t\t\tfh_len < 2)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.ino);\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif(fh_type != FILEID_INO32_GEN_PARENT || fh_len < 4)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.parent_ino);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\treturn squashfs_export_iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+}\n+\n+\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(struct kmem_cache *cachep, void *foo)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.26/fs/squashfs/Makefile linux-2.6.26-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.26/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/fs/squashfs/Makefile\t2008-08-18 16:44:36.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.26/fs/squashfs/squashfs2_0.c linux-2.6.26-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.26/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-18 16:44:36.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.26/fs/squashfs/squashfs.h linux-2.6.26-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.26/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-18 16:44:36.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.26/include/linux/squashfs_fs.h linux-2.6.26-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.26/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-18 16:44:36.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.26/include/linux/squashfs_fs_i.h linux-2.6.26-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.26/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-18 16:44:36.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.26/include/linux/squashfs_fs_sb.h linux-2.6.26-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.26/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-18 16:44:36.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.26/init/do_mounts_rd.c linux-2.6.26-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.26/init/do_mounts_rd.c\t2008-07-13 22:51:29.000000000 +0100\n+++ linux-2.6.26-squashfs3.4/init/do_mounts_rd.c\t2008-08-18 16:44:36.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.27-rc4/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.27-rc4/fs/Kconfig linux-2.6.27-rc4-squashfs3.4/fs/Kconfig\n--- linux-2.6.27-rc4/fs/Kconfig\t2008-08-11 15:20:41.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/fs/Kconfig\t2008-08-19 18:31:56.000000000 +0100\n@@ -1348,6 +1348,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.27-rc4/fs/Makefile linux-2.6.27-rc4-squashfs3.4/fs/Makefile\n--- linux-2.6.27-rc4/fs/Makefile\t2008-08-11 15:20:41.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/fs/Makefile\t2008-08-19 18:31:56.000000000 +0100\n@@ -74,6 +74,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-y\t\t\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.27-rc4/fs/squashfs/inode.c linux-2.6.27-rc4-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.27-rc4/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:25:23.000000000 +0100\n@@ -0,0 +1,2173 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <linux/smp_lock.h>\n+#include <linux/exportfs.h>\n+\n+#include \"squashfs.h\"\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.fh_to_dentry = squashfs_fh_to_dentry,\n+\t.fh_to_parent = squashfs_fh_to_parent,\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\n+\n+\n+static struct dentry *squashfs_export_iget(struct super_block *s,\n+\tunsigned int inode_number)\n+{\n+\tsquashfs_inode_t inode;\n+\tstruct inode *i;\n+\tstruct dentry *dentry;\n+\n+\tTRACE(\"Entered squashfs_export_iget\\n\");\n+\n+\tinode = squashfs_inode_lookup(s, inode_number);\n+\tif(inode == SQUASHFS_INVALID_BLK) {\n+\t\tdentry = ERR_PTR(-ENOENT);\n+\t\tgoto failure;\n+\t}\n+\n+\ti = squashfs_iget(s, inode, inode_number);\n+\tif(i == NULL) {\n+\t\tdentry = ERR_PTR(-EACCES);\n+\t\tgoto failure;\n+\t}\n+\n+\tdentry = d_alloc_anon(i);\n+\tif (dentry == NULL) {\n+\t\tiput(i);\n+\t\tdentry = ERR_PTR(-ENOMEM);\n+\t}\n+\n+failure:\n+\treturn dentry;\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif((fh_type != FILEID_INO32_GEN && fh_type != FILEID_INO32_GEN_PARENT) ||\n+\t\t\tfh_len < 2)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.ino);\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif(fh_type != FILEID_INO32_GEN_PARENT || fh_len < 4)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.parent_ino);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\treturn squashfs_export_iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+}\n+\n+\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void *foo)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.27-rc4/fs/squashfs/Makefile linux-2.6.27-rc4-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.27-rc4/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/fs/squashfs/Makefile\t2008-08-19 18:31:56.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.27-rc4/fs/squashfs/squashfs2_0.c linux-2.6.27-rc4-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.27-rc4/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-19 18:31:56.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.27-rc4/fs/squashfs/squashfs.h linux-2.6.27-rc4-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.27-rc4/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-19 18:31:56.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.27-rc4/include/linux/squashfs_fs.h linux-2.6.27-rc4-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.27-rc4/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-19 18:31:56.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.27-rc4/include/linux/squashfs_fs_i.h linux-2.6.27-rc4-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.27-rc4/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-19 18:31:56.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.27-rc4/include/linux/squashfs_fs_sb.h linux-2.6.27-rc4-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.27-rc4/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-19 18:31:56.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.27-rc4/init/do_mounts_rd.c linux-2.6.27-rc4-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.27-rc4/init/do_mounts_rd.c\t2008-08-11 15:20:55.000000000 +0100\n+++ linux-2.6.27-rc4-squashfs3.4/init/do_mounts_rd.c\t2008-08-19 18:31:56.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -37,6 +38,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -51,6 +53,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -62,6 +65,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -99,6 +103,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/kernel-patches/linux-2.6.27-rc4-next/squashfs3.4-patch",
    "content": "diff -x .gitignore -Nurp linux-2.6.27-rc4-next/fs/Kconfig linux-2.6.27-rc4-next-squashfs3.4/fs/Kconfig\n--- linux-2.6.27-rc4-next/fs/Kconfig\t2008-08-20 02:17:13.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/fs/Kconfig\t2008-08-20 04:15:06.000000000 +0100\n@@ -1356,6 +1356,56 @@ config CRAMFS\n \n \t  If unsure, say N.\n \n+config SQUASHFS\n+\ttristate \"SquashFS 3.4 - Squashed file system support\"\n+\tselect ZLIB_INFLATE\n+\thelp\n+\t  Saying Y here includes support for SquashFS 3.4 (a Compressed\n+\t  Read-Only File System).  Squashfs is a highly compressed read-only\n+\t  filesystem for Linux.  It uses zlib compression to compress both\n+\t  files, inodes and directories.  Inodes in the system are very small\n+\t  and all blocks are packed to minimise data overhead. Block sizes\n+\t  greater than 4K are supported up to a maximum of 1 Mbytes (default\n+\t  block size 128K).  SquashFS 3.3 supports 64 bit filesystems and files\n+\t  (larger than 4GB), full uid/gid information, hard links and timestamps.  \n+\n+\t  Squashfs is intended for general read-only filesystem use, for\n+\t  archival use (i.e. in cases where a .tar.gz file may be used), and in\n+\t  embedded systems where low overhead is needed.  Further information\n+\t  and filesystem tools are available from http://squashfs.sourceforge.net.\n+\n+\t  If you want to compile this as a module ( = code which can be\n+\t  inserted in and removed from the running kernel whenever you want),\n+\t  say M here and read <file:Documentation/modules.txt>.  The module\n+\t  will be called squashfs.  Note that the root file system (the one\n+\t  containing the directory /) cannot be compiled as a module.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_EMBEDDED\n+\n+\tbool \"Additional option for memory-constrained systems\" \n+\tdepends on SQUASHFS\n+\tdefault n\n+\thelp\n+\t  Saying Y here allows you to specify cache size.\n+\n+\t  If unsure, say N.\n+\n+config SQUASHFS_FRAGMENT_CACHE_SIZE\n+\tint \"Number of fragments cached\" if SQUASHFS_EMBEDDED\n+\tdepends on SQUASHFS\n+\tdefault \"3\"\n+\thelp\n+\t  By default SquashFS caches the last 3 fragments read from\n+\t  the filesystem.  Increasing this amount may mean SquashFS\n+\t  has to re-read fragments less often from disk, at the expense\n+\t  of extra system memory.  Decreasing this amount will mean\n+\t  SquashFS uses less memory at the expense of extra reads from disk.\n+\n+\t  Note there must be at least one cached fragment.  Anything\n+\t  much more than three will probably not make much difference.\n+\n config VXFS_FS\n \ttristate \"FreeVxFS file system support (VERITAS VxFS(TM) compatible)\"\n \tdepends on BLOCK\ndiff -x .gitignore -Nurp linux-2.6.27-rc4-next/fs/Makefile linux-2.6.27-rc4-next-squashfs3.4/fs/Makefile\n--- linux-2.6.27-rc4-next/fs/Makefile\t2008-08-20 02:17:14.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/fs/Makefile\t2008-08-20 04:15:06.000000000 +0100\n@@ -75,6 +75,7 @@ obj-$(CONFIG_JBD)\t\t+= jbd/\n obj-$(CONFIG_JBD2)\t\t+= jbd2/\n obj-$(CONFIG_EXT2_FS)\t\t+= ext2/\n obj-$(CONFIG_CRAMFS)\t\t+= cramfs/\n+obj-$(CONFIG_SQUASHFS)\t\t+= squashfs/\n obj-y\t\t\t\t+= ramfs/\n obj-$(CONFIG_HUGETLBFS)\t\t+= hugetlbfs/\n obj-$(CONFIG_CODA_FS)\t\t+= coda/\ndiff -x .gitignore -Nurp linux-2.6.27-rc4-next/fs/squashfs/inode.c linux-2.6.27-rc4-next-squashfs3.4/fs/squashfs/inode.c\n--- linux-2.6.27-rc4-next/fs/squashfs/inode.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/fs/squashfs/inode.c\t2008-08-26 08:25:34.000000000 +0100\n@@ -0,0 +1,2157 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * inode.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+#include <linux/buffer_head.h>\n+#include <linux/vfs.h>\n+#include <linux/vmalloc.h>\n+#include <linux/spinlock.h>\n+#include <linux/smp_lock.h>\n+#include <linux/exportfs.h>\n+\n+#include \"squashfs.h\"\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type);\n+static struct dentry *squashfs_get_parent(struct dentry *child);\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);\n+static int squashfs_statfs(struct dentry *, struct kstatfs *);\n+static int squashfs_symlink_readpage(struct file *file, struct page *page);\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+static int squashfs_readpage(struct file *file, struct page *page);\n+static int squashfs_readdir(struct file *, void *, filldir_t);\n+static struct dentry *squashfs_lookup(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+static int squashfs_remount(struct super_block *s, int *flags, char *data);\n+static void squashfs_put_super(struct super_block *);\n+static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,\n+\t\t\t\tstruct vfsmount *);\n+static struct inode *squashfs_alloc_inode(struct super_block *sb);\n+static void squashfs_destroy_inode(struct inode *inode);\n+static int init_inodecache(void);\n+static void destroy_inodecache(void);\n+\n+static struct file_system_type squashfs_fs_type = {\n+\t.owner = THIS_MODULE,\n+\t.name = \"squashfs\",\n+\t.get_sb = squashfs_get_sb,\n+\t.kill_sb = kill_block_super,\n+\t.fs_flags = FS_REQUIRES_DEV\n+};\n+\n+static const unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static struct super_operations squashfs_super_ops = {\n+\t.alloc_inode = squashfs_alloc_inode,\n+\t.destroy_inode = squashfs_destroy_inode,\n+\t.statfs = squashfs_statfs,\n+\t.put_super = squashfs_put_super,\n+\t.remount_fs = squashfs_remount\n+};\n+\n+static struct export_operations squashfs_export_ops = {\n+\t.fh_to_dentry = squashfs_fh_to_dentry,\n+\t.fh_to_parent = squashfs_fh_to_parent,\n+\t.get_parent = squashfs_get_parent\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {\n+\t.readpage = squashfs_symlink_readpage\n+};\n+\n+SQSH_EXTERN const struct address_space_operations squashfs_aops = {\n+\t.readpage = squashfs_readpage\n+};\n+\n+static const struct file_operations squashfs_dir_ops = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir\n+};\n+\n+SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {\n+\t.lookup = squashfs_lookup\n+};\n+\n+\n+static struct buffer_head *get_block_length(struct super_block *s,\n+\t\t\t\tint *cur_index, int *offset, int *c_byte)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned short temp;\n+\tstruct buffer_head *bh;\n+\n+\tif (!(bh = sb_bread(s, *cur_index)))\n+\t\tgoto out;\n+\n+\tif (msblk->devblksize - *offset == 1) {\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\telse\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\tbrelse(bh);\n+\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\tgoto out;\n+\t\tif (msblk->swap)\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\telse\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\tbh->b_data); \n+\t\t*c_byte = temp;\n+\t\t*offset = 1;\n+\t} else {\n+\t\tif (msblk->swap) {\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t} else {\n+\t\t\t((unsigned char *) &temp)[0] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset));\n+\t\t\t((unsigned char *) &temp)[1] = *((unsigned char *)\n+\t\t\t\t(bh->b_data + *offset + 1)); \n+\t\t}\n+\t\t*c_byte = temp;\n+\t\t*offset += 2;\n+\t}\n+\n+\tif (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {\n+\t\tif (*offset == msblk->devblksize) {\n+\t\t\tbrelse(bh);\n+\t\t\tif (!(bh = sb_bread(s, ++(*cur_index))))\n+\t\t\t\tgoto out;\n+\t\t\t*offset = 0;\n+\t\t}\n+\t\tif (*((unsigned char *) (bh->b_data + *offset)) !=\n+\t\t\t\t\t\tSQUASHFS_MARKER_BYTE) {\n+\t\t\tERROR(\"Metadata block marker corrupt @ %x\\n\",\n+\t\t\t\t\t\t*cur_index);\n+\t\t\tbrelse(bh);\n+\t\t\tgoto out;\n+\t\t}\n+\t\t(*offset)++;\n+\t}\n+\treturn bh;\n+\n+out:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\tlong long index, unsigned int length,\n+\t\t\tlong long *next_index, int srclength)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tstruct buffer_head **bh;\n+\tunsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);\n+\tunsigned int cur_index = index >> msblk->devblksize_log2;\n+\tint bytes, avail_bytes, b = 0, k = 0;\n+\tunsigned int compressed;\n+\tunsigned int c_byte = length;\n+\n+\tbh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *\n+\t\t\t\t\t\t\t\tsizeof(struct buffer_head *), GFP_KERNEL);\n+\tif (bh == NULL)\n+\t\tgoto read_failure;\n+\n+\tif (c_byte) {\n+\t\tbytes = -offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d, src size %d\\n\", index,\n+\t\t\t\t\tcompressed ? \"\" : \"un\", (unsigned int) c_byte, srclength);\n+\n+\t\tif (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tfor (b = 0; bytes < (int) c_byte; b++, cur_index++) {\n+\t\t\tbh[b] = sb_getblk(s, cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b, bh);\n+\t} else {\n+\t\tif (index < 0 || (index + 2) > sblk->bytes_used)\n+\t\t\tgoto read_failure;\n+\n+\t\tbh[0] = get_block_length(s, &cur_index, &offset, &c_byte);\n+\t\tif (bh[0] == NULL)\n+\t\t\tgoto read_failure;\n+\t\tb = 1;\n+\n+\t\tbytes = msblk->devblksize - offset;\n+\t\tcompressed = SQUASHFS_COMPRESSED(c_byte);\n+\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n+\n+\t\tTRACE(\"Block @ 0x%llx, %scompressed size %d\\n\", index, compressed\n+\t\t\t\t\t? \"\" : \"un\", (unsigned int) c_byte);\n+\n+\t\tif (c_byte > srclength || (index + c_byte) > sblk->bytes_used)\n+\t\t\tgoto block_release;\n+\n+\t\tfor (; bytes < c_byte; b++) {\n+\t\t\tbh[b] = sb_getblk(s, ++cur_index);\n+\t\t\tif (bh[b] == NULL)\n+\t\t\t\tgoto block_release;\n+\t\t\tbytes += msblk->devblksize;\n+\t\t}\n+\t\tll_rw_block(READ, b - 1, bh + 1);\n+\t}\n+\n+\tif (compressed) {\n+\t\tint zlib_err = 0;\n+\n+\t\t/*\n+\t \t* uncompress block\n+\t \t*/\n+\n+\t\tmutex_lock(&msblk->read_data_mutex);\n+\n+\t\tmsblk->stream.next_out = buffer;\n+\t\tmsblk->stream.avail_out = srclength;\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\twait_on_buffer(bh[k]);\n+\t\t\tif (!buffer_uptodate(bh[k]))\n+\t\t\t\tgoto release_mutex;\n+\n+\t\t\tmsblk->stream.next_in = bh[k]->b_data + offset;\n+\t\t\tmsblk->stream.avail_in = avail_bytes;\n+\n+\t\t\tif (k == 0) {\n+\t\t\t\tzlib_err = zlib_inflateInit(&msblk->stream);\n+\t\t\t\tif (zlib_err != Z_OK) {\n+\t\t\t\t\tERROR(\"zlib_inflateInit returned unexpected result 0x%x,\"\n+\t\t\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\t\t\tgoto release_mutex;\n+\t\t\t\t}\n+\n+\t\t\t\tif (avail_bytes == 0) {\n+\t\t\t\t\toffset = 0;\n+\t\t\t\t\tbrelse(bh[k]);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tzlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);\n+\t\t\tif (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {\n+\t\t\t\tERROR(\"zlib_inflate returned unexpected result 0x%x,\"\n+\t\t\t\t\t\" srclength %d, avail_in %d, avail_out %d\\n\", zlib_err,\n+\t\t\t\t\tsrclength, msblk->stream.avail_in, msblk->stream.avail_out);\n+\t\t\t\tgoto release_mutex;\n+\t\t\t}\n+\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\n+\t\tif (zlib_err != Z_STREAM_END)\n+\t\t\tgoto release_mutex;\n+\n+\t\tzlib_err = zlib_inflateEnd(&msblk->stream);\n+\t\tif (zlib_err != Z_OK) {\n+\t\t\tERROR(\"zlib_inflateEnd returned unexpected result 0x%x,\"\n+\t\t\t\t\" srclength %d\\n\", zlib_err, srclength);\n+\t\t\tgoto release_mutex;\n+\t\t}\n+\t\tbytes = msblk->stream.total_out;\n+\t\tmutex_unlock(&msblk->read_data_mutex);\n+\t} else {\n+\t\tint i;\n+\n+\t\tfor(i = 0; i < b; i++) {\n+\t\t\twait_on_buffer(bh[i]);\n+\t\t\tif (!buffer_uptodate(bh[i]))\n+\t\t\t\tgoto block_release;\n+\t\t}\n+\n+\t\tfor (bytes = 0; k < b; k++) {\n+\t\t\tavail_bytes = min(c_byte - bytes, msblk->devblksize - offset);\n+\n+\t\t\tmemcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);\n+\t\t\tbytes += avail_bytes;\n+\t\t\toffset = 0;\n+\t\t\tbrelse(bh[k]);\n+\t\t}\n+\t}\n+\n+\tif (next_index)\n+\t\t*next_index = index + c_byte + (length ? 0 :\n+\t\t\t\t(SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));\n+\n+\tkfree(bh);\n+\treturn bytes;\n+\n+release_mutex:\n+\tmutex_unlock(&msblk->read_data_mutex);\n+\n+block_release:\n+\tfor (; k < b; k++)\n+\t\tbrelse(bh[k]);\n+\n+read_failure:\n+\tERROR(\"sb_bread failed reading block 0x%x\\n\", cur_index);\n+\tkfree(bh);\n+\treturn 0;\n+}\n+\n+\n+static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,\n+\tstruct squashfs_cache *cache, long long block, int length)\n+{\n+\tint i, n;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tspin_lock(&cache->lock);\n+\n+\twhile (1) {\n+\t\tfor (i = 0; i < cache->entries && cache->entry[i].block != block; i++);\n+\n+\t\tif (i == cache->entries) {\n+\t\t\tif (cache->unused_blks == 0) {\n+\t\t\t\tcache->waiting ++;\n+\t\t\t\tspin_unlock(&cache->lock);\n+\t\t\t\twait_event(cache->wait_queue, cache->unused_blks);\n+\t\t\t\tspin_lock(&cache->lock);\n+\t\t\t\tcache->waiting --;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\ti = cache->next_blk;\n+\t\t\tfor (n = 0; n < cache->entries; n++) {\n+\t\t\t\tif (cache->entry[i].locked == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\ti = (i + 1) % cache->entries;\n+\t\t\t}\n+\n+\t\t\tcache->next_blk = (i + 1) % cache->entries;\n+\t\t\tentry = &cache->entry[i];\n+\n+\t\t\tcache->unused_blks --;\n+\t\t\tentry->block = block;\n+\t\t\tentry->locked = 1;\n+\t\t\tentry->pending = 1;\n+\t\t\tentry->waiting = 0;\n+\t\t\tentry->error = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\n+\t\t\tentry->length = squashfs_read_data(s, entry->data,\n+\t\t\t\tblock, length, &entry->next_index, cache->block_size);\n+\n+\t\t\tspin_lock(&cache->lock);\n+\n+\t\t\tif (entry->length == 0)\n+\t\t\t\tentry->error = 1;\n+\n+\t\t\tentry->pending = 0;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\tif (entry->waiting)\n+\t\t\t\twake_up_all(&entry->wait_queue);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tentry = &cache->entry[i];\n+\t\tif (entry->locked == 0)\n+\t\t\tcache->unused_blks --;\n+\t\tentry->locked++;\n+\n+\t\tif (entry->pending) {\n+\t\t\tentry->waiting ++;\n+\t\t\tspin_unlock(&cache->lock);\n+\t\t\twait_event(entry->wait_queue, !entry->pending);\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tspin_unlock(&cache->lock);\n+\t\tgoto out;\n+\t}\n+\n+out:\n+\tTRACE(\"Got %s %d, start block %lld, locked %d, error %d\\n\", i,\n+\t\tcache->name, entry->block, entry->locked, entry->error);\n+\tif (entry->error)\n+\t\tERROR(\"Unable to read %s cache entry [%llx]\\n\", cache->name, block);\n+\treturn entry;\n+}\n+\n+\n+static void squashfs_cache_put(struct squashfs_cache *cache,\n+\t\t\t\tstruct squashfs_cache_entry *entry)\n+{\n+\tspin_lock(&cache->lock);\n+\tentry->locked --;\n+\tif (entry->locked == 0) {\n+\t\tcache->unused_blks ++;\n+\t\tspin_unlock(&cache->lock);\n+\t\tif (cache->waiting)\n+\t\t\twake_up(&cache->wait_queue);\n+\t} else\n+\t\tspin_unlock(&cache->lock);\n+}\n+\n+\n+static void squashfs_cache_delete(struct squashfs_cache *cache)\n+{\n+\tint i;\n+\n+\tif (cache == NULL)\n+\t\treturn;\n+\n+\tfor (i = 0; i < cache->entries; i++)\n+\t\tif (cache->entry[i].data) {\n+\t\t\tif (cache->use_vmalloc)\n+\t\t\t\tvfree(cache->entry[i].data);\n+\t\t\telse\n+\t\t\t\tkfree(cache->entry[i].data);\n+\t\t}\n+\n+\tkfree(cache);\n+}\n+\n+\n+static struct squashfs_cache *squashfs_cache_init(char *name, int entries,\n+\tint block_size, int use_vmalloc)\n+{\n+\tint i;\n+\tstruct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +\n+\t\t\tentries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);\n+\tif (cache == NULL) {\n+\t\tERROR(\"Failed to allocate %s cache\\n\", name);\n+\t\tgoto failed;\n+\t}\n+\n+\tcache->next_blk = 0;\n+\tcache->unused_blks = entries;\n+\tcache->entries = entries;\n+\tcache->block_size = block_size;\n+\tcache->use_vmalloc = use_vmalloc;\n+\tcache->name = name;\n+\tcache->waiting = 0;\n+\tspin_lock_init(&cache->lock);\n+\tinit_waitqueue_head(&cache->wait_queue);\n+\n+\tfor (i = 0; i < entries; i++) {\n+\t\tinit_waitqueue_head(&cache->entry[i].wait_queue);\n+\t\tcache->entry[i].block = SQUASHFS_INVALID_BLK;\n+\t\tcache->entry[i].data = use_vmalloc ? vmalloc(block_size) :\n+\t\t\t\tkmalloc(block_size, GFP_KERNEL);\n+\t\tif (cache->entry[i].data == NULL) {\n+\t\t\tERROR(\"Failed to allocate %s cache entry\\n\", name);\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t}\n+\n+\treturn cache;\n+\n+cleanup:\n+\tsquashfs_cache_delete(cache);\n+failed:\n+\treturn NULL;\n+}\n+\n+\n+SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tint bytes, return_length = length;\n+\tstruct squashfs_cache_entry *entry;\n+\n+\tTRACE(\"Entered squashfs_get_cached_block [%llx:%x]\\n\", block, offset);\n+\n+\twhile (1) {\n+\t\tentry = squashfs_cache_get(s, msblk->block_cache, block, 0);\n+\t\tbytes = entry->length - offset;\n+\n+\t\tif (entry->error || bytes < 1) {\n+\t\t\treturn_length = 0;\n+\t\t\tgoto finish;\n+\t\t} else if (bytes >= length) {\n+\t\t\tif (buffer)\n+\t\t\t\tmemcpy(buffer, entry->data + offset, length);\n+\t\t\tif (entry->length - offset == length) {\n+\t\t\t\t*next_block = entry->next_index;\n+\t\t\t\t*next_offset = 0;\n+\t\t\t} else {\n+\t\t\t\t*next_block = block;\n+\t\t\t\t*next_offset = offset + length;\n+\t\t\t}\n+\t\t\tgoto finish;\n+\t\t} else {\n+\t\t\tif (buffer) {\n+\t\t\t\tmemcpy(buffer, entry->data + offset, bytes);\n+\t\t\t\tbuffer = (char *) buffer + bytes;\n+\t\t\t}\n+\t\t\tblock = entry->next_index;\n+\t\t\tsquashfs_cache_put(msblk->block_cache, entry);\n+\t\t\tlength -= bytes;\n+\t\t\toffset = 0;\n+\t\t}\n+\t}\n+\n+finish:\n+\tsquashfs_cache_put(msblk->block_cache, entry);\n+\treturn return_length;\n+}\n+\n+\n+static int get_fragment_location(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);\n+\tstruct squashfs_fragment_entry fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(sfragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,\n+\t\t\t\t\t sizeof(fragment_entry), &start_block, &offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,\n+\t\t\t\tstruct squashfs_cache_entry *fragment)\n+{\n+\tsquashfs_cache_put(msblk->fragment_cache, fragment);\n+}\n+\n+\n+SQSH_EXTERN\n+struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,\n+\t\t\t\tlong long start_block, int length)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\n+\treturn squashfs_cache_get(s, msblk->fragment_cache, start_block, length);\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\t\t\tstruct squashfs_base_inode_header *inodeb)\n+{\n+\ti->i_ino = inodeb->inode_number;\n+\ti->i_mtime.tv_sec = inodeb->mtime;\n+\ti->i_atime.tv_sec = inodeb->mtime;\n+\ti->i_ctime.tv_sec = inodeb->mtime;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_size = 0;\n+\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];\n+\tint offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);\n+\tsquashfs_inode_t inode;\n+\n+\tTRACE(\"Entered squashfs_inode_lookup, inode_number = %d\\n\", ino);\n+\n+\tif (msblk->swap) {\n+\t\tsquashfs_inode_t sinode;\n+\n+\t\tif (!squashfs_get_cached_block(s, &sinode, start, offset,\n+\t\t\t\t\tsizeof(sinode), &start, &offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_INODE_T((&inode), &sinode);\n+\t} else if (!squashfs_get_cached_block(s, &inode, start, offset,\n+\t\t\t\t\tsizeof(inode), &start, &offset))\n+\t\t\tgoto out;\n+\n+\tTRACE(\"squashfs_inode_lookup, inode = 0x%llx\\n\", inode);\n+\n+\treturn inode;\n+\n+out:\n+\treturn SQUASHFS_INVALID_BLK;\n+}\n+\n+\n+\n+static struct dentry *squashfs_export_iget(struct super_block *s,\n+\tunsigned int inode_number)\n+{\n+\tsquashfs_inode_t inode;\n+\tstruct dentry *dentry = ERR_PTR(-ENOENT);\n+\n+\tTRACE(\"Entered squashfs_export_iget\\n\");\n+\n+\tinode = squashfs_inode_lookup(s, inode_number);\n+\tif(inode != SQUASHFS_INVALID_BLK)\n+\t\tdentry = d_obtain_alias(squashfs_iget(s, inode, inode_number));\n+\n+\treturn dentry;\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_dentry(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif((fh_type != FILEID_INO32_GEN && fh_type != FILEID_INO32_GEN_PARENT) ||\n+\t\t\tfh_len < 2)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.ino);\n+}\n+\n+\n+static struct dentry *squashfs_fh_to_parent(struct super_block *s,\n+\t\tstruct fid *fid, int fh_len, int fh_type)\n+{\n+\tif(fh_type != FILEID_INO32_GEN_PARENT || fh_len < 4)\n+\t\treturn NULL;\n+\n+\treturn squashfs_export_iget(s, fid->i32.parent_ino);\n+}\n+\n+\n+static struct dentry *squashfs_get_parent(struct dentry *child)\n+{\n+\tstruct inode *i = child->d_inode;\n+\n+\tTRACE(\"Entered squashfs_get_parent\\n\");\n+\n+\treturn squashfs_export_iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);\n+}\n+\n+\n+SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,\n+\t\t\t\tsquashfs_inode_t inode, unsigned int inode_number)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct inode *i = iget_locked(s, inode_number);\n+\n+\tTRACE(\"Entered squashfs_iget\\n\");\n+\n+\tif(i && (i->i_state & I_NEW)) {\n+\t\t(msblk->read_inode)(i, inode);\n+\t\tunlock_new_inode(i);\n+\t}\n+\n+\treturn i;\n+}\n+\n+\n+static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header id, sid;\n+\tstruct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, sinodeb, block, offset,\n+\t\t\t\t\tsizeof(*sinodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, inodeb, block, offset,\n+\t\t\t\t\tsizeof(*inodeb), &next_block, &next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_reg_inode_header *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header *sinodep = &sid.reg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\t\tif(!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t&frag_size))\n+\t\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = 1;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LREG_TYPE: {\n+\t\t\tunsigned int frag_size;\n+\t\t\tlong long frag_blk;\n+\t\t\tstruct squashfs_lreg_inode_header *inodep = &id.lreg;\n+\t\t\tstruct squashfs_lreg_inode_header *sinodep = &sid.lreg;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG)\n+\t\t\t\tif (!get_fragment_location(s, inodep->fragment, &frag_blk,\n+\t\t\t\t\t\t\t\t\t\t\t\t &frag_size))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops;\n+\t\t\ti->i_fop = &squashfs_dir_ops;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header *inodep = &id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header *sinodep = &sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?\n+\t\t\t\t\tS_IFCHR : S_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset, inodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\t\t\tstruct squashfs_ipc_inode_header *inodep = &id.ipc;\n+\t\t\tstruct squashfs_ipc_inode_header *sinodep = &sid.ipc;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, sinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, inodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_nlink = inodep->nlink;\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%llx:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\tmake_bad_inode(i);\n+\treturn 0;\n+}\n+\n+\n+static int read_inode_lookup_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);\n+\n+\tTRACE(\"In read_inode_lookup_table, length %d\\n\", length);\n+\n+\t/* Allocate inode lookup table */\n+\tmsblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->inode_lookup_table == NULL) {\n+\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,\n+\t\t\tsblk->lookup_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read inode lookup table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long block;\n+\n+\t\tfor (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_LOOKUP_BLOCKS((&block),\n+\t\t\t\t\t\t&msblk->inode_lookup_table[i], 1);\n+\t\t\tmsblk->inode_lookup_table[i] = block;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int read_fragment_index_table(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);\n+\n+\tif(length == 0)\n+\t\treturn 1;\n+\n+\t/* Allocate fragment index table */\n+\tmsblk->fragment_index = kmalloc(length, GFP_KERNEL);\n+\tif (msblk->fragment_index == NULL) {\n+\t\tERROR(\"Failed to allocate fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (!squashfs_read_data(s, (char *) msblk->fragment_index,\n+\t\t\tsblk->fragment_table_start, length |\n+\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tlong long fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {\n+\t\t\t/* XXX */\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index[i], 1);\n+\t\t\tmsblk->fragment_index[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode;\n+\tmsblk->read_blocklist = read_blocklist;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table;\n+\n+\tif (sblk->s_major == 1) {\n+\t\tif (!squashfs_1_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 1.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 1.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if (sblk->s_major == 2) {\n+\t\tif (!squashfs_2_0_supported(msblk)) {\n+\t\t\tSERROR(\"Major/Minor mismatch, Squashfs 2.0 filesystems \"\n+\t\t\t\t\"are unsupported\\n\");\n+\t\t\tSERROR(\"Please recompile with Squashfs 2.0 support enabled\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t} else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >\n+\t\t\tSQUASHFS_MINOR) {\n+\t\tSERROR(\"Major/Minor mismatch, trying to mount newer %d.%d \"\n+\t\t\t\t\"filesystem\\n\", sblk->s_major, sblk->s_minor);\n+\t\tSERROR(\"Please update your kernel\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int squashfs_fill_super(struct super_block *s, void *data, int silent)\n+{\n+\tstruct squashfs_sb_info *msblk;\n+\tstruct squashfs_super_block *sblk;\n+\tchar b[BDEVNAME_SIZE];\n+\tstruct inode *root;\n+\n+\tTRACE(\"Entered squashfs_fill_superblock\\n\");\n+\n+\ts->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);\n+\tif (s->s_fs_info == NULL) {\n+\t\tERROR(\"Failed to allocate superblock\\n\");\n+\t\tgoto failure;\n+\t}\n+\tmsblk = s->s_fs_info;\n+\n+\tmsblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());\n+\tif (msblk->stream.workspace == NULL) {\n+\t\tERROR(\"Failed to allocate zlib workspace\\n\");\n+\t\tgoto failure;\n+\t}\n+\tsblk = &msblk->sblk;\n+\t\n+\tmsblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);\n+\tmsblk->devblksize_log2 = ffz(~msblk->devblksize);\n+\n+\tmutex_init(&msblk->read_data_mutex);\n+\tmutex_init(&msblk->read_page_mutex);\n+\tmutex_init(&msblk->meta_index_mutex);\n+\t\n+\t/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not\n+ \t * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,\n+ \t * first set sblk->bytes_used to a useful value */\n+\tsblk->bytes_used = sizeof(struct squashfs_super_block);\n+\tif (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,\n+\t\t\t\t\tsizeof(struct squashfs_super_block) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {\n+\t\tSERROR(\"unable to read superblock\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Check it is a SQUASHFS superblock */\n+\tif ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {\n+\t\tif (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {\n+\t\t\tstruct squashfs_super_block ssblk;\n+\n+\t\t\tWARNING(\"Mounting a different endian SQUASHFS filesystem on %s\\n\",\n+\t\t\t\tbdevname(s->s_bdev, b));\n+\n+\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);\n+\t\t\tmemcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));\n+\t\t\tmsblk->swap = 1;\n+\t\t} else  {\n+\t\t\tSERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n+\t\t\t\t\t\t\tbdevname(s->s_bdev, b));\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\t}\n+\n+\t/* Check the MAJOR & MINOR versions */\n+\tif(!supported_squashfs_filesystem(msblk, silent))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the filesystem does not extend beyond the end of the\n+\t   block device */\n+\tif(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))\n+\t\tgoto failed_mount;\n+\n+\t/* Check the root inode for sanity */\n+\tif (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)\n+\t\tgoto failed_mount;\n+\n+\tTRACE(\"Found valid superblock on %s\\n\", bdevname(s->s_bdev, b));\n+\tTRACE(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)\n+\t\t\t\t\t? \"un\" : \"\");\n+\tTRACE(\"Check data is %spresent in the filesystem\\n\",\n+\t\t\t\t\tSQUASHFS_CHECK_DATA(sblk->flags) ?  \"\" : \"not \");\n+\tTRACE(\"Filesystem size %lld bytes\\n\", sblk->bytes_used);\n+\tTRACE(\"Block size %d\\n\", sblk->block_size);\n+\tTRACE(\"Number of inodes %d\\n\", sblk->inodes);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"Number of fragments %d\\n\", sblk->fragments);\n+\tTRACE(\"Number of uids %d\\n\", sblk->no_uids);\n+\tTRACE(\"Number of gids %d\\n\", sblk->no_guids);\n+\tTRACE(\"sblk->inode_table_start %llx\\n\", sblk->inode_table_start);\n+\tTRACE(\"sblk->directory_table_start %llx\\n\", sblk->directory_table_start);\n+\tif (sblk->s_major > 1)\n+\t\tTRACE(\"sblk->fragment_table_start %llx\\n\", sblk->fragment_table_start);\n+\tTRACE(\"sblk->uid_start %llx\\n\", sblk->uid_start);\n+\n+\ts->s_maxbytes = MAX_LFS_FILESIZE;\n+\ts->s_flags |= MS_RDONLY;\n+\ts->s_op = &squashfs_super_ops;\n+\n+\tmsblk->block_cache = squashfs_cache_init(\"metadata\", SQUASHFS_CACHED_BLKS,\n+\t\tSQUASHFS_METADATA_SIZE, 0);\n+\tif (msblk->block_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate read_page block */\n+\tmsblk->read_page = vmalloc(sblk->block_size);\n+\tif (msblk->read_page == NULL) {\n+\t\tERROR(\"Failed to allocate read_page block\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\n+\t/* Allocate uid and gid tables */\n+\tmsblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\tsizeof(unsigned int), GFP_KERNEL);\n+\tif (msblk->uid == NULL) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\tgoto failed_mount;\n+\t}\n+\tmsblk->guid = msblk->uid + sblk->no_uids;\n+   \n+\tif (msblk->swap) {\n+\t\tunsigned int suid[sblk->no_uids + sblk->no_guids];\n+\n+\t\tif (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\t\tSQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +\n+\t\t\tsblk->no_guids), (sizeof(unsigned int) * 8));\n+\t} else\n+\t\tif (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,\n+\t\t\t\t\t((sblk->no_uids + sblk->no_guids) *\n+\t\t\t\t\t sizeof(unsigned int)) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {\n+\t\t\tERROR(\"unable to read uid/gid table\\n\");\n+\t\t\tgoto failed_mount;\n+\t\t}\n+\n+\n+\tif (sblk->s_major == 1 && squashfs_1_0_supported(msblk))\n+\t\tgoto allocate_root;\n+\n+\tmsblk->fragment_cache = squashfs_cache_init(\"fragment\",\n+\t\tSQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);\n+\tif (msblk->fragment_cache == NULL)\n+\t\tgoto failed_mount;\n+\n+\t/* Allocate and read fragment index table */\n+\tif (msblk->read_fragment_index_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\tif(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)\n+\t\tgoto allocate_root;\n+\n+\t/* Allocate and read inode lookup table */\n+\tif (read_inode_lookup_table(s) == 0)\n+\t\tgoto failed_mount;\n+\n+\ts->s_export_op = &squashfs_export_ops;\n+\n+allocate_root:\n+\troot = new_inode(s);\n+\tif ((msblk->read_inode)(root, sblk->root_inode) == 0)\n+\t\tgoto failed_mount;\n+\tinsert_inode_hash(root);\n+\n+\ts->s_root = d_alloc_root(root);\n+\tif (s->s_root == NULL) {\n+\t\tERROR(\"Root inode create failed\\n\");\n+\t\tiput(root);\n+\t\tgoto failed_mount;\n+\t}\n+\n+\tTRACE(\"Leaving squashfs_fill_super\\n\");\n+\treturn 0;\n+\n+failed_mount:\n+\tkfree(msblk->inode_lookup_table);\n+\tkfree(msblk->fragment_index);\n+\tsquashfs_cache_delete(msblk->fragment_cache);\n+\tkfree(msblk->uid);\n+\tvfree(msblk->read_page);\n+\tsquashfs_cache_delete(msblk->block_cache);\n+\tkfree(msblk->fragment_index_2);\n+\tvfree(msblk->stream.workspace);\n+\tkfree(s->s_fs_info);\n+\ts->s_fs_info = NULL;\n+\treturn -EINVAL;\n+\n+failure:\n+\treturn -ENOMEM;\n+}\n+\n+\n+static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)\n+{\n+\tstruct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tTRACE(\"Entered squashfs_statfs\\n\");\n+\n+\tbuf->f_type = SQUASHFS_MAGIC;\n+\tbuf->f_bsize = sblk->block_size;\n+\tbuf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;\n+\tbuf->f_bfree = buf->f_bavail = 0;\n+\tbuf->f_files = sblk->inodes;\n+\tbuf->f_ffree = 0;\n+\tbuf->f_namelen = SQUASHFS_NAME_LEN;\n+\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_symlink_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tint index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;\n+\tlong long block = SQUASHFS_I(inode)->start_block;\n+\tint offset = SQUASHFS_I(inode)->offset;\n+\tvoid *pageaddr = kmap(page);\n+\n+\tTRACE(\"Entered squashfs_symlink_readpage, page index %ld, start block \"\n+\t\t\t\t\"%llx, offset %x\\n\", page->index,\n+\t\t\t\tSQUASHFS_I(inode)->start_block,\n+\t\t\t\tSQUASHFS_I(inode)->offset);\n+\n+\tfor (length = 0; length < index; length += bytes) {\n+\t\tbytes = squashfs_get_cached_block(inode->i_sb, NULL, block,\n+\t\t\t\toffset, PAGE_CACHE_SIZE, &block, &offset);\n+\t\tif (bytes == 0) {\n+\t\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\t\t\tgoto skip_read;\n+\t\t}\n+\t}\n+\n+\tif (length != index) {\n+\t\tERROR(\"(squashfs_symlink_readpage) length != index\\n\");\n+\t\tbytes = 0;\n+\t\tgoto skip_read;\n+\t}\n+\n+\tavail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);\n+\n+\tbytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,\n+\t\tavail_bytes, &block, &offset);\n+\tif (bytes == 0)\n+\t\tERROR(\"Unable to read symbolic link [%llx:%x]\\n\", block, offset);\n+\n+skip_read:\n+\tmemset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);\n+\tkunmap(page);\n+\tflush_dcache_page(page);\n+\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\treturn 0;\n+}\n+\n+\n+static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)\n+{\n+\tstruct meta_index *meta = NULL;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"locate_meta_index: index %d, offset %d\\n\", index, offset);\n+\n+\tif (msblk->meta_index == NULL)\n+\t\tgoto not_allocated;\n+\n+\tfor (i = 0; i < SQUASHFS_META_NUMBER; i ++) {\n+\t\tif (msblk->meta_index[i].inode_number == inode->i_ino &&\n+\t\t\t\tmsblk->meta_index[i].offset >= offset &&\n+\t\t\t\tmsblk->meta_index[i].offset <= index &&\n+\t\t\t\tmsblk->meta_index[i].locked == 0) {\n+\t\t\tTRACE(\"locate_meta_index: entry %d, offset %d\\n\", i,\n+\t\t\t\t\tmsblk->meta_index[i].offset);\n+\t\t\tmeta = &msblk->meta_index[i];\n+\t\t\toffset = meta->offset;\n+\t\t}\n+\t}\n+\n+\tif (meta)\n+\t\tmeta->locked = 1;\n+\n+not_allocated:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\n+\treturn meta;\n+}\n+\n+\n+static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct meta_index *meta = NULL;\n+\tint i;\n+\n+\tmutex_lock(&msblk->meta_index_mutex);\n+\n+\tTRACE(\"empty_meta_index: offset %d, skip %d\\n\", offset, skip);\n+\n+\tif (msblk->meta_index == NULL) {\n+\t\tmsblk->meta_index = kmalloc(sizeof(struct meta_index) *\n+\t\t\t\t\tSQUASHFS_META_NUMBER, GFP_KERNEL);\n+\t\tif (msblk->meta_index == NULL) {\n+\t\t\tERROR(\"Failed to allocate meta_index\\n\");\n+\t\t\tgoto failed;\n+\t\t}\n+\t\tfor (i = 0; i < SQUASHFS_META_NUMBER; i++) {\n+\t\t\tmsblk->meta_index[i].inode_number = 0;\n+\t\t\tmsblk->meta_index[i].locked = 0;\n+\t\t}\n+\t\tmsblk->next_meta_index = 0;\n+\t}\n+\n+\tfor (i = SQUASHFS_META_NUMBER; i &&\n+\t\t\tmsblk->meta_index[msblk->next_meta_index].locked; i --)\n+\t\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tif (i == 0) {\n+\t\tTRACE(\"empty_meta_index: failed!\\n\");\n+\t\tgoto failed;\n+\t}\n+\n+\tTRACE(\"empty_meta_index: returned meta entry %d, %p\\n\",\n+\t\t\tmsblk->next_meta_index,\n+\t\t\t&msblk->meta_index[msblk->next_meta_index]);\n+\n+\tmeta = &msblk->meta_index[msblk->next_meta_index];\n+\tmsblk->next_meta_index = (msblk->next_meta_index + 1) %\n+\t\t\tSQUASHFS_META_NUMBER;\n+\n+\tmeta->inode_number = inode->i_ino;\n+\tmeta->offset = offset;\n+\tmeta->skip = skip;\n+\tmeta->entries = 0;\n+\tmeta->locked = 1;\n+\n+failed:\n+\tmutex_unlock(&msblk->meta_index_mutex);\n+\treturn meta;\n+}\n+\n+\n+static void release_meta_index(struct inode *inode, struct meta_index *meta)\n+{\n+\tmeta->locked = 0;\n+\tsmp_mb();\n+}\n+\n+\n+static int read_block_index(struct super_block *s, int blocks, char *block_list,\n+\t\t\t\tlong long *start_block, int *offset)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tunsigned int *block_listp;\n+\tint block = 0;\n+\t\n+\tif (msblk->swap) {\n+\t\tchar sblock_list[blocks << 2];\n+\n+\t\tif (!squashfs_get_cached_block(s, sblock_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t\tSQUASHFS_SWAP_INTS(((unsigned int *)block_list),\n+\t\t\t\t((unsigned int *)sblock_list), blocks);\n+\t} else {\n+\t\tif (!squashfs_get_cached_block(s, block_list, *start_block,\n+\t\t\t\t*offset, blocks << 2, start_block, offset)) {\n+\t\t\tERROR(\"Fail reading block list [%llx:%x]\\n\", *start_block, *offset);\n+\t\t\tgoto failure;\n+\t\t}\n+\t}\n+\n+\tfor (block_listp = (unsigned int *) block_list; blocks;\n+\t\t\t\tblock_listp++, blocks --)\n+\t\tblock += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);\n+\n+\treturn block;\n+\n+failure:\n+\treturn -1;\n+}\n+\n+\n+#define SIZE 256\n+\n+static inline int calculate_skip(int blocks) {\n+\tint skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);\n+\treturn skip >= 7 ? 7 : skip + 1;\n+}\n+\n+\n+static int get_meta_index(struct inode *inode, int index,\n+\t\tlong long *index_block, int *index_offset,\n+\t\tlong long *data_block, char *block_list)\n+{\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint skip = calculate_skip(i_size_read(inode) >> sblk->block_log);\n+\tint offset = 0;\n+\tstruct meta_index *meta;\n+\tstruct meta_entry *meta_entry;\n+\tlong long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;\n+\tint cur_offset = SQUASHFS_I(inode)->offset;\n+\tlong long cur_data_block = SQUASHFS_I(inode)->start_block;\n+\tint i;\n+ \n+\tindex /= SQUASHFS_META_INDEXES * skip;\n+\n+\twhile (offset < index) {\n+\t\tmeta = locate_meta_index(inode, index, offset + 1);\n+\n+\t\tif (meta == NULL) {\n+\t\t\tmeta = empty_meta_index(inode, offset + 1, skip);\n+\t\t\tif (meta == NULL)\n+\t\t\t\tgoto all_done;\n+\t\t} else {\n+\t\t\tif(meta->entries == 0)\n+\t\t\t\tgoto failed;\n+\t\t\t/* XXX */\n+\t\t\toffset = index < meta->offset + meta->entries ? index :\n+\t\t\t\tmeta->offset + meta->entries - 1;\n+\t\t\t/* XXX */\n+\t\t\tmeta_entry = &meta->meta_entry[offset - meta->offset];\n+\t\t\tcur_index_block = meta_entry->index_block + sblk->inode_table_start;\n+\t\t\tcur_offset = meta_entry->offset;\n+\t\t\tcur_data_block = meta_entry->data_block;\n+\t\t\tTRACE(\"get_meta_index: offset %d, meta->offset %d, \"\n+\t\t\t\t\"meta->entries %d\\n\", offset, meta->offset, meta->entries);\n+\t\t\tTRACE(\"get_meta_index: index_block 0x%llx, offset 0x%x\"\n+\t\t\t\t\" data_block 0x%llx\\n\", cur_index_block,\n+\t\t\t\tcur_offset, cur_data_block);\n+\t\t}\n+\n+\t\tfor (i = meta->offset + meta->entries; i <= index &&\n+\t\t\t\ti < meta->offset + SQUASHFS_META_ENTRIES; i++) {\n+\t\t\tint blocks = skip * SQUASHFS_META_INDEXES;\n+\n+\t\t\twhile (blocks) {\n+\t\t\t\tint block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;\n+\t\t\t\tint res = read_block_index(inode->i_sb, block, block_list,\n+\t\t\t\t\t&cur_index_block, &cur_offset);\n+\n+\t\t\t\tif (res == -1)\n+\t\t\t\t\tgoto failed;\n+\n+\t\t\t\tcur_data_block += res;\n+\t\t\t\tblocks -= block;\n+\t\t\t}\n+\n+\t\t\tmeta_entry = &meta->meta_entry[i - meta->offset];\n+\t\t\tmeta_entry->index_block = cur_index_block - sblk->inode_table_start;\n+\t\t\tmeta_entry->offset = cur_offset;\n+\t\t\tmeta_entry->data_block = cur_data_block;\n+\t\t\tmeta->entries ++;\n+\t\t\toffset ++;\n+\t\t}\n+\n+\t\tTRACE(\"get_meta_index: meta->offset %d, meta->entries %d\\n\",\n+\t\t\t\tmeta->offset, meta->entries);\n+\n+\t\trelease_meta_index(inode, meta);\n+\t}\n+\n+all_done:\n+\t*index_block = cur_index_block;\n+\t*index_offset = cur_offset;\n+\t*data_block = cur_data_block;\n+\n+\treturn offset * SQUASHFS_META_INDEXES * skip;\n+\n+failed:\n+\trelease_meta_index(inode, meta);\n+\treturn -1;\n+}\n+\n+\n+static long long read_blocklist(struct inode *inode, int index,\n+\t\t\t\tint readahead_blks, char *block_list,\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize)\n+{\n+\tlong long block_ptr;\n+\tint offset;\n+\tlong long block;\n+\tint res = get_meta_index(inode, index, &block_ptr, &offset, &block,\n+\t\tblock_list);\n+\n+\tTRACE(\"read_blocklist: res %d, index %d, block_ptr 0x%llx, offset\"\n+\t\t       \" 0x%x, block 0x%llx\\n\", res, index, block_ptr, offset, block);\n+\n+\tif(res == -1)\n+\t\tgoto failure;\n+\n+\tindex -= res;\n+\n+\twhile (index) {\n+\t\tint blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;\n+\t\tint res = read_block_index(inode->i_sb, blocks, block_list,\n+\t\t\t&block_ptr, &offset);\n+\t\tif (res == -1)\n+\t\t\tgoto failure;\n+\t\tblock += res;\n+\t\tindex -= blocks;\n+\t}\n+\n+\tif (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)\n+\t\tgoto failure;\n+\t*bsize = *((unsigned int *) block_list);\n+\n+\treturn block;\n+\n+failure:\n+\treturn 0;\n+}\n+\n+\n+static int squashfs_readpage(struct file *file, struct page *page)\n+{\n+\tstruct inode *inode = page->mapping->host;\n+\tstruct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned char *block_list = NULL;\n+\tlong long block;\n+\tunsigned int bsize, i;\n+\tint bytes;\n+\tint index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);\n+ \tvoid *pageaddr;\n+\tstruct squashfs_cache_entry *fragment = NULL;\n+\tchar *data_ptr = msblk->read_page;\n+\t\n+\tint mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;\n+\tint start_index = page->index & ~mask;\n+\tint end_index = start_index | mask;\n+\tint file_end = i_size_read(inode) >> sblk->block_log;\n+\tint sparse = 0;\n+\n+\tTRACE(\"Entered squashfs_readpage, page index %lx, start block %llx\\n\",\n+\t\t\t\t\tpage->index, SQUASHFS_I(inode)->start_block);\n+\n+\tif (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>\n+\t\t\t\t\tPAGE_CACHE_SHIFT))\n+\t\tgoto out;\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tblock_list = kmalloc(SIZE, GFP_KERNEL);\n+\t\tif (block_list == NULL) {\n+\t\t\tERROR(\"Failed to allocate block_list\\n\");\n+\t\t\tgoto error_out;\n+\t\t}\n+\n+\t\tblock = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);\n+\t\tif (block == 0)\n+\t\t\tgoto error_out;\n+\n+\t\tif (bsize == 0) { /* hole */\n+\t\t\tbytes = index == file_end ?\n+\t\t\t\t(i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;\n+\t\t\tsparse = 1;\n+\t\t} else {\n+\t\t\tmutex_lock(&msblk->read_page_mutex);\n+\t\t\n+\t\t\tbytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,\n+\t\t\t\tbsize, NULL, sblk->block_size);\n+\n+\t\t\tif (bytes == 0) {\n+\t\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\", block, bsize);\n+\t\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\t\t\tgoto error_out;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfragment = get_cached_fragment(inode->i_sb,\n+\t\t\t\t\tSQUASHFS_I(inode)-> u.s1.fragment_start_block,\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_size);\n+\n+\t\tif (fragment->error) {\n+\t\t\tERROR(\"Unable to read page, block %llx, size %x\\n\",\n+\t\t\t\t\tSQUASHFS_I(inode)->u.s1.fragment_start_block,\n+\t\t\t\t\t(int) SQUASHFS_I(inode)->u.s1.fragment_size);\n+\t\t\trelease_cached_fragment(msblk, fragment);\n+\t\t\tgoto error_out;\n+\t\t}\n+\t\tbytes = i_size_read(inode) & (sblk->block_size - 1);\n+\t\tdata_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;\n+\t}\n+\n+\tfor (i = start_index; i <= end_index && bytes > 0; i++,\n+\t\t\t\t\t\tbytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {\n+\t\tstruct page *push_page;\n+\t\tint avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);\n+\n+\t\tTRACE(\"bytes %d, i %d, available_bytes %d\\n\", bytes, i, avail);\n+\n+\t\tpush_page = (i == page->index) ? page :\n+\t\t\tgrab_cache_page_nowait(page->mapping, i);\n+\n+\t\tif (!push_page)\n+\t\t\tcontinue;\n+\n+\t\tif (PageUptodate(push_page))\n+\t\t\tgoto skip_page;\n+\n+ \t\tpageaddr = kmap_atomic(push_page, KM_USER0);\n+\t\tmemcpy(pageaddr, data_ptr, avail);\n+\t\tmemset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);\n+\t\tkunmap_atomic(pageaddr, KM_USER0);\n+\t\tflush_dcache_page(push_page);\n+\t\tSetPageUptodate(push_page);\n+skip_page:\n+\t\tunlock_page(push_page);\n+\t\tif(i != page->index)\n+\t\t\tpage_cache_release(push_page);\n+\t}\n+\n+\tif (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK\n+\t\t\t\t\t|| index < file_end) {\n+\t\tif (!sparse)\n+\t\t\tmutex_unlock(&msblk->read_page_mutex);\n+\t\tkfree(block_list);\n+\t} else\n+\t\trelease_cached_fragment(msblk, fragment);\n+\n+\treturn 0;\n+\n+error_out:\n+\tSetPageError(page);\n+out:\n+\tpageaddr = kmap_atomic(page, KM_USER0);\n+\tmemset(pageaddr, 0, PAGE_CACHE_SIZE);\n+\tkunmap_atomic(pageaddr, KM_USER0);\n+\tflush_dcache_page(page);\n+\tif (!PageError(page))\n+\t\tSetPageUptodate(page);\n+\tunlock_page(page);\n+\n+\tkfree(block_list);\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tf_pos -= 3;\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, &index, index_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start, &index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start, &index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length + 3;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s,\n+\t\t\t\tlong long *next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start, unsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tstr = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);\n+\tif (str == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index sindex;\n+\t\t\tsquashfs_get_cached_block(s, &sindex, index_start, index_offset,\n+\t\t\t\tsizeof(sindex), &index_start, &index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, index, index_start, index_offset,\n+\t\t\t\tsizeof(struct squashfs_dir_index), &index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start, index_offset,\n+\t\t\t\t\tindex->size + 1, &index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+\n+failure:\n+\treturn length + 3;\n+}\n+\n+\t\t\n+static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\twhile(file->f_pos < 3) {\n+\t\tchar *name;\n+\t\tint size, i_ino;\n+\n+\t\tif(file->f_pos == 0) {\n+\t\t\tname = \".\";\n+\t\t\tsize = 1;\n+\t\t\ti_ino = i->i_ino;\n+\t\t} else {\n+\t\t\tname = \"..\";\n+\t\t\tsize = 2;\n+\t\t\ti_ino = SQUASHFS_I(i)->u.s2.parent_inode;\n+\t\t}\n+\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %d, %d)\\n\",\n+\t\t\t\t(unsigned int) dirent, name, size, (int)\n+\t\t\t\tfile->f_pos, i_ino, squashfs_filetype_table[1]);\n+\n+\t\tif (filldir(dirent, name, size, file->f_pos, i_ino,\n+\t\t\t\tsquashfs_filetype_table[1]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\tgoto finish;\n+\t\t}\n+\t\tfile->f_pos += size;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name, dire->size + 1,\n+\t\t\t\t\t(int) file->f_pos, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1, file->f_pos,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]) < 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;\n+\tstruct squashfs_dir_header dirh;\n+\tstruct squashfs_dir_entry *dire;\n+\n+\tTRACE(\"Entered squashfs_lookup [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tdire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL);\n+\tif (dire == NULL) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_lookup;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_lookup;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name, len);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,\n+\t\t\t\t\t next_offset, sizeof(sdirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,\n+\t\t\t\t\tnext_offset, sizeof(dirh), &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(sdire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire, next_block,\n+\t\t\t\t\t\tnext_offset, sizeof(*dire), &next_block, &next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,\n+\t\t\t\t\tnext_offset, dire->size + 1, &next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (name[0] < dire->name[0])\n+\t\t\t\tgoto exit_lookup;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory entry %s, inode\"\n+\t\t\t\t\t\"  %x:%x, %d\\n\", name, dirh.start_block, dire->offset,\n+\t\t\t\t\tdirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);\n+\n+\t\t\t\tgoto exit_lookup;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_lookup:\n+\tkfree(dire);\n+\tif (inode)\n+\t\treturn d_splice_alias(inode, dentry);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_lookup;\n+}\n+\n+\n+static int squashfs_remount(struct super_block *s, int *flags, char *data)\n+{\n+\t*flags |= MS_RDONLY;\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_put_super(struct super_block *s)\n+{\n+\tif (s->s_fs_info) {\n+\t\tstruct squashfs_sb_info *sbi = s->s_fs_info;\n+\t\tsquashfs_cache_delete(sbi->block_cache);\n+\t\tsquashfs_cache_delete(sbi->fragment_cache);\n+\t\tvfree(sbi->read_page);\n+\t\tkfree(sbi->uid);\n+\t\tkfree(sbi->fragment_index);\n+\t\tkfree(sbi->fragment_index_2);\n+\t\tkfree(sbi->meta_index);\n+\t\tvfree(sbi->stream.workspace);\n+\t\tkfree(s->s_fs_info);\n+\t\ts->s_fs_info = NULL;\n+\t}\n+}\n+\n+\n+static int squashfs_get_sb(struct file_system_type *fs_type, int flags,\n+\t\t\t\tconst char *dev_name, void *data, struct vfsmount *mnt)\n+{\n+\treturn get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,\n+\t\t\t\tmnt);\n+}\n+\n+\n+static int __init init_squashfs_fs(void)\n+{\n+\tint err = init_inodecache();\n+\tif (err)\n+\t\tgoto out;\n+\n+\tprintk(KERN_INFO \"squashfs: version 3.4 (2008/08/26) \"\n+\t\t\"Phillip Lougher\\n\");\n+\n+\terr = register_filesystem(&squashfs_fs_type);\n+\tif (err)\n+\t\tdestroy_inodecache();\n+\n+out:\n+\treturn err;\n+}\n+\n+\n+static void __exit exit_squashfs_fs(void)\n+{\n+\tunregister_filesystem(&squashfs_fs_type);\n+\tdestroy_inodecache();\n+}\n+\n+\n+static struct kmem_cache * squashfs_inode_cachep;\n+\n+\n+static struct inode *squashfs_alloc_inode(struct super_block *sb)\n+{\n+\tstruct squashfs_inode_info *ei;\n+\tei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);\n+\treturn ei ? &ei->vfs_inode : NULL;\n+}\n+\n+\n+static void squashfs_destroy_inode(struct inode *inode)\n+{\n+\tkmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));\n+}\n+\n+\n+static void init_once(void *foo)\n+{\n+\tstruct squashfs_inode_info *ei = foo;\n+\n+\tinode_init_once(&ei->vfs_inode);\n+}\n+ \n+\n+static int __init init_inodecache(void)\n+{\n+\tsquashfs_inode_cachep = kmem_cache_create(\"squashfs_inode_cache\",\n+\t    sizeof(struct squashfs_inode_info), 0,\n+\t\tSLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);\n+\tif (squashfs_inode_cachep == NULL)\n+\t\treturn -ENOMEM;\n+\treturn 0;\n+}\n+\n+\n+static void destroy_inodecache(void)\n+{\n+\tkmem_cache_destroy(squashfs_inode_cachep);\n+}\n+\n+\n+module_init(init_squashfs_fs);\n+module_exit(exit_squashfs_fs);\n+MODULE_DESCRIPTION(\"squashfs 3.4, a compressed read-only filesystem\");\n+MODULE_AUTHOR(\"Phillip Lougher <phillip@lougher.demon.co.uk>\");\n+MODULE_LICENSE(\"GPL\");\ndiff -x .gitignore -Nurp linux-2.6.27-rc4-next/fs/squashfs/Makefile linux-2.6.27-rc4-next-squashfs3.4/fs/squashfs/Makefile\n--- linux-2.6.27-rc4-next/fs/squashfs/Makefile\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/fs/squashfs/Makefile\t2008-08-20 04:15:06.000000000 +0100\n@@ -0,0 +1,7 @@\n+#\n+# Makefile for the linux squashfs routines.\n+#\n+\n+obj-$(CONFIG_SQUASHFS) += squashfs.o\n+squashfs-y += inode.o\n+squashfs-y += squashfs2_0.o\ndiff -x .gitignore -Nurp linux-2.6.27-rc4-next/fs/squashfs/squashfs2_0.c linux-2.6.27-rc4-next-squashfs3.4/fs/squashfs/squashfs2_0.c\n--- linux-2.6.27-rc4-next/fs/squashfs/squashfs2_0.c\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/fs/squashfs/squashfs2_0.c\t2008-08-20 04:15:06.000000000 +0100\n@@ -0,0 +1,740 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs2_0.c\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+#include <linux/module.h>\n+#include <linux/zlib.h>\n+#include <linux/fs.h>\n+#include <linux/squashfs_fs_sb.h>\n+#include <linux/squashfs_fs_i.h>\n+\n+#include \"squashfs.h\"\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);\n+static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,\n+\t\t\t\tstruct nameidata *);\n+\n+static struct file_operations squashfs_dir_ops_2 = {\n+\t.read = generic_read_dir,\n+\t.readdir = squashfs_readdir_2\n+};\n+\n+static struct inode_operations squashfs_dir_inode_ops_2 = {\n+\t.lookup = squashfs_lookup_2\n+};\n+\n+static unsigned char squashfs_filetype_table[] = {\n+\tDT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK\n+};\n+\n+static int read_fragment_index_table_2(struct super_block *s)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tif (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments), GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate uid/gid table\\n\");\n+\t\treturn 0;\n+\t}\n+   \n+\tif (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&\n+\t\t\t\t\t!squashfs_read_data(s, (char *)\n+\t\t\t\t\tmsblk->fragment_index_2,\n+\t\t\t\t\tsblk->fragment_table_start,\n+\t\t\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2\n+\t\t\t\t\t(sblk->fragments) |\n+\t\t\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {\n+\t\tERROR(\"unable to read fragment index table\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tif (msblk->swap) {\n+\t\tint i;\n+\t\tunsigned int fragment;\n+\n+\t\tfor (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);\n+\t\t\t\t\t\t\t\t\ti++) {\n+\t\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),\n+\t\t\t\t\t\t&msblk->fragment_index_2[i], 1);\n+\t\t\tmsblk->fragment_index_2[i] = fragment;\n+\t\t}\n+\t}\n+\n+\treturn 1;\n+}\n+\n+\n+static int get_fragment_location_2(struct super_block *s, unsigned int fragment,\n+\t\t\t\tlong long *fragment_start_block,\n+\t\t\t\tunsigned int *fragment_size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tlong long start_block =\n+\t\tmsblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];\n+\tint offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);\n+\tstruct squashfs_fragment_entry_2 fragment_entry;\n+\n+\tif (msblk->swap) {\n+\t\tstruct squashfs_fragment_entry_2 sfragment_entry;\n+\n+\t\tif (!squashfs_get_cached_block(s, (char *) &sfragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(sfragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) &fragment_entry,\n+\t\t\t\t\tstart_block, offset,\n+\t\t\t\t\tsizeof(fragment_entry), &start_block,\n+\t\t\t\t\t&offset))\n+\t\t\tgoto out;\n+\n+\t*fragment_start_block = fragment_entry.start_block;\n+\t*fragment_size = fragment_entry.size;\n+\n+\treturn 1;\n+\n+out:\n+\treturn 0;\n+}\n+\n+\n+static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,\n+\t\tstruct squashfs_base_inode_header_2 *inodeb, unsigned int ino)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\ti->i_ino = ino;\n+\ti->i_mtime.tv_sec = sblk->mkfs_time;\n+\ti->i_atime.tv_sec = sblk->mkfs_time;\n+\ti->i_ctime.tv_sec = sblk->mkfs_time;\n+\ti->i_uid = msblk->uid[inodeb->uid];\n+\ti->i_mode = inodeb->mode;\n+\ti->i_nlink = 1;\n+\ti->i_size = 0;\n+\tif (inodeb->guid == SQUASHFS_GUIDS)\n+\t\ti->i_gid = i->i_uid;\n+\telse\n+\t\ti->i_gid = msblk->guid[inodeb->guid];\n+}\n+\n+\n+static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)\n+{\n+\tstruct super_block *s = i->i_sb;\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tunsigned int block = SQUASHFS_INODE_BLK(inode) +\n+\t\tsblk->inode_table_start;\n+\tunsigned int offset = SQUASHFS_INODE_OFFSET(inode);\n+\tunsigned int ino = SQUASHFS_MK_VFS_INODE(block -\n+\t\tsblk->inode_table_start, offset);\n+\tlong long next_block;\n+\tunsigned int next_offset;\n+\tunion squashfs_inode_header_2 id, sid;\n+\tstruct squashfs_base_inode_header_2 *inodeb = &id.base,\n+\t\t\t\t\t  *sinodeb = &sid.base;\n+\n+\tTRACE(\"Entered squashfs_read_inode_2\\n\");\n+\n+\tif (msblk->swap) {\n+\t\tif (!squashfs_get_cached_block(s, (char *) sinodeb, block,\n+\t\t\t\t\toffset, sizeof(*sinodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,\n+\t\t\t\t\tsizeof(*sinodeb));\n+\t} else\n+\t\tif (!squashfs_get_cached_block(s, (char *) inodeb, block,\n+\t\t\t\t\toffset, sizeof(*inodeb), &next_block,\n+\t\t\t\t\t&next_offset))\n+\t\t\tgoto failed_read;\n+\n+\tsquashfs_new_inode(msblk, i, inodeb, ino);\n+\n+\tswitch(inodeb->inode_type) {\n+\t\tcase SQUASHFS_FILE_TYPE: {\n+\t\t\tstruct squashfs_reg_inode_header_2 *inodep = &id.reg;\n+\t\t\tstruct squashfs_reg_inode_header_2 *sinodep = &sid.reg;\n+\t\t\tlong long frag_blk;\n+\t\t\tunsigned int frag_size = 0;\n+\t\t\t\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\tfrag_blk = SQUASHFS_INVALID_BLK;\n+\t\t\tif (inodep->fragment != SQUASHFS_INVALID_FRAG &&\n+\t\t\t\t\t!get_fragment_location_2(s,\n+\t\t\t\t\tinodep->fragment, &frag_blk, &frag_size))\n+\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_fop = &generic_ro_fops;\n+\t\t\ti->i_mode |= S_IFREG;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\ti->i_blocks = ((i->i_size - 1) >> 9) + 1;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_size = frag_size;\n+\t\t\tSQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->u.s1.block_list_start = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\t\t\ti->i_data.a_ops = &squashfs_aops;\n+\n+\t\t\tTRACE(\"File inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"block_list_start %llx, offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, next_block,\n+\t\t\t\t\tnext_offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_DIR_TYPE: {\n+\t\t\tstruct squashfs_dir_inode_header_2 *inodep = &id.dir;\n+\t\t\tstruct squashfs_dir_inode_header_2 *sinodep = &sid.dir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count = 0;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Directory inode %x:%x, start_block %x, offset \"\n+\t\t\t\t\t\"%x\\n\", SQUASHFS_INODE_BLK(inode),\n+\t\t\t\t\toffset, inodep->start_block,\n+\t\t\t\t\tinodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_LDIR_TYPE: {\n+\t\t\tstruct squashfs_ldir_inode_header_2 *inodep = &id.ldir;\n+\t\t\tstruct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->file_size;\n+\t\t\ti->i_op = &squashfs_dir_inode_ops_2;\n+\t\t\ti->i_fop = &squashfs_dir_ops_2;\n+\t\t\ti->i_mode |= S_IFDIR;\n+\t\t\ti->i_mtime.tv_sec = inodep->mtime;\n+\t\t\ti->i_atime.tv_sec = inodep->mtime;\n+\t\t\ti->i_ctime.tv_sec = inodep->mtime;\n+\t\t\tSQUASHFS_I(i)->start_block = inodep->start_block;\n+\t\t\tSQUASHFS_I(i)->offset = inodep->offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start = next_block;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset =\n+\t\t\t\t\t\t\t\tnext_offset;\n+\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count =\n+\t\t\t\t\t\t\t\tinodep->i_count;\n+\t\t\tSQUASHFS_I(i)->u.s2.parent_inode = 0;\n+\n+\t\t\tTRACE(\"Long directory inode %x:%x, start_block %x, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->start_block, inodep->offset);\n+\t\t\tbreak;\n+\t\t}\n+\t\tcase SQUASHFS_SYMLINK_TYPE: {\n+\t\t\tstruct squashfs_symlink_inode_header_2 *inodep =\n+\t\t\t\t\t\t\t\t&id.symlink;\n+\t\t\tstruct squashfs_symlink_inode_header_2 *sinodep =\n+\t\t\t\t\t\t\t\t&sid.symlink;\n+\t\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n+\t\t\t\t\t\t\t\tsinodep);\n+\t\t\t} else\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_size = inodep->symlink_size;\n+\t\t\ti->i_op = &page_symlink_inode_operations;\n+\t\t\ti->i_data.a_ops = &squashfs_symlink_aops;\n+\t\t\ti->i_mode |= S_IFLNK;\n+\t\t\tSQUASHFS_I(i)->start_block = next_block;\n+\t\t\tSQUASHFS_I(i)->offset = next_offset;\n+\n+\t\t\tTRACE(\"Symbolic link inode %x:%x, start_block %llx, \"\n+\t\t\t\t\t\"offset %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tnext_block, next_offset);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_BLKDEV_TYPE:\n+\t\t case SQUASHFS_CHRDEV_TYPE: {\n+\t\t\tstruct squashfs_dev_inode_header_2 *inodep = &id.dev;\n+\t\t\tstruct squashfs_dev_inode_header_2 *sinodep = &sid.dev;\n+\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tsinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*sinodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);\n+\t\t\t} else\t\n+\t\t\t\tif (!squashfs_get_cached_block(s, (char *)\n+\t\t\t\t\t\tinodep, block, offset,\n+\t\t\t\t\t\tsizeof(*inodep), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type ==\n+\t\t\t\t\tSQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :\n+\t\t\t\t\tS_IFBLK;\n+\t\t\tinit_special_inode(i, i->i_mode,\n+\t\t\t\t\told_decode_dev(inodep->rdev));\n+\n+\t\t\tTRACE(\"Device inode %x:%x, rdev %x\\n\",\n+\t\t\t\t\tSQUASHFS_INODE_BLK(inode), offset,\n+\t\t\t\t\tinodep->rdev);\n+\t\t\tbreak;\n+\t\t }\n+\t\t case SQUASHFS_FIFO_TYPE:\n+\t\t case SQUASHFS_SOCKET_TYPE: {\n+\n+\t\t\ti->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)\n+\t\t\t\t\t\t\t? S_IFIFO : S_IFSOCK;\n+\t\t\tinit_special_inode(i, i->i_mode, 0);\n+\t\t\tbreak;\n+\t\t }\n+\t\t default:\n+\t\t\tERROR(\"Unknown inode type %d in squashfs_iget!\\n\",\n+\t\t\t\t\tinodeb->inode_type);\n+\t\t\tgoto failed_read1;\n+\t}\n+\t\n+\treturn 1;\n+\n+failed_read:\n+\tERROR(\"Unable to read inode [%x:%x]\\n\", block, offset);\n+\n+failed_read1:\n+\treturn 0;\n+}\n+\n+\n+static int get_dir_index_using_offset(struct super_block *s, long long \n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tlong long f_pos)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 index;\n+\n+\tTRACE(\"Entered get_dir_index_using_offset, i_count %d, f_pos %d\\n\",\n+\t\t\t\t\ti_count, (unsigned int) f_pos);\n+\n+\tif (f_pos == 0)\n+\t\tgoto finish;\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) &index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(index), &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tif (index.index > f_pos)\n+\t\t\tbreak;\n+\n+\t\tsquashfs_get_cached_block(s, NULL, index_start, index_offset,\n+\t\t\t\t\tindex.size + 1, &index_start,\n+\t\t\t\t\t&index_offset);\n+\n+\t\tlength = index.index;\n+\t\t*next_block = index.start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\n+finish:\n+\treturn length;\n+}\n+\n+\n+static int get_dir_index_using_name(struct super_block *s, long long\n+\t\t\t\t*next_block, unsigned int *next_offset,\n+\t\t\t\tlong long index_start,\n+\t\t\t\tunsigned int index_offset, int i_count,\n+\t\t\t\tconst char *name, int size)\n+{\n+\tstruct squashfs_sb_info *msblk = s->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tint i, length = 0;\n+\tstruct squashfs_dir_index_2 *index;\n+\tchar *str;\n+\n+\tTRACE(\"Entered get_dir_index_using_name, i_count %d\\n\", i_count);\n+\n+\tif (!(str = kmalloc(sizeof(struct squashfs_dir_index) +\n+\t\t(SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_index\\n\");\n+\t\tgoto failure;\n+\t}\n+\n+\tindex = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);\n+\tstrncpy(str, name, size);\n+\tstr[size] = '\\0';\n+\n+\tfor (i = 0; i < i_count; i++) {\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_index_2 sindex;\n+\t\t\tsquashfs_get_cached_block(s, (char *) &sindex,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(sindex), &index_start,\n+\t\t\t\t\t&index_offset);\n+\t\t\tSQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);\n+\t\t} else\n+\t\t\tsquashfs_get_cached_block(s, (char *) index,\n+\t\t\t\t\tindex_start, index_offset,\n+\t\t\t\t\tsizeof(struct squashfs_dir_index_2),\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tsquashfs_get_cached_block(s, index->name, index_start,\n+\t\t\t\t\tindex_offset, index->size + 1,\n+\t\t\t\t\t&index_start, &index_offset);\n+\n+\t\tindex->name[index->size + 1] = '\\0';\n+\n+\t\tif (strcmp(index->name, str) > 0)\n+\t\t\tbreak;\n+\n+\t\tlength = index->index;\n+\t\t*next_block = index->start_block + sblk->directory_table_start;\n+\t}\n+\n+\t*next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;\n+\tkfree(str);\n+failure:\n+\treturn length;\n+}\n+\n+\t\t\n+static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)\n+{\n+\tstruct inode *i = file->f_dentry->d_inode;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\n+\tTRACE(\"Entered squashfs_readdir_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto finish;\n+\t}\n+\n+\tlength = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count,\n+\t\t\t\tfile->f_pos);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\t\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block, next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\t\tnext_block, next_offset,\n+\t\t\t\t\t\tdire->size + 1, &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (file->f_pos >= length)\n+\t\t\t\tcontinue;\n+\n+\t\t\tdire->name[dire->size + 1] = '\\0';\n+\n+\t\t\tTRACE(\"Calling filldir(%x, %s, %d, %d, %x:%x, %d)\\n\",\n+\t\t\t\t\t(unsigned int) dirent, dire->name,\n+\t\t\t\t\tdire->size + 1, (int) file->f_pos,\n+\t\t\t\t\tdirh.start_block, dire->offset,\n+\t\t\t\t\tsquashfs_filetype_table[dire->type]);\n+\n+\t\t\tif (filldir(dirent, dire->name, dire->size + 1,\n+\t\t\t\t\tfile->f_pos, SQUASHFS_MK_VFS_INODE(\n+\t\t\t\t\tdirh.start_block, dire->offset),\n+\t\t\t\t\tsquashfs_filetype_table[dire->type])\n+\t\t\t\t\t< 0) {\n+\t\t\t\tTRACE(\"Filldir returned less than 0\\n\");\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\t\t\tfile->f_pos = length;\n+\t\t}\n+\t}\n+\n+finish:\n+\tkfree(dire);\n+\treturn 0;\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tkfree(dire);\n+\treturn 0;\n+}\n+\n+\n+static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,\n+\t\t\t\tstruct nameidata *nd)\n+{\n+\tconst unsigned char *name = dentry->d_name.name;\n+\tint len = dentry->d_name.len;\n+\tstruct inode *inode = NULL;\n+\tstruct squashfs_sb_info *msblk = i->i_sb->s_fs_info;\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\tlong long next_block = SQUASHFS_I(i)->start_block +\n+\t\t\t\tsblk->directory_table_start;\n+\tint next_offset = SQUASHFS_I(i)->offset, length = 0,\n+\t\t\t\tdir_count;\n+\tstruct squashfs_dir_header_2 dirh;\n+\tstruct squashfs_dir_entry_2 *dire;\n+\tint sorted = sblk->s_major == 2 && sblk->s_minor >= 1;\n+\n+\tTRACE(\"Entered squashfs_lookup_2 [%llx:%x]\\n\", next_block, next_offset);\n+\n+\tif (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +\n+\t\tSQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {\n+\t\tERROR(\"Failed to allocate squashfs_dir_entry\\n\");\n+\t\tgoto exit_loop;\n+\t}\n+\n+\tif (len > SQUASHFS_NAME_LEN)\n+\t\tgoto exit_loop;\n+\n+\tlength = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_start,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_offset,\n+\t\t\t\tSQUASHFS_I(i)->u.s2.directory_index_count, name,\n+\t\t\t\tlen);\n+\n+\twhile (length < i_size_read(i)) {\n+\t\t/* read directory header */\n+\t\tif (msblk->swap) {\n+\t\t\tstruct squashfs_dir_header_2 sdirh;\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(sdirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(sdirh);\n+\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n+\t\t} else {\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,\n+\t\t\t\t\tnext_block, next_offset, sizeof(dirh),\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += sizeof(dirh);\n+\t\t}\n+\n+\t\tdir_count = dirh.count + 1;\n+\t\twhile (dir_count--) {\n+\t\t\tif (msblk->swap) {\n+\t\t\t\tstruct squashfs_dir_entry_2 sdire;\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\t&sdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(sdire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\t\t\t\t\n+\t\t\t\tlength += sizeof(sdire);\n+\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n+\t\t\t} else {\n+\t\t\t\tif (!squashfs_get_cached_block(i->i_sb, (char *)\n+\t\t\t\t\t\tdire, next_block,next_offset,\n+\t\t\t\t\t\tsizeof(*dire), &next_block,\n+\t\t\t\t\t\t&next_offset))\n+\t\t\t\t\tgoto failed_read;\n+\n+\t\t\t\tlength += sizeof(*dire);\n+\t\t\t}\n+\n+\t\t\tif (!squashfs_get_cached_block(i->i_sb, dire->name,\n+\t\t\t\t\tnext_block, next_offset, dire->size + 1,\n+\t\t\t\t\t&next_block, &next_offset))\n+\t\t\t\tgoto failed_read;\n+\n+\t\t\tlength += dire->size + 1;\n+\n+\t\t\tif (sorted && name[0] < dire->name[0])\n+\t\t\t\tgoto exit_loop;\n+\n+\t\t\tif ((len == dire->size + 1) && !strncmp(name,\n+\t\t\t\t\t\tdire->name, len)) {\n+\t\t\t\tsquashfs_inode_t ino =\n+\t\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\t\t\t\tunsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,\n+\t\t\t\t\tdire->offset);\n+\n+\t\t\t\tTRACE(\"calling squashfs_iget for directory \"\n+\t\t\t\t\t\"entry %s, inode %x:%x, %lld\\n\", name,\n+\t\t\t\t\tdirh.start_block, dire->offset, ino);\n+\n+\t\t\t\tinode = squashfs_iget(i->i_sb, ino, inode_number);\n+\n+\t\t\t\tgoto exit_loop;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+exit_loop:\n+\tkfree(dire);\n+\td_add(dentry, inode);\n+\treturn ERR_PTR(0);\n+\n+failed_read:\n+\tERROR(\"Unable to read directory block [%llx:%x]\\n\", next_block,\n+\t\tnext_offset);\n+\tgoto exit_loop;\n+}\n+\n+\n+int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\tstruct squashfs_super_block *sblk = &msblk->sblk;\n+\n+\tmsblk->read_inode = squashfs_read_inode_2;\n+\tmsblk->read_fragment_index_table = read_fragment_index_table_2;\n+\n+\tsblk->bytes_used = sblk->bytes_used_2;\n+\tsblk->uid_start = sblk->uid_start_2;\n+\tsblk->guid_start = sblk->guid_start_2;\n+\tsblk->inode_table_start = sblk->inode_table_start_2;\n+\tsblk->directory_table_start = sblk->directory_table_start_2;\n+\tsblk->fragment_table_start = sblk->fragment_table_start_2;\n+\n+\treturn 1;\n+}\ndiff -x .gitignore -Nurp linux-2.6.27-rc4-next/fs/squashfs/squashfs.h linux-2.6.27-rc4-next-squashfs3.4/fs/squashfs/squashfs.h\n--- linux-2.6.27-rc4-next/fs/squashfs/squashfs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/fs/squashfs/squashfs.h\t2008-08-20 04:15:06.000000000 +0100\n@@ -0,0 +1,86 @@\n+/*\n+ * Squashfs - a compressed read only filesystem for Linux\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs.h\n+ */\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+#endif\n+\n+#ifdef SQUASHFS_TRACE\n+#define TRACE(s, args...)\tprintk(KERN_NOTICE \"SQUASHFS: \"s, ## args)\n+#else\n+#define TRACE(s, args...)\t{}\n+#endif\n+\n+#define ERROR(s, args...)\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args)\n+\n+#define SERROR(s, args...)\tdo { \\\n+\t\t\t\tif (!silent) \\\n+\t\t\t\tprintk(KERN_ERR \"SQUASHFS error: \"s, ## args);\\\n+\t\t\t\t} while(0)\n+\n+#define WARNING(s, args...)\tprintk(KERN_WARNING \"SQUASHFS: \"s, ## args)\n+\n+static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)\n+{\n+\treturn list_entry(inode, struct squashfs_inode_info, vfs_inode);\n+}\n+\n+#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)\n+#define SQSH_EXTERN\n+extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,\n+\t\t\t\tlong long index, unsigned int length,\n+\t\t\t\tlong long *next_index, int srclength);\n+extern int squashfs_get_cached_block(struct super_block *s, void *buffer,\n+\t\t\t\tlong long block, unsigned int offset,\n+\t\t\t\tint length, long long *next_block,\n+\t\t\t\tunsigned int *next_offset);\n+extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct\n+\t\t\t\t\tsquashfs_cache_entry *fragment);\n+extern struct squashfs_cache_entry *get_cached_fragment(struct super_block\n+\t\t\t\t\t*s, long long start_block,\n+\t\t\t\t\tint length);\n+extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);\n+extern const struct address_space_operations squashfs_symlink_aops;\n+extern const struct address_space_operations squashfs_aops;\n+extern struct inode_operations squashfs_dir_inode_ops;\n+#else\n+#define SQSH_EXTERN static\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);\n+#else\n+static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)\n+{\n+\treturn 0;\n+}\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.27-rc4-next/include/linux/squashfs_fs.h linux-2.6.27-rc4-next-squashfs3.4/include/linux/squashfs_fs.h\n--- linux-2.6.27-rc4-next/include/linux/squashfs_fs.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/include/linux/squashfs_fs.h\t2008-08-20 04:15:06.000000000 +0100\n@@ -0,0 +1,935 @@\n+#ifndef SQUASHFS_FS\n+#define SQUASHFS_FS\n+\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs.h\n+ */\n+\n+#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+#endif\n+\n+#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n+#define SQUASHFS_MAJOR\t\t\t3\n+#define SQUASHFS_MINOR\t\t\t1\n+#define SQUASHFS_MAGIC\t\t\t0x73717368\n+#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n+#define SQUASHFS_START\t\t\t0\n+\n+/* size of metadata (inode and directory) blocks */\n+#define SQUASHFS_METADATA_SIZE\t\t8192\n+#define SQUASHFS_METADATA_LOG\t\t13\n+\n+/* default size of data blocks */\n+#define SQUASHFS_FILE_SIZE\t\t131072\n+#define SQUASHFS_FILE_LOG\t\t17\n+\n+#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n+\n+/* Max number of uids and gids */\n+#define SQUASHFS_UIDS\t\t\t256\n+#define SQUASHFS_GUIDS\t\t\t255\n+\n+/* Max length of filename (not 255) */\n+#define SQUASHFS_NAME_LEN\t\t256\n+\n+#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n+#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n+#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n+#define SQUASHFS_USED_BLK\t\t((long long) -2)\n+\n+/* Filesystem flags */\n+#define SQUASHFS_NOI\t\t\t0\n+#define SQUASHFS_NOD\t\t\t1\n+#define SQUASHFS_CHECK\t\t\t2\n+#define SQUASHFS_NOF\t\t\t3\n+#define SQUASHFS_NO_FRAG\t\t4\n+#define SQUASHFS_ALWAYS_FRAG\t\t5\n+#define SQUASHFS_DUPLICATE\t\t6\n+#define SQUASHFS_EXPORT\t\t\t7\n+\n+#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n+\n+#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOI)\n+\n+#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOD)\n+\n+#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NOF)\n+\n+#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n+\n+#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n+\n+#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n+\n+#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_EXPORT)\n+\n+#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n+\t\t\t\t\t\tSQUASHFS_CHECK)\n+\n+#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n+\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n+\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n+\t\t(duplicate_checking << 6) | (exportable << 7))\n+\n+/* Max number of types and file types */\n+#define SQUASHFS_DIR_TYPE\t\t1\n+#define SQUASHFS_FILE_TYPE\t\t2\n+#define SQUASHFS_SYMLINK_TYPE\t\t3\n+#define SQUASHFS_BLKDEV_TYPE\t\t4\n+#define SQUASHFS_CHRDEV_TYPE\t\t5\n+#define SQUASHFS_FIFO_TYPE\t\t6\n+#define SQUASHFS_SOCKET_TYPE\t\t7\n+#define SQUASHFS_LDIR_TYPE\t\t8\n+#define SQUASHFS_LREG_TYPE\t\t9\n+\n+/* 1.0 filesystem type definitions */\n+#define SQUASHFS_TYPES\t\t\t5\n+#define SQUASHFS_IPC_TYPE\t\t0\n+\n+/* Flag whether block is compressed or uncompressed, bit is set if block is\n+ * uncompressed */\n+#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n+\n+#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n+\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n+\n+#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n+\n+#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n+\n+#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n+\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n+\n+#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n+\n+/*\n+ * Inode number ops.  Inodes consist of a compressed block number, and an\n+ * uncompressed  offset within that block\n+ */\n+#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n+\n+#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n+\n+#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n+\t\t\t\t\t<< 16) + (B)))\n+\n+/* Compute 32 bit VFS inode number from squashfs inode number */\n+#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n+\t\t\t\t\t((b) >> 2) + 1))\n+/* XXX */\n+\n+/* Translate between VFS mode and squashfs mode */\n+#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n+\n+#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n+\t\t\t\t\t\tsizeof(long long))\n+\n+/* inode lookup table defines */\n+#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n+\n+#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n+\t\t\t\t\tsizeof(long long))\n+\n+/* cached data constants for filesystem */\n+#define SQUASHFS_CACHED_BLKS\t\t8\n+\n+#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n+\n+#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n+\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n+\n+#define SQUASHFS_MARKER_BYTE\t\t0xff\n+\n+/* meta index cache */\n+#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n+#define SQUASHFS_META_ENTRIES\t31\n+#define SQUASHFS_META_NUMBER\t8\n+#define SQUASHFS_SLOTS\t\t4\n+\n+struct meta_entry {\n+\tlong long\t\tdata_block;\n+\tunsigned int\t\tindex_block;\n+\tunsigned short\t\toffset;\n+\tunsigned short\t\tpad;\n+};\n+\n+struct meta_index {\n+\tunsigned int\t\tinode_number;\n+\tunsigned int\t\toffset;\n+\tunsigned short\t\tentries;\n+\tunsigned short\t\tskip;\n+\tunsigned short\t\tlocked;\n+\tunsigned short\t\tpad;\n+\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n+};\n+\n+\n+/*\n+ * definitions for structures on disk\n+ */\n+\n+typedef long long\t\tsquashfs_block_t;\n+typedef long long\t\tsquashfs_inode_t;\n+\n+struct squashfs_super_block {\n+\tunsigned int\t\ts_magic;\n+\tunsigned int\t\tinodes;\n+\tunsigned int\t\tbytes_used_2;\n+\tunsigned int\t\tuid_start_2;\n+\tunsigned int\t\tguid_start_2;\n+\tunsigned int\t\tinode_table_start_2;\n+\tunsigned int\t\tdirectory_table_start_2;\n+\tunsigned int\t\ts_major:16;\n+\tunsigned int\t\ts_minor:16;\n+\tunsigned int\t\tblock_size_1:16;\n+\tunsigned int\t\tblock_log:16;\n+\tunsigned int\t\tflags:8;\n+\tunsigned int\t\tno_uids:8;\n+\tunsigned int\t\tno_guids:8;\n+\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n+\tsquashfs_inode_t\troot_inode;\n+\tunsigned int\t\tblock_size;\n+\tunsigned int\t\tfragments;\n+\tunsigned int\t\tfragment_table_start_2;\n+\tlong long\t\tbytes_used;\n+\tlong long\t\tuid_start;\n+\tlong long\t\tguid_start;\n+\tlong long\t\tinode_table_start;\n+\tlong long\t\tdirectory_table_start;\n+\tlong long\t\tfragment_table_start;\n+\tlong long\t\tlookup_table_start;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_index {\n+\tunsigned int\t\tindex;\n+\tunsigned int\t\tstart_block;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n+\tunsigned int\t\tinode_type:4;\t\\\n+\tunsigned int\t\tmode:12;\t\\\n+\tunsigned int\t\tuid:8;\t\t\\\n+\tunsigned int\t\tguid:8;\t\t\\\n+\tunsigned int\t\tmtime;\t\t\\\n+\tunsigned int \t\tinode_number;\n+\n+struct squashfs_base_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_lreg_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tsquashfs_block_t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tlong long\t\tfile_size;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tparent_inode;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header {\n+\tSQUASHFS_BASE_INODE_HEADER;\n+\tunsigned int\t\tnlink;\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\ti_count:16;\n+\tunsigned int\t\tparent_inode;\n+\tstruct squashfs_dir_index\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header {\n+\tstruct squashfs_base_inode_header\tbase;\n+\tstruct squashfs_dev_inode_header\tdev;\n+\tstruct squashfs_symlink_inode_header\tsymlink;\n+\tstruct squashfs_reg_inode_header\treg;\n+\tstruct squashfs_lreg_inode_header\tlreg;\n+\tstruct squashfs_dir_inode_header\tdir;\n+\tstruct squashfs_ldir_inode_header\tldir;\n+\tstruct squashfs_ipc_inode_header\tipc;\n+};\n+\t\n+struct squashfs_dir_entry {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tint\t\t\tinode_number:16;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_header {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tinode_number;\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry {\n+\tlong long\t\tstart_block;\n+\tunsigned int\t\tsize;\n+\tunsigned int\t\tunused;\n+} __attribute__ ((packed));\n+\n+extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\n+extern int squashfs_uncompress_init(void);\n+extern int squashfs_uncompress_exit(void);\n+\n+/*\n+ * macros to convert each packed bitfield structure from little endian to big\n+ * endian and vice versa.  These are needed when creating or using a filesystem\n+ * on a machine with different byte ordering to the target architecture.\n+ *\n+ */\n+\n+#define SQUASHFS_SWAP_START \\\n+\tint bits;\\\n+\tint b_pos;\\\n+\tunsigned long long val;\\\n+\tunsigned char *s;\\\n+\tunsigned char *d;\n+\n+#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n+\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n+\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n+\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n+\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n+\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n+\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n+\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n+\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n+\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n+\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n+\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n+\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n+\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n+\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n+\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n+\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n+\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n+\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n+\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n+\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n+\n+#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 2);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t16)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 4);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t32)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\t64)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n+}\n+\n+#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n+\tint entry;\\\n+\tint bit_position;\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n+\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n+\t\t\tbits)\\\n+\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n+\n+#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n+\n+struct squashfs_base_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\ttype:4;\n+\tunsigned int\t\toffset:4;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_1 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:4; /* index into uid table */\n+\tunsigned int\t\tguid:4; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_1 {\n+\tstruct squashfs_base_inode_header_1\tbase;\n+\tstruct squashfs_dev_inode_header_1\tdev;\n+\tstruct squashfs_symlink_inode_header_1\tsymlink;\n+\tstruct squashfs_reg_inode_header_1\treg;\n+\tstruct squashfs_dir_inode_header_1\tdir;\n+\tstruct squashfs_ipc_inode_header_1\tipc;\n+};\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n+}\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n+}\n+\n+#endif\n+\n+#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n+\n+struct squashfs_dir_index_2 {\n+\tunsigned int\t\tindex:27;\n+\tunsigned int\t\tstart_block:29;\n+\tunsigned char\t\tsize;\n+\tunsigned char\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_base_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_ipc_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+} __attribute__ ((packed));\n+\n+struct squashfs_dev_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\trdev;\n+} __attribute__ ((packed));\n+\t\n+struct squashfs_symlink_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned short\t\tsymlink_size;\n+\tchar\t\t\tsymlink[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_reg_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tfragment;\n+\tunsigned int\t\toffset;\n+\tunsigned int\t\tfile_size:32;\n+\tunsigned short\t\tblock_list[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:19;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__  ((packed));\n+\n+struct squashfs_ldir_inode_header_2 {\n+\tunsigned int\t\tinode_type:4;\n+\tunsigned int\t\tmode:12; /* protection */\n+\tunsigned int\t\tuid:8; /* index into uid table */\n+\tunsigned int\t\tguid:8; /* index into guid table */\n+\tunsigned int\t\tfile_size:27;\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\tmtime;\n+\tunsigned int\t\tstart_block:24;\n+\tunsigned int\t\ti_count:16;\n+\tstruct squashfs_dir_index_2\tindex[0];\n+} __attribute__  ((packed));\n+\n+union squashfs_inode_header_2 {\n+\tstruct squashfs_base_inode_header_2\tbase;\n+\tstruct squashfs_dev_inode_header_2\tdev;\n+\tstruct squashfs_symlink_inode_header_2\tsymlink;\n+\tstruct squashfs_reg_inode_header_2\treg;\n+\tstruct squashfs_dir_inode_header_2\tdir;\n+\tstruct squashfs_ldir_inode_header_2\tldir;\n+\tstruct squashfs_ipc_inode_header_2\tipc;\n+};\n+\t\n+struct squashfs_dir_header_2 {\n+\tunsigned int\t\tcount:8;\n+\tunsigned int\t\tstart_block:24;\n+} __attribute__ ((packed));\n+\n+struct squashfs_dir_entry_2 {\n+\tunsigned int\t\toffset:13;\n+\tunsigned int\t\ttype:3;\n+\tunsigned int\t\tsize:8;\n+\tchar\t\t\tname[0];\n+} __attribute__ ((packed));\n+\n+struct squashfs_fragment_entry_2 {\n+\tunsigned int\t\tstart_block;\n+\tunsigned int\t\tsize;\n+} __attribute__ ((packed));\n+\n+#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+\tSQUASHFS_MEMSET(s, d, n);\\\n+\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n+\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n+\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n+\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n+\n+#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n+}\n+\n+#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n+\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n+\n+#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n+\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n+\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n+\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n+\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n+\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n+\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n+\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n+\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n+}\n+#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n+\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n+}\n+\n+#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n+\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n+\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n+\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n+\tSQUASHFS_SWAP_START\\\n+\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n+\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n+\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n+}\n+\n+#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n+\n+/* fragment and fragment table defines */\n+#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n+\n+#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n+\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n+\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n+\n+#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n+\t\t\t\t\t\tsizeof(int))\n+\n+#endif\n+\n+#ifdef __KERNEL__\n+\n+/*\n+ * macros used to swap each structure entry, taking into account\n+ * bitfields and different bitfield placing conventions on differing\n+ * architectures\n+ */\n+\n+#include <asm/byteorder.h>\n+\n+#ifdef __BIG_ENDIAN\n+\t/* convert from little endian to big endian */\n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, b_pos)\n+#else\n+\t/* convert from big endian to little endian */ \n+#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n+\t\ttbits, 64 - tbits - b_pos)\n+#endif\n+\n+#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n+\tb_pos = pos % 8;\\\n+\tval = 0;\\\n+\ts = (unsigned char *)p + (pos / 8);\\\n+\td = ((unsigned char *) &val) + 7;\\\n+\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n+\t\t*d-- = *s++;\\\n+\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n+}\n+\n+#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n+\n+#endif\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.27-rc4-next/include/linux/squashfs_fs_i.h linux-2.6.27-rc4-next-squashfs3.4/include/linux/squashfs_fs_i.h\n--- linux-2.6.27-rc4-next/include/linux/squashfs_fs_i.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/include/linux/squashfs_fs_i.h\t2008-08-20 04:15:06.000000000 +0100\n@@ -0,0 +1,45 @@\n+#ifndef SQUASHFS_FS_I\n+#define SQUASHFS_FS_I\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_i.h\n+ */\n+\n+struct squashfs_inode_info {\n+\tlong long\tstart_block;\n+\tunsigned int\toffset;\n+\tunion {\n+\t\tstruct {\n+\t\t\tlong long\tfragment_start_block;\n+\t\t\tunsigned int\tfragment_size;\n+\t\t\tunsigned int\tfragment_offset;\n+\t\t\tlong long\tblock_list_start;\n+\t\t} s1;\n+\t\tstruct {\n+\t\t\tlong long\tdirectory_index_start;\n+\t\t\tunsigned int\tdirectory_index_offset;\n+\t\t\tunsigned int\tdirectory_index_count;\n+\t\t\tunsigned int\tparent_inode;\n+\t\t} s2;\n+\t} u;\n+\tstruct inode\tvfs_inode;\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.27-rc4-next/include/linux/squashfs_fs_sb.h linux-2.6.27-rc4-next-squashfs3.4/include/linux/squashfs_fs_sb.h\n--- linux-2.6.27-rc4-next/include/linux/squashfs_fs_sb.h\t1970-01-01 01:00:00.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/include/linux/squashfs_fs_sb.h\t2008-08-20 04:15:06.000000000 +0100\n@@ -0,0 +1,79 @@\n+#ifndef SQUASHFS_FS_SB\n+#define SQUASHFS_FS_SB\n+/*\n+ * Squashfs\n+ *\n+ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n+ * Phillip Lougher <phillip@lougher.demon.co.uk>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2,\n+ * or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n+ *\n+ * squashfs_fs_sb.h\n+ */\n+\n+#include <linux/squashfs_fs.h>\n+\n+struct squashfs_cache_entry {\n+\tlong long\tblock;\n+\tint\t\tlength;\n+\tint\t\tlocked;\n+\tlong long\tnext_index;\n+\tchar\t\tpending;\n+\tchar\t\terror;\n+\tint\t\twaiting;\n+\twait_queue_head_t\twait_queue;\n+\tchar\t\t*data;\n+};\n+\n+struct squashfs_cache {\n+\tchar *name;\n+\tint entries;\n+\tint block_size;\n+\tint next_blk;\n+\tint waiting;\n+\tint unused_blks;\n+\tint use_vmalloc;\n+\tspinlock_t lock;\n+\twait_queue_head_t wait_queue;\n+\tstruct squashfs_cache_entry entry[0];\n+};\n+\n+struct squashfs_sb_info {\n+\tstruct squashfs_super_block\tsblk;\n+\tint\t\t\tdevblksize;\n+\tint\t\t\tdevblksize_log2;\n+\tint\t\t\tswap;\n+\tstruct squashfs_cache\t*block_cache;\n+\tstruct squashfs_cache\t*fragment_cache;\n+\tint\t\t\tnext_meta_index;\n+\tunsigned int\t\t*uid;\n+\tunsigned int\t\t*guid;\n+\tlong long\t\t*fragment_index;\n+\tunsigned int\t\t*fragment_index_2;\n+\tchar\t\t\t*read_page;\n+\tstruct mutex\t\tread_data_mutex;\n+\tstruct mutex\t\tread_page_mutex;\n+\tstruct mutex\t\tmeta_index_mutex;\n+\tstruct meta_index\t*meta_index;\n+\tz_stream\t\tstream;\n+\tlong long\t\t*inode_lookup_table;\n+\tint\t\t\t(*read_inode)(struct inode *i,  squashfs_inode_t \\\n+\t\t\t\tinode);\n+\tlong long\t\t(*read_blocklist)(struct inode *inode, int \\\n+\t\t\t\tindex, int readahead_blks, char *block_list, \\\n+\t\t\t\tunsigned short **block_p, unsigned int *bsize);\n+\tint\t\t\t(*read_fragment_index_table)(struct super_block *s);\n+};\n+#endif\ndiff -x .gitignore -Nurp linux-2.6.27-rc4-next/init/do_mounts_rd.c linux-2.6.27-rc4-next-squashfs3.4/init/do_mounts_rd.c\n--- linux-2.6.27-rc4-next/init/do_mounts_rd.c\t2008-08-20 02:17:38.000000000 +0100\n+++ linux-2.6.27-rc4-next-squashfs3.4/init/do_mounts_rd.c\t2008-08-20 04:15:06.000000000 +0100\n@@ -5,6 +5,7 @@\n #include <linux/ext2_fs.h>\n #include <linux/romfs_fs.h>\n #include <linux/cramfs_fs.h>\n+#include <linux/squashfs_fs.h>\n #include <linux/initrd.h>\n #include <linux/string.h>\n \n@@ -37,6 +38,7 @@ static int __init crd_load(int in_fd, in\n  * numbers could not be found.\n  *\n  * We currently check for the following magic numbers:\n+ *      squashfs\n  * \tminix\n  * \text2\n  *\tromfs\n@@ -51,6 +53,7 @@ identify_ramdisk_image(int fd, int start\n \tstruct ext2_super_block *ext2sb;\n \tstruct romfs_super_block *romfsb;\n \tstruct cramfs_super *cramfsb;\n+\tstruct squashfs_super_block *squashfsb;\n \tint nblocks = -1;\n \tunsigned char *buf;\n \n@@ -62,6 +65,7 @@ identify_ramdisk_image(int fd, int start\n \text2sb = (struct ext2_super_block *) buf;\n \tromfsb = (struct romfs_super_block *) buf;\n \tcramfsb = (struct cramfs_super *) buf;\n+\tsquashfsb = (struct squashfs_super_block *) buf;\n \tmemset(buf, 0xe5, size);\n \n \t/*\n@@ -99,6 +103,18 @@ identify_ramdisk_image(int fd, int start\n \t\tgoto done;\n \t}\n \n+\t/* squashfs is at block zero too */\n+\tif (squashfsb->s_magic == SQUASHFS_MAGIC) {\n+\t\tprintk(KERN_NOTICE\n+\t\t       \"RAMDISK: squashfs filesystem found at block %d\\n\",\n+\t\t       start_block);\n+\t\tif (squashfsb->s_major < 3)\n+\t\t\tnblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\telse\n+\t\t\tnblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;\n+\t\tgoto done;\n+\t}\n+\n \t/*\n \t * Read block 1 to test for minix and ext2 superblock\n \t */\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/Makefile",
    "content": "ifndef Sqlzma\n$(error Sqlzma is not defined)\nendif\n\nINSTALL_DIR = /usr/local/bin\n\nINCLUDEDIR = .\n\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\nifdef UseDebugFlags\nDebugFlags = -g -Wall -Wno-unused-variable -O0 -UNDEBUG\nendif\nCFLAGS += -I${Sqlzma} -D_REENTRANT -DNDEBUG ${DebugFlags}\nLDFLAGS += -L${LzmaAlone} -L${LzmaC}\n\nall: mksquashfs unsquashfs\n\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\t$(CC) $(LDFLAGS) mksquashfs.o read_fs.o sort.o -lz -lpthread -lm -lunlzma_r -llzma_r -lstdc++ -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h \\\n\t${LzmaAlone}/liblzma_r.a ${LzmaC}/libunlzma_r.a\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nunsquashfs: unsquashfs.o\n\t$(CC) $(LDFLAGS) unsquashfs.o -lpthread -lm -lunlzma -lz -o $@\n\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h \\\n\t${Sqlzma}/sqlzma.h ${Sqlzma}/sqmagic.h ${LzmaC}/libunlzma.a\n\nclean:\n\t-rm -f *.o mksquashfs unsquashfs\n\ninstall: mksquashfs unsquashfs\n\tmkdir -p $(INSTALL_DIR)\n\tcp mksquashfs unsquashfs $(INSTALL_DIR)\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\ntypedef union squashfs_inode_header_1 squashfs_inode_header_1;\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n#endif\n\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/time.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#ifndef FNM_EXTMATCH\n#define FNM_EXTMATCH (1 << 5)\n#endif\n\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tprintf(\"\\n\"); \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\nint progress_enabled = FALSE;\nint sparse_files = TRUE;\nint old_exclude = TRUE;\nint use_regex = FALSE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\nstruct sqlzma_un un;\nstruct sqlzma_opts sqlzma_opts = {\n\t.try_lzma\t= 1,\n\t.dicsize\t= SQUASHFS_FILE_SIZE\n};\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\nint empty_files = 0;\n\n/* exclude file handling */\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint old_excluded(char *filename, struct stat *buf);\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nstruct pathnames *paths = NULL;\nstruct pathname *path = NULL;\nstruct pathname *stickypath = NULL;\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\n\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n\n#define FRAG_SIZE 32768\n#define FRAG_INDEX (1LL << 32)\n\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache, *sdirectory_compressed;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, sdirectory_compressed_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* recovery file for abnormal exit on appending */\nchar recovery_file[1024] = \"\";\nint recover = TRUE;\n\n/* struct describing a cache entry passed between threads */\nstruct file_buffer {\n\tstruct cache *cache;\n\tint keep;\n\tlong long file_size;\n\tlong long index;\n\tlong long block;\n\tlong long sequence;\n\tint size;\n\tint c_byte;\n\tint used;\n\tint\tfragment;\n\tint error;\n\tstruct file_buffer *hash_next;\n\tstruct file_buffer *hash_prev;\n\tstruct file_buffer *free_next;\n\tstruct file_buffer *free_prev;\n\tstruct file_buffer *next;\n\tchar data[0];\n};\n\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n/* describes the list of blocks in a file which is a possible\n   duplicate.  For each block, it indicates whether the block is\n   in memory or on disk */\nstruct buffer_list {\n\tlong long start;\n\tint size;\n\tstruct file_buffer *read_buffer;\n};\n\nstruct cache *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate, *to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread, progress_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\npthread_mutex_t progress_mutex;\npthread_cond_t progress_wait;\nint rotate = 0;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\nint fragment_buffer_size;\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table, squashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *, char *, struct dir_info *));\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info);\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf);\nextern struct priority_entry *priority_list[65536];\nvoid progress_bar(long long current, long long max, int columns);\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tstruct file_buffer *free_list;\n\tstruct file_buffer *hash_table[65536];\n};\n\n\n#define INSERT_LIST(NAME, TYPE) \\\nvoid insert_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(*list) { \\\n\t\tentry->NAME##_next = *list; \\\n\t\tentry->NAME##_prev = (*list)->NAME##_prev; \\\n\t\t(*list)->NAME##_prev->NAME##_next = entry; \\\n\t\t(*list)->NAME##_prev = entry; \\\n\t} else { \\\n\t\t*list = entry; \\\n\t\tentry->NAME##_prev = entry->NAME##_next = entry; \\\n\t} \\\n}\n\n\n#define REMOVE_LIST(NAME, TYPE) \\\nvoid remove_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(entry->NAME##_prev == entry && entry->NAME##_next == entry) { \\\n\t\t/* only this entry in the list */ \\\n\t\t*list = NULL; \\\n\t} else if(entry->NAME##_prev != NULL && entry->NAME##_next != NULL) { \\\n\t\t/* more than one entry in the list */ \\\n\t\tentry->NAME##_next->NAME##_prev = entry->NAME##_prev; \\\n\t\tentry->NAME##_prev->NAME##_next = entry->NAME##_next; \\\n\t\tif(*list == entry) \\\n\t\t\t*list = entry->NAME##_next; \\\n\t} \\\n\tentry->NAME##_prev = entry->NAME##_next = NULL; \\\n}\n\n\n#define CALCULATE_HASH(start)\t(start & 0xffff) \\\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tint hash = CALCULATE_HASH(entry->index);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->index)] = entry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nINSERT_LIST(free, struct file_buffer)\n\n/* Called with the cache mutex held */\nREMOVE_LIST(free, struct file_buffer)\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\treturn NULL;\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct file_buffer *) * 65536);\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\n\treturn cache;\n}\n\n\nstruct file_buffer *cache_lookup(struct cache *cache, long long index)\n{\n\t/* Lookup block in the cache, if found return with usage count\n \t * incremented, if not found return NULL */\n\tint hash = CALCULATE_HASH(index);\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->index == index)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/* found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(&cache->free_list, entry);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n}\n\n\n#define GET_FREELIST 1\n\nstruct file_buffer *cache_get(struct cache *cache, long long index, int keep)\n{\n\t/* Get a free block out of the cache indexed on index. */\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\twhile(1) {\n\t\t/* first try to get a block from the free list */\n#ifdef GET_FREELIST\n\t\tif(cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t} else\n#endif\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\t/* next try to allocate new block */\n\t\t\tentry = malloc(sizeof(struct file_buffer) + cache->buffer_size);\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t\tbreak;\n\t\t} else\n#ifndef GET_FREELIST\n\t\tif(cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t}\n#endif\n\t\t\t/* wait for a block */\n\t\t\tpthread_cond_wait(&cache->wait_for_free, &cache->mutex);\n\t}\n\n\t/* initialise block and if a keep block insert into the hash table */\n\tentry->used = 1;\n\tentry->error = FALSE;\n\tentry->keep = keep;\n\tif(keep) {\n\t\tentry->index = index;\n\t\tinsert_hash_table(cache, entry);\n\t}\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\treturn NULL;\n}\n\n\nvoid cache_rehash(struct file_buffer *entry, long long index)\n{\n\tstruct cache *cache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\tif(entry->keep)\n\t\tremove_hash_table(cache, entry);\n\tentry->keep = TRUE;\n\tentry->index = index;\n\tinsert_hash_table(cache, entry);\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\nvoid cache_block_put(struct file_buffer *entry)\n{\n\tstruct cache *cache;\n\n\t/* finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and if a keep block put onto the free list.  As keep\n \t * blocks remain accessible via the hash table they can be found getting a\n \t * new lease of life before they are reused. */\n\n\tif(entry == NULL)\n\t\treturn;\n\n\tcache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tif(entry->keep)\n\t\t\tinsert_free_list(&cache->free_list, entry);\n\t\telse {\n\t\t\tfree(entry);\n\t\t\tcache->count --;\n\t\t}\n\n\t\t/* One or more threads may be waiting on this block */\n\t\tpthread_cond_signal(&cache->wait_for_free);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\ninline void inc_progress_bar()\n{\n\tcur_uncompressed ++;\n}\n\n\ninline void update_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tif(thread[i])\n\t\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tmemcpy(directory_table + directory_bytes, sdirectory_compressed, sdirectory_compressed_bytes);\n\tdirectory_bytes += sdirectory_compressed_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, &thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tBAD_ERROR(\"mangle::compress failed, not enough memory\\n\");\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid compression level\\n\");\n\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect zlib version\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state inconsistent\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t}\n\n\tres = sqlzma_cm(&sqlzma_opts, stream, (void *)s, size, (void *)d,\n\t\t\tblock_size);\n\tc_byte = stream->total_out;\n\n\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed, data_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\", strerror(errno));\n\n\tif(read(fd, buff, bytes) == -1)\n\t\tBAD_ERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\", strerror(errno));\n\n\tif(write(fd, buff, bytes) == -1)\n\t\tBAD_ERROR(\"Write on destination failed because %s\\n\", strerror(errno));\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %lld, start_block 0x%llx, blocks %d, fragment %d, offset %d, size %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block 0x%llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %lld, start_block 0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %lld, start_block 0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir)\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir);\n\telse\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL);\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nstruct file_buffer *get_fragment(struct fragment *fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\tlong long start_block;\n\tstruct file_buffer *buffer, *compressed_buffer;\n\n\tif(fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn NULL;\n\n\tbuffer = cache_lookup(fragment_buffer, fragment->index);\n\tif(buffer)\n\t\treturn buffer;\n\n\tcompressed_buffer = cache_lookup(writer_buffer, fragment->index + FRAG_INDEX);\n\n\tbuffer = cache_get(fragment_buffer, fragment->index, 1);\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\tstart_block = disk_fragment->start_block;\n\tpthread_mutex_unlock(&fragment_mutex);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar *data;\n\t\tchar cbuffer[block_size];\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)cbuffer, .sz = size},\n\t\t\t{.buf = (void *)buffer->data, .sz = bytes}\n\t\t};\n\n\t\tif(compressed_buffer)\n\t\t\tdata = compressed_buffer->data;\n\t\telse {\n\t\t\tdata = cbuffer;\n\t\t\tread_bytes(fd, start_block, size, data);\n\t\t}\n\n\t\tsbuf[Src].buf = data;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tBAD_ERROR(\"%s:%d: res %d\\n\", __func__, __LINE__, res);\n\t} else if(compressed_buffer)\n\t\tmemcpy(buffer->data, compressed_buffer->data, size);\n\telse\n\t\tread_bytes(fd, start_block, size, buffer->data);\n\n\treturn buffer;\n}\n\n\nstruct frag_locked {\n\tstruct file_buffer *buffer;\n\tint c_byte;\n\tint fragment;\n\tstruct frag_locked *fragment_prev;\n\tstruct frag_locked *fragment_next;\n};\n\nint fragments_locked = FALSE;\nstruct frag_locked *frag_locked_list = NULL;\n\nINSERT_LIST(fragment, struct frag_locked)\nREMOVE_LIST(fragment, struct frag_locked)\n\nint lock_fragments()\n{\n\tint count;\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragments_locked = TRUE;\n\tcount = fragments_outstanding;\n\tpthread_mutex_unlock(&fragment_mutex);\n\treturn count;\n}\n\n\nvoid unlock_fragments()\n{\n\tstruct frag_locked *entry;\n\tint compressed_size;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(frag_locked_list) {\n\t\tentry = frag_locked_list;\n\t\tremove_fragment_list(&frag_locked_list, entry);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->c_byte);\n\t\tfragment_table[entry->fragment].size = entry->c_byte;\n\t\tfragment_table[entry->fragment].start_block = bytes;\n\t\tentry->buffer->block = bytes;\n\t\tbytes += compressed_size;\n\t\tfragments_outstanding --;\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\tqueue_put(to_writer, entry->buffer);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tTRACE(\"fragment_locked writing fragment %d, compressed size %d\\n\", entry->fragment, compressed_size);\n\t\tfree(entry);\n\t}\n\tfragments_locked = FALSE;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nint add_pending_fragment(struct file_buffer *write_buffer, int c_byte, int fragment)\n{\n\tstruct frag_locked *entry = malloc(sizeof(struct frag_locked));\n\tif(entry == NULL)\n\t\treturn FALSE;\n\tentry->buffer = write_buffer;\n\tentry->c_byte = c_byte;\n\tentry->fragment = fragment;\n\tentry->fragment_prev = entry->fragment_next = NULL;\n\tpthread_mutex_lock(&fragment_mutex);\n\tinsert_fragment_list(&frag_locked_list, entry);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].unused = 0;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = cache_get(fragment_buffer, fragments, 1);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data, file_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes, compressed_size);\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tlong long slist[meta_blocks];\n\t\tSQUASHFS_SWAP_LONG_LONGS(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count * sizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments, frag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block 0x%llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l, unsigned int *blocks)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\tstruct file_buffer *write_buffer;\n\tint i;\n\n\tfor(i = 0; l; i++)  {\n\t\tbytes = SQUASHFS_COMPRESSED_SIZE_BLOCK(blocks[i]);\n\t\tif(bytes == 0) /* sparse block */\n\t\t\tcontinue;\n\t\twrite_buffer = cache_lookup(writer_buffer, start);\n\t\tif(write_buffer) {\n\t\t\tchksum = get_checksum(write_buffer->data, bytes, chksum);\n\t\t\tcache_block_put(write_buffer);\n\t\t} else\n\t\t\tchksum = get_checksum(read_from_disk(start, bytes), bytes, chksum);\n\t\tl -= bytes;\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset != dupl_ptr->fragment->offset || bytes != dupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer = get_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(frag_buffer->data + dupl_ptr->fragment->offset, file_size);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes, unsigned int *block_list, long long start, struct fragment *fragment, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nchar buffer2[SQUASHFS_FILE_MAX_SIZE];\nstruct file_info *duplicate(long long file_size, long long bytes, unsigned int **block_list, long long *start, struct fragment **fragment, struct file_buffer *file_buffer, struct buffer_list *buffer_list, int blocks, unsigned short checksum, unsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tint block;\n\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks * sizeof(unsigned int)) != 0)\n\t\t\t\tcontinue;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_disk(*start, bytes, *block_list);\n\t\t\t\tfragment_checksum = get_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer = get_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum = get_checksum_disk(dupl_ptr->start, dupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum = get_checksum_mem(frag_buffer->data + dupl_ptr->fragment->offset, frag_bytes);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum || fragment_checksum != dupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tstruct buffer_list *b = &buffer_list[block];\n\t\t\t\tstruct file_buffer *target_buffer = NULL;\n\t\t\t\tstruct file_buffer *dup_buffer = NULL;\n\t\t\t\tchar *target_data, *dup_data;\n\t\t\t\tint res;\n\n\t\t\t\tif(b->read_buffer)\n\t\t\t\t\ttarget_data = b->read_buffer->data;\n\t\t\t\telse if(b->size) {\n\t\t\t\t\ttarget_buffer = cache_lookup(writer_buffer, b->start);\n\t\t\t\t\tif(target_buffer)\n\t\t\t\t\t\ttarget_data = target_buffer->data;\n\t\t\t\t\telse\n\t\t\t\t\t\ttarget_data = read_from_disk(b->start, b->size);\n\t\t\t\t} else\n\t\t\t\t\tcontinue;\n\n\t\t\t\tdup_buffer = cache_lookup(writer_buffer, dup_start);\n\t\t\t\tif(dup_buffer)\n\t\t\t\t\tdup_data = dup_buffer->data;\n\t\t\t\telse {\n\t\t\t\t\tread_bytes(fd, dup_start, b->size, buffer2);\n\t\t\t\t\tdup_data = buffer2;\n\t\t\t\t}\n\t\t\t\tres = memcmp(target_data, dup_data, b->size);\n\t\t\t\tif(target_buffer)\n\t\t\t\t\tcache_block_put(target_buffer);\n\t\t\t\tif(dup_buffer)\n\t\t\t\t\tcache_block_put(dup_buffer);\n\t\t\t\tif(res != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_start += b->size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tstruct file_buffer *frag_buffer = get_fragment(dupl_ptr->fragment);\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(file_buffer->data, frag_buffer->data + dupl_ptr->fragment->offset, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment, checksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\n\tstruct file_buffer *file_buffer;\n\tstatic int index = 0;\n\tint blocks, byte, count, expected, file, frag_block;\n\tlong long bytes, read_size;\n\n\tif(dir_ent->inode->read)\n\t\treturn;\n\n\tdir_ent->inode->read = TRUE;\nagain:\n\tbytes = 0;\n\tcount = 0;\n\tfile_buffer = NULL;\n\tread_size = buf->st_size;\n\tblocks = (read_size + block_size - 1) >> block_log;\n\tfrag_block = !no_fragments && (always_use_fragments ||\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\texpected = read_size - ((long long) count * block_size) > block_size ? block_size : read_size - ((long long) count * block_size);\n\n\t\tif(file_buffer)\n\t\t\tqueue_put(from_reader, file_buffer);\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = index ++;\n\n\t\tbyte = file_buffer->size = read(file, file_buffer->data, block_size);\n\n\t\tfile_buffer->file_size = read_size;\n\n\t\tif(byte != expected)\n\t\t\tgoto restat;\n\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->error = FALSE;\n\n\t\tbytes += byte;\n\t\tcount ++;\n\t} while(count < blocks);\n\n\tif(read_size != bytes)\n\t\tgoto restat;\n\n\tif(expected == block_size) {\n\t\tchar buffer;\n\n\t\tif(read(file, &buffer, 1) == 1)\n\t\t\tgoto restat;\n\t}\n\n\tfile_buffer->fragment = (file_buffer->block == frag_block);\n\n\tif(file_buffer->fragment)\n\t\tqueue_put(from_deflate, file_buffer);\n\telse\n\t\tqueue_put(from_reader, file_buffer);\n\n\tclose(file);\n\n\treturn;\n\nread_err:\n\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\tfile_buffer->sequence = index ++;\nread_err2:\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n\treturn;\nrestat:\n\tfstat(file, &buf2);\n\tclose(file);\n\tif(read_size != buf2.st_size) {\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\n\t\tfile_buffer->error = 2;\n\t\tqueue_put(from_deflate, file_buffer);\n\t\tgoto again;\n\t}\n\tgoto read_err2;\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\treturn NULL;\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\n\tthread[0] = 0;\n\n\tpthread_exit(NULL);\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer, write_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tERROR(\"Lseek on destination failed because %s\\n\", strerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write(fd, file_buffer->data, file_buffer->size) == -1) {\n\t\t\tERROR(\"Write on destination failed because %s\\n\", strerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\nint all_zero(struct file_buffer *file_buffer)\n{\n\tint i;\n\tlong entries = file_buffer->size / sizeof(long);\n\tlong *p = (long *) file_buffer->data;\n\n\tfor(i = 0; i < entries && p[i] == 0; i++);\n\n\tif(i == entries) {\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1); i < file_buffer->size &&\n\t\t\t\t\t\tfile_buffer->data[i] == 0; i++);\n\n\t\treturn i == file_buffer->size;\n\t}\n\n\treturn 0;\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer = cache_get(writer_buffer, 0, 0);\n\n\t\tif(sparse_files && all_zero(file_buffer)) \n\t\t\twrite_buffer->c_byte = 0;\n\t\telse\n\t\t\twrite_buffer->c_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noD, 1);\n\t\twrite_buffer->sequence = file_buffer->sequence;\n\t\twrite_buffer->file_size = file_buffer->file_size;\n\t\twrite_buffer->block = file_buffer->block;\n\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK(write_buffer->c_byte);\n\t\twrite_buffer->fragment = FALSE;\n\t\twrite_buffer->error = FALSE;\n\t\tcache_block_put(file_buffer);\n\t\tqueue_put(from_deflate, write_buffer);\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer = cache_get(writer_buffer, file_buffer->block + FRAG_INDEX, 1);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data, file_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\twrite_buffer->size = compressed_size;\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tif(fragments_locked == FALSE) {\n\t\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\t\twrite_buffer->block = bytes;\n\t\t\tbytes += compressed_size;\n\t\t\tfragments_outstanding --;\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tqueue_put(to_writer, write_buffer);\n\t\t\tTRACE(\"Writing fragment %lld, uncompressed size %d, compressed size %d\\n\", file_buffer->block, file_buffer->size, compressed_size);\n\t\t} else {\n\t\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\t\tadd_pending_fragment(write_buffer, c_byte, file_buffer->block);\n\t\t}\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->sequence);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int sequence = 0;\n\tint hash = BLOCK_HASH(sequence);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->sequence == sequence)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->sequence == sequence)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tsequence ++;\n\n\treturn file_buffer;\n}\n\n\nvoid *progress_thrd(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tprintf(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&progress_mutex);\n\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) * 1000;\n\t\tpthread_cond_timedwait(&progress_wait, &progress_mutex, &timespec);\n\t\tif(progress_enabled && estimated_uncompressed)\n\t\t\tprogress_bar(cur_uncompressed, estimated_uncompressed, columns);\n\t}\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits = floor(log10(max)) + 1;\n\tint used = max_digits * 2 + 11;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(current > max) {\n\t\tprintf(\"%lld %lld\\n\", current, max);\n\t\treturn;\n\t}\n\n\tif(columns - used < 0)\n\t\treturn;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n\treturn;\n}\n\n\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\tempty_files ++;\n\tif (!progress)\n\t\tprintf(\"empty file %s \\n\",dir_ent->pathname );\n\t\t\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL, &empty_fragment, NULL);\n}\n\n\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent, int size, int *duplicate_file, struct file_buffer *file_buffer, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment, file_buffer, NULL, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\t\tif (!progress)\n\t\t\t\tprintf(\"duplicate file %s \\n\",dir_ent->pathname);\n\t}\n\n\tcache_block_put(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tinc_progress_bar();\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n}\n\n\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size, struct file_buffer *file_buffer, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum)) {\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file, file_buffer, checksum);\n\t\treturn;\n\t}\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\tcache_block_put(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tinc_progress_bar();\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0, NULL, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0, NULL, fragment, NULL);\n\n\treturn;\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\n{\n\tint block;\n\tunsigned int frag_bytes;\n\tlong long file_bytes, start;\n\tstruct fragment *fragment;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list;\n\tstruct file_buffer *read_buffer;\n\tint status;\n\n\t*duplicate_file = FALSE;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tlock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tif(reader_buffer) {\n\t\t\tread_buffer = reader_buffer;\n\t\t\treader_buffer = NULL;\n\t\t} else {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tif(read_buffer->c_byte) {\n\t\t\tread_buffer->block = bytes;\n\t\t\tbytes += read_buffer->size;\n\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\tfile_bytes += read_buffer->size;\n\t\t\tqueue_put(to_writer, read_buffer);\n\t\t} else\n\t\t\tcache_block_put(read_buffer);\n\t\tinc_progress_bar();\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t\tinc_progress_bar();\n\t} else\n\t\tread_buffer = NULL;\n\n\tunlock_fragments();\n\tfragment = get_and_fill_fragment(read_buffer);\n\tcache_block_put(read_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment, 0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_list, fragment, NULL);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(!block_device) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tftruncate(fd, bytes);\n\t}\n\tunlock_fragments();\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent, long long read_size, struct file_buffer *reader_buffer, int *duplicate_file)\n{\n\tint block, thresh;\n\tunsigned int frag_bytes;\n\tlong long file_bytes, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer *read_buffer;\n\tstruct buffer_list *buffer_list;\n\tint status, num_locked_fragments;\n\n\tif(!no_fragments && always_use_fragments) {\n\t\tblocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif((buffer_list = malloc(blocks * sizeof(struct buffer_list))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tnum_locked_fragments = lock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tthresh = blocks > (writer_buffer_size - num_locked_fragments) ? blocks - (writer_buffer_size - num_locked_fragments): 0;\n\tfor(block = 0; block < blocks; block ++) {\n\t\tif(reader_buffer) {\n\t\t\tread_buffer = reader_buffer;\n\t\t\treader_buffer = NULL;\n\t\t } else {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\n\t\tblock_list[block] = read_buffer->c_byte;\n\t\tbuffer_list[block].start = bytes;\n\t\tbuffer_list[block].size = read_buffer->size;\n\n\t\tif(read_buffer->c_byte) {\n\t\t\tread_buffer->block = bytes;\n\t\t\tbytes += read_buffer->size;\n\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\tfile_bytes += read_buffer->size;\n\t\t\tif(block < thresh) {\n\t\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else\n\t\t\t\tbuffer_list[block].read_buffer = read_buffer;\n\t\t} else {\n\t\t\tbuffer_list[block].read_buffer = NULL;\n\t\t\tcache_block_put(read_buffer);\n\t\t}\n\t\tinc_progress_bar();\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t} else\n\t\tread_buffer = NULL;\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &start, &fragment, read_buffer, buffer_list, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tif(buffer_list[block].read_buffer)\n\t\t\t\tqueue_put(to_writer, buffer_list[block].read_buffer);\n\t\tfragment = get_and_fill_fragment(read_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tcache_block_put(buffer_list[block].read_buffer);\n\t\tbytes = buffer_list[0].start;\n\t\tif(thresh && !block_device) {\n\t\t\tqueue_put(to_writer, NULL);\n\t\t\tif(queue_get(from_writer) != 0)\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\tftruncate(fd, bytes);\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tcache_block_put(read_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(thresh && !block_device) {\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tftruncate(fd, bytes);\n\t}\n\tunlock_fragments();\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\tcache_block_put(buffer_list[blocks].read_buffer);\n\tfree(buffer_list);\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *duplicate_file)\n{\n\tint status;\n\tstruct file_buffer *read_buffer;\n\tlong long read_size;\n\nagain:\n\tread_buffer = get_file_buffer(from_deflate);\n\tstatus = read_buffer->error;\n\tif(status) {\n\t\tcache_block_put(read_buffer);\n\t\tgoto file_err;\n\t}\n\t\n\tread_size = read_buffer->file_size;\n\n\tif(read_size == 0) {\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t\tcache_block_put(read_buffer);\n\t} else if(!no_fragments && (read_size < block_size))\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\telse if(pre_duplicate(read_size))\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\telse\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size, read_buffer, duplicate_file);\n\nfile_err:\n\tif(status == 2) {\n\t\tERROR(\"File %s changed size while reading filesystem, attempting to re-read\\n\", dir_ent->pathname);\n\t\tgoto again;\n\t} else if(status == 1) {\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\", dir_ent->pathname);\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t}\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\n\tif((buf->st_mode & S_IFMT) == S_IFREG)\n\t\testimated_uncompressed += (buf->st_size + block_size - 1) >> block_log;\n\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", pathname, strerror(errno));\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0, &dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tif(progress)\n\t\tenable_progress_bar();\n\tdir_scan2(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\tstruct pathnames *new;\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", filename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\\n\", filename, buf.st_mode & S_IFMT);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(old_exclude) {\n\t\t\tif(old_excluded(filename, &buf))\n\t\t\t\tcontinue;\n\t\t} else {\n\t\t\tif(excluded(paths, dir_name, &new))\n\t\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, new, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\n\nvoid dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type = -1;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\twrite_file(inode, dir_ent, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tdir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tBAD_ERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t}\n\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t\tupdate_progress_bar();\n\t}\n\n\twrite_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 23; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint old_excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint old_add_exclude(char *path)\n{\n\tint i;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat exclude dir/file %s because %s, ignoring\", path, strerror(errno));\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tERROR(\"Cannot stat exclude dir/file %s because %s, ignoring\", filename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(fragment_buffer_size);\n\treader_buffer = cache_init(block_size, reader_buffer_size);\n\twriter_buffer = cache_init(block_size, writer_buffer_size);\n\tfragment_buffer = cache_init(block_size, fragment_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&progress_thread, NULL, progress_thrd, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) != 0 )\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator, NULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tif((inode_lookup_table = realloc(inode_lookup_table, lookup_bytes)) == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number + dir_inode_no;\n\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(&inode_lookup_table[inode_number - 1], &inode->inode, sizeof(squashfs_inode));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_LONG_LONGS((&inode->inode), &inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table, 0);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing exclude which subsumes the exclude currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific excludes, delete as they're subsumed by this exclude\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid add_exclude(char *target)\n{\n\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 || strncmp(target, \"../\", 3) == 0)\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with -wildcards or -regex options\\n\");\t\n\telse if(strncmp(target, \"... \", 4) == 0)\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\n\telse\t\n\t\tpath = add_path(path, target, target);\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n, res;\n\t\t\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\n\t*new = init_subdir();\n\tif(stickypath)\n\t\t*new = add_subdir(*new, stickypath);\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\n\t\t\tif(match && path->name[i].paths == NULL) {\n\t\t\t\t/* match on a leaf component, any subdirectories in the\n\t\t\t\t * filesystem should be excluded */\n\t\t\t\tres = TRUE;\n\t\t\t\tgoto empty_set;\n\t\t\t}\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t\t/* no matching names found, return empty new search set */\n\t\t\tres = FALSE;\n\t\t\tgoto empty_set;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches).\n\t * Return new set */\n\treturn FALSE;\n\nempty_set:\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn res;\n}\n\n\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\n#define RECOVER_ID_SIZE 28\n\nvoid write_recovery_data(squashfs_super_block *sBlk)\n{\n\tint recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\n\tpid_t pid = getpid();\n\tchar *metadata;\n\tchar header[] = RECOVER_ID;\n\n\tif(recover == FALSE) {\n\t\tprintf(\"No recovery data option specified.\\n\");\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\n\t\treturn;\n\t}\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in write_recovery_data\\n\");\n\n\tread_bytes(fd, sBlk->inode_table_start, bytes, metadata);\n\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\", getbase(destination_file), pid);\n\tif((recoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1)\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  Aborting\\n\", strerror(errno));\n\t\t\n\tif(write(recoverfd, header, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tif(write(recoverfd, sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tif(write(recoverfd, metadata, bytes) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\", strerror(errno));\n\n\tclose(recoverfd);\n\tfree(metadata);\n\t\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file, recovery_file);\n\tprintf(\"to restore filesystem\\n\\n\");\n}\n\n\nvoid read_recovery_data(char *recovery_file, char *destination_file)\n{\n\tint fd, recoverfd, bytes;\n\tsquashfs_super_block orig_sBlk, sBlk;\n\tchar *metadata;\n\tint readbytes;\n\tstruct stat buf;\n\tchar header[] = RECOVER_ID;\n\tchar header2[RECOVER_ID_SIZE];\n\n\tif((recoverfd = open(recovery_file, O_RDONLY)) == -1)\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\", strerror(errno));\n\n\tif(stat(destination_file, &buf) == -1)\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\", strerror(errno));\n\n\tif((fd = open(destination_file, O_RDWR)) == -1)\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\", strerror(errno));\n\n\tif(read(recoverfd, header2, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\n\n\tif(read(recoverfd, &sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\n\tread_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &orig_sBlk);\n\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4, sizeof(squashfs_super_block) - 4) != 0)\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to match\\n\");\n\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in read_recovery_data\\n\");\n\n\tif((readbytes = read(recoverfd, metadata, bytes)) == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\", strerror(errno));\n\n\tif(readbytes != bytes)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\twrite_bytes(fd, 0, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\twrite_bytes(fd, sBlk.inode_table_start, bytes, metadata);\n\n\tclose(recoverfd);\n\tclose(fd);\n\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\", recovery_file);\n\t\n\texit(0);\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.4 (2008/08/26)\\n\");\\\n\tprintf(\"copyright (C) 2008 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n\tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\\\n\tprintf(\"and LZMA %s support for slax.org by jro.\\n\",LZMA_VERSION);\nint main(int argc, char *argv[])\n{\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT, writeb_mbytes = WRITER_BUFFER_DEFAULT, fragmentb_mbytes = FRAGMENT_BUFFER_DEFAULT;\n\tint s_minor;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tpthread_mutex_init(&progress_mutex, NULL);\n\tun.un_lzma = 1;\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-recover\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\n\t\t\trecover = FALSE;\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = FALSE;\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\n\t\t\tsparse_files = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-fragment-queue\") == 0) {\n\t\t\tif((++i == argc) || (fragmentb_mbytes = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -fragment-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragmentb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -fragment-queue should be 1 megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0\n\t\t\t|| strcmp(argv[i], \"-lzmadic\") == 0) {\n\t\t\tlong bs;\n\t\t\tunsigned int bl;\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -b|-lzmadic missing block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tbs = strtol(argv[i], &b, 10);\n\t\t\tif(*b == 'm' || *b == 'M')\n\t\t\t\tbs *= 1048576;\n\t\t\telse if(*b == 'k' || *b == 'K')\n\t\t\t\tbs *= 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tERROR(\"%s: -b|-lzmadic invalid size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tbl = slog(bs);\n\t\t\tif(bl == 0) {\n\t\t\t\tERROR(\"%s: -b|-lzmadic size not power of two or not between 4096 and 1Mbyte\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif (!strcmp(argv[i - 1], \"-b\")) {\n\t\t\t\tblock_size = bs;\n\t\t\t\tblock_log = bl;\n\t\t\t}\n\t\t\tsqlzma_opts.dicsize = bs;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0) {\n\t\t\tsilent = FALSE;\n\t\t\tprogress = FALSE;\n\t\t}\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n\t\t\tun.un_lzma = 0;\n\t\t\tsqlzma_opts.try_lzma = 0;\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data using recovery file <name>\\n\");\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery file\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.  By default will use number of\\n\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> Mbytes.  Default %d Mbytes\\n\", READER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> Mbytes.  Default %d Mbytes\\n\", WRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-fragment-queue <size>\\tSet fagment queue to <size> Mbytes.  Default %d Mbytes\\n\", FRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards (globbing) to be used in\\n\\t\\t\\texclude dirs/files\\n\");\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n\t\t\tERROR(\"-lzmadic <dic_size>\\tset the LZMA dictionary\"\n\t\t\t      \" size to <dic_size>\\n\"\n\t\t\t      \"\\t\\t\\tDefault value always follow the block\"\n\t\t\t      \" size\\n\"\n\t\t\t      \"\\t\\t\\tUse this alone or AFTER -b option\\n\");\n\t\t\tERROR(\"-nolzma\\t\\t\\tnever try LZMA compression\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\tfragment_buffer_size = fragmentb_mbytes << (20 - block_log);\n\n\tif(block_size <= 65536 && sparse_files == FALSE)\n\t\ts_minor = 0;\n\telse\n\t\ts_minor = SQUASHFS_MINOR;\n\n\tfor(i = 0; i < source; i++)\n\t\tif(lstat(source_path[i], &source_buf) == -1) {\n\t\t\tfprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tsignal(SIGTERM, sighandler2);\n\tsignal(SIGINT, sighandler2);\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\t\tif(old_exclude)\n\t\t\t\t\t\told_add_exclude(filename);\n\t\t\t\t\telse\n\t\t\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc)\n\t\t\tif(old_exclude)\n\t\t\t\told_add_exclude(argv[i++]);\n\t\t\telse\n\t\t\t\tadd_exclude(argv[i++]);\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\t//sqlzma_opts.dicsize = block_size;\n\t\ts_minor = sBlk.s_minor;\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t}\n\n\tinitialise_threads();\n\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tERROR(\"%s:%d: %d\\n\", __func__, __LINE__, i);\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t\tif (sqlzma_opts.try_lzma)\n\t\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tif (sqlzma_opts.try_lzma)\n\t\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -exportable options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = (inode_dir_offset + inode_dir_file_size) & ~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = (inode_dir_offset + inode_dir_file_size) & (SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tscache_bytes = root_inode_offset + root_inode_size;\n\t\tsdirectory_cache_bytes = uncompressed_data;\n\t\tsdata_cache = (char *)malloc(scache_bytes);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\twrite_recovery_data(&sBlk);\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\tsdirectory_bytes = last_directory_block;\n\t\t\tsdirectory_compressed_bytes = 0;\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\tsdirectory_compressed_bytes = last_directory_block - inode_dir_start_block;\n\t\t\tsdirectory_compressed = malloc(sdirectory_compressed_bytes);\n\t\t\tmemcpy(sdirectory_compressed, directory_table + inode_dir_start_block, sdirectory_compressed_bytes); \n\t\t\tsdirectory_bytes = inode_dir_start_block;\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(path || stickypath) {\n\t\tpaths = init_subdir();\n\t\tif(path)\n\t\t\tpaths = add_subdir(paths, path);\n\t\tif(stickypath)\n\t\t\tpaths = add_subdir(paths, stickypath);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC_LZMA;\n\tif (!un.un_lzma)\n\t\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = s_minor;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\tif(progress && estimated_uncompressed) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tunlock_fragments();\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\twhile(fragments_outstanding) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tsched_yield();\n\t\t\tpthread_mutex_lock(&fragment_mutex);\n\t\t}\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() : SQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\", sBlk.lookup_table_start);\n\n\tsBlk.no_uids = uid_count;\n\tif(sBlk.no_uids) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tsBlk.no_guids = guid_count;\n\tif(sBlk.no_guids) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\tclose(fd);\n\n\tif(recovery_file[0] != '\\0')\n\t\tunlink(recovery_file);\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s%s filesystem, data block size %d, %s data, %s metadata, %s fragments, duplicates are %sremoved\\n\",\n\t\texportable ? \"Exportable \" : \"\", be ?  \"Big endian\" : \"Little endian\", block_size,\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" : \"compressed\",\n\t\tno_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\", duplicate_checking ? \"\" : \"not \");\n\tif (sqlzma_opts.try_lzma)\n\t\tprintf(\"lzmadic %u\\n\", sqlzma_opts.dicsize);\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d including %d empty files\\n\", file_count - dup_files, empty_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d including %d empty files\\n\", file_count, empty_files);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of non empty duplicate files %d\\n\", file_count - dup_files - empty_files);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tint uid = uids[i];\n\t\tstruct passwd *user = getpwuid(uid);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\nextern struct sqlzma_un un;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)buffer},\n\t\t\t{.buf = (void *)block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %d, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tswitch (sBlk->s_magic) {\n\t\tsquashfs_super_block sblk;\n\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\tbreak;\n\tcase SQUASHFS_MAGIC:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tif (!un.un_lzma)\n\t\t\tgoto bad;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\n\tbad:\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Filesystem on %s is %d.%d, which is a later filesystem version than I support\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid %s%s SQUASHFS superblock on %s.\\n\", SQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", *be ? \"big endian\" : \"little endian\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %llx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block = start; \n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dirh.inode_number + dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\tif((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tlong long sindex[indexes];\n\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length %d\\n\", i, index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_inode_t sinode;\n\t\tfor(i = 0; i < sBlk->inodes; i++) {\n\t\t\tSQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));\n\t\t\tmemcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table,\n\t\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\twrite_file(&inode, entry->dir, &duplicate_file);\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n#endif\n\n#ifdef\tCONFIG_SQUASHFS_VMALLOC\n#define SQUASHFS_ALLOC(a)\t\tvmalloc(a)\n#define SQUASHFS_FREE(a)\t\tvfree(a)\n#else\n#define SQUASHFS_ALLOC(a)\t\tkmalloc(a, GFP_KERNEL)\n#define SQUASHFS_FREE(a)\t\tkfree(a)\n#endif\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t1\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tunused;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/squashfs3.4/squashfs-tools/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define CONFIG_SQUASHFS_1_0_COMPATIBILITY\n#define CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n#include <signal.h>\n#include <pthread.h>\n#include <math.h>\n#include <sys/ioctl.h>\n#include <sys/time.h>\n\n#include <sys/sysctl.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"sqlzma.h\"\n#include \"sqmagic.h\"\n\ntypedef unsigned int UInt32;\n#ifndef FNM_EXTMATCH\n#define FNM_EXTMATCH (1 << 5)\n#endif\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\t\tprintf(\"\\n\"); \\\n\t\t\t\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar symlink[65536];\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(unsigned int block_start, unsigned int offset, struct inode **i);\n\tvoid (*read_fragment)(unsigned int fragment, long long *start_block, int *size);\n\tvoid (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, char *block_ptr, int blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block, unsigned int offset);\n} squashfs_operations;\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tint\twait_free;\n\tint\twait_pending;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tpthread_cond_t wait_for_pending;\n\tstruct cache_entry *free_list;\n\tstruct cache_entry *hash_table[65536];\n};\n\n/* struct describing a cache entry passed between threads */\nstruct cache_entry {\n\tstruct cache *cache;\n\tlong long block;\n\tint\tsize;\n\tint\tused;\n\tint error;\n\tint\tpending;\n\tstruct cache_entry *hash_next;\n\tstruct cache_entry *hash_prev;\n\tstruct cache_entry *free_next;\n\tstruct cache_entry *free_prev;\n\tchar *data;\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\tsize;\n\tint\treadp;\n\tint\twritep;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t empty;\n\tpthread_cond_t full;\n\tvoid **data;\n};\n\nstruct cache *fragment_cache, *data_cache;\nstruct queue *to_reader, *to_deflate, *to_writer, *from_writer;\npthread_t *thread, *deflator_thread;\npthread_mutex_t\tfragment_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 256\n/* default size of data buffer in Mbytes */\n#define DATA_BUFFER_DEFAULT 256\n\nsquashfs_super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nsquashfs_fragment_entry_2 *fragment_table_2;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nunsigned int block_log;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE, use_regex = FALSE, use_lzma = FALSE;\nchar **created_inode;\nint root_process;\nstruct sqlzma_un un;\nint columns;\nint rotate = 0;\npthread_mutex_t\tscreen_mutex;\npthread_cond_t progress_wait;\nint progress = TRUE, progress_enabled = FALSE;\nunsigned int total_blocks = 0, total_files = 0, total_inodes = 0;\nunsigned int cur_blocks = 0;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0}\n};\n\nvoid progress_bar(long long current, long long max, int columns);\nvoid update_progress_bar();\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tint hash = CALCULATE_HASH(entry->block);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->block)] = entry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(cache->free_list) {\n\t\tentry->free_next = cache->free_list;\n\t\tentry->free_prev = cache->free_list->free_prev;\n\t\tcache->free_list->free_prev->free_next = entry;\n\t\tcache->free_list->free_prev = entry;\n\t} else {\n\t\tcache->free_list = entry;\n\t\tentry->free_prev = entry->free_next = entry;\n\t}\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->free_prev == NULL && entry->free_next == NULL)\n\t\t/* not in free list */\n\t\treturn;\n\telse if(entry->free_prev == entry && entry->free_next == entry) {\n\t\t/* only this entry in the free list */\n\t\tcache->free_list = NULL;\n\t} else {\n\t\t/* more than one entry in the free list */\n\t\tentry->free_next->free_prev = entry->free_prev;\n\t\tentry->free_prev->free_next = entry->free_next;\n\t\tif(cache->free_list == entry)\n\t\t\tcache->free_list = entry->free_next;\n\t}\n\n\tentry->free_prev = entry->free_next = NULL;\n}\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\treturn NULL;\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct cache_entry *) * 65536);\n\tcache->wait_free = FALSE;\n\tcache->wait_pending = FALSE;\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\tpthread_cond_init(&cache->wait_for_pending, NULL);\n\n\treturn cache;\n}\n\n\nstruct cache_entry *cache_get(struct cache *cache, long long block, int size)\n{\n\t/* Get a block out of the cache.  If the block isn't in the cache\n \t * it is added and queued to the reader() and deflate() threads for reading\n \t * off disk and decompression.  The cache grows until max_blocks is reached,\n \t * once this occurs existing discarded blocks on the free list are reused */\n\tint hash = CALCULATE_HASH(block);\n\tstruct cache_entry *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->block == block)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/* found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(cache, entry);\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t} else {\n\t\t/* not in the cache */\n\t\t\n\t\t/* first try to allocate new block */\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\tentry = malloc(sizeof(struct cache_entry));\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->data = malloc(cache->buffer_size);\n\t\t\tif(entry->data == NULL) {\n\t\t\t\tfree(entry);\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t} else {\n\t\t\t/* try to get from free list */\n\t\t\twhile(cache->free_list == NULL) {\n\t\t\t\tcache->wait_free = TRUE;\n\t\t\t\tpthread_cond_wait(&cache->wait_for_free, &cache->mutex);\n\t\t\t}\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(cache, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t}\n\n\t\t/* initialise block and insert into the hash table */\n\t\tentry->block = block;\n\t\tentry->size = size;\n\t\tentry->used = 1;\n\t\tentry->error = FALSE;\n\t\tentry->pending = TRUE;\n\t\tinsert_hash_table(cache, entry);\n\n\t\t/* queue to read thread to read and ultimately (via the decompress\n \t\t * threads) decompress the buffer\n \t\t */\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t\tqueue_put(to_reader, entry);\n\t}\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\treturn NULL;\n}\n\n\t\nvoid cache_block_ready(struct cache_entry *entry, int error)\n{\n\t/* mark cache entry as being complete, reading and (if necessary)\n \t * decompression has taken place, and the buffer is valid for use.\n \t * If an error occurs reading or decompressing, the buffer also \n \t * becomes ready but with an error... */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\tentry->pending = FALSE;\n\tentry->error = error;\n\n\t/* if the wait_pending flag is set, one or more threads may be waiting on\n \t * this buffer */\n\tif(entry->cache->wait_pending) {\n\t\tentry->cache->wait_pending = FALSE;\n\t\tpthread_cond_broadcast(&entry->cache->wait_for_pending);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_wait(struct cache_entry *entry)\n{\n\t/* wait for this cache entry to become ready, when reading and (if necessary)\n \t * decompression has taken place */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\twhile(entry->pending) {\n\t\tentry->cache->wait_pending = TRUE;\n\t\tpthread_cond_wait(&entry->cache->wait_for_pending, &entry->cache->mutex);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_put(struct cache_entry *entry)\n{\n\t/* finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and is put onto the free list.  As it remains accessible\n \t * via the hash table it can be found getting a new lease of life before it\n \t * is reused. */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tinsert_free_list(entry->cache, entry);\n\n\t\t/* if the wait_free flag is set, one or more threads may be waiting on\n \t \t * this buffer */\n\t\tif(entry->cache->wait_free) {\n\t\t\tentry->cache->wait_free = FALSE;\n\t\t\tpthread_cond_broadcast(&entry->cache->wait_for_free);\n\t\t}\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\t/* printf(\"i%d \", inode->inode_number); */\n\n\tif((user = getpwuid(inode->uid)) == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tif((group = getgrgid(inode->gid)) == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0, inode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) - strlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \", (int) inode->data >> 8, (int) inode->data & 0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)buffer},\n\t\t\t{.buf = (void *)block, .sz = bytes}\n\t\t};\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tsbuf[Src].sz = c_byte;\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)data, .sz = c_byte},\n\t\t\t{.buf = (void *)block, .sz = bytes}\n\t\t};\n\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\tprintf(\"la _n\");\n\t\tres = sqlzma_un(&un, sbuf + Src, sbuf + Dst);\n\t\tif (res)\n\t\t\tabort();\n\t\tbytes = un.un_reslen;\n\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid read_block_list(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nvoid read_block_list_1(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) | (SQUASHFS_COMPRESSED(block_size) ? 0 : SQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time, unsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids()\n{\n\tif((uid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) suid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n\t\tSQUASHFS_SWAP_INTS(uid_table, suid_table, sBlk.no_uids + sBlk.no_guids);\n\t} else\n\t\tif(read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t\t* sizeof(unsigned int), (char *) uid_table) ==\n\t\t\t\tFALSE)\n\t\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_2()\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk.fragments, indexes, sBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table_2 = (squashfs_fragment_entry_2 *)\n\t\t\tmalloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk.fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t((char *) fragment_table_2) + (i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%x, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment), (&fragment_table_2[i]));\n\t\t\tmemcpy((char *) &fragment_table_2[i], (char *) &sfragment, sizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n}\n\n\nvoid read_fragment_table_1()\n{\n}\n\n\nvoid read_fragment(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nvoid read_fragment_2(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table_2[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data;\n\nint write_block(int file_fd, char *buffer, int size, int hole)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(lseek_broken == FALSE && lseek(file_fd, off, SEEK_CUR) == -1) {\n\t\t\t/* failed to seek beyond end of file */\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t\tlseek_broken = TRUE;\n\t\t}\n\t\tif(lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size : hole;\n\t\t\t\tif(write(file_fd, zero_data, avail_bytes) < avail_bytes)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t}\n\n\tif(write(file_fd, buffer, size) < size)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\nstruct file_entry {\n\tint offset;\n\tint size;\n\tstruct cache_entry *buffer;\n};\n\n\nstruct squashfs_file {\n\tint fd;\n\tint blocks;\n\tlong long file_size;\n\tint mode;\n\tuid_t uid;\n\tgid_t gid;\n\ttime_t time;\n\tchar *pathname;\n};\n\n\nint write_file(struct inode *inode, char *pathname)\n{\n\tunsigned int file_fd, i;\n\tunsigned int *block_list;\n\tint file_end = inode->data / block_size;\n\tlong long start = inode->start;\n\tstruct squashfs_file *file;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", inode->blocks);\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0), (mode_t) inode->mode & 0777)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif((block_list = malloc(inode->blocks * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc block list\\n\");\n\n\ts_ops.read_block_list(block_list, inode->block_ptr, inode->blocks);\n\n\tif((file = malloc(sizeof(struct squashfs_file))) == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\n\t/* the writer thread is queued a squashfs_file structure describing the\n \t * file.  If the file has one or more blocks or a fragments they are queued\n \t * separately (references to blocks in the cache). */\n\tfile->fd = file_fd;\n\tfile->file_size = inode->data;\n\tfile->mode = inode->mode;\n\tfile->gid = inode->gid;\n\tfile->uid = inode->uid;\n\tfile->time = inode->time;\n\tfile->pathname = strdup(pathname);\n\tfile->blocks = inode->blocks + (inode->frag_bytes > 0);\n\tqueue_put(to_writer, file);\n\n\tfor(i = 0; i < inode->blocks; i++) {\n\t\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry *));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\tblock->offset = 0;\n\t\tblock->size = i == file_end ? inode->data & (block_size - 1) : block_size;\n\t\tif(block_list[i] == 0) /* sparse file */\n\t\t\tblock->buffer = NULL;\n\t\telse {\n\t\t\tblock->buffer = cache_get(data_cache, start, block_list[i]);\n\t\t\tif(block->buffer == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_file: cache_get failed\\n\");\n\t\t\tstart += c_byte;\n\t\t}\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tif(inode->frag_bytes) {\n\t\tint size;\n\t\tlong long start;\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry *));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\ts_ops.read_fragment(inode->fragment, &start, &size);\n\t\tblock->buffer = cache_get(fragment_cache, start, size);\n\t\tif(block->buffer == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: cache_get failed\\n\");\n\t\tblock->offset = inode->offset;\n\t\tblock->size = inode->frag_bytes;\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tfree(block_list);\n\treturn TRUE;\n}\n\n\nstatic struct inode *read_inode(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i, pathname))\n\t\t\t\tfile_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %lld\\n\", i->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%llx\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\tmakedev((i->data >> 8) & 0xff, i->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tchrdev ? \"character\" : \"block\", pathname);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid, i->time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", i->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_2 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode, sizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[header.base.uid];\n    i.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_2), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_2!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_1 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\tstatic int inode_number = 1;\n\n\tif(bytes == -1)\n\t\tgoto error;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode, sizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n    i.uid = (uid_t) uid_table[(header.base.inode_type - 1) / SQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) % SQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n    i.gid = header.base.guid == 15 ? i.uid : (uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep = &header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tstrncpy(i.symlink, block_ptr + sizeof(squashfs_symlink_inode_header_1), inodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_1!\\n\", header.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n\nerror:\n\treturn NULL;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_opendir(unsigned int block_start, unsigned int offset, struct inode **i)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif((*i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nstruct dir *squashfs_opendir_2(unsigned int block_start, unsigned int offset, struct inode **i)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(((*i) = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) * sizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname, REG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, because %s\\n\", targname, alltarget, str);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf component of a\n\t\t   \t   pre-existing extract which subsumes the extract currently\n\t\t   \t   being added, in which case stop adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist from more\n\t\t       specific extracts, delete as they're subsumed by this extract\n\t\t\t*/\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames *));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) + (paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0, NULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/* match on a leaf component, any subdirectories will\n\t\t\t\t * implicitly match, therefore return an empty new search set */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any subdirectories to\n\t\t\t\t * the new set of subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/* no matching names found, delete empty search set, and return\n        * FALSE */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches),\n     * return new search set and return TRUE */\n\treturn TRUE;\n\nempty_set:\n   /* found matching leaf exclude, return empty search set and return TRUE */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nint pre_scan(char *parent_name, unsigned int start_block, unsigned int offset, struct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(dir == NULL) {\n\t\tERROR(\"pre_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"pre_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tpre_scan(parent_name, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif(type == SQUASHFS_FILE_TYPE || type == SQUASHFS_LREG_TYPE) {\n\t\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(created_inode[i->inode_number - 1] == NULL) {\n\t\t\t\t\tcreated_inode[i->inode_number - 1] = (char *) i;\n\t\t\t\t\ttotal_blocks += (i->data + (block_size - 1)) >> block_log;\n\t\t\t\t}\n\t\t\t\ttotal_files ++;\n\t\t\t}\n\t\t\ttotal_inodes ++;\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tsquashfs_closedir(dir);\n\n\treturn TRUE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, struct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(parent_name, i);\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 && (!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly) {\n\t\t\t\tcreate_inode(pathname, i);\n\t\t\t\tupdate_progress_bar();\n\t\t\t\t}\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tif(!lsonly)\n\t\tset_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\tunsigned char b[5];\n\tint offset, dicSize, i;\n\t\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"little\" : \"big\", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tprintf(\"Found a valid %s endian SQUASHFS %d:%d superblock on %s.\\n\", swap ? \"big\" : \"little\", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str : \"failed to get time\\n\");\n\tprintf(\"Filesystem is %sexportable via NFS\\n\", SQUASHFS_EXPORTABLE(sBlk.flags) ? \"\" : \"not \");\n\n\tprintf(\"Inodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tif(sBlk.s_major > 1 && !SQUASHFS_NO_FRAGMENTS(sBlk.flags))\n\t\tprintf(\"Fragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Check data is %spresent in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not \");\n\tif(sBlk.s_major > 1) {\n\t\tprintf(\"Fragments are %spresent in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not \" : \"\");\n\t\tprintf(\"Always_use_fragments option is %sspecified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not \");\n\t} else\n\t\tprintf(\"Fragments are not supported by the filesystem\\n\");\n\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\", SQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\tif(sBlk.s_major > 2)\n\t\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\telse\n\t\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk.bytes_used_2 / 1024.0, sBlk.bytes_used_2 / (1024.0 * 1024.0));\n\tprintf(\"Block size %d\\n\", sBlk.block_size);\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.fragments);\n\tprintf(\"Number of inodes %d\\n\", sBlk.inodes);\n\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\toffset =-1;\n\tif (!SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags)) {\n\t\toffset = 0x77;\n\t}\n\telse if (!SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags)) {\n\t\toffset = sBlk.inode_table_start + 2;\n\t}\n\telse if (!SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags)) {\n        \toffset = sBlk.directory_table_start + 2;\n        }\n\telse if (!SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) && (sBlk.s_major > 1)) {\n\t\toffset = sBlk.fragment_table_start +  SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments) + 2 ;\n\t}\n\tif (offset != -1) {\n\t\tread_bytes(SQUASHFS_START + offset, sizeof(b), (char *) b);\n\t\tif (b[0] == 0x5d ) {\n        \t\tdicSize =b[1] | ((UInt32)b[2] << 8) | ((UInt32)b[3] << 16) | ((UInt32)b[4] << 24);\n        \t\tprintf(\"Dictionary size  %u \\n\",dicSize);\n\t\t}\n\t}\n\n\tprintf(\"Used bytes  0x%llx\\n\", sBlk.bytes_used);\n\tprintf(\"Inode table starts at  0x%llx\\n\", sBlk.inode_table_start);\n\tprintf(\"Directory table starts at 0x%llx\\n\", sBlk.directory_table_start);\n\tprintf(\"UID list starts at 0x%llx\\n\", sBlk.uid_start);\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Fragment table starts at 0x%llx\\n\\n\", sBlk.fragment_table_start);\n\n/*\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\tif(sBlk.s_major > 1)\n\t\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\", sBlk.fragment_table_start);\n*/\n}\n\n\nint read_super(char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tun.un_lzma = 1;\n\tswap = 0;\n\tswitch (sBlk.s_magic) {\n\t\tsquashfs_super_block sblk;\n\tcase SQUASHFS_MAGIC:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA:\n\t\tbreak;\n\tcase SQUASHFS_MAGIC_SWAP:\n\t\tun.un_lzma = 0;\n\t\t/*FALLTHROUGH*/\n\tcase SQUASHFS_MAGIC_LZMA_SWAP:\n\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, &sBlk);\n\t\tmemcpy(&sBlk, &sblk, sizeof(squashfs_super_block));\n\t\tswap = 1;\n\t\tbreak;\n\tdefault:\n\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\tgoto failed_mount;\n \t}\n\tif (use_lzma)\n\t\tun.un_lzma=1;\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 1 || sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk.bytes_used_2;\n\t\tsBlk.uid_start = sBlk.uid_start_2;\n\t\tsBlk.guid_start = sBlk.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s_major == 1) {\n\t\t\tsBlk.block_size = sBlk.block_size_1;\n\t\t\tsBlk.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t} else {\n\t\t\tsBlk.fragment_table_start = sBlk.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_2;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t}\n\t} else if(sBlk.s_major == 3 && sBlk.s_minor <= 1) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir;\n\t\ts_ops.read_fragment = read_fragment;\n\t\ts_ops.read_fragment_table = read_fragment_table;\n\t\ts_ops.read_block_list = read_block_list;\n\t\ts_ops.read_inode = read_inode;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s_major, sBlk.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tif((fd = fopen(filename, \"r\")) == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename, strerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n/* reader thread.  This thread processes read requests queued by the\n * cache_get() routine. */\nvoid *reader(void *arg)\n{\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_reader);\n\t\tint res = read_bytes(entry->block,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size),\n\t\t\tentry->data);\n\n\t\tif(res && SQUASHFS_COMPRESSED_BLOCK(entry->size))\n\t\t\t/* queue successfully read block to the deflate thread(s)\n \t\t\t * for further processing */\n\t\t\tqueue_put(to_deflate, entry);\n\t\telse\n\t\t\t/* block has either been successfully read and is uncompressed,\n \t\t\t * or an error has occurred, clear pending flag, set\n \t\t\t * error appropriately, and wake up any threads waiting on\n \t\t\t * this buffer */\n\t\t\tcache_block_ready(entry, !res);\n\t}\n}\n\n\n/* writer thread.  This processes file write requests queued by the\n * write_file() routine. */\nvoid *writer(void *arg)\n{\n\tint i;\n\n\twhile(1) {\n\t\tstruct squashfs_file *file = queue_get(to_writer);\n\t\tint file_fd;\n\t\tint hole = 0;\n\t\tint failed = FALSE;\n\n\t\tif(file == NULL) {\n\t\t\tqueue_put(from_writer, NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\tTRACE(\"writer: regular file, blocks %d\\n\", file->blocks);\n\n\t\tfile_fd = file->fd;\n\n\t\tfor(i = 0; i < file->blocks; i++, cur_blocks ++) {\n\t\t\tstruct file_entry *block = queue_get(to_writer);\n\n\t\t\tif(block->buffer == 0) { /* sparse file */\n\t\t\t\thole += block->size;\n\t\t\t\tfree(block);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcache_block_wait(block->buffer);\n\n\t\t\tif(block->buffer->error)\n\t\t\t\tfailed = TRUE;\n\n\t\t\tif(failed == FALSE && write_block(file_fd, block->buffer->data + block->offset, block->size, hole) == FALSE) {\n\t\t\t\tERROR(\"writer: failed to write data block %d\\n\", i);\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\t\t\thole = 0;\n\t\t\tcache_block_put(block->buffer);\n\t\t\tfree(block);\n\t\t}\n\n\t\tif(hole && failed == FALSE) {\n\t\t\t/* corner case for hole extending to end of file */\n\t\t\tif(lseek(file_fd, hole, SEEK_CUR) == -1) {\n\t\t\t\t/* for broken lseeks which cannot seek beyond end of\n \t\t\t \t* file, write_block will do the right thing */\n\t\t\t\thole --;\n\t\t\t\tif(write_block(file_fd, \"\\0\", 1, hole) == FALSE) {\n\t\t\t\t\tERROR(\"writer: failed to write sparse data block\\n\");\n\t\t\t\t\tfailed = TRUE;\n\t\t\t\t}\n\t\t\t} else if(ftruncate(file_fd, file->file_size) == -1) {\n\t\t\t\tERROR(\"writer: failed to write sparse data block\\n\");\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\t\t}\n\n\t\tclose(file_fd);\n\t\tif(failed == FALSE)\n\t\t\tset_attributes(file->pathname, file->mode, file->uid, file->gid, file->time, force);\n\t\telse {\n\t\t\tERROR(\"Failed to write %s, skipping\\n\", file->pathname);\n\t\t\tunlink(file->pathname);\n\t\t}\n\t\tfree(file->pathname);\n\t\tfree(file);\n\n\t}\n}\n\n\n/* decompress thread.  This decompresses buffers queued by the read thread */\nvoid *deflator(void *arg)\n{\n\tchar tmp[block_size];\n\tstruct sqlzma_un *thread_un = (struct sqlzma_un *) arg;\n\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_deflate);\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tenum {Src, Dst};\n\t\tstruct sized_buf sbuf[] = {\n\t\t\t{.buf = (void *)entry->data, .sz = SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size)},\n\t\t\t{.buf = (void *)tmp, .sz = bytes}\n\t\t};\n\n\t\tres = sqlzma_un(thread_un, sbuf + Src, sbuf + Dst);\n\t\tif(res)\n\t\t\tabort();\n\t\tbytes = thread_un->un_reslen;\n\t\tmemcpy(entry->data, tmp, bytes);\n\n\t\t/* block has been either successfully decompressed, or an error\n \t\t * occurred, clear pending flag, set error appropriately and\n \t\t * wake up any threads waiting on this block */ \n\t\tcache_block_ready(entry, res != Z_OK);\n\t}\n}\n\n\nvoid *progress_thread(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tERROR(\"TIOCGWINZ ioctl failed, defaulting to 80 columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&screen_mutex);\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) * 1000;\n\t\tpthread_cond_timedwait(&progress_wait, &screen_mutex, &timespec);\n\t\tif(progress_enabled)\n\t\t\tprogress_bar(sym_count + dev_count +\n\t\t\t\tfifo_count + cur_blocks, total_inodes - total_files +\n\t\t\t\ttotal_blocks, columns);\n\t}\n}\n\n\nvoid initialise_threads(int fragment_buffer_size, int data_buffer_size)\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\tint all_buffers_size = fragment_buffer_size + data_buffer_size;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((3 + processors) * sizeof(pthread_t))) == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[3];\n\n\tto_reader = queue_init(all_buffers_size);\n\tto_deflate = queue_init(all_buffers_size);\n\tto_writer = queue_init(1000);\n\tfrom_writer = queue_init(1);\n\tfragment_cache = cache_init(block_size, fragment_buffer_size);\n\tdata_cache = cache_init(block_size, data_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&thread[2], NULL, progress_thread, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tstruct sqlzma_un *thread_un = malloc(sizeof(struct sqlzma_un));\n\t\tif(thread_un == NULL)\n\t\t\tEXIT_UNSQUASH(\"Failed to allocate memory for sqlzma_un\\n\");\n\t\tif(sqlzma_init(thread_un, un.un_lzma, 0) != Z_OK)\n\t\t\tEXIT_UNSQUASH(\"Failed to initialize: sqlzma_init\\n\");\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, thread_un) != 0 )\n\t\t\tEXIT_UNSQUASH(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel unsquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid update_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits = floor(log10(max)) + 1;\n\tint used = max_digits * 2 + 11;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\n\tif(current > max) {\n\t\tprintf(\"%lld %lld\\n\", current, max);\n\t\treturn;\n\t}\n\n\tif(columns - used < 0)\n\t\treturn;\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 3.4 (2008/08/26)\\n\");\\\n\tprintf(\"copyright (C) 2008 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\\\n\tprintf(\"\\nand LZMA %s support for slax.org by jro.\\n\",LZMA_VERSION);\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tint n;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\tint fragment_buffer_size = FRAGMENT_BUFFER_DEFAULT;\n\tint data_buffer_size = DATA_BUFFER_DEFAULT;\n\tchar *b;\n\tstruct winsize winsize;\n\n\tpthread_mutex_init(&screen_mutex, NULL);\n\troot_process = geteuid() == 0;\n\tif(root_process)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 || strcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 || strcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0 || strcmp(argv[i], \"-n\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 || strcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-processors\") == 0 || strcmp(argv[i], \"-p\") == 0) {\n\t\t\tif((++i == argc) || (processors = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-data-queue\") == 0 || strcmp(argv[i], \"-da\") == 0) {\n\t\t\tif((++i == argc) || (data_buffer_size = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -data-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(data_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -data-queue should be 1 Mbyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-frag-queue\") == 0 || strcmp(argv[i], \"-fr\") == 0) {\n\t\t\tif((++i == argc) || (fragment_buffer_size = strtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -frag-queue missing or invalid queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragment_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -frag-queue should be 1 Mbyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 || strcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 || strcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 || strcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 || strcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 || strcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 || strcmp(argv[i], \"-r\") == 0) {\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-lzma\") == 0)\n\t\t\tuse_lzma = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(lsonly || info)\n\t\tprogress = FALSE;\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-n[o-progress]\\t\\tdon't display the progress bar\\n\");\n\t\t\tERROR(\"\\t-p[rocessors] <number>\\tuse <number> processors.  By default will use\\n\\t\\t\\t\\tnumber of processors available\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are unsquashed with file\\n\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file attributes (like\\n\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-da[ta-queue] <size>\\tSet data queue to <size> Mbytes.  Default %d\\n\\t\\t\\t\\tMbytes\\n\", DATA_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-fr[ag-queue] <size>\\tSet fagment queue to <size> Mbytes.  Default %d\\n\\t\\t\\t\\tMbytes\\n\", FRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX regular expressions\\n\\t\\t\\t\\trather than use the default shell wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t\tERROR(\"\\t-lzma\\t\\t\\tuse lzma as compression method\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tblock_size = sBlk.block_size;\n\tblock_log = sBlk.block_log;\n\n\tfragment_buffer_size <<= 20 - block_log;\n\tdata_buffer_size <<= 20 - block_log;\n\tinitialise_threads(fragment_buffer_size, data_buffer_size);\n\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate data\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\ti = sqlzma_init(&un, un.un_lzma, 0);\n\tif (i != Z_OK) {\n\t\tfputs(\"sqlzma_init failed\", stderr);\n\t\tabort();\n\t}\n\n\tread_uids_guids();\n\n\ts_ops.read_fragment_table();\n\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start);\n\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start);\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tpre_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tprintf(\"%d inodes (%d blocks) to write\\n\\n\", total_inodes, total_inodes - total_files + total_blocks);\n\n\tif(progress)\n\t\tenable_progress_bar();\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tqueue_put(to_writer, NULL);\n\tqueue_get(from_writer);\n\n\tif(progress) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(sym_count + dev_count + fifo_count + cur_blocks,\n\t\t\ttotal_inodes - total_files + total_blocks, columns);\n\t}\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-3.4-nb4/unsquashfs-lzma",
    "content": "#!/bin/bash\n\n./unsquashfs -lzma $@\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/Makefile",
    "content": "INCLUDEDIR = -I. -I./lzma/C \nLZMAPATH = ./lzma/C/LzmaLib\n\nUSE_LZMA = 1\n\nifdef USE_LZMA\n  LZMA_CFLAGS = -DUSE_LZMA\n  LZMA_LIB = -L$(LZMAPATH) -llzma\n  CFLAGS += $(LZMA_CFLAGS)\nendif\n\nCFLAGS := $(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -O2\n\nUSE_LZMA = 1\n\nifdef USE_LZMA\n  LZMA_CFLAGS = -DUSE_LZMA\n  LZMA_LIB = -L$(LZMAPATH) -llzma\n  CFLAGS += $(LZMA_CFLAGS)\nendif\n\nall: mksquashfs-lzma unsquashfs-lzma\n\nmksquashfs-lzma: mksquashfs.o read_fs.o sort.o swap.o pseudo.o uncompress.o\n\tmake -C $(LZMAPATH)\n\t$(CC) mksquashfs.o read_fs.o sort.o swap.o pseudo.o uncompress.o -lz -lpthread -lm $(LZMA_LIB) -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h squashfs_swap.h uncompress.h Makefile\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h squashfs_swap.h uncompress.h Makefile\n\nsort.o: sort.c squashfs_fs.h global.h sort.h Makefile\n\nswap.o: swap.c Makefile\n\npseudo.o: pseudo.c pseudo.h Makefile\n\nuncompress.o: uncompress.c uncompress.h\n\nunsquashfs-lzma: unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o unsquash-4.o swap.o uncompress.o\n\t$(CC) unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o unsquash-4.o swap.o uncompress.o -lz -lpthread -lm $(LZMA_LIB) -o $@\n\nunsquashfs.o: unsquashfs.h unsquashfs.c squashfs_fs.h squashfs_swap.h squashfs_compat.h global.h uncompress.h Makefile\n\nunsquash-1.o: unsquashfs.h unsquash-1.c squashfs_fs.h squashfs_compat.h global.h uncompress.h Makefile\n\nunsquash-2.o: unsquashfs.h unsquash-2.c unsquashfs.h squashfs_fs.h squashfs_compat.h global.h uncompress.h Makefile\n\nunsquash-3.o: unsquashfs.h unsquash-3.c squashfs_fs.h squashfs_compat.h global.h uncompress.h Makefile\n\nunsquash-4.o: unsquashfs.h unsquash-4.c squashfs_fs.h squashfs_swap.h global.h uncompress.h Makefile\n\nclean:\n\t-rm -f *.o mksquashfs-lzma unsquashfs-lzma\n\ninstall: mksquashfs unsquashfs\n\tmkdir -p $(INSTALL_DIR)\n\tcp mksquashfs $(INSTALL_DIR)\n\tcp unsquashfs $(INSTALL_DIR)\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/README-4.0",
    "content": "\tSQUASHFS 4.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2009 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs 4.0.  This is an initial tools only release to\nsupport users of the 2.6.29 kernel, following the mainlining of Squashfs\nearlier this year.\n\nLater releases will probably contain kernel patches supporting 4.0\nlayouts for earlier kernels.\n\nNew Mksquashfs options\n----------------------\n\nMksquashfs now supports pseudo files, these allow fake directories, character\nand block devices to be specified and added to the Squashfs filesystem being\nbuilt, rather than requiring them to be present in the source directories.\nThis, for example, allows device nodes to be added to the filesystem without\nrequiring root access.\n\nTwo options are supported, -p allows one pseudo file to be specified on the\ncommand line, and -pf allows a pseudo file to be specified containing a\nlist of pseduo definitions, one per line.\n\nPseudo device nodes are specified using 7 arguments\n\nFilename type mode uid gid major minor\n\nWhere type is either\n\tb - for block devices, and\n\tc - for character devices\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nUid and gid can be either specified as a decimal number, or by name.\n\nFor example:\n\n/dev/chr_dev c 666 root root 100 1\n/dev/blk_dev b 444 0 0 200 200\n\nDirectories are specified using 5 arguments\n\nFilename type mode uid gid\n\nWhere type is d.\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\ntypedef unsigned int squashfs_id;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/7zC.txt",
    "content": "7z ANSI-C Decoder 4.62\r\n----------------------\r\n\r\n7z ANSI-C provides 7z/LZMA decoding.\r\n7z ANSI-C version is simplified version ported from C++ code.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\n7z ANSI-C Decoder is part of the LZMA SDK.\r\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\r\n\r\nFiles\r\n---------------------\r\n\r\n7zDecode.*   - Low level 7z decoding\r\n7zExtract.*  - High level 7z decoding\r\n7zHeader.*   - .7z format constants\r\n7zIn.*       - .7z archive opening\r\n7zItem.*     - .7z structures\r\n7zMain.c     - Test application\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nYou must download 7-Zip program from www.7-zip.org.\r\n\r\nYou can create .7z archive with 7z.exe or 7za.exe:\r\n\r\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255\r\n\r\nIf you have big number of files in archive, and you need fast extracting, \r\nyou can use partly-solid archives:\r\n  \r\n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\r\n\r\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r\n512KB for extracting one file from such archive.\r\n\r\n\r\nLimitations of current version of 7z ANSI-C Decoder\r\n---------------------------------------------------\r\n\r\n - It reads only \"FileName\", \"Size\", \"LastWriteTime\" and \"CRC\" information for each file in archive.\r\n - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.\r\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r\n \r\nThese limitations will be fixed in future versions.\r\n\r\n\r\nUsing 7z ANSI-C Decoder Test application:\r\n-----------------------------------------\r\n\r\nUsage: 7zDec <command> <archive_name>\r\n\r\n<Command>:\r\n  e: Extract files from archive\r\n  l: List contents of archive\r\n  t: Test integrity of archive\r\n\r\nExample: \r\n\r\n  7zDec l archive.7z\r\n\r\nlists contents of archive.7z\r\n\r\n  7zDec e archive.7z\r\n\r\nextracts files from archive.7z to current folder.\r\n\r\n\r\nHow to use .7z Decoder\r\n----------------------\r\n\r\nMemory allocation\r\n~~~~~~~~~~~~~~~~~\r\n\r\n7z Decoder uses two memory pools:\r\n1) Temporary pool\r\n2) Main pool\r\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\r\n\r\n\r\nSteps for using 7z decoder\r\n--------------------------\r\n\r\nUse code at 7zMain.c as example.\r\n\r\n1) Declare variables:\r\n  inStream                 /* implements ILookInStream interface */\r\n  CSzArEx db;              /* 7z archive database structure */\r\n  ISzAlloc allocImp;       /* memory functions for main pool */\r\n  ISzAlloc allocTempImp;   /* memory functions for temporary pool */\r\n\r\n2) call CrcGenerateTable(); function to initialize CRC structures.\r\n\r\n3) call SzArEx_Init(&db); function to initialize db structures.\r\n\r\n4) call SzArEx_Open(&db, inStream, &allocMain, &allocTemp) to open archive\r\n\r\nThis function opens archive \"inStream\" and reads headers to \"db\".\r\nAll items in \"db\" will be allocated with \"allocMain\" functions.\r\nSzArEx_Open function allocates and frees temporary structures by \"allocTemp\" functions.\r\n\r\n5) List items or Extract items\r\n\r\n  Listing code:\r\n  ~~~~~~~~~~~~~\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.db.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n\r\n  Extracting code:\r\n  ~~~~~~~~~~~~~~~~\r\n\r\n  SZ_RESULT SzAr_Extract(\r\n    CArchiveDatabaseEx *db,\r\n    ILookInStream *inStream, \r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n  If you need to decompress more than one file, you can send these values from previous call:\r\n    blockIndex, \r\n    outBuffer, \r\n    outBufferSize,\r\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \r\n  it will increase decompression speed.\r\n\r\n  After decompressing you must free \"outBuffer\":\r\n  allocImp.Free(outBuffer);\r\n\r\n6) call SzArEx_Free(&db, allocImp.Free) to free allocated items in \"db\".\r\n\r\n\r\n\r\n\r\nMemory requirements for .7z decoding \r\n------------------------------------\r\n\r\nMemory usage for Archive opening:\r\n  - Temporary pool:\r\n     - Memory for uncompressed .7z headers\r\n     - some other temporary blocks\r\n  - Main pool:\r\n     - Memory for database: \r\n       Estimated size of one file structures in solid archive:\r\n         - Size (4 or 8 Bytes)\r\n         - CRC32 (4 bytes)\r\n         - LastWriteTime (8 bytes)\r\n         - Some file information (4 bytes)\r\n         - File Name (variable length) + pointer + allocation structures\r\n\r\nMemory usage for archive Decompressing:\r\n  - Temporary pool:\r\n     - Memory for LZMA decompressing structures\r\n  - Main pool:\r\n     - Memory for decompressed solid block\r\n     - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these \r\n       temprorary buffers can be about 15% of solid block size. \r\n  \r\n\r\n7z Decoder doesn't allocate memory for compressed blocks. \r\nInstead of this, you must allocate buffer with desired \r\nsize before calling 7z Decoder. Use 7zMain.c as example.\r\n\r\n\r\nDefines\r\n-------\r\n\r\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/sdk.html\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\r\n-----------------------------------\r\n\r\nThis file contains description of 7z archive format. \r\n7z archive can contain files compressed with any method.\r\nSee \"Methods.txt\" for description for defined compressing methods.\r\n\r\n\r\nFormat structure Overview\r\n-------------------------\r\n\r\nSome fields can be optional.\r\n\r\nArchive structure\r\n~~~~~~~~~~~~~~~~~  \r\nSignatureHeader\r\n[PackedStreams]\r\n[PackedStreamsForHeaders]\r\n[\r\n  Header \r\n  or \r\n  {\r\n    Packed Header\r\n    HeaderInfo\r\n  }\r\n]\r\n\r\n\r\n\r\nHeader structure\r\n~~~~~~~~~~~~~~~~  \r\n{\r\n  ArchiveProperties\r\n  AdditionalStreams\r\n  {\r\n    PackInfo\r\n    {\r\n      PackPos\r\n      NumPackStreams\r\n      Sizes[NumPackStreams]\r\n      CRCs[NumPackStreams]\r\n    }\r\n    CodersInfo\r\n    {\r\n      NumFolders\r\n      Folders[NumFolders]\r\n      {\r\n        NumCoders\r\n        CodersInfo[NumCoders]\r\n        {\r\n          ID\r\n          NumInStreams;\r\n          NumOutStreams;\r\n          PropertiesSize\r\n          Properties[PropertiesSize]\r\n        }\r\n        NumBindPairs\r\n        BindPairsInfo[NumBindPairs]\r\n        {\r\n          InIndex;\r\n          OutIndex;\r\n        }\r\n        PackedIndices\r\n      }\r\n      UnPackSize[Folders][Folders.NumOutstreams]\r\n      CRCs[NumFolders]\r\n    }\r\n    SubStreamsInfo\r\n    {\r\n      NumUnPackStreamsInFolders[NumFolders];\r\n      UnPackSizes[]\r\n      CRCs[]\r\n    }\r\n  }\r\n  MainStreamsInfo\r\n  {\r\n    (Same as in AdditionalStreams)\r\n  }\r\n  FilesInfo\r\n  {\r\n    NumFiles\r\n    Properties[]\r\n    {\r\n      ID\r\n      Size\r\n      Data\r\n    }\r\n  }\r\n}\r\n\r\nHeaderInfo structure\r\n~~~~~~~~~~~~~~~~~~~~\r\n{\r\n  (Same as in AdditionalStreams)\r\n}\r\n\r\n\r\n\r\nNotes about Notation and encoding\r\n---------------------------------\r\n\r\n7z uses little endian encoding.\r\n\r\n7z archive format has optional headers that are marked as\r\n[]\r\nHeader\r\n[]\r\n\r\nREAL_UINT64 means real UINT64.\r\n\r\nUINT64 means real UINT64 encoded with the following scheme:\r\n\r\n  Size of encoding sequence depends from first byte:\r\n  First_Byte  Extra_Bytes        Value\r\n  (binary)   \r\n  0xxxxxxx               : ( xxxxxxx           )\r\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r\n  ...\r\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r\n  11111110    BYTE y[7]  :                         y\r\n  11111111    BYTE y[8]  :                         y\r\n\r\n\r\n\r\nProperty IDs\r\n------------\r\n\r\n0x00 = kEnd,\r\n\r\n0x01 = kHeader,\r\n\r\n0x02 = kArchiveProperties,\r\n    \r\n0x03 = kAdditionalStreamsInfo,\r\n0x04 = kMainStreamsInfo,\r\n0x05 = kFilesInfo,\r\n    \r\n0x06 = kPackInfo,\r\n0x07 = kUnPackInfo,\r\n0x08 = kSubStreamsInfo,\r\n\r\n0x09 = kSize,\r\n0x0A = kCRC,\r\n\r\n0x0B = kFolder,\r\n\r\n0x0C = kCodersUnPackSize,\r\n0x0D = kNumUnPackStream,\r\n\r\n0x0E = kEmptyStream,\r\n0x0F = kEmptyFile,\r\n0x10 = kAnti,\r\n\r\n0x11 = kName,\r\n0x12 = kCreationTime,\r\n0x13 = kLastAccessTime,\r\n0x14 = kLastWriteTime,\r\n0x15 = kWinAttributes,\r\n0x16 = kComment,\r\n\r\n0x17 = kEncodedHeader,\r\n\r\n\r\n7z format headers\r\n-----------------\r\n\r\nSignatureHeader\r\n~~~~~~~~~~~~~~~\r\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n\r\n  ArchiveVersion\r\n  {\r\n    BYTE Major;   // now = 0\r\n    BYTE Minor;   // now = 2\r\n  };\r\n\r\n  UINT32 StartHeaderCRC;\r\n\r\n  StartHeader\r\n  {\r\n    REAL_UINT64 NextHeaderOffset\r\n    REAL_UINT64 NextHeaderSize\r\n    UINT32 NextHeaderCRC\r\n  }\r\n\r\n\r\n...........................\r\n\r\n\r\nArchiveProperties\r\n~~~~~~~~~~~~~~~~~\r\nBYTE NID::kArchiveProperties (0x02)\r\nfor (;;)\r\n{\r\n  BYTE PropertyType;\r\n  if (aType == 0)\r\n    break;\r\n  UINT64 PropertySize;\r\n  BYTE PropertyData[PropertySize];\r\n}\r\n\r\n\r\nDigests (NumStreams)\r\n~~~~~~~~~~~~~~~~~~~~~\r\n  BYTE AllAreDefined\r\n  if (AllAreDefined == 0)\r\n  {\r\n    for(NumStreams)\r\n      BIT Defined\r\n  }\r\n  UINT32 CRCs[NumDefined]\r\n\r\n\r\nPackInfo\r\n~~~~~~~~~~~~\r\n  BYTE NID::kPackInfo  (0x06)\r\n  UINT64 PackPos\r\n  UINT64 NumPackStreams\r\n\r\n  []\r\n  BYTE NID::kSize    (0x09)\r\n  UINT64 PackSizes[NumPackStreams]\r\n  []\r\n\r\n  []\r\n  BYTE NID::kCRC      (0x0A)\r\n  PackStreamDigests[NumPackStreams]\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFolder\r\n~~~~~~\r\n  UINT64 NumCoders;\r\n  for (NumCoders)\r\n  {\r\n    BYTE \r\n    {\r\n      0:3 DecompressionMethod.IDSize\r\n      4:\r\n        0 - IsSimple\r\n        1 - Is not simple\r\n      5:\r\n        0 - No Attributes\r\n        1 - There Are Attributes\r\n      7:\r\n        0 - Last Method in Alternative_Method_List\r\n        1 - There are more alternative methods\r\n    } \r\n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\r\n    if (!IsSimple)\r\n    {\r\n      UINT64 NumInStreams;\r\n      UINT64 NumOutStreams;\r\n    }\r\n    if (DecompressionMethod[0] != 0)\r\n    {\r\n      UINT64 PropertiesSize\r\n      BYTE Properties[PropertiesSize]\r\n    }\r\n  }\r\n    \r\n  NumBindPairs = NumOutStreamsTotal - 1;\r\n\r\n  for (NumBindPairs)\r\n  {\r\n    UINT64 InIndex;\r\n    UINT64 OutIndex;\r\n  }\r\n\r\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r\n  if (NumPackedStreams > 1)\r\n    for(NumPackedStreams)\r\n    {\r\n      UINT64 Index;\r\n    };\r\n\r\n\r\n\r\n\r\nCoders Info\r\n~~~~~~~~~~~\r\n\r\n  BYTE NID::kUnPackInfo  (0x07)\r\n\r\n\r\n  BYTE NID::kFolder  (0x0B)\r\n  UINT64 NumFolders\r\n  BYTE External\r\n  switch(External)\r\n  {\r\n    case 0:\r\n      Folders[NumFolders]\r\n    case 1:\r\n      UINT64 DataStreamIndex\r\n  }\r\n\r\n\r\n  BYTE ID::kCodersUnPackSize  (0x0C)\r\n  for(Folders)\r\n    for(Folder.NumOutStreams)\r\n     UINT64 UnPackSize;\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC   (0x0A)\r\n  UnPackDigests[NumFolders]\r\n  []\r\n\r\n  \r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\n\r\nSubStreams Info\r\n~~~~~~~~~~~~~~\r\n  BYTE NID::kSubStreamsInfo; (0x08)\r\n\r\n  []\r\n  BYTE NID::kNumUnPackStream; (0x0D)\r\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kSize  (0x09)\r\n  UINT64 UnPackSizes[]\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC  (0x0A)\r\n  Digests[Number of streams with unknown CRC]\r\n  []\r\n\r\n  \r\n  BYTE NID::kEnd\r\n\r\n\r\nStreams Info\r\n~~~~~~~~~~~~\r\n\r\n  []\r\n  PackInfo\r\n  []\r\n\r\n\r\n  []\r\n  CodersInfo\r\n  []\r\n\r\n\r\n  []\r\n  SubStreamsInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFilesInfo\r\n~~~~~~~~~\r\n  BYTE NID::kFilesInfo;  (0x05)\r\n  UINT64 NumFiles\r\n\r\n  for (;;)\r\n  {\r\n    BYTE PropertyType;\r\n    if (aType == 0)\r\n      break;\r\n\r\n    UINT64 Size;\r\n\r\n    switch(PropertyType)\r\n    {\r\n      kEmptyStream:   (0x0E)\r\n        for(NumFiles)\r\n          BIT IsEmptyStream\r\n\r\n      kEmptyFile:     (0x0F)\r\n        for(EmptyStreams)\r\n          BIT IsEmptyFile\r\n\r\n      kAnti:          (0x10)\r\n        for(EmptyStreams)\r\n          BIT IsAntiFile\r\n      \r\n      case kCreationTime:   (0x12)\r\n      case kLastAccessTime: (0x13)\r\n      case kLastWriteTime:  (0x14)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT TimeDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Items)\r\n          UINT32 Time\r\n        []\r\n      \r\n      kNames:     (0x11)\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Files)\r\n        {\r\n          wchar_t Names[NameSize];\r\n          wchar_t 0;\r\n        }\r\n        []\r\n\r\n      kAttributes:  (0x15)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT AttributesAreDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Attributes)\r\n          UINT32 Attributes\r\n        []\r\n    }\r\n  }\r\n\r\n\r\nHeader\r\n~~~~~~\r\n  BYTE NID::kHeader (0x01)\r\n\r\n  []\r\n  ArchiveProperties\r\n  []\r\n\r\n  []\r\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  BYTE NID::kMainStreamsInfo;    (0x04)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  FilesInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nHeaderInfo\r\n~~~~~~~~~~\r\n  []\r\n  BYTE NID::kEncodedHeader; (0x17)\r\n  StreamsInfo for Encoded Header\r\n  []\r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/7zBuf.c",
    "content": "/* 7zBuf.c -- Byte Buffer\r\n2008-03-28\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"7zBuf.h\"\r\n\r\nvoid Buf_Init(CBuf *p)\r\n{\r\n  p->data = 0;\r\n  p->size = 0;\r\n}\r\n\r\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)\r\n{\r\n  p->size = 0;\r\n  if (size == 0)\r\n  {\r\n    p->data = 0;\r\n    return 1;\r\n  }\r\n  p->data = (Byte *)alloc->Alloc(alloc, size);\r\n  if (p->data != 0)\r\n  {\r\n    p->size = size;\r\n    return 1;\r\n  }\r\n  return 0;\r\n}\r\n\r\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->data);\r\n  p->data = 0;\r\n  p->size = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/7zBuf.h",
    "content": "/* 7zBuf.h -- Byte Buffer\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_BUF_H\r\n#define __7Z_BUF_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct\r\n{\r\n  Byte *data;\r\n  size_t size;\r\n} CBuf;\r\n\r\nvoid Buf_Init(CBuf *p);\r\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);\r\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc);\r\n\r\ntypedef struct\r\n{\r\n  Byte *data;\r\n  size_t size;\r\n  size_t pos;\r\n} CDynBuf;\r\n\r\nvoid DynBuf_Construct(CDynBuf *p);\r\nvoid DynBuf_SeekToBeg(CDynBuf *p);\r\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);\r\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/7zBuf2.c",
    "content": "/* 7zBuf2.c -- Byte Buffer\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n#include \"7zBuf.h\"\r\n\r\nvoid DynBuf_Construct(CDynBuf *p)\r\n{\r\n  p->data = 0;\r\n  p->size = 0;\r\n  p->pos = 0;\r\n}\r\n\r\nvoid DynBuf_SeekToBeg(CDynBuf *p)\r\n{\r\n  p->pos = 0;\r\n}\r\n\r\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)\r\n{\r\n  if (size > p->size - p->pos)\r\n  {\r\n    size_t newSize = p->pos + size;\r\n    Byte *data;\r\n    newSize += newSize / 4;\r\n    data = (Byte *)alloc->Alloc(alloc, newSize);\r\n    if (data == 0)\r\n      return 0;\r\n    p->size = newSize;\r\n    memcpy(data, p->data, p->pos);\r\n    alloc->Free(alloc, p->data);\r\n    p->data = data;\r\n  }\r\n  memcpy(p->data + p->pos, buf, size);\r\n  p->pos += size;\r\n  return 1;\r\n}\r\n\r\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->data);\r\n  p->data = 0;\r\n  p->size = 0;\r\n  p->pos = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/7zCrc.c",
    "content": "/* 7zCrc.c -- CRC32 calculation\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = CRC_UPDATE_BYTE(v, *p);\r\n  return v;\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/7zCrc.h",
    "content": "/* 7zCrc.h -- CRC32 calculation\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"Types.h\"\r\n\r\nextern UInt32 g_CrcTable[];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void);\r\n\r\n#define CRC_INIT_VAL 0xFFFFFFFF\r\n#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)\r\n#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/7zFile.c",
    "content": "/* 7zFile.c -- File IO\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zFile.h\"\r\n\r\n#ifndef USE_WINDOWS_FILE\r\n\r\n#include <errno.h>\r\n\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FILE\r\n\r\n/*\r\n   ReadFile and WriteFile functions in Windows have BUG:\r\n   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r\n   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r\n   (Insufficient system resources exist to complete the requested service).\r\n   Probably in some version of Windows there are problems with other sizes:\r\n   for 32 MB (maybe also for 16 MB).\r\n   And message can be \"Network connection was lost\"\r\n*/\r\n\r\n#define kChunkSizeMax (1 << 22)\r\n\r\n#endif\r\n\r\nvoid File_Construct(CSzFile *p)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  p->handle = INVALID_HANDLE_VALUE;\r\n  #else\r\n  p->file = NULL;\r\n  #endif\r\n}\r\n\r\nstatic WRes File_Open(CSzFile *p, const char *name, int writeMode)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  p->handle = CreateFileA(name,\r\n      writeMode ? GENERIC_WRITE : GENERIC_READ,\r\n      FILE_SHARE_READ, NULL,\r\n      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\r\n      FILE_ATTRIBUTE_NORMAL, NULL);\r\n  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r\n  #else\r\n  p->file = fopen(name, writeMode ? \"wb+\" : \"rb\");\r\n  return (p->file != 0) ? 0 : errno;\r\n  #endif\r\n}\r\n\r\nWRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }\r\nWRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }\r\n\r\nWRes File_Close(CSzFile *p)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  if (p->handle != INVALID_HANDLE_VALUE)\r\n  {\r\n    if (!CloseHandle(p->handle))\r\n      return GetLastError();\r\n    p->handle = INVALID_HANDLE_VALUE;\r\n  }\r\n  #else\r\n  if (p->file != NULL)\r\n  {\r\n    int res = fclose(p->file);\r\n    if (res != 0)\r\n      return res;\r\n    p->file = NULL;\r\n  }\r\n  #endif\r\n  return 0;\r\n}\r\n\r\nWRes File_Read(CSzFile *p, void *data, size_t *size)\r\n{\r\n  size_t originalSize = *size;\r\n  if (originalSize == 0)\r\n    return 0;\r\n\r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  *size = 0;\r\n  do\r\n  {\r\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r\n    DWORD processed = 0;\r\n    BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);\r\n    data = (void *)((Byte *)data + processed);\r\n    originalSize -= processed;\r\n    *size += processed;\r\n    if (!res)\r\n      return GetLastError();\r\n    if (processed == 0)\r\n      break;\r\n  }\r\n  while (originalSize > 0);\r\n  return 0;\r\n\r\n  #else\r\n  \r\n  *size = fread(data, 1, originalSize, p->file);\r\n  if (*size == originalSize)\r\n    return 0;\r\n  return ferror(p->file);\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_Write(CSzFile *p, const void *data, size_t *size)\r\n{\r\n  size_t originalSize = *size;\r\n  if (originalSize == 0)\r\n    return 0;\r\n  \r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  *size = 0;\r\n  do\r\n  {\r\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r\n    DWORD processed = 0;\r\n    BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);\r\n    data = (void *)((Byte *)data + processed);\r\n    originalSize -= processed;\r\n    *size += processed;\r\n    if (!res)\r\n      return GetLastError();\r\n    if (processed == 0)\r\n      break;\r\n  }\r\n  while (originalSize > 0);\r\n  return 0;\r\n\r\n  #else\r\n\r\n  *size = fwrite(data, 1, originalSize, p->file);\r\n  if (*size == originalSize)\r\n    return 0;\r\n  return ferror(p->file);\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  LARGE_INTEGER value;\r\n  DWORD moveMethod;\r\n  value.LowPart = (DWORD)*pos;\r\n  value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */\r\n  switch (origin)\r\n  {\r\n    case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;\r\n    case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;\r\n    case SZ_SEEK_END: moveMethod = FILE_END; break;\r\n    default: return ERROR_INVALID_PARAMETER;\r\n  }\r\n  value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n  {\r\n    WRes res = GetLastError();\r\n    if (res != NO_ERROR)\r\n      return res;\r\n  }\r\n  *pos = ((Int64)value.HighPart << 32) | value.LowPart;\r\n  return 0;\r\n\r\n  #else\r\n  \r\n  int moveMethod;\r\n  int res;\r\n  switch (origin)\r\n  {\r\n    case SZ_SEEK_SET: moveMethod = SEEK_SET; break;\r\n    case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;\r\n    case SZ_SEEK_END: moveMethod = SEEK_END; break;\r\n    default: return 1;\r\n  }\r\n  res = fseek(p->file, (long)*pos, moveMethod);\r\n  *pos = ftell(p->file);\r\n  return res;\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_GetLength(CSzFile *p, UInt64 *length)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  \r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);\r\n  if (sizeLow == 0xFFFFFFFF)\r\n  {\r\n    DWORD res = GetLastError();\r\n    if (res != NO_ERROR)\r\n      return res;\r\n  }\r\n  *length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return 0;\r\n  \r\n  #else\r\n  \r\n  long pos = ftell(p->file);\r\n  int res = fseek(p->file, 0, SEEK_END);\r\n  *length = ftell(p->file);\r\n  fseek(p->file, pos, SEEK_SET);\r\n  return res;\r\n  \r\n  #endif\r\n}\r\n\r\n\r\n/* ---------- FileSeqInStream ---------- */\r\n\r\nstatic SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CFileSeqInStream *p = (CFileSeqInStream *)pp;\r\n  return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;\r\n}\r\n\r\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p)\r\n{\r\n  p->s.Read = FileSeqInStream_Read;\r\n}\r\n\r\n\r\n/* ---------- FileInStream ---------- */\r\n\r\nstatic SRes FileInStream_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CFileInStream *p = (CFileInStream *)pp;\r\n  return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;\r\n}\r\n\r\nstatic SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)\r\n{\r\n  CFileInStream *p = (CFileInStream *)pp;\r\n  return File_Seek(&p->file, pos, origin);\r\n}\r\n\r\nvoid FileInStream_CreateVTable(CFileInStream *p)\r\n{\r\n  p->s.Read = FileInStream_Read;\r\n  p->s.Seek = FileInStream_Seek;\r\n}\r\n\r\n\r\n/* ---------- FileOutStream ---------- */\r\n\r\nstatic size_t FileOutStream_Write(void *pp, const void *data, size_t size)\r\n{\r\n  CFileOutStream *p = (CFileOutStream *)pp;\r\n  File_Write(&p->file, data, &size);\r\n  return size;\r\n}\r\n\r\nvoid FileOutStream_CreateVTable(CFileOutStream *p)\r\n{\r\n  p->s.Write = FileOutStream_Write;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/7zFile.h",
    "content": "/* 7zFile.h -- File IO\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_FILE_H\r\n#define __7Z_FILE_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WINDOWS_FILE\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FILE\r\n#include <windows.h>\r\n#else\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"Types.h\"\r\n\r\n\r\n/* ---------- File ---------- */\r\n\r\ntypedef struct\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  HANDLE handle;\r\n  #else\r\n  FILE *file;\r\n  #endif\r\n} CSzFile;\r\n\r\nvoid File_Construct(CSzFile *p);\r\nWRes InFile_Open(CSzFile *p, const char *name);\r\nWRes OutFile_Open(CSzFile *p, const char *name);\r\nWRes File_Close(CSzFile *p);\r\n\r\n/* reads max(*size, remain file's size) bytes */\r\nWRes File_Read(CSzFile *p, void *data, size_t *size);\r\n\r\n/* writes *size bytes */\r\nWRes File_Write(CSzFile *p, const void *data, size_t *size);\r\n\r\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);\r\nWRes File_GetLength(CSzFile *p, UInt64 *length);\r\n\r\n\r\n/* ---------- FileInStream ---------- */\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  CSzFile file;\r\n} CFileSeqInStream;\r\n\r\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p);\r\n\r\n\r\ntypedef struct\r\n{\r\n  ISeekInStream s;\r\n  CSzFile file;\r\n} CFileInStream;\r\n\r\nvoid FileInStream_CreateVTable(CFileInStream *p);\r\n\r\n\r\ntypedef struct\r\n{\r\n  ISeqOutStream s;\r\n  CSzFile file;\r\n} CFileOutStream;\r\n\r\nvoid FileOutStream_CreateVTable(CFileOutStream *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/7zStream.c",
    "content": "/* 7zStream.c -- 7z Stream functions\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"Types.h\"\r\n\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)\r\n{\r\n  while (size != 0)\r\n  {\r\n    size_t processed = size;\r\n    RINOK(stream->Read(stream, buf, &processed));\r\n    if (processed == 0)\r\n      return errorType;\r\n    buf = (void *)((Byte *)buf + processed);\r\n    size -= processed;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)\r\n{\r\n  return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r\n}\r\n\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)\r\n{\r\n  size_t processed = 1;\r\n  RINOK(stream->Read(stream, buf, &processed));\r\n  return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;\r\n}\r\n\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)\r\n{\r\n  Int64 t = offset;\r\n  return stream->Seek(stream, &t, SZ_SEEK_SET);\r\n}\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)\r\n{\r\n  void *lookBuf;\r\n  if (*size == 0)\r\n    return SZ_OK;\r\n  RINOK(stream->Look(stream, &lookBuf, size));\r\n  memcpy(buf, lookBuf, *size);\r\n  return stream->Skip(stream, *size);\r\n}\r\n\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)\r\n{\r\n  while (size != 0)\r\n  {\r\n    size_t processed = size;\r\n    RINOK(stream->Read(stream, buf, &processed));\r\n    if (processed == 0)\r\n      return errorType;\r\n    buf = (void *)((Byte *)buf + processed);\r\n    size -= processed;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)\r\n{\r\n  return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r\n}\r\n\r\nstatic SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)\r\n{\r\n  SRes res = SZ_OK;\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t size2 = p->size - p->pos;\r\n  if (size2 == 0 && *size > 0)\r\n  {\r\n    p->pos = 0;\r\n    size2 = LookToRead_BUF_SIZE;\r\n    res = p->realStream->Read(p->realStream, p->buf, &size2);\r\n    p->size = size2;\r\n  }\r\n  if (size2 < *size)\r\n    *size = size2;\r\n  *buf = p->buf + p->pos;\r\n  return res;\r\n}\r\n\r\nstatic SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)\r\n{\r\n  SRes res = SZ_OK;\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t size2 = p->size - p->pos;\r\n  if (size2 == 0 && *size > 0)\r\n  {\r\n    p->pos = 0;\r\n    if (*size > LookToRead_BUF_SIZE)\r\n      *size = LookToRead_BUF_SIZE;\r\n    res = p->realStream->Read(p->realStream, p->buf, size);\r\n    size2 = p->size = *size;\r\n  }\r\n  if (size2 < *size)\r\n    *size = size2;\r\n  *buf = p->buf + p->pos;\r\n  return res;\r\n}\r\n\r\nstatic SRes LookToRead_Skip(void *pp, size_t offset)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  p->pos += offset;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LookToRead_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t rem = p->size - p->pos;\r\n  if (rem == 0)\r\n    return p->realStream->Read(p->realStream, buf, size);\r\n  if (rem > *size)\r\n    rem = *size;\r\n  memcpy(buf, p->buf + p->pos, rem);\r\n  p->pos += rem;\r\n  *size = rem;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  p->pos = p->size = 0;\r\n  return p->realStream->Seek(p->realStream, pos, origin);\r\n}\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead)\r\n{\r\n  p->s.Look = lookahead ?\r\n      LookToRead_Look_Lookahead :\r\n      LookToRead_Look_Exact;\r\n  p->s.Skip = LookToRead_Skip;\r\n  p->s.Read = LookToRead_Read;\r\n  p->s.Seek = LookToRead_Seek;\r\n}\r\n\r\nvoid LookToRead_Init(CLookToRead *p)\r\n{\r\n  p->pos = p->size = 0;\r\n}\r\n\r\nstatic SRes SecToLook_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CSecToLook *p = (CSecToLook *)pp;\r\n  return LookInStream_LookRead(p->realStream, buf, size);\r\n}\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p)\r\n{\r\n  p->s.Read = SecToLook_Read;\r\n}\r\n\r\nstatic SRes SecToRead_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CSecToRead *p = (CSecToRead *)pp;\r\n  return p->realStream->Read(p->realStream, buf, size);\r\n}\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p)\r\n{\r\n  p->s.Read = SecToRead_Read;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/7zVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 65\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.65\"\r\n#define MY_DATE \"2009-02-03\"\r\n#define MY_COPYRIGHT \": Igor Pavlov : Public domain\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \" \" MY_COPYRIGHT \" : \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Alloc.c",
    "content": "/* Alloc.c -- Memory allocation functions\r\n2008-09-24\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdlib.h>\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  {\r\n    void *p = malloc(size);\r\n    fprintf(stderr, \"\\nAlloc %10d bytes, count = %10d,  addr = %8X\", size, g_allocCount++, (unsigned)p);\r\n    return p;\r\n  }\r\n  #else\r\n  return malloc(size);\r\n  #endif\r\n}\r\n\r\nvoid MyFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d,  addr = %8X\", --g_allocCount, (unsigned)address);\r\n  #endif\r\n  free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#ifndef MEM_LARGE_PAGES\r\n#undef _7ZIP_LARGE_PAGES\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nSIZE_T g_LargePageSize = 0;\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n#endif\r\n\r\nvoid SetLargePageSize()\r\n{\r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  SIZE_T size = 0;\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        GetProcAddress(GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return;\r\n  size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return;\r\n  g_LargePageSize = size;\r\n  #endif\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))\r\n  {\r\n    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),\r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Alloc.h",
    "content": "/* Alloc.h -- Memory allocation functions\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size);\r\nvoid MyFree(void *address);\r\n\r\n#ifdef _WIN32\r\n\r\nvoid SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size);\r\nvoid MidFree(void *address);\r\nvoid *BigAlloc(size_t size);\r\nvoid BigFree(void *address);\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z.mak\" CFG=\"7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /FAs /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_SZ_ALLOC_DEBUG2\" /D \"_SZ_NO_INT_64_A\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z - Win32 Release\"\r\n# Name \"7z - Win32 Debug\"\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zBuf.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zBuf.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zFile.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zFile.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zStream.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bcj2.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bcj2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bra86.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z\"=.\\7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zAlloc.c",
    "content": "/* 7zAlloc.c -- Allocation functions\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n\r\n#endif\r\n\r\nvoid *SzAlloc(void *p, size_t size)\r\n{\r\n  p = p;\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *p, void *address)\r\n{\r\n  p = p;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(void *p, size_t size)\r\n{\r\n  p = p;\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *p, void *address)\r\n{\r\n  p = p;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zAlloc.h",
    "content": "/* 7zAlloc.h -- Allocation functions\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *SzAlloc(void *p, size_t size);\r\nvoid SzFree(void *p, void *address);\r\n\r\nvoid *SzAllocTemp(void *p, size_t size);\r\nvoid SzFreeTemp(void *p, void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zDecode.c",
    "content": "/* 7zDecode.c -- Decoding from 7z folder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"../../Bcj2.h\"\r\n#include \"../../Bra.h\"\r\n#include \"../../LzmaDec.h\"\r\n#include \"7zDecode.h\"\r\n\r\n#define k_Copy 0\r\n#define k_LZMA 0x30101\r\n#define k_BCJ 0x03030103\r\n#define k_BCJ2 0x0303011B\r\n\r\nstatic SRes SzDecodeLzma(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,\r\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)\r\n{\r\n  CLzmaDec state;\r\n  SRes res = SZ_OK;\r\n\r\n  LzmaDec_Construct(&state);\r\n  RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));\r\n  state.dic = outBuffer;\r\n  state.dicBufSize = outSize;\r\n  LzmaDec_Init(&state);\r\n\r\n  for (;;)\r\n  {\r\n    Byte *inBuf = NULL;\r\n    size_t lookahead = (1 << 18);\r\n    if (lookahead > inSize)\r\n      lookahead = (size_t)inSize;\r\n    res = inStream->Look((void *)inStream, (void **)&inBuf, &lookahead);\r\n    if (res != SZ_OK)\r\n      break;\r\n\r\n    {\r\n      SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;\r\n      ELzmaStatus status;\r\n      res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);\r\n      lookahead -= inProcessed;\r\n      inSize -= inProcessed;\r\n      if (res != SZ_OK)\r\n        break;\r\n      if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))\r\n      {\r\n        if (state.dicBufSize != outSize || lookahead != 0 ||\r\n            (status != LZMA_STATUS_FINISHED_WITH_MARK &&\r\n             status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))\r\n          res = SZ_ERROR_DATA;\r\n        break;\r\n      }\r\n      res = inStream->Skip((void *)inStream, inProcessed);\r\n      if (res != SZ_OK)\r\n        break;\r\n    }\r\n  }\r\n\r\n  LzmaDec_FreeProbs(&state, allocMain);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)\r\n{\r\n  while (inSize > 0)\r\n  {\r\n    void *inBuf;\r\n    size_t curSize = (1 << 18);\r\n    if (curSize > inSize)\r\n      curSize = (size_t)inSize;\r\n    RINOK(inStream->Look((void *)inStream, (void **)&inBuf, &curSize));\r\n    if (curSize == 0)\r\n      return SZ_ERROR_INPUT_EOF;\r\n    memcpy(outBuffer, inBuf, curSize);\r\n    outBuffer += curSize;\r\n    inSize -= curSize;\r\n    RINOK(inStream->Skip((void *)inStream, curSize));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)\r\n#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)\r\n\r\nSRes CheckSupportedFolder(const CSzFolder *f)\r\n{\r\n  if (f->NumCoders < 1 || f->NumCoders > 4)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (IS_UNSUPPORTED_CODER(f->Coders[0]))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (f->NumCoders == 1)\r\n  {\r\n    if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 2)\r\n  {\r\n    if (IS_NO_BCJ(f->Coders[1]) ||\r\n        f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||\r\n        f->NumBindPairs != 1 ||\r\n        f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 4)\r\n  {\r\n    if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||\r\n        IS_UNSUPPORTED_CODER(f->Coders[2]) ||\r\n        IS_NO_BCJ2(f->Coders[3]))\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    if (f->NumPackStreams != 4 ||\r\n        f->PackStreams[0] != 2 ||\r\n        f->PackStreams[1] != 6 ||\r\n        f->PackStreams[2] != 1 ||\r\n        f->PackStreams[3] != 0 ||\r\n        f->NumBindPairs != 3 ||\r\n        f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||\r\n        f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||\r\n        f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  return SZ_ERROR_UNSUPPORTED;\r\n}\r\n\r\nUInt64 GetSum(const UInt64 *values, UInt32 index)\r\n{\r\n  UInt64 sum = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < index; i++)\r\n    sum += values[i];\r\n  return sum;\r\n}\r\n\r\nSRes SzDecode2(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *inStream, UInt64 startPos,\r\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,\r\n    Byte *tempBuf[])\r\n{\r\n  UInt32 ci;\r\n  SizeT tempSizes[3] = { 0, 0, 0};\r\n  SizeT tempSize3 = 0;\r\n  Byte *tempBuf3 = 0;\r\n\r\n  RINOK(CheckSupportedFolder(folder));\r\n\r\n  for (ci = 0; ci < folder->NumCoders; ci++)\r\n  {\r\n    CSzCoderInfo *coder = &folder->Coders[ci];\r\n\r\n    if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)\r\n    {\r\n      UInt32 si = 0;\r\n      UInt64 offset;\r\n      UInt64 inSize;\r\n      Byte *outBufCur = outBuffer;\r\n      SizeT outSizeCur = outSize;\r\n      if (folder->NumCoders == 4)\r\n      {\r\n        UInt32 indices[] = { 3, 2, 0 };\r\n        UInt64 unpackSize = folder->UnpackSizes[ci];\r\n        si = indices[ci];\r\n        if (ci < 2)\r\n        {\r\n          Byte *temp;\r\n          outSizeCur = (SizeT)unpackSize;\r\n          if (outSizeCur != unpackSize)\r\n            return SZ_ERROR_MEM;\r\n          temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);\r\n          if (temp == 0 && outSizeCur != 0)\r\n            return SZ_ERROR_MEM;\r\n          outBufCur = tempBuf[1 - ci] = temp;\r\n          tempSizes[1 - ci] = outSizeCur;\r\n        }\r\n        else if (ci == 2)\r\n        {\r\n          if (unpackSize > outSize) /* check it */\r\n            return SZ_ERROR_PARAM;\r\n          tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);\r\n          tempSize3 = outSizeCur = (SizeT)unpackSize;\r\n        }\r\n        else\r\n          return SZ_ERROR_UNSUPPORTED;\r\n      }\r\n      offset = GetSum(packSizes, si);\r\n      inSize = packSizes[si];\r\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r\n\r\n      if (coder->MethodID == k_Copy)\r\n      {\r\n        if (inSize != outSizeCur) /* check it */\r\n          return SZ_ERROR_DATA;\r\n        RINOK(SzDecodeCopy(inSize, inStream, outBufCur));\r\n      }\r\n      else\r\n      {\r\n        RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));\r\n      }\r\n    }\r\n    else if (coder->MethodID == k_BCJ)\r\n    {\r\n      UInt32 state;\r\n      if (ci != 1)\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      x86_Convert_Init(state);\r\n      x86_Convert(outBuffer, outSize, 0, &state, 0);\r\n    }\r\n    else if (coder->MethodID == k_BCJ2)\r\n    {\r\n      UInt64 offset = GetSum(packSizes, 1);\r\n      UInt64 s3Size = packSizes[1];\r\n      SRes res;\r\n      if (ci != 3)\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r\n      tempSizes[2] = (SizeT)s3Size;\r\n      if (tempSizes[2] != s3Size)\r\n        return SZ_ERROR_MEM;\r\n      tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);\r\n      if (tempBuf[2] == 0 && tempSizes[2] != 0)\r\n        return SZ_ERROR_MEM;\r\n      res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);\r\n      RINOK(res)\r\n\r\n      res = Bcj2_Decode(\r\n          tempBuf3, tempSize3,\r\n          tempBuf[0], tempSizes[0],\r\n          tempBuf[1], tempSizes[1],\r\n          tempBuf[2], tempSizes[2],\r\n          outBuffer, outSize);\r\n      RINOK(res)\r\n    }\r\n    else\r\n      return SZ_ERROR_UNSUPPORTED;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *inStream, UInt64 startPos,\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  Byte *tempBuf[3] = { 0, 0, 0};\r\n  int i;\r\n  SRes res = SzDecode2(packSizes, folder, inStream, startPos,\r\n      outBuffer, (SizeT)outSize, allocMain, tempBuf);\r\n  for (i = 0; i < 3; i++)\r\n    IAlloc_Free(allocMain, tempBuf[i]);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zDecode.h",
    "content": "/* 7zDecode.h -- Decoding from 7z folder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n\r\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *stream, UInt64 startPos,\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zExtract.c",
    "content": "/* 7zExtract.c -- Extracting from 7z archive\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"7zDecode.h\"\r\n#include \"7zExtract.h\"\r\n\r\nSRes SzAr_Extract(\r\n    const CSzArEx *p,\r\n    ILookInStream *inStream,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer,\r\n    size_t *outBufferSize,\r\n    size_t *offset,\r\n    size_t *outSizeProcessed,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = p->FileIndexToFolderIndexMap[fileIndex];\r\n  SRes res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    IAlloc_Free(allocMain, *outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CSzFolder *folder = p->db.Folders + folderIndex;\r\n    UInt64 unpackSizeSpec = SzFolder_GetUnpackSize(folder);\r\n    size_t unpackSize = (size_t)unpackSizeSpec;\r\n    UInt64 startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);\r\n\r\n    if (unpackSize != unpackSizeSpec)\r\n      return SZ_ERROR_MEM;\r\n    *blockIndex = folderIndex;\r\n    IAlloc_Free(allocMain, *outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(LookInStream_SeekTo(inStream, startOffset));\r\n    \r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = unpackSize;\r\n      if (unpackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unpackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZ_ERROR_MEM;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        res = SzDecode(p->db.PackSizes +\r\n          p->FolderStartPackStreamIndex[folderIndex], folder,\r\n          inStream, startOffset,\r\n          *outBuffer, unpackSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (folder->UnpackCRCDefined)\r\n          {\r\n            if (CrcCalc(*outBuffer, unpackSize) != folder->UnpackCRC)\r\n              res = SZ_ERROR_CRC;\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i;\r\n    CSzFileItem *fileItem = p->db.Files + fileIndex;\r\n    *offset = 0;\r\n    for (i = p->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)p->db.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZ_ERROR_FAIL;\r\n    {\r\n      if (fileItem->FileCRCDefined)\r\n      {\r\n        if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)\r\n          res = SZ_ERROR_CRC;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zExtract.h",
    "content": "/* 7zExtract.h -- Extracting from 7z archive\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive.\r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send\r\n    these values from previous call:\r\n      *blockIndex,\r\n      *outBuffer,\r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid,\r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables\r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSRes SzAr_Extract(\r\n    const CSzArEx *db,\r\n    ILookInStream *inStream,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zHeader.c",
    "content": "/*  7zHeader.c -- 7z Headers\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zHeader.h",
    "content": "/* 7zHeader.h -- 7z Headers\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnpackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnpackSize,\r\n  k7zIdNumUnpackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCTime,\r\n  k7zIdATime,\r\n  k7zIdMTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos,\r\n  k7zIdDummy\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zIn.c",
    "content": "/* 7zIn.c -- 7z Input functions\r\n2008-12-31 : Igor Pavlov : Public domain */\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"../../CpuArch.h\"\r\n\r\n#include \"7zDecode.h\"\r\n#include \"7zIn.h\"\r\n\r\n#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }\r\n\r\n#define NUM_FOLDER_CODERS_MAX 32\r\n#define NUM_CODER_STREAMS_MAX 32\r\n\r\nvoid SzArEx_Init(CSzArEx *p)\r\n{\r\n  SzAr_Init(&p->db);\r\n  p->FolderStartPackStreamIndex = 0;\r\n  p->PackStreamStartPositions = 0;\r\n  p->FolderStartFileIndex = 0;\r\n  p->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)\r\n{\r\n  IAlloc_Free(alloc, p->FolderStartPackStreamIndex);\r\n  IAlloc_Free(alloc, p->PackStreamStartPositions);\r\n  IAlloc_Free(alloc, p->FolderStartFileIndex);\r\n  IAlloc_Free(alloc, p->FileIndexToFolderIndexMap);\r\n  SzAr_Free(&p->db, alloc);\r\n  SzArEx_Init(p);\r\n}\r\n\r\n/*\r\nUInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nUInt64 GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CSzFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n#define MY_ALLOC(T, p, size, alloc) { if ((size) == 0) p = 0; else \\\r\n  if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == 0) return SZ_ERROR_MEM; }\r\n\r\nstatic SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 startPos = 0;\r\n  UInt64 startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  MY_ALLOC(UInt32, p->FolderStartPackStreamIndex, p->db.NumFolders, alloc);\r\n  for (i = 0; i < p->db.NumFolders; i++)\r\n  {\r\n    p->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += p->db.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  MY_ALLOC(UInt64, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);\r\n\r\n  for (i = 0; i < p->db.NumPackStreams; i++)\r\n  {\r\n    p->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += p->db.PackSizes[i];\r\n  }\r\n\r\n  MY_ALLOC(UInt32, p->FolderStartFileIndex, p->db.NumFolders, alloc);\r\n  MY_ALLOC(UInt32, p->FileIndexToFolderIndexMap, p->db.NumFiles, alloc);\r\n\r\n  for (i = 0; i < p->db.NumFiles; i++)\r\n  {\r\n    CSzFileItem *file = p->db.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      p->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= p->db.NumFolders)\r\n          return SZ_ERROR_ARCHIVE;\r\n        p->FolderStartFileIndex[folderIndex] = i;\r\n        if (p->db.Folders[folderIndex].NumUnpackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    p->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= p->db.Folders[folderIndex].NumUnpackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return p->dataPos +\r\n    p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize)\r\n{\r\n  UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];\r\n  CSzFolder *folder = p->db.Folders + folderIndex;\r\n  UInt64 size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n  {\r\n    UInt64 t = size + p->db.PackSizes[packStreamIndex + i];\r\n    if (t < size) /* check it */\r\n      return SZ_ERROR_FAIL;\r\n    size = t;\r\n  }\r\n  *resSize = size;\r\n  return SZ_OK;\r\n}\r\n\r\n\r\n/*\r\nSRes SzReadTime(const CObjectVector<CBuf> &dataVector,\r\n    CObjectVector<CSzFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for (int i = 0; i < files.Size(); i++)\r\n  {\r\n    CSzFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCTime: file.IsCTimeDefined = defined; if (defined) file.CTime = fileTime; break;\r\n      case k7zIdATime: file.IsATimeDefined = defined; if (defined) file.ATime = fileTime; break;\r\n      case k7zIdMTime: file.IsMTimeDefined = defined; if (defined) file.MTime = fileTime; break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nstatic int TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nstatic SRes SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZ_ERROR_ARCHIVE;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadID(CSzData *sd, UInt64 *value)\r\n{\r\n  return SzReadNumber(sd, value);\r\n}\r\n\r\nstatic SRes SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZ_ERROR_ARCHIVE;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nstatic SRes SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZ_ERROR_ARCHIVE;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nstatic SRes SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  MY_ALLOC(Byte, *v, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, alloc);\r\n  MY_ALLOC(Byte, *v, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadHashDigests(\r\n    CSzData *sd,\r\n    size_t numItems,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *alloc)\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, alloc));\r\n  MY_ALLOC(UInt32, *digests, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadPackInfo(\r\n    CSzData *sd,\r\n    UInt64 *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    UInt64 **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadNumber(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  MY_ALLOC(UInt64, *packSizes, (size_t)*numPackStreams, alloc);\r\n\r\n  for (i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadNumber(sd, (*packSizes) + i));\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, alloc);\r\n    MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, alloc);\r\n    for (i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZ_ERROR_UNSUPPORTED;\r\n}\r\n\r\nstatic SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)\r\n{\r\n  UInt32 numCoders, numBindPairs, numPackStreams, i;\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  if (numCoders > NUM_FOLDER_CODERS_MAX)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  folder->NumCoders = numCoders;\r\n  \r\n  MY_ALLOC(CSzCoderInfo, folder->Coders, (size_t)numCoders, alloc);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfo_Init(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CSzCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      unsigned idSize, j;\r\n      Byte longID[15];\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      idSize = (unsigned)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, longID, idSize));\r\n      if (idSize > sizeof(coder->MethodID))\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      coder->MethodID = 0;\r\n      for (j = 0; j < idSize; j++)\r\n        coder->MethodID |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n        if (coder->NumInStreams > NUM_CODER_STREAMS_MAX ||\r\n            coder->NumOutStreams > NUM_CODER_STREAMS_MAX)\r\n          return SZ_ERROR_UNSUPPORTED;\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!Buf_Create(&coder->Props, (size_t)propertiesSize, alloc))\r\n          return SZ_ERROR_MEM;\r\n        RINOK(SzReadBytes(sd, coder->Props.data, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += coder->NumInStreams;\r\n    numOutStreams += coder->NumOutStreams;\r\n  }\r\n\r\n  if (numOutStreams == 0)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  folder->NumBindPairs = numBindPairs = numOutStreams - 1;\r\n  MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, alloc);\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bp = folder->BindPairs + i;\r\n    RINOK(SzReadNumber32(sd, &bp->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bp->OutIndex));\r\n  }\r\n\r\n  if (numInStreams < numBindPairs)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  folder->NumPackStreams = numPackStreams = numInStreams - numBindPairs;\r\n  MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackStreams, alloc);\r\n\r\n  if (numPackStreams == 1)\r\n  {\r\n    for (i = 0; i < numInStreams ; i++)\r\n      if (SzFolder_FindBindPairForInStream(folder, i) < 0)\r\n        break;\r\n    if (i == numInStreams)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    folder->PackStreams[0] = i;\r\n  }\r\n  else\r\n    for (i = 0; i < numPackStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadUnpackInfo(\r\n    CSzData *sd,\r\n    UInt32 *numFolders,\r\n    CSzFolder **folders,  /* for alloc */\r\n    ISzAlloc *alloc,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n    MY_ALLOC(CSzFolder, *folders, (size_t)*numFolders, alloc);\r\n\r\n    for (i = 0; i < *numFolders; i++)\r\n      SzFolder_Init((*folders) + i);\r\n\r\n    for (i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, alloc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnpackSize));\r\n\r\n  for (i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CSzFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);\r\n\r\n    MY_ALLOC(UInt64, folder->UnpackSizes, (size_t)numOutStreams, alloc);\r\n\r\n    for (j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadNumber(sd, folder->UnpackSizes + j));\r\n    }\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SRes res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < *numFolders; i++)\r\n        {\r\n          CSzFolder *folder = (*folders) + i;\r\n          folder->UnpackCRCDefined = crcsDefined[i];\r\n          folder->UnpackCRC = crcs[i];\r\n        }\r\n      }\r\n      IAlloc_Free(allocTemp, crcs);\r\n      IAlloc_Free(allocTemp, crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nstatic SRes SzReadSubStreamsInfo(\r\n    CSzData *sd,\r\n    UInt32 numFolders,\r\n    CSzFolder *folders,\r\n    UInt32 *numUnpackStreams,\r\n    UInt64 **unpackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n    folders[i].NumUnpackStreams = 1;\r\n  *numUnpackStreams = numFolders;\r\n\r\n  for (;;)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnpackStream)\r\n    {\r\n      *numUnpackStreams = 0;\r\n      for (i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnpackStreams = numStreams;\r\n        *numUnpackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnpackStreams == 0)\r\n  {\r\n    *unpackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unpackSizes = (UInt64 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt64));\r\n    RINOM(*unpackSizes);\r\n    *digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    UInt64 sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      UInt64 size;\r\n      RINOK(SzReadNumber(sd, &size));\r\n      (*unpackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unpackSizes)[si++] = SzFolder_GetUnpackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for (i = 0; i < *numUnpackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  for (;;)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0;\r\n      UInt32 *digests2 = 0;\r\n      SRes res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CSzFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnpackStreams;\r\n          if (numSubstreams == 1 && folder->UnpackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnpackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      IAlloc_Free(allocTemp, digestsDefined2);\r\n      IAlloc_Free(allocTemp, digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nstatic SRes SzReadStreamsInfo(\r\n    CSzData *sd,\r\n    UInt64 *dataOffset,\r\n    CSzAr *p,\r\n    UInt32 *numUnpackStreams,\r\n    UInt64 **unpackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    ISzAlloc *alloc,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,\r\n            &p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc));\r\n        break;\r\n      }\r\n      case k7zIdUnpackInfo:\r\n      {\r\n        RINOK(SzReadUnpackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,\r\n            numUnpackStreams, unpackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZ_ERROR_UNSUPPORTED;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nstatic SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CSzFileItem *file = files + i;\r\n    while (pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZ_ERROR_ARCHIVE;\r\n        if (pos + 2 > sd->Size)\r\n          return SZ_ERROR_ARCHIVE;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZ_ERROR_ARCHIVE;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    MY_ALLOC(char, file->Name, (size_t)len, alloc);\r\n\r\n    len = 0;\r\n    while (2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while (numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadHeader2(\r\n    CSzArEx *p,   /* allocMain */\r\n    CSzData *sd,\r\n    UInt64 **unpackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    Byte **lwtVector,         /* allocTemp */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnpackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CSzFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &p->dataPos,\r\n        &p->db,\r\n        &numUnpackStreams,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests, allocMain, allocTemp));\r\n    p->dataPos += p->startPosAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZ_ERROR_ARCHIVE;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  p->db.NumFiles = numFiles;\r\n\r\n  MY_ALLOC(CSzFileItem, files, (size_t)numFiles, allocMain);\r\n\r\n  p->db.Files = files;\r\n  for (i = 0; i < numFiles; i++)\r\n    SzFile_Init(files + i);\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdMTime:\r\n      {\r\n        RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));\r\n        RINOK(SzReadSwitch(sd));\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CSzFileItem *f = &files[i];\r\n          Byte defined = (*lwtVector)[i];\r\n          f->MTimeDefined = defined;\r\n          f->MTime.Low = f->MTime.High = 0;\r\n          if (defined)\r\n          {\r\n            RINOK(SzReadUInt32(sd, &f->MTime.Low));\r\n            RINOK(SzReadUInt32(sd, &f->MTime.High));\r\n          }\r\n        }\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      CSzFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if (file->HasStream)\r\n      {\r\n        file->IsDir = 0;\r\n        file->Size = (*unpackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->FileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDir = 1;\r\n        else\r\n          file->IsDir = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->FileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArEx_Fill(p, allocMain);\r\n}\r\n\r\nstatic SRes SzReadHeader(\r\n    CSzArEx *p,\r\n    CSzData *sd,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 *unpackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  Byte *lwtVector = 0;\r\n  SRes res = SzReadHeader2(p, sd,\r\n      &unpackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector, &lwtVector,\r\n      allocMain, allocTemp);\r\n  IAlloc_Free(allocTemp, unpackSizes);\r\n  IAlloc_Free(allocTemp, digestsDefined);\r\n  IAlloc_Free(allocTemp, digests);\r\n  IAlloc_Free(allocTemp, emptyStreamVector);\r\n  IAlloc_Free(allocTemp, emptyFileVector);\r\n  IAlloc_Free(allocTemp, lwtVector);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzReadAndDecodePackedStreams2(\r\n    ILookInStream *inStream,\r\n    CSzData *sd,\r\n    CBuf *outBuffer,\r\n    UInt64 baseOffset,\r\n    CSzAr *p,\r\n    UInt64 **unpackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnpackStreams = 0;\r\n  UInt64 dataStartPos;\r\n  CSzFolder *folder;\r\n  UInt64 unpackSize;\r\n  SRes res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,\r\n      &numUnpackStreams,  unpackSizes, digestsDefined, digests,\r\n      allocTemp, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (p->NumFolders != 1)\r\n    return SZ_ERROR_ARCHIVE;\r\n\r\n  folder = p->Folders;\r\n  unpackSize = SzFolder_GetUnpackSize(folder);\r\n  \r\n  RINOK(LookInStream_SeekTo(inStream, dataStartPos));\r\n\r\n  if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))\r\n    return SZ_ERROR_MEM;\r\n  \r\n  res = SzDecode(p->PackSizes, folder,\r\n          inStream, dataStartPos,\r\n          outBuffer->data, (size_t)unpackSize, allocTemp);\r\n  RINOK(res);\r\n  if (folder->UnpackCRCDefined)\r\n    if (CrcCalc(outBuffer->data, (size_t)unpackSize) != folder->UnpackCRC)\r\n      return SZ_ERROR_CRC;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadAndDecodePackedStreams(\r\n    ILookInStream *inStream,\r\n    CSzData *sd,\r\n    CBuf *outBuffer,\r\n    UInt64 baseOffset,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  CSzAr p;\r\n  UInt64 *unpackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  SRes res;\r\n  SzAr_Init(&p);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,\r\n    &p, &unpackSizes, &digestsDefined, &digests,\r\n    allocTemp);\r\n  SzAr_Free(&p, allocTemp);\r\n  IAlloc_Free(allocTemp, unpackSizes);\r\n  IAlloc_Free(allocTemp, digestsDefined);\r\n  IAlloc_Free(allocTemp, digests);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzArEx_Open2(\r\n    CSzArEx *p,\r\n    ILookInStream *inStream,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte header[k7zStartHeaderSize];\r\n  UInt64 nextHeaderOffset, nextHeaderSize;\r\n  size_t nextHeaderSizeT;\r\n  UInt32 nextHeaderCRC;\r\n  CBuf buffer;\r\n  SRes res;\r\n\r\n  RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));\r\n\r\n  if (!TestSignatureCandidate(header))\r\n    return SZ_ERROR_NO_ARCHIVE;\r\n  if (header[6] != k7zMajorVersion)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  nextHeaderOffset = GetUi64(header + 12);\r\n  nextHeaderSize = GetUi64(header + 20);\r\n  nextHeaderCRC = GetUi32(header + 28);\r\n\r\n  p->startPosAfterHeader = k7zStartHeaderSize;\r\n  \r\n  if (CrcCalc(header + 12, 20) != GetUi32(header + 8))\r\n    return SZ_ERROR_CRC;\r\n\r\n  nextHeaderSizeT = (size_t)nextHeaderSize;\r\n  if (nextHeaderSizeT != nextHeaderSize)\r\n    return SZ_ERROR_MEM;\r\n  if (nextHeaderSizeT == 0)\r\n    return SZ_OK;\r\n  if (nextHeaderOffset > nextHeaderOffset + nextHeaderSize ||\r\n      nextHeaderOffset > nextHeaderOffset + nextHeaderSize + k7zStartHeaderSize)\r\n    return SZ_ERROR_NO_ARCHIVE;\r\n\r\n  {\r\n    Int64 pos = 0;\r\n    RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));\r\n    if ((UInt64)pos < nextHeaderOffset ||\r\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset ||\r\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)\r\n      return SZ_ERROR_INPUT_EOF;\r\n  }\r\n\r\n  RINOK(LookInStream_SeekTo(inStream, k7zStartHeaderSize + nextHeaderOffset));\r\n\r\n  if (!Buf_Create(&buffer, nextHeaderSizeT, allocTemp))\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LookInStream_Read(inStream, buffer.data, nextHeaderSizeT);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = SZ_ERROR_ARCHIVE;\r\n    if (CrcCalc(buffer.data, nextHeaderSizeT) == nextHeaderCRC)\r\n    {\r\n      CSzData sd;\r\n      UInt64 type;\r\n      sd.Data = buffer.data;\r\n      sd.Size = buffer.size;\r\n      res = SzReadID(&sd, &type);\r\n      if (res == SZ_OK)\r\n      {\r\n        if (type == k7zIdEncodedHeader)\r\n        {\r\n          CBuf outBuffer;\r\n          Buf_Init(&outBuffer);\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, p->startPosAfterHeader, allocTemp);\r\n          if (res != SZ_OK)\r\n            Buf_Free(&outBuffer, allocTemp);\r\n          else\r\n          {\r\n            Buf_Free(&buffer, allocTemp);\r\n            buffer.data = outBuffer.data;\r\n            buffer.size = outBuffer.size;\r\n            sd.Data = buffer.data;\r\n            sd.Size = buffer.size;\r\n            res = SzReadID(&sd, &type);\r\n          }\r\n        }\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        if (type == k7zIdHeader)\r\n          res = SzReadHeader(p, &sd, allocMain, allocTemp);\r\n        else\r\n          res = SZ_ERROR_UNSUPPORTED;\r\n      }\r\n    }\r\n  }\r\n  Buf_Free(&buffer, allocTemp);\r\n  return res;\r\n}\r\n\r\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)\r\n{\r\n  SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArEx_Free(p, allocMain);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zIn.h",
    "content": "/* 7zIn.h -- 7z Input functions\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n\r\ntypedef struct\r\n{\r\n  CSzAr db;\r\n  \r\n  UInt64 startPosAfterHeader;\r\n  UInt64 dataPos;\r\n\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  UInt64 *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n} CSzArEx;\r\n\r\nvoid SzArEx_Init(CSzArEx *p);\r\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);\r\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);\r\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);\r\n\r\n/*\r\nErrors:\r\nSZ_ERROR_NO_ARCHIVE\r\nSZ_ERROR_ARCHIVE\r\nSZ_ERROR_UNSUPPORTED\r\nSZ_ERROR_MEM\r\nSZ_ERROR_CRC\r\nSZ_ERROR_INPUT_EOF\r\nSZ_ERROR_FAIL\r\n*/\r\n\r\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zItem.c",
    "content": "/* 7zItem.c -- 7z Items\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zItem.h\"\r\n\r\nvoid SzCoderInfo_Init(CSzCoderInfo *p)\r\n{\r\n  Buf_Init(&p->Props);\r\n}\r\n\r\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc)\r\n{\r\n  Buf_Free(&p->Props, alloc);\r\n  SzCoderInfo_Init(p);\r\n}\r\n\r\nvoid SzFolder_Init(CSzFolder *p)\r\n{\r\n  p->Coders = 0;\r\n  p->BindPairs = 0;\r\n  p->PackStreams = 0;\r\n  p->UnpackSizes = 0;\r\n  p->NumCoders = 0;\r\n  p->NumBindPairs = 0;\r\n  p->NumPackStreams = 0;\r\n  p->UnpackCRCDefined = 0;\r\n  p->UnpackCRC = 0;\r\n  p->NumUnpackStreams = 0;\r\n}\r\n\r\nvoid SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  if (p->Coders)\r\n    for (i = 0; i < p->NumCoders; i++)\r\n      SzCoderInfo_Free(&p->Coders[i], alloc);\r\n  IAlloc_Free(alloc, p->Coders);\r\n  IAlloc_Free(alloc, p->BindPairs);\r\n  IAlloc_Free(alloc, p->PackStreams);\r\n  IAlloc_Free(alloc, p->UnpackSizes);\r\n  SzFolder_Init(p);\r\n}\r\n\r\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumCoders; i++)\r\n    result += p->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumBindPairs; i++)\r\n    if (p->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumBindPairs; i++)\r\n    if (p->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p)\r\n{\r\n  int i = (int)SzFolder_GetNumOutStreams(p);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolder_FindBindPairForOutStream(p, i) < 0)\r\n      return p->UnpackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\nvoid SzFile_Init(CSzFileItem *p)\r\n{\r\n  p->HasStream = 1;\r\n  p->IsDir = 0;\r\n  p->IsAnti = 0;\r\n  p->FileCRCDefined = 0;\r\n  p->MTimeDefined = 0;\r\n  p->Name = 0;\r\n}\r\n\r\nstatic void SzFile_Free(CSzFileItem *p, ISzAlloc *alloc)\r\n{\r\n  IAlloc_Free(alloc, p->Name);\r\n  SzFile_Init(p);\r\n}\r\n\r\nvoid SzAr_Init(CSzAr *p)\r\n{\r\n  p->PackSizes = 0;\r\n  p->PackCRCsDefined = 0;\r\n  p->PackCRCs = 0;\r\n  p->Folders = 0;\r\n  p->Files = 0;\r\n  p->NumPackStreams = 0;\r\n  p->NumFolders = 0;\r\n  p->NumFiles = 0;\r\n}\r\n\r\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  if (p->Folders)\r\n    for (i = 0; i < p->NumFolders; i++)\r\n      SzFolder_Free(&p->Folders[i], alloc);\r\n  if (p->Files)\r\n    for (i = 0; i < p->NumFiles; i++)\r\n      SzFile_Free(&p->Files[i], alloc);\r\n  IAlloc_Free(alloc, p->PackSizes);\r\n  IAlloc_Free(alloc, p->PackCRCsDefined);\r\n  IAlloc_Free(alloc, p->PackCRCs);\r\n  IAlloc_Free(alloc, p->Folders);\r\n  IAlloc_Free(alloc, p->Files);\r\n  SzAr_Init(p);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zItem.h",
    "content": "/* 7zItem.h -- 7z Items\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../7zBuf.h\"\r\n\r\ntypedef struct\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  UInt64 MethodID;\r\n  CBuf Props;\r\n} CSzCoderInfo;\r\n\r\nvoid SzCoderInfo_Init(CSzCoderInfo *p);\r\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc);\r\n\r\ntypedef struct\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n} CBindPair;\r\n\r\ntypedef struct\r\n{\r\n  CSzCoderInfo *Coders;\r\n  CBindPair *BindPairs;\r\n  UInt32 *PackStreams;\r\n  UInt64 *UnpackSizes;\r\n  UInt32 NumCoders;\r\n  UInt32 NumBindPairs;\r\n  UInt32 NumPackStreams;\r\n  int UnpackCRCDefined;\r\n  UInt32 UnpackCRC;\r\n\r\n  UInt32 NumUnpackStreams;\r\n} CSzFolder;\r\n\r\nvoid SzFolder_Init(CSzFolder *p);\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);\r\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p);\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r\n\r\ntypedef struct\r\n{\r\n  UInt32 Low;\r\n  UInt32 High;\r\n} CNtfsFileTime;\r\n\r\ntypedef struct\r\n{\r\n  CNtfsFileTime MTime;\r\n  UInt64 Size;\r\n  char *Name;\r\n  UInt32 FileCRC;\r\n\r\n  Byte HasStream;\r\n  Byte IsDir;\r\n  Byte IsAnti;\r\n  Byte FileCRCDefined;\r\n  Byte MTimeDefined;\r\n} CSzFileItem;\r\n\r\nvoid SzFile_Init(CSzFileItem *p);\r\n\r\ntypedef struct\r\n{\r\n  UInt64 *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  CSzFolder *Folders;\r\n  CSzFileItem *Files;\r\n  UInt32 NumPackStreams;\r\n  UInt32 NumFolders;\r\n  UInt32 NumFiles;\r\n} CSzAr;\r\n\r\nvoid SzAr_Init(CSzAr *p);\r\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/7zMain.c",
    "content": "/* 7zMain.c - Test application for 7z Decoder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <stdlib.h>\r\n#include <stdio.h>\r\n#include <string.h>\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"../../7zFile.h\"\r\n#include \"../../7zVersion.h\"\r\n\r\n#include \"7zAlloc.h\"\r\n#include \"7zExtract.h\"\r\n#include \"7zIn.h\"\r\n\r\nstatic void ConvertNumberToString(UInt64 value, char *s)\r\n{\r\n  char temp[32];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (char)('0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\n#define PERIOD_4 (4 * 365 + 1)\r\n#define PERIOD_100 (PERIOD_4 * 25 - 1)\r\n#define PERIOD_400 (PERIOD_100 * 4 + 1)\r\n\r\nstatic void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)\r\n{\r\n  unsigned year, mon, day, hour, min, sec;\r\n  UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  unsigned temp;\r\n  UInt32 v;\r\n  v64 /= 10000000;\r\n  sec = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  min = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  hour = (unsigned)(v64 % 24);\r\n  v64 /= 24;\r\n\r\n  v = (UInt32)v64;\r\n\r\n  year = (unsigned)(1601 + v / PERIOD_400 * 400);\r\n  v %= PERIOD_400;\r\n\r\n  temp = (unsigned)(v / PERIOD_100);\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp * 100;\r\n  v -= temp * PERIOD_100;\r\n\r\n  temp = v / PERIOD_4;\r\n  if (temp == 25)\r\n    temp = 24;\r\n  year += temp * 4;\r\n  v -= temp * PERIOD_4;\r\n\r\n  temp = v / 365;\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp;\r\n  v -= temp * 365;\r\n\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  for (mon = 1; mon <= 12; mon++)\r\n  {\r\n    unsigned s = ms[mon - 1];\r\n    if (v < s)\r\n      break;\r\n    v -= s;\r\n  }\r\n  day = (unsigned)v + 1;\r\n  sprintf(s, \"%04d-%02d-%02d %02d:%02d:%02d\", year, mon, day, hour, min, sec);\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint MY_CDECL main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CLookToRead lookStream;\r\n  CSzArEx db;\r\n  SRes res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  if (InFile_Open(&archiveStream.file, args[2]))\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  \r\n  FileInStream_CreateVTable(&archiveStream);\r\n  LookToRead_CreateVTable(&lookStream, False);\r\n  \r\n  lookStream.realStream = &archiveStream.s;\r\n  LookToRead_Init(&lookStream);\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  CrcGenerateTable();\r\n\r\n  SzArEx_Init(&db);\r\n  res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0, testCommand = 0, extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0) listCommand = 1;\r\n    else if (strcmp(command, \"t\") == 0) testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0) extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        CSzFileItem *f = db.db.Files + i;\r\n        char s[32], t[32];\r\n        ConvertNumberToString(f->Size, s);\r\n        if (f->MTimeDefined)\r\n          ConvertFileTimeToString(&f->MTime, t);\r\n        else\r\n          strcpy(t, \"                   \");\r\n\r\n        printf(\"%s %10s  %s\\n\", t, s, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      /*\r\n      if you need cache, use these 3 variables.\r\n      if you use external function, you can make these variable as static.\r\n      */\r\n      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r\n      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r\n      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CSzFileItem *f = db.db.Files + i;\r\n        if (f->IsDir)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ?\r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDir)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzAr_Extract(&db, &lookStream.s, i,\r\n            &blockIndex, &outBuffer, &outBufferSize,\r\n            &offset, &outSizeProcessed,\r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          CSzFile outFile;\r\n          size_t processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          if (OutFile_Open(&outFile, fileName))\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n          processedSize = outSizeProcessed;\r\n          if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 ||\r\n              processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n          if (File_Close(&outFile))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      IAlloc_Free(&allocImp, outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZ_ERROR_FAIL;\r\n    }\r\n  }\r\n  SzArEx_Free(&db, &allocImp);\r\n\r\n  File_Close(&archiveStream.file);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == SZ_ERROR_UNSUPPORTED)\r\n    PrintError(\"decoder doesn't support this archive\");\r\n  else if (res == SZ_ERROR_MEM)\r\n    PrintError(\"can not allocate memory\");\r\n  else if (res == SZ_ERROR_CRC)\r\n    PrintError(\"CRC error\");\r\n  else\r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/makefile",
    "content": "MY_STATIC_LINK=1\r\n\r\nPROG = 7zDec.exe\r\n\r\nC_OBJS = \\\r\n  $O\\7zBuf.obj \\\r\n  $O\\7zBuf2.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\Bcj2.obj \\\r\n  $O\\7zFile.obj \\\r\n  $O\\7zStream.obj \\\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $(C_OBJS) \\\r\n\r\n!include \"../../../CPP/Build.mak\"\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL_O1)\r\n$(C_OBJS): ../../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Archive/7z/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB =\r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = 7zAlloc.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o 7zFile.o 7zStream.o\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuf.o: ../../7zBuf.c\r\n\t$(CXX) $(CFLAGS) ../../7zBuf.c\r\n\r\n7zBuf2.o: ../../7zBuf2.c\r\n\t$(CXX) $(CFLAGS) ../../7zBuf2.c\r\n\r\n7zCrc.o: ../../7zCrc.c\r\n\t$(CXX) $(CFLAGS) ../../7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\nLzmaDec.o: ../../LzmaDec.c\r\n\t$(CXX) $(CFLAGS) ../../LzmaDec.c\r\n\r\nBra86.o: ../../Bra86.c\r\n\t$(CXX) $(CFLAGS) ../../Bra86.c\r\n\r\nBcj2.o: ../../Bcj2.c\r\n\t$(CXX) $(CFLAGS) ../../Bcj2.c\r\n\r\n7zFile.o: ../../7zFile.c\r\n\t$(CXX) $(CFLAGS) ../../7zFile.c\r\n\r\n7zStream.o: ../../7zStream.c\r\n\t$(CXX) $(CFLAGS) ../../7zStream.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Bcj2.c",
    "content": "/* Bcj2.c -- Converter for x86 code (BCJ2)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bcj2.h\"\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)\r\n#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*buffer++)\r\n#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }\r\n#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \\\r\n  { int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }}\r\n\r\n#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;\r\n\r\nint Bcj2_Decode(\r\n    const Byte *buf0, SizeT size0,\r\n    const Byte *buf1, SizeT size1,\r\n    const Byte *buf2, SizeT size2,\r\n    const Byte *buf3, SizeT size3,\r\n    Byte *outBuf, SizeT outSize)\r\n{\r\n  CProb p[256 + 2];\r\n  SizeT inPos = 0, outPos = 0;\r\n\r\n  const Byte *buffer, *bufferLim;\r\n  UInt32 range, code;\r\n  Byte prevByte = 0;\r\n\r\n  unsigned int i;\r\n  for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)\r\n    p[i] = kBitModelTotal >> 1;\r\n\r\n  buffer = buf3;\r\n  bufferLim = buffer + size3;\r\n  RC_INIT2\r\n\r\n  if (outSize == 0)\r\n    return SZ_OK;\r\n\r\n  for (;;)\r\n  {\r\n    Byte b;\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    UInt32 ttt;\r\n\r\n    SizeT limit = size0 - inPos;\r\n    if (outSize - outPos < limit)\r\n      limit = outSize - outPos;\r\n    while (limit != 0)\r\n    {\r\n      Byte b = buf0[inPos];\r\n      outBuf[outPos++] = b;\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      inPos++;\r\n      prevByte = b;\r\n      limit--;\r\n    }\r\n\r\n    if (limit == 0 || outPos == outSize)\r\n      break;\r\n\r\n    b = buf0[inPos++];\r\n\r\n    if (b == 0xE8)\r\n      prob = p + prevByte;\r\n    else if (b == 0xE9)\r\n      prob = p + 256;\r\n    else\r\n      prob = p + 257;\r\n\r\n    IF_BIT_0(prob)\r\n    {\r\n      UPDATE_0(prob)\r\n      prevByte = b;\r\n    }\r\n    else\r\n    {\r\n      UInt32 dest;\r\n      const Byte *v;\r\n      UPDATE_1(prob)\r\n      if (b == 0xE8)\r\n      {\r\n        v = buf1;\r\n        if (size1 < 4)\r\n          return SZ_ERROR_DATA;\r\n        buf1 += 4;\r\n        size1 -= 4;\r\n      }\r\n      else\r\n      {\r\n        v = buf2;\r\n        if (size2 < 4)\r\n          return SZ_ERROR_DATA;\r\n        buf2 += 4;\r\n        size2 -= 4;\r\n      }\r\n      dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |\r\n          ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);\r\n      outBuf[outPos++] = (Byte)dest;\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 8);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 16);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = prevByte = (Byte)(dest >> 24);\r\n    }\r\n  }\r\n  return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Bcj2.h",
    "content": "/* Bcj2.h -- Converter for x86 code (BCJ2)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __BCJ2_H\r\n#define __BCJ2_H\r\n\r\n#include \"Types.h\"\r\n\r\n/*\r\nConditions:\r\n  outSize <= FullOutputSize,\r\n  where FullOutputSize is full size of output stream of x86_2 filter.\r\n\r\nIf buf0 overlaps outBuf, there are two required conditions:\r\n  1) (buf0 >= outBuf)\r\n  2) (buf0 + size0 >= outBuf + FullOutputSize).\r\n\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nint Bcj2_Decode(\r\n    const Byte *buf0, SizeT size0,\r\n    const Byte *buf1, SizeT size1,\r\n    const Byte *buf2, SizeT size2,\r\n    const Byte *buf3, SizeT size3,\r\n    Byte *outBuf, SizeT outSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Bra.c",
    "content": "/* Bra.c -- Converters for RISC code\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  ip += 8;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      dest >>= 2;\r\n      data[i + 2] = (Byte)(dest >> 16);\r\n      data[i + 1] = (Byte)(dest >> 8);\r\n      data[i + 0] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  ip += 4;\r\n  for (i = 0; i <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 &&\r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src =\r\n        (((UInt32)data[i + 1] & 0x7) << 19) |\r\n        ((UInt32)data[i + 0] << 11) |\r\n        (((UInt32)data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));\r\n      data[i + 0] = (Byte)(dest >> 11);\r\n      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));\r\n      data[i + 2] = (Byte)dest;\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)\r\n    {\r\n      UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  UInt32 i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||\r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src =\r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      UInt32 dest;\r\n      \r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = ip + i + src;\r\n      else\r\n        dest = src - (ip + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Bra.h",
    "content": "/* Bra.h -- Branch converters for executables\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __BRA_H\r\n#define __BRA_H\r\n\r\n#include \"Types.h\"\r\n\r\n/*\r\nThese functions convert relative addresses to absolute addresses\r\nin CALL instructions to increase the compression ratio.\r\n  \r\n  In:\r\n    data     - data buffer\r\n    size     - size of data\r\n    ip       - current virtual Instruction Pinter (IP) value\r\n    state    - state variable for x86 converter\r\n    encoding - 0 (for decoding), 1 (for encoding)\r\n  \r\n  Out:\r\n    state    - state variable for x86 converter\r\n\r\n  Returns:\r\n    The number of processed bytes. If you call these functions with multiple calls,\r\n    you must start next call with first byte after block of processed bytes.\r\n  \r\n  Type   Endian  Alignment  LookAhead\r\n  \r\n  x86    little      1          4\r\n  ARMT   little      2          2\r\n  ARM    little      4          0\r\n  PPC     big        4          0\r\n  SPARC   big        4          0\r\n  IA64   little     16          0\r\n\r\n  size must be >= Alignment + LookAhead, if it's not last block.\r\n  If (size < Alignment + LookAhead), converter returns 0.\r\n\r\n  Example:\r\n\r\n    UInt32 ip = 0;\r\n    for ()\r\n    {\r\n      ; size must be >= Alignment + LookAhead, if it's not last block\r\n      SizeT processed = Convert(data, size, ip, 1);\r\n      data += processed;\r\n      size -= processed;\r\n      ip += processed;\r\n    }\r\n*/\r\n\r\n#define x86_Convert_Init(state) { state = 0; }\r\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);\r\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Bra86.c",
    "content": "/* Bra86.c -- Converter for x86 code (BCJ)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)\r\n{\r\n  SizeT bufferPos = 0, prevPosT;\r\n  UInt32 prevMask = *state & 0x7;\r\n  if (size < 5)\r\n    return 0;\r\n  ip += 5;\r\n  prevPosT = (SizeT)0 - 1;\r\n\r\n  for (;;)\r\n  {\r\n    Byte *p = data + bufferPos;\r\n    Byte *limit = data + size - 4;\r\n    for (; p < limit; p++)\r\n      if ((*p & 0xFE) == 0xE8)\r\n        break;\r\n    bufferPos = (SizeT)(p - data);\r\n    if (p >= limit)\r\n      break;\r\n    prevPosT = bufferPos - prevPosT;\r\n    if (prevPosT > 3)\r\n      prevMask = 0;\r\n    else\r\n    {\r\n      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r\n      if (prevMask != 0)\r\n      {\r\n        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r\n        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r\n        {\r\n          prevPosT = bufferPos;\r\n          prevMask = ((prevMask << 1) & 0x7) | 1;\r\n          bufferPos++;\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    prevPosT = bufferPos;\r\n\r\n    if (Test86MSByte(p[4]))\r\n    {\r\n      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r\n      UInt32 dest;\r\n      for (;;)\r\n      {\r\n        Byte b;\r\n        int index;\r\n        if (encoding)\r\n          dest = (ip + (UInt32)bufferPos) + src;\r\n        else\r\n          dest = src - (ip + (UInt32)bufferPos);\r\n        if (prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[prevMask] * 8;\r\n        b = (Byte)(dest >> (24 - index));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index)) - 1);\r\n      }\r\n      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      p[3] = (Byte)(dest >> 16);\r\n      p[2] = (Byte)(dest >> 8);\r\n      p[1] = (Byte)dest;\r\n      bufferPos += 5;\r\n    }\r\n    else\r\n    {\r\n      prevMask = ((prevMask << 1) & 0x7) | 1;\r\n      bufferPos++;\r\n    }\r\n  }\r\n  prevPosT = bufferPos - prevPosT;\r\n  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/BraIA64.c",
    "content": "/* BraIA64.c -- Converter for IA-64 code\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\nstatic const Byte kBranchTable[32] =\r\n{\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0\r\n};\r\n\r\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 16)\r\n    return 0;\r\n  size -= 16;\r\n  for (i = 0; i <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    int slot;\r\n    for (slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      UInt32 bytePos, bitRes;\r\n      UInt64 instruction, instNorm;\r\n      int j;\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      bytePos = (bitPos >> 3);\r\n      bitRes = bitPos & 0x7;\r\n      instruction = 0;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)data[i + j + bytePos] << (8 * j);\r\n\r\n      instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)\r\n      {\r\n        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);\r\n        UInt32 dest;\r\n        src |= ((UInt32)(instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        if (encoding)\r\n          dest = ip + (UInt32)i + src;\r\n        else\r\n          dest = src - (ip + (UInt32)i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~((UInt64)(0x8FFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/CpuArch.h",
    "content": "/* CpuArch.h\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __CPUARCH_H\r\n#define __CPUARCH_H\r\n\r\n/*\r\nLITTLE_ENDIAN_UNALIGN means:\r\n  1) CPU is LITTLE_ENDIAN\r\n  2) it's allowed to make unaligned memory accesses\r\nif LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know\r\nabout these properties of platform.\r\n*/\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#ifdef LITTLE_ENDIAN_UNALIGN\r\n\r\n#define GetUi16(p) (*(const UInt16 *)(p))\r\n#define GetUi32(p) (*(const UInt32 *)(p))\r\n#define GetUi64(p) (*(const UInt64 *)(p))\r\n#define SetUi32(p, d) *(UInt32 *)(p) = (d);\r\n\r\n#else\r\n\r\n#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))\r\n\r\n#define GetUi32(p) ( \\\r\n             ((const Byte *)(p))[0]        | \\\r\n    ((UInt32)((const Byte *)(p))[1] <<  8) | \\\r\n    ((UInt32)((const Byte *)(p))[2] << 16) | \\\r\n    ((UInt32)((const Byte *)(p))[3] << 24))\r\n\r\n#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))\r\n\r\n#define SetUi32(p, d) { UInt32 _x_ = (d); \\\r\n    ((Byte *)(p))[0] = (Byte)_x_; \\\r\n    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \\\r\n    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \\\r\n    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }\r\n\r\n#endif\r\n\r\n#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)\r\n\r\n#pragma intrinsic(_byteswap_ulong)\r\n#pragma intrinsic(_byteswap_uint64)\r\n#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))\r\n#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))\r\n\r\n#else\r\n\r\n#define GetBe32(p) ( \\\r\n    ((UInt32)((const Byte *)(p))[0] << 24) | \\\r\n    ((UInt32)((const Byte *)(p))[1] << 16) | \\\r\n    ((UInt32)((const Byte *)(p))[2] <<  8) | \\\r\n             ((const Byte *)(p))[3] )\r\n\r\n#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))\r\n\r\n#endif\r\n\r\n#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzFind.c",
    "content": "/* LzFind.c -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"LzFind.h\"\r\n#include \"LzHash.h\"\r\n\r\n#define kEmptyHashValue 0\r\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\r\n#define kMaxHistorySize ((UInt32)3 << 30)\r\n\r\n#define kStartMaxLen 3\r\n\r\nstatic void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  if (!p->directInput)\r\n  {\r\n    alloc->Free(alloc, p->bufferBase);\r\n    p->bufferBase = 0;\r\n  }\r\n}\r\n\r\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r\n\r\nstatic int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r\n{\r\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r\n  if (p->directInput)\r\n  {\r\n    p->blockSize = blockSize;\r\n    return 1;\r\n  }\r\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\r\n  {\r\n    LzInWindow_Free(p, alloc);\r\n    p->blockSize = blockSize;\r\n    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r\n  }\r\n  return (p->bufferBase != 0);\r\n}\r\n\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r\n\r\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r\n\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r\n{\r\n  p->posLimit -= subValue;\r\n  p->pos -= subValue;\r\n  p->streamPos -= subValue;\r\n}\r\n\r\nstatic void MatchFinder_ReadBlock(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached || p->result != SZ_OK)\r\n    return;\r\n  for (;;)\r\n  {\r\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\r\n    size_t size = (p->bufferBase + p->blockSize - dest);\r\n    if (size == 0)\r\n      return;\r\n    p->result = p->stream->Read(p->stream, dest, &size);\r\n    if (p->result != SZ_OK)\r\n      return;\r\n    if (size == 0)\r\n    {\r\n      p->streamEndWasReached = 1;\r\n      return;\r\n    }\r\n    p->streamPos += (UInt32)size;\r\n    if (p->streamPos - p->pos > p->keepSizeAfter)\r\n      return;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\r\n{\r\n  memmove(p->bufferBase,\r\n    p->buffer - p->keepSizeBefore,\r\n    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\r\n  p->buffer = p->bufferBase + p->keepSizeBefore;\r\n}\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p)\r\n{\r\n  /* if (p->streamEndWasReached) return 0; */\r\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r\n}\r\n\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached)\r\n    return;\r\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\r\n    MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r\n{\r\n  if (MatchFinder_NeedMove(p))\r\n    MatchFinder_MoveBlock(p);\r\n  MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_SetDefaultSettings(CMatchFinder *p)\r\n{\r\n  p->cutValue = 32;\r\n  p->btMode = 1;\r\n  p->numHashBytes = 4;\r\n  /* p->skipModeBits = 0; */\r\n  p->directInput = 0;\r\n  p->bigHash = 0;\r\n}\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  p->bufferBase = 0;\r\n  p->directInput = 0;\r\n  p->hash = 0;\r\n  MatchFinder_SetDefaultSettings(p);\r\n\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    p->crc[i] = r;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hash);\r\n  p->hash = 0;\r\n}\r\n\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  MatchFinder_FreeThisClassMemory(p, alloc);\r\n  LzInWindow_Free(p, alloc);\r\n}\r\n\r\nstatic CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r\n{\r\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r\n  if (sizeInBytes / sizeof(CLzRef) != num)\r\n    return 0;\r\n  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r\n}\r\n\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 sizeReserv;\r\n  if (historySize > kMaxHistorySize)\r\n  {\r\n    MatchFinder_Free(p, alloc);\r\n    return 0;\r\n  }\r\n  sizeReserv = historySize >> 1;\r\n  if (historySize > ((UInt32)2 << 30))\r\n    sizeReserv = historySize >> 2;\r\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r\n\r\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r\n  if (LzInWindow_Create(p, sizeReserv, alloc))\r\n  {\r\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r\n    UInt32 hs;\r\n    p->matchMaxLen = matchMaxLen;\r\n    {\r\n      p->fixedHashSize = 0;\r\n      if (p->numHashBytes == 2)\r\n        hs = (1 << 16) - 1;\r\n      else\r\n      {\r\n        hs = historySize - 1;\r\n        hs |= (hs >> 1);\r\n        hs |= (hs >> 2);\r\n        hs |= (hs >> 4);\r\n        hs |= (hs >> 8);\r\n        hs >>= 1;\r\n        /* hs >>= p->skipModeBits; */\r\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r\n        if (hs > (1 << 24))\r\n        {\r\n          if (p->numHashBytes == 3)\r\n            hs = (1 << 24) - 1;\r\n          else\r\n            hs >>= 1;\r\n        }\r\n      }\r\n      p->hashMask = hs;\r\n      hs++;\r\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r\n      hs += p->fixedHashSize;\r\n    }\r\n\r\n    {\r\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\r\n      UInt32 newSize;\r\n      p->historySize = historySize;\r\n      p->hashSizeSum = hs;\r\n      p->cyclicBufferSize = newCyclicBufferSize;\r\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r\n      newSize = p->hashSizeSum + p->numSons;\r\n      if (p->hash != 0 && prevSize == newSize)\r\n        return 1;\r\n      MatchFinder_FreeThisClassMemory(p, alloc);\r\n      p->hash = AllocRefs(newSize, alloc);\r\n      if (p->hash != 0)\r\n      {\r\n        p->son = p->hash + p->hashSizeSum;\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  MatchFinder_Free(p, alloc);\r\n  return 0;\r\n}\r\n\r\nstatic void MatchFinder_SetLimits(CMatchFinder *p)\r\n{\r\n  UInt32 limit = kMaxValForNormalize - p->pos;\r\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  limit2 = p->streamPos - p->pos;\r\n  if (limit2 <= p->keepSizeAfter)\r\n  {\r\n    if (limit2 > 0)\r\n      limit2 = 1;\r\n  }\r\n  else\r\n    limit2 -= p->keepSizeAfter;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  {\r\n    UInt32 lenLimit = p->streamPos - p->pos;\r\n    if (lenLimit > p->matchMaxLen)\r\n      lenLimit = p->matchMaxLen;\r\n    p->lenLimit = lenLimit;\r\n  }\r\n  p->posLimit = p->pos + limit;\r\n}\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->hashSizeSum; i++)\r\n    p->hash[i] = kEmptyHashValue;\r\n  p->cyclicBufferPos = 0;\r\n  p->buffer = p->bufferBase;\r\n  p->pos = p->streamPos = p->cyclicBufferSize;\r\n  p->result = SZ_OK;\r\n  p->streamEndWasReached = 0;\r\n  MatchFinder_ReadBlock(p);\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r\n{\r\n  return (p->pos - p->historySize - 1) & kNormalizeMask;\r\n}\r\n\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_Normalize(CMatchFinder *p)\r\n{\r\n  UInt32 subValue = MatchFinder_GetSubValue(p);\r\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r\n  MatchFinder_ReduceOffsets(p, subValue);\r\n}\r\n\r\nstatic void MatchFinder_CheckLimits(CMatchFinder *p)\r\n{\r\n  if (p->pos == kMaxValForNormalize)\r\n    MatchFinder_Normalize(p);\r\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r\n    MatchFinder_CheckAndMoveAndRead(p);\r\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\r\n    p->cyclicBufferPos = 0;\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  son[_cyclicBufferPos] = curMatch;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n      return distances;\r\n    {\r\n      const Byte *pb = cur - delta;\r\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r\n      {\r\n        UInt32 len = 0;\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n            return distances;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return distances;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return distances;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        {\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define MOVE_POS \\\r\n  ++p->cyclicBufferPos; \\\r\n  p->buffer++; \\\r\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r\n\r\n#define MOVE_POS_RET MOVE_POS return offset;\r\n\r\nstatic void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r\n\r\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\r\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\r\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\r\n  cur = p->buffer;\r\n\r\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r\n\r\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r\n\r\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\r\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\r\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\r\n\r\n#define SKIP_FOOTER \\\r\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r\n\r\nstatic UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(2)\r\n  HASH2_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 1)\r\n}\r\n\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 2)\r\n}\r\n\r\nstatic UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, delta2, maxLen, offset;\r\n  GET_MATCHES_HEADER(3)\r\n\r\n  HASH3_CALC;\r\n\r\n  delta2 = p->pos - p->hash[hash2Value];\r\n  curMatch = p->hash[kFix3HashSize + hashValue];\r\n  \r\n  p->hash[hash2Value] =\r\n  p->hash[kFix3HashSize + hashValue] = p->pos;\r\n\r\n\r\n  maxLen = 2;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[0] = maxLen;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n  \r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n\r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      p->son[p->cyclicBufferPos] = curMatch;\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances + offset, maxLen) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances, 2) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nstatic void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(2)\r\n    HASH2_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value;\r\n    SKIP_HEADER(3)\r\n    HASH3_CALC;\r\n    curMatch = p->hash[kFix3HashSize + hashValue];\r\n    p->hash[hash2Value] =\r\n    p->hash[kFix3HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] =\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r\n  if (!p->btMode)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 2)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 3)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r\n  }\r\n  else\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzFind.h",
    "content": "/* LzFind.h -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFIND_H\r\n#define __LZFIND_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef UInt32 CLzRef;\r\n\r\ntypedef struct _CMatchFinder\r\n{\r\n  Byte *buffer;\r\n  UInt32 pos;\r\n  UInt32 posLimit;\r\n  UInt32 streamPos;\r\n  UInt32 lenLimit;\r\n\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r\n\r\n  UInt32 matchMaxLen;\r\n  CLzRef *hash;\r\n  CLzRef *son;\r\n  UInt32 hashMask;\r\n  UInt32 cutValue;\r\n\r\n  Byte *bufferBase;\r\n  ISeqInStream *stream;\r\n  int streamEndWasReached;\r\n\r\n  UInt32 blockSize;\r\n  UInt32 keepSizeBefore;\r\n  UInt32 keepSizeAfter;\r\n\r\n  UInt32 numHashBytes;\r\n  int directInput;\r\n  int btMode;\r\n  /* int skipModeBits; */\r\n  int bigHash;\r\n  UInt32 historySize;\r\n  UInt32 fixedHashSize;\r\n  UInt32 hashSizeSum;\r\n  UInt32 numSons;\r\n  SRes result;\r\n  UInt32 crc[256];\r\n} CMatchFinder;\r\n\r\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r\n\r\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p);\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p);\r\n\r\n/* Conditions:\r\n     historySize <= 3 GB\r\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r\n*/\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc);\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *distances, UInt32 maxLen);\r\n\r\n/*\r\nConditions:\r\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r\n*/\r\n\r\ntypedef void (*Mf_Init_Func)(void *object);\r\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\r\n\r\ntypedef struct _IMatchFinder\r\n{\r\n  Mf_Init_Func Init;\r\n  Mf_GetIndexByte_Func GetIndexByte;\r\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r\n  Mf_GetMatches_Func GetMatches;\r\n  Mf_Skip_Func Skip;\r\n} IMatchFinder;\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p);\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzFindMt.c",
    "content": "/* LzFindMt.c -- multithreaded Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzHash.h\"\r\n\r\n#include \"LzFindMt.h\"\r\n\r\nvoid MtSync_Construct(CMtSync *p)\r\n{\r\n  p->wasCreated = False;\r\n  p->csWasInitialized = False;\r\n  p->csWasEntered = False;\r\n  Thread_Construct(&p->thread);\r\n  Event_Construct(&p->canStart);\r\n  Event_Construct(&p->wasStarted);\r\n  Event_Construct(&p->wasStopped);\r\n  Semaphore_Construct(&p->freeSemaphore);\r\n  Semaphore_Construct(&p->filledSemaphore);\r\n}\r\n\r\nvoid MtSync_GetNextBlock(CMtSync *p)\r\n{\r\n  if (p->needStart)\r\n  {\r\n    p->numProcessedBlocks = 1;\r\n    p->needStart = False;\r\n    p->stopWriting = False;\r\n    p->exit = False;\r\n    Event_Reset(&p->wasStarted);\r\n    Event_Reset(&p->wasStopped);\r\n\r\n    Event_Set(&p->canStart);\r\n    Event_Wait(&p->wasStarted);\r\n  }\r\n  else\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n    p->numProcessedBlocks++;\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  Semaphore_Wait(&p->filledSemaphore);\r\n  CriticalSection_Enter(&p->cs);\r\n  p->csWasEntered = True;\r\n}\r\n\r\n/* MtSync_StopWriting must be called if Writing was started */\r\n\r\nvoid MtSync_StopWriting(CMtSync *p)\r\n{\r\n  UInt32 myNumBlocks = p->numProcessedBlocks;\r\n  if (!Thread_WasCreated(&p->thread) || p->needStart)\r\n    return;\r\n  p->stopWriting = True;\r\n  if (p->csWasEntered)\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n  }\r\n  Semaphore_Release1(&p->freeSemaphore);\r\n \r\n  Event_Wait(&p->wasStopped);\r\n\r\n  while (myNumBlocks++ != p->numProcessedBlocks)\r\n  {\r\n    Semaphore_Wait(&p->filledSemaphore);\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  p->needStart = True;\r\n}\r\n\r\nvoid MtSync_Destruct(CMtSync *p)\r\n{\r\n  if (Thread_WasCreated(&p->thread))\r\n  {\r\n    MtSync_StopWriting(p);\r\n    p->exit = True;\r\n    if (p->needStart)\r\n      Event_Set(&p->canStart);\r\n    Thread_Wait(&p->thread);\r\n    Thread_Close(&p->thread);\r\n  }\r\n  if (p->csWasInitialized)\r\n  {\r\n    CriticalSection_Delete(&p->cs);\r\n    p->csWasInitialized = False;\r\n  }\r\n\r\n  Event_Close(&p->canStart);\r\n  Event_Close(&p->wasStarted);\r\n  Event_Close(&p->wasStopped);\r\n  Semaphore_Close(&p->freeSemaphore);\r\n  Semaphore_Close(&p->filledSemaphore);\r\n\r\n  p->wasCreated = False;\r\n}\r\n\r\n#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }\r\n\r\nstatic SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  if (p->wasCreated)\r\n    return SZ_OK;\r\n\r\n  RINOK_THREAD(CriticalSection_Init(&p->cs));\r\n  p->csWasInitialized = True;\r\n\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));\r\n  \r\n  RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));\r\n  RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));\r\n\r\n  p->needStart = True;\r\n  \r\n  RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));\r\n  p->wasCreated = True;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\r\n  if (res != SZ_OK)\r\n    MtSync_Destruct(p);\r\n  return res;\r\n}\r\n\r\nvoid MtSync_Init(CMtSync *p) { p->needStart = True; }\r\n\r\n#define kMtMaxValForNormalize 0xFFFFFFFF\r\n\r\n#define DEF_GetHeads2(name, v, action) \\\r\nstatic void GetHeads ## name(const Byte *p, UInt32 pos, \\\r\nUInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \\\r\n{ action; for (; numHeads != 0; numHeads--) { \\\r\nconst UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r\n\r\n#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)\r\n\r\nDEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )\r\nDEF_GetHeads(3,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\r\nDEF_GetHeads(4,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)\r\nDEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\r\nDEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)\r\n\r\nvoid HashThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->hashSync;\r\n  for (;;)\r\n  {\r\n    UInt32 numProcessedBlocks = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = numProcessedBlocks;\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n\r\n      {\r\n        CMatchFinder *mf = mt->MatchFinder;\r\n        if (MatchFinder_NeedMove(mf))\r\n        {\r\n          CriticalSection_Enter(&mt->btSync.cs);\r\n          CriticalSection_Enter(&mt->hashSync.cs);\r\n          {\r\n            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            const Byte *afterPtr;\r\n            MatchFinder_MoveBlock(mf);\r\n            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            mt->pointerToCurPos -= beforePtr - afterPtr;\r\n            mt->buffer -= beforePtr - afterPtr;\r\n          }\r\n          CriticalSection_Leave(&mt->btSync.cs);\r\n          CriticalSection_Leave(&mt->hashSync.cs);\r\n          continue;\r\n        }\r\n\r\n        Semaphore_Wait(&p->freeSemaphore);\r\n\r\n        MatchFinder_ReadIfRequired(mf);\r\n        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))\r\n        {\r\n          UInt32 subValue = (mf->pos - mf->historySize - 1);\r\n          MatchFinder_ReduceOffsets(mf, subValue);\r\n          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);\r\n        }\r\n        {\r\n          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n          UInt32 num = mf->streamPos - mf->pos;\r\n          heads[0] = 2;\r\n          heads[1] = num;\r\n          if (num >= mf->numHashBytes)\r\n          {\r\n            num = num - mf->numHashBytes + 1;\r\n            if (num > kMtHashBlockSize - 2)\r\n              num = kMtHashBlockSize - 2;\r\n            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);\r\n            heads[0] += num;\r\n          }\r\n          mf->pos += num;\r\n          mf->buffer += num;\r\n        }\r\n      }\r\n\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r\n{\r\n  MtSync_GetNextBlock(&p->hashSync);\r\n  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];\r\n  p->hashNumAvail = p->hashBuf[p->hashBufPos++];\r\n}\r\n\r\n#define kEmptyHashValue 0\r\n\r\n/* #define MFMT_GM_INLINE */\r\n\r\n#ifdef MFMT_GM_INLINE\r\n\r\n#define NO_INLINE MY_FAST_CALL\r\n\r\nInt32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\r\n{\r\n  do\r\n  {\r\n  UInt32 *distances = _distances + 1;\r\n  UInt32 curMatch = pos - *hash++;\r\n\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  UInt32 cutValue = _cutValue;\r\n  UInt32 maxLen = _maxLen;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      break;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            break;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n  pos++;\r\n  _cyclicBufferPos++;\r\n  cur++;\r\n  {\r\n    UInt32 num = (UInt32)(distances - _distances);\r\n    *_distances = num - 1;\r\n    _distances += num;\r\n    limit -= num;\r\n  }\r\n  }\r\n  while (limit > 0 && --size != 0);\r\n  *posRes = pos;\r\n  return limit;\r\n}\r\n\r\n#endif\r\n\r\nvoid BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  UInt32 numProcessed = 0;\r\n  UInt32 curPos = 2;\r\n  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\r\n  distances[1] = p->hashNumAvail;\r\n  while (curPos < limit)\r\n  {\r\n    if (p->hashBufPos == p->hashBufPosLimit)\r\n    {\r\n      MatchFinderMt_GetNextBlock_Hash(p);\r\n      distances[1] = numProcessed + p->hashNumAvail;\r\n      if (p->hashNumAvail >= p->numHashBytes)\r\n        continue;\r\n      for (; p->hashNumAvail != 0; p->hashNumAvail--)\r\n        distances[curPos++] = 0;\r\n      break;\r\n    }\r\n    {\r\n      UInt32 size = p->hashBufPosLimit - p->hashBufPos;\r\n      UInt32 lenLimit = p->matchMaxLen;\r\n      UInt32 pos = p->pos;\r\n      UInt32 cyclicBufferPos = p->cyclicBufferPos;\r\n      if (lenLimit >= p->hashNumAvail)\r\n        lenLimit = p->hashNumAvail;\r\n      {\r\n        UInt32 size2 = p->hashNumAvail - lenLimit + 1;\r\n        if (size2 < size)\r\n          size = size2;\r\n        size2 = p->cyclicBufferSize - cyclicBufferPos;\r\n        if (size2 < size)\r\n          size = size2;\r\n      }\r\n      #ifndef MFMT_GM_INLINE\r\n      while (curPos < limit && size-- != 0)\r\n      {\r\n        UInt32 *startDistances = distances + curPos;\r\n        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],\r\n          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r\n          startDistances + 1, p->numHashBytes - 1) - startDistances);\r\n        *startDistances = num - 1;\r\n        curPos += num;\r\n        cyclicBufferPos++;\r\n        pos++;\r\n        p->buffer++;\r\n      }\r\n      #else\r\n      {\r\n        UInt32 posRes;\r\n        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r\n          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);\r\n        p->hashBufPos += posRes - pos;\r\n        cyclicBufferPos += posRes - pos;\r\n        p->buffer += posRes - pos;\r\n        pos = posRes;\r\n      }\r\n      #endif\r\n\r\n      numProcessed += pos - p->pos;\r\n      p->hashNumAvail -= pos - p->pos;\r\n      p->pos = pos;\r\n      if (cyclicBufferPos == p->cyclicBufferSize)\r\n        cyclicBufferPos = 0;\r\n      p->cyclicBufferPos = cyclicBufferPos;\r\n    }\r\n  }\r\n  distances[0] = curPos;\r\n}\r\n\r\nvoid BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r\n{\r\n  CMtSync *sync = &p->hashSync;\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Enter(&sync->cs);\r\n    sync->csWasEntered = True;\r\n  }\r\n  \r\n  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);\r\n\r\n  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\r\n  {\r\n    UInt32 subValue = p->pos - p->cyclicBufferSize;\r\n    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);\r\n    p->pos -= subValue;\r\n  }\r\n\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Leave(&sync->cs);\r\n    sync->csWasEntered = False;\r\n  }\r\n}\r\n\r\nvoid BtThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->btSync;\r\n  for (;;)\r\n  {\r\n    UInt32 blockIndex = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = blockIndex;\r\n        MtSync_StopWriting(&mt->hashSync);\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n      Semaphore_Wait(&p->freeSemaphore);\r\n      BtFillBlock(mt, blockIndex++);\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p)\r\n{\r\n  p->hashBuf = 0;\r\n  MtSync_Construct(&p->hashSync);\r\n  MtSync_Construct(&p->btSync);\r\n}\r\n\r\nvoid MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hashBuf);\r\n  p->hashBuf = 0;\r\n}\r\n\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  MtSync_Destruct(&p->hashSync);\r\n  MtSync_Destruct(&p->btSync);\r\n  MatchFinderMt_FreeMem(p, alloc);\r\n}\r\n\r\n#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\r\n#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\r\n\r\nstatic unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r\nstatic unsigned MY_STD_CALL BtThreadFunc2(void *p)\r\n{\r\n  Byte allocaDummy[0x180];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  BtThreadFunc((CMatchFinderMt *)p);\r\n  return 0;\r\n}\r\n\r\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\r\n{\r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->historySize = historySize;\r\n  if (kMtBtBlockSize <= matchMaxLen * 4)\r\n    return SZ_ERROR_PARAM;\r\n  if (p->hashBuf == 0)\r\n  {\r\n    p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r\n    if (p->hashBuf == 0)\r\n      return SZ_ERROR_MEM;\r\n    p->btBuf = p->hashBuf + kHashBufferSize;\r\n  }\r\n  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);\r\n  keepAddBufferAfter += kMtHashBlockSize;\r\n  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))\r\n    return SZ_ERROR_MEM;\r\n\r\n  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));\r\n  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));\r\n  return SZ_OK;\r\n}\r\n\r\n/* Call it after ReleaseStream / SetStream */\r\nvoid MatchFinderMt_Init(CMatchFinderMt *p)\r\n{\r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->btBufPos = p->btBufPosLimit = 0;\r\n  p->hashBufPos = p->hashBufPosLimit = 0;\r\n  MatchFinder_Init(mf);\r\n  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);\r\n  p->btNumAvailBytes = 0;\r\n  p->lzPos = p->historySize + 1;\r\n\r\n  p->hash = mf->hash;\r\n  p->fixedHashSize = mf->fixedHashSize;\r\n  p->crc = mf->crc;\r\n\r\n  p->son = mf->son;\r\n  p->matchMaxLen = mf->matchMaxLen;\r\n  p->numHashBytes = mf->numHashBytes;\r\n  p->pos = mf->pos;\r\n  p->buffer = mf->buffer;\r\n  p->cyclicBufferPos = mf->cyclicBufferPos;\r\n  p->cyclicBufferSize = mf->cyclicBufferSize;\r\n  p->cutValue = mf->cutValue;\r\n}\r\n\r\n/* ReleaseStream is required to finish multithreading */\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p)\r\n{\r\n  MtSync_StopWriting(&p->btSync);\r\n  /* p->MatchFinder->ReleaseStream(); */\r\n}\r\n\r\nvoid MatchFinderMt_Normalize(CMatchFinderMt *p)\r\n{\r\n  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\r\n  p->lzPos = p->historySize + 1;\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r\n{\r\n  UInt32 blockIndex;\r\n  MtSync_GetNextBlock(&p->btSync);\r\n  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);\r\n  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;\r\n  p->btBufPosLimit += p->btBuf[p->btBufPos++];\r\n  p->btNumAvailBytes = p->btBuf[p->btBufPos++];\r\n  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)\r\n    MatchFinderMt_Normalize(p);\r\n}\r\n\r\nconst Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r\n{\r\n  return p->pointerToCurPos;\r\n}\r\n\r\n#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\r\n\r\nUInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r\n{\r\n  GET_NEXT_BLOCK_IF_REQUIRED;\r\n  return p->btNumAvailBytes;\r\n}\r\n\r\nByte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)\r\n{\r\n  return p->pointerToCurPos[index];\r\n}\r\n\r\nUInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, curMatch2;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH2_CALC\r\n      \r\n  curMatch2 = hash[hash2Value];\r\n  hash[hash2Value] = lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos)\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n    {\r\n      *distances++ = 2;\r\n      *distances++ = lzPos - curMatch2 - 1;\r\n    }\r\n  return distances;\r\n}\r\n\r\nUInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH3_CALC\r\n\r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  \r\n  hash[                hash2Value] =\r\n  hash[kFix3HashSize + hash3Value] =\r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] = 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    *distances++ = 3;\r\n    *distances++ = lzPos - curMatch3 - 1;\r\n  }\r\n  return distances;\r\n}\r\n\r\n/*\r\nUInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH4_CALC\r\n      \r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  curMatch4 = hash[kFix4HashSize + hash4Value];\r\n  \r\n  hash[                hash2Value] =\r\n  hash[kFix3HashSize + hash3Value] =\r\n  hash[kFix4HashSize + hash4Value] =\r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch3 - 1;\r\n    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])\r\n    {\r\n      distances[0] = 4;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 3;\r\n    distances += 2;\r\n  }\r\n\r\n  if (curMatch4 >= matchMinPos)\r\n    if (\r\n      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&\r\n      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]\r\n      )\r\n    {\r\n      *distances++ = 4;\r\n      *distances++ = lzPos - curMatch4 - 1;\r\n    }\r\n  return distances;\r\n}\r\n*/\r\n\r\n#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\r\n\r\nUInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n  p->btNumAvailBytes--;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < len; i += 2)\r\n    {\r\n      *distances++ = *btBuf++;\r\n      *distances++ = *btBuf++;\r\n    }\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\nUInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n\r\n  if (len == 0)\r\n  {\r\n    if (p->btNumAvailBytes-- >= 4)\r\n      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\r\n  }\r\n  else\r\n  {\r\n    /* Condition: there are matches in btBuf with length < p->numHashBytes */\r\n    UInt32 *distances2;\r\n    p->btNumAvailBytes--;\r\n    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\r\n    do\r\n    {\r\n      *distances2++ = *btBuf++;\r\n      *distances2++ = *btBuf++;\r\n    }\r\n    while ((len -= 2) != 0);\r\n    len  = (UInt32)(distances2 - (distances));\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\n#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED\r\n#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r\n#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);\r\n\r\nvoid MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER2 { p->btNumAvailBytes--;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(2)\r\n      UInt32 hash2Value;\r\n      MT_HASH2_CALC\r\n      hash[hash2Value] = p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(3)\r\n      UInt32 hash2Value, hash3Value;\r\n      MT_HASH3_CALC\r\n      hash[kFix3HashSize + hash3Value] =\r\n      hash[                hash2Value] =\r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\n/*\r\nvoid MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(4)\r\n      UInt32 hash2Value, hash3Value, hash4Value;\r\n      MT_HASH4_CALC\r\n      hash[kFix4HashSize + hash4Value] =\r\n      hash[kFix3HashSize + hash3Value] =\r\n      hash[                hash2Value] =\r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n*/\r\n\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\r\n  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\r\n  switch(p->MatchFinder->numHashBytes)\r\n  {\r\n    case 2:\r\n      p->GetHeadsFunc = GetHeads2;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)0;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\r\n      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\r\n      break;\r\n    case 3:\r\n      p->GetHeadsFunc = GetHeads3;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;\r\n      break;\r\n    default:\r\n    /* case 4: */\r\n      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\r\n      /* p->GetHeadsFunc = GetHeads4; */\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\r\n      break;\r\n    /*\r\n    default:\r\n      p->GetHeadsFunc = GetHeads5;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;\r\n      break;\r\n    */\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzFindMt.h",
    "content": "/* LzFindMt.h -- multithreaded Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFINDMT_H\r\n#define __LZFINDMT_H\r\n\r\n#include \"Threads.h\"\r\n#include \"LzFind.h\"\r\n\r\n#define kMtHashBlockSize (1 << 13)\r\n#define kMtHashNumBlocks (1 << 3)\r\n#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)\r\n\r\n#define kMtBtBlockSize (1 << 14)\r\n#define kMtBtNumBlocks (1 << 6)\r\n#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)\r\n\r\ntypedef struct _CMtSync\r\n{\r\n  Bool wasCreated;\r\n  Bool needStart;\r\n  Bool exit;\r\n  Bool stopWriting;\r\n\r\n  CThread thread;\r\n  CAutoResetEvent canStart;\r\n  CAutoResetEvent wasStarted;\r\n  CAutoResetEvent wasStopped;\r\n  CSemaphore freeSemaphore;\r\n  CSemaphore filledSemaphore;\r\n  Bool csWasInitialized;\r\n  Bool csWasEntered;\r\n  CCriticalSection cs;\r\n  UInt32 numProcessedBlocks;\r\n} CMtSync;\r\n\r\ntypedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);\r\n\r\n/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */\r\n#define kMtCacheLineDummy 128\r\n\r\ntypedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,\r\n  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);\r\n\r\ntypedef struct _CMatchFinderMt\r\n{\r\n  /* LZ */\r\n  const Byte *pointerToCurPos;\r\n  UInt32 *btBuf;\r\n  UInt32 btBufPos;\r\n  UInt32 btBufPosLimit;\r\n  UInt32 lzPos;\r\n  UInt32 btNumAvailBytes;\r\n\r\n  UInt32 *hash;\r\n  UInt32 fixedHashSize;\r\n  UInt32 historySize;\r\n  const UInt32 *crc;\r\n\r\n  Mf_Mix_Matches MixMatchesFunc;\r\n  \r\n  /* LZ + BT */\r\n  CMtSync btSync;\r\n  Byte btDummy[kMtCacheLineDummy];\r\n\r\n  /* BT */\r\n  UInt32 *hashBuf;\r\n  UInt32 hashBufPos;\r\n  UInt32 hashBufPosLimit;\r\n  UInt32 hashNumAvail;\r\n\r\n  CLzRef *son;\r\n  UInt32 matchMaxLen;\r\n  UInt32 numHashBytes;\r\n  UInt32 pos;\r\n  Byte *buffer;\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be historySize + 1 */\r\n  UInt32 cutValue;\r\n\r\n  /* BT + Hash */\r\n  CMtSync hashSync;\r\n  /* Byte hashDummy[kMtCacheLineDummy]; */\r\n  \r\n  /* Hash */\r\n  Mf_GetHeads GetHeadsFunc;\r\n  CMatchFinder *MatchFinder;\r\n} CMatchFinderMt;\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p);\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);\r\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzHash.h",
    "content": "/* LzHash.h -- HASH functions for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZHASH_H\r\n#define __LZHASH_H\r\n\r\n#define kHash2Size (1 << 10)\r\n#define kHash3Size (1 << 16)\r\n#define kHash4Size (1 << 20)\r\n\r\n#define kFix3HashSize (kHash2Size)\r\n#define kFix4HashSize (kHash2Size + kHash3Size)\r\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r\n\r\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r\n\r\n#define HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r\n\r\n#define HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r\n\r\n#define HASH5_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\\r\n  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\\r\n  hash4Value &= (kHash4Size - 1); }\r\n\r\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r\n\r\n\r\n#define MT_HASH2_CALC \\\r\n  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r\n\r\n#define MT_HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r\n\r\n#define MT_HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaDec.c",
    "content": "/* LzmaDec.c -- LZMA Decoder\r\n2008-11-06 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzmaDec.h\"\r\n\r\n#include <string.h>\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_INIT_SIZE 5\r\n\r\n#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));\r\n#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \\\r\n  { UPDATE_0(p); i = (i + i); A0; } else \\\r\n  { UPDATE_1(p); i = (i + i) + 1; A1; }\r\n#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)\r\n\r\n#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }\r\n#define TREE_DECODE(probs, limit, i) \\\r\n  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }\r\n\r\n/* #define _LZMA_SIZE_OPT */\r\n\r\n#ifdef _LZMA_SIZE_OPT\r\n#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)\r\n#else\r\n#define TREE_6_DECODE(probs, i) \\\r\n  { i = 1; \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  i -= 0x40; }\r\n#endif\r\n\r\n#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0_CHECK range = bound;\r\n#define UPDATE_1_CHECK range -= bound; code -= bound;\r\n#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \\\r\n  { UPDATE_0_CHECK; i = (i + i); A0; } else \\\r\n  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }\r\n#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)\r\n#define TREE_DECODE_CHECK(probs, limit, i) \\\r\n  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols)\r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nstatic const Byte kLiteralNextStates[kNumStates * 2] =\r\n{\r\n  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\r\n  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\r\n};\r\n\r\n#define LZMA_DIC_MIN (1 << 12)\r\n\r\n/* First LZMA-symbol is always decoded.\r\nAnd it decodes new LZMA-symbols while (buf < bufLimit), but \"buf\" is without last normalization\r\nOut:\r\n  Result:\r\n    SZ_OK - OK\r\n    SZ_ERROR_DATA - Error\r\n  p->remainLen:\r\n    < kMatchSpecLenStart : normal remain\r\n    = kMatchSpecLenStart : finished\r\n    = kMatchSpecLenStart + 1 : Flush marker\r\n    = kMatchSpecLenStart + 2 : State Init Marker\r\n*/\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  CLzmaProb *probs = p->probs;\r\n\r\n  unsigned state = p->state;\r\n  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];\r\n  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;\r\n  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;\r\n  unsigned lc = p->prop.lc;\r\n\r\n  Byte *dic = p->dic;\r\n  SizeT dicBufSize = p->dicBufSize;\r\n  SizeT dicPos = p->dicPos;\r\n  \r\n  UInt32 processedPos = p->processedPos;\r\n  UInt32 checkDicSize = p->checkDicSize;\r\n  unsigned len = 0;\r\n\r\n  const Byte *buf = p->buf;\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n\r\n  do\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = processedPos & pbMask;\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0(prob)\r\n    {\r\n      unsigned symbol;\r\n      UPDATE_0(prob);\r\n      prob = probs + Literal;\r\n      if (checkDicSize != 0 || processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r\n        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        symbol = 1;\r\n        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      dic[dicPos++] = (Byte)symbol;\r\n      processedPos++;\r\n\r\n      state = kLiteralNextStates[state];\r\n      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\r\n      continue;\r\n    }\r\n    else\r\n    {\r\n      UPDATE_1(prob);\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0(prob)\r\n      {\r\n        UPDATE_0(prob);\r\n        state += kNumStates;\r\n        prob = probs + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1(prob);\r\n        if (checkDicSize == 0 && processedPos == 0)\r\n          return SZ_ERROR_DATA;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0(prob)\r\n        {\r\n          UPDATE_0(prob);\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n            dicPos++;\r\n            processedPos++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            continue;\r\n          }\r\n          UPDATE_1(prob);\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UPDATE_1(prob);\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            distance = rep1;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(prob);\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0(prob)\r\n            {\r\n              UPDATE_0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0(probLen)\r\n        {\r\n          UPDATE_0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = (1 << kLenNumLowBits);\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0(probLen)\r\n          {\r\n            UPDATE_0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = (1 << kLenNumMidBits);\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = (1 << kLenNumHighBits);\r\n          }\r\n        }\r\n        TREE_DECODE(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state >= kNumStates)\r\n      {\r\n        UInt32 distance;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);\r\n        TREE_6_DECODE(prob, distance);\r\n        if (distance >= kStartPosModelIndex)\r\n        {\r\n          unsigned posSlot = (unsigned)distance;\r\n          int numDirectBits = (int)(((distance >> 1) - 1));\r\n          distance = (2 | (distance & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            distance <<= numDirectBits;\r\n            prob = probs + SpecPos + distance - posSlot - 1;\r\n            {\r\n              UInt32 mask = 1;\r\n              unsigned i = 1;\r\n              do\r\n              {\r\n                GET_BIT2(prob + i, i, ; , distance |= mask);\r\n                mask <<= 1;\r\n              }\r\n              while (--numDirectBits != 0);\r\n            }\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE\r\n              range >>= 1;\r\n              \r\n              {\r\n                UInt32 t;\r\n                code -= range;\r\n                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */\r\n                distance = (distance << 1) + (t + 1);\r\n                code += range & t;\r\n              }\r\n              /*\r\n              distance <<= 1;\r\n              if (code >= range)\r\n              {\r\n                code -= range;\r\n                distance |= 1;\r\n              }\r\n              */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            distance <<= kNumAlignBits;\r\n            {\r\n              unsigned i = 1;\r\n              GET_BIT2(prob + i, i, ; , distance |= 1);\r\n              GET_BIT2(prob + i, i, ; , distance |= 2);\r\n              GET_BIT2(prob + i, i, ; , distance |= 4);\r\n              GET_BIT2(prob + i, i, ; , distance |= 8);\r\n            }\r\n            if (distance == (UInt32)0xFFFFFFFF)\r\n            {\r\n              len += kMatchSpecLenStart;\r\n              state -= kNumStates;\r\n              break;\r\n            }\r\n          }\r\n        }\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        rep0 = distance + 1;\r\n        if (checkDicSize == 0)\r\n        {\r\n          if (distance >= processedPos)\r\n            return SZ_ERROR_DATA;\r\n        }\r\n        else if (distance >= checkDicSize)\r\n          return SZ_ERROR_DATA;\r\n        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r\n        /* state = kLiteralNextStates[state]; */\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n\r\n      if (limit == dicPos)\r\n        return SZ_ERROR_DATA;\r\n      {\r\n        SizeT rem = limit - dicPos;\r\n        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\r\n        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\r\n\r\n        processedPos += curLen;\r\n\r\n        len -= curLen;\r\n        if (pos + curLen <= dicBufSize)\r\n        {\r\n          Byte *dest = dic + dicPos;\r\n          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;\r\n          const Byte *lim = dest + curLen;\r\n          dicPos += curLen;\r\n          do\r\n            *(dest) = (Byte)*(dest + src);\r\n          while (++dest != lim);\r\n        }\r\n        else\r\n        {\r\n          do\r\n          {\r\n            dic[dicPos++] = dic[pos];\r\n            if (++pos == dicBufSize)\r\n              pos = 0;\r\n          }\r\n          while (--curLen != 0);\r\n        }\r\n      }\r\n    }\r\n  }\r\n  while (dicPos < limit && buf < bufLimit);\r\n  NORMALIZE;\r\n  p->buf = buf;\r\n  p->range = range;\r\n  p->code = code;\r\n  p->remainLen = len;\r\n  p->dicPos = dicPos;\r\n  p->processedPos = processedPos;\r\n  p->reps[0] = rep0;\r\n  p->reps[1] = rep1;\r\n  p->reps[2] = rep2;\r\n  p->reps[3] = rep3;\r\n  p->state = state;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\r\n{\r\n  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\r\n  {\r\n    Byte *dic = p->dic;\r\n    SizeT dicPos = p->dicPos;\r\n    SizeT dicBufSize = p->dicBufSize;\r\n    unsigned len = p->remainLen;\r\n    UInt32 rep0 = p->reps[0];\r\n    if (limit - dicPos < len)\r\n      len = (unsigned)(limit - dicPos);\r\n\r\n    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r\n      p->checkDicSize = p->prop.dicSize;\r\n\r\n    p->processedPos += len;\r\n    p->remainLen -= len;\r\n    while (len-- != 0)\r\n    {\r\n      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n      dicPos++;\r\n    }\r\n    p->dicPos = dicPos;\r\n  }\r\n}\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  do\r\n  {\r\n    SizeT limit2 = limit;\r\n    if (p->checkDicSize == 0)\r\n    {\r\n      UInt32 rem = p->prop.dicSize - p->processedPos;\r\n      if (limit - p->dicPos > rem)\r\n        limit2 = p->dicPos + rem;\r\n    }\r\n    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r\n    if (p->processedPos >= p->prop.dicSize)\r\n      p->checkDicSize = p->prop.dicSize;\r\n    LzmaDec_WriteRem(p, limit);\r\n  }\r\n  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r\n\r\n  if (p->remainLen > kMatchSpecLenStart)\r\n  {\r\n    p->remainLen = kMatchSpecLenStart;\r\n  }\r\n  return 0;\r\n}\r\n\r\ntypedef enum\r\n{\r\n  DUMMY_ERROR, /* unexpected end of input stream */\r\n  DUMMY_LIT,\r\n  DUMMY_MATCH,\r\n  DUMMY_REP\r\n} ELzmaDummy;\r\n\r\nstatic ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\r\n{\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n  const Byte *bufLimit = buf + inSize;\r\n  CLzmaProb *probs = p->probs;\r\n  unsigned state = p->state;\r\n  ELzmaDummy res;\r\n\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0_CHECK(prob)\r\n    {\r\n      UPDATE_0_CHECK\r\n\r\n      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\r\n\r\n      prob = probs + Literal;\r\n      if (p->checkDicSize != 0 || p->processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE *\r\n          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r\n          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        unsigned symbol = 1;\r\n        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r\n            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        unsigned symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      res = DUMMY_LIT;\r\n    }\r\n    else\r\n    {\r\n      unsigned len;\r\n      UPDATE_1_CHECK;\r\n\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0_CHECK(prob)\r\n      {\r\n        UPDATE_0_CHECK;\r\n        state = 0;\r\n        prob = probs + LenCoder;\r\n        res = DUMMY_MATCH;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1_CHECK;\r\n        res = DUMMY_REP;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0_CHECK(prob)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            NORMALIZE_CHECK;\r\n            return DUMMY_REP;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0_CHECK(prob)\r\n            {\r\n              UPDATE_0_CHECK;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1_CHECK;\r\n            }\r\n          }\r\n        }\r\n        state = kNumStates;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0_CHECK(probLen)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = 1 << kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0_CHECK(probLen)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = 1 << kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = 1 << kLenNumHighBits;\r\n          }\r\n        }\r\n        TREE_DECODE_CHECK(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        unsigned posSlot;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<\r\n            kNumPosSlotBits);\r\n        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n\r\n          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE_CHECK\r\n              range >>= 1;\r\n              code -= range & (((code - range) >> 31) - 1);\r\n              /* if (code >= range) code -= range; */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            unsigned i = 1;\r\n            do\r\n            {\r\n              GET_BIT_CHECK(prob + i, i);\r\n            }\r\n            while (--numDirectBits != 0);\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  NORMALIZE_CHECK;\r\n  return res;\r\n}\r\n\r\n\r\nstatic void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\r\n{\r\n  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\r\n  p->range = 0xFFFFFFFF;\r\n  p->needFlush = 0;\r\n}\r\n\r\nvoid LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r\n{\r\n  p->needFlush = 1;\r\n  p->remainLen = 0;\r\n  p->tempBufSize = 0;\r\n\r\n  if (initDic)\r\n  {\r\n    p->processedPos = 0;\r\n    p->checkDicSize = 0;\r\n    p->needInitState = 1;\r\n  }\r\n  if (initState)\r\n    p->needInitState = 1;\r\n}\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p)\r\n{\r\n  p->dicPos = 0;\r\n  LzmaDec_InitDicAndState(p, True, True);\r\n}\r\n\r\nstatic void LzmaDec_InitStateReal(CLzmaDec *p)\r\n{\r\n  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\r\n  UInt32 i;\r\n  CLzmaProb *probs = p->probs;\r\n  for (i = 0; i < numProbs; i++)\r\n    probs[i] = kBitModelTotal >> 1;\r\n  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;\r\n  p->state = 0;\r\n  p->needInitState = 0;\r\n}\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\r\n    ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT inSize = *srcLen;\r\n  (*srcLen) = 0;\r\n  LzmaDec_WriteRem(p, dicLimit);\r\n  \r\n  *status = LZMA_STATUS_NOT_SPECIFIED;\r\n\r\n  while (p->remainLen != kMatchSpecLenStart)\r\n  {\r\n      int checkEndMarkNow;\r\n\r\n      if (p->needFlush != 0)\r\n      {\r\n        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r\n          p->tempBuf[p->tempBufSize++] = *src++;\r\n        if (p->tempBufSize < RC_INIT_SIZE)\r\n        {\r\n          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n          return SZ_OK;\r\n        }\r\n        if (p->tempBuf[0] != 0)\r\n          return SZ_ERROR_DATA;\r\n\r\n        LzmaDec_InitRc(p, p->tempBuf);\r\n        p->tempBufSize = 0;\r\n      }\r\n\r\n      checkEndMarkNow = 0;\r\n      if (p->dicPos >= dicLimit)\r\n      {\r\n        if (p->remainLen == 0 && p->code == 0)\r\n        {\r\n          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;\r\n          return SZ_OK;\r\n        }\r\n        if (finishMode == LZMA_FINISH_ANY)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_OK;\r\n        }\r\n        if (p->remainLen != 0)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_ERROR_DATA;\r\n        }\r\n        checkEndMarkNow = 1;\r\n      }\r\n\r\n      if (p->needInitState)\r\n        LzmaDec_InitStateReal(p);\r\n  \r\n      if (p->tempBufSize == 0)\r\n      {\r\n        SizeT processed;\r\n        const Byte *bufLimit;\r\n        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            memcpy(p->tempBuf, src, inSize);\r\n            p->tempBufSize = (unsigned)inSize;\r\n            (*srcLen) += inSize;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n          bufLimit = src;\r\n        }\r\n        else\r\n          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\r\n        p->buf = src;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\r\n          return SZ_ERROR_DATA;\r\n        processed = (SizeT)(p->buf - src);\r\n        (*srcLen) += processed;\r\n        src += processed;\r\n        inSize -= processed;\r\n      }\r\n      else\r\n      {\r\n        unsigned rem = p->tempBufSize, lookAhead = 0;\r\n        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\r\n          p->tempBuf[rem++] = src[lookAhead++];\r\n        p->tempBufSize = rem;\r\n        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            (*srcLen) += lookAhead;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n        }\r\n        p->buf = p->tempBuf;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r\n          return SZ_ERROR_DATA;\r\n        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\r\n        (*srcLen) += lookAhead;\r\n        src += lookAhead;\r\n        inSize -= lookAhead;\r\n        p->tempBufSize = 0;\r\n      }\r\n  }\r\n  if (p->code == 0)\r\n    *status = LZMA_STATUS_FINISHED_WITH_MARK;\r\n  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT outSize = *destLen;\r\n  SizeT inSize = *srcLen;\r\n  *srcLen = *destLen = 0;\r\n  for (;;)\r\n  {\r\n    SizeT inSizeCur = inSize, outSizeCur, dicPos;\r\n    ELzmaFinishMode curFinishMode;\r\n    SRes res;\r\n    if (p->dicPos == p->dicBufSize)\r\n      p->dicPos = 0;\r\n    dicPos = p->dicPos;\r\n    if (outSize > p->dicBufSize - dicPos)\r\n    {\r\n      outSizeCur = p->dicBufSize;\r\n      curFinishMode = LZMA_FINISH_ANY;\r\n    }\r\n    else\r\n    {\r\n      outSizeCur = dicPos + outSize;\r\n      curFinishMode = finishMode;\r\n    }\r\n\r\n    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);\r\n    src += inSizeCur;\r\n    inSize -= inSizeCur;\r\n    *srcLen += inSizeCur;\r\n    outSizeCur = p->dicPos - dicPos;\r\n    memcpy(dest, p->dic + dicPos, outSizeCur);\r\n    dest += outSizeCur;\r\n    outSize -= outSizeCur;\r\n    *destLen += outSizeCur;\r\n    if (res != 0)\r\n      return res;\r\n    if (outSizeCur == 0 || outSize == 0)\r\n      return SZ_OK;\r\n  }\r\n}\r\n\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->probs);\r\n  p->probs = 0;\r\n}\r\n\r\nstatic void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->dic);\r\n  p->dic = 0;\r\n}\r\n\r\nvoid LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  LzmaDec_FreeProbs(p, alloc);\r\n  LzmaDec_FreeDict(p, alloc);\r\n}\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)\r\n{\r\n  UInt32 dicSize;\r\n  Byte d;\r\n  \r\n  if (size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  else\r\n    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);\r\n \r\n  if (dicSize < LZMA_DIC_MIN)\r\n    dicSize = LZMA_DIC_MIN;\r\n  p->dicSize = dicSize;\r\n\r\n  d = data[0];\r\n  if (d >= (9 * 5 * 5))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  p->lc = d % 9;\r\n  d /= 9;\r\n  p->pb = d / 5;\r\n  p->lp = d % 5;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r\n{\r\n  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r\n  if (p->probs == 0 || numProbs != p->numProbs)\r\n  {\r\n    LzmaDec_FreeProbs(p, alloc);\r\n    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r\n    p->numProbs = numProbs;\r\n    if (p->probs == 0)\r\n      return SZ_ERROR_MEM;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  SizeT dicBufSize;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  dicBufSize = propNew.dicSize;\r\n  if (p->dic == 0 || dicBufSize != p->dicBufSize)\r\n  {\r\n    LzmaDec_FreeDict(p, alloc);\r\n    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r\n    if (p->dic == 0)\r\n    {\r\n      LzmaDec_FreeProbs(p, alloc);\r\n      return SZ_ERROR_MEM;\r\n    }\r\n  }\r\n  p->dicBufSize = dicBufSize;\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc)\r\n{\r\n  CLzmaDec p;\r\n  SRes res;\r\n  SizeT inSize = *srcLen;\r\n  SizeT outSize = *destLen;\r\n  *srcLen = *destLen = 0;\r\n  if (inSize < RC_INIT_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  LzmaDec_Construct(&p);\r\n  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\r\n  if (res != 0)\r\n    return res;\r\n  p.dic = dest;\r\n  p.dicBufSize = outSize;\r\n\r\n  LzmaDec_Init(&p);\r\n  \r\n  *srcLen = inSize;\r\n  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r\n\r\n  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r\n    res = SZ_ERROR_INPUT_EOF;\r\n\r\n  (*destLen) = p.dicPos;\r\n  LzmaDec_FreeProbs(&p, alloc);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaDec.h",
    "content": "/* LzmaDec.h -- LZMA Decoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMADEC_H\r\n#define __LZMADEC_H\r\n\r\n#include \"Types.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* _LZMA_PROB32 can increase the speed on some CPUs,\r\n   but memory usage for CLzmaDec::probs will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n\r\n/* ---------- LZMA Properties ---------- */\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaProps\r\n{\r\n  unsigned lc, lp, pb;\r\n  UInt32 dicSize;\r\n} CLzmaProps;\r\n\r\n/* LzmaProps_Decode - decodes properties\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);\r\n\r\n\r\n/* ---------- LZMA Decoder state ---------- */\r\n\r\n/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.\r\n   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */\r\n\r\n#define LZMA_REQUIRED_INPUT_MAX 20\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProps prop;\r\n  CLzmaProb *probs;\r\n  Byte *dic;\r\n  const Byte *buf;\r\n  UInt32 range, code;\r\n  SizeT dicPos;\r\n  SizeT dicBufSize;\r\n  UInt32 processedPos;\r\n  UInt32 checkDicSize;\r\n  unsigned state;\r\n  UInt32 reps[4];\r\n  unsigned remainLen;\r\n  int needFlush;\r\n  int needInitState;\r\n  UInt32 numProbs;\r\n  unsigned tempBufSize;\r\n  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];\r\n} CLzmaDec;\r\n\r\n#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p);\r\n\r\n/* There are two types of LZMA streams:\r\n     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.\r\n     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_FINISH_ANY,   /* finish at any point */\r\n  LZMA_FINISH_END    /* block must be finished at the end */\r\n} ELzmaFinishMode;\r\n\r\n/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!\r\n\r\n   You must use LZMA_FINISH_END, when you know that current output buffer\r\n   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.\r\n\r\n   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,\r\n   and output value of destLen will be less than output buffer size limit.\r\n   You can check status result also.\r\n\r\n   You can use multiple checks to test data integrity after full decompression:\r\n     1) Check Result and \"status\" variable.\r\n     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.\r\n        You must use correct finish mode in that case. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */\r\n  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\r\n  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */\r\n  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */\r\n  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */\r\n} ELzmaStatus;\r\n\r\n/* ELzmaStatus is used only as output value for function call */\r\n\r\n\r\n/* ---------- Interfaces ---------- */\r\n\r\n/* There are 3 levels of interfaces:\r\n     1) Dictionary Interface\r\n     2) Buffer Interface\r\n     3) One Call Interface\r\n   You can select any of these interfaces, but don't mix functions from different\r\n   groups for same object. */\r\n\r\n\r\n/* There are two variants to allocate state for Dictionary Interface:\r\n     1) LzmaDec_Allocate / LzmaDec_Free\r\n     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs\r\n   You can use variant 2, if you set dictionary buffer manually.\r\n   For Buffer Interface you must always use variant 1.\r\n\r\nLzmaDec_Allocate* can return:\r\n  SZ_OK\r\n  SZ_ERROR_MEM         - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n   \r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);\r\n\r\n/* ---------- Dictionary Interface ---------- */\r\n\r\n/* You can use it, if you want to eliminate the overhead for data copying from\r\n   dictionary to some other external buffer.\r\n   You must work with CLzmaDec variables directly in this interface.\r\n\r\n   STEPS:\r\n     LzmaDec_Constr()\r\n     LzmaDec_Allocate()\r\n     for (each new stream)\r\n     {\r\n       LzmaDec_Init()\r\n       while (it needs more decompression)\r\n       {\r\n         LzmaDec_DecodeToDic()\r\n         use data from CLzmaDec::dic and update CLzmaDec::dicPos\r\n       }\r\n     }\r\n     LzmaDec_Free()\r\n*/\r\n\r\n/* LzmaDec_DecodeToDic\r\n   \r\n   The decoding to internal dictionary buffer (CLzmaDec::dic).\r\n   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (dicLimit).\r\n  LZMA_FINISH_ANY - Decode just dicLimit bytes.\r\n  LZMA_FINISH_END - Stream must be finished after dicLimit.\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_NEEDS_MORE_INPUT\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- Buffer Interface ---------- */\r\n\r\n/* It's zlib-like interface.\r\n   See LzmaDec_DecodeToDic description for information about STEPS and return results,\r\n   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need\r\n   to work with CLzmaDec variables manually.\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n*/\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaDecode\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n  SZ_ERROR_MEM  - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n*/\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaEnc.c",
    "content": "/* LzmaEnc.c -- LZMA Encoder\r\n2009-02-02 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n/* #define SHOW_STAT */\r\n/* #define SHOW_STAT2 */\r\n\r\n#if defined(SHOW_STAT) || defined(SHOW_STAT2)\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"LzmaEnc.h\"\r\n\r\n#include \"LzFind.h\"\r\n#ifdef COMPRESS_MF_MT\r\n#include \"LzFindMt.h\"\r\n#endif\r\n\r\n#ifdef SHOW_STAT\r\nstatic int ttt = 0;\r\n#endif\r\n\r\n#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)\r\n\r\n#define kBlockSize (9 << 10)\r\n#define kUnpackBlockSize (1 << 18)\r\n#define kMatchArraySize (1 << 21)\r\n#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)\r\n\r\n#define kNumMaxDirectBits (31)\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n#define kProbInitValue (kBitModelTotal >> 1)\r\n\r\n#define kNumMoveReducingBits 4\r\n#define kNumBitPriceShiftBits 4\r\n#define kBitPrice (1 << kNumBitPriceShiftBits)\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p)\r\n{\r\n  p->level = 5;\r\n  p->dictSize = p->mc = 0;\r\n  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\r\n  p->writeEndMark = 0;\r\n}\r\n\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p)\r\n{\r\n  int level = p->level;\r\n  if (level < 0) level = 5;\r\n  p->level = level;\r\n  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));\r\n  if (p->lc < 0) p->lc = 3;\r\n  if (p->lp < 0) p->lp = 0;\r\n  if (p->pb < 0) p->pb = 2;\r\n  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);\r\n  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);\r\n  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);\r\n  if (p->numHashBytes < 0) p->numHashBytes = 4;\r\n  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\r\n  if (p->numThreads < 0)\r\n    p->numThreads =\r\n      #ifdef COMPRESS_MF_MT\r\n      ((p->btMode && p->algo) ? 2 : 1);\r\n      #else\r\n      1;\r\n      #endif\r\n}\r\n\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n  return props.dictSize;\r\n}\r\n\r\n/* #define LZMA_LOG_BSR */\r\n/* Define it for Intel's CPU */\r\n\r\n\r\n#ifdef LZMA_LOG_BSR\r\n\r\n#define kDicLogSizeMaxCompress 30\r\n\r\n#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }\r\n\r\nUInt32 GetPosSlot1(UInt32 pos)\r\n{\r\n  UInt32 res;\r\n  BSR2_RET(pos, res);\r\n  return res;\r\n}\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }\r\n\r\n#else\r\n\r\n#define kNumLogBits (9 + (int)sizeof(size_t) / 2)\r\n#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)\r\n\r\nvoid LzmaEnc_FastPosInit(Byte *g_FastPos)\r\n{\r\n  int c = 2, slotFast;\r\n  g_FastPos[0] = 0;\r\n  g_FastPos[1] = 1;\r\n  \r\n  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)\r\n  {\r\n    UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n    UInt32 j;\r\n    for (j = 0; j < k; j++, c++)\r\n      g_FastPos[c] = (Byte)slotFast;\r\n  }\r\n}\r\n\r\n#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \\\r\n  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \\\r\n  res = p->g_FastPos[pos >> i] + (i * 2); }\r\n/*\r\n#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \\\r\n  p->g_FastPos[pos >> 6] + 12 : \\\r\n  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }\r\n*/\r\n\r\n#define GetPosSlot1(pos) p->g_FastPos[pos]\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }\r\n\r\n#endif\r\n\r\n\r\n#define LZMA_NUM_REPS 4\r\n\r\ntypedef unsigned CState;\r\n\r\ntypedef struct _COptimal\r\n{\r\n  UInt32 price;\r\n\r\n  CState state;\r\n  int prev1IsChar;\r\n  int prev2;\r\n\r\n  UInt32 posPrev2;\r\n  UInt32 backPrev2;\r\n\r\n  UInt32 posPrev;\r\n  UInt32 backPrev;\r\n  UInt32 backs[LZMA_NUM_REPS];\r\n} COptimal;\r\n\r\n#define kNumOpts (1 << 12)\r\n\r\n#define kNumLenToPosStates 4\r\n#define kNumPosSlotBits 6\r\n#define kDicLogSizeMin 0\r\n#define kDicLogSizeMax 32\r\n#define kDistTableSizeMax (kDicLogSizeMax * 2)\r\n\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n#define kAlignMask (kAlignTableSize - 1)\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)\r\n\r\n#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n#define LZMA_PB_MAX 4\r\n#define LZMA_LC_MAX 8\r\n#define LZMA_LP_MAX 4\r\n\r\n#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)\r\n\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define LZMA_MATCH_LEN_MIN 2\r\n#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)\r\n\r\n#define kNumStates 12\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb choice;\r\n  CLzmaProb choice2;\r\n  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];\r\n  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];\r\n  CLzmaProb high[kLenNumHighSymbols];\r\n} CLenEnc;\r\n\r\ntypedef struct\r\n{\r\n  CLenEnc p;\r\n  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\r\n  UInt32 tableSize;\r\n  UInt32 counters[LZMA_NUM_PB_STATES_MAX];\r\n} CLenPriceEnc;\r\n\r\ntypedef struct _CRangeEnc\r\n{\r\n  UInt32 range;\r\n  Byte cache;\r\n  UInt64 low;\r\n  UInt64 cacheSize;\r\n  Byte *buf;\r\n  Byte *bufLim;\r\n  Byte *bufBase;\r\n  ISeqOutStream *outStream;\r\n  UInt64 processed;\r\n  SRes res;\r\n} CRangeEnc;\r\n\r\ntypedef struct _CSeqInStreamBuf\r\n{\r\n  ISeqInStream funcTable;\r\n  const Byte *data;\r\n  SizeT rem;\r\n} CSeqInStreamBuf;\r\n\r\nstatic SRes MyRead(void *pp, void *data, size_t *size)\r\n{\r\n  size_t curSize = *size;\r\n  CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;\r\n  if (p->rem < curSize)\r\n    curSize = p->rem;\r\n  memcpy(data, p->data, curSize);\r\n  p->rem -= curSize;\r\n  p->data += curSize;\r\n  *size = curSize;\r\n  return SZ_OK;\r\n}\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n} CSaveState;\r\n\r\ntypedef struct _CLzmaEnc\r\n{\r\n  IMatchFinder matchFinder;\r\n  void *matchFinderObj;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Bool mtMode;\r\n  CMatchFinderMt matchFinderMt;\r\n  #endif\r\n\r\n  CMatchFinder matchFinderBase;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte pad[128];\r\n  #endif\r\n  \r\n  UInt32 optimumEndIndex;\r\n  UInt32 optimumCurrentIndex;\r\n\r\n  UInt32 longestMatchLength;\r\n  UInt32 numPairs;\r\n  UInt32 numAvail;\r\n  COptimal opt[kNumOpts];\r\n  \r\n  #ifndef LZMA_LOG_BSR\r\n  Byte g_FastPos[1 << kNumLogBits];\r\n  #endif\r\n\r\n  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];\r\n  UInt32 numFastBytes;\r\n  UInt32 additionalOffset;\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n\r\n  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n  UInt32 alignPrices[kAlignTableSize];\r\n  UInt32 alignPriceCount;\r\n\r\n  UInt32 distTableSize;\r\n\r\n  unsigned lc, lp, pb;\r\n  unsigned lpMask, pbMask;\r\n\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  unsigned lclp;\r\n\r\n  Bool fastMode;\r\n  \r\n  CRangeEnc rc;\r\n\r\n  Bool writeEndMark;\r\n  UInt64 nowPos64;\r\n  UInt32 matchPriceCount;\r\n  Bool finished;\r\n  Bool multiThread;\r\n\r\n  SRes result;\r\n  UInt32 dictSize;\r\n  UInt32 matchFinderCycles;\r\n\r\n  ISeqInStream *inStream;\r\n  CSeqInStreamBuf seqBufInStream;\r\n\r\n  CSaveState saveState;\r\n} CLzmaEnc;\r\n\r\nvoid LzmaEnc_SaveState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CSaveState *dest = &p->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nvoid LzmaEnc_RestoreState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *dest = (CLzmaEnc *)pp;\r\n  const CSaveState *p = &dest->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n\r\n  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||\r\n      props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))\r\n    return SZ_ERROR_PARAM;\r\n  p->dictSize = props.dictSize;\r\n  p->matchFinderCycles = props.mc;\r\n  {\r\n    unsigned fb = props.fb;\r\n    if (fb < 5)\r\n      fb = 5;\r\n    if (fb > LZMA_MATCH_LEN_MAX)\r\n      fb = LZMA_MATCH_LEN_MAX;\r\n    p->numFastBytes = fb;\r\n  }\r\n  p->lc = props.lc;\r\n  p->lp = props.lp;\r\n  p->pb = props.pb;\r\n  p->fastMode = (props.algo == 0);\r\n  p->matchFinderBase.btMode = props.btMode;\r\n  {\r\n    UInt32 numHashBytes = 4;\r\n    if (props.btMode)\r\n    {\r\n      if (props.numHashBytes < 2)\r\n        numHashBytes = 2;\r\n      else if (props.numHashBytes < 4)\r\n        numHashBytes = props.numHashBytes;\r\n    }\r\n    p->matchFinderBase.numHashBytes = numHashBytes;\r\n  }\r\n\r\n  p->matchFinderBase.cutValue = props.mc;\r\n\r\n  p->writeEndMark = props.writeEndMark;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  /*\r\n  if (newMultiThread != _multiThread)\r\n  {\r\n    ReleaseMatchFinder();\r\n    _multiThread = newMultiThread;\r\n  }\r\n  */\r\n  p->multiThread = (props.numThreads > 1);\r\n  #endif\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nstatic const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nstatic const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nstatic const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n#define IsCharState(s) ((s) < 7)\r\n\r\n#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)\r\n\r\n#define kInfinityPrice (1 << 30)\r\n\r\nstatic void RangeEnc_Construct(CRangeEnc *p)\r\n{\r\n  p->outStream = 0;\r\n  p->bufBase = 0;\r\n}\r\n\r\n#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)\r\n\r\n#define RC_BUF_SIZE (1 << 16)\r\nstatic int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  if (p->bufBase == 0)\r\n  {\r\n    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);\r\n    if (p->bufBase == 0)\r\n      return 0;\r\n    p->bufLim = p->bufBase + RC_BUF_SIZE;\r\n  }\r\n  return 1;\r\n}\r\n\r\nstatic void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->bufBase);\r\n  p->bufBase = 0;\r\n}\r\n\r\nstatic void RangeEnc_Init(CRangeEnc *p)\r\n{\r\n  /* Stream.Init(); */\r\n  p->low = 0;\r\n  p->range = 0xFFFFFFFF;\r\n  p->cacheSize = 1;\r\n  p->cache = 0;\r\n\r\n  p->buf = p->bufBase;\r\n\r\n  p->processed = 0;\r\n  p->res = SZ_OK;\r\n}\r\n\r\nstatic void RangeEnc_FlushStream(CRangeEnc *p)\r\n{\r\n  size_t num;\r\n  if (p->res != SZ_OK)\r\n    return;\r\n  num = p->buf - p->bufBase;\r\n  if (num != p->outStream->Write(p->outStream, p->bufBase, num))\r\n    p->res = SZ_ERROR_WRITE;\r\n  p->processed += num;\r\n  p->buf = p->bufBase;\r\n}\r\n\r\nstatic void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)\r\n{\r\n  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)\r\n  {\r\n    Byte temp = p->cache;\r\n    do\r\n    {\r\n      Byte *buf = p->buf;\r\n      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));\r\n      p->buf = buf;\r\n      if (buf == p->bufLim)\r\n        RangeEnc_FlushStream(p);\r\n      temp = 0xFF;\r\n    }\r\n    while (--p->cacheSize != 0);\r\n    p->cache = (Byte)((UInt32)p->low >> 24);\r\n  }\r\n  p->cacheSize++;\r\n  p->low = (UInt32)p->low << 8;\r\n}\r\n\r\nstatic void RangeEnc_FlushData(CRangeEnc *p)\r\n{\r\n  int i;\r\n  for (i = 0; i < 5; i++)\r\n    RangeEnc_ShiftLow(p);\r\n}\r\n\r\nstatic void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)\r\n{\r\n  do\r\n  {\r\n    p->range >>= 1;\r\n    p->low += p->range & (0 - ((value >> --numBits) & 1));\r\n    if (p->range < kTopValue)\r\n    {\r\n      p->range <<= 8;\r\n      RangeEnc_ShiftLow(p);\r\n    }\r\n  }\r\n  while (numBits != 0);\r\n}\r\n\r\nstatic void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)\r\n{\r\n  UInt32 ttt = *prob;\r\n  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;\r\n  if (symbol == 0)\r\n  {\r\n    p->range = newBound;\r\n    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;\r\n  }\r\n  else\r\n  {\r\n    p->low += newBound;\r\n    p->range -= newBound;\r\n    ttt -= ttt >> kNumMoveBits;\r\n  }\r\n  *prob = (CLzmaProb)ttt;\r\n  if (p->range < kTopValue)\r\n  {\r\n    p->range <<= 8;\r\n    RangeEnc_ShiftLow(p);\r\n  }\r\n}\r\n\r\nstatic void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)\r\n{\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nstatic void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)\r\n{\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nvoid LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\r\n{\r\n  UInt32 i;\r\n  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))\r\n  {\r\n    const int kCyclesBits = kNumBitPriceShiftBits;\r\n    UInt32 w = i;\r\n    UInt32 bitCount = 0;\r\n    int j;\r\n    for (j = 0; j < kCyclesBits; j++)\r\n    {\r\n      w = w * w;\r\n      bitCount <<= 1;\r\n      while (w >= ((UInt32)1 << 16))\r\n      {\r\n        w >>= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);\r\n  }\r\n}\r\n\r\n\r\n#define GET_PRICE(prob, symbol) \\\r\n  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICEa(prob, symbol) \\\r\n  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\n#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\nstatic UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\nstatic UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\n\r\nstatic void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0;)\r\n  {\r\n    UInt32 bit;\r\n    i--;\r\n    bit = (symbol >> i) & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n}\r\n\r\nstatic void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = 0; i < numBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= (1 << numBitLevels);\r\n  while (symbol != 1)\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);\r\n    symbol >>= 1;\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += GET_PRICEa(probs[m], bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\n\r\nstatic void LenEnc_Init(CLenEnc *p)\r\n{\r\n  unsigned i;\r\n  p->choice = p->choice2 = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)\r\n    p->low[i] = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)\r\n    p->mid[i] = kProbInitValue;\r\n  for (i = 0; i < kLenNumHighSymbols; i++)\r\n    p->high[i] = kProbInitValue;\r\n}\r\n\r\nstatic void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)\r\n{\r\n  if (symbol < kLenNumLowSymbols)\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 0);\r\n    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);\r\n  }\r\n  else\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 1);\r\n    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 0);\r\n      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 1);\r\n      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)\r\n{\r\n  UInt32 a0 = GET_PRICE_0a(p->choice);\r\n  UInt32 a1 = GET_PRICE_1a(p->choice);\r\n  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);\r\n  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kLenNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);\r\n  }\r\n  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);\r\n}\r\n\r\nstatic void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);\r\n  p->counters[posState] = p->tableSize;\r\n}\r\n\r\nstatic void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)\r\n{\r\n  UInt32 posState;\r\n  for (posState = 0; posState < numPosStates; posState++)\r\n    LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\nstatic void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_Encode(&p->p, rc, symbol, posState);\r\n  if (updatePrice)\r\n    if (--p->counters[posState] == 0)\r\n      LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\n\r\n\r\n\r\nstatic void MovePos(CLzmaEnc *p, UInt32 num)\r\n{\r\n  #ifdef SHOW_STAT\r\n  ttt += num;\r\n  printf(\"\\n MovePos %d\", num);\r\n  #endif\r\n  if (num != 0)\r\n  {\r\n    p->additionalOffset += num;\r\n    p->matchFinder.Skip(p->matchFinderObj, num);\r\n  }\r\n}\r\n\r\nstatic UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)\r\n{\r\n  UInt32 lenRes = 0, numPairs;\r\n  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);\r\n  #ifdef SHOW_STAT\r\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numPairs / 2);\r\n  ttt++;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < numPairs; i += 2)\r\n      printf(\"%2d %6d   | \", p->matches[i], p->matches[i + 1]);\r\n  }\r\n  #endif\r\n  if (numPairs > 0)\r\n  {\r\n    lenRes = p->matches[numPairs - 2];\r\n    if (lenRes == p->numFastBytes)\r\n    {\r\n      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n      UInt32 distance = p->matches[numPairs - 1] + 1;\r\n      UInt32 numAvail = p->numAvail;\r\n      if (numAvail > LZMA_MATCH_LEN_MAX)\r\n        numAvail = LZMA_MATCH_LEN_MAX;\r\n      {\r\n        const Byte *pby2 = pby - distance;\r\n        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r\n      }\r\n    }\r\n  }\r\n  p->additionalOffset++;\r\n  *numDistancePairsRes = numPairs;\r\n  return lenRes;\r\n}\r\n\r\n\r\n#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;\r\n#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;\r\n#define IsShortRep(p) ((p)->backPrev == 0)\r\n\r\nstatic UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)\r\n{\r\n  return\r\n    GET_PRICE_0(p->isRepG0[state]) +\r\n    GET_PRICE_0(p->isRep0Long[state][posState]);\r\n}\r\n\r\nstatic UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)\r\n{\r\n  UInt32 price;\r\n  if (repIndex == 0)\r\n  {\r\n    price = GET_PRICE_0(p->isRepG0[state]);\r\n    price += GET_PRICE_1(p->isRep0Long[state][posState]);\r\n  }\r\n  else\r\n  {\r\n    price = GET_PRICE_1(p->isRepG0[state]);\r\n    if (repIndex == 1)\r\n      price += GET_PRICE_0(p->isRepG1[state]);\r\n    else\r\n    {\r\n      price += GET_PRICE_1(p->isRepG1[state]);\r\n      price += GET_PRICE(p->isRepG2[state], repIndex - 2);\r\n    }\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)\r\n{\r\n  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +\r\n    GetPureRepPrice(p, repIndex, state, posState);\r\n}\r\n\r\nstatic UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)\r\n{\r\n  UInt32 posMem = p->opt[cur].posPrev;\r\n  UInt32 backMem = p->opt[cur].backPrev;\r\n  p->optimumEndIndex = cur;\r\n  do\r\n  {\r\n    if (p->opt[cur].prev1IsChar)\r\n    {\r\n      MakeAsChar(&p->opt[posMem])\r\n      p->opt[posMem].posPrev = posMem - 1;\r\n      if (p->opt[cur].prev2)\r\n      {\r\n        p->opt[posMem - 1].prev1IsChar = False;\r\n        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;\r\n        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;\r\n      }\r\n    }\r\n    {\r\n      UInt32 posPrev = posMem;\r\n      UInt32 backCur = backMem;\r\n      \r\n      backMem = p->opt[posPrev].backPrev;\r\n      posMem = p->opt[posPrev].posPrev;\r\n      \r\n      p->opt[posPrev].backPrev = backCur;\r\n      p->opt[posPrev].posPrev = cur;\r\n      cur = posPrev;\r\n    }\r\n  }\r\n  while (cur != 0);\r\n  *backRes = p->opt[0].backPrev;\r\n  p->optimumCurrentIndex  = p->opt[0].posPrev;\r\n  return p->optimumCurrentIndex;\r\n}\r\n\r\n#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)\r\n\r\nstatic UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;\r\n  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\r\n  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];\r\n  UInt32 *matches;\r\n  const Byte *data;\r\n  Byte curByte, matchByte;\r\n  if (p->optimumEndIndex != p->optimumCurrentIndex)\r\n  {\r\n    const COptimal *opt = &p->opt[p->optimumCurrentIndex];\r\n    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;\r\n    *backRes = opt->backPrev;\r\n    p->optimumCurrentIndex = opt->posPrev;\r\n    return lenRes;\r\n  }\r\n  p->optimumCurrentIndex = p->optimumEndIndex = 0;\r\n  \r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  if (numAvail < 2)\r\n  {\r\n    *backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  repMaxIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 lenTest;\r\n    const Byte *data2;\r\n    reps[i] = p->reps[i];\r\n    data2 = data - (reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if (repLens[repMaxIndex] >= p->numFastBytes)\r\n  {\r\n    UInt32 lenRes;\r\n    *backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    MovePos(p, lenRes - 1);\r\n    return lenRes;\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n  curByte = *data;\r\n  matchByte = *(data - (reps[0] + 1));\r\n\r\n  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    *backRes = (UInt32)-1;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[0].state = (CState)p->state;\r\n\r\n  posState = (position & p->pbMask);\r\n\r\n  {\r\n    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +\r\n        (!IsCharState(p->state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n  }\r\n\r\n  MakeAsChar(&p->opt[1]);\r\n\r\n  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);\r\n  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);\r\n\r\n  if (matchByte == curByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);\r\n    if (shortRepPrice < p->opt[1].price)\r\n    {\r\n      p->opt[1].price = shortRepPrice;\r\n      MakeAsShortRep(&p->opt[1]);\r\n    }\r\n  }\r\n  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);\r\n\r\n  if (lenEnd < 2)\r\n  {\r\n    *backRes = p->opt[1].backPrev;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[1].posPrev = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n    p->opt[0].backs[i] = reps[i];\r\n\r\n  len = lenEnd;\r\n  do\r\n    p->opt[len--].price = kInfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    UInt32 price;\r\n    if (repLen < 2)\r\n      continue;\r\n    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];\r\n      COptimal *opt = &p->opt[repLen];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = i;\r\n        opt->prev1IsChar = False;\r\n      }\r\n    }\r\n    while (--repLen >= 2);\r\n  }\r\n\r\n  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= mainLen)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matches[offs])\r\n      offs += 2;\r\n    for (; ; len++)\r\n    {\r\n      COptimal *opt;\r\n      UInt32 distance = matches[offs + 1];\r\n\r\n      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];\r\n      UInt32 lenToPosState = GetLenToPosState(len);\r\n      if (distance < kNumFullDistances)\r\n        curAndLenPrice += p->distancesPrices[lenToPosState][distance];\r\n      else\r\n      {\r\n        UInt32 slot;\r\n        GetPosSlot2(distance, slot);\r\n        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];\r\n      }\r\n      opt = &p->opt[len];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = distance + LZMA_NUM_REPS;\r\n        opt->prev1IsChar = False;\r\n      }\r\n      if (len == matches[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numPairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  cur = 0;\r\n\r\n    #ifdef SHOW_STAT2\r\n    if (position >= 0)\r\n    {\r\n      unsigned i;\r\n      printf(\"\\n pos = %4X\", position);\r\n      for (i = cur; i <= lenEnd; i++)\r\n      printf(\"\\nprice[%4X] = %d\", position - cur + i, p->opt[i].price);\r\n    }\r\n    #endif\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;\r\n    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;\r\n    Bool nextIsChar;\r\n    Byte curByte, matchByte;\r\n    const Byte *data;\r\n    COptimal *curOpt;\r\n    COptimal *nextOpt;\r\n\r\n    cur++;\r\n    if (cur == lenEnd)\r\n      return Backward(p, backRes, cur);\r\n\r\n    newLen = ReadMatchDistances(p, &numPairs);\r\n    if (newLen >= p->numFastBytes)\r\n    {\r\n      p->numPairs = numPairs;\r\n      p->longestMatchLength = newLen;\r\n      return Backward(p, backRes, cur);\r\n    }\r\n    position++;\r\n    curOpt = &p->opt[cur];\r\n    posPrev = curOpt->posPrev;\r\n    if (curOpt->prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOpt->prev2)\r\n      {\r\n        state = p->opt[curOpt->posPrev2].state;\r\n        if (curOpt->backPrev2 < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      else\r\n        state = p->opt[posPrev].state;\r\n      state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n      state = p->opt[posPrev].state;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (IsShortRep(curOpt))\r\n        state = kShortRepNextStates[state];\r\n      else\r\n        state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      const COptimal *prevOpt;\r\n      if (curOpt->prev1IsChar && curOpt->prev2)\r\n      {\r\n        posPrev = curOpt->posPrev2;\r\n        pos = curOpt->backPrev2;\r\n        state = kRepNextStates[state];\r\n      }\r\n      else\r\n      {\r\n        pos = curOpt->backPrev;\r\n        if (pos < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      prevOpt = &p->opt[posPrev];\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        UInt32 i;\r\n        reps[0] = prevOpt->backs[pos];\r\n        for (i = 1; i <= pos; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n        for (; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i];\r\n      }\r\n      else\r\n      {\r\n        UInt32 i;\r\n        reps[0] = (pos - LZMA_NUM_REPS);\r\n        for (i = 1; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n      }\r\n    }\r\n    curOpt->state = (CState)state;\r\n\r\n    curOpt->backs[0] = reps[0];\r\n    curOpt->backs[1] = reps[1];\r\n    curOpt->backs[2] = reps[2];\r\n    curOpt->backs[3] = reps[3];\r\n\r\n    curPrice = curOpt->price;\r\n    nextIsChar = False;\r\n    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n    curByte = *data;\r\n    matchByte = *(data - (reps[0] + 1));\r\n\r\n    posState = (position & p->pbMask);\r\n\r\n    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);\r\n    {\r\n      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n      curAnd1Price +=\r\n        (!IsCharState(state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n    }\r\n\r\n    nextOpt = &p->opt[cur + 1];\r\n\r\n    if (curAnd1Price < nextOpt->price)\r\n    {\r\n      nextOpt->price = curAnd1Price;\r\n      nextOpt->posPrev = cur;\r\n      MakeAsChar(nextOpt);\r\n      nextIsChar = True;\r\n    }\r\n\r\n    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);\r\n    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);\r\n    \r\n    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);\r\n      if (shortRepPrice <= nextOpt->price)\r\n      {\r\n        nextOpt->price = shortRepPrice;\r\n        nextOpt->posPrev = cur;\r\n        MakeAsShortRep(nextOpt);\r\n        nextIsChar = True;\r\n      }\r\n    }\r\n    numAvailFull = p->numAvail;\r\n    {\r\n      UInt32 temp = kNumOpts - 1 - cur;\r\n      if (temp < numAvailFull)\r\n        numAvailFull = temp;\r\n    }\r\n\r\n    if (numAvailFull < 2)\r\n      continue;\r\n    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);\r\n\r\n    if (!nextIsChar && matchByte != curByte) /* speed optimization */\r\n    {\r\n      /* try Literal + rep0 */\r\n      UInt32 temp;\r\n      UInt32 lenTest2;\r\n      const Byte *data2 = data - (reps[0] + 1);\r\n      UInt32 limit = p->numFastBytes + 1;\r\n      if (limit > numAvailFull)\r\n        limit = numAvailFull;\r\n\r\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r\n      lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        UInt32 state2 = kLiteralNextStates[state];\r\n        UInt32 posStateNext = (position + 1) & p->pbMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price +\r\n            GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n            GET_PRICE_1(p->isRep[state2]);\r\n        /* for (; lenTest2 >= 2; lenTest2--) */\r\n        {\r\n          UInt32 curAndLenPrice;\r\n          COptimal *opt;\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while (lenEnd < offset)\r\n            p->opt[++lenEnd].price = kInfinityPrice;\r\n          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n          opt = &p->opt[offset];\r\n          if (curAndLenPrice < opt->price)\r\n          {\r\n            opt->price = curAndLenPrice;\r\n            opt->posPrev = cur + 1;\r\n            opt->backPrev = 0;\r\n            opt->prev1IsChar = True;\r\n            opt->prev2 = False;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    startLen = 2; /* speed optimization */\r\n    {\r\n    UInt32 repIndex;\r\n    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)\r\n    {\r\n      UInt32 lenTest;\r\n      UInt32 lenTestTemp;\r\n      UInt32 price;\r\n      const Byte *data2 = data - (reps[repIndex] + 1);\r\n      if (data[0] != data2[0] || data[1] != data2[1])\r\n        continue;\r\n      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n      while (lenEnd < cur + lenTest)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n      lenTestTemp = lenTest;\r\n      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];\r\n        COptimal *opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = repIndex;\r\n          opt->prev1IsChar = False;\r\n        }\r\n      }\r\n      while (--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      /* if (_maxMode) */\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kRepNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice =\r\n                price + p->repLenEnc.prices[posState][lenTest - 2] +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (position + lenTest + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n    }\r\n    }\r\n    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */\r\n    if (newLen > numAvail)\r\n    {\r\n      newLen = numAvail;\r\n      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);\r\n      matches[numPairs] = newLen;\r\n      numPairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\r\n      UInt32 offs, curBack, posSlot;\r\n      UInt32 lenTest;\r\n      while (lenEnd < cur + newLen)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n\r\n      offs = 0;\r\n      while (startLen > matches[offs])\r\n        offs += 2;\r\n      curBack = matches[offs + 1];\r\n      GetPosSlot2(curBack, posSlot);\r\n      for (lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        COptimal *opt;\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];\r\n        \r\n        opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = curBack + LZMA_NUM_REPS;\r\n          opt->prev1IsChar = False;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matches[offs])\r\n        {\r\n          /* Try Match + Literal + Rep0 */\r\n          const Byte *data2 = data - (curBack + 1);\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kMatchNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (posStateNext + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = curBack + LZMA_NUM_REPS;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numPairs)\r\n            break;\r\n          curBack = matches[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            GetPosSlot2(curBack, posSlot);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))\r\n\r\nstatic UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;\r\n  const Byte *data;\r\n  const UInt32 *matches;\r\n\r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  *backRes = (UInt32)-1;\r\n  if (numAvail < 2)\r\n    return 1;\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n\r\n  repLen = repIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    for (len = 2; len < numAvail && data[len] == data2[len]; len++);\r\n    if (len >= p->numFastBytes)\r\n    {\r\n      *backRes = i;\r\n      MovePos(p, len - 1);\r\n      return len;\r\n    }\r\n    if (len > repLen)\r\n    {\r\n      repIndex = i;\r\n      repLen = len;\r\n    }\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n\r\n  mainDist = 0; /* for GCC */\r\n  if (mainLen >= 2)\r\n  {\r\n    mainDist = matches[numPairs - 1];\r\n    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matches[numPairs - 3], mainDist))\r\n        break;\r\n      numPairs -= 2;\r\n      mainLen = matches[numPairs - 2];\r\n      mainDist = matches[numPairs - 1];\r\n    }\r\n    if (mainLen == 2 && mainDist >= 0x80)\r\n      mainLen = 1;\r\n  }\r\n\r\n  if (repLen >= 2 && (\r\n        (repLen + 1 >= mainLen) ||\r\n        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||\r\n        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))\r\n  {\r\n    *backRes = repIndex;\r\n    MovePos(p, repLen - 1);\r\n    return repLen;\r\n  }\r\n  \r\n  if (mainLen < 2 || numAvail <= 2)\r\n    return 1;\r\n\r\n  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);\r\n  if (p->longestMatchLength >= 2)\r\n  {\r\n    UInt32 newDistance = matches[p->numPairs - 1];\r\n    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||\r\n        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||\r\n        (p->longestMatchLength > mainLen + 1) ||\r\n        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))\r\n      return 1;\r\n  }\r\n  \r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len, limit;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    limit = mainLen - 1;\r\n    for (len = 2; len < limit && data[len] == data2[len]; len++);\r\n    if (len >= limit)\r\n      return 1;\r\n  }\r\n  *backRes = mainDist + LZMA_NUM_REPS;\r\n  MovePos(p, mainLen - 2);\r\n  return mainLen;\r\n}\r\n\r\nstatic void WriteEndMarker(CLzmaEnc *p, UInt32 posState)\r\n{\r\n  UInt32 len;\r\n  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n  p->state = kMatchNextStates[p->state];\r\n  len = LZMA_MATCH_LEN_MIN;\r\n  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);\r\n  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);\r\n  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);\r\n}\r\n\r\nstatic SRes CheckErrors(CLzmaEnc *p)\r\n{\r\n  if (p->result != SZ_OK)\r\n    return p->result;\r\n  if (p->rc.res != SZ_OK)\r\n    p->result = SZ_ERROR_WRITE;\r\n  if (p->matchFinderBase.result != SZ_OK)\r\n    p->result = SZ_ERROR_READ;\r\n  if (p->result != SZ_OK)\r\n    p->finished = True;\r\n  return p->result;\r\n}\r\n\r\nstatic SRes Flush(CLzmaEnc *p, UInt32 nowPos)\r\n{\r\n  /* ReleaseMFStream(); */\r\n  p->finished = True;\r\n  if (p->writeEndMark)\r\n    WriteEndMarker(p, nowPos & p->pbMask);\r\n  RangeEnc_FlushData(&p->rc);\r\n  RangeEnc_FlushStream(&p->rc);\r\n  return CheckErrors(p);\r\n}\r\n\r\nstatic void FillAlignPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < kAlignTableSize; i++)\r\n    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);\r\n  p->alignPriceCount = 0;\r\n}\r\n\r\nstatic void FillDistancesPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  UInt32 i, lenToPosState;\r\n  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  {\r\n    UInt32 posSlot = GetPosSlot1(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);\r\n  }\r\n\r\n  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n    UInt32 posSlot;\r\n    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);\r\n    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);\r\n\r\n    {\r\n      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];\r\n      UInt32 i;\r\n      for (i = 0; i < kStartPosModelIndex; i++)\r\n        distancesPrices[i] = posSlotPrices[i];\r\n      for (; i < kNumFullDistances; i++)\r\n        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];\r\n    }\r\n  }\r\n  p->matchPriceCount = 0;\r\n}\r\n\r\nvoid LzmaEnc_Construct(CLzmaEnc *p)\r\n{\r\n  RangeEnc_Construct(&p->rc);\r\n  MatchFinder_Construct(&p->matchFinderBase);\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Construct(&p->matchFinderMt);\r\n  p->matchFinderMt.MatchFinder = &p->matchFinderBase;\r\n  #endif\r\n\r\n  {\r\n    CLzmaEncProps props;\r\n    LzmaEncProps_Init(&props);\r\n    LzmaEnc_SetProps(p, &props);\r\n  }\r\n\r\n  #ifndef LZMA_LOG_BSR\r\n  LzmaEnc_FastPosInit(p->g_FastPos);\r\n  #endif\r\n\r\n  LzmaEnc_InitPriceTables(p->ProbPrices);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)\r\n{\r\n  void *p;\r\n  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));\r\n  if (p != 0)\r\n    LzmaEnc_Construct((CLzmaEnc *)p);\r\n  return p;\r\n}\r\n\r\nvoid LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->litProbs);\r\n  alloc->Free(alloc, p->saveState.litProbs);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nvoid LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);\r\n  #endif\r\n  MatchFinder_Free(&p->matchFinderBase, allocBig);\r\n  LzmaEnc_FreeLits(p, alloc);\r\n  RangeEnc_Free(&p->rc, alloc);\r\n}\r\n\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);\r\n  alloc->Free(alloc, p);\r\n}\r\n\r\nstatic SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)\r\n{\r\n  UInt32 nowPos32, startPos32;\r\n  if (p->inStream != 0)\r\n  {\r\n    p->matchFinderBase.stream = p->inStream;\r\n    p->matchFinder.Init(p->matchFinderObj);\r\n    p->inStream = 0;\r\n  }\r\n\r\n  if (p->finished)\r\n    return p->result;\r\n  RINOK(CheckErrors(p));\r\n\r\n  nowPos32 = (UInt32)p->nowPos64;\r\n  startPos32 = nowPos32;\r\n\r\n  if (p->nowPos64 == 0)\r\n  {\r\n    UInt32 numPairs;\r\n    Byte curByte;\r\n    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n      return Flush(p, nowPos32);\r\n    ReadMatchDistances(p, &numPairs);\r\n    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);\r\n    p->state = kLiteralNextStates[p->state];\r\n    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);\r\n    LitEnc_Encode(&p->rc, p->litProbs, curByte);\r\n    p->additionalOffset--;\r\n    nowPos32++;\r\n  }\r\n\r\n  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)\r\n  for (;;)\r\n  {\r\n    UInt32 pos, len, posState;\r\n\r\n    if (p->fastMode)\r\n      len = GetOptimumFast(p, &pos);\r\n    else\r\n      len = GetOptimum(p, nowPos32, &pos);\r\n\r\n    #ifdef SHOW_STAT2\r\n    printf(\"\\n pos = %4X,   len = %d   pos = %d\", nowPos32, len, pos);\r\n    #endif\r\n\r\n    posState = nowPos32 & p->pbMask;\r\n    if (len == 1 && pos == (UInt32)-1)\r\n    {\r\n      Byte curByte;\r\n      CLzmaProb *probs;\r\n      const Byte *data;\r\n\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);\r\n      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n      curByte = *data;\r\n      probs = LIT_PROBS(nowPos32, *(data - 1));\r\n      if (IsCharState(p->state))\r\n        LitEnc_Encode(&p->rc, probs, curByte);\r\n      else\r\n        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));\r\n      p->state = kLiteralNextStates[p->state];\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);\r\n        if (pos == 0)\r\n        {\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = p->reps[pos];\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);\r\n          if (pos == 1)\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);\r\n          else\r\n          {\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);\r\n            if (pos == 3)\r\n              p->reps[3] = p->reps[2];\r\n            p->reps[2] = p->reps[1];\r\n          }\r\n          p->reps[1] = p->reps[0];\r\n          p->reps[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          p->state = kShortRepNextStates[p->state];\r\n        else\r\n        {\r\n          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n          p->state = kRepNextStates[p->state];\r\n        }\r\n      }\r\n      else\r\n      {\r\n        UInt32 posSlot;\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n        p->state = kMatchNextStates[p->state];\r\n        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n        pos -= LZMA_NUM_REPS;\r\n        GetPosSlot(pos, posSlot);\r\n        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);\r\n          else\r\n          {\r\n            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);\r\n            p->alignPriceCount++;\r\n          }\r\n        }\r\n        p->reps[3] = p->reps[2];\r\n        p->reps[2] = p->reps[1];\r\n        p->reps[1] = p->reps[0];\r\n        p->reps[0] = pos;\r\n        p->matchPriceCount++;\r\n      }\r\n    }\r\n    p->additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (p->additionalOffset == 0)\r\n    {\r\n      UInt32 processed;\r\n      if (!p->fastMode)\r\n      {\r\n        if (p->matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices(p);\r\n        if (p->alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices(p);\r\n      }\r\n      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n        break;\r\n      processed = nowPos32 - startPos32;\r\n      if (useLimits)\r\n      {\r\n        if (processed + kNumOpts + 300 >= maxUnpackSize ||\r\n            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)\r\n          break;\r\n      }\r\n      else if (processed >= (1 << 15))\r\n      {\r\n        p->nowPos64 += nowPos32 - startPos32;\r\n        return CheckErrors(p);\r\n      }\r\n    }\r\n  }\r\n  p->nowPos64 += nowPos32 - startPos32;\r\n  return Flush(p, nowPos32);\r\n}\r\n\r\n#define kBigHashDicLimit ((UInt32)1 << 24)\r\n\r\nstatic SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 beforeSize = kNumOpts;\r\n  Bool btMode;\r\n  if (!RangeEnc_Alloc(&p->rc, alloc))\r\n    return SZ_ERROR_MEM;\r\n  btMode = (p->matchFinderBase.btMode != 0);\r\n  #ifdef COMPRESS_MF_MT\r\n  p->mtMode = (p->multiThread && !p->fastMode && btMode);\r\n  #endif\r\n\r\n  {\r\n    unsigned lclp = p->lc + p->lp;\r\n    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)\r\n    {\r\n      LzmaEnc_FreeLits(p, alloc);\r\n      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      if (p->litProbs == 0 || p->saveState.litProbs == 0)\r\n      {\r\n        LzmaEnc_FreeLits(p, alloc);\r\n        return SZ_ERROR_MEM;\r\n      }\r\n      p->lclp = lclp;\r\n    }\r\n  }\r\n\r\n  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);\r\n\r\n  if (beforeSize + p->dictSize < keepWindowSize)\r\n    beforeSize = keepWindowSize - p->dictSize;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (p->mtMode)\r\n  {\r\n    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));\r\n    p->matchFinderObj = &p->matchFinderMt;\r\n    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))\r\n      return SZ_ERROR_MEM;\r\n    p->matchFinderObj = &p->matchFinderBase;\r\n    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nvoid LzmaEnc_Init(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  p->state = 0;\r\n  for (i = 0 ; i < LZMA_NUM_REPS; i++)\r\n    p->reps[i] = 0;\r\n\r\n  RangeEnc_Init(&p->rc);\r\n\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    UInt32 j;\r\n    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)\r\n    {\r\n      p->isMatch[i][j] = kProbInitValue;\r\n      p->isRep0Long[i][j] = kProbInitValue;\r\n    }\r\n    p->isRep[i] = kProbInitValue;\r\n    p->isRepG0[i] = kProbInitValue;\r\n    p->isRepG1[i] = kProbInitValue;\r\n    p->isRepG2[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    UInt32 num = 0x300 << (p->lp + p->lc);\r\n    for (i = 0; i < num; i++)\r\n      p->litProbs[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    for (i = 0; i < kNumLenToPosStates; i++)\r\n    {\r\n      CLzmaProb *probs = p->posSlotEncoder[i];\r\n      UInt32 j;\r\n      for (j = 0; j < (1 << kNumPosSlotBits); j++)\r\n        probs[j] = kProbInitValue;\r\n    }\r\n  }\r\n  {\r\n    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      p->posEncoders[i] = kProbInitValue;\r\n  }\r\n\r\n  LenEnc_Init(&p->lenEnc.p);\r\n  LenEnc_Init(&p->repLenEnc.p);\r\n\r\n  for (i = 0; i < (1 << kNumAlignBits); i++)\r\n    p->posAlignEncoder[i] = kProbInitValue;\r\n\r\n  p->optimumEndIndex = 0;\r\n  p->optimumCurrentIndex = 0;\r\n  p->additionalOffset = 0;\r\n\r\n  p->pbMask = (1 << p->pb) - 1;\r\n  p->lpMask = (1 << p->lp) - 1;\r\n}\r\n\r\nvoid LzmaEnc_InitPrices(CLzmaEnc *p)\r\n{\r\n  if (!p->fastMode)\r\n  {\r\n    FillDistancesPrices(p);\r\n    FillAlignPrices(p);\r\n  }\r\n\r\n  p->lenEnc.tableSize =\r\n  p->repLenEnc.tableSize =\r\n      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;\r\n  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);\r\n  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);\r\n}\r\n\r\nstatic SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)\r\n    if (p->dictSize <= ((UInt32)1 << i))\r\n      break;\r\n  p->distTableSize = i * 2;\r\n\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));\r\n  LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  p->nowPos64 = 0;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  p->rc.outStream = outStream;\r\n  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);\r\n}\r\n\r\nSRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,\r\n    ISeqInStream *inStream, UInt32 keepWindowSize,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nstatic void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)\r\n{\r\n  p->seqBufInStream.funcTable.Read = MyRead;\r\n  p->seqBufInStream.data = src;\r\n  p->seqBufInStream.rem = srcLen;\r\n}\r\n\r\nSRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\r\n    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n  p->inStream = &p->seqBufInStream.funcTable;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nvoid LzmaEnc_Finish(CLzmaEncHandle pp)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  if (p->mtMode)\r\n    MatchFinderMt_ReleaseStream(&p->matchFinderMt);\r\n  #else\r\n  pp = pp;\r\n  #endif\r\n}\r\n\r\ntypedef struct _CSeqOutStreamBuf\r\n{\r\n  ISeqOutStream funcTable;\r\n  Byte *data;\r\n  SizeT rem;\r\n  Bool overflow;\r\n} CSeqOutStreamBuf;\r\n\r\nstatic size_t MyWrite(void *pp, const void *data, size_t size)\r\n{\r\n  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;\r\n  if (p->rem < size)\r\n  {\r\n    size = p->rem;\r\n    p->overflow = True;\r\n  }\r\n  memcpy(p->data, data, size);\r\n  p->rem -= size;\r\n  p->data += size;\r\n  return size;\r\n}\r\n\r\n\r\nUInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n}\r\n\r\nconst Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n}\r\n\r\nSRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\r\n    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  UInt64 nowPos64;\r\n  SRes res;\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = False;\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n\r\n  if (reInit)\r\n    LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  nowPos64 = p->nowPos64;\r\n  RangeEnc_Init(&p->rc);\r\n  p->rc.outStream = &outStream.funcTable;\r\n\r\n  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);\r\n  \r\n  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  SRes res = SZ_OK;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte allocaDummy[0x300];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  #endif\r\n\r\n  RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));\r\n\r\n  for (;;)\r\n  {\r\n    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);\r\n    if (res != SZ_OK || p->finished != 0)\r\n      break;\r\n    if (progress != 0)\r\n    {\r\n      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));\r\n      if (res != SZ_OK)\r\n      {\r\n        res = SZ_ERROR_PROGRESS;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  LzmaEnc_Finish(pp);\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  int i;\r\n  UInt32 dictSize = p->dictSize;\r\n  if (*size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_PARAM;\r\n  *size = LZMA_PROPS_SIZE;\r\n  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);\r\n\r\n  for (i = 11; i <= 30; i++)\r\n  {\r\n    if (dictSize <= ((UInt32)2 << i))\r\n    {\r\n      dictSize = (2 << i);\r\n      break;\r\n    }\r\n    if (dictSize <= ((UInt32)3 << i))\r\n    {\r\n      dictSize = (3 << i);\r\n      break;\r\n    }\r\n  }\r\n\r\n  for (i = 0; i < 4; i++)\r\n    props[1 + i] = (Byte)(dictSize >> (8 * i));\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  SRes res;\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = writeEndMark;\r\n  res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,\r\n      progress, alloc, allocBig);\r\n\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n  return res;\r\n}\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);\r\n  SRes res;\r\n  if (p == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LzmaEnc_SetProps(p, props);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);\r\n    if (res == SZ_OK)\r\n      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,\r\n          writeEndMark, progress, alloc, allocBig);\r\n  }\r\n\r\n  LzmaEnc_Destroy(p, alloc, allocBig);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaEnc.h",
    "content": "/*  LzmaEnc.h -- LZMA Encoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMAENC_H\r\n#define __LZMAENC_H\r\n\r\n#include \"Types.h\"\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaEncProps\r\n{\r\n  int level;       /*  0 <= level <= 9 */\r\n  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version\r\n                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version\r\n                       default = (1 << 24) */\r\n  int lc;          /* 0 <= lc <= 8, default = 3 */\r\n  int lp;          /* 0 <= lp <= 4, default = 0 */\r\n  int pb;          /* 0 <= pb <= 4, default = 2 */\r\n  int algo;        /* 0 - fast, 1 - normal, default = 1 */\r\n  int fb;          /* 5 <= fb <= 273, default = 32 */\r\n  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */\r\n  int numHashBytes; /* 2, 3 or 4, default = 4 */\r\n  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */\r\n  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */\r\n  int numThreads;  /* 1 or 2, default = 2 */\r\n} CLzmaEncProps;\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p);\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p);\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);\r\n\r\n\r\n/* ---------- CLzmaEncHandle Interface ---------- */\r\n\r\n/* LzmaEnc_* functions can return the following exit codes:\r\nReturns:\r\n  SZ_OK           - OK\r\n  SZ_ERROR_MEM    - Memory allocation error\r\n  SZ_ERROR_PARAM  - Incorrect paramater in props\r\n  SZ_ERROR_WRITE  - Write callback error.\r\n  SZ_ERROR_PROGRESS - some break from progress callback\r\n  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\ntypedef void * CLzmaEncHandle;\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);\r\nSRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaEncode\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaLib/LzmaLib.def",
    "content": "EXPORTS\r\n  LzmaCompress\r\n  LzmaUncompress\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaLib/LzmaLib.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaLib\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n\r\nCFG=LzmaLib - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaLib.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaLib.mak\" CFG=\"LzmaLib - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"LzmaLib - Win32 Release\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n!MESSAGE \"LzmaLib - Win32 Debug\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nMTL=midl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"LzmaLib - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /c\r\n# ADD CPP /nologo /Gr /MT /W3 /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"LzmaLib - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /GZ /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"LzmaLib - Win32 Release\"\r\n# Name \"LzmaLib - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaLib.def\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaLibExports.c\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaLib.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaLib.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Types.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaLib/LzmaLib.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"LzmaLib\"=.\\LzmaLib.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaLib/LzmaLibExports.c",
    "content": "/* LzmaLibExports.c -- LZMA library DLL Entry point\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <windows.h>\r\n\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r\n{\r\n  hInstance = hInstance;\r\n  dwReason = dwReason;\r\n  lpReserved = lpReserved;\r\n  return TRUE;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaLib/Makefile",
    "content": "CC = gcc\nLIB = liblzma.a\nRM = rm -f\nCFLAGS = -c -O2 -Wall\nAR = ar\nRANLIB = ranlib\n\nOBJS = \\\n  Alloc.o \\\n  LzFind.o \\\n  LzmaDec.o \\\n  LzmaEnc.o \\\n  LzmaLib.o \\\n  7zFile.o \\\n  7zStream.o \\\n\nall: $(LIB)\n\n$(LIB): $(OBJS)\n\trm -f $@\n\t$(AR) rcu $@ $(OBJS)\n\t$(RANLIB) $@\n\nAlloc.o: ../Alloc.c\n\t$(CC) $(CFLAGS) ../Alloc.c\n\nLzFind.o: ../LzFind.c\n\t$(CC) $(CFLAGS) ../LzFind.c\n\nLzmaDec.o: ../LzmaDec.c\n\t$(CC) $(CFLAGS) ../LzmaDec.c\n\nLzmaEnc.o: ../LzmaEnc.c\n\t$(CC) $(CFLAGS) ../LzmaEnc.c\n\nLzmaLib.o: ../LzmaLib.c\n\t$(CC) $(CFLAGS) ../LzmaLib.c\n\n7zFile.o: ../7zFile.c\n\t$(CC) $(CFLAGS) ../7zFile.c\n\n7zStream.o: ../7zStream.c\n\t$(CC) $(CFLAGS) ../7zStream.c\n\nclean:\n\t-$(RM) $(PROG) *.o *.a\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaLib/resource.rc",
    "content": "#include \"../../CPP/7zip/MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"LZMA library\", \"LZMA\")\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaLib.c",
    "content": "/* LzmaLib.c -- LZMA library wrapper\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"LzmaEnc.h\"\r\n#include \"LzmaDec.h\"\r\n#include \"Alloc.h\"\r\n#include \"LzmaLib.h\"\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  srcLen,\r\n  unsigned char *outProps, size_t *outPropsSize,\r\n  int level, /* 0 <= level <= 9, default = 5 */\r\n  unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */\r\n  int lc, /* 0 <= lc <= 8, default = 3  */\r\n  int lp, /* 0 <= lp <= 4, default = 0  */\r\n  int pb, /* 0 <= pb <= 4, default = 2  */\r\n  int fb,  /* 5 <= fb <= 273, default = 32 */\r\n  int numThreads /* 1 or 2, default = 2 */\r\n)\r\n{\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n  props.level = level;\r\n  props.dictSize = dictSize;\r\n  props.lc = lc;\r\n  props.lp = lp;\r\n  props.pb = pb;\r\n  props.fb = fb;\r\n  props.numThreads = numThreads;\r\n\r\n  return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,\r\n      NULL, &g_Alloc, &g_Alloc);\r\n}\r\n\r\n\r\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  *srcLen,\r\n  const unsigned char *props, size_t propsSize)\r\n{\r\n  ELzmaStatus status;\r\n  return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaLib.h",
    "content": "/* LzmaLib.h -- LZMA library interface\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMALIB_H\r\n#define __LZMALIB_H\r\n\r\n#include \"Types.h\"\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\n/*\r\nRAM requirements for LZMA:\r\n  for compression:   (dictSize * 11.5 + 6 MB) + state_size\r\n  for decompression: dictSize + state_size\r\n    state_size = (4 + (1.5 << (lc + lp))) KB\r\n    by default (lc=3, lp=0), state_size = 16 KB.\r\n\r\nLZMA properties (5 bytes) format\r\n    Offset Size  Description\r\n      0     1    lc, lp and pb in encoded form.\r\n      1     4    dictSize (little endian).\r\n*/\r\n\r\n/*\r\nLzmaCompress\r\n------------\r\n\r\noutPropsSize -\r\n     In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r\n     Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r\n\r\n  LZMA Encoder will use defult values for any parameter, if it is\r\n  -1  for any from: level, loc, lp, pb, fb, numThreads\r\n   0  for dictSize\r\n  \r\nlevel - compression level: 0 <= level <= 9;\r\n\r\n  level dictSize algo  fb\r\n    0:    16 KB   0    32\r\n    1:    64 KB   0    32\r\n    2:   256 KB   0    32\r\n    3:     1 MB   0    32\r\n    4:     4 MB   0    32\r\n    5:    16 MB   1    32\r\n    6:    32 MB   1    32\r\n    7+:   64 MB   1    64\r\n \r\n  The default value for \"level\" is 5.\r\n\r\n  algo = 0 means fast method\r\n  algo = 1 means normal method\r\n\r\ndictSize - The dictionary size in bytes. The maximum value is\r\n        128 MB = (1 << 27) bytes for 32-bit version\r\n          1 GB = (1 << 30) bytes for 64-bit version\r\n     The default value is 16 MB = (1 << 24) bytes.\r\n     It's recommended to use the dictionary that is larger than 4 KB and\r\n     that can be calculated as (1 << N) or (3 << N) sizes.\r\n\r\nlc - The number of literal context bits (high bits of previous literal).\r\n     It can be in the range from 0 to 8. The default value is 3.\r\n     Sometimes lc=4 gives the gain for big files.\r\n\r\nlp - The number of literal pos bits (low bits of current position for literals).\r\n     It can be in the range from 0 to 4. The default value is 0.\r\n     The lp switch is intended for periodical data when the period is equal to 2^lp.\r\n     For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's\r\n     better to set lc=0, if you change lp switch.\r\n\r\npb - The number of pos bits (low bits of current position).\r\n     It can be in the range from 0 to 4. The default value is 2.\r\n     The pb switch is intended for periodical data when the period is equal 2^pb.\r\n\r\nfb - Word size (the number of fast bytes).\r\n     It can be in the range from 5 to 273. The default value is 32.\r\n     Usually, a big number gives a little bit better compression ratio and\r\n     slower compression process.\r\n\r\nnumThreads - The number of thereads. 1 or 2. The default value is 2.\r\n     Fast mode (algo = 0) can use only 1 thread.\r\n\r\nOut:\r\n  destLen  - processed output size\r\nReturns:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,\r\n  unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */\r\n  int level,      /* 0 <= level <= 9, default = 5 */\r\n  unsigned dictSize,  /* default = (1 << 24) */\r\n  int lc,        /* 0 <= lc <= 8, default = 3  */\r\n  int lp,        /* 0 <= lp <= 4, default = 0  */\r\n  int pb,        /* 0 <= pb <= 4, default = 2  */\r\n  int fb,        /* 5 <= fb <= 273, default = 32 */\r\n  int numThreads /* 1 or 2, default = 2 */\r\n  );\r\n\r\n/*\r\nLzmaUncompress\r\n--------------\r\nIn:\r\n  dest     - output data\r\n  destLen  - output data size\r\n  src      - input data\r\n  srcLen   - input data size\r\nOut:\r\n  destLen  - processed output size\r\n  srcLen   - processed input size\r\nReturns:\r\n  SZ_OK                - OK\r\n  SZ_ERROR_DATA        - Data error\r\n  SZ_ERROR_MEM         - Memory allocation arror\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)\r\n*/\r\n\r\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,\r\n  const unsigned char *props, size_t propsSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaUtil/Lzma86Dec.c",
    "content": "/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder\r\n2008-04-07\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"Lzma86Dec.h\"\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../Bra.h\"\r\n#include \"../LzmaDec.h\"\r\n\r\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\r\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)\r\n{\r\n  unsigned i;\r\n  if (srcLen < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n  *unpackSize = 0;\r\n  for (i = 0; i < sizeof(UInt64); i++)\r\n    *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);\r\n  return SZ_OK;\r\n}\r\n\r\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)\r\n{\r\n  SRes res;\r\n  int useFilter;\r\n  SizeT inSizePure;\r\n  ELzmaStatus status;\r\n\r\n  if (*srcLen < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  useFilter = src[0];\r\n\r\n  if (useFilter > 1)\r\n  {\r\n    *destLen = 0;\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  }\r\n\r\n  inSizePure = *srcLen - LZMA86_HEADER_SIZE;\r\n  res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,\r\n      src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);\r\n  *srcLen = inSizePure + LZMA86_HEADER_SIZE;\r\n  if (res != SZ_OK)\r\n    return res;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(dest, *destLen, 0, &x86State, 0);\r\n  }\r\n  return SZ_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaUtil/Lzma86Dec.h",
    "content": "/* Lzma86Dec.h -- LZMA + x86 (BCJ) Filter Decoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMA86DEC_H\r\n#define __LZMA86DEC_H\r\n\r\n#include \"../Types.h\"\r\n\r\n/*\r\nLzma86_GetUnpackSize:\r\n  In:\r\n    src      - input data\r\n    srcLen   - input data size\r\n  Out:\r\n    unpackSize - size of uncompressed stream\r\n  Return code:\r\n    SZ_OK               - OK\r\n    SZ_ERROR_INPUT_EOF  - Error in headers\r\n*/\r\n\r\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);\r\n\r\n/*\r\nLzma86_Decode:\r\n  In:\r\n    dest     - output data\r\n    destLen  - output data size\r\n    src      - input data\r\n    srcLen   - input data size\r\n  Out:\r\n    destLen  - processed output size\r\n    srcLen   - processed input size\r\n  Return code:\r\n    SZ_OK           - OK\r\n    SZ_ERROR_DATA  - Data error\r\n    SZ_ERROR_MEM   - Memory allocation error\r\n    SZ_ERROR_UNSUPPORTED - unsupported file\r\n    SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer\r\n*/\r\n\r\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaUtil/Lzma86Enc.c",
    "content": "/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"Lzma86Enc.h\"\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../Bra.h\"\r\n#include \"../LzmaEnc.h\"\r\n\r\n#define SZE_OUT_OVERFLOW SZE_DATA_ERROR\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\r\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\r\n\r\nint Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r\n    int level, UInt32 dictSize, int filterMode)\r\n{\r\n  size_t outSize2 = *destLen;\r\n  Byte *filteredStream;\r\n  Bool useFilter;\r\n  int mainResult = SZ_ERROR_OUTPUT_EOF;\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n  props.level = level;\r\n  props.dictSize = dictSize;\r\n  \r\n  *destLen = 0;\r\n  if (outSize2 < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  {\r\n    int i;\r\n    UInt64 t = srcLen;\r\n    for (i = 0; i < 8; i++, t >>= 8)\r\n      dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;\r\n  }\r\n\r\n  filteredStream = 0;\r\n  useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (srcLen != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(srcLen);\r\n      if (filteredStream == 0)\r\n        return SZ_ERROR_MEM;\r\n      memcpy(filteredStream, src, srcLen);\r\n    }\r\n    {\r\n      UInt32 x86State;\r\n      x86_Convert_Init(x86State);\r\n      x86_Convert(filteredStream, srcLen, 0, &x86State, 1);\r\n    }\r\n  }\r\n\r\n  {\r\n    size_t minSize = 0;\r\n    Bool bestIsFiltered = False;\r\n\r\n    /* passes for SZ_FILTER_AUTO:\r\n        0 - BCJ + LZMA\r\n        1 - LZMA\r\n        2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.\r\n    */\r\n    int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n\r\n    int i;\r\n    for (i = 0; i < numPasses; i++)\r\n    {\r\n      size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;\r\n      size_t outPropsSize = 5;\r\n      SRes curRes;\r\n      Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);\r\n      if (curModeIsFiltered && !bestIsFiltered)\r\n        break;\r\n      if (useFilter && i == 0)\r\n        curModeIsFiltered = True;\r\n      \r\n      curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,\r\n          curModeIsFiltered ? filteredStream : src, srcLen,\r\n          &props, dest + 1, &outPropsSize, 0,\r\n          NULL, &g_Alloc, &g_Alloc);\r\n      \r\n      if (curRes != SZ_ERROR_OUTPUT_EOF)\r\n      {\r\n        if (curRes != SZ_OK)\r\n        {\r\n          mainResult = curRes;\r\n          break;\r\n        }\r\n        if (outSizeProcessed <= minSize || mainResult != SZ_OK)\r\n        {\r\n          minSize = outSizeProcessed;\r\n          bestIsFiltered = curModeIsFiltered;\r\n          mainResult = SZ_OK;\r\n        }\r\n      }\r\n    }\r\n    dest[0] = (bestIsFiltered ? 1 : 0);\r\n    *destLen = LZMA86_HEADER_SIZE + minSize;\r\n  }\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaUtil/Lzma86Enc.h",
    "content": "/* Lzma86Enc.h -- LZMA + x86 (BCJ) Filter Encoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMA86ENC_H\r\n#define __LZMA86ENC_H\r\n\r\n#include \"../Types.h\"\r\n\r\n/*\r\nIt's an example for LZMA + x86 Filter use.\r\nYou can use .lzma86 extension, if you write that stream to file.\r\n.lzma86 header adds one additional byte to standard .lzma header.\r\n.lzma86 header (14 bytes):\r\n  Offset Size  Description\r\n    0     1    = 0 - no filter,\r\n               = 1 - x86 filter\r\n    1     1    lc, lp and pb in encoded form\r\n    2     4    dictSize (little endian)\r\n    6     8    uncompressed size (little endian)\r\n\r\n\r\nLzma86_Encode\r\n-------------\r\nlevel - compression level: 0 <= level <= 9, the default value for \"level\" is 5.\r\n\r\n\r\ndictSize - The dictionary size in bytes. The maximum value is\r\n        128 MB = (1 << 27) bytes for 32-bit version\r\n          1 GB = (1 << 30) bytes for 64-bit version\r\n     The default value is 16 MB = (1 << 24) bytes, for level = 5.\r\n     It's recommended to use the dictionary that is larger than 4 KB and\r\n     that can be calculated as (1 << N) or (3 << N) sizes.\r\n     For better compression ratio dictSize must be >= inSize.\r\n\r\nfilterMode:\r\n    SZ_FILTER_NO   - no Filter\r\n    SZ_FILTER_YES  - x86 Filter\r\n    SZ_FILTER_AUTO - it tries both alternatives to select best.\r\n              Encoder will use 2 or 3 passes:\r\n              2 passes when FILTER_NO provides better compression.\r\n              3 passes when FILTER_YES provides better compression.\r\n\r\nLzma86Encode allocates Data with MyAlloc functions.\r\nRAM Requirements for compressing:\r\n  RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize\r\n      filterMode     FilterBlockSize\r\n     SZ_FILTER_NO         0\r\n     SZ_FILTER_YES      inSize\r\n     SZ_FILTER_AUTO     inSize\r\n\r\n\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nenum ESzFilterMode\r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nSRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r\n    int level, UInt32 dictSize, int filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaUtil/LzmaUtil.c",
    "content": "/* LzmaUtil.c -- Test application for LZMA compression\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#define _CRT_SECURE_NO_WARNINGS\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../7zFile.h\"\r\n#include \"../7zVersion.h\"\r\n#include \"../LzmaDec.h\"\r\n#include \"../LzmaEnc.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\nconst char *kDataErrorMessage = \"Data error\";\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nvoid PrintHelp(char *buffer)\r\n{\r\n  strcat(buffer, \"\\nLZMA Utility \" MY_VERSION_COPYRIGHT_DATE \"\\n\"\r\n      \"\\nUsage:  lzma <e|d> inputFile outputFile\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\");\r\n}\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  strcat(buffer, \"\\nError: \");\r\n  strcat(buffer, message);\r\n  strcat(buffer, \"\\n\");\r\n  return 1;\r\n}\r\n\r\nint PrintErrorNumber(char *buffer, SRes val)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError code: %x\\n\", (unsigned)val);\r\n  return 1;\r\n}\r\n\r\nint PrintUserError(char *buffer)\r\n{\r\n  return PrintError(buffer, \"Incorrect command\");\r\n}\r\n\r\n#define IN_BUF_SIZE (1 << 16)\r\n#define OUT_BUF_SIZE (1 << 16)\r\n\r\nstatic SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    UInt64 unpackSize)\r\n{\r\n  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);\r\n  Byte inBuf[IN_BUF_SIZE];\r\n  Byte outBuf[OUT_BUF_SIZE];\r\n  size_t inPos = 0, inSize = 0, outPos = 0;\r\n  LzmaDec_Init(state);\r\n  for (;;)\r\n  {\r\n    if (inPos == inSize)\r\n    {\r\n      inSize = IN_BUF_SIZE;\r\n      RINOK(inStream->Read(inStream, inBuf, &inSize));\r\n      inPos = 0;\r\n    }\r\n    {\r\n      SRes res;\r\n      SizeT inProcessed = inSize - inPos;\r\n      SizeT outProcessed = OUT_BUF_SIZE - outPos;\r\n      ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\r\n      ELzmaStatus status;\r\n      if (thereIsSize && outProcessed > unpackSize)\r\n      {\r\n        outProcessed = (SizeT)unpackSize;\r\n        finishMode = LZMA_FINISH_END;\r\n      }\r\n      \r\n      res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,\r\n        inBuf + inPos, &inProcessed, finishMode, &status);\r\n      inPos += inProcessed;\r\n      outPos += outProcessed;\r\n      unpackSize -= outProcessed;\r\n      \r\n      if (outStream)\r\n        if (outStream->Write(outStream, outBuf, outPos) != outPos)\r\n          return SZ_ERROR_WRITE;\r\n        \r\n      outPos = 0;\r\n      \r\n      if (res != SZ_OK || thereIsSize && unpackSize == 0)\r\n        return res;\r\n      \r\n      if (inProcessed == 0 && outProcessed == 0)\r\n      {\r\n        if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)\r\n          return SZ_ERROR_DATA;\r\n        return res;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)\r\n{\r\n  UInt64 unpackSize;\r\n  int i;\r\n  SRes res = 0;\r\n\r\n  CLzmaDec state;\r\n\r\n  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */\r\n  unsigned char header[LZMA_PROPS_SIZE + 8];\r\n\r\n  /* Read and parse header */\r\n\r\n  RINOK(SeqInStream_Read(inStream, header, sizeof(header)));\r\n\r\n  unpackSize = 0;\r\n  for (i = 0; i < 8; i++)\r\n    unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);\r\n\r\n  LzmaDec_Construct(&state);\r\n  RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));\r\n  res = Decode2(&state, outStream, inStream, unpackSize);\r\n  LzmaDec_Free(&state, &g_Alloc);\r\n  return res;\r\n}\r\n\r\nstatic SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)\r\n{\r\n  CLzmaEncHandle enc;\r\n  SRes res;\r\n  CLzmaEncProps props;\r\n\r\n  rs = rs;\r\n\r\n  enc = LzmaEnc_Create(&g_Alloc);\r\n  if (enc == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  LzmaEncProps_Init(&props);\r\n  res = LzmaEnc_SetProps(enc, &props);\r\n\r\n  if (res == SZ_OK)\r\n  {\r\n    Byte header[LZMA_PROPS_SIZE + 8];\r\n    size_t headerSize = LZMA_PROPS_SIZE;\r\n    int i;\r\n\r\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r\n    for (i = 0; i < 8; i++)\r\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r\n    if (outStream->Write(outStream, header, headerSize) != headerSize)\r\n      res = SZ_ERROR_WRITE;\r\n    else\r\n    {\r\n      if (res == SZ_OK)\r\n        res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);\r\n    }\r\n  }\r\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  CFileSeqInStream inStream;\r\n  CFileOutStream outStream;\r\n  char c;\r\n  int res;\r\n  int encodeMode;\r\n  Bool useOutFile = False;\r\n\r\n  FileSeqInStream_CreateVTable(&inStream);\r\n  File_Construct(&inStream.file);\r\n\r\n  FileOutStream_CreateVTable(&outStream);\r\n  File_Construct(&outStream.file);\r\n\r\n  if (numArgs == 1)\r\n  {\r\n    PrintHelp(rs);\r\n    return 0;\r\n  }\r\n\r\n  if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1)\r\n    return PrintUserError(rs);\r\n\r\n  c = args[1][0];\r\n  encodeMode = (c == 'e' || c == 'E');\r\n  if (!encodeMode && c != 'd' && c != 'D')\r\n    return PrintUserError(rs);\r\n\r\n  {\r\n    size_t t4 = sizeof(UInt32);\r\n    size_t t8 = sizeof(UInt64);\r\n    if (t4 != 4 || t8 != 8)\r\n      return PrintError(rs, \"Incorrect UInt32 or UInt64\");\r\n  }\r\n\r\n  if (InFile_Open(&inStream.file, args[2]) != 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 3)\r\n  {\r\n    useOutFile = True;\r\n    if (OutFile_Open(&outStream.file, args[3]) != 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n  else if (encodeMode)\r\n    PrintUserError(rs);\r\n\r\n  if (encodeMode)\r\n  {\r\n    UInt64 fileSize;\r\n    File_GetLength(&inStream.file, &fileSize);\r\n    res = Encode(&outStream.s, &inStream.s, fileSize, rs);\r\n  }\r\n  else\r\n  {\r\n    res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL);\r\n  }\r\n\r\n  if (useOutFile)\r\n    File_Close(&outStream.file);\r\n  File_Close(&inStream.file);\r\n\r\n  if (res != SZ_OK)\r\n  {\r\n    if (res == SZ_ERROR_MEM)\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    else if (res == SZ_ERROR_DATA)\r\n      return PrintError(rs, kDataErrorMessage);\r\n    else if (res == SZ_ERROR_WRITE)\r\n      return PrintError(rs, kCantWriteMessage);\r\n    else if (res == SZ_ERROR_READ)\r\n      return PrintError(rs, kCantReadMessage);\r\n    return PrintErrorNumber(rs, res);\r\n  }\r\n  return 0;\r\n}\r\n\r\nint MY_CDECL main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaUtil/LzmaUtil.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaUtil\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=LzmaUtil - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaUtil.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaUtil.mak\" CFG=\"LzmaUtil - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"LzmaUtil - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"LzmaUtil - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"LzmaUtil - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\util\\lzmac.exe\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"LzmaUtil - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /GZ /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\util\\lzmac.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"LzmaUtil - Win32 Release\"\r\n# Name \"LzmaUtil - Win32 Debug\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zFile.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zFile.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zStream.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zVersion.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\CpuArch.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaUtil.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Types.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaUtil/LzmaUtil.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"LzmaUtil\"=.\\LzmaUtil.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaUtil/makefile",
    "content": "MY_STATIC_LINK=1\r\nPROG = LZMAc.exe\r\n\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n\r\nLIB_OBJS = \\\r\n  $O\\LzmaUtil.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\7zFile.obj \\\r\n  $O\\7zStream.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $(LIB_OBJS) \\\r\n  $(C_OBJS) \\\r\n\r\n!include \"../../CPP/Build.mak\"\r\n\r\n$(LIB_OBJS): $(*B).c\r\n\t$(COMPL_O2)\r\n$(C_OBJS): ../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/LzmaUtil/makefile.gcc",
    "content": "PROG = lzma\nCC = gcc\nLIB = liblzma.a\nRM = rm -f\nCFLAGS = -c -O2 -Wall\nAR = ar\nRANLIB = ranlib\n\nOBJS = \\\n  Alloc.o \\\n  LzFind.o \\\n  LzmaDec.o \\\n  LzmaEnc.o \\\n  LzmaLib.o \\\n  7zFile.o \\\n  7zStream.o \\\n\nall: $(PROG)\n\n$(PROG): LzmaUtil.o $(LIB)\n\t$(CC) -o $(PROG) $(LDFLAGS) $< $(LIB)\n\nLzmaUtil.o: LzmaUtil.c\n\t$(CC) $(CFLAGS) LzmaUtil.c\n\n$(LIB): $(OBJS)\n\trm -f $@\n\t$(AR) rcu $@ $(OBJS)\n\t$(RANLIB) $@\n\nAlloc.o: ../Alloc.c\n\t$(CC) $(CFLAGS) ../Alloc.c\n\nLzFind.o: ../LzFind.c\n\t$(CC) $(CFLAGS) ../LzFind.c\n\nLzmaDec.o: ../LzmaDec.c\n\t$(CC) $(CFLAGS) ../LzmaDec.c\n\nLzmaEnc.o: ../LzmaEnc.c\n\t$(CC) $(CFLAGS) ../LzmaEnc.c\n\nLzmaLib.o: ../LzmaLib.c\n\t$(CC) $(CFLAGS) ../LzmaLib.c\n\n7zFile.o: ../7zFile.c\n\t$(CC) $(CFLAGS) ../7zFile.c\n\n7zStream.o: ../7zStream.c\n\t$(CC) $(CFLAGS) ../7zStream.c\n\nclean:\n\t-$(RM) $(PROG) *.o *.a\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Threads.c",
    "content": "/* Threads.c -- multithreading library\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"Threads.h\"\r\n#include <process.h>\r\n\r\nstatic WRes GetError()\r\n{\r\n  DWORD res = GetLastError();\r\n  return (res) ? (WRes)(res) : 1;\r\n}\r\n\r\nWRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }\r\nWRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }\r\n\r\nstatic WRes MyCloseHandle(HANDLE *h)\r\n{\r\n  if (*h != NULL)\r\n    if (!CloseHandle(*h))\r\n      return GetError();\r\n  *h = NULL;\r\n  return 0;\r\n}\r\n\r\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n{\r\n  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r\n  thread->handle =\r\n    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */\r\n    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);\r\n    /* maybe we must use errno here, but probably GetLastError() is also OK. */\r\n  return HandleToWRes(thread->handle);\r\n}\r\n\r\nWRes WaitObject(HANDLE h)\r\n{\r\n  return (WRes)WaitForSingleObject(h, INFINITE);\r\n}\r\n\r\nWRes Thread_Wait(CThread *thread)\r\n{\r\n  if (thread->handle == NULL)\r\n    return 1;\r\n  return WaitObject(thread->handle);\r\n}\r\n\r\nWRes Thread_Close(CThread *thread)\r\n{\r\n  return MyCloseHandle(&thread->handle);\r\n}\r\n\r\nWRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)\r\n{\r\n  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);\r\n  return HandleToWRes(p->handle);\r\n}\r\n\r\nWRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, TRUE, initialSignaled); }\r\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)\r\n  { return ManualResetEvent_Create(p, 0); }\r\n\r\nWRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, FALSE, initialSignaled); }\r\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)\r\n  { return AutoResetEvent_Create(p, 0); }\r\n\r\nWRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }\r\nWRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }\r\nWRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }\r\nWRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }\r\n\r\n\r\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)\r\n{\r\n  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);\r\n  return HandleToWRes(p->handle);\r\n}\r\n\r\nWRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)\r\n{\r\n  return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));\r\n}\r\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)\r\n{\r\n  return Semaphore_Release(p, (LONG)releaseCount, NULL);\r\n}\r\nWRes Semaphore_Release1(CSemaphore *p)\r\n{\r\n  return Semaphore_ReleaseN(p, 1);\r\n}\r\n\r\nWRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }\r\nWRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }\r\n\r\nWRes CriticalSection_Init(CCriticalSection *p)\r\n{\r\n  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\r\n  __try\r\n  {\r\n    InitializeCriticalSection(p);\r\n    /* InitializeCriticalSectionAndSpinCount(p, 0); */\r\n  }\r\n  __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }\r\n  return 0;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Threads.h",
    "content": "/* Threads.h -- multithreading library\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_THRESDS_H\r\n#define __7Z_THRESDS_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _CThread\r\n{\r\n  HANDLE handle;\r\n} CThread;\r\n\r\n#define Thread_Construct(thread) (thread)->handle = NULL\r\n#define Thread_WasCreated(thread) ((thread)->handle != NULL)\r\n \r\ntypedef unsigned THREAD_FUNC_RET_TYPE;\r\n#define THREAD_FUNC_CALL_TYPE MY_STD_CALL\r\n#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r\n\r\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);\r\nWRes Thread_Wait(CThread *thread);\r\nWRes Thread_Close(CThread *thread);\r\n\r\ntypedef struct _CEvent\r\n{\r\n  HANDLE handle;\r\n} CEvent;\r\n\r\ntypedef CEvent CAutoResetEvent;\r\ntypedef CEvent CManualResetEvent;\r\n\r\n#define Event_Construct(event) (event)->handle = NULL\r\n#define Event_IsCreated(event) ((event)->handle != NULL)\r\n\r\nWRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);\r\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);\r\nWRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);\r\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);\r\nWRes Event_Set(CEvent *event);\r\nWRes Event_Reset(CEvent *event);\r\nWRes Event_Wait(CEvent *event);\r\nWRes Event_Close(CEvent *event);\r\n\r\n\r\ntypedef struct _CSemaphore\r\n{\r\n  HANDLE handle;\r\n} CSemaphore;\r\n\r\n#define Semaphore_Construct(p) (p)->handle = NULL\r\n\r\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);\r\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\r\nWRes Semaphore_Release1(CSemaphore *p);\r\nWRes Semaphore_Wait(CSemaphore *p);\r\nWRes Semaphore_Close(CSemaphore *p);\r\n\r\n\r\ntypedef CRITICAL_SECTION CCriticalSection;\r\n\r\nWRes CriticalSection_Init(CCriticalSection *p);\r\n#define CriticalSection_Delete(p) DeleteCriticalSection(p)\r\n#define CriticalSection_Enter(p) EnterCriticalSection(p)\r\n#define CriticalSection_Leave(p) LeaveCriticalSection(p)\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/C/Types.h",
    "content": "/* Types.h -- Basic types\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_TYPES_H\r\n#define __7Z_TYPES_H\r\n\r\n#include <stddef.h>\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#define SZ_OK 0\r\n\r\n#define SZ_ERROR_DATA 1\r\n#define SZ_ERROR_MEM 2\r\n#define SZ_ERROR_CRC 3\r\n#define SZ_ERROR_UNSUPPORTED 4\r\n#define SZ_ERROR_PARAM 5\r\n#define SZ_ERROR_INPUT_EOF 6\r\n#define SZ_ERROR_OUTPUT_EOF 7\r\n#define SZ_ERROR_READ 8\r\n#define SZ_ERROR_WRITE 9\r\n#define SZ_ERROR_PROGRESS 10\r\n#define SZ_ERROR_FAIL 11\r\n#define SZ_ERROR_THREAD 12\r\n\r\n#define SZ_ERROR_ARCHIVE 16\r\n#define SZ_ERROR_NO_ARCHIVE 17\r\n\r\ntypedef int SRes;\r\n\r\n#ifdef _WIN32\r\ntypedef DWORD WRes;\r\n#else\r\ntypedef int WRes;\r\n#endif\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r\n#endif\r\n\r\ntypedef unsigned char Byte;\r\ntypedef short Int16;\r\ntypedef unsigned short UInt16;\r\n\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef long Int32;\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef int Int32;\r\ntypedef unsigned int UInt32;\r\n#endif\r\n\r\n#ifdef _SZ_NO_INT_64\r\n\r\n/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r\n   NOTES: Some code will work incorrectly in that case! */\r\n\r\ntypedef long Int64;\r\ntypedef unsigned long UInt64;\r\n\r\n#else\r\n\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef __int64 Int64;\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef long long int Int64;\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\ntypedef size_t SizeT;\r\n#endif\r\n\r\ntypedef int Bool;\r\n#define True 1\r\n#define False 0\r\n\r\n\r\n#ifdef _MSC_VER\r\n\r\n#if _MSC_VER >= 1300\r\n#define MY_NO_INLINE __declspec(noinline)\r\n#else\r\n#define MY_NO_INLINE\r\n#endif\r\n\r\n#define MY_CDECL __cdecl\r\n#define MY_STD_CALL __stdcall\r\n#define MY_FAST_CALL MY_NO_INLINE __fastcall\r\n\r\n#else\r\n\r\n#define MY_CDECL\r\n#define MY_STD_CALL\r\n#define MY_FAST_CALL\r\n\r\n#endif\r\n\r\n\r\n/* The following interfaces use first parameter as pointer to structure */\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) < input(*size)) is allowed */\r\n} ISeqInStream;\r\n\r\n/* it can return SZ_ERROR_INPUT_EOF */\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r\n\r\ntypedef struct\r\n{\r\n  size_t (*Write)(void *p, const void *buf, size_t size);\r\n    /* Returns: result - the number of actually written bytes.\r\n       (result < size) means error */\r\n} ISeqOutStream;\r\n\r\ntypedef enum\r\n{\r\n  SZ_SEEK_SET = 0,\r\n  SZ_SEEK_CUR = 1,\r\n  SZ_SEEK_END = 2\r\n} ESzSeek;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ISeekInStream;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Look)(void *p, void **buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) > input(*size)) is not allowed\r\n       (output(*size) < input(*size)) is allowed */\r\n  SRes (*Skip)(void *p, size_t offset);\r\n    /* offset must be <= output(*size) of Look */\r\n\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ILookInStream;\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r\n\r\n/* reads via ILookInStream::Read */\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r\n\r\n#define LookToRead_BUF_SIZE (1 << 14)\r\n\r\ntypedef struct\r\n{\r\n  ILookInStream s;\r\n  ISeekInStream *realStream;\r\n  size_t pos;\r\n  size_t size;\r\n  Byte buf[LookToRead_BUF_SIZE];\r\n} CLookToRead;\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r\nvoid LookToRead_Init(CLookToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToLook;\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToRead;\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r\n    /* Returns: result. (result != SZ_OK) means break.\r\n       Value (UInt64)(Int64)-1 for size means unknown value. */\r\n} ICompressProgress;\r\n\r\ntypedef struct\r\n{\r\n  void *(*Alloc)(void *p, size_t size);\r\n  void (*Free)(void *p, void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\n#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r\n#define IAlloc_Free(p, a) (p)->Free((p), a)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zCompressionMode.cpp",
    "content": "// CompressionMethod.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zCompressionMode.h",
    "content": "// 7zCompressionMode.h\r\n\r\n#ifndef __7Z_COMPRESSION_MODE_H\r\n#define __7Z_COMPRESSION_MODE_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CMethodFull: public CMethod\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBind\r\n{\r\n  UInt32 InCoder;\r\n  UInt32 InStream;\r\n  UInt32 OutCoder;\r\n  UInt32 OutStream;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  CObjectVector<CMethodFull> Methods;\r\n  CRecordVector<CBind> Binds;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }\r\n  CCompressionMethodMode(): PasswordIsDefined(false)\r\n      #ifdef COMPRESS_MT\r\n      , NumThreads(1)\r\n      #endif\r\n  {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zDecode.cpp",
    "content": "// 7zDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/LockedStream.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertFolderItemInfoToBindInfo(const CFolder &folder,\r\n    CBindInfoEx &bindInfo)\r\n{\r\n  bindInfo.Clear();\r\n  int i;\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    NCoderMixer::CBindPair bindPair;\r\n    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;\r\n    bindInfo.BindPairs.Add(bindPair);\r\n  }\r\n  UInt32 outStreamIndex = 0;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    const CCoderInfo &coderInfo = folder.Coders[i];\r\n    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;\r\n    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    bindInfo.Coders.Add(coderStreamsInfo);\r\n    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);\r\n    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)\r\n      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)\r\n        bindInfo.OutStreams.Add(outStreamIndex);\r\n  }\r\n  for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);\r\n}\r\n\r\nstatic bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1,\r\n    const NCoderMixer::CCoderStreamsInfo &a2)\r\n{\r\n  return (a1.NumInStreams == a2.NumInStreams) &&\r\n    (a1.NumOutStreams == a2.NumOutStreams);\r\n}\r\n\r\nstatic bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)\r\n{\r\n  return (a1.InIndex == a2.InIndex) &&\r\n    (a1.OutIndex == a2.OutIndex);\r\n}\r\n\r\nstatic bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)\r\n{\r\n  if (a1.Coders.Size() != a2.Coders.Size())\r\n    return false;\r\n  int i;\r\n  for (i = 0; i < a1.Coders.Size(); i++)\r\n    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))\r\n      return false;\r\n  if (a1.BindPairs.Size() != a2.BindPairs.Size())\r\n    return false;\r\n  for (i = 0; i < a1.BindPairs.Size(); i++)\r\n    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))\r\n      return false;\r\n  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)\r\n    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])\r\n      return false;\r\n  if (a1.InStreams.Size() != a2.InStreams.Size())\r\n    return false;\r\n  if (a1.OutStreams.Size() != a2.OutStreams.Size())\r\n    return false;\r\n  return true;\r\n}\r\n\r\nCDecoder::CDecoder(bool multiThread)\r\n{\r\n  #ifndef _ST_MODE\r\n  multiThread = true;\r\n  #endif\r\n  _multiThread = multiThread;\r\n  _bindInfoExPrevIsDefined = false;\r\n}\r\n\r\nHRESULT CDecoder::Decode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    UInt64 startPos,\r\n    const UInt64 *packSizes,\r\n    const CFolder &folderInfo,\r\n    ISequentialOutStream *outStream,\r\n    ICompressProgressInfo *compressProgress\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    #ifdef COMPRESS_MT\r\n    , bool mtMode, UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  if (!folderInfo.CheckStructure())\r\n    return E_NOTIMPL;\r\n  #ifndef _NO_CRYPTO\r\n  passwordIsDefined = false;\r\n  #endif\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;\r\n  \r\n  CLockedInStream lockedInStream;\r\n  lockedInStream.Init(inStream);\r\n  \r\n  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)\r\n  {\r\n    CLockedSequentialInStreamImp *lockedStreamImpSpec = new\r\n        CLockedSequentialInStreamImp;\r\n    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;\r\n    lockedStreamImpSpec->Init(&lockedInStream, startPos);\r\n    startPos += packSizes[j];\r\n    \r\n    CLimitedSequentialInStream *streamSpec = new\r\n        CLimitedSequentialInStream;\r\n    CMyComPtr<ISequentialInStream> inStream = streamSpec;\r\n    streamSpec->SetStream(lockedStreamImp);\r\n    streamSpec->Init(packSizes[j]);\r\n    inStreams.Add(inStream);\r\n  }\r\n  \r\n  int numCoders = folderInfo.Coders.Size();\r\n  \r\n  CBindInfoEx bindInfo;\r\n  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);\r\n  bool createNewCoders;\r\n  if (!_bindInfoExPrevIsDefined)\r\n    createNewCoders = true;\r\n  else\r\n    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);\r\n  if (createNewCoders)\r\n  {\r\n    int i;\r\n    _decoders.Clear();\r\n    // _decoders2.Clear();\r\n    \r\n    _mixerCoder.Release();\r\n\r\n    if (_multiThread)\r\n    {\r\n      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;\r\n      _mixerCoder = _mixerCoderMTSpec;\r\n      _mixerCoderCommon = _mixerCoderMTSpec;\r\n    }\r\n    else\r\n    {\r\n      #ifdef _ST_MODE\r\n      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;\r\n      _mixerCoder = _mixerCoderSTSpec;\r\n      _mixerCoderCommon = _mixerCoderSTSpec;\r\n      #endif\r\n    }\r\n    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));\r\n    \r\n    for (i = 0; i < numCoders; i++)\r\n    {\r\n      const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n\r\n  \r\n      CMyComPtr<ICompressCoder> decoder;\r\n      CMyComPtr<ICompressCoder2> decoder2;\r\n      RINOK(CreateCoder(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          coderInfo.MethodID, decoder, decoder2, false));\r\n      CMyComPtr<IUnknown> decoderUnknown;\r\n      if (coderInfo.IsSimpleCoder())\r\n      {\r\n        if (decoder == 0)\r\n          return E_NOTIMPL;\r\n\r\n        decoderUnknown = (IUnknown *)decoder;\r\n        \r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder(decoder);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder(decoder, false);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        if (decoder2 == 0)\r\n          return E_NOTIMPL;\r\n        decoderUnknown = (IUnknown *)decoder2;\r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder2(decoder2);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder2(decoder2, false);\r\n        #endif\r\n      }\r\n      _decoders.Add(decoderUnknown);\r\n      #ifdef EXTERNAL_CODECS\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n      }\r\n      #endif\r\n    }\r\n    _bindInfoExPrev = bindInfo;\r\n    _bindInfoExPrevIsDefined = true;\r\n  }\r\n  int i;\r\n  _mixerCoderCommon->ReInit();\r\n  \r\n  UInt32 packStreamIndex = 0, unpackStreamIndex = 0;\r\n  UInt32 coderIndex = 0;\r\n  // UInt32 coder2Index = 0;\r\n  \r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];\r\n    \r\n    {\r\n      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n      if (setDecoderProperties)\r\n      {\r\n        const CByteBuffer &props = coderInfo.Props;\r\n        size_t size = props.GetCapacity();\r\n        if (size > 0xFFFFFFFF)\r\n          return E_NOTIMPL;\r\n        if (size > 0)\r\n        {\r\n          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)props, (UInt32)size));\r\n        }\r\n      }\r\n    }\r\n\r\n    #ifdef COMPRESS_MT\r\n    if (mtMode)\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(numThreads));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    {\r\n      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n      if (cryptoSetPassword)\r\n      {\r\n        if (getTextPassword == 0)\r\n          return E_FAIL;\r\n        CMyComBSTR passwordBSTR;\r\n        RINOK(getTextPassword->CryptoGetTextPassword(&passwordBSTR));\r\n        CByteBuffer buffer;\r\n        passwordIsDefined = true;\r\n        const UString password(passwordBSTR);\r\n        const UInt32 sizeInBytes = password.Length() * 2;\r\n        buffer.SetCapacity(sizeInBytes);\r\n        for (int i = 0; i < password.Length(); i++)\r\n        {\r\n          wchar_t c = password[i];\r\n          ((Byte *)buffer)[i * 2] = (Byte)c;\r\n          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n        }\r\n        RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    coderIndex++;\r\n    \r\n    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;\r\n    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    CRecordVector<const UInt64 *> packSizesPointers;\r\n    CRecordVector<const UInt64 *> unpackSizesPointers;\r\n    packSizesPointers.Reserve(numInStreams);\r\n    unpackSizesPointers.Reserve(numOutStreams);\r\n    UInt32 j;\r\n    for (j = 0; j < numOutStreams; j++, unpackStreamIndex++)\r\n      unpackSizesPointers.Add(&folderInfo.UnpackSizes[unpackStreamIndex]);\r\n    \r\n    for (j = 0; j < numInStreams; j++, packStreamIndex++)\r\n    {\r\n      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);\r\n      if (bindPairIndex >= 0)\r\n        packSizesPointers.Add(\r\n        &folderInfo.UnpackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);\r\n      else\r\n      {\r\n        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);\r\n        if (index < 0)\r\n          return E_FAIL;\r\n        packSizesPointers.Add(&packSizes[index]);\r\n      }\r\n    }\r\n    \r\n    _mixerCoderCommon->SetCoderInfo(i,\r\n        &packSizesPointers.Front(),\r\n        &unpackSizesPointers.Front());\r\n  }\r\n  UInt32 mainCoder, temp;\r\n  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);\r\n\r\n  if (_multiThread)\r\n    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);\r\n  /*\r\n  else\r\n    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;\r\n  */\r\n  \r\n  if (numCoders == 0)\r\n    return 0;\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  inStreamPointers.Reserve(inStreams.Size());\r\n  for (i = 0; i < inStreams.Size(); i++)\r\n    inStreamPointers.Add(inStreams[i]);\r\n  ISequentialOutStream *outStreamPointer = outStream;\r\n  return _mixerCoder->Code(&inStreamPointers.Front(), NULL,\r\n    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zDecode.h",
    "content": "// 7zDecode.h\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"7zItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CBindInfoEx: public NCoderMixer::CBindInfo\r\n{\r\n  CRecordVector<CMethodId> CoderMethodIDs;\r\n  void Clear()\r\n  {\r\n    CBindInfo::Clear();\r\n    CoderMethodIDs.Clear();\r\n  }\r\n};\r\n\r\nclass CDecoder\r\n{\r\n  bool _bindInfoExPrevIsDefined;\r\n  CBindInfoEx _bindInfoExPrev;\r\n  \r\n  bool _multiThread;\r\n  #ifdef _ST_MODE\r\n  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;\r\n  #endif\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;\r\n  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;\r\n  \r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n  CObjectVector<CMyComPtr<IUnknown> > _decoders;\r\n  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;\r\npublic:\r\n  CDecoder(bool multiThread);\r\n  HRESULT Decode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      IInStream *inStream,\r\n      UInt64 startPos,\r\n      const UInt64 *packSizes,\r\n      const CFolder &folder,\r\n      ISequentialOutStream *outStream,\r\n      ICompressProgressInfo *compressProgress\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , bool mtMode, UInt32 numThreads\r\n      #endif\r\n      );\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zEncode.cpp",
    "content": "// Encode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zSpecStream.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/InOutTempBuffer.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nstatic const UInt64 k_AES = 0x06F10701;\r\nstatic const UInt64 k_BCJ  = 0x03030103;\r\nstatic const UInt64 k_BCJ2 = 0x0303011B;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,\r\n    const CRecordVector<CMethodId> decompressionMethods,\r\n    CFolder &folder)\r\n{\r\n  folder.Coders.Clear();\r\n  // bindInfo.CoderMethodIDs.Clear();\r\n  // folder.OutStreams.Clear();\r\n  folder.PackStreams.Clear();\r\n  folder.BindPairs.Clear();\r\n  int i;\r\n  for (i = 0; i < bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = bindInfo.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = bindInfo.BindPairs[i].OutIndex;\r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n  for (i = 0; i < bindInfo.Coders.Size(); i++)\r\n  {\r\n    CCoderInfo coderInfo;\r\n    const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];\r\n    coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;\r\n    coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;\r\n    coderInfo.MethodID = decompressionMethods[i];\r\n    folder.Coders.Add(coderInfo);\r\n  }\r\n  for (i = 0; i < bindInfo.InStreams.Size(); i++)\r\n    folder.PackStreams.Add(bindInfo.InStreams[i]);\r\n}\r\n\r\nHRESULT CEncoder::CreateMixerCoder(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const UInt64 *inSizeForReduce)\r\n{\r\n  _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;\r\n  _mixerCoder = _mixerCoderSpec;\r\n  RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));\r\n  for (int i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _codersInfo.Add(CCoderInfo());\r\n    CCoderInfo &encodingInfo = _codersInfo.Back();\r\n    encodingInfo.MethodID = methodFull.Id;\r\n    CMyComPtr<ICompressCoder> encoder;\r\n    CMyComPtr<ICompressCoder2> encoder2;\r\n    \r\n\r\n    RINOK(CreateCoder(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        methodFull.Id, encoder, encoder2, true));\r\n\r\n    if (!encoder && !encoder2)\r\n      return E_FAIL;\r\n\r\n    CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;\r\n   \r\n    #ifdef COMPRESS_MT\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));\r\n      }\r\n    }\r\n    #endif\r\n        \r\n\r\n    RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon));\r\n\r\n    /*\r\n    CMyComPtr<ICryptoResetSalt> resetSalt;\r\n    encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);\r\n    if (resetSalt != NULL)\r\n    {\r\n      resetSalt->ResetSalt();\r\n    }\r\n    */\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n    encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n    if (setCompressCodecsInfo)\r\n    {\r\n      RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n    }\r\n    #endif\r\n    \r\n    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n    encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n\r\n    if (cryptoSetPassword)\r\n    {\r\n      CByteBuffer buffer;\r\n      const UInt32 sizeInBytes = _options.Password.Length() * 2;\r\n      buffer.SetCapacity(sizeInBytes);\r\n      for (int i = 0; i < _options.Password.Length(); i++)\r\n      {\r\n        wchar_t c = _options.Password[i];\r\n        ((Byte *)buffer)[i * 2] = (Byte)c;\r\n        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n      }\r\n      RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n    }\r\n\r\n    if (encoder)\r\n      _mixerCoderSpec->AddCoder(encoder);\r\n    else\r\n      _mixerCoderSpec->AddCoder2(encoder2);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Encode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    ISequentialInStream *inStream,\r\n    const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n    CFolder &folderItem,\r\n    ISequentialOutStream *outStream,\r\n    CRecordVector<UInt64> &packSizes,\r\n    ICompressProgressInfo *compressProgress)\r\n{\r\n  RINOK(EncoderConstr());\r\n\r\n  if (_mixerCoderSpec == NULL)\r\n  {\r\n    RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));\r\n  }\r\n  _mixerCoderSpec->ReInit();\r\n  // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);\r\n\r\n  CObjectVector<CInOutTempBuffer> inOutTempBuffers;\r\n  CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;\r\n  CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;\r\n  int numMethods = _bindInfo.Coders.Size();\r\n  int i;\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    inOutTempBuffers.Add(CInOutTempBuffer());\r\n    inOutTempBuffers.Back().Create();\r\n    inOutTempBuffers.Back().InitWriting();\r\n  }\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CSequentialOutTempBufferImp *tempBufferSpec =\r\n        new CSequentialOutTempBufferImp;\r\n    CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;\r\n    tempBufferSpec->Init(&inOutTempBuffers[i - 1]);\r\n    tempBuffers.Add(tempBuffer);\r\n    tempBufferSpecs.Add(tempBufferSpec);\r\n  }\r\n\r\n  for (i = 0; i < numMethods; i++)\r\n    _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    return E_FAIL;\r\n  UInt32 mainCoderIndex, mainStreamIndex;\r\n  _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);\r\n  \r\n  if (inStreamSize != NULL)\r\n  {\r\n    CRecordVector<const UInt64 *> sizePointers;\r\n    for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)\r\n      if (i == mainStreamIndex)\r\n        sizePointers.Add(inStreamSize);\r\n      else\r\n        sizePointers.Add(NULL);\r\n    _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);\r\n  }\r\n\r\n  \r\n  // UInt64 outStreamStartPos;\r\n  // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));\r\n  \r\n  CSequentialInStreamSizeCount2 *inStreamSizeCountSpec =\r\n      new CSequentialInStreamSizeCount2;\r\n  CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;\r\n  CSequentialOutStreamSizeCount *outStreamSizeCountSpec =\r\n      new CSequentialOutStreamSizeCount;\r\n  CMyComPtr<ISequentialOutStream> outStreamSizeCount = outStreamSizeCountSpec;\r\n\r\n  inStreamSizeCountSpec->Init(inStream);\r\n  outStreamSizeCountSpec->SetStream(outStream);\r\n  outStreamSizeCountSpec->Init();\r\n\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  CRecordVector<ISequentialOutStream *> outStreamPointers;\r\n  inStreamPointers.Add(inStreamSizeCount);\r\n  outStreamPointers.Add(outStreamSizeCount);\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n    outStreamPointers.Add(tempBuffers[i - 1]);\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    CCoderInfo &encodingInfo = _codersInfo[i];\r\n    \r\n    CMyComPtr<ICryptoResetInitVector> resetInitVector;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);\r\n    if (resetInitVector != NULL)\r\n    {\r\n      resetInitVector->ResetInitVector();\r\n    }\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n    if (writeCoderProperties != NULL)\r\n    {\r\n      CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n      outStreamSpec->Init();\r\n      writeCoderProperties->WriteCoderProperties(outStream);\r\n      size_t size = outStreamSpec->GetSize();\r\n      encodingInfo.Props.SetCapacity(size);\r\n      memmove(encodingInfo.Props, outStreamSpec->GetBuffer(), size);\r\n    }\r\n  }\r\n\r\n  UInt32 progressIndex = mainCoderIndex;\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    const CCoderInfo &e = _codersInfo[i];\r\n    if ((e.MethodID == k_BCJ || e.MethodID == k_BCJ2) && i + 1 < _codersInfo.Size())\r\n      progressIndex = i + 1;\r\n  }\r\n\r\n  _mixerCoderSpec->SetProgressCoderIndex(progressIndex);\r\n  \r\n  RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,\r\n    &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));\r\n  \r\n  ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods,\r\n      folderItem);\r\n  \r\n  packSizes.Add(outStreamSizeCountSpec->GetSize());\r\n  \r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];\r\n    inOutTempBuffer.FlushWrite();\r\n    inOutTempBuffer.InitReading();\r\n    inOutTempBuffer.WriteToStream(outStream);\r\n    packSizes.Add(inOutTempBuffer.GetDataSize());\r\n  }\r\n  \r\n  for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)\r\n  {\r\n    int binder = _bindInfo.FindBinderForInStream(\r\n        _bindReverseConverter->DestOutToSrcInMap[i]);\r\n    UInt64 streamSize;\r\n    if (binder < 0)\r\n      streamSize = inStreamSizeCountSpec->GetSize();\r\n    else\r\n      streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);\r\n    folderItem.UnpackSizes.Add(streamSize);\r\n  }\r\n  for (i = numMethods - 1; i >= 0; i--)\r\n    folderItem.Coders[numMethods - 1 - i].Props = _codersInfo[i].Props;\r\n  return S_OK;\r\n}\r\n\r\n\r\nCEncoder::CEncoder(const CCompressionMethodMode &options):\r\n  _bindReverseConverter(0),\r\n  _constructed(false)\r\n{\r\n  if (options.IsEmpty())\r\n    throw 1;\r\n\r\n  _options = options;\r\n  _mixerCoderSpec = NULL;\r\n}\r\n\r\nHRESULT CEncoder::EncoderConstr()\r\n{\r\n  if (_constructed)\r\n    return S_OK;\r\n  if (_options.Methods.IsEmpty())\r\n  {\r\n    // it has only password method;\r\n    if (!_options.PasswordIsDefined)\r\n      throw 1;\r\n    if (!_options.Binds.IsEmpty())\r\n      throw 1;\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    CMethodFull method;\r\n    \r\n    method.NumInStreams = 1;\r\n    method.NumOutStreams = 1;\r\n    coderStreamsInfo.NumInStreams = 1;\r\n    coderStreamsInfo.NumOutStreams = 1;\r\n    method.Id = k_AES;\r\n    \r\n    _options.Methods.Add(method);\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  \r\n    _bindInfo.InStreams.Add(0);\r\n    _bindInfo.OutStreams.Add(0);\r\n  }\r\n  else\r\n  {\r\n\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  int i;\r\n  for (i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;\r\n    coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;\r\n    if (_options.Binds.IsEmpty())\r\n    {\r\n      if (i < _options.Methods.Size() - 1)\r\n      {\r\n        NCoderMixer::CBindPair bindPair;\r\n        bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;\r\n        bindPair.OutIndex = numOutStreams;\r\n        _bindInfo.BindPairs.Add(bindPair);\r\n      }\r\n      else\r\n        _bindInfo.OutStreams.Insert(0, numOutStreams);\r\n      for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)\r\n        _bindInfo.OutStreams.Add(numOutStreams + j);\r\n    }\r\n    \r\n    numInStreams += coderStreamsInfo.NumInStreams;\r\n    numOutStreams += coderStreamsInfo.NumOutStreams;\r\n\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  }\r\n\r\n  if (!_options.Binds.IsEmpty())\r\n  {\r\n    for (i = 0; i < _options.Binds.Size(); i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      const CBind &bind = _options.Binds[i];\r\n      bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;\r\n      bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    for (i = 0; i < (int)numOutStreams; i++)\r\n      if (_bindInfo.FindBinderForOutStream(i) == -1)\r\n        _bindInfo.OutStreams.Add(i);\r\n  }\r\n\r\n  for (i = 0; i < (int)numInStreams; i++)\r\n    if (_bindInfo.FindBinderForInStream(i) == -1)\r\n      _bindInfo.InStreams.Add(i);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    throw 1; // this is error\r\n\r\n  // Make main stream first in list\r\n  int inIndex = _bindInfo.InStreams[0];\r\n  for (;;)\r\n  {\r\n    UInt32 coderIndex, coderStreamIndex;\r\n    _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);\r\n    UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);\r\n    int binder = _bindInfo.FindBinderForOutStream(outIndex);\r\n    if (binder >= 0)\r\n    {\r\n      inIndex = _bindInfo.BindPairs[binder].InIndex;\r\n      continue;\r\n    }\r\n    for (i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n      if (_bindInfo.OutStreams[i] == outIndex)\r\n      {\r\n        _bindInfo.OutStreams.Delete(i);\r\n        _bindInfo.OutStreams.Insert(0, outIndex);\r\n        break;\r\n      }\r\n    break;\r\n  }\r\n\r\n  if (_options.PasswordIsDefined)\r\n  {\r\n    int numCryptoStreams = _bindInfo.OutStreams.Size();\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      bindPair.InIndex = numInStreams + i;\r\n      bindPair.OutIndex = _bindInfo.OutStreams[i];\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    _bindInfo.OutStreams.Clear();\r\n\r\n    /*\r\n    if (numCryptoStreams == 0)\r\n      numCryptoStreams = 1;\r\n    */\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n      CMethodFull method;\r\n      method.NumInStreams = 1;\r\n      method.NumOutStreams = 1;\r\n      coderStreamsInfo.NumInStreams = method.NumOutStreams;\r\n      coderStreamsInfo.NumOutStreams = method.NumInStreams;\r\n      method.Id = k_AES;\r\n\r\n      _options.Methods.Add(method);\r\n      _bindInfo.Coders.Add(coderStreamsInfo);\r\n      _bindInfo.OutStreams.Add(numOutStreams + i);\r\n    }\r\n  }\r\n\r\n  }\r\n\r\n  for (int i = _options.Methods.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _decompressionMethods.Add(methodFull.Id);\r\n  }\r\n\r\n  _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);\r\n  _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);\r\n  _constructed = true;\r\n  return S_OK;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  delete _bindReverseConverter;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zEncode.h",
    "content": "// 7zEncode.h\r\n\r\n#ifndef __7Z_ENCODE_H\r\n#define __7Z_ENCODE_H\r\n\r\n// #include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n#include \"7zItem.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CEncoder\r\n{\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;\r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n\r\n  CObjectVector<CCoderInfo> _codersInfo;\r\n\r\n  CCompressionMethodMode _options;\r\n  NCoderMixer::CBindInfo _bindInfo;\r\n  NCoderMixer::CBindInfo _decompressBindInfo;\r\n  NCoderMixer::CBindReverseConverter *_bindReverseConverter;\r\n  CRecordVector<CMethodId> _decompressionMethods;\r\n\r\n  HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const UInt64 *inSizeForReduce);\r\n\r\n  bool _constructed;\r\npublic:\r\n  CEncoder(const CCompressionMethodMode &options);\r\n  ~CEncoder();\r\n  HRESULT EncoderConstr();\r\n  HRESULT Encode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      ISequentialInStream *inStream,\r\n      const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n      CFolder &folderItem,\r\n      ISequentialOutStream *outStream,\r\n      CRecordVector<UInt64> &packSizes,\r\n      ICompressProgressInfo *compressProgress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zExtract.cpp",
    "content": "// 7zExtract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zFolderOutStream.h\"\r\n#include \"7zDecode.h\"\r\n// #include \"7z1Decode.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CExtractFolderInfo\r\n{\r\n  #ifdef _7Z_VOL\r\n  int VolumeIndex;\r\n  #endif\r\n  CNum FileIndex;\r\n  CNum FolderIndex;\r\n  CBoolVector ExtractStatuses;\r\n  UInt64 UnpackSize;\r\n  CExtractFolderInfo(\r\n    #ifdef _7Z_VOL\r\n    int volumeIndex,\r\n    #endif\r\n    CNum fileIndex, CNum folderIndex):\r\n    #ifdef _7Z_VOL\r\n    VolumeIndex(volumeIndex),\r\n    #endif\r\n    FileIndex(fileIndex),\r\n    FolderIndex(folderIndex),\r\n    UnpackSize(0)\r\n  {\r\n    if (fileIndex != kNumNoIndex)\r\n    {\r\n      ExtractStatuses.Reserve(1);\r\n      ExtractStatuses.Add(true);\r\n    }\r\n  };\r\n};\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool testMode = (testModeSpec != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;\r\n  UInt64 importantTotalUnpacked = 0;\r\n\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (allFilesMode)\r\n    numItems =\r\n    #ifdef _7Z_VOL\r\n    _refs.Size();\r\n    #else\r\n    _db.Files.Size();\r\n    #endif\r\n\r\n  if(numItems == 0)\r\n    return S_OK;\r\n\r\n  /*\r\n  if(_volumes.Size() != 1)\r\n    return E_FAIL;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_db = volume.Database;\r\n  IInStream *_inStream = volume.Stream;\r\n  */\r\n  \r\n  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;\r\n  for(UInt32 ii = 0; ii < numItems; ii++)\r\n  {\r\n    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];\r\n    UInt32 ref2Index = allFilesMode ? ii : indices[ii];\r\n    // const CRef2 &ref2 = _refs[ref2Index];\r\n\r\n    // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)\r\n    {\r\n      #ifdef _7Z_VOL\r\n      // const CRef &ref = ref2.Refs[ri];\r\n      const CRef &ref = _refs[ref2Index];\r\n\r\n      int volumeIndex = ref.VolumeIndex;\r\n      const CVolume &volume = _volumes[volumeIndex];\r\n      const CArchiveDatabaseEx &db = volume.Database;\r\n      UInt32 fileIndex = ref.ItemIndex;\r\n      #else\r\n      const CArchiveDatabaseEx &db = _db;\r\n      UInt32 fileIndex = ref2Index;\r\n      #endif\r\n\r\n      CNum folderIndex = db.FileIndexToFolderIndexMap[fileIndex];\r\n      if (folderIndex == kNumNoIndex)\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex,\r\n            #endif\r\n            fileIndex, kNumNoIndex));\r\n        continue;\r\n      }\r\n      if (extractFolderInfoVector.IsEmpty() ||\r\n        folderIndex != extractFolderInfoVector.Back().FolderIndex\r\n        #ifdef _7Z_VOL\r\n        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex\r\n        #endif\r\n        )\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex,\r\n            #endif\r\n            kNumNoIndex, folderIndex));\r\n        const CFolder &folderInfo = db.Folders[folderIndex];\r\n        UInt64 unpackSize = folderInfo.GetUnpackSize();\r\n        importantTotalUnpacked += unpackSize;\r\n        extractFolderInfoVector.Back().UnpackSize = unpackSize;\r\n      }\r\n      \r\n      CExtractFolderInfo &efi = extractFolderInfoVector.Back();\r\n      \r\n      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];\r\n      CNum startIndex = db.FolderStartFileIndex[folderIndex];\r\n      for (CNum index = efi.ExtractStatuses.Size();\r\n          index <= fileIndex - startIndex; index++)\r\n      {\r\n        // UInt64 unpackSize = _db.Files[startIndex + index].UnpackSize;\r\n        // Count partial_folder_size\r\n        // efi.UnpackSize += unpackSize;\r\n        // importantTotalUnpacked += unpackSize;\r\n        efi.ExtractStatuses.Add(index == fileIndex - startIndex);\r\n      }\r\n    }\r\n  }\r\n\r\n  extractCallback->SetTotal(importantTotalUnpacked);\r\n\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  // CDecoder1 decoder;\r\n\r\n  UInt64 currentTotalPacked = 0;\r\n  UInt64 currentTotalUnpacked = 0;\r\n  UInt64 totalFolderUnpacked;\r\n  UInt64 totalFolderPacked;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for(int i = 0; i < extractFolderInfoVector.Size(); i++,\r\n      currentTotalUnpacked += totalFolderUnpacked,\r\n      currentTotalPacked += totalFolderPacked)\r\n  {\r\n    lps->OutSize = currentTotalUnpacked;\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    const CExtractFolderInfo &efi = extractFolderInfoVector[i];\r\n    totalFolderUnpacked = efi.UnpackSize;\r\n\r\n    totalFolderPacked = 0;\r\n\r\n    CFolderOutStream *folderOutStream = new CFolderOutStream;\r\n    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);\r\n\r\n    #ifdef _7Z_VOL\r\n    const CVolume &volume = _volumes[efi.VolumeIndex];\r\n    const CArchiveDatabaseEx &db = volume.Database;\r\n    #else\r\n    const CArchiveDatabaseEx &db = _db;\r\n    #endif\r\n\r\n    CNum startIndex;\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      startIndex = efi.FileIndex;\r\n    else\r\n      startIndex = db.FolderStartFileIndex[efi.FolderIndex];\r\n\r\n\r\n    HRESULT result = folderOutStream->Init(&db,\r\n        #ifdef _7Z_VOL\r\n        volume.StartRef2Index,\r\n        #else\r\n        0,\r\n        #endif\r\n        startIndex,\r\n        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);\r\n\r\n    RINOK(result);\r\n\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      continue;\r\n\r\n    CNum folderIndex = efi.FolderIndex;\r\n    const CFolder &folderInfo = db.Folders[folderIndex];\r\n\r\n    totalFolderPacked = _db.GetFolderFullPackSize(folderIndex);\r\n\r\n    CNum packStreamIndex = db.FolderStartPackStreamIndex[folderIndex];\r\n    UInt64 folderStartPackPos = db.GetFolderStreamPos(folderIndex, 0);\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (extractCallback)\r\n      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    #endif\r\n\r\n    try\r\n    {\r\n      #ifndef _NO_CRYPTO\r\n      bool passwordIsDefined;\r\n      #endif\r\n\r\n      HRESULT result = decoder.Decode(\r\n          EXTERNAL_CODECS_VARS\r\n          #ifdef _7Z_VOL\r\n          volume.Stream,\r\n          #else\r\n          _inStream,\r\n          #endif\r\n          folderStartPackPos,\r\n          &db.PackSizes[packStreamIndex],\r\n          folderInfo,\r\n          outStream,\r\n          progress\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword, passwordIsDefined\r\n          #endif\r\n          #ifdef COMPRESS_MT\r\n          , true, _numThreads\r\n          #endif\r\n          );\r\n\r\n      if (result == S_FALSE)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));\r\n        continue;\r\n      }\r\n      if (result != S_OK)\r\n        return result;\r\n      if (folderOutStream->WasWritingFinished() != S_OK)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n      continue;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zFolderInStream.cpp",
    "content": "// 7zFolderInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderInStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderInStream::CFolderInStream()\r\n{\r\n  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;\r\n  _inStreamWithHash = _inStreamWithHashSpec;\r\n}\r\n\r\nvoid CFolderInStream::Init(IArchiveUpdateCallback *updateCallback,\r\n    const UInt32 *fileIndices, UInt32 numFiles)\r\n{\r\n  _updateCallback = updateCallback;\r\n  _numFiles = numFiles;\r\n  _fileIndex = 0;\r\n  _fileIndices = fileIndices;\r\n  Processed.Clear();\r\n  CRCs.Clear();\r\n  Sizes.Clear();\r\n  _fileIsOpen = false;\r\n  _currentSizeIsDefined = false;\r\n}\r\n\r\nHRESULT CFolderInStream::OpenStream()\r\n{\r\n  _filePos = 0;\r\n  while (_fileIndex < _numFiles)\r\n  {\r\n    _currentSizeIsDefined = false;\r\n    CMyComPtr<ISequentialInStream> stream;\r\n    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);\r\n    if (result != S_OK && result != S_FALSE)\r\n      return result;\r\n    _fileIndex++;\r\n    _inStreamWithHashSpec->SetStream(stream);\r\n    _inStreamWithHashSpec->Init();\r\n    if (!stream)\r\n    {\r\n      RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n      Sizes.Add(0);\r\n      Processed.Add(result == S_OK);\r\n      AddDigest();\r\n      continue;\r\n    }\r\n    CMyComPtr<IStreamGetSize> streamGetSize;\r\n    if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)\r\n    {\r\n      if(streamGetSize)\r\n      {\r\n        _currentSizeIsDefined = true;\r\n        RINOK(streamGetSize->GetSize(&_currentSize));\r\n      }\r\n    }\r\n\r\n    _fileIsOpen = true;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFolderInStream::AddDigest()\r\n{\r\n  CRCs.Add(_inStreamWithHashSpec->GetCRC());\r\n}\r\n\r\nHRESULT CFolderInStream::CloseStream()\r\n{\r\n  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n  _inStreamWithHashSpec->ReleaseStream();\r\n  _fileIsOpen = false;\r\n  Processed.Add(true);\r\n  Sizes.Add(_filePos);\r\n  AddDigest();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 localProcessedSize;\r\n      RINOK(_inStreamWithHash->Read(\r\n          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));\r\n      if (localProcessedSize == 0)\r\n      {\r\n        RINOK(CloseStream());\r\n        continue;\r\n      }\r\n      realProcessedSize += localProcessedSize;\r\n      _filePos += localProcessedSize;\r\n      size -= localProcessedSize;\r\n      break;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenStream());\r\n    }\r\n  }\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)\r\n{\r\n  *value = 0;\r\n  int subStreamIndex = (int)subStream;\r\n  if (subStreamIndex < 0 || subStream > Sizes.Size())\r\n    return E_FAIL;\r\n  if (subStreamIndex < Sizes.Size())\r\n  {\r\n    *value= Sizes[subStreamIndex];\r\n    return S_OK;\r\n  }\r\n  if (!_currentSizeIsDefined)\r\n    return S_FALSE;\r\n  *value = _currentSize;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zFolderInStream.h",
    "content": "// 7z/FolderInStream.h\r\n\r\n#ifndef __7Z_FOLDERINSTREAM_H\r\n#define __7Z_FOLDERINSTREAM_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zHeader.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../Common/InStreamWithCRC.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderInStream:\r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  CFolderInStream();\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\nprivate:\r\n  CSequentialInStreamWithCRC *_inStreamWithHashSpec;\r\n  CMyComPtr<ISequentialInStream> _inStreamWithHash;\r\n  CMyComPtr<IArchiveUpdateCallback> _updateCallback;\r\n\r\n  bool _currentSizeIsDefined;\r\n  UInt64 _currentSize;\r\n\r\n  bool _fileIsOpen;\r\n  UInt64 _filePos;\r\n\r\n  const UInt32 *_fileIndices;\r\n  UInt32 _numFiles;\r\n  UInt32 _fileIndex;\r\n\r\n  HRESULT OpenStream();\r\n  HRESULT CloseStream();\r\n  void AddDigest();\r\npublic:\r\n  void Init(IArchiveUpdateCallback *updateCallback,\r\n      const UInt32 *fileIndices, UInt32 numFiles);\r\n  CRecordVector<bool> Processed;\r\n  CRecordVector<UInt32> CRCs;\r\n  CRecordVector<UInt64> Sizes;\r\n  UInt64 GetFullSize() const\r\n  {\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < Sizes.Size(); i++)\r\n      size += Sizes[i];\r\n    return size;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zFolderOutStream.cpp",
    "content": "// 7zFolderOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderOutStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderOutStream::CFolderOutStream()\r\n{\r\n  _outStreamWithHashSpec = new COutStreamWithCRC;\r\n  _outStreamWithHash = _outStreamWithHashSpec;\r\n}\r\n\r\nHRESULT CFolderOutStream::Init(\r\n    const CArchiveDatabaseEx *archiveDatabase,\r\n    UInt32 ref2Offset,\r\n    UInt32 startIndex,\r\n    const CBoolVector *extractStatuses,\r\n    IArchiveExtractCallback *extractCallback,\r\n    bool testMode,\r\n    bool checkCrc)\r\n{\r\n  _archiveDatabase = archiveDatabase;\r\n  _ref2Offset = ref2Offset;\r\n  _startIndex = startIndex;\r\n\r\n  _extractStatuses = extractStatuses;\r\n  _extractCallback = extractCallback;\r\n  _testMode = testMode;\r\n\r\n  _checkCrc = checkCrc;\r\n\r\n  _currentIndex = 0;\r\n  _fileIsOpen = false;\r\n  return WriteEmptyFiles();\r\n}\r\n\r\nHRESULT CFolderOutStream::OpenFile()\r\n{\r\n  Int32 askMode;\r\n  if((*_extractStatuses)[_currentIndex])\r\n    askMode = _testMode ?\r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n  else\r\n    askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n\r\n  UInt32 index = _startIndex + _currentIndex;\r\n  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));\r\n\r\n  _outStreamWithHashSpec->SetStream(realOutStream);\r\n  _outStreamWithHashSpec->Init(_checkCrc);\r\n  if (askMode == NArchive::NExtract::NAskMode::kExtract &&\r\n      (!realOutStream))\r\n  {\r\n    const CFileItem &fi = _archiveDatabase->Files[index];\r\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir)\r\n      askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  }\r\n  return _extractCallback->PrepareOperation(askMode);\r\n}\r\n\r\nHRESULT CFolderOutStream::WriteEmptyFiles()\r\n{\r\n  for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)\r\n  {\r\n    UInt32 index = _startIndex + _currentIndex;\r\n    const CFileItem &fi = _archiveDatabase->Files[index];\r\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir && fi.Size != 0)\r\n      return S_OK;\r\n    RINOK(OpenFile());\r\n    RINOK(_extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\r\n    _outStreamWithHashSpec->ReleaseStream();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderOutStream::Write(const void *data,\r\n    UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 index = _startIndex + _currentIndex;\r\n      const CFileItem &fi = _archiveDatabase->Files[index];\r\n      UInt64 fileSize = fi.Size;\r\n      \r\n      UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos,\r\n          UInt64(size - realProcessedSize));\r\n      \r\n      UInt32 processedSizeLocal;\r\n      RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize,\r\n            numBytesToWrite, &processedSizeLocal));\r\n\r\n      _filePos += processedSizeLocal;\r\n      realProcessedSize += processedSizeLocal;\r\n      if (_filePos == fileSize)\r\n      {\r\n        bool digestsAreEqual;\r\n        if (fi.CrcDefined && _checkCrc)\r\n          digestsAreEqual = fi.Crc == _outStreamWithHashSpec->GetCRC();\r\n        else\r\n          digestsAreEqual = true;\r\n\r\n        RINOK(_extractCallback->SetOperationResult(\r\n            digestsAreEqual ?\r\n            NArchive::NExtract::NOperationResult::kOK :\r\n            NArchive::NExtract::NOperationResult::kCRCError));\r\n        _outStreamWithHashSpec->ReleaseStream();\r\n        _fileIsOpen = false;\r\n        _currentIndex++;\r\n      }\r\n      if (realProcessedSize == size)\r\n      {\r\n        if (processedSize != NULL)\r\n          *processedSize = realProcessedSize;\r\n        return WriteEmptyFiles();\r\n      }\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n      _filePos = 0;\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)\r\n{\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      RINOK(_extractCallback->SetOperationResult(resultEOperationResult));\r\n      _outStreamWithHashSpec->ReleaseStream();\r\n      _fileIsOpen = false;\r\n      _currentIndex++;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::WasWritingFinished()\r\n{\r\n  if (_currentIndex == _extractStatuses->Size())\r\n    return S_OK;\r\n  return E_FAIL;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zFolderOutStream.h",
    "content": "// 7zFolderOutStream.h\r\n\r\n#ifndef __7Z_FOLDEROUTSTREAM_H\r\n#define __7Z_FOLDEROUTSTREAM_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../IArchive.h\"\r\n#include \"../Common/OutStreamWithCRC.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  \r\n  CFolderOutStream();\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n\r\n  COutStreamWithCRC *_outStreamWithHashSpec;\r\n  CMyComPtr<ISequentialOutStream> _outStreamWithHash;\r\n  const CArchiveDatabaseEx *_archiveDatabase;\r\n  const CBoolVector *_extractStatuses;\r\n  UInt32 _startIndex;\r\n  UInt32 _ref2Offset;\r\n  int _currentIndex;\r\n  // UInt64 _currentDataPos;\r\n  CMyComPtr<IArchiveExtractCallback> _extractCallback;\r\n  bool _testMode;\r\n\r\n  bool _fileIsOpen;\r\n\r\n  bool _checkCrc;\r\n  UInt64 _filePos;\r\n\r\n  HRESULT OpenFile();\r\n  HRESULT WriteEmptyFiles();\r\npublic:\r\n  HRESULT Init(\r\n      const CArchiveDatabaseEx *archiveDatabase,\r\n      UInt32 ref2Offset,\r\n      UInt32 startIndex,\r\n      const CBoolVector *extractStatuses,\r\n      IArchiveExtractCallback *extractCallback,\r\n      bool testMode,\r\n      bool checkCrc);\r\n  HRESULT FlushCorrupted(Int32 resultEOperationResult);\r\n  HRESULT WasWritingFinished();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zHandler.cpp",
    "content": "// 7zHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/CpuArch.h\"\r\n}\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zProperties.h\"\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n#include \"../Common/ParseProperties.h\"\r\n#endif\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nextern UString ConvertMethodIdToString(UInt64 id);\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCHandler::CHandler()\r\n{\r\n  _crcSize = 4;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  _passwordIsDefined = false;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  #else\r\n  Init();\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = _db.Files.Size();\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _SFX\r\n\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,\r\n      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\n\r\n#else\r\n\r\nSTATPROPSTG kArcProps[] =\r\n{\r\n  { NULL, kpidMethod, VT_BSTR},\r\n  { NULL, kpidSolid, VT_BOOL},\r\n  { NULL, kpidNumBlocks, VT_UI4},\r\n  { NULL, kpidPhySize, VT_UI8},\r\n  { NULL, kpidHeadersSize, VT_UI8},\r\n  { NULL, kpidOffset, VT_UI8}\r\n};\r\n\r\nSTDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidMethod:\r\n    {\r\n      UString resString;\r\n      CRecordVector<UInt64> ids;\r\n      int i;\r\n      for (i = 0; i < _db.Folders.Size(); i++)\r\n      {\r\n        const CFolder &f = _db.Folders[i];\r\n        for (int j = f.Coders.Size() - 1; j >= 0; j--)\r\n          ids.AddToUniqueSorted(f.Coders[j].MethodID);\r\n      }\r\n\r\n      for (i = 0; i < ids.Size(); i++)\r\n      {\r\n        UInt64 id = ids[i];\r\n        UString methodName;\r\n        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);\r\n        if (methodName.IsEmpty())\r\n          methodName = ConvertMethodIdToString(id);\r\n        if (!resString.IsEmpty())\r\n          resString += L' ';\r\n        resString += methodName;\r\n      }\r\n      prop = resString;\r\n      break;\r\n    }\r\n    case kpidSolid: prop = _db.IsSolid(); break;\r\n    case kpidNumBlocks: prop = (UInt32)_db.Folders.Size(); break;\r\n    case kpidHeadersSize:  prop = _db.HeadersSize; break;\r\n    case kpidPhySize:  prop = _db.PhySize; break;\r\n    case kpidOffset: if (_db.ArchiveInfo.StartPosition != 0) prop = _db.ArchiveInfo.StartPosition; break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nIMP_IInArchive_ArcProps\r\n\r\n#endif\r\n\r\nstatic void SetPropFromUInt64Def(CUInt64DefVector &v, int index, NCOM::CPropVariant &prop)\r\n{\r\n  UInt64 value;\r\n  if (v.GetItem(index, value))\r\n  {\r\n    FILETIME ft;\r\n    ft.dwLowDateTime = (DWORD)value;\r\n    ft.dwHighDateTime = (DWORD)(value >> 32);\r\n    prop = ft;\r\n  }\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString GetStringForSizeValue(UInt32 value)\r\n{\r\n  for (int i = 31; i >= 0; i--)\r\n    if ((UInt32(1) << i) == value)\r\n      return ConvertUInt32ToString(i);\r\n  UString result;\r\n  if (value % (1 << 20) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 20);\r\n    result += L\"m\";\r\n  }\r\n  else if (value % (1 << 10) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 10);\r\n    result += L\"k\";\r\n  }\r\n  else\r\n  {\r\n    result += ConvertUInt32ToString(value);\r\n    result += L\"b\";\r\n  }\r\n  return result;\r\n}\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_PPMD  = 0x030401;\r\n\r\nstatic wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));\r\n}\r\nstatic inline UString GetHex2(Byte value)\r\n{\r\n  UString result;\r\n  result += GetHex((Byte)(value >> 4));\r\n  result += GetHex((Byte)(value & 0xF));\r\n  return result;\r\n}\r\n\r\n#endif\r\n\r\nstatic const UInt64 k_AES  = 0x06F10701;\r\n\r\nbool CHandler::IsEncrypted(UInt32 index2) const\r\n{\r\n  CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n  if (folderIndex != kNumNoIndex)\r\n  {\r\n    const CFolder &folderInfo = _db.Folders[folderIndex];\r\n    for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n      if (folderInfo.Coders[i].MethodID == k_AES)\r\n        return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  \r\n  /*\r\n  const CRef2 &ref2 = _refs[index];\r\n  if (ref2.Refs.IsEmpty())\r\n    return E_FAIL;\r\n  const CRef &ref = ref2.Refs.Front();\r\n  */\r\n  \r\n  const CFileItem &item = _db.Files[index];\r\n  UInt32 index2 = index;\r\n\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n      if (!item.Name.IsEmpty())\r\n        prop = NItemName::GetOSName(item.Name);\r\n      break;\r\n    case kpidIsDir:  prop = item.IsDir; break;\r\n    case kpidSize:\r\n    {\r\n      prop = item.Size;\r\n      // prop = ref2.Size;\r\n      break;\r\n    }\r\n    case kpidPackSize:\r\n    {\r\n      // prop = ref2.PackSize;\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2)\r\n            prop = _db.GetFolderFullPackSize(folderIndex);\r\n          /*\r\n          else\r\n            prop = (UInt64)0;\r\n          */\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    }\r\n    case kpidPosition:  { UInt64 v; if (_db.StartPos.GetItem(index2, v)) prop = v; break; }\r\n    case kpidCTime:  SetPropFromUInt64Def(_db.CTime, index2, prop); break;\r\n    case kpidATime:  SetPropFromUInt64Def(_db.ATime, index2, prop); break;\r\n    case kpidMTime:  SetPropFromUInt64Def(_db.MTime, index2, prop); break;\r\n    case kpidAttrib:  if (item.AttribDefined) prop = item.Attrib; break;\r\n    case kpidCRC:  if (item.CrcDefined) prop = item.Crc; break;\r\n    case kpidEncrypted:  prop = IsEncrypted(index2); break;\r\n    case kpidIsAnti:  prop = _db.IsItemAnti(index2); break;\r\n    #ifndef _SFX\r\n    case kpidMethod:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _db.Folders[folderIndex];\r\n          UString methodsString;\r\n          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n          {\r\n            const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n            if (!methodsString.IsEmpty())\r\n              methodsString += L' ';\r\n\r\n            {\r\n              UString methodName;\r\n              bool methodIsKnown = FindMethod(\r\n                  EXTERNAL_CODECS_VARS\r\n                  coderInfo.MethodID, methodName);\r\n\r\n              if (methodIsKnown)\r\n              {\r\n                methodsString += methodName;\r\n                if (coderInfo.MethodID == k_LZMA)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 5)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_PPMD)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 5)\r\n                  {\r\n                    Byte order = *(const Byte *)coderInfo.Props;\r\n                    methodsString += L\":o\";\r\n                    methodsString += ConvertUInt32ToString(order);\r\n                    methodsString += L\":mem\";\r\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_AES)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 1)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    const Byte *data = (const Byte *)coderInfo.Props;\r\n                    Byte firstByte = *data++;\r\n                    UInt32 numCyclesPower = firstByte & 0x3F;\r\n                    methodsString += ConvertUInt32ToString(numCyclesPower);\r\n                    /*\r\n                    if ((firstByte & 0xC0) != 0)\r\n                    {\r\n                      methodsString += L\":\";\r\n                      return S_OK;\r\n                      UInt32 saltSize = (firstByte >> 7) & 1;\r\n                      UInt32 ivSize = (firstByte >> 6) & 1;\r\n                      if (coderInfo.Props.GetCapacity() >= 2)\r\n                      {\r\n                        Byte secondByte = *data++;\r\n                        saltSize += (secondByte >> 4);\r\n                        ivSize += (secondByte & 0x0F);\r\n                      }\r\n                    }\r\n                    */\r\n                  }\r\n                }\r\n                else\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() > 0)\r\n                  {\r\n                    methodsString += L\":[\";\r\n                    for (size_t bi = 0; bi < coderInfo.Props.GetCapacity(); bi++)\r\n                    {\r\n                      if (bi > 5 && bi + 1 < coderInfo.Props.GetCapacity())\r\n                      {\r\n                        methodsString += L\"..\";\r\n                        break;\r\n                      }\r\n                      else\r\n                        methodsString += GetHex2(coderInfo.Props[bi]);\r\n                    }\r\n                    methodsString += L\"]\";\r\n                  }\r\n                }\r\n              }\r\n              else\r\n              {\r\n                methodsString += ConvertMethodIdToString(coderInfo.MethodID);\r\n              }\r\n            }\r\n          }\r\n          prop = methodsString;\r\n        }\r\n      }\r\n      break;\r\n    case kpidBlock:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n          prop = (UInt32)folderIndex;\r\n      }\r\n      break;\r\n    case kpidPackedSize0:\r\n    case kpidPackedSize1:\r\n    case kpidPackedSize2:\r\n    case kpidPackedSize3:\r\n    case kpidPackedSize4:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _db.Folders[folderIndex];\r\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 &&\r\n              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))\r\n          {\r\n            prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);\r\n          }\r\n          else\r\n            prop = (UInt64)0;\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    #endif\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 *maxCheckStartPosition,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Clear();\r\n  #endif\r\n  try\r\n  {\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(\r\n          IID_ICryptoGetTextPassword, &getTextPassword);\r\n    }\r\n    #endif\r\n    CInArchive archive;\r\n    RINOK(archive.Open(stream, maxCheckStartPosition));\r\n    #ifndef _NO_CRYPTO\r\n    _passwordIsDefined = false;\r\n    UString password;\r\n    #endif\r\n    HRESULT result = archive.ReadDatabase(\r\n      EXTERNAL_CODECS_VARS\r\n      _db\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, _passwordIsDefined\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    _db.Fill();\r\n    _inStream = stream;\r\n  }\r\n  catch(...)\r\n  {\r\n    Close();\r\n    return S_FALSE;\r\n  }\r\n  // _inStream = stream;\r\n  #ifndef _SFX\r\n  FillPopIDs();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  COM_TRY_BEGIN\r\n  _inStream.Release();\r\n  _db.Clear();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef COMPRESS_MT\r\n  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();\r\n  _numThreads = numProcessors;\r\n  #endif\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    const PROPVARIANT &value = values[i];\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index == 0)\r\n    {\r\n      if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n      {\r\n        #ifdef COMPRESS_MT\r\n        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n        #endif\r\n        continue;\r\n      }\r\n      else\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#endif\r\n#endif\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zHandler.h",
    "content": "// 7z/Handler.h\r\n\r\n#ifndef __7Z_HANDLER_H\r\n#define __7Z_HANDLER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../IArchive.h\"\r\n#include \"7zIn.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#ifndef EXTRACT_ONLY\r\n#include \"../Common/HandlerOut.h\"\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\n#ifndef __7Z_SET_PROPERTIES\r\n\r\n#ifdef EXTRACT_ONLY\r\n#ifdef COMPRESS_MT\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n#else\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n\r\n#endif\r\n\r\n\r\nclass CHandler:\r\n  #ifndef EXTRACT_ONLY\r\n  public NArchive::COutHandler,\r\n  #endif\r\n  public IInArchive,\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  public ISetProperties,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public IOutArchive,\r\n  #endif\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IInArchive)\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  MY_QUERYINTERFACE_ENTRY(ISetProperties)\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  MY_QUERYINTERFACE_ENTRY(IOutArchive)\r\n  #endif\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);\r\n  #endif\r\n\r\n  #ifndef EXTRACT_ONLY\r\n  INTERFACE_IOutArchive(;)\r\n  #endif\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n  CHandler();\r\n\r\nprivate:\r\n  CMyComPtr<IInStream> _inStream;\r\n  NArchive::N7z::CArchiveDatabaseEx _db;\r\n  #ifndef _NO_CRYPTO\r\n  bool _passwordIsDefined;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  \r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  #else\r\n  \r\n  CRecordVector<CBind> _binds;\r\n\r\n  HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);\r\n\r\n  HRESULT SetCompressionMethod(CCompressionMethodMode &method,\r\n      CObjectVector<COneMethodInfo> &methodsInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  HRESULT SetCompressionMethod(\r\n      CCompressionMethodMode &method,\r\n      CCompressionMethodMode &headerMethod);\r\n\r\n  #endif\r\n\r\n  bool IsEncrypted(UInt32 index2) const;\r\n  #ifndef _SFX\r\n\r\n  CRecordVector<UInt64> _fileInfoPopIDs;\r\n  void FillPopIDs();\r\n\r\n  #endif\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zHandlerOut.cpp",
    "content": "// 7zHandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const UInt32 kLzmaAlgorithmX5 = 1;\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5;\r\n\r\nstatic inline bool IsCopyMethod(const UString &methodName)\r\n  { return (methodName.CompareNoCase(kCopyMethod) == 0); }\r\n\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  CMyComPtr<ICryptoGetTextPassword2> getTextPassword;\r\n  if (!getTextPassword)\r\n  {\r\n    CMyComPtr<IArchiveUpdateCallback> udateCallback2(updateCallback);\r\n    udateCallback2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);\r\n  }\r\n  \r\n  if (getTextPassword)\r\n  {\r\n    CMyComBSTR password;\r\n    Int32 passwordIsDefined;\r\n    RINOK(getTextPassword->CryptoGetTextPassword2(\r\n        &passwordIsDefined, &password));\r\n    methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);\r\n    if (methodMode.PasswordIsDefined)\r\n      methodMode.Password = password;\r\n  }\r\n  else\r\n    methodMode.PasswordIsDefined = false;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CCompressionMethodMode &headerMethod)\r\n{\r\n  HRESULT res = SetCompressionMethod(methodMode, _methods\r\n  #ifdef COMPRESS_MT\r\n  , _numThreads\r\n  #endif\r\n  );\r\n  RINOK(res);\r\n  methodMode.Binds = _binds;\r\n\r\n  if (_compressHeaders)\r\n  {\r\n    // headerMethod.Methods.Add(methodMode.Methods.Back());\r\n\r\n    CObjectVector<COneMethodInfo> headerMethodInfoVector;\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = kLZMAMethodName;\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kMatchFinder;\r\n      prop.Value = kLzmaMatchFinderForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kAlgorithm;\r\n      prop.Value = kAlgorithmForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kNumFastBytes;\r\n      prop.Value = (UInt32)kNumFastBytesForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = (UInt32)kDictionaryForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    headerMethodInfoVector.Add(oneMethodInfo);\r\n    HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector\r\n      #ifdef COMPRESS_MT\r\n      ,1\r\n      #endif\r\n    );\r\n    RINOK(res);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CObjectVector<COneMethodInfo> &methodsInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  \r\n  if (methodsInfo.IsEmpty())\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = ((level == 0) ? kCopyMethod : kDefaultMethodName);\r\n    methodsInfo.Add(oneMethodInfo);\r\n  }\r\n\r\n  bool needSolid = false;\r\n  for(int i = 0; i < methodsInfo.Size(); i++)\r\n  {\r\n    COneMethodInfo &oneMethodInfo = methodsInfo[i];\r\n    SetCompressionMethod2(oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , numThreads\r\n      #endif\r\n      );\r\n\r\n    if (!IsCopyMethod(oneMethodInfo.MethodName))\r\n      needSolid = true;\r\n\r\n    CMethodFull methodFull;\r\n\r\n    if (!FindMethod(\r\n        EXTERNAL_CODECS_VARS\r\n        oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams))\r\n      return E_INVALIDARG;\r\n    methodFull.Props = oneMethodInfo.Props;\r\n    methodMode.Methods.Add(methodFull);\r\n\r\n    if (!_numSolidBytesDefined)\r\n    {\r\n      for (int j = 0; j < methodFull.Props.Size(); j++)\r\n      {\r\n        const CProp &prop = methodFull.Props[j];\r\n        if ((prop.Id == NCoderPropID::kDictionarySize ||\r\n             prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4)\r\n        {\r\n          _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7;\r\n          const UInt64 kMinSize = (1 << 24);\r\n          if (_numSolidBytes < kMinSize)\r\n            _numSolidBytes = kMinSize;\r\n          _numSolidBytesDefined = true;\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (!needSolid && !_numSolidBytesDefined)\r\n  {\r\n    _numSolidBytesDefined = true;\r\n    _numSolidBytes  = 0;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, bool writeTime, PROPID propID, UInt64 &ft, bool &ftDefined)\r\n{\r\n  ft = 0;\r\n  ftDefined = false;\r\n  if (!writeTime)\r\n    return S_OK;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(updateCallback->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    ft = prop.filetime.dwLowDateTime | ((UInt64)prop.filetime.dwHighDateTime << 32);\r\n    ftDefined = true;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  const CArchiveDatabaseEx *db = 0;\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() > 1)\r\n    return E_FAIL;\r\n  const CVolume *volume = 0;\r\n  if (_volumes.Size() == 1)\r\n  {\r\n    volume = &_volumes.Front();\r\n    db = &volume->Database;\r\n  }\r\n  #else\r\n  if (_inStream != 0)\r\n    db = &_db;\r\n  #endif\r\n\r\n  CObjectVector<CUpdateItem> updateItems;\r\n  \r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    Int32 newData;\r\n    Int32 newProperties;\r\n    UInt32 indexInArchive;\r\n    if (!updateCallback)\r\n      return E_FAIL;\r\n    RINOK(updateCallback->GetUpdateItemInfo(i, &newData, &newProperties, &indexInArchive));\r\n    CUpdateItem ui;\r\n    ui.NewProperties = IntToBool(newProperties);\r\n    ui.NewData = IntToBool(newData);\r\n    ui.IndexInArchive = indexInArchive;\r\n    ui.IndexInClient = i;\r\n    ui.IsAnti = false;\r\n    ui.Size = 0;\r\n\r\n    if (ui.IndexInArchive != -1)\r\n    {\r\n      const CFileItem &fi = db->Files[ui.IndexInArchive];\r\n      ui.Name = fi.Name;\r\n      ui.IsDir = fi.IsDir;\r\n      ui.Size = fi.Size;\r\n      ui.IsAnti = db->IsItemAnti(ui.IndexInArchive);\r\n      \r\n      ui.CTimeDefined = db->CTime.GetItem(ui.IndexInArchive, ui.CTime);\r\n      ui.ATimeDefined = db->ATime.GetItem(ui.IndexInArchive, ui.ATime);\r\n      ui.MTimeDefined = db->MTime.GetItem(ui.IndexInArchive, ui.MTime);\r\n    }\r\n\r\n    if (ui.NewProperties)\r\n    {\r\n      bool nameIsDefined;\r\n      bool folderStatusIsDefined;\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidAttrib, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          ui.AttribDefined = false;\r\n        else if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.Attrib = prop.ulVal;\r\n          ui.AttribDefined = true;\r\n        }\r\n      }\r\n      \r\n      // we need MTime to sort files.\r\n      RINOK(GetTime(updateCallback, i, WriteCTime, kpidCTime, ui.CTime, ui.CTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, WriteATime, kpidATime, ui.ATime, ui.ATimeDefined));\r\n      RINOK(GetTime(updateCallback, i, true,       kpidMTime, ui.MTime, ui.MTimeDefined));\r\n\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidPath, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          nameIsDefined = false;\r\n        else if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.Name = NItemName::MakeLegalName(prop.bstrVal);\r\n          nameIsDefined = true;\r\n        }\r\n      }\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsDir, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          folderStatusIsDefined = false;\r\n        else if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.IsDir = (prop.boolVal != VARIANT_FALSE);\r\n          folderStatusIsDefined = true;\r\n        }\r\n      }\r\n\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsAnti, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          ui.IsAnti = false;\r\n        else if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n          ui.IsAnti = (prop.boolVal != VARIANT_FALSE);\r\n      }\r\n\r\n      if (ui.IsAnti)\r\n      {\r\n        ui.AttribDefined = false;\r\n\r\n        ui.CTimeDefined = false;\r\n        ui.ATimeDefined = false;\r\n        ui.MTimeDefined = false;\r\n        \r\n        ui.Size = 0;\r\n      }\r\n\r\n      if (!folderStatusIsDefined && ui.AttribDefined)\r\n        ui.SetDirStatusFromAttrib();\r\n    }\r\n\r\n    if (ui.NewData)\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(i, kpidSize, &prop));\r\n      if (prop.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      ui.Size = (UInt64)prop.uhVal.QuadPart;\r\n      if (ui.Size != 0 && ui.IsAnti)\r\n        return E_INVALIDARG;\r\n    }\r\n    updateItems.Add(ui);\r\n  }\r\n\r\n  CCompressionMethodMode methodMode, headerMethod;\r\n  RINOK(SetCompressionMethod(methodMode, headerMethod));\r\n  #ifdef COMPRESS_MT\r\n  methodMode.NumThreads = _numThreads;\r\n  headerMethod.NumThreads = 1;\r\n  #endif\r\n\r\n  RINOK(SetPassword(methodMode, updateCallback));\r\n\r\n  bool compressMainHeader = _compressHeaders;  // check it\r\n\r\n  bool encryptHeaders = false;\r\n\r\n  if (methodMode.PasswordIsDefined)\r\n  {\r\n    if (_encryptHeadersSpecified)\r\n      encryptHeaders = _encryptHeaders;\r\n    #ifndef _NO_CRYPTO\r\n    else\r\n      encryptHeaders = _passwordIsDefined;\r\n    #endif\r\n    compressMainHeader = true;\r\n    if(encryptHeaders)\r\n      RINOK(SetPassword(headerMethod, updateCallback));\r\n  }\r\n\r\n  if (numItems < 2)\r\n    compressMainHeader = false;\r\n\r\n  CUpdateOptions options;\r\n  options.Method = &methodMode;\r\n  options.HeaderMethod = (_compressHeaders || encryptHeaders) ? &headerMethod : 0;\r\n  options.UseFilters = _level != 0 && _autoFilter;\r\n  options.MaxFilter = _level >= 8;\r\n\r\n  options.HeaderOptions.CompressMainHeader = compressMainHeader;\r\n  options.HeaderOptions.WriteCTime = WriteCTime;\r\n  options.HeaderOptions.WriteATime = WriteATime;\r\n  options.HeaderOptions.WriteMTime = WriteMTime;\r\n  \r\n  options.NumSolidFiles = _numSolidFiles;\r\n  options.NumSolidBytes = _numSolidBytes;\r\n  options.SolidExtension = _solidExtension;\r\n  options.RemoveSfxBlock = _removeSfxBlock;\r\n  options.VolumeMode = _volumeMode;\r\n\r\n  COutArchive archive;\r\n  CArchiveDatabase newDatabase;\r\n  HRESULT res = Update(\r\n      EXTERNAL_CODECS_VARS\r\n      #ifdef _7Z_VOL\r\n      volume ? volume->Stream: 0,\r\n      volume ? db : 0,\r\n      #else\r\n      _inStream,\r\n      db,\r\n      #endif\r\n      updateItems,\r\n      archive, newDatabase, outStream, updateCallback, options);\r\n\r\n  RINOK(res);\r\n\r\n  updateItems.ClearAndFree();\r\n\r\n  return archive.WriteDatabase(EXTERNAL_CODECS_VARS\r\n      newDatabase, options.HeaderMethod, options.HeaderOptions);\r\n\r\n  COM_TRY_END\r\n}\r\n\r\nstatic HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)\r\n{\r\n  stream = 0;\r\n  int index = ParseStringToUInt32(srcString, coder);\r\n  if (index == 0)\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0, index);\r\n  if (srcString[0] == 'S')\r\n  {\r\n    srcString.Delete(0);\r\n    int index = ParseStringToUInt32(srcString, stream);\r\n    if (index == 0)\r\n      return E_INVALIDARG;\r\n    srcString.Delete(0, index);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetBindInfo(UString &srcString, CBind &bind)\r\n{\r\n  RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream));\r\n  if (srcString[0] != ':')\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0);\r\n  RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream));\r\n  if (!srcString.IsEmpty())\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  _binds.Clear();\r\n  BeforeSetProperty();\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n\r\n    const PROPVARIANT &value = values[i];\r\n\r\n    if (name[0] == 'B')\r\n    {\r\n      name.Delete(0);\r\n      CBind bind;\r\n      RINOK(GetBindInfo(name, bind));\r\n      _binds.Add(bind);\r\n      continue;\r\n    }\r\n\r\n    RINOK(SetProperty(name, value));\r\n  }\r\n\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zHeader.cpp",
    "content": "// 7z/Header.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nByte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n#ifdef _7Z_VOL\r\nByte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};\r\n#endif\r\n\r\nclass SignatureInitializer\r\n{\r\npublic:\r\n  SignatureInitializer()\r\n  {\r\n    kSignature[0]--;\r\n    #ifdef _7Z_VOL\r\n    kFinishSignature[0]--;\r\n    #endif\r\n  };\r\n} g_SignatureInitializer;\r\n\r\n}}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zHeader.h",
    "content": "// 7z/7zHeader.h\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nconst int kSignatureSize = 6;\r\nextern Byte kSignature[kSignatureSize];\r\n\r\n// #define _7Z_VOL\r\n// 7z-MultiVolume is not finished yet.\r\n// It can work already, but I still do not like some\r\n// things of that new multivolume format.\r\n// So please keep it commented.\r\n\r\n#ifdef _7Z_VOL\r\nextern Byte kFinishSignature[kSignatureSize];\r\n#endif\r\n\r\nstruct CArchiveVersion\r\n{\r\n  Byte Major;\r\n  Byte Minor;\r\n};\r\n\r\nconst Byte kMajorVersion = 0;\r\n\r\nstruct CStartHeader\r\n{\r\n  UInt64 NextHeaderOffset;\r\n  UInt64 NextHeaderSize;\r\n  UInt32 NextHeaderCRC;\r\n};\r\n\r\nconst UInt32 kStartHeaderSize = 20;\r\n\r\n#ifdef _7Z_VOL\r\nstruct CFinishHeader: public CStartHeader\r\n{\r\n  UInt64 ArchiveStartOffset;  // data offset from end if that struct\r\n  UInt64 AdditionalStartBlockSize; // start  signature & start header size\r\n};\r\n\r\nconst UInt32 kFinishHeaderSize = kStartHeaderSize + 16;\r\n#endif\r\n\r\nnamespace NID\r\n{\r\n  enum EEnum\r\n  {\r\n    kEnd,\r\n\r\n    kHeader,\r\n\r\n    kArchiveProperties,\r\n    \r\n    kAdditionalStreamsInfo,\r\n    kMainStreamsInfo,\r\n    kFilesInfo,\r\n    \r\n    kPackInfo,\r\n    kUnpackInfo,\r\n    kSubStreamsInfo,\r\n\r\n    kSize,\r\n    kCRC,\r\n\r\n    kFolder,\r\n\r\n    kCodersUnpackSize,\r\n    kNumUnpackStream,\r\n\r\n    kEmptyStream,\r\n    kEmptyFile,\r\n    kAnti,\r\n\r\n    kName,\r\n    kCTime,\r\n    kATime,\r\n    kMTime,\r\n    kWinAttributes,\r\n    kComment,\r\n\r\n    kEncodedHeader,\r\n\r\n    kStartPos,\r\n    kDummy\r\n  };\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zIn.cpp",
    "content": "// 7zIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/7zCrc.h\"\r\n  #include \"../../../../C/CpuArch.h\"\r\n}\r\n\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"7zDecode.h\"\r\n#include \"7zIn.h\"\r\n\r\n#define Get16(p) GetUi16(p)\r\n#define Get32(p) GetUi32(p)\r\n#define Get64(p) GetUi64(p)\r\n\r\n// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader\r\n#ifndef _SFX\r\n#define FORMAT_7Z_RECOVERY\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void BoolVector_Fill_False(CBoolVector &v, int size)\r\n{\r\n  v.Clear();\r\n  v.Reserve(size);\r\n  for (int i = 0; i < size; i++)\r\n    v.Add(false);\r\n}\r\n\r\nstatic bool BoolVector_GetAndSet(CBoolVector &v, UInt32 index)\r\n{\r\n  if (index >= (UInt32)v.Size())\r\n    return true;\r\n  bool res = v[index];\r\n  v[index] = true;\r\n  return res;\r\n}\r\n\r\nbool CFolder::CheckStructure() const\r\n{\r\n  const int kNumCodersMax = sizeof(UInt32) * 8; // don't change it\r\n  const int kMaskSize = sizeof(UInt32) * 8; // it must be >= kNumCodersMax\r\n  const int kNumBindsMax = 32;\r\n\r\n  if (Coders.Size() > kNumCodersMax || BindPairs.Size() > kNumBindsMax)\r\n    return false;\r\n\r\n  {\r\n    CBoolVector v;\r\n    BoolVector_Fill_False(v, BindPairs.Size() + PackStreams.Size());\r\n    \r\n    int i;\r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, BindPairs[i].InIndex))\r\n        return false;\r\n    for (i = 0; i < PackStreams.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, PackStreams[i]))\r\n        return false;\r\n    \r\n    BoolVector_Fill_False(v, UnpackSizes.Size());\r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, BindPairs[i].OutIndex))\r\n        return false;\r\n  }\r\n  \r\n  UInt32 mask[kMaskSize];\r\n  int i;\r\n  for (i = 0; i < kMaskSize; i++)\r\n    mask[i] = 0;\r\n\r\n  {\r\n    CIntVector inStreamToCoder, outStreamToCoder;\r\n    for (i = 0; i < Coders.Size(); i++)\r\n    {\r\n      CNum j;\r\n      const CCoderInfo &coder = Coders[i];\r\n      for (j = 0; j < coder.NumInStreams; j++)\r\n        inStreamToCoder.Add(i);\r\n      for (j = 0; j < coder.NumOutStreams; j++)\r\n        outStreamToCoder.Add(i);\r\n    }\r\n    \r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n    {\r\n      const CBindPair &bp = BindPairs[i];\r\n      mask[inStreamToCoder[bp.InIndex]] |= (1 << outStreamToCoder[bp.OutIndex]);\r\n    }\r\n  }\r\n  \r\n  for (i = 0; i < kMaskSize; i++)\r\n    for (int j = 0; j < kMaskSize; j++)\r\n      if (((1 << j) & mask[i]) != 0)\r\n        mask[i] |= mask[j];\r\n\r\n  for (i = 0; i < kMaskSize; i++)\r\n    if (((1 << i) & mask[i]) != 0)\r\n      return false;\r\n\r\n  return true;\r\n}\r\n\r\nclass CInArchiveException {};\r\n\r\nstatic void ThrowException() { throw CInArchiveException(); }\r\nstatic inline void ThrowEndOfData()   { ThrowException(); }\r\nstatic inline void ThrowUnsupported() { ThrowException(); }\r\nstatic inline void ThrowIncorrect()   { ThrowException(); }\r\nstatic inline void ThrowUnsupportedVersion() { ThrowException(); }\r\n\r\n/*\r\nclass CInArchiveException\r\n{\r\npublic:\r\n  enum CCauseType\r\n  {\r\n    kUnsupportedVersion = 0,\r\n    kUnsupported,\r\n    kIncorrect,\r\n    kEndOfData,\r\n  } Cause;\r\n  CInArchiveException(CCauseType cause): Cause(cause) {};\r\n};\r\n\r\nstatic void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }\r\nstatic void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }\r\nstatic void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }\r\nstatic void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }\r\nstatic void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }\r\n*/\r\n\r\nclass CStreamSwitch\r\n{\r\n  CInArchive *_archive;\r\n  bool _needRemove;\r\npublic:\r\n  CStreamSwitch(): _needRemove(false) {}\r\n  ~CStreamSwitch() { Remove(); }\r\n  void Remove();\r\n  void Set(CInArchive *archive, const Byte *data, size_t size);\r\n  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);\r\n  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);\r\n};\r\n\r\nvoid CStreamSwitch::Remove()\r\n{\r\n  if (_needRemove)\r\n  {\r\n    _archive->DeleteByteStream();\r\n    _needRemove = false;\r\n  }\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)\r\n{\r\n  Remove();\r\n  _archive = archive;\r\n  _archive->AddByteStream(data, size);\r\n  _needRemove = true;\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)\r\n{\r\n  Set(archive, byteBuffer, byteBuffer.GetCapacity());\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)\r\n{\r\n  Remove();\r\n  Byte external = archive->ReadByte();\r\n  if (external != 0)\r\n  {\r\n    int dataIndex = (int)archive->ReadNum();\r\n    if (dataIndex < 0 || dataIndex >= dataVector->Size())\r\n      ThrowIncorrect();\r\n    Set(archive, (*dataVector)[dataIndex]);\r\n  }\r\n}\r\n\r\nByte CInByte2::ReadByte()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  return _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::ReadBytes(Byte *data, size_t size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  for (size_t i = 0; i < size; i++)\r\n    data[i] = _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::SkeepData(UInt64 size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  _pos += (size_t)size;\r\n}\r\n\r\nvoid CInByte2::SkeepData()\r\n{\r\n  SkeepData(ReadNumber());\r\n}\r\n\r\nUInt64 CInByte2::ReadNumber()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  Byte firstByte = _buffer[_pos++];\r\n  Byte mask = 0x80;\r\n  UInt64 value = 0;\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      value += (highPart << (i * 8));\r\n      return value;\r\n    }\r\n    if (_pos >= _size)\r\n      ThrowEndOfData();\r\n    value |= ((UInt64)_buffer[_pos++] << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return value;\r\n}\r\n\r\nCNum CInByte2::ReadNum()\r\n{\r\n  UInt64 value = ReadNumber();\r\n  if (value > kNumMax)\r\n    ThrowUnsupported();\r\n  return (CNum)value;\r\n}\r\n\r\nUInt32 CInByte2::ReadUInt32()\r\n{\r\n  if (_pos + 4 > _size)\r\n    ThrowEndOfData();\r\n  UInt32 res = Get32(_buffer + _pos);\r\n  _pos += 4;\r\n  return res;\r\n}\r\n\r\nUInt64 CInByte2::ReadUInt64()\r\n{\r\n  if (_pos + 8 > _size)\r\n    ThrowEndOfData();\r\n  UInt64 res = Get64(_buffer + _pos);\r\n  _pos += 8;\r\n  return res;\r\n}\r\n\r\nvoid CInByte2::ReadString(UString &s)\r\n{\r\n  const Byte *buf = _buffer + _pos;\r\n  size_t rem = (_size - _pos) / 2 * 2;\r\n  {\r\n    size_t i;\r\n    for (i = 0; i < rem; i += 2)\r\n      if (buf[i] == 0 && buf[i + 1] == 0)\r\n        break;\r\n    if (i == rem)\r\n      ThrowEndOfData();\r\n    rem = i;\r\n  }\r\n  int len = (int)(rem / 2);\r\n  if (len < 0 || (size_t)len * 2 != rem)\r\n    ThrowUnsupported();\r\n  wchar_t *p = s.GetBuffer(len);\r\n  int i;\r\n  for (i = 0; i < len; i++, buf += 2)\r\n    p[i] = (wchar_t)Get16(buf);\r\n  s.ReleaseBuffer(len);\r\n  _pos += rem + 2;\r\n}\r\n\r\nstatic inline bool TestSignatureCandidate(const Byte *p)\r\n{\r\n  for (int i = 0; i < kSignatureSize; i++)\r\n    if (p[i] != kSignature[i])\r\n      return false;\r\n  return (p[0x1A] == 0 && p[0x1B] == 0);\r\n}\r\n\r\nHRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));\r\n\r\n  if (TestSignatureCandidate(_header))\r\n    return S_OK;\r\n\r\n  CByteBuffer byteBuffer;\r\n  const UInt32 kBufferSize = (1 << 16);\r\n  byteBuffer.SetCapacity(kBufferSize);\r\n  Byte *buffer = byteBuffer;\r\n  UInt32 numPrevBytes = kHeaderSize - 1;\r\n  memcpy(buffer, _header + 1, numPrevBytes);\r\n  UInt64 curTestPos = _arhiveBeginStreamPosition + 1;\r\n  for (;;)\r\n  {\r\n    if (searchHeaderSizeLimit != NULL)\r\n      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)\r\n        break;\r\n    do\r\n    {\r\n      UInt32 numReadBytes = kBufferSize - numPrevBytes;\r\n      UInt32 processedSize;\r\n      RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));\r\n      numPrevBytes += processedSize;\r\n      if (processedSize == 0)\r\n        return S_FALSE;\r\n    }\r\n    while (numPrevBytes < kHeaderSize);\r\n    UInt32 numTests = numPrevBytes - kHeaderSize + 1;\r\n    for (UInt32 pos = 0; pos < numTests; pos++)\r\n    {\r\n      for (; buffer[pos] != '7' && pos < numTests; pos++);\r\n      if (pos == numTests)\r\n        break;\r\n      if (TestSignatureCandidate(buffer + pos))\r\n      {\r\n        memcpy(_header, buffer + pos, kHeaderSize);\r\n        curTestPos += pos;\r\n        _arhiveBeginStreamPosition = curTestPos;\r\n        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);\r\n      }\r\n    }\r\n    curTestPos += numTests;\r\n    numPrevBytes -= numTests;\r\n    memmove(buffer, buffer + numTests, numPrevBytes);\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\n// S_FALSE means that file is not archive\r\nHRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  HeadersSize = 0;\r\n  Close();\r\n  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))\r\n  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));\r\n  _stream = stream;\r\n  return S_OK;\r\n}\r\n  \r\nvoid CInArchive::Close()\r\n{\r\n  _stream.Release();\r\n}\r\n\r\nvoid CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)\r\n{\r\n  for (;;)\r\n  {\r\n    if (ReadID() == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::GetNextFolderItem(CFolder &folder)\r\n{\r\n  CNum numCoders = ReadNum();\r\n\r\n  folder.Coders.Clear();\r\n  folder.Coders.Reserve((int)numCoders);\r\n  CNum numInStreams = 0;\r\n  CNum numOutStreams = 0;\r\n  CNum i;\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    folder.Coders.Add(CCoderInfo());\r\n    CCoderInfo &coder = folder.Coders.Back();\r\n\r\n    {\r\n      Byte mainByte = ReadByte();\r\n      int idSize = (mainByte & 0xF);\r\n      Byte longID[15];\r\n      ReadBytes(longID, idSize);\r\n      if (idSize > 8)\r\n        ThrowUnsupported();\r\n      UInt64 id = 0;\r\n      for (int j = 0; j < idSize; j++)\r\n        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n      coder.MethodID = id;\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        coder.NumInStreams = ReadNum();\r\n        coder.NumOutStreams = ReadNum();\r\n      }\r\n      else\r\n      {\r\n        coder.NumInStreams = 1;\r\n        coder.NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        CNum propsSize = ReadNum();\r\n        coder.Props.SetCapacity((size_t)propsSize);\r\n        ReadBytes((Byte *)coder.Props, (size_t)propsSize);\r\n      }\r\n      if ((mainByte & 0x80) != 0)\r\n        ThrowUnsupported();\r\n    }\r\n    numInStreams += coder.NumInStreams;\r\n    numOutStreams += coder.NumOutStreams;\r\n  }\r\n\r\n  CNum numBindPairs = numOutStreams - 1;\r\n  folder.BindPairs.Clear();\r\n  folder.BindPairs.Reserve(numBindPairs);\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair bp;\r\n    bp.InIndex = ReadNum();\r\n    bp.OutIndex = ReadNum();\r\n    folder.BindPairs.Add(bp);\r\n  }\r\n\r\n  if (numInStreams < numBindPairs)\r\n    ThrowUnsupported();\r\n  CNum numPackStreams = numInStreams - numBindPairs;\r\n  folder.PackStreams.Reserve(numPackStreams);\r\n  if (numPackStreams == 1)\r\n  {\r\n    for (i = 0; i < numInStreams; i++)\r\n      if (folder.FindBindPairForInStream(i) < 0)\r\n      {\r\n        folder.PackStreams.Add(i);\r\n        break;\r\n      }\r\n    if (folder.PackStreams.Size() != 1)\r\n      ThrowUnsupported();\r\n  }\r\n  else\r\n    for (i = 0; i < numPackStreams; i++)\r\n      folder.PackStreams.Add(ReadNum());\r\n}\r\n\r\nvoid CInArchive::WaitAttribute(UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == attribute)\r\n      return;\r\n    if (type == NID::kEnd)\r\n      ThrowIncorrect();\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadHashDigests(int numItems,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  ReadBoolVector2(numItems, digestsDefined);\r\n  digests.Clear();\r\n  digests.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 crc = 0;\r\n    if (digestsDefined[i])\r\n      crc = ReadUInt32();\r\n    digests.Add(crc);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadPackInfo(\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CBoolVector &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs)\r\n{\r\n  dataOffset = ReadNumber();\r\n  CNum numPackStreams = ReadNum();\r\n\r\n  WaitAttribute(NID::kSize);\r\n  packSizes.Clear();\r\n  packSizes.Reserve(numPackStreams);\r\n  for (CNum i = 0; i < numPackStreams; i++)\r\n    packSizes.Add(ReadNumber());\r\n\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    if (type == NID::kCRC)\r\n    {\r\n      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs);\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n  if (packCRCsDefined.IsEmpty())\r\n  {\r\n    BoolVector_Fill_False(packCRCsDefined, numPackStreams);\r\n    packCRCs.Reserve(numPackStreams);\r\n    packCRCs.Clear();\r\n    for (CNum i = 0; i < numPackStreams; i++)\r\n      packCRCs.Add(0);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadUnpackInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    CObjectVector<CFolder> &folders)\r\n{\r\n  WaitAttribute(NID::kFolder);\r\n  CNum numFolders = ReadNum();\r\n\r\n  {\r\n    CStreamSwitch streamSwitch;\r\n    streamSwitch.Set(this, dataVector);\r\n    folders.Clear();\r\n    folders.Reserve(numFolders);\r\n    for (CNum i = 0; i < numFolders; i++)\r\n    {\r\n      folders.Add(CFolder());\r\n      GetNextFolderItem(folders.Back());\r\n    }\r\n  }\r\n\r\n  WaitAttribute(NID::kCodersUnpackSize);\r\n\r\n  CNum i;\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    CFolder &folder = folders[i];\r\n    CNum numOutStreams = folder.GetNumOutStreams();\r\n    folder.UnpackSizes.Reserve(numOutStreams);\r\n    for (CNum j = 0; j < numOutStreams; j++)\r\n      folder.UnpackSizes.Add(ReadNumber());\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      return;\r\n    if (type == NID::kCRC)\r\n    {\r\n      CBoolVector crcsDefined;\r\n      CRecordVector<UInt32> crcs;\r\n      ReadHashDigests(numFolders, crcsDefined, crcs);\r\n      for (i = 0; i < numFolders; i++)\r\n      {\r\n        CFolder &folder = folders[i];\r\n        folder.UnpackCRCDefined = crcsDefined[i];\r\n        folder.UnpackCRC = crcs[i];\r\n      }\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    CRecordVector<UInt64> &unpackSizes,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  numUnpackStreamsInFolders.Clear();\r\n  numUnpackStreamsInFolders.Reserve(folders.Size());\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kNumUnpackStream)\r\n    {\r\n      for (int i = 0; i < folders.Size(); i++)\r\n        numUnpackStreamsInFolders.Add(ReadNum());\r\n      continue;\r\n    }\r\n    if (type == NID::kCRC || type == NID::kSize)\r\n      break;\r\n    if (type == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n\r\n  if (numUnpackStreamsInFolders.IsEmpty())\r\n    for (int i = 0; i < folders.Size(); i++)\r\n      numUnpackStreamsInFolders.Add(1);\r\n\r\n  int i;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n  {\r\n    // v3.13 incorrectly worked with empty folders\r\n    // v4.07: we check that folder is empty\r\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    UInt64 sum = 0;\r\n    for (CNum j = 1; j < numSubstreams; j++)\r\n      if (type == NID::kSize)\r\n      {\r\n        UInt64 size = ReadNumber();\r\n        unpackSizes.Add(size);\r\n        sum += size;\r\n      }\r\n    unpackSizes.Add(folders[i].GetUnpackSize() - sum);\r\n  }\r\n  if (type == NID::kSize)\r\n    type = ReadID();\r\n\r\n  int numDigests = 0;\r\n  int numDigestsTotal = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\r\n      numDigests += numSubstreams;\r\n    numDigestsTotal += numSubstreams;\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    if (type == NID::kCRC)\r\n    {\r\n      CBoolVector digestsDefined2;\r\n      CRecordVector<UInt32> digests2;\r\n      ReadHashDigests(numDigests, digestsDefined2, digests2);\r\n      int digestIndex = 0;\r\n      for (i = 0; i < folders.Size(); i++)\r\n      {\r\n        CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n        const CFolder &folder = folders[i];\r\n        if (numSubstreams == 1 && folder.UnpackCRCDefined)\r\n        {\r\n          digestsDefined.Add(true);\r\n          digests.Add(folder.UnpackCRC);\r\n        }\r\n        else\r\n          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)\r\n          {\r\n            digestsDefined.Add(digestsDefined2[digestIndex]);\r\n            digests.Add(digests2[digestIndex]);\r\n          }\r\n      }\r\n    }\r\n    else if (type == NID::kEnd)\r\n    {\r\n      if (digestsDefined.IsEmpty())\r\n      {\r\n        BoolVector_Fill_False(digestsDefined, numDigestsTotal);\r\n        digests.Clear();\r\n        for (int i = 0; i < numDigestsTotal; i++)\r\n          digests.Add(0);\r\n      }\r\n      return;\r\n    }\r\n    else\r\n      SkeepData();\r\n    type = ReadID();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadStreamsInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CBoolVector &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs,\r\n    CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    CRecordVector<UInt64> &unpackSizes,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type > ((UInt32)1 << 30))\r\n      ThrowIncorrect();\r\n    switch((UInt32)type)\r\n    {\r\n      case NID::kEnd:\r\n        return;\r\n      case NID::kPackInfo:\r\n      {\r\n        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);\r\n        break;\r\n      }\r\n      case NID::kUnpackInfo:\r\n      {\r\n        ReadUnpackInfo(dataVector, folders);\r\n        break;\r\n      }\r\n      case NID::kSubStreamsInfo:\r\n      {\r\n        ReadSubStreamsInfo(folders, numUnpackStreamsInFolders,\r\n            unpackSizes, digestsDefined, digests);\r\n        break;\r\n      }\r\n      default:\r\n        ThrowIncorrect();\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector(int numItems, CBoolVector &v)\r\n{\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      b = ReadByte();\r\n      mask = 0x80;\r\n    }\r\n    v.Add((b & mask) != 0);\r\n    mask >>= 1;\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)\r\n{\r\n  Byte allAreDefined = ReadByte();\r\n  if (allAreDefined == 0)\r\n  {\r\n    ReadBoolVector(numItems, v);\r\n    return;\r\n  }\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n    v.Add(true);\r\n}\r\n\r\nvoid CInArchive::ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\r\n    CUInt64DefVector &v, int numFiles)\r\n{\r\n  ReadBoolVector2(numFiles, v.Defined);\r\n\r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, &dataVector);\r\n  v.Values.Reserve(numFiles);\r\n\r\n  for (int i = 0; i < numFiles; i++)\r\n  {\r\n    UInt64 t = 0;\r\n    if (v.Defined[i])\r\n      t = ReadUInt64();\r\n    v.Values.Add(t);\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadAndDecodePackedStreams(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    UInt64 baseOffset,\r\n    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  CRecordVector<UInt64> packSizes;\r\n  CBoolVector packCRCsDefined;\r\n  CRecordVector<UInt32> packCRCs;\r\n  CObjectVector<CFolder> folders;\r\n  \r\n  CRecordVector<CNum> numUnpackStreamsInFolders;\r\n  CRecordVector<UInt64> unpackSizes;\r\n  CBoolVector digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  ReadStreamsInfo(NULL,\r\n    dataOffset,\r\n    packSizes,\r\n    packCRCsDefined,\r\n    packCRCs,\r\n    folders,\r\n    numUnpackStreamsInFolders,\r\n    unpackSizes,\r\n    digestsDefined,\r\n    digests);\r\n  \r\n  // db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\r\n  \r\n  CNum packIndex = 0;\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  UInt64 dataStartPos = baseOffset + dataOffset;\r\n  for (int i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    dataVector.Add(CByteBuffer());\r\n    CByteBuffer &data = dataVector.Back();\r\n    UInt64 unpackSize64 = folder.GetUnpackSize();\r\n    size_t unpackSize = (size_t)unpackSize64;\r\n    if (unpackSize != unpackSize64)\r\n      ThrowUnsupported();\r\n    data.SetCapacity(unpackSize);\r\n    \r\n    CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    outStreamSpec->Init(data, unpackSize);\r\n    \r\n    HRESULT result = decoder.Decode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      _stream, dataStartPos,\r\n      &packSizes[packIndex], folder, outStream, NULL\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, passwordIsDefined\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , false, 1\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    \r\n    if (folder.UnpackCRCDefined)\r\n      if (CrcCalc(data, unpackSize) != folder.UnpackCRC)\r\n        ThrowIncorrect();\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      UInt64 packSize = packSizes[packIndex++];\r\n      dataStartPos += packSize;\r\n      HeadersSize += packSize;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CInArchive::ReadHeader(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  UInt64 type = ReadID();\r\n\r\n  if (type == NID::kArchiveProperties)\r\n  {\r\n    ReadArchiveProperties(db.ArchiveInfo);\r\n    type = ReadID();\r\n  }\r\n \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  if (type == NID::kAdditionalStreamsInfo)\r\n  {\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        db.ArchiveInfo.StartPositionAfterHeader,\r\n        db.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword, passwordIsDefined\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n\r\n  CRecordVector<UInt64> unpackSizes;\r\n  CBoolVector digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  if (type == NID::kMainStreamsInfo)\r\n  {\r\n    ReadStreamsInfo(&dataVector,\r\n        db.ArchiveInfo.DataStartPosition,\r\n        db.PackSizes,\r\n        db.PackCRCsDefined,\r\n        db.PackCRCs,\r\n        db.Folders,\r\n        db.NumUnpackStreamsVector,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    db.ArchiveInfo.DataStartPosition += db.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n  else\r\n  {\r\n    for (int i = 0; i < db.Folders.Size(); i++)\r\n    {\r\n      db.NumUnpackStreamsVector.Add(1);\r\n      CFolder &folder = db.Folders[i];\r\n      unpackSizes.Add(folder.GetUnpackSize());\r\n      digestsDefined.Add(folder.UnpackCRCDefined);\r\n      digests.Add(folder.UnpackCRC);\r\n    }\r\n  }\r\n\r\n  db.Files.Clear();\r\n\r\n  if (type == NID::kEnd)\r\n    return S_OK;\r\n  if (type != NID::kFilesInfo)\r\n    ThrowIncorrect();\r\n  \r\n  CNum numFiles = ReadNum();\r\n  db.Files.Reserve(numFiles);\r\n  CNum i;\r\n  for (i = 0; i < numFiles; i++)\r\n    db.Files.Add(CFileItem());\r\n\r\n  db.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);\r\n  if (!db.PackSizes.IsEmpty())\r\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);\r\n  if (numFiles > 0  && !digests.IsEmpty())\r\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);\r\n\r\n  CBoolVector emptyStreamVector;\r\n  BoolVector_Fill_False(emptyStreamVector, (int)numFiles);\r\n  CBoolVector emptyFileVector;\r\n  CBoolVector antiFileVector;\r\n  CNum numEmptyStreams = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    UInt64 size = ReadNumber();\r\n    size_t ppp = _inByteBack->_pos;\r\n    bool addPropIdToList = true;\r\n    bool isKnownType = true;\r\n    if (type > ((UInt32)1 << 30))\r\n      isKnownType = false;\r\n    else switch((UInt32)type)\r\n    {\r\n      case NID::kName:\r\n      {\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for (int i = 0; i < db.Files.Size(); i++)\r\n          _inByteBack->ReadString(db.Files[i].Name);\r\n        break;\r\n      }\r\n      case NID::kWinAttributes:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(db.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = db.Files[i];\r\n          file.AttribDefined = boolVector[i];\r\n          if (file.AttribDefined)\r\n            file.Attrib = ReadUInt32();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyStream:\r\n      {\r\n        ReadBoolVector(numFiles, emptyStreamVector);\r\n        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)\r\n          if (emptyStreamVector[i])\r\n            numEmptyStreams++;\r\n\r\n        BoolVector_Fill_False(emptyFileVector, numEmptyStreams);\r\n        BoolVector_Fill_False(antiFileVector, numEmptyStreams);\r\n\r\n        break;\r\n      }\r\n      case NID::kEmptyFile:  ReadBoolVector(numEmptyStreams, emptyFileVector); break;\r\n      case NID::kAnti:  ReadBoolVector(numEmptyStreams, antiFileVector); break;\r\n      case NID::kStartPos:  ReadUInt64DefVector(dataVector, db.StartPos, (int)numFiles); break;\r\n      case NID::kCTime:  ReadUInt64DefVector(dataVector, db.CTime, (int)numFiles); break;\r\n      case NID::kATime:  ReadUInt64DefVector(dataVector, db.ATime, (int)numFiles); break;\r\n      case NID::kMTime:  ReadUInt64DefVector(dataVector, db.MTime, (int)numFiles); break;\r\n      case NID::kDummy:\r\n      {\r\n        for (UInt64 j = 0; j < size; j++)\r\n          if (ReadByte() != 0)\r\n            ThrowIncorrect();\r\n        addPropIdToList = false;\r\n        break;\r\n      }\r\n      default:\r\n        addPropIdToList = isKnownType = false;\r\n    }\r\n    if (isKnownType)\r\n    {\r\n      if(addPropIdToList)\r\n        db.ArchiveInfo.FileInfoPopIDs.Add(type);\r\n    }\r\n    else\r\n      SkeepData(size);\r\n    bool checkRecordsSize = (db.ArchiveInfo.Version.Major > 0 ||\r\n        db.ArchiveInfo.Version.Minor > 2);\r\n    if (checkRecordsSize && _inByteBack->_pos - ppp != size)\r\n      ThrowIncorrect();\r\n  }\r\n\r\n  CNum emptyFileIndex = 0;\r\n  CNum sizeIndex = 0;\r\n\r\n  CNum numAntiItems = 0;\r\n  for (i = 0; i < numEmptyStreams; i++)\r\n    if (antiFileVector[i])\r\n      numAntiItems++;\r\n    \r\n  for (i = 0; i < numFiles; i++)\r\n  {\r\n    CFileItem &file = db.Files[i];\r\n    bool isAnti;\r\n    file.HasStream = !emptyStreamVector[i];\r\n    if (file.HasStream)\r\n    {\r\n      file.IsDir = false;\r\n      isAnti = false;\r\n      file.Size = unpackSizes[sizeIndex];\r\n      file.Crc = digests[sizeIndex];\r\n      file.CrcDefined = digestsDefined[sizeIndex];\r\n      sizeIndex++;\r\n    }\r\n    else\r\n    {\r\n      file.IsDir = !emptyFileVector[emptyFileIndex];\r\n      isAnti = antiFileVector[emptyFileIndex];\r\n      emptyFileIndex++;\r\n      file.Size = 0;\r\n      file.CrcDefined = false;\r\n    }\r\n    if (numAntiItems != 0)\r\n      db.IsAnti.Add(isAnti);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartPackStream()\r\n{\r\n  FolderStartPackStreamIndex.Clear();\r\n  FolderStartPackStreamIndex.Reserve(Folders.Size());\r\n  CNum startPos = 0;\r\n  for (int i = 0; i < Folders.Size(); i++)\r\n  {\r\n    FolderStartPackStreamIndex.Add(startPos);\r\n    startPos += (CNum)Folders[i].PackStreams.Size();\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillStartPos()\r\n{\r\n  PackStreamStartPositions.Clear();\r\n  PackStreamStartPositions.Reserve(PackSizes.Size());\r\n  UInt64 startPos = 0;\r\n  for (int i = 0; i < PackSizes.Size(); i++)\r\n  {\r\n    PackStreamStartPositions.Add(startPos);\r\n    startPos += PackSizes[i];\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartFileIndex()\r\n{\r\n  FolderStartFileIndex.Clear();\r\n  FolderStartFileIndex.Reserve(Folders.Size());\r\n  FileIndexToFolderIndexMap.Clear();\r\n  FileIndexToFolderIndexMap.Reserve(Files.Size());\r\n  \r\n  int folderIndex = 0;\r\n  CNum indexInFolder = 0;\r\n  for (int i = 0; i < Files.Size(); i++)\r\n  {\r\n    const CFileItem &file = Files[i];\r\n    bool emptyStream = !file.HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      FileIndexToFolderIndexMap.Add(kNumNoIndex);\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      // v3.13 incorrectly worked with empty folders\r\n      // v4.07: Loop for skipping empty folders\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= Folders.Size())\r\n          ThrowIncorrect();\r\n        FolderStartFileIndex.Add(i); // check it\r\n        if (NumUnpackStreamsVector[folderIndex] != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    FileIndexToFolderIndexMap.Add(folderIndex);\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= NumUnpackStreamsVector[folderIndex])\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n\r\n  db.ArchiveInfo.Version.Major = _header[6];\r\n  db.ArchiveInfo.Version.Minor = _header[7];\r\n\r\n  if (db.ArchiveInfo.Version.Major != kMajorVersion)\r\n    ThrowUnsupportedVersion();\r\n\r\n  UInt32 crcFromArchive = Get32(_header + 8);\r\n  UInt64 nextHeaderOffset = Get64(_header + 0xC);\r\n  UInt64 nextHeaderSize = Get64(_header + 0x14);\r\n  UInt32 nextHeaderCRC = Get32(_header + 0x1C);\r\n  UInt32 crc = CrcCalc(_header + 0xC, 20);\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)\r\n  {\r\n    UInt64 cur, cur2;\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));\r\n    const int kCheckSize = 500;\r\n    Byte buf[kCheckSize];\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));\r\n    int checkSize = kCheckSize;\r\n    if (cur2 - cur < kCheckSize)\r\n      checkSize = (int)(cur2 - cur);\r\n    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));\r\n    \r\n    RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));\r\n\r\n    int i;\r\n    for (i = (int)checkSize - 2; i >= 0; i--)\r\n      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)\r\n        break;\r\n    if (i < 0)\r\n      return S_FALSE;\r\n    nextHeaderSize = checkSize - i;\r\n    nextHeaderOffset = cur2 - cur + i;\r\n    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);\r\n    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));\r\n  }\r\n  #endif\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  crcFromArchive = crc;\r\n  #endif\r\n\r\n  db.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;\r\n\r\n  if (crc != crcFromArchive)\r\n    ThrowIncorrect();\r\n\r\n  if (nextHeaderSize == 0)\r\n    return S_OK;\r\n\r\n  if (nextHeaderSize > (UInt64)0xFFFFFFFF)\r\n    return S_FALSE;\r\n\r\n  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));\r\n\r\n  CByteBuffer buffer2;\r\n  buffer2.SetCapacity((size_t)nextHeaderSize);\r\n\r\n  RINOK(ReadStream_FALSE(_stream, buffer2, (size_t)nextHeaderSize));\r\n  HeadersSize += kHeaderSize + nextHeaderSize;\r\n  db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;\r\n\r\n  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)\r\n    ThrowIncorrect();\r\n  \r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, buffer2);\r\n  \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  UInt64 type = ReadID();\r\n  if (type != NID::kHeader)\r\n  {\r\n    if (type != NID::kEncodedHeader)\r\n      ThrowIncorrect();\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        db.ArchiveInfo.StartPositionAfterHeader,\r\n        db.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword, passwordIsDefined\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    if (dataVector.Size() == 0)\r\n      return S_OK;\r\n    if (dataVector.Size() > 1)\r\n      ThrowIncorrect();\r\n    streamSwitch.Remove();\r\n    streamSwitch.Set(this, dataVector.Front());\r\n    if (ReadID() != NID::kHeader)\r\n      ThrowIncorrect();\r\n  }\r\n\r\n  db.HeadersSize = HeadersSize;\r\n\r\n  return ReadHeader(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    db\r\n    #ifndef _NO_CRYPTO\r\n    , getTextPassword, passwordIsDefined\r\n    #endif\r\n    );\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  try\r\n  {\r\n    return ReadDatabase2(\r\n      EXTERNAL_CODECS_LOC_VARS db\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, passwordIsDefined\r\n      #endif\r\n      );\r\n  }\r\n  catch(CInArchiveException &) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zIn.h",
    "content": "// 7zIn.h\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../IStream.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/InBuffer.h\"\r\n\r\n#include \"7zItem.h\"\r\n \r\nnamespace NArchive {\r\nnamespace N7z {\r\n  \r\nstruct CInArchiveInfo\r\n{\r\n  CArchiveVersion Version;\r\n  UInt64 StartPosition;\r\n  UInt64 StartPositionAfterHeader;\r\n  UInt64 DataStartPosition;\r\n  UInt64 DataStartPosition2;\r\n  CRecordVector<UInt64> FileInfoPopIDs;\r\n  void Clear()\r\n  {\r\n    FileInfoPopIDs.Clear();\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabaseEx: public CArchiveDatabase\r\n{\r\n  CInArchiveInfo ArchiveInfo;\r\n  CRecordVector<UInt64> PackStreamStartPositions;\r\n  CRecordVector<CNum> FolderStartPackStreamIndex;\r\n  CRecordVector<CNum> FolderStartFileIndex;\r\n  CRecordVector<CNum> FileIndexToFolderIndexMap;\r\n\r\n  UInt64 HeadersSize;\r\n  UInt64 PhySize;\r\n\r\n  void Clear()\r\n  {\r\n    CArchiveDatabase::Clear();\r\n    ArchiveInfo.Clear();\r\n    PackStreamStartPositions.Clear();\r\n    FolderStartPackStreamIndex.Clear();\r\n    FolderStartFileIndex.Clear();\r\n    FileIndexToFolderIndexMap.Clear();\r\n\r\n    HeadersSize = 0;\r\n    PhySize = 0;\r\n  }\r\n\r\n  void FillFolderStartPackStream();\r\n  void FillStartPos();\r\n  void FillFolderStartFileIndex();\r\n\r\n  void Fill()\r\n  {\r\n    FillFolderStartPackStream();\r\n    FillStartPos();\r\n    FillFolderStartFileIndex();\r\n  }\r\n  \r\n  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const\r\n  {\r\n    return ArchiveInfo.DataStartPosition +\r\n        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n  }\r\n  \r\n  UInt64 GetFolderFullPackSize(int folderIndex) const\r\n  {\r\n    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];\r\n    const CFolder &folder = Folders[folderIndex];\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < folder.PackStreams.Size(); i++)\r\n      size += PackSizes[packStreamIndex + i];\r\n    return size;\r\n  }\r\n  \r\n  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\r\n  {\r\n    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n  }\r\n\r\n  UInt64 GetFilePackSize(CNum fileIndex) const\r\n  {\r\n    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n    if (folderIndex != kNumNoIndex)\r\n      if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n        return GetFolderFullPackSize(folderIndex);\r\n    return 0;\r\n  }\r\n};\r\n\r\nclass CInByte2\r\n{\r\n  const Byte *_buffer;\r\n  size_t _size;\r\npublic:\r\n  size_t _pos;\r\n  void Init(const Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  Byte ReadByte();\r\n  void ReadBytes(Byte *data, size_t size);\r\n  void SkeepData(UInt64 size);\r\n  void SkeepData();\r\n  UInt64 ReadNumber();\r\n  CNum ReadNum();\r\n  UInt32 ReadUInt32();\r\n  UInt64 ReadUInt64();\r\n  void ReadString(UString &s);\r\n};\r\n\r\nclass CStreamSwitch;\r\n\r\nconst UInt32 kHeaderSize = 32;\r\n\r\nclass CInArchive\r\n{\r\n  friend class CStreamSwitch;\r\n\r\n  CMyComPtr<IInStream> _stream;\r\n\r\n  CObjectVector<CInByte2> _inByteVector;\r\n  CInByte2 *_inByteBack;\r\n \r\n  UInt64 _arhiveBeginStreamPosition;\r\n\r\n  Byte _header[kHeaderSize];\r\n\r\n  UInt64 HeadersSize;\r\n\r\n  void AddByteStream(const Byte *buffer, size_t size)\r\n  {\r\n    _inByteVector.Add(CInByte2());\r\n    _inByteBack = &_inByteVector.Back();\r\n    _inByteBack->Init(buffer, size);\r\n  }\r\n  \r\n  void DeleteByteStream()\r\n  {\r\n    _inByteVector.DeleteBack();\r\n    if (!_inByteVector.IsEmpty())\r\n      _inByteBack = &_inByteVector.Back();\r\n  }\r\n\r\nprivate:\r\n  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);\r\n  \r\n  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }\r\n  Byte ReadByte() { return _inByteBack->ReadByte(); }\r\n  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }\r\n  CNum ReadNum() { return _inByteBack->ReadNum(); }\r\n  UInt64 ReadID() { return _inByteBack->ReadNumber(); }\r\n  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }\r\n  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }\r\n  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }\r\n  void SkeepData() { _inByteBack->SkeepData(); }\r\n  void WaitAttribute(UInt64 attribute);\r\n\r\n  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);\r\n  void GetNextFolderItem(CFolder &itemInfo);\r\n  void ReadHashDigests(int numItems,\r\n      CBoolVector &digestsDefined, CRecordVector<UInt32> &digests);\r\n  \r\n  void ReadPackInfo(\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CBoolVector &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs);\r\n  \r\n  void ReadUnpackInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      CObjectVector<CFolder> &folders);\r\n  \r\n  void ReadSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      CRecordVector<UInt64> &unpackSizes,\r\n      CBoolVector &digestsDefined,\r\n      CRecordVector<UInt32> &digests);\r\n\r\n  void ReadStreamsInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CBoolVector &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs,\r\n      CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      CRecordVector<UInt64> &unpackSizes,\r\n      CBoolVector &digestsDefined,\r\n      CRecordVector<UInt32> &digests);\r\n\r\n\r\n  void ReadBoolVector(int numItems, CBoolVector &v);\r\n  void ReadBoolVector2(int numItems, CBoolVector &v);\r\n  void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\r\n      CUInt64DefVector &v, int numFiles);\r\n  HRESULT ReadAndDecodePackedStreams(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      UInt64 baseOffset, UInt64 &dataOffset,\r\n      CObjectVector<CByteBuffer> &dataVector\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n  HRESULT ReadHeader(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n  HRESULT ReadDatabase2(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\npublic:\r\n  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive\r\n  void Close();\r\n\r\n  HRESULT ReadDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n};\r\n  \r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zItem.h",
    "content": "// 7zItem.h\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../Common/MethodId.h\"\r\n\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\ntypedef UInt32 CNum;\r\nconst CNum kNumMax     = 0x7FFFFFFF;\r\nconst CNum kNumNoIndex = 0xFFFFFFFF;\r\n\r\nstruct CCoderInfo\r\n{\r\n  CMethodId MethodID;\r\n  CByteBuffer Props;\r\n  CNum NumInStreams;\r\n  CNum NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBindPair\r\n{\r\n  CNum InIndex;\r\n  CNum OutIndex;\r\n};\r\n\r\nstruct CFolder\r\n{\r\n  CObjectVector<CCoderInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<CNum> PackStreams;\r\n  CRecordVector<UInt64> UnpackSizes;\r\n  UInt32 UnpackCRC;\r\n  bool UnpackCRCDefined;\r\n\r\n  CFolder(): UnpackCRCDefined(false) {}\r\n\r\n  UInt64 GetUnpackSize() const // test it\r\n  {\r\n    if (UnpackSizes.IsEmpty())\r\n      return 0;\r\n    for (int i = UnpackSizes.Size() - 1; i >= 0; i--)\r\n      if (FindBindPairForOutStream(i) < 0)\r\n        return UnpackSizes[i];\r\n    throw 1;\r\n  }\r\n\r\n  CNum GetNumOutStreams() const\r\n  {\r\n    CNum result = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n      result += Coders[i].NumOutStreams;\r\n    return result;\r\n  }\r\n\r\n  int FindBindPairForInStream(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBindPairForOutStream(CNum outStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindPackStreamArrayIndex(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < PackStreams.Size(); i++)\r\n      if (PackStreams[i] == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  bool CheckStructure() const;\r\n};\r\n\r\nstruct CUInt64DefVector\r\n{\r\n  CRecordVector<UInt64> Values;\r\n  CRecordVector<bool> Defined;\r\n  \r\n  void Clear()\r\n  {\r\n    Values.Clear();\r\n    Defined.Clear();\r\n  }\r\n  \r\n  void ReserveDown()\r\n  {\r\n    Values.ReserveDown();\r\n    Values.ReserveDown();\r\n  }\r\n\r\n  bool GetItem(int index, UInt64 &value) const\r\n  {\r\n    if (index < Defined.Size() && Defined[index])\r\n    {\r\n      value = Values[index];\r\n      return true;\r\n    }\r\n    value = 0;\r\n    return false;\r\n  }\r\n  \r\n  void SetItem(int index, bool defined, UInt64 value)\r\n  {\r\n    while (index >= Defined.Size())\r\n      Defined.Add(false);\r\n    Defined[index] = defined;\r\n    if (!defined)\r\n      return;\r\n    while (index >= Values.Size())\r\n      Values.Add(0);\r\n    Values[index] = value;\r\n  }\r\n\r\n  bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }\r\n};\r\n\r\nstruct CFileItem\r\n{\r\n  UInt64 Size;\r\n  UInt32 Attrib;\r\n  UInt32 Crc;\r\n  UString Name;\r\n\r\n  bool HasStream; // Test it !!! it means that there is\r\n                  // stream in some folder. It can be empty stream\r\n  bool IsDir;\r\n  bool CrcDefined;\r\n  bool AttribDefined;\r\n\r\n  CFileItem():\r\n    HasStream(true),\r\n    IsDir(false),\r\n    CrcDefined(false),\r\n    AttribDefined(false)\r\n      {}\r\n  void SetAttrib(UInt32 attrib)\r\n  {\r\n    AttribDefined = true;\r\n    Attrib = attrib;\r\n  }\r\n};\r\n\r\nstruct CFileItem2\r\n{\r\n  UInt64 CTime;\r\n  UInt64 ATime;\r\n  UInt64 MTime;\r\n  UInt64 StartPos;\r\n  bool CTimeDefined;\r\n  bool ATimeDefined;\r\n  bool MTimeDefined;\r\n  bool StartPosDefined;\r\n  bool IsAnti;\r\n};\r\n\r\nstruct CArchiveDatabase\r\n{\r\n  CRecordVector<UInt64> PackSizes;\r\n  CRecordVector<bool> PackCRCsDefined;\r\n  CRecordVector<UInt32> PackCRCs;\r\n  CObjectVector<CFolder> Folders;\r\n  CRecordVector<CNum> NumUnpackStreamsVector;\r\n  CObjectVector<CFileItem> Files;\r\n\r\n  CUInt64DefVector CTime;\r\n  CUInt64DefVector ATime;\r\n  CUInt64DefVector MTime;\r\n  CUInt64DefVector StartPos;\r\n  CRecordVector<bool> IsAnti;\r\n\r\n  void Clear()\r\n  {\r\n    PackSizes.Clear();\r\n    PackCRCsDefined.Clear();\r\n    PackCRCs.Clear();\r\n    Folders.Clear();\r\n    NumUnpackStreamsVector.Clear();\r\n    Files.Clear();\r\n    CTime.Clear();\r\n    ATime.Clear();\r\n    MTime.Clear();\r\n    StartPos.Clear();\r\n    IsAnti.Clear();\r\n  }\r\n\r\n  void ReserveDown()\r\n  {\r\n    PackSizes.ReserveDown();\r\n    PackCRCsDefined.ReserveDown();\r\n    PackCRCs.ReserveDown();\r\n    Folders.ReserveDown();\r\n    NumUnpackStreamsVector.ReserveDown();\r\n    Files.ReserveDown();\r\n    CTime.ReserveDown();\r\n    ATime.ReserveDown();\r\n    MTime.ReserveDown();\r\n    StartPos.ReserveDown();\r\n    IsAnti.ReserveDown();\r\n  }\r\n\r\n  bool IsEmpty() const\r\n  {\r\n    return (PackSizes.IsEmpty() &&\r\n      PackCRCsDefined.IsEmpty() &&\r\n      PackCRCs.IsEmpty() &&\r\n      Folders.IsEmpty() &&\r\n      NumUnpackStreamsVector.IsEmpty() &&\r\n      Files.IsEmpty());\r\n  }\r\n\r\n  bool CheckNumFiles() const\r\n  {\r\n    int size = Files.Size();\r\n    return (\r\n      CTime.CheckSize(size) &&\r\n      ATime.CheckSize(size) &&\r\n      MTime.CheckSize(size) &&\r\n      StartPos.CheckSize(size) &&\r\n      (size == IsAnti.Size() || IsAnti.Size() == 0));\r\n  }\r\n\r\n  bool IsSolid() const\r\n  {\r\n    for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)\r\n      if (NumUnpackStreamsVector[i] > 1)\r\n        return true;\r\n    return false;\r\n  }\r\n  bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }\r\n  void SetItemAnti(int index, bool isAnti)\r\n  {\r\n    while (index >= IsAnti.Size())\r\n      IsAnti.Add(false);\r\n    IsAnti[index] = isAnti;\r\n  }\r\n\r\n  void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;\r\n  void AddFile(const CFileItem &file, const CFileItem2 &file2);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zOut.cpp",
    "content": "// 7zOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/AutoPtr.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zOut.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nstatic HRESULT WriteBytes(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size > 0)\r\n  {\r\n    UInt32 curSize = (UInt32)MyMin(size, (size_t)0xFFFFFFFF);\r\n    UInt32 processedSize;\r\n    RINOK(stream->Write(data, curSize, &processedSize));\r\n    if (processedSize == 0)\r\n      return E_FAIL;\r\n    data = (const void *)((const Byte *)data + processedSize);\r\n    size -= processedSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nHRESULT COutArchive::WriteDirect(const void *data, UInt32 size)\r\n{\r\n  return ::WriteBytes(SeqStream, data, size);\r\n}\r\n\r\nHRESULT COutArchive::WriteSignature()\r\n{\r\n  Byte buf[8];\r\n  memcpy(buf, kSignature, kSignatureSize);\r\n  buf[kSignatureSize] = kMajorVersion;\r\n  buf[kSignatureSize + 1] = 3;\r\n  return WriteDirect(buf, 8);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishSignature()\r\n{\r\n  RINOK(WriteDirect(kFinishSignature, kSignatureSize));\r\n  CArchiveVersion av;\r\n  av.Major = kMajorVersion;\r\n  av.Minor = 2;\r\n  RINOK(WriteDirectByte(av.Major));\r\n  return WriteDirectByte(av.Minor);\r\n}\r\n#endif\r\n\r\nstatic void SetUInt32(Byte *p, UInt32 d)\r\n{\r\n  for (int i = 0; i < 4; i++, d >>= 8)\r\n    p[i] = (Byte)d;\r\n}\r\n\r\nstatic void SetUInt64(Byte *p, UInt64 d)\r\n{\r\n  for (int i = 0; i < 8; i++, d >>= 8)\r\n    p[i] = (Byte)d;\r\n}\r\n\r\nHRESULT COutArchive::WriteStartHeader(const CStartHeader &h)\r\n{\r\n  Byte buf[24];\r\n  SetUInt64(buf + 4, h.NextHeaderOffset);\r\n  SetUInt64(buf + 12, h.NextHeaderSize);\r\n  SetUInt32(buf + 20, h.NextHeaderCRC);\r\n  SetUInt32(buf, CrcCalc(buf + 4, 20));\r\n  return WriteDirect(buf, 24);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)\r\n{\r\n  CCRC crc;\r\n  crc.UpdateUInt64(h.NextHeaderOffset);\r\n  crc.UpdateUInt64(h.NextHeaderSize);\r\n  crc.UpdateUInt32(h.NextHeaderCRC);\r\n  crc.UpdateUInt64(h.ArchiveStartOffset);\r\n  crc.UpdateUInt64(h.AdditionalStartBlockSize);\r\n  RINOK(WriteDirectUInt32(crc.GetDigest()));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  RINOK(WriteDirectUInt32(h.NextHeaderCRC));\r\n  RINOK(WriteDirectUInt64(h.ArchiveStartOffset));\r\n  return WriteDirectUInt64(h.AdditionalStartBlockSize);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)\r\n{\r\n  Close();\r\n  #ifdef _7Z_VOL\r\n  // endMarker = false;\r\n  _endMarker = endMarker;\r\n  #endif\r\n  SeqStream = stream;\r\n  if (!endMarker)\r\n  {\r\n    SeqStream.QueryInterface(IID_IOutStream, &Stream);\r\n    if (!Stream)\r\n    {\r\n      return E_NOTIMPL;\r\n      // endMarker = true;\r\n    }\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (endMarker)\r\n  {\r\n    /*\r\n    CStartHeader sh;\r\n    sh.NextHeaderOffset = (UInt32)(Int32)-1;\r\n    sh.NextHeaderSize = (UInt32)(Int32)-1;\r\n    sh.NextHeaderCRC = 0;\r\n    WriteStartHeader(sh);\r\n    */\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!Stream)\r\n      return E_FAIL;\r\n    RINOK(WriteSignature());\r\n    RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutArchive::Close()\r\n{\r\n  SeqStream.Release();\r\n  Stream.Release();\r\n}\r\n\r\nHRESULT COutArchive::SkeepPrefixArchiveHeader()\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n    return S_OK;\r\n  #endif\r\n  return Stream->Seek(24, STREAM_SEEK_CUR, NULL);\r\n}\r\n\r\nUInt64 COutArchive::GetPos() const\r\n{\r\n  if (_countMode)\r\n    return _countSize;\r\n  if (_writeToStream)\r\n    return _outByte.GetProcessedSize();\r\n  return _outByte2.GetPos();\r\n}\r\n\r\nvoid COutArchive::WriteBytes(const void *data, size_t size)\r\n{\r\n  if (_countMode)\r\n    _countSize += size;\r\n  else if (_writeToStream)\r\n  {\r\n    _outByte.WriteBytes(data, size);\r\n    _crc = CrcUpdate(_crc, data, size);\r\n  }\r\n  else\r\n    _outByte2.WriteBytes(data, size);\r\n}\r\n\r\nvoid COutArchive::WriteByte(Byte b)\r\n{\r\n  if (_countMode)\r\n    _countSize++;\r\n  else if (_writeToStream)\r\n  {\r\n    _outByte.WriteByte(b);\r\n    _crc = CRC_UPDATE_BYTE(_crc, b);\r\n  }\r\n  else\r\n    _outByte2.WriteByte(b);\r\n}\r\n\r\nvoid COutArchive::WriteUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nvoid COutArchive::WriteUInt64(UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nvoid COutArchive::WriteNumber(UInt64 value)\r\n{\r\n  Byte firstByte = 0;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n    {\r\n      firstByte |= Byte(value >> (8 * i));\r\n      break;\r\n    }\r\n    firstByte |= mask;\r\n    mask >>= 1;\r\n  }\r\n  WriteByte(firstByte);\r\n  for (;i > 0; i--)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nstatic UInt32 GetBigNumberSize(UInt64 value)\r\n{\r\n  int i;\r\n  for (i = 1; i < 9; i++)\r\n    if (value < (((UInt64)1 << (i * 7))))\r\n      break;\r\n  return i;\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nUInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)\r\n{\r\n  UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;\r\n  if (nameLength != 0)\r\n  {\r\n    nameLength = (nameLength + 1) * 2;\r\n    result += nameLength + GetBigNumberSize(nameLength) + 2;\r\n  }\r\n  if (props)\r\n  {\r\n    result += 20;\r\n  }\r\n  if (result >= 128)\r\n    result++;\r\n  result += kSignatureSize + 2 + kFinishHeaderSize;\r\n  return result;\r\n}\r\n\r\nUInt64 COutArchive::GetVolPureSize(UInt64 volSize, int nameLength, bool props)\r\n{\r\n  UInt32 headersSizeBase = COutArchive::GetVolHeadersSize(1, nameLength, props);\r\n  int testSize;\r\n  if (volSize > headersSizeBase)\r\n    testSize = volSize - headersSizeBase;\r\n  else\r\n    testSize = 1;\r\n  UInt32 headersSize = COutArchive::GetVolHeadersSize(testSize, nameLength, props);\r\n  UInt64 pureSize = 1;\r\n  if (volSize > headersSize)\r\n    pureSize = volSize - headersSize;\r\n  return pureSize;\r\n}\r\n#endif\r\n\r\nvoid COutArchive::WriteFolder(const CFolder &folder)\r\n{\r\n  WriteNumber(folder.Coders.Size());\r\n  int i;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    const CCoderInfo &coder = folder.Coders[i];\r\n    {\r\n      size_t propsSize = coder.Props.GetCapacity();\r\n      \r\n      UInt64 id = coder.MethodID;\r\n      int idSize;\r\n      for (idSize = 1; idSize < sizeof(id); idSize++)\r\n        if ((id >> (8 * idSize)) == 0)\r\n          break;\r\n      BYTE longID[15];\r\n      for (int t = idSize - 1; t >= 0 ; t--, id >>= 8)\r\n        longID[t] = (Byte)(id & 0xFF);\r\n      Byte b;\r\n      b = (Byte)(idSize & 0xF);\r\n      bool isComplex = !coder.IsSimpleCoder();\r\n      b |= (isComplex ? 0x10 : 0);\r\n      b |= ((propsSize != 0) ? 0x20 : 0 );\r\n      WriteByte(b);\r\n      WriteBytes(longID, idSize);\r\n      if (isComplex)\r\n      {\r\n        WriteNumber(coder.NumInStreams);\r\n        WriteNumber(coder.NumOutStreams);\r\n      }\r\n      if (propsSize == 0)\r\n        continue;\r\n      WriteNumber(propsSize);\r\n      WriteBytes(coder.Props, propsSize);\r\n    }\r\n  }\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = folder.BindPairs[i];\r\n    WriteNumber(bindPair.InIndex);\r\n    WriteNumber(bindPair.OutIndex);\r\n  }\r\n  if (folder.PackStreams.Size() > 1)\r\n    for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    {\r\n      WriteNumber(folder.PackStreams[i]);\r\n    }\r\n}\r\n\r\nvoid COutArchive::WriteBoolVector(const CBoolVector &boolVector)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0x80;\r\n  for (int i = 0; i < boolVector.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n      b |= mask;\r\n    mask >>= 1;\r\n    if (mask == 0)\r\n    {\r\n      WriteByte(b);\r\n      mask = 0x80;\r\n      b = 0;\r\n    }\r\n  }\r\n  if (mask != 0x80)\r\n    WriteByte(b);\r\n}\r\n\r\n\r\nvoid COutArchive::WriteHashDigests(\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  int numDefined = 0;\r\n  int i;\r\n  for (i = 0; i < digestsDefined.Size(); i++)\r\n    if (digestsDefined[i])\r\n      numDefined++;\r\n  if (numDefined == 0)\r\n    return;\r\n\r\n  WriteByte(NID::kCRC);\r\n  if (numDefined == digestsDefined.Size())\r\n    WriteByte(1);\r\n  else\r\n  {\r\n    WriteByte(0);\r\n    WriteBoolVector(digestsDefined);\r\n  }\r\n  for (i = 0; i < digests.Size(); i++)\r\n    if (digestsDefined[i])\r\n      WriteUInt32(digests[i]);\r\n}\r\n\r\nvoid COutArchive::WritePackInfo(\r\n    UInt64 dataOffset,\r\n    const CRecordVector<UInt64> &packSizes,\r\n    const CRecordVector<bool> &packCRCsDefined,\r\n    const CRecordVector<UInt32> &packCRCs)\r\n{\r\n  if (packSizes.IsEmpty())\r\n    return;\r\n  WriteByte(NID::kPackInfo);\r\n  WriteNumber(dataOffset);\r\n  WriteNumber(packSizes.Size());\r\n  WriteByte(NID::kSize);\r\n  for (int i = 0; i < packSizes.Size(); i++)\r\n    WriteNumber(packSizes[i]);\r\n\r\n  WriteHashDigests(packCRCsDefined, packCRCs);\r\n  \r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::WriteUnpackInfo(const CObjectVector<CFolder> &folders)\r\n{\r\n  if (folders.IsEmpty())\r\n    return;\r\n\r\n  WriteByte(NID::kUnpackInfo);\r\n\r\n  WriteByte(NID::kFolder);\r\n  WriteNumber(folders.Size());\r\n  {\r\n    WriteByte(0);\r\n    for (int i = 0; i < folders.Size(); i++)\r\n      WriteFolder(folders[i]);\r\n  }\r\n  \r\n  WriteByte(NID::kCodersUnpackSize);\r\n  int i;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    for (int j = 0; j < folder.UnpackSizes.Size(); j++)\r\n      WriteNumber(folder.UnpackSizes[j]);\r\n  }\r\n\r\n  CRecordVector<bool> unpackCRCsDefined;\r\n  CRecordVector<UInt32> unpackCRCs;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    unpackCRCsDefined.Add(folder.UnpackCRCDefined);\r\n    unpackCRCs.Add(folder.UnpackCRC);\r\n  }\r\n  WriteHashDigests(unpackCRCsDefined, unpackCRCs);\r\n\r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::WriteSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    const CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    const CRecordVector<UInt64> &unpackSizes,\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  WriteByte(NID::kSubStreamsInfo);\r\n\r\n  int i;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n  {\r\n    if (numUnpackStreamsInFolders[i] != 1)\r\n    {\r\n      WriteByte(NID::kNumUnpackStream);\r\n      for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n        WriteNumber(numUnpackStreamsInFolders[i]);\r\n      break;\r\n    }\r\n  }\r\n \r\n\r\n  bool needFlag = true;\r\n  CNum index = 0;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n    for (CNum j = 0; j < numUnpackStreamsInFolders[i]; j++)\r\n    {\r\n      if (j + 1 != numUnpackStreamsInFolders[i])\r\n      {\r\n        if (needFlag)\r\n          WriteByte(NID::kSize);\r\n        needFlag = false;\r\n        WriteNumber(unpackSizes[index]);\r\n      }\r\n      index++;\r\n    }\r\n\r\n  CRecordVector<bool> digestsDefined2;\r\n  CRecordVector<UInt32> digests2;\r\n\r\n  int digestIndex = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    int numSubStreams = (int)numUnpackStreamsInFolders[i];\r\n    if (numSubStreams == 1 && folders[i].UnpackCRCDefined)\r\n      digestIndex++;\r\n    else\r\n      for (int j = 0; j < numSubStreams; j++, digestIndex++)\r\n      {\r\n        digestsDefined2.Add(digestsDefined[digestIndex]);\r\n        digests2.Add(digests[digestIndex]);\r\n      }\r\n  }\r\n  WriteHashDigests(digestsDefined2, digests2);\r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::SkipAlign(unsigned /* pos */, unsigned /* alignSize */)\r\n{\r\n  return;\r\n}\r\n\r\n/*\r\n7-Zip 4.50 - 4.58 contain BUG, so they do not support .7z archives with Unknown field.\r\n\r\nvoid COutArchive::SkipAlign(unsigned pos, unsigned alignSize)\r\n{\r\n  pos += (unsigned)GetPos();\r\n  pos &= (alignSize - 1);\r\n  if (pos == 0)\r\n    return;\r\n  unsigned skip = alignSize - pos;\r\n  if (skip < 2)\r\n    skip += alignSize;\r\n  skip -= 2;\r\n  WriteByte(NID::kDummy);\r\n  WriteByte((Byte)skip);\r\n  for (unsigned i = 0; i < skip; i++)\r\n    WriteByte(0);\r\n}\r\n*/\r\n\r\nvoid COutArchive::WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize)\r\n{\r\n  const UInt64 bvSize = (numDefined == v.Size()) ? 0 : (v.Size() + 7) / 8;\r\n  const UInt64 dataSize = (UInt64)numDefined * itemSize + bvSize + 2;\r\n  SkipAlign(3 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), itemSize);\r\n\r\n  WriteByte(type);\r\n  WriteNumber(dataSize);\r\n  if (numDefined == v.Size())\r\n    WriteByte(1);\r\n  else\r\n  {\r\n    WriteByte(0);\r\n    WriteBoolVector(v);\r\n  }\r\n  WriteByte(0);\r\n}\r\n\r\nvoid COutArchive::WriteUInt64DefVector(const CUInt64DefVector &v, Byte type)\r\n{\r\n  int numDefined = 0;\r\n\r\n  int i;\r\n  for (i = 0; i < v.Defined.Size(); i++)\r\n    if (v.Defined[i])\r\n      numDefined++;\r\n\r\n  if (numDefined == 0)\r\n    return;\r\n\r\n  WriteAlignedBoolHeader(v.Defined, numDefined, type, 8);\r\n  \r\n  for (i = 0; i < v.Defined.Size(); i++)\r\n    if (v.Defined[i])\r\n      WriteUInt64(v.Values[i]);\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const Byte *data, size_t dataSize,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  CSequentialInStreamImp *streamSpec = new CSequentialInStreamImp;\r\n  CMyComPtr<ISequentialInStream> stream = streamSpec;\r\n  streamSpec->Init(data, dataSize);\r\n  CFolder folderItem;\r\n  folderItem.UnpackCRCDefined = true;\r\n  folderItem.UnpackCRC = CrcCalc(data, dataSize);\r\n  UInt64 dataSize64 = dataSize;\r\n  RINOK(encoder.Encode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      stream, NULL, &dataSize64, folderItem, SeqStream, packSizes, NULL))\r\n  folders.Add(folderItem);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const CByteBuffer &data,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  return EncodeStream(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      encoder, data, data.GetCapacity(), packSizes, folders);\r\n}\r\n\r\nvoid COutArchive::WriteHeader(\r\n    const CArchiveDatabase &db,\r\n    const CHeaderOptions &headerOptions,\r\n    UInt64 &headerOffset)\r\n{\r\n  int i;\r\n  \r\n  UInt64 packedSize = 0;\r\n  for (i = 0; i < db.PackSizes.Size(); i++)\r\n    packedSize += db.PackSizes[i];\r\n\r\n  headerOffset = packedSize;\r\n\r\n  WriteByte(NID::kHeader);\r\n\r\n  // Archive Properties\r\n\r\n  if (db.Folders.Size() > 0)\r\n  {\r\n    WriteByte(NID::kMainStreamsInfo);\r\n    WritePackInfo(0, db.PackSizes,\r\n        db.PackCRCsDefined,\r\n        db.PackCRCs);\r\n\r\n    WriteUnpackInfo(db.Folders);\r\n\r\n    CRecordVector<UInt64> unpackSizes;\r\n    CRecordVector<bool> digestsDefined;\r\n    CRecordVector<UInt32> digests;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = db.Files[i];\r\n      if (!file.HasStream)\r\n        continue;\r\n      unpackSizes.Add(file.Size);\r\n      digestsDefined.Add(file.CrcDefined);\r\n      digests.Add(file.Crc);\r\n    }\r\n\r\n    WriteSubStreamsInfo(\r\n        db.Folders,\r\n        db.NumUnpackStreamsVector,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    WriteByte(NID::kEnd);\r\n  }\r\n\r\n  if (db.Files.IsEmpty())\r\n  {\r\n    WriteByte(NID::kEnd);\r\n    return;\r\n  }\r\n\r\n  WriteByte(NID::kFilesInfo);\r\n  WriteNumber(db.Files.Size());\r\n\r\n  {\r\n  /* ---------- Empty Streams ---------- */\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve(db.Files.Size());\r\n  int numEmptyStreams = 0;\r\n  for (i = 0; i < db.Files.Size(); i++)\r\n    if (db.Files[i].HasStream)\r\n      emptyStreamVector.Add(false);\r\n    else\r\n    {\r\n      emptyStreamVector.Add(true);\r\n      numEmptyStreams++;\r\n    }\r\n  if (numEmptyStreams > 0)\r\n  {\r\n    WriteByte(NID::kEmptyStream);\r\n    WriteNumber((emptyStreamVector.Size() + 7) / 8);\r\n    WriteBoolVector(emptyStreamVector);\r\n\r\n    CBoolVector emptyFileVector, antiVector;\r\n    emptyFileVector.Reserve(numEmptyStreams);\r\n    antiVector.Reserve(numEmptyStreams);\r\n    CNum numEmptyFiles = 0, numAntiItems = 0;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = db.Files[i];\r\n      if (!file.HasStream)\r\n      {\r\n        emptyFileVector.Add(!file.IsDir);\r\n        if (!file.IsDir)\r\n          numEmptyFiles++;\r\n        bool isAnti = db.IsItemAnti(i);\r\n        antiVector.Add(isAnti);\r\n        if (isAnti)\r\n          numAntiItems++;\r\n      }\r\n    }\r\n\r\n    if (numEmptyFiles > 0)\r\n    {\r\n      WriteByte(NID::kEmptyFile);\r\n      WriteNumber((emptyFileVector.Size() + 7) / 8);\r\n      WriteBoolVector(emptyFileVector);\r\n    }\r\n\r\n    if (numAntiItems > 0)\r\n    {\r\n      WriteByte(NID::kAnti);\r\n      WriteNumber((antiVector.Size() + 7) / 8);\r\n      WriteBoolVector(antiVector);\r\n    }\r\n  }\r\n  }\r\n\r\n\r\n  {\r\n    /* ---------- Names ---------- */\r\n    \r\n    int numDefined = 0;\r\n    size_t namesDataSize = 0;\r\n    for (int i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const UString &name = db.Files[i].Name;\r\n      if (!name.IsEmpty())\r\n        numDefined++;\r\n      namesDataSize += (name.Length() + 1) * 2;\r\n    }\r\n    \r\n    if (numDefined > 0)\r\n    {\r\n      namesDataSize++;\r\n      SkipAlign(2 + GetBigNumberSize(namesDataSize), 2);\r\n\r\n      WriteByte(NID::kName);\r\n      WriteNumber(namesDataSize);\r\n      WriteByte(0);\r\n      for (int i = 0; i < db.Files.Size(); i++)\r\n      {\r\n        const UString &name = db.Files[i].Name;\r\n        for (int t = 0; t <= name.Length(); t++)\r\n        {\r\n          wchar_t c = name[t];\r\n          WriteByte((Byte)c);\r\n          WriteByte((Byte)(c >> 8));\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (headerOptions.WriteCTime) WriteUInt64DefVector(db.CTime, NID::kCTime);\r\n  if (headerOptions.WriteATime) WriteUInt64DefVector(db.ATime, NID::kATime);\r\n  if (headerOptions.WriteMTime) WriteUInt64DefVector(db.MTime, NID::kMTime);\r\n  WriteUInt64DefVector(db.StartPos, NID::kStartPos);\r\n  \r\n  {\r\n    /* ---------- Write Attrib ---------- */\r\n    CBoolVector boolVector;\r\n    boolVector.Reserve(db.Files.Size());\r\n    int numDefined = 0;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      bool defined = db.Files[i].AttribDefined;\r\n      boolVector.Add(defined);\r\n      if (defined)\r\n        numDefined++;\r\n    }\r\n    if (numDefined > 0)\r\n    {\r\n      WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttributes, 4);\r\n      for (i = 0; i < db.Files.Size(); i++)\r\n      {\r\n        const CFileItem &file = db.Files[i];\r\n        if (file.AttribDefined)\r\n          WriteUInt32(file.Attrib);\r\n      }\r\n    }\r\n  }\r\n\r\n  WriteByte(NID::kEnd); // for files\r\n  WriteByte(NID::kEnd); // for headers\r\n}\r\n\r\nHRESULT COutArchive::WriteDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CArchiveDatabase &db,\r\n    const CCompressionMethodMode *options,\r\n    const CHeaderOptions &headerOptions)\r\n{\r\n  if (!db.CheckNumFiles())\r\n    return E_FAIL;\r\n\r\n  UInt64 headerOffset;\r\n  UInt32 headerCRC;\r\n  UInt64 headerSize;\r\n  if (db.IsEmpty())\r\n  {\r\n    headerSize = 0;\r\n    headerOffset = 0;\r\n    headerCRC = CrcCalc(0, 0);\r\n  }\r\n  else\r\n  {\r\n    bool encodeHeaders = false;\r\n    if (options != 0)\r\n      if (options->IsEmpty())\r\n        options = 0;\r\n    if (options != 0)\r\n      if (options->PasswordIsDefined || headerOptions.CompressMainHeader)\r\n        encodeHeaders = true;\r\n\r\n    _outByte.SetStream(SeqStream);\r\n    _outByte.Init();\r\n    _crc = CRC_INIT_VAL;\r\n    _countMode = encodeHeaders;\r\n    _writeToStream = true;\r\n    _countSize = 0;\r\n    WriteHeader(db, headerOptions, headerOffset);\r\n\r\n    if (encodeHeaders)\r\n    {\r\n      CByteBuffer buf;\r\n      buf.SetCapacity(_countSize);\r\n      _outByte2.Init((Byte *)buf, _countSize);\r\n      \r\n      _countMode = false;\r\n      _writeToStream = false;\r\n      WriteHeader(db, headerOptions, headerOffset);\r\n      \r\n      if (_countSize != _outByte2.GetPos())\r\n        return E_FAIL;\r\n\r\n      CCompressionMethodMode encryptOptions;\r\n      encryptOptions.PasswordIsDefined = options->PasswordIsDefined;\r\n      encryptOptions.Password = options->Password;\r\n      CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions);\r\n      CRecordVector<UInt64> packSizes;\r\n      CObjectVector<CFolder> folders;\r\n      RINOK(EncodeStream(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          encoder, (const Byte *)buf,\r\n          _countSize, packSizes, folders));\r\n\r\n      _writeToStream = true;\r\n      \r\n      if (folders.Size() == 0)\r\n        throw 1;\r\n\r\n      WriteID(NID::kEncodedHeader);\r\n      WritePackInfo(headerOffset, packSizes,\r\n        CRecordVector<bool>(), CRecordVector<UInt32>());\r\n      WriteUnpackInfo(folders);\r\n      WriteByte(NID::kEnd);\r\n      for (int i = 0; i < packSizes.Size(); i++)\r\n        headerOffset += packSizes[i];\r\n    }\r\n    RINOK(_outByte.Flush());\r\n    headerCRC = CRC_GET_DIGEST(_crc);\r\n    headerSize = _outByte.GetProcessedSize();\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n  {\r\n    CFinishHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset =\r\n        UInt64(0) - (headerSize +\r\n        4 + kFinishHeaderSize);\r\n    h.ArchiveStartOffset = h.NextHeaderOffset - headerOffset;\r\n    h.AdditionalStartBlockSize = 0;\r\n    RINOK(WriteFinishHeader(h));\r\n    return WriteFinishSignature();\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    CStartHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = headerOffset;\r\n    RINOK(Stream->Seek(_prefixHeaderPos, STREAM_SEEK_SET, NULL));\r\n    return WriteStartHeader(h);\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabase::GetFile(int index, CFileItem &file, CFileItem2 &file2) const\r\n{\r\n  file = Files[index];\r\n  file2.CTimeDefined = CTime.GetItem(index, file2.CTime);\r\n  file2.ATimeDefined = ATime.GetItem(index, file2.ATime);\r\n  file2.MTimeDefined = MTime.GetItem(index, file2.MTime);\r\n  file2.StartPosDefined = StartPos.GetItem(index, file2.StartPos);\r\n  file2.IsAnti = IsItemAnti(index);\r\n}\r\n\r\nvoid CArchiveDatabase::AddFile(const CFileItem &file, const CFileItem2 &file2)\r\n{\r\n  int index = Files.Size();\r\n  CTime.SetItem(index, file2.CTimeDefined, file2.CTime);\r\n  ATime.SetItem(index, file2.ATimeDefined, file2.ATime);\r\n  MTime.SetItem(index, file2.MTimeDefined, file2.MTime);\r\n  StartPos.SetItem(index, file2.StartPosDefined, file2.StartPos);\r\n  SetItemAnti(index, file2.IsAnti);\r\n  Files.Add(file);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zOut.h",
    "content": "// 7z/Out.h\r\n\r\n#ifndef __7Z_OUT_H\r\n#define __7Z_OUT_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zCompressionMode.h\"\r\n#include \"7zEncode.h\"\r\n\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CWriteBufferLoc\r\n{\r\n  Byte *_data;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  CWriteBufferLoc(): _size(0), _pos(0) {}\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    _data = data;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    if (size > _size - _pos)\r\n      throw 1;\r\n    memcpy(_data + _pos, data, size);\r\n    _pos += size;\r\n  }\r\n  void WriteByte(Byte b)\r\n  {\r\n    if (_size == _pos)\r\n      throw 1;\r\n    _data[_pos++] = b;\r\n  }\r\n  size_t GetPos() const { return _pos; }\r\n};\r\n\r\nstruct CHeaderOptions\r\n{\r\n  bool CompressMainHeader;\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  CHeaderOptions():\r\n      CompressMainHeader(true),\r\n      WriteCTime(false),\r\n      WriteATime(false),\r\n      WriteMTime(true)\r\n      {}\r\n};\r\n\r\nclass COutArchive\r\n{\r\n  UInt64 _prefixHeaderPos;\r\n\r\n  HRESULT WriteDirect(const void *data, UInt32 size);\r\n  \r\n  UInt64 GetPos() const;\r\n  void WriteBytes(const void *data, size_t size);\r\n  void WriteBytes(const CByteBuffer &data) { WriteBytes(data, data.GetCapacity()); }\r\n  void WriteByte(Byte b);\r\n  void WriteUInt32(UInt32 value);\r\n  void WriteUInt64(UInt64 value);\r\n  void WriteNumber(UInt64 value);\r\n  void WriteID(UInt64 value) { WriteNumber(value); }\r\n\r\n  void WriteFolder(const CFolder &folder);\r\n  HRESULT WriteFileHeader(const CFileItem &itemInfo);\r\n  void WriteBoolVector(const CBoolVector &boolVector);\r\n  void WriteHashDigests(\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  void WritePackInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs);\r\n\r\n  void WriteUnpackInfo(const CObjectVector<CFolder> &folders);\r\n\r\n  void WriteSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unpackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  void SkipAlign(unsigned pos, unsigned alignSize);\r\n  void WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize);\r\n  void WriteUInt64DefVector(const CUInt64DefVector &v, Byte type);\r\n\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const Byte *data, size_t dataSize,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const CByteBuffer &data,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  void WriteHeader(\r\n      const CArchiveDatabase &db,\r\n      const CHeaderOptions &headerOptions,\r\n      UInt64 &headerOffset);\r\n  \r\n  bool _countMode;\r\n  bool _writeToStream;\r\n  size_t _countSize;\r\n  UInt32 _crc;\r\n  COutBuffer _outByte;\r\n  CWriteBufferLoc _outByte2;\r\n\r\n  #ifdef _7Z_VOL\r\n  bool _endMarker;\r\n  #endif\r\n\r\n  HRESULT WriteSignature();\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishSignature();\r\n  #endif\r\n  HRESULT WriteStartHeader(const CStartHeader &h);\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishHeader(const CFinishHeader &h);\r\n  #endif\r\n  CMyComPtr<IOutStream> Stream;\r\npublic:\r\n\r\n  COutArchive() { _outByte.Create(1 << 16); }\r\n  CMyComPtr<ISequentialOutStream> SeqStream;\r\n  HRESULT Create(ISequentialOutStream *stream, bool endMarker);\r\n  void Close();\r\n  HRESULT SkeepPrefixArchiveHeader();\r\n  HRESULT WriteDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CArchiveDatabase &db,\r\n      const CCompressionMethodMode *options,\r\n      const CHeaderOptions &headerOptions);\r\n\r\n  #ifdef _7Z_VOL\r\n  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);\r\n  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);\r\n  #endif\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zProperties.cpp",
    "content": "// 7zProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zProperties.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zHandler.h\"\r\n\r\n// #define _MULTI_PACK\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CPropMap\r\n{\r\n  UInt64 FilePropID;\r\n  STATPROPSTG StatPROPSTG;\r\n};\r\n\r\nCPropMap kPropMap[] =\r\n{\r\n  { NID::kName, NULL, kpidPath, VT_BSTR},\r\n  { NID::kSize, NULL, kpidSize, VT_UI8},\r\n  { NID::kPackInfo, NULL, kpidPackSize, VT_UI8},\r\n  \r\n  #ifdef _MULTI_PACK\r\n  { 100, L\"Pack0\", kpidPackedSize0, VT_UI8},\r\n  { 101, L\"Pack1\", kpidPackedSize1, VT_UI8},\r\n  { 102, L\"Pack2\", kpidPackedSize2, VT_UI8},\r\n  { 103, L\"Pack3\", kpidPackedSize3, VT_UI8},\r\n  { 104, L\"Pack4\", kpidPackedSize4, VT_UI8},\r\n  #endif\r\n\r\n  { NID::kCTime, NULL, kpidCTime, VT_FILETIME},\r\n  { NID::kMTime, NULL, kpidMTime, VT_FILETIME},\r\n  { NID::kATime, NULL, kpidATime, VT_FILETIME},\r\n  { NID::kWinAttributes, NULL, kpidAttrib, VT_UI4},\r\n  { NID::kStartPos, NULL, kpidPosition, VT_UI4},\r\n\r\n  { NID::kCRC, NULL, kpidCRC, VT_UI4},\r\n  \r\n  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},\r\n\r\n  #ifndef _SFX\r\n  { 97, NULL, kpidEncrypted, VT_BOOL},\r\n  { 98, NULL, kpidMethod, VT_BSTR},\r\n  { 99, NULL, kpidBlock, VT_UI4}\r\n  #endif\r\n};\r\n\r\nstatic const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);\r\n\r\nstatic int FindPropInMap(UInt64 filePropID)\r\n{\r\n  for (int i = 0; i < kPropMapSize; i++)\r\n    if (kPropMap[i].FilePropID == filePropID)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void CopyOneItem(CRecordVector<UInt64> &src,\r\n    CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      dest.Add(item);\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < dest.Size(); i++)\r\n    if (dest[i] == item)\r\n    {\r\n      dest.Delete(i);\r\n      break;\r\n    }\r\n  dest.Insert(0, item);\r\n}\r\n\r\nvoid CHandler::FillPopIDs()\r\n{\r\n  _fileInfoPopIDs.Clear();\r\n\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() < 1)\r\n    return;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_db = volume.Database;\r\n  #endif\r\n\r\n  CRecordVector<UInt64> fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;\r\n\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);\r\n\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);\r\n  _fileInfoPopIDs += fileInfoPopIDs;\r\n \r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Add(97);\r\n  _fileInfoPopIDs.Add(98);\r\n  _fileInfoPopIDs.Add(99);\r\n  #endif\r\n  #ifdef _MULTI_PACK\r\n  _fileInfoPopIDs.Add(100);\r\n  _fileInfoPopIDs.Add(101);\r\n  _fileInfoPopIDs.Add(102);\r\n  _fileInfoPopIDs.Add(103);\r\n  _fileInfoPopIDs.Add(104);\r\n  #endif\r\n\r\n  #ifndef _SFX\r\n  InsertToHead(_fileInfoPopIDs, NID::kMTime);\r\n  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);\r\n  InsertToHead(_fileInfoPopIDs, NID::kSize);\r\n  InsertToHead(_fileInfoPopIDs, NID::kName);\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)\r\n{\r\n  *numProperties = _fileInfoPopIDs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)\r\n{\r\n  if ((int)index >= _fileInfoPopIDs.Size())\r\n    return E_INVALIDARG;\r\n  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);\r\n  if (indexInMap == -1)\r\n    return E_INVALIDARG;\r\n  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;\r\n  *propID = srcItem.propid;\r\n  *varType = srcItem.vt;\r\n  *name = 0;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zProperties.h",
    "content": "// 7zProperties.h\r\n\r\n#ifndef __7Z_PROPERTIES_H\r\n#define __7Z_PROPERTIES_H\r\n\r\n#include \"../../PropID.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nenum\r\n{\r\n  kpidPackedSize0 = kpidUserDefined,\r\n  kpidPackedSize1,\r\n  kpidPackedSize2,\r\n  kpidPackedSize3,\r\n  kpidPackedSize4\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zRegister.cpp",
    "content": "// 7zRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"7zHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::N7z::CHandler;  }\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"7z\", L\"7z\", 0, 7, {'7' + 1 , 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };\r\n\r\nREGISTER_ARC_DEC_SIG(7z)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zSpecStream.cpp",
    "content": "// 7zSpecStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zSpecStream.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(\r\n    UInt64 subStream, UInt64 *value)\r\n{\r\n  if (_getSubStreamSize == NULL)\r\n    return E_NOTIMPL;\r\n  return  _getSubStreamSize->GetSubStreamSize(subStream, value);\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zSpecStream.h",
    "content": "// 7zSpecStream.h\r\n\r\n#ifndef __7Z_SPEC_STREAM_H\r\n#define __7Z_SPEC_STREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CSequentialInStreamSizeCount2:\r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _getSubStreamSize = 0;\r\n    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zUpdate.cpp",
    "content": "// 7zUpdate.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zFolderInStream.h\"\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kMatchFinderForBCJ2_LZMA = L\"BT2\";\r\nstatic const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;\r\nstatic const UInt32 kAlgorithmForBCJ2_LZMA = 1;\r\nstatic const UInt32 kNumFastBytesForBCJ2_LZMA = 64;\r\n\r\nstatic HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream,\r\n    UInt64 position, UInt64 size, ICompressProgressInfo *progress)\r\n{\r\n  RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));\r\n  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;\r\n  CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);\r\n  streamSpec->SetStream(inStream);\r\n  streamSpec->Init(size);\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n  RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));\r\n  return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);\r\n}\r\n\r\nstatic int GetReverseSlashPos(const UString &name)\r\n{\r\n  int slashPos = name.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = name.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n  return slashPos;\r\n}\r\n\r\nint CUpdateItem::GetExtensionPos() const\r\n{\r\n  int slashPos = GetReverseSlashPos(Name);\r\n  int dotPos = Name.ReverseFind(L'.');\r\n  if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n    return Name.Length();\r\n  return dotPos + 1;\r\n}\r\n\r\nUString CUpdateItem::GetExtension() const\r\n{\r\n  return Name.Mid(GetExtensionPos());\r\n}\r\n\r\n#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }\r\n\r\nstatic int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)\r\n{\r\n  size_t c1 = a1.GetCapacity();\r\n  size_t c2 = a2.GetCapacity();\r\n  RINOZ(MyCompare(c1, c2));\r\n  for (size_t i = 0; i < c1; i++)\r\n    RINOZ(MyCompare(a1[i], a2[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareCoders(const CCoderInfo &c1, const CCoderInfo &c2)\r\n{\r\n  RINOZ(MyCompare(c1.NumInStreams, c2.NumInStreams));\r\n  RINOZ(MyCompare(c1.NumOutStreams, c2.NumOutStreams));\r\n  RINOZ(MyCompare(c1.MethodID, c2.MethodID));\r\n  return CompareBuffers(c1.Props, c2.Props);\r\n}\r\n\r\nstatic int CompareBindPairs(const CBindPair &b1, const CBindPair &b2)\r\n{\r\n  RINOZ(MyCompare(b1.InIndex, b2.InIndex));\r\n  return MyCompare(b1.OutIndex, b2.OutIndex);\r\n}\r\n\r\nstatic int CompareFolders(const CFolder &f1, const CFolder &f2)\r\n{\r\n  int s1 = f1.Coders.Size();\r\n  int s2 = f2.Coders.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  int i;\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareCoders(f1.Coders[i], f2.Coders[i]));\r\n  s1 = f1.BindPairs.Size();\r\n  s2 = f2.BindPairs.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareBindPairs(f1.BindPairs[i], f2.BindPairs[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareFiles(const CFileItem &f1, const CFileItem &f2)\r\n{\r\n  return MyStringCompareNoCase(f1.Name, f2.Name);\r\n}\r\n\r\nstatic int CompareFolderRefs(const int *p1, const int *p2, void *param)\r\n{\r\n  int i1 = *p1;\r\n  int i2 = *p2;\r\n  const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param;\r\n  RINOZ(CompareFolders(\r\n      db.Folders[i1],\r\n      db.Folders[i2]));\r\n  RINOZ(MyCompare(\r\n      db.NumUnpackStreamsVector[i1],\r\n      db.NumUnpackStreamsVector[i2]));\r\n  if (db.NumUnpackStreamsVector[i1] == 0)\r\n    return 0;\r\n  return CompareFiles(\r\n      db.Files[db.FolderStartFileIndex[i1]],\r\n      db.Files[db.FolderStartFileIndex[i2]]);\r\n}\r\n\r\n////////////////////////////////////////////////////////////\r\n\r\nstatic int CompareEmptyItems(const int *p1, const int *p2, void *param)\r\n{\r\n  const CObjectVector<CUpdateItem> &updateItems = *(const CObjectVector<CUpdateItem> *)param;\r\n  const CUpdateItem &u1 = updateItems[*p1];\r\n  const CUpdateItem &u2 = updateItems[*p2];\r\n  if (u1.IsDir != u2.IsDir)\r\n    return (u1.IsDir) ? 1 : -1;\r\n  if (u1.IsDir)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    int n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  if (u1.IsAnti != u2.IsAnti)\r\n    return (u1.IsAnti ? 1 : -1);\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstatic const char *g_Exts =\r\n  \" lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo\"\r\n  \" zip jar ear war msi\"\r\n  \" 3gp avi mov mpeg mpg mpe wmv\"\r\n  \" aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav\"\r\n  \" swf \"\r\n  \" chm hxi hxs\"\r\n  \" gif jpeg jpg jp2 png tiff  bmp ico psd psp\"\r\n  \" awg ps eps cgm dxf svg vrml wmf emf ai md\"\r\n  \" cad dwg pps key sxi\"\r\n  \" max 3ds\"\r\n  \" iso bin nrg mdf img pdi tar cpio xpi\"\r\n  \" vfd vhd vud vmc vsv\"\r\n  \" vmdk dsk nvram vmem vmsd vmsn vmss vmtm\"\r\n  \" inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def\"\r\n  \" f77 f f90 f95\"\r\n  \" asm sql manifest dep \"\r\n  \" mak clw csproj vcproj sln dsp dsw \"\r\n  \" class \"\r\n  \" bat cmd\"\r\n  \" xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml\"\r\n  \" awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs\"\r\n  \" text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf\"\r\n  \" sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf\"\r\n  \" abw afp cwk lwp wpd wps wpt wrf wri\"\r\n  \" abf afm bdf fon mgf otf pcf pfa snf ttf\"\r\n  \" dbf mdb nsf ntf wdb db fdb gdb\"\r\n  \" exe dll ocx vbx sfx sys tlb awx com obj lib out o so \"\r\n  \" pdb pch idb ncb opt\";\r\n\r\nint GetExtIndex(const char *ext)\r\n{\r\n  int extIndex = 1;\r\n  const char *p = g_Exts;\r\n  for (;;)\r\n  {\r\n    char c = *p++;\r\n    if (c == 0)\r\n      return extIndex;\r\n    if (c == ' ')\r\n      continue;\r\n    int pos = 0;\r\n    for (;;)\r\n    {\r\n      char c2 = ext[pos++];\r\n      if (c2 == 0 && (c == 0 || c == ' '))\r\n        return extIndex;\r\n      if (c != c2)\r\n        break;\r\n      c = *p++;\r\n    }\r\n    extIndex++;\r\n    for (;;)\r\n    {\r\n      if (c == 0)\r\n        return extIndex;\r\n      if (c == ' ')\r\n        break;\r\n      c = *p++;\r\n    }\r\n  }\r\n}\r\n\r\nstruct CRefItem\r\n{\r\n  const CUpdateItem *UpdateItem;\r\n  UInt32 Index;\r\n  UInt32 ExtensionPos;\r\n  UInt32 NamePos;\r\n  int ExtensionIndex;\r\n  CRefItem(UInt32 index, const CUpdateItem &ui, bool sortByType):\r\n    UpdateItem(&ui),\r\n    Index(index),\r\n    ExtensionPos(0),\r\n    NamePos(0),\r\n    ExtensionIndex(0)\r\n  {\r\n    if (sortByType)\r\n    {\r\n      int slashPos = GetReverseSlashPos(ui.Name);\r\n      NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0);\r\n      int dotPos = ui.Name.ReverseFind(L'.');\r\n      if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n        ExtensionPos = ui.Name.Length();\r\n      else\r\n      {\r\n        ExtensionPos = dotPos + 1;\r\n        UString us = ui.Name.Mid(ExtensionPos);\r\n        if (!us.IsEmpty())\r\n        {\r\n          us.MakeLower();\r\n          int i;\r\n          AString s;\r\n          for (i = 0; i < us.Length(); i++)\r\n          {\r\n            wchar_t c = us[i];\r\n            if (c >= 0x80)\r\n              break;\r\n            s += (char)c;\r\n          }\r\n          if (i == us.Length())\r\n            ExtensionIndex = GetExtIndex(s);\r\n          else\r\n            ExtensionIndex = 0;\r\n        }\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nstatic int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *param)\r\n{\r\n  const CRefItem &a1 = *p1;\r\n  const CRefItem &a2 = *p2;\r\n  const CUpdateItem &u1 = *a1.UpdateItem;\r\n  const CUpdateItem &u2 = *a2.UpdateItem;\r\n  int n;\r\n  if (u1.IsDir != u2.IsDir)\r\n    return (u1.IsDir) ? 1 : -1;\r\n  if (u1.IsDir)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  bool sortByType = *(bool *)param;\r\n  if (sortByType)\r\n  {\r\n    RINOZ(MyCompare(a1.ExtensionIndex, a2.ExtensionIndex))\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos));\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos));\r\n    if (!u1.MTimeDefined && u2.MTimeDefined) return 1;\r\n    if (u1.MTimeDefined && !u2.MTimeDefined) return -1;\r\n    if (u1.MTimeDefined && u2.MTimeDefined) RINOZ(MyCompare(u1.MTime, u2.MTime));\r\n    RINOZ(MyCompare(u1.Size, u2.Size))\r\n  }\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstruct CSolidGroup\r\n{\r\n  CCompressionMethodMode Method;\r\n  CRecordVector<UInt32> Indices;\r\n};\r\n\r\nstatic wchar_t *g_ExeExts[] =\r\n{\r\n  L\"dll\",\r\n  L\"exe\",\r\n  L\"ocx\",\r\n  L\"sfx\",\r\n  L\"sys\"\r\n};\r\n\r\nstatic bool IsExeFile(const UString &ext)\r\n{\r\n  for (int i = 0; i < sizeof(g_ExeExts) / sizeof(g_ExeExts[0]); i++)\r\n    if (ext.CompareNoCase(g_ExeExts[i]) == 0)\r\n      return true;\r\n  return false;\r\n}\r\n\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_BCJ   = 0x03030103;\r\nstatic const UInt64 k_BCJ2  = 0x0303011B;\r\n\r\nstatic bool GetMethodFull(UInt64 methodID,\r\n    UInt32 numInStreams, CMethodFull &methodResult)\r\n{\r\n  methodResult.Id = methodID;\r\n  methodResult.NumInStreams = numInStreams;\r\n  methodResult.NumOutStreams = 1;\r\n  return true;\r\n}\r\n\r\nstatic bool MakeExeMethod(const CCompressionMethodMode &method,\r\n    bool bcj2Filter, CCompressionMethodMode &exeMethod)\r\n{\r\n  exeMethod = method;\r\n  if (bcj2Filter)\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ2, 4, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    if (!GetMethodFull(k_LZMA, 1, methodFull))\r\n      return false;\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kAlgorithm;\r\n      prop.Value = kAlgorithmForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kMatchFinder;\r\n      prop.Value = kMatchFinderForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = kDictionaryForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kNumFastBytes;\r\n      prop.Value = kNumFastBytesForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n\r\n    exeMethod.Methods.Add(methodFull);\r\n    exeMethod.Methods.Add(methodFull);\r\n    CBind bind;\r\n\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 2;\r\n    bind.OutStream = 1;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 3;\r\n    bind.OutStream = 2;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  else\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ, 1, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    CBind bind;\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  return true;\r\n}\r\n\r\nstatic void SplitFilesToGroups(\r\n    const CCompressionMethodMode &method,\r\n    bool useFilters, bool maxFilter,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    CObjectVector<CSolidGroup> &groups)\r\n{\r\n  if (method.Methods.Size() != 1 || method.Binds.Size() != 0)\r\n    useFilters = false;\r\n  groups.Clear();\r\n  groups.Add(CSolidGroup());\r\n  groups.Add(CSolidGroup());\r\n  CSolidGroup &generalGroup = groups[0];\r\n  CSolidGroup &exeGroup = groups[1];\r\n  generalGroup.Method = method;\r\n  int i;\r\n  for (i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &ui = updateItems[i];\r\n    if (!ui.NewData)\r\n      continue;\r\n    if (!ui.HasStream())\r\n      continue;\r\n    if (useFilters)\r\n    {\r\n      const UString name = ui.Name;\r\n      int dotPos = name.ReverseFind(L'.');\r\n      if (dotPos >= 0)\r\n      {\r\n        UString ext = name.Mid(dotPos + 1);\r\n        if (IsExeFile(ext))\r\n        {\r\n          exeGroup.Indices.Add(i);\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    generalGroup.Indices.Add(i);\r\n  }\r\n  if (exeGroup.Indices.Size() > 0)\r\n    if (!MakeExeMethod(method, maxFilter, exeGroup.Method))\r\n      exeGroup.Method = method;\r\n  for (i = 0; i < groups.Size();)\r\n    if (groups[i].Indices.Size() == 0)\r\n      groups.Delete(i);\r\n    else\r\n      i++;\r\n}\r\n\r\nstatic void FromUpdateItemToFileItem(const CUpdateItem &ui,\r\n    CFileItem &file, CFileItem2 &file2)\r\n{\r\n  file.Name = NItemName::MakeLegalName(ui.Name);\r\n  if (ui.AttribDefined)\r\n    file.SetAttrib(ui.Attrib);\r\n  \r\n  file2.CTime = ui.CTime;  file2.CTimeDefined = ui.CTimeDefined;\r\n  file2.ATime = ui.ATime;  file2.ATimeDefined = ui.ATimeDefined;\r\n  file2.MTime = ui.MTime;  file2.MTimeDefined = ui.MTimeDefined;\r\n  file2.IsAnti = ui.IsAnti;\r\n  file2.StartPosDefined = false;\r\n\r\n  file.Size = ui.Size;\r\n  file.IsDir = ui.IsDir;\r\n  file.HasStream = ui.HasStream();\r\n}\r\n\r\nstatic HRESULT Update2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  UInt64 numSolidFiles = options.NumSolidFiles;\r\n  if (numSolidFiles == 0)\r\n    numSolidFiles = 1;\r\n  /*\r\n  CMyComPtr<IOutStream> outStream;\r\n  RINOK(seqOutStream->QueryInterface(IID_IOutStream, (void **)&outStream));\r\n  if (!outStream)\r\n    return E_NOTIMPL;\r\n  */\r\n\r\n  UInt64 startBlockSize = db != 0 ? db->ArchiveInfo.StartPosition: 0;\r\n  if (startBlockSize > 0 && !options.RemoveSfxBlock)\r\n  {\r\n    RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));\r\n  }\r\n\r\n  CRecordVector<int> fileIndexToUpdateIndexMap;\r\n  if (db != 0)\r\n  {\r\n    fileIndexToUpdateIndexMap.Reserve(db->Files.Size());\r\n    for (int i = 0; i < db->Files.Size(); i++)\r\n      fileIndexToUpdateIndexMap.Add(-1);\r\n  }\r\n  int i;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    int index = updateItems[i].IndexInArchive;\r\n    if (index != -1)\r\n      fileIndexToUpdateIndexMap[index] = i;\r\n  }\r\n\r\n  CRecordVector<int> folderRefs;\r\n  if (db != 0)\r\n  {\r\n    for(i = 0; i < db->Folders.Size(); i++)\r\n    {\r\n      CNum indexInFolder = 0;\r\n      CNum numCopyItems = 0;\r\n      CNum numUnpackStreams = db->NumUnpackStreamsVector[i];\r\n      for (CNum fileIndex = db->FolderStartFileIndex[i];\r\n      indexInFolder < numUnpackStreams; fileIndex++)\r\n      {\r\n        if (db->Files[fileIndex].HasStream)\r\n        {\r\n          indexInFolder++;\r\n          int updateIndex = fileIndexToUpdateIndexMap[fileIndex];\r\n          if (updateIndex >= 0)\r\n            if (!updateItems[updateIndex].NewData)\r\n              numCopyItems++;\r\n        }\r\n      }\r\n      if (numCopyItems != numUnpackStreams && numCopyItems != 0)\r\n        return E_NOTIMPL; // It needs repacking !!!\r\n      if (numCopyItems > 0)\r\n        folderRefs.Add(i);\r\n    }\r\n    folderRefs.Sort(CompareFolderRefs, (void *)db);\r\n  }\r\n\r\n  ////////////////////////////\r\n\r\n  RINOK(archive.Create(seqOutStream, false));\r\n  RINOK(archive.SkeepPrefixArchiveHeader());\r\n  UInt64 complexity = 0;\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n    complexity += db->GetFolderFullPackSize(folderRefs[i]);\r\n  UInt64 inSizeForReduce = 0;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &ui = updateItems[i];\r\n    if (ui.NewData)\r\n    {\r\n      complexity += ui.Size;\r\n      if (numSolidFiles == 1)\r\n      {\r\n        if (ui.Size > inSizeForReduce)\r\n          inSizeForReduce = ui.Size;\r\n      }\r\n      else\r\n        inSizeForReduce += ui.Size;\r\n    }\r\n  }\r\n  RINOK(updateCallback->SetTotal(complexity));\r\n  complexity = 0;\r\n  RINOK(updateCallback->SetCompleted(&complexity));\r\n\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(updateCallback, true);\r\n\r\n  /////////////////////////////////////////\r\n  // Write Copy Items\r\n\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n  {\r\n    int folderIndex = folderRefs[i];\r\n    \r\n    lps->ProgressOffset = complexity;\r\n    UInt64 packSize = db->GetFolderFullPackSize(folderIndex);\r\n    RINOK(WriteRange(inStream, archive.SeqStream,\r\n        db->GetFolderStreamPos(folderIndex, 0), packSize, progress));\r\n    complexity += packSize;\r\n    \r\n    const CFolder &folder = db->Folders[folderIndex];\r\n    CNum startIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      newDatabase.PackSizes.Add(db->PackSizes[startIndex + j]);\r\n      // newDatabase.PackCRCsDefined.Add(db.PackCRCsDefined[startIndex + j]);\r\n      // newDatabase.PackCRCs.Add(db.PackCRCs[startIndex + j]);\r\n    }\r\n    newDatabase.Folders.Add(folder);\r\n\r\n    CNum numUnpackStreams = db->NumUnpackStreamsVector[folderIndex];\r\n    newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\r\n\r\n    CNum indexInFolder = 0;\r\n    for (CNum fi = db->FolderStartFileIndex[folderIndex];\r\n        indexInFolder < numUnpackStreams; fi++)\r\n    {\r\n      CFileItem file;\r\n      CFileItem2 file2;\r\n      db->GetFile(fi, file, file2);\r\n      if (file.HasStream)\r\n      {\r\n        indexInFolder++;\r\n        int updateIndex = fileIndexToUpdateIndexMap[fi];\r\n        if (updateIndex >= 0)\r\n        {\r\n          const CUpdateItem &ui = updateItems[updateIndex];\r\n          if (ui.NewProperties)\r\n          {\r\n            CFileItem uf;\r\n            FromUpdateItemToFileItem(ui, uf, file2);\r\n            uf.Size = file.Size;\r\n            uf.Crc = file.Crc;\r\n            uf.CrcDefined = file.CrcDefined;\r\n            uf.HasStream = file.HasStream;\r\n            file = uf;\r\n          }\r\n        }\r\n        newDatabase.AddFile(file, file2);\r\n      }\r\n    }\r\n  }\r\n\r\n  folderRefs.ClearAndFree();\r\n  fileIndexToUpdateIndexMap.ClearAndFree();\r\n\r\n  /////////////////////////////////////////\r\n  // Compress New Files\r\n\r\n  CObjectVector<CSolidGroup> groups;\r\n  SplitFilesToGroups(*options.Method, options.UseFilters, options.MaxFilter,\r\n      updateItems, groups);\r\n\r\n  const UInt32 kMinReduceSize = (1 << 16);\r\n  if (inSizeForReduce < kMinReduceSize)\r\n    inSizeForReduce = kMinReduceSize;\r\n\r\n  for (int groupIndex = 0; groupIndex < groups.Size(); groupIndex++)\r\n  {\r\n    const CSolidGroup &group = groups[groupIndex];\r\n    int numFiles = group.Indices.Size();\r\n    if (numFiles == 0)\r\n      continue;\r\n    CRecordVector<CRefItem> refItems;\r\n    refItems.Reserve(numFiles);\r\n    bool sortByType = (numSolidFiles > 1);\r\n    for (i = 0; i < numFiles; i++)\r\n      refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType));\r\n    refItems.Sort(CompareUpdateItems, (void *)&sortByType);\r\n    \r\n    CRecordVector<UInt32> indices;\r\n    indices.Reserve(numFiles);\r\n\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      UInt32 index = refItems[i].Index;\r\n      indices.Add(index);\r\n      /*\r\n      const CUpdateItem &ui = updateItems[index];\r\n      CFileItem file;\r\n      if (ui.NewProperties)\r\n        FromUpdateItemToFileItem(ui, file);\r\n      else\r\n        file = db.Files[ui.IndexInArchive];\r\n      if (file.IsAnti || file.IsDir)\r\n        return E_FAIL;\r\n      newDatabase.Files.Add(file);\r\n      */\r\n    }\r\n    \r\n    CEncoder encoder(group.Method);\r\n\r\n    for (i = 0; i < numFiles;)\r\n    {\r\n      UInt64 totalSize = 0;\r\n      int numSubFiles;\r\n      UString prevExtension;\r\n      for (numSubFiles = 0; i + numSubFiles < numFiles &&\r\n          numSubFiles < numSolidFiles; numSubFiles++)\r\n      {\r\n        const CUpdateItem &ui = updateItems[indices[i + numSubFiles]];\r\n        totalSize += ui.Size;\r\n        if (totalSize > options.NumSolidBytes)\r\n          break;\r\n        if (options.SolidExtension)\r\n        {\r\n          UString ext = ui.GetExtension();\r\n          if (numSubFiles == 0)\r\n            prevExtension = ext;\r\n          else\r\n            if (ext.CompareNoCase(prevExtension) != 0)\r\n              break;\r\n        }\r\n      }\r\n      if (numSubFiles < 1)\r\n        numSubFiles = 1;\r\n\r\n      CFolderInStream *inStreamSpec = new CFolderInStream;\r\n      CMyComPtr<ISequentialInStream> solidInStream(inStreamSpec);\r\n      inStreamSpec->Init(updateCallback, &indices[i], numSubFiles);\r\n      \r\n      CFolder folderItem;\r\n\r\n      int startPackIndex = newDatabase.PackSizes.Size();\r\n      RINOK(encoder.Encode(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          solidInStream, NULL, &inSizeForReduce, folderItem,\r\n          archive.SeqStream, newDatabase.PackSizes, progress));\r\n\r\n      for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)\r\n        lps->OutSize += newDatabase.PackSizes[startPackIndex];\r\n\r\n      lps->InSize += folderItem.GetUnpackSize();\r\n      // for()\r\n      // newDatabase.PackCRCsDefined.Add(false);\r\n      // newDatabase.PackCRCs.Add(0);\r\n      \r\n      newDatabase.Folders.Add(folderItem);\r\n      \r\n      CNum numUnpackStreams = 0;\r\n      for (int subIndex = 0; subIndex < numSubFiles; subIndex++)\r\n      {\r\n        const CUpdateItem &ui = updateItems[indices[i + subIndex]];\r\n        CFileItem file;\r\n        CFileItem2 file2;\r\n        if (ui.NewProperties)\r\n          FromUpdateItemToFileItem(ui, file, file2);\r\n        else\r\n          db->GetFile(ui.IndexInArchive, file, file2);\r\n        if (file2.IsAnti || file.IsDir)\r\n          return E_FAIL;\r\n        \r\n        /*\r\n        CFileItem &file = newDatabase.Files[\r\n              startFileIndexInDatabase + i + subIndex];\r\n        */\r\n        if (!inStreamSpec->Processed[subIndex])\r\n        {\r\n          continue;\r\n          // file.Name += L\".locked\";\r\n        }\r\n\r\n        file.Crc = inStreamSpec->CRCs[subIndex];\r\n        file.Size = inStreamSpec->Sizes[subIndex];\r\n        if (file.Size != 0)\r\n        {\r\n          file.CrcDefined = true;\r\n          file.HasStream = true;\r\n          numUnpackStreams++;\r\n        }\r\n        else\r\n        {\r\n          file.CrcDefined = false;\r\n          file.HasStream = false;\r\n        }\r\n        newDatabase.AddFile(file, file2);\r\n      }\r\n      // numUnpackStreams = 0 is very bad case for locked files\r\n      // v3.13 doesn't understand it.\r\n      newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\r\n      i += numSubFiles;\r\n    }\r\n  }\r\n\r\n  groups.ClearAndFree();\r\n\r\n  {\r\n    /////////////////////////////////////////\r\n    // Write Empty Files & Folders\r\n    \r\n    CRecordVector<int> emptyRefs;\r\n    for(i = 0; i < updateItems.Size(); i++)\r\n    {\r\n      const CUpdateItem &ui = updateItems[i];\r\n      if (ui.NewData)\r\n      {\r\n        if (ui.HasStream())\r\n          continue;\r\n      }\r\n      else\r\n        if (ui.IndexInArchive != -1)\r\n          if (db->Files[ui.IndexInArchive].HasStream)\r\n            continue;\r\n      emptyRefs.Add(i);\r\n    }\r\n    emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);\r\n    for (i = 0; i < emptyRefs.Size(); i++)\r\n    {\r\n      const CUpdateItem &ui = updateItems[emptyRefs[i]];\r\n      CFileItem file;\r\n      CFileItem2 file2;\r\n      if (ui.NewProperties)\r\n        FromUpdateItemToFileItem(ui, file, file2);\r\n      else\r\n        db->GetFile(ui.IndexInArchive, file, file2);\r\n      newDatabase.AddFile(file, file2);\r\n    }\r\n  }\r\n    \r\n  newDatabase.ReserveDown();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  return Update2(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        inStream, db, updateItems,\r\n        archive, newDatabase, seqOutStream, updateCallback, options);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/7zUpdate.h",
    "content": "// 7zUpdate.h\r\n\r\n#ifndef __7Z_UPDATE_H\r\n#define __7Z_UPDATE_H\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CUpdateItem\r\n{\r\n  int IndexInArchive;\r\n  int IndexInClient;\r\n  \r\n  UInt64 CTime;\r\n  UInt64 ATime;\r\n  UInt64 MTime;\r\n\r\n  UInt64 Size;\r\n  UString Name;\r\n\r\n  UInt32 Attrib;\r\n  \r\n  bool NewData;\r\n  bool NewProperties;\r\n\r\n  bool IsAnti;\r\n  bool IsDir;\r\n\r\n  bool AttribDefined;\r\n  bool CTimeDefined;\r\n  bool ATimeDefined;\r\n  bool MTimeDefined;\r\n\r\n  bool HasStream() const { return !IsDir && !IsAnti && Size != 0; }\r\n\r\n  CUpdateItem():\r\n      IsAnti(false),\r\n      IsDir(false),\r\n      AttribDefined(false),\r\n      CTimeDefined(false),\r\n      ATimeDefined(false),\r\n      MTimeDefined(false)\r\n      {}\r\n  void SetDirStatusFromAttrib() { IsDir = ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0); };\r\n\r\n  int GetExtensionPos() const;\r\n  UString GetExtension() const;\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  const CCompressionMethodMode *Method;\r\n  const CCompressionMethodMode *HeaderMethod;\r\n  bool UseFilters;\r\n  bool MaxFilter;\r\n\r\n  CHeaderOptions HeaderOptions;\r\n\r\n  UInt64 NumSolidFiles;\r\n  UInt64 NumSolidBytes;\r\n  bool SolidExtension;\r\n  bool RemoveSfxBlock;\r\n  bool VolumeMode;\r\n};\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options);\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Archive.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Archive2.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n  GetNumberOfMethods PRIVATE\r\n  GetMethodProperty PRIVATE\r\n  SetLargePageMode PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/ArchiveExports.cpp",
    "content": "// ArchiveExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterArc.h\"\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\r\nvoid RegisterArc(const CArcInfo *arcInfo)\r\n{\r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler,\r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\n#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nint FindFormatCalssId(const GUID *clsID)\r\n{\r\n  GUID cls = *clsID;\r\n  CLS_ARC_ID_ITEM(cls) = 0;\r\n  if (cls != CLSID_CArchiveHandler)\r\n    return -1;\r\n  Byte id = CLS_ARC_ID_ITEM(*clsID);\r\n  for (unsigned i = 0; i < g_NumArcs; i++)\r\n    if (g_Arcs[i]->ClassId == id)\r\n      return (int)i;\r\n  return -1;\r\n}\r\n\r\nSTDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  {\r\n    int needIn = (*iid == IID_IInArchive);\r\n    int needOut = (*iid == IID_IOutArchive);\r\n    if (!needIn && !needOut)\r\n      return E_NOINTERFACE;\r\n    int formatIndex = FindFormatCalssId(clsid);\r\n    if (formatIndex < 0)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    \r\n    const CArcInfo &arc = *g_Arcs[formatIndex];\r\n    if (needIn)\r\n    {\r\n      *outObject = arc.CreateInArchive();\r\n      ((IInArchive *)*outObject)->AddRef();\r\n    }\r\n    else\r\n    {\r\n      if (!arc.CreateOutArchive)\r\n        return CLASS_E_CLASSNOTAVAILABLE;\r\n      *outObject = arc.CreateOutArchive();\r\n      ((IOutArchive *)*outObject)->AddRef();\r\n    }\r\n  }\r\n  COM_TRY_END\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  if (formatIndex >= g_NumArcs)\r\n    return E_INVALIDARG;\r\n  const CArcInfo &arc = *g_Arcs[formatIndex];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case NArchive::kName:\r\n      prop = arc.Name;\r\n      break;\r\n    case NArchive::kClassID:\r\n    {\r\n      GUID clsId = CLSID_CArchiveHandler;\r\n      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;\r\n      return SetPropGUID(clsId, value);\r\n    }\r\n    case NArchive::kExtension:\r\n      if (arc.Ext != 0)\r\n        prop = arc.Ext;\r\n      break;\r\n    case NArchive::kAddExtension:\r\n      if (arc.AddExt != 0)\r\n        prop = arc.AddExt;\r\n      break;\r\n    case NArchive::kUpdate:\r\n      prop = (bool)(arc.CreateOutArchive != 0);\r\n      break;\r\n    case NArchive::kKeepName:\r\n      prop = arc.KeepName;\r\n      break;\r\n    case NArchive::kStartSignature:\r\n      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  return GetHandlerProperty2(0, propID, value);\r\n}\r\n\r\nSTDAPI GetNumberOfFormats(UINT32 *numFormats)\r\n{\r\n  *numFormats = g_NumArcs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/CoderMixer2.cpp",
    "content": "// CoderMixer2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):\r\n  _srcBindInfo(srcBindInfo)\r\n{\r\n  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);\r\n\r\n  UInt32  j;\r\n  for (j = 0; j < NumSrcInStreams; j++)\r\n  {\r\n    _srcInToDestOutMap.Add(0);\r\n    DestOutToSrcInMap.Add(0);\r\n  }\r\n  for (j = 0; j < _numSrcOutStreams; j++)\r\n  {\r\n    _srcOutToDestInMap.Add(0);\r\n    _destInToSrcOutMap.Add(0);\r\n  }\r\n\r\n  UInt32 destInOffset = 0;\r\n  UInt32 destOutOffset = 0;\r\n  UInt32 srcInOffset = NumSrcInStreams;\r\n  UInt32 srcOutOffset = _numSrcOutStreams;\r\n\r\n  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];\r\n\r\n    srcInOffset -= srcCoderInfo.NumInStreams;\r\n    srcOutOffset -= srcCoderInfo.NumOutStreams;\r\n    \r\n    UInt32 j;\r\n    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)\r\n    {\r\n      UInt32 index = srcInOffset + j;\r\n      _srcInToDestOutMap[index] = destOutOffset;\r\n      DestOutToSrcInMap[destOutOffset] = index;\r\n    }\r\n    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)\r\n    {\r\n      UInt32 index = srcOutOffset + j;\r\n      _srcOutToDestInMap[index] = destInOffset;\r\n      _destInToSrcOutMap[destInOffset] = index;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)\r\n{\r\n  destBindInfo.Coders.Clear();\r\n  destBindInfo.BindPairs.Clear();\r\n  destBindInfo.InStreams.Clear();\r\n  destBindInfo.OutStreams.Clear();\r\n\r\n  int i;\r\n  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];\r\n    CCoderStreamsInfo destCoderInfo;\r\n    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;\r\n    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;\r\n    destBindInfo.Coders.Add(destCoderInfo);\r\n  }\r\n  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];\r\n    CBindPair destBindPair;\r\n    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];\r\n    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];\r\n    destBindInfo.BindPairs.Add(destBindPair);\r\n  }\r\n  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)\r\n    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);\r\n  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)\r\n    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);\r\n}\r\n\r\nCCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams):\r\n    NumInStreams(numInStreams),\r\n    NumOutStreams(numOutStreams)\r\n{\r\n  InSizes.Reserve(NumInStreams);\r\n  InSizePointers.Reserve(NumInStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\nvoid CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,\r\n      const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/CoderMixer2.h",
    "content": "// CoderMixer2.h\r\n\r\n#ifndef __CODER_MIXER2_H\r\n#define __CODER_MIXER2_H\r\n\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n};\r\n\r\nstruct CCoderStreamsInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n};\r\n\r\nstruct CBindInfo\r\n{\r\n  CRecordVector<CCoderStreamsInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<UInt32> InStreams;\r\n  CRecordVector<UInt32> OutStreams;\r\n\r\n  void Clear()\r\n  {\r\n    Coders.Clear();\r\n    BindPairs.Clear();\r\n    InStreams.Clear();\r\n    OutStreams.Clear();\r\n  }\r\n\r\n  /*\r\n  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const\r\n  {\r\n    UInt32 numOutStreams = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      numOutStreams += Coders[i].NumOutStreams;\r\n    return numOutStreams;\r\n  }\r\n  */\r\n\r\n\r\n  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const\r\n  {\r\n    numInStreams = 0;\r\n    numOutStreams = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n    {\r\n      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];\r\n      numInStreams += coderStreamsInfo.NumInStreams;\r\n      numOutStreams += coderStreamsInfo.NumOutStreams;\r\n    }\r\n  }\r\n\r\n  int FindBinderForInStream(UInt32 inStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBinderForOutStream(UInt32 outStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumInStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumOutStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n\r\n  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,\r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumInStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,\r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumOutStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n};\r\n\r\nclass CBindReverseConverter\r\n{\r\n  UInt32 _numSrcOutStreams;\r\n  NCoderMixer::CBindInfo _srcBindInfo;\r\n  CRecordVector<UInt32> _srcInToDestOutMap;\r\n  CRecordVector<UInt32> _srcOutToDestInMap;\r\n  CRecordVector<UInt32> _destInToSrcOutMap;\r\npublic:\r\n  UInt32 NumSrcInStreams;\r\n  CRecordVector<UInt32> DestOutToSrcInMap;\r\n\r\n  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);\r\n  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);\r\n};\r\n\r\nstruct CCoderInfo2\r\n{\r\n  CMyComPtr<ICompressCoder> Coder;\r\n  CMyComPtr<ICompressCoder2> Coder2;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n\r\n  CRecordVector<UInt64> InSizes;\r\n  CRecordVector<UInt64> OutSizes;\r\n  CRecordVector<const UInt64 *> InSizePointers;\r\n  CRecordVector<const UInt64 *> OutSizePointers;\r\n\r\n  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n\r\n  HRESULT QueryInterface(REFGUID iid, void** pp) const\r\n  {\r\n    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;\r\n    return p->QueryInterface(iid, pp);\r\n  }\r\n};\r\n\r\nclass CCoderMixer2\r\n{\r\npublic:\r\n  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;\r\n  virtual void ReInit() = 0;\r\n  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;\r\n};\r\n\r\n}\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/CoderMixer2MT.cpp",
    "content": "// CoderMixer2MT.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2MT.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams):\r\n    CCoderInfo2(numInStreams, numOutStreams)\r\n{\r\n  InStreams.Reserve(NumInStreams);\r\n  InStreamPointers.Reserve(NumInStreams);\r\n  OutStreams.Reserve(NumOutStreams);\r\n  OutStreamPointers.Reserve(NumOutStreams);\r\n}\r\n\r\nvoid CCoder2::Execute() { Code(NULL); }\r\n\r\nvoid CCoder2::Code(ICompressProgressInfo *progress)\r\n{\r\n  InStreamPointers.Clear();\r\n  OutStreamPointers.Clear();\r\n  UInt32 i;\r\n  for (i = 0; i < NumInStreams; i++)\r\n  {\r\n    if (InSizePointers[i] != NULL)\r\n      InSizePointers[i] = &InSizes[i];\r\n    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);\r\n  }\r\n  for (i = 0; i < NumOutStreams; i++)\r\n  {\r\n    if (OutSizePointers[i] != NULL)\r\n      OutSizePointers[i] = &OutSizes[i];\r\n    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);\r\n  }\r\n  if (Coder)\r\n    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],\r\n        InSizePointers[0], OutSizePointers[0], progress);\r\n  else\r\n    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,\r\n      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);\r\n  {\r\n    int i;\r\n    for (i = 0; i < InStreams.Size(); i++)\r\n      InStreams[i].Release();\r\n    for (i = 0; i < OutStreams.Size(); i++)\r\n      OutStreams[i].Release();\r\n  }\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\n\r\nvoid CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n//////////////////////////////////////\r\n// CCoderMixer2MT\r\n\r\nHRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)\r\n{\r\n  _bindInfo = bindInfo;\r\n  _streamBinders.Clear();\r\n  for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    _streamBinders.Add(CStreamBinder());\r\n    RINOK(_streamBinders.Back().CreateEvents());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoderCommon()\r\n{\r\n  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];\r\n  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);\r\n  _coders.Add(threadCoderInfo);\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder(ICompressCoder *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder = coder;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder2 = coder;\r\n}\r\n\r\n\r\nvoid CCoderMixer2MT::ReInit()\r\n{\r\n  for(int i = 0; i < _streamBinders.Size(); i++)\r\n    _streamBinders[i].ReInit();\r\n}\r\n\r\n\r\nHRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams)\r\n{\r\n  /*\r\n  if (_coders.Size() != _bindInfo.Coders.Size())\r\n    throw 0;\r\n  */\r\n  int i;\r\n  for(i = 0; i < _coders.Size(); i++)\r\n  {\r\n    CCoder2 &coderInfo = _coders[i];\r\n    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];\r\n    coderInfo.InStreams.Clear();\r\n    UInt32 j;\r\n    for(j = 0; j < coderStreamsInfo.NumInStreams; j++)\r\n      coderInfo.InStreams.Add(NULL);\r\n    coderInfo.OutStreams.Clear();\r\n    for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)\r\n      coderInfo.OutStreams.Add(NULL);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = _bindInfo.BindPairs[i];\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);\r\n    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);\r\n\r\n    _streamBinders[i].CreateStreams(\r\n        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],\r\n        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.InStreams.Size(); i++)\r\n  {\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);\r\n    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];\r\n  }\r\n  \r\n  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);\r\n    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)\r\n{\r\n  for (int i = 0; i < _coders.Size(); i++)\r\n    if (_coders[i].Result == code)\r\n      return code;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||\r\n      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())\r\n    return E_INVALIDARG;\r\n\r\n  Init(inStreams, outStreams);\r\n\r\n  int i;\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n    {\r\n      RINOK(_coders[i].Create());\r\n    }\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].Start();\r\n\r\n  _coders[_progressCoderIndex].Code(progress);\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].WaitFinish();\r\n\r\n  RINOK(ReturnIfError(E_ABORT));\r\n  RINOK(ReturnIfError(E_OUTOFMEMORY));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK && result != E_FAIL && result != S_FALSE)\r\n      return result;\r\n  }\r\n\r\n  RINOK(ReturnIfError(S_FALSE));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/CoderMixer2MT.h",
    "content": "// CoderMixer2MT.h\r\n\r\n#ifndef __CODER_MIXER2_MT_H\r\n#define __CODER_MIXER2_MT_H\r\n\r\n#include \"CoderMixer2.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../Common/StreamBinder.h\"\r\n#include \"../../Common/VirtThread.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CCoder2: public CCoderInfo2, public CVirtThread\r\n{\r\n  HRESULT Result;\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;\r\n  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;\r\n  CRecordVector<ISequentialInStream*> InStreamPointers;\r\n  CRecordVector<ISequentialOutStream*> OutStreamPointers;\r\n\r\n  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n  virtual void Execute();\r\n  void Code(ICompressProgressInfo *progress);\r\n};\r\n\r\n\r\n/*\r\n  SetBindInfo()\r\n  for each coder\r\n    AddCoder[2]()\r\n  SetProgressIndex(UInt32 coderIndex);\r\n \r\n  for each file\r\n  {\r\n    ReInit()\r\n    for each coder\r\n      SetCoderInfo\r\n    Code\r\n  }\r\n*/\r\n\r\nclass CCoderMixer2MT:\r\n  public ICompressCoder2,\r\n  public CCoderMixer2,\r\n  public CMyUnknownImp\r\n{\r\n  CBindInfo _bindInfo;\r\n  CObjectVector<CStreamBinder> _streamBinders;\r\n  int _progressCoderIndex;\r\n\r\n  void AddCoderCommon();\r\n  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);\r\n  HRESULT ReturnIfError(HRESULT code);\r\npublic:\r\n  CObjectVector<CCoder2> _coders;\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n\r\n  HRESULT SetBindInfo(const CBindInfo &bindInfo);\r\n  void AddCoder(ICompressCoder *coder);\r\n  void AddCoder2(ICompressCoder2 *coder);\r\n  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }\r\n\r\n  void ReInit();\r\n  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)\r\n    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }\r\n  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const\r\n    {  return _streamBinders[binderIndex].ProcessedSize; }\r\n};\r\n\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/CrossThreadProgress.cpp",
    "content": "// CrossThreadProgress.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CrossThreadProgress.h\"\r\n\r\nSTDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  InSize = inSize;\r\n  OutSize = outSize;\r\n  ProgressEvent.Set();\r\n  WaitEvent.Lock();\r\n  return Result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/CrossThreadProgress.h",
    "content": "// CrossThreadProgress.h\r\n\r\n#ifndef __CROSSTHREADPROGRESS_H\r\n#define __CROSSTHREADPROGRESS_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CCrossThreadProgress:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  const UInt64 *InSize;\r\n  const UInt64 *OutSize;\r\n  HRESULT Result;\r\n  NWindows::NSynchronization::CAutoResetEvent ProgressEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent WaitEvent;\r\n\r\n  HRes Create()\r\n  {\r\n    RINOK(ProgressEvent.CreateIfNotCreated());\r\n    return WaitEvent.CreateIfNotCreated();\r\n  }\r\n  void Init()\r\n  {\r\n    ProgressEvent.Reset();\r\n    WaitEvent.Reset();\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/DummyOutStream.cpp",
    "content": "// DummyOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DummyOutStream.h\"\r\n\r\nSTDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/DummyOutStream.h",
    "content": "// DummyOutStream.h\r\n\r\n#ifndef __DUMMYOUTSTREAM_H\r\n#define __DUMMYOUTSTREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nclass CDummyOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init() { _size = 0; }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/HandlerOut.cpp",
    "content": "// HandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#include \"HandlerOut.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\n\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kLZMA2MethodName = L\"LZMA2\";\r\nstatic const wchar_t *kBZip2MethodName = L\"BZip2\";\r\nstatic const wchar_t *kPpmdMethodName = L\"PPMd\";\r\nstatic const wchar_t *kDeflateMethodName = L\"Deflate\";\r\nstatic const wchar_t *kDeflate64MethodName = L\"Deflate64\";\r\n\r\nstatic const wchar_t *kLzmaMatchFinderX1 = L\"HC4\";\r\nstatic const wchar_t *kLzmaMatchFinderX5 = L\"BT4\";\r\n\r\nstatic const UInt32 kLzmaAlgoX1 = 0;\r\nstatic const UInt32 kLzmaAlgoX5 = 1;\r\n\r\nstatic const UInt32 kLzmaDicSizeX1 = 1 << 16;\r\nstatic const UInt32 kLzmaDicSizeX3 = 1 << 20;\r\nstatic const UInt32 kLzmaDicSizeX5 = 1 << 24;\r\nstatic const UInt32 kLzmaDicSizeX7 = 1 << 25;\r\nstatic const UInt32 kLzmaDicSizeX9 = 1 << 26;\r\n\r\nstatic const UInt32 kLzmaFastBytesX1 = 32;\r\nstatic const UInt32 kLzmaFastBytesX7 = 64;\r\n\r\nstatic const UInt32 kPpmdMemSizeX1 = (1 << 22);\r\nstatic const UInt32 kPpmdMemSizeX5 = (1 << 24);\r\nstatic const UInt32 kPpmdMemSizeX7 = (1 << 26);\r\nstatic const UInt32 kPpmdMemSizeX9 = (192 << 20);\r\n\r\nstatic const UInt32 kPpmdOrderX1 = 4;\r\nstatic const UInt32 kPpmdOrderX5 = 6;\r\nstatic const UInt32 kPpmdOrderX7 = 16;\r\nstatic const UInt32 kPpmdOrderX9 = 32;\r\n\r\nstatic const UInt32 kDeflateAlgoX1 = 0;\r\nstatic const UInt32 kDeflateAlgoX5 = 1;\r\n\r\nstatic const UInt32 kDeflateFastBytesX1 = 32;\r\nstatic const UInt32 kDeflateFastBytesX7 = 64;\r\nstatic const UInt32 kDeflateFastBytesX9 = 128;\r\n\r\nstatic const UInt32 kDeflatePassesX1 = 1;\r\nstatic const UInt32 kDeflatePassesX7 = 3;\r\nstatic const UInt32 kDeflatePassesX9 = 10;\r\n\r\nstatic const UInt32 kBZip2NumPassesX1 = 1;\r\nstatic const UInt32 kBZip2NumPassesX7 = 2;\r\nstatic const UInt32 kBZip2NumPassesX9 = 7;\r\n\r\nstatic const UInt32 kBZip2DicSizeX1 = 100000;\r\nstatic const UInt32 kBZip2DicSizeX3 = 500000;\r\nstatic const UInt32 kBZip2DicSizeX5 = 900000;\r\n\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5;\r\n\r\nstatic bool AreEqual(const UString &methodName, const wchar_t *s)\r\n  { return (methodName.CompareNoCase(s) == 0); }\r\n\r\nstatic inline bool IsLZMAMethod(const UString &methodName)\r\n{\r\n  return\r\n    AreEqual(methodName, kLZMAMethodName) ||\r\n    AreEqual(methodName, kLZMA2MethodName);\r\n}\r\n\r\nstatic inline bool IsBZip2Method(const UString &methodName)\r\n  { return AreEqual(methodName, kBZip2MethodName); }\r\n\r\nstatic inline bool IsPpmdMethod(const UString &methodName)\r\n  { return AreEqual(methodName, kPpmdMethodName); }\r\n\r\nstatic inline bool IsDeflateMethod(const UString &methodName)\r\n{\r\n  return\r\n    AreEqual(methodName, kDeflateMethodName) ||\r\n    AreEqual(methodName, kDeflate64MethodName);\r\n}\r\n\r\nstruct CNameToPropID\r\n{\r\n  PROPID PropID;\r\n  VARTYPE VarType;\r\n  const wchar_t *Name;\r\n};\r\n\r\nCNameToPropID g_NameToPropID[] =\r\n{\r\n  { NCoderPropID::kOrder, VT_UI4, L\"O\" },\r\n  { NCoderPropID::kPosStateBits, VT_UI4, L\"PB\" },\r\n  { NCoderPropID::kLitContextBits, VT_UI4, L\"LC\" },\r\n  { NCoderPropID::kLitPosBits, VT_UI4, L\"LP\" },\r\n  { NCoderPropID::kEndMarker, VT_BOOL, L\"eos\" },\r\n\r\n  { NCoderPropID::kNumPasses, VT_UI4, L\"Pass\" },\r\n  { NCoderPropID::kNumFastBytes, VT_UI4, L\"fb\" },\r\n  { NCoderPropID::kMatchFinderCycles, VT_UI4, L\"mc\" },\r\n  { NCoderPropID::kAlgorithm, VT_UI4, L\"a\" },\r\n  { NCoderPropID::kMatchFinder, VT_BSTR, L\"mf\" },\r\n  { NCoderPropID::kNumThreads, VT_UI4, L\"mt\" }\r\n};\r\n\r\nstatic bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp)\r\n{\r\n  if (varType == srcProp.vt)\r\n  {\r\n    destProp = srcProp;\r\n    return true;\r\n  }\r\n  if (varType == VT_UI1)\r\n  {\r\n    if (srcProp.vt == VT_UI4)\r\n    {\r\n      UInt32 value = srcProp.ulVal;\r\n      if (value > 0xFF)\r\n        return false;\r\n      destProp = (Byte)value;\r\n      return true;\r\n    }\r\n  }\r\n  else if (varType == VT_BOOL)\r\n  {\r\n    bool res;\r\n    if (SetBoolProperty(res, srcProp) != S_OK)\r\n      return false;\r\n    destProp = res;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n    \r\nstatic int FindPropIdFromStringName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)\r\n    if (name.CompareNoCase(g_NameToPropID[i].Name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID,\r\n    const NWindows::NCOM::CPropVariant &value)\r\n{\r\n  for (int j = 0; j < oneMethodInfo.Props.Size(); j++)\r\n    if (oneMethodInfo.Props[j].Id == propID)\r\n      return;\r\n  CProp prop;\r\n  prop.Id = propID;\r\n  prop.Value = value;\r\n  oneMethodInfo.Props.Add(prop);\r\n}\r\n\r\nvoid COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  if (oneMethodInfo.MethodName.IsEmpty())\r\n    oneMethodInfo.MethodName = kDefaultMethodName;\r\n  \r\n  if (IsLZMAMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 dicSize =\r\n      (level >= 9 ? kLzmaDicSizeX9 :\r\n      (level >= 7 ? kLzmaDicSizeX7 :\r\n      (level >= 5 ? kLzmaDicSizeX5 :\r\n      (level >= 3 ? kLzmaDicSizeX3 :\r\n                    kLzmaDicSizeX1))));\r\n    \r\n    UInt32 algo =\r\n      (level >= 5 ? kLzmaAlgoX5 :\r\n                    kLzmaAlgoX1);\r\n    \r\n    UInt32 fastBytes =\r\n      (level >= 7 ? kLzmaFastBytesX7 :\r\n                    kLzmaFastBytesX1);\r\n    \r\n    const wchar_t *matchFinder =\r\n      (level >= 5 ? kLzmaMatchFinderX5 :\r\n                    kLzmaMatchFinderX1);\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsDeflateMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 fastBytes =\r\n      (level >= 9 ? kDeflateFastBytesX9 :\r\n      (level >= 7 ? kDeflateFastBytesX7 :\r\n                    kDeflateFastBytesX1));\r\n    \r\n    UInt32 numPasses =\r\n      (level >= 9 ? kDeflatePassesX9 :\r\n      (level >= 7 ? kDeflatePassesX7 :\r\n                    kDeflatePassesX1));\r\n    \r\n    UInt32 algo =\r\n      (level >= 5 ? kDeflateAlgoX5 :\r\n                    kDeflateAlgoX1);\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n  }\r\n  else if (IsBZip2Method(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 numPasses =\r\n      (level >= 9 ? kBZip2NumPassesX9 :\r\n      (level >= 7 ? kBZip2NumPassesX7 :\r\n                    kBZip2NumPassesX1));\r\n    \r\n    UInt32 dicSize =\r\n      (level >= 5 ? kBZip2DicSizeX5 :\r\n      (level >= 3 ? kBZip2DicSizeX3 :\r\n                    kBZip2DicSizeX1));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsPpmdMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 useMemSize =\r\n      (level >= 9 ? kPpmdMemSizeX9 :\r\n      (level >= 7 ? kPpmdMemSizeX7 :\r\n      (level >= 5 ? kPpmdMemSizeX5 :\r\n                    kPpmdMemSizeX1)));\r\n    \r\n    UInt32 order =\r\n      (level >= 9 ? kPpmdOrderX9 :\r\n      (level >= 7 ? kPpmdOrderX7 :\r\n      (level >= 5 ? kPpmdOrderX5 :\r\n                    kPpmdOrderX1)));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order);\r\n  }\r\n}\r\n\r\nstatic void SplitParams(const UString &srcString, UStringVector &subStrings)\r\n{\r\n  subStrings.Clear();\r\n  UString name;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L':')\r\n    {\r\n      subStrings.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  subStrings.Add(name);\r\n}\r\n\r\nstatic void SplitParam(const UString &param, UString &name, UString &value)\r\n{\r\n  int eqPos = param.Find(L'=');\r\n  if (eqPos >= 0)\r\n  {\r\n    name = param.Left(eqPos);\r\n    value = param.Mid(eqPos + 1);\r\n    return;\r\n  }\r\n  for(int i = 0; i < param.Length(); i++)\r\n  {\r\n    wchar_t c = param[i];\r\n    if (c >= L'0' && c <= L'9')\r\n    {\r\n      name = param.Left(i);\r\n      value = param.Mid(i);\r\n      return;\r\n    }\r\n  }\r\n  name = param;\r\n}\r\n\r\nHRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value)\r\n{\r\n  CProp prop;\r\n  if (name.CompareNoCase(L\"D\") == 0 ||\r\n      name.CompareNoCase(L\"MEM\") == 0)\r\n  {\r\n    UInt32 dicSize;\r\n    RINOK(ParsePropDictionaryValue(value, dicSize));\r\n    prop.Id = (name.CompareNoCase(L\"D\") == 0) ?\r\n        NCoderPropID::kDictionarySize :\r\n        NCoderPropID::kUsedMemorySize;\r\n    prop.Value = dicSize;\r\n  }\r\n  else\r\n  {\r\n    int index = FindPropIdFromStringName(name);\r\n    if (index < 0)\r\n      return E_INVALIDARG;\r\n    \r\n    const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n    prop.Id = nameToPropID.PropID;\r\n    \r\n    NCOM::CPropVariant propValue;\r\n    \r\n    if (nameToPropID.VarType == VT_BSTR)\r\n      propValue = value;\r\n    else if (nameToPropID.VarType == VT_BOOL)\r\n    {\r\n      bool res;\r\n      if (!StringToBool(value, res))\r\n        return E_INVALIDARG;\r\n      propValue = res;\r\n    }\r\n    else\r\n    {\r\n      UInt32 number;\r\n      if (ParseStringToUInt32(value, number) == value.Length())\r\n        propValue = number;\r\n      else\r\n        propValue = value;\r\n    }\r\n    \r\n    if (!ConvertProperty(propValue, nameToPropID.VarType, prop.Value))\r\n      return E_INVALIDARG;\r\n  }\r\n  oneMethodInfo.Props.Add(prop);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString)\r\n{\r\n  UStringVector params;\r\n  SplitParams(srcString, params);\r\n  if (params.Size() > 0)\r\n    oneMethodInfo.MethodName = params[0];\r\n  for (int i = 1; i < params.Size(); i++)\r\n  {\r\n    const UString &param = params[i];\r\n    UString name, value;\r\n    SplitParam(param, name, value);\r\n    RINOK(SetParam(oneMethodInfo, name, value));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const UString &s)\r\n{\r\n  UString s2 = s;\r\n  s2.MakeUpper();\r\n  for (int i = 0; i < s2.Length();)\r\n  {\r\n    const wchar_t *start = ((const wchar_t *)s2) + i;\r\n    const wchar_t *end;\r\n    UInt64 v = ConvertStringToUInt64(start, &end);\r\n    if (start == end)\r\n    {\r\n      if (s2[i++] != 'E')\r\n        return E_INVALIDARG;\r\n      _solidExtension = true;\r\n      continue;\r\n    }\r\n    i += (int)(end - start);\r\n    if (i == s2.Length())\r\n      return E_INVALIDARG;\r\n    wchar_t c = s2[i++];\r\n    switch(c)\r\n    {\r\n      case 'F':\r\n        if (v < 1)\r\n          v = 1;\r\n        _numSolidFiles = v;\r\n        break;\r\n      case 'B':\r\n        _numSolidBytes = v;\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'K':\r\n        _numSolidBytes = (v << 10);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'M':\r\n        _numSolidBytes = (v << 20);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'G':\r\n        _numSolidBytes = (v << 30);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)\r\n{\r\n  bool isSolid;\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      isSolid = true;\r\n      break;\r\n    case VT_BOOL:\r\n      isSolid = (value.boolVal != VARIANT_FALSE);\r\n      break;\r\n    case VT_BSTR:\r\n      if (StringToBool(value.bstrVal, isSolid))\r\n        break;\r\n      return SetSolidSettings(value.bstrVal);\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  if (isSolid)\r\n    InitSolid();\r\n  else\r\n    _numSolidFiles = 1;\r\n  return S_OK;\r\n}\r\n\r\nvoid COutHandler::Init()\r\n{\r\n  _removeSfxBlock = false;\r\n  _compressHeaders = true;\r\n  _encryptHeadersSpecified = false;\r\n  _encryptHeaders = false;\r\n  \r\n  WriteCTime = false;\r\n  WriteATime = false;\r\n  WriteMTime = true;\r\n  \r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  \r\n  _level = 5;\r\n  _autoFilter = true;\r\n  _volumeMode = false;\r\n  _crcSize = 4;\r\n  InitSolid();\r\n}\r\n\r\nvoid COutHandler::BeforeSetProperty()\r\n{\r\n  Init();\r\n  #ifdef COMPRESS_MT\r\n  numProcessors = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n\r\n  mainDicSize = 0xFFFFFFFF;\r\n  mainDicMethodIndex = 0xFFFFFFFF;\r\n  minNumber = 0;\r\n  _crcSize = 4;\r\n}\r\n\r\nHRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)\r\n{\r\n  UString name = nameSpec;\r\n  name.MakeUpper();\r\n  if (name.IsEmpty())\r\n    return E_INVALIDARG;\r\n  \r\n  if (name[0] == 'X')\r\n  {\r\n    name.Delete(0);\r\n    _level = 9;\r\n    return ParsePropValue(name, value, _level);\r\n  }\r\n  \r\n  if (name[0] == L'S')\r\n  {\r\n    name.Delete(0);\r\n    if (name.IsEmpty())\r\n      return SetSolidSettings(value);\r\n    if (value.vt != VT_EMPTY)\r\n      return E_INVALIDARG;\r\n    return SetSolidSettings(name);\r\n  }\r\n  \r\n  if (name == L\"CRC\")\r\n  {\r\n    _crcSize = 4;\r\n    name.Delete(0, 3);\r\n    return ParsePropValue(name, value, _crcSize);\r\n  }\r\n  \r\n  UInt32 number;\r\n  int index = ParseStringToUInt32(name, number);\r\n  UString realName = name.Mid(index);\r\n  if (index == 0)\r\n  {\r\n    if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n    {\r\n      #ifdef COMPRESS_MT\r\n      RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n      #endif\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"RSFX\") == 0)  return SetBoolProperty(_removeSfxBlock, value);\r\n    if (name.CompareNoCase(L\"F\") == 0) return SetBoolProperty(_autoFilter, value);\r\n    if (name.CompareNoCase(L\"HC\") == 0) return SetBoolProperty(_compressHeaders, value);\r\n    if (name.CompareNoCase(L\"HCF\") == 0)\r\n    {\r\n      bool compressHeadersFull = true;\r\n      RINOK(SetBoolProperty(compressHeadersFull, value));\r\n      if (!compressHeadersFull)\r\n        return E_INVALIDARG;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"HE\") == 0)\r\n    {\r\n      RINOK(SetBoolProperty(_encryptHeaders, value));\r\n      _encryptHeadersSpecified = true;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"TC\") == 0) return SetBoolProperty(WriteCTime, value);\r\n    if (name.CompareNoCase(L\"TA\") == 0) return SetBoolProperty(WriteATime, value);\r\n    if (name.CompareNoCase(L\"TM\") == 0) return SetBoolProperty(WriteMTime, value);\r\n    if (name.CompareNoCase(L\"V\") == 0) return SetBoolProperty(_volumeMode, value);\r\n    number = 0;\r\n  }\r\n  if (number > 10000)\r\n    return E_FAIL;\r\n  if (number < minNumber)\r\n    return E_INVALIDARG;\r\n  number -= minNumber;\r\n  for(int j = _methods.Size(); j <= (int)number; j++)\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    _methods.Add(oneMethodInfo);\r\n  }\r\n  \r\n  COneMethodInfo &oneMethodInfo = _methods[number];\r\n  \r\n  if (realName.Length() == 0)\r\n  {\r\n    if (value.vt != VT_BSTR)\r\n      return E_INVALIDARG;\r\n    \r\n    RINOK(SetParams(oneMethodInfo, value.bstrVal));\r\n  }\r\n  else\r\n  {\r\n    CProp prop;\r\n    if (realName.Left(1).CompareNoCase(L\"D\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize));\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = dicSize;\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else if (realName.Left(1).CompareNoCase(L\"C\") == 0)\r\n    {\r\n      UInt32 blockSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, blockSize));\r\n      prop.Id = NCoderPropID::kBlockSize;\r\n      prop.Value = blockSize;\r\n    }\r\n    else if (realName.Left(3).CompareNoCase(L\"MEM\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize));\r\n      prop.Id = NCoderPropID::kUsedMemorySize;\r\n      prop.Value = dicSize;\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else\r\n    {\r\n      int index = FindPropIdFromStringName(realName);\r\n      if (index < 0)\r\n        return E_INVALIDARG;\r\n      const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n      prop.Id = nameToPropID.PropID;\r\n      if (!ConvertProperty(value, nameToPropID.VarType, prop.Value))\r\n        return E_INVALIDARG;\r\n    }\r\n    oneMethodInfo.Props.Add(prop);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/HandlerOut.h",
    "content": "// HandlerOut.h\r\n\r\n#ifndef __HANDLER_OUT_H\r\n#define __HANDLER_OUT_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\n\r\nstruct COneMethodInfo\r\n{\r\n  CObjectVector<CProp> Props;\r\n  UString MethodName;\r\n};\r\n\r\nclass COutHandler\r\n{\r\npublic:\r\n  HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);\r\n  \r\n  HRESULT SetSolidSettings(const UString &s);\r\n  HRESULT SetSolidSettings(const PROPVARIANT &value);\r\n\r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  CObjectVector<COneMethodInfo> _methods;\r\n  bool _removeSfxBlock;\r\n  \r\n  UInt64 _numSolidFiles;\r\n  UInt64 _numSolidBytes;\r\n  bool _numSolidBytesDefined;\r\n  bool _solidExtension;\r\n\r\n  bool _compressHeaders;\r\n  bool _encryptHeadersSpecified;\r\n  bool _encryptHeaders;\r\n\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  bool _autoFilter;\r\n  UInt32 _level;\r\n\r\n  bool _volumeMode;\r\n\r\n  HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value);\r\n  HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);\r\n\r\n  void SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }\r\n  void InitSolidSize()  { _numSolidBytes = (UInt64)(Int64)(-1); }\r\n  void InitSolid()\r\n  {\r\n    InitSolidFiles();\r\n    InitSolidSize();\r\n    _solidExtension = false;\r\n    _numSolidBytesDefined = false;\r\n  }\r\n\r\n  void Init();\r\n\r\n  COutHandler() { Init(); }\r\n\r\n  void BeforeSetProperty();\r\n\r\n  UInt32 minNumber;\r\n  UInt32 numProcessors;\r\n  UInt32 mainDicSize;\r\n  UInt32 mainDicMethodIndex;\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.cpp",
    "content": "// InStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _size += realProcessedSize;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if (seekOrigin != STREAM_SEEK_SET || offset != 0)\r\n    return E_FAIL;\r\n  _size = 0;\r\n  _crc = CRC_INIT_VAL;\r\n  return _stream->Seek(offset, seekOrigin, newPosition);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.h",
    "content": "// InStreamWithCRC.h\r\n\r\n#ifndef __INSTREAMWITHCRC_H\r\n#define __INSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass CSequentialInStreamWithCRC:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CInStreamWithCRC:\r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\nprivate:\r\n  CMyComPtr<IInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(IInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/ItemNameUtils.cpp",
    "content": "// Archive/Common/ItemNameUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\nstatic const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;\r\nstatic const wchar_t kDirDelimiter = L'/';\r\n\r\nUString MakeLegalName(const UString &name)\r\n{\r\n  UString zipName = name;\r\n  zipName.Replace(kOSDirDelimiter, kDirDelimiter);\r\n  return zipName;\r\n}\r\n\r\nUString GetOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(kDirDelimiter, kOSDirDelimiter);\r\n  return newName;\r\n}\r\n\r\nUString GetOSName2(const UString &name)\r\n{\r\n  if (name.IsEmpty())\r\n    return UString();\r\n  UString newName = GetOSName(name);\r\n  if (newName[newName.Length() - 1] == kOSDirDelimiter)\r\n    newName.Delete(newName.Length() - 1);\r\n  return newName;\r\n}\r\n\r\nbool HasTailSlash(const AString &name, UINT codePage)\r\n{\r\n  if (name.IsEmpty())\r\n    return false;\r\n  LPCSTR prev =\r\n  #ifdef _WIN32\r\n    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);\r\n  #else\r\n    (LPCSTR)(name) + (name.Length() - 1);\r\n  #endif\r\n  return (*prev == '/');\r\n}\r\n\r\n#ifndef _WIN32\r\nUString WinNameToOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(L'\\\\', kOSDirDelimiter);\r\n  return newName;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/ItemNameUtils.h",
    "content": "// Archive/Common/ItemNameUtils.h\r\n\r\n#ifndef __ARCHIVE_ITEMNAMEUTILS_H\r\n#define __ARCHIVE_ITEMNAMEUTILS_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\n  UString MakeLegalName(const UString &name);\r\n  UString GetOSName(const UString &name);\r\n  UString GetOSName2(const UString &name);\r\n  bool HasTailSlash(const AString &name, UINT codePage);\r\n\r\n  #ifdef _WIN32\r\n  inline UString WinNameToOSName(const UString &name)  { return name; }\r\n  #else\r\n  UString WinNameToOSName(const UString &name);\r\n  #endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/MultiStream.cpp",
    "content": "// MultiStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MultiStream.h\"\r\n\r\nSTDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(_streamIndex < Streams.Size() && size > 0)\r\n  {\r\n    CSubStreamInfo &s = Streams[_streamIndex];\r\n    if (_pos == s.Size)\r\n    {\r\n      _streamIndex++;\r\n      _pos = 0;\r\n      continue;\r\n    }\r\n    RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));\r\n    UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));\r\n    UInt32 realProcessed;\r\n    HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _pos += realProcessed;\r\n    _seekPos += realProcessed;\r\n    RINOK(result);\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 newPos;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      newPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      newPos = _seekPos + offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      newPos = _totalLength + offset;\r\n      break;\r\n    default:\r\n      return STG_E_INVALIDFUNCTION;\r\n  }\r\n  _seekPos = 0;\r\n  for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)\r\n  {\r\n    UInt64 size = Streams[_streamIndex].Size;\r\n    if (newPos < _seekPos + size)\r\n    {\r\n      _pos = newPos - _seekPos;\r\n      _seekPos += _pos;\r\n      if (newPosition != 0)\r\n        *newPosition = newPos;\r\n      return S_OK;\r\n    }\r\n    _seekPos += size;\r\n  }\r\n  if (newPos == _seekPos)\r\n  {\r\n    if (newPosition != 0)\r\n      *newPosition = newPos;\r\n    return S_OK;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\n\r\n/*\r\nclass COutVolumeStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback,\r\n      const UString &name)\r\n  {\r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n*/\r\n\r\n/*\r\nSTDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));\r\n      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));\r\n      subStream.Pos = 0;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n    if (_offsetPos >= subStream.Size)\r\n    {\r\n      _offsetPos -= subStream.Size;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      CMyComPtr<IOutStream> outStream;\r\n      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == subStream.Size)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/MultiStream.h",
    "content": "// MultiStream.h\r\n\r\n#ifndef __MULTISTREAM_H\r\n#define __MULTISTREAM_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nclass CMultiStream:\r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex;\r\n  UInt64 _pos;\r\n  UInt64 _seekPos;\r\n  UInt64 _totalLength;\r\npublic:\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<IInStream> Stream;\r\n    UInt64 Pos;\r\n    UInt64 Size;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _pos = 0;\r\n    _seekPos = 0;\r\n    _totalLength = 0;\r\n    for (int i = 0; i < Streams.Size(); i++)\r\n      _totalLength += Streams[i].Size;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n\r\n/*\r\nclass COutMultiStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<ISequentialOutStream> Stream;\r\n    UInt64 Size;\r\n    UInt64 Pos;\r\n };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp",
    "content": "// OutStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  if (_calculate)\r\n    _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.h",
    "content": "// OutStreamWithCRC.h\r\n\r\n#ifndef __OUT_STREAM_WITH_CRC_H\r\n#define __OUT_STREAM_WITH_CRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass COutStreamWithCRC:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _calculate;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(bool calculate = true)\r\n  {\r\n    _size = 0;\r\n    _calculate = calculate;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void InitCRC() { _crc = CRC_INIT_VAL; }\r\n  UInt64 GetSize() const { return _size; }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/ParseProperties.cpp",
    "content": "// ParseProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ParseProperties.h\"\r\n\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (prop.vt == VT_UI4)\r\n  {\r\n    if (!name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    resValue = prop.ulVal;\r\n  }\r\n  else if (prop.vt == VT_EMPTY)\r\n  {\r\n    if(!name.IsEmpty())\r\n    {\r\n      const wchar_t *start = name;\r\n      const wchar_t *end;\r\n      UInt64 v = ConvertStringToUInt64(start, &end);\r\n      if (end - start != name.Length())\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)v;\r\n    }\r\n  }\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kLogarithmicSizeLimit = 32;\r\nstatic const wchar_t kByteSymbol = L'B';\r\nstatic const wchar_t kKiloByteSymbol = L'K';\r\nstatic const wchar_t kMegaByteSymbol = L'M';\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)\r\n{\r\n  UString srcString = srcStringSpec;\r\n  srcString.MakeUpper();\r\n\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || srcString.Length() > numDigits + 1)\r\n    return E_INVALIDARG;\r\n  if (srcString.Length() == numDigits)\r\n  {\r\n    if (number >= kLogarithmicSizeLimit)\r\n      return E_INVALIDARG;\r\n    dicSize = (UInt32)1 << (int)number;\r\n    return S_OK;\r\n  }\r\n  switch (srcString[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      if (number >= ((UInt64)1 << kLogarithmicSizeLimit))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)number;\r\n      break;\r\n    case kKiloByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 10);\r\n      break;\r\n    case kMegaByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 20);\r\n      break;\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    if (prop.vt == VT_UI4)\r\n    {\r\n      UInt32 logDicSize = prop.ulVal;\r\n      if (logDicSize >= 32)\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)1 << logDicSize;\r\n      return S_OK;\r\n    }\r\n    if (prop.vt == VT_BSTR)\r\n      return ParsePropDictionaryValue(prop.bstrVal, resValue);\r\n    return E_INVALIDARG;\r\n  }\r\n  return ParsePropDictionaryValue(name, resValue);\r\n}\r\n\r\nbool StringToBool(const UString &s, bool &res)\r\n{\r\n  if (s.IsEmpty() || s.CompareNoCase(L\"ON\") == 0 || s.Compare(L\"+\") == 0)\r\n  {\r\n    res = true;\r\n    return true;\r\n  }\r\n  if (s.CompareNoCase(L\"OFF\") == 0 || s.Compare(L\"-\") == 0)\r\n  {\r\n    res = false;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      dest = true;\r\n      return S_OK;\r\n    case VT_BOOL:\r\n      dest = (value.boolVal != VARIANT_FALSE);\r\n      return S_OK;\r\n    /*\r\n    case VT_UI4:\r\n      dest = (value.ulVal != 0);\r\n      break;\r\n    */\r\n    case VT_BSTR:\r\n      return StringToBool(value.bstrVal, dest) ?  S_OK : E_INVALIDARG;\r\n  }\r\n  return E_INVALIDARG;\r\n}\r\n\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number)\r\n{\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number64 = ConvertStringToUInt64(start, &end);\r\n  if (number64 > 0xFFFFFFFF)\r\n  {\r\n    number = 0;\r\n    return 0;\r\n  }\r\n  number = (UInt32)number64;\r\n  return (int)(end - start);\r\n}\r\n\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    switch(prop.vt)\r\n    {\r\n      case VT_UI4:\r\n        numThreads = prop.ulVal;\r\n        break;\r\n      default:\r\n      {\r\n        bool val;\r\n        RINOK(SetBoolProperty(val, prop));\r\n        numThreads = (val ? defaultNumThreads : 1);\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index != name.Length())\r\n      return E_INVALIDARG;\r\n    numThreads = number;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/ParseProperties.h",
    "content": "// ParseProperties.h\r\n\r\n#ifndef __PARSEPROPERTIES_H\r\n#define __PARSEPROPERTIES_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\n\r\nbool StringToBool(const UString &s, bool &res);\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number);\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/DllExports2.cpp",
    "content": "// DLLExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyInitGuid.h\"\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nHINSTANCE g_hInstance;\r\n#ifndef _UNICODE\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)\r\n{\r\n  if (dwReason == DLL_PROCESS_ATTACH)\r\n  {\r\n    g_hInstance = hInstance;\r\n    #ifndef _UNICODE\r\n    #ifdef _WIN32\r\n    g_IsNT = IsItWindowsNT();\r\n    #endif\r\n    #endif\r\n  }\r\n  return TRUE;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler,\r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec,\r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);\r\nSTDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);\r\n\r\nSTDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  // COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)\r\n  {\r\n    return CreateCoder(clsid, iid, outObject);\r\n  }\r\n  else\r\n  {\r\n    return CreateArchiver(clsid, iid, outObject);\r\n  }\r\n  // COM_TRY_END\r\n}\r\n\r\nSTDAPI SetLargePageMode()\r\n{\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  SetLargePageSize();\r\n  #endif\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/IArchive.h",
    "content": "// IArchive.h\r\n\r\n#ifndef __IARCHIVE_H\r\n#define __IARCHIVE_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../IProgress.h\"\r\n#include \"../PropID.h\"\r\n\r\n#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)\r\n#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nnamespace NFileTimeType\r\n{\r\n  enum EEnum\r\n  {\r\n    kWindows,\r\n    kUnix,\r\n    kDOS\r\n  };\r\n}\r\n\r\nnamespace NArchive\r\n{\r\n  enum\r\n  {\r\n    kName = 0,\r\n    kClassID,\r\n    kExtension,\r\n    kAddExtension,\r\n    kUpdate,\r\n    kKeepName,\r\n    kStartSignature,\r\n    kFinishSignature,\r\n    kAssociate\r\n  };\r\n\r\n  namespace NExtract\r\n  {\r\n    namespace NAskMode\r\n    {\r\n      enum\r\n      {\r\n        kExtract = 0,\r\n        kTest,\r\n        kSkip\r\n      };\r\n    }\r\n    namespace NOperationResult\r\n    {\r\n      enum\r\n      {\r\n        kOK = 0,\r\n        kUnSupportedMethod,\r\n        kDataError,\r\n        kCRCError\r\n      };\r\n    }\r\n  }\r\n  namespace NUpdate\r\n  {\r\n    namespace NOperationResult\r\n    {\r\n      enum\r\n      {\r\n        kOK = 0,\r\n        kError\r\n      };\r\n    }\r\n  }\r\n}\r\n\r\n#define INTERFACE_IArchiveOpenCallback(x) \\\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) x; \\\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)\r\n{\r\n  INTERFACE_IArchiveOpenCallback(PURE);\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveExtractCallback(x) \\\r\n  INTERFACE_IProgress(x) \\\r\n  /* GetStream OUT: S_OK - OK, S_FALSE - skeep this file */ \\\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream,  Int32 askExtractMode) x; \\\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode) x; \\\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)\r\n{\r\n  INTERFACE_IArchiveExtractCallback(PURE)\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveOpenVolumeCallback(x) \\\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) x; \\\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)\r\n{\r\n  INTERFACE_IArchiveOpenVolumeCallback(PURE);\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)\r\n{\r\n  STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;\r\n};\r\n\r\n\r\n/*\r\nIInArchive::Extract:\r\n  indices must be sorted\r\n  numItems = 0xFFFFFFFF means \"all files\"\r\n  testMode != 0 means \"test files without writing to outStream\"\r\n*/\r\n\r\n#define INTERFACE_IInArchive(x) \\\r\n  STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \\\r\n  STDMETHOD(Close)() x; \\\r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \\\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \\\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;\r\n\r\nARCHIVE_INTERFACE(IInArchive, 0x60)\r\n{\r\n  INTERFACE_IInArchive(PURE)\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveUpdateCallback(x) \\\r\n  INTERFACE_IProgress(x); \\\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,  \\\r\n      Int32 *newData, /*1 - new data, 0 - old data */ \\\r\n      Int32 *newProperties, /* 1 - new properties, 0 - old properties */ \\\r\n      UInt32 *indexInArchive /* -1 if there is no in archive, or if doesn't matter */ \\\r\n      )  x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) x; \\\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)\r\n{\r\n  INTERFACE_IArchiveUpdateCallback(PURE);\r\n};\r\n\r\n#define INTERFACE_IArchiveUpdateCallback2(x) \\\r\n  INTERFACE_IArchiveUpdateCallback(x) \\\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) x; \\\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)\r\n{\r\n  INTERFACE_IArchiveUpdateCallback2(PURE);\r\n};\r\n\r\n\r\n#define INTERFACE_IOutArchive(x) \\\r\n  STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \\\r\n  STDMETHOD(GetFileTimeType)(UInt32 *type) x;\r\n\r\nARCHIVE_INTERFACE(IOutArchive, 0xA0)\r\n{\r\n  INTERFACE_IOutArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(ISetProperties, 0x03)\r\n{\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;\r\n};\r\n\r\n\r\n#define IMP_IInArchive_GetProp(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \\\r\n\r\n#define IMP_IInArchive_GetProp_WITH_NAME(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; \\\r\n    if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \\\r\n\r\n#define IMP_IInArchive_Props \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)\r\n\r\n#define IMP_IInArchive_Props_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)\r\n\r\n\r\n#define IMP_IInArchive_ArcProps \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_NO \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = 0; return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \\\r\n    { return E_NOTIMPL; } \\\r\n  STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \\\r\n    { value->vt = VT_EMPTY; return S_OK; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp",
    "content": "// LzmaArcRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"LzmaHandler.h\"\r\n\r\nstatic IInArchive *CreateArc() { return new NArchive::NLzma::CHandler;  }\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"Lzma\", L\"lzma lzma86\", 0, 0xA, {0 }, 0, true, CreateArc, NULL };\r\n\r\nREGISTER_ARC(Lzma)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp",
    "content": "// LzmaFiltersDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaFiltersDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nstatic const UInt64 k_LZMA = 0x030101;\r\nstatic const UInt64 k_BCJ = 0x03030103;\r\n  \r\nHRESULT CDecoder::Code(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CHeader &block,\r\n    ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    UInt64 *inProcessedSize, ICompressProgressInfo *progress)\r\n{\r\n  *inProcessedSize = (UInt64)(Int64)-1;\r\n\r\n  if (block.FilterMethod > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (!_lzmaDecoder)\r\n  {\r\n    RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_LZMA, _lzmaDecoder, false));\r\n    if (_lzmaDecoder == 0)\r\n      return E_NOTIMPL;\r\n  }\r\n\r\n  {\r\n    CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n    _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n    if (!setDecoderProperties)\r\n      return E_NOTIMPL;\r\n    RINOK(setDecoderProperties->SetDecoderProperties2(block.LzmaProps, 5));\r\n  }\r\n\r\n  bool filteredMode = (block.FilterMethod == 1);\r\n\r\n  CMyComPtr<ICompressSetOutStream> setOutStream;\r\n\r\n  if (filteredMode)\r\n  {\r\n    if (!_bcjStream)\r\n    {\r\n      CMyComPtr<ICompressCoder> coder;\r\n      RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_BCJ, coder, false));\r\n      if (!coder)\r\n        return E_NOTIMPL;\r\n      coder.QueryInterface(IID_ISequentialOutStream, &_bcjStream);\r\n      if (!_bcjStream)\r\n        return E_NOTIMPL;\r\n    }\r\n\r\n    _bcjStream.QueryInterface(IID_ICompressSetOutStream, &setOutStream);\r\n    if (!setOutStream)\r\n      return E_NOTIMPL;\r\n    RINOK(setOutStream->SetOutStream(outStream));\r\n    outStream = _bcjStream;\r\n  }\r\n\r\n  const UInt64 *unpackSize = block.HasUnpackSize() ? &block.UnpackSize : NULL;\r\n  RINOK(_lzmaDecoder->Code(inStream, outStream, NULL, unpackSize, progress));\r\n\r\n  if (filteredMode)\r\n  {\r\n    CMyComPtr<IOutStreamFlush> flush;\r\n    _bcjStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n    if (flush)\r\n    {\r\n      RINOK(flush->Flush());\r\n    }\r\n    RINOK(setOutStream->ReleaseOutStream());\r\n  }\r\n\r\n  CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;\r\n  _lzmaDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);\r\n  if (getInStreamProcessedSize)\r\n  {\r\n    RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(inProcessedSize));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h",
    "content": "// LzmaFiltersDecode.h\r\n\r\n#ifndef __LZMA_FILTERS_DECODE_H\r\n#define __LZMA_FILTERS_DECODE_H\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"LzmaItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nclass CDecoder\r\n{\r\n  CMyComPtr<ICompressCoder> _lzmaDecoder;\r\n  CMyComPtr<ISequentialOutStream> _bcjStream;\r\npublic:\r\n  HRESULT Code(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CHeader &block,\r\n      ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      UInt64 *inProcessedSize, ICompressProgressInfo *progress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Lzma/LzmaHandler.cpp",
    "content": "// LzmaHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaHandler.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n#include \"../Common/DummyOutStream.h\"\r\n\r\n#include \"LzmaFiltersDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nSTATPROPSTG kProps[] =\r\n{\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidPackSize, VT_UI8},\r\n  { NULL, kpidMethod, VT_UI1}\r\n};\r\n\r\nIMP_IInArchive_Props\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = 1;\r\n  return S_OK;\r\n}\r\n\r\nstatic void ConvertUInt32ToString(UInt32 value, wchar_t *s)\r\n{\r\n  ConvertUInt64ToString(value, s + MyStringLen(s));\r\n}\r\n\r\nstatic void DictSizeToString(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i <= 31; i++)\r\n    if ((UInt32(1) << i) == value)\r\n    {\r\n      ConvertUInt32ToString(i, s);\r\n      return;\r\n    }\r\n  wchar_t c = L'b';\r\n  if ((value & ((1 << 20) - 1)) == 0)\r\n  {\r\n    value >>= 20;\r\n    c = L'm';\r\n  }\r\n  else if ((value & ((1 << 10) - 1)) == 0)\r\n  {\r\n    value >>= 10;\r\n    c = L'k';\r\n  }\r\n  ConvertUInt32ToString(value, s);\r\n  int p = MyStringLen(s);\r\n  s[p++] = c;\r\n  s[p++] = L'\\0';\r\n}\r\n\r\nstatic void MyStrCat(wchar_t *d, const wchar_t *s)\r\n{\r\n  MyStringCopy(d + MyStringLen(d), s);\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  switch(propID)\r\n  {\r\n    case kpidSize:\r\n      if (m_StreamInfo.HasUnpackSize())\r\n        propVariant = (UInt64)m_StreamInfo.UnpackSize;\r\n      break;\r\n    case kpidPackSize:\r\n      propVariant = (UInt64)m_PackSize;\r\n      break;\r\n    case kpidMethod:\r\n    {\r\n      wchar_t s[64];\r\n      s[0] = '\\0';\r\n      if (m_StreamInfo.IsThereFilter)\r\n      {\r\n        const wchar_t *f;\r\n        if (m_StreamInfo.FilterMethod == 0)\r\n          f = L\"Copy\";\r\n        else if (m_StreamInfo.FilterMethod == 1)\r\n          f = L\"BCJ\";\r\n        else\r\n          f = L\"Unknown\";\r\n        MyStrCat(s, f);\r\n        MyStrCat(s, L\" \");\r\n      }\r\n      MyStrCat(s, L\"LZMA:\");\r\n      DictSizeToString(m_StreamInfo.GetDicSize(), s);\r\n      propVariant = s;\r\n      break;\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *inStream,\r\n    const UInt64 * /* maxCheckStartPosition */,\r\n    IArchiveOpenCallback * /* openArchiveCallback */)\r\n{\r\n  {\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));\r\n\r\n    HRESULT res = ReadStreamHeader(inStream, m_StreamInfo);\r\n    if (res != S_OK)\r\n      return S_FALSE;\r\n    \r\n    Byte b;\r\n    RINOK(ReadStream_FALSE(inStream, &b, 1));\r\n    if (b != 0)\r\n      return S_FALSE;\r\n\r\n    UInt64 endPos;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));\r\n    m_PackSize = endPos - m_StreamStartPosition - m_StreamInfo.GetHeaderSize();\r\n\r\n    m_Stream = inStream;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  m_Stream.Release();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 _aTestMode, IArchiveExtractCallback *extractCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (!allFilesMode)\r\n  {\r\n    if (numItems == 0)\r\n      return S_OK;\r\n    if (numItems != 1)\r\n      return E_INVALIDARG;\r\n    if (indices[0] != 0)\r\n      return E_INVALIDARG;\r\n  }\r\n\r\n  bool testMode = (_aTestMode != 0);\r\n\r\n  RINOK(extractCallback->SetTotal(m_PackSize));\r\n    \r\n  UInt64 currentTotalPacked = 0;\r\n\r\n  CDummyOutStream *outStreamSpec = new CDummyOutStream;\r\n  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n\r\n  {\r\n    CMyComPtr<ISequentialOutStream> realOutStream;\r\n    Int32 askMode = testMode ?\r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n    \r\n    RINOK(extractCallback->GetStream(0, &realOutStream, askMode));\r\n\r\n    outStreamSpec->SetStream(realOutStream);\r\n    outStreamSpec->Init();\r\n    if(!testMode && !realOutStream)\r\n      return S_OK;\r\n    extractCallback->PrepareOperation(askMode);\r\n  }\r\n  \r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, true);\r\n\r\n  CDecoder decoder;\r\n  RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));\r\n  UInt64 streamPos = m_StreamStartPosition;\r\n  Int32 opRes = NArchive::NExtract::NOperationResult::kOK;\r\n  bool firstItem = true;\r\n  for (;;)\r\n  {\r\n    CHeader st;\r\n    HRESULT result = ReadStreamHeader(m_Stream, st);\r\n    if (result != S_OK)\r\n    {\r\n      if (firstItem)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    firstItem = false;\r\n\r\n    lps->OutSize = outStreamSpec->GetSize();\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    streamPos += st.GetHeaderSize();\r\n    UInt64 packProcessed;\r\n\r\n    {\r\n      result = decoder.Code(\r\n          EXTERNAL_CODECS_VARS\r\n          st, m_Stream, outStream, &packProcessed, progress);\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;\r\n        break;\r\n      }\r\n      if (result == S_FALSE)\r\n      {\r\n        opRes = NArchive::NExtract::NOperationResult::kDataError;\r\n        break;\r\n      }\r\n      RINOK(result);\r\n    }\r\n\r\n    if (packProcessed == (UInt64)(Int64)-1)\r\n      break;\r\n    RINOK(m_Stream->Seek(streamPos + packProcessed, STREAM_SEEK_SET, NULL));\r\n    currentTotalPacked += packProcessed;\r\n    streamPos += packProcessed;\r\n  }\r\n  outStream.Release();\r\n  return extractCallback->SetOperationResult(opRes);\r\n  COM_TRY_END\r\n}\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Lzma/LzmaHandler.h",
    "content": "// Lzma/Handler.h\r\n\r\n#ifndef __GZIP_HANDLER_H\r\n#define __GZIP_HANDLER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"LzmaIn.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\n// const UInt64 k_LZMA = 0x030101;\r\n\r\nclass CHandler:\r\n  public IInArchive,\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n  MY_QUERYINTERFACE_ENTRY(IInArchive)\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  STDMETHOD(Open)(IInStream *inStream,\r\n      const UInt64 *maxCheckStartPosition,\r\n      IArchiveOpenCallback *openArchiveCallback);\r\n  STDMETHOD(Close)();\r\n  \r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID,  PROPVARIANT *value);\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems,\r\n      Int32 testMode, IArchiveExtractCallback *extractCallback);\r\n\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);\r\n\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties);\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index,\r\n      BSTR *name, PROPID *propID, VARTYPE *varType);\r\n\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties);\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index,\r\n      BSTR *name, PROPID *propID, VARTYPE *varType);\r\n\r\n  UString GetMethodString();\r\npublic:\r\n  CHandler() {  }\r\n\r\nprivate:\r\n  CHeader m_StreamInfo;\r\n  UInt64 m_StreamStartPosition;\r\n  UInt64 m_PackSize;\r\n\r\n  CMyComPtr<IInStream> m_Stream;\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Lzma/LzmaIn.cpp",
    "content": "// Archive/LzmaIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaIn.h\"\r\n\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n \r\nstatic bool CheckDictSize(const Byte *p)\r\n{\r\n  UInt32 dicSize = GetUi32(p);\r\n  int i;\r\n  for (i = 1; i <= 30; i++)\r\n    if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block)\r\n{\r\n  Byte sig[5 + 9];\r\n  RINOK(ReadStream_FALSE(inStream, sig, 5 + 8));\r\n\r\n  const Byte kMaxProp0Val = 5 * 5 * 9 - 1;\r\n  if (sig[0] > kMaxProp0Val)\r\n    return S_FALSE;\r\n\r\n  for (int i = 0; i < 5; i++)\r\n    block.LzmaProps[i] = sig[i];\r\n  \r\n  block.IsThereFilter = false;\r\n  block.FilterMethod = 0;\r\n\r\n  if (!CheckDictSize(sig + 1))\r\n  {\r\n    if (sig[0] > 1 || sig[1] > kMaxProp0Val)\r\n      return S_FALSE;\r\n    block.IsThereFilter = true;\r\n    block.FilterMethod = sig[0];\r\n    for (int i = 0; i < 5; i++)\r\n      block.LzmaProps[i] = sig[i + 1];\r\n    if (!CheckDictSize(block.LzmaProps + 1))\r\n      return S_FALSE;\r\n    RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1));\r\n  }\r\n  UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0);\r\n  block.UnpackSize = GetUi64(sig + unpOffset);\r\n  if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56))\r\n    return S_FALSE;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Lzma/LzmaIn.h",
    "content": "// Archive/LzmaIn.h\r\n\r\n#ifndef __ARCHIVE_LZMA_IN_H\r\n#define __ARCHIVE_LZMA_IN_H\r\n\r\n#include \"LzmaItem.h\"\r\n#include \"../../IStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &st);\r\n\r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Lzma/LzmaItem.h",
    "content": "// Archive/LzmaItem.h\r\n\r\n#ifndef __ARCHIVE_LZMA_ITEM_H\r\n#define __ARCHIVE_LZMA_ITEM_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\n#include \"../../../../C/CpuArch.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nstruct CHeader\r\n{\r\n  UInt64 UnpackSize;\r\n  bool IsThereFilter;\r\n  Byte FilterMethod;\r\n  Byte LzmaProps[5];\r\n\r\n  UInt32 GetDicSize() const { return GetUi32(LzmaProps + 1); }\r\n  bool HasUnpackSize() const { return (UnpackSize != (UInt64)(Int64)-1);  }\r\n  unsigned GetHeaderSize() const { return 5 + 8 + (IsThereFilter ? 1 : 0); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Lzma/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Split/SplitHandler.cpp",
    "content": "// SplitHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/ComTry.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"../../Common/ProgressUtils.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/MultiStream.h\"\r\n\r\n#include \"SplitHandler.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\nSTATPROPSTG kProps[] =\r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidPackSize, VT_UI8},\r\n};\r\n\r\nIMP_IInArchive_Props\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nclass CSeqName\r\n{\r\npublic:\r\n  UString _unchangedPart;\r\n  UString _changedPart;\r\n  bool _splitStyle;\r\n  UString GetNextName()\r\n  {\r\n    UString newName;\r\n    if (_splitStyle)\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == 'z')\r\n        {\r\n          c = 'a';\r\n          newName = c + newName;\r\n          continue;\r\n        }\r\n        else if (c == 'Z')\r\n        {\r\n          c = 'A';\r\n          newName = c + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        if ((c == 'z' || c == 'Z') && i == 0)\r\n        {\r\n          _unchangedPart += c;\r\n          wchar_t newChar = (c == 'z') ? L'a' : L'A';\r\n          newName.Empty();\r\n          numLetters++;\r\n          for (int k = 0; k < numLetters; k++)\r\n            newName += newChar;\r\n          break;\r\n        }\r\n        newName = c + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == L'9')\r\n        {\r\n          c = L'0';\r\n          newName = c + newName;\r\n          if (i == 0)\r\n            newName = UString(L'1') + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        newName = c + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n    }\r\n    _changedPart = newName;\r\n    return _unchangedPart + _changedPart;\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 * /* maxCheckStartPosition */,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  if (openArchiveCallback == 0)\r\n    return S_FALSE;\r\n  // try\r\n  {\r\n    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openArchiveCallback;\r\n    if (openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback,\r\n        &openVolumeCallback) != S_OK)\r\n      return S_FALSE;\r\n    \r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(openVolumeCallback->GetProperty(kpidName, &prop));\r\n      if (prop.vt != VT_BSTR)\r\n        return S_FALSE;\r\n      _name = prop.bstrVal;\r\n    }\r\n    \r\n    int dotPos = _name.ReverseFind('.');\r\n    UString prefix, ext;\r\n    if (dotPos >= 0)\r\n    {\r\n      prefix = _name.Left(dotPos + 1);\r\n      ext = _name.Mid(dotPos + 1);\r\n    }\r\n    else\r\n      ext = _name;\r\n    UString extBig = ext;\r\n    extBig.MakeUpper();\r\n\r\n    CSeqName seqName;\r\n\r\n    int numLetters = 2;\r\n    bool splitStyle = false;\r\n    if (extBig.Right(2) == L\"AA\")\r\n    {\r\n      splitStyle = true;\r\n      while (numLetters < extBig.Length())\r\n      {\r\n        if (extBig[extBig.Length() - numLetters - 1] != 'A')\r\n          break;\r\n        numLetters++;\r\n      }\r\n    }\r\n    else if (ext.Right(2) == L\"01\")\r\n    {\r\n      while (numLetters < extBig.Length())\r\n      {\r\n        if (extBig[extBig.Length() - numLetters - 1] != '0')\r\n          break;\r\n        numLetters++;\r\n      }\r\n      if (numLetters != ext.Length())\r\n        return S_FALSE;\r\n    }\r\n    else\r\n      return S_FALSE;\r\n\r\n    _streams.Add(stream);\r\n\r\n    seqName._unchangedPart = prefix + ext.Left(extBig.Length() - numLetters);\r\n    seqName._changedPart = ext.Right(numLetters);\r\n    seqName._splitStyle = splitStyle;\r\n\r\n    if (prefix.Length() < 1)\r\n      _subName = L\"file\";\r\n    else\r\n      _subName = prefix.Left(prefix.Length() - 1);\r\n\r\n    _totalSize = 0;\r\n    UInt64 size;\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\r\n      if (prop.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      size = prop.uhVal.QuadPart;\r\n    }\r\n    _totalSize += size;\r\n    _sizes.Add(size);\r\n    \r\n    if (openArchiveCallback != NULL)\r\n    {\r\n      UInt64 numFiles = _streams.Size();\r\n      RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\r\n    }\r\n\r\n    for (;;)\r\n    {\r\n      UString fullName = seqName.GetNextName();\r\n      CMyComPtr<IInStream> nextStream;\r\n      HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);\r\n      if (result == S_FALSE)\r\n        break;\r\n      if (result != S_OK)\r\n        return result;\r\n      if (!stream)\r\n        break;\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\r\n        if (prop.vt != VT_UI8)\r\n          return E_INVALIDARG;\r\n        size = prop.uhVal.QuadPart;\r\n      }\r\n      _totalSize += size;\r\n      _sizes.Add(size);\r\n      _streams.Add(nextStream);\r\n      if (openArchiveCallback != NULL)\r\n      {\r\n        UInt64 numFiles = _streams.Size();\r\n        RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\r\n      }\r\n    }\r\n  }\r\n  /*\r\n  catch(...)\r\n  {\r\n    return S_FALSE;\r\n  }\r\n  */\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  _sizes.Clear();\r\n  _streams.Clear();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = _streams.IsEmpty() ? 0 : 1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n      prop = _subName;\r\n      break;\r\n    case kpidSize:\r\n    case kpidPackSize:\r\n      prop = _totalSize;\r\n      break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  if (numItems != UInt32(-1))\r\n  {\r\n    if (numItems != 1)\r\n      return E_INVALIDARG;\r\n    if (indices[0] != 0)\r\n      return E_INVALIDARG;\r\n  }\r\n  bool testMode = (_aTestMode != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = _anExtractCallback;\r\n  extractCallback->SetTotal(_totalSize);\r\n  \r\n  /*\r\n  CMyComPtr<IArchiveVolumeExtractCallback> volumeExtractCallback;\r\n  if (extractCallback.QueryInterface(&volumeExtractCallback) != S_OK)\r\n    return E_FAIL;\r\n  */\r\n\r\n  UInt64 currentTotalSize = 0;\r\n  UInt64 currentItemSize;\r\n\r\n  RINOK(extractCallback->SetCompleted(&currentTotalSize));\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n  Int32 askMode;\r\n  askMode = testMode ? NArchive::NExtract::NAskMode::kTest :\r\n  NArchive::NExtract::NAskMode::kExtract;\r\n  Int32 index = 0;\r\n  RINOK(extractCallback->GetStream(index, &realOutStream, askMode));\r\n  \r\n  RINOK(extractCallback->PrepareOperation(askMode));\r\n  if (testMode)\r\n  {\r\n    RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\r\n    return S_OK;\r\n  }\r\n  \r\n  if (!testMode && (!realOutStream))\r\n    return S_OK;\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for (int i = 0; i < _streams.Size(); i++, currentTotalSize += currentItemSize)\r\n  {\r\n    lps->InSize = lps->OutSize = currentTotalSize;\r\n    RINOK(lps->SetCur());\r\n    IInStream *inStream = _streams[i];\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));\r\n    currentItemSize = copyCoderSpec->TotalSize;\r\n  }\r\n  realOutStream.Release();\r\n  return extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  *stream = 0;\r\n  CMultiStream *streamSpec = new CMultiStream;\r\n  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;\r\n  for (int i = 0; i < _streams.Size(); i++)\r\n  {\r\n    CMultiStream::CSubStreamInfo subStreamInfo;\r\n    subStreamInfo.Stream = _streams[i];\r\n    subStreamInfo.Pos = 0;\r\n    subStreamInfo.Size = _sizes[i];\r\n    streamSpec->Streams.Add(subStreamInfo);\r\n  }\r\n  streamSpec->Init();\r\n  *stream = streamTemp.Detach();\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Split/SplitHandler.h",
    "content": "// Split/Handler.h\r\n\r\n#ifndef __SPLIT_HANDLER_H\r\n#define __SPLIT_HANDLER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\nclass CHandler:\r\n  public IInArchive,\r\n  public IInArchiveGetStream,\r\n  // public IOutArchive,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);\r\n\r\nprivate:\r\n  UString _subName;\r\n  UString _name;\r\n  CObjectVector<CMyComPtr<IInStream> > _streams;\r\n  CRecordVector<UInt64> _sizes;\r\n\r\n  UInt64 _totalSize;\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Split/SplitHandlerOut.cpp",
    "content": "// Split/OutHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SplitHandler.h\"\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\n/*\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  if (numItems != 1)\r\n    return E_INVALIDARG;\r\n\r\n  UInt64 volumeSize = 0;\r\n\r\n  CMyComPtr<IArchiveUpdateCallback2> callback2;\r\n  updateCallback->QueryInterface(IID_IArchiveUpdateCallback2,\r\n      (void **)&callback2);\r\n\r\n  RINOK(callback2->GetVolumeSize(0, &volumeSize));\r\n\r\n  Int32 newData;\r\n  Int32 newProperties;\r\n  UInt32 indexInArchive;\r\n  if (!updateCallback)\r\n    return E_FAIL;\r\n\r\n  UInt32 fileIndex = 0;\r\n  RINOK(updateCallback->GetUpdateItemInfo(fileIndex,\r\n    &newData, &newProperties, &indexInArchive));\r\n\r\n  if (newProperties != 0)\r\n  {\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsFolder, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n      }\r\n      else if (prop.vt != VT_BOOL)\r\n        return E_INVALIDARG;\r\n      else\r\n      {\r\n        if (prop.boolVal != VARIANT_FALSE)\r\n          return E_INVALIDARG;\r\n      }\r\n    }\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsAnti, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n      }\r\n      else if (prop.vt != VT_BOOL)\r\n        return E_INVALIDARG;\r\n      else\r\n      {\r\n        if (prop.boolVal != VARIANT_FALSE)\r\n          return E_INVALIDARG;\r\n      }\r\n    }\r\n  }\r\n  UInt64 newSize;\r\n  bool thereIsCopyData = false;\r\n  if (newData != 0)\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(updateCallback->GetProperty(fileIndex, kpidSize, &prop));\r\n    if (prop.vt != VT_UI8)\r\n      return E_INVALIDARG;\r\n    newSize = prop.uhVal.QuadPart;\r\n  }\r\n  else\r\n    thereIsCopyData = true;\r\n\r\n  UInt64 pos = 0;\r\n  while(pos < newSize)\r\n  {\r\n\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Split/SplitRegister.cpp",
    "content": "// SplitRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"SplitHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::NSplit::CHandler;  }\r\n/*\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::NSplit::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n*/\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n{ L\"Split\", L\"001\", 0, 0xEA, { 0 }, 0, false, CreateArc, 0 };\r\n\r\nREGISTER_ARC(Split)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/Split/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Archive/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Alone\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Alone - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\" CFG=\"Alone - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Alone - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Alone - Win32 Release\"\r\n# Name \"Alone - Win32 Debug\"\r\n# Name \"Alone - Win32 ReleaseU\"\r\n# Name \"Alone - Win32 DebugU\"\r\n# Begin Group \"Console\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ArError.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\CompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\Main.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\MainAr.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\AutoPtr.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Buffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ComTry.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\DynamicBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyException.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyGuidDef.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyInitGuid.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Device.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Handle.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterArc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterCodec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA_Alone\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Coder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Coder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Register.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchMisc.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchMisc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwap.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwap.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwapRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"7z\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zExtract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"split\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZM\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaArcRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaItem.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"UI Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Property.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7-zip\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IMyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IPassword.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\PropID.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\BraIA64.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Alone\"=.\\Alone.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Alone7z/makefile",
    "content": "PROG = 7za.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib Advapi32.lib\r\n\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -D_NO_CRYPTO \\\r\n  -DWIN_LONG_PATH \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n  $O\\Time.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OffsetStream.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\DummyOutStream.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\MultiStream.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n\r\nLZM_OBJS = \\\r\n  $O\\LzmaArcRegister.obj \\\r\n  $O\\LzmaFiltersDecode.obj \\\r\n  $O\\LzmaHandler.obj \\\r\n  $O\\LzmaIn.obj \\\r\n\r\nSPLIT_OBJS = \\\r\n  $O\\SplitHandler.obj \\\r\n  $O\\SplitHandlerOut.obj \\\r\n  $O\\SplitRegister.obj \\\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(LZM_OBJS) \\\r\n  $(SPLIT_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): ../../UI/Console/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../../UI/Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZM_OBJS): ../../Archive/Lzma/$(*B).cpp\r\n\t$(COMPL)\r\n$(SPLIT_OBJS): ../../Archive/Split/$(*B).cpp\r\n\t$(COMPL)\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Alone7z/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_APP(\"7-Zip Standalone Console\", \"7za\")\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Format7zExtractR/makefile",
    "content": "PROG = 7zxr.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DEXTRACT_ONLY \\\r\n  -DCOMPRESS_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Format7zExtractR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Extracting Plugin\", \"7zxr\")\r\n\r\n101  ICON  \"../../Archive/Icons/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Format7zR/makefile",
    "content": "PROG = 7zra.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Bundles/Format7zR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Plugin\", \"7zr\")\r\n\r\n101  ICON  \"../../Archive/Icons/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/CreateCoder.cpp",
    "content": "// CreateCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CreateCoder.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Windows/Defs.h\"\r\n#include \"FilterCoder.h\"\r\n#include \"RegisterCodec.h\"\r\n\r\nstatic const unsigned int kNumCodecsMax = 64;\r\nunsigned int g_NumCodecs = 0;\r\nconst CCodecInfo *g_Codecs[kNumCodecsMax];\r\nvoid RegisterCodec(const CCodecInfo *codecInfo)\r\n{\r\n  if (g_NumCodecs < kNumCodecsMax)\r\n    g_Codecs[g_NumCodecs++] = codecInfo;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = 1;\r\n  else if (prop.vt == VT_UI4)\r\n    res = prop.ulVal;\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = true;\r\n  else if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs)\r\n{\r\n  UInt32 num;\r\n  RINOK(codecsInfo->GetNumberOfMethods(&num));\r\n  for (UInt32 i = 0; i < num; i++)\r\n  {\r\n    CCodecInfoEx info;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kID, &prop));\r\n    // if (prop.vt != VT_BSTR)\r\n    // info.Id.IDSize = (Byte)SysStringByteLen(prop.bstrVal);\r\n    // memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);\r\n    if (prop.vt != VT_UI8)\r\n    {\r\n      continue; // old Interface\r\n      // return E_INVALIDARG;\r\n    }\r\n    info.Id = prop.uhVal.QuadPart;\r\n    prop.Clear();\r\n    \r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      info.Name = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_INVALIDARG;;\r\n    \r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kInStreams, info.NumInStreams));\r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kOutStreams, info.NumOutStreams));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned));\r\n    \r\n    externalCodecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  const UString &name,\r\n  CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (name.CompareNoCase(codec.Name) == 0)\r\n    {\r\n      methodId = codec.Id;\r\n      numInStreams = codec.NumInStreams;\r\n      numOutStreams = 1;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (codec.Name.CompareNoCase(name) == 0)\r\n      {\r\n        methodId = codec.Id;\r\n        numInStreams = codec.NumInStreams;\r\n        numOutStreams = codec.NumOutStreams;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  CMethodId methodId, UString &name)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (methodId == codec.Id)\r\n    {\r\n      name = codec.Name;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (methodId == codec.Id)\r\n      {\r\n        name = codec.Name;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder)\r\n{\r\n  bool created = false;\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (codec.Id == methodId)\r\n    {\r\n      if (encode)\r\n      {\r\n        if (codec.CreateEncoder)\r\n        {\r\n          void *p = codec.CreateEncoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n      }\r\n      else\r\n        if (codec.CreateDecoder)\r\n        {\r\n          void *p = codec.CreateDecoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  if (!created && externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (codec.Id == methodId)\r\n      {\r\n        if (encode)\r\n        {\r\n          if (codec.EncoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n        }\r\n        else\r\n          if (codec.DecoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n      }\r\n    }\r\n  #endif\r\n\r\n  if (onlyCoder && filter)\r\n  {\r\n    CFilterCoder *coderSpec = new CFilterCoder;\r\n    coder = coderSpec;\r\n    coderSpec->Filter = filter;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, true);\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    coder, coder2, encode);\r\n}\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressCoder> coder;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, false);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/CreateCoder.h",
    "content": "// CreateCoder.h\r\n\r\n#ifndef __CREATECODER_H\r\n#define __CREATECODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nstruct CCodecInfoEx\r\n{\r\n  UString Name;\r\n  CMethodId Id;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }\r\n  CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}\r\n};\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)\r\n#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);\r\n#define IMPL_ISetCompressCodecsInfo2(x) \\\r\nSTDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \\\r\n  COM_TRY_BEGIN _codecsInfo = compressCodecsInfo;  return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }\r\n#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)\r\n\r\n#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs\r\n#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,\r\n#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,\r\n\r\n#else\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo\r\n#define DECL_ISetCompressCodecsInfo\r\n#define IMPL_ISetCompressCodecsInfo\r\n#define EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_VARS\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2\r\n#define EXTERNAL_CODECS_LOC_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS\r\n#define EXTERNAL_CODECS_LOC_VARS\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, UString &name);\r\n\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode);\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/FilePathAutoRename.cpp",
    "content": "// FilePathAutoRename.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"FilePathAutoRename.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic bool MakeAutoName(const UString &name,\r\n    const UString &extension, int value, UString &path)\r\n{\r\n  wchar_t number[32];\r\n  ConvertUInt64ToString(value, number);\r\n  path = name;\r\n  path += number;\r\n  path += extension;\r\n  return NFile::NFind::DoesFileExist(path);\r\n}\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath)\r\n{\r\n  UString path;\r\n  int dotPos = fullProcessedPath.ReverseFind(L'.');\r\n\r\n  int slashPos = fullProcessedPath.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = fullProcessedPath.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n\r\n  UString name, extension;\r\n  if (dotPos > slashPos &&  dotPos > 0)\r\n  {\r\n    name = fullProcessedPath.Left(dotPos);\r\n    extension = fullProcessedPath.Mid(dotPos);\r\n  }\r\n  else\r\n    name = fullProcessedPath;\r\n  name += L'_';\r\n  int indexLeft = 1, indexRight = (1 << 30);\r\n  while (indexLeft != indexRight)\r\n  {\r\n    int indexMid = (indexLeft + indexRight) / 2;\r\n    if (MakeAutoName(name, extension, indexMid, path))\r\n      indexLeft = indexMid + 1;\r\n    else\r\n      indexRight = indexMid;\r\n  }\r\n  if (MakeAutoName(name, extension, indexRight, fullProcessedPath))\r\n    return false;\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/FilePathAutoRename.h",
    "content": "// Util/FilePathAutoRename.h\r\n\r\n#ifndef __FILEPATHAUTORENAME_H\r\n#define __FILEPATHAUTORENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  #ifdef _WIN32\r\n  if (result)\r\n    return S_OK;\r\n  DWORD lastError = ::GetLastError();\r\n  if (lastError == 0)\r\n    return E_FAIL;\r\n  return HRESULT_FROM_WIN32(lastError);\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nbool CInFileStream::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE),\r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do\r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  }\r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nHRESULT COutFileStream::Close()\r\n{\r\n  return ConvertBoolToHRESULT(File.Close());\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  ProcessedSize += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  ProcessedSize += res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15);\r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),\r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do\r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  }\r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WIN_FILE\r\n#endif\r\n\r\n#ifdef USE_WIN_FILE\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream:\r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\npublic:\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #endif\r\n  #endif\r\n\r\n  HRESULT Close();\r\n  \r\n  UInt64 ProcessedSize;\r\n\r\n  #ifdef USE_WIN_FILE\r\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n  {\r\n    return File.SetTime(cTime, aTime, mTime);\r\n  }\r\n  bool SetMTime(const FILETIME *mTime) {  return File.SetMTime(mTime); }\r\n  #endif\r\n\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/FilterCoder.cpp",
    "content": "// FilterCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FilterCoder.h\"\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#include \"../../Common/Defs.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCFilterCoder::CFilterCoder()\r\n{\r\n  _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n}\r\n\r\nCFilterCoder::~CFilterCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)\r\n{\r\n  if (_outSizeIsDefined)\r\n  {\r\n    UInt64 remSize = _outSize - _nowPos64;\r\n    if (size > remSize)\r\n      size = (UInt32)remSize;\r\n  }\r\n  RINOK(WriteStream(outStream, _buffer, size));\r\n  _nowPos64 += size;\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  RINOK(Init());\r\n  UInt32 bufferPos = 0;\r\n  _outSizeIsDefined = (outSize != 0);\r\n  if (_outSizeIsDefined)\r\n    _outSize = *outSize;\r\n\r\n  while(NeedMore())\r\n  {\r\n    size_t processedSize = kBufferSize - bufferPos;\r\n    \r\n    // Change it: It can be optimized using ReadPart\r\n    RINOK(ReadStream(inStream, _buffer + bufferPos, &processedSize));\r\n    \r\n    UInt32 endPos = bufferPos + (UInt32)processedSize;\r\n\r\n    bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (bufferPos > endPos)\r\n    {\r\n      for (; endPos< bufferPos; endPos++)\r\n        _buffer[endPos] = 0;\r\n      bufferPos = Filter->Filter(_buffer, endPos);\r\n    }\r\n\r\n    if (bufferPos == 0)\r\n    {\r\n      if (endPos > 0)\r\n        return WriteWithLimit(outStream, endPos);\r\n      return S_OK;\r\n    }\r\n    RINOK(WriteWithLimit(outStream, bufferPos));\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));\r\n    }\r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n// #ifdef _ST_MODE\r\nSTDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _bufferPos = 0;\r\n  _outStream = outStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseOutStream()\r\n{\r\n  _outStream.Release();\r\n  return S_OK;\r\n};\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    UInt32 sizeMax = kBufferSize - _bufferPos;\r\n    UInt32 sizeTemp = size;\r\n    if (sizeTemp > sizeMax)\r\n      sizeTemp = sizeMax;\r\n    memmove(_buffer + _bufferPos, data, sizeTemp);\r\n    size -= sizeTemp;\r\n    processedSizeTotal += sizeTemp;\r\n    data = (const Byte *)data + sizeTemp;\r\n    UInt32 endPos = _bufferPos + sizeTemp;\r\n    _bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (_bufferPos == 0)\r\n    {\r\n      _bufferPos = endPos;\r\n      break;\r\n    }\r\n    if (_bufferPos > endPos)\r\n    {\r\n      if (size != 0)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    RINOK(WriteWithLimit(_outStream, _bufferPos));\r\n    UInt32 i = 0;\r\n    while(_bufferPos < endPos)\r\n      _buffer[i++] = _buffer[_bufferPos++];\r\n    _bufferPos = i;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::Flush()\r\n{\r\n  if (_bufferPos != 0)\r\n  {\r\n    UInt32 endPos = Filter->Filter(_buffer, _bufferPos);\r\n    if (endPos > _bufferPos)\r\n    {\r\n      for (; _bufferPos < endPos; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      if (Filter->Filter(_buffer, endPos) != endPos)\r\n        return E_FAIL;\r\n    }\r\n    RINOK(WriteStream(_outStream, _buffer, _bufferPos));\r\n    _bufferPos = 0;\r\n  }\r\n  CMyComPtr<IOutStreamFlush> flush;\r\n  _outStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n  if (flush)\r\n    return  flush->Flush();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _convertedPosBegin = _convertedPosEnd = _bufferPos = 0;\r\n  _inStream = inStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseInStream()\r\n{\r\n  _inStream.Release();\r\n  return S_OK;\r\n};\r\n\r\nSTDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_convertedPosBegin != _convertedPosEnd)\r\n    {\r\n      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);\r\n      memmove(data, _buffer + _convertedPosBegin, sizeTemp);\r\n      _convertedPosBegin += sizeTemp;\r\n      data = (void *)((Byte *)data + sizeTemp);\r\n      size -= sizeTemp;\r\n      processedSizeTotal += sizeTemp;\r\n      break;\r\n    }\r\n    int i;\r\n    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)\r\n      _buffer[i] = _buffer[i + _convertedPosEnd];\r\n    _bufferPos = i;\r\n    _convertedPosBegin = _convertedPosEnd = 0;\r\n    size_t processedSizeTemp = kBufferSize - _bufferPos;\r\n    RINOK(ReadStream(_inStream, _buffer + _bufferPos, &processedSizeTemp));\r\n    _bufferPos = _bufferPos + (UInt32)processedSizeTemp;\r\n    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    if (_convertedPosEnd == 0)\r\n    {\r\n      if (_bufferPos == 0)\r\n        break;\r\n      else\r\n      {\r\n        _convertedPosEnd = _bufferPos; // check it\r\n        continue;\r\n      }\r\n    }\r\n    if (_convertedPosEnd > _bufferPos)\r\n    {\r\n      for (; _bufferPos < _convertedPosEnd; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\n// #endif // _ST_MODE\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)\r\n{\r\n  return _setPassword->CryptoSetPassword(data, size);\r\n}\r\n#endif\r\n\r\n#ifndef EXTRACT_ONLY\r\nSTDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  return _writeCoderProperties->WriteCoderProperties(outStream);\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CFilterCoder::ResetSalt()\r\n{\r\n  return _CryptoResetSalt->ResetSalt();\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CFilterCoder::ResetInitVector()\r\n{\r\n  return _CryptoResetInitVector->ResetInitVector();\r\n}\r\n#endif\r\n\r\nSTDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)\r\n{\r\n  return _setDecoderProperties->SetDecoderProperties2(data, size);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/FilterCoder.h",
    "content": "// FilterCoder.h\r\n\r\n#ifndef __FILTERCODER_H\r\n#define __FILTERCODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \\\r\n{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \\\r\n*outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\nclass CFilterCoder:\r\n  public ICompressCoder,\r\n  // #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ISequentialInStream,\r\n  public ICompressSetOutStream,\r\n  public ISequentialOutStream,\r\n  public IOutStreamFlush,\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoSetPassword,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  // public ICryptoResetSalt,\r\n  public ICryptoResetInitVector,\r\n  #endif\r\n  public ICompressSetDecoderProperties2,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  // #ifdef _ST_MODE\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  CMyComPtr<ISequentialOutStream> _outStream;\r\n  UInt32 _bufferPos;\r\n  UInt32 _convertedPosBegin;\r\n  UInt32 _convertedPosEnd;\r\n  // #endif\r\n  bool _outSizeIsDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _nowPos64;\r\n\r\n  HRESULT Init()\r\n  {\r\n    _nowPos64 = 0;\r\n    _outSizeIsDefined = false;\r\n    return Filter->Init();\r\n  }\r\n\r\n  CMyComPtr<ICryptoSetPassword> _setPassword;\r\n  #ifndef EXTRACT_ONLY\r\n  CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;\r\n  CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;\r\n  // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;\r\n  CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;\r\n  #endif\r\n  CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;\r\npublic:\r\n  CMyComPtr<ICompressFilter> Filter;\r\n\r\n  CFilterCoder();\r\n  ~CFilterCoder();\r\n  HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);\r\n  bool NeedMore() const\r\n    { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }\r\n\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n    MY_QUERYINTERFACE_ENTRY(ICompressCoder)\r\n    // #ifdef _ST_MODE\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialInStream)\r\n\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)\r\n    // #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)\r\n    #endif\r\n\r\n    #ifndef EXTRACT_ONLY\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)\r\n    // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)\r\n    #endif\r\n\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  // #ifdef _ST_MODE\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \\\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Flush)();\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  // STDMETHOD(ResetSalt)();\r\n  STDMETHOD(ResetInitVector)();\r\n  #endif\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n};\r\n\r\n// #ifdef _ST_MODE\r\nclass CInStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  CInStreamReleaser(): FilterCoder(0) {}\r\n  ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }\r\n};\r\n\r\nclass COutStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  COutStreamReleaser(): FilterCoder(0) {}\r\n  ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }\r\n};\r\n// #endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nCInBuffer::CInBuffer():\r\n  _buffer(0),\r\n  _bufferLimit(0),\r\n  _bufferBase(0),\r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct CInBufferException: public CSystemException\r\n{\r\n  CInBufferException(HRESULT errorCode): CSystemException(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if (_buffer >= _bufferLimit)\r\n      if (!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if (_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  UInt32 ReadBytes(Byte *buf, UInt32 size)\r\n  {\r\n    if ((UInt32)(_bufferLimit - _buffer) >= size)\r\n    {\r\n      for (UInt32 i = 0; i < size; i++)\r\n        buf[i] = _buffer[i];\r\n      _buffer += size;\r\n      return size;\r\n    }\r\n    for (UInt32 i = 0; i < size; i++)\r\n    {\r\n      if (_buffer >= _bufferLimit)\r\n        if (!ReadBlock())\r\n          return i;\r\n      buf[i] = *_buffer++;\r\n    }\r\n    return size;\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/InOutTempBuffer.cpp",
    "content": "// InOutTempBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InOutTempBuffer.h\"\r\n#include \"../../Common/Defs.h\"\r\n// #include \"Windows/Defs.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic UInt32 kTmpBufferMemorySize = (1 << 20);\r\n\r\nstatic LPCTSTR kTempFilePrefixString = TEXT(\"iot\");\r\n\r\nCInOutTempBuffer::CInOutTempBuffer():\r\n  _buffer(NULL)\r\n{\r\n}\r\n\r\nvoid CInOutTempBuffer::Create()\r\n{\r\n  _buffer = new Byte[kTmpBufferMemorySize];\r\n}\r\n\r\nCInOutTempBuffer::~CInOutTempBuffer()\r\n{\r\n  delete []_buffer;\r\n}\r\nvoid CInOutTempBuffer::InitWriting()\r\n{\r\n  _bufferPosition = 0;\r\n  _tmpFileCreated = false;\r\n  _fileSize = 0;\r\n}\r\n\r\nbool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)\r\n{\r\n  if (size == 0)\r\n    return true;\r\n  if(!_tmpFileCreated)\r\n  {\r\n    CSysString tempDirPath;\r\n    if(!MyGetTempPath(tempDirPath))\r\n      return false;\r\n    if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)\r\n      return false;\r\n    // _outFile.SetOpenCreationDispositionCreateAlways();\r\n    if(!_outFile.Create(_tmpFileName, true))\r\n      return false;\r\n    _tmpFileCreated = true;\r\n  }\r\n  UInt32 processedSize;\r\n  if(!_outFile.Write(data, size, processedSize))\r\n    return false;\r\n  _fileSize += processedSize;\r\n  return (processedSize == size);\r\n}\r\n\r\nbool CInOutTempBuffer::FlushWrite()\r\n{\r\n  return _outFile.Close();\r\n}\r\n\r\nbool CInOutTempBuffer::Write(const void *data, UInt32 size)\r\n{\r\n  if(_bufferPosition < kTmpBufferMemorySize)\r\n  {\r\n    UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);\r\n    memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);\r\n    _bufferPosition += curSize;\r\n    size -= curSize;\r\n    data = ((const Byte *)data) + curSize;\r\n    _fileSize += curSize;\r\n  }\r\n  return WriteToFile(data, size);\r\n}\r\n\r\nbool CInOutTempBuffer::InitReading()\r\n{\r\n  _currentPositionInBuffer = 0;\r\n  if(_tmpFileCreated)\r\n    return _inFile.Open(_tmpFileName);\r\n  return true;\r\n}\r\n\r\nHRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)\r\n{\r\n  if (_currentPositionInBuffer < _bufferPosition)\r\n  {\r\n    UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;\r\n    RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite));\r\n    _currentPositionInBuffer += sizeToWrite;\r\n  }\r\n  if (!_tmpFileCreated)\r\n    return true;\r\n  for (;;)\r\n  {\r\n    UInt32 localProcessedSize;\r\n    if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))\r\n      return E_FAIL;\r\n    if (localProcessedSize == 0)\r\n      return S_OK;\r\n    RINOK(WriteStream(stream, _buffer, localProcessedSize));\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (!_buffer->Write(data, size))\r\n  {\r\n    if (processedSize != NULL)\r\n      *processedSize = 0;\r\n    return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/InOutTempBuffer.h",
    "content": "// Util/InOutTempBuffer.h\r\n\r\n#ifndef __IN_OUT_TEMP_BUFFER_H\r\n#define __IN_OUT_TEMP_BUFFER_H\r\n\r\n#include \"../../Windows/FileIO.h\"\r\n#include \"../../Windows/FileDir.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../IStream.h\"\r\n\r\nclass CInOutTempBuffer\r\n{\r\n  NWindows::NFile::NDirectory::CTempFile _tempFile;\r\n  NWindows::NFile::NIO::COutFile _outFile;\r\n  NWindows::NFile::NIO::CInFile _inFile;\r\n  Byte *_buffer;\r\n  UInt32 _bufferPosition;\r\n  UInt32 _currentPositionInBuffer;\r\n  CSysString _tmpFileName;\r\n  bool _tmpFileCreated;\r\n\r\n  UInt64 _fileSize;\r\n\r\n  bool WriteToFile(const void *data, UInt32 size);\r\npublic:\r\n  CInOutTempBuffer();\r\n  ~CInOutTempBuffer();\r\n  void Create();\r\n\r\n  void InitWriting();\r\n  bool Write(const void *data, UInt32 size);\r\n  UInt64 GetDataSize() const { return _fileSize; }\r\n  bool FlushWrite();\r\n  bool InitReading();\r\n  HRESULT WriteToStream(ISequentialOutStream *stream);\r\n};\r\n\r\nclass CSequentialOutTempBufferImp:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CInOutTempBuffer *_buffer;\r\npublic:\r\n  // CSequentialOutStreamImp(): _size(0) {}\r\n  // UInt32 _size;\r\n  void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }\r\n  // UInt32 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/LimitedStreams.cpp",
    "content": "// LimitedStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LimitedStreams.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\nSTDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size);\r\n  HRESULT result = S_OK;\r\n  if (sizeToRead > 0)\r\n  {\r\n    result = _stream->Read(data, sizeToRead, &realProcessedSize);\r\n    _pos += realProcessedSize;\r\n    if (realProcessedSize == 0)\r\n      _wasFinished = true;\r\n  }\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  HRESULT result = S_OK;\r\n  if (processedSize != NULL)\r\n    *processedSize = 0;\r\n  if (size > _size)\r\n  {\r\n    size = (UInt32)_size;\r\n    if (size == 0)\r\n    {\r\n      _overflow = true;\r\n      return E_FAIL;\r\n    }\r\n  }\r\n  if (_stream)\r\n    result = _stream->Write(data, size, &size);\r\n  _size -= size;\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/LimitedStreams.h",
    "content": "// LimitedStreams.h\r\n\r\n#ifndef __LIMITEDSTREAMS_H\r\n#define __LIMITEDSTREAMS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLimitedSequentialInStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt64 _pos;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream; }\r\n  void Init(UInt64 streamSize)\r\n  {\r\n    _size = streamSize;\r\n    _pos = 0;\r\n    _wasFinished = false;\r\n  }\r\n \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _pos; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CLimitedSequentialOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  bool _overflow;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(UInt64 size)\r\n  {\r\n    _size = size;\r\n    _overflow = false;\r\n  }\r\n  bool IsFinishedOK() const { return (_size == 0 && !_overflow); }\r\n  UInt64 GetRem() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/LockedStream.cpp",
    "content": "// LockedStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LockedStream.h\"\r\n\r\nHRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size,\r\n  UInt32 *processedSize)\r\n{\r\n  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);\r\n  RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));\r\n  return _stream->Read(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);\r\n  _pos += realProcessedSize;\r\n  if (processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/LockedStream.h",
    "content": "// LockedStream.h\r\n\r\n#ifndef __LOCKEDSTREAM_H\r\n#define __LOCKEDSTREAM_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLockedInStream\r\n{\r\n  CMyComPtr<IInStream> _stream;\r\n  NWindows::NSynchronization::CCriticalSection _criticalSection;\r\npublic:\r\n  void Init(IInStream *stream)\r\n    { _stream = stream; }\r\n  HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CLockedSequentialInStreamImp:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CLockedInStream *_lockedInStream;\r\n  UInt64 _pos;\r\npublic:\r\n  void Init(CLockedInStream *lockedInStream, UInt64 startPos)\r\n  {\r\n    _lockedInStream = lockedInStream;\r\n    _pos = startPos;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/MethodId.cpp",
    "content": "// MethodId.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodId.h\"\r\n#include \"../../Common/MyString.h\"\r\n\r\nstatic inline wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nUString ConvertMethodIdToString(UInt64 id)\r\n{\r\n  wchar_t s[32];\r\n  int len = 32;\r\n  s[--len] = 0;\r\n  do\r\n  {\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n  }\r\n  while (id != 0);\r\n  return s + len;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/MethodId.h",
    "content": "// MethodId.h\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Common/Types.h\"\r\n\r\ntypedef UInt64 CMethodId;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/MethodProps.cpp",
    "content": "// MethodProps.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodProps.h\"\r\n\r\nstatic UInt64 k_LZMA = 0x030101;\r\n// static UInt64 k_LZMA2 = 0x030102;\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)\r\n{\r\n  bool tryReduce = false;\r\n  UInt32 reducedDictionarySize = 1 << 10;\r\n  if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))\r\n  {\r\n    for (;;)\r\n    {\r\n      const UInt32 step = (reducedDictionarySize >> 1);\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      reducedDictionarySize += step;\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      if (reducedDictionarySize >= ((UInt32)3 << 30))\r\n        break;\r\n      reducedDictionarySize += step;\r\n    }\r\n  }\r\n\r\n  {\r\n    int numProps = method.Props.Size();\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n    if (setCoderProperties == NULL)\r\n    {\r\n      if (numProps != 0)\r\n        return E_INVALIDARG;\r\n    }\r\n    else\r\n    {\r\n      CRecordVector<PROPID> propIDs;\r\n      NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps];\r\n      HRESULT res = S_OK;\r\n      try\r\n      {\r\n        for (int i = 0; i < numProps; i++)\r\n        {\r\n          const CProp &prop = method.Props[i];\r\n          propIDs.Add(prop.Id);\r\n          NWindows::NCOM::CPropVariant &value = values[i];\r\n          value = prop.Value;\r\n          // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)\r\n          if (tryReduce)\r\n            if (prop.Id == NCoderPropID::kDictionarySize)\r\n              if (value.vt == VT_UI4)\r\n                if (reducedDictionarySize < value.ulVal)\r\n            value.ulVal = reducedDictionarySize;\r\n        }\r\n        CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n        coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n        res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps);\r\n      }\r\n      catch(...)\r\n      {\r\n        delete []values;\r\n        throw;\r\n      }\r\n      delete []values;\r\n      RINOK(res);\r\n    }\r\n  }\r\n \r\n  /*\r\n  CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n  coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n  if (writeCoderProperties != NULL)\r\n  {\r\n    CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n    outStreamSpec->Init();\r\n    RINOK(writeCoderProperties->WriteCoderProperties(outStream));\r\n    size_t size = outStreamSpec->GetSize();\r\n    filterProps.SetCapacity(size);\r\n    memmove(filterProps, outStreamSpec->GetBuffer(), size);\r\n  }\r\n  */\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/MethodProps.h",
    "content": "// MethodProps.h\r\n\r\n#ifndef __7Z_METHOD_PROPS_H\r\n#define __7Z_METHOD_PROPS_H\r\n\r\n#include \"../../Common/MyVector.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\nstruct CProp\r\n{\r\n  PROPID Id;\r\n  NWindows::NCOM::CPropVariant Value;\r\n};\r\n\r\nstruct CMethod\r\n{\r\n  CMethodId Id;\r\n  CObjectVector<CProp> Props;\r\n};\r\n\r\nstruct CMethodsMode\r\n{\r\n  CObjectVector<CMethod> Methods;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n\r\n  CMethodsMode()\r\n      #ifdef COMPRESS_MT\r\n      : NumThreads(1)\r\n      #endif\r\n  {}\r\n  bool IsEmpty() const { return Methods.IsEmpty() ; }\r\n};\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/OffsetStream.cpp",
    "content": "// OffsetStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"OffsetStream.h\"\r\n\r\nHRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)\r\n{\r\n  _offset = offset;\r\n  _stream = stream;\r\n  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return _stream->Write(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 absoluteNewPosition;\r\n  if (seekOrigin == STREAM_SEEK_SET)\r\n    offset += _offset;\r\n  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);\r\n  if (newPosition != NULL)\r\n    *newPosition = absoluteNewPosition - _offset;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)\r\n{\r\n  return _stream->SetSize(_offset + newSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/OffsetStream.h",
    "content": "// OffsetStream.h\r\n\r\n#ifndef __OFFSETSTREAM_H\r\n#define __OFFSETSTREAM_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass COffsetOutStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 _offset;\r\n  CMyComPtr<IOutStream> _stream;\r\npublic:\r\n  HRESULT Init(IOutStream *stream, UInt64 offset);\r\n  \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{\r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos)\r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode == S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = Flush();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException: public CSystemException\r\n{\r\n  COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void FlushWithCheck();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/ProgressUtils.cpp",
    "content": "// ProgressUtils.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ProgressUtils.h\"\r\n\r\nCLocalProgress::CLocalProgress()\r\n{\r\n  ProgressOffset = InSize = OutSize = 0;\r\n  SendRatio = SendProgress = true;\r\n}\r\n\r\nvoid CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)\r\n{\r\n  _ratioProgress.Release();\r\n  _progress = progress;\r\n  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);\r\n  _inSizeIsMain = inSizeIsMain;\r\n}\r\n\r\nSTDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  UInt64 inSizeNew = InSize, outSizeNew = OutSize;\r\n  if (inSize)\r\n    inSizeNew += (*inSize);\r\n  if (outSize)\r\n    outSizeNew += (*outSize);\r\n  if (SendRatio && _ratioProgress)\r\n  {\r\n    RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));\r\n  }\r\n  inSizeNew += ProgressOffset;\r\n  outSizeNew += ProgressOffset;\r\n  if (SendProgress)\r\n    return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CLocalProgress::SetCur()\r\n{\r\n  return SetRatioInfo(NULL, NULL);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/ProgressUtils.h",
    "content": "// ProgressUtils.h\r\n\r\n#ifndef __PROGRESSUTILS_H\r\n#define __PROGRESSUTILS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n#include \"../IProgress.h\"\r\n\r\nclass CLocalProgress:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<IProgress> _progress;\r\n  CMyComPtr<ICompressProgressInfo> _ratioProgress;\r\n  bool _inSizeIsMain;\r\npublic:\r\n  UInt64 ProgressOffset;\r\n  UInt64 InSize;\r\n  UInt64 OutSize;\r\n  bool SendRatio;\r\n  bool SendProgress;\r\n\r\n  CLocalProgress();\r\n  void Init(IProgress *progress, bool inSizeIsMain);\r\n  HRESULT SetCur();\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/RegisterArc.h",
    "content": "// RegisterArc.h\r\n\r\n#ifndef __REGISTERARC_H\r\n#define __REGISTERARC_H\r\n\r\n#include \"../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcInfo\r\n{\r\n  const wchar_t *Name;\r\n  const wchar_t *Ext;\r\n  const wchar_t *AddExt;\r\n  Byte ClassId;\r\n  Byte Signature[16];\r\n  int SignatureSize;\r\n  bool KeepName;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n};\r\n\r\nvoid RegisterArc(const CArcInfo *arcInfo);\r\n\r\n#define REGISTER_ARC_NAME(x) CRegister ## x\r\n\r\n#define REGISTER_ARC_DEC_SIG(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { g_ArcInfo.Signature[0]--; RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#define REGISTER_ARC(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/RegisterCodec.h",
    "content": "// RegisterCodec.h\r\n\r\n#ifndef __REGISTERCODEC_H\r\n#define __REGISTERCODEC_H\r\n\r\n#include \"../Common/MethodId.h\"\r\n\r\ntypedef void * (*CreateCodecP)();\r\nstruct CCodecInfo\r\n{\r\n  CreateCodecP CreateDecoder;\r\n  CreateCodecP CreateEncoder;\r\n  CMethodId Id;\r\n  const wchar_t *Name;\r\n  UInt32 NumInStreams;\r\n  bool IsFilter;\r\n};\r\n\r\nvoid RegisterCodec(const CCodecInfo *codecInfo);\r\n\r\n#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x\r\n\r\n#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \\\r\n    REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \\\r\n    static REGISTER_CODEC_NAME(x) g_RegisterCodec;\r\n\r\n#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x\r\n#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \\\r\n    REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \\\r\n    RegisterCodec(&g_CodecsInfo[i]); }}; \\\r\n    static REGISTER_CODECS_NAME(x) g_RegisterCodecs;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/StreamBinder.cpp",
    "content": "// StreamBinder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamBinder.h\"\r\n#include \"../../Common/Defs.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NSynchronization;\r\n\r\nclass CSequentialInStreamForBinder:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Read(data, size, processedSize); }\r\n\r\nclass CSequentialOutStreamForBinder:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialOutStreamForBinder() {  m_StreamBinder->CloseWrite(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Write(data, size, processedSize); }\r\n\r\n\r\n//////////////////////////\r\n// CStreamBinder\r\n// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.\r\n\r\nHRes CStreamBinder::CreateEvents()\r\n{\r\n  RINOK(_allBytesAreWritenEvent.Create(true));\r\n  RINOK(_thereAreBytesToReadEvent.Create());\r\n  return _readStreamIsClosedEvent.Create();\r\n}\r\n\r\nvoid CStreamBinder::ReInit()\r\n{\r\n  _thereAreBytesToReadEvent.Reset();\r\n  _readStreamIsClosedEvent.Reset();\r\n  ProcessedSize = 0;\r\n}\r\n\r\n\r\n  \r\nvoid CStreamBinder::CreateStreams(ISequentialInStream **inStream,\r\n      ISequentialOutStream **outStream)\r\n{\r\n  CSequentialInStreamForBinder *inStreamSpec = new\r\n      CSequentialInStreamForBinder;\r\n  CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n  inStreamSpec->SetBinder(this);\r\n  *inStream = inStreamLoc.Detach();\r\n\r\n  CSequentialOutStreamForBinder *outStreamSpec = new\r\n      CSequentialOutStreamForBinder;\r\n  CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);\r\n  outStreamSpec->SetBinder(this);\r\n  *outStream = outStreamLoc.Detach();\r\n\r\n  _buffer = NULL;\r\n  _bufferSize= 0;\r\n  ProcessedSize = 0;\r\n}\r\n\r\nHRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 sizeToRead = size;\r\n  if (size > 0)\r\n  {\r\n    RINOK(_thereAreBytesToReadEvent.Lock());\r\n    sizeToRead = MyMin(_bufferSize, size);\r\n    if (_bufferSize > 0)\r\n    {\r\n      memcpy(data, _buffer, sizeToRead);\r\n      _buffer = ((const Byte *)_buffer) + sizeToRead;\r\n      _bufferSize -= sizeToRead;\r\n      if (_bufferSize == 0)\r\n      {\r\n        _thereAreBytesToReadEvent.Reset();\r\n        _allBytesAreWritenEvent.Set();\r\n      }\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = sizeToRead;\r\n  ProcessedSize += sizeToRead;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseRead()\r\n{\r\n  _readStreamIsClosedEvent.Set();\r\n}\r\n\r\nHRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > 0)\r\n  {\r\n    _buffer = data;\r\n    _bufferSize = size;\r\n    _allBytesAreWritenEvent.Reset();\r\n    _thereAreBytesToReadEvent.Set();\r\n\r\n    HANDLE events[2];\r\n    events[0] = _allBytesAreWritenEvent;\r\n    events[1] = _readStreamIsClosedEvent;\r\n    DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);\r\n    if (waitResult != WAIT_OBJECT_0 + 0)\r\n    {\r\n      // ReadingWasClosed = true;\r\n      return S_FALSE;\r\n    }\r\n    // if(!_allBytesAreWritenEvent.Lock())\r\n    //   return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseWrite()\r\n{\r\n  // _bufferSize must be = 0\r\n  _thereAreBytesToReadEvent.Set();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/StreamBinder.h",
    "content": "// StreamBinder.h\r\n\r\n#ifndef __STREAMBINDER_H\r\n#define __STREAMBINDER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Windows/Synchronization.h\"\r\n\r\nclass CStreamBinder\r\n{\r\n  NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent;\r\n  UInt32 _bufferSize;\r\n  const void *_buffer;\r\npublic:\r\n  // bool ReadingWasClosed;\r\n  UInt64 ProcessedSize;\r\n  CStreamBinder() {}\r\n  HRes CreateEvents();\r\n\r\n  void CreateStreams(ISequentialInStream **inStream,\r\n      ISequentialOutStream **outStream);\r\n  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseRead();\r\n\r\n  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseWrite();\r\n  void ReInit();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/StreamObjects.cpp",
    "content": "// StreamObjects.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamObjects.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\n\r\nSTDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t rem = _size - _pos;\r\n  if (size < rem)\r\n    rem = (size_t)size;\r\n  memcpy(data, _dataPointer + _pos, rem);\r\n  _pos += rem;\r\n  if (processedSize != NULL)\r\n    *processedSize = (UInt32)rem;\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CWriteBuffer::Write(const void *data, size_t size)\r\n{\r\n  size_t newCapacity = _size + size;\r\n  _buffer.EnsureCapacity(newCapacity);\r\n  memcpy(_buffer + _size, data, size);\r\n  _size += size;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  _writeBuffer.Write(data, (size_t)size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t rem = _size - _pos;\r\n  if (size < rem)\r\n    rem = (size_t)size;\r\n  memcpy(_buffer + _pos, data, rem);\r\n  _pos += rem;\r\n  if (processedSize != NULL)\r\n    *processedSize = (UInt32)rem;\r\n  return (rem == size ? S_OK : E_FAIL);\r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/StreamObjects.h",
    "content": "// StreamObjects.h\r\n\r\n#ifndef __STREAMOBJECTS_H\r\n#define __STREAMOBJECTS_H\r\n\r\n#include \"../../Common/DynamicBuffer.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CSequentialInStreamImp:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *_dataPointer;\r\n  size_t _size;\r\n  size_t _pos;\r\n\r\npublic:\r\n  void Init(const Byte *dataPointer, size_t size)\r\n  {\r\n    _dataPointer = dataPointer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n\r\nclass CWriteBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _size;\r\npublic:\r\n  CWriteBuffer(): _size(0) {}\r\n  void Init() { _size = 0;  }\r\n  void Write(const void *data, size_t size);\r\n  size_t GetSize() const { return _size; }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _buffer; }\r\n};\r\n\r\nclass CSequentialOutStreamImp:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CWriteBuffer _writeBuffer;\r\npublic:\r\n  void Init() { _writeBuffer.Init(); }\r\n  size_t GetSize() const { return _writeBuffer.GetSize(); }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamImp2:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n\r\n  void Init(Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _pos = 0;\r\n    _size = size;\r\n  }\r\n\r\n  size_t GetPos() const { return _pos; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialInStreamSizeCount:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamSizeCount:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void Init() { _size = 0; }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBlockSize = ((UInt32)1 << 31);\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSize)\r\n{\r\n  size_t size = *processedSize;\r\n  *processedSize = 0;\r\n  while (size != 0)\r\n  {\r\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\r\n    UInt32 processedSizeLoc;\r\n    HRESULT res = stream->Read(data, curSize, &processedSizeLoc);\r\n    *processedSize += processedSizeLoc;\r\n    data = (void *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size)\r\n{\r\n  size_t processedSize = size;\r\n  RINOK(ReadStream(stream, data, &processedSize));\r\n  return (size == processedSize) ? S_OK : S_FALSE;\r\n}\r\n\r\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size)\r\n{\r\n  size_t processedSize = size;\r\n  RINOK(ReadStream(stream, data, &processedSize));\r\n  return (size == processedSize) ? S_OK : E_FAIL;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size != 0)\r\n  {\r\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\r\n    UInt32 processedSizeLoc;\r\n    HRESULT res = stream->Write(data, curSize, &processedSizeLoc);\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *size);\r\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size);\r\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/VirtThread.cpp",
    "content": "// VirtThread.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"VirtThread.h\"\r\n\r\nstatic THREAD_FUNC_DECL CoderThread(void *p)\r\n{\r\n  for (;;)\r\n  {\r\n    CVirtThread *t = (CVirtThread *)p;\r\n    t->StartEvent.Lock();\r\n    if (t->ExitEvent)\r\n      return 0;\r\n    t->Execute();\r\n    t->FinishedEvent.Set();\r\n  }\r\n}\r\n\r\nWRes CVirtThread::Create()\r\n{\r\n  RINOK(StartEvent.CreateIfNotCreated());\r\n  RINOK(FinishedEvent.CreateIfNotCreated());\r\n  StartEvent.Reset();\r\n  FinishedEvent.Reset();\r\n  ExitEvent = false;\r\n  if (Thread.IsCreated())\r\n    return S_OK;\r\n  return Thread.Create(CoderThread, this);\r\n}\r\n\r\nvoid CVirtThread::Start()\r\n{\r\n  ExitEvent = false;\r\n  StartEvent.Set();\r\n}\r\n\r\nCVirtThread::~CVirtThread()\r\n{\r\n  ExitEvent = true;\r\n  if (StartEvent.IsCreated())\r\n    StartEvent.Set();\r\n  Thread.Wait();\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Common/VirtThread.h",
    "content": "// VirtThread.h\r\n\r\n#ifndef __VIRTTHREAD_H\r\n#define __VIRTTHREAD_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Windows/Thread.h\"\r\n\r\nstruct CVirtThread\r\n{\r\n  NWindows::NSynchronization::CAutoResetEvent StartEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent FinishedEvent;\r\n  NWindows::CThread Thread;\r\n  bool ExitEvent;\r\n\r\n  ~CVirtThread();\r\n  WRes Create();\r\n  void Start();\r\n  void WaitFinish() { FinishedEvent.Lock(); }\r\n  virtual void Execute() = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/Bcj2Coder.cpp",
    "content": "// Bcj2Coder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"Bcj2Coder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\ninline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }\r\ninline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }\r\ninline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CEncoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CEncoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize = 0;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusEncoder[i].Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    for (;;)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it\r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        UInt32 index;\r\n        if (b == 0xE8)\r\n          index = prevByte;\r\n        else if (b == 0xE9)\r\n          index = 256;\r\n        else if (IsJcc(prevByte, b))\r\n          index = 257;\r\n        else\r\n        {\r\n          prevByte = b;\r\n          continue;\r\n        }\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (!IsJ(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src =\r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;\r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;\r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      unsigned index = GetIndex(prevByte, b);\r\n      if (convert)\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 1);\r\n        bufferPos += 5;\r\n        COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n        for (int i = 24; i >= 0; i -= 8)\r\n          s.WriteByte((Byte)(dest >> i));\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize =\r\n        _mainStream.GetProcessedSize() +\r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeEncoder.GetProcessedSize();\r\n      */\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusDecoder[i].Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  for (;;)\r\n  {\r\n    if (processedBytes >= (1 << 20) && progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize =\r\n        _mainInStream.GetProcessedSize() +\r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeDecoder.GetProcessedSize();\r\n      */\r\n      const UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    UInt32 i;\r\n    Byte b = 0;\r\n    const UInt32 kBurstSize = (1 << 18);\r\n    for (i = 0; i < kBurstSize; i++)\r\n    {\r\n      if (!_mainInStream.ReadByte(b))\r\n        return Flush();\r\n      _outStream.WriteByte(b);\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      prevByte = b;\r\n    }\r\n    processedBytes += i;\r\n    if (i == kBurstSize)\r\n      continue;\r\n    unsigned index = GetIndex(prevByte, b);\r\n    if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)\r\n    {\r\n      UInt32 src = 0;\r\n      CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n      for (int i = 0; i < 4; i++)\r\n      {\r\n        Byte b0;\r\n        if(!s.ReadByte(b0))\r\n          return S_FALSE;\r\n        src <<= 8;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (Byte)(dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const CInBufferException &e) { return e.ErrorCode; }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/Bcj2Coder.h",
    "content": "// Bcj2Coder.h\r\n\r\n#ifndef __COMPRESS_BCJ2_CODER_H\r\n#define __COMPRESS_BCJ2_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CEncoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CEncoder(): _buffer(0) {};\r\n  ~CEncoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n};\r\n\r\n#endif\r\n\r\nclass CDecoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CDecoder *_coder;\r\n  public:\r\n    CCoderReleaser(CDecoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/Bcj2Register.cpp",
    "content": "// Bcj2Register.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"Bcj2Coder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x0303011B, L\"BCJ2\", 4, false };\r\n\r\nREGISTER_CODEC(BCJ2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/BcjCoder.cpp",
    "content": "// BcjCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"BcjCoder.h\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/BcjCoder.h",
    "content": "// BcjCoder.h\r\n\r\n#ifndef __COMPRESS_BCJ_CODER_H\r\n#define __COMPRESS_BCJ_CODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Bra.h\"\r\n}\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  void x86Init() { x86_Convert_Init(_prevMask); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 ,\r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/BcjRegister.cpp",
    "content": "// BcjRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"BcjCoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x03030103, L\"BCJ\", 1, true };\r\n\r\nREGISTER_CODEC(BCJ)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __COMPRESS_BRANCH_CODER_H\r\n#define __COMPRESS_BRANCH_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/BranchMisc.cpp",
    "content": "// BranchMisc.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Bra.h\"\r\n}\r\n\r\n#include \"BranchMisc.h\"\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  {  return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); }\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/BranchMisc.h",
    "content": "// BranchMisc.h\r\n\r\n#ifndef __COMPRESS_BRANCH_MISC_H\r\n#define __COMPRESS_BRANCH_MISC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM,   0x05, 1)\r\nMyClassA(BC_ARMT,  0x07, 1)\r\nMyClassA(BC_PPC,   0x02, 5)\r\nMyClassA(BC_SPARC, 0x08, 5)\r\nMyClassA(BC_IA64,  0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/BranchRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"BranchMisc.h\"\r\n\r\n#define CREATE_CODEC(x) \\\r\n  static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \\\r\n  static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }\r\n\r\nCREATE_CODEC(BC_PPC)\r\nCREATE_CODEC(BC_IA64)\r\nCREATE_CODEC(BC_ARM)\r\nCREATE_CODEC(BC_ARMT)\r\nCREATE_CODEC(BC_SPARC)\r\n\r\n#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true  }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  METHOD_ITEM(BC_PPC,   0x02, 0x05, L\"PPC\"),\r\n  METHOD_ITEM(BC_IA64,  0x04, 1, L\"IA64\"),\r\n  METHOD_ITEM(BC_ARM,   0x05, 1, L\"ARM\"),\r\n  METHOD_ITEM(BC_ARMT,  0x07, 1, L\"ARMT\"),\r\n  METHOD_ITEM(BC_SPARC, 0x08, 0x05, L\"SPARC\")\r\n};\r\n\r\nREGISTER_CODECS(Branch)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/ByteSwap.cpp",
    "content": "// ByteSwap.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nSTDMETHODIMP CByteSwap2::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 2;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b = data[i];\r\n    data[i] = data[i + 1];\r\n    data[i + 1] = b;\r\n  }\r\n  return i;\r\n}\r\n\r\nSTDMETHODIMP CByteSwap4::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 4;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b0 = data[i];\r\n    Byte b1 = data[i + 1];\r\n    data[i] = data[i + 3];\r\n    data[i + 1] = data[i + 2];\r\n    data[i + 2] = b1;\r\n    data[i + 3] = b0;\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/ByteSwap.h",
    "content": "// ByteSwap.h\r\n\r\n#ifndef __COMPRESS_BYTE_SWAP_H\r\n#define __COMPRESS_BYTE_SWAP_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nclass CByteSwap2:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\nclass CByteSwap4:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/ByteSwapRegister.cpp",
    "content": "// ByteSwapRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nstatic void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }\r\nstatic void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  { CreateCodec2, CreateCodec4, 0x020302, L\"Swap2\", 1, true },\r\n  { CreateCodec4, CreateCodec4, 0x020304, L\"Swap4\", 1, true }\r\n};\r\n\r\nREGISTER_CODECS(ByteSwap)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/CodecExports.cpp",
    "content": "// CodecExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterCodec.h\"\r\n#include \"../ICoder.h\"\r\n\r\nextern unsigned int g_NumCodecs;\r\nextern const CCodecInfo *g_Codecs[];\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec,\r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nstatic HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)\r\n{\r\n  GUID clsId = CLSID_CCodec;\r\n  for (int i = 0; i < sizeof(id); i++, id >>= 8)\r\n    clsId.Data4[i] = (Byte)(id & 0xFF);\r\n  if (encode)\r\n    clsId.Data3++;\r\n  return SetPropGUID(clsId, value);\r\n}\r\n\r\nstatic HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)\r\n{\r\n  index = -1;\r\n  if (clsID->Data1 != CLSID_CCodec.Data1 ||\r\n      clsID->Data2 != CLSID_CCodec.Data2 ||\r\n      (clsID->Data3 & ~1) != kDecodeId)\r\n    return S_OK;\r\n  encode = (clsID->Data3 != kDecodeId);\r\n  UInt64 id = 0;\r\n  for (int j = 0; j < 8; j++)\r\n    id |= ((UInt64)clsID->Data4[j]) << (8 * j);\r\n  for (unsigned i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)\r\n      continue;\r\n    if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n        codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n      return E_NOINTERFACE;\r\n    index = i;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  const CCodecInfo &codec = *g_Codecs[index];\r\n  if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n      codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n    return E_NOINTERFACE;\r\n  if (encode)\r\n  {\r\n    if (!codec.CreateEncoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateEncoder();\r\n  }\r\n  else\r\n  {\r\n    if (!codec.CreateDecoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateDecoder();\r\n  }\r\n  if (isCoder)\r\n    ((ICompressCoder *)*outObject)->AddRef();\r\n  else if (isCoder2)\r\n    ((ICompressCoder2 *)*outObject)->AddRef();\r\n  else\r\n    ((ICompressFilter *)*outObject)->AddRef();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  if (!isCoder && !isCoder2 && !isFilter)\r\n    return E_NOINTERFACE;\r\n  bool encode;\r\n  int codecIndex;\r\n  HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);\r\n  if (res != S_OK)\r\n    return res;\r\n  if (codecIndex < 0)\r\n    return CLASS_E_CLASSNOTAVAILABLE;\r\n  return CreateCoder2(encode, codecIndex, iid, outObject);\r\n}\r\n\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  ::VariantClear((VARIANTARG *)value);\r\n  const CCodecInfo &codec = *g_Codecs[codecIndex];\r\n  switch(propID)\r\n  {\r\n    case NMethodPropID::kID:\r\n    {\r\n      value->uhVal.QuadPart = (UInt64)codec.Id;\r\n      value->vt = VT_UI8;\r\n      break;\r\n    }\r\n    case NMethodPropID::kName:\r\n      if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)\r\n        value->vt = VT_BSTR;\r\n      break;\r\n    case NMethodPropID::kDecoder:\r\n      if (codec.CreateDecoder)\r\n        return SetClassID(codec.Id, false, value);\r\n      break;\r\n    case NMethodPropID::kEncoder:\r\n      if (codec.CreateEncoder)\r\n        return SetClassID(codec.Id, true, value);\r\n      break;\r\n    case NMethodPropID::kInStreams:\r\n    {\r\n      if (codec.NumInStreams != 1)\r\n      {\r\n        value->vt = VT_UI4;\r\n        value->ulVal = (ULONG)codec.NumInStreams;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetNumberOfMethods(UINT32 *numCodecs)\r\n{\r\n  *numCodecs = g_NumCodecs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/CopyCoder.cpp",
    "content": "// Compress/CopyCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"CopyCoder.h\"\r\n\r\nnamespace NCompress {\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCCopyCoder::~CCopyCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  TotalSize = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 realProcessedSize;\r\n    UInt32 size = kBufferSize;\r\n    if (outSize != 0)\r\n      if (size > *outSize - TotalSize)\r\n        size = (UInt32)(*outSize - TotalSize);\r\n    RINOK(inStream->Read(_buffer, size, &realProcessedSize));\r\n    if (realProcessedSize == 0)\r\n      break;\r\n    RINOK(WriteStream(outStream, _buffer, realProcessedSize));\r\n    TotalSize += realProcessedSize;\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = TotalSize;\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/CopyCoder.h",
    "content": "// Compress/CopyCoder.h\r\n\r\n#ifndef __COMPRESS_COPY_CODER_H\r\n#define __COMPRESS_COPY_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\n\r\nclass CCopyCoder:\r\n  public ICompressCoder,\r\n  public ICompressGetInStreamProcessedSize,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  UInt64 TotalSize;\r\n  CCopyCoder(): TotalSize(0) , _buffer(0) {};\r\n  ~CCopyCoder();\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/CopyRegister.cpp",
    "content": "// CopyRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"CopyCoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n{ CreateCodec, CreateCodec, 0x00, L\"Copy\", 1, false };\r\n\r\nREGISTER_CODEC(Copy)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /FAcs /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEncoder.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LzmaUtil\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LzmaDecoder.h\"\r\n#include \"../LzmaEncoder.h\"\r\n\r\n#include \"LzmaBenchCon.h\"\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/7zVersion.h\"\r\n  #include \"../../../../C/Alloc.h\"\r\n  #include \"../../../../C/LzmaUtil/Lzma86Dec.h\"\r\n  #include \"../../../../C/LzmaUtil/Lzma86Enc.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kAlgo,\r\n  kDict,\r\n  kFb,\r\n  kMc,\r\n  kLc,\r\n  kLp,\r\n  kPb,\r\n  kMatchFinder,\r\n  kMultiThread,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] =\r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MT\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kPostChar, false, 0, 0, L\"+\" }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\"\r\n    \"  -d{N}:  set dictionary size - [12, 30], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -mc{N}: set number of cycles for match finder\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\\n\"\r\n    \"  -mt{N}: set number of CPU threads\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[],\r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nstatic void ParseUInt32(const CParser &parser, int index, UInt32 &res)\r\n{\r\n  if (parser[index].ThereIs)\r\n    if (!GetNumber(parser[index].PostStrings[0], res))\r\n      IncorrectCommand();\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);\r\n  if (unsupportedTypes)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }\r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...)\r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++];\r\n\r\n  bool dictDefined = false;\r\n  UInt32 dict = (UInt32)-1;\r\n  if(parser[NKey::kDict].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDict].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dict = 1 << dicLog;\r\n    dictDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  UInt32 numThreads = (UInt32)-1;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (parser[NKey::kMultiThread].ThereIs)\r\n  {\r\n    UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n    const UString &s = parser[NKey::kMultiThread].PostStrings[0];\r\n    if (s.IsEmpty())\r\n      numThreads = numCPUs;\r\n    else\r\n      if (!GetNumber(s, numThreads))\r\n        IncorrectCommand();\r\n  }\r\n  #endif\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 1;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchCon(stderr, numIterations, numThreads, dict);\r\n  }\r\n\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = 1;\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++];\r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\",\r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  COutFileStream *outStreamSpec = NULL;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++];\r\n    outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\",\r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    size_t inSize = (size_t)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize);\r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    if (ReadStream_FAIL(inStream, inBuffer, inSize) != S_OK)\r\n      throw \"Can not read\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSize;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize);\r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictDefined)\r\n        dict = 1 << 23;\r\n      int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,\r\n          5, dict, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      UInt64 outSize64;\r\n      if (Lzma86_GetUnpackSize(inBuffer, inSize, &outSize64) != 0)\r\n        throw \"data error\";\r\n      outSize = (size_t)outSize64;\r\n      if (outSize != outSize64)\r\n        throw \"too big\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize);\r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = Lzma86_Decode(outBuffer, &outSize, inBuffer, &inSize);\r\n      if (inSize != (size_t)fileSize)\r\n        throw \"incorrect processed size\";\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, outSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLzma::CEncoder *encoderSpec = new NCompress::NLzma::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictDefined)\r\n      dict = 1 << 23;\r\n\r\n    UInt32 pb = 2;\r\n    UInt32 lc = 3; // = 0; for 32-bit data\r\n    UInt32 lp = 0; // = 2; for 32-bit data\r\n    UInt32 algo = 1;\r\n    UInt32 fb = 128;\r\n    UInt32 mc = 16 + fb / 2;\r\n    bool mcDefined = false;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    ParseUInt32(parser, NKey::kAlgo, algo);\r\n    ParseUInt32(parser, NKey::kFb, fb);\r\n    ParseUInt32(parser, NKey::kLc, lc);\r\n    ParseUInt32(parser, NKey::kLp, lp);\r\n    ParseUInt32(parser, NKey::kPb, pb);\r\n\r\n    mcDefined = parser[NKey::kMc].ThereIs;\r\n    if (mcDefined)\r\n      if (!GetNumber(parser[NKey::kMc].PostStrings[0], mc))\r\n        IncorrectCommand();\r\n    \r\n    PROPID propIDs[] =\r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker,\r\n      NCoderPropID::kNumThreads,\r\n      NCoderPropID::kMatchFinderCycles,\r\n    };\r\n    const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\r\n    PROPVARIANT props[kNumPropsMax];\r\n    for (int p = 0; p < 6; p++)\r\n      props[p].vt = VT_UI4;\r\n\r\n    props[0].ulVal = (UInt32)dict;\r\n    props[1].ulVal = (UInt32)pb;\r\n    props[2].ulVal = (UInt32)lc;\r\n    props[3].ulVal = (UInt32)lp;\r\n    props[4].ulVal = (UInt32)algo;\r\n    props[5].ulVal = (UInt32)fb;\r\n\r\n    props[6].vt = VT_BSTR;\r\n    props[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    props[7].vt = VT_BOOL;\r\n    props[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    props[8].vt = VT_UI4;\r\n    props[8].ulVal = (UInt32)numThreads;\r\n\r\n    // it must be last in property list\r\n    props[9].vt = VT_UI4;\r\n    props[9].ulVal = (UInt32)mc;\r\n\r\n    int numProps = kNumPropsMax;\r\n    if (!mcDefined)\r\n      numProps--;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, props, numProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }\r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NCompress::NLzma::CDecoder *decoderSpec = new NCompress::NLzma::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    decoderSpec->FinishStream = true;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte header[kPropertiesSize + 8];\r\n    if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(header, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n      fileSize |= ((UInt64)header[kPropertiesSize + i]) << (8 * i);\r\n\r\n    if (decoder->Code(inStream, outStream, 0, (fileSize == (UInt64)(Int64)-1) ? 0 : &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }\r\n  }\r\n  if (outStreamSpec != NULL)\r\n  {\r\n    if (outStreamSpec->Close() != S_OK)\r\n    {\r\n      fprintf(stderr, \"File closing error\");\r\n      return 1;\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n\r\nint MY_CDECL main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s)\r\n  {\r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1;\r\n  }\r\n  catch(...)\r\n  {\r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#define USE_POSIX_TIME\r\n#define USE_POSIX_TIME2\r\n#endif\r\n\r\n#ifdef USE_POSIX_TIME\r\n#include <time.h>\r\n#ifdef USE_POSIX_TIME2\r\n#include <sys/time.h>\r\n#endif\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n\r\n#ifdef BENCH_MT\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Windows/Thread.h\"\r\n#endif\r\n\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../ICoder.h\"\r\n#else\r\n#include \"../LzmaDecoder.h\"\r\n#include \"../LzmaEncoder.h\"\r\n#endif\r\n\r\nstatic const UInt32 kUncompressMinBlockSize = 1 << 26;\r\nstatic const UInt32 kAdditionalSize = (1 << 16);\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 5;\r\n\r\nclass CBaseRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CBaseRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd()\r\n  {\r\n    return\r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBenchBuffer\r\n{\r\npublic:\r\n  size_t BufferSize;\r\n  Byte *Buffer;\r\n  CBenchBuffer(): Buffer(0) {}\r\n  virtual ~CBenchBuffer() { Free(); }\r\n  void Free()\r\n  {\r\n    ::MidFree(Buffer);\r\n    Buffer = 0;\r\n  }\r\n  bool Alloc(size_t bufferSize)\r\n  {\r\n    if (Buffer != 0 && BufferSize == bufferSize)\r\n      return true;\r\n    Free();\r\n    Buffer = (Byte *)::MidAlloc(bufferSize);\r\n    BufferSize = bufferSize;\r\n    return (Buffer != 0);\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator: public CBenchBuffer\r\n{\r\n  CBaseRandomGenerator *RG;\r\npublic:\r\n  void Set(CBaseRandomGenerator *rg) { RG = rg; }\r\n  UInt32 GetVal(UInt32 &res, int numBits)\r\n  {\r\n    UInt32 val = res & (((UInt32)1 << numBits) - 1);\r\n    res >>= numBits;\r\n    return val;\r\n  }\r\n  UInt32 GetLen(UInt32 &res)\r\n  {\r\n    UInt32 len = GetVal(res, 2);\r\n    return GetVal(res, 1 + len);\r\n  }\r\n  void Generate()\r\n  {\r\n    UInt32 pos = 0;\r\n    UInt32 rep0 = 1;\r\n    while (pos < BufferSize)\r\n    {\r\n      UInt32 res = RG->GetRnd();\r\n      res >>= 1;\r\n      if (GetVal(res, 1) == 0 || pos < 1024)\r\n        Buffer[pos++] = (Byte)(res & 0xFF);\r\n      else\r\n      {\r\n        UInt32 len;\r\n        len = 1 + GetLen(res);\r\n        if (GetVal(res, 3) != 0)\r\n        {\r\n          len += GetLen(res);\r\n          do\r\n          {\r\n            UInt32 ppp = GetVal(res, 5) + 6;\r\n            res = RG->GetRnd();\r\n            if (ppp > 30)\r\n              continue;\r\n            rep0 = /* (1 << ppp) +*/  GetVal(res, ppp);\r\n            res = RG->GetRnd();\r\n          }\r\n          while (rep0 >= pos);\r\n          rep0++;\r\n        }\r\n\r\n        for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)\r\n          Buffer[pos] = Buffer[pos - rep0];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\n\r\nclass CBenchmarkInStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Pos;\r\n  size_t Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t remain = Size - Pos;\r\n  UInt32 kMaxBlockSize = (1 << 20);\r\n  if (size > kMaxBlockSize)\r\n    size = kMaxBlockSize;\r\n  if (size > remain)\r\n    size = (UInt32)remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream:\r\n  public ISequentialOutStream,\r\n  public CBenchBuffer,\r\n  public CMyUnknownImp\r\n{\r\n  // bool _overflow;\r\npublic:\r\n  UInt32 Pos;\r\n  // CBenchmarkOutStream(): _overflow(false) {}\r\n  void Init()\r\n  {\r\n    // _overflow = false;\r\n    Pos = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t curSize = BufferSize - Pos;\r\n  if (curSize > size)\r\n    curSize = size;\r\n  memcpy(Buffer + Pos, data, curSize);\r\n  Pos += (UInt32)curSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)curSize;\r\n  if (curSize != size)\r\n  {\r\n    // _overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  UInt32 Crc;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { Crc = CRC_INIT_VAL; }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  Crc = CrcUpdate(Crc, data, size);\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  timeval v;\r\n  if (gettimeofday(&v, 0) == 0)\r\n    return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;\r\n  return (UInt64)time(NULL) * 1000000;\r\n  #else\r\n  return time(NULL);\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return GetTickCount();\r\n  #endif\r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  return 1000000;\r\n  #else\r\n  return 1;\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return 1000;\r\n  #endif\r\n}\r\n\r\n#ifndef USE_POSIX_TIME\r\nstatic inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }\r\n#endif\r\nstatic UInt64 GetUserTime()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return clock();\r\n  #else\r\n  FILETIME creationTime, exitTime, kernelTime, userTime;\r\n  if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)\r\n    return GetTime64(userTime) + GetTime64(kernelTime);\r\n  return (UInt64)GetTickCount() * 10000;\r\n  #endif\r\n}\r\n\r\nstatic UInt64 GetUserFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return CLOCKS_PER_SEC;\r\n  #else\r\n  return 10000000;\r\n  #endif\r\n}\r\n\r\nclass CBenchProgressStatus\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::NSynchronization::CCriticalSection CS;\r\n  #endif\r\npublic:\r\n  HRESULT Res;\r\n  bool EncodeMode;\r\n  void SetResult(HRESULT res)\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    Res = res;\r\n  }\r\n  HRESULT GetResult()\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    return Res;\r\n  }\r\n};\r\n\r\nclass CBenchProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CBenchProgressStatus *Status;\r\n  CBenchInfo BenchInfo;\r\n  HRESULT Res;\r\n  IBenchCallback *callback;\r\n  CBenchProgressInfo(): callback(0) {}\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nvoid SetStartTime(CBenchInfo &bi)\r\n{\r\n  bi.GlobalFreq = GetFreq();\r\n  bi.UserFreq = GetUserFreq();\r\n  bi.GlobalTime = ::GetTimeCount();\r\n  bi.UserTime = ::GetUserTime();\r\n}\r\n\r\nvoid SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)\r\n{\r\n  dest.GlobalFreq = GetFreq();\r\n  dest.UserFreq = GetUserFreq();\r\n  dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;\r\n  dest.UserTime = ::GetUserTime() - biStart.UserTime;\r\n}\r\n\r\nSTDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  HRESULT res = Status->GetResult();\r\n  if (res != S_OK)\r\n    return res;\r\n  if (!callback)\r\n    return res;\r\n  CBenchInfo info = BenchInfo;\r\n  SetFinishTime(BenchInfo, info);\r\n  if (Status->EncodeMode)\r\n  {\r\n    info.UnpackSize = *inSize;\r\n    info.PackSize = *outSize;\r\n    res = callback->SetEncodeResult(info, false);\r\n  }\r\n  else\r\n  {\r\n    info.PackSize = BenchInfo.PackSize + *inSize;\r\n    info.UnpackSize = BenchInfo.UnpackSize + *outSize;\r\n    res = callback->SetDecodeResult(info, false);\r\n  }\r\n  if (res != S_OK)\r\n    Status->SetResult(res);\r\n  return res;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nUInt64 GetUsage(const CBenchInfo &info)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userTime, userFreq);\r\n  NormalizeVals(globalFreq, globalTime);\r\n  if (userFreq == 0)\r\n    userFreq = 1;\r\n  if (globalTime == 0)\r\n    globalTime = 1;\r\n  return userTime * globalFreq * 1000000 / userFreq / globalTime;\r\n}\r\n\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userFreq, userTime);\r\n  NormalizeVals(globalTime, globalFreq);\r\n  if (globalFreq == 0)\r\n    globalFreq = 1;\r\n  if (userTime == 0)\r\n    userTime = 1;\r\n  return userFreq * globalTime / globalFreq *  rating / userTime;\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)\r\n{\r\n  UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);\r\n  UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits));\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)\r\n{\r\n  UInt64 numCommands = (inSize * 200 + outSize * 4) * numIterations;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\n#ifdef EXTERNAL_LZMA\r\ntypedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID,\r\n    const GUID *interfaceID, void **outObject);\r\n#endif\r\n\r\nstruct CEncoderInfo;\r\n\r\nstruct CEncoderInfo\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::CThread thread[2];\r\n  #endif\r\n  CMyComPtr<ICompressCoder> encoder;\r\n  CBenchProgressInfo *progressInfoSpec[2];\r\n  CMyComPtr<ICompressProgressInfo> progressInfo[2];\r\n  UInt32 NumIterations;\r\n  #ifdef USE_ALLOCA\r\n  size_t AllocaSize;\r\n  #endif\r\n\r\n  struct CDecoderInfo\r\n  {\r\n    CEncoderInfo *Encoder;\r\n    UInt32 DecoderIndex;\r\n    #ifdef USE_ALLOCA\r\n    size_t AllocaSize;\r\n    #endif\r\n    bool CallbackMode;\r\n  };\r\n  CDecoderInfo decodersInfo[2];\r\n\r\n  CMyComPtr<ICompressCoder> decoders[2];\r\n  HRESULT Results[2];\r\n  CBenchmarkOutStream *outStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  IBenchCallback *callback;\r\n  UInt32 crc;\r\n  UInt32 kBufferSize;\r\n  UInt32 compressedSize;\r\n  CBenchRandomGenerator rg;\r\n  CBenchmarkOutStream *propStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> propStream;\r\n  HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);\r\n  HRESULT Encode();\r\n  HRESULT Decode(UInt32 decoderIndex);\r\n\r\n  CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}\r\n\r\n  #ifdef BENCH_MT\r\n  static THREAD_FUNC_DECL EncodeThreadFunction(void *param)\r\n  {\r\n    CEncoderInfo *encoder = (CEncoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(encoder->AllocaSize);\r\n    #endif\r\n    HRESULT res = encoder->Encode();\r\n    encoder->Results[0] = res;\r\n    if (res != S_OK)\r\n      encoder->progressInfoSpec[0]->Status->SetResult(res);\r\n\r\n    return 0;\r\n  }\r\n  static THREAD_FUNC_DECL DecodeThreadFunction(void *param)\r\n  {\r\n    CDecoderInfo *decoder = (CDecoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(decoder->AllocaSize);\r\n    #endif\r\n    CEncoderInfo *encoder = decoder->Encoder;\r\n    encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);\r\n    return 0;\r\n  }\r\n\r\n  HRESULT CreateEncoderThread()\r\n  {\r\n    return thread[0].Create(EncodeThreadFunction, this);\r\n  }\r\n\r\n  HRESULT CreateDecoderThread(int index, bool callbackMode\r\n      #ifdef USE_ALLOCA\r\n      , size_t allocaSize\r\n      #endif\r\n      )\r\n  {\r\n    CDecoderInfo &decoder = decodersInfo[index];\r\n    decoder.DecoderIndex = index;\r\n    decoder.Encoder = this;\r\n    #ifdef USE_ALLOCA\r\n    decoder.AllocaSize = allocaSize;\r\n    #endif\r\n    decoder.CallbackMode = callbackMode;\r\n    return thread[index].Create(DecodeThreadFunction, &decoder);\r\n  }\r\n  #endif\r\n};\r\n\r\nHRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)\r\n{\r\n  rg.Set(rgLoc);\r\n  kBufferSize = dictionarySize + kAdditionalSize;\r\n  UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n  if (!rg.Alloc(kBufferSize))\r\n    return E_OUTOFMEMORY;\r\n  rg.Generate();\r\n  crc = CrcCalc(rg.Buffer, rg.BufferSize);\r\n\r\n  outStreamSpec = new CBenchmarkOutStream;\r\n  if (!outStreamSpec->Alloc(kCompressedBufferSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  outStream = outStreamSpec;\r\n\r\n  propStreamSpec = 0;\r\n  if (!propStream)\r\n  {\r\n    propStreamSpec = new CBenchmarkOutStream;\r\n    propStream = propStreamSpec;\r\n  }\r\n  if (!propStreamSpec->Alloc(kMaxLzmaPropSize))\r\n    return E_OUTOFMEMORY;\r\n  propStreamSpec->Init();\r\n  \r\n  PROPID propIDs[] =\r\n  {\r\n    NCoderPropID::kDictionarySize,\r\n    NCoderPropID::kMultiThread\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)dictionarySize;\r\n\r\n  properties[1].vt = VT_BOOL;\r\n  properties[1].boolVal = (numThreads > 1) ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n  {\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));\r\n    if (!setCoderProperties)\r\n      return E_FAIL;\r\n    RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, kNumProps));\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);\r\n    if (writeCoderProperties)\r\n    {\r\n      RINOK(writeCoderProperties->WriteCoderProperties(propStream));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Encode()\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n  outStreamSpec->Init();\r\n\r\n  RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));\r\n  compressedSize = outStreamSpec->Pos;\r\n  encoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Decode(UInt32 decoderIndex)\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];\r\n\r\n  CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;\r\n  decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);\r\n  if (!compressSetDecoderProperties)\r\n    return E_FAIL;\r\n\r\n  CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n  CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n  CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];\r\n  pi->BenchInfo.UnpackSize = 0;\r\n  pi->BenchInfo.PackSize = 0;\r\n\r\n  for (UInt32 j = 0; j < NumIterations; j++)\r\n  {\r\n    inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n    crcOutStreamSpec->Init();\r\n    \r\n    RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));\r\n    UInt64 outSize = kBufferSize;\r\n    RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));\r\n    if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)\r\n      return S_FALSE;\r\n    pi->BenchInfo.UnpackSize += kBufferSize;\r\n    pi->BenchInfo.PackSize += compressedSize;\r\n  }\r\n  decoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nstatic const UInt32 kNumThreadsMax = (1 << 16);\r\n\r\nstruct CBenchEncoders\r\n{\r\n  CEncoderInfo *encoders;\r\n  CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }\r\n  ~CBenchEncoders() { delete []encoders; }\r\n};\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)\r\n{\r\n  UInt32 numEncoderThreads =\r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? numThreads / 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  UInt32 numSubDecoderThreads =\r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)\r\n  {\r\n    return E_INVALIDARG;\r\n  }\r\n\r\n  CBenchEncoders encodersSpec(numEncoderThreads);\r\n  CEncoderInfo *encoders = encodersSpec.encoders;\r\n\r\n  #ifdef EXTERNAL_LZMA\r\n  UString name = L\"LZMA\";\r\n  #endif\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.callback = (i == 0) ? callback : 0;\r\n\r\n    #ifdef EXTERNAL_LZMA\r\n    RINOK(codecs->CreateCoder(name, true, encoder.encoder));\r\n    #else\r\n    encoder.encoder = new NCompress::NLzma::CEncoder;\r\n    #endif\r\n    for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n    {\r\n      #ifdef EXTERNAL_LZMA\r\n      RINOK(codecs->CreateCoder(name, false, encoder.decoders[j]));\r\n      #else\r\n      encoder.decoders[j] = new NCompress::NLzma::CDecoder;\r\n      #endif\r\n    }\r\n  }\r\n\r\n  CBaseRandomGenerator rg;\r\n  rg.Init();\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));\r\n  }\r\n\r\n  CBenchProgressStatus status;\r\n  status.Res = S_OK;\r\n  status.EncodeMode = true;\r\n\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;\r\n      encoder.progressInfoSpec[j]->Status = &status;\r\n    }\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numEncoderThreads > 1)\r\n    {\r\n      #ifdef USE_ALLOCA\r\n      encoder.AllocaSize = (i * 16 * 21) & 0x7FF;\r\n      #endif\r\n      RINOK(encoder.CreateEncoderThread())\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Encode());\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  if (numEncoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      encoders[i].thread[0].Wait();\r\n  #endif\r\n\r\n  RINOK(status.Res);\r\n\r\n  CBenchInfo info;\r\n\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = 1; // progressInfoSpec->NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetEncodeResult(info, true));\r\n\r\n\r\n  status.Res = S_OK;\r\n  status.EncodeMode = false;\r\n\r\n  UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;\r\n\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numDecoderThreads > 1)\r\n    {\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)\r\n            #ifdef USE_ALLOCA\r\n            , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF\r\n            #endif\r\n            );\r\n        RINOK(res);\r\n      }\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Decode(0));\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  HRESULT res = S_OK;\r\n  if (numDecoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        CEncoderInfo &encoder = encoders[i];\r\n        encoder.thread[j].Wait();\r\n        if (encoder.Results[j] != S_OK)\r\n          res = encoder.Results[j];\r\n      }\r\n  RINOK(res);\r\n  #endif\r\n  RINOK(status.Res);\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetDecodeResult(info, false));\r\n  RINOK(callback->SetDecodeResult(info, true));\r\n  return S_OK;\r\n}\r\n\r\n\r\ninline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)\r\n{\r\n  UInt32 hs = dictionary - 1;\r\n  hs |= (hs >> 1);\r\n  hs |= (hs >> 2);\r\n  hs |= (hs >> 4);\r\n  hs |= (hs >> 8);\r\n  hs >>= 1;\r\n  hs |= 0xFFFF;\r\n  if (hs > (1 << 24))\r\n    hs >>= 1;\r\n  hs++;\r\n  return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +\r\n      (1 << 20) + (multiThread ? (6 << 20) : 0);\r\n}\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  const UInt32 kBufferSize = dictionary;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2);\r\n  UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;\r\n  UInt32 numBigThreads = numThreads / numSubThreads;\r\n  return (kBufferSize + kCompressedBufferSize +\r\n    GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;\r\n}\r\n\r\nstatic bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)\r\n{\r\n  for (UInt32 i = 0; i < numCycles; i++)\r\n    if (CrcCalc(data, size) != crcBase)\r\n      return false;\r\n  return true;\r\n}\r\n\r\n#ifdef BENCH_MT\r\nstruct CCrcInfo\r\n{\r\n  NWindows::CThread Thread;\r\n  const Byte *Data;\r\n  UInt32 Size;\r\n  UInt32 NumCycles;\r\n  UInt32 Crc;\r\n  bool Res;\r\n  void Wait()\r\n  {\r\n    Thread.Wait();\r\n    Thread.Close();\r\n  }\r\n};\r\n\r\nstatic THREAD_FUNC_DECL CrcThreadFunction(void *param)\r\n{\r\n  CCrcInfo *p = (CCrcInfo *)param;\r\n  p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);\r\n  return 0;\r\n}\r\n\r\nstruct CCrcThreads\r\n{\r\n  UInt32 NumThreads;\r\n  CCrcInfo *Items;\r\n  CCrcThreads(): Items(0), NumThreads(0) {}\r\n  void WaitAll()\r\n  {\r\n    for (UInt32 i = 0; i < NumThreads; i++)\r\n      Items[i].Wait();\r\n    NumThreads = 0;\r\n  }\r\n  ~CCrcThreads()\r\n  {\r\n    WaitAll();\r\n    delete []Items;\r\n  }\r\n};\r\n#endif\r\n\r\nstatic UInt32 CrcCalc1(const Byte *buf, UInt32 size)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    crc = CRC_UPDATE_BYTE(crc, buf[i]);\r\n  return CRC_GET_DIGEST(crc);\r\n}\r\n\r\nstatic void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  for (UInt32 i = 0; i < size; i++)\r\n    buf[i] = (Byte)RG.GetRnd();\r\n}\r\n\r\nstatic UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  RandGen(buf, size, RG);\r\n  return CrcCalc1(buf, size);\r\n}\r\n\r\nbool CrcInternalTest()\r\n{\r\n  CBenchBuffer buffer;\r\n  const UInt32 kBufferSize0 = (1 << 8);\r\n  const UInt32 kBufferSize1 = (1 << 10);\r\n  const UInt32 kCheckSize = (1 << 5);\r\n  if (!buffer.Alloc(kBufferSize0 + kBufferSize1))\r\n    return false;\r\n  Byte *buf = buffer.Buffer;\r\n  UInt32 i;\r\n  for (i = 0; i < kBufferSize0; i++)\r\n    buf[i] = (Byte)i;\r\n  UInt32 crc1 = CrcCalc1(buf, kBufferSize0);\r\n  if (crc1 != 0x29058C73)\r\n    return false;\r\n  CBaseRandomGenerator RG;\r\n  RandGen(buf + kBufferSize0, kBufferSize1, RG);\r\n  for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)\r\n    for (UInt32 j = 0; j < kCheckSize; j++)\r\n      if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))\r\n        return false;\r\n  return true;\r\n}\r\n\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)\r\n{\r\n  if (numThreads == 0)\r\n    numThreads = 1;\r\n\r\n  CBenchBuffer buffer;\r\n  size_t totalSize = (size_t)bufferSize * numThreads;\r\n  if (totalSize / numThreads != bufferSize)\r\n    return E_OUTOFMEMORY;\r\n  if (!buffer.Alloc(totalSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  Byte *buf = buffer.Buffer;\r\n  CBaseRandomGenerator RG;\r\n  UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;\r\n\r\n  UInt64 timeVal;\r\n  #ifdef BENCH_MT\r\n  CCrcThreads threads;\r\n  if (numThreads > 1)\r\n  {\r\n    threads.Items = new CCrcInfo[numThreads];\r\n    UInt32 i;\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      Byte *data = buf + (size_t)bufferSize * i;\r\n      info.Data = data;\r\n      info.NumCycles = numCycles;\r\n      info.Size = bufferSize;\r\n      info.Crc = RandGenCrc(data, bufferSize, RG);\r\n    }\r\n    timeVal = GetTimeCount();\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      RINOK(info.Thread.Create(CrcThreadFunction, &info));\r\n      threads.NumThreads++;\r\n    }\r\n    threads.WaitAll();\r\n    for (i = 0; i < numThreads; i++)\r\n      if (!threads.Items[i].Res)\r\n        return S_FALSE;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 crc = RandGenCrc(buf, bufferSize, RG);\r\n    timeVal = GetTimeCount();\r\n    if (!CrcBig(buf, bufferSize, numCycles, crc))\r\n      return S_FALSE;\r\n  }\r\n  timeVal = GetTimeCount() - timeVal;\r\n  if (timeVal == 0)\r\n    timeVal = 1;\r\n\r\n  UInt64 size = (UInt64)numCycles * totalSize;\r\n  speed = MyMultDiv64(size, timeVal, GetFreq());\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LZMABENCH_H\r\n#define __LZMABENCH_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\n\r\nstruct CBenchInfo\r\n{\r\n  UInt64 GlobalTime;\r\n  UInt64 GlobalFreq;\r\n  UInt64 UserTime;\r\n  UInt64 UserFreq;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt32 NumIterations;\r\n  CBenchInfo(): NumIterations(0) {}\r\n};\r\n\r\nstruct IBenchCallback\r\n{\r\n  virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;\r\n  virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;\r\n};\r\n\r\nUInt64 GetUsage(const CBenchInfo &benchOnfo);\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);\r\n\r\nconst int kBenchMinDicLogSize = 18;\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);\r\n\r\nbool CrcInternalTest();\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp",
    "content": "// LzmaBenchCon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaBenchCon.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#if defined(BENCH_MT) || defined(_WIN32)\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#ifdef BREAK_HANDLER\r\n#include \"../../UI/Console/ConsoleClose.h\"\r\n#endif\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nstruct CTotalBenchRes\r\n{\r\n  UInt64 NumIterations;\r\n  UInt64 Rating;\r\n  UInt64 Usage;\r\n  UInt64 RPU;\r\n  void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }\r\n  void Normalize()\r\n  {\r\n    if (NumIterations == 0)\r\n      return;\r\n    Rating /= NumIterations;\r\n    Usage /= NumIterations;\r\n    RPU /= NumIterations;\r\n    NumIterations = 1;\r\n  }\r\n  void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)\r\n  {\r\n    Rating = (r1.Rating + r2.Rating) / 2;\r\n    Usage = (r1.Usage + r2.Usage) / 2;\r\n    RPU = (r1.RPU + r2.RPU) / 2;\r\n    NumIterations = (r1.NumIterations + r2.NumIterations) / 2;\r\n  }\r\n};\r\n\r\nstruct CBenchCallback: public IBenchCallback\r\n{\r\n  CTotalBenchRes EncodeRes;\r\n  CTotalBenchRes DecodeRes;\r\n  FILE *f;\r\n  void Init() { EncodeRes.Init(); DecodeRes.Init(); }\r\n  void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }\r\n  UInt32 dictionarySize;\r\n  HRESULT SetEncodeResult(const CBenchInfo &info, bool final);\r\n  HRESULT SetDecodeResult(const CBenchInfo &info, bool final);\r\n};\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic void PrintNumber(FILE *f, UInt64 value, int size)\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(value, s);\r\n  fprintf(f, \" \");\r\n  for (int len = (int)strlen(s); len < size; len++)\r\n    fprintf(f, \" \");\r\n  fprintf(f, \"%s\", s);\r\n}\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  PrintNumber(f, rating / 1000000, 6);\r\n}\r\n\r\nstatic void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)\r\n{\r\n  PrintNumber(f, (usage + 5000) / 10000, 5);\r\n  PrintRating(f, rpu);\r\n  PrintRating(f, rating);\r\n}\r\n\r\n\r\nstatic void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)\r\n{\r\n  UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);\r\n  PrintNumber(f, speed / 1024, 7);\r\n  UInt64 usage = GetUsage(info);\r\n  UInt64 rpu = GetRatingPerUsage(info, rating);\r\n  PrintResults(f, usage, rpu, rating);\r\n  res.NumIterations++;\r\n  res.RPU += rpu;\r\n  res.Rating += rating;\r\n  res.Usage += usage;\r\n}\r\n\r\nstatic void PrintTotals(FILE *f, const CTotalBenchRes &res)\r\n{\r\n  fprintf(f, \"       \");\r\n  PrintResults(f, res.Usage, res.RPU, res.Rating);\r\n}\r\n\r\n\r\nHRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);\r\n    PrintResults(f, info, rating, EncodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const char *kSep = \"  | \";\r\n\r\n\r\nHRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);\r\n    fprintf(f, kSep);\r\n    CBenchInfo info2 = info;\r\n    info2.UnpackSize *= info2.NumIterations;\r\n    info2.PackSize *= info2.NumIterations;\r\n    info2.NumIterations = 1;\r\n    PrintResults(f, info2, rating, DecodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)\r\n{\r\n  fprintf(f, \"\\nRAM %s \", sizeString);\r\n  PrintNumber(f, (size >> 20), 5);\r\n  fprintf(f, \" MB,  # %s %3d\", threadsString, (unsigned int)numThreads);\r\n}\r\n\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();  //\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  if (numThreads > 1)\r\n    numThreads &= ~1;\r\n  if (dictionary == (UInt32)-1)\r\n  {\r\n    int dicSizeLog;\r\n    for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)\r\n      if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)\r\n        break;\r\n    dictionary = (1 << dicSizeLog);\r\n  }\r\n  #else\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 22);\r\n  numThreads = 1;\r\n  #endif\r\n\r\n  PrintRequirements(f, \"usage:\", GetBenchMemoryUsage(numThreads, dictionary), \"Benchmark threads:   \", numThreads);\r\n\r\n  CBenchCallback callback;\r\n  callback.Init();\r\n  callback.f = f;\r\n  \r\n  fprintf(f, \"\\n\\nDict        Compressing          |        Decompressing\\n   \");\r\n  int j;\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"   Speed Usage    R/U Rating\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n   \");\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"    KB/s     %%   MIPS   MIPS\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    const int kStartDicLog = 22;\r\n    int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;\r\n    while (((UInt32)1 << pow) > dictionary)\r\n      pow--;\r\n    for (; ((UInt32)1 << pow) <= dictionary; pow++)\r\n    {\r\n      fprintf(f, \"%2d:\", pow);\r\n      callback.dictionarySize = (UInt32)1 << pow;\r\n      HRESULT res = LzmaBench(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        numThreads, callback.dictionarySize, &callback);\r\n      fprintf(f, \"\\n\");\r\n      RINOK(res);\r\n    }\r\n  }\r\n  callback.Normalize();\r\n  fprintf(f, \"----------------------------------------------------------------\\nAvr:\");\r\n  PrintTotals(f, callback.EncodeRes);\r\n  fprintf(f, \"     \");\r\n  PrintTotals(f, callback.DecodeRes);\r\n  fprintf(f, \"\\nTot:\");\r\n  CTotalBenchRes midRes;\r\n  midRes.SetMid(callback.EncodeRes, callback.DecodeRes);\r\n  PrintTotals(f, midRes);\r\n  fprintf(f, \"\\n\");\r\n  return S_OK;\r\n}\r\n\r\nstruct CTempValues\r\n{\r\n  UInt64 *Values;\r\n  CTempValues(UInt32 num) { Values = new UInt64[num]; }\r\n  ~CTempValues() { delete []Values; }\r\n};\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  #else\r\n  numThreads = 1;\r\n  #endif\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 24);\r\n\r\n  CTempValues speedTotals(numThreads);\r\n  fprintf(f, \"\\n\\nSize\");\r\n  for (UInt32 ti = 0; ti < numThreads; ti++)\r\n  {\r\n    fprintf(f, \" %5d\", ti + 1);\r\n    speedTotals.Values[ti] = 0;\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n\r\n  UInt64 numSteps = 0;\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    for (int pow = 10; pow < 32; pow++)\r\n    {\r\n      UInt32 bufSize = (UInt32)1 << pow;\r\n      if (bufSize > dictionary)\r\n        break;\r\n      fprintf(f, \"%2d: \", pow);\r\n      UInt64 speed;\r\n      for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      {\r\n        #ifdef BREAK_HANDLER\r\n        if (NConsoleClose::TestBreakSignal())\r\n          return E_ABORT;\r\n        #endif\r\n        RINOK(CrcBench(ti + 1, bufSize, speed));\r\n        PrintNumber(f, (speed >> 20), 5);\r\n        speedTotals.Values[ti] += speed;\r\n      }\r\n      fprintf(f, \"\\n\");\r\n      numSteps++;\r\n    }\r\n  }\r\n  if (numSteps != 0)\r\n  {\r\n    fprintf(f, \"\\nAvg:\");\r\n    for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);\r\n    fprintf(f, \"\\n\");\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h",
    "content": "// LzmaBenchCon.h\r\n\r\n#ifndef __LZMABENCHCON_H\r\n#define __LZMABENCHCON_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nLIBS = $(LIBS) user32.lib\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -DBENCH_MT \\\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj\r\n\r\nWIN_OBJS = \\\r\n  $O\\System.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZMAUTIL_OBJS = \\\r\n  $O\\Lzma86Dec.obj \\\r\n  $O\\Lzma86Enc.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZMAUTIL_OBJS) \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZMAUTIL_OBJS): ../../../../C/LzmaUtil/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c\r\n\r\nifdef SystemDrive\r\nIS_MINGW = 1\r\nendif\r\n\r\nifdef IS_MINGW\r\nFILE_IO =FileIO\r\nFILE_IO_2 =Windows/$(FILE_IO)\r\nLIB2 = -luuid\r\nelse\r\nFILE_IO =C_FileIO\r\nFILE_IO_2 =Common/$(FILE_IO)\r\nendif\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaBenchCon.o \\\r\n  LzmaDecoder.o \\\r\n  LzmaEncoder.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  $(FILE_IO).o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  IntToString.o \\\r\n  MyString.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  MyVector.o \\\r\n  7zCrc.o \\\r\n  Alloc.o \\\r\n  Bra86.o \\\r\n  LzFind.o \\\r\n  LzmaDec.o \\\r\n  LzmaEnc.o \\\r\n  Lzma86Dec.o \\\r\n  Lzma86Enc.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaBenchCon.o: LzmaBenchCon.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBenchCon.cpp\r\n\r\nLzmaDecoder.o: ../LzmaDecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LzmaDecoder.cpp\r\n\r\nLzmaEncoder.o: ../LzmaEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LzmaEncoder.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\n$(FILE_IO).o: ../../../$(FILE_IO_2).cpp\r\n\t$(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp\r\n\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nIntToString.o: ../../../Common/IntToString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp\r\n\r\nMyString.o: ../../../Common/MyString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyString.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nMyVector.o: ../../../Common/MyVector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyVector.cpp\r\n\r\n7zCrc.o: ../../../../C/7zCrc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c\r\n\r\nAlloc.o: ../../../../C/Alloc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c\r\n\r\nBra86.o: ../../../../C/Bra86.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Bra86.c\r\n\r\nLzFind.o: ../../../../C/LzFind.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzFind.c\r\n\r\nLzmaDec.o: ../../../../C/LzmaDec.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaDec.c\r\n\r\nLzmaEnc.o: ../../../../C/LzmaEnc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaEnc.c\r\n\r\nLzma86Dec.o: ../../../../C/LzmaUtil/Lzma86Dec.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Dec.c\r\n\r\nLzma86Enc.o: ../../../../C/LzmaUtil/Lzma86Enc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LzmaDecoder.cpp",
    "content": "// LzmaDecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"LzmaDecoder.h\"\r\n\r\nstatic HRESULT SResToHRESULT(SRes res)\r\n{\r\n  switch(res)\r\n  {\r\n    case SZ_OK: return S_OK;\r\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\r\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\r\n    case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;\r\n    // case SZ_ERROR_PROGRESS: return E_ABORT;\r\n    case SZ_ERROR_DATA: return S_FALSE;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstatic const UInt32 kInBufSize = 1 << 20;\r\n\r\nCDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false), FinishStream(false)\r\n{\r\n  LzmaDec_Construct(&_state);\r\n}\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCDecoder::~CDecoder()\r\n{\r\n  LzmaDec_Free(&_state, &g_Alloc);\r\n  MyFree(_inBuf);\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)\r\n{\r\n  RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc)));\r\n\r\n  if (_inBuf == 0)\r\n  {\r\n    _inBuf = (Byte *)MyAlloc(kInBufSize);\r\n    if (_inBuf == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) { *value = _inSizeProcessed; return S_OK; }\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; }\r\nSTDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; }\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  _outSizeDefined = (outSize != NULL);\r\n  if (_outSizeDefined)\r\n    _outSize = *outSize;\r\n\r\n  LzmaDec_Init(&_state);\r\n  \r\n  _inPos = _inSize = 0;\r\n  _inSizeProcessed = _outSizeProcessed = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)\r\n{\r\n  if (_inBuf == 0)\r\n    return S_FALSE;\r\n  SetOutStreamSize(outSize);\r\n\r\n  for (;;)\r\n  {\r\n    if (_inPos == _inSize)\r\n    {\r\n      _inPos = _inSize = 0;\r\n      RINOK(inStream->Read(_inBuf, kInBufSize, &_inSize));\r\n    }\r\n\r\n    SizeT dicPos = _state.dicPos;\r\n    SizeT curSize = _state.dicBufSize - dicPos;\r\n    const UInt32 kStepSize = ((UInt32)1 << 22);\r\n    if (curSize > kStepSize)\r\n      curSize = (SizeT)kStepSize;\r\n    \r\n    ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\r\n    if (_outSizeDefined)\r\n    {\r\n      const UInt64 rem = _outSize - _outSizeProcessed;\r\n      if (rem < curSize)\r\n      {\r\n        curSize = (SizeT)rem;\r\n        if (FinishStream)\r\n          finishMode = LZMA_FINISH_END;\r\n      }\r\n    }\r\n\r\n    SizeT inSizeProcessed = _inSize - _inPos;\r\n    ELzmaStatus status;\r\n    SRes res = LzmaDec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status);\r\n\r\n    _inPos += (UInt32)inSizeProcessed;\r\n    _inSizeProcessed += inSizeProcessed;\r\n    SizeT outSizeProcessed = _state.dicPos - dicPos;\r\n    _outSizeProcessed += outSizeProcessed;\r\n\r\n    bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0);\r\n    bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize);\r\n\r\n    if (res != 0 || _state.dicPos == _state.dicBufSize || finished || stopDecoding)\r\n    {\r\n      HRESULT res2 = WriteStream(outStream, _state.dic, _state.dicPos);\r\n      if (res != 0)\r\n        return S_FALSE;\r\n      RINOK(res2);\r\n      if (stopDecoding)\r\n        return S_OK;\r\n      if (finished)\r\n        return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE);\r\n    }\r\n    if (_state.dicPos == _state.dicBufSize)\r\n      _state.dicPos = 0;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed));\r\n    }\r\n  }\r\n}\r\n\r\n#ifndef NO_READ_FROM_CODER\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  do\r\n  {\r\n    if (_inPos == _inSize)\r\n    {\r\n      _inPos = _inSize = 0;\r\n      RINOK(_inStream->Read(_inBuf, kInBufSize, &_inSize));\r\n    }\r\n    {\r\n      SizeT inProcessed = _inSize - _inPos;\r\n\r\n      if (_outSizeDefined)\r\n      {\r\n        const UInt64 rem = _outSize - _outSizeProcessed;\r\n        if (rem < size)\r\n          size = (UInt32)rem;\r\n      }\r\n\r\n      SizeT outProcessed = size;\r\n      ELzmaStatus status;\r\n      SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,\r\n          _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);\r\n      _inPos += (UInt32)inProcessed;\r\n      _inSizeProcessed += inProcessed;\r\n      _outSizeProcessed += outProcessed;\r\n      size -= (UInt32)outProcessed;\r\n      data = (Byte *)data + outProcessed;\r\n      if (processedSize)\r\n        *processedSize += (UInt32)outProcessed;\r\n      RINOK(SResToHRESULT(res));\r\n      if (inProcessed == 0 && outProcessed == 0)\r\n        return S_OK;\r\n    }\r\n  }\r\n  while (size != 0);\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LzmaDecoder.h",
    "content": "// LzmaDecoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/LzmaDec.h\"\r\n}\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nclass CDecoder:\r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  public ICompressGetInStreamProcessedSize,\r\n  #ifndef NO_READ_FROM_CODER\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  Byte *_inBuf;\r\n  UInt32 _inPos;\r\n  UInt32 _inSize;\r\n  CLzmaDec _state;\r\n  bool _outSizeDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _inSizeProcessed;\r\n  UInt64 _outSizeProcessed;\r\npublic:\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  MY_UNKNOWN_IMP5(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize,\r\n      ICompressSetInStream,\r\n      ICompressSetOutStreamSize,\r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize)\r\n  #endif\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  bool FinishStream;\r\n\r\n  CDecoder();\r\n  virtual ~CDecoder();\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LzmaEncoder.cpp",
    "content": "// LzmaEncoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"LzmaEncoder.h\"\r\n\r\nstatic HRESULT SResToHRESULT(SRes res)\r\n{\r\n  switch(res)\r\n  {\r\n    case SZ_OK: return S_OK;\r\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\r\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\r\n    // case SZ_ERROR_THREAD: return E_FAIL;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstatic const UInt32 kStreamStepSize = (UInt32)1 << 31;\r\n\r\nstatic SRes MyRead(void *object, void *data, size_t *size)\r\n{\r\n  UInt32 curSize = ((*size < kStreamStepSize) ? (UInt32)*size : kStreamStepSize);\r\n  HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize);\r\n  *size = curSize;\r\n  return (SRes)res;\r\n}\r\n\r\nstatic size_t MyWrite(void *object, const void *data, size_t size)\r\n{\r\n  CSeqOutStream *p = (CSeqOutStream *)object;\r\n  p->Res = WriteStream(p->RealStream, data, size);\r\n  if (p->Res != 0)\r\n    return 0;\r\n  return size;\r\n}\r\n\r\nstatic void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }\r\nstatic void SzBigFree(void *, void *address) { BigFree(address); }\r\nstatic ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };\r\n\r\nstatic void *SzAlloc(void *, size_t size) { return MyAlloc(size); }\r\nstatic void SzFree(void *, void *address) { MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCEncoder::CEncoder()\r\n{\r\n  _seqInStream.SeqInStream.Read = MyRead;\r\n  _seqOutStream.SeqOutStream.Write = MyWrite;\r\n  _encoder = 0;\r\n  _encoder = LzmaEnc_Create(&g_Alloc);\r\n  if (_encoder == 0)\r\n    throw 1;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  if (_encoder != 0)\r\n    LzmaEnc_Destroy(_encoder, &g_Alloc, &g_BigAlloc);\r\n}\r\n\r\ninline wchar_t GetUpperChar(wchar_t c)\r\n{\r\n  if (c >= 'a' && c <= 'z')\r\n    c -= 0x20;\r\n  return c;\r\n}\r\n\r\nstatic int ParseMatchFinder(const wchar_t *s, int *btMode, int *numHashBytes)\r\n{\r\n  wchar_t c = GetUpperChar(*s++);\r\n  if (c == L'H')\r\n  {\r\n    if (GetUpperChar(*s++) != L'C')\r\n      return 0;\r\n    int numHashBytesLoc = (int)(*s++ - L'0');\r\n    if (numHashBytesLoc < 4 || numHashBytesLoc > 4)\r\n      return 0;\r\n    if (*s++ != 0)\r\n      return 0;\r\n    *btMode = 0;\r\n    *numHashBytes = numHashBytesLoc;\r\n    return 1;\r\n  }\r\n  if (c != L'B')\r\n    return 0;\r\n\r\n  if (GetUpperChar(*s++) != L'T')\r\n    return 0;\r\n  int numHashBytesLoc = (int)(*s++ - L'0');\r\n  if (numHashBytesLoc < 2 || numHashBytesLoc > 4)\r\n    return 0;\r\n  c = GetUpperChar(*s++);\r\n  if (c != L'\\0')\r\n    return 0;\r\n  *btMode = 1;\r\n  *numHashBytes = numHashBytesLoc;\r\n  return 1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,\r\n    const PROPVARIANT *coderProps, UInt32 numProps)\r\n{\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    const PROPVARIANT &prop = coderProps[i];\r\n    switch (propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.fb = prop.ulVal; break;\r\n      case NCoderPropID::kMatchFinderCycles:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.mc = prop.ulVal; break;\r\n      case NCoderPropID::kAlgorithm:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.algo = prop.ulVal; break;\r\n      case NCoderPropID::kDictionarySize:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.dictSize = prop.ulVal; break;\r\n      case NCoderPropID::kPosStateBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.pb = prop.ulVal; break;\r\n      case NCoderPropID::kLitPosBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lp = prop.ulVal; break;\r\n      case NCoderPropID::kLitContextBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lc = prop.ulVal; break;\r\n      case NCoderPropID::kNumThreads:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.numThreads = prop.ulVal; break;\r\n      case NCoderPropID::kMultiThread:\r\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.numThreads = ((prop.boolVal == VARIANT_TRUE) ? 2 : 1); break;\r\n      case NCoderPropID::kEndMarker:\r\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.writeEndMark = (prop.boolVal == VARIANT_TRUE); break;\r\n      case NCoderPropID::kMatchFinder:\r\n        if (prop.vt != VT_BSTR) return E_INVALIDARG;\r\n        if (!ParseMatchFinder(prop.bstrVal, &props.btMode, &props.numHashBytes /* , &_matchFinderBase.skipModeBits */))\r\n          return E_INVALIDARG; break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return SResToHRESULT(LzmaEnc_SetProps(_encoder, &props));\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  Byte props[LZMA_PROPS_SIZE];\r\n  size_t size = LZMA_PROPS_SIZE;\r\n  RINOK(LzmaEnc_WriteProperties(_encoder, props, &size));\r\n  return WriteStream(outStream, props, size);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _seqOutStream.RealStream = outStream;\r\n  _seqOutStream.Res = S_OK;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _seqOutStream.RealStream.Release();\r\n  return S_OK;\r\n}\r\n\r\ntypedef struct _CCompressProgressImp\r\n{\r\n  ICompressProgress p;\r\n  ICompressProgressInfo *Progress;\r\n  HRESULT Res;\r\n} CCompressProgressImp;\r\n\r\n#define PROGRESS_UNKNOWN_VALUE ((UInt64)(Int64)-1)\r\n\r\n#define CONVERT_PR_VAL(x) (x == PROGRESS_UNKNOWN_VALUE ? NULL : &x)\r\n\r\nSRes CompressProgress(void *pp, UInt64 inSize, UInt64 outSize)\r\n{\r\n  CCompressProgressImp *p = (CCompressProgressImp *)pp;\r\n  p->Res = p->Progress->SetRatioInfo(CONVERT_PR_VAL(inSize), CONVERT_PR_VAL(outSize));\r\n  return (SRes)p->Res;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)\r\n{\r\n  CCompressProgressImp progressImp;\r\n  progressImp.p.Progress = CompressProgress;\r\n  progressImp.Progress = progress;\r\n  progressImp.Res = SZ_OK;\r\n\r\n  _seqInStream.RealStream = inStream;\r\n  SetOutStream(outStream);\r\n  SRes res = LzmaEnc_Encode(_encoder, &_seqOutStream.SeqOutStream, &_seqInStream.SeqInStream, progress ? &progressImp.p : NULL, &g_Alloc, &g_BigAlloc);\r\n  ReleaseOutStream();\r\n  if (res == SZ_ERROR_WRITE && _seqOutStream.Res != S_OK)\r\n    return _seqOutStream.Res;\r\n  if (res == SZ_ERROR_PROGRESS && progressImp.Res != S_OK)\r\n    return progressImp.Res;\r\n  return SResToHRESULT(res);\r\n}\r\n  \r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LzmaEncoder.h",
    "content": "// LzmaEncoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/LzmaEnc.h\"\r\n}\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstruct CSeqInStream\r\n{\r\n  ISeqInStream SeqInStream;\r\n  ISequentialInStream *RealStream;\r\n};\r\n\r\nstruct CSeqOutStream\r\n{\r\n  ISeqOutStream SeqOutStream;\r\n  CMyComPtr<ISequentialOutStream> RealStream;\r\n  HRESULT Res;\r\n};\r\n\r\nclass CEncoder :\r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CMyUnknownImp\r\n{\r\n  CLzmaEncHandle _encoder;\r\n \r\n  CSeqInStream _seqInStream;\r\n  CSeqOutStream _seqOutStream;\r\n\r\npublic:\r\n  CEncoder();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/LzmaRegister.cpp",
    "content": "// LzmaRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"LzmaDecoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CDecoder); }\r\n#ifndef EXTRACT_ONLY\r\n#include \"LzmaEncoder.h\"\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CEncoder);  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x030101, L\"LZMA\", 1, false };\r\n\r\nREGISTER_CODEC(LZMA)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/RangeCoder.h",
    "content": "// Compress/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGE_CODER_H\r\n#define __COMPRESS_RANGE_CODER_H\r\n\r\n#include \"../Common/InBuffer.h\"\r\n#include \"../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1;\r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)\r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);\r\n    }\r\n    _cacheSize++;\r\n    Low = (UInt32)Low << 8;\r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numBits)\r\n  {\r\n    for (numBits--; numBits >= 0; numBits--)\r\n    {\r\n      Range >>= 1;\r\n      Low += Range & (0 - ((value >> numBits) & 1));\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;\r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8;\r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/RangeCoderBit.h",
    "content": "// Compress/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGE_CODER_BIT_H\r\n#define __COMPRESS_RANGE_CODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 4;\r\n\r\nconst int kNumBitPriceShiftBits = 4;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nextern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/Compress/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize,\r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kBlockSize,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kMatchFinderCycles,\r\n    kNumPasses = 0x460,\r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kNumThreads,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetCoderMt, 0x25)\r\n{\r\n  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block\r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICompressCodecsInfo, 0x60)\r\n{\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n};\r\nCODER_INTERFACE(ISetCompressCodecsInfo, 0x61)\r\n{\r\n  STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICryptoResetSalt, 0x88)\r\n{\r\n  STDMETHOD(ResetSalt)() PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICryptoResetInitVector, 0x8C)\r\n{\r\n  STDMETHOD(ResetInitVector)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription,\r\n    kDecoderIsAssigned,\r\n    kEncoderIsAssigned\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/IDecl.h",
    "content": "// IDecl.h\r\n\r\n#ifndef __IDECL_H\r\n#define __IDECL_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n\r\n#define DECL_INTERFACE_SUB(i, base, groupId, subId) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \\\r\nstruct i: public base\r\n\r\n#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/IPassword.h",
    "content": "// IPassword.h\r\n\r\n#ifndef __IPASSWORD_H\r\n#define __IPASSWORD_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;\r\n};\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;\r\n};\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/IProgress.h",
    "content": "// Interface/IProgress.h\r\n\r\n#ifndef __IPROGRESS_H\r\n#define __IPROGRESS_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define INTERFACE_IProgress(x) \\\r\n  STDMETHOD(SetTotal)(UInt64 total) x; \\\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) x; \\\r\n\r\nDECL_INTERFACE(IProgress, 0, 5)\r\n{\r\n  INTERFACE_IProgress(PURE)\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000000050002}\r\nDEFINE_GUID(IID_IProgress2,\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000050002\")\r\nIProgress2: public IUnknown\r\n{\r\npublic:\r\n  STDMETHOD(SetTotal)(const UInt64 *total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream,\r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/MyVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 65\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.65\"\r\n#define MY_7ZIP_VERSION \"7-Zip 4.65\"\r\n#define MY_DATE \"2009-02-03\"\r\n#define MY_COPYRIGHT \"Copyright (c) 1999-2009 Igor Pavlov\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \"  \" MY_COPYRIGHT \"  \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/MyVersionInfo.rc",
    "content": "#include <WinVer.h>\r\n#include \"MyVersion.h\"\r\n\r\n#define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0\r\n\r\n#ifdef DEBUG\r\n#define DBG_FL VS_FF_DEBUG\r\n#else\r\n#define DBG_FL 0\r\n#endif\r\n\r\n#define MY_VERSION_INFO(fileType, descr, intName, origName)  \\\r\nLANGUAGE 9, 1 \\\r\n1 VERSIONINFO \\\r\n  FILEVERSION MY_VER \\\r\n  PRODUCTVERSION MY_VER \\\r\n  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK \\\r\n  FILEFLAGS DBG_FL \\\r\n  FILEOS VOS_NT_WINDOWS32 \\\r\n  FILETYPE fileType \\\r\n  FILESUBTYPE 0x0L \\\r\nBEGIN \\\r\n    BLOCK \"StringFileInfo\" \\\r\n    BEGIN  \\\r\n        BLOCK \"040904b0\" \\\r\n        BEGIN \\\r\n            VALUE \"CompanyName\", \"Igor Pavlov\" \\\r\n            VALUE \"FileDescription\", descr \\\r\n            VALUE \"FileVersion\", MY_VERSION  \\\r\n            VALUE \"InternalName\", intName \\\r\n            VALUE \"LegalCopyright\", MY_COPYRIGHT \\\r\n            VALUE \"OriginalFilename\", origName \\\r\n            VALUE \"ProductName\", \"7-Zip\" \\\r\n            VALUE \"ProductVersion\", MY_VERSION \\\r\n        END \\\r\n    END \\\r\n    BLOCK \"VarFileInfo\" \\\r\n    BEGIN \\\r\n        VALUE \"Translation\", 0x409, 1200 \\\r\n    END \\\r\nEND\r\n\r\n#define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(VFT_APP, descr, intName, intName \".exe\")\r\n\r\n#define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(VFT_DLL, descr, intName, intName \".dll\")\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/PropID.h",
    "content": "// PropID.h\r\n\r\n#ifndef __7ZIP_PROPID_H\r\n#define __7ZIP_PROPID_H\r\n\r\nenum\r\n{\r\n  kpidNoProperty = 0,\r\n  \r\n  kpidHandlerItemIndex = 2,\r\n  kpidPath,\r\n  kpidName,\r\n  kpidExtension,\r\n  kpidIsDir,\r\n  kpidSize,\r\n  kpidPackSize,\r\n  kpidAttrib,\r\n  kpidCTime,\r\n  kpidATime,\r\n  kpidMTime,\r\n  kpidSolid,\r\n  kpidCommented,\r\n  kpidEncrypted,\r\n  kpidSplitBefore,\r\n  kpidSplitAfter,\r\n  kpidDictionarySize,\r\n  kpidCRC,\r\n  kpidType,\r\n  kpidIsAnti,\r\n  kpidMethod,\r\n  kpidHostOS,\r\n  kpidFileSystem,\r\n  kpidUser,\r\n  kpidGroup,\r\n  kpidBlock,\r\n  kpidComment,\r\n  kpidPosition,\r\n  kpidPrefix,\r\n  kpidNumSubDirs,\r\n  kpidNumSubFiles,\r\n  kpidUnpackVer,\r\n  kpidVolume,\r\n  kpidIsVolume,\r\n  kpidOffset,\r\n  kpidLinks,\r\n  kpidNumBlocks,\r\n  kpidNumVolumes,\r\n  kpidTimeType,\r\n  kpidBit64,\r\n  kpidBigEndian,\r\n  kpidCpu,\r\n  kpidPhySize,\r\n  kpidHeadersSize,\r\n  kpidChecksum,\r\n  kpidCharacts,\r\n  kpidVa,\r\n\r\n  kpidTotalSize = 0x1100,\r\n  kpidFreeSpace,\r\n  kpidClusterSize,\r\n  kpidVolumeName,\r\n\r\n  kpidLocalName = 0x1200,\r\n  kpidProvider,\r\n\r\n  kpidUserDefined = 0x10000\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Client7z/Client7z.cpp",
    "content": "// Client7z.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyInitGuid.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/DLL.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../MyVersion.h\"\r\n\r\n// use another CLSIDs, if you want to support other formats (zip, rar, ...).\r\n// {23170F69-40C1-278A-1000-000110070000}\r\nDEFINE_GUID(CLSID_CFormat7z,\r\n  0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);\r\n\r\nusing namespace NWindows;\r\n\r\n#define kDllName \"7z.dll\"\r\n\r\nstatic const char *kCopyrightString = MY_7ZIP_VERSION\r\n\" (\"  kDllName \" client) \"\r\nMY_COPYRIGHT \" \" MY_DATE;\r\n\r\nstatic const char *kHelpString =\r\n\"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\\n\"\r\n\"Examples:\\n\"\r\n\"  Client7z.exe a archive.7z f1.txt f2.txt  : compress two files to archive.7z\\n\"\r\n\"  Client7z.exe l archive.7z   : List contents of archive.7z\\n\"\r\n\"  Client7z.exe x archive.7z   : eXtract files from archive.7z\\n\";\r\n\r\n\r\ntypedef UINT32 (WINAPI * CreateObjectFunc)(\r\n    const GUID *clsID,\r\n    const GUID *interfaceID,\r\n    void **outObject);\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nvoid PrintString(const UString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)GetOemString(s));\r\n}\r\n\r\nvoid PrintString(const AString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)s);\r\n}\r\n\r\nvoid PrintNewLine()\r\n{\r\n  PrintString(\"\\n\");\r\n}\r\n\r\nvoid PrintStringLn(const AString &s)\r\n{\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nvoid PrintError(const AString &s)\r\n{\r\n  PrintNewLine();\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nstatic HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\r\n}\r\n\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Open callback class\r\n\r\n\r\nclass CArchiveOpenCallback:\r\n  public IArchiveOpenCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveOpenCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream);\r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Extracting callback class\r\n\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCRCFailed = \"CRC Failed\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nclass CArchiveExtractCallback:\r\n  public IArchiveExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IArchiveExtractCallback\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  UString _directoryPath;  // Output directory\r\n  UString _filePath;       // name inside arcvhive\r\n  UString _diskFilePath;   // full path to file on disk\r\n  bool _extractMode;\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME MTime;\r\n    UInt32 Attrib;\r\n    bool isDir;\r\n    bool AttribDefined;\r\n    bool MTimeDefined;\r\n  } _processedFileInfo;\r\n\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n\r\npublic:\r\n  void Init(IInArchive *archiveHandler, const UString &directoryPath);\r\n\r\n  UInt64 NumErrors;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveExtractCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nvoid CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)\r\n{\r\n  NumErrors = 0;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,\r\n    ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  {\r\n    // Get Name\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));\r\n    \r\n    UString fullPath;\r\n    if (prop.vt == VT_EMPTY)\r\n      fullPath = kEmptyFileAlias;\r\n    else\r\n    {\r\n      if (prop.vt != VT_BSTR)\r\n        return E_FAIL;\r\n      fullPath = prop.bstrVal;\r\n    }\r\n    _filePath = fullPath;\r\n  }\r\n\r\n  if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)\r\n    return S_OK;\r\n\r\n  {\r\n    // Get Attrib\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\r\n    if (prop.vt == VT_EMPTY)\r\n    {\r\n      _processedFileInfo.Attrib = 0;\r\n      _processedFileInfo.AttribDefined = false;\r\n    }\r\n    else\r\n    {\r\n      if (prop.vt != VT_UI4)\r\n        return E_FAIL;\r\n      _processedFileInfo.Attrib = prop.ulVal;\r\n      _processedFileInfo.AttribDefined = true;\r\n    }\r\n  }\r\n\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir));\r\n\r\n  {\r\n    // Get Modified Time\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));\r\n    _processedFileInfo.MTimeDefined = false;\r\n    switch(prop.vt)\r\n    {\r\n      case VT_EMPTY:\r\n        // _processedFileInfo.MTime = _utcMTimeDefault;\r\n        break;\r\n      case VT_FILETIME:\r\n        _processedFileInfo.MTime = prop.filetime;\r\n        _processedFileInfo.MTimeDefined = true;\r\n        break;\r\n      default:\r\n        return E_FAIL;\r\n    }\r\n\r\n  }\r\n  {\r\n    // Get Size\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    bool newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    UInt64 newFileSize;\r\n    if (newFileSizeDefined)\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n  }\r\n\r\n  \r\n  {\r\n    // Create folders for file\r\n    int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (slashPos >= 0)\r\n      NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));\r\n  }\r\n\r\n  UString fullProcessedPath = _directoryPath + _filePath;\r\n  _diskFilePath = fullProcessedPath;\r\n\r\n  if (_processedFileInfo.isDir)\r\n  {\r\n    NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (NFile::NFind::FindFile(fullProcessedPath, fi))\r\n    {\r\n      if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n      {\r\n        PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath);\r\n        return E_ABORT;\r\n      }\r\n    }\r\n    \r\n    _outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n    if (!_outFileStreamSpec->Open(fullProcessedPath, CREATE_ALWAYS))\r\n    {\r\n      PrintString((UString)L\"can not open output file \" + fullProcessedPath);\r\n      return E_ABORT;\r\n    }\r\n    _outFileStream = outStreamLoc;\r\n    *outStream = outStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:  _extractMode = true; break;\r\n  };\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:  PrintString(kExtractingString); break;\r\n    case NArchive::NExtract::NAskMode::kTest:  PrintString(kTestingString); break;\r\n    case NArchive::NExtract::NAskMode::kSkip:  PrintString(kSkippingString); break;\r\n  };\r\n  PrintString(_filePath);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumErrors++;\r\n      PrintString(\"     \");\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          PrintString(kUnsupportedMethod);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          PrintString(kCRCFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          PrintString(kDataError);\r\n          break;\r\n        default:\r\n          PrintString(kUnknownError);\r\n      }\r\n    }\r\n  }\r\n\r\n  if (_outFileStream != NULL)\r\n  {\r\n    if (_processedFileInfo.MTimeDefined)\r\n      _outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);\r\n    RINOK(_outFileStreamSpec->Close());\r\n  }\r\n  _outFileStream.Release();\r\n  if (_extractMode && _processedFileInfo.AttribDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);\r\n  PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream);\r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Creating callback class\r\n\r\nstruct CDirItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  UString FullPath;\r\n  UInt32 Attrib;\r\n\r\n  bool isDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CArchiveUpdateCallback:\r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IUpdateCallback2\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,\r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  UString DirPrefix;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n  bool m_NeedBeClosed;\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {};\r\n\r\n  ~CArchiveUpdateCallback() { Finilize(); }\r\n  HRESULT Finilize();\r\n\r\n  void Init(const CObjectVector<CDirItem> *dirItems)\r\n  {\r\n    DirItems = dirItems;\r\n    m_NeedBeClosed = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */,\r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  if (newData != NULL)\r\n    *newData = BoolToInt(true);\r\n  if (newProperties != NULL)\r\n    *newProperties = BoolToInt(true);\r\n  if (indexInArchive != NULL)\r\n    *indexInArchive = (UInt32)-1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    prop = false;\r\n    prop.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[index];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:  prop = dirItem.Name; break;\r\n      case kpidIsDir:  prop = dirItem.isDir(); break;\r\n      case kpidSize:  prop = dirItem.Size; break;\r\n      case kpidAttrib:  prop = dirItem.Attrib; break;\r\n      case kpidCTime:  prop = dirItem.CTime; break;\r\n      case kpidATime:  prop = dirItem.ATime; break;\r\n      case kpidMTime:  prop = dirItem.MTime; break;\r\n    }\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveUpdateCallback::Finilize()\r\n{\r\n  if (m_NeedBeClosed)\r\n  {\r\n    PrintNewLine();\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void GetStream2(const wchar_t *name)\r\n{\r\n  PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  PrintString(name);\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  RINOK(Finilize());\r\n\r\n  const CDirItem &dirItem = (*DirItems)[index];\r\n  GetStream2(dirItem.Name);\r\n \r\n  if (dirItem.isDir())\r\n    return S_OK;\r\n\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if (!inStreamSpec->Open(path))\r\n    {\r\n      DWORD sysError = ::GetLastError();\r\n      FailedCodes.Add(sysError);\r\n      FailedFiles.Add(path);\r\n      // if (systemError == ERROR_SHARING_VIOLATION)\r\n      {\r\n        PrintNewLine();\r\n        PrintError(\"WARNING: can't open file\");\r\n        // PrintString(NError::MyFormatMessageW(systemError));\r\n        return S_FALSE;\r\n      }\r\n      // return sysError;\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */)\r\n{\r\n  m_NeedBeClosed = true;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if (!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    if (AskPassword)\r\n    {\r\n      // You can ask real password here from user\r\n      // Password = GetPassword(OutStream);\r\n      // PasswordIsDefined = true;\r\n      PrintError(\"Password is not defined\");\r\n      return E_ABORT;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////////////////\r\n// Main function\r\n\r\nint MY_CDECL main(int argc, char* argv[])\r\n{\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  #endif\r\n\r\n  PrintStringLn(kCopyrightString);\r\n\r\n  if (argc < 3)\r\n  {\r\n    PrintStringLn(kHelpString);\r\n    return 1;\r\n  }\r\n  NWindows::NDLL::CLibrary library;\r\n  if (!library.Load(TEXT(kDllName)))\r\n  {\r\n    PrintError(\"Can not load library\");\r\n    return 1;\r\n  }\r\n  CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress(\"CreateObject\");\r\n  if (createObjectFunc == 0)\r\n  {\r\n    PrintError(\"Can not get CreateObject\");\r\n    return 1;\r\n  }\r\n\r\n  AString command = argv[1];\r\n  command.MakeLower();\r\n  UString archiveName = GetUnicodeString(argv[2], CP_OEMCP);\r\n  if (command.Compare(\"a\") == 0)\r\n  {\r\n    // create archive command\r\n    if (argc < 4)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n    CObjectVector<CDirItem> dirItems;\r\n    int i;\r\n    for (i = 3; i < argc; i++)\r\n    {\r\n      CDirItem di;\r\n      UString name = GetUnicodeString(argv[i], CP_OEMCP);\r\n      \r\n      NFile::NFind::CFileInfoW fi;\r\n      if (!NFile::NFind::FindFile(name, fi))\r\n      {\r\n        PrintString(UString(L\"Can't find file\") + name);\r\n        return 1;\r\n      }\r\n\r\n      di.Attrib = fi.Attrib;\r\n      di.Size = fi.Size;\r\n      di.CTime = fi.CTime;\r\n      di.ATime = fi.ATime;\r\n      di.MTime = fi.MTime;\r\n      di.Name = name;\r\n      di.FullPath = name;\r\n      dirItems.Add(di);\r\n    }\r\n    COutFileStream *outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;\r\n    if (!outFileStreamSpec->Create(archiveName, false))\r\n    {\r\n      PrintError(\"can't create archive file\");\r\n      return 1;\r\n    }\r\n\r\n    CMyComPtr<IOutArchive> outArchive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n\r\n    CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n    CMyComPtr<IArchiveUpdateCallback2> updateCallback(updateCallbackSpec);\r\n    updateCallbackSpec->Init(&dirItems);\r\n    // updateCallbackSpec->PasswordIsDefined = true;\r\n    // updateCallbackSpec->Password = L\"1\";\r\n\r\n    HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);\r\n    updateCallbackSpec->Finilize();\r\n    if (result != S_OK)\r\n    {\r\n      PrintError(\"Update Error\");\r\n      return 1;\r\n    }\r\n    for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)\r\n    {\r\n      PrintNewLine();\r\n      PrintString((UString)L\"Error for file: \" + updateCallbackSpec->FailedFiles[i]);\r\n    }\r\n    if (updateCallbackSpec->FailedFiles.Size() != 0)\r\n      return 1;\r\n  }\r\n  else\r\n  {\r\n    if (argc != 3)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n\r\n    bool listCommand;\r\n    if (command.Compare(\"l\") == 0)\r\n      listCommand = true;\r\n    else if (command.Compare(\"x\") == 0)\r\n      listCommand = false;\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      return 1;\r\n    }\r\n  \r\n    CMyComPtr<IInArchive> archive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n    \r\n    CInFileStream *fileSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> file = fileSpec;\r\n    \r\n    if (!fileSpec->Open(archiveName))\r\n    {\r\n      PrintError(\"Can not open archive file\");\r\n      return 1;\r\n    }\r\n\r\n    {\r\n      CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;\r\n      CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);\r\n      openCallbackSpec->PasswordIsDefined = false;\r\n      // openCallbackSpec->PasswordIsDefined = true;\r\n      // openCallbackSpec->Password = L\"1\";\r\n      \r\n      if (archive->Open(file, 0, openCallback) != S_OK)\r\n      {\r\n        PrintError(\"Can not open archive\");\r\n        return 1;\r\n      }\r\n    }\r\n    \r\n    if (listCommand)\r\n    {\r\n      // List command\r\n      UInt32 numItems = 0;\r\n      archive->GetNumberOfItems(&numItems);\r\n      for (UInt32 i = 0; i < numItems; i++)\r\n      {\r\n        {\r\n          // Get uncompressed size of file\r\n          NWindows::NCOM::CPropVariant prop;\r\n          archive->GetProperty(i, kpidSize, &prop);\r\n          UString s = ConvertPropVariantToString(prop);\r\n          PrintString(s);\r\n          PrintString(\"  \");\r\n        }\r\n        {\r\n          // Get name of file\r\n          NWindows::NCOM::CPropVariant prop;\r\n          archive->GetProperty(i, kpidPath, &prop);\r\n          UString s = ConvertPropVariantToString(prop);\r\n          PrintString(s);\r\n        }\r\n        PrintString(\"\\n\");\r\n      }\r\n    }\r\n    else\r\n    {\r\n      // Extract command\r\n      CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n      CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);\r\n      extractCallbackSpec->Init(archive, L\"\"); // second parameter is output folder path\r\n      extractCallbackSpec->PasswordIsDefined = false;\r\n      // extractCallbackSpec->PasswordIsDefined = true;\r\n      // extractCallbackSpec->Password = L\"1\";\r\n      HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);\r\n      if (result != S_OK)\r\n      {\r\n        PrintError(\"Extract Error\");\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Client7z/Client7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Client7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Client7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\" CFG=\"Client7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Client7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Client7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Client7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Client7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Client7z - Win32 Release\"\r\n# Name \"Client7z - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"stdafx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\Client7z.cpp\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Client7z/Client7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Client7z\"=.\\Client7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Client7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Client7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include <windows.h>\r\n#include <stdio.h>\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Client7z/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\Client7z.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FileStreams.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp",
    "content": "// ArchiveCommandLine.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <io.h>\r\n#endif\r\n#include <stdio.h>\r\n\r\n#include \"Common/ListFileUtils.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/FileMapping.h\"\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ArchiveCommandLine.h\"\r\n#include \"UpdateAction.h\"\r\n#include \"Update.h\"\r\n#include \"SortUtils.h\"\r\n#include \"EnumDirItems.h\"\r\n\r\nextern bool g_CaseSensitive;\r\n\r\n#if _MSC_VER >= 1400\r\n#define MY_isatty_fileno(x) _isatty(_fileno(x))\r\n#else\r\n#define MY_isatty_fileno(x) isatty(fileno(x))\r\n#endif\r\n\r\n#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);\r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kHelp3,\r\n  kDisableHeaders,\r\n  kDisablePercents,\r\n  kArchiveType,\r\n  kYes,\r\n  #ifndef _NO_CRYPTO\r\n  kPassword,\r\n  #endif\r\n  kProperty,\r\n  kOutputDir,\r\n  kWorkingDir,\r\n  kInclude,\r\n  kExclude,\r\n  kArInclude,\r\n  kArExclude,\r\n  kNoArName,\r\n  kUpdate,\r\n  kVolume,\r\n  kRecursed,\r\n  kSfx,\r\n  kStdIn,\r\n  kStdOut,\r\n  kOverwrite,\r\n  kEmail,\r\n  kShowDialog,\r\n  kLargePages,\r\n  kCharSet,\r\n  kTechMode,\r\n  kShareForWrite,\r\n  kCaseSensitive\r\n};\r\n\r\n}\r\n\r\n\r\nstatic const wchar_t kRecursedIDChar = 'R';\r\nstatic const wchar_t *kRecursedPostCharSet = L\"0-\";\r\n\r\nnamespace NRecursedPostCharIndex {\r\n  enum EEnum\r\n  {\r\n    kWildCardRecursionOnly = 0,\r\n    kNoRecursion = 1\r\n  };\r\n}\r\n\r\nstatic const char kImmediateNameID = '!';\r\nstatic const char kMapNameID = '#';\r\nstatic const char kFileListID = '@';\r\n\r\nstatic const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be\r\nstatic const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be\r\n\r\nstatic const wchar_t *kOverwritePostCharSet = L\"asut\";\r\n\r\nNExtract::NOverwriteMode::EEnum k_OverwriteModes[] =\r\n{\r\n  NExtract::NOverwriteMode::kWithoutPrompt,\r\n  NExtract::NOverwriteMode::kSkipExisting,\r\n  NExtract::NOverwriteMode::kAutoRename,\r\n  NExtract::NOverwriteMode::kAutoRenameExisting\r\n};\r\n\r\nstatic const CSwitchForm kSwitchForms[] =\r\n  {\r\n    { L\"?\",  NSwitchType::kSimple, false },\r\n    { L\"H\",  NSwitchType::kSimple, false },\r\n    { L\"-HELP\",  NSwitchType::kSimple, false },\r\n    { L\"BA\", NSwitchType::kSimple, false },\r\n    { L\"BD\", NSwitchType::kSimple, false },\r\n    { L\"T\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"Y\",  NSwitchType::kSimple, false },\r\n    #ifndef _NO_CRYPTO\r\n    { L\"P\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    #endif\r\n    { L\"M\",  NSwitchType::kUnLimitedPostString, true, 1 },\r\n    { L\"O\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"W\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"I\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"X\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AI\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AX\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AN\", NSwitchType::kSimple, false },\r\n    { L\"U\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"V\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"R\",  NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },\r\n    { L\"SFX\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SI\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SO\", NSwitchType::kSimple, false, 0 },\r\n    { L\"AO\", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},\r\n    { L\"SEML\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"AD\",  NSwitchType::kSimple, false },\r\n    { L\"SLP\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SCS\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SLT\", NSwitchType::kSimple, false },\r\n    { L\"SSW\", NSwitchType::kSimple, false },\r\n    { L\"SSC\", NSwitchType::kPostChar, false, 0, 0, L\"-\" }\r\n  };\r\n\r\nstatic const CCommandForm g_CommandForms[] =\r\n{\r\n  { L\"A\", false },\r\n  { L\"U\", false },\r\n  { L\"D\", false },\r\n  { L\"T\", false },\r\n  { L\"E\", false },\r\n  { L\"X\", false },\r\n  { L\"L\", false },\r\n  { L\"B\", false },\r\n  { L\"I\", false }\r\n};\r\n\r\nstatic const int kNumCommandForms = sizeof(g_CommandForms) /  sizeof(g_CommandForms[0]);\r\n\r\nstatic const wchar_t *kUniversalWildcard = L\"*\";\r\nstatic const int kMinNonSwitchWords = 1;\r\nstatic const int kCommandIndex = 0;\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\";\r\nstatic const char *kIncorrectListFile = \"Incorrect item in listfile.\\nCheck charset encoding and -scs switch.\";\r\nstatic const char *kIncorrectWildCardInListFile = \"Incorrect wildcard in listfile\";\r\nstatic const char *kIncorrectWildCardInCommandLine  = \"Incorrect wildcard in command line\";\r\nstatic const char *kTerminalOutError = \"I won't write compressed data to a terminal\";\r\nstatic const char *kSameTerminalError = \"I won't write data and program's messages to same terminal\";\r\n\r\nstatic void ThrowException(const char *errorMessage)\r\n{\r\n  throw CArchiveCommandLineException(errorMessage);\r\n};\r\n\r\nstatic void ThrowUserErrorException()\r\n{\r\n  ThrowException(kUserErrorMessage);\r\n};\r\n\r\n// ---------------------------\r\n\r\nbool CArchiveCommand::IsFromExtractGroup() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kExtract:\r\n    case NCommandType::kFullExtract:\r\n      return true;\r\n    default:\r\n      return false;\r\n  }\r\n}\r\n\r\nNExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kFullExtract:\r\n      return NExtract::NPathMode::kFullPathnames;\r\n    default:\r\n      return NExtract::NPathMode::kNoPathnames;\r\n  }\r\n}\r\n\r\nbool CArchiveCommand::IsFromUpdateGroup() const\r\n{\r\n  return (CommandType == NCommandType::kAdd ||\r\n    CommandType == NCommandType::kUpdate ||\r\n    CommandType == NCommandType::kDelete);\r\n}\r\n\r\nstatic NRecursedType::EEnum GetRecursedTypeFromIndex(int index)\r\n{\r\n  switch (index)\r\n  {\r\n    case NRecursedPostCharIndex::kWildCardRecursionOnly:\r\n      return NRecursedType::kWildCardOnlyRecursed;\r\n    case NRecursedPostCharIndex::kNoRecursion:\r\n      return NRecursedType::kNonRecursed;\r\n    default:\r\n      return NRecursedType::kRecursed;\r\n  }\r\n}\r\n\r\nstatic bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)\r\n{\r\n  UString commandStringUpper = commandString;\r\n  commandStringUpper.MakeUpper();\r\n  UString postString;\r\n  int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper,\r\n      postString) ;\r\n  if (commandIndex < 0)\r\n    return false;\r\n  command.CommandType = (NCommandType::EEnum)commandIndex;\r\n  return true;\r\n}\r\n\r\n// ------------------------------------------------------------------\r\n// filenames functions\r\n\r\nstatic bool AddNameToCensor(NWildcard::CCensor &wildcardCensor,\r\n    const UString &name, bool include, NRecursedType::EEnum type)\r\n{\r\n  bool isWildCard = DoesNameContainWildCard(name);\r\n  bool recursed = false;\r\n\r\n  switch (type)\r\n  {\r\n    case NRecursedType::kWildCardOnlyRecursed:\r\n      recursed = isWildCard;\r\n      break;\r\n    case NRecursedType::kRecursed:\r\n      recursed = true;\r\n      break;\r\n    case NRecursedType::kNonRecursed:\r\n      recursed = false;\r\n      break;\r\n  }\r\n  wildcardCensor.AddItem(include, name, recursed);\r\n  return true;\r\n}\r\n\r\nstatic void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,\r\n    LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)\r\n{\r\n  UStringVector names;\r\n  if (!ReadNamesFromListFile(fileName, names, codePage))\r\n    throw kIncorrectListFile;\r\n  for (int i = 0; i < names.Size(); i++)\r\n    if (!AddNameToCensor(wildcardCensor, names[i], include, type))\r\n      throw kIncorrectWildCardInListFile;\r\n}\r\n\r\nstatic void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor,\r\n    const UString &name, bool include, NRecursedType::EEnum recursedType)\r\n{\r\n  if (!AddNameToCensor(wildcardCensor, name, include, recursedType))\r\n    throw kIncorrectWildCardInCommandLine;\r\n}\r\n\r\nstatic void AddToCensorFromNonSwitchesStrings(\r\n    int startIndex,\r\n    NWildcard::CCensor &wildcardCensor,\r\n    const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,\r\n    bool thereAreSwitchIncludes, UINT codePage)\r\n{\r\n  if (nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes))\r\n    AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);\r\n  for (int i = startIndex; i < nonSwitchStrings.Size(); i++)\r\n  {\r\n    const UString &s = nonSwitchStrings[i];\r\n    if (s[0] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);\r\n    else\r\n      AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor,\r\n    const UString &switchParam, bool include,\r\n    NRecursedType::EEnum commonRecursedType)\r\n{\r\n  int splitPos = switchParam.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  UString mappingName = switchParam.Left(splitPos);\r\n  \r\n  UString switchParam2 = switchParam.Mid(splitPos + 1);\r\n  splitPos = switchParam2.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  \r\n  UString mappingSize = switchParam2.Left(splitPos);\r\n  UString eventName = switchParam2.Mid(splitPos + 1);\r\n  \r\n  UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);\r\n  UInt32 dataSize = (UInt32)dataSize64;\r\n  {\r\n    CFileMapping fileMapping;\r\n    if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName)))\r\n      ThrowException(\"Can not open mapping\");\r\n    LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize);\r\n    if (data == NULL)\r\n      ThrowException(\"MapViewOfFile error\");\r\n    try\r\n    {\r\n      const wchar_t *curData = (const wchar_t *)data;\r\n      if (*curData != 0)\r\n        ThrowException(\"Incorrect mapping data\");\r\n      UInt32 numChars = dataSize / sizeof(wchar_t);\r\n      UString name;\r\n      for (UInt32 i = 1; i < numChars; i++)\r\n      {\r\n        wchar_t c = curData[i];\r\n        if (c == L'\\0')\r\n        {\r\n          AddCommandLineWildCardToCensr(wildcardCensor,\r\n              name, include, commonRecursedType);\r\n          name.Empty();\r\n        }\r\n        else\r\n          name += c;\r\n      }\r\n      if (!name.IsEmpty())\r\n        ThrowException(\"data error\");\r\n    }\r\n    catch(...)\r\n    {\r\n      UnmapViewOfFile(data);\r\n      throw;\r\n    }\r\n    UnmapViewOfFile(data);\r\n  }\r\n  \r\n  {\r\n    NSynchronization::CManualResetEvent event;\r\n    if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)\r\n      event.Set();\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,\r\n    const UStringVector &strings, bool include,\r\n    NRecursedType::EEnum commonRecursedType, UINT codePage)\r\n{\r\n  for (int i = 0; i < strings.Size(); i++)\r\n  {\r\n    const UString &name = strings[i];\r\n    NRecursedType::EEnum recursedType;\r\n    int pos = 0;\r\n    if (name.Length() < kSomeCludePostStringMinSize)\r\n      ThrowUserErrorException();\r\n    if (::MyCharUpper(name[pos]) == kRecursedIDChar)\r\n    {\r\n      pos++;\r\n      int index = UString(kRecursedPostCharSet).Find(name[pos]);\r\n      recursedType = GetRecursedTypeFromIndex(index);\r\n      if (index >= 0)\r\n        pos++;\r\n    }\r\n    else\r\n      recursedType = commonRecursedType;\r\n    if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)\r\n      ThrowUserErrorException();\r\n    UString tail = name.Mid(pos + 1);\r\n    if (name[pos] == kImmediateNameID)\r\n      AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);\r\n    else if (name[pos] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);\r\n    #ifdef _WIN32\r\n    else if (name[pos] == kMapNameID)\r\n      ParseMapWithPaths(wildcardCensor, tail, include, recursedType);\r\n    #endif\r\n    else\r\n      ThrowUserErrorException();\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\n// This code converts all short file names to long file names.\r\n\r\nstatic void ConvertToLongName(const UString &prefix, UString &name)\r\n{\r\n  if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n    return;\r\n  NFind::CFileInfoW fileInfo;\r\n  if (NFind::FindFile(prefix + name, fileInfo))\r\n    name = fileInfo.Name;\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)\r\n{\r\n  for (int i = 0; i < items.Size(); i++)\r\n  {\r\n    NWildcard::CItem &item = items[i];\r\n    if (item.Recursive || item.PathParts.Size() != 1)\r\n      continue;\r\n    ConvertToLongName(prefix, item.PathParts.Front());\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)\r\n{\r\n  ConvertToLongNames(prefix, node.IncludeItems);\r\n  ConvertToLongNames(prefix, node.ExcludeItems);\r\n  int i;\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n    ConvertToLongName(prefix, node.SubNodes[i].Name);\r\n  // mix folders with same name\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];\r\n    for (int j = i + 1; j < node.SubNodes.Size();)\r\n    {\r\n      const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];\r\n      if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)\r\n      {\r\n        nextNode1.IncludeItems += nextNode2.IncludeItems;\r\n        nextNode1.ExcludeItems += nextNode2.ExcludeItems;\r\n        node.SubNodes.Delete(j);\r\n      }\r\n      else\r\n        j++;\r\n    }\r\n  }\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode = node.SubNodes[i];\r\n    ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode);\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(NWildcard::CCensor &censor)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    NWildcard::CPair &pair = censor.Pairs[i];\r\n    ConvertToLongNames(pair.Prefix, pair.Head);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\nstatic NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)\r\n{\r\n  switch(i)\r\n  {\r\n    case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;\r\n    case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;\r\n    case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;\r\n    case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;\r\n  }\r\n  throw 98111603;\r\n}\r\n\r\nconst UString kUpdatePairStateIDSet = L\"PQRXYZW\";\r\nconst int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};\r\n\r\nconst UString kUpdatePairActionIDSet = L\"0123\"; //Ignore, Copy, Compress, Create Anti\r\n\r\nconst wchar_t *kUpdateIgnoreItselfPostStringID = L\"-\";\r\nconst wchar_t kUpdateNewArchivePostCharID = '!';\r\n\r\n\r\nstatic bool ParseUpdateCommandString2(const UString &command,\r\n    NUpdateArchive::CActionSet &actionSet, UString &postString)\r\n{\r\n  for (int i = 0; i < command.Length();)\r\n  {\r\n    wchar_t c = MyCharUpper(command[i]);\r\n    int statePos = kUpdatePairStateIDSet.Find(c);\r\n    if (statePos < 0)\r\n    {\r\n      postString = command.Mid(i);\r\n      return true;\r\n    }\r\n    i++;\r\n    if (i >= command.Length())\r\n      return false;\r\n    int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));\r\n    if (actionPos < 0)\r\n      return false;\r\n    actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);\r\n    if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)\r\n      return false;\r\n    i++;\r\n  }\r\n  postString.Empty();\r\n  return true;\r\n}\r\n\r\nstatic void ParseUpdateCommandString(CUpdateOptions &options,\r\n    const UStringVector &updatePostStrings,\r\n    const NUpdateArchive::CActionSet &defaultActionSet)\r\n{\r\n  for (int i = 0; i < updatePostStrings.Size(); i++)\r\n  {\r\n    const UString &updateString = updatePostStrings[i];\r\n    if (updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)\r\n    {\r\n      if (options.UpdateArchiveItself)\r\n      {\r\n        options.UpdateArchiveItself = false;\r\n        options.Commands.Delete(0);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      NUpdateArchive::CActionSet actionSet = defaultActionSet;\r\n\r\n      UString postString;\r\n      if (!ParseUpdateCommandString2(updateString, actionSet, postString))\r\n        ThrowUserErrorException();\r\n      if (postString.IsEmpty())\r\n      {\r\n        if (options.UpdateArchiveItself)\r\n          options.Commands[0].ActionSet = actionSet;\r\n      }\r\n      else\r\n      {\r\n        if (MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)\r\n          ThrowUserErrorException();\r\n        CUpdateArchiveCommand uc;\r\n        UString archivePath = postString.Mid(1);\r\n        if (archivePath.IsEmpty())\r\n          ThrowUserErrorException();\r\n        uc.UserArchivePath = archivePath;\r\n        uc.ActionSet = actionSet;\r\n        options.Commands.Add(uc);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic const char kByteSymbol = 'B';\r\nstatic const char kKiloSymbol = 'K';\r\nstatic const char kMegaSymbol = 'M';\r\nstatic const char kGigaSymbol = 'G';\r\n\r\nstatic bool ParseComplexSize(const UString &src, UInt64 &result)\r\n{\r\n  UString s = src;\r\n  s.MakeUpper();\r\n\r\n  const wchar_t *start = s;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || s.Length() > numDigits + 1)\r\n    return false;\r\n  if (s.Length() == numDigits)\r\n  {\r\n    result = number;\r\n    return true;\r\n  }\r\n  int numBits;\r\n  switch (s[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      result = number;\r\n      return true;\r\n    case kKiloSymbol:\r\n      numBits = 10;\r\n      break;\r\n    case kMegaSymbol:\r\n      numBits = 20;\r\n      break;\r\n    case kGigaSymbol:\r\n      numBits = 30;\r\n      break;\r\n    default:\r\n      return false;\r\n  }\r\n  if (number >= ((UInt64)1 << (64 - numBits)))\r\n    return false;\r\n  result = number << numBits;\r\n  return true;\r\n}\r\n\r\nstatic void SetAddCommandOptions(\r\n    NCommandType::EEnum commandType,\r\n    const CParser &parser,\r\n    CUpdateOptions &options)\r\n{\r\n  NUpdateArchive::CActionSet defaultActionSet;\r\n  switch(commandType)\r\n  {\r\n    case NCommandType::kAdd:\r\n      defaultActionSet = NUpdateArchive::kAddActionSet;\r\n      break;\r\n    case NCommandType::kDelete:\r\n      defaultActionSet = NUpdateArchive::kDeleteActionSet;\r\n      break;\r\n    default:\r\n      defaultActionSet = NUpdateArchive::kUpdateActionSet;\r\n  }\r\n  \r\n  options.UpdateArchiveItself = true;\r\n  \r\n  options.Commands.Clear();\r\n  CUpdateArchiveCommand updateMainCommand;\r\n  updateMainCommand.ActionSet = defaultActionSet;\r\n  options.Commands.Add(updateMainCommand);\r\n  if (parser[NKey::kUpdate].ThereIs)\r\n    ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings,\r\n        defaultActionSet);\r\n  if (parser[NKey::kWorkingDir].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];\r\n    if (postString.IsEmpty())\r\n      NDirectory::MyGetTempPath(options.WorkingDir);\r\n    else\r\n      options.WorkingDir = postString;\r\n  }\r\n  options.SfxMode = parser[NKey::kSfx].ThereIs;\r\n  if (options.SfxMode)\r\n    options.SfxModule = parser[NKey::kSfx].PostStrings[0];\r\n\r\n  if (parser[NKey::kVolume].ThereIs)\r\n  {\r\n    const UStringVector &sv = parser[NKey::kVolume].PostStrings;\r\n    for (int i = 0; i < sv.Size(); i++)\r\n    {\r\n      UInt64 size;\r\n      if (!ParseComplexSize(sv[i], size))\r\n        ThrowException(\"Incorrect volume size\");\r\n      options.VolumesSizes.Add(size);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)\r\n{\r\n  if (parser[NKey::kProperty].ThereIs)\r\n  {\r\n    // options.MethodMode.Properties.Clear();\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      CProperty property;\r\n      const UString &postString = parser[NKey::kProperty].PostStrings[i];\r\n      int index = postString.Find(L'=');\r\n      if (index < 0)\r\n        property.Name = postString;\r\n      else\r\n      {\r\n        property.Name = postString.Left(index);\r\n        property.Value = postString.Mid(index + 1);\r\n      }\r\n      properties.Add(property);\r\n    }\r\n  }\r\n}\r\n\r\nCArchiveCommandLineParser::CArchiveCommandLineParser():\r\n  parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}\r\n\r\nvoid CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,\r\n    CArchiveCommandLineOptions &options)\r\n{\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...)\r\n  {\r\n    ThrowUserErrorException();\r\n  }\r\n\r\n  options.IsInTerminal = MY_IS_TERMINAL(stdin);\r\n  options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);\r\n  options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);\r\n  options.StdOutMode = parser[NKey::kStdOut].ThereIs;\r\n  options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;\r\n  options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs  || parser[NKey::kHelp3].ThereIs;\r\n\r\n  #ifdef _WIN32\r\n  options.LargePages = false;\r\n  if (parser[NKey::kLargePages].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kLargePages].PostStrings.Front();\r\n    if (postString.IsEmpty())\r\n      options.LargePages = true;\r\n  }\r\n  #endif\r\n}\r\n\r\nstruct CCodePagePair\r\n{\r\n  const wchar_t *Name;\r\n  UINT CodePage;\r\n};\r\n\r\nstatic CCodePagePair g_CodePagePairs[] =\r\n{\r\n  { L\"UTF-8\", CP_UTF8 },\r\n  { L\"WIN\",   CP_ACP },\r\n  { L\"DOS\",   CP_OEMCP }\r\n};\r\n\r\nstatic const int kNumCodePages = sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]);\r\n\r\nstatic bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)\r\n{\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(s, &end);\r\n  if (*end != 0)\r\n    return false;\r\n  if (number > (UInt32)0xFFFFFFFF)\r\n    return false;\r\n  v = (UInt32)number;\r\n  return true;\r\n}\r\n\r\nvoid CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)\r\n{\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n  int numNonSwitchStrings = nonSwitchStrings.Size();\r\n  if (numNonSwitchStrings < kMinNonSwitchWords)\r\n    ThrowUserErrorException();\r\n\r\n  if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))\r\n    ThrowUserErrorException();\r\n\r\n  options.TechMode = parser[NKey::kTechMode].ThereIs;\r\n\r\n  if (parser[NKey::kCaseSensitive].ThereIs)\r\n    g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);\r\n\r\n  NRecursedType::EEnum recursedType;\r\n  if (parser[NKey::kRecursed].ThereIs)\r\n    recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);\r\n  else\r\n    recursedType = NRecursedType::kNonRecursed;\r\n\r\n  UINT codePage = CP_UTF8;\r\n  if (parser[NKey::kCharSet].ThereIs)\r\n  {\r\n    UString name = parser[NKey::kCharSet].PostStrings.Front();\r\n    name.MakeUpper();\r\n    int i;\r\n    for (i = 0; i < kNumCodePages; i++)\r\n    {\r\n      const CCodePagePair &pair = g_CodePagePairs[i];\r\n      if (name.Compare(pair.Name) == 0)\r\n      {\r\n        codePage = pair.CodePage;\r\n        break;\r\n      }\r\n    }\r\n    if (i >= kNumCodePages)\r\n      ThrowUserErrorException();\r\n  }\r\n\r\n  bool thereAreSwitchIncludes = false;\r\n  if (parser[NKey::kInclude].ThereIs)\r\n  {\r\n    thereAreSwitchIncludes = true;\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\r\n        parser[NKey::kInclude].PostStrings, true, recursedType, codePage);\r\n  }\r\n  if (parser[NKey::kExclude].ThereIs)\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\r\n        parser[NKey::kExclude].PostStrings, false, recursedType, codePage);\r\n \r\n  int curCommandIndex = kCommandIndex + 1;\r\n  bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs &&\r\n      options.Command.CommandType != NCommandType::kBenchmark &&\r\n      options.Command.CommandType != NCommandType::kInfo;\r\n  if (thereIsArchiveName)\r\n  {\r\n    if (curCommandIndex >= numNonSwitchStrings)\r\n      ThrowUserErrorException();\r\n    options.ArchiveName = nonSwitchStrings[curCommandIndex++];\r\n  }\r\n\r\n  AddToCensorFromNonSwitchesStrings(\r\n      curCommandIndex, options.WildcardCensor,\r\n      nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);\r\n\r\n  options.YesToAll = parser[NKey::kYes].ThereIs;\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  #ifndef _NO_CRYPTO\r\n  options.PasswordEnabled = parser[NKey::kPassword].ThereIs;\r\n  if (options.PasswordEnabled)\r\n    options.Password = parser[NKey::kPassword].PostStrings[0];\r\n  #endif\r\n\r\n  options.StdInMode = parser[NKey::kStdIn].ThereIs;\r\n  options.ShowDialog = parser[NKey::kShowDialog].ThereIs;\r\n\r\n  if (parser[NKey::kArchiveType].ThereIs)\r\n    options.ArcType = parser[NKey::kArchiveType].PostStrings[0];\r\n\r\n  if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if (options.StdInMode)\r\n      ThrowException(\"Reading archives from stdin is not implemented\");\r\n    if (!options.WildcardCensor.AllAreRelative())\r\n      ThrowException(\"Cannot use absolute pathnames for this command\");\r\n\r\n    NWildcard::CCensor archiveWildcardCensor;\r\n\r\n    if (parser[NKey::kArInclude].ThereIs)\r\n    {\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\r\n        parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);\r\n    }\r\n    if (parser[NKey::kArExclude].ThereIs)\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\r\n      parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);\r\n\r\n    if (thereIsArchiveName)\r\n      AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(archiveWildcardCensor);\r\n    #endif\r\n\r\n    archiveWildcardCensor.ExtendExclude();\r\n\r\n    UStringVector archivePaths;\r\n\r\n    {\r\n      CDirItems dirItems;\r\n      {\r\n        UStringVector errorPaths;\r\n        CRecordVector<DWORD> errorCodes;\r\n        HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);\r\n        if (res != S_OK || errorPaths.Size() > 0)\r\n          throw \"cannot find archive\";\r\n      }\r\n      for (int i = 0; i < dirItems.Items.Size(); i++)\r\n      {\r\n        const CDirItem &dirItem = dirItems.Items[i];\r\n        if (!dirItem.IsDir())\r\n          archivePaths.Add(dirItems.GetPhyPath(i));\r\n      }\r\n    }\r\n\r\n    if (archivePaths.Size() == 0)\r\n      throw \"there is no such archive\";\r\n\r\n    UStringVector archivePathsFull;\r\n\r\n    int i;\r\n    for (i = 0; i < archivePaths.Size(); i++)\r\n    {\r\n      UString fullPath;\r\n      NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);\r\n      archivePathsFull.Add(fullPath);\r\n    }\r\n    CIntVector indices;\r\n    SortFileNames(archivePathsFull, indices);\r\n    options.ArchivePathsSorted.Reserve(indices.Size());\r\n    options.ArchivePathsFullSorted.Reserve(indices.Size());\r\n    for (i = 0; i < indices.Size(); i++)\r\n    {\r\n      options.ArchivePathsSorted.Add(archivePaths[indices[i]]);\r\n      options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);\r\n    }\r\n\r\n    if (isExtractGroupCommand)\r\n    {\r\n      SetMethodOptions(parser, options.ExtractProperties);\r\n      if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)\r\n        throw kSameTerminalError;\r\n      if (parser[NKey::kOutputDir].ThereIs)\r\n      {\r\n        options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];\r\n        NFile::NName::NormalizeDirPathPrefix(options.OutputDir);\r\n      }\r\n\r\n      options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;\r\n      if (parser[NKey::kOverwrite].ThereIs)\r\n        options.OverwriteMode =\r\n            k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];\r\n      else if (options.YesToAll)\r\n        options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n    }\r\n  }\r\n  else if (options.Command.IsFromUpdateGroup())\r\n  {\r\n    CUpdateOptions &updateOptions = options.UpdateOptions;\r\n\r\n    SetAddCommandOptions(options.Command.CommandType, parser, updateOptions);\r\n    \r\n    SetMethodOptions(parser, updateOptions.MethodMode.Properties);\r\n\r\n    if (parser[NKey::kShareForWrite].ThereIs)\r\n      updateOptions.OpenShareForWrite = true;\r\n\r\n    options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;\r\n\r\n    if (options.EnablePercents)\r\n    {\r\n      if ((options.StdOutMode && !options.IsStdErrTerminal) ||\r\n         (!options.StdOutMode && !options.IsStdOutTerminal))\r\n        options.EnablePercents = false;\r\n    }\r\n\r\n    updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;\r\n    if (updateOptions.EMailMode)\r\n    {\r\n      updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();\r\n      if (updateOptions.EMailAddress.Length() > 0)\r\n        if (updateOptions.EMailAddress[0] == L'.')\r\n        {\r\n          updateOptions.EMailRemoveAfter = true;\r\n          updateOptions.EMailAddress.Delete(0);\r\n        }\r\n    }\r\n\r\n    updateOptions.StdOutMode = options.StdOutMode;\r\n    updateOptions.StdInMode = options.StdInMode;\r\n\r\n    if (updateOptions.StdOutMode && updateOptions.EMailMode)\r\n      throw \"stdout mode and email mode cannot be combined\";\r\n    if (updateOptions.StdOutMode && options.IsStdOutTerminal)\r\n      throw kTerminalOutError;\r\n    if (updateOptions.StdInMode)\r\n      updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(options.WildcardCensor);\r\n    #endif\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    options.NumThreads = (UInt32)-1;\r\n    options.DictionarySize = (UInt32)-1;\r\n    options.NumIterations = 1;\r\n    if (curCommandIndex < numNonSwitchStrings)\r\n    {\r\n      if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))\r\n        ThrowUserErrorException();\r\n    }\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      UString postString = parser[NKey::kProperty].PostStrings[i];\r\n      postString.MakeUpper();\r\n      if (postString.Length() < 2)\r\n        ThrowUserErrorException();\r\n      if (postString[0] == 'D')\r\n      {\r\n        int pos = 1;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        UInt32 logSize;\r\n        if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))\r\n          ThrowUserErrorException();\r\n        if (logSize > 31)\r\n          ThrowUserErrorException();\r\n        options.DictionarySize = 1 << logSize;\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == 'T' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        if (postString[pos] != 0)\r\n          if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))\r\n            ThrowUserErrorException();\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == '=' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] != 0)\r\n          options.Method = postString.Mid(2);\r\n      }\r\n      else\r\n        ThrowUserErrorException();\r\n    }\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n  }\r\n  else\r\n    ThrowUserErrorException();\r\n  options.WildcardCensor.ExtendExclude();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h",
    "content": "// ArchiveCommandLine.h\r\n\r\n#ifndef __ARCHIVECOMMANDLINE_H\r\n#define __ARCHIVECOMMANDLINE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#include \"Extract.h\"\r\n#include \"Update.h\"\r\n\r\nstruct CArchiveCommandLineException: public AString\r\n{\r\n  CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {}\r\n};\r\n\r\nnamespace NCommandType { enum EEnum\r\n{\r\n  kAdd = 0,\r\n  kUpdate,\r\n  kDelete,\r\n  kTest,\r\n  kExtract,\r\n  kFullExtract,\r\n  kList,\r\n  kBenchmark,\r\n  kInfo\r\n};}\r\n\r\nnamespace NRecursedType { enum EEnum\r\n{\r\n  kRecursed,\r\n  kWildCardOnlyRecursed,\r\n  kNonRecursed\r\n};}\r\n\r\nstruct CArchiveCommand\r\n{\r\n  NCommandType::EEnum CommandType;\r\n  bool IsFromExtractGroup() const;\r\n  bool IsFromUpdateGroup() const;\r\n  bool IsTestMode() const { return CommandType == NCommandType::kTest; }\r\n  NExtract::NPathMode::EEnum GetPathMode() const;\r\n};\r\n\r\nstruct CArchiveCommandLineOptions\r\n{\r\n  bool HelpMode;\r\n\r\n  #ifdef _WIN32\r\n  bool LargePages;\r\n  #endif\r\n\r\n  bool IsInTerminal;\r\n  bool IsStdOutTerminal;\r\n  bool IsStdErrTerminal;\r\n  bool StdInMode;\r\n  bool StdOutMode;\r\n  bool EnableHeaders;\r\n\r\n  bool YesToAll;\r\n  bool ShowDialog;\r\n  // NWildcard::CCensor ArchiveWildcardCensor;\r\n  NWildcard::CCensor WildcardCensor;\r\n\r\n  CArchiveCommand Command;\r\n  UString ArchiveName;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordEnabled;\r\n  UString Password;\r\n  #endif\r\n\r\n  bool TechMode;\r\n  // Extract\r\n  bool AppendName;\r\n  UString OutputDir;\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n  UStringVector ArchivePathsSorted;\r\n  UStringVector ArchivePathsFullSorted;\r\n  CObjectVector<CProperty> ExtractProperties;\r\n\r\n  CUpdateOptions UpdateOptions;\r\n  UString ArcType;\r\n  bool EnablePercents;\r\n\r\n  // Benchmark\r\n  UInt32 NumIterations;\r\n  UInt32 NumThreads;\r\n  UInt32 DictionarySize;\r\n  UString Method;\r\n\r\n\r\n  CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};\r\n};\r\n\r\nclass CArchiveCommandLineParser\r\n{\r\n  NCommandLineParser::CParser parser;\r\npublic:\r\n  CArchiveCommandLineParser();\r\n  void Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options);\r\n  void Parse2(CArchiveCommandLineOptions &options);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp",
    "content": "// ArchiveExtractCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n#include \"OpenArchive.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic const wchar_t *kCantAutoRename = L\"ERROR: Can not create file with auto name\";\r\nstatic const wchar_t *kCantRenameFile = L\"ERROR: Can not rename existing file \";\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\n\r\nvoid CArchiveExtractCallback::Init(\r\n    IInArchive *archiveHandler,\r\n    IFolderArchiveExtractCallback *extractCallback2,\r\n    bool stdOutMode,\r\n    const UString &directoryPath,\r\n    const UStringVector &removePathParts,\r\n    const UString &itemDefaultName,\r\n    const FILETIME &utcMTimeDefault,\r\n    UInt32 attributesDefault,\r\n    UInt64 packSize)\r\n{\r\n  _stdOutMode = stdOutMode;\r\n  _numErrors = 0;\r\n  _unpTotal = 1;\r\n  _packTotal = packSize;\r\n\r\n  _extractCallback2 = extractCallback2;\r\n  _compressProgress.Release();\r\n  _extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);\r\n\r\n  LocalProgressSpec->Init(extractCallback2, true);\r\n  LocalProgressSpec->SendProgress = false;\r\n\r\n  _itemDefaultName = itemDefaultName;\r\n  _utcMTimeDefault = utcMTimeDefault;\r\n  _attributesDefault = attributesDefault;\r\n  _removePathParts = removePathParts;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  _unpTotal = size;\r\n  if (!_multiArchives && _extractCallback2)\r\n    return _extractCallback2->SetTotal(size);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  const UInt64 kMax = (UInt64)1 << 31;\r\n  while (v1 > kMax)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)\r\n{\r\n  NormalizeVals(packTotal, unpTotal);\r\n  NormalizeVals(unpCur, unpTotal);\r\n  if (unpTotal == 0)\r\n    unpTotal = 1;\r\n  return unpCur * packTotal / unpTotal;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_extractCallback2)\r\n    return S_OK;\r\n\r\n  if (_multiArchives)\r\n  {\r\n    if (completeValue != NULL)\r\n    {\r\n      UInt64 packCur = LocalProgressSpec->InSize + MyMultDiv64(*completeValue, _unpTotal, _packTotal);\r\n      return _extractCallback2->SetCompleted(&packCur);\r\n    }\r\n  }\r\n  return _extractCallback2->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return _localProgress->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\nvoid CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)\r\n{\r\n  fullPath = _directoryPath;\r\n  for(int i = 0; i < dirPathParts.Size(); i++)\r\n  {\r\n    if (i > 0)\r\n      fullPath += wchar_t(NFile::NName::kDirDelimiter);\r\n    fullPath += dirPathParts[i];\r\n    NFile::NDirectory::MyCreateDirectory(fullPath);\r\n  }\r\n}\r\n\r\nstatic UString MakePathNameFromParts(const UStringVector &parts)\r\n{\r\n  UString result;\r\n  for(int i = 0; i < parts.Size(); i++)\r\n  {\r\n    if(i != 0)\r\n      result += wchar_t(NFile::NName::kDirDelimiter);\r\n    result += parts[i];\r\n  }\r\n  return result;\r\n}\r\n\r\n\r\nHRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(_archiveHandler->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    filetime = prop.filetime;\r\n    filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  _encrypted = false;\r\n  _isSplit = false;\r\n  _curSize = 0;\r\n\r\n  UString fullPath;\r\n\r\n  RINOK(GetArchiveItemPath(_archiveHandler, index, _itemDefaultName, fullPath));\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDir));\r\n\r\n  _filePath = fullPath;\r\n\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPosition, &prop));\r\n    if (prop.vt != VT_EMPTY)\r\n    {\r\n      if (prop.vt != VT_UI8)\r\n        return E_FAIL;\r\n      _position = prop.uhVal.QuadPart;\r\n      _isSplit = true;\r\n    }\r\n  }\r\n    \r\n  RINOK(IsArchiveItemProp(_archiveHandler, index, kpidEncrypted, _encrypted));\r\n\r\n  bool newFileSizeDefined;\r\n  UInt64 newFileSize;\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    if (newFileSizeDefined)\r\n    {\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n      _curSize = newFileSize;\r\n    }\r\n  }\r\n\r\n  if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)\r\n  {\r\n    if (_stdOutMode)\r\n    {\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc = new CStdOutFileStream;\r\n      *outStream = outStreamLoc.Detach();\r\n      return S_OK;\r\n    }\r\n\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n        _processedFileInfo.Attributes = _attributesDefault;\r\n        _processedFileInfo.AttributesAreDefined = false;\r\n      }\r\n      else\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_FAIL;\r\n        _processedFileInfo.Attributes = prop.ulVal;\r\n        _processedFileInfo.AttributesAreDefined = true;\r\n      }\r\n    }\r\n\r\n    RINOK(GetTime(index, kpidCTime, _processedFileInfo.CTime, _processedFileInfo.CTimeDefined));\r\n    RINOK(GetTime(index, kpidATime, _processedFileInfo.ATime, _processedFileInfo.ATimeDefined));\r\n    RINOK(GetTime(index, kpidMTime, _processedFileInfo.MTime, _processedFileInfo.MTimeDefined));\r\n\r\n    bool isAnti = false;\r\n    RINOK(IsArchiveItemProp(_archiveHandler, index, kpidIsAnti, isAnti));\r\n\r\n    UStringVector pathParts;\r\n    SplitPathToParts(fullPath, pathParts);\r\n    \r\n    if(pathParts.IsEmpty())\r\n      return E_FAIL;\r\n    int numRemovePathParts = 0;\r\n    switch(_pathMode)\r\n    {\r\n      case NExtract::NPathMode::kFullPathnames:\r\n        break;\r\n      case NExtract::NPathMode::kCurrentPathnames:\r\n      {\r\n        numRemovePathParts = _removePathParts.Size();\r\n        if (pathParts.Size() <= numRemovePathParts)\r\n          return E_FAIL;\r\n        for (int i = 0; i < numRemovePathParts; i++)\r\n          if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0)\r\n            return E_FAIL;\r\n        break;\r\n      }\r\n      case NExtract::NPathMode::kNoPathnames:\r\n      {\r\n        numRemovePathParts = pathParts.Size() - 1;\r\n        break;\r\n      }\r\n    }\r\n    pathParts.Delete(0, numRemovePathParts);\r\n    MakeCorrectPath(pathParts);\r\n    UString processedPath = MakePathNameFromParts(pathParts);\r\n    if (!isAnti)\r\n    {\r\n      if (!_processedFileInfo.IsDir)\r\n      {\r\n        if (!pathParts.IsEmpty())\r\n          pathParts.DeleteBack();\r\n      }\r\n    \r\n      if (!pathParts.IsEmpty())\r\n      {\r\n        UString fullPathNew;\r\n        CreateComplexDirectory(pathParts, fullPathNew);\r\n        if (_processedFileInfo.IsDir)\r\n          NFile::NDirectory::SetDirTime(fullPathNew,\r\n            (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\r\n            (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\r\n            (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\r\n      }\r\n    }\r\n\r\n\r\n    UString fullProcessedPath = _directoryPath + processedPath;\r\n\r\n    if(_processedFileInfo.IsDir)\r\n    {\r\n      _diskFilePath = fullProcessedPath;\r\n      if (isAnti)\r\n        NFile::NDirectory::MyRemoveDirectory(_diskFilePath);\r\n      return S_OK;\r\n    }\r\n\r\n    if (!_isSplit)\r\n    {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      switch(_overwriteMode)\r\n      {\r\n        case NExtract::NOverwriteMode::kSkipExisting:\r\n          return S_OK;\r\n        case NExtract::NOverwriteMode::kAskBefore:\r\n        {\r\n          Int32 overwiteResult;\r\n          RINOK(_extractCallback2->AskOverwrite(\r\n              fullProcessedPath, &fileInfo.MTime, &fileInfo.Size, fullPath,\r\n              _processedFileInfo.MTimeDefined ? &_processedFileInfo.MTime : NULL,\r\n              newFileSizeDefined ? &newFileSize : NULL,\r\n              &overwiteResult))\r\n\r\n          switch(overwiteResult)\r\n          {\r\n            case NOverwriteAnswer::kCancel:\r\n              return E_ABORT;\r\n            case NOverwriteAnswer::kNo:\r\n              return S_OK;\r\n            case NOverwriteAnswer::kNoToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kSkipExisting;\r\n              return S_OK;\r\n            case NOverwriteAnswer::kYesToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n              break;\r\n            case NOverwriteAnswer::kYes:\r\n              break;\r\n            case NOverwriteAnswer::kAutoRename:\r\n              _overwriteMode = NExtract::NOverwriteMode::kAutoRename;\r\n              break;\r\n            default:\r\n              return E_FAIL;\r\n          }\r\n        }\r\n      }\r\n      if (_overwriteMode == NExtract::NOverwriteMode::kAutoRename)\r\n      {\r\n        if (!AutoRenamePath(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantAutoRename) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)\r\n      {\r\n        UString existPath = fullProcessedPath;\r\n        if (!AutoRenamePath(existPath))\r\n        {\r\n          UString message = kCantAutoRename + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n        if(!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))\r\n        {\r\n          UString message = UString(kCantRenameFile) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else\r\n        if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantDeleteOutputFile) +  fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n          // return E_FAIL;\r\n        }\r\n    }\r\n    }\r\n    if (!isAnti)\r\n    {\r\n      _outFileStreamSpec = new COutFileStream;\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n      if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))\r\n      {\r\n        // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)\r\n        {\r\n          UString message = L\"can not open output file \" + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n        }\r\n      }\r\n      if (_isSplit)\r\n      {\r\n        RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));\r\n      }\r\n      _outFileStream = outStreamLoc;\r\n      *outStream = outStreamLoc.Detach();\r\n    }\r\n    _diskFilePath = fullProcessedPath;\r\n  }\r\n  else\r\n  {\r\n    *outStream = NULL;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  return _extractCallback2->PrepareOperation(_filePath, _processedFileInfo.IsDir,\r\n      askExtractMode, _isSplit ? &_position: 0);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n    case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n    case NArchive::NExtract::NOperationResult::kCRCError:\r\n    case NArchive::NExtract::NOperationResult::kDataError:\r\n      break;\r\n    default:\r\n      _outFileStream.Release();\r\n      return E_FAIL;\r\n  }\r\n  if (_outFileStream != NULL)\r\n  {\r\n    _outFileStreamSpec->SetTime(\r\n        (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\r\n        (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\r\n        (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\r\n    _curSize = _outFileStreamSpec->ProcessedSize;\r\n    RINOK(_outFileStreamSpec->Close());\r\n    _outFileStream.Release();\r\n  }\r\n  UnpackSize += _curSize;\r\n  if (_processedFileInfo.IsDir)\r\n    NumFolders++;\r\n  else\r\n    NumFiles++;\r\n\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CArchiveExtractCallback::GetInStream(\r\n    const wchar_t *name, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  CInFileStream *inFile = new CInFileStream;\r\n  CMyComPtr<ISequentialInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(_srcDirectoryPrefix + name))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_cryptoGetTextPassword)\r\n  {\r\n    RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword,\r\n        &_cryptoGetTextPassword));\r\n  }\r\n  return _cryptoGetTextPassword->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h",
    "content": "// ArchiveExtractCallback.h\r\n\r\n#ifndef __ARCHIVEEXTRACTCALLBACK_H\r\n#define __ARCHIVEEXTRACTCALLBACK_H\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"IFileExtractCallback.h\"\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"ExtractMode.h\"\r\n\r\nclass CArchiveExtractCallback:\r\n  public IArchiveExtractCallback,\r\n  // public IArchiveVolumeExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(ICryptoGetTextPassword, ICompressProgressInfo)\r\n  // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)\r\n\r\n  INTERFACE_IArchiveExtractCallback(;)\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IArchiveVolumeExtractCallback\r\n  // STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;\r\n  CMyComPtr<ICompressProgressInfo> _compressProgress;\r\n  CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;\r\n  UString _directoryPath;\r\n  NExtract::NPathMode::EEnum _pathMode;\r\n  NExtract::NOverwriteMode::EEnum _overwriteMode;\r\n\r\n  UString _filePath;\r\n  UInt64 _position;\r\n  bool _isSplit;\r\n\r\n  UString _diskFilePath;\r\n\r\n  bool _extractMode;\r\n\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  bool _encrypted;\r\n\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME CTime;\r\n    FILETIME ATime;\r\n    FILETIME MTime;\r\n    UInt32 Attributes;\r\n  \r\n    bool CTimeDefined;\r\n    bool ATimeDefined;\r\n    bool MTimeDefined;\r\n\r\n    bool IsDir;\r\n    bool AttributesAreDefined;\r\n  } _processedFileInfo;\r\n\r\n  UInt64 _curSize;\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n  UStringVector _removePathParts;\r\n\r\n  UString _itemDefaultName;\r\n  FILETIME _utcMTimeDefault;\r\n  UInt32 _attributesDefault;\r\n  bool _stdOutMode;\r\n\r\n  void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);\r\n  HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);\r\npublic:\r\n  CArchiveExtractCallback():\r\n      WriteCTime(true),\r\n      WriteATime(true),\r\n      WriteMTime(true),\r\n      _multiArchives(false)\r\n  {\r\n    LocalProgressSpec = new CLocalProgress();\r\n    _localProgress = LocalProgressSpec;\r\n  }\r\n\r\n  CLocalProgress *LocalProgressSpec;\r\n  CMyComPtr<ICompressProgressInfo> _localProgress;\r\n  UInt64 _packTotal;\r\n  UInt64 _unpTotal;\r\n\r\n  bool _multiArchives;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  UInt64 UnpackSize;\r\n  \r\n  void InitForMulti(bool multiArchives,\r\n      NExtract::NPathMode::EEnum pathMode,\r\n      NExtract::NOverwriteMode::EEnum overwriteMode)\r\n  {\r\n    _multiArchives = multiArchives; NumFolders = NumFiles = UnpackSize = 0;\r\n    _pathMode = pathMode;\r\n    _overwriteMode = overwriteMode;\r\n  }\r\n\r\n  void Init(\r\n      IInArchive *archiveHandler,\r\n      IFolderArchiveExtractCallback *extractCallback2,\r\n      bool stdOutMode,\r\n      const UString &directoryPath,\r\n      const UStringVector &removePathParts,\r\n      const UString &itemDefaultName,\r\n      const FILETIME &utcMTimeDefault,\r\n      UInt32 attributesDefault,\r\n      UInt64 packSize);\r\n\r\n  UInt64 _numErrors;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ArchiveName.cpp",
    "content": "// ArchiveName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)\r\n{\r\n  UString resultName = L\"Archive\";\r\n  if (fromPrev)\r\n  {\r\n    UString dirPrefix;\r\n    if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))\r\n    {\r\n      if (dirPrefix.Length() > 0)\r\n        if (dirPrefix[dirPrefix.Length() - 1] == WCHAR_PATH_SEPARATOR)\r\n        {\r\n          dirPrefix.Delete(dirPrefix.Length() - 1);\r\n          NFile::NFind::CFileInfoW fileInfo;\r\n          if (NFile::NFind::FindFile(dirPrefix, fileInfo))\r\n            resultName = fileInfo.Name;\r\n        }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if (!NFile::NFind::FindFile(srcName, fileInfo))\r\n      return resultName;\r\n    resultName = fileInfo.Name;\r\n    if (!fileInfo.IsDir() && !keepName)\r\n    {\r\n      int dotPos = resultName.ReverseFind('.');\r\n      if (dotPos > 0)\r\n      {\r\n        UString archiveName2 = resultName.Left(dotPos);\r\n        if (archiveName2.ReverseFind('.') < 0)\r\n          resultName = archiveName2;\r\n      }\r\n    }\r\n  }\r\n  return resultName;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ArchiveName.h",
    "content": "// ArchiveName.h\r\n\r\n#ifndef __ARCHIVENAME_H\r\n#define __ARCHIVENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp",
    "content": "// ArchiveOpenCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n    return ReOpenCallback->SetTotal(files, bytes);\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->Open_SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n    return ReOpenCallback->SetCompleted(files, bytes);\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->Open_SetCompleted(files, bytes);\r\n  COM_TRY_END\r\n}\r\n  \r\nSTDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  if (_subArchiveMode)\r\n    switch(propID)\r\n    {\r\n      case kpidName: prop = _subArchiveName; break;\r\n    }\r\n  else\r\n    switch(propID)\r\n    {\r\n      case kpidName:  prop = _fileInfo.Name; break;\r\n      case kpidIsDir:  prop = _fileInfo.IsDir(); break;\r\n      case kpidSize:  prop = _fileInfo.Size; break;\r\n      case kpidAttrib:  prop = (UInt32)_fileInfo.Attrib; break;\r\n      case kpidCTime:  prop = _fileInfo.CTime; break;\r\n      case kpidATime:  prop = _fileInfo.ATime; break;\r\n      case kpidMTime:  prop = _fileInfo.MTime; break;\r\n    }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nint COpenCallbackImp::FindName(const UString &name)\r\n{\r\n  for (int i = 0; i < FileNames.Size(); i++)\r\n    if (name.CompareNoCase(FileNames[i]) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstruct CInFileStreamVol: public CInFileStream\r\n{\r\n  UString Name;\r\n  COpenCallbackImp *OpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;\r\n  ~CInFileStreamVol()\r\n  {\r\n    int index = OpenCallbackImp->FindName(Name);\r\n    if (index >= 0)\r\n      OpenCallbackImp->FileNames.Delete(index);\r\n  }\r\n};\r\n\r\nSTDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (_subArchiveMode)\r\n    return S_FALSE;\r\n  if (Callback)\r\n  {\r\n    RINOK(Callback->Open_CheckBreak());\r\n  }\r\n  *inStream = NULL;\r\n  UString fullPath = _folderPrefix + name;\r\n  if (!NFile::NFind::FindFile(fullPath, _fileInfo))\r\n    return S_FALSE;\r\n  if (_fileInfo.IsDir())\r\n    return S_FALSE;\r\n  CInFileStreamVol *inFile = new CInFileStreamVol;\r\n  CMyComPtr<IInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(fullPath))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  inFile->Name = name;\r\n  inFile->OpenCallbackImp = this;\r\n  inFile->OpenCallbackRef = this;\r\n  FileNames.Add(name);\r\n  TotalSize += _fileInfo.Size;\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n  {\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    ReOpenCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    if (getTextPassword)\r\n      return getTextPassword->CryptoGetTextPassword(password);\r\n  }\r\n  if (!Callback)\r\n    return E_NOTIMPL;\r\n  return Callback->Open_CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n#endif\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h",
    "content": "// ArchiveOpenCallback.h\r\n\r\n#ifndef __ARCHIVE_OPEN_CALLBACK_H\r\n#define __ARCHIVE_OPEN_CALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#ifndef _NO_CRYPTO\r\n#include \"../../IPassword.h\"\r\n#endif\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#ifdef _NO_CRYPTO\r\n\r\n#define INTERFACE_IOpenCallbackUI_Crypto(x)\r\n\r\n#else\r\n\r\n#define INTERFACE_IOpenCallbackUI_Crypto(x) \\\r\n  virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x; \\\r\n  virtual HRESULT Open_GetPasswordIfAny(UString &password) x; \\\r\n  virtual bool Open_WasPasswordAsked() x; \\\r\n  virtual void Open_ClearPasswordWasAskedFlag() x; \\\r\n  \r\n#endif\r\n\r\n#define INTERFACE_IOpenCallbackUI(x) \\\r\n  virtual HRESULT Open_CheckBreak() x; \\\r\n  virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  INTERFACE_IOpenCallbackUI_Crypto(x)\r\n\r\nstruct IOpenCallbackUI\r\n{\r\n  INTERFACE_IOpenCallbackUI(=0)\r\n};\r\n\r\nclass COpenCallbackImp:\r\n  public IArchiveOpenCallback,\r\n  public IArchiveOpenVolumeCallback,\r\n  public IArchiveOpenSetSubArchiveName,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifndef _NO_CRYPTO\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveOpenVolumeCallback,\r\n      ICryptoGetTextPassword,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      IArchiveOpenVolumeCallback,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #endif\r\n\r\n  INTERFACE_IArchiveOpenCallback(;)\r\n  INTERFACE_IArchiveOpenVolumeCallback(;)\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n  #endif\r\n\r\n  STDMETHOD(SetSubArchiveName(const wchar_t *name))\r\n  {\r\n    _subArchiveMode = true;\r\n    _subArchiveName = name;\r\n    return  S_OK;\r\n  }\r\n\r\nprivate:\r\n  UString _folderPrefix;\r\n  NWindows::NFile::NFind::CFileInfoW _fileInfo;\r\n  bool _subArchiveMode;\r\n  UString _subArchiveName;\r\npublic:\r\n  UStringVector FileNames;\r\n  IOpenCallbackUI *Callback;\r\n  CMyComPtr<IArchiveOpenCallback> ReOpenCallback;\r\n  UInt64 TotalSize;\r\n\r\n  COpenCallbackImp(): Callback(NULL) {}\r\n  void Init(const UString &folderPrefix,  const UString &fileName)\r\n  {\r\n    _folderPrefix = folderPrefix;\r\n    if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))\r\n      throw 1;\r\n    FileNames.Clear();\r\n    _subArchiveMode = false;\r\n    TotalSize = 0;\r\n  }\r\n  int FindName(const UString &name);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/DefaultName.cpp",
    "content": "// DefaultName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nstatic UString GetDefaultName3(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  int extLength = extension.Length();\r\n  int fileNameLength = fileName.Length();\r\n  if (fileNameLength > extLength + 1)\r\n  {\r\n    int dotPos = fileNameLength - (extLength + 1);\r\n    if (fileName[dotPos] == '.')\r\n      if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)\r\n        return fileName.Left(dotPos) + addSubExtension;\r\n  }\r\n  int dotPos = fileName.ReverseFind(L'.');\r\n  if (dotPos > 0)\r\n    return fileName.Left(dotPos) + addSubExtension;\r\n\r\n  if (addSubExtension.IsEmpty())\r\n    return fileName + L\"~\";\r\n  else\r\n    return fileName + addSubExtension;\r\n}\r\n\r\nUString GetDefaultName2(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  UString name = GetDefaultName3(fileName, extension, addSubExtension);\r\n  name.TrimRight();\r\n  return name;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/DefaultName.h",
    "content": "// DefaultName.h\r\n\r\n#ifndef __DEFAULTNAME_H\r\n#define __DEFAULTNAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString GetDefaultName2(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/DirItem.h",
    "content": "// DirItem.h\r\n\r\n#ifndef __DIR_ITEM_H\r\n#define __DIR_ITEM_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CDirItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  UInt32 Attrib;\r\n  int PhyParent;\r\n  int LogParent;\r\n  \r\n  CDirItem(): PhyParent(-1), LogParent(-1) {}\r\n  bool IsDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CDirItems\r\n{\r\n  UStringVector Prefixes;\r\n  CIntVector PhyParents;\r\n  CIntVector LogParents;\r\n\r\n  UString GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const;\r\npublic:\r\n  CObjectVector<CDirItem> Items;\r\n\r\n  int GetNumFolders() const { return Prefixes.Size(); }\r\n  UString GetPhyPath(int index) const;\r\n  UString GetLogPath(int index) const;\r\n\r\n  int AddPrefix(int phyParent, int logParent, const UString &prefix);\r\n  void DeleteLastPrefix();\r\n\r\n  void EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\r\n\r\n  void EnumerateDirItems2(\r\n    const UString &phyPrefix,\r\n    const UString &logPrefix,\r\n    const UStringVector &filePaths,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\r\n\r\n  void ReserveDown();\r\n};\r\n\r\nstruct CArcItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  bool IsDir;\r\n  bool SizeDefined;\r\n  bool Censored;\r\n  UInt32 IndexInServer;\r\n  int TimeType;\r\n  \r\n  CArcItem(): IsDir(false), SizeDefined(false), Censored(false), TimeType(-1) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp",
    "content": "// EnumDirItems.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nvoid AddDirFileInfo(int phyParent, int logParent,\r\n    const NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems)\r\n{\r\n  CDirItem di;\r\n  di.Size = fi.Size;\r\n  di.CTime = fi.CTime;\r\n  di.ATime = fi.ATime;\r\n  di.MTime = fi.MTime;\r\n  di.Attrib = fi.Attrib;\r\n  di.PhyParent = phyParent;\r\n  di.LogParent = logParent;\r\n  di.Name = fi.Name;\r\n  dirItems.Add(di);\r\n}\r\n\r\nUString CDirItems::GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const\r\n{\r\n  UString path;\r\n  int len = name.Length();\r\n  int i;\r\n  for (i = index; i >= 0; i = parents[i])\r\n    len += Prefixes[i].Length();\r\n  int totalLen = len;\r\n  wchar_t *p = path.GetBuffer(len);\r\n  p[len] = 0;\r\n  len -= name.Length();\r\n  memcpy(p + len, (const wchar_t *)name, name.Length() * sizeof(wchar_t));\r\n  for (i = index; i >= 0; i = parents[i])\r\n  {\r\n    const UString &s = Prefixes[i];\r\n    len -= s.Length();\r\n    memcpy(p + len, (const wchar_t *)s, s.Length() * sizeof(wchar_t));\r\n  }\r\n  path.ReleaseBuffer(totalLen);\r\n  return path;\r\n}\r\n\r\nUString CDirItems::GetPhyPath(int index) const\r\n{\r\n  const CDirItem &di = Items[index];\r\n  return GetPrefixesPath(PhyParents, di.PhyParent, di.Name);\r\n}\r\n\r\nUString CDirItems::GetLogPath(int index) const\r\n{\r\n  const CDirItem &di = Items[index];\r\n  return GetPrefixesPath(LogParents, di.LogParent, di.Name);\r\n}\r\n\r\nvoid CDirItems::ReserveDown()\r\n{\r\n  Prefixes.ReserveDown();\r\n  PhyParents.ReserveDown();\r\n  LogParents.ReserveDown();\r\n  Items.ReserveDown();\r\n}\r\n\r\nint CDirItems::AddPrefix(int phyParent, int logParent, const UString &prefix)\r\n{\r\n  PhyParents.Add(phyParent);\r\n  LogParents.Add(logParent);\r\n  return Prefixes.Add(prefix);\r\n}\r\n\r\nvoid CDirItems::DeleteLastPrefix()\r\n{\r\n  PhyParents.DeleteBack();\r\n  LogParents.DeleteBack();\r\n  Prefixes.DeleteBack();\r\n}\r\n\r\nvoid CDirItems::EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\r\n{\r\n  NFind::CEnumeratorW enumerator(phyPrefix + (wchar_t)kAnyStringWildcard);\r\n  for (;;)\r\n  {\r\n    NFind::CFileInfoW fi;\r\n    bool found;\r\n    if (!enumerator.Next(fi, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPrefix);\r\n      return;\r\n    }\r\n    if (!found)\r\n      break;\r\n    AddDirFileInfo(phyParent, logParent, fi, Items);\r\n    if (fi.IsDir())\r\n    {\r\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\r\n      int parent = AddPrefix(phyParent, logParent, name2);\r\n      EnumerateDirectory(parent, parent, phyPrefix + name2, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CDirItems::EnumerateDirItems2(const UString &phyPrefix, const UString &logPrefix,\r\n    const UStringVector &filePaths, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\r\n{\r\n  int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, phyPrefix);\r\n  int logParent = logPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, logPrefix);\r\n\r\n  for (int i = 0; i < filePaths.Size(); i++)\r\n  {\r\n    const UString &filePath = filePaths[i];\r\n    NFind::CFileInfoW fi;\r\n    const UString phyPath = phyPrefix + filePath;\r\n    if (!NFind::FindFile(phyPath, fi))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPath);\r\n      continue;\r\n    }\r\n    int delimiter = filePath.ReverseFind((wchar_t)kDirDelimiter);\r\n    UString phyPrefixCur;\r\n    int phyParentCur = phyParent;\r\n    if (delimiter >= 0)\r\n    {\r\n      phyPrefixCur = filePath.Left(delimiter + 1);\r\n      phyParentCur = AddPrefix(phyParent, logParent, phyPrefixCur);\r\n    }\r\n    AddDirFileInfo(phyParentCur, logParent, fi, Items);\r\n    if (fi.IsDir())\r\n    {\r\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\r\n      int parent = AddPrefix(phyParentCur, logParent, name2);\r\n      EnumerateDirectory(parent, parent, phyPrefix + phyPrefixCur + name2, errorPaths, errorCodes);\r\n    }\r\n  }\r\n  ReserveDown();\r\n}\r\n\r\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\nstatic HRESULT EnumerateDirItems_Spec(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &curFolderName,\r\n    const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n  \r\n{\r\n  const UString name2 = curFolderName + (wchar_t)kDirDelimiter;\r\n  int parent = dirItems.AddPrefix(phyParent, logParent, name2);\r\n  int numItems = dirItems.Items.Size();\r\n  HRESULT res = EnumerateDirItems(curNode, parent, parent, phyPrefix + name2,\r\n    addArchivePrefix, dirItems, enterToSubFolders, callback, errorPaths, errorCodes);\r\n  if (numItems == dirItems.Items.Size())\r\n    dirItems.DeleteLastPrefix();\r\n  return res;\r\n}\r\n\r\n\r\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,  // prefix from curNode\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  if (!enterToSubFolders)\r\n    if (curNode.NeedCheckSubDirs())\r\n      enterToSubFolders = true;\r\n  if (callback)\r\n    RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\r\n\r\n  // try direct_names case at first\r\n  if (addArchivePrefix.IsEmpty() && !enterToSubFolders)\r\n  {\r\n    // check that all names are direct\r\n    int i;\r\n    for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n    {\r\n      const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n      if (item.Recursive || item.PathParts.Size() != 1)\r\n        break;\r\n      const UString &name = item.PathParts.Front();\r\n      if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n        break;\r\n    }\r\n    if (i == curNode.IncludeItems.Size())\r\n    {\r\n      // all names are direct (no wildcards)\r\n      // so we don't need file_system's dir enumerator\r\n      CRecordVector<bool> needEnterVector;\r\n      for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n      {\r\n        const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n        const UString &name = item.PathParts.Front();\r\n        const UString fullPath = phyPrefix + name;\r\n        NFind::CFileInfoW fi;\r\n        if (!NFind::FindFile(fullPath, fi))\r\n        {\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        bool isDir = fi.IsDir();\r\n        if (isDir && !item.ForDir || !isDir && !item.ForFile)\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        {\r\n          UStringVector pathParts;\r\n          pathParts.Add(fi.Name);\r\n          if (curNode.CheckPathToRoot(false, pathParts, !isDir))\r\n            continue;\r\n        }\r\n        AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\r\n        if (!isDir)\r\n          continue;\r\n        \r\n        UStringVector addArchivePrefixNew;\r\n        const NWildcard::CCensorNode *nextNode = 0;\r\n        int index = curNode.FindSubNode(name);\r\n        if (index >= 0)\r\n        {\r\n          for (int t = needEnterVector.Size(); t <= index; t++)\r\n            needEnterVector.Add(true);\r\n          needEnterVector[index] = false;\r\n          nextNode = &curNode.SubNodes[index];\r\n        }\r\n        else\r\n        {\r\n          nextNode = &curNode;\r\n          addArchivePrefixNew.Add(name); // don't change it to fi.Name. It's for shortnames support\r\n        }\r\n\r\n        RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix,\r\n            addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes));\r\n      }\r\n      for (i = 0; i < curNode.SubNodes.Size(); i++)\r\n      {\r\n        if (i < needEnterVector.Size())\r\n          if (!needEnterVector[i])\r\n            continue;\r\n        const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];\r\n        const UString fullPath = phyPrefix + nextNode.Name;\r\n        NFind::CFileInfoW fi;\r\n        if (!NFind::FindFile(fullPath, fi))\r\n        {\r\n          if (!nextNode.AreThereIncludeItems())\r\n            continue;\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        if (!fi.IsDir())\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n\r\n        RINOK(EnumerateDirItems_Spec(nextNode, phyParent, logParent, fi.Name, phyPrefix,\r\n            UStringVector(), dirItems, false, callback, errorPaths, errorCodes));\r\n      }\r\n      return S_OK;\r\n    }\r\n  }\r\n\r\n\r\n  NFind::CEnumeratorW enumerator(phyPrefix + wchar_t(kAnyStringWildcard));\r\n  for (int ttt = 0; ; ttt++)\r\n  {\r\n    NFind::CFileInfoW fi;\r\n    bool found;\r\n    if (!enumerator.Next(fi, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPrefix);\r\n      break;\r\n    }\r\n    if (!found)\r\n      break;\r\n\r\n    if (callback && (ttt & 0xFF) == 0xFF)\r\n      RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\r\n    const UString &name = fi.Name;\r\n    bool enterToSubFolders2 = enterToSubFolders;\r\n    UStringVector addArchivePrefixNew = addArchivePrefix;\r\n    addArchivePrefixNew.Add(name);\r\n    {\r\n      UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);\r\n      if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fi.IsDir()))\r\n        continue;\r\n    }\r\n    if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir()))\r\n    {\r\n      AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\r\n      if (fi.IsDir())\r\n        enterToSubFolders2 = true;\r\n    }\r\n    if (!fi.IsDir())\r\n      continue;\r\n\r\n    const NWildcard::CCensorNode *nextNode = 0;\r\n    if (addArchivePrefix.IsEmpty())\r\n    {\r\n      int index = curNode.FindSubNode(name);\r\n      if (index >= 0)\r\n        nextNode = &curNode.SubNodes[index];\r\n    }\r\n    if (!enterToSubFolders2 && nextNode == 0)\r\n      continue;\r\n\r\n    addArchivePrefixNew = addArchivePrefix;\r\n    if (nextNode == 0)\r\n    {\r\n      nextNode = &curNode;\r\n      addArchivePrefixNew.Add(name);\r\n    }\r\n\r\n    RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, name, phyPrefix,\r\n        addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor,\r\n    CDirItems &dirItems,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    const NWildcard::CPair &pair = censor.Pairs[i];\r\n    int phyParent = pair.Prefix.IsEmpty() ? -1 : dirItems.AddPrefix(-1, -1, pair.Prefix);\r\n    RINOK(EnumerateDirItems(pair.Head, phyParent, -1, pair.Prefix, UStringVector(), dirItems, false,\r\n        callback, errorPaths, errorCodes));\r\n  }\r\n  dirItems.ReserveDown();\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/EnumDirItems.h",
    "content": "// EnumDirItems.h\r\n\r\n#ifndef __ENUM_DIR_ITEMS_H\r\n#define __ENUM_DIR_ITEMS_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"DirItem.h\"\r\n\r\nvoid AddDirFileInfo(int phyParent, int logParent,\r\n    const NWindows::NFile::NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems);\r\n\r\nstruct IEnumDirItemCallback\r\n{\r\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) = 0;\r\n};\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor,\r\n    CDirItems &dirItems,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ExitCode.h",
    "content": "// ExitCode.h\r\n\r\n#ifndef __EXIT_CODE_H\r\n#define __EXIT_CODE_H\r\n\r\nnamespace NExitCode {\r\n\r\nenum EEnum {\r\n\r\n  kSuccess       = 0,     // Successful operation\r\n  kWarning       = 1,     // Non fatal error(s) occurred\r\n  kFatalError    = 2,     // A fatal error occurred\r\n  // kCRCError      = 3,     // A CRC error occurred when unpacking\r\n  // kLockedArchive = 4,     // Attempt to modify an archive previously locked\r\n  // kWriteError    = 5,     // Write to disk error\r\n  // kOpenError     = 6,     // Open file error\r\n  kUserError     = 7,     // Command line option error\r\n  kMemoryError   = 8,     // Not enough memory for operation\r\n  // kCreateFileError = 9,     // Create file error\r\n  \r\n  kUserBreak     = 255   // User stopped the process\r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/Extract.cpp",
    "content": "// Extract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Extract.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n#include \"SetProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic HRESULT DecompressArchive(\r\n    IInArchive *archive,\r\n    UInt64 packSize,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IExtractCallbackUI *callback,\r\n    CArchiveExtractCallback *extractCallbackSpec,\r\n    UString &errorMessage)\r\n{\r\n  CRecordVector<UInt32> realIndices;\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UString filePath;\r\n    RINOK(GetArchiveItemPath(archive, i, options.DefaultItemName, filePath));\r\n    bool isFolder;\r\n    RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n    if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n      continue;\r\n    realIndices.Add(i);\r\n  }\r\n  if (realIndices.Size() == 0)\r\n  {\r\n    callback->ThereAreNoFiles();\r\n    return S_OK;\r\n  }\r\n\r\n  UStringVector removePathParts;\r\n\r\n  UString outDir = options.OutputDir;\r\n  outDir.Replace(L\"*\", options.DefaultItemName);\r\n  #ifdef _WIN32\r\n  outDir.TrimRight();\r\n  #endif\r\n\r\n  if(!outDir.IsEmpty())\r\n    if(!NFile::NDirectory::CreateComplexDirectory(outDir))\r\n    {\r\n      HRESULT res = ::GetLastError();\r\n      if (res == S_OK)\r\n        res = E_FAIL;\r\n      errorMessage = ((UString)L\"Can not create output directory \") + outDir;\r\n      return res;\r\n    }\r\n\r\n  extractCallbackSpec->Init(\r\n      archive,\r\n      callback,\r\n      options.StdOutMode,\r\n      outDir,\r\n      removePathParts,\r\n      options.DefaultItemName,\r\n      options.ArchiveFileInfo.MTime,\r\n      options.ArchiveFileInfo.Attrib,\r\n      packSize);\r\n\r\n  #ifdef COMPRESS_MT\r\n  RINOK(SetProperties(archive, options.Properties));\r\n  #endif\r\n\r\n  HRESULT result = archive->Extract(&realIndices.Front(),\r\n    realIndices.Size(), options.TestMode? 1: 0, extractCallbackSpec);\r\n\r\n  return callback->ExtractResult(result);\r\n}\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &optionsSpec,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage,\r\n    CDecompressStat &stat)\r\n{\r\n  stat.Clear();\r\n  CExtractOptions options = optionsSpec;\r\n  int i;\r\n  UInt64 totalPackSize = 0;\r\n  CRecordVector<UInt64> archiveSizes;\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archivePath, fi))\r\n      throw \"there is no such archive\";\r\n    if (fi.IsDir())\r\n      throw \"can't decompress folder\";\r\n    archiveSizes.Add(fi.Size);\r\n    totalPackSize += fi.Size;\r\n  }\r\n  CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n  CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);\r\n  bool multi = (archivePaths.Size() > 1);\r\n  extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);\r\n  if (multi)\r\n  {\r\n    RINOK(extractCallback->SetTotal(totalPackSize));\r\n  }\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archivePath, fi))\r\n      throw \"there is no such archive\";\r\n\r\n    if (fi.IsDir())\r\n      throw \"there is no such archive\";\r\n\r\n    options.ArchiveFileInfo = fi;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    openCallback->Open_ClearPasswordWasAskedFlag();\r\n    #endif\r\n\r\n    RINOK(extractCallback->BeforeOpen(archivePath));\r\n    CArchiveLink archiveLink;\r\n\r\n    CIntVector formatIndices2 = formatIndices;\r\n    #ifndef _SFX\r\n    if (formatIndices.IsEmpty())\r\n    {\r\n      int pos = archivePath.ReverseFind(L'.');\r\n      if (pos >= 0)\r\n      {\r\n        UString s = archivePath.Mid(pos + 1);\r\n        int index = codecs->FindFormatForExtension(s);\r\n        if (index >= 0 && s == L\"001\")\r\n        {\r\n          s = archivePath.Left(pos);\r\n          pos = s.ReverseFind(L'.');\r\n          if (pos >= 0)\r\n          {\r\n            int index2 = codecs->FindFormatForExtension(s.Mid(pos + 1));\r\n            if (index2 >= 0 && s.CompareNoCase(L\"rar\") != 0)\r\n            {\r\n              formatIndices2.Add(index2);\r\n              formatIndices2.Add(index);\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n    #endif\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices2, archivePath, archiveLink, openCallback);\r\n    if (result == E_ABORT)\r\n      return result;\r\n\r\n    bool crypted = false;\r\n    #ifndef _NO_CRYPTO\r\n    crypted = openCallback->Open_WasPasswordAsked();\r\n    #endif\r\n\r\n    RINOK(extractCallback->OpenResult(archivePath, result, crypted));\r\n    if (result != S_OK)\r\n      continue;\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n        totalPackSize -= archiveSizes[index];\r\n        archiveSizes.Delete(index);\r\n      }\r\n    }\r\n    if (archiveLink.VolumePaths.Size() != 0)\r\n    {\r\n      totalPackSize += archiveLink.VolumesSize;\r\n      RINOK(extractCallback->SetTotal(totalPackSize));\r\n    }\r\n\r\n    #ifndef _NO_CRYPTO\r\n    UString password;\r\n    RINOK(openCallback->Open_GetPasswordIfAny(password));\r\n    if (!password.IsEmpty())\r\n    {\r\n      RINOK(extractCallback->SetPassword(password));\r\n    }\r\n    #endif\r\n\r\n    options.DefaultItemName = archiveLink.GetDefaultItemName();\r\n    RINOK(DecompressArchive(\r\n        archiveLink.GetArchive(),\r\n        fi.Size + archiveLink.VolumesSize,\r\n        wildcardCensor, options, extractCallback, extractCallbackSpec, errorMessage));\r\n    extractCallbackSpec->LocalProgressSpec->InSize += fi.Size +\r\n        archiveLink.VolumesSize;\r\n    extractCallbackSpec->LocalProgressSpec->OutSize = extractCallbackSpec->UnpackSize;\r\n    if (!errorMessage.IsEmpty())\r\n      return E_FAIL;\r\n  }\r\n  stat.NumFolders = extractCallbackSpec->NumFolders;\r\n  stat.NumFiles = extractCallbackSpec->NumFiles;\r\n  stat.UnpackSize = extractCallbackSpec->UnpackSize;\r\n  stat.NumArchives = archivePaths.Size();\r\n  stat.PackSize = extractCallbackSpec->LocalProgressSpec->InSize;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/Extract.h",
    "content": "// Extract.h\r\n\r\n#ifndef __EXTRACT_H\r\n#define __EXTRACT_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"ExtractMode.h\"\r\n#include \"Property.h\"\r\n\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nclass CExtractOptions\r\n{\r\npublic:\r\n  bool StdOutMode;\r\n  bool TestMode;\r\n  NExtract::NPathMode::EEnum PathMode;\r\n\r\n  UString OutputDir;\r\n  bool YesToAll;\r\n  UString DefaultItemName;\r\n  NWindows::NFile::NFind::CFileInfoW ArchiveFileInfo;\r\n  \r\n  // bool ShowDialog;\r\n  // bool PasswordEnabled;\r\n  // UString Password;\r\n  #ifdef COMPRESS_MT\r\n  CObjectVector<CProperty> Properties;\r\n  #endif\r\n\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  CCodecs *Codecs;\r\n  #endif\r\n\r\n  CExtractOptions():\r\n      StdOutMode(false),\r\n      YesToAll(false),\r\n      TestMode(false),\r\n      PathMode(NExtract::NPathMode::kFullPathnames),\r\n      OverwriteMode(NExtract::NOverwriteMode::kAskBefore)\r\n      {}\r\n\r\n  /*\r\n    bool FullPathMode() const { return (ExtractMode == NExtractMode::kTest) ||\r\n    (ExtractMode == NExtractMode::kFullPath); }\r\n  */\r\n};\r\n\r\nstruct CDecompressStat\r\n{\r\n  UInt64 NumArchives;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  void Clear() { NumArchives = PackSize = UnpackSize = NumFolders = NumFiles = 0; }\r\n};\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage,\r\n    CDecompressStat &stat);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ExtractMode.h",
    "content": "// ExtractMode.h\r\n\r\n#ifndef __EXTRACT_MODE_H\r\n#define __EXTRACT_MODE_H\r\n\r\nnamespace NExtract {\r\n  \r\n  namespace NPathMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kFullPathnames,\r\n      kCurrentPathnames,\r\n      kNoPathnames\r\n    };\r\n  }\r\n  \r\n  namespace NOverwriteMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kAskBefore,\r\n      kWithoutPrompt,\r\n      kSkipExisting,\r\n      kAutoRename,\r\n      kAutoRenameExisting\r\n    };\r\n  }\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp",
    "content": "// ExtractingFilePath.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ExtractingFilePath.h\"\r\n\r\nstatic UString ReplaceIncorrectChars(const UString &s)\r\n{\r\n  #ifdef _WIN32\r\n  UString res;\r\n  for (int i = 0; i < s.Length(); i++)\r\n  {\r\n    wchar_t c = s[i];\r\n    if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>'  || c == '|' || c == ':' || c == '\"')\r\n      c = '_';\r\n    res += c;\r\n  }\r\n  res.TrimRight();\r\n  return res;\r\n  #else\r\n  return s;\r\n  #endif\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t *g_ReservedNames[] =\r\n{\r\n  L\"CON\", L\"PRN\", L\"AUX\", L\"NUL\"\r\n};\r\n\r\nstatic bool CheckTail(const UString &name, int len)\r\n{\r\n  int dotPos = name.Find(L'.');\r\n  if (dotPos < 0)\r\n    dotPos = name.Length();\r\n  UString s = name.Left(dotPos);\r\n  s.TrimRight();\r\n  return (s.Length() != len);\r\n}\r\n\r\nstatic bool CheckNameNum(const UString &name, const wchar_t *reservedName)\r\n{\r\n  int len = MyStringLen(reservedName);\r\n  if (name.Length() <= len)\r\n    return true;\r\n  if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n    return true;\r\n  wchar_t c = name[len];\r\n  if (c < L'0' || c > L'9')\r\n    return true;\r\n  return CheckTail(name, len + 1);\r\n}\r\n\r\nstatic bool IsSupportedName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++)\r\n  {\r\n    const wchar_t *reservedName = g_ReservedNames[i];\r\n    int len = MyStringLen(reservedName);\r\n    if (name.Length() < len)\r\n      continue;\r\n    if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n      continue;\r\n    if (!CheckTail(name, len))\r\n      return false;\r\n  }\r\n  if (!CheckNameNum(name, L\"COM\"))\r\n    return false;\r\n  return CheckNameNum(name, L\"LPT\");\r\n}\r\n#endif\r\n\r\nstatic UString GetCorrectFileName(const UString &path)\r\n{\r\n  if (path == L\"..\" || path == L\".\")\r\n    return UString();\r\n  return ReplaceIncorrectChars(path);\r\n}\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts)\r\n{\r\n  for (int i = 0; i < pathParts.Size();)\r\n  {\r\n    UString &s = pathParts[i];\r\n    s = GetCorrectFileName(s);\r\n    if (s.IsEmpty())\r\n      pathParts.Delete(i);\r\n    else\r\n    {\r\n      #ifdef _WIN32\r\n      if (!IsSupportedName(s))\r\n        s = (UString)L\"_\" + s;\r\n      #endif\r\n      i++;\r\n    }\r\n  }\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h",
    "content": "// ExtractingFilePath.h\r\n\r\n#ifndef __EXTRACTINGFILEPATH_H\r\n#define __EXTRACTINGFILEPATH_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h",
    "content": "// IFileExtractCallback.h\r\n\r\n#ifndef __IFILEEXTRACTCALLBACK_H\r\n#define __IFILEEXTRACTCALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"../../IDecl.h\"\r\n\r\nnamespace NOverwriteAnswer\r\n{\r\n  enum EEnum\r\n  {\r\n    kYes,\r\n    kYesToAll,\r\n    kNo,\r\n    kNoToAll,\r\n    kAutoRename,\r\n    kCancel\r\n  };\r\n}\r\n\r\nDECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)\r\n{\r\npublic:\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer) PURE;\r\n  STDMETHOD(PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position) PURE;\r\n  STDMETHOD(MessageError)(const wchar_t *message) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE;\r\n};\r\n\r\nstruct IExtractCallbackUI: IFolderArchiveExtractCallback\r\n{\r\n  virtual HRESULT BeforeOpen(const wchar_t *name) = 0;\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted) = 0;\r\n  virtual HRESULT ThereAreNoFiles() = 0;\r\n  virtual HRESULT ExtractResult(HRESULT result) = 0;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  virtual HRESULT SetPassword(const UString &password) = 0;\r\n  #endif\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp",
    "content": "// LoadCodecs.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LoadCodecs.h\"\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Common/StringToInt.h\"\r\n#endif\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/FileFind.h\"\r\n#include \"../../../Windows/DLL.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Windows/ResourceString.h\"\r\nstatic const UINT kIconTypesResId = 100;\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/Registry.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\n#ifdef _WIN32\r\nextern HINSTANCE g_hInstance;\r\n#endif\r\n\r\nstatic CSysString GetLibraryFolderPrefix()\r\n{\r\n  #ifdef _WIN32\r\n  TCHAR fullPath[MAX_PATH + 1];\r\n  ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);\r\n  CSysString path = fullPath;\r\n  int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  return path.Left(pos + 1);\r\n  #else\r\n  return CSysString(); // FIX IT\r\n  #endif\r\n}\r\n\r\n#define kCodecsFolderName TEXT(\"Codecs\")\r\n#define kFormatsFolderName TEXT(\"Formats\")\r\nstatic const TCHAR *kMainDll = TEXT(\"7z.dll\");\r\n\r\n#ifdef _WIN32\r\nstatic LPCTSTR kRegistryPath = TEXT(\"Software\") TEXT(STRING_PATH_SEPARATOR) TEXT(\"7-zip\");\r\nstatic LPCTSTR kProgramPathValue = TEXT(\"Path\");\r\nstatic bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)\r\n{\r\n  NRegistry::CKey key;\r\n  if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)\r\n    if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)\r\n    {\r\n      NName::NormalizeDirPathPrefix(path);\r\n      return true;\r\n    }\r\n  return false;\r\n}\r\n\r\n#endif\r\n\r\nCSysString GetBaseFolderPrefixFromRegistry()\r\n{\r\n  CSysString moduleFolderPrefix = GetLibraryFolderPrefix();\r\n  NFind::CFileInfo fi;\r\n  if (NFind::FindFile(moduleFolderPrefix + kMainDll, fi))\r\n    if (!fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fi))\r\n    if (fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fi))\r\n    if (fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  #ifdef _WIN32\r\n  CSysString path;\r\n  if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))\r\n    return path;\r\n  if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))\r\n    return path;\r\n  #endif\r\n  return moduleFolderPrefix;\r\n}\r\n\r\ntypedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);\r\ntypedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, void **outObject);\r\ntypedef UInt32 (WINAPI *SetLargePageModeFunc)();\r\n\r\n\r\nstatic HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 index,\r\n    PROPID propId, CLSID &clsId, bool &isAssigned)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  isAssigned = false;\r\n  RINOK(getMethodProperty(index, propId, &prop));\r\n  if (prop.vt == VT_BSTR)\r\n  {\r\n    isAssigned = true;\r\n    clsId = *(const GUID *)prop.bstrVal;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::LoadCodecs()\r\n{\r\n  CCodecLib &lib = Libs.Back();\r\n  lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress(\"GetMethodProperty\");\r\n  if (lib.GetMethodProperty == NULL)\r\n    return S_OK;\r\n\r\n  UInt32 numMethods = 1;\r\n  GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProcAddress(\"GetNumberOfMethods\");\r\n  if (getNumberOfMethodsFunc != NULL)\r\n  {\r\n    RINOK(getNumberOfMethodsFunc(&numMethods));\r\n  }\r\n\r\n  for(UInt32 i = 0; i < numMethods; i++)\r\n  {\r\n    CDllCodecInfo info;\r\n    info.LibIndex = Libs.Size() - 1;\r\n    info.CodecIndex = i;\r\n\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));\r\n\r\n    Codecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, NCOM::CPropVariant &prop)\r\n{\r\n  if (getProp2)\r\n    return getProp2(index, propID, &prop);;\r\n  return getProp(propID, &prop);\r\n}\r\n\r\nstatic HRESULT ReadBoolProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadStringProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, UString &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BSTR)\r\n    res = prop.bstrVal;\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\r\nvoid RegisterArc(const CArcInfo *arcInfo)\r\n{\r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo;\r\n}\r\n\r\nstatic void SplitString(const UString &srcString, UStringVector &destStrings)\r\n{\r\n  destStrings.Clear();\r\n  UString s;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L' ')\r\n    {\r\n      if (!s.IsEmpty())\r\n      {\r\n        destStrings.Add(s);\r\n        s.Empty();\r\n      }\r\n    }\r\n    else\r\n      s += c;\r\n  }\r\n  if (!s.IsEmpty())\r\n    destStrings.Add(s);\r\n}\r\n\r\nvoid CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt)\r\n{\r\n  UStringVector exts, addExts;\r\n  SplitString(ext, exts);\r\n  if (addExt != 0)\r\n    SplitString(addExt, addExts);\r\n  for (int i = 0; i < exts.Size(); i++)\r\n  {\r\n    CArcExtInfo extInfo;\r\n    extInfo.Ext = exts[i];\r\n    if (i < addExts.Size())\r\n    {\r\n      extInfo.AddExt = addExts[i];\r\n      if (extInfo.AddExt == L\"*\")\r\n        extInfo.AddExt.Empty();\r\n    }\r\n    Exts.Add(extInfo);\r\n  }\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nHRESULT CCodecs::LoadFormats()\r\n{\r\n  const NDLL::CLibrary &lib = Libs.Back().Lib;\r\n  GetHandlerPropertyFunc getProp = 0;\r\n  GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)\r\n      lib.GetProcAddress(\"GetHandlerProperty2\");\r\n  if (getProp2 == NULL)\r\n  {\r\n    getProp = (GetHandlerPropertyFunc)\r\n        lib.GetProcAddress(\"GetHandlerProperty\");\r\n    if (getProp == NULL)\r\n      return S_OK;\r\n  }\r\n\r\n  UInt32 numFormats = 1;\r\n  GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)\r\n    lib.GetProcAddress(\"GetNumberOfFormats\");\r\n  if (getNumberOfFormats != NULL)\r\n  {\r\n    RINOK(getNumberOfFormats(&numFormats));\r\n  }\r\n  if (getProp2 == NULL)\r\n    numFormats = 1;\r\n\r\n  for(UInt32 i = 0; i < numFormats; i++)\r\n  {\r\n    CArcInfoEx item;\r\n    item.LibIndex = Libs.Size() - 1;\r\n    item.FormatIndex = i;\r\n\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)\r\n      continue;\r\n    if (prop.vt != VT_BSTR)\r\n      continue;\r\n    item.ClassID = *(const GUID *)prop.bstrVal;\r\n    prop.Clear();\r\n\r\n    UString ext, addExt;\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));\r\n    item.AddExts(ext, addExt);\r\n\r\n    ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);\r\n    if (item.UpdateEnabled)\r\n      ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);\r\n    \r\n    if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)\r\n      if (prop.vt == VT_BSTR)\r\n      {\r\n        UINT len = ::SysStringByteLen(prop.bstrVal);\r\n        item.StartSignature.SetCapacity(len);\r\n        memmove(item.StartSignature, prop.bstrVal, len);\r\n      }\r\n    Formats.Add(item);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef NEW_FOLDER_INTERFACE\r\nvoid CCodecLib::LoadIcons()\r\n{\r\n  UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId);\r\n  UStringVector pairs;\r\n  SplitString(iconTypes, pairs);\r\n  for (int i = 0; i < pairs.Size(); i++)\r\n  {\r\n    const UString &s = pairs[i];\r\n    int pos = s.Find(L':');\r\n    if (pos < 0)\r\n      continue;\r\n    CIconPair iconPair;\r\n    const wchar_t *end;\r\n    UString num = s.Mid(pos + 1);\r\n    iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);\r\n    if (*end != L'\\0')\r\n      continue;\r\n    iconPair.Ext = s.Left(pos);\r\n    IconPairs.Add(iconPair);\r\n  }\r\n}\r\n\r\nint CCodecLib::FindIconIndex(const UString &ext) const\r\n{\r\n  for (int i = 0; i < IconPairs.Size(); i++)\r\n  {\r\n    const CIconPair &pair = IconPairs[i];\r\n    if (ext.CompareNoCase(pair.Ext) == 0)\r\n      return pair.IconIndex;\r\n  }\r\n  return -1;\r\n}\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nextern \"C\"\r\n{\r\n  extern SIZE_T g_LargePageSize;\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::LoadDll(const CSysString &dllPath)\r\n{\r\n  {\r\n    NDLL::CLibrary library;\r\n    if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))\r\n      return S_OK;\r\n  }\r\n  Libs.Add(CCodecLib());\r\n  CCodecLib &lib = Libs.Back();\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  lib.Path = dllPath;\r\n  #endif\r\n  bool used = false;\r\n  HRESULT res = S_OK;\r\n  if (lib.Lib.Load(dllPath))\r\n  {\r\n    #ifdef NEW_FOLDER_INTERFACE\r\n    lib.LoadIcons();\r\n    #endif\r\n\r\n    #ifdef _7ZIP_LARGE_PAGES\r\n    if (g_LargePageSize != 0)\r\n    {\r\n      SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProcAddress(\"SetLargePageMode\");\r\n      if (setLargePageMode != 0)\r\n        setLargePageMode();\r\n    }\r\n    #endif\r\n\r\n    lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress(\"CreateObject\");\r\n    if (lib.CreateObject != 0)\r\n    {\r\n      int startSize = Codecs.Size();\r\n      res = LoadCodecs();\r\n      used = (Codecs.Size() != startSize);\r\n      if (res == S_OK)\r\n      {\r\n        startSize = Formats.Size();\r\n        res = LoadFormats();\r\n        used = used || (Formats.Size() != startSize);\r\n      }\r\n    }\r\n  }\r\n  if (!used)\r\n    Libs.DeleteBack();\r\n  return res;\r\n}\r\n\r\nHRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)\r\n{\r\n  NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT(\"*\")));\r\n  NFile::NFind::CFileInfo fi;\r\n  while (enumerator.Next(fi))\r\n  {\r\n    if (fi.IsDir())\r\n      continue;\r\n    RINOK(LoadDll(folderPrefix + fi.Name));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n#ifndef _SFX\r\nstatic inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)\r\n{\r\n  bb.SetCapacity(size);\r\n  memmove((Byte *)bb, data, size);\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::Load()\r\n{\r\n  Formats.Clear();\r\n  #ifdef EXTERNAL_CODECS\r\n  Codecs.Clear();\r\n  #endif\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n  {\r\n    const CArcInfo &arc = *g_Arcs[i];\r\n    CArcInfoEx item;\r\n    item.Name = arc.Name;\r\n    item.CreateInArchive = arc.CreateInArchive;\r\n    item.CreateOutArchive = arc.CreateOutArchive;\r\n    item.AddExts(arc.Ext, arc.AddExt);\r\n    item.UpdateEnabled = (arc.CreateOutArchive != 0);\r\n    item.KeepName = arc.KeepName;\r\n\r\n    #ifndef _SFX\r\n    SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);\r\n    #endif\r\n    Formats.Add(item);\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();\r\n  RINOK(LoadDll(baseFolder + kMainDll));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nint CCodecs::FindFormatForArchiveName(const UString &arcPath) const\r\n{\r\n  int slashPos1 = arcPath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  int slashPos2 = arcPath.ReverseFind(L'.');\r\n  int dotPos = arcPath.ReverseFind(L'.');\r\n  if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)\r\n    return -1;\r\n  UString ext = arcPath.Mid(dotPos + 1);\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    // if (arc.FindExtension(ext) >= 0)\r\n    UString mainExt = arc.GetMainExt();\r\n    if (!mainExt.IsEmpty() && ext.CompareNoCase(mainExt) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForExtension(const UString &ext) const\r\n{\r\n  if (ext.IsEmpty())\r\n    return -1;\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n    if (Formats[i].FindExtension(ext) >= 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveType(const UString &arcType) const\r\n{\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n    if (Formats[i].Name.CompareNoCase(arcType) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nbool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const\r\n{\r\n  formatIndices.Clear();\r\n  for (int pos = 0; pos < arcType.Length();)\r\n  {\r\n    int pos2 = arcType.Find('.', pos);\r\n    if (pos2 < 0)\r\n      pos2 = arcType.Length();\r\n    const UString name = arcType.Mid(pos, pos2 - pos);\r\n    int index = FindFormatForArchiveType(name);\r\n    if (index < 0 && name != L\"*\")\r\n    {\r\n      formatIndices.Clear();\r\n      return false;\r\n    }\r\n    formatIndices.Add(index);\r\n    pos = pos2 + 1;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\n#ifdef EXPORT_CODECS\r\nextern unsigned int g_NumCodecs;\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);\r\n// STDAPI GetNumberOfMethods(UInt32 *numCodecs);\r\n#endif\r\n\r\nSTDMETHODIMP CCodecs::GetNumberOfMethods(UInt32 *numMethods)\r\n{\r\n  *numMethods =\r\n      #ifdef EXPORT_CODECS\r\n      g_NumCodecs +\r\n      #endif\r\n      Codecs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return GetMethodProperty(index, propID, value);\r\n  #endif\r\n\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n\r\n  if (propID == NMethodPropID::kDecoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.DecoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  if (propID == NMethodPropID::kEncoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.EncoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(false, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.DecoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(true, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.EncoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const\r\n{\r\n  for (int i = 0; i < Codecs.Size(); i++)\r\n  {\r\n    const CDllCodecInfo &codec = Codecs[i];\r\n    if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigned)\r\n      continue;\r\n    const CCodecLib &lib = Libs[codec.LibIndex];\r\n    UString res;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      res = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      continue;\r\n    if (name.CompareNoCase(res) == 0)\r\n      return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICompressCoder, (void **)&coder);\r\n  }\r\n  return CLASS_E_CLASSNOTAVAILABLE;\r\n}\r\n\r\nint CCodecs::GetCodecLibIndex(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return -1;\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.LibIndex;\r\n  #else\r\n  return -1;\r\n  #endif\r\n}\r\n\r\nbool CCodecs::GetCodecEncoderIsAssigned(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n  {\r\n    NWindows::NCOM::CPropVariant prop;\r\n    if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK)\r\n      if (prop.vt != VT_EMPTY)\r\n        return true;\r\n    return false;\r\n  }\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.EncoderIsAssigned;\r\n  #else\r\n  return false;\r\n  #endif\r\n}\r\n\r\nHRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(GetProperty(index, NMethodPropID::kID, &prop));\r\n  if (prop.vt != VT_UI8)\r\n    return E_INVALIDARG;\r\n  id = prop.uhVal.QuadPart;\r\n  return S_OK;\r\n}\r\n\r\nUString CCodecs::GetCodecName(UInt32 index)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK)\r\n    if (prop.vt == VT_BSTR)\r\n      s = prop.bstrVal;\r\n  return s;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/LoadCodecs.h",
    "content": "// LoadCodecs.h\r\n\r\n#ifndef __LOADCODECS_H\r\n#define __LOADCODECS_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/DLL.h\"\r\n#endif\r\n\r\nstruct CDllCodecInfo\r\n{\r\n  CLSID Encoder;\r\n  CLSID Decoder;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  int LibIndex;\r\n  UInt32 CodecIndex;\r\n};\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcExtInfo\r\n{\r\n  UString Ext;\r\n  UString AddExt;\r\n  CArcExtInfo() {}\r\n  CArcExtInfo(const UString &ext): Ext(ext) {}\r\n  CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}\r\n};\r\n\r\n\r\nstruct CArcInfoEx\r\n{\r\n  #ifdef EXTERNAL_CODECS\r\n  int LibIndex;\r\n  UInt32 FormatIndex;\r\n  CLSID ClassID;\r\n  #endif\r\n  bool UpdateEnabled;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n  UString Name;\r\n  CObjectVector<CArcExtInfo> Exts;\r\n  #ifndef _SFX\r\n  CByteBuffer StartSignature;\r\n  // CByteBuffer FinishSignature;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  UStringVector AssociateExts;\r\n  #endif\r\n  #endif\r\n  bool KeepName;\r\n  UString GetMainExt() const\r\n  {\r\n    if (Exts.IsEmpty())\r\n      return UString();\r\n    return Exts[0].Ext;\r\n  }\r\n  int FindExtension(const UString &ext) const\r\n  {\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n      if (ext.CompareNoCase(Exts[i].Ext) == 0)\r\n        return i;\r\n    return -1;\r\n  }\r\n  UString GetAllExtensions() const\r\n  {\r\n    UString s;\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n    {\r\n      if (i > 0)\r\n        s += ' ';\r\n      s += Exts[i].Ext;\r\n    }\r\n    return s;\r\n  }\r\n\r\n  void AddExts(const wchar_t* ext, const wchar_t* addExt);\r\n\r\n  CArcInfoEx():\r\n    #ifdef EXTERNAL_CODECS\r\n    LibIndex(-1),\r\n    #endif\r\n    UpdateEnabled(false),\r\n    CreateInArchive(0), CreateOutArchive(0),\r\n    KeepName(false)\r\n    #ifndef _SFX\r\n    #endif\r\n  {}\r\n};\r\n\r\n#ifdef EXTERNAL_CODECS\r\ntypedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);\r\n\r\n\r\nstruct CCodecLib\r\n{\r\n  NWindows::NDLL::CLibrary Lib;\r\n  GetMethodPropertyFunc GetMethodProperty;\r\n  CreateObjectFunc CreateObject;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  struct CIconPair\r\n  {\r\n    UString Ext;\r\n    UInt32 IconIndex;\r\n  };\r\n  CSysString Path;\r\n  CObjectVector<CIconPair> IconPairs;\r\n  void LoadIcons();\r\n  int FindIconIndex(const UString &ext) const;\r\n  #endif\r\n  CCodecLib(): GetMethodProperty(0) {}\r\n};\r\n#endif\r\n\r\nclass CCodecs:\r\n  #ifdef EXTERNAL_CODECS\r\n  public ICompressCodecsInfo,\r\n  #else\r\n  public IUnknown,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef EXTERNAL_CODECS\r\n  CObjectVector<CCodecLib> Libs;\r\n  CObjectVector<CDllCodecInfo> Codecs;\r\n  HRESULT LoadCodecs();\r\n  HRESULT LoadFormats();\r\n  HRESULT LoadDll(const CSysString &path);\r\n  HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);\r\n\r\n  HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const\r\n  {\r\n    return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);\r\n  }\r\n  #endif\r\n\r\npublic:\r\n  CObjectVector<CArcInfoEx> Formats;\r\n  HRESULT Load();\r\n  \r\n  #ifndef _SFX\r\n  int FindFormatForArchiveName(const UString &arcPath) const;\r\n  int FindFormatForExtension(const UString &ext) const;\r\n  int FindFormatForArchiveType(const UString &arcType) const;\r\n  bool FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const;\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder);\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder);\r\n  #endif\r\n\r\n  int GetCodecLibIndex(UInt32 index);\r\n  bool GetCodecEncoderIsAssigned(UInt32 index);\r\n  HRESULT GetCodecId(UInt32 index, UInt64 &id);\r\n  UString GetCodecName(UInt32 index);\r\n\r\n  HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const\r\n  {\r\n    const CArcInfoEx &ai = Formats[formatIndex];\r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateInArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, false);\r\n    #endif\r\n  }\r\n  HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const\r\n  {\r\n    const CArcInfoEx &ai = Formats[formatIndex];\r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateOutArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, true);\r\n    #endif\r\n  }\r\n  int FindOutFormatFromName(const UString &name) const\r\n  {\r\n    for (int i = 0; i < Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = Formats[i];\r\n      if (!arc.UpdateEnabled)\r\n        continue;\r\n      if (arc.Name.CompareNoCase(name) == 0)\r\n        return i;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;\r\n  #endif\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/OpenArchive.cpp",
    "content": "// OpenArchive.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidPath, &prop));\r\n  if(prop.vt == VT_BSTR)\r\n    result = prop.bstrVal;\r\n  else if (prop.vt == VT_EMPTY)\r\n    result.Empty();\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result)\r\n{\r\n  RINOK(GetArchiveItemPath(archive, index, result));\r\n  if (result.IsEmpty())\r\n  {\r\n    result = defaultName;\r\n    NCOM::CPropVariant prop;\r\n    RINOK(archive->GetProperty(index, kpidExtension, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n    {\r\n      result += L'.';\r\n      result += prop.bstrVal;\r\n    }\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\r\n    const FILETIME &defaultFileTime, FILETIME &fileTime)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidMTime, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n    fileTime = prop.filetime;\r\n  else if (prop.vt == VT_EMPTY)\r\n    fileTime = defaultFileTime;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\r\n}\r\n\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsAnti, result);\r\n}\r\n\r\n// Static-SFX (for Linux) can be big.\r\nconst UInt64 kMaxCheckStartPosition = 1 << 22;\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  inStreamSpec->Open(fileName);\r\n  return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n}\r\n\r\n#ifndef _SFX\r\nstatic inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)\r\n{\r\n  for (size_t i = 0; i < size; i++)\r\n    if (p1[i] != p2[i])\r\n      return false;\r\n  return true;\r\n}\r\n#endif\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    IInStream *inStream,\r\n    const UString &fileName,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  *archiveResult = NULL;\r\n  UString extension;\r\n  {\r\n    int dotPos = fileName.ReverseFind(L'.');\r\n    if (dotPos >= 0)\r\n      extension = fileName.Mid(dotPos + 1);\r\n  }\r\n  CIntVector orderIndices;\r\n  if (arcTypeIndex >= 0)\r\n    orderIndices.Add(arcTypeIndex);\r\n  else\r\n  {\r\n\r\n  int i;\r\n  int numFinded = 0;\r\n  for (i = 0; i < codecs->Formats.Size(); i++)\r\n    if (codecs->Formats[i].FindExtension(extension) >= 0)\r\n      orderIndices.Insert(numFinded++, i);\r\n    else\r\n      orderIndices.Add(i);\r\n  \r\n  #ifndef _SFX\r\n  if (numFinded != 1)\r\n  {\r\n    CIntVector orderIndices2;\r\n    CByteBuffer byteBuffer;\r\n    const size_t kBufferSize = (1 << 21);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    size_t processedSize = kBufferSize;\r\n    RINOK(ReadStream(inStream, byteBuffer, &processedSize));\r\n    if (processedSize == 0)\r\n      return S_FALSE;\r\n\r\n    const Byte *buf = byteBuffer;\r\n    Byte hash[1 << 16];\r\n    memset(hash, 0xFF, 1 << 16);\r\n    Byte prevs[256];\r\n    if (orderIndices.Size() > 255)\r\n      return S_FALSE;\r\n    int i;\r\n    for (i = 0; i < orderIndices.Size(); i++)\r\n    {\r\n      const CArcInfoEx &ai = codecs->Formats[orderIndices[i]];\r\n      const CByteBuffer &sig = ai.StartSignature;\r\n      if (sig.GetCapacity() < 2)\r\n        continue;\r\n      UInt32 v = sig[0] | ((UInt32)sig[1] << 8);\r\n      prevs[i] = hash[v];\r\n      hash[v] = (Byte)i;\r\n    }\r\n\r\n    processedSize--;\r\n    for (UInt32 pos = 0; pos < processedSize; pos++)\r\n    {\r\n      for (; pos < processedSize && hash[buf[pos] | ((UInt32)buf[pos + 1] << 8)] == 0xFF; pos++);\r\n      if (pos == processedSize)\r\n        break;\r\n      UInt32 v = buf[pos] | ((UInt32)buf[pos + 1] << 8);\r\n      Byte *ptr = &hash[v];\r\n      int i = *ptr;\r\n      do\r\n      {\r\n        int index = orderIndices[i];\r\n        const CArcInfoEx &ai = codecs->Formats[index];\r\n        const CByteBuffer &sig = ai.StartSignature;\r\n        if (sig.GetCapacity() != 0 && pos + sig.GetCapacity() <= processedSize + 1)\r\n          if (TestSignature(buf + pos, sig, sig.GetCapacity()))\r\n          {\r\n            orderIndices2.Add(index);\r\n            orderIndices[i] = 0xFF;\r\n            *ptr = prevs[i];\r\n          }\r\n        ptr = &prevs[i];\r\n        i = *ptr;\r\n      }\r\n      while (i != 0xFF);\r\n    }\r\n    \r\n    for (i = 0; i < orderIndices.Size(); i++)\r\n    {\r\n      int val = orderIndices[i];\r\n      if (val != 0xFF)\r\n        orderIndices2.Add(val);\r\n    }\r\n    orderIndices = orderIndices2;\r\n\r\n    if (orderIndices.Size() >= 2)\r\n    {\r\n      int isoIndex = codecs->FindFormatForArchiveType(L\"iso\");\r\n      int udfIndex = codecs->FindFormatForArchiveType(L\"udf\");\r\n      int iIso = -1;\r\n      int iUdf = -1;\r\n      for (int i = 0; i < orderIndices.Size(); i++)\r\n      {\r\n        if (orderIndices[i] == isoIndex) iIso = i;\r\n        if (orderIndices[i] == udfIndex) iUdf = i;\r\n      }\r\n      if (iUdf == iIso + 1)\r\n      {\r\n        orderIndices[iUdf] = isoIndex;\r\n        orderIndices[iIso] = udfIndex;\r\n      }\r\n    }\r\n  }\r\n  else if (extension == L\"000\" || extension == L\"001\")\r\n  {\r\n    CByteBuffer byteBuffer;\r\n    const size_t kBufferSize = (1 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    size_t processedSize = kBufferSize;\r\n    RINOK(ReadStream(inStream, buffer, &processedSize));\r\n    if (processedSize >= 16)\r\n    {\r\n      Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};\r\n      if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] & 1) != 0)\r\n      {\r\n        for (int i = 0; i < orderIndices.Size(); i++)\r\n        {\r\n          int index = orderIndices[i];\r\n          const CArcInfoEx &ai = codecs->Formats[index];\r\n          if (ai.Name.CompareNoCase(L\"rar\") != 0)\r\n            continue;\r\n          orderIndices.Delete(i--);\r\n          orderIndices.Insert(0, index);\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n  }\r\n\r\n  for(int i = 0; i < orderIndices.Size(); i++)\r\n  {\r\n    inStream->Seek(0, STREAM_SEEK_SET, NULL);\r\n\r\n    CMyComPtr<IInArchive> archive;\r\n\r\n    formatIndex = orderIndices[i];\r\n    RINOK(codecs->CreateInArchive(formatIndex, archive));\r\n    if (!archive)\r\n      continue;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    HRESULT result = archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n    if (result == S_FALSE)\r\n      continue;\r\n    RINOK(result);\r\n    *archiveResult = archive.Detach();\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex];\r\n    if (format.Exts.Size() == 0)\r\n    {\r\n      defaultItemName = GetDefaultName2(fileName, L\"\", L\"\");\r\n    }\r\n    else\r\n    {\r\n      int subExtIndex = format.FindExtension(extension);\r\n      if (subExtIndex < 0)\r\n        subExtIndex = 0;\r\n      defaultItemName = GetDefaultName2(fileName,\r\n          format.Exts[subExtIndex].Ext,\r\n          format.Exts[subExtIndex].AddExt);\r\n    }\r\n    return S_OK;\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &filePath,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  if (!inStreamSpec->Open(filePath))\r\n    return GetLastError();\r\n  return OpenArchive(codecs, arcTypeIndex, inStream, ExtractFileNameFromPath(filePath),\r\n    archiveResult, formatIndex,\r\n    defaultItemName, openArchiveCallback);\r\n}\r\n\r\nstatic void MakeDefaultName(UString &name)\r\n{\r\n  int dotPos = name.ReverseFind(L'.');\r\n  if (dotPos < 0)\r\n    return;\r\n  UString ext = name.Mid(dotPos + 1);\r\n  if (ext.IsEmpty())\r\n    return;\r\n  for (int pos = 0; pos < ext.Length(); pos++)\r\n    if (ext[pos] < L'0' || ext[pos] > L'9')\r\n      return;\r\n  name = name.Left(dotPos);\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &fileName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  if (formatIndices.Size() >= 3)\r\n    return E_NOTIMPL;\r\n  \r\n  int arcTypeIndex = -1;\r\n  if (formatIndices.Size() >= 1)\r\n    arcTypeIndex = formatIndices[formatIndices.Size() - 1];\r\n  \r\n  HRESULT result = OpenArchive(codecs, arcTypeIndex, fileName,\r\n    archive0, formatIndex0, defaultItemName0, openArchiveCallback);\r\n  RINOK(result);\r\n\r\n  if (formatIndices.Size() == 1)\r\n    return S_OK;\r\n  arcTypeIndex = -1;\r\n  if (formatIndices.Size() >= 2)\r\n    arcTypeIndex = formatIndices[formatIndices.Size() - 2];\r\n\r\n  HRESULT resSpec = (formatIndices.Size() == 0 ? S_OK : E_NOTIMPL);\r\n\r\n  CMyComPtr<IInArchiveGetStream> getStream;\r\n  result = (*archive0)->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream);\r\n  if (result != S_OK || !getStream)\r\n    return resSpec;\r\n\r\n  CMyComPtr<ISequentialInStream> subSeqStream;\r\n  result = getStream->GetStream(0, &subSeqStream);\r\n  if (result != S_OK || !subSeqStream)\r\n    return resSpec;\r\n\r\n  CMyComPtr<IInStream> subStream;\r\n  result = subSeqStream.QueryInterface(IID_IInStream, &subStream);\r\n  if (result != S_OK || !subStream)\r\n    return resSpec;\r\n\r\n  UInt32 numItems;\r\n  RINOK((*archive0)->GetNumberOfItems(&numItems));\r\n  if (numItems < 1)\r\n    return resSpec;\r\n\r\n  UString subPath;\r\n  RINOK(GetArchiveItemPath(*archive0, 0, subPath))\r\n  if (subPath.IsEmpty())\r\n  {\r\n    MakeDefaultName(defaultItemName0);\r\n    subPath = defaultItemName0;\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex0];\r\n    if (format.Name.CompareNoCase(L\"7z\") == 0)\r\n    {\r\n      if (subPath.Right(3).CompareNoCase(L\".7z\") != 0)\r\n        subPath += L\".7z\";\r\n    }\r\n  }\r\n  else\r\n    subPath = ExtractFileNameFromPath(subPath);\r\n\r\n  CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;\r\n  openArchiveCallback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);\r\n  if (setSubArchiveName)\r\n    setSubArchiveName->SetSubArchiveName(subPath);\r\n\r\n  result = OpenArchive(codecs, arcTypeIndex, subStream, subPath,\r\n      archive1, formatIndex1, defaultItemName1, openArchiveCallback);\r\n  resSpec = (formatIndices.Size() == 0 ? S_OK : S_FALSE);\r\n  if (result != S_OK)\r\n    return resSpec;\r\n  return S_OK;\r\n}\r\n\r\nstatic void SetCallback(const UString &archiveName,\r\n    IOpenCallbackUI *openCallbackUI,\r\n    IArchiveOpenCallback *reOpenCallback,\r\n    CMyComPtr<IArchiveOpenCallback> &openCallback)\r\n{\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n  openCallbackSpec->ReOpenCallback = reOpenCallback;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  openCallbackSpec->Init(\r\n      fullName.Left(fileNamePartStartIndex),\r\n      fullName.Mid(fileNamePartStartIndex));\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &archiveName,\r\n    IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI)\r\n{\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(archiveName, openCallbackUI, NULL, openCallback);\r\n  int formatInfo;\r\n  return OpenArchive(codecs, arcTypeIndex, archiveName, archive, formatInfo, defaultItemName, openCallback);\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  volumesSize = 0;\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  UString prefix = fullName.Left(fileNamePartStartIndex);\r\n  UString name = fullName.Mid(fileNamePartStartIndex);\r\n  openCallbackSpec->Init(prefix, name);\r\n\r\n  int formatIndex0, formatIndex1;\r\n  RINOK(OpenArchive(codecs, formatIndices, archiveName,\r\n      archive0,\r\n      archive1,\r\n      formatIndex0,\r\n      formatIndex1,\r\n      defaultItemName0,\r\n      defaultItemName1,\r\n      openCallback));\r\n  volumePaths.Add(prefix + name);\r\n  for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)\r\n    volumePaths.Add(prefix + openCallbackSpec->FileNames[i]);\r\n  volumesSize = openCallbackSpec->TotalSize;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveLink::Close()\r\n{\r\n  if (Archive1 != 0)\r\n    RINOK(Archive1->Close());\r\n  if (Archive0 != 0)\r\n    RINOK(Archive0->Close());\r\n  IsOpen = false;\r\n  return S_OK;\r\n}\r\n\r\nvoid CArchiveLink::Release()\r\n{\r\n  IsOpen = false;\r\n  Archive1.Release();\r\n  Archive0.Release();\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  HRESULT res = OpenArchive(codecs, formatIndices, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1,\r\n    archiveLink.FormatIndex0, archiveLink.FormatIndex1,\r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\r\n    openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT MyOpenArchive(CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  HRESULT res = MyOpenArchive(codecs, formatIndices, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1,\r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\r\n    archiveLink.VolumePaths,\r\n    archiveLink.VolumesSize,\r\n    openCallbackUI);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT ReOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, const UString &fileName,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  if (archiveLink.GetNumLevels() > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (archiveLink.GetNumLevels() == 0)\r\n    return MyOpenArchive(codecs, CIntVector(), fileName, archiveLink, 0);\r\n\r\n  CMyComPtr<IArchiveOpenCallback> openCallbackNew;\r\n  SetCallback(fileName, NULL, openCallback, openCallbackNew);\r\n\r\n  HRESULT res = ReOpenArchive(archiveLink.GetArchive(), fileName, openCallbackNew);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/OpenArchive.h",
    "content": "// OpenArchive.h\r\n\r\n#ifndef __OPENARCHIVE_H\r\n#define __OPENARCHIVE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"LoadCodecs.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result);\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result);\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\r\n    const FILETIME &defaultFileTime, FILETIME &fileTime);\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result);\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result);\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result);\r\n\r\nstruct ISetSubArchiveName\r\n{\r\n  virtual void SetSubArchiveName(const wchar_t *name) = 0;\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    IInStream *inStream,\r\n    const UString &fileName,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &filePath,\r\n    IInArchive **archive,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &filePath,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback);\r\n\r\nstruct CArchiveLink\r\n{\r\n  CMyComPtr<IInArchive> Archive0;\r\n  CMyComPtr<IInArchive> Archive1;\r\n  UString DefaultItemName0;\r\n  UString DefaultItemName1;\r\n\r\n  int FormatIndex0;\r\n  int FormatIndex1;\r\n  \r\n  UStringVector VolumePaths;\r\n\r\n  bool IsOpen;\r\n  UInt64 VolumesSize;\r\n\r\n  int GetNumLevels() const\r\n  {\r\n    int result = 0;\r\n    if (Archive0)\r\n    {\r\n      result++;\r\n      if (Archive1)\r\n        result++;\r\n    }\r\n    return result;\r\n  }\r\n\r\n  CArchiveLink(): IsOpen(false), VolumesSize(0) {};\r\n\r\n  IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; }\r\n  UString GetDefaultItemName()  { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; }\r\n  int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; }\r\n  HRESULT Close();\r\n  void Release();\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT ReOpenArchive(\r\n    CCodecs *codecs,\r\n    CArchiveLink &archiveLink,\r\n    const UString &fileName,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp",
    "content": "// PropIDUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropIDUtils.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../PropID.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic void ConvertUInt32ToHex(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    int t = value & 0xF;\r\n    value >>= 4;\r\n    s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));\r\n  }\r\n  s[8] = L'\\0';\r\n}\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full)\r\n{\r\n  switch(propID)\r\n  {\r\n    case kpidCTime:\r\n    case kpidATime:\r\n    case kpidMTime:\r\n    {\r\n      if (propVariant.vt != VT_FILETIME)\r\n        return UString(); // It is error;\r\n      FILETIME localFileTime;\r\n      if (propVariant.filetime.dwHighDateTime == 0 &&\r\n          propVariant.filetime.dwLowDateTime == 0)\r\n        return UString();\r\n      if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n        return UString(); // It is error;\r\n      return ConvertFileTimeToString(localFileTime, true, full);\r\n    }\r\n    case kpidCRC:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      wchar_t temp[12];\r\n      ConvertUInt32ToHex(propVariant.ulVal, temp);\r\n      return temp;\r\n    }\r\n    case kpidAttrib:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UString result;\r\n      UInt32 attributes = propVariant.ulVal;\r\n      if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';\r\n      if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';\r\n      if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';\r\n      if (NFile::NFind::NAttributes::IsDir(attributes)) result += L'D';\r\n      if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';\r\n      if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';\r\n      if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';\r\n      return result;\r\n    }\r\n    case kpidDictionarySize:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UInt32 size = propVariant.ulVal;\r\n      if (size % (1 << 20) == 0)\r\n        return ConvertUInt32ToString(size >> 20) + L\"MB\";\r\n      if (size % (1 << 10) == 0)\r\n        return ConvertUInt32ToString(size >> 10) + L\"KB\";\r\n      return ConvertUInt32ToString(size);\r\n    }\r\n  }\r\n  return ConvertPropVariantToString(propVariant);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/PropIDUtils.h",
    "content": "// PropIDUtils.h\r\n\r\n#ifndef __PROPIDUTILS_H\r\n#define __PROPIDUTILS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/Property.h",
    "content": "// Property.h\r\n\r\n#ifndef __PROPERTY_H\r\n#define __PROPERTY_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nstruct CProperty\r\n{\r\n  UString Name;\r\n  UString Value;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/SetProperties.cpp",
    "content": "// SetProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SetProperties.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\n\r\nstatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)\r\n{\r\n  const wchar_t *endPtr;\r\n  UInt64 result = ConvertStringToUInt64(s, &endPtr);\r\n  if (endPtr - (const wchar_t *)s != s.Length())\r\n    prop = s;\r\n  else if (result <= 0xFFFFFFFF)\r\n    prop = (UInt32)result;\r\n  else\r\n    prop = result;\r\n}\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)\r\n{\r\n  if (properties.IsEmpty())\r\n    return S_OK;\r\n  CMyComPtr<ISetProperties> setProperties;\r\n  unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);\r\n  if (!setProperties)\r\n    return S_OK;\r\n\r\n  UStringVector realNames;\r\n  CPropVariant *values = new CPropVariant[properties.Size()];\r\n  try\r\n  {\r\n    int i;\r\n    for(i = 0; i < properties.Size(); i++)\r\n    {\r\n      const CProperty &property = properties[i];\r\n      NCOM::CPropVariant propVariant;\r\n      UString name = property.Name;\r\n      if (property.Value.IsEmpty())\r\n      {\r\n        if (!name.IsEmpty())\r\n        {\r\n          wchar_t c = name[name.Length() - 1];\r\n          if (c == L'-')\r\n            propVariant = false;\r\n          else if (c == L'+')\r\n            propVariant = true;\r\n          if (propVariant.vt != VT_EMPTY)\r\n            name = name.Left(name.Length() - 1);\r\n        }\r\n      }\r\n      else\r\n        ParseNumberString(property.Value, propVariant);\r\n      realNames.Add(name);\r\n      values[i] = propVariant;\r\n    }\r\n    CRecordVector<const wchar_t *> names;\r\n    for(i = 0; i < realNames.Size(); i++)\r\n      names.Add((const wchar_t *)realNames[i]);\r\n    \r\n    RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));\r\n  }\r\n  catch(...)\r\n  {\r\n    delete []values;\r\n    throw;\r\n  }\r\n  delete []values;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/SetProperties.h",
    "content": "// SetProperties.h\r\n\r\n#ifndef __SETPROPERTIES_H\r\n#define __SETPROPERTIES_H\r\n\r\n#include \"Property.h\"\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/SortUtils.cpp",
    "content": "// SortUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SortUtils.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nstatic int CompareStrings(const int *p1, const int *p2, void *param)\r\n{\r\n  const UStringVector &strings = *(const UStringVector *)param;\r\n  return CompareFileNames(strings[*p1], strings[*p2]);\r\n}\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numItems = strings.Size();\r\n  indices.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n    indices.Add(i);\r\n  indices.Sort(CompareStrings, (void *)&strings);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/SortUtils.h",
    "content": "// SortUtils.h\r\n\r\n#ifndef __SORTUTLS_H\r\n#define __SORTUTLS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/StdAfx.h",
    "content": "// stdafx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/TempFiles.cpp",
    "content": "// TempFiles.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"TempFiles.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileIO.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nvoid CTempFiles::Clear()\r\n{\r\n  while(!Paths.IsEmpty())\r\n  {\r\n    NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());\r\n    Paths.DeleteBack();\r\n  }\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/TempFiles.h",
    "content": "// TempFiles.h\r\n\r\n#ifndef __TEMPFILES_H\r\n#define __TEMPFILES_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nclass CTempFiles\r\n{\r\n  void Clear();\r\npublic:\r\n  UStringVector Paths;\r\n  ~CTempFiles() { Clear(); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/Update.cpp",
    "content": "// Update.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Update.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/DLL.h\"\r\n#endif\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/DirItem.h\"\r\n#include \"../Common/EnumDirItems.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n#include \"SetProperties.h\"\r\n#include \"TempFiles.h\"\r\n#include \"UpdateCallback.h\"\r\n\r\nstatic const char *kUpdateIsNotSupoorted =\r\n  \"update operations are not supported for this archive\";\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nstatic const wchar_t *kTempFolderPrefix = L\"7zE\";\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)\r\n{\r\n  CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;\r\n  return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);\r\n}\r\n\r\nclass COutMultiVolStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    COutFileStream *StreamSpec;\r\n    CMyComPtr<IOutStream> Stream;\r\n    UString Name;\r\n    UInt64 Pos;\r\n    UInt64 RealSize;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  // CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  CRecordVector<UInt64> Sizes;\r\n  UString Prefix;\r\n  CTempFiles *TempFiles;\r\n\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  HRESULT Close();\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n// static NSynchronization::CCriticalSection g_TempPathsCS;\r\n\r\nHRESULT COutMultiVolStream::Close()\r\n{\r\n  HRESULT res = S_OK;\r\n  for (int i = 0; i < Streams.Size(); i++)\r\n  {\r\n    CSubStreamInfo &s = Streams[i];\r\n    if (s.StreamSpec)\r\n    {\r\n      HRESULT res2 = s.StreamSpec->Close();\r\n      if (res2 != S_OK)\r\n        res = res2;\r\n    }\r\n  }\r\n  return res;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n\r\n      wchar_t temp[32];\r\n      ConvertUInt64ToString(_streamIndex + 1, temp);\r\n      UString res = temp;\r\n      while (res.Length() < 3)\r\n        res = UString(L'0') + res;\r\n      UString name = Prefix + res;\r\n      subStream.StreamSpec = new COutFileStream;\r\n      subStream.Stream = subStream.StreamSpec;\r\n      if(!subStream.StreamSpec->Create(name, false))\r\n        return ::GetLastError();\r\n      {\r\n        // NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);\r\n        TempFiles->Paths.Add(name);\r\n      }\r\n\r\n      subStream.Pos = 0;\r\n      subStream.RealSize = 0;\r\n      subStream.Name = name;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n\r\n    int index = _streamIndex;\r\n    if (index >= Sizes.Size())\r\n      index = Sizes.Size() - 1;\r\n    UInt64 volSize = Sizes[index];\r\n\r\n    if (_offsetPos >= volSize)\r\n    {\r\n      _offsetPos -= volSize;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      // CMyComPtr<IOutStream> outStream;\r\n      // RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(subStream.Stream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, volSize - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if (_offsetPos > subStream.RealSize)\r\n      subStream.RealSize = _offsetPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == volSize)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed == 0 && curSize != 0)\r\n      return E_FAIL;\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  if (newPosition != NULL)\r\n    *newPosition = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::SetSize(Int64 newSize)\r\n{\r\n  if (newSize < 0)\r\n    return E_INVALIDARG;\r\n  int i = 0;\r\n  while (i < Streams.Size())\r\n  {\r\n    CSubStreamInfo &subStream = Streams[i++];\r\n    if ((UInt64)newSize < subStream.RealSize)\r\n    {\r\n      RINOK(subStream.Stream->SetSize(newSize));\r\n      subStream.RealSize = newSize;\r\n      break;\r\n    }\r\n    newSize -= subStream.RealSize;\r\n  }\r\n  while (i < Streams.Size())\r\n  {\r\n    {\r\n      CSubStreamInfo &subStream = Streams.Back();\r\n      subStream.Stream.Release();\r\n      NDirectory::DeleteFileAlways(subStream.Name);\r\n    }\r\n    Streams.DeleteBack();\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  _length = newSize;\r\n  return S_OK;\r\n}\r\n\r\nstatic const wchar_t *kDefaultArchiveType = L\"7z\";\r\nstatic const wchar_t *kSFXExtension =\r\n  #ifdef _WIN32\r\n    L\"exe\";\r\n  #else\r\n    L\"\";\r\n  #endif\r\n\r\nbool CUpdateOptions::Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath)\r\n{\r\n  if (formatIndices.Size() > 1)\r\n    return false;\r\n  int arcTypeIndex = -1;\r\n  if (formatIndices.Size() != 0)\r\n    arcTypeIndex = formatIndices[0];\r\n  if (arcTypeIndex >= 0)\r\n    MethodMode.FormatIndex = arcTypeIndex;\r\n  else\r\n  {\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveName(arcPath);\r\n    if (MethodMode.FormatIndex < 0)\r\n      MethodMode.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArchiveType);\r\n  }\r\n  if (MethodMode.FormatIndex < 0)\r\n    return false;\r\n  const CArcInfoEx &arcInfo = codecs->Formats[MethodMode.FormatIndex];\r\n  if (!arcInfo.UpdateEnabled)\r\n    return false;\r\n  UString typeExt = arcInfo.GetMainExt();\r\n  UString ext = typeExt;\r\n  if (SfxMode)\r\n    ext = kSFXExtension;\r\n  ArchivePath.BaseExtension = ext;\r\n  ArchivePath.VolExtension = typeExt;\r\n  ArchivePath.ParseFromPath(arcPath);\r\n  for (int i = 0; i < Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &uc = Commands[i];\r\n    uc.ArchivePath.BaseExtension = ext;\r\n    uc.ArchivePath.VolExtension = typeExt;\r\n    uc.ArchivePath.ParseFromPath(uc.UserArchivePath);\r\n  }\r\n  return true;\r\n}\r\n\r\n/*\r\nstruct CUpdateProduceCallbackImp: public IUpdateProduceCallback\r\n{\r\n  const CObjectVector<CArcItem> *_arcItems;\r\n  IUpdateCallbackUI *_callback;\r\n  \r\n  CUpdateProduceCallbackImp(const CObjectVector<CArcItem> *a, \r\n      IUpdateCallbackUI *callback): _arcItems(a), _callback(callback) {}\r\n  virtual HRESULT ShowDeleteFile(int arcIndex);\r\n};\r\n\r\nHRESULT CUpdateProduceCallbackImp::ShowDeleteFile(int arcIndex)\r\n{\r\n  return _callback->ShowDeleteFile((*_arcItems)[arcIndex].Name);\r\n}\r\n*/\r\n\r\nstatic HRESULT Compress(\r\n    CCodecs *codecs,\r\n    const CActionSet &actionSet,\r\n    IInArchive *archive,\r\n    const CCompressionMethodMode &compressionMethod,\r\n    CArchivePath &archivePath,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    bool shareForWrite,\r\n    bool stdInMode,\r\n    /* const UString & stdInFileName, */\r\n    bool stdOutMode,\r\n    const CDirItems &dirItems,\r\n    bool sfxMode,\r\n    const UString &sfxModule,\r\n    const CRecordVector<UInt64> &volumesSizes,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI *callback)\r\n{\r\n  CMyComPtr<IOutArchive> outArchive;\r\n  if(archive != NULL)\r\n  {\r\n    CMyComPtr<IInArchive> archive2 = archive;\r\n    HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);\r\n    if(result != S_OK)\r\n      throw kUpdateIsNotSupoorted;\r\n  }\r\n  else\r\n  {\r\n    RINOK(codecs->CreateOutArchive(compressionMethod.FormatIndex, outArchive));\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n  }\r\n  if (outArchive == 0)\r\n    throw kUpdateIsNotSupoorted;\r\n  \r\n  NFileTimeType::EEnum fileTimeType;\r\n  UInt32 value;\r\n  RINOK(outArchive->GetFileTimeType(&value));\r\n\r\n  switch(value)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n    case NFileTimeType::kUnix:\r\n    case NFileTimeType::kDOS:\r\n      fileTimeType = (NFileTimeType::EEnum)value;\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n\r\n  CRecordVector<CUpdatePair2> updatePairs2;\r\n\r\n  {\r\n    CRecordVector<CUpdatePair> updatePairs;\r\n    GetUpdatePairInfoList(dirItems, arcItems, fileTimeType, updatePairs); // must be done only once!!!\r\n    // CUpdateProduceCallbackImp upCallback(&arcItems, callback);\r\n    UpdateProduce(updatePairs, actionSet, updatePairs2, NULL /* &upCallback */);\r\n  }\r\n\r\n  UInt32 numFiles = 0;\r\n  for (int i = 0; i < updatePairs2.Size(); i++)\r\n    if (updatePairs2[i].NewData)\r\n      numFiles++;\r\n  \r\n  RINOK(callback->SetNumFiles(numFiles));\r\n\r\n  \r\n  CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n  CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);\r\n  \r\n  updateCallbackSpec->ShareForWrite = shareForWrite;\r\n  updateCallbackSpec->StdInMode = stdInMode;\r\n  updateCallbackSpec->Callback = callback;\r\n  updateCallbackSpec->DirItems = &dirItems;\r\n  updateCallbackSpec->ArcItems = &arcItems;\r\n  updateCallbackSpec->UpdatePairs = &updatePairs2;\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n\r\n  const UString &archiveName = archivePath.GetFinalPath();\r\n  if (!stdOutMode)\r\n  {\r\n    UString resultPath;\r\n    int pos;\r\n    if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))\r\n      throw 1417161;\r\n    NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));\r\n  }\r\n\r\n  COutFileStream *outStreamSpec = NULL;\r\n  COutMultiVolStream *volStreamSpec = NULL;\r\n\r\n  if (volumesSizes.Size() == 0)\r\n  {\r\n    if (stdOutMode)\r\n      outStream = new CStdOutFileStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      outStream = outStreamSpec;\r\n      bool isOK = false;\r\n      UString realPath;\r\n      for (int i = 0; i < (1 << 16); i++)\r\n      {\r\n        if (archivePath.Temp)\r\n        {\r\n          if (i > 0)\r\n          {\r\n            wchar_t s[32];\r\n            ConvertUInt64ToString(i, s);\r\n            archivePath.TempPostfix = s;\r\n          }\r\n          realPath = archivePath.GetTempPath();\r\n        }\r\n        else\r\n          realPath = archivePath.GetFinalPath();\r\n        if (outStreamSpec->Create(realPath, false))\r\n        {\r\n          tempFiles.Paths.Add(realPath);\r\n          isOK = true;\r\n          break;\r\n        }\r\n        if (::GetLastError() != ERROR_FILE_EXISTS)\r\n          break;\r\n        if (!archivePath.Temp)\r\n          break;\r\n      }\r\n      if (!isOK)\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (stdOutMode)\r\n      return E_FAIL;\r\n    volStreamSpec = new COutMultiVolStream;\r\n    outStream = volStreamSpec;\r\n    volStreamSpec->Sizes = volumesSizes;\r\n    volStreamSpec->Prefix = archivePath.GetFinalPath() + UString(L\".\");\r\n    volStreamSpec->TempFiles = &tempFiles;\r\n    volStreamSpec->Init();\r\n\r\n    /*\r\n    updateCallbackSpec->VolumesSizes = volumesSizes;\r\n    updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;\r\n    if (!archivePath.VolExtension.IsEmpty())\r\n      updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;\r\n    */\r\n  }\r\n\r\n  RINOK(SetProperties(outArchive, compressionMethod.Properties));\r\n\r\n  if (sfxMode)\r\n  {\r\n    CInFileStream *sfxStreamSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> sfxStream(sfxStreamSpec);\r\n    if (!sfxStreamSpec->Open(sfxModule))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"Can't open sfx module\";\r\n      errorInfo.FileName = sfxModule;\r\n      return E_FAIL;\r\n    }\r\n\r\n    CMyComPtr<ISequentialOutStream> sfxOutStream;\r\n    COutFileStream *outStreamSpec = NULL;\r\n    if (volumesSizes.Size() == 0)\r\n      sfxOutStream = outStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      sfxOutStream = outStreamSpec;\r\n      UString realPath = archivePath.GetFinalPath();\r\n      if (!outStreamSpec->Create(realPath, false))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    RINOK(CopyBlock(sfxStream, sfxOutStream));\r\n    if (outStreamSpec)\r\n    {\r\n      RINOK(outStreamSpec->Close());\r\n    }\r\n  }\r\n\r\n  HRESULT result = outArchive->UpdateItems(outStream, updatePairs2.Size(), updateCallback);\r\n  callback->Finilize();\r\n  RINOK(result);\r\n  if (outStreamSpec)\r\n    result = outStreamSpec->Close();\r\n  else if (volStreamSpec)\r\n    result = volStreamSpec->Close();\r\n  return result;\r\n}\r\n\r\nHRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,\r\n    IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    CObjectVector<CArcItem> &arcItems)\r\n{\r\n  arcItems.Clear();\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n  arcItems.Reserve(numItems);\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    CArcItem ai;\r\n\r\n    RINOK(GetArchiveItemPath(archive, i, ai.Name));\r\n    // check it: defaultItemName !!!\r\n    if (ai.Name.IsEmpty())\r\n      ai.Name = defaultItemName;\r\n    RINOK(IsArchiveItemFolder(archive, i, ai.IsDir));\r\n    ai.Censored = censor.CheckPath(ai.Name, !ai.IsDir);\r\n    RINOK(GetArchiveItemFileTime(archive, i, archiveFileInfo.MTime, ai.MTime));\r\n\r\n    {\r\n      CPropVariant prop;\r\n      RINOK(archive->GetProperty(i, kpidSize, &prop));\r\n      ai.SizeDefined = (prop.vt != VT_EMPTY);\r\n      if (ai.SizeDefined)\r\n        ai.Size = ConvertPropVariantToUInt64(prop);\r\n    }\r\n\r\n    {\r\n      CPropVariant prop;\r\n      RINOK(archive->GetProperty(i, kpidTimeType, &prop));\r\n      if (prop.vt == VT_UI4)\r\n      {\r\n        ai.TimeType = (int)(NFileTimeType::EEnum)prop.ulVal;\r\n        switch(ai.TimeType)\r\n        {\r\n          case NFileTimeType::kWindows:\r\n          case NFileTimeType::kUnix:\r\n          case NFileTimeType::kDOS:\r\n            break;\r\n          default:\r\n            return E_FAIL;\r\n        }\r\n      }\r\n    }\r\n\r\n    ai.IndexInServer = i;\r\n    arcItems.Add(ai);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nstatic HRESULT UpdateWithItemLists(\r\n    CCodecs *codecs,\r\n    CUpdateOptions &options,\r\n    IInArchive *archive,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    CDirItems &dirItems,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &command = options.Commands[i];\r\n    if (options.StdOutMode)\r\n    {\r\n      RINOK(callback->StartArchive(0, archive != 0));\r\n    }\r\n    else\r\n    {\r\n      RINOK(callback->StartArchive(command.ArchivePath.GetFinalPath(),\r\n          i == 0 && options.UpdateArchiveItself && archive != 0));\r\n    }\r\n\r\n    RINOK(Compress(\r\n        codecs,\r\n        command.ActionSet, archive,\r\n        options.MethodMode,\r\n        command.ArchivePath,\r\n        arcItems,\r\n        options.OpenShareForWrite,\r\n        options.StdInMode,\r\n        /* options.StdInFileName, */\r\n        options.StdOutMode,\r\n        dirItems,\r\n        options.SfxMode, options.SfxModule,\r\n        options.VolumesSizes,\r\n        tempFiles,\r\n        errorInfo, callback));\r\n\r\n    RINOK(callback->FinishArchive());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _WIN32\r\nclass CCurrentDirRestorer\r\n{\r\n  UString m_CurrentDirectory;\r\npublic:\r\n  CCurrentDirRestorer()\r\n    { NFile::NDirectory::MyGetCurrentDirectory(m_CurrentDirectory); }\r\n  ~CCurrentDirRestorer()\r\n    { RestoreDirectory();}\r\n  bool RestoreDirectory()\r\n    { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(m_CurrentDirectory)); }\r\n};\r\n#endif\r\n\r\nstruct CEnumDirItemUpdateCallback: public IEnumDirItemCallback\r\n{\r\n  IUpdateCallbackUI2 *Callback;\r\n  HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path)\r\n  {\r\n    return Callback->ScanProgress(numFolders, numFiles, path);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\ntypedef ULONG (FAR PASCAL MY_MAPISENDDOCUMENTS)(\r\n  ULONG_PTR ulUIParam,\r\n  LPSTR lpszDelimChar,\r\n  LPSTR lpszFilePaths,\r\n  LPSTR lpszFileNames,\r\n  ULONG ulReserved\r\n);\r\ntypedef MY_MAPISENDDOCUMENTS FAR *MY_LPMAPISENDDOCUMENTS;\r\n#endif\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor,\r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  if (options.StdOutMode && options.EMailMode)\r\n    return E_FAIL;\r\n\r\n  if (options.VolumesSizes.Size() > 0 && (options.EMailMode || options.SfxMode))\r\n    return E_NOTIMPL;\r\n\r\n  if (options.SfxMode)\r\n  {\r\n    CProperty property;\r\n    property.Name = L\"rsfx\";\r\n    property.Value = L\"on\";\r\n    options.MethodMode.Properties.Add(property);\r\n    if (options.SfxModule.IsEmpty())\r\n    {\r\n      errorInfo.Message = L\"sfx file is not specified\";\r\n      return E_FAIL;\r\n    }\r\n    UString name = options.SfxModule;\r\n    if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))\r\n    {\r\n      errorInfo.Message = L\"can't find specified sfx module\";\r\n      return E_FAIL;\r\n    }\r\n  }\r\n\r\n  const UString archiveName = options.ArchivePath.GetFinalPath();\r\n\r\n  UString defaultItemName;\r\n  NFind::CFileInfoW archiveFileInfo;\r\n\r\n  CArchiveLink archiveLink;\r\n  IInArchive *archive = 0;\r\n  if (NFind::FindFile(archiveName, archiveFileInfo))\r\n  {\r\n    if (archiveFileInfo.IsDir())\r\n      throw \"there is no such archive\";\r\n    if (options.VolumesSizes.Size() > 0)\r\n      return E_NOTIMPL;\r\n    CIntVector formatIndices;\r\n    if (options.MethodMode.FormatIndex >= 0)\r\n      formatIndices.Add(options.MethodMode.FormatIndex);\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, openCallback);\r\n    if (result == E_ABORT)\r\n      return result;\r\n    RINOK(callback->OpenResult(archiveName, result));\r\n    RINOK(result);\r\n    if (archiveLink.VolumePaths.Size() > 1)\r\n    {\r\n      errorInfo.SystemError = (DWORD)E_NOTIMPL;\r\n      errorInfo.Message = L\"Updating for multivolume archives is not implemented\";\r\n      return E_NOTIMPL;\r\n    }\r\n    archive = archiveLink.GetArchive();\r\n    defaultItemName = archiveLink.GetDefaultItemName();\r\n  }\r\n  else\r\n  {\r\n    /*\r\n    if (archiveType.IsEmpty())\r\n      throw \"type of archive is not specified\";\r\n    */\r\n  }\r\n\r\n  CDirItems dirItems;\r\n  if (options.StdInMode)\r\n  {\r\n    CDirItem di;\r\n    di.Name = options.StdInFileName;\r\n    di.Size = (UInt64)(Int64)-1;\r\n    di.Attrib = 0;\r\n    NTime::GetCurUtcFileTime(di.MTime);\r\n    di.CTime = di.ATime = di.MTime;\r\n    dirItems.Items.Add(di);\r\n  }\r\n  else\r\n  {\r\n    bool needScanning = false;\r\n    for(int i = 0; i < options.Commands.Size(); i++)\r\n      if (options.Commands[i].ActionSet.NeedScanning())\r\n        needScanning = true;\r\n    if (needScanning)\r\n    {\r\n      CEnumDirItemUpdateCallback enumCallback;\r\n      enumCallback.Callback = callback;\r\n      RINOK(callback->StartScanning());\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(censor, dirItems, &enumCallback, errorPaths, errorCodes);\r\n      for (int i = 0; i < errorPaths.Size(); i++)\r\n      {\r\n        RINOK(callback->CanNotFindError(errorPaths[i], errorCodes[i]));\r\n      }\r\n      if (res != S_OK)\r\n      {\r\n        if (res != E_ABORT)\r\n          errorInfo.Message = L\"Scanning error\";\r\n        // errorInfo.FileName = errorPath;\r\n        return res;\r\n      }\r\n      RINOK(callback->FinishScanning());\r\n    }\r\n  }\r\n\r\n  UString tempDirPrefix;\r\n  bool usesTempDir = false;\r\n  \r\n  #ifdef _WIN32\r\n  NDirectory::CTempDirectoryW tempDirectory;\r\n  if (options.EMailMode && options.EMailRemoveAfter)\r\n  {\r\n    tempDirectory.Create(kTempFolderPrefix);\r\n    tempDirPrefix = tempDirectory.GetPath();\r\n    NormalizeDirPathPrefix(tempDirPrefix);\r\n    usesTempDir = true;\r\n  }\r\n  #endif\r\n\r\n  CTempFiles tempFiles;\r\n\r\n  bool createTempFile = false;\r\n  if(!options.StdOutMode && options.UpdateArchiveItself)\r\n  {\r\n    CArchivePath &ap = options.Commands[0].ArchivePath;\r\n    ap = options.ArchivePath;\r\n    // if ((archive != 0 && !usesTempDir) || !options.WorkingDir.IsEmpty())\r\n    if ((archive != 0 || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)\r\n    {\r\n      createTempFile = true;\r\n      ap.Temp = true;\r\n      if (!options.WorkingDir.IsEmpty())\r\n      {\r\n        ap.TempPrefix = options.WorkingDir;\r\n        NormalizeDirPathPrefix(ap.TempPrefix);\r\n      }\r\n    }\r\n  }\r\n\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CArchivePath &ap = options.Commands[i].ArchivePath;\r\n    if (usesTempDir)\r\n    {\r\n      // Check it\r\n      ap.Prefix = tempDirPrefix;\r\n      // ap.Temp = true;\r\n      // ap.TempPrefix = tempDirPrefix;\r\n    }\r\n    if (i > 0 || !createTempFile)\r\n    {\r\n      const UString &path = ap.GetFinalPath();\r\n      if (NFind::DoesFileExist(path))\r\n      {\r\n        errorInfo.SystemError = 0;\r\n        errorInfo.Message = L\"File already exists\";\r\n        errorInfo.FileName = path;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n\r\n  CObjectVector<CArcItem> arcItems;\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(EnumerateInArchiveItems(censor,\r\n        archive, defaultItemName, archiveFileInfo, arcItems));\r\n  }\r\n\r\n  RINOK(UpdateWithItemLists(codecs, options, archive, arcItems, dirItems,\r\n      tempFiles, errorInfo, callback));\r\n\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(archiveLink.Close());\r\n    archiveLink.Release();\r\n  }\r\n\r\n  tempFiles.Paths.Clear();\r\n  if(createTempFile)\r\n  {\r\n    try\r\n    {\r\n      CArchivePath &ap = options.Commands[0].ArchivePath;\r\n      const UString &tempPath = ap.GetTempPath();\r\n      if (archive != NULL)\r\n        if (!NDirectory::DeleteFileAlways(archiveName))\r\n        {\r\n          errorInfo.SystemError = ::GetLastError();\r\n          errorInfo.Message = L\"delete file error\";\r\n          errorInfo.FileName = archiveName;\r\n          return E_FAIL;\r\n        }\r\n      if (!NDirectory::MyMoveFile(tempPath, archiveName))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.Message = L\"move file error\";\r\n        errorInfo.FileName = tempPath;\r\n        errorInfo.FileName2 = archiveName;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      throw;\r\n    }\r\n  }\r\n\r\n  #ifdef _WIN32\r\n  if (options.EMailMode)\r\n  {\r\n    NDLL::CLibrary mapiLib;\r\n    if (!mapiLib.Load(TEXT(\"Mapi32.dll\")))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not load Mapi32.dll\";\r\n      return E_FAIL;\r\n    }\r\n    MY_LPMAPISENDDOCUMENTS fnSend = (MY_LPMAPISENDDOCUMENTS)\r\n        mapiLib.GetProcAddress(\"MAPISendDocuments\");\r\n    if (fnSend == 0)\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not find MAPISendDocuments function\";\r\n      return E_FAIL;\r\n    }\r\n    UStringVector fullPaths;\r\n    int i;\r\n    for(i = 0; i < options.Commands.Size(); i++)\r\n    {\r\n      CArchivePath &ap = options.Commands[i].ArchivePath;\r\n      UString arcPath;\r\n      if(!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        return E_FAIL;\r\n      }\r\n      fullPaths.Add(arcPath);\r\n    }\r\n    CCurrentDirRestorer curDirRestorer;\r\n    for(i = 0; i < fullPaths.Size(); i++)\r\n    {\r\n      UString arcPath = fullPaths[i];\r\n      UString fileName = ExtractFileNameFromPath(arcPath);\r\n      AString path = GetAnsiString(arcPath);\r\n      AString name = GetAnsiString(fileName);\r\n      // Warning!!! MAPISendDocuments function changes Current directory\r\n      fnSend(0, \";\", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0);\r\n    }\r\n  }\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/Update.h",
    "content": "// Update.h\r\n\r\n#ifndef __UPDATE_H\r\n#define __UPDATE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"Property.h\"\r\n#include \"LoadCodecs.h\"\r\n\r\nstruct CArchivePath\r\n{\r\n  UString Prefix;   // path(folder) prefix including slash\r\n  UString Name; // base name\r\n  UString BaseExtension; // archive type extension or \"exe\" extension\r\n  UString VolExtension;  // archive type extension for volumes\r\n\r\n  bool Temp;\r\n  UString TempPrefix;  // path(folder) for temp location\r\n  UString TempPostfix;\r\n\r\n  CArchivePath(): Temp(false) {};\r\n  \r\n  void ParseFromPath(const UString &path)\r\n  {\r\n    SplitPathToParts(path, Prefix, Name);\r\n    if (Name.IsEmpty())\r\n      return;\r\n    int dotPos = Name.ReverseFind(L'.');\r\n    if (dotPos <= 0)\r\n      return;\r\n    if (dotPos == Name.Length() - 1)\r\n    {\r\n      Name = Name.Left(dotPos);\r\n      BaseExtension.Empty();\r\n      return;\r\n    }\r\n    if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0)\r\n    {\r\n      BaseExtension = Name.Mid(dotPos + 1);\r\n      Name = Name.Left(dotPos);\r\n    }\r\n    else\r\n      BaseExtension.Empty();\r\n  }\r\n\r\n  UString GetPathWithoutExt() const\r\n  {\r\n    return Prefix + Name;\r\n  }\r\n\r\n  UString GetFinalPath() const\r\n  {\r\n    UString path = GetPathWithoutExt();\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    return path;\r\n  }\r\n\r\n  \r\n  UString GetTempPath() const\r\n  {\r\n    UString path = TempPrefix + Name;\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    path += L\".tmp\";\r\n    path += TempPostfix;\r\n    return path;\r\n  }\r\n};\r\n\r\nstruct CUpdateArchiveCommand\r\n{\r\n  UString UserArchivePath;\r\n  CArchivePath ArchivePath;\r\n  NUpdateArchive::CActionSet ActionSet;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  int FormatIndex;\r\n  CObjectVector<CProperty> Properties;\r\n  CCompressionMethodMode(): FormatIndex(-1) {}\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  CCompressionMethodMode MethodMode;\r\n\r\n  CObjectVector<CUpdateArchiveCommand> Commands;\r\n  bool UpdateArchiveItself;\r\n  CArchivePath ArchivePath;\r\n  \r\n  bool SfxMode;\r\n  UString SfxModule;\r\n  \r\n  bool OpenShareForWrite;\r\n\r\n  bool StdInMode;\r\n  UString StdInFileName;\r\n  bool StdOutMode;\r\n  \r\n  bool EMailMode;\r\n  bool EMailRemoveAfter;\r\n  UString EMailAddress;\r\n\r\n  UString WorkingDir;\r\n\r\n  bool Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath);\r\n\r\n  CUpdateOptions():\r\n    UpdateArchiveItself(true),\r\n    SfxMode(false),\r\n    StdInMode(false),\r\n    StdOutMode(false),\r\n    EMailMode(false),\r\n    EMailRemoveAfter(false),\r\n    OpenShareForWrite(false)\r\n      {};\r\n  CRecordVector<UInt64> VolumesSizes;\r\n};\r\n\r\nstruct CErrorInfo\r\n{\r\n  DWORD SystemError;\r\n  UString FileName;\r\n  UString FileName2;\r\n  UString Message;\r\n  // UStringVector ErrorPaths;\r\n  // CRecordVector<DWORD> ErrorCodes;\r\n  CErrorInfo(): SystemError(0) {};\r\n};\r\n\r\nstruct CUpdateErrorInfo: public CErrorInfo\r\n{\r\n};\r\n\r\n#define INTERFACE_IUpdateCallbackUI2(x) \\\r\n  INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \\\r\n  virtual HRESULT StartScanning() x; \\\r\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) x; \\\r\n  virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT FinishScanning() x; \\\r\n  virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \\\r\n  virtual HRESULT FinishArchive() x; \\\r\n\r\nstruct IUpdateCallbackUI2: public IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI2(=0)\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor,\r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/UpdateAction.cpp",
    "content": "// UpdateAction.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n\r\nnamespace NUpdateArchive {\r\n\r\nconst CActionSet kAddActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kUpdateActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kFreshActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kSynchronizeActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n};\r\n\r\nconst CActionSet kDeleteActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/UpdateAction.h",
    "content": "// UpdateAction.h\r\n\r\n#ifndef __UPDATE_ACTION_H\r\n#define __UPDATE_ACTION_H\r\n\r\nnamespace NUpdateArchive {\r\n\r\n  namespace NPairState\r\n  {\r\n    const int kNumValues = 7;\r\n    enum EEnum\r\n    {\r\n      kNotMasked = 0,\r\n      kOnlyInArchive,\r\n      kOnlyOnDisk,\r\n      kNewInArchive,\r\n      kOldInArchive,\r\n      kSameFiles,\r\n      kUnknowNewerFiles\r\n    };\r\n  }\r\n  namespace NPairAction\r\n  {\r\n    enum EEnum\r\n    {\r\n      kIgnore = 0,\r\n      kCopy,\r\n      kCompress,\r\n      kCompressAsAnti\r\n    };\r\n  }\r\n  struct CActionSet\r\n  {\r\n    NPairAction::EEnum StateActions[NPairState::kNumValues];\r\n    bool NeedScanning() const\r\n    {\r\n      int i;\r\n      for (i = 0; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] == NPairAction::kCompress)\r\n          return true;\r\n      for (i = 1; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] != NPairAction::kIgnore)\r\n          return true;\r\n      return false;\r\n    }\r\n  };\r\n  extern const CActionSet kAddActionSet;\r\n  extern const CActionSet kUpdateActionSet;\r\n  extern const CActionSet kFreshActionSet;\r\n  extern const CActionSet kSynchronizeActionSet;\r\n  extern const CActionSet kDeleteActionSet;\r\n};\r\n\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp",
    "content": "// UpdateCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCArchiveUpdateCallback::CArchiveUpdateCallback():\r\n  Callback(0),\r\n  ShareForWrite(false),\r\n  StdInMode(false),\r\n  DirItems(0),\r\n  ArcItems(0),\r\n  UpdatePairs(0),\r\n  NewNames(0)\r\n  {}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetTotal(size);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\n\r\n/*\r\nSTATPROPSTG kProperties[] =\r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidIsDir, VT_BOOL},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidCTime, VT_FILETIME},\r\n  { NULL, kpidATime, VT_FILETIME},\r\n  { NULL, kpidMTime, VT_FILETIME},\r\n  { NULL, kpidAttrib, VT_UI4},\r\n  { NULL, kpidIsAnti, VT_BOOL}\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)\r\n{\r\n  return CStatPropEnumerator::CreateEnumerator(kProperties, sizeof(kProperties) / sizeof(kProperties[0]), enumerator);\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,\r\n      Int32 *newData, Int32 *newProps, UInt32 *indexInArchive)\r\n{\r\n  COM_TRY_BEGIN\r\n  RINOK(Callback->CheckBreak());\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  if (newData != NULL) *newData = BoolToInt(up.NewData);\r\n  if (newProps != NULL) *newProps = BoolToInt(up.NewProps);\r\n  if (indexInArchive != NULL)\r\n  {\r\n    *indexInArchive = (UInt32)-1;\r\n    if (up.ExistInArchive())\r\n      *indexInArchive = (ArcItems == 0) ? up.ArcIndex : (*ArcItems)[up.ArcIndex].IndexInServer;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    prop = up.IsAnti;\r\n    prop.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  if (up.IsAnti)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidIsDir:\r\n      case kpidPath:\r\n        break;\r\n      case kpidSize:\r\n        prop = (UInt64)0;\r\n        prop.Detach(value);\r\n        return S_OK;\r\n      default:\r\n        prop.Detach(value);\r\n        return S_OK;\r\n    }\r\n  }\r\n  \r\n  if (up.ExistOnDisk())\r\n  {\r\n    const CDirItem &di = DirItems->Items[up.DirIndex];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:  prop = DirItems->GetLogPath(up.DirIndex); break;\r\n      case kpidIsDir:  prop = di.IsDir(); break;\r\n      case kpidSize:  prop = di.Size; break;\r\n      case kpidAttrib:  prop = di.Attrib; break;\r\n      case kpidCTime:  prop = di.CTime; break;\r\n      case kpidATime:  prop = di.ATime; break;\r\n      case kpidMTime:  prop = di.MTime; break;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (propID == kpidPath)\r\n    {\r\n      if (up.NewNameIndex >= 0)\r\n      {\r\n        prop = (*NewNames)[up.NewNameIndex];\r\n        prop.Detach(value);\r\n        return S_OK;\r\n      }\r\n    }\r\n    if (up.ExistInArchive() && Archive)\r\n    {\r\n      UInt32 indexInArchive;\r\n      if (ArcItems == 0)\r\n        indexInArchive = up.ArcIndex;\r\n      else\r\n        indexInArchive = (*ArcItems)[up.ArcIndex].IndexInServer;\r\n      return Archive->GetProperty(indexInArchive, propID, value);\r\n    }\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  if (!up.NewData)\r\n    return E_FAIL;\r\n  \r\n  RINOK(Callback->CheckBreak());\r\n  RINOK(Callback->Finilize());\r\n\r\n  if (up.IsAnti)\r\n  {\r\n    return Callback->GetStream((*ArcItems)[up.ArcIndex].Name, true);\r\n  }\r\n  const CDirItem &di = DirItems->Items[up.DirIndex];\r\n  RINOK(Callback->GetStream(DirItems->GetLogPath(up.DirIndex), false));\r\n \r\n  if (di.IsDir())\r\n    return S_OK;\r\n\r\n  if (StdInMode)\r\n  {\r\n    CStdInFileStream *inStreamSpec = new CStdInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  else\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    const UString path = DirItems->GetPhyPath(up.DirIndex);\r\n    if (!inStreamSpec->OpenShared(path, ShareForWrite))\r\n    {\r\n      return Callback->OpenFileError(path, ::GetLastError());\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetOperationResult(operationResult);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if (!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->CryptoGetTextPassword2(passwordIsDefined, password);\r\n  COM_TRY_END\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/UpdateCallback.h",
    "content": "// UpdateCallback.h\r\n\r\n#ifndef __UPDATECALLBACK_H\r\n#define __UPDATECALLBACK_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/UpdatePair.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#define INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT SetTotal(UInt64 size) x; \\\r\n  virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \\\r\n  virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x; \\\r\n  virtual HRESULT CheckBreak() x; \\\r\n  virtual HRESULT Finilize() x; \\\r\n  virtual HRESULT SetNumFiles(UInt64 numFiles) x; \\\r\n  virtual HRESULT GetStream(const wchar_t *name, bool isAnti) x; \\\r\n  virtual HRESULT OpenFileError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT SetOperationResult(Int32 operationResult) x; \\\r\n  virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x; \\\r\n  // virtual HRESULT ShowDeleteFile(const wchar_t *name) x; \\\r\n  // virtual HRESULT CloseProgress() { return S_OK; };\r\n\r\nstruct IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI(=0)\r\n};\r\n\r\nclass CArchiveUpdateCallback:\r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveUpdateCallback2,\r\n      ICryptoGetTextPassword2,\r\n      ICompressProgressInfo)\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  INTERFACE_IArchiveUpdateCallback2(;)\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  IUpdateCallbackUI *Callback;\r\n\r\n  bool ShareForWrite;\r\n  bool StdInMode;\r\n  const CDirItems *DirItems;\r\n  const CObjectVector<CArcItem> *ArcItems;\r\n  const CRecordVector<CUpdatePair2> *UpdatePairs;\r\n  const UStringVector *NewNames;\r\n  CMyComPtr<IInArchive> Archive;\r\n\r\n  CArchiveUpdateCallback();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/UpdatePair.cpp",
    "content": "// UpdatePair.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <time.h>\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"UpdatePair.h\"\r\n#include \"SortUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nstatic int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time1, const FILETIME &time2)\r\n{\r\n  switch(fileTimeType)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n      return ::CompareFileTime(&time1, &time2);\r\n    case NFileTimeType::kUnix:\r\n      {\r\n        UInt32 unixTime1, unixTime2;\r\n        FileTimeToUnixTime(time1, unixTime1);\r\n        FileTimeToUnixTime(time2, unixTime2);\r\n        return MyCompare(unixTime1, unixTime2);\r\n      }\r\n    case NFileTimeType::kDOS:\r\n      {\r\n        UInt32 dosTime1, dosTime2;\r\n        FileTimeToDosTime(time1, dosTime1);\r\n        FileTimeToDosTime(time2, dosTime2);\r\n        return MyCompare(dosTime1, dosTime2);\r\n      }\r\n  }\r\n  throw 4191618;\r\n}\r\n\r\nstatic const wchar_t *kDuplicateFileNameMessage = L\"Duplicate filename:\";\r\nstatic const wchar_t *kNotCensoredCollisionMessaged = L\"Internal file name collision (file on disk, file in archive):\";\r\n\r\nstatic void ThrowError(const UString &message, const UString &s1, const UString &s2)\r\n{\r\n  UString m = message;\r\n  m += L'\\n';\r\n  m += s1;\r\n  m += L'\\n';\r\n  m += s2;\r\n  throw m;\r\n}\r\n\r\nstatic void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)\r\n{\r\n  for(int i = 0; i + 1 < indices.Size(); i++)\r\n    if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)\r\n      ThrowError(kDuplicateFileNameMessage, strings[indices[i]], strings[indices[i + 1]]);\r\n}\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CDirItems &dirItems,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CRecordVector<CUpdatePair> &updatePairs)\r\n{\r\n  CIntVector dirIndices, arcIndices;\r\n  \r\n  int numDirItems = dirItems.Items.Size();\r\n  int numArcItems = arcItems.Size();\r\n  \r\n  \r\n  {\r\n    UStringVector arcNames;\r\n    arcNames.Reserve(numArcItems);\r\n    for (int i = 0; i < numArcItems; i++)\r\n      arcNames.Add(arcItems[i].Name);\r\n    SortFileNames(arcNames, arcIndices);\r\n    TestDuplicateString(arcNames, arcIndices);\r\n  }\r\n\r\n  UStringVector dirNames;\r\n  {\r\n    dirNames.Reserve(numDirItems);\r\n    for (int i = 0; i < numDirItems; i++)\r\n      dirNames.Add(dirItems.GetLogPath(i));\r\n    SortFileNames(dirNames, dirIndices);\r\n    TestDuplicateString(dirNames, dirIndices);\r\n  }\r\n  \r\n  int dirIndex = 0, arcIndex = 0;\r\n  while (dirIndex < numDirItems && arcIndex < numArcItems)\r\n  {\r\n    CUpdatePair pair;\r\n    int dirIndex2 = dirIndices[dirIndex];\r\n    int arcIndex2 = arcIndices[arcIndex];\r\n    const CDirItem &di = dirItems.Items[dirIndex2];\r\n    const CArcItem &ai = arcItems[arcIndex2];\r\n    int compareResult = CompareFileNames(dirNames[dirIndex2], ai.Name);\r\n    if (compareResult < 0)\r\n    {\r\n      pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n      pair.DirIndex = dirIndex2;\r\n      dirIndex++;\r\n    }\r\n    else if (compareResult > 0)\r\n    {\r\n      pair.State = ai.Censored ?\r\n          NUpdateArchive::NPairState::kOnlyInArchive:\r\n          NUpdateArchive::NPairState::kNotMasked;\r\n      pair.ArcIndex = arcIndex2;\r\n      arcIndex++;\r\n    }\r\n    else\r\n    {\r\n      if (!ai.Censored)\r\n        ThrowError(kNotCensoredCollisionMessaged, dirNames[dirIndex2], ai.Name);\r\n      pair.DirIndex = dirIndex2;\r\n      pair.ArcIndex = arcIndex2;\r\n      switch (MyCompareTime(\r\n          ai.TimeType != - 1 ? (NFileTimeType::EEnum)ai.TimeType : fileTimeType,\r\n          di.MTime, ai.MTime))\r\n      {\r\n        case -1: pair.State = NUpdateArchive::NPairState::kNewInArchive; break;\r\n        case 1:  pair.State = NUpdateArchive::NPairState::kOldInArchive; break;\r\n        default:\r\n          if (ai.SizeDefined)\r\n            if (di.Size != ai.Size)\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n            else\r\n              pair.State = NUpdateArchive::NPairState::kSameFiles;\r\n          else\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n      }\r\n      dirIndex++;\r\n      arcIndex++;\r\n    }\r\n    updatePairs.Add(pair);\r\n  }\r\n\r\n  for (; dirIndex < numDirItems; dirIndex++)\r\n  {\r\n    CUpdatePair pair;\r\n    pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n    pair.DirIndex = dirIndices[dirIndex];\r\n    updatePairs.Add(pair);\r\n  }\r\n  \r\n  for (; arcIndex < numArcItems; arcIndex++)\r\n  {\r\n    CUpdatePair pair;\r\n    int arcIndex2 = arcIndices[arcIndex];\r\n    pair.State = arcItems[arcIndex2].Censored ?\r\n        NUpdateArchive::NPairState::kOnlyInArchive:\r\n        NUpdateArchive::NPairState::kNotMasked;\r\n    pair.ArcIndex = arcIndex2;\r\n    updatePairs.Add(pair);\r\n  }\r\n\r\n  updatePairs.ReserveDown();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/UpdatePair.h",
    "content": "// UpdatePair.h\r\n\r\n#ifndef __UPDATE_PAIR_H\r\n#define __UPDATE_PAIR_H\r\n\r\n#include \"DirItem.h\"\r\n#include \"UpdateAction.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CUpdatePair\r\n{\r\n  NUpdateArchive::NPairState::EEnum State;\r\n  int ArcIndex;\r\n  int DirIndex;\r\n  CUpdatePair(): ArcIndex(-1), DirIndex(-1) {}\r\n};\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CDirItems &dirItems,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CRecordVector<CUpdatePair> &updatePairs);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp",
    "content": "// UpdateProduce.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateProduce.h\"\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic const char *kUpdateActionSetCollision = \"Internal collision in update action set\";\r\n\r\nvoid UpdateProduce(\r\n    const CRecordVector<CUpdatePair> &updatePairs,\r\n    const CActionSet &actionSet,\r\n    CRecordVector<CUpdatePair2> &operationChain,\r\n    IUpdateProduceCallback *callback)\r\n{\r\n  for (int i = 0; i < updatePairs.Size(); i++)\r\n  {\r\n    const CUpdatePair &pair = updatePairs[i];\r\n\r\n    CUpdatePair2 up2;\r\n    up2.IsAnti = false;\r\n    up2.DirIndex = pair.DirIndex;\r\n    up2.ArcIndex = pair.ArcIndex;\r\n    up2.NewData = up2.NewProps = true;\r\n    \r\n    switch(actionSet.StateActions[pair.State])\r\n    {\r\n      case NPairAction::kIgnore:\r\n        /*\r\n        if (pair.State != NPairState::kOnlyOnDisk)\r\n          IgnoreArchiveItem(m_ArchiveItems[pair.ArcIndex]);\r\n        // cout << \"deleting\";\r\n        */\r\n        if (callback)\r\n          callback->ShowDeleteFile(pair.ArcIndex);\r\n        continue;\r\n\r\n      case NPairAction::kCopy:\r\n        if (pair.State == NPairState::kOnlyOnDisk)\r\n          throw kUpdateActionSetCollision;\r\n        up2.NewData = up2.NewProps = false;\r\n        break;\r\n      \r\n      case NPairAction::kCompress:\r\n        if (pair.State == NPairState::kOnlyInArchive ||\r\n            pair.State == NPairState::kNotMasked)\r\n          throw kUpdateActionSetCollision;\r\n        break;\r\n      \r\n      case NPairAction::kCompressAsAnti:\r\n        up2.IsAnti = true;\r\n        break;\r\n    }\r\n    operationChain.Add(up2);\r\n  }\r\n  operationChain.ReserveDown();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/UpdateProduce.h",
    "content": "// UpdateProduce.h\r\n\r\n#ifndef __UPDATE_PRODUCE_H\r\n#define __UPDATE_PRODUCE_H\r\n\r\n#include \"UpdatePair.h\"\r\n\r\nstruct CUpdatePair2\r\n{\r\n  bool NewData;\r\n  bool NewProps;\r\n  bool IsAnti;\r\n  \r\n  int DirIndex;\r\n  int ArcIndex;\r\n  int NewNameIndex;\r\n\r\n  bool ExistOnDisk() const { return DirIndex != -1; }\r\n  bool ExistInArchive() const { return ArcIndex != -1; }\r\n\r\n  CUpdatePair2(): IsAnti(false), DirIndex(-1), ArcIndex(-1), NewNameIndex(-1) {}\r\n};\r\n\r\nstruct IUpdateProduceCallback\r\n{\r\n  virtual HRESULT ShowDeleteFile(int arcIndex) = 0;\r\n};\r\n\r\nvoid UpdateProduce(\r\n    const CRecordVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CRecordVector<CUpdatePair2> &operationChain,\r\n    IUpdateProduceCallback *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/WorkDir.cpp",
    "content": "// WorkDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"WorkDir.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nstatic inline UINT GetCurrentCodePage()\r\n  { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)\r\n{\r\n  NWorkDir::NMode::EEnum mode = workDirInfo.Mode;\r\n  if (workDirInfo.ForRemovableOnly)\r\n  {\r\n    mode = NWorkDir::NMode::kCurrent;\r\n    UString prefix = path.Left(3);\r\n    if (prefix[1] == L':' && prefix[2] == L'\\\\')\r\n    {\r\n      UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));\r\n      if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)\r\n        mode = workDirInfo.Mode;\r\n    }\r\n    /*\r\n    CParsedPath parsedPath;\r\n    parsedPath.ParsePath(archiveName);\r\n    UINT driveType = GetDriveType(parsedPath.Prefix);\r\n    if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))\r\n      mode = NZipSettings::NWorkDir::NMode::kCurrent;\r\n    */\r\n  }\r\n  switch(mode)\r\n  {\r\n    case NWorkDir::NMode::kCurrent:\r\n    {\r\n      return ExtractDirPrefixFromPath(path);\r\n    }\r\n    case NWorkDir::NMode::kSpecified:\r\n    {\r\n      UString tempDir = workDirInfo.Path;\r\n      NormalizeDirPathPrefix(tempDir);\r\n      return tempDir;\r\n    }\r\n    default:\r\n    {\r\n      UString tempDir;\r\n      if(!NFile::NDirectory::MyGetTempPath(tempDir))\r\n        throw 141717;\r\n      return tempDir;\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/WorkDir.h",
    "content": "// WorkDir.h\r\n\r\n#ifndef __WORKDIR_H\r\n#define __WORKDIR_H\r\n\r\n#include \"ZipRegistry.h\"\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Common/ZipRegistry.h",
    "content": "// ZipRegistry.h\r\n\r\n#ifndef __ZIPREGISTRY_H\r\n#define __ZIPREGISTRY_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"ExtractMode.h\"\r\n\r\nnamespace NExtract\r\n{\r\n  struct CInfo\r\n  {\r\n    NPathMode::EEnum PathMode;\r\n    NOverwriteMode::EEnum OverwriteMode;\r\n    UStringVector Paths;\r\n    bool ShowPassword;\r\n  };\r\n}\r\n\r\nnamespace NCompression {\r\n  \r\n  struct CFormatOptions\r\n  {\r\n    CSysString FormatID;\r\n    UString Options;\r\n    UString Method;\r\n    UString EncryptionMethod;\r\n    UInt32 Level;\r\n    UInt32 Dictionary;\r\n    UInt32 Order;\r\n    UInt32 BlockLogSize;\r\n    UInt32 NumThreads;\r\n    void ResetForLevelChange()\r\n    {\r\n      BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1);\r\n      Method.Empty();\r\n      // EncryptionMethod.Empty();\r\n      // Options.Empty();\r\n    }\r\n    CFormatOptions() { ResetForLevelChange(); }\r\n  };\r\n\r\n  struct CInfo\r\n  {\r\n    UStringVector HistoryArchives;\r\n    UInt32 Level;\r\n    UString ArchiveType;\r\n\r\n    CObjectVector<CFormatOptions> FormatOptionsVector;\r\n\r\n    bool ShowPassword;\r\n    bool EncryptHeaders;\r\n  };\r\n}\r\n\r\nnamespace NWorkDir{\r\n  \r\n  namespace NMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kSystem,\r\n      kCurrent,\r\n      kSpecified\r\n    };\r\n  }\r\n  struct CInfo\r\n  {\r\n    NMode::EEnum Mode;\r\n    UString Path;\r\n    bool ForRemovableOnly;\r\n    void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }\r\n    void SetDefault()\r\n    {\r\n      Mode = NMode::kSystem;\r\n      Path.Empty();\r\n      SetForRemovableOnlyDefault();\r\n    }\r\n  };\r\n}\r\n\r\nvoid SaveExtractionInfo(const NExtract::CInfo &info);\r\nvoid ReadExtractionInfo(NExtract::CInfo &info);\r\n\r\nvoid SaveCompressionInfo(const NCompression::CInfo &info);\r\nvoid ReadCompressionInfo(NCompression::CInfo &info);\r\n\r\nvoid SaveWorkDirInfo(const NWorkDir::CInfo &info);\r\nvoid ReadWorkDirInfo(NWorkDir::CInfo &info);\r\n\r\nvoid SaveCascadedMenu(bool enabled);\r\nbool ReadCascadedMenu();\r\n\r\nvoid SaveContextMenuStatus(UInt32 value);\r\nbool ReadContextMenuStatus(UInt32 &value);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/ConsoleClose.cpp",
    "content": "// ConsoleClose.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n\r\nstatic int g_BreakCounter = 0;\r\nstatic const int kBreakAbortThreshold = 2;\r\n\r\nnamespace NConsoleClose {\r\n\r\nstatic BOOL WINAPI HandlerRoutine(DWORD ctrlType)\r\n{\r\n  if (ctrlType == CTRL_LOGOFF_EVENT)\r\n  {\r\n    // printf(\"\\nCTRL_LOGOFF_EVENT\\n\");\r\n    return TRUE;\r\n  }\r\n\r\n  g_BreakCounter++;\r\n  if (g_BreakCounter < kBreakAbortThreshold)\r\n    return TRUE;\r\n  return FALSE;\r\n  /*\r\n  switch(ctrlType)\r\n  {\r\n    case CTRL_C_EVENT:\r\n    case CTRL_BREAK_EVENT:\r\n      if (g_BreakCounter < kBreakAbortThreshold)\r\n      return TRUE;\r\n  }\r\n  return FALSE;\r\n  */\r\n}\r\n\r\nbool TestBreakSignal()\r\n{\r\n  /*\r\n  if (g_BreakCounter > 0)\r\n    return true;\r\n  */\r\n  return (g_BreakCounter > 0);\r\n}\r\n\r\nvoid CheckCtrlBreak()\r\n{\r\n  if (TestBreakSignal())\r\n    throw CCtrlBreakException();\r\n}\r\n\r\nCCtrlHandlerSetter::CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\nCCtrlHandlerSetter::~CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/ConsoleClose.h",
    "content": "// ConsoleCloseUtils.h\r\n\r\n#ifndef __CONSOLECLOSEUTILS_H\r\n#define __CONSOLECLOSEUTILS_H\r\n\r\nnamespace NConsoleClose {\r\n\r\nbool TestBreakSignal();\r\n\r\nclass CCtrlHandlerSetter\r\n{\r\npublic:\r\n  CCtrlHandlerSetter();\r\n  virtual ~CCtrlHandlerSetter();\r\n};\r\n\r\nclass CCtrlBreakException\r\n{};\r\n\r\nvoid CheckCtrlBreak();\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UserInputUtils.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Error.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic const char *kTestString    =  \"Testing     \";\r\nstatic const char *kExtractString =  \"Extracting  \";\r\nstatic const char *kSkipString   =  \"Skipping    \";\r\n\r\n// static const char *kCantAutoRename = \"can not create file with auto name\\n\";\r\n// static const char *kCantRenameFile = \"can not rename existing file\\n\";\r\n// static const char *kCantDeleteOutputFile = \"can not delete output file \";\r\nstatic const char *kError = \"ERROR: \";\r\nstatic const char *kMemoryExceptionMessage = \"Can't allocate required memory!\";\r\n\r\nstatic const char *kProcessing = \"Processing archive: \";\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kNoFiles = \"No files to process\";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCrcFailed = \"CRC Failed\";\r\nstatic const char *kCrcFailedEncrypted = \"CRC Failed in encrypted file. Wrong password?\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kDataErrorEncrypted = \"Data Error in encrypted file. Wrong password?\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::AskOverwrite(\r\n    const wchar_t *existName, const FILETIME *, const UInt64 *,\r\n    const wchar_t *newName, const FILETIME *, const UInt64 *,\r\n    Int32 *answer)\r\n{\r\n  (*OutStream) << \"file \" << existName <<\r\n    \"\\nalready exists. Overwrite with \" << endl;\r\n  (*OutStream) << newName;\r\n  \r\n  NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);\r\n  \r\n  switch(overwriteAnswer)\r\n  {\r\n    case NUserAnswerMode::kQuit:  return E_ABORT;\r\n    case NUserAnswerMode::kNo:     *answer = NOverwriteAnswer::kNo; break;\r\n    case NUserAnswerMode::kNoAll:  *answer = NOverwriteAnswer::kNoToAll; break;\r\n    case NUserAnswerMode::kYesAll: *answer = NOverwriteAnswer::kYesToAll; break;\r\n    case NUserAnswerMode::kYes:    *answer = NOverwriteAnswer::kYes; break;\r\n    case NUserAnswerMode::kAutoRenameAll: *answer = NOverwriteAnswer::kAutoRename; break;\r\n    default: return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position)\r\n{\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract: (*OutStream) << kExtractString; break;\r\n    case NArchive::NExtract::NAskMode::kTest:    (*OutStream) << kTestString; break;\r\n    case NArchive::NExtract::NAskMode::kSkip:    (*OutStream) << kSkipString; break;\r\n  };\r\n  (*OutStream) << name;\r\n  if (position != 0)\r\n    (*OutStream) << \" <\" << *position << \">\";\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)\r\n{\r\n  (*OutStream) << message << endl;\r\n  NumFileErrorsInCurrentArchive++;\r\n  NumFileErrors++;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumFileErrorsInCurrentArchive++;\r\n      NumFileErrors++;\r\n      (*OutStream) << \"     \";\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          (*OutStream) << kUnsupportedMethod;\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError);\r\n          break;\r\n        default:\r\n          (*OutStream) << kUnknownError;\r\n      }\r\n    }\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\n\r\nHRESULT CExtractCallbackConsole::SetPassword(const UString &password)\r\n{\r\n  PasswordIsDefined = true;\r\n  Password = password;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream);\r\n    PasswordIsDefined = true;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)\r\n{\r\n  NumArchives++;\r\n  NumFileErrorsInCurrentArchive = 0;\r\n  (*OutStream) << endl << kProcessing << name << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT result, bool encrypted)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n  {\r\n    (*OutStream) << \"Error: \";\r\n    if (result == S_FALSE)\r\n    {\r\n      (*OutStream) << (encrypted ?\r\n        \"Can not open encrypted archive. Wrong password?\" :\r\n        \"Can not open file as archive\");\r\n    }\r\n    else\r\n    {\r\n      if (result == E_OUTOFMEMORY)\r\n        (*OutStream) << \"Can't allocate required memory\";\r\n      else\r\n        (*OutStream) << NError::MyFormatMessage(result);\r\n    }\r\n    (*OutStream) << endl;\r\n    NumArchiveErrors++;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nHRESULT CExtractCallbackConsole::ThereAreNoFiles()\r\n{\r\n  (*OutStream) << endl << kNoFiles << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)\r\n{\r\n  if (result == S_OK)\r\n  {\r\n    (*OutStream) << endl;\r\n    if (NumFileErrorsInCurrentArchive == 0)\r\n      (*OutStream) << kEverythingIsOk << endl;\r\n    else\r\n    {\r\n      NumArchiveErrors++;\r\n      (*OutStream) << \"Sub items Errors: \" << NumFileErrorsInCurrentArchive << endl;\r\n    }\r\n  }\r\n  if (result == S_OK)\r\n    return result;\r\n  NumArchiveErrors++;\r\n  if (result == E_ABORT || result == ERROR_DISK_FULL)\r\n    return result;\r\n  (*OutStream) << endl << kError;\r\n  if (result == E_OUTOFMEMORY)\r\n    (*OutStream) << kMemoryExceptionMessage;\r\n  else\r\n  {\r\n    UString message;\r\n    NError::MyFormatMessage(result, message);\r\n    (*OutStream) << message;\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.h",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#ifndef __EXTRACTCALLBACKCONSOLE_H\r\n#define __EXTRACTCALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../Common/ArchiveExtractCallback.h\"\r\n\r\nclass CExtractCallbackConsole:\r\n  public IExtractCallbackUI,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IFolderArchiveExtractCallback)\r\n  #ifndef _NO_CRYPTO\r\n  MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)\r\n  #endif\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  STDMETHOD(SetTotal)(UInt64 total);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IFolderArchiveExtractCallback\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer);\r\n  STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position);\r\n\r\n  STDMETHOD(MessageError)(const wchar_t *message);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);\r\n\r\n  HRESULT BeforeOpen(const wchar_t *name);\r\n  HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);\r\n  HRESULT ThereAreNoFiles();\r\n  HRESULT ExtractResult(HRESULT result);\r\n\r\n \r\n  #ifndef _NO_CRYPTO\r\n  HRESULT SetPassword(const UString &password);\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  #endif\r\n  \r\n  UInt64 NumArchives;\r\n  UInt64 NumArchiveErrors;\r\n  UInt64 NumFileErrors;\r\n  UInt64 NumFileErrorsInCurrentArchive;\r\n\r\n  CStdOutStream *OutStream;\r\n\r\n  void Init()\r\n  {\r\n    NumArchives = 0;\r\n    NumArchiveErrors = 0;\r\n    NumFileErrors = 0;\r\n    NumFileErrorsInCurrentArchive = 0;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/List.cpp",
    "content": "// List.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"List.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../Common/PropIDUtils.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstruct CPropIdToName\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n};\r\n\r\nstatic CPropIdToName kPropIdToName[] =\r\n{\r\n  { kpidPath, L\"Path\" },\r\n  { kpidName, L\"Name\" },\r\n  { kpidIsDir, L\"Folder\" },\r\n  { kpidSize, L\"Size\" },\r\n  { kpidPackSize, L\"Packed Size\" },\r\n  { kpidAttrib, L\"Attributes\" },\r\n  { kpidCTime, L\"Created\" },\r\n  { kpidATime, L\"Accessed\" },\r\n  { kpidMTime, L\"Modified\" },\r\n  { kpidSolid, L\"Solid\" },\r\n  { kpidCommented, L\"Commented\" },\r\n  { kpidEncrypted, L\"Encrypted\" },\r\n  { kpidSplitBefore, L\"Split Before\" },\r\n  { kpidSplitAfter, L\"Split After\" },\r\n  { kpidDictionarySize, L\"Dictionary Size\" },\r\n  { kpidCRC, L\"CRC\" },\r\n  { kpidType, L\"Type\" },\r\n  { kpidIsAnti, L\"Anti\" },\r\n  { kpidMethod, L\"Method\" },\r\n  { kpidHostOS, L\"Host OS\" },\r\n  { kpidFileSystem, L\"File System\" },\r\n  { kpidUser, L\"User\" },\r\n  { kpidGroup, L\"Group\" },\r\n  { kpidBlock, L\"Block\" },\r\n  { kpidComment, L\"Comment\" },\r\n  { kpidPosition, L\"Position\" },\r\n  { kpidPrefix, L\"Prefix\" },\r\n  { kpidNumSubDirs, L\"Folders\" },\r\n  { kpidNumSubFiles, L\"Files\" },\r\n  { kpidUnpackVer, L\"Version\" },\r\n  { kpidVolume, L\"Volume\" },\r\n  { kpidIsVolume, L\"Multivolume\" },\r\n  { kpidOffset, L\"Offset\" },\r\n  { kpidLinks, L\"Links\" },\r\n  { kpidNumBlocks, L\"Blocks\" },\r\n  { kpidNumVolumes, L\"Volumes\" },\r\n\r\n  { kpidBit64, L\"64-bit\" },\r\n  { kpidBigEndian, L\"Big-endian\" },\r\n  { kpidCpu, L\"CPU\" },\r\n  { kpidPhySize, L\"Physical Size\" },\r\n  { kpidHeadersSize, L\"Headers Size\" },\r\n  { kpidChecksum, L\"Checksum\" },\r\n  { kpidCharacts, L\"Characteristics\" },\r\n  { kpidVa, L\"Virtual Address\" },\r\n  { kpidFreeSpace, L\"Free Space\" },\r\n  { kpidClusterSize, L\"Cluster Size\" }\r\n};\r\n\r\nstatic const char kEmptyAttribChar = '.';\r\n\r\nstatic const char *kListing = \"Listing archive: \";\r\nstatic const wchar_t *kFilesMessage = L\"files\";\r\nstatic const wchar_t *kDirsMessage = L\"folders\";\r\n\r\nstatic void GetAttribString(DWORD wa, bool isDir, char *s)\r\n{\r\n  s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : kEmptyAttribChar;\r\n  s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0) ? 'R': kEmptyAttribChar;\r\n  s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? 'H': kEmptyAttribChar;\r\n  s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? 'S': kEmptyAttribChar;\r\n  s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? 'A': kEmptyAttribChar;\r\n  s[5] = '\\0';\r\n}\r\n\r\nenum EAdjustment\r\n{\r\n  kLeft,\r\n  kCenter,\r\n  kRight\r\n};\r\n\r\nstruct CFieldInfo\r\n{\r\n  PROPID PropID;\r\n  UString Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nstruct CFieldInfoInit\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nCFieldInfoInit kStandardFieldTable[] =\r\n{\r\n  { kpidMTime, L\"   Date      Time\", kLeft, kLeft, 0, 19 },\r\n  { kpidAttrib, L\"Attr\", kRight, kCenter, 1, 5 },\r\n  { kpidSize, L\"Size\", kRight, kRight, 1, 12 },\r\n  { kpidPackSize, L\"Compressed\", kRight, kRight, 1, 12 },\r\n  { kpidPath, L\"Name\", kLeft, kLeft, 2, 24 }\r\n};\r\n\r\nvoid PrintSpaces(int numSpaces)\r\n{\r\n  for (int i = 0; i < numSpaces; i++)\r\n    g_StdOut << ' ';\r\n}\r\n\r\nvoid PrintString(EAdjustment adjustment, int width, const UString &textString)\r\n{\r\n  const int numSpaces = width - textString.Length();\r\n  int numLeftSpaces = 0;\r\n  switch (adjustment)\r\n  {\r\n    case kLeft:\r\n      numLeftSpaces = 0;\r\n      break;\r\n    case kCenter:\r\n      numLeftSpaces = numSpaces / 2;\r\n      break;\r\n    case kRight:\r\n      numLeftSpaces = numSpaces;\r\n      break;\r\n  }\r\n  PrintSpaces(numLeftSpaces);\r\n  g_StdOut << textString;\r\n  PrintSpaces(numSpaces - numLeftSpaces);\r\n}\r\n\r\nclass CFieldPrinter\r\n{\r\n  CObjectVector<CFieldInfo> _fields;\r\npublic:\r\n  void Clear() { _fields.Clear(); }\r\n  void Init(const CFieldInfoInit *standardFieldTable, int numItems);\r\n  HRESULT Init(IInArchive *archive);\r\n  void PrintTitle();\r\n  void PrintTitleLines();\r\n  HRESULT PrintItemInfo(IInArchive *archive,\r\n      const UString &defaultItemName,\r\n      UInt32 index,\r\n      bool techMode);\r\n  HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\r\n      const UInt64 *size, const UInt64 *compressedSize);\r\n};\r\n\r\nvoid CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)\r\n{\r\n  Clear();\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    CFieldInfo fieldInfo;\r\n    const CFieldInfoInit &fieldInfoInit = standardFieldTable[i];\r\n    fieldInfo.PropID = fieldInfoInit.PropID;\r\n    fieldInfo.Name = fieldInfoInit.Name;\r\n    fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment;\r\n    fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment;\r\n    fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth;\r\n    fieldInfo.Width = fieldInfoInit.Width;\r\n    _fields.Add(fieldInfo);\r\n  }\r\n}\r\n\r\nstatic UString GetPropName(PROPID propID, BSTR name)\r\n{\r\n  for (int i = 0; i < sizeof(kPropIdToName) / sizeof(kPropIdToName[0]); i++)\r\n  {\r\n    const CPropIdToName &propIdToName = kPropIdToName[i];\r\n    if (propIdToName.PropID == propID)\r\n      return propIdToName.Name;\r\n  }\r\n  if (name)\r\n    return name;\r\n  wchar_t s[32];\r\n  ConvertUInt64ToString(propID, s);\r\n  return s;\r\n}\r\n\r\nHRESULT CFieldPrinter::Init(IInArchive *archive)\r\n{\r\n  Clear();\r\n  UInt32 numProps;\r\n  RINOK(archive->GetNumberOfProperties(&numProps));\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    CMyComBSTR name;\r\n    PROPID propID;\r\n    VARTYPE vt;\r\n    RINOK(archive->GetPropertyInfo(i, &name, &propID, &vt));\r\n    CFieldInfo fieldInfo;\r\n    fieldInfo.PropID = propID;\r\n    fieldInfo.Name = GetPropName(propID, name);\r\n    _fields.Add(fieldInfo);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitle()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    PrintString(fieldInfo.TitleAdjustment,\r\n      ((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);\r\n  }\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitleLines()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    for (int i = 0; i < fieldInfo.Width; i++)\r\n      g_StdOut << '-';\r\n  }\r\n}\r\n\r\n\r\nBOOL IsFileTimeZero(CONST FILETIME *lpFileTime)\r\n{\r\n  return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);\r\n}\r\n\r\nstatic const char *kEmptyTimeString = \"                   \";\r\nvoid PrintTime(const NCOM::CPropVariant &prop)\r\n{\r\n  if (prop.vt != VT_FILETIME)\r\n    throw \"incorrect item\";\r\n  if (IsFileTimeZero(&prop.filetime))\r\n    g_StdOut << kEmptyTimeString;\r\n  else\r\n  {\r\n    FILETIME localFileTime;\r\n    if (!FileTimeToLocalFileTime(&prop.filetime, &localFileTime))\r\n      throw \"FileTimeToLocalFileTime error\";\r\n    char s[32];\r\n    if (ConvertFileTimeToString(localFileTime, s, true, true))\r\n      g_StdOut << s;\r\n    else\r\n      g_StdOut << kEmptyTimeString;\r\n  }\r\n}\r\n\r\nHRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    UInt32 index,\r\n    bool techMode)\r\n{\r\n  /*\r\n  if (techMode)\r\n  {\r\n    g_StdOut << \"Index = \";\r\n    g_StdOut << (UInt64)index;\r\n    g_StdOut << endl;\r\n  }\r\n  */\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    if (!techMode)\r\n      PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      UString s;\r\n      RINOK(GetArchiveItemPath(archive, index, defaultItemName, s));\r\n      prop = s;\r\n    }\r\n    else\r\n    {\r\n      RINOK(archive->GetProperty(index, fieldInfo.PropID, &prop));\r\n    }\r\n    if (techMode)\r\n    {\r\n      g_StdOut << fieldInfo.Name << \" = \";\r\n    }\r\n    int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;\r\n    if (prop.vt == VT_EMPTY)\r\n    {\r\n      switch(fieldInfo.PropID)\r\n      {\r\n        case kpidPath:  prop = defaultItemName; break;\r\n        default:\r\n          if (techMode)\r\n            g_StdOut << endl;\r\n          else\r\n            PrintSpaces(width);\r\n          continue;\r\n      }\r\n    }\r\n    if (fieldInfo.PropID == kpidMTime)\r\n    {\r\n      PrintTime(prop);\r\n    }\r\n    else if (fieldInfo.PropID == kpidAttrib)\r\n    {\r\n      if (prop.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      UInt32 attributes = prop.ulVal;\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, index, isFolder));\r\n      char s[8];\r\n      GetAttribString(attributes, isFolder, s);\r\n      g_StdOut << s;\r\n    }\r\n    else if (prop.vt == VT_BSTR)\r\n    {\r\n      if (techMode)\r\n        g_StdOut << prop.bstrVal;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, prop.bstrVal);\r\n    }\r\n    else\r\n    {\r\n      UString s = ConvertPropertyToString(prop, fieldInfo.PropID);\r\n      s.Replace(wchar_t(0xA), L' ');\r\n      s.Replace(wchar_t(0xD), L' ');\r\n\r\n      if (techMode)\r\n        g_StdOut << s;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, s);\r\n    }\r\n    if (techMode)\r\n      g_StdOut << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)\r\n{\r\n  wchar_t textString[32] = { 0 };\r\n  if (value != NULL)\r\n    ConvertUInt64ToString(*value, textString);\r\n  PrintString(adjustment, width, textString);\r\n}\r\n\r\n\r\nHRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\r\n    const UInt64 *size, const UInt64 *compressedSize)\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    NCOM::CPropVariant prop;\r\n    if (fieldInfo.PropID == kpidSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);\r\n    else if (fieldInfo.PropID == kpidPackSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);\r\n    else if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      wchar_t textString[32];\r\n      ConvertUInt64ToString(numFiles, textString);\r\n      UString temp = textString;\r\n      temp += L\" \";\r\n      temp += kFilesMessage;\r\n      temp += L\", \";\r\n      ConvertUInt64ToString(numDirs, textString);\r\n      temp += textString;\r\n      temp += L\" \";\r\n      temp += kDirsMessage;\r\n      PrintString(fieldInfo.TextAdjustment, 0, temp);\r\n    }\r\n    else\r\n      PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L\"\");\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nbool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  if (archive->GetProperty(index, propID, &prop) != S_OK)\r\n    throw \"GetPropertyValue error\";\r\n  if (prop.vt == VT_EMPTY)\r\n    return false;\r\n  value = ConvertPropVariantToUInt64(prop);\r\n  return true;\r\n}\r\n\r\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode,\r\n    #ifndef _NO_CRYPTO\r\n    bool &passwordEnabled, UString &password,\r\n    #endif\r\n    UInt64 &numErrors)\r\n{\r\n  numErrors = 0;\r\n  CFieldPrinter fieldPrinter;\r\n  if (!techMode)\r\n    fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));\r\n\r\n  UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;\r\n  UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;\r\n  for (int i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archiveName = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archiveName, fi) || fi.IsDir())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not file\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    CArchiveLink archiveLink;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &g_StdOut;\r\n\r\n    #ifndef _NO_CRYPTO\r\n\r\n    openCallback.PasswordIsDefined = passwordEnabled;\r\n    openCallback.Password = password;\r\n\r\n    #endif\r\n\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, &openCallback);\r\n    if (result != S_OK)\r\n    {\r\n      if (result == E_ABORT)\r\n        return result;\r\n      g_StdOut << endl << \"Error: \" << archiveName << \": \";\r\n      if (result == S_FALSE)\r\n        g_StdOut << \"is not supported archive\";\r\n      else if (result == E_OUTOFMEMORY)\r\n        g_StdOut << \"Can't allocate required memory\";\r\n      else\r\n        g_StdOut << NError::MyFormatMessage(result);\r\n      g_StdOut << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n      }\r\n    }\r\n\r\n    IInArchive *archive = archiveLink.GetArchive();\r\n    const UString defaultItemName = archiveLink.GetDefaultItemName();\r\n\r\n    if (enableHeaders)\r\n    {\r\n      g_StdOut << endl << kListing << archiveName << endl << endl;\r\n\r\n      UInt32 numProps;\r\n      if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)\r\n      {\r\n        for (UInt32 i = 0; i < numProps; i++)\r\n        {\r\n          CMyComBSTR name;\r\n          PROPID propID;\r\n          VARTYPE vt;\r\n          if (archive->GetArchivePropertyInfo(i, &name, &propID, &vt) != S_OK)\r\n            continue;\r\n          NCOM::CPropVariant prop;\r\n          if (archive->GetArchiveProperty(propID, &prop) != S_OK)\r\n            continue;\r\n          UString s = ConvertPropertyToString(prop, propID);\r\n          if (!s.IsEmpty())\r\n            g_StdOut << GetPropName(propID, name) << \" = \" << s << endl;\r\n        }\r\n      }\r\n      if (techMode)\r\n        g_StdOut << \"----------\\n\";\r\n      if (numProps > 0)\r\n        g_StdOut << endl;\r\n    }\r\n\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitle();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n    }\r\n\r\n    if (techMode)\r\n    {\r\n      RINOK(fieldPrinter.Init(archive));\r\n    }\r\n    UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0;\r\n    UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;\r\n    UInt32 numItems;\r\n    RINOK(archive->GetNumberOfItems(&numItems));\r\n    for(UInt32 i = 0; i < numItems; i++)\r\n    {\r\n      if (NConsoleClose::TestBreakSignal())\r\n        return E_ABORT;\r\n\r\n      UString filePath;\r\n      RINOK(GetArchiveItemPath(archive, i, defaultItemName, filePath));\r\n\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n      if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n        continue;\r\n      \r\n      fieldPrinter.PrintItemInfo(archive, defaultItemName, i, techMode);\r\n      \r\n      UInt64 packSize, unpackSize;\r\n      if (!GetUInt64Value(archive, i, kpidSize, unpackSize))\r\n        unpackSize = 0;\r\n      else\r\n        totalUnPackSizePointer = &totalUnPackSize;\r\n      if (!GetUInt64Value(archive, i, kpidPackSize, packSize))\r\n        packSize = 0;\r\n      else\r\n        totalPackSizePointer = &totalPackSize;\r\n      \r\n      g_StdOut << endl;\r\n\r\n      if (isFolder)\r\n        numDirs++;\r\n      else\r\n        numFiles++;\r\n      totalPackSize += packSize;\r\n      totalUnPackSize += unpackSize;\r\n    }\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintSummaryInfo(numFiles, numDirs, totalUnPackSizePointer, totalPackSizePointer);\r\n      g_StdOut << endl;\r\n    }\r\n    if (totalPackSizePointer != 0)\r\n    {\r\n      totalPackSizePointer2 = &totalPackSize2;\r\n      totalPackSize2 += totalPackSize;\r\n    }\r\n    if (totalUnPackSizePointer != 0)\r\n    {\r\n      totalUnPackSizePointer2 = &totalUnPackSize2;\r\n      totalUnPackSize2 += totalUnPackSize;\r\n    }\r\n    numFiles2 += numFiles;\r\n    numDirs2 += numDirs;\r\n  }\r\n  if (enableHeaders && !techMode && archivePaths.Size() > 1)\r\n  {\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintTitleLines();\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintSummaryInfo(numFiles2, numDirs2, totalUnPackSizePointer2, totalPackSizePointer2);\r\n    g_StdOut << endl;\r\n    g_StdOut << \"Archives: \" << archivePaths.Size() << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/List.h",
    "content": "// List.h\r\n\r\n#ifndef __LIST_H\r\n#define __LIST_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode,\r\n    #ifndef _NO_CRYPTO\r\n    bool &passwordEnabled, UString &password,\r\n    #endif\r\n    UInt64 &errors);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/Main.cpp",
    "content": "// Main.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n\r\n#include \"Common/CommandLineParser.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/Error.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/MemoryLock.h\"\r\n#endif\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/UpdateAction.h\"\r\n#include \"../Common/Update.h\"\r\n#include \"../Common/Extract.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"../Common/ExitCode.h\"\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../Common/LoadCodecs.h\"\r\n#endif\r\n\r\n#include \"../../Compress/LZMA_Alone/LzmaBenchCon.h\"\r\n\r\n#include \"List.h\"\r\n#include \"OpenCallbackConsole.h\"\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\n#if defined( _WIN32) && defined( _7ZIP_LARGE_PAGES)\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NCommandLineParser;\r\n\r\nHINSTANCE g_hInstance = 0;\r\nextern CStdOutStream *g_StdStream;\r\n\r\nstatic const char *kCopyrightString = \"\\n7-Zip\"\r\n#ifndef EXTERNAL_CODECS\r\n\" (A)\"\r\n#endif\r\n\r\n#ifdef _WIN64\r\n\" [64]\"\r\n#endif\r\n\r\n\" \" MY_VERSION_COPYRIGHT_DATE \"\\n\";\r\n\r\nstatic const char *kHelpString =\r\n    \"\\nUsage: 7z\"\r\n#ifdef _NO_CRYPTO\r\n    \"r\"\r\n#else\r\n#ifndef EXTERNAL_CODECS\r\n    \"a\"\r\n#endif\r\n#endif\r\n    \" <command> [<switches>...] <archive_name> [<file_names>...]\\n\"\r\n    \"       [<@listfiles...>]\\n\"\r\n    \"\\n\"\r\n    \"<Commands>\\n\"\r\n    \"  a: Add files to archive\\n\"\r\n    \"  b: Benchmark\\n\"\r\n    \"  d: Delete files from archive\\n\"\r\n    \"  e: Extract files from archive (without using directory names)\\n\"\r\n    \"  l: List contents of archive\\n\"\r\n//    \"  l[a|t][f]: List contents of archive\\n\"\r\n//    \"    a - with Additional fields\\n\"\r\n//    \"    t - with all fields\\n\"\r\n//    \"    f - with Full pathnames\\n\"\r\n    \"  t: Test integrity of archive\\n\"\r\n    \"  u: Update files to archive\\n\"\r\n    \"  x: eXtract files with full paths\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -ai[r[-|0]]{@listfile|!wildcard}: Include archives\\n\"\r\n    \"  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives\\n\"\r\n    \"  -bd: Disable percentage indicator\\n\"\r\n    \"  -i[r[-|0]]{@listfile|!wildcard}: Include filenames\\n\"\r\n    \"  -m{Parameters}: set compression Method\\n\"\r\n    \"  -o{Directory}: set Output directory\\n\"\r\n    #ifndef _NO_CRYPTO\r\n    \"  -p{Password}: set Password\\n\"\r\n    #endif\r\n    \"  -r[-|0]: Recurse subdirectories\\n\"\r\n    \"  -scs{UTF-8 | WIN | DOS}: set charset for list files\\n\"\r\n    \"  -sfx[{name}]: Create SFX archive\\n\"\r\n    \"  -si[{name}]: read data from stdin\\n\"\r\n    \"  -slt: show technical information for l (List) command\\n\"\r\n    \"  -so: write data to stdout\\n\"\r\n    \"  -ssc[-]: set sensitive case mode\\n\"\r\n    \"  -ssw: compress shared files\\n\"\r\n    \"  -t{Type}: Set type of archive\\n\"\r\n    \"  -v{Size}[b|k|m|g]: Create volumes\\n\"\r\n    \"  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\\n\"\r\n    \"  -w[{path}]: assign Work directory. Empty path means a temporary directory\\n\"\r\n    \"  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\\n\"\r\n    \"  -y: assume Yes on all queries\\n\";\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\"; // NExitCode::kUserError\r\nstatic const char *kNoFormats = \"7-Zip cannot find the code that works with archives.\";\r\n\r\nstatic const wchar_t *kDefaultSfxModule = L\"7zCon.sfx\";\r\n\r\nstatic void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code)\r\n{\r\n  s << message << endl;\r\n  throw code;\r\n}\r\n\r\nstatic void PrintHelpAndExit(CStdOutStream &s) // yyy\r\n{\r\n  s << kHelpString;\r\n  ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError);\r\n}\r\n\r\n#ifndef _WIN32\r\nstatic void GetArguments(int numArguments, const char *arguments[], UStringVector &parts)\r\n{\r\n  parts.Clear();\r\n  for(int i = 0; i < numArguments; i++)\r\n  {\r\n    UString s = MultiByteToUnicodeString(arguments[i]);\r\n    parts.Add(s);\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp)\r\n{\r\n  s << kCopyrightString;\r\n  // s << \"# CPUs: \" << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << \"\\n\";\r\n  if (needHelp)\r\n    s << kHelpString;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic void PrintString(CStdOutStream &stdStream, const AString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n#endif\r\n\r\nstatic void PrintString(CStdOutStream &stdStream, const UString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n\r\nstatic inline char GetHex(Byte value)\r\n{\r\n  return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nconst char *kUnsupportedArcTypeMessage = \"Unsupported archive type\";\r\n\r\nint Main2(\r\n  #ifndef _WIN32\r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n)\r\n{\r\n  #ifdef _WIN32\r\n  SetFileApisToOEM();\r\n  #endif\r\n  \r\n  UStringVector commandStrings;\r\n  #ifdef _WIN32\r\n  NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);\r\n  #else\r\n  GetArguments(numArguments, arguments, commandStrings);\r\n  #endif\r\n\r\n  if(commandStrings.Size() == 1)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n  commandStrings.Delete(0);\r\n\r\n  CArchiveCommandLineOptions options;\r\n\r\n  CArchiveCommandLineParser parser;\r\n\r\n  parser.Parse1(commandStrings, options);\r\n\r\n  if(options.HelpMode)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  if (options.LargePages)\r\n  {\r\n    SetLargePageSize();\r\n    NSecurity::EnableLockMemoryPrivilege();\r\n  }\r\n  #endif\r\n\r\n  CStdOutStream &stdStream = options.StdOutMode ? g_StdErr : g_StdOut;\r\n  g_StdStream = &stdStream;\r\n\r\n  if (options.EnableHeaders)\r\n    ShowCopyrightAndHelp(stdStream, false);\r\n\r\n  parser.Parse2(options);\r\n\r\n  CCodecs *codecs = new CCodecs;\r\n  CMyComPtr<\r\n    #ifdef EXTERNAL_CODECS\r\n    ICompressCodecsInfo\r\n    #else\r\n    IUnknown\r\n    #endif\r\n    > compressCodecsInfo = codecs;\r\n  HRESULT result = codecs->Load();\r\n  if (result != S_OK)\r\n    throw CSystemException(result);\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  if (codecs->Formats.Size() == 0 &&\r\n        (isExtractGroupCommand ||\r\n        options.Command.CommandType == NCommandType::kList ||\r\n        options.Command.IsFromUpdateGroup()))\r\n    throw kNoFormats;\r\n\r\n  CIntVector formatIndices;\r\n  if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices))\r\n    throw kUnsupportedArcTypeMessage;\r\n\r\n  if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n    stdStream << endl << \"Formats:\" << endl;\r\n    int i;\r\n    for (i = 0; i < codecs->Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = codecs->Formats[i];\r\n      #ifdef EXTERNAL_CODECS\r\n      if (arc.LibIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(arc.LibIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n      #endif\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(arc.UpdateEnabled ? 'C' : ' ');\r\n      stdStream << (char)(arc.KeepName ? 'K' : ' ');\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, arc.Name, 6);\r\n      stdStream << \"  \";\r\n      UString s;\r\n      for (int t = 0; t < arc.Exts.Size(); t++)\r\n      {\r\n        const CArcExtInfo &ext = arc.Exts[t];\r\n        s += ext.Ext;\r\n        if (!ext.AddExt.IsEmpty())\r\n        {\r\n          s += L\" (\";\r\n          s += ext.AddExt;\r\n          s += L')';\r\n        }\r\n        s += L' ';\r\n      }\r\n      PrintString(stdStream, s, 14);\r\n      stdStream << \"  \";\r\n      const CByteBuffer &sig = arc.StartSignature;\r\n      for (size_t j = 0; j < sig.GetCapacity(); j++)\r\n      {\r\n        Byte b = sig[j];\r\n        if (b > 0x20 && b < 0x80)\r\n        {\r\n          stdStream << (char)b;\r\n        }\r\n        else\r\n        {\r\n          stdStream << GetHex((Byte)((b >> 4) & 0xF));\r\n          stdStream << GetHex((Byte)(b & 0xF));\r\n        }\r\n        stdStream << ' ';\r\n      }\r\n      stdStream << endl;\r\n    }\r\n    stdStream << endl << \"Codecs:\" << endl;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    UInt32 numMethods;\r\n    if (codecs->GetNumberOfMethods(&numMethods) == S_OK)\r\n    for (UInt32 j = 0; j < numMethods; j++)\r\n    {\r\n      int libIndex = codecs->GetCodecLibIndex(j);\r\n      if (libIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(libIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(codecs->GetCodecEncoderIsAssigned(j) ? 'C' : ' ');\r\n      UInt64 id;\r\n      stdStream << \"  \";\r\n      HRESULT res = codecs->GetCodecId(j, id);\r\n      if (res != S_OK)\r\n        id = (UInt64)(Int64)-1;\r\n      char s[32];\r\n      ConvertUInt64ToString(id, s, 16);\r\n      PrintString(stdStream, s, 8);\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, codecs->GetCodecName(j), 11);\r\n      stdStream << endl;\r\n      /*\r\n      if (res != S_OK)\r\n        throw \"incorrect Codec ID\";\r\n      */\r\n    }\r\n    #endif\r\n    return S_OK;\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    if (options.Method.CompareNoCase(L\"CRC\") == 0)\r\n    {\r\n      HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nCRC Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      HRESULT res = LzmaBenchCon(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        (FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nDecoding Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n  }\r\n  else if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if(isExtractGroupCommand)\r\n    {\r\n      CExtractCallbackConsole *ecs = new CExtractCallbackConsole;\r\n      CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;\r\n\r\n      ecs->OutStream = &stdStream;\r\n\r\n      #ifndef _NO_CRYPTO\r\n      ecs->PasswordIsDefined = options.PasswordEnabled;\r\n      ecs->Password = options.Password;\r\n      #endif\r\n\r\n      ecs->Init();\r\n\r\n      COpenCallbackConsole openCallback;\r\n      openCallback.OutStream = &stdStream;\r\n\r\n      #ifndef _NO_CRYPTO\r\n      openCallback.PasswordIsDefined = options.PasswordEnabled;\r\n      openCallback.Password = options.Password;\r\n      #endif\r\n\r\n      CExtractOptions eo;\r\n      eo.StdOutMode = options.StdOutMode;\r\n      eo.PathMode = options.Command.GetPathMode();\r\n      eo.TestMode = options.Command.IsTestMode();\r\n      eo.OverwriteMode = options.OverwriteMode;\r\n      eo.OutputDir = options.OutputDir;\r\n      eo.YesToAll = options.YesToAll;\r\n      #ifdef COMPRESS_MT\r\n      eo.Properties = options.ExtractProperties;\r\n      #endif\r\n      UString errorMessage;\r\n      CDecompressStat stat;\r\n      HRESULT result = DecompressArchives(\r\n          codecs,\r\n          formatIndices,\r\n          options.ArchivePathsSorted,\r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head,\r\n          eo, &openCallback, ecs, errorMessage, stat);\r\n      if (!errorMessage.IsEmpty())\r\n      {\r\n        stdStream << endl << \"Error: \" << errorMessage;\r\n        if (result == S_OK)\r\n          result = E_FAIL;\r\n      }\r\n\r\n      stdStream << endl;\r\n      if (ecs->NumArchives > 1)\r\n        stdStream << \"Archives: \" << ecs->NumArchives << endl;\r\n      if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0)\r\n      {\r\n        if (ecs->NumArchives > 1)\r\n        {\r\n          stdStream << endl;\r\n          if (ecs->NumArchiveErrors != 0)\r\n            stdStream << \"Archive Errors: \" << ecs->NumArchiveErrors << endl;\r\n          if (ecs->NumFileErrors != 0)\r\n            stdStream << \"Sub items Errors: \" << ecs->NumFileErrors << endl;\r\n        }\r\n        if (result != S_OK)\r\n          throw CSystemException(result);\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n      if (stat.NumFolders != 0)\r\n        stdStream << \"Folders: \" << stat.NumFolders << endl;\r\n      if (stat.NumFiles != 1 || stat.NumFolders != 0)\r\n          stdStream << \"Files: \" << stat.NumFiles << endl;\r\n      stdStream\r\n           << \"Size:       \" << stat.UnpackSize << endl\r\n           << \"Compressed: \" << stat.PackSize << endl;\r\n    }\r\n    else\r\n    {\r\n      UInt64 numErrors = 0;\r\n      HRESULT result = ListArchives(\r\n          codecs,\r\n          formatIndices,\r\n          options.ArchivePathsSorted,\r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head,\r\n          options.EnableHeaders,\r\n          options.TechMode,\r\n          #ifndef _NO_CRYPTO\r\n          options.PasswordEnabled,\r\n          options.Password,\r\n          #endif\r\n          numErrors);\r\n      if (numErrors > 0)\r\n      {\r\n        g_StdOut << endl << \"Errors: \" << numErrors;\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    UString workingDir;\r\n\r\n    CUpdateOptions &uo = options.UpdateOptions;\r\n    if (uo.SfxMode && uo.SfxModule.IsEmpty())\r\n      uo.SfxModule = kDefaultSfxModule;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &stdStream;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    bool passwordIsDefined =\r\n        options.PasswordEnabled && !options.Password.IsEmpty();\r\n    openCallback.PasswordIsDefined = passwordIsDefined;\r\n    openCallback.Password = options.Password;\r\n    #endif\r\n\r\n    CUpdateCallbackConsole callback;\r\n    callback.EnablePercents = options.EnablePercents;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    callback.PasswordIsDefined = passwordIsDefined;\r\n    callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty();\r\n    callback.Password = options.Password;\r\n    #endif\r\n    callback.StdOutMode = uo.StdOutMode;\r\n    callback.Init(&stdStream);\r\n\r\n    CUpdateErrorInfo errorInfo;\r\n\r\n    if (!uo.Init(codecs, formatIndices, options.ArchiveName))\r\n      throw kUnsupportedArcTypeMessage;\r\n    HRESULT result = UpdateArchive(codecs,\r\n        options.WildcardCensor, uo,\r\n        errorInfo, &openCallback, &callback);\r\n\r\n    int exitCode = NExitCode::kSuccess;\r\n    if (callback.CantFindFiles.Size() > 0)\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      int numErrors = callback.CantFindFiles.Size();\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.CantFindFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.CantFindCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot find \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n\r\n    if (result != S_OK)\r\n    {\r\n      UString message;\r\n      if (!errorInfo.Message.IsEmpty())\r\n      {\r\n        message += errorInfo.Message;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName2.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName2;\r\n        message += L\"\\n\";\r\n      }\r\n      if (errorInfo.SystemError != 0)\r\n      {\r\n        message += NError::MyFormatMessageW(errorInfo.SystemError);\r\n        message += L\"\\n\";\r\n      }\r\n      if (!message.IsEmpty())\r\n        stdStream << L\"\\nError:\\n\" << message;\r\n      throw CSystemException(result);\r\n    }\r\n    int numErrors = callback.FailedFiles.Size();\r\n    if (numErrors == 0)\r\n    {\r\n      if (callback.CantFindFiles.Size() == 0)\r\n        stdStream << kEverythingIsOk << endl;\r\n    }\r\n    else\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.FailedFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.FailedCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot open \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n    return exitCode;\r\n  }\r\n  else\r\n    PrintHelpAndExit(stdStream);\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/MainAr.cpp",
    "content": "// MainAr.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <locale.h>\r\n\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"../Common/ExitCode.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCStdOutStream *g_StdStream = 0;\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\n#endif\r\n#if !defined(_UNICODE) || !defined(_WIN64)\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern int Main2(\r\n  #ifndef _WIN32\r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n);\r\n\r\nstatic const char *kExceptionErrorMessage = \"\\n\\nError:\\n\";\r\nstatic const char *kUserBreak  = \"\\nBreak signaled\\n\";\r\n\r\nstatic const char *kMemoryExceptionMessage = \"\\n\\nERROR: Can't allocate required memory!\\n\";\r\nstatic const char *kUnknownExceptionMessage = \"\\n\\nUnknown Error\\n\";\r\nstatic const char *kInternalExceptionMessage = \"\\n\\nInternal Error #\";\r\n\r\nint MY_CDECL main\r\n(\r\n#ifndef _WIN32\r\nint numArguments, const char *arguments[]\r\n#endif\r\n)\r\n{\r\n  g_StdStream = &g_StdOut;\r\n  #ifdef _WIN32\r\n  \r\n  #ifdef _UNICODE\r\n  #ifndef _WIN64\r\n  if (!IsItWindowsNT())\r\n  {\r\n    (*g_StdStream) << \"This program requires Windows NT/2000/2003/2008/XP/Vista\";\r\n    return NExitCode::kFatalError;\r\n  }\r\n  #endif\r\n  #else\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  \r\n  #endif\r\n\r\n  // setlocale(LC_COLLATE, \".OCP\");\r\n  NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;\r\n  int res = 0;\r\n  try\r\n  {\r\n    res = Main2(\r\n#ifndef _WIN32\r\n      numArguments, arguments\r\n#endif\r\n    );\r\n  }\r\n  catch(const CNewException &)\r\n  {\r\n    (*g_StdStream) << kMemoryExceptionMessage;\r\n    return (NExitCode::kMemoryError);\r\n  }\r\n  catch(const NConsoleClose::CCtrlBreakException &)\r\n  {\r\n    (*g_StdStream) << endl << kUserBreak;\r\n    return (NExitCode::kUserBreak);\r\n  }\r\n  catch(const CArchiveCommandLineException &e)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << e << endl;\r\n    return (NExitCode::kUserError);\r\n  }\r\n  catch(const CSystemException &systemError)\r\n  {\r\n    if (systemError.ErrorCode == E_OUTOFMEMORY)\r\n    {\r\n      (*g_StdStream) << kMemoryExceptionMessage;\r\n      return (NExitCode::kMemoryError);\r\n    }\r\n    if (systemError.ErrorCode == E_ABORT)\r\n    {\r\n      (*g_StdStream) << endl << kUserBreak;\r\n      return (NExitCode::kUserBreak);\r\n    }\r\n    UString message;\r\n    NError::MyFormatMessage(systemError.ErrorCode, message);\r\n    (*g_StdStream) << endl << endl << \"System error:\" << endl <<\r\n        message << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(NExitCode::EEnum &exitCode)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << exitCode << endl;\r\n    return (exitCode);\r\n  }\r\n  /*\r\n  catch(const NExitCode::CMultipleErrors &multipleErrors)\r\n  {\r\n    (*g_StdStream) << endl << multipleErrors.NumErrors << \" errors\" << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  */\r\n  catch(const UString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const AString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const char *s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(int t)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << t << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(...)\r\n  {\r\n    (*g_StdStream) << kUnknownExceptionMessage;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  return  res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.cpp",
    "content": "// OpenCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nHRESULT COpenCallbackConsole::Open_CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_SetTotal(const UInt64 *, const UInt64 *)\r\n{\r\n  return Open_CheckBreak();\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_SetCompleted(const UInt64 *, const UInt64 *)\r\n{\r\n  return Open_CheckBreak();\r\n}\r\n \r\n#ifndef _NO_CRYPTO\r\n\r\nHRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password)\r\n{\r\n  PasswordWasAsked = true;\r\n  RINOK(Open_CheckBreak());\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream);\r\n    PasswordIsDefined = true;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_GetPasswordIfAny(UString &password)\r\n{\r\n  if (PasswordIsDefined)\r\n    password = Password;\r\n  return S_OK;\r\n}\r\n\r\nbool COpenCallbackConsole::Open_WasPasswordAsked()\r\n{\r\n  return PasswordWasAsked;\r\n}\r\n\r\nvoid COpenCallbackConsole::Open_ClearPasswordWasAskedFlag()\r\n{\r\n  PasswordWasAsked = false;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.h",
    "content": "// OpenCallbackConsole.h\r\n\r\n#ifndef __OPENCALLBACKCONSOLE_H\r\n#define __OPENCALLBACKCONSOLE_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../Common/ArchiveOpenCallback.h\"\r\n\r\nclass COpenCallbackConsole: public IOpenCallbackUI\r\n{\r\npublic:\r\n  INTERFACE_IOpenCallbackUI(;)\r\n  \r\n  CStdOutStream *OutStream;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordIsDefined;\r\n  bool PasswordWasAsked;\r\n  UString Password;\r\n  COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {}\r\n  #endif\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/PercentPrinter.cpp",
    "content": "// PercentPrinter.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"PercentPrinter.h\"\r\n\r\nconst int kPaddingSize = 2;\r\nconst int kPercentsSize = 4;\r\nconst int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;\r\n\r\nstatic void ClearPrev(char *p, int num)\r\n{\r\n  int i;\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  for (i = 0; i < num; i++) *p++ = ' ';\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  *p = '\\0';\r\n}\r\n\r\nvoid CPercentPrinter::ClosePrint()\r\n{\r\n  if (m_NumExtraChars == 0)\r\n    return;\r\n  char s[kMaxExtraSize * 3 + 1];\r\n  ClearPrev(s, m_NumExtraChars);\r\n  (*OutStream) << s;\r\n  m_NumExtraChars = 0;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const char *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const wchar_t *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintNewLine()\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << \"\\n\";\r\n}\r\n\r\nvoid CPercentPrinter::RePrintRatio()\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s);\r\n  int size = (int)strlen(s);\r\n  s[size++] = '%';\r\n  s[size] = '\\0';\r\n\r\n  int extraSize = kPaddingSize + MyMax(size, kPercentsSize);\r\n  if (extraSize < m_NumExtraChars)\r\n    extraSize = m_NumExtraChars;\r\n\r\n  char fullString[kMaxExtraSize * 3];\r\n  char *p = fullString;\r\n  int i;\r\n  if (m_NumExtraChars == 0)\r\n  {\r\n    for (i = 0; i < extraSize; i++)\r\n      *p++ = ' ';\r\n    m_NumExtraChars = extraSize;\r\n  }\r\n\r\n  for (i = 0; i < m_NumExtraChars; i++)\r\n    *p++ = '\\b';\r\n  m_NumExtraChars = extraSize;\r\n  for (; size < m_NumExtraChars; size++)\r\n    *p++ = ' ';\r\n  MyStringCopy(p, s);\r\n  (*OutStream) << fullString;\r\n  OutStream->Flush();\r\n  m_PrevValue = m_CurValue;\r\n}\r\n\r\nvoid CPercentPrinter::PrintRatio()\r\n{\r\n  if (m_CurValue < m_PrevValue + m_MinStepSize &&\r\n      m_CurValue + m_MinStepSize > m_PrevValue && m_NumExtraChars != 0)\r\n    return;\r\n  RePrintRatio();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/PercentPrinter.h",
    "content": "// PercentPrinter.h\r\n\r\n#ifndef __PERCENTPRINTER_H\r\n#define __PERCENTPRINTER_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/StdOutStream.h\"\r\n\r\nclass CPercentPrinter\r\n{\r\n  UInt64 m_MinStepSize;\r\n  UInt64 m_PrevValue;\r\n  UInt64 m_CurValue;\r\n  UInt64 m_Total;\r\n  int m_NumExtraChars;\r\npublic:\r\n  CStdOutStream *OutStream;\r\n\r\n  CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize),\r\n      m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}\r\n  void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }\r\n  void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }\r\n  void PrintString(const char *s);\r\n  void PrintString(const wchar_t *s);\r\n  void PrintNewLine();\r\n  void ClosePrint();\r\n  void RePrintRatio();\r\n  void PrintRatio();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp",
    "content": "// UpdateCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifdef COMPRESS_MT\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nusing namespace NWindows;\r\n\r\n#ifdef COMPRESS_MT\r\nstatic NSynchronization::CCriticalSection g_CriticalSection;\r\n#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);\r\n#else\r\n#define MT_LOCK\r\n#endif\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nstatic const char *kCreatingArchiveMessage = \"Creating archive \";\r\nstatic const char *kUpdatingArchiveMessage = \"Updating archive \";\r\nstatic const char *kScanningMessage = \"Scanning\";\r\n\r\n\r\nHRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n    (*OutStream) << \"Error: \" << name << \" is not supported archive\" << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartScanning()\r\n{\r\n  (*OutStream) << kScanningMessage;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::ScanProgress(UInt64 /* numFolders */, UInt64 /* numFiles */, const wchar_t * /* path */)\r\n{\r\n  return CheckBreak();\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)\r\n{\r\n  CantFindFiles.Add(name);\r\n  CantFindCodes.Add(systemError);\r\n  // m_PercentPrinter.ClosePrint();\r\n  if (!m_WarningsMode)\r\n  {\r\n    (*OutStream) << endl << endl;\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_WarningsMode = true;\r\n  }\r\n  m_PercentPrinter.PrintString(name);\r\n  m_PercentPrinter.PrintString(\":  WARNING: \");\r\n  m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n  m_PercentPrinter.PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishScanning()\r\n{\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)\r\n{\r\n  if(updating)\r\n    (*OutStream) << kUpdatingArchiveMessage;\r\n  else\r\n    (*OutStream) << kCreatingArchiveMessage;\r\n  if (name != 0)\r\n    (*OutStream) << name;\r\n  else\r\n    (*OutStream) << \"StdOut\";\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishArchive()\r\n{\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::Finilize()\r\n{\r\n  MT_LOCK\r\n  if (m_NeedBeClosed)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.ClosePrint();\r\n    }\r\n    if (!StdOutMode && m_NeedNewLine)\r\n    {\r\n      m_PercentPrinter.PrintNewLine();\r\n      m_NeedNewLine = false;\r\n    }\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)\r\n{\r\n  MT_LOCK\r\n  if (EnablePercents)\r\n    m_PercentPrinter.SetTotal(size);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  MT_LOCK\r\n  if (completeValue != NULL)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.SetRatio(*completeValue);\r\n      m_PercentPrinter.PrintRatio();\r\n      m_NeedBeClosed = true;\r\n    }\r\n  }\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)\r\n{\r\n  MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  if(isAnti)\r\n    m_PercentPrinter.PrintString(\"Anti item    \");\r\n  else\r\n    m_PercentPrinter.PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)\r\n{\r\n  MT_LOCK\r\n  FailedCodes.Add(systemError);\r\n  FailedFiles.Add(name);\r\n  // if (systemError == ERROR_SHARING_VIOLATION)\r\n  {\r\n    m_PercentPrinter.ClosePrint();\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_PercentPrinter.PrintString(\"WARNING: \");\r\n    m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n    return S_FALSE;\r\n  }\r\n  // return systemError;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )\r\n{\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  #ifdef _NO_CRYPTO\r\n\r\n  *passwordIsDefined = false;\r\n  return StringToBstr(L\"\", password);\r\n  \r\n  #else\r\n  \r\n  if (!PasswordIsDefined)\r\n  {\r\n    if (AskPassword)\r\n    {\r\n      Password = GetPassword(OutStream);\r\n      PasswordIsDefined = true;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  return StringToBstr(Password, password);\r\n  \r\n  #endif\r\n  \r\n}\r\n\r\n/*\r\nHRESULT CUpdateCallbackConsole::ShowDeleteFile(const wchar_t *name)\r\n{\r\n  // MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  RINOK(Finilize());\r\n  m_PercentPrinter.PrintString(\"Deleting  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.h",
    "content": "// UpdateCallbackConsole.h\r\n\r\n#ifndef __UPDATECALLBACKCONSOLE_H\r\n#define __UPDATECALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"PercentPrinter.h\"\r\n#include \"../Common/Update.h\"\r\n\r\nclass CUpdateCallbackConsole: public IUpdateCallbackUI2\r\n{\r\n  CPercentPrinter m_PercentPrinter;\r\n  bool m_NeedBeClosed;\r\n  bool m_NeedNewLine;\r\n\r\n  bool m_WarningsMode;\r\n\r\n  CStdOutStream *OutStream;\r\npublic:\r\n  bool EnablePercents;\r\n  bool StdOutMode;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n  #endif\r\n\r\n  CUpdateCallbackConsole():\r\n      m_PercentPrinter(1 << 16),\r\n      #ifndef _NO_CRYPTO\r\n      PasswordIsDefined(false),\r\n      AskPassword(false),\r\n      #endif\r\n      StdOutMode(false),\r\n      EnablePercents(true),\r\n      m_WarningsMode(false)\r\n      {}\r\n  \r\n  ~CUpdateCallbackConsole() { Finilize(); }\r\n  void Init(CStdOutStream *outStream)\r\n  {\r\n    m_NeedBeClosed = false;\r\n    m_NeedNewLine = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n    OutStream = outStream;\r\n    m_PercentPrinter.OutStream = outStream;\r\n  }\r\n\r\n  INTERFACE_IUpdateCallbackUI2(;)\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  UStringVector CantFindFiles;\r\n  CRecordVector<HRESULT> CantFindCodes;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp",
    "content": "// UserInputUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StdInStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"UserInputUtils.h\"\r\n\r\nstatic const char kYes = 'Y';\r\nstatic const char kNo = 'N';\r\nstatic const char kYesAll = 'A';\r\nstatic const char kNoAll = 'S';\r\nstatic const char kAutoRenameAll = 'U';\r\nstatic const char kQuit = 'Q';\r\n\r\nstatic const char *kFirstQuestionMessage = \"?\\n\";\r\nstatic const char *kHelpQuestionMessage =\r\n  \"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? \";\r\n\r\n// return true if pressed Quite;\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << kFirstQuestionMessage;\r\n  for(;;)\r\n  {\r\n    (*outStream) << kHelpQuestionMessage;\r\n    AString scannedString = g_StdIn.ScanStringUntilNewLine();\r\n    scannedString.Trim();\r\n    if(!scannedString.IsEmpty())\r\n      switch(::MyCharUpper(scannedString[0]))\r\n      {\r\n        case kYes:\r\n          return NUserAnswerMode::kYes;\r\n        case kNo:\r\n          return NUserAnswerMode::kNo;\r\n        case kYesAll:\r\n          return NUserAnswerMode::kYesAll;\r\n        case kNoAll:\r\n          return NUserAnswerMode::kNoAll;\r\n        case kAutoRenameAll:\r\n          return NUserAnswerMode::kAutoRenameAll;\r\n        case kQuit:\r\n          return NUserAnswerMode::kQuit;\r\n      }\r\n  }\r\n}\r\n\r\nUString GetPassword(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << \"\\nEnter password:\";\r\n  outStream->Flush();\r\n  AString oemPassword = g_StdIn.ScanStringUntilNewLine();\r\n  return MultiByteToUnicodeString(oemPassword, CP_OEMCP);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/UserInputUtils.h",
    "content": "// UserInputUtils.h\r\n\r\n#ifndef __USERINPUTUTILS_H\r\n#define __USERINPUTUTILS_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n\r\nnamespace NUserAnswerMode {\r\n\r\nenum EEnum\r\n{\r\n  kYes,\r\n  kNo,\r\n  kYesAll,\r\n  kNoAll,\r\n  kAutoRenameAll,\r\n  kQuit\r\n};\r\n}\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);\r\nUString GetPassword(CStdOutStream *outStream);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/7zip/UI/Console/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../  \\\r\n  -DCOMPRESS_MT \\\r\n  -DWIN_LONG_PATH \\\r\n  -DEXTERNAL_LZMA \\\r\n  -DEXTERNAL_CODECS \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n  -D_7ZIP_LARGE_PAGES \\\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Registry.obj \\\r\n  $O\\System.obj \\\r\n  $O\\Time.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\n!include \"../../Crc2.mak\"\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $O\\CopyCoder.obj \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\CopyCoder.obj: ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n!include \"../../Crc.mak\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Build.mak",
    "content": "!IFDEF CPU\r\n!IFNDEF NO_BUFFEROVERFLOWU\r\nLIBS = $(LIBS) bufferoverflowU.lib\r\n!ENDIF\r\n!ENDIF\r\n\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IF \"$(CPU)\" != \"IA64\"\r\n!IF \"$(CPU)\" != \"AMD64\"\r\nMY_ML = ml\r\n!ELSE\r\nMY_ML = ml64\r\n!ENDIF\r\n!ENDIF\r\n\r\nCOMPL_ASM = $(MY_ML) -c -Fo$O/ $**\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -WX -EHsc -Gr -Gy -GR-\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\n!IFDEF NEW_COMPILER\r\nCFLAGS = $(CFLAGS) -W4 -GS- -Zc:forScope\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -W3\r\n!ENDIF\r\n\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF -OPT:ICF\r\n\r\n!IFDEF DEF_FILE\r\nLFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)\r\n!ENDIF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL_PCH  = $(CPP) $(CFLAGS_O1) -Yc\"StdAfx.h\" -Fp$O/a.pch $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) -Yu\"StdAfx.h\" -Fp$O/a.pch $**\r\n\r\nall: $(PROGPATH)\r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch\r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS) $(DEF_FILE)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n$O\\resource.res: $(*B).rc\r\n\trc -fo$@ $**\r\n$O\\StdAfx.obj: $(*B).cpp\r\n\t$(COMPL_PCH)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/AutoPtr.h",
    "content": "// Common/AutoPtr.h\r\n\r\n#ifndef __COMMON_AUTOPTR_H\r\n#define __COMMON_AUTOPTR_H\r\n\r\ntemplate<class T> class CMyAutoPtr\r\n{\r\n  T *_p;\r\npublic:\r\n  CMyAutoPtr(T *p = 0) : _p(p) {}\r\n  CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {}\r\n  CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p)\r\n  {\r\n    reset(p.release());\r\n    return (*this);\r\n  }\r\n  ~CMyAutoPtr() { delete _p; }\r\n  T& operator*() const { return *_p; }\r\n  // T* operator->() const { return (&**this); }\r\n  T* get() const { return _p; }\r\n  T* release()\r\n  {\r\n    T *tmp = _p;\r\n    _p = 0;\r\n    return tmp;\r\n  }\r\n  void reset(T* p = 0)\r\n  {\r\n    if (p != _p)\r\n      delete _p;\r\n    _p = p;\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/Buffer.h",
    "content": "// Common/Buffer.h\r\n\r\n#ifndef __COMMON_BUFFER_H\r\n#define __COMMON_BUFFER_H\r\n\r\n#include \"Defs.h\"\r\n\r\ntemplate <class T> class CBuffer\r\n{\r\nprotected:\r\n  size_t _capacity;\r\n  T *_items;\r\npublic:\r\n  void Free()\r\n  {\r\n    delete []_items;\r\n    _items = 0;\r\n    _capacity = 0;\r\n  }\r\n  CBuffer(): _capacity(0), _items(0) {};\r\n  CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }\r\n  CBuffer(size_t size): _items(0),  _capacity(0) {  SetCapacity(size); }\r\n  virtual ~CBuffer() { delete []_items; }\r\n  operator T *() { return _items; };\r\n  operator const T *() const { return _items; };\r\n  size_t GetCapacity() const { return  _capacity; }\r\n  void SetCapacity(size_t newCapacity)\r\n  {\r\n    if (newCapacity == _capacity)\r\n      return;\r\n    T *newBuffer;\r\n    if (newCapacity > 0)\r\n    {\r\n      newBuffer = new T[newCapacity];\r\n      if (_capacity > 0)\r\n        memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));\r\n    }\r\n    else\r\n      newBuffer = 0;\r\n    delete []_items;\r\n    _items = newBuffer;\r\n    _capacity = newCapacity;\r\n  }\r\n  CBuffer& operator=(const CBuffer &buffer)\r\n  {\r\n    Free();\r\n    if (buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nbool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  if (b1.GetCapacity() != b2.GetCapacity())\r\n    return false;\r\n  for (size_t i = 0; i < b1.GetCapacity(); i++)\r\n    if (b1[i] != b2[i])\r\n      return false;\r\n  return true;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  return !(b1 == b2);\r\n}\r\n\r\ntypedef CBuffer<char> CCharBuffer;\r\ntypedef CBuffer<wchar_t> CWCharBuffer;\r\ntypedef CBuffer<unsigned char> CByteBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/7zCrc.h\"\r\n}\r\n\r\nstruct CCRCTableInit { CCRCTableInit() { CrcGenerateTable(); } } g_CRCTableInit;\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nbool CInFile::OpenShared(const char *name, bool)\r\n{\r\n  return Open(name);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nbool COutFile::Open(const char *name, DWORD creationDisposition)\r\n{\r\n  return Create(name, false);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  bool OpenShared(const char *name, bool shareForWrite);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  bool Open(const char *name, DWORD creationDisposition);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else\r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  for (;;)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      break;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{\r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */);\r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms,\r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0)\r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while (pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for (int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len)\r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if (temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if (_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString:\r\n      case NSwitchType::kUnLimitedPostString:\r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for (int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\r\n    const UString &commandString, UString &postString)\r\n{\r\n  for (int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if (commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"MyString.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  {\r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms);\r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms,\r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\r\n    const UString &commandString, UString &postString);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/DynamicBuffer.h",
    "content": "// Common/DynamicBuffer.h\r\n\r\n#ifndef __COMMON_DYNAMICBUFFER_H\r\n#define __COMMON_DYNAMICBUFFER_H\r\n\r\n#include \"Buffer.h\"\r\n\r\ntemplate <class T> class CDynamicBuffer: public CBuffer<T>\r\n{\r\n  void GrowLength(size_t size)\r\n  {\r\n    size_t delta;\r\n    if (this->_capacity > 64)\r\n      delta = this->_capacity / 4;\r\n    else if (this->_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    delta = MyMax(delta, size);\r\n    SetCapacity(this->_capacity + delta);\r\n  }\r\npublic:\r\n  CDynamicBuffer(): CBuffer<T>() {};\r\n  CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};\r\n  CDynamicBuffer(size_t size): CBuffer<T>(size) {};\r\n  CDynamicBuffer& operator=(const CDynamicBuffer &buffer)\r\n  {\r\n    this->Free();\r\n    if (buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n  void EnsureCapacity(size_t capacity)\r\n  {\r\n    if (this->_capacity < capacity)\r\n      GrowLength(capacity - this->_capacity);\r\n  }\r\n};\r\n\r\ntypedef CDynamicBuffer<char> CCharDynamicBuffer;\r\ntypedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;\r\ntypedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/IntToString.cpp",
    "content": "// Common/IntToString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"IntToString.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)\r\n{\r\n  if (base < 2 || base > 36)\r\n  {\r\n    *s = '\\0';\r\n    return;\r\n  }\r\n  char temp[72];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    int delta = (int)(value % base);\r\n    temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));\r\n    value /= base;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s)\r\n{\r\n  wchar_t temp[32];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = L'\\0';\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = '-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = L'-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/IntToString.h",
    "content": "// Common/IntToString.h\r\n\r\n#ifndef __COMMON_INTTOSTRING_H\r\n#define __COMMON_INTTOSTRING_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s);\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s);\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/ListFileUtils.cpp",
    "content": "// Common/ListFileUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MyWindows.h\"\r\n#include \"../Windows/FileIO.h\"\r\n\r\n#include \"ListFileUtils.h\"\r\n#include \"StringConvert.h\"\r\n#include \"UTFConvert.h\"\r\n\r\nstatic const char kQuoteChar     = '\\\"';\r\nstatic void RemoveQuote(UString &s)\r\n{\r\n  if (s.Length() >= 2)\r\n    if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)\r\n      s = s.Mid(1, s.Length() - 2);\r\n}\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)\r\n{\r\n  NWindows::NFile::NIO::CInFile file;\r\n  if (!file.Open(fileName))\r\n    return false;\r\n  UInt64 length;\r\n  if (!file.GetLength(length))\r\n    return false;\r\n  if (length > ((UInt32)1 << 31))\r\n    return false;\r\n  AString s;\r\n  char *p = s.GetBuffer((int)length + 1);\r\n  UInt32 processed;\r\n  if (!file.Read(p, (UInt32)length, processed))\r\n    return false;\r\n  p[(UInt32)length] = 0;\r\n  s.ReleaseBuffer();\r\n  file.Close();\r\n\r\n  UString u;\r\n  #ifdef CP_UTF8\r\n  if (codePage == CP_UTF8)\r\n  {\r\n    if (!ConvertUTF8ToUnicode(s, u))\r\n      return false;\r\n  }\r\n  else\r\n  #endif\r\n    u = MultiByteToUnicodeString(s, codePage);\r\n  if (!u.IsEmpty())\r\n  {\r\n    if (u[0] == 0xFEFF)\r\n      u.Delete(0);\r\n  }\r\n\r\n  UString t;\r\n  for (int i = 0; i < u.Length(); i++)\r\n  {\r\n    wchar_t c = u[i];\r\n    if (c == L'\\n' || c == 0xD)\r\n    {\r\n      t.Trim();\r\n      RemoveQuote(t);\r\n      if (!t.IsEmpty())\r\n        resultStrings.Add(t);\r\n      t.Empty();\r\n    }\r\n    else\r\n      t += c;\r\n  }\r\n  t.Trim();\r\n  RemoveQuote(t);\r\n  if (!t.IsEmpty())\r\n    resultStrings.Add(t);\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/ListFileUtils.h",
    "content": "// Common/ListFileUtils.h\r\n\r\n#ifndef __COMMON_LISTFILEUTILS_H\r\n#define __COMMON_LISTFILEUTILS_H\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRESULT __result_ = (x); if (__result_ != S_OK) return __result_; }\r\n#endif\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p)\r\n  {\r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p)\r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\ninline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr)\r\n{\r\n  *bstr = ::SysAllocString(src);\r\n  return (*bstr != 0) ? S_OK : E_OUTOFMEMORY;\r\n}\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR(): m_str(NULL) {}\r\n  CMyComBSTR(LPCOLESTR src) { m_str = ::SysAllocString(src); }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR src)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(src);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const\r\n  {\r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memcpy(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  /*\r\n  void Attach(BSTR src) { m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  */\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) {\r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \\\r\n    { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \\\r\n    MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n    MY_QUERYINTERFACE_ENTRY(i)\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyException.h",
    "content": "// Common/Exception.h\r\n\r\n#ifndef __COMMON_EXCEPTION_H\r\n#define __COMMON_EXCEPTION_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\nstruct CSystemException\r\n{\r\n  HRESULT ErrorCode;\r\n  CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline int operator==(REFGUID g1, REFGUID g2)\r\n{\r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return 0;\r\n  return 1;\r\n}\r\ninline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyString.cpp",
    "content": "// Common/MyString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <ctype.h>\r\n#endif\r\n\r\n#ifndef _UNICODE\r\n#include \"StringConvert.h\"\r\n#endif\r\n\r\n#include \"MyString.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1);\r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1),\r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{\r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1));\r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{\r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1));\r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1);\r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1),\r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n/*\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{\r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyString.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{\r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{\r\n  T *destStart = dest;\r\n  while ((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n// int MyStringCompareNoCase(const char *s1, const char  *s2);\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if (pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex,\r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n  int _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if (realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if (newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if (_capacity > 0)\r\n    {\r\n      for (int i = 0; i < _length; i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n    }\r\n    _chars = newBuffer;\r\n    _chars[_length] = 0;\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize)\r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0) { SetCapacity(3); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;}\r\n\r\n  // The minimum size of the character buffer in characters.\r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if (minBufLength >= _capacity)\r\n      SetCapacity(minBufLength);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if (newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if (&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int Compare(const T *s) const\r\n    { return MyStringCompare(_chars, s); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const T *s) const\r\n    { return MyStringCompareNoCase(_chars, s); }\r\n\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for (int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    charSet += (T)' ';\r\n    charSet += (T)'\\n';\r\n    charSet += (T)'\\t';\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if (pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for (int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0)\r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0)\r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct\r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else\r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyVector.cpp",
    "content": "// Common/MyVector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector() { ClearAndFree(); }\r\n\r\nvoid CBaseRecordVector::ClearAndFree()\r\n{\r\n  Clear();\r\n  delete []((unsigned char *)_items);\r\n  _capacity = 0;\r\n  _size = 0;\r\n  _items = 0;\r\n}\r\n\r\nvoid CBaseRecordVector::Clear() { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index) { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if (_size != _capacity)\r\n    return;\r\n  int delta = 1;\r\n  if (_capacity >= 64)\r\n    delta = _capacity / 4;\r\n  else if (_capacity >= 8)\r\n    delta = 8;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  // if (newCapacity <= _capacity)\r\n  if (newCapacity == _capacity)\r\n    return;\r\n  if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))\r\n    throw 1052353;\r\n  size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;\r\n  if (newSize / _itemSize != (size_t)(unsigned)newCapacity)\r\n    throw 1052354;\r\n  unsigned char *p = NULL;\r\n  if (newSize > 0)\r\n  {\r\n    p = new unsigned char[newSize];\r\n    if (p == 0)\r\n      throw 1052355;\r\n    int numRecordsToMove = (_size < newCapacity ? _size : newCapacity);\r\n    memcpy(p, _items, _itemSize * numRecordsToMove);\r\n  }\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::ReserveDown()\r\n{\r\n  Reserve(_size);\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize,\r\n    ((unsigned char  *)_items) + srcIndex * _itemSize,\r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyVector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n  int _capacity;\r\n  int _size;\r\n  void *_items;\r\n  size_t _itemSize;\r\n  \r\n  void ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; }\r\npublic:\r\n  CBaseRecordVector(size_t itemSize): _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n  virtual ~CBaseRecordVector();\r\n  void ClearAndFree();\r\n  int Size() const { return _size; }\r\n  bool IsEmpty() const { return (_size == 0); }\r\n  void Reserve(int newCapacity);\r\n  void ReserveDown();\r\n  virtual void Delete(int index, int num = 1);\r\n  void Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector(): CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v): CBaseRecordVector(sizeof(T)) { *this = v; }\r\n  CRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for (int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  int Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n  void Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n  T& operator[](int index) { return ((T *)_items)[index]; }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  T& Back() { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  int AddToUniqueSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    T temp = p[k];\r\n    for (;;)\r\n    {\r\n      int s = (k << 1);\r\n      if (s > size)\r\n        break;\r\n      if (s < size && compare(p + s + 1, p + s, param) > 0)\r\n        s++;\r\n      if (compare(&temp, p + s, param) >= 0)\r\n        break;\r\n      p[k] = p[s];\r\n      k = s;\r\n    }\r\n    p[k] = temp;\r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    int size = _size;\r\n    if (size <= 1)\r\n      return;\r\n    T* p = (&Front()) - 1;\r\n    {\r\n      int i = size / 2;\r\n      do\r\n        SortRefDown(p, i, size, compare, param);\r\n      while (--i != 0);\r\n    }\r\n    do\r\n    {\r\n      T temp = p[size];\r\n      p[size--] = p[1];\r\n      p[1] = temp;\r\n      SortRefDown(p, 1, size, compare, param);\r\n    }\r\n    while (size > 1);\r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector() {};\r\n  ~CObjectVector() { Clear(); };\r\n  CObjectVector(const CObjectVector &v) { *this = v; }\r\n  CObjectVector& operator=(const CObjectVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CObjectVector& operator+=(const CObjectVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for (int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n  T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Back() { return operator[](_size - 1); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  int Add(const T& item) { return CPointerVector::Add(new T(item)); }\r\n  void Insert(int index, const T& item) { CPointerVector::Insert(index, new T(item)); }\r\n  virtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for (int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for (int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param)\r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#define CHAR_PATH_SEPARATOR '\\\\'\r\n#define WCHAR_PATH_SEPARATOR L'\\\\'\r\n#define STRING_PATH_SEPARATOR \"\\\\\"\r\n#define WSTRING_PATH_SEPARATOR L\"\\\\\"\r\n\r\n#else\r\n\r\n#define CHAR_PATH_SEPARATOR '/'\r\n#define WCHAR_PATH_SEPARATOR L'/'\r\n#define STRING_PATH_SEPARATOR \"/\"\r\n#define WSTRING_PATH_SEPARATOR L\"/\"\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\n\r\n#undef BYTE\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\n\r\n#undef WORD\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\n\r\n#undef DWORD\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOTIMPL ((HRESULT)0x80004001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall\r\n#else\r\n#define STDMETHODCALLTYPE\r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct\r\n\r\n#ifdef __cplusplus\r\n\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n  #ifndef _WIN32\r\n  virtual ~IUnknown() {}\r\n  #endif\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#endif\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\r\n  VT_EMPTY = 0,\r\n  VT_NULL = 1,\r\n  VT_I2 = 2,\r\n  VT_I4 = 3,\r\n  VT_R4 = 4,\r\n  VT_R8 = 5,\r\n  VT_CY = 6,\r\n  VT_DATE = 7,\r\n  VT_BSTR = 8,\r\n  VT_DISPATCH = 9,\r\n  VT_ERROR = 10,\r\n  VT_BOOL = 11,\r\n  VT_VARIANT = 12,\r\n  VT_UNKNOWN = 13,\r\n  VT_DECIMAL = 14,\r\n  VT_I1 = 16,\r\n  VT_UI1 = 17,\r\n  VT_UI2 = 18,\r\n  VT_UI4 = 19,\r\n  VT_I8 = 20,\r\n  VT_UI8 = 21,\r\n  VT_INT = 22,\r\n  VT_UINT = 23,\r\n  VT_VOID = 24,\r\n  VT_HRESULT = 25,\r\n  VT_FILETIME = 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\n#ifdef __cplusplus\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union\r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\n\r\n#endif\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\r\n  STREAM_SEEK_SET = 0,\r\n  STREAM_SEEK_CUR = 1,\r\n  STREAM_SEEK_END = 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\n#ifdef _WIN32\r\nvoid *\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n#endif\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\n#ifdef _WIN32\r\nvoid\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator delete(void *p) throw();\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/StdInStream.cpp",
    "content": "// Common/StdInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n#include \"StdInStream.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kIllegalChar = '\\0';\r\nstatic const char kNewLineChar = '\\n';\r\n\r\nstatic const char *kEOFMessage = \"Unexpected end of input stream\";\r\nstatic const char *kReadErrorMessage  =\"Error reading input stream\";\r\nstatic const char *kIllegalCharMessage = \"Illegal character in input stream\";\r\n\r\nstatic LPCTSTR kFileOpenMode = TEXT(\"r\");\r\n\r\nCStdInStream g_StdIn(stdin);\r\n\r\nbool CStdInStream::Open(LPCTSTR fileName)\r\n{\r\n  Close();\r\n  _stream = _tfopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdInStream::Close()\r\n{\r\n  if (!_streamIsOpen)\r\n    return true;\r\n  _streamIsOpen = (fclose(_stream) != 0);\r\n  return !_streamIsOpen;\r\n}\r\n\r\nCStdInStream::~CStdInStream()\r\n{\r\n  Close();\r\n}\r\n\r\nAString CStdInStream::ScanStringUntilNewLine()\r\n{\r\n  AString s;\r\n  for (;;)\r\n  {\r\n    int intChar = GetChar();\r\n    if (intChar == EOF)\r\n      throw kEOFMessage;\r\n    char c = char(intChar);\r\n    if (c == kIllegalChar)\r\n      throw kIllegalCharMessage;\r\n    if (c == kNewLineChar)\r\n      break;\r\n    s += c;\r\n  }\r\n  return s;\r\n}\r\n\r\nvoid CStdInStream::ReadToString(AString &resultString)\r\n{\r\n  resultString.Empty();\r\n  int c;\r\n  while ((c = GetChar()) != EOF)\r\n    resultString += char(c);\r\n}\r\n\r\nbool CStdInStream::Eof()\r\n{\r\n  return (feof(_stream) != 0);\r\n}\r\n\r\nint CStdInStream::GetChar()\r\n{\r\n  int c = fgetc(_stream); // getc() doesn't work in BeOS?\r\n  if (c == EOF && !Eof())\r\n    throw kReadErrorMessage;\r\n  return c;\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/StdInStream.h",
    "content": "// Common/StdInStream.h\r\n\r\n#ifndef __COMMON_STDINSTREAM_H\r\n#define __COMMON_STDINSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nclass CStdInStream\r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdInStream(): _streamIsOpen(false) {};\r\n  CStdInStream(FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdInStream();\r\n  bool Open(LPCTSTR fileName);\r\n  bool Close();\r\n\r\n  AString ScanStringUntilNewLine();\r\n  void ReadToString(AString &resultString);\r\n\r\n  bool Eof();\r\n  int GetChar();\r\n};\r\n\r\nextern CStdInStream g_StdIn;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/StdOutStream.cpp",
    "content": "// Common/StdOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n\r\n#include \"StdOutStream.h\"\r\n#include \"IntToString.h\"\r\n#include \"StringConvert.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kNewLineChar =  '\\n';\r\n\r\nstatic const char *kFileOpenMode = \"wt\";\r\n\r\nCStdOutStream  g_StdOut(stdout);\r\nCStdOutStream  g_StdErr(stderr);\r\n\r\nbool CStdOutStream::Open(const char *fileName)\r\n{\r\n  Close();\r\n  _stream = fopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdOutStream::Close()\r\n{\r\n  if (!_streamIsOpen)\r\n    return true;\r\n  if (fclose(_stream) != 0)\r\n    return false;\r\n  _stream = 0;\r\n  _streamIsOpen = false;\r\n  return true;\r\n}\r\n\r\nbool CStdOutStream::Flush()\r\n{\r\n  return (fflush(_stream) == 0);\r\n}\r\n\r\nCStdOutStream::~CStdOutStream ()\r\n{\r\n  Close();\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream  &))\r\n{\r\n  (*aFunction)(*this);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream)\r\n{\r\n  return outStream << kNewLineChar;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const char *string)\r\n{\r\n  fputs(string, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const wchar_t *string)\r\n{\r\n  *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(char c)\r\n{\r\n  fputc(c, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(int number)\r\n{\r\n  char textString[32];\r\n  ConvertInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(UInt64 number)\r\n{\r\n  char textString[32];\r\n  ConvertUInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/StdOutStream.h",
    "content": "// Common/StdOutStream.h\r\n\r\n#ifndef __COMMON_STDOUTSTREAM_H\r\n#define __COMMON_STDOUTSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Types.h\"\r\n\r\nclass CStdOutStream\r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdOutStream (): _streamIsOpen(false), _stream(0) {};\r\n  CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdOutStream ();\r\n  operator FILE *() { return _stream; }\r\n  bool Open(const char *fileName);\r\n  bool Close();\r\n  bool Flush();\r\n  CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream  &));\r\n  CStdOutStream & operator<<(const char *string);\r\n  CStdOutStream & operator<<(const wchar_t *string);\r\n  CStdOutStream & operator<<(char c);\r\n  CStdOutStream & operator<<(int number);\r\n  CStdOutStream & operator<<(UInt64 number);\r\n};\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream);\r\n\r\nextern CStdOutStream g_StdOut;\r\nextern CStdOutStream g_StdErr;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString,\r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()),\r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if (numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed)\r\n{\r\n  AString dest;\r\n  defaultCharWasUsed = false;\r\n  if (!s.IsEmpty())\r\n  {\r\n    int numRequiredBytes = s.Length() * 2;\r\n    BOOL defUsed;\r\n    int numChars = WideCharToMultiByte(codePage, 0, s, s.Length(),\r\n        dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1,\r\n        &defaultChar, &defUsed);\r\n    defaultCharWasUsed = (defUsed != FALSE);\r\n    #ifndef _WIN32_WCE\r\n    if (numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    dest.ReleaseBuffer(numChars);\r\n  }\r\n  return dest;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  bool defaultCharWasUsed;\r\n  return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed);\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage, char defaultChar, bool &defaultCharWasUsed);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    UInt32 v;\r\n    if (c >= '0' && c <= '9') v = (c - '0');\r\n    else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A');\r\n    else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a');\r\n    else\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 4;\r\n    result |= v;\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Types.h\"\r\n}\r\n\r\ntypedef int HRes;\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/UTFConvert.cpp",
    "content": "// UTFConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UTFConvert.h\"\r\n#include \"Types.h\"\r\n\r\nstatic const Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nstatic Bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, size_t srcLen)\r\n{\r\n  size_t destPos = 0, srcPos = 0;\r\n  for (;;)\r\n  {\r\n    Byte c;\r\n    int numAdds;\r\n    if (srcPos == srcLen)\r\n    {\r\n      *destLen = destPos;\r\n      return True;\r\n    }\r\n    c = (Byte)src[srcPos++];\r\n\r\n    if (c < 0x80)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (wchar_t)c;\r\n      destPos++;\r\n      continue;\r\n    }\r\n    if (c < 0xC0)\r\n      break;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (c < kUtf8Limits[numAdds])\r\n        break;\r\n    UInt32 value = (c - kUtf8Limits[numAdds - 1]);\r\n\r\n    do\r\n    {\r\n      Byte c2;\r\n      if (srcPos == srcLen)\r\n        break;\r\n      c2 = (Byte)src[srcPos++];\r\n      if (c2 < 0x80 || c2 >= 0xC0)\r\n        break;\r\n      value <<= 6;\r\n      value |= (c2 - 0x80);\r\n    }\r\n    while (--numAdds != 0);\r\n    \r\n    if (value < 0x10000)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (wchar_t)value;\r\n      destPos++;\r\n    }\r\n    else\r\n    {\r\n      value -= 0x10000;\r\n      if (value >= 0x100000)\r\n        break;\r\n      if (dest)\r\n      {\r\n        dest[destPos + 0] = (wchar_t)(0xD800 + (value >> 10));\r\n        dest[destPos + 1] = (wchar_t)(0xDC00 + (value & 0x3FF));\r\n      }\r\n      destPos += 2;\r\n    }\r\n  }\r\n  *destLen = destPos;\r\n  return False;\r\n}\r\n\r\nstatic Bool Utf16_To_Utf8(char *dest, size_t *destLen, const wchar_t *src, size_t srcLen)\r\n{\r\n  size_t destPos = 0, srcPos = 0;\r\n  for (;;)\r\n  {\r\n    unsigned numAdds;\r\n    UInt32 value;\r\n    if (srcPos == srcLen)\r\n    {\r\n      *destLen = destPos;\r\n      return True;\r\n    }\r\n    value = src[srcPos++];\r\n    if (value < 0x80)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (char)value;\r\n      destPos++;\r\n      continue;\r\n    }\r\n    if (value >= 0xD800 && value < 0xE000)\r\n    {\r\n      UInt32 c2;\r\n      if (value >= 0xDC00 || srcPos == srcLen)\r\n        break;\r\n      c2 = src[srcPos++];\r\n      if (c2 < 0xDC00 || c2 >= 0xE000)\r\n        break;\r\n      value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n    }\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n        break;\r\n    if (dest)\r\n      dest[destPos] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n    destPos++;\r\n    do\r\n    {\r\n      numAdds--;\r\n      if (dest)\r\n        dest[destPos] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      destPos++;\r\n    }\r\n    while (numAdds != 0);\r\n  }\r\n  *destLen = destPos;\r\n  return False;\r\n}\r\n\r\nbool ConvertUTF8ToUnicode(const AString &src, UString &dest)\r\n{\r\n  dest.Empty();\r\n  size_t destLen = 0;\r\n  Utf8_To_Utf16(NULL, &destLen, src, src.Length());\r\n  wchar_t *p = dest.GetBuffer((int)destLen);\r\n  Bool res = Utf8_To_Utf16(p, &destLen, src, src.Length());\r\n  p[destLen] = 0;\r\n  dest.ReleaseBuffer();\r\n  return res ? true : false;\r\n}\r\n\r\nbool ConvertUnicodeToUTF8(const UString &src, AString &dest)\r\n{\r\n  dest.Empty();\r\n  size_t destLen = 0;\r\n  Utf16_To_Utf8(NULL, &destLen, src, src.Length());\r\n  char *p = dest.GetBuffer((int)destLen);\r\n  Bool res = Utf16_To_Utf8(p, &destLen, src, src.Length());\r\n  p[destLen] = 0;\r\n  dest.ReleaseBuffer();\r\n  return res ? true : false;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/UTFConvert.h",
    "content": "// Common/UTFConvert.h\r\n\r\n#ifndef __COMMON_UTFCONVERT_H\r\n#define __COMMON_UTFCONVERT_H\r\n\r\n#include \"MyString.h\"\r\n\r\nbool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);\r\nbool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/Wildcard.cpp",
    "content": "// Common/Wildcard.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Wildcard.h\"\r\n\r\nbool g_CaseSensitive =\r\n  #ifdef _WIN32\r\n    false;\r\n  #else\r\n    true;\r\n  #endif\r\n\r\nstatic const wchar_t kAnyCharsChar = L'*';\r\nstatic const wchar_t kAnyCharChar = L'?';\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t kDirDelimiter1 = L'\\\\';\r\n#endif\r\nstatic const wchar_t kDirDelimiter2 = L'/';\r\n\r\nstatic const UString kWildCardCharSet = L\"?*\";\r\n\r\nstatic const UString kIllegalWildCardFileNameChars=\r\n  L\"\\x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\xA\\xB\\xC\\xD\\xE\\xF\"\r\n  L\"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F\"\r\n  L\"\\\"/:<>\\\\|\";\r\n\r\n\r\nstatic inline bool IsCharDirLimiter(wchar_t c)\r\n{\r\n  return (\r\n    #ifdef _WIN32\r\n    c == kDirDelimiter1 ||\r\n    #endif\r\n    c == kDirDelimiter2);\r\n}\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2)\r\n{\r\n  if (g_CaseSensitive)\r\n    return s1.Compare(s2);\r\n  return s1.CompareNoCase(s2);\r\n}\r\n\r\n// -----------------------------------------\r\n// this function compares name with mask\r\n// ? - any char\r\n// * - any char or empty\r\n\r\nstatic bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t m = *mask;\r\n    wchar_t c = *name;\r\n    if (m == 0)\r\n      return (c == 0);\r\n    if (m == kAnyCharsChar)\r\n    {\r\n      if (EnhancedMaskTest(mask + 1, name))\r\n        return true;\r\n      if (c == 0)\r\n        return false;\r\n    }\r\n    else\r\n    {\r\n      if (m == kAnyCharChar)\r\n      {\r\n        if (c == 0)\r\n          return false;\r\n      }\r\n      else if (m != c)\r\n        if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))\r\n          return false;\r\n      mask++;\r\n    }\r\n    name++;\r\n  }\r\n}\r\n\r\n// --------------------------------------------------\r\n// Splits path to strings\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts)\r\n{\r\n  pathParts.Clear();\r\n  UString name;\r\n  int len = path.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = path[i];\r\n    if (IsCharDirLimiter(c))\r\n    {\r\n      pathParts.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  pathParts.Add(name);\r\n}\r\n\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  dirPrefix = path.Left(i + 1);\r\n  name = path.Mid(i + 1);\r\n}\r\n\r\nUString ExtractDirPrefixFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Left(i + 1);\r\n}\r\n\r\nUString ExtractFileNameFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Mid(i + 1);\r\n}\r\n\r\n\r\nbool CompareWildCardWithName(const UString &mask, const UString &name)\r\n{\r\n  return EnhancedMaskTest(mask, name);\r\n}\r\n\r\nbool DoesNameContainWildCard(const UString &path)\r\n{\r\n  return (path.FindOneOf(kWildCardCharSet) >= 0);\r\n}\r\n\r\n\r\n// ----------------------------------------------------------'\r\n// NWildcard\r\n\r\nnamespace NWildcard {\r\n\r\n\r\n/*\r\nM = MaskParts.Size();\r\nN = TestNameParts.Size();\r\n\r\n                           File                          Dir\r\nForFile     req   M<=N  [N-M, N)                          -\r\n         nonreq   M=N   [0, M)                            -\r\n \r\nForDir      req   M<N   [0, M) ... [N-M-1, N-1)  same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\nForBoth     req   m<=N  [0, M) ... [N-M, N)      same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\n*/\r\n\r\nbool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (!isFile && !ForDir)\r\n    return false;\r\n  int delta = (int)pathParts.Size() - (int)PathParts.Size();\r\n  if (delta < 0)\r\n    return false;\r\n  int start = 0;\r\n  int finish = 0;\r\n  if (isFile)\r\n  {\r\n    if (!ForDir && !Recursive && delta !=0)\r\n      return false;\r\n    if (!ForFile && delta == 0)\r\n      return false;\r\n    if (!ForDir && Recursive)\r\n      start = delta;\r\n  }\r\n  if (Recursive)\r\n  {\r\n    finish = delta;\r\n    if (isFile && !ForFile)\r\n      finish = delta - 1;\r\n  }\r\n  for (int d = start; d <= finish; d++)\r\n  {\r\n    int i;\r\n    for (i = 0; i < PathParts.Size(); i++)\r\n      if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))\r\n        break;\r\n    if (i == PathParts.Size())\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nint CCensorNode::FindSubNode(const UString &name) const\r\n{\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (CompareFileNames(SubNodes[i].Name, name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensorNode::AddItemSimple(bool include, CItem &item)\r\n{\r\n  if (include)\r\n    IncludeItems.Add(item);\r\n  else\r\n    ExcludeItems.Add(item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, CItem &item)\r\n{\r\n  if (item.PathParts.Size() <= 1)\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  const UString &front = item.PathParts.Front();\r\n  if (DoesNameContainWildCard(front))\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  int index = FindSubNode(front);\r\n  if (index < 0)\r\n    index = SubNodes.Add(CCensorNode(front, this));\r\n  item.PathParts.Delete(0);\r\n  SubNodes[index].AddItem(include, item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)\r\n{\r\n  CItem item;\r\n  SplitPathToParts(path, item.PathParts);\r\n  item.Recursive = recursive;\r\n  item.ForFile = forFile;\r\n  item.ForDir = forDir;\r\n  AddItem(include, item);\r\n}\r\n\r\nbool CCensorNode::NeedCheckSubDirs() const\r\n{\r\n  for (int i = 0; i < IncludeItems.Size(); i++)\r\n  {\r\n    const CItem &item = IncludeItems[i];\r\n    if (item.Recursive || item.PathParts.Size() > 1)\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::AreThereIncludeItems() const\r\n{\r\n  if (IncludeItems.Size() > 0)\r\n    return true;\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (SubNodes[i].AreThereIncludeItems())\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const\r\n{\r\n  const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;\r\n  for (int i = 0; i < items.Size(); i++)\r\n    if (items[i].CheckPath(pathParts, isFile))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const\r\n{\r\n  if (CheckPathCurrent(false, pathParts, isFile))\r\n  {\r\n    include = false;\r\n    return true;\r\n  }\r\n  include = true;\r\n  bool finded = CheckPathCurrent(true, pathParts, isFile);\r\n  if (pathParts.Size() == 1)\r\n    return finded;\r\n  int index = FindSubNode(pathParts.Front());\r\n  if (index >= 0)\r\n  {\r\n    UStringVector pathParts2 = pathParts;\r\n    pathParts2.Delete(0);\r\n    if (SubNodes[index].CheckPath(pathParts2, isFile, include))\r\n      return true;\r\n  }\r\n  return finded;\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPath(pathParts, isFile, include);\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool include;\r\n  if (CheckPath(path, isFile, include))\r\n    return include;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (CheckPathCurrent(include, pathParts, isFile))\r\n    return true;\r\n  if (Parent == 0)\r\n    return false;\r\n  pathParts.Insert(0, Name);\r\n  return Parent->CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n\r\n/*\r\nbool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n*/\r\n\r\nvoid CCensorNode::AddItem2(bool include, const UString &path, bool recursive)\r\n{\r\n  if (path.IsEmpty())\r\n    return;\r\n  bool forFile = true;\r\n  bool forFolder = true;\r\n  UString path2 = path;\r\n  if (IsCharDirLimiter(path[path.Length() - 1]))\r\n  {\r\n    path2.Delete(path.Length() - 1);\r\n    forFile = false;\r\n  }\r\n  AddItem(include, path2, recursive, forFile, forFolder);\r\n}\r\n\r\nvoid CCensorNode::ExtendExclude(const CCensorNode &fromNodes)\r\n{\r\n  ExcludeItems += fromNodes.ExcludeItems;\r\n  for (int i = 0; i < fromNodes.SubNodes.Size(); i++)\r\n  {\r\n    const CCensorNode &node = fromNodes.SubNodes[i];\r\n    int subNodeIndex = FindSubNode(node.Name);\r\n    if (subNodeIndex < 0)\r\n      subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));\r\n    SubNodes[subNodeIndex].ExtendExclude(node);\r\n  }\r\n}\r\n\r\nint CCensor::FindPrefix(const UString &prefix) const\r\n{\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n    if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensor::AddItem(bool include, const UString &path, bool recursive)\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  bool forFile = true;\r\n  if (pathParts.Back().IsEmpty())\r\n  {\r\n    forFile = false;\r\n    pathParts.DeleteBack();\r\n  }\r\n  const UString &front = pathParts.Front();\r\n  bool isAbs = false;\r\n  if (front.IsEmpty())\r\n    isAbs = true;\r\n  else if (front.Length() == 2 && front[1] == L':')\r\n    isAbs = true;\r\n  else\r\n  {\r\n    for (int i = 0; i < pathParts.Size(); i++)\r\n    {\r\n      const UString &part = pathParts[i];\r\n      if (part == L\"..\" || part == L\".\")\r\n      {\r\n        isAbs = true;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  int numAbsParts = 0;\r\n  if (isAbs)\r\n    if (pathParts.Size() > 1)\r\n      numAbsParts = pathParts.Size() - 1;\r\n    else\r\n      numAbsParts = 1;\r\n  UString prefix;\r\n  for (int i = 0; i < numAbsParts; i++)\r\n  {\r\n    const UString &front = pathParts.Front();\r\n    if (DoesNameContainWildCard(front))\r\n      break;\r\n    prefix += front;\r\n    prefix += WCHAR_PATH_SEPARATOR;\r\n    pathParts.Delete(0);\r\n  }\r\n  int index = FindPrefix(prefix);\r\n  if (index < 0)\r\n    index = Pairs.Add(CPair(prefix));\r\n\r\n  CItem item;\r\n  item.PathParts = pathParts;\r\n  item.ForDir = true;\r\n  item.ForFile = forFile;\r\n  item.Recursive = recursive;\r\n  Pairs[index].Head.AddItem(include, item);\r\n}\r\n\r\nbool CCensor::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool finded = false;\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n  {\r\n    bool include;\r\n    if (Pairs[i].Head.CheckPath(path, isFile, include))\r\n    {\r\n      if (!include)\r\n        return false;\r\n      finded = true;\r\n    }\r\n  }\r\n  return finded;\r\n}\r\n\r\nvoid CCensor::ExtendExclude()\r\n{\r\n  int i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (Pairs[i].Prefix.IsEmpty())\r\n      break;\r\n  if (i == Pairs.Size())\r\n    return;\r\n  int index = i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (index != i)\r\n      Pairs[i].Head.ExtendExclude(Pairs[index].Head);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Common/Wildcard.h",
    "content": "// Common/Wildcard.h\r\n\r\n#ifndef __COMMON_WILDCARD_H\r\n#define __COMMON_WILDCARD_H\r\n\r\n#include \"MyString.h\"\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2);\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts);\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);\r\nUString ExtractDirPrefixFromPath(const UString &path);\r\nUString ExtractFileNameFromPath(const UString &path);\r\nbool DoesNameContainWildCard(const UString &path);\r\nbool CompareWildCardWithName(const UString &mask, const UString &name);\r\n\r\nnamespace NWildcard {\r\n\r\nstruct CItem\r\n{\r\n  UStringVector PathParts;\r\n  bool Recursive;\r\n  bool ForFile;\r\n  bool ForDir;\r\n  bool CheckPath(const UStringVector &pathParts, bool isFile) const;\r\n};\r\n\r\nclass CCensorNode\r\n{\r\n  CCensorNode *Parent;\r\n  bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;\r\n  void AddItemSimple(bool include, CItem &item);\r\n  bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;\r\npublic:\r\n  CCensorNode(): Parent(0) { };\r\n  CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };\r\n  UString Name;\r\n  CObjectVector<CCensorNode> SubNodes;\r\n  CObjectVector<CItem> IncludeItems;\r\n  CObjectVector<CItem> ExcludeItems;\r\n\r\n  int FindSubNode(const UString &path) const;\r\n\r\n  void AddItem(bool include, CItem &item);\r\n  void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);\r\n  void AddItem2(bool include, const UString &path, bool recursive);\r\n\r\n  bool NeedCheckSubDirs() const;\r\n  bool AreThereIncludeItems() const;\r\n\r\n  bool CheckPath(const UString &path, bool isFile, bool &include) const;\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n\r\n  bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;\r\n  // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;\r\n  void ExtendExclude(const CCensorNode &fromNodes);\r\n};\r\n\r\nstruct CPair\r\n{\r\n  UString Prefix;\r\n  CCensorNode Head;\r\n  CPair(const UString &prefix): Prefix(prefix) { };\r\n};\r\n\r\nclass CCensor\r\n{\r\n  int FindPrefix(const UString &prefix) const;\r\npublic:\r\n  CObjectVector<CPair> Pairs;\r\n  bool AllAreRelative() const\r\n    { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }\r\n  void AddItem(bool include, const UString &path, bool recursive);\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n  void ExtendExclude();\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/DLL.cpp",
    "content": "// Windows/DLL.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DLL.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nCLibrary::~CLibrary()\r\n{\r\n  Free();\r\n}\r\n\r\nbool CLibrary::Free()\r\n{\r\n  if (_module == 0)\r\n    return true;\r\n  // MessageBox(0, TEXT(\"\"), TEXT(\"Free\"), 0);\r\n  // Sleep(5000);\r\n  if (!::FreeLibrary(_module))\r\n    return false;\r\n  _module = 0;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadOperations(HMODULE newModule)\r\n{\r\n  if (newModule == NULL)\r\n    return false;\r\n  if (!Free())\r\n    return false;\r\n  _module = newModule;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"LoadEx\"), 0);\r\n  return LoadOperations(::LoadLibraryEx(fileName, NULL, flags));\r\n}\r\n\r\nbool CLibrary::Load(LPCTSTR fileName)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"Load\"), 0);\r\n  // Sleep(5000);\r\n  // OutputDebugString(fileName);\r\n  // OutputDebugString(TEXT(\"\\n\"));\r\n  return LoadOperations(::LoadLibrary(fileName));\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\nCSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n\r\nbool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));\r\n  return LoadEx(GetSysPath(fileName), flags);\r\n}\r\nbool CLibrary::Load(LPCWSTR fileName)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryW(fileName));\r\n  return Load(GetSysPath(fileName));\r\n}\r\n#endif\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result)\r\n{\r\n  result.Empty();\r\n  TCHAR fullPath[MAX_PATH + 2];\r\n  DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1);\r\n  if (size <= MAX_PATH && size != 0)\r\n  {\r\n    result = fullPath;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result)\r\n{\r\n  result.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    wchar_t fullPath[MAX_PATH + 2];\r\n    DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);\r\n    if (size <= MAX_PATH && size != 0)\r\n    {\r\n      result = fullPath;\r\n      return true;\r\n    }\r\n    return false;\r\n  }\r\n  CSysString resultSys;\r\n  if (!MyGetModuleFileName(hModule, resultSys))\r\n    return false;\r\n  result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());\r\n  return true;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/DLL.h",
    "content": "// Windows/DLL.h\r\n\r\n#ifndef __WINDOWS_DLL_H\r\n#define __WINDOWS_DLL_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nclass CLibrary\r\n{\r\n  bool LoadOperations(HMODULE newModule);\r\nprotected:\r\n  HMODULE _module;\r\npublic:\r\n  operator HMODULE() const { return _module; }\r\n  HMODULE* operator&() { return &_module; }\r\n\r\n  CLibrary():_module(NULL) {};\r\n  ~CLibrary();\r\n  void Attach(HMODULE m)\r\n  {\r\n    Free();\r\n    _module = m;\r\n  }\r\n  HMODULE Detach()\r\n  {\r\n    HMODULE m = _module;\r\n    _module = NULL;\r\n    return m;\r\n  }\r\n\r\n  // operator HMODULE() const { return _module; };\r\n  bool IsLoaded() const { return (_module != NULL); };\r\n  bool Free();\r\n  bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCWSTR fileName);\r\n  #endif\r\n  FARPROC GetProcAddress(LPCSTR procName) const\r\n    { return ::GetProcAddress(_module, procName); }\r\n};\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result);\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result);\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\n#ifdef _WIN32\r\ninline bool LRESULTToBool(LRESULT value)\r\n  { return (value != FALSE); }\r\n#endif\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/Error.cpp",
    "content": "// Windows/Error.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifndef _UNICODE\r\n#include \"Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message)\r\n{\r\n  LPVOID msgBuf;\r\n  if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r\n      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n      NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)\r\n    return false;\r\n  message = (LPCTSTR)msgBuf;\r\n  ::LocalFree(msgBuf);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyFormatMessage(DWORD messageID, UString &message)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPVOID msgBuf;\r\n    if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r\n        FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n        NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)\r\n      return false;\r\n    message = (LPCWSTR)msgBuf;\r\n    ::LocalFree(msgBuf);\r\n    return true;\r\n  }\r\n  CSysString messageSys;\r\n  bool result = MyFormatMessage(messageID, messageSys);\r\n  message = GetUnicodeString(messageSys);\r\n  return result;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/Error.h",
    "content": "// Windows/Error.h\r\n\r\n#ifndef __WINDOWS_ERROR_H\r\n#define __WINDOWS_ERROR_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message);\r\ninline CSysString MyFormatMessage(DWORD messageID)\r\n{\r\n  CSysString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#ifdef _UNICODE\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n  { return MyFormatMessage(messageID); }\r\n#else\r\nbool MyFormatMessage(DWORD messageID, UString &message);\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n{\r\n  UString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileDir.cpp",
    "content": "// Windows/FileDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileDir.h\"\r\n#include \"FileName.h\"\r\n#include \"FileFind.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n// SetCurrentDirectory doesn't support \\\\?\\ prefix\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR fileName, UString &res);\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n#endif\r\n\r\nnamespace NDirectory {\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\nstatic UString GetUnicodePath(const CSysString &sysPath)\r\n  { return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }\r\nstatic CSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\nbool MyGetSystemDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetWindowsDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n\r\nbool MyGetSystemDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetSystemDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n{\r\n  #ifndef _UNICODE\r\n  if (!g_IsNT)\r\n  {\r\n    ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\r\n    return false;\r\n  }\r\n  #endif\r\n  HANDLE hDir = ::CreateFileW(fileName, GENERIC_WRITE,\r\n      FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n      NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (hDir == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      hDir = ::CreateFileW(longPath, GENERIC_WRITE,\r\n        FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  }\r\n  #endif\r\n\r\n  bool res = false;\r\n  if (hDir != INVALID_HANDLE_VALUE)\r\n  {\r\n    res = BOOLToBool(::SetFileTime(hDir, cTime, aTime, mTime));\r\n    ::CloseHandle(hDir);\r\n  }\r\n  return res;\r\n}\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (::SetFileAttributes(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyRemoveDirectory(LPCTSTR pathName)\r\n{\r\n  if (::RemoveDirectory(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2)\r\n{\r\n  if (!GetLongPathBase(s1, d1) || !GetLongPathBase(s2, d2))\r\n    return false;\r\n  if (d1.IsEmpty() && d2.IsEmpty()) return false;\r\n  if (d1.IsEmpty()) d1 = s1;\r\n  if (d2.IsEmpty()) d2 = s2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName)\r\n{\r\n  if (::MoveFile(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return MySetFileAttributes(GetSysPath(fileName), fileAttributes);\r\n  if (::SetFileAttributesW(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n\r\nbool MyRemoveDirectory(LPCWSTR pathName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyRemoveDirectory(GetSysPath(pathName));\r\n  if (::RemoveDirectoryW(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));\r\n  if (::MoveFileW(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nbool MyCreateDirectory(LPCTSTR pathName)\r\n{\r\n  if (::CreateDirectory(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyCreateDirectory(LPCWSTR pathName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyCreateDirectory(GetSysPath(pathName));\r\n  if (::CreateDirectoryW(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\n/*\r\nbool CreateComplexDirectory(LPCTSTR pathName)\r\n{\r\n  NName::CParsedPath path;\r\n  path.ParsePath(pathName);\r\n  CSysString fullPath = path.Prefix;\r\n  DWORD errorCode = ERROR_SUCCESS;\r\n  for (int i = 0; i < path.PathParts.Size(); i++)\r\n  {\r\n    const CSysString &string = path.PathParts[i];\r\n    if (string.IsEmpty())\r\n    {\r\n      if (i != path.PathParts.Size() - 1)\r\n        return false;\r\n      return true;\r\n    }\r\n    fullPath += path.PathParts[i];\r\n    if (!MyCreateDirectory(fullPath))\r\n    {\r\n      DWORD errorCode = GetLastError();\r\n      if (errorCode != ERROR_ALREADY_EXISTS)\r\n        return false;\r\n    }\r\n    fullPath += NName::kDirDelimiter;\r\n  }\r\n  return true;\r\n}\r\n*/\r\n\r\nbool CreateComplexDirectory(LPCTSTR _aPathName)\r\n{\r\n  CSysString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == ':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  CSysString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if (MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfo fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDir())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == ':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while (pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateComplexDirectory(LPCWSTR _aPathName)\r\n{\r\n  UString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == L':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  UString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if (MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfoW fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDir())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == L':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while (pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\nbool DeleteFileAlways(LPCTSTR name)\r\n{\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFile(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DeleteFileAlways(LPCWSTR name)\r\n{\r\n  if (!g_IsNT)\r\n    return DeleteFileAlways(GetSysPath(name));\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFileW(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nstatic bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)\r\n{\r\n  if (fileInfo.IsDir())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\n\r\nbool RemoveDirectoryWithSubItems(const CSysString &path)\r\n{\r\n  NFind::CFileInfo fileInfo;\r\n  CSysString pathPrefix = path + NName::kDirDelimiter;\r\n  {\r\n    NFind::CEnumerator enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));\r\n    while (enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)\r\n{\r\n  if (fileInfo.IsDir())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\nbool RemoveDirectoryWithSubItems(const UString &path)\r\n{\r\n  NFind::CFileInfoW fileInfo;\r\n  UString pathPrefix = path + UString(NName::kDirDelimiter);\r\n  {\r\n    NFind::CEnumeratorW enumerator(pathPrefix + UString(NName::kAnyStringWildcard));\r\n    while (enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\n\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)\r\n{\r\n  DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  shortPath.ReleaseBuffer();\r\n  return (needLength > 0 && needLength < MAX_PATH);\r\n}\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  LPTSTR fileNamePointer = 0;\r\n  LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n  DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n  resultPath.ReleaseBuffer();\r\n  if (needLength == 0)\r\n    return false;\r\n  if (needLength >= MAX_PATH)\r\n  {\r\n    #ifdef WIN_LONG_PATH2\r\n    needLength++;\r\n    buffer = resultPath.GetBuffer(needLength + 1);\r\n    DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength2 == 0 || needLength2 > needLength)\r\n    #endif\r\n      return false;\r\n  }\r\n  if (fileNamePointer == 0)\r\n    fileNamePartStartIndex = lstrlen(fileName);\r\n  else\r\n    fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR fileNamePointer = 0;\r\n    LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n    DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength == 0)\r\n      return false;\r\n    if (needLength >= MAX_PATH)\r\n    {\r\n      #ifdef WIN_LONG_PATH\r\n      needLength++;\r\n      buffer = resultPath.GetBuffer(needLength + 1);\r\n      DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n      resultPath.ReleaseBuffer();\r\n      if (needLength2 == 0 || needLength2 > needLength)\r\n      #endif\r\n        return false;\r\n    }\r\n    if (fileNamePointer == 0)\r\n      fileNamePartStartIndex = MyStringLen(fileName);\r\n    else\r\n      fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  }\r\n  else\r\n  {\r\n    CSysString sysPath;\r\n    if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))\r\n      return false;\r\n    UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));\r\n    UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));\r\n    fileNamePartStartIndex = resultPath1.Length();\r\n    resultPath = resultPath1 + resultPath2;\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n#endif\r\n\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetCurrentDirectory(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path)\r\n{\r\n  if (g_IsNT)\r\n    return BOOLToBool(::SetCurrentDirectoryW(path));\r\n  return MySetCurrentDirectory(GetSysPath(path));\r\n}\r\nbool MyGetCurrentDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetCurrentDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath, UINT32 &filePart)\r\n{\r\n  LPTSTR filePartPointer;\r\n  DWORD value = ::SearchPath(path, fileName, extension,\r\n    MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n  filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);\r\n  resultPath.ReleaseBuffer();\r\n  return (value > 0 && value <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath, UINT32 &filePart)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR filePartPointer = 0;\r\n    DWORD value = ::SearchPathW(path, fileName, extension,\r\n        MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n    filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);\r\n    resultPath.ReleaseBuffer();\r\n    return (value > 0 && value <= MAX_PATH);\r\n  }\r\n  \r\n  CSysString sysPath;\r\n  if (!MySearchPath(\r\n      path != 0 ? (LPCTSTR)GetSysPath(path): 0,\r\n      fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,\r\n      extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,\r\n      sysPath, filePart))\r\n    return false;\r\n  UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));\r\n  UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));\r\n  filePart = resultPath1.Length();\r\n  resultPath = resultPath1 + resultPath2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &path)\r\n{\r\n  path.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetTempPath(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)\r\n{\r\n  UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return number;\r\n}\r\n\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));\r\n    path.ReleaseBuffer();\r\n    return number;\r\n  }\r\n  CSysString sysPath;\r\n  UINT number = MyGetTempFileName(\r\n      dirPath ? (LPCTSTR)GetSysPath(dirPath): 0,\r\n      prefix ? (LPCTSTR)GetSysPath(prefix): 0,\r\n      sysPath);\r\n  path = GetUnicodePath(sysPath);\r\n  return number;\r\n}\r\n#endif\r\n\r\nUINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if (number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  CSysString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFile::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nUINT CTempFileW::Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if (number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFileW::Create(LPCWSTR prefix, UString &resultPath)\r\n{\r\n  UString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFileW::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFile tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!::DeleteFile(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if (NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectory::Create(LPCTSTR prefix)\r\n{\r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateTempDirectory(LPCWSTR prefix, UString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFileW tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!DeleteFileAlways(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if (NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectoryW::Create(LPCWSTR prefix)\r\n{\r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileDir.h",
    "content": "// Windows/FileDir.h\r\n\r\n#ifndef __WINDOWS_FILEDIR_H\r\n#define __WINDOWS_FILEDIR_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NDirectory {\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path);\r\nbool MyGetSystemDirectory(CSysString &path);\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path);\r\nbool MyGetSystemDirectory(UString &path);\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);\r\nbool MyRemoveDirectory(LPCTSTR pathName);\r\nbool MyCreateDirectory(LPCTSTR pathName);\r\nbool CreateComplexDirectory(LPCTSTR pathName);\r\nbool DeleteFileAlways(LPCTSTR name);\r\nbool RemoveDirectoryWithSubItems(const CSysString &path);\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);\r\nbool MyRemoveDirectory(LPCWSTR pathName);\r\nbool MyCreateDirectory(LPCWSTR pathName);\r\nbool CreateComplexDirectory(LPCWSTR pathName);\r\nbool DeleteFileAlways(LPCWSTR name);\r\nbool RemoveDirectoryWithSubItems(const UString &path);\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,\r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName);\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,\r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName);\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);\r\n#endif\r\n\r\ninline bool MySetCurrentDirectory(LPCTSTR path)\r\n  { return BOOLToBool(::SetCurrentDirectory(path)); }\r\nbool MyGetCurrentDirectory(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path);\r\nbool MyGetCurrentDirectory(UString &resultPath);\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath, UINT32 &filePart);\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath, UINT32 &filePart);\r\n#endif\r\n\r\ninline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n\r\n#ifndef _UNICODE\r\ninline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &resultPath);\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n#endif\r\n\r\nclass CTempFile\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _fileName;\r\npublic:\r\n  CTempFile(): _mustBeDeleted(false) {}\r\n  ~CTempFile() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n  bool Create(LPCTSTR prefix, CSysString &resultPath);\r\n  bool Remove();\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempFile CTempFileW;\r\n#else\r\nclass CTempFileW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _fileName;\r\npublic:\r\n  CTempFileW(): _mustBeDeleted(false) {}\r\n  ~CTempFileW() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n  bool Create(LPCWSTR prefix, UString &resultPath);\r\n  bool Remove();\r\n};\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);\r\n\r\nclass CTempDirectory\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _tempDir;\r\npublic:\r\n  const CSysString &GetPath() const { return _tempDir; }\r\n  CTempDirectory(): _mustBeDeleted(false) {}\r\n  ~CTempDirectory() { Remove();  }\r\n  bool Create(LPCTSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempDirectory CTempDirectoryW;\r\n#else\r\nclass CTempDirectoryW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _tempDir;\r\npublic:\r\n  const UString &GetPath() const { return _tempDir; }\r\n  CTempDirectoryW(): _mustBeDeleted(false) {}\r\n  ~CTempDirectoryW() { Remove();  }\r\n  bool Create(LPCWSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileFind.cpp",
    "content": "// Windows/FileFind.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileFind.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n\r\nnamespace NFind {\r\n\r\nstatic const TCHAR kDot = TEXT('.');\r\n\r\nbool CFileInfo::IsDots() const\r\n{\r\n  if (!IsDir() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileInfoW::IsDots() const\r\n{\r\n  if (!IsDir() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n#endif\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = fd.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfoW &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = fd.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage());\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n#endif\r\n  \r\n////////////////////////////////\r\n// CFindFile\r\n\r\nbool CFindFile::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::FindClose(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\n          \r\nbool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  WIN32_FIND_DATA fd;\r\n  _handle = ::FindFirstFile(wildcard, &fd);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(wildcard, longPath))\r\n      _handle = ::FindFirstFileW(longPath, &fd);\r\n  }\r\n  #endif\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return false;\r\n  ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW fd;\r\n    _handle = ::FindFirstFileW(wildcard, &fd);\r\n    #ifdef WIN_LONG_PATH\r\n    if (_handle == INVALID_HANDLE_VALUE)\r\n    {\r\n      UString longPath;\r\n      if (GetLongPath(wildcard, longPath))\r\n        _handle = ::FindFirstFileW(longPath, &fd);\r\n    }\r\n    #endif\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA fd;\r\n    _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard,\r\n        GetCurrentCodePage()), &fd);\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFindFile::FindNext(CFileInfo &fileInfo)\r\n{\r\n  WIN32_FIND_DATA fd;\r\n  bool result = BOOLToBool(::FindNextFile(_handle, &fd));\r\n  if (result)\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  return result;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindNext(CFileInfoW &fileInfo)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW fd;\r\n    if (!::FindNextFileW(_handle, &fd))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA fd;\r\n    if (!::FindNextFileA(_handle, &fd))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n#endif\r\n\r\nbool DoesFileExist(LPCTSTR name)\r\n{\r\n  CFileInfo fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DoesFileExist(LPCWSTR name)\r\n{\r\n  CFileInfoW fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n#endif\r\n\r\n/////////////////////////////////////\r\n// CEnumerator\r\n\r\nbool CEnumerator::NextAny(CFileInfo &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CEnumeratorW::NextAny(CFileInfoW &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#endif\r\n\r\n////////////////////////////////\r\n// CFindChangeNotification\r\n// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.\r\n\r\nbool CFindChangeNotification::Close()\r\n{\r\n  if (!IsHandleAllocated())\r\n    return true;\r\n  if (!::FindCloseChangeNotification(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n           \r\nHANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  _handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n\r\n#ifndef _UNICODE\r\nHANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  if (!g_IsNT)\r\n    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);\r\n  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  UINT32 size = GetLogicalDriveStrings(0, NULL);\r\n  if (size == 0)\r\n    return false;\r\n  CSysString buffer;\r\n  UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size));\r\n  if (newSize == 0)\r\n    return false;\r\n  if (newSize > size)\r\n    return false;\r\n  CSysString string;\r\n  for (UINT32 i = 0; i < newSize; i++)\r\n  {\r\n    TCHAR c = buffer[i];\r\n    if (c == TEXT('\\0'))\r\n    {\r\n      driveStrings.Add(string);\r\n      string.Empty();\r\n    }\r\n    else\r\n      string += c;\r\n  }\r\n  if (!string.IsEmpty())\r\n    return false;\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  if (g_IsNT)\r\n  {\r\n    UINT32 size = GetLogicalDriveStringsW(0, NULL);\r\n    if (size == 0)\r\n      return false;\r\n    UString buffer;\r\n    UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size));\r\n    if (newSize == 0)\r\n      return false;\r\n    if (newSize > size)\r\n      return false;\r\n    UString string;\r\n    for (UINT32 i = 0; i < newSize; i++)\r\n    {\r\n      WCHAR c = buffer[i];\r\n      if (c == L'\\0')\r\n      {\r\n        driveStrings.Add(string);\r\n        string.Empty();\r\n      }\r\n      else\r\n        string += c;\r\n    }\r\n    return string.IsEmpty();\r\n  }\r\n  CSysStringVector driveStringsA;\r\n  bool res = MyGetLogicalDriveStrings(driveStringsA);\r\n  for (int i = 0; i < driveStringsA.Size(); i++)\r\n    driveStrings.Add(GetUnicodeString(driveStringsA[i]));\r\n  return res;\r\n}\r\n#endif\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileFind.h",
    "content": "// Windows/FileFind.h\r\n\r\n#ifndef __WINDOWS_FILEFIND_H\r\n#define __WINDOWS_FILEFIND_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"../Common/Types.h\"\r\n#include \"FileName.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NFind {\r\n\r\nnamespace NAttributes\r\n{\r\n  inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }\r\n  inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; }\r\n  inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; }\r\n  inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; }\r\n  inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }\r\n  inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }\r\n  inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }\r\n}\r\n\r\nclass CFileInfoBase\r\n{\r\n  bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }\r\npublic:\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  DWORD Attrib;\r\n  \r\n  #ifndef _WIN32_WCE\r\n  UINT32 ReparseTag;\r\n  #else\r\n  DWORD ObjectID;\r\n  #endif\r\n\r\n  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }\r\n  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }\r\n  bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }\r\n  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }\r\n  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }\r\n  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }\r\n  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }\r\n  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }\r\n  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }\r\n  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }\r\n  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }\r\n  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }\r\n};\r\n\r\nclass CFileInfo: public CFileInfoBase\r\n{\r\npublic:\r\n  CSysString Name;\r\n  bool IsDots() const;\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CFileInfo CFileInfoW;\r\n#else\r\nclass CFileInfoW: public CFileInfoBase\r\n{\r\npublic:\r\n  UString Name;\r\n  bool IsDots() const;\r\n};\r\n#endif\r\n\r\nclass CFindFile\r\n{\r\n  friend class CEnumerator;\r\n  HANDLE _handle;\r\npublic:\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }\r\n  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindFile() {  Close(); }\r\n  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n  bool FindNext(CFileInfo &fileInfo);\r\n  #ifndef _UNICODE\r\n  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\n  bool FindNext(CFileInfoW &fileInfo);\r\n  #endif\r\n  bool Close();\r\n};\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n\r\nbool DoesFileExist(LPCTSTR name);\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\nbool DoesFileExist(LPCWSTR name);\r\n#endif\r\n\r\nclass CEnumerator\r\n{\r\n  CFindFile _findFile;\r\n  CSysString _wildcard;\r\n  bool NextAny(CFileInfo &fileInfo);\r\npublic:\r\n  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfo &fileInfo);\r\n  bool Next(CFileInfo &fileInfo, bool &found);\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CEnumerator CEnumeratorW;\r\n#else\r\nclass CEnumeratorW\r\n{\r\n  CFindFile _findFile;\r\n  UString _wildcard;\r\n  bool NextAny(CFileInfoW &fileInfo);\r\npublic:\r\n  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfoW &fileInfo);\r\n  bool Next(CFileInfoW &fileInfo, bool &found);\r\n};\r\n#endif\r\n\r\nclass CFindChangeNotification\r\n{\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE () { return _handle; }\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }\r\n  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindChangeNotification() { Close(); }\r\n  bool Close();\r\n  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #ifndef _UNICODE\r\n  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #endif\r\n  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings);\r\n#endif\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifdef WIN_LONG_PATH\r\n#include \"../Common/MyString.h\"\r\n#endif\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR s, UString &res)\r\n{\r\n  res.Empty();\r\n  int len = MyStringLen(s);\r\n  wchar_t c = s[0];\r\n  if (len < 1 || c == L'\\\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))\r\n    return true;\r\n  UString curDir;\r\n  bool isAbs = false;\r\n  if (len > 3)\r\n    isAbs = (s[1] == L':' && s[2] == L'\\\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));\r\n\r\n  if (!isAbs)\r\n    {\r\n      DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));\r\n      curDir.ReleaseBuffer();\r\n      if (needLength == 0 || needLength > MAX_PATH)\r\n        return false;\r\n      if (curDir[curDir.Length() - 1] != L'\\\\')\r\n        curDir += L'\\\\';\r\n    }\r\n  res = UString(L\"\\\\\\\\?\\\\\") + curDir + s;\r\n  return true;\r\n}\r\n\r\nbool GetLongPath(LPCWSTR path, UString &longPath)\r\n{\r\n  if (GetLongPathBase(path, longPath))\r\n    return !longPath.IsEmpty();\r\n  return false;\r\n}\r\n#endif\r\n\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode,\r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n      flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP),\r\n      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFileW(fileName, desiredAccess, shareMode,\r\n    (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n    flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::CloseHandle(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if (sizeLow == 0xFFFFFFFF)\r\n    if (::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if (::GetLastError() != NO_ERROR)\r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if (!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CTime = winFileInfo.ftCreationTime;\r\n  fileInfo.ATime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.MTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes;\r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\n// Probably in some version of Windows there are problems with other sizes:\r\n// for 32 MB (maybe also for 16 MB).\r\n// And message can be \"Network connection was lost\"\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 22);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, cTime, aTime, mTime)); }\r\n\r\nbool COutFile::SetMTime(const FILETIME *mTime) {  return SetTime(NULL, NULL, mTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if (!Seek(length, newPosition))\r\n    return false;\r\n  if (newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{\r\n  DWORD    Attributes;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  DWORD    VolumeSerialNumber;\r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks;\r\n  UInt64   FileIndex;\r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _handle(INVALID_HANDLE_VALUE){};\r\n  ~CFileBase();\r\n\r\n  bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition);\r\n  bool SeekToBegin();\r\n  bool SeekToEnd(UInt64 &newPosition);\r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\r\n  bool SetMTime(const FILETIME *mTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileMapping.cpp",
    "content": "// Windows/FileMapping.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileMapping.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NMapping {\r\n\r\n\r\n\r\n\r\n}}}"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileMapping.h",
    "content": "// Windows/FileMapping.h\r\n\r\n#ifndef __WINDOWS_FILEMAPPING_H\r\n#define __WINDOWS_FILEMAPPING_H\r\n\r\n#include \"Windows/Handle.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\n// namespace NFile {\r\n// namespace NMapping {\r\n\r\nclass CFileMapping: public CHandle\r\n{\r\npublic:\r\n  bool Create(HANDLE file, LPSECURITY_ATTRIBUTES attributes,\r\n    DWORD protect, UINT64 maximumSize, LPCTSTR name)\r\n  {\r\n    _handle = ::CreateFileMapping(file, attributes,\r\n      protect, DWORD(maximumSize >> 32), DWORD(maximumSize), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenFileMapping(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  LPVOID MapViewOfFile(DWORD desiredAccess, UINT64 fileOffset,\r\n      SIZE_T numberOfBytesToMap)\r\n  {\r\n    return ::MapViewOfFile(_handle, desiredAccess,\r\n        DWORD(fileOffset >> 32), DWORD(fileOffset), numberOfBytesToMap);\r\n  }\r\n\r\n  LPVOID MapViewOfFileEx(DWORD desiredAccess, UINT64 fileOffset,\r\n      SIZE_T numberOfBytesToMap, LPVOID baseAddress)\r\n  {\r\n    return ::MapViewOfFileEx(_handle, desiredAccess,\r\n      DWORD(fileOffset >> 32), DWORD(fileOffset),\r\n      numberOfBytesToMap, baseAddress);\r\n  }\r\n  \r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileName.cpp",
    "content": "// Windows/FileName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)\r\n    dirPath += kDirDelimiter;\r\n}\r\n\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)\r\n    dirPath += wchar_t(kDirDelimiter);\r\n}\r\n#endif\r\n\r\nconst wchar_t kExtensionDelimiter = L'.';\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\r\n    UString &pureName, UString &extensionDelimiter, UString &extension)\r\n{\r\n  int index = fullName.ReverseFind(kExtensionDelimiter);\r\n  if (index < 0)\r\n  {\r\n    pureName = fullName;\r\n    extensionDelimiter.Empty();\r\n    extension.Empty();\r\n  }\r\n  else\r\n  {\r\n    pureName = fullName.Left(index);\r\n    extensionDelimiter = kExtensionDelimiter;\r\n    extension = fullName.Mid(index + 1);\r\n  }\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/FileName.h",
    "content": "// Windows/FileName.h\r\n\r\n#ifndef __WINDOWS_FILENAME_H\r\n#define __WINDOWS_FILENAME_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nconst TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;\r\nconst TCHAR kAnyStringWildcard = '*';\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\\\'\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\\\'\r\n#endif\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\r\n    UString &pureName, UString &extensionDelimiter, UString &extension);\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/Handle.h",
    "content": "// Windows/Handle.h\r\n\r\n#ifndef __WINDOWS_HANDLE_H\r\n#define __WINDOWS_HANDLE_H\r\n\r\nnamespace NWindows {\r\n\r\nclass CHandle\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE() { return _handle; }\r\n  CHandle(): _handle(NULL) {}\r\n  ~CHandle() { Close(); }\r\n  bool Close()\r\n  {\r\n    if (_handle == NULL)\r\n      return true;\r\n    if (!::CloseHandle(_handle))\r\n      return false;\r\n    _handle = NULL;\r\n    return true;\r\n  }\r\n  void Attach(HANDLE handle)\r\n    { _handle = handle; }\r\n  HANDLE Detach()\r\n  {\r\n    HANDLE handle = _handle;\r\n    _handle = NULL;\r\n    return handle;\r\n  }\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/MemoryLock.cpp",
    "content": "// Common/MemoryLock.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\n#ifndef _UNICODE\r\ntypedef BOOL (WINAPI * OpenProcessTokenP)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);\r\ntypedef BOOL (WINAPI * LookupPrivilegeValueP)(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID  lpLuid);\r\ntypedef BOOL (WINAPI * AdjustTokenPrivilegesP)(HANDLE TokenHandle, BOOL DisableAllPrivileges,\r\n    PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength);\r\n#endif\r\n\r\n#ifdef _UNICODE\r\nbool EnableLockMemoryPrivilege(\r\n#else\r\nstatic bool EnableLockMemoryPrivilege2(HMODULE hModule,\r\n#endif\r\nbool enable)\r\n{\r\n  #ifndef _UNICODE\r\n  if (hModule == NULL)\r\n    return false;\r\n  OpenProcessTokenP openProcessToken = (OpenProcessTokenP)GetProcAddress(hModule, \"OpenProcessToken\");\r\n  LookupPrivilegeValueP lookupPrivilegeValue = (LookupPrivilegeValueP)GetProcAddress(hModule, \"LookupPrivilegeValueA\" );\r\n  AdjustTokenPrivilegesP adjustTokenPrivileges = (AdjustTokenPrivilegesP)GetProcAddress(hModule, \"AdjustTokenPrivileges\");\r\n  if (openProcessToken == NULL || adjustTokenPrivileges == NULL || lookupPrivilegeValue == NULL)\r\n    return false;\r\n  #endif\r\n\r\n  HANDLE token;\r\n  if (!\r\n    #ifdef _UNICODE\r\n    ::OpenProcessToken\r\n    #else\r\n    openProcessToken\r\n    #endif\r\n    (::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))\r\n    return false;\r\n  TOKEN_PRIVILEGES tp;\r\n  bool res = false;\r\n  if (\r\n    #ifdef _UNICODE\r\n    ::LookupPrivilegeValue\r\n    #else\r\n    lookupPrivilegeValue\r\n    #endif\r\n    (NULL, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)))\r\n  {\r\n    tp.PrivilegeCount = 1;\r\n    tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED: 0;\r\n    if (\r\n      #ifdef _UNICODE\r\n      ::AdjustTokenPrivileges\r\n      #else\r\n      adjustTokenPrivileges\r\n      #endif\r\n      (token, FALSE, &tp, 0, NULL, NULL))\r\n      res = (GetLastError() == ERROR_SUCCESS);\r\n  }\r\n  ::CloseHandle(token);\r\n  return res;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool EnableLockMemoryPrivilege(bool enable)\r\n{\r\n  HMODULE hModule = LoadLibrary(TEXT(\"Advapi32.dll\"));\r\n  if (hModule == NULL)\r\n    return false;\r\n  bool res = EnableLockMemoryPrivilege2(hModule, enable);\r\n  ::FreeLibrary(hModule);\r\n  return res;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/MemoryLock.h",
    "content": "// Windows/MemoryLock.h\r\n\r\n#ifndef __WINDOWS_MEMORYLOCK_H\r\n#define __WINDOWS_MEMORYLOCK_H\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\nbool EnableLockMemoryPrivilege(bool enable = true);\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/PropVariant.cpp",
    "content": "// Windows/PropVariant.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariant.h\"\r\n\r\n#include \"../Common/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nCPropVariant::CPropVariant(const PROPVARIANT& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(const CPropVariant& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(BSTR bstrSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = bstrSrc;\r\n}\r\n\r\nCPropVariant::CPropVariant(LPCOLESTR lpszSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = lpszSrc;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const CPropVariant& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\nCPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(BSTR bstrSrc)\r\n{\r\n  *this = (LPCOLESTR)bstrSrc;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)\r\n{\r\n  InternalClear();\r\n  vt = VT_BSTR;\r\n  wReserved1 = 0;\r\n  bstrVal = ::SysAllocString(lpszSrc);\r\n  if (bstrVal == NULL && lpszSrc != NULL)\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = E_OUTOFMEMORY;\r\n  }\r\n  return *this;\r\n}\r\n\r\n\r\nCPropVariant& CPropVariant::operator=(bool bSrc)\r\n{\r\n  if (vt != VT_BOOL)\r\n  {\r\n    InternalClear();\r\n    vt = VT_BOOL;\r\n  }\r\n  boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt32 value)\r\n{\r\n  if (vt != VT_UI4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI4;\r\n  }\r\n  ulVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt64 value)\r\n{\r\n  if (vt != VT_UI8)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI8;\r\n  }\r\n  uhVal.QuadPart = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const FILETIME &value)\r\n{\r\n  if (vt != VT_FILETIME)\r\n  {\r\n    InternalClear();\r\n    vt = VT_FILETIME;\r\n  }\r\n  filetime = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int32 value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  \r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Byte value)\r\n{\r\n  if (vt != VT_UI1)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI1;\r\n  }\r\n  bVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int16 value)\r\n{\r\n  if (vt != VT_I2)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I2;\r\n  }\r\n  iVal = value;\r\n  return *this;\r\n}\r\n\r\n/*\r\nCPropVariant& CPropVariant::operator=(LONG value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  return *this;\r\n}\r\n*/\r\n\r\nstatic HRESULT MyPropVariantClear(PROPVARIANT *propVariant)\r\n{\r\n  switch(propVariant->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      propVariant->vt = VT_EMPTY;\r\n      propVariant->wReserved1 = 0;\r\n      return S_OK;\r\n  }\r\n  return ::VariantClear((VARIANTARG *)propVariant);\r\n}\r\n\r\nHRESULT CPropVariant::Clear()\r\n{\r\n  return MyPropVariantClear(this);\r\n}\r\n\r\nHRESULT CPropVariant::Copy(const PROPVARIANT* pSrc)\r\n{\r\n  ::VariantClear((tagVARIANT *)this);\r\n  switch(pSrc->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));\r\n      return S_OK;\r\n  }\r\n  return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc));\r\n}\r\n\r\n\r\nHRESULT CPropVariant::Attach(PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(this, pSrc, sizeof(PROPVARIANT));\r\n  pSrc->vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::Detach(PROPVARIANT* pDest)\r\n{\r\n  HRESULT hr = MyPropVariantClear(pDest);\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(pDest, this, sizeof(PROPVARIANT));\r\n  vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::InternalClear()\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n  return hr;\r\n}\r\n\r\nvoid CPropVariant::InternalCopy(const PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Copy(pSrc);\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n}\r\n\r\nint CPropVariant::Compare(const CPropVariant &a)\r\n{\r\n  if (vt != a.vt)\r\n    return 0; // it's mean some bug\r\n  switch (vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return 0;\r\n    \r\n    /*\r\n    case VT_I1:\r\n      return MyCompare(cVal, a.cVal);\r\n    */\r\n    case VT_UI1:\r\n      return MyCompare(bVal, a.bVal);\r\n\r\n    case VT_I2:\r\n      return MyCompare(iVal, a.iVal);\r\n    case VT_UI2:\r\n      return MyCompare(uiVal, a.uiVal);\r\n    \r\n    case VT_I4:\r\n      return MyCompare(lVal, a.lVal);\r\n    /*\r\n    case VT_INT:\r\n      return MyCompare(intVal, a.intVal);\r\n    */\r\n    case VT_UI4:\r\n      return MyCompare(ulVal, a.ulVal);\r\n    /*\r\n    case VT_UINT:\r\n      return MyCompare(uintVal, a.uintVal);\r\n    */\r\n    case VT_I8:\r\n      return MyCompare(hVal.QuadPart, a.hVal.QuadPart);\r\n    case VT_UI8:\r\n      return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);\r\n\r\n    case VT_BOOL:\r\n      return -MyCompare(boolVal, a.boolVal);\r\n\r\n    case VT_FILETIME:\r\n      return ::CompareFileTime(&filetime, &a.filetime);\r\n    case VT_BSTR:\r\n      return 0; // Not implemented\r\n      // return MyCompare(aPropVarint.cVal);\r\n\r\n    default:\r\n      return 0;\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/PropVariant.h",
    "content": "// Windows/PropVariant.h\r\n\r\n#ifndef __WINDOWS_PROPVARIANT_H\r\n#define __WINDOWS_PROPVARIANT_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nclass CPropVariant : public tagPROPVARIANT\r\n{\r\npublic:\r\n  CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }\r\n  ~CPropVariant() { Clear(); }\r\n  CPropVariant(const PROPVARIANT& varSrc);\r\n  CPropVariant(const CPropVariant& varSrc);\r\n  CPropVariant(BSTR bstrSrc);\r\n  CPropVariant(LPCOLESTR lpszSrc);\r\n  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };\r\n  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }\r\n  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal = *(ULARGE_INTEGER*)&value; }\r\n  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }\r\n  CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }\r\n  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }\r\n  CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }\r\n  // CPropVariant(LONG value, VARTYPE vtSrc = VT_I4) { vt = vtSrc; lVal = value; }\r\n\r\n  CPropVariant& operator=(const CPropVariant& varSrc);\r\n  CPropVariant& operator=(const PROPVARIANT& varSrc);\r\n  CPropVariant& operator=(BSTR bstrSrc);\r\n  CPropVariant& operator=(LPCOLESTR lpszSrc);\r\n  CPropVariant& operator=(bool bSrc);\r\n  CPropVariant& operator=(UInt32 value);\r\n  CPropVariant& operator=(UInt64 value);\r\n  CPropVariant& operator=(const FILETIME &value);\r\n\r\n  CPropVariant& operator=(Int32 value);\r\n  CPropVariant& operator=(Byte value);\r\n  CPropVariant& operator=(Int16 value);\r\n  // CPropVariant& operator=(LONG  value);\r\n\r\n  HRESULT Clear();\r\n  HRESULT Copy(const PROPVARIANT* pSrc);\r\n  HRESULT Attach(PROPVARIANT* pSrc);\r\n  HRESULT Detach(PROPVARIANT* pDest);\r\n\r\n  HRESULT InternalClear();\r\n  void InternalCopy(const PROPVARIANT* pSrc);\r\n\r\n  int Compare(const CPropVariant &a1);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/PropVariantConversions.cpp",
    "content": "// PropVariantConversions.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariantConversions.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\nstatic UString ConvertUInt64ToString(UInt64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString ConvertInt64ToString(Int64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic char *UIntToStringSpec(char c, UInt32 value, char *s, int numPos)\r\n{\r\n  if (c != 0)\r\n    *s++ = c;\r\n  char temp[16];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (char)('0' + value % 10);\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  int i;\r\n  for (i = 0; i < numPos - pos; i++)\r\n    *s++ = '0';\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n  return s;\r\n}\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)\r\n{\r\n  s[0] = '\\0';\r\n  SYSTEMTIME st;\r\n  if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))\r\n    return false;\r\n  s = UIntToStringSpec(0, st.wYear, s, 4);\r\n  s = UIntToStringSpec('-', st.wMonth, s, 2);\r\n  s = UIntToStringSpec('-', st.wDay, s, 2);\r\n  if (includeTime)\r\n  {\r\n    s = UIntToStringSpec(' ', st.wHour, s, 2);\r\n    s = UIntToStringSpec(':', st.wMinute, s, 2);\r\n    if (includeSeconds)\r\n      UIntToStringSpec(':', st.wSecond, s, 2);\r\n  }\r\n  return true;\r\n}\r\n\r\nUString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds)\r\n{\r\n  char s[32];\r\n  ConvertFileTimeToString(fileTime, s,  includeTime, includeSeconds);\r\n  return GetUnicodeString(s);\r\n}\r\n \r\n\r\nUString ConvertPropVariantToString(const PROPVARIANT &prop)\r\n{\r\n  switch (prop.vt)\r\n  {\r\n    case VT_EMPTY: return UString();\r\n    case VT_BSTR: return prop.bstrVal;\r\n    case VT_UI1: return ConvertUInt64ToString(prop.bVal);\r\n    case VT_UI2: return ConvertUInt64ToString(prop.uiVal);\r\n    case VT_UI4: return ConvertUInt64ToString(prop.ulVal);\r\n    case VT_UI8: return ConvertUInt64ToString(prop.uhVal.QuadPart);\r\n    case VT_FILETIME: return ConvertFileTimeToString(prop.filetime, true, true);\r\n    // case VT_I1: return ConvertInt64ToString(prop.cVal);\r\n    case VT_I2: return ConvertInt64ToString(prop.iVal);\r\n    case VT_I4: return ConvertInt64ToString(prop.lVal);\r\n    case VT_I8: return ConvertInt64ToString(prop.hVal.QuadPart);\r\n    case VT_BOOL: return VARIANT_BOOLToBool(prop.boolVal) ? L\"+\" : L\"-\";\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 150245;\r\n      #else\r\n      return UString();\r\n      #endif\r\n  }\r\n}\r\n\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &prop)\r\n{\r\n  switch (prop.vt)\r\n  {\r\n    case VT_UI1: return prop.bVal;\r\n    case VT_UI2: return prop.uiVal;\r\n    case VT_UI4: return prop.ulVal;\r\n    case VT_UI8: return (UInt64)prop.uhVal.QuadPart;\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 151199;\r\n      #else\r\n      return 0;\r\n      #endif\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/PropVariantConversions.h",
    "content": "// Windows/PropVariantConversions.h\r\n\r\n#ifndef __PROPVARIANTCONVERSIONS_H\r\n#define __PROPVARIANTCONVERSIONS_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/MyString.h\"\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant);\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/Synchronization.cpp",
    "content": "// Windows/Synchronization.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Synchronization.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/Synchronization.h",
    "content": "// Windows/Synchronization.h\r\n\r\n#ifndef __WINDOWS_SYNCHRONIZATION_H\r\n#define __WINDOWS_SYNCHRONIZATION_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\n#ifdef _WIN32\r\n#include \"Handle.h\"\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\nclass CBaseEvent\r\n{\r\nprotected:\r\n  ::CEvent _object;\r\npublic:\r\n  bool IsCreated() { return Event_IsCreated(&_object) != 0; }\r\n  operator HANDLE() { return _object.handle; }\r\n  CBaseEvent() { Event_Construct(&_object); }\r\n  ~CBaseEvent() { Close(); }\r\n  WRes Close() { return Event_Close(&_object); }\r\n  #ifdef _WIN32\r\n  WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),\r\n        BoolToBOOL(initiallyOwn), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  #endif\r\n\r\n  WRes Set() { return Event_Set(&_object); }\r\n  // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }\r\n  WRes Reset() { return Event_Reset(&_object); }\r\n  WRes Lock() { return Event_Wait(&_object); }\r\n};\r\n\r\nclass CManualResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  WRes Create(bool initiallyOwn = false)\r\n  {\r\n    return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);\r\n  }\r\n  WRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return ManualResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  #ifdef _WIN32\r\n  WRes CreateWithName(bool initiallyOwn, LPCTSTR name)\r\n  {\r\n    return CBaseEvent::Create(true, initiallyOwn, name);\r\n  }\r\n  #endif\r\n};\r\n\r\nclass CAutoResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  WRes Create()\r\n  {\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  WRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\nclass CObject: public CHandle\r\n{\r\npublic:\r\n  WRes Lock(DWORD timeoutInterval = INFINITE)\r\n    { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }\r\n};\r\nclass CMutex: public CObject\r\n{\r\npublic:\r\n  WRes Create(bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Release()\r\n  {\r\n    return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();\r\n  }\r\n};\r\nclass CMutexLock\r\n{\r\n  CMutex *_object;\r\npublic:\r\n  CMutexLock(CMutex &object): _object(&object) { _object->Lock(); }\r\n  ~CMutexLock() { _object->Release(); }\r\n};\r\n#endif\r\n\r\nclass CSemaphore\r\n{\r\n  ::CSemaphore _object;\r\npublic:\r\n  CSemaphore() { Semaphore_Construct(&_object); }\r\n  ~CSemaphore() { Close(); }\r\n  WRes Close() {  return Semaphore_Close(&_object); }\r\n  operator HANDLE() { return _object.handle; }\r\n  WRes Create(UInt32 initiallyCount, UInt32 maxCount)\r\n  {\r\n    return Semaphore_Create(&_object, initiallyCount, maxCount);\r\n  }\r\n  WRes Release() { return Semaphore_Release1(&_object); }\r\n  WRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }\r\n  WRes Lock() { return Semaphore_Wait(&_object); }\r\n};\r\n\r\nclass CCriticalSection\r\n{\r\n  ::CCriticalSection _object;\r\npublic:\r\n  CCriticalSection() { CriticalSection_Init(&_object); }\r\n  ~CCriticalSection() { CriticalSection_Delete(&_object); }\r\n  void Enter() { CriticalSection_Enter(&_object); }\r\n  void Leave() { CriticalSection_Leave(&_object); }\r\n};\r\n\r\nclass CCriticalSectionLock\r\n{\r\n  CCriticalSection *_object;\r\n  void Unlock()  { _object->Leave(); }\r\npublic:\r\n  CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); }\r\n  ~CCriticalSectionLock() { Unlock(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/System.cpp",
    "content": "// Windows/System.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"System.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors()\r\n{\r\n  SYSTEM_INFO systemInfo;\r\n  GetSystemInfo(&systemInfo);\r\n  return (UInt32)systemInfo.dwNumberOfProcessors;\r\n}\r\n\r\n#if !defined(_WIN64) && defined(__GNUC__)\r\n\r\ntypedef struct _MY_MEMORYSTATUSEX {\r\n  DWORD dwLength;\r\n  DWORD dwMemoryLoad;\r\n  DWORDLONG ullTotalPhys;\r\n  DWORDLONG ullAvailPhys;\r\n  DWORDLONG ullTotalPageFile;\r\n  DWORDLONG ullAvailPageFile;\r\n  DWORDLONG ullTotalVirtual;\r\n  DWORDLONG ullAvailVirtual;\r\n  DWORDLONG ullAvailExtendedVirtual;\r\n} MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX;\r\n\r\n#else\r\n\r\n#define MY_MEMORYSTATUSEX MEMORYSTATUSEX\r\n#define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX\r\n\r\n#endif\r\n\r\ntypedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);\r\n\r\nUInt64 GetRamSize()\r\n{\r\n  MY_MEMORYSTATUSEX stat;\r\n  stat.dwLength = sizeof(stat);\r\n  #ifdef _WIN64\r\n  if (!::GlobalMemoryStatusEx(&stat))\r\n    return 0;\r\n  return stat.ullTotalPhys;\r\n  #else\r\n  GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")),\r\n        \"GlobalMemoryStatusEx\");\r\n  if (globalMemoryStatusEx != 0)\r\n    if (globalMemoryStatusEx(&stat))\r\n      return stat.ullTotalPhys;\r\n  {\r\n    MEMORYSTATUS stat;\r\n    stat.dwLength = sizeof(stat);\r\n    GlobalMemoryStatus(&stat);\r\n    return stat.dwTotalPhys;\r\n  }\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/System.h",
    "content": "// Windows/System.h\r\n\r\n#ifndef __WINDOWS_SYSTEM_H\r\n#define __WINDOWS_SYSTEM_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors();\r\nUInt64 GetRamSize();\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/Thread.h",
    "content": "// Windows/Thread.h\r\n\r\n#ifndef __WINDOWS_THREAD_H\r\n#define __WINDOWS_THREAD_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\nnamespace NWindows {\r\n\r\nclass CThread\r\n{\r\n  ::CThread thread;\r\npublic:\r\n  CThread() { Thread_Construct(&thread); }\r\n  ~CThread() { Close(); }\r\n  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }\r\n  WRes Close()  { return Thread_Close(&thread); }\r\n  WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n    { return Thread_Create(&thread, startAddress, parameter); }\r\n  WRes Wait() { return Thread_Wait(&thread); }\r\n  \r\n  #ifdef _WIN32\r\n  operator HANDLE() { return thread.handle; }\r\n  void Attach(HANDLE handle) { thread.handle = handle; }\r\n  HANDLE Detach() { HANDLE h = thread.handle; thread.handle = NULL; return h; }\r\n  DWORD Resume() { return ::ResumeThread(thread.handle); }\r\n  DWORD Suspend() { return ::SuspendThread(thread.handle); }\r\n  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }\r\n  int GetPriority() { return ::GetThreadPriority(thread.handle); }\r\n  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }\r\n  #endif\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/Time.cpp",
    "content": "// Windows/Time.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Time.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)\r\n{\r\n  return BOOLToBool(::DosDateTimeToFileTime((UInt16)(dosTime >> 16), (UInt16)(dosTime & 0xFFFF), &fileTime));\r\n}\r\n\r\nstatic const UInt32 kHighDosTime = 0xFF9FBF7D;\r\nstatic const UInt32 kLowDosTime = 0x210000;\r\n\r\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)\r\n{\r\n  WORD datePart, timePart;\r\n  if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))\r\n  {\r\n    dosTime = (fileTime.dwHighDateTime >= 0x01C00000) ? kHighDosTime : kLowDosTime;\r\n    return false;\r\n  }\r\n  dosTime = (((UInt32)datePart) << 16) + timePart;\r\n  return true;\r\n}\r\n\r\nstatic const UInt32 kNumTimeQuantumsInSecond = 10000000;\r\nstatic const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;\r\n\r\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)\r\n{\r\n  UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;\r\n  fileTime.dwLowDateTime = (DWORD)v;\r\n  fileTime.dwHighDateTime = (DWORD)(v >> 32);\r\n}\r\n\r\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)\r\n{\r\n  UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;\r\n  if (winTime < kUnixTimeStartValue)\r\n  {\r\n    unixTime = 0;\r\n    return false;\r\n  }\r\n  winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;\r\n  if (winTime > 0xFFFFFFFF)\r\n  {\r\n    unixTime = 0xFFFFFFFF;\r\n    return false;\r\n  }\r\n  unixTime = (UInt32)winTime;\r\n  return true;\r\n}\r\n\r\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\r\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds)\r\n{\r\n  resSeconds = 0;\r\n  if (year < 1601 || year >= 10000 || month < 1 || month > 12 ||\r\n      day < 1 || day > 31 || hour > 23 || min > 59 || sec > 59)\r\n    return false;\r\n  UInt32 numYears = year - 1601;\r\n  UInt32 numDays = numYears * 365 + numYears / 4 - numYears / 100 + numYears / 400;\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  month--;\r\n  for (unsigned i = 0; i < month; i++)\r\n    numDays += ms[i];\r\n  numDays += day - 1;\r\n  resSeconds = ((UInt64)(numDays * 24 + hour) * 60 + min) * 60 + sec;\r\n  return true;\r\n}\r\n\r\nvoid GetCurUtcFileTime(FILETIME &ft)\r\n{\r\n  SYSTEMTIME st;\r\n  GetSystemTime(&st);\r\n  SystemTimeToFileTime(&st, &ft);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CPP/Windows/Time.h",
    "content": "// Windows/Time.h\r\n\r\n#ifndef __WINDOWS_TIME_H\r\n#define __WINDOWS_TIME_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime);\r\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime);\r\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime);\r\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime);\r\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\r\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds);\r\nvoid GetCurUtcFileTime(FILETIME &ft);\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid SetStream(System.IO.Stream inStream);\r\n\t\tvoid Init();\r\n\t\tvoid ReleaseStream();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetMatches(UInt32[] distances);\r\n\t\tvoid Skip(UInt32 num);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize = 0;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\tUInt32[] _son;\r\n\t\tUInt32[] _hash;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\t\tUInt32 _hashMask;\r\n\t\tUInt32 _hashSizeSum = 0;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\r\n\t\tconst UInt32 kHash2Size = 1 << 10;\r\n\t\tconst UInt32 kHash3Size = 1 << 16;\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kStartMaxLen = 1;\r\n\t\tconst UInt32 kHash3Offset = kHash2Size;\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\t\r\n\t\tUInt32 kNumHashDirectBytes = 0;\r\n\t\tUInt32 kMinMatchCheck = 4;\r\n\t\tUInt32 kFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\r\n\t\tpublic void SetType(int numHashBytes)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\t\tkMinMatchCheck = 4;\r\n\t\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\t\tkFixHashSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic new void SetStream(System.IO.Stream stream) { base.SetStream(stream); }\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\t\t\r\n\t\tpublic new void Init()\r\n\t\t{\r\n\t\t\tbase.Init();\r\n\t\t\tfor (UInt32 i = 0; i < _hashSizeSum; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\t\tthrow new Exception();\r\n\t\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\t\t\t\t\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\tUInt32 cyclicBufferSize = historySize + 1;\r\n\t\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t\t_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\t\tUInt32 hs = kBT2HashSize;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\ths = historySize - 1;\r\n\t\t\t\ths |= (hs >> 1);\r\n\t\t\t\ths |= (hs >> 2);\r\n\t\t\t\ths |= (hs >> 4);\r\n\t\t\t\ths |= (hs >> 8);\r\n\t\t\t\ths >>= 1;\r\n\t\t\t\ths |= 0xFFFF;\r\n\t\t\t\tif (hs > (1 << 24))\r\n\t\t\t\t\ths >>= 1;\r\n\t\t\t\t_hashMask = hs;\r\n\t\t\t\ths++;\r\n\t\t\t\ths += kFixHashSize;\r\n\t\t\t}\r\n\t\t\tif (hs != _hashSizeSum)\r\n\t\t\t\t_hash = new UInt32[_hashSizeSum = hs];\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetMatches(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 offset = 0;\r\n\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\t\t\tUInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 curMatch2 = _hash[hash2Value];\r\n\t\t\t\tUInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t\t{\r\n\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\t\t\t\r\n\t\t\tif (kNumHashDirectBytes != 0)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\r\n\t\t\twhile(true)\r\n\t\t\t{\r\n\t\t\t\tif(curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (maxLen < len)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t\treturn offset;\r\n\t\t}\r\n\r\n\t\tpublic void Skip(UInt32 num)\r\n\t\t{\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenLimit;\r\n\t\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tMovePos();\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\t\tUInt32 hashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\t\tUInt32 hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\t\tUInt32 hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\t\tUInt32 len0, len1;\r\n\t\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\t\tlen1 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\t\tlen0 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tMovePos();\r\n\t\t\t}\r\n\t\t\twhile (--num != 0);\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 subValue = _pos - _cyclicBufferSize;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize; // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos; // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos\r\n\t\tpublic UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\t\tif (offset > 0)\r\n\t\t\t\toffset--;\r\n\t\t\t\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { _stream = stream; }\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic uint TrainSize = 0;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t\tTrainSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tlong len = stream.Length;\r\n\t\t\tuint size = (len < _windowSize) ? (uint)len : _windowSize;\r\n\t\t\tTrainSize = size;\r\n\t\t\tstream.Position = len - size;\r\n\t\t\t_streamPos = _pos = 0;\r\n\t\t\twhile (size > 0)\r\n\t\t\t{\r\n\t\t\t\tuint curSize = _windowSize - _pos;\r\n\t\t\t\tif (size < curSize)\r\n\t\t\t\t\tcurSize = size;\r\n\t\t\t\tint numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tsize -= (uint)numReadBytes;\r\n\t\t\t\t_pos += (uint)numReadBytes;\r\n\t\t\t\t_streamPos += (uint)numReadBytes;\r\n\t\t\t\tif (_pos == _windowSize)\r\n\t\t\t\t\t_streamPos = _pos = 0;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t\tpublic bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\t// public const int kDicLogSizeMax = 30;\r\n\t\t// public const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tbool _solid = false;\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream, _solid);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t_solid = true;\r\n\t\t\treturn m_OutWindow.Train(stream);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get { return 0; }}\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t};\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1 << 11];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 22;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 11))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 21))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 10] + 20);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 20] + 40);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 17))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 27))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 16] + 32);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 26] + 52);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 22;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32[] prices, UInt32 st)\r\n\t\t\t{\r\n\t\t\t\tUInt32 a0 = _choice.GetPrice0();\r\n\t\t\t\tUInt32 a1 = _choice.GetPrice1();\r\n\t\t\t\tUInt32 b0 = a1 + _choice2.GetPrice0();\r\n\t\t\t\tUInt32 b1 = a1 + _choice2.GetPrice1();\r\n\t\t\t\tUInt32 i = 0;\r\n\t\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\tLZ.IMatchFinder _matchFinder = null;\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates];\r\n\t\t\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];\r\n\t\t\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _numDistancePairs;\r\n\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\t\tSystem.IO.Stream _inStream;\r\n\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark = false;\r\n\t\t\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tif (_matchFinderType == EMatchFinderType.BT2)\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs)\r\n\t\t{\r\n\t\t\tlenRes = 0;\r\n\t\t\tnumDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\t\tif (numDistancePairs > 0)\r\n\t\t\t{\r\n\t\t\t\tlenRes = _matchDistances[numDistancePairs - 2];\r\n\t\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t}\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tif (num > 0)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Skip(num);\r\n\t\t\t\t_additionalOffset += num;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t\t}\r\n\t\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\t\tUInt32 lenMain, numDistancePairs;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain, out numDistancePairs);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\t\t\t\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = (UInt32)0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\t\tif(lenEnd < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\t\tUInt32 len = lenEnd;\r\n\t\t\tdo\r\n\t\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\t\twhile (len >= 2);\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tif (repLen < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tUInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--repLen >= 2);\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\t\t\t\r\n\t\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\t\tif (len <= lenMain)\r\n\t\t\t{\r\n\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\tfor (; ; len++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 distance = _matchDistances[offs + 1];\r\n\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen, out numDistancePairs);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_numDistancePairs = numDistancePairs;\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t\t{\r\n\t\t\t\t\t// try Literal + rep0\r\n\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 startLen = 2; // speed optimization \r\n\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t\t// if (_maxMode)\r\n\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, reps[repIndex], t);\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)(reps[repIndex] + 1))), \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t\t}\r\n\t\t\t\tif (newLen >= startLen)\r\n\t\t\t\t{\r\n\t\t\t\t\tnormalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = startLen; ; lenTest++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t);\r\n\t\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)(curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t\t_matchFinder.Init();\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t\tif (_trainSize > 0)\r\n\t\t\t\t\t_matchFinder.Skip(_trainSize);\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len, numDistancePairs; // it's not used\r\n\t\t\t\tReadMatchDistances(out len, out numDistancePairs);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 len = GetOptimum((UInt32)nowPos64, out pos);\r\n\t\t\t\t\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t// if (!_fastMode)\r\n\t\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// if (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\t\t\r\n\t\tUInt32[] tempPrices = new UInt32[Base.kNumFullDistances];\r\n\t\tUInt32 _matchPriceCount;\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t\t{ \r\n\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, \r\n\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tRangeCoder.BitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\t\t\t\r\n\t\t\t\tUInt32 st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\t\tUInt32 st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t\t}\r\n\t\t\t_matchPriceCount = 0;\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = 0;\r\n\t\t}\r\n\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t/*\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t*/\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 30;\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _trainSize = 0;\r\n\t\tpublic void SetTrainSize(uint trainSize)\r\n\t\t{\r\n\t\t\t_trainSize = trainSize;\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\t\r\n\tpublic class CDoubleStream: Stream\r\n\t{\r\n\t\tpublic System.IO.Stream s1;\r\n\t\tpublic System.IO.Stream s2;\r\n\t\tpublic int fileIndex;\r\n\t\tpublic long skipSize;\r\n\t\t\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return false; }}\r\n\t\tpublic override bool CanSeek { get { return false; }}\r\n\t\tpublic override long Length { get { return s1.Length + s2.Length - skipSize; } }\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\tint numTotal = 0;\r\n\t\t\twhile (count > 0)\r\n\t\t\t{\r\n\t\t\t\tif (fileIndex == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tint num = s1.Read(buffer, offset, count);\r\n\t\t\t\t\toffset += num;\r\n\t\t\t\t\tcount -= num;\r\n\t\t\t\t\tnumTotal += num;\r\n\t\t\t\t\tif (num == 0)\r\n\t\t\t\t\t\tfileIndex++;\r\n\t\t\t\t}\r\n\t\t\t\tif (fileIndex == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tnumTotal += s2.Read(buffer, offset, count);\r\n\t\t\t\t\treturn numTotal;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn numTotal;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Write\"));\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Seek\"));\r\n\t\t}\r\n\t\tpublic override void SetLength(long value)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't SetLength\"));\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut,\r\n\t\t\tTrain\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0, 29], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.61  2008-11-23\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[13];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"T\", SwitchType.UnLimitedPostString, false, 1);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary);\r\n\t\t\t}\r\n\r\n\t\t\tstring train = \"\";\r\n\t\t\tif (parser[(int)Key.Train].ThereIs)\r\n\t\t\t\ttrain = (string)parser[(int)Key.Train].PostStrings[0];\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream trainStream = null;\r\n\t\t\tif (train.Length != 0)\r\n\t\t\t\ttrainStream = new FileStream(train, FileMode.Open, FileAccess.Read);\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tCDoubleStream doubleStream = new CDoubleStream();\r\n\t\t\t\t\tdoubleStream.s1 = trainStream;\r\n\t\t\t\t\tdoubleStream.s2 = inStream;\r\n\t\t\t\t\tdoubleStream.fileIndex = 0;\r\n\t\t\t\t\tinStream = doubleStream;\r\n\t\t\t\t\tlong trainFileSize = trainStream.Length;\r\n\t\t\t\t\tdoubleStream.skipSize = 0;\r\n\t\t\t\t\tif (trainFileSize > dictionary)\r\n\t\t\t\t\t\tdoubleStream.skipSize = trainFileSize - dictionary;\r\n\t\t\t\t\ttrainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);\r\n\t\t\t\t\tencoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));\r\n\t\t\t\t}\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!decoder.Train(trainStream))\r\n\t\t\t\t\t\tthrow (new Exception(\"can't train\"));\r\n\t\t\t\t}\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.50727</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tUInt32 Rep0;\r\n\t\t\t\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\t\tUInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\tRG.Init();\r\n\t\t\t\tRep0 = 1;\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)RG.GetRnd(8);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 len;\r\n\t\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\t\tUInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 220 + outSize * 20;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 18))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "// LZ.BinTree\r\n\r\npackage SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\r\n\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize = 0;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\tint[] _hash;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\tint _hashMask;\r\n\tint _hashSizeSum = 0;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\r\n\tstatic final int kHash2Size = 1 << 10;\r\n\tstatic final int kHash3Size = 1 << 16;\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kStartMaxLen = 1;\r\n\tstatic final int kHash3Offset = kHash2Size;\r\n\tstatic final int kEmptyHashValue = 0;\r\n\tstatic final int kMaxValForNormalize = (1 << 30) - 1;\r\n\t\r\n\tint kNumHashDirectBytes = 0;\r\n\tint kMinMatchCheck = 4;\r\n\tint kFixHashSize = kHash2Size + kHash3Size;\r\n\r\n\tpublic void SetType(int numHashBytes)\r\n\t{\r\n\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\tkMinMatchCheck = 4;\r\n\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\tkFixHashSize = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tfor (int i = 0; i < _hashSizeSum; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\treturn false;\r\n\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\tint cyclicBufferSize = historySize + 1;\r\n\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t_son = new int[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\tint hs = kBT2HashSize;\r\n\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\ths = historySize - 1;\r\n\t\t\ths |= (hs >> 1);\r\n\t\t\ths |= (hs >> 2);\r\n\t\t\ths |= (hs >> 4);\r\n\t\t\ths |= (hs >> 8);\r\n\t\t\ths >>= 1;\r\n\t\t\ths |= 0xFFFF;\r\n\t\t\tif (hs > (1 << 24))\r\n\t\t\t\ths >>= 1;\r\n\t\t\t_hashMask = hs;\r\n\t\t\ths++;\r\n\t\t\ths += kFixHashSize;\r\n\t\t}\r\n\t\tif (hs != _hashSizeSum)\r\n\t\t\t_hash = new int [_hashSizeSum = hs];\r\n\t\treturn true;\r\n\t}\r\n\tpublic int GetMatches(int[] distances) throws IOException\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t{\r\n\t\t\t\tMovePos();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint offset = 0;\r\n\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\tint maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint curMatch2 = _hash[hash2Value];\r\n\t\t\tint curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t}\r\n\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t}\r\n\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t{\r\n\t\t\t\toffset -= 2;\r\n\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\tint len0, len1;\r\n\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\tif (kNumHashDirectBytes != 0)\r\n\t\t{\r\n\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint count = _cutValue;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint len = Math.min(len0, len1);\r\n\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t{\r\n\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tif (maxLen < len)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t{\r\n\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\tlen1 = len;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\tlen0 = len;\r\n\t\t\t}\r\n\t\t}\r\n\t\tMovePos();\r\n\t\treturn offset;\r\n\t}\r\n\r\n\tpublic void Skip(int num) throws IOException\r\n\t{\r\n\t\tdo\r\n\t\t{\r\n\t\t\tint lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tint cur = _bufferOffset + _pos;\r\n\t\t\t\r\n\t\t\tint hashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\t\tint hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\t\tint hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tint len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\tint count = _cutValue;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tint len = Math.min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t}\r\n\t\twhile (--num != 0);\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint subValue = _pos - _cyclicBufferSize;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue) { _cutValue = cutValue; }\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\tif (offset > 0)\r\n\t\t\toffset--;\r\n\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free() { _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream) { _stream = stream; \t}\r\n\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\t// public static final int kDicLogSizeMax = 28;\r\n\t// public static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\r\n\r\n\r\n\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\r\n\tstatic byte[] g_FastPos = new byte[1 << 11];\r\n\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 22;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 11))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 21))\r\n\t\t\treturn (g_FastPos[pos >> 10] + 20);\r\n\t\treturn (g_FastPos[pos >> 20] + 40);\r\n\t}\r\n\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 17))\r\n\t\t\treturn (g_FastPos[pos >> 6] + 12);\r\n\t\tif (pos < (1 << 27))\r\n\t\t\treturn (g_FastPos[pos >> 16] + 32);\r\n\t\treturn (g_FastPos[pos >> 26] + 52);\r\n\t}\r\n\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\r\n\tstatic final int kDefaultDictionaryLogSize = 22;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\r\n\t\t\tpublic void Init() { SevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders); }\r\n\r\n\r\n\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetPrices(int posState, int numSymbols, int[] prices, int st)\r\n\t\t{\r\n\t\t\tint a0 = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\tint a1 = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\tint b0 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\tint b1 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\tint i = 0;\r\n\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t}\r\n\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t}\r\n\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t}\r\n\t};\r\n\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols<<Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\tpublic void SetTableSize(int tableSize) { _tableSize = tableSize; }\r\n\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t}\r\n\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\r\n\tstatic final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;\r\n\t\tpublic int BackPrev;\r\n\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\r\n\t\tpublic void MakeAsChar() { BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep() { return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null;\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\r\n\tshort[] _isMatch = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances-Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen*2+2];\r\n\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _numDistancePairs;\r\n\r\n\tint _additionalOffset;\r\n\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\r\n\tboolean _longestMatchWasFound;\r\n\r\n\tint[] _posSlotPrices = new int[1<<(Base.kNumPosSlotBits+Base.kNumLenToPosStatesBits)];\r\n\tint[] _distancesPrices = new int[Base.kNumFullDistances<<Base.kNumLenToPosStatesBits];\r\n\tint[] _alignPrices = new int[Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\tjava.io.InputStream _inStream;\r\n\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\r\n\tboolean _needReleaseMFStream = false;\r\n\r\n\tvoid Create()\r\n\t{\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tif (_matchFinderType == EMatchFinderTypeBT2)\r\n\t\t\t\tnumHashBytes = 2;\r\n\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\r\n\tvoid SetWriteEndMarkerMode(boolean writeEndMarker)\r\n\t{\r\n\t\t_writeEndMark = writeEndMarker;\r\n\t}\r\n\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\r\n\r\n\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n\t\t_posAlignEncoder.Init();\r\n\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = 0;\r\n\t\t_numDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\tif (_numDistancePairs > 0)\r\n\t\t{\r\n\t\t\tlenRes = _matchDistances[_numDistancePairs - 2];\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[_numDistancePairs - 1],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t}\r\n\t\t_additionalOffset++;\r\n\t\treturn lenRes;\r\n\t}\r\n\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tif (num > 0)\r\n\t\t{\r\n\t\t\t_matchFinder.Skip(num);\r\n\t\t\t_additionalOffset += num;\r\n\t\t}\r\n\t}\r\n\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\r\n\tint GetPureRepPrice(int repIndex, int state, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t}\r\n\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\r\n\tint Backward(int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\tint backRes;\r\n\r\n\tint GetOptimum(int position) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\tint lenMain, numDistancePairs;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tnumDistancePairs = _numDistancePairs;\r\n\r\n\t\tint numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\tif (numAvailableBytes < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\tbyte matchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[0].State = _state;\r\n\r\n\t\tint posState = (position & _posStateMask);\r\n\r\n\t\t_optimum[1].Price = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\tif (lenEnd < 2)\r\n\t\t{\r\n\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\tint len = lenEnd;\r\n\t\tdo\r\n\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\twhile (len >= 2);\r\n\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tif (repLen < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tint price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twhile (--repLen >= 2);\r\n\t\t}\r\n\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\r\n\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\tif (len <= lenMain)\r\n\t\t{\r\n\t\t\tint offs = 0;\r\n\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\toffs += 2;\r\n\t\t\tfor (; ; len++)\r\n\t\t\t{\r\n\t\t\t\tint distance = _matchDistances[offs + 1];\r\n\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t{\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint cur = 0;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\r\n\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t{\r\n\t\t\t\t// try Literal + rep0\r\n\t\t\t\tint t = Math.min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint startLen = 2; // speed optimization \r\n\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\tint lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t// if (_maxMode)\r\n\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t{\r\n\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, reps[repIndex], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - (reps[repIndex] + 1)),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t{\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t}\r\n\t\t\tif (newLen >= startLen)\r\n\t\t\t{\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\tint offs = 0;\r\n\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\tfor (int lenTest = startLen; ; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, curBack, t);\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\r\n\t\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - (curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\r\n\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\r\n\t\t\tint len = GetOptimum((int)nowPos64);\r\n\t\t\tint pos = backRes;\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\t// if (!_fastMode)\r\n\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\r\n\t\t// if (!_fastMode)\r\n\t\t{\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\r\n\tlong[] processedInSize = new long[1]; long[] processedOutSize = new long[1]; boolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\r\n\r\n\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\r\n\tint[] tempPrices = new int[Base.kNumFullDistances];\r\n\tint _matchPriceCount;\r\n\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t{\r\n\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t}\r\n\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tBitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\r\n\t\t\tint st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\tint st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t}\r\n\t\t_matchPriceCount = 0;\r\n\t}\r\n\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = 0;\r\n\t}\r\n\r\n\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\t/*\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\t*/\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = 29;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++) ;\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.61  2008-11-23\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SetNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator() { Init(); }\r\n\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tint Rep0;\r\n\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\r\n\t\tpublic CBenchRandomGenerator() { }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit() { return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\tint GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\tRG.Init();\r\n\t\t\tRep0 = 1;\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint len;\r\n\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, long elapsedTime, long size)\r\n\t{\r\n\t\tlong t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\tlong numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime, long outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 220 + outSize * 20;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 18))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 18 (256 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/Methods.txt",
    "content": "7-Zip method IDs (4.65)\r\n-----------------------\r\n\r\nEach compression or crypto method in 7z has unique binary value (ID).\r\nThe length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).\r\n\r\nIf you want to add some new ID, you have two ways:\r\n1) Write request for allocating IDs to 7-zip developers.\r\n2) Generate 8-bytes ID:\r\n\r\n    3F ZZ ZZ ZZ ZZ ZZ MM MM \r\n\r\n    3F              - Prefix for random IDs (1 byte)\r\n    ZZ ZZ ZZ ZZ ZZ  - Developer ID (5 bytes). Use real random bytes. \r\n                      \r\n    MM MM           - Method ID (2 bytes)\r\n\r\n    You can notify 7-Zip developers about your Developer ID / Method ID.\r\n\r\n    Note: Use new ID only if old codec can not decode data encoded with new version.\r\n\r\n\r\nList of defined IDs\r\n-------------------\r\n      \r\n00 - Copy\r\n\r\n02 - Common\r\n   03 Swap\r\n      - 2 Swap2\r\n      - 4 Swap4\r\n\r\n03 - 7z\r\n   01 - LZMA\r\n      01 - Version\r\n  \r\n   03 - Branch\r\n      01 - x86\r\n         03  - BCJ\r\n         1B  - BCJ2\r\n      02 - PPC\r\n         05 - PPC (Big Endian)\r\n      03 - Alpha\r\n         01 - Alpha\r\n      04 - IA64\r\n         01 - IA64\r\n      05 - ARM\r\n         01 - ARM\r\n      06 - M68\r\n         05 - M68 (Big Endian)\r\n      07 - ARM Thumb\r\n         01 - ARMT\r\n      08 - SPARC\r\n         05 - SPARC\r\n\r\n   04 - PPMD\r\n      01 - Version\r\n\r\n   7F -\r\n      01 - experimental methods.\r\n\r\n\r\n04 - Misc\r\n   00 - Reserved\r\n   01 - Zip\r\n      00 - Copy (not used). Use {00} instead\r\n      01 - Shrink\r\n      06 - Implode\r\n      08 - Deflate\r\n      09 - Deflate64\r\n      12 - BZip2 (not used). Use {04 02 02} instead\r\n   02 - BZip\r\n      02 - BZip2\r\n   03 - Rar\r\n      01 - Rar15\r\n      02 - Rar20\r\n      03 - Rar29\r\n   04 - Arj\r\n      01 - Arj (1,2,3)\r\n      02 - Arj 4\r\n   05 - Z\r\n   06 - Lzh\r\n   07 - Reserved for 7z\r\n   08 - Cab\r\n   09 - NSIS\r\n      01 - DeflateNSIS\r\n      02 - BZip2NSIS\r\n\r\n\r\n06 - Crypto \r\n   00 - \r\n   01 - AES\r\n      0x - AES-128\r\n      4x - AES-192\r\n      8x - AES-256\r\n      Cx - AES\r\n\r\n      x0 - ECB\r\n      x1 - CBC\r\n      x2 - CFB\r\n      x3 - OFB\r\n\r\n   07 - Reserved\r\n   0F - Reserved\r\n\r\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\r\n\r\n   F1 - Misc Ciphers (Combine)\r\n      01 - Zip\r\n         01 - Main Zip crypto algo\r\n      03 - RAR\r\n         02 - \r\n         03 - Rar29 AES-128 + (modified SHA-1)\r\n      07 - 7z\r\n         01 - AES-256 + SHA-256\r\n\r\n07 - Hash (subject to change)\r\n   00 - \r\n   01 - CRC\r\n   02 - SHA-1\r\n   03 - SHA-256\r\n   04 - SHA-384\r\n   05 - SHA-512\r\n\r\n   F0 - Misc Hash\r\n\r\n   F1 - Misc\r\n      03 - RAR\r\n         03 - Rar29 Password Hashing (modified SHA1)\r\n      07 - 7z \r\n         01 - SHA-256 Password Hashing\r\n    \r\n   \r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/history.txt",
    "content": "HISTORY of the LZMA SDK\r\n-----------------------\r\n\r\n4.65           2009-02-03\r\n-------------------------\r\n- Some minor fixes\r\n\r\n\r\n4.63           2008-12-31\r\n-------------------------\r\n- Some minor fixes\r\n\r\n\r\n4.61 beta      2008-11-23\r\n-------------------------\r\n- The bug in ANSI-C LZMA Decoder was fixed:\r\n    If encoded stream was corrupted, decoder could access memory \r\n    outside of allocated range.\r\n- Some changes in ANSI-C 7z Decoder interfaces.\r\n- LZMA SDK is placed in the public domain.\r\n\r\n\r\n4.60 beta      2008-08-19\r\n-------------------------\r\n- Some minor fixes.\r\n\r\n\r\n4.59 beta      2008-08-13\r\n-------------------------\r\n- The bug was fixed:\r\n    LZMA Encoder in fast compression mode could access memory outside of \r\n    allocated range in some rare cases.\r\n\r\n\r\n4.58 beta      2008-05-05\r\n-------------------------\r\n- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r\n- ANSI-C LZMA Encoder was included to LZMA SDK.\r\n- C++ LZMA code now is just wrapper over ANSI-C code.\r\n\r\n\r\n4.57           2007-12-12\r\n-------------------------\r\n- Speed optimizations in ++ LZMA Decoder. \r\n- Small changes for more compatibility with some C/C++ compilers.\r\n\r\n\r\n4.49 beta      2007-07-05\r\n-------------------------\r\n- .7z ANSI-C Decoder:\r\n     - now it supports BCJ and BCJ2 filters\r\n     - now it supports files larger than 4 GB.\r\n     - now it supports \"Last Write Time\" field for files.\r\n- C++ code for .7z archives compressing/decompressing from 7-zip \r\n  was included to LZMA SDK.\r\n  \r\n\r\n4.43           2006-06-04\r\n-------------------------\r\n- Small changes for more compatibility with some C/C++ compilers.\r\n  \r\n\r\n4.42           2006-05-15\r\n-------------------------\r\n- Small changes in .h files in ANSI-C version.\r\n  \r\n\r\n4.39 beta      2006-04-14\r\n-------------------------\r\n- The bug in versions 4.33b:4.38b was fixed:\r\n  C++ version of LZMA encoder could not correctly compress \r\n  files larger than 2 GB with HC4 match finder (-mfhc4).\r\n  \r\n\r\n4.37 beta      2005-04-06\r\n-------------------------\r\n- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r\n\r\n\r\n4.35 beta      2005-03-02\r\n-------------------------\r\n- The bug was fixed in C++ version of LZMA Decoder:\r\n    If encoded stream was corrupted, decoder could access memory \r\n    outside of allocated range.\r\n\r\n\r\n4.34 beta      2006-02-27\r\n-------------------------\r\n- Compressing speed and memory requirements for compressing were increased\r\n- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r\n\r\n\r\n4.32           2005-12-09\r\n-------------------------\r\n- Java version of LZMA SDK was included\r\n\r\n\r\n4.30           2005-11-20\r\n-------------------------\r\n- Compression ratio was improved in -a2 mode\r\n- Speed optimizations for compressing in -a2 mode\r\n- -fb switch now supports values up to 273\r\n- The bug in 7z_C (7zIn.c) was fixed:\r\n  It used Alloc/Free functions from different memory pools.\r\n  So if program used two memory pools, it worked incorrectly.\r\n- 7z_C: .7z format supporting was improved\r\n- LZMA# SDK (C#.NET version) was included\r\n\r\n\r\n4.27 (Updated) 2005-09-21\r\n-------------------------\r\n- Some GUIDs/interfaces in C++ were changed.\r\n IStream.h:\r\n   ISequentialInStream::Read now works as old ReadPart\r\n   ISequentialOutStream::Write now works as old WritePart\r\n\r\n\r\n4.27           2005-08-07\r\n-------------------------\r\n- The bug in LzmaDecodeSize.c was fixed:\r\n   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r\n   decompressing worked incorrectly.\r\n\r\n\r\n4.26           2005-08-05\r\n-------------------------\r\n- Fixes in 7z_C code and LzmaTest.c:\r\n  previous versions could work incorrectly,\r\n  if malloc(0) returns 0\r\n\r\n\r\n4.23           2005-06-29\r\n-------------------------\r\n- Small fixes in C++ code\r\n\r\n\r\n4.22           2005-06-10\r\n-------------------------\r\n- Small fixes\r\n\r\n\r\n4.21           2005-06-08\r\n-------------------------\r\n- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r\n- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r\n    - LzmaStateDecode.h\r\n    - LzmaStateDecode.c\r\n    - LzmaStateTest.c\r\n- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r\n\r\n\r\n4.17           2005-04-18\r\n-------------------------\r\n- New example for RAM->RAM compressing/decompressing: \r\n  LZMA + BCJ (filter for x86 code):\r\n    - LzmaRam.h\r\n    - LzmaRam.cpp\r\n    - LzmaRamDecode.h\r\n    - LzmaRamDecode.c\r\n    - -f86 switch for lzma.exe\r\n\r\n\r\n4.16           2005-03-29\r\n-------------------------\r\n- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r\n   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r\n   decoder could access memory outside of allocated range.\r\n- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r\n  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r\n  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r\n- Small speed optimization in LZMA C++ code\r\n- filter for SPARC's code was added\r\n- Simplified version of .7z ANSI-C Decoder was included\r\n\r\n\r\n4.06           2004-09-05\r\n-------------------------\r\n- The bug in v4.05 was fixed:\r\n    LZMA-Encoder didn't release output stream in some cases.\r\n\r\n\r\n4.05           2004-08-25\r\n-------------------------\r\n- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r\n  and PowerPC code was included to SDK\r\n- Some internal minor changes\r\n\r\n\r\n4.04           2004-07-28\r\n-------------------------\r\n- More compatibility with some C++ compilers\r\n\r\n\r\n4.03           2004-06-18\r\n-------------------------\r\n- \"Benchmark\" command was added. It measures compressing \r\n  and decompressing speed and shows rating values. \r\n  Also it checks hardware errors.\r\n\r\n\r\n4.02           2004-06-10\r\n-------------------------\r\n- C++ LZMA Encoder/Decoder code now is more portable\r\n  and it can be compiled by GCC on Linux.\r\n\r\n\r\n4.01           2004-02-15\r\n-------------------------\r\n- Some detection of data corruption was enabled.\r\n    LzmaDecode.c / RangeDecoderReadByte\r\n    .....\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n\r\n\r\n4.00           2004-02-13\r\n-------------------------\r\n- Original version of LZMA SDK\r\n\r\n\r\n\r\nHISTORY of the LZMA\r\n-------------------\r\n  2001-2008:  Improvements to LZMA compressing/decompressing code, \r\n              keeping compatibility with original LZMA format\r\n  1996-2001:  Development of LZMA compression format\r\n\r\n  Some milestones:\r\n\r\n  2001-08-30: LZMA compression was added to 7-Zip\r\n  1999-01-02: First version of 7-Zip was released\r\n  \r\n\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/lzma/lzma.txt",
    "content": "LZMA SDK 4.65\r\n-------------\r\n\r\nLZMA SDK provides the documentation, samples, header files, libraries, \r\nand tools you need to develop applications that use LZMA compression.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\nLZMA is an improved version of famous LZ77 compression algorithm. \r\nIt was improved in way of maximum increasing of compression ratio,\r\nkeeping high decompression speed and low memory requirements for \r\ndecompressing.\r\n\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\r\n\r\n\r\nLZMA SDK Contents\r\n-----------------\r\n\r\nLZMA SDK includes:\r\n\r\n  - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing\r\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\r\n\r\n\r\nUNIX/Linux version \r\n------------------\r\nTo compile C++ version of file->file LZMA encoding, go to directory\r\nC++/7zip/Compress/LZMA_Alone \r\nand call make to recompile it:\r\n  make -f makefile.gcc clean all\r\n\r\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\r\nTo compile with static libraries, you can use \r\nLIB = -lm -static\r\n\r\n\r\nFiles\r\n---------------------\r\nlzma.txt     - LZMA SDK description (this file)\r\n7zFormat.txt - 7z Format description\r\n7zC.txt      - 7z ANSI-C Decoder description\r\nmethods.txt  - Compression method IDs for .7z\r\nlzma.exe     - Compiled file->file LZMA encoder/decoder for Windows\r\nhistory.txt  - history of the LZMA SDK\r\n\r\n\r\nSource code structure\r\n---------------------\r\n\r\nC/  - C files\r\n        7zCrc*.*   - CRC code\r\n        Alloc.*    - Memory allocation functions\r\n        Bra*.*     - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n        LzFind.*   - Match finder for LZ (LZMA) encoders \r\n        LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding\r\n        LzHash.h   - Additional file for LZ match finder\r\n        LzmaDec.*  - LZMA decoding\r\n        LzmaEnc.*  - LZMA encoding\r\n        LzmaLib.*  - LZMA Library for DLL calling\r\n        Types.h    - Basic types for another .c files\r\n\tThreads.*  - The code for multithreading.\r\n\r\n    LzmaLib  - LZMA Library (.DLL for Windows)\r\n    \r\n    LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).\r\n\r\n    Archive - files related to archiving\r\n      7z     - 7z ANSI-C Decoder\r\n\r\nCPP/ -- CPP files\r\n\r\n  Common  - common files for C++ projects\r\n  Windows - common files for Windows related code\r\n\r\n  7zip    - files related to 7-Zip Project\r\n\r\n    Common   - common files for 7-Zip\r\n\r\n    Compress - files related to compression/decompression\r\n\r\n      Copy         - Copy coder\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n      LZMA         - LZMA compression/decompression on C++\r\n      LZMA_Alone   - file->file LZMA compression/decompression\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n\r\n    Archive - files related to archiving\r\n\r\n      Common   - common files for archive handling\r\n      7z       - 7z C++ Encoder/Decoder\r\n\r\n    Bundles    - Modules that are bundles of other modules\r\n  \r\n      Alone7z           - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2\r\n      Format7zR         - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r\n      Format7zExtractR  - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.\r\n\r\n    UI        - User Interface files\r\n         \r\n      Client7z - Test application for 7za.dll,  7zr.dll, 7zxr.dll\r\n      Common   - Common UI files\r\n      Console  - Code for console archiver\r\n\r\n\r\n\r\nCS/ - C# files\r\n  7zip\r\n    Common   - some common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      LzmaAlone    - file->file LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nJava/  - Java files\r\n  SevenZip\r\n    Compression    - files related to compression/decompression\r\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\n\r\nC/C++ source code of LZMA SDK is part of 7-Zip project.\r\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r\n\r\n  http://sourceforge.net/projects/sevenzip/\r\n\r\n\r\n\r\nLZMA features\r\n-------------\r\n  - Variable dictionary size (up to 1 GB)\r\n  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r\n  - Estimated decompressing speed: \r\n      - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64\r\n      - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC\r\n  - Small memory requirements for decompressing (16 KB + DictionarySize)\r\n  - Small code size for decompressing: 5-8 KB\r\n\r\nLZMA decoder uses only integer operations and can be \r\nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r\n\r\nSome critical operations that affect the speed of LZMA decompression:\r\n  1) 32*16 bit integer multiply\r\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\r\n  3) 32-bit shift and arithmetic operations\r\n\r\nThe speed of LZMA decompressing mostly depends from CPU speed.\r\nMemory speed has no big meaning. But if your CPU has small data cache, \r\noverall weight of memory speed will slightly increase.\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nUsing LZMA encoder/decoder executable\r\n--------------------------------------\r\n\r\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\r\n\r\n  e: encode file\r\n\r\n  d: decode file\r\n\r\n  b: Benchmark. There are two tests: compressing and decompressing \r\n     with LZMA method. Benchmark shows rating in MIPS (million \r\n     instructions per second). Rating value is calculated from \r\n     measured speed and it is normalized with Intel's Core 2 results.\r\n     Also Benchmark checks possible hardware errors (RAM \r\n     errors in most cases). Benchmark uses these settings:\r\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r\n     Also you can change the number of iterations. Example for 30 iterations:\r\n       LZMA b 30\r\n     Default number of iterations is 10.\r\n\r\n<Switches>\r\n  \r\n\r\n  -a{N}:  set compression mode 0 = fast, 1 = normal\r\n          default: 1 (normal)\r\n\r\n  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r\n          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \r\n          For decompressing file compressed by LZMA method with dictionary \r\n          size D = 2^N you need about D bytes of memory (RAM).\r\n\r\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\r\n          Usually big number gives a little bit better compression ratio \r\n          and slower compression process.\r\n\r\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\r\n          Sometimes lc=4 gives gain for big files.\r\n\r\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r\n          lp switch is intended for periodical data when period is \r\n          equal 2^N. For example, for 32-bit (4 bytes) \r\n          periodical data you can use lp=2. Often it's better to set lc0, \r\n          if you change lp switch.\r\n\r\n  -pb{N}: set number of pos bits - [0, 4], default: 2\r\n          pb switch is intended for periodical data \r\n          when period is equal 2^N.\r\n\r\n  -mf{MF_ID}: set Match Finder. Default: bt4. \r\n              Algorithms from hc* group doesn't provide good compression \r\n              ratio, but they often works pretty fast in combination with \r\n              fast mode (-a0).\r\n\r\n              Memory requirements depend from dictionary size \r\n              (parameter \"d\" in table below). \r\n\r\n               MF_ID     Memory                   Description\r\n\r\n                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r\n                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r\n                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r\n                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r\n\r\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \r\n          eos marker, since LZMA decoder knows uncompressed size \r\n          stored in .lzma file header.\r\n\r\n  -si:    Read data from stdin (it will write End Of Stream marker).\r\n  -so:    Write data to stdout\r\n\r\n\r\nExamples:\r\n\r\n1) LZMA e file.bin file.lzma -d16 -lc0 \r\n\r\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r\nand 0 literal context bits. -lc0 allows to reduce memory requirements \r\nfor decompression.\r\n\r\n\r\n2) LZMA e file.bin file.lzma -lc0 -lp2\r\n\r\ncompresses file.bin to file.lzma with settings suitable \r\nfor 32-bit periodical data (for example, ARM or MIPS code).\r\n\r\n3) LZMA d file.lzma file.bin\r\n\r\ndecompresses file.lzma to file.bin.\r\n\r\n\r\nCompression ratio hints\r\n-----------------------\r\n\r\nRecommendations\r\n---------------\r\n\r\nTo increase the compression ratio for LZMA compressing it's desirable \r\nto have aligned data (if it's possible) and also it's desirable to locate\r\ndata in such order, where code is grouped in one place and data is \r\ngrouped in other place (it's better than such mixing: code, data, code,\r\ndata, ...).\r\n\r\n\r\nFilters\r\n-------\r\nYou can increase the compression ratio for some data types, using\r\nspecial filters before compressing. For example, it's possible to \r\nincrease the compression ratio on 5-10% for code for those CPU ISAs: \r\nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r\n\r\nYou can find C source code of such filters in C/Bra*.* files\r\n\r\nYou can check the compression ratio gain of these filters with such \r\n7-Zip commands (example for ARM code):\r\nNo filter:\r\n  7z a a1.7z a.bin -m0=lzma\r\n\r\nWith filter for little-endian ARM code:\r\n  7z a a2.7z a.bin -m0=arm -m1=lzma        \r\n\r\nIt works in such manner:\r\nCompressing    = Filter_encoding + LZMA_encoding\r\nDecompressing  = LZMA_decoding + Filter_decoding\r\n\r\nCompressing and decompressing speed of such filters is very high,\r\nso it will not increase decompressing time too much.\r\nMoreover, it reduces decompression time for LZMA_decoding, \r\nsince compression ratio with filtering is higher.\r\n\r\nThese filters convert CALL (calling procedure) instructions \r\nfrom relative offsets to absolute addresses, so such data becomes more \r\ncompressible.\r\n\r\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r\n\r\n\r\nLZMA compressed file format\r\n---------------------------\r\nOffset Size Description\r\n  0     1   Special LZMA properties (lc,lp, pb in encoded form)\r\n  1     4   Dictionary size (little endian)\r\n  5     8   Uncompressed size (little endian). -1 means unknown size\r\n 13         Compressed data\r\n\r\n\r\nANSI-C LZMA Decoder\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nPlease note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.\r\nIf you want to use old interfaces you can download previous version of LZMA SDK\r\nfrom sourceforge.net site.\r\n\r\nTo use ANSI-C LZMA Decoder you need the following files:\r\n1) LzmaDec.h + LzmaDec.c + Types.h\r\nLzmaUtil/LzmaUtil.c is example application that uses these files.\r\n\r\n\r\nMemory requirements for LZMA decoding\r\n-------------------------------------\r\n\r\nStack usage of LZMA decoding function for local variables is not \r\nlarger than 200-400 bytes.\r\n\r\nLZMA Decoder uses dictionary buffer and internal state structure.\r\nInternal state structure consumes\r\n  state_size = (4 + (1.5 << (lc + lp))) KB\r\nby default (lc=3, lp=0), state_size = 16 KB.\r\n\r\n\r\nHow To decompress data\r\n----------------------\r\n\r\nLZMA Decoder (ANSI-C version) now supports 2 interfaces:\r\n1) Single-call Decompressing\r\n2) Multi-call State Decompressing (zlib-like interface)\r\n\r\nYou must use external allocator:\r\nExample:\r\nvoid *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\r\nvoid SzFree(void *p, void *address) { p = p; free(address); }\r\nISzAlloc alloc = { SzAlloc, SzFree };\r\n\r\nYou can use p = p; operator to disable compiler warnings.\r\n\r\n\r\nSingle-call Decompressing\r\n-------------------------\r\nWhen to use: RAM->RAM decompressing\r\nCompile files: LzmaDec.h + LzmaDec.c + Types.h\r\nCompile defines: no defines\r\nMemory Requirements:\r\n  - Input buffer: compressed size\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures: state_size (16 KB for default settings) \r\n\r\nInterface:\r\n  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, \r\n      ELzmaStatus *status, ISzAlloc *alloc);\r\n  In: \r\n    dest     - output data\r\n    destLen  - output data size\r\n    src      - input data\r\n    srcLen   - input data size\r\n    propData - LZMA properties  (5 bytes)\r\n    propSize - size of propData buffer (5 bytes)\r\n    finishMode - It has meaning only if the decoding reaches output limit (*destLen).\r\n\t LZMA_FINISH_ANY - Decode just destLen bytes.\r\n\t LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n                           You can use LZMA_FINISH_END, when you know that \r\n                           current output buffer covers last bytes of stream. \r\n    alloc    - Memory allocator.\r\n\r\n  Out: \r\n    destLen  - processed output size \r\n    srcLen   - processed input size \r\n\r\n  Output:\r\n    SZ_OK\r\n      status:\r\n        LZMA_STATUS_FINISHED_WITH_MARK\r\n        LZMA_STATUS_NOT_FINISHED \r\n        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n    SZ_ERROR_DATA - Data error\r\n    SZ_ERROR_MEM  - Memory allocation error\r\n    SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n\r\n  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,\r\n  and output value of destLen will be less than output buffer size limit.\r\n\r\n  You can use multiple checks to test data integrity after full decompression:\r\n    1) Check Result and \"status\" variable.\r\n    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. \r\n       You must use correct finish mode in that case. */ \r\n\r\n\r\nMulti-call State Decompressing (zlib-like interface)\r\n----------------------------------------------------\r\n\r\nWhen to use: file->file decompressing \r\nCompile files: LzmaDec.h + LzmaDec.c + Types.h\r\n\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures: state_size (16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in LZMA properties header)\r\n\r\n1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:\r\n   unsigned char header[LZMA_PROPS_SIZE + 8];\r\n   ReadFile(inFile, header, sizeof(header)\r\n\r\n2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties\r\n\r\n  CLzmaDec state;\r\n  LzmaDec_Constr(&state);\r\n  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);\r\n  if (res != SZ_OK)\r\n    return res;\r\n\r\n3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop\r\n\r\n  LzmaDec_Init(&state);\r\n  for (;;)\r\n  {\r\n    ... \r\n    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, \r\n    \tconst Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);\r\n    ...\r\n  }\r\n\r\n\r\n4) Free all allocated structures\r\n  LzmaDec_Free(&state, &g_Alloc);\r\n\r\nFor full code example, look at C/LzmaUtil/LzmaUtil.c code.\r\n\r\n\r\nHow To compress data\r\n--------------------\r\n\r\nCompile files: LzmaEnc.h + LzmaEnc.c + Types.h +\r\nLzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h\r\n\r\nMemory Requirements:\r\n  - (dictSize * 11.5 + 6 MB) + state_size\r\n\r\nLzma Encoder can use two memory allocators:\r\n1) alloc - for small arrays.\r\n2) allocBig - for big arrays.\r\n\r\nFor example, you can use Large RAM Pages (2 MB) in allocBig allocator for \r\nbetter compression speed. Note that Windows has bad implementation for \r\nLarge RAM Pages. \r\nIt's OK to use same allocator for alloc and allocBig.\r\n\r\n\r\nSingle-call Compression with callbacks\r\n--------------------------------------\r\n\r\nCheck C/LzmaUtil/LzmaUtil.c as example, \r\n\r\nWhen to use: file->file decompressing \r\n\r\n1) you must implement callback structures for interfaces:\r\nISeqInStream\r\nISeqOutStream\r\nICompressProgress\r\nISzAlloc\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) {  p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\n  CFileSeqInStream inStream;\r\n  CFileSeqOutStream outStream;\r\n\r\n  inStream.funcTable.Read = MyRead;\r\n  inStream.file = inFile;\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.file = outFile;\r\n\r\n\r\n2) Create CLzmaEncHandle object;\r\n\r\n  CLzmaEncHandle enc;\r\n\r\n  enc = LzmaEnc_Create(&g_Alloc);\r\n  if (enc == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n\r\n3) initialize CLzmaEncProps properties;\r\n\r\n  LzmaEncProps_Init(&props);\r\n\r\n  Then you can change some properties in that structure.\r\n\r\n4) Send LZMA properties to LZMA Encoder\r\n\r\n  res = LzmaEnc_SetProps(enc, &props);\r\n\r\n5) Write encoded properties to header\r\n\r\n    Byte header[LZMA_PROPS_SIZE + 8];\r\n    size_t headerSize = LZMA_PROPS_SIZE;\r\n    UInt64 fileSize;\r\n    int i;\r\n\r\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r\n    fileSize = MyGetFileLength(inFile);\r\n    for (i = 0; i < 8; i++)\r\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r\n    MyWriteFileAndCheck(outFile, header, headerSize)\r\n\r\n6) Call encoding function:\r\n      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, \r\n        NULL, &g_Alloc, &g_Alloc);\r\n\r\n7) Destroy LZMA Encoder Object\r\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r\n\r\n\r\nIf callback function return some error code, LzmaEnc_Encode also returns that code.\r\n\r\n\r\nSingle-call RAM->RAM Compression\r\n--------------------------------\r\n\r\nSingle-call RAM->RAM Compression is similar to Compression with callbacks,\r\nbut you provide pointers to buffers instead of pointers to stream callbacks:\r\n\r\nHRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, \r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error \r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.\r\n\r\n_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for \r\n                 some structures will be doubled in that case.\r\n\r\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.\r\n\r\n_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.\r\n\r\n\r\nC++ LZMA Encoder/Decoder \r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nC++ LZMA code use COM-like interfaces. So if you want to use it, \r\nyou can study basics of COM/OLE.\r\nC++ LZMA code is just wrapper over ANSI-C code.\r\n\r\n\r\nC++ Notes\r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nIf you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),\r\nyou must check that you correctly work with \"new\" operator.\r\n7-Zip can be compiled with MSVC 6.0 that doesn't throw \"exception\" from \"new\" operator.\r\nSo 7-Zip uses \"CPP\\Common\\NewHandler.cpp\" that redefines \"new\" operator:\r\noperator new(size_t size)\r\n{\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\nIf you use MSCV that throws exception for \"new\" operator, you can compile without \r\n\"NewHandler.cpp\". So standard exception will be used. Actually some code of \r\n7-Zip catches any exception in internal code and converts it to HRESULT code.\r\nSo you don't need to catch CNewException, if you call COM interfaces of 7-Zip.\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/sdk.html\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/time.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"pseudo.h\"\n#include \"uncompress.h\"\n\n#ifdef USE_LZMA\n#include <LzmaEnc.h>\n#include <LzmaDec.h>\n#define LZMA_DEFAULT_LEVEL\t5\n#define LZMA_DEFAULT_DICT\t(1 << 23) //0 //by siyou for avoid malloc fail.\n#define LZMA_DEFAULT_LC\t1\n#define LZMA_DEFAULT_LP\t2\n#define LZMA_DEFAULT_PB 2\n#define LZMA_DEFAULT_FB 32\n#endif\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tprintf(\"\\n\"); \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\n/* offset of data in compressed metadata blocks (allowing room for\n * compressed size */\n#define BLOCK_OFFSET 2\nint delete = FALSE;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0;\nint silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\nint progress_enabled = FALSE;\nint sparse_files = TRUE;\nint old_exclude = TRUE;\nint use_regex = FALSE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned int id_count = 0;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0,\n\tsock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* exclude file handling */\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint old_excluded(char *filename, struct stat *buf);\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nstruct pathnames *paths = NULL;\nstruct pathname *path = NULL;\nstruct pathname *stickypath = NULL;\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\n\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n\n#define FRAG_SIZE 32768\n#define FRAG_INDEX (1LL << 32)\n\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is\n * cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache, *sdirectory_compressed;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, sdirectory_compressed_bytes,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* recovery file for abnormal exit on appending */\nchar recovery_file[1024] = \"\";\nint recover = TRUE;\n\n/* struct describing a cache entry passed between threads */\nstruct file_buffer {\n\tstruct cache *cache;\n\tint keep;\n\tlong long file_size;\n\tlong long index;\n\tlong long block;\n\tlong long sequence;\n\tint size;\n\tint c_byte;\n\tint used;\n\tint\tfragment;\n\tint error;\n\tstruct file_buffer *hash_next;\n\tstruct file_buffer *hash_prev;\n\tstruct file_buffer *free_next;\n\tstruct file_buffer *free_prev;\n\tstruct file_buffer *next;\n\tchar data[0];\n};\n\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n\n/* in memory uid tables */\n#define ID_ENTRIES 256\n#define ID_HASH(id) (id & (ID_ENTRIES - 1))\n#define ISA_UID 1\n#define ISA_GID 2\nstruct id {\n\tunsigned int id;\n\tint\tindex;\n\tchar\tflags;\n\tstruct id *next;\n};\nstruct id *id_hash_table[ID_ENTRIES];\nstruct id *id_table[SQUASHFS_IDS], *sid_table[SQUASHFS_IDS];\nunsigned int uid_count = 0, guid_count = 0;\nunsigned int sid_count = 0, suid_count = 0, sguid_count = 0;\n\nstruct cache *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate,\n\t*to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread, progress_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\npthread_mutex_t progress_mutex;\npthread_cond_t progress_wait;\nint rotate = 0;\nstruct pseudo *pseudo = NULL;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\nint fragment_buffer_size;\n\nchar *read_from_disk(long long start, unsigned int avail_bytes);\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type);\nextern int read_super(int fd, squashfs_super_block *sBlk, char *source);\nextern long long read_filesystem(char *root_name, int fd,\n\tsquashfs_super_block *sBlk, char **cinode_table, char **data_cache,\n\tchar **cdirectory_table, char **directory_data_cache,\n\tunsigned int *last_directory_block, unsigned int *inode_dir_offset,\n\tunsigned int *inode_dir_file_size, unsigned int *root_inode_size,\n\tunsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\tlong long *uncompressed_file, unsigned int *uncompressed_inode,\n\tunsigned int *uncompressed_directory,\n\tunsigned int *inode_dir_inode_number,\n\tunsigned int *inode_dir_parent_inode,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\tsquashfs_fragment_entry **fragment_table,\n\tsquashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *,\n\tchar *, struct dir_info *));\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo);\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info);\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority,\n\tstruct stat *buf);\nextern struct priority_entry *priority_list[65536];\nvoid progress_bar(long long current, long long max, int columns);\nlong long generic_write_table(int length, char *buffer, int uncompressed);\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tstruct file_buffer *free_list;\n\tstruct file_buffer *hash_table[65536];\n};\n\n\n#define INSERT_LIST(NAME, TYPE) \\\nvoid insert_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(*list) { \\\n\t\tentry->NAME##_next = *list; \\\n\t\tentry->NAME##_prev = (*list)->NAME##_prev; \\\n\t\t(*list)->NAME##_prev->NAME##_next = entry; \\\n\t\t(*list)->NAME##_prev = entry; \\\n\t} else { \\\n\t\t*list = entry; \\\n\t\tentry->NAME##_prev = entry->NAME##_next = entry; \\\n\t} \\\n}\n\n\n#define REMOVE_LIST(NAME, TYPE) \\\nvoid remove_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(entry->NAME##_prev == entry && entry->NAME##_next == entry) { \\\n\t\t/* only this entry in the list */ \\\n\t\t*list = NULL; \\\n\t} else if(entry->NAME##_prev != NULL && entry->NAME##_next != NULL) { \\\n\t\t/* more than one entry in the list */ \\\n\t\tentry->NAME##_next->NAME##_prev = entry->NAME##_prev; \\\n\t\tentry->NAME##_prev->NAME##_next = entry->NAME##_next; \\\n\t\tif(*list == entry) \\\n\t\t\t*list = entry->NAME##_next; \\\n\t} \\\n\tentry->NAME##_prev = entry->NAME##_next = NULL; \\\n}\n\n\n#define CALCULATE_HASH(start)\t(start & 0xffff) \\\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tint hash = CALCULATE_HASH(entry->index);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->index)] =\n\t\t\tentry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nINSERT_LIST(free, struct file_buffer)\n\n/* Called with the cache mutex held */\nREMOVE_LIST(free, struct file_buffer)\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\treturn NULL;\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct file_buffer *) * 65536);\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\n\treturn cache;\n}\n\n\nstruct file_buffer *cache_lookup(struct cache *cache, long long index)\n{\n\t/* Lookup block in the cache, if found return with usage count\n \t * incremented, if not found return NULL */\n\tint hash = CALCULATE_HASH(index);\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->index == index)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/* found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(&cache->free_list, entry);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n}\n\n\n#define GET_FREELIST 1\n\nstruct file_buffer *cache_get(struct cache *cache, long long index, int keep)\n{\n\t/* Get a free block out of the cache indexed on index. */\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\twhile(1) {\n\t\t/* first try to get a block from the free list */\n#ifdef GET_FREELIST\n\t\tif(cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t} else\n#endif\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\t/* next try to allocate new block */\n\t\t\tentry = malloc(sizeof(struct file_buffer) +\n\t\t\t\tcache->buffer_size);\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t\tbreak;\n\t\t} else\n#ifndef GET_FREELIST\n\t\tif(cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t}\n#endif\n\t\t\t/* wait for a block */\n\t\t\tpthread_cond_wait(&cache->wait_for_free, &cache->mutex);\n\t}\n\n\t/* initialise block and if a keep block insert into the hash table */\n\tentry->used = 1;\n\tentry->error = FALSE;\n\tentry->keep = keep;\n\tif(keep) {\n\t\tentry->index = index;\n\t\tinsert_hash_table(cache, entry);\n\t}\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\treturn NULL;\n}\n\n\nvoid cache_rehash(struct file_buffer *entry, long long index)\n{\n\tstruct cache *cache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\tif(entry->keep)\n\t\tremove_hash_table(cache, entry);\n\tentry->keep = TRUE;\n\tentry->index = index;\n\tinsert_hash_table(cache, entry);\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\nvoid cache_block_put(struct file_buffer *entry)\n{\n\tstruct cache *cache;\n\n\t/* finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and if a keep block put onto the free list.  As keep\n \t * blocks remain accessible via the hash table they can be found\n \t * getting a new lease of life before they are reused. */\n\n\tif(entry == NULL)\n\t\treturn;\n\n\tcache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tif(entry->keep)\n\t\t\tinsert_free_list(&cache->free_list, entry);\n\t\telse {\n\t\t\tfree(entry);\n\t\t\tcache->count --;\n\t\t}\n\n\t\t/* One or more threads may be waiting on this block */\n\t\tpthread_cond_signal(&cache->wait_for_free);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) \\\n\t\t\t+ (((char *)A) - data_cache)))\n\n\ninline void inc_progress_bar()\n{\n\tcur_uncompressed ++;\n}\n\n\ninline void update_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tif(thread[i])\n\t\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache,\n\t\tsdirectory_cache_bytes);\n\tdirectory_cache_bytes = sdirectory_cache_bytes;\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n \tmemcpy(directory_table + directory_bytes, sdirectory_compressed,\n\t\tsdirectory_compressed_bytes);\n \tdirectory_bytes += sdirectory_compressed_bytes;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tid_count = sid_count;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, &thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n#ifdef USE_LZMA\nstatic void *lzma_malloc(void *p, size_t size)\n{\n\t(void)p;\n\treturn malloc(size);\n}\nstatic void lzma_free(void *p, void *addr)\n{\n\t(void)p;\n\tfree(addr);\n}\nstatic ISzAlloc lzma_alloc = { lzma_malloc, lzma_free };\n#endif\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size,\n\tint block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\n#ifdef USE_LZMA\n\tif (compression == LZMA_COMPRESSION) {\n\t\tsize_t outsize = block_size - LZMA_PROPS_SIZE;\n\t\tsize_t propsize = LZMA_PROPS_SIZE;\n\t\tCLzmaEncProps props;\n\n\t\tLzmaEncProps_Init(&props);\n\t\tprops.level = LZMA_DEFAULT_LEVEL;\n\t\tprops.dictSize = LZMA_DEFAULT_DICT;\n\t\tprops.lc = LZMA_DEFAULT_LC;\n\t\tprops.lp = LZMA_DEFAULT_LP;\n\t\tprops.pb = LZMA_DEFAULT_PB;\n\t\tprops.fb = LZMA_DEFAULT_FB;\n\t\tprops.numThreads = 1;\n\n\t\tres = LzmaEncode((unsigned char *) d + LZMA_PROPS_SIZE, &outsize,\n\t\t\t(unsigned char *) s, size,\n\t\t\t&props, (unsigned char *) d, &propsize,\n\t\t\t1, NULL, &lzma_alloc, &lzma_alloc);\n\t\tswitch(res) {\n\t\tcase SZ_OK:\n\t\t\toutsize += LZMA_PROPS_SIZE;\n\t\t\tbreak;\n\t\tcase SZ_ERROR_DATA:\n\t\t\tBAD_ERROR(\"lzma::compress failed, data error\\n\");\n\t\t\tbreak;\n\t\tcase SZ_ERROR_MEM:\n\t\t\tBAD_ERROR(\"lzma::compress failed, memory allocation error\\n\");\n\t\t\tbreak;\n\t\tcase SZ_ERROR_PARAM:\n\t\t\tBAD_ERROR(\"lzma::compress failed, invalid parameters\\n\");\n\t\t\tbreak;\n        case SZ_ERROR_OUTPUT_EOF:\n            memcpy(d, s, size);\n            return size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK :\n                    SQUASHFS_COMPRESSED_BIT);\n        case SZ_ERROR_THREAD:\n\t\t\tBAD_ERROR(\"lzma::compress failed, errors in multithreading functions\\n\");\n\t\t\tbreak;\n\t\t/* should not happen */\n\t\tdefault:\n\t\t\tBAD_ERROR(\"lzma::compress failed, unknown error\\n\");\n\t\t\tbreak;\n\t\t}\n\n\t\treturn outsize;\n\t}\n#endif\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tBAD_ERROR(\"mangle::compress failed, not enough \"\n\t\t\t\t\"memory\\n\");\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough \"\n\t\t\t\t\t\"memory\\n\");\n\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid \"\n\t\t\t\t\t\"compression level\\n\");\n\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect \"\n\t\t\t\t\t\"zlib version\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown \"\n\t\t\t\t\t\"error %d\\n\", res);\n\t\t}\n\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state \"\n\t\t\t\t\"inconsistent\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\",\n\t\t\t\tres);\n\t}\n\n\tstream->next_in = (unsigned char *) s;\n\tstream->avail_in = size;\n\tstream->next_out = (unsigned char *) d;\n\tstream->avail_out = block_size;\n\n\tres = deflate(stream, Z_FINISH);\n\tif(res != Z_STREAM_END && res != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state \"\n\t\t\t\t\"inconsistent\\n\");\n\t\telse if(res == Z_BUF_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\"\n\t\t\t\t\"\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\",\n\t\t\t\tres);\n\t}\n\n\tc_byte = stream->total_out;\n\n\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK :\n\t\t\tSQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size,\n\tint uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed,\n\t\tdata_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tinode_table = realloc(inode_table, inode_size +\n\t\t\t\t(SQUASHFS_METADATA_SIZE << 1) + 2);\n\t\t\tif(inode_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET,\n\t\t\tdata_cache, SQUASHFS_METADATA_SIZE,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\t(unsigned short *) (inode_table + inode_bytes), 1);\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE,\n\t\t\tcache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ?\n\t\t\t\t((req_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : req_size -\n\t\t\t\tdata_space;\n\n\t\t\tdata_cache = realloc(data_cache, cache_size +\n\t\t\t\trealloc_size);\n\t\t\tif(data_cache == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)\n\t\t(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nint read_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = read(fd, buff + count, bytes - count);\n\t\tif(res < 1) {\n\t\t\tif(res == 0)\n\t\t\t\tgoto bytes_read;\n\t\t\telse if(errno != EINTR) {\n\t\t\t\tERROR(\"Read failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t} else\n\t\t\t\tres = 0;\n\t\t}\n\t}\n\nbytes_read:\n\treturn count;\n}\n\n\nvoid read_destination(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_destination: reading from position 0x%llx, bytes %d\\n\",\n\t\tbyte, bytes);\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(read_bytes(fd, buff, bytes) < bytes)\n\t\tBAD_ERROR(\"Read on destination failed\\n\");\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nint write_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = write(fd, buff + count, bytes - count);\n\t\tif(res == -1) {\n\t\t\tif(errno != EINTR) {\n\t\t\t\tERROR(\"Write failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nvoid write_destination(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(fd, buff, bytes) == -1)\n\t\tBAD_ERROR(\"Write on destination failed\\n\");\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tinode_table = realloc(inode_table, inode_size +\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2));\n\t\t\tif(inode_table == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET, datap,\n\t\t\tavail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\t(unsigned short *) (inode_table + inode_bytes), 1); \n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_destination(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tdirectory_table = realloc(directory_table,\n\t\t\t\tdirectory_size + ((SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2));\n\t\t\tif(directory_table == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\tBLOCK_OFFSET, directoryp, avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, (unsigned short *)\n\t\t\t(directory_table + directory_bytes), 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_destination(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_id_table()\n{\n\tunsigned int id_bytes = SQUASHFS_ID_BYTES(id_count);\n\tchar buffer[id_bytes];\n\tunsigned int *p = (unsigned int *) buffer;\n\tint i;\n\n\tTRACE(\"write_id_table: ids %d, id_bytes %d\\n\", id_count, id_bytes);\n\tfor(i = 0; i < id_count; i++, p++) {\n\t\tTRACE(\"write_id_table: id index %d, id %d\", i, id_table[i]->id);\n\t\tSQUASHFS_SWAP_INTS(&id_table[i]->id, p, 1);\n\t}\n\n\treturn generic_write_table(id_bytes, buffer, 1);\n}\n\n\nstruct id *get_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = id_hash_table[hash];\n\n\tfor(; entry; entry = entry->next)\n\t\tif(entry->id == id)\n\t\t\tbreak;\n\n\treturn entry;\n}\n\n\nstruct id *create_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = malloc(sizeof(struct id));\n\tif(entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in create_id\\n\");\n\tentry->id = id;\n\tentry->index = id_count ++;\n\tentry->flags = 0;\n\tentry->next = id_hash_table[hash];\n\tid_hash_table[hash] = entry;\n\tid_table[entry->index] = entry;\n\treturn entry;\n}\n\n\nunsigned int get_uid(unsigned int uid)\n{\n\tstruct id *entry = get_id(uid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of uids!\\n\");\n\t\tentry = create_id(uid);\n\t}\n\n\tif((entry->flags & ISA_UID) == 0) {\n\t\tentry->flags |= ISA_UID;\n\t\tuid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nunsigned int get_guid(unsigned int guid)\n{\n\tstruct id *entry = get_id(guid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of gids!\\n\");\n\t\tentry = create_id(guid);\n\t}\n\n\tif((entry->flags & ISA_GID) == 0) {\n\t\tentry->flags |= ISA_GID;\n\t\tguid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type,\n\tlong long byte_size, long long start_block, unsigned int offset,\n\tunsigned int *block_list, struct fragment *fragment,\n\tstruct directory *dir_in, unsigned int sparse)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE ||\n\t\ttype == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number :\n\t\tdir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((unsigned int) global_uid == -1 ?\n\t\tbuf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((unsigned int) global_gid == -1 ?\n\t\tbuf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\tTRACE(\"File inode, file_size %lld, start_block 0x%llx, blocks \"\n\t\t\t\"%d, fragment %d, offset %d, size %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset,\n\t\t\tfragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(sparse && sparse >= byte_size)\n\t\t\tsparse = byte_size - 1;\n\t\treg->sparse = sparse;\n\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\tTRACE(\"Long file inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"blocks %d, fragment %d, offset %d, size %d, nlink %d\"\n\t\t\t\"\\n\", byte_size, start_block, offset, fragment->index,\n\t\t\tfragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\n\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inodep);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index,\n\t\t\t\t(squashfs_dir_index *) p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name,\n\t\t\t\tindex[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size\n\t\t\t\t+ 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %lld, start_block \"\n\t\t\t\"0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir,\n\t\t\t(squashfs_dir_inode_header *) inode);\n\t\tTRACE(\"Directory inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"offset 0x%x, nlink %d\\n\", byte_size, start_block,\n\t\t\toffset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\t\tunsigned int major = major(buf->st_rdev);\n\t\tunsigned int minor = minor(buf->st_rdev);\n\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", major, filename,\n\t\t\t\tmajor & 0xfff);\n\t\t\tmajor &= 0xfff;\n\t\t}\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", minor, filename,\n\t\t\t\tminor & 0xfffff);\n\t\t\tminor &= 0xfffff;\n\t\t}\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (major << 8) | (minor & 0xff) |\n\t\t\t\t((minor & ~0xff) << 12);\n\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev,\n\t\t\t(squashfs_dev_inode_header *) inode);\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink,\n\t\t\t*inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty \"\n\t\t\t\t\"symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! \"\n\t\t\t\t\"Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inodep);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte,\n\t\t\tnlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc,\n\t\t\t(squashfs_ipc_inode_header *) inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type ==\n\t\t\tSQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type,\n\t\tbase->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan3_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name,\n\tint type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\"\n\t\t\t\"\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size +\n\t\t\tsizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tbuff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE);\n\t\tif(buff == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\"\n\t\t\t\t\"\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff +\n\t\t\tbuff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block ||\n\t\t\t((dir->entry_count_p != NULL) &&\n\t\t\t((dir->p + sizeof(squashfs_dir_entry) + size -\n\t\t\tdir->index_count_p) > SQUASHFS_METADATA_SIZE)) ||\n\t\t\t((long long) inode_number - dir->inode_number) > 32767\n\t\t\t|| ((long long) inode_number - dir->inode_number)\n\t\t\t< -32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size -\n\t\t\t\t\tdir->index_count_p) >\n\t\t\t\t\tSQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0) {\n\t\t\t\t\tdir->index = realloc(dir->index,\n\t\t\t\t\t\t(dir->i_count + I_COUNT_SIZE) *\n\t\t\t\t\t\tsizeof(struct cached_dir_index));\n\t\t\t\t\tif(dir->index == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in \"\n\t\t\t\t\t\t\t\"directory index table \"\n\t\t\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t\t}\n\t\t\t\tdir->index[dir->i_count].index.index =\n\t\t\t\t\tdir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) +\n\t\t\t\t\tsize;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header,\n\t\t\t\t(squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tSQUASHFS_SWAP_DIR_ENTRY(&idir, idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info,\n\tstruct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ?\n\t\t\t((dir_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tdirectory_data_cache = realloc(directory_data_cache,\n\t\t\tdirectory_cache_size + realloc_size);\n\t\tif(directory_data_cache == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header,\n\t\t\t(squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff,\n\t\t\tdir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count &&\n\t\t\t\tdir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block =\n\t\t\t\tdirectory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) <\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tdirectory_table = realloc(directory_table,\n\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2);\n\t\t\tif(directory_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\t\tBLOCK_OFFSET, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE,\n\t\t\t\tnoI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, (unsigned short *)\n\t\t\t(directory_table + directory_bytes), 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemcpy(directory_data_cache, directory_data_cache +\n\t\t\tSQUASHFS_METADATA_SIZE, directory_cache_bytes -\n\t\t\tSQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir)\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE,\n\t\t\tdir_size + 3, directory_block, directory_offset, NULL,\n\t\t\tNULL, dir, 0);\n\telse\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE,\n\t\t\tdir_size + 3, directory_block, directory_offset, NULL,\n\t\t\tNULL, NULL, 0);\n\n#ifdef SQUASHFS_TRACE\n\t{\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header dirh;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((squashfs_dir_header *) dirp,\n\t\t\t\t&dirh);\n\t\t\tcount = dirh.count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\",\n\t\t\t\tdirh.start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(idirp, &idir);\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type \"\n\t\t\t\t\t\"%d\\n\", buffer, idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size +\t\t\t\t\t 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nstruct file_buffer *get_fragment(struct fragment *fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\tlong long start_block;\n\tstruct file_buffer *buffer, *compressed_buffer;\n\n\tif(fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn NULL;\n\n\tbuffer = cache_lookup(fragment_buffer, fragment->index);\n\tif(buffer)\n\t\treturn buffer;\n\n\tcompressed_buffer = cache_lookup(writer_buffer, fragment->index +\n\t\tFRAG_INDEX);\n\n\tbuffer = cache_get(fragment_buffer, fragment->index, 1);\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\tstart_block = disk_fragment->start_block;\n\tpthread_mutex_unlock(&fragment_mutex);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar *data;\n\n\t\tif(compressed_buffer)\n\t\t\tdata = compressed_buffer->data;\n\t\telse\n\t\t\tdata = read_from_disk(start_block, size);\n\n\t\tres = uncompress_wrapper((unsigned char *) buffer->data, &bytes,\n\t\t\t(const unsigned char *) data, size);\n\t\tif(res != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"uncompress failed,\"\n\t\t\t\t\t\"  unknown error %d\\n\", res);\n\t\t}\n\t} else if(compressed_buffer)\n\t\tmemcpy(buffer->data, compressed_buffer->data, size);\n\telse\n\t\tread_destination(fd, start_block, size, buffer->data);\n\n\tcache_block_put(compressed_buffer);\n\n\treturn buffer;\n}\n\n\nstruct frag_locked {\n\tstruct file_buffer *buffer;\n\tint c_byte;\n\tint fragment;\n\tstruct frag_locked *fragment_prev;\n\tstruct frag_locked *fragment_next;\n};\n\nint fragments_locked = FALSE;\nstruct frag_locked *frag_locked_list = NULL;\n\nINSERT_LIST(fragment, struct frag_locked)\nREMOVE_LIST(fragment, struct frag_locked)\n\nint lock_fragments()\n{\n\tint count;\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragments_locked = TRUE;\n\tcount = fragments_outstanding;\n\tpthread_mutex_unlock(&fragment_mutex);\n\treturn count;\n}\n\n\nvoid unlock_fragments()\n{\n\tstruct frag_locked *entry;\n\tint compressed_size;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(frag_locked_list) {\n\t\tentry = frag_locked_list;\n\t\tremove_fragment_list(&frag_locked_list, entry);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->c_byte);\n\t\tfragment_table[entry->fragment].size = entry->c_byte;\n\t\tfragment_table[entry->fragment].start_block = bytes;\n\t\tentry->buffer->block = bytes;\n\t\tbytes += compressed_size;\n\t\tfragments_outstanding --;\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\tqueue_put(to_writer, entry->buffer);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tTRACE(\"fragment_locked writing fragment %d, compressed size %d\"\n\t\t\t\"\\n\", entry->fragment, compressed_size);\n\t\tfree(entry);\n\t}\n\tfragments_locked = FALSE;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nint add_pending_fragment(struct file_buffer *write_buffer, int c_byte,\n\tint fragment)\n{\n\tstruct frag_locked *entry = malloc(sizeof(struct frag_locked));\n\tif(entry == NULL)\n\t\treturn FALSE;\n\tentry->buffer = write_buffer;\n\tentry->c_byte = c_byte;\n\tentry->fragment = fragment;\n\tentry->fragment_prev = entry->fragment_next = NULL;\n\tpthread_mutex_lock(&fragment_mutex);\n\tinsert_fragment_list(&frag_locked_list, entry);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tfragment_table = realloc(fragment_table, (fragments +\n\t\t\tFRAG_SIZE) * sizeof(squashfs_fragment_entry));\n\t\tif(fragment_table == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].unused = 0;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = cache_get(fragment_buffer, fragments, 1);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data,\n\t\tfile_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) /\n\t\tSQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + BLOCK_OFFSET, buffer + i *\n\t\t\tSQUASHFS_METADATA_SIZE , avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, (unsigned short *) cbuffer, 1);\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes,\n\t\t\tcompressed_size);\n\t\twrite_destination(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tSQUASHFS_INSWAP_LONG_LONGS(list, meta_blocks);\n\twrite_destination(fd, bytes, sizeof(list), (char *) list);\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count *\n\t\tsizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments,\n\t\tfrag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block 0x%llx, \"\n\t\t\t\"size %d\\n\", i, fragment_table[i].start_block,\n\t\t\tfragment_table[i].size);\n\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_destination(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\nchar read_from_file_buffer2[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk2(long long start, unsigned int avail_bytes)\n{\n\tread_destination(fd, start, avail_bytes, read_from_file_buffer2);\n\treturn read_from_file_buffer2;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l,\n\tunsigned int *blocks)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\tstruct file_buffer *write_buffer;\n\tint i;\n\n\tfor(i = 0; l; i++)  {\n\t\tbytes = SQUASHFS_COMPRESSED_SIZE_BLOCK(blocks[i]);\n\t\tif(bytes == 0) /* sparse block */\n\t\t\tcontinue;\n\t\twrite_buffer = cache_lookup(writer_buffer, start);\n\t\tif(write_buffer) {\n\t\t\tchksum = get_checksum(write_buffer->data, bytes,\n\t\t\t\tchksum);\n\t\t\tcache_block_put(write_buffer);\n\t\t} else\n\t\t\tchksum = get_checksum(read_from_disk(start, bytes),\n\t\t\t\tbytes, chksum);\n\t\tl -= bytes;\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes,\n\tunsigned int *block_listp, int blocks, unsigned int fragment,\n\tint offset, int bytes)\n{\n\tstruct fragment *frg;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset !=\n\t\t\t\tdupl_ptr->fragment->offset || bytes !=\n\t\t\t\tdupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && file_size ==\n\t\t\t\tdupl_ptr->fragment->size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, file_size);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes &&\n\t\t\t\t frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tlong long target_start, dup_start = dupl_ptr->start;\n\t\t\tint block;\n\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks *\n\t\t\t\t\tsizeof(unsigned int)) != 0)\n\t\t\t\tcontinue;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_disk(*start, bytes,\n\t\t\t\t\t*block_list);\n\t\t\t\tfragment_checksum =\n\t\t\t\t\tget_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, frag_bytes);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum ||\n\t\t\t\t\tfragment_checksum !=\n\t\t\t\t\tdupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\ttarget_start = *start;\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t((*block_list)[block]);\n\t\t\t\tstruct file_buffer *target_buffer = NULL;\n\t\t\t\tstruct file_buffer *dup_buffer = NULL;\n\t\t\t\tchar *target_data, *dup_data;\n\t\t\t\tint res;\n\n\t\t\t\tif(size == 0)\n\t\t\t\t\tcontinue;\n\t\t\t\ttarget_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\ttarget_start);\n\t\t\t\tif(target_buffer)\n\t\t\t\t\ttarget_data = target_buffer->data;\n\t\t\t\telse\n\t\t\t\t\ttarget_data =\n\t\t\t\t\t\tread_from_disk(target_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tdup_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\tdup_start);\n\t\t\t\tif(dup_buffer)\n\t\t\t\t\tdup_data = dup_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tdup_data = read_from_disk2(dup_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tres = memcmp(target_data, dup_data, size);\n\t\t\t\tcache_block_put(target_buffer);\n\t\t\t\tcache_block_put(dup_buffer);\n\t\t\t\tif(res != 0)\n\t\t\t\t\tbreak;\n\t\t\t\ttarget_start += size;\n\t\t\t\tdup_start += size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\n\t\t\t\tif(frag_bytes == 0 ||\n\t\t\t\t\t\tmemcmp(file_buffer->data,\n\t\t\t\t\t\tfrag_buffer->data +\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfrag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start \"\n\t\t\t\t\t\t\"0x%llx, size %lld, checksum \"\n\t\t\t\t\t\t\"0x%x, fragment %d, size %d, \"\n\t\t\t\t\t\t\"offset %d, checksum 0x%x\\n\",\n\t\t\t\t\t\tdupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes,\n\t\t\t\t\t\tdupl_ptr->checksum,\n\t\t\t\t\t\tdupl_ptr->fragment->index,\n\t\t\t\t\t\tfrag_bytes,\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment,\n\t\tchecksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\n\tstruct file_buffer *file_buffer;\n\tstatic int index = 0;\n\tint blocks, byte, count, expected, file, frag_block;\n\tlong long bytes, read_size;\n\n\tif(dir_ent->inode->read)\n\t\treturn;\n\n\tdir_ent->inode->read = TRUE;\nagain:\n\tbytes = 0;\n\tcount = 0;\n\tfile_buffer = NULL;\n\tread_size = buf->st_size;\n\tblocks = (read_size + block_size - 1) >> block_log;\n\tfrag_block = !no_fragments && (always_use_fragments ||\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\texpected = read_size - ((long long) count * block_size) >\n\t\t\tblock_size ? block_size :\n\t\t\tread_size - ((long long) count * block_size);\n\n\t\tif(file_buffer)\n\t\t\tqueue_put(from_reader, file_buffer);\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = index ++;\n\n\t\tbyte = file_buffer->size = read_bytes(file, file_buffer->data,\n\t\t\tblock_size);\n\n\t\tfile_buffer->file_size = read_size;\n\n\t\tif(byte != expected)\n\t\t\tgoto restat;\n\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->error = FALSE;\n\t\tfile_buffer->fragment = (file_buffer->block == frag_block);\n\n\t\tbytes += byte;\n\t\tcount ++;\n\t} while(count < blocks);\n\n\tif(read_size != bytes)\n\t\tgoto restat;\n\n\tif(expected == block_size) {\n\t\tchar buffer;\n\n\t\tif(read_bytes(file, &buffer, 1) == 1)\n\t\t\tgoto restat;\n\t}\n\n\tqueue_put(from_reader, file_buffer);\n\n\tclose(file);\n\n\treturn;\n\nread_err:\n\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\tfile_buffer->sequence = index ++;\nread_err2:\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n\treturn;\nrestat:\n\tfstat(file, &buf2);\n\tclose(file);\n\tif(read_size != buf2.st_size) {\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\n\t\tfile_buffer->error = 2;\n\t\tqueue_put(from_deflate, file_buffer);\n\t\tgoto again;\n\t}\n\tgoto read_err2;\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\n\tthread[0] = 0;\n\n\tpthread_exit(NULL);\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer,\n\t\t\t\twrite_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write_bytes(fd, file_buffer->data,\n\t\t\t\tfile_buffer->size) == -1) {\n\t\t\tERROR(\"Write on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\nint all_zero(struct file_buffer *file_buffer)\n{\n\tint i;\n\tlong entries = file_buffer->size / sizeof(long);\n\tlong *p = (long *) file_buffer->data;\n\n\tfor(i = 0; i < entries && p[i] == 0; i++);\n\n\tif(i == entries) {\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1);\n\t\t\ti < file_buffer->size && file_buffer->data[i] == 0;\n\t\t\ti++);\n\n\t\treturn i == file_buffer->size;\n\t}\n\n\treturn 0;\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer;\n\n\t\tif(sparse_files && all_zero(file_buffer)) { \n\t\t\tfile_buffer->c_byte = 0;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else if(file_buffer->fragment) {\n\t\t\tfile_buffer->c_byte = file_buffer->size;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else {\n\t\t\twrite_buffer = cache_get(writer_buffer, 0, 0);\n\t\t\twrite_buffer->c_byte = mangle2(&stream,\n\t\t\t\twrite_buffer->data, file_buffer->data,\n\t\t\t\tfile_buffer->size, block_size, noD, 1);\n\t\t\twrite_buffer->sequence = file_buffer->sequence;\n\t\t\twrite_buffer->file_size = file_buffer->file_size;\n\t\t\twrite_buffer->block = file_buffer->block;\n\t\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t(write_buffer->c_byte);\n\t\t\twrite_buffer->fragment = FALSE;\n\t\t\twrite_buffer->error = FALSE;\n\t\t\tcache_block_put(file_buffer);\n\t\t\tqueue_put(from_deflate, write_buffer);\n\t\t}\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer =\n\t\t\tcache_get(writer_buffer, file_buffer->block +\n\t\t\tFRAG_INDEX, 1);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data,\n\t\t\tfile_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\twrite_buffer->size = compressed_size;\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tif(fragments_locked == FALSE) {\n\t\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\t\twrite_buffer->block = bytes;\n\t\t\tbytes += compressed_size;\n\t\t\tfragments_outstanding --;\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tqueue_put(to_writer, write_buffer);\n\t\t\tTRACE(\"Writing fragment %lld, uncompressed size %d, \"\n\t\t\t\t\"compressed size %d\\n\", file_buffer->block,\n\t\t\t\tfile_buffer->size, compressed_size);\n\t\t} else {\n\t\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\t\tadd_pending_fragment(write_buffer, c_byte,\n\t\t\t\t\tfile_buffer->block);\n\t\t}\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->sequence);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int sequence = 0;\n\tint hash = BLOCK_HASH(sequence);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->sequence == sequence)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->sequence == sequence)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tsequence ++;\n\n\treturn file_buffer;\n}\n\n\nvoid *progress_thrd(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&progress_mutex);\n\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) *\n\t\t\t1000;\n\t\tpthread_cond_timedwait(&progress_wait, &progress_mutex,\n\t\t\t&timespec);\n\t\tif(progress_enabled && estimated_uncompressed)\n\t\t\tprogress_bar(cur_uncompressed, estimated_uncompressed,\n\t\t\t\tcolumns);\n\t}\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits = floor(log10(max)) + 1;\n\tint used = max_digits * 2 + 11;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\tstatic int tty = -1;\n\n\tif((current > max) || (columns - used < 0))\n\t\treturn;\n\n\tif(tty == -1)\n\t\ttty = isatty(STDOUT_FILENO);\n\tif(!tty) {\n\t\tstatic long long previous = -1;\n\n\t\t/* Updating much more frequently than this results in huge\n\t\t * log files. */\n\t\tif((current % 100) != 0 && current != max)\n\t\t\treturn;\n\t\t/* Don't update just to rotate the spinner. */\n\t\tif(current == previous)\n\t\t\treturn;\n\t\tprevious = current;\n\t}\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL,\n\t\t\t&empty_fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL,\n\t\t\t&empty_fragment, NULL, 0);\n}\n\n\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint size, int *duplicate_file, struct file_buffer *file_buffer,\n\tunsigned short checksum)\n{\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment,\n\t\tfile_buffer, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\tcache_block_put(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tinc_progress_bar();\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n}\n\n\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size,\n\tstruct file_buffer *file_buffer, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum)) {\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file,\n\t\t\tfile_buffer, checksum);\n\t\treturn;\n\t}\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\tcache_block_put(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tinc_progress_bar();\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n\n\treturn;\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tlong long file_bytes, start;\n\tstruct fragment *fragment;\n\tunsigned int *block_list;\n\tint block, status;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\t*duplicate_file = FALSE;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tlock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else {\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tfragment = get_and_fill_fragment(fragment_buffer);\n\tcache_block_put(fragment_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment,\n\t\t\t0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < (1LL << 32) && start <\n\t\t\t(1LL << 32) && sparse == 0)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size,\n\t\t\tstart, blocks, block_list, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size,\n\t\t\tstart, blocks, block_list, fragment, NULL, sparse);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(!block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tint block, thresh;\n\tlong long file_bytes, dup_start, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer **buffer_list;\n\tint status, num_locked_fragments;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\tblock_list = malloc(blocks * sizeof(unsigned int));\n\tif(block_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tbuffer_list = malloc(blocks * sizeof(struct file_buffer *));\n\tif(buffer_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tnum_locked_fragments = lock_fragments();\n\n\tfile_bytes = 0;\n\tstart = dup_start = bytes;\n\tthresh = blocks > (writer_buffer_size - num_locked_fragments) ?\n\t\tblocks - (writer_buffer_size - num_locked_fragments): 0;\n\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tif(block < thresh) {\n\t\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t\t} else\n\t\t\t\t\tbuffer_list[block] = read_buffer;\n\t\t\t} else {\n\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &dup_start,\n\t\t&fragment, fragment_buffer, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tif(buffer_list[block])\n\t\t\t\tqueue_put(to_writer, buffer_list[block]);\n\t\tfragment = get_and_fill_fragment(fragment_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tcache_block_put(buffer_list[block]);\n\t\tbytes = start;\n\t\tif(thresh && !block_device) {\n\t\t\tint res;\n\n\t\t\tqueue_put(to_writer, NULL);\n\t\t\tif(queue_get(from_writer) != 0)\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\tres = ftruncate(fd, bytes);\n\t\t\tif(res != 0)\n\t\t\t\tBAD_ERROR(\"Failed to truncate dest file because\"\n\t\t\t\t\t\"  %s\\n\", strerror(errno));\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tcache_block_put(fragment_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < (1LL << 32) && dup_start <\n\t\t\t(1LL << 32) && sparse == 0)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size,\n\t\t\tdup_start, blocks, block_listp, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size,\n\t\t\tdup_start, blocks, block_listp, fragment, NULL, sparse);\n\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(thresh && !block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\tcache_block_put(buffer_list[blocks]);\n\tfree(buffer_list);\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tint status;\n\tstruct file_buffer *read_buffer;\n\tlong long read_size;\n\nagain:\n\tread_buffer = get_file_buffer(from_deflate);\n\n\tstatus = read_buffer->error;\n\tif(status) {\n\t\tcache_block_put(read_buffer);\n\t\tgoto file_err;\n\t}\n\t\n\tread_size = read_buffer->file_size;\n\n\tif(read_size == 0) {\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t\tcache_block_put(read_buffer);\n\t} else if(read_buffer->fragment && read_buffer->c_byte)\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer,\n\t\t\tduplicate_file);\n\telse if(pre_duplicate(read_size))\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\telse\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\nfile_err:\n\tif(status == 2) {\n\t\tERROR(\"File %s changed size while reading filesystem, \"\n\t\t\t\"attempting to re-read\\n\", dir_ent->pathname);\n\t\tgoto again;\n\t} else if(status == 1) {\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\",\n\t\t\tdir_ent->pathname);\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t}\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) ||\n\t\t\t\t((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\"\n\t\t\t\"\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\n\tif((buf->st_mode & S_IFMT) == S_IFREG)\n\t\testimated_uncompressed += (buf->st_size + block_size - 1) >>\n\t\t\tblock_log;\n\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir,\n\tstruct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0) {\n\t\tdir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) *\n\t\t\t\tsizeof(struct dir_ent *));\n\t\tif(dir->list == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\t}\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) :\n\t\tNULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count\n\t\t= 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL,\n\t\t\t\t&old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\",\n\t\t\t\tsource_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count &&\n\t\t\t\tstrcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL,\n\t\t\t\t&old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count &&\n\t\t\t\tstrcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tcontinue;\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nstruct dir_ent *scan2_lookup(struct dir_info *dir, char *name)\n{\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++)\n\t\tif(strcmp(dir->list[i]->name, name) == 0)\n\t\t\treturn dir->list[i];\n\n\treturn NULL;\n}\n\n\nstruct dir_ent *scan3_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode,\n\t\t\t\tdir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name,\n\t\t\t\tdir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct dir_info *dir)\n{\n\tdir->current_count = 0;\n}\n\n\nvoid scan3_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tdir_scan2(dir_info, pseudo);\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/*\n \t\t *dummy top level directory, if multiple sources specified on\n\t\t * command line\n\t\t */\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", pathname,\n\t\t\tstrerror(errno));\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0,\n\t\t\t&dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tif(progress)\n\t\tenable_progress_bar();\n\tdir_scan3(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\tstruct pathnames *new;\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\",\n\t\t\t\tfilename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\"\n\t\t\t\t\"\\n\", filename, buf.st_mode & S_IFMT);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(old_exclude) {\n\t\t\tif(old_excluded(filename, &buf))\n\t\t\t\tcontinue;\n\t\t} else {\n\t\t\tif(excluded(paths, dir_name, &new))\n\t\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tsub_dir = dir_scan1(filename, new, scan1_readdir);\n\t\t\tif(sub_dir == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf),\n\t\t\tNULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\nerror:\n\treturn dir;\n}\n\n\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo)\n{\n\tstruct dir_info *sub_dir;\n\tstruct dir_ent *dir_ent;\n\tstruct pseudo_entry *pseudo_ent;\n\tstruct stat buf;\n\tstatic pseudo_ino = 1;\n\t\n\tif(dir == NULL && (dir = scan1_opendir(\"\")) == NULL)\n\t\treturn NULL;\n\t\n\twhile((dir_ent = scan2_readdir(dir)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *name = dir_ent->name;\n\n\t\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\tdir_scan2(dir_ent->dir, pseudo_subdir(name, pseudo));\n\t}\n\n\twhile((pseudo_ent = pseudo_readdir(pseudo)) != NULL) {\n\t\tdir_ent = scan2_lookup(dir, pseudo_ent->name);\n\t\tif(dir_ent) {\n\t\t\tERROR(\"Pseudo file \\\"%s\\\" exists in source filesystem \"\n\t\t\t\t\"\\\"%s\\\"\\n\", pseudo_ent->pathname,\n\t\t\t\tdir_ent->pathname);\n\t\t\tERROR(\"Ignoring, exclude it (-e/-ef) to override\\n\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(pseudo_ent->dev->type == 'd') {\n\t\t\tsub_dir = dir_scan2(NULL, pseudo_ent->pseudo);\n\t\t\tif(sub_dir == NULL) {\n\t\t\t\tERROR(\"Could not create pseudo directory \\\"%s\\\"\"\n\t\t\t\t\t\", skipping...\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = pseudo_ent->dev->mode;\n\t\tbuf.st_uid = pseudo_ent->dev->uid;\n\t\tbuf.st_gid = pseudo_ent->dev->gid;\n\t\tbuf.st_rdev = makedev(pseudo_ent->dev->major,\n\t\t\tpseudo_ent->dev->minor);\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_ino = pseudo_ino ++;\n\n\t\tadd_dir_entry(pseudo_ent->name, pseudo_ent->pathname, sub_dir,\n\t\t\tlookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan2_freedir(dir);\n\tsort_directory(dir);\n\n\treturn dir;\n}\n\n\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan3_init_dir(&dir);\n\t\n\twhile((dir_ent = scan3_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\t?  dir_ent->inode->inode_number :\n\t\t\tdir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\twrite_file(inode, dir_ent,\n\t\t\t\t\t\t&duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld \"\n\t\t\t\t\t\t\"bytes %s\\n\", filename,\n\t\t\t\t\t\tbuf->st_size, duplicate_file ?\n\t\t\t\t\t\t\"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tdir_scan3(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\"\n\t\t\t\t\t\t\"\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\",dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tBAD_ERROR(\"%s unrecognised file type, \"\n\t\t\t\t\t\t\"mode is %x\\n\", filename,\n\t\t\t\t\t\tbuf->st_mode);\n\t\t\t}\n\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed \"\n\t\t\t\t\t\t\t\"size %lld bytes LINK\"\n\t\t\t\t\t\t\t\"\\n\", filename,\n\t\t\t\t\t\t\tbuf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx LINK\\n\", dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t\tupdate_progress_bar();\n\t}\n\n\twrite_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan3_freedir(&dir);\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 20; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint old_excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) &&\n\t\t\t\t(exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) { \\\n\t\texclude_paths = realloc(exclude_paths, (exclude + EXCLUDE_SIZE) \\\n\t\t\t* sizeof(struct exclude_info)); \\\n\t\tif(exclude_paths == NULL) \\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\"); \\\n\t} \\\n\texclude_paths[exclude].st_dev = buf.st_dev; \\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint old_add_exclude(char *path)\n{\n\tint i;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 ||\n\t\t\tstrncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat exclude dir/file %s because %s, \"\n\t\t\t\t\"ignoring\", path, strerror(errno));\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tERROR(\"Cannot stat exclude dir/file %s because \"\n\t\t\t\t\t\"%s, ignoring\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type)\n{\n\told_root_entry = realloc(old_root_entry,\n\t\tsizeof(struct old_root_entry_info) * (old_root_entries + 1));\n\tif(old_root_entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries \"\n\t\t\t\"reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  \"\n\t\t\t\t\"Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(fragment_buffer_size);\n\treader_buffer = cache_init(block_size, reader_buffer_size);\n\twriter_buffer = cache_init(block_size, writer_buffer_size);\n\tfragment_buffer = cache_init(block_size, fragment_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&progress_thread, NULL, progress_thrd, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) !=\n\t\t\t\t 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator,\n\t\t\t\tNULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tinode_lookup_table = realloc(inode_lookup_table, lookup_bytes);\n\tif(inode_lookup_table == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number +\n\t\t\t\tdir_inode_no;\n\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(&inode->inode,\n\t\t\t\t&inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table,\n\t\t0);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) *\n\t\t\tsizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname,\n\t\t\t\tREG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, \"\n\t\t\t\t\t\"because %s\\n\", targname, alltarget,\n\t\t\t\t\tstr);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target,\n\t\t\t\talltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing exclude which subsumes\n\t\t\t * the exclude currently being added, in which case stop\n\t\t\t * adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist\n\t\t\t * from more specific excludes, delete as they're\n\t\t\t * subsumed by this exclude */\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid add_exclude(char *target)\n{\n\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 ||\n\t\t\tstrncmp(target, \"../\", 3) == 0)\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with \"\n\t\t\t\"-wildcards or -regex options\\n\");\t\n\telse if(strncmp(target, \"... \", 4) == 0)\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\n\telse\t\n\t\tpath = add_path(path, target, target);\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) +\n\t\t\t(paths->count + PATHS_ALLOC_SIZE) *\n\t\t\tsizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n, res;\n\t\t\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\n\t*new = init_subdir();\n\tif(stickypath)\n\t\t*new = add_subdir(*new, stickypath);\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0,\n\t\t\t\t\tNULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name,\n\t\t\t\t\tFNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) ==\n\t\t\t\t\t 0;\n\n\t\t\tif(match && path->name[i].paths == NULL) {\n\t\t\t\t/* match on a leaf component, any subdirectories\n\t\t\t\t * in the filesystem should be excluded */\n\t\t\t\tres = TRUE;\n\t\t\t\tgoto empty_set;\n\t\t\t}\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any\n\t\t\t\t * subdirectories to the new set of\n\t\t\t\t * subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t\t/* no matching names found, return empty new search set\n\t\t\t */\n\t\t\tres = FALSE;\n\t\t\tgoto empty_set;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches).\n\t * Return new set */\n\treturn FALSE;\n\nempty_set:\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn res;\n}\n\n\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\n#define RECOVER_ID_SIZE 28\n\nvoid write_recovery_data(squashfs_super_block *sBlk)\n{\n\tint recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\n\tpid_t pid = getpid();\n\tchar *metadata;\n\tchar header[] = RECOVER_ID;\n\n\tif(recover == FALSE) {\n\t\tprintf(\"No recovery data option specified.\\n\");\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\n\t\treturn;\n\t}\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"write_recovery_data\\n\");\n\n\tread_destination(fd, sBlk->inode_table_start, bytes, metadata);\n\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\",\n\t\tgetbase(destination_file), pid);\n\trecoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);\n\tif(recoverfd == -1)\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  \"\n\t\t\t\"Aborting\\n\", strerror(errno));\n\t\t\n\tif(write_bytes(recoverfd, header, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, metadata, bytes) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tclose(recoverfd);\n\tfree(metadata);\n\t\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file,\n\t\trecovery_file);\n\tprintf(\"to restore filesystem\\n\\n\");\n}\n\n\nvoid read_recovery_data(char *recovery_file, char *destination_file)\n{\n\tint fd, recoverfd, bytes;\n\tsquashfs_super_block orig_sBlk, sBlk;\n\tchar *metadata;\n\tint res;\n\tstruct stat buf;\n\tchar header[] = RECOVER_ID;\n\tchar header2[RECOVER_ID_SIZE];\n\n\tif((recoverfd = open(recovery_file, O_RDONLY)) == -1)\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(stat(destination_file, &buf) == -1)\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif((fd = open(destination_file, O_RDWR)) == -1)\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tres = read_bytes(recoverfd, header2, RECOVER_ID_SIZE);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < RECOVER_ID_SIZE)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\n\n\tres = read_bytes(recoverfd, &sBlk, sizeof(squashfs_super_block));\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < sizeof(squashfs_super_block))\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\tread_destination(fd, 0, sizeof(squashfs_super_block), (char *)\n\t\t&orig_sBlk);\n\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4,\n\t\t\tsizeof(squashfs_super_block) - 4) != 0)\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to \"\n\t\t\t\"match\\n\");\n\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"read_recovery_data\\n\");\n\n\tres = read_bytes(recoverfd, metadata, bytes);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < bytes)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\twrite_destination(fd, 0, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\twrite_destination(fd, sBlk.inode_table_start, bytes, metadata);\n\n\tclose(recoverfd);\n\tclose(fd);\n\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\",\n\t\trecovery_file);\n\t\n\texit(0);\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 4.0 (2009/04/05)\\n\");\\\n\tprintf(\"copyright (C) 2009 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n\tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint nopad = FALSE, keep_as_directory = FALSE;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT,\n\t\twriteb_mbytes = WRITER_BUFFER_DEFAULT,\n\t\tfragmentb_mbytes = FRAGMENT_BUFFER_DEFAULT;\n\tint s_minor = SQUASHFS_MINOR;\n\n\tcompression=LZMA_COMPRESSION;\n\n\tpthread_mutex_init(&progress_mutex, NULL);\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-pf\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -pf missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_file(&pseudo, argv[i]) == FALSE) {\n\t\t\t\tERROR(\"Failed to parse pseudo file \\\"%s\\\"\\n\",\n\t\t\t\t\targv[i]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-p\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -p missing pseudo file definition\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_def(&pseudo, argv[i]) == FALSE) {\n\t\t\t\tERROR(\"Failed to parse pseudo definition\\n\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-recover\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\n\t\t\trecover = FALSE;\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = FALSE;\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\n\t\t\tsparse_files = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid \"\n\t\t\t\t\t\"processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte \"\n\t\t\t\t\t\"or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-fragment-queue\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(fragmentb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -fragment-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragmentb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -fragment-queue should be 1 \"\n\t\t\t\t\t\"megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -b missing block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_size = strtol(argv[i], &b, 10);\n\t\t\tif(*b == 'm' || *b == 'M')\n\t\t\t\tblock_size *= 1048576;\n\t\t\telse if(*b == 'k' || *b == 'K')\n\t\t\t\tblock_size *= 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tERROR(\"%s: -b invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or \"\n\t\t\t\t\t\"not between 4096 and 1Mbyte\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n#ifdef USE_LZMA\n\t\t} else if(strcmp(argv[i], \"-nolzma\") == 0) {\n\t\t\tcompression = ZLIB_COMPRESSION;\n#endif\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or \"\n\t\t\t\t\t\t\"unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or \"\n\t\t\t\t\t\t\"unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0) {\n\t\t\tsilent = FALSE;\n\t\t\tprogress = FALSE;\n\t\t}\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] \"\n\t\t\t\t\"[-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and \"\n\t\t\t\t\"copyright message\\n\");\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data \"\n\t\t\t\t\"using recovery file <name>\\n\");\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery \"\n\t\t\t\t\"file\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem \"\n\t\t\t\t\"exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress \"\n\t\t\t\t\"bar\\n\");\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to \"\n\t\t\t\t\"<block_size>.  Default %d bytes\\n\",\n\t\t\t\tSQUASHFS_FILE_SIZE);\n#ifdef USE_LZMA\n\t\t\tERROR(\"-lzma Enable LZMA compression\\n\");\n#endif\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.\"\n\t\t\t\t\"  By default will use number of\\n\");\n\t\t\tERROR(\"\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tREADER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tWRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-fragment-queue <size>\\tSet fagment queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tFRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for \"\n\t\t\t\t\"files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate \"\n\t\t\t\t\"checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing \"\n\t\t\t\t\"filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is \"\n\t\t\t\t\"specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, \"\n\t\t\t\t\"rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source \"\n\t\t\t\t\"files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in \"\n\t\t\t\t\"the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new \"\n\t\t\t\t\"source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple \"\n\t\t\t\t\"of 4K\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for \"\n\t\t\t\t\"-noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to \"\n\t\t\t\t\"priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  \"\n\t\t\t\t\"Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.\"\n\t\t\t\t\"  One per line\\n\");\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards \"\n\t\t\t\t\"(globbing) to be used in\\n\\t\\t\\texclude \"\n\t\t\t\t\"dirs/files\\n\");\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to \"\n\t\t\t\t\"be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n\t\t\tERROR(\"-p <pseudo-definition>\\tAdd pseudo file definition\\n\");\n\t\t\tERROR(\"-pf <pseudo-file>\\tAdd list of pseudo file definitions\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\tfragment_buffer_size = fragmentb_mbytes << (20 - block_log);\n\n\tfor(i = 0; i < source; i++)\n\t\tif(lstat(source_path[i], &source_buf) == -1) {\n\t\t\tfprintf(stderr, \"Cannot stat source directory \\\"%s\\\" \"\n\t\t\t\t\"because %s\\n\", source_path[i],\n\t\t\t\tstrerror(errno));\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tfd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR,\n\t\t\t\tS_IRUSR |S_IWUSR|S_IRGRP|S_IROTH);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as \"\n\t\t\t\t\t\"destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tfd = open(argv[source + 1], (delete ? O_TRUNC : 0) |\n\t\t\t\tO_RDWR);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not open regular file for \"\n\t\t\t\t\t\"writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tsignal(SIGTERM, sighandler2);\n\tsignal(SIGINT, sighandler2);\n\n\t/* process the exclude files - must be done afer destination file has\n\t * been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\t\tif(old_exclude)\n\t\t\t\t\t\told_add_exclude(filename);\n\t\t\t\t\telse\n\t\t\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-sort\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-p\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc)\n\t\t\tif(old_exclude)\n\t\t\t\told_add_exclude(argv[i++]);\n\t\t\telse\n\t\t\t\tadd_exclude(argv[i++]);\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-ef\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-p\") == 0)\n\t\t\ti++;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\ts_minor = sBlk.s_minor;\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t}\n\n\tinitialise_threads();\n\n\tif(delete) {\n\t\tprintf(\"Creating %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\tSQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset,\n\t\t\tinode_dir_file_size, root_inode_size,\n\t\t\tinode_dir_start_block, uncompressed_data,\n\t\t\tcompressed_data, inode_dir_inode_number,\n\t\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start =\n\t\t\tSQUASHFS_INODE_BLK(sBlk.root_inode),\n\t\t\troot_inode_offset =\n\t\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table,\n\t\t\t\t&data_cache, &directory_table,\n\t\t\t\t&directory_data_cache, &last_directory_block,\n\t\t\t\t&inode_dir_offset, &inode_dir_file_size,\n\t\t\t\t&root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count,\n\t\t\t\t&fifo_count, &sock_count, &total_bytes,\n\t\t\t\t&total_inode_bytes, &total_directory_bytes,\n\t\t\t\t&inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry,\n\t\t\t\t&fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = realloc((char *) fragment_table,\n\t\t\t\t((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1))\n\t\t\t\t * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %d.%d filesystem on %s, block \"\n\t\t\t\"size %d\\n\", SQUASHFS_MAJOR, s_minor, argv[source + 1],\n\t\t\tblock_size);\n\t\tprintf(\"All -b, -noI, -noD, -noF, no-duplicates, no-fragments, \"\n\t\t\t\"-always-use-fragments and -exportable options ignored\"\n\t\t\t\"\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with \"\n\t\t\t\"-noappend specified!\\n\\n\");\n\n\t\tcompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t(SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tscache_bytes = root_inode_offset + root_inode_size;\n\t\tsdirectory_cache_bytes = uncompressed_data;\n\t\tsdata_cache = malloc(scache_bytes);\n\t\tsdirectory_data_cache = malloc(sdirectory_cache_bytes);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache +\n\t\t\tcompressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes +\n\t\t\tcompressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\tsid_count = id_count;\n\t\twrite_recovery_data(&sBlk);\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_destination(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/*\n\t\t * set the filesystem state up to be able to append to the\n\t\t * original filesystem.  The filesystem state differs depending\n\t\t * on whether we're appending to the original root directory, or\n\t\t * if the original root directory becomes a sub-directory\n\t\t * (root-becomes specified on command line, here root_name !=\n\t\t * NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\tsdirectory_bytes = last_directory_block;\n\t\t\tsdirectory_compressed_bytes = 0;\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache +\n\t\t\t\tcompressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode,\n\t\t\t\tinode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\tsdirectory_compressed_bytes = last_directory_block -\n\t\t\t\tinode_dir_start_block;\n\t\t\tsdirectory_compressed =\n\t\t\t\tmalloc(sdirectory_compressed_bytes);\n\t\t\tmemcpy(sdirectory_compressed, directory_table +\n\t\t\t\tinode_dir_start_block,\n\t\t\t\tsdirectory_compressed_bytes); \n\t\t\tsdirectory_bytes = inode_dir_start_block;\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count +\n\t\t\tfifo_count + sock_count;\n\t}\n\n\tif(path || stickypath) {\n\t\tpaths = init_subdir();\n\t\tif(path)\n\t\t\tpaths = add_subdir(paths, path);\n\t\tif(stickypath)\n\t\t\tpaths = add_subdir(paths, stickypath);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = s_minor;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, no_fragments,\n\t\talways_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\tif(progress && estimated_uncompressed) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tunlock_fragments();\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\twhile(fragments_outstanding) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tsched_yield();\n\t\t\tpthread_mutex_lock(&fragment_mutex);\n\t\t}\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() :\n\t\tSQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\",\n\t\tsBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\",\n\t\t\tsBlk.lookup_table_start);\n\n\tsBlk.no_ids = id_count;\n\tsBlk.id_table_start = write_id_table();\n\n\tsBlk.bytes_used = bytes;\n\n\t/* Only compression supported */\n\tsBlk.compression = compression;\n\n\t/* Xattrs are not currently supported */\n\tsBlk.xattr_table_start = SQUASHFS_INVALID_BLK;\n\n\tSQUASHFS_INSWAP_SUPER_BLOCK(&sBlk); \n\twrite_destination(fd, SQUASHFS_START, sizeof(squashfs_super_block),\n\t\t(char *) &sBlk);\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_destination(fd, bytes, 4096 - i, temp);\n\t}\n\n\tclose(fd);\n\n\tif(recovery_file[0] != '\\0')\n\t\tunlink(recovery_file);\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%sSquashfs %d.%d filesystem, data block size %d\\n\",\n\t\texportable ? \"Exportable \" : \"\", SQUASHFS_MAJOR, SQUASHFS_MINOR,\n\t\tblock_size);\n\tprintf(\"\\t%s data, %s metadata, %s fragments\\n\",\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" :\n\t\t\"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" :\n\t\t\"compressed\");\n\tprintf(\"\\tduplicates are %sremoved\\n\", duplicate_checking ? \"\" :\n\t\t\"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0,\n\t\tbytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0,\n\t\ttotal_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0,\n\t\ttotal_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count -\n\t\t\tdup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of ids (unique uids + gids) %d\\n\", id_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_UID) {\n\t\t\tstruct passwd *user = getpwuid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" :\n\t\t\t\tuser->pw_name, id_table[i]->id);\n\t\t}\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_GID) {\n\t\t\tstruct group *group = getgrgid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" :\n\t\t\t\tgroup->gr_name, id_table[i]->id);\n\t\t}\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/mksquashfs.c.orig",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/time.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n#include <regex.h>\n#include <fnmatch.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"pseudo.h\"\n#include \"uncompress.h\"\n\n#ifdef USE_LZMA\n#include <LzmaEnc.h>\n#include <LzmaDec.h>\n#define LZMA_DEFAULT_LEVEL\t5\n#define LZMA_DEFAULT_DICT\t0\n#define LZMA_DEFAULT_LC\t1\n#define LZMA_DEFAULT_LP\t2\n#define LZMA_DEFAULT_PB 2\n#define LZMA_DEFAULT_FB 32\n#endif\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tprintf(\"\\n\"); \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\n/* offset of data in compressed metadata blocks (allowing room for\n * compressed size */\n#define BLOCK_OFFSET 2\nint delete = FALSE;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0;\nint silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\nint progress_enabled = FALSE;\nint sparse_files = TRUE;\nint old_exclude = TRUE;\nint use_regex = FALSE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned int id_count = 0;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0,\n\tsock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* exclude file handling */\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint old_excluded(char *filename, struct stat *buf);\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nstruct pathnames *paths = NULL;\nstruct pathname *path = NULL;\nstruct pathname *stickypath = NULL;\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\n\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n\n#define FRAG_SIZE 32768\n#define FRAG_INDEX (1LL << 32)\n\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is\n * cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache, *sdirectory_compressed;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, sdirectory_compressed_bytes,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* recovery file for abnormal exit on appending */\nchar recovery_file[1024] = \"\";\nint recover = TRUE;\n\n/* struct describing a cache entry passed between threads */\nstruct file_buffer {\n\tstruct cache *cache;\n\tint keep;\n\tlong long file_size;\n\tlong long index;\n\tlong long block;\n\tlong long sequence;\n\tint size;\n\tint c_byte;\n\tint used;\n\tint\tfragment;\n\tint error;\n\tstruct file_buffer *hash_next;\n\tstruct file_buffer *hash_prev;\n\tstruct file_buffer *free_next;\n\tstruct file_buffer *free_prev;\n\tstruct file_buffer *next;\n\tchar data[0];\n};\n\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n\n/* in memory uid tables */\n#define ID_ENTRIES 256\n#define ID_HASH(id) (id & (ID_ENTRIES - 1))\n#define ISA_UID 1\n#define ISA_GID 2\nstruct id {\n\tunsigned int id;\n\tint\tindex;\n\tchar\tflags;\n\tstruct id *next;\n};\nstruct id *id_hash_table[ID_ENTRIES];\nstruct id *id_table[SQUASHFS_IDS], *sid_table[SQUASHFS_IDS];\nunsigned int uid_count = 0, guid_count = 0;\nunsigned int sid_count = 0, suid_count = 0, sguid_count = 0;\n\nstruct cache *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate,\n\t*to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread, progress_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\npthread_mutex_t progress_mutex;\npthread_cond_t progress_wait;\nint rotate = 0;\nstruct pseudo *pseudo = NULL;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\nint fragment_buffer_size;\n\nchar *read_from_disk(long long start, unsigned int avail_bytes);\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type);\nextern int read_super(int fd, squashfs_super_block *sBlk, char *source);\nextern long long read_filesystem(char *root_name, int fd,\n\tsquashfs_super_block *sBlk, char **cinode_table, char **data_cache,\n\tchar **cdirectory_table, char **directory_data_cache,\n\tunsigned int *last_directory_block, unsigned int *inode_dir_offset,\n\tunsigned int *inode_dir_file_size, unsigned int *root_inode_size,\n\tunsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\tlong long *uncompressed_file, unsigned int *uncompressed_inode,\n\tunsigned int *uncompressed_directory,\n\tunsigned int *inode_dir_inode_number,\n\tunsigned int *inode_dir_parent_inode,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\tsquashfs_fragment_entry **fragment_table,\n\tsquashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *,\n\tchar *, struct dir_info *));\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo);\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info);\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority,\n\tstruct stat *buf);\nextern struct priority_entry *priority_list[65536];\nvoid progress_bar(long long current, long long max, int columns);\nlong long generic_write_table(int length, char *buffer, int uncompressed);\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tstruct file_buffer *free_list;\n\tstruct file_buffer *hash_table[65536];\n};\n\n\n#define INSERT_LIST(NAME, TYPE) \\\nvoid insert_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(*list) { \\\n\t\tentry->NAME##_next = *list; \\\n\t\tentry->NAME##_prev = (*list)->NAME##_prev; \\\n\t\t(*list)->NAME##_prev->NAME##_next = entry; \\\n\t\t(*list)->NAME##_prev = entry; \\\n\t} else { \\\n\t\t*list = entry; \\\n\t\tentry->NAME##_prev = entry->NAME##_next = entry; \\\n\t} \\\n}\n\n\n#define REMOVE_LIST(NAME, TYPE) \\\nvoid remove_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(entry->NAME##_prev == entry && entry->NAME##_next == entry) { \\\n\t\t/* only this entry in the list */ \\\n\t\t*list = NULL; \\\n\t} else if(entry->NAME##_prev != NULL && entry->NAME##_next != NULL) { \\\n\t\t/* more than one entry in the list */ \\\n\t\tentry->NAME##_next->NAME##_prev = entry->NAME##_prev; \\\n\t\tentry->NAME##_prev->NAME##_next = entry->NAME##_next; \\\n\t\tif(*list == entry) \\\n\t\t\t*list = entry->NAME##_next; \\\n\t} \\\n\tentry->NAME##_prev = entry->NAME##_next = NULL; \\\n}\n\n\n#define CALCULATE_HASH(start)\t(start & 0xffff) \\\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tint hash = CALCULATE_HASH(entry->index);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->index)] =\n\t\t\tentry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nINSERT_LIST(free, struct file_buffer)\n\n/* Called with the cache mutex held */\nREMOVE_LIST(free, struct file_buffer)\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\treturn NULL;\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct file_buffer *) * 65536);\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\n\treturn cache;\n}\n\n\nstruct file_buffer *cache_lookup(struct cache *cache, long long index)\n{\n\t/* Lookup block in the cache, if found return with usage count\n \t * incremented, if not found return NULL */\n\tint hash = CALCULATE_HASH(index);\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->index == index)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/* found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(&cache->free_list, entry);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n}\n\n\n#define GET_FREELIST 1\n\nstruct file_buffer *cache_get(struct cache *cache, long long index, int keep)\n{\n\t/* Get a free block out of the cache indexed on index. */\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\twhile(1) {\n\t\t/* first try to get a block from the free list */\n#ifdef GET_FREELIST\n\t\tif(cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t} else\n#endif\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\t/* next try to allocate new block */\n\t\t\tentry = malloc(sizeof(struct file_buffer) +\n\t\t\t\tcache->buffer_size);\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t\tbreak;\n\t\t} else\n#ifndef GET_FREELIST\n\t\tif(cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t}\n#endif\n\t\t\t/* wait for a block */\n\t\t\tpthread_cond_wait(&cache->wait_for_free, &cache->mutex);\n\t}\n\n\t/* initialise block and if a keep block insert into the hash table */\n\tentry->used = 1;\n\tentry->error = FALSE;\n\tentry->keep = keep;\n\tif(keep) {\n\t\tentry->index = index;\n\t\tinsert_hash_table(cache, entry);\n\t}\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\treturn NULL;\n}\n\n\nvoid cache_rehash(struct file_buffer *entry, long long index)\n{\n\tstruct cache *cache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\tif(entry->keep)\n\t\tremove_hash_table(cache, entry);\n\tentry->keep = TRUE;\n\tentry->index = index;\n\tinsert_hash_table(cache, entry);\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\nvoid cache_block_put(struct file_buffer *entry)\n{\n\tstruct cache *cache;\n\n\t/* finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and if a keep block put onto the free list.  As keep\n \t * blocks remain accessible via the hash table they can be found\n \t * getting a new lease of life before they are reused. */\n\n\tif(entry == NULL)\n\t\treturn;\n\n\tcache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tif(entry->keep)\n\t\t\tinsert_free_list(&cache->free_list, entry);\n\t\telse {\n\t\t\tfree(entry);\n\t\t\tcache->count --;\n\t\t}\n\n\t\t/* One or more threads may be waiting on this block */\n\t\tpthread_cond_signal(&cache->wait_for_free);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) \\\n\t\t\t+ (((char *)A) - data_cache)))\n\n\ninline void inc_progress_bar()\n{\n\tcur_uncompressed ++;\n}\n\n\ninline void update_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tif(thread[i])\n\t\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache,\n\t\tsdirectory_cache_bytes);\n\tdirectory_cache_bytes = sdirectory_cache_bytes;\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n \tmemcpy(directory_table + directory_bytes, sdirectory_compressed,\n\t\tsdirectory_compressed_bytes);\n \tdirectory_bytes += sdirectory_compressed_bytes;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tid_count = sid_count;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, &thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n#ifdef USE_LZMA\nstatic void *lzma_malloc(void *p, size_t size)\n{\n\t(void)p;\n\treturn malloc(size);\n}\nstatic void lzma_free(void *p, void *addr)\n{\n\t(void)p;\n\tfree(addr);\n}\nstatic ISzAlloc lzma_alloc = { lzma_malloc, lzma_free };\n#endif\n\nunsigned int mangle2(z_stream **strm, char *d, char *s, int size,\n\tint block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte;\n\tunsigned int res;\n\tz_stream *stream = *strm;\n\n\tif(uncompressed)\n\t\tgoto notcompressed;\n\n#ifdef USE_LZMA\n\tif (compression == LZMA_COMPRESSION) {\n\t\tsize_t outsize = block_size - LZMA_PROPS_SIZE;\n\t\tsize_t propsize = LZMA_PROPS_SIZE;\n\t\tCLzmaEncProps props;\n\n\t\tLzmaEncProps_Init(&props);\n\t\tprops.level = LZMA_DEFAULT_LEVEL;\n\t\tprops.dictSize = LZMA_DEFAULT_DICT;\n\t\tprops.lc = LZMA_DEFAULT_LC;\n\t\tprops.lp = LZMA_DEFAULT_LP;\n\t\tprops.pb = LZMA_DEFAULT_PB;\n\t\tprops.fb = LZMA_DEFAULT_FB;\n\t\tprops.numThreads = 1;\n\n\t\tres = LzmaEncode((unsigned char *) d + LZMA_PROPS_SIZE, &outsize,\n\t\t\t(unsigned char *) s, size,\n\t\t\t&props, (unsigned char *) d, &propsize,\n\t\t\t1, NULL, &lzma_alloc, &lzma_alloc);\n\t\tswitch(res) {\n\t\tcase SZ_OK:\n\t\t\toutsize += LZMA_PROPS_SIZE;\n\t\t\tbreak;\n\t\tcase SZ_ERROR_DATA:\n\t\t\tBAD_ERROR(\"lzma::compress failed, data error\\n\");\n\t\t\tbreak;\n\t\tcase SZ_ERROR_MEM:\n\t\t\tBAD_ERROR(\"lzma::compress failed, memory allocation error\\n\");\n\t\t\tbreak;\n\t\tcase SZ_ERROR_PARAM:\n\t\t\tBAD_ERROR(\"lzma::compress failed, invalid parameters\\n\");\n\t\t\tbreak;\n        case SZ_ERROR_OUTPUT_EOF:\n            memcpy(d, s, size);\n            return size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK :\n                    SQUASHFS_COMPRESSED_BIT);\n        case SZ_ERROR_THREAD:\n\t\t\tBAD_ERROR(\"lzma::compress failed, errors in multithreading functions\\n\");\n\t\t\tbreak;\n\t\t/* should not happen */\n\t\tdefault:\n\t\t\tBAD_ERROR(\"lzma::compress failed, unknown error\\n\");\n\t\t\tbreak;\n\t\t}\n\n\t\treturn outsize;\n\t}\n#endif\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tBAD_ERROR(\"mangle::compress failed, not enough \"\n\t\t\t\t\"memory\\n\");\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not enough \"\n\t\t\t\t\t\"memory\\n\");\n\t\t\telse if(res == Z_STREAM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, not a valid \"\n\t\t\t\t\t\"compression level\\n\");\n\t\t\telse if(res == Z_VERSION_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, incorrect \"\n\t\t\t\t\t\"zlib version\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::compress failed, unknown \"\n\t\t\t\t\t\"error %d\\n\", res);\n\t\t}\n\t} else if((res = deflateReset(stream)) != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state \"\n\t\t\t\t\"inconsistent\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\",\n\t\t\t\tres);\n\t}\n\n\tstream->next_in = (unsigned char *) s;\n\tstream->avail_in = size;\n\tstream->next_out = (unsigned char *) d;\n\tstream->avail_out = block_size;\n\n\tres = deflate(stream, Z_FINISH);\n\tif(res != Z_STREAM_END && res != Z_OK) {\n\t\tif(res == Z_STREAM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, stream state \"\n\t\t\t\t\"inconsistent\\n\");\n\t\telse if(res == Z_BUF_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, no progress possible\"\n\t\t\t\t\"\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\",\n\t\t\t\tres);\n\t}\n\n\tc_byte = stream->total_out;\n\n\tif(res != Z_STREAM_END || c_byte >= size) {\nnotcompressed:\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK :\n\t\t\tSQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size,\n\tint uncompressed, int data_block)\n{\n\tstatic z_stream *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed,\n\t\tdata_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tinode_table = realloc(inode_table, inode_size +\n\t\t\t\t(SQUASHFS_METADATA_SIZE << 1) + 2);\n\t\t\tif(inode_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET,\n\t\t\tdata_cache, SQUASHFS_METADATA_SIZE,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\t(unsigned short *) (inode_table + inode_bytes), 1);\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE,\n\t\t\tcache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ?\n\t\t\t\t((req_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : req_size -\n\t\t\t\tdata_space;\n\n\t\t\tdata_cache = realloc(data_cache, cache_size +\n\t\t\t\trealloc_size);\n\t\t\tif(data_cache == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)\n\t\t(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nint read_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = read(fd, buff + count, bytes - count);\n\t\tif(res < 1) {\n\t\t\tif(res == 0)\n\t\t\t\tgoto bytes_read;\n\t\t\telse if(errno != EINTR) {\n\t\t\t\tERROR(\"Read failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t} else\n\t\t\t\tres = 0;\n\t\t}\n\t}\n\nbytes_read:\n\treturn count;\n}\n\n\nvoid read_destination(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_destination: reading from position 0x%llx, bytes %d\\n\",\n\t\tbyte, bytes);\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(read_bytes(fd, buff, bytes) < bytes)\n\t\tBAD_ERROR(\"Read on destination failed\\n\");\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nint write_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = write(fd, buff + count, bytes - count);\n\t\tif(res == -1) {\n\t\t\tif(errno != EINTR) {\n\t\t\t\tERROR(\"Write failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nvoid write_destination(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(fd, buff, bytes) == -1)\n\t\tBAD_ERROR(\"Write on destination failed\\n\");\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tinode_table = realloc(inode_table, inode_size +\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2));\n\t\t\tif(inode_table == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET, datap,\n\t\t\tavail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\t(unsigned short *) (inode_table + inode_bytes), 1); \n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_destination(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tdirectory_table = realloc(directory_table,\n\t\t\t\tdirectory_size + ((SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2));\n\t\t\tif(directory_table == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\tBLOCK_OFFSET, directoryp, avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, (unsigned short *)\n\t\t\t(directory_table + directory_bytes), 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_destination(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_id_table()\n{\n\tunsigned int id_bytes = SQUASHFS_ID_BYTES(id_count);\n\tchar buffer[id_bytes];\n\tunsigned int *p = (unsigned int *) buffer;\n\tint i;\n\n\tTRACE(\"write_id_table: ids %d, id_bytes %d\\n\", id_count, id_bytes);\n\tfor(i = 0; i < id_count; i++, p++) {\n\t\tTRACE(\"write_id_table: id index %d, id %d\", i, id_table[i]->id);\n\t\tSQUASHFS_SWAP_INTS(&id_table[i]->id, p, 1);\n\t}\n\n\treturn generic_write_table(id_bytes, buffer, 1);\n}\n\n\nstruct id *get_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = id_hash_table[hash];\n\n\tfor(; entry; entry = entry->next)\n\t\tif(entry->id == id)\n\t\t\tbreak;\n\n\treturn entry;\n}\n\n\nstruct id *create_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = malloc(sizeof(struct id));\n\tif(entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in create_id\\n\");\n\tentry->id = id;\n\tentry->index = id_count ++;\n\tentry->flags = 0;\n\tentry->next = id_hash_table[hash];\n\tid_hash_table[hash] = entry;\n\tid_table[entry->index] = entry;\n\treturn entry;\n}\n\n\nunsigned int get_uid(unsigned int uid)\n{\n\tstruct id *entry = get_id(uid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of uids!\\n\");\n\t\tentry = create_id(uid);\n\t}\n\n\tif((entry->flags & ISA_UID) == 0) {\n\t\tentry->flags |= ISA_UID;\n\t\tuid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nunsigned int get_guid(unsigned int guid)\n{\n\tstruct id *entry = get_id(guid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of gids!\\n\");\n\t\tentry = create_id(guid);\n\t}\n\n\tif((entry->flags & ISA_GID) == 0) {\n\t\tentry->flags |= ISA_GID;\n\t\tguid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type,\n\tlong long byte_size, long long start_block, unsigned int offset,\n\tunsigned int *block_list, struct fragment *fragment,\n\tstruct directory *dir_in, unsigned int sparse)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE ||\n\t\ttype == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number :\n\t\tdir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((unsigned int) global_uid == -1 ?\n\t\tbuf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((unsigned int) global_gid == -1 ?\n\t\tbuf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\tTRACE(\"File inode, file_size %lld, start_block 0x%llx, blocks \"\n\t\t\t\"%d, fragment %d, offset %d, size %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset,\n\t\t\tfragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(sparse && sparse >= byte_size)\n\t\t\tsparse = byte_size - 1;\n\t\treg->sparse = sparse;\n\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\tTRACE(\"Long file inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"blocks %d, fragment %d, offset %d, size %d, nlink %d\"\n\t\t\t\"\\n\", byte_size, start_block, offset, fragment->index,\n\t\t\tfragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\n\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inodep);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index,\n\t\t\t\t(squashfs_dir_index *) p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name,\n\t\t\t\tindex[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size\n\t\t\t\t+ 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %lld, start_block \"\n\t\t\t\"0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir,\n\t\t\t(squashfs_dir_inode_header *) inode);\n\t\tTRACE(\"Directory inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"offset 0x%x, nlink %d\\n\", byte_size, start_block,\n\t\t\toffset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\t\tunsigned int major = major(buf->st_rdev);\n\t\tunsigned int minor = minor(buf->st_rdev);\n\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", major, filename,\n\t\t\t\tmajor & 0xfff);\n\t\t\tmajor &= 0xfff;\n\t\t}\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", minor, filename,\n\t\t\t\tminor & 0xfffff);\n\t\t\tminor &= 0xfffff;\n\t\t}\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (major << 8) | (minor & 0xff) |\n\t\t\t\t((minor & ~0xff) << 12);\n\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev,\n\t\t\t(squashfs_dev_inode_header *) inode);\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink,\n\t\t\t*inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty \"\n\t\t\t\t\"symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! \"\n\t\t\t\t\"Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inodep);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte,\n\t\t\tnlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc,\n\t\t\t(squashfs_ipc_inode_header *) inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type ==\n\t\t\tSQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type,\n\t\tbase->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan3_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name,\n\tint type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\"\n\t\t\t\"\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size +\n\t\t\tsizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tbuff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE);\n\t\tif(buff == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\"\n\t\t\t\t\"\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff +\n\t\t\tbuff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block ||\n\t\t\t((dir->entry_count_p != NULL) &&\n\t\t\t((dir->p + sizeof(squashfs_dir_entry) + size -\n\t\t\tdir->index_count_p) > SQUASHFS_METADATA_SIZE)) ||\n\t\t\t((long long) inode_number - dir->inode_number) > 32767\n\t\t\t|| ((long long) inode_number - dir->inode_number)\n\t\t\t< -32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size -\n\t\t\t\t\tdir->index_count_p) >\n\t\t\t\t\tSQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0) {\n\t\t\t\t\tdir->index = realloc(dir->index,\n\t\t\t\t\t\t(dir->i_count + I_COUNT_SIZE) *\n\t\t\t\t\t\tsizeof(struct cached_dir_index));\n\t\t\t\t\tif(dir->index == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in \"\n\t\t\t\t\t\t\t\"directory index table \"\n\t\t\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t\t}\n\t\t\t\tdir->index[dir->i_count].index.index =\n\t\t\t\t\tdir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) +\n\t\t\t\t\tsize;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header,\n\t\t\t\t(squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tSQUASHFS_SWAP_DIR_ENTRY(&idir, idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info,\n\tstruct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ?\n\t\t\t((dir_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tdirectory_data_cache = realloc(directory_data_cache,\n\t\t\tdirectory_cache_size + realloc_size);\n\t\tif(directory_data_cache == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header,\n\t\t\t(squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff,\n\t\t\tdir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count &&\n\t\t\t\tdir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block =\n\t\t\t\tdirectory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) <\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tdirectory_table = realloc(directory_table,\n\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2);\n\t\t\tif(directory_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\t\tBLOCK_OFFSET, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE,\n\t\t\t\tnoI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, (unsigned short *)\n\t\t\t(directory_table + directory_bytes), 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemcpy(directory_data_cache, directory_data_cache +\n\t\t\tSQUASHFS_METADATA_SIZE, directory_cache_bytes -\n\t\t\tSQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir)\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE,\n\t\t\tdir_size + 3, directory_block, directory_offset, NULL,\n\t\t\tNULL, dir, 0);\n\telse\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE,\n\t\t\tdir_size + 3, directory_block, directory_offset, NULL,\n\t\t\tNULL, NULL, 0);\n\n#ifdef SQUASHFS_TRACE\n\t{\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header dirh;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((squashfs_dir_header *) dirp,\n\t\t\t\t&dirh);\n\t\t\tcount = dirh.count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\",\n\t\t\t\tdirh.start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(idirp, &idir);\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type \"\n\t\t\t\t\t\"%d\\n\", buffer, idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size +\t\t\t\t\t 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nstruct file_buffer *get_fragment(struct fragment *fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\tlong long start_block;\n\tstruct file_buffer *buffer, *compressed_buffer;\n\n\tif(fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn NULL;\n\n\tbuffer = cache_lookup(fragment_buffer, fragment->index);\n\tif(buffer)\n\t\treturn buffer;\n\n\tcompressed_buffer = cache_lookup(writer_buffer, fragment->index +\n\t\tFRAG_INDEX);\n\n\tbuffer = cache_get(fragment_buffer, fragment->index, 1);\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\tstart_block = disk_fragment->start_block;\n\tpthread_mutex_unlock(&fragment_mutex);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar *data;\n\n\t\tif(compressed_buffer)\n\t\t\tdata = compressed_buffer->data;\n\t\telse\n\t\t\tdata = read_from_disk(start_block, size);\n\n\t\tres = uncompress_wrapper((unsigned char *) buffer->data, &bytes,\n\t\t\t(const unsigned char *) data, size);\n\t\tif(res != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"uncompress failed,\"\n\t\t\t\t\t\"  unknown error %d\\n\", res);\n\t\t}\n\t} else if(compressed_buffer)\n\t\tmemcpy(buffer->data, compressed_buffer->data, size);\n\telse\n\t\tread_destination(fd, start_block, size, buffer->data);\n\n\tcache_block_put(compressed_buffer);\n\n\treturn buffer;\n}\n\n\nstruct frag_locked {\n\tstruct file_buffer *buffer;\n\tint c_byte;\n\tint fragment;\n\tstruct frag_locked *fragment_prev;\n\tstruct frag_locked *fragment_next;\n};\n\nint fragments_locked = FALSE;\nstruct frag_locked *frag_locked_list = NULL;\n\nINSERT_LIST(fragment, struct frag_locked)\nREMOVE_LIST(fragment, struct frag_locked)\n\nint lock_fragments()\n{\n\tint count;\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragments_locked = TRUE;\n\tcount = fragments_outstanding;\n\tpthread_mutex_unlock(&fragment_mutex);\n\treturn count;\n}\n\n\nvoid unlock_fragments()\n{\n\tstruct frag_locked *entry;\n\tint compressed_size;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(frag_locked_list) {\n\t\tentry = frag_locked_list;\n\t\tremove_fragment_list(&frag_locked_list, entry);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->c_byte);\n\t\tfragment_table[entry->fragment].size = entry->c_byte;\n\t\tfragment_table[entry->fragment].start_block = bytes;\n\t\tentry->buffer->block = bytes;\n\t\tbytes += compressed_size;\n\t\tfragments_outstanding --;\n\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\tqueue_put(to_writer, entry->buffer);\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tTRACE(\"fragment_locked writing fragment %d, compressed size %d\"\n\t\t\t\"\\n\", entry->fragment, compressed_size);\n\t\tfree(entry);\n\t}\n\tfragments_locked = FALSE;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nint add_pending_fragment(struct file_buffer *write_buffer, int c_byte,\n\tint fragment)\n{\n\tstruct frag_locked *entry = malloc(sizeof(struct frag_locked));\n\tif(entry == NULL)\n\t\treturn FALSE;\n\tentry->buffer = write_buffer;\n\tentry->c_byte = c_byte;\n\tentry->fragment = fragment;\n\tentry->fragment_prev = entry->fragment_next = NULL;\n\tpthread_mutex_lock(&fragment_mutex);\n\tinsert_fragment_list(&frag_locked_list, entry);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tfragment_table = realloc(fragment_table, (fragments +\n\t\t\tFRAG_SIZE) * sizeof(squashfs_fragment_entry));\n\t\tif(fragment_table == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].unused = 0;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = cache_get(fragment_buffer, fragments, 1);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data,\n\t\tfile_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) /\n\t\tSQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n\tlong long obytes = bytes;\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + BLOCK_OFFSET, buffer + i *\n\t\t\tSQUASHFS_METADATA_SIZE , avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, (unsigned short *) cbuffer, 1);\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes,\n\t\t\tcompressed_size);\n\t\twrite_destination(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tSQUASHFS_INSWAP_LONG_LONGS(list, meta_blocks);\n\twrite_destination(fd, bytes, sizeof(list), (char *) list);\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count *\n\t\tsizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments,\n\t\tfrag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block 0x%llx, \"\n\t\t\t\"size %d\\n\", i, fragment_table[i].start_block,\n\t\t\tfragment_table[i].size);\n\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_destination(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\nchar read_from_file_buffer2[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk2(long long start, unsigned int avail_bytes)\n{\n\tread_destination(fd, start, avail_bytes, read_from_file_buffer2);\n\treturn read_from_file_buffer2;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l,\n\tunsigned int *blocks)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\tstruct file_buffer *write_buffer;\n\tint i;\n\n\tfor(i = 0; l; i++)  {\n\t\tbytes = SQUASHFS_COMPRESSED_SIZE_BLOCK(blocks[i]);\n\t\tif(bytes == 0) /* sparse block */\n\t\t\tcontinue;\n\t\twrite_buffer = cache_lookup(writer_buffer, start);\n\t\tif(write_buffer) {\n\t\t\tchksum = get_checksum(write_buffer->data, bytes,\n\t\t\t\tchksum);\n\t\t\tcache_block_put(write_buffer);\n\t\t} else\n\t\t\tchksum = get_checksum(read_from_disk(start, bytes),\n\t\t\t\tbytes, chksum);\n\t\tl -= bytes;\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes,\n\tunsigned int *block_listp, int blocks, unsigned int fragment,\n\tint offset, int bytes)\n{\n\tstruct fragment *frg;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset !=\n\t\t\t\tdupl_ptr->fragment->offset || bytes !=\n\t\t\t\tdupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && file_size ==\n\t\t\t\tdupl_ptr->fragment->size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, file_size);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes &&\n\t\t\t\t frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tlong long target_start, dup_start = dupl_ptr->start;\n\t\t\tint block;\n\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks *\n\t\t\t\t\tsizeof(unsigned int)) != 0)\n\t\t\t\tcontinue;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_disk(*start, bytes,\n\t\t\t\t\t*block_list);\n\t\t\t\tfragment_checksum =\n\t\t\t\t\tget_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, frag_bytes);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum ||\n\t\t\t\t\tfragment_checksum !=\n\t\t\t\t\tdupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\ttarget_start = *start;\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t((*block_list)[block]);\n\t\t\t\tstruct file_buffer *target_buffer = NULL;\n\t\t\t\tstruct file_buffer *dup_buffer = NULL;\n\t\t\t\tchar *target_data, *dup_data;\n\t\t\t\tint res;\n\n\t\t\t\tif(size == 0)\n\t\t\t\t\tcontinue;\n\t\t\t\ttarget_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\ttarget_start);\n\t\t\t\tif(target_buffer)\n\t\t\t\t\ttarget_data = target_buffer->data;\n\t\t\t\telse\n\t\t\t\t\ttarget_data =\n\t\t\t\t\t\tread_from_disk(target_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tdup_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\tdup_start);\n\t\t\t\tif(dup_buffer)\n\t\t\t\t\tdup_data = dup_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tdup_data = read_from_disk2(dup_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tres = memcmp(target_data, dup_data, size);\n\t\t\t\tcache_block_put(target_buffer);\n\t\t\t\tcache_block_put(dup_buffer);\n\t\t\t\tif(res != 0)\n\t\t\t\t\tbreak;\n\t\t\t\ttarget_start += size;\n\t\t\t\tdup_start += size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\n\t\t\t\tif(frag_bytes == 0 ||\n\t\t\t\t\t\tmemcmp(file_buffer->data,\n\t\t\t\t\t\tfrag_buffer->data +\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfrag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start \"\n\t\t\t\t\t\t\"0x%llx, size %lld, checksum \"\n\t\t\t\t\t\t\"0x%x, fragment %d, size %d, \"\n\t\t\t\t\t\t\"offset %d, checksum 0x%x\\n\",\n\t\t\t\t\t\tdupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes,\n\t\t\t\t\t\tdupl_ptr->checksum,\n\t\t\t\t\t\tdupl_ptr->fragment->index,\n\t\t\t\t\t\tfrag_bytes,\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment,\n\t\tchecksum, fragment_checksum, checksum_flag);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\n\tstruct file_buffer *file_buffer;\n\tstatic int index = 0;\n\tint blocks, byte, count, expected, file, frag_block;\n\tlong long bytes, read_size;\n\n\tif(dir_ent->inode->read)\n\t\treturn;\n\n\tdir_ent->inode->read = TRUE;\nagain:\n\tbytes = 0;\n\tcount = 0;\n\tfile_buffer = NULL;\n\tread_size = buf->st_size;\n\tblocks = (read_size + block_size - 1) >> block_log;\n\tfrag_block = !no_fragments && (always_use_fragments ||\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\texpected = read_size - ((long long) count * block_size) >\n\t\t\tblock_size ? block_size :\n\t\t\tread_size - ((long long) count * block_size);\n\n\t\tif(file_buffer)\n\t\t\tqueue_put(from_reader, file_buffer);\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = index ++;\n\n\t\tbyte = file_buffer->size = read_bytes(file, file_buffer->data,\n\t\t\tblock_size);\n\n\t\tfile_buffer->file_size = read_size;\n\n\t\tif(byte != expected)\n\t\t\tgoto restat;\n\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->error = FALSE;\n\t\tfile_buffer->fragment = (file_buffer->block == frag_block);\n\n\t\tbytes += byte;\n\t\tcount ++;\n\t} while(count < blocks);\n\n\tif(read_size != bytes)\n\t\tgoto restat;\n\n\tif(expected == block_size) {\n\t\tchar buffer;\n\n\t\tif(read_bytes(file, &buffer, 1) == 1)\n\t\t\tgoto restat;\n\t}\n\n\tqueue_put(from_reader, file_buffer);\n\n\tclose(file);\n\n\treturn;\n\nread_err:\n\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\tfile_buffer->sequence = index ++;\nread_err2:\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n\treturn;\nrestat:\n\tfstat(file, &buf2);\n\tclose(file);\n\tif(read_size != buf2.st_size) {\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\n\t\tfile_buffer->error = 2;\n\t\tqueue_put(from_deflate, file_buffer);\n\t\tgoto again;\n\t}\n\tgoto read_err2;\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\n\tthread[0] = 0;\n\n\tpthread_exit(NULL);\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer,\n\t\t\t\twrite_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write_bytes(fd, file_buffer->data,\n\t\t\t\tfile_buffer->size) == -1) {\n\t\t\tERROR(\"Write on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\nint all_zero(struct file_buffer *file_buffer)\n{\n\tint i;\n\tlong entries = file_buffer->size / sizeof(long);\n\tlong *p = (long *) file_buffer->data;\n\n\tfor(i = 0; i < entries && p[i] == 0; i++);\n\n\tif(i == entries) {\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1);\n\t\t\ti < file_buffer->size && file_buffer->data[i] == 0;\n\t\t\ti++);\n\n\t\treturn i == file_buffer->size;\n\t}\n\n\treturn 0;\n}\n\n\nvoid *deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer;\n\n\t\tif(sparse_files && all_zero(file_buffer)) { \n\t\t\tfile_buffer->c_byte = 0;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else if(file_buffer->fragment) {\n\t\t\tfile_buffer->c_byte = file_buffer->size;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else {\n\t\t\twrite_buffer = cache_get(writer_buffer, 0, 0);\n\t\t\twrite_buffer->c_byte = mangle2(&stream,\n\t\t\t\twrite_buffer->data, file_buffer->data,\n\t\t\t\tfile_buffer->size, block_size, noD, 1);\n\t\t\twrite_buffer->sequence = file_buffer->sequence;\n\t\t\twrite_buffer->file_size = file_buffer->file_size;\n\t\t\twrite_buffer->block = file_buffer->block;\n\t\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t(write_buffer->c_byte);\n\t\t\twrite_buffer->fragment = FALSE;\n\t\t\twrite_buffer->error = FALSE;\n\t\t\tcache_block_put(file_buffer);\n\t\t\tqueue_put(from_deflate, write_buffer);\n\t\t}\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tz_stream *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer =\n\t\t\tcache_get(writer_buffer, file_buffer->block +\n\t\t\tFRAG_INDEX, 1);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data,\n\t\t\tfile_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\twrite_buffer->size = compressed_size;\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tif(fragments_locked == FALSE) {\n\t\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\t\twrite_buffer->block = bytes;\n\t\t\tbytes += compressed_size;\n\t\t\tfragments_outstanding --;\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tqueue_put(to_writer, write_buffer);\n\t\t\tTRACE(\"Writing fragment %lld, uncompressed size %d, \"\n\t\t\t\t\"compressed size %d\\n\", file_buffer->block,\n\t\t\t\tfile_buffer->size, compressed_size);\n\t\t} else {\n\t\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\t\tadd_pending_fragment(write_buffer, c_byte,\n\t\t\t\t\tfile_buffer->block);\n\t\t}\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->sequence);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int sequence = 0;\n\tint hash = BLOCK_HASH(sequence);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->sequence == sequence)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->sequence == sequence)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tsequence ++;\n\n\treturn file_buffer;\n}\n\n\nvoid *progress_thrd(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&progress_mutex);\n\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) *\n\t\t\t1000;\n\t\tpthread_cond_timedwait(&progress_wait, &progress_mutex,\n\t\t\t&timespec);\n\t\tif(progress_enabled && estimated_uncompressed)\n\t\t\tprogress_bar(cur_uncompressed, estimated_uncompressed,\n\t\t\t\tcolumns);\n\t}\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits = floor(log10(max)) + 1;\n\tint used = max_digits * 2 + 11;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\tstatic int tty = -1;\n\n\tif((current > max) || (columns - used < 0))\n\t\treturn;\n\n\tif(tty == -1)\n\t\ttty = isatty(STDOUT_FILENO);\n\tif(!tty) {\n\t\tstatic long long previous = -1;\n\n\t\t/* Updating much more frequently than this results in huge\n\t\t * log files. */\n\t\tif((current % 100) != 0 && current != max)\n\t\t\treturn;\n\t\t/* Don't update just to rotate the spinner. */\n\t\tif(current == previous)\n\t\t\treturn;\n\t\tprevious = current;\n\t}\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL,\n\t\t\t&empty_fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL,\n\t\t\t&empty_fragment, NULL, 0);\n}\n\n\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint size, int *duplicate_file, struct file_buffer *file_buffer,\n\tunsigned short checksum)\n{\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment,\n\t\tfile_buffer, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\tcache_block_put(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tinc_progress_bar();\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n}\n\n\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size,\n\tstruct file_buffer *file_buffer, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum)) {\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file,\n\t\t\tfile_buffer, checksum);\n\t\treturn;\n\t}\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\tcache_block_put(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tinc_progress_bar();\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n\n\treturn;\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tlong long file_bytes, start;\n\tstruct fragment *fragment;\n\tunsigned int *block_list;\n\tint block, status;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\t*duplicate_file = FALSE;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tlock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else {\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tfragment = get_and_fill_fragment(fragment_buffer);\n\tcache_block_put(fragment_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment,\n\t\t\t0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < (1LL << 32) && start <\n\t\t\t(1LL << 32) && sparse == 0)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size,\n\t\t\tstart, blocks, block_list, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size,\n\t\t\tstart, blocks, block_list, fragment, NULL, sparse);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(!block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tint block, thresh;\n\tlong long file_bytes, dup_start, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer **buffer_list;\n\tint status, num_locked_fragments;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\tblock_list = malloc(blocks * sizeof(unsigned int));\n\tif(block_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tbuffer_list = malloc(blocks * sizeof(struct file_buffer *));\n\tif(buffer_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tnum_locked_fragments = lock_fragments();\n\n\tfile_bytes = 0;\n\tstart = dup_start = bytes;\n\tthresh = blocks > (writer_buffer_size - num_locked_fragments) ?\n\t\tblocks - (writer_buffer_size - num_locked_fragments): 0;\n\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tif(block < thresh) {\n\t\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t\t} else\n\t\t\t\t\tbuffer_list[block] = read_buffer;\n\t\t\t} else {\n\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &dup_start,\n\t\t&fragment, fragment_buffer, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tif(buffer_list[block])\n\t\t\t\tqueue_put(to_writer, buffer_list[block]);\n\t\tfragment = get_and_fill_fragment(fragment_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tcache_block_put(buffer_list[block]);\n\t\tbytes = start;\n\t\tif(thresh && !block_device) {\n\t\t\tint res;\n\n\t\t\tqueue_put(to_writer, NULL);\n\t\t\tif(queue_get(from_writer) != 0)\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\tres = ftruncate(fd, bytes);\n\t\t\tif(res != 0)\n\t\t\t\tBAD_ERROR(\"Failed to truncate dest file because\"\n\t\t\t\t\t\"  %s\\n\", strerror(errno));\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tcache_block_put(fragment_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < (1LL << 32) && dup_start <\n\t\t\t(1LL << 32) && sparse == 0)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size,\n\t\t\tdup_start, blocks, block_listp, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size,\n\t\t\tdup_start, blocks, block_listp, fragment, NULL, sparse);\n\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(thresh && !block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\tcache_block_put(buffer_list[blocks]);\n\tfree(buffer_list);\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tint status;\n\tstruct file_buffer *read_buffer;\n\tlong long read_size;\n\nagain:\n\tread_buffer = get_file_buffer(from_deflate);\n\n\tstatus = read_buffer->error;\n\tif(status) {\n\t\tcache_block_put(read_buffer);\n\t\tgoto file_err;\n\t}\n\t\n\tread_size = read_buffer->file_size;\n\n\tif(read_size == 0) {\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t\tcache_block_put(read_buffer);\n\t} else if(read_buffer->fragment && read_buffer->c_byte)\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer,\n\t\t\tduplicate_file);\n\telse if(pre_duplicate(read_size))\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\telse\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\nfile_err:\n\tif(status == 2) {\n\t\tERROR(\"File %s changed size while reading filesystem, \"\n\t\t\t\"attempting to re-read\\n\", dir_ent->pathname);\n\t\tgoto again;\n\t} else if(status == 1) {\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\",\n\t\t\tdir_ent->pathname);\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t}\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) ||\n\t\t\t\t((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\"\n\t\t\t\"\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\n\tif((buf->st_mode & S_IFMT) == S_IFREG)\n\t\testimated_uncompressed += (buf->st_size + block_size - 1) >>\n\t\t\tblock_log;\n\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir,\n\tstruct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0) {\n\t\tdir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) *\n\t\t\t\tsizeof(struct dir_ent *));\n\t\tif(dir->list == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\t}\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) :\n\t\tNULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count\n\t\t= 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL,\n\t\t\t\t&old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\",\n\t\t\t\tsource_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count &&\n\t\t\t\tstrcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL,\n\t\t\t\t&old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count &&\n\t\t\t\tstrcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tcontinue;\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nstruct dir_ent *scan2_lookup(struct dir_info *dir, char *name)\n{\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++)\n\t\tif(strcmp(dir->list[i]->name, name) == 0)\n\t\t\treturn dir->list[i];\n\n\treturn NULL;\n}\n\n\nstruct dir_ent *scan3_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode,\n\t\t\t\tdir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name,\n\t\t\t\tdir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct dir_info *dir)\n{\n\tdir->current_count = 0;\n}\n\n\nvoid scan3_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tdir_scan2(dir_info, pseudo);\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/*\n \t\t *dummy top level directory, if multiple sources specified on\n\t\t * command line\n\t\t */\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", pathname,\n\t\t\tstrerror(errno));\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0,\n\t\t\t&dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tif(progress)\n\t\tenable_progress_bar();\n\tdir_scan3(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\tstruct pathnames *new;\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\",\n\t\t\t\tfilename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\"\n\t\t\t\t\"\\n\", filename, buf.st_mode & S_IFMT);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(old_exclude) {\n\t\t\tif(old_excluded(filename, &buf))\n\t\t\t\tcontinue;\n\t\t} else {\n\t\t\tif(excluded(paths, dir_name, &new))\n\t\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tsub_dir = dir_scan1(filename, new, scan1_readdir);\n\t\t\tif(sub_dir == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf),\n\t\t\tNULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\nerror:\n\treturn dir;\n}\n\n\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo)\n{\n\tstruct dir_info *sub_dir;\n\tstruct dir_ent *dir_ent;\n\tstruct pseudo_entry *pseudo_ent;\n\tstruct stat buf;\n\tstatic pseudo_ino = 1;\n\t\n\tif(dir == NULL && (dir = scan1_opendir(\"\")) == NULL)\n\t\treturn NULL;\n\t\n\twhile((dir_ent = scan2_readdir(dir)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *name = dir_ent->name;\n\n\t\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\tdir_scan2(dir_ent->dir, pseudo_subdir(name, pseudo));\n\t}\n\n\twhile((pseudo_ent = pseudo_readdir(pseudo)) != NULL) {\n\t\tdir_ent = scan2_lookup(dir, pseudo_ent->name);\n\t\tif(dir_ent) {\n\t\t\tERROR(\"Pseudo file \\\"%s\\\" exists in source filesystem \"\n\t\t\t\t\"\\\"%s\\\"\\n\", pseudo_ent->pathname,\n\t\t\t\tdir_ent->pathname);\n\t\t\tERROR(\"Ignoring, exclude it (-e/-ef) to override\\n\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(pseudo_ent->dev->type == 'd') {\n\t\t\tsub_dir = dir_scan2(NULL, pseudo_ent->pseudo);\n\t\t\tif(sub_dir == NULL) {\n\t\t\t\tERROR(\"Could not create pseudo directory \\\"%s\\\"\"\n\t\t\t\t\t\", skipping...\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = pseudo_ent->dev->mode;\n\t\tbuf.st_uid = pseudo_ent->dev->uid;\n\t\tbuf.st_gid = pseudo_ent->dev->gid;\n\t\tbuf.st_rdev = makedev(pseudo_ent->dev->major,\n\t\t\tpseudo_ent->dev->minor);\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_ino = pseudo_ino ++;\n\n\t\tadd_dir_entry(pseudo_ent->name, pseudo_ent->pathname, sub_dir,\n\t\t\tlookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan2_freedir(dir);\n\tsort_directory(dir);\n\n\treturn dir;\n}\n\n\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan3_init_dir(&dir);\n\t\n\twhile((dir_ent = scan3_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\t?  dir_ent->inode->inode_number :\n\t\t\tdir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\twrite_file(inode, dir_ent,\n\t\t\t\t\t\t&duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld \"\n\t\t\t\t\t\t\"bytes %s\\n\", filename,\n\t\t\t\t\t\tbuf->st_size, duplicate_file ?\n\t\t\t\t\t\t\"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tdir_scan3(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\"\n\t\t\t\t\t\t\"\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\",dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tBAD_ERROR(\"%s unrecognised file type, \"\n\t\t\t\t\t\t\"mode is %x\\n\", filename,\n\t\t\t\t\t\tbuf->st_mode);\n\t\t\t}\n\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed \"\n\t\t\t\t\t\t\t\"size %lld bytes LINK\"\n\t\t\t\t\t\t\t\"\\n\", filename,\n\t\t\t\t\t\t\tbuf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx LINK\\n\", dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t\tupdate_progress_bar();\n\t}\n\n\twrite_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan3_freedir(&dir);\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 20; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint old_excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) &&\n\t\t\t\t(exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) { \\\n\t\texclude_paths = realloc(exclude_paths, (exclude + EXCLUDE_SIZE) \\\n\t\t\t* sizeof(struct exclude_info)); \\\n\t\tif(exclude_paths == NULL) \\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\"); \\\n\t} \\\n\texclude_paths[exclude].st_dev = buf.st_dev; \\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint old_add_exclude(char *path)\n{\n\tint i;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 ||\n\t\t\tstrncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat exclude dir/file %s because %s, \"\n\t\t\t\t\"ignoring\", path, strerror(errno));\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tERROR(\"Cannot stat exclude dir/file %s because \"\n\t\t\t\t\t\"%s, ignoring\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type)\n{\n\told_root_entry = realloc(old_root_entry,\n\t\tsizeof(struct old_root_entry_info) * (old_root_entries + 1));\n\tif(old_root_entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries \"\n\t\t\t\"reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  \"\n\t\t\t\t\"Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(fragment_buffer_size);\n\treader_buffer = cache_init(block_size, reader_buffer_size);\n\twriter_buffer = cache_init(block_size, writer_buffer_size);\n\tfragment_buffer = cache_init(block_size, fragment_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&progress_thread, NULL, progress_thrd, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) !=\n\t\t\t\t 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator,\n\t\t\t\tNULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tinode_lookup_table = realloc(inode_lookup_table, lookup_bytes);\n\tif(inode_lookup_table == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number +\n\t\t\t\tdir_inode_no;\n\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(&inode->inode,\n\t\t\t\t&inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table,\n\t\t0);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) *\n\t\t\tsizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname,\n\t\t\t\tREG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, \"\n\t\t\t\t\t\"because %s\\n\", targname, alltarget,\n\t\t\t\t\tstr);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target,\n\t\t\t\talltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing exclude which subsumes\n\t\t\t * the exclude currently being added, in which case stop\n\t\t\t * adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist\n\t\t\t * from more specific excludes, delete as they're\n\t\t\t * subsumed by this exclude */\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid add_exclude(char *target)\n{\n\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 ||\n\t\t\tstrncmp(target, \"../\", 3) == 0)\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with \"\n\t\t\t\"-wildcards or -regex options\\n\");\t\n\telse if(strncmp(target, \"... \", 4) == 0)\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\n\telse\t\n\t\tpath = add_path(path, target, target);\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) +\n\t\t\t(paths->count + PATHS_ALLOC_SIZE) *\n\t\t\tsizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n, res;\n\t\t\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\n\t*new = init_subdir();\n\tif(stickypath)\n\t\t*new = add_subdir(*new, stickypath);\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0,\n\t\t\t\t\tNULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name,\n\t\t\t\t\tFNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) ==\n\t\t\t\t\t 0;\n\n\t\t\tif(match && path->name[i].paths == NULL) {\n\t\t\t\t/* match on a leaf component, any subdirectories\n\t\t\t\t * in the filesystem should be excluded */\n\t\t\t\tres = TRUE;\n\t\t\t\tgoto empty_set;\n\t\t\t}\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any\n\t\t\t\t * subdirectories to the new set of\n\t\t\t\t * subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t\t/* no matching names found, return empty new search set\n\t\t\t */\n\t\t\tres = FALSE;\n\t\t\tgoto empty_set;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches).\n\t * Return new set */\n\treturn FALSE;\n\nempty_set:\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn res;\n}\n\n\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\n#define RECOVER_ID_SIZE 28\n\nvoid write_recovery_data(squashfs_super_block *sBlk)\n{\n\tint recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\n\tpid_t pid = getpid();\n\tchar *metadata;\n\tchar header[] = RECOVER_ID;\n\n\tif(recover == FALSE) {\n\t\tprintf(\"No recovery data option specified.\\n\");\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\n\t\treturn;\n\t}\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"write_recovery_data\\n\");\n\n\tread_destination(fd, sBlk->inode_table_start, bytes, metadata);\n\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\",\n\t\tgetbase(destination_file), pid);\n\trecoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);\n\tif(recoverfd == -1)\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  \"\n\t\t\t\"Aborting\\n\", strerror(errno));\n\t\t\n\tif(write_bytes(recoverfd, header, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, metadata, bytes) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tclose(recoverfd);\n\tfree(metadata);\n\t\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file,\n\t\trecovery_file);\n\tprintf(\"to restore filesystem\\n\\n\");\n}\n\n\nvoid read_recovery_data(char *recovery_file, char *destination_file)\n{\n\tint fd, recoverfd, bytes;\n\tsquashfs_super_block orig_sBlk, sBlk;\n\tchar *metadata;\n\tint res;\n\tstruct stat buf;\n\tchar header[] = RECOVER_ID;\n\tchar header2[RECOVER_ID_SIZE];\n\n\tif((recoverfd = open(recovery_file, O_RDONLY)) == -1)\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(stat(destination_file, &buf) == -1)\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif((fd = open(destination_file, O_RDWR)) == -1)\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tres = read_bytes(recoverfd, header2, RECOVER_ID_SIZE);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < RECOVER_ID_SIZE)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\n\n\tres = read_bytes(recoverfd, &sBlk, sizeof(squashfs_super_block));\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < sizeof(squashfs_super_block))\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\tread_destination(fd, 0, sizeof(squashfs_super_block), (char *)\n\t\t&orig_sBlk);\n\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4,\n\t\t\tsizeof(squashfs_super_block) - 4) != 0)\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to \"\n\t\t\t\"match\\n\");\n\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"read_recovery_data\\n\");\n\n\tres = read_bytes(recoverfd, metadata, bytes);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < bytes)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\twrite_destination(fd, 0, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\twrite_destination(fd, sBlk.inode_table_start, bytes, metadata);\n\n\tclose(recoverfd);\n\tclose(fd);\n\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\",\n\t\trecovery_file);\n\t\n\texit(0);\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 4.0 (2009/04/05)\\n\");\\\n\tprintf(\"copyright (C) 2009 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n\tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint nopad = FALSE, keep_as_directory = FALSE;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT,\n\t\twriteb_mbytes = WRITER_BUFFER_DEFAULT,\n\t\tfragmentb_mbytes = FRAGMENT_BUFFER_DEFAULT;\n\tint s_minor = SQUASHFS_MINOR;\n\n\tpthread_mutex_init(&progress_mutex, NULL);\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-pf\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -pf missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_file(&pseudo, argv[i]) == FALSE) {\n\t\t\t\tERROR(\"Failed to parse pseudo file \\\"%s\\\"\\n\",\n\t\t\t\t\targv[i]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-p\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -p missing pseudo file definition\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_def(&pseudo, argv[i]) == FALSE) {\n\t\t\t\tERROR(\"Failed to parse pseudo definition\\n\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-recover\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\n\t\t\trecover = FALSE;\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = FALSE;\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\n\t\t\tsparse_files = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid \"\n\t\t\t\t\t\"processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte \"\n\t\t\t\t\t\"or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-fragment-queue\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(fragmentb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -fragment-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragmentb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -fragment-queue should be 1 \"\n\t\t\t\t\t\"megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -b missing block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_size = strtol(argv[i], &b, 10);\n\t\t\tif(*b == 'm' || *b == 'M')\n\t\t\t\tblock_size *= 1048576;\n\t\t\telse if(*b == 'k' || *b == 'K')\n\t\t\t\tblock_size *= 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tERROR(\"%s: -b invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or \"\n\t\t\t\t\t\"not between 4096 and 1Mbyte\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n#ifdef USE_LZMA\n\t\t} else if(strcmp(argv[i], \"-lzma\") == 0) {\n\t\t\tcompression = LZMA_COMPRESSION;\n#endif\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or \"\n\t\t\t\t\t\t\"unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or \"\n\t\t\t\t\t\t\"unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0) {\n\t\t\tsilent = FALSE;\n\t\t\tprogress = FALSE;\n\t\t}\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] \"\n\t\t\t\t\"[-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and \"\n\t\t\t\t\"copyright message\\n\");\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data \"\n\t\t\t\t\"using recovery file <name>\\n\");\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery \"\n\t\t\t\t\"file\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem \"\n\t\t\t\t\"exportable via NFS\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress \"\n\t\t\t\t\"bar\\n\");\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to \"\n\t\t\t\t\"<block_size>.  Default %d bytes\\n\",\n\t\t\t\tSQUASHFS_FILE_SIZE);\n#ifdef USE_LZMA\n\t\t\tERROR(\"-lzma Enable LZMA compression\\n\");\n#endif\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.\"\n\t\t\t\t\"  By default will use number of\\n\");\n\t\t\tERROR(\"\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tREADER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tWRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-fragment-queue <size>\\tSet fagment queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tFRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for \"\n\t\t\t\t\"files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate \"\n\t\t\t\t\"checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing \"\n\t\t\t\t\"filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is \"\n\t\t\t\t\"specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, \"\n\t\t\t\t\"rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source \"\n\t\t\t\t\"files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in \"\n\t\t\t\t\"the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new \"\n\t\t\t\t\"source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple \"\n\t\t\t\t\"of 4K\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for \"\n\t\t\t\t\"-noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to \"\n\t\t\t\t\"priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  \"\n\t\t\t\t\"Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.\"\n\t\t\t\t\"  One per line\\n\");\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards \"\n\t\t\t\t\"(globbing) to be used in\\n\\t\\t\\texclude \"\n\t\t\t\t\"dirs/files\\n\");\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to \"\n\t\t\t\t\"be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n\t\t\tERROR(\"-p <pseudo-definition>\\tAdd pseudo file definition\\n\");\n\t\t\tERROR(\"-pf <pseudo-file>\\tAdd list of pseudo file definitions\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\tfragment_buffer_size = fragmentb_mbytes << (20 - block_log);\n\n\tfor(i = 0; i < source; i++)\n\t\tif(lstat(source_path[i], &source_buf) == -1) {\n\t\t\tfprintf(stderr, \"Cannot stat source directory \\\"%s\\\" \"\n\t\t\t\t\"because %s\\n\", source_path[i],\n\t\t\t\tstrerror(errno));\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tfd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR,\n\t\t\t\tS_IRWXU);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as \"\n\t\t\t\t\t\"destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tfd = open(argv[source + 1], (delete ? O_TRUNC : 0) |\n\t\t\t\tO_RDWR);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not open regular file for \"\n\t\t\t\t\t\"writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tsignal(SIGTERM, sighandler2);\n\tsignal(SIGINT, sighandler2);\n\n\t/* process the exclude files - must be done afer destination file has\n\t * been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\t\tif(old_exclude)\n\t\t\t\t\t\told_add_exclude(filename);\n\t\t\t\t\telse\n\t\t\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-sort\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-p\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc)\n\t\t\tif(old_exclude)\n\t\t\t\told_add_exclude(argv[i++]);\n\t\t\telse\n\t\t\t\tadd_exclude(argv[i++]);\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-ef\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-p\") == 0)\n\t\t\ti++;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\ts_minor = sBlk.s_minor;\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t}\n\n\tinitialise_threads();\n\n\tif(delete) {\n\t\tprintf(\"Creating %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\tSQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset,\n\t\t\tinode_dir_file_size, root_inode_size,\n\t\t\tinode_dir_start_block, uncompressed_data,\n\t\t\tcompressed_data, inode_dir_inode_number,\n\t\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start =\n\t\t\tSQUASHFS_INODE_BLK(sBlk.root_inode),\n\t\t\troot_inode_offset =\n\t\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table,\n\t\t\t\t&data_cache, &directory_table,\n\t\t\t\t&directory_data_cache, &last_directory_block,\n\t\t\t\t&inode_dir_offset, &inode_dir_file_size,\n\t\t\t\t&root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count,\n\t\t\t\t&fifo_count, &sock_count, &total_bytes,\n\t\t\t\t&total_inode_bytes, &total_directory_bytes,\n\t\t\t\t&inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry,\n\t\t\t\t&fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = realloc((char *) fragment_table,\n\t\t\t\t((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1))\n\t\t\t\t * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %d.%d filesystem on %s, block \"\n\t\t\t\"size %d\\n\", SQUASHFS_MAJOR, s_minor, argv[source + 1],\n\t\t\tblock_size);\n\t\tprintf(\"All -b, -noI, -noD, -noF, no-duplicates, no-fragments, \"\n\t\t\t\"-always-use-fragments and -exportable options ignored\"\n\t\t\t\"\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with \"\n\t\t\t\"-noappend specified!\\n\\n\");\n\n\t\tcompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t(SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tscache_bytes = root_inode_offset + root_inode_size;\n\t\tsdirectory_cache_bytes = uncompressed_data;\n\t\tsdata_cache = malloc(scache_bytes);\n\t\tsdirectory_data_cache = malloc(sdirectory_cache_bytes);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache +\n\t\t\tcompressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes +\n\t\t\tcompressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\tsid_count = id_count;\n\t\twrite_recovery_data(&sBlk);\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_destination(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/*\n\t\t * set the filesystem state up to be able to append to the\n\t\t * original filesystem.  The filesystem state differs depending\n\t\t * on whether we're appending to the original root directory, or\n\t\t * if the original root directory becomes a sub-directory\n\t\t * (root-becomes specified on command line, here root_name !=\n\t\t * NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\tsdirectory_bytes = last_directory_block;\n\t\t\tsdirectory_compressed_bytes = 0;\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache +\n\t\t\t\tcompressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode,\n\t\t\t\tinode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\tsdirectory_compressed_bytes = last_directory_block -\n\t\t\t\tinode_dir_start_block;\n\t\t\tsdirectory_compressed =\n\t\t\t\tmalloc(sdirectory_compressed_bytes);\n\t\t\tmemcpy(sdirectory_compressed, directory_table +\n\t\t\t\tinode_dir_start_block,\n\t\t\t\tsdirectory_compressed_bytes); \n\t\t\tsdirectory_bytes = inode_dir_start_block;\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count +\n\t\t\tfifo_count + sock_count;\n\t}\n\n\tif(path || stickypath) {\n\t\tpaths = init_subdir();\n\t\tif(path)\n\t\t\tpaths = add_subdir(paths, path);\n\t\tif(stickypath)\n\t\t\tpaths = add_subdir(paths, stickypath);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = s_minor;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, no_fragments,\n\t\talways_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\tif(progress && estimated_uncompressed) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tunlock_fragments();\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\twhile(fragments_outstanding) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tsched_yield();\n\t\t\tpthread_mutex_lock(&fragment_mutex);\n\t\t}\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() :\n\t\tSQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\",\n\t\tsBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\",\n\t\t\tsBlk.lookup_table_start);\n\n\tsBlk.no_ids = id_count;\n\tsBlk.id_table_start = write_id_table();\n\n\tsBlk.bytes_used = bytes;\n\n\t/* Only compression supported */\n\tsBlk.compression = compression;\n\n\t/* Xattrs are not currently supported */\n\tsBlk.xattr_table_start = SQUASHFS_INVALID_BLK;\n\n\tSQUASHFS_INSWAP_SUPER_BLOCK(&sBlk); \n\twrite_destination(fd, SQUASHFS_START, sizeof(squashfs_super_block),\n\t\t(char *) &sBlk);\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_destination(fd, bytes, 4096 - i, temp);\n\t}\n\n\tclose(fd);\n\n\tif(recovery_file[0] != '\\0')\n\t\tunlink(recovery_file);\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%sSquashfs %d.%d filesystem, data block size %d\\n\",\n\t\texportable ? \"Exportable \" : \"\", SQUASHFS_MAJOR, SQUASHFS_MINOR,\n\t\tblock_size);\n\tprintf(\"\\t%s data, %s metadata, %s fragments\\n\",\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" :\n\t\t\"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" :\n\t\t\"compressed\");\n\tprintf(\"\\tduplicates are %sremoved\\n\", duplicate_checking ? \"\" :\n\t\t\"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0,\n\t\tbytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0,\n\t\ttotal_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0,\n\t\ttotal_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count -\n\t\t\tdup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of ids (unique uids + gids) %d\\n\", id_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_UID) {\n\t\t\tstruct passwd *user = getpwuid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" :\n\t\t\t\tuser->pw_name, id_table[i]->id);\n\t\t}\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_GID) {\n\t\t\tstruct group *group = getgrgid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" :\n\t\t\t\tgroup->gr_name, id_table[i]->id);\n\t\t}\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/mksquashfs.h",
    "content": "#ifndef MKSQUASHFS_H\n#define MKSQUASHFS_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define SQUASHFS_SWAP_SHORTS(s, d, n) swap_le16_num(s, d, n)\n#define SQUASHFS_SWAP_INTS(s, d, n) swap_le32_num(s, d, n)\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) swap_le64_num(s, d, n)\n\n#define SWAP_LE16(s, d, field)\tswap_le16(&((s)->field), &((d)->field))\n#define SWAP_LE32(s, d, field)\tswap_le32(&((s)->field), &((d)->field))\n#define SWAP_LE64(s, d, field)\tswap_le64(&((s)->field), &((d)->field))\n#define SWAP_LES16(s, d, field)\tswap_le16((unsigned short *) &((s)->field), \\\n\t\t\t\t(unsigned short *) &((d)->field))\n#else\n#define SQUASHFS_MEMCPY(s, d, n)\tmemcpy(d, s, n)\n#define SQUASHFS_SWAP_SHORTS(s, d, n)\tmemcpy(d, s, n * sizeof(short))\n#define SQUASHFS_SWAP_INTS(s, d, n)\tmemcpy(d, s, n * sizeof(int))\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) \\\n\t\t\t\t\tmemcpy(d, s, n * sizeof(long long))\n#endif\n\nextern int uncompress_wrapper(unsigned char *dest, unsigned long *dest_len,\n    const unsigned char *src, unsigned long src_len);\n\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/pseudo.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * pseudo.c\n */\n\n#include <pwd.h>\n#include <grp.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <stdlib.h>\n#include <sys/types.h>\n\n#include \"pseudo.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\n#define TRUE 1\n#define FALSE 0\n\nstatic void dump_pseudo(struct pseudo *pseudo, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tfor(i = 0; i < pseudo->names; i++) {\n\t\tstruct pseudo_entry *entry = &pseudo->name[i];\n\t\tif(string)\n\t\t\tstrcat(strcat(strcpy(path, string), \"/\"), entry->name);\n\t\telse\n\t\t\tstrcpy(path, entry->name);\n\t\tif(entry->pseudo == NULL)\n\t\t\tERROR(\"%s %c %o %d %d %d %d\\n\", path, entry->dev->type,\n\t\t\t\tentry->dev->mode, entry->dev->uid,\n\t\t\t\tentry->dev->gid, entry->dev->major,\n\t\t\t\tentry->dev->minor);\n\t\telse\n\t\t\tdump_pseudo(entry->pseudo, path);\n\t}\n}\n\n\nstatic char *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\n/*\n * Add pseudo device target to the set of pseudo devices.  Pseudo_dev\n * describes the pseudo device attributes.\n */\nstruct pseudo *add_pseudo(struct pseudo *pseudo, struct pseudo_dev *pseudo_dev,\n\tchar *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(pseudo == NULL) {\n\t\tif((pseudo = malloc(sizeof(struct pseudo))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate pseudo file\\n\");\n\n\t\tpseudo->names = 0;\n\t\tpseudo->count = 0;\n\t\tpseudo->name = NULL;\n\t}\n\n\tfor(i = 0; i < pseudo->names; i++)\n\t\tif(strcmp(pseudo->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == pseudo->names) {\n\t\t/* allocate new name entry */\n\t\tpseudo->names ++;\n\t\tpseudo->name = realloc(pseudo->name, (i + 1) *\n\t\t\tsizeof(struct pseudo_entry));\n\t\tif(pseudo->name == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate pseudo file\\n\");\n\t\tpseudo->name[i].name = strdup(targname);\n\n\t\tif(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component */\n\t\t\tpseudo->name[i].pseudo = NULL;\n\t\t\tpseudo->name[i].dev = malloc(sizeof(struct pseudo_dev));\n\t\t\tif(pseudo->name[i].dev == NULL)\n\t\t\t\tBAD_ERROR(\"failed to allocate pseudo file\\n\");\n\t\t\tpseudo->name[i].pathname = strdup(alltarget);\n\t\t\tmemcpy(pseudo->name[i].dev, pseudo_dev,\n\t\t\t\tsizeof(struct pseudo_dev));\n\t\t} else {\n\t\t\t/* recurse adding child components */\n\t\t\tpseudo->name[i].dev = NULL;\n\t\t\tpseudo->name[i].pseudo = add_pseudo(NULL, pseudo_dev,\n\t\t\t\ttarget, alltarget);\n\t\t}\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(pseudo->name[i].pseudo == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing pseudo file.\n\t\t\t */\n\t\t\tif(target[0] != '\\0') {\n\t\t\t\t/* entry must exist as a 'd' type pseudo file */\n\t\t\t\tif(pseudo->name[i].dev->type == 'd')\n\t\t\t\t\t/* recurse adding child components */\n\t\t\t\t\tpseudo->name[i].pseudo =\n\t\t\t\t\t\tadd_pseudo(NULL, pseudo_dev,\n\t\t\t\t\t\ttarget, alltarget);\n\t\t\t\telse\n\t\t\t\t\tERROR(\"%s already exists as a non \"\n\t\t\t\t\t\t\"directory.  Ignoring %s!\\n\",\n\t\t\t\t\t\t targname, alltarget);\n\t\t\t} else if(memcmp(pseudo_dev, pseudo->name[i].dev,\n\t\t\t\t\tsizeof(struct pseudo_dev)) != 0)\n\t\t\t\tERROR(\"%s already exists as a different pseudo \"\n\t\t\t\t\t\"definition.  Ignoring!\\n\", alltarget);\n\t\t\telse ERROR(\"%s already exists as an identical \"\n\t\t\t\t\t\"pseudo definition!\\n\", alltarget);\n\t\t} else {\n\t\t\t/* sub-directory exists which means this can only be a\n\t\t\t * 'd' type pseudo file */\n\t\t\tif(target[0] == '\\0') {\n\t\t\t\tif(pseudo->name[i].dev == NULL &&\n\t\t\t\t\t\tpseudo_dev->type == 'd') {\n\t\t\t\t\tpseudo->name[i].dev =\n\t\t\t\t\t\tmalloc(sizeof(struct pseudo_dev));\n\t\t\t\t\tif(pseudo->name[i].dev == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"failed to allocate \"\n\t\t\t\t\t\t\t\"pseudo file\\n\");\n\t\t\t\t\tpseudo->name[i].pathname =\n\t\t\t\t\t\tstrdup(alltarget);\n\t\t\t\t\tmemcpy(pseudo->name[i].dev, pseudo_dev,\n\t\t\t\t\t\tsizeof(struct pseudo_dev));\n\t\t\t\t} else\n\t\t\t\t\tERROR(\"%s already exists as a \"\n\t\t\t\t\t\t\"directory.  Ignoring %s!\\n\",\n\t\t\t\t\t\ttargname, alltarget);\n\t\t\t} else\n\t\t\t\t/* recurse adding child components */\n\t\t\t\tadd_pseudo(pseudo->name[i].pseudo, pseudo_dev,\n\t\t\t\t\ttarget, alltarget);\n\t\t}\n\t}\n\n\treturn pseudo;\n}\n\n\n/*\n * Find subdirectory in pseudo directory referenced by pseudo, matching\n * filename.  If filename doesn't exist or if filename is a leaf file\n * return NULL\n */\nstruct pseudo *pseudo_subdir(char *filename, struct pseudo *pseudo)\n{\n\tint i;\n\n\tif(pseudo == NULL)\n\t\treturn NULL;\n\n\tfor(i = 0; i < pseudo->names; i++)\n\t\tif(strcmp(filename, pseudo->name[i].name) == 0)\n\t\t\treturn pseudo->name[i].pseudo;\n\n\treturn NULL;\n}\n\n\nstruct pseudo_entry *pseudo_readdir(struct pseudo *pseudo)\n{\n\tif(pseudo == NULL)\n\t\treturn NULL;\n\n\twhile(pseudo->count < pseudo->names) {\n\t\tif(pseudo->name[pseudo->count].dev != NULL)\n\t\t\treturn &pseudo->name[pseudo->count++];\n\t\telse\n\t\t\tpseudo->count++;\n\t}\n\n\treturn NULL;\n}\n\n\nint read_pseudo_def(struct pseudo **pseudo, char *def)\n{\n\tint n;\n\tunsigned int major = 0, minor = 0, mode;\n\tchar filename[2048], type, suid[100], sgid[100], *ptr;\n\tlong long uid, gid;\n\tstruct pseudo_dev dev;\n\n\tn = sscanf(def, \"%s %c %o %s %s %u %u\", filename, &type, &mode, suid, sgid,\n\t\t\t&major, &minor);\n\n\tif(n < 5) {\n\t\tERROR(\"Not enough or invalid arguments in pseudo file \"\n\t\t\t\"definition\\n\");\n\t\tgoto error;\n\t}\n\n\tswitch(type) {\n\tcase 'b':\n\tcase 'c':\n\t\tif(n < 7) {\n\t\t\tERROR(\"Not enough or invalid arguments in pseudo file \"\n\t\t\t\t\"definition\\n\");\n\t\t\tgoto error;\n\t\t}\t\n\t\t\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range\\n\", major);\n\t\t\tgoto error;\n\t\t}\n\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range\\n\", minor);\n\t\t\tgoto error;\n\t\t}\n\n\t\t/* fall through */\n\tcase 'd':\n\t\tif(mode > 0777) {\n\t\t\tERROR(\"Mode %o out of range\\n\", mode);\n\t\t\tgoto error;\n\t\t}\n\n\t\tuid = strtoll(suid, &ptr, 10);\n\t\tif(*ptr == '\\0') {\n\t\t\tif(uid < 0 || uid > ((1LL << 32) - 1)) {\n\t\t\t\tERROR(\"Uid %s out of range\\n\", suid);\n\t\t\t\tgoto error;\n\t\t\t}\n\t\t} else {\n\t\t\tstruct passwd *pwuid = getpwnam(suid);\n\t\t\tif(pwuid)\n\t\t\t\tuid = pwuid->pw_uid;\n\t\t\telse {\n\t\t\t\tERROR(\"Uid %s invalid uid or unknown user\\n\",\n\t\t\t\t\tsuid);\n\t\t\t\tgoto error;\n\t\t\t}\n\t\t}\n\t\t\n\t\tgid = strtoll(sgid, &ptr, 10);\n\t\tif(*ptr == '\\0') {\n\t\t\tif(gid < 0 || gid > ((1LL << 32) - 1)) {\n\t\t\t\tERROR(\"Gid %s out of range\\n\", sgid);\n\t\t\t\tgoto error;\n\t\t\t}\n\t\t} else {\n\t\t\tstruct group *grgid = getgrnam(sgid);\n\t\t\tif(grgid)\n\t\t\t\tgid = grgid->gr_gid;\n\t\t\telse {\n\t\t\t\tERROR(\"Gid %s invalid uid or unknown user\\n\",\n\t\t\t\t\tsgid);\n\t\t\t\tgoto error;\n\t\t\t}\n\t\t}\n\n\t\tbreak;\n\tdefault:\n\t\tERROR(\"Unsupported type %c\\n\", type);\n\t\tgoto error;\n\t}\n\n\n\tswitch(type) {\n\tcase 'b':\n\t\tmode |= S_IFBLK;\n\t\tbreak;\n\tcase 'c':\n\t\tmode |= S_IFCHR;\n\t\tbreak;\n\tcase 'd':\n\t\tmode |= S_IFDIR;\n\t\tbreak;\n\t}\n\n\tdev.type = type;\n\tdev.mode = mode;\n\tdev.uid = uid;\n\tdev.gid = gid;\n\tdev.major = major;\n\tdev.minor = minor;\n\n\t*pseudo = add_pseudo(*pseudo, &dev, filename, filename);\n\n\treturn TRUE;\n\nerror:\n\tERROR(\"Bad pseudo file definition \\\"%s\\\"\\n\", def);\n\treturn FALSE;\n}\n\t\t\n\nint read_pseudo_file(struct pseudo **pseudo, char *filename)\n{\n\tFILE *fd;\n\tchar line[2048];\n\tint res = TRUE;\n\n\tfd = fopen(filename, \"r\");\n\tif(fd == NULL) {\n\t\tERROR(\"Could not open pseudo device file \\\"%s\\\" because %s\\n\",\n\t\t\t\tfilename, strerror(errno));\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%2047[^\\n]\\n\", line) > 0) {\n\t\tres = read_pseudo_def(pseudo, line);\n\t\tif(res == FALSE)\n\t\t\tbreak;\n\t};\n\tfclose(fd);\n\treturn res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/pseudo.h",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * pseudo.h\n */\nstruct pseudo_dev {\n\tchar\t\ttype;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tgid;\n\tunsigned int\tmajor;\n\tunsigned int\tminor;\n};\n\nstruct pseudo_entry {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct pseudo\t\t*pseudo;\n\tstruct pseudo_dev\t*dev;\n};\n\t\nstruct pseudo {\n\tint\t\t\tnames;\n\tint\t\t\tcount;\n\tstruct pseudo_entry\t*name;\n};\n\nextern int read_pseudo_def(struct pseudo **, char *);\nextern int read_pseudo_file(struct pseudo **, char *);\nextern struct pseudo *pseudo_subdir(char *, struct pseudo *);\nextern struct pseudo_entry *pseudo_readdir(struct pseudo *);\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_destination(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int,\n\tunsigned int, int, int);\nextern void *create_id(unsigned int);\nextern unsigned int get_uid(unsigned int);\nextern unsigned int get_guid(unsigned int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"uncompress.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint read_block(int fd, long long start, long long *next, unsigned char *block,\n\tsquashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tread_destination(fd, start, 2, (char *)&c_byte);\n\tSQUASHFS_INSWAP_SHORTS(&c_byte, 1);\n\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_destination(fd, start + offset, c_byte, buffer);\n\n\t\tres = uncompress_wrapper(block, &bytes,\n\t\t\t(const unsigned char *) buffer, c_byte);\n\t\tif(res != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"uncompress failed, unknown error \"\n\t\t\t\t\t\"%d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_destination(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end,\n\tlong long root_inode_start, int root_inode_offset,\n\tsquashfs_super_block *sBlk, squashfs_inode_header *dir_inode,\n\tunsigned char **inode_table, unsigned int *root_inode_block,\n\tunsigned int *root_inode_size, long long *uncompressed_file,\n\tunsigned int *uncompressed_directory, int *file_count, int *sym_count,\n\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\tunsigned int *id_table)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start \"\n\t\t\"0x%llx\\n\", start, end, root_inode_start);\n\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx \"\n\t\t\t\t\"containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE) {\n\t\t\t*inode_table = realloc(*inode_table, size\n\t\t\t\t+= SQUASHFS_METADATA_SIZE);\n\t\t\tif(*inode_table == NULL)\n\t\t\t\treturn FALSE;\n\t\t}\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tbyte = read_block(fd, start, &start, *inode_table + bytes,\n\t\t\tsBlk);\n\t\tif(byte == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain\n\t * the last directory start block index.  This is used when calculating\n\t * the total uncompressed directory size.  The directory bytes in the\n\t * last * block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base,\n\t\t\t(squashfs_base_inode_header *) (*inode_table + bytes));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir,\n\t\t\t(squashfs_dir_inode_header *) (*inode_table + bytes));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir,\n\t\t\t(squashfs_ldir_inode_header *) (*inode_table + bytes));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\tget_uid(id_table[dir_inode->base.uid]);\n\tget_guid(id_table[dir_inode->base.guid]);\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode,\n\t\t\t(squashfs_reg_inode_header *) cur_ptr);\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position \"\n\t\t\t\"0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\tinode.inode_type);\n\n\t\tget_uid(id_table[inode.uid]);\n\t\tget_guid(id_table[inode.guid]);\n\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? 0 :\n\t\t\t\t\tinode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >>\n\t\t\t\t\tsBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, \"\n\t\t\t\t\t\"file_size %d, blocks %d\\n\",\n\t\t\t\t\tinode.file_size, blocks);\n\n\t\t\t\tblock_list = malloc(blocks *\n\t\t\t\t\tsizeof(unsigned int));\n\t\t\t\tif(block_list == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list \"\n\t\t\t\t\t\t\"malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tSQUASHFS_SWAP_INTS(block_list,\n\t\t\t\t\t(unsigned int *) cur_ptr, blocks);\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes +=\n\t\t\t\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t\t(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes,\n\t\t\t\t\tblock_list, blocks, inode.fragment,\n\t\t\t\t\tinode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode,\n\t\t\t\t\t(squashfs_lreg_inode_header *) cur_ptr);\n\n\t\t\t\tfrag_bytes = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? 0 :\n\t\t\t\t\tinode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t\t?  (inode.file_size +\n\t\t\t\t\tsBlk->block_size - 1) >>\n\t\t\t\t\tsBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular \"\n\t\t\t\t\t\"file, file_size %lld, blocks %d\\n\",\n\t\t\t\t\tinode.file_size, blocks);\n\n\t\t\t\tblock_list = malloc(blocks *\n\t\t\t\t\tsizeof(unsigned int));\n\t\t\t\tif(block_list == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list \"\n\t\t\t\t\t\t\"malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tSQUASHFS_SWAP_INTS(block_list,\n\t\t\t\t\t(unsigned int *) cur_ptr, blocks);\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes +=\n\t\t\t\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t\t(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes,\n\t\t\t\t\tblock_list, blocks, inode.fragment,\n\t\t\t\t\tinode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep,\n\t\t\t\t\t(squashfs_symlink_inode_header *)\n\t\t\t\t\tcur_ptr);\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode,\n\t\t\t\t\t(squashfs_dir_inode_header *) cur_ptr);\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory +=\n\t\t\t\t\tdir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode,\n\t\t\t\t\t(squashfs_ldir_inode_header *) cur_ptr);\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory +=\n\t\t\t\t\tdir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index,\n\t\t\t\t\t\t(squashfs_dir_index *) cur_ptr);\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) +\n\t\t\t\t\t\tindex.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in \"\n\t\t\t\t\t\"scan_inode_table!\\n\",\n\t\t\t\t\tinode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, char *source)\n{\n\tread_destination(fd, SQUASHFS_START, sizeof(squashfs_super_block),\n\t\t(char *) sBlk);\n\tSQUASHFS_INSWAP_SUPER_BLOCK(sBlk);\n\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP)\n\t\t\tERROR(\"Pre 4.0 big-endian filesystem on %s, appending\"\n\t\t\t\t\" to this is unsupported\\n\", source);\n\t\telse\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n\t\t\t\tsource);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 4)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.\"\n\t\t\t\t\"  Appending\\nto SQUASHFS %d.%d filesystems is \"\n\t\t\t\t\"not supported.  Please convert it to a \"\n\t\t\t\t\"SQUASHFS 4 filesystem\\n\", source,\n\t\t\t\tsBlk->s_major,\n\t\t\t\tsBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Filesystem on %s is %d.%d, which is a later \"\n\t\t\t\t\"filesystem version than I support\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n\tprintf(\"Found a valid %sSQUASHFS superblock on %s.\\n\",\n\t\tSQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\",\n\t\tSQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\",\n\t\tSQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\",\n\t\tSQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\",\n\t\tsBlk->bytes_used / 1024.0, sBlk->bytes_used\n\t\t/ (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of ids %d\\n\", sBlk->no_ids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\",\n\t\tsBlk->directory_table_start);\n\tTRACE(\"sBlk->id_table_start %llx\\n\", sBlk->id_table_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %llx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries,\n\tunsigned int directory_start_block, int offset, int size,\n\tunsigned int *last_directory_block, squashfs_super_block *sBlk,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block,\n\t\tlast_start_block = start; \n\n\tsize += offset;\n\tdirectory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) &\n\t\t~(SQUASHFS_METADATA_SIZE - 1));\n\tif(directory_table == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so \"\n\t\t\t\"far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tbyte = read_block(fd, start, &start, directory_table + bytes,\n\t\t\tsBlk);\n\t\tif(byte == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh,\n\t\t\t(squashfs_dir_header *) (directory_table + bytes));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position \"\n\t\t\t\"0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire,\n\t\t\t\t(squashfs_dir_entry *)\n\t\t\t\t(directory_table + bytes));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, \"\n\t\t\t\t\"inode %x:%x, type 0x%x\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name,\n\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n\t\t\t\tdire->offset), dirh.inode_number +\n\t\t\t\tdire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block -\n\t\tsBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nunsigned int *read_id_table(int fd, squashfs_super_block *sBlk)\n{\n\tint indexes = SQUASHFS_ID_BLOCKS(sBlk->no_ids);\n\tlong long index[indexes];\n\tint bytes = SQUASHFS_ID_BYTES(sBlk->no_ids);\n\tunsigned int *id_table;\n\tint i;\n\n\tid_table = malloc(bytes);\n\tif(id_table == NULL) {\n\t\tERROR(\"Failed to allocate id table\\n\");\n\t\treturn NULL;\n\t}\n\n\tread_destination(fd, sBlk->id_table_start,\n\t\tSQUASHFS_ID_BLOCK_BYTES(sBlk->no_ids), (char *) index);\n\tSQUASHFS_INSWAP_ID_BLOCKS(index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length;\n\t\tlength = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) id_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read id table block %d, from 0x%llx, length %d\\n\", i,\n\t\t\tindex[i], length);\n\t}\n\n\tSQUASHFS_INSWAP_INTS(id_table, sBlk->no_ids);\n\n\tfor(i = 0; i < sBlk->no_ids; i++) {\n\t\tTRACE(\"Adding id %d to id tables\\n\", id_table[i]);\n\t\tcreate_id(id_table[i]);\n\t}\n\n\treturn id_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk,\n\tsquashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk->fragments, indexes,\n\t\tsBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\t*fragment_table = malloc(sBlk->fragments *\n\t\tsizeof(squashfs_fragment_entry));\n\tif(*fragment_table == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tread_destination(fd, sBlk->fragment_table_start,\n\t\tSQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments),\n\t\t(char *) fragment_table_index);\n\tSQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((unsigned char *) *fragment_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t}\n\n\tfor(i = 0; i < sBlk->fragments; i++)\n\t\tSQUASHFS_INSWAP_FRAGMENT_ENTRY(&(*fragment_table)[i]);\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk,\n\tsquashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\t*inode_lookup_table = malloc(lookup_bytes);\n\tif(*inode_lookup_table == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tread_destination(fd, sBlk->lookup_table_start,\n\t\tSQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\tSQUASHFS_INSWAP_LONG_LONGS(index, indexes);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) *inode_lookup_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length \"\n\t\t\t\"%d\\n\", i, index[i], length);\n\t}\n\n\tSQUASHFS_INSWAP_LONG_LONGS(*inode_lookup_table, sBlk->inodes);\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk,\n\tchar **cinode_table, char **data_cache, char **cdirectory_table,\n\tchar **directory_data_cache, unsigned int *last_directory_block,\n\tunsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block,\n\tint *file_count, int *sym_count, int *dev_count, int *dir_count,\n\tint *fifo_count, int *sock_count, long long *uncompressed_file,\n\tunsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\tunsigned int *inode_dir_inode_number,\n\tunsigned int *inode_dir_parent_inode,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\tsquashfs_fragment_entry **fragment_table,\n\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start;\n\tlong long end = sBlk->directory_table_start;\n\tlong long root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk->root_inode);\n\tunsigned int root_inode_block, files;\n\tsquashfs_inode_header inode;\n\tunsigned int *id_table;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tid_table = read_id_table(fd, sBlk);\n\tif(id_table == NULL)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start,\n\t\t\troot_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file,\n\t\t\tuncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count, id_table))\n\t\t\t== 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE ||\n\t\t\tinode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tdirectory_table = squashfs_readdir(fd, !root_name,\n\t\t\t*inode_dir_start_block, *inode_dir_offset,\n\t\t\t*inode_dir_file_size, last_directory_block, sBlk,\n\t\t\tpush_directory_entry);\n\t\tif(directory_table == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\"\n\t\t\t\t\"\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\t*cinode_table = malloc(root_inode_start);\n\t\tif(*cinode_table == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for \"\n\t\t\t\t\"existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_destination(fd, start, root_inode_start, *cinode_table);\n\n\t\t*cdirectory_table = malloc(*last_directory_block);\n\t\tif(*cdirectory_table == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for \"\n\t\t\t\t\"existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_destination(fd, sBlk->directory_table_start,\n\t\t\t*last_directory_block, *cdirectory_table);\n\n\t\t*data_cache = malloc(root_inode_offset + *root_inode_size);\n\t\tif(*data_cache == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block,\n\t\t\troot_inode_offset + *root_inode_size);\n\n\t\t*directory_data_cache = malloc(*inode_dir_offset +\n\t\t\t*inode_dir_file_size);\n\t\tif(*directory_data_cache == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory \"\n\t\t\t\t\"cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table,\n\t\t\t*inode_dir_offset + *inode_dir_file_size);\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/read_fs.h",
    "content": "#ifndef READ_FS_H\n#define READ_FS_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.h\n *\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define SQUASHFS_SWAP_SHORTS(d, s, n) swap_le16_num(s, d, n)\n#define SQUASHFS_SWAP_INTS(d, s, n) swap_le32_num(s, d, n)\n#define SQUASHFS_SWAP_LONG_LONGS(d, s, n) swap_le64_num(s, d, n)\n\n#define SWAP_LE16(d, s, field)\tswap_le16(&((s)->field), &((d)->field))\n#define SWAP_LE32(d, s, field)\tswap_le32(&((s)->field), &((d)->field))\n#define SWAP_LE64(d, s, field)\tswap_le64(&((s)->field), &((d)->field))\n#define SWAP_LES16(d, s, field)\tswap_le16((unsigned short *) &((s)->field), \\\n\t\t\t\t(unsigned short *) &((d)->field))\n#else\n#define SQUASHFS_MEMCPY(d, s, n)\tmemcpy(d, s, n)\n#define SQUASHFS_SWAP_SHORTS(d, s, n)\tmemcpy(d, s, n * sizeof(short))\n#define SQUASHFS_SWAP_INTS(d, s, n)\tmemcpy(d, s, n * sizeof(int))\n#define SQUASHFS_SWAP_LONG_LONGS(d, s, n) \\\n\t\t\t\t\tmemcpy(d, s, n * sizeof(long long))\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority,\n\t\t\t\tfilename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 ||\n\t\t\tstrncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino \"\n\t\t\t\"%llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is \"\n\t\t\t\"supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry\");\n\t        ERROR(\" should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to \"\n\t\t\t\"$PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source \"\n\t\t\t\"directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory \"\n\t\t\t\"test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more \"\n\t\t\t\"than one source entry!  Please use an absolute path.\"\n\t\t\t\"\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority,\n\tstruct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent,\n\t\t\t\t\tget_priority(dir_ent->pathname, buf,\n\t\t\t\t\tpriority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority,\n\t\t\t\t\tbuf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source,\n\t\t\t\tsource_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of \"\n\t\t\t\t\"-32767:32768 - skipping...\\n\", sort_filename,\n\t\t\t\tpriority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\twrite_file(&inode, entry->dir, &duplicate_file);\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\"\n\t\t\t\t\t\"\\n\", entry->dir->pathname,\n\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes \"\n\t\t\t\t\t\"LINK\\n\", entry->dir->pathname,\n\t\t\t\t\tentry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tchar\t\t\tread;\n\tstruct inode_info\t*next;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/squashfs_compat.h",
    "content": "#ifndef SQUASHFS_COMPAT\n#define SQUASHFS_COMPAT\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_compat.h\n */\n\n/*\n * definitions for structures on disk - layout 3.x\n */\n\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\nstruct squashfs_super_block_3 {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index_3 {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER_3\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index_3\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_3 {\n\tstruct squashfs_base_inode_header_3\tbase;\n\tstruct squashfs_dev_inode_header_3\tdev;\n\tstruct squashfs_symlink_inode_header_3\tsymlink;\n\tstruct squashfs_reg_inode_header_3\treg;\n\tstruct squashfs_lreg_inode_header_3\tlreg;\n\tstruct squashfs_dir_inode_header_3\tdir;\n\tstruct squashfs_ldir_inode_header_3\tldir;\n\tstruct squashfs_ipc_inode_header_3\tipc;\n};\n\t\nstruct squashfs_dir_entry_3 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header_3 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_3 {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\n\ntypedef struct squashfs_super_block_3 squashfs_super_block_3;\ntypedef struct squashfs_dir_index_3 squashfs_dir_index_3;\ntypedef struct squashfs_base_inode_header_3 squashfs_base_inode_header_3;\ntypedef struct squashfs_ipc_inode_header_3 squashfs_ipc_inode_header_3;\ntypedef struct squashfs_dev_inode_header_3 squashfs_dev_inode_header_3;\ntypedef struct squashfs_symlink_inode_header_3 squashfs_symlink_inode_header_3;\ntypedef struct squashfs_reg_inode_header_3 squashfs_reg_inode_header_3;\ntypedef struct squashfs_lreg_inode_header_3 squashfs_lreg_inode_header_3;\ntypedef struct squashfs_dir_inode_header_3 squashfs_dir_inode_header_3;\ntypedef struct squashfs_ldir_inode_header_3 squashfs_ldir_inode_header_3;\ntypedef struct squashfs_dir_entry_3 squashfs_dir_entry_3;\ntypedef struct squashfs_dir_header_3 squashfs_dir_header_3;\ntypedef struct squashfs_fragment_entry_3 squashfs_fragment_entry_3;\ntypedef union squashfs_inode_header_3 squashfs_inode_header_3;\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block_3));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_3(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_3))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_3)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_3));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_3));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_3));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T_3(s, d) SQUASHFS_SWAP_LONG_LONGS_3(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_3));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_3(A)\t((A) * sizeof(struct squashfs_fragment_entry_3))\n\n#define SQUASHFS_FRAGMENT_INDEX_3(A)\t(SQUASHFS_FRAGMENT_BYTES_3(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_3(A)\t(SQUASHFS_FRAGMENT_BYTES_3(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_3(A)\t((SQUASHFS_FRAGMENT_BYTES_3(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_3(A)\t(SQUASHFS_FRAGMENT_INDEXES_3(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/*\n * definitions for structures on disk - layout 1.x\n */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\ntypedef union squashfs_inode_header_1 squashfs_inode_header_1;\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n/*\n * definitions for structures on disk - layout 2.x\n */\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS_3(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t((A) * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t4\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_IDS\t\t\t65536\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_MKFLAGS(noi, nod, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | \\\n\t\t(nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n#define SQUASHFS_LSYMLINK_TYPE\t\t10\n#define SQUASHFS_LBLKDEV_TYPE\t\t11\n#define SQUASHFS_LCHRDEV_TYPE\t\t12\n#define SQUASHFS_LFIFO_TYPE\t\t13\n#define SQUASHFS_LSOCKET_TYPE\t\t14\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* uid lookup table defines */\n#define SQUASHFS_ID_BYTES(A)\t((A) * sizeof(unsigned int))\n\n#define SQUASHFS_ID_BLOCK(A)\t\t(SQUASHFS_ID_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCK_OFFSET(A)\t\t(SQUASHFS_ID_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCKS(A)\t((SQUASHFS_ID_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCK_BYTES(A)\t(SQUASHFS_ID_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\n#define ZLIB_COMPRESSION\t1\n#define LZMA_COMPRESSION\t2\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned short\t\tcompression;\n\tunsigned short\t\tblock_log;\n\tunsigned short\t\tflags;\n\tunsigned short\t\tno_ids;\n\tunsigned short\t\ts_major;\n\tunsigned short\t\ts_minor;\n\tsquashfs_inode_t\troot_inode;\n\tlong long\t\tbytes_used;\n\tlong long\t\tid_table_start;\n\tlong long\t\txattr_table_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n};\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\tname[0];\n};\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned short\t\tinode_type;\t\\\n\tunsigned short\t\tmode;\t\\\n\tunsigned short\t\tuid;\t\t\\\n\tunsigned short\t\tguid;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n};\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n};\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\trdev;\n};\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n};\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned int\t\tblock_list[0];\n};\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tlong long\t\tfile_size;\n\tlong long\t\tsparse;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\txattr;\n\tunsigned int\t\tblock_list[0];\n};\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tfile_size;\n\tunsigned short\t\toffset;\n\tunsigned int\t\tparent_inode;\n};\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n\tunsigned short\t\ti_count;\n\tunsigned short\t\toffset;\n\tunsigned int\t\txattr;\n\tstruct squashfs_dir_index\tindex[0];\n};\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned short\t\toffset;\n\tshort\t\t\tinode_number;\n\tunsigned short\t\ttype;\n\tunsigned short\t\tsize;\n\tchar\t\t\tname[0];\n};\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n};\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tunused;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/squashfs_swap.h",
    "content": "#ifndef SQUASHFS_SWAP_H\n#define SQUASHFS_SWAP_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_swap.h\n */\n\n/*\n * macros to convert each stucture from big endian to little endian\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\nextern void swap_le16(unsigned short *, unsigned short *);\nextern void swap_le32(unsigned int *, unsigned int *);\nextern void swap_le64(long long *, long long *);\nextern void swap_le16_num(unsigned short *, unsigned short *, int);\nextern void swap_le32_num(unsigned int *, unsigned int *, int);\nextern void swap_le64_num(long long *, long long *, int);\nextern unsigned short inswap_le16(unsigned short);\nextern unsigned int inswap_le32(unsigned int);\nextern long long inswap_le64(long long);\nextern void inswap_le16_num(unsigned short *, int);\nextern void inswap_le32_num(unsigned int *, int);\nextern void inswap_le64_num(long long *, int);\n\n#define _SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##32(s, d, s_magic);\\\n\tSWAP_FUNC##32(s, d, inodes);\\\n\tSWAP_FUNC##32(s, d, mkfs_time);\\\n\tSWAP_FUNC##32(s, d, block_size);\\\n\tSWAP_FUNC##32(s, d, fragments);\\\n\tSWAP_FUNC##16(s, d, compression);\\\n\tSWAP_FUNC##16(s, d, block_log);\\\n\tSWAP_FUNC##16(s, d, flags);\\\n\tSWAP_FUNC##16(s, d, no_ids);\\\n\tSWAP_FUNC##16(s, d, s_major);\\\n\tSWAP_FUNC##16(s, d, s_minor);\\\n\tSWAP_FUNC##64(s, d, root_inode);\\\n\tSWAP_FUNC##64(s, d, bytes_used);\\\n\tSWAP_FUNC##64(s, d, id_table_start);\\\n\tSWAP_FUNC##64(s, d, xattr_table_start);\\\n\tSWAP_FUNC##64(s, d, inode_table_start);\\\n\tSWAP_FUNC##64(s, d, directory_table_start);\\\n\tSWAP_FUNC##64(s, d, fragment_table_start);\\\n\tSWAP_FUNC##64(s, d, lookup_table_start);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##32(s, d, index);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, size);\\\n}\n\n#define _SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n}\n\n#define _SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n}\n\n#define _SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##32(s, d, rdev);\\\n}\n\n#define _SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##32(s, d, symlink_size);\\\n}\n\n#define _SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, fragment);\\\n\tSWAP_FUNC##32(s, d, offset);\\\n\tSWAP_FUNC##32(s, d, file_size);\\\n}\n\n#define _SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##64(s, d, start_block);\\\n\tSWAP_FUNC##64(s, d, file_size);\\\n\tSWAP_FUNC##64(s, d, sparse);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##32(s, d, fragment);\\\n\tSWAP_FUNC##32(s, d, offset);\\\n\tSWAP_FUNC##32(s, d, xattr);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##16(s, d, file_size);\\\n\tSWAP_FUNC##16(s, d, offset);\\\n\tSWAP_FUNC##32(s, d, parent_inode);\\\n}\n\n#define _SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##32(s, d, file_size);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, parent_inode);\\\n\tSWAP_FUNC##16(s, d, i_count);\\\n\tSWAP_FUNC##16(s, d, offset);\\\n\tSWAP_FUNC##32(s, d, xattr);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, offset);\\\n\tSWAP_FUNC##S16(s, d, inode_number);\\\n\tSWAP_FUNC##16(s, d, type);\\\n\tSWAP_FUNC##16(s, d, size);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##32(s, d, count);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n}\n\n#define _SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##64(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, size);\\\n}\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d)\t\\\n\t\t\t_SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \\\n\t\t\t_SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#define SQUASHFS_INSWAP_SUPER_BLOCK(s) \\\n\t\t\t_SQUASHFS_SWAP_SUPER_BLOCK(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_INDEX(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INDEX(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_BASE_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_BASE_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_IPC_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_IPC_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DEV_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DEV_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_REG_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_REG_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LREG_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LREG_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LDIR_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_ENTRY(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_ENTRY(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s) \\\n\t\t\t_SQUASHFS_SWAP_FRAGMENT_ENTRY(s, s, INSWAP_LE)\n#define INSWAP_LE16(s, d, field)\t(s)->field = inswap_le16((s)->field)\n#define INSWAP_LE32(s, d, field)\t(s)->field = inswap_le32((s)->field)\n#define INSWAP_LE64(s, d, field)\t(s)->field = inswap_le64((s)->field)\n#define INSWAP_LES16(s, d, field) \\\n\t\t(s)->field = (short) inswap_le16((unsigned short) (s)->field)\n#define SQUASHFS_INSWAP_INODE_T(s) s = inswap_le64(s)\n#define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_ID_BLOCKS(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_SHORTS(s, n) inswap_le16_num(s, n)\n#define SQUASHFS_INSWAP_INTS(s, n) inswap_le32_num(s, n)\n#define SQUASHFS_INSWAP_LONG_LONGS(s, n) inswap_le64_num(s, n)\n#else\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d)\t\\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#define SQUASHFS_INSWAP_SUPER_BLOCK(s)\n#define SQUASHFS_INSWAP_DIR_INDEX(s)\n#define SQUASHFS_INSWAP_BASE_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_IPC_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DEV_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_REG_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LREG_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DIR_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DIR_ENTRY(s)\n#define SQUASHFS_INSWAP_DIR_HEADER(s)\n#define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s)\n#define SQUASHFS_INSWAP_INODE_T(s)\n#define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n)\n#define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n)\n#define SQUASHFS_INSWAP_ID_BLOCKS(s, n)\n#define SQUASHFS_INSWAP_SHORTS(s, n)\n#define SQUASHFS_INSWAP_INTS(s, n)\n#define SQUASHFS_INSWAP_LONG_LONGS(s, n)\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/swap.c",
    "content": "/*\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * swap.c\n */\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#if __BYTE_ORDER == __BIG_ENDIAN\nvoid swap_le16(unsigned short *src, unsigned short *dest)\n{\n\tunsigned char *s = (unsigned char *) src;\n\tunsigned char *d = (unsigned char *) dest;\n\n\td[0] = s[1];\n\td[1] = s[0];\n}\n\n\nvoid swap_le32(unsigned int *src, unsigned int *dest)\n{\n\tunsigned char *s = (unsigned char *) src;\n\tunsigned char *d = (unsigned char *) dest;\n\n\td[0] = s[3];\n\td[1] = s[2];\n\td[2] = s[1];\n\td[3] = s[0];\n}\n\n\nvoid swap_le64(long long *src, long long *dest)\n{\n\tunsigned char *s = (unsigned char *) src;\n\tunsigned char *d = (unsigned char *) dest;\n\n\td[0] = s[7];\n\td[1] = s[6];\n\td[2] = s[5];\n\td[3] = s[4];\n\td[4] = s[3];\n\td[5] = s[2];\n\td[6] = s[1];\n\td[7] = s[0];\n}\n\n\nunsigned short inswap_le16(unsigned short num)\n{\n\treturn (num >> 8) |\n\t\t((num & 0xff) << 8);\n}\n\n\nunsigned int inswap_le32(unsigned int num)\n{\n\treturn (num >> 24) |\n\t\t((num & 0xff0000) >> 8) |\n\t\t((num & 0xff00) << 8) |\n\t\t((num & 0xff) << 24);\n}\n\n\nlong long inswap_le64(long long n)\n{\n\tunsigned long long num = n;\n\n\treturn (num >> 56) |\n\t\t((num & 0xff000000000000LL) >> 40) |\n\t\t((num & 0xff0000000000LL) >> 24) |\n\t\t((num & 0xff00000000LL) >> 8) |\n\t\t((num & 0xff000000) << 8) |\n\t\t((num & 0xff0000) << 24) |\n\t\t((num & 0xff00) << 40) |\n\t\t((num & 0xff) << 56);\n}\n\n\n#define SWAP_LE_NUM(BITS, TYPE) \\\nvoid swap_le##BITS##_num(TYPE *s, TYPE *d, int n) \\\n{\\\n\tint i;\\\n\tfor(i = 0; i < n; i++, s++, d++)\\\n\t\tswap_le##BITS(s, d);\\\n}\n\nSWAP_LE_NUM(16, unsigned short)\nSWAP_LE_NUM(32, unsigned int)\nSWAP_LE_NUM(64, long long)\n\n#define INSWAP_LE_NUM(BITS, TYPE) \\\nvoid inswap_le##BITS##_num(TYPE *s, int n) \\\n{\\\n\tint i;\\\n\tfor(i = 0; i < n; i++)\\\n\t\ts[i] = inswap_le##BITS(s[i]);\\\n}\n\nINSWAP_LE_NUM(16, unsigned short)\nINSWAP_LE_NUM(32, unsigned int)\nINSWAP_LE_NUM(64, long long)\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/uncompress.c",
    "content": "/*\n * Copyright (c) 2009  Felix Fietkau <nbd@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * uncompress.c\n */\n\n\n\n#ifdef USE_LZMA\n#include <LzmaLib.h>\n#endif\n#include <zlib.h>\n#include \"squashfs_fs.h\"\n\n/* compression algorithm */\nint compression = ZLIB_COMPRESSION;\n\n\nint uncompress_wrapper(unsigned char *dest, unsigned long *dest_len,\n\tconst unsigned char *src, unsigned long src_len)\n{\n\tint res;\n\n#ifdef USE_LZMA\n\tif (compression == LZMA_COMPRESSION) {\n\t\tsize_t slen = src_len - LZMA_PROPS_SIZE;\n\t\tres = LzmaUncompress((unsigned char *)dest, dest_len,\n\t\t\t(const unsigned char *) src + LZMA_PROPS_SIZE, &slen,\n\t\t\t(const unsigned char *) src, LZMA_PROPS_SIZE);\n\t\tswitch(res) {\n\t\tcase SZ_OK:\n\t\t\tres = Z_OK;\n\t\t\tbreak;\n\t\tcase SZ_ERROR_MEM:\n\t\t\tres = Z_MEM_ERROR;\n\t\t\tbreak;\n\t\t}\n\t} else\n#endif\n\tres = uncompress(dest, dest_len, src, src_len);\n\treturn res;\n}\n\n\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/uncompress.h",
    "content": "/*\n * Copyright (c) 2009  Felix Fietkau <nbd@openwrt.org>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * uncompress.h\n */\n\n#ifdef USE_LZMA\n#include <LzmaLib.h>\n#endif\n\nextern int compression;\nextern int uncompress_wrapper(unsigned char *dest, unsigned long *dest_len,\n    const unsigned char *src, unsigned long src_len);\n\n\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/unsquash-1.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-1.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nvoid read_block_list_1(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tTRACE(\"read_block_list: blocks %d\\n\", blocks);\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS_3((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) |\n\t\t\t(SQUASHFS_COMPRESSED(block_size) ? 0 :\n\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nint read_fragment_table_1()\n{\n\tTRACE(\"read_fragment_table\\n\");\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_1 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"read_inode: inode table block %lld not found\\n\", start); \n\t\treturn NULL;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[(header.base.inode_type - 1) /\n\t\tSQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) %\n\t\t\tSQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n\n\ti.gid = header.base.guid == 15 ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\ti.sparse = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_1),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_1!\\n\",\n\t\t\t\theader.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_1(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\tif(((*i) = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes,\n\t\t\t\t\tsizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes,\n\t\t\t\t\tsizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc \"\n\t\t\t\t\t\t\"failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint read_uids_guids_1()\n{\n\tint res;\n\n\tTRACE(\"read_uids_guids: no_uids %d, no_guids %d\\n\", sBlk.no_uids,\n\t\tsBlk.no_guids);\n\n\tuid_table = malloc((sBlk.no_uids + sBlk.no_guids) *\n\t\tsizeof(unsigned int));\n\tif(uid_table == NULL) {\n\t\tERROR(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\t\treturn FALSE;\n\t}\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tres = read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t* sizeof(unsigned int), (char *) suid_table);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read uid/gid table\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_INTS_3(uid_table, suid_table,\n\t\t\tsBlk.no_uids + sBlk.no_guids);\n\t} else {\n\t\tres = read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t* sizeof(unsigned int), (char *) uid_table);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read uid/gid table\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/unsquash-2.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-2.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nstatic squashfs_fragment_entry_2 *fragment_table;\n\nvoid read_block_list_2(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tTRACE(\"read_block_list: blocks %d\\n\", blocks);\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS_3(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nint read_fragment_table_2()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.fragments, indexes,\n\t\tsBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn TRUE;\n\n\tfragment_table = malloc(sBlk.fragments *\n\t\tsizeof(squashfs_fragment_entry_2));\n\tif(fragment_table == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\t res = read_bytes(sBlk.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments),\n\t\t\t(char *) sfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index,\n\t\t\tsfragment_table_index, indexes);\n\t} else {\n\t\tres = read_bytes(sBlk.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments),\n\t\t\t(char *) fragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%x, length %d\\n\", i,\n\t\t\tfragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table block\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment),\n\t\t\t\t(&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment,\n\t\t\t\tsizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_2(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_2 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"read_inode: inode table block %lld not found\\n\", start); \n\t\treturn NULL;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr,\n\t\t\t\t\tsizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr,\n\t\t\t\t\tsizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_2),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_2!\\n\",\n\t\t\t\theader.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/unsquash-3.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-3.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nstatic squashfs_fragment_entry_3 *fragment_table;\n\nint read_fragment_table_3()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES_3(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.fragments, indexes,\n\t\tsBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = malloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry_3))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tres = read_bytes(sBlk.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.fragments),\n\t\t\t(char *) sfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_3(fragment_table_index,\n\t\t\tsfragment_table_index, indexes);\n\t} else {\n\t\tres = read_bytes(sBlk.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.fragments),\n\t\t\t(char *) fragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table block\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_3 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_3((&sfragment),\n\t\t\t\t(&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment,\n\t\t\t\tsizeof(squashfs_fragment_entry_3));\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_3(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_3 *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_3(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_3 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"read_inode: inode table block %lld not found\\n\", start); \n\t\treturn NULL;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_3 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_3(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_3));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_3 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_3(&header.dir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_3 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_3(&header.ldir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr,\n\t\t\t\t\tsizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_3 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_3(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log :\n\t\t\t\tinode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 1;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header_3 *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER_3(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log :\n\t\t\t\tinode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 1;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_3 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_3 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_3),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_3 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_3 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_3(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\",\n\t\t\t\theader.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_3(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header_3 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_3) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_3 *dire = (squashfs_dir_entry_3 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\tif((*i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_3 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_3(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_3 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes,\n\t\t\t\t\tsizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_3(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes,\n\t\t\t\t\tsizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc \"\n\t\t\t\t\t\t\"failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/unsquash-4.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-4.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n\nstatic struct squashfs_fragment_entry *fragment_table;\nstatic unsigned int *id_table;\n\nint read_fragment_table_4()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.fragments, indexes,\n\t\tsBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = malloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tres = read_bytes(sBlk.fragment_table_start,\n\t\tSQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments),\n\t\t(char *) fragment_table_index);\n\tif(res == FALSE) {\n\t\tERROR(\"read_fragment_table: failed to read fragment table \"\n\t\t\t\"index\\n\");\n\t\treturn FALSE;\n\t}\n\tSQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < sBlk.fragments; i++) \n\t\tSQUASHFS_INSWAP_FRAGMENT_ENTRY(&fragment_table[i]);\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_4(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_4(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"read_inode: inode table block %lld not found\\n\", start); \t\t\n\t\treturn NULL;\n\t}\n\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base,\n\t\t(squashfs_base_inode_header *) block_ptr);\n\n\ti.uid = (uid_t) id_table[header.base.uid];\n\ti.gid = (uid_t) id_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inode,\n\t\t\t\t(squashfs_dir_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inode,\n\t\t\t\t(squashfs_ldir_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode,\n\t\t\t\t(squashfs_reg_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log :\n\t\t\t\tinode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode,\n\t\t\t\t(squashfs_lreg_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log :\n\t\t\t\tinode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = inode->sparse != 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\tcase SQUASHFS_LSYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inode = &header.symlink;\n\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inode,\n\t\t\t\t(squashfs_symlink_inode_header *) block_ptr);\n\n\t\t\ti.symlink = malloc(inode->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header),\n\t\t\t\tinode->symlink_size);\n\t\t\ti.symlink[inode->symlink_size] = '\\0';\n\t\t\ti.data = inode->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE:\n \t\tcase SQUASHFS_LBLKDEV_TYPE:\n\t \tcase SQUASHFS_LCHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inode = &header.dev;\n\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inode,\n\t\t\t\t(squashfs_dev_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->rdev;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\tcase SQUASHFS_LFIFO_TYPE:\n\t\tcase SQUASHFS_LSOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\",\n\t\t\t\theader.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_4(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\tif((*i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, (squashfs_dir_header *)\n\t\t\t(directory_table + bytes));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, (squashfs_dir_entry *)\n\t\t\t\t(directory_table + bytes));\n\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc \"\n\t\t\t\t\t\t\"failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint read_uids_guids_4()\n{\n\tint res, i, indexes = SQUASHFS_ID_BLOCKS(sBlk.no_ids);\n\tlong long id_index_table[indexes];\n\n\tTRACE(\"read_uids_guids: no_ids %d\\n\", sBlk.no_ids);\n\n\tid_table = malloc(SQUASHFS_ID_BYTES(sBlk.no_ids));\n\tif(id_table == NULL) {\n\t\tERROR(\"read_uids_guids: failed to allocate id table\\n\");\n\t\treturn FALSE;\n\t}\n\n\tres = read_bytes(sBlk.id_table_start,\n\t\tSQUASHFS_ID_BLOCK_BYTES(sBlk.no_ids), (char *) id_index_table);\n\tif(res == FALSE) {\n\t\tERROR(\"read_uids_guids: failed to read id index table\\n\");\n\t\treturn FALSE;\n\t}\n\tSQUASHFS_INSWAP_ID_BLOCKS(id_index_table, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tres = read_block(id_index_table[i], NULL,\n\t\t\t((char *) id_table) + i * SQUASHFS_METADATA_SIZE);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read id table block\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_INTS(id_table, sBlk.no_ids);\n\n\treturn TRUE;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_swap.h\"\n#include \"squashfs_compat.h\"\n#include \"uncompress.h\"\n#include \"read_fs.h\"\n\nstruct cache *fragment_cache, *data_cache;\nstruct queue *to_reader, *to_deflate, *to_writer, *from_writer;\npthread_t *thread, *deflator_thread;\npthread_mutex_t\tfragment_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n\nstruct super_block sBlk;\nsquashfs_operations s_ops;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nunsigned int block_log;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE;\nint use_regex = FALSE;\nchar **created_inode;\nint root_process;\nint columns;\nint rotate = 0;\npthread_mutex_t\tscreen_mutex;\npthread_cond_t progress_wait;\nint progress = TRUE, progress_enabled = FALSE;\nunsigned int total_blocks = 0, total_files = 0, total_inodes = 0;\nunsigned int cur_blocks = 0;\nint inode_number = 1;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0}\n};\n\nvoid progress_bar(long long current, long long max, int columns);\nvoid update_progress_bar();\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tint hash = CALCULATE_HASH(entry->block);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->block)] =\n\t\t\tentry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(cache->free_list) {\n\t\tentry->free_next = cache->free_list;\n\t\tentry->free_prev = cache->free_list->free_prev;\n\t\tcache->free_list->free_prev->free_next = entry;\n\t\tcache->free_list->free_prev = entry;\n\t} else {\n\t\tcache->free_list = entry;\n\t\tentry->free_prev = entry->free_next = entry;\n\t}\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->free_prev == NULL && entry->free_next == NULL)\n\t\t/* not in free list */\n\t\treturn;\n\telse if(entry->free_prev == entry && entry->free_next == entry) {\n\t\t/* only this entry in the free list */\n\t\tcache->free_list = NULL;\n\t} else {\n\t\t/* more than one entry in the free list */\n\t\tentry->free_next->free_prev = entry->free_prev;\n\t\tentry->free_prev->free_next = entry->free_next;\n\t\tif(cache->free_list == entry)\n\t\t\tcache->free_list = entry->free_next;\n\t}\n\n\tentry->free_prev = entry->free_next = NULL;\n}\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\treturn NULL;\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct cache_entry *) * 65536);\n\tcache->wait_free = FALSE;\n\tcache->wait_pending = FALSE;\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\tpthread_cond_init(&cache->wait_for_pending, NULL);\n\n\treturn cache;\n}\n\n\nstruct cache_entry *cache_get(struct cache *cache, long long block, int size)\n{\n\t/*\n\t * Get a block out of the cache.  If the block isn't in the cache\n \t * it is added and queued to the reader() and deflate() threads for\n \t * reading off disk and decompression.  The cache grows until max_blocks\n \t * is reached, once this occurs existing discarded blocks on the free\n \t * list are reused\n \t */\n\tint hash = CALCULATE_HASH(block);\n\tstruct cache_entry *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->block == block)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/*\n \t\t *found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(cache, entry);\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t} else {\n\t\t/*\n \t\t * not in the cache\n\t\t *\n\t\t * first try to allocate new block\n\t\t */\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\tentry = malloc(sizeof(struct cache_entry));\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->data = malloc(cache->buffer_size);\n\t\t\tif(entry->data == NULL) {\n\t\t\t\tfree(entry);\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t} else {\n\t\t\t/*\n\t\t\t * try to get from free list\n\t\t\t */\n\t\t\twhile(cache->free_list == NULL) {\n\t\t\t\tcache->wait_free = TRUE;\n\t\t\t\tpthread_cond_wait(&cache->wait_for_free,\n\t\t\t\t\t&cache->mutex);\n\t\t\t}\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(cache, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t}\n\n\t\t/*\n\t\t * initialise block and insert into the hash table\n\t\t */\n\t\tentry->block = block;\n\t\tentry->size = size;\n\t\tentry->used = 1;\n\t\tentry->error = FALSE;\n\t\tentry->pending = TRUE;\n\t\tinsert_hash_table(cache, entry);\n\n\t\t/*\n\t\t * queue to read thread to read and ultimately (via the\n\t\t * decompress threads) decompress the buffer\n \t\t */\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t\tqueue_put(to_reader, entry);\n\t}\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\treturn NULL;\n}\n\n\t\nvoid cache_block_ready(struct cache_entry *entry, int error)\n{\n\t/*\n\t * mark cache entry as being complete, reading and (if necessary)\n \t * decompression has taken place, and the buffer is valid for use.\n \t * If an error occurs reading or decompressing, the buffer also \n \t * becomes ready but with an error...\n \t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\tentry->pending = FALSE;\n\tentry->error = error;\n\n\t/*\n\t * if the wait_pending flag is set, one or more threads may be waiting\n\t * on this buffer\n\t */\n\tif(entry->cache->wait_pending) {\n\t\tentry->cache->wait_pending = FALSE;\n\t\tpthread_cond_broadcast(&entry->cache->wait_for_pending);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_wait(struct cache_entry *entry)\n{\n\t/*\n\t * wait for this cache entry to become ready, when reading and (if\n\t * necessary) decompression has taken place\n\t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\twhile(entry->pending) {\n\t\tentry->cache->wait_pending = TRUE;\n\t\tpthread_cond_wait(&entry->cache->wait_for_pending,\n\t\t\t&entry->cache->mutex);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_put(struct cache_entry *entry)\n{\n\t/*\n\t * finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and is put onto the free list.  As it remains\n \t * accessible via the hash table it can be found getting a new lease of\n \t * life before it is reused.\n \t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tinsert_free_list(entry->cache, entry);\n\n\t\t/*\n\t\t * if the wait_free flag is set, one or more threads may be\n\t\t * waiting on this buffer\n\t\t */\n\t\tif(entry->cache->wait_free) {\n\t\t\tentry->cache->wait_free = FALSE;\n\t\t\tpthread_cond_broadcast(&entry->cache->wait_for_free);\n\t\t}\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\tif((user = getpwuid(inode->uid)) == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tif((group = getgrgid(inode->gid)) == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) -\n\t\t\t\tstrlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0,\n\t\t\t\tinode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) -\n\t\t\t\tstrlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \",\n\t\t\t\t(int) inode->data >> 8, (int) inode->data &\n\t\t\t\t0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1,\n\t\tt->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n\nint add_entry(struct hash_table_entry *hash_table[], long long start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], long long start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\tint res, count;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte,\n\t\tbytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = read(fd, buff + count, bytes - count);\n\t\tif(res < 1) {\n\t\t\tif(res == 0) {\n\t\t\t\tERROR(\"Read on filesystem failed because EOF\\n\");\n\t\t\t\treturn FALSE;\n\t\t\t} else if(errno != EINTR) {\n\t\t\t\tERROR(\"Read on filesystem failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn FALSE;\n\t\t\t} else\n\t\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start,\n\t\tSQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ?\n\t\t\"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tres = uncompress_wrapper((unsigned char *) block, &bytes,\n\t\t\t(const unsigned char *) buffer, c_byte);\n\t\tif(res != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"uncompress failed, unknown error \"\n\t\t\t\t\t\"%d\\n\", res);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\tERROR(\"read_block: failed to read block @0x%llx\\n\", start);\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start,\n\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte),\n\t\tSQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" :\n\t\t\"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\tgoto failed;\n\n\t\tres = uncompress_wrapper((unsigned char *) block, &bytes,\n\t\t\t(const unsigned char *) data, c_byte);\n\t\tif(res != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"uncompress failed, unknown error \"\n\t\t\t\t\t\"%d\\n\", res);\n\t\t\tgoto failed;\n\t\t}\n\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\n\t\treturn c_byte;\n\t}\n\nfailed:\n\tERROR(\"read_data_block: failed to read block @0x%llx, size %d\\n\", start,\n\t\tsize);\n\treturn FALSE;\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\tTRACE(\"uncompress_inode_table: start %lld, end %lld\\n\", start, end);\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory \"\n\t\t\t\t\"in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tres = read_block(start, &start, inode_table + bytes);\n\t\tif(res == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read \"\n\t\t\t\t\"block \\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time,\n\tunsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids \"\n\t\t\t\t\"on %s, because %s\\n\", pathname,\n\t\t\t\tstrerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint write_bytes(int fd, char *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = write(fd, buff + count, bytes - count);\n\t\tif(res == -1) {\n\t\t\tif(errno != EINTR) {\n\t\t\t\tERROR(\"Write on output file failed because \"\n\t\t\t\t\t\"%s\\n\", strerror(errno));\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data = NULL;\n\nint write_block(int file_fd, char *buffer, int size, int hole, int sparse)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(sparse && lseek_broken == FALSE) {\n\t\t\t int error = lseek(file_fd, off, SEEK_CUR);\n\t\t\t if(error == -1)\n\t\t\t\t/* failed to seek beyond end of file */\n\t\t\t\tlseek_broken = TRUE;\n\t\t}\n\n\t\tif((sparse == FALSE || lseek_broken) && zero_data == NULL) {\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc \"\n\t\t\t\t\t\"zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t}\n\n\t\tif(sparse == FALSE || lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size :\n\t\t\t\t\thole;\n\t\t\t\tif(write_bytes(file_fd, zero_data, avail_bytes)\n\t\t\t\t\t\t== -1)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t}\n\n\tif(write_bytes(file_fd, buffer, size) == -1)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\nint write_file(struct inode *inode, char *pathname)\n{\n\tunsigned int file_fd, i;\n\tunsigned int *block_list;\n\tint file_end = inode->data / block_size;\n\tlong long start = inode->start;\n\tstruct squashfs_file *file;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", inode->blocks);\n\n\tfile_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0),\n\t\t(mode_t) inode->mode & 0777);\n\tif(file_fd == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif((block_list = malloc(inode->blocks * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc block list\\n\");\n\n\ts_ops.read_block_list(block_list, inode->block_ptr, inode->blocks);\n\n\tif((file = malloc(sizeof(struct squashfs_file))) == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\n\t/*\n\t * the writer thread is queued a squashfs_file structure describing the\n \t * file.  If the file has one or more blocks or a fragments they are\n \t * queued separately (references to blocks in the cache).\n \t */\n\tfile->fd = file_fd;\n\tfile->file_size = inode->data;\n\tfile->mode = inode->mode;\n\tfile->gid = inode->gid;\n\tfile->uid = inode->uid;\n\tfile->time = inode->time;\n\tfile->pathname = strdup(pathname);\n\tfile->blocks = inode->blocks + (inode->frag_bytes > 0);\n\tfile->sparse = inode->sparse;\n\tqueue_put(to_writer, file);\n\n\tfor(i = 0; i < inode->blocks; i++) {\n\t\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\tblock->offset = 0;\n\t\tblock->size = i == file_end ? inode->data & (block_size - 1) :\n\t\t\tblock_size;\n\t\tif(block_list[i] == 0) /* sparse file */\n\t\t\tblock->buffer = NULL;\n\t\telse {\n\t\t\tblock->buffer = cache_get(data_cache, start,\n\t\t\t\tblock_list[i]);\n\t\t\tif(block->buffer == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_file: cache_get failed\\n\");\n\t\t\tstart += c_byte;\n\t\t}\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tif(inode->frag_bytes) {\n\t\tint size;\n\t\tlong long start;\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\ts_ops.read_fragment(inode->fragment, &start, &size);\n\t\tblock->buffer = cache_get(fragment_cache, start, size);\n\t\tif(block->buffer == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: cache_get failed\\n\");\n\t\tblock->offset = inode->offset;\n\t\tblock->size = inode->frag_bytes;\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tfree(block_list);\n\treturn TRUE;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, \"\n\t\t\t\t\"because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, \"\n\t\t\t\t\"blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i, pathname))\n\t\t\t\tfile_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %lld\\n\",\n\t\t\t\ti->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink \"\n\t\t\t\t\t\"%s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change \"\n\t\t\t\t\t\t\"uid and gids on %s, because \"\n\t\t\t\t\t\t\"%s\\n\", pathname,\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%llx\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\t\tmakedev((i->data >> 8) & 0xff,\n\t\t\t\t\t\ti->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create \"\n\t\t\t\t\t\t\"%s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid,\n\t\t\t\t\ti->gid, i->time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s \"\n\t\t\t\t\t\"device %s, because you're not \"\n\t\t\t\t\t\"superuser!\\n\", chrdev ? \"character\" :\n\t\t\t\t\t\"block\", pathname);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, \"\n\t\t\t\t\t\"because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid,\n\t\t\t\ti->time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\",\n\t\t\t\ti->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\tTRACE(\"uncompress_directory_table: start %lld, end %lld\\n\", start, end);\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of \"\n\t\t\t\t\"memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\",\n\t\t\t\tstart);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tres = read_block(start, &start, directory_table + bytes);\n\t\tif(res == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to \"\n\t\t\t\t\"read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/*\n\t\t * allocate new name entry\n\t\t */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) *\n\t\t\tsizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname,\n\t\t\t\tREG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, \"\n\t\t\t\t\t\"because %s\\n\", targname, alltarget,\n\t\t\t\t\tstr);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/*\n\t\t\t * at leaf pathname component\n\t\t\t*/\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/*\n\t\t\t * recurse adding child components\n\t\t\t */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/*\n\t\t * existing matching entry\n\t\t */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/*\n\t\t\t * No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing extract which subsumes\n\t\t\t * the extract currently being added, in which case stop\n\t\t\t * adding components\n\t\t\t */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/*\n\t\t\t * at leaf pathname component and child components exist\n\t\t\t * from more specific extracts, delete as they're\n\t\t\t * subsumed by this extract\n\t\t\t */\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/*\n\t\t\t * recurse adding child components\n\t\t\t */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) +\n\t\t(paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0,\n\t\t\t\tNULL, 0) == 0 : fnmatch(path->name[i].name,\n\t\t\t\tname, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) ==\n\t\t\t\t0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/*\n\t\t\t\t * match on a leaf component, any subdirectories\n\t\t\t\t * will implicitly match, therefore return an\n\t\t\t\t * empty new search set\n\t\t\t\t */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/*\n\t\t\t\t * match on a non-leaf component, add any\n\t\t\t\t * subdirectories to the new set of\n\t\t\t\t * subdirectories to scan for this name\n\t\t\t\t */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/*\n\t\t * no matching names found, delete empty search set, and return\n\t\t * FALSE\n\t\t */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/*\n\t* one or more matches with sub-directories found (no leaf matches),\n\t* return new search set and return TRUE\n\t*/\n\treturn TRUE;\n\nempty_set:\n\t/*\n\t * found matching leaf exclude, return empty search set and return TRUE\n\t */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nint pre_scan(char *parent_name, unsigned int start_block, unsigned int offset,\n\tstruct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(dir == NULL) {\n\t\tERROR(\"pre_scan: Failed to read directory %s (%x:%x)\\n\",\n\t\t\tparent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"pre_scan: name %s, start_block %d, offset %d, type %d\\n\",\n\t\t\tname, start_block, offset, type);\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tpre_scan(parent_name, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif(type == SQUASHFS_FILE_TYPE ||\n\t\t\t\t\ttype == SQUASHFS_LREG_TYPE) {\n\t\t\t\tif((i = s_ops.read_inode(start_block, offset))\n\t\t\t\t\t\t== NULL) {\n\t\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(created_inode[i->inode_number - 1] == NULL) {\n\t\t\t\t\tcreated_inode[i->inode_number - 1] =\n\t\t\t\t\t\t(char *) i;\n\t\t\t\t\ttotal_blocks += (i->data +\n\t\t\t\t\t\t(block_size - 1)) >> block_log;\n\t\t\t\t}\n\t\t\t\ttotal_files ++;\n\t\t\t}\n\t\t\ttotal_inodes ++;\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tsquashfs_closedir(dir);\n\n\treturn TRUE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset,\n\tstruct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\",\n\t\t\tparent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(parent_name, i);\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 &&\n\t\t\t(!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\",\n\t\t\tparent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\",\n\t\t\tname, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly) {\n\t\t\t\tcreate_inode(pathname, i);\n\t\t\t\tupdate_progress_bar();\n\t\t\t\t}\n\n\t\t\tif(i->type == SQUASHFS_SYMLINK_TYPE ||\n\t\t\t\t\ti->type == SQUASHFS_LSYMLINK_TYPE)\n\t\t\t\tfree(i->symlink);\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tif(!lsonly)\n\t\tset_attributes(parent_name, dir->mode, dir->uid, dir->guid,\n\t\t\tdir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %sSQUASHFS %d:%d superblock on %s.\\n\",\n\t\tsBlk.s_major == 4 ? \"\" : swap ? \"little endian \" :\n\t\t\"big endian \", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tprintf(\"Found a valid %sSQUASHFS %d:%d superblock on %s.\\n\",\n\t\tsBlk.s_major == 4 ? \"\" : swap ? \"big endian \" :\n\t\t\"little endian \", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str :\n\t\t\"failed to get time\\n\");\n\tprintf(\"Filesystem is %sexportable via NFS\\n\",\n\t\tSQUASHFS_EXPORTABLE(sBlk.flags) ? \"\" : \"not \");\n\n\tprintf(\"Inodes are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tif(sBlk.s_major > 1 && !SQUASHFS_NO_FRAGMENTS(sBlk.flags))\n\t\tprintf(\"Fragments are %scompressed\\n\",\n\t\t\tSQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" :\n\t\t\t\"\");\n\tprintf(\"Check data is %spresent in the filesystem\\n\",\n\t\tSQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not \");\n\tif(sBlk.s_major > 1) {\n\t\tprintf(\"Fragments are %spresent in the filesystem\\n\",\n\t\t\tSQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not \" : \"\");\n\t\tprintf(\"Always_use_fragments option is %sspecified\\n\",\n\t\t\tSQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not \");\n\t} else\n\t\tprintf(\"Fragments are not supported by the filesystem\\n\");\n\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\",\n\t\t\tSQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\",\n\t\tsBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tprintf(\"Block size %d\\n\", sBlk.block_size);\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.fragments);\n\tprintf(\"Number of inodes %d\\n\", sBlk.inodes);\n\tif(sBlk.s_major == 4)\n\t\tprintf(\"Number of ids %d\\n\", sBlk.no_ids);\n\telse {\n\t\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\t\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\t}\n\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\",\n\t\tsBlk.directory_table_start);\n\tif(sBlk.s_major == 4)\n\t\tTRACE(\"sBlk.id_table_start 0x%llx\\n\", sBlk.id_table_start);\n\telse {\n\t\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\t\tTRACE(\"sBlk.guid_start 0x%llx\\n\", sBlk.guid_start);\n\t}\n\tif(sBlk.s_major > 1)\n\t\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\",\n\t\t\tsBlk.fragment_table_start);\n}\n\n\nint read_super(char *source)\n{\n\tsquashfs_super_block_3 sBlk_3;\n\tsquashfs_super_block sBlk_4;\n\n\t/*\n\t * Try to read a Squashfs 4 superblock\n\t */\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block),\n\t\t(char *) &sBlk_4);\n\tswap = sBlk_4.s_magic != SQUASHFS_MAGIC;\n\tSQUASHFS_INSWAP_SUPER_BLOCK(&sBlk_4);\n\n\tif(sBlk_4.s_magic == SQUASHFS_MAGIC && sBlk_4.s_major == 4 &&\n\t\t\tsBlk_4.s_minor == 0) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir_4;\n\t\ts_ops.read_fragment = read_fragment_4;\n\t\ts_ops.read_fragment_table = read_fragment_table_4;\n\t\ts_ops.read_block_list = read_block_list_2;\n\t\ts_ops.read_inode = read_inode_4;\n\t\ts_ops.read_uids_guids = read_uids_guids_4;\n\t\tmemcpy(&sBlk, &sBlk_4, sizeof(sBlk_4));\n\t\tgoto done;\n\t}\n\n\t/*\n \t * Not a Squashfs 4 superblock, try to read a squashfs 3 superblock\n \t * (compatible with 1 and 2 filesystems)\n \t */\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block_3),\n\t\t(char *) &sBlk_3);\n\n\t/*\n\t * Check it is a SQUASHFS superblock\n\t */\n\tswap = 0;\n\tif(sBlk_3.s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk_3.s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block_3 sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem \"\n\t\t\t\t\"on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK_3(&sblk, &sBlk_3);\n\t\t\tmemcpy(&sBlk_3, &sblk, sizeof(squashfs_super_block_3));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n\t\t\t\tsource);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\tsBlk.s_magic = sBlk_3.s_magic;\n\tsBlk.inodes = sBlk_3.inodes;\n\tsBlk.mkfs_time = sBlk_3.mkfs_time;\n\tsBlk.block_size = sBlk_3.block_size;\n\tsBlk.fragments = sBlk_3.fragments;\n\tsBlk.block_log = sBlk_3.block_log;\n\tsBlk.flags = sBlk_3.flags;\n\tsBlk.s_major = sBlk_3.s_major;\n\tsBlk.s_minor = sBlk_3.s_minor;\n\tsBlk.root_inode = sBlk_3.root_inode;\n\tsBlk.bytes_used = sBlk_3.bytes_used;\n\tsBlk.inode_table_start = sBlk_3.inode_table_start;\n\tsBlk.directory_table_start = sBlk_3.directory_table_start;\n\tsBlk.fragment_table_start = sBlk_3.fragment_table_start;\n\tsBlk.lookup_table_start = sBlk_3.lookup_table_start;\n\tsBlk.no_uids = sBlk_3.no_uids;\n\tsBlk.no_guids = sBlk_3.no_guids;\n\tsBlk.uid_start = sBlk_3.uid_start;\n\tsBlk.guid_start = sBlk_3.guid_start;\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 1 || sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk_3.bytes_used_2;\n\t\tsBlk.uid_start = sBlk_3.uid_start_2;\n\t\tsBlk.guid_start = sBlk_3.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk_3.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk_3.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s_major == 1) {\n\t\t\tsBlk.block_size = sBlk_3.block_size_1;\n\t\t\tsBlk.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_1;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t\t} else {\n\t\t\tsBlk.fragment_table_start =\n\t\t\t\tsBlk_3.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_1;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list_2;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t\t}\n\t} else if(sBlk.s_major == 3) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir_3;\n\t\ts_ops.read_fragment = read_fragment_3;\n\t\ts_ops.read_fragment_table = read_fragment_table_3;\n\t\ts_ops.read_block_list = read_block_list_2;\n\t\ts_ops.read_inode = read_inode_3;\n\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s_major,\n\t\t\tsBlk.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\ndone:\n\tcompression = sBlk.compression;\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tif((fd = fopen(filename, \"r\")) == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename,\n\t\t\tstrerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n/*\n * reader thread.  This thread processes read requests queued by the\n * cache_get() routine.\n */\nvoid *reader(void *arg)\n{\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_reader);\n\t\tint res = read_bytes(entry->block,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size),\n\t\t\tentry->data);\n\n\t\tif(res && SQUASHFS_COMPRESSED_BLOCK(entry->size))\n\t\t\t/*\n\t\t\t * queue successfully read block to the deflate\n\t\t\t * thread(s) for further processing\n \t\t\t */\n\t\t\tqueue_put(to_deflate, entry);\n\t\telse\n\t\t\t/*\n\t\t\t * block has either been successfully read and is\n\t\t\t * uncompressed, or an error has occurred, clear pending\n\t\t\t * flag, set error appropriately, and wake up any\n\t\t\t * threads waiting on this buffer\n\t\t\t */\n\t\t\tcache_block_ready(entry, !res);\n\t}\n}\n\n\n/*\n * writer thread.  This processes file write requests queued by the\n * write_file() routine.\n */\nvoid *writer(void *arg)\n{\n\tint i;\n\n\twhile(1) {\n\t\tstruct squashfs_file *file = queue_get(to_writer);\n\t\tint file_fd;\n\t\tint hole = 0;\n\t\tint failed = FALSE;\n\t\tint error;\n\n\t\tif(file == NULL) {\n\t\t\tqueue_put(from_writer, NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\tTRACE(\"writer: regular file, blocks %d\\n\", file->blocks);\n\n\t\tfile_fd = file->fd;\n\n\t\tfor(i = 0; i < file->blocks; i++, cur_blocks ++) {\n\t\t\tstruct file_entry *block = queue_get(to_writer);\n\n\t\t\tif(block->buffer == 0) { /* sparse file */\n\t\t\t\thole += block->size;\n\t\t\t\tfree(block);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcache_block_wait(block->buffer);\n\n\t\t\tif(block->buffer->error)\n\t\t\t\tfailed = TRUE;\n\n\t\t\tif(failed)\n\t\t\t\tcontinue;\n\n\t\t\terror = write_block(file_fd, block->buffer->data +\n\t\t\t\tblock->offset, block->size, hole, file->sparse);\n\n\t\t\tif(error == FALSE) {\n\t\t\t\tERROR(\"writer: failed to write data block %d\\n\",\n\t\t\t\t\ti);\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\n\t\t\thole = 0;\n\t\t\tcache_block_put(block->buffer);\n\t\t\tfree(block);\n\t\t}\n\n\t\tif(hole && failed == FALSE) {\n\t\t\t/*\n\t\t\t * corner case for hole extending to end of file\n\t\t\t */\n\t\t\tif(file->sparse == FALSE ||\n\t\t\t\t\tlseek(file_fd, hole, SEEK_CUR) == -1) {\n\t\t\t\t/*\n\t\t\t\t * for files which we don't want to write\n\t\t\t\t * sparsely, or for broken lseeks which cannot\n\t\t\t\t * seek beyond end of file, write_block will do\n\t\t\t\t * the right thing\n\t\t\t\t */\n\t\t\t\thole --;\n\t\t\t\tif(write_block(file_fd, \"\\0\", 1, hole,\n\t\t\t\t\t\tfile->sparse) == FALSE) {\n\t\t\t\t\tERROR(\"writer: failed to write sparse \"\n\t\t\t\t\t\t\"data block\\n\");\n\t\t\t\t\tfailed = TRUE;\n\t\t\t\t}\n\t\t\t} else if(ftruncate(file_fd, file->file_size) == -1) {\n\t\t\t\tERROR(\"writer: failed to write sparse data \"\n\t\t\t\t\t\"block\\n\");\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\t\t}\n\n\t\tclose(file_fd);\n\t\tif(failed == FALSE)\n\t\t\tset_attributes(file->pathname, file->mode, file->uid,\n\t\t\t\tfile->gid, file->time, force);\n\t\telse {\n\t\t\tERROR(\"Failed to write %s, skipping\\n\", file->pathname);\n\t\t\tunlink(file->pathname);\n\t\t}\n\t\tfree(file->pathname);\n\t\tfree(file);\n\n\t}\n}\n\n\n/*\n * decompress thread.  This decompresses buffers queued by the read thread\n */\nvoid *deflator(void *arg)\n{\n\tchar tmp[block_size];\n\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_deflate);\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\n\t\tres = uncompress_wrapper((unsigned char *) tmp, &bytes,\n\t\t\t(const unsigned char *) entry->data,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size));\n\n\t\tif(res != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"uncompress failed, not enough\"\n\t\t\t\t\t\"memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"uncompress failed, not enough \"\n\t\t\t\t\t\"room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"uncompress failed, unknown error \"\n\t\t\t\t\t\"%d\\n\", res);\n\t\t} else\n\t\t\tmemcpy(entry->data, tmp, bytes);\n\n\t\t/*\n\t\t * block has been either successfully decompressed, or an error\n \t\t * occurred, clear pending flag, set error appropriately and\n \t\t * wake up any threads waiting on this block\n \t\t */ \n\t\tcache_block_ready(entry, res != Z_OK);\n\t}\n}\n\n\nvoid *progress_thread(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&screen_mutex);\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) *\n\t\t\t1000;\n\t\tpthread_cond_timedwait(&progress_wait, &screen_mutex,\n\t\t\t&timespec);\n\t\tif(progress_enabled)\n\t\t\tprogress_bar(sym_count + dev_count +\n\t\t\t\tfifo_count + cur_blocks, total_inodes -\n\t\t\t\ttotal_files + total_blocks, columns);\n\t}\n}\n\n\nvoid initialise_threads(int fragment_buffer_size, int data_buffer_size)\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\tint all_buffers_size = fragment_buffer_size + data_buffer_size;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\"\n\t\t\t\"\\n\");\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  \"\n\t\t\t\t\"Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((3 + processors) * sizeof(pthread_t))) == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[3];\n\n\tto_reader = queue_init(all_buffers_size);\n\tto_deflate = queue_init(all_buffers_size);\n\tto_writer = queue_init(1000);\n\tfrom_writer = queue_init(1);\n\tfragment_cache = cache_init(block_size, fragment_buffer_size);\n\tdata_cache = cache_init(block_size, data_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&thread[2], NULL, progress_thread, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) !=\n\t\t\t\t 0)\n\t\t\tEXIT_UNSQUASH(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel unsquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\"\n\t\t\t\"\\n\");\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid update_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits = floor(log10(max)) + 1;\n\tint used = max_digits * 2 + 11;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\tstatic int tty = -1;\n\n\tif((current > max) || (columns - used < 0))\n\t\treturn;\n\n\tif(tty == -1)\n\t\ttty = isatty(STDOUT_FILENO);\n\tif(!tty) {\n\t\tstatic long long previous = -1;\n\n\t\t/* Updating much more frequently than this results in huge\n\t\t * log files. */\n\t\tif((current % 100) != 0 && current != max)\n\t\t\treturn;\n\t\t/* Don't update just to rotate the spinner. */\n\t\tif(current == previous)\n\t\t\treturn;\n\t\tprevious = current;\n\t}\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 4.0 (2009/04/05)\\n\");\\\n\tprintf(\"copyright (C) 2009 Phillip Lougher <phillip@lougher.demon.co.uk>\"\\\n\t\t\"\\n\\n\");\\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\"\\\n\t\t\"\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\"\\\n\t\t\"\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\"\\\n\t\t\"\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\"\\\n\t\t\"\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tint n;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\tint fragment_buffer_size = FRAGMENT_BUFFER_DEFAULT;\n\tint data_buffer_size = DATA_BUFFER_DEFAULT;\n\tchar *b;\n\tstruct winsize winsize;\n\n\tpthread_mutex_init(&screen_mutex, NULL);\n\troot_process = geteuid() == 0;\n\tif(root_process)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-n\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-processors\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-p\") == 0) {\n\t\t\tif((++i == argc) || \n\t\t\t\t\t(processors = strtol(argv[i], &b, 10),\n\t\t\t\t\t*b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid \"\n\t\t\t\t\t\"processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-data-queue\") == 0 ||\n\t\t\t\t\t strcmp(argv[i], \"-da\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(data_buffer_size = strtol(argv[i], &b,\n\t\t\t\t\t 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -data-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(data_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -data-queue should be 1 Mbyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-frag-queue\") == 0 ||\n\t\t\t\t\tstrcmp(argv[i], \"-fr\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(fragment_buffer_size = strtol(argv[i],\n\t\t\t\t\t &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -frag-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragment_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -frag-queue should be 1 Mbyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-r\") == 0)\n\t\t\tuse_regex = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(lsonly || info)\n\t\tprogress = FALSE;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or \"\n\t\t\t\t\"files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and \"\n\t\t\t\t\"copyright information\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, \"\n\t\t\t\t\"default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-n[o-progress]\\t\\tdon't display the progress \"\n\t\t\t\t\"bar\\n\");\n\t\t\tERROR(\"\\t-p[rocessors] <number>\\tuse <number> \"\n\t\t\t\t\"processors.  By default will use\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tnumber of processors available\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are \"\n\t\t\t\t\"unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are \"\n\t\t\t\t\"unsquashed with file\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file \"\n\t\t\t\t\"attributes (like\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then \"\n\t\t\t\t\"overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock \"\n\t\t\t\t\"information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or \"\n\t\t\t\t\"files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-da[ta-queue] <size>\\tSet data queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d\\n\\t\\t\\t\\tMbytes\\n\",\n\t\t\t\tDATA_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-fr[ag-queue] <size>\\tSet fagment queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d\\n\\t\\t\\t\\t Mbytes\\n\",\n\t\t\t\tFRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX \"\n\t\t\t\t\"regular expressions\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\trather than use the default shell \"\n\t\t\t\t\"wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i],\n\t\t\tstrerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tblock_size = sBlk.block_size;\n\tblock_log = sBlk.block_log;\n\n\tfragment_buffer_size <<= 20 - block_log;\n\tdata_buffer_size <<= 20 - block_log;\n\tinitialise_threads(fragment_buffer_size, data_buffer_size);\n\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate data\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tif(s_ops.read_uids_guids() == FALSE)\n\t\tEXIT_UNSQUASH(\"failed to uid/gid table\\n\");\n\n\tif(s_ops.read_fragment_table() == FALSE)\n\t\tEXIT_UNSQUASH(\"failed to read fragment table\\n\");\n\n\tuncompress_inode_table(sBlk.inode_table_start,\n\t\tsBlk.directory_table_start);\n\n\tuncompress_directory_table(sBlk.directory_table_start,\n\t\tsBlk.fragment_table_start);\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tpre_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode),\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\tinode_number = 1;\n\n\tprintf(\"%d inodes (%d blocks) to write\\n\\n\", total_inodes,\n\t\ttotal_inodes - total_files + total_blocks);\n\n\tif(progress)\n\t\tenable_progress_bar();\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode),\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tqueue_put(to_writer, NULL);\n\tqueue_get(from_writer);\n\n\tif(progress) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(sym_count + dev_count + fifo_count + cur_blocks,\n\t\t\ttotal_inodes - total_files + total_blocks, columns);\n\t}\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-lzma/unsquashfs.h",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs.h\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n#include <signal.h>\n#include <pthread.h>\n#include <math.h>\n#include <sys/ioctl.h>\n#include <sys/time.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"global.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\t\tprintf(\"\\n\"); \\\n\t\t\t\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\n/*\n * Unified superblock containing fields for all superblocks\n */\nstruct super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tmkfs_time;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned short\t\tcompression;\n\tunsigned short\t\tblock_log;\n\tunsigned short\t\tflags;\n\tunsigned short\t\tno_ids;\n\tunsigned short\t\ts_major;\n\tunsigned short\t\ts_minor;\n\tsquashfs_inode_t\troot_inode;\n\tlong long\t\tbytes_used;\n\tlong long\t\tid_table_start;\n\tlong long\t\txattr_table_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n\t/* fields only used by squashfs 3 and earlier layouts */\n\tunsigned int\t\tno_uids;\n\tunsigned int\t\tno_guids;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n};\n\nstruct hash_table_entry {\n\tlong long\tstart;\n\tint\t\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar *symlink;\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n\tchar sparse;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(unsigned int block_start, unsigned int offset, struct inode **i);\n\tvoid (*read_fragment)(unsigned int fragment, long long *start_block, int *size);\n\tint (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, char *block_ptr, int blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block, unsigned int offset);\n\tint (*read_uids_guids)();\n} squashfs_operations;\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tint\twait_free;\n\tint\twait_pending;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tpthread_cond_t wait_for_pending;\n\tstruct cache_entry *free_list;\n\tstruct cache_entry *hash_table[65536];\n};\n\n/* struct describing a cache entry passed between threads */\nstruct cache_entry {\n\tstruct cache *cache;\n\tlong long block;\n\tint\tsize;\n\tint\tused;\n\tint error;\n\tint\tpending;\n\tstruct cache_entry *hash_next;\n\tstruct cache_entry *hash_prev;\n\tstruct cache_entry *free_next;\n\tstruct cache_entry *free_prev;\n\tchar *data;\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\tsize;\n\tint\treadp;\n\tint\twritep;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t empty;\n\tpthread_cond_t full;\n\tvoid **data;\n};\n\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 256\n/* default size of data buffer in Mbytes */\n#define DATA_BUFFER_DEFAULT 256\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\nstruct file_entry {\n\tint offset;\n\tint size;\n\tstruct cache_entry *buffer;\n};\n\n\nstruct squashfs_file {\n\tint fd;\n\tint blocks;\n\tlong long file_size;\n\tint mode;\n\tuid_t uid;\n\tgid_t gid;\n\ttime_t time;\n\tchar *pathname;\n\tchar sparse;\n};\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\n/* globals */\nextern struct super_block sBlk;\nextern squashfs_operations s_ops;\nextern int swap;\nextern char *inode_table, *directory_table;\nextern struct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nextern unsigned int *uid_table, *guid_table;\nextern pthread_mutex_t screen_mutex;\nextern int progress_enabled;\nextern int inode_number;\nextern int lookup_type[];\n\n/* unsquashfs.c */\nextern int lookup_entry(struct hash_table_entry **, long long);\nextern int read_bytes(long long, int, char *);\nextern int read_block(long long, long long *, char *);\n\n/* unsquash-1.c */\nextern void read_block_list_1(unsigned int *, char *, int);\nextern int read_fragment_table_1();\nextern struct inode *read_inode_1(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_1(unsigned int, unsigned int, struct inode **);\nextern int read_uids_guids_1();\n\n/* unsquash-2.c */\nextern void read_block_list_2(unsigned int *, char *, int);\nextern int read_fragment_table_2();\nextern void read_fragment_2(unsigned int, long long *, int *);\nextern struct inode *read_inode_2(unsigned int, unsigned int);\n\n/* unsquash-3.c */\nextern int read_fragment_table_3();\nextern void read_fragment_3(unsigned int, long long *, int *);\nextern struct inode *read_inode_3(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_3(unsigned int, unsigned int, struct inode **);\n\n/* unsquash-4.c */\nextern int read_fragment_table_4();\nextern void read_fragment_4(unsigned int, long long *, int *);\nextern struct inode *read_inode_4(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_4(unsigned int, unsigned int, struct inode **);\nextern int read_uids_guids_4();\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/Makefile",
    "content": "#\n# Building LZMA support\n# Download LZMA sdk (4.65 used in development, other versions may work),\n# set LZMA_DIR to unpacked source, and uncomment next line\nLZMA_SUPPORT = 1\nLZMA_DIR = ./lzma\n#LZMA_DIR = ../../lzma465\n#LZMA_DIR = ../../LZMA/lzma465\nCC=gcc\n\n#Compression default.\nCOMP_DEFAULT = gzip\n\nINCLUDEDIR = -I.\nINSTALL_DIR = /usr/local/bin\n\nMKSQUASHFS_OBJS = mksquashfs.o read_fs.o sort.o swap.o pseudo.o compressor.o \\\n\tgzip_wrapper.o\n\nUNSQUASHFS_OBJS = unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o \\\n\tunsquash-4.o swap.o compressor.o gzip_wrapper.o\n\nCFLAGS = $(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \\\n\t-D_GNU_SOURCE -DCOMP_DEFAULT=\\\"$(COMP_DEFAULT)\\\" -O2 -Wall\n\nifdef LZMA_SUPPORT\nLZMA_OBJS = $(LZMA_DIR)/C/Alloc.o $(LZMA_DIR)/C/LzFind.o \\\n\t$(LZMA_DIR)/C/LzmaDec.o $(LZMA_DIR)/C/LzmaEnc.o $(LZMA_DIR)/C/LzmaLib.o\nINCLUDEDIR += -I$(LZMA_DIR)/C\nCFLAGS += -DLZMA_SUPPORT\nMKSQUASHFS_OBJS += lzma_wrapper.o $(LZMA_OBJS)\nUNSQUASHFS_OBJS += lzma_wrapper.o $(LZMA_OBJS)\nendif\n\n.PHONY: all\nall: mksquashfs unsquashfs\n\nmksquashfs: $(MKSQUASHFS_OBJS)\n\t$(CC) $(MKSQUASHFS_OBJS) -lz -lpthread -lm -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h \\\n\tsquashfs_swap.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h squashfs_swap.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nswap.o: swap.c\n\npseudo.o: pseudo.c pseudo.h\n\ncompressor.o: compressor.c compressor.h\n\nunsquashfs: $(UNSQUASHFS_OBJS)\n\t$(CC) $(UNSQUASHFS_OBJS) -lz -lpthread -lm -o $@\n\nunsquashfs.o: unsquashfs.h unsquashfs.c squashfs_fs.h squashfs_swap.h \\\n\tsquashfs_compat.h global.h\n\nunsquash-1.o: unsquashfs.h unsquash-1.c squashfs_fs.h squashfs_compat.h \\\n\tglobal.h\n\nunsquash-2.o: unsquashfs.h unsquash-2.c unsquashfs.h squashfs_fs.h \\\n\tsquashfs_compat.h global.h\n\nunsquash-3.o: unsquashfs.h unsquash-3.c squashfs_fs.h squashfs_compat.h \\\n\tglobal.h\n\nunsquash-4.o: unsquashfs.h unsquash-4.c squashfs_fs.h squashfs_swap.h \\\n\tglobal.h\n\n.PHONY: romfs\n\t@echo \"Done\"\n\n.PHONY: clean\nclean:\n\t-rm -f *.o mksquashfs unsquashfs\n\n.PHONY: install\ninstall: mksquashfs unsquashfs\n\tmkdir -p $(INSTALL_DIR)\n\tcp mksquashfs $(INSTALL_DIR)\n\tcp unsquashfs $(INSTALL_DIR)\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/compressor.c",
    "content": "/*\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * compressor.c\n */\n\n#include <stdio.h>\n#include <string.h>\n#include \"compressor.h\"\n#include \"squashfs_fs.h\"\n\nextern int gzip_compress(void **, char *, char *, int, int, int *);\nextern int gzip_uncompress(char *, char *, int, int, int *);\nextern int lzma_compress(void **, char *, char *, int, int, int *);\nextern int lzma_uncompress(char *, char *, int, int, int *);\n\nstruct compressor compressor[] = {\n\t{ gzip_compress, gzip_uncompress, ZLIB_COMPRESSION, \"gzip\", 1 },\n#ifdef LZMA_SUPPORT\n\t{ lzma_compress, lzma_uncompress, LZMA_COMPRESSION, \"lzma\", 1 },\n#else\n\t{ NULL, NULL, LZMA_COMPRESSION, \"lzma\", 0 },\n#endif\n\t{ NULL, NULL , 0, \"unknown\", 0}\n};\n\n\nstruct compressor *lookup_compressor(char *name)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i].id; i++)\n\t\tif(strcmp(compressor[i].name, name) == 0)\n\t\t\tbreak;\n\n\treturn &compressor[i];\n}\n\n\nstruct compressor *lookup_compressor_id(int id)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i].id; i++)\n\t\tif(id == compressor[i].id)\n\t\t\tbreak;\n\n\treturn &compressor[i];\n}\n\n\nvoid display_compressors(char *indent, char *def_comp)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i].id; i++)\n\t\tif(compressor[i].supported)\n\t\t\tfprintf(stderr, \"%s\\t%s%s\\n\", indent,\n\t\t\t\tcompressor[i].name,\n\t\t\t\tstrcmp(compressor[i].name, def_comp) == 0 ?\n\t\t\t\t\" (default)\" : \"\");\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/compressor.h",
    "content": "/*\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * compressor.h\n */\n\nstruct compressor {\n\tint (*compress)(void **, char *, char *, int, int, int *);\n\tint (*uncompress)(char *, char *, int, int, int *);\n\tint id;\n\tchar *name;\n\tint supported;\n};\n\nextern struct compressor *lookup_compressor(char *);\nextern struct compressor *lookup_compressor_id(int);\nextern void display_compressors(char *, char *);\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\ntypedef union squashfs_inode_header squashfs_inode_header;\n\ntypedef unsigned int squashfs_id;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/gzip_wrapper.c",
    "content": "/*\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * gzip_wrapper.c\n */\n\n#include <zlib.h>\n#include <stdlib.h>\n\nint gzip_compress(void **strm, char *d, char *s, int size, int block_size,\n\t\tint *error)\n{\n\tint res = 0;\n\tz_stream *stream = *strm;\n\n\tif(stream == NULL) {\n\t\tif((stream = *strm = malloc(sizeof(z_stream))) == NULL)\n\t\t\tgoto failed;\n\n\t\tstream->zalloc = Z_NULL;\n\t\tstream->zfree = Z_NULL;\n\t\tstream->opaque = 0;\n\n\t\tif((res = deflateInit(stream, 9)) != Z_OK)\n\t\t\tgoto failed;\n\t} else if((res = deflateReset(stream)) != Z_OK)\n\t\tgoto failed;\n\n\tstream->next_in = (unsigned char *) s;\n\tstream->avail_in = size;\n\tstream->next_out = (unsigned char *) d;\n\tstream->avail_out = block_size;\n\n\tres = deflate(stream, Z_FINISH);\n\tif(res == Z_STREAM_END)\n\t\t/*\n\t\t * Success, return the compressed size.\n\t\t */\n\t\treturn (int) stream->total_out;\n\tif(res == Z_OK)\n\t\t/*\n\t\t * Output buffer overflow.  Return out of buffer space\n\t\t */\n\t\treturn 0;\nfailed:\n\t/*\n\t * All other errors return failure, with the compressor\n\t * specific error code in *error\n\t */\n\t*error = res;\n\treturn -1;\n}\n\n\nint gzip_uncompress(char *d, char *s, int size, int block_size, int *error)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\n\tres = uncompress((unsigned char *) d, &bytes,\n\t\t(const unsigned char *) s, size);\n\n\t*error = res;\n\treturn res == Z_OK ? (int) bytes : -1;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/7zC.txt",
    "content": "7z ANSI-C Decoder 4.62\r\n----------------------\r\n\r\n7z ANSI-C provides 7z/LZMA decoding.\r\n7z ANSI-C version is simplified version ported from C++ code.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\n7z ANSI-C Decoder is part of the LZMA SDK.\r\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\r\n\r\nFiles\r\n---------------------\r\n\r\n7zDecode.*   - Low level 7z decoding\r\n7zExtract.*  - High level 7z decoding\r\n7zHeader.*   - .7z format constants\r\n7zIn.*       - .7z archive opening\r\n7zItem.*     - .7z structures\r\n7zMain.c     - Test application\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nYou must download 7-Zip program from www.7-zip.org.\r\n\r\nYou can create .7z archive with 7z.exe or 7za.exe:\r\n\r\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255\r\n\r\nIf you have big number of files in archive, and you need fast extracting, \r\nyou can use partly-solid archives:\r\n  \r\n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\r\n\r\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r\n512KB for extracting one file from such archive.\r\n\r\n\r\nLimitations of current version of 7z ANSI-C Decoder\r\n---------------------------------------------------\r\n\r\n - It reads only \"FileName\", \"Size\", \"LastWriteTime\" and \"CRC\" information for each file in archive.\r\n - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.\r\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r\n \r\nThese limitations will be fixed in future versions.\r\n\r\n\r\nUsing 7z ANSI-C Decoder Test application:\r\n-----------------------------------------\r\n\r\nUsage: 7zDec <command> <archive_name>\r\n\r\n<Command>:\r\n  e: Extract files from archive\r\n  l: List contents of archive\r\n  t: Test integrity of archive\r\n\r\nExample: \r\n\r\n  7zDec l archive.7z\r\n\r\nlists contents of archive.7z\r\n\r\n  7zDec e archive.7z\r\n\r\nextracts files from archive.7z to current folder.\r\n\r\n\r\nHow to use .7z Decoder\r\n----------------------\r\n\r\nMemory allocation\r\n~~~~~~~~~~~~~~~~~\r\n\r\n7z Decoder uses two memory pools:\r\n1) Temporary pool\r\n2) Main pool\r\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\r\n\r\n\r\nSteps for using 7z decoder\r\n--------------------------\r\n\r\nUse code at 7zMain.c as example.\r\n\r\n1) Declare variables:\r\n  inStream                 /* implements ILookInStream interface */\r\n  CSzArEx db;              /* 7z archive database structure */\r\n  ISzAlloc allocImp;       /* memory functions for main pool */\r\n  ISzAlloc allocTempImp;   /* memory functions for temporary pool */\r\n\r\n2) call CrcGenerateTable(); function to initialize CRC structures.\r\n\r\n3) call SzArEx_Init(&db); function to initialize db structures.\r\n\r\n4) call SzArEx_Open(&db, inStream, &allocMain, &allocTemp) to open archive\r\n\r\nThis function opens archive \"inStream\" and reads headers to \"db\".\r\nAll items in \"db\" will be allocated with \"allocMain\" functions.\r\nSzArEx_Open function allocates and frees temporary structures by \"allocTemp\" functions.\r\n\r\n5) List items or Extract items\r\n\r\n  Listing code:\r\n  ~~~~~~~~~~~~~\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.db.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n\r\n  Extracting code:\r\n  ~~~~~~~~~~~~~~~~\r\n\r\n  SZ_RESULT SzAr_Extract(\r\n    CArchiveDatabaseEx *db,\r\n    ILookInStream *inStream, \r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n  If you need to decompress more than one file, you can send these values from previous call:\r\n    blockIndex, \r\n    outBuffer, \r\n    outBufferSize,\r\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \r\n  it will increase decompression speed.\r\n\r\n  After decompressing you must free \"outBuffer\":\r\n  allocImp.Free(outBuffer);\r\n\r\n6) call SzArEx_Free(&db, allocImp.Free) to free allocated items in \"db\".\r\n\r\n\r\n\r\n\r\nMemory requirements for .7z decoding \r\n------------------------------------\r\n\r\nMemory usage for Archive opening:\r\n  - Temporary pool:\r\n     - Memory for uncompressed .7z headers\r\n     - some other temporary blocks\r\n  - Main pool:\r\n     - Memory for database: \r\n       Estimated size of one file structures in solid archive:\r\n         - Size (4 or 8 Bytes)\r\n         - CRC32 (4 bytes)\r\n         - LastWriteTime (8 bytes)\r\n         - Some file information (4 bytes)\r\n         - File Name (variable length) + pointer + allocation structures\r\n\r\nMemory usage for archive Decompressing:\r\n  - Temporary pool:\r\n     - Memory for LZMA decompressing structures\r\n  - Main pool:\r\n     - Memory for decompressed solid block\r\n     - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these \r\n       temprorary buffers can be about 15% of solid block size. \r\n  \r\n\r\n7z Decoder doesn't allocate memory for compressed blocks. \r\nInstead of this, you must allocate buffer with desired \r\nsize before calling 7z Decoder. Use 7zMain.c as example.\r\n\r\n\r\nDefines\r\n-------\r\n\r\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/sdk.html\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\r\n-----------------------------------\r\n\r\nThis file contains description of 7z archive format. \r\n7z archive can contain files compressed with any method.\r\nSee \"Methods.txt\" for description for defined compressing methods.\r\n\r\n\r\nFormat structure Overview\r\n-------------------------\r\n\r\nSome fields can be optional.\r\n\r\nArchive structure\r\n~~~~~~~~~~~~~~~~~  \r\nSignatureHeader\r\n[PackedStreams]\r\n[PackedStreamsForHeaders]\r\n[\r\n  Header \r\n  or \r\n  {\r\n    Packed Header\r\n    HeaderInfo\r\n  }\r\n]\r\n\r\n\r\n\r\nHeader structure\r\n~~~~~~~~~~~~~~~~  \r\n{\r\n  ArchiveProperties\r\n  AdditionalStreams\r\n  {\r\n    PackInfo\r\n    {\r\n      PackPos\r\n      NumPackStreams\r\n      Sizes[NumPackStreams]\r\n      CRCs[NumPackStreams]\r\n    }\r\n    CodersInfo\r\n    {\r\n      NumFolders\r\n      Folders[NumFolders]\r\n      {\r\n        NumCoders\r\n        CodersInfo[NumCoders]\r\n        {\r\n          ID\r\n          NumInStreams;\r\n          NumOutStreams;\r\n          PropertiesSize\r\n          Properties[PropertiesSize]\r\n        }\r\n        NumBindPairs\r\n        BindPairsInfo[NumBindPairs]\r\n        {\r\n          InIndex;\r\n          OutIndex;\r\n        }\r\n        PackedIndices\r\n      }\r\n      UnPackSize[Folders][Folders.NumOutstreams]\r\n      CRCs[NumFolders]\r\n    }\r\n    SubStreamsInfo\r\n    {\r\n      NumUnPackStreamsInFolders[NumFolders];\r\n      UnPackSizes[]\r\n      CRCs[]\r\n    }\r\n  }\r\n  MainStreamsInfo\r\n  {\r\n    (Same as in AdditionalStreams)\r\n  }\r\n  FilesInfo\r\n  {\r\n    NumFiles\r\n    Properties[]\r\n    {\r\n      ID\r\n      Size\r\n      Data\r\n    }\r\n  }\r\n}\r\n\r\nHeaderInfo structure\r\n~~~~~~~~~~~~~~~~~~~~\r\n{\r\n  (Same as in AdditionalStreams)\r\n}\r\n\r\n\r\n\r\nNotes about Notation and encoding\r\n---------------------------------\r\n\r\n7z uses little endian encoding.\r\n\r\n7z archive format has optional headers that are marked as\r\n[]\r\nHeader\r\n[]\r\n\r\nREAL_UINT64 means real UINT64.\r\n\r\nUINT64 means real UINT64 encoded with the following scheme:\r\n\r\n  Size of encoding sequence depends from first byte:\r\n  First_Byte  Extra_Bytes        Value\r\n  (binary)   \r\n  0xxxxxxx               : ( xxxxxxx           )\r\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r\n  ...\r\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r\n  11111110    BYTE y[7]  :                         y\r\n  11111111    BYTE y[8]  :                         y\r\n\r\n\r\n\r\nProperty IDs\r\n------------\r\n\r\n0x00 = kEnd,\r\n\r\n0x01 = kHeader,\r\n\r\n0x02 = kArchiveProperties,\r\n    \r\n0x03 = kAdditionalStreamsInfo,\r\n0x04 = kMainStreamsInfo,\r\n0x05 = kFilesInfo,\r\n    \r\n0x06 = kPackInfo,\r\n0x07 = kUnPackInfo,\r\n0x08 = kSubStreamsInfo,\r\n\r\n0x09 = kSize,\r\n0x0A = kCRC,\r\n\r\n0x0B = kFolder,\r\n\r\n0x0C = kCodersUnPackSize,\r\n0x0D = kNumUnPackStream,\r\n\r\n0x0E = kEmptyStream,\r\n0x0F = kEmptyFile,\r\n0x10 = kAnti,\r\n\r\n0x11 = kName,\r\n0x12 = kCreationTime,\r\n0x13 = kLastAccessTime,\r\n0x14 = kLastWriteTime,\r\n0x15 = kWinAttributes,\r\n0x16 = kComment,\r\n\r\n0x17 = kEncodedHeader,\r\n\r\n\r\n7z format headers\r\n-----------------\r\n\r\nSignatureHeader\r\n~~~~~~~~~~~~~~~\r\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n\r\n  ArchiveVersion\r\n  {\r\n    BYTE Major;   // now = 0\r\n    BYTE Minor;   // now = 2\r\n  };\r\n\r\n  UINT32 StartHeaderCRC;\r\n\r\n  StartHeader\r\n  {\r\n    REAL_UINT64 NextHeaderOffset\r\n    REAL_UINT64 NextHeaderSize\r\n    UINT32 NextHeaderCRC\r\n  }\r\n\r\n\r\n...........................\r\n\r\n\r\nArchiveProperties\r\n~~~~~~~~~~~~~~~~~\r\nBYTE NID::kArchiveProperties (0x02)\r\nfor (;;)\r\n{\r\n  BYTE PropertyType;\r\n  if (aType == 0)\r\n    break;\r\n  UINT64 PropertySize;\r\n  BYTE PropertyData[PropertySize];\r\n}\r\n\r\n\r\nDigests (NumStreams)\r\n~~~~~~~~~~~~~~~~~~~~~\r\n  BYTE AllAreDefined\r\n  if (AllAreDefined == 0)\r\n  {\r\n    for(NumStreams)\r\n      BIT Defined\r\n  }\r\n  UINT32 CRCs[NumDefined]\r\n\r\n\r\nPackInfo\r\n~~~~~~~~~~~~\r\n  BYTE NID::kPackInfo  (0x06)\r\n  UINT64 PackPos\r\n  UINT64 NumPackStreams\r\n\r\n  []\r\n  BYTE NID::kSize    (0x09)\r\n  UINT64 PackSizes[NumPackStreams]\r\n  []\r\n\r\n  []\r\n  BYTE NID::kCRC      (0x0A)\r\n  PackStreamDigests[NumPackStreams]\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFolder\r\n~~~~~~\r\n  UINT64 NumCoders;\r\n  for (NumCoders)\r\n  {\r\n    BYTE \r\n    {\r\n      0:3 DecompressionMethod.IDSize\r\n      4:\r\n        0 - IsSimple\r\n        1 - Is not simple\r\n      5:\r\n        0 - No Attributes\r\n        1 - There Are Attributes\r\n      7:\r\n        0 - Last Method in Alternative_Method_List\r\n        1 - There are more alternative methods\r\n    } \r\n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\r\n    if (!IsSimple)\r\n    {\r\n      UINT64 NumInStreams;\r\n      UINT64 NumOutStreams;\r\n    }\r\n    if (DecompressionMethod[0] != 0)\r\n    {\r\n      UINT64 PropertiesSize\r\n      BYTE Properties[PropertiesSize]\r\n    }\r\n  }\r\n    \r\n  NumBindPairs = NumOutStreamsTotal - 1;\r\n\r\n  for (NumBindPairs)\r\n  {\r\n    UINT64 InIndex;\r\n    UINT64 OutIndex;\r\n  }\r\n\r\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r\n  if (NumPackedStreams > 1)\r\n    for(NumPackedStreams)\r\n    {\r\n      UINT64 Index;\r\n    };\r\n\r\n\r\n\r\n\r\nCoders Info\r\n~~~~~~~~~~~\r\n\r\n  BYTE NID::kUnPackInfo  (0x07)\r\n\r\n\r\n  BYTE NID::kFolder  (0x0B)\r\n  UINT64 NumFolders\r\n  BYTE External\r\n  switch(External)\r\n  {\r\n    case 0:\r\n      Folders[NumFolders]\r\n    case 1:\r\n      UINT64 DataStreamIndex\r\n  }\r\n\r\n\r\n  BYTE ID::kCodersUnPackSize  (0x0C)\r\n  for(Folders)\r\n    for(Folder.NumOutStreams)\r\n     UINT64 UnPackSize;\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC   (0x0A)\r\n  UnPackDigests[NumFolders]\r\n  []\r\n\r\n  \r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\n\r\nSubStreams Info\r\n~~~~~~~~~~~~~~\r\n  BYTE NID::kSubStreamsInfo; (0x08)\r\n\r\n  []\r\n  BYTE NID::kNumUnPackStream; (0x0D)\r\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kSize  (0x09)\r\n  UINT64 UnPackSizes[]\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC  (0x0A)\r\n  Digests[Number of streams with unknown CRC]\r\n  []\r\n\r\n  \r\n  BYTE NID::kEnd\r\n\r\n\r\nStreams Info\r\n~~~~~~~~~~~~\r\n\r\n  []\r\n  PackInfo\r\n  []\r\n\r\n\r\n  []\r\n  CodersInfo\r\n  []\r\n\r\n\r\n  []\r\n  SubStreamsInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFilesInfo\r\n~~~~~~~~~\r\n  BYTE NID::kFilesInfo;  (0x05)\r\n  UINT64 NumFiles\r\n\r\n  for (;;)\r\n  {\r\n    BYTE PropertyType;\r\n    if (aType == 0)\r\n      break;\r\n\r\n    UINT64 Size;\r\n\r\n    switch(PropertyType)\r\n    {\r\n      kEmptyStream:   (0x0E)\r\n        for(NumFiles)\r\n          BIT IsEmptyStream\r\n\r\n      kEmptyFile:     (0x0F)\r\n        for(EmptyStreams)\r\n          BIT IsEmptyFile\r\n\r\n      kAnti:          (0x10)\r\n        for(EmptyStreams)\r\n          BIT IsAntiFile\r\n      \r\n      case kCreationTime:   (0x12)\r\n      case kLastAccessTime: (0x13)\r\n      case kLastWriteTime:  (0x14)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT TimeDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Items)\r\n          UINT32 Time\r\n        []\r\n      \r\n      kNames:     (0x11)\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Files)\r\n        {\r\n          wchar_t Names[NameSize];\r\n          wchar_t 0;\r\n        }\r\n        []\r\n\r\n      kAttributes:  (0x15)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT AttributesAreDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Attributes)\r\n          UINT32 Attributes\r\n        []\r\n    }\r\n  }\r\n\r\n\r\nHeader\r\n~~~~~~\r\n  BYTE NID::kHeader (0x01)\r\n\r\n  []\r\n  ArchiveProperties\r\n  []\r\n\r\n  []\r\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  BYTE NID::kMainStreamsInfo;    (0x04)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  FilesInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nHeaderInfo\r\n~~~~~~~~~~\r\n  []\r\n  BYTE NID::kEncodedHeader; (0x17)\r\n  StreamsInfo for Encoded Header\r\n  []\r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/7zBuf.c",
    "content": "/* 7zBuf.c -- Byte Buffer\r\n2008-03-28\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"7zBuf.h\"\r\n\r\nvoid Buf_Init(CBuf *p)\r\n{\r\n  p->data = 0;\r\n  p->size = 0;\r\n}\r\n\r\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)\r\n{\r\n  p->size = 0;\r\n  if (size == 0)\r\n  {\r\n    p->data = 0;\r\n    return 1;\r\n  }\r\n  p->data = (Byte *)alloc->Alloc(alloc, size);\r\n  if (p->data != 0)\r\n  {\r\n    p->size = size;\r\n    return 1;\r\n  }\r\n  return 0;\r\n}\r\n\r\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->data);\r\n  p->data = 0;\r\n  p->size = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/7zBuf.h",
    "content": "/* 7zBuf.h -- Byte Buffer\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_BUF_H\r\n#define __7Z_BUF_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct\r\n{\r\n  Byte *data;\r\n  size_t size;\r\n} CBuf;\r\n\r\nvoid Buf_Init(CBuf *p);\r\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);\r\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc);\r\n\r\ntypedef struct\r\n{\r\n  Byte *data;\r\n  size_t size;\r\n  size_t pos;\r\n} CDynBuf;\r\n\r\nvoid DynBuf_Construct(CDynBuf *p);\r\nvoid DynBuf_SeekToBeg(CDynBuf *p);\r\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);\r\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/7zBuf2.c",
    "content": "/* 7zBuf2.c -- Byte Buffer\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n#include \"7zBuf.h\"\r\n\r\nvoid DynBuf_Construct(CDynBuf *p)\r\n{\r\n  p->data = 0;\r\n  p->size = 0;\r\n  p->pos = 0;\r\n}\r\n\r\nvoid DynBuf_SeekToBeg(CDynBuf *p)\r\n{\r\n  p->pos = 0;\r\n}\r\n\r\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)\r\n{\r\n  if (size > p->size - p->pos)\r\n  {\r\n    size_t newSize = p->pos + size;\r\n    Byte *data;\r\n    newSize += newSize / 4;\r\n    data = (Byte *)alloc->Alloc(alloc, newSize);\r\n    if (data == 0)\r\n      return 0;\r\n    p->size = newSize;\r\n    memcpy(data, p->data, p->pos);\r\n    alloc->Free(alloc, p->data);\r\n    p->data = data;\r\n  }\r\n  memcpy(p->data + p->pos, buf, size);\r\n  p->pos += size;\r\n  return 1;\r\n}\r\n\r\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->data);\r\n  p->data = 0;\r\n  p->size = 0;\r\n  p->pos = 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/7zCrc.c",
    "content": "/* 7zCrc.c -- CRC32 calculation\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\r\n{\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = CRC_UPDATE_BYTE(v, *p);\r\n  return v;\r\n}\r\n\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\r\n{\r\n  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/7zCrc.h",
    "content": "/* 7zCrc.h -- CRC32 calculation\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"Types.h\"\r\n\r\nextern UInt32 g_CrcTable[];\r\n\r\nvoid MY_FAST_CALL CrcGenerateTable(void);\r\n\r\n#define CRC_INIT_VAL 0xFFFFFFFF\r\n#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)\r\n#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\r\n\r\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);\r\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/7zFile.c",
    "content": "/* 7zFile.c -- File IO\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zFile.h\"\r\n\r\n#ifndef USE_WINDOWS_FILE\r\n\r\n#include <errno.h>\r\n\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FILE\r\n\r\n/*\r\n   ReadFile and WriteFile functions in Windows have BUG:\r\n   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r\n   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r\n   (Insufficient system resources exist to complete the requested service).\r\n   Probably in some version of Windows there are problems with other sizes:\r\n   for 32 MB (maybe also for 16 MB).\r\n   And message can be \"Network connection was lost\"\r\n*/\r\n\r\n#define kChunkSizeMax (1 << 22)\r\n\r\n#endif\r\n\r\nvoid File_Construct(CSzFile *p)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  p->handle = INVALID_HANDLE_VALUE;\r\n  #else\r\n  p->file = NULL;\r\n  #endif\r\n}\r\n\r\nstatic WRes File_Open(CSzFile *p, const char *name, int writeMode)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  p->handle = CreateFileA(name,\r\n      writeMode ? GENERIC_WRITE : GENERIC_READ,\r\n      FILE_SHARE_READ, NULL,\r\n      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\r\n      FILE_ATTRIBUTE_NORMAL, NULL);\r\n  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r\n  #else\r\n  p->file = fopen(name, writeMode ? \"wb+\" : \"rb\");\r\n  return (p->file != 0) ? 0 : errno;\r\n  #endif\r\n}\r\n\r\nWRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }\r\nWRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }\r\n\r\nWRes File_Close(CSzFile *p)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  if (p->handle != INVALID_HANDLE_VALUE)\r\n  {\r\n    if (!CloseHandle(p->handle))\r\n      return GetLastError();\r\n    p->handle = INVALID_HANDLE_VALUE;\r\n  }\r\n  #else\r\n  if (p->file != NULL)\r\n  {\r\n    int res = fclose(p->file);\r\n    if (res != 0)\r\n      return res;\r\n    p->file = NULL;\r\n  }\r\n  #endif\r\n  return 0;\r\n}\r\n\r\nWRes File_Read(CSzFile *p, void *data, size_t *size)\r\n{\r\n  size_t originalSize = *size;\r\n  if (originalSize == 0)\r\n    return 0;\r\n\r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  *size = 0;\r\n  do\r\n  {\r\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r\n    DWORD processed = 0;\r\n    BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);\r\n    data = (void *)((Byte *)data + processed);\r\n    originalSize -= processed;\r\n    *size += processed;\r\n    if (!res)\r\n      return GetLastError();\r\n    if (processed == 0)\r\n      break;\r\n  }\r\n  while (originalSize > 0);\r\n  return 0;\r\n\r\n  #else\r\n  \r\n  *size = fread(data, 1, originalSize, p->file);\r\n  if (*size == originalSize)\r\n    return 0;\r\n  return ferror(p->file);\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_Write(CSzFile *p, const void *data, size_t *size)\r\n{\r\n  size_t originalSize = *size;\r\n  if (originalSize == 0)\r\n    return 0;\r\n  \r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  *size = 0;\r\n  do\r\n  {\r\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\r\n    DWORD processed = 0;\r\n    BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);\r\n    data = (void *)((Byte *)data + processed);\r\n    originalSize -= processed;\r\n    *size += processed;\r\n    if (!res)\r\n      return GetLastError();\r\n    if (processed == 0)\r\n      break;\r\n  }\r\n  while (originalSize > 0);\r\n  return 0;\r\n\r\n  #else\r\n\r\n  *size = fwrite(data, 1, originalSize, p->file);\r\n  if (*size == originalSize)\r\n    return 0;\r\n  return ferror(p->file);\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n\r\n  LARGE_INTEGER value;\r\n  DWORD moveMethod;\r\n  value.LowPart = (DWORD)*pos;\r\n  value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */\r\n  switch (origin)\r\n  {\r\n    case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;\r\n    case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;\r\n    case SZ_SEEK_END: moveMethod = FILE_END; break;\r\n    default: return ERROR_INVALID_PARAMETER;\r\n  }\r\n  value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n  {\r\n    WRes res = GetLastError();\r\n    if (res != NO_ERROR)\r\n      return res;\r\n  }\r\n  *pos = ((Int64)value.HighPart << 32) | value.LowPart;\r\n  return 0;\r\n\r\n  #else\r\n  \r\n  int moveMethod;\r\n  int res;\r\n  switch (origin)\r\n  {\r\n    case SZ_SEEK_SET: moveMethod = SEEK_SET; break;\r\n    case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;\r\n    case SZ_SEEK_END: moveMethod = SEEK_END; break;\r\n    default: return 1;\r\n  }\r\n  res = fseek(p->file, (long)*pos, moveMethod);\r\n  *pos = ftell(p->file);\r\n  return res;\r\n  \r\n  #endif\r\n}\r\n\r\nWRes File_GetLength(CSzFile *p, UInt64 *length)\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  \r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);\r\n  if (sizeLow == 0xFFFFFFFF)\r\n  {\r\n    DWORD res = GetLastError();\r\n    if (res != NO_ERROR)\r\n      return res;\r\n  }\r\n  *length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return 0;\r\n  \r\n  #else\r\n  \r\n  long pos = ftell(p->file);\r\n  int res = fseek(p->file, 0, SEEK_END);\r\n  *length = ftell(p->file);\r\n  fseek(p->file, pos, SEEK_SET);\r\n  return res;\r\n  \r\n  #endif\r\n}\r\n\r\n\r\n/* ---------- FileSeqInStream ---------- */\r\n\r\nstatic SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CFileSeqInStream *p = (CFileSeqInStream *)pp;\r\n  return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;\r\n}\r\n\r\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p)\r\n{\r\n  p->s.Read = FileSeqInStream_Read;\r\n}\r\n\r\n\r\n/* ---------- FileInStream ---------- */\r\n\r\nstatic SRes FileInStream_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CFileInStream *p = (CFileInStream *)pp;\r\n  return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;\r\n}\r\n\r\nstatic SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)\r\n{\r\n  CFileInStream *p = (CFileInStream *)pp;\r\n  return File_Seek(&p->file, pos, origin);\r\n}\r\n\r\nvoid FileInStream_CreateVTable(CFileInStream *p)\r\n{\r\n  p->s.Read = FileInStream_Read;\r\n  p->s.Seek = FileInStream_Seek;\r\n}\r\n\r\n\r\n/* ---------- FileOutStream ---------- */\r\n\r\nstatic size_t FileOutStream_Write(void *pp, const void *data, size_t size)\r\n{\r\n  CFileOutStream *p = (CFileOutStream *)pp;\r\n  File_Write(&p->file, data, &size);\r\n  return size;\r\n}\r\n\r\nvoid FileOutStream_CreateVTable(CFileOutStream *p)\r\n{\r\n  p->s.Write = FileOutStream_Write;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/7zFile.h",
    "content": "/* 7zFile.h -- File IO\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_FILE_H\r\n#define __7Z_FILE_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WINDOWS_FILE\r\n#endif\r\n\r\n#ifdef USE_WINDOWS_FILE\r\n#include <windows.h>\r\n#else\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"Types.h\"\r\n\r\n\r\n/* ---------- File ---------- */\r\n\r\ntypedef struct\r\n{\r\n  #ifdef USE_WINDOWS_FILE\r\n  HANDLE handle;\r\n  #else\r\n  FILE *file;\r\n  #endif\r\n} CSzFile;\r\n\r\nvoid File_Construct(CSzFile *p);\r\nWRes InFile_Open(CSzFile *p, const char *name);\r\nWRes OutFile_Open(CSzFile *p, const char *name);\r\nWRes File_Close(CSzFile *p);\r\n\r\n/* reads max(*size, remain file's size) bytes */\r\nWRes File_Read(CSzFile *p, void *data, size_t *size);\r\n\r\n/* writes *size bytes */\r\nWRes File_Write(CSzFile *p, const void *data, size_t *size);\r\n\r\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);\r\nWRes File_GetLength(CSzFile *p, UInt64 *length);\r\n\r\n\r\n/* ---------- FileInStream ---------- */\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  CSzFile file;\r\n} CFileSeqInStream;\r\n\r\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p);\r\n\r\n\r\ntypedef struct\r\n{\r\n  ISeekInStream s;\r\n  CSzFile file;\r\n} CFileInStream;\r\n\r\nvoid FileInStream_CreateVTable(CFileInStream *p);\r\n\r\n\r\ntypedef struct\r\n{\r\n  ISeqOutStream s;\r\n  CSzFile file;\r\n} CFileOutStream;\r\n\r\nvoid FileOutStream_CreateVTable(CFileOutStream *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/7zStream.c",
    "content": "/* 7zStream.c -- 7z Stream functions\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"Types.h\"\r\n\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)\r\n{\r\n  while (size != 0)\r\n  {\r\n    size_t processed = size;\r\n    RINOK(stream->Read(stream, buf, &processed));\r\n    if (processed == 0)\r\n      return errorType;\r\n    buf = (void *)((Byte *)buf + processed);\r\n    size -= processed;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)\r\n{\r\n  return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r\n}\r\n\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)\r\n{\r\n  size_t processed = 1;\r\n  RINOK(stream->Read(stream, buf, &processed));\r\n  return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;\r\n}\r\n\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)\r\n{\r\n  Int64 t = offset;\r\n  return stream->Seek(stream, &t, SZ_SEEK_SET);\r\n}\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)\r\n{\r\n  void *lookBuf;\r\n  if (*size == 0)\r\n    return SZ_OK;\r\n  RINOK(stream->Look(stream, &lookBuf, size));\r\n  memcpy(buf, lookBuf, *size);\r\n  return stream->Skip(stream, *size);\r\n}\r\n\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)\r\n{\r\n  while (size != 0)\r\n  {\r\n    size_t processed = size;\r\n    RINOK(stream->Read(stream, buf, &processed));\r\n    if (processed == 0)\r\n      return errorType;\r\n    buf = (void *)((Byte *)buf + processed);\r\n    size -= processed;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)\r\n{\r\n  return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r\n}\r\n\r\nstatic SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)\r\n{\r\n  SRes res = SZ_OK;\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t size2 = p->size - p->pos;\r\n  if (size2 == 0 && *size > 0)\r\n  {\r\n    p->pos = 0;\r\n    size2 = LookToRead_BUF_SIZE;\r\n    res = p->realStream->Read(p->realStream, p->buf, &size2);\r\n    p->size = size2;\r\n  }\r\n  if (size2 < *size)\r\n    *size = size2;\r\n  *buf = p->buf + p->pos;\r\n  return res;\r\n}\r\n\r\nstatic SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)\r\n{\r\n  SRes res = SZ_OK;\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t size2 = p->size - p->pos;\r\n  if (size2 == 0 && *size > 0)\r\n  {\r\n    p->pos = 0;\r\n    if (*size > LookToRead_BUF_SIZE)\r\n      *size = LookToRead_BUF_SIZE;\r\n    res = p->realStream->Read(p->realStream, p->buf, size);\r\n    size2 = p->size = *size;\r\n  }\r\n  if (size2 < *size)\r\n    *size = size2;\r\n  *buf = p->buf + p->pos;\r\n  return res;\r\n}\r\n\r\nstatic SRes LookToRead_Skip(void *pp, size_t offset)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  p->pos += offset;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LookToRead_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  size_t rem = p->size - p->pos;\r\n  if (rem == 0)\r\n    return p->realStream->Read(p->realStream, buf, size);\r\n  if (rem > *size)\r\n    rem = *size;\r\n  memcpy(buf, p->buf + p->pos, rem);\r\n  p->pos += rem;\r\n  *size = rem;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)\r\n{\r\n  CLookToRead *p = (CLookToRead *)pp;\r\n  p->pos = p->size = 0;\r\n  return p->realStream->Seek(p->realStream, pos, origin);\r\n}\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead)\r\n{\r\n  p->s.Look = lookahead ?\r\n      LookToRead_Look_Lookahead :\r\n      LookToRead_Look_Exact;\r\n  p->s.Skip = LookToRead_Skip;\r\n  p->s.Read = LookToRead_Read;\r\n  p->s.Seek = LookToRead_Seek;\r\n}\r\n\r\nvoid LookToRead_Init(CLookToRead *p)\r\n{\r\n  p->pos = p->size = 0;\r\n}\r\n\r\nstatic SRes SecToLook_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CSecToLook *p = (CSecToLook *)pp;\r\n  return LookInStream_LookRead(p->realStream, buf, size);\r\n}\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p)\r\n{\r\n  p->s.Read = SecToLook_Read;\r\n}\r\n\r\nstatic SRes SecToRead_Read(void *pp, void *buf, size_t *size)\r\n{\r\n  CSecToRead *p = (CSecToRead *)pp;\r\n  return p->realStream->Read(p->realStream, buf, size);\r\n}\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p)\r\n{\r\n  p->s.Read = SecToRead_Read;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/7zVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 65\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.65\"\r\n#define MY_DATE \"2009-02-03\"\r\n#define MY_COPYRIGHT \": Igor Pavlov : Public domain\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \" \" MY_COPYRIGHT \" : \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Alloc.c",
    "content": "/* Alloc.c -- Memory allocation functions\r\n2008-09-24\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdlib.h>\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  {\r\n    void *p = malloc(size);\r\n    fprintf(stderr, \"\\nAlloc %10d bytes, count = %10d,  addr = %8X\", size, g_allocCount++, (unsigned)p);\r\n    return p;\r\n  }\r\n  #else\r\n  return malloc(size);\r\n  #endif\r\n}\r\n\r\nvoid MyFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d,  addr = %8X\", --g_allocCount, (unsigned)address);\r\n  #endif\r\n  free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#ifndef MEM_LARGE_PAGES\r\n#undef _7ZIP_LARGE_PAGES\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nSIZE_T g_LargePageSize = 0;\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n#endif\r\n\r\nvoid SetLargePageSize()\r\n{\r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  SIZE_T size = 0;\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        GetProcAddress(GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return;\r\n  size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return;\r\n  g_LargePageSize = size;\r\n  #endif\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  #ifdef _7ZIP_LARGE_PAGES\r\n  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))\r\n  {\r\n    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),\r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  #endif\r\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Alloc.h",
    "content": "/* Alloc.h -- Memory allocation functions\r\n2008-03-13\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size);\r\nvoid MyFree(void *address);\r\n\r\n#ifdef _WIN32\r\n\r\nvoid SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size);\r\nvoid MidFree(void *address);\r\nvoid *BigAlloc(size_t size);\r\nvoid BigFree(void *address);\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z.mak\" CFG=\"7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /FAs /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_SZ_ALLOC_DEBUG2\" /D \"_SZ_NO_INT_64_A\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z - Win32 Release\"\r\n# Name \"7z - Win32 Debug\"\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zBuf.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zBuf.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zFile.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zFile.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\7zStream.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bcj2.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bcj2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Bra86.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z\"=.\\7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zAlloc.c",
    "content": "/* 7zAlloc.c -- Allocation functions\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n\r\n#endif\r\n\r\nvoid *SzAlloc(void *p, size_t size)\r\n{\r\n  p = p;\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *p, void *address)\r\n{\r\n  p = p;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(void *p, size_t size)\r\n{\r\n  p = p;\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *p, void *address)\r\n{\r\n  p = p;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zAlloc.h",
    "content": "/* 7zAlloc.h -- Allocation functions\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *SzAlloc(void *p, size_t size);\r\nvoid SzFree(void *p, void *address);\r\n\r\nvoid *SzAllocTemp(void *p, size_t size);\r\nvoid SzFreeTemp(void *p, void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zDecode.c",
    "content": "/* 7zDecode.c -- Decoding from 7z folder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"../../Bcj2.h\"\r\n#include \"../../Bra.h\"\r\n#include \"../../LzmaDec.h\"\r\n#include \"7zDecode.h\"\r\n\r\n#define k_Copy 0\r\n#define k_LZMA 0x30101\r\n#define k_BCJ 0x03030103\r\n#define k_BCJ2 0x0303011B\r\n\r\nstatic SRes SzDecodeLzma(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,\r\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)\r\n{\r\n  CLzmaDec state;\r\n  SRes res = SZ_OK;\r\n\r\n  LzmaDec_Construct(&state);\r\n  RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));\r\n  state.dic = outBuffer;\r\n  state.dicBufSize = outSize;\r\n  LzmaDec_Init(&state);\r\n\r\n  for (;;)\r\n  {\r\n    Byte *inBuf = NULL;\r\n    size_t lookahead = (1 << 18);\r\n    if (lookahead > inSize)\r\n      lookahead = (size_t)inSize;\r\n    res = inStream->Look((void *)inStream, (void **)&inBuf, &lookahead);\r\n    if (res != SZ_OK)\r\n      break;\r\n\r\n    {\r\n      SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;\r\n      ELzmaStatus status;\r\n      res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);\r\n      lookahead -= inProcessed;\r\n      inSize -= inProcessed;\r\n      if (res != SZ_OK)\r\n        break;\r\n      if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))\r\n      {\r\n        if (state.dicBufSize != outSize || lookahead != 0 ||\r\n            (status != LZMA_STATUS_FINISHED_WITH_MARK &&\r\n             status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))\r\n          res = SZ_ERROR_DATA;\r\n        break;\r\n      }\r\n      res = inStream->Skip((void *)inStream, inProcessed);\r\n      if (res != SZ_OK)\r\n        break;\r\n    }\r\n  }\r\n\r\n  LzmaDec_FreeProbs(&state, allocMain);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)\r\n{\r\n  while (inSize > 0)\r\n  {\r\n    void *inBuf;\r\n    size_t curSize = (1 << 18);\r\n    if (curSize > inSize)\r\n      curSize = (size_t)inSize;\r\n    RINOK(inStream->Look((void *)inStream, (void **)&inBuf, &curSize));\r\n    if (curSize == 0)\r\n      return SZ_ERROR_INPUT_EOF;\r\n    memcpy(outBuffer, inBuf, curSize);\r\n    outBuffer += curSize;\r\n    inSize -= curSize;\r\n    RINOK(inStream->Skip((void *)inStream, curSize));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)\r\n#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)\r\n#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)\r\n\r\nSRes CheckSupportedFolder(const CSzFolder *f)\r\n{\r\n  if (f->NumCoders < 1 || f->NumCoders > 4)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (IS_UNSUPPORTED_CODER(f->Coders[0]))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (f->NumCoders == 1)\r\n  {\r\n    if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 2)\r\n  {\r\n    if (IS_NO_BCJ(f->Coders[1]) ||\r\n        f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||\r\n        f->NumBindPairs != 1 ||\r\n        f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  if (f->NumCoders == 4)\r\n  {\r\n    if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||\r\n        IS_UNSUPPORTED_CODER(f->Coders[2]) ||\r\n        IS_NO_BCJ2(f->Coders[3]))\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    if (f->NumPackStreams != 4 ||\r\n        f->PackStreams[0] != 2 ||\r\n        f->PackStreams[1] != 6 ||\r\n        f->PackStreams[2] != 1 ||\r\n        f->PackStreams[3] != 0 ||\r\n        f->NumBindPairs != 3 ||\r\n        f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||\r\n        f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||\r\n        f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    return SZ_OK;\r\n  }\r\n  return SZ_ERROR_UNSUPPORTED;\r\n}\r\n\r\nUInt64 GetSum(const UInt64 *values, UInt32 index)\r\n{\r\n  UInt64 sum = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < index; i++)\r\n    sum += values[i];\r\n  return sum;\r\n}\r\n\r\nSRes SzDecode2(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *inStream, UInt64 startPos,\r\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,\r\n    Byte *tempBuf[])\r\n{\r\n  UInt32 ci;\r\n  SizeT tempSizes[3] = { 0, 0, 0};\r\n  SizeT tempSize3 = 0;\r\n  Byte *tempBuf3 = 0;\r\n\r\n  RINOK(CheckSupportedFolder(folder));\r\n\r\n  for (ci = 0; ci < folder->NumCoders; ci++)\r\n  {\r\n    CSzCoderInfo *coder = &folder->Coders[ci];\r\n\r\n    if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)\r\n    {\r\n      UInt32 si = 0;\r\n      UInt64 offset;\r\n      UInt64 inSize;\r\n      Byte *outBufCur = outBuffer;\r\n      SizeT outSizeCur = outSize;\r\n      if (folder->NumCoders == 4)\r\n      {\r\n        UInt32 indices[] = { 3, 2, 0 };\r\n        UInt64 unpackSize = folder->UnpackSizes[ci];\r\n        si = indices[ci];\r\n        if (ci < 2)\r\n        {\r\n          Byte *temp;\r\n          outSizeCur = (SizeT)unpackSize;\r\n          if (outSizeCur != unpackSize)\r\n            return SZ_ERROR_MEM;\r\n          temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);\r\n          if (temp == 0 && outSizeCur != 0)\r\n            return SZ_ERROR_MEM;\r\n          outBufCur = tempBuf[1 - ci] = temp;\r\n          tempSizes[1 - ci] = outSizeCur;\r\n        }\r\n        else if (ci == 2)\r\n        {\r\n          if (unpackSize > outSize) /* check it */\r\n            return SZ_ERROR_PARAM;\r\n          tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);\r\n          tempSize3 = outSizeCur = (SizeT)unpackSize;\r\n        }\r\n        else\r\n          return SZ_ERROR_UNSUPPORTED;\r\n      }\r\n      offset = GetSum(packSizes, si);\r\n      inSize = packSizes[si];\r\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r\n\r\n      if (coder->MethodID == k_Copy)\r\n      {\r\n        if (inSize != outSizeCur) /* check it */\r\n          return SZ_ERROR_DATA;\r\n        RINOK(SzDecodeCopy(inSize, inStream, outBufCur));\r\n      }\r\n      else\r\n      {\r\n        RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));\r\n      }\r\n    }\r\n    else if (coder->MethodID == k_BCJ)\r\n    {\r\n      UInt32 state;\r\n      if (ci != 1)\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      x86_Convert_Init(state);\r\n      x86_Convert(outBuffer, outSize, 0, &state, 0);\r\n    }\r\n    else if (coder->MethodID == k_BCJ2)\r\n    {\r\n      UInt64 offset = GetSum(packSizes, 1);\r\n      UInt64 s3Size = packSizes[1];\r\n      SRes res;\r\n      if (ci != 3)\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\r\n      tempSizes[2] = (SizeT)s3Size;\r\n      if (tempSizes[2] != s3Size)\r\n        return SZ_ERROR_MEM;\r\n      tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);\r\n      if (tempBuf[2] == 0 && tempSizes[2] != 0)\r\n        return SZ_ERROR_MEM;\r\n      res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);\r\n      RINOK(res)\r\n\r\n      res = Bcj2_Decode(\r\n          tempBuf3, tempSize3,\r\n          tempBuf[0], tempSizes[0],\r\n          tempBuf[1], tempSizes[1],\r\n          tempBuf[2], tempSizes[2],\r\n          outBuffer, outSize);\r\n      RINOK(res)\r\n    }\r\n    else\r\n      return SZ_ERROR_UNSUPPORTED;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *inStream, UInt64 startPos,\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\r\n{\r\n  Byte *tempBuf[3] = { 0, 0, 0};\r\n  int i;\r\n  SRes res = SzDecode2(packSizes, folder, inStream, startPos,\r\n      outBuffer, (SizeT)outSize, allocMain, tempBuf);\r\n  for (i = 0; i < 3; i++)\r\n    IAlloc_Free(allocMain, tempBuf[i]);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zDecode.h",
    "content": "/* 7zDecode.h -- Decoding from 7z folder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n\r\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\r\n    ILookInStream *stream, UInt64 startPos,\r\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zExtract.c",
    "content": "/* 7zExtract.c -- Extracting from 7z archive\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"7zDecode.h\"\r\n#include \"7zExtract.h\"\r\n\r\nSRes SzAr_Extract(\r\n    const CSzArEx *p,\r\n    ILookInStream *inStream,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer,\r\n    size_t *outBufferSize,\r\n    size_t *offset,\r\n    size_t *outSizeProcessed,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = p->FileIndexToFolderIndexMap[fileIndex];\r\n  SRes res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    IAlloc_Free(allocMain, *outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CSzFolder *folder = p->db.Folders + folderIndex;\r\n    UInt64 unpackSizeSpec = SzFolder_GetUnpackSize(folder);\r\n    size_t unpackSize = (size_t)unpackSizeSpec;\r\n    UInt64 startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);\r\n\r\n    if (unpackSize != unpackSizeSpec)\r\n      return SZ_ERROR_MEM;\r\n    *blockIndex = folderIndex;\r\n    IAlloc_Free(allocMain, *outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(LookInStream_SeekTo(inStream, startOffset));\r\n    \r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = unpackSize;\r\n      if (unpackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unpackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZ_ERROR_MEM;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        res = SzDecode(p->db.PackSizes +\r\n          p->FolderStartPackStreamIndex[folderIndex], folder,\r\n          inStream, startOffset,\r\n          *outBuffer, unpackSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (folder->UnpackCRCDefined)\r\n          {\r\n            if (CrcCalc(*outBuffer, unpackSize) != folder->UnpackCRC)\r\n              res = SZ_ERROR_CRC;\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i;\r\n    CSzFileItem *fileItem = p->db.Files + fileIndex;\r\n    *offset = 0;\r\n    for (i = p->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)p->db.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZ_ERROR_FAIL;\r\n    {\r\n      if (fileItem->FileCRCDefined)\r\n      {\r\n        if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)\r\n          res = SZ_ERROR_CRC;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zExtract.h",
    "content": "/* 7zExtract.h -- Extracting from 7z archive\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive.\r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send\r\n    these values from previous call:\r\n      *blockIndex,\r\n      *outBuffer,\r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid,\r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables\r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSRes SzAr_Extract(\r\n    const CSzArEx *db,\r\n    ILookInStream *inStream,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zHeader.c",
    "content": "/*  7zHeader.c -- 7z Headers\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zHeader.h",
    "content": "/* 7zHeader.h -- 7z Headers\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../Types.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnpackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnpackSize,\r\n  k7zIdNumUnpackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCTime,\r\n  k7zIdATime,\r\n  k7zIdMTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos,\r\n  k7zIdDummy\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zIn.c",
    "content": "/* 7zIn.c -- 7z Input functions\r\n2008-12-31 : Igor Pavlov : Public domain */\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"../../CpuArch.h\"\r\n\r\n#include \"7zDecode.h\"\r\n#include \"7zIn.h\"\r\n\r\n#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }\r\n\r\n#define NUM_FOLDER_CODERS_MAX 32\r\n#define NUM_CODER_STREAMS_MAX 32\r\n\r\nvoid SzArEx_Init(CSzArEx *p)\r\n{\r\n  SzAr_Init(&p->db);\r\n  p->FolderStartPackStreamIndex = 0;\r\n  p->PackStreamStartPositions = 0;\r\n  p->FolderStartFileIndex = 0;\r\n  p->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)\r\n{\r\n  IAlloc_Free(alloc, p->FolderStartPackStreamIndex);\r\n  IAlloc_Free(alloc, p->PackStreamStartPositions);\r\n  IAlloc_Free(alloc, p->FolderStartFileIndex);\r\n  IAlloc_Free(alloc, p->FileIndexToFolderIndexMap);\r\n  SzAr_Free(&p->db, alloc);\r\n  SzArEx_Init(p);\r\n}\r\n\r\n/*\r\nUInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nUInt64 GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CSzFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n#define MY_ALLOC(T, p, size, alloc) { if ((size) == 0) p = 0; else \\\r\n  if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == 0) return SZ_ERROR_MEM; }\r\n\r\nstatic SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 startPos = 0;\r\n  UInt64 startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  MY_ALLOC(UInt32, p->FolderStartPackStreamIndex, p->db.NumFolders, alloc);\r\n  for (i = 0; i < p->db.NumFolders; i++)\r\n  {\r\n    p->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += p->db.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  MY_ALLOC(UInt64, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);\r\n\r\n  for (i = 0; i < p->db.NumPackStreams; i++)\r\n  {\r\n    p->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += p->db.PackSizes[i];\r\n  }\r\n\r\n  MY_ALLOC(UInt32, p->FolderStartFileIndex, p->db.NumFolders, alloc);\r\n  MY_ALLOC(UInt32, p->FileIndexToFolderIndexMap, p->db.NumFiles, alloc);\r\n\r\n  for (i = 0; i < p->db.NumFiles; i++)\r\n  {\r\n    CSzFileItem *file = p->db.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      p->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= p->db.NumFolders)\r\n          return SZ_ERROR_ARCHIVE;\r\n        p->FolderStartFileIndex[folderIndex] = i;\r\n        if (p->db.Folders[folderIndex].NumUnpackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    p->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= p->db.Folders[folderIndex].NumUnpackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return p->dataPos +\r\n    p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize)\r\n{\r\n  UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];\r\n  CSzFolder *folder = p->db.Folders + folderIndex;\r\n  UInt64 size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n  {\r\n    UInt64 t = size + p->db.PackSizes[packStreamIndex + i];\r\n    if (t < size) /* check it */\r\n      return SZ_ERROR_FAIL;\r\n    size = t;\r\n  }\r\n  *resSize = size;\r\n  return SZ_OK;\r\n}\r\n\r\n\r\n/*\r\nSRes SzReadTime(const CObjectVector<CBuf> &dataVector,\r\n    CObjectVector<CSzFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for (int i = 0; i < files.Size(); i++)\r\n  {\r\n    CSzFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCTime: file.IsCTimeDefined = defined; if (defined) file.CTime = fileTime; break;\r\n      case k7zIdATime: file.IsATimeDefined = defined; if (defined) file.ATime = fileTime; break;\r\n      case k7zIdMTime: file.IsMTimeDefined = defined; if (defined) file.MTime = fileTime; break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nstatic int TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nstatic SRes SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZ_ERROR_ARCHIVE;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadID(CSzData *sd, UInt64 *value)\r\n{\r\n  return SzReadNumber(sd, value);\r\n}\r\n\r\nstatic SRes SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZ_ERROR_ARCHIVE;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nstatic SRes SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZ_ERROR_ARCHIVE;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nstatic SRes SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  MY_ALLOC(Byte, *v, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, alloc);\r\n  MY_ALLOC(Byte, *v, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadHashDigests(\r\n    CSzData *sd,\r\n    size_t numItems,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *alloc)\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, alloc));\r\n  MY_ALLOC(UInt32, *digests, numItems, alloc);\r\n  for (i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadPackInfo(\r\n    CSzData *sd,\r\n    UInt64 *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    UInt64 **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadNumber(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  MY_ALLOC(UInt64, *packSizes, (size_t)*numPackStreams, alloc);\r\n\r\n  for (i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadNumber(sd, (*packSizes) + i));\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, alloc);\r\n    MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, alloc);\r\n    for (i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZ_ERROR_UNSUPPORTED;\r\n}\r\n\r\nstatic SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)\r\n{\r\n  UInt32 numCoders, numBindPairs, numPackStreams, i;\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  if (numCoders > NUM_FOLDER_CODERS_MAX)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  folder->NumCoders = numCoders;\r\n  \r\n  MY_ALLOC(CSzCoderInfo, folder->Coders, (size_t)numCoders, alloc);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfo_Init(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CSzCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      unsigned idSize, j;\r\n      Byte longID[15];\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      idSize = (unsigned)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, longID, idSize));\r\n      if (idSize > sizeof(coder->MethodID))\r\n        return SZ_ERROR_UNSUPPORTED;\r\n      coder->MethodID = 0;\r\n      for (j = 0; j < idSize; j++)\r\n        coder->MethodID |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n        if (coder->NumInStreams > NUM_CODER_STREAMS_MAX ||\r\n            coder->NumOutStreams > NUM_CODER_STREAMS_MAX)\r\n          return SZ_ERROR_UNSUPPORTED;\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!Buf_Create(&coder->Props, (size_t)propertiesSize, alloc))\r\n          return SZ_ERROR_MEM;\r\n        RINOK(SzReadBytes(sd, coder->Props.data, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += coder->NumInStreams;\r\n    numOutStreams += coder->NumOutStreams;\r\n  }\r\n\r\n  if (numOutStreams == 0)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  folder->NumBindPairs = numBindPairs = numOutStreams - 1;\r\n  MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, alloc);\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bp = folder->BindPairs + i;\r\n    RINOK(SzReadNumber32(sd, &bp->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bp->OutIndex));\r\n  }\r\n\r\n  if (numInStreams < numBindPairs)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  folder->NumPackStreams = numPackStreams = numInStreams - numBindPairs;\r\n  MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackStreams, alloc);\r\n\r\n  if (numPackStreams == 1)\r\n  {\r\n    for (i = 0; i < numInStreams ; i++)\r\n      if (SzFolder_FindBindPairForInStream(folder, i) < 0)\r\n        break;\r\n    if (i == numInStreams)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    folder->PackStreams[0] = i;\r\n  }\r\n  else\r\n    for (i = 0; i < numPackStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadUnpackInfo(\r\n    CSzData *sd,\r\n    UInt32 *numFolders,\r\n    CSzFolder **folders,  /* for alloc */\r\n    ISzAlloc *alloc,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n    MY_ALLOC(CSzFolder, *folders, (size_t)*numFolders, alloc);\r\n\r\n    for (i = 0; i < *numFolders; i++)\r\n      SzFolder_Init((*folders) + i);\r\n\r\n    for (i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, alloc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnpackSize));\r\n\r\n  for (i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CSzFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);\r\n\r\n    MY_ALLOC(UInt64, folder->UnpackSizes, (size_t)numOutStreams, alloc);\r\n\r\n    for (j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadNumber(sd, folder->UnpackSizes + j));\r\n    }\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SRes res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < *numFolders; i++)\r\n        {\r\n          CSzFolder *folder = (*folders) + i;\r\n          folder->UnpackCRCDefined = crcsDefined[i];\r\n          folder->UnpackCRC = crcs[i];\r\n        }\r\n      }\r\n      IAlloc_Free(allocTemp, crcs);\r\n      IAlloc_Free(allocTemp, crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nstatic SRes SzReadSubStreamsInfo(\r\n    CSzData *sd,\r\n    UInt32 numFolders,\r\n    CSzFolder *folders,\r\n    UInt32 *numUnpackStreams,\r\n    UInt64 **unpackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n    folders[i].NumUnpackStreams = 1;\r\n  *numUnpackStreams = numFolders;\r\n\r\n  for (;;)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnpackStream)\r\n    {\r\n      *numUnpackStreams = 0;\r\n      for (i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnpackStreams = numStreams;\r\n        *numUnpackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnpackStreams == 0)\r\n  {\r\n    *unpackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unpackSizes = (UInt64 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt64));\r\n    RINOM(*unpackSizes);\r\n    *digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    UInt64 sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      UInt64 size;\r\n      RINOK(SzReadNumber(sd, &size));\r\n      (*unpackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unpackSizes)[si++] = SzFolder_GetUnpackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for (i = 0; i < *numUnpackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  for (;;)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0;\r\n      UInt32 *digests2 = 0;\r\n      SRes res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CSzFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnpackStreams;\r\n          if (numSubstreams == 1 && folder->UnpackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnpackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      IAlloc_Free(allocTemp, digestsDefined2);\r\n      IAlloc_Free(allocTemp, digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nstatic SRes SzReadStreamsInfo(\r\n    CSzData *sd,\r\n    UInt64 *dataOffset,\r\n    CSzAr *p,\r\n    UInt32 *numUnpackStreams,\r\n    UInt64 **unpackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    ISzAlloc *alloc,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZ_ERROR_UNSUPPORTED;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,\r\n            &p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc));\r\n        break;\r\n      }\r\n      case k7zIdUnpackInfo:\r\n      {\r\n        RINOK(SzReadUnpackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,\r\n            numUnpackStreams, unpackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZ_ERROR_UNSUPPORTED;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nstatic SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CSzFileItem *file = files + i;\r\n    while (pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZ_ERROR_ARCHIVE;\r\n        if (pos + 2 > sd->Size)\r\n          return SZ_ERROR_ARCHIVE;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZ_ERROR_ARCHIVE;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    MY_ALLOC(char, file->Name, (size_t)len, alloc);\r\n\r\n    len = 0;\r\n    while (2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while (numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadHeader2(\r\n    CSzArEx *p,   /* allocMain */\r\n    CSzData *sd,\r\n    UInt64 **unpackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    Byte **lwtVector,         /* allocTemp */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnpackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CSzFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &p->dataPos,\r\n        &p->db,\r\n        &numUnpackStreams,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests, allocMain, allocTemp));\r\n    p->dataPos += p->startPosAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZ_ERROR_ARCHIVE;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  p->db.NumFiles = numFiles;\r\n\r\n  MY_ALLOC(CSzFileItem, files, (size_t)numFiles, allocMain);\r\n\r\n  p->db.Files = files;\r\n  for (i = 0; i < numFiles; i++)\r\n    SzFile_Init(files + i);\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdMTime:\r\n      {\r\n        RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));\r\n        RINOK(SzReadSwitch(sd));\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CSzFileItem *f = &files[i];\r\n          Byte defined = (*lwtVector)[i];\r\n          f->MTimeDefined = defined;\r\n          f->MTime.Low = f->MTime.High = 0;\r\n          if (defined)\r\n          {\r\n            RINOK(SzReadUInt32(sd, &f->MTime.Low));\r\n            RINOK(SzReadUInt32(sd, &f->MTime.High));\r\n          }\r\n        }\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      CSzFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if (file->HasStream)\r\n      {\r\n        file->IsDir = 0;\r\n        file->Size = (*unpackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->FileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDir = 1;\r\n        else\r\n          file->IsDir = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->FileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArEx_Fill(p, allocMain);\r\n}\r\n\r\nstatic SRes SzReadHeader(\r\n    CSzArEx *p,\r\n    CSzData *sd,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 *unpackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  Byte *lwtVector = 0;\r\n  SRes res = SzReadHeader2(p, sd,\r\n      &unpackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector, &lwtVector,\r\n      allocMain, allocTemp);\r\n  IAlloc_Free(allocTemp, unpackSizes);\r\n  IAlloc_Free(allocTemp, digestsDefined);\r\n  IAlloc_Free(allocTemp, digests);\r\n  IAlloc_Free(allocTemp, emptyStreamVector);\r\n  IAlloc_Free(allocTemp, emptyFileVector);\r\n  IAlloc_Free(allocTemp, lwtVector);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzReadAndDecodePackedStreams2(\r\n    ILookInStream *inStream,\r\n    CSzData *sd,\r\n    CBuf *outBuffer,\r\n    UInt64 baseOffset,\r\n    CSzAr *p,\r\n    UInt64 **unpackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnpackStreams = 0;\r\n  UInt64 dataStartPos;\r\n  CSzFolder *folder;\r\n  UInt64 unpackSize;\r\n  SRes res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,\r\n      &numUnpackStreams,  unpackSizes, digestsDefined, digests,\r\n      allocTemp, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (p->NumFolders != 1)\r\n    return SZ_ERROR_ARCHIVE;\r\n\r\n  folder = p->Folders;\r\n  unpackSize = SzFolder_GetUnpackSize(folder);\r\n  \r\n  RINOK(LookInStream_SeekTo(inStream, dataStartPos));\r\n\r\n  if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))\r\n    return SZ_ERROR_MEM;\r\n  \r\n  res = SzDecode(p->PackSizes, folder,\r\n          inStream, dataStartPos,\r\n          outBuffer->data, (size_t)unpackSize, allocTemp);\r\n  RINOK(res);\r\n  if (folder->UnpackCRCDefined)\r\n    if (CrcCalc(outBuffer->data, (size_t)unpackSize) != folder->UnpackCRC)\r\n      return SZ_ERROR_CRC;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes SzReadAndDecodePackedStreams(\r\n    ILookInStream *inStream,\r\n    CSzData *sd,\r\n    CBuf *outBuffer,\r\n    UInt64 baseOffset,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  CSzAr p;\r\n  UInt64 *unpackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  SRes res;\r\n  SzAr_Init(&p);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,\r\n    &p, &unpackSizes, &digestsDefined, &digests,\r\n    allocTemp);\r\n  SzAr_Free(&p, allocTemp);\r\n  IAlloc_Free(allocTemp, unpackSizes);\r\n  IAlloc_Free(allocTemp, digestsDefined);\r\n  IAlloc_Free(allocTemp, digests);\r\n  return res;\r\n}\r\n\r\nstatic SRes SzArEx_Open2(\r\n    CSzArEx *p,\r\n    ILookInStream *inStream,\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte header[k7zStartHeaderSize];\r\n  UInt64 nextHeaderOffset, nextHeaderSize;\r\n  size_t nextHeaderSizeT;\r\n  UInt32 nextHeaderCRC;\r\n  CBuf buffer;\r\n  SRes res;\r\n\r\n  RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));\r\n\r\n  if (!TestSignatureCandidate(header))\r\n    return SZ_ERROR_NO_ARCHIVE;\r\n  if (header[6] != k7zMajorVersion)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  nextHeaderOffset = GetUi64(header + 12);\r\n  nextHeaderSize = GetUi64(header + 20);\r\n  nextHeaderCRC = GetUi32(header + 28);\r\n\r\n  p->startPosAfterHeader = k7zStartHeaderSize;\r\n  \r\n  if (CrcCalc(header + 12, 20) != GetUi32(header + 8))\r\n    return SZ_ERROR_CRC;\r\n\r\n  nextHeaderSizeT = (size_t)nextHeaderSize;\r\n  if (nextHeaderSizeT != nextHeaderSize)\r\n    return SZ_ERROR_MEM;\r\n  if (nextHeaderSizeT == 0)\r\n    return SZ_OK;\r\n  if (nextHeaderOffset > nextHeaderOffset + nextHeaderSize ||\r\n      nextHeaderOffset > nextHeaderOffset + nextHeaderSize + k7zStartHeaderSize)\r\n    return SZ_ERROR_NO_ARCHIVE;\r\n\r\n  {\r\n    Int64 pos = 0;\r\n    RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));\r\n    if ((UInt64)pos < nextHeaderOffset ||\r\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset ||\r\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)\r\n      return SZ_ERROR_INPUT_EOF;\r\n  }\r\n\r\n  RINOK(LookInStream_SeekTo(inStream, k7zStartHeaderSize + nextHeaderOffset));\r\n\r\n  if (!Buf_Create(&buffer, nextHeaderSizeT, allocTemp))\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LookInStream_Read(inStream, buffer.data, nextHeaderSizeT);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = SZ_ERROR_ARCHIVE;\r\n    if (CrcCalc(buffer.data, nextHeaderSizeT) == nextHeaderCRC)\r\n    {\r\n      CSzData sd;\r\n      UInt64 type;\r\n      sd.Data = buffer.data;\r\n      sd.Size = buffer.size;\r\n      res = SzReadID(&sd, &type);\r\n      if (res == SZ_OK)\r\n      {\r\n        if (type == k7zIdEncodedHeader)\r\n        {\r\n          CBuf outBuffer;\r\n          Buf_Init(&outBuffer);\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, p->startPosAfterHeader, allocTemp);\r\n          if (res != SZ_OK)\r\n            Buf_Free(&outBuffer, allocTemp);\r\n          else\r\n          {\r\n            Buf_Free(&buffer, allocTemp);\r\n            buffer.data = outBuffer.data;\r\n            buffer.size = outBuffer.size;\r\n            sd.Data = buffer.data;\r\n            sd.Size = buffer.size;\r\n            res = SzReadID(&sd, &type);\r\n          }\r\n        }\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        if (type == k7zIdHeader)\r\n          res = SzReadHeader(p, &sd, allocMain, allocTemp);\r\n        else\r\n          res = SZ_ERROR_UNSUPPORTED;\r\n      }\r\n    }\r\n  }\r\n  Buf_Free(&buffer, allocTemp);\r\n  return res;\r\n}\r\n\r\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)\r\n{\r\n  SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArEx_Free(p, allocMain);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zIn.h",
    "content": "/* 7zIn.h -- 7z Input functions\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n\r\ntypedef struct\r\n{\r\n  CSzAr db;\r\n  \r\n  UInt64 startPosAfterHeader;\r\n  UInt64 dataPos;\r\n\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  UInt64 *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n} CSzArEx;\r\n\r\nvoid SzArEx_Init(CSzArEx *p);\r\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);\r\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);\r\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);\r\n\r\n/*\r\nErrors:\r\nSZ_ERROR_NO_ARCHIVE\r\nSZ_ERROR_ARCHIVE\r\nSZ_ERROR_UNSUPPORTED\r\nSZ_ERROR_MEM\r\nSZ_ERROR_CRC\r\nSZ_ERROR_INPUT_EOF\r\nSZ_ERROR_FAIL\r\n*/\r\n\r\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zItem.c",
    "content": "/* 7zItem.c -- 7z Items\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"7zItem.h\"\r\n\r\nvoid SzCoderInfo_Init(CSzCoderInfo *p)\r\n{\r\n  Buf_Init(&p->Props);\r\n}\r\n\r\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc)\r\n{\r\n  Buf_Free(&p->Props, alloc);\r\n  SzCoderInfo_Init(p);\r\n}\r\n\r\nvoid SzFolder_Init(CSzFolder *p)\r\n{\r\n  p->Coders = 0;\r\n  p->BindPairs = 0;\r\n  p->PackStreams = 0;\r\n  p->UnpackSizes = 0;\r\n  p->NumCoders = 0;\r\n  p->NumBindPairs = 0;\r\n  p->NumPackStreams = 0;\r\n  p->UnpackCRCDefined = 0;\r\n  p->UnpackCRC = 0;\r\n  p->NumUnpackStreams = 0;\r\n}\r\n\r\nvoid SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  if (p->Coders)\r\n    for (i = 0; i < p->NumCoders; i++)\r\n      SzCoderInfo_Free(&p->Coders[i], alloc);\r\n  IAlloc_Free(alloc, p->Coders);\r\n  IAlloc_Free(alloc, p->BindPairs);\r\n  IAlloc_Free(alloc, p->PackStreams);\r\n  IAlloc_Free(alloc, p->UnpackSizes);\r\n  SzFolder_Init(p);\r\n}\r\n\r\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumCoders; i++)\r\n    result += p->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumBindPairs; i++)\r\n    if (p->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->NumBindPairs; i++)\r\n    if (p->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p)\r\n{\r\n  int i = (int)SzFolder_GetNumOutStreams(p);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolder_FindBindPairForOutStream(p, i) < 0)\r\n      return p->UnpackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\nvoid SzFile_Init(CSzFileItem *p)\r\n{\r\n  p->HasStream = 1;\r\n  p->IsDir = 0;\r\n  p->IsAnti = 0;\r\n  p->FileCRCDefined = 0;\r\n  p->MTimeDefined = 0;\r\n  p->Name = 0;\r\n}\r\n\r\nstatic void SzFile_Free(CSzFileItem *p, ISzAlloc *alloc)\r\n{\r\n  IAlloc_Free(alloc, p->Name);\r\n  SzFile_Init(p);\r\n}\r\n\r\nvoid SzAr_Init(CSzAr *p)\r\n{\r\n  p->PackSizes = 0;\r\n  p->PackCRCsDefined = 0;\r\n  p->PackCRCs = 0;\r\n  p->Folders = 0;\r\n  p->Files = 0;\r\n  p->NumPackStreams = 0;\r\n  p->NumFolders = 0;\r\n  p->NumFiles = 0;\r\n}\r\n\r\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc)\r\n{\r\n  UInt32 i;\r\n  if (p->Folders)\r\n    for (i = 0; i < p->NumFolders; i++)\r\n      SzFolder_Free(&p->Folders[i], alloc);\r\n  if (p->Files)\r\n    for (i = 0; i < p->NumFiles; i++)\r\n      SzFile_Free(&p->Files[i], alloc);\r\n  IAlloc_Free(alloc, p->PackSizes);\r\n  IAlloc_Free(alloc, p->PackCRCsDefined);\r\n  IAlloc_Free(alloc, p->PackCRCs);\r\n  IAlloc_Free(alloc, p->Folders);\r\n  IAlloc_Free(alloc, p->Files);\r\n  SzAr_Init(p);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zItem.h",
    "content": "/* 7zItem.h -- 7z Items\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../7zBuf.h\"\r\n\r\ntypedef struct\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  UInt64 MethodID;\r\n  CBuf Props;\r\n} CSzCoderInfo;\r\n\r\nvoid SzCoderInfo_Init(CSzCoderInfo *p);\r\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc);\r\n\r\ntypedef struct\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n} CBindPair;\r\n\r\ntypedef struct\r\n{\r\n  CSzCoderInfo *Coders;\r\n  CBindPair *BindPairs;\r\n  UInt32 *PackStreams;\r\n  UInt64 *UnpackSizes;\r\n  UInt32 NumCoders;\r\n  UInt32 NumBindPairs;\r\n  UInt32 NumPackStreams;\r\n  int UnpackCRCDefined;\r\n  UInt32 UnpackCRC;\r\n\r\n  UInt32 NumUnpackStreams;\r\n} CSzFolder;\r\n\r\nvoid SzFolder_Init(CSzFolder *p);\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);\r\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p);\r\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\r\n\r\ntypedef struct\r\n{\r\n  UInt32 Low;\r\n  UInt32 High;\r\n} CNtfsFileTime;\r\n\r\ntypedef struct\r\n{\r\n  CNtfsFileTime MTime;\r\n  UInt64 Size;\r\n  char *Name;\r\n  UInt32 FileCRC;\r\n\r\n  Byte HasStream;\r\n  Byte IsDir;\r\n  Byte IsAnti;\r\n  Byte FileCRCDefined;\r\n  Byte MTimeDefined;\r\n} CSzFileItem;\r\n\r\nvoid SzFile_Init(CSzFileItem *p);\r\n\r\ntypedef struct\r\n{\r\n  UInt64 *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  CSzFolder *Folders;\r\n  CSzFileItem *Files;\r\n  UInt32 NumPackStreams;\r\n  UInt32 NumFolders;\r\n  UInt32 NumFiles;\r\n} CSzAr;\r\n\r\nvoid SzAr_Init(CSzAr *p);\r\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/7zMain.c",
    "content": "/* 7zMain.c - Test application for 7z Decoder\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#include <stdlib.h>\r\n#include <stdio.h>\r\n#include <string.h>\r\n\r\n#include \"../../7zCrc.h\"\r\n#include \"../../7zFile.h\"\r\n#include \"../../7zVersion.h\"\r\n\r\n#include \"7zAlloc.h\"\r\n#include \"7zExtract.h\"\r\n#include \"7zIn.h\"\r\n\r\nstatic void ConvertNumberToString(UInt64 value, char *s)\r\n{\r\n  char temp[32];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (char)('0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\n#define PERIOD_4 (4 * 365 + 1)\r\n#define PERIOD_100 (PERIOD_4 * 25 - 1)\r\n#define PERIOD_400 (PERIOD_100 * 4 + 1)\r\n\r\nstatic void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)\r\n{\r\n  unsigned year, mon, day, hour, min, sec;\r\n  UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  unsigned temp;\r\n  UInt32 v;\r\n  v64 /= 10000000;\r\n  sec = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  min = (unsigned)(v64 % 60);\r\n  v64 /= 60;\r\n  hour = (unsigned)(v64 % 24);\r\n  v64 /= 24;\r\n\r\n  v = (UInt32)v64;\r\n\r\n  year = (unsigned)(1601 + v / PERIOD_400 * 400);\r\n  v %= PERIOD_400;\r\n\r\n  temp = (unsigned)(v / PERIOD_100);\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp * 100;\r\n  v -= temp * PERIOD_100;\r\n\r\n  temp = v / PERIOD_4;\r\n  if (temp == 25)\r\n    temp = 24;\r\n  year += temp * 4;\r\n  v -= temp * PERIOD_4;\r\n\r\n  temp = v / 365;\r\n  if (temp == 4)\r\n    temp = 3;\r\n  year += temp;\r\n  v -= temp * 365;\r\n\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  for (mon = 1; mon <= 12; mon++)\r\n  {\r\n    unsigned s = ms[mon - 1];\r\n    if (v < s)\r\n      break;\r\n    v -= s;\r\n  }\r\n  day = (unsigned)v + 1;\r\n  sprintf(s, \"%04d-%02d-%02d %02d:%02d:%02d\", year, mon, day, hour, min, sec);\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint MY_CDECL main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CLookToRead lookStream;\r\n  CSzArEx db;\r\n  SRes res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  if (InFile_Open(&archiveStream.file, args[2]))\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  \r\n  FileInStream_CreateVTable(&archiveStream);\r\n  LookToRead_CreateVTable(&lookStream, False);\r\n  \r\n  lookStream.realStream = &archiveStream.s;\r\n  LookToRead_Init(&lookStream);\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  CrcGenerateTable();\r\n\r\n  SzArEx_Init(&db);\r\n  res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0, testCommand = 0, extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0) listCommand = 1;\r\n    else if (strcmp(command, \"t\") == 0) testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0) extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        CSzFileItem *f = db.db.Files + i;\r\n        char s[32], t[32];\r\n        ConvertNumberToString(f->Size, s);\r\n        if (f->MTimeDefined)\r\n          ConvertFileTimeToString(&f->MTime, t);\r\n        else\r\n          strcpy(t, \"                   \");\r\n\r\n        printf(\"%s %10s  %s\\n\", t, s, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      /*\r\n      if you need cache, use these 3 variables.\r\n      if you use external function, you can make these variable as static.\r\n      */\r\n      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\r\n      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\r\n      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.db.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CSzFileItem *f = db.db.Files + i;\r\n        if (f->IsDir)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ?\r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDir)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzAr_Extract(&db, &lookStream.s, i,\r\n            &blockIndex, &outBuffer, &outBufferSize,\r\n            &offset, &outSizeProcessed,\r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          CSzFile outFile;\r\n          size_t processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          if (OutFile_Open(&outFile, fileName))\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n          processedSize = outSizeProcessed;\r\n          if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 ||\r\n              processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n          if (File_Close(&outFile))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZ_ERROR_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      IAlloc_Free(&allocImp, outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZ_ERROR_FAIL;\r\n    }\r\n  }\r\n  SzArEx_Free(&db, &allocImp);\r\n\r\n  File_Close(&archiveStream.file);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == SZ_ERROR_UNSUPPORTED)\r\n    PrintError(\"decoder doesn't support this archive\");\r\n  else if (res == SZ_ERROR_MEM)\r\n    PrintError(\"can not allocate memory\");\r\n  else if (res == SZ_ERROR_CRC)\r\n    PrintError(\"CRC error\");\r\n  else\r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/makefile",
    "content": "MY_STATIC_LINK=1\r\n\r\nPROG = 7zDec.exe\r\n\r\nC_OBJS = \\\r\n  $O\\7zBuf.obj \\\r\n  $O\\7zBuf2.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\Bcj2.obj \\\r\n  $O\\7zFile.obj \\\r\n  $O\\7zStream.obj \\\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $(C_OBJS) \\\r\n\r\n!include \"../../../CPP/Build.mak\"\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL_O1)\r\n$(C_OBJS): ../../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Archive/7z/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB =\r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = 7zAlloc.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o 7zFile.o 7zStream.o\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuf.o: ../../7zBuf.c\r\n\t$(CXX) $(CFLAGS) ../../7zBuf.c\r\n\r\n7zBuf2.o: ../../7zBuf2.c\r\n\t$(CXX) $(CFLAGS) ../../7zBuf2.c\r\n\r\n7zCrc.o: ../../7zCrc.c\r\n\t$(CXX) $(CFLAGS) ../../7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\nLzmaDec.o: ../../LzmaDec.c\r\n\t$(CXX) $(CFLAGS) ../../LzmaDec.c\r\n\r\nBra86.o: ../../Bra86.c\r\n\t$(CXX) $(CFLAGS) ../../Bra86.c\r\n\r\nBcj2.o: ../../Bcj2.c\r\n\t$(CXX) $(CFLAGS) ../../Bcj2.c\r\n\r\n7zFile.o: ../../7zFile.c\r\n\t$(CXX) $(CFLAGS) ../../7zFile.c\r\n\r\n7zStream.o: ../../7zStream.c\r\n\t$(CXX) $(CFLAGS) ../../7zStream.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Bcj2.c",
    "content": "/* Bcj2.c -- Converter for x86 code (BCJ2)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bcj2.h\"\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb UInt16\r\n#endif\r\n\r\n#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)\r\n#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*buffer++)\r\n#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }\r\n#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \\\r\n  { int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }}\r\n\r\n#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;\r\n\r\nint Bcj2_Decode(\r\n    const Byte *buf0, SizeT size0,\r\n    const Byte *buf1, SizeT size1,\r\n    const Byte *buf2, SizeT size2,\r\n    const Byte *buf3, SizeT size3,\r\n    Byte *outBuf, SizeT outSize)\r\n{\r\n  CProb p[256 + 2];\r\n  SizeT inPos = 0, outPos = 0;\r\n\r\n  const Byte *buffer, *bufferLim;\r\n  UInt32 range, code;\r\n  Byte prevByte = 0;\r\n\r\n  unsigned int i;\r\n  for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)\r\n    p[i] = kBitModelTotal >> 1;\r\n\r\n  buffer = buf3;\r\n  bufferLim = buffer + size3;\r\n  RC_INIT2\r\n\r\n  if (outSize == 0)\r\n    return SZ_OK;\r\n\r\n  for (;;)\r\n  {\r\n    Byte b;\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    UInt32 ttt;\r\n\r\n    SizeT limit = size0 - inPos;\r\n    if (outSize - outPos < limit)\r\n      limit = outSize - outPos;\r\n    while (limit != 0)\r\n    {\r\n      Byte b = buf0[inPos];\r\n      outBuf[outPos++] = b;\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      inPos++;\r\n      prevByte = b;\r\n      limit--;\r\n    }\r\n\r\n    if (limit == 0 || outPos == outSize)\r\n      break;\r\n\r\n    b = buf0[inPos++];\r\n\r\n    if (b == 0xE8)\r\n      prob = p + prevByte;\r\n    else if (b == 0xE9)\r\n      prob = p + 256;\r\n    else\r\n      prob = p + 257;\r\n\r\n    IF_BIT_0(prob)\r\n    {\r\n      UPDATE_0(prob)\r\n      prevByte = b;\r\n    }\r\n    else\r\n    {\r\n      UInt32 dest;\r\n      const Byte *v;\r\n      UPDATE_1(prob)\r\n      if (b == 0xE8)\r\n      {\r\n        v = buf1;\r\n        if (size1 < 4)\r\n          return SZ_ERROR_DATA;\r\n        buf1 += 4;\r\n        size1 -= 4;\r\n      }\r\n      else\r\n      {\r\n        v = buf2;\r\n        if (size2 < 4)\r\n          return SZ_ERROR_DATA;\r\n        buf2 += 4;\r\n        size2 -= 4;\r\n      }\r\n      dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |\r\n          ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);\r\n      outBuf[outPos++] = (Byte)dest;\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 8);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = (Byte)(dest >> 16);\r\n      if (outPos == outSize)\r\n        break;\r\n      outBuf[outPos++] = prevByte = (Byte)(dest >> 24);\r\n    }\r\n  }\r\n  return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Bcj2.h",
    "content": "/* Bcj2.h -- Converter for x86 code (BCJ2)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __BCJ2_H\r\n#define __BCJ2_H\r\n\r\n#include \"Types.h\"\r\n\r\n/*\r\nConditions:\r\n  outSize <= FullOutputSize,\r\n  where FullOutputSize is full size of output stream of x86_2 filter.\r\n\r\nIf buf0 overlaps outBuf, there are two required conditions:\r\n  1) (buf0 >= outBuf)\r\n  2) (buf0 + size0 >= outBuf + FullOutputSize).\r\n\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nint Bcj2_Decode(\r\n    const Byte *buf0, SizeT size0,\r\n    const Byte *buf1, SizeT size1,\r\n    const Byte *buf2, SizeT size2,\r\n    const Byte *buf3, SizeT size3,\r\n    Byte *outBuf, SizeT outSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Bra.c",
    "content": "/* Bra.c -- Converters for RISC code\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  ip += 8;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      dest >>= 2;\r\n      data[i + 2] = (Byte)(dest >> 16);\r\n      data[i + 1] = (Byte)(dest >> 8);\r\n      data[i + 0] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  ip += 4;\r\n  for (i = 0; i <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 &&\r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 dest;\r\n      UInt32 src =\r\n        (((UInt32)data[i + 1] & 0x7) << 19) |\r\n        ((UInt32)data[i + 0] << 11) |\r\n        (((UInt32)data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));\r\n      data[i + 0] = (Byte)(dest >> 11);\r\n      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));\r\n      data[i + 2] = (Byte)dest;\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)\r\n    {\r\n      UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = ip + (UInt32)i + src;\r\n      else\r\n        dest = src - (ip + (UInt32)i);\r\n      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n\r\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  UInt32 i;\r\n  if (size < 4)\r\n    return 0;\r\n  size -= 4;\r\n  for (i = 0; i <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||\r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src =\r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      UInt32 dest;\r\n      \r\n      src <<= 2;\r\n      if (encoding)\r\n        dest = ip + i + src;\r\n      else\r\n        dest = src - (ip + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Bra.h",
    "content": "/* Bra.h -- Branch converters for executables\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __BRA_H\r\n#define __BRA_H\r\n\r\n#include \"Types.h\"\r\n\r\n/*\r\nThese functions convert relative addresses to absolute addresses\r\nin CALL instructions to increase the compression ratio.\r\n  \r\n  In:\r\n    data     - data buffer\r\n    size     - size of data\r\n    ip       - current virtual Instruction Pinter (IP) value\r\n    state    - state variable for x86 converter\r\n    encoding - 0 (for decoding), 1 (for encoding)\r\n  \r\n  Out:\r\n    state    - state variable for x86 converter\r\n\r\n  Returns:\r\n    The number of processed bytes. If you call these functions with multiple calls,\r\n    you must start next call with first byte after block of processed bytes.\r\n  \r\n  Type   Endian  Alignment  LookAhead\r\n  \r\n  x86    little      1          4\r\n  ARMT   little      2          2\r\n  ARM    little      4          0\r\n  PPC     big        4          0\r\n  SPARC   big        4          0\r\n  IA64   little     16          0\r\n\r\n  size must be >= Alignment + LookAhead, if it's not last block.\r\n  If (size < Alignment + LookAhead), converter returns 0.\r\n\r\n  Example:\r\n\r\n    UInt32 ip = 0;\r\n    for ()\r\n    {\r\n      ; size must be >= Alignment + LookAhead, if it's not last block\r\n      SizeT processed = Convert(data, size, ip, 1);\r\n      data += processed;\r\n      size -= processed;\r\n      ip += processed;\r\n    }\r\n*/\r\n\r\n#define x86_Convert_Init(state) { state = 0; }\r\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);\r\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Bra86.c",
    "content": "/* Bra86.c -- Converter for x86 code (BCJ)\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)\r\n{\r\n  SizeT bufferPos = 0, prevPosT;\r\n  UInt32 prevMask = *state & 0x7;\r\n  if (size < 5)\r\n    return 0;\r\n  ip += 5;\r\n  prevPosT = (SizeT)0 - 1;\r\n\r\n  for (;;)\r\n  {\r\n    Byte *p = data + bufferPos;\r\n    Byte *limit = data + size - 4;\r\n    for (; p < limit; p++)\r\n      if ((*p & 0xFE) == 0xE8)\r\n        break;\r\n    bufferPos = (SizeT)(p - data);\r\n    if (p >= limit)\r\n      break;\r\n    prevPosT = bufferPos - prevPosT;\r\n    if (prevPosT > 3)\r\n      prevMask = 0;\r\n    else\r\n    {\r\n      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r\n      if (prevMask != 0)\r\n      {\r\n        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r\n        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r\n        {\r\n          prevPosT = bufferPos;\r\n          prevMask = ((prevMask << 1) & 0x7) | 1;\r\n          bufferPos++;\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    prevPosT = bufferPos;\r\n\r\n    if (Test86MSByte(p[4]))\r\n    {\r\n      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r\n      UInt32 dest;\r\n      for (;;)\r\n      {\r\n        Byte b;\r\n        int index;\r\n        if (encoding)\r\n          dest = (ip + (UInt32)bufferPos) + src;\r\n        else\r\n          dest = src - (ip + (UInt32)bufferPos);\r\n        if (prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[prevMask] * 8;\r\n        b = (Byte)(dest >> (24 - index));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index)) - 1);\r\n      }\r\n      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      p[3] = (Byte)(dest >> 16);\r\n      p[2] = (Byte)(dest >> 8);\r\n      p[1] = (Byte)dest;\r\n      bufferPos += 5;\r\n    }\r\n    else\r\n    {\r\n      prevMask = ((prevMask << 1) & 0x7) | 1;\r\n      bufferPos++;\r\n    }\r\n  }\r\n  prevPosT = bufferPos - prevPosT;\r\n  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/BraIA64.c",
    "content": "/* BraIA64.c -- Converter for IA-64 code\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"Bra.h\"\r\n\r\nstatic const Byte kBranchTable[32] =\r\n{\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0\r\n};\r\n\r\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\r\n{\r\n  SizeT i;\r\n  if (size < 16)\r\n    return 0;\r\n  size -= 16;\r\n  for (i = 0; i <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    int slot;\r\n    for (slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      UInt32 bytePos, bitRes;\r\n      UInt64 instruction, instNorm;\r\n      int j;\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      bytePos = (bitPos >> 3);\r\n      bitRes = bitPos & 0x7;\r\n      instruction = 0;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)data[i + j + bytePos] << (8 * j);\r\n\r\n      instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)\r\n      {\r\n        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);\r\n        UInt32 dest;\r\n        src |= ((UInt32)(instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        if (encoding)\r\n          dest = ip + (UInt32)i + src;\r\n        else\r\n          dest = src - (ip + (UInt32)i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~((UInt64)(0x8FFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);\r\n        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/CpuArch.h",
    "content": "/* CpuArch.h\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __CPUARCH_H\r\n#define __CPUARCH_H\r\n\r\n/*\r\nLITTLE_ENDIAN_UNALIGN means:\r\n  1) CPU is LITTLE_ENDIAN\r\n  2) it's allowed to make unaligned memory accesses\r\nif LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know\r\nabout these properties of platform.\r\n*/\r\n\r\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r\n#define LITTLE_ENDIAN_UNALIGN\r\n#endif\r\n\r\n#ifdef LITTLE_ENDIAN_UNALIGN\r\n\r\n#define GetUi16(p) (*(const UInt16 *)(p))\r\n#define GetUi32(p) (*(const UInt32 *)(p))\r\n#define GetUi64(p) (*(const UInt64 *)(p))\r\n#define SetUi32(p, d) *(UInt32 *)(p) = (d);\r\n\r\n#else\r\n\r\n#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))\r\n\r\n#define GetUi32(p) ( \\\r\n             ((const Byte *)(p))[0]        | \\\r\n    ((UInt32)((const Byte *)(p))[1] <<  8) | \\\r\n    ((UInt32)((const Byte *)(p))[2] << 16) | \\\r\n    ((UInt32)((const Byte *)(p))[3] << 24))\r\n\r\n#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))\r\n\r\n#define SetUi32(p, d) { UInt32 _x_ = (d); \\\r\n    ((Byte *)(p))[0] = (Byte)_x_; \\\r\n    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \\\r\n    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \\\r\n    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }\r\n\r\n#endif\r\n\r\n#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)\r\n\r\n#pragma intrinsic(_byteswap_ulong)\r\n#pragma intrinsic(_byteswap_uint64)\r\n#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))\r\n#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))\r\n\r\n#else\r\n\r\n#define GetBe32(p) ( \\\r\n    ((UInt32)((const Byte *)(p))[0] << 24) | \\\r\n    ((UInt32)((const Byte *)(p))[1] << 16) | \\\r\n    ((UInt32)((const Byte *)(p))[2] <<  8) | \\\r\n             ((const Byte *)(p))[3] )\r\n\r\n#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))\r\n\r\n#endif\r\n\r\n#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzFind.c",
    "content": "/* LzFind.c -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"LzFind.h\"\r\n#include \"LzHash.h\"\r\n\r\n#define kEmptyHashValue 0\r\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\r\n#define kMaxHistorySize ((UInt32)3 << 30)\r\n\r\n#define kStartMaxLen 3\r\n\r\nstatic void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  if (!p->directInput)\r\n  {\r\n    alloc->Free(alloc, p->bufferBase);\r\n    p->bufferBase = 0;\r\n  }\r\n}\r\n\r\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\r\n\r\nstatic int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\r\n{\r\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\r\n  if (p->directInput)\r\n  {\r\n    p->blockSize = blockSize;\r\n    return 1;\r\n  }\r\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\r\n  {\r\n    LzInWindow_Free(p, alloc);\r\n    p->blockSize = blockSize;\r\n    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r\n  }\r\n  return (p->bufferBase != 0);\r\n}\r\n\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r\n\r\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r\n\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\r\n{\r\n  p->posLimit -= subValue;\r\n  p->pos -= subValue;\r\n  p->streamPos -= subValue;\r\n}\r\n\r\nstatic void MatchFinder_ReadBlock(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached || p->result != SZ_OK)\r\n    return;\r\n  for (;;)\r\n  {\r\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\r\n    size_t size = (p->bufferBase + p->blockSize - dest);\r\n    if (size == 0)\r\n      return;\r\n    p->result = p->stream->Read(p->stream, dest, &size);\r\n    if (p->result != SZ_OK)\r\n      return;\r\n    if (size == 0)\r\n    {\r\n      p->streamEndWasReached = 1;\r\n      return;\r\n    }\r\n    p->streamPos += (UInt32)size;\r\n    if (p->streamPos - p->pos > p->keepSizeAfter)\r\n      return;\r\n  }\r\n}\r\n\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\r\n{\r\n  memmove(p->bufferBase,\r\n    p->buffer - p->keepSizeBefore,\r\n    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\r\n  p->buffer = p->bufferBase + p->keepSizeBefore;\r\n}\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p)\r\n{\r\n  /* if (p->streamEndWasReached) return 0; */\r\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r\n}\r\n\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\r\n{\r\n  if (p->streamEndWasReached)\r\n    return;\r\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\r\n    MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\r\n{\r\n  if (MatchFinder_NeedMove(p))\r\n    MatchFinder_MoveBlock(p);\r\n  MatchFinder_ReadBlock(p);\r\n}\r\n\r\nstatic void MatchFinder_SetDefaultSettings(CMatchFinder *p)\r\n{\r\n  p->cutValue = 32;\r\n  p->btMode = 1;\r\n  p->numHashBytes = 4;\r\n  /* p->skipModeBits = 0; */\r\n  p->directInput = 0;\r\n  p->bigHash = 0;\r\n}\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  p->bufferBase = 0;\r\n  p->directInput = 0;\r\n  p->hash = 0;\r\n  MatchFinder_SetDefaultSettings(p);\r\n\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r\n    p->crc[i] = r;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hash);\r\n  p->hash = 0;\r\n}\r\n\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r\n{\r\n  MatchFinder_FreeThisClassMemory(p, alloc);\r\n  LzInWindow_Free(p, alloc);\r\n}\r\n\r\nstatic CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r\n{\r\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r\n  if (sizeInBytes / sizeof(CLzRef) != num)\r\n    return 0;\r\n  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r\n}\r\n\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc)\r\n{\r\n  UInt32 sizeReserv;\r\n  if (historySize > kMaxHistorySize)\r\n  {\r\n    MatchFinder_Free(p, alloc);\r\n    return 0;\r\n  }\r\n  sizeReserv = historySize >> 1;\r\n  if (historySize > ((UInt32)2 << 30))\r\n    sizeReserv = historySize >> 2;\r\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r\n\r\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r\n  if (LzInWindow_Create(p, sizeReserv, alloc))\r\n  {\r\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r\n    UInt32 hs;\r\n    p->matchMaxLen = matchMaxLen;\r\n    {\r\n      p->fixedHashSize = 0;\r\n      if (p->numHashBytes == 2)\r\n        hs = (1 << 16) - 1;\r\n      else\r\n      {\r\n        hs = historySize - 1;\r\n        hs |= (hs >> 1);\r\n        hs |= (hs >> 2);\r\n        hs |= (hs >> 4);\r\n        hs |= (hs >> 8);\r\n        hs >>= 1;\r\n        /* hs >>= p->skipModeBits; */\r\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r\n        if (hs > (1 << 24))\r\n        {\r\n          if (p->numHashBytes == 3)\r\n            hs = (1 << 24) - 1;\r\n          else\r\n            hs >>= 1;\r\n        }\r\n      }\r\n      p->hashMask = hs;\r\n      hs++;\r\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\r\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\r\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\r\n      hs += p->fixedHashSize;\r\n    }\r\n\r\n    {\r\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\r\n      UInt32 newSize;\r\n      p->historySize = historySize;\r\n      p->hashSizeSum = hs;\r\n      p->cyclicBufferSize = newCyclicBufferSize;\r\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r\n      newSize = p->hashSizeSum + p->numSons;\r\n      if (p->hash != 0 && prevSize == newSize)\r\n        return 1;\r\n      MatchFinder_FreeThisClassMemory(p, alloc);\r\n      p->hash = AllocRefs(newSize, alloc);\r\n      if (p->hash != 0)\r\n      {\r\n        p->son = p->hash + p->hashSizeSum;\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  MatchFinder_Free(p, alloc);\r\n  return 0;\r\n}\r\n\r\nstatic void MatchFinder_SetLimits(CMatchFinder *p)\r\n{\r\n  UInt32 limit = kMaxValForNormalize - p->pos;\r\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  limit2 = p->streamPos - p->pos;\r\n  if (limit2 <= p->keepSizeAfter)\r\n  {\r\n    if (limit2 > 0)\r\n      limit2 = 1;\r\n  }\r\n  else\r\n    limit2 -= p->keepSizeAfter;\r\n  if (limit2 < limit)\r\n    limit = limit2;\r\n  {\r\n    UInt32 lenLimit = p->streamPos - p->pos;\r\n    if (lenLimit > p->matchMaxLen)\r\n      lenLimit = p->matchMaxLen;\r\n    p->lenLimit = lenLimit;\r\n  }\r\n  p->posLimit = p->pos + limit;\r\n}\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < p->hashSizeSum; i++)\r\n    p->hash[i] = kEmptyHashValue;\r\n  p->cyclicBufferPos = 0;\r\n  p->buffer = p->bufferBase;\r\n  p->pos = p->streamPos = p->cyclicBufferSize;\r\n  p->result = SZ_OK;\r\n  p->streamEndWasReached = 0;\r\n  MatchFinder_ReadBlock(p);\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r\n{\r\n  return (p->pos - p->historySize - 1) & kNormalizeMask;\r\n}\r\n\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n}\r\n\r\nstatic void MatchFinder_Normalize(CMatchFinder *p)\r\n{\r\n  UInt32 subValue = MatchFinder_GetSubValue(p);\r\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r\n  MatchFinder_ReduceOffsets(p, subValue);\r\n}\r\n\r\nstatic void MatchFinder_CheckLimits(CMatchFinder *p)\r\n{\r\n  if (p->pos == kMaxValForNormalize)\r\n    MatchFinder_Normalize(p);\r\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\r\n    MatchFinder_CheckAndMoveAndRead(p);\r\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\r\n    p->cyclicBufferPos = 0;\r\n  MatchFinder_SetLimits(p);\r\n}\r\n\r\nstatic UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  son[_cyclicBufferPos] = curMatch;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n      return distances;\r\n    {\r\n      const Byte *pb = cur - delta;\r\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\r\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\r\n      {\r\n        UInt32 len = 0;\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n            return distances;\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\r\n    UInt32 *distances, UInt32 maxLen)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return distances;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return distances;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\r\n{\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      return;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        while (++len != lenLimit)\r\n          if (pb[len] != cur[len])\r\n            break;\r\n        {\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            return;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define MOVE_POS \\\r\n  ++p->cyclicBufferPos; \\\r\n  p->buffer++; \\\r\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\r\n\r\n#define MOVE_POS_RET MOVE_POS return offset;\r\n\r\nstatic void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r\n\r\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\r\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\r\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\r\n  cur = p->buffer;\r\n\r\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\r\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\r\n\r\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\r\n\r\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\r\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\r\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\r\n\r\n#define SKIP_FOOTER \\\r\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r\n\r\nstatic UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(2)\r\n  HASH2_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 1)\r\n}\r\n\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = 0;\r\n  GET_MATCHES_FOOTER(offset, 2)\r\n}\r\n\r\nstatic UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, delta2, maxLen, offset;\r\n  GET_MATCHES_HEADER(3)\r\n\r\n  HASH3_CALC;\r\n\r\n  delta2 = p->pos - p->hash[hash2Value];\r\n  curMatch = p->hash[kFix3HashSize + hashValue];\r\n  \r\n  p->hash[hash2Value] =\r\n  p->hash[kFix3HashSize + hashValue] = p->pos;\r\n\r\n\r\n  maxLen = 2;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[0] = maxLen;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n  \r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  GET_MATCHES_FOOTER(offset, maxLen)\r\n}\r\n\r\nstatic UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r\n  GET_MATCHES_HEADER(4)\r\n\r\n  HASH4_CALC;\r\n\r\n  delta2 = p->pos - p->hash[                hash2Value];\r\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r\n  curMatch = p->hash[kFix4HashSize + hashValue];\r\n\r\n  p->hash[                hash2Value] =\r\n  p->hash[kFix3HashSize + hash3Value] =\r\n  p->hash[kFix4HashSize + hashValue] = p->pos;\r\n\r\n  maxLen = 1;\r\n  offset = 0;\r\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r\n  {\r\n    distances[0] = maxLen = 2;\r\n    distances[1] = delta2 - 1;\r\n    offset = 2;\r\n  }\r\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r\n  {\r\n    maxLen = 3;\r\n    distances[offset + 1] = delta3 - 1;\r\n    offset += 2;\r\n    delta2 = delta3;\r\n  }\r\n  if (offset != 0)\r\n  {\r\n    for (; maxLen != lenLimit; maxLen++)\r\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r\n        break;\r\n    distances[offset - 2] = maxLen;\r\n    if (maxLen == lenLimit)\r\n    {\r\n      p->son[p->cyclicBufferPos] = curMatch;\r\n      MOVE_POS_RET;\r\n    }\r\n  }\r\n  if (maxLen < 3)\r\n    maxLen = 3;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances + offset, maxLen) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r\n{\r\n  UInt32 offset;\r\n  GET_MATCHES_HEADER(3)\r\n  HASH_ZIP_CALC;\r\n  curMatch = p->hash[hashValue];\r\n  p->hash[hashValue] = p->pos;\r\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r\n    distances, 2) - (distances));\r\n  MOVE_POS_RET\r\n}\r\n\r\nstatic void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(2)\r\n    HASH2_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value;\r\n    SKIP_HEADER(3)\r\n    HASH3_CALC;\r\n    curMatch = p->hash[kFix3HashSize + hashValue];\r\n    p->hash[hash2Value] =\r\n    p->hash[kFix3HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    SKIP_FOOTER\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nstatic void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    UInt32 hash2Value, hash3Value;\r\n    SKIP_HEADER(4)\r\n    HASH4_CALC;\r\n    curMatch = p->hash[kFix4HashSize + hashValue];\r\n    p->hash[                hash2Value] =\r\n    p->hash[kFix3HashSize + hash3Value] =\r\n    p->hash[kFix4HashSize + hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r\n{\r\n  do\r\n  {\r\n    SKIP_HEADER(3)\r\n    HASH_ZIP_CALC;\r\n    curMatch = p->hash[hashValue];\r\n    p->hash[hashValue] = p->pos;\r\n    p->son[p->cyclicBufferPos] = curMatch;\r\n    MOVE_POS\r\n  }\r\n  while (--num != 0);\r\n}\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r\n  if (!p->btMode)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 2)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\r\n  }\r\n  else if (p->numHashBytes == 3)\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r\n  }\r\n  else\r\n  {\r\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzFind.h",
    "content": "/* LzFind.h -- Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFIND_H\r\n#define __LZFIND_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef UInt32 CLzRef;\r\n\r\ntypedef struct _CMatchFinder\r\n{\r\n  Byte *buffer;\r\n  UInt32 pos;\r\n  UInt32 posLimit;\r\n  UInt32 streamPos;\r\n  UInt32 lenLimit;\r\n\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r\n\r\n  UInt32 matchMaxLen;\r\n  CLzRef *hash;\r\n  CLzRef *son;\r\n  UInt32 hashMask;\r\n  UInt32 cutValue;\r\n\r\n  Byte *bufferBase;\r\n  ISeqInStream *stream;\r\n  int streamEndWasReached;\r\n\r\n  UInt32 blockSize;\r\n  UInt32 keepSizeBefore;\r\n  UInt32 keepSizeAfter;\r\n\r\n  UInt32 numHashBytes;\r\n  int directInput;\r\n  int btMode;\r\n  /* int skipModeBits; */\r\n  int bigHash;\r\n  UInt32 historySize;\r\n  UInt32 fixedHashSize;\r\n  UInt32 hashSizeSum;\r\n  UInt32 numSons;\r\n  SRes result;\r\n  UInt32 crc[256];\r\n} CMatchFinder;\r\n\r\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r\n\r\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r\n\r\nint MatchFinder_NeedMove(CMatchFinder *p);\r\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\r\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\r\n\r\nvoid MatchFinder_Construct(CMatchFinder *p);\r\n\r\n/* Conditions:\r\n     historySize <= 3 GB\r\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\r\n*/\r\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\r\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r\n    ISzAlloc *alloc);\r\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r\n\r\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *distances, UInt32 maxLen);\r\n\r\n/*\r\nConditions:\r\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\r\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\r\n*/\r\n\r\ntypedef void (*Mf_Init_Func)(void *object);\r\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\r\n\r\ntypedef struct _IMatchFinder\r\n{\r\n  Mf_Init_Func Init;\r\n  Mf_GetIndexByte_Func GetIndexByte;\r\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r\n  Mf_GetMatches_Func GetMatches;\r\n  Mf_Skip_Func Skip;\r\n} IMatchFinder;\r\n\r\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r\n\r\nvoid MatchFinder_Init(CMatchFinder *p);\r\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzFindMt.c",
    "content": "/* LzFindMt.c -- multithreaded Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzHash.h\"\r\n\r\n#include \"LzFindMt.h\"\r\n\r\nvoid MtSync_Construct(CMtSync *p)\r\n{\r\n  p->wasCreated = False;\r\n  p->csWasInitialized = False;\r\n  p->csWasEntered = False;\r\n  Thread_Construct(&p->thread);\r\n  Event_Construct(&p->canStart);\r\n  Event_Construct(&p->wasStarted);\r\n  Event_Construct(&p->wasStopped);\r\n  Semaphore_Construct(&p->freeSemaphore);\r\n  Semaphore_Construct(&p->filledSemaphore);\r\n}\r\n\r\nvoid MtSync_GetNextBlock(CMtSync *p)\r\n{\r\n  if (p->needStart)\r\n  {\r\n    p->numProcessedBlocks = 1;\r\n    p->needStart = False;\r\n    p->stopWriting = False;\r\n    p->exit = False;\r\n    Event_Reset(&p->wasStarted);\r\n    Event_Reset(&p->wasStopped);\r\n\r\n    Event_Set(&p->canStart);\r\n    Event_Wait(&p->wasStarted);\r\n  }\r\n  else\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n    p->numProcessedBlocks++;\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  Semaphore_Wait(&p->filledSemaphore);\r\n  CriticalSection_Enter(&p->cs);\r\n  p->csWasEntered = True;\r\n}\r\n\r\n/* MtSync_StopWriting must be called if Writing was started */\r\n\r\nvoid MtSync_StopWriting(CMtSync *p)\r\n{\r\n  UInt32 myNumBlocks = p->numProcessedBlocks;\r\n  if (!Thread_WasCreated(&p->thread) || p->needStart)\r\n    return;\r\n  p->stopWriting = True;\r\n  if (p->csWasEntered)\r\n  {\r\n    CriticalSection_Leave(&p->cs);\r\n    p->csWasEntered = False;\r\n  }\r\n  Semaphore_Release1(&p->freeSemaphore);\r\n \r\n  Event_Wait(&p->wasStopped);\r\n\r\n  while (myNumBlocks++ != p->numProcessedBlocks)\r\n  {\r\n    Semaphore_Wait(&p->filledSemaphore);\r\n    Semaphore_Release1(&p->freeSemaphore);\r\n  }\r\n  p->needStart = True;\r\n}\r\n\r\nvoid MtSync_Destruct(CMtSync *p)\r\n{\r\n  if (Thread_WasCreated(&p->thread))\r\n  {\r\n    MtSync_StopWriting(p);\r\n    p->exit = True;\r\n    if (p->needStart)\r\n      Event_Set(&p->canStart);\r\n    Thread_Wait(&p->thread);\r\n    Thread_Close(&p->thread);\r\n  }\r\n  if (p->csWasInitialized)\r\n  {\r\n    CriticalSection_Delete(&p->cs);\r\n    p->csWasInitialized = False;\r\n  }\r\n\r\n  Event_Close(&p->canStart);\r\n  Event_Close(&p->wasStarted);\r\n  Event_Close(&p->wasStopped);\r\n  Semaphore_Close(&p->freeSemaphore);\r\n  Semaphore_Close(&p->filledSemaphore);\r\n\r\n  p->wasCreated = False;\r\n}\r\n\r\n#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }\r\n\r\nstatic SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  if (p->wasCreated)\r\n    return SZ_OK;\r\n\r\n  RINOK_THREAD(CriticalSection_Init(&p->cs));\r\n  p->csWasInitialized = True;\r\n\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));\r\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));\r\n  \r\n  RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));\r\n  RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));\r\n\r\n  p->needStart = True;\r\n  \r\n  RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));\r\n  p->wasCreated = True;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r\n{\r\n  SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\r\n  if (res != SZ_OK)\r\n    MtSync_Destruct(p);\r\n  return res;\r\n}\r\n\r\nvoid MtSync_Init(CMtSync *p) { p->needStart = True; }\r\n\r\n#define kMtMaxValForNormalize 0xFFFFFFFF\r\n\r\n#define DEF_GetHeads2(name, v, action) \\\r\nstatic void GetHeads ## name(const Byte *p, UInt32 pos, \\\r\nUInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \\\r\n{ action; for (; numHeads != 0; numHeads--) { \\\r\nconst UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r\n\r\n#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)\r\n\r\nDEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )\r\nDEF_GetHeads(3,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\r\nDEF_GetHeads(4,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)\r\nDEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\r\nDEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)\r\n\r\nvoid HashThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->hashSync;\r\n  for (;;)\r\n  {\r\n    UInt32 numProcessedBlocks = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = numProcessedBlocks;\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n\r\n      {\r\n        CMatchFinder *mf = mt->MatchFinder;\r\n        if (MatchFinder_NeedMove(mf))\r\n        {\r\n          CriticalSection_Enter(&mt->btSync.cs);\r\n          CriticalSection_Enter(&mt->hashSync.cs);\r\n          {\r\n            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            const Byte *afterPtr;\r\n            MatchFinder_MoveBlock(mf);\r\n            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);\r\n            mt->pointerToCurPos -= beforePtr - afterPtr;\r\n            mt->buffer -= beforePtr - afterPtr;\r\n          }\r\n          CriticalSection_Leave(&mt->btSync.cs);\r\n          CriticalSection_Leave(&mt->hashSync.cs);\r\n          continue;\r\n        }\r\n\r\n        Semaphore_Wait(&p->freeSemaphore);\r\n\r\n        MatchFinder_ReadIfRequired(mf);\r\n        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))\r\n        {\r\n          UInt32 subValue = (mf->pos - mf->historySize - 1);\r\n          MatchFinder_ReduceOffsets(mf, subValue);\r\n          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);\r\n        }\r\n        {\r\n          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n          UInt32 num = mf->streamPos - mf->pos;\r\n          heads[0] = 2;\r\n          heads[1] = num;\r\n          if (num >= mf->numHashBytes)\r\n          {\r\n            num = num - mf->numHashBytes + 1;\r\n            if (num > kMtHashBlockSize - 2)\r\n              num = kMtHashBlockSize - 2;\r\n            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);\r\n            heads[0] += num;\r\n          }\r\n          mf->pos += num;\r\n          mf->buffer += num;\r\n        }\r\n      }\r\n\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r\n{\r\n  MtSync_GetNextBlock(&p->hashSync);\r\n  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r\n  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];\r\n  p->hashNumAvail = p->hashBuf[p->hashBufPos++];\r\n}\r\n\r\n#define kEmptyHashValue 0\r\n\r\n/* #define MFMT_GM_INLINE */\r\n\r\n#ifdef MFMT_GM_INLINE\r\n\r\n#define NO_INLINE MY_FAST_CALL\r\n\r\nInt32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,\r\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r\n    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\r\n{\r\n  do\r\n  {\r\n  UInt32 *distances = _distances + 1;\r\n  UInt32 curMatch = pos - *hash++;\r\n\r\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\r\n  UInt32 len0 = 0, len1 = 0;\r\n  UInt32 cutValue = _cutValue;\r\n  UInt32 maxLen = _maxLen;\r\n  for (;;)\r\n  {\r\n    UInt32 delta = pos - curMatch;\r\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\r\n    {\r\n      *ptr0 = *ptr1 = kEmptyHashValue;\r\n      break;\r\n    }\r\n    {\r\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\r\n      const Byte *pb = cur - delta;\r\n      UInt32 len = (len0 < len1 ? len0 : len1);\r\n      if (pb[len] == cur[len])\r\n      {\r\n        if (++len != lenLimit && pb[len] == cur[len])\r\n          while (++len != lenLimit)\r\n            if (pb[len] != cur[len])\r\n              break;\r\n        if (maxLen < len)\r\n        {\r\n          *distances++ = maxLen = len;\r\n          *distances++ = delta - 1;\r\n          if (len == lenLimit)\r\n          {\r\n            *ptr1 = pair[0];\r\n            *ptr0 = pair[1];\r\n            break;\r\n          }\r\n        }\r\n      }\r\n      if (pb[len] < cur[len])\r\n      {\r\n        *ptr1 = curMatch;\r\n        ptr1 = pair + 1;\r\n        curMatch = *ptr1;\r\n        len1 = len;\r\n      }\r\n      else\r\n      {\r\n        *ptr0 = curMatch;\r\n        ptr0 = pair;\r\n        curMatch = *ptr0;\r\n        len0 = len;\r\n      }\r\n    }\r\n  }\r\n  pos++;\r\n  _cyclicBufferPos++;\r\n  cur++;\r\n  {\r\n    UInt32 num = (UInt32)(distances - _distances);\r\n    *_distances = num - 1;\r\n    _distances += num;\r\n    limit -= num;\r\n  }\r\n  }\r\n  while (limit > 0 && --size != 0);\r\n  *posRes = pos;\r\n  return limit;\r\n}\r\n\r\n#endif\r\n\r\nvoid BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  UInt32 numProcessed = 0;\r\n  UInt32 curPos = 2;\r\n  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\r\n  distances[1] = p->hashNumAvail;\r\n  while (curPos < limit)\r\n  {\r\n    if (p->hashBufPos == p->hashBufPosLimit)\r\n    {\r\n      MatchFinderMt_GetNextBlock_Hash(p);\r\n      distances[1] = numProcessed + p->hashNumAvail;\r\n      if (p->hashNumAvail >= p->numHashBytes)\r\n        continue;\r\n      for (; p->hashNumAvail != 0; p->hashNumAvail--)\r\n        distances[curPos++] = 0;\r\n      break;\r\n    }\r\n    {\r\n      UInt32 size = p->hashBufPosLimit - p->hashBufPos;\r\n      UInt32 lenLimit = p->matchMaxLen;\r\n      UInt32 pos = p->pos;\r\n      UInt32 cyclicBufferPos = p->cyclicBufferPos;\r\n      if (lenLimit >= p->hashNumAvail)\r\n        lenLimit = p->hashNumAvail;\r\n      {\r\n        UInt32 size2 = p->hashNumAvail - lenLimit + 1;\r\n        if (size2 < size)\r\n          size = size2;\r\n        size2 = p->cyclicBufferSize - cyclicBufferPos;\r\n        if (size2 < size)\r\n          size = size2;\r\n      }\r\n      #ifndef MFMT_GM_INLINE\r\n      while (curPos < limit && size-- != 0)\r\n      {\r\n        UInt32 *startDistances = distances + curPos;\r\n        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],\r\n          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r\n          startDistances + 1, p->numHashBytes - 1) - startDistances);\r\n        *startDistances = num - 1;\r\n        curPos += num;\r\n        cyclicBufferPos++;\r\n        pos++;\r\n        p->buffer++;\r\n      }\r\n      #else\r\n      {\r\n        UInt32 posRes;\r\n        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r\n          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);\r\n        p->hashBufPos += posRes - pos;\r\n        cyclicBufferPos += posRes - pos;\r\n        p->buffer += posRes - pos;\r\n        pos = posRes;\r\n      }\r\n      #endif\r\n\r\n      numProcessed += pos - p->pos;\r\n      p->hashNumAvail -= pos - p->pos;\r\n      p->pos = pos;\r\n      if (cyclicBufferPos == p->cyclicBufferSize)\r\n        cyclicBufferPos = 0;\r\n      p->cyclicBufferPos = cyclicBufferPos;\r\n    }\r\n  }\r\n  distances[0] = curPos;\r\n}\r\n\r\nvoid BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r\n{\r\n  CMtSync *sync = &p->hashSync;\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Enter(&sync->cs);\r\n    sync->csWasEntered = True;\r\n  }\r\n  \r\n  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);\r\n\r\n  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\r\n  {\r\n    UInt32 subValue = p->pos - p->cyclicBufferSize;\r\n    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);\r\n    p->pos -= subValue;\r\n  }\r\n\r\n  if (!sync->needStart)\r\n  {\r\n    CriticalSection_Leave(&sync->cs);\r\n    sync->csWasEntered = False;\r\n  }\r\n}\r\n\r\nvoid BtThreadFunc(CMatchFinderMt *mt)\r\n{\r\n  CMtSync *p = &mt->btSync;\r\n  for (;;)\r\n  {\r\n    UInt32 blockIndex = 0;\r\n    Event_Wait(&p->canStart);\r\n    Event_Set(&p->wasStarted);\r\n    for (;;)\r\n    {\r\n      if (p->exit)\r\n        return;\r\n      if (p->stopWriting)\r\n      {\r\n        p->numProcessedBlocks = blockIndex;\r\n        MtSync_StopWriting(&mt->hashSync);\r\n        Event_Set(&p->wasStopped);\r\n        break;\r\n      }\r\n      Semaphore_Wait(&p->freeSemaphore);\r\n      BtFillBlock(mt, blockIndex++);\r\n      Semaphore_Release1(&p->filledSemaphore);\r\n    }\r\n  }\r\n}\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p)\r\n{\r\n  p->hashBuf = 0;\r\n  MtSync_Construct(&p->hashSync);\r\n  MtSync_Construct(&p->btSync);\r\n}\r\n\r\nvoid MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->hashBuf);\r\n  p->hashBuf = 0;\r\n}\r\n\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r\n{\r\n  MtSync_Destruct(&p->hashSync);\r\n  MtSync_Destruct(&p->btSync);\r\n  MatchFinderMt_FreeMem(p, alloc);\r\n}\r\n\r\n#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\r\n#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\r\n\r\nstatic unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r\nstatic unsigned MY_STD_CALL BtThreadFunc2(void *p)\r\n{\r\n  Byte allocaDummy[0x180];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  BtThreadFunc((CMatchFinderMt *)p);\r\n  return 0;\r\n}\r\n\r\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\r\n{\r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->historySize = historySize;\r\n  if (kMtBtBlockSize <= matchMaxLen * 4)\r\n    return SZ_ERROR_PARAM;\r\n  if (p->hashBuf == 0)\r\n  {\r\n    p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r\n    if (p->hashBuf == 0)\r\n      return SZ_ERROR_MEM;\r\n    p->btBuf = p->hashBuf + kHashBufferSize;\r\n  }\r\n  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);\r\n  keepAddBufferAfter += kMtHashBlockSize;\r\n  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))\r\n    return SZ_ERROR_MEM;\r\n\r\n  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));\r\n  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));\r\n  return SZ_OK;\r\n}\r\n\r\n/* Call it after ReleaseStream / SetStream */\r\nvoid MatchFinderMt_Init(CMatchFinderMt *p)\r\n{\r\n  CMatchFinder *mf = p->MatchFinder;\r\n  p->btBufPos = p->btBufPosLimit = 0;\r\n  p->hashBufPos = p->hashBufPosLimit = 0;\r\n  MatchFinder_Init(mf);\r\n  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);\r\n  p->btNumAvailBytes = 0;\r\n  p->lzPos = p->historySize + 1;\r\n\r\n  p->hash = mf->hash;\r\n  p->fixedHashSize = mf->fixedHashSize;\r\n  p->crc = mf->crc;\r\n\r\n  p->son = mf->son;\r\n  p->matchMaxLen = mf->matchMaxLen;\r\n  p->numHashBytes = mf->numHashBytes;\r\n  p->pos = mf->pos;\r\n  p->buffer = mf->buffer;\r\n  p->cyclicBufferPos = mf->cyclicBufferPos;\r\n  p->cyclicBufferSize = mf->cyclicBufferSize;\r\n  p->cutValue = mf->cutValue;\r\n}\r\n\r\n/* ReleaseStream is required to finish multithreading */\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p)\r\n{\r\n  MtSync_StopWriting(&p->btSync);\r\n  /* p->MatchFinder->ReleaseStream(); */\r\n}\r\n\r\nvoid MatchFinderMt_Normalize(CMatchFinderMt *p)\r\n{\r\n  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\r\n  p->lzPos = p->historySize + 1;\r\n}\r\n\r\nvoid MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r\n{\r\n  UInt32 blockIndex;\r\n  MtSync_GetNextBlock(&p->btSync);\r\n  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);\r\n  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;\r\n  p->btBufPosLimit += p->btBuf[p->btBufPos++];\r\n  p->btNumAvailBytes = p->btBuf[p->btBufPos++];\r\n  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)\r\n    MatchFinderMt_Normalize(p);\r\n}\r\n\r\nconst Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r\n{\r\n  return p->pointerToCurPos;\r\n}\r\n\r\n#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\r\n\r\nUInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r\n{\r\n  GET_NEXT_BLOCK_IF_REQUIRED;\r\n  return p->btNumAvailBytes;\r\n}\r\n\r\nByte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)\r\n{\r\n  return p->pointerToCurPos[index];\r\n}\r\n\r\nUInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, curMatch2;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH2_CALC\r\n      \r\n  curMatch2 = hash[hash2Value];\r\n  hash[hash2Value] = lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos)\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n    {\r\n      *distances++ = 2;\r\n      *distances++ = lzPos - curMatch2 - 1;\r\n    }\r\n  return distances;\r\n}\r\n\r\nUInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH3_CALC\r\n\r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  \r\n  hash[                hash2Value] =\r\n  hash[kFix3HashSize + hash3Value] =\r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] = 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    *distances++ = 3;\r\n    *distances++ = lzPos - curMatch3 - 1;\r\n  }\r\n  return distances;\r\n}\r\n\r\n/*\r\nUInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r\n{\r\n  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;\r\n  UInt32 *hash = p->hash;\r\n  const Byte *cur = p->pointerToCurPos;\r\n  UInt32 lzPos = p->lzPos;\r\n  MT_HASH4_CALC\r\n      \r\n  curMatch2 = hash[                hash2Value];\r\n  curMatch3 = hash[kFix3HashSize + hash3Value];\r\n  curMatch4 = hash[kFix4HashSize + hash4Value];\r\n  \r\n  hash[                hash2Value] =\r\n  hash[kFix3HashSize + hash3Value] =\r\n  hash[kFix4HashSize + hash4Value] =\r\n    lzPos;\r\n\r\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch2 - 1;\r\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r\n    {\r\n      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 2;\r\n    distances += 2;\r\n  }\r\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r\n  {\r\n    distances[1] = lzPos - curMatch3 - 1;\r\n    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])\r\n    {\r\n      distances[0] = 4;\r\n      return distances + 2;\r\n    }\r\n    distances[0] = 3;\r\n    distances += 2;\r\n  }\r\n\r\n  if (curMatch4 >= matchMinPos)\r\n    if (\r\n      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&\r\n      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]\r\n      )\r\n    {\r\n      *distances++ = 4;\r\n      *distances++ = lzPos - curMatch4 - 1;\r\n    }\r\n  return distances;\r\n}\r\n*/\r\n\r\n#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\r\n\r\nUInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n  p->btNumAvailBytes--;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < len; i += 2)\r\n    {\r\n      *distances++ = *btBuf++;\r\n      *distances++ = *btBuf++;\r\n    }\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\nUInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r\n{\r\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\r\n  UInt32 len = *btBuf++;\r\n  p->btBufPos += 1 + len;\r\n\r\n  if (len == 0)\r\n  {\r\n    if (p->btNumAvailBytes-- >= 4)\r\n      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\r\n  }\r\n  else\r\n  {\r\n    /* Condition: there are matches in btBuf with length < p->numHashBytes */\r\n    UInt32 *distances2;\r\n    p->btNumAvailBytes--;\r\n    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\r\n    do\r\n    {\r\n      *distances2++ = *btBuf++;\r\n      *distances2++ = *btBuf++;\r\n    }\r\n    while ((len -= 2) != 0);\r\n    len  = (UInt32)(distances2 - (distances));\r\n  }\r\n  INCREASE_LZ_POS\r\n  return len;\r\n}\r\n\r\n#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED\r\n#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r\n#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);\r\n\r\nvoid MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER2 { p->btNumAvailBytes--;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(2)\r\n      UInt32 hash2Value;\r\n      MT_HASH2_CALC\r\n      hash[hash2Value] = p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\nvoid MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(3)\r\n      UInt32 hash2Value, hash3Value;\r\n      MT_HASH3_CALC\r\n      hash[kFix3HashSize + hash3Value] =\r\n      hash[                hash2Value] =\r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n\r\n/*\r\nvoid MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r\n{\r\n  SKIP_HEADER(4)\r\n      UInt32 hash2Value, hash3Value, hash4Value;\r\n      MT_HASH4_CALC\r\n      hash[kFix4HashSize + hash4Value] =\r\n      hash[kFix3HashSize + hash3Value] =\r\n      hash[                hash2Value] =\r\n        p->lzPos;\r\n  SKIP_FOOTER\r\n}\r\n*/\r\n\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\r\n{\r\n  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\r\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;\r\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\r\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\r\n  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\r\n  switch(p->MatchFinder->numHashBytes)\r\n  {\r\n    case 2:\r\n      p->GetHeadsFunc = GetHeads2;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)0;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\r\n      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\r\n      break;\r\n    case 3:\r\n      p->GetHeadsFunc = GetHeads3;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;\r\n      break;\r\n    default:\r\n    /* case 4: */\r\n      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\r\n      /* p->GetHeadsFunc = GetHeads4; */\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\r\n      break;\r\n    /*\r\n    default:\r\n      p->GetHeadsFunc = GetHeads5;\r\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;\r\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;\r\n      break;\r\n    */\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzFindMt.h",
    "content": "/* LzFindMt.h -- multithreaded Match finder for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZFINDMT_H\r\n#define __LZFINDMT_H\r\n\r\n#include \"Threads.h\"\r\n#include \"LzFind.h\"\r\n\r\n#define kMtHashBlockSize (1 << 13)\r\n#define kMtHashNumBlocks (1 << 3)\r\n#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)\r\n\r\n#define kMtBtBlockSize (1 << 14)\r\n#define kMtBtNumBlocks (1 << 6)\r\n#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)\r\n\r\ntypedef struct _CMtSync\r\n{\r\n  Bool wasCreated;\r\n  Bool needStart;\r\n  Bool exit;\r\n  Bool stopWriting;\r\n\r\n  CThread thread;\r\n  CAutoResetEvent canStart;\r\n  CAutoResetEvent wasStarted;\r\n  CAutoResetEvent wasStopped;\r\n  CSemaphore freeSemaphore;\r\n  CSemaphore filledSemaphore;\r\n  Bool csWasInitialized;\r\n  Bool csWasEntered;\r\n  CCriticalSection cs;\r\n  UInt32 numProcessedBlocks;\r\n} CMtSync;\r\n\r\ntypedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);\r\n\r\n/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */\r\n#define kMtCacheLineDummy 128\r\n\r\ntypedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,\r\n  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);\r\n\r\ntypedef struct _CMatchFinderMt\r\n{\r\n  /* LZ */\r\n  const Byte *pointerToCurPos;\r\n  UInt32 *btBuf;\r\n  UInt32 btBufPos;\r\n  UInt32 btBufPosLimit;\r\n  UInt32 lzPos;\r\n  UInt32 btNumAvailBytes;\r\n\r\n  UInt32 *hash;\r\n  UInt32 fixedHashSize;\r\n  UInt32 historySize;\r\n  const UInt32 *crc;\r\n\r\n  Mf_Mix_Matches MixMatchesFunc;\r\n  \r\n  /* LZ + BT */\r\n  CMtSync btSync;\r\n  Byte btDummy[kMtCacheLineDummy];\r\n\r\n  /* BT */\r\n  UInt32 *hashBuf;\r\n  UInt32 hashBufPos;\r\n  UInt32 hashBufPosLimit;\r\n  UInt32 hashNumAvail;\r\n\r\n  CLzRef *son;\r\n  UInt32 matchMaxLen;\r\n  UInt32 numHashBytes;\r\n  UInt32 pos;\r\n  Byte *buffer;\r\n  UInt32 cyclicBufferPos;\r\n  UInt32 cyclicBufferSize; /* it must be historySize + 1 */\r\n  UInt32 cutValue;\r\n\r\n  /* BT + Hash */\r\n  CMtSync hashSync;\r\n  /* Byte hashDummy[kMtCacheLineDummy]; */\r\n  \r\n  /* Hash */\r\n  Mf_GetHeads GetHeadsFunc;\r\n  CMatchFinder *MatchFinder;\r\n} CMatchFinderMt;\r\n\r\nvoid MatchFinderMt_Construct(CMatchFinderMt *p);\r\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);\r\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);\r\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\r\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzHash.h",
    "content": "/* LzHash.h -- HASH functions for LZ algorithms\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZHASH_H\r\n#define __LZHASH_H\r\n\r\n#define kHash2Size (1 << 10)\r\n#define kHash3Size (1 << 16)\r\n#define kHash4Size (1 << 20)\r\n\r\n#define kFix3HashSize (kHash2Size)\r\n#define kFix4HashSize (kHash2Size + kHash3Size)\r\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r\n\r\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r\n\r\n#define HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r\n\r\n#define HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r\n\r\n#define HASH5_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\\r\n  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\\r\n  hash4Value &= (kHash4Size - 1); }\r\n\r\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r\n\r\n\r\n#define MT_HASH2_CALC \\\r\n  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r\n\r\n#define MT_HASH3_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r\n\r\n#define MT_HASH4_CALC { \\\r\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\r\n  hash2Value = temp & (kHash2Size - 1); \\\r\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\r\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaDec.c",
    "content": "/* LzmaDec.c -- LZMA Decoder\r\n2008-11-06 : Igor Pavlov : Public domain */\r\n\r\n#include \"LzmaDec.h\"\r\n\r\n#include <string.h>\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_INIT_SIZE 5\r\n\r\n#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\r\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));\r\n#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \\\r\n  { UPDATE_0(p); i = (i + i); A0; } else \\\r\n  { UPDATE_1(p); i = (i + i) + 1; A1; }\r\n#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)\r\n\r\n#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }\r\n#define TREE_DECODE(probs, limit, i) \\\r\n  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }\r\n\r\n/* #define _LZMA_SIZE_OPT */\r\n\r\n#ifdef _LZMA_SIZE_OPT\r\n#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)\r\n#else\r\n#define TREE_6_DECODE(probs, i) \\\r\n  { i = 1; \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  TREE_GET_BIT(probs, i); \\\r\n  i -= 0x40; }\r\n#endif\r\n\r\n#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r\n\r\n#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r\n#define UPDATE_0_CHECK range = bound;\r\n#define UPDATE_1_CHECK range -= bound; code -= bound;\r\n#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \\\r\n  { UPDATE_0_CHECK; i = (i + i); A0; } else \\\r\n  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }\r\n#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)\r\n#define TREE_DECODE_CHECK(probs, limit, i) \\\r\n  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols)\r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nstatic const Byte kLiteralNextStates[kNumStates * 2] =\r\n{\r\n  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\r\n  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\r\n};\r\n\r\n#define LZMA_DIC_MIN (1 << 12)\r\n\r\n/* First LZMA-symbol is always decoded.\r\nAnd it decodes new LZMA-symbols while (buf < bufLimit), but \"buf\" is without last normalization\r\nOut:\r\n  Result:\r\n    SZ_OK - OK\r\n    SZ_ERROR_DATA - Error\r\n  p->remainLen:\r\n    < kMatchSpecLenStart : normal remain\r\n    = kMatchSpecLenStart : finished\r\n    = kMatchSpecLenStart + 1 : Flush marker\r\n    = kMatchSpecLenStart + 2 : State Init Marker\r\n*/\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  CLzmaProb *probs = p->probs;\r\n\r\n  unsigned state = p->state;\r\n  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];\r\n  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;\r\n  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;\r\n  unsigned lc = p->prop.lc;\r\n\r\n  Byte *dic = p->dic;\r\n  SizeT dicBufSize = p->dicBufSize;\r\n  SizeT dicPos = p->dicPos;\r\n  \r\n  UInt32 processedPos = p->processedPos;\r\n  UInt32 checkDicSize = p->checkDicSize;\r\n  unsigned len = 0;\r\n\r\n  const Byte *buf = p->buf;\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n\r\n  do\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = processedPos & pbMask;\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0(prob)\r\n    {\r\n      unsigned symbol;\r\n      UPDATE_0(prob);\r\n      prob = probs + Literal;\r\n      if (checkDicSize != 0 || processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r\n        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        symbol = 1;\r\n        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      dic[dicPos++] = (Byte)symbol;\r\n      processedPos++;\r\n\r\n      state = kLiteralNextStates[state];\r\n      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\r\n      continue;\r\n    }\r\n    else\r\n    {\r\n      UPDATE_1(prob);\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0(prob)\r\n      {\r\n        UPDATE_0(prob);\r\n        state += kNumStates;\r\n        prob = probs + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1(prob);\r\n        if (checkDicSize == 0 && processedPos == 0)\r\n          return SZ_ERROR_DATA;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0(prob)\r\n        {\r\n          UPDATE_0(prob);\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n            dicPos++;\r\n            processedPos++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            continue;\r\n          }\r\n          UPDATE_1(prob);\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UPDATE_1(prob);\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0(prob)\r\n          {\r\n            UPDATE_0(prob);\r\n            distance = rep1;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(prob);\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0(prob)\r\n            {\r\n              UPDATE_0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0(probLen)\r\n        {\r\n          UPDATE_0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = (1 << kLenNumLowBits);\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0(probLen)\r\n          {\r\n            UPDATE_0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = (1 << kLenNumMidBits);\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = (1 << kLenNumHighBits);\r\n          }\r\n        }\r\n        TREE_DECODE(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state >= kNumStates)\r\n      {\r\n        UInt32 distance;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);\r\n        TREE_6_DECODE(prob, distance);\r\n        if (distance >= kStartPosModelIndex)\r\n        {\r\n          unsigned posSlot = (unsigned)distance;\r\n          int numDirectBits = (int)(((distance >> 1) - 1));\r\n          distance = (2 | (distance & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            distance <<= numDirectBits;\r\n            prob = probs + SpecPos + distance - posSlot - 1;\r\n            {\r\n              UInt32 mask = 1;\r\n              unsigned i = 1;\r\n              do\r\n              {\r\n                GET_BIT2(prob + i, i, ; , distance |= mask);\r\n                mask <<= 1;\r\n              }\r\n              while (--numDirectBits != 0);\r\n            }\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE\r\n              range >>= 1;\r\n              \r\n              {\r\n                UInt32 t;\r\n                code -= range;\r\n                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */\r\n                distance = (distance << 1) + (t + 1);\r\n                code += range & t;\r\n              }\r\n              /*\r\n              distance <<= 1;\r\n              if (code >= range)\r\n              {\r\n                code -= range;\r\n                distance |= 1;\r\n              }\r\n              */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            distance <<= kNumAlignBits;\r\n            {\r\n              unsigned i = 1;\r\n              GET_BIT2(prob + i, i, ; , distance |= 1);\r\n              GET_BIT2(prob + i, i, ; , distance |= 2);\r\n              GET_BIT2(prob + i, i, ; , distance |= 4);\r\n              GET_BIT2(prob + i, i, ; , distance |= 8);\r\n            }\r\n            if (distance == (UInt32)0xFFFFFFFF)\r\n            {\r\n              len += kMatchSpecLenStart;\r\n              state -= kNumStates;\r\n              break;\r\n            }\r\n          }\r\n        }\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        rep0 = distance + 1;\r\n        if (checkDicSize == 0)\r\n        {\r\n          if (distance >= processedPos)\r\n            return SZ_ERROR_DATA;\r\n        }\r\n        else if (distance >= checkDicSize)\r\n          return SZ_ERROR_DATA;\r\n        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r\n        /* state = kLiteralNextStates[state]; */\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n\r\n      if (limit == dicPos)\r\n        return SZ_ERROR_DATA;\r\n      {\r\n        SizeT rem = limit - dicPos;\r\n        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\r\n        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\r\n\r\n        processedPos += curLen;\r\n\r\n        len -= curLen;\r\n        if (pos + curLen <= dicBufSize)\r\n        {\r\n          Byte *dest = dic + dicPos;\r\n          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;\r\n          const Byte *lim = dest + curLen;\r\n          dicPos += curLen;\r\n          do\r\n            *(dest) = (Byte)*(dest + src);\r\n          while (++dest != lim);\r\n        }\r\n        else\r\n        {\r\n          do\r\n          {\r\n            dic[dicPos++] = dic[pos];\r\n            if (++pos == dicBufSize)\r\n              pos = 0;\r\n          }\r\n          while (--curLen != 0);\r\n        }\r\n      }\r\n    }\r\n  }\r\n  while (dicPos < limit && buf < bufLimit);\r\n  NORMALIZE;\r\n  p->buf = buf;\r\n  p->range = range;\r\n  p->code = code;\r\n  p->remainLen = len;\r\n  p->dicPos = dicPos;\r\n  p->processedPos = processedPos;\r\n  p->reps[0] = rep0;\r\n  p->reps[1] = rep1;\r\n  p->reps[2] = rep2;\r\n  p->reps[3] = rep3;\r\n  p->state = state;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\r\n{\r\n  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\r\n  {\r\n    Byte *dic = p->dic;\r\n    SizeT dicPos = p->dicPos;\r\n    SizeT dicBufSize = p->dicBufSize;\r\n    unsigned len = p->remainLen;\r\n    UInt32 rep0 = p->reps[0];\r\n    if (limit - dicPos < len)\r\n      len = (unsigned)(limit - dicPos);\r\n\r\n    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r\n      p->checkDicSize = p->prop.dicSize;\r\n\r\n    p->processedPos += len;\r\n    p->remainLen -= len;\r\n    while (len-- != 0)\r\n    {\r\n      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r\n      dicPos++;\r\n    }\r\n    p->dicPos = dicPos;\r\n  }\r\n}\r\n\r\nstatic int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r\n{\r\n  do\r\n  {\r\n    SizeT limit2 = limit;\r\n    if (p->checkDicSize == 0)\r\n    {\r\n      UInt32 rem = p->prop.dicSize - p->processedPos;\r\n      if (limit - p->dicPos > rem)\r\n        limit2 = p->dicPos + rem;\r\n    }\r\n    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r\n    if (p->processedPos >= p->prop.dicSize)\r\n      p->checkDicSize = p->prop.dicSize;\r\n    LzmaDec_WriteRem(p, limit);\r\n  }\r\n  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r\n\r\n  if (p->remainLen > kMatchSpecLenStart)\r\n  {\r\n    p->remainLen = kMatchSpecLenStart;\r\n  }\r\n  return 0;\r\n}\r\n\r\ntypedef enum\r\n{\r\n  DUMMY_ERROR, /* unexpected end of input stream */\r\n  DUMMY_LIT,\r\n  DUMMY_MATCH,\r\n  DUMMY_REP\r\n} ELzmaDummy;\r\n\r\nstatic ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\r\n{\r\n  UInt32 range = p->range;\r\n  UInt32 code = p->code;\r\n  const Byte *bufLimit = buf + inSize;\r\n  CLzmaProb *probs = p->probs;\r\n  unsigned state = p->state;\r\n  ELzmaDummy res;\r\n\r\n  {\r\n    CLzmaProb *prob;\r\n    UInt32 bound;\r\n    unsigned ttt;\r\n    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r\n\r\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IF_BIT_0_CHECK(prob)\r\n    {\r\n      UPDATE_0_CHECK\r\n\r\n      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\r\n\r\n      prob = probs + Literal;\r\n      if (p->checkDicSize != 0 || p->processedPos != 0)\r\n        prob += (LZMA_LIT_SIZE *\r\n          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r\n          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r\n\r\n      if (state < kNumLitStates)\r\n      {\r\n        unsigned symbol = 1;\r\n        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);\r\n      }\r\n      else\r\n      {\r\n        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r\n            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\r\n        unsigned offs = 0x100;\r\n        unsigned symbol = 1;\r\n        do\r\n        {\r\n          unsigned bit;\r\n          CLzmaProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & offs);\r\n          probLit = prob + offs + bit + symbol;\r\n          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      res = DUMMY_LIT;\r\n    }\r\n    else\r\n    {\r\n      unsigned len;\r\n      UPDATE_1_CHECK;\r\n\r\n      prob = probs + IsRep + state;\r\n      IF_BIT_0_CHECK(prob)\r\n      {\r\n        UPDATE_0_CHECK;\r\n        state = 0;\r\n        prob = probs + LenCoder;\r\n        res = DUMMY_MATCH;\r\n      }\r\n      else\r\n      {\r\n        UPDATE_1_CHECK;\r\n        res = DUMMY_REP;\r\n        prob = probs + IsRepG0 + state;\r\n        IF_BIT_0_CHECK(prob)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            NORMALIZE_CHECK;\r\n            return DUMMY_REP;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          prob = probs + IsRepG1 + state;\r\n          IF_BIT_0_CHECK(prob)\r\n          {\r\n            UPDATE_0_CHECK;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            prob = probs + IsRepG2 + state;\r\n            IF_BIT_0_CHECK(prob)\r\n            {\r\n              UPDATE_0_CHECK;\r\n            }\r\n            else\r\n            {\r\n              UPDATE_1_CHECK;\r\n            }\r\n          }\r\n        }\r\n        state = kNumStates;\r\n        prob = probs + RepLenCoder;\r\n      }\r\n      {\r\n        unsigned limit, offset;\r\n        CLzmaProb *probLen = prob + LenChoice;\r\n        IF_BIT_0_CHECK(probLen)\r\n        {\r\n          UPDATE_0_CHECK;\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          limit = 1 << kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UPDATE_1_CHECK;\r\n          probLen = prob + LenChoice2;\r\n          IF_BIT_0_CHECK(probLen)\r\n          {\r\n            UPDATE_0_CHECK;\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            limit = 1 << kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UPDATE_1_CHECK;\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            limit = 1 << kLenNumHighBits;\r\n          }\r\n        }\r\n        TREE_DECODE_CHECK(probLen, limit, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        unsigned posSlot;\r\n        prob = probs + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<\r\n            kNumPosSlotBits);\r\n        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n\r\n          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              NORMALIZE_CHECK\r\n              range >>= 1;\r\n              code -= range & (((code - range) >> 31) - 1);\r\n              /* if (code >= range) code -= range; */\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = probs + Align;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            unsigned i = 1;\r\n            do\r\n            {\r\n              GET_BIT_CHECK(prob + i, i);\r\n            }\r\n            while (--numDirectBits != 0);\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n  NORMALIZE_CHECK;\r\n  return res;\r\n}\r\n\r\n\r\nstatic void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\r\n{\r\n  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\r\n  p->range = 0xFFFFFFFF;\r\n  p->needFlush = 0;\r\n}\r\n\r\nvoid LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r\n{\r\n  p->needFlush = 1;\r\n  p->remainLen = 0;\r\n  p->tempBufSize = 0;\r\n\r\n  if (initDic)\r\n  {\r\n    p->processedPos = 0;\r\n    p->checkDicSize = 0;\r\n    p->needInitState = 1;\r\n  }\r\n  if (initState)\r\n    p->needInitState = 1;\r\n}\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p)\r\n{\r\n  p->dicPos = 0;\r\n  LzmaDec_InitDicAndState(p, True, True);\r\n}\r\n\r\nstatic void LzmaDec_InitStateReal(CLzmaDec *p)\r\n{\r\n  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\r\n  UInt32 i;\r\n  CLzmaProb *probs = p->probs;\r\n  for (i = 0; i < numProbs; i++)\r\n    probs[i] = kBitModelTotal >> 1;\r\n  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;\r\n  p->state = 0;\r\n  p->needInitState = 0;\r\n}\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\r\n    ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT inSize = *srcLen;\r\n  (*srcLen) = 0;\r\n  LzmaDec_WriteRem(p, dicLimit);\r\n  \r\n  *status = LZMA_STATUS_NOT_SPECIFIED;\r\n\r\n  while (p->remainLen != kMatchSpecLenStart)\r\n  {\r\n      int checkEndMarkNow;\r\n\r\n      if (p->needFlush != 0)\r\n      {\r\n        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r\n          p->tempBuf[p->tempBufSize++] = *src++;\r\n        if (p->tempBufSize < RC_INIT_SIZE)\r\n        {\r\n          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n          return SZ_OK;\r\n        }\r\n        if (p->tempBuf[0] != 0)\r\n          return SZ_ERROR_DATA;\r\n\r\n        LzmaDec_InitRc(p, p->tempBuf);\r\n        p->tempBufSize = 0;\r\n      }\r\n\r\n      checkEndMarkNow = 0;\r\n      if (p->dicPos >= dicLimit)\r\n      {\r\n        if (p->remainLen == 0 && p->code == 0)\r\n        {\r\n          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;\r\n          return SZ_OK;\r\n        }\r\n        if (finishMode == LZMA_FINISH_ANY)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_OK;\r\n        }\r\n        if (p->remainLen != 0)\r\n        {\r\n          *status = LZMA_STATUS_NOT_FINISHED;\r\n          return SZ_ERROR_DATA;\r\n        }\r\n        checkEndMarkNow = 1;\r\n      }\r\n\r\n      if (p->needInitState)\r\n        LzmaDec_InitStateReal(p);\r\n  \r\n      if (p->tempBufSize == 0)\r\n      {\r\n        SizeT processed;\r\n        const Byte *bufLimit;\r\n        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            memcpy(p->tempBuf, src, inSize);\r\n            p->tempBufSize = (unsigned)inSize;\r\n            (*srcLen) += inSize;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n          bufLimit = src;\r\n        }\r\n        else\r\n          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\r\n        p->buf = src;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\r\n          return SZ_ERROR_DATA;\r\n        processed = (SizeT)(p->buf - src);\r\n        (*srcLen) += processed;\r\n        src += processed;\r\n        inSize -= processed;\r\n      }\r\n      else\r\n      {\r\n        unsigned rem = p->tempBufSize, lookAhead = 0;\r\n        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\r\n          p->tempBuf[rem++] = src[lookAhead++];\r\n        p->tempBufSize = rem;\r\n        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\r\n        {\r\n          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);\r\n          if (dummyRes == DUMMY_ERROR)\r\n          {\r\n            (*srcLen) += lookAhead;\r\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\r\n            return SZ_OK;\r\n          }\r\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\r\n          {\r\n            *status = LZMA_STATUS_NOT_FINISHED;\r\n            return SZ_ERROR_DATA;\r\n          }\r\n        }\r\n        p->buf = p->tempBuf;\r\n        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r\n          return SZ_ERROR_DATA;\r\n        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\r\n        (*srcLen) += lookAhead;\r\n        src += lookAhead;\r\n        inSize -= lookAhead;\r\n        p->tempBufSize = 0;\r\n      }\r\n  }\r\n  if (p->code == 0)\r\n    *status = LZMA_STATUS_FINISHED_WITH_MARK;\r\n  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;\r\n}\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\r\n{\r\n  SizeT outSize = *destLen;\r\n  SizeT inSize = *srcLen;\r\n  *srcLen = *destLen = 0;\r\n  for (;;)\r\n  {\r\n    SizeT inSizeCur = inSize, outSizeCur, dicPos;\r\n    ELzmaFinishMode curFinishMode;\r\n    SRes res;\r\n    if (p->dicPos == p->dicBufSize)\r\n      p->dicPos = 0;\r\n    dicPos = p->dicPos;\r\n    if (outSize > p->dicBufSize - dicPos)\r\n    {\r\n      outSizeCur = p->dicBufSize;\r\n      curFinishMode = LZMA_FINISH_ANY;\r\n    }\r\n    else\r\n    {\r\n      outSizeCur = dicPos + outSize;\r\n      curFinishMode = finishMode;\r\n    }\r\n\r\n    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);\r\n    src += inSizeCur;\r\n    inSize -= inSizeCur;\r\n    *srcLen += inSizeCur;\r\n    outSizeCur = p->dicPos - dicPos;\r\n    memcpy(dest, p->dic + dicPos, outSizeCur);\r\n    dest += outSizeCur;\r\n    outSize -= outSizeCur;\r\n    *destLen += outSizeCur;\r\n    if (res != 0)\r\n      return res;\r\n    if (outSizeCur == 0 || outSize == 0)\r\n      return SZ_OK;\r\n  }\r\n}\r\n\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->probs);\r\n  p->probs = 0;\r\n}\r\n\r\nstatic void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->dic);\r\n  p->dic = 0;\r\n}\r\n\r\nvoid LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r\n{\r\n  LzmaDec_FreeProbs(p, alloc);\r\n  LzmaDec_FreeDict(p, alloc);\r\n}\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)\r\n{\r\n  UInt32 dicSize;\r\n  Byte d;\r\n  \r\n  if (size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  else\r\n    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);\r\n \r\n  if (dicSize < LZMA_DIC_MIN)\r\n    dicSize = LZMA_DIC_MIN;\r\n  p->dicSize = dicSize;\r\n\r\n  d = data[0];\r\n  if (d >= (9 * 5 * 5))\r\n    return SZ_ERROR_UNSUPPORTED;\r\n\r\n  p->lc = d % 9;\r\n  d /= 9;\r\n  p->pb = d / 5;\r\n  p->lp = d % 5;\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r\n{\r\n  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r\n  if (p->probs == 0 || numProbs != p->numProbs)\r\n  {\r\n    LzmaDec_FreeProbs(p, alloc);\r\n    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r\n    p->numProbs = numProbs;\r\n    if (p->probs == 0)\r\n      return SZ_ERROR_MEM;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\r\n{\r\n  CLzmaProps propNew;\r\n  SizeT dicBufSize;\r\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r\n  dicBufSize = propNew.dicSize;\r\n  if (p->dic == 0 || dicBufSize != p->dicBufSize)\r\n  {\r\n    LzmaDec_FreeDict(p, alloc);\r\n    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r\n    if (p->dic == 0)\r\n    {\r\n      LzmaDec_FreeProbs(p, alloc);\r\n      return SZ_ERROR_MEM;\r\n    }\r\n  }\r\n  p->dicBufSize = dicBufSize;\r\n  p->prop = propNew;\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc)\r\n{\r\n  CLzmaDec p;\r\n  SRes res;\r\n  SizeT inSize = *srcLen;\r\n  SizeT outSize = *destLen;\r\n  *srcLen = *destLen = 0;\r\n  if (inSize < RC_INIT_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  LzmaDec_Construct(&p);\r\n  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\r\n  if (res != 0)\r\n    return res;\r\n  p.dic = dest;\r\n  p.dicBufSize = outSize;\r\n\r\n  LzmaDec_Init(&p);\r\n  \r\n  *srcLen = inSize;\r\n  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r\n\r\n  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r\n    res = SZ_ERROR_INPUT_EOF;\r\n\r\n  (*destLen) = p.dicPos;\r\n  LzmaDec_FreeProbs(&p, alloc);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaDec.h",
    "content": "/* LzmaDec.h -- LZMA Decoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMADEC_H\r\n#define __LZMADEC_H\r\n\r\n#include \"Types.h\"\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* _LZMA_PROB32 can increase the speed on some CPUs,\r\n   but memory usage for CLzmaDec::probs will be doubled in that case */\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n\r\n/* ---------- LZMA Properties ---------- */\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaProps\r\n{\r\n  unsigned lc, lp, pb;\r\n  UInt32 dicSize;\r\n} CLzmaProps;\r\n\r\n/* LzmaProps_Decode - decodes properties\r\nReturns:\r\n  SZ_OK\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n\r\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);\r\n\r\n\r\n/* ---------- LZMA Decoder state ---------- */\r\n\r\n/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.\r\n   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */\r\n\r\n#define LZMA_REQUIRED_INPUT_MAX 20\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProps prop;\r\n  CLzmaProb *probs;\r\n  Byte *dic;\r\n  const Byte *buf;\r\n  UInt32 range, code;\r\n  SizeT dicPos;\r\n  SizeT dicBufSize;\r\n  UInt32 processedPos;\r\n  UInt32 checkDicSize;\r\n  unsigned state;\r\n  UInt32 reps[4];\r\n  unsigned remainLen;\r\n  int needFlush;\r\n  int needInitState;\r\n  UInt32 numProbs;\r\n  unsigned tempBufSize;\r\n  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];\r\n} CLzmaDec;\r\n\r\n#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }\r\n\r\nvoid LzmaDec_Init(CLzmaDec *p);\r\n\r\n/* There are two types of LZMA streams:\r\n     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.\r\n     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_FINISH_ANY,   /* finish at any point */\r\n  LZMA_FINISH_END    /* block must be finished at the end */\r\n} ELzmaFinishMode;\r\n\r\n/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!\r\n\r\n   You must use LZMA_FINISH_END, when you know that current output buffer\r\n   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.\r\n\r\n   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,\r\n   and output value of destLen will be less than output buffer size limit.\r\n   You can check status result also.\r\n\r\n   You can use multiple checks to test data integrity after full decompression:\r\n     1) Check Result and \"status\" variable.\r\n     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.\r\n        You must use correct finish mode in that case. */\r\n\r\ntypedef enum\r\n{\r\n  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */\r\n  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\r\n  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */\r\n  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */\r\n  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */\r\n} ELzmaStatus;\r\n\r\n/* ELzmaStatus is used only as output value for function call */\r\n\r\n\r\n/* ---------- Interfaces ---------- */\r\n\r\n/* There are 3 levels of interfaces:\r\n     1) Dictionary Interface\r\n     2) Buffer Interface\r\n     3) One Call Interface\r\n   You can select any of these interfaces, but don't mix functions from different\r\n   groups for same object. */\r\n\r\n\r\n/* There are two variants to allocate state for Dictionary Interface:\r\n     1) LzmaDec_Allocate / LzmaDec_Free\r\n     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs\r\n   You can use variant 2, if you set dictionary buffer manually.\r\n   For Buffer Interface you must always use variant 1.\r\n\r\nLzmaDec_Allocate* can return:\r\n  SZ_OK\r\n  SZ_ERROR_MEM         - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n*/\r\n   \r\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);\r\n\r\nSRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);\r\nvoid LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);\r\n\r\n/* ---------- Dictionary Interface ---------- */\r\n\r\n/* You can use it, if you want to eliminate the overhead for data copying from\r\n   dictionary to some other external buffer.\r\n   You must work with CLzmaDec variables directly in this interface.\r\n\r\n   STEPS:\r\n     LzmaDec_Constr()\r\n     LzmaDec_Allocate()\r\n     for (each new stream)\r\n     {\r\n       LzmaDec_Init()\r\n       while (it needs more decompression)\r\n       {\r\n         LzmaDec_DecodeToDic()\r\n         use data from CLzmaDec::dic and update CLzmaDec::dicPos\r\n       }\r\n     }\r\n     LzmaDec_Free()\r\n*/\r\n\r\n/* LzmaDec_DecodeToDic\r\n   \r\n   The decoding to internal dictionary buffer (CLzmaDec::dic).\r\n   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (dicLimit).\r\n  LZMA_FINISH_ANY - Decode just dicLimit bytes.\r\n  LZMA_FINISH_END - Stream must be finished after dicLimit.\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_NEEDS_MORE_INPUT\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n*/\r\n\r\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- Buffer Interface ---------- */\r\n\r\n/* It's zlib-like interface.\r\n   See LzmaDec_DecodeToDic description for information about STEPS and return results,\r\n   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need\r\n   to work with CLzmaDec variables manually.\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n*/\r\n\r\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,\r\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\r\n\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaDecode\r\n\r\nfinishMode:\r\n  It has meaning only if the decoding reaches output limit (*destLen).\r\n  LZMA_FINISH_ANY - Decode just destLen bytes.\r\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n\r\nReturns:\r\n  SZ_OK\r\n    status:\r\n      LZMA_STATUS_FINISHED_WITH_MARK\r\n      LZMA_STATUS_NOT_FINISHED\r\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n  SZ_ERROR_DATA - Data error\r\n  SZ_ERROR_MEM  - Memory allocation error\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n*/\r\n\r\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r\n    ELzmaStatus *status, ISzAlloc *alloc);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaEnc.c",
    "content": "/* LzmaEnc.c -- LZMA Encoder\r\n2009-02-02 : Igor Pavlov : Public domain */\r\n\r\n#include <string.h>\r\n\r\n/* #define SHOW_STAT */\r\n/* #define SHOW_STAT2 */\r\n\r\n#if defined(SHOW_STAT) || defined(SHOW_STAT2)\r\n#include <stdio.h>\r\n#endif\r\n\r\n#include \"LzmaEnc.h\"\r\n\r\n#include \"LzFind.h\"\r\n#ifdef COMPRESS_MF_MT\r\n#include \"LzFindMt.h\"\r\n#endif\r\n\r\n#ifdef SHOW_STAT\r\nstatic int ttt = 0;\r\n#endif\r\n\r\n#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)\r\n\r\n#define kBlockSize (9 << 10)\r\n#define kUnpackBlockSize (1 << 18)\r\n#define kMatchArraySize (1 << 21)\r\n#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)\r\n\r\n#define kNumMaxDirectBits (31)\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n#define kProbInitValue (kBitModelTotal >> 1)\r\n\r\n#define kNumMoveReducingBits 4\r\n#define kNumBitPriceShiftBits 4\r\n#define kBitPrice (1 << kNumBitPriceShiftBits)\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p)\r\n{\r\n  p->level = 5;\r\n  p->dictSize = p->mc = 0;\r\n  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\r\n  p->writeEndMark = 0;\r\n}\r\n\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p)\r\n{\r\n  int level = p->level;\r\n  if (level < 0) level = 5;\r\n  p->level = level;\r\n  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));\r\n  if (p->lc < 0) p->lc = 3;\r\n  if (p->lp < 0) p->lp = 0;\r\n  if (p->pb < 0) p->pb = 2;\r\n  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);\r\n  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);\r\n  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);\r\n  if (p->numHashBytes < 0) p->numHashBytes = 4;\r\n  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\r\n  if (p->numThreads < 0)\r\n    p->numThreads =\r\n      #ifdef COMPRESS_MF_MT\r\n      ((p->btMode && p->algo) ? 2 : 1);\r\n      #else\r\n      1;\r\n      #endif\r\n}\r\n\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n  return props.dictSize;\r\n}\r\n\r\n/* #define LZMA_LOG_BSR */\r\n/* Define it for Intel's CPU */\r\n\r\n\r\n#ifdef LZMA_LOG_BSR\r\n\r\n#define kDicLogSizeMaxCompress 30\r\n\r\n#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }\r\n\r\nUInt32 GetPosSlot1(UInt32 pos)\r\n{\r\n  UInt32 res;\r\n  BSR2_RET(pos, res);\r\n  return res;\r\n}\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }\r\n\r\n#else\r\n\r\n#define kNumLogBits (9 + (int)sizeof(size_t) / 2)\r\n#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)\r\n\r\nvoid LzmaEnc_FastPosInit(Byte *g_FastPos)\r\n{\r\n  int c = 2, slotFast;\r\n  g_FastPos[0] = 0;\r\n  g_FastPos[1] = 1;\r\n  \r\n  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)\r\n  {\r\n    UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n    UInt32 j;\r\n    for (j = 0; j < k; j++, c++)\r\n      g_FastPos[c] = (Byte)slotFast;\r\n  }\r\n}\r\n\r\n#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \\\r\n  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \\\r\n  res = p->g_FastPos[pos >> i] + (i * 2); }\r\n/*\r\n#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \\\r\n  p->g_FastPos[pos >> 6] + 12 : \\\r\n  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }\r\n*/\r\n\r\n#define GetPosSlot1(pos) p->g_FastPos[pos]\r\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\r\n#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }\r\n\r\n#endif\r\n\r\n\r\n#define LZMA_NUM_REPS 4\r\n\r\ntypedef unsigned CState;\r\n\r\ntypedef struct _COptimal\r\n{\r\n  UInt32 price;\r\n\r\n  CState state;\r\n  int prev1IsChar;\r\n  int prev2;\r\n\r\n  UInt32 posPrev2;\r\n  UInt32 backPrev2;\r\n\r\n  UInt32 posPrev;\r\n  UInt32 backPrev;\r\n  UInt32 backs[LZMA_NUM_REPS];\r\n} COptimal;\r\n\r\n#define kNumOpts (1 << 12)\r\n\r\n#define kNumLenToPosStates 4\r\n#define kNumPosSlotBits 6\r\n#define kDicLogSizeMin 0\r\n#define kDicLogSizeMax 32\r\n#define kDistTableSizeMax (kDicLogSizeMax * 2)\r\n\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n#define kAlignMask (kAlignTableSize - 1)\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)\r\n\r\n#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CLzmaProb UInt32\r\n#else\r\n#define CLzmaProb UInt16\r\n#endif\r\n\r\n#define LZMA_PB_MAX 4\r\n#define LZMA_LC_MAX 8\r\n#define LZMA_LP_MAX 4\r\n\r\n#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)\r\n\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\r\n\r\n#define LZMA_MATCH_LEN_MIN 2\r\n#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)\r\n\r\n#define kNumStates 12\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb choice;\r\n  CLzmaProb choice2;\r\n  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];\r\n  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];\r\n  CLzmaProb high[kLenNumHighSymbols];\r\n} CLenEnc;\r\n\r\ntypedef struct\r\n{\r\n  CLenEnc p;\r\n  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\r\n  UInt32 tableSize;\r\n  UInt32 counters[LZMA_NUM_PB_STATES_MAX];\r\n} CLenPriceEnc;\r\n\r\ntypedef struct _CRangeEnc\r\n{\r\n  UInt32 range;\r\n  Byte cache;\r\n  UInt64 low;\r\n  UInt64 cacheSize;\r\n  Byte *buf;\r\n  Byte *bufLim;\r\n  Byte *bufBase;\r\n  ISeqOutStream *outStream;\r\n  UInt64 processed;\r\n  SRes res;\r\n} CRangeEnc;\r\n\r\ntypedef struct _CSeqInStreamBuf\r\n{\r\n  ISeqInStream funcTable;\r\n  const Byte *data;\r\n  SizeT rem;\r\n} CSeqInStreamBuf;\r\n\r\nstatic SRes MyRead(void *pp, void *data, size_t *size)\r\n{\r\n  size_t curSize = *size;\r\n  CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;\r\n  if (p->rem < curSize)\r\n    curSize = p->rem;\r\n  memcpy(data, p->data, curSize);\r\n  p->rem -= curSize;\r\n  p->data += curSize;\r\n  *size = curSize;\r\n  return SZ_OK;\r\n}\r\n\r\ntypedef struct\r\n{\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n} CSaveState;\r\n\r\ntypedef struct _CLzmaEnc\r\n{\r\n  IMatchFinder matchFinder;\r\n  void *matchFinderObj;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Bool mtMode;\r\n  CMatchFinderMt matchFinderMt;\r\n  #endif\r\n\r\n  CMatchFinder matchFinderBase;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte pad[128];\r\n  #endif\r\n  \r\n  UInt32 optimumEndIndex;\r\n  UInt32 optimumCurrentIndex;\r\n\r\n  UInt32 longestMatchLength;\r\n  UInt32 numPairs;\r\n  UInt32 numAvail;\r\n  COptimal opt[kNumOpts];\r\n  \r\n  #ifndef LZMA_LOG_BSR\r\n  Byte g_FastPos[1 << kNumLogBits];\r\n  #endif\r\n\r\n  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];\r\n  UInt32 numFastBytes;\r\n  UInt32 additionalOffset;\r\n  UInt32 reps[LZMA_NUM_REPS];\r\n  UInt32 state;\r\n\r\n  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n  UInt32 alignPrices[kAlignTableSize];\r\n  UInt32 alignPriceCount;\r\n\r\n  UInt32 distTableSize;\r\n\r\n  unsigned lc, lp, pb;\r\n  unsigned lpMask, pbMask;\r\n\r\n  CLzmaProb *litProbs;\r\n\r\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n  CLzmaProb isRep[kNumStates];\r\n  CLzmaProb isRepG0[kNumStates];\r\n  CLzmaProb isRepG1[kNumStates];\r\n  CLzmaProb isRepG2[kNumStates];\r\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\r\n\r\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\r\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\r\n  \r\n  CLenPriceEnc lenEnc;\r\n  CLenPriceEnc repLenEnc;\r\n\r\n  unsigned lclp;\r\n\r\n  Bool fastMode;\r\n  \r\n  CRangeEnc rc;\r\n\r\n  Bool writeEndMark;\r\n  UInt64 nowPos64;\r\n  UInt32 matchPriceCount;\r\n  Bool finished;\r\n  Bool multiThread;\r\n\r\n  SRes result;\r\n  UInt32 dictSize;\r\n  UInt32 matchFinderCycles;\r\n\r\n  ISeqInStream *inStream;\r\n  CSeqInStreamBuf seqBufInStream;\r\n\r\n  CSaveState saveState;\r\n} CLzmaEnc;\r\n\r\nvoid LzmaEnc_SaveState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CSaveState *dest = &p->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nvoid LzmaEnc_RestoreState(CLzmaEncHandle pp)\r\n{\r\n  CLzmaEnc *dest = (CLzmaEnc *)pp;\r\n  const CSaveState *p = &dest->saveState;\r\n  int i;\r\n  dest->lenEnc = p->lenEnc;\r\n  dest->repLenEnc = p->repLenEnc;\r\n  dest->state = p->state;\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\r\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\r\n  }\r\n  for (i = 0; i < kNumLenToPosStates; i++)\r\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\r\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\r\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\r\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\r\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\r\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\r\n  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));\r\n}\r\n\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  CLzmaEncProps props = *props2;\r\n  LzmaEncProps_Normalize(&props);\r\n\r\n  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||\r\n      props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))\r\n    return SZ_ERROR_PARAM;\r\n  p->dictSize = props.dictSize;\r\n  p->matchFinderCycles = props.mc;\r\n  {\r\n    unsigned fb = props.fb;\r\n    if (fb < 5)\r\n      fb = 5;\r\n    if (fb > LZMA_MATCH_LEN_MAX)\r\n      fb = LZMA_MATCH_LEN_MAX;\r\n    p->numFastBytes = fb;\r\n  }\r\n  p->lc = props.lc;\r\n  p->lp = props.lp;\r\n  p->pb = props.pb;\r\n  p->fastMode = (props.algo == 0);\r\n  p->matchFinderBase.btMode = props.btMode;\r\n  {\r\n    UInt32 numHashBytes = 4;\r\n    if (props.btMode)\r\n    {\r\n      if (props.numHashBytes < 2)\r\n        numHashBytes = 2;\r\n      else if (props.numHashBytes < 4)\r\n        numHashBytes = props.numHashBytes;\r\n    }\r\n    p->matchFinderBase.numHashBytes = numHashBytes;\r\n  }\r\n\r\n  p->matchFinderBase.cutValue = props.mc;\r\n\r\n  p->writeEndMark = props.writeEndMark;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  /*\r\n  if (newMultiThread != _multiThread)\r\n  {\r\n    ReleaseMatchFinder();\r\n    _multiThread = newMultiThread;\r\n  }\r\n  */\r\n  p->multiThread = (props.numThreads > 1);\r\n  #endif\r\n\r\n  return SZ_OK;\r\n}\r\n\r\nstatic const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nstatic const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nstatic const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nstatic const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n#define IsCharState(s) ((s) < 7)\r\n\r\n#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)\r\n\r\n#define kInfinityPrice (1 << 30)\r\n\r\nstatic void RangeEnc_Construct(CRangeEnc *p)\r\n{\r\n  p->outStream = 0;\r\n  p->bufBase = 0;\r\n}\r\n\r\n#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)\r\n\r\n#define RC_BUF_SIZE (1 << 16)\r\nstatic int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  if (p->bufBase == 0)\r\n  {\r\n    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);\r\n    if (p->bufBase == 0)\r\n      return 0;\r\n    p->bufLim = p->bufBase + RC_BUF_SIZE;\r\n  }\r\n  return 1;\r\n}\r\n\r\nstatic void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->bufBase);\r\n  p->bufBase = 0;\r\n}\r\n\r\nstatic void RangeEnc_Init(CRangeEnc *p)\r\n{\r\n  /* Stream.Init(); */\r\n  p->low = 0;\r\n  p->range = 0xFFFFFFFF;\r\n  p->cacheSize = 1;\r\n  p->cache = 0;\r\n\r\n  p->buf = p->bufBase;\r\n\r\n  p->processed = 0;\r\n  p->res = SZ_OK;\r\n}\r\n\r\nstatic void RangeEnc_FlushStream(CRangeEnc *p)\r\n{\r\n  size_t num;\r\n  if (p->res != SZ_OK)\r\n    return;\r\n  num = p->buf - p->bufBase;\r\n  if (num != p->outStream->Write(p->outStream, p->bufBase, num))\r\n    p->res = SZ_ERROR_WRITE;\r\n  p->processed += num;\r\n  p->buf = p->bufBase;\r\n}\r\n\r\nstatic void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)\r\n{\r\n  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)\r\n  {\r\n    Byte temp = p->cache;\r\n    do\r\n    {\r\n      Byte *buf = p->buf;\r\n      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));\r\n      p->buf = buf;\r\n      if (buf == p->bufLim)\r\n        RangeEnc_FlushStream(p);\r\n      temp = 0xFF;\r\n    }\r\n    while (--p->cacheSize != 0);\r\n    p->cache = (Byte)((UInt32)p->low >> 24);\r\n  }\r\n  p->cacheSize++;\r\n  p->low = (UInt32)p->low << 8;\r\n}\r\n\r\nstatic void RangeEnc_FlushData(CRangeEnc *p)\r\n{\r\n  int i;\r\n  for (i = 0; i < 5; i++)\r\n    RangeEnc_ShiftLow(p);\r\n}\r\n\r\nstatic void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)\r\n{\r\n  do\r\n  {\r\n    p->range >>= 1;\r\n    p->low += p->range & (0 - ((value >> --numBits) & 1));\r\n    if (p->range < kTopValue)\r\n    {\r\n      p->range <<= 8;\r\n      RangeEnc_ShiftLow(p);\r\n    }\r\n  }\r\n  while (numBits != 0);\r\n}\r\n\r\nstatic void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)\r\n{\r\n  UInt32 ttt = *prob;\r\n  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;\r\n  if (symbol == 0)\r\n  {\r\n    p->range = newBound;\r\n    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;\r\n  }\r\n  else\r\n  {\r\n    p->low += newBound;\r\n    p->range -= newBound;\r\n    ttt -= ttt >> kNumMoveBits;\r\n  }\r\n  *prob = (CLzmaProb)ttt;\r\n  if (p->range < kTopValue)\r\n  {\r\n    p->range <<= 8;\r\n    RangeEnc_ShiftLow(p);\r\n  }\r\n}\r\n\r\nstatic void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)\r\n{\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nstatic void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)\r\n{\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n}\r\n\r\nvoid LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\r\n{\r\n  UInt32 i;\r\n  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))\r\n  {\r\n    const int kCyclesBits = kNumBitPriceShiftBits;\r\n    UInt32 w = i;\r\n    UInt32 bitCount = 0;\r\n    int j;\r\n    for (j = 0; j < kCyclesBits; j++)\r\n    {\r\n      w = w * w;\r\n      bitCount <<= 1;\r\n      while (w >= ((UInt32)1 << 16))\r\n      {\r\n        w >>= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);\r\n  }\r\n}\r\n\r\n\r\n#define GET_PRICE(prob, symbol) \\\r\n  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICEa(prob, symbol) \\\r\n  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\r\n\r\n#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\n#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]\r\n#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r\n\r\nstatic UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\nstatic UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 offs = 0x100;\r\n  symbol |= 0x100;\r\n  do\r\n  {\r\n    matchByte <<= 1;\r\n    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);\r\n    symbol <<= 1;\r\n    offs &= ~(matchByte ^ symbol);\r\n  }\r\n  while (symbol < 0x10000);\r\n  return price;\r\n}\r\n\r\n\r\nstatic void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0;)\r\n  {\r\n    UInt32 bit;\r\n    i--;\r\n    bit = (symbol >> i) & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n}\r\n\r\nstatic void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = 0; i < numBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    RangeEnc_EncodeBit(rc, probs + m, bit);\r\n    m = (m << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  symbol |= (1 << numBitLevels);\r\n  while (symbol != 1)\r\n  {\r\n    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);\r\n    symbol >>= 1;\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 m = 1;\r\n  int i;\r\n  for (i = numBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += GET_PRICEa(probs[m], bit);\r\n    m = (m << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\n\r\nstatic void LenEnc_Init(CLenEnc *p)\r\n{\r\n  unsigned i;\r\n  p->choice = p->choice2 = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)\r\n    p->low[i] = kProbInitValue;\r\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)\r\n    p->mid[i] = kProbInitValue;\r\n  for (i = 0; i < kLenNumHighSymbols; i++)\r\n    p->high[i] = kProbInitValue;\r\n}\r\n\r\nstatic void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)\r\n{\r\n  if (symbol < kLenNumLowSymbols)\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 0);\r\n    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);\r\n  }\r\n  else\r\n  {\r\n    RangeEnc_EncodeBit(rc, &p->choice, 1);\r\n    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 0);\r\n      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(rc, &p->choice2, 1);\r\n      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)\r\n{\r\n  UInt32 a0 = GET_PRICE_0a(p->choice);\r\n  UInt32 a1 = GET_PRICE_1a(p->choice);\r\n  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);\r\n  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);\r\n  UInt32 i = 0;\r\n  for (i = 0; i < kLenNumLowSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);\r\n  }\r\n  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)\r\n  {\r\n    if (i >= numSymbols)\r\n      return;\r\n    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);\r\n  }\r\n  for (; i < numSymbols; i++)\r\n    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);\r\n}\r\n\r\nstatic void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);\r\n  p->counters[posState] = p->tableSize;\r\n}\r\n\r\nstatic void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)\r\n{\r\n  UInt32 posState;\r\n  for (posState = 0; posState < numPosStates; posState++)\r\n    LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\nstatic void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)\r\n{\r\n  LenEnc_Encode(&p->p, rc, symbol, posState);\r\n  if (updatePrice)\r\n    if (--p->counters[posState] == 0)\r\n      LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r\n}\r\n\r\n\r\n\r\n\r\nstatic void MovePos(CLzmaEnc *p, UInt32 num)\r\n{\r\n  #ifdef SHOW_STAT\r\n  ttt += num;\r\n  printf(\"\\n MovePos %d\", num);\r\n  #endif\r\n  if (num != 0)\r\n  {\r\n    p->additionalOffset += num;\r\n    p->matchFinder.Skip(p->matchFinderObj, num);\r\n  }\r\n}\r\n\r\nstatic UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)\r\n{\r\n  UInt32 lenRes = 0, numPairs;\r\n  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);\r\n  #ifdef SHOW_STAT\r\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numPairs / 2);\r\n  ttt++;\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < numPairs; i += 2)\r\n      printf(\"%2d %6d   | \", p->matches[i], p->matches[i + 1]);\r\n  }\r\n  #endif\r\n  if (numPairs > 0)\r\n  {\r\n    lenRes = p->matches[numPairs - 2];\r\n    if (lenRes == p->numFastBytes)\r\n    {\r\n      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n      UInt32 distance = p->matches[numPairs - 1] + 1;\r\n      UInt32 numAvail = p->numAvail;\r\n      if (numAvail > LZMA_MATCH_LEN_MAX)\r\n        numAvail = LZMA_MATCH_LEN_MAX;\r\n      {\r\n        const Byte *pby2 = pby - distance;\r\n        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r\n      }\r\n    }\r\n  }\r\n  p->additionalOffset++;\r\n  *numDistancePairsRes = numPairs;\r\n  return lenRes;\r\n}\r\n\r\n\r\n#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;\r\n#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;\r\n#define IsShortRep(p) ((p)->backPrev == 0)\r\n\r\nstatic UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)\r\n{\r\n  return\r\n    GET_PRICE_0(p->isRepG0[state]) +\r\n    GET_PRICE_0(p->isRep0Long[state][posState]);\r\n}\r\n\r\nstatic UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)\r\n{\r\n  UInt32 price;\r\n  if (repIndex == 0)\r\n  {\r\n    price = GET_PRICE_0(p->isRepG0[state]);\r\n    price += GET_PRICE_1(p->isRep0Long[state][posState]);\r\n  }\r\n  else\r\n  {\r\n    price = GET_PRICE_1(p->isRepG0[state]);\r\n    if (repIndex == 1)\r\n      price += GET_PRICE_0(p->isRepG1[state]);\r\n    else\r\n    {\r\n      price += GET_PRICE_1(p->isRepG1[state]);\r\n      price += GET_PRICE(p->isRepG2[state], repIndex - 2);\r\n    }\r\n  }\r\n  return price;\r\n}\r\n\r\nstatic UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)\r\n{\r\n  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +\r\n    GetPureRepPrice(p, repIndex, state, posState);\r\n}\r\n\r\nstatic UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)\r\n{\r\n  UInt32 posMem = p->opt[cur].posPrev;\r\n  UInt32 backMem = p->opt[cur].backPrev;\r\n  p->optimumEndIndex = cur;\r\n  do\r\n  {\r\n    if (p->opt[cur].prev1IsChar)\r\n    {\r\n      MakeAsChar(&p->opt[posMem])\r\n      p->opt[posMem].posPrev = posMem - 1;\r\n      if (p->opt[cur].prev2)\r\n      {\r\n        p->opt[posMem - 1].prev1IsChar = False;\r\n        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;\r\n        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;\r\n      }\r\n    }\r\n    {\r\n      UInt32 posPrev = posMem;\r\n      UInt32 backCur = backMem;\r\n      \r\n      backMem = p->opt[posPrev].backPrev;\r\n      posMem = p->opt[posPrev].posPrev;\r\n      \r\n      p->opt[posPrev].backPrev = backCur;\r\n      p->opt[posPrev].posPrev = cur;\r\n      cur = posPrev;\r\n    }\r\n  }\r\n  while (cur != 0);\r\n  *backRes = p->opt[0].backPrev;\r\n  p->optimumCurrentIndex  = p->opt[0].posPrev;\r\n  return p->optimumCurrentIndex;\r\n}\r\n\r\n#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)\r\n\r\nstatic UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;\r\n  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\r\n  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];\r\n  UInt32 *matches;\r\n  const Byte *data;\r\n  Byte curByte, matchByte;\r\n  if (p->optimumEndIndex != p->optimumCurrentIndex)\r\n  {\r\n    const COptimal *opt = &p->opt[p->optimumCurrentIndex];\r\n    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;\r\n    *backRes = opt->backPrev;\r\n    p->optimumCurrentIndex = opt->posPrev;\r\n    return lenRes;\r\n  }\r\n  p->optimumCurrentIndex = p->optimumEndIndex = 0;\r\n  \r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  if (numAvail < 2)\r\n  {\r\n    *backRes = (UInt32)(-1);\r\n    return 1;\r\n  }\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  repMaxIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 lenTest;\r\n    const Byte *data2;\r\n    reps[i] = p->reps[i];\r\n    data2 = data - (reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n    {\r\n      repLens[i] = 0;\r\n      continue;\r\n    }\r\n    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n    repLens[i] = lenTest;\r\n    if (lenTest > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if (repLens[repMaxIndex] >= p->numFastBytes)\r\n  {\r\n    UInt32 lenRes;\r\n    *backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    MovePos(p, lenRes - 1);\r\n    return lenRes;\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n  curByte = *data;\r\n  matchByte = *(data - (reps[0] + 1));\r\n\r\n  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)\r\n  {\r\n    *backRes = (UInt32)-1;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[0].state = (CState)p->state;\r\n\r\n  posState = (position & p->pbMask);\r\n\r\n  {\r\n    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +\r\n        (!IsCharState(p->state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n  }\r\n\r\n  MakeAsChar(&p->opt[1]);\r\n\r\n  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);\r\n  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);\r\n\r\n  if (matchByte == curByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);\r\n    if (shortRepPrice < p->opt[1].price)\r\n    {\r\n      p->opt[1].price = shortRepPrice;\r\n      MakeAsShortRep(&p->opt[1]);\r\n    }\r\n  }\r\n  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);\r\n\r\n  if (lenEnd < 2)\r\n  {\r\n    *backRes = p->opt[1].backPrev;\r\n    return 1;\r\n  }\r\n\r\n  p->opt[1].posPrev = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n    p->opt[0].backs[i] = reps[i];\r\n\r\n  len = lenEnd;\r\n  do\r\n    p->opt[len--].price = kInfinityPrice;\r\n  while (len >= 2);\r\n\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    UInt32 price;\r\n    if (repLen < 2)\r\n      continue;\r\n    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);\r\n    do\r\n    {\r\n      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];\r\n      COptimal *opt = &p->opt[repLen];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = i;\r\n        opt->prev1IsChar = False;\r\n      }\r\n    }\r\n    while (--repLen >= 2);\r\n  }\r\n\r\n  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);\r\n\r\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n  if (len <= mainLen)\r\n  {\r\n    UInt32 offs = 0;\r\n    while (len > matches[offs])\r\n      offs += 2;\r\n    for (; ; len++)\r\n    {\r\n      COptimal *opt;\r\n      UInt32 distance = matches[offs + 1];\r\n\r\n      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];\r\n      UInt32 lenToPosState = GetLenToPosState(len);\r\n      if (distance < kNumFullDistances)\r\n        curAndLenPrice += p->distancesPrices[lenToPosState][distance];\r\n      else\r\n      {\r\n        UInt32 slot;\r\n        GetPosSlot2(distance, slot);\r\n        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];\r\n      }\r\n      opt = &p->opt[len];\r\n      if (curAndLenPrice < opt->price)\r\n      {\r\n        opt->price = curAndLenPrice;\r\n        opt->posPrev = 0;\r\n        opt->backPrev = distance + LZMA_NUM_REPS;\r\n        opt->prev1IsChar = False;\r\n      }\r\n      if (len == matches[offs])\r\n      {\r\n        offs += 2;\r\n        if (offs == numPairs)\r\n          break;\r\n      }\r\n    }\r\n  }\r\n\r\n  cur = 0;\r\n\r\n    #ifdef SHOW_STAT2\r\n    if (position >= 0)\r\n    {\r\n      unsigned i;\r\n      printf(\"\\n pos = %4X\", position);\r\n      for (i = cur; i <= lenEnd; i++)\r\n      printf(\"\\nprice[%4X] = %d\", position - cur + i, p->opt[i].price);\r\n    }\r\n    #endif\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;\r\n    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;\r\n    Bool nextIsChar;\r\n    Byte curByte, matchByte;\r\n    const Byte *data;\r\n    COptimal *curOpt;\r\n    COptimal *nextOpt;\r\n\r\n    cur++;\r\n    if (cur == lenEnd)\r\n      return Backward(p, backRes, cur);\r\n\r\n    newLen = ReadMatchDistances(p, &numPairs);\r\n    if (newLen >= p->numFastBytes)\r\n    {\r\n      p->numPairs = numPairs;\r\n      p->longestMatchLength = newLen;\r\n      return Backward(p, backRes, cur);\r\n    }\r\n    position++;\r\n    curOpt = &p->opt[cur];\r\n    posPrev = curOpt->posPrev;\r\n    if (curOpt->prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOpt->prev2)\r\n      {\r\n        state = p->opt[curOpt->posPrev2].state;\r\n        if (curOpt->backPrev2 < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      else\r\n        state = p->opt[posPrev].state;\r\n      state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n      state = p->opt[posPrev].state;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (IsShortRep(curOpt))\r\n        state = kShortRepNextStates[state];\r\n      else\r\n        state = kLiteralNextStates[state];\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      const COptimal *prevOpt;\r\n      if (curOpt->prev1IsChar && curOpt->prev2)\r\n      {\r\n        posPrev = curOpt->posPrev2;\r\n        pos = curOpt->backPrev2;\r\n        state = kRepNextStates[state];\r\n      }\r\n      else\r\n      {\r\n        pos = curOpt->backPrev;\r\n        if (pos < LZMA_NUM_REPS)\r\n          state = kRepNextStates[state];\r\n        else\r\n          state = kMatchNextStates[state];\r\n      }\r\n      prevOpt = &p->opt[posPrev];\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        UInt32 i;\r\n        reps[0] = prevOpt->backs[pos];\r\n        for (i = 1; i <= pos; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n        for (; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i];\r\n      }\r\n      else\r\n      {\r\n        UInt32 i;\r\n        reps[0] = (pos - LZMA_NUM_REPS);\r\n        for (i = 1; i < LZMA_NUM_REPS; i++)\r\n          reps[i] = prevOpt->backs[i - 1];\r\n      }\r\n    }\r\n    curOpt->state = (CState)state;\r\n\r\n    curOpt->backs[0] = reps[0];\r\n    curOpt->backs[1] = reps[1];\r\n    curOpt->backs[2] = reps[2];\r\n    curOpt->backs[3] = reps[3];\r\n\r\n    curPrice = curOpt->price;\r\n    nextIsChar = False;\r\n    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n    curByte = *data;\r\n    matchByte = *(data - (reps[0] + 1));\r\n\r\n    posState = (position & p->pbMask);\r\n\r\n    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);\r\n    {\r\n      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\r\n      curAnd1Price +=\r\n        (!IsCharState(state) ?\r\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\r\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\r\n    }\r\n\r\n    nextOpt = &p->opt[cur + 1];\r\n\r\n    if (curAnd1Price < nextOpt->price)\r\n    {\r\n      nextOpt->price = curAnd1Price;\r\n      nextOpt->posPrev = cur;\r\n      MakeAsChar(nextOpt);\r\n      nextIsChar = True;\r\n    }\r\n\r\n    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);\r\n    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);\r\n    \r\n    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);\r\n      if (shortRepPrice <= nextOpt->price)\r\n      {\r\n        nextOpt->price = shortRepPrice;\r\n        nextOpt->posPrev = cur;\r\n        MakeAsShortRep(nextOpt);\r\n        nextIsChar = True;\r\n      }\r\n    }\r\n    numAvailFull = p->numAvail;\r\n    {\r\n      UInt32 temp = kNumOpts - 1 - cur;\r\n      if (temp < numAvailFull)\r\n        numAvailFull = temp;\r\n    }\r\n\r\n    if (numAvailFull < 2)\r\n      continue;\r\n    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);\r\n\r\n    if (!nextIsChar && matchByte != curByte) /* speed optimization */\r\n    {\r\n      /* try Literal + rep0 */\r\n      UInt32 temp;\r\n      UInt32 lenTest2;\r\n      const Byte *data2 = data - (reps[0] + 1);\r\n      UInt32 limit = p->numFastBytes + 1;\r\n      if (limit > numAvailFull)\r\n        limit = numAvailFull;\r\n\r\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\r\n      lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        UInt32 state2 = kLiteralNextStates[state];\r\n        UInt32 posStateNext = (position + 1) & p->pbMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price +\r\n            GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n            GET_PRICE_1(p->isRep[state2]);\r\n        /* for (; lenTest2 >= 2; lenTest2--) */\r\n        {\r\n          UInt32 curAndLenPrice;\r\n          COptimal *opt;\r\n          UInt32 offset = cur + 1 + lenTest2;\r\n          while (lenEnd < offset)\r\n            p->opt[++lenEnd].price = kInfinityPrice;\r\n          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n          opt = &p->opt[offset];\r\n          if (curAndLenPrice < opt->price)\r\n          {\r\n            opt->price = curAndLenPrice;\r\n            opt->posPrev = cur + 1;\r\n            opt->backPrev = 0;\r\n            opt->prev1IsChar = True;\r\n            opt->prev2 = False;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \r\n    startLen = 2; /* speed optimization */\r\n    {\r\n    UInt32 repIndex;\r\n    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)\r\n    {\r\n      UInt32 lenTest;\r\n      UInt32 lenTestTemp;\r\n      UInt32 price;\r\n      const Byte *data2 = data - (reps[repIndex] + 1);\r\n      if (data[0] != data2[0] || data[1] != data2[1])\r\n        continue;\r\n      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r\n      while (lenEnd < cur + lenTest)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n      lenTestTemp = lenTest;\r\n      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);\r\n      do\r\n      {\r\n        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];\r\n        COptimal *opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = repIndex;\r\n          opt->prev1IsChar = False;\r\n        }\r\n      }\r\n      while (--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n      \r\n      if (repIndex == 0)\r\n        startLen = lenTest + 1;\r\n        \r\n      /* if (_maxMode) */\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kRepNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice =\r\n                price + p->repLenEnc.prices[posState][lenTest - 2] +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (position + lenTest + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n    }\r\n    }\r\n    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */\r\n    if (newLen > numAvail)\r\n    {\r\n      newLen = numAvail;\r\n      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);\r\n      matches[numPairs] = newLen;\r\n      numPairs += 2;\r\n    }\r\n    if (newLen >= startLen)\r\n    {\r\n      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\r\n      UInt32 offs, curBack, posSlot;\r\n      UInt32 lenTest;\r\n      while (lenEnd < cur + newLen)\r\n        p->opt[++lenEnd].price = kInfinityPrice;\r\n\r\n      offs = 0;\r\n      while (startLen > matches[offs])\r\n        offs += 2;\r\n      curBack = matches[offs + 1];\r\n      GetPosSlot2(curBack, posSlot);\r\n      for (lenTest = /*2*/ startLen; ; lenTest++)\r\n      {\r\n        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\r\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\r\n        COptimal *opt;\r\n        if (curBack < kNumFullDistances)\r\n          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];\r\n        else\r\n          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];\r\n        \r\n        opt = &p->opt[cur + lenTest];\r\n        if (curAndLenPrice < opt->price)\r\n        {\r\n          opt->price = curAndLenPrice;\r\n          opt->posPrev = cur;\r\n          opt->backPrev = curBack + LZMA_NUM_REPS;\r\n          opt->prev1IsChar = False;\r\n        }\r\n\r\n        if (/*_maxMode && */lenTest == matches[offs])\r\n        {\r\n          /* Try Match + Literal + Rep0 */\r\n          const Byte *data2 = data - (curBack + 1);\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = lenTest2 + p->numFastBytes;\r\n          UInt32 nextRepMatchPrice;\r\n          if (limit > numAvailFull)\r\n            limit = numAvailFull;\r\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            UInt32 state2 = kMatchNextStates[state];\r\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice +\r\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\r\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\r\n                    data[lenTest], data2[lenTest], p->ProbPrices);\r\n            state2 = kLiteralNextStates[state2];\r\n            posStateNext = (posStateNext + 1) & p->pbMask;\r\n            nextRepMatchPrice = curAndLenCharPrice +\r\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\r\n                GET_PRICE_1(p->isRep[state2]);\r\n            \r\n            /* for (; lenTest2 >= 2; lenTest2--) */\r\n            {\r\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\r\n              UInt32 curAndLenPrice;\r\n              COptimal *opt;\r\n              while (lenEnd < offset)\r\n                p->opt[++lenEnd].price = kInfinityPrice;\r\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r\n              opt = &p->opt[offset];\r\n              if (curAndLenPrice < opt->price)\r\n              {\r\n                opt->price = curAndLenPrice;\r\n                opt->posPrev = cur + lenTest + 1;\r\n                opt->backPrev = 0;\r\n                opt->prev1IsChar = True;\r\n                opt->prev2 = True;\r\n                opt->posPrev2 = cur;\r\n                opt->backPrev2 = curBack + LZMA_NUM_REPS;\r\n              }\r\n            }\r\n          }\r\n          offs += 2;\r\n          if (offs == numPairs)\r\n            break;\r\n          curBack = matches[offs + 1];\r\n          if (curBack >= kNumFullDistances)\r\n            GetPosSlot2(curBack, posSlot);\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))\r\n\r\nstatic UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)\r\n{\r\n  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;\r\n  const Byte *data;\r\n  const UInt32 *matches;\r\n\r\n  if (p->additionalOffset == 0)\r\n    mainLen = ReadMatchDistances(p, &numPairs);\r\n  else\r\n  {\r\n    mainLen = p->longestMatchLength;\r\n    numPairs = p->numPairs;\r\n  }\r\n\r\n  numAvail = p->numAvail;\r\n  *backRes = (UInt32)-1;\r\n  if (numAvail < 2)\r\n    return 1;\r\n  if (numAvail > LZMA_MATCH_LEN_MAX)\r\n    numAvail = LZMA_MATCH_LEN_MAX;\r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n\r\n  repLen = repIndex = 0;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    for (len = 2; len < numAvail && data[len] == data2[len]; len++);\r\n    if (len >= p->numFastBytes)\r\n    {\r\n      *backRes = i;\r\n      MovePos(p, len - 1);\r\n      return len;\r\n    }\r\n    if (len > repLen)\r\n    {\r\n      repIndex = i;\r\n      repLen = len;\r\n    }\r\n  }\r\n\r\n  matches = p->matches;\r\n  if (mainLen >= p->numFastBytes)\r\n  {\r\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\r\n    MovePos(p, mainLen - 1);\r\n    return mainLen;\r\n  }\r\n\r\n  mainDist = 0; /* for GCC */\r\n  if (mainLen >= 2)\r\n  {\r\n    mainDist = matches[numPairs - 1];\r\n    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)\r\n    {\r\n      if (!ChangePair(matches[numPairs - 3], mainDist))\r\n        break;\r\n      numPairs -= 2;\r\n      mainLen = matches[numPairs - 2];\r\n      mainDist = matches[numPairs - 1];\r\n    }\r\n    if (mainLen == 2 && mainDist >= 0x80)\r\n      mainLen = 1;\r\n  }\r\n\r\n  if (repLen >= 2 && (\r\n        (repLen + 1 >= mainLen) ||\r\n        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||\r\n        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))\r\n  {\r\n    *backRes = repIndex;\r\n    MovePos(p, repLen - 1);\r\n    return repLen;\r\n  }\r\n  \r\n  if (mainLen < 2 || numAvail <= 2)\r\n    return 1;\r\n\r\n  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);\r\n  if (p->longestMatchLength >= 2)\r\n  {\r\n    UInt32 newDistance = matches[p->numPairs - 1];\r\n    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||\r\n        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||\r\n        (p->longestMatchLength > mainLen + 1) ||\r\n        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))\r\n      return 1;\r\n  }\r\n  \r\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r\n  for (i = 0; i < LZMA_NUM_REPS; i++)\r\n  {\r\n    UInt32 len, limit;\r\n    const Byte *data2 = data - (p->reps[i] + 1);\r\n    if (data[0] != data2[0] || data[1] != data2[1])\r\n      continue;\r\n    limit = mainLen - 1;\r\n    for (len = 2; len < limit && data[len] == data2[len]; len++);\r\n    if (len >= limit)\r\n      return 1;\r\n  }\r\n  *backRes = mainDist + LZMA_NUM_REPS;\r\n  MovePos(p, mainLen - 2);\r\n  return mainLen;\r\n}\r\n\r\nstatic void WriteEndMarker(CLzmaEnc *p, UInt32 posState)\r\n{\r\n  UInt32 len;\r\n  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n  p->state = kMatchNextStates[p->state];\r\n  len = LZMA_MATCH_LEN_MIN;\r\n  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);\r\n  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);\r\n  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);\r\n}\r\n\r\nstatic SRes CheckErrors(CLzmaEnc *p)\r\n{\r\n  if (p->result != SZ_OK)\r\n    return p->result;\r\n  if (p->rc.res != SZ_OK)\r\n    p->result = SZ_ERROR_WRITE;\r\n  if (p->matchFinderBase.result != SZ_OK)\r\n    p->result = SZ_ERROR_READ;\r\n  if (p->result != SZ_OK)\r\n    p->finished = True;\r\n  return p->result;\r\n}\r\n\r\nstatic SRes Flush(CLzmaEnc *p, UInt32 nowPos)\r\n{\r\n  /* ReleaseMFStream(); */\r\n  p->finished = True;\r\n  if (p->writeEndMark)\r\n    WriteEndMarker(p, nowPos & p->pbMask);\r\n  RangeEnc_FlushData(&p->rc);\r\n  RangeEnc_FlushStream(&p->rc);\r\n  return CheckErrors(p);\r\n}\r\n\r\nstatic void FillAlignPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < kAlignTableSize; i++)\r\n    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);\r\n  p->alignPriceCount = 0;\r\n}\r\n\r\nstatic void FillDistancesPrices(CLzmaEnc *p)\r\n{\r\n  UInt32 tempPrices[kNumFullDistances];\r\n  UInt32 i, lenToPosState;\r\n  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)\r\n  {\r\n    UInt32 posSlot = GetPosSlot1(i);\r\n    UInt32 footerBits = ((posSlot >> 1) - 1);\r\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);\r\n  }\r\n\r\n  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n    UInt32 posSlot;\r\n    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];\r\n    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];\r\n    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);\r\n    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)\r\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);\r\n\r\n    {\r\n      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];\r\n      UInt32 i;\r\n      for (i = 0; i < kStartPosModelIndex; i++)\r\n        distancesPrices[i] = posSlotPrices[i];\r\n      for (; i < kNumFullDistances; i++)\r\n        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];\r\n    }\r\n  }\r\n  p->matchPriceCount = 0;\r\n}\r\n\r\nvoid LzmaEnc_Construct(CLzmaEnc *p)\r\n{\r\n  RangeEnc_Construct(&p->rc);\r\n  MatchFinder_Construct(&p->matchFinderBase);\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Construct(&p->matchFinderMt);\r\n  p->matchFinderMt.MatchFinder = &p->matchFinderBase;\r\n  #endif\r\n\r\n  {\r\n    CLzmaEncProps props;\r\n    LzmaEncProps_Init(&props);\r\n    LzmaEnc_SetProps(p, &props);\r\n  }\r\n\r\n  #ifndef LZMA_LOG_BSR\r\n  LzmaEnc_FastPosInit(p->g_FastPos);\r\n  #endif\r\n\r\n  LzmaEnc_InitPriceTables(p->ProbPrices);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)\r\n{\r\n  void *p;\r\n  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));\r\n  if (p != 0)\r\n    LzmaEnc_Construct((CLzmaEnc *)p);\r\n  return p;\r\n}\r\n\r\nvoid LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)\r\n{\r\n  alloc->Free(alloc, p->litProbs);\r\n  alloc->Free(alloc, p->saveState.litProbs);\r\n  p->litProbs = 0;\r\n  p->saveState.litProbs = 0;\r\n}\r\n\r\nvoid LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);\r\n  #endif\r\n  MatchFinder_Free(&p->matchFinderBase, allocBig);\r\n  LzmaEnc_FreeLits(p, alloc);\r\n  RangeEnc_Free(&p->rc, alloc);\r\n}\r\n\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);\r\n  alloc->Free(alloc, p);\r\n}\r\n\r\nstatic SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)\r\n{\r\n  UInt32 nowPos32, startPos32;\r\n  if (p->inStream != 0)\r\n  {\r\n    p->matchFinderBase.stream = p->inStream;\r\n    p->matchFinder.Init(p->matchFinderObj);\r\n    p->inStream = 0;\r\n  }\r\n\r\n  if (p->finished)\r\n    return p->result;\r\n  RINOK(CheckErrors(p));\r\n\r\n  nowPos32 = (UInt32)p->nowPos64;\r\n  startPos32 = nowPos32;\r\n\r\n  if (p->nowPos64 == 0)\r\n  {\r\n    UInt32 numPairs;\r\n    Byte curByte;\r\n    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n      return Flush(p, nowPos32);\r\n    ReadMatchDistances(p, &numPairs);\r\n    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);\r\n    p->state = kLiteralNextStates[p->state];\r\n    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);\r\n    LitEnc_Encode(&p->rc, p->litProbs, curByte);\r\n    p->additionalOffset--;\r\n    nowPos32++;\r\n  }\r\n\r\n  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)\r\n  for (;;)\r\n  {\r\n    UInt32 pos, len, posState;\r\n\r\n    if (p->fastMode)\r\n      len = GetOptimumFast(p, &pos);\r\n    else\r\n      len = GetOptimum(p, nowPos32, &pos);\r\n\r\n    #ifdef SHOW_STAT2\r\n    printf(\"\\n pos = %4X,   len = %d   pos = %d\", nowPos32, len, pos);\r\n    #endif\r\n\r\n    posState = nowPos32 & p->pbMask;\r\n    if (len == 1 && pos == (UInt32)-1)\r\n    {\r\n      Byte curByte;\r\n      CLzmaProb *probs;\r\n      const Byte *data;\r\n\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);\r\n      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n      curByte = *data;\r\n      probs = LIT_PROBS(nowPos32, *(data - 1));\r\n      if (IsCharState(p->state))\r\n        LitEnc_Encode(&p->rc, probs, curByte);\r\n      else\r\n        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));\r\n      p->state = kLiteralNextStates[p->state];\r\n    }\r\n    else\r\n    {\r\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\r\n      if (pos < LZMA_NUM_REPS)\r\n      {\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);\r\n        if (pos == 0)\r\n        {\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance = p->reps[pos];\r\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);\r\n          if (pos == 1)\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);\r\n          else\r\n          {\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);\r\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);\r\n            if (pos == 3)\r\n              p->reps[3] = p->reps[2];\r\n            p->reps[2] = p->reps[1];\r\n          }\r\n          p->reps[1] = p->reps[0];\r\n          p->reps[0] = distance;\r\n        }\r\n        if (len == 1)\r\n          p->state = kShortRepNextStates[p->state];\r\n        else\r\n        {\r\n          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n          p->state = kRepNextStates[p->state];\r\n        }\r\n      }\r\n      else\r\n      {\r\n        UInt32 posSlot;\r\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\r\n        p->state = kMatchNextStates[p->state];\r\n        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\r\n        pos -= LZMA_NUM_REPS;\r\n        GetPosSlot(pos, posSlot);\r\n        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);\r\n          else\r\n          {\r\n            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);\r\n            p->alignPriceCount++;\r\n          }\r\n        }\r\n        p->reps[3] = p->reps[2];\r\n        p->reps[2] = p->reps[1];\r\n        p->reps[1] = p->reps[0];\r\n        p->reps[0] = pos;\r\n        p->matchPriceCount++;\r\n      }\r\n    }\r\n    p->additionalOffset -= len;\r\n    nowPos32 += len;\r\n    if (p->additionalOffset == 0)\r\n    {\r\n      UInt32 processed;\r\n      if (!p->fastMode)\r\n      {\r\n        if (p->matchPriceCount >= (1 << 7))\r\n          FillDistancesPrices(p);\r\n        if (p->alignPriceCount >= kAlignTableSize)\r\n          FillAlignPrices(p);\r\n      }\r\n      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\r\n        break;\r\n      processed = nowPos32 - startPos32;\r\n      if (useLimits)\r\n      {\r\n        if (processed + kNumOpts + 300 >= maxUnpackSize ||\r\n            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)\r\n          break;\r\n      }\r\n      else if (processed >= (1 << 15))\r\n      {\r\n        p->nowPos64 += nowPos32 - startPos32;\r\n        return CheckErrors(p);\r\n      }\r\n    }\r\n  }\r\n  p->nowPos64 += nowPos32 - startPos32;\r\n  return Flush(p, nowPos32);\r\n}\r\n\r\n#define kBigHashDicLimit ((UInt32)1 << 24)\r\n\r\nstatic SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 beforeSize = kNumOpts;\r\n  Bool btMode;\r\n  if (!RangeEnc_Alloc(&p->rc, alloc))\r\n    return SZ_ERROR_MEM;\r\n  btMode = (p->matchFinderBase.btMode != 0);\r\n  #ifdef COMPRESS_MF_MT\r\n  p->mtMode = (p->multiThread && !p->fastMode && btMode);\r\n  #endif\r\n\r\n  {\r\n    unsigned lclp = p->lc + p->lp;\r\n    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)\r\n    {\r\n      LzmaEnc_FreeLits(p, alloc);\r\n      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r\n      if (p->litProbs == 0 || p->saveState.litProbs == 0)\r\n      {\r\n        LzmaEnc_FreeLits(p, alloc);\r\n        return SZ_ERROR_MEM;\r\n      }\r\n      p->lclp = lclp;\r\n    }\r\n  }\r\n\r\n  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);\r\n\r\n  if (beforeSize + p->dictSize < keepWindowSize)\r\n    beforeSize = keepWindowSize - p->dictSize;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (p->mtMode)\r\n  {\r\n    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));\r\n    p->matchFinderObj = &p->matchFinderMt;\r\n    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))\r\n      return SZ_ERROR_MEM;\r\n    p->matchFinderObj = &p->matchFinderBase;\r\n    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nvoid LzmaEnc_Init(CLzmaEnc *p)\r\n{\r\n  UInt32 i;\r\n  p->state = 0;\r\n  for (i = 0 ; i < LZMA_NUM_REPS; i++)\r\n    p->reps[i] = 0;\r\n\r\n  RangeEnc_Init(&p->rc);\r\n\r\n\r\n  for (i = 0; i < kNumStates; i++)\r\n  {\r\n    UInt32 j;\r\n    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)\r\n    {\r\n      p->isMatch[i][j] = kProbInitValue;\r\n      p->isRep0Long[i][j] = kProbInitValue;\r\n    }\r\n    p->isRep[i] = kProbInitValue;\r\n    p->isRepG0[i] = kProbInitValue;\r\n    p->isRepG1[i] = kProbInitValue;\r\n    p->isRepG2[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    UInt32 num = 0x300 << (p->lp + p->lc);\r\n    for (i = 0; i < num; i++)\r\n      p->litProbs[i] = kProbInitValue;\r\n  }\r\n\r\n  {\r\n    for (i = 0; i < kNumLenToPosStates; i++)\r\n    {\r\n      CLzmaProb *probs = p->posSlotEncoder[i];\r\n      UInt32 j;\r\n      for (j = 0; j < (1 << kNumPosSlotBits); j++)\r\n        probs[j] = kProbInitValue;\r\n    }\r\n  }\r\n  {\r\n    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      p->posEncoders[i] = kProbInitValue;\r\n  }\r\n\r\n  LenEnc_Init(&p->lenEnc.p);\r\n  LenEnc_Init(&p->repLenEnc.p);\r\n\r\n  for (i = 0; i < (1 << kNumAlignBits); i++)\r\n    p->posAlignEncoder[i] = kProbInitValue;\r\n\r\n  p->optimumEndIndex = 0;\r\n  p->optimumCurrentIndex = 0;\r\n  p->additionalOffset = 0;\r\n\r\n  p->pbMask = (1 << p->pb) - 1;\r\n  p->lpMask = (1 << p->lp) - 1;\r\n}\r\n\r\nvoid LzmaEnc_InitPrices(CLzmaEnc *p)\r\n{\r\n  if (!p->fastMode)\r\n  {\r\n    FillDistancesPrices(p);\r\n    FillAlignPrices(p);\r\n  }\r\n\r\n  p->lenEnc.tableSize =\r\n  p->repLenEnc.tableSize =\r\n      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;\r\n  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);\r\n  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);\r\n}\r\n\r\nstatic SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)\r\n    if (p->dictSize <= ((UInt32)1 << i))\r\n      break;\r\n  p->distTableSize = i * 2;\r\n\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));\r\n  LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  p->nowPos64 = 0;\r\n  return SZ_OK;\r\n}\r\n\r\nstatic SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  p->rc.outStream = outStream;\r\n  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);\r\n}\r\n\r\nSRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,\r\n    ISeqInStream *inStream, UInt32 keepWindowSize,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  p->inStream = inStream;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nstatic void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)\r\n{\r\n  p->seqBufInStream.funcTable.Read = MyRead;\r\n  p->seqBufInStream.data = src;\r\n  p->seqBufInStream.rem = srcLen;\r\n}\r\n\r\nSRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\r\n    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n  p->inStream = &p->seqBufInStream.funcTable;\r\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r\n}\r\n\r\nvoid LzmaEnc_Finish(CLzmaEncHandle pp)\r\n{\r\n  #ifdef COMPRESS_MF_MT\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  if (p->mtMode)\r\n    MatchFinderMt_ReleaseStream(&p->matchFinderMt);\r\n  #else\r\n  pp = pp;\r\n  #endif\r\n}\r\n\r\ntypedef struct _CSeqOutStreamBuf\r\n{\r\n  ISeqOutStream funcTable;\r\n  Byte *data;\r\n  SizeT rem;\r\n  Bool overflow;\r\n} CSeqOutStreamBuf;\r\n\r\nstatic size_t MyWrite(void *pp, const void *data, size_t size)\r\n{\r\n  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;\r\n  if (p->rem < size)\r\n  {\r\n    size = p->rem;\r\n    p->overflow = True;\r\n  }\r\n  memcpy(p->data, data, size);\r\n  p->rem -= size;\r\n  p->data += size;\r\n  return size;\r\n}\r\n\r\n\r\nUInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r\n}\r\n\r\nconst Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)\r\n{\r\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r\n}\r\n\r\nSRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\r\n    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  UInt64 nowPos64;\r\n  SRes res;\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = False;\r\n  p->finished = False;\r\n  p->result = SZ_OK;\r\n\r\n  if (reInit)\r\n    LzmaEnc_Init(p);\r\n  LzmaEnc_InitPrices(p);\r\n  nowPos64 = p->nowPos64;\r\n  RangeEnc_Init(&p->rc);\r\n  p->rc.outStream = &outStream.funcTable;\r\n\r\n  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);\r\n  \r\n  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\r\n    ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  SRes res = SZ_OK;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  Byte allocaDummy[0x300];\r\n  int i = 0;\r\n  for (i = 0; i < 16; i++)\r\n    allocaDummy[i] = (Byte)i;\r\n  #endif\r\n\r\n  RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));\r\n\r\n  for (;;)\r\n  {\r\n    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);\r\n    if (res != SZ_OK || p->finished != 0)\r\n      break;\r\n    if (progress != 0)\r\n    {\r\n      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));\r\n      if (res != SZ_OK)\r\n      {\r\n        res = SZ_ERROR_PROGRESS;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  LzmaEnc_Finish(pp);\r\n  return res;\r\n}\r\n\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n  int i;\r\n  UInt32 dictSize = p->dictSize;\r\n  if (*size < LZMA_PROPS_SIZE)\r\n    return SZ_ERROR_PARAM;\r\n  *size = LZMA_PROPS_SIZE;\r\n  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);\r\n\r\n  for (i = 11; i <= 30; i++)\r\n  {\r\n    if (dictSize <= ((UInt32)2 << i))\r\n    {\r\n      dictSize = (2 << i);\r\n      break;\r\n    }\r\n    if (dictSize <= ((UInt32)3 << i))\r\n    {\r\n      dictSize = (3 << i);\r\n      break;\r\n    }\r\n  }\r\n\r\n  for (i = 0; i < 4; i++)\r\n    props[1 + i] = (Byte)(dictSize >> (8 * i));\r\n  return SZ_OK;\r\n}\r\n\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  SRes res;\r\n  CLzmaEnc *p = (CLzmaEnc *)pp;\r\n\r\n  CSeqOutStreamBuf outStream;\r\n\r\n  LzmaEnc_SetInputBuf(p, src, srcLen);\r\n\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.data = dest;\r\n  outStream.rem = *destLen;\r\n  outStream.overflow = False;\r\n\r\n  p->writeEndMark = writeEndMark;\r\n  res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,\r\n      progress, alloc, allocBig);\r\n\r\n  *destLen -= outStream.rem;\r\n  if (outStream.overflow)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n  return res;\r\n}\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r\n{\r\n  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);\r\n  SRes res;\r\n  if (p == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  res = LzmaEnc_SetProps(p, props);\r\n  if (res == SZ_OK)\r\n  {\r\n    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);\r\n    if (res == SZ_OK)\r\n      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,\r\n          writeEndMark, progress, alloc, allocBig);\r\n  }\r\n\r\n  LzmaEnc_Destroy(p, alloc, allocBig);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaEnc.h",
    "content": "/*  LzmaEnc.h -- LZMA Encoder\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __LZMAENC_H\r\n#define __LZMAENC_H\r\n\r\n#include \"Types.h\"\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\ntypedef struct _CLzmaEncProps\r\n{\r\n  int level;       /*  0 <= level <= 9 */\r\n  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version\r\n                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version\r\n                       default = (1 << 24) */\r\n  int lc;          /* 0 <= lc <= 8, default = 3 */\r\n  int lp;          /* 0 <= lp <= 4, default = 0 */\r\n  int pb;          /* 0 <= pb <= 4, default = 2 */\r\n  int algo;        /* 0 - fast, 1 - normal, default = 1 */\r\n  int fb;          /* 5 <= fb <= 273, default = 32 */\r\n  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */\r\n  int numHashBytes; /* 2, 3 or 4, default = 4 */\r\n  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */\r\n  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */\r\n  int numThreads;  /* 1 or 2, default = 2 */\r\n} CLzmaEncProps;\r\n\r\nvoid LzmaEncProps_Init(CLzmaEncProps *p);\r\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p);\r\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);\r\n\r\n\r\n/* ---------- CLzmaEncHandle Interface ---------- */\r\n\r\n/* LzmaEnc_* functions can return the following exit codes:\r\nReturns:\r\n  SZ_OK           - OK\r\n  SZ_ERROR_MEM    - Memory allocation error\r\n  SZ_ERROR_PARAM  - Incorrect paramater in props\r\n  SZ_ERROR_WRITE  - Write callback error.\r\n  SZ_ERROR_PROGRESS - some break from progress callback\r\n  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\ntypedef void * CLzmaEncHandle;\r\n\r\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);\r\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);\r\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);\r\nSRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\nSRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n/* ---------- One Call Interface ---------- */\r\n\r\n/* LzmaEncode\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaLib/LzmaLib.def",
    "content": "EXPORTS\r\n  LzmaCompress\r\n  LzmaUncompress\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaLib/LzmaLib.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaLib\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n\r\nCFG=LzmaLib - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaLib.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaLib.mak\" CFG=\"LzmaLib - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"LzmaLib - Win32 Release\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n!MESSAGE \"LzmaLib - Win32 Debug\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nMTL=midl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"LzmaLib - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /c\r\n# ADD CPP /nologo /Gr /MT /W3 /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"LzmaLib - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /GZ /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"LzmaLib - Win32 Release\"\r\n# Name \"LzmaLib - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaLib.def\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaLibExports.c\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaLib.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaLib.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Types.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaLib/LzmaLib.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"LzmaLib\"=.\\LzmaLib.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaLib/LzmaLibExports.c",
    "content": "/* LzmaLibExports.c -- LZMA library DLL Entry point\r\n2008-10-04 : Igor Pavlov : Public domain */\r\n\r\n#include <windows.h>\r\n\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r\n{\r\n  hInstance = hInstance;\r\n  dwReason = dwReason;\r\n  lpReserved = lpReserved;\r\n  return TRUE;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaLib/Makefile",
    "content": "CC = gcc\nLIB = liblzma.a\nRM = rm -f\nCFLAGS = -c -O2 -Wall\nAR = ar\nRANLIB = ranlib\n\nOBJS = \\\n  Alloc.o \\\n  LzFind.o \\\n  LzmaDec.o \\\n  LzmaEnc.o \\\n  LzmaLib.o \\\n  7zFile.o \\\n  7zStream.o \\\n\nall: $(LIB)\n\n$(LIB): $(OBJS)\n\trm -f $@\n\t$(AR) rcu $@ $(OBJS)\n\t$(RANLIB) $@\n\nAlloc.o: ../Alloc.c\n\t$(CC) $(CFLAGS) ../Alloc.c\n\nLzFind.o: ../LzFind.c\n\t$(CC) $(CFLAGS) ../LzFind.c\n\nLzmaDec.o: ../LzmaDec.c\n\t$(CC) $(CFLAGS) ../LzmaDec.c\n\nLzmaEnc.o: ../LzmaEnc.c\n\t$(CC) $(CFLAGS) ../LzmaEnc.c\n\nLzmaLib.o: ../LzmaLib.c\n\t$(CC) $(CFLAGS) ../LzmaLib.c\n\n7zFile.o: ../7zFile.c\n\t$(CC) $(CFLAGS) ../7zFile.c\n\n7zStream.o: ../7zStream.c\n\t$(CC) $(CFLAGS) ../7zStream.c\n\nclean:\n\t-$(RM) $(PROG) *.o *.a\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaLib/resource.rc",
    "content": "#include \"../../CPP/7zip/MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"LZMA library\", \"LZMA\")\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaLib.c",
    "content": "/* LzmaLib.c -- LZMA library wrapper\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"LzmaEnc.h\"\r\n#include \"LzmaDec.h\"\r\n#include \"Alloc.h\"\r\n#include \"LzmaLib.h\"\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  srcLen,\r\n  unsigned char *outProps, size_t *outPropsSize,\r\n  int level, /* 0 <= level <= 9, default = 5 */\r\n  unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */\r\n  int lc, /* 0 <= lc <= 8, default = 3  */\r\n  int lp, /* 0 <= lp <= 4, default = 0  */\r\n  int pb, /* 0 <= pb <= 4, default = 2  */\r\n  int fb,  /* 5 <= fb <= 273, default = 32 */\r\n  int numThreads /* 1 or 2, default = 2 */\r\n)\r\n{\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n  props.level = level;\r\n  props.dictSize = dictSize;\r\n  props.lc = lc;\r\n  props.lp = lp;\r\n  props.pb = pb;\r\n  props.fb = fb;\r\n  props.numThreads = numThreads;\r\n\r\n  return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,\r\n      NULL, &g_Alloc, &g_Alloc);\r\n}\r\n\r\n\r\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  *srcLen,\r\n  const unsigned char *props, size_t propsSize)\r\n{\r\n  ELzmaStatus status;\r\n  return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaLib.h",
    "content": "/* LzmaLib.h -- LZMA library interface\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMALIB_H\r\n#define __LZMALIB_H\r\n\r\n#include \"Types.h\"\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL\r\n\r\n#define LZMA_PROPS_SIZE 5\r\n\r\n/*\r\nRAM requirements for LZMA:\r\n  for compression:   (dictSize * 11.5 + 6 MB) + state_size\r\n  for decompression: dictSize + state_size\r\n    state_size = (4 + (1.5 << (lc + lp))) KB\r\n    by default (lc=3, lp=0), state_size = 16 KB.\r\n\r\nLZMA properties (5 bytes) format\r\n    Offset Size  Description\r\n      0     1    lc, lp and pb in encoded form.\r\n      1     4    dictSize (little endian).\r\n*/\r\n\r\n/*\r\nLzmaCompress\r\n------------\r\n\r\noutPropsSize -\r\n     In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r\n     Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\r\n\r\n  LZMA Encoder will use defult values for any parameter, if it is\r\n  -1  for any from: level, loc, lp, pb, fb, numThreads\r\n   0  for dictSize\r\n  \r\nlevel - compression level: 0 <= level <= 9;\r\n\r\n  level dictSize algo  fb\r\n    0:    16 KB   0    32\r\n    1:    64 KB   0    32\r\n    2:   256 KB   0    32\r\n    3:     1 MB   0    32\r\n    4:     4 MB   0    32\r\n    5:    16 MB   1    32\r\n    6:    32 MB   1    32\r\n    7+:   64 MB   1    64\r\n \r\n  The default value for \"level\" is 5.\r\n\r\n  algo = 0 means fast method\r\n  algo = 1 means normal method\r\n\r\ndictSize - The dictionary size in bytes. The maximum value is\r\n        128 MB = (1 << 27) bytes for 32-bit version\r\n          1 GB = (1 << 30) bytes for 64-bit version\r\n     The default value is 16 MB = (1 << 24) bytes.\r\n     It's recommended to use the dictionary that is larger than 4 KB and\r\n     that can be calculated as (1 << N) or (3 << N) sizes.\r\n\r\nlc - The number of literal context bits (high bits of previous literal).\r\n     It can be in the range from 0 to 8. The default value is 3.\r\n     Sometimes lc=4 gives the gain for big files.\r\n\r\nlp - The number of literal pos bits (low bits of current position for literals).\r\n     It can be in the range from 0 to 4. The default value is 0.\r\n     The lp switch is intended for periodical data when the period is equal to 2^lp.\r\n     For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's\r\n     better to set lc=0, if you change lp switch.\r\n\r\npb - The number of pos bits (low bits of current position).\r\n     It can be in the range from 0 to 4. The default value is 2.\r\n     The pb switch is intended for periodical data when the period is equal 2^pb.\r\n\r\nfb - Word size (the number of fast bytes).\r\n     It can be in the range from 5 to 273. The default value is 32.\r\n     Usually, a big number gives a little bit better compression ratio and\r\n     slower compression process.\r\n\r\nnumThreads - The number of thereads. 1 or 2. The default value is 2.\r\n     Fast mode (algo = 0) can use only 1 thread.\r\n\r\nOut:\r\n  destLen  - processed output size\r\nReturns:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,\r\n  unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */\r\n  int level,      /* 0 <= level <= 9, default = 5 */\r\n  unsigned dictSize,  /* default = (1 << 24) */\r\n  int lc,        /* 0 <= lc <= 8, default = 3  */\r\n  int lp,        /* 0 <= lp <= 4, default = 0  */\r\n  int pb,        /* 0 <= pb <= 4, default = 2  */\r\n  int fb,        /* 5 <= fb <= 273, default = 32 */\r\n  int numThreads /* 1 or 2, default = 2 */\r\n  );\r\n\r\n/*\r\nLzmaUncompress\r\n--------------\r\nIn:\r\n  dest     - output data\r\n  destLen  - output data size\r\n  src      - input data\r\n  srcLen   - input data size\r\nOut:\r\n  destLen  - processed output size\r\n  srcLen   - processed input size\r\nReturns:\r\n  SZ_OK                - OK\r\n  SZ_ERROR_DATA        - Data error\r\n  SZ_ERROR_MEM         - Memory allocation arror\r\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n  SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)\r\n*/\r\n\r\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,\r\n  const unsigned char *props, size_t propsSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaUtil/Lzma86Dec.c",
    "content": "/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder\r\n2008-04-07\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"Lzma86Dec.h\"\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../Bra.h\"\r\n#include \"../LzmaDec.h\"\r\n\r\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\r\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)\r\n{\r\n  unsigned i;\r\n  if (srcLen < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n  *unpackSize = 0;\r\n  for (i = 0; i < sizeof(UInt64); i++)\r\n    *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);\r\n  return SZ_OK;\r\n}\r\n\r\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)\r\n{\r\n  SRes res;\r\n  int useFilter;\r\n  SizeT inSizePure;\r\n  ELzmaStatus status;\r\n\r\n  if (*srcLen < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_INPUT_EOF;\r\n\r\n  useFilter = src[0];\r\n\r\n  if (useFilter > 1)\r\n  {\r\n    *destLen = 0;\r\n    return SZ_ERROR_UNSUPPORTED;\r\n  }\r\n\r\n  inSizePure = *srcLen - LZMA86_HEADER_SIZE;\r\n  res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,\r\n      src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);\r\n  *srcLen = inSizePure + LZMA86_HEADER_SIZE;\r\n  if (res != SZ_OK)\r\n    return res;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 x86State;\r\n    x86_Convert_Init(x86State);\r\n    x86_Convert(dest, *destLen, 0, &x86State, 0);\r\n  }\r\n  return SZ_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaUtil/Lzma86Dec.h",
    "content": "/* Lzma86Dec.h -- LZMA + x86 (BCJ) Filter Decoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMA86DEC_H\r\n#define __LZMA86DEC_H\r\n\r\n#include \"../Types.h\"\r\n\r\n/*\r\nLzma86_GetUnpackSize:\r\n  In:\r\n    src      - input data\r\n    srcLen   - input data size\r\n  Out:\r\n    unpackSize - size of uncompressed stream\r\n  Return code:\r\n    SZ_OK               - OK\r\n    SZ_ERROR_INPUT_EOF  - Error in headers\r\n*/\r\n\r\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);\r\n\r\n/*\r\nLzma86_Decode:\r\n  In:\r\n    dest     - output data\r\n    destLen  - output data size\r\n    src      - input data\r\n    srcLen   - input data size\r\n  Out:\r\n    destLen  - processed output size\r\n    srcLen   - processed input size\r\n  Return code:\r\n    SZ_OK           - OK\r\n    SZ_ERROR_DATA  - Data error\r\n    SZ_ERROR_MEM   - Memory allocation error\r\n    SZ_ERROR_UNSUPPORTED - unsupported file\r\n    SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer\r\n*/\r\n\r\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaUtil/Lzma86Enc.c",
    "content": "/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include <string.h>\r\n\r\n#include \"Lzma86Enc.h\"\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../Bra.h\"\r\n#include \"../LzmaEnc.h\"\r\n\r\n#define SZE_OUT_OVERFLOW SZE_DATA_ERROR\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\r\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\r\n\r\nint Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r\n    int level, UInt32 dictSize, int filterMode)\r\n{\r\n  size_t outSize2 = *destLen;\r\n  Byte *filteredStream;\r\n  Bool useFilter;\r\n  int mainResult = SZ_ERROR_OUTPUT_EOF;\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n  props.level = level;\r\n  props.dictSize = dictSize;\r\n  \r\n  *destLen = 0;\r\n  if (outSize2 < LZMA86_HEADER_SIZE)\r\n    return SZ_ERROR_OUTPUT_EOF;\r\n\r\n  {\r\n    int i;\r\n    UInt64 t = srcLen;\r\n    for (i = 0; i < 8; i++, t >>= 8)\r\n      dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;\r\n  }\r\n\r\n  filteredStream = 0;\r\n  useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (srcLen != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(srcLen);\r\n      if (filteredStream == 0)\r\n        return SZ_ERROR_MEM;\r\n      memcpy(filteredStream, src, srcLen);\r\n    }\r\n    {\r\n      UInt32 x86State;\r\n      x86_Convert_Init(x86State);\r\n      x86_Convert(filteredStream, srcLen, 0, &x86State, 1);\r\n    }\r\n  }\r\n\r\n  {\r\n    size_t minSize = 0;\r\n    Bool bestIsFiltered = False;\r\n\r\n    /* passes for SZ_FILTER_AUTO:\r\n        0 - BCJ + LZMA\r\n        1 - LZMA\r\n        2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.\r\n    */\r\n    int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n\r\n    int i;\r\n    for (i = 0; i < numPasses; i++)\r\n    {\r\n      size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;\r\n      size_t outPropsSize = 5;\r\n      SRes curRes;\r\n      Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);\r\n      if (curModeIsFiltered && !bestIsFiltered)\r\n        break;\r\n      if (useFilter && i == 0)\r\n        curModeIsFiltered = True;\r\n      \r\n      curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,\r\n          curModeIsFiltered ? filteredStream : src, srcLen,\r\n          &props, dest + 1, &outPropsSize, 0,\r\n          NULL, &g_Alloc, &g_Alloc);\r\n      \r\n      if (curRes != SZ_ERROR_OUTPUT_EOF)\r\n      {\r\n        if (curRes != SZ_OK)\r\n        {\r\n          mainResult = curRes;\r\n          break;\r\n        }\r\n        if (outSizeProcessed <= minSize || mainResult != SZ_OK)\r\n        {\r\n          minSize = outSizeProcessed;\r\n          bestIsFiltered = curModeIsFiltered;\r\n          mainResult = SZ_OK;\r\n        }\r\n      }\r\n    }\r\n    dest[0] = (bestIsFiltered ? 1 : 0);\r\n    *destLen = LZMA86_HEADER_SIZE + minSize;\r\n  }\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaUtil/Lzma86Enc.h",
    "content": "/* Lzma86Enc.h -- LZMA + x86 (BCJ) Filter Encoder\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#ifndef __LZMA86ENC_H\r\n#define __LZMA86ENC_H\r\n\r\n#include \"../Types.h\"\r\n\r\n/*\r\nIt's an example for LZMA + x86 Filter use.\r\nYou can use .lzma86 extension, if you write that stream to file.\r\n.lzma86 header adds one additional byte to standard .lzma header.\r\n.lzma86 header (14 bytes):\r\n  Offset Size  Description\r\n    0     1    = 0 - no filter,\r\n               = 1 - x86 filter\r\n    1     1    lc, lp and pb in encoded form\r\n    2     4    dictSize (little endian)\r\n    6     8    uncompressed size (little endian)\r\n\r\n\r\nLzma86_Encode\r\n-------------\r\nlevel - compression level: 0 <= level <= 9, the default value for \"level\" is 5.\r\n\r\n\r\ndictSize - The dictionary size in bytes. The maximum value is\r\n        128 MB = (1 << 27) bytes for 32-bit version\r\n          1 GB = (1 << 30) bytes for 64-bit version\r\n     The default value is 16 MB = (1 << 24) bytes, for level = 5.\r\n     It's recommended to use the dictionary that is larger than 4 KB and\r\n     that can be calculated as (1 << N) or (3 << N) sizes.\r\n     For better compression ratio dictSize must be >= inSize.\r\n\r\nfilterMode:\r\n    SZ_FILTER_NO   - no Filter\r\n    SZ_FILTER_YES  - x86 Filter\r\n    SZ_FILTER_AUTO - it tries both alternatives to select best.\r\n              Encoder will use 2 or 3 passes:\r\n              2 passes when FILTER_NO provides better compression.\r\n              3 passes when FILTER_YES provides better compression.\r\n\r\nLzma86Encode allocates Data with MyAlloc functions.\r\nRAM Requirements for compressing:\r\n  RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize\r\n      filterMode     FilterBlockSize\r\n     SZ_FILTER_NO         0\r\n     SZ_FILTER_YES      inSize\r\n     SZ_FILTER_AUTO     inSize\r\n\r\n\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error\r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n*/\r\n\r\nenum ESzFilterMode\r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nSRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\r\n    int level, UInt32 dictSize, int filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaUtil/LzmaUtil.c",
    "content": "/* LzmaUtil.c -- Test application for LZMA compression\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#define _CRT_SECURE_NO_WARNINGS\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"../Alloc.h\"\r\n#include \"../7zFile.h\"\r\n#include \"../7zVersion.h\"\r\n#include \"../LzmaDec.h\"\r\n#include \"../LzmaEnc.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\nconst char *kDataErrorMessage = \"Data error\";\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nvoid PrintHelp(char *buffer)\r\n{\r\n  strcat(buffer, \"\\nLZMA Utility \" MY_VERSION_COPYRIGHT_DATE \"\\n\"\r\n      \"\\nUsage:  lzma <e|d> inputFile outputFile\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\");\r\n}\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  strcat(buffer, \"\\nError: \");\r\n  strcat(buffer, message);\r\n  strcat(buffer, \"\\n\");\r\n  return 1;\r\n}\r\n\r\nint PrintErrorNumber(char *buffer, SRes val)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError code: %x\\n\", (unsigned)val);\r\n  return 1;\r\n}\r\n\r\nint PrintUserError(char *buffer)\r\n{\r\n  return PrintError(buffer, \"Incorrect command\");\r\n}\r\n\r\n#define IN_BUF_SIZE (1 << 16)\r\n#define OUT_BUF_SIZE (1 << 16)\r\n\r\nstatic SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,\r\n    UInt64 unpackSize)\r\n{\r\n  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);\r\n  Byte inBuf[IN_BUF_SIZE];\r\n  Byte outBuf[OUT_BUF_SIZE];\r\n  size_t inPos = 0, inSize = 0, outPos = 0;\r\n  LzmaDec_Init(state);\r\n  for (;;)\r\n  {\r\n    if (inPos == inSize)\r\n    {\r\n      inSize = IN_BUF_SIZE;\r\n      RINOK(inStream->Read(inStream, inBuf, &inSize));\r\n      inPos = 0;\r\n    }\r\n    {\r\n      SRes res;\r\n      SizeT inProcessed = inSize - inPos;\r\n      SizeT outProcessed = OUT_BUF_SIZE - outPos;\r\n      ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\r\n      ELzmaStatus status;\r\n      if (thereIsSize && outProcessed > unpackSize)\r\n      {\r\n        outProcessed = (SizeT)unpackSize;\r\n        finishMode = LZMA_FINISH_END;\r\n      }\r\n      \r\n      res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,\r\n        inBuf + inPos, &inProcessed, finishMode, &status);\r\n      inPos += inProcessed;\r\n      outPos += outProcessed;\r\n      unpackSize -= outProcessed;\r\n      \r\n      if (outStream)\r\n        if (outStream->Write(outStream, outBuf, outPos) != outPos)\r\n          return SZ_ERROR_WRITE;\r\n        \r\n      outPos = 0;\r\n      \r\n      if (res != SZ_OK || thereIsSize && unpackSize == 0)\r\n        return res;\r\n      \r\n      if (inProcessed == 0 && outProcessed == 0)\r\n      {\r\n        if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)\r\n          return SZ_ERROR_DATA;\r\n        return res;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)\r\n{\r\n  UInt64 unpackSize;\r\n  int i;\r\n  SRes res = 0;\r\n\r\n  CLzmaDec state;\r\n\r\n  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */\r\n  unsigned char header[LZMA_PROPS_SIZE + 8];\r\n\r\n  /* Read and parse header */\r\n\r\n  RINOK(SeqInStream_Read(inStream, header, sizeof(header)));\r\n\r\n  unpackSize = 0;\r\n  for (i = 0; i < 8; i++)\r\n    unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);\r\n\r\n  LzmaDec_Construct(&state);\r\n  RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));\r\n  res = Decode2(&state, outStream, inStream, unpackSize);\r\n  LzmaDec_Free(&state, &g_Alloc);\r\n  return res;\r\n}\r\n\r\nstatic SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)\r\n{\r\n  CLzmaEncHandle enc;\r\n  SRes res;\r\n  CLzmaEncProps props;\r\n\r\n  rs = rs;\r\n\r\n  enc = LzmaEnc_Create(&g_Alloc);\r\n  if (enc == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n  LzmaEncProps_Init(&props);\r\n  res = LzmaEnc_SetProps(enc, &props);\r\n\r\n  if (res == SZ_OK)\r\n  {\r\n    Byte header[LZMA_PROPS_SIZE + 8];\r\n    size_t headerSize = LZMA_PROPS_SIZE;\r\n    int i;\r\n\r\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r\n    for (i = 0; i < 8; i++)\r\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r\n    if (outStream->Write(outStream, header, headerSize) != headerSize)\r\n      res = SZ_ERROR_WRITE;\r\n    else\r\n    {\r\n      if (res == SZ_OK)\r\n        res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);\r\n    }\r\n  }\r\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  CFileSeqInStream inStream;\r\n  CFileOutStream outStream;\r\n  char c;\r\n  int res;\r\n  int encodeMode;\r\n  Bool useOutFile = False;\r\n\r\n  FileSeqInStream_CreateVTable(&inStream);\r\n  File_Construct(&inStream.file);\r\n\r\n  FileOutStream_CreateVTable(&outStream);\r\n  File_Construct(&outStream.file);\r\n\r\n  if (numArgs == 1)\r\n  {\r\n    PrintHelp(rs);\r\n    return 0;\r\n  }\r\n\r\n  if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1)\r\n    return PrintUserError(rs);\r\n\r\n  c = args[1][0];\r\n  encodeMode = (c == 'e' || c == 'E');\r\n  if (!encodeMode && c != 'd' && c != 'D')\r\n    return PrintUserError(rs);\r\n\r\n  {\r\n    size_t t4 = sizeof(UInt32);\r\n    size_t t8 = sizeof(UInt64);\r\n    if (t4 != 4 || t8 != 8)\r\n      return PrintError(rs, \"Incorrect UInt32 or UInt64\");\r\n  }\r\n\r\n  if (InFile_Open(&inStream.file, args[2]) != 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 3)\r\n  {\r\n    useOutFile = True;\r\n    if (OutFile_Open(&outStream.file, args[3]) != 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n  else if (encodeMode)\r\n    PrintUserError(rs);\r\n\r\n  if (encodeMode)\r\n  {\r\n    UInt64 fileSize;\r\n    File_GetLength(&inStream.file, &fileSize);\r\n    res = Encode(&outStream.s, &inStream.s, fileSize, rs);\r\n  }\r\n  else\r\n  {\r\n    res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL);\r\n  }\r\n\r\n  if (useOutFile)\r\n    File_Close(&outStream.file);\r\n  File_Close(&inStream.file);\r\n\r\n  if (res != SZ_OK)\r\n  {\r\n    if (res == SZ_ERROR_MEM)\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    else if (res == SZ_ERROR_DATA)\r\n      return PrintError(rs, kDataErrorMessage);\r\n    else if (res == SZ_ERROR_WRITE)\r\n      return PrintError(rs, kCantWriteMessage);\r\n    else if (res == SZ_ERROR_READ)\r\n      return PrintError(rs, kCantReadMessage);\r\n    return PrintErrorNumber(rs, res);\r\n  }\r\n  return 0;\r\n}\r\n\r\nint MY_CDECL main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaUtil/LzmaUtil.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaUtil\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=LzmaUtil - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaUtil.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"LzmaUtil.mak\" CFG=\"LzmaUtil - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"LzmaUtil - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"LzmaUtil - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"LzmaUtil - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\util\\lzmac.exe\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"LzmaUtil - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /GZ /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\util\\lzmac.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"LzmaUtil - Win32 Release\"\r\n# Name \"LzmaUtil - Win32 Debug\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zFile.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zFile.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zStream.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\7zVersion.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\CpuArch.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaUtil.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Types.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaUtil/LzmaUtil.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"LzmaUtil\"=.\\LzmaUtil.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaUtil/makefile",
    "content": "MY_STATIC_LINK=1\r\nPROG = LZMAc.exe\r\n\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n\r\nLIB_OBJS = \\\r\n  $O\\LzmaUtil.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\7zFile.obj \\\r\n  $O\\7zStream.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $(LIB_OBJS) \\\r\n  $(C_OBJS) \\\r\n\r\n!include \"../../CPP/Build.mak\"\r\n\r\n$(LIB_OBJS): $(*B).c\r\n\t$(COMPL_O2)\r\n$(C_OBJS): ../$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/LzmaUtil/makefile.gcc",
    "content": "PROG = lzma\nCC = gcc\nLIB = liblzma.a\nRM = rm -f\nCFLAGS = -c -O2 -Wall\nAR = ar\nRANLIB = ranlib\n\nOBJS = \\\n  Alloc.o \\\n  LzFind.o \\\n  LzmaDec.o \\\n  LzmaEnc.o \\\n  LzmaLib.o \\\n  7zFile.o \\\n  7zStream.o \\\n\nall: $(PROG)\n\n$(PROG): LzmaUtil.o $(LIB)\n\t$(CC) -o $(PROG) $(LDFLAGS) $< $(LIB)\n\nLzmaUtil.o: LzmaUtil.c\n\t$(CC) $(CFLAGS) LzmaUtil.c\n\n$(LIB): $(OBJS)\n\trm -f $@\n\t$(AR) rcu $@ $(OBJS)\n\t$(RANLIB) $@\n\nAlloc.o: ../Alloc.c\n\t$(CC) $(CFLAGS) ../Alloc.c\n\nLzFind.o: ../LzFind.c\n\t$(CC) $(CFLAGS) ../LzFind.c\n\nLzmaDec.o: ../LzmaDec.c\n\t$(CC) $(CFLAGS) ../LzmaDec.c\n\nLzmaEnc.o: ../LzmaEnc.c\n\t$(CC) $(CFLAGS) ../LzmaEnc.c\n\nLzmaLib.o: ../LzmaLib.c\n\t$(CC) $(CFLAGS) ../LzmaLib.c\n\n7zFile.o: ../7zFile.c\n\t$(CC) $(CFLAGS) ../7zFile.c\n\n7zStream.o: ../7zStream.c\n\t$(CC) $(CFLAGS) ../7zStream.c\n\nclean:\n\t-$(RM) $(PROG) *.o *.a\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Threads.c",
    "content": "/* Threads.c -- multithreading library\r\n2008-08-05\r\nIgor Pavlov\r\nPublic domain */\r\n\r\n#include \"Threads.h\"\r\n#include <process.h>\r\n\r\nstatic WRes GetError()\r\n{\r\n  DWORD res = GetLastError();\r\n  return (res) ? (WRes)(res) : 1;\r\n}\r\n\r\nWRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }\r\nWRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }\r\n\r\nstatic WRes MyCloseHandle(HANDLE *h)\r\n{\r\n  if (*h != NULL)\r\n    if (!CloseHandle(*h))\r\n      return GetError();\r\n  *h = NULL;\r\n  return 0;\r\n}\r\n\r\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n{\r\n  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r\n  thread->handle =\r\n    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */\r\n    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);\r\n    /* maybe we must use errno here, but probably GetLastError() is also OK. */\r\n  return HandleToWRes(thread->handle);\r\n}\r\n\r\nWRes WaitObject(HANDLE h)\r\n{\r\n  return (WRes)WaitForSingleObject(h, INFINITE);\r\n}\r\n\r\nWRes Thread_Wait(CThread *thread)\r\n{\r\n  if (thread->handle == NULL)\r\n    return 1;\r\n  return WaitObject(thread->handle);\r\n}\r\n\r\nWRes Thread_Close(CThread *thread)\r\n{\r\n  return MyCloseHandle(&thread->handle);\r\n}\r\n\r\nWRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)\r\n{\r\n  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);\r\n  return HandleToWRes(p->handle);\r\n}\r\n\r\nWRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, TRUE, initialSignaled); }\r\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)\r\n  { return ManualResetEvent_Create(p, 0); }\r\n\r\nWRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)\r\n  { return Event_Create(p, FALSE, initialSignaled); }\r\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)\r\n  { return AutoResetEvent_Create(p, 0); }\r\n\r\nWRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }\r\nWRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }\r\nWRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }\r\nWRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }\r\n\r\n\r\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)\r\n{\r\n  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);\r\n  return HandleToWRes(p->handle);\r\n}\r\n\r\nWRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)\r\n{\r\n  return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));\r\n}\r\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)\r\n{\r\n  return Semaphore_Release(p, (LONG)releaseCount, NULL);\r\n}\r\nWRes Semaphore_Release1(CSemaphore *p)\r\n{\r\n  return Semaphore_ReleaseN(p, 1);\r\n}\r\n\r\nWRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }\r\nWRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }\r\n\r\nWRes CriticalSection_Init(CCriticalSection *p)\r\n{\r\n  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\r\n  __try\r\n  {\r\n    InitializeCriticalSection(p);\r\n    /* InitializeCriticalSectionAndSpinCount(p, 0); */\r\n  }\r\n  __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }\r\n  return 0;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Threads.h",
    "content": "/* Threads.h -- multithreading library\r\n2008-11-22 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_THRESDS_H\r\n#define __7Z_THRESDS_H\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct _CThread\r\n{\r\n  HANDLE handle;\r\n} CThread;\r\n\r\n#define Thread_Construct(thread) (thread)->handle = NULL\r\n#define Thread_WasCreated(thread) ((thread)->handle != NULL)\r\n \r\ntypedef unsigned THREAD_FUNC_RET_TYPE;\r\n#define THREAD_FUNC_CALL_TYPE MY_STD_CALL\r\n#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r\n\r\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);\r\nWRes Thread_Wait(CThread *thread);\r\nWRes Thread_Close(CThread *thread);\r\n\r\ntypedef struct _CEvent\r\n{\r\n  HANDLE handle;\r\n} CEvent;\r\n\r\ntypedef CEvent CAutoResetEvent;\r\ntypedef CEvent CManualResetEvent;\r\n\r\n#define Event_Construct(event) (event)->handle = NULL\r\n#define Event_IsCreated(event) ((event)->handle != NULL)\r\n\r\nWRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);\r\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);\r\nWRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);\r\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);\r\nWRes Event_Set(CEvent *event);\r\nWRes Event_Reset(CEvent *event);\r\nWRes Event_Wait(CEvent *event);\r\nWRes Event_Close(CEvent *event);\r\n\r\n\r\ntypedef struct _CSemaphore\r\n{\r\n  HANDLE handle;\r\n} CSemaphore;\r\n\r\n#define Semaphore_Construct(p) (p)->handle = NULL\r\n\r\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);\r\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\r\nWRes Semaphore_Release1(CSemaphore *p);\r\nWRes Semaphore_Wait(CSemaphore *p);\r\nWRes Semaphore_Close(CSemaphore *p);\r\n\r\n\r\ntypedef CRITICAL_SECTION CCriticalSection;\r\n\r\nWRes CriticalSection_Init(CCriticalSection *p);\r\n#define CriticalSection_Delete(p) DeleteCriticalSection(p)\r\n#define CriticalSection_Enter(p) EnterCriticalSection(p)\r\n#define CriticalSection_Leave(p) LeaveCriticalSection(p)\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/C/Types.h",
    "content": "/* Types.h -- Basic types\r\n2008-11-23 : Igor Pavlov : Public domain */\r\n\r\n#ifndef __7Z_TYPES_H\r\n#define __7Z_TYPES_H\r\n\r\n#include <stddef.h>\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n\r\n#define SZ_OK 0\r\n\r\n#define SZ_ERROR_DATA 1\r\n#define SZ_ERROR_MEM 2\r\n#define SZ_ERROR_CRC 3\r\n#define SZ_ERROR_UNSUPPORTED 4\r\n#define SZ_ERROR_PARAM 5\r\n#define SZ_ERROR_INPUT_EOF 6\r\n#define SZ_ERROR_OUTPUT_EOF 7\r\n#define SZ_ERROR_READ 8\r\n#define SZ_ERROR_WRITE 9\r\n#define SZ_ERROR_PROGRESS 10\r\n#define SZ_ERROR_FAIL 11\r\n#define SZ_ERROR_THREAD 12\r\n\r\n#define SZ_ERROR_ARCHIVE 16\r\n#define SZ_ERROR_NO_ARCHIVE 17\r\n\r\ntypedef int SRes;\r\n\r\n#ifdef _WIN32\r\ntypedef DWORD WRes;\r\n#else\r\ntypedef int WRes;\r\n#endif\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r\n#endif\r\n\r\ntypedef unsigned char Byte;\r\ntypedef short Int16;\r\ntypedef unsigned short UInt16;\r\n\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\ntypedef long Int32;\r\ntypedef unsigned long UInt32;\r\n#else\r\ntypedef int Int32;\r\ntypedef unsigned int UInt32;\r\n#endif\r\n\r\n#ifdef _SZ_NO_INT_64\r\n\r\n/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r\n   NOTES: Some code will work incorrectly in that case! */\r\n\r\ntypedef long Int64;\r\ntypedef unsigned long UInt64;\r\n\r\n#else\r\n\r\n#if defined(_MSC_VER) || defined(__BORLANDC__)\r\ntypedef __int64 Int64;\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef long long int Int64;\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\r\ntypedef UInt32 SizeT;\r\n#else\r\ntypedef size_t SizeT;\r\n#endif\r\n\r\ntypedef int Bool;\r\n#define True 1\r\n#define False 0\r\n\r\n\r\n#ifdef _MSC_VER\r\n\r\n#if _MSC_VER >= 1300\r\n#define MY_NO_INLINE __declspec(noinline)\r\n#else\r\n#define MY_NO_INLINE\r\n#endif\r\n\r\n#define MY_CDECL __cdecl\r\n#define MY_STD_CALL __stdcall\r\n#define MY_FAST_CALL MY_NO_INLINE __fastcall\r\n\r\n#else\r\n\r\n#define MY_CDECL\r\n#define MY_STD_CALL\r\n#define MY_FAST_CALL\r\n\r\n#endif\r\n\r\n\r\n/* The following interfaces use first parameter as pointer to structure */\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) < input(*size)) is allowed */\r\n} ISeqInStream;\r\n\r\n/* it can return SZ_ERROR_INPUT_EOF */\r\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r\n\r\ntypedef struct\r\n{\r\n  size_t (*Write)(void *p, const void *buf, size_t size);\r\n    /* Returns: result - the number of actually written bytes.\r\n       (result < size) means error */\r\n} ISeqOutStream;\r\n\r\ntypedef enum\r\n{\r\n  SZ_SEEK_SET = 0,\r\n  SZ_SEEK_CUR = 1,\r\n  SZ_SEEK_END = 2\r\n} ESzSeek;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ISeekInStream;\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Look)(void *p, void **buf, size_t *size);\r\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r\n       (output(*size) > input(*size)) is not allowed\r\n       (output(*size) < input(*size)) is allowed */\r\n  SRes (*Skip)(void *p, size_t offset);\r\n    /* offset must be <= output(*size) of Look */\r\n\r\n  SRes (*Read)(void *p, void *buf, size_t *size);\r\n    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r\n} ILookInStream;\r\n\r\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r\n\r\n/* reads via ILookInStream::Read */\r\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r\n\r\n#define LookToRead_BUF_SIZE (1 << 14)\r\n\r\ntypedef struct\r\n{\r\n  ILookInStream s;\r\n  ISeekInStream *realStream;\r\n  size_t pos;\r\n  size_t size;\r\n  Byte buf[LookToRead_BUF_SIZE];\r\n} CLookToRead;\r\n\r\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r\nvoid LookToRead_Init(CLookToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToLook;\r\n\r\nvoid SecToLook_CreateVTable(CSecToLook *p);\r\n\r\ntypedef struct\r\n{\r\n  ISeqInStream s;\r\n  ILookInStream *realStream;\r\n} CSecToRead;\r\n\r\nvoid SecToRead_CreateVTable(CSecToRead *p);\r\n\r\ntypedef struct\r\n{\r\n  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r\n    /* Returns: result. (result != SZ_OK) means break.\r\n       Value (UInt64)(Int64)-1 for size means unknown value. */\r\n} ICompressProgress;\r\n\r\ntypedef struct\r\n{\r\n  void *(*Alloc)(void *p, size_t size);\r\n  void (*Free)(void *p, void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\n#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r\n#define IAlloc_Free(p, a) (p)->Free((p), a)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zCompressionMode.cpp",
    "content": "// CompressionMethod.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zCompressionMode.h",
    "content": "// 7zCompressionMode.h\r\n\r\n#ifndef __7Z_COMPRESSION_MODE_H\r\n#define __7Z_COMPRESSION_MODE_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CMethodFull: public CMethod\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBind\r\n{\r\n  UInt32 InCoder;\r\n  UInt32 InStream;\r\n  UInt32 OutCoder;\r\n  UInt32 OutStream;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  CObjectVector<CMethodFull> Methods;\r\n  CRecordVector<CBind> Binds;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }\r\n  CCompressionMethodMode(): PasswordIsDefined(false)\r\n      #ifdef COMPRESS_MT\r\n      , NumThreads(1)\r\n      #endif\r\n  {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zDecode.cpp",
    "content": "// 7zDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/LockedStream.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertFolderItemInfoToBindInfo(const CFolder &folder,\r\n    CBindInfoEx &bindInfo)\r\n{\r\n  bindInfo.Clear();\r\n  int i;\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    NCoderMixer::CBindPair bindPair;\r\n    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;\r\n    bindInfo.BindPairs.Add(bindPair);\r\n  }\r\n  UInt32 outStreamIndex = 0;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    const CCoderInfo &coderInfo = folder.Coders[i];\r\n    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;\r\n    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    bindInfo.Coders.Add(coderStreamsInfo);\r\n    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);\r\n    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)\r\n      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)\r\n        bindInfo.OutStreams.Add(outStreamIndex);\r\n  }\r\n  for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);\r\n}\r\n\r\nstatic bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1,\r\n    const NCoderMixer::CCoderStreamsInfo &a2)\r\n{\r\n  return (a1.NumInStreams == a2.NumInStreams) &&\r\n    (a1.NumOutStreams == a2.NumOutStreams);\r\n}\r\n\r\nstatic bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)\r\n{\r\n  return (a1.InIndex == a2.InIndex) &&\r\n    (a1.OutIndex == a2.OutIndex);\r\n}\r\n\r\nstatic bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)\r\n{\r\n  if (a1.Coders.Size() != a2.Coders.Size())\r\n    return false;\r\n  int i;\r\n  for (i = 0; i < a1.Coders.Size(); i++)\r\n    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))\r\n      return false;\r\n  if (a1.BindPairs.Size() != a2.BindPairs.Size())\r\n    return false;\r\n  for (i = 0; i < a1.BindPairs.Size(); i++)\r\n    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))\r\n      return false;\r\n  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)\r\n    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])\r\n      return false;\r\n  if (a1.InStreams.Size() != a2.InStreams.Size())\r\n    return false;\r\n  if (a1.OutStreams.Size() != a2.OutStreams.Size())\r\n    return false;\r\n  return true;\r\n}\r\n\r\nCDecoder::CDecoder(bool multiThread)\r\n{\r\n  #ifndef _ST_MODE\r\n  multiThread = true;\r\n  #endif\r\n  _multiThread = multiThread;\r\n  _bindInfoExPrevIsDefined = false;\r\n}\r\n\r\nHRESULT CDecoder::Decode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    UInt64 startPos,\r\n    const UInt64 *packSizes,\r\n    const CFolder &folderInfo,\r\n    ISequentialOutStream *outStream,\r\n    ICompressProgressInfo *compressProgress\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    #ifdef COMPRESS_MT\r\n    , bool mtMode, UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  if (!folderInfo.CheckStructure())\r\n    return E_NOTIMPL;\r\n  #ifndef _NO_CRYPTO\r\n  passwordIsDefined = false;\r\n  #endif\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;\r\n  \r\n  CLockedInStream lockedInStream;\r\n  lockedInStream.Init(inStream);\r\n  \r\n  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)\r\n  {\r\n    CLockedSequentialInStreamImp *lockedStreamImpSpec = new\r\n        CLockedSequentialInStreamImp;\r\n    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;\r\n    lockedStreamImpSpec->Init(&lockedInStream, startPos);\r\n    startPos += packSizes[j];\r\n    \r\n    CLimitedSequentialInStream *streamSpec = new\r\n        CLimitedSequentialInStream;\r\n    CMyComPtr<ISequentialInStream> inStream = streamSpec;\r\n    streamSpec->SetStream(lockedStreamImp);\r\n    streamSpec->Init(packSizes[j]);\r\n    inStreams.Add(inStream);\r\n  }\r\n  \r\n  int numCoders = folderInfo.Coders.Size();\r\n  \r\n  CBindInfoEx bindInfo;\r\n  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);\r\n  bool createNewCoders;\r\n  if (!_bindInfoExPrevIsDefined)\r\n    createNewCoders = true;\r\n  else\r\n    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);\r\n  if (createNewCoders)\r\n  {\r\n    int i;\r\n    _decoders.Clear();\r\n    // _decoders2.Clear();\r\n    \r\n    _mixerCoder.Release();\r\n\r\n    if (_multiThread)\r\n    {\r\n      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;\r\n      _mixerCoder = _mixerCoderMTSpec;\r\n      _mixerCoderCommon = _mixerCoderMTSpec;\r\n    }\r\n    else\r\n    {\r\n      #ifdef _ST_MODE\r\n      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;\r\n      _mixerCoder = _mixerCoderSTSpec;\r\n      _mixerCoderCommon = _mixerCoderSTSpec;\r\n      #endif\r\n    }\r\n    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));\r\n    \r\n    for (i = 0; i < numCoders; i++)\r\n    {\r\n      const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n\r\n  \r\n      CMyComPtr<ICompressCoder> decoder;\r\n      CMyComPtr<ICompressCoder2> decoder2;\r\n      RINOK(CreateCoder(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          coderInfo.MethodID, decoder, decoder2, false));\r\n      CMyComPtr<IUnknown> decoderUnknown;\r\n      if (coderInfo.IsSimpleCoder())\r\n      {\r\n        if (decoder == 0)\r\n          return E_NOTIMPL;\r\n\r\n        decoderUnknown = (IUnknown *)decoder;\r\n        \r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder(decoder);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder(decoder, false);\r\n        #endif\r\n      }\r\n      else\r\n      {\r\n        if (decoder2 == 0)\r\n          return E_NOTIMPL;\r\n        decoderUnknown = (IUnknown *)decoder2;\r\n        if (_multiThread)\r\n          _mixerCoderMTSpec->AddCoder2(decoder2);\r\n        #ifdef _ST_MODE\r\n        else\r\n          _mixerCoderSTSpec->AddCoder2(decoder2, false);\r\n        #endif\r\n      }\r\n      _decoders.Add(decoderUnknown);\r\n      #ifdef EXTERNAL_CODECS\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n      }\r\n      #endif\r\n    }\r\n    _bindInfoExPrev = bindInfo;\r\n    _bindInfoExPrevIsDefined = true;\r\n  }\r\n  int i;\r\n  _mixerCoderCommon->ReInit();\r\n  \r\n  UInt32 packStreamIndex = 0, unpackStreamIndex = 0;\r\n  UInt32 coderIndex = 0;\r\n  // UInt32 coder2Index = 0;\r\n  \r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];\r\n    \r\n    {\r\n      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n      if (setDecoderProperties)\r\n      {\r\n        const CByteBuffer &props = coderInfo.Props;\r\n        size_t size = props.GetCapacity();\r\n        if (size > 0xFFFFFFFF)\r\n          return E_NOTIMPL;\r\n        if (size > 0)\r\n        {\r\n          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)props, (UInt32)size));\r\n        }\r\n      }\r\n    }\r\n\r\n    #ifdef COMPRESS_MT\r\n    if (mtMode)\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(numThreads));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    {\r\n      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n      if (cryptoSetPassword)\r\n      {\r\n        if (getTextPassword == 0)\r\n          return E_FAIL;\r\n        CMyComBSTR passwordBSTR;\r\n        RINOK(getTextPassword->CryptoGetTextPassword(&passwordBSTR));\r\n        CByteBuffer buffer;\r\n        passwordIsDefined = true;\r\n        const UString password(passwordBSTR);\r\n        const UInt32 sizeInBytes = password.Length() * 2;\r\n        buffer.SetCapacity(sizeInBytes);\r\n        for (int i = 0; i < password.Length(); i++)\r\n        {\r\n          wchar_t c = password[i];\r\n          ((Byte *)buffer)[i * 2] = (Byte)c;\r\n          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n        }\r\n        RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    coderIndex++;\r\n    \r\n    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;\r\n    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;\r\n    CRecordVector<const UInt64 *> packSizesPointers;\r\n    CRecordVector<const UInt64 *> unpackSizesPointers;\r\n    packSizesPointers.Reserve(numInStreams);\r\n    unpackSizesPointers.Reserve(numOutStreams);\r\n    UInt32 j;\r\n    for (j = 0; j < numOutStreams; j++, unpackStreamIndex++)\r\n      unpackSizesPointers.Add(&folderInfo.UnpackSizes[unpackStreamIndex]);\r\n    \r\n    for (j = 0; j < numInStreams; j++, packStreamIndex++)\r\n    {\r\n      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);\r\n      if (bindPairIndex >= 0)\r\n        packSizesPointers.Add(\r\n        &folderInfo.UnpackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);\r\n      else\r\n      {\r\n        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);\r\n        if (index < 0)\r\n          return E_FAIL;\r\n        packSizesPointers.Add(&packSizes[index]);\r\n      }\r\n    }\r\n    \r\n    _mixerCoderCommon->SetCoderInfo(i,\r\n        &packSizesPointers.Front(),\r\n        &unpackSizesPointers.Front());\r\n  }\r\n  UInt32 mainCoder, temp;\r\n  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);\r\n\r\n  if (_multiThread)\r\n    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);\r\n  /*\r\n  else\r\n    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;\r\n  */\r\n  \r\n  if (numCoders == 0)\r\n    return 0;\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  inStreamPointers.Reserve(inStreams.Size());\r\n  for (i = 0; i < inStreams.Size(); i++)\r\n    inStreamPointers.Add(inStreams[i]);\r\n  ISequentialOutStream *outStreamPointer = outStream;\r\n  return _mixerCoder->Code(&inStreamPointers.Front(), NULL,\r\n    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zDecode.h",
    "content": "// 7zDecode.h\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"7zItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CBindInfoEx: public NCoderMixer::CBindInfo\r\n{\r\n  CRecordVector<CMethodId> CoderMethodIDs;\r\n  void Clear()\r\n  {\r\n    CBindInfo::Clear();\r\n    CoderMethodIDs.Clear();\r\n  }\r\n};\r\n\r\nclass CDecoder\r\n{\r\n  bool _bindInfoExPrevIsDefined;\r\n  CBindInfoEx _bindInfoExPrev;\r\n  \r\n  bool _multiThread;\r\n  #ifdef _ST_MODE\r\n  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;\r\n  #endif\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;\r\n  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;\r\n  \r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n  CObjectVector<CMyComPtr<IUnknown> > _decoders;\r\n  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;\r\npublic:\r\n  CDecoder(bool multiThread);\r\n  HRESULT Decode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      IInStream *inStream,\r\n      UInt64 startPos,\r\n      const UInt64 *packSizes,\r\n      const CFolder &folder,\r\n      ISequentialOutStream *outStream,\r\n      ICompressProgressInfo *compressProgress\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , bool mtMode, UInt32 numThreads\r\n      #endif\r\n      );\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zEncode.cpp",
    "content": "// Encode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zSpecStream.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/InOutTempBuffer.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/FilterCoder.h\"\r\n\r\nstatic const UInt64 k_AES = 0x06F10701;\r\nstatic const UInt64 k_BCJ  = 0x03030103;\r\nstatic const UInt64 k_BCJ2 = 0x0303011B;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,\r\n    const CRecordVector<CMethodId> decompressionMethods,\r\n    CFolder &folder)\r\n{\r\n  folder.Coders.Clear();\r\n  // bindInfo.CoderMethodIDs.Clear();\r\n  // folder.OutStreams.Clear();\r\n  folder.PackStreams.Clear();\r\n  folder.BindPairs.Clear();\r\n  int i;\r\n  for (i = 0; i < bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    CBindPair bindPair;\r\n    bindPair.InIndex = bindInfo.BindPairs[i].InIndex;\r\n    bindPair.OutIndex = bindInfo.BindPairs[i].OutIndex;\r\n    folder.BindPairs.Add(bindPair);\r\n  }\r\n  for (i = 0; i < bindInfo.Coders.Size(); i++)\r\n  {\r\n    CCoderInfo coderInfo;\r\n    const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];\r\n    coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;\r\n    coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;\r\n    coderInfo.MethodID = decompressionMethods[i];\r\n    folder.Coders.Add(coderInfo);\r\n  }\r\n  for (i = 0; i < bindInfo.InStreams.Size(); i++)\r\n    folder.PackStreams.Add(bindInfo.InStreams[i]);\r\n}\r\n\r\nHRESULT CEncoder::CreateMixerCoder(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const UInt64 *inSizeForReduce)\r\n{\r\n  _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;\r\n  _mixerCoder = _mixerCoderSpec;\r\n  RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));\r\n  for (int i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _codersInfo.Add(CCoderInfo());\r\n    CCoderInfo &encodingInfo = _codersInfo.Back();\r\n    encodingInfo.MethodID = methodFull.Id;\r\n    CMyComPtr<ICompressCoder> encoder;\r\n    CMyComPtr<ICompressCoder2> encoder2;\r\n    \r\n\r\n    RINOK(CreateCoder(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        methodFull.Id, encoder, encoder2, true));\r\n\r\n    if (!encoder && !encoder2)\r\n      return E_FAIL;\r\n\r\n    CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;\r\n   \r\n    #ifdef COMPRESS_MT\r\n    {\r\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\r\n      encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\r\n      if (setCoderMt)\r\n      {\r\n        RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));\r\n      }\r\n    }\r\n    #endif\r\n        \r\n\r\n    RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon));\r\n\r\n    /*\r\n    CMyComPtr<ICryptoResetSalt> resetSalt;\r\n    encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);\r\n    if (resetSalt != NULL)\r\n    {\r\n      resetSalt->ResetSalt();\r\n    }\r\n    */\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n    encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n    if (setCompressCodecsInfo)\r\n    {\r\n      RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\r\n    }\r\n    #endif\r\n    \r\n    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\r\n    encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\r\n\r\n    if (cryptoSetPassword)\r\n    {\r\n      CByteBuffer buffer;\r\n      const UInt32 sizeInBytes = _options.Password.Length() * 2;\r\n      buffer.SetCapacity(sizeInBytes);\r\n      for (int i = 0; i < _options.Password.Length(); i++)\r\n      {\r\n        wchar_t c = _options.Password[i];\r\n        ((Byte *)buffer)[i * 2] = (Byte)c;\r\n        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\r\n      }\r\n      RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\r\n    }\r\n\r\n    if (encoder)\r\n      _mixerCoderSpec->AddCoder(encoder);\r\n    else\r\n      _mixerCoderSpec->AddCoder2(encoder2);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Encode(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    ISequentialInStream *inStream,\r\n    const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n    CFolder &folderItem,\r\n    ISequentialOutStream *outStream,\r\n    CRecordVector<UInt64> &packSizes,\r\n    ICompressProgressInfo *compressProgress)\r\n{\r\n  RINOK(EncoderConstr());\r\n\r\n  if (_mixerCoderSpec == NULL)\r\n  {\r\n    RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));\r\n  }\r\n  _mixerCoderSpec->ReInit();\r\n  // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);\r\n\r\n  CObjectVector<CInOutTempBuffer> inOutTempBuffers;\r\n  CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;\r\n  CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;\r\n  int numMethods = _bindInfo.Coders.Size();\r\n  int i;\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    inOutTempBuffers.Add(CInOutTempBuffer());\r\n    inOutTempBuffers.Back().Create();\r\n    inOutTempBuffers.Back().InitWriting();\r\n  }\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CSequentialOutTempBufferImp *tempBufferSpec =\r\n        new CSequentialOutTempBufferImp;\r\n    CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;\r\n    tempBufferSpec->Init(&inOutTempBuffers[i - 1]);\r\n    tempBuffers.Add(tempBuffer);\r\n    tempBufferSpecs.Add(tempBufferSpec);\r\n  }\r\n\r\n  for (i = 0; i < numMethods; i++)\r\n    _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    return E_FAIL;\r\n  UInt32 mainCoderIndex, mainStreamIndex;\r\n  _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);\r\n  \r\n  if (inStreamSize != NULL)\r\n  {\r\n    CRecordVector<const UInt64 *> sizePointers;\r\n    for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)\r\n      if (i == mainStreamIndex)\r\n        sizePointers.Add(inStreamSize);\r\n      else\r\n        sizePointers.Add(NULL);\r\n    _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);\r\n  }\r\n\r\n  \r\n  // UInt64 outStreamStartPos;\r\n  // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));\r\n  \r\n  CSequentialInStreamSizeCount2 *inStreamSizeCountSpec =\r\n      new CSequentialInStreamSizeCount2;\r\n  CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;\r\n  CSequentialOutStreamSizeCount *outStreamSizeCountSpec =\r\n      new CSequentialOutStreamSizeCount;\r\n  CMyComPtr<ISequentialOutStream> outStreamSizeCount = outStreamSizeCountSpec;\r\n\r\n  inStreamSizeCountSpec->Init(inStream);\r\n  outStreamSizeCountSpec->SetStream(outStream);\r\n  outStreamSizeCountSpec->Init();\r\n\r\n  CRecordVector<ISequentialInStream *> inStreamPointers;\r\n  CRecordVector<ISequentialOutStream *> outStreamPointers;\r\n  inStreamPointers.Add(inStreamSizeCount);\r\n  outStreamPointers.Add(outStreamSizeCount);\r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n    outStreamPointers.Add(tempBuffers[i - 1]);\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    CCoderInfo &encodingInfo = _codersInfo[i];\r\n    \r\n    CMyComPtr<ICryptoResetInitVector> resetInitVector;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);\r\n    if (resetInitVector != NULL)\r\n    {\r\n      resetInitVector->ResetInitVector();\r\n    }\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n    if (writeCoderProperties != NULL)\r\n    {\r\n      CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n      outStreamSpec->Init();\r\n      writeCoderProperties->WriteCoderProperties(outStream);\r\n      size_t size = outStreamSpec->GetSize();\r\n      encodingInfo.Props.SetCapacity(size);\r\n      memmove(encodingInfo.Props, outStreamSpec->GetBuffer(), size);\r\n    }\r\n  }\r\n\r\n  UInt32 progressIndex = mainCoderIndex;\r\n\r\n  for (i = 0; i < _codersInfo.Size(); i++)\r\n  {\r\n    const CCoderInfo &e = _codersInfo[i];\r\n    if ((e.MethodID == k_BCJ || e.MethodID == k_BCJ2) && i + 1 < _codersInfo.Size())\r\n      progressIndex = i + 1;\r\n  }\r\n\r\n  _mixerCoderSpec->SetProgressCoderIndex(progressIndex);\r\n  \r\n  RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,\r\n    &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));\r\n  \r\n  ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods,\r\n      folderItem);\r\n  \r\n  packSizes.Add(outStreamSizeCountSpec->GetSize());\r\n  \r\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];\r\n    inOutTempBuffer.FlushWrite();\r\n    inOutTempBuffer.InitReading();\r\n    inOutTempBuffer.WriteToStream(outStream);\r\n    packSizes.Add(inOutTempBuffer.GetDataSize());\r\n  }\r\n  \r\n  for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)\r\n  {\r\n    int binder = _bindInfo.FindBinderForInStream(\r\n        _bindReverseConverter->DestOutToSrcInMap[i]);\r\n    UInt64 streamSize;\r\n    if (binder < 0)\r\n      streamSize = inStreamSizeCountSpec->GetSize();\r\n    else\r\n      streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);\r\n    folderItem.UnpackSizes.Add(streamSize);\r\n  }\r\n  for (i = numMethods - 1; i >= 0; i--)\r\n    folderItem.Coders[numMethods - 1 - i].Props = _codersInfo[i].Props;\r\n  return S_OK;\r\n}\r\n\r\n\r\nCEncoder::CEncoder(const CCompressionMethodMode &options):\r\n  _bindReverseConverter(0),\r\n  _constructed(false)\r\n{\r\n  if (options.IsEmpty())\r\n    throw 1;\r\n\r\n  _options = options;\r\n  _mixerCoderSpec = NULL;\r\n}\r\n\r\nHRESULT CEncoder::EncoderConstr()\r\n{\r\n  if (_constructed)\r\n    return S_OK;\r\n  if (_options.Methods.IsEmpty())\r\n  {\r\n    // it has only password method;\r\n    if (!_options.PasswordIsDefined)\r\n      throw 1;\r\n    if (!_options.Binds.IsEmpty())\r\n      throw 1;\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    CMethodFull method;\r\n    \r\n    method.NumInStreams = 1;\r\n    method.NumOutStreams = 1;\r\n    coderStreamsInfo.NumInStreams = 1;\r\n    coderStreamsInfo.NumOutStreams = 1;\r\n    method.Id = k_AES;\r\n    \r\n    _options.Methods.Add(method);\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  \r\n    _bindInfo.InStreams.Add(0);\r\n    _bindInfo.OutStreams.Add(0);\r\n  }\r\n  else\r\n  {\r\n\r\n  UInt32 numInStreams = 0, numOutStreams = 0;\r\n  int i;\r\n  for (i = 0; i < _options.Methods.Size(); i++)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n    coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;\r\n    coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;\r\n    if (_options.Binds.IsEmpty())\r\n    {\r\n      if (i < _options.Methods.Size() - 1)\r\n      {\r\n        NCoderMixer::CBindPair bindPair;\r\n        bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;\r\n        bindPair.OutIndex = numOutStreams;\r\n        _bindInfo.BindPairs.Add(bindPair);\r\n      }\r\n      else\r\n        _bindInfo.OutStreams.Insert(0, numOutStreams);\r\n      for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)\r\n        _bindInfo.OutStreams.Add(numOutStreams + j);\r\n    }\r\n    \r\n    numInStreams += coderStreamsInfo.NumInStreams;\r\n    numOutStreams += coderStreamsInfo.NumOutStreams;\r\n\r\n    _bindInfo.Coders.Add(coderStreamsInfo);\r\n  }\r\n\r\n  if (!_options.Binds.IsEmpty())\r\n  {\r\n    for (i = 0; i < _options.Binds.Size(); i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      const CBind &bind = _options.Binds[i];\r\n      bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;\r\n      bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    for (i = 0; i < (int)numOutStreams; i++)\r\n      if (_bindInfo.FindBinderForOutStream(i) == -1)\r\n        _bindInfo.OutStreams.Add(i);\r\n  }\r\n\r\n  for (i = 0; i < (int)numInStreams; i++)\r\n    if (_bindInfo.FindBinderForInStream(i) == -1)\r\n      _bindInfo.InStreams.Add(i);\r\n\r\n  if (_bindInfo.InStreams.IsEmpty())\r\n    throw 1; // this is error\r\n\r\n  // Make main stream first in list\r\n  int inIndex = _bindInfo.InStreams[0];\r\n  for (;;)\r\n  {\r\n    UInt32 coderIndex, coderStreamIndex;\r\n    _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);\r\n    UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);\r\n    int binder = _bindInfo.FindBinderForOutStream(outIndex);\r\n    if (binder >= 0)\r\n    {\r\n      inIndex = _bindInfo.BindPairs[binder].InIndex;\r\n      continue;\r\n    }\r\n    for (i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n      if (_bindInfo.OutStreams[i] == outIndex)\r\n      {\r\n        _bindInfo.OutStreams.Delete(i);\r\n        _bindInfo.OutStreams.Insert(0, outIndex);\r\n        break;\r\n      }\r\n    break;\r\n  }\r\n\r\n  if (_options.PasswordIsDefined)\r\n  {\r\n    int numCryptoStreams = _bindInfo.OutStreams.Size();\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CBindPair bindPair;\r\n      bindPair.InIndex = numInStreams + i;\r\n      bindPair.OutIndex = _bindInfo.OutStreams[i];\r\n      _bindInfo.BindPairs.Add(bindPair);\r\n    }\r\n    _bindInfo.OutStreams.Clear();\r\n\r\n    /*\r\n    if (numCryptoStreams == 0)\r\n      numCryptoStreams = 1;\r\n    */\r\n\r\n    for (i = 0; i < numCryptoStreams; i++)\r\n    {\r\n      NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\r\n      CMethodFull method;\r\n      method.NumInStreams = 1;\r\n      method.NumOutStreams = 1;\r\n      coderStreamsInfo.NumInStreams = method.NumOutStreams;\r\n      coderStreamsInfo.NumOutStreams = method.NumInStreams;\r\n      method.Id = k_AES;\r\n\r\n      _options.Methods.Add(method);\r\n      _bindInfo.Coders.Add(coderStreamsInfo);\r\n      _bindInfo.OutStreams.Add(numOutStreams + i);\r\n    }\r\n  }\r\n\r\n  }\r\n\r\n  for (int i = _options.Methods.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CMethodFull &methodFull = _options.Methods[i];\r\n    _decompressionMethods.Add(methodFull.Id);\r\n  }\r\n\r\n  _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);\r\n  _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);\r\n  _constructed = true;\r\n  return S_OK;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  delete _bindReverseConverter;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zEncode.h",
    "content": "// 7zEncode.h\r\n\r\n#ifndef __7Z_ENCODE_H\r\n#define __7Z_ENCODE_H\r\n\r\n// #include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../Common/CoderMixer2.h\"\r\n#include \"../Common/CoderMixer2MT.h\"\r\n#ifdef _ST_MODE\r\n#include \"../Common/CoderMixer2ST.h\"\r\n#endif\r\n#include \"7zItem.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CEncoder\r\n{\r\n  NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;\r\n  CMyComPtr<ICompressCoder2> _mixerCoder;\r\n\r\n  CObjectVector<CCoderInfo> _codersInfo;\r\n\r\n  CCompressionMethodMode _options;\r\n  NCoderMixer::CBindInfo _bindInfo;\r\n  NCoderMixer::CBindInfo _decompressBindInfo;\r\n  NCoderMixer::CBindReverseConverter *_bindReverseConverter;\r\n  CRecordVector<CMethodId> _decompressionMethods;\r\n\r\n  HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const UInt64 *inSizeForReduce);\r\n\r\n  bool _constructed;\r\npublic:\r\n  CEncoder(const CCompressionMethodMode &options);\r\n  ~CEncoder();\r\n  HRESULT EncoderConstr();\r\n  HRESULT Encode(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      ISequentialInStream *inStream,\r\n      const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\r\n      CFolder &folderItem,\r\n      ISequentialOutStream *outStream,\r\n      CRecordVector<UInt64> &packSizes,\r\n      ICompressProgressInfo *compressProgress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zExtract.cpp",
    "content": "// 7zExtract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zFolderOutStream.h\"\r\n#include \"7zDecode.h\"\r\n// #include \"7z1Decode.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/LimitedStreams.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CExtractFolderInfo\r\n{\r\n  #ifdef _7Z_VOL\r\n  int VolumeIndex;\r\n  #endif\r\n  CNum FileIndex;\r\n  CNum FolderIndex;\r\n  CBoolVector ExtractStatuses;\r\n  UInt64 UnpackSize;\r\n  CExtractFolderInfo(\r\n    #ifdef _7Z_VOL\r\n    int volumeIndex,\r\n    #endif\r\n    CNum fileIndex, CNum folderIndex):\r\n    #ifdef _7Z_VOL\r\n    VolumeIndex(volumeIndex),\r\n    #endif\r\n    FileIndex(fileIndex),\r\n    FolderIndex(folderIndex),\r\n    UnpackSize(0)\r\n  {\r\n    if (fileIndex != kNumNoIndex)\r\n    {\r\n      ExtractStatuses.Reserve(1);\r\n      ExtractStatuses.Add(true);\r\n    }\r\n  };\r\n};\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool testMode = (testModeSpec != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;\r\n  UInt64 importantTotalUnpacked = 0;\r\n\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (allFilesMode)\r\n    numItems =\r\n    #ifdef _7Z_VOL\r\n    _refs.Size();\r\n    #else\r\n    _db.Files.Size();\r\n    #endif\r\n\r\n  if(numItems == 0)\r\n    return S_OK;\r\n\r\n  /*\r\n  if(_volumes.Size() != 1)\r\n    return E_FAIL;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_db = volume.Database;\r\n  IInStream *_inStream = volume.Stream;\r\n  */\r\n  \r\n  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;\r\n  for(UInt32 ii = 0; ii < numItems; ii++)\r\n  {\r\n    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];\r\n    UInt32 ref2Index = allFilesMode ? ii : indices[ii];\r\n    // const CRef2 &ref2 = _refs[ref2Index];\r\n\r\n    // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)\r\n    {\r\n      #ifdef _7Z_VOL\r\n      // const CRef &ref = ref2.Refs[ri];\r\n      const CRef &ref = _refs[ref2Index];\r\n\r\n      int volumeIndex = ref.VolumeIndex;\r\n      const CVolume &volume = _volumes[volumeIndex];\r\n      const CArchiveDatabaseEx &db = volume.Database;\r\n      UInt32 fileIndex = ref.ItemIndex;\r\n      #else\r\n      const CArchiveDatabaseEx &db = _db;\r\n      UInt32 fileIndex = ref2Index;\r\n      #endif\r\n\r\n      CNum folderIndex = db.FileIndexToFolderIndexMap[fileIndex];\r\n      if (folderIndex == kNumNoIndex)\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex,\r\n            #endif\r\n            fileIndex, kNumNoIndex));\r\n        continue;\r\n      }\r\n      if (extractFolderInfoVector.IsEmpty() ||\r\n        folderIndex != extractFolderInfoVector.Back().FolderIndex\r\n        #ifdef _7Z_VOL\r\n        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex\r\n        #endif\r\n        )\r\n      {\r\n        extractFolderInfoVector.Add(CExtractFolderInfo(\r\n            #ifdef _7Z_VOL\r\n            volumeIndex,\r\n            #endif\r\n            kNumNoIndex, folderIndex));\r\n        const CFolder &folderInfo = db.Folders[folderIndex];\r\n        UInt64 unpackSize = folderInfo.GetUnpackSize();\r\n        importantTotalUnpacked += unpackSize;\r\n        extractFolderInfoVector.Back().UnpackSize = unpackSize;\r\n      }\r\n      \r\n      CExtractFolderInfo &efi = extractFolderInfoVector.Back();\r\n      \r\n      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];\r\n      CNum startIndex = db.FolderStartFileIndex[folderIndex];\r\n      for (CNum index = efi.ExtractStatuses.Size();\r\n          index <= fileIndex - startIndex; index++)\r\n      {\r\n        // UInt64 unpackSize = _db.Files[startIndex + index].UnpackSize;\r\n        // Count partial_folder_size\r\n        // efi.UnpackSize += unpackSize;\r\n        // importantTotalUnpacked += unpackSize;\r\n        efi.ExtractStatuses.Add(index == fileIndex - startIndex);\r\n      }\r\n    }\r\n  }\r\n\r\n  extractCallback->SetTotal(importantTotalUnpacked);\r\n\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  // CDecoder1 decoder;\r\n\r\n  UInt64 currentTotalPacked = 0;\r\n  UInt64 currentTotalUnpacked = 0;\r\n  UInt64 totalFolderUnpacked;\r\n  UInt64 totalFolderPacked;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for(int i = 0; i < extractFolderInfoVector.Size(); i++,\r\n      currentTotalUnpacked += totalFolderUnpacked,\r\n      currentTotalPacked += totalFolderPacked)\r\n  {\r\n    lps->OutSize = currentTotalUnpacked;\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    const CExtractFolderInfo &efi = extractFolderInfoVector[i];\r\n    totalFolderUnpacked = efi.UnpackSize;\r\n\r\n    totalFolderPacked = 0;\r\n\r\n    CFolderOutStream *folderOutStream = new CFolderOutStream;\r\n    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);\r\n\r\n    #ifdef _7Z_VOL\r\n    const CVolume &volume = _volumes[efi.VolumeIndex];\r\n    const CArchiveDatabaseEx &db = volume.Database;\r\n    #else\r\n    const CArchiveDatabaseEx &db = _db;\r\n    #endif\r\n\r\n    CNum startIndex;\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      startIndex = efi.FileIndex;\r\n    else\r\n      startIndex = db.FolderStartFileIndex[efi.FolderIndex];\r\n\r\n\r\n    HRESULT result = folderOutStream->Init(&db,\r\n        #ifdef _7Z_VOL\r\n        volume.StartRef2Index,\r\n        #else\r\n        0,\r\n        #endif\r\n        startIndex,\r\n        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);\r\n\r\n    RINOK(result);\r\n\r\n    if (efi.FileIndex != kNumNoIndex)\r\n      continue;\r\n\r\n    CNum folderIndex = efi.FolderIndex;\r\n    const CFolder &folderInfo = db.Folders[folderIndex];\r\n\r\n    totalFolderPacked = _db.GetFolderFullPackSize(folderIndex);\r\n\r\n    CNum packStreamIndex = db.FolderStartPackStreamIndex[folderIndex];\r\n    UInt64 folderStartPackPos = db.GetFolderStreamPos(folderIndex, 0);\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (extractCallback)\r\n      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    #endif\r\n\r\n    try\r\n    {\r\n      #ifndef _NO_CRYPTO\r\n      bool passwordIsDefined;\r\n      #endif\r\n\r\n      HRESULT result = decoder.Decode(\r\n          EXTERNAL_CODECS_VARS\r\n          #ifdef _7Z_VOL\r\n          volume.Stream,\r\n          #else\r\n          _inStream,\r\n          #endif\r\n          folderStartPackPos,\r\n          &db.PackSizes[packStreamIndex],\r\n          folderInfo,\r\n          outStream,\r\n          progress\r\n          #ifndef _NO_CRYPTO\r\n          , getTextPassword, passwordIsDefined\r\n          #endif\r\n          #ifdef COMPRESS_MT\r\n          , true, _numThreads\r\n          #endif\r\n          );\r\n\r\n      if (result == S_FALSE)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));\r\n        continue;\r\n      }\r\n      if (result != S_OK)\r\n        return result;\r\n      if (folderOutStream->WasWritingFinished() != S_OK)\r\n      {\r\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n        continue;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\r\n      continue;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zFolderInStream.cpp",
    "content": "// 7zFolderInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderInStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderInStream::CFolderInStream()\r\n{\r\n  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;\r\n  _inStreamWithHash = _inStreamWithHashSpec;\r\n}\r\n\r\nvoid CFolderInStream::Init(IArchiveUpdateCallback *updateCallback,\r\n    const UInt32 *fileIndices, UInt32 numFiles)\r\n{\r\n  _updateCallback = updateCallback;\r\n  _numFiles = numFiles;\r\n  _fileIndex = 0;\r\n  _fileIndices = fileIndices;\r\n  Processed.Clear();\r\n  CRCs.Clear();\r\n  Sizes.Clear();\r\n  _fileIsOpen = false;\r\n  _currentSizeIsDefined = false;\r\n}\r\n\r\nHRESULT CFolderInStream::OpenStream()\r\n{\r\n  _filePos = 0;\r\n  while (_fileIndex < _numFiles)\r\n  {\r\n    _currentSizeIsDefined = false;\r\n    CMyComPtr<ISequentialInStream> stream;\r\n    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);\r\n    if (result != S_OK && result != S_FALSE)\r\n      return result;\r\n    _fileIndex++;\r\n    _inStreamWithHashSpec->SetStream(stream);\r\n    _inStreamWithHashSpec->Init();\r\n    if (!stream)\r\n    {\r\n      RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n      Sizes.Add(0);\r\n      Processed.Add(result == S_OK);\r\n      AddDigest();\r\n      continue;\r\n    }\r\n    CMyComPtr<IStreamGetSize> streamGetSize;\r\n    if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)\r\n    {\r\n      if(streamGetSize)\r\n      {\r\n        _currentSizeIsDefined = true;\r\n        RINOK(streamGetSize->GetSize(&_currentSize));\r\n      }\r\n    }\r\n\r\n    _fileIsOpen = true;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFolderInStream::AddDigest()\r\n{\r\n  CRCs.Add(_inStreamWithHashSpec->GetCRC());\r\n}\r\n\r\nHRESULT CFolderInStream::CloseStream()\r\n{\r\n  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\r\n  _inStreamWithHashSpec->ReleaseStream();\r\n  _fileIsOpen = false;\r\n  Processed.Add(true);\r\n  Sizes.Add(_filePos);\r\n  AddDigest();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 localProcessedSize;\r\n      RINOK(_inStreamWithHash->Read(\r\n          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));\r\n      if (localProcessedSize == 0)\r\n      {\r\n        RINOK(CloseStream());\r\n        continue;\r\n      }\r\n      realProcessedSize += localProcessedSize;\r\n      _filePos += localProcessedSize;\r\n      size -= localProcessedSize;\r\n      break;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenStream());\r\n    }\r\n  }\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)\r\n{\r\n  *value = 0;\r\n  int subStreamIndex = (int)subStream;\r\n  if (subStreamIndex < 0 || subStream > Sizes.Size())\r\n    return E_FAIL;\r\n  if (subStreamIndex < Sizes.Size())\r\n  {\r\n    *value= Sizes[subStreamIndex];\r\n    return S_OK;\r\n  }\r\n  if (!_currentSizeIsDefined)\r\n    return S_FALSE;\r\n  *value = _currentSize;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zFolderInStream.h",
    "content": "// 7z/FolderInStream.h\r\n\r\n#ifndef __7Z_FOLDERINSTREAM_H\r\n#define __7Z_FOLDERINSTREAM_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zHeader.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../Common/InStreamWithCRC.h\"\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderInStream:\r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  CFolderInStream();\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\nprivate:\r\n  CSequentialInStreamWithCRC *_inStreamWithHashSpec;\r\n  CMyComPtr<ISequentialInStream> _inStreamWithHash;\r\n  CMyComPtr<IArchiveUpdateCallback> _updateCallback;\r\n\r\n  bool _currentSizeIsDefined;\r\n  UInt64 _currentSize;\r\n\r\n  bool _fileIsOpen;\r\n  UInt64 _filePos;\r\n\r\n  const UInt32 *_fileIndices;\r\n  UInt32 _numFiles;\r\n  UInt32 _fileIndex;\r\n\r\n  HRESULT OpenStream();\r\n  HRESULT CloseStream();\r\n  void AddDigest();\r\npublic:\r\n  void Init(IArchiveUpdateCallback *updateCallback,\r\n      const UInt32 *fileIndices, UInt32 numFiles);\r\n  CRecordVector<bool> Processed;\r\n  CRecordVector<UInt32> CRCs;\r\n  CRecordVector<UInt64> Sizes;\r\n  UInt64 GetFullSize() const\r\n  {\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < Sizes.Size(); i++)\r\n      size += Sizes[i];\r\n    return size;\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zFolderOutStream.cpp",
    "content": "// 7zFolderOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zFolderOutStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCFolderOutStream::CFolderOutStream()\r\n{\r\n  _outStreamWithHashSpec = new COutStreamWithCRC;\r\n  _outStreamWithHash = _outStreamWithHashSpec;\r\n}\r\n\r\nHRESULT CFolderOutStream::Init(\r\n    const CArchiveDatabaseEx *archiveDatabase,\r\n    UInt32 ref2Offset,\r\n    UInt32 startIndex,\r\n    const CBoolVector *extractStatuses,\r\n    IArchiveExtractCallback *extractCallback,\r\n    bool testMode,\r\n    bool checkCrc)\r\n{\r\n  _archiveDatabase = archiveDatabase;\r\n  _ref2Offset = ref2Offset;\r\n  _startIndex = startIndex;\r\n\r\n  _extractStatuses = extractStatuses;\r\n  _extractCallback = extractCallback;\r\n  _testMode = testMode;\r\n\r\n  _checkCrc = checkCrc;\r\n\r\n  _currentIndex = 0;\r\n  _fileIsOpen = false;\r\n  return WriteEmptyFiles();\r\n}\r\n\r\nHRESULT CFolderOutStream::OpenFile()\r\n{\r\n  Int32 askMode;\r\n  if((*_extractStatuses)[_currentIndex])\r\n    askMode = _testMode ?\r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n  else\r\n    askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n\r\n  UInt32 index = _startIndex + _currentIndex;\r\n  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));\r\n\r\n  _outStreamWithHashSpec->SetStream(realOutStream);\r\n  _outStreamWithHashSpec->Init(_checkCrc);\r\n  if (askMode == NArchive::NExtract::NAskMode::kExtract &&\r\n      (!realOutStream))\r\n  {\r\n    const CFileItem &fi = _archiveDatabase->Files[index];\r\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir)\r\n      askMode = NArchive::NExtract::NAskMode::kSkip;\r\n  }\r\n  return _extractCallback->PrepareOperation(askMode);\r\n}\r\n\r\nHRESULT CFolderOutStream::WriteEmptyFiles()\r\n{\r\n  for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)\r\n  {\r\n    UInt32 index = _startIndex + _currentIndex;\r\n    const CFileItem &fi = _archiveDatabase->Files[index];\r\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir && fi.Size != 0)\r\n      return S_OK;\r\n    RINOK(OpenFile());\r\n    RINOK(_extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\r\n    _outStreamWithHashSpec->ReleaseStream();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFolderOutStream::Write(const void *data,\r\n    UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      UInt32 index = _startIndex + _currentIndex;\r\n      const CFileItem &fi = _archiveDatabase->Files[index];\r\n      UInt64 fileSize = fi.Size;\r\n      \r\n      UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos,\r\n          UInt64(size - realProcessedSize));\r\n      \r\n      UInt32 processedSizeLocal;\r\n      RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize,\r\n            numBytesToWrite, &processedSizeLocal));\r\n\r\n      _filePos += processedSizeLocal;\r\n      realProcessedSize += processedSizeLocal;\r\n      if (_filePos == fileSize)\r\n      {\r\n        bool digestsAreEqual;\r\n        if (fi.CrcDefined && _checkCrc)\r\n          digestsAreEqual = fi.Crc == _outStreamWithHashSpec->GetCRC();\r\n        else\r\n          digestsAreEqual = true;\r\n\r\n        RINOK(_extractCallback->SetOperationResult(\r\n            digestsAreEqual ?\r\n            NArchive::NExtract::NOperationResult::kOK :\r\n            NArchive::NExtract::NOperationResult::kCRCError));\r\n        _outStreamWithHashSpec->ReleaseStream();\r\n        _fileIsOpen = false;\r\n        _currentIndex++;\r\n      }\r\n      if (realProcessedSize == size)\r\n      {\r\n        if (processedSize != NULL)\r\n          *processedSize = realProcessedSize;\r\n        return WriteEmptyFiles();\r\n      }\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n      _filePos = 0;\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)\r\n{\r\n  while(_currentIndex < _extractStatuses->Size())\r\n  {\r\n    if (_fileIsOpen)\r\n    {\r\n      RINOK(_extractCallback->SetOperationResult(resultEOperationResult));\r\n      _outStreamWithHashSpec->ReleaseStream();\r\n      _fileIsOpen = false;\r\n      _currentIndex++;\r\n    }\r\n    else\r\n    {\r\n      RINOK(OpenFile());\r\n      _fileIsOpen = true;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CFolderOutStream::WasWritingFinished()\r\n{\r\n  if (_currentIndex == _extractStatuses->Size())\r\n    return S_OK;\r\n  return E_FAIL;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zFolderOutStream.h",
    "content": "// 7zFolderOutStream.h\r\n\r\n#ifndef __7Z_FOLDEROUTSTREAM_H\r\n#define __7Z_FOLDEROUTSTREAM_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../IArchive.h\"\r\n#include \"../Common/OutStreamWithCRC.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CFolderOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  \r\n  CFolderOutStream();\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n\r\n  COutStreamWithCRC *_outStreamWithHashSpec;\r\n  CMyComPtr<ISequentialOutStream> _outStreamWithHash;\r\n  const CArchiveDatabaseEx *_archiveDatabase;\r\n  const CBoolVector *_extractStatuses;\r\n  UInt32 _startIndex;\r\n  UInt32 _ref2Offset;\r\n  int _currentIndex;\r\n  // UInt64 _currentDataPos;\r\n  CMyComPtr<IArchiveExtractCallback> _extractCallback;\r\n  bool _testMode;\r\n\r\n  bool _fileIsOpen;\r\n\r\n  bool _checkCrc;\r\n  UInt64 _filePos;\r\n\r\n  HRESULT OpenFile();\r\n  HRESULT WriteEmptyFiles();\r\npublic:\r\n  HRESULT Init(\r\n      const CArchiveDatabaseEx *archiveDatabase,\r\n      UInt32 ref2Offset,\r\n      UInt32 startIndex,\r\n      const CBoolVector *extractStatuses,\r\n      IArchiveExtractCallback *extractCallback,\r\n      bool testMode,\r\n      bool checkCrc);\r\n  HRESULT FlushCorrupted(Int32 resultEOperationResult);\r\n  HRESULT WasWritingFinished();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zHandler.cpp",
    "content": "// 7zHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/CpuArch.h\"\r\n}\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zProperties.h\"\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n#include \"../Common/ParseProperties.h\"\r\n#endif\r\n#endif\r\n\r\nusing namespace NWindows;\r\n\r\nextern UString ConvertMethodIdToString(UInt64 id);\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nCHandler::CHandler()\r\n{\r\n  _crcSize = 4;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  _passwordIsDefined = false;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  #else\r\n  Init();\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = _db.Files.Size();\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _SFX\r\n\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,\r\n      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\n\r\n#else\r\n\r\nSTATPROPSTG kArcProps[] =\r\n{\r\n  { NULL, kpidMethod, VT_BSTR},\r\n  { NULL, kpidSolid, VT_BOOL},\r\n  { NULL, kpidNumBlocks, VT_UI4},\r\n  { NULL, kpidPhySize, VT_UI8},\r\n  { NULL, kpidHeadersSize, VT_UI8},\r\n  { NULL, kpidOffset, VT_UI8}\r\n};\r\n\r\nSTDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidMethod:\r\n    {\r\n      UString resString;\r\n      CRecordVector<UInt64> ids;\r\n      int i;\r\n      for (i = 0; i < _db.Folders.Size(); i++)\r\n      {\r\n        const CFolder &f = _db.Folders[i];\r\n        for (int j = f.Coders.Size() - 1; j >= 0; j--)\r\n          ids.AddToUniqueSorted(f.Coders[j].MethodID);\r\n      }\r\n\r\n      for (i = 0; i < ids.Size(); i++)\r\n      {\r\n        UInt64 id = ids[i];\r\n        UString methodName;\r\n        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);\r\n        if (methodName.IsEmpty())\r\n          methodName = ConvertMethodIdToString(id);\r\n        if (!resString.IsEmpty())\r\n          resString += L' ';\r\n        resString += methodName;\r\n      }\r\n      prop = resString;\r\n      break;\r\n    }\r\n    case kpidSolid: prop = _db.IsSolid(); break;\r\n    case kpidNumBlocks: prop = (UInt32)_db.Folders.Size(); break;\r\n    case kpidHeadersSize:  prop = _db.HeadersSize; break;\r\n    case kpidPhySize:  prop = _db.PhySize; break;\r\n    case kpidOffset: if (_db.ArchiveInfo.StartPosition != 0) prop = _db.ArchiveInfo.StartPosition; break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nIMP_IInArchive_ArcProps\r\n\r\n#endif\r\n\r\nstatic void SetPropFromUInt64Def(CUInt64DefVector &v, int index, NCOM::CPropVariant &prop)\r\n{\r\n  UInt64 value;\r\n  if (v.GetItem(index, value))\r\n  {\r\n    FILETIME ft;\r\n    ft.dwLowDateTime = (DWORD)value;\r\n    ft.dwHighDateTime = (DWORD)(value >> 32);\r\n    prop = ft;\r\n  }\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString GetStringForSizeValue(UInt32 value)\r\n{\r\n  for (int i = 31; i >= 0; i--)\r\n    if ((UInt32(1) << i) == value)\r\n      return ConvertUInt32ToString(i);\r\n  UString result;\r\n  if (value % (1 << 20) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 20);\r\n    result += L\"m\";\r\n  }\r\n  else if (value % (1 << 10) == 0)\r\n  {\r\n    result += ConvertUInt32ToString(value >> 10);\r\n    result += L\"k\";\r\n  }\r\n  else\r\n  {\r\n    result += ConvertUInt32ToString(value);\r\n    result += L\"b\";\r\n  }\r\n  return result;\r\n}\r\n\r\nstatic const UInt64 k_Copy = 0x0;\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_PPMD  = 0x030401;\r\n\r\nstatic wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));\r\n}\r\nstatic inline UString GetHex2(Byte value)\r\n{\r\n  UString result;\r\n  result += GetHex((Byte)(value >> 4));\r\n  result += GetHex((Byte)(value & 0xF));\r\n  return result;\r\n}\r\n\r\n#endif\r\n\r\nstatic const UInt64 k_AES  = 0x06F10701;\r\n\r\nbool CHandler::IsEncrypted(UInt32 index2) const\r\n{\r\n  CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n  if (folderIndex != kNumNoIndex)\r\n  {\r\n    const CFolder &folderInfo = _db.Folders[folderIndex];\r\n    for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n      if (folderInfo.Coders[i].MethodID == k_AES)\r\n        return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  \r\n  /*\r\n  const CRef2 &ref2 = _refs[index];\r\n  if (ref2.Refs.IsEmpty())\r\n    return E_FAIL;\r\n  const CRef &ref = ref2.Refs.Front();\r\n  */\r\n  \r\n  const CFileItem &item = _db.Files[index];\r\n  UInt32 index2 = index;\r\n\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n      if (!item.Name.IsEmpty())\r\n        prop = NItemName::GetOSName(item.Name);\r\n      break;\r\n    case kpidIsDir:  prop = item.IsDir; break;\r\n    case kpidSize:\r\n    {\r\n      prop = item.Size;\r\n      // prop = ref2.Size;\r\n      break;\r\n    }\r\n    case kpidPackSize:\r\n    {\r\n      // prop = ref2.PackSize;\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2)\r\n            prop = _db.GetFolderFullPackSize(folderIndex);\r\n          /*\r\n          else\r\n            prop = (UInt64)0;\r\n          */\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    }\r\n    case kpidPosition:  { UInt64 v; if (_db.StartPos.GetItem(index2, v)) prop = v; break; }\r\n    case kpidCTime:  SetPropFromUInt64Def(_db.CTime, index2, prop); break;\r\n    case kpidATime:  SetPropFromUInt64Def(_db.ATime, index2, prop); break;\r\n    case kpidMTime:  SetPropFromUInt64Def(_db.MTime, index2, prop); break;\r\n    case kpidAttrib:  if (item.AttribDefined) prop = item.Attrib; break;\r\n    case kpidCRC:  if (item.CrcDefined) prop = item.Crc; break;\r\n    case kpidEncrypted:  prop = IsEncrypted(index2); break;\r\n    case kpidIsAnti:  prop = _db.IsItemAnti(index2); break;\r\n    #ifndef _SFX\r\n    case kpidMethod:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _db.Folders[folderIndex];\r\n          UString methodsString;\r\n          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\r\n          {\r\n            const CCoderInfo &coderInfo = folderInfo.Coders[i];\r\n            if (!methodsString.IsEmpty())\r\n              methodsString += L' ';\r\n\r\n            {\r\n              UString methodName;\r\n              bool methodIsKnown = FindMethod(\r\n                  EXTERNAL_CODECS_VARS\r\n                  coderInfo.MethodID, methodName);\r\n\r\n              if (methodIsKnown)\r\n              {\r\n                methodsString += methodName;\r\n                if (coderInfo.MethodID == k_LZMA)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 5)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_PPMD)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 5)\r\n                  {\r\n                    Byte order = *(const Byte *)coderInfo.Props;\r\n                    methodsString += L\":o\";\r\n                    methodsString += ConvertUInt32ToString(order);\r\n                    methodsString += L\":mem\";\r\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\r\n                    methodsString += GetStringForSizeValue(dicSize);\r\n                  }\r\n                }\r\n                else if (coderInfo.MethodID == k_AES)\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() >= 1)\r\n                  {\r\n                    methodsString += L\":\";\r\n                    const Byte *data = (const Byte *)coderInfo.Props;\r\n                    Byte firstByte = *data++;\r\n                    UInt32 numCyclesPower = firstByte & 0x3F;\r\n                    methodsString += ConvertUInt32ToString(numCyclesPower);\r\n                    /*\r\n                    if ((firstByte & 0xC0) != 0)\r\n                    {\r\n                      methodsString += L\":\";\r\n                      return S_OK;\r\n                      UInt32 saltSize = (firstByte >> 7) & 1;\r\n                      UInt32 ivSize = (firstByte >> 6) & 1;\r\n                      if (coderInfo.Props.GetCapacity() >= 2)\r\n                      {\r\n                        Byte secondByte = *data++;\r\n                        saltSize += (secondByte >> 4);\r\n                        ivSize += (secondByte & 0x0F);\r\n                      }\r\n                    }\r\n                    */\r\n                  }\r\n                }\r\n                else\r\n                {\r\n                  if (coderInfo.Props.GetCapacity() > 0)\r\n                  {\r\n                    methodsString += L\":[\";\r\n                    for (size_t bi = 0; bi < coderInfo.Props.GetCapacity(); bi++)\r\n                    {\r\n                      if (bi > 5 && bi + 1 < coderInfo.Props.GetCapacity())\r\n                      {\r\n                        methodsString += L\"..\";\r\n                        break;\r\n                      }\r\n                      else\r\n                        methodsString += GetHex2(coderInfo.Props[bi]);\r\n                    }\r\n                    methodsString += L\"]\";\r\n                  }\r\n                }\r\n              }\r\n              else\r\n              {\r\n                methodsString += ConvertMethodIdToString(coderInfo.MethodID);\r\n              }\r\n            }\r\n          }\r\n          prop = methodsString;\r\n        }\r\n      }\r\n      break;\r\n    case kpidBlock:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n          prop = (UInt32)folderIndex;\r\n      }\r\n      break;\r\n    case kpidPackedSize0:\r\n    case kpidPackedSize1:\r\n    case kpidPackedSize2:\r\n    case kpidPackedSize3:\r\n    case kpidPackedSize4:\r\n      {\r\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\r\n        if (folderIndex != kNumNoIndex)\r\n        {\r\n          const CFolder &folderInfo = _db.Folders[folderIndex];\r\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 &&\r\n              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))\r\n          {\r\n            prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);\r\n          }\r\n          else\r\n            prop = (UInt64)0;\r\n        }\r\n        else\r\n          prop = (UInt64)0;\r\n      }\r\n      break;\r\n    #endif\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 *maxCheckStartPosition,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Clear();\r\n  #endif\r\n  try\r\n  {\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    if (openArchiveCallback)\r\n    {\r\n      openArchiveCallbackTemp.QueryInterface(\r\n          IID_ICryptoGetTextPassword, &getTextPassword);\r\n    }\r\n    #endif\r\n    CInArchive archive;\r\n    RINOK(archive.Open(stream, maxCheckStartPosition));\r\n    #ifndef _NO_CRYPTO\r\n    _passwordIsDefined = false;\r\n    UString password;\r\n    #endif\r\n    HRESULT result = archive.ReadDatabase(\r\n      EXTERNAL_CODECS_VARS\r\n      _db\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, _passwordIsDefined\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    _db.Fill();\r\n    _inStream = stream;\r\n  }\r\n  catch(...)\r\n  {\r\n    Close();\r\n    return S_FALSE;\r\n  }\r\n  // _inStream = stream;\r\n  #ifndef _SFX\r\n  FillPopIDs();\r\n  #endif\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  COM_TRY_BEGIN\r\n  _inStream.Release();\r\n  _db.Clear();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifdef __7Z_SET_PROPERTIES\r\n#ifdef EXTRACT_ONLY\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  #ifdef COMPRESS_MT\r\n  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();\r\n  _numThreads = numProcessors;\r\n  #endif\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    const PROPVARIANT &value = values[i];\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index == 0)\r\n    {\r\n      if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n      {\r\n        #ifdef COMPRESS_MT\r\n        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n        #endif\r\n        continue;\r\n      }\r\n      else\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#endif\r\n#endif\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zHandler.h",
    "content": "// 7z/Handler.h\r\n\r\n#ifndef __7Z_HANDLER_H\r\n#define __7Z_HANDLER_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../IArchive.h\"\r\n#include \"7zIn.h\"\r\n\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#ifndef EXTRACT_ONLY\r\n#include \"../Common/HandlerOut.h\"\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\n#ifndef __7Z_SET_PROPERTIES\r\n\r\n#ifdef EXTRACT_ONLY\r\n#ifdef COMPRESS_MT\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n#else\r\n#define __7Z_SET_PROPERTIES\r\n#endif\r\n\r\n#endif\r\n\r\n\r\nclass CHandler:\r\n  #ifndef EXTRACT_ONLY\r\n  public NArchive::COutHandler,\r\n  #endif\r\n  public IInArchive,\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  public ISetProperties,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public IOutArchive,\r\n  #endif\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IInArchive)\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  MY_QUERYINTERFACE_ENTRY(ISetProperties)\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  MY_QUERYINTERFACE_ENTRY(IOutArchive)\r\n  #endif\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  #ifdef __7Z_SET_PROPERTIES\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);\r\n  #endif\r\n\r\n  #ifndef EXTRACT_ONLY\r\n  INTERFACE_IOutArchive(;)\r\n  #endif\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n  CHandler();\r\n\r\nprivate:\r\n  CMyComPtr<IInStream> _inStream;\r\n  NArchive::N7z::CArchiveDatabaseEx _db;\r\n  #ifndef _NO_CRYPTO\r\n  bool _passwordIsDefined;\r\n  #endif\r\n\r\n  #ifdef EXTRACT_ONLY\r\n  \r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  #else\r\n  \r\n  CRecordVector<CBind> _binds;\r\n\r\n  HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);\r\n\r\n  HRESULT SetCompressionMethod(CCompressionMethodMode &method,\r\n      CObjectVector<COneMethodInfo> &methodsInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  HRESULT SetCompressionMethod(\r\n      CCompressionMethodMode &method,\r\n      CCompressionMethodMode &headerMethod);\r\n\r\n  #endif\r\n\r\n  bool IsEncrypted(UInt32 index2) const;\r\n  #ifndef _SFX\r\n\r\n  CRecordVector<UInt64> _fileInfoPopIDs;\r\n  void FillPopIDs();\r\n\r\n  #endif\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zHandlerOut.cpp",
    "content": "// 7zHandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const UInt32 kLzmaAlgorithmX5 = 1;\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5;\r\n\r\nstatic inline bool IsCopyMethod(const UString &methodName)\r\n  { return (methodName.CompareNoCase(kCopyMethod) == 0); }\r\n\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  CMyComPtr<ICryptoGetTextPassword2> getTextPassword;\r\n  if (!getTextPassword)\r\n  {\r\n    CMyComPtr<IArchiveUpdateCallback> udateCallback2(updateCallback);\r\n    udateCallback2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);\r\n  }\r\n  \r\n  if (getTextPassword)\r\n  {\r\n    CMyComBSTR password;\r\n    Int32 passwordIsDefined;\r\n    RINOK(getTextPassword->CryptoGetTextPassword2(\r\n        &passwordIsDefined, &password));\r\n    methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);\r\n    if (methodMode.PasswordIsDefined)\r\n      methodMode.Password = password;\r\n  }\r\n  else\r\n    methodMode.PasswordIsDefined = false;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CCompressionMethodMode &headerMethod)\r\n{\r\n  HRESULT res = SetCompressionMethod(methodMode, _methods\r\n  #ifdef COMPRESS_MT\r\n  , _numThreads\r\n  #endif\r\n  );\r\n  RINOK(res);\r\n  methodMode.Binds = _binds;\r\n\r\n  if (_compressHeaders)\r\n  {\r\n    // headerMethod.Methods.Add(methodMode.Methods.Back());\r\n\r\n    CObjectVector<COneMethodInfo> headerMethodInfoVector;\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = kLZMAMethodName;\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kMatchFinder;\r\n      prop.Value = kLzmaMatchFinderForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kAlgorithm;\r\n      prop.Value = kAlgorithmForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kNumFastBytes;\r\n      prop.Value = (UInt32)kNumFastBytesForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = (UInt32)kDictionaryForHeaders;\r\n      oneMethodInfo.Props.Add(prop);\r\n    }\r\n    headerMethodInfoVector.Add(oneMethodInfo);\r\n    HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector\r\n      #ifdef COMPRESS_MT\r\n      ,1\r\n      #endif\r\n    );\r\n    RINOK(res);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CHandler::SetCompressionMethod(\r\n    CCompressionMethodMode &methodMode,\r\n    CObjectVector<COneMethodInfo> &methodsInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  \r\n  if (methodsInfo.IsEmpty())\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    oneMethodInfo.MethodName = ((level == 0) ? kCopyMethod : kDefaultMethodName);\r\n    methodsInfo.Add(oneMethodInfo);\r\n  }\r\n\r\n  bool needSolid = false;\r\n  for(int i = 0; i < methodsInfo.Size(); i++)\r\n  {\r\n    COneMethodInfo &oneMethodInfo = methodsInfo[i];\r\n    SetCompressionMethod2(oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , numThreads\r\n      #endif\r\n      );\r\n\r\n    if (!IsCopyMethod(oneMethodInfo.MethodName))\r\n      needSolid = true;\r\n\r\n    CMethodFull methodFull;\r\n\r\n    if (!FindMethod(\r\n        EXTERNAL_CODECS_VARS\r\n        oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams))\r\n      return E_INVALIDARG;\r\n    methodFull.Props = oneMethodInfo.Props;\r\n    methodMode.Methods.Add(methodFull);\r\n\r\n    if (!_numSolidBytesDefined)\r\n    {\r\n      for (int j = 0; j < methodFull.Props.Size(); j++)\r\n      {\r\n        const CProp &prop = methodFull.Props[j];\r\n        if ((prop.Id == NCoderPropID::kDictionarySize ||\r\n             prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4)\r\n        {\r\n          _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7;\r\n          const UInt64 kMinSize = (1 << 24);\r\n          if (_numSolidBytes < kMinSize)\r\n            _numSolidBytes = kMinSize;\r\n          _numSolidBytesDefined = true;\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (!needSolid && !_numSolidBytesDefined)\r\n  {\r\n    _numSolidBytesDefined = true;\r\n    _numSolidBytes  = 0;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, bool writeTime, PROPID propID, UInt64 &ft, bool &ftDefined)\r\n{\r\n  ft = 0;\r\n  ftDefined = false;\r\n  if (!writeTime)\r\n    return S_OK;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(updateCallback->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    ft = prop.filetime.dwLowDateTime | ((UInt64)prop.filetime.dwHighDateTime << 32);\r\n    ftDefined = true;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  const CArchiveDatabaseEx *db = 0;\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() > 1)\r\n    return E_FAIL;\r\n  const CVolume *volume = 0;\r\n  if (_volumes.Size() == 1)\r\n  {\r\n    volume = &_volumes.Front();\r\n    db = &volume->Database;\r\n  }\r\n  #else\r\n  if (_inStream != 0)\r\n    db = &_db;\r\n  #endif\r\n\r\n  CObjectVector<CUpdateItem> updateItems;\r\n  \r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    Int32 newData;\r\n    Int32 newProperties;\r\n    UInt32 indexInArchive;\r\n    if (!updateCallback)\r\n      return E_FAIL;\r\n    RINOK(updateCallback->GetUpdateItemInfo(i, &newData, &newProperties, &indexInArchive));\r\n    CUpdateItem ui;\r\n    ui.NewProperties = IntToBool(newProperties);\r\n    ui.NewData = IntToBool(newData);\r\n    ui.IndexInArchive = indexInArchive;\r\n    ui.IndexInClient = i;\r\n    ui.IsAnti = false;\r\n    ui.Size = 0;\r\n\r\n    if (ui.IndexInArchive != -1)\r\n    {\r\n      const CFileItem &fi = db->Files[ui.IndexInArchive];\r\n      ui.Name = fi.Name;\r\n      ui.IsDir = fi.IsDir;\r\n      ui.Size = fi.Size;\r\n      ui.IsAnti = db->IsItemAnti(ui.IndexInArchive);\r\n      \r\n      ui.CTimeDefined = db->CTime.GetItem(ui.IndexInArchive, ui.CTime);\r\n      ui.ATimeDefined = db->ATime.GetItem(ui.IndexInArchive, ui.ATime);\r\n      ui.MTimeDefined = db->MTime.GetItem(ui.IndexInArchive, ui.MTime);\r\n    }\r\n\r\n    if (ui.NewProperties)\r\n    {\r\n      bool nameIsDefined;\r\n      bool folderStatusIsDefined;\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidAttrib, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          ui.AttribDefined = false;\r\n        else if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.Attrib = prop.ulVal;\r\n          ui.AttribDefined = true;\r\n        }\r\n      }\r\n      \r\n      // we need MTime to sort files.\r\n      RINOK(GetTime(updateCallback, i, WriteCTime, kpidCTime, ui.CTime, ui.CTimeDefined));\r\n      RINOK(GetTime(updateCallback, i, WriteATime, kpidATime, ui.ATime, ui.ATimeDefined));\r\n      RINOK(GetTime(updateCallback, i, true,       kpidMTime, ui.MTime, ui.MTimeDefined));\r\n\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidPath, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          nameIsDefined = false;\r\n        else if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.Name = NItemName::MakeLegalName(prop.bstrVal);\r\n          nameIsDefined = true;\r\n        }\r\n      }\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsDir, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          folderStatusIsDefined = false;\r\n        else if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n        {\r\n          ui.IsDir = (prop.boolVal != VARIANT_FALSE);\r\n          folderStatusIsDefined = true;\r\n        }\r\n      }\r\n\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(updateCallback->GetProperty(i, kpidIsAnti, &prop));\r\n        if (prop.vt == VT_EMPTY)\r\n          ui.IsAnti = false;\r\n        else if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        else\r\n          ui.IsAnti = (prop.boolVal != VARIANT_FALSE);\r\n      }\r\n\r\n      if (ui.IsAnti)\r\n      {\r\n        ui.AttribDefined = false;\r\n\r\n        ui.CTimeDefined = false;\r\n        ui.ATimeDefined = false;\r\n        ui.MTimeDefined = false;\r\n        \r\n        ui.Size = 0;\r\n      }\r\n\r\n      if (!folderStatusIsDefined && ui.AttribDefined)\r\n        ui.SetDirStatusFromAttrib();\r\n    }\r\n\r\n    if (ui.NewData)\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(i, kpidSize, &prop));\r\n      if (prop.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      ui.Size = (UInt64)prop.uhVal.QuadPart;\r\n      if (ui.Size != 0 && ui.IsAnti)\r\n        return E_INVALIDARG;\r\n    }\r\n    updateItems.Add(ui);\r\n  }\r\n\r\n  CCompressionMethodMode methodMode, headerMethod;\r\n  RINOK(SetCompressionMethod(methodMode, headerMethod));\r\n  #ifdef COMPRESS_MT\r\n  methodMode.NumThreads = _numThreads;\r\n  headerMethod.NumThreads = 1;\r\n  #endif\r\n\r\n  RINOK(SetPassword(methodMode, updateCallback));\r\n\r\n  bool compressMainHeader = _compressHeaders;  // check it\r\n\r\n  bool encryptHeaders = false;\r\n\r\n  if (methodMode.PasswordIsDefined)\r\n  {\r\n    if (_encryptHeadersSpecified)\r\n      encryptHeaders = _encryptHeaders;\r\n    #ifndef _NO_CRYPTO\r\n    else\r\n      encryptHeaders = _passwordIsDefined;\r\n    #endif\r\n    compressMainHeader = true;\r\n    if(encryptHeaders)\r\n      RINOK(SetPassword(headerMethod, updateCallback));\r\n  }\r\n\r\n  if (numItems < 2)\r\n    compressMainHeader = false;\r\n\r\n  CUpdateOptions options;\r\n  options.Method = &methodMode;\r\n  options.HeaderMethod = (_compressHeaders || encryptHeaders) ? &headerMethod : 0;\r\n  options.UseFilters = _level != 0 && _autoFilter;\r\n  options.MaxFilter = _level >= 8;\r\n\r\n  options.HeaderOptions.CompressMainHeader = compressMainHeader;\r\n  options.HeaderOptions.WriteCTime = WriteCTime;\r\n  options.HeaderOptions.WriteATime = WriteATime;\r\n  options.HeaderOptions.WriteMTime = WriteMTime;\r\n  \r\n  options.NumSolidFiles = _numSolidFiles;\r\n  options.NumSolidBytes = _numSolidBytes;\r\n  options.SolidExtension = _solidExtension;\r\n  options.RemoveSfxBlock = _removeSfxBlock;\r\n  options.VolumeMode = _volumeMode;\r\n\r\n  COutArchive archive;\r\n  CArchiveDatabase newDatabase;\r\n  HRESULT res = Update(\r\n      EXTERNAL_CODECS_VARS\r\n      #ifdef _7Z_VOL\r\n      volume ? volume->Stream: 0,\r\n      volume ? db : 0,\r\n      #else\r\n      _inStream,\r\n      db,\r\n      #endif\r\n      updateItems,\r\n      archive, newDatabase, outStream, updateCallback, options);\r\n\r\n  RINOK(res);\r\n\r\n  updateItems.ClearAndFree();\r\n\r\n  return archive.WriteDatabase(EXTERNAL_CODECS_VARS\r\n      newDatabase, options.HeaderMethod, options.HeaderOptions);\r\n\r\n  COM_TRY_END\r\n}\r\n\r\nstatic HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)\r\n{\r\n  stream = 0;\r\n  int index = ParseStringToUInt32(srcString, coder);\r\n  if (index == 0)\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0, index);\r\n  if (srcString[0] == 'S')\r\n  {\r\n    srcString.Delete(0);\r\n    int index = ParseStringToUInt32(srcString, stream);\r\n    if (index == 0)\r\n      return E_INVALIDARG;\r\n    srcString.Delete(0, index);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT GetBindInfo(UString &srcString, CBind &bind)\r\n{\r\n  RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream));\r\n  if (srcString[0] != ':')\r\n    return E_INVALIDARG;\r\n  srcString.Delete(0);\r\n  RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream));\r\n  if (!srcString.IsEmpty())\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\r\n{\r\n  COM_TRY_BEGIN\r\n  _binds.Clear();\r\n  BeforeSetProperty();\r\n\r\n  for (int i = 0; i < numProperties; i++)\r\n  {\r\n    UString name = names[i];\r\n    name.MakeUpper();\r\n    if (name.IsEmpty())\r\n      return E_INVALIDARG;\r\n\r\n    const PROPVARIANT &value = values[i];\r\n\r\n    if (name[0] == 'B')\r\n    {\r\n      name.Delete(0);\r\n      CBind bind;\r\n      RINOK(GetBindInfo(name, bind));\r\n      _binds.Add(bind);\r\n      continue;\r\n    }\r\n\r\n    RINOK(SetProperty(name, value));\r\n  }\r\n\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zHeader.cpp",
    "content": "// 7z/Header.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nByte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n#ifdef _7Z_VOL\r\nByte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};\r\n#endif\r\n\r\nclass SignatureInitializer\r\n{\r\npublic:\r\n  SignatureInitializer()\r\n  {\r\n    kSignature[0]--;\r\n    #ifdef _7Z_VOL\r\n    kFinishSignature[0]--;\r\n    #endif\r\n  };\r\n} g_SignatureInitializer;\r\n\r\n}}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zHeader.h",
    "content": "// 7z/7zHeader.h\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nconst int kSignatureSize = 6;\r\nextern Byte kSignature[kSignatureSize];\r\n\r\n// #define _7Z_VOL\r\n// 7z-MultiVolume is not finished yet.\r\n// It can work already, but I still do not like some\r\n// things of that new multivolume format.\r\n// So please keep it commented.\r\n\r\n#ifdef _7Z_VOL\r\nextern Byte kFinishSignature[kSignatureSize];\r\n#endif\r\n\r\nstruct CArchiveVersion\r\n{\r\n  Byte Major;\r\n  Byte Minor;\r\n};\r\n\r\nconst Byte kMajorVersion = 0;\r\n\r\nstruct CStartHeader\r\n{\r\n  UInt64 NextHeaderOffset;\r\n  UInt64 NextHeaderSize;\r\n  UInt32 NextHeaderCRC;\r\n};\r\n\r\nconst UInt32 kStartHeaderSize = 20;\r\n\r\n#ifdef _7Z_VOL\r\nstruct CFinishHeader: public CStartHeader\r\n{\r\n  UInt64 ArchiveStartOffset;  // data offset from end if that struct\r\n  UInt64 AdditionalStartBlockSize; // start  signature & start header size\r\n};\r\n\r\nconst UInt32 kFinishHeaderSize = kStartHeaderSize + 16;\r\n#endif\r\n\r\nnamespace NID\r\n{\r\n  enum EEnum\r\n  {\r\n    kEnd,\r\n\r\n    kHeader,\r\n\r\n    kArchiveProperties,\r\n    \r\n    kAdditionalStreamsInfo,\r\n    kMainStreamsInfo,\r\n    kFilesInfo,\r\n    \r\n    kPackInfo,\r\n    kUnpackInfo,\r\n    kSubStreamsInfo,\r\n\r\n    kSize,\r\n    kCRC,\r\n\r\n    kFolder,\r\n\r\n    kCodersUnpackSize,\r\n    kNumUnpackStream,\r\n\r\n    kEmptyStream,\r\n    kEmptyFile,\r\n    kAnti,\r\n\r\n    kName,\r\n    kCTime,\r\n    kATime,\r\n    kMTime,\r\n    kWinAttributes,\r\n    kComment,\r\n\r\n    kEncodedHeader,\r\n\r\n    kStartPos,\r\n    kDummy\r\n  };\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zIn.cpp",
    "content": "// 7zIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/7zCrc.h\"\r\n  #include \"../../../../C/CpuArch.h\"\r\n}\r\n\r\n#include \"../../Common/StreamObjects.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"7zDecode.h\"\r\n#include \"7zIn.h\"\r\n\r\n#define Get16(p) GetUi16(p)\r\n#define Get32(p) GetUi32(p)\r\n#define Get64(p) GetUi64(p)\r\n\r\n// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader\r\n#ifndef _SFX\r\n#define FORMAT_7Z_RECOVERY\r\n#endif\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic void BoolVector_Fill_False(CBoolVector &v, int size)\r\n{\r\n  v.Clear();\r\n  v.Reserve(size);\r\n  for (int i = 0; i < size; i++)\r\n    v.Add(false);\r\n}\r\n\r\nstatic bool BoolVector_GetAndSet(CBoolVector &v, UInt32 index)\r\n{\r\n  if (index >= (UInt32)v.Size())\r\n    return true;\r\n  bool res = v[index];\r\n  v[index] = true;\r\n  return res;\r\n}\r\n\r\nbool CFolder::CheckStructure() const\r\n{\r\n  const int kNumCodersMax = sizeof(UInt32) * 8; // don't change it\r\n  const int kMaskSize = sizeof(UInt32) * 8; // it must be >= kNumCodersMax\r\n  const int kNumBindsMax = 32;\r\n\r\n  if (Coders.Size() > kNumCodersMax || BindPairs.Size() > kNumBindsMax)\r\n    return false;\r\n\r\n  {\r\n    CBoolVector v;\r\n    BoolVector_Fill_False(v, BindPairs.Size() + PackStreams.Size());\r\n    \r\n    int i;\r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, BindPairs[i].InIndex))\r\n        return false;\r\n    for (i = 0; i < PackStreams.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, PackStreams[i]))\r\n        return false;\r\n    \r\n    BoolVector_Fill_False(v, UnpackSizes.Size());\r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n      if (BoolVector_GetAndSet(v, BindPairs[i].OutIndex))\r\n        return false;\r\n  }\r\n  \r\n  UInt32 mask[kMaskSize];\r\n  int i;\r\n  for (i = 0; i < kMaskSize; i++)\r\n    mask[i] = 0;\r\n\r\n  {\r\n    CIntVector inStreamToCoder, outStreamToCoder;\r\n    for (i = 0; i < Coders.Size(); i++)\r\n    {\r\n      CNum j;\r\n      const CCoderInfo &coder = Coders[i];\r\n      for (j = 0; j < coder.NumInStreams; j++)\r\n        inStreamToCoder.Add(i);\r\n      for (j = 0; j < coder.NumOutStreams; j++)\r\n        outStreamToCoder.Add(i);\r\n    }\r\n    \r\n    for (i = 0; i < BindPairs.Size(); i++)\r\n    {\r\n      const CBindPair &bp = BindPairs[i];\r\n      mask[inStreamToCoder[bp.InIndex]] |= (1 << outStreamToCoder[bp.OutIndex]);\r\n    }\r\n  }\r\n  \r\n  for (i = 0; i < kMaskSize; i++)\r\n    for (int j = 0; j < kMaskSize; j++)\r\n      if (((1 << j) & mask[i]) != 0)\r\n        mask[i] |= mask[j];\r\n\r\n  for (i = 0; i < kMaskSize; i++)\r\n    if (((1 << i) & mask[i]) != 0)\r\n      return false;\r\n\r\n  return true;\r\n}\r\n\r\nclass CInArchiveException {};\r\n\r\nstatic void ThrowException() { throw CInArchiveException(); }\r\nstatic inline void ThrowEndOfData()   { ThrowException(); }\r\nstatic inline void ThrowUnsupported() { ThrowException(); }\r\nstatic inline void ThrowIncorrect()   { ThrowException(); }\r\nstatic inline void ThrowUnsupportedVersion() { ThrowException(); }\r\n\r\n/*\r\nclass CInArchiveException\r\n{\r\npublic:\r\n  enum CCauseType\r\n  {\r\n    kUnsupportedVersion = 0,\r\n    kUnsupported,\r\n    kIncorrect,\r\n    kEndOfData,\r\n  } Cause;\r\n  CInArchiveException(CCauseType cause): Cause(cause) {};\r\n};\r\n\r\nstatic void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }\r\nstatic void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }\r\nstatic void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }\r\nstatic void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }\r\nstatic void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }\r\n*/\r\n\r\nclass CStreamSwitch\r\n{\r\n  CInArchive *_archive;\r\n  bool _needRemove;\r\npublic:\r\n  CStreamSwitch(): _needRemove(false) {}\r\n  ~CStreamSwitch() { Remove(); }\r\n  void Remove();\r\n  void Set(CInArchive *archive, const Byte *data, size_t size);\r\n  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);\r\n  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);\r\n};\r\n\r\nvoid CStreamSwitch::Remove()\r\n{\r\n  if (_needRemove)\r\n  {\r\n    _archive->DeleteByteStream();\r\n    _needRemove = false;\r\n  }\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)\r\n{\r\n  Remove();\r\n  _archive = archive;\r\n  _archive->AddByteStream(data, size);\r\n  _needRemove = true;\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)\r\n{\r\n  Set(archive, byteBuffer, byteBuffer.GetCapacity());\r\n}\r\n\r\nvoid CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)\r\n{\r\n  Remove();\r\n  Byte external = archive->ReadByte();\r\n  if (external != 0)\r\n  {\r\n    int dataIndex = (int)archive->ReadNum();\r\n    if (dataIndex < 0 || dataIndex >= dataVector->Size())\r\n      ThrowIncorrect();\r\n    Set(archive, (*dataVector)[dataIndex]);\r\n  }\r\n}\r\n\r\nByte CInByte2::ReadByte()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  return _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::ReadBytes(Byte *data, size_t size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  for (size_t i = 0; i < size; i++)\r\n    data[i] = _buffer[_pos++];\r\n}\r\n\r\nvoid CInByte2::SkeepData(UInt64 size)\r\n{\r\n  if (size > _size - _pos)\r\n    ThrowEndOfData();\r\n  _pos += (size_t)size;\r\n}\r\n\r\nvoid CInByte2::SkeepData()\r\n{\r\n  SkeepData(ReadNumber());\r\n}\r\n\r\nUInt64 CInByte2::ReadNumber()\r\n{\r\n  if (_pos >= _size)\r\n    ThrowEndOfData();\r\n  Byte firstByte = _buffer[_pos++];\r\n  Byte mask = 0x80;\r\n  UInt64 value = 0;\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      value += (highPart << (i * 8));\r\n      return value;\r\n    }\r\n    if (_pos >= _size)\r\n      ThrowEndOfData();\r\n    value |= ((UInt64)_buffer[_pos++] << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return value;\r\n}\r\n\r\nCNum CInByte2::ReadNum()\r\n{\r\n  UInt64 value = ReadNumber();\r\n  if (value > kNumMax)\r\n    ThrowUnsupported();\r\n  return (CNum)value;\r\n}\r\n\r\nUInt32 CInByte2::ReadUInt32()\r\n{\r\n  if (_pos + 4 > _size)\r\n    ThrowEndOfData();\r\n  UInt32 res = Get32(_buffer + _pos);\r\n  _pos += 4;\r\n  return res;\r\n}\r\n\r\nUInt64 CInByte2::ReadUInt64()\r\n{\r\n  if (_pos + 8 > _size)\r\n    ThrowEndOfData();\r\n  UInt64 res = Get64(_buffer + _pos);\r\n  _pos += 8;\r\n  return res;\r\n}\r\n\r\nvoid CInByte2::ReadString(UString &s)\r\n{\r\n  const Byte *buf = _buffer + _pos;\r\n  size_t rem = (_size - _pos) / 2 * 2;\r\n  {\r\n    size_t i;\r\n    for (i = 0; i < rem; i += 2)\r\n      if (buf[i] == 0 && buf[i + 1] == 0)\r\n        break;\r\n    if (i == rem)\r\n      ThrowEndOfData();\r\n    rem = i;\r\n  }\r\n  int len = (int)(rem / 2);\r\n  if (len < 0 || (size_t)len * 2 != rem)\r\n    ThrowUnsupported();\r\n  wchar_t *p = s.GetBuffer(len);\r\n  int i;\r\n  for (i = 0; i < len; i++, buf += 2)\r\n    p[i] = (wchar_t)Get16(buf);\r\n  s.ReleaseBuffer(len);\r\n  _pos += rem + 2;\r\n}\r\n\r\nstatic inline bool TestSignatureCandidate(const Byte *p)\r\n{\r\n  for (int i = 0; i < kSignatureSize; i++)\r\n    if (p[i] != kSignature[i])\r\n      return false;\r\n  return (p[0x1A] == 0 && p[0x1B] == 0);\r\n}\r\n\r\nHRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));\r\n\r\n  if (TestSignatureCandidate(_header))\r\n    return S_OK;\r\n\r\n  CByteBuffer byteBuffer;\r\n  const UInt32 kBufferSize = (1 << 16);\r\n  byteBuffer.SetCapacity(kBufferSize);\r\n  Byte *buffer = byteBuffer;\r\n  UInt32 numPrevBytes = kHeaderSize - 1;\r\n  memcpy(buffer, _header + 1, numPrevBytes);\r\n  UInt64 curTestPos = _arhiveBeginStreamPosition + 1;\r\n  for (;;)\r\n  {\r\n    if (searchHeaderSizeLimit != NULL)\r\n      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)\r\n        break;\r\n    do\r\n    {\r\n      UInt32 numReadBytes = kBufferSize - numPrevBytes;\r\n      UInt32 processedSize;\r\n      RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));\r\n      numPrevBytes += processedSize;\r\n      if (processedSize == 0)\r\n        return S_FALSE;\r\n    }\r\n    while (numPrevBytes < kHeaderSize);\r\n    UInt32 numTests = numPrevBytes - kHeaderSize + 1;\r\n    for (UInt32 pos = 0; pos < numTests; pos++)\r\n    {\r\n      for (; buffer[pos] != '7' && pos < numTests; pos++);\r\n      if (pos == numTests)\r\n        break;\r\n      if (TestSignatureCandidate(buffer + pos))\r\n      {\r\n        memcpy(_header, buffer + pos, kHeaderSize);\r\n        curTestPos += pos;\r\n        _arhiveBeginStreamPosition = curTestPos;\r\n        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);\r\n      }\r\n    }\r\n    curTestPos += numTests;\r\n    numPrevBytes -= numTests;\r\n    memmove(buffer, buffer + numTests, numPrevBytes);\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\n// S_FALSE means that file is not archive\r\nHRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\r\n{\r\n  HeadersSize = 0;\r\n  Close();\r\n  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))\r\n  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));\r\n  _stream = stream;\r\n  return S_OK;\r\n}\r\n  \r\nvoid CInArchive::Close()\r\n{\r\n  _stream.Release();\r\n}\r\n\r\nvoid CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)\r\n{\r\n  for (;;)\r\n  {\r\n    if (ReadID() == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::GetNextFolderItem(CFolder &folder)\r\n{\r\n  CNum numCoders = ReadNum();\r\n\r\n  folder.Coders.Clear();\r\n  folder.Coders.Reserve((int)numCoders);\r\n  CNum numInStreams = 0;\r\n  CNum numOutStreams = 0;\r\n  CNum i;\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    folder.Coders.Add(CCoderInfo());\r\n    CCoderInfo &coder = folder.Coders.Back();\r\n\r\n    {\r\n      Byte mainByte = ReadByte();\r\n      int idSize = (mainByte & 0xF);\r\n      Byte longID[15];\r\n      ReadBytes(longID, idSize);\r\n      if (idSize > 8)\r\n        ThrowUnsupported();\r\n      UInt64 id = 0;\r\n      for (int j = 0; j < idSize; j++)\r\n        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);\r\n      coder.MethodID = id;\r\n\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        coder.NumInStreams = ReadNum();\r\n        coder.NumOutStreams = ReadNum();\r\n      }\r\n      else\r\n      {\r\n        coder.NumInStreams = 1;\r\n        coder.NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        CNum propsSize = ReadNum();\r\n        coder.Props.SetCapacity((size_t)propsSize);\r\n        ReadBytes((Byte *)coder.Props, (size_t)propsSize);\r\n      }\r\n      if ((mainByte & 0x80) != 0)\r\n        ThrowUnsupported();\r\n    }\r\n    numInStreams += coder.NumInStreams;\r\n    numOutStreams += coder.NumOutStreams;\r\n  }\r\n\r\n  CNum numBindPairs = numOutStreams - 1;\r\n  folder.BindPairs.Clear();\r\n  folder.BindPairs.Reserve(numBindPairs);\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair bp;\r\n    bp.InIndex = ReadNum();\r\n    bp.OutIndex = ReadNum();\r\n    folder.BindPairs.Add(bp);\r\n  }\r\n\r\n  if (numInStreams < numBindPairs)\r\n    ThrowUnsupported();\r\n  CNum numPackStreams = numInStreams - numBindPairs;\r\n  folder.PackStreams.Reserve(numPackStreams);\r\n  if (numPackStreams == 1)\r\n  {\r\n    for (i = 0; i < numInStreams; i++)\r\n      if (folder.FindBindPairForInStream(i) < 0)\r\n      {\r\n        folder.PackStreams.Add(i);\r\n        break;\r\n      }\r\n    if (folder.PackStreams.Size() != 1)\r\n      ThrowUnsupported();\r\n  }\r\n  else\r\n    for (i = 0; i < numPackStreams; i++)\r\n      folder.PackStreams.Add(ReadNum());\r\n}\r\n\r\nvoid CInArchive::WaitAttribute(UInt64 attribute)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == attribute)\r\n      return;\r\n    if (type == NID::kEnd)\r\n      ThrowIncorrect();\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadHashDigests(int numItems,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  ReadBoolVector2(numItems, digestsDefined);\r\n  digests.Clear();\r\n  digests.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 crc = 0;\r\n    if (digestsDefined[i])\r\n      crc = ReadUInt32();\r\n    digests.Add(crc);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadPackInfo(\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CBoolVector &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs)\r\n{\r\n  dataOffset = ReadNumber();\r\n  CNum numPackStreams = ReadNum();\r\n\r\n  WaitAttribute(NID::kSize);\r\n  packSizes.Clear();\r\n  packSizes.Reserve(numPackStreams);\r\n  for (CNum i = 0; i < numPackStreams; i++)\r\n    packSizes.Add(ReadNumber());\r\n\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    if (type == NID::kCRC)\r\n    {\r\n      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs);\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n  if (packCRCsDefined.IsEmpty())\r\n  {\r\n    BoolVector_Fill_False(packCRCsDefined, numPackStreams);\r\n    packCRCs.Reserve(numPackStreams);\r\n    packCRCs.Clear();\r\n    for (CNum i = 0; i < numPackStreams; i++)\r\n      packCRCs.Add(0);\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadUnpackInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    CObjectVector<CFolder> &folders)\r\n{\r\n  WaitAttribute(NID::kFolder);\r\n  CNum numFolders = ReadNum();\r\n\r\n  {\r\n    CStreamSwitch streamSwitch;\r\n    streamSwitch.Set(this, dataVector);\r\n    folders.Clear();\r\n    folders.Reserve(numFolders);\r\n    for (CNum i = 0; i < numFolders; i++)\r\n    {\r\n      folders.Add(CFolder());\r\n      GetNextFolderItem(folders.Back());\r\n    }\r\n  }\r\n\r\n  WaitAttribute(NID::kCodersUnpackSize);\r\n\r\n  CNum i;\r\n  for (i = 0; i < numFolders; i++)\r\n  {\r\n    CFolder &folder = folders[i];\r\n    CNum numOutStreams = folder.GetNumOutStreams();\r\n    folder.UnpackSizes.Reserve(numOutStreams);\r\n    for (CNum j = 0; j < numOutStreams; j++)\r\n      folder.UnpackSizes.Add(ReadNumber());\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      return;\r\n    if (type == NID::kCRC)\r\n    {\r\n      CBoolVector crcsDefined;\r\n      CRecordVector<UInt32> crcs;\r\n      ReadHashDigests(numFolders, crcsDefined, crcs);\r\n      for (i = 0; i < numFolders; i++)\r\n      {\r\n        CFolder &folder = folders[i];\r\n        folder.UnpackCRCDefined = crcsDefined[i];\r\n        folder.UnpackCRC = crcs[i];\r\n      }\r\n      continue;\r\n    }\r\n    SkeepData();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    CRecordVector<UInt64> &unpackSizes,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  numUnpackStreamsInFolders.Clear();\r\n  numUnpackStreamsInFolders.Reserve(folders.Size());\r\n  UInt64 type;\r\n  for (;;)\r\n  {\r\n    type = ReadID();\r\n    if (type == NID::kNumUnpackStream)\r\n    {\r\n      for (int i = 0; i < folders.Size(); i++)\r\n        numUnpackStreamsInFolders.Add(ReadNum());\r\n      continue;\r\n    }\r\n    if (type == NID::kCRC || type == NID::kSize)\r\n      break;\r\n    if (type == NID::kEnd)\r\n      break;\r\n    SkeepData();\r\n  }\r\n\r\n  if (numUnpackStreamsInFolders.IsEmpty())\r\n    for (int i = 0; i < folders.Size(); i++)\r\n      numUnpackStreamsInFolders.Add(1);\r\n\r\n  int i;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n  {\r\n    // v3.13 incorrectly worked with empty folders\r\n    // v4.07: we check that folder is empty\r\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    UInt64 sum = 0;\r\n    for (CNum j = 1; j < numSubstreams; j++)\r\n      if (type == NID::kSize)\r\n      {\r\n        UInt64 size = ReadNumber();\r\n        unpackSizes.Add(size);\r\n        sum += size;\r\n      }\r\n    unpackSizes.Add(folders[i].GetUnpackSize() - sum);\r\n  }\r\n  if (type == NID::kSize)\r\n    type = ReadID();\r\n\r\n  int numDigests = 0;\r\n  int numDigestsTotal = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\r\n      numDigests += numSubstreams;\r\n    numDigestsTotal += numSubstreams;\r\n  }\r\n\r\n  for (;;)\r\n  {\r\n    if (type == NID::kCRC)\r\n    {\r\n      CBoolVector digestsDefined2;\r\n      CRecordVector<UInt32> digests2;\r\n      ReadHashDigests(numDigests, digestsDefined2, digests2);\r\n      int digestIndex = 0;\r\n      for (i = 0; i < folders.Size(); i++)\r\n      {\r\n        CNum numSubstreams = numUnpackStreamsInFolders[i];\r\n        const CFolder &folder = folders[i];\r\n        if (numSubstreams == 1 && folder.UnpackCRCDefined)\r\n        {\r\n          digestsDefined.Add(true);\r\n          digests.Add(folder.UnpackCRC);\r\n        }\r\n        else\r\n          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)\r\n          {\r\n            digestsDefined.Add(digestsDefined2[digestIndex]);\r\n            digests.Add(digests2[digestIndex]);\r\n          }\r\n      }\r\n    }\r\n    else if (type == NID::kEnd)\r\n    {\r\n      if (digestsDefined.IsEmpty())\r\n      {\r\n        BoolVector_Fill_False(digestsDefined, numDigestsTotal);\r\n        digests.Clear();\r\n        for (int i = 0; i < numDigestsTotal; i++)\r\n          digests.Add(0);\r\n      }\r\n      return;\r\n    }\r\n    else\r\n      SkeepData();\r\n    type = ReadID();\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadStreamsInfo(\r\n    const CObjectVector<CByteBuffer> *dataVector,\r\n    UInt64 &dataOffset,\r\n    CRecordVector<UInt64> &packSizes,\r\n    CBoolVector &packCRCsDefined,\r\n    CRecordVector<UInt32> &packCRCs,\r\n    CObjectVector<CFolder> &folders,\r\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    CRecordVector<UInt64> &unpackSizes,\r\n    CBoolVector &digestsDefined,\r\n    CRecordVector<UInt32> &digests)\r\n{\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type > ((UInt32)1 << 30))\r\n      ThrowIncorrect();\r\n    switch((UInt32)type)\r\n    {\r\n      case NID::kEnd:\r\n        return;\r\n      case NID::kPackInfo:\r\n      {\r\n        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);\r\n        break;\r\n      }\r\n      case NID::kUnpackInfo:\r\n      {\r\n        ReadUnpackInfo(dataVector, folders);\r\n        break;\r\n      }\r\n      case NID::kSubStreamsInfo:\r\n      {\r\n        ReadSubStreamsInfo(folders, numUnpackStreamsInFolders,\r\n            unpackSizes, digestsDefined, digests);\r\n        break;\r\n      }\r\n      default:\r\n        ThrowIncorrect();\r\n    }\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector(int numItems, CBoolVector &v)\r\n{\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      b = ReadByte();\r\n      mask = 0x80;\r\n    }\r\n    v.Add((b & mask) != 0);\r\n    mask >>= 1;\r\n  }\r\n}\r\n\r\nvoid CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)\r\n{\r\n  Byte allAreDefined = ReadByte();\r\n  if (allAreDefined == 0)\r\n  {\r\n    ReadBoolVector(numItems, v);\r\n    return;\r\n  }\r\n  v.Clear();\r\n  v.Reserve(numItems);\r\n  for (int i = 0; i < numItems; i++)\r\n    v.Add(true);\r\n}\r\n\r\nvoid CInArchive::ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\r\n    CUInt64DefVector &v, int numFiles)\r\n{\r\n  ReadBoolVector2(numFiles, v.Defined);\r\n\r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, &dataVector);\r\n  v.Values.Reserve(numFiles);\r\n\r\n  for (int i = 0; i < numFiles; i++)\r\n  {\r\n    UInt64 t = 0;\r\n    if (v.Defined[i])\r\n      t = ReadUInt64();\r\n    v.Values.Add(t);\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadAndDecodePackedStreams(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    UInt64 baseOffset,\r\n    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  CRecordVector<UInt64> packSizes;\r\n  CBoolVector packCRCsDefined;\r\n  CRecordVector<UInt32> packCRCs;\r\n  CObjectVector<CFolder> folders;\r\n  \r\n  CRecordVector<CNum> numUnpackStreamsInFolders;\r\n  CRecordVector<UInt64> unpackSizes;\r\n  CBoolVector digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  ReadStreamsInfo(NULL,\r\n    dataOffset,\r\n    packSizes,\r\n    packCRCsDefined,\r\n    packCRCs,\r\n    folders,\r\n    numUnpackStreamsInFolders,\r\n    unpackSizes,\r\n    digestsDefined,\r\n    digests);\r\n  \r\n  // db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\r\n  \r\n  CNum packIndex = 0;\r\n  CDecoder decoder(\r\n    #ifdef _ST_MODE\r\n    false\r\n    #else\r\n    true\r\n    #endif\r\n    );\r\n  UInt64 dataStartPos = baseOffset + dataOffset;\r\n  for (int i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    dataVector.Add(CByteBuffer());\r\n    CByteBuffer &data = dataVector.Back();\r\n    UInt64 unpackSize64 = folder.GetUnpackSize();\r\n    size_t unpackSize = (size_t)unpackSize64;\r\n    if (unpackSize != unpackSize64)\r\n      ThrowUnsupported();\r\n    data.SetCapacity(unpackSize);\r\n    \r\n    CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    outStreamSpec->Init(data, unpackSize);\r\n    \r\n    HRESULT result = decoder.Decode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      _stream, dataStartPos,\r\n      &packSizes[packIndex], folder, outStream, NULL\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, passwordIsDefined\r\n      #endif\r\n      #ifdef COMPRESS_MT\r\n      , false, 1\r\n      #endif\r\n      );\r\n    RINOK(result);\r\n    \r\n    if (folder.UnpackCRCDefined)\r\n      if (CrcCalc(data, unpackSize) != folder.UnpackCRC)\r\n        ThrowIncorrect();\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      UInt64 packSize = packSizes[packIndex++];\r\n      dataStartPos += packSize;\r\n      HeadersSize += packSize;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CInArchive::ReadHeader(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  UInt64 type = ReadID();\r\n\r\n  if (type == NID::kArchiveProperties)\r\n  {\r\n    ReadArchiveProperties(db.ArchiveInfo);\r\n    type = ReadID();\r\n  }\r\n \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  if (type == NID::kAdditionalStreamsInfo)\r\n  {\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        db.ArchiveInfo.StartPositionAfterHeader,\r\n        db.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword, passwordIsDefined\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n\r\n  CRecordVector<UInt64> unpackSizes;\r\n  CBoolVector digestsDefined;\r\n  CRecordVector<UInt32> digests;\r\n  \r\n  if (type == NID::kMainStreamsInfo)\r\n  {\r\n    ReadStreamsInfo(&dataVector,\r\n        db.ArchiveInfo.DataStartPosition,\r\n        db.PackSizes,\r\n        db.PackCRCsDefined,\r\n        db.PackCRCs,\r\n        db.Folders,\r\n        db.NumUnpackStreamsVector,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    db.ArchiveInfo.DataStartPosition += db.ArchiveInfo.StartPositionAfterHeader;\r\n    type = ReadID();\r\n  }\r\n  else\r\n  {\r\n    for (int i = 0; i < db.Folders.Size(); i++)\r\n    {\r\n      db.NumUnpackStreamsVector.Add(1);\r\n      CFolder &folder = db.Folders[i];\r\n      unpackSizes.Add(folder.GetUnpackSize());\r\n      digestsDefined.Add(folder.UnpackCRCDefined);\r\n      digests.Add(folder.UnpackCRC);\r\n    }\r\n  }\r\n\r\n  db.Files.Clear();\r\n\r\n  if (type == NID::kEnd)\r\n    return S_OK;\r\n  if (type != NID::kFilesInfo)\r\n    ThrowIncorrect();\r\n  \r\n  CNum numFiles = ReadNum();\r\n  db.Files.Reserve(numFiles);\r\n  CNum i;\r\n  for (i = 0; i < numFiles; i++)\r\n    db.Files.Add(CFileItem());\r\n\r\n  db.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);\r\n  if (!db.PackSizes.IsEmpty())\r\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);\r\n  if (numFiles > 0  && !digests.IsEmpty())\r\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);\r\n\r\n  CBoolVector emptyStreamVector;\r\n  BoolVector_Fill_False(emptyStreamVector, (int)numFiles);\r\n  CBoolVector emptyFileVector;\r\n  CBoolVector antiFileVector;\r\n  CNum numEmptyStreams = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt64 type = ReadID();\r\n    if (type == NID::kEnd)\r\n      break;\r\n    UInt64 size = ReadNumber();\r\n    size_t ppp = _inByteBack->_pos;\r\n    bool addPropIdToList = true;\r\n    bool isKnownType = true;\r\n    if (type > ((UInt32)1 << 30))\r\n      isKnownType = false;\r\n    else switch((UInt32)type)\r\n    {\r\n      case NID::kName:\r\n      {\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for (int i = 0; i < db.Files.Size(); i++)\r\n          _inByteBack->ReadString(db.Files[i].Name);\r\n        break;\r\n      }\r\n      case NID::kWinAttributes:\r\n      {\r\n        CBoolVector boolVector;\r\n        ReadBoolVector2(db.Files.Size(), boolVector);\r\n        CStreamSwitch streamSwitch;\r\n        streamSwitch.Set(this, &dataVector);\r\n        for (i = 0; i < numFiles; i++)\r\n        {\r\n          CFileItem &file = db.Files[i];\r\n          file.AttribDefined = boolVector[i];\r\n          if (file.AttribDefined)\r\n            file.Attrib = ReadUInt32();\r\n        }\r\n        break;\r\n      }\r\n      case NID::kEmptyStream:\r\n      {\r\n        ReadBoolVector(numFiles, emptyStreamVector);\r\n        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)\r\n          if (emptyStreamVector[i])\r\n            numEmptyStreams++;\r\n\r\n        BoolVector_Fill_False(emptyFileVector, numEmptyStreams);\r\n        BoolVector_Fill_False(antiFileVector, numEmptyStreams);\r\n\r\n        break;\r\n      }\r\n      case NID::kEmptyFile:  ReadBoolVector(numEmptyStreams, emptyFileVector); break;\r\n      case NID::kAnti:  ReadBoolVector(numEmptyStreams, antiFileVector); break;\r\n      case NID::kStartPos:  ReadUInt64DefVector(dataVector, db.StartPos, (int)numFiles); break;\r\n      case NID::kCTime:  ReadUInt64DefVector(dataVector, db.CTime, (int)numFiles); break;\r\n      case NID::kATime:  ReadUInt64DefVector(dataVector, db.ATime, (int)numFiles); break;\r\n      case NID::kMTime:  ReadUInt64DefVector(dataVector, db.MTime, (int)numFiles); break;\r\n      case NID::kDummy:\r\n      {\r\n        for (UInt64 j = 0; j < size; j++)\r\n          if (ReadByte() != 0)\r\n            ThrowIncorrect();\r\n        addPropIdToList = false;\r\n        break;\r\n      }\r\n      default:\r\n        addPropIdToList = isKnownType = false;\r\n    }\r\n    if (isKnownType)\r\n    {\r\n      if(addPropIdToList)\r\n        db.ArchiveInfo.FileInfoPopIDs.Add(type);\r\n    }\r\n    else\r\n      SkeepData(size);\r\n    bool checkRecordsSize = (db.ArchiveInfo.Version.Major > 0 ||\r\n        db.ArchiveInfo.Version.Minor > 2);\r\n    if (checkRecordsSize && _inByteBack->_pos - ppp != size)\r\n      ThrowIncorrect();\r\n  }\r\n\r\n  CNum emptyFileIndex = 0;\r\n  CNum sizeIndex = 0;\r\n\r\n  CNum numAntiItems = 0;\r\n  for (i = 0; i < numEmptyStreams; i++)\r\n    if (antiFileVector[i])\r\n      numAntiItems++;\r\n    \r\n  for (i = 0; i < numFiles; i++)\r\n  {\r\n    CFileItem &file = db.Files[i];\r\n    bool isAnti;\r\n    file.HasStream = !emptyStreamVector[i];\r\n    if (file.HasStream)\r\n    {\r\n      file.IsDir = false;\r\n      isAnti = false;\r\n      file.Size = unpackSizes[sizeIndex];\r\n      file.Crc = digests[sizeIndex];\r\n      file.CrcDefined = digestsDefined[sizeIndex];\r\n      sizeIndex++;\r\n    }\r\n    else\r\n    {\r\n      file.IsDir = !emptyFileVector[emptyFileIndex];\r\n      isAnti = antiFileVector[emptyFileIndex];\r\n      emptyFileIndex++;\r\n      file.Size = 0;\r\n      file.CrcDefined = false;\r\n    }\r\n    if (numAntiItems != 0)\r\n      db.IsAnti.Add(isAnti);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartPackStream()\r\n{\r\n  FolderStartPackStreamIndex.Clear();\r\n  FolderStartPackStreamIndex.Reserve(Folders.Size());\r\n  CNum startPos = 0;\r\n  for (int i = 0; i < Folders.Size(); i++)\r\n  {\r\n    FolderStartPackStreamIndex.Add(startPos);\r\n    startPos += (CNum)Folders[i].PackStreams.Size();\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillStartPos()\r\n{\r\n  PackStreamStartPositions.Clear();\r\n  PackStreamStartPositions.Reserve(PackSizes.Size());\r\n  UInt64 startPos = 0;\r\n  for (int i = 0; i < PackSizes.Size(); i++)\r\n  {\r\n    PackStreamStartPositions.Add(startPos);\r\n    startPos += PackSizes[i];\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabaseEx::FillFolderStartFileIndex()\r\n{\r\n  FolderStartFileIndex.Clear();\r\n  FolderStartFileIndex.Reserve(Folders.Size());\r\n  FileIndexToFolderIndexMap.Clear();\r\n  FileIndexToFolderIndexMap.Reserve(Files.Size());\r\n  \r\n  int folderIndex = 0;\r\n  CNum indexInFolder = 0;\r\n  for (int i = 0; i < Files.Size(); i++)\r\n  {\r\n    const CFileItem &file = Files[i];\r\n    bool emptyStream = !file.HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      FileIndexToFolderIndexMap.Add(kNumNoIndex);\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      // v3.13 incorrectly worked with empty folders\r\n      // v4.07: Loop for skipping empty folders\r\n      for (;;)\r\n      {\r\n        if (folderIndex >= Folders.Size())\r\n          ThrowIncorrect();\r\n        FolderStartFileIndex.Add(i); // check it\r\n        if (NumUnpackStreamsVector[folderIndex] != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    FileIndexToFolderIndexMap.Add(folderIndex);\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= NumUnpackStreamsVector[folderIndex])\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n\r\n  db.ArchiveInfo.Version.Major = _header[6];\r\n  db.ArchiveInfo.Version.Minor = _header[7];\r\n\r\n  if (db.ArchiveInfo.Version.Major != kMajorVersion)\r\n    ThrowUnsupportedVersion();\r\n\r\n  UInt32 crcFromArchive = Get32(_header + 8);\r\n  UInt64 nextHeaderOffset = Get64(_header + 0xC);\r\n  UInt64 nextHeaderSize = Get64(_header + 0x14);\r\n  UInt32 nextHeaderCRC = Get32(_header + 0x1C);\r\n  UInt32 crc = CrcCalc(_header + 0xC, 20);\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)\r\n  {\r\n    UInt64 cur, cur2;\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));\r\n    const int kCheckSize = 500;\r\n    Byte buf[kCheckSize];\r\n    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));\r\n    int checkSize = kCheckSize;\r\n    if (cur2 - cur < kCheckSize)\r\n      checkSize = (int)(cur2 - cur);\r\n    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));\r\n    \r\n    RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));\r\n\r\n    int i;\r\n    for (i = (int)checkSize - 2; i >= 0; i--)\r\n      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)\r\n        break;\r\n    if (i < 0)\r\n      return S_FALSE;\r\n    nextHeaderSize = checkSize - i;\r\n    nextHeaderOffset = cur2 - cur + i;\r\n    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);\r\n    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));\r\n  }\r\n  #endif\r\n\r\n  #ifdef FORMAT_7Z_RECOVERY\r\n  crcFromArchive = crc;\r\n  #endif\r\n\r\n  db.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;\r\n\r\n  if (crc != crcFromArchive)\r\n    ThrowIncorrect();\r\n\r\n  if (nextHeaderSize == 0)\r\n    return S_OK;\r\n\r\n  if (nextHeaderSize > (UInt64)0xFFFFFFFF)\r\n    return S_FALSE;\r\n\r\n  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));\r\n\r\n  CByteBuffer buffer2;\r\n  buffer2.SetCapacity((size_t)nextHeaderSize);\r\n\r\n  RINOK(ReadStream_FALSE(_stream, buffer2, (size_t)nextHeaderSize));\r\n  HeadersSize += kHeaderSize + nextHeaderSize;\r\n  db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;\r\n\r\n  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)\r\n    ThrowIncorrect();\r\n  \r\n  CStreamSwitch streamSwitch;\r\n  streamSwitch.Set(this, buffer2);\r\n  \r\n  CObjectVector<CByteBuffer> dataVector;\r\n  \r\n  UInt64 type = ReadID();\r\n  if (type != NID::kHeader)\r\n  {\r\n    if (type != NID::kEncodedHeader)\r\n      ThrowIncorrect();\r\n    HRESULT result = ReadAndDecodePackedStreams(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        db.ArchiveInfo.StartPositionAfterHeader,\r\n        db.ArchiveInfo.DataStartPosition2,\r\n        dataVector\r\n        #ifndef _NO_CRYPTO\r\n        , getTextPassword, passwordIsDefined\r\n        #endif\r\n        );\r\n    RINOK(result);\r\n    if (dataVector.Size() == 0)\r\n      return S_OK;\r\n    if (dataVector.Size() > 1)\r\n      ThrowIncorrect();\r\n    streamSwitch.Remove();\r\n    streamSwitch.Set(this, dataVector.Front());\r\n    if (ReadID() != NID::kHeader)\r\n      ThrowIncorrect();\r\n  }\r\n\r\n  db.HeadersSize = HeadersSize;\r\n\r\n  return ReadHeader(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    db\r\n    #ifndef _NO_CRYPTO\r\n    , getTextPassword, passwordIsDefined\r\n    #endif\r\n    );\r\n}\r\n\r\nHRESULT CInArchive::ReadDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CArchiveDatabaseEx &db\r\n    #ifndef _NO_CRYPTO\r\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n    #endif\r\n    )\r\n{\r\n  try\r\n  {\r\n    return ReadDatabase2(\r\n      EXTERNAL_CODECS_LOC_VARS db\r\n      #ifndef _NO_CRYPTO\r\n      , getTextPassword, passwordIsDefined\r\n      #endif\r\n      );\r\n  }\r\n  catch(CInArchiveException &) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zIn.h",
    "content": "// 7zIn.h\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../IStream.h\"\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n#include \"../../Common/InBuffer.h\"\r\n\r\n#include \"7zItem.h\"\r\n \r\nnamespace NArchive {\r\nnamespace N7z {\r\n  \r\nstruct CInArchiveInfo\r\n{\r\n  CArchiveVersion Version;\r\n  UInt64 StartPosition;\r\n  UInt64 StartPositionAfterHeader;\r\n  UInt64 DataStartPosition;\r\n  UInt64 DataStartPosition2;\r\n  CRecordVector<UInt64> FileInfoPopIDs;\r\n  void Clear()\r\n  {\r\n    FileInfoPopIDs.Clear();\r\n  }\r\n};\r\n\r\nstruct CArchiveDatabaseEx: public CArchiveDatabase\r\n{\r\n  CInArchiveInfo ArchiveInfo;\r\n  CRecordVector<UInt64> PackStreamStartPositions;\r\n  CRecordVector<CNum> FolderStartPackStreamIndex;\r\n  CRecordVector<CNum> FolderStartFileIndex;\r\n  CRecordVector<CNum> FileIndexToFolderIndexMap;\r\n\r\n  UInt64 HeadersSize;\r\n  UInt64 PhySize;\r\n\r\n  void Clear()\r\n  {\r\n    CArchiveDatabase::Clear();\r\n    ArchiveInfo.Clear();\r\n    PackStreamStartPositions.Clear();\r\n    FolderStartPackStreamIndex.Clear();\r\n    FolderStartFileIndex.Clear();\r\n    FileIndexToFolderIndexMap.Clear();\r\n\r\n    HeadersSize = 0;\r\n    PhySize = 0;\r\n  }\r\n\r\n  void FillFolderStartPackStream();\r\n  void FillStartPos();\r\n  void FillFolderStartFileIndex();\r\n\r\n  void Fill()\r\n  {\r\n    FillFolderStartPackStream();\r\n    FillStartPos();\r\n    FillFolderStartFileIndex();\r\n  }\r\n  \r\n  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const\r\n  {\r\n    return ArchiveInfo.DataStartPosition +\r\n        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n  }\r\n  \r\n  UInt64 GetFolderFullPackSize(int folderIndex) const\r\n  {\r\n    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];\r\n    const CFolder &folder = Folders[folderIndex];\r\n    UInt64 size = 0;\r\n    for (int i = 0; i < folder.PackStreams.Size(); i++)\r\n      size += PackSizes[packStreamIndex + i];\r\n    return size;\r\n  }\r\n  \r\n  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\r\n  {\r\n    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n  }\r\n\r\n  UInt64 GetFilePackSize(CNum fileIndex) const\r\n  {\r\n    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n    if (folderIndex != kNumNoIndex)\r\n      if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n        return GetFolderFullPackSize(folderIndex);\r\n    return 0;\r\n  }\r\n};\r\n\r\nclass CInByte2\r\n{\r\n  const Byte *_buffer;\r\n  size_t _size;\r\npublic:\r\n  size_t _pos;\r\n  void Init(const Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  Byte ReadByte();\r\n  void ReadBytes(Byte *data, size_t size);\r\n  void SkeepData(UInt64 size);\r\n  void SkeepData();\r\n  UInt64 ReadNumber();\r\n  CNum ReadNum();\r\n  UInt32 ReadUInt32();\r\n  UInt64 ReadUInt64();\r\n  void ReadString(UString &s);\r\n};\r\n\r\nclass CStreamSwitch;\r\n\r\nconst UInt32 kHeaderSize = 32;\r\n\r\nclass CInArchive\r\n{\r\n  friend class CStreamSwitch;\r\n\r\n  CMyComPtr<IInStream> _stream;\r\n\r\n  CObjectVector<CInByte2> _inByteVector;\r\n  CInByte2 *_inByteBack;\r\n \r\n  UInt64 _arhiveBeginStreamPosition;\r\n\r\n  Byte _header[kHeaderSize];\r\n\r\n  UInt64 HeadersSize;\r\n\r\n  void AddByteStream(const Byte *buffer, size_t size)\r\n  {\r\n    _inByteVector.Add(CInByte2());\r\n    _inByteBack = &_inByteVector.Back();\r\n    _inByteBack->Init(buffer, size);\r\n  }\r\n  \r\n  void DeleteByteStream()\r\n  {\r\n    _inByteVector.DeleteBack();\r\n    if (!_inByteVector.IsEmpty())\r\n      _inByteBack = &_inByteVector.Back();\r\n  }\r\n\r\nprivate:\r\n  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);\r\n  \r\n  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }\r\n  Byte ReadByte() { return _inByteBack->ReadByte(); }\r\n  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }\r\n  CNum ReadNum() { return _inByteBack->ReadNum(); }\r\n  UInt64 ReadID() { return _inByteBack->ReadNumber(); }\r\n  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }\r\n  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }\r\n  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }\r\n  void SkeepData() { _inByteBack->SkeepData(); }\r\n  void WaitAttribute(UInt64 attribute);\r\n\r\n  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);\r\n  void GetNextFolderItem(CFolder &itemInfo);\r\n  void ReadHashDigests(int numItems,\r\n      CBoolVector &digestsDefined, CRecordVector<UInt32> &digests);\r\n  \r\n  void ReadPackInfo(\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CBoolVector &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs);\r\n  \r\n  void ReadUnpackInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      CObjectVector<CFolder> &folders);\r\n  \r\n  void ReadSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      CRecordVector<UInt64> &unpackSizes,\r\n      CBoolVector &digestsDefined,\r\n      CRecordVector<UInt32> &digests);\r\n\r\n  void ReadStreamsInfo(\r\n      const CObjectVector<CByteBuffer> *dataVector,\r\n      UInt64 &dataOffset,\r\n      CRecordVector<UInt64> &packSizes,\r\n      CBoolVector &packCRCsDefined,\r\n      CRecordVector<UInt32> &packCRCs,\r\n      CObjectVector<CFolder> &folders,\r\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      CRecordVector<UInt64> &unpackSizes,\r\n      CBoolVector &digestsDefined,\r\n      CRecordVector<UInt32> &digests);\r\n\r\n\r\n  void ReadBoolVector(int numItems, CBoolVector &v);\r\n  void ReadBoolVector2(int numItems, CBoolVector &v);\r\n  void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\r\n      CUInt64DefVector &v, int numFiles);\r\n  HRESULT ReadAndDecodePackedStreams(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      UInt64 baseOffset, UInt64 &dataOffset,\r\n      CObjectVector<CByteBuffer> &dataVector\r\n      #ifndef _NO_CRYPTO\r\n      , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n  HRESULT ReadHeader(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n  HRESULT ReadDatabase2(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\npublic:\r\n  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive\r\n  void Close();\r\n\r\n  HRESULT ReadDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CArchiveDatabaseEx &db\r\n      #ifndef _NO_CRYPTO\r\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\r\n      #endif\r\n      );\r\n};\r\n  \r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zItem.h",
    "content": "// 7zItem.h\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../../Common/MyString.h\"\r\n\r\n#include \"../../Common/MethodId.h\"\r\n\r\n#include \"7zHeader.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\ntypedef UInt32 CNum;\r\nconst CNum kNumMax     = 0x7FFFFFFF;\r\nconst CNum kNumNoIndex = 0xFFFFFFFF;\r\n\r\nstruct CCoderInfo\r\n{\r\n  CMethodId MethodID;\r\n  CByteBuffer Props;\r\n  CNum NumInStreams;\r\n  CNum NumOutStreams;\r\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\r\n};\r\n\r\nstruct CBindPair\r\n{\r\n  CNum InIndex;\r\n  CNum OutIndex;\r\n};\r\n\r\nstruct CFolder\r\n{\r\n  CObjectVector<CCoderInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<CNum> PackStreams;\r\n  CRecordVector<UInt64> UnpackSizes;\r\n  UInt32 UnpackCRC;\r\n  bool UnpackCRCDefined;\r\n\r\n  CFolder(): UnpackCRCDefined(false) {}\r\n\r\n  UInt64 GetUnpackSize() const // test it\r\n  {\r\n    if (UnpackSizes.IsEmpty())\r\n      return 0;\r\n    for (int i = UnpackSizes.Size() - 1; i >= 0; i--)\r\n      if (FindBindPairForOutStream(i) < 0)\r\n        return UnpackSizes[i];\r\n    throw 1;\r\n  }\r\n\r\n  CNum GetNumOutStreams() const\r\n  {\r\n    CNum result = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n      result += Coders[i].NumOutStreams;\r\n    return result;\r\n  }\r\n\r\n  int FindBindPairForInStream(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBindPairForOutStream(CNum outStreamIndex) const\r\n  {\r\n    for(int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindPackStreamArrayIndex(CNum inStreamIndex) const\r\n  {\r\n    for(int i = 0; i < PackStreams.Size(); i++)\r\n      if (PackStreams[i] == inStreamIndex)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  bool CheckStructure() const;\r\n};\r\n\r\nstruct CUInt64DefVector\r\n{\r\n  CRecordVector<UInt64> Values;\r\n  CRecordVector<bool> Defined;\r\n  \r\n  void Clear()\r\n  {\r\n    Values.Clear();\r\n    Defined.Clear();\r\n  }\r\n  \r\n  void ReserveDown()\r\n  {\r\n    Values.ReserveDown();\r\n    Values.ReserveDown();\r\n  }\r\n\r\n  bool GetItem(int index, UInt64 &value) const\r\n  {\r\n    if (index < Defined.Size() && Defined[index])\r\n    {\r\n      value = Values[index];\r\n      return true;\r\n    }\r\n    value = 0;\r\n    return false;\r\n  }\r\n  \r\n  void SetItem(int index, bool defined, UInt64 value)\r\n  {\r\n    while (index >= Defined.Size())\r\n      Defined.Add(false);\r\n    Defined[index] = defined;\r\n    if (!defined)\r\n      return;\r\n    while (index >= Values.Size())\r\n      Values.Add(0);\r\n    Values[index] = value;\r\n  }\r\n\r\n  bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }\r\n};\r\n\r\nstruct CFileItem\r\n{\r\n  UInt64 Size;\r\n  UInt32 Attrib;\r\n  UInt32 Crc;\r\n  UString Name;\r\n\r\n  bool HasStream; // Test it !!! it means that there is\r\n                  // stream in some folder. It can be empty stream\r\n  bool IsDir;\r\n  bool CrcDefined;\r\n  bool AttribDefined;\r\n\r\n  CFileItem():\r\n    HasStream(true),\r\n    IsDir(false),\r\n    CrcDefined(false),\r\n    AttribDefined(false)\r\n      {}\r\n  void SetAttrib(UInt32 attrib)\r\n  {\r\n    AttribDefined = true;\r\n    Attrib = attrib;\r\n  }\r\n};\r\n\r\nstruct CFileItem2\r\n{\r\n  UInt64 CTime;\r\n  UInt64 ATime;\r\n  UInt64 MTime;\r\n  UInt64 StartPos;\r\n  bool CTimeDefined;\r\n  bool ATimeDefined;\r\n  bool MTimeDefined;\r\n  bool StartPosDefined;\r\n  bool IsAnti;\r\n};\r\n\r\nstruct CArchiveDatabase\r\n{\r\n  CRecordVector<UInt64> PackSizes;\r\n  CRecordVector<bool> PackCRCsDefined;\r\n  CRecordVector<UInt32> PackCRCs;\r\n  CObjectVector<CFolder> Folders;\r\n  CRecordVector<CNum> NumUnpackStreamsVector;\r\n  CObjectVector<CFileItem> Files;\r\n\r\n  CUInt64DefVector CTime;\r\n  CUInt64DefVector ATime;\r\n  CUInt64DefVector MTime;\r\n  CUInt64DefVector StartPos;\r\n  CRecordVector<bool> IsAnti;\r\n\r\n  void Clear()\r\n  {\r\n    PackSizes.Clear();\r\n    PackCRCsDefined.Clear();\r\n    PackCRCs.Clear();\r\n    Folders.Clear();\r\n    NumUnpackStreamsVector.Clear();\r\n    Files.Clear();\r\n    CTime.Clear();\r\n    ATime.Clear();\r\n    MTime.Clear();\r\n    StartPos.Clear();\r\n    IsAnti.Clear();\r\n  }\r\n\r\n  void ReserveDown()\r\n  {\r\n    PackSizes.ReserveDown();\r\n    PackCRCsDefined.ReserveDown();\r\n    PackCRCs.ReserveDown();\r\n    Folders.ReserveDown();\r\n    NumUnpackStreamsVector.ReserveDown();\r\n    Files.ReserveDown();\r\n    CTime.ReserveDown();\r\n    ATime.ReserveDown();\r\n    MTime.ReserveDown();\r\n    StartPos.ReserveDown();\r\n    IsAnti.ReserveDown();\r\n  }\r\n\r\n  bool IsEmpty() const\r\n  {\r\n    return (PackSizes.IsEmpty() &&\r\n      PackCRCsDefined.IsEmpty() &&\r\n      PackCRCs.IsEmpty() &&\r\n      Folders.IsEmpty() &&\r\n      NumUnpackStreamsVector.IsEmpty() &&\r\n      Files.IsEmpty());\r\n  }\r\n\r\n  bool CheckNumFiles() const\r\n  {\r\n    int size = Files.Size();\r\n    return (\r\n      CTime.CheckSize(size) &&\r\n      ATime.CheckSize(size) &&\r\n      MTime.CheckSize(size) &&\r\n      StartPos.CheckSize(size) &&\r\n      (size == IsAnti.Size() || IsAnti.Size() == 0));\r\n  }\r\n\r\n  bool IsSolid() const\r\n  {\r\n    for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)\r\n      if (NumUnpackStreamsVector[i] > 1)\r\n        return true;\r\n    return false;\r\n  }\r\n  bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }\r\n  void SetItemAnti(int index, bool isAnti)\r\n  {\r\n    while (index >= IsAnti.Size())\r\n      IsAnti.Add(false);\r\n    IsAnti[index] = isAnti;\r\n  }\r\n\r\n  void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;\r\n  void AddFile(const CFileItem &file, const CFileItem2 &file2);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zOut.cpp",
    "content": "// 7zOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/AutoPtr.h\"\r\n#include \"../../Common/StreamObjects.h\"\r\n\r\n#include \"7zOut.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nstatic HRESULT WriteBytes(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size > 0)\r\n  {\r\n    UInt32 curSize = (UInt32)MyMin(size, (size_t)0xFFFFFFFF);\r\n    UInt32 processedSize;\r\n    RINOK(stream->Write(data, curSize, &processedSize));\r\n    if (processedSize == 0)\r\n      return E_FAIL;\r\n    data = (const void *)((const Byte *)data + processedSize);\r\n    size -= processedSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nHRESULT COutArchive::WriteDirect(const void *data, UInt32 size)\r\n{\r\n  return ::WriteBytes(SeqStream, data, size);\r\n}\r\n\r\nHRESULT COutArchive::WriteSignature()\r\n{\r\n  Byte buf[8];\r\n  memcpy(buf, kSignature, kSignatureSize);\r\n  buf[kSignatureSize] = kMajorVersion;\r\n  buf[kSignatureSize + 1] = 3;\r\n  return WriteDirect(buf, 8);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishSignature()\r\n{\r\n  RINOK(WriteDirect(kFinishSignature, kSignatureSize));\r\n  CArchiveVersion av;\r\n  av.Major = kMajorVersion;\r\n  av.Minor = 2;\r\n  RINOK(WriteDirectByte(av.Major));\r\n  return WriteDirectByte(av.Minor);\r\n}\r\n#endif\r\n\r\nstatic void SetUInt32(Byte *p, UInt32 d)\r\n{\r\n  for (int i = 0; i < 4; i++, d >>= 8)\r\n    p[i] = (Byte)d;\r\n}\r\n\r\nstatic void SetUInt64(Byte *p, UInt64 d)\r\n{\r\n  for (int i = 0; i < 8; i++, d >>= 8)\r\n    p[i] = (Byte)d;\r\n}\r\n\r\nHRESULT COutArchive::WriteStartHeader(const CStartHeader &h)\r\n{\r\n  Byte buf[24];\r\n  SetUInt64(buf + 4, h.NextHeaderOffset);\r\n  SetUInt64(buf + 12, h.NextHeaderSize);\r\n  SetUInt32(buf + 20, h.NextHeaderCRC);\r\n  SetUInt32(buf, CrcCalc(buf + 4, 20));\r\n  return WriteDirect(buf, 24);\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nHRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)\r\n{\r\n  CCRC crc;\r\n  crc.UpdateUInt64(h.NextHeaderOffset);\r\n  crc.UpdateUInt64(h.NextHeaderSize);\r\n  crc.UpdateUInt32(h.NextHeaderCRC);\r\n  crc.UpdateUInt64(h.ArchiveStartOffset);\r\n  crc.UpdateUInt64(h.AdditionalStartBlockSize);\r\n  RINOK(WriteDirectUInt32(crc.GetDigest()));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\r\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\r\n  RINOK(WriteDirectUInt32(h.NextHeaderCRC));\r\n  RINOK(WriteDirectUInt64(h.ArchiveStartOffset));\r\n  return WriteDirectUInt64(h.AdditionalStartBlockSize);\r\n}\r\n#endif\r\n\r\nHRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)\r\n{\r\n  Close();\r\n  #ifdef _7Z_VOL\r\n  // endMarker = false;\r\n  _endMarker = endMarker;\r\n  #endif\r\n  SeqStream = stream;\r\n  if (!endMarker)\r\n  {\r\n    SeqStream.QueryInterface(IID_IOutStream, &Stream);\r\n    if (!Stream)\r\n    {\r\n      return E_NOTIMPL;\r\n      // endMarker = true;\r\n    }\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (endMarker)\r\n  {\r\n    /*\r\n    CStartHeader sh;\r\n    sh.NextHeaderOffset = (UInt32)(Int32)-1;\r\n    sh.NextHeaderSize = (UInt32)(Int32)-1;\r\n    sh.NextHeaderCRC = 0;\r\n    WriteStartHeader(sh);\r\n    */\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    if (!Stream)\r\n      return E_FAIL;\r\n    RINOK(WriteSignature());\r\n    RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutArchive::Close()\r\n{\r\n  SeqStream.Release();\r\n  Stream.Release();\r\n}\r\n\r\nHRESULT COutArchive::SkeepPrefixArchiveHeader()\r\n{\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n    return S_OK;\r\n  #endif\r\n  return Stream->Seek(24, STREAM_SEEK_CUR, NULL);\r\n}\r\n\r\nUInt64 COutArchive::GetPos() const\r\n{\r\n  if (_countMode)\r\n    return _countSize;\r\n  if (_writeToStream)\r\n    return _outByte.GetProcessedSize();\r\n  return _outByte2.GetPos();\r\n}\r\n\r\nvoid COutArchive::WriteBytes(const void *data, size_t size)\r\n{\r\n  if (_countMode)\r\n    _countSize += size;\r\n  else if (_writeToStream)\r\n  {\r\n    _outByte.WriteBytes(data, size);\r\n    _crc = CrcUpdate(_crc, data, size);\r\n  }\r\n  else\r\n    _outByte2.WriteBytes(data, size);\r\n}\r\n\r\nvoid COutArchive::WriteByte(Byte b)\r\n{\r\n  if (_countMode)\r\n    _countSize++;\r\n  else if (_writeToStream)\r\n  {\r\n    _outByte.WriteByte(b);\r\n    _crc = CRC_UPDATE_BYTE(_crc, b);\r\n  }\r\n  else\r\n    _outByte2.WriteByte(b);\r\n}\r\n\r\nvoid COutArchive::WriteUInt32(UInt32 value)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nvoid COutArchive::WriteUInt64(UInt64 value)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nvoid COutArchive::WriteNumber(UInt64 value)\r\n{\r\n  Byte firstByte = 0;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\r\n    {\r\n      firstByte |= Byte(value >> (8 * i));\r\n      break;\r\n    }\r\n    firstByte |= mask;\r\n    mask >>= 1;\r\n  }\r\n  WriteByte(firstByte);\r\n  for (;i > 0; i--)\r\n  {\r\n    WriteByte((Byte)value);\r\n    value >>= 8;\r\n  }\r\n}\r\n\r\nstatic UInt32 GetBigNumberSize(UInt64 value)\r\n{\r\n  int i;\r\n  for (i = 1; i < 9; i++)\r\n    if (value < (((UInt64)1 << (i * 7))))\r\n      break;\r\n  return i;\r\n}\r\n\r\n#ifdef _7Z_VOL\r\nUInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)\r\n{\r\n  UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;\r\n  if (nameLength != 0)\r\n  {\r\n    nameLength = (nameLength + 1) * 2;\r\n    result += nameLength + GetBigNumberSize(nameLength) + 2;\r\n  }\r\n  if (props)\r\n  {\r\n    result += 20;\r\n  }\r\n  if (result >= 128)\r\n    result++;\r\n  result += kSignatureSize + 2 + kFinishHeaderSize;\r\n  return result;\r\n}\r\n\r\nUInt64 COutArchive::GetVolPureSize(UInt64 volSize, int nameLength, bool props)\r\n{\r\n  UInt32 headersSizeBase = COutArchive::GetVolHeadersSize(1, nameLength, props);\r\n  int testSize;\r\n  if (volSize > headersSizeBase)\r\n    testSize = volSize - headersSizeBase;\r\n  else\r\n    testSize = 1;\r\n  UInt32 headersSize = COutArchive::GetVolHeadersSize(testSize, nameLength, props);\r\n  UInt64 pureSize = 1;\r\n  if (volSize > headersSize)\r\n    pureSize = volSize - headersSize;\r\n  return pureSize;\r\n}\r\n#endif\r\n\r\nvoid COutArchive::WriteFolder(const CFolder &folder)\r\n{\r\n  WriteNumber(folder.Coders.Size());\r\n  int i;\r\n  for (i = 0; i < folder.Coders.Size(); i++)\r\n  {\r\n    const CCoderInfo &coder = folder.Coders[i];\r\n    {\r\n      size_t propsSize = coder.Props.GetCapacity();\r\n      \r\n      UInt64 id = coder.MethodID;\r\n      int idSize;\r\n      for (idSize = 1; idSize < sizeof(id); idSize++)\r\n        if ((id >> (8 * idSize)) == 0)\r\n          break;\r\n      BYTE longID[15];\r\n      for (int t = idSize - 1; t >= 0 ; t--, id >>= 8)\r\n        longID[t] = (Byte)(id & 0xFF);\r\n      Byte b;\r\n      b = (Byte)(idSize & 0xF);\r\n      bool isComplex = !coder.IsSimpleCoder();\r\n      b |= (isComplex ? 0x10 : 0);\r\n      b |= ((propsSize != 0) ? 0x20 : 0 );\r\n      WriteByte(b);\r\n      WriteBytes(longID, idSize);\r\n      if (isComplex)\r\n      {\r\n        WriteNumber(coder.NumInStreams);\r\n        WriteNumber(coder.NumOutStreams);\r\n      }\r\n      if (propsSize == 0)\r\n        continue;\r\n      WriteNumber(propsSize);\r\n      WriteBytes(coder.Props, propsSize);\r\n    }\r\n  }\r\n  for (i = 0; i < folder.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = folder.BindPairs[i];\r\n    WriteNumber(bindPair.InIndex);\r\n    WriteNumber(bindPair.OutIndex);\r\n  }\r\n  if (folder.PackStreams.Size() > 1)\r\n    for (i = 0; i < folder.PackStreams.Size(); i++)\r\n    {\r\n      WriteNumber(folder.PackStreams[i]);\r\n    }\r\n}\r\n\r\nvoid COutArchive::WriteBoolVector(const CBoolVector &boolVector)\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0x80;\r\n  for (int i = 0; i < boolVector.Size(); i++)\r\n  {\r\n    if (boolVector[i])\r\n      b |= mask;\r\n    mask >>= 1;\r\n    if (mask == 0)\r\n    {\r\n      WriteByte(b);\r\n      mask = 0x80;\r\n      b = 0;\r\n    }\r\n  }\r\n  if (mask != 0x80)\r\n    WriteByte(b);\r\n}\r\n\r\n\r\nvoid COutArchive::WriteHashDigests(\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  int numDefined = 0;\r\n  int i;\r\n  for (i = 0; i < digestsDefined.Size(); i++)\r\n    if (digestsDefined[i])\r\n      numDefined++;\r\n  if (numDefined == 0)\r\n    return;\r\n\r\n  WriteByte(NID::kCRC);\r\n  if (numDefined == digestsDefined.Size())\r\n    WriteByte(1);\r\n  else\r\n  {\r\n    WriteByte(0);\r\n    WriteBoolVector(digestsDefined);\r\n  }\r\n  for (i = 0; i < digests.Size(); i++)\r\n    if (digestsDefined[i])\r\n      WriteUInt32(digests[i]);\r\n}\r\n\r\nvoid COutArchive::WritePackInfo(\r\n    UInt64 dataOffset,\r\n    const CRecordVector<UInt64> &packSizes,\r\n    const CRecordVector<bool> &packCRCsDefined,\r\n    const CRecordVector<UInt32> &packCRCs)\r\n{\r\n  if (packSizes.IsEmpty())\r\n    return;\r\n  WriteByte(NID::kPackInfo);\r\n  WriteNumber(dataOffset);\r\n  WriteNumber(packSizes.Size());\r\n  WriteByte(NID::kSize);\r\n  for (int i = 0; i < packSizes.Size(); i++)\r\n    WriteNumber(packSizes[i]);\r\n\r\n  WriteHashDigests(packCRCsDefined, packCRCs);\r\n  \r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::WriteUnpackInfo(const CObjectVector<CFolder> &folders)\r\n{\r\n  if (folders.IsEmpty())\r\n    return;\r\n\r\n  WriteByte(NID::kUnpackInfo);\r\n\r\n  WriteByte(NID::kFolder);\r\n  WriteNumber(folders.Size());\r\n  {\r\n    WriteByte(0);\r\n    for (int i = 0; i < folders.Size(); i++)\r\n      WriteFolder(folders[i]);\r\n  }\r\n  \r\n  WriteByte(NID::kCodersUnpackSize);\r\n  int i;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    for (int j = 0; j < folder.UnpackSizes.Size(); j++)\r\n      WriteNumber(folder.UnpackSizes[j]);\r\n  }\r\n\r\n  CRecordVector<bool> unpackCRCsDefined;\r\n  CRecordVector<UInt32> unpackCRCs;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    const CFolder &folder = folders[i];\r\n    unpackCRCsDefined.Add(folder.UnpackCRCDefined);\r\n    unpackCRCs.Add(folder.UnpackCRC);\r\n  }\r\n  WriteHashDigests(unpackCRCsDefined, unpackCRCs);\r\n\r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::WriteSubStreamsInfo(\r\n    const CObjectVector<CFolder> &folders,\r\n    const CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n    const CRecordVector<UInt64> &unpackSizes,\r\n    const CRecordVector<bool> &digestsDefined,\r\n    const CRecordVector<UInt32> &digests)\r\n{\r\n  WriteByte(NID::kSubStreamsInfo);\r\n\r\n  int i;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n  {\r\n    if (numUnpackStreamsInFolders[i] != 1)\r\n    {\r\n      WriteByte(NID::kNumUnpackStream);\r\n      for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n        WriteNumber(numUnpackStreamsInFolders[i]);\r\n      break;\r\n    }\r\n  }\r\n \r\n\r\n  bool needFlag = true;\r\n  CNum index = 0;\r\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\r\n    for (CNum j = 0; j < numUnpackStreamsInFolders[i]; j++)\r\n    {\r\n      if (j + 1 != numUnpackStreamsInFolders[i])\r\n      {\r\n        if (needFlag)\r\n          WriteByte(NID::kSize);\r\n        needFlag = false;\r\n        WriteNumber(unpackSizes[index]);\r\n      }\r\n      index++;\r\n    }\r\n\r\n  CRecordVector<bool> digestsDefined2;\r\n  CRecordVector<UInt32> digests2;\r\n\r\n  int digestIndex = 0;\r\n  for (i = 0; i < folders.Size(); i++)\r\n  {\r\n    int numSubStreams = (int)numUnpackStreamsInFolders[i];\r\n    if (numSubStreams == 1 && folders[i].UnpackCRCDefined)\r\n      digestIndex++;\r\n    else\r\n      for (int j = 0; j < numSubStreams; j++, digestIndex++)\r\n      {\r\n        digestsDefined2.Add(digestsDefined[digestIndex]);\r\n        digests2.Add(digests[digestIndex]);\r\n      }\r\n  }\r\n  WriteHashDigests(digestsDefined2, digests2);\r\n  WriteByte(NID::kEnd);\r\n}\r\n\r\nvoid COutArchive::SkipAlign(unsigned /* pos */, unsigned /* alignSize */)\r\n{\r\n  return;\r\n}\r\n\r\n/*\r\n7-Zip 4.50 - 4.58 contain BUG, so they do not support .7z archives with Unknown field.\r\n\r\nvoid COutArchive::SkipAlign(unsigned pos, unsigned alignSize)\r\n{\r\n  pos += (unsigned)GetPos();\r\n  pos &= (alignSize - 1);\r\n  if (pos == 0)\r\n    return;\r\n  unsigned skip = alignSize - pos;\r\n  if (skip < 2)\r\n    skip += alignSize;\r\n  skip -= 2;\r\n  WriteByte(NID::kDummy);\r\n  WriteByte((Byte)skip);\r\n  for (unsigned i = 0; i < skip; i++)\r\n    WriteByte(0);\r\n}\r\n*/\r\n\r\nvoid COutArchive::WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize)\r\n{\r\n  const UInt64 bvSize = (numDefined == v.Size()) ? 0 : (v.Size() + 7) / 8;\r\n  const UInt64 dataSize = (UInt64)numDefined * itemSize + bvSize + 2;\r\n  SkipAlign(3 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), itemSize);\r\n\r\n  WriteByte(type);\r\n  WriteNumber(dataSize);\r\n  if (numDefined == v.Size())\r\n    WriteByte(1);\r\n  else\r\n  {\r\n    WriteByte(0);\r\n    WriteBoolVector(v);\r\n  }\r\n  WriteByte(0);\r\n}\r\n\r\nvoid COutArchive::WriteUInt64DefVector(const CUInt64DefVector &v, Byte type)\r\n{\r\n  int numDefined = 0;\r\n\r\n  int i;\r\n  for (i = 0; i < v.Defined.Size(); i++)\r\n    if (v.Defined[i])\r\n      numDefined++;\r\n\r\n  if (numDefined == 0)\r\n    return;\r\n\r\n  WriteAlignedBoolHeader(v.Defined, numDefined, type, 8);\r\n  \r\n  for (i = 0; i < v.Defined.Size(); i++)\r\n    if (v.Defined[i])\r\n      WriteUInt64(v.Values[i]);\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const Byte *data, size_t dataSize,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  CSequentialInStreamImp *streamSpec = new CSequentialInStreamImp;\r\n  CMyComPtr<ISequentialInStream> stream = streamSpec;\r\n  streamSpec->Init(data, dataSize);\r\n  CFolder folderItem;\r\n  folderItem.UnpackCRCDefined = true;\r\n  folderItem.UnpackCRC = CrcCalc(data, dataSize);\r\n  UInt64 dataSize64 = dataSize;\r\n  RINOK(encoder.Encode(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      stream, NULL, &dataSize64, folderItem, SeqStream, packSizes, NULL))\r\n  folders.Add(folderItem);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutArchive::EncodeStream(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    CEncoder &encoder, const CByteBuffer &data,\r\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\r\n{\r\n  return EncodeStream(\r\n      EXTERNAL_CODECS_LOC_VARS\r\n      encoder, data, data.GetCapacity(), packSizes, folders);\r\n}\r\n\r\nvoid COutArchive::WriteHeader(\r\n    const CArchiveDatabase &db,\r\n    const CHeaderOptions &headerOptions,\r\n    UInt64 &headerOffset)\r\n{\r\n  int i;\r\n  \r\n  UInt64 packedSize = 0;\r\n  for (i = 0; i < db.PackSizes.Size(); i++)\r\n    packedSize += db.PackSizes[i];\r\n\r\n  headerOffset = packedSize;\r\n\r\n  WriteByte(NID::kHeader);\r\n\r\n  // Archive Properties\r\n\r\n  if (db.Folders.Size() > 0)\r\n  {\r\n    WriteByte(NID::kMainStreamsInfo);\r\n    WritePackInfo(0, db.PackSizes,\r\n        db.PackCRCsDefined,\r\n        db.PackCRCs);\r\n\r\n    WriteUnpackInfo(db.Folders);\r\n\r\n    CRecordVector<UInt64> unpackSizes;\r\n    CRecordVector<bool> digestsDefined;\r\n    CRecordVector<UInt32> digests;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = db.Files[i];\r\n      if (!file.HasStream)\r\n        continue;\r\n      unpackSizes.Add(file.Size);\r\n      digestsDefined.Add(file.CrcDefined);\r\n      digests.Add(file.Crc);\r\n    }\r\n\r\n    WriteSubStreamsInfo(\r\n        db.Folders,\r\n        db.NumUnpackStreamsVector,\r\n        unpackSizes,\r\n        digestsDefined,\r\n        digests);\r\n    WriteByte(NID::kEnd);\r\n  }\r\n\r\n  if (db.Files.IsEmpty())\r\n  {\r\n    WriteByte(NID::kEnd);\r\n    return;\r\n  }\r\n\r\n  WriteByte(NID::kFilesInfo);\r\n  WriteNumber(db.Files.Size());\r\n\r\n  {\r\n  /* ---------- Empty Streams ---------- */\r\n  CBoolVector emptyStreamVector;\r\n  emptyStreamVector.Reserve(db.Files.Size());\r\n  int numEmptyStreams = 0;\r\n  for (i = 0; i < db.Files.Size(); i++)\r\n    if (db.Files[i].HasStream)\r\n      emptyStreamVector.Add(false);\r\n    else\r\n    {\r\n      emptyStreamVector.Add(true);\r\n      numEmptyStreams++;\r\n    }\r\n  if (numEmptyStreams > 0)\r\n  {\r\n    WriteByte(NID::kEmptyStream);\r\n    WriteNumber((emptyStreamVector.Size() + 7) / 8);\r\n    WriteBoolVector(emptyStreamVector);\r\n\r\n    CBoolVector emptyFileVector, antiVector;\r\n    emptyFileVector.Reserve(numEmptyStreams);\r\n    antiVector.Reserve(numEmptyStreams);\r\n    CNum numEmptyFiles = 0, numAntiItems = 0;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const CFileItem &file = db.Files[i];\r\n      if (!file.HasStream)\r\n      {\r\n        emptyFileVector.Add(!file.IsDir);\r\n        if (!file.IsDir)\r\n          numEmptyFiles++;\r\n        bool isAnti = db.IsItemAnti(i);\r\n        antiVector.Add(isAnti);\r\n        if (isAnti)\r\n          numAntiItems++;\r\n      }\r\n    }\r\n\r\n    if (numEmptyFiles > 0)\r\n    {\r\n      WriteByte(NID::kEmptyFile);\r\n      WriteNumber((emptyFileVector.Size() + 7) / 8);\r\n      WriteBoolVector(emptyFileVector);\r\n    }\r\n\r\n    if (numAntiItems > 0)\r\n    {\r\n      WriteByte(NID::kAnti);\r\n      WriteNumber((antiVector.Size() + 7) / 8);\r\n      WriteBoolVector(antiVector);\r\n    }\r\n  }\r\n  }\r\n\r\n\r\n  {\r\n    /* ---------- Names ---------- */\r\n    \r\n    int numDefined = 0;\r\n    size_t namesDataSize = 0;\r\n    for (int i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      const UString &name = db.Files[i].Name;\r\n      if (!name.IsEmpty())\r\n        numDefined++;\r\n      namesDataSize += (name.Length() + 1) * 2;\r\n    }\r\n    \r\n    if (numDefined > 0)\r\n    {\r\n      namesDataSize++;\r\n      SkipAlign(2 + GetBigNumberSize(namesDataSize), 2);\r\n\r\n      WriteByte(NID::kName);\r\n      WriteNumber(namesDataSize);\r\n      WriteByte(0);\r\n      for (int i = 0; i < db.Files.Size(); i++)\r\n      {\r\n        const UString &name = db.Files[i].Name;\r\n        for (int t = 0; t <= name.Length(); t++)\r\n        {\r\n          wchar_t c = name[t];\r\n          WriteByte((Byte)c);\r\n          WriteByte((Byte)(c >> 8));\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  if (headerOptions.WriteCTime) WriteUInt64DefVector(db.CTime, NID::kCTime);\r\n  if (headerOptions.WriteATime) WriteUInt64DefVector(db.ATime, NID::kATime);\r\n  if (headerOptions.WriteMTime) WriteUInt64DefVector(db.MTime, NID::kMTime);\r\n  WriteUInt64DefVector(db.StartPos, NID::kStartPos);\r\n  \r\n  {\r\n    /* ---------- Write Attrib ---------- */\r\n    CBoolVector boolVector;\r\n    boolVector.Reserve(db.Files.Size());\r\n    int numDefined = 0;\r\n    for (i = 0; i < db.Files.Size(); i++)\r\n    {\r\n      bool defined = db.Files[i].AttribDefined;\r\n      boolVector.Add(defined);\r\n      if (defined)\r\n        numDefined++;\r\n    }\r\n    if (numDefined > 0)\r\n    {\r\n      WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttributes, 4);\r\n      for (i = 0; i < db.Files.Size(); i++)\r\n      {\r\n        const CFileItem &file = db.Files[i];\r\n        if (file.AttribDefined)\r\n          WriteUInt32(file.Attrib);\r\n      }\r\n    }\r\n  }\r\n\r\n  WriteByte(NID::kEnd); // for files\r\n  WriteByte(NID::kEnd); // for headers\r\n}\r\n\r\nHRESULT COutArchive::WriteDatabase(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CArchiveDatabase &db,\r\n    const CCompressionMethodMode *options,\r\n    const CHeaderOptions &headerOptions)\r\n{\r\n  if (!db.CheckNumFiles())\r\n    return E_FAIL;\r\n\r\n  UInt64 headerOffset;\r\n  UInt32 headerCRC;\r\n  UInt64 headerSize;\r\n  if (db.IsEmpty())\r\n  {\r\n    headerSize = 0;\r\n    headerOffset = 0;\r\n    headerCRC = CrcCalc(0, 0);\r\n  }\r\n  else\r\n  {\r\n    bool encodeHeaders = false;\r\n    if (options != 0)\r\n      if (options->IsEmpty())\r\n        options = 0;\r\n    if (options != 0)\r\n      if (options->PasswordIsDefined || headerOptions.CompressMainHeader)\r\n        encodeHeaders = true;\r\n\r\n    _outByte.SetStream(SeqStream);\r\n    _outByte.Init();\r\n    _crc = CRC_INIT_VAL;\r\n    _countMode = encodeHeaders;\r\n    _writeToStream = true;\r\n    _countSize = 0;\r\n    WriteHeader(db, headerOptions, headerOffset);\r\n\r\n    if (encodeHeaders)\r\n    {\r\n      CByteBuffer buf;\r\n      buf.SetCapacity(_countSize);\r\n      _outByte2.Init((Byte *)buf, _countSize);\r\n      \r\n      _countMode = false;\r\n      _writeToStream = false;\r\n      WriteHeader(db, headerOptions, headerOffset);\r\n      \r\n      if (_countSize != _outByte2.GetPos())\r\n        return E_FAIL;\r\n\r\n      CCompressionMethodMode encryptOptions;\r\n      encryptOptions.PasswordIsDefined = options->PasswordIsDefined;\r\n      encryptOptions.Password = options->Password;\r\n      CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions);\r\n      CRecordVector<UInt64> packSizes;\r\n      CObjectVector<CFolder> folders;\r\n      RINOK(EncodeStream(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          encoder, (const Byte *)buf,\r\n          _countSize, packSizes, folders));\r\n\r\n      _writeToStream = true;\r\n      \r\n      if (folders.Size() == 0)\r\n        throw 1;\r\n\r\n      WriteID(NID::kEncodedHeader);\r\n      WritePackInfo(headerOffset, packSizes,\r\n        CRecordVector<bool>(), CRecordVector<UInt32>());\r\n      WriteUnpackInfo(folders);\r\n      WriteByte(NID::kEnd);\r\n      for (int i = 0; i < packSizes.Size(); i++)\r\n        headerOffset += packSizes[i];\r\n    }\r\n    RINOK(_outByte.Flush());\r\n    headerCRC = CRC_GET_DIGEST(_crc);\r\n    headerSize = _outByte.GetProcessedSize();\r\n  }\r\n  #ifdef _7Z_VOL\r\n  if (_endMarker)\r\n  {\r\n    CFinishHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset =\r\n        UInt64(0) - (headerSize +\r\n        4 + kFinishHeaderSize);\r\n    h.ArchiveStartOffset = h.NextHeaderOffset - headerOffset;\r\n    h.AdditionalStartBlockSize = 0;\r\n    RINOK(WriteFinishHeader(h));\r\n    return WriteFinishSignature();\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    CStartHeader h;\r\n    h.NextHeaderSize = headerSize;\r\n    h.NextHeaderCRC = headerCRC;\r\n    h.NextHeaderOffset = headerOffset;\r\n    RINOK(Stream->Seek(_prefixHeaderPos, STREAM_SEEK_SET, NULL));\r\n    return WriteStartHeader(h);\r\n  }\r\n}\r\n\r\nvoid CArchiveDatabase::GetFile(int index, CFileItem &file, CFileItem2 &file2) const\r\n{\r\n  file = Files[index];\r\n  file2.CTimeDefined = CTime.GetItem(index, file2.CTime);\r\n  file2.ATimeDefined = ATime.GetItem(index, file2.ATime);\r\n  file2.MTimeDefined = MTime.GetItem(index, file2.MTime);\r\n  file2.StartPosDefined = StartPos.GetItem(index, file2.StartPos);\r\n  file2.IsAnti = IsItemAnti(index);\r\n}\r\n\r\nvoid CArchiveDatabase::AddFile(const CFileItem &file, const CFileItem2 &file2)\r\n{\r\n  int index = Files.Size();\r\n  CTime.SetItem(index, file2.CTimeDefined, file2.CTime);\r\n  ATime.SetItem(index, file2.ATimeDefined, file2.ATime);\r\n  MTime.SetItem(index, file2.MTimeDefined, file2.MTime);\r\n  StartPos.SetItem(index, file2.StartPosDefined, file2.StartPos);\r\n  SetItemAnti(index, file2.IsAnti);\r\n  Files.Add(file);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zOut.h",
    "content": "// 7z/Out.h\r\n\r\n#ifndef __7Z_OUT_H\r\n#define __7Z_OUT_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zCompressionMode.h\"\r\n#include \"7zEncode.h\"\r\n\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nclass CWriteBufferLoc\r\n{\r\n  Byte *_data;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n  CWriteBufferLoc(): _size(0), _pos(0) {}\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    _data = data;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    if (size > _size - _pos)\r\n      throw 1;\r\n    memcpy(_data + _pos, data, size);\r\n    _pos += size;\r\n  }\r\n  void WriteByte(Byte b)\r\n  {\r\n    if (_size == _pos)\r\n      throw 1;\r\n    _data[_pos++] = b;\r\n  }\r\n  size_t GetPos() const { return _pos; }\r\n};\r\n\r\nstruct CHeaderOptions\r\n{\r\n  bool CompressMainHeader;\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  CHeaderOptions():\r\n      CompressMainHeader(true),\r\n      WriteCTime(false),\r\n      WriteATime(false),\r\n      WriteMTime(true)\r\n      {}\r\n};\r\n\r\nclass COutArchive\r\n{\r\n  UInt64 _prefixHeaderPos;\r\n\r\n  HRESULT WriteDirect(const void *data, UInt32 size);\r\n  \r\n  UInt64 GetPos() const;\r\n  void WriteBytes(const void *data, size_t size);\r\n  void WriteBytes(const CByteBuffer &data) { WriteBytes(data, data.GetCapacity()); }\r\n  void WriteByte(Byte b);\r\n  void WriteUInt32(UInt32 value);\r\n  void WriteUInt64(UInt64 value);\r\n  void WriteNumber(UInt64 value);\r\n  void WriteID(UInt64 value) { WriteNumber(value); }\r\n\r\n  void WriteFolder(const CFolder &folder);\r\n  HRESULT WriteFileHeader(const CFileItem &itemInfo);\r\n  void WriteBoolVector(const CBoolVector &boolVector);\r\n  void WriteHashDigests(\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  void WritePackInfo(\r\n      UInt64 dataOffset,\r\n      const CRecordVector<UInt64> &packSizes,\r\n      const CRecordVector<bool> &packCRCsDefined,\r\n      const CRecordVector<UInt32> &packCRCs);\r\n\r\n  void WriteUnpackInfo(const CObjectVector<CFolder> &folders);\r\n\r\n  void WriteSubStreamsInfo(\r\n      const CObjectVector<CFolder> &folders,\r\n      const CRecordVector<CNum> &numUnpackStreamsInFolders,\r\n      const CRecordVector<UInt64> &unpackSizes,\r\n      const CRecordVector<bool> &digestsDefined,\r\n      const CRecordVector<UInt32> &hashDigests);\r\n\r\n  void SkipAlign(unsigned pos, unsigned alignSize);\r\n  void WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize);\r\n  void WriteUInt64DefVector(const CUInt64DefVector &v, Byte type);\r\n\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const Byte *data, size_t dataSize,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  HRESULT EncodeStream(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      CEncoder &encoder, const CByteBuffer &data,\r\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\r\n  void WriteHeader(\r\n      const CArchiveDatabase &db,\r\n      const CHeaderOptions &headerOptions,\r\n      UInt64 &headerOffset);\r\n  \r\n  bool _countMode;\r\n  bool _writeToStream;\r\n  size_t _countSize;\r\n  UInt32 _crc;\r\n  COutBuffer _outByte;\r\n  CWriteBufferLoc _outByte2;\r\n\r\n  #ifdef _7Z_VOL\r\n  bool _endMarker;\r\n  #endif\r\n\r\n  HRESULT WriteSignature();\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishSignature();\r\n  #endif\r\n  HRESULT WriteStartHeader(const CStartHeader &h);\r\n  #ifdef _7Z_VOL\r\n  HRESULT WriteFinishHeader(const CFinishHeader &h);\r\n  #endif\r\n  CMyComPtr<IOutStream> Stream;\r\npublic:\r\n\r\n  COutArchive() { _outByte.Create(1 << 16); }\r\n  CMyComPtr<ISequentialOutStream> SeqStream;\r\n  HRESULT Create(ISequentialOutStream *stream, bool endMarker);\r\n  void Close();\r\n  HRESULT SkeepPrefixArchiveHeader();\r\n  HRESULT WriteDatabase(\r\n      DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CArchiveDatabase &db,\r\n      const CCompressionMethodMode *options,\r\n      const CHeaderOptions &headerOptions);\r\n\r\n  #ifdef _7Z_VOL\r\n  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);\r\n  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);\r\n  #endif\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zProperties.cpp",
    "content": "// 7zProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zProperties.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zHandler.h\"\r\n\r\n// #define _MULTI_PACK\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CPropMap\r\n{\r\n  UInt64 FilePropID;\r\n  STATPROPSTG StatPROPSTG;\r\n};\r\n\r\nCPropMap kPropMap[] =\r\n{\r\n  { NID::kName, NULL, kpidPath, VT_BSTR},\r\n  { NID::kSize, NULL, kpidSize, VT_UI8},\r\n  { NID::kPackInfo, NULL, kpidPackSize, VT_UI8},\r\n  \r\n  #ifdef _MULTI_PACK\r\n  { 100, L\"Pack0\", kpidPackedSize0, VT_UI8},\r\n  { 101, L\"Pack1\", kpidPackedSize1, VT_UI8},\r\n  { 102, L\"Pack2\", kpidPackedSize2, VT_UI8},\r\n  { 103, L\"Pack3\", kpidPackedSize3, VT_UI8},\r\n  { 104, L\"Pack4\", kpidPackedSize4, VT_UI8},\r\n  #endif\r\n\r\n  { NID::kCTime, NULL, kpidCTime, VT_FILETIME},\r\n  { NID::kMTime, NULL, kpidMTime, VT_FILETIME},\r\n  { NID::kATime, NULL, kpidATime, VT_FILETIME},\r\n  { NID::kWinAttributes, NULL, kpidAttrib, VT_UI4},\r\n  { NID::kStartPos, NULL, kpidPosition, VT_UI4},\r\n\r\n  { NID::kCRC, NULL, kpidCRC, VT_UI4},\r\n  \r\n  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},\r\n\r\n  #ifndef _SFX\r\n  { 97, NULL, kpidEncrypted, VT_BOOL},\r\n  { 98, NULL, kpidMethod, VT_BSTR},\r\n  { 99, NULL, kpidBlock, VT_UI4}\r\n  #endif\r\n};\r\n\r\nstatic const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);\r\n\r\nstatic int FindPropInMap(UInt64 filePropID)\r\n{\r\n  for (int i = 0; i < kPropMapSize; i++)\r\n    if (kPropMap[i].FilePropID == filePropID)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void CopyOneItem(CRecordVector<UInt64> &src,\r\n    CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      dest.Add(item);\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)\r\n{\r\n  for (int i = 0; i < src.Size(); i++)\r\n    if (src[i] == item)\r\n    {\r\n      src.Delete(i);\r\n      return;\r\n    }\r\n}\r\n\r\nstatic void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)\r\n{\r\n  for (int i = 0; i < dest.Size(); i++)\r\n    if (dest[i] == item)\r\n    {\r\n      dest.Delete(i);\r\n      break;\r\n    }\r\n  dest.Insert(0, item);\r\n}\r\n\r\nvoid CHandler::FillPopIDs()\r\n{\r\n  _fileInfoPopIDs.Clear();\r\n\r\n  #ifdef _7Z_VOL\r\n  if(_volumes.Size() < 1)\r\n    return;\r\n  const CVolume &volume = _volumes.Front();\r\n  const CArchiveDatabaseEx &_db = volume.Database;\r\n  #endif\r\n\r\n  CRecordVector<UInt64> fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;\r\n\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);\r\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);\r\n\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);\r\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);\r\n  _fileInfoPopIDs += fileInfoPopIDs;\r\n \r\n  #ifndef _SFX\r\n  _fileInfoPopIDs.Add(97);\r\n  _fileInfoPopIDs.Add(98);\r\n  _fileInfoPopIDs.Add(99);\r\n  #endif\r\n  #ifdef _MULTI_PACK\r\n  _fileInfoPopIDs.Add(100);\r\n  _fileInfoPopIDs.Add(101);\r\n  _fileInfoPopIDs.Add(102);\r\n  _fileInfoPopIDs.Add(103);\r\n  _fileInfoPopIDs.Add(104);\r\n  #endif\r\n\r\n  #ifndef _SFX\r\n  InsertToHead(_fileInfoPopIDs, NID::kMTime);\r\n  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);\r\n  InsertToHead(_fileInfoPopIDs, NID::kSize);\r\n  InsertToHead(_fileInfoPopIDs, NID::kName);\r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)\r\n{\r\n  *numProperties = _fileInfoPopIDs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)\r\n{\r\n  if ((int)index >= _fileInfoPopIDs.Size())\r\n    return E_INVALIDARG;\r\n  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);\r\n  if (indexInMap == -1)\r\n    return E_INVALIDARG;\r\n  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;\r\n  *propID = srcItem.propid;\r\n  *varType = srcItem.vt;\r\n  *name = 0;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zProperties.h",
    "content": "// 7zProperties.h\r\n\r\n#ifndef __7Z_PROPERTIES_H\r\n#define __7Z_PROPERTIES_H\r\n\r\n#include \"../../PropID.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nenum\r\n{\r\n  kpidPackedSize0 = kpidUserDefined,\r\n  kpidPackedSize1,\r\n  kpidPackedSize2,\r\n  kpidPackedSize3,\r\n  kpidPackedSize4\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zRegister.cpp",
    "content": "// 7zRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"7zHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::N7z::CHandler;  }\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"7z\", L\"7z\", 0, 7, {'7' + 1 , 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };\r\n\r\nREGISTER_ARC_DEC_SIG(7z)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zSpecStream.cpp",
    "content": "// 7zSpecStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"7zSpecStream.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(\r\n    UInt64 subStream, UInt64 *value)\r\n{\r\n  if (_getSubStreamSize == NULL)\r\n    return E_NOTIMPL;\r\n  return  _getSubStreamSize->GetSubStreamSize(subStream, value);\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zSpecStream.h",
    "content": "// 7zSpecStream.h\r\n\r\n#ifndef __7Z_SPEC_STREAM_H\r\n#define __7Z_SPEC_STREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CSequentialInStreamSizeCount2:\r\n  public ISequentialInStream,\r\n  public ICompressGetSubStreamSize,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _getSubStreamSize = 0;\r\n    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zUpdate.cpp",
    "content": "// 7zUpdate.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/LimitedStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n\r\n#include \"7zEncode.h\"\r\n#include \"7zFolderInStream.h\"\r\n#include \"7zHandler.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zUpdate.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstatic const wchar_t *kMatchFinderForBCJ2_LZMA = L\"BT2\";\r\nstatic const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;\r\nstatic const UInt32 kAlgorithmForBCJ2_LZMA = 1;\r\nstatic const UInt32 kNumFastBytesForBCJ2_LZMA = 64;\r\n\r\nstatic HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream,\r\n    UInt64 position, UInt64 size, ICompressProgressInfo *progress)\r\n{\r\n  RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));\r\n  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;\r\n  CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);\r\n  streamSpec->SetStream(inStream);\r\n  streamSpec->Init(size);\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n  RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));\r\n  return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);\r\n}\r\n\r\nstatic int GetReverseSlashPos(const UString &name)\r\n{\r\n  int slashPos = name.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = name.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n  return slashPos;\r\n}\r\n\r\nint CUpdateItem::GetExtensionPos() const\r\n{\r\n  int slashPos = GetReverseSlashPos(Name);\r\n  int dotPos = Name.ReverseFind(L'.');\r\n  if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n    return Name.Length();\r\n  return dotPos + 1;\r\n}\r\n\r\nUString CUpdateItem::GetExtension() const\r\n{\r\n  return Name.Mid(GetExtensionPos());\r\n}\r\n\r\n#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }\r\n\r\nstatic int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)\r\n{\r\n  size_t c1 = a1.GetCapacity();\r\n  size_t c2 = a2.GetCapacity();\r\n  RINOZ(MyCompare(c1, c2));\r\n  for (size_t i = 0; i < c1; i++)\r\n    RINOZ(MyCompare(a1[i], a2[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareCoders(const CCoderInfo &c1, const CCoderInfo &c2)\r\n{\r\n  RINOZ(MyCompare(c1.NumInStreams, c2.NumInStreams));\r\n  RINOZ(MyCompare(c1.NumOutStreams, c2.NumOutStreams));\r\n  RINOZ(MyCompare(c1.MethodID, c2.MethodID));\r\n  return CompareBuffers(c1.Props, c2.Props);\r\n}\r\n\r\nstatic int CompareBindPairs(const CBindPair &b1, const CBindPair &b2)\r\n{\r\n  RINOZ(MyCompare(b1.InIndex, b2.InIndex));\r\n  return MyCompare(b1.OutIndex, b2.OutIndex);\r\n}\r\n\r\nstatic int CompareFolders(const CFolder &f1, const CFolder &f2)\r\n{\r\n  int s1 = f1.Coders.Size();\r\n  int s2 = f2.Coders.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  int i;\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareCoders(f1.Coders[i], f2.Coders[i]));\r\n  s1 = f1.BindPairs.Size();\r\n  s2 = f2.BindPairs.Size();\r\n  RINOZ(MyCompare(s1, s2));\r\n  for (i = 0; i < s1; i++)\r\n    RINOZ(CompareBindPairs(f1.BindPairs[i], f2.BindPairs[i]));\r\n  return 0;\r\n}\r\n\r\nstatic int CompareFiles(const CFileItem &f1, const CFileItem &f2)\r\n{\r\n  return MyStringCompareNoCase(f1.Name, f2.Name);\r\n}\r\n\r\nstatic int CompareFolderRefs(const int *p1, const int *p2, void *param)\r\n{\r\n  int i1 = *p1;\r\n  int i2 = *p2;\r\n  const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param;\r\n  RINOZ(CompareFolders(\r\n      db.Folders[i1],\r\n      db.Folders[i2]));\r\n  RINOZ(MyCompare(\r\n      db.NumUnpackStreamsVector[i1],\r\n      db.NumUnpackStreamsVector[i2]));\r\n  if (db.NumUnpackStreamsVector[i1] == 0)\r\n    return 0;\r\n  return CompareFiles(\r\n      db.Files[db.FolderStartFileIndex[i1]],\r\n      db.Files[db.FolderStartFileIndex[i2]]);\r\n}\r\n\r\n////////////////////////////////////////////////////////////\r\n\r\nstatic int CompareEmptyItems(const int *p1, const int *p2, void *param)\r\n{\r\n  const CObjectVector<CUpdateItem> &updateItems = *(const CObjectVector<CUpdateItem> *)param;\r\n  const CUpdateItem &u1 = updateItems[*p1];\r\n  const CUpdateItem &u2 = updateItems[*p2];\r\n  if (u1.IsDir != u2.IsDir)\r\n    return (u1.IsDir) ? 1 : -1;\r\n  if (u1.IsDir)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    int n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  if (u1.IsAnti != u2.IsAnti)\r\n    return (u1.IsAnti ? 1 : -1);\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstatic const char *g_Exts =\r\n  \" lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo\"\r\n  \" zip jar ear war msi\"\r\n  \" 3gp avi mov mpeg mpg mpe wmv\"\r\n  \" aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav\"\r\n  \" swf \"\r\n  \" chm hxi hxs\"\r\n  \" gif jpeg jpg jp2 png tiff  bmp ico psd psp\"\r\n  \" awg ps eps cgm dxf svg vrml wmf emf ai md\"\r\n  \" cad dwg pps key sxi\"\r\n  \" max 3ds\"\r\n  \" iso bin nrg mdf img pdi tar cpio xpi\"\r\n  \" vfd vhd vud vmc vsv\"\r\n  \" vmdk dsk nvram vmem vmsd vmsn vmss vmtm\"\r\n  \" inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def\"\r\n  \" f77 f f90 f95\"\r\n  \" asm sql manifest dep \"\r\n  \" mak clw csproj vcproj sln dsp dsw \"\r\n  \" class \"\r\n  \" bat cmd\"\r\n  \" xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml\"\r\n  \" awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs\"\r\n  \" text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf\"\r\n  \" sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf\"\r\n  \" abw afp cwk lwp wpd wps wpt wrf wri\"\r\n  \" abf afm bdf fon mgf otf pcf pfa snf ttf\"\r\n  \" dbf mdb nsf ntf wdb db fdb gdb\"\r\n  \" exe dll ocx vbx sfx sys tlb awx com obj lib out o so \"\r\n  \" pdb pch idb ncb opt\";\r\n\r\nint GetExtIndex(const char *ext)\r\n{\r\n  int extIndex = 1;\r\n  const char *p = g_Exts;\r\n  for (;;)\r\n  {\r\n    char c = *p++;\r\n    if (c == 0)\r\n      return extIndex;\r\n    if (c == ' ')\r\n      continue;\r\n    int pos = 0;\r\n    for (;;)\r\n    {\r\n      char c2 = ext[pos++];\r\n      if (c2 == 0 && (c == 0 || c == ' '))\r\n        return extIndex;\r\n      if (c != c2)\r\n        break;\r\n      c = *p++;\r\n    }\r\n    extIndex++;\r\n    for (;;)\r\n    {\r\n      if (c == 0)\r\n        return extIndex;\r\n      if (c == ' ')\r\n        break;\r\n      c = *p++;\r\n    }\r\n  }\r\n}\r\n\r\nstruct CRefItem\r\n{\r\n  const CUpdateItem *UpdateItem;\r\n  UInt32 Index;\r\n  UInt32 ExtensionPos;\r\n  UInt32 NamePos;\r\n  int ExtensionIndex;\r\n  CRefItem(UInt32 index, const CUpdateItem &ui, bool sortByType):\r\n    UpdateItem(&ui),\r\n    Index(index),\r\n    ExtensionPos(0),\r\n    NamePos(0),\r\n    ExtensionIndex(0)\r\n  {\r\n    if (sortByType)\r\n    {\r\n      int slashPos = GetReverseSlashPos(ui.Name);\r\n      NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0);\r\n      int dotPos = ui.Name.ReverseFind(L'.');\r\n      if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\r\n        ExtensionPos = ui.Name.Length();\r\n      else\r\n      {\r\n        ExtensionPos = dotPos + 1;\r\n        UString us = ui.Name.Mid(ExtensionPos);\r\n        if (!us.IsEmpty())\r\n        {\r\n          us.MakeLower();\r\n          int i;\r\n          AString s;\r\n          for (i = 0; i < us.Length(); i++)\r\n          {\r\n            wchar_t c = us[i];\r\n            if (c >= 0x80)\r\n              break;\r\n            s += (char)c;\r\n          }\r\n          if (i == us.Length())\r\n            ExtensionIndex = GetExtIndex(s);\r\n          else\r\n            ExtensionIndex = 0;\r\n        }\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nstatic int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *param)\r\n{\r\n  const CRefItem &a1 = *p1;\r\n  const CRefItem &a2 = *p2;\r\n  const CUpdateItem &u1 = *a1.UpdateItem;\r\n  const CUpdateItem &u2 = *a2.UpdateItem;\r\n  int n;\r\n  if (u1.IsDir != u2.IsDir)\r\n    return (u1.IsDir) ? 1 : -1;\r\n  if (u1.IsDir)\r\n  {\r\n    if (u1.IsAnti != u2.IsAnti)\r\n      return (u1.IsAnti ? 1 : -1);\r\n    n = MyStringCompareNoCase(u1.Name, u2.Name);\r\n    return -n;\r\n  }\r\n  bool sortByType = *(bool *)param;\r\n  if (sortByType)\r\n  {\r\n    RINOZ(MyCompare(a1.ExtensionIndex, a2.ExtensionIndex))\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos));\r\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos));\r\n    if (!u1.MTimeDefined && u2.MTimeDefined) return 1;\r\n    if (u1.MTimeDefined && !u2.MTimeDefined) return -1;\r\n    if (u1.MTimeDefined && u2.MTimeDefined) RINOZ(MyCompare(u1.MTime, u2.MTime));\r\n    RINOZ(MyCompare(u1.Size, u2.Size))\r\n  }\r\n  return MyStringCompareNoCase(u1.Name, u2.Name);\r\n}\r\n\r\nstruct CSolidGroup\r\n{\r\n  CCompressionMethodMode Method;\r\n  CRecordVector<UInt32> Indices;\r\n};\r\n\r\nstatic wchar_t *g_ExeExts[] =\r\n{\r\n  L\"dll\",\r\n  L\"exe\",\r\n  L\"ocx\",\r\n  L\"sfx\",\r\n  L\"sys\"\r\n};\r\n\r\nstatic bool IsExeFile(const UString &ext)\r\n{\r\n  for (int i = 0; i < sizeof(g_ExeExts) / sizeof(g_ExeExts[0]); i++)\r\n    if (ext.CompareNoCase(g_ExeExts[i]) == 0)\r\n      return true;\r\n  return false;\r\n}\r\n\r\nstatic const UInt64 k_LZMA  = 0x030101;\r\nstatic const UInt64 k_BCJ   = 0x03030103;\r\nstatic const UInt64 k_BCJ2  = 0x0303011B;\r\n\r\nstatic bool GetMethodFull(UInt64 methodID,\r\n    UInt32 numInStreams, CMethodFull &methodResult)\r\n{\r\n  methodResult.Id = methodID;\r\n  methodResult.NumInStreams = numInStreams;\r\n  methodResult.NumOutStreams = 1;\r\n  return true;\r\n}\r\n\r\nstatic bool MakeExeMethod(const CCompressionMethodMode &method,\r\n    bool bcj2Filter, CCompressionMethodMode &exeMethod)\r\n{\r\n  exeMethod = method;\r\n  if (bcj2Filter)\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ2, 4, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    if (!GetMethodFull(k_LZMA, 1, methodFull))\r\n      return false;\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kAlgorithm;\r\n      prop.Value = kAlgorithmForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kMatchFinder;\r\n      prop.Value = kMatchFinderForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = kDictionaryForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n    {\r\n      CProp prop;\r\n      prop.Id = NCoderPropID::kNumFastBytes;\r\n      prop.Value = kNumFastBytesForBCJ2_LZMA;\r\n      methodFull.Props.Add(prop);\r\n    }\r\n\r\n    exeMethod.Methods.Add(methodFull);\r\n    exeMethod.Methods.Add(methodFull);\r\n    CBind bind;\r\n\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 2;\r\n    bind.OutStream = 1;\r\n    exeMethod.Binds.Add(bind);\r\n\r\n    bind.InCoder = 3;\r\n    bind.OutStream = 2;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  else\r\n  {\r\n    CMethodFull methodFull;\r\n    if (!GetMethodFull(k_BCJ, 1, methodFull))\r\n      return false;\r\n    exeMethod.Methods.Insert(0, methodFull);\r\n    CBind bind;\r\n    bind.OutCoder = 0;\r\n    bind.InStream = 0;\r\n    bind.InCoder = 1;\r\n    bind.OutStream = 0;\r\n    exeMethod.Binds.Add(bind);\r\n  }\r\n  return true;\r\n}\r\n\r\nstatic void SplitFilesToGroups(\r\n    const CCompressionMethodMode &method,\r\n    bool useFilters, bool maxFilter,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    CObjectVector<CSolidGroup> &groups)\r\n{\r\n  if (method.Methods.Size() != 1 || method.Binds.Size() != 0)\r\n    useFilters = false;\r\n  groups.Clear();\r\n  groups.Add(CSolidGroup());\r\n  groups.Add(CSolidGroup());\r\n  CSolidGroup &generalGroup = groups[0];\r\n  CSolidGroup &exeGroup = groups[1];\r\n  generalGroup.Method = method;\r\n  int i;\r\n  for (i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &ui = updateItems[i];\r\n    if (!ui.NewData)\r\n      continue;\r\n    if (!ui.HasStream())\r\n      continue;\r\n    if (useFilters)\r\n    {\r\n      const UString name = ui.Name;\r\n      int dotPos = name.ReverseFind(L'.');\r\n      if (dotPos >= 0)\r\n      {\r\n        UString ext = name.Mid(dotPos + 1);\r\n        if (IsExeFile(ext))\r\n        {\r\n          exeGroup.Indices.Add(i);\r\n          continue;\r\n        }\r\n      }\r\n    }\r\n    generalGroup.Indices.Add(i);\r\n  }\r\n  if (exeGroup.Indices.Size() > 0)\r\n    if (!MakeExeMethod(method, maxFilter, exeGroup.Method))\r\n      exeGroup.Method = method;\r\n  for (i = 0; i < groups.Size();)\r\n    if (groups[i].Indices.Size() == 0)\r\n      groups.Delete(i);\r\n    else\r\n      i++;\r\n}\r\n\r\nstatic void FromUpdateItemToFileItem(const CUpdateItem &ui,\r\n    CFileItem &file, CFileItem2 &file2)\r\n{\r\n  file.Name = NItemName::MakeLegalName(ui.Name);\r\n  if (ui.AttribDefined)\r\n    file.SetAttrib(ui.Attrib);\r\n  \r\n  file2.CTime = ui.CTime;  file2.CTimeDefined = ui.CTimeDefined;\r\n  file2.ATime = ui.ATime;  file2.ATimeDefined = ui.ATimeDefined;\r\n  file2.MTime = ui.MTime;  file2.MTimeDefined = ui.MTimeDefined;\r\n  file2.IsAnti = ui.IsAnti;\r\n  file2.StartPosDefined = false;\r\n\r\n  file.Size = ui.Size;\r\n  file.IsDir = ui.IsDir;\r\n  file.HasStream = ui.HasStream();\r\n}\r\n\r\nstatic HRESULT Update2(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  UInt64 numSolidFiles = options.NumSolidFiles;\r\n  if (numSolidFiles == 0)\r\n    numSolidFiles = 1;\r\n  /*\r\n  CMyComPtr<IOutStream> outStream;\r\n  RINOK(seqOutStream->QueryInterface(IID_IOutStream, (void **)&outStream));\r\n  if (!outStream)\r\n    return E_NOTIMPL;\r\n  */\r\n\r\n  UInt64 startBlockSize = db != 0 ? db->ArchiveInfo.StartPosition: 0;\r\n  if (startBlockSize > 0 && !options.RemoveSfxBlock)\r\n  {\r\n    RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));\r\n  }\r\n\r\n  CRecordVector<int> fileIndexToUpdateIndexMap;\r\n  if (db != 0)\r\n  {\r\n    fileIndexToUpdateIndexMap.Reserve(db->Files.Size());\r\n    for (int i = 0; i < db->Files.Size(); i++)\r\n      fileIndexToUpdateIndexMap.Add(-1);\r\n  }\r\n  int i;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    int index = updateItems[i].IndexInArchive;\r\n    if (index != -1)\r\n      fileIndexToUpdateIndexMap[index] = i;\r\n  }\r\n\r\n  CRecordVector<int> folderRefs;\r\n  if (db != 0)\r\n  {\r\n    for(i = 0; i < db->Folders.Size(); i++)\r\n    {\r\n      CNum indexInFolder = 0;\r\n      CNum numCopyItems = 0;\r\n      CNum numUnpackStreams = db->NumUnpackStreamsVector[i];\r\n      for (CNum fileIndex = db->FolderStartFileIndex[i];\r\n      indexInFolder < numUnpackStreams; fileIndex++)\r\n      {\r\n        if (db->Files[fileIndex].HasStream)\r\n        {\r\n          indexInFolder++;\r\n          int updateIndex = fileIndexToUpdateIndexMap[fileIndex];\r\n          if (updateIndex >= 0)\r\n            if (!updateItems[updateIndex].NewData)\r\n              numCopyItems++;\r\n        }\r\n      }\r\n      if (numCopyItems != numUnpackStreams && numCopyItems != 0)\r\n        return E_NOTIMPL; // It needs repacking !!!\r\n      if (numCopyItems > 0)\r\n        folderRefs.Add(i);\r\n    }\r\n    folderRefs.Sort(CompareFolderRefs, (void *)db);\r\n  }\r\n\r\n  ////////////////////////////\r\n\r\n  RINOK(archive.Create(seqOutStream, false));\r\n  RINOK(archive.SkeepPrefixArchiveHeader());\r\n  UInt64 complexity = 0;\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n    complexity += db->GetFolderFullPackSize(folderRefs[i]);\r\n  UInt64 inSizeForReduce = 0;\r\n  for(i = 0; i < updateItems.Size(); i++)\r\n  {\r\n    const CUpdateItem &ui = updateItems[i];\r\n    if (ui.NewData)\r\n    {\r\n      complexity += ui.Size;\r\n      if (numSolidFiles == 1)\r\n      {\r\n        if (ui.Size > inSizeForReduce)\r\n          inSizeForReduce = ui.Size;\r\n      }\r\n      else\r\n        inSizeForReduce += ui.Size;\r\n    }\r\n  }\r\n  RINOK(updateCallback->SetTotal(complexity));\r\n  complexity = 0;\r\n  RINOK(updateCallback->SetCompleted(&complexity));\r\n\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(updateCallback, true);\r\n\r\n  /////////////////////////////////////////\r\n  // Write Copy Items\r\n\r\n  for(i = 0; i < folderRefs.Size(); i++)\r\n  {\r\n    int folderIndex = folderRefs[i];\r\n    \r\n    lps->ProgressOffset = complexity;\r\n    UInt64 packSize = db->GetFolderFullPackSize(folderIndex);\r\n    RINOK(WriteRange(inStream, archive.SeqStream,\r\n        db->GetFolderStreamPos(folderIndex, 0), packSize, progress));\r\n    complexity += packSize;\r\n    \r\n    const CFolder &folder = db->Folders[folderIndex];\r\n    CNum startIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\r\n    {\r\n      newDatabase.PackSizes.Add(db->PackSizes[startIndex + j]);\r\n      // newDatabase.PackCRCsDefined.Add(db.PackCRCsDefined[startIndex + j]);\r\n      // newDatabase.PackCRCs.Add(db.PackCRCs[startIndex + j]);\r\n    }\r\n    newDatabase.Folders.Add(folder);\r\n\r\n    CNum numUnpackStreams = db->NumUnpackStreamsVector[folderIndex];\r\n    newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\r\n\r\n    CNum indexInFolder = 0;\r\n    for (CNum fi = db->FolderStartFileIndex[folderIndex];\r\n        indexInFolder < numUnpackStreams; fi++)\r\n    {\r\n      CFileItem file;\r\n      CFileItem2 file2;\r\n      db->GetFile(fi, file, file2);\r\n      if (file.HasStream)\r\n      {\r\n        indexInFolder++;\r\n        int updateIndex = fileIndexToUpdateIndexMap[fi];\r\n        if (updateIndex >= 0)\r\n        {\r\n          const CUpdateItem &ui = updateItems[updateIndex];\r\n          if (ui.NewProperties)\r\n          {\r\n            CFileItem uf;\r\n            FromUpdateItemToFileItem(ui, uf, file2);\r\n            uf.Size = file.Size;\r\n            uf.Crc = file.Crc;\r\n            uf.CrcDefined = file.CrcDefined;\r\n            uf.HasStream = file.HasStream;\r\n            file = uf;\r\n          }\r\n        }\r\n        newDatabase.AddFile(file, file2);\r\n      }\r\n    }\r\n  }\r\n\r\n  folderRefs.ClearAndFree();\r\n  fileIndexToUpdateIndexMap.ClearAndFree();\r\n\r\n  /////////////////////////////////////////\r\n  // Compress New Files\r\n\r\n  CObjectVector<CSolidGroup> groups;\r\n  SplitFilesToGroups(*options.Method, options.UseFilters, options.MaxFilter,\r\n      updateItems, groups);\r\n\r\n  const UInt32 kMinReduceSize = (1 << 16);\r\n  if (inSizeForReduce < kMinReduceSize)\r\n    inSizeForReduce = kMinReduceSize;\r\n\r\n  for (int groupIndex = 0; groupIndex < groups.Size(); groupIndex++)\r\n  {\r\n    const CSolidGroup &group = groups[groupIndex];\r\n    int numFiles = group.Indices.Size();\r\n    if (numFiles == 0)\r\n      continue;\r\n    CRecordVector<CRefItem> refItems;\r\n    refItems.Reserve(numFiles);\r\n    bool sortByType = (numSolidFiles > 1);\r\n    for (i = 0; i < numFiles; i++)\r\n      refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType));\r\n    refItems.Sort(CompareUpdateItems, (void *)&sortByType);\r\n    \r\n    CRecordVector<UInt32> indices;\r\n    indices.Reserve(numFiles);\r\n\r\n    for (i = 0; i < numFiles; i++)\r\n    {\r\n      UInt32 index = refItems[i].Index;\r\n      indices.Add(index);\r\n      /*\r\n      const CUpdateItem &ui = updateItems[index];\r\n      CFileItem file;\r\n      if (ui.NewProperties)\r\n        FromUpdateItemToFileItem(ui, file);\r\n      else\r\n        file = db.Files[ui.IndexInArchive];\r\n      if (file.IsAnti || file.IsDir)\r\n        return E_FAIL;\r\n      newDatabase.Files.Add(file);\r\n      */\r\n    }\r\n    \r\n    CEncoder encoder(group.Method);\r\n\r\n    for (i = 0; i < numFiles;)\r\n    {\r\n      UInt64 totalSize = 0;\r\n      int numSubFiles;\r\n      UString prevExtension;\r\n      for (numSubFiles = 0; i + numSubFiles < numFiles &&\r\n          numSubFiles < numSolidFiles; numSubFiles++)\r\n      {\r\n        const CUpdateItem &ui = updateItems[indices[i + numSubFiles]];\r\n        totalSize += ui.Size;\r\n        if (totalSize > options.NumSolidBytes)\r\n          break;\r\n        if (options.SolidExtension)\r\n        {\r\n          UString ext = ui.GetExtension();\r\n          if (numSubFiles == 0)\r\n            prevExtension = ext;\r\n          else\r\n            if (ext.CompareNoCase(prevExtension) != 0)\r\n              break;\r\n        }\r\n      }\r\n      if (numSubFiles < 1)\r\n        numSubFiles = 1;\r\n\r\n      CFolderInStream *inStreamSpec = new CFolderInStream;\r\n      CMyComPtr<ISequentialInStream> solidInStream(inStreamSpec);\r\n      inStreamSpec->Init(updateCallback, &indices[i], numSubFiles);\r\n      \r\n      CFolder folderItem;\r\n\r\n      int startPackIndex = newDatabase.PackSizes.Size();\r\n      RINOK(encoder.Encode(\r\n          EXTERNAL_CODECS_LOC_VARS\r\n          solidInStream, NULL, &inSizeForReduce, folderItem,\r\n          archive.SeqStream, newDatabase.PackSizes, progress));\r\n\r\n      for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)\r\n        lps->OutSize += newDatabase.PackSizes[startPackIndex];\r\n\r\n      lps->InSize += folderItem.GetUnpackSize();\r\n      // for()\r\n      // newDatabase.PackCRCsDefined.Add(false);\r\n      // newDatabase.PackCRCs.Add(0);\r\n      \r\n      newDatabase.Folders.Add(folderItem);\r\n      \r\n      CNum numUnpackStreams = 0;\r\n      for (int subIndex = 0; subIndex < numSubFiles; subIndex++)\r\n      {\r\n        const CUpdateItem &ui = updateItems[indices[i + subIndex]];\r\n        CFileItem file;\r\n        CFileItem2 file2;\r\n        if (ui.NewProperties)\r\n          FromUpdateItemToFileItem(ui, file, file2);\r\n        else\r\n          db->GetFile(ui.IndexInArchive, file, file2);\r\n        if (file2.IsAnti || file.IsDir)\r\n          return E_FAIL;\r\n        \r\n        /*\r\n        CFileItem &file = newDatabase.Files[\r\n              startFileIndexInDatabase + i + subIndex];\r\n        */\r\n        if (!inStreamSpec->Processed[subIndex])\r\n        {\r\n          continue;\r\n          // file.Name += L\".locked\";\r\n        }\r\n\r\n        file.Crc = inStreamSpec->CRCs[subIndex];\r\n        file.Size = inStreamSpec->Sizes[subIndex];\r\n        if (file.Size != 0)\r\n        {\r\n          file.CrcDefined = true;\r\n          file.HasStream = true;\r\n          numUnpackStreams++;\r\n        }\r\n        else\r\n        {\r\n          file.CrcDefined = false;\r\n          file.HasStream = false;\r\n        }\r\n        newDatabase.AddFile(file, file2);\r\n      }\r\n      // numUnpackStreams = 0 is very bad case for locked files\r\n      // v3.13 doesn't understand it.\r\n      newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\r\n      i += numSubFiles;\r\n    }\r\n  }\r\n\r\n  groups.ClearAndFree();\r\n\r\n  {\r\n    /////////////////////////////////////////\r\n    // Write Empty Files & Folders\r\n    \r\n    CRecordVector<int> emptyRefs;\r\n    for(i = 0; i < updateItems.Size(); i++)\r\n    {\r\n      const CUpdateItem &ui = updateItems[i];\r\n      if (ui.NewData)\r\n      {\r\n        if (ui.HasStream())\r\n          continue;\r\n      }\r\n      else\r\n        if (ui.IndexInArchive != -1)\r\n          if (db->Files[ui.IndexInArchive].HasStream)\r\n            continue;\r\n      emptyRefs.Add(i);\r\n    }\r\n    emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);\r\n    for (i = 0; i < emptyRefs.Size(); i++)\r\n    {\r\n      const CUpdateItem &ui = updateItems[emptyRefs[i]];\r\n      CFileItem file;\r\n      CFileItem2 file2;\r\n      if (ui.NewProperties)\r\n        FromUpdateItemToFileItem(ui, file, file2);\r\n      else\r\n        db->GetFile(ui.IndexInArchive, file, file2);\r\n      newDatabase.AddFile(file, file2);\r\n    }\r\n  }\r\n    \r\n  newDatabase.ReserveDown();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options)\r\n{\r\n  return Update2(\r\n        EXTERNAL_CODECS_LOC_VARS\r\n        inStream, db, updateItems,\r\n        archive, newDatabase, seqOutStream, updateCallback, options);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/7zUpdate.h",
    "content": "// 7zUpdate.h\r\n\r\n#ifndef __7Z_UPDATE_H\r\n#define __7Z_UPDATE_H\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zOut.h\"\r\n#include \"7zCompressionMode.h\"\r\n\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace N7z {\r\n\r\nstruct CUpdateItem\r\n{\r\n  int IndexInArchive;\r\n  int IndexInClient;\r\n  \r\n  UInt64 CTime;\r\n  UInt64 ATime;\r\n  UInt64 MTime;\r\n\r\n  UInt64 Size;\r\n  UString Name;\r\n\r\n  UInt32 Attrib;\r\n  \r\n  bool NewData;\r\n  bool NewProperties;\r\n\r\n  bool IsAnti;\r\n  bool IsDir;\r\n\r\n  bool AttribDefined;\r\n  bool CTimeDefined;\r\n  bool ATimeDefined;\r\n  bool MTimeDefined;\r\n\r\n  bool HasStream() const { return !IsDir && !IsAnti && Size != 0; }\r\n\r\n  CUpdateItem():\r\n      IsAnti(false),\r\n      IsDir(false),\r\n      AttribDefined(false),\r\n      CTimeDefined(false),\r\n      ATimeDefined(false),\r\n      MTimeDefined(false)\r\n      {}\r\n  void SetDirStatusFromAttrib() { IsDir = ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0); };\r\n\r\n  int GetExtensionPos() const;\r\n  UString GetExtension() const;\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  const CCompressionMethodMode *Method;\r\n  const CCompressionMethodMode *HeaderMethod;\r\n  bool UseFilters;\r\n  bool MaxFilter;\r\n\r\n  CHeaderOptions HeaderOptions;\r\n\r\n  UInt64 NumSolidFiles;\r\n  UInt64 NumSolidBytes;\r\n  bool SolidExtension;\r\n  bool RemoveSfxBlock;\r\n  bool VolumeMode;\r\n};\r\n\r\nHRESULT Update(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    IInStream *inStream,\r\n    const CArchiveDatabaseEx *db,\r\n    const CObjectVector<CUpdateItem> &updateItems,\r\n    COutArchive &archive,\r\n    CArchiveDatabase &newDatabase,\r\n    ISequentialOutStream *seqOutStream,\r\n    IArchiveUpdateCallback *updateCallback,\r\n    const CUpdateOptions &options);\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Archive.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Archive2.def",
    "content": "EXPORTS\r\n  CreateObject PRIVATE\r\n  GetHandlerProperty PRIVATE\r\n  GetNumberOfFormats PRIVATE\r\n  GetHandlerProperty2 PRIVATE\r\n  CreateObject PRIVATE\r\n  GetNumberOfMethods PRIVATE\r\n  GetMethodProperty PRIVATE\r\n  SetLargePageMode PRIVATE\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/ArchiveExports.cpp",
    "content": "// ArchiveExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterArc.h\"\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\r\nvoid RegisterArc(const CArcInfo *arcInfo)\r\n{\r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler,\r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\n#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nint FindFormatCalssId(const GUID *clsID)\r\n{\r\n  GUID cls = *clsID;\r\n  CLS_ARC_ID_ITEM(cls) = 0;\r\n  if (cls != CLSID_CArchiveHandler)\r\n    return -1;\r\n  Byte id = CLS_ARC_ID_ITEM(*clsID);\r\n  for (unsigned i = 0; i < g_NumArcs; i++)\r\n    if (g_Arcs[i]->ClassId == id)\r\n      return (int)i;\r\n  return -1;\r\n}\r\n\r\nSTDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  {\r\n    int needIn = (*iid == IID_IInArchive);\r\n    int needOut = (*iid == IID_IOutArchive);\r\n    if (!needIn && !needOut)\r\n      return E_NOINTERFACE;\r\n    int formatIndex = FindFormatCalssId(clsid);\r\n    if (formatIndex < 0)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    \r\n    const CArcInfo &arc = *g_Arcs[formatIndex];\r\n    if (needIn)\r\n    {\r\n      *outObject = arc.CreateInArchive();\r\n      ((IInArchive *)*outObject)->AddRef();\r\n    }\r\n    else\r\n    {\r\n      if (!arc.CreateOutArchive)\r\n        return CLASS_E_CLASSNOTAVAILABLE;\r\n      *outObject = arc.CreateOutArchive();\r\n      ((IOutArchive *)*outObject)->AddRef();\r\n    }\r\n  }\r\n  COM_TRY_END\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  if (formatIndex >= g_NumArcs)\r\n    return E_INVALIDARG;\r\n  const CArcInfo &arc = *g_Arcs[formatIndex];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case NArchive::kName:\r\n      prop = arc.Name;\r\n      break;\r\n    case NArchive::kClassID:\r\n    {\r\n      GUID clsId = CLSID_CArchiveHandler;\r\n      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;\r\n      return SetPropGUID(clsId, value);\r\n    }\r\n    case NArchive::kExtension:\r\n      if (arc.Ext != 0)\r\n        prop = arc.Ext;\r\n      break;\r\n    case NArchive::kAddExtension:\r\n      if (arc.AddExt != 0)\r\n        prop = arc.AddExt;\r\n      break;\r\n    case NArchive::kUpdate:\r\n      prop = (bool)(arc.CreateOutArchive != 0);\r\n      break;\r\n    case NArchive::kKeepName:\r\n      prop = arc.KeepName;\r\n      break;\r\n    case NArchive::kStartSignature:\r\n      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  return GetHandlerProperty2(0, propID, value);\r\n}\r\n\r\nSTDAPI GetNumberOfFormats(UINT32 *numFormats)\r\n{\r\n  *numFormats = g_NumArcs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/CoderMixer2.cpp",
    "content": "// CoderMixer2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):\r\n  _srcBindInfo(srcBindInfo)\r\n{\r\n  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);\r\n\r\n  UInt32  j;\r\n  for (j = 0; j < NumSrcInStreams; j++)\r\n  {\r\n    _srcInToDestOutMap.Add(0);\r\n    DestOutToSrcInMap.Add(0);\r\n  }\r\n  for (j = 0; j < _numSrcOutStreams; j++)\r\n  {\r\n    _srcOutToDestInMap.Add(0);\r\n    _destInToSrcOutMap.Add(0);\r\n  }\r\n\r\n  UInt32 destInOffset = 0;\r\n  UInt32 destOutOffset = 0;\r\n  UInt32 srcInOffset = NumSrcInStreams;\r\n  UInt32 srcOutOffset = _numSrcOutStreams;\r\n\r\n  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];\r\n\r\n    srcInOffset -= srcCoderInfo.NumInStreams;\r\n    srcOutOffset -= srcCoderInfo.NumOutStreams;\r\n    \r\n    UInt32 j;\r\n    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)\r\n    {\r\n      UInt32 index = srcInOffset + j;\r\n      _srcInToDestOutMap[index] = destOutOffset;\r\n      DestOutToSrcInMap[destOutOffset] = index;\r\n    }\r\n    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)\r\n    {\r\n      UInt32 index = srcOutOffset + j;\r\n      _srcOutToDestInMap[index] = destInOffset;\r\n      _destInToSrcOutMap[destInOffset] = index;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)\r\n{\r\n  destBindInfo.Coders.Clear();\r\n  destBindInfo.BindPairs.Clear();\r\n  destBindInfo.InStreams.Clear();\r\n  destBindInfo.OutStreams.Clear();\r\n\r\n  int i;\r\n  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];\r\n    CCoderStreamsInfo destCoderInfo;\r\n    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;\r\n    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;\r\n    destBindInfo.Coders.Add(destCoderInfo);\r\n  }\r\n  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)\r\n  {\r\n    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];\r\n    CBindPair destBindPair;\r\n    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];\r\n    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];\r\n    destBindInfo.BindPairs.Add(destBindPair);\r\n  }\r\n  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)\r\n    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);\r\n  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)\r\n    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);\r\n}\r\n\r\nCCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams):\r\n    NumInStreams(numInStreams),\r\n    NumOutStreams(numOutStreams)\r\n{\r\n  InSizes.Reserve(NumInStreams);\r\n  InSizePointers.Reserve(NumInStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n  OutSizePointers.Reserve(NumOutStreams);\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\nvoid CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,\r\n      const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/CoderMixer2.h",
    "content": "// CoderMixer2.h\r\n\r\n#ifndef __CODER_MIXER2_H\r\n#define __CODER_MIXER2_H\r\n\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../ICoder.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n};\r\n\r\nstruct CCoderStreamsInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n};\r\n\r\nstruct CBindInfo\r\n{\r\n  CRecordVector<CCoderStreamsInfo> Coders;\r\n  CRecordVector<CBindPair> BindPairs;\r\n  CRecordVector<UInt32> InStreams;\r\n  CRecordVector<UInt32> OutStreams;\r\n\r\n  void Clear()\r\n  {\r\n    Coders.Clear();\r\n    BindPairs.Clear();\r\n    InStreams.Clear();\r\n    OutStreams.Clear();\r\n  }\r\n\r\n  /*\r\n  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const\r\n  {\r\n    UInt32 numOutStreams = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      numOutStreams += Coders[i].NumOutStreams;\r\n    return numOutStreams;\r\n  }\r\n  */\r\n\r\n\r\n  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const\r\n  {\r\n    numInStreams = 0;\r\n    numOutStreams = 0;\r\n    for (int i = 0; i < Coders.Size(); i++)\r\n    {\r\n      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];\r\n      numInStreams += coderStreamsInfo.NumInStreams;\r\n      numOutStreams += coderStreamsInfo.NumOutStreams;\r\n    }\r\n  }\r\n\r\n  int FindBinderForInStream(UInt32 inStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].InIndex == inStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindBinderForOutStream(UInt32 outStream) const\r\n  {\r\n    for (int i = 0; i < BindPairs.Size(); i++)\r\n      if (BindPairs[i].OutIndex == outStream)\r\n        return i;\r\n    return -1;\r\n  }\r\n\r\n  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumInStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const\r\n  {\r\n    UInt32 streamIndex = 0;\r\n    for (UInt32 i = 0; i < coderIndex; i++)\r\n      streamIndex += Coders[i].NumOutStreams;\r\n    return streamIndex;\r\n  }\r\n\r\n\r\n  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,\r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumInStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,\r\n      UInt32 &coderStreamIndex) const\r\n  {\r\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\r\n    {\r\n      UInt32 curSize = Coders[coderIndex].NumOutStreams;\r\n      if (streamIndex < curSize)\r\n      {\r\n        coderStreamIndex = streamIndex;\r\n        return;\r\n      }\r\n      streamIndex -= curSize;\r\n    }\r\n    throw 1;\r\n  }\r\n};\r\n\r\nclass CBindReverseConverter\r\n{\r\n  UInt32 _numSrcOutStreams;\r\n  NCoderMixer::CBindInfo _srcBindInfo;\r\n  CRecordVector<UInt32> _srcInToDestOutMap;\r\n  CRecordVector<UInt32> _srcOutToDestInMap;\r\n  CRecordVector<UInt32> _destInToSrcOutMap;\r\npublic:\r\n  UInt32 NumSrcInStreams;\r\n  CRecordVector<UInt32> DestOutToSrcInMap;\r\n\r\n  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);\r\n  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);\r\n};\r\n\r\nstruct CCoderInfo2\r\n{\r\n  CMyComPtr<ICompressCoder> Coder;\r\n  CMyComPtr<ICompressCoder2> Coder2;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n\r\n  CRecordVector<UInt64> InSizes;\r\n  CRecordVector<UInt64> OutSizes;\r\n  CRecordVector<const UInt64 *> InSizePointers;\r\n  CRecordVector<const UInt64 *> OutSizePointers;\r\n\r\n  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n\r\n  HRESULT QueryInterface(REFGUID iid, void** pp) const\r\n  {\r\n    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;\r\n    return p->QueryInterface(iid, pp);\r\n  }\r\n};\r\n\r\nclass CCoderMixer2\r\n{\r\npublic:\r\n  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;\r\n  virtual void ReInit() = 0;\r\n  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;\r\n};\r\n\r\n}\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/CoderMixer2MT.cpp",
    "content": "// CoderMixer2MT.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CoderMixer2MT.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nCCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams):\r\n    CCoderInfo2(numInStreams, numOutStreams)\r\n{\r\n  InStreams.Reserve(NumInStreams);\r\n  InStreamPointers.Reserve(NumInStreams);\r\n  OutStreams.Reserve(NumOutStreams);\r\n  OutStreamPointers.Reserve(NumOutStreams);\r\n}\r\n\r\nvoid CCoder2::Execute() { Code(NULL); }\r\n\r\nvoid CCoder2::Code(ICompressProgressInfo *progress)\r\n{\r\n  InStreamPointers.Clear();\r\n  OutStreamPointers.Clear();\r\n  UInt32 i;\r\n  for (i = 0; i < NumInStreams; i++)\r\n  {\r\n    if (InSizePointers[i] != NULL)\r\n      InSizePointers[i] = &InSizes[i];\r\n    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);\r\n  }\r\n  for (i = 0; i < NumOutStreams; i++)\r\n  {\r\n    if (OutSizePointers[i] != NULL)\r\n      OutSizePointers[i] = &OutSizes[i];\r\n    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);\r\n  }\r\n  if (Coder)\r\n    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],\r\n        InSizePointers[0], OutSizePointers[0], progress);\r\n  else\r\n    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,\r\n      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);\r\n  {\r\n    int i;\r\n    for (i = 0; i < InStreams.Size(); i++)\r\n      InStreams[i].Release();\r\n    for (i = 0; i < OutStreams.Size(); i++)\r\n      OutStreams[i].Release();\r\n  }\r\n}\r\n\r\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\r\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\r\n{\r\n  sizes.Clear();\r\n  sizePointers.Clear();\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    if (srcSizes == 0 || srcSizes[i] == NULL)\r\n    {\r\n      sizes.Add(0);\r\n      sizePointers.Add(NULL);\r\n    }\r\n    else\r\n    {\r\n      sizes.Add(*srcSizes[i]);\r\n      sizePointers.Add(&sizes.Back());\r\n    }\r\n  }\r\n}\r\n\r\n\r\nvoid CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)\r\n{\r\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\r\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\r\n}\r\n\r\n//////////////////////////////////////\r\n// CCoderMixer2MT\r\n\r\nHRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)\r\n{\r\n  _bindInfo = bindInfo;\r\n  _streamBinders.Clear();\r\n  for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    _streamBinders.Add(CStreamBinder());\r\n    RINOK(_streamBinders.Back().CreateEvents());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoderCommon()\r\n{\r\n  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];\r\n  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);\r\n  _coders.Add(threadCoderInfo);\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder(ICompressCoder *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder = coder;\r\n}\r\n\r\nvoid CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)\r\n{\r\n  AddCoderCommon();\r\n  _coders.Back().Coder2 = coder;\r\n}\r\n\r\n\r\nvoid CCoderMixer2MT::ReInit()\r\n{\r\n  for(int i = 0; i < _streamBinders.Size(); i++)\r\n    _streamBinders[i].ReInit();\r\n}\r\n\r\n\r\nHRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams)\r\n{\r\n  /*\r\n  if (_coders.Size() != _bindInfo.Coders.Size())\r\n    throw 0;\r\n  */\r\n  int i;\r\n  for(i = 0; i < _coders.Size(); i++)\r\n  {\r\n    CCoder2 &coderInfo = _coders[i];\r\n    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];\r\n    coderInfo.InStreams.Clear();\r\n    UInt32 j;\r\n    for(j = 0; j < coderStreamsInfo.NumInStreams; j++)\r\n      coderInfo.InStreams.Add(NULL);\r\n    coderInfo.OutStreams.Clear();\r\n    for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)\r\n      coderInfo.OutStreams.Add(NULL);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.BindPairs.Size(); i++)\r\n  {\r\n    const CBindPair &bindPair = _bindInfo.BindPairs[i];\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);\r\n    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);\r\n\r\n    _streamBinders[i].CreateStreams(\r\n        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],\r\n        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);\r\n  }\r\n\r\n  for(i = 0; i < _bindInfo.InStreams.Size(); i++)\r\n  {\r\n    UInt32 inCoderIndex, inCoderStreamIndex;\r\n    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);\r\n    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];\r\n  }\r\n  \r\n  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)\r\n  {\r\n    UInt32 outCoderIndex, outCoderStreamIndex;\r\n    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);\r\n    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)\r\n{\r\n  for (int i = 0; i < _coders.Size(); i++)\r\n    if (_coders[i].Result == code)\r\n      return code;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||\r\n      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())\r\n    return E_INVALIDARG;\r\n\r\n  Init(inStreams, outStreams);\r\n\r\n  int i;\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n    {\r\n      RINOK(_coders[i].Create());\r\n    }\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].Start();\r\n\r\n  _coders[_progressCoderIndex].Code(progress);\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n    if (i != _progressCoderIndex)\r\n      _coders[i].WaitFinish();\r\n\r\n  RINOK(ReturnIfError(E_ABORT));\r\n  RINOK(ReturnIfError(E_OUTOFMEMORY));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK && result != E_FAIL && result != S_FALSE)\r\n      return result;\r\n  }\r\n\r\n  RINOK(ReturnIfError(S_FALSE));\r\n\r\n  for (i = 0; i < _coders.Size(); i++)\r\n  {\r\n    HRESULT result = _coders[i].Result;\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/CoderMixer2MT.h",
    "content": "// CoderMixer2MT.h\r\n\r\n#ifndef __CODER_MIXER2_MT_H\r\n#define __CODER_MIXER2_MT_H\r\n\r\n#include \"CoderMixer2.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../Common/StreamBinder.h\"\r\n#include \"../../Common/VirtThread.h\"\r\n\r\nnamespace NCoderMixer {\r\n\r\nstruct CCoder2: public CCoderInfo2, public CVirtThread\r\n{\r\n  HRESULT Result;\r\n  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;\r\n  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;\r\n  CRecordVector<ISequentialInStream*> InStreamPointers;\r\n  CRecordVector<ISequentialOutStream*> OutStreamPointers;\r\n\r\n  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);\r\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\r\n  virtual void Execute();\r\n  void Code(ICompressProgressInfo *progress);\r\n};\r\n\r\n\r\n/*\r\n  SetBindInfo()\r\n  for each coder\r\n    AddCoder[2]()\r\n  SetProgressIndex(UInt32 coderIndex);\r\n \r\n  for each file\r\n  {\r\n    ReInit()\r\n    for each coder\r\n      SetCoderInfo\r\n    Code\r\n  }\r\n*/\r\n\r\nclass CCoderMixer2MT:\r\n  public ICompressCoder2,\r\n  public CCoderMixer2,\r\n  public CMyUnknownImp\r\n{\r\n  CBindInfo _bindInfo;\r\n  CObjectVector<CStreamBinder> _streamBinders;\r\n  int _progressCoderIndex;\r\n\r\n  void AddCoderCommon();\r\n  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);\r\n  HRESULT ReturnIfError(HRESULT code);\r\npublic:\r\n  CObjectVector<CCoder2> _coders;\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n\r\n  HRESULT SetBindInfo(const CBindInfo &bindInfo);\r\n  void AddCoder(ICompressCoder *coder);\r\n  void AddCoder2(ICompressCoder2 *coder);\r\n  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }\r\n\r\n  void ReInit();\r\n  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)\r\n    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }\r\n  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const\r\n    {  return _streamBinders[binderIndex].ProcessedSize; }\r\n};\r\n\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/CrossThreadProgress.cpp",
    "content": "// CrossThreadProgress.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CrossThreadProgress.h\"\r\n\r\nSTDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  InSize = inSize;\r\n  OutSize = outSize;\r\n  ProgressEvent.Set();\r\n  WaitEvent.Lock();\r\n  return Result;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/CrossThreadProgress.h",
    "content": "// CrossThreadProgress.h\r\n\r\n#ifndef __CROSSTHREADPROGRESS_H\r\n#define __CROSSTHREADPROGRESS_H\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nclass CCrossThreadProgress:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  const UInt64 *InSize;\r\n  const UInt64 *OutSize;\r\n  HRESULT Result;\r\n  NWindows::NSynchronization::CAutoResetEvent ProgressEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent WaitEvent;\r\n\r\n  HRes Create()\r\n  {\r\n    RINOK(ProgressEvent.CreateIfNotCreated());\r\n    return WaitEvent.CreateIfNotCreated();\r\n  }\r\n  void Init()\r\n  {\r\n    ProgressEvent.Reset();\r\n    WaitEvent.Reset();\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/DummyOutStream.cpp",
    "content": "// DummyOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DummyOutStream.h\"\r\n\r\nSTDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/DummyOutStream.h",
    "content": "// DummyOutStream.h\r\n\r\n#ifndef __DUMMYOUTSTREAM_H\r\n#define __DUMMYOUTSTREAM_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nclass CDummyOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init() { _size = 0; }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/HandlerOut.cpp",
    "content": "// HandlerOut.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#ifdef COMPRESS_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/ParseProperties.h\"\r\n\r\n#include \"HandlerOut.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\n\r\nstatic const wchar_t *kCopyMethod = L\"Copy\";\r\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\r\nstatic const wchar_t *kLZMA2MethodName = L\"LZMA2\";\r\nstatic const wchar_t *kBZip2MethodName = L\"BZip2\";\r\nstatic const wchar_t *kPpmdMethodName = L\"PPMd\";\r\nstatic const wchar_t *kDeflateMethodName = L\"Deflate\";\r\nstatic const wchar_t *kDeflate64MethodName = L\"Deflate64\";\r\n\r\nstatic const wchar_t *kLzmaMatchFinderX1 = L\"HC4\";\r\nstatic const wchar_t *kLzmaMatchFinderX5 = L\"BT4\";\r\n\r\nstatic const UInt32 kLzmaAlgoX1 = 0;\r\nstatic const UInt32 kLzmaAlgoX5 = 1;\r\n\r\nstatic const UInt32 kLzmaDicSizeX1 = 1 << 16;\r\nstatic const UInt32 kLzmaDicSizeX3 = 1 << 20;\r\nstatic const UInt32 kLzmaDicSizeX5 = 1 << 24;\r\nstatic const UInt32 kLzmaDicSizeX7 = 1 << 25;\r\nstatic const UInt32 kLzmaDicSizeX9 = 1 << 26;\r\n\r\nstatic const UInt32 kLzmaFastBytesX1 = 32;\r\nstatic const UInt32 kLzmaFastBytesX7 = 64;\r\n\r\nstatic const UInt32 kPpmdMemSizeX1 = (1 << 22);\r\nstatic const UInt32 kPpmdMemSizeX5 = (1 << 24);\r\nstatic const UInt32 kPpmdMemSizeX7 = (1 << 26);\r\nstatic const UInt32 kPpmdMemSizeX9 = (192 << 20);\r\n\r\nstatic const UInt32 kPpmdOrderX1 = 4;\r\nstatic const UInt32 kPpmdOrderX5 = 6;\r\nstatic const UInt32 kPpmdOrderX7 = 16;\r\nstatic const UInt32 kPpmdOrderX9 = 32;\r\n\r\nstatic const UInt32 kDeflateAlgoX1 = 0;\r\nstatic const UInt32 kDeflateAlgoX5 = 1;\r\n\r\nstatic const UInt32 kDeflateFastBytesX1 = 32;\r\nstatic const UInt32 kDeflateFastBytesX7 = 64;\r\nstatic const UInt32 kDeflateFastBytesX9 = 128;\r\n\r\nstatic const UInt32 kDeflatePassesX1 = 1;\r\nstatic const UInt32 kDeflatePassesX7 = 3;\r\nstatic const UInt32 kDeflatePassesX9 = 10;\r\n\r\nstatic const UInt32 kBZip2NumPassesX1 = 1;\r\nstatic const UInt32 kBZip2NumPassesX7 = 2;\r\nstatic const UInt32 kBZip2NumPassesX9 = 7;\r\n\r\nstatic const UInt32 kBZip2DicSizeX1 = 100000;\r\nstatic const UInt32 kBZip2DicSizeX3 = 500000;\r\nstatic const UInt32 kBZip2DicSizeX5 = 900000;\r\n\r\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\r\n\r\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\r\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\r\nstatic const UInt32 kNumFastBytesForHeaders = 273;\r\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5;\r\n\r\nstatic bool AreEqual(const UString &methodName, const wchar_t *s)\r\n  { return (methodName.CompareNoCase(s) == 0); }\r\n\r\nstatic inline bool IsLZMAMethod(const UString &methodName)\r\n{\r\n  return\r\n    AreEqual(methodName, kLZMAMethodName) ||\r\n    AreEqual(methodName, kLZMA2MethodName);\r\n}\r\n\r\nstatic inline bool IsBZip2Method(const UString &methodName)\r\n  { return AreEqual(methodName, kBZip2MethodName); }\r\n\r\nstatic inline bool IsPpmdMethod(const UString &methodName)\r\n  { return AreEqual(methodName, kPpmdMethodName); }\r\n\r\nstatic inline bool IsDeflateMethod(const UString &methodName)\r\n{\r\n  return\r\n    AreEqual(methodName, kDeflateMethodName) ||\r\n    AreEqual(methodName, kDeflate64MethodName);\r\n}\r\n\r\nstruct CNameToPropID\r\n{\r\n  PROPID PropID;\r\n  VARTYPE VarType;\r\n  const wchar_t *Name;\r\n};\r\n\r\nCNameToPropID g_NameToPropID[] =\r\n{\r\n  { NCoderPropID::kOrder, VT_UI4, L\"O\" },\r\n  { NCoderPropID::kPosStateBits, VT_UI4, L\"PB\" },\r\n  { NCoderPropID::kLitContextBits, VT_UI4, L\"LC\" },\r\n  { NCoderPropID::kLitPosBits, VT_UI4, L\"LP\" },\r\n  { NCoderPropID::kEndMarker, VT_BOOL, L\"eos\" },\r\n\r\n  { NCoderPropID::kNumPasses, VT_UI4, L\"Pass\" },\r\n  { NCoderPropID::kNumFastBytes, VT_UI4, L\"fb\" },\r\n  { NCoderPropID::kMatchFinderCycles, VT_UI4, L\"mc\" },\r\n  { NCoderPropID::kAlgorithm, VT_UI4, L\"a\" },\r\n  { NCoderPropID::kMatchFinder, VT_BSTR, L\"mf\" },\r\n  { NCoderPropID::kNumThreads, VT_UI4, L\"mt\" }\r\n};\r\n\r\nstatic bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp)\r\n{\r\n  if (varType == srcProp.vt)\r\n  {\r\n    destProp = srcProp;\r\n    return true;\r\n  }\r\n  if (varType == VT_UI1)\r\n  {\r\n    if (srcProp.vt == VT_UI4)\r\n    {\r\n      UInt32 value = srcProp.ulVal;\r\n      if (value > 0xFF)\r\n        return false;\r\n      destProp = (Byte)value;\r\n      return true;\r\n    }\r\n  }\r\n  else if (varType == VT_BOOL)\r\n  {\r\n    bool res;\r\n    if (SetBoolProperty(res, srcProp) != S_OK)\r\n      return false;\r\n    destProp = res;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n    \r\nstatic int FindPropIdFromStringName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)\r\n    if (name.CompareNoCase(g_NameToPropID[i].Name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstatic void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID,\r\n    const NWindows::NCOM::CPropVariant &value)\r\n{\r\n  for (int j = 0; j < oneMethodInfo.Props.Size(); j++)\r\n    if (oneMethodInfo.Props[j].Id == propID)\r\n      return;\r\n  CProp prop;\r\n  prop.Id = propID;\r\n  prop.Value = value;\r\n  oneMethodInfo.Props.Add(prop);\r\n}\r\n\r\nvoid COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n    #ifdef COMPRESS_MT\r\n    , UInt32 numThreads\r\n    #endif\r\n    )\r\n{\r\n  UInt32 level = _level;\r\n  if (oneMethodInfo.MethodName.IsEmpty())\r\n    oneMethodInfo.MethodName = kDefaultMethodName;\r\n  \r\n  if (IsLZMAMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 dicSize =\r\n      (level >= 9 ? kLzmaDicSizeX9 :\r\n      (level >= 7 ? kLzmaDicSizeX7 :\r\n      (level >= 5 ? kLzmaDicSizeX5 :\r\n      (level >= 3 ? kLzmaDicSizeX3 :\r\n                    kLzmaDicSizeX1))));\r\n    \r\n    UInt32 algo =\r\n      (level >= 5 ? kLzmaAlgoX5 :\r\n                    kLzmaAlgoX1);\r\n    \r\n    UInt32 fastBytes =\r\n      (level >= 7 ? kLzmaFastBytesX7 :\r\n                    kLzmaFastBytesX1);\r\n    \r\n    const wchar_t *matchFinder =\r\n      (level >= 5 ? kLzmaMatchFinderX5 :\r\n                    kLzmaMatchFinderX1);\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsDeflateMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 fastBytes =\r\n      (level >= 9 ? kDeflateFastBytesX9 :\r\n      (level >= 7 ? kDeflateFastBytesX7 :\r\n                    kDeflateFastBytesX1));\r\n    \r\n    UInt32 numPasses =\r\n      (level >= 9 ? kDeflatePassesX9 :\r\n      (level >= 7 ? kDeflatePassesX7 :\r\n                    kDeflatePassesX1));\r\n    \r\n    UInt32 algo =\r\n      (level >= 5 ? kDeflateAlgoX5 :\r\n                    kDeflateAlgoX1);\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n  }\r\n  else if (IsBZip2Method(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 numPasses =\r\n      (level >= 9 ? kBZip2NumPassesX9 :\r\n      (level >= 7 ? kBZip2NumPassesX7 :\r\n                    kBZip2NumPassesX1));\r\n    \r\n    UInt32 dicSize =\r\n      (level >= 5 ? kBZip2DicSizeX5 :\r\n      (level >= 3 ? kBZip2DicSizeX3 :\r\n                    kBZip2DicSizeX1));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\r\n    #ifdef COMPRESS_MT\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\r\n    #endif\r\n  }\r\n  else if (IsPpmdMethod(oneMethodInfo.MethodName))\r\n  {\r\n    UInt32 useMemSize =\r\n      (level >= 9 ? kPpmdMemSizeX9 :\r\n      (level >= 7 ? kPpmdMemSizeX7 :\r\n      (level >= 5 ? kPpmdMemSizeX5 :\r\n                    kPpmdMemSizeX1)));\r\n    \r\n    UInt32 order =\r\n      (level >= 9 ? kPpmdOrderX9 :\r\n      (level >= 7 ? kPpmdOrderX7 :\r\n      (level >= 5 ? kPpmdOrderX5 :\r\n                    kPpmdOrderX1)));\r\n    \r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize);\r\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order);\r\n  }\r\n}\r\n\r\nstatic void SplitParams(const UString &srcString, UStringVector &subStrings)\r\n{\r\n  subStrings.Clear();\r\n  UString name;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L':')\r\n    {\r\n      subStrings.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  subStrings.Add(name);\r\n}\r\n\r\nstatic void SplitParam(const UString &param, UString &name, UString &value)\r\n{\r\n  int eqPos = param.Find(L'=');\r\n  if (eqPos >= 0)\r\n  {\r\n    name = param.Left(eqPos);\r\n    value = param.Mid(eqPos + 1);\r\n    return;\r\n  }\r\n  for(int i = 0; i < param.Length(); i++)\r\n  {\r\n    wchar_t c = param[i];\r\n    if (c >= L'0' && c <= L'9')\r\n    {\r\n      name = param.Left(i);\r\n      value = param.Mid(i);\r\n      return;\r\n    }\r\n  }\r\n  name = param;\r\n}\r\n\r\nHRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value)\r\n{\r\n  CProp prop;\r\n  if (name.CompareNoCase(L\"D\") == 0 ||\r\n      name.CompareNoCase(L\"MEM\") == 0)\r\n  {\r\n    UInt32 dicSize;\r\n    RINOK(ParsePropDictionaryValue(value, dicSize));\r\n    prop.Id = (name.CompareNoCase(L\"D\") == 0) ?\r\n        NCoderPropID::kDictionarySize :\r\n        NCoderPropID::kUsedMemorySize;\r\n    prop.Value = dicSize;\r\n  }\r\n  else\r\n  {\r\n    int index = FindPropIdFromStringName(name);\r\n    if (index < 0)\r\n      return E_INVALIDARG;\r\n    \r\n    const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n    prop.Id = nameToPropID.PropID;\r\n    \r\n    NCOM::CPropVariant propValue;\r\n    \r\n    if (nameToPropID.VarType == VT_BSTR)\r\n      propValue = value;\r\n    else if (nameToPropID.VarType == VT_BOOL)\r\n    {\r\n      bool res;\r\n      if (!StringToBool(value, res))\r\n        return E_INVALIDARG;\r\n      propValue = res;\r\n    }\r\n    else\r\n    {\r\n      UInt32 number;\r\n      if (ParseStringToUInt32(value, number) == value.Length())\r\n        propValue = number;\r\n      else\r\n        propValue = value;\r\n    }\r\n    \r\n    if (!ConvertProperty(propValue, nameToPropID.VarType, prop.Value))\r\n      return E_INVALIDARG;\r\n  }\r\n  oneMethodInfo.Props.Add(prop);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString)\r\n{\r\n  UStringVector params;\r\n  SplitParams(srcString, params);\r\n  if (params.Size() > 0)\r\n    oneMethodInfo.MethodName = params[0];\r\n  for (int i = 1; i < params.Size(); i++)\r\n  {\r\n    const UString &param = params[i];\r\n    UString name, value;\r\n    SplitParam(param, name, value);\r\n    RINOK(SetParam(oneMethodInfo, name, value));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const UString &s)\r\n{\r\n  UString s2 = s;\r\n  s2.MakeUpper();\r\n  for (int i = 0; i < s2.Length();)\r\n  {\r\n    const wchar_t *start = ((const wchar_t *)s2) + i;\r\n    const wchar_t *end;\r\n    UInt64 v = ConvertStringToUInt64(start, &end);\r\n    if (start == end)\r\n    {\r\n      if (s2[i++] != 'E')\r\n        return E_INVALIDARG;\r\n      _solidExtension = true;\r\n      continue;\r\n    }\r\n    i += (int)(end - start);\r\n    if (i == s2.Length())\r\n      return E_INVALIDARG;\r\n    wchar_t c = s2[i++];\r\n    switch(c)\r\n    {\r\n      case 'F':\r\n        if (v < 1)\r\n          v = 1;\r\n        _numSolidFiles = v;\r\n        break;\r\n      case 'B':\r\n        _numSolidBytes = v;\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'K':\r\n        _numSolidBytes = (v << 10);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'M':\r\n        _numSolidBytes = (v << 20);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      case 'G':\r\n        _numSolidBytes = (v << 30);\r\n        _numSolidBytesDefined = true;\r\n        break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)\r\n{\r\n  bool isSolid;\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      isSolid = true;\r\n      break;\r\n    case VT_BOOL:\r\n      isSolid = (value.boolVal != VARIANT_FALSE);\r\n      break;\r\n    case VT_BSTR:\r\n      if (StringToBool(value.bstrVal, isSolid))\r\n        break;\r\n      return SetSolidSettings(value.bstrVal);\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  if (isSolid)\r\n    InitSolid();\r\n  else\r\n    _numSolidFiles = 1;\r\n  return S_OK;\r\n}\r\n\r\nvoid COutHandler::Init()\r\n{\r\n  _removeSfxBlock = false;\r\n  _compressHeaders = true;\r\n  _encryptHeadersSpecified = false;\r\n  _encryptHeaders = false;\r\n  \r\n  WriteCTime = false;\r\n  WriteATime = false;\r\n  WriteMTime = true;\r\n  \r\n  #ifdef COMPRESS_MT\r\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\r\n  #endif\r\n  \r\n  _level = 5;\r\n  _autoFilter = true;\r\n  _volumeMode = false;\r\n  _crcSize = 4;\r\n  InitSolid();\r\n}\r\n\r\nvoid COutHandler::BeforeSetProperty()\r\n{\r\n  Init();\r\n  #ifdef COMPRESS_MT\r\n  numProcessors = NSystem::GetNumberOfProcessors();\r\n  #endif\r\n\r\n  mainDicSize = 0xFFFFFFFF;\r\n  mainDicMethodIndex = 0xFFFFFFFF;\r\n  minNumber = 0;\r\n  _crcSize = 4;\r\n}\r\n\r\nHRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)\r\n{\r\n  UString name = nameSpec;\r\n  name.MakeUpper();\r\n  if (name.IsEmpty())\r\n    return E_INVALIDARG;\r\n  \r\n  if (name[0] == 'X')\r\n  {\r\n    name.Delete(0);\r\n    _level = 9;\r\n    return ParsePropValue(name, value, _level);\r\n  }\r\n  \r\n  if (name[0] == L'S')\r\n  {\r\n    name.Delete(0);\r\n    if (name.IsEmpty())\r\n      return SetSolidSettings(value);\r\n    if (value.vt != VT_EMPTY)\r\n      return E_INVALIDARG;\r\n    return SetSolidSettings(name);\r\n  }\r\n  \r\n  if (name == L\"CRC\")\r\n  {\r\n    _crcSize = 4;\r\n    name.Delete(0, 3);\r\n    return ParsePropValue(name, value, _crcSize);\r\n  }\r\n  \r\n  UInt32 number;\r\n  int index = ParseStringToUInt32(name, number);\r\n  UString realName = name.Mid(index);\r\n  if (index == 0)\r\n  {\r\n    if(name.Left(2).CompareNoCase(L\"MT\") == 0)\r\n    {\r\n      #ifdef COMPRESS_MT\r\n      RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\r\n      #endif\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"RSFX\") == 0)  return SetBoolProperty(_removeSfxBlock, value);\r\n    if (name.CompareNoCase(L\"F\") == 0) return SetBoolProperty(_autoFilter, value);\r\n    if (name.CompareNoCase(L\"HC\") == 0) return SetBoolProperty(_compressHeaders, value);\r\n    if (name.CompareNoCase(L\"HCF\") == 0)\r\n    {\r\n      bool compressHeadersFull = true;\r\n      RINOK(SetBoolProperty(compressHeadersFull, value));\r\n      if (!compressHeadersFull)\r\n        return E_INVALIDARG;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"HE\") == 0)\r\n    {\r\n      RINOK(SetBoolProperty(_encryptHeaders, value));\r\n      _encryptHeadersSpecified = true;\r\n      return S_OK;\r\n    }\r\n    if (name.CompareNoCase(L\"TC\") == 0) return SetBoolProperty(WriteCTime, value);\r\n    if (name.CompareNoCase(L\"TA\") == 0) return SetBoolProperty(WriteATime, value);\r\n    if (name.CompareNoCase(L\"TM\") == 0) return SetBoolProperty(WriteMTime, value);\r\n    if (name.CompareNoCase(L\"V\") == 0) return SetBoolProperty(_volumeMode, value);\r\n    number = 0;\r\n  }\r\n  if (number > 10000)\r\n    return E_FAIL;\r\n  if (number < minNumber)\r\n    return E_INVALIDARG;\r\n  number -= minNumber;\r\n  for(int j = _methods.Size(); j <= (int)number; j++)\r\n  {\r\n    COneMethodInfo oneMethodInfo;\r\n    _methods.Add(oneMethodInfo);\r\n  }\r\n  \r\n  COneMethodInfo &oneMethodInfo = _methods[number];\r\n  \r\n  if (realName.Length() == 0)\r\n  {\r\n    if (value.vt != VT_BSTR)\r\n      return E_INVALIDARG;\r\n    \r\n    RINOK(SetParams(oneMethodInfo, value.bstrVal));\r\n  }\r\n  else\r\n  {\r\n    CProp prop;\r\n    if (realName.Left(1).CompareNoCase(L\"D\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize));\r\n      prop.Id = NCoderPropID::kDictionarySize;\r\n      prop.Value = dicSize;\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else if (realName.Left(1).CompareNoCase(L\"C\") == 0)\r\n    {\r\n      UInt32 blockSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, blockSize));\r\n      prop.Id = NCoderPropID::kBlockSize;\r\n      prop.Value = blockSize;\r\n    }\r\n    else if (realName.Left(3).CompareNoCase(L\"MEM\") == 0)\r\n    {\r\n      UInt32 dicSize;\r\n      RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize));\r\n      prop.Id = NCoderPropID::kUsedMemorySize;\r\n      prop.Value = dicSize;\r\n      if (number <= mainDicMethodIndex)\r\n        mainDicSize = dicSize;\r\n    }\r\n    else\r\n    {\r\n      int index = FindPropIdFromStringName(realName);\r\n      if (index < 0)\r\n        return E_INVALIDARG;\r\n      const CNameToPropID &nameToPropID = g_NameToPropID[index];\r\n      prop.Id = nameToPropID.PropID;\r\n      if (!ConvertProperty(value, nameToPropID.VarType, prop.Value))\r\n        return E_INVALIDARG;\r\n    }\r\n    oneMethodInfo.Props.Add(prop);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/HandlerOut.h",
    "content": "// HandlerOut.h\r\n\r\n#ifndef __HANDLER_OUT_H\r\n#define __HANDLER_OUT_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../Common/MethodProps.h\"\r\n\r\nnamespace NArchive {\r\n\r\nstruct COneMethodInfo\r\n{\r\n  CObjectVector<CProp> Props;\r\n  UString MethodName;\r\n};\r\n\r\nclass COutHandler\r\n{\r\npublic:\r\n  HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);\r\n  \r\n  HRESULT SetSolidSettings(const UString &s);\r\n  HRESULT SetSolidSettings(const PROPVARIANT &value);\r\n\r\n  #ifdef COMPRESS_MT\r\n  UInt32 _numThreads;\r\n  #endif\r\n\r\n  UInt32 _crcSize;\r\n\r\n  CObjectVector<COneMethodInfo> _methods;\r\n  bool _removeSfxBlock;\r\n  \r\n  UInt64 _numSolidFiles;\r\n  UInt64 _numSolidBytes;\r\n  bool _numSolidBytesDefined;\r\n  bool _solidExtension;\r\n\r\n  bool _compressHeaders;\r\n  bool _encryptHeadersSpecified;\r\n  bool _encryptHeaders;\r\n\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  bool _autoFilter;\r\n  UInt32 _level;\r\n\r\n  bool _volumeMode;\r\n\r\n  HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value);\r\n  HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);\r\n\r\n  void SetCompressionMethod2(COneMethodInfo &oneMethodInfo\r\n      #ifdef COMPRESS_MT\r\n      , UInt32 numThreads\r\n      #endif\r\n      );\r\n\r\n  void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }\r\n  void InitSolidSize()  { _numSolidBytes = (UInt64)(Int64)(-1); }\r\n  void InitSolid()\r\n  {\r\n    InitSolidFiles();\r\n    InitSolidSize();\r\n    _solidExtension = false;\r\n    _numSolidBytesDefined = false;\r\n  }\r\n\r\n  void Init();\r\n\r\n  COutHandler() { Init(); }\r\n\r\n  void BeforeSetProperty();\r\n\r\n  UInt32 minNumber;\r\n  UInt32 numProcessors;\r\n  UInt32 mainDicSize;\r\n  UInt32 mainDicMethodIndex;\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.cpp",
    "content": "// InStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  if (size > 0 && realProcessedSize == 0)\r\n    _wasFinished = true;\r\n  _size += realProcessedSize;\r\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if (seekOrigin != STREAM_SEEK_SET || offset != 0)\r\n    return E_FAIL;\r\n  _size = 0;\r\n  _crc = CRC_INIT_VAL;\r\n  return _stream->Seek(offset, seekOrigin, newPosition);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/InStreamWithCRC.h",
    "content": "// InStreamWithCRC.h\r\n\r\n#ifndef __INSTREAMWITHCRC_H\r\n#define __INSTREAMWITHCRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass CSequentialInStreamWithCRC:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CInStreamWithCRC:\r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\nprivate:\r\n  CMyComPtr<IInStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(IInStream *stream) { _stream = stream;  }\r\n  void Init()\r\n  {\r\n    _size = 0;\r\n    _wasFinished = false;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n  UInt64 GetSize() const { return _size; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/ItemNameUtils.cpp",
    "content": "// Archive/Common/ItemNameUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ItemNameUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\nstatic const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;\r\nstatic const wchar_t kDirDelimiter = L'/';\r\n\r\nUString MakeLegalName(const UString &name)\r\n{\r\n  UString zipName = name;\r\n  zipName.Replace(kOSDirDelimiter, kDirDelimiter);\r\n  return zipName;\r\n}\r\n\r\nUString GetOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(kDirDelimiter, kOSDirDelimiter);\r\n  return newName;\r\n}\r\n\r\nUString GetOSName2(const UString &name)\r\n{\r\n  if (name.IsEmpty())\r\n    return UString();\r\n  UString newName = GetOSName(name);\r\n  if (newName[newName.Length() - 1] == kOSDirDelimiter)\r\n    newName.Delete(newName.Length() - 1);\r\n  return newName;\r\n}\r\n\r\nbool HasTailSlash(const AString &name, UINT codePage)\r\n{\r\n  if (name.IsEmpty())\r\n    return false;\r\n  LPCSTR prev =\r\n  #ifdef _WIN32\r\n    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);\r\n  #else\r\n    (LPCSTR)(name) + (name.Length() - 1);\r\n  #endif\r\n  return (*prev == '/');\r\n}\r\n\r\n#ifndef _WIN32\r\nUString WinNameToOSName(const UString &name)\r\n{\r\n  UString newName = name;\r\n  newName.Replace(L'\\\\', kOSDirDelimiter);\r\n  return newName;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/ItemNameUtils.h",
    "content": "// Archive/Common/ItemNameUtils.h\r\n\r\n#ifndef __ARCHIVE_ITEMNAMEUTILS_H\r\n#define __ARCHIVE_ITEMNAMEUTILS_H\r\n\r\n#include \"../../../Common/MyString.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NItemName {\r\n\r\n  UString MakeLegalName(const UString &name);\r\n  UString GetOSName(const UString &name);\r\n  UString GetOSName2(const UString &name);\r\n  bool HasTailSlash(const AString &name, UINT codePage);\r\n\r\n  #ifdef _WIN32\r\n  inline UString WinNameToOSName(const UString &name)  { return name; }\r\n  #else\r\n  UString WinNameToOSName(const UString &name);\r\n  #endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/MultiStream.cpp",
    "content": "// MultiStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MultiStream.h\"\r\n\r\nSTDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(_streamIndex < Streams.Size() && size > 0)\r\n  {\r\n    CSubStreamInfo &s = Streams[_streamIndex];\r\n    if (_pos == s.Size)\r\n    {\r\n      _streamIndex++;\r\n      _pos = 0;\r\n      continue;\r\n    }\r\n    RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));\r\n    UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));\r\n    UInt32 realProcessed;\r\n    HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    _pos += realProcessed;\r\n    _seekPos += realProcessed;\r\n    RINOK(result);\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 newPos;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      newPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      newPos = _seekPos + offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      newPos = _totalLength + offset;\r\n      break;\r\n    default:\r\n      return STG_E_INVALIDFUNCTION;\r\n  }\r\n  _seekPos = 0;\r\n  for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)\r\n  {\r\n    UInt64 size = Streams[_streamIndex].Size;\r\n    if (newPos < _seekPos + size)\r\n    {\r\n      _pos = newPos - _seekPos;\r\n      _seekPos += _pos;\r\n      if (newPosition != 0)\r\n        *newPosition = newPos;\r\n      return S_OK;\r\n    }\r\n    _seekPos += size;\r\n  }\r\n  if (newPos == _seekPos)\r\n  {\r\n    if (newPosition != 0)\r\n      *newPosition = newPos;\r\n    return S_OK;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\n\r\n/*\r\nclass COutVolumeStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _volIndex;\r\n  UInt64 _volSize;\r\n  UInt64 _curPos;\r\n  CMyComPtr<ISequentialOutStream> _volumeStream;\r\n  COutArchive _archive;\r\n  CCRC _crc;\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  CFileItem _file;\r\n  CUpdateOptions _options;\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init(IArchiveUpdateCallback2 *volumeCallback,\r\n      const UString &name)\r\n  {\r\n    _file.Name = name;\r\n    _file.IsStartPosDefined = true;\r\n    _file.StartPos = 0;\r\n    \r\n    VolumeCallback = volumeCallback;\r\n    _volIndex = 0;\r\n    _volSize = 0;\r\n  }\r\n  \r\n  HRESULT Flush();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nHRESULT COutVolumeStream::Flush()\r\n{\r\n  if (_volumeStream)\r\n  {\r\n    _file.UnPackSize = _curPos;\r\n    _file.FileCRC = _crc.GetDigest();\r\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\r\n    _archive.Close();\r\n    _volumeStream.Release();\r\n    _file.StartPos += _file.UnPackSize;\r\n  }\r\n  return S_OK;\r\n}\r\n*/\r\n\r\n/*\r\nSTDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));\r\n      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));\r\n      subStream.Pos = 0;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n    if (_offsetPos >= subStream.Size)\r\n    {\r\n      _offsetPos -= subStream.Size;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      CMyComPtr<IOutStream> outStream;\r\n      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == subStream.Size)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed != curSize && realProcessed == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/MultiStream.h",
    "content": "// MultiStream.h\r\n\r\n#ifndef __MULTISTREAM_H\r\n#define __MULTISTREAM_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyVector.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nclass CMultiStream:\r\n  public IInStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex;\r\n  UInt64 _pos;\r\n  UInt64 _seekPos;\r\n  UInt64 _totalLength;\r\npublic:\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<IInStream> Stream;\r\n    UInt64 Pos;\r\n    UInt64 Size;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _pos = 0;\r\n    _seekPos = 0;\r\n    _totalLength = 0;\r\n    for (int i = 0; i < Streams.Size(); i++)\r\n      _totalLength += Streams[i].Size;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IInStream)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n\r\n/*\r\nclass COutMultiStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    CMyComPtr<ISequentialOutStream> Stream;\r\n    UInt64 Size;\r\n    UInt64 Pos;\r\n };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp",
    "content": "// OutStreamWithCRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutStreamWithCRC.h\"\r\n\r\nSTDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result;\r\n  if(!_stream)\r\n  {\r\n    realProcessedSize = size;\r\n    result = S_OK;\r\n  }\r\n  else\r\n    result = _stream->Write(data, size, &realProcessedSize);\r\n  if (_calculate)\r\n    _crc = CrcUpdate(_crc, data, realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/OutStreamWithCRC.h",
    "content": "// OutStreamWithCRC.h\r\n\r\n#ifndef __OUT_STREAM_WITH_CRC_H\r\n#define __OUT_STREAM_WITH_CRC_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../IStream.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n}\r\n\r\nclass COutStreamWithCRC:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  UInt32 _crc;\r\n  bool _calculate;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(bool calculate = true)\r\n  {\r\n    _size = 0;\r\n    _calculate = calculate;\r\n    _crc = CRC_INIT_VAL;\r\n  }\r\n  void InitCRC() { _crc = CRC_INIT_VAL; }\r\n  UInt64 GetSize() const { return _size; }\r\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/ParseProperties.cpp",
    "content": "// ParseProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ParseProperties.h\"\r\n\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (prop.vt == VT_UI4)\r\n  {\r\n    if (!name.IsEmpty())\r\n      return E_INVALIDARG;\r\n    resValue = prop.ulVal;\r\n  }\r\n  else if (prop.vt == VT_EMPTY)\r\n  {\r\n    if(!name.IsEmpty())\r\n    {\r\n      const wchar_t *start = name;\r\n      const wchar_t *end;\r\n      UInt64 v = ConvertStringToUInt64(start, &end);\r\n      if (end - start != name.Length())\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)v;\r\n    }\r\n  }\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kLogarithmicSizeLimit = 32;\r\nstatic const wchar_t kByteSymbol = L'B';\r\nstatic const wchar_t kKiloByteSymbol = L'K';\r\nstatic const wchar_t kMegaByteSymbol = L'M';\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)\r\n{\r\n  UString srcString = srcStringSpec;\r\n  srcString.MakeUpper();\r\n\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || srcString.Length() > numDigits + 1)\r\n    return E_INVALIDARG;\r\n  if (srcString.Length() == numDigits)\r\n  {\r\n    if (number >= kLogarithmicSizeLimit)\r\n      return E_INVALIDARG;\r\n    dicSize = (UInt32)1 << (int)number;\r\n    return S_OK;\r\n  }\r\n  switch (srcString[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      if (number >= ((UInt64)1 << kLogarithmicSizeLimit))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)number;\r\n      break;\r\n    case kKiloByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 10);\r\n      break;\r\n    case kMegaByteSymbol:\r\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))\r\n        return E_INVALIDARG;\r\n      dicSize = (UInt32)(number << 20);\r\n      break;\r\n    default:\r\n      return E_INVALIDARG;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    if (prop.vt == VT_UI4)\r\n    {\r\n      UInt32 logDicSize = prop.ulVal;\r\n      if (logDicSize >= 32)\r\n        return E_INVALIDARG;\r\n      resValue = (UInt32)1 << logDicSize;\r\n      return S_OK;\r\n    }\r\n    if (prop.vt == VT_BSTR)\r\n      return ParsePropDictionaryValue(prop.bstrVal, resValue);\r\n    return E_INVALIDARG;\r\n  }\r\n  return ParsePropDictionaryValue(name, resValue);\r\n}\r\n\r\nbool StringToBool(const UString &s, bool &res)\r\n{\r\n  if (s.IsEmpty() || s.CompareNoCase(L\"ON\") == 0 || s.Compare(L\"+\") == 0)\r\n  {\r\n    res = true;\r\n    return true;\r\n  }\r\n  if (s.CompareNoCase(L\"OFF\") == 0 || s.Compare(L\"-\") == 0)\r\n  {\r\n    res = false;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)\r\n{\r\n  switch(value.vt)\r\n  {\r\n    case VT_EMPTY:\r\n      dest = true;\r\n      return S_OK;\r\n    case VT_BOOL:\r\n      dest = (value.boolVal != VARIANT_FALSE);\r\n      return S_OK;\r\n    /*\r\n    case VT_UI4:\r\n      dest = (value.ulVal != 0);\r\n      break;\r\n    */\r\n    case VT_BSTR:\r\n      return StringToBool(value.bstrVal, dest) ?  S_OK : E_INVALIDARG;\r\n  }\r\n  return E_INVALIDARG;\r\n}\r\n\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number)\r\n{\r\n  const wchar_t *start = srcString;\r\n  const wchar_t *end;\r\n  UInt64 number64 = ConvertStringToUInt64(start, &end);\r\n  if (number64 > 0xFFFFFFFF)\r\n  {\r\n    number = 0;\r\n    return 0;\r\n  }\r\n  number = (UInt32)number64;\r\n  return (int)(end - start);\r\n}\r\n\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)\r\n{\r\n  if (name.IsEmpty())\r\n  {\r\n    switch(prop.vt)\r\n    {\r\n      case VT_UI4:\r\n        numThreads = prop.ulVal;\r\n        break;\r\n      default:\r\n      {\r\n        bool val;\r\n        RINOK(SetBoolProperty(val, prop));\r\n        numThreads = (val ? defaultNumThreads : 1);\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    UInt32 number;\r\n    int index = ParseStringToUInt32(name, number);\r\n    if (index != name.Length())\r\n      return E_INVALIDARG;\r\n    numThreads = number;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/ParseProperties.h",
    "content": "// ParseProperties.h\r\n\r\n#ifndef __PARSEPROPERTIES_H\r\n#define __PARSEPROPERTIES_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n\r\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);\r\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\r\n\r\nbool StringToBool(const UString &s, bool &res);\r\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);\r\nint ParseStringToUInt32(const UString &srcString, UInt32 &number);\r\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/DllExports2.cpp",
    "content": "// DLLExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyInitGuid.h\"\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Common/Types.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\n#include \"IArchive.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\nHINSTANCE g_hInstance;\r\n#ifndef _UNICODE\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)\r\n{\r\n  if (dwReason == DLL_PROCESS_ATTACH)\r\n  {\r\n    g_hInstance = hInstance;\r\n    #ifndef _UNICODE\r\n    #ifdef _WIN32\r\n    g_IsNT = IsItWindowsNT();\r\n    #endif\r\n    #endif\r\n  }\r\n  return TRUE;\r\n}\r\n\r\nDEFINE_GUID(CLSID_CArchiveHandler,\r\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec,\r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);\r\nSTDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);\r\n\r\nSTDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  // COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)\r\n  {\r\n    return CreateCoder(clsid, iid, outObject);\r\n  }\r\n  else\r\n  {\r\n    return CreateArchiver(clsid, iid, outObject);\r\n  }\r\n  // COM_TRY_END\r\n}\r\n\r\nSTDAPI SetLargePageMode()\r\n{\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  SetLargePageSize();\r\n  #endif\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/IArchive.h",
    "content": "// IArchive.h\r\n\r\n#ifndef __IARCHIVE_H\r\n#define __IARCHIVE_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../IProgress.h\"\r\n#include \"../PropID.h\"\r\n\r\n#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)\r\n#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nnamespace NFileTimeType\r\n{\r\n  enum EEnum\r\n  {\r\n    kWindows,\r\n    kUnix,\r\n    kDOS\r\n  };\r\n}\r\n\r\nnamespace NArchive\r\n{\r\n  enum\r\n  {\r\n    kName = 0,\r\n    kClassID,\r\n    kExtension,\r\n    kAddExtension,\r\n    kUpdate,\r\n    kKeepName,\r\n    kStartSignature,\r\n    kFinishSignature,\r\n    kAssociate\r\n  };\r\n\r\n  namespace NExtract\r\n  {\r\n    namespace NAskMode\r\n    {\r\n      enum\r\n      {\r\n        kExtract = 0,\r\n        kTest,\r\n        kSkip\r\n      };\r\n    }\r\n    namespace NOperationResult\r\n    {\r\n      enum\r\n      {\r\n        kOK = 0,\r\n        kUnSupportedMethod,\r\n        kDataError,\r\n        kCRCError\r\n      };\r\n    }\r\n  }\r\n  namespace NUpdate\r\n  {\r\n    namespace NOperationResult\r\n    {\r\n      enum\r\n      {\r\n        kOK = 0,\r\n        kError\r\n      };\r\n    }\r\n  }\r\n}\r\n\r\n#define INTERFACE_IArchiveOpenCallback(x) \\\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) x; \\\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)\r\n{\r\n  INTERFACE_IArchiveOpenCallback(PURE);\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveExtractCallback(x) \\\r\n  INTERFACE_IProgress(x) \\\r\n  /* GetStream OUT: S_OK - OK, S_FALSE - skeep this file */ \\\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream,  Int32 askExtractMode) x; \\\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode) x; \\\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)\r\n{\r\n  INTERFACE_IArchiveExtractCallback(PURE)\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveOpenVolumeCallback(x) \\\r\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) x; \\\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)\r\n{\r\n  INTERFACE_IArchiveOpenVolumeCallback(PURE);\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)\r\n{\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)\r\n{\r\n  STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;\r\n};\r\n\r\n\r\n/*\r\nIInArchive::Extract:\r\n  indices must be sorted\r\n  numItems = 0xFFFFFFFF means \"all files\"\r\n  testMode != 0 means \"test files without writing to outStream\"\r\n*/\r\n\r\n#define INTERFACE_IInArchive(x) \\\r\n  STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \\\r\n  STDMETHOD(Close)() x; \\\r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \\\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \\\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \\\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;\r\n\r\nARCHIVE_INTERFACE(IInArchive, 0x60)\r\n{\r\n  INTERFACE_IInArchive(PURE)\r\n};\r\n\r\n\r\n#define INTERFACE_IArchiveUpdateCallback(x) \\\r\n  INTERFACE_IProgress(x); \\\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,  \\\r\n      Int32 *newData, /*1 - new data, 0 - old data */ \\\r\n      Int32 *newProperties, /* 1 - new properties, 0 - old properties */ \\\r\n      UInt32 *indexInArchive /* -1 if there is no in archive, or if doesn't matter */ \\\r\n      )  x; \\\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) x; \\\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)\r\n{\r\n  INTERFACE_IArchiveUpdateCallback(PURE);\r\n};\r\n\r\n#define INTERFACE_IArchiveUpdateCallback2(x) \\\r\n  INTERFACE_IArchiveUpdateCallback(x) \\\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) x; \\\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) x; \\\r\n\r\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)\r\n{\r\n  INTERFACE_IArchiveUpdateCallback2(PURE);\r\n};\r\n\r\n\r\n#define INTERFACE_IOutArchive(x) \\\r\n  STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \\\r\n  STDMETHOD(GetFileTimeType)(UInt32 *type) x;\r\n\r\nARCHIVE_INTERFACE(IOutArchive, 0xA0)\r\n{\r\n  INTERFACE_IOutArchive(PURE)\r\n};\r\n\r\n\r\nARCHIVE_INTERFACE(ISetProperties, 0x03)\r\n{\r\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;\r\n};\r\n\r\n\r\n#define IMP_IInArchive_GetProp(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \\\r\n\r\n#define IMP_IInArchive_GetProp_WITH_NAME(k) \\\r\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\r\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\r\n    const STATPROPSTG &srcItem = k[index]; \\\r\n    *propID = srcItem.propid; *varType = srcItem.vt; \\\r\n    if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \\\r\n\r\n#define IMP_IInArchive_Props \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)\r\n\r\n#define IMP_IInArchive_Props_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)\r\n\r\n\r\n#define IMP_IInArchive_ArcProps \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_WITH_NAME \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kArcProps)\r\n\r\n#define IMP_IInArchive_ArcProps_NO \\\r\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\r\n    { *numProperties = 0; return S_OK; } \\\r\n  STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \\\r\n    { return E_NOTIMPL; } \\\r\n  STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \\\r\n    { value->vt = VT_EMPTY; return S_OK; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp",
    "content": "// LzmaArcRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"LzmaHandler.h\"\r\n\r\nstatic IInArchive *CreateArc() { return new NArchive::NLzma::CHandler;  }\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n  { L\"Lzma\", L\"lzma lzma86\", 0, 0xA, {0 }, 0, true, CreateArc, NULL };\r\n\r\nREGISTER_ARC(Lzma)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp",
    "content": "// LzmaFiltersDecode.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaFiltersDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nstatic const UInt64 k_LZMA = 0x030101;\r\nstatic const UInt64 k_BCJ = 0x03030103;\r\n  \r\nHRESULT CDecoder::Code(\r\n    DECL_EXTERNAL_CODECS_LOC_VARS\r\n    const CHeader &block,\r\n    ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    UInt64 *inProcessedSize, ICompressProgressInfo *progress)\r\n{\r\n  *inProcessedSize = (UInt64)(Int64)-1;\r\n\r\n  if (block.FilterMethod > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (!_lzmaDecoder)\r\n  {\r\n    RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_LZMA, _lzmaDecoder, false));\r\n    if (_lzmaDecoder == 0)\r\n      return E_NOTIMPL;\r\n  }\r\n\r\n  {\r\n    CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\r\n    _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\r\n    if (!setDecoderProperties)\r\n      return E_NOTIMPL;\r\n    RINOK(setDecoderProperties->SetDecoderProperties2(block.LzmaProps, 5));\r\n  }\r\n\r\n  bool filteredMode = (block.FilterMethod == 1);\r\n\r\n  CMyComPtr<ICompressSetOutStream> setOutStream;\r\n\r\n  if (filteredMode)\r\n  {\r\n    if (!_bcjStream)\r\n    {\r\n      CMyComPtr<ICompressCoder> coder;\r\n      RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_BCJ, coder, false));\r\n      if (!coder)\r\n        return E_NOTIMPL;\r\n      coder.QueryInterface(IID_ISequentialOutStream, &_bcjStream);\r\n      if (!_bcjStream)\r\n        return E_NOTIMPL;\r\n    }\r\n\r\n    _bcjStream.QueryInterface(IID_ICompressSetOutStream, &setOutStream);\r\n    if (!setOutStream)\r\n      return E_NOTIMPL;\r\n    RINOK(setOutStream->SetOutStream(outStream));\r\n    outStream = _bcjStream;\r\n  }\r\n\r\n  const UInt64 *unpackSize = block.HasUnpackSize() ? &block.UnpackSize : NULL;\r\n  RINOK(_lzmaDecoder->Code(inStream, outStream, NULL, unpackSize, progress));\r\n\r\n  if (filteredMode)\r\n  {\r\n    CMyComPtr<IOutStreamFlush> flush;\r\n    _bcjStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n    if (flush)\r\n    {\r\n      RINOK(flush->Flush());\r\n    }\r\n    RINOK(setOutStream->ReleaseOutStream());\r\n  }\r\n\r\n  CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;\r\n  _lzmaDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);\r\n  if (getInStreamProcessedSize)\r\n  {\r\n    RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(inProcessedSize));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h",
    "content": "// LzmaFiltersDecode.h\r\n\r\n#ifndef __LZMA_FILTERS_DECODE_H\r\n#define __LZMA_FILTERS_DECODE_H\r\n\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"LzmaItem.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nclass CDecoder\r\n{\r\n  CMyComPtr<ICompressCoder> _lzmaDecoder;\r\n  CMyComPtr<ISequentialOutStream> _bcjStream;\r\npublic:\r\n  HRESULT Code(DECL_EXTERNAL_CODECS_LOC_VARS\r\n      const CHeader &block,\r\n      ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      UInt64 *inProcessedSize, ICompressProgressInfo *progress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Lzma/LzmaHandler.cpp",
    "content": "// LzmaHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaHandler.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n#include \"../Common/DummyOutStream.h\"\r\n\r\n#include \"LzmaFiltersDecode.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nSTATPROPSTG kProps[] =\r\n{\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidPackSize, VT_UI8},\r\n  { NULL, kpidMethod, VT_UI1}\r\n};\r\n\r\nIMP_IInArchive_Props\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = 1;\r\n  return S_OK;\r\n}\r\n\r\nstatic void ConvertUInt32ToString(UInt32 value, wchar_t *s)\r\n{\r\n  ConvertUInt64ToString(value, s + MyStringLen(s));\r\n}\r\n\r\nstatic void DictSizeToString(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i <= 31; i++)\r\n    if ((UInt32(1) << i) == value)\r\n    {\r\n      ConvertUInt32ToString(i, s);\r\n      return;\r\n    }\r\n  wchar_t c = L'b';\r\n  if ((value & ((1 << 20) - 1)) == 0)\r\n  {\r\n    value >>= 20;\r\n    c = L'm';\r\n  }\r\n  else if ((value & ((1 << 10) - 1)) == 0)\r\n  {\r\n    value >>= 10;\r\n    c = L'k';\r\n  }\r\n  ConvertUInt32ToString(value, s);\r\n  int p = MyStringLen(s);\r\n  s[p++] = c;\r\n  s[p++] = L'\\0';\r\n}\r\n\r\nstatic void MyStrCat(wchar_t *d, const wchar_t *s)\r\n{\r\n  MyStringCopy(d + MyStringLen(d), s);\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  NWindows::NCOM::CPropVariant propVariant;\r\n  switch(propID)\r\n  {\r\n    case kpidSize:\r\n      if (m_StreamInfo.HasUnpackSize())\r\n        propVariant = (UInt64)m_StreamInfo.UnpackSize;\r\n      break;\r\n    case kpidPackSize:\r\n      propVariant = (UInt64)m_PackSize;\r\n      break;\r\n    case kpidMethod:\r\n    {\r\n      wchar_t s[64];\r\n      s[0] = '\\0';\r\n      if (m_StreamInfo.IsThereFilter)\r\n      {\r\n        const wchar_t *f;\r\n        if (m_StreamInfo.FilterMethod == 0)\r\n          f = L\"Copy\";\r\n        else if (m_StreamInfo.FilterMethod == 1)\r\n          f = L\"BCJ\";\r\n        else\r\n          f = L\"Unknown\";\r\n        MyStrCat(s, f);\r\n        MyStrCat(s, L\" \");\r\n      }\r\n      MyStrCat(s, L\"LZMA:\");\r\n      DictSizeToString(m_StreamInfo.GetDicSize(), s);\r\n      propVariant = s;\r\n      break;\r\n    }\r\n  }\r\n  propVariant.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *inStream,\r\n    const UInt64 * /* maxCheckStartPosition */,\r\n    IArchiveOpenCallback * /* openArchiveCallback */)\r\n{\r\n  {\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));\r\n\r\n    HRESULT res = ReadStreamHeader(inStream, m_StreamInfo);\r\n    if (res != S_OK)\r\n      return S_FALSE;\r\n    \r\n    Byte b;\r\n    RINOK(ReadStream_FALSE(inStream, &b, 1));\r\n    if (b != 0)\r\n      return S_FALSE;\r\n\r\n    UInt64 endPos;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));\r\n    m_PackSize = endPos - m_StreamStartPosition - m_StreamInfo.GetHeaderSize();\r\n\r\n    m_Stream = inStream;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  m_Stream.Release();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 _aTestMode, IArchiveExtractCallback *extractCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  bool allFilesMode = (numItems == UInt32(-1));\r\n  if (!allFilesMode)\r\n  {\r\n    if (numItems == 0)\r\n      return S_OK;\r\n    if (numItems != 1)\r\n      return E_INVALIDARG;\r\n    if (indices[0] != 0)\r\n      return E_INVALIDARG;\r\n  }\r\n\r\n  bool testMode = (_aTestMode != 0);\r\n\r\n  RINOK(extractCallback->SetTotal(m_PackSize));\r\n    \r\n  UInt64 currentTotalPacked = 0;\r\n\r\n  CDummyOutStream *outStreamSpec = new CDummyOutStream;\r\n  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n\r\n  {\r\n    CMyComPtr<ISequentialOutStream> realOutStream;\r\n    Int32 askMode = testMode ?\r\n        NArchive::NExtract::NAskMode::kTest :\r\n        NArchive::NExtract::NAskMode::kExtract;\r\n    \r\n    RINOK(extractCallback->GetStream(0, &realOutStream, askMode));\r\n\r\n    outStreamSpec->SetStream(realOutStream);\r\n    outStreamSpec->Init();\r\n    if(!testMode && !realOutStream)\r\n      return S_OK;\r\n    extractCallback->PrepareOperation(askMode);\r\n  }\r\n  \r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, true);\r\n\r\n  CDecoder decoder;\r\n  RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));\r\n  UInt64 streamPos = m_StreamStartPosition;\r\n  Int32 opRes = NArchive::NExtract::NOperationResult::kOK;\r\n  bool firstItem = true;\r\n  for (;;)\r\n  {\r\n    CHeader st;\r\n    HRESULT result = ReadStreamHeader(m_Stream, st);\r\n    if (result != S_OK)\r\n    {\r\n      if (firstItem)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    firstItem = false;\r\n\r\n    lps->OutSize = outStreamSpec->GetSize();\r\n    lps->InSize = currentTotalPacked;\r\n    RINOK(lps->SetCur());\r\n    \r\n    streamPos += st.GetHeaderSize();\r\n    UInt64 packProcessed;\r\n\r\n    {\r\n      result = decoder.Code(\r\n          EXTERNAL_CODECS_VARS\r\n          st, m_Stream, outStream, &packProcessed, progress);\r\n      if (result == E_NOTIMPL)\r\n      {\r\n        opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;\r\n        break;\r\n      }\r\n      if (result == S_FALSE)\r\n      {\r\n        opRes = NArchive::NExtract::NOperationResult::kDataError;\r\n        break;\r\n      }\r\n      RINOK(result);\r\n    }\r\n\r\n    if (packProcessed == (UInt64)(Int64)-1)\r\n      break;\r\n    RINOK(m_Stream->Seek(streamPos + packProcessed, STREAM_SEEK_SET, NULL));\r\n    currentTotalPacked += packProcessed;\r\n    streamPos += packProcessed;\r\n  }\r\n  outStream.Release();\r\n  return extractCallback->SetOperationResult(opRes);\r\n  COM_TRY_END\r\n}\r\n\r\nIMPL_ISetCompressCodecsInfo\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Lzma/LzmaHandler.h",
    "content": "// Lzma/Handler.h\r\n\r\n#ifndef __GZIP_HANDLER_H\r\n#define __GZIP_HANDLER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../IArchive.h\"\r\n#include \"../../Common/CreateCoder.h\"\r\n\r\n#include \"LzmaIn.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\n// const UInt64 k_LZMA = 0x030101;\r\n\r\nclass CHandler:\r\n  public IInArchive,\r\n  PUBLIC_ISetCompressCodecsInfo\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n  MY_QUERYINTERFACE_ENTRY(IInArchive)\r\n  QUERY_ENTRY_ISetCompressCodecsInfo\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  STDMETHOD(Open)(IInStream *inStream,\r\n      const UInt64 *maxCheckStartPosition,\r\n      IArchiveOpenCallback *openArchiveCallback);\r\n  STDMETHOD(Close)();\r\n  \r\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID,  PROPVARIANT *value);\r\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems,\r\n      Int32 testMode, IArchiveExtractCallback *extractCallback);\r\n\r\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);\r\n\r\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties);\r\n  STDMETHOD(GetPropertyInfo)(UInt32 index,\r\n      BSTR *name, PROPID *propID, VARTYPE *varType);\r\n\r\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties);\r\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index,\r\n      BSTR *name, PROPID *propID, VARTYPE *varType);\r\n\r\n  UString GetMethodString();\r\npublic:\r\n  CHandler() {  }\r\n\r\nprivate:\r\n  CHeader m_StreamInfo;\r\n  UInt64 m_StreamStartPosition;\r\n  UInt64 m_PackSize;\r\n\r\n  CMyComPtr<IInStream> m_Stream;\r\n\r\n  DECL_EXTERNAL_CODECS_VARS\r\n\r\n  DECL_ISetCompressCodecsInfo\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Lzma/LzmaIn.cpp",
    "content": "// Archive/LzmaIn.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaIn.h\"\r\n\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n \r\nstatic bool CheckDictSize(const Byte *p)\r\n{\r\n  UInt32 dicSize = GetUi32(p);\r\n  int i;\r\n  for (i = 1; i <= 30; i++)\r\n    if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block)\r\n{\r\n  Byte sig[5 + 9];\r\n  RINOK(ReadStream_FALSE(inStream, sig, 5 + 8));\r\n\r\n  const Byte kMaxProp0Val = 5 * 5 * 9 - 1;\r\n  if (sig[0] > kMaxProp0Val)\r\n    return S_FALSE;\r\n\r\n  for (int i = 0; i < 5; i++)\r\n    block.LzmaProps[i] = sig[i];\r\n  \r\n  block.IsThereFilter = false;\r\n  block.FilterMethod = 0;\r\n\r\n  if (!CheckDictSize(sig + 1))\r\n  {\r\n    if (sig[0] > 1 || sig[1] > kMaxProp0Val)\r\n      return S_FALSE;\r\n    block.IsThereFilter = true;\r\n    block.FilterMethod = sig[0];\r\n    for (int i = 0; i < 5; i++)\r\n      block.LzmaProps[i] = sig[i + 1];\r\n    if (!CheckDictSize(block.LzmaProps + 1))\r\n      return S_FALSE;\r\n    RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1));\r\n  }\r\n  UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0);\r\n  block.UnpackSize = GetUi64(sig + unpOffset);\r\n  if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56))\r\n    return S_FALSE;\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Lzma/LzmaIn.h",
    "content": "// Archive/LzmaIn.h\r\n\r\n#ifndef __ARCHIVE_LZMA_IN_H\r\n#define __ARCHIVE_LZMA_IN_H\r\n\r\n#include \"LzmaItem.h\"\r\n#include \"../../IStream.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &st);\r\n\r\n}}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Lzma/LzmaItem.h",
    "content": "// Archive/LzmaItem.h\r\n\r\n#ifndef __ARCHIVE_LZMA_ITEM_H\r\n#define __ARCHIVE_LZMA_ITEM_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\n#include \"../../../../C/CpuArch.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NLzma {\r\n\r\nstruct CHeader\r\n{\r\n  UInt64 UnpackSize;\r\n  bool IsThereFilter;\r\n  Byte FilterMethod;\r\n  Byte LzmaProps[5];\r\n\r\n  UInt32 GetDicSize() const { return GetUi32(LzmaProps + 1); }\r\n  bool HasUnpackSize() const { return (UnpackSize != (UInt64)(Int64)-1);  }\r\n  unsigned GetHeaderSize() const { return 5 + 8 + (IsThereFilter ? 1 : 0); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Lzma/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Split/SplitHandler.cpp",
    "content": "// SplitHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/ComTry.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"../../Common/ProgressUtils.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/ItemNameUtils.h\"\r\n#include \"../Common/MultiStream.h\"\r\n\r\n#include \"SplitHandler.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\nSTATPROPSTG kProps[] =\r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidPackSize, VT_UI8},\r\n};\r\n\r\nIMP_IInArchive_Props\r\nIMP_IInArchive_ArcProps_NO\r\n\r\nclass CSeqName\r\n{\r\npublic:\r\n  UString _unchangedPart;\r\n  UString _changedPart;\r\n  bool _splitStyle;\r\n  UString GetNextName()\r\n  {\r\n    UString newName;\r\n    if (_splitStyle)\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == 'z')\r\n        {\r\n          c = 'a';\r\n          newName = c + newName;\r\n          continue;\r\n        }\r\n        else if (c == 'Z')\r\n        {\r\n          c = 'A';\r\n          newName = c + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        if ((c == 'z' || c == 'Z') && i == 0)\r\n        {\r\n          _unchangedPart += c;\r\n          wchar_t newChar = (c == 'z') ? L'a' : L'A';\r\n          newName.Empty();\r\n          numLetters++;\r\n          for (int k = 0; k < numLetters; k++)\r\n            newName += newChar;\r\n          break;\r\n        }\r\n        newName = c + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      int i;\r\n      int numLetters = _changedPart.Length();\r\n      for (i = numLetters - 1; i >= 0; i--)\r\n      {\r\n        wchar_t c = _changedPart[i];\r\n        if (c == L'9')\r\n        {\r\n          c = L'0';\r\n          newName = c + newName;\r\n          if (i == 0)\r\n            newName = UString(L'1') + newName;\r\n          continue;\r\n        }\r\n        c++;\r\n        newName = c + newName;\r\n        i--;\r\n        for (; i >= 0; i--)\r\n          newName = _changedPart[i] + newName;\r\n        break;\r\n      }\r\n    }\r\n    _changedPart = newName;\r\n    return _unchangedPart + _changedPart;\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CHandler::Open(IInStream *stream,\r\n    const UInt64 * /* maxCheckStartPosition */,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n  Close();\r\n  if (openArchiveCallback == 0)\r\n    return S_FALSE;\r\n  // try\r\n  {\r\n    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;\r\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openArchiveCallback;\r\n    if (openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback,\r\n        &openVolumeCallback) != S_OK)\r\n      return S_FALSE;\r\n    \r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(openVolumeCallback->GetProperty(kpidName, &prop));\r\n      if (prop.vt != VT_BSTR)\r\n        return S_FALSE;\r\n      _name = prop.bstrVal;\r\n    }\r\n    \r\n    int dotPos = _name.ReverseFind('.');\r\n    UString prefix, ext;\r\n    if (dotPos >= 0)\r\n    {\r\n      prefix = _name.Left(dotPos + 1);\r\n      ext = _name.Mid(dotPos + 1);\r\n    }\r\n    else\r\n      ext = _name;\r\n    UString extBig = ext;\r\n    extBig.MakeUpper();\r\n\r\n    CSeqName seqName;\r\n\r\n    int numLetters = 2;\r\n    bool splitStyle = false;\r\n    if (extBig.Right(2) == L\"AA\")\r\n    {\r\n      splitStyle = true;\r\n      while (numLetters < extBig.Length())\r\n      {\r\n        if (extBig[extBig.Length() - numLetters - 1] != 'A')\r\n          break;\r\n        numLetters++;\r\n      }\r\n    }\r\n    else if (ext.Right(2) == L\"01\")\r\n    {\r\n      while (numLetters < extBig.Length())\r\n      {\r\n        if (extBig[extBig.Length() - numLetters - 1] != '0')\r\n          break;\r\n        numLetters++;\r\n      }\r\n      if (numLetters != ext.Length())\r\n        return S_FALSE;\r\n    }\r\n    else\r\n      return S_FALSE;\r\n\r\n    _streams.Add(stream);\r\n\r\n    seqName._unchangedPart = prefix + ext.Left(extBig.Length() - numLetters);\r\n    seqName._changedPart = ext.Right(numLetters);\r\n    seqName._splitStyle = splitStyle;\r\n\r\n    if (prefix.Length() < 1)\r\n      _subName = L\"file\";\r\n    else\r\n      _subName = prefix.Left(prefix.Length() - 1);\r\n\r\n    _totalSize = 0;\r\n    UInt64 size;\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\r\n      if (prop.vt != VT_UI8)\r\n        return E_INVALIDARG;\r\n      size = prop.uhVal.QuadPart;\r\n    }\r\n    _totalSize += size;\r\n    _sizes.Add(size);\r\n    \r\n    if (openArchiveCallback != NULL)\r\n    {\r\n      UInt64 numFiles = _streams.Size();\r\n      RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\r\n    }\r\n\r\n    for (;;)\r\n    {\r\n      UString fullName = seqName.GetNextName();\r\n      CMyComPtr<IInStream> nextStream;\r\n      HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);\r\n      if (result == S_FALSE)\r\n        break;\r\n      if (result != S_OK)\r\n        return result;\r\n      if (!stream)\r\n        break;\r\n      {\r\n        NCOM::CPropVariant prop;\r\n        RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\r\n        if (prop.vt != VT_UI8)\r\n          return E_INVALIDARG;\r\n        size = prop.uhVal.QuadPart;\r\n      }\r\n      _totalSize += size;\r\n      _sizes.Add(size);\r\n      _streams.Add(nextStream);\r\n      if (openArchiveCallback != NULL)\r\n      {\r\n        UInt64 numFiles = _streams.Size();\r\n        RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\r\n      }\r\n    }\r\n  }\r\n  /*\r\n  catch(...)\r\n  {\r\n    return S_FALSE;\r\n  }\r\n  */\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::Close()\r\n{\r\n  _sizes.Clear();\r\n  _streams.Clear();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\r\n{\r\n  *numItems = _streams.IsEmpty() ? 0 : 1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  switch(propID)\r\n  {\r\n    case kpidPath:\r\n      prop = _subName;\r\n      break;\r\n    case kpidSize:\r\n    case kpidPackSize:\r\n      prop = _totalSize;\r\n      break;\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\r\n    Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  if (numItems != UInt32(-1))\r\n  {\r\n    if (numItems != 1)\r\n      return E_INVALIDARG;\r\n    if (indices[0] != 0)\r\n      return E_INVALIDARG;\r\n  }\r\n  bool testMode = (_aTestMode != 0);\r\n  CMyComPtr<IArchiveExtractCallback> extractCallback = _anExtractCallback;\r\n  extractCallback->SetTotal(_totalSize);\r\n  \r\n  /*\r\n  CMyComPtr<IArchiveVolumeExtractCallback> volumeExtractCallback;\r\n  if (extractCallback.QueryInterface(&volumeExtractCallback) != S_OK)\r\n    return E_FAIL;\r\n  */\r\n\r\n  UInt64 currentTotalSize = 0;\r\n  UInt64 currentItemSize;\r\n\r\n  RINOK(extractCallback->SetCompleted(&currentTotalSize));\r\n  CMyComPtr<ISequentialOutStream> realOutStream;\r\n  Int32 askMode;\r\n  askMode = testMode ? NArchive::NExtract::NAskMode::kTest :\r\n  NArchive::NExtract::NAskMode::kExtract;\r\n  Int32 index = 0;\r\n  RINOK(extractCallback->GetStream(index, &realOutStream, askMode));\r\n  \r\n  RINOK(extractCallback->PrepareOperation(askMode));\r\n  if (testMode)\r\n  {\r\n    RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\r\n    return S_OK;\r\n  }\r\n  \r\n  if (!testMode && (!realOutStream))\r\n    return S_OK;\r\n\r\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\r\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\r\n\r\n  CLocalProgress *lps = new CLocalProgress;\r\n  CMyComPtr<ICompressProgressInfo> progress = lps;\r\n  lps->Init(extractCallback, false);\r\n\r\n  for (int i = 0; i < _streams.Size(); i++, currentTotalSize += currentItemSize)\r\n  {\r\n    lps->InSize = lps->OutSize = currentTotalSize;\r\n    RINOK(lps->SetCur());\r\n    IInStream *inStream = _streams[i];\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));\r\n    currentItemSize = copyCoderSpec->TotalSize;\r\n  }\r\n  realOutStream.Release();\r\n  return extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)\r\n{\r\n  if (index != 0)\r\n    return E_INVALIDARG;\r\n  *stream = 0;\r\n  CMultiStream *streamSpec = new CMultiStream;\r\n  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;\r\n  for (int i = 0; i < _streams.Size(); i++)\r\n  {\r\n    CMultiStream::CSubStreamInfo subStreamInfo;\r\n    subStreamInfo.Stream = _streams[i];\r\n    subStreamInfo.Pos = 0;\r\n    subStreamInfo.Size = _sizes[i];\r\n    streamSpec->Streams.Add(subStreamInfo);\r\n  }\r\n  streamSpec->Init();\r\n  *stream = streamTemp.Detach();\r\n  return S_OK;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Split/SplitHandler.h",
    "content": "// Split/Handler.h\r\n\r\n#ifndef __SPLIT_HANDLER_H\r\n#define __SPLIT_HANDLER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../IArchive.h\"\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\nclass CHandler:\r\n  public IInArchive,\r\n  public IInArchiveGetStream,\r\n  // public IOutArchive,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)\r\n\r\n  INTERFACE_IInArchive(;)\r\n\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);\r\n\r\nprivate:\r\n  UString _subName;\r\n  UString _name;\r\n  CObjectVector<CMyComPtr<IInStream> > _streams;\r\n  CRecordVector<UInt64> _sizes;\r\n\r\n  UInt64 _totalSize;\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Split/SplitHandlerOut.cpp",
    "content": "// Split/OutHandler.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SplitHandler.h\"\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../../Common/ComTry.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nnamespace NArchive {\r\nnamespace NSplit {\r\n\r\n/*\r\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\r\n{\r\n  *type = NFileTimeType::kWindows;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\r\n    IArchiveUpdateCallback *updateCallback)\r\n{\r\n  COM_TRY_BEGIN\r\n\r\n  if (numItems != 1)\r\n    return E_INVALIDARG;\r\n\r\n  UInt64 volumeSize = 0;\r\n\r\n  CMyComPtr<IArchiveUpdateCallback2> callback2;\r\n  updateCallback->QueryInterface(IID_IArchiveUpdateCallback2,\r\n      (void **)&callback2);\r\n\r\n  RINOK(callback2->GetVolumeSize(0, &volumeSize));\r\n\r\n  Int32 newData;\r\n  Int32 newProperties;\r\n  UInt32 indexInArchive;\r\n  if (!updateCallback)\r\n    return E_FAIL;\r\n\r\n  UInt32 fileIndex = 0;\r\n  RINOK(updateCallback->GetUpdateItemInfo(fileIndex,\r\n    &newData, &newProperties, &indexInArchive));\r\n\r\n  if (newProperties != 0)\r\n  {\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsFolder, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n      }\r\n      else if (prop.vt != VT_BOOL)\r\n        return E_INVALIDARG;\r\n      else\r\n      {\r\n        if (prop.boolVal != VARIANT_FALSE)\r\n          return E_INVALIDARG;\r\n      }\r\n    }\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsAnti, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n      }\r\n      else if (prop.vt != VT_BOOL)\r\n        return E_INVALIDARG;\r\n      else\r\n      {\r\n        if (prop.boolVal != VARIANT_FALSE)\r\n          return E_INVALIDARG;\r\n      }\r\n    }\r\n  }\r\n  UInt64 newSize;\r\n  bool thereIsCopyData = false;\r\n  if (newData != 0)\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(updateCallback->GetProperty(fileIndex, kpidSize, &prop));\r\n    if (prop.vt != VT_UI8)\r\n      return E_INVALIDARG;\r\n    newSize = prop.uhVal.QuadPart;\r\n  }\r\n  else\r\n    thereIsCopyData = true;\r\n\r\n  UInt64 pos = 0;\r\n  while(pos < newSize)\r\n  {\r\n\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Split/SplitRegister.cpp",
    "content": "// SplitRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#include \"SplitHandler.h\"\r\nstatic IInArchive *CreateArc() { return new NArchive::NSplit::CHandler;  }\r\n/*\r\n#ifndef EXTRACT_ONLY\r\nstatic IOutArchive *CreateArcOut() { return new NArchive::NSplit::CHandler;  }\r\n#else\r\n#define CreateArcOut 0\r\n#endif\r\n*/\r\n\r\nstatic CArcInfo g_ArcInfo =\r\n{ L\"Split\", L\"001\", 0, 0xEA, { 0 }, 0, false, CreateArc, 0 };\r\n\r\nREGISTER_ARC(Split)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/Split/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Archive/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Alone\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Alone - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Alone.mak\" CFG=\"Alone - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Alone - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Alone - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Alone - Win32 Release\"\r\n# Name \"Alone - Win32 Debug\"\r\n# Name \"Alone - Win32 ReleaseU\"\r\n# Name \"Alone - Win32 DebugU\"\r\n# Begin Group \"Console\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ArError.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\CompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\List.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\Main.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\MainAr.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.rc\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\AutoPtr.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Buffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ComTry.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\DynamicBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\ListFileUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyException.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyGuidDef.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyInitGuid.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Random.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StdOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\UTFConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Device.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Error.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Handle.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\MemoryLock.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Time.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\CreateCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilePathAutoRename.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FilterCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InOutTempBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LimitedStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\LockedStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodId.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\MethodProps.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OffsetStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\ProgressUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterArc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\RegisterCodec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamBinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamObjects.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\VirtThread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA_Alone\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Coder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Coder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\Bcj2Register.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BcjRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchMisc.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchMisc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\BranchRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwap.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwap.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\ByteSwapRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyCoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\CopyRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaEncoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LzmaRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"7z\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zEncode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zExtract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Archive Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\MultiStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"split\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZM\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaArcRegister.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Archive\\Lzma\\LzmaItem.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"UI Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\DefaultName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Extract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\OpenArchive.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Property.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SetProperties.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\SortUtils.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\TempFiles.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\Update.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateAction.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdatePair.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\UI\\Common\\WorkDir.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7-zip\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IMyUnknown.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IPassword.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IProgress.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\PropID.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\BraIA64.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\IStream.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\r\n\r\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\r\n\r\n# ADD CPP /O2\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\r\n\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n\r\n!ENDIF \r\n\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Alone7z/Alone.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Alone\"=.\\Alone.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Alone7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Alone7z/makefile",
    "content": "PROG = 7za.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib Advapi32.lib\r\n\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -D_NO_CRYPTO \\\r\n  -DWIN_LONG_PATH \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n  $O\\Time.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OffsetStream.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\DummyOutStream.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\MultiStream.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n\r\nLZM_OBJS = \\\r\n  $O\\LzmaArcRegister.obj \\\r\n  $O\\LzmaFiltersDecode.obj \\\r\n  $O\\LzmaHandler.obj \\\r\n  $O\\LzmaIn.obj \\\r\n\r\nSPLIT_OBJS = \\\r\n  $O\\SplitHandler.obj \\\r\n  $O\\SplitHandlerOut.obj \\\r\n  $O\\SplitRegister.obj \\\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(LZM_OBJS) \\\r\n  $(SPLIT_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): ../../UI/Console/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../../UI/Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZM_OBJS): ../../Archive/Lzma/$(*B).cpp\r\n\t$(COMPL)\r\n$(SPLIT_OBJS): ../../Archive/Split/$(*B).cpp\r\n\t$(COMPL)\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Alone7z/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_APP(\"7-Zip Standalone Console\", \"7za\")\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Format7zExtractR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Format7zExtractR/makefile",
    "content": "PROG = 7zxr.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DEXTRACT_ONLY \\\r\n  -DCOMPRESS_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Format7zExtractR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Extracting Plugin\", \"7zxr\")\r\n\r\n101  ICON  \"../../Archive/Icons/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Format7zR/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Format7zR/makefile",
    "content": "PROG = 7zra.dll\r\nDEF_FILE = ../../Archive/Archive2.def\r\nLIBS = $(LIBS) user32.lib oleaut32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../ \\\r\n  -DCOMPRESS_MT \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -D_NO_CRYPTO\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\Synchronization.obj \\\r\n  $O\\System.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\CreateCoder.obj \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\InOutTempBuffer.obj \\\r\n  $O\\FilterCoder.obj \\\r\n  $O\\LimitedStreams.obj \\\r\n  $O\\LockedStream.obj \\\r\n  $O\\MethodId.obj \\\r\n  $O\\MethodProps.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamBinder.obj \\\r\n  $O\\StreamObjects.obj \\\r\n  $O\\StreamUtils.obj \\\r\n  $O\\VirtThread.obj \\\r\n\r\nAR_OBJS = \\\r\n  $O\\ArchiveExports.obj \\\r\n  $O\\DllExports2.obj \\\r\n\r\nAR_COMMON_OBJS = \\\r\n  $O\\CoderMixer2.obj \\\r\n  $O\\CoderMixer2MT.obj \\\r\n  $O\\CrossThreadProgress.obj \\\r\n  $O\\HandlerOut.obj \\\r\n  $O\\InStreamWithCRC.obj \\\r\n  $O\\ItemNameUtils.obj \\\r\n  $O\\OutStreamWithCRC.obj \\\r\n  $O\\ParseProperties.obj \\\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zCompressionMode.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zEncode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zFolderInStream.obj \\\r\n  $O\\7zFolderOutStream.obj \\\r\n  $O\\7zHandler.obj \\\r\n  $O\\7zHandlerOut.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zOut.obj \\\r\n  $O\\7zProperties.obj \\\r\n  $O\\7zSpecStream.obj \\\r\n  $O\\7zUpdate.obj \\\r\n  $O\\7zRegister.obj \\\r\n\r\n\r\nCOMPRESS_OBJS = \\\r\n  $O\\CodecExports.obj \\\r\n  $O\\Bcj2Coder.obj \\\r\n  $O\\Bcj2Register.obj \\\r\n  $O\\BcjCoder.obj \\\r\n  $O\\BcjRegister.obj \\\r\n  $O\\BranchCoder.obj \\\r\n  $O\\BranchMisc.obj \\\r\n  $O\\BranchRegister.obj \\\r\n  $O\\ByteSwap.obj \\\r\n  $O\\ByteSwapRegister.obj \\\r\n  $O\\CopyCoder.obj \\\r\n  $O\\CopyRegister.obj \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n  $O\\LzmaRegister.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\BraIA64.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(AR_OBJS) \\\r\n  $(AR_COMMON_OBJS) \\\r\n  $(7Z_OBJS) \\\r\n  $(COMPRESS_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $O\\resource.res\r\n\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_OBJS): ../../Archive/$(*B).cpp\r\n\t$(COMPL)\r\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\r\n\t$(COMPL)\r\n\r\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\r\n\t$(COMPL_O2)\r\n\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Bundles/Format7zR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\r\n\r\nMY_VERSION_INFO_DLL(\"7z Standalone Plugin\", \"7zr\")\r\n\r\n101  ICON  \"../../Archive/Icons/7z.ico\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/CreateCoder.cpp",
    "content": "// CreateCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CreateCoder.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../../Windows/Defs.h\"\r\n#include \"FilterCoder.h\"\r\n#include \"RegisterCodec.h\"\r\n\r\nstatic const unsigned int kNumCodecsMax = 64;\r\nunsigned int g_NumCodecs = 0;\r\nconst CCodecInfo *g_Codecs[kNumCodecsMax];\r\nvoid RegisterCodec(const CCodecInfo *codecInfo)\r\n{\r\n  if (g_NumCodecs < kNumCodecsMax)\r\n    g_Codecs[g_NumCodecs++] = codecInfo;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = 1;\r\n  else if (prop.vt == VT_UI4)\r\n    res = prop.ulVal;\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_EMPTY)\r\n    res = true;\r\n  else if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else\r\n    return E_INVALIDARG;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs)\r\n{\r\n  UInt32 num;\r\n  RINOK(codecsInfo->GetNumberOfMethods(&num));\r\n  for (UInt32 i = 0; i < num; i++)\r\n  {\r\n    CCodecInfoEx info;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kID, &prop));\r\n    // if (prop.vt != VT_BSTR)\r\n    // info.Id.IDSize = (Byte)SysStringByteLen(prop.bstrVal);\r\n    // memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);\r\n    if (prop.vt != VT_UI8)\r\n    {\r\n      continue; // old Interface\r\n      // return E_INVALIDARG;\r\n    }\r\n    info.Id = prop.uhVal.QuadPart;\r\n    prop.Clear();\r\n    \r\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      info.Name = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_INVALIDARG;;\r\n    \r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kInStreams, info.NumInStreams));\r\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kOutStreams, info.NumOutStreams));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned));\r\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned));\r\n    \r\n    externalCodecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  const UString &name,\r\n  CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (name.CompareNoCase(codec.Name) == 0)\r\n    {\r\n      methodId = codec.Id;\r\n      numInStreams = codec.NumInStreams;\r\n      numOutStreams = 1;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (codec.Name.CompareNoCase(name) == 0)\r\n      {\r\n        methodId = codec.Id;\r\n        numInStreams = codec.NumInStreams;\r\n        numOutStreams = codec.NumOutStreams;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool FindMethod(\r\n  #ifdef EXTERNAL_CODECS\r\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\r\n  #endif\r\n  CMethodId methodId, UString &name)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (methodId == codec.Id)\r\n    {\r\n      name = codec.Name;\r\n      return true;\r\n    }\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  if (externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (methodId == codec.Id)\r\n      {\r\n        name = codec.Name;\r\n        return true;\r\n      }\r\n    }\r\n  #endif\r\n  return false;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder)\r\n{\r\n  bool created = false;\r\n  UInt32 i;\r\n  for (i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (codec.Id == methodId)\r\n    {\r\n      if (encode)\r\n      {\r\n        if (codec.CreateEncoder)\r\n        {\r\n          void *p = codec.CreateEncoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n      }\r\n      else\r\n        if (codec.CreateDecoder)\r\n        {\r\n          void *p = codec.CreateDecoder();\r\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\r\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\r\n          else coder2 = (ICompressCoder2 *)p;\r\n          created = (p != 0);\r\n          break;\r\n        }\r\n    }\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  if (!created && externalCodecs)\r\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\r\n    {\r\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\r\n      if (codec.Id == methodId)\r\n      {\r\n        if (encode)\r\n        {\r\n          if (codec.EncoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n        }\r\n        else\r\n          if (codec.DecoderIsAssigned)\r\n          {\r\n            if (codec.IsSimpleCodec())\r\n            {\r\n              HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);\r\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\r\n                return result;\r\n              if (!coder)\r\n              {\r\n                RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter));\r\n              }\r\n            }\r\n            else\r\n            {\r\n              RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressCoder2, (void **)&coder2));\r\n            }\r\n            break;\r\n          }\r\n      }\r\n    }\r\n  #endif\r\n\r\n  if (onlyCoder && filter)\r\n  {\r\n    CFilterCoder *coderSpec = new CFilterCoder;\r\n    coder = coderSpec;\r\n    coderSpec->Filter = filter;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, true);\r\n}\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode)\r\n{\r\n  CMyComPtr<ICompressFilter> filter;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    coder, coder2, encode);\r\n}\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode)\r\n{\r\n  CMyComPtr<ICompressCoder> coder;\r\n  CMyComPtr<ICompressCoder2> coder2;\r\n  return CreateCoder(\r\n    EXTERNAL_CODECS_LOC_VARS\r\n    methodId,\r\n    filter, coder, coder2, encode, false);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/CreateCoder.h",
    "content": "// CreateCoder.h\r\n\r\n#ifndef __CREATECODER_H\r\n#define __CREATECODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nstruct CCodecInfoEx\r\n{\r\n  UString Name;\r\n  CMethodId Id;\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }\r\n  CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}\r\n};\r\n\r\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)\r\n#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);\r\n#define IMPL_ISetCompressCodecsInfo2(x) \\\r\nSTDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \\\r\n  COM_TRY_BEGIN _codecsInfo = compressCodecsInfo;  return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }\r\n#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)\r\n\r\n#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs\r\n#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs\r\n\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,\r\n#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,\r\n\r\n#else\r\n\r\n#define PUBLIC_ISetCompressCodecsInfo\r\n#define QUERY_ENTRY_ISetCompressCodecsInfo\r\n#define DECL_ISetCompressCodecsInfo\r\n#define IMPL_ISetCompressCodecsInfo\r\n#define EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_VARS\r\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS2\r\n#define EXTERNAL_CODECS_LOC_VARS2\r\n#define DECL_EXTERNAL_CODECS_LOC_VARS\r\n#define EXTERNAL_CODECS_LOC_VARS\r\n\r\n#endif\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);\r\n\r\nbool FindMethod(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId, UString &name);\r\n\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode, bool onlyCoder);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder,\r\n  CMyComPtr<ICompressCoder2> &coder2,\r\n  bool encode);\r\n\r\nHRESULT CreateCoder(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressCoder> &coder, bool encode);\r\n\r\nHRESULT CreateFilter(\r\n  DECL_EXTERNAL_CODECS_LOC_VARS\r\n  CMethodId methodId,\r\n  CMyComPtr<ICompressFilter> &filter,\r\n  bool encode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/FilePathAutoRename.cpp",
    "content": "// FilePathAutoRename.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"FilePathAutoRename.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic bool MakeAutoName(const UString &name,\r\n    const UString &extension, int value, UString &path)\r\n{\r\n  wchar_t number[32];\r\n  ConvertUInt64ToString(value, number);\r\n  path = name;\r\n  path += number;\r\n  path += extension;\r\n  return NFile::NFind::DoesFileExist(path);\r\n}\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath)\r\n{\r\n  UString path;\r\n  int dotPos = fullProcessedPath.ReverseFind(L'.');\r\n\r\n  int slashPos = fullProcessedPath.ReverseFind(L'/');\r\n  #ifdef _WIN32\r\n  int slash1Pos = fullProcessedPath.ReverseFind(L'\\\\');\r\n  slashPos = MyMax(slashPos, slash1Pos);\r\n  #endif\r\n\r\n  UString name, extension;\r\n  if (dotPos > slashPos &&  dotPos > 0)\r\n  {\r\n    name = fullProcessedPath.Left(dotPos);\r\n    extension = fullProcessedPath.Mid(dotPos);\r\n  }\r\n  else\r\n    name = fullProcessedPath;\r\n  name += L'_';\r\n  int indexLeft = 1, indexRight = (1 << 30);\r\n  while (indexLeft != indexRight)\r\n  {\r\n    int indexMid = (indexLeft + indexRight) / 2;\r\n    if (MakeAutoName(name, extension, indexMid, path))\r\n      indexLeft = indexMid + 1;\r\n    else\r\n      indexRight = indexMid;\r\n  }\r\n  if (MakeAutoName(name, extension, indexRight, fullProcessedPath))\r\n    return false;\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/FilePathAutoRename.h",
    "content": "// Util/FilePathAutoRename.h\r\n\r\n#ifndef __FILEPATHAUTORENAME_H\r\n#define __FILEPATHAUTORENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nbool AutoRenamePath(UString &fullProcessedPath);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  #ifdef _WIN32\r\n  if (result)\r\n    return S_OK;\r\n  DWORD lastError = ::GetLastError();\r\n  if (lastError == 0)\r\n    return E_FAIL;\r\n  return HRESULT_FROM_WIN32(lastError);\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nbool CInFileStream::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n\r\n#ifdef USE_WIN_FILE\r\n#ifndef _UNICODE\r\nbool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{\r\n  return File.OpenShared(fileName, shareForWrite);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE),\r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do\r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  }\r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nHRESULT COutFileStream::Close()\r\n{\r\n  return ConvertBoolToHRESULT(File.Close());\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  ProcessedSize += realProcessedSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  ProcessedSize += res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef USE_WIN_FILE\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15);\r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),\r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do\r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  }\r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#define USE_WIN_FILE\r\n#endif\r\n\r\n#ifdef USE_WIN_FILE\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream:\r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  #ifdef USE_WIN_FILE\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\npublic:\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #ifdef USE_WIN_FILE\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Create(fileName, createAlways);\r\n  }\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  {\r\n    ProcessedSize = 0;\r\n    return File.Open(fileName, creationDisposition);\r\n  }\r\n  #endif\r\n  #endif\r\n\r\n  HRESULT Close();\r\n  \r\n  UInt64 ProcessedSize;\r\n\r\n  #ifdef USE_WIN_FILE\r\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n  {\r\n    return File.SetTime(cTime, aTime, mTime);\r\n  }\r\n  bool SetMTime(const FILETIME *mTime) {  return File.SetMTime(mTime); }\r\n  #endif\r\n\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/FilterCoder.cpp",
    "content": "// FilterCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FilterCoder.h\"\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n#include \"../../Common/Defs.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCFilterCoder::CFilterCoder()\r\n{\r\n  _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n}\r\n\r\nCFilterCoder::~CFilterCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)\r\n{\r\n  if (_outSizeIsDefined)\r\n  {\r\n    UInt64 remSize = _outSize - _nowPos64;\r\n    if (size > remSize)\r\n      size = (UInt32)remSize;\r\n  }\r\n  RINOK(WriteStream(outStream, _buffer, size));\r\n  _nowPos64 += size;\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  RINOK(Init());\r\n  UInt32 bufferPos = 0;\r\n  _outSizeIsDefined = (outSize != 0);\r\n  if (_outSizeIsDefined)\r\n    _outSize = *outSize;\r\n\r\n  while(NeedMore())\r\n  {\r\n    size_t processedSize = kBufferSize - bufferPos;\r\n    \r\n    // Change it: It can be optimized using ReadPart\r\n    RINOK(ReadStream(inStream, _buffer + bufferPos, &processedSize));\r\n    \r\n    UInt32 endPos = bufferPos + (UInt32)processedSize;\r\n\r\n    bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (bufferPos > endPos)\r\n    {\r\n      for (; endPos< bufferPos; endPos++)\r\n        _buffer[endPos] = 0;\r\n      bufferPos = Filter->Filter(_buffer, endPos);\r\n    }\r\n\r\n    if (bufferPos == 0)\r\n    {\r\n      if (endPos > 0)\r\n        return WriteWithLimit(outStream, endPos);\r\n      return S_OK;\r\n    }\r\n    RINOK(WriteWithLimit(outStream, bufferPos));\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));\r\n    }\r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n// #ifdef _ST_MODE\r\nSTDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _bufferPos = 0;\r\n  _outStream = outStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseOutStream()\r\n{\r\n  _outStream.Release();\r\n  return S_OK;\r\n};\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    UInt32 sizeMax = kBufferSize - _bufferPos;\r\n    UInt32 sizeTemp = size;\r\n    if (sizeTemp > sizeMax)\r\n      sizeTemp = sizeMax;\r\n    memmove(_buffer + _bufferPos, data, sizeTemp);\r\n    size -= sizeTemp;\r\n    processedSizeTotal += sizeTemp;\r\n    data = (const Byte *)data + sizeTemp;\r\n    UInt32 endPos = _bufferPos + sizeTemp;\r\n    _bufferPos = Filter->Filter(_buffer, endPos);\r\n    if (_bufferPos == 0)\r\n    {\r\n      _bufferPos = endPos;\r\n      break;\r\n    }\r\n    if (_bufferPos > endPos)\r\n    {\r\n      if (size != 0)\r\n        return E_FAIL;\r\n      break;\r\n    }\r\n    RINOK(WriteWithLimit(_outStream, _bufferPos));\r\n    UInt32 i = 0;\r\n    while(_bufferPos < endPos)\r\n      _buffer[i++] = _buffer[_bufferPos++];\r\n    _bufferPos = i;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::Flush()\r\n{\r\n  if (_bufferPos != 0)\r\n  {\r\n    UInt32 endPos = Filter->Filter(_buffer, _bufferPos);\r\n    if (endPos > _bufferPos)\r\n    {\r\n      for (; _bufferPos < endPos; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      if (Filter->Filter(_buffer, endPos) != endPos)\r\n        return E_FAIL;\r\n    }\r\n    RINOK(WriteStream(_outStream, _buffer, _bufferPos));\r\n    _bufferPos = 0;\r\n  }\r\n  CMyComPtr<IOutStreamFlush> flush;\r\n  _outStream.QueryInterface(IID_IOutStreamFlush, &flush);\r\n  if (flush)\r\n    return  flush->Flush();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _convertedPosBegin = _convertedPosEnd = _bufferPos = 0;\r\n  _inStream = inStream;\r\n  return Init();\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::ReleaseInStream()\r\n{\r\n  _inStream.Release();\r\n  return S_OK;\r\n};\r\n\r\nSTDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 processedSizeTotal = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_convertedPosBegin != _convertedPosEnd)\r\n    {\r\n      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);\r\n      memmove(data, _buffer + _convertedPosBegin, sizeTemp);\r\n      _convertedPosBegin += sizeTemp;\r\n      data = (void *)((Byte *)data + sizeTemp);\r\n      size -= sizeTemp;\r\n      processedSizeTotal += sizeTemp;\r\n      break;\r\n    }\r\n    int i;\r\n    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)\r\n      _buffer[i] = _buffer[i + _convertedPosEnd];\r\n    _bufferPos = i;\r\n    _convertedPosBegin = _convertedPosEnd = 0;\r\n    size_t processedSizeTemp = kBufferSize - _bufferPos;\r\n    RINOK(ReadStream(_inStream, _buffer + _bufferPos, &processedSizeTemp));\r\n    _bufferPos = _bufferPos + (UInt32)processedSizeTemp;\r\n    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    if (_convertedPosEnd == 0)\r\n    {\r\n      if (_bufferPos == 0)\r\n        break;\r\n      else\r\n      {\r\n        _convertedPosEnd = _bufferPos; // check it\r\n        continue;\r\n      }\r\n    }\r\n    if (_convertedPosEnd > _bufferPos)\r\n    {\r\n      for (; _bufferPos < _convertedPosEnd; _bufferPos++)\r\n        _buffer[_bufferPos] = 0;\r\n      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = processedSizeTotal;\r\n  return S_OK;\r\n}\r\n\r\n// #endif // _ST_MODE\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)\r\n{\r\n  return _setPassword->CryptoSetPassword(data, size);\r\n}\r\n#endif\r\n\r\n#ifndef EXTRACT_ONLY\r\nSTDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);\r\n}\r\n\r\nSTDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  return _writeCoderProperties->WriteCoderProperties(outStream);\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CFilterCoder::ResetSalt()\r\n{\r\n  return _CryptoResetSalt->ResetSalt();\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CFilterCoder::ResetInitVector()\r\n{\r\n  return _CryptoResetInitVector->ResetInitVector();\r\n}\r\n#endif\r\n\r\nSTDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)\r\n{\r\n  return _setDecoderProperties->SetDecoderProperties2(data, size);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/FilterCoder.h",
    "content": "// FilterCoder.h\r\n\r\n#ifndef __FILTERCODER_H\r\n#define __FILTERCODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n#include \"../IPassword.h\"\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \\\r\n{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \\\r\n*outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\nclass CFilterCoder:\r\n  public ICompressCoder,\r\n  // #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ISequentialInStream,\r\n  public ICompressSetOutStream,\r\n  public ISequentialOutStream,\r\n  public IOutStreamFlush,\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoSetPassword,\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  // public ICryptoResetSalt,\r\n  public ICryptoResetInitVector,\r\n  #endif\r\n  public ICompressSetDecoderProperties2,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  // #ifdef _ST_MODE\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  CMyComPtr<ISequentialOutStream> _outStream;\r\n  UInt32 _bufferPos;\r\n  UInt32 _convertedPosBegin;\r\n  UInt32 _convertedPosEnd;\r\n  // #endif\r\n  bool _outSizeIsDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _nowPos64;\r\n\r\n  HRESULT Init()\r\n  {\r\n    _nowPos64 = 0;\r\n    _outSizeIsDefined = false;\r\n    return Filter->Init();\r\n  }\r\n\r\n  CMyComPtr<ICryptoSetPassword> _setPassword;\r\n  #ifndef EXTRACT_ONLY\r\n  CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;\r\n  CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;\r\n  // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;\r\n  CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;\r\n  #endif\r\n  CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;\r\npublic:\r\n  CMyComPtr<ICompressFilter> Filter;\r\n\r\n  CFilterCoder();\r\n  ~CFilterCoder();\r\n  HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);\r\n  bool NeedMore() const\r\n    { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }\r\n\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN\r\n    MY_QUERYINTERFACE_ENTRY(ICompressCoder)\r\n    // #ifdef _ST_MODE\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialInStream)\r\n\r\n    MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)\r\n    MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)\r\n    // #endif\r\n\r\n    #ifndef _NO_CRYPTO\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)\r\n    #endif\r\n\r\n    #ifndef EXTRACT_ONLY\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)\r\n    // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)\r\n    #endif\r\n\r\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  // #ifdef _ST_MODE\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \\\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Flush)();\r\n  // #endif\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);\r\n  #endif\r\n  #ifndef EXTRACT_ONLY\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  // STDMETHOD(ResetSalt)();\r\n  STDMETHOD(ResetInitVector)();\r\n  #endif\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n};\r\n\r\n// #ifdef _ST_MODE\r\nclass CInStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  CInStreamReleaser(): FilterCoder(0) {}\r\n  ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }\r\n};\r\n\r\nclass COutStreamReleaser\r\n{\r\npublic:\r\n  CFilterCoder *FilterCoder;\r\n  COutStreamReleaser(): FilterCoder(0) {}\r\n  ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }\r\n};\r\n// #endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nCInBuffer::CInBuffer():\r\n  _buffer(0),\r\n  _bufferLimit(0),\r\n  _bufferBase(0),\r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct CInBufferException: public CSystemException\r\n{\r\n  CInBufferException(HRESULT errorCode): CSystemException(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if (_buffer >= _bufferLimit)\r\n      if (!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if (_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  UInt32 ReadBytes(Byte *buf, UInt32 size)\r\n  {\r\n    if ((UInt32)(_bufferLimit - _buffer) >= size)\r\n    {\r\n      for (UInt32 i = 0; i < size; i++)\r\n        buf[i] = _buffer[i];\r\n      _buffer += size;\r\n      return size;\r\n    }\r\n    for (UInt32 i = 0; i < size; i++)\r\n    {\r\n      if (_buffer >= _bufferLimit)\r\n        if (!ReadBlock())\r\n          return i;\r\n      buf[i] = *_buffer++;\r\n    }\r\n    return size;\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/InOutTempBuffer.cpp",
    "content": "// InOutTempBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InOutTempBuffer.h\"\r\n#include \"../../Common/Defs.h\"\r\n// #include \"Windows/Defs.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic UInt32 kTmpBufferMemorySize = (1 << 20);\r\n\r\nstatic LPCTSTR kTempFilePrefixString = TEXT(\"iot\");\r\n\r\nCInOutTempBuffer::CInOutTempBuffer():\r\n  _buffer(NULL)\r\n{\r\n}\r\n\r\nvoid CInOutTempBuffer::Create()\r\n{\r\n  _buffer = new Byte[kTmpBufferMemorySize];\r\n}\r\n\r\nCInOutTempBuffer::~CInOutTempBuffer()\r\n{\r\n  delete []_buffer;\r\n}\r\nvoid CInOutTempBuffer::InitWriting()\r\n{\r\n  _bufferPosition = 0;\r\n  _tmpFileCreated = false;\r\n  _fileSize = 0;\r\n}\r\n\r\nbool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)\r\n{\r\n  if (size == 0)\r\n    return true;\r\n  if(!_tmpFileCreated)\r\n  {\r\n    CSysString tempDirPath;\r\n    if(!MyGetTempPath(tempDirPath))\r\n      return false;\r\n    if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)\r\n      return false;\r\n    // _outFile.SetOpenCreationDispositionCreateAlways();\r\n    if(!_outFile.Create(_tmpFileName, true))\r\n      return false;\r\n    _tmpFileCreated = true;\r\n  }\r\n  UInt32 processedSize;\r\n  if(!_outFile.Write(data, size, processedSize))\r\n    return false;\r\n  _fileSize += processedSize;\r\n  return (processedSize == size);\r\n}\r\n\r\nbool CInOutTempBuffer::FlushWrite()\r\n{\r\n  return _outFile.Close();\r\n}\r\n\r\nbool CInOutTempBuffer::Write(const void *data, UInt32 size)\r\n{\r\n  if(_bufferPosition < kTmpBufferMemorySize)\r\n  {\r\n    UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);\r\n    memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);\r\n    _bufferPosition += curSize;\r\n    size -= curSize;\r\n    data = ((const Byte *)data) + curSize;\r\n    _fileSize += curSize;\r\n  }\r\n  return WriteToFile(data, size);\r\n}\r\n\r\nbool CInOutTempBuffer::InitReading()\r\n{\r\n  _currentPositionInBuffer = 0;\r\n  if(_tmpFileCreated)\r\n    return _inFile.Open(_tmpFileName);\r\n  return true;\r\n}\r\n\r\nHRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)\r\n{\r\n  if (_currentPositionInBuffer < _bufferPosition)\r\n  {\r\n    UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;\r\n    RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite));\r\n    _currentPositionInBuffer += sizeToWrite;\r\n  }\r\n  if (!_tmpFileCreated)\r\n    return true;\r\n  for (;;)\r\n  {\r\n    UInt32 localProcessedSize;\r\n    if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))\r\n      return E_FAIL;\r\n    if (localProcessedSize == 0)\r\n      return S_OK;\r\n    RINOK(WriteStream(stream, _buffer, localProcessedSize));\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (!_buffer->Write(data, size))\r\n  {\r\n    if (processedSize != NULL)\r\n      *processedSize = 0;\r\n    return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/InOutTempBuffer.h",
    "content": "// Util/InOutTempBuffer.h\r\n\r\n#ifndef __IN_OUT_TEMP_BUFFER_H\r\n#define __IN_OUT_TEMP_BUFFER_H\r\n\r\n#include \"../../Windows/FileIO.h\"\r\n#include \"../../Windows/FileDir.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../IStream.h\"\r\n\r\nclass CInOutTempBuffer\r\n{\r\n  NWindows::NFile::NDirectory::CTempFile _tempFile;\r\n  NWindows::NFile::NIO::COutFile _outFile;\r\n  NWindows::NFile::NIO::CInFile _inFile;\r\n  Byte *_buffer;\r\n  UInt32 _bufferPosition;\r\n  UInt32 _currentPositionInBuffer;\r\n  CSysString _tmpFileName;\r\n  bool _tmpFileCreated;\r\n\r\n  UInt64 _fileSize;\r\n\r\n  bool WriteToFile(const void *data, UInt32 size);\r\npublic:\r\n  CInOutTempBuffer();\r\n  ~CInOutTempBuffer();\r\n  void Create();\r\n\r\n  void InitWriting();\r\n  bool Write(const void *data, UInt32 size);\r\n  UInt64 GetDataSize() const { return _fileSize; }\r\n  bool FlushWrite();\r\n  bool InitReading();\r\n  HRESULT WriteToStream(ISequentialOutStream *stream);\r\n};\r\n\r\nclass CSequentialOutTempBufferImp:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CInOutTempBuffer *_buffer;\r\npublic:\r\n  // CSequentialOutStreamImp(): _size(0) {}\r\n  // UInt32 _size;\r\n  void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }\r\n  // UInt32 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/LimitedStreams.cpp",
    "content": "// LimitedStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LimitedStreams.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\nSTDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size);\r\n  HRESULT result = S_OK;\r\n  if (sizeToRead > 0)\r\n  {\r\n    result = _stream->Read(data, sizeToRead, &realProcessedSize);\r\n    _pos += realProcessedSize;\r\n    if (realProcessedSize == 0)\r\n      _wasFinished = true;\r\n  }\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  HRESULT result = S_OK;\r\n  if (processedSize != NULL)\r\n    *processedSize = 0;\r\n  if (size > _size)\r\n  {\r\n    size = (UInt32)_size;\r\n    if (size == 0)\r\n    {\r\n      _overflow = true;\r\n      return E_FAIL;\r\n    }\r\n  }\r\n  if (_stream)\r\n    result = _stream->Write(data, size, &size);\r\n  _size -= size;\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/LimitedStreams.h",
    "content": "// LimitedStreams.h\r\n\r\n#ifndef __LIMITEDSTREAMS_H\r\n#define __LIMITEDSTREAMS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLimitedSequentialInStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\n  UInt64 _pos;\r\n  bool _wasFinished;\r\npublic:\r\n  void SetStream(ISequentialInStream *stream) { _stream = stream; }\r\n  void Init(UInt64 streamSize)\r\n  {\r\n    _size = streamSize;\r\n    _pos = 0;\r\n    _wasFinished = false;\r\n  }\r\n \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  UInt64 GetSize() const { return _pos; }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\nclass CLimitedSequentialOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\n  bool _overflow;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void ReleaseStream() { _stream.Release(); }\r\n  void Init(UInt64 size)\r\n  {\r\n    _size = size;\r\n    _overflow = false;\r\n  }\r\n  bool IsFinishedOK() const { return (_size == 0 && !_overflow); }\r\n  UInt64 GetRem() const { return _size; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/LockedStream.cpp",
    "content": "// LockedStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LockedStream.h\"\r\n\r\nHRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size,\r\n  UInt32 *processedSize)\r\n{\r\n  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);\r\n  RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));\r\n  return _stream->Read(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize = 0;\r\n  HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);\r\n  _pos += realProcessedSize;\r\n  if (processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/LockedStream.h",
    "content": "// LockedStream.h\r\n\r\n#ifndef __LOCKEDSTREAM_H\r\n#define __LOCKEDSTREAM_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CLockedInStream\r\n{\r\n  CMyComPtr<IInStream> _stream;\r\n  NWindows::NSynchronization::CCriticalSection _criticalSection;\r\npublic:\r\n  void Init(IInStream *stream)\r\n    { _stream = stream; }\r\n  HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CLockedSequentialInStreamImp:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CLockedInStream *_lockedInStream;\r\n  UInt64 _pos;\r\npublic:\r\n  void Init(CLockedInStream *lockedInStream, UInt64 startPos)\r\n  {\r\n    _lockedInStream = lockedInStream;\r\n    _pos = startPos;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/MethodId.cpp",
    "content": "// MethodId.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MethodId.h\"\r\n#include \"../../Common/MyString.h\"\r\n\r\nstatic inline wchar_t GetHex(Byte value)\r\n{\r\n  return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nUString ConvertMethodIdToString(UInt64 id)\r\n{\r\n  wchar_t s[32];\r\n  int len = 32;\r\n  s[--len] = 0;\r\n  do\r\n  {\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n    s[--len] = GetHex((Byte)id & 0xF);\r\n    id >>= 4;\r\n  }\r\n  while (id != 0);\r\n  return s + len;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/MethodId.h",
    "content": "// MethodId.h\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"../../Common/Types.h\"\r\n\r\ntypedef UInt64 CMethodId;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/MethodProps.cpp",
    "content": "// MethodProps.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\n#include \"MethodProps.h\"\r\n\r\nstatic UInt64 k_LZMA = 0x030101;\r\n// static UInt64 k_LZMA2 = 0x030102;\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)\r\n{\r\n  bool tryReduce = false;\r\n  UInt32 reducedDictionarySize = 1 << 10;\r\n  if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))\r\n  {\r\n    for (;;)\r\n    {\r\n      const UInt32 step = (reducedDictionarySize >> 1);\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      reducedDictionarySize += step;\r\n      if (reducedDictionarySize >= *inSizeForReduce)\r\n      {\r\n        tryReduce = true;\r\n        break;\r\n      }\r\n      if (reducedDictionarySize >= ((UInt32)3 << 30))\r\n        break;\r\n      reducedDictionarySize += step;\r\n    }\r\n  }\r\n\r\n  {\r\n    int numProps = method.Props.Size();\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n    if (setCoderProperties == NULL)\r\n    {\r\n      if (numProps != 0)\r\n        return E_INVALIDARG;\r\n    }\r\n    else\r\n    {\r\n      CRecordVector<PROPID> propIDs;\r\n      NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps];\r\n      HRESULT res = S_OK;\r\n      try\r\n      {\r\n        for (int i = 0; i < numProps; i++)\r\n        {\r\n          const CProp &prop = method.Props[i];\r\n          propIDs.Add(prop.Id);\r\n          NWindows::NCOM::CPropVariant &value = values[i];\r\n          value = prop.Value;\r\n          // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)\r\n          if (tryReduce)\r\n            if (prop.Id == NCoderPropID::kDictionarySize)\r\n              if (value.vt == VT_UI4)\r\n                if (reducedDictionarySize < value.ulVal)\r\n            value.ulVal = reducedDictionarySize;\r\n        }\r\n        CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n        coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\r\n        res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps);\r\n      }\r\n      catch(...)\r\n      {\r\n        delete []values;\r\n        throw;\r\n      }\r\n      delete []values;\r\n      RINOK(res);\r\n    }\r\n  }\r\n \r\n  /*\r\n  CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n  coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\r\n  if (writeCoderProperties != NULL)\r\n  {\r\n    CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\r\n    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\r\n    outStreamSpec->Init();\r\n    RINOK(writeCoderProperties->WriteCoderProperties(outStream));\r\n    size_t size = outStreamSpec->GetSize();\r\n    filterProps.SetCapacity(size);\r\n    memmove(filterProps, outStreamSpec->GetBuffer(), size);\r\n  }\r\n  */\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/MethodProps.h",
    "content": "// MethodProps.h\r\n\r\n#ifndef __7Z_METHOD_PROPS_H\r\n#define __7Z_METHOD_PROPS_H\r\n\r\n#include \"../../Common/MyVector.h\"\r\n\r\n#include \"../../Windows/PropVariant.h\"\r\n\r\n#include \"MethodId.h\"\r\n\r\nstruct CProp\r\n{\r\n  PROPID Id;\r\n  NWindows::NCOM::CPropVariant Value;\r\n};\r\n\r\nstruct CMethod\r\n{\r\n  CMethodId Id;\r\n  CObjectVector<CProp> Props;\r\n};\r\n\r\nstruct CMethodsMode\r\n{\r\n  CObjectVector<CMethod> Methods;\r\n  #ifdef COMPRESS_MT\r\n  UInt32 NumThreads;\r\n  #endif\r\n\r\n  CMethodsMode()\r\n      #ifdef COMPRESS_MT\r\n      : NumThreads(1)\r\n      #endif\r\n  {}\r\n  bool IsEmpty() const { return Methods.IsEmpty() ; }\r\n};\r\n\r\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/OffsetStream.cpp",
    "content": "// OffsetStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"OffsetStream.h\"\r\n\r\nHRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)\r\n{\r\n  _offset = offset;\r\n  _stream = stream;\r\n  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  return _stream->Write(data, size, processedSize);\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,\r\n    UInt64 *newPosition)\r\n{\r\n  UInt64 absoluteNewPosition;\r\n  if (seekOrigin == STREAM_SEEK_SET)\r\n    offset += _offset;\r\n  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);\r\n  if (newPosition != NULL)\r\n    *newPosition = absoluteNewPosition - _offset;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)\r\n{\r\n  return _stream->SetSize(_offset + newSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/OffsetStream.h",
    "content": "// OffsetStream.h\r\n\r\n#ifndef __OFFSETSTREAM_H\r\n#define __OFFSETSTREAM_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass COffsetOutStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 _offset;\r\n  CMyComPtr<IOutStream> _stream;\r\npublic:\r\n  HRESULT Init(IOutStream *stream, UInt64 offset);\r\n  \r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../C/Alloc.h\"\r\n}\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{\r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos)\r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode == S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = Flush();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../../Common/MyException.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException: public CSystemException\r\n{\r\n  COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void FlushWithCheck();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/ProgressUtils.cpp",
    "content": "// ProgressUtils.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ProgressUtils.h\"\r\n\r\nCLocalProgress::CLocalProgress()\r\n{\r\n  ProgressOffset = InSize = OutSize = 0;\r\n  SendRatio = SendProgress = true;\r\n}\r\n\r\nvoid CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)\r\n{\r\n  _ratioProgress.Release();\r\n  _progress = progress;\r\n  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);\r\n  _inSizeIsMain = inSizeIsMain;\r\n}\r\n\r\nSTDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  UInt64 inSizeNew = InSize, outSizeNew = OutSize;\r\n  if (inSize)\r\n    inSizeNew += (*inSize);\r\n  if (outSize)\r\n    outSizeNew += (*outSize);\r\n  if (SendRatio && _ratioProgress)\r\n  {\r\n    RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));\r\n  }\r\n  inSizeNew += ProgressOffset;\r\n  outSizeNew += ProgressOffset;\r\n  if (SendProgress)\r\n    return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CLocalProgress::SetCur()\r\n{\r\n  return SetRatioInfo(NULL, NULL);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/ProgressUtils.h",
    "content": "// ProgressUtils.h\r\n\r\n#ifndef __PROGRESSUTILS_H\r\n#define __PROGRESSUTILS_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n#include \"../IProgress.h\"\r\n\r\nclass CLocalProgress:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<IProgress> _progress;\r\n  CMyComPtr<ICompressProgressInfo> _ratioProgress;\r\n  bool _inSizeIsMain;\r\npublic:\r\n  UInt64 ProgressOffset;\r\n  UInt64 InSize;\r\n  UInt64 OutSize;\r\n  bool SendRatio;\r\n  bool SendProgress;\r\n\r\n  CLocalProgress();\r\n  void Init(IProgress *progress, bool inSizeIsMain);\r\n  HRESULT SetCur();\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/RegisterArc.h",
    "content": "// RegisterArc.h\r\n\r\n#ifndef __REGISTERARC_H\r\n#define __REGISTERARC_H\r\n\r\n#include \"../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcInfo\r\n{\r\n  const wchar_t *Name;\r\n  const wchar_t *Ext;\r\n  const wchar_t *AddExt;\r\n  Byte ClassId;\r\n  Byte Signature[16];\r\n  int SignatureSize;\r\n  bool KeepName;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n};\r\n\r\nvoid RegisterArc(const CArcInfo *arcInfo);\r\n\r\n#define REGISTER_ARC_NAME(x) CRegister ## x\r\n\r\n#define REGISTER_ARC_DEC_SIG(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { g_ArcInfo.Signature[0]--; RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#define REGISTER_ARC(x) struct REGISTER_ARC_NAME(x) { \\\r\n    REGISTER_ARC_NAME(x)() { RegisterArc(&g_ArcInfo); }}; \\\r\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/RegisterCodec.h",
    "content": "// RegisterCodec.h\r\n\r\n#ifndef __REGISTERCODEC_H\r\n#define __REGISTERCODEC_H\r\n\r\n#include \"../Common/MethodId.h\"\r\n\r\ntypedef void * (*CreateCodecP)();\r\nstruct CCodecInfo\r\n{\r\n  CreateCodecP CreateDecoder;\r\n  CreateCodecP CreateEncoder;\r\n  CMethodId Id;\r\n  const wchar_t *Name;\r\n  UInt32 NumInStreams;\r\n  bool IsFilter;\r\n};\r\n\r\nvoid RegisterCodec(const CCodecInfo *codecInfo);\r\n\r\n#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x\r\n\r\n#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \\\r\n    REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \\\r\n    static REGISTER_CODEC_NAME(x) g_RegisterCodec;\r\n\r\n#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x\r\n#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \\\r\n    REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \\\r\n    RegisterCodec(&g_CodecsInfo[i]); }}; \\\r\n    static REGISTER_CODECS_NAME(x) g_RegisterCodecs;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/StreamBinder.cpp",
    "content": "// StreamBinder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamBinder.h\"\r\n#include \"../../Common/Defs.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NSynchronization;\r\n\r\nclass CSequentialInStreamForBinder:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Read(data, size, processedSize); }\r\n\r\nclass CSequentialOutStreamForBinder:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\nprivate:\r\n  CStreamBinder *m_StreamBinder;\r\npublic:\r\n  ~CSequentialOutStreamForBinder() {  m_StreamBinder->CloseWrite(); }\r\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\r\n};\r\n\r\nSTDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n  { return m_StreamBinder->Write(data, size, processedSize); }\r\n\r\n\r\n//////////////////////////\r\n// CStreamBinder\r\n// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.\r\n\r\nHRes CStreamBinder::CreateEvents()\r\n{\r\n  RINOK(_allBytesAreWritenEvent.Create(true));\r\n  RINOK(_thereAreBytesToReadEvent.Create());\r\n  return _readStreamIsClosedEvent.Create();\r\n}\r\n\r\nvoid CStreamBinder::ReInit()\r\n{\r\n  _thereAreBytesToReadEvent.Reset();\r\n  _readStreamIsClosedEvent.Reset();\r\n  ProcessedSize = 0;\r\n}\r\n\r\n\r\n  \r\nvoid CStreamBinder::CreateStreams(ISequentialInStream **inStream,\r\n      ISequentialOutStream **outStream)\r\n{\r\n  CSequentialInStreamForBinder *inStreamSpec = new\r\n      CSequentialInStreamForBinder;\r\n  CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n  inStreamSpec->SetBinder(this);\r\n  *inStream = inStreamLoc.Detach();\r\n\r\n  CSequentialOutStreamForBinder *outStreamSpec = new\r\n      CSequentialOutStreamForBinder;\r\n  CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);\r\n  outStreamSpec->SetBinder(this);\r\n  *outStream = outStreamLoc.Detach();\r\n\r\n  _buffer = NULL;\r\n  _bufferSize= 0;\r\n  ProcessedSize = 0;\r\n}\r\n\r\nHRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 sizeToRead = size;\r\n  if (size > 0)\r\n  {\r\n    RINOK(_thereAreBytesToReadEvent.Lock());\r\n    sizeToRead = MyMin(_bufferSize, size);\r\n    if (_bufferSize > 0)\r\n    {\r\n      memcpy(data, _buffer, sizeToRead);\r\n      _buffer = ((const Byte *)_buffer) + sizeToRead;\r\n      _bufferSize -= sizeToRead;\r\n      if (_bufferSize == 0)\r\n      {\r\n        _thereAreBytesToReadEvent.Reset();\r\n        _allBytesAreWritenEvent.Set();\r\n      }\r\n    }\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = sizeToRead;\r\n  ProcessedSize += sizeToRead;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseRead()\r\n{\r\n  _readStreamIsClosedEvent.Set();\r\n}\r\n\r\nHRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (size > 0)\r\n  {\r\n    _buffer = data;\r\n    _bufferSize = size;\r\n    _allBytesAreWritenEvent.Reset();\r\n    _thereAreBytesToReadEvent.Set();\r\n\r\n    HANDLE events[2];\r\n    events[0] = _allBytesAreWritenEvent;\r\n    events[1] = _readStreamIsClosedEvent;\r\n    DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);\r\n    if (waitResult != WAIT_OBJECT_0 + 0)\r\n    {\r\n      // ReadingWasClosed = true;\r\n      return S_FALSE;\r\n    }\r\n    // if(!_allBytesAreWritenEvent.Lock())\r\n    //   return E_FAIL;\r\n  }\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nvoid CStreamBinder::CloseWrite()\r\n{\r\n  // _bufferSize must be = 0\r\n  _thereAreBytesToReadEvent.Set();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/StreamBinder.h",
    "content": "// StreamBinder.h\r\n\r\n#ifndef __STREAMBINDER_H\r\n#define __STREAMBINDER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Windows/Synchronization.h\"\r\n\r\nclass CStreamBinder\r\n{\r\n  NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent;\r\n  NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent;\r\n  UInt32 _bufferSize;\r\n  const void *_buffer;\r\npublic:\r\n  // bool ReadingWasClosed;\r\n  UInt64 ProcessedSize;\r\n  CStreamBinder() {}\r\n  HRes CreateEvents();\r\n\r\n  void CreateStreams(ISequentialInStream **inStream,\r\n      ISequentialOutStream **outStream);\r\n  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseRead();\r\n\r\n  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);\r\n  void CloseWrite();\r\n  void ReInit();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/StreamObjects.cpp",
    "content": "// StreamObjects.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamObjects.h\"\r\n#include \"../../Common/Defs.h\"\r\n\r\n\r\nSTDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t rem = _size - _pos;\r\n  if (size < rem)\r\n    rem = (size_t)size;\r\n  memcpy(data, _dataPointer + _pos, rem);\r\n  _pos += rem;\r\n  if (processedSize != NULL)\r\n    *processedSize = (UInt32)rem;\r\n  return S_OK;\r\n}\r\n\r\n\r\nvoid CWriteBuffer::Write(const void *data, size_t size)\r\n{\r\n  size_t newCapacity = _size + size;\r\n  _buffer.EnsureCapacity(newCapacity);\r\n  memcpy(_buffer + _size, data, size);\r\n  _size += size;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  _writeBuffer.Write(data, (size_t)size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t rem = _size - _pos;\r\n  if (size < rem)\r\n    rem = (size_t)size;\r\n  memcpy(_buffer + _pos, data, rem);\r\n  _pos += rem;\r\n  if (processedSize != NULL)\r\n    *processedSize = (UInt32)rem;\r\n  return (rem == size ? S_OK : E_FAIL);\r\n}\r\n\r\nSTDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n\r\nSTDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 realProcessedSize;\r\n  HRESULT result = _stream->Write(data, size, &realProcessedSize);\r\n  _size += realProcessedSize;\r\n  if (processedSize != 0)\r\n    *processedSize = realProcessedSize;\r\n  return result;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/StreamObjects.h",
    "content": "// StreamObjects.h\r\n\r\n#ifndef __STREAMOBJECTS_H\r\n#define __STREAMOBJECTS_H\r\n\r\n#include \"../../Common/DynamicBuffer.h\"\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../IStream.h\"\r\n\r\nclass CSequentialInStreamImp:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *_dataPointer;\r\n  size_t _size;\r\n  size_t _pos;\r\n\r\npublic:\r\n  void Init(const Byte *dataPointer, size_t size)\r\n  {\r\n    _dataPointer = dataPointer;\r\n    _size = size;\r\n    _pos = 0;\r\n  }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n\r\nclass CWriteBuffer\r\n{\r\n  CByteDynamicBuffer _buffer;\r\n  size_t _size;\r\npublic:\r\n  CWriteBuffer(): _size(0) {}\r\n  void Init() { _size = 0;  }\r\n  void Write(const void *data, size_t size);\r\n  size_t GetSize() const { return _size; }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _buffer; }\r\n};\r\n\r\nclass CSequentialOutStreamImp:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CWriteBuffer _writeBuffer;\r\npublic:\r\n  void Init() { _writeBuffer.Init(); }\r\n  size_t GetSize() const { return _writeBuffer.GetSize(); }\r\n  const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamImp2:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\n  size_t _size;\r\n  size_t _pos;\r\npublic:\r\n\r\n  void Init(Byte *buffer, size_t size)\r\n  {\r\n    _buffer = buffer;\r\n    _pos = 0;\r\n    _size = size;\r\n  }\r\n\r\n  size_t GetPos() const { return _pos; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialInStreamSizeCount:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void Init(ISequentialInStream *stream)\r\n  {\r\n    _stream = stream;\r\n    _size = 0;\r\n  }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nclass CSequentialOutStreamSizeCount:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _size;\r\npublic:\r\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\r\n  void Init() { _size = 0; }\r\n  UInt64 GetSize() const { return _size; }\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StreamUtils.h\"\r\n\r\nstatic const UInt32 kBlockSize = ((UInt32)1 << 31);\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSize)\r\n{\r\n  size_t size = *processedSize;\r\n  *processedSize = 0;\r\n  while (size != 0)\r\n  {\r\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\r\n    UInt32 processedSizeLoc;\r\n    HRESULT res = stream->Read(data, curSize, &processedSizeLoc);\r\n    *processedSize += processedSizeLoc;\r\n    data = (void *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size)\r\n{\r\n  size_t processedSize = size;\r\n  RINOK(ReadStream(stream, data, &processedSize));\r\n  return (size == processedSize) ? S_OK : S_FALSE;\r\n}\r\n\r\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size)\r\n{\r\n  size_t processedSize = size;\r\n  RINOK(ReadStream(stream, data, &processedSize));\r\n  return (size == processedSize) ? S_OK : E_FAIL;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size)\r\n{\r\n  while (size != 0)\r\n  {\r\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\r\n    UInt32 processedSizeLoc;\r\n    HRESULT res = stream->Write(data, curSize, &processedSizeLoc);\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *size);\r\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size);\r\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/VirtThread.cpp",
    "content": "// VirtThread.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"VirtThread.h\"\r\n\r\nstatic THREAD_FUNC_DECL CoderThread(void *p)\r\n{\r\n  for (;;)\r\n  {\r\n    CVirtThread *t = (CVirtThread *)p;\r\n    t->StartEvent.Lock();\r\n    if (t->ExitEvent)\r\n      return 0;\r\n    t->Execute();\r\n    t->FinishedEvent.Set();\r\n  }\r\n}\r\n\r\nWRes CVirtThread::Create()\r\n{\r\n  RINOK(StartEvent.CreateIfNotCreated());\r\n  RINOK(FinishedEvent.CreateIfNotCreated());\r\n  StartEvent.Reset();\r\n  FinishedEvent.Reset();\r\n  ExitEvent = false;\r\n  if (Thread.IsCreated())\r\n    return S_OK;\r\n  return Thread.Create(CoderThread, this);\r\n}\r\n\r\nvoid CVirtThread::Start()\r\n{\r\n  ExitEvent = false;\r\n  StartEvent.Set();\r\n}\r\n\r\nCVirtThread::~CVirtThread()\r\n{\r\n  ExitEvent = true;\r\n  if (StartEvent.IsCreated())\r\n    StartEvent.Set();\r\n  Thread.Wait();\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Common/VirtThread.h",
    "content": "// VirtThread.h\r\n\r\n#ifndef __VIRTTHREAD_H\r\n#define __VIRTTHREAD_H\r\n\r\n#include \"../../Windows/Synchronization.h\"\r\n#include \"../../Windows/Thread.h\"\r\n\r\nstruct CVirtThread\r\n{\r\n  NWindows::NSynchronization::CAutoResetEvent StartEvent;\r\n  NWindows::NSynchronization::CAutoResetEvent FinishedEvent;\r\n  NWindows::CThread Thread;\r\n  bool ExitEvent;\r\n\r\n  ~CVirtThread();\r\n  WRes Create();\r\n  void Start();\r\n  void WaitFinish() { FinishedEvent.Lock(); }\r\n  virtual void Execute() = 0;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/Bcj2Coder.cpp",
    "content": "// Bcj2Coder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"Bcj2Coder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\ninline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }\r\ninline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }\r\ninline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CEncoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CEncoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize = 0;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusEncoder[i].Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  for (;;)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    for (;;)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it\r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        UInt32 index;\r\n        if (b == 0xE8)\r\n          index = prevByte;\r\n        else if (b == 0xE9)\r\n          index = 256;\r\n        else if (IsJcc(prevByte, b))\r\n          index = 257;\r\n        else\r\n        {\r\n          prevByte = b;\r\n          continue;\r\n        }\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (!IsJ(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src =\r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;\r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;\r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      unsigned index = GetIndex(prevByte, b);\r\n      if (convert)\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 1);\r\n        bufferPos += 5;\r\n        COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n        for (int i = 24; i >= 0; i -= 8)\r\n          s.WriteByte((Byte)(dest >> i));\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize =\r\n        _mainStream.GetProcessedSize() +\r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeEncoder.GetProcessedSize();\r\n      */\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 ** /* inSizes */,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 ** /* outSizes */,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256 + 2; i++)\r\n    _statusDecoder[i].Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  for (;;)\r\n  {\r\n    if (processedBytes >= (1 << 20) && progress != NULL)\r\n    {\r\n      /*\r\n      const UInt64 compressedSize =\r\n        _mainInStream.GetProcessedSize() +\r\n        _callStream.GetProcessedSize() +\r\n        _jumpStream.GetProcessedSize() +\r\n        _rangeDecoder.GetProcessedSize();\r\n      */\r\n      const UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    UInt32 i;\r\n    Byte b = 0;\r\n    const UInt32 kBurstSize = (1 << 18);\r\n    for (i = 0; i < kBurstSize; i++)\r\n    {\r\n      if (!_mainInStream.ReadByte(b))\r\n        return Flush();\r\n      _outStream.WriteByte(b);\r\n      if (IsJ(prevByte, b))\r\n        break;\r\n      prevByte = b;\r\n    }\r\n    processedBytes += i;\r\n    if (i == kBurstSize)\r\n      continue;\r\n    unsigned index = GetIndex(prevByte, b);\r\n    if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)\r\n    {\r\n      UInt32 src = 0;\r\n      CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\r\n      for (int i = 0; i < 4; i++)\r\n      {\r\n        Byte b0;\r\n        if(!s.ReadByte(b0))\r\n          return S_FALSE;\r\n        src <<= 8;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (Byte)(dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const CInBufferException &e) { return e.ErrorCode; }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/Bcj2Coder.h",
    "content": "// Bcj2Coder.h\r\n\r\n#ifndef __COMPRESS_BCJ2_CODER_H\r\n#define __COMPRESS_BCJ2_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NBcj2 {\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CEncoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CEncoder(): _buffer(0) {};\r\n  ~CEncoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic:\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n};\r\n\r\n#endif\r\n\r\nclass CDecoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CDecoder *_coder;\r\n  public:\r\n    CCoderReleaser(CDecoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/Bcj2Register.cpp",
    "content": "// Bcj2Register.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"Bcj2Coder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x0303011B, L\"BCJ2\", 4, false };\r\n\r\nREGISTER_CODEC(BCJ2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/BcjCoder.cpp",
    "content": "// BcjCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"BcjCoder.h\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/BcjCoder.h",
    "content": "// BcjCoder.h\r\n\r\n#ifndef __COMPRESS_BCJ_CODER_H\r\n#define __COMPRESS_BCJ_CODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Bra.h\"\r\n}\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  void x86Init() { x86_Convert_Init(_prevMask); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 ,\r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/BcjRegister.cpp",
    "content": "// BcjRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"BcjCoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }\r\n#ifndef EXTRACT_ONLY\r\nstatic void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder());  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x03030103, L\"BCJ\", 1, true };\r\n\r\nREGISTER_CODEC(BCJ)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __COMPRESS_BRANCH_CODER_H\r\n#define __COMPRESS_BRANCH_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/BranchMisc.cpp",
    "content": "// BranchMisc.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Bra.h\"\r\n}\r\n\r\n#include \"BranchMisc.h\"\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); }\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n  { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); }\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n  {  return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); }\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/BranchMisc.h",
    "content": "// BranchMisc.h\r\n\r\n#ifndef __COMPRESS_BRANCH_MISC_H\r\n#define __COMPRESS_BRANCH_MISC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM,   0x05, 1)\r\nMyClassA(BC_ARMT,  0x07, 1)\r\nMyClassA(BC_PPC,   0x02, 5)\r\nMyClassA(BC_SPARC, 0x08, 5)\r\nMyClassA(BC_IA64,  0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/BranchRegister.cpp",
    "content": "// BranchRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"BranchMisc.h\"\r\n\r\n#define CREATE_CODEC(x) \\\r\n  static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \\\r\n  static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }\r\n\r\nCREATE_CODEC(BC_PPC)\r\nCREATE_CODEC(BC_IA64)\r\nCREATE_CODEC(BC_ARM)\r\nCREATE_CODEC(BC_ARMT)\r\nCREATE_CODEC(BC_SPARC)\r\n\r\n#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true  }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  METHOD_ITEM(BC_PPC,   0x02, 0x05, L\"PPC\"),\r\n  METHOD_ITEM(BC_IA64,  0x04, 1, L\"IA64\"),\r\n  METHOD_ITEM(BC_ARM,   0x05, 1, L\"ARM\"),\r\n  METHOD_ITEM(BC_ARMT,  0x07, 1, L\"ARMT\"),\r\n  METHOD_ITEM(BC_SPARC, 0x08, 0x05, L\"SPARC\")\r\n};\r\n\r\nREGISTER_CODECS(Branch)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/ByteSwap.cpp",
    "content": "// ByteSwap.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nSTDMETHODIMP CByteSwap2::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 2;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b = data[i];\r\n    data[i] = data[i + 1];\r\n    data[i + 1] = b;\r\n  }\r\n  return i;\r\n}\r\n\r\nSTDMETHODIMP CByteSwap4::Init() { return S_OK; }\r\n\r\nSTDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)\r\n{\r\n  const UInt32 kStep = 4;\r\n  UInt32 i;\r\n  for (i = 0; i + kStep <= size; i += kStep)\r\n  {\r\n    Byte b0 = data[i];\r\n    Byte b1 = data[i + 1];\r\n    data[i] = data[i + 3];\r\n    data[i + 1] = data[i + 2];\r\n    data[i + 2] = b1;\r\n    data[i + 3] = b0;\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/ByteSwap.h",
    "content": "// ByteSwap.h\r\n\r\n#ifndef __COMPRESS_BYTE_SWAP_H\r\n#define __COMPRESS_BYTE_SWAP_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nclass CByteSwap2:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\nclass CByteSwap4:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/ByteSwapRegister.cpp",
    "content": "// ByteSwapRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"ByteSwap.h\"\r\n\r\nstatic void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }\r\nstatic void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }\r\n\r\nstatic CCodecInfo g_CodecsInfo[] =\r\n{\r\n  { CreateCodec2, CreateCodec4, 0x020302, L\"Swap2\", 1, true },\r\n  { CreateCodec4, CreateCodec4, 0x020304, L\"Swap4\", 1, true }\r\n};\r\n\r\nREGISTER_CODECS(ByteSwap)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/CodecExports.cpp",
    "content": "// CodecExports.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/ComTry.h\"\r\n#include \"../../Windows/PropVariant.h\"\r\n#include \"../Common/RegisterCodec.h\"\r\n#include \"../ICoder.h\"\r\n\r\nextern unsigned int g_NumCodecs;\r\nextern const CCodecInfo *g_Codecs[];\r\n\r\nstatic const UInt16 kDecodeId = 0x2790;\r\n\r\nDEFINE_GUID(CLSID_CCodec,\r\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\r\n{\r\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\r\n    value->vt = VT_BSTR;\r\n  return S_OK;\r\n}\r\n\r\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\r\n{\r\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\r\n}\r\n\r\nstatic HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)\r\n{\r\n  GUID clsId = CLSID_CCodec;\r\n  for (int i = 0; i < sizeof(id); i++, id >>= 8)\r\n    clsId.Data4[i] = (Byte)(id & 0xFF);\r\n  if (encode)\r\n    clsId.Data3++;\r\n  return SetPropGUID(clsId, value);\r\n}\r\n\r\nstatic HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)\r\n{\r\n  index = -1;\r\n  if (clsID->Data1 != CLSID_CCodec.Data1 ||\r\n      clsID->Data2 != CLSID_CCodec.Data2 ||\r\n      (clsID->Data3 & ~1) != kDecodeId)\r\n    return S_OK;\r\n  encode = (clsID->Data3 != kDecodeId);\r\n  UInt64 id = 0;\r\n  for (int j = 0; j < 8; j++)\r\n    id |= ((UInt64)clsID->Data4[j]) << (8 * j);\r\n  for (unsigned i = 0; i < g_NumCodecs; i++)\r\n  {\r\n    const CCodecInfo &codec = *g_Codecs[i];\r\n    if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)\r\n      continue;\r\n    if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n        codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n      return E_NOINTERFACE;\r\n    index = i;\r\n    return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  const CCodecInfo &codec = *g_Codecs[index];\r\n  if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\r\n      codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\r\n    return E_NOINTERFACE;\r\n  if (encode)\r\n  {\r\n    if (!codec.CreateEncoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateEncoder();\r\n  }\r\n  else\r\n  {\r\n    if (!codec.CreateDecoder)\r\n      return CLASS_E_CLASSNOTAVAILABLE;\r\n    *outObject = codec.CreateDecoder();\r\n  }\r\n  if (isCoder)\r\n    ((ICompressCoder *)*outObject)->AddRef();\r\n  else if (isCoder2)\r\n    ((ICompressCoder2 *)*outObject)->AddRef();\r\n  else\r\n    ((ICompressFilter *)*outObject)->AddRef();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)\r\n{\r\n  *outObject = 0;\r\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\r\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\r\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\r\n  if (!isCoder && !isCoder2 && !isFilter)\r\n    return E_NOINTERFACE;\r\n  bool encode;\r\n  int codecIndex;\r\n  HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);\r\n  if (res != S_OK)\r\n    return res;\r\n  if (codecIndex < 0)\r\n    return CLASS_E_CLASSNOTAVAILABLE;\r\n  return CreateCoder2(encode, codecIndex, iid, outObject);\r\n}\r\n\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)\r\n{\r\n  ::VariantClear((VARIANTARG *)value);\r\n  const CCodecInfo &codec = *g_Codecs[codecIndex];\r\n  switch(propID)\r\n  {\r\n    case NMethodPropID::kID:\r\n    {\r\n      value->uhVal.QuadPart = (UInt64)codec.Id;\r\n      value->vt = VT_UI8;\r\n      break;\r\n    }\r\n    case NMethodPropID::kName:\r\n      if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)\r\n        value->vt = VT_BSTR;\r\n      break;\r\n    case NMethodPropID::kDecoder:\r\n      if (codec.CreateDecoder)\r\n        return SetClassID(codec.Id, false, value);\r\n      break;\r\n    case NMethodPropID::kEncoder:\r\n      if (codec.CreateEncoder)\r\n        return SetClassID(codec.Id, true, value);\r\n      break;\r\n    case NMethodPropID::kInStreams:\r\n    {\r\n      if (codec.NumInStreams != 1)\r\n      {\r\n        value->vt = VT_UI4;\r\n        value->ulVal = (ULONG)codec.NumInStreams;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDAPI GetNumberOfMethods(UINT32 *numCodecs)\r\n{\r\n  *numCodecs = g_NumCodecs;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/CopyCoder.cpp",
    "content": "// Compress/CopyCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"CopyCoder.h\"\r\n\r\nnamespace NCompress {\r\n\r\nstatic const UInt32 kBufferSize = 1 << 17;\r\n\r\nCCopyCoder::~CCopyCoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)::MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  TotalSize = 0;\r\n  for (;;)\r\n  {\r\n    UInt32 realProcessedSize;\r\n    UInt32 size = kBufferSize;\r\n    if (outSize != 0)\r\n      if (size > *outSize - TotalSize)\r\n        size = (UInt32)(*outSize - TotalSize);\r\n    RINOK(inStream->Read(_buffer, size, &realProcessedSize));\r\n    if (realProcessedSize == 0)\r\n      break;\r\n    RINOK(WriteStream(outStream, _buffer, realProcessedSize));\r\n    TotalSize += realProcessedSize;\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = TotalSize;\r\n  return S_OK;\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/CopyCoder.h",
    "content": "// Compress/CopyCoder.h\r\n\r\n#ifndef __COMPRESS_COPY_CODER_H\r\n#define __COMPRESS_COPY_CODER_H\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\n\r\nclass CCopyCoder:\r\n  public ICompressCoder,\r\n  public ICompressGetInStreamProcessedSize,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  UInt64 TotalSize;\r\n  CCopyCoder(): TotalSize(0) , _buffer(0) {};\r\n  ~CCopyCoder();\r\n\r\n  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/CopyRegister.cpp",
    "content": "// CopyRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"CopyCoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n{ CreateCodec, CreateCodec, 0x00, L\"Copy\", 1, false };\r\n\r\nREGISTER_CODEC(Copy)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /FAcs /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaDecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LzmaEncoder.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\System.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Thread.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LzmaUtil\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Threads.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\..\\C\\Types.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBenchCon.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LzmaDecoder.h\"\r\n#include \"../LzmaEncoder.h\"\r\n\r\n#include \"LzmaBenchCon.h\"\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\nextern \"C\"\r\n{\r\n  #include \"../../../../C/7zVersion.h\"\r\n  #include \"../../../../C/Alloc.h\"\r\n  #include \"../../../../C/LzmaUtil/Lzma86Dec.h\"\r\n  #include \"../../../../C/LzmaUtil/Lzma86Enc.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kAlgo,\r\n  kDict,\r\n  kFb,\r\n  kMc,\r\n  kLc,\r\n  kLp,\r\n  kPb,\r\n  kMatchFinder,\r\n  kMultiThread,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] =\r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MT\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kPostChar, false, 0, 0, L\"+\" }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\"\r\n    \"  -d{N}:  set dictionary size - [12, 30], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -mc{N}: set number of cycles for match finder\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\\n\"\r\n    \"  -mt{N}: set number of CPU threads\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[],\r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nstatic void ParseUInt32(const CParser &parser, int index, UInt32 &res)\r\n{\r\n  if (parser[index].ThereIs)\r\n    if (!GetNumber(parser[index].PostStrings[0], res))\r\n      IncorrectCommand();\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);\r\n  if (unsupportedTypes)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }\r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...)\r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++];\r\n\r\n  bool dictDefined = false;\r\n  UInt32 dict = (UInt32)-1;\r\n  if(parser[NKey::kDict].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDict].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dict = 1 << dicLog;\r\n    dictDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  UInt32 numThreads = (UInt32)-1;\r\n\r\n  #ifdef COMPRESS_MF_MT\r\n  if (parser[NKey::kMultiThread].ThereIs)\r\n  {\r\n    UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n    const UString &s = parser[NKey::kMultiThread].PostStrings[0];\r\n    if (s.IsEmpty())\r\n      numThreads = numCPUs;\r\n    else\r\n      if (!GetNumber(s, numThreads))\r\n        IncorrectCommand();\r\n  }\r\n  #endif\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 1;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchCon(stderr, numIterations, numThreads, dict);\r\n  }\r\n\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = 1;\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++];\r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\",\r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  COutFileStream *outStreamSpec = NULL;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++];\r\n    outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\",\r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    size_t inSize = (size_t)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize);\r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    if (ReadStream_FAIL(inStream, inBuffer, inSize) != S_OK)\r\n      throw \"Can not read\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSize;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize);\r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictDefined)\r\n        dict = 1 << 23;\r\n      int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,\r\n          5, dict, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      UInt64 outSize64;\r\n      if (Lzma86_GetUnpackSize(inBuffer, inSize, &outSize64) != 0)\r\n        throw \"data error\";\r\n      outSize = (size_t)outSize64;\r\n      if (outSize != outSize64)\r\n        throw \"too big\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize);\r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = Lzma86_Decode(outBuffer, &outSize, inBuffer, &inSize);\r\n      if (inSize != (size_t)fileSize)\r\n        throw \"incorrect processed size\";\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, outSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLzma::CEncoder *encoderSpec = new NCompress::NLzma::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictDefined)\r\n      dict = 1 << 23;\r\n\r\n    UInt32 pb = 2;\r\n    UInt32 lc = 3; // = 0; for 32-bit data\r\n    UInt32 lp = 0; // = 2; for 32-bit data\r\n    UInt32 algo = 1;\r\n    UInt32 fb = 128;\r\n    UInt32 mc = 16 + fb / 2;\r\n    bool mcDefined = false;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    ParseUInt32(parser, NKey::kAlgo, algo);\r\n    ParseUInt32(parser, NKey::kFb, fb);\r\n    ParseUInt32(parser, NKey::kLc, lc);\r\n    ParseUInt32(parser, NKey::kLp, lp);\r\n    ParseUInt32(parser, NKey::kPb, pb);\r\n\r\n    mcDefined = parser[NKey::kMc].ThereIs;\r\n    if (mcDefined)\r\n      if (!GetNumber(parser[NKey::kMc].PostStrings[0], mc))\r\n        IncorrectCommand();\r\n    \r\n    PROPID propIDs[] =\r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker,\r\n      NCoderPropID::kNumThreads,\r\n      NCoderPropID::kMatchFinderCycles,\r\n    };\r\n    const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\r\n    PROPVARIANT props[kNumPropsMax];\r\n    for (int p = 0; p < 6; p++)\r\n      props[p].vt = VT_UI4;\r\n\r\n    props[0].ulVal = (UInt32)dict;\r\n    props[1].ulVal = (UInt32)pb;\r\n    props[2].ulVal = (UInt32)lc;\r\n    props[3].ulVal = (UInt32)lp;\r\n    props[4].ulVal = (UInt32)algo;\r\n    props[5].ulVal = (UInt32)fb;\r\n\r\n    props[6].vt = VT_BSTR;\r\n    props[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    props[7].vt = VT_BOOL;\r\n    props[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    props[8].vt = VT_UI4;\r\n    props[8].ulVal = (UInt32)numThreads;\r\n\r\n    // it must be last in property list\r\n    props[9].vt = VT_UI4;\r\n    props[9].ulVal = (UInt32)mc;\r\n\r\n    int numProps = kNumPropsMax;\r\n    if (!mcDefined)\r\n      numProps--;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, props, numProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }\r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NCompress::NLzma::CDecoder *decoderSpec = new NCompress::NLzma::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    decoderSpec->FinishStream = true;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte header[kPropertiesSize + 8];\r\n    if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(header, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n      fileSize |= ((UInt64)header[kPropertiesSize + i]) << (8 * i);\r\n\r\n    if (decoder->Code(inStream, outStream, 0, (fileSize == (UInt64)(Int64)-1) ? 0 : &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }\r\n  }\r\n  if (outStreamSpec != NULL)\r\n  {\r\n    if (outStreamSpec->Close() != S_OK)\r\n    {\r\n      fprintf(stderr, \"File closing error\");\r\n      return 1;\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n\r\nint MY_CDECL main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s)\r\n  {\r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1;\r\n  }\r\n  catch(...)\r\n  {\r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#define USE_POSIX_TIME\r\n#define USE_POSIX_TIME2\r\n#endif\r\n\r\n#ifdef USE_POSIX_TIME\r\n#include <time.h>\r\n#ifdef USE_POSIX_TIME2\r\n#include <sys/time.h>\r\n#endif\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#define USE_ALLOCA\r\n#endif\r\n\r\n#ifdef USE_ALLOCA\r\n#ifdef _WIN32\r\n#include <malloc.h>\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n#endif\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/7zCrc.h\"\r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n\r\n#ifdef BENCH_MT\r\n#include \"../../../Windows/Synchronization.h\"\r\n#include \"../../../Windows/Thread.h\"\r\n#endif\r\n\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../../Windows/PropVariant.h\"\r\n#include \"../../ICoder.h\"\r\n#else\r\n#include \"../LzmaDecoder.h\"\r\n#include \"../LzmaEncoder.h\"\r\n#endif\r\n\r\nstatic const UInt32 kUncompressMinBlockSize = 1 << 26;\r\nstatic const UInt32 kAdditionalSize = (1 << 16);\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 5;\r\n\r\nclass CBaseRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CBaseRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd()\r\n  {\r\n    return\r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBenchBuffer\r\n{\r\npublic:\r\n  size_t BufferSize;\r\n  Byte *Buffer;\r\n  CBenchBuffer(): Buffer(0) {}\r\n  virtual ~CBenchBuffer() { Free(); }\r\n  void Free()\r\n  {\r\n    ::MidFree(Buffer);\r\n    Buffer = 0;\r\n  }\r\n  bool Alloc(size_t bufferSize)\r\n  {\r\n    if (Buffer != 0 && BufferSize == bufferSize)\r\n      return true;\r\n    Free();\r\n    Buffer = (Byte *)::MidAlloc(bufferSize);\r\n    BufferSize = bufferSize;\r\n    return (Buffer != 0);\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator: public CBenchBuffer\r\n{\r\n  CBaseRandomGenerator *RG;\r\npublic:\r\n  void Set(CBaseRandomGenerator *rg) { RG = rg; }\r\n  UInt32 GetVal(UInt32 &res, int numBits)\r\n  {\r\n    UInt32 val = res & (((UInt32)1 << numBits) - 1);\r\n    res >>= numBits;\r\n    return val;\r\n  }\r\n  UInt32 GetLen(UInt32 &res)\r\n  {\r\n    UInt32 len = GetVal(res, 2);\r\n    return GetVal(res, 1 + len);\r\n  }\r\n  void Generate()\r\n  {\r\n    UInt32 pos = 0;\r\n    UInt32 rep0 = 1;\r\n    while (pos < BufferSize)\r\n    {\r\n      UInt32 res = RG->GetRnd();\r\n      res >>= 1;\r\n      if (GetVal(res, 1) == 0 || pos < 1024)\r\n        Buffer[pos++] = (Byte)(res & 0xFF);\r\n      else\r\n      {\r\n        UInt32 len;\r\n        len = 1 + GetLen(res);\r\n        if (GetVal(res, 3) != 0)\r\n        {\r\n          len += GetLen(res);\r\n          do\r\n          {\r\n            UInt32 ppp = GetVal(res, 5) + 6;\r\n            res = RG->GetRnd();\r\n            if (ppp > 30)\r\n              continue;\r\n            rep0 = /* (1 << ppp) +*/  GetVal(res, ppp);\r\n            res = RG->GetRnd();\r\n          }\r\n          while (rep0 >= pos);\r\n          rep0++;\r\n        }\r\n\r\n        for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)\r\n          Buffer[pos] = Buffer[pos - rep0];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\n\r\nclass CBenchmarkInStream:\r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Pos;\r\n  size_t Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t remain = Size - Pos;\r\n  UInt32 kMaxBlockSize = (1 << 20);\r\n  if (size > kMaxBlockSize)\r\n    size = kMaxBlockSize;\r\n  if (size > remain)\r\n    size = (UInt32)remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream:\r\n  public ISequentialOutStream,\r\n  public CBenchBuffer,\r\n  public CMyUnknownImp\r\n{\r\n  // bool _overflow;\r\npublic:\r\n  UInt32 Pos;\r\n  // CBenchmarkOutStream(): _overflow(false) {}\r\n  void Init()\r\n  {\r\n    // _overflow = false;\r\n    Pos = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  size_t curSize = BufferSize - Pos;\r\n  if (curSize > size)\r\n    curSize = size;\r\n  memcpy(Buffer + Pos, data, curSize);\r\n  Pos += (UInt32)curSize;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)curSize;\r\n  if (curSize != size)\r\n  {\r\n    // _overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream:\r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  UInt32 Crc;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { Crc = CRC_INIT_VAL; }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  Crc = CrcUpdate(Crc, data, size);\r\n  if (processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  timeval v;\r\n  if (gettimeofday(&v, 0) == 0)\r\n    return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;\r\n  return (UInt64)time(NULL) * 1000000;\r\n  #else\r\n  return time(NULL);\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return GetTickCount();\r\n  #endif\r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  #ifdef USE_POSIX_TIME2\r\n  return 1000000;\r\n  #else\r\n  return 1;\r\n  #endif\r\n  #else\r\n  /*\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  */\r\n  return 1000;\r\n  #endif\r\n}\r\n\r\n#ifndef USE_POSIX_TIME\r\nstatic inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }\r\n#endif\r\nstatic UInt64 GetUserTime()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return clock();\r\n  #else\r\n  FILETIME creationTime, exitTime, kernelTime, userTime;\r\n  if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)\r\n    return GetTime64(userTime) + GetTime64(kernelTime);\r\n  return (UInt64)GetTickCount() * 10000;\r\n  #endif\r\n}\r\n\r\nstatic UInt64 GetUserFreq()\r\n{\r\n  #ifdef USE_POSIX_TIME\r\n  return CLOCKS_PER_SEC;\r\n  #else\r\n  return 10000000;\r\n  #endif\r\n}\r\n\r\nclass CBenchProgressStatus\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::NSynchronization::CCriticalSection CS;\r\n  #endif\r\npublic:\r\n  HRESULT Res;\r\n  bool EncodeMode;\r\n  void SetResult(HRESULT res)\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    Res = res;\r\n  }\r\n  HRESULT GetResult()\r\n  {\r\n    #ifdef BENCH_MT\r\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\r\n    #endif\r\n    return Res;\r\n  }\r\n};\r\n\r\nclass CBenchProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CBenchProgressStatus *Status;\r\n  CBenchInfo BenchInfo;\r\n  HRESULT Res;\r\n  IBenchCallback *callback;\r\n  CBenchProgressInfo(): callback(0) {}\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nvoid SetStartTime(CBenchInfo &bi)\r\n{\r\n  bi.GlobalFreq = GetFreq();\r\n  bi.UserFreq = GetUserFreq();\r\n  bi.GlobalTime = ::GetTimeCount();\r\n  bi.UserTime = ::GetUserTime();\r\n}\r\n\r\nvoid SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)\r\n{\r\n  dest.GlobalFreq = GetFreq();\r\n  dest.UserFreq = GetUserFreq();\r\n  dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;\r\n  dest.UserTime = ::GetUserTime() - biStart.UserTime;\r\n}\r\n\r\nSTDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  HRESULT res = Status->GetResult();\r\n  if (res != S_OK)\r\n    return res;\r\n  if (!callback)\r\n    return res;\r\n  CBenchInfo info = BenchInfo;\r\n  SetFinishTime(BenchInfo, info);\r\n  if (Status->EncodeMode)\r\n  {\r\n    info.UnpackSize = *inSize;\r\n    info.PackSize = *outSize;\r\n    res = callback->SetEncodeResult(info, false);\r\n  }\r\n  else\r\n  {\r\n    info.PackSize = BenchInfo.PackSize + *inSize;\r\n    info.UnpackSize = BenchInfo.UnpackSize + *outSize;\r\n    res = callback->SetDecodeResult(info, false);\r\n  }\r\n  if (res != S_OK)\r\n    Status->SetResult(res);\r\n  return res;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nUInt64 GetUsage(const CBenchInfo &info)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userTime, userFreq);\r\n  NormalizeVals(globalFreq, globalTime);\r\n  if (userFreq == 0)\r\n    userFreq = 1;\r\n  if (globalTime == 0)\r\n    globalTime = 1;\r\n  return userTime * globalFreq * 1000000 / userFreq / globalTime;\r\n}\r\n\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)\r\n{\r\n  UInt64 userTime = info.UserTime;\r\n  UInt64 userFreq = info.UserFreq;\r\n  UInt64 globalTime = info.GlobalTime;\r\n  UInt64 globalFreq = info.GlobalFreq;\r\n  NormalizeVals(userFreq, userTime);\r\n  NormalizeVals(globalTime, globalFreq);\r\n  if (globalFreq == 0)\r\n    globalFreq = 1;\r\n  if (userTime == 0)\r\n    userTime = 1;\r\n  return userFreq * globalTime / globalFreq *  rating / userTime;\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)\r\n{\r\n  UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);\r\n  UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits));\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)\r\n{\r\n  UInt64 numCommands = (inSize * 200 + outSize * 4) * numIterations;\r\n  return MyMultDiv64(numCommands, elapsedTime, freq);\r\n}\r\n\r\n#ifdef EXTERNAL_LZMA\r\ntypedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID,\r\n    const GUID *interfaceID, void **outObject);\r\n#endif\r\n\r\nstruct CEncoderInfo;\r\n\r\nstruct CEncoderInfo\r\n{\r\n  #ifdef BENCH_MT\r\n  NWindows::CThread thread[2];\r\n  #endif\r\n  CMyComPtr<ICompressCoder> encoder;\r\n  CBenchProgressInfo *progressInfoSpec[2];\r\n  CMyComPtr<ICompressProgressInfo> progressInfo[2];\r\n  UInt32 NumIterations;\r\n  #ifdef USE_ALLOCA\r\n  size_t AllocaSize;\r\n  #endif\r\n\r\n  struct CDecoderInfo\r\n  {\r\n    CEncoderInfo *Encoder;\r\n    UInt32 DecoderIndex;\r\n    #ifdef USE_ALLOCA\r\n    size_t AllocaSize;\r\n    #endif\r\n    bool CallbackMode;\r\n  };\r\n  CDecoderInfo decodersInfo[2];\r\n\r\n  CMyComPtr<ICompressCoder> decoders[2];\r\n  HRESULT Results[2];\r\n  CBenchmarkOutStream *outStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  IBenchCallback *callback;\r\n  UInt32 crc;\r\n  UInt32 kBufferSize;\r\n  UInt32 compressedSize;\r\n  CBenchRandomGenerator rg;\r\n  CBenchmarkOutStream *propStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> propStream;\r\n  HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);\r\n  HRESULT Encode();\r\n  HRESULT Decode(UInt32 decoderIndex);\r\n\r\n  CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}\r\n\r\n  #ifdef BENCH_MT\r\n  static THREAD_FUNC_DECL EncodeThreadFunction(void *param)\r\n  {\r\n    CEncoderInfo *encoder = (CEncoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(encoder->AllocaSize);\r\n    #endif\r\n    HRESULT res = encoder->Encode();\r\n    encoder->Results[0] = res;\r\n    if (res != S_OK)\r\n      encoder->progressInfoSpec[0]->Status->SetResult(res);\r\n\r\n    return 0;\r\n  }\r\n  static THREAD_FUNC_DECL DecodeThreadFunction(void *param)\r\n  {\r\n    CDecoderInfo *decoder = (CDecoderInfo *)param;\r\n    #ifdef USE_ALLOCA\r\n    alloca(decoder->AllocaSize);\r\n    #endif\r\n    CEncoderInfo *encoder = decoder->Encoder;\r\n    encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);\r\n    return 0;\r\n  }\r\n\r\n  HRESULT CreateEncoderThread()\r\n  {\r\n    return thread[0].Create(EncodeThreadFunction, this);\r\n  }\r\n\r\n  HRESULT CreateDecoderThread(int index, bool callbackMode\r\n      #ifdef USE_ALLOCA\r\n      , size_t allocaSize\r\n      #endif\r\n      )\r\n  {\r\n    CDecoderInfo &decoder = decodersInfo[index];\r\n    decoder.DecoderIndex = index;\r\n    decoder.Encoder = this;\r\n    #ifdef USE_ALLOCA\r\n    decoder.AllocaSize = allocaSize;\r\n    #endif\r\n    decoder.CallbackMode = callbackMode;\r\n    return thread[index].Create(DecodeThreadFunction, &decoder);\r\n  }\r\n  #endif\r\n};\r\n\r\nHRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)\r\n{\r\n  rg.Set(rgLoc);\r\n  kBufferSize = dictionarySize + kAdditionalSize;\r\n  UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n  if (!rg.Alloc(kBufferSize))\r\n    return E_OUTOFMEMORY;\r\n  rg.Generate();\r\n  crc = CrcCalc(rg.Buffer, rg.BufferSize);\r\n\r\n  outStreamSpec = new CBenchmarkOutStream;\r\n  if (!outStreamSpec->Alloc(kCompressedBufferSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  outStream = outStreamSpec;\r\n\r\n  propStreamSpec = 0;\r\n  if (!propStream)\r\n  {\r\n    propStreamSpec = new CBenchmarkOutStream;\r\n    propStream = propStreamSpec;\r\n  }\r\n  if (!propStreamSpec->Alloc(kMaxLzmaPropSize))\r\n    return E_OUTOFMEMORY;\r\n  propStreamSpec->Init();\r\n  \r\n  PROPID propIDs[] =\r\n  {\r\n    NCoderPropID::kDictionarySize,\r\n    NCoderPropID::kMultiThread\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)dictionarySize;\r\n\r\n  properties[1].vt = VT_BOOL;\r\n  properties[1].boolVal = (numThreads > 1) ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n  {\r\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\r\n    RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));\r\n    if (!setCoderProperties)\r\n      return E_FAIL;\r\n    RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, kNumProps));\r\n\r\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\r\n    encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);\r\n    if (writeCoderProperties)\r\n    {\r\n      RINOK(writeCoderProperties->WriteCoderProperties(propStream));\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Encode()\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n  outStreamSpec->Init();\r\n\r\n  RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));\r\n  compressedSize = outStreamSpec->Pos;\r\n  encoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoderInfo::Decode(UInt32 decoderIndex)\r\n{\r\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n  CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];\r\n\r\n  CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;\r\n  decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);\r\n  if (!compressSetDecoderProperties)\r\n    return E_FAIL;\r\n\r\n  CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n  CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n  CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];\r\n  pi->BenchInfo.UnpackSize = 0;\r\n  pi->BenchInfo.PackSize = 0;\r\n\r\n  for (UInt32 j = 0; j < NumIterations; j++)\r\n  {\r\n    inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n    crcOutStreamSpec->Init();\r\n    \r\n    RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));\r\n    UInt64 outSize = kBufferSize;\r\n    RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));\r\n    if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)\r\n      return S_FALSE;\r\n    pi->BenchInfo.UnpackSize += kBufferSize;\r\n    pi->BenchInfo.PackSize += compressedSize;\r\n  }\r\n  decoder.Release();\r\n  return S_OK;\r\n}\r\n\r\nstatic const UInt32 kNumThreadsMax = (1 << 16);\r\n\r\nstruct CBenchEncoders\r\n{\r\n  CEncoderInfo *encoders;\r\n  CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }\r\n  ~CBenchEncoders() { delete []encoders; }\r\n};\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)\r\n{\r\n  UInt32 numEncoderThreads =\r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? numThreads / 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  UInt32 numSubDecoderThreads =\r\n    #ifdef BENCH_MT\r\n    (numThreads > 1 ? 2 : 1);\r\n    #else\r\n    1;\r\n    #endif\r\n  if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)\r\n  {\r\n    return E_INVALIDARG;\r\n  }\r\n\r\n  CBenchEncoders encodersSpec(numEncoderThreads);\r\n  CEncoderInfo *encoders = encodersSpec.encoders;\r\n\r\n  #ifdef EXTERNAL_LZMA\r\n  UString name = L\"LZMA\";\r\n  #endif\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.callback = (i == 0) ? callback : 0;\r\n\r\n    #ifdef EXTERNAL_LZMA\r\n    RINOK(codecs->CreateCoder(name, true, encoder.encoder));\r\n    #else\r\n    encoder.encoder = new NCompress::NLzma::CEncoder;\r\n    #endif\r\n    for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n    {\r\n      #ifdef EXTERNAL_LZMA\r\n      RINOK(codecs->CreateCoder(name, false, encoder.decoders[j]));\r\n      #else\r\n      encoder.decoders[j] = new NCompress::NLzma::CDecoder;\r\n      #endif\r\n    }\r\n  }\r\n\r\n  CBaseRandomGenerator rg;\r\n  rg.Init();\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));\r\n  }\r\n\r\n  CBenchProgressStatus status;\r\n  status.Res = S_OK;\r\n  status.EncodeMode = true;\r\n\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;\r\n      encoder.progressInfoSpec[j]->Status = &status;\r\n    }\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numEncoderThreads > 1)\r\n    {\r\n      #ifdef USE_ALLOCA\r\n      encoder.AllocaSize = (i * 16 * 21) & 0x7FF;\r\n      #endif\r\n      RINOK(encoder.CreateEncoderThread())\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Encode());\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  if (numEncoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      encoders[i].thread[0].Wait();\r\n  #endif\r\n\r\n  RINOK(status.Res);\r\n\r\n  CBenchInfo info;\r\n\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = 1; // progressInfoSpec->NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetEncodeResult(info, true));\r\n\r\n\r\n  status.Res = S_OK;\r\n  status.EncodeMode = false;\r\n\r\n  UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;\r\n\r\n    if (i == 0)\r\n    {\r\n      encoder.progressInfoSpec[0]->callback = callback;\r\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;\r\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\r\n    }\r\n\r\n    #ifdef BENCH_MT\r\n    if (numDecoderThreads > 1)\r\n    {\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)\r\n            #ifdef USE_ALLOCA\r\n            , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF\r\n            #endif\r\n            );\r\n        RINOK(res);\r\n      }\r\n    }\r\n    else\r\n    #endif\r\n    {\r\n      RINOK(encoder.Decode(0));\r\n    }\r\n  }\r\n  #ifdef BENCH_MT\r\n  HRESULT res = S_OK;\r\n  if (numDecoderThreads > 1)\r\n    for (i = 0; i < numEncoderThreads; i++)\r\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\r\n      {\r\n        CEncoderInfo &encoder = encoders[i];\r\n        encoder.thread[j].Wait();\r\n        if (encoder.Results[j] != S_OK)\r\n          res = encoder.Results[j];\r\n      }\r\n  RINOK(res);\r\n  #endif\r\n  RINOK(status.Res);\r\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\r\n  info.UnpackSize = 0;\r\n  info.PackSize = 0;\r\n  info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;\r\n  for (i = 0; i < numEncoderThreads; i++)\r\n  {\r\n    CEncoderInfo &encoder = encoders[i];\r\n    info.UnpackSize += encoder.kBufferSize;\r\n    info.PackSize += encoder.compressedSize;\r\n  }\r\n  RINOK(callback->SetDecodeResult(info, false));\r\n  RINOK(callback->SetDecodeResult(info, true));\r\n  return S_OK;\r\n}\r\n\r\n\r\ninline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)\r\n{\r\n  UInt32 hs = dictionary - 1;\r\n  hs |= (hs >> 1);\r\n  hs |= (hs >> 2);\r\n  hs |= (hs >> 4);\r\n  hs |= (hs >> 8);\r\n  hs >>= 1;\r\n  hs |= 0xFFFF;\r\n  if (hs > (1 << 24))\r\n    hs >>= 1;\r\n  hs++;\r\n  return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +\r\n      (1 << 20) + (multiThread ? (6 << 20) : 0);\r\n}\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  const UInt32 kBufferSize = dictionary;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2);\r\n  UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;\r\n  UInt32 numBigThreads = numThreads / numSubThreads;\r\n  return (kBufferSize + kCompressedBufferSize +\r\n    GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;\r\n}\r\n\r\nstatic bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)\r\n{\r\n  for (UInt32 i = 0; i < numCycles; i++)\r\n    if (CrcCalc(data, size) != crcBase)\r\n      return false;\r\n  return true;\r\n}\r\n\r\n#ifdef BENCH_MT\r\nstruct CCrcInfo\r\n{\r\n  NWindows::CThread Thread;\r\n  const Byte *Data;\r\n  UInt32 Size;\r\n  UInt32 NumCycles;\r\n  UInt32 Crc;\r\n  bool Res;\r\n  void Wait()\r\n  {\r\n    Thread.Wait();\r\n    Thread.Close();\r\n  }\r\n};\r\n\r\nstatic THREAD_FUNC_DECL CrcThreadFunction(void *param)\r\n{\r\n  CCrcInfo *p = (CCrcInfo *)param;\r\n  p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);\r\n  return 0;\r\n}\r\n\r\nstruct CCrcThreads\r\n{\r\n  UInt32 NumThreads;\r\n  CCrcInfo *Items;\r\n  CCrcThreads(): Items(0), NumThreads(0) {}\r\n  void WaitAll()\r\n  {\r\n    for (UInt32 i = 0; i < NumThreads; i++)\r\n      Items[i].Wait();\r\n    NumThreads = 0;\r\n  }\r\n  ~CCrcThreads()\r\n  {\r\n    WaitAll();\r\n    delete []Items;\r\n  }\r\n};\r\n#endif\r\n\r\nstatic UInt32 CrcCalc1(const Byte *buf, UInt32 size)\r\n{\r\n  UInt32 crc = CRC_INIT_VAL;;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    crc = CRC_UPDATE_BYTE(crc, buf[i]);\r\n  return CRC_GET_DIGEST(crc);\r\n}\r\n\r\nstatic void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  for (UInt32 i = 0; i < size; i++)\r\n    buf[i] = (Byte)RG.GetRnd();\r\n}\r\n\r\nstatic UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\r\n{\r\n  RandGen(buf, size, RG);\r\n  return CrcCalc1(buf, size);\r\n}\r\n\r\nbool CrcInternalTest()\r\n{\r\n  CBenchBuffer buffer;\r\n  const UInt32 kBufferSize0 = (1 << 8);\r\n  const UInt32 kBufferSize1 = (1 << 10);\r\n  const UInt32 kCheckSize = (1 << 5);\r\n  if (!buffer.Alloc(kBufferSize0 + kBufferSize1))\r\n    return false;\r\n  Byte *buf = buffer.Buffer;\r\n  UInt32 i;\r\n  for (i = 0; i < kBufferSize0; i++)\r\n    buf[i] = (Byte)i;\r\n  UInt32 crc1 = CrcCalc1(buf, kBufferSize0);\r\n  if (crc1 != 0x29058C73)\r\n    return false;\r\n  CBaseRandomGenerator RG;\r\n  RandGen(buf + kBufferSize0, kBufferSize1, RG);\r\n  for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)\r\n    for (UInt32 j = 0; j < kCheckSize; j++)\r\n      if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))\r\n        return false;\r\n  return true;\r\n}\r\n\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)\r\n{\r\n  if (numThreads == 0)\r\n    numThreads = 1;\r\n\r\n  CBenchBuffer buffer;\r\n  size_t totalSize = (size_t)bufferSize * numThreads;\r\n  if (totalSize / numThreads != bufferSize)\r\n    return E_OUTOFMEMORY;\r\n  if (!buffer.Alloc(totalSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  Byte *buf = buffer.Buffer;\r\n  CBaseRandomGenerator RG;\r\n  UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;\r\n\r\n  UInt64 timeVal;\r\n  #ifdef BENCH_MT\r\n  CCrcThreads threads;\r\n  if (numThreads > 1)\r\n  {\r\n    threads.Items = new CCrcInfo[numThreads];\r\n    UInt32 i;\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      Byte *data = buf + (size_t)bufferSize * i;\r\n      info.Data = data;\r\n      info.NumCycles = numCycles;\r\n      info.Size = bufferSize;\r\n      info.Crc = RandGenCrc(data, bufferSize, RG);\r\n    }\r\n    timeVal = GetTimeCount();\r\n    for (i = 0; i < numThreads; i++)\r\n    {\r\n      CCrcInfo &info = threads.Items[i];\r\n      RINOK(info.Thread.Create(CrcThreadFunction, &info));\r\n      threads.NumThreads++;\r\n    }\r\n    threads.WaitAll();\r\n    for (i = 0; i < numThreads; i++)\r\n      if (!threads.Items[i].Res)\r\n        return S_FALSE;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 crc = RandGenCrc(buf, bufferSize, RG);\r\n    timeVal = GetTimeCount();\r\n    if (!CrcBig(buf, bufferSize, numCycles, crc))\r\n      return S_FALSE;\r\n  }\r\n  timeVal = GetTimeCount() - timeVal;\r\n  if (timeVal == 0)\r\n    timeVal = 1;\r\n\r\n  UInt64 size = (UInt64)numCycles * totalSize;\r\n  speed = MyMultDiv64(size, timeVal, GetFreq());\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LZMABENCH_H\r\n#define __LZMABENCH_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\n\r\nstruct CBenchInfo\r\n{\r\n  UInt64 GlobalTime;\r\n  UInt64 GlobalFreq;\r\n  UInt64 UserTime;\r\n  UInt64 UserFreq;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt32 NumIterations;\r\n  CBenchInfo(): NumIterations(0) {}\r\n};\r\n\r\nstruct IBenchCallback\r\n{\r\n  virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;\r\n  virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;\r\n};\r\n\r\nUInt64 GetUsage(const CBenchInfo &benchOnfo);\r\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);\r\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);\r\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);\r\n\r\nHRESULT LzmaBench(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);\r\n\r\nconst int kBenchMinDicLogSize = 18;\r\n\r\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);\r\n\r\nbool CrcInternalTest();\r\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp",
    "content": "// LzmaBenchCon.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaBenchCon.h\"\r\n#include \"../../../Common/IntToString.h\"\r\n\r\n#if defined(BENCH_MT) || defined(_WIN32)\r\n#include \"../../../Windows/System.h\"\r\n#endif\r\n\r\n#ifdef BREAK_HANDLER\r\n#include \"../../UI/Console/ConsoleClose.h\"\r\n#endif\r\n#include \"../../../Common/MyCom.h\"\r\n\r\nstruct CTotalBenchRes\r\n{\r\n  UInt64 NumIterations;\r\n  UInt64 Rating;\r\n  UInt64 Usage;\r\n  UInt64 RPU;\r\n  void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }\r\n  void Normalize()\r\n  {\r\n    if (NumIterations == 0)\r\n      return;\r\n    Rating /= NumIterations;\r\n    Usage /= NumIterations;\r\n    RPU /= NumIterations;\r\n    NumIterations = 1;\r\n  }\r\n  void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)\r\n  {\r\n    Rating = (r1.Rating + r2.Rating) / 2;\r\n    Usage = (r1.Usage + r2.Usage) / 2;\r\n    RPU = (r1.RPU + r2.RPU) / 2;\r\n    NumIterations = (r1.NumIterations + r2.NumIterations) / 2;\r\n  }\r\n};\r\n\r\nstruct CBenchCallback: public IBenchCallback\r\n{\r\n  CTotalBenchRes EncodeRes;\r\n  CTotalBenchRes DecodeRes;\r\n  FILE *f;\r\n  void Init() { EncodeRes.Init(); DecodeRes.Init(); }\r\n  void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }\r\n  UInt32 dictionarySize;\r\n  HRESULT SetEncodeResult(const CBenchInfo &info, bool final);\r\n  HRESULT SetDecodeResult(const CBenchInfo &info, bool final);\r\n};\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  while (v1 > 1000000)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\r\n{\r\n  UInt64 elTime = elapsedTime;\r\n  NormalizeVals(freq, elTime);\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic void PrintNumber(FILE *f, UInt64 value, int size)\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(value, s);\r\n  fprintf(f, \" \");\r\n  for (int len = (int)strlen(s); len < size; len++)\r\n    fprintf(f, \" \");\r\n  fprintf(f, \"%s\", s);\r\n}\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  PrintNumber(f, rating / 1000000, 6);\r\n}\r\n\r\nstatic void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)\r\n{\r\n  PrintNumber(f, (usage + 5000) / 10000, 5);\r\n  PrintRating(f, rpu);\r\n  PrintRating(f, rating);\r\n}\r\n\r\n\r\nstatic void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)\r\n{\r\n  UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);\r\n  PrintNumber(f, speed / 1024, 7);\r\n  UInt64 usage = GetUsage(info);\r\n  UInt64 rpu = GetRatingPerUsage(info, rating);\r\n  PrintResults(f, usage, rpu, rating);\r\n  res.NumIterations++;\r\n  res.RPU += rpu;\r\n  res.Rating += rating;\r\n  res.Usage += usage;\r\n}\r\n\r\nstatic void PrintTotals(FILE *f, const CTotalBenchRes &res)\r\n{\r\n  fprintf(f, \"       \");\r\n  PrintResults(f, res.Usage, res.RPU, res.Rating);\r\n}\r\n\r\n\r\nHRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);\r\n    PrintResults(f, info, rating, EncodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const char *kSep = \"  | \";\r\n\r\n\r\nHRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)\r\n{\r\n  #ifdef BREAK_HANDLER\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  #endif\r\n  if (final)\r\n  {\r\n    UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);\r\n    fprintf(f, kSep);\r\n    CBenchInfo info2 = info;\r\n    info2.UnpackSize *= info2.NumIterations;\r\n    info2.PackSize *= info2.NumIterations;\r\n    info2.NumIterations = 1;\r\n    PrintResults(f, info2, rating, DecodeRes);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)\r\n{\r\n  fprintf(f, \"\\nRAM %s \", sizeString);\r\n  PrintNumber(f, (size >> 20), 5);\r\n  fprintf(f, \" MB,  # %s %3d\", threadsString, (unsigned int)numThreads);\r\n}\r\n\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();  //\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  if (numThreads > 1)\r\n    numThreads &= ~1;\r\n  if (dictionary == (UInt32)-1)\r\n  {\r\n    int dicSizeLog;\r\n    for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)\r\n      if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)\r\n        break;\r\n    dictionary = (1 << dicSizeLog);\r\n  }\r\n  #else\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 22);\r\n  numThreads = 1;\r\n  #endif\r\n\r\n  PrintRequirements(f, \"usage:\", GetBenchMemoryUsage(numThreads, dictionary), \"Benchmark threads:   \", numThreads);\r\n\r\n  CBenchCallback callback;\r\n  callback.Init();\r\n  callback.f = f;\r\n  \r\n  fprintf(f, \"\\n\\nDict        Compressing          |        Decompressing\\n   \");\r\n  int j;\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"   Speed Usage    R/U Rating\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n   \");\r\n  for (j = 0; j < 2; j++)\r\n  {\r\n    fprintf(f, \"    KB/s     %%   MIPS   MIPS\");\r\n    if (j == 0)\r\n      fprintf(f, kSep);\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    const int kStartDicLog = 22;\r\n    int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;\r\n    while (((UInt32)1 << pow) > dictionary)\r\n      pow--;\r\n    for (; ((UInt32)1 << pow) <= dictionary; pow++)\r\n    {\r\n      fprintf(f, \"%2d:\", pow);\r\n      callback.dictionarySize = (UInt32)1 << pow;\r\n      HRESULT res = LzmaBench(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        numThreads, callback.dictionarySize, &callback);\r\n      fprintf(f, \"\\n\");\r\n      RINOK(res);\r\n    }\r\n  }\r\n  callback.Normalize();\r\n  fprintf(f, \"----------------------------------------------------------------\\nAvr:\");\r\n  PrintTotals(f, callback.EncodeRes);\r\n  fprintf(f, \"     \");\r\n  PrintTotals(f, callback.DecodeRes);\r\n  fprintf(f, \"\\nTot:\");\r\n  CTotalBenchRes midRes;\r\n  midRes.SetMid(callback.EncodeRes, callback.DecodeRes);\r\n  PrintTotals(f, midRes);\r\n  fprintf(f, \"\\n\");\r\n  return S_OK;\r\n}\r\n\r\nstruct CTempValues\r\n{\r\n  UInt64 *Values;\r\n  CTempValues(UInt32 num) { Values = new UInt64[num]; }\r\n  ~CTempValues() { delete []Values; }\r\n};\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\r\n{\r\n  if (!CrcInternalTest())\r\n    return S_FALSE;\r\n\r\n  #ifdef BENCH_MT\r\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();\r\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\r\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\r\n  if (numThreads == (UInt32)-1)\r\n    numThreads = numCPUs;\r\n  #else\r\n  numThreads = 1;\r\n  #endif\r\n  if (dictionary == (UInt32)-1)\r\n    dictionary = (1 << 24);\r\n\r\n  CTempValues speedTotals(numThreads);\r\n  fprintf(f, \"\\n\\nSize\");\r\n  for (UInt32 ti = 0; ti < numThreads; ti++)\r\n  {\r\n    fprintf(f, \" %5d\", ti + 1);\r\n    speedTotals.Values[ti] = 0;\r\n  }\r\n  fprintf(f, \"\\n\\n\");\r\n\r\n  UInt64 numSteps = 0;\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    for (int pow = 10; pow < 32; pow++)\r\n    {\r\n      UInt32 bufSize = (UInt32)1 << pow;\r\n      if (bufSize > dictionary)\r\n        break;\r\n      fprintf(f, \"%2d: \", pow);\r\n      UInt64 speed;\r\n      for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      {\r\n        #ifdef BREAK_HANDLER\r\n        if (NConsoleClose::TestBreakSignal())\r\n          return E_ABORT;\r\n        #endif\r\n        RINOK(CrcBench(ti + 1, bufSize, speed));\r\n        PrintNumber(f, (speed >> 20), 5);\r\n        speedTotals.Values[ti] += speed;\r\n      }\r\n      fprintf(f, \"\\n\");\r\n      numSteps++;\r\n    }\r\n  }\r\n  if (numSteps != 0)\r\n  {\r\n    fprintf(f, \"\\nAvg:\");\r\n    for (UInt32 ti = 0; ti < numThreads; ti++)\r\n      PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);\r\n    fprintf(f, \"\\n\");\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h",
    "content": "// LzmaBenchCon.h\r\n\r\n#ifndef __LZMABENCHCON_H\r\n#define __LZMABENCHCON_H\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n#ifdef EXTERNAL_LZMA\r\n#include \"../../UI/Common/LoadCodecs.h\"\r\n#endif\r\nHRESULT LzmaBenchCon(\r\n  #ifdef EXTERNAL_LZMA\r\n  CCodecs *codecs,\r\n  #endif\r\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nLIBS = $(LIBS) user32.lib\r\nCFLAGS = $(CFLAGS) \\\r\n  -DCOMPRESS_MF_MT \\\r\n  -DBENCH_MT \\\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LzmaDecoder.obj \\\r\n  $O\\LzmaEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj\r\n\r\nWIN_OBJS = \\\r\n  $O\\System.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Bra86.obj \\\r\n  $O\\LzFind.obj \\\r\n  $O\\LzFindMt.obj \\\r\n  $O\\LzmaDec.obj \\\r\n  $O\\LzmaEnc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\nC_LZMAUTIL_OBJS = \\\r\n  $O\\Lzma86Dec.obj \\\r\n  $O\\Lzma86Enc.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(C_LZMAUTIL_OBJS) \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n$(C_LZMAUTIL_OBJS): ../../../../C/LzmaUtil/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c\r\n\r\nifdef SystemDrive\r\nIS_MINGW = 1\r\nendif\r\n\r\nifdef IS_MINGW\r\nFILE_IO =FileIO\r\nFILE_IO_2 =Windows/$(FILE_IO)\r\nLIB2 = -luuid\r\nelse\r\nFILE_IO =C_FileIO\r\nFILE_IO_2 =Common/$(FILE_IO)\r\nendif\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaBenchCon.o \\\r\n  LzmaDecoder.o \\\r\n  LzmaEncoder.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  $(FILE_IO).o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  IntToString.o \\\r\n  MyString.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  MyVector.o \\\r\n  7zCrc.o \\\r\n  Alloc.o \\\r\n  Bra86.o \\\r\n  LzFind.o \\\r\n  LzmaDec.o \\\r\n  LzmaEnc.o \\\r\n  Lzma86Dec.o \\\r\n  Lzma86Enc.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaBenchCon.o: LzmaBenchCon.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBenchCon.cpp\r\n\r\nLzmaDecoder.o: ../LzmaDecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LzmaDecoder.cpp\r\n\r\nLzmaEncoder.o: ../LzmaEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LzmaEncoder.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\n$(FILE_IO).o: ../../../$(FILE_IO_2).cpp\r\n\t$(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp\r\n\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nIntToString.o: ../../../Common/IntToString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp\r\n\r\nMyString.o: ../../../Common/MyString.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyString.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nMyVector.o: ../../../Common/MyVector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyVector.cpp\r\n\r\n7zCrc.o: ../../../../C/7zCrc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c\r\n\r\nAlloc.o: ../../../../C/Alloc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c\r\n\r\nBra86.o: ../../../../C/Bra86.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/Bra86.c\r\n\r\nLzFind.o: ../../../../C/LzFind.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzFind.c\r\n\r\nLzmaDec.o: ../../../../C/LzmaDec.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaDec.c\r\n\r\nLzmaEnc.o: ../../../../C/LzmaEnc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaEnc.c\r\n\r\nLzma86Dec.o: ../../../../C/LzmaUtil/Lzma86Dec.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Dec.c\r\n\r\nLzma86Enc.o: ../../../../C/LzmaUtil/Lzma86Enc.c\r\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LzmaDecoder.cpp",
    "content": "// LzmaDecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"LzmaDecoder.h\"\r\n\r\nstatic HRESULT SResToHRESULT(SRes res)\r\n{\r\n  switch(res)\r\n  {\r\n    case SZ_OK: return S_OK;\r\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\r\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\r\n    case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;\r\n    // case SZ_ERROR_PROGRESS: return E_ABORT;\r\n    case SZ_ERROR_DATA: return S_FALSE;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstatic const UInt32 kInBufSize = 1 << 20;\r\n\r\nCDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false), FinishStream(false)\r\n{\r\n  LzmaDec_Construct(&_state);\r\n}\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCDecoder::~CDecoder()\r\n{\r\n  LzmaDec_Free(&_state, &g_Alloc);\r\n  MyFree(_inBuf);\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)\r\n{\r\n  RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc)));\r\n\r\n  if (_inBuf == 0)\r\n  {\r\n    _inBuf = (Byte *)MyAlloc(kInBufSize);\r\n    if (_inBuf == 0)\r\n      return E_OUTOFMEMORY;\r\n  }\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) { *value = _inSizeProcessed; return S_OK; }\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; }\r\nSTDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; }\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  _outSizeDefined = (outSize != NULL);\r\n  if (_outSizeDefined)\r\n    _outSize = *outSize;\r\n\r\n  LzmaDec_Init(&_state);\r\n  \r\n  _inPos = _inSize = 0;\r\n  _inSizeProcessed = _outSizeProcessed = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)\r\n{\r\n  if (_inBuf == 0)\r\n    return S_FALSE;\r\n  SetOutStreamSize(outSize);\r\n\r\n  for (;;)\r\n  {\r\n    if (_inPos == _inSize)\r\n    {\r\n      _inPos = _inSize = 0;\r\n      RINOK(inStream->Read(_inBuf, kInBufSize, &_inSize));\r\n    }\r\n\r\n    SizeT dicPos = _state.dicPos;\r\n    SizeT curSize = _state.dicBufSize - dicPos;\r\n    const UInt32 kStepSize = ((UInt32)1 << 22);\r\n    if (curSize > kStepSize)\r\n      curSize = (SizeT)kStepSize;\r\n    \r\n    ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\r\n    if (_outSizeDefined)\r\n    {\r\n      const UInt64 rem = _outSize - _outSizeProcessed;\r\n      if (rem < curSize)\r\n      {\r\n        curSize = (SizeT)rem;\r\n        if (FinishStream)\r\n          finishMode = LZMA_FINISH_END;\r\n      }\r\n    }\r\n\r\n    SizeT inSizeProcessed = _inSize - _inPos;\r\n    ELzmaStatus status;\r\n    SRes res = LzmaDec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status);\r\n\r\n    _inPos += (UInt32)inSizeProcessed;\r\n    _inSizeProcessed += inSizeProcessed;\r\n    SizeT outSizeProcessed = _state.dicPos - dicPos;\r\n    _outSizeProcessed += outSizeProcessed;\r\n\r\n    bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0);\r\n    bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize);\r\n\r\n    if (res != 0 || _state.dicPos == _state.dicBufSize || finished || stopDecoding)\r\n    {\r\n      HRESULT res2 = WriteStream(outStream, _state.dic, _state.dicPos);\r\n      if (res != 0)\r\n        return S_FALSE;\r\n      RINOK(res2);\r\n      if (stopDecoding)\r\n        return S_OK;\r\n      if (finished)\r\n        return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE);\r\n    }\r\n    if (_state.dicPos == _state.dicBufSize)\r\n      _state.dicPos = 0;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed));\r\n    }\r\n  }\r\n}\r\n\r\n#ifndef NO_READ_FROM_CODER\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  do\r\n  {\r\n    if (_inPos == _inSize)\r\n    {\r\n      _inPos = _inSize = 0;\r\n      RINOK(_inStream->Read(_inBuf, kInBufSize, &_inSize));\r\n    }\r\n    {\r\n      SizeT inProcessed = _inSize - _inPos;\r\n\r\n      if (_outSizeDefined)\r\n      {\r\n        const UInt64 rem = _outSize - _outSizeProcessed;\r\n        if (rem < size)\r\n          size = (UInt32)rem;\r\n      }\r\n\r\n      SizeT outProcessed = size;\r\n      ELzmaStatus status;\r\n      SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,\r\n          _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);\r\n      _inPos += (UInt32)inProcessed;\r\n      _inSizeProcessed += inProcessed;\r\n      _outSizeProcessed += outProcessed;\r\n      size -= (UInt32)outProcessed;\r\n      data = (Byte *)data + outProcessed;\r\n      if (processedSize)\r\n        *processedSize += (UInt32)outProcessed;\r\n      RINOK(SResToHRESULT(res));\r\n      if (inProcessed == 0 && outProcessed == 0)\r\n        return S_OK;\r\n    }\r\n  }\r\n  while (size != 0);\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LzmaDecoder.h",
    "content": "// LzmaDecoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/LzmaDec.h\"\r\n}\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nclass CDecoder:\r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  public ICompressGetInStreamProcessedSize,\r\n  #ifndef NO_READ_FROM_CODER\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CMyComPtr<ISequentialInStream> _inStream;\r\n  Byte *_inBuf;\r\n  UInt32 _inPos;\r\n  UInt32 _inSize;\r\n  CLzmaDec _state;\r\n  bool _outSizeDefined;\r\n  UInt64 _outSize;\r\n  UInt64 _inSizeProcessed;\r\n  UInt64 _outSizeProcessed;\r\npublic:\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  MY_UNKNOWN_IMP5(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize,\r\n      ICompressSetInStream,\r\n      ICompressSetOutStreamSize,\r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      ICompressSetDecoderProperties2,\r\n      ICompressGetInStreamProcessedSize)\r\n  #endif\r\n\r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifndef NO_READ_FROM_CODER\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  bool FinishStream;\r\n\r\n  CDecoder();\r\n  virtual ~CDecoder();\r\n\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LzmaEncoder.cpp",
    "content": "// LzmaEncoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/Alloc.h\"\r\n}\r\n\r\n#include \"../Common/StreamUtils.h\"\r\n\r\n#include \"LzmaEncoder.h\"\r\n\r\nstatic HRESULT SResToHRESULT(SRes res)\r\n{\r\n  switch(res)\r\n  {\r\n    case SZ_OK: return S_OK;\r\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\r\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\r\n    // case SZ_ERROR_THREAD: return E_FAIL;\r\n  }\r\n  return E_FAIL;\r\n}\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstatic const UInt32 kStreamStepSize = (UInt32)1 << 31;\r\n\r\nstatic SRes MyRead(void *object, void *data, size_t *size)\r\n{\r\n  UInt32 curSize = ((*size < kStreamStepSize) ? (UInt32)*size : kStreamStepSize);\r\n  HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize);\r\n  *size = curSize;\r\n  return (SRes)res;\r\n}\r\n\r\nstatic size_t MyWrite(void *object, const void *data, size_t size)\r\n{\r\n  CSeqOutStream *p = (CSeqOutStream *)object;\r\n  p->Res = WriteStream(p->RealStream, data, size);\r\n  if (p->Res != 0)\r\n    return 0;\r\n  return size;\r\n}\r\n\r\nstatic void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }\r\nstatic void SzBigFree(void *, void *address) { BigFree(address); }\r\nstatic ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };\r\n\r\nstatic void *SzAlloc(void *, size_t size) { return MyAlloc(size); }\r\nstatic void SzFree(void *, void *address) { MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\nCEncoder::CEncoder()\r\n{\r\n  _seqInStream.SeqInStream.Read = MyRead;\r\n  _seqOutStream.SeqOutStream.Write = MyWrite;\r\n  _encoder = 0;\r\n  _encoder = LzmaEnc_Create(&g_Alloc);\r\n  if (_encoder == 0)\r\n    throw 1;\r\n}\r\n\r\nCEncoder::~CEncoder()\r\n{\r\n  if (_encoder != 0)\r\n    LzmaEnc_Destroy(_encoder, &g_Alloc, &g_BigAlloc);\r\n}\r\n\r\ninline wchar_t GetUpperChar(wchar_t c)\r\n{\r\n  if (c >= 'a' && c <= 'z')\r\n    c -= 0x20;\r\n  return c;\r\n}\r\n\r\nstatic int ParseMatchFinder(const wchar_t *s, int *btMode, int *numHashBytes)\r\n{\r\n  wchar_t c = GetUpperChar(*s++);\r\n  if (c == L'H')\r\n  {\r\n    if (GetUpperChar(*s++) != L'C')\r\n      return 0;\r\n    int numHashBytesLoc = (int)(*s++ - L'0');\r\n    if (numHashBytesLoc < 4 || numHashBytesLoc > 4)\r\n      return 0;\r\n    if (*s++ != 0)\r\n      return 0;\r\n    *btMode = 0;\r\n    *numHashBytes = numHashBytesLoc;\r\n    return 1;\r\n  }\r\n  if (c != L'B')\r\n    return 0;\r\n\r\n  if (GetUpperChar(*s++) != L'T')\r\n    return 0;\r\n  int numHashBytesLoc = (int)(*s++ - L'0');\r\n  if (numHashBytesLoc < 2 || numHashBytesLoc > 4)\r\n    return 0;\r\n  c = GetUpperChar(*s++);\r\n  if (c != L'\\0')\r\n    return 0;\r\n  *btMode = 1;\r\n  *numHashBytes = numHashBytesLoc;\r\n  return 1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,\r\n    const PROPVARIANT *coderProps, UInt32 numProps)\r\n{\r\n  CLzmaEncProps props;\r\n  LzmaEncProps_Init(&props);\r\n\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    const PROPVARIANT &prop = coderProps[i];\r\n    switch (propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.fb = prop.ulVal; break;\r\n      case NCoderPropID::kMatchFinderCycles:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.mc = prop.ulVal; break;\r\n      case NCoderPropID::kAlgorithm:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.algo = prop.ulVal; break;\r\n      case NCoderPropID::kDictionarySize:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.dictSize = prop.ulVal; break;\r\n      case NCoderPropID::kPosStateBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.pb = prop.ulVal; break;\r\n      case NCoderPropID::kLitPosBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lp = prop.ulVal; break;\r\n      case NCoderPropID::kLitContextBits:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lc = prop.ulVal; break;\r\n      case NCoderPropID::kNumThreads:\r\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.numThreads = prop.ulVal; break;\r\n      case NCoderPropID::kMultiThread:\r\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.numThreads = ((prop.boolVal == VARIANT_TRUE) ? 2 : 1); break;\r\n      case NCoderPropID::kEndMarker:\r\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.writeEndMark = (prop.boolVal == VARIANT_TRUE); break;\r\n      case NCoderPropID::kMatchFinder:\r\n        if (prop.vt != VT_BSTR) return E_INVALIDARG;\r\n        if (!ParseMatchFinder(prop.bstrVal, &props.btMode, &props.numHashBytes /* , &_matchFinderBase.skipModeBits */))\r\n          return E_INVALIDARG; break;\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return SResToHRESULT(LzmaEnc_SetProps(_encoder, &props));\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{\r\n  Byte props[LZMA_PROPS_SIZE];\r\n  size_t size = LZMA_PROPS_SIZE;\r\n  RINOK(LzmaEnc_WriteProperties(_encoder, props, &size));\r\n  return WriteStream(outStream, props, size);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _seqOutStream.RealStream = outStream;\r\n  _seqOutStream.Res = S_OK;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _seqOutStream.RealStream.Release();\r\n  return S_OK;\r\n}\r\n\r\ntypedef struct _CCompressProgressImp\r\n{\r\n  ICompressProgress p;\r\n  ICompressProgressInfo *Progress;\r\n  HRESULT Res;\r\n} CCompressProgressImp;\r\n\r\n#define PROGRESS_UNKNOWN_VALUE ((UInt64)(Int64)-1)\r\n\r\n#define CONVERT_PR_VAL(x) (x == PROGRESS_UNKNOWN_VALUE ? NULL : &x)\r\n\r\nSRes CompressProgress(void *pp, UInt64 inSize, UInt64 outSize)\r\n{\r\n  CCompressProgressImp *p = (CCompressProgressImp *)pp;\r\n  p->Res = p->Progress->SetRatioInfo(CONVERT_PR_VAL(inSize), CONVERT_PR_VAL(outSize));\r\n  return (SRes)p->Res;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n    const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)\r\n{\r\n  CCompressProgressImp progressImp;\r\n  progressImp.p.Progress = CompressProgress;\r\n  progressImp.Progress = progress;\r\n  progressImp.Res = SZ_OK;\r\n\r\n  _seqInStream.RealStream = inStream;\r\n  SetOutStream(outStream);\r\n  SRes res = LzmaEnc_Encode(_encoder, &_seqOutStream.SeqOutStream, &_seqInStream.SeqInStream, progress ? &progressImp.p : NULL, &g_Alloc, &g_BigAlloc);\r\n  ReleaseOutStream();\r\n  if (res == SZ_ERROR_WRITE && _seqOutStream.Res != S_OK)\r\n    return _seqOutStream.Res;\r\n  if (res == SZ_ERROR_PROGRESS && progressImp.Res != S_OK)\r\n    return progressImp.Res;\r\n  return SResToHRESULT(res);\r\n}\r\n  \r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LzmaEncoder.h",
    "content": "// LzmaEncoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../../C/LzmaEnc.h\"\r\n}\r\n\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#include \"../ICoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLzma {\r\n\r\nstruct CSeqInStream\r\n{\r\n  ISeqInStream SeqInStream;\r\n  ISequentialInStream *RealStream;\r\n};\r\n\r\nstruct CSeqOutStream\r\n{\r\n  ISeqOutStream SeqOutStream;\r\n  CMyComPtr<ISequentialOutStream> RealStream;\r\n  HRESULT Res;\r\n};\r\n\r\nclass CEncoder :\r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CMyUnknownImp\r\n{\r\n  CLzmaEncHandle _encoder;\r\n \r\n  CSeqInStream _seqInStream;\r\n  CSeqOutStream _seqOutStream;\r\n\r\npublic:\r\n  CEncoder();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder();\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/LzmaRegister.cpp",
    "content": "// LzmaRegister.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../Common/RegisterCodec.h\"\r\n\r\n#include \"LzmaDecoder.h\"\r\n\r\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CDecoder); }\r\n#ifndef EXTRACT_ONLY\r\n#include \"LzmaEncoder.h\"\r\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CEncoder);  }\r\n#else\r\n#define CreateCodecOut 0\r\n#endif\r\n\r\nstatic CCodecInfo g_CodecInfo =\r\n  { CreateCodec, CreateCodecOut, 0x030101, L\"LZMA\", 1, false };\r\n\r\nREGISTER_CODEC(LZMA)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/RangeCoder.h",
    "content": "// Compress/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGE_CODER_H\r\n#define __COMPRESS_RANGE_CODER_H\r\n\r\n#include \"../Common/InBuffer.h\"\r\n#include \"../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1;\r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)\r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);\r\n    }\r\n    _cacheSize++;\r\n    Low = (UInt32)Low << 8;\r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numBits)\r\n  {\r\n    for (numBits--; numBits >= 0; numBits--)\r\n    {\r\n      Range >>= 1;\r\n      Low += Range & (0 - ((value >> numBits) & 1));\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;\r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8;\r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/RangeCoderBit.h",
    "content": "// Compress/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGE_CODER_BIT_H\r\n#define __COMPRESS_RANGE_CODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 4;\r\n\r\nconst int kNumBitPriceShiftBits = 4;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nextern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/Compress/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize,\r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kBlockSize,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kMatchFinderCycles,\r\n    kNumPasses = 0x460,\r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kNumThreads,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetCoderMt, 0x25)\r\n{\r\n  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block\r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICompressCodecsInfo, 0x60)\r\n{\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;\r\n};\r\nCODER_INTERFACE(ISetCompressCodecsInfo, 0x61)\r\n{\r\n  STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICryptoResetSalt, 0x88)\r\n{\r\n  STDMETHOD(ResetSalt)() PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICryptoResetInitVector, 0x8C)\r\n{\r\n  STDMETHOD(ResetInitVector)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription,\r\n    kDecoderIsAssigned,\r\n    kEncoderIsAssigned\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/IDecl.h",
    "content": "// IDecl.h\r\n\r\n#ifndef __IDECL_H\r\n#define __IDECL_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n\r\n#define DECL_INTERFACE_SUB(i, base, groupId, subId) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \\\r\nstruct i: public base\r\n\r\n#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/IPassword.h",
    "content": "// IPassword.h\r\n\r\n#ifndef __IPASSWORD_H\r\n#define __IPASSWORD_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;\r\n};\r\n\r\nPASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)\r\n{\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;\r\n};\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/IProgress.h",
    "content": "// Interface/IProgress.h\r\n\r\n#ifndef __IPROGRESS_H\r\n#define __IPROGRESS_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define INTERFACE_IProgress(x) \\\r\n  STDMETHOD(SetTotal)(UInt64 total) x; \\\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) x; \\\r\n\r\nDECL_INTERFACE(IProgress, 0, 5)\r\n{\r\n  INTERFACE_IProgress(PURE)\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000000050002}\r\nDEFINE_GUID(IID_IProgress2,\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000050002\")\r\nIProgress2: public IUnknown\r\n{\r\npublic:\r\n  STDMETHOD(SetTotal)(const UInt64 *total) PURE;\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n#include \"IDecl.h\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream,\r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/MyVersion.h",
    "content": "#define MY_VER_MAJOR 4\r\n#define MY_VER_MINOR 65\r\n#define MY_VER_BUILD 0\r\n#define MY_VERSION \"4.65\"\r\n#define MY_7ZIP_VERSION \"7-Zip 4.65\"\r\n#define MY_DATE \"2009-02-03\"\r\n#define MY_COPYRIGHT \"Copyright (c) 1999-2009 Igor Pavlov\"\r\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \"  \" MY_COPYRIGHT \"  \" MY_DATE\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/MyVersionInfo.rc",
    "content": "#include <WinVer.h>\r\n#include \"MyVersion.h\"\r\n\r\n#define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0\r\n\r\n#ifdef DEBUG\r\n#define DBG_FL VS_FF_DEBUG\r\n#else\r\n#define DBG_FL 0\r\n#endif\r\n\r\n#define MY_VERSION_INFO(fileType, descr, intName, origName)  \\\r\nLANGUAGE 9, 1 \\\r\n1 VERSIONINFO \\\r\n  FILEVERSION MY_VER \\\r\n  PRODUCTVERSION MY_VER \\\r\n  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK \\\r\n  FILEFLAGS DBG_FL \\\r\n  FILEOS VOS_NT_WINDOWS32 \\\r\n  FILETYPE fileType \\\r\n  FILESUBTYPE 0x0L \\\r\nBEGIN \\\r\n    BLOCK \"StringFileInfo\" \\\r\n    BEGIN  \\\r\n        BLOCK \"040904b0\" \\\r\n        BEGIN \\\r\n            VALUE \"CompanyName\", \"Igor Pavlov\" \\\r\n            VALUE \"FileDescription\", descr \\\r\n            VALUE \"FileVersion\", MY_VERSION  \\\r\n            VALUE \"InternalName\", intName \\\r\n            VALUE \"LegalCopyright\", MY_COPYRIGHT \\\r\n            VALUE \"OriginalFilename\", origName \\\r\n            VALUE \"ProductName\", \"7-Zip\" \\\r\n            VALUE \"ProductVersion\", MY_VERSION \\\r\n        END \\\r\n    END \\\r\n    BLOCK \"VarFileInfo\" \\\r\n    BEGIN \\\r\n        VALUE \"Translation\", 0x409, 1200 \\\r\n    END \\\r\nEND\r\n\r\n#define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(VFT_APP, descr, intName, intName \".exe\")\r\n\r\n#define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(VFT_DLL, descr, intName, intName \".dll\")\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/PropID.h",
    "content": "// PropID.h\r\n\r\n#ifndef __7ZIP_PROPID_H\r\n#define __7ZIP_PROPID_H\r\n\r\nenum\r\n{\r\n  kpidNoProperty = 0,\r\n  \r\n  kpidHandlerItemIndex = 2,\r\n  kpidPath,\r\n  kpidName,\r\n  kpidExtension,\r\n  kpidIsDir,\r\n  kpidSize,\r\n  kpidPackSize,\r\n  kpidAttrib,\r\n  kpidCTime,\r\n  kpidATime,\r\n  kpidMTime,\r\n  kpidSolid,\r\n  kpidCommented,\r\n  kpidEncrypted,\r\n  kpidSplitBefore,\r\n  kpidSplitAfter,\r\n  kpidDictionarySize,\r\n  kpidCRC,\r\n  kpidType,\r\n  kpidIsAnti,\r\n  kpidMethod,\r\n  kpidHostOS,\r\n  kpidFileSystem,\r\n  kpidUser,\r\n  kpidGroup,\r\n  kpidBlock,\r\n  kpidComment,\r\n  kpidPosition,\r\n  kpidPrefix,\r\n  kpidNumSubDirs,\r\n  kpidNumSubFiles,\r\n  kpidUnpackVer,\r\n  kpidVolume,\r\n  kpidIsVolume,\r\n  kpidOffset,\r\n  kpidLinks,\r\n  kpidNumBlocks,\r\n  kpidNumVolumes,\r\n  kpidTimeType,\r\n  kpidBit64,\r\n  kpidBigEndian,\r\n  kpidCpu,\r\n  kpidPhySize,\r\n  kpidHeadersSize,\r\n  kpidChecksum,\r\n  kpidCharacts,\r\n  kpidVa,\r\n\r\n  kpidTotalSize = 0x1100,\r\n  kpidFreeSpace,\r\n  kpidClusterSize,\r\n  kpidVolumeName,\r\n\r\n  kpidLocalName = 0x1200,\r\n  kpidProvider,\r\n\r\n  kpidUserDefined = 0x10000\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Client7z/Client7z.cpp",
    "content": "// Client7z.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyInitGuid.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/DLL.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../MyVersion.h\"\r\n\r\n// use another CLSIDs, if you want to support other formats (zip, rar, ...).\r\n// {23170F69-40C1-278A-1000-000110070000}\r\nDEFINE_GUID(CLSID_CFormat7z,\r\n  0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);\r\n\r\nusing namespace NWindows;\r\n\r\n#define kDllName \"7z.dll\"\r\n\r\nstatic const char *kCopyrightString = MY_7ZIP_VERSION\r\n\" (\"  kDllName \" client) \"\r\nMY_COPYRIGHT \" \" MY_DATE;\r\n\r\nstatic const char *kHelpString =\r\n\"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\\n\"\r\n\"Examples:\\n\"\r\n\"  Client7z.exe a archive.7z f1.txt f2.txt  : compress two files to archive.7z\\n\"\r\n\"  Client7z.exe l archive.7z   : List contents of archive.7z\\n\"\r\n\"  Client7z.exe x archive.7z   : eXtract files from archive.7z\\n\";\r\n\r\n\r\ntypedef UINT32 (WINAPI * CreateObjectFunc)(\r\n    const GUID *clsID,\r\n    const GUID *interfaceID,\r\n    void **outObject);\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nvoid PrintString(const UString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)GetOemString(s));\r\n}\r\n\r\nvoid PrintString(const AString &s)\r\n{\r\n  printf(\"%s\", (LPCSTR)s);\r\n}\r\n\r\nvoid PrintNewLine()\r\n{\r\n  PrintString(\"\\n\");\r\n}\r\n\r\nvoid PrintStringLn(const AString &s)\r\n{\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nvoid PrintError(const AString &s)\r\n{\r\n  PrintNewLine();\r\n  PrintString(s);\r\n  PrintNewLine();\r\n}\r\n\r\nstatic HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\r\n}\r\n\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Open callback class\r\n\r\n\r\nclass CArchiveOpenCallback:\r\n  public IArchiveOpenCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\r\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\r\n\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveOpenCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)\r\n{\r\n  return S_OK;\r\n}\r\n  \r\nSTDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream);\r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Extracting callback class\r\n\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\nstatic const char *kTestingString    =  \"Testing     \";\r\nstatic const char *kExtractingString =  \"Extracting  \";\r\nstatic const char *kSkippingString   =  \"Skipping    \";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCRCFailed = \"CRC Failed\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nclass CArchiveExtractCallback:\r\n  public IArchiveExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IArchiveExtractCallback\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\r\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\r\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  UString _directoryPath;  // Output directory\r\n  UString _filePath;       // name inside arcvhive\r\n  UString _diskFilePath;   // full path to file on disk\r\n  bool _extractMode;\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME MTime;\r\n    UInt32 Attrib;\r\n    bool isDir;\r\n    bool AttribDefined;\r\n    bool MTimeDefined;\r\n  } _processedFileInfo;\r\n\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n\r\npublic:\r\n  void Init(IInArchive *archiveHandler, const UString &directoryPath);\r\n\r\n  UInt64 NumErrors;\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  CArchiveExtractCallback() : PasswordIsDefined(false) {}\r\n};\r\n\r\nvoid CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)\r\n{\r\n  NumErrors = 0;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,\r\n    ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  {\r\n    // Get Name\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));\r\n    \r\n    UString fullPath;\r\n    if (prop.vt == VT_EMPTY)\r\n      fullPath = kEmptyFileAlias;\r\n    else\r\n    {\r\n      if (prop.vt != VT_BSTR)\r\n        return E_FAIL;\r\n      fullPath = prop.bstrVal;\r\n    }\r\n    _filePath = fullPath;\r\n  }\r\n\r\n  if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)\r\n    return S_OK;\r\n\r\n  {\r\n    // Get Attrib\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\r\n    if (prop.vt == VT_EMPTY)\r\n    {\r\n      _processedFileInfo.Attrib = 0;\r\n      _processedFileInfo.AttribDefined = false;\r\n    }\r\n    else\r\n    {\r\n      if (prop.vt != VT_UI4)\r\n        return E_FAIL;\r\n      _processedFileInfo.Attrib = prop.ulVal;\r\n      _processedFileInfo.AttribDefined = true;\r\n    }\r\n  }\r\n\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir));\r\n\r\n  {\r\n    // Get Modified Time\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));\r\n    _processedFileInfo.MTimeDefined = false;\r\n    switch(prop.vt)\r\n    {\r\n      case VT_EMPTY:\r\n        // _processedFileInfo.MTime = _utcMTimeDefault;\r\n        break;\r\n      case VT_FILETIME:\r\n        _processedFileInfo.MTime = prop.filetime;\r\n        _processedFileInfo.MTimeDefined = true;\r\n        break;\r\n      default:\r\n        return E_FAIL;\r\n    }\r\n\r\n  }\r\n  {\r\n    // Get Size\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    bool newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    UInt64 newFileSize;\r\n    if (newFileSizeDefined)\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n  }\r\n\r\n  \r\n  {\r\n    // Create folders for file\r\n    int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (slashPos >= 0)\r\n      NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));\r\n  }\r\n\r\n  UString fullProcessedPath = _directoryPath + _filePath;\r\n  _diskFilePath = fullProcessedPath;\r\n\r\n  if (_processedFileInfo.isDir)\r\n  {\r\n    NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (NFile::NFind::FindFile(fullProcessedPath, fi))\r\n    {\r\n      if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n      {\r\n        PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath);\r\n        return E_ABORT;\r\n      }\r\n    }\r\n    \r\n    _outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n    if (!_outFileStreamSpec->Open(fullProcessedPath, CREATE_ALWAYS))\r\n    {\r\n      PrintString((UString)L\"can not open output file \" + fullProcessedPath);\r\n      return E_ABORT;\r\n    }\r\n    _outFileStream = outStreamLoc;\r\n    *outStream = outStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:  _extractMode = true; break;\r\n  };\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:  PrintString(kExtractingString); break;\r\n    case NArchive::NExtract::NAskMode::kTest:  PrintString(kTestingString); break;\r\n    case NArchive::NExtract::NAskMode::kSkip:  PrintString(kSkippingString); break;\r\n  };\r\n  PrintString(_filePath);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumErrors++;\r\n      PrintString(\"     \");\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          PrintString(kUnsupportedMethod);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          PrintString(kCRCFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          PrintString(kDataError);\r\n          break;\r\n        default:\r\n          PrintString(kUnknownError);\r\n      }\r\n    }\r\n  }\r\n\r\n  if (_outFileStream != NULL)\r\n  {\r\n    if (_processedFileInfo.MTimeDefined)\r\n      _outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);\r\n    RINOK(_outFileStreamSpec->Close());\r\n  }\r\n  _outFileStream.Release();\r\n  if (_extractMode && _processedFileInfo.AttribDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);\r\n  PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    // You can ask real password here from user\r\n    // Password = GetPassword(OutStream);\r\n    // PasswordIsDefined = true;\r\n    PrintError(\"Password is not defined\");\r\n    return E_ABORT;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////\r\n// Archive Creating callback class\r\n\r\nstruct CDirItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  UString FullPath;\r\n  UInt32 Attrib;\r\n\r\n  bool isDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CArchiveUpdateCallback:\r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2)\r\n\r\n  // IProgress\r\n  STDMETHOD(SetTotal)(UInt64 size);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IUpdateCallback2\r\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);\r\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,\r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\r\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\r\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  UString DirPrefix;\r\n  const CObjectVector<CDirItem> *DirItems;\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n\r\n  bool m_NeedBeClosed;\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {};\r\n\r\n  ~CArchiveUpdateCallback() { Finilize(); }\r\n  HRESULT Finilize();\r\n\r\n  void Init(const CObjectVector<CDirItem> *dirItems)\r\n  {\r\n    DirItems = dirItems;\r\n    m_NeedBeClosed = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n  }\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)\r\n{\r\n  return E_NOTIMPL;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */,\r\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\r\n{\r\n  if (newData != NULL)\r\n    *newData = BoolToInt(true);\r\n  if (newProperties != NULL)\r\n    *newProperties = BoolToInt(true);\r\n  if (indexInArchive != NULL)\r\n    *indexInArchive = (UInt32)-1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    prop = false;\r\n    prop.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  {\r\n    const CDirItem &dirItem = (*DirItems)[index];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:  prop = dirItem.Name; break;\r\n      case kpidIsDir:  prop = dirItem.isDir(); break;\r\n      case kpidSize:  prop = dirItem.Size; break;\r\n      case kpidAttrib:  prop = dirItem.Attrib; break;\r\n      case kpidCTime:  prop = dirItem.CTime; break;\r\n      case kpidATime:  prop = dirItem.ATime; break;\r\n      case kpidMTime:  prop = dirItem.MTime; break;\r\n    }\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveUpdateCallback::Finilize()\r\n{\r\n  if (m_NeedBeClosed)\r\n  {\r\n    PrintNewLine();\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic void GetStream2(const wchar_t *name)\r\n{\r\n  PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  PrintString(name);\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  RINOK(Finilize());\r\n\r\n  const CDirItem &dirItem = (*DirItems)[index];\r\n  GetStream2(dirItem.Name);\r\n \r\n  if (dirItem.isDir())\r\n    return S_OK;\r\n\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    UString path = DirPrefix + dirItem.FullPath;\r\n    if (!inStreamSpec->Open(path))\r\n    {\r\n      DWORD sysError = ::GetLastError();\r\n      FailedCodes.Add(sysError);\r\n      FailedFiles.Add(path);\r\n      // if (systemError == ERROR_SHARING_VIOLATION)\r\n      {\r\n        PrintNewLine();\r\n        PrintError(\"WARNING: can't open file\");\r\n        // PrintString(NError::MyFormatMessageW(systemError));\r\n        return S_FALSE;\r\n      }\r\n      // return sysError;\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */)\r\n{\r\n  m_NeedBeClosed = true;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if (!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    if (AskPassword)\r\n    {\r\n      // You can ask real password here from user\r\n      // Password = GetPassword(OutStream);\r\n      // PasswordIsDefined = true;\r\n      PrintError(\"Password is not defined\");\r\n      return E_ABORT;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n\r\n\r\n//////////////////////////////////////////////////////////////////////////\r\n// Main function\r\n\r\nint MY_CDECL main(int argc, char* argv[])\r\n{\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  #endif\r\n\r\n  PrintStringLn(kCopyrightString);\r\n\r\n  if (argc < 3)\r\n  {\r\n    PrintStringLn(kHelpString);\r\n    return 1;\r\n  }\r\n  NWindows::NDLL::CLibrary library;\r\n  if (!library.Load(TEXT(kDllName)))\r\n  {\r\n    PrintError(\"Can not load library\");\r\n    return 1;\r\n  }\r\n  CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress(\"CreateObject\");\r\n  if (createObjectFunc == 0)\r\n  {\r\n    PrintError(\"Can not get CreateObject\");\r\n    return 1;\r\n  }\r\n\r\n  AString command = argv[1];\r\n  command.MakeLower();\r\n  UString archiveName = GetUnicodeString(argv[2], CP_OEMCP);\r\n  if (command.Compare(\"a\") == 0)\r\n  {\r\n    // create archive command\r\n    if (argc < 4)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n    CObjectVector<CDirItem> dirItems;\r\n    int i;\r\n    for (i = 3; i < argc; i++)\r\n    {\r\n      CDirItem di;\r\n      UString name = GetUnicodeString(argv[i], CP_OEMCP);\r\n      \r\n      NFile::NFind::CFileInfoW fi;\r\n      if (!NFile::NFind::FindFile(name, fi))\r\n      {\r\n        PrintString(UString(L\"Can't find file\") + name);\r\n        return 1;\r\n      }\r\n\r\n      di.Attrib = fi.Attrib;\r\n      di.Size = fi.Size;\r\n      di.CTime = fi.CTime;\r\n      di.ATime = fi.ATime;\r\n      di.MTime = fi.MTime;\r\n      di.Name = name;\r\n      di.FullPath = name;\r\n      dirItems.Add(di);\r\n    }\r\n    COutFileStream *outFileStreamSpec = new COutFileStream;\r\n    CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;\r\n    if (!outFileStreamSpec->Create(archiveName, false))\r\n    {\r\n      PrintError(\"can't create archive file\");\r\n      return 1;\r\n    }\r\n\r\n    CMyComPtr<IOutArchive> outArchive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n\r\n    CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n    CMyComPtr<IArchiveUpdateCallback2> updateCallback(updateCallbackSpec);\r\n    updateCallbackSpec->Init(&dirItems);\r\n    // updateCallbackSpec->PasswordIsDefined = true;\r\n    // updateCallbackSpec->Password = L\"1\";\r\n\r\n    HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);\r\n    updateCallbackSpec->Finilize();\r\n    if (result != S_OK)\r\n    {\r\n      PrintError(\"Update Error\");\r\n      return 1;\r\n    }\r\n    for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)\r\n    {\r\n      PrintNewLine();\r\n      PrintString((UString)L\"Error for file: \" + updateCallbackSpec->FailedFiles[i]);\r\n    }\r\n    if (updateCallbackSpec->FailedFiles.Size() != 0)\r\n      return 1;\r\n  }\r\n  else\r\n  {\r\n    if (argc != 3)\r\n    {\r\n      PrintStringLn(kHelpString);\r\n      return 1;\r\n    }\r\n\r\n    bool listCommand;\r\n    if (command.Compare(\"l\") == 0)\r\n      listCommand = true;\r\n    else if (command.Compare(\"x\") == 0)\r\n      listCommand = false;\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      return 1;\r\n    }\r\n  \r\n    CMyComPtr<IInArchive> archive;\r\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)\r\n    {\r\n      PrintError(\"Can not get class object\");\r\n      return 1;\r\n    }\r\n    \r\n    CInFileStream *fileSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> file = fileSpec;\r\n    \r\n    if (!fileSpec->Open(archiveName))\r\n    {\r\n      PrintError(\"Can not open archive file\");\r\n      return 1;\r\n    }\r\n\r\n    {\r\n      CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;\r\n      CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);\r\n      openCallbackSpec->PasswordIsDefined = false;\r\n      // openCallbackSpec->PasswordIsDefined = true;\r\n      // openCallbackSpec->Password = L\"1\";\r\n      \r\n      if (archive->Open(file, 0, openCallback) != S_OK)\r\n      {\r\n        PrintError(\"Can not open archive\");\r\n        return 1;\r\n      }\r\n    }\r\n    \r\n    if (listCommand)\r\n    {\r\n      // List command\r\n      UInt32 numItems = 0;\r\n      archive->GetNumberOfItems(&numItems);\r\n      for (UInt32 i = 0; i < numItems; i++)\r\n      {\r\n        {\r\n          // Get uncompressed size of file\r\n          NWindows::NCOM::CPropVariant prop;\r\n          archive->GetProperty(i, kpidSize, &prop);\r\n          UString s = ConvertPropVariantToString(prop);\r\n          PrintString(s);\r\n          PrintString(\"  \");\r\n        }\r\n        {\r\n          // Get name of file\r\n          NWindows::NCOM::CPropVariant prop;\r\n          archive->GetProperty(i, kpidPath, &prop);\r\n          UString s = ConvertPropVariantToString(prop);\r\n          PrintString(s);\r\n        }\r\n        PrintString(\"\\n\");\r\n      }\r\n    }\r\n    else\r\n    {\r\n      // Extract command\r\n      CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n      CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);\r\n      extractCallbackSpec->Init(archive, L\"\"); // second parameter is output folder path\r\n      extractCallbackSpec->PasswordIsDefined = false;\r\n      // extractCallbackSpec->PasswordIsDefined = true;\r\n      // extractCallbackSpec->Password = L\"1\";\r\n      HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);\r\n      if (result != S_OK)\r\n      {\r\n        PrintError(\"Extract Error\");\r\n        return 1;\r\n      }\r\n    }\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Client7z/Client7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Client7z\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=Client7z - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"Client7z.mak\" CFG=\"Client7z - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"Client7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"Client7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"Client7z - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n\r\n!ELSEIF  \"$(CFG)\" == \"Client7z - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"Client7z - Win32 Release\"\r\n# Name \"Client7z - Win32 Debug\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"stdafx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\DLL.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileDir.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileFind.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileName.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\IntToString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyString.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyVector.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Wildcard.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\Client7z.cpp\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Client7z/Client7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"Client7z\"=.\\Client7z.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Client7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Client7z/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include <windows.h>\r\n#include <stdio.h>\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Client7z/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\Client7z.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\IntToString.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FileStreams.obj \\\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.cpp",
    "content": "// ArchiveCommandLine.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include <io.h>\r\n#endif\r\n#include <stdio.h>\r\n\r\n#include \"Common/ListFileUtils.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/FileMapping.h\"\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ArchiveCommandLine.h\"\r\n#include \"UpdateAction.h\"\r\n#include \"Update.h\"\r\n#include \"SortUtils.h\"\r\n#include \"EnumDirItems.h\"\r\n\r\nextern bool g_CaseSensitive;\r\n\r\n#if _MSC_VER >= 1400\r\n#define MY_isatty_fileno(x) _isatty(_fileno(x))\r\n#else\r\n#define MY_isatty_fileno(x) isatty(fileno(x))\r\n#endif\r\n\r\n#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);\r\n\r\nusing namespace NCommandLineParser;\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kHelp3,\r\n  kDisableHeaders,\r\n  kDisablePercents,\r\n  kArchiveType,\r\n  kYes,\r\n  #ifndef _NO_CRYPTO\r\n  kPassword,\r\n  #endif\r\n  kProperty,\r\n  kOutputDir,\r\n  kWorkingDir,\r\n  kInclude,\r\n  kExclude,\r\n  kArInclude,\r\n  kArExclude,\r\n  kNoArName,\r\n  kUpdate,\r\n  kVolume,\r\n  kRecursed,\r\n  kSfx,\r\n  kStdIn,\r\n  kStdOut,\r\n  kOverwrite,\r\n  kEmail,\r\n  kShowDialog,\r\n  kLargePages,\r\n  kCharSet,\r\n  kTechMode,\r\n  kShareForWrite,\r\n  kCaseSensitive\r\n};\r\n\r\n}\r\n\r\n\r\nstatic const wchar_t kRecursedIDChar = 'R';\r\nstatic const wchar_t *kRecursedPostCharSet = L\"0-\";\r\n\r\nnamespace NRecursedPostCharIndex {\r\n  enum EEnum\r\n  {\r\n    kWildCardRecursionOnly = 0,\r\n    kNoRecursion = 1\r\n  };\r\n}\r\n\r\nstatic const char kImmediateNameID = '!';\r\nstatic const char kMapNameID = '#';\r\nstatic const char kFileListID = '@';\r\n\r\nstatic const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be\r\nstatic const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be\r\n\r\nstatic const wchar_t *kOverwritePostCharSet = L\"asut\";\r\n\r\nNExtract::NOverwriteMode::EEnum k_OverwriteModes[] =\r\n{\r\n  NExtract::NOverwriteMode::kWithoutPrompt,\r\n  NExtract::NOverwriteMode::kSkipExisting,\r\n  NExtract::NOverwriteMode::kAutoRename,\r\n  NExtract::NOverwriteMode::kAutoRenameExisting\r\n};\r\n\r\nstatic const CSwitchForm kSwitchForms[] =\r\n  {\r\n    { L\"?\",  NSwitchType::kSimple, false },\r\n    { L\"H\",  NSwitchType::kSimple, false },\r\n    { L\"-HELP\",  NSwitchType::kSimple, false },\r\n    { L\"BA\", NSwitchType::kSimple, false },\r\n    { L\"BD\", NSwitchType::kSimple, false },\r\n    { L\"T\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"Y\",  NSwitchType::kSimple, false },\r\n    #ifndef _NO_CRYPTO\r\n    { L\"P\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    #endif\r\n    { L\"M\",  NSwitchType::kUnLimitedPostString, true, 1 },\r\n    { L\"O\",  NSwitchType::kUnLimitedPostString, false, 1 },\r\n    { L\"W\",  NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"I\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"X\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AI\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AX\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\r\n    { L\"AN\", NSwitchType::kSimple, false },\r\n    { L\"U\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"V\",  NSwitchType::kUnLimitedPostString, true, 1},\r\n    { L\"R\",  NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },\r\n    { L\"SFX\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SI\", NSwitchType::kUnLimitedPostString, false, 0 },\r\n    { L\"SO\", NSwitchType::kSimple, false, 0 },\r\n    { L\"AO\", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},\r\n    { L\"SEML\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"AD\",  NSwitchType::kSimple, false },\r\n    { L\"SLP\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SCS\", NSwitchType::kUnLimitedPostString, false, 0},\r\n    { L\"SLT\", NSwitchType::kSimple, false },\r\n    { L\"SSW\", NSwitchType::kSimple, false },\r\n    { L\"SSC\", NSwitchType::kPostChar, false, 0, 0, L\"-\" }\r\n  };\r\n\r\nstatic const CCommandForm g_CommandForms[] =\r\n{\r\n  { L\"A\", false },\r\n  { L\"U\", false },\r\n  { L\"D\", false },\r\n  { L\"T\", false },\r\n  { L\"E\", false },\r\n  { L\"X\", false },\r\n  { L\"L\", false },\r\n  { L\"B\", false },\r\n  { L\"I\", false }\r\n};\r\n\r\nstatic const int kNumCommandForms = sizeof(g_CommandForms) /  sizeof(g_CommandForms[0]);\r\n\r\nstatic const wchar_t *kUniversalWildcard = L\"*\";\r\nstatic const int kMinNonSwitchWords = 1;\r\nstatic const int kCommandIndex = 0;\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\";\r\nstatic const char *kIncorrectListFile = \"Incorrect item in listfile.\\nCheck charset encoding and -scs switch.\";\r\nstatic const char *kIncorrectWildCardInListFile = \"Incorrect wildcard in listfile\";\r\nstatic const char *kIncorrectWildCardInCommandLine  = \"Incorrect wildcard in command line\";\r\nstatic const char *kTerminalOutError = \"I won't write compressed data to a terminal\";\r\nstatic const char *kSameTerminalError = \"I won't write data and program's messages to same terminal\";\r\n\r\nstatic void ThrowException(const char *errorMessage)\r\n{\r\n  throw CArchiveCommandLineException(errorMessage);\r\n};\r\n\r\nstatic void ThrowUserErrorException()\r\n{\r\n  ThrowException(kUserErrorMessage);\r\n};\r\n\r\n// ---------------------------\r\n\r\nbool CArchiveCommand::IsFromExtractGroup() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kExtract:\r\n    case NCommandType::kFullExtract:\r\n      return true;\r\n    default:\r\n      return false;\r\n  }\r\n}\r\n\r\nNExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const\r\n{\r\n  switch(CommandType)\r\n  {\r\n    case NCommandType::kTest:\r\n    case NCommandType::kFullExtract:\r\n      return NExtract::NPathMode::kFullPathnames;\r\n    default:\r\n      return NExtract::NPathMode::kNoPathnames;\r\n  }\r\n}\r\n\r\nbool CArchiveCommand::IsFromUpdateGroup() const\r\n{\r\n  return (CommandType == NCommandType::kAdd ||\r\n    CommandType == NCommandType::kUpdate ||\r\n    CommandType == NCommandType::kDelete);\r\n}\r\n\r\nstatic NRecursedType::EEnum GetRecursedTypeFromIndex(int index)\r\n{\r\n  switch (index)\r\n  {\r\n    case NRecursedPostCharIndex::kWildCardRecursionOnly:\r\n      return NRecursedType::kWildCardOnlyRecursed;\r\n    case NRecursedPostCharIndex::kNoRecursion:\r\n      return NRecursedType::kNonRecursed;\r\n    default:\r\n      return NRecursedType::kRecursed;\r\n  }\r\n}\r\n\r\nstatic bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)\r\n{\r\n  UString commandStringUpper = commandString;\r\n  commandStringUpper.MakeUpper();\r\n  UString postString;\r\n  int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper,\r\n      postString) ;\r\n  if (commandIndex < 0)\r\n    return false;\r\n  command.CommandType = (NCommandType::EEnum)commandIndex;\r\n  return true;\r\n}\r\n\r\n// ------------------------------------------------------------------\r\n// filenames functions\r\n\r\nstatic bool AddNameToCensor(NWildcard::CCensor &wildcardCensor,\r\n    const UString &name, bool include, NRecursedType::EEnum type)\r\n{\r\n  bool isWildCard = DoesNameContainWildCard(name);\r\n  bool recursed = false;\r\n\r\n  switch (type)\r\n  {\r\n    case NRecursedType::kWildCardOnlyRecursed:\r\n      recursed = isWildCard;\r\n      break;\r\n    case NRecursedType::kRecursed:\r\n      recursed = true;\r\n      break;\r\n    case NRecursedType::kNonRecursed:\r\n      recursed = false;\r\n      break;\r\n  }\r\n  wildcardCensor.AddItem(include, name, recursed);\r\n  return true;\r\n}\r\n\r\nstatic void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,\r\n    LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)\r\n{\r\n  UStringVector names;\r\n  if (!ReadNamesFromListFile(fileName, names, codePage))\r\n    throw kIncorrectListFile;\r\n  for (int i = 0; i < names.Size(); i++)\r\n    if (!AddNameToCensor(wildcardCensor, names[i], include, type))\r\n      throw kIncorrectWildCardInListFile;\r\n}\r\n\r\nstatic void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor,\r\n    const UString &name, bool include, NRecursedType::EEnum recursedType)\r\n{\r\n  if (!AddNameToCensor(wildcardCensor, name, include, recursedType))\r\n    throw kIncorrectWildCardInCommandLine;\r\n}\r\n\r\nstatic void AddToCensorFromNonSwitchesStrings(\r\n    int startIndex,\r\n    NWildcard::CCensor &wildcardCensor,\r\n    const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,\r\n    bool thereAreSwitchIncludes, UINT codePage)\r\n{\r\n  if (nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes))\r\n    AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);\r\n  for (int i = startIndex; i < nonSwitchStrings.Size(); i++)\r\n  {\r\n    const UString &s = nonSwitchStrings[i];\r\n    if (s[0] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);\r\n    else\r\n      AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor,\r\n    const UString &switchParam, bool include,\r\n    NRecursedType::EEnum commonRecursedType)\r\n{\r\n  int splitPos = switchParam.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  UString mappingName = switchParam.Left(splitPos);\r\n  \r\n  UString switchParam2 = switchParam.Mid(splitPos + 1);\r\n  splitPos = switchParam2.Find(L':');\r\n  if (splitPos < 0)\r\n    ThrowUserErrorException();\r\n  \r\n  UString mappingSize = switchParam2.Left(splitPos);\r\n  UString eventName = switchParam2.Mid(splitPos + 1);\r\n  \r\n  UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);\r\n  UInt32 dataSize = (UInt32)dataSize64;\r\n  {\r\n    CFileMapping fileMapping;\r\n    if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName)))\r\n      ThrowException(\"Can not open mapping\");\r\n    LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize);\r\n    if (data == NULL)\r\n      ThrowException(\"MapViewOfFile error\");\r\n    try\r\n    {\r\n      const wchar_t *curData = (const wchar_t *)data;\r\n      if (*curData != 0)\r\n        ThrowException(\"Incorrect mapping data\");\r\n      UInt32 numChars = dataSize / sizeof(wchar_t);\r\n      UString name;\r\n      for (UInt32 i = 1; i < numChars; i++)\r\n      {\r\n        wchar_t c = curData[i];\r\n        if (c == L'\\0')\r\n        {\r\n          AddCommandLineWildCardToCensr(wildcardCensor,\r\n              name, include, commonRecursedType);\r\n          name.Empty();\r\n        }\r\n        else\r\n          name += c;\r\n      }\r\n      if (!name.IsEmpty())\r\n        ThrowException(\"data error\");\r\n    }\r\n    catch(...)\r\n    {\r\n      UnmapViewOfFile(data);\r\n      throw;\r\n    }\r\n    UnmapViewOfFile(data);\r\n  }\r\n  \r\n  {\r\n    NSynchronization::CManualResetEvent event;\r\n    if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)\r\n      event.Set();\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,\r\n    const UStringVector &strings, bool include,\r\n    NRecursedType::EEnum commonRecursedType, UINT codePage)\r\n{\r\n  for (int i = 0; i < strings.Size(); i++)\r\n  {\r\n    const UString &name = strings[i];\r\n    NRecursedType::EEnum recursedType;\r\n    int pos = 0;\r\n    if (name.Length() < kSomeCludePostStringMinSize)\r\n      ThrowUserErrorException();\r\n    if (::MyCharUpper(name[pos]) == kRecursedIDChar)\r\n    {\r\n      pos++;\r\n      int index = UString(kRecursedPostCharSet).Find(name[pos]);\r\n      recursedType = GetRecursedTypeFromIndex(index);\r\n      if (index >= 0)\r\n        pos++;\r\n    }\r\n    else\r\n      recursedType = commonRecursedType;\r\n    if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)\r\n      ThrowUserErrorException();\r\n    UString tail = name.Mid(pos + 1);\r\n    if (name[pos] == kImmediateNameID)\r\n      AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);\r\n    else if (name[pos] == kFileListID)\r\n      AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);\r\n    #ifdef _WIN32\r\n    else if (name[pos] == kMapNameID)\r\n      ParseMapWithPaths(wildcardCensor, tail, include, recursedType);\r\n    #endif\r\n    else\r\n      ThrowUserErrorException();\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\n// This code converts all short file names to long file names.\r\n\r\nstatic void ConvertToLongName(const UString &prefix, UString &name)\r\n{\r\n  if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n    return;\r\n  NFind::CFileInfoW fileInfo;\r\n  if (NFind::FindFile(prefix + name, fileInfo))\r\n    name = fileInfo.Name;\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)\r\n{\r\n  for (int i = 0; i < items.Size(); i++)\r\n  {\r\n    NWildcard::CItem &item = items[i];\r\n    if (item.Recursive || item.PathParts.Size() != 1)\r\n      continue;\r\n    ConvertToLongName(prefix, item.PathParts.Front());\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)\r\n{\r\n  ConvertToLongNames(prefix, node.IncludeItems);\r\n  ConvertToLongNames(prefix, node.ExcludeItems);\r\n  int i;\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n    ConvertToLongName(prefix, node.SubNodes[i].Name);\r\n  // mix folders with same name\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];\r\n    for (int j = i + 1; j < node.SubNodes.Size();)\r\n    {\r\n      const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];\r\n      if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)\r\n      {\r\n        nextNode1.IncludeItems += nextNode2.IncludeItems;\r\n        nextNode1.ExcludeItems += nextNode2.ExcludeItems;\r\n        node.SubNodes.Delete(j);\r\n      }\r\n      else\r\n        j++;\r\n    }\r\n  }\r\n  for (i = 0; i < node.SubNodes.Size(); i++)\r\n  {\r\n    NWildcard::CCensorNode &nextNode = node.SubNodes[i];\r\n    ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode);\r\n  }\r\n}\r\n\r\nstatic void ConvertToLongNames(NWildcard::CCensor &censor)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    NWildcard::CPair &pair = censor.Pairs[i];\r\n    ConvertToLongNames(pair.Prefix, pair.Head);\r\n  }\r\n}\r\n\r\n#endif\r\n\r\nstatic NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)\r\n{\r\n  switch(i)\r\n  {\r\n    case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;\r\n    case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;\r\n    case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;\r\n    case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;\r\n  }\r\n  throw 98111603;\r\n}\r\n\r\nconst UString kUpdatePairStateIDSet = L\"PQRXYZW\";\r\nconst int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};\r\n\r\nconst UString kUpdatePairActionIDSet = L\"0123\"; //Ignore, Copy, Compress, Create Anti\r\n\r\nconst wchar_t *kUpdateIgnoreItselfPostStringID = L\"-\";\r\nconst wchar_t kUpdateNewArchivePostCharID = '!';\r\n\r\n\r\nstatic bool ParseUpdateCommandString2(const UString &command,\r\n    NUpdateArchive::CActionSet &actionSet, UString &postString)\r\n{\r\n  for (int i = 0; i < command.Length();)\r\n  {\r\n    wchar_t c = MyCharUpper(command[i]);\r\n    int statePos = kUpdatePairStateIDSet.Find(c);\r\n    if (statePos < 0)\r\n    {\r\n      postString = command.Mid(i);\r\n      return true;\r\n    }\r\n    i++;\r\n    if (i >= command.Length())\r\n      return false;\r\n    int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));\r\n    if (actionPos < 0)\r\n      return false;\r\n    actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);\r\n    if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)\r\n      return false;\r\n    i++;\r\n  }\r\n  postString.Empty();\r\n  return true;\r\n}\r\n\r\nstatic void ParseUpdateCommandString(CUpdateOptions &options,\r\n    const UStringVector &updatePostStrings,\r\n    const NUpdateArchive::CActionSet &defaultActionSet)\r\n{\r\n  for (int i = 0; i < updatePostStrings.Size(); i++)\r\n  {\r\n    const UString &updateString = updatePostStrings[i];\r\n    if (updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)\r\n    {\r\n      if (options.UpdateArchiveItself)\r\n      {\r\n        options.UpdateArchiveItself = false;\r\n        options.Commands.Delete(0);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      NUpdateArchive::CActionSet actionSet = defaultActionSet;\r\n\r\n      UString postString;\r\n      if (!ParseUpdateCommandString2(updateString, actionSet, postString))\r\n        ThrowUserErrorException();\r\n      if (postString.IsEmpty())\r\n      {\r\n        if (options.UpdateArchiveItself)\r\n          options.Commands[0].ActionSet = actionSet;\r\n      }\r\n      else\r\n      {\r\n        if (MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)\r\n          ThrowUserErrorException();\r\n        CUpdateArchiveCommand uc;\r\n        UString archivePath = postString.Mid(1);\r\n        if (archivePath.IsEmpty())\r\n          ThrowUserErrorException();\r\n        uc.UserArchivePath = archivePath;\r\n        uc.ActionSet = actionSet;\r\n        options.Commands.Add(uc);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic const char kByteSymbol = 'B';\r\nstatic const char kKiloSymbol = 'K';\r\nstatic const char kMegaSymbol = 'M';\r\nstatic const char kGigaSymbol = 'G';\r\n\r\nstatic bool ParseComplexSize(const UString &src, UInt64 &result)\r\n{\r\n  UString s = src;\r\n  s.MakeUpper();\r\n\r\n  const wchar_t *start = s;\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(start, &end);\r\n  int numDigits = (int)(end - start);\r\n  if (numDigits == 0 || s.Length() > numDigits + 1)\r\n    return false;\r\n  if (s.Length() == numDigits)\r\n  {\r\n    result = number;\r\n    return true;\r\n  }\r\n  int numBits;\r\n  switch (s[numDigits])\r\n  {\r\n    case kByteSymbol:\r\n      result = number;\r\n      return true;\r\n    case kKiloSymbol:\r\n      numBits = 10;\r\n      break;\r\n    case kMegaSymbol:\r\n      numBits = 20;\r\n      break;\r\n    case kGigaSymbol:\r\n      numBits = 30;\r\n      break;\r\n    default:\r\n      return false;\r\n  }\r\n  if (number >= ((UInt64)1 << (64 - numBits)))\r\n    return false;\r\n  result = number << numBits;\r\n  return true;\r\n}\r\n\r\nstatic void SetAddCommandOptions(\r\n    NCommandType::EEnum commandType,\r\n    const CParser &parser,\r\n    CUpdateOptions &options)\r\n{\r\n  NUpdateArchive::CActionSet defaultActionSet;\r\n  switch(commandType)\r\n  {\r\n    case NCommandType::kAdd:\r\n      defaultActionSet = NUpdateArchive::kAddActionSet;\r\n      break;\r\n    case NCommandType::kDelete:\r\n      defaultActionSet = NUpdateArchive::kDeleteActionSet;\r\n      break;\r\n    default:\r\n      defaultActionSet = NUpdateArchive::kUpdateActionSet;\r\n  }\r\n  \r\n  options.UpdateArchiveItself = true;\r\n  \r\n  options.Commands.Clear();\r\n  CUpdateArchiveCommand updateMainCommand;\r\n  updateMainCommand.ActionSet = defaultActionSet;\r\n  options.Commands.Add(updateMainCommand);\r\n  if (parser[NKey::kUpdate].ThereIs)\r\n    ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings,\r\n        defaultActionSet);\r\n  if (parser[NKey::kWorkingDir].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];\r\n    if (postString.IsEmpty())\r\n      NDirectory::MyGetTempPath(options.WorkingDir);\r\n    else\r\n      options.WorkingDir = postString;\r\n  }\r\n  options.SfxMode = parser[NKey::kSfx].ThereIs;\r\n  if (options.SfxMode)\r\n    options.SfxModule = parser[NKey::kSfx].PostStrings[0];\r\n\r\n  if (parser[NKey::kVolume].ThereIs)\r\n  {\r\n    const UStringVector &sv = parser[NKey::kVolume].PostStrings;\r\n    for (int i = 0; i < sv.Size(); i++)\r\n    {\r\n      UInt64 size;\r\n      if (!ParseComplexSize(sv[i], size))\r\n        ThrowException(\"Incorrect volume size\");\r\n      options.VolumesSizes.Add(size);\r\n    }\r\n  }\r\n}\r\n\r\nstatic void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)\r\n{\r\n  if (parser[NKey::kProperty].ThereIs)\r\n  {\r\n    // options.MethodMode.Properties.Clear();\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      CProperty property;\r\n      const UString &postString = parser[NKey::kProperty].PostStrings[i];\r\n      int index = postString.Find(L'=');\r\n      if (index < 0)\r\n        property.Name = postString;\r\n      else\r\n      {\r\n        property.Name = postString.Left(index);\r\n        property.Value = postString.Mid(index + 1);\r\n      }\r\n      properties.Add(property);\r\n    }\r\n  }\r\n}\r\n\r\nCArchiveCommandLineParser::CArchiveCommandLineParser():\r\n  parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}\r\n\r\nvoid CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,\r\n    CArchiveCommandLineOptions &options)\r\n{\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...)\r\n  {\r\n    ThrowUserErrorException();\r\n  }\r\n\r\n  options.IsInTerminal = MY_IS_TERMINAL(stdin);\r\n  options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);\r\n  options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);\r\n  options.StdOutMode = parser[NKey::kStdOut].ThereIs;\r\n  options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;\r\n  options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs  || parser[NKey::kHelp3].ThereIs;\r\n\r\n  #ifdef _WIN32\r\n  options.LargePages = false;\r\n  if (parser[NKey::kLargePages].ThereIs)\r\n  {\r\n    const UString &postString = parser[NKey::kLargePages].PostStrings.Front();\r\n    if (postString.IsEmpty())\r\n      options.LargePages = true;\r\n  }\r\n  #endif\r\n}\r\n\r\nstruct CCodePagePair\r\n{\r\n  const wchar_t *Name;\r\n  UINT CodePage;\r\n};\r\n\r\nstatic CCodePagePair g_CodePagePairs[] =\r\n{\r\n  { L\"UTF-8\", CP_UTF8 },\r\n  { L\"WIN\",   CP_ACP },\r\n  { L\"DOS\",   CP_OEMCP }\r\n};\r\n\r\nstatic const int kNumCodePages = sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]);\r\n\r\nstatic bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)\r\n{\r\n  const wchar_t *end;\r\n  UInt64 number = ConvertStringToUInt64(s, &end);\r\n  if (*end != 0)\r\n    return false;\r\n  if (number > (UInt32)0xFFFFFFFF)\r\n    return false;\r\n  v = (UInt32)number;\r\n  return true;\r\n}\r\n\r\nvoid CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)\r\n{\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n  int numNonSwitchStrings = nonSwitchStrings.Size();\r\n  if (numNonSwitchStrings < kMinNonSwitchWords)\r\n    ThrowUserErrorException();\r\n\r\n  if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))\r\n    ThrowUserErrorException();\r\n\r\n  options.TechMode = parser[NKey::kTechMode].ThereIs;\r\n\r\n  if (parser[NKey::kCaseSensitive].ThereIs)\r\n    g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);\r\n\r\n  NRecursedType::EEnum recursedType;\r\n  if (parser[NKey::kRecursed].ThereIs)\r\n    recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);\r\n  else\r\n    recursedType = NRecursedType::kNonRecursed;\r\n\r\n  UINT codePage = CP_UTF8;\r\n  if (parser[NKey::kCharSet].ThereIs)\r\n  {\r\n    UString name = parser[NKey::kCharSet].PostStrings.Front();\r\n    name.MakeUpper();\r\n    int i;\r\n    for (i = 0; i < kNumCodePages; i++)\r\n    {\r\n      const CCodePagePair &pair = g_CodePagePairs[i];\r\n      if (name.Compare(pair.Name) == 0)\r\n      {\r\n        codePage = pair.CodePage;\r\n        break;\r\n      }\r\n    }\r\n    if (i >= kNumCodePages)\r\n      ThrowUserErrorException();\r\n  }\r\n\r\n  bool thereAreSwitchIncludes = false;\r\n  if (parser[NKey::kInclude].ThereIs)\r\n  {\r\n    thereAreSwitchIncludes = true;\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\r\n        parser[NKey::kInclude].PostStrings, true, recursedType, codePage);\r\n  }\r\n  if (parser[NKey::kExclude].ThereIs)\r\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\r\n        parser[NKey::kExclude].PostStrings, false, recursedType, codePage);\r\n \r\n  int curCommandIndex = kCommandIndex + 1;\r\n  bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs &&\r\n      options.Command.CommandType != NCommandType::kBenchmark &&\r\n      options.Command.CommandType != NCommandType::kInfo;\r\n  if (thereIsArchiveName)\r\n  {\r\n    if (curCommandIndex >= numNonSwitchStrings)\r\n      ThrowUserErrorException();\r\n    options.ArchiveName = nonSwitchStrings[curCommandIndex++];\r\n  }\r\n\r\n  AddToCensorFromNonSwitchesStrings(\r\n      curCommandIndex, options.WildcardCensor,\r\n      nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);\r\n\r\n  options.YesToAll = parser[NKey::kYes].ThereIs;\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  #ifndef _NO_CRYPTO\r\n  options.PasswordEnabled = parser[NKey::kPassword].ThereIs;\r\n  if (options.PasswordEnabled)\r\n    options.Password = parser[NKey::kPassword].PostStrings[0];\r\n  #endif\r\n\r\n  options.StdInMode = parser[NKey::kStdIn].ThereIs;\r\n  options.ShowDialog = parser[NKey::kShowDialog].ThereIs;\r\n\r\n  if (parser[NKey::kArchiveType].ThereIs)\r\n    options.ArcType = parser[NKey::kArchiveType].PostStrings[0];\r\n\r\n  if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if (options.StdInMode)\r\n      ThrowException(\"Reading archives from stdin is not implemented\");\r\n    if (!options.WildcardCensor.AllAreRelative())\r\n      ThrowException(\"Cannot use absolute pathnames for this command\");\r\n\r\n    NWildcard::CCensor archiveWildcardCensor;\r\n\r\n    if (parser[NKey::kArInclude].ThereIs)\r\n    {\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\r\n        parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);\r\n    }\r\n    if (parser[NKey::kArExclude].ThereIs)\r\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\r\n      parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);\r\n\r\n    if (thereIsArchiveName)\r\n      AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(archiveWildcardCensor);\r\n    #endif\r\n\r\n    archiveWildcardCensor.ExtendExclude();\r\n\r\n    UStringVector archivePaths;\r\n\r\n    {\r\n      CDirItems dirItems;\r\n      {\r\n        UStringVector errorPaths;\r\n        CRecordVector<DWORD> errorCodes;\r\n        HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);\r\n        if (res != S_OK || errorPaths.Size() > 0)\r\n          throw \"cannot find archive\";\r\n      }\r\n      for (int i = 0; i < dirItems.Items.Size(); i++)\r\n      {\r\n        const CDirItem &dirItem = dirItems.Items[i];\r\n        if (!dirItem.IsDir())\r\n          archivePaths.Add(dirItems.GetPhyPath(i));\r\n      }\r\n    }\r\n\r\n    if (archivePaths.Size() == 0)\r\n      throw \"there is no such archive\";\r\n\r\n    UStringVector archivePathsFull;\r\n\r\n    int i;\r\n    for (i = 0; i < archivePaths.Size(); i++)\r\n    {\r\n      UString fullPath;\r\n      NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);\r\n      archivePathsFull.Add(fullPath);\r\n    }\r\n    CIntVector indices;\r\n    SortFileNames(archivePathsFull, indices);\r\n    options.ArchivePathsSorted.Reserve(indices.Size());\r\n    options.ArchivePathsFullSorted.Reserve(indices.Size());\r\n    for (i = 0; i < indices.Size(); i++)\r\n    {\r\n      options.ArchivePathsSorted.Add(archivePaths[indices[i]]);\r\n      options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);\r\n    }\r\n\r\n    if (isExtractGroupCommand)\r\n    {\r\n      SetMethodOptions(parser, options.ExtractProperties);\r\n      if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)\r\n        throw kSameTerminalError;\r\n      if (parser[NKey::kOutputDir].ThereIs)\r\n      {\r\n        options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];\r\n        NFile::NName::NormalizeDirPathPrefix(options.OutputDir);\r\n      }\r\n\r\n      options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;\r\n      if (parser[NKey::kOverwrite].ThereIs)\r\n        options.OverwriteMode =\r\n            k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];\r\n      else if (options.YesToAll)\r\n        options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n    }\r\n  }\r\n  else if (options.Command.IsFromUpdateGroup())\r\n  {\r\n    CUpdateOptions &updateOptions = options.UpdateOptions;\r\n\r\n    SetAddCommandOptions(options.Command.CommandType, parser, updateOptions);\r\n    \r\n    SetMethodOptions(parser, updateOptions.MethodMode.Properties);\r\n\r\n    if (parser[NKey::kShareForWrite].ThereIs)\r\n      updateOptions.OpenShareForWrite = true;\r\n\r\n    options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;\r\n\r\n    if (options.EnablePercents)\r\n    {\r\n      if ((options.StdOutMode && !options.IsStdErrTerminal) ||\r\n         (!options.StdOutMode && !options.IsStdOutTerminal))\r\n        options.EnablePercents = false;\r\n    }\r\n\r\n    updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;\r\n    if (updateOptions.EMailMode)\r\n    {\r\n      updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();\r\n      if (updateOptions.EMailAddress.Length() > 0)\r\n        if (updateOptions.EMailAddress[0] == L'.')\r\n        {\r\n          updateOptions.EMailRemoveAfter = true;\r\n          updateOptions.EMailAddress.Delete(0);\r\n        }\r\n    }\r\n\r\n    updateOptions.StdOutMode = options.StdOutMode;\r\n    updateOptions.StdInMode = options.StdInMode;\r\n\r\n    if (updateOptions.StdOutMode && updateOptions.EMailMode)\r\n      throw \"stdout mode and email mode cannot be combined\";\r\n    if (updateOptions.StdOutMode && options.IsStdOutTerminal)\r\n      throw kTerminalOutError;\r\n    if (updateOptions.StdInMode)\r\n      updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();\r\n\r\n    #ifdef _WIN32\r\n    ConvertToLongNames(options.WildcardCensor);\r\n    #endif\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    options.NumThreads = (UInt32)-1;\r\n    options.DictionarySize = (UInt32)-1;\r\n    options.NumIterations = 1;\r\n    if (curCommandIndex < numNonSwitchStrings)\r\n    {\r\n      if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))\r\n        ThrowUserErrorException();\r\n    }\r\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\r\n    {\r\n      UString postString = parser[NKey::kProperty].PostStrings[i];\r\n      postString.MakeUpper();\r\n      if (postString.Length() < 2)\r\n        ThrowUserErrorException();\r\n      if (postString[0] == 'D')\r\n      {\r\n        int pos = 1;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        UInt32 logSize;\r\n        if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))\r\n          ThrowUserErrorException();\r\n        if (logSize > 31)\r\n          ThrowUserErrorException();\r\n        options.DictionarySize = 1 << logSize;\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == 'T' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] == '=')\r\n          pos++;\r\n        if (postString[pos] != 0)\r\n          if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))\r\n            ThrowUserErrorException();\r\n      }\r\n      else if (postString[0] == 'M' && postString[1] == '=' )\r\n      {\r\n        int pos = 2;\r\n        if (postString[pos] != 0)\r\n          options.Method = postString.Mid(2);\r\n      }\r\n      else\r\n        ThrowUserErrorException();\r\n    }\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n  }\r\n  else\r\n    ThrowUserErrorException();\r\n  options.WildcardCensor.ExtendExclude();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ArchiveCommandLine.h",
    "content": "// ArchiveCommandLine.h\r\n\r\n#ifndef __ARCHIVECOMMANDLINE_H\r\n#define __ARCHIVECOMMANDLINE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/CommandLineParser.h\"\r\n\r\n#include \"Extract.h\"\r\n#include \"Update.h\"\r\n\r\nstruct CArchiveCommandLineException: public AString\r\n{\r\n  CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {}\r\n};\r\n\r\nnamespace NCommandType { enum EEnum\r\n{\r\n  kAdd = 0,\r\n  kUpdate,\r\n  kDelete,\r\n  kTest,\r\n  kExtract,\r\n  kFullExtract,\r\n  kList,\r\n  kBenchmark,\r\n  kInfo\r\n};}\r\n\r\nnamespace NRecursedType { enum EEnum\r\n{\r\n  kRecursed,\r\n  kWildCardOnlyRecursed,\r\n  kNonRecursed\r\n};}\r\n\r\nstruct CArchiveCommand\r\n{\r\n  NCommandType::EEnum CommandType;\r\n  bool IsFromExtractGroup() const;\r\n  bool IsFromUpdateGroup() const;\r\n  bool IsTestMode() const { return CommandType == NCommandType::kTest; }\r\n  NExtract::NPathMode::EEnum GetPathMode() const;\r\n};\r\n\r\nstruct CArchiveCommandLineOptions\r\n{\r\n  bool HelpMode;\r\n\r\n  #ifdef _WIN32\r\n  bool LargePages;\r\n  #endif\r\n\r\n  bool IsInTerminal;\r\n  bool IsStdOutTerminal;\r\n  bool IsStdErrTerminal;\r\n  bool StdInMode;\r\n  bool StdOutMode;\r\n  bool EnableHeaders;\r\n\r\n  bool YesToAll;\r\n  bool ShowDialog;\r\n  // NWildcard::CCensor ArchiveWildcardCensor;\r\n  NWildcard::CCensor WildcardCensor;\r\n\r\n  CArchiveCommand Command;\r\n  UString ArchiveName;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordEnabled;\r\n  UString Password;\r\n  #endif\r\n\r\n  bool TechMode;\r\n  // Extract\r\n  bool AppendName;\r\n  UString OutputDir;\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n  UStringVector ArchivePathsSorted;\r\n  UStringVector ArchivePathsFullSorted;\r\n  CObjectVector<CProperty> ExtractProperties;\r\n\r\n  CUpdateOptions UpdateOptions;\r\n  UString ArcType;\r\n  bool EnablePercents;\r\n\r\n  // Benchmark\r\n  UInt32 NumIterations;\r\n  UInt32 NumThreads;\r\n  UInt32 DictionarySize;\r\n  UString Method;\r\n\r\n\r\n  CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};\r\n};\r\n\r\nclass CArchiveCommandLineParser\r\n{\r\n  NCommandLineParser::CParser parser;\r\npublic:\r\n  CArchiveCommandLineParser();\r\n  void Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options);\r\n  void Parse2(CArchiveCommandLineOptions &options);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp",
    "content": "// ArchiveExtractCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n#include \"OpenArchive.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic const wchar_t *kCantAutoRename = L\"ERROR: Can not create file with auto name\";\r\nstatic const wchar_t *kCantRenameFile = L\"ERROR: Can not rename existing file \";\r\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\r\n\r\n\r\nvoid CArchiveExtractCallback::Init(\r\n    IInArchive *archiveHandler,\r\n    IFolderArchiveExtractCallback *extractCallback2,\r\n    bool stdOutMode,\r\n    const UString &directoryPath,\r\n    const UStringVector &removePathParts,\r\n    const UString &itemDefaultName,\r\n    const FILETIME &utcMTimeDefault,\r\n    UInt32 attributesDefault,\r\n    UInt64 packSize)\r\n{\r\n  _stdOutMode = stdOutMode;\r\n  _numErrors = 0;\r\n  _unpTotal = 1;\r\n  _packTotal = packSize;\r\n\r\n  _extractCallback2 = extractCallback2;\r\n  _compressProgress.Release();\r\n  _extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);\r\n\r\n  LocalProgressSpec->Init(extractCallback2, true);\r\n  LocalProgressSpec->SendProgress = false;\r\n\r\n  _itemDefaultName = itemDefaultName;\r\n  _utcMTimeDefault = utcMTimeDefault;\r\n  _attributesDefault = attributesDefault;\r\n  _removePathParts = removePathParts;\r\n  _archiveHandler = archiveHandler;\r\n  _directoryPath = directoryPath;\r\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  _unpTotal = size;\r\n  if (!_multiArchives && _extractCallback2)\r\n    return _extractCallback2->SetTotal(size);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\r\n{\r\n  const UInt64 kMax = (UInt64)1 << 31;\r\n  while (v1 > kMax)\r\n  {\r\n    v1 >>= 1;\r\n    v2 >>= 1;\r\n  }\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)\r\n{\r\n  NormalizeVals(packTotal, unpTotal);\r\n  NormalizeVals(unpCur, unpTotal);\r\n  if (unpTotal == 0)\r\n    unpTotal = 1;\r\n  return unpCur * packTotal / unpTotal;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_extractCallback2)\r\n    return S_OK;\r\n\r\n  if (_multiArchives)\r\n  {\r\n    if (completeValue != NULL)\r\n    {\r\n      UInt64 packCur = LocalProgressSpec->InSize + MyMultDiv64(*completeValue, _unpTotal, _packTotal);\r\n      return _extractCallback2->SetCompleted(&packCur);\r\n    }\r\n  }\r\n  return _extractCallback2->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return _localProgress->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\nvoid CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)\r\n{\r\n  fullPath = _directoryPath;\r\n  for(int i = 0; i < dirPathParts.Size(); i++)\r\n  {\r\n    if (i > 0)\r\n      fullPath += wchar_t(NFile::NName::kDirDelimiter);\r\n    fullPath += dirPathParts[i];\r\n    NFile::NDirectory::MyCreateDirectory(fullPath);\r\n  }\r\n}\r\n\r\nstatic UString MakePathNameFromParts(const UStringVector &parts)\r\n{\r\n  UString result;\r\n  for(int i = 0; i < parts.Size(); i++)\r\n  {\r\n    if(i != 0)\r\n      result += wchar_t(NFile::NName::kDirDelimiter);\r\n    result += parts[i];\r\n  }\r\n  return result;\r\n}\r\n\r\n\r\nHRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)\r\n{\r\n  filetimeIsDefined = false;\r\n  NCOM::CPropVariant prop;\r\n  RINOK(_archiveHandler->GetProperty(index, propID, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n  {\r\n    filetime = prop.filetime;\r\n    filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  *outStream = 0;\r\n  _outFileStream.Release();\r\n\r\n  _encrypted = false;\r\n  _isSplit = false;\r\n  _curSize = 0;\r\n\r\n  UString fullPath;\r\n\r\n  RINOK(GetArchiveItemPath(_archiveHandler, index, _itemDefaultName, fullPath));\r\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDir));\r\n\r\n  _filePath = fullPath;\r\n\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidPosition, &prop));\r\n    if (prop.vt != VT_EMPTY)\r\n    {\r\n      if (prop.vt != VT_UI8)\r\n        return E_FAIL;\r\n      _position = prop.uhVal.QuadPart;\r\n      _isSplit = true;\r\n    }\r\n  }\r\n    \r\n  RINOK(IsArchiveItemProp(_archiveHandler, index, kpidEncrypted, _encrypted));\r\n\r\n  bool newFileSizeDefined;\r\n  UInt64 newFileSize;\r\n  {\r\n    NCOM::CPropVariant prop;\r\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\r\n    newFileSizeDefined = (prop.vt != VT_EMPTY);\r\n    if (newFileSizeDefined)\r\n    {\r\n      newFileSize = ConvertPropVariantToUInt64(prop);\r\n      _curSize = newFileSize;\r\n    }\r\n  }\r\n\r\n  if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)\r\n  {\r\n    if (_stdOutMode)\r\n    {\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc = new CStdOutFileStream;\r\n      *outStream = outStreamLoc.Detach();\r\n      return S_OK;\r\n    }\r\n\r\n    {\r\n      NCOM::CPropVariant prop;\r\n      RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\r\n      if (prop.vt == VT_EMPTY)\r\n      {\r\n        _processedFileInfo.Attributes = _attributesDefault;\r\n        _processedFileInfo.AttributesAreDefined = false;\r\n      }\r\n      else\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_FAIL;\r\n        _processedFileInfo.Attributes = prop.ulVal;\r\n        _processedFileInfo.AttributesAreDefined = true;\r\n      }\r\n    }\r\n\r\n    RINOK(GetTime(index, kpidCTime, _processedFileInfo.CTime, _processedFileInfo.CTimeDefined));\r\n    RINOK(GetTime(index, kpidATime, _processedFileInfo.ATime, _processedFileInfo.ATimeDefined));\r\n    RINOK(GetTime(index, kpidMTime, _processedFileInfo.MTime, _processedFileInfo.MTimeDefined));\r\n\r\n    bool isAnti = false;\r\n    RINOK(IsArchiveItemProp(_archiveHandler, index, kpidIsAnti, isAnti));\r\n\r\n    UStringVector pathParts;\r\n    SplitPathToParts(fullPath, pathParts);\r\n    \r\n    if(pathParts.IsEmpty())\r\n      return E_FAIL;\r\n    int numRemovePathParts = 0;\r\n    switch(_pathMode)\r\n    {\r\n      case NExtract::NPathMode::kFullPathnames:\r\n        break;\r\n      case NExtract::NPathMode::kCurrentPathnames:\r\n      {\r\n        numRemovePathParts = _removePathParts.Size();\r\n        if (pathParts.Size() <= numRemovePathParts)\r\n          return E_FAIL;\r\n        for (int i = 0; i < numRemovePathParts; i++)\r\n          if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0)\r\n            return E_FAIL;\r\n        break;\r\n      }\r\n      case NExtract::NPathMode::kNoPathnames:\r\n      {\r\n        numRemovePathParts = pathParts.Size() - 1;\r\n        break;\r\n      }\r\n    }\r\n    pathParts.Delete(0, numRemovePathParts);\r\n    MakeCorrectPath(pathParts);\r\n    UString processedPath = MakePathNameFromParts(pathParts);\r\n    if (!isAnti)\r\n    {\r\n      if (!_processedFileInfo.IsDir)\r\n      {\r\n        if (!pathParts.IsEmpty())\r\n          pathParts.DeleteBack();\r\n      }\r\n    \r\n      if (!pathParts.IsEmpty())\r\n      {\r\n        UString fullPathNew;\r\n        CreateComplexDirectory(pathParts, fullPathNew);\r\n        if (_processedFileInfo.IsDir)\r\n          NFile::NDirectory::SetDirTime(fullPathNew,\r\n            (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\r\n            (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\r\n            (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\r\n      }\r\n    }\r\n\r\n\r\n    UString fullProcessedPath = _directoryPath + processedPath;\r\n\r\n    if(_processedFileInfo.IsDir)\r\n    {\r\n      _diskFilePath = fullProcessedPath;\r\n      if (isAnti)\r\n        NFile::NDirectory::MyRemoveDirectory(_diskFilePath);\r\n      return S_OK;\r\n    }\r\n\r\n    if (!_isSplit)\r\n    {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\r\n    {\r\n      switch(_overwriteMode)\r\n      {\r\n        case NExtract::NOverwriteMode::kSkipExisting:\r\n          return S_OK;\r\n        case NExtract::NOverwriteMode::kAskBefore:\r\n        {\r\n          Int32 overwiteResult;\r\n          RINOK(_extractCallback2->AskOverwrite(\r\n              fullProcessedPath, &fileInfo.MTime, &fileInfo.Size, fullPath,\r\n              _processedFileInfo.MTimeDefined ? &_processedFileInfo.MTime : NULL,\r\n              newFileSizeDefined ? &newFileSize : NULL,\r\n              &overwiteResult))\r\n\r\n          switch(overwiteResult)\r\n          {\r\n            case NOverwriteAnswer::kCancel:\r\n              return E_ABORT;\r\n            case NOverwriteAnswer::kNo:\r\n              return S_OK;\r\n            case NOverwriteAnswer::kNoToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kSkipExisting;\r\n              return S_OK;\r\n            case NOverwriteAnswer::kYesToAll:\r\n              _overwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\r\n              break;\r\n            case NOverwriteAnswer::kYes:\r\n              break;\r\n            case NOverwriteAnswer::kAutoRename:\r\n              _overwriteMode = NExtract::NOverwriteMode::kAutoRename;\r\n              break;\r\n            default:\r\n              return E_FAIL;\r\n          }\r\n        }\r\n      }\r\n      if (_overwriteMode == NExtract::NOverwriteMode::kAutoRename)\r\n      {\r\n        if (!AutoRenamePath(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantAutoRename) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)\r\n      {\r\n        UString existPath = fullProcessedPath;\r\n        if (!AutoRenamePath(existPath))\r\n        {\r\n          UString message = kCantAutoRename + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n        if(!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))\r\n        {\r\n          UString message = UString(kCantRenameFile) + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return E_FAIL;\r\n        }\r\n      }\r\n      else\r\n        if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\r\n        {\r\n          UString message = UString(kCantDeleteOutputFile) +  fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n          // return E_FAIL;\r\n        }\r\n    }\r\n    }\r\n    if (!isAnti)\r\n    {\r\n      _outFileStreamSpec = new COutFileStream;\r\n      CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\r\n      if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))\r\n      {\r\n        // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)\r\n        {\r\n          UString message = L\"can not open output file \" + fullProcessedPath;\r\n          RINOK(_extractCallback2->MessageError(message));\r\n          return S_OK;\r\n        }\r\n      }\r\n      if (_isSplit)\r\n      {\r\n        RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));\r\n      }\r\n      _outFileStream = outStreamLoc;\r\n      *outStream = outStreamLoc.Detach();\r\n    }\r\n    _diskFilePath = fullProcessedPath;\r\n  }\r\n  else\r\n  {\r\n    *outStream = NULL;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\r\n{\r\n  COM_TRY_BEGIN\r\n  _extractMode = false;\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract:\r\n      _extractMode = true;\r\n  };\r\n  return _extractCallback2->PrepareOperation(_filePath, _processedFileInfo.IsDir,\r\n      askExtractMode, _isSplit ? &_position: 0);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n    case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n    case NArchive::NExtract::NOperationResult::kCRCError:\r\n    case NArchive::NExtract::NOperationResult::kDataError:\r\n      break;\r\n    default:\r\n      _outFileStream.Release();\r\n      return E_FAIL;\r\n  }\r\n  if (_outFileStream != NULL)\r\n  {\r\n    _outFileStreamSpec->SetTime(\r\n        (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\r\n        (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\r\n        (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\r\n    _curSize = _outFileStreamSpec->ProcessedSize;\r\n    RINOK(_outFileStreamSpec->Close());\r\n    _outFileStream.Release();\r\n  }\r\n  UnpackSize += _curSize;\r\n  if (_processedFileInfo.IsDir)\r\n    NumFolders++;\r\n  else\r\n    NumFiles++;\r\n\r\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\r\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\r\n  RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n/*\r\nSTDMETHODIMP CArchiveExtractCallback::GetInStream(\r\n    const wchar_t *name, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  CInFileStream *inFile = new CInFileStream;\r\n  CMyComPtr<ISequentialInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(_srcDirectoryPrefix + name))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (!_cryptoGetTextPassword)\r\n  {\r\n    RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword,\r\n        &_cryptoGetTextPassword));\r\n  }\r\n  return _cryptoGetTextPassword->CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ArchiveExtractCallback.h",
    "content": "// ArchiveExtractCallback.h\r\n\r\n#ifndef __ARCHIVEEXTRACTCALLBACK_H\r\n#define __ARCHIVEEXTRACTCALLBACK_H\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"IFileExtractCallback.h\"\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/ProgressUtils.h\"\r\n#include \"../../IPassword.h\"\r\n\r\n#include \"ExtractMode.h\"\r\n\r\nclass CArchiveExtractCallback:\r\n  public IArchiveExtractCallback,\r\n  // public IArchiveVolumeExtractCallback,\r\n  public ICryptoGetTextPassword,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP2(ICryptoGetTextPassword, ICompressProgressInfo)\r\n  // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)\r\n\r\n  INTERFACE_IArchiveExtractCallback(;)\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  // IArchiveVolumeExtractCallback\r\n  // STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);\r\n\r\n  // ICryptoGetTextPassword\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\r\n\r\nprivate:\r\n  CMyComPtr<IInArchive> _archiveHandler;\r\n  CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;\r\n  CMyComPtr<ICompressProgressInfo> _compressProgress;\r\n  CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;\r\n  UString _directoryPath;\r\n  NExtract::NPathMode::EEnum _pathMode;\r\n  NExtract::NOverwriteMode::EEnum _overwriteMode;\r\n\r\n  UString _filePath;\r\n  UInt64 _position;\r\n  bool _isSplit;\r\n\r\n  UString _diskFilePath;\r\n\r\n  bool _extractMode;\r\n\r\n  bool WriteCTime;\r\n  bool WriteATime;\r\n  bool WriteMTime;\r\n\r\n  bool _encrypted;\r\n\r\n  struct CProcessedFileInfo\r\n  {\r\n    FILETIME CTime;\r\n    FILETIME ATime;\r\n    FILETIME MTime;\r\n    UInt32 Attributes;\r\n  \r\n    bool CTimeDefined;\r\n    bool ATimeDefined;\r\n    bool MTimeDefined;\r\n\r\n    bool IsDir;\r\n    bool AttributesAreDefined;\r\n  } _processedFileInfo;\r\n\r\n  UInt64 _curSize;\r\n  COutFileStream *_outFileStreamSpec;\r\n  CMyComPtr<ISequentialOutStream> _outFileStream;\r\n  UStringVector _removePathParts;\r\n\r\n  UString _itemDefaultName;\r\n  FILETIME _utcMTimeDefault;\r\n  UInt32 _attributesDefault;\r\n  bool _stdOutMode;\r\n\r\n  void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);\r\n  HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);\r\npublic:\r\n  CArchiveExtractCallback():\r\n      WriteCTime(true),\r\n      WriteATime(true),\r\n      WriteMTime(true),\r\n      _multiArchives(false)\r\n  {\r\n    LocalProgressSpec = new CLocalProgress();\r\n    _localProgress = LocalProgressSpec;\r\n  }\r\n\r\n  CLocalProgress *LocalProgressSpec;\r\n  CMyComPtr<ICompressProgressInfo> _localProgress;\r\n  UInt64 _packTotal;\r\n  UInt64 _unpTotal;\r\n\r\n  bool _multiArchives;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  UInt64 UnpackSize;\r\n  \r\n  void InitForMulti(bool multiArchives,\r\n      NExtract::NPathMode::EEnum pathMode,\r\n      NExtract::NOverwriteMode::EEnum overwriteMode)\r\n  {\r\n    _multiArchives = multiArchives; NumFolders = NumFiles = UnpackSize = 0;\r\n    _pathMode = pathMode;\r\n    _overwriteMode = overwriteMode;\r\n  }\r\n\r\n  void Init(\r\n      IInArchive *archiveHandler,\r\n      IFolderArchiveExtractCallback *extractCallback2,\r\n      bool stdOutMode,\r\n      const UString &directoryPath,\r\n      const UStringVector &removePathParts,\r\n      const UString &itemDefaultName,\r\n      const FILETIME &utcMTimeDefault,\r\n      UInt32 attributesDefault,\r\n      UInt64 packSize);\r\n\r\n  UInt64 _numErrors;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ArchiveName.cpp",
    "content": "// ArchiveName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)\r\n{\r\n  UString resultName = L\"Archive\";\r\n  if (fromPrev)\r\n  {\r\n    UString dirPrefix;\r\n    if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))\r\n    {\r\n      if (dirPrefix.Length() > 0)\r\n        if (dirPrefix[dirPrefix.Length() - 1] == WCHAR_PATH_SEPARATOR)\r\n        {\r\n          dirPrefix.Delete(dirPrefix.Length() - 1);\r\n          NFile::NFind::CFileInfoW fileInfo;\r\n          if (NFile::NFind::FindFile(dirPrefix, fileInfo))\r\n            resultName = fileInfo.Name;\r\n        }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    NFile::NFind::CFileInfoW fileInfo;\r\n    if (!NFile::NFind::FindFile(srcName, fileInfo))\r\n      return resultName;\r\n    resultName = fileInfo.Name;\r\n    if (!fileInfo.IsDir() && !keepName)\r\n    {\r\n      int dotPos = resultName.ReverseFind('.');\r\n      if (dotPos > 0)\r\n      {\r\n        UString archiveName2 = resultName.Left(dotPos);\r\n        if (archiveName2.ReverseFind('.') < 0)\r\n          resultName = archiveName2;\r\n      }\r\n    }\r\n  }\r\n  return resultName;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ArchiveName.h",
    "content": "// ArchiveName.h\r\n\r\n#ifndef __ARCHIVENAME_H\r\n#define __ARCHIVENAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp",
    "content": "// ArchiveOpenCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/ComTry.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n    return ReOpenCallback->SetTotal(files, bytes);\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->Open_SetTotal(files, bytes);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n    return ReOpenCallback->SetCompleted(files, bytes);\r\n  if (!Callback)\r\n    return S_OK;\r\n  return Callback->Open_SetCompleted(files, bytes);\r\n  COM_TRY_END\r\n}\r\n  \r\nSTDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  NCOM::CPropVariant prop;\r\n  if (_subArchiveMode)\r\n    switch(propID)\r\n    {\r\n      case kpidName: prop = _subArchiveName; break;\r\n    }\r\n  else\r\n    switch(propID)\r\n    {\r\n      case kpidName:  prop = _fileInfo.Name; break;\r\n      case kpidIsDir:  prop = _fileInfo.IsDir(); break;\r\n      case kpidSize:  prop = _fileInfo.Size; break;\r\n      case kpidAttrib:  prop = (UInt32)_fileInfo.Attrib; break;\r\n      case kpidCTime:  prop = _fileInfo.CTime; break;\r\n      case kpidATime:  prop = _fileInfo.ATime; break;\r\n      case kpidMTime:  prop = _fileInfo.MTime; break;\r\n    }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nint COpenCallbackImp::FindName(const UString &name)\r\n{\r\n  for (int i = 0; i < FileNames.Size(); i++)\r\n    if (name.CompareNoCase(FileNames[i]) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nstruct CInFileStreamVol: public CInFileStream\r\n{\r\n  UString Name;\r\n  COpenCallbackImp *OpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;\r\n  ~CInFileStreamVol()\r\n  {\r\n    int index = OpenCallbackImp->FindName(Name);\r\n    if (index >= 0)\r\n      OpenCallbackImp->FileNames.Delete(index);\r\n  }\r\n};\r\n\r\nSTDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (_subArchiveMode)\r\n    return S_FALSE;\r\n  if (Callback)\r\n  {\r\n    RINOK(Callback->Open_CheckBreak());\r\n  }\r\n  *inStream = NULL;\r\n  UString fullPath = _folderPrefix + name;\r\n  if (!NFile::NFind::FindFile(fullPath, _fileInfo))\r\n    return S_FALSE;\r\n  if (_fileInfo.IsDir())\r\n    return S_FALSE;\r\n  CInFileStreamVol *inFile = new CInFileStreamVol;\r\n  CMyComPtr<IInStream> inStreamTemp = inFile;\r\n  if (!inFile->Open(fullPath))\r\n    return ::GetLastError();\r\n  *inStream = inStreamTemp.Detach();\r\n  inFile->Name = name;\r\n  inFile->OpenCallbackImp = this;\r\n  inFile->OpenCallbackRef = this;\r\n  FileNames.Add(name);\r\n  TotalSize += _fileInfo.Size;\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\nSTDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  if (ReOpenCallback)\r\n  {\r\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\r\n    ReOpenCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\r\n    if (getTextPassword)\r\n      return getTextPassword->CryptoGetTextPassword(password);\r\n  }\r\n  if (!Callback)\r\n    return E_NOTIMPL;\r\n  return Callback->Open_CryptoGetTextPassword(password);\r\n  COM_TRY_END\r\n}\r\n#endif\r\n  \r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ArchiveOpenCallback.h",
    "content": "// ArchiveOpenCallback.h\r\n\r\n#ifndef __ARCHIVE_OPEN_CALLBACK_H\r\n#define __ARCHIVE_OPEN_CALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/MyCom.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#ifndef _NO_CRYPTO\r\n#include \"../../IPassword.h\"\r\n#endif\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#ifdef _NO_CRYPTO\r\n\r\n#define INTERFACE_IOpenCallbackUI_Crypto(x)\r\n\r\n#else\r\n\r\n#define INTERFACE_IOpenCallbackUI_Crypto(x) \\\r\n  virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x; \\\r\n  virtual HRESULT Open_GetPasswordIfAny(UString &password) x; \\\r\n  virtual bool Open_WasPasswordAsked() x; \\\r\n  virtual void Open_ClearPasswordWasAskedFlag() x; \\\r\n  \r\n#endif\r\n\r\n#define INTERFACE_IOpenCallbackUI(x) \\\r\n  virtual HRESULT Open_CheckBreak() x; \\\r\n  virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) x; \\\r\n  INTERFACE_IOpenCallbackUI_Crypto(x)\r\n\r\nstruct IOpenCallbackUI\r\n{\r\n  INTERFACE_IOpenCallbackUI(=0)\r\n};\r\n\r\nclass COpenCallbackImp:\r\n  public IArchiveOpenCallback,\r\n  public IArchiveOpenVolumeCallback,\r\n  public IArchiveOpenSetSubArchiveName,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifndef _NO_CRYPTO\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveOpenVolumeCallback,\r\n      ICryptoGetTextPassword,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #else\r\n  MY_UNKNOWN_IMP2(\r\n      IArchiveOpenVolumeCallback,\r\n      IArchiveOpenSetSubArchiveName\r\n      )\r\n  #endif\r\n\r\n  INTERFACE_IArchiveOpenCallback(;)\r\n  INTERFACE_IArchiveOpenVolumeCallback(;)\r\n\r\n  #ifndef _NO_CRYPTO\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n  #endif\r\n\r\n  STDMETHOD(SetSubArchiveName(const wchar_t *name))\r\n  {\r\n    _subArchiveMode = true;\r\n    _subArchiveName = name;\r\n    return  S_OK;\r\n  }\r\n\r\nprivate:\r\n  UString _folderPrefix;\r\n  NWindows::NFile::NFind::CFileInfoW _fileInfo;\r\n  bool _subArchiveMode;\r\n  UString _subArchiveName;\r\npublic:\r\n  UStringVector FileNames;\r\n  IOpenCallbackUI *Callback;\r\n  CMyComPtr<IArchiveOpenCallback> ReOpenCallback;\r\n  UInt64 TotalSize;\r\n\r\n  COpenCallbackImp(): Callback(NULL) {}\r\n  void Init(const UString &folderPrefix,  const UString &fileName)\r\n  {\r\n    _folderPrefix = folderPrefix;\r\n    if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))\r\n      throw 1;\r\n    FileNames.Clear();\r\n    _subArchiveMode = false;\r\n    TotalSize = 0;\r\n  }\r\n  int FindName(const UString &name);\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/DefaultName.cpp",
    "content": "// DefaultName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nstatic UString GetDefaultName3(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  int extLength = extension.Length();\r\n  int fileNameLength = fileName.Length();\r\n  if (fileNameLength > extLength + 1)\r\n  {\r\n    int dotPos = fileNameLength - (extLength + 1);\r\n    if (fileName[dotPos] == '.')\r\n      if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)\r\n        return fileName.Left(dotPos) + addSubExtension;\r\n  }\r\n  int dotPos = fileName.ReverseFind(L'.');\r\n  if (dotPos > 0)\r\n    return fileName.Left(dotPos) + addSubExtension;\r\n\r\n  if (addSubExtension.IsEmpty())\r\n    return fileName + L\"~\";\r\n  else\r\n    return fileName + addSubExtension;\r\n}\r\n\r\nUString GetDefaultName2(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension)\r\n{\r\n  UString name = GetDefaultName3(fileName, extension, addSubExtension);\r\n  name.TrimRight();\r\n  return name;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/DefaultName.h",
    "content": "// DefaultName.h\r\n\r\n#ifndef __DEFAULTNAME_H\r\n#define __DEFAULTNAME_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString GetDefaultName2(const UString &fileName,\r\n    const UString &extension, const UString &addSubExtension);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/DirItem.h",
    "content": "// DirItem.h\r\n\r\n#ifndef __DIR_ITEM_H\r\n#define __DIR_ITEM_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CDirItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  UInt32 Attrib;\r\n  int PhyParent;\r\n  int LogParent;\r\n  \r\n  CDirItem(): PhyParent(-1), LogParent(-1) {}\r\n  bool IsDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\r\n};\r\n\r\nclass CDirItems\r\n{\r\n  UStringVector Prefixes;\r\n  CIntVector PhyParents;\r\n  CIntVector LogParents;\r\n\r\n  UString GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const;\r\npublic:\r\n  CObjectVector<CDirItem> Items;\r\n\r\n  int GetNumFolders() const { return Prefixes.Size(); }\r\n  UString GetPhyPath(int index) const;\r\n  UString GetLogPath(int index) const;\r\n\r\n  int AddPrefix(int phyParent, int logParent, const UString &prefix);\r\n  void DeleteLastPrefix();\r\n\r\n  void EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\r\n\r\n  void EnumerateDirItems2(\r\n    const UString &phyPrefix,\r\n    const UString &logPrefix,\r\n    const UStringVector &filePaths,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\r\n\r\n  void ReserveDown();\r\n};\r\n\r\nstruct CArcItem\r\n{\r\n  UInt64 Size;\r\n  FILETIME MTime;\r\n  UString Name;\r\n  bool IsDir;\r\n  bool SizeDefined;\r\n  bool Censored;\r\n  UInt32 IndexInServer;\r\n  int TimeType;\r\n  \r\n  CArcItem(): IsDir(false), SizeDefined(false), Censored(false), TimeType(-1) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/EnumDirItems.cpp",
    "content": "// EnumDirItems.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nvoid AddDirFileInfo(int phyParent, int logParent,\r\n    const NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems)\r\n{\r\n  CDirItem di;\r\n  di.Size = fi.Size;\r\n  di.CTime = fi.CTime;\r\n  di.ATime = fi.ATime;\r\n  di.MTime = fi.MTime;\r\n  di.Attrib = fi.Attrib;\r\n  di.PhyParent = phyParent;\r\n  di.LogParent = logParent;\r\n  di.Name = fi.Name;\r\n  dirItems.Add(di);\r\n}\r\n\r\nUString CDirItems::GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const\r\n{\r\n  UString path;\r\n  int len = name.Length();\r\n  int i;\r\n  for (i = index; i >= 0; i = parents[i])\r\n    len += Prefixes[i].Length();\r\n  int totalLen = len;\r\n  wchar_t *p = path.GetBuffer(len);\r\n  p[len] = 0;\r\n  len -= name.Length();\r\n  memcpy(p + len, (const wchar_t *)name, name.Length() * sizeof(wchar_t));\r\n  for (i = index; i >= 0; i = parents[i])\r\n  {\r\n    const UString &s = Prefixes[i];\r\n    len -= s.Length();\r\n    memcpy(p + len, (const wchar_t *)s, s.Length() * sizeof(wchar_t));\r\n  }\r\n  path.ReleaseBuffer(totalLen);\r\n  return path;\r\n}\r\n\r\nUString CDirItems::GetPhyPath(int index) const\r\n{\r\n  const CDirItem &di = Items[index];\r\n  return GetPrefixesPath(PhyParents, di.PhyParent, di.Name);\r\n}\r\n\r\nUString CDirItems::GetLogPath(int index) const\r\n{\r\n  const CDirItem &di = Items[index];\r\n  return GetPrefixesPath(LogParents, di.LogParent, di.Name);\r\n}\r\n\r\nvoid CDirItems::ReserveDown()\r\n{\r\n  Prefixes.ReserveDown();\r\n  PhyParents.ReserveDown();\r\n  LogParents.ReserveDown();\r\n  Items.ReserveDown();\r\n}\r\n\r\nint CDirItems::AddPrefix(int phyParent, int logParent, const UString &prefix)\r\n{\r\n  PhyParents.Add(phyParent);\r\n  LogParents.Add(logParent);\r\n  return Prefixes.Add(prefix);\r\n}\r\n\r\nvoid CDirItems::DeleteLastPrefix()\r\n{\r\n  PhyParents.DeleteBack();\r\n  LogParents.DeleteBack();\r\n  Prefixes.DeleteBack();\r\n}\r\n\r\nvoid CDirItems::EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\r\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\r\n{\r\n  NFind::CEnumeratorW enumerator(phyPrefix + (wchar_t)kAnyStringWildcard);\r\n  for (;;)\r\n  {\r\n    NFind::CFileInfoW fi;\r\n    bool found;\r\n    if (!enumerator.Next(fi, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPrefix);\r\n      return;\r\n    }\r\n    if (!found)\r\n      break;\r\n    AddDirFileInfo(phyParent, logParent, fi, Items);\r\n    if (fi.IsDir())\r\n    {\r\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\r\n      int parent = AddPrefix(phyParent, logParent, name2);\r\n      EnumerateDirectory(parent, parent, phyPrefix + name2, errorPaths, errorCodes);\r\n    }\r\n  }\r\n}\r\n\r\nvoid CDirItems::EnumerateDirItems2(const UString &phyPrefix, const UString &logPrefix,\r\n    const UStringVector &filePaths, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\r\n{\r\n  int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, phyPrefix);\r\n  int logParent = logPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, logPrefix);\r\n\r\n  for (int i = 0; i < filePaths.Size(); i++)\r\n  {\r\n    const UString &filePath = filePaths[i];\r\n    NFind::CFileInfoW fi;\r\n    const UString phyPath = phyPrefix + filePath;\r\n    if (!NFind::FindFile(phyPath, fi))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPath);\r\n      continue;\r\n    }\r\n    int delimiter = filePath.ReverseFind((wchar_t)kDirDelimiter);\r\n    UString phyPrefixCur;\r\n    int phyParentCur = phyParent;\r\n    if (delimiter >= 0)\r\n    {\r\n      phyPrefixCur = filePath.Left(delimiter + 1);\r\n      phyParentCur = AddPrefix(phyParent, logParent, phyPrefixCur);\r\n    }\r\n    AddDirFileInfo(phyParentCur, logParent, fi, Items);\r\n    if (fi.IsDir())\r\n    {\r\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\r\n      int parent = AddPrefix(phyParentCur, logParent, name2);\r\n      EnumerateDirectory(parent, parent, phyPrefix + phyPrefixCur + name2, errorPaths, errorCodes);\r\n    }\r\n  }\r\n  ReserveDown();\r\n}\r\n\r\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\nstatic HRESULT EnumerateDirItems_Spec(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &curFolderName,\r\n    const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n  \r\n{\r\n  const UString name2 = curFolderName + (wchar_t)kDirDelimiter;\r\n  int parent = dirItems.AddPrefix(phyParent, logParent, name2);\r\n  int numItems = dirItems.Items.Size();\r\n  HRESULT res = EnumerateDirItems(curNode, parent, parent, phyPrefix + name2,\r\n    addArchivePrefix, dirItems, enterToSubFolders, callback, errorPaths, errorCodes);\r\n  if (numItems == dirItems.Items.Size())\r\n    dirItems.DeleteLastPrefix();\r\n  return res;\r\n}\r\n\r\n\r\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\r\n    int phyParent, int logParent, const UString &phyPrefix,\r\n    const UStringVector &addArchivePrefix,  // prefix from curNode\r\n    CDirItems &dirItems,\r\n    bool enterToSubFolders,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  if (!enterToSubFolders)\r\n    if (curNode.NeedCheckSubDirs())\r\n      enterToSubFolders = true;\r\n  if (callback)\r\n    RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\r\n\r\n  // try direct_names case at first\r\n  if (addArchivePrefix.IsEmpty() && !enterToSubFolders)\r\n  {\r\n    // check that all names are direct\r\n    int i;\r\n    for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n    {\r\n      const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n      if (item.Recursive || item.PathParts.Size() != 1)\r\n        break;\r\n      const UString &name = item.PathParts.Front();\r\n      if (name.IsEmpty() || DoesNameContainWildCard(name))\r\n        break;\r\n    }\r\n    if (i == curNode.IncludeItems.Size())\r\n    {\r\n      // all names are direct (no wildcards)\r\n      // so we don't need file_system's dir enumerator\r\n      CRecordVector<bool> needEnterVector;\r\n      for (i = 0; i < curNode.IncludeItems.Size(); i++)\r\n      {\r\n        const NWildcard::CItem &item = curNode.IncludeItems[i];\r\n        const UString &name = item.PathParts.Front();\r\n        const UString fullPath = phyPrefix + name;\r\n        NFind::CFileInfoW fi;\r\n        if (!NFind::FindFile(fullPath, fi))\r\n        {\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        bool isDir = fi.IsDir();\r\n        if (isDir && !item.ForDir || !isDir && !item.ForFile)\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        {\r\n          UStringVector pathParts;\r\n          pathParts.Add(fi.Name);\r\n          if (curNode.CheckPathToRoot(false, pathParts, !isDir))\r\n            continue;\r\n        }\r\n        AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\r\n        if (!isDir)\r\n          continue;\r\n        \r\n        UStringVector addArchivePrefixNew;\r\n        const NWildcard::CCensorNode *nextNode = 0;\r\n        int index = curNode.FindSubNode(name);\r\n        if (index >= 0)\r\n        {\r\n          for (int t = needEnterVector.Size(); t <= index; t++)\r\n            needEnterVector.Add(true);\r\n          needEnterVector[index] = false;\r\n          nextNode = &curNode.SubNodes[index];\r\n        }\r\n        else\r\n        {\r\n          nextNode = &curNode;\r\n          addArchivePrefixNew.Add(name); // don't change it to fi.Name. It's for shortnames support\r\n        }\r\n\r\n        RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix,\r\n            addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes));\r\n      }\r\n      for (i = 0; i < curNode.SubNodes.Size(); i++)\r\n      {\r\n        if (i < needEnterVector.Size())\r\n          if (!needEnterVector[i])\r\n            continue;\r\n        const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];\r\n        const UString fullPath = phyPrefix + nextNode.Name;\r\n        NFind::CFileInfoW fi;\r\n        if (!NFind::FindFile(fullPath, fi))\r\n        {\r\n          if (!nextNode.AreThereIncludeItems())\r\n            continue;\r\n          errorCodes.Add(::GetLastError());\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n        if (!fi.IsDir())\r\n        {\r\n          errorCodes.Add((DWORD)E_FAIL);\r\n          errorPaths.Add(fullPath);\r\n          continue;\r\n        }\r\n\r\n        RINOK(EnumerateDirItems_Spec(nextNode, phyParent, logParent, fi.Name, phyPrefix,\r\n            UStringVector(), dirItems, false, callback, errorPaths, errorCodes));\r\n      }\r\n      return S_OK;\r\n    }\r\n  }\r\n\r\n\r\n  NFind::CEnumeratorW enumerator(phyPrefix + wchar_t(kAnyStringWildcard));\r\n  for (int ttt = 0; ; ttt++)\r\n  {\r\n    NFind::CFileInfoW fi;\r\n    bool found;\r\n    if (!enumerator.Next(fi, found))\r\n    {\r\n      errorCodes.Add(::GetLastError());\r\n      errorPaths.Add(phyPrefix);\r\n      break;\r\n    }\r\n    if (!found)\r\n      break;\r\n\r\n    if (callback && (ttt & 0xFF) == 0xFF)\r\n      RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\r\n    const UString &name = fi.Name;\r\n    bool enterToSubFolders2 = enterToSubFolders;\r\n    UStringVector addArchivePrefixNew = addArchivePrefix;\r\n    addArchivePrefixNew.Add(name);\r\n    {\r\n      UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);\r\n      if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fi.IsDir()))\r\n        continue;\r\n    }\r\n    if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir()))\r\n    {\r\n      AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\r\n      if (fi.IsDir())\r\n        enterToSubFolders2 = true;\r\n    }\r\n    if (!fi.IsDir())\r\n      continue;\r\n\r\n    const NWildcard::CCensorNode *nextNode = 0;\r\n    if (addArchivePrefix.IsEmpty())\r\n    {\r\n      int index = curNode.FindSubNode(name);\r\n      if (index >= 0)\r\n        nextNode = &curNode.SubNodes[index];\r\n    }\r\n    if (!enterToSubFolders2 && nextNode == 0)\r\n      continue;\r\n\r\n    addArchivePrefixNew = addArchivePrefix;\r\n    if (nextNode == 0)\r\n    {\r\n      nextNode = &curNode;\r\n      addArchivePrefixNew.Add(name);\r\n    }\r\n\r\n    RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, name, phyPrefix,\r\n        addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor,\r\n    CDirItems &dirItems,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes)\r\n{\r\n  for (int i = 0; i < censor.Pairs.Size(); i++)\r\n  {\r\n    const NWildcard::CPair &pair = censor.Pairs[i];\r\n    int phyParent = pair.Prefix.IsEmpty() ? -1 : dirItems.AddPrefix(-1, -1, pair.Prefix);\r\n    RINOK(EnumerateDirItems(pair.Head, phyParent, -1, pair.Prefix, UStringVector(), dirItems, false,\r\n        callback, errorPaths, errorCodes));\r\n  }\r\n  dirItems.ReserveDown();\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/EnumDirItems.h",
    "content": "// EnumDirItems.h\r\n\r\n#ifndef __ENUM_DIR_ITEMS_H\r\n#define __ENUM_DIR_ITEMS_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"DirItem.h\"\r\n\r\nvoid AddDirFileInfo(int phyParent, int logParent,\r\n    const NWindows::NFile::NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems);\r\n\r\nstruct IEnumDirItemCallback\r\n{\r\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) = 0;\r\n};\r\n\r\nHRESULT EnumerateItems(\r\n    const NWildcard::CCensor &censor,\r\n    CDirItems &dirItems,\r\n    IEnumDirItemCallback *callback,\r\n    UStringVector &errorPaths,\r\n    CRecordVector<DWORD> &errorCodes);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ExitCode.h",
    "content": "// ExitCode.h\r\n\r\n#ifndef __EXIT_CODE_H\r\n#define __EXIT_CODE_H\r\n\r\nnamespace NExitCode {\r\n\r\nenum EEnum {\r\n\r\n  kSuccess       = 0,     // Successful operation\r\n  kWarning       = 1,     // Non fatal error(s) occurred\r\n  kFatalError    = 2,     // A fatal error occurred\r\n  // kCRCError      = 3,     // A CRC error occurred when unpacking\r\n  // kLockedArchive = 4,     // Attempt to modify an archive previously locked\r\n  // kWriteError    = 5,     // Write to disk error\r\n  // kOpenError     = 6,     // Open file error\r\n  kUserError     = 7,     // Command line option error\r\n  kMemoryError   = 8,     // Not enough memory for operation\r\n  // kCreateFileError = 9,     // Create file error\r\n  \r\n  kUserBreak     = 255   // User stopped the process\r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/Extract.cpp",
    "content": "// Extract.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Extract.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n#include \"SetProperties.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic HRESULT DecompressArchive(\r\n    IInArchive *archive,\r\n    UInt64 packSize,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IExtractCallbackUI *callback,\r\n    CArchiveExtractCallback *extractCallbackSpec,\r\n    UString &errorMessage)\r\n{\r\n  CRecordVector<UInt32> realIndices;\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n\r\n  for(UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UString filePath;\r\n    RINOK(GetArchiveItemPath(archive, i, options.DefaultItemName, filePath));\r\n    bool isFolder;\r\n    RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n    if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n      continue;\r\n    realIndices.Add(i);\r\n  }\r\n  if (realIndices.Size() == 0)\r\n  {\r\n    callback->ThereAreNoFiles();\r\n    return S_OK;\r\n  }\r\n\r\n  UStringVector removePathParts;\r\n\r\n  UString outDir = options.OutputDir;\r\n  outDir.Replace(L\"*\", options.DefaultItemName);\r\n  #ifdef _WIN32\r\n  outDir.TrimRight();\r\n  #endif\r\n\r\n  if(!outDir.IsEmpty())\r\n    if(!NFile::NDirectory::CreateComplexDirectory(outDir))\r\n    {\r\n      HRESULT res = ::GetLastError();\r\n      if (res == S_OK)\r\n        res = E_FAIL;\r\n      errorMessage = ((UString)L\"Can not create output directory \") + outDir;\r\n      return res;\r\n    }\r\n\r\n  extractCallbackSpec->Init(\r\n      archive,\r\n      callback,\r\n      options.StdOutMode,\r\n      outDir,\r\n      removePathParts,\r\n      options.DefaultItemName,\r\n      options.ArchiveFileInfo.MTime,\r\n      options.ArchiveFileInfo.Attrib,\r\n      packSize);\r\n\r\n  #ifdef COMPRESS_MT\r\n  RINOK(SetProperties(archive, options.Properties));\r\n  #endif\r\n\r\n  HRESULT result = archive->Extract(&realIndices.Front(),\r\n    realIndices.Size(), options.TestMode? 1: 0, extractCallbackSpec);\r\n\r\n  return callback->ExtractResult(result);\r\n}\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &optionsSpec,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage,\r\n    CDecompressStat &stat)\r\n{\r\n  stat.Clear();\r\n  CExtractOptions options = optionsSpec;\r\n  int i;\r\n  UInt64 totalPackSize = 0;\r\n  CRecordVector<UInt64> archiveSizes;\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archivePath, fi))\r\n      throw \"there is no such archive\";\r\n    if (fi.IsDir())\r\n      throw \"can't decompress folder\";\r\n    archiveSizes.Add(fi.Size);\r\n    totalPackSize += fi.Size;\r\n  }\r\n  CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\r\n  CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);\r\n  bool multi = (archivePaths.Size() > 1);\r\n  extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);\r\n  if (multi)\r\n  {\r\n    RINOK(extractCallback->SetTotal(totalPackSize));\r\n  }\r\n  for (i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archivePath = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archivePath, fi))\r\n      throw \"there is no such archive\";\r\n\r\n    if (fi.IsDir())\r\n      throw \"there is no such archive\";\r\n\r\n    options.ArchiveFileInfo = fi;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    openCallback->Open_ClearPasswordWasAskedFlag();\r\n    #endif\r\n\r\n    RINOK(extractCallback->BeforeOpen(archivePath));\r\n    CArchiveLink archiveLink;\r\n\r\n    CIntVector formatIndices2 = formatIndices;\r\n    #ifndef _SFX\r\n    if (formatIndices.IsEmpty())\r\n    {\r\n      int pos = archivePath.ReverseFind(L'.');\r\n      if (pos >= 0)\r\n      {\r\n        UString s = archivePath.Mid(pos + 1);\r\n        int index = codecs->FindFormatForExtension(s);\r\n        if (index >= 0 && s == L\"001\")\r\n        {\r\n          s = archivePath.Left(pos);\r\n          pos = s.ReverseFind(L'.');\r\n          if (pos >= 0)\r\n          {\r\n            int index2 = codecs->FindFormatForExtension(s.Mid(pos + 1));\r\n            if (index2 >= 0 && s.CompareNoCase(L\"rar\") != 0)\r\n            {\r\n              formatIndices2.Add(index2);\r\n              formatIndices2.Add(index);\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n    #endif\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices2, archivePath, archiveLink, openCallback);\r\n    if (result == E_ABORT)\r\n      return result;\r\n\r\n    bool crypted = false;\r\n    #ifndef _NO_CRYPTO\r\n    crypted = openCallback->Open_WasPasswordAsked();\r\n    #endif\r\n\r\n    RINOK(extractCallback->OpenResult(archivePath, result, crypted));\r\n    if (result != S_OK)\r\n      continue;\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n        totalPackSize -= archiveSizes[index];\r\n        archiveSizes.Delete(index);\r\n      }\r\n    }\r\n    if (archiveLink.VolumePaths.Size() != 0)\r\n    {\r\n      totalPackSize += archiveLink.VolumesSize;\r\n      RINOK(extractCallback->SetTotal(totalPackSize));\r\n    }\r\n\r\n    #ifndef _NO_CRYPTO\r\n    UString password;\r\n    RINOK(openCallback->Open_GetPasswordIfAny(password));\r\n    if (!password.IsEmpty())\r\n    {\r\n      RINOK(extractCallback->SetPassword(password));\r\n    }\r\n    #endif\r\n\r\n    options.DefaultItemName = archiveLink.GetDefaultItemName();\r\n    RINOK(DecompressArchive(\r\n        archiveLink.GetArchive(),\r\n        fi.Size + archiveLink.VolumesSize,\r\n        wildcardCensor, options, extractCallback, extractCallbackSpec, errorMessage));\r\n    extractCallbackSpec->LocalProgressSpec->InSize += fi.Size +\r\n        archiveLink.VolumesSize;\r\n    extractCallbackSpec->LocalProgressSpec->OutSize = extractCallbackSpec->UnpackSize;\r\n    if (!errorMessage.IsEmpty())\r\n      return E_FAIL;\r\n  }\r\n  stat.NumFolders = extractCallbackSpec->NumFolders;\r\n  stat.NumFiles = extractCallbackSpec->NumFiles;\r\n  stat.UnpackSize = extractCallbackSpec->UnpackSize;\r\n  stat.NumArchives = archivePaths.Size();\r\n  stat.PackSize = extractCallbackSpec->LocalProgressSpec->InSize;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/Extract.h",
    "content": "// Extract.h\r\n\r\n#ifndef __EXTRACT_H\r\n#define __EXTRACT_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"ArchiveExtractCallback.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"ExtractMode.h\"\r\n#include \"Property.h\"\r\n\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nclass CExtractOptions\r\n{\r\npublic:\r\n  bool StdOutMode;\r\n  bool TestMode;\r\n  NExtract::NPathMode::EEnum PathMode;\r\n\r\n  UString OutputDir;\r\n  bool YesToAll;\r\n  UString DefaultItemName;\r\n  NWindows::NFile::NFind::CFileInfoW ArchiveFileInfo;\r\n  \r\n  // bool ShowDialog;\r\n  // bool PasswordEnabled;\r\n  // UString Password;\r\n  #ifdef COMPRESS_MT\r\n  CObjectVector<CProperty> Properties;\r\n  #endif\r\n\r\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  CCodecs *Codecs;\r\n  #endif\r\n\r\n  CExtractOptions():\r\n      StdOutMode(false),\r\n      YesToAll(false),\r\n      TestMode(false),\r\n      PathMode(NExtract::NPathMode::kFullPathnames),\r\n      OverwriteMode(NExtract::NOverwriteMode::kAskBefore)\r\n      {}\r\n\r\n  /*\r\n    bool FullPathMode() const { return (ExtractMode == NExtractMode::kTest) ||\r\n    (ExtractMode == NExtractMode::kFullPath); }\r\n  */\r\n};\r\n\r\nstruct CDecompressStat\r\n{\r\n  UInt64 NumArchives;\r\n  UInt64 UnpackSize;\r\n  UInt64 PackSize;\r\n  UInt64 NumFolders;\r\n  UInt64 NumFiles;\r\n  void Clear() { NumArchives = PackSize = UnpackSize = NumFolders = NumFiles = 0; }\r\n};\r\n\r\nHRESULT DecompressArchives(\r\n    CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    const CExtractOptions &options,\r\n    IOpenCallbackUI *openCallback,\r\n    IExtractCallbackUI *extractCallback,\r\n    UString &errorMessage,\r\n    CDecompressStat &stat);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ExtractMode.h",
    "content": "// ExtractMode.h\r\n\r\n#ifndef __EXTRACT_MODE_H\r\n#define __EXTRACT_MODE_H\r\n\r\nnamespace NExtract {\r\n  \r\n  namespace NPathMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kFullPathnames,\r\n      kCurrentPathnames,\r\n      kNoPathnames\r\n    };\r\n  }\r\n  \r\n  namespace NOverwriteMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kAskBefore,\r\n      kWithoutPrompt,\r\n      kSkipExisting,\r\n      kAutoRename,\r\n      kAutoRenameExisting\r\n    };\r\n  }\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ExtractingFilePath.cpp",
    "content": "// ExtractingFilePath.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ExtractingFilePath.h\"\r\n\r\nstatic UString ReplaceIncorrectChars(const UString &s)\r\n{\r\n  #ifdef _WIN32\r\n  UString res;\r\n  for (int i = 0; i < s.Length(); i++)\r\n  {\r\n    wchar_t c = s[i];\r\n    if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>'  || c == '|' || c == ':' || c == '\"')\r\n      c = '_';\r\n    res += c;\r\n  }\r\n  res.TrimRight();\r\n  return res;\r\n  #else\r\n  return s;\r\n  #endif\r\n}\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t *g_ReservedNames[] =\r\n{\r\n  L\"CON\", L\"PRN\", L\"AUX\", L\"NUL\"\r\n};\r\n\r\nstatic bool CheckTail(const UString &name, int len)\r\n{\r\n  int dotPos = name.Find(L'.');\r\n  if (dotPos < 0)\r\n    dotPos = name.Length();\r\n  UString s = name.Left(dotPos);\r\n  s.TrimRight();\r\n  return (s.Length() != len);\r\n}\r\n\r\nstatic bool CheckNameNum(const UString &name, const wchar_t *reservedName)\r\n{\r\n  int len = MyStringLen(reservedName);\r\n  if (name.Length() <= len)\r\n    return true;\r\n  if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n    return true;\r\n  wchar_t c = name[len];\r\n  if (c < L'0' || c > L'9')\r\n    return true;\r\n  return CheckTail(name, len + 1);\r\n}\r\n\r\nstatic bool IsSupportedName(const UString &name)\r\n{\r\n  for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++)\r\n  {\r\n    const wchar_t *reservedName = g_ReservedNames[i];\r\n    int len = MyStringLen(reservedName);\r\n    if (name.Length() < len)\r\n      continue;\r\n    if (name.Left(len).CompareNoCase(reservedName) != 0)\r\n      continue;\r\n    if (!CheckTail(name, len))\r\n      return false;\r\n  }\r\n  if (!CheckNameNum(name, L\"COM\"))\r\n    return false;\r\n  return CheckNameNum(name, L\"LPT\");\r\n}\r\n#endif\r\n\r\nstatic UString GetCorrectFileName(const UString &path)\r\n{\r\n  if (path == L\"..\" || path == L\".\")\r\n    return UString();\r\n  return ReplaceIncorrectChars(path);\r\n}\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts)\r\n{\r\n  for (int i = 0; i < pathParts.Size();)\r\n  {\r\n    UString &s = pathParts[i];\r\n    s = GetCorrectFileName(s);\r\n    if (s.IsEmpty())\r\n      pathParts.Delete(i);\r\n    else\r\n    {\r\n      #ifdef _WIN32\r\n      if (!IsSupportedName(s))\r\n        s = (UString)L\"_\" + s;\r\n      #endif\r\n      i++;\r\n    }\r\n  }\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ExtractingFilePath.h",
    "content": "// ExtractingFilePath.h\r\n\r\n#ifndef __EXTRACTINGFILEPATH_H\r\n#define __EXTRACTINGFILEPATH_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid MakeCorrectPath(UStringVector &pathParts);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/IFileExtractCallback.h",
    "content": "// IFileExtractCallback.h\r\n\r\n#ifndef __IFILEEXTRACTCALLBACK_H\r\n#define __IFILEEXTRACTCALLBACK_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"../../IDecl.h\"\r\n\r\nnamespace NOverwriteAnswer\r\n{\r\n  enum EEnum\r\n  {\r\n    kYes,\r\n    kYesToAll,\r\n    kNo,\r\n    kNoToAll,\r\n    kAutoRename,\r\n    kCancel\r\n  };\r\n}\r\n\r\nDECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)\r\n{\r\npublic:\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer) PURE;\r\n  STDMETHOD(PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position) PURE;\r\n  STDMETHOD(MessageError)(const wchar_t *message) PURE;\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE;\r\n};\r\n\r\nstruct IExtractCallbackUI: IFolderArchiveExtractCallback\r\n{\r\n  virtual HRESULT BeforeOpen(const wchar_t *name) = 0;\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted) = 0;\r\n  virtual HRESULT ThereAreNoFiles() = 0;\r\n  virtual HRESULT ExtractResult(HRESULT result) = 0;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  virtual HRESULT SetPassword(const UString &password) = 0;\r\n  #endif\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/LoadCodecs.cpp",
    "content": "// LoadCodecs.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LoadCodecs.h\"\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Common/StringToInt.h\"\r\n#endif\r\n#include \"../../../Windows/PropVariant.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n#include \"../../Common/RegisterArc.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/FileFind.h\"\r\n#include \"../../../Windows/DLL.h\"\r\n#ifdef NEW_FOLDER_INTERFACE\r\n#include \"../../../Windows/ResourceString.h\"\r\nstatic const UINT kIconTypesResId = 100;\r\n#endif\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/Registry.h\"\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\n#ifdef _WIN32\r\nextern HINSTANCE g_hInstance;\r\n#endif\r\n\r\nstatic CSysString GetLibraryFolderPrefix()\r\n{\r\n  #ifdef _WIN32\r\n  TCHAR fullPath[MAX_PATH + 1];\r\n  ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);\r\n  CSysString path = fullPath;\r\n  int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  return path.Left(pos + 1);\r\n  #else\r\n  return CSysString(); // FIX IT\r\n  #endif\r\n}\r\n\r\n#define kCodecsFolderName TEXT(\"Codecs\")\r\n#define kFormatsFolderName TEXT(\"Formats\")\r\nstatic const TCHAR *kMainDll = TEXT(\"7z.dll\");\r\n\r\n#ifdef _WIN32\r\nstatic LPCTSTR kRegistryPath = TEXT(\"Software\") TEXT(STRING_PATH_SEPARATOR) TEXT(\"7-zip\");\r\nstatic LPCTSTR kProgramPathValue = TEXT(\"Path\");\r\nstatic bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)\r\n{\r\n  NRegistry::CKey key;\r\n  if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)\r\n    if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)\r\n    {\r\n      NName::NormalizeDirPathPrefix(path);\r\n      return true;\r\n    }\r\n  return false;\r\n}\r\n\r\n#endif\r\n\r\nCSysString GetBaseFolderPrefixFromRegistry()\r\n{\r\n  CSysString moduleFolderPrefix = GetLibraryFolderPrefix();\r\n  NFind::CFileInfo fi;\r\n  if (NFind::FindFile(moduleFolderPrefix + kMainDll, fi))\r\n    if (!fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fi))\r\n    if (fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fi))\r\n    if (fi.IsDir())\r\n      return moduleFolderPrefix;\r\n  #ifdef _WIN32\r\n  CSysString path;\r\n  if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))\r\n    return path;\r\n  if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))\r\n    return path;\r\n  #endif\r\n  return moduleFolderPrefix;\r\n}\r\n\r\ntypedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);\r\ntypedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, void **outObject);\r\ntypedef UInt32 (WINAPI *SetLargePageModeFunc)();\r\n\r\n\r\nstatic HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 index,\r\n    PROPID propId, CLSID &clsId, bool &isAssigned)\r\n{\r\n  NWindows::NCOM::CPropVariant prop;\r\n  isAssigned = false;\r\n  RINOK(getMethodProperty(index, propId, &prop));\r\n  if (prop.vt == VT_BSTR)\r\n  {\r\n    isAssigned = true;\r\n    clsId = *(const GUID *)prop.bstrVal;\r\n  }\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::LoadCodecs()\r\n{\r\n  CCodecLib &lib = Libs.Back();\r\n  lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress(\"GetMethodProperty\");\r\n  if (lib.GetMethodProperty == NULL)\r\n    return S_OK;\r\n\r\n  UInt32 numMethods = 1;\r\n  GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProcAddress(\"GetNumberOfMethods\");\r\n  if (getNumberOfMethodsFunc != NULL)\r\n  {\r\n    RINOK(getNumberOfMethodsFunc(&numMethods));\r\n  }\r\n\r\n  for(UInt32 i = 0; i < numMethods; i++)\r\n  {\r\n    CDllCodecInfo info;\r\n    info.LibIndex = Libs.Size() - 1;\r\n    info.CodecIndex = i;\r\n\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));\r\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));\r\n\r\n    Codecs.Add(info);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, NCOM::CPropVariant &prop)\r\n{\r\n  if (getProp2)\r\n    return getProp2(index, propID, &prop);;\r\n  return getProp(propID, &prop);\r\n}\r\n\r\nstatic HRESULT ReadBoolProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, bool &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BOOL)\r\n    res = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nstatic HRESULT ReadStringProp(\r\n    GetHandlerPropertyFunc getProp,\r\n    GetHandlerPropertyFunc2 getProp2,\r\n    UInt32 index, PROPID propID, UString &res)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\r\n  if (prop.vt == VT_BSTR)\r\n    res = prop.bstrVal;\r\n  else if (prop.vt != VT_EMPTY)\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\nstatic const unsigned int kNumArcsMax = 32;\r\nstatic unsigned int g_NumArcs = 0;\r\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\r\nvoid RegisterArc(const CArcInfo *arcInfo)\r\n{\r\n  if (g_NumArcs < kNumArcsMax)\r\n    g_Arcs[g_NumArcs++] = arcInfo;\r\n}\r\n\r\nstatic void SplitString(const UString &srcString, UStringVector &destStrings)\r\n{\r\n  destStrings.Clear();\r\n  UString s;\r\n  int len = srcString.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = srcString[i];\r\n    if (c == L' ')\r\n    {\r\n      if (!s.IsEmpty())\r\n      {\r\n        destStrings.Add(s);\r\n        s.Empty();\r\n      }\r\n    }\r\n    else\r\n      s += c;\r\n  }\r\n  if (!s.IsEmpty())\r\n    destStrings.Add(s);\r\n}\r\n\r\nvoid CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt)\r\n{\r\n  UStringVector exts, addExts;\r\n  SplitString(ext, exts);\r\n  if (addExt != 0)\r\n    SplitString(addExt, addExts);\r\n  for (int i = 0; i < exts.Size(); i++)\r\n  {\r\n    CArcExtInfo extInfo;\r\n    extInfo.Ext = exts[i];\r\n    if (i < addExts.Size())\r\n    {\r\n      extInfo.AddExt = addExts[i];\r\n      if (extInfo.AddExt == L\"*\")\r\n        extInfo.AddExt.Empty();\r\n    }\r\n    Exts.Add(extInfo);\r\n  }\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\nHRESULT CCodecs::LoadFormats()\r\n{\r\n  const NDLL::CLibrary &lib = Libs.Back().Lib;\r\n  GetHandlerPropertyFunc getProp = 0;\r\n  GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)\r\n      lib.GetProcAddress(\"GetHandlerProperty2\");\r\n  if (getProp2 == NULL)\r\n  {\r\n    getProp = (GetHandlerPropertyFunc)\r\n        lib.GetProcAddress(\"GetHandlerProperty\");\r\n    if (getProp == NULL)\r\n      return S_OK;\r\n  }\r\n\r\n  UInt32 numFormats = 1;\r\n  GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)\r\n    lib.GetProcAddress(\"GetNumberOfFormats\");\r\n  if (getNumberOfFormats != NULL)\r\n  {\r\n    RINOK(getNumberOfFormats(&numFormats));\r\n  }\r\n  if (getProp2 == NULL)\r\n    numFormats = 1;\r\n\r\n  for(UInt32 i = 0; i < numFormats; i++)\r\n  {\r\n    CArcInfoEx item;\r\n    item.LibIndex = Libs.Size() - 1;\r\n    item.FormatIndex = i;\r\n\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)\r\n      continue;\r\n    if (prop.vt != VT_BSTR)\r\n      continue;\r\n    item.ClassID = *(const GUID *)prop.bstrVal;\r\n    prop.Clear();\r\n\r\n    UString ext, addExt;\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));\r\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));\r\n    item.AddExts(ext, addExt);\r\n\r\n    ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);\r\n    if (item.UpdateEnabled)\r\n      ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);\r\n    \r\n    if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)\r\n      if (prop.vt == VT_BSTR)\r\n      {\r\n        UINT len = ::SysStringByteLen(prop.bstrVal);\r\n        item.StartSignature.SetCapacity(len);\r\n        memmove(item.StartSignature, prop.bstrVal, len);\r\n      }\r\n    Formats.Add(item);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef NEW_FOLDER_INTERFACE\r\nvoid CCodecLib::LoadIcons()\r\n{\r\n  UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId);\r\n  UStringVector pairs;\r\n  SplitString(iconTypes, pairs);\r\n  for (int i = 0; i < pairs.Size(); i++)\r\n  {\r\n    const UString &s = pairs[i];\r\n    int pos = s.Find(L':');\r\n    if (pos < 0)\r\n      continue;\r\n    CIconPair iconPair;\r\n    const wchar_t *end;\r\n    UString num = s.Mid(pos + 1);\r\n    iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);\r\n    if (*end != L'\\0')\r\n      continue;\r\n    iconPair.Ext = s.Left(pos);\r\n    IconPairs.Add(iconPair);\r\n  }\r\n}\r\n\r\nint CCodecLib::FindIconIndex(const UString &ext) const\r\n{\r\n  for (int i = 0; i < IconPairs.Size(); i++)\r\n  {\r\n    const CIconPair &pair = IconPairs[i];\r\n    if (ext.CompareNoCase(pair.Ext) == 0)\r\n      return pair.IconIndex;\r\n  }\r\n  return -1;\r\n}\r\n#endif\r\n\r\n#ifdef _7ZIP_LARGE_PAGES\r\nextern \"C\"\r\n{\r\n  extern SIZE_T g_LargePageSize;\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::LoadDll(const CSysString &dllPath)\r\n{\r\n  {\r\n    NDLL::CLibrary library;\r\n    if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))\r\n      return S_OK;\r\n  }\r\n  Libs.Add(CCodecLib());\r\n  CCodecLib &lib = Libs.Back();\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  lib.Path = dllPath;\r\n  #endif\r\n  bool used = false;\r\n  HRESULT res = S_OK;\r\n  if (lib.Lib.Load(dllPath))\r\n  {\r\n    #ifdef NEW_FOLDER_INTERFACE\r\n    lib.LoadIcons();\r\n    #endif\r\n\r\n    #ifdef _7ZIP_LARGE_PAGES\r\n    if (g_LargePageSize != 0)\r\n    {\r\n      SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProcAddress(\"SetLargePageMode\");\r\n      if (setLargePageMode != 0)\r\n        setLargePageMode();\r\n    }\r\n    #endif\r\n\r\n    lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress(\"CreateObject\");\r\n    if (lib.CreateObject != 0)\r\n    {\r\n      int startSize = Codecs.Size();\r\n      res = LoadCodecs();\r\n      used = (Codecs.Size() != startSize);\r\n      if (res == S_OK)\r\n      {\r\n        startSize = Formats.Size();\r\n        res = LoadFormats();\r\n        used = used || (Formats.Size() != startSize);\r\n      }\r\n    }\r\n  }\r\n  if (!used)\r\n    Libs.DeleteBack();\r\n  return res;\r\n}\r\n\r\nHRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)\r\n{\r\n  NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT(\"*\")));\r\n  NFile::NFind::CFileInfo fi;\r\n  while (enumerator.Next(fi))\r\n  {\r\n    if (fi.IsDir())\r\n      continue;\r\n    RINOK(LoadDll(folderPrefix + fi.Name));\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#endif\r\n\r\n#ifndef _SFX\r\nstatic inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)\r\n{\r\n  bb.SetCapacity(size);\r\n  memmove((Byte *)bb, data, size);\r\n}\r\n#endif\r\n\r\nHRESULT CCodecs::Load()\r\n{\r\n  Formats.Clear();\r\n  #ifdef EXTERNAL_CODECS\r\n  Codecs.Clear();\r\n  #endif\r\n  for (UInt32 i = 0; i < g_NumArcs; i++)\r\n  {\r\n    const CArcInfo &arc = *g_Arcs[i];\r\n    CArcInfoEx item;\r\n    item.Name = arc.Name;\r\n    item.CreateInArchive = arc.CreateInArchive;\r\n    item.CreateOutArchive = arc.CreateOutArchive;\r\n    item.AddExts(arc.Ext, arc.AddExt);\r\n    item.UpdateEnabled = (arc.CreateOutArchive != 0);\r\n    item.KeepName = arc.KeepName;\r\n\r\n    #ifndef _SFX\r\n    SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);\r\n    #endif\r\n    Formats.Add(item);\r\n  }\r\n  #ifdef EXTERNAL_CODECS\r\n  const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();\r\n  RINOK(LoadDll(baseFolder + kMainDll));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n#ifndef _SFX\r\n\r\nint CCodecs::FindFormatForArchiveName(const UString &arcPath) const\r\n{\r\n  int slashPos1 = arcPath.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  int slashPos2 = arcPath.ReverseFind(L'.');\r\n  int dotPos = arcPath.ReverseFind(L'.');\r\n  if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)\r\n    return -1;\r\n  UString ext = arcPath.Mid(dotPos + 1);\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n  {\r\n    const CArcInfoEx &arc = Formats[i];\r\n    if (!arc.UpdateEnabled)\r\n      continue;\r\n    // if (arc.FindExtension(ext) >= 0)\r\n    UString mainExt = arc.GetMainExt();\r\n    if (!mainExt.IsEmpty() && ext.CompareNoCase(mainExt) == 0)\r\n      return i;\r\n  }\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForExtension(const UString &ext) const\r\n{\r\n  if (ext.IsEmpty())\r\n    return -1;\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n    if (Formats[i].FindExtension(ext) >= 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nint CCodecs::FindFormatForArchiveType(const UString &arcType) const\r\n{\r\n  for (int i = 0; i < Formats.Size(); i++)\r\n    if (Formats[i].Name.CompareNoCase(arcType) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nbool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const\r\n{\r\n  formatIndices.Clear();\r\n  for (int pos = 0; pos < arcType.Length();)\r\n  {\r\n    int pos2 = arcType.Find('.', pos);\r\n    if (pos2 < 0)\r\n      pos2 = arcType.Length();\r\n    const UString name = arcType.Mid(pos, pos2 - pos);\r\n    int index = FindFormatForArchiveType(name);\r\n    if (index < 0 && name != L\"*\")\r\n    {\r\n      formatIndices.Clear();\r\n      return false;\r\n    }\r\n    formatIndices.Add(index);\r\n    pos = pos2 + 1;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\n#ifdef EXTERNAL_CODECS\r\n\r\n#ifdef EXPORT_CODECS\r\nextern unsigned int g_NumCodecs;\r\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);\r\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);\r\n// STDAPI GetNumberOfMethods(UInt32 *numCodecs);\r\n#endif\r\n\r\nSTDMETHODIMP CCodecs::GetNumberOfMethods(UInt32 *numMethods)\r\n{\r\n  *numMethods =\r\n      #ifdef EXPORT_CODECS\r\n      g_NumCodecs +\r\n      #endif\r\n      Codecs.Size();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return GetMethodProperty(index, propID, value);\r\n  #endif\r\n\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n\r\n  if (propID == NMethodPropID::kDecoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.DecoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  if (propID == NMethodPropID::kEncoderIsAssigned)\r\n  {\r\n    NWindows::NCOM::CPropVariant propVariant;\r\n    propVariant = ci.EncoderIsAssigned;\r\n    propVariant.Detach(value);\r\n    return S_OK;\r\n  }\r\n  return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(false, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.DecoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return CreateCoder2(true, index, iid, coder);\r\n  #endif\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  if (ci.EncoderIsAssigned)\r\n    return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const\r\n{\r\n  for (int i = 0; i < Codecs.Size(); i++)\r\n  {\r\n    const CDllCodecInfo &codec = Codecs[i];\r\n    if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigned)\r\n      continue;\r\n    const CCodecLib &lib = Libs[codec.LibIndex];\r\n    UString res;\r\n    NWindows::NCOM::CPropVariant prop;\r\n    RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n      res = prop.bstrVal;\r\n    else if (prop.vt != VT_EMPTY)\r\n      continue;\r\n    if (name.CompareNoCase(res) == 0)\r\n      return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICompressCoder, (void **)&coder);\r\n  }\r\n  return CLASS_E_CLASSNOTAVAILABLE;\r\n}\r\n\r\nint CCodecs::GetCodecLibIndex(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n    return -1;\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.LibIndex;\r\n  #else\r\n  return -1;\r\n  #endif\r\n}\r\n\r\nbool CCodecs::GetCodecEncoderIsAssigned(UInt32 index)\r\n{\r\n  #ifdef EXPORT_CODECS\r\n  if (index < g_NumCodecs)\r\n  {\r\n    NWindows::NCOM::CPropVariant prop;\r\n    if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK)\r\n      if (prop.vt != VT_EMPTY)\r\n        return true;\r\n    return false;\r\n  }\r\n  #endif\r\n  #ifdef EXTERNAL_CODECS\r\n  const CDllCodecInfo &ci = Codecs[index\r\n      #ifdef EXPORT_CODECS\r\n      - g_NumCodecs\r\n      #endif\r\n      ];\r\n  return ci.EncoderIsAssigned;\r\n  #else\r\n  return false;\r\n  #endif\r\n}\r\n\r\nHRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  RINOK(GetProperty(index, NMethodPropID::kID, &prop));\r\n  if (prop.vt != VT_UI8)\r\n    return E_INVALIDARG;\r\n  id = prop.uhVal.QuadPart;\r\n  return S_OK;\r\n}\r\n\r\nUString CCodecs::GetCodecName(UInt32 index)\r\n{\r\n  UString s;\r\n  NWindows::NCOM::CPropVariant prop;\r\n  if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK)\r\n    if (prop.vt == VT_BSTR)\r\n      s = prop.bstrVal;\r\n  return s;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/LoadCodecs.h",
    "content": "// LoadCodecs.h\r\n\r\n#ifndef __LOADCODECS_H\r\n#define __LOADCODECS_H\r\n\r\n#include \"../../../Common/Types.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/MyString.h\"\r\n#include \"../../../Common/Buffer.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../../../Windows/DLL.h\"\r\n#endif\r\n\r\nstruct CDllCodecInfo\r\n{\r\n  CLSID Encoder;\r\n  CLSID Decoder;\r\n  bool EncoderIsAssigned;\r\n  bool DecoderIsAssigned;\r\n  int LibIndex;\r\n  UInt32 CodecIndex;\r\n};\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\ntypedef IInArchive * (*CreateInArchiveP)();\r\ntypedef IOutArchive * (*CreateOutArchiveP)();\r\n\r\nstruct CArcExtInfo\r\n{\r\n  UString Ext;\r\n  UString AddExt;\r\n  CArcExtInfo() {}\r\n  CArcExtInfo(const UString &ext): Ext(ext) {}\r\n  CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}\r\n};\r\n\r\n\r\nstruct CArcInfoEx\r\n{\r\n  #ifdef EXTERNAL_CODECS\r\n  int LibIndex;\r\n  UInt32 FormatIndex;\r\n  CLSID ClassID;\r\n  #endif\r\n  bool UpdateEnabled;\r\n  CreateInArchiveP CreateInArchive;\r\n  CreateOutArchiveP CreateOutArchive;\r\n  UString Name;\r\n  CObjectVector<CArcExtInfo> Exts;\r\n  #ifndef _SFX\r\n  CByteBuffer StartSignature;\r\n  // CByteBuffer FinishSignature;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  UStringVector AssociateExts;\r\n  #endif\r\n  #endif\r\n  bool KeepName;\r\n  UString GetMainExt() const\r\n  {\r\n    if (Exts.IsEmpty())\r\n      return UString();\r\n    return Exts[0].Ext;\r\n  }\r\n  int FindExtension(const UString &ext) const\r\n  {\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n      if (ext.CompareNoCase(Exts[i].Ext) == 0)\r\n        return i;\r\n    return -1;\r\n  }\r\n  UString GetAllExtensions() const\r\n  {\r\n    UString s;\r\n    for (int i = 0; i < Exts.Size(); i++)\r\n    {\r\n      if (i > 0)\r\n        s += ' ';\r\n      s += Exts[i].Ext;\r\n    }\r\n    return s;\r\n  }\r\n\r\n  void AddExts(const wchar_t* ext, const wchar_t* addExt);\r\n\r\n  CArcInfoEx():\r\n    #ifdef EXTERNAL_CODECS\r\n    LibIndex(-1),\r\n    #endif\r\n    UpdateEnabled(false),\r\n    CreateInArchive(0), CreateOutArchive(0),\r\n    KeepName(false)\r\n    #ifndef _SFX\r\n    #endif\r\n  {}\r\n};\r\n\r\n#ifdef EXTERNAL_CODECS\r\ntypedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);\r\n\r\n\r\nstruct CCodecLib\r\n{\r\n  NWindows::NDLL::CLibrary Lib;\r\n  GetMethodPropertyFunc GetMethodProperty;\r\n  CreateObjectFunc CreateObject;\r\n  #ifdef NEW_FOLDER_INTERFACE\r\n  struct CIconPair\r\n  {\r\n    UString Ext;\r\n    UInt32 IconIndex;\r\n  };\r\n  CSysString Path;\r\n  CObjectVector<CIconPair> IconPairs;\r\n  void LoadIcons();\r\n  int FindIconIndex(const UString &ext) const;\r\n  #endif\r\n  CCodecLib(): GetMethodProperty(0) {}\r\n};\r\n#endif\r\n\r\nclass CCodecs:\r\n  #ifdef EXTERNAL_CODECS\r\n  public ICompressCodecsInfo,\r\n  #else\r\n  public IUnknown,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef EXTERNAL_CODECS\r\n  CObjectVector<CCodecLib> Libs;\r\n  CObjectVector<CDllCodecInfo> Codecs;\r\n  HRESULT LoadCodecs();\r\n  HRESULT LoadFormats();\r\n  HRESULT LoadDll(const CSysString &path);\r\n  HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);\r\n\r\n  HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const\r\n  {\r\n    return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);\r\n  }\r\n  #endif\r\n\r\npublic:\r\n  CObjectVector<CArcInfoEx> Formats;\r\n  HRESULT Load();\r\n  \r\n  #ifndef _SFX\r\n  int FindFormatForArchiveName(const UString &arcPath) const;\r\n  int FindFormatForExtension(const UString &ext) const;\r\n  int FindFormatForArchiveType(const UString &arcType) const;\r\n  bool FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const;\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods);\r\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\r\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder);\r\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder);\r\n  #endif\r\n\r\n  int GetCodecLibIndex(UInt32 index);\r\n  bool GetCodecEncoderIsAssigned(UInt32 index);\r\n  HRESULT GetCodecId(UInt32 index, UInt64 &id);\r\n  UString GetCodecName(UInt32 index);\r\n\r\n  HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const\r\n  {\r\n    const CArcInfoEx &ai = Formats[formatIndex];\r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateInArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, false);\r\n    #endif\r\n  }\r\n  HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const\r\n  {\r\n    const CArcInfoEx &ai = Formats[formatIndex];\r\n    #ifdef EXTERNAL_CODECS\r\n    if (ai.LibIndex < 0)\r\n    #endif\r\n    {\r\n      archive = ai.CreateOutArchive();\r\n      return S_OK;\r\n    }\r\n    #ifdef EXTERNAL_CODECS\r\n    return CreateArchiveHandler(ai, (void **)&archive, true);\r\n    #endif\r\n  }\r\n  int FindOutFormatFromName(const UString &name) const\r\n  {\r\n    for (int i = 0; i < Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = Formats[i];\r\n      if (!arc.UpdateEnabled)\r\n        continue;\r\n      if (arc.Name.CompareNoCase(name) == 0)\r\n        return i;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  #ifdef EXTERNAL_CODECS\r\n  HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;\r\n  #endif\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/OpenArchive.cpp",
    "content": "// OpenArchive.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenArchive.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"DefaultName.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidPath, &prop));\r\n  if(prop.vt == VT_BSTR)\r\n    result = prop.bstrVal;\r\n  else if (prop.vt == VT_EMPTY)\r\n    result.Empty();\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result)\r\n{\r\n  RINOK(GetArchiveItemPath(archive, index, result));\r\n  if (result.IsEmpty())\r\n  {\r\n    result = defaultName;\r\n    NCOM::CPropVariant prop;\r\n    RINOK(archive->GetProperty(index, kpidExtension, &prop));\r\n    if (prop.vt == VT_BSTR)\r\n    {\r\n      result += L'.';\r\n      result += prop.bstrVal;\r\n    }\r\n    else if (prop.vt != VT_EMPTY)\r\n      return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\r\n    const FILETIME &defaultFileTime, FILETIME &fileTime)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, kpidMTime, &prop));\r\n  if (prop.vt == VT_FILETIME)\r\n    fileTime = prop.filetime;\r\n  else if (prop.vt == VT_EMPTY)\r\n    fileTime = defaultFileTime;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  RINOK(archive->GetProperty(index, propID, &prop));\r\n  if(prop.vt == VT_BOOL)\r\n    result = VARIANT_BOOLToBool(prop.boolVal);\r\n  else if (prop.vt == VT_EMPTY)\r\n    result = false;\r\n  else\r\n    return E_FAIL;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\r\n}\r\n\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result)\r\n{\r\n  return IsArchiveItemProp(archive, index, kpidIsAnti, result);\r\n}\r\n\r\n// Static-SFX (for Linux) can be big.\r\nconst UInt64 kMaxCheckStartPosition = 1 << 22;\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  inStreamSpec->Open(fileName);\r\n  return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n}\r\n\r\n#ifndef _SFX\r\nstatic inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)\r\n{\r\n  for (size_t i = 0; i < size; i++)\r\n    if (p1[i] != p2[i])\r\n      return false;\r\n  return true;\r\n}\r\n#endif\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    IInStream *inStream,\r\n    const UString &fileName,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  *archiveResult = NULL;\r\n  UString extension;\r\n  {\r\n    int dotPos = fileName.ReverseFind(L'.');\r\n    if (dotPos >= 0)\r\n      extension = fileName.Mid(dotPos + 1);\r\n  }\r\n  CIntVector orderIndices;\r\n  if (arcTypeIndex >= 0)\r\n    orderIndices.Add(arcTypeIndex);\r\n  else\r\n  {\r\n\r\n  int i;\r\n  int numFinded = 0;\r\n  for (i = 0; i < codecs->Formats.Size(); i++)\r\n    if (codecs->Formats[i].FindExtension(extension) >= 0)\r\n      orderIndices.Insert(numFinded++, i);\r\n    else\r\n      orderIndices.Add(i);\r\n  \r\n  #ifndef _SFX\r\n  if (numFinded != 1)\r\n  {\r\n    CIntVector orderIndices2;\r\n    CByteBuffer byteBuffer;\r\n    const size_t kBufferSize = (1 << 21);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    size_t processedSize = kBufferSize;\r\n    RINOK(ReadStream(inStream, byteBuffer, &processedSize));\r\n    if (processedSize == 0)\r\n      return S_FALSE;\r\n\r\n    const Byte *buf = byteBuffer;\r\n    Byte hash[1 << 16];\r\n    memset(hash, 0xFF, 1 << 16);\r\n    Byte prevs[256];\r\n    if (orderIndices.Size() > 255)\r\n      return S_FALSE;\r\n    int i;\r\n    for (i = 0; i < orderIndices.Size(); i++)\r\n    {\r\n      const CArcInfoEx &ai = codecs->Formats[orderIndices[i]];\r\n      const CByteBuffer &sig = ai.StartSignature;\r\n      if (sig.GetCapacity() < 2)\r\n        continue;\r\n      UInt32 v = sig[0] | ((UInt32)sig[1] << 8);\r\n      prevs[i] = hash[v];\r\n      hash[v] = (Byte)i;\r\n    }\r\n\r\n    processedSize--;\r\n    for (UInt32 pos = 0; pos < processedSize; pos++)\r\n    {\r\n      for (; pos < processedSize && hash[buf[pos] | ((UInt32)buf[pos + 1] << 8)] == 0xFF; pos++);\r\n      if (pos == processedSize)\r\n        break;\r\n      UInt32 v = buf[pos] | ((UInt32)buf[pos + 1] << 8);\r\n      Byte *ptr = &hash[v];\r\n      int i = *ptr;\r\n      do\r\n      {\r\n        int index = orderIndices[i];\r\n        const CArcInfoEx &ai = codecs->Formats[index];\r\n        const CByteBuffer &sig = ai.StartSignature;\r\n        if (sig.GetCapacity() != 0 && pos + sig.GetCapacity() <= processedSize + 1)\r\n          if (TestSignature(buf + pos, sig, sig.GetCapacity()))\r\n          {\r\n            orderIndices2.Add(index);\r\n            orderIndices[i] = 0xFF;\r\n            *ptr = prevs[i];\r\n          }\r\n        ptr = &prevs[i];\r\n        i = *ptr;\r\n      }\r\n      while (i != 0xFF);\r\n    }\r\n    \r\n    for (i = 0; i < orderIndices.Size(); i++)\r\n    {\r\n      int val = orderIndices[i];\r\n      if (val != 0xFF)\r\n        orderIndices2.Add(val);\r\n    }\r\n    orderIndices = orderIndices2;\r\n\r\n    if (orderIndices.Size() >= 2)\r\n    {\r\n      int isoIndex = codecs->FindFormatForArchiveType(L\"iso\");\r\n      int udfIndex = codecs->FindFormatForArchiveType(L\"udf\");\r\n      int iIso = -1;\r\n      int iUdf = -1;\r\n      for (int i = 0; i < orderIndices.Size(); i++)\r\n      {\r\n        if (orderIndices[i] == isoIndex) iIso = i;\r\n        if (orderIndices[i] == udfIndex) iUdf = i;\r\n      }\r\n      if (iUdf == iIso + 1)\r\n      {\r\n        orderIndices[iUdf] = isoIndex;\r\n        orderIndices[iIso] = udfIndex;\r\n      }\r\n    }\r\n  }\r\n  else if (extension == L\"000\" || extension == L\"001\")\r\n  {\r\n    CByteBuffer byteBuffer;\r\n    const size_t kBufferSize = (1 << 10);\r\n    byteBuffer.SetCapacity(kBufferSize);\r\n    Byte *buffer = byteBuffer;\r\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\r\n    size_t processedSize = kBufferSize;\r\n    RINOK(ReadStream(inStream, buffer, &processedSize));\r\n    if (processedSize >= 16)\r\n    {\r\n      Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};\r\n      if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] & 1) != 0)\r\n      {\r\n        for (int i = 0; i < orderIndices.Size(); i++)\r\n        {\r\n          int index = orderIndices[i];\r\n          const CArcInfoEx &ai = codecs->Formats[index];\r\n          if (ai.Name.CompareNoCase(L\"rar\") != 0)\r\n            continue;\r\n          orderIndices.Delete(i--);\r\n          orderIndices.Insert(0, index);\r\n          break;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n  }\r\n\r\n  for(int i = 0; i < orderIndices.Size(); i++)\r\n  {\r\n    inStream->Seek(0, STREAM_SEEK_SET, NULL);\r\n\r\n    CMyComPtr<IInArchive> archive;\r\n\r\n    formatIndex = orderIndices[i];\r\n    RINOK(codecs->CreateInArchive(formatIndex, archive));\r\n    if (!archive)\r\n      continue;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n\r\n    HRESULT result = archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\r\n    if (result == S_FALSE)\r\n      continue;\r\n    RINOK(result);\r\n    *archiveResult = archive.Detach();\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex];\r\n    if (format.Exts.Size() == 0)\r\n    {\r\n      defaultItemName = GetDefaultName2(fileName, L\"\", L\"\");\r\n    }\r\n    else\r\n    {\r\n      int subExtIndex = format.FindExtension(extension);\r\n      if (subExtIndex < 0)\r\n        subExtIndex = 0;\r\n      defaultItemName = GetDefaultName2(fileName,\r\n          format.Exts[subExtIndex].Ext,\r\n          format.Exts[subExtIndex].AddExt);\r\n    }\r\n    return S_OK;\r\n  }\r\n  return S_FALSE;\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &filePath,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  CInFileStream *inStreamSpec = new CInFileStream;\r\n  CMyComPtr<IInStream> inStream(inStreamSpec);\r\n  if (!inStreamSpec->Open(filePath))\r\n    return GetLastError();\r\n  return OpenArchive(codecs, arcTypeIndex, inStream, ExtractFileNameFromPath(filePath),\r\n    archiveResult, formatIndex,\r\n    defaultItemName, openArchiveCallback);\r\n}\r\n\r\nstatic void MakeDefaultName(UString &name)\r\n{\r\n  int dotPos = name.ReverseFind(L'.');\r\n  if (dotPos < 0)\r\n    return;\r\n  UString ext = name.Mid(dotPos + 1);\r\n  if (ext.IsEmpty())\r\n    return;\r\n  for (int pos = 0; pos < ext.Length(); pos++)\r\n    if (ext[pos] < L'0' || ext[pos] > L'9')\r\n      return;\r\n  name = name.Left(dotPos);\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &fileName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback)\r\n{\r\n  if (formatIndices.Size() >= 3)\r\n    return E_NOTIMPL;\r\n  \r\n  int arcTypeIndex = -1;\r\n  if (formatIndices.Size() >= 1)\r\n    arcTypeIndex = formatIndices[formatIndices.Size() - 1];\r\n  \r\n  HRESULT result = OpenArchive(codecs, arcTypeIndex, fileName,\r\n    archive0, formatIndex0, defaultItemName0, openArchiveCallback);\r\n  RINOK(result);\r\n\r\n  if (formatIndices.Size() == 1)\r\n    return S_OK;\r\n  arcTypeIndex = -1;\r\n  if (formatIndices.Size() >= 2)\r\n    arcTypeIndex = formatIndices[formatIndices.Size() - 2];\r\n\r\n  HRESULT resSpec = (formatIndices.Size() == 0 ? S_OK : E_NOTIMPL);\r\n\r\n  CMyComPtr<IInArchiveGetStream> getStream;\r\n  result = (*archive0)->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream);\r\n  if (result != S_OK || !getStream)\r\n    return resSpec;\r\n\r\n  CMyComPtr<ISequentialInStream> subSeqStream;\r\n  result = getStream->GetStream(0, &subSeqStream);\r\n  if (result != S_OK || !subSeqStream)\r\n    return resSpec;\r\n\r\n  CMyComPtr<IInStream> subStream;\r\n  result = subSeqStream.QueryInterface(IID_IInStream, &subStream);\r\n  if (result != S_OK || !subStream)\r\n    return resSpec;\r\n\r\n  UInt32 numItems;\r\n  RINOK((*archive0)->GetNumberOfItems(&numItems));\r\n  if (numItems < 1)\r\n    return resSpec;\r\n\r\n  UString subPath;\r\n  RINOK(GetArchiveItemPath(*archive0, 0, subPath))\r\n  if (subPath.IsEmpty())\r\n  {\r\n    MakeDefaultName(defaultItemName0);\r\n    subPath = defaultItemName0;\r\n    const CArcInfoEx &format = codecs->Formats[formatIndex0];\r\n    if (format.Name.CompareNoCase(L\"7z\") == 0)\r\n    {\r\n      if (subPath.Right(3).CompareNoCase(L\".7z\") != 0)\r\n        subPath += L\".7z\";\r\n    }\r\n  }\r\n  else\r\n    subPath = ExtractFileNameFromPath(subPath);\r\n\r\n  CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;\r\n  openArchiveCallback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);\r\n  if (setSubArchiveName)\r\n    setSubArchiveName->SetSubArchiveName(subPath);\r\n\r\n  result = OpenArchive(codecs, arcTypeIndex, subStream, subPath,\r\n      archive1, formatIndex1, defaultItemName1, openArchiveCallback);\r\n  resSpec = (formatIndices.Size() == 0 ? S_OK : S_FALSE);\r\n  if (result != S_OK)\r\n    return resSpec;\r\n  return S_OK;\r\n}\r\n\r\nstatic void SetCallback(const UString &archiveName,\r\n    IOpenCallbackUI *openCallbackUI,\r\n    IArchiveOpenCallback *reOpenCallback,\r\n    CMyComPtr<IArchiveOpenCallback> &openCallback)\r\n{\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n  openCallbackSpec->ReOpenCallback = reOpenCallback;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  openCallbackSpec->Init(\r\n      fullName.Left(fileNamePartStartIndex),\r\n      fullName.Mid(fileNamePartStartIndex));\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &archiveName,\r\n    IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI)\r\n{\r\n  CMyComPtr<IArchiveOpenCallback> openCallback;\r\n  SetCallback(archiveName, openCallbackUI, NULL, openCallback);\r\n  int formatInfo;\r\n  return OpenArchive(codecs, arcTypeIndex, archiveName, archive, formatInfo, defaultItemName, openCallback);\r\n}\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    UStringVector &volumePaths,\r\n    UInt64 &volumesSize,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  volumesSize = 0;\r\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\r\n  CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;\r\n  openCallbackSpec->Callback = openCallbackUI;\r\n\r\n  UString fullName;\r\n  int fileNamePartStartIndex;\r\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\r\n  UString prefix = fullName.Left(fileNamePartStartIndex);\r\n  UString name = fullName.Mid(fileNamePartStartIndex);\r\n  openCallbackSpec->Init(prefix, name);\r\n\r\n  int formatIndex0, formatIndex1;\r\n  RINOK(OpenArchive(codecs, formatIndices, archiveName,\r\n      archive0,\r\n      archive1,\r\n      formatIndex0,\r\n      formatIndex1,\r\n      defaultItemName0,\r\n      defaultItemName1,\r\n      openCallback));\r\n  volumePaths.Add(prefix + name);\r\n  for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)\r\n    volumePaths.Add(prefix + openCallbackSpec->FileNames[i]);\r\n  volumesSize = openCallbackSpec->TotalSize;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CArchiveLink::Close()\r\n{\r\n  if (Archive1 != 0)\r\n    RINOK(Archive1->Close());\r\n  if (Archive0 != 0)\r\n    RINOK(Archive0->Close());\r\n  IsOpen = false;\r\n  return S_OK;\r\n}\r\n\r\nvoid CArchiveLink::Release()\r\n{\r\n  IsOpen = false;\r\n  Archive1.Release();\r\n  Archive0.Release();\r\n}\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  HRESULT res = OpenArchive(codecs, formatIndices, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1,\r\n    archiveLink.FormatIndex0, archiveLink.FormatIndex1,\r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\r\n    openCallback);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT MyOpenArchive(CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI)\r\n{\r\n  HRESULT res = MyOpenArchive(codecs, formatIndices, archiveName,\r\n    &archiveLink.Archive0, &archiveLink.Archive1,\r\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\r\n    archiveLink.VolumePaths,\r\n    archiveLink.VolumesSize,\r\n    openCallbackUI);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n\r\nHRESULT ReOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, const UString &fileName,\r\n    IArchiveOpenCallback *openCallback)\r\n{\r\n  if (archiveLink.GetNumLevels() > 1)\r\n    return E_NOTIMPL;\r\n\r\n  if (archiveLink.GetNumLevels() == 0)\r\n    return MyOpenArchive(codecs, CIntVector(), fileName, archiveLink, 0);\r\n\r\n  CMyComPtr<IArchiveOpenCallback> openCallbackNew;\r\n  SetCallback(fileName, NULL, openCallback, openCallbackNew);\r\n\r\n  HRESULT res = ReOpenArchive(archiveLink.GetArchive(), fileName, openCallbackNew);\r\n  archiveLink.IsOpen = (res == S_OK);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/OpenArchive.h",
    "content": "// OpenArchive.h\r\n\r\n#ifndef __OPENARCHIVE_H\r\n#define __OPENARCHIVE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Windows/FileFind.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"LoadCodecs.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result);\r\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result);\r\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\r\n    const FILETIME &defaultFileTime, FILETIME &fileTime);\r\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result);\r\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result);\r\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result);\r\n\r\nstruct ISetSubArchiveName\r\n{\r\n  virtual void SetSubArchiveName(const wchar_t *name) = 0;\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    IInStream *inStream,\r\n    const UString &fileName,\r\n    IInArchive **archiveResult,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    int arcTypeIndex,\r\n    const UString &filePath,\r\n    IInArchive **archive,\r\n    int &formatIndex,\r\n    UString &defaultItemName,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &filePath,\r\n    IInArchive **archive0,\r\n    IInArchive **archive1,\r\n    int &formatIndex0,\r\n    int &formatIndex1,\r\n    UString &defaultItemName0,\r\n    UString &defaultItemName1,\r\n    IArchiveOpenCallback *openArchiveCallback);\r\n\r\n\r\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback);\r\n\r\nstruct CArchiveLink\r\n{\r\n  CMyComPtr<IInArchive> Archive0;\r\n  CMyComPtr<IInArchive> Archive1;\r\n  UString DefaultItemName0;\r\n  UString DefaultItemName1;\r\n\r\n  int FormatIndex0;\r\n  int FormatIndex1;\r\n  \r\n  UStringVector VolumePaths;\r\n\r\n  bool IsOpen;\r\n  UInt64 VolumesSize;\r\n\r\n  int GetNumLevels() const\r\n  {\r\n    int result = 0;\r\n    if (Archive0)\r\n    {\r\n      result++;\r\n      if (Archive1)\r\n        result++;\r\n    }\r\n    return result;\r\n  }\r\n\r\n  CArchiveLink(): IsOpen(false), VolumesSize(0) {};\r\n\r\n  IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; }\r\n  UString GetDefaultItemName()  { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; }\r\n  int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; }\r\n  HRESULT Close();\r\n  void Release();\r\n};\r\n\r\nHRESULT OpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\nHRESULT MyOpenArchive(\r\n    CCodecs *codecs,\r\n    const CIntVector &formatIndices,\r\n    const UString &archiveName,\r\n    CArchiveLink &archiveLink,\r\n    IOpenCallbackUI *openCallbackUI);\r\n\r\nHRESULT ReOpenArchive(\r\n    CCodecs *codecs,\r\n    CArchiveLink &archiveLink,\r\n    const UString &fileName,\r\n    IArchiveOpenCallback *openCallback);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/PropIDUtils.cpp",
    "content": "// PropIDUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropIDUtils.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../PropID.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstatic UString ConvertUInt32ToString(UInt32 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic void ConvertUInt32ToHex(UInt32 value, wchar_t *s)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n  {\r\n    int t = value & 0xF;\r\n    value >>= 4;\r\n    s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));\r\n  }\r\n  s[8] = L'\\0';\r\n}\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full)\r\n{\r\n  switch(propID)\r\n  {\r\n    case kpidCTime:\r\n    case kpidATime:\r\n    case kpidMTime:\r\n    {\r\n      if (propVariant.vt != VT_FILETIME)\r\n        return UString(); // It is error;\r\n      FILETIME localFileTime;\r\n      if (propVariant.filetime.dwHighDateTime == 0 &&\r\n          propVariant.filetime.dwLowDateTime == 0)\r\n        return UString();\r\n      if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\r\n        return UString(); // It is error;\r\n      return ConvertFileTimeToString(localFileTime, true, full);\r\n    }\r\n    case kpidCRC:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      wchar_t temp[12];\r\n      ConvertUInt32ToHex(propVariant.ulVal, temp);\r\n      return temp;\r\n    }\r\n    case kpidAttrib:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UString result;\r\n      UInt32 attributes = propVariant.ulVal;\r\n      if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';\r\n      if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';\r\n      if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';\r\n      if (NFile::NFind::NAttributes::IsDir(attributes)) result += L'D';\r\n      if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';\r\n      if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';\r\n      if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';\r\n      return result;\r\n    }\r\n    case kpidDictionarySize:\r\n    {\r\n      if(propVariant.vt != VT_UI4)\r\n        break;\r\n      UInt32 size = propVariant.ulVal;\r\n      if (size % (1 << 20) == 0)\r\n        return ConvertUInt32ToString(size >> 20) + L\"MB\";\r\n      if (size % (1 << 10) == 0)\r\n        return ConvertUInt32ToString(size >> 10) + L\"KB\";\r\n      return ConvertUInt32ToString(size);\r\n    }\r\n  }\r\n  return ConvertPropVariantToString(propVariant);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/PropIDUtils.h",
    "content": "// PropIDUtils.h\r\n\r\n#ifndef __PROPIDUTILS_H\r\n#define __PROPIDUTILS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/Property.h",
    "content": "// Property.h\r\n\r\n#ifndef __PROPERTY_H\r\n#define __PROPERTY_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nstruct CProperty\r\n{\r\n  UString Name;\r\n  UString Value;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/SetProperties.cpp",
    "content": "// SetProperties.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SetProperties.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StringToInt.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\n\r\nstatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)\r\n{\r\n  const wchar_t *endPtr;\r\n  UInt64 result = ConvertStringToUInt64(s, &endPtr);\r\n  if (endPtr - (const wchar_t *)s != s.Length())\r\n    prop = s;\r\n  else if (result <= 0xFFFFFFFF)\r\n    prop = (UInt32)result;\r\n  else\r\n    prop = result;\r\n}\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)\r\n{\r\n  if (properties.IsEmpty())\r\n    return S_OK;\r\n  CMyComPtr<ISetProperties> setProperties;\r\n  unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);\r\n  if (!setProperties)\r\n    return S_OK;\r\n\r\n  UStringVector realNames;\r\n  CPropVariant *values = new CPropVariant[properties.Size()];\r\n  try\r\n  {\r\n    int i;\r\n    for(i = 0; i < properties.Size(); i++)\r\n    {\r\n      const CProperty &property = properties[i];\r\n      NCOM::CPropVariant propVariant;\r\n      UString name = property.Name;\r\n      if (property.Value.IsEmpty())\r\n      {\r\n        if (!name.IsEmpty())\r\n        {\r\n          wchar_t c = name[name.Length() - 1];\r\n          if (c == L'-')\r\n            propVariant = false;\r\n          else if (c == L'+')\r\n            propVariant = true;\r\n          if (propVariant.vt != VT_EMPTY)\r\n            name = name.Left(name.Length() - 1);\r\n        }\r\n      }\r\n      else\r\n        ParseNumberString(property.Value, propVariant);\r\n      realNames.Add(name);\r\n      values[i] = propVariant;\r\n    }\r\n    CRecordVector<const wchar_t *> names;\r\n    for(i = 0; i < realNames.Size(); i++)\r\n      names.Add((const wchar_t *)realNames[i]);\r\n    \r\n    RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));\r\n  }\r\n  catch(...)\r\n  {\r\n    delete []values;\r\n    throw;\r\n  }\r\n  delete []values;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/SetProperties.h",
    "content": "// SetProperties.h\r\n\r\n#ifndef __SETPROPERTIES_H\r\n#define __SETPROPERTIES_H\r\n\r\n#include \"Property.h\"\r\n\r\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/SortUtils.cpp",
    "content": "// SortUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"SortUtils.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nstatic int CompareStrings(const int *p1, const int *p2, void *param)\r\n{\r\n  const UStringVector &strings = *(const UStringVector *)param;\r\n  return CompareFileNames(strings[*p1], strings[*p2]);\r\n}\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numItems = strings.Size();\r\n  indices.Reserve(numItems);\r\n  for(int i = 0; i < numItems; i++)\r\n    indices.Add(i);\r\n  indices.Sort(CompareStrings, (void *)&strings);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/SortUtils.h",
    "content": "// SortUtils.h\r\n\r\n#ifndef __SORTUTLS_H\r\n#define __SORTUTLS_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/StdAfx.h",
    "content": "// stdafx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/TempFiles.cpp",
    "content": "// TempFiles.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"TempFiles.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileIO.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\n\r\nvoid CTempFiles::Clear()\r\n{\r\n  while(!Paths.IsEmpty())\r\n  {\r\n    NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());\r\n    Paths.DeleteBack();\r\n  }\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/TempFiles.h",
    "content": "// TempFiles.h\r\n\r\n#ifndef __TEMPFILES_H\r\n#define __TEMPFILES_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nclass CTempFiles\r\n{\r\n  void Clear();\r\npublic:\r\n  UStringVector Paths;\r\n  ~CTempFiles() { Clear(); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/Update.cpp",
    "content": "// Update.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Update.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"Windows/DLL.h\"\r\n#endif\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\n#include \"../../Compress/CopyCoder.h\"\r\n\r\n#include \"../Common/DirItem.h\"\r\n#include \"../Common/EnumDirItems.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#include \"EnumDirItems.h\"\r\n#include \"SetProperties.h\"\r\n#include \"TempFiles.h\"\r\n#include \"UpdateCallback.h\"\r\n\r\nstatic const char *kUpdateIsNotSupoorted =\r\n  \"update operations are not supported for this archive\";\r\n\r\nusing namespace NWindows;\r\nusing namespace NCOM;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nstatic const wchar_t *kTempFolderPrefix = L\"7zE\";\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)\r\n{\r\n  CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;\r\n  return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);\r\n}\r\n\r\nclass COutMultiVolStream:\r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  int _streamIndex; // required stream\r\n  UInt64 _offsetPos; // offset from start of _streamIndex index\r\n  UInt64 _absPos;\r\n  UInt64 _length;\r\n\r\n  struct CSubStreamInfo\r\n  {\r\n    COutFileStream *StreamSpec;\r\n    CMyComPtr<IOutStream> Stream;\r\n    UString Name;\r\n    UInt64 Pos;\r\n    UInt64 RealSize;\r\n  };\r\n  CObjectVector<CSubStreamInfo> Streams;\r\npublic:\r\n  // CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\r\n  CRecordVector<UInt64> Sizes;\r\n  UString Prefix;\r\n  CTempFiles *TempFiles;\r\n\r\n  void Init()\r\n  {\r\n    _streamIndex = 0;\r\n    _offsetPos = 0;\r\n    _absPos = 0;\r\n    _length = 0;\r\n  }\r\n\r\n  HRESULT Close();\r\n\r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n// static NSynchronization::CCriticalSection g_TempPathsCS;\r\n\r\nHRESULT COutMultiVolStream::Close()\r\n{\r\n  HRESULT res = S_OK;\r\n  for (int i = 0; i < Streams.Size(); i++)\r\n  {\r\n    CSubStreamInfo &s = Streams[i];\r\n    if (s.StreamSpec)\r\n    {\r\n      HRESULT res2 = s.StreamSpec->Close();\r\n      if (res2 != S_OK)\r\n        res = res2;\r\n    }\r\n  }\r\n  return res;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  while(size > 0)\r\n  {\r\n    if (_streamIndex >= Streams.Size())\r\n    {\r\n      CSubStreamInfo subStream;\r\n\r\n      wchar_t temp[32];\r\n      ConvertUInt64ToString(_streamIndex + 1, temp);\r\n      UString res = temp;\r\n      while (res.Length() < 3)\r\n        res = UString(L'0') + res;\r\n      UString name = Prefix + res;\r\n      subStream.StreamSpec = new COutFileStream;\r\n      subStream.Stream = subStream.StreamSpec;\r\n      if(!subStream.StreamSpec->Create(name, false))\r\n        return ::GetLastError();\r\n      {\r\n        // NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);\r\n        TempFiles->Paths.Add(name);\r\n      }\r\n\r\n      subStream.Pos = 0;\r\n      subStream.RealSize = 0;\r\n      subStream.Name = name;\r\n      Streams.Add(subStream);\r\n      continue;\r\n    }\r\n    CSubStreamInfo &subStream = Streams[_streamIndex];\r\n\r\n    int index = _streamIndex;\r\n    if (index >= Sizes.Size())\r\n      index = Sizes.Size() - 1;\r\n    UInt64 volSize = Sizes[index];\r\n\r\n    if (_offsetPos >= volSize)\r\n    {\r\n      _offsetPos -= volSize;\r\n      _streamIndex++;\r\n      continue;\r\n    }\r\n    if (_offsetPos != subStream.Pos)\r\n    {\r\n      // CMyComPtr<IOutStream> outStream;\r\n      // RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\r\n      RINOK(subStream.Stream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\r\n      subStream.Pos = _offsetPos;\r\n    }\r\n\r\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, volSize - subStream.Pos);\r\n    UInt32 realProcessed;\r\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\r\n    data = (void *)((Byte *)data + realProcessed);\r\n    size -= realProcessed;\r\n    subStream.Pos += realProcessed;\r\n    _offsetPos += realProcessed;\r\n    _absPos += realProcessed;\r\n    if (_absPos > _length)\r\n      _length = _absPos;\r\n    if (_offsetPos > subStream.RealSize)\r\n      subStream.RealSize = _offsetPos;\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessed;\r\n    if (subStream.Pos == volSize)\r\n    {\r\n      _streamIndex++;\r\n      _offsetPos = 0;\r\n    }\r\n    if (realProcessed == 0 && curSize != 0)\r\n      return E_FAIL;\r\n    break;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  switch(seekOrigin)\r\n  {\r\n    case STREAM_SEEK_SET:\r\n      _absPos = offset;\r\n      break;\r\n    case STREAM_SEEK_CUR:\r\n      _absPos += offset;\r\n      break;\r\n    case STREAM_SEEK_END:\r\n      _absPos = _length + offset;\r\n      break;\r\n  }\r\n  _offsetPos = _absPos;\r\n  if (newPosition != NULL)\r\n    *newPosition = _absPos;\r\n  _streamIndex = 0;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP COutMultiVolStream::SetSize(Int64 newSize)\r\n{\r\n  if (newSize < 0)\r\n    return E_INVALIDARG;\r\n  int i = 0;\r\n  while (i < Streams.Size())\r\n  {\r\n    CSubStreamInfo &subStream = Streams[i++];\r\n    if ((UInt64)newSize < subStream.RealSize)\r\n    {\r\n      RINOK(subStream.Stream->SetSize(newSize));\r\n      subStream.RealSize = newSize;\r\n      break;\r\n    }\r\n    newSize -= subStream.RealSize;\r\n  }\r\n  while (i < Streams.Size())\r\n  {\r\n    {\r\n      CSubStreamInfo &subStream = Streams.Back();\r\n      subStream.Stream.Release();\r\n      NDirectory::DeleteFileAlways(subStream.Name);\r\n    }\r\n    Streams.DeleteBack();\r\n  }\r\n  _offsetPos = _absPos;\r\n  _streamIndex = 0;\r\n  _length = newSize;\r\n  return S_OK;\r\n}\r\n\r\nstatic const wchar_t *kDefaultArchiveType = L\"7z\";\r\nstatic const wchar_t *kSFXExtension =\r\n  #ifdef _WIN32\r\n    L\"exe\";\r\n  #else\r\n    L\"\";\r\n  #endif\r\n\r\nbool CUpdateOptions::Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath)\r\n{\r\n  if (formatIndices.Size() > 1)\r\n    return false;\r\n  int arcTypeIndex = -1;\r\n  if (formatIndices.Size() != 0)\r\n    arcTypeIndex = formatIndices[0];\r\n  if (arcTypeIndex >= 0)\r\n    MethodMode.FormatIndex = arcTypeIndex;\r\n  else\r\n  {\r\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveName(arcPath);\r\n    if (MethodMode.FormatIndex < 0)\r\n      MethodMode.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArchiveType);\r\n  }\r\n  if (MethodMode.FormatIndex < 0)\r\n    return false;\r\n  const CArcInfoEx &arcInfo = codecs->Formats[MethodMode.FormatIndex];\r\n  if (!arcInfo.UpdateEnabled)\r\n    return false;\r\n  UString typeExt = arcInfo.GetMainExt();\r\n  UString ext = typeExt;\r\n  if (SfxMode)\r\n    ext = kSFXExtension;\r\n  ArchivePath.BaseExtension = ext;\r\n  ArchivePath.VolExtension = typeExt;\r\n  ArchivePath.ParseFromPath(arcPath);\r\n  for (int i = 0; i < Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &uc = Commands[i];\r\n    uc.ArchivePath.BaseExtension = ext;\r\n    uc.ArchivePath.VolExtension = typeExt;\r\n    uc.ArchivePath.ParseFromPath(uc.UserArchivePath);\r\n  }\r\n  return true;\r\n}\r\n\r\n/*\r\nstruct CUpdateProduceCallbackImp: public IUpdateProduceCallback\r\n{\r\n  const CObjectVector<CArcItem> *_arcItems;\r\n  IUpdateCallbackUI *_callback;\r\n  \r\n  CUpdateProduceCallbackImp(const CObjectVector<CArcItem> *a, \r\n      IUpdateCallbackUI *callback): _arcItems(a), _callback(callback) {}\r\n  virtual HRESULT ShowDeleteFile(int arcIndex);\r\n};\r\n\r\nHRESULT CUpdateProduceCallbackImp::ShowDeleteFile(int arcIndex)\r\n{\r\n  return _callback->ShowDeleteFile((*_arcItems)[arcIndex].Name);\r\n}\r\n*/\r\n\r\nstatic HRESULT Compress(\r\n    CCodecs *codecs,\r\n    const CActionSet &actionSet,\r\n    IInArchive *archive,\r\n    const CCompressionMethodMode &compressionMethod,\r\n    CArchivePath &archivePath,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    bool shareForWrite,\r\n    bool stdInMode,\r\n    /* const UString & stdInFileName, */\r\n    bool stdOutMode,\r\n    const CDirItems &dirItems,\r\n    bool sfxMode,\r\n    const UString &sfxModule,\r\n    const CRecordVector<UInt64> &volumesSizes,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI *callback)\r\n{\r\n  CMyComPtr<IOutArchive> outArchive;\r\n  if(archive != NULL)\r\n  {\r\n    CMyComPtr<IInArchive> archive2 = archive;\r\n    HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);\r\n    if(result != S_OK)\r\n      throw kUpdateIsNotSupoorted;\r\n  }\r\n  else\r\n  {\r\n    RINOK(codecs->CreateOutArchive(compressionMethod.FormatIndex, outArchive));\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    {\r\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\r\n      outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\r\n      if (setCompressCodecsInfo)\r\n      {\r\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\r\n      }\r\n    }\r\n    #endif\r\n  }\r\n  if (outArchive == 0)\r\n    throw kUpdateIsNotSupoorted;\r\n  \r\n  NFileTimeType::EEnum fileTimeType;\r\n  UInt32 value;\r\n  RINOK(outArchive->GetFileTimeType(&value));\r\n\r\n  switch(value)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n    case NFileTimeType::kUnix:\r\n    case NFileTimeType::kDOS:\r\n      fileTimeType = (NFileTimeType::EEnum)value;\r\n      break;\r\n    default:\r\n      return E_FAIL;\r\n  }\r\n\r\n  CRecordVector<CUpdatePair2> updatePairs2;\r\n\r\n  {\r\n    CRecordVector<CUpdatePair> updatePairs;\r\n    GetUpdatePairInfoList(dirItems, arcItems, fileTimeType, updatePairs); // must be done only once!!!\r\n    // CUpdateProduceCallbackImp upCallback(&arcItems, callback);\r\n    UpdateProduce(updatePairs, actionSet, updatePairs2, NULL /* &upCallback */);\r\n  }\r\n\r\n  UInt32 numFiles = 0;\r\n  for (int i = 0; i < updatePairs2.Size(); i++)\r\n    if (updatePairs2[i].NewData)\r\n      numFiles++;\r\n  \r\n  RINOK(callback->SetNumFiles(numFiles));\r\n\r\n  \r\n  CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\r\n  CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);\r\n  \r\n  updateCallbackSpec->ShareForWrite = shareForWrite;\r\n  updateCallbackSpec->StdInMode = stdInMode;\r\n  updateCallbackSpec->Callback = callback;\r\n  updateCallbackSpec->DirItems = &dirItems;\r\n  updateCallbackSpec->ArcItems = &arcItems;\r\n  updateCallbackSpec->UpdatePairs = &updatePairs2;\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n\r\n  const UString &archiveName = archivePath.GetFinalPath();\r\n  if (!stdOutMode)\r\n  {\r\n    UString resultPath;\r\n    int pos;\r\n    if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))\r\n      throw 1417161;\r\n    NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));\r\n  }\r\n\r\n  COutFileStream *outStreamSpec = NULL;\r\n  COutMultiVolStream *volStreamSpec = NULL;\r\n\r\n  if (volumesSizes.Size() == 0)\r\n  {\r\n    if (stdOutMode)\r\n      outStream = new CStdOutFileStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      outStream = outStreamSpec;\r\n      bool isOK = false;\r\n      UString realPath;\r\n      for (int i = 0; i < (1 << 16); i++)\r\n      {\r\n        if (archivePath.Temp)\r\n        {\r\n          if (i > 0)\r\n          {\r\n            wchar_t s[32];\r\n            ConvertUInt64ToString(i, s);\r\n            archivePath.TempPostfix = s;\r\n          }\r\n          realPath = archivePath.GetTempPath();\r\n        }\r\n        else\r\n          realPath = archivePath.GetFinalPath();\r\n        if (outStreamSpec->Create(realPath, false))\r\n        {\r\n          tempFiles.Paths.Add(realPath);\r\n          isOK = true;\r\n          break;\r\n        }\r\n        if (::GetLastError() != ERROR_FILE_EXISTS)\r\n          break;\r\n        if (!archivePath.Temp)\r\n          break;\r\n      }\r\n      if (!isOK)\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (stdOutMode)\r\n      return E_FAIL;\r\n    volStreamSpec = new COutMultiVolStream;\r\n    outStream = volStreamSpec;\r\n    volStreamSpec->Sizes = volumesSizes;\r\n    volStreamSpec->Prefix = archivePath.GetFinalPath() + UString(L\".\");\r\n    volStreamSpec->TempFiles = &tempFiles;\r\n    volStreamSpec->Init();\r\n\r\n    /*\r\n    updateCallbackSpec->VolumesSizes = volumesSizes;\r\n    updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;\r\n    if (!archivePath.VolExtension.IsEmpty())\r\n      updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;\r\n    */\r\n  }\r\n\r\n  RINOK(SetProperties(outArchive, compressionMethod.Properties));\r\n\r\n  if (sfxMode)\r\n  {\r\n    CInFileStream *sfxStreamSpec = new CInFileStream;\r\n    CMyComPtr<IInStream> sfxStream(sfxStreamSpec);\r\n    if (!sfxStreamSpec->Open(sfxModule))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"Can't open sfx module\";\r\n      errorInfo.FileName = sfxModule;\r\n      return E_FAIL;\r\n    }\r\n\r\n    CMyComPtr<ISequentialOutStream> sfxOutStream;\r\n    COutFileStream *outStreamSpec = NULL;\r\n    if (volumesSizes.Size() == 0)\r\n      sfxOutStream = outStream;\r\n    else\r\n    {\r\n      outStreamSpec = new COutFileStream;\r\n      sfxOutStream = outStreamSpec;\r\n      UString realPath = archivePath.GetFinalPath();\r\n      if (!outStreamSpec->Create(realPath, false))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.FileName = realPath;\r\n        errorInfo.Message = L\"Can not open file\";\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    RINOK(CopyBlock(sfxStream, sfxOutStream));\r\n    if (outStreamSpec)\r\n    {\r\n      RINOK(outStreamSpec->Close());\r\n    }\r\n  }\r\n\r\n  HRESULT result = outArchive->UpdateItems(outStream, updatePairs2.Size(), updateCallback);\r\n  callback->Finilize();\r\n  RINOK(result);\r\n  if (outStreamSpec)\r\n    result = outStreamSpec->Close();\r\n  else if (volStreamSpec)\r\n    result = volStreamSpec->Close();\r\n  return result;\r\n}\r\n\r\nHRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,\r\n    IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\r\n    CObjectVector<CArcItem> &arcItems)\r\n{\r\n  arcItems.Clear();\r\n  UInt32 numItems;\r\n  RINOK(archive->GetNumberOfItems(&numItems));\r\n  arcItems.Reserve(numItems);\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    CArcItem ai;\r\n\r\n    RINOK(GetArchiveItemPath(archive, i, ai.Name));\r\n    // check it: defaultItemName !!!\r\n    if (ai.Name.IsEmpty())\r\n      ai.Name = defaultItemName;\r\n    RINOK(IsArchiveItemFolder(archive, i, ai.IsDir));\r\n    ai.Censored = censor.CheckPath(ai.Name, !ai.IsDir);\r\n    RINOK(GetArchiveItemFileTime(archive, i, archiveFileInfo.MTime, ai.MTime));\r\n\r\n    {\r\n      CPropVariant prop;\r\n      RINOK(archive->GetProperty(i, kpidSize, &prop));\r\n      ai.SizeDefined = (prop.vt != VT_EMPTY);\r\n      if (ai.SizeDefined)\r\n        ai.Size = ConvertPropVariantToUInt64(prop);\r\n    }\r\n\r\n    {\r\n      CPropVariant prop;\r\n      RINOK(archive->GetProperty(i, kpidTimeType, &prop));\r\n      if (prop.vt == VT_UI4)\r\n      {\r\n        ai.TimeType = (int)(NFileTimeType::EEnum)prop.ulVal;\r\n        switch(ai.TimeType)\r\n        {\r\n          case NFileTimeType::kWindows:\r\n          case NFileTimeType::kUnix:\r\n          case NFileTimeType::kDOS:\r\n            break;\r\n          default:\r\n            return E_FAIL;\r\n        }\r\n      }\r\n    }\r\n\r\n    ai.IndexInServer = i;\r\n    arcItems.Add(ai);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n\r\nstatic HRESULT UpdateWithItemLists(\r\n    CCodecs *codecs,\r\n    CUpdateOptions &options,\r\n    IInArchive *archive,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    CDirItems &dirItems,\r\n    CTempFiles &tempFiles,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CUpdateArchiveCommand &command = options.Commands[i];\r\n    if (options.StdOutMode)\r\n    {\r\n      RINOK(callback->StartArchive(0, archive != 0));\r\n    }\r\n    else\r\n    {\r\n      RINOK(callback->StartArchive(command.ArchivePath.GetFinalPath(),\r\n          i == 0 && options.UpdateArchiveItself && archive != 0));\r\n    }\r\n\r\n    RINOK(Compress(\r\n        codecs,\r\n        command.ActionSet, archive,\r\n        options.MethodMode,\r\n        command.ArchivePath,\r\n        arcItems,\r\n        options.OpenShareForWrite,\r\n        options.StdInMode,\r\n        /* options.StdInFileName, */\r\n        options.StdOutMode,\r\n        dirItems,\r\n        options.SfxMode, options.SfxModule,\r\n        options.VolumesSizes,\r\n        tempFiles,\r\n        errorInfo, callback));\r\n\r\n    RINOK(callback->FinishArchive());\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _WIN32\r\nclass CCurrentDirRestorer\r\n{\r\n  UString m_CurrentDirectory;\r\npublic:\r\n  CCurrentDirRestorer()\r\n    { NFile::NDirectory::MyGetCurrentDirectory(m_CurrentDirectory); }\r\n  ~CCurrentDirRestorer()\r\n    { RestoreDirectory();}\r\n  bool RestoreDirectory()\r\n    { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(m_CurrentDirectory)); }\r\n};\r\n#endif\r\n\r\nstruct CEnumDirItemUpdateCallback: public IEnumDirItemCallback\r\n{\r\n  IUpdateCallbackUI2 *Callback;\r\n  HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path)\r\n  {\r\n    return Callback->ScanProgress(numFolders, numFiles, path);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\ntypedef ULONG (FAR PASCAL MY_MAPISENDDOCUMENTS)(\r\n  ULONG_PTR ulUIParam,\r\n  LPSTR lpszDelimChar,\r\n  LPSTR lpszFilePaths,\r\n  LPSTR lpszFileNames,\r\n  ULONG ulReserved\r\n);\r\ntypedef MY_MAPISENDDOCUMENTS FAR *MY_LPMAPISENDDOCUMENTS;\r\n#endif\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor,\r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback)\r\n{\r\n  if (options.StdOutMode && options.EMailMode)\r\n    return E_FAIL;\r\n\r\n  if (options.VolumesSizes.Size() > 0 && (options.EMailMode || options.SfxMode))\r\n    return E_NOTIMPL;\r\n\r\n  if (options.SfxMode)\r\n  {\r\n    CProperty property;\r\n    property.Name = L\"rsfx\";\r\n    property.Value = L\"on\";\r\n    options.MethodMode.Properties.Add(property);\r\n    if (options.SfxModule.IsEmpty())\r\n    {\r\n      errorInfo.Message = L\"sfx file is not specified\";\r\n      return E_FAIL;\r\n    }\r\n    UString name = options.SfxModule;\r\n    if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))\r\n    {\r\n      errorInfo.Message = L\"can't find specified sfx module\";\r\n      return E_FAIL;\r\n    }\r\n  }\r\n\r\n  const UString archiveName = options.ArchivePath.GetFinalPath();\r\n\r\n  UString defaultItemName;\r\n  NFind::CFileInfoW archiveFileInfo;\r\n\r\n  CArchiveLink archiveLink;\r\n  IInArchive *archive = 0;\r\n  if (NFind::FindFile(archiveName, archiveFileInfo))\r\n  {\r\n    if (archiveFileInfo.IsDir())\r\n      throw \"there is no such archive\";\r\n    if (options.VolumesSizes.Size() > 0)\r\n      return E_NOTIMPL;\r\n    CIntVector formatIndices;\r\n    if (options.MethodMode.FormatIndex >= 0)\r\n      formatIndices.Add(options.MethodMode.FormatIndex);\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, openCallback);\r\n    if (result == E_ABORT)\r\n      return result;\r\n    RINOK(callback->OpenResult(archiveName, result));\r\n    RINOK(result);\r\n    if (archiveLink.VolumePaths.Size() > 1)\r\n    {\r\n      errorInfo.SystemError = (DWORD)E_NOTIMPL;\r\n      errorInfo.Message = L\"Updating for multivolume archives is not implemented\";\r\n      return E_NOTIMPL;\r\n    }\r\n    archive = archiveLink.GetArchive();\r\n    defaultItemName = archiveLink.GetDefaultItemName();\r\n  }\r\n  else\r\n  {\r\n    /*\r\n    if (archiveType.IsEmpty())\r\n      throw \"type of archive is not specified\";\r\n    */\r\n  }\r\n\r\n  CDirItems dirItems;\r\n  if (options.StdInMode)\r\n  {\r\n    CDirItem di;\r\n    di.Name = options.StdInFileName;\r\n    di.Size = (UInt64)(Int64)-1;\r\n    di.Attrib = 0;\r\n    NTime::GetCurUtcFileTime(di.MTime);\r\n    di.CTime = di.ATime = di.MTime;\r\n    dirItems.Items.Add(di);\r\n  }\r\n  else\r\n  {\r\n    bool needScanning = false;\r\n    for(int i = 0; i < options.Commands.Size(); i++)\r\n      if (options.Commands[i].ActionSet.NeedScanning())\r\n        needScanning = true;\r\n    if (needScanning)\r\n    {\r\n      CEnumDirItemUpdateCallback enumCallback;\r\n      enumCallback.Callback = callback;\r\n      RINOK(callback->StartScanning());\r\n      UStringVector errorPaths;\r\n      CRecordVector<DWORD> errorCodes;\r\n      HRESULT res = EnumerateItems(censor, dirItems, &enumCallback, errorPaths, errorCodes);\r\n      for (int i = 0; i < errorPaths.Size(); i++)\r\n      {\r\n        RINOK(callback->CanNotFindError(errorPaths[i], errorCodes[i]));\r\n      }\r\n      if (res != S_OK)\r\n      {\r\n        if (res != E_ABORT)\r\n          errorInfo.Message = L\"Scanning error\";\r\n        // errorInfo.FileName = errorPath;\r\n        return res;\r\n      }\r\n      RINOK(callback->FinishScanning());\r\n    }\r\n  }\r\n\r\n  UString tempDirPrefix;\r\n  bool usesTempDir = false;\r\n  \r\n  #ifdef _WIN32\r\n  NDirectory::CTempDirectoryW tempDirectory;\r\n  if (options.EMailMode && options.EMailRemoveAfter)\r\n  {\r\n    tempDirectory.Create(kTempFolderPrefix);\r\n    tempDirPrefix = tempDirectory.GetPath();\r\n    NormalizeDirPathPrefix(tempDirPrefix);\r\n    usesTempDir = true;\r\n  }\r\n  #endif\r\n\r\n  CTempFiles tempFiles;\r\n\r\n  bool createTempFile = false;\r\n  if(!options.StdOutMode && options.UpdateArchiveItself)\r\n  {\r\n    CArchivePath &ap = options.Commands[0].ArchivePath;\r\n    ap = options.ArchivePath;\r\n    // if ((archive != 0 && !usesTempDir) || !options.WorkingDir.IsEmpty())\r\n    if ((archive != 0 || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)\r\n    {\r\n      createTempFile = true;\r\n      ap.Temp = true;\r\n      if (!options.WorkingDir.IsEmpty())\r\n      {\r\n        ap.TempPrefix = options.WorkingDir;\r\n        NormalizeDirPathPrefix(ap.TempPrefix);\r\n      }\r\n    }\r\n  }\r\n\r\n  for(int i = 0; i < options.Commands.Size(); i++)\r\n  {\r\n    CArchivePath &ap = options.Commands[i].ArchivePath;\r\n    if (usesTempDir)\r\n    {\r\n      // Check it\r\n      ap.Prefix = tempDirPrefix;\r\n      // ap.Temp = true;\r\n      // ap.TempPrefix = tempDirPrefix;\r\n    }\r\n    if (i > 0 || !createTempFile)\r\n    {\r\n      const UString &path = ap.GetFinalPath();\r\n      if (NFind::DoesFileExist(path))\r\n      {\r\n        errorInfo.SystemError = 0;\r\n        errorInfo.Message = L\"File already exists\";\r\n        errorInfo.FileName = path;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n  }\r\n\r\n  CObjectVector<CArcItem> arcItems;\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(EnumerateInArchiveItems(censor,\r\n        archive, defaultItemName, archiveFileInfo, arcItems));\r\n  }\r\n\r\n  RINOK(UpdateWithItemLists(codecs, options, archive, arcItems, dirItems,\r\n      tempFiles, errorInfo, callback));\r\n\r\n  if (archive != NULL)\r\n  {\r\n    RINOK(archiveLink.Close());\r\n    archiveLink.Release();\r\n  }\r\n\r\n  tempFiles.Paths.Clear();\r\n  if(createTempFile)\r\n  {\r\n    try\r\n    {\r\n      CArchivePath &ap = options.Commands[0].ArchivePath;\r\n      const UString &tempPath = ap.GetTempPath();\r\n      if (archive != NULL)\r\n        if (!NDirectory::DeleteFileAlways(archiveName))\r\n        {\r\n          errorInfo.SystemError = ::GetLastError();\r\n          errorInfo.Message = L\"delete file error\";\r\n          errorInfo.FileName = archiveName;\r\n          return E_FAIL;\r\n        }\r\n      if (!NDirectory::MyMoveFile(tempPath, archiveName))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        errorInfo.Message = L\"move file error\";\r\n        errorInfo.FileName = tempPath;\r\n        errorInfo.FileName2 = archiveName;\r\n        return E_FAIL;\r\n      }\r\n    }\r\n    catch(...)\r\n    {\r\n      throw;\r\n    }\r\n  }\r\n\r\n  #ifdef _WIN32\r\n  if (options.EMailMode)\r\n  {\r\n    NDLL::CLibrary mapiLib;\r\n    if (!mapiLib.Load(TEXT(\"Mapi32.dll\")))\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not load Mapi32.dll\";\r\n      return E_FAIL;\r\n    }\r\n    MY_LPMAPISENDDOCUMENTS fnSend = (MY_LPMAPISENDDOCUMENTS)\r\n        mapiLib.GetProcAddress(\"MAPISendDocuments\");\r\n    if (fnSend == 0)\r\n    {\r\n      errorInfo.SystemError = ::GetLastError();\r\n      errorInfo.Message = L\"can not find MAPISendDocuments function\";\r\n      return E_FAIL;\r\n    }\r\n    UStringVector fullPaths;\r\n    int i;\r\n    for(i = 0; i < options.Commands.Size(); i++)\r\n    {\r\n      CArchivePath &ap = options.Commands[i].ArchivePath;\r\n      UString arcPath;\r\n      if(!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))\r\n      {\r\n        errorInfo.SystemError = ::GetLastError();\r\n        return E_FAIL;\r\n      }\r\n      fullPaths.Add(arcPath);\r\n    }\r\n    CCurrentDirRestorer curDirRestorer;\r\n    for(i = 0; i < fullPaths.Size(); i++)\r\n    {\r\n      UString arcPath = fullPaths[i];\r\n      UString fileName = ExtractFileNameFromPath(arcPath);\r\n      AString path = GetAnsiString(arcPath);\r\n      AString name = GetAnsiString(fileName);\r\n      // Warning!!! MAPISendDocuments function changes Current directory\r\n      fnSend(0, \";\", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0);\r\n    }\r\n  }\r\n  #endif\r\n  return S_OK;\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/Update.h",
    "content": "// Update.h\r\n\r\n#ifndef __UPDATE_H\r\n#define __UPDATE_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n#include \"ArchiveOpenCallback.h\"\r\n#include \"UpdateCallback.h\"\r\n#include \"Property.h\"\r\n#include \"LoadCodecs.h\"\r\n\r\nstruct CArchivePath\r\n{\r\n  UString Prefix;   // path(folder) prefix including slash\r\n  UString Name; // base name\r\n  UString BaseExtension; // archive type extension or \"exe\" extension\r\n  UString VolExtension;  // archive type extension for volumes\r\n\r\n  bool Temp;\r\n  UString TempPrefix;  // path(folder) for temp location\r\n  UString TempPostfix;\r\n\r\n  CArchivePath(): Temp(false) {};\r\n  \r\n  void ParseFromPath(const UString &path)\r\n  {\r\n    SplitPathToParts(path, Prefix, Name);\r\n    if (Name.IsEmpty())\r\n      return;\r\n    int dotPos = Name.ReverseFind(L'.');\r\n    if (dotPos <= 0)\r\n      return;\r\n    if (dotPos == Name.Length() - 1)\r\n    {\r\n      Name = Name.Left(dotPos);\r\n      BaseExtension.Empty();\r\n      return;\r\n    }\r\n    if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0)\r\n    {\r\n      BaseExtension = Name.Mid(dotPos + 1);\r\n      Name = Name.Left(dotPos);\r\n    }\r\n    else\r\n      BaseExtension.Empty();\r\n  }\r\n\r\n  UString GetPathWithoutExt() const\r\n  {\r\n    return Prefix + Name;\r\n  }\r\n\r\n  UString GetFinalPath() const\r\n  {\r\n    UString path = GetPathWithoutExt();\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    return path;\r\n  }\r\n\r\n  \r\n  UString GetTempPath() const\r\n  {\r\n    UString path = TempPrefix + Name;\r\n    if (!BaseExtension.IsEmpty())\r\n      path += UString(L'.') + BaseExtension;\r\n    path += L\".tmp\";\r\n    path += TempPostfix;\r\n    return path;\r\n  }\r\n};\r\n\r\nstruct CUpdateArchiveCommand\r\n{\r\n  UString UserArchivePath;\r\n  CArchivePath ArchivePath;\r\n  NUpdateArchive::CActionSet ActionSet;\r\n};\r\n\r\nstruct CCompressionMethodMode\r\n{\r\n  int FormatIndex;\r\n  CObjectVector<CProperty> Properties;\r\n  CCompressionMethodMode(): FormatIndex(-1) {}\r\n};\r\n\r\nstruct CUpdateOptions\r\n{\r\n  CCompressionMethodMode MethodMode;\r\n\r\n  CObjectVector<CUpdateArchiveCommand> Commands;\r\n  bool UpdateArchiveItself;\r\n  CArchivePath ArchivePath;\r\n  \r\n  bool SfxMode;\r\n  UString SfxModule;\r\n  \r\n  bool OpenShareForWrite;\r\n\r\n  bool StdInMode;\r\n  UString StdInFileName;\r\n  bool StdOutMode;\r\n  \r\n  bool EMailMode;\r\n  bool EMailRemoveAfter;\r\n  UString EMailAddress;\r\n\r\n  UString WorkingDir;\r\n\r\n  bool Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath);\r\n\r\n  CUpdateOptions():\r\n    UpdateArchiveItself(true),\r\n    SfxMode(false),\r\n    StdInMode(false),\r\n    StdOutMode(false),\r\n    EMailMode(false),\r\n    EMailRemoveAfter(false),\r\n    OpenShareForWrite(false)\r\n      {};\r\n  CRecordVector<UInt64> VolumesSizes;\r\n};\r\n\r\nstruct CErrorInfo\r\n{\r\n  DWORD SystemError;\r\n  UString FileName;\r\n  UString FileName2;\r\n  UString Message;\r\n  // UStringVector ErrorPaths;\r\n  // CRecordVector<DWORD> ErrorCodes;\r\n  CErrorInfo(): SystemError(0) {};\r\n};\r\n\r\nstruct CUpdateErrorInfo: public CErrorInfo\r\n{\r\n};\r\n\r\n#define INTERFACE_IUpdateCallbackUI2(x) \\\r\n  INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \\\r\n  virtual HRESULT StartScanning() x; \\\r\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) x; \\\r\n  virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT FinishScanning() x; \\\r\n  virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \\\r\n  virtual HRESULT FinishArchive() x; \\\r\n\r\nstruct IUpdateCallbackUI2: public IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI2(=0)\r\n};\r\n\r\nHRESULT UpdateArchive(\r\n    CCodecs *codecs,\r\n    const NWildcard::CCensor &censor,\r\n    CUpdateOptions &options,\r\n    CUpdateErrorInfo &errorInfo,\r\n    IOpenCallbackUI *openCallback,\r\n    IUpdateCallbackUI2 *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/UpdateAction.cpp",
    "content": "// UpdateAction.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateAction.h\"\r\n\r\nnamespace NUpdateArchive {\r\n\r\nconst CActionSet kAddActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kUpdateActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kFreshActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress\r\n};\r\n\r\nconst CActionSet kSynchronizeActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n  NPairAction::kCopy,\r\n  NPairAction::kCompress,\r\n};\r\n\r\nconst CActionSet kDeleteActionSet =\r\n{\r\n  NPairAction::kCopy,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore,\r\n  NPairAction::kIgnore\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/UpdateAction.h",
    "content": "// UpdateAction.h\r\n\r\n#ifndef __UPDATE_ACTION_H\r\n#define __UPDATE_ACTION_H\r\n\r\nnamespace NUpdateArchive {\r\n\r\n  namespace NPairState\r\n  {\r\n    const int kNumValues = 7;\r\n    enum EEnum\r\n    {\r\n      kNotMasked = 0,\r\n      kOnlyInArchive,\r\n      kOnlyOnDisk,\r\n      kNewInArchive,\r\n      kOldInArchive,\r\n      kSameFiles,\r\n      kUnknowNewerFiles\r\n    };\r\n  }\r\n  namespace NPairAction\r\n  {\r\n    enum EEnum\r\n    {\r\n      kIgnore = 0,\r\n      kCopy,\r\n      kCompress,\r\n      kCompressAsAnti\r\n    };\r\n  }\r\n  struct CActionSet\r\n  {\r\n    NPairAction::EEnum StateActions[NPairState::kNumValues];\r\n    bool NeedScanning() const\r\n    {\r\n      int i;\r\n      for (i = 0; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] == NPairAction::kCompress)\r\n          return true;\r\n      for (i = 1; i < NPairState::kNumValues; i++)\r\n        if (StateActions[i] != NPairAction::kIgnore)\r\n          return true;\r\n      return false;\r\n    }\r\n  };\r\n  extern const CActionSet kAddActionSet;\r\n  extern const CActionSet kUpdateActionSet;\r\n  extern const CActionSet kFreshActionSet;\r\n  extern const CActionSet kSynchronizeActionSet;\r\n  extern const CActionSet kDeleteActionSet;\r\n};\r\n\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/UpdateCallback.cpp",
    "content": "// UpdateCallback.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallback.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/Defs.h\"\r\n#include \"Common/ComTry.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCArchiveUpdateCallback::CArchiveUpdateCallback():\r\n  Callback(0),\r\n  ShareForWrite(false),\r\n  StdInMode(false),\r\n  DirItems(0),\r\n  ArcItems(0),\r\n  UpdatePairs(0),\r\n  NewNames(0)\r\n  {}\r\n\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetTotal(size);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetCompleted(completeValue);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetRatioInfo(inSize, outSize);\r\n  COM_TRY_END\r\n}\r\n\r\n\r\n/*\r\nSTATPROPSTG kProperties[] =\r\n{\r\n  { NULL, kpidPath, VT_BSTR},\r\n  { NULL, kpidIsDir, VT_BOOL},\r\n  { NULL, kpidSize, VT_UI8},\r\n  { NULL, kpidCTime, VT_FILETIME},\r\n  { NULL, kpidATime, VT_FILETIME},\r\n  { NULL, kpidMTime, VT_FILETIME},\r\n  { NULL, kpidAttrib, VT_UI4},\r\n  { NULL, kpidIsAnti, VT_BOOL}\r\n};\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)\r\n{\r\n  return CStatPropEnumerator::CreateEnumerator(kProperties, sizeof(kProperties) / sizeof(kProperties[0]), enumerator);\r\n}\r\n*/\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,\r\n      Int32 *newData, Int32 *newProps, UInt32 *indexInArchive)\r\n{\r\n  COM_TRY_BEGIN\r\n  RINOK(Callback->CheckBreak());\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  if (newData != NULL) *newData = BoolToInt(up.NewData);\r\n  if (newProps != NULL) *newProps = BoolToInt(up.NewProps);\r\n  if (indexInArchive != NULL)\r\n  {\r\n    *indexInArchive = (UInt32)-1;\r\n    if (up.ExistInArchive())\r\n      *indexInArchive = (ArcItems == 0) ? up.ArcIndex : (*ArcItems)[up.ArcIndex].IndexInServer;\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  NWindows::NCOM::CPropVariant prop;\r\n  \r\n  if (propID == kpidIsAnti)\r\n  {\r\n    prop = up.IsAnti;\r\n    prop.Detach(value);\r\n    return S_OK;\r\n  }\r\n\r\n  if (up.IsAnti)\r\n  {\r\n    switch(propID)\r\n    {\r\n      case kpidIsDir:\r\n      case kpidPath:\r\n        break;\r\n      case kpidSize:\r\n        prop = (UInt64)0;\r\n        prop.Detach(value);\r\n        return S_OK;\r\n      default:\r\n        prop.Detach(value);\r\n        return S_OK;\r\n    }\r\n  }\r\n  \r\n  if (up.ExistOnDisk())\r\n  {\r\n    const CDirItem &di = DirItems->Items[up.DirIndex];\r\n    switch(propID)\r\n    {\r\n      case kpidPath:  prop = DirItems->GetLogPath(up.DirIndex); break;\r\n      case kpidIsDir:  prop = di.IsDir(); break;\r\n      case kpidSize:  prop = di.Size; break;\r\n      case kpidAttrib:  prop = di.Attrib; break;\r\n      case kpidCTime:  prop = di.CTime; break;\r\n      case kpidATime:  prop = di.ATime; break;\r\n      case kpidMTime:  prop = di.MTime; break;\r\n    }\r\n  }\r\n  else\r\n  {\r\n    if (propID == kpidPath)\r\n    {\r\n      if (up.NewNameIndex >= 0)\r\n      {\r\n        prop = (*NewNames)[up.NewNameIndex];\r\n        prop.Detach(value);\r\n        return S_OK;\r\n      }\r\n    }\r\n    if (up.ExistInArchive() && Archive)\r\n    {\r\n      UInt32 indexInArchive;\r\n      if (ArcItems == 0)\r\n        indexInArchive = up.ArcIndex;\r\n      else\r\n        indexInArchive = (*ArcItems)[up.ArcIndex].IndexInServer;\r\n      return Archive->GetProperty(indexInArchive, propID, value);\r\n    }\r\n  }\r\n  prop.Detach(value);\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\r\n  if (!up.NewData)\r\n    return E_FAIL;\r\n  \r\n  RINOK(Callback->CheckBreak());\r\n  RINOK(Callback->Finilize());\r\n\r\n  if (up.IsAnti)\r\n  {\r\n    return Callback->GetStream((*ArcItems)[up.ArcIndex].Name, true);\r\n  }\r\n  const CDirItem &di = DirItems->Items[up.DirIndex];\r\n  RINOK(Callback->GetStream(DirItems->GetLogPath(up.DirIndex), false));\r\n \r\n  if (di.IsDir())\r\n    return S_OK;\r\n\r\n  if (StdInMode)\r\n  {\r\n    CStdInFileStream *inStreamSpec = new CStdInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  else\r\n  {\r\n    CInFileStream *inStreamSpec = new CInFileStream;\r\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\r\n    const UString path = DirItems->GetPhyPath(up.DirIndex);\r\n    if (!inStreamSpec->OpenShared(path, ShareForWrite))\r\n    {\r\n      return Callback->OpenFileError(path, ::GetLastError());\r\n    }\r\n    *inStream = inStreamLoc.Detach();\r\n  }\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->SetOperationResult(operationResult);\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\r\n{\r\n  if (VolumesSizes.Size() == 0)\r\n    return S_FALSE;\r\n  if (index >= (UInt32)VolumesSizes.Size())\r\n    index = VolumesSizes.Size() - 1;\r\n  *size = VolumesSizes[index];\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\r\n{\r\n  COM_TRY_BEGIN\r\n  wchar_t temp[32];\r\n  ConvertUInt64ToString(index + 1, temp);\r\n  UString res = temp;\r\n  while (res.Length() < 2)\r\n    res = UString(L'0') + res;\r\n  UString fileName = VolName;\r\n  fileName += L'.';\r\n  fileName += res;\r\n  fileName += VolExt;\r\n  COutFileStream *streamSpec = new COutFileStream;\r\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\r\n  if (!streamSpec->Create(fileName, false))\r\n    return ::GetLastError();\r\n  *volumeStream = streamLoc.Detach();\r\n  return S_OK;\r\n  COM_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  COM_TRY_BEGIN\r\n  return Callback->CryptoGetTextPassword2(passwordIsDefined, password);\r\n  COM_TRY_END\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/UpdateCallback.h",
    "content": "// UpdateCallback.h\r\n\r\n#ifndef __UPDATECALLBACK_H\r\n#define __UPDATECALLBACK_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n#include \"../Common/UpdatePair.h\"\r\n#include \"../Common/UpdateProduce.h\"\r\n\r\n#define INTERFACE_IUpdateCallbackUI(x) \\\r\n  virtual HRESULT SetTotal(UInt64 size) x; \\\r\n  virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \\\r\n  virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x; \\\r\n  virtual HRESULT CheckBreak() x; \\\r\n  virtual HRESULT Finilize() x; \\\r\n  virtual HRESULT SetNumFiles(UInt64 numFiles) x; \\\r\n  virtual HRESULT GetStream(const wchar_t *name, bool isAnti) x; \\\r\n  virtual HRESULT OpenFileError(const wchar_t *name, DWORD systemError) x; \\\r\n  virtual HRESULT SetOperationResult(Int32 operationResult) x; \\\r\n  virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x; \\\r\n  // virtual HRESULT ShowDeleteFile(const wchar_t *name) x; \\\r\n  // virtual HRESULT CloseProgress() { return S_OK; };\r\n\r\nstruct IUpdateCallbackUI\r\n{\r\n  INTERFACE_IUpdateCallbackUI(=0)\r\n};\r\n\r\nclass CArchiveUpdateCallback:\r\n  public IArchiveUpdateCallback2,\r\n  public ICryptoGetTextPassword2,\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP3(\r\n      IArchiveUpdateCallback2,\r\n      ICryptoGetTextPassword2,\r\n      ICompressProgressInfo)\r\n\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n\r\n  INTERFACE_IArchiveUpdateCallback2(;)\r\n\r\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\r\n\r\npublic:\r\n  CRecordVector<UInt64> VolumesSizes;\r\n  UString VolName;\r\n  UString VolExt;\r\n\r\n  IUpdateCallbackUI *Callback;\r\n\r\n  bool ShareForWrite;\r\n  bool StdInMode;\r\n  const CDirItems *DirItems;\r\n  const CObjectVector<CArcItem> *ArcItems;\r\n  const CRecordVector<CUpdatePair2> *UpdatePairs;\r\n  const UStringVector *NewNames;\r\n  CMyComPtr<IInArchive> Archive;\r\n\r\n  CArchiveUpdateCallback();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/UpdatePair.cpp",
    "content": "// UpdatePair.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <time.h>\r\n\r\n#include \"Common/Defs.h\"\r\n#include \"Common/Wildcard.h\"\r\n#include \"Windows/Time.h\"\r\n\r\n#include \"UpdatePair.h\"\r\n#include \"SortUtils.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NTime;\r\n\r\nstatic int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time1, const FILETIME &time2)\r\n{\r\n  switch(fileTimeType)\r\n  {\r\n    case NFileTimeType::kWindows:\r\n      return ::CompareFileTime(&time1, &time2);\r\n    case NFileTimeType::kUnix:\r\n      {\r\n        UInt32 unixTime1, unixTime2;\r\n        FileTimeToUnixTime(time1, unixTime1);\r\n        FileTimeToUnixTime(time2, unixTime2);\r\n        return MyCompare(unixTime1, unixTime2);\r\n      }\r\n    case NFileTimeType::kDOS:\r\n      {\r\n        UInt32 dosTime1, dosTime2;\r\n        FileTimeToDosTime(time1, dosTime1);\r\n        FileTimeToDosTime(time2, dosTime2);\r\n        return MyCompare(dosTime1, dosTime2);\r\n      }\r\n  }\r\n  throw 4191618;\r\n}\r\n\r\nstatic const wchar_t *kDuplicateFileNameMessage = L\"Duplicate filename:\";\r\nstatic const wchar_t *kNotCensoredCollisionMessaged = L\"Internal file name collision (file on disk, file in archive):\";\r\n\r\nstatic void ThrowError(const UString &message, const UString &s1, const UString &s2)\r\n{\r\n  UString m = message;\r\n  m += L'\\n';\r\n  m += s1;\r\n  m += L'\\n';\r\n  m += s2;\r\n  throw m;\r\n}\r\n\r\nstatic void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)\r\n{\r\n  for(int i = 0; i + 1 < indices.Size(); i++)\r\n    if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)\r\n      ThrowError(kDuplicateFileNameMessage, strings[indices[i]], strings[indices[i + 1]]);\r\n}\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CDirItems &dirItems,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CRecordVector<CUpdatePair> &updatePairs)\r\n{\r\n  CIntVector dirIndices, arcIndices;\r\n  \r\n  int numDirItems = dirItems.Items.Size();\r\n  int numArcItems = arcItems.Size();\r\n  \r\n  \r\n  {\r\n    UStringVector arcNames;\r\n    arcNames.Reserve(numArcItems);\r\n    for (int i = 0; i < numArcItems; i++)\r\n      arcNames.Add(arcItems[i].Name);\r\n    SortFileNames(arcNames, arcIndices);\r\n    TestDuplicateString(arcNames, arcIndices);\r\n  }\r\n\r\n  UStringVector dirNames;\r\n  {\r\n    dirNames.Reserve(numDirItems);\r\n    for (int i = 0; i < numDirItems; i++)\r\n      dirNames.Add(dirItems.GetLogPath(i));\r\n    SortFileNames(dirNames, dirIndices);\r\n    TestDuplicateString(dirNames, dirIndices);\r\n  }\r\n  \r\n  int dirIndex = 0, arcIndex = 0;\r\n  while (dirIndex < numDirItems && arcIndex < numArcItems)\r\n  {\r\n    CUpdatePair pair;\r\n    int dirIndex2 = dirIndices[dirIndex];\r\n    int arcIndex2 = arcIndices[arcIndex];\r\n    const CDirItem &di = dirItems.Items[dirIndex2];\r\n    const CArcItem &ai = arcItems[arcIndex2];\r\n    int compareResult = CompareFileNames(dirNames[dirIndex2], ai.Name);\r\n    if (compareResult < 0)\r\n    {\r\n      pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n      pair.DirIndex = dirIndex2;\r\n      dirIndex++;\r\n    }\r\n    else if (compareResult > 0)\r\n    {\r\n      pair.State = ai.Censored ?\r\n          NUpdateArchive::NPairState::kOnlyInArchive:\r\n          NUpdateArchive::NPairState::kNotMasked;\r\n      pair.ArcIndex = arcIndex2;\r\n      arcIndex++;\r\n    }\r\n    else\r\n    {\r\n      if (!ai.Censored)\r\n        ThrowError(kNotCensoredCollisionMessaged, dirNames[dirIndex2], ai.Name);\r\n      pair.DirIndex = dirIndex2;\r\n      pair.ArcIndex = arcIndex2;\r\n      switch (MyCompareTime(\r\n          ai.TimeType != - 1 ? (NFileTimeType::EEnum)ai.TimeType : fileTimeType,\r\n          di.MTime, ai.MTime))\r\n      {\r\n        case -1: pair.State = NUpdateArchive::NPairState::kNewInArchive; break;\r\n        case 1:  pair.State = NUpdateArchive::NPairState::kOldInArchive; break;\r\n        default:\r\n          if (ai.SizeDefined)\r\n            if (di.Size != ai.Size)\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n            else\r\n              pair.State = NUpdateArchive::NPairState::kSameFiles;\r\n          else\r\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\r\n      }\r\n      dirIndex++;\r\n      arcIndex++;\r\n    }\r\n    updatePairs.Add(pair);\r\n  }\r\n\r\n  for (; dirIndex < numDirItems; dirIndex++)\r\n  {\r\n    CUpdatePair pair;\r\n    pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\r\n    pair.DirIndex = dirIndices[dirIndex];\r\n    updatePairs.Add(pair);\r\n  }\r\n  \r\n  for (; arcIndex < numArcItems; arcIndex++)\r\n  {\r\n    CUpdatePair pair;\r\n    int arcIndex2 = arcIndices[arcIndex];\r\n    pair.State = arcItems[arcIndex2].Censored ?\r\n        NUpdateArchive::NPairState::kOnlyInArchive:\r\n        NUpdateArchive::NPairState::kNotMasked;\r\n    pair.ArcIndex = arcIndex2;\r\n    updatePairs.Add(pair);\r\n  }\r\n\r\n  updatePairs.ReserveDown();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/UpdatePair.h",
    "content": "// UpdatePair.h\r\n\r\n#ifndef __UPDATE_PAIR_H\r\n#define __UPDATE_PAIR_H\r\n\r\n#include \"DirItem.h\"\r\n#include \"UpdateAction.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\nstruct CUpdatePair\r\n{\r\n  NUpdateArchive::NPairState::EEnum State;\r\n  int ArcIndex;\r\n  int DirIndex;\r\n  CUpdatePair(): ArcIndex(-1), DirIndex(-1) {}\r\n};\r\n\r\nvoid GetUpdatePairInfoList(\r\n    const CDirItems &dirItems,\r\n    const CObjectVector<CArcItem> &arcItems,\r\n    NFileTimeType::EEnum fileTimeType,\r\n    CRecordVector<CUpdatePair> &updatePairs);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/UpdateProduce.cpp",
    "content": "// UpdateProduce.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateProduce.h\"\r\n\r\nusing namespace NUpdateArchive;\r\n\r\nstatic const char *kUpdateActionSetCollision = \"Internal collision in update action set\";\r\n\r\nvoid UpdateProduce(\r\n    const CRecordVector<CUpdatePair> &updatePairs,\r\n    const CActionSet &actionSet,\r\n    CRecordVector<CUpdatePair2> &operationChain,\r\n    IUpdateProduceCallback *callback)\r\n{\r\n  for (int i = 0; i < updatePairs.Size(); i++)\r\n  {\r\n    const CUpdatePair &pair = updatePairs[i];\r\n\r\n    CUpdatePair2 up2;\r\n    up2.IsAnti = false;\r\n    up2.DirIndex = pair.DirIndex;\r\n    up2.ArcIndex = pair.ArcIndex;\r\n    up2.NewData = up2.NewProps = true;\r\n    \r\n    switch(actionSet.StateActions[pair.State])\r\n    {\r\n      case NPairAction::kIgnore:\r\n        /*\r\n        if (pair.State != NPairState::kOnlyOnDisk)\r\n          IgnoreArchiveItem(m_ArchiveItems[pair.ArcIndex]);\r\n        // cout << \"deleting\";\r\n        */\r\n        if (callback)\r\n          callback->ShowDeleteFile(pair.ArcIndex);\r\n        continue;\r\n\r\n      case NPairAction::kCopy:\r\n        if (pair.State == NPairState::kOnlyOnDisk)\r\n          throw kUpdateActionSetCollision;\r\n        up2.NewData = up2.NewProps = false;\r\n        break;\r\n      \r\n      case NPairAction::kCompress:\r\n        if (pair.State == NPairState::kOnlyInArchive ||\r\n            pair.State == NPairState::kNotMasked)\r\n          throw kUpdateActionSetCollision;\r\n        break;\r\n      \r\n      case NPairAction::kCompressAsAnti:\r\n        up2.IsAnti = true;\r\n        break;\r\n    }\r\n    operationChain.Add(up2);\r\n  }\r\n  operationChain.ReserveDown();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/UpdateProduce.h",
    "content": "// UpdateProduce.h\r\n\r\n#ifndef __UPDATE_PRODUCE_H\r\n#define __UPDATE_PRODUCE_H\r\n\r\n#include \"UpdatePair.h\"\r\n\r\nstruct CUpdatePair2\r\n{\r\n  bool NewData;\r\n  bool NewProps;\r\n  bool IsAnti;\r\n  \r\n  int DirIndex;\r\n  int ArcIndex;\r\n  int NewNameIndex;\r\n\r\n  bool ExistOnDisk() const { return DirIndex != -1; }\r\n  bool ExistInArchive() const { return ArcIndex != -1; }\r\n\r\n  CUpdatePair2(): IsAnti(false), DirIndex(-1), ArcIndex(-1), NewNameIndex(-1) {}\r\n};\r\n\r\nstruct IUpdateProduceCallback\r\n{\r\n  virtual HRESULT ShowDeleteFile(int arcIndex) = 0;\r\n};\r\n\r\nvoid UpdateProduce(\r\n    const CRecordVector<CUpdatePair> &updatePairs,\r\n    const NUpdateArchive::CActionSet &actionSet,\r\n    CRecordVector<CUpdatePair2> &operationChain,\r\n    IUpdateProduceCallback *callback);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/WorkDir.cpp",
    "content": "// WorkDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"WorkDir.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/FileDir.h\"\r\n\r\nstatic inline UINT GetCurrentCodePage()\r\n  { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NName;\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)\r\n{\r\n  NWorkDir::NMode::EEnum mode = workDirInfo.Mode;\r\n  if (workDirInfo.ForRemovableOnly)\r\n  {\r\n    mode = NWorkDir::NMode::kCurrent;\r\n    UString prefix = path.Left(3);\r\n    if (prefix[1] == L':' && prefix[2] == L'\\\\')\r\n    {\r\n      UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));\r\n      if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)\r\n        mode = workDirInfo.Mode;\r\n    }\r\n    /*\r\n    CParsedPath parsedPath;\r\n    parsedPath.ParsePath(archiveName);\r\n    UINT driveType = GetDriveType(parsedPath.Prefix);\r\n    if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))\r\n      mode = NZipSettings::NWorkDir::NMode::kCurrent;\r\n    */\r\n  }\r\n  switch(mode)\r\n  {\r\n    case NWorkDir::NMode::kCurrent:\r\n    {\r\n      return ExtractDirPrefixFromPath(path);\r\n    }\r\n    case NWorkDir::NMode::kSpecified:\r\n    {\r\n      UString tempDir = workDirInfo.Path;\r\n      NormalizeDirPathPrefix(tempDir);\r\n      return tempDir;\r\n    }\r\n    default:\r\n    {\r\n      UString tempDir;\r\n      if(!NFile::NDirectory::MyGetTempPath(tempDir))\r\n        throw 141717;\r\n      return tempDir;\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/WorkDir.h",
    "content": "// WorkDir.h\r\n\r\n#ifndef __WORKDIR_H\r\n#define __WORKDIR_H\r\n\r\n#include \"ZipRegistry.h\"\r\n\r\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Common/ZipRegistry.h",
    "content": "// ZipRegistry.h\r\n\r\n#ifndef __ZIPREGISTRY_H\r\n#define __ZIPREGISTRY_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/Types.h\"\r\n#include \"ExtractMode.h\"\r\n\r\nnamespace NExtract\r\n{\r\n  struct CInfo\r\n  {\r\n    NPathMode::EEnum PathMode;\r\n    NOverwriteMode::EEnum OverwriteMode;\r\n    UStringVector Paths;\r\n    bool ShowPassword;\r\n  };\r\n}\r\n\r\nnamespace NCompression {\r\n  \r\n  struct CFormatOptions\r\n  {\r\n    CSysString FormatID;\r\n    UString Options;\r\n    UString Method;\r\n    UString EncryptionMethod;\r\n    UInt32 Level;\r\n    UInt32 Dictionary;\r\n    UInt32 Order;\r\n    UInt32 BlockLogSize;\r\n    UInt32 NumThreads;\r\n    void ResetForLevelChange()\r\n    {\r\n      BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1);\r\n      Method.Empty();\r\n      // EncryptionMethod.Empty();\r\n      // Options.Empty();\r\n    }\r\n    CFormatOptions() { ResetForLevelChange(); }\r\n  };\r\n\r\n  struct CInfo\r\n  {\r\n    UStringVector HistoryArchives;\r\n    UInt32 Level;\r\n    UString ArchiveType;\r\n\r\n    CObjectVector<CFormatOptions> FormatOptionsVector;\r\n\r\n    bool ShowPassword;\r\n    bool EncryptHeaders;\r\n  };\r\n}\r\n\r\nnamespace NWorkDir{\r\n  \r\n  namespace NMode\r\n  {\r\n    enum EEnum\r\n    {\r\n      kSystem,\r\n      kCurrent,\r\n      kSpecified\r\n    };\r\n  }\r\n  struct CInfo\r\n  {\r\n    NMode::EEnum Mode;\r\n    UString Path;\r\n    bool ForRemovableOnly;\r\n    void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }\r\n    void SetDefault()\r\n    {\r\n      Mode = NMode::kSystem;\r\n      Path.Empty();\r\n      SetForRemovableOnlyDefault();\r\n    }\r\n  };\r\n}\r\n\r\nvoid SaveExtractionInfo(const NExtract::CInfo &info);\r\nvoid ReadExtractionInfo(NExtract::CInfo &info);\r\n\r\nvoid SaveCompressionInfo(const NCompression::CInfo &info);\r\nvoid ReadCompressionInfo(NCompression::CInfo &info);\r\n\r\nvoid SaveWorkDirInfo(const NWorkDir::CInfo &info);\r\nvoid ReadWorkDirInfo(NWorkDir::CInfo &info);\r\n\r\nvoid SaveCascadedMenu(bool enabled);\r\nbool ReadCascadedMenu();\r\n\r\nvoid SaveContextMenuStatus(UInt32 value);\r\nbool ReadContextMenuStatus(UInt32 &value);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/ConsoleClose.cpp",
    "content": "// ConsoleClose.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n\r\nstatic int g_BreakCounter = 0;\r\nstatic const int kBreakAbortThreshold = 2;\r\n\r\nnamespace NConsoleClose {\r\n\r\nstatic BOOL WINAPI HandlerRoutine(DWORD ctrlType)\r\n{\r\n  if (ctrlType == CTRL_LOGOFF_EVENT)\r\n  {\r\n    // printf(\"\\nCTRL_LOGOFF_EVENT\\n\");\r\n    return TRUE;\r\n  }\r\n\r\n  g_BreakCounter++;\r\n  if (g_BreakCounter < kBreakAbortThreshold)\r\n    return TRUE;\r\n  return FALSE;\r\n  /*\r\n  switch(ctrlType)\r\n  {\r\n    case CTRL_C_EVENT:\r\n    case CTRL_BREAK_EVENT:\r\n      if (g_BreakCounter < kBreakAbortThreshold)\r\n      return TRUE;\r\n  }\r\n  return FALSE;\r\n  */\r\n}\r\n\r\nbool TestBreakSignal()\r\n{\r\n  /*\r\n  if (g_BreakCounter > 0)\r\n    return true;\r\n  */\r\n  return (g_BreakCounter > 0);\r\n}\r\n\r\nvoid CheckCtrlBreak()\r\n{\r\n  if (TestBreakSignal())\r\n    throw CCtrlBreakException();\r\n}\r\n\r\nCCtrlHandlerSetter::CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\nCCtrlHandlerSetter::~CCtrlHandlerSetter()\r\n{\r\n  if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))\r\n    throw \"SetConsoleCtrlHandler fails\";\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/ConsoleClose.h",
    "content": "// ConsoleCloseUtils.h\r\n\r\n#ifndef __CONSOLECLOSEUTILS_H\r\n#define __CONSOLECLOSEUTILS_H\r\n\r\nnamespace NConsoleClose {\r\n\r\nbool TestBreakSignal();\r\n\r\nclass CCtrlHandlerSetter\r\n{\r\npublic:\r\n  CCtrlHandlerSetter();\r\n  virtual ~CCtrlHandlerSetter();\r\n};\r\n\r\nclass CCtrlBreakException\r\n{};\r\n\r\nvoid CheckCtrlBreak();\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UserInputUtils.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/Wildcard.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileFind.h\"\r\n#include \"Windows/Time.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Error.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n\r\n#include \"../../Common/FilePathAutoRename.h\"\r\n\r\n#include \"../Common/ExtractingFilePath.h\"\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NDirectory;\r\n\r\nstatic const char *kTestString    =  \"Testing     \";\r\nstatic const char *kExtractString =  \"Extracting  \";\r\nstatic const char *kSkipString   =  \"Skipping    \";\r\n\r\n// static const char *kCantAutoRename = \"can not create file with auto name\\n\";\r\n// static const char *kCantRenameFile = \"can not rename existing file\\n\";\r\n// static const char *kCantDeleteOutputFile = \"can not delete output file \";\r\nstatic const char *kError = \"ERROR: \";\r\nstatic const char *kMemoryExceptionMessage = \"Can't allocate required memory!\";\r\n\r\nstatic const char *kProcessing = \"Processing archive: \";\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kNoFiles = \"No files to process\";\r\n\r\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\r\nstatic const char *kCrcFailed = \"CRC Failed\";\r\nstatic const char *kCrcFailedEncrypted = \"CRC Failed in encrypted file. Wrong password?\";\r\nstatic const char *kDataError = \"Data Error\";\r\nstatic const char *kDataErrorEncrypted = \"Data Error in encrypted file. Wrong password?\";\r\nstatic const char *kUnknownError = \"Unknown Error\";\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::AskOverwrite(\r\n    const wchar_t *existName, const FILETIME *, const UInt64 *,\r\n    const wchar_t *newName, const FILETIME *, const UInt64 *,\r\n    Int32 *answer)\r\n{\r\n  (*OutStream) << \"file \" << existName <<\r\n    \"\\nalready exists. Overwrite with \" << endl;\r\n  (*OutStream) << newName;\r\n  \r\n  NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);\r\n  \r\n  switch(overwriteAnswer)\r\n  {\r\n    case NUserAnswerMode::kQuit:  return E_ABORT;\r\n    case NUserAnswerMode::kNo:     *answer = NOverwriteAnswer::kNo; break;\r\n    case NUserAnswerMode::kNoAll:  *answer = NOverwriteAnswer::kNoToAll; break;\r\n    case NUserAnswerMode::kYesAll: *answer = NOverwriteAnswer::kYesToAll; break;\r\n    case NUserAnswerMode::kYes:    *answer = NOverwriteAnswer::kYes; break;\r\n    case NUserAnswerMode::kAutoRenameAll: *answer = NOverwriteAnswer::kAutoRename; break;\r\n    default: return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position)\r\n{\r\n  switch (askExtractMode)\r\n  {\r\n    case NArchive::NExtract::NAskMode::kExtract: (*OutStream) << kExtractString; break;\r\n    case NArchive::NExtract::NAskMode::kTest:    (*OutStream) << kTestString; break;\r\n    case NArchive::NExtract::NAskMode::kSkip:    (*OutStream) << kSkipString; break;\r\n  };\r\n  (*OutStream) << name;\r\n  if (position != 0)\r\n    (*OutStream) << \" <\" << *position << \">\";\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)\r\n{\r\n  (*OutStream) << message << endl;\r\n  NumFileErrorsInCurrentArchive++;\r\n  NumFileErrors++;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted)\r\n{\r\n  switch(operationResult)\r\n  {\r\n    case NArchive::NExtract::NOperationResult::kOK:\r\n      break;\r\n    default:\r\n    {\r\n      NumFileErrorsInCurrentArchive++;\r\n      NumFileErrors++;\r\n      (*OutStream) << \"     \";\r\n      switch(operationResult)\r\n      {\r\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\r\n          (*OutStream) << kUnsupportedMethod;\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kCRCError:\r\n          (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed);\r\n          break;\r\n        case NArchive::NExtract::NOperationResult::kDataError:\r\n          (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError);\r\n          break;\r\n        default:\r\n          (*OutStream) << kUnknownError;\r\n      }\r\n    }\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\n#ifndef _NO_CRYPTO\r\n\r\nHRESULT CExtractCallbackConsole::SetPassword(const UString &password)\r\n{\r\n  PasswordIsDefined = true;\r\n  Password = password;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)\r\n{\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream);\r\n    PasswordIsDefined = true;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)\r\n{\r\n  NumArchives++;\r\n  NumFileErrorsInCurrentArchive = 0;\r\n  (*OutStream) << endl << kProcessing << name << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT result, bool encrypted)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n  {\r\n    (*OutStream) << \"Error: \";\r\n    if (result == S_FALSE)\r\n    {\r\n      (*OutStream) << (encrypted ?\r\n        \"Can not open encrypted archive. Wrong password?\" :\r\n        \"Can not open file as archive\");\r\n    }\r\n    else\r\n    {\r\n      if (result == E_OUTOFMEMORY)\r\n        (*OutStream) << \"Can't allocate required memory\";\r\n      else\r\n        (*OutStream) << NError::MyFormatMessage(result);\r\n    }\r\n    (*OutStream) << endl;\r\n    NumArchiveErrors++;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nHRESULT CExtractCallbackConsole::ThereAreNoFiles()\r\n{\r\n  (*OutStream) << endl << kNoFiles << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)\r\n{\r\n  if (result == S_OK)\r\n  {\r\n    (*OutStream) << endl;\r\n    if (NumFileErrorsInCurrentArchive == 0)\r\n      (*OutStream) << kEverythingIsOk << endl;\r\n    else\r\n    {\r\n      NumArchiveErrors++;\r\n      (*OutStream) << \"Sub items Errors: \" << NumFileErrorsInCurrentArchive << endl;\r\n    }\r\n  }\r\n  if (result == S_OK)\r\n    return result;\r\n  NumArchiveErrors++;\r\n  if (result == E_ABORT || result == ERROR_DISK_FULL)\r\n    return result;\r\n  (*OutStream) << endl << kError;\r\n  if (result == E_OUTOFMEMORY)\r\n    (*OutStream) << kMemoryExceptionMessage;\r\n  else\r\n  {\r\n    UString message;\r\n    NError::MyFormatMessage(result, message);\r\n    (*OutStream) << message;\r\n  }\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/ExtractCallbackConsole.h",
    "content": "// ExtractCallbackConsole.h\r\n\r\n#ifndef __EXTRACTCALLBACKCONSOLE_H\r\n#define __EXTRACTCALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../IPassword.h\"\r\n#include \"../../Archive/IArchive.h\"\r\n#include \"../Common/ArchiveExtractCallback.h\"\r\n\r\nclass CExtractCallbackConsole:\r\n  public IExtractCallbackUI,\r\n  #ifndef _NO_CRYPTO\r\n  public ICryptoGetTextPassword,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_QUERYINTERFACE_BEGIN2(IFolderArchiveExtractCallback)\r\n  #ifndef _NO_CRYPTO\r\n  MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)\r\n  #endif\r\n  MY_QUERYINTERFACE_END\r\n  MY_ADDREF_RELEASE\r\n\r\n  STDMETHOD(SetTotal)(UInt64 total);\r\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\r\n\r\n  // IFolderArchiveExtractCallback\r\n  STDMETHOD(AskOverwrite)(\r\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\r\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\r\n      Int32 *answer);\r\n  STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position);\r\n\r\n  STDMETHOD(MessageError)(const wchar_t *message);\r\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);\r\n\r\n  HRESULT BeforeOpen(const wchar_t *name);\r\n  HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);\r\n  HRESULT ThereAreNoFiles();\r\n  HRESULT ExtractResult(HRESULT result);\r\n\r\n \r\n  #ifndef _NO_CRYPTO\r\n  HRESULT SetPassword(const UString &password);\r\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\r\n\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n\r\n  #endif\r\n  \r\n  UInt64 NumArchives;\r\n  UInt64 NumArchiveErrors;\r\n  UInt64 NumFileErrors;\r\n  UInt64 NumFileErrorsInCurrentArchive;\r\n\r\n  CStdOutStream *OutStream;\r\n\r\n  void Init()\r\n  {\r\n    NumArchives = 0;\r\n    NumArchiveErrors = 0;\r\n    NumFileErrors = 0;\r\n    NumFileErrorsInCurrentArchive = 0;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/List.cpp",
    "content": "// List.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"List.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyCom.h\"\r\n\r\n#include \"Windows/PropVariant.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/PropVariantConversions.h\"\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"../../Archive/IArchive.h\"\r\n\r\n#include \"../Common/PropIDUtils.h\"\r\n#include \"../Common/OpenArchive.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nstruct CPropIdToName\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n};\r\n\r\nstatic CPropIdToName kPropIdToName[] =\r\n{\r\n  { kpidPath, L\"Path\" },\r\n  { kpidName, L\"Name\" },\r\n  { kpidIsDir, L\"Folder\" },\r\n  { kpidSize, L\"Size\" },\r\n  { kpidPackSize, L\"Packed Size\" },\r\n  { kpidAttrib, L\"Attributes\" },\r\n  { kpidCTime, L\"Created\" },\r\n  { kpidATime, L\"Accessed\" },\r\n  { kpidMTime, L\"Modified\" },\r\n  { kpidSolid, L\"Solid\" },\r\n  { kpidCommented, L\"Commented\" },\r\n  { kpidEncrypted, L\"Encrypted\" },\r\n  { kpidSplitBefore, L\"Split Before\" },\r\n  { kpidSplitAfter, L\"Split After\" },\r\n  { kpidDictionarySize, L\"Dictionary Size\" },\r\n  { kpidCRC, L\"CRC\" },\r\n  { kpidType, L\"Type\" },\r\n  { kpidIsAnti, L\"Anti\" },\r\n  { kpidMethod, L\"Method\" },\r\n  { kpidHostOS, L\"Host OS\" },\r\n  { kpidFileSystem, L\"File System\" },\r\n  { kpidUser, L\"User\" },\r\n  { kpidGroup, L\"Group\" },\r\n  { kpidBlock, L\"Block\" },\r\n  { kpidComment, L\"Comment\" },\r\n  { kpidPosition, L\"Position\" },\r\n  { kpidPrefix, L\"Prefix\" },\r\n  { kpidNumSubDirs, L\"Folders\" },\r\n  { kpidNumSubFiles, L\"Files\" },\r\n  { kpidUnpackVer, L\"Version\" },\r\n  { kpidVolume, L\"Volume\" },\r\n  { kpidIsVolume, L\"Multivolume\" },\r\n  { kpidOffset, L\"Offset\" },\r\n  { kpidLinks, L\"Links\" },\r\n  { kpidNumBlocks, L\"Blocks\" },\r\n  { kpidNumVolumes, L\"Volumes\" },\r\n\r\n  { kpidBit64, L\"64-bit\" },\r\n  { kpidBigEndian, L\"Big-endian\" },\r\n  { kpidCpu, L\"CPU\" },\r\n  { kpidPhySize, L\"Physical Size\" },\r\n  { kpidHeadersSize, L\"Headers Size\" },\r\n  { kpidChecksum, L\"Checksum\" },\r\n  { kpidCharacts, L\"Characteristics\" },\r\n  { kpidVa, L\"Virtual Address\" },\r\n  { kpidFreeSpace, L\"Free Space\" },\r\n  { kpidClusterSize, L\"Cluster Size\" }\r\n};\r\n\r\nstatic const char kEmptyAttribChar = '.';\r\n\r\nstatic const char *kListing = \"Listing archive: \";\r\nstatic const wchar_t *kFilesMessage = L\"files\";\r\nstatic const wchar_t *kDirsMessage = L\"folders\";\r\n\r\nstatic void GetAttribString(DWORD wa, bool isDir, char *s)\r\n{\r\n  s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : kEmptyAttribChar;\r\n  s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0) ? 'R': kEmptyAttribChar;\r\n  s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? 'H': kEmptyAttribChar;\r\n  s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? 'S': kEmptyAttribChar;\r\n  s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? 'A': kEmptyAttribChar;\r\n  s[5] = '\\0';\r\n}\r\n\r\nenum EAdjustment\r\n{\r\n  kLeft,\r\n  kCenter,\r\n  kRight\r\n};\r\n\r\nstruct CFieldInfo\r\n{\r\n  PROPID PropID;\r\n  UString Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nstruct CFieldInfoInit\r\n{\r\n  PROPID PropID;\r\n  const wchar_t *Name;\r\n  EAdjustment TitleAdjustment;\r\n  EAdjustment TextAdjustment;\r\n  int PrefixSpacesWidth;\r\n  int Width;\r\n};\r\n\r\nCFieldInfoInit kStandardFieldTable[] =\r\n{\r\n  { kpidMTime, L\"   Date      Time\", kLeft, kLeft, 0, 19 },\r\n  { kpidAttrib, L\"Attr\", kRight, kCenter, 1, 5 },\r\n  { kpidSize, L\"Size\", kRight, kRight, 1, 12 },\r\n  { kpidPackSize, L\"Compressed\", kRight, kRight, 1, 12 },\r\n  { kpidPath, L\"Name\", kLeft, kLeft, 2, 24 }\r\n};\r\n\r\nvoid PrintSpaces(int numSpaces)\r\n{\r\n  for (int i = 0; i < numSpaces; i++)\r\n    g_StdOut << ' ';\r\n}\r\n\r\nvoid PrintString(EAdjustment adjustment, int width, const UString &textString)\r\n{\r\n  const int numSpaces = width - textString.Length();\r\n  int numLeftSpaces = 0;\r\n  switch (adjustment)\r\n  {\r\n    case kLeft:\r\n      numLeftSpaces = 0;\r\n      break;\r\n    case kCenter:\r\n      numLeftSpaces = numSpaces / 2;\r\n      break;\r\n    case kRight:\r\n      numLeftSpaces = numSpaces;\r\n      break;\r\n  }\r\n  PrintSpaces(numLeftSpaces);\r\n  g_StdOut << textString;\r\n  PrintSpaces(numSpaces - numLeftSpaces);\r\n}\r\n\r\nclass CFieldPrinter\r\n{\r\n  CObjectVector<CFieldInfo> _fields;\r\npublic:\r\n  void Clear() { _fields.Clear(); }\r\n  void Init(const CFieldInfoInit *standardFieldTable, int numItems);\r\n  HRESULT Init(IInArchive *archive);\r\n  void PrintTitle();\r\n  void PrintTitleLines();\r\n  HRESULT PrintItemInfo(IInArchive *archive,\r\n      const UString &defaultItemName,\r\n      UInt32 index,\r\n      bool techMode);\r\n  HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\r\n      const UInt64 *size, const UInt64 *compressedSize);\r\n};\r\n\r\nvoid CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)\r\n{\r\n  Clear();\r\n  for (int i = 0; i < numItems; i++)\r\n  {\r\n    CFieldInfo fieldInfo;\r\n    const CFieldInfoInit &fieldInfoInit = standardFieldTable[i];\r\n    fieldInfo.PropID = fieldInfoInit.PropID;\r\n    fieldInfo.Name = fieldInfoInit.Name;\r\n    fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment;\r\n    fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment;\r\n    fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth;\r\n    fieldInfo.Width = fieldInfoInit.Width;\r\n    _fields.Add(fieldInfo);\r\n  }\r\n}\r\n\r\nstatic UString GetPropName(PROPID propID, BSTR name)\r\n{\r\n  for (int i = 0; i < sizeof(kPropIdToName) / sizeof(kPropIdToName[0]); i++)\r\n  {\r\n    const CPropIdToName &propIdToName = kPropIdToName[i];\r\n    if (propIdToName.PropID == propID)\r\n      return propIdToName.Name;\r\n  }\r\n  if (name)\r\n    return name;\r\n  wchar_t s[32];\r\n  ConvertUInt64ToString(propID, s);\r\n  return s;\r\n}\r\n\r\nHRESULT CFieldPrinter::Init(IInArchive *archive)\r\n{\r\n  Clear();\r\n  UInt32 numProps;\r\n  RINOK(archive->GetNumberOfProperties(&numProps));\r\n  for (UInt32 i = 0; i < numProps; i++)\r\n  {\r\n    CMyComBSTR name;\r\n    PROPID propID;\r\n    VARTYPE vt;\r\n    RINOK(archive->GetPropertyInfo(i, &name, &propID, &vt));\r\n    CFieldInfo fieldInfo;\r\n    fieldInfo.PropID = propID;\r\n    fieldInfo.Name = GetPropName(propID, name);\r\n    _fields.Add(fieldInfo);\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitle()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    PrintString(fieldInfo.TitleAdjustment,\r\n      ((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);\r\n  }\r\n}\r\n\r\nvoid CFieldPrinter::PrintTitleLines()\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    for (int i = 0; i < fieldInfo.Width; i++)\r\n      g_StdOut << '-';\r\n  }\r\n}\r\n\r\n\r\nBOOL IsFileTimeZero(CONST FILETIME *lpFileTime)\r\n{\r\n  return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);\r\n}\r\n\r\nstatic const char *kEmptyTimeString = \"                   \";\r\nvoid PrintTime(const NCOM::CPropVariant &prop)\r\n{\r\n  if (prop.vt != VT_FILETIME)\r\n    throw \"incorrect item\";\r\n  if (IsFileTimeZero(&prop.filetime))\r\n    g_StdOut << kEmptyTimeString;\r\n  else\r\n  {\r\n    FILETIME localFileTime;\r\n    if (!FileTimeToLocalFileTime(&prop.filetime, &localFileTime))\r\n      throw \"FileTimeToLocalFileTime error\";\r\n    char s[32];\r\n    if (ConvertFileTimeToString(localFileTime, s, true, true))\r\n      g_StdOut << s;\r\n    else\r\n      g_StdOut << kEmptyTimeString;\r\n  }\r\n}\r\n\r\nHRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,\r\n    const UString &defaultItemName,\r\n    UInt32 index,\r\n    bool techMode)\r\n{\r\n  /*\r\n  if (techMode)\r\n  {\r\n    g_StdOut << \"Index = \";\r\n    g_StdOut << (UInt64)index;\r\n    g_StdOut << endl;\r\n  }\r\n  */\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    if (!techMode)\r\n      PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n\r\n    NCOM::CPropVariant prop;\r\n    if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      UString s;\r\n      RINOK(GetArchiveItemPath(archive, index, defaultItemName, s));\r\n      prop = s;\r\n    }\r\n    else\r\n    {\r\n      RINOK(archive->GetProperty(index, fieldInfo.PropID, &prop));\r\n    }\r\n    if (techMode)\r\n    {\r\n      g_StdOut << fieldInfo.Name << \" = \";\r\n    }\r\n    int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;\r\n    if (prop.vt == VT_EMPTY)\r\n    {\r\n      switch(fieldInfo.PropID)\r\n      {\r\n        case kpidPath:  prop = defaultItemName; break;\r\n        default:\r\n          if (techMode)\r\n            g_StdOut << endl;\r\n          else\r\n            PrintSpaces(width);\r\n          continue;\r\n      }\r\n    }\r\n    if (fieldInfo.PropID == kpidMTime)\r\n    {\r\n      PrintTime(prop);\r\n    }\r\n    else if (fieldInfo.PropID == kpidAttrib)\r\n    {\r\n      if (prop.vt != VT_UI4)\r\n        throw \"incorrect item\";\r\n      UInt32 attributes = prop.ulVal;\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, index, isFolder));\r\n      char s[8];\r\n      GetAttribString(attributes, isFolder, s);\r\n      g_StdOut << s;\r\n    }\r\n    else if (prop.vt == VT_BSTR)\r\n    {\r\n      if (techMode)\r\n        g_StdOut << prop.bstrVal;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, prop.bstrVal);\r\n    }\r\n    else\r\n    {\r\n      UString s = ConvertPropertyToString(prop, fieldInfo.PropID);\r\n      s.Replace(wchar_t(0xA), L' ');\r\n      s.Replace(wchar_t(0xD), L' ');\r\n\r\n      if (techMode)\r\n        g_StdOut << s;\r\n      else\r\n        PrintString(fieldInfo.TextAdjustment, width, s);\r\n    }\r\n    if (techMode)\r\n      g_StdOut << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)\r\n{\r\n  wchar_t textString[32] = { 0 };\r\n  if (value != NULL)\r\n    ConvertUInt64ToString(*value, textString);\r\n  PrintString(adjustment, width, textString);\r\n}\r\n\r\n\r\nHRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\r\n    const UInt64 *size, const UInt64 *compressedSize)\r\n{\r\n  for (int i = 0; i < _fields.Size(); i++)\r\n  {\r\n    const CFieldInfo &fieldInfo = _fields[i];\r\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\r\n    NCOM::CPropVariant prop;\r\n    if (fieldInfo.PropID == kpidSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);\r\n    else if (fieldInfo.PropID == kpidPackSize)\r\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);\r\n    else if (fieldInfo.PropID == kpidPath)\r\n    {\r\n      wchar_t textString[32];\r\n      ConvertUInt64ToString(numFiles, textString);\r\n      UString temp = textString;\r\n      temp += L\" \";\r\n      temp += kFilesMessage;\r\n      temp += L\", \";\r\n      ConvertUInt64ToString(numDirs, textString);\r\n      temp += textString;\r\n      temp += L\" \";\r\n      temp += kDirsMessage;\r\n      PrintString(fieldInfo.TextAdjustment, 0, temp);\r\n    }\r\n    else\r\n      PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L\"\");\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nbool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)\r\n{\r\n  NCOM::CPropVariant prop;\r\n  if (archive->GetProperty(index, propID, &prop) != S_OK)\r\n    throw \"GetPropertyValue error\";\r\n  if (prop.vt == VT_EMPTY)\r\n    return false;\r\n  value = ConvertPropVariantToUInt64(prop);\r\n  return true;\r\n}\r\n\r\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode,\r\n    #ifndef _NO_CRYPTO\r\n    bool &passwordEnabled, UString &password,\r\n    #endif\r\n    UInt64 &numErrors)\r\n{\r\n  numErrors = 0;\r\n  CFieldPrinter fieldPrinter;\r\n  if (!techMode)\r\n    fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));\r\n\r\n  UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;\r\n  UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;\r\n  for (int i = 0; i < archivePaths.Size(); i++)\r\n  {\r\n    const UString &archiveName = archivePaths[i];\r\n    NFile::NFind::CFileInfoW fi;\r\n    if (!NFile::NFind::FindFile(archiveName, fi) || fi.IsDir())\r\n    {\r\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not file\" << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    CArchiveLink archiveLink;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &g_StdOut;\r\n\r\n    #ifndef _NO_CRYPTO\r\n\r\n    openCallback.PasswordIsDefined = passwordEnabled;\r\n    openCallback.Password = password;\r\n\r\n    #endif\r\n\r\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, &openCallback);\r\n    if (result != S_OK)\r\n    {\r\n      if (result == E_ABORT)\r\n        return result;\r\n      g_StdOut << endl << \"Error: \" << archiveName << \": \";\r\n      if (result == S_FALSE)\r\n        g_StdOut << \"is not supported archive\";\r\n      else if (result == E_OUTOFMEMORY)\r\n        g_StdOut << \"Can't allocate required memory\";\r\n      else\r\n        g_StdOut << NError::MyFormatMessage(result);\r\n      g_StdOut << endl;\r\n      numErrors++;\r\n      continue;\r\n    }\r\n\r\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\r\n    {\r\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\r\n      if (index >= 0 && index > i)\r\n      {\r\n        archivePaths.Delete(index);\r\n        archivePathsFull.Delete(index);\r\n      }\r\n    }\r\n\r\n    IInArchive *archive = archiveLink.GetArchive();\r\n    const UString defaultItemName = archiveLink.GetDefaultItemName();\r\n\r\n    if (enableHeaders)\r\n    {\r\n      g_StdOut << endl << kListing << archiveName << endl << endl;\r\n\r\n      UInt32 numProps;\r\n      if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)\r\n      {\r\n        for (UInt32 i = 0; i < numProps; i++)\r\n        {\r\n          CMyComBSTR name;\r\n          PROPID propID;\r\n          VARTYPE vt;\r\n          if (archive->GetArchivePropertyInfo(i, &name, &propID, &vt) != S_OK)\r\n            continue;\r\n          NCOM::CPropVariant prop;\r\n          if (archive->GetArchiveProperty(propID, &prop) != S_OK)\r\n            continue;\r\n          UString s = ConvertPropertyToString(prop, propID);\r\n          if (!s.IsEmpty())\r\n            g_StdOut << GetPropName(propID, name) << \" = \" << s << endl;\r\n        }\r\n      }\r\n      if (techMode)\r\n        g_StdOut << \"----------\\n\";\r\n      if (numProps > 0)\r\n        g_StdOut << endl;\r\n    }\r\n\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitle();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n    }\r\n\r\n    if (techMode)\r\n    {\r\n      RINOK(fieldPrinter.Init(archive));\r\n    }\r\n    UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0;\r\n    UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;\r\n    UInt32 numItems;\r\n    RINOK(archive->GetNumberOfItems(&numItems));\r\n    for(UInt32 i = 0; i < numItems; i++)\r\n    {\r\n      if (NConsoleClose::TestBreakSignal())\r\n        return E_ABORT;\r\n\r\n      UString filePath;\r\n      RINOK(GetArchiveItemPath(archive, i, defaultItemName, filePath));\r\n\r\n      bool isFolder;\r\n      RINOK(IsArchiveItemFolder(archive, i, isFolder));\r\n      if (!wildcardCensor.CheckPath(filePath, !isFolder))\r\n        continue;\r\n      \r\n      fieldPrinter.PrintItemInfo(archive, defaultItemName, i, techMode);\r\n      \r\n      UInt64 packSize, unpackSize;\r\n      if (!GetUInt64Value(archive, i, kpidSize, unpackSize))\r\n        unpackSize = 0;\r\n      else\r\n        totalUnPackSizePointer = &totalUnPackSize;\r\n      if (!GetUInt64Value(archive, i, kpidPackSize, packSize))\r\n        packSize = 0;\r\n      else\r\n        totalPackSizePointer = &totalPackSize;\r\n      \r\n      g_StdOut << endl;\r\n\r\n      if (isFolder)\r\n        numDirs++;\r\n      else\r\n        numFiles++;\r\n      totalPackSize += packSize;\r\n      totalUnPackSize += unpackSize;\r\n    }\r\n    if (enableHeaders && !techMode)\r\n    {\r\n      fieldPrinter.PrintTitleLines();\r\n      g_StdOut << endl;\r\n      fieldPrinter.PrintSummaryInfo(numFiles, numDirs, totalUnPackSizePointer, totalPackSizePointer);\r\n      g_StdOut << endl;\r\n    }\r\n    if (totalPackSizePointer != 0)\r\n    {\r\n      totalPackSizePointer2 = &totalPackSize2;\r\n      totalPackSize2 += totalPackSize;\r\n    }\r\n    if (totalUnPackSizePointer != 0)\r\n    {\r\n      totalUnPackSizePointer2 = &totalUnPackSize2;\r\n      totalUnPackSize2 += totalUnPackSize;\r\n    }\r\n    numFiles2 += numFiles;\r\n    numDirs2 += numDirs;\r\n  }\r\n  if (enableHeaders && !techMode && archivePaths.Size() > 1)\r\n  {\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintTitleLines();\r\n    g_StdOut << endl;\r\n    fieldPrinter.PrintSummaryInfo(numFiles2, numDirs2, totalUnPackSizePointer2, totalPackSizePointer2);\r\n    g_StdOut << endl;\r\n    g_StdOut << \"Archives: \" << archivePaths.Size() << endl;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/List.h",
    "content": "// List.h\r\n\r\n#ifndef __LIST_H\r\n#define __LIST_H\r\n\r\n#include \"Common/Wildcard.h\"\r\n#include \"../Common/LoadCodecs.h\"\r\n\r\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\r\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\r\n    const NWildcard::CCensorNode &wildcardCensor,\r\n    bool enableHeaders, bool techMode,\r\n    #ifndef _NO_CRYPTO\r\n    bool &passwordEnabled, UString &password,\r\n    #endif\r\n    UInt64 &errors);\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/Main.cpp",
    "content": "// Main.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/MyInitGuid.h\"\r\n\r\n#include \"Common/CommandLineParser.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/StringToInt.h\"\r\n\r\n#include \"Windows/FileDir.h\"\r\n#include \"Windows/FileName.h\"\r\n#include \"Windows/Defs.h\"\r\n#include \"Windows/Error.h\"\r\n#ifdef _WIN32\r\n#include \"Windows/MemoryLock.h\"\r\n#endif\r\n\r\n#include \"../../IPassword.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../Common/UpdateAction.h\"\r\n#include \"../Common/Update.h\"\r\n#include \"../Common/Extract.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"../Common/ExitCode.h\"\r\n#ifdef EXTERNAL_CODECS\r\n#include \"../Common/LoadCodecs.h\"\r\n#endif\r\n\r\n#include \"../../Compress/LZMA_Alone/LzmaBenchCon.h\"\r\n\r\n#include \"List.h\"\r\n#include \"OpenCallbackConsole.h\"\r\n#include \"ExtractCallbackConsole.h\"\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"../../MyVersion.h\"\r\n\r\n#if defined( _WIN32) && defined( _7ZIP_LARGE_PAGES)\r\nextern \"C\"\r\n{\r\n#include \"../../../../C/Alloc.h\"\r\n}\r\n#endif\r\n\r\nusing namespace NWindows;\r\nusing namespace NFile;\r\nusing namespace NCommandLineParser;\r\n\r\nHINSTANCE g_hInstance = 0;\r\nextern CStdOutStream *g_StdStream;\r\n\r\nstatic const char *kCopyrightString = \"\\n7-Zip\"\r\n#ifndef EXTERNAL_CODECS\r\n\" (A)\"\r\n#endif\r\n\r\n#ifdef _WIN64\r\n\" [64]\"\r\n#endif\r\n\r\n\" \" MY_VERSION_COPYRIGHT_DATE \"\\n\";\r\n\r\nstatic const char *kHelpString =\r\n    \"\\nUsage: 7z\"\r\n#ifdef _NO_CRYPTO\r\n    \"r\"\r\n#else\r\n#ifndef EXTERNAL_CODECS\r\n    \"a\"\r\n#endif\r\n#endif\r\n    \" <command> [<switches>...] <archive_name> [<file_names>...]\\n\"\r\n    \"       [<@listfiles...>]\\n\"\r\n    \"\\n\"\r\n    \"<Commands>\\n\"\r\n    \"  a: Add files to archive\\n\"\r\n    \"  b: Benchmark\\n\"\r\n    \"  d: Delete files from archive\\n\"\r\n    \"  e: Extract files from archive (without using directory names)\\n\"\r\n    \"  l: List contents of archive\\n\"\r\n//    \"  l[a|t][f]: List contents of archive\\n\"\r\n//    \"    a - with Additional fields\\n\"\r\n//    \"    t - with all fields\\n\"\r\n//    \"    f - with Full pathnames\\n\"\r\n    \"  t: Test integrity of archive\\n\"\r\n    \"  u: Update files to archive\\n\"\r\n    \"  x: eXtract files with full paths\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -ai[r[-|0]]{@listfile|!wildcard}: Include archives\\n\"\r\n    \"  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives\\n\"\r\n    \"  -bd: Disable percentage indicator\\n\"\r\n    \"  -i[r[-|0]]{@listfile|!wildcard}: Include filenames\\n\"\r\n    \"  -m{Parameters}: set compression Method\\n\"\r\n    \"  -o{Directory}: set Output directory\\n\"\r\n    #ifndef _NO_CRYPTO\r\n    \"  -p{Password}: set Password\\n\"\r\n    #endif\r\n    \"  -r[-|0]: Recurse subdirectories\\n\"\r\n    \"  -scs{UTF-8 | WIN | DOS}: set charset for list files\\n\"\r\n    \"  -sfx[{name}]: Create SFX archive\\n\"\r\n    \"  -si[{name}]: read data from stdin\\n\"\r\n    \"  -slt: show technical information for l (List) command\\n\"\r\n    \"  -so: write data to stdout\\n\"\r\n    \"  -ssc[-]: set sensitive case mode\\n\"\r\n    \"  -ssw: compress shared files\\n\"\r\n    \"  -t{Type}: Set type of archive\\n\"\r\n    \"  -v{Size}[b|k|m|g]: Create volumes\\n\"\r\n    \"  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\\n\"\r\n    \"  -w[{path}]: assign Work directory. Empty path means a temporary directory\\n\"\r\n    \"  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\\n\"\r\n    \"  -y: assume Yes on all queries\\n\";\r\n\r\n// ---------------------------\r\n// exception messages\r\n\r\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\r\nstatic const char *kUserErrorMessage  = \"Incorrect command line\"; // NExitCode::kUserError\r\nstatic const char *kNoFormats = \"7-Zip cannot find the code that works with archives.\";\r\n\r\nstatic const wchar_t *kDefaultSfxModule = L\"7zCon.sfx\";\r\n\r\nstatic void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code)\r\n{\r\n  s << message << endl;\r\n  throw code;\r\n}\r\n\r\nstatic void PrintHelpAndExit(CStdOutStream &s) // yyy\r\n{\r\n  s << kHelpString;\r\n  ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError);\r\n}\r\n\r\n#ifndef _WIN32\r\nstatic void GetArguments(int numArguments, const char *arguments[], UStringVector &parts)\r\n{\r\n  parts.Clear();\r\n  for(int i = 0; i < numArguments; i++)\r\n  {\r\n    UString s = MultiByteToUnicodeString(arguments[i]);\r\n    parts.Add(s);\r\n  }\r\n}\r\n#endif\r\n\r\nstatic void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp)\r\n{\r\n  s << kCopyrightString;\r\n  // s << \"# CPUs: \" << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << \"\\n\";\r\n  if (needHelp)\r\n    s << kHelpString;\r\n}\r\n\r\n#ifdef EXTERNAL_CODECS\r\nstatic void PrintString(CStdOutStream &stdStream, const AString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n#endif\r\n\r\nstatic void PrintString(CStdOutStream &stdStream, const UString &s, int size)\r\n{\r\n  int len = s.Length();\r\n  stdStream << s;\r\n  for (int i = len; i < size; i++)\r\n    stdStream << ' ';\r\n}\r\n\r\nstatic inline char GetHex(Byte value)\r\n{\r\n  return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\r\n}\r\n\r\nconst char *kUnsupportedArcTypeMessage = \"Unsupported archive type\";\r\n\r\nint Main2(\r\n  #ifndef _WIN32\r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n)\r\n{\r\n  #ifdef _WIN32\r\n  SetFileApisToOEM();\r\n  #endif\r\n  \r\n  UStringVector commandStrings;\r\n  #ifdef _WIN32\r\n  NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);\r\n  #else\r\n  GetArguments(numArguments, arguments, commandStrings);\r\n  #endif\r\n\r\n  if(commandStrings.Size() == 1)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n  commandStrings.Delete(0);\r\n\r\n  CArchiveCommandLineOptions options;\r\n\r\n  CArchiveCommandLineParser parser;\r\n\r\n  parser.Parse1(commandStrings, options);\r\n\r\n  if(options.HelpMode)\r\n  {\r\n    ShowCopyrightAndHelp(g_StdOut, true);\r\n    return 0;\r\n  }\r\n\r\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\r\n  if (options.LargePages)\r\n  {\r\n    SetLargePageSize();\r\n    NSecurity::EnableLockMemoryPrivilege();\r\n  }\r\n  #endif\r\n\r\n  CStdOutStream &stdStream = options.StdOutMode ? g_StdErr : g_StdOut;\r\n  g_StdStream = &stdStream;\r\n\r\n  if (options.EnableHeaders)\r\n    ShowCopyrightAndHelp(stdStream, false);\r\n\r\n  parser.Parse2(options);\r\n\r\n  CCodecs *codecs = new CCodecs;\r\n  CMyComPtr<\r\n    #ifdef EXTERNAL_CODECS\r\n    ICompressCodecsInfo\r\n    #else\r\n    IUnknown\r\n    #endif\r\n    > compressCodecsInfo = codecs;\r\n  HRESULT result = codecs->Load();\r\n  if (result != S_OK)\r\n    throw CSystemException(result);\r\n\r\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\r\n\r\n  if (codecs->Formats.Size() == 0 &&\r\n        (isExtractGroupCommand ||\r\n        options.Command.CommandType == NCommandType::kList ||\r\n        options.Command.IsFromUpdateGroup()))\r\n    throw kNoFormats;\r\n\r\n  CIntVector formatIndices;\r\n  if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices))\r\n    throw kUnsupportedArcTypeMessage;\r\n\r\n  if (options.Command.CommandType == NCommandType::kInfo)\r\n  {\r\n    stdStream << endl << \"Formats:\" << endl;\r\n    int i;\r\n    for (i = 0; i < codecs->Formats.Size(); i++)\r\n    {\r\n      const CArcInfoEx &arc = codecs->Formats[i];\r\n      #ifdef EXTERNAL_CODECS\r\n      if (arc.LibIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(arc.LibIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n      #endif\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(arc.UpdateEnabled ? 'C' : ' ');\r\n      stdStream << (char)(arc.KeepName ? 'K' : ' ');\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, arc.Name, 6);\r\n      stdStream << \"  \";\r\n      UString s;\r\n      for (int t = 0; t < arc.Exts.Size(); t++)\r\n      {\r\n        const CArcExtInfo &ext = arc.Exts[t];\r\n        s += ext.Ext;\r\n        if (!ext.AddExt.IsEmpty())\r\n        {\r\n          s += L\" (\";\r\n          s += ext.AddExt;\r\n          s += L')';\r\n        }\r\n        s += L' ';\r\n      }\r\n      PrintString(stdStream, s, 14);\r\n      stdStream << \"  \";\r\n      const CByteBuffer &sig = arc.StartSignature;\r\n      for (size_t j = 0; j < sig.GetCapacity(); j++)\r\n      {\r\n        Byte b = sig[j];\r\n        if (b > 0x20 && b < 0x80)\r\n        {\r\n          stdStream << (char)b;\r\n        }\r\n        else\r\n        {\r\n          stdStream << GetHex((Byte)((b >> 4) & 0xF));\r\n          stdStream << GetHex((Byte)(b & 0xF));\r\n        }\r\n        stdStream << ' ';\r\n      }\r\n      stdStream << endl;\r\n    }\r\n    stdStream << endl << \"Codecs:\" << endl;\r\n\r\n    #ifdef EXTERNAL_CODECS\r\n    UInt32 numMethods;\r\n    if (codecs->GetNumberOfMethods(&numMethods) == S_OK)\r\n    for (UInt32 j = 0; j < numMethods; j++)\r\n    {\r\n      int libIndex = codecs->GetCodecLibIndex(j);\r\n      if (libIndex >= 0)\r\n      {\r\n        char s[32];\r\n        ConvertUInt64ToString(libIndex, s);\r\n        PrintString(stdStream, s, 2);\r\n      }\r\n      else\r\n        stdStream << \"  \";\r\n      stdStream << ' ';\r\n      stdStream << (char)(codecs->GetCodecEncoderIsAssigned(j) ? 'C' : ' ');\r\n      UInt64 id;\r\n      stdStream << \"  \";\r\n      HRESULT res = codecs->GetCodecId(j, id);\r\n      if (res != S_OK)\r\n        id = (UInt64)(Int64)-1;\r\n      char s[32];\r\n      ConvertUInt64ToString(id, s, 16);\r\n      PrintString(stdStream, s, 8);\r\n      stdStream << \"  \";\r\n      PrintString(stdStream, codecs->GetCodecName(j), 11);\r\n      stdStream << endl;\r\n      /*\r\n      if (res != S_OK)\r\n        throw \"incorrect Codec ID\";\r\n      */\r\n    }\r\n    #endif\r\n    return S_OK;\r\n  }\r\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\r\n  {\r\n    if (options.Method.CompareNoCase(L\"CRC\") == 0)\r\n    {\r\n      HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nCRC Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n    else\r\n    {\r\n      HRESULT res = LzmaBenchCon(\r\n        #ifdef EXTERNAL_LZMA\r\n        codecs,\r\n        #endif\r\n        (FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\r\n      if (res != S_OK)\r\n      {\r\n        if (res == S_FALSE)\r\n        {\r\n          stdStream << \"\\nDecoding Error\\n\";\r\n          return NExitCode::kFatalError;\r\n        }\r\n        throw CSystemException(res);\r\n      }\r\n    }\r\n  }\r\n  else if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\r\n  {\r\n    if(isExtractGroupCommand)\r\n    {\r\n      CExtractCallbackConsole *ecs = new CExtractCallbackConsole;\r\n      CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;\r\n\r\n      ecs->OutStream = &stdStream;\r\n\r\n      #ifndef _NO_CRYPTO\r\n      ecs->PasswordIsDefined = options.PasswordEnabled;\r\n      ecs->Password = options.Password;\r\n      #endif\r\n\r\n      ecs->Init();\r\n\r\n      COpenCallbackConsole openCallback;\r\n      openCallback.OutStream = &stdStream;\r\n\r\n      #ifndef _NO_CRYPTO\r\n      openCallback.PasswordIsDefined = options.PasswordEnabled;\r\n      openCallback.Password = options.Password;\r\n      #endif\r\n\r\n      CExtractOptions eo;\r\n      eo.StdOutMode = options.StdOutMode;\r\n      eo.PathMode = options.Command.GetPathMode();\r\n      eo.TestMode = options.Command.IsTestMode();\r\n      eo.OverwriteMode = options.OverwriteMode;\r\n      eo.OutputDir = options.OutputDir;\r\n      eo.YesToAll = options.YesToAll;\r\n      #ifdef COMPRESS_MT\r\n      eo.Properties = options.ExtractProperties;\r\n      #endif\r\n      UString errorMessage;\r\n      CDecompressStat stat;\r\n      HRESULT result = DecompressArchives(\r\n          codecs,\r\n          formatIndices,\r\n          options.ArchivePathsSorted,\r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head,\r\n          eo, &openCallback, ecs, errorMessage, stat);\r\n      if (!errorMessage.IsEmpty())\r\n      {\r\n        stdStream << endl << \"Error: \" << errorMessage;\r\n        if (result == S_OK)\r\n          result = E_FAIL;\r\n      }\r\n\r\n      stdStream << endl;\r\n      if (ecs->NumArchives > 1)\r\n        stdStream << \"Archives: \" << ecs->NumArchives << endl;\r\n      if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0)\r\n      {\r\n        if (ecs->NumArchives > 1)\r\n        {\r\n          stdStream << endl;\r\n          if (ecs->NumArchiveErrors != 0)\r\n            stdStream << \"Archive Errors: \" << ecs->NumArchiveErrors << endl;\r\n          if (ecs->NumFileErrors != 0)\r\n            stdStream << \"Sub items Errors: \" << ecs->NumFileErrors << endl;\r\n        }\r\n        if (result != S_OK)\r\n          throw CSystemException(result);\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n      if (stat.NumFolders != 0)\r\n        stdStream << \"Folders: \" << stat.NumFolders << endl;\r\n      if (stat.NumFiles != 1 || stat.NumFolders != 0)\r\n          stdStream << \"Files: \" << stat.NumFiles << endl;\r\n      stdStream\r\n           << \"Size:       \" << stat.UnpackSize << endl\r\n           << \"Compressed: \" << stat.PackSize << endl;\r\n    }\r\n    else\r\n    {\r\n      UInt64 numErrors = 0;\r\n      HRESULT result = ListArchives(\r\n          codecs,\r\n          formatIndices,\r\n          options.ArchivePathsSorted,\r\n          options.ArchivePathsFullSorted,\r\n          options.WildcardCensor.Pairs.Front().Head,\r\n          options.EnableHeaders,\r\n          options.TechMode,\r\n          #ifndef _NO_CRYPTO\r\n          options.PasswordEnabled,\r\n          options.Password,\r\n          #endif\r\n          numErrors);\r\n      if (numErrors > 0)\r\n      {\r\n        g_StdOut << endl << \"Errors: \" << numErrors;\r\n        return NExitCode::kFatalError;\r\n      }\r\n      if (result != S_OK)\r\n        throw CSystemException(result);\r\n    }\r\n  }\r\n  else if(options.Command.IsFromUpdateGroup())\r\n  {\r\n    UString workingDir;\r\n\r\n    CUpdateOptions &uo = options.UpdateOptions;\r\n    if (uo.SfxMode && uo.SfxModule.IsEmpty())\r\n      uo.SfxModule = kDefaultSfxModule;\r\n\r\n    COpenCallbackConsole openCallback;\r\n    openCallback.OutStream = &stdStream;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    bool passwordIsDefined =\r\n        options.PasswordEnabled && !options.Password.IsEmpty();\r\n    openCallback.PasswordIsDefined = passwordIsDefined;\r\n    openCallback.Password = options.Password;\r\n    #endif\r\n\r\n    CUpdateCallbackConsole callback;\r\n    callback.EnablePercents = options.EnablePercents;\r\n\r\n    #ifndef _NO_CRYPTO\r\n    callback.PasswordIsDefined = passwordIsDefined;\r\n    callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty();\r\n    callback.Password = options.Password;\r\n    #endif\r\n    callback.StdOutMode = uo.StdOutMode;\r\n    callback.Init(&stdStream);\r\n\r\n    CUpdateErrorInfo errorInfo;\r\n\r\n    if (!uo.Init(codecs, formatIndices, options.ArchiveName))\r\n      throw kUnsupportedArcTypeMessage;\r\n    HRESULT result = UpdateArchive(codecs,\r\n        options.WildcardCensor, uo,\r\n        errorInfo, &openCallback, &callback);\r\n\r\n    int exitCode = NExitCode::kSuccess;\r\n    if (callback.CantFindFiles.Size() > 0)\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      int numErrors = callback.CantFindFiles.Size();\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.CantFindFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.CantFindCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot find \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n\r\n    if (result != S_OK)\r\n    {\r\n      UString message;\r\n      if (!errorInfo.Message.IsEmpty())\r\n      {\r\n        message += errorInfo.Message;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName;\r\n        message += L\"\\n\";\r\n      }\r\n      if (!errorInfo.FileName2.IsEmpty())\r\n      {\r\n        message += errorInfo.FileName2;\r\n        message += L\"\\n\";\r\n      }\r\n      if (errorInfo.SystemError != 0)\r\n      {\r\n        message += NError::MyFormatMessageW(errorInfo.SystemError);\r\n        message += L\"\\n\";\r\n      }\r\n      if (!message.IsEmpty())\r\n        stdStream << L\"\\nError:\\n\" << message;\r\n      throw CSystemException(result);\r\n    }\r\n    int numErrors = callback.FailedFiles.Size();\r\n    if (numErrors == 0)\r\n    {\r\n      if (callback.CantFindFiles.Size() == 0)\r\n        stdStream << kEverythingIsOk << endl;\r\n    }\r\n    else\r\n    {\r\n      stdStream << endl;\r\n      stdStream << \"WARNINGS for files:\" << endl << endl;\r\n      for (int i = 0; i < numErrors; i++)\r\n      {\r\n        stdStream << callback.FailedFiles[i] << \" : \";\r\n        stdStream << NError::MyFormatMessageW(callback.FailedCodes[i]) << endl;\r\n      }\r\n      stdStream << \"----------------\" << endl;\r\n      stdStream << \"WARNING: Cannot open \" << numErrors << \" file\";\r\n      if (numErrors > 1)\r\n        stdStream << \"s\";\r\n      stdStream << endl;\r\n      exitCode = NExitCode::kWarning;\r\n    }\r\n    return exitCode;\r\n  }\r\n  else\r\n    PrintHelpAndExit(stdStream);\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/MainAr.cpp",
    "content": "// MainAr.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n// #include <locale.h>\r\n\r\n#include \"Windows/Error.h\"\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"Common/NewHandler.h\"\r\n#include \"Common/MyException.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"../Common/ExitCode.h\"\r\n#include \"../Common/ArchiveCommandLine.h\"\r\n#include \"ConsoleClose.h\"\r\n\r\nusing namespace NWindows;\r\n\r\nCStdOutStream *g_StdStream = 0;\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool g_IsNT = false;\r\n#endif\r\n#if !defined(_UNICODE) || !defined(_WIN64)\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo))\r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n#endif\r\n\r\nextern int Main2(\r\n  #ifndef _WIN32\r\n  int numArguments, const char *arguments[]\r\n  #endif\r\n);\r\n\r\nstatic const char *kExceptionErrorMessage = \"\\n\\nError:\\n\";\r\nstatic const char *kUserBreak  = \"\\nBreak signaled\\n\";\r\n\r\nstatic const char *kMemoryExceptionMessage = \"\\n\\nERROR: Can't allocate required memory!\\n\";\r\nstatic const char *kUnknownExceptionMessage = \"\\n\\nUnknown Error\\n\";\r\nstatic const char *kInternalExceptionMessage = \"\\n\\nInternal Error #\";\r\n\r\nint MY_CDECL main\r\n(\r\n#ifndef _WIN32\r\nint numArguments, const char *arguments[]\r\n#endif\r\n)\r\n{\r\n  g_StdStream = &g_StdOut;\r\n  #ifdef _WIN32\r\n  \r\n  #ifdef _UNICODE\r\n  #ifndef _WIN64\r\n  if (!IsItWindowsNT())\r\n  {\r\n    (*g_StdStream) << \"This program requires Windows NT/2000/2003/2008/XP/Vista\";\r\n    return NExitCode::kFatalError;\r\n  }\r\n  #endif\r\n  #else\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n  \r\n  #endif\r\n\r\n  // setlocale(LC_COLLATE, \".OCP\");\r\n  NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;\r\n  int res = 0;\r\n  try\r\n  {\r\n    res = Main2(\r\n#ifndef _WIN32\r\n      numArguments, arguments\r\n#endif\r\n    );\r\n  }\r\n  catch(const CNewException &)\r\n  {\r\n    (*g_StdStream) << kMemoryExceptionMessage;\r\n    return (NExitCode::kMemoryError);\r\n  }\r\n  catch(const NConsoleClose::CCtrlBreakException &)\r\n  {\r\n    (*g_StdStream) << endl << kUserBreak;\r\n    return (NExitCode::kUserBreak);\r\n  }\r\n  catch(const CArchiveCommandLineException &e)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << e << endl;\r\n    return (NExitCode::kUserError);\r\n  }\r\n  catch(const CSystemException &systemError)\r\n  {\r\n    if (systemError.ErrorCode == E_OUTOFMEMORY)\r\n    {\r\n      (*g_StdStream) << kMemoryExceptionMessage;\r\n      return (NExitCode::kMemoryError);\r\n    }\r\n    if (systemError.ErrorCode == E_ABORT)\r\n    {\r\n      (*g_StdStream) << endl << kUserBreak;\r\n      return (NExitCode::kUserBreak);\r\n    }\r\n    UString message;\r\n    NError::MyFormatMessage(systemError.ErrorCode, message);\r\n    (*g_StdStream) << endl << endl << \"System error:\" << endl <<\r\n        message << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(NExitCode::EEnum &exitCode)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << exitCode << endl;\r\n    return (exitCode);\r\n  }\r\n  /*\r\n  catch(const NExitCode::CMultipleErrors &multipleErrors)\r\n  {\r\n    (*g_StdStream) << endl << multipleErrors.NumErrors << \" errors\" << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  */\r\n  catch(const UString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const AString &s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(const char *s)\r\n  {\r\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(int t)\r\n  {\r\n    (*g_StdStream) << kInternalExceptionMessage << t << endl;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  catch(...)\r\n  {\r\n    (*g_StdStream) << kUnknownExceptionMessage;\r\n    return (NExitCode::kFatalError);\r\n  }\r\n  return  res;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.cpp",
    "content": "// OpenCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OpenCallbackConsole.h\"\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nHRESULT COpenCallbackConsole::Open_CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_SetTotal(const UInt64 *, const UInt64 *)\r\n{\r\n  return Open_CheckBreak();\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_SetCompleted(const UInt64 *, const UInt64 *)\r\n{\r\n  return Open_CheckBreak();\r\n}\r\n \r\n#ifndef _NO_CRYPTO\r\n\r\nHRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password)\r\n{\r\n  PasswordWasAsked = true;\r\n  RINOK(Open_CheckBreak());\r\n  if (!PasswordIsDefined)\r\n  {\r\n    Password = GetPassword(OutStream);\r\n    PasswordIsDefined = true;\r\n  }\r\n  return StringToBstr(Password, password);\r\n}\r\n\r\nHRESULT COpenCallbackConsole::Open_GetPasswordIfAny(UString &password)\r\n{\r\n  if (PasswordIsDefined)\r\n    password = Password;\r\n  return S_OK;\r\n}\r\n\r\nbool COpenCallbackConsole::Open_WasPasswordAsked()\r\n{\r\n  return PasswordWasAsked;\r\n}\r\n\r\nvoid COpenCallbackConsole::Open_ClearPasswordWasAskedFlag()\r\n{\r\n  PasswordWasAsked = false;\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/OpenCallbackConsole.h",
    "content": "// OpenCallbackConsole.h\r\n\r\n#ifndef __OPENCALLBACKCONSOLE_H\r\n#define __OPENCALLBACKCONSOLE_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n#include \"../Common/ArchiveOpenCallback.h\"\r\n\r\nclass COpenCallbackConsole: public IOpenCallbackUI\r\n{\r\npublic:\r\n  INTERFACE_IOpenCallbackUI(;)\r\n  \r\n  CStdOutStream *OutStream;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordIsDefined;\r\n  bool PasswordWasAsked;\r\n  UString Password;\r\n  COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {}\r\n  #endif\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/PercentPrinter.cpp",
    "content": "// PercentPrinter.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/IntToString.h\"\r\n#include \"Common/MyString.h\"\r\n\r\n#include \"PercentPrinter.h\"\r\n\r\nconst int kPaddingSize = 2;\r\nconst int kPercentsSize = 4;\r\nconst int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;\r\n\r\nstatic void ClearPrev(char *p, int num)\r\n{\r\n  int i;\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  for (i = 0; i < num; i++) *p++ = ' ';\r\n  for (i = 0; i < num; i++) *p++ = '\\b';\r\n  *p = '\\0';\r\n}\r\n\r\nvoid CPercentPrinter::ClosePrint()\r\n{\r\n  if (m_NumExtraChars == 0)\r\n    return;\r\n  char s[kMaxExtraSize * 3 + 1];\r\n  ClearPrev(s, m_NumExtraChars);\r\n  (*OutStream) << s;\r\n  m_NumExtraChars = 0;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const char *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintString(const wchar_t *s)\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << s;\r\n}\r\n\r\nvoid CPercentPrinter::PrintNewLine()\r\n{\r\n  ClosePrint();\r\n  (*OutStream) << \"\\n\";\r\n}\r\n\r\nvoid CPercentPrinter::RePrintRatio()\r\n{\r\n  char s[32];\r\n  ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s);\r\n  int size = (int)strlen(s);\r\n  s[size++] = '%';\r\n  s[size] = '\\0';\r\n\r\n  int extraSize = kPaddingSize + MyMax(size, kPercentsSize);\r\n  if (extraSize < m_NumExtraChars)\r\n    extraSize = m_NumExtraChars;\r\n\r\n  char fullString[kMaxExtraSize * 3];\r\n  char *p = fullString;\r\n  int i;\r\n  if (m_NumExtraChars == 0)\r\n  {\r\n    for (i = 0; i < extraSize; i++)\r\n      *p++ = ' ';\r\n    m_NumExtraChars = extraSize;\r\n  }\r\n\r\n  for (i = 0; i < m_NumExtraChars; i++)\r\n    *p++ = '\\b';\r\n  m_NumExtraChars = extraSize;\r\n  for (; size < m_NumExtraChars; size++)\r\n    *p++ = ' ';\r\n  MyStringCopy(p, s);\r\n  (*OutStream) << fullString;\r\n  OutStream->Flush();\r\n  m_PrevValue = m_CurValue;\r\n}\r\n\r\nvoid CPercentPrinter::PrintRatio()\r\n{\r\n  if (m_CurValue < m_PrevValue + m_MinStepSize &&\r\n      m_CurValue + m_MinStepSize > m_PrevValue && m_NumExtraChars != 0)\r\n    return;\r\n  RePrintRatio();\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/PercentPrinter.h",
    "content": "// PercentPrinter.h\r\n\r\n#ifndef __PERCENTPRINTER_H\r\n#define __PERCENTPRINTER_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/StdOutStream.h\"\r\n\r\nclass CPercentPrinter\r\n{\r\n  UInt64 m_MinStepSize;\r\n  UInt64 m_PrevValue;\r\n  UInt64 m_CurValue;\r\n  UInt64 m_Total;\r\n  int m_NumExtraChars;\r\npublic:\r\n  CStdOutStream *OutStream;\r\n\r\n  CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize),\r\n      m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}\r\n  void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }\r\n  void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }\r\n  void PrintString(const char *s);\r\n  void PrintString(const wchar_t *s);\r\n  void PrintNewLine();\r\n  void ClosePrint();\r\n  void RePrintRatio();\r\n  void PrintRatio();\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp",
    "content": "// UpdateCallbackConsole.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UpdateCallbackConsole.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifdef COMPRESS_MT\r\n#include \"Windows/Synchronization.h\"\r\n#endif\r\n\r\n#include \"ConsoleClose.h\"\r\n#include \"UserInputUtils.h\"\r\n\r\nusing namespace NWindows;\r\n\r\n#ifdef COMPRESS_MT\r\nstatic NSynchronization::CCriticalSection g_CriticalSection;\r\n#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);\r\n#else\r\n#define MT_LOCK\r\n#endif\r\n\r\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\r\n\r\nstatic const char *kCreatingArchiveMessage = \"Creating archive \";\r\nstatic const char *kUpdatingArchiveMessage = \"Updating archive \";\r\nstatic const char *kScanningMessage = \"Scanning\";\r\n\r\n\r\nHRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)\r\n{\r\n  (*OutStream) << endl;\r\n  if (result != S_OK)\r\n    (*OutStream) << \"Error: \" << name << \" is not supported archive\" << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartScanning()\r\n{\r\n  (*OutStream) << kScanningMessage;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::ScanProgress(UInt64 /* numFolders */, UInt64 /* numFiles */, const wchar_t * /* path */)\r\n{\r\n  return CheckBreak();\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)\r\n{\r\n  CantFindFiles.Add(name);\r\n  CantFindCodes.Add(systemError);\r\n  // m_PercentPrinter.ClosePrint();\r\n  if (!m_WarningsMode)\r\n  {\r\n    (*OutStream) << endl << endl;\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_WarningsMode = true;\r\n  }\r\n  m_PercentPrinter.PrintString(name);\r\n  m_PercentPrinter.PrintString(\":  WARNING: \");\r\n  m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n  m_PercentPrinter.PrintNewLine();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishScanning()\r\n{\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)\r\n{\r\n  if(updating)\r\n    (*OutStream) << kUpdatingArchiveMessage;\r\n  else\r\n    (*OutStream) << kCreatingArchiveMessage;\r\n  if (name != 0)\r\n    (*OutStream) << name;\r\n  else\r\n    (*OutStream) << \"StdOut\";\r\n  (*OutStream) << endl << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::FinishArchive()\r\n{\r\n  (*OutStream) << endl;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CheckBreak()\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::Finilize()\r\n{\r\n  MT_LOCK\r\n  if (m_NeedBeClosed)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.ClosePrint();\r\n    }\r\n    if (!StdOutMode && m_NeedNewLine)\r\n    {\r\n      m_PercentPrinter.PrintNewLine();\r\n      m_NeedNewLine = false;\r\n    }\r\n    m_NeedBeClosed = false;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */)\r\n{\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)\r\n{\r\n  MT_LOCK\r\n  if (EnablePercents)\r\n    m_PercentPrinter.SetTotal(size);\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)\r\n{\r\n  MT_LOCK\r\n  if (completeValue != NULL)\r\n  {\r\n    if (EnablePercents)\r\n    {\r\n      m_PercentPrinter.SetRatio(*completeValue);\r\n      m_PercentPrinter.PrintRatio();\r\n      m_NeedBeClosed = true;\r\n    }\r\n  }\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)\r\n{\r\n  if (NConsoleClose::TestBreakSignal())\r\n    return E_ABORT;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)\r\n{\r\n  MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  if(isAnti)\r\n    m_PercentPrinter.PrintString(\"Anti item    \");\r\n  else\r\n    m_PercentPrinter.PrintString(\"Compressing  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)\r\n{\r\n  MT_LOCK\r\n  FailedCodes.Add(systemError);\r\n  FailedFiles.Add(name);\r\n  // if (systemError == ERROR_SHARING_VIOLATION)\r\n  {\r\n    m_PercentPrinter.ClosePrint();\r\n    m_PercentPrinter.PrintNewLine();\r\n    m_PercentPrinter.PrintString(\"WARNING: \");\r\n    m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\r\n    return S_FALSE;\r\n  }\r\n  // return systemError;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )\r\n{\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\r\n{\r\n  #ifdef _NO_CRYPTO\r\n\r\n  *passwordIsDefined = false;\r\n  return StringToBstr(L\"\", password);\r\n  \r\n  #else\r\n  \r\n  if (!PasswordIsDefined)\r\n  {\r\n    if (AskPassword)\r\n    {\r\n      Password = GetPassword(OutStream);\r\n      PasswordIsDefined = true;\r\n    }\r\n  }\r\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\r\n  return StringToBstr(Password, password);\r\n  \r\n  #endif\r\n  \r\n}\r\n\r\n/*\r\nHRESULT CUpdateCallbackConsole::ShowDeleteFile(const wchar_t *name)\r\n{\r\n  // MT_LOCK\r\n  if (StdOutMode)\r\n    return S_OK;\r\n  RINOK(Finilize());\r\n  m_PercentPrinter.PrintString(\"Deleting  \");\r\n  if (name[0] == 0)\r\n    name = kEmptyFileAlias;\r\n  m_PercentPrinter.PrintString(name);\r\n  if (EnablePercents)\r\n    m_PercentPrinter.RePrintRatio();\r\n  m_NeedBeClosed = true;\r\n  m_NeedNewLine = true;\r\n  return S_OK;\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.h",
    "content": "// UpdateCallbackConsole.h\r\n\r\n#ifndef __UPDATECALLBACKCONSOLE_H\r\n#define __UPDATECALLBACKCONSOLE_H\r\n\r\n#include \"Common/MyString.h\"\r\n#include \"Common/StdOutStream.h\"\r\n#include \"PercentPrinter.h\"\r\n#include \"../Common/Update.h\"\r\n\r\nclass CUpdateCallbackConsole: public IUpdateCallbackUI2\r\n{\r\n  CPercentPrinter m_PercentPrinter;\r\n  bool m_NeedBeClosed;\r\n  bool m_NeedNewLine;\r\n\r\n  bool m_WarningsMode;\r\n\r\n  CStdOutStream *OutStream;\r\npublic:\r\n  bool EnablePercents;\r\n  bool StdOutMode;\r\n\r\n  #ifndef _NO_CRYPTO\r\n  bool PasswordIsDefined;\r\n  UString Password;\r\n  bool AskPassword;\r\n  #endif\r\n\r\n  CUpdateCallbackConsole():\r\n      m_PercentPrinter(1 << 16),\r\n      #ifndef _NO_CRYPTO\r\n      PasswordIsDefined(false),\r\n      AskPassword(false),\r\n      #endif\r\n      StdOutMode(false),\r\n      EnablePercents(true),\r\n      m_WarningsMode(false)\r\n      {}\r\n  \r\n  ~CUpdateCallbackConsole() { Finilize(); }\r\n  void Init(CStdOutStream *outStream)\r\n  {\r\n    m_NeedBeClosed = false;\r\n    m_NeedNewLine = false;\r\n    FailedFiles.Clear();\r\n    FailedCodes.Clear();\r\n    OutStream = outStream;\r\n    m_PercentPrinter.OutStream = outStream;\r\n  }\r\n\r\n  INTERFACE_IUpdateCallbackUI2(;)\r\n\r\n  UStringVector FailedFiles;\r\n  CRecordVector<HRESULT> FailedCodes;\r\n\r\n  UStringVector CantFindFiles;\r\n  CRecordVector<HRESULT> CantFindCodes;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/UserInputUtils.cpp",
    "content": "// UserInputUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Common/StdInStream.h\"\r\n#include \"Common/StringConvert.h\"\r\n\r\n#include \"UserInputUtils.h\"\r\n\r\nstatic const char kYes = 'Y';\r\nstatic const char kNo = 'N';\r\nstatic const char kYesAll = 'A';\r\nstatic const char kNoAll = 'S';\r\nstatic const char kAutoRenameAll = 'U';\r\nstatic const char kQuit = 'Q';\r\n\r\nstatic const char *kFirstQuestionMessage = \"?\\n\";\r\nstatic const char *kHelpQuestionMessage =\r\n  \"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? \";\r\n\r\n// return true if pressed Quite;\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << kFirstQuestionMessage;\r\n  for(;;)\r\n  {\r\n    (*outStream) << kHelpQuestionMessage;\r\n    AString scannedString = g_StdIn.ScanStringUntilNewLine();\r\n    scannedString.Trim();\r\n    if(!scannedString.IsEmpty())\r\n      switch(::MyCharUpper(scannedString[0]))\r\n      {\r\n        case kYes:\r\n          return NUserAnswerMode::kYes;\r\n        case kNo:\r\n          return NUserAnswerMode::kNo;\r\n        case kYesAll:\r\n          return NUserAnswerMode::kYesAll;\r\n        case kNoAll:\r\n          return NUserAnswerMode::kNoAll;\r\n        case kAutoRenameAll:\r\n          return NUserAnswerMode::kAutoRenameAll;\r\n        case kQuit:\r\n          return NUserAnswerMode::kQuit;\r\n      }\r\n  }\r\n}\r\n\r\nUString GetPassword(CStdOutStream *outStream)\r\n{\r\n  (*outStream) << \"\\nEnter password:\";\r\n  outStream->Flush();\r\n  AString oemPassword = g_StdIn.ScanStringUntilNewLine();\r\n  return MultiByteToUnicodeString(oemPassword, CP_OEMCP);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/UserInputUtils.h",
    "content": "// UserInputUtils.h\r\n\r\n#ifndef __USERINPUTUTILS_H\r\n#define __USERINPUTUTILS_H\r\n\r\n#include \"Common/StdOutStream.h\"\r\n\r\nnamespace NUserAnswerMode {\r\n\r\nenum EEnum\r\n{\r\n  kYes,\r\n  kNo,\r\n  kYesAll,\r\n  kNoAll,\r\n  kAutoRenameAll,\r\n  kQuit\r\n};\r\n}\r\n\r\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);\r\nUString GetPassword(CStdOutStream *outStream);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/7zip/UI/Console/makefile",
    "content": "PROG = 7z.exe\r\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\r\nCFLAGS = $(CFLAGS) -I ../../../  \\\r\n  -DCOMPRESS_MT \\\r\n  -DWIN_LONG_PATH \\\r\n  -DEXTERNAL_LZMA \\\r\n  -DEXTERNAL_CODECS \\\r\n  -DBREAK_HANDLER \\\r\n  -DBENCH_MT \\\r\n  -D_7ZIP_LARGE_PAGES \\\r\n\r\nCONSOLE_OBJS = \\\r\n  $O\\ConsoleClose.obj \\\r\n  $O\\ExtractCallbackConsole.obj \\\r\n  $O\\List.obj \\\r\n  $O\\Main.obj \\\r\n  $O\\MainAr.obj \\\r\n  $O\\OpenCallbackConsole.obj \\\r\n  $O\\PercentPrinter.obj \\\r\n  $O\\UpdateCallbackConsole.obj \\\r\n  $O\\UserInputUtils.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\IntToString.obj \\\r\n  $O\\ListFileUtils.obj \\\r\n  $O\\NewHandler.obj \\\r\n  $O\\StdInStream.obj \\\r\n  $O\\StdOutStream.obj \\\r\n  $O\\MyString.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\UTFConvert.obj \\\r\n  $O\\MyVector.obj \\\r\n  $O\\Wildcard.obj \\\r\n\r\nWIN_OBJS = \\\r\n  $O\\DLL.obj \\\r\n  $O\\Error.obj \\\r\n  $O\\FileDir.obj \\\r\n  $O\\FileFind.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\FileName.obj \\\r\n  $O\\MemoryLock.obj \\\r\n  $O\\PropVariant.obj \\\r\n  $O\\PropVariantConversions.obj \\\r\n  $O\\Registry.obj \\\r\n  $O\\System.obj \\\r\n  $O\\Time.obj \\\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\FilePathAutoRename.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\ProgressUtils.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nUI_COMMON_OBJS = \\\r\n  $O\\ArchiveCommandLine.obj \\\r\n  $O\\ArchiveExtractCallback.obj \\\r\n  $O\\ArchiveOpenCallback.obj \\\r\n  $O\\DefaultName.obj \\\r\n  $O\\EnumDirItems.obj \\\r\n  $O\\Extract.obj \\\r\n  $O\\ExtractingFilePath.obj \\\r\n  $O\\LoadCodecs.obj \\\r\n  $O\\OpenArchive.obj \\\r\n  $O\\PropIDUtils.obj \\\r\n  $O\\SetProperties.obj \\\r\n  $O\\SortUtils.obj \\\r\n  $O\\TempFiles.obj \\\r\n  $O\\Update.obj \\\r\n  $O\\UpdateAction.obj \\\r\n  $O\\UpdateCallback.obj \\\r\n  $O\\UpdatePair.obj \\\r\n  $O\\UpdateProduce.obj \\\r\n  $O\\WorkDir.obj \\\r\n\r\nLZMA_BENCH_OBJS = \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaBenchCon.obj \\\r\n\r\nC_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\Threads.obj \\\r\n\r\n!include \"../../Crc2.mak\"\r\n\r\nOBJS = \\\r\n  $O\\StdAfx.obj \\\r\n  $(CONSOLE_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(WIN_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(UI_COMMON_OBJS) \\\r\n  $O\\CopyCoder.obj \\\r\n  $(LZMA_BENCH_OBJS) \\\r\n  $(C_OBJS) \\\r\n  $(CRC_OBJS) \\\r\n  $O\\resource.res\r\n\r\n!include \"../../../Build.mak\"\r\n\r\n$(CONSOLE_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(UI_COMMON_OBJS): ../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\CopyCoder.obj: ../../Compress/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\r\n\t$(COMPL)\r\n$(C_OBJS): ../../../../C/$(*B).c\r\n\t$(COMPL_O2)\r\n!include \"../../Crc.mak\"\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Build.mak",
    "content": "!IFDEF CPU\r\n!IFNDEF NO_BUFFEROVERFLOWU\r\nLIBS = $(LIBS) bufferoverflowU.lib\r\n!ENDIF\r\n!ENDIF\r\n\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\n!IF \"$(CPU)\" != \"IA64\"\r\n!IF \"$(CPU)\" != \"AMD64\"\r\nMY_ML = ml\r\n!ELSE\r\nMY_ML = ml64\r\n!ENDIF\r\n!ENDIF\r\n\r\nCOMPL_ASM = $(MY_ML) -c -Fo$O/ $**\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -WX -EHsc -Gr -Gy -GR-\r\n\r\n!IFDEF MY_STATIC_LINK\r\n!IFNDEF MY_SINGLE_THREAD\r\nCFLAGS = $(CFLAGS) -MT\r\n!ENDIF\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -MD\r\n!ENDIF\r\n\r\n!IFDEF NEW_COMPILER\r\nCFLAGS = $(CFLAGS) -W4 -GS- -Zc:forScope\r\n!ELSE\r\nCFLAGS = $(CFLAGS) -W3\r\n!ENDIF\r\n\r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF -OPT:ICF\r\n\r\n!IFDEF DEF_FILE\r\nLFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)\r\n!ENDIF\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL_PCH  = $(CPP) $(CFLAGS_O1) -Yc\"StdAfx.h\" -Fp$O/a.pch $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) -Yu\"StdAfx.h\" -Fp$O/a.pch $**\r\n\r\nall: $(PROGPATH)\r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch\r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS) $(DEF_FILE)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n$O\\resource.res: $(*B).rc\r\n\trc -fo$@ $**\r\n$O\\StdAfx.obj: $(*B).cpp\r\n\t$(COMPL_PCH)\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/AutoPtr.h",
    "content": "// Common/AutoPtr.h\r\n\r\n#ifndef __COMMON_AUTOPTR_H\r\n#define __COMMON_AUTOPTR_H\r\n\r\ntemplate<class T> class CMyAutoPtr\r\n{\r\n  T *_p;\r\npublic:\r\n  CMyAutoPtr(T *p = 0) : _p(p) {}\r\n  CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {}\r\n  CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p)\r\n  {\r\n    reset(p.release());\r\n    return (*this);\r\n  }\r\n  ~CMyAutoPtr() { delete _p; }\r\n  T& operator*() const { return *_p; }\r\n  // T* operator->() const { return (&**this); }\r\n  T* get() const { return _p; }\r\n  T* release()\r\n  {\r\n    T *tmp = _p;\r\n    _p = 0;\r\n    return tmp;\r\n  }\r\n  void reset(T* p = 0)\r\n  {\r\n    if (p != _p)\r\n      delete _p;\r\n    _p = p;\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/Buffer.h",
    "content": "// Common/Buffer.h\r\n\r\n#ifndef __COMMON_BUFFER_H\r\n#define __COMMON_BUFFER_H\r\n\r\n#include \"Defs.h\"\r\n\r\ntemplate <class T> class CBuffer\r\n{\r\nprotected:\r\n  size_t _capacity;\r\n  T *_items;\r\npublic:\r\n  void Free()\r\n  {\r\n    delete []_items;\r\n    _items = 0;\r\n    _capacity = 0;\r\n  }\r\n  CBuffer(): _capacity(0), _items(0) {};\r\n  CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }\r\n  CBuffer(size_t size): _items(0),  _capacity(0) {  SetCapacity(size); }\r\n  virtual ~CBuffer() { delete []_items; }\r\n  operator T *() { return _items; };\r\n  operator const T *() const { return _items; };\r\n  size_t GetCapacity() const { return  _capacity; }\r\n  void SetCapacity(size_t newCapacity)\r\n  {\r\n    if (newCapacity == _capacity)\r\n      return;\r\n    T *newBuffer;\r\n    if (newCapacity > 0)\r\n    {\r\n      newBuffer = new T[newCapacity];\r\n      if (_capacity > 0)\r\n        memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));\r\n    }\r\n    else\r\n      newBuffer = 0;\r\n    delete []_items;\r\n    _items = newBuffer;\r\n    _capacity = newCapacity;\r\n  }\r\n  CBuffer& operator=(const CBuffer &buffer)\r\n  {\r\n    Free();\r\n    if (buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nbool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  if (b1.GetCapacity() != b2.GetCapacity())\r\n    return false;\r\n  for (size_t i = 0; i < b1.GetCapacity(); i++)\r\n    if (b1[i] != b2[i])\r\n      return false;\r\n  return true;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)\r\n{\r\n  return !(b1 == b2);\r\n}\r\n\r\ntypedef CBuffer<char> CCharBuffer;\r\ntypedef CBuffer<wchar_t> CWCharBuffer;\r\ntypedef CBuffer<unsigned char> CByteBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/7zCrc.h\"\r\n}\r\n\r\nstruct CCRCTableInit { CCRCTableInit() { CrcGenerateTable(); } } g_CRCTableInit;\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nbool CInFile::OpenShared(const char *name, bool)\r\n{\r\n  return Open(name);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nbool COutFile::Open(const char *name, DWORD creationDisposition)\r\n{\r\n  return Create(name, false);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  bool OpenShared(const char *name, bool shareForWrite);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  bool Open(const char *name, DWORD creationDisposition);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else\r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  for (;;)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      break;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{\r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */);\r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms,\r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0)\r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while (pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for (int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len)\r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if (temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if (_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString:\r\n      case NSwitchType::kUnLimitedPostString:\r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for (int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\r\n    const UString &commandString, UString &postString)\r\n{\r\n  for (int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if (commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"MyString.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  {\r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms);\r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms,\r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\r\n    const UString &commandString, UString &postString);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/DynamicBuffer.h",
    "content": "// Common/DynamicBuffer.h\r\n\r\n#ifndef __COMMON_DYNAMICBUFFER_H\r\n#define __COMMON_DYNAMICBUFFER_H\r\n\r\n#include \"Buffer.h\"\r\n\r\ntemplate <class T> class CDynamicBuffer: public CBuffer<T>\r\n{\r\n  void GrowLength(size_t size)\r\n  {\r\n    size_t delta;\r\n    if (this->_capacity > 64)\r\n      delta = this->_capacity / 4;\r\n    else if (this->_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    delta = MyMax(delta, size);\r\n    SetCapacity(this->_capacity + delta);\r\n  }\r\npublic:\r\n  CDynamicBuffer(): CBuffer<T>() {};\r\n  CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};\r\n  CDynamicBuffer(size_t size): CBuffer<T>(size) {};\r\n  CDynamicBuffer& operator=(const CDynamicBuffer &buffer)\r\n  {\r\n    this->Free();\r\n    if (buffer._capacity > 0)\r\n    {\r\n      SetCapacity(buffer._capacity);\r\n      memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));\r\n    }\r\n    return *this;\r\n  }\r\n  void EnsureCapacity(size_t capacity)\r\n  {\r\n    if (this->_capacity < capacity)\r\n      GrowLength(capacity - this->_capacity);\r\n  }\r\n};\r\n\r\ntypedef CDynamicBuffer<char> CCharDynamicBuffer;\r\ntypedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;\r\ntypedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/IntToString.cpp",
    "content": "// Common/IntToString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"IntToString.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)\r\n{\r\n  if (base < 2 || base > 36)\r\n  {\r\n    *s = '\\0';\r\n    return;\r\n  }\r\n  char temp[72];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    int delta = (int)(value % base);\r\n    temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));\r\n    value /= base;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n}\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s)\r\n{\r\n  wchar_t temp[32];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = L'\\0';\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = '-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s)\r\n{\r\n  if (value < 0)\r\n  {\r\n    *s++ = L'-';\r\n    value = -value;\r\n  }\r\n  ConvertUInt64ToString(value, s);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/IntToString.h",
    "content": "// Common/IntToString.h\r\n\r\n#ifndef __COMMON_INTTOSTRING_H\r\n#define __COMMON_INTTOSTRING_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);\r\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s);\r\n\r\nvoid ConvertInt64ToString(Int64 value, char *s);\r\nvoid ConvertInt64ToString(Int64 value, wchar_t *s);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/ListFileUtils.cpp",
    "content": "// Common/ListFileUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"MyWindows.h\"\r\n#include \"../Windows/FileIO.h\"\r\n\r\n#include \"ListFileUtils.h\"\r\n#include \"StringConvert.h\"\r\n#include \"UTFConvert.h\"\r\n\r\nstatic const char kQuoteChar     = '\\\"';\r\nstatic void RemoveQuote(UString &s)\r\n{\r\n  if (s.Length() >= 2)\r\n    if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)\r\n      s = s.Mid(1, s.Length() - 2);\r\n}\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)\r\n{\r\n  NWindows::NFile::NIO::CInFile file;\r\n  if (!file.Open(fileName))\r\n    return false;\r\n  UInt64 length;\r\n  if (!file.GetLength(length))\r\n    return false;\r\n  if (length > ((UInt32)1 << 31))\r\n    return false;\r\n  AString s;\r\n  char *p = s.GetBuffer((int)length + 1);\r\n  UInt32 processed;\r\n  if (!file.Read(p, (UInt32)length, processed))\r\n    return false;\r\n  p[(UInt32)length] = 0;\r\n  s.ReleaseBuffer();\r\n  file.Close();\r\n\r\n  UString u;\r\n  #ifdef CP_UTF8\r\n  if (codePage == CP_UTF8)\r\n  {\r\n    if (!ConvertUTF8ToUnicode(s, u))\r\n      return false;\r\n  }\r\n  else\r\n  #endif\r\n    u = MultiByteToUnicodeString(s, codePage);\r\n  if (!u.IsEmpty())\r\n  {\r\n    if (u[0] == 0xFEFF)\r\n      u.Delete(0);\r\n  }\r\n\r\n  UString t;\r\n  for (int i = 0; i < u.Length(); i++)\r\n  {\r\n    wchar_t c = u[i];\r\n    if (c == L'\\n' || c == 0xD)\r\n    {\r\n      t.Trim();\r\n      RemoveQuote(t);\r\n      if (!t.IsEmpty())\r\n        resultStrings.Add(t);\r\n      t.Empty();\r\n    }\r\n    else\r\n      t += c;\r\n  }\r\n  t.Trim();\r\n  RemoveQuote(t);\r\n  if (!t.IsEmpty())\r\n    resultStrings.Add(t);\r\n  return true;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/ListFileUtils.h",
    "content": "// Common/ListFileUtils.h\r\n\r\n#ifndef __COMMON_LISTFILEUTILS_H\r\n#define __COMMON_LISTFILEUTILS_H\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#ifndef RINOK\r\n#define RINOK(x) { HRESULT __result_ = (x); if (__result_ != S_OK) return __result_; }\r\n#endif\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p)\r\n  {\r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p)\r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\ninline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr)\r\n{\r\n  *bstr = ::SysAllocString(src);\r\n  return (*bstr != 0) ? S_OK : E_OUTOFMEMORY;\r\n}\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR(): m_str(NULL) {}\r\n  CMyComBSTR(LPCOLESTR src) { m_str = ::SysAllocString(src); }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR src)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(src);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const\r\n  {\r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memcpy(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  /*\r\n  void Attach(BSTR src) { m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  */\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) {\r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \\\r\n    { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \\\r\n    MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n    MY_QUERYINTERFACE_ENTRY(i)\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyException.h",
    "content": "// Common/Exception.h\r\n\r\n#ifndef __COMMON_EXCEPTION_H\r\n#define __COMMON_EXCEPTION_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\nstruct CSystemException\r\n{\r\n  HRESULT ErrorCode;\r\n  CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline int operator==(REFGUID g1, REFGUID g2)\r\n{\r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return 0;\r\n  return 1;\r\n}\r\ninline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyString.cpp",
    "content": "// Common/MyString.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <ctype.h>\r\n#endif\r\n\r\n#ifndef _UNICODE\r\n#include \"StringConvert.h\"\r\n#endif\r\n\r\n#include \"MyString.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1);\r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1),\r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{\r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1));\r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{\r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1));\r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1);\r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1),\r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n/*\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{\r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyString.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{\r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{\r\n  T *destStart = dest;\r\n  while ((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n// int MyStringCompareNoCase(const char *s1, const char  *s2);\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if (pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex,\r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n  int _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if (realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if (newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if (_capacity > 0)\r\n    {\r\n      for (int i = 0; i < _length; i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n    }\r\n    _chars = newBuffer;\r\n    _chars[_length] = 0;\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize)\r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0) { SetCapacity(3); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;}\r\n\r\n  // The minimum size of the character buffer in characters.\r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if (minBufLength >= _capacity)\r\n      SetCapacity(minBufLength);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if (newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if (&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int Compare(const T *s) const\r\n    { return MyStringCompare(_chars, s); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const T *s) const\r\n    { return MyStringCompareNoCase(_chars, s); }\r\n\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    for (;;)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for (int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    charSet += (T)' ';\r\n    charSet += (T)'\\n';\r\n    charSet += (T)'\\t';\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if (pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for (int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0)\r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0)\r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result;\r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct\r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else\r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyVector.cpp",
    "content": "// Common/MyVector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"MyVector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector() { ClearAndFree(); }\r\n\r\nvoid CBaseRecordVector::ClearAndFree()\r\n{\r\n  Clear();\r\n  delete []((unsigned char *)_items);\r\n  _capacity = 0;\r\n  _size = 0;\r\n  _items = 0;\r\n}\r\n\r\nvoid CBaseRecordVector::Clear() { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index) { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if (_size != _capacity)\r\n    return;\r\n  int delta = 1;\r\n  if (_capacity >= 64)\r\n    delta = _capacity / 4;\r\n  else if (_capacity >= 8)\r\n    delta = 8;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  // if (newCapacity <= _capacity)\r\n  if (newCapacity == _capacity)\r\n    return;\r\n  if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))\r\n    throw 1052353;\r\n  size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;\r\n  if (newSize / _itemSize != (size_t)(unsigned)newCapacity)\r\n    throw 1052354;\r\n  unsigned char *p = NULL;\r\n  if (newSize > 0)\r\n  {\r\n    p = new unsigned char[newSize];\r\n    if (p == 0)\r\n      throw 1052355;\r\n    int numRecordsToMove = (_size < newCapacity ? _size : newCapacity);\r\n    memcpy(p, _items, _itemSize * numRecordsToMove);\r\n  }\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::ReserveDown()\r\n{\r\n  Reserve(_size);\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize,\r\n    ((unsigned char  *)_items) + srcIndex * _itemSize,\r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyVector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n  int _capacity;\r\n  int _size;\r\n  void *_items;\r\n  size_t _itemSize;\r\n  \r\n  void ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; }\r\npublic:\r\n  CBaseRecordVector(size_t itemSize): _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n  virtual ~CBaseRecordVector();\r\n  void ClearAndFree();\r\n  int Size() const { return _size; }\r\n  bool IsEmpty() const { return (_size == 0); }\r\n  void Reserve(int newCapacity);\r\n  void ReserveDown();\r\n  virtual void Delete(int index, int num = 1);\r\n  void Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector(): CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v): CBaseRecordVector(sizeof(T)) { *this = v; }\r\n  CRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for (int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  int Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n  void Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n  T& operator[](int index) { return ((T *)_items)[index]; }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  T& Back() { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n\r\n  int AddToUniqueSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    T temp = p[k];\r\n    for (;;)\r\n    {\r\n      int s = (k << 1);\r\n      if (s > size)\r\n        break;\r\n      if (s < size && compare(p + s + 1, p + s, param) > 0)\r\n        s++;\r\n      if (compare(&temp, p + s, param) >= 0)\r\n        break;\r\n      p[k] = p[s];\r\n      k = s;\r\n    }\r\n    p[k] = temp;\r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param)\r\n  {\r\n    int size = _size;\r\n    if (size <= 1)\r\n      return;\r\n    T* p = (&Front()) - 1;\r\n    {\r\n      int i = size / 2;\r\n      do\r\n        SortRefDown(p, i, size, compare, param);\r\n      while (--i != 0);\r\n    }\r\n    do\r\n    {\r\n      T temp = p[size];\r\n      p[size--] = p[1];\r\n      p[1] = temp;\r\n      SortRefDown(p, 1, size, compare, param);\r\n    }\r\n    while (size > 1);\r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector() {};\r\n  ~CObjectVector() { Clear(); };\r\n  CObjectVector(const CObjectVector &v) { *this = v; }\r\n  CObjectVector& operator=(const CObjectVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CObjectVector& operator+=(const CObjectVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for (int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n  const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n  T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n  T& Front() { return operator[](0); }\r\n  const T& Front() const { return operator[](0); }\r\n  T& Back() { return operator[](_size - 1); }\r\n  const T& Back() const { return operator[](_size - 1); }\r\n  int Add(const T& item) { return CPointerVector::Add(new T(item)); }\r\n  void Insert(int index, const T& item) { CPointerVector::Insert(index, new T(item)); }\r\n  virtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for (int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for (int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n    return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size();\r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param)\r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#define CHAR_PATH_SEPARATOR '\\\\'\r\n#define WCHAR_PATH_SEPARATOR L'\\\\'\r\n#define STRING_PATH_SEPARATOR \"\\\\\"\r\n#define WSTRING_PATH_SEPARATOR L\"\\\\\"\r\n\r\n#else\r\n\r\n#define CHAR_PATH_SEPARATOR '/'\r\n#define WCHAR_PATH_SEPARATOR L'/'\r\n#define STRING_PATH_SEPARATOR \"/\"\r\n#define WSTRING_PATH_SEPARATOR L\"/\"\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\n\r\n#undef BYTE\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\n\r\n#undef WORD\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\n\r\n#undef DWORD\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOTIMPL ((HRESULT)0x80004001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall\r\n#else\r\n#define STDMETHODCALLTYPE\r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct\r\n\r\n#ifdef __cplusplus\r\n\r\nDEFINE_GUID(IID_IUnknown,\r\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n  #ifndef _WIN32\r\n  virtual ~IUnknown() {}\r\n  #endif\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#endif\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\r\n  VT_EMPTY = 0,\r\n  VT_NULL = 1,\r\n  VT_I2 = 2,\r\n  VT_I4 = 3,\r\n  VT_R4 = 4,\r\n  VT_R8 = 5,\r\n  VT_CY = 6,\r\n  VT_DATE = 7,\r\n  VT_BSTR = 8,\r\n  VT_DISPATCH = 9,\r\n  VT_ERROR = 10,\r\n  VT_BOOL = 11,\r\n  VT_VARIANT = 12,\r\n  VT_UNKNOWN = 13,\r\n  VT_DECIMAL = 14,\r\n  VT_I1 = 16,\r\n  VT_UI1 = 17,\r\n  VT_UI2 = 18,\r\n  VT_UI4 = 19,\r\n  VT_I8 = 20,\r\n  VT_UI8 = 21,\r\n  VT_INT = 22,\r\n  VT_UINT = 23,\r\n  VT_VOID = 24,\r\n  VT_HRESULT = 25,\r\n  VT_FILETIME = 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\n#ifdef __cplusplus\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union\r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\n\r\n#endif\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\r\n  STREAM_SEEK_SET = 0,\r\n  STREAM_SEEK_CUR = 1,\r\n  STREAM_SEEK_END = 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\n#ifdef _WIN32\r\nvoid *\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n#endif\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\n#ifdef _WIN32\r\nvoid\r\n#ifdef _MSC_VER\r\n__cdecl\r\n#endif\r\noperator delete(void *p) throw();\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/StdInStream.cpp",
    "content": "// Common/StdInStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n#include \"StdInStream.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kIllegalChar = '\\0';\r\nstatic const char kNewLineChar = '\\n';\r\n\r\nstatic const char *kEOFMessage = \"Unexpected end of input stream\";\r\nstatic const char *kReadErrorMessage  =\"Error reading input stream\";\r\nstatic const char *kIllegalCharMessage = \"Illegal character in input stream\";\r\n\r\nstatic LPCTSTR kFileOpenMode = TEXT(\"r\");\r\n\r\nCStdInStream g_StdIn(stdin);\r\n\r\nbool CStdInStream::Open(LPCTSTR fileName)\r\n{\r\n  Close();\r\n  _stream = _tfopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdInStream::Close()\r\n{\r\n  if (!_streamIsOpen)\r\n    return true;\r\n  _streamIsOpen = (fclose(_stream) != 0);\r\n  return !_streamIsOpen;\r\n}\r\n\r\nCStdInStream::~CStdInStream()\r\n{\r\n  Close();\r\n}\r\n\r\nAString CStdInStream::ScanStringUntilNewLine()\r\n{\r\n  AString s;\r\n  for (;;)\r\n  {\r\n    int intChar = GetChar();\r\n    if (intChar == EOF)\r\n      throw kEOFMessage;\r\n    char c = char(intChar);\r\n    if (c == kIllegalChar)\r\n      throw kIllegalCharMessage;\r\n    if (c == kNewLineChar)\r\n      break;\r\n    s += c;\r\n  }\r\n  return s;\r\n}\r\n\r\nvoid CStdInStream::ReadToString(AString &resultString)\r\n{\r\n  resultString.Empty();\r\n  int c;\r\n  while ((c = GetChar()) != EOF)\r\n    resultString += char(c);\r\n}\r\n\r\nbool CStdInStream::Eof()\r\n{\r\n  return (feof(_stream) != 0);\r\n}\r\n\r\nint CStdInStream::GetChar()\r\n{\r\n  int c = fgetc(_stream); // getc() doesn't work in BeOS?\r\n  if (c == EOF && !Eof())\r\n    throw kReadErrorMessage;\r\n  return c;\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/StdInStream.h",
    "content": "// Common/StdInStream.h\r\n\r\n#ifndef __COMMON_STDINSTREAM_H\r\n#define __COMMON_STDINSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nclass CStdInStream\r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdInStream(): _streamIsOpen(false) {};\r\n  CStdInStream(FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdInStream();\r\n  bool Open(LPCTSTR fileName);\r\n  bool Close();\r\n\r\n  AString ScanStringUntilNewLine();\r\n  void ReadToString(AString &resultString);\r\n\r\n  bool Eof();\r\n  int GetChar();\r\n};\r\n\r\nextern CStdInStream g_StdIn;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/StdOutStream.cpp",
    "content": "// Common/StdOutStream.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <tchar.h>\r\n\r\n#include \"StdOutStream.h\"\r\n#include \"IntToString.h\"\r\n#include \"StringConvert.h\"\r\n\r\n#ifdef _MSC_VER\r\n// \"was declared deprecated\" disabling\r\n#pragma warning(disable : 4996 )\r\n#endif\r\n\r\nstatic const char kNewLineChar =  '\\n';\r\n\r\nstatic const char *kFileOpenMode = \"wt\";\r\n\r\nCStdOutStream  g_StdOut(stdout);\r\nCStdOutStream  g_StdErr(stderr);\r\n\r\nbool CStdOutStream::Open(const char *fileName)\r\n{\r\n  Close();\r\n  _stream = fopen(fileName, kFileOpenMode);\r\n  _streamIsOpen = (_stream != 0);\r\n  return _streamIsOpen;\r\n}\r\n\r\nbool CStdOutStream::Close()\r\n{\r\n  if (!_streamIsOpen)\r\n    return true;\r\n  if (fclose(_stream) != 0)\r\n    return false;\r\n  _stream = 0;\r\n  _streamIsOpen = false;\r\n  return true;\r\n}\r\n\r\nbool CStdOutStream::Flush()\r\n{\r\n  return (fflush(_stream) == 0);\r\n}\r\n\r\nCStdOutStream::~CStdOutStream ()\r\n{\r\n  Close();\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream  &))\r\n{\r\n  (*aFunction)(*this);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream)\r\n{\r\n  return outStream << kNewLineChar;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const char *string)\r\n{\r\n  fputs(string, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(const wchar_t *string)\r\n{\r\n  *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(char c)\r\n{\r\n  fputc(c, _stream);\r\n  return *this;\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(int number)\r\n{\r\n  char textString[32];\r\n  ConvertInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n\r\nCStdOutStream & CStdOutStream::operator<<(UInt64 number)\r\n{\r\n  char textString[32];\r\n  ConvertUInt64ToString(number, textString);\r\n  return operator<<(textString);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/StdOutStream.h",
    "content": "// Common/StdOutStream.h\r\n\r\n#ifndef __COMMON_STDOUTSTREAM_H\r\n#define __COMMON_STDOUTSTREAM_H\r\n\r\n#include <stdio.h>\r\n\r\n#include \"Types.h\"\r\n\r\nclass CStdOutStream\r\n{\r\n  bool _streamIsOpen;\r\n  FILE *_stream;\r\npublic:\r\n  CStdOutStream (): _streamIsOpen(false), _stream(0) {};\r\n  CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};\r\n  ~CStdOutStream ();\r\n  operator FILE *() { return _stream; }\r\n  bool Open(const char *fileName);\r\n  bool Close();\r\n  bool Flush();\r\n  CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream  &));\r\n  CStdOutStream & operator<<(const char *string);\r\n  CStdOutStream & operator<<(const wchar_t *string);\r\n  CStdOutStream & operator<<(char c);\r\n  CStdOutStream & operator<<(int number);\r\n  CStdOutStream & operator<<(UInt64 number);\r\n};\r\n\r\nCStdOutStream & endl(CStdOutStream & outStream);\r\n\r\nextern CStdOutStream g_StdOut;\r\nextern CStdOutStream g_StdErr;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString,\r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()),\r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if (numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed)\r\n{\r\n  AString dest;\r\n  defaultCharWasUsed = false;\r\n  if (!s.IsEmpty())\r\n  {\r\n    int numRequiredBytes = s.Length() * 2;\r\n    BOOL defUsed;\r\n    int numChars = WideCharToMultiByte(codePage, 0, s, s.Length(),\r\n        dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1,\r\n        &defaultChar, &defUsed);\r\n    defaultCharWasUsed = (defUsed != FALSE);\r\n    #ifndef _WIN32_WCE\r\n    if (numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    dest.ReleaseBuffer(numChars);\r\n  }\r\n  return dest;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  bool defaultCharWasUsed;\r\n  return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed);\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if (!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"MyString.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage, char defaultChar, bool &defaultCharWasUsed);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    char c = *s;\r\n    UInt32 v;\r\n    if (c >= '0' && c <= '9') v = (c - '0');\r\n    else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A');\r\n    else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a');\r\n    else\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 4;\r\n    result |= v;\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  for (;;)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Types.h\"\r\n}\r\n\r\ntypedef int HRes;\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/UTFConvert.cpp",
    "content": "// UTFConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"UTFConvert.h\"\r\n#include \"Types.h\"\r\n\r\nstatic const Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nstatic Bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, size_t srcLen)\r\n{\r\n  size_t destPos = 0, srcPos = 0;\r\n  for (;;)\r\n  {\r\n    Byte c;\r\n    int numAdds;\r\n    if (srcPos == srcLen)\r\n    {\r\n      *destLen = destPos;\r\n      return True;\r\n    }\r\n    c = (Byte)src[srcPos++];\r\n\r\n    if (c < 0x80)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (wchar_t)c;\r\n      destPos++;\r\n      continue;\r\n    }\r\n    if (c < 0xC0)\r\n      break;\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (c < kUtf8Limits[numAdds])\r\n        break;\r\n    UInt32 value = (c - kUtf8Limits[numAdds - 1]);\r\n\r\n    do\r\n    {\r\n      Byte c2;\r\n      if (srcPos == srcLen)\r\n        break;\r\n      c2 = (Byte)src[srcPos++];\r\n      if (c2 < 0x80 || c2 >= 0xC0)\r\n        break;\r\n      value <<= 6;\r\n      value |= (c2 - 0x80);\r\n    }\r\n    while (--numAdds != 0);\r\n    \r\n    if (value < 0x10000)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (wchar_t)value;\r\n      destPos++;\r\n    }\r\n    else\r\n    {\r\n      value -= 0x10000;\r\n      if (value >= 0x100000)\r\n        break;\r\n      if (dest)\r\n      {\r\n        dest[destPos + 0] = (wchar_t)(0xD800 + (value >> 10));\r\n        dest[destPos + 1] = (wchar_t)(0xDC00 + (value & 0x3FF));\r\n      }\r\n      destPos += 2;\r\n    }\r\n  }\r\n  *destLen = destPos;\r\n  return False;\r\n}\r\n\r\nstatic Bool Utf16_To_Utf8(char *dest, size_t *destLen, const wchar_t *src, size_t srcLen)\r\n{\r\n  size_t destPos = 0, srcPos = 0;\r\n  for (;;)\r\n  {\r\n    unsigned numAdds;\r\n    UInt32 value;\r\n    if (srcPos == srcLen)\r\n    {\r\n      *destLen = destPos;\r\n      return True;\r\n    }\r\n    value = src[srcPos++];\r\n    if (value < 0x80)\r\n    {\r\n      if (dest)\r\n        dest[destPos] = (char)value;\r\n      destPos++;\r\n      continue;\r\n    }\r\n    if (value >= 0xD800 && value < 0xE000)\r\n    {\r\n      UInt32 c2;\r\n      if (value >= 0xDC00 || srcPos == srcLen)\r\n        break;\r\n      c2 = src[srcPos++];\r\n      if (c2 < 0xDC00 || c2 >= 0xE000)\r\n        break;\r\n      value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n    }\r\n    for (numAdds = 1; numAdds < 5; numAdds++)\r\n      if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n        break;\r\n    if (dest)\r\n      dest[destPos] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n    destPos++;\r\n    do\r\n    {\r\n      numAdds--;\r\n      if (dest)\r\n        dest[destPos] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      destPos++;\r\n    }\r\n    while (numAdds != 0);\r\n  }\r\n  *destLen = destPos;\r\n  return False;\r\n}\r\n\r\nbool ConvertUTF8ToUnicode(const AString &src, UString &dest)\r\n{\r\n  dest.Empty();\r\n  size_t destLen = 0;\r\n  Utf8_To_Utf16(NULL, &destLen, src, src.Length());\r\n  wchar_t *p = dest.GetBuffer((int)destLen);\r\n  Bool res = Utf8_To_Utf16(p, &destLen, src, src.Length());\r\n  p[destLen] = 0;\r\n  dest.ReleaseBuffer();\r\n  return res ? true : false;\r\n}\r\n\r\nbool ConvertUnicodeToUTF8(const UString &src, AString &dest)\r\n{\r\n  dest.Empty();\r\n  size_t destLen = 0;\r\n  Utf16_To_Utf8(NULL, &destLen, src, src.Length());\r\n  char *p = dest.GetBuffer((int)destLen);\r\n  Bool res = Utf16_To_Utf8(p, &destLen, src, src.Length());\r\n  p[destLen] = 0;\r\n  dest.ReleaseBuffer();\r\n  return res ? true : false;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/UTFConvert.h",
    "content": "// Common/UTFConvert.h\r\n\r\n#ifndef __COMMON_UTFCONVERT_H\r\n#define __COMMON_UTFCONVERT_H\r\n\r\n#include \"MyString.h\"\r\n\r\nbool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);\r\nbool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/Wildcard.cpp",
    "content": "// Common/Wildcard.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Wildcard.h\"\r\n\r\nbool g_CaseSensitive =\r\n  #ifdef _WIN32\r\n    false;\r\n  #else\r\n    true;\r\n  #endif\r\n\r\nstatic const wchar_t kAnyCharsChar = L'*';\r\nstatic const wchar_t kAnyCharChar = L'?';\r\n\r\n#ifdef _WIN32\r\nstatic const wchar_t kDirDelimiter1 = L'\\\\';\r\n#endif\r\nstatic const wchar_t kDirDelimiter2 = L'/';\r\n\r\nstatic const UString kWildCardCharSet = L\"?*\";\r\n\r\nstatic const UString kIllegalWildCardFileNameChars=\r\n  L\"\\x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\xA\\xB\\xC\\xD\\xE\\xF\"\r\n  L\"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F\"\r\n  L\"\\\"/:<>\\\\|\";\r\n\r\n\r\nstatic inline bool IsCharDirLimiter(wchar_t c)\r\n{\r\n  return (\r\n    #ifdef _WIN32\r\n    c == kDirDelimiter1 ||\r\n    #endif\r\n    c == kDirDelimiter2);\r\n}\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2)\r\n{\r\n  if (g_CaseSensitive)\r\n    return s1.Compare(s2);\r\n  return s1.CompareNoCase(s2);\r\n}\r\n\r\n// -----------------------------------------\r\n// this function compares name with mask\r\n// ? - any char\r\n// * - any char or empty\r\n\r\nstatic bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)\r\n{\r\n  for (;;)\r\n  {\r\n    wchar_t m = *mask;\r\n    wchar_t c = *name;\r\n    if (m == 0)\r\n      return (c == 0);\r\n    if (m == kAnyCharsChar)\r\n    {\r\n      if (EnhancedMaskTest(mask + 1, name))\r\n        return true;\r\n      if (c == 0)\r\n        return false;\r\n    }\r\n    else\r\n    {\r\n      if (m == kAnyCharChar)\r\n      {\r\n        if (c == 0)\r\n          return false;\r\n      }\r\n      else if (m != c)\r\n        if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))\r\n          return false;\r\n      mask++;\r\n    }\r\n    name++;\r\n  }\r\n}\r\n\r\n// --------------------------------------------------\r\n// Splits path to strings\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts)\r\n{\r\n  pathParts.Clear();\r\n  UString name;\r\n  int len = path.Length();\r\n  if (len == 0)\r\n    return;\r\n  for (int i = 0; i < len; i++)\r\n  {\r\n    wchar_t c = path[i];\r\n    if (IsCharDirLimiter(c))\r\n    {\r\n      pathParts.Add(name);\r\n      name.Empty();\r\n    }\r\n    else\r\n      name += c;\r\n  }\r\n  pathParts.Add(name);\r\n}\r\n\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  dirPrefix = path.Left(i + 1);\r\n  name = path.Mid(i + 1);\r\n}\r\n\r\nUString ExtractDirPrefixFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Left(i + 1);\r\n}\r\n\r\nUString ExtractFileNameFromPath(const UString &path)\r\n{\r\n  int i;\r\n  for (i = path.Length() - 1; i >= 0; i--)\r\n    if (IsCharDirLimiter(path[i]))\r\n      break;\r\n  return path.Mid(i + 1);\r\n}\r\n\r\n\r\nbool CompareWildCardWithName(const UString &mask, const UString &name)\r\n{\r\n  return EnhancedMaskTest(mask, name);\r\n}\r\n\r\nbool DoesNameContainWildCard(const UString &path)\r\n{\r\n  return (path.FindOneOf(kWildCardCharSet) >= 0);\r\n}\r\n\r\n\r\n// ----------------------------------------------------------'\r\n// NWildcard\r\n\r\nnamespace NWildcard {\r\n\r\n\r\n/*\r\nM = MaskParts.Size();\r\nN = TestNameParts.Size();\r\n\r\n                           File                          Dir\r\nForFile     req   M<=N  [N-M, N)                          -\r\n         nonreq   M=N   [0, M)                            -\r\n \r\nForDir      req   M<N   [0, M) ... [N-M-1, N-1)  same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\nForBoth     req   m<=N  [0, M) ... [N-M, N)      same as ForBoth-File\r\n         nonreq         [0, M)                   same as ForBoth-File\r\n\r\n*/\r\n\r\nbool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (!isFile && !ForDir)\r\n    return false;\r\n  int delta = (int)pathParts.Size() - (int)PathParts.Size();\r\n  if (delta < 0)\r\n    return false;\r\n  int start = 0;\r\n  int finish = 0;\r\n  if (isFile)\r\n  {\r\n    if (!ForDir && !Recursive && delta !=0)\r\n      return false;\r\n    if (!ForFile && delta == 0)\r\n      return false;\r\n    if (!ForDir && Recursive)\r\n      start = delta;\r\n  }\r\n  if (Recursive)\r\n  {\r\n    finish = delta;\r\n    if (isFile && !ForFile)\r\n      finish = delta - 1;\r\n  }\r\n  for (int d = start; d <= finish; d++)\r\n  {\r\n    int i;\r\n    for (i = 0; i < PathParts.Size(); i++)\r\n      if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))\r\n        break;\r\n    if (i == PathParts.Size())\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nint CCensorNode::FindSubNode(const UString &name) const\r\n{\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (CompareFileNames(SubNodes[i].Name, name) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensorNode::AddItemSimple(bool include, CItem &item)\r\n{\r\n  if (include)\r\n    IncludeItems.Add(item);\r\n  else\r\n    ExcludeItems.Add(item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, CItem &item)\r\n{\r\n  if (item.PathParts.Size() <= 1)\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  const UString &front = item.PathParts.Front();\r\n  if (DoesNameContainWildCard(front))\r\n  {\r\n    AddItemSimple(include, item);\r\n    return;\r\n  }\r\n  int index = FindSubNode(front);\r\n  if (index < 0)\r\n    index = SubNodes.Add(CCensorNode(front, this));\r\n  item.PathParts.Delete(0);\r\n  SubNodes[index].AddItem(include, item);\r\n}\r\n\r\nvoid CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)\r\n{\r\n  CItem item;\r\n  SplitPathToParts(path, item.PathParts);\r\n  item.Recursive = recursive;\r\n  item.ForFile = forFile;\r\n  item.ForDir = forDir;\r\n  AddItem(include, item);\r\n}\r\n\r\nbool CCensorNode::NeedCheckSubDirs() const\r\n{\r\n  for (int i = 0; i < IncludeItems.Size(); i++)\r\n  {\r\n    const CItem &item = IncludeItems[i];\r\n    if (item.Recursive || item.PathParts.Size() > 1)\r\n      return true;\r\n  }\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::AreThereIncludeItems() const\r\n{\r\n  if (IncludeItems.Size() > 0)\r\n    return true;\r\n  for (int i = 0; i < SubNodes.Size(); i++)\r\n    if (SubNodes[i].AreThereIncludeItems())\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const\r\n{\r\n  const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;\r\n  for (int i = 0; i < items.Size(); i++)\r\n    if (items[i].CheckPath(pathParts, isFile))\r\n      return true;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const\r\n{\r\n  if (CheckPathCurrent(false, pathParts, isFile))\r\n  {\r\n    include = false;\r\n    return true;\r\n  }\r\n  include = true;\r\n  bool finded = CheckPathCurrent(true, pathParts, isFile);\r\n  if (pathParts.Size() == 1)\r\n    return finded;\r\n  int index = FindSubNode(pathParts.Front());\r\n  if (index >= 0)\r\n  {\r\n    UStringVector pathParts2 = pathParts;\r\n    pathParts2.Delete(0);\r\n    if (SubNodes[index].CheckPath(pathParts2, isFile, include))\r\n      return true;\r\n  }\r\n  return finded;\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPath(pathParts, isFile, include);\r\n}\r\n\r\nbool CCensorNode::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool include;\r\n  if (CheckPath(path, isFile, include))\r\n    return include;\r\n  return false;\r\n}\r\n\r\nbool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const\r\n{\r\n  if (CheckPathCurrent(include, pathParts, isFile))\r\n    return true;\r\n  if (Parent == 0)\r\n    return false;\r\n  pathParts.Insert(0, Name);\r\n  return Parent->CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n\r\n/*\r\nbool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  return CheckPathToRoot(include, pathParts, isFile);\r\n}\r\n*/\r\n\r\nvoid CCensorNode::AddItem2(bool include, const UString &path, bool recursive)\r\n{\r\n  if (path.IsEmpty())\r\n    return;\r\n  bool forFile = true;\r\n  bool forFolder = true;\r\n  UString path2 = path;\r\n  if (IsCharDirLimiter(path[path.Length() - 1]))\r\n  {\r\n    path2.Delete(path.Length() - 1);\r\n    forFile = false;\r\n  }\r\n  AddItem(include, path2, recursive, forFile, forFolder);\r\n}\r\n\r\nvoid CCensorNode::ExtendExclude(const CCensorNode &fromNodes)\r\n{\r\n  ExcludeItems += fromNodes.ExcludeItems;\r\n  for (int i = 0; i < fromNodes.SubNodes.Size(); i++)\r\n  {\r\n    const CCensorNode &node = fromNodes.SubNodes[i];\r\n    int subNodeIndex = FindSubNode(node.Name);\r\n    if (subNodeIndex < 0)\r\n      subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));\r\n    SubNodes[subNodeIndex].ExtendExclude(node);\r\n  }\r\n}\r\n\r\nint CCensor::FindPrefix(const UString &prefix) const\r\n{\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n    if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nvoid CCensor::AddItem(bool include, const UString &path, bool recursive)\r\n{\r\n  UStringVector pathParts;\r\n  SplitPathToParts(path, pathParts);\r\n  bool forFile = true;\r\n  if (pathParts.Back().IsEmpty())\r\n  {\r\n    forFile = false;\r\n    pathParts.DeleteBack();\r\n  }\r\n  const UString &front = pathParts.Front();\r\n  bool isAbs = false;\r\n  if (front.IsEmpty())\r\n    isAbs = true;\r\n  else if (front.Length() == 2 && front[1] == L':')\r\n    isAbs = true;\r\n  else\r\n  {\r\n    for (int i = 0; i < pathParts.Size(); i++)\r\n    {\r\n      const UString &part = pathParts[i];\r\n      if (part == L\"..\" || part == L\".\")\r\n      {\r\n        isAbs = true;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  int numAbsParts = 0;\r\n  if (isAbs)\r\n    if (pathParts.Size() > 1)\r\n      numAbsParts = pathParts.Size() - 1;\r\n    else\r\n      numAbsParts = 1;\r\n  UString prefix;\r\n  for (int i = 0; i < numAbsParts; i++)\r\n  {\r\n    const UString &front = pathParts.Front();\r\n    if (DoesNameContainWildCard(front))\r\n      break;\r\n    prefix += front;\r\n    prefix += WCHAR_PATH_SEPARATOR;\r\n    pathParts.Delete(0);\r\n  }\r\n  int index = FindPrefix(prefix);\r\n  if (index < 0)\r\n    index = Pairs.Add(CPair(prefix));\r\n\r\n  CItem item;\r\n  item.PathParts = pathParts;\r\n  item.ForDir = true;\r\n  item.ForFile = forFile;\r\n  item.Recursive = recursive;\r\n  Pairs[index].Head.AddItem(include, item);\r\n}\r\n\r\nbool CCensor::CheckPath(const UString &path, bool isFile) const\r\n{\r\n  bool finded = false;\r\n  for (int i = 0; i < Pairs.Size(); i++)\r\n  {\r\n    bool include;\r\n    if (Pairs[i].Head.CheckPath(path, isFile, include))\r\n    {\r\n      if (!include)\r\n        return false;\r\n      finded = true;\r\n    }\r\n  }\r\n  return finded;\r\n}\r\n\r\nvoid CCensor::ExtendExclude()\r\n{\r\n  int i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (Pairs[i].Prefix.IsEmpty())\r\n      break;\r\n  if (i == Pairs.Size())\r\n    return;\r\n  int index = i;\r\n  for (i = 0; i < Pairs.Size(); i++)\r\n    if (index != i)\r\n      Pairs[i].Head.ExtendExclude(Pairs[index].Head);\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Common/Wildcard.h",
    "content": "// Common/Wildcard.h\r\n\r\n#ifndef __COMMON_WILDCARD_H\r\n#define __COMMON_WILDCARD_H\r\n\r\n#include \"MyString.h\"\r\n\r\nint CompareFileNames(const UString &s1, const UString &s2);\r\n\r\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts);\r\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);\r\nUString ExtractDirPrefixFromPath(const UString &path);\r\nUString ExtractFileNameFromPath(const UString &path);\r\nbool DoesNameContainWildCard(const UString &path);\r\nbool CompareWildCardWithName(const UString &mask, const UString &name);\r\n\r\nnamespace NWildcard {\r\n\r\nstruct CItem\r\n{\r\n  UStringVector PathParts;\r\n  bool Recursive;\r\n  bool ForFile;\r\n  bool ForDir;\r\n  bool CheckPath(const UStringVector &pathParts, bool isFile) const;\r\n};\r\n\r\nclass CCensorNode\r\n{\r\n  CCensorNode *Parent;\r\n  bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;\r\n  void AddItemSimple(bool include, CItem &item);\r\n  bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;\r\npublic:\r\n  CCensorNode(): Parent(0) { };\r\n  CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };\r\n  UString Name;\r\n  CObjectVector<CCensorNode> SubNodes;\r\n  CObjectVector<CItem> IncludeItems;\r\n  CObjectVector<CItem> ExcludeItems;\r\n\r\n  int FindSubNode(const UString &path) const;\r\n\r\n  void AddItem(bool include, CItem &item);\r\n  void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);\r\n  void AddItem2(bool include, const UString &path, bool recursive);\r\n\r\n  bool NeedCheckSubDirs() const;\r\n  bool AreThereIncludeItems() const;\r\n\r\n  bool CheckPath(const UString &path, bool isFile, bool &include) const;\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n\r\n  bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;\r\n  // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;\r\n  void ExtendExclude(const CCensorNode &fromNodes);\r\n};\r\n\r\nstruct CPair\r\n{\r\n  UString Prefix;\r\n  CCensorNode Head;\r\n  CPair(const UString &prefix): Prefix(prefix) { };\r\n};\r\n\r\nclass CCensor\r\n{\r\n  int FindPrefix(const UString &prefix) const;\r\npublic:\r\n  CObjectVector<CPair> Pairs;\r\n  bool AllAreRelative() const\r\n    { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }\r\n  void AddItem(bool include, const UString &path, bool recursive);\r\n  bool CheckPath(const UString &path, bool isFile) const;\r\n  void ExtendExclude();\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/DLL.cpp",
    "content": "// Windows/DLL.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"DLL.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nCLibrary::~CLibrary()\r\n{\r\n  Free();\r\n}\r\n\r\nbool CLibrary::Free()\r\n{\r\n  if (_module == 0)\r\n    return true;\r\n  // MessageBox(0, TEXT(\"\"), TEXT(\"Free\"), 0);\r\n  // Sleep(5000);\r\n  if (!::FreeLibrary(_module))\r\n    return false;\r\n  _module = 0;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadOperations(HMODULE newModule)\r\n{\r\n  if (newModule == NULL)\r\n    return false;\r\n  if (!Free())\r\n    return false;\r\n  _module = newModule;\r\n  return true;\r\n}\r\n\r\nbool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"LoadEx\"), 0);\r\n  return LoadOperations(::LoadLibraryEx(fileName, NULL, flags));\r\n}\r\n\r\nbool CLibrary::Load(LPCTSTR fileName)\r\n{\r\n  // MessageBox(0, fileName, TEXT(\"Load\"), 0);\r\n  // Sleep(5000);\r\n  // OutputDebugString(fileName);\r\n  // OutputDebugString(TEXT(\"\\n\"));\r\n  return LoadOperations(::LoadLibrary(fileName));\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\nCSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n\r\nbool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));\r\n  return LoadEx(GetSysPath(fileName), flags);\r\n}\r\nbool CLibrary::Load(LPCWSTR fileName)\r\n{\r\n  if (g_IsNT)\r\n    return LoadOperations(::LoadLibraryW(fileName));\r\n  return Load(GetSysPath(fileName));\r\n}\r\n#endif\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result)\r\n{\r\n  result.Empty();\r\n  TCHAR fullPath[MAX_PATH + 2];\r\n  DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1);\r\n  if (size <= MAX_PATH && size != 0)\r\n  {\r\n    result = fullPath;\r\n    return true;\r\n  }\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result)\r\n{\r\n  result.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    wchar_t fullPath[MAX_PATH + 2];\r\n    DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);\r\n    if (size <= MAX_PATH && size != 0)\r\n    {\r\n      result = fullPath;\r\n      return true;\r\n    }\r\n    return false;\r\n  }\r\n  CSysString resultSys;\r\n  if (!MyGetModuleFileName(hModule, resultSys))\r\n    return false;\r\n  result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());\r\n  return true;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/DLL.h",
    "content": "// Windows/DLL.h\r\n\r\n#ifndef __WINDOWS_DLL_H\r\n#define __WINDOWS_DLL_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NDLL {\r\n\r\nclass CLibrary\r\n{\r\n  bool LoadOperations(HMODULE newModule);\r\nprotected:\r\n  HMODULE _module;\r\npublic:\r\n  operator HMODULE() const { return _module; }\r\n  HMODULE* operator&() { return &_module; }\r\n\r\n  CLibrary():_module(NULL) {};\r\n  ~CLibrary();\r\n  void Attach(HMODULE m)\r\n  {\r\n    Free();\r\n    _module = m;\r\n  }\r\n  HMODULE Detach()\r\n  {\r\n    HMODULE m = _module;\r\n    _module = NULL;\r\n    return m;\r\n  }\r\n\r\n  // operator HMODULE() const { return _module; };\r\n  bool IsLoaded() const { return (_module != NULL); };\r\n  bool Free();\r\n  bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\r\n  bool Load(LPCWSTR fileName);\r\n  #endif\r\n  FARPROC GetProcAddress(LPCSTR procName) const\r\n    { return ::GetProcAddress(_module, procName); }\r\n};\r\n\r\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result);\r\n#ifndef _UNICODE\r\nbool MyGetModuleFileName(HMODULE hModule, UString &result);\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\n#ifdef _WIN32\r\ninline bool LRESULTToBool(LRESULT value)\r\n  { return (value != FALSE); }\r\n#endif\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/Error.cpp",
    "content": "// Windows/Error.h\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/Error.h\"\r\n#ifndef _UNICODE\r\n#include \"Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message)\r\n{\r\n  LPVOID msgBuf;\r\n  if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r\n      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n      NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)\r\n    return false;\r\n  message = (LPCTSTR)msgBuf;\r\n  ::LocalFree(msgBuf);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyFormatMessage(DWORD messageID, UString &message)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPVOID msgBuf;\r\n    if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |\r\n        FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\r\n        NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)\r\n      return false;\r\n    message = (LPCWSTR)msgBuf;\r\n    ::LocalFree(msgBuf);\r\n    return true;\r\n  }\r\n  CSysString messageSys;\r\n  bool result = MyFormatMessage(messageID, messageSys);\r\n  message = GetUnicodeString(messageSys);\r\n  return result;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/Error.h",
    "content": "// Windows/Error.h\r\n\r\n#ifndef __WINDOWS_ERROR_H\r\n#define __WINDOWS_ERROR_H\r\n\r\n#include \"Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NError {\r\n\r\nbool MyFormatMessage(DWORD messageID, CSysString &message);\r\ninline CSysString MyFormatMessage(DWORD messageID)\r\n{\r\n  CSysString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#ifdef _UNICODE\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n  { return MyFormatMessage(messageID); }\r\n#else\r\nbool MyFormatMessage(DWORD messageID, UString &message);\r\ninline UString MyFormatMessageW(DWORD messageID)\r\n{\r\n  UString message;\r\n  MyFormatMessage(messageID, message);\r\n  return message;\r\n}\r\n#endif\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileDir.cpp",
    "content": "// Windows/FileDir.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileDir.h\"\r\n#include \"FileName.h\"\r\n#include \"FileFind.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n// SetCurrentDirectory doesn't support \\\\?\\ prefix\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR fileName, UString &res);\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n#endif\r\n\r\nnamespace NDirectory {\r\n\r\n#ifndef _UNICODE\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\nstatic UString GetUnicodePath(const CSysString &sysPath)\r\n  { return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }\r\nstatic CSysString GetSysPath(LPCWSTR sysPath)\r\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\nbool MyGetSystemDirectory(CSysString &path)\r\n{\r\n  UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetWindowsDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n\r\nbool MyGetSystemDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetSystemDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n{\r\n  #ifndef _UNICODE\r\n  if (!g_IsNT)\r\n  {\r\n    ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\r\n    return false;\r\n  }\r\n  #endif\r\n  HANDLE hDir = ::CreateFileW(fileName, GENERIC_WRITE,\r\n      FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n      NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (hDir == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      hDir = ::CreateFileW(longPath, GENERIC_WRITE,\r\n        FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\r\n  }\r\n  #endif\r\n\r\n  bool res = false;\r\n  if (hDir != INVALID_HANDLE_VALUE)\r\n  {\r\n    res = BOOLToBool(::SetFileTime(hDir, cTime, aTime, mTime));\r\n    ::CloseHandle(hDir);\r\n  }\r\n  return res;\r\n}\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (::SetFileAttributes(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyRemoveDirectory(LPCTSTR pathName)\r\n{\r\n  if (::RemoveDirectory(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2)\r\n{\r\n  if (!GetLongPathBase(s1, d1) || !GetLongPathBase(s2, d2))\r\n    return false;\r\n  if (d1.IsEmpty() && d2.IsEmpty()) return false;\r\n  if (d1.IsEmpty()) d1 = s1;\r\n  if (d2.IsEmpty()) d2 = s2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName)\r\n{\r\n  if (::MoveFile(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return MySetFileAttributes(GetSysPath(fileName), fileAttributes);\r\n  if (::SetFileAttributesW(fileName, fileAttributes))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(fileName, longPath))\r\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n\r\nbool MyRemoveDirectory(LPCWSTR pathName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyRemoveDirectory(GetSysPath(pathName));\r\n  if (::RemoveDirectoryW(pathName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(pathName, longPath))\r\n    return BOOLToBool(::RemoveDirectoryW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));\r\n  if (::MoveFileW(existFileName, newFileName))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString d1, d2;\r\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\r\n    return BOOLToBool(::MoveFileW(d1, d2));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nbool MyCreateDirectory(LPCTSTR pathName)\r\n{\r\n  if (::CreateDirectory(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyCreateDirectory(LPCWSTR pathName)\r\n{\r\n  if (!g_IsNT)\r\n    return MyCreateDirectory(GetSysPath(pathName));\r\n  if (::CreateDirectoryW(pathName, NULL))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\r\n  }\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\n/*\r\nbool CreateComplexDirectory(LPCTSTR pathName)\r\n{\r\n  NName::CParsedPath path;\r\n  path.ParsePath(pathName);\r\n  CSysString fullPath = path.Prefix;\r\n  DWORD errorCode = ERROR_SUCCESS;\r\n  for (int i = 0; i < path.PathParts.Size(); i++)\r\n  {\r\n    const CSysString &string = path.PathParts[i];\r\n    if (string.IsEmpty())\r\n    {\r\n      if (i != path.PathParts.Size() - 1)\r\n        return false;\r\n      return true;\r\n    }\r\n    fullPath += path.PathParts[i];\r\n    if (!MyCreateDirectory(fullPath))\r\n    {\r\n      DWORD errorCode = GetLastError();\r\n      if (errorCode != ERROR_ALREADY_EXISTS)\r\n        return false;\r\n    }\r\n    fullPath += NName::kDirDelimiter;\r\n  }\r\n  return true;\r\n}\r\n*/\r\n\r\nbool CreateComplexDirectory(LPCTSTR _aPathName)\r\n{\r\n  CSysString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == ':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  CSysString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if (MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfo fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDir())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == ':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while (pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateComplexDirectory(LPCWSTR _aPathName)\r\n{\r\n  UString pathName = _aPathName;\r\n  int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n  if (pos > 0 && pos == pathName.Length() - 1)\r\n  {\r\n    if (pathName.Length() == 3 && pathName[1] == L':')\r\n      return true; // Disk folder;\r\n    pathName.Delete(pos);\r\n  }\r\n  UString pathName2 = pathName;\r\n  pos = pathName.Length();\r\n  for (;;)\r\n  {\r\n    if (MyCreateDirectory(pathName))\r\n      break;\r\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\r\n    {\r\n      NFind::CFileInfoW fileInfo;\r\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\r\n        return true;\r\n      if (!fileInfo.IsDir())\r\n        return false;\r\n      break;\r\n    }\r\n    pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\r\n    if (pos < 0 || pos == 0)\r\n      return false;\r\n    if (pathName[pos - 1] == L':')\r\n      return false;\r\n    pathName = pathName.Left(pos);\r\n  }\r\n  pathName = pathName2;\r\n  while (pos < pathName.Length())\r\n  {\r\n    pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);\r\n    if (pos < 0)\r\n      pos = pathName.Length();\r\n    if (!MyCreateDirectory(pathName.Left(pos)))\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\n#endif\r\n\r\nbool DeleteFileAlways(LPCTSTR name)\r\n{\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFile(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH2\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DeleteFileAlways(LPCWSTR name)\r\n{\r\n  if (!g_IsNT)\r\n    return DeleteFileAlways(GetSysPath(name));\r\n  if (!MySetFileAttributes(name, 0))\r\n    return false;\r\n  if (::DeleteFileW(name))\r\n    return true;\r\n  #ifdef WIN_LONG_PATH\r\n  UString longPath;\r\n  if (GetLongPath(name, longPath))\r\n    return BOOLToBool(::DeleteFileW(longPath));\r\n  #endif\r\n  return false;\r\n}\r\n#endif\r\n\r\nstatic bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)\r\n{\r\n  if (fileInfo.IsDir())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\n\r\nbool RemoveDirectoryWithSubItems(const CSysString &path)\r\n{\r\n  NFind::CFileInfo fileInfo;\r\n  CSysString pathPrefix = path + NName::kDirDelimiter;\r\n  {\r\n    NFind::CEnumerator enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));\r\n    while (enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n\r\n#ifndef _UNICODE\r\nstatic bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)\r\n{\r\n  if (fileInfo.IsDir())\r\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\r\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\r\n}\r\nbool RemoveDirectoryWithSubItems(const UString &path)\r\n{\r\n  NFind::CFileInfoW fileInfo;\r\n  UString pathPrefix = path + UString(NName::kDirDelimiter);\r\n  {\r\n    NFind::CEnumeratorW enumerator(pathPrefix + UString(NName::kAnyStringWildcard));\r\n    while (enumerator.Next(fileInfo))\r\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\r\n        return false;\r\n  }\r\n  if (!MySetFileAttributes(path, 0))\r\n    return false;\r\n  return MyRemoveDirectory(path);\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\n\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)\r\n{\r\n  DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\r\n  shortPath.ReleaseBuffer();\r\n  return (needLength > 0 && needLength < MAX_PATH);\r\n}\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  LPTSTR fileNamePointer = 0;\r\n  LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n  DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n  resultPath.ReleaseBuffer();\r\n  if (needLength == 0)\r\n    return false;\r\n  if (needLength >= MAX_PATH)\r\n  {\r\n    #ifdef WIN_LONG_PATH2\r\n    needLength++;\r\n    buffer = resultPath.GetBuffer(needLength + 1);\r\n    DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength2 == 0 || needLength2 > needLength)\r\n    #endif\r\n      return false;\r\n  }\r\n  if (fileNamePointer == 0)\r\n    fileNamePartStartIndex = lstrlen(fileName);\r\n  else\r\n    fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)\r\n{\r\n  resultPath.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR fileNamePointer = 0;\r\n    LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);\r\n    DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\r\n    resultPath.ReleaseBuffer();\r\n    if (needLength == 0)\r\n      return false;\r\n    if (needLength >= MAX_PATH)\r\n    {\r\n      #ifdef WIN_LONG_PATH\r\n      needLength++;\r\n      buffer = resultPath.GetBuffer(needLength + 1);\r\n      DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\r\n      resultPath.ReleaseBuffer();\r\n      if (needLength2 == 0 || needLength2 > needLength)\r\n      #endif\r\n        return false;\r\n    }\r\n    if (fileNamePointer == 0)\r\n      fileNamePartStartIndex = MyStringLen(fileName);\r\n    else\r\n      fileNamePartStartIndex = (int)(fileNamePointer - buffer);\r\n  }\r\n  else\r\n  {\r\n    CSysString sysPath;\r\n    if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))\r\n      return false;\r\n    UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));\r\n    UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));\r\n    fileNamePartStartIndex = resultPath1.Length();\r\n    resultPath = resultPath1 + resultPath2;\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &path)\r\n{\r\n  int index;\r\n  return MyGetFullPathName(fileName, path, index);\r\n}\r\n#endif\r\n\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Mid(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)\r\n{\r\n  int index;\r\n  if (!MyGetFullPathName(fileName, resultName, index))\r\n    return false;\r\n  resultName = resultName.Left(index);\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetCurrentDirectory(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path)\r\n{\r\n  if (g_IsNT)\r\n    return BOOLToBool(::SetCurrentDirectoryW(path));\r\n  return MySetCurrentDirectory(GetSysPath(path));\r\n}\r\nbool MyGetCurrentDirectory(UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetCurrentDirectory(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath, UINT32 &filePart)\r\n{\r\n  LPTSTR filePartPointer;\r\n  DWORD value = ::SearchPath(path, fileName, extension,\r\n    MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n  filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);\r\n  resultPath.ReleaseBuffer();\r\n  return (value > 0 && value <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath, UINT32 &filePart)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    LPWSTR filePartPointer = 0;\r\n    DWORD value = ::SearchPathW(path, fileName, extension,\r\n        MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\r\n    filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);\r\n    resultPath.ReleaseBuffer();\r\n    return (value > 0 && value <= MAX_PATH);\r\n  }\r\n  \r\n  CSysString sysPath;\r\n  if (!MySearchPath(\r\n      path != 0 ? (LPCTSTR)GetSysPath(path): 0,\r\n      fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,\r\n      extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,\r\n      sysPath, filePart))\r\n    return false;\r\n  UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));\r\n  UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));\r\n  filePart = resultPath1.Length();\r\n  resultPath = resultPath1 + resultPath2;\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &path)\r\n{\r\n  DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return (needLength > 0 && needLength <= MAX_PATH);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &path)\r\n{\r\n  path.Empty();\r\n  if (g_IsNT)\r\n  {\r\n    DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\r\n    path.ReleaseBuffer();\r\n    return (needLength > 0 && needLength <= MAX_PATH);\r\n  }\r\n  CSysString sysPath;\r\n  if (!MyGetTempPath(sysPath))\r\n    return false;\r\n  path = GetUnicodePath(sysPath);\r\n  return true;\r\n}\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)\r\n{\r\n  UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));\r\n  path.ReleaseBuffer();\r\n  return number;\r\n}\r\n\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));\r\n    path.ReleaseBuffer();\r\n    return number;\r\n  }\r\n  CSysString sysPath;\r\n  UINT number = MyGetTempFileName(\r\n      dirPath ? (LPCTSTR)GetSysPath(dirPath): 0,\r\n      prefix ? (LPCTSTR)GetSysPath(prefix): 0,\r\n      sysPath);\r\n  path = GetUnicodePath(sysPath);\r\n  return number;\r\n}\r\n#endif\r\n\r\nUINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if (number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)\r\n{\r\n  CSysString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFile::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nUINT CTempFileW::Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath)\r\n{\r\n  Remove();\r\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\r\n  if (number != 0)\r\n  {\r\n    _fileName = resultPath;\r\n    _mustBeDeleted = true;\r\n  }\r\n  return number;\r\n}\r\n\r\nbool CTempFileW::Create(LPCWSTR prefix, UString &resultPath)\r\n{\r\n  UString tempPath;\r\n  if (!MyGetTempPath(tempPath))\r\n    return false;\r\n  if (Create(tempPath, prefix, resultPath) != 0)\r\n    return true;\r\n  if (!MyGetWindowsDirectory(tempPath))\r\n    return false;\r\n  return (Create(tempPath, prefix, resultPath) != 0);\r\n}\r\n\r\nbool CTempFileW::Remove()\r\n{\r\n  if (!_mustBeDeleted)\r\n    return true;\r\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\r\n  return !_mustBeDeleted;\r\n}\r\n\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFile tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!::DeleteFile(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if (NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectory::Create(LPCTSTR prefix)\r\n{\r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nbool CreateTempDirectory(LPCWSTR prefix, UString &dirName)\r\n{\r\n  /*\r\n  CSysString prefix = tempPath + prefixChars;\r\n  CRandom random;\r\n  random.Init();\r\n  */\r\n  for (;;)\r\n  {\r\n    CTempFileW tempFile;\r\n    if (!tempFile.Create(prefix, dirName))\r\n      return false;\r\n    if (!DeleteFileAlways(dirName))\r\n      return false;\r\n    /*\r\n    UINT32 randomNumber = random.Generate();\r\n    TCHAR randomNumberString[32];\r\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\r\n    dirName = prefix + randomNumberString;\r\n    */\r\n    if (NFind::DoesFileExist(dirName))\r\n      continue;\r\n    if (MyCreateDirectory(dirName))\r\n      return true;\r\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\r\n      return false;\r\n  }\r\n}\r\n\r\nbool CTempDirectoryW::Create(LPCWSTR prefix)\r\n{\r\n  Remove();\r\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\r\n}\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileDir.h",
    "content": "// Windows/FileDir.h\r\n\r\n#ifndef __WINDOWS_FILEDIR_H\r\n#define __WINDOWS_FILEDIR_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NDirectory {\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);\r\n#endif\r\n\r\nbool MyGetWindowsDirectory(CSysString &path);\r\nbool MyGetSystemDirectory(CSysString &path);\r\n#ifndef _UNICODE\r\nbool MyGetWindowsDirectory(UString &path);\r\nbool MyGetSystemDirectory(UString &path);\r\n#endif\r\n\r\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\r\n\r\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);\r\nbool MyRemoveDirectory(LPCTSTR pathName);\r\nbool MyCreateDirectory(LPCTSTR pathName);\r\nbool CreateComplexDirectory(LPCTSTR pathName);\r\nbool DeleteFileAlways(LPCTSTR name);\r\nbool RemoveDirectoryWithSubItems(const CSysString &path);\r\n\r\n#ifndef _UNICODE\r\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);\r\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);\r\nbool MyRemoveDirectory(LPCWSTR pathName);\r\nbool MyCreateDirectory(LPCWSTR pathName);\r\nbool CreateComplexDirectory(LPCWSTR pathName);\r\nbool DeleteFileAlways(LPCWSTR name);\r\nbool RemoveDirectoryWithSubItems(const UString &path);\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);\r\n\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,\r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);\r\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName);\r\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);\r\n#ifndef _UNICODE\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,\r\n    int &fileNamePartStartIndex);\r\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);\r\nbool GetOnlyName(LPCWSTR fileName, UString &resultName);\r\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);\r\n#endif\r\n\r\ninline bool MySetCurrentDirectory(LPCTSTR path)\r\n  { return BOOLToBool(::SetCurrentDirectory(path)); }\r\nbool MyGetCurrentDirectory(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MySetCurrentDirectory(LPCWSTR path);\r\nbool MyGetCurrentDirectory(UString &resultPath);\r\n#endif\r\n#endif\r\n\r\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath, UINT32 &filePart);\r\n#ifndef _UNICODE\r\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath, UINT32 &filePart);\r\n#endif\r\n\r\ninline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\r\n  CSysString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n\r\n#ifndef _UNICODE\r\ninline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\r\n  UString &resultPath)\r\n{\r\n  UINT32 value;\r\n  return MySearchPath(path, fileName, extension, resultPath, value);\r\n}\r\n#endif\r\n\r\nbool MyGetTempPath(CSysString &resultPath);\r\n#ifndef _UNICODE\r\nbool MyGetTempPath(UString &resultPath);\r\n#endif\r\n\r\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n#ifndef _UNICODE\r\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n#endif\r\n\r\nclass CTempFile\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _fileName;\r\npublic:\r\n  CTempFile(): _mustBeDeleted(false) {}\r\n  ~CTempFile() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\r\n  bool Create(LPCTSTR prefix, CSysString &resultPath);\r\n  bool Remove();\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempFile CTempFileW;\r\n#else\r\nclass CTempFileW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _fileName;\r\npublic:\r\n  CTempFileW(): _mustBeDeleted(false) {}\r\n  ~CTempFileW() { Remove(); }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n  UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\r\n  bool Create(LPCWSTR prefix, UString &resultPath);\r\n  bool Remove();\r\n};\r\n#endif\r\n\r\nbool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);\r\n\r\nclass CTempDirectory\r\n{\r\n  bool _mustBeDeleted;\r\n  CSysString _tempDir;\r\npublic:\r\n  const CSysString &GetPath() const { return _tempDir; }\r\n  CTempDirectory(): _mustBeDeleted(false) {}\r\n  ~CTempDirectory() { Remove();  }\r\n  bool Create(LPCTSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CTempDirectory CTempDirectoryW;\r\n#else\r\nclass CTempDirectoryW\r\n{\r\n  bool _mustBeDeleted;\r\n  UString _tempDir;\r\npublic:\r\n  const UString &GetPath() const { return _tempDir; }\r\n  CTempDirectoryW(): _mustBeDeleted(false) {}\r\n  ~CTempDirectoryW() { Remove();  }\r\n  bool Create(LPCWSTR prefix) ;\r\n  bool Remove()\r\n  {\r\n    if (!_mustBeDeleted)\r\n      return true;\r\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\r\n    return (!_mustBeDeleted);\r\n  }\r\n  void DisableDeleting() { _mustBeDeleted = false; }\r\n};\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileFind.cpp",
    "content": "// Windows/FileFind.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileFind.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\nbool GetLongPath(LPCWSTR fileName, UString &res);\r\n\r\nnamespace NFind {\r\n\r\nstatic const TCHAR kDot = TEXT('.');\r\n\r\nbool CFileInfo::IsDots() const\r\n{\r\n  if (!IsDir() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileInfoW::IsDots() const\r\n{\r\n  if (!IsDir() || Name.IsEmpty())\r\n    return false;\r\n  if (Name[0] != kDot)\r\n    return false;\r\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\r\n}\r\n#endif\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = fd.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n\r\n#ifndef _UNICODE\r\n\r\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfoW &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = fd.cFileName;\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n\r\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi)\r\n{\r\n  fi.Attrib = fd.dwFileAttributes;\r\n  fi.CTime = fd.ftCreationTime;\r\n  fi.ATime = fd.ftLastAccessTime;\r\n  fi.MTime = fd.ftLastWriteTime;\r\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\r\n  fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage());\r\n  #ifndef _WIN32_WCE\r\n  fi.ReparseTag = fd.dwReserved0;\r\n  #else\r\n  fi.ObjectID = fd.dwOID;\r\n  #endif\r\n}\r\n#endif\r\n  \r\n////////////////////////////////\r\n// CFindFile\r\n\r\nbool CFindFile::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::FindClose(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\n          \r\nbool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  WIN32_FIND_DATA fd;\r\n  _handle = ::FindFirstFile(wildcard, &fd);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(wildcard, longPath))\r\n      _handle = ::FindFirstFileW(longPath, &fd);\r\n  }\r\n  #endif\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return false;\r\n  ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW fd;\r\n    _handle = ::FindFirstFileW(wildcard, &fd);\r\n    #ifdef WIN_LONG_PATH\r\n    if (_handle == INVALID_HANDLE_VALUE)\r\n    {\r\n      UString longPath;\r\n      if (GetLongPath(wildcard, longPath))\r\n        _handle = ::FindFirstFileW(longPath, &fd);\r\n    }\r\n    #endif\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA fd;\r\n    _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard,\r\n        GetCurrentCodePage()), &fd);\r\n    if (_handle != INVALID_HANDLE_VALUE)\r\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFindFile::FindNext(CFileInfo &fileInfo)\r\n{\r\n  WIN32_FIND_DATA fd;\r\n  bool result = BOOLToBool(::FindNextFile(_handle, &fd));\r\n  if (result)\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  return result;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFindFile::FindNext(CFileInfoW &fileInfo)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    WIN32_FIND_DATAW fd;\r\n    if (!::FindNextFileW(_handle, &fd))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  else\r\n  {\r\n    WIN32_FIND_DATAA fd;\r\n    if (!::FindNextFileA(_handle, &fd))\r\n      return false;\r\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\r\n  }\r\n  return true;\r\n}\r\n#endif\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)\r\n{\r\n  CFindFile finder;\r\n  return finder.FindFirst(wildcard, fileInfo);\r\n}\r\n#endif\r\n\r\nbool DoesFileExist(LPCTSTR name)\r\n{\r\n  CFileInfo fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool DoesFileExist(LPCWSTR name)\r\n{\r\n  CFileInfoW fileInfo;\r\n  return FindFile(name, fileInfo);\r\n}\r\n#endif\r\n\r\n/////////////////////////////////////\r\n// CEnumerator\r\n\r\nbool CEnumerator::NextAny(CFileInfo &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumerator::Next(CFileInfo &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CEnumeratorW::NextAny(CFileInfoW &fileInfo)\r\n{\r\n  if (_findFile.IsHandleAllocated())\r\n    return _findFile.FindNext(fileInfo);\r\n  else\r\n    return _findFile.FindFirst(_wildcard, fileInfo);\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo)\r\n{\r\n  for (;;)\r\n  {\r\n    if (!NextAny(fileInfo))\r\n      return false;\r\n    if (!fileInfo.IsDots())\r\n      return true;\r\n  }\r\n}\r\n\r\nbool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)\r\n{\r\n  if (Next(fileInfo))\r\n  {\r\n    found = true;\r\n    return true;\r\n  }\r\n  found = false;\r\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\r\n}\r\n\r\n#endif\r\n\r\n////////////////////////////////\r\n// CFindChangeNotification\r\n// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.\r\n\r\nbool CFindChangeNotification::Close()\r\n{\r\n  if (!IsHandleAllocated())\r\n    return true;\r\n  if (!::FindCloseChangeNotification(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n           \r\nHANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  _handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n\r\n#ifndef _UNICODE\r\nHANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)\r\n{\r\n  if (!g_IsNT)\r\n    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);\r\n  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);\r\n  #ifdef WIN_LONG_PATH\r\n  if (!IsHandleAllocated())\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(pathName, longPath))\r\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\r\n  }\r\n  #endif\r\n  return _handle;\r\n}\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  UINT32 size = GetLogicalDriveStrings(0, NULL);\r\n  if (size == 0)\r\n    return false;\r\n  CSysString buffer;\r\n  UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size));\r\n  if (newSize == 0)\r\n    return false;\r\n  if (newSize > size)\r\n    return false;\r\n  CSysString string;\r\n  for (UINT32 i = 0; i < newSize; i++)\r\n  {\r\n    TCHAR c = buffer[i];\r\n    if (c == TEXT('\\0'))\r\n    {\r\n      driveStrings.Add(string);\r\n      string.Empty();\r\n    }\r\n    else\r\n      string += c;\r\n  }\r\n  if (!string.IsEmpty())\r\n    return false;\r\n  return true;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings)\r\n{\r\n  driveStrings.Clear();\r\n  if (g_IsNT)\r\n  {\r\n    UINT32 size = GetLogicalDriveStringsW(0, NULL);\r\n    if (size == 0)\r\n      return false;\r\n    UString buffer;\r\n    UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size));\r\n    if (newSize == 0)\r\n      return false;\r\n    if (newSize > size)\r\n      return false;\r\n    UString string;\r\n    for (UINT32 i = 0; i < newSize; i++)\r\n    {\r\n      WCHAR c = buffer[i];\r\n      if (c == L'\\0')\r\n      {\r\n        driveStrings.Add(string);\r\n        string.Empty();\r\n      }\r\n      else\r\n        string += c;\r\n    }\r\n    return string.IsEmpty();\r\n  }\r\n  CSysStringVector driveStringsA;\r\n  bool res = MyGetLogicalDriveStrings(driveStringsA);\r\n  for (int i = 0; i < driveStringsA.Size(); i++)\r\n    driveStrings.Add(GetUnicodeString(driveStringsA[i]));\r\n  return res;\r\n}\r\n#endif\r\n\r\n#endif\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileFind.h",
    "content": "// Windows/FileFind.h\r\n\r\n#ifndef __WINDOWS_FILEFIND_H\r\n#define __WINDOWS_FILEFIND_H\r\n\r\n#include \"../Common/MyString.h\"\r\n#include \"../Common/Types.h\"\r\n#include \"FileName.h\"\r\n#include \"Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NFind {\r\n\r\nnamespace NAttributes\r\n{\r\n  inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }\r\n  inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; }\r\n  inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; }\r\n  inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; }\r\n  inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }\r\n  inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }\r\n  inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }\r\n}\r\n\r\nclass CFileInfoBase\r\n{\r\n  bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }\r\npublic:\r\n  UInt64 Size;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  DWORD Attrib;\r\n  \r\n  #ifndef _WIN32_WCE\r\n  UINT32 ReparseTag;\r\n  #else\r\n  DWORD ObjectID;\r\n  #endif\r\n\r\n  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }\r\n  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }\r\n  bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }\r\n  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }\r\n  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }\r\n  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }\r\n  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }\r\n  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }\r\n  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }\r\n  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }\r\n  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }\r\n  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }\r\n};\r\n\r\nclass CFileInfo: public CFileInfoBase\r\n{\r\npublic:\r\n  CSysString Name;\r\n  bool IsDots() const;\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CFileInfo CFileInfoW;\r\n#else\r\nclass CFileInfoW: public CFileInfoBase\r\n{\r\npublic:\r\n  UString Name;\r\n  bool IsDots() const;\r\n};\r\n#endif\r\n\r\nclass CFindFile\r\n{\r\n  friend class CEnumerator;\r\n  HANDLE _handle;\r\npublic:\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }\r\n  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindFile() {  Close(); }\r\n  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n  bool FindNext(CFileInfo &fileInfo);\r\n  #ifndef _UNICODE\r\n  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\n  bool FindNext(CFileInfoW &fileInfo);\r\n  #endif\r\n  bool Close();\r\n};\r\n\r\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);\r\n\r\nbool DoesFileExist(LPCTSTR name);\r\n#ifndef _UNICODE\r\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);\r\nbool DoesFileExist(LPCWSTR name);\r\n#endif\r\n\r\nclass CEnumerator\r\n{\r\n  CFindFile _findFile;\r\n  CSysString _wildcard;\r\n  bool NextAny(CFileInfo &fileInfo);\r\npublic:\r\n  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfo &fileInfo);\r\n  bool Next(CFileInfo &fileInfo, bool &found);\r\n};\r\n\r\n#ifdef _UNICODE\r\ntypedef CEnumerator CEnumeratorW;\r\n#else\r\nclass CEnumeratorW\r\n{\r\n  CFindFile _findFile;\r\n  UString _wildcard;\r\n  bool NextAny(CFileInfoW &fileInfo);\r\npublic:\r\n  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}\r\n  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}\r\n  bool Next(CFileInfoW &fileInfo);\r\n  bool Next(CFileInfoW &fileInfo, bool &found);\r\n};\r\n#endif\r\n\r\nclass CFindChangeNotification\r\n{\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE () { return _handle; }\r\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }\r\n  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}\r\n  ~CFindChangeNotification() { Close(); }\r\n  bool Close();\r\n  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #ifndef _UNICODE\r\n  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);\r\n  #endif\r\n  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);\r\n#ifndef _UNICODE\r\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings);\r\n#endif\r\n#endif\r\n\r\n}}}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifdef WIN_LONG_PATH\r\n#include \"../Common/MyString.h\"\r\n#endif\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\n\r\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\r\n#define WIN_LONG_PATH2\r\n#endif\r\n\r\n#ifdef WIN_LONG_PATH\r\nbool GetLongPathBase(LPCWSTR s, UString &res)\r\n{\r\n  res.Empty();\r\n  int len = MyStringLen(s);\r\n  wchar_t c = s[0];\r\n  if (len < 1 || c == L'\\\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))\r\n    return true;\r\n  UString curDir;\r\n  bool isAbs = false;\r\n  if (len > 3)\r\n    isAbs = (s[1] == L':' && s[2] == L'\\\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));\r\n\r\n  if (!isAbs)\r\n    {\r\n      DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));\r\n      curDir.ReleaseBuffer();\r\n      if (needLength == 0 || needLength > MAX_PATH)\r\n        return false;\r\n      if (curDir[curDir.Length() - 1] != L'\\\\')\r\n        curDir += L'\\\\';\r\n    }\r\n  res = UString(L\"\\\\\\\\?\\\\\") + curDir + s;\r\n  return true;\r\n}\r\n\r\nbool GetLongPath(LPCWSTR path, UString &longPath)\r\n{\r\n  if (GetLongPathBase(path, longPath))\r\n    return !longPath.IsEmpty();\r\n  return false;\r\n}\r\n#endif\r\n\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode,\r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n      flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH2\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (!g_IsNT)\r\n    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP),\r\n      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n  if (!Close())\r\n    return false;\r\n  _handle = ::CreateFileW(fileName, desiredAccess, shareMode,\r\n    (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n    flagsAndAttributes, (HANDLE)NULL);\r\n  #ifdef WIN_LONG_PATH\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n  {\r\n    UString longPath;\r\n    if (GetLongPath(fileName, longPath))\r\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\r\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\r\n        flagsAndAttributes, (HANDLE)NULL);\r\n  }\r\n  #endif\r\n  return (_handle != INVALID_HANDLE_VALUE);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if (_handle == INVALID_HANDLE_VALUE)\r\n    return true;\r\n  if (!::CloseHandle(_handle))\r\n    return false;\r\n  _handle = INVALID_HANDLE_VALUE;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if (sizeLow == 0xFFFFFFFF)\r\n    if (::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if (::GetLastError() != NO_ERROR)\r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if (!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CTime = winFileInfo.ftCreationTime;\r\n  fileInfo.ATime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.MTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes;\r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)\r\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return OpenShared(fileName, false); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\n// Probably in some version of Windows there are problems with other sizes:\r\n// for 32 MB (maybe also for 16 MB).\r\n// And message can be \"Network connection was lost\"\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 22);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, cTime, aTime, mTime)); }\r\n\r\nbool COutFile::SetMTime(const FILETIME *mTime) {  return SetTime(NULL, NULL, mTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if (!Seek(length, newPosition))\r\n    return false;\r\n  if (newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{\r\n  DWORD    Attributes;\r\n  FILETIME CTime;\r\n  FILETIME ATime;\r\n  FILETIME MTime;\r\n  DWORD    VolumeSerialNumber;\r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks;\r\n  UInt64   FileIndex;\r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _handle(INVALID_HANDLE_VALUE){};\r\n  ~CFileBase();\r\n\r\n  bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition);\r\n  bool SeekToBegin();\r\n  bool SeekToEnd(UInt64 &newPosition);\r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\r\n  bool SetMTime(const FILETIME *mTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileMapping.cpp",
    "content": "// Windows/FileMapping.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileMapping.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NMapping {\r\n\r\n\r\n\r\n\r\n}}}"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileMapping.h",
    "content": "// Windows/FileMapping.h\r\n\r\n#ifndef __WINDOWS_FILEMAPPING_H\r\n#define __WINDOWS_FILEMAPPING_H\r\n\r\n#include \"Windows/Handle.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\n// namespace NFile {\r\n// namespace NMapping {\r\n\r\nclass CFileMapping: public CHandle\r\n{\r\npublic:\r\n  bool Create(HANDLE file, LPSECURITY_ATTRIBUTES attributes,\r\n    DWORD protect, UINT64 maximumSize, LPCTSTR name)\r\n  {\r\n    _handle = ::CreateFileMapping(file, attributes,\r\n      protect, DWORD(maximumSize >> 32), DWORD(maximumSize), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenFileMapping(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    return (_handle != NULL);\r\n  }\r\n\r\n  LPVOID MapViewOfFile(DWORD desiredAccess, UINT64 fileOffset,\r\n      SIZE_T numberOfBytesToMap)\r\n  {\r\n    return ::MapViewOfFile(_handle, desiredAccess,\r\n        DWORD(fileOffset >> 32), DWORD(fileOffset), numberOfBytesToMap);\r\n  }\r\n\r\n  LPVOID MapViewOfFileEx(DWORD desiredAccess, UINT64 fileOffset,\r\n      SIZE_T numberOfBytesToMap, LPVOID baseAddress)\r\n  {\r\n    return ::MapViewOfFileEx(_handle, desiredAccess,\r\n      DWORD(fileOffset >> 32), DWORD(fileOffset),\r\n      numberOfBytesToMap, baseAddress);\r\n  }\r\n  \r\n\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileName.cpp",
    "content": "// Windows/FileName.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Windows/FileName.h\"\r\n#include \"Common/Wildcard.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)\r\n    dirPath += kDirDelimiter;\r\n}\r\n\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath)\r\n{\r\n  if (dirPath.IsEmpty())\r\n    return;\r\n  if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)\r\n    dirPath += wchar_t(kDirDelimiter);\r\n}\r\n#endif\r\n\r\nconst wchar_t kExtensionDelimiter = L'.';\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\r\n    UString &pureName, UString &extensionDelimiter, UString &extension)\r\n{\r\n  int index = fullName.ReverseFind(kExtensionDelimiter);\r\n  if (index < 0)\r\n  {\r\n    pureName = fullName;\r\n    extensionDelimiter.Empty();\r\n    extension.Empty();\r\n  }\r\n  else\r\n  {\r\n    pureName = fullName.Left(index);\r\n    extensionDelimiter = kExtensionDelimiter;\r\n    extension = fullName.Mid(index + 1);\r\n  }\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/FileName.h",
    "content": "// Windows/FileName.h\r\n\r\n#ifndef __WINDOWS_FILENAME_H\r\n#define __WINDOWS_FILENAME_H\r\n\r\n#include \"../Common/MyString.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NName {\r\n\r\nconst TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;\r\nconst TCHAR kAnyStringWildcard = '*';\r\n\r\nvoid NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\\\'\r\n#ifndef _UNICODE\r\nvoid NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\\\'\r\n#endif\r\n\r\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\r\n    UString &pureName, UString &extensionDelimiter, UString &extension);\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/Handle.h",
    "content": "// Windows/Handle.h\r\n\r\n#ifndef __WINDOWS_HANDLE_H\r\n#define __WINDOWS_HANDLE_H\r\n\r\nnamespace NWindows {\r\n\r\nclass CHandle\r\n{\r\nprotected:\r\n  HANDLE _handle;\r\npublic:\r\n  operator HANDLE() { return _handle; }\r\n  CHandle(): _handle(NULL) {}\r\n  ~CHandle() { Close(); }\r\n  bool Close()\r\n  {\r\n    if (_handle == NULL)\r\n      return true;\r\n    if (!::CloseHandle(_handle))\r\n      return false;\r\n    _handle = NULL;\r\n    return true;\r\n  }\r\n  void Attach(HANDLE handle)\r\n    { _handle = handle; }\r\n  HANDLE Detach()\r\n  {\r\n    HANDLE handle = _handle;\r\n    _handle = NULL;\r\n    return handle;\r\n  }\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/MemoryLock.cpp",
    "content": "// Common/MemoryLock.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\n#ifndef _UNICODE\r\ntypedef BOOL (WINAPI * OpenProcessTokenP)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);\r\ntypedef BOOL (WINAPI * LookupPrivilegeValueP)(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID  lpLuid);\r\ntypedef BOOL (WINAPI * AdjustTokenPrivilegesP)(HANDLE TokenHandle, BOOL DisableAllPrivileges,\r\n    PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength);\r\n#endif\r\n\r\n#ifdef _UNICODE\r\nbool EnableLockMemoryPrivilege(\r\n#else\r\nstatic bool EnableLockMemoryPrivilege2(HMODULE hModule,\r\n#endif\r\nbool enable)\r\n{\r\n  #ifndef _UNICODE\r\n  if (hModule == NULL)\r\n    return false;\r\n  OpenProcessTokenP openProcessToken = (OpenProcessTokenP)GetProcAddress(hModule, \"OpenProcessToken\");\r\n  LookupPrivilegeValueP lookupPrivilegeValue = (LookupPrivilegeValueP)GetProcAddress(hModule, \"LookupPrivilegeValueA\" );\r\n  AdjustTokenPrivilegesP adjustTokenPrivileges = (AdjustTokenPrivilegesP)GetProcAddress(hModule, \"AdjustTokenPrivileges\");\r\n  if (openProcessToken == NULL || adjustTokenPrivileges == NULL || lookupPrivilegeValue == NULL)\r\n    return false;\r\n  #endif\r\n\r\n  HANDLE token;\r\n  if (!\r\n    #ifdef _UNICODE\r\n    ::OpenProcessToken\r\n    #else\r\n    openProcessToken\r\n    #endif\r\n    (::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))\r\n    return false;\r\n  TOKEN_PRIVILEGES tp;\r\n  bool res = false;\r\n  if (\r\n    #ifdef _UNICODE\r\n    ::LookupPrivilegeValue\r\n    #else\r\n    lookupPrivilegeValue\r\n    #endif\r\n    (NULL, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)))\r\n  {\r\n    tp.PrivilegeCount = 1;\r\n    tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED: 0;\r\n    if (\r\n      #ifdef _UNICODE\r\n      ::AdjustTokenPrivileges\r\n      #else\r\n      adjustTokenPrivileges\r\n      #endif\r\n      (token, FALSE, &tp, 0, NULL, NULL))\r\n      res = (GetLastError() == ERROR_SUCCESS);\r\n  }\r\n  ::CloseHandle(token);\r\n  return res;\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool EnableLockMemoryPrivilege(bool enable)\r\n{\r\n  HMODULE hModule = LoadLibrary(TEXT(\"Advapi32.dll\"));\r\n  if (hModule == NULL)\r\n    return false;\r\n  bool res = EnableLockMemoryPrivilege2(hModule, enable);\r\n  ::FreeLibrary(hModule);\r\n  return res;\r\n}\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/MemoryLock.h",
    "content": "// Windows/MemoryLock.h\r\n\r\n#ifndef __WINDOWS_MEMORYLOCK_H\r\n#define __WINDOWS_MEMORYLOCK_H\r\n\r\nnamespace NWindows {\r\nnamespace NSecurity {\r\n\r\nbool EnableLockMemoryPrivilege(bool enable = true);\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/PropVariant.cpp",
    "content": "// Windows/PropVariant.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariant.h\"\r\n\r\n#include \"../Common/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nCPropVariant::CPropVariant(const PROPVARIANT& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(const CPropVariant& varSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  InternalCopy(&varSrc);\r\n}\r\n\r\nCPropVariant::CPropVariant(BSTR bstrSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = bstrSrc;\r\n}\r\n\r\nCPropVariant::CPropVariant(LPCOLESTR lpszSrc)\r\n{\r\n  vt = VT_EMPTY;\r\n  *this = lpszSrc;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const CPropVariant& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\nCPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc)\r\n{\r\n  InternalCopy(&varSrc);\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(BSTR bstrSrc)\r\n{\r\n  *this = (LPCOLESTR)bstrSrc;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)\r\n{\r\n  InternalClear();\r\n  vt = VT_BSTR;\r\n  wReserved1 = 0;\r\n  bstrVal = ::SysAllocString(lpszSrc);\r\n  if (bstrVal == NULL && lpszSrc != NULL)\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = E_OUTOFMEMORY;\r\n  }\r\n  return *this;\r\n}\r\n\r\n\r\nCPropVariant& CPropVariant::operator=(bool bSrc)\r\n{\r\n  if (vt != VT_BOOL)\r\n  {\r\n    InternalClear();\r\n    vt = VT_BOOL;\r\n  }\r\n  boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt32 value)\r\n{\r\n  if (vt != VT_UI4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI4;\r\n  }\r\n  ulVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(UInt64 value)\r\n{\r\n  if (vt != VT_UI8)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI8;\r\n  }\r\n  uhVal.QuadPart = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(const FILETIME &value)\r\n{\r\n  if (vt != VT_FILETIME)\r\n  {\r\n    InternalClear();\r\n    vt = VT_FILETIME;\r\n  }\r\n  filetime = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int32 value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  \r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Byte value)\r\n{\r\n  if (vt != VT_UI1)\r\n  {\r\n    InternalClear();\r\n    vt = VT_UI1;\r\n  }\r\n  bVal = value;\r\n  return *this;\r\n}\r\n\r\nCPropVariant& CPropVariant::operator=(Int16 value)\r\n{\r\n  if (vt != VT_I2)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I2;\r\n  }\r\n  iVal = value;\r\n  return *this;\r\n}\r\n\r\n/*\r\nCPropVariant& CPropVariant::operator=(LONG value)\r\n{\r\n  if (vt != VT_I4)\r\n  {\r\n    InternalClear();\r\n    vt = VT_I4;\r\n  }\r\n  lVal = value;\r\n  return *this;\r\n}\r\n*/\r\n\r\nstatic HRESULT MyPropVariantClear(PROPVARIANT *propVariant)\r\n{\r\n  switch(propVariant->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      propVariant->vt = VT_EMPTY;\r\n      propVariant->wReserved1 = 0;\r\n      return S_OK;\r\n  }\r\n  return ::VariantClear((VARIANTARG *)propVariant);\r\n}\r\n\r\nHRESULT CPropVariant::Clear()\r\n{\r\n  return MyPropVariantClear(this);\r\n}\r\n\r\nHRESULT CPropVariant::Copy(const PROPVARIANT* pSrc)\r\n{\r\n  ::VariantClear((tagVARIANT *)this);\r\n  switch(pSrc->vt)\r\n  {\r\n    case VT_UI1:\r\n    case VT_I1:\r\n    case VT_I2:\r\n    case VT_UI2:\r\n    case VT_BOOL:\r\n    case VT_I4:\r\n    case VT_UI4:\r\n    case VT_R4:\r\n    case VT_INT:\r\n    case VT_UINT:\r\n    case VT_ERROR:\r\n    case VT_FILETIME:\r\n    case VT_UI8:\r\n    case VT_R8:\r\n    case VT_CY:\r\n    case VT_DATE:\r\n      memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));\r\n      return S_OK;\r\n  }\r\n  return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc));\r\n}\r\n\r\n\r\nHRESULT CPropVariant::Attach(PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(this, pSrc, sizeof(PROPVARIANT));\r\n  pSrc->vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::Detach(PROPVARIANT* pDest)\r\n{\r\n  HRESULT hr = MyPropVariantClear(pDest);\r\n  if (FAILED(hr))\r\n    return hr;\r\n  memcpy(pDest, this, sizeof(PROPVARIANT));\r\n  vt = VT_EMPTY;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CPropVariant::InternalClear()\r\n{\r\n  HRESULT hr = Clear();\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n  return hr;\r\n}\r\n\r\nvoid CPropVariant::InternalCopy(const PROPVARIANT* pSrc)\r\n{\r\n  HRESULT hr = Copy(pSrc);\r\n  if (FAILED(hr))\r\n  {\r\n    vt = VT_ERROR;\r\n    scode = hr;\r\n  }\r\n}\r\n\r\nint CPropVariant::Compare(const CPropVariant &a)\r\n{\r\n  if (vt != a.vt)\r\n    return 0; // it's mean some bug\r\n  switch (vt)\r\n  {\r\n    case VT_EMPTY:\r\n      return 0;\r\n    \r\n    /*\r\n    case VT_I1:\r\n      return MyCompare(cVal, a.cVal);\r\n    */\r\n    case VT_UI1:\r\n      return MyCompare(bVal, a.bVal);\r\n\r\n    case VT_I2:\r\n      return MyCompare(iVal, a.iVal);\r\n    case VT_UI2:\r\n      return MyCompare(uiVal, a.uiVal);\r\n    \r\n    case VT_I4:\r\n      return MyCompare(lVal, a.lVal);\r\n    /*\r\n    case VT_INT:\r\n      return MyCompare(intVal, a.intVal);\r\n    */\r\n    case VT_UI4:\r\n      return MyCompare(ulVal, a.ulVal);\r\n    /*\r\n    case VT_UINT:\r\n      return MyCompare(uintVal, a.uintVal);\r\n    */\r\n    case VT_I8:\r\n      return MyCompare(hVal.QuadPart, a.hVal.QuadPart);\r\n    case VT_UI8:\r\n      return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);\r\n\r\n    case VT_BOOL:\r\n      return -MyCompare(boolVal, a.boolVal);\r\n\r\n    case VT_FILETIME:\r\n      return ::CompareFileTime(&filetime, &a.filetime);\r\n    case VT_BSTR:\r\n      return 0; // Not implemented\r\n      // return MyCompare(aPropVarint.cVal);\r\n\r\n    default:\r\n      return 0;\r\n  }\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/PropVariant.h",
    "content": "// Windows/PropVariant.h\r\n\r\n#ifndef __WINDOWS_PROPVARIANT_H\r\n#define __WINDOWS_PROPVARIANT_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NCOM {\r\n\r\nclass CPropVariant : public tagPROPVARIANT\r\n{\r\npublic:\r\n  CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }\r\n  ~CPropVariant() { Clear(); }\r\n  CPropVariant(const PROPVARIANT& varSrc);\r\n  CPropVariant(const CPropVariant& varSrc);\r\n  CPropVariant(BSTR bstrSrc);\r\n  CPropVariant(LPCOLESTR lpszSrc);\r\n  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };\r\n  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }\r\n  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal = *(ULARGE_INTEGER*)&value; }\r\n  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }\r\n  CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }\r\n  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }\r\n  CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }\r\n  // CPropVariant(LONG value, VARTYPE vtSrc = VT_I4) { vt = vtSrc; lVal = value; }\r\n\r\n  CPropVariant& operator=(const CPropVariant& varSrc);\r\n  CPropVariant& operator=(const PROPVARIANT& varSrc);\r\n  CPropVariant& operator=(BSTR bstrSrc);\r\n  CPropVariant& operator=(LPCOLESTR lpszSrc);\r\n  CPropVariant& operator=(bool bSrc);\r\n  CPropVariant& operator=(UInt32 value);\r\n  CPropVariant& operator=(UInt64 value);\r\n  CPropVariant& operator=(const FILETIME &value);\r\n\r\n  CPropVariant& operator=(Int32 value);\r\n  CPropVariant& operator=(Byte value);\r\n  CPropVariant& operator=(Int16 value);\r\n  // CPropVariant& operator=(LONG  value);\r\n\r\n  HRESULT Clear();\r\n  HRESULT Copy(const PROPVARIANT* pSrc);\r\n  HRESULT Attach(PROPVARIANT* pSrc);\r\n  HRESULT Detach(PROPVARIANT* pDest);\r\n\r\n  HRESULT InternalClear();\r\n  void InternalCopy(const PROPVARIANT* pSrc);\r\n\r\n  int Compare(const CPropVariant &a1);\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/PropVariantConversions.cpp",
    "content": "// PropVariantConversions.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"PropVariantConversions.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"Common/StringConvert.h\"\r\n#include \"Common/IntToString.h\"\r\n\r\nstatic UString ConvertUInt64ToString(UInt64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertUInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic UString ConvertInt64ToString(Int64 value)\r\n{\r\n  wchar_t buffer[32];\r\n  ConvertInt64ToString(value, buffer);\r\n  return buffer;\r\n}\r\n\r\nstatic char *UIntToStringSpec(char c, UInt32 value, char *s, int numPos)\r\n{\r\n  if (c != 0)\r\n    *s++ = c;\r\n  char temp[16];\r\n  int pos = 0;\r\n  do\r\n  {\r\n    temp[pos++] = (char)('0' + value % 10);\r\n    value /= 10;\r\n  }\r\n  while (value != 0);\r\n  int i;\r\n  for (i = 0; i < numPos - pos; i++)\r\n    *s++ = '0';\r\n  do\r\n    *s++ = temp[--pos];\r\n  while (pos > 0);\r\n  *s = '\\0';\r\n  return s;\r\n}\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)\r\n{\r\n  s[0] = '\\0';\r\n  SYSTEMTIME st;\r\n  if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))\r\n    return false;\r\n  s = UIntToStringSpec(0, st.wYear, s, 4);\r\n  s = UIntToStringSpec('-', st.wMonth, s, 2);\r\n  s = UIntToStringSpec('-', st.wDay, s, 2);\r\n  if (includeTime)\r\n  {\r\n    s = UIntToStringSpec(' ', st.wHour, s, 2);\r\n    s = UIntToStringSpec(':', st.wMinute, s, 2);\r\n    if (includeSeconds)\r\n      UIntToStringSpec(':', st.wSecond, s, 2);\r\n  }\r\n  return true;\r\n}\r\n\r\nUString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds)\r\n{\r\n  char s[32];\r\n  ConvertFileTimeToString(fileTime, s,  includeTime, includeSeconds);\r\n  return GetUnicodeString(s);\r\n}\r\n \r\n\r\nUString ConvertPropVariantToString(const PROPVARIANT &prop)\r\n{\r\n  switch (prop.vt)\r\n  {\r\n    case VT_EMPTY: return UString();\r\n    case VT_BSTR: return prop.bstrVal;\r\n    case VT_UI1: return ConvertUInt64ToString(prop.bVal);\r\n    case VT_UI2: return ConvertUInt64ToString(prop.uiVal);\r\n    case VT_UI4: return ConvertUInt64ToString(prop.ulVal);\r\n    case VT_UI8: return ConvertUInt64ToString(prop.uhVal.QuadPart);\r\n    case VT_FILETIME: return ConvertFileTimeToString(prop.filetime, true, true);\r\n    // case VT_I1: return ConvertInt64ToString(prop.cVal);\r\n    case VT_I2: return ConvertInt64ToString(prop.iVal);\r\n    case VT_I4: return ConvertInt64ToString(prop.lVal);\r\n    case VT_I8: return ConvertInt64ToString(prop.hVal.QuadPart);\r\n    case VT_BOOL: return VARIANT_BOOLToBool(prop.boolVal) ? L\"+\" : L\"-\";\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 150245;\r\n      #else\r\n      return UString();\r\n      #endif\r\n  }\r\n}\r\n\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &prop)\r\n{\r\n  switch (prop.vt)\r\n  {\r\n    case VT_UI1: return prop.bVal;\r\n    case VT_UI2: return prop.uiVal;\r\n    case VT_UI4: return prop.ulVal;\r\n    case VT_UI8: return (UInt64)prop.uhVal.QuadPart;\r\n    default:\r\n      #ifndef _WIN32_WCE\r\n      throw 151199;\r\n      #else\r\n      return 0;\r\n      #endif\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/PropVariantConversions.h",
    "content": "// Windows/PropVariantConversions.h\r\n\r\n#ifndef __PROPVARIANTCONVERSIONS_H\r\n#define __PROPVARIANTCONVERSIONS_H\r\n\r\n#include \"Common/Types.h\"\r\n#include \"Common/MyString.h\"\r\n\r\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true);\r\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant);\r\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/Synchronization.cpp",
    "content": "// Windows/Synchronization.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Synchronization.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/Synchronization.h",
    "content": "// Windows/Synchronization.h\r\n\r\n#ifndef __WINDOWS_SYNCHRONIZATION_H\r\n#define __WINDOWS_SYNCHRONIZATION_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\n#ifdef _WIN32\r\n#include \"Handle.h\"\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NSynchronization {\r\n\r\nclass CBaseEvent\r\n{\r\nprotected:\r\n  ::CEvent _object;\r\npublic:\r\n  bool IsCreated() { return Event_IsCreated(&_object) != 0; }\r\n  operator HANDLE() { return _object.handle; }\r\n  CBaseEvent() { Event_Construct(&_object); }\r\n  ~CBaseEvent() { Close(); }\r\n  WRes Close() { return Event_Close(&_object); }\r\n  #ifdef _WIN32\r\n  WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),\r\n        BoolToBOOL(initiallyOwn), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_object.handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  #endif\r\n\r\n  WRes Set() { return Event_Set(&_object); }\r\n  // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }\r\n  WRes Reset() { return Event_Reset(&_object); }\r\n  WRes Lock() { return Event_Wait(&_object); }\r\n};\r\n\r\nclass CManualResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  WRes Create(bool initiallyOwn = false)\r\n  {\r\n    return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);\r\n  }\r\n  WRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return ManualResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  #ifdef _WIN32\r\n  WRes CreateWithName(bool initiallyOwn, LPCTSTR name)\r\n  {\r\n    return CBaseEvent::Create(true, initiallyOwn, name);\r\n  }\r\n  #endif\r\n};\r\n\r\nclass CAutoResetEvent: public CBaseEvent\r\n{\r\npublic:\r\n  WRes Create()\r\n  {\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n  WRes CreateIfNotCreated()\r\n  {\r\n    if (IsCreated())\r\n      return 0;\r\n    return AutoResetEvent_CreateNotSignaled(&_object);\r\n  }\r\n};\r\n\r\n#ifdef _WIN32\r\nclass CObject: public CHandle\r\n{\r\npublic:\r\n  WRes Lock(DWORD timeoutInterval = INFINITE)\r\n    { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }\r\n};\r\nclass CMutex: public CObject\r\n{\r\npublic:\r\n  WRes Create(bool initiallyOwn, LPCTSTR name = NULL,\r\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\r\n  {\r\n    _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\r\n  {\r\n    _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);\r\n    if (_handle != 0)\r\n      return 0;\r\n    return ::GetLastError();\r\n  }\r\n  WRes Release()\r\n  {\r\n    return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();\r\n  }\r\n};\r\nclass CMutexLock\r\n{\r\n  CMutex *_object;\r\npublic:\r\n  CMutexLock(CMutex &object): _object(&object) { _object->Lock(); }\r\n  ~CMutexLock() { _object->Release(); }\r\n};\r\n#endif\r\n\r\nclass CSemaphore\r\n{\r\n  ::CSemaphore _object;\r\npublic:\r\n  CSemaphore() { Semaphore_Construct(&_object); }\r\n  ~CSemaphore() { Close(); }\r\n  WRes Close() {  return Semaphore_Close(&_object); }\r\n  operator HANDLE() { return _object.handle; }\r\n  WRes Create(UInt32 initiallyCount, UInt32 maxCount)\r\n  {\r\n    return Semaphore_Create(&_object, initiallyCount, maxCount);\r\n  }\r\n  WRes Release() { return Semaphore_Release1(&_object); }\r\n  WRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }\r\n  WRes Lock() { return Semaphore_Wait(&_object); }\r\n};\r\n\r\nclass CCriticalSection\r\n{\r\n  ::CCriticalSection _object;\r\npublic:\r\n  CCriticalSection() { CriticalSection_Init(&_object); }\r\n  ~CCriticalSection() { CriticalSection_Delete(&_object); }\r\n  void Enter() { CriticalSection_Enter(&_object); }\r\n  void Leave() { CriticalSection_Leave(&_object); }\r\n};\r\n\r\nclass CCriticalSectionLock\r\n{\r\n  CCriticalSection *_object;\r\n  void Unlock()  { _object->Leave(); }\r\npublic:\r\n  CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); }\r\n  ~CCriticalSectionLock() { Unlock(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/System.cpp",
    "content": "// Windows/System.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"System.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors()\r\n{\r\n  SYSTEM_INFO systemInfo;\r\n  GetSystemInfo(&systemInfo);\r\n  return (UInt32)systemInfo.dwNumberOfProcessors;\r\n}\r\n\r\n#if !defined(_WIN64) && defined(__GNUC__)\r\n\r\ntypedef struct _MY_MEMORYSTATUSEX {\r\n  DWORD dwLength;\r\n  DWORD dwMemoryLoad;\r\n  DWORDLONG ullTotalPhys;\r\n  DWORDLONG ullAvailPhys;\r\n  DWORDLONG ullTotalPageFile;\r\n  DWORDLONG ullAvailPageFile;\r\n  DWORDLONG ullTotalVirtual;\r\n  DWORDLONG ullAvailVirtual;\r\n  DWORDLONG ullAvailExtendedVirtual;\r\n} MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX;\r\n\r\n#else\r\n\r\n#define MY_MEMORYSTATUSEX MEMORYSTATUSEX\r\n#define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX\r\n\r\n#endif\r\n\r\ntypedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);\r\n\r\nUInt64 GetRamSize()\r\n{\r\n  MY_MEMORYSTATUSEX stat;\r\n  stat.dwLength = sizeof(stat);\r\n  #ifdef _WIN64\r\n  if (!::GlobalMemoryStatusEx(&stat))\r\n    return 0;\r\n  return stat.ullTotalPhys;\r\n  #else\r\n  GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")),\r\n        \"GlobalMemoryStatusEx\");\r\n  if (globalMemoryStatusEx != 0)\r\n    if (globalMemoryStatusEx(&stat))\r\n      return stat.ullTotalPhys;\r\n  {\r\n    MEMORYSTATUS stat;\r\n    stat.dwLength = sizeof(stat);\r\n    GlobalMemoryStatus(&stat);\r\n    return stat.dwTotalPhys;\r\n  }\r\n  #endif\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/System.h",
    "content": "// Windows/System.h\r\n\r\n#ifndef __WINDOWS_SYSTEM_H\r\n#define __WINDOWS_SYSTEM_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NSystem {\r\n\r\nUInt32 GetNumberOfProcessors();\r\nUInt64 GetRamSize();\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/Thread.h",
    "content": "// Windows/Thread.h\r\n\r\n#ifndef __WINDOWS_THREAD_H\r\n#define __WINDOWS_THREAD_H\r\n\r\n#include \"Defs.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../../C/Threads.h\"\r\n}\r\n\r\nnamespace NWindows {\r\n\r\nclass CThread\r\n{\r\n  ::CThread thread;\r\npublic:\r\n  CThread() { Thread_Construct(&thread); }\r\n  ~CThread() { Close(); }\r\n  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }\r\n  WRes Close()  { return Thread_Close(&thread); }\r\n  WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r\n    { return Thread_Create(&thread, startAddress, parameter); }\r\n  WRes Wait() { return Thread_Wait(&thread); }\r\n  \r\n  #ifdef _WIN32\r\n  operator HANDLE() { return thread.handle; }\r\n  void Attach(HANDLE handle) { thread.handle = handle; }\r\n  HANDLE Detach() { HANDLE h = thread.handle; thread.handle = NULL; return h; }\r\n  DWORD Resume() { return ::ResumeThread(thread.handle); }\r\n  DWORD Suspend() { return ::SuspendThread(thread.handle); }\r\n  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }\r\n  int GetPriority() { return ::GetThreadPriority(thread.handle); }\r\n  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }\r\n  #endif\r\n};\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/Time.cpp",
    "content": "// Windows/Time.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"Time.h\"\r\n#include \"Windows/Defs.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)\r\n{\r\n  return BOOLToBool(::DosDateTimeToFileTime((UInt16)(dosTime >> 16), (UInt16)(dosTime & 0xFFFF), &fileTime));\r\n}\r\n\r\nstatic const UInt32 kHighDosTime = 0xFF9FBF7D;\r\nstatic const UInt32 kLowDosTime = 0x210000;\r\n\r\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)\r\n{\r\n  WORD datePart, timePart;\r\n  if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))\r\n  {\r\n    dosTime = (fileTime.dwHighDateTime >= 0x01C00000) ? kHighDosTime : kLowDosTime;\r\n    return false;\r\n  }\r\n  dosTime = (((UInt32)datePart) << 16) + timePart;\r\n  return true;\r\n}\r\n\r\nstatic const UInt32 kNumTimeQuantumsInSecond = 10000000;\r\nstatic const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;\r\n\r\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)\r\n{\r\n  UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;\r\n  fileTime.dwLowDateTime = (DWORD)v;\r\n  fileTime.dwHighDateTime = (DWORD)(v >> 32);\r\n}\r\n\r\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)\r\n{\r\n  UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;\r\n  if (winTime < kUnixTimeStartValue)\r\n  {\r\n    unixTime = 0;\r\n    return false;\r\n  }\r\n  winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;\r\n  if (winTime > 0xFFFFFFFF)\r\n  {\r\n    unixTime = 0xFFFFFFFF;\r\n    return false;\r\n  }\r\n  unixTime = (UInt32)winTime;\r\n  return true;\r\n}\r\n\r\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\r\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds)\r\n{\r\n  resSeconds = 0;\r\n  if (year < 1601 || year >= 10000 || month < 1 || month > 12 ||\r\n      day < 1 || day > 31 || hour > 23 || min > 59 || sec > 59)\r\n    return false;\r\n  UInt32 numYears = year - 1601;\r\n  UInt32 numDays = numYears * 365 + numYears / 4 - numYears / 100 + numYears / 400;\r\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\r\n    ms[1] = 29;\r\n  month--;\r\n  for (unsigned i = 0; i < month; i++)\r\n    numDays += ms[i];\r\n  numDays += day - 1;\r\n  resSeconds = ((UInt64)(numDays * 24 + hour) * 60 + min) * 60 + sec;\r\n  return true;\r\n}\r\n\r\nvoid GetCurUtcFileTime(FILETIME &ft)\r\n{\r\n  SYSTEMTIME st;\r\n  GetSystemTime(&st);\r\n  SystemTimeToFileTime(&st, &ft);\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CPP/Windows/Time.h",
    "content": "// Windows/Time.h\r\n\r\n#ifndef __WINDOWS_TIME_H\r\n#define __WINDOWS_TIME_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NTime {\r\n\r\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime);\r\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime);\r\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime);\r\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime);\r\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\r\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds);\r\nvoid GetCurUtcFileTime(FILETIME &ft);\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid SetStream(System.IO.Stream inStream);\r\n\t\tvoid Init();\r\n\t\tvoid ReleaseStream();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetMatches(UInt32[] distances);\r\n\t\tvoid Skip(UInt32 num);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize = 0;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\tUInt32[] _son;\r\n\t\tUInt32[] _hash;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\t\tUInt32 _hashMask;\r\n\t\tUInt32 _hashSizeSum = 0;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\r\n\t\tconst UInt32 kHash2Size = 1 << 10;\r\n\t\tconst UInt32 kHash3Size = 1 << 16;\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kStartMaxLen = 1;\r\n\t\tconst UInt32 kHash3Offset = kHash2Size;\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\t\r\n\t\tUInt32 kNumHashDirectBytes = 0;\r\n\t\tUInt32 kMinMatchCheck = 4;\r\n\t\tUInt32 kFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\r\n\t\tpublic void SetType(int numHashBytes)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\t\tkMinMatchCheck = 4;\r\n\t\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\t\tkFixHashSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic new void SetStream(System.IO.Stream stream) { base.SetStream(stream); }\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\t\t\r\n\t\tpublic new void Init()\r\n\t\t{\r\n\t\t\tbase.Init();\r\n\t\t\tfor (UInt32 i = 0; i < _hashSizeSum; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\t\tthrow new Exception();\r\n\t\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\t\t\t\t\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\tUInt32 cyclicBufferSize = historySize + 1;\r\n\t\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t\t_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\t\tUInt32 hs = kBT2HashSize;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\ths = historySize - 1;\r\n\t\t\t\ths |= (hs >> 1);\r\n\t\t\t\ths |= (hs >> 2);\r\n\t\t\t\ths |= (hs >> 4);\r\n\t\t\t\ths |= (hs >> 8);\r\n\t\t\t\ths >>= 1;\r\n\t\t\t\ths |= 0xFFFF;\r\n\t\t\t\tif (hs > (1 << 24))\r\n\t\t\t\t\ths >>= 1;\r\n\t\t\t\t_hashMask = hs;\r\n\t\t\t\ths++;\r\n\t\t\t\ths += kFixHashSize;\r\n\t\t\t}\r\n\t\t\tif (hs != _hashSizeSum)\r\n\t\t\t\t_hash = new UInt32[_hashSizeSum = hs];\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetMatches(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 offset = 0;\r\n\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\t\t\tUInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tUInt32 curMatch2 = _hash[hash2Value];\r\n\t\t\t\tUInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t\t{\r\n\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\t\t\t\r\n\t\t\tif (kNumHashDirectBytes != 0)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\r\n\t\t\twhile(true)\r\n\t\t\t{\r\n\t\t\t\tif(curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (maxLen < len)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t\treturn offset;\r\n\t\t}\r\n\r\n\t\tpublic void Skip(UInt32 num)\r\n\t\t{\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenLimit;\r\n\t\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tMovePos();\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\t\tUInt32 hashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\r\n\t\t\t\t\tUInt32 hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\r\n\t\t\t\t\tUInt32 hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\r\n\r\n\t\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\t\tUInt32 len0, len1;\r\n\t\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\t\tUInt32 count = _cutValue;\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\t\tUInt32 len = Math.Min(len0, len1);\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\t\tlen1 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\t\tlen0 = len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tMovePos();\r\n\t\t\t}\r\n\t\t\twhile (--num != 0);\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 subValue = _pos - _cyclicBufferSize;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize; // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos; // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos\r\n\t\tpublic UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\t\tif (offset > 0)\r\n\t\t\t\toffset--;\r\n\t\t\t\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { _stream = stream; }\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic uint TrainSize = 0;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t\tTrainSize = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tlong len = stream.Length;\r\n\t\t\tuint size = (len < _windowSize) ? (uint)len : _windowSize;\r\n\t\t\tTrainSize = size;\r\n\t\t\tstream.Position = len - size;\r\n\t\t\t_streamPos = _pos = 0;\r\n\t\t\twhile (size > 0)\r\n\t\t\t{\r\n\t\t\t\tuint curSize = _windowSize - _pos;\r\n\t\t\t\tif (size < curSize)\r\n\t\t\t\t\tcurSize = size;\r\n\t\t\t\tint numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tsize -= (uint)numReadBytes;\r\n\t\t\t\t_pos += (uint)numReadBytes;\r\n\t\t\t\t_streamPos += (uint)numReadBytes;\r\n\t\t\t\tif (_pos == _windowSize)\r\n\t\t\t\t\t_streamPos = _pos = 0;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t\tpublic bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\t// public const int kDicLogSizeMax = 30;\r\n\t\t// public const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tbool _solid = false;\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream, _solid);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\tpublic bool Train(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t_solid = true;\r\n\t\t\treturn m_OutWindow.Train(stream);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get { return 0; }}\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t};\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1 << 11];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 22;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 11))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 21))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 10] + 20);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 20] + 40);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 17))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 27))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 16] + 32);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 26] + 52);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 22;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32[] prices, UInt32 st)\r\n\t\t\t{\r\n\t\t\t\tUInt32 a0 = _choice.GetPrice0();\r\n\t\t\t\tUInt32 a1 = _choice.GetPrice1();\r\n\t\t\t\tUInt32 b0 = a1 + _choice2.GetPrice0();\r\n\t\t\t\tUInt32 b1 = a1 + _choice2.GetPrice1();\r\n\t\t\t\tUInt32 i = 0;\r\n\t\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\tLZ.IMatchFinder _matchFinder = null;\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates];\r\n\t\t\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];\r\n\t\t\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _numDistancePairs;\r\n\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\t\tSystem.IO.Stream _inStream;\r\n\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark = false;\r\n\t\t\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tif (_matchFinderType == EMatchFinderType.BT2)\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs)\r\n\t\t{\r\n\t\t\tlenRes = 0;\r\n\t\t\tnumDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\t\tif (numDistancePairs > 0)\r\n\t\t\t{\r\n\t\t\t\tlenRes = _matchDistances[numDistancePairs - 2];\r\n\t\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t}\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tif (num > 0)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Skip(num);\r\n\t\t\t\t_additionalOffset += num;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t\t}\r\n\t\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\t\tUInt32 lenMain, numDistancePairs;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain, out numDistancePairs);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\t\t\t\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = (UInt32)0xFFFFFFFF;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\t\tif(lenEnd < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\t\tUInt32 len = lenEnd;\r\n\t\t\tdo\r\n\t\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\t\twhile (len >= 2);\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tif (repLen < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tUInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--repLen >= 2);\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\t\t\t\r\n\t\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\t\tif (len <= lenMain)\r\n\t\t\t{\r\n\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\tfor (; ; len++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 distance = _matchDistances[offs + 1];\r\n\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen, out numDistancePairs);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_numDistancePairs = numDistancePairs;\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t\t{\r\n\t\t\t\t\t// try Literal + rep0\r\n\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tUInt32 startLen = 2; // speed optimization \r\n\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t\t// if (_maxMode)\r\n\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, reps[repIndex], t);\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)(reps[repIndex] + 1))), \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t\t}\r\n\t\t\t\tif (newLen >= startLen)\r\n\t\t\t\t{\r\n\t\t\t\t\tnormalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tUInt32 offs = 0;\r\n\t\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = startLen; ; lenTest++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t);\r\n\t\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)(curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t\t_matchFinder.Init();\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t\tif (_trainSize > 0)\r\n\t\t\t\t\t_matchFinder.Skip(_trainSize);\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len, numDistancePairs; // it's not used\r\n\t\t\t\tReadMatchDistances(out len, out numDistancePairs);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 len = GetOptimum((UInt32)nowPos64, out pos);\r\n\t\t\t\t\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t// if (!_fastMode)\r\n\t\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// if (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\t\t\r\n\t\tUInt32[] tempPrices = new UInt32[Base.kNumFullDistances];\r\n\t\tUInt32 _matchPriceCount;\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t\t{ \r\n\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, \r\n\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tRangeCoder.BitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\t\t\t\r\n\t\t\t\tUInt32 st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\t\tUInt32 st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t\t}\r\n\t\t\t_matchPriceCount = 0;\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = 0;\r\n\t\t}\r\n\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\t\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t/*\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t*/\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 30;\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _trainSize = 0;\r\n\t\tpublic void SetTrainSize(uint trainSize)\r\n\t\t{\r\n\t\t\t_trainSize = trainSize;\r\n\t\t}\r\n\t\t\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\t\r\n\tpublic class CDoubleStream: Stream\r\n\t{\r\n\t\tpublic System.IO.Stream s1;\r\n\t\tpublic System.IO.Stream s2;\r\n\t\tpublic int fileIndex;\r\n\t\tpublic long skipSize;\r\n\t\t\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return false; }}\r\n\t\tpublic override bool CanSeek { get { return false; }}\r\n\t\tpublic override long Length { get { return s1.Length + s2.Length - skipSize; } }\r\n\t\tpublic override long Position\r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\tint numTotal = 0;\r\n\t\t\twhile (count > 0)\r\n\t\t\t{\r\n\t\t\t\tif (fileIndex == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tint num = s1.Read(buffer, offset, count);\r\n\t\t\t\t\toffset += num;\r\n\t\t\t\t\tcount -= num;\r\n\t\t\t\t\tnumTotal += num;\r\n\t\t\t\t\tif (num == 0)\r\n\t\t\t\t\t\tfileIndex++;\r\n\t\t\t\t}\r\n\t\t\t\tif (fileIndex == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tnumTotal += s2.Read(buffer, offset, count);\r\n\t\t\t\t\treturn numTotal;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn numTotal;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Write\"));\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't Seek\"));\r\n\t\t}\r\n\t\tpublic override void SetLength(long value)\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"can't SetLength\"));\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut,\r\n\t\t\tTrain\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0, 29], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.61  2008-11-23\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[13];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"T\", SwitchType.UnLimitedPostString, false, 1);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary);\r\n\t\t\t}\r\n\r\n\t\t\tstring train = \"\";\r\n\t\t\tif (parser[(int)Key.Train].ThereIs)\r\n\t\t\t\ttrain = (string)parser[(int)Key.Train].PostStrings[0];\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream trainStream = null;\r\n\t\t\tif (train.Length != 0)\r\n\t\t\t\ttrainStream = new FileStream(train, FileMode.Open, FileAccess.Read);\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tCDoubleStream doubleStream = new CDoubleStream();\r\n\t\t\t\t\tdoubleStream.s1 = trainStream;\r\n\t\t\t\t\tdoubleStream.s2 = inStream;\r\n\t\t\t\t\tdoubleStream.fileIndex = 0;\r\n\t\t\t\t\tinStream = doubleStream;\r\n\t\t\t\t\tlong trainFileSize = trainStream.Length;\r\n\t\t\t\t\tdoubleStream.skipSize = 0;\r\n\t\t\t\t\tif (trainFileSize > dictionary)\r\n\t\t\t\t\t\tdoubleStream.skipSize = trainFileSize - dictionary;\r\n\t\t\t\t\ttrainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);\r\n\t\t\t\t\tencoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));\r\n\t\t\t\t}\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tif (trainStream != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!decoder.Train(trainStream))\r\n\t\t\t\t\t\tthrow (new Exception(\"can't train\"));\r\n\t\t\t\t}\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.50727</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n    <PlatformTarget>AnyCPU</PlatformTarget>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tUInt32 Rep0;\r\n\t\t\t\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\t\tUInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\tRG.Init();\r\n\t\t\t\tRep0 = 1;\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)RG.GetRnd(8);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 len;\r\n\t\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\t\tUInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 220 + outSize * 20;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 18))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "// LZ.BinTree\r\n\r\npackage SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\r\n\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize = 0;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\tint[] _hash;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\tint _hashMask;\r\n\tint _hashSizeSum = 0;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\r\n\tstatic final int kHash2Size = 1 << 10;\r\n\tstatic final int kHash3Size = 1 << 16;\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kStartMaxLen = 1;\r\n\tstatic final int kHash3Offset = kHash2Size;\r\n\tstatic final int kEmptyHashValue = 0;\r\n\tstatic final int kMaxValForNormalize = (1 << 30) - 1;\r\n\t\r\n\tint kNumHashDirectBytes = 0;\r\n\tint kMinMatchCheck = 4;\r\n\tint kFixHashSize = kHash2Size + kHash3Size;\r\n\r\n\tpublic void SetType(int numHashBytes)\r\n\t{\r\n\t\tHASH_ARRAY = (numHashBytes > 2);\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 0;\r\n\t\t\tkMinMatchCheck = 4;\r\n\t\t\tkFixHashSize = kHash2Size + kHash3Size;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = 2;\r\n\t\t\tkMinMatchCheck = 2 + 1;\r\n\t\t\tkFixHashSize = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tfor (int i = 0; i < _hashSizeSum; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tif (historySize > kMaxValForNormalize - 256)\r\n\t\t\treturn false;\r\n\t\t_cutValue = 16 + (matchMaxLen >> 1);\r\n\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\tint cyclicBufferSize = historySize + 1;\r\n\t\tif (_cyclicBufferSize != cyclicBufferSize)\r\n\t\t\t_son = new int[(_cyclicBufferSize = cyclicBufferSize) * 2];\r\n\r\n\t\tint hs = kBT2HashSize;\r\n\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\ths = historySize - 1;\r\n\t\t\ths |= (hs >> 1);\r\n\t\t\ths |= (hs >> 2);\r\n\t\t\ths |= (hs >> 4);\r\n\t\t\ths |= (hs >> 8);\r\n\t\t\ths >>= 1;\r\n\t\t\ths |= 0xFFFF;\r\n\t\t\tif (hs > (1 << 24))\r\n\t\t\t\ths >>= 1;\r\n\t\t\t_hashMask = hs;\r\n\t\t\ths++;\r\n\t\t\ths += kFixHashSize;\r\n\t\t}\r\n\t\tif (hs != _hashSizeSum)\r\n\t\t\t_hash = new int [_hashSizeSum = hs];\r\n\t\treturn true;\r\n\t}\r\n\tpublic int GetMatches(int[] distances) throws IOException\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t{\r\n\t\t\t\tMovePos();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint offset = 0;\r\n\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\tint maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint curMatch2 = _hash[hash2Value];\r\n\t\t\tint curMatch3 = _hash[kHash3Offset + hash3Value];\r\n\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\tif (curMatch2 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = 2;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\r\n\t\t\t\t}\r\n\t\t\tif (curMatch3 > matchMinPos)\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tif (curMatch3 == curMatch2)\r\n\t\t\t\t\t\toffset -= 2;\r\n\t\t\t\t\tdistances[offset++] = maxLen = 3;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\r\n\t\t\t\t\tcurMatch2 = curMatch3;\r\n\t\t\t\t}\r\n\t\t\tif (offset != 0 && curMatch2 == curMatch)\r\n\t\t\t{\r\n\t\t\t\toffset -= 2;\r\n\t\t\t\tmaxLen = kStartMaxLen;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\tint len0, len1;\r\n\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\tif (kNumHashDirectBytes != 0)\r\n\t\t{\r\n\t\t\tif (curMatch > matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\r\n\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\r\n\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint count = _cutValue;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint len = Math.min(len0, len1);\r\n\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t{\r\n\t\t\t\twhile(++len != lenLimit)\r\n\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tif (maxLen < len)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[offset++] = maxLen = len;\r\n\t\t\t\t\tdistances[offset++] = delta - 1;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t{\r\n\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\tlen1 = len;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\tlen0 = len;\r\n\t\t\t}\r\n\t\t}\r\n\t\tMovePos();\r\n\t\treturn offset;\r\n\t}\r\n\r\n\tpublic void Skip(int num) throws IOException\r\n\t{\r\n\t\tdo\r\n\t\t{\r\n\t\t\tint lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kMinMatchCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\tMovePos();\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n\t\t\tint cur = _bufferOffset + _pos;\r\n\t\t\t\r\n\t\t\tint hashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\t\tint hash2Value = temp & (kHash2Size - 1);\r\n\t\t\t\t_hash[hash2Value] = _pos;\r\n\t\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\t\tint hash3Value = temp & (kHash3Size - 1);\r\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\r\n\t\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\r\n\r\n\t\t\tint curMatch = _hash[kFixHashSize + hashValue];\r\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\r\n\r\n\t\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tint ptr1 = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tint len0, len1;\r\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\r\n\r\n\t\t\tint count = _cutValue;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tint len = Math.min(len0, len1);\r\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (++len != lenLimit)\r\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tif (len == lenLimit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\r\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr1] = curMatch;\r\n\t\t\t\t\tptr1 = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptr1];\r\n\t\t\t\t\tlen1 = len;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptr0] = curMatch;\r\n\t\t\t\t\tptr0 = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptr0];\r\n\t\t\t\t\tlen0 = len;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tMovePos();\r\n\t\t}\r\n\t\twhile (--num != 0);\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint subValue = _pos - _cyclicBufferSize;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue) { _cutValue = cutValue; }\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\t// we need one additional byte, since MovePos moves on 1 byte.\r\n\t\tif (offset > 0)\r\n\t\t\toffset--;\r\n\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free() { _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream) { _stream = stream; \t}\r\n\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\t// public static final int kDicLogSizeMax = 28;\r\n\t// public static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\r\n\r\n\r\n\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\r\n\tstatic byte[] g_FastPos = new byte[1 << 11];\r\n\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 22;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 11))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 21))\r\n\t\t\treturn (g_FastPos[pos >> 10] + 20);\r\n\t\treturn (g_FastPos[pos >> 20] + 40);\r\n\t}\r\n\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 17))\r\n\t\t\treturn (g_FastPos[pos >> 6] + 12);\r\n\t\tif (pos < (1 << 27))\r\n\t\t\treturn (g_FastPos[pos >> 16] + 32);\r\n\t\treturn (g_FastPos[pos >> 26] + 52);\r\n\t}\r\n\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\r\n\tstatic final int kDefaultDictionaryLogSize = 22;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\r\n\t\t\tpublic void Init() { SevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders); }\r\n\r\n\r\n\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetPrices(int posState, int numSymbols, int[] prices, int st)\r\n\t\t{\r\n\t\t\tint a0 = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\tint a1 = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\tint b0 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\tint b1 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\tint i = 0;\r\n\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\r\n\t\t\t}\r\n\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\r\n\t\t\t{\r\n\t\t\t\tif (i >= numSymbols)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\r\n\t\t\t}\r\n\t\t\tfor (; i < numSymbols; i++)\r\n\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\r\n\t\t}\r\n\t};\r\n\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols<<Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\tpublic void SetTableSize(int tableSize) { _tableSize = tableSize; }\r\n\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\r\n\t\t}\r\n\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\r\n\tstatic final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;\r\n\t\tpublic int BackPrev;\r\n\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\r\n\t\tpublic void MakeAsChar() { BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep() { return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null;\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\r\n\tshort[] _isMatch = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\r\n\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances-Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen*2+2];\r\n\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _numDistancePairs;\r\n\r\n\tint _additionalOffset;\r\n\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\r\n\tboolean _longestMatchWasFound;\r\n\r\n\tint[] _posSlotPrices = new int[1<<(Base.kNumPosSlotBits+Base.kNumLenToPosStatesBits)];\r\n\tint[] _distancesPrices = new int[Base.kNumFullDistances<<Base.kNumLenToPosStatesBits];\r\n\tint[] _alignPrices = new int[Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\tjava.io.InputStream _inStream;\r\n\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\r\n\tboolean _needReleaseMFStream = false;\r\n\r\n\tvoid Create()\r\n\t{\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tif (_matchFinderType == EMatchFinderTypeBT2)\r\n\t\t\t\tnumHashBytes = 2;\r\n\t\t\tbt.SetType(numHashBytes);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\r\n\tvoid SetWriteEndMarkerMode(boolean writeEndMarker)\r\n\t{\r\n\t\t_writeEndMark = writeEndMarker;\r\n\t}\r\n\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\r\n\r\n\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n\t\t_posAlignEncoder.Init();\r\n\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = 0;\r\n\t\t_numDistancePairs = _matchFinder.GetMatches(_matchDistances);\r\n\t\tif (_numDistancePairs > 0)\r\n\t\t{\r\n\t\t\tlenRes = _matchDistances[_numDistancePairs - 2];\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[_numDistancePairs - 1],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t}\r\n\t\t_additionalOffset++;\r\n\t\treturn lenRes;\r\n\t}\r\n\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tif (num > 0)\r\n\t\t{\r\n\t\t\t_matchFinder.Skip(num);\r\n\t\t\t_additionalOffset += num;\r\n\t\t}\r\n\t}\r\n\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\r\n\tint GetPureRepPrice(int repIndex, int state, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\treturn price + GetPureRepPrice(repIndex, state, posState);\r\n\t}\r\n\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\r\n\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\r\n\tint Backward(int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\tint backRes;\r\n\r\n\tint GetOptimum(int position) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\r\n\r\n\t\tint lenMain, numDistancePairs;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tnumDistancePairs = _numDistancePairs;\r\n\r\n\t\tint numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\tif (numAvailableBytes < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tif (numAvailableBytes > Base.kMatchMaxLen)\r\n\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\r\n\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\tbyte matchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\r\n\t\t{\r\n\t\t\tbackRes = -1;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[0].State = _state;\r\n\r\n\t\tint posState = (position & _posStateMask);\r\n\r\n\t\t_optimum[1].Price = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\r\n\r\n\t\tif (lenEnd < 2)\r\n\t\t{\r\n\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\t\tint len = lenEnd;\r\n\t\tdo\r\n\t\t\t_optimum[len--].Price = kIfinityPrice;\r\n\t\twhile (len >= 2);\r\n\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tif (repLen < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tint price = repMatchPrice + GetPureRepPrice(i, _state, posState);\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\r\n\t\t\t\tOptimal optimum = _optimum[repLen];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\twhile (--repLen >= 2);\r\n\t\t}\r\n\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\r\n\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\r\n\t\tif (len <= lenMain)\r\n\t\t{\r\n\t\t\tint offs = 0;\r\n\t\t\twhile (len > _matchDistances[offs])\r\n\t\t\t\toffs += 2;\r\n\t\t\tfor (; ; len++)\r\n\t\t\t{\r\n\t\t\t\tint distance = _matchDistances[offs + 1];\r\n\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\r\n\t\t\t\tOptimal optimum = _optimum[len];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t\tif (len == _matchDistances[offs])\r\n\t\t\t\t{\r\n\t\t\t\t\toffs += 2;\r\n\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint cur = 0;\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tnumDistancePairs = _numDistancePairs;\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\r\n\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tnumAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (!nextIsChar && matchByte != currentByte)\r\n\t\t\t{\r\n\t\t\t\t// try Literal + rep0\r\n\t\t\t\tint t = Math.min(numAvailableBytesFull - 1, _numFastBytes);\r\n\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint offset = cur + 1 + lenTest2;\r\n\t\t\t\t\t\twhile (lenEnd < offset)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[offset];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tint startLen = 2; // speed optimization \r\n\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\tint lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\r\n\t\t\t\tif (lenTest < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\tif (repIndex == 0)\r\n\t\t\t\t\tstartLen = lenTest + 1;\r\n\r\n\t\t\t\t// if (_maxMode)\r\n\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t{\r\n\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, reps[repIndex], t);\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - (reps[repIndex] + 1)),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t{\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\r\n\t\t\t\t_matchDistances[numDistancePairs] = newLen;\r\n\t\t\t\tnumDistancePairs += 2;\r\n\t\t\t}\r\n\t\t\tif (newLen >= startLen)\r\n\t\t\t{\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\tint offs = 0;\r\n\t\t\t\twhile (startLen > _matchDistances[offs])\r\n\t\t\t\t\toffs += 2;\r\n\r\n\t\t\t\tfor (int lenTest = startLen; ; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[offs + 1];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (lenTest == _matchDistances[offs])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\r\n\t\t\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, curBack, t);\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\r\n\t\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - (curBack + 1) - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\toffs += 2;\r\n\t\t\t\t\t\tif (offs == numDistancePairs)\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\r\n\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\r\n\t\t\tint len = GetOptimum((int)nowPos64);\r\n\t\t\tint pos = backRes;\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t_alignPriceCount++;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t_matchPriceCount++;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\t// if (!_fastMode)\r\n\t\t\t\tif (_matchPriceCount >= (1 << 7))\r\n\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\r\n\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\r\n\t\t// if (!_fastMode)\r\n\t\t{\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\r\n\tlong[] processedInSize = new long[1]; long[] processedOutSize = new long[1]; boolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\r\n\r\n\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\r\n\tint[] tempPrices = new int[Base.kNumFullDistances];\r\n\tint _matchPriceCount;\r\n\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\r\n\t\t{\r\n\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t}\r\n\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tBitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\r\n\r\n\t\t\tint st = (lenToPosState << Base.kNumPosSlotBits);\r\n\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\r\n\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\r\n\t\t\tint st2 = lenToPosState * Base.kNumFullDistances;\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\r\n\t\t}\r\n\t\t_matchPriceCount = 0;\r\n\t}\r\n\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = 0;\r\n\t}\r\n\r\n\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\t/*\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\t*/\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = 29;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++) ;\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n}\r\n\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.61  2008-11-23\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SetNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator() { Init(); }\r\n\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tint Rep0;\r\n\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\r\n\t\tpublic CBenchRandomGenerator() { }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit() { return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\r\n\t\tint GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\tRG.Init();\r\n\t\t\tRep0 = 1;\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint len;\r\n\t\t\t\t\tif (RG.GetRnd(3) == 0)\r\n\t\t\t\t\t\tlen = 1 + GetLen1();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdo\r\n\t\t\t\t\t\t\tRep0 = GetOffset();\r\n\t\t\t\t\t\twhile (Rep0 >= Pos);\r\n\t\t\t\t\t\tRep0++;\r\n\t\t\t\t\t\tlen = 2 + GetLen2();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, long elapsedTime, long size)\r\n\t{\r\n\t\tlong t = GetLogSize(dictionarySize) - (18 << kSubBits);\r\n\t\tlong numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime, long outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 220 + outSize * 20;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 18))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 18 (256 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/Methods.txt",
    "content": "7-Zip method IDs (4.65)\r\n-----------------------\r\n\r\nEach compression or crypto method in 7z has unique binary value (ID).\r\nThe length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).\r\n\r\nIf you want to add some new ID, you have two ways:\r\n1) Write request for allocating IDs to 7-zip developers.\r\n2) Generate 8-bytes ID:\r\n\r\n    3F ZZ ZZ ZZ ZZ ZZ MM MM \r\n\r\n    3F              - Prefix for random IDs (1 byte)\r\n    ZZ ZZ ZZ ZZ ZZ  - Developer ID (5 bytes). Use real random bytes. \r\n                      \r\n    MM MM           - Method ID (2 bytes)\r\n\r\n    You can notify 7-Zip developers about your Developer ID / Method ID.\r\n\r\n    Note: Use new ID only if old codec can not decode data encoded with new version.\r\n\r\n\r\nList of defined IDs\r\n-------------------\r\n      \r\n00 - Copy\r\n\r\n02 - Common\r\n   03 Swap\r\n      - 2 Swap2\r\n      - 4 Swap4\r\n\r\n03 - 7z\r\n   01 - LZMA\r\n      01 - Version\r\n  \r\n   03 - Branch\r\n      01 - x86\r\n         03  - BCJ\r\n         1B  - BCJ2\r\n      02 - PPC\r\n         05 - PPC (Big Endian)\r\n      03 - Alpha\r\n         01 - Alpha\r\n      04 - IA64\r\n         01 - IA64\r\n      05 - ARM\r\n         01 - ARM\r\n      06 - M68\r\n         05 - M68 (Big Endian)\r\n      07 - ARM Thumb\r\n         01 - ARMT\r\n      08 - SPARC\r\n         05 - SPARC\r\n\r\n   04 - PPMD\r\n      01 - Version\r\n\r\n   7F -\r\n      01 - experimental methods.\r\n\r\n\r\n04 - Misc\r\n   00 - Reserved\r\n   01 - Zip\r\n      00 - Copy (not used). Use {00} instead\r\n      01 - Shrink\r\n      06 - Implode\r\n      08 - Deflate\r\n      09 - Deflate64\r\n      12 - BZip2 (not used). Use {04 02 02} instead\r\n   02 - BZip\r\n      02 - BZip2\r\n   03 - Rar\r\n      01 - Rar15\r\n      02 - Rar20\r\n      03 - Rar29\r\n   04 - Arj\r\n      01 - Arj (1,2,3)\r\n      02 - Arj 4\r\n   05 - Z\r\n   06 - Lzh\r\n   07 - Reserved for 7z\r\n   08 - Cab\r\n   09 - NSIS\r\n      01 - DeflateNSIS\r\n      02 - BZip2NSIS\r\n\r\n\r\n06 - Crypto \r\n   00 - \r\n   01 - AES\r\n      0x - AES-128\r\n      4x - AES-192\r\n      8x - AES-256\r\n      Cx - AES\r\n\r\n      x0 - ECB\r\n      x1 - CBC\r\n      x2 - CFB\r\n      x3 - OFB\r\n\r\n   07 - Reserved\r\n   0F - Reserved\r\n\r\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\r\n\r\n   F1 - Misc Ciphers (Combine)\r\n      01 - Zip\r\n         01 - Main Zip crypto algo\r\n      03 - RAR\r\n         02 - \r\n         03 - Rar29 AES-128 + (modified SHA-1)\r\n      07 - 7z\r\n         01 - AES-256 + SHA-256\r\n\r\n07 - Hash (subject to change)\r\n   00 - \r\n   01 - CRC\r\n   02 - SHA-1\r\n   03 - SHA-256\r\n   04 - SHA-384\r\n   05 - SHA-512\r\n\r\n   F0 - Misc Hash\r\n\r\n   F1 - Misc\r\n      03 - RAR\r\n         03 - Rar29 Password Hashing (modified SHA1)\r\n      07 - 7z \r\n         01 - SHA-256 Password Hashing\r\n    \r\n   \r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/history.txt",
    "content": "HISTORY of the LZMA SDK\r\n-----------------------\r\n\r\n4.65           2009-02-03\r\n-------------------------\r\n- Some minor fixes\r\n\r\n\r\n4.63           2008-12-31\r\n-------------------------\r\n- Some minor fixes\r\n\r\n\r\n4.61 beta      2008-11-23\r\n-------------------------\r\n- The bug in ANSI-C LZMA Decoder was fixed:\r\n    If encoded stream was corrupted, decoder could access memory \r\n    outside of allocated range.\r\n- Some changes in ANSI-C 7z Decoder interfaces.\r\n- LZMA SDK is placed in the public domain.\r\n\r\n\r\n4.60 beta      2008-08-19\r\n-------------------------\r\n- Some minor fixes.\r\n\r\n\r\n4.59 beta      2008-08-13\r\n-------------------------\r\n- The bug was fixed:\r\n    LZMA Encoder in fast compression mode could access memory outside of \r\n    allocated range in some rare cases.\r\n\r\n\r\n4.58 beta      2008-05-05\r\n-------------------------\r\n- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r\n- ANSI-C LZMA Encoder was included to LZMA SDK.\r\n- C++ LZMA code now is just wrapper over ANSI-C code.\r\n\r\n\r\n4.57           2007-12-12\r\n-------------------------\r\n- Speed optimizations in ++ LZMA Decoder. \r\n- Small changes for more compatibility with some C/C++ compilers.\r\n\r\n\r\n4.49 beta      2007-07-05\r\n-------------------------\r\n- .7z ANSI-C Decoder:\r\n     - now it supports BCJ and BCJ2 filters\r\n     - now it supports files larger than 4 GB.\r\n     - now it supports \"Last Write Time\" field for files.\r\n- C++ code for .7z archives compressing/decompressing from 7-zip \r\n  was included to LZMA SDK.\r\n  \r\n\r\n4.43           2006-06-04\r\n-------------------------\r\n- Small changes for more compatibility with some C/C++ compilers.\r\n  \r\n\r\n4.42           2006-05-15\r\n-------------------------\r\n- Small changes in .h files in ANSI-C version.\r\n  \r\n\r\n4.39 beta      2006-04-14\r\n-------------------------\r\n- The bug in versions 4.33b:4.38b was fixed:\r\n  C++ version of LZMA encoder could not correctly compress \r\n  files larger than 2 GB with HC4 match finder (-mfhc4).\r\n  \r\n\r\n4.37 beta      2005-04-06\r\n-------------------------\r\n- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r\n\r\n\r\n4.35 beta      2005-03-02\r\n-------------------------\r\n- The bug was fixed in C++ version of LZMA Decoder:\r\n    If encoded stream was corrupted, decoder could access memory \r\n    outside of allocated range.\r\n\r\n\r\n4.34 beta      2006-02-27\r\n-------------------------\r\n- Compressing speed and memory requirements for compressing were increased\r\n- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r\n\r\n\r\n4.32           2005-12-09\r\n-------------------------\r\n- Java version of LZMA SDK was included\r\n\r\n\r\n4.30           2005-11-20\r\n-------------------------\r\n- Compression ratio was improved in -a2 mode\r\n- Speed optimizations for compressing in -a2 mode\r\n- -fb switch now supports values up to 273\r\n- The bug in 7z_C (7zIn.c) was fixed:\r\n  It used Alloc/Free functions from different memory pools.\r\n  So if program used two memory pools, it worked incorrectly.\r\n- 7z_C: .7z format supporting was improved\r\n- LZMA# SDK (C#.NET version) was included\r\n\r\n\r\n4.27 (Updated) 2005-09-21\r\n-------------------------\r\n- Some GUIDs/interfaces in C++ were changed.\r\n IStream.h:\r\n   ISequentialInStream::Read now works as old ReadPart\r\n   ISequentialOutStream::Write now works as old WritePart\r\n\r\n\r\n4.27           2005-08-07\r\n-------------------------\r\n- The bug in LzmaDecodeSize.c was fixed:\r\n   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r\n   decompressing worked incorrectly.\r\n\r\n\r\n4.26           2005-08-05\r\n-------------------------\r\n- Fixes in 7z_C code and LzmaTest.c:\r\n  previous versions could work incorrectly,\r\n  if malloc(0) returns 0\r\n\r\n\r\n4.23           2005-06-29\r\n-------------------------\r\n- Small fixes in C++ code\r\n\r\n\r\n4.22           2005-06-10\r\n-------------------------\r\n- Small fixes\r\n\r\n\r\n4.21           2005-06-08\r\n-------------------------\r\n- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r\n- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r\n    - LzmaStateDecode.h\r\n    - LzmaStateDecode.c\r\n    - LzmaStateTest.c\r\n- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r\n\r\n\r\n4.17           2005-04-18\r\n-------------------------\r\n- New example for RAM->RAM compressing/decompressing: \r\n  LZMA + BCJ (filter for x86 code):\r\n    - LzmaRam.h\r\n    - LzmaRam.cpp\r\n    - LzmaRamDecode.h\r\n    - LzmaRamDecode.c\r\n    - -f86 switch for lzma.exe\r\n\r\n\r\n4.16           2005-03-29\r\n-------------------------\r\n- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r\n   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r\n   decoder could access memory outside of allocated range.\r\n- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r\n  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r\n  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r\n- Small speed optimization in LZMA C++ code\r\n- filter for SPARC's code was added\r\n- Simplified version of .7z ANSI-C Decoder was included\r\n\r\n\r\n4.06           2004-09-05\r\n-------------------------\r\n- The bug in v4.05 was fixed:\r\n    LZMA-Encoder didn't release output stream in some cases.\r\n\r\n\r\n4.05           2004-08-25\r\n-------------------------\r\n- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r\n  and PowerPC code was included to SDK\r\n- Some internal minor changes\r\n\r\n\r\n4.04           2004-07-28\r\n-------------------------\r\n- More compatibility with some C++ compilers\r\n\r\n\r\n4.03           2004-06-18\r\n-------------------------\r\n- \"Benchmark\" command was added. It measures compressing \r\n  and decompressing speed and shows rating values. \r\n  Also it checks hardware errors.\r\n\r\n\r\n4.02           2004-06-10\r\n-------------------------\r\n- C++ LZMA Encoder/Decoder code now is more portable\r\n  and it can be compiled by GCC on Linux.\r\n\r\n\r\n4.01           2004-02-15\r\n-------------------------\r\n- Some detection of data corruption was enabled.\r\n    LzmaDecode.c / RangeDecoderReadByte\r\n    .....\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n\r\n\r\n4.00           2004-02-13\r\n-------------------------\r\n- Original version of LZMA SDK\r\n\r\n\r\n\r\nHISTORY of the LZMA\r\n-------------------\r\n  2001-2008:  Improvements to LZMA compressing/decompressing code, \r\n              keeping compatibility with original LZMA format\r\n  1996-2001:  Development of LZMA compression format\r\n\r\n  Some milestones:\r\n\r\n  2001-08-30: LZMA compression was added to 7-Zip\r\n  1999-01-02: First version of 7-Zip was released\r\n  \r\n\r\nEnd of document\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma/lzma.txt",
    "content": "LZMA SDK 4.65\r\n-------------\r\n\r\nLZMA SDK provides the documentation, samples, header files, libraries, \r\nand tools you need to develop applications that use LZMA compression.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\nLZMA is an improved version of famous LZ77 compression algorithm. \r\nIt was improved in way of maximum increasing of compression ratio,\r\nkeeping high decompression speed and low memory requirements for \r\ndecompressing.\r\n\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\r\n\r\n\r\nLZMA SDK Contents\r\n-----------------\r\n\r\nLZMA SDK includes:\r\n\r\n  - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing\r\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\r\n\r\n\r\nUNIX/Linux version \r\n------------------\r\nTo compile C++ version of file->file LZMA encoding, go to directory\r\nC++/7zip/Compress/LZMA_Alone \r\nand call make to recompile it:\r\n  make -f makefile.gcc clean all\r\n\r\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\r\nTo compile with static libraries, you can use \r\nLIB = -lm -static\r\n\r\n\r\nFiles\r\n---------------------\r\nlzma.txt     - LZMA SDK description (this file)\r\n7zFormat.txt - 7z Format description\r\n7zC.txt      - 7z ANSI-C Decoder description\r\nmethods.txt  - Compression method IDs for .7z\r\nlzma.exe     - Compiled file->file LZMA encoder/decoder for Windows\r\nhistory.txt  - history of the LZMA SDK\r\n\r\n\r\nSource code structure\r\n---------------------\r\n\r\nC/  - C files\r\n        7zCrc*.*   - CRC code\r\n        Alloc.*    - Memory allocation functions\r\n        Bra*.*     - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n        LzFind.*   - Match finder for LZ (LZMA) encoders \r\n        LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding\r\n        LzHash.h   - Additional file for LZ match finder\r\n        LzmaDec.*  - LZMA decoding\r\n        LzmaEnc.*  - LZMA encoding\r\n        LzmaLib.*  - LZMA Library for DLL calling\r\n        Types.h    - Basic types for another .c files\r\n\tThreads.*  - The code for multithreading.\r\n\r\n    LzmaLib  - LZMA Library (.DLL for Windows)\r\n    \r\n    LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).\r\n\r\n    Archive - files related to archiving\r\n      7z     - 7z ANSI-C Decoder\r\n\r\nCPP/ -- CPP files\r\n\r\n  Common  - common files for C++ projects\r\n  Windows - common files for Windows related code\r\n\r\n  7zip    - files related to 7-Zip Project\r\n\r\n    Common   - common files for 7-Zip\r\n\r\n    Compress - files related to compression/decompression\r\n\r\n      Copy         - Copy coder\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n      LZMA         - LZMA compression/decompression on C++\r\n      LZMA_Alone   - file->file LZMA compression/decompression\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n\r\n    Archive - files related to archiving\r\n\r\n      Common   - common files for archive handling\r\n      7z       - 7z C++ Encoder/Decoder\r\n\r\n    Bundles    - Modules that are bundles of other modules\r\n  \r\n      Alone7z           - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2\r\n      Format7zR         - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r\n      Format7zExtractR  - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.\r\n\r\n    UI        - User Interface files\r\n         \r\n      Client7z - Test application for 7za.dll,  7zr.dll, 7zxr.dll\r\n      Common   - Common UI files\r\n      Console  - Code for console archiver\r\n\r\n\r\n\r\nCS/ - C# files\r\n  7zip\r\n    Common   - some common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      LzmaAlone    - file->file LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nJava/  - Java files\r\n  SevenZip\r\n    Compression    - files related to compression/decompression\r\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\n\r\nC/C++ source code of LZMA SDK is part of 7-Zip project.\r\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r\n\r\n  http://sourceforge.net/projects/sevenzip/\r\n\r\n\r\n\r\nLZMA features\r\n-------------\r\n  - Variable dictionary size (up to 1 GB)\r\n  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r\n  - Estimated decompressing speed: \r\n      - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64\r\n      - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC\r\n  - Small memory requirements for decompressing (16 KB + DictionarySize)\r\n  - Small code size for decompressing: 5-8 KB\r\n\r\nLZMA decoder uses only integer operations and can be \r\nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r\n\r\nSome critical operations that affect the speed of LZMA decompression:\r\n  1) 32*16 bit integer multiply\r\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\r\n  3) 32-bit shift and arithmetic operations\r\n\r\nThe speed of LZMA decompressing mostly depends from CPU speed.\r\nMemory speed has no big meaning. But if your CPU has small data cache, \r\noverall weight of memory speed will slightly increase.\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nUsing LZMA encoder/decoder executable\r\n--------------------------------------\r\n\r\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\r\n\r\n  e: encode file\r\n\r\n  d: decode file\r\n\r\n  b: Benchmark. There are two tests: compressing and decompressing \r\n     with LZMA method. Benchmark shows rating in MIPS (million \r\n     instructions per second). Rating value is calculated from \r\n     measured speed and it is normalized with Intel's Core 2 results.\r\n     Also Benchmark checks possible hardware errors (RAM \r\n     errors in most cases). Benchmark uses these settings:\r\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r\n     Also you can change the number of iterations. Example for 30 iterations:\r\n       LZMA b 30\r\n     Default number of iterations is 10.\r\n\r\n<Switches>\r\n  \r\n\r\n  -a{N}:  set compression mode 0 = fast, 1 = normal\r\n          default: 1 (normal)\r\n\r\n  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r\n          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \r\n          For decompressing file compressed by LZMA method with dictionary \r\n          size D = 2^N you need about D bytes of memory (RAM).\r\n\r\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\r\n          Usually big number gives a little bit better compression ratio \r\n          and slower compression process.\r\n\r\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\r\n          Sometimes lc=4 gives gain for big files.\r\n\r\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r\n          lp switch is intended for periodical data when period is \r\n          equal 2^N. For example, for 32-bit (4 bytes) \r\n          periodical data you can use lp=2. Often it's better to set lc0, \r\n          if you change lp switch.\r\n\r\n  -pb{N}: set number of pos bits - [0, 4], default: 2\r\n          pb switch is intended for periodical data \r\n          when period is equal 2^N.\r\n\r\n  -mf{MF_ID}: set Match Finder. Default: bt4. \r\n              Algorithms from hc* group doesn't provide good compression \r\n              ratio, but they often works pretty fast in combination with \r\n              fast mode (-a0).\r\n\r\n              Memory requirements depend from dictionary size \r\n              (parameter \"d\" in table below). \r\n\r\n               MF_ID     Memory                   Description\r\n\r\n                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r\n                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r\n                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r\n                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r\n\r\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \r\n          eos marker, since LZMA decoder knows uncompressed size \r\n          stored in .lzma file header.\r\n\r\n  -si:    Read data from stdin (it will write End Of Stream marker).\r\n  -so:    Write data to stdout\r\n\r\n\r\nExamples:\r\n\r\n1) LZMA e file.bin file.lzma -d16 -lc0 \r\n\r\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r\nand 0 literal context bits. -lc0 allows to reduce memory requirements \r\nfor decompression.\r\n\r\n\r\n2) LZMA e file.bin file.lzma -lc0 -lp2\r\n\r\ncompresses file.bin to file.lzma with settings suitable \r\nfor 32-bit periodical data (for example, ARM or MIPS code).\r\n\r\n3) LZMA d file.lzma file.bin\r\n\r\ndecompresses file.lzma to file.bin.\r\n\r\n\r\nCompression ratio hints\r\n-----------------------\r\n\r\nRecommendations\r\n---------------\r\n\r\nTo increase the compression ratio for LZMA compressing it's desirable \r\nto have aligned data (if it's possible) and also it's desirable to locate\r\ndata in such order, where code is grouped in one place and data is \r\ngrouped in other place (it's better than such mixing: code, data, code,\r\ndata, ...).\r\n\r\n\r\nFilters\r\n-------\r\nYou can increase the compression ratio for some data types, using\r\nspecial filters before compressing. For example, it's possible to \r\nincrease the compression ratio on 5-10% for code for those CPU ISAs: \r\nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r\n\r\nYou can find C source code of such filters in C/Bra*.* files\r\n\r\nYou can check the compression ratio gain of these filters with such \r\n7-Zip commands (example for ARM code):\r\nNo filter:\r\n  7z a a1.7z a.bin -m0=lzma\r\n\r\nWith filter for little-endian ARM code:\r\n  7z a a2.7z a.bin -m0=arm -m1=lzma        \r\n\r\nIt works in such manner:\r\nCompressing    = Filter_encoding + LZMA_encoding\r\nDecompressing  = LZMA_decoding + Filter_decoding\r\n\r\nCompressing and decompressing speed of such filters is very high,\r\nso it will not increase decompressing time too much.\r\nMoreover, it reduces decompression time for LZMA_decoding, \r\nsince compression ratio with filtering is higher.\r\n\r\nThese filters convert CALL (calling procedure) instructions \r\nfrom relative offsets to absolute addresses, so such data becomes more \r\ncompressible.\r\n\r\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r\n\r\n\r\nLZMA compressed file format\r\n---------------------------\r\nOffset Size Description\r\n  0     1   Special LZMA properties (lc,lp, pb in encoded form)\r\n  1     4   Dictionary size (little endian)\r\n  5     8   Uncompressed size (little endian). -1 means unknown size\r\n 13         Compressed data\r\n\r\n\r\nANSI-C LZMA Decoder\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nPlease note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.\r\nIf you want to use old interfaces you can download previous version of LZMA SDK\r\nfrom sourceforge.net site.\r\n\r\nTo use ANSI-C LZMA Decoder you need the following files:\r\n1) LzmaDec.h + LzmaDec.c + Types.h\r\nLzmaUtil/LzmaUtil.c is example application that uses these files.\r\n\r\n\r\nMemory requirements for LZMA decoding\r\n-------------------------------------\r\n\r\nStack usage of LZMA decoding function for local variables is not \r\nlarger than 200-400 bytes.\r\n\r\nLZMA Decoder uses dictionary buffer and internal state structure.\r\nInternal state structure consumes\r\n  state_size = (4 + (1.5 << (lc + lp))) KB\r\nby default (lc=3, lp=0), state_size = 16 KB.\r\n\r\n\r\nHow To decompress data\r\n----------------------\r\n\r\nLZMA Decoder (ANSI-C version) now supports 2 interfaces:\r\n1) Single-call Decompressing\r\n2) Multi-call State Decompressing (zlib-like interface)\r\n\r\nYou must use external allocator:\r\nExample:\r\nvoid *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\r\nvoid SzFree(void *p, void *address) { p = p; free(address); }\r\nISzAlloc alloc = { SzAlloc, SzFree };\r\n\r\nYou can use p = p; operator to disable compiler warnings.\r\n\r\n\r\nSingle-call Decompressing\r\n-------------------------\r\nWhen to use: RAM->RAM decompressing\r\nCompile files: LzmaDec.h + LzmaDec.c + Types.h\r\nCompile defines: no defines\r\nMemory Requirements:\r\n  - Input buffer: compressed size\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures: state_size (16 KB for default settings) \r\n\r\nInterface:\r\n  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r\n      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, \r\n      ELzmaStatus *status, ISzAlloc *alloc);\r\n  In: \r\n    dest     - output data\r\n    destLen  - output data size\r\n    src      - input data\r\n    srcLen   - input data size\r\n    propData - LZMA properties  (5 bytes)\r\n    propSize - size of propData buffer (5 bytes)\r\n    finishMode - It has meaning only if the decoding reaches output limit (*destLen).\r\n\t LZMA_FINISH_ANY - Decode just destLen bytes.\r\n\t LZMA_FINISH_END - Stream must be finished after (*destLen).\r\n                           You can use LZMA_FINISH_END, when you know that \r\n                           current output buffer covers last bytes of stream. \r\n    alloc    - Memory allocator.\r\n\r\n  Out: \r\n    destLen  - processed output size \r\n    srcLen   - processed input size \r\n\r\n  Output:\r\n    SZ_OK\r\n      status:\r\n        LZMA_STATUS_FINISHED_WITH_MARK\r\n        LZMA_STATUS_NOT_FINISHED \r\n        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r\n    SZ_ERROR_DATA - Data error\r\n    SZ_ERROR_MEM  - Memory allocation error\r\n    SZ_ERROR_UNSUPPORTED - Unsupported properties\r\n    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r\n\r\n  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,\r\n  and output value of destLen will be less than output buffer size limit.\r\n\r\n  You can use multiple checks to test data integrity after full decompression:\r\n    1) Check Result and \"status\" variable.\r\n    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r\n    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. \r\n       You must use correct finish mode in that case. */ \r\n\r\n\r\nMulti-call State Decompressing (zlib-like interface)\r\n----------------------------------------------------\r\n\r\nWhen to use: file->file decompressing \r\nCompile files: LzmaDec.h + LzmaDec.c + Types.h\r\n\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures: state_size (16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in LZMA properties header)\r\n\r\n1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:\r\n   unsigned char header[LZMA_PROPS_SIZE + 8];\r\n   ReadFile(inFile, header, sizeof(header)\r\n\r\n2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties\r\n\r\n  CLzmaDec state;\r\n  LzmaDec_Constr(&state);\r\n  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);\r\n  if (res != SZ_OK)\r\n    return res;\r\n\r\n3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop\r\n\r\n  LzmaDec_Init(&state);\r\n  for (;;)\r\n  {\r\n    ... \r\n    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, \r\n    \tconst Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);\r\n    ...\r\n  }\r\n\r\n\r\n4) Free all allocated structures\r\n  LzmaDec_Free(&state, &g_Alloc);\r\n\r\nFor full code example, look at C/LzmaUtil/LzmaUtil.c code.\r\n\r\n\r\nHow To compress data\r\n--------------------\r\n\r\nCompile files: LzmaEnc.h + LzmaEnc.c + Types.h +\r\nLzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h\r\n\r\nMemory Requirements:\r\n  - (dictSize * 11.5 + 6 MB) + state_size\r\n\r\nLzma Encoder can use two memory allocators:\r\n1) alloc - for small arrays.\r\n2) allocBig - for big arrays.\r\n\r\nFor example, you can use Large RAM Pages (2 MB) in allocBig allocator for \r\nbetter compression speed. Note that Windows has bad implementation for \r\nLarge RAM Pages. \r\nIt's OK to use same allocator for alloc and allocBig.\r\n\r\n\r\nSingle-call Compression with callbacks\r\n--------------------------------------\r\n\r\nCheck C/LzmaUtil/LzmaUtil.c as example, \r\n\r\nWhen to use: file->file decompressing \r\n\r\n1) you must implement callback structures for interfaces:\r\nISeqInStream\r\nISeqOutStream\r\nICompressProgress\r\nISzAlloc\r\n\r\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r\nstatic void SzFree(void *p, void *address) {  p = p; MyFree(address); }\r\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\r\n\r\n  CFileSeqInStream inStream;\r\n  CFileSeqOutStream outStream;\r\n\r\n  inStream.funcTable.Read = MyRead;\r\n  inStream.file = inFile;\r\n  outStream.funcTable.Write = MyWrite;\r\n  outStream.file = outFile;\r\n\r\n\r\n2) Create CLzmaEncHandle object;\r\n\r\n  CLzmaEncHandle enc;\r\n\r\n  enc = LzmaEnc_Create(&g_Alloc);\r\n  if (enc == 0)\r\n    return SZ_ERROR_MEM;\r\n\r\n\r\n3) initialize CLzmaEncProps properties;\r\n\r\n  LzmaEncProps_Init(&props);\r\n\r\n  Then you can change some properties in that structure.\r\n\r\n4) Send LZMA properties to LZMA Encoder\r\n\r\n  res = LzmaEnc_SetProps(enc, &props);\r\n\r\n5) Write encoded properties to header\r\n\r\n    Byte header[LZMA_PROPS_SIZE + 8];\r\n    size_t headerSize = LZMA_PROPS_SIZE;\r\n    UInt64 fileSize;\r\n    int i;\r\n\r\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r\n    fileSize = MyGetFileLength(inFile);\r\n    for (i = 0; i < 8; i++)\r\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r\n    MyWriteFileAndCheck(outFile, header, headerSize)\r\n\r\n6) Call encoding function:\r\n      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, \r\n        NULL, &g_Alloc, &g_Alloc);\r\n\r\n7) Destroy LZMA Encoder Object\r\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r\n\r\n\r\nIf callback function return some error code, LzmaEnc_Encode also returns that code.\r\n\r\n\r\nSingle-call RAM->RAM Compression\r\n--------------------------------\r\n\r\nSingle-call RAM->RAM Compression is similar to Compression with callbacks,\r\nbut you provide pointers to buffers instead of pointers to stream callbacks:\r\n\r\nHRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r\n    CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, \r\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r\n\r\nReturn code:\r\n  SZ_OK               - OK\r\n  SZ_ERROR_MEM        - Memory allocation error \r\n  SZ_ERROR_PARAM      - Incorrect paramater\r\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.\r\n\r\n_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for \r\n                 some structures will be doubled in that case.\r\n\r\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.\r\n\r\n_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.\r\n\r\n\r\nC++ LZMA Encoder/Decoder \r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nC++ LZMA code use COM-like interfaces. So if you want to use it, \r\nyou can study basics of COM/OLE.\r\nC++ LZMA code is just wrapper over ANSI-C code.\r\n\r\n\r\nC++ Notes\r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nIf you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),\r\nyou must check that you correctly work with \"new\" operator.\r\n7-Zip can be compiled with MSVC 6.0 that doesn't throw \"exception\" from \"new\" operator.\r\nSo 7-Zip uses \"CPP\\Common\\NewHandler.cpp\" that redefines \"new\" operator:\r\noperator new(size_t size)\r\n{\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\nIf you use MSCV that throws exception for \"new\" operator, you can compile without \r\n\"NewHandler.cpp\". So standard exception will be used. Actually some code of \r\n7-Zip catches any exception in internal code and converts it to HRESULT code.\r\nSo you don't need to catch CNewException, if you call COM interfaces of 7-Zip.\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/sdk.html\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/lzma_wrapper.c",
    "content": "/*\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * lzma_wrapper.c\n */\n\n#include <LzmaLib.h>\n\n#define LZMA_HEADER_SIZE\t(LZMA_PROPS_SIZE + 8)\n\nint lzma_compress(void **strm, char *dest, char *src,  int size,int block_size,\n\t\tint *error)\n{\n\tunsigned char *d = (unsigned char *) dest, *s = (unsigned char *) src;\n\tsize_t props_size = LZMA_PROPS_SIZE,\n\t\toutlen = block_size - LZMA_HEADER_SIZE;\n\tint res;\n\n\tres = LzmaCompress(d + LZMA_HEADER_SIZE, &outlen, s, size, d,\n\t\t&props_size, 5, block_size, 3, 0, 2, 32, 1);\n\t\n\tif(res == SZ_ERROR_OUTPUT_EOF) {\n\t\t/*\n\t\t * Output buffer overflow.  Return out of buffer space error\n\t\t */\n\t\treturn 0;\n\t}\n\n\tif(res != SZ_OK) {\n\t\t/*\n\t\t * All other errors return failure, with the compressor\n\t\t * specific error code in *error\n\t\t */\n\t\t*error = res;\n\t\treturn -1;\n\t}\n\n\t/*\n\t * Fill in the 8 byte little endian uncompressed size field in the\n\t * LZMA header.  8 bytes is excessively large for squashfs but\n\t * this is the standard LZMA header and which is expected by the kernel\n\t * code\n\t */\n\td[LZMA_PROPS_SIZE] = size & 255;\n\td[LZMA_PROPS_SIZE + 1] = (size >> 8) & 255;\n\td[LZMA_PROPS_SIZE + 2] = (size >> 16) & 255;\n\td[LZMA_PROPS_SIZE + 3] = (size >> 24) & 255;\n\td[LZMA_PROPS_SIZE + 4] = 0;\n\td[LZMA_PROPS_SIZE + 5] = 0;\n\td[LZMA_PROPS_SIZE + 6] = 0;\n\td[LZMA_PROPS_SIZE + 7] = 0;\n\n\t/*\n\t * Success, return the compressed size.  Outlen returned by the LZMA\n\t * compressor does not include the LZMA header space\n\t */\n\treturn outlen + LZMA_HEADER_SIZE;\n}\n\n\nint lzma_uncompress(char *dest, char *src, int size, int block_size,\n\tint *error)\n{\n\tunsigned char *d = (unsigned char *) dest, *s = (unsigned char *) src;\n\tsize_t outlen, inlen = size - LZMA_HEADER_SIZE;\n\tint res;\n\n\toutlen = s[LZMA_PROPS_SIZE] |\n\t\t(s[LZMA_PROPS_SIZE + 1] << 8) |\n\t\t(s[LZMA_PROPS_SIZE + 2] << 16) |\n\t\t(s[LZMA_PROPS_SIZE + 3] << 24);\n\n\tres = LzmaUncompress(d, &outlen, s + LZMA_HEADER_SIZE, &inlen,\n\t\ts, LZMA_PROPS_SIZE);\n\t\n\t*error = res;\n\treturn res == SZ_OK ? outlen : -1;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/time.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n#include <regex.h>\n#include <fnmatch.h>\n#include <sys/wait.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n#include \"pseudo.h\"\n#include \"compressor.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tprintf(\"\\n\"); \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\n/* offset of data in compressed metadata blocks (allowing room for\n * compressed size */\n#define BLOCK_OFFSET 2\nint delete = FALSE;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0;\nint silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\nint progress_enabled = FALSE;\nint sparse_files = TRUE;\nint old_exclude = TRUE;\nint use_regex = FALSE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned int id_count = 0;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0,\n\tsock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* exclude file handling */\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint old_excluded(char *filename, struct stat *buf);\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nstruct pathnames *paths = NULL;\nstruct pathname *path = NULL;\nstruct pathname *stickypath = NULL;\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\n\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n\n#define FRAG_SIZE 32768\n#define FRAG_INDEX (1LL << 32)\n\nsquashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\t*name;\n\tstruct inode_info\tinode;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is\n * cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache, *sdirectory_compressed;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, sdirectory_compressed_bytes,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* recovery file for abnormal exit on appending */\nchar recovery_file[1024] = \"\";\nint recover = TRUE;\n\n/* struct describing a cache entry passed between threads */\nstruct file_buffer {\n\tstruct cache *cache;\n\tint keep;\n\tlong long file_size;\n\tlong long index;\n\tlong long block;\n\tlong long sequence;\n\tint size;\n\tint c_byte;\n\tint used;\n\tint\tfragment;\n\tint error;\n\tstruct file_buffer *hash_next;\n\tstruct file_buffer *hash_prev;\n\tstruct file_buffer *free_next;\n\tstruct file_buffer *free_prev;\n\tstruct file_buffer *next;\n\tchar data[0];\n};\n\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n\n/* in memory uid tables */\n#define ID_ENTRIES 256\n#define ID_HASH(id) (id & (ID_ENTRIES - 1))\n#define ISA_UID 1\n#define ISA_GID 2\nstruct id {\n\tunsigned int id;\n\tint\tindex;\n\tchar\tflags;\n\tstruct id *next;\n};\nstruct id *id_hash_table[ID_ENTRIES];\nstruct id *id_table[SQUASHFS_IDS], *sid_table[SQUASHFS_IDS];\nunsigned int uid_count = 0, guid_count = 0;\nunsigned int sid_count = 0, suid_count = 0, sguid_count = 0;\n\nstruct cache *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate,\n\t*to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread, progress_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\npthread_mutex_t progress_mutex;\npthread_cond_t progress_wait;\nint rotate = 0;\nstruct pseudo *pseudo = NULL;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 64\nint writer_buffer_size;\nint reader_buffer_size;\nint fragment_buffer_size;\n\n/* compression operations structure */\nstatic struct compressor *comp;\nchar *comp_name = COMP_DEFAULT;\n\nchar *read_from_disk(long long start, unsigned int avail_bytes);\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type);\nextern struct compressor  *read_super(int fd, squashfs_super_block *sBlk,\n\tchar *source);\nextern long long read_filesystem(char *root_name, int fd,\n\tsquashfs_super_block *sBlk, char **cinode_table, char **data_cache,\n\tchar **cdirectory_table, char **directory_data_cache,\n\tunsigned int *last_directory_block, unsigned int *inode_dir_offset,\n\tunsigned int *inode_dir_file_size, unsigned int *root_inode_size,\n\tunsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\tlong long *uncompressed_file, unsigned int *uncompressed_inode,\n\tunsigned int *uncompressed_directory,\n\tunsigned int *inode_dir_inode_number,\n\tunsigned int *inode_dir_parent_inode,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\tsquashfs_fragment_entry **fragment_table,\n\tsquashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *,\n\tchar *, struct dir_info *));\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo);\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info);\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag);\nextern void generate_file_priorities(struct dir_info *dir, int priority,\n\tstruct stat *buf);\nextern struct priority_entry *priority_list[65536];\nvoid progress_bar(long long current, long long max, int columns);\nlong long generic_write_table(int length, char *buffer, int uncompressed);\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tstruct file_buffer *free_list;\n\tstruct file_buffer *hash_table[65536];\n};\n\n\n#define INSERT_LIST(NAME, TYPE) \\\nvoid insert_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(*list) { \\\n\t\tentry->NAME##_next = *list; \\\n\t\tentry->NAME##_prev = (*list)->NAME##_prev; \\\n\t\t(*list)->NAME##_prev->NAME##_next = entry; \\\n\t\t(*list)->NAME##_prev = entry; \\\n\t} else { \\\n\t\t*list = entry; \\\n\t\tentry->NAME##_prev = entry->NAME##_next = entry; \\\n\t} \\\n}\n\n\n#define REMOVE_LIST(NAME, TYPE) \\\nvoid remove_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(entry->NAME##_prev == entry && entry->NAME##_next == entry) { \\\n\t\t/* only this entry in the list */ \\\n\t\t*list = NULL; \\\n\t} else if(entry->NAME##_prev != NULL && entry->NAME##_next != NULL) { \\\n\t\t/* more than one entry in the list */ \\\n\t\tentry->NAME##_next->NAME##_prev = entry->NAME##_prev; \\\n\t\tentry->NAME##_prev->NAME##_next = entry->NAME##_next; \\\n\t\tif(*list == entry) \\\n\t\t\t*list = entry->NAME##_next; \\\n\t} \\\n\tentry->NAME##_prev = entry->NAME##_next = NULL; \\\n}\n\n\n#define CALCULATE_HASH(start)\t(start & 0xffff) \\\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tint hash = CALCULATE_HASH(entry->index);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->index)] =\n\t\t\tentry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nINSERT_LIST(free, struct file_buffer)\n\n/* Called with the cache mutex held */\nREMOVE_LIST(free, struct file_buffer)\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\treturn NULL;\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct file_buffer *) * 65536);\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\n\treturn cache;\n}\n\n\nstruct file_buffer *cache_lookup(struct cache *cache, long long index)\n{\n\t/* Lookup block in the cache, if found return with usage count\n \t * incremented, if not found return NULL */\n\tint hash = CALCULATE_HASH(index);\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->index == index)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/* found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(&cache->free_list, entry);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n}\n\n\n#define GET_FREELIST 1\n\nstruct file_buffer *cache_get(struct cache *cache, long long index, int keep)\n{\n\t/* Get a free block out of the cache indexed on index. */\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\twhile(1) {\n\t\t/* first try to get a block from the free list */\n#ifdef GET_FREELIST\n\t\tif(cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t} else\n#endif\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\t/* next try to allocate new block */\n\t\t\tentry = malloc(sizeof(struct file_buffer) +\n\t\t\t\tcache->buffer_size);\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t\tbreak;\n\t\t} else\n#ifndef GET_FREELIST\n\t\tif(cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t}\n#endif\n\t\t\t/* wait for a block */\n\t\t\tpthread_cond_wait(&cache->wait_for_free, &cache->mutex);\n\t}\n\n\t/* initialise block and if a keep block insert into the hash table */\n\tentry->used = 1;\n\tentry->error = FALSE;\n\tentry->keep = keep;\n\tif(keep) {\n\t\tentry->index = index;\n\t\tinsert_hash_table(cache, entry);\n\t}\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\treturn NULL;\n}\n\n\nvoid cache_rehash(struct file_buffer *entry, long long index)\n{\n\tstruct cache *cache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\tif(entry->keep)\n\t\tremove_hash_table(cache, entry);\n\tentry->keep = TRUE;\n\tentry->index = index;\n\tinsert_hash_table(cache, entry);\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\nvoid cache_block_put(struct file_buffer *entry)\n{\n\tstruct cache *cache;\n\n\t/* finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and if a keep block put onto the free list.  As keep\n \t * blocks remain accessible via the hash table they can be found\n \t * getting a new lease of life before they are reused. */\n\n\tif(entry == NULL)\n\t\treturn;\n\n\tcache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tif(entry->keep)\n\t\t\tinsert_free_list(&cache->free_list, entry);\n\t\telse {\n\t\t\tfree(entry);\n\t\t\tcache->count --;\n\t\t}\n\n\t\t/* One or more threads may be waiting on this block */\n\t\tpthread_cond_signal(&cache->wait_for_free);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) \\\n\t\t\t+ (((char *)A) - data_cache)))\n\n\ninline void inc_progress_bar()\n{\n\tcur_uncompressed ++;\n}\n\n\ninline void update_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tif(thread[i])\n\t\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache,\n\t\tsdirectory_cache_bytes);\n\tdirectory_cache_bytes = sdirectory_cache_bytes;\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n \tmemcpy(directory_table + directory_bytes, sdirectory_compressed,\n\t\tsdirectory_compressed_bytes);\n \tdirectory_bytes += sdirectory_compressed_bytes;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tid_count = sid_count;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, &thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nint mangle2(void **strm, char *d, char *s, int size,\n\tint block_size, int uncompressed, int data_block)\n{\n\tint error, c_byte = 0;\n\n\tif(!uncompressed) {\n\t\tc_byte = comp->compress(strm, d, s, size, block_size, &error);\n\t\tif(c_byte == -1)\n\t\t\tBAD_ERROR(\"mangle2:: %s compress failed with error \"\n\t\t\t\t\"code %d\\n\", comp->name, error);\n\t}\n\n\tif(c_byte == 0 || c_byte >= size) {\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK :\n\t\t\tSQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn c_byte;\n}\n\n\nint mangle(char *d, char *s, int size, int block_size,\n\tint uncompressed, int data_block)\n{\n\tstatic void *stream = NULL;\n\n\treturn mangle2(&stream, d, s, size, block_size, uncompressed,\n\t\tdata_block);\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tinode_table = realloc(inode_table, inode_size +\n\t\t\t\t(SQUASHFS_METADATA_SIZE << 1) + 2);\n\t\t\tif(inode_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET,\n\t\t\tdata_cache, SQUASHFS_METADATA_SIZE,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\t(unsigned short *) (inode_table + inode_bytes), 1);\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE,\n\t\t\tcache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ?\n\t\t\t\t((req_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : req_size -\n\t\t\t\tdata_space;\n\n\t\t\tdata_cache = realloc(data_cache, cache_size +\n\t\t\t\trealloc_size);\n\t\t\tif(data_cache == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)\n\t\t(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nint read_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = read(fd, buff + count, bytes - count);\n\t\tif(res < 1) {\n\t\t\tif(res == 0)\n\t\t\t\tgoto bytes_read;\n\t\t\telse if(errno != EINTR) {\n\t\t\t\tERROR(\"Read failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t} else\n\t\t\t\tres = 0;\n\t\t}\n\t}\n\nbytes_read:\n\treturn count;\n}\n\n\nvoid read_destination(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_destination: reading from position 0x%llx, bytes %d\\n\",\n\t\tbyte, bytes);\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(read_bytes(fd, buff, bytes) < bytes)\n\t\tBAD_ERROR(\"Read on destination failed\\n\");\n\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nint write_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = write(fd, buff + count, bytes - count);\n\t\tif(res == -1) {\n\t\t\tif(errno != EINTR) {\n\t\t\t\tERROR(\"Write failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nvoid write_destination(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(interrupted < 2)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(fd, buff, bytes) == -1)\n\t\tBAD_ERROR(\"Write on destination failed\\n\");\n\t\n\tif(interrupted < 2)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tinode_table = realloc(inode_table, inode_size +\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2));\n\t\t\tif(inode_table == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET, datap,\n\t\t\tavail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\t(unsigned short *) (inode_table + inode_bytes), 1); \n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_destination(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tdirectory_table = realloc(directory_table,\n\t\t\t\tdirectory_size + ((SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2));\n\t\t\tif(directory_table == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\tBLOCK_OFFSET, directoryp, avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, (unsigned short *)\n\t\t\t(directory_table + directory_bytes), 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_destination(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_id_table()\n{\n\tunsigned int id_bytes = SQUASHFS_ID_BYTES(id_count);\n\tchar buffer[id_bytes];\n\tunsigned int *p = (unsigned int *) buffer;\n\tint i;\n\n\tTRACE(\"write_id_table: ids %d, id_bytes %d\\n\", id_count, id_bytes);\n\tfor(i = 0; i < id_count; i++, p++) {\n\t\tTRACE(\"write_id_table: id index %d, id %d\", i, id_table[i]->id);\n\t\tSQUASHFS_SWAP_INTS(&id_table[i]->id, p, 1);\n\t}\n\n\treturn generic_write_table(id_bytes, buffer, 1);\n}\n\n\nstruct id *get_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = id_hash_table[hash];\n\n\tfor(; entry; entry = entry->next)\n\t\tif(entry->id == id)\n\t\t\tbreak;\n\n\treturn entry;\n}\n\n\nstruct id *create_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = malloc(sizeof(struct id));\n\tif(entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in create_id\\n\");\n\tentry->id = id;\n\tentry->index = id_count ++;\n\tentry->flags = 0;\n\tentry->next = id_hash_table[hash];\n\tid_hash_table[hash] = entry;\n\tid_table[entry->index] = entry;\n\treturn entry;\n}\n\n\nunsigned int get_uid(unsigned int uid)\n{\n\tstruct id *entry = get_id(uid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of uids!\\n\");\n\t\tentry = create_id(uid);\n\t}\n\n\tif((entry->flags & ISA_UID) == 0) {\n\t\tentry->flags |= ISA_UID;\n\t\tuid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nunsigned int get_guid(unsigned int guid)\n{\n\tstruct id *entry = get_id(guid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of gids!\\n\");\n\t\tentry = create_id(guid);\n\t}\n\n\tif((entry->flags & ISA_GID) == 0) {\n\t\tentry->flags |= ISA_GID;\n\t\tguid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type,\n\tlong long byte_size, long long start_block, unsigned int offset,\n\tunsigned int *block_list, struct fragment *fragment,\n\tstruct directory *dir_in, unsigned int sparse)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE ||\n\t\ttype == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number :\n\t\tdir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((unsigned int) global_uid == -1 ?\n\t\tbuf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((unsigned int) global_gid == -1 ?\n\t\tbuf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\tTRACE(\"File inode, file_size %lld, start_block 0x%llx, blocks \"\n\t\t\t\"%d, fragment %d, offset %d, size %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset,\n\t\t\tfragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(sparse && sparse >= byte_size)\n\t\t\tsparse = byte_size - 1;\n\t\treg->sparse = sparse;\n\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\tTRACE(\"Long file inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"blocks %d, fragment %d, offset %d, size %d, nlink %d\"\n\t\t\t\"\\n\", byte_size, start_block, offset, fragment->index,\n\t\t\tfragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\n\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inodep);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index,\n\t\t\t\t(squashfs_dir_index *) p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name,\n\t\t\t\tindex[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size\n\t\t\t\t+ 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %lld, start_block \"\n\t\t\t\"0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir,\n\t\t\t(squashfs_dir_inode_header *) inode);\n\t\tTRACE(\"Directory inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"offset 0x%x, nlink %d\\n\", byte_size, start_block,\n\t\t\toffset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\t\tunsigned int major = major(buf->st_rdev);\n\t\tunsigned int minor = minor(buf->st_rdev);\n\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", major, filename,\n\t\t\t\tmajor & 0xfff);\n\t\t\tmajor &= 0xfff;\n\t\t}\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", minor, filename,\n\t\t\t\tminor & 0xfffff);\n\t\t\tminor &= 0xfffff;\n\t\t}\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (major << 8) | (minor & 0xff) |\n\t\t\t\t((minor & ~0xff) << 12);\n\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev,\n\t\t\t(squashfs_dev_inode_header *) inode);\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink,\n\t\t\t*inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty \"\n\t\t\t\t\"symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! \"\n\t\t\t\t\"Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inodep);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte,\n\t\t\tnlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc,\n\t\t\t(squashfs_ipc_inode_header *) inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type ==\n\t\t\tSQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type,\n\t\tbase->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan3_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name,\n\tint type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\"\n\t\t\t\"\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size +\n\t\t\tsizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tbuff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE);\n\t\tif(buff == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\"\n\t\t\t\t\"\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff +\n\t\t\tbuff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block ||\n\t\t\t((dir->entry_count_p != NULL) &&\n\t\t\t((dir->p + sizeof(squashfs_dir_entry) + size -\n\t\t\tdir->index_count_p) > SQUASHFS_METADATA_SIZE)) ||\n\t\t\t((long long) inode_number - dir->inode_number) > 32767\n\t\t\t|| ((long long) inode_number - dir->inode_number)\n\t\t\t< -32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size -\n\t\t\t\t\tdir->index_count_p) >\n\t\t\t\t\tSQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0) {\n\t\t\t\t\tdir->index = realloc(dir->index,\n\t\t\t\t\t\t(dir->i_count + I_COUNT_SIZE) *\n\t\t\t\t\t\tsizeof(struct cached_dir_index));\n\t\t\t\t\tif(dir->index == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in \"\n\t\t\t\t\t\t\t\"directory index table \"\n\t\t\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t\t}\n\t\t\t\tdir->index[dir->i_count].index.index =\n\t\t\t\t\tdir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) +\n\t\t\t\t\tsize;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header,\n\t\t\t\t(squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tSQUASHFS_SWAP_DIR_ENTRY(&idir, idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info,\n\tstruct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ?\n\t\t\t((dir_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tdirectory_data_cache = realloc(directory_data_cache,\n\t\t\tdirectory_cache_size + realloc_size);\n\t\tif(directory_data_cache == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header,\n\t\t\t(squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff,\n\t\t\tdir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count &&\n\t\t\t\tdir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block =\n\t\t\t\tdirectory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) <\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tdirectory_table = realloc(directory_table,\n\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2);\n\t\t\tif(directory_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\t\tBLOCK_OFFSET, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE,\n\t\t\t\tnoI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, (unsigned short *)\n\t\t\t(directory_table + directory_bytes), 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemcpy(directory_data_cache, directory_data_cache +\n\t\t\tSQUASHFS_METADATA_SIZE, directory_cache_bytes -\n\t\t\tSQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir)\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE,\n\t\t\tdir_size + 3, directory_block, directory_offset, NULL,\n\t\t\tNULL, dir, 0);\n\telse\n\t\tcreate_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE,\n\t\t\tdir_size + 3, directory_block, directory_offset, NULL,\n\t\t\tNULL, NULL, 0);\n\n#ifdef SQUASHFS_TRACE\n\t{\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header dirh;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((squashfs_dir_header *) dirp,\n\t\t\t\t&dirh);\n\t\t\tcount = dirh.count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\",\n\t\t\t\tdirh.start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(idirp, &idir);\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type \"\n\t\t\t\t\t\"%d\\n\", buffer, idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size +\t\t\t\t\t 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nstruct file_buffer *get_fragment(struct fragment *fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment;\n\tint size;\n\tlong long start_block;\n\tstruct file_buffer *buffer, *compressed_buffer;\n\n\tif(fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn NULL;\n\n\tbuffer = cache_lookup(fragment_buffer, fragment->index);\n\tif(buffer)\n\t\treturn buffer;\n\n\tcompressed_buffer = cache_lookup(writer_buffer, fragment->index +\n\t\tFRAG_INDEX);\n\n\tbuffer = cache_get(fragment_buffer, fragment->index, 1);\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\tstart_block = disk_fragment->start_block;\n\tpthread_mutex_unlock(&fragment_mutex);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint error, res;\n\t\tchar *data;\n\n\t\tif(compressed_buffer)\n\t\t\tdata = compressed_buffer->data;\n\t\telse\n\t\t\tdata = read_from_disk(start_block, size);\n\n\t\tres = comp->uncompress(buffer->data, data, size, block_size,\n\t\t\t&error);\n\t\tif(res == -1)\n\t\t\tBAD_ERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t} else if(compressed_buffer)\n\t\tmemcpy(buffer->data, compressed_buffer->data, size);\n\telse\n\t\tread_destination(fd, start_block, size, buffer->data);\n\n\tcache_block_put(compressed_buffer);\n\n\treturn buffer;\n}\n\n\nstruct frag_locked {\n\tstruct file_buffer *buffer;\n\tint c_byte;\n\tint fragment;\n\tstruct frag_locked *fragment_prev;\n\tstruct frag_locked *fragment_next;\n};\n\nint fragments_locked = FALSE;\nstruct frag_locked *frag_locked_list = NULL;\n\nINSERT_LIST(fragment, struct frag_locked)\nREMOVE_LIST(fragment, struct frag_locked)\n\nint lock_fragments()\n{\n\tint count;\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragments_locked = TRUE;\n\tcount = fragments_outstanding;\n\tpthread_mutex_unlock(&fragment_mutex);\n\treturn count;\n}\n\n\nvoid unlock_fragments()\n{\n\tstruct frag_locked *entry;\n\tint compressed_size;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(frag_locked_list) {\n\t\tentry = frag_locked_list;\n\t\tremove_fragment_list(&frag_locked_list, entry);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->c_byte);\n\t\tfragment_table[entry->fragment].size = entry->c_byte;\n\t\tfragment_table[entry->fragment].start_block = bytes;\n\t\tentry->buffer->block = bytes;\n\t\tbytes += compressed_size;\n\t\tfragments_outstanding --;\n\t\tqueue_put(to_writer, entry->buffer);\n\t\tTRACE(\"fragment_locked writing fragment %d, compressed size %d\"\n\t\t\t\"\\n\", entry->fragment, compressed_size);\n\t\tfree(entry);\n\t}\n\tfragments_locked = FALSE;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nint add_pending_fragment(struct file_buffer *write_buffer, int c_byte,\n\tint fragment)\n{\n\tstruct frag_locked *entry = malloc(sizeof(struct frag_locked));\n\tif(entry == NULL)\n\t\treturn FALSE;\n\tentry->buffer = write_buffer;\n\tentry->c_byte = c_byte;\n\tentry->fragment = fragment;\n\tentry->fragment_prev = entry->fragment_next = NULL;\n\tpthread_mutex_lock(&fragment_mutex);\n\tinsert_fragment_list(&frag_locked_list, entry);\n\tpthread_mutex_unlock(&fragment_mutex);\n\n\treturn TRUE;\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tfragment_table = realloc(fragment_table, (fragments +\n\t\t\tFRAG_SIZE) * sizeof(squashfs_fragment_entry));\n\t\tif(fragment_table == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].unused = 0;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = cache_get(fragment_buffer, fragments, 1);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data,\n\t\tfile_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, char *buffer, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) /\n\t\tSQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n#ifdef SQUASHFS_TRACE\n\tlong long obytes = bytes;\n#endif\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + BLOCK_OFFSET, buffer + i *\n\t\t\tSQUASHFS_METADATA_SIZE , avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, (unsigned short *) cbuffer, 1);\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes,\n\t\t\tcompressed_size);\n\t\twrite_destination(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\tlength -= avail_bytes;\n\t}\n\n\tSQUASHFS_INSWAP_LONG_LONGS(list, meta_blocks);\n\twrite_destination(fd, bytes, sizeof(list), (char *) list);\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\tTRACE(\"total uncompressed %d compressed %lld\\n\", inode_count *\n\t\tsizeof(squashfs_inode), bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tchar buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments,\n\t\tfrag_bytes);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block 0x%llx, \"\n\t\t\t\"size %d\\n\", i, fragment_table[i].start_block,\n\t\t\tfragment_table[i].size);\n\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\treturn generic_write_table(frag_bytes, buffer, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tread_destination(fd, start, avail_bytes, read_from_file_buffer);\n\treturn read_from_file_buffer;\n}\n\n\nchar read_from_file_buffer2[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk2(long long start, unsigned int avail_bytes)\n{\n\tread_destination(fd, start, avail_bytes, read_from_file_buffer2);\n\treturn read_from_file_buffer2;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l,\n\tunsigned int *blocks)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\tstruct file_buffer *write_buffer;\n\tint i;\n\n\tfor(i = 0; l; i++)  {\n\t\tbytes = SQUASHFS_COMPRESSED_SIZE_BLOCK(blocks[i]);\n\t\tif(bytes == 0) /* sparse block */\n\t\t\tcontinue;\n\t\twrite_buffer = cache_lookup(writer_buffer, start);\n\t\tif(write_buffer) {\n\t\t\tchksum = get_checksum(write_buffer->data, bytes,\n\t\t\t\tchksum);\n\t\t\tcache_block_put(write_buffer);\n\t\t} else\n\t\t\tchksum = get_checksum(read_from_disk(start, bytes),\n\t\t\t\tbytes, chksum);\n\t\tl -= bytes;\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes,\n\tunsigned int *block_listp, int blocks, unsigned int fragment,\n\tint offset, int bytes)\n{\n\tstruct fragment *frg;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset !=\n\t\t\t\tdupl_ptr->fragment->offset || bytes !=\n\t\t\t\tdupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tif((frg = malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && file_size ==\n\t\t\t\tdupl_ptr->fragment->size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, file_size);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag)\n{\n\tstruct file_info *dupl_ptr;\n\n\tif((dupl_ptr = malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes &&\n\t\t\t\t frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tlong long target_start, dup_start = dupl_ptr->start;\n\t\t\tint block;\n\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks *\n\t\t\t\t\tsizeof(unsigned int)) != 0)\n\t\t\t\tcontinue;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_disk(*start, bytes,\n\t\t\t\t\t*block_list);\n\t\t\t\tfragment_checksum =\n\t\t\t\t\tget_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, frag_bytes);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum ||\n\t\t\t\t\tfragment_checksum !=\n\t\t\t\t\tdupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\ttarget_start = *start;\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t((*block_list)[block]);\n\t\t\t\tstruct file_buffer *target_buffer = NULL;\n\t\t\t\tstruct file_buffer *dup_buffer = NULL;\n\t\t\t\tchar *target_data, *dup_data;\n\t\t\t\tint res;\n\n\t\t\t\tif(size == 0)\n\t\t\t\t\tcontinue;\n\t\t\t\ttarget_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\ttarget_start);\n\t\t\t\tif(target_buffer)\n\t\t\t\t\ttarget_data = target_buffer->data;\n\t\t\t\telse\n\t\t\t\t\ttarget_data =\n\t\t\t\t\t\tread_from_disk(target_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tdup_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\tdup_start);\n\t\t\t\tif(dup_buffer)\n\t\t\t\t\tdup_data = dup_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tdup_data = read_from_disk2(dup_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tres = memcmp(target_data, dup_data, size);\n\t\t\t\tcache_block_put(target_buffer);\n\t\t\t\tcache_block_put(dup_buffer);\n\t\t\t\tif(res != 0)\n\t\t\t\t\tbreak;\n\t\t\t\ttarget_start += size;\n\t\t\t\tdup_start += size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\n\t\t\t\tif(frag_bytes == 0 ||\n\t\t\t\t\t\tmemcmp(file_buffer->data,\n\t\t\t\t\t\tfrag_buffer->data +\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfrag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start \"\n\t\t\t\t\t\t\"0x%llx, size %lld, checksum \"\n\t\t\t\t\t\t\"0x%x, fragment %d, size %d, \"\n\t\t\t\t\t\t\"offset %d, checksum 0x%x\\n\",\n\t\t\t\t\t\tdupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes,\n\t\t\t\t\t\tdupl_ptr->checksum,\n\t\t\t\t\t\tdupl_ptr->fragment->index,\n\t\t\t\t\t\tfrag_bytes,\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment,\n\t\tchecksum, fragment_checksum, checksum_flag);\n}\n\n\nstatic int seq = 0;\nvoid reader_read_process(struct dir_ent *dir_ent)\n{\n\tstruct file_buffer *prev_buffer = NULL, *file_buffer;\n\tint status, res, byte, count = 0;\n\tint file = get_pseudo_file(dir_ent->inode->pseudo_id)->fd;\n\tint child = get_pseudo_file(dir_ent->inode->pseudo_id)->child;\n\tlong long bytes = 0;\n\n\twhile(1) {\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = seq ++;\n\n\t\tbyte = read_bytes(file, file_buffer->data, block_size);\n\t\tif(byte == -1)\n\t\t\tgoto read_err;\n\n\t\tfile_buffer->size = byte;\n\t\tfile_buffer->file_size = -1;\n\t\tfile_buffer->block = count ++;\n\t\tfile_buffer->error = FALSE;\n\t\tfile_buffer->fragment = FALSE;\n\t\tbytes += byte;\n\n\t\tif(byte == 0)\n\t\t\tbreak;\n\n\t\t/*\n\t\t * Update estimated_uncompressed block count.  This is done\n\t\t * on every block rather than waiting for all blocks to be\n\t\t * read incase write_file_process() is running in parallel\n\t\t * with this.  Otherwise cur uncompressed block count may\n\t\t * get ahead of the total uncompressed block count.\n\t\t */ \n\t\testimated_uncompressed ++;\n\n\t\tif(prev_buffer)\n\t\t\tqueue_put(from_reader, prev_buffer);\n\t\tprev_buffer = file_buffer;\n\t}\n\n\t/*\n \t * Update inode file size now that the size of the dynamic pseudo file\n\t * is known.  This is needed for the -info option.\n\t */\n\tdir_ent->inode->buf.st_size = bytes;\n\n\tres = waitpid(child, &status, 0);\n\tif(res == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)\n\t\tgoto read_err;\n\n\tif(prev_buffer == NULL)\n\t\tprev_buffer = file_buffer;\n\telse {\n\t\tcache_block_put(file_buffer);\n\t\tseq --;\n\t}\n\tprev_buffer->file_size = bytes;\n\tprev_buffer->fragment = !no_fragments &&\n\t\t(count == 2 || always_use_fragments) && (byte < block_size);\n\tqueue_put(from_reader, prev_buffer);\n\n\treturn;\n\nread_err:\n\tif(prev_buffer) {\n\t\tcache_block_put(file_buffer);\n\t\tseq --;\n\t\tfile_buffer = prev_buffer;\n\t}\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\n\tstruct file_buffer *file_buffer;\n\tint blocks, byte, count, expected, file, frag_block;\n\tlong long bytes, read_size;\n\n\tif(dir_ent->inode->read)\n\t\treturn;\n\n\tdir_ent->inode->read = TRUE;\nagain:\n\tbytes = 0;\n\tcount = 0;\n\tfile_buffer = NULL;\n\tread_size = buf->st_size;\n\tblocks = (read_size + block_size - 1) >> block_log;\n\tfrag_block = !no_fragments && (always_use_fragments ||\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\n\n\tif((file = open(dir_ent->pathname, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\texpected = read_size - ((long long) count * block_size) >\n\t\t\tblock_size ? block_size :\n\t\t\tread_size - ((long long) count * block_size);\n\n\t\tif(file_buffer)\n\t\t\tqueue_put(from_reader, file_buffer);\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = seq ++;\n\n\t\tbyte = file_buffer->size = read_bytes(file, file_buffer->data,\n\t\t\tblock_size);\n\n\t\tfile_buffer->file_size = read_size;\n\n\t\tif(byte != expected)\n\t\t\tgoto restat;\n\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->error = FALSE;\n\t\tfile_buffer->fragment = (file_buffer->block == frag_block);\n\n\t\tbytes += byte;\n\t\tcount ++;\n\t} while(count < blocks);\n\n\tif(read_size != bytes)\n\t\tgoto restat;\n\n\tif(expected == block_size) {\n\t\tchar buffer;\n\n\t\tif(read_bytes(file, &buffer, 1) == 1)\n\t\t\tgoto restat;\n\t}\n\n\tqueue_put(from_reader, file_buffer);\n\n\tclose(file);\n\n\treturn;\n\nread_err:\n\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\tfile_buffer->sequence = seq ++;\nread_err2:\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n\treturn;\nrestat:\n\tfstat(file, &buf2);\n\tclose(file);\n\tif(read_size != buf2.st_size) {\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\n\t\tfile_buffer->error = 2;\n\t\tqueue_put(from_deflate, file_buffer);\n\t\tgoto again;\n\t}\n\tgoto read_err2;\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->inode->root_entry)\n\t\t\tcontinue;\n\n\t\tif(dir_ent->inode->pseudo_file) {\n\t\t\treader_read_process(dir_ent);\n\t\t\tcontinue;\n\t\t}\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry; entry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\n\tthread[0] = 0;\n\n\tpthread_exit(NULL);\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer,\n\t\t\t\twrite_error ? (void *) &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write_bytes(fd, file_buffer->data,\n\t\t\t\tfile_buffer->size) == -1) {\n\t\t\tERROR(\"Write on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\nint all_zero(struct file_buffer *file_buffer)\n{\n\tint i;\n\tlong entries = file_buffer->size / sizeof(long);\n\tlong *p = (long *) file_buffer->data;\n\n\tfor(i = 0; i < entries && p[i] == 0; i++);\n\n\tif(i == entries) {\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1);\n\t\t\ti < file_buffer->size && file_buffer->data[i] == 0;\n\t\t\ti++);\n\n\t\treturn i == file_buffer->size;\n\t}\n\n\treturn 0;\n}\n\n\nvoid *deflator(void *arg)\n{\n\tvoid *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer;\n\n\t\tif(sparse_files && all_zero(file_buffer)) { \n\t\t\tfile_buffer->c_byte = 0;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else if(file_buffer->fragment) {\n\t\t\tfile_buffer->c_byte = file_buffer->size;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else {\n\t\t\twrite_buffer = cache_get(writer_buffer, 0, 0);\n\t\t\twrite_buffer->c_byte = mangle2(&stream,\n\t\t\t\twrite_buffer->data, file_buffer->data,\n\t\t\t\tfile_buffer->size, block_size, noD, 1);\n\t\t\twrite_buffer->sequence = file_buffer->sequence;\n\t\t\twrite_buffer->file_size = file_buffer->file_size;\n\t\t\twrite_buffer->block = file_buffer->block;\n\t\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t(write_buffer->c_byte);\n\t\t\twrite_buffer->fragment = FALSE;\n\t\t\twrite_buffer->error = FALSE;\n\t\t\tcache_block_put(file_buffer);\n\t\t\tqueue_put(from_deflate, write_buffer);\n\t\t}\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tvoid *stream = NULL;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer =\n\t\t\tcache_get(writer_buffer, file_buffer->block +\n\t\t\tFRAG_INDEX, 1);\n\n\t\tc_byte = mangle2(&stream, write_buffer->data, file_buffer->data,\n\t\t\tfile_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\twrite_buffer->size = compressed_size;\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tif(fragments_locked == FALSE) {\n\t\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\t\twrite_buffer->block = bytes;\n\t\t\tbytes += compressed_size;\n\t\t\tfragments_outstanding --;\n\t\t\tqueue_put(to_writer, write_buffer);\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tTRACE(\"Writing fragment %lld, uncompressed size %d, \"\n\t\t\t\t\"compressed size %d\\n\", file_buffer->block,\n\t\t\t\tfile_buffer->size, compressed_size);\n\t\t} else {\n\t\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\t\tadd_pending_fragment(write_buffer, c_byte,\n\t\t\t\t\tfile_buffer->block);\n\t\t}\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->sequence);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int sequence = 0;\n\tint hash = BLOCK_HASH(sequence);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->sequence == sequence)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->sequence == sequence)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tsequence ++;\n\n\treturn file_buffer;\n}\n\n\nvoid *progress_thrd(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&progress_mutex);\n\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) *\n\t\t\t1000;\n\t\tpthread_cond_timedwait(&progress_wait, &progress_mutex,\n\t\t\t&timespec);\n\t\tif(progress_enabled && estimated_uncompressed)\n\t\t\tprogress_bar(cur_uncompressed, estimated_uncompressed,\n\t\t\t\tcolumns);\n\t}\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits = floor(log10(max)) + 1;\n\tint used = max_digits * 2 + 11;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\tstatic int tty = -1;\n\n\tif((current > max) || (columns - used < 0))\n\t\treturn;\n\n\tif(tty == -1)\n\t\ttty = isatty(STDOUT_FILENO);\n\tif(!tty) {\n\t\tstatic long long previous = -1;\n\n\t\t/* Updating much more frequently than this results in huge\n\t\t * log files. */\n\t\tif((current % 100) != 0 && current != max)\n\t\t\treturn;\n\t\t/* Don't update just to rotate the spinner. */\n\t\tif(current == previous)\n\t\t\treturn;\n\t\tprevious = current;\n\t}\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0, NULL,\n\t\t\t&empty_fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, 0, 0, 0, NULL,\n\t\t\t&empty_fragment, NULL, 0);\n}\n\n\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint size, int *duplicate_file, struct file_buffer *file_buffer,\n\tunsigned short checksum)\n{\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment,\n\t\tfile_buffer, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\tcache_block_put(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tinc_progress_bar();\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n}\n\n\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size,\n\tstruct file_buffer *file_buffer, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum)) {\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file,\n\t\t\tfile_buffer, checksum);\n\t\treturn;\n\t}\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\tcache_block_put(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tinc_progress_bar();\n\n\tif(dir_ent->inode->nlink == 1)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, size, 0, 0,\n\t\t\tNULL, fragment, NULL, 0);\n\n\treturn;\n}\n\n\nint write_file_process(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tstruct file_buffer *read_buffer, int *duplicate_file)\n{\n\tlong long read_size, file_bytes, start;\n\tstruct fragment *fragment;\n\tunsigned int *block_list = NULL;\n\tint block = 0, status;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\t*duplicate_file = FALSE;\n\n\tlock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\twhile (1) {\n\t\tread_size = read_buffer->file_size;\n\t\tif(read_buffer->fragment && read_buffer->c_byte)\n\t\t\tfragment_buffer = read_buffer;\n\t\telse {\n\t\t\tblock_list = realloc(block_list, (block + 1) *\n\t\t\t\tsizeof(unsigned int));\n\t\t\tif(block_list == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory allocating block_list\"\n\t\t\t\t\t\"\\n\");\n\t\t\tblock_list[block ++] = read_buffer->c_byte;\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else {\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(read_size != -1)\n\t\t\tbreak;\n\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t}\n\n\tunlock_fragments();\n\tfragment = get_and_fill_fragment(fragment_buffer);\n\tcache_block_put(fragment_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment,\n\t\t\t0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tif(read_size < (1LL << 32) && start < (1LL << 32) && sparse == 0)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size,\n\t\t\tstart, block, block_list, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size,\n\t\t\tstart, block, block_list, fragment, NULL, sparse);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(!block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tlong long file_bytes, start;\n\tstruct fragment *fragment;\n\tunsigned int *block_list;\n\tint block, status;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\t*duplicate_file = FALSE;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tlock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else {\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tfragment = get_and_fill_fragment(fragment_buffer);\n\tcache_block_put(fragment_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment,\n\t\t\t0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < (1LL << 32) && start <\n\t\t\t(1LL << 32) && sparse == 0)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size,\n\t\t\tstart, blocks, block_list, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size,\n\t\t\tstart, blocks, block_list, fragment, NULL, sparse);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(!block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tint block, thresh;\n\tlong long file_bytes, dup_start, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer **buffer_list;\n\tint status, num_locked_fragments;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\tblock_list = malloc(blocks * sizeof(unsigned int));\n\tif(block_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tbuffer_list = malloc(blocks * sizeof(struct file_buffer *));\n\tif(buffer_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tnum_locked_fragments = lock_fragments();\n\n\tfile_bytes = 0;\n\tstart = dup_start = bytes;\n\tthresh = blocks > (writer_buffer_size - num_locked_fragments) ?\n\t\tblocks - (writer_buffer_size - num_locked_fragments): 0;\n\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tif(block < thresh) {\n\t\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t\t} else\n\t\t\t\t\tbuffer_list[block] = read_buffer;\n\t\t\t} else {\n\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &dup_start,\n\t\t&fragment, fragment_buffer, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tif(buffer_list[block])\n\t\t\t\tqueue_put(to_writer, buffer_list[block]);\n\t\tfragment = get_and_fill_fragment(fragment_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tcache_block_put(buffer_list[block]);\n\t\tbytes = start;\n\t\tif(thresh && !block_device) {\n\t\t\tint res;\n\n\t\t\tqueue_put(to_writer, NULL);\n\t\t\tif(queue_get(from_writer) != 0)\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\tres = ftruncate(fd, bytes);\n\t\t\tif(res != 0)\n\t\t\t\tBAD_ERROR(\"Failed to truncate dest file because\"\n\t\t\t\t\t\"  %s\\n\", strerror(errno));\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tcache_block_put(fragment_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tif(dir_ent->inode->nlink == 1 && read_size < (1LL << 32) && dup_start <\n\t\t\t(1LL << 32) && sparse == 0)\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size,\n\t\t\tdup_start, blocks, block_listp, fragment, NULL, 0);\n\telse\n\t\tcreate_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size,\n\t\t\tdup_start, blocks, block_listp, fragment, NULL, sparse);\n\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(thresh && !block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\tcache_block_put(buffer_list[blocks]);\n\tfree(buffer_list);\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tint status;\n\tstruct file_buffer *read_buffer;\n\tlong long read_size;\n\nagain:\n\tread_buffer = get_file_buffer(from_deflate);\n\n\tstatus = read_buffer->error;\n\tif(status) {\n\t\tcache_block_put(read_buffer);\n\t\tgoto file_err;\n\t}\n\t\n\tread_size = read_buffer->file_size;\n\n\tif(read_size == -1)\n\t\tstatus = write_file_process(inode, dir_ent, read_buffer,\n\t\t\tduplicate_file);\n\telse if(read_size == 0) {\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t\tcache_block_put(read_buffer);\n\t} else if(read_buffer->fragment && read_buffer->c_byte)\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer,\n\t\t\tduplicate_file);\n\telse if(pre_duplicate(read_size))\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\telse\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\nfile_err:\n\tif(status == 2) {\n\t\tERROR(\"File %s changed size while reading filesystem, \"\n\t\t\t\"attempting to re-read\\n\", dir_ent->pathname);\n\t\tgoto again;\n\t} else if(status == 1) {\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\",\n\t\t\tdir_ent->pathname);\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t}\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) ||\n\t\t\t\t((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\"\n\t\t\t\"\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->root_entry = FALSE;\n\tinode->pseudo_file = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\n\tif((buf->st_mode & S_IFMT) == S_IFREG)\n\t\testimated_uncompressed += (buf->st_size + block_size - 1) >>\n\t\t\tblock_log;\n\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir,\n\tstruct inode_info *inode_info, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0) {\n\t\tdir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) *\n\t\t\t\tsizeof(struct dir_ent *));\n\t\tif(dir->list == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\t}\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) :\n\t\tNULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count++]->our_dir = dir;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count\n\t\t= 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].inode.type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL,\n\t\t\t\t&old_root_entry[i].inode, dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\",\n\t\t\t\tsource_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count &&\n\t\t\t\tstrcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].inode.type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL,\n\t\t\t\t&old_root_entry[i].inode, dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count &&\n\t\t\t\tstrcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->inode->root_entry)\n\t\t\tcontinue;\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nstruct dir_ent *scan2_lookup(struct dir_info *dir, char *name)\n{\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++)\n\t\tif(strcmp(dir->list[i]->name, name) == 0)\n\t\t\treturn dir->list[i];\n\n\treturn NULL;\n}\n\n\nstruct dir_ent *scan3_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->inode->root_entry)\n\t\t\tadd_dir(dir_info->list[current_count]->inode->inode,\n\t\t\t\tdir_info->list[current_count]->inode->inode_number,\n\t\t\t\tdir_info->list[current_count]->name,\n\t\t\t\tdir_info->list[current_count]->inode->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct dir_info *dir)\n{\n\tdir->current_count = 0;\n}\n\n\nvoid scan3_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tdir_scan2(dir_info, pseudo);\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/*\n \t\t *dummy top level directory, if multiple sources specified on\n\t\t * command line\n\t\t */\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t} else if(lstat(pathname, &buf) == -1) {\n\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\", pathname,\n\t\t\tstrerror(errno));\n\t\treturn;\n\t}\n\n\tdir_ent->inode = lookup_inode(&buf);\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted)\n\t\tgenerate_file_priorities(dir_info, 0,\n\t\t\t&dir_info->dir_ent->inode->buf);\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tif(progress)\n\t\tenable_progress_bar();\n\tdir_scan3(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\tstruct pathnames *new;\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\",\n\t\t\t\tfilename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\"\n\t\t\t\t\"\\n\", filename, buf.st_mode & S_IFMT);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(old_exclude) {\n\t\t\tif(old_excluded(filename, &buf))\n\t\t\t\tcontinue;\n\t\t} else {\n\t\t\tif(excluded(paths, dir_name, &new))\n\t\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tsub_dir = dir_scan1(filename, new, scan1_readdir);\n\t\t\tif(sub_dir == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf),\n\t\t\tdir);\n\t}\n\n\tscan1_freedir(dir);\n\nerror:\n\treturn dir;\n}\n\n\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo)\n{\n\tstruct dir_info *sub_dir;\n\tstruct dir_ent *dir_ent;\n\tstruct pseudo_entry *pseudo_ent;\n\tstruct stat buf;\n\tstatic int pseudo_ino = 1;\n\t\n\tif(dir == NULL && (dir = scan1_opendir(\"\")) == NULL)\n\t\treturn NULL;\n\t\n\twhile((dir_ent = scan2_readdir(dir)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *name = dir_ent->name;\n\n\t\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\tdir_scan2(dir_ent->dir, pseudo_subdir(name, pseudo));\n\t}\n\n\twhile((pseudo_ent = pseudo_readdir(pseudo)) != NULL) {\n\t\tdir_ent = scan2_lookup(dir, pseudo_ent->name);\n\t\tif(pseudo_ent->dev->type == 's') {\n\t\t\tstruct stat *buf;\n\t\t\tif(dir_ent == NULL) {\n\t\t\t\tERROR(\"Pseudo set file \\\"%s\\\" does not exist \"\n\t\t\t\t\t\"in source filesystem.  Ignoring\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(dir_ent->inode->root_entry) {\n\t\t\t\tERROR(\"Pseudo set file \\\"%s\\\" is a pre-existing\"\n\t\t\t\t\t\" file in the filesystem being appended\"\n\t\t\t\t\t\"  to.  It cannot be modified. \"\n\t\t\t\t\t\"Ignoring!\\n\", pseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tbuf = &dir_ent->inode->buf;\n\t\t\tbuf->st_mode = (buf->st_mode & S_IFMT) |\n\t\t\t\tpseudo_ent->dev->mode;\n\t\t\tbuf->st_uid = pseudo_ent->dev->uid;\n\t\t\tbuf->st_gid = pseudo_ent->dev->gid;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(dir_ent) {\n\t\t\tERROR(\"Pseudo file \\\"%s\\\" exists in source filesystem \"\n\t\t\t\t\"\\\"%s\\\"\\n\", pseudo_ent->pathname,\n\t\t\t\tdir_ent->pathname);\n\t\t\tERROR(\"Ignoring, exclude it (-e/-ef) to override\\n\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(pseudo_ent->dev->type == 'd') {\n\t\t\tsub_dir = dir_scan2(NULL, pseudo_ent->pseudo);\n\t\t\tif(sub_dir == NULL) {\n\t\t\t\tERROR(\"Could not create pseudo directory \\\"%s\\\"\"\n\t\t\t\t\t\", skipping...\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = pseudo_ent->dev->mode;\n\t\tbuf.st_uid = pseudo_ent->dev->uid;\n\t\tbuf.st_gid = pseudo_ent->dev->gid;\n\t\tbuf.st_rdev = makedev(pseudo_ent->dev->major,\n\t\t\tpseudo_ent->dev->minor);\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_ino = pseudo_ino ++;\n\n\t\tif(pseudo_ent->dev->type == 'f') {\n#ifdef USE_TMP_FILE\n\t\t\tstruct stat buf2;\n\t\t\tint res = stat(pseudo_ent->dev->filename, &buf2);\n\t\t\tif(res == -1) {\n\t\t\t\tERROR(\"Stat on pseudo file \\\"%s\\\" failed, \"\n\t\t\t\t\t\"skipping...\", pseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tbuf.st_size = buf2.st_size;\n\t\t\tadd_dir_entry(pseudo_ent->name,\n\t\t\t\tpseudo_ent->dev->filename, sub_dir,\n\t\t\t\tlookup_inode(&buf), dir);\n#else\n\t\t\tstruct inode_info *inode = lookup_inode(&buf);\n\t\t\tinode->pseudo_id = pseudo_ent->dev->pseudo_id;\n\t\t\tinode->pseudo_file = TRUE;\t\t\n\t\t\tadd_dir_entry(pseudo_ent->name, pseudo_ent->pathname,\n\t\t\t\tsub_dir, inode, dir);\n#endif\n\t\t} else\n\t\t\tadd_dir_entry(pseudo_ent->name, pseudo_ent->pathname,\n\t\t\t\tsub_dir, lookup_inode(&buf), dir);\n\t}\n\n\tscan2_freedir(dir);\n\tsort_directory(dir);\n\n\treturn dir;\n}\n\n\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan3_init_dir(&dir);\n\t\n\twhile((dir_ent = scan3_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\t?  dir_ent->inode->inode_number :\n\t\t\tdir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\twrite_file(inode, dir_ent,\n\t\t\t\t\t\t&duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld \"\n\t\t\t\t\t\t\"bytes %s\\n\", filename,\n\t\t\t\t\t\t(long long) buf->st_size,\n\t\t\t\t\t\tduplicate_file ?  \"DUPLICATE\" :\n\t\t\t\t\t\t \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tdir_scan3(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\"\n\t\t\t\t\t\t\"\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\",dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tcreate_inode(inode, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tBAD_ERROR(\"%s unrecognised file type, \"\n\t\t\t\t\t\t\"mode is %x\\n\", filename,\n\t\t\t\t\t\tbuf->st_mode);\n\t\t\t}\n\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed \"\n\t\t\t\t\t\t\t\"size %lld bytes LINK\"\n\t\t\t\t\t\t\t\"\\n\", filename,\n\t\t\t\t\t\t\t(long long)\n\t\t\t\t\t\t\tbuf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx LINK\\n\", dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t\tupdate_progress_bar();\n\t}\n\n\twrite_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan3_freedir(&dir);\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 20; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint old_excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) &&\n\t\t\t\t(exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) { \\\n\t\texclude_paths = realloc(exclude_paths, (exclude + EXCLUDE_SIZE) \\\n\t\t\t* sizeof(struct exclude_info)); \\\n\t\tif(exclude_paths == NULL) \\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\"); \\\n\t} \\\n\texclude_paths[exclude].st_dev = buf.st_dev; \\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint old_add_exclude(char *path)\n{\n\tint i;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 ||\n\t\t\tstrncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat exclude dir/file %s because %s, \"\n\t\t\t\t\"ignoring\", path, strerror(errno));\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tERROR(\"Cannot stat exclude dir/file %s because \"\n\t\t\t\t\t\"%s, ignoring\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type)\n{\n\told_root_entry = realloc(old_root_entry,\n\t\tsizeof(struct old_root_entry_info) * (old_root_entries + 1));\n\tif(old_root_entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries \"\n\t\t\t\"reallocation\\n\");\n\n\told_root_entry[old_root_entries].name = strdup(name);\n\told_root_entry[old_root_entries].inode.inode = inode;\n\told_root_entry[old_root_entries].inode.inode_number = inode_number;\n\told_root_entry[old_root_entries].inode.type = type;\n\told_root_entry[old_root_entries++].inode.root_entry = TRUE;\n}\n\n\nvoid initialise_threads()\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  \"\n\t\t\t\t\"Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(fragment_buffer_size);\n\treader_buffer = cache_init(block_size, reader_buffer_size);\n\twriter_buffer = cache_init(block_size, writer_buffer_size);\n\tfragment_buffer = cache_init(block_size, fragment_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&progress_thread, NULL, progress_thrd, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) !=\n\t\t\t\t 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator,\n\t\t\t\tNULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tinode_lookup_table = realloc(inode_lookup_table, lookup_bytes);\n\tif(inode_lookup_table == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number +\n\t\t\t\tdir_inode_no;\n\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(&inode->inode,\n\t\t\t\t&inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, (char *) inode_lookup_table,\n\t\t0);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) *\n\t\t\tsizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname,\n\t\t\t\tREG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, \"\n\t\t\t\t\t\"because %s\\n\", targname, alltarget,\n\t\t\t\t\tstr);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target,\n\t\t\t\talltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing exclude which subsumes\n\t\t\t * the exclude currently being added, in which case stop\n\t\t\t * adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist\n\t\t\t * from more specific excludes, delete as they're\n\t\t\t * subsumed by this exclude */\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid add_exclude(char *target)\n{\n\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 ||\n\t\t\tstrncmp(target, \"../\", 3) == 0)\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with \"\n\t\t\t\"-wildcards or -regex options\\n\");\t\n\telse if(strncmp(target, \"... \", 4) == 0)\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\n\telse\t\n\t\tpath = add_path(path, target, target);\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) +\n\t\t\t(paths->count + PATHS_ALLOC_SIZE) *\n\t\t\tsizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n, res;\n\t\t\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\n\t*new = init_subdir();\n\tif(stickypath)\n\t\t*new = add_subdir(*new, stickypath);\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0,\n\t\t\t\t\tNULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name,\n\t\t\t\t\tFNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) ==\n\t\t\t\t\t 0;\n\n\t\t\tif(match && path->name[i].paths == NULL) {\n\t\t\t\t/* match on a leaf component, any subdirectories\n\t\t\t\t * in the filesystem should be excluded */\n\t\t\t\tres = TRUE;\n\t\t\t\tgoto empty_set;\n\t\t\t}\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any\n\t\t\t\t * subdirectories to the new set of\n\t\t\t\t * subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t\t/* no matching names found, return empty new search set\n\t\t\t */\n\t\t\tres = FALSE;\n\t\t\tgoto empty_set;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches).\n\t * Return new set */\n\treturn FALSE;\n\nempty_set:\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn res;\n}\n\n\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\n#define RECOVER_ID_SIZE 28\n\nvoid write_recovery_data(squashfs_super_block *sBlk)\n{\n\tint recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\n\tpid_t pid = getpid();\n\tchar *metadata;\n\tchar header[] = RECOVER_ID;\n\n\tif(recover == FALSE) {\n\t\tprintf(\"No recovery data option specified.\\n\");\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\n\t\treturn;\n\t}\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"write_recovery_data\\n\");\n\n\tread_destination(fd, sBlk->inode_table_start, bytes, metadata);\n\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\",\n\t\tgetbase(destination_file), pid);\n\trecoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);\n\tif(recoverfd == -1)\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  \"\n\t\t\t\"Aborting\\n\", strerror(errno));\n\t\t\n\tif(write_bytes(recoverfd, header, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, sBlk, sizeof(squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, metadata, bytes) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tclose(recoverfd);\n\tfree(metadata);\n\t\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file,\n\t\trecovery_file);\n\tprintf(\"to restore filesystem\\n\\n\");\n}\n\n\nvoid read_recovery_data(char *recovery_file, char *destination_file)\n{\n\tint fd, recoverfd, bytes;\n\tsquashfs_super_block orig_sBlk, sBlk;\n\tchar *metadata;\n\tint res;\n\tstruct stat buf;\n\tchar header[] = RECOVER_ID;\n\tchar header2[RECOVER_ID_SIZE];\n\n\tif((recoverfd = open(recovery_file, O_RDONLY)) == -1)\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(stat(destination_file, &buf) == -1)\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif((fd = open(destination_file, O_RDWR)) == -1)\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tres = read_bytes(recoverfd, header2, RECOVER_ID_SIZE);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < RECOVER_ID_SIZE)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\n\n\tres = read_bytes(recoverfd, &sBlk, sizeof(squashfs_super_block));\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < sizeof(squashfs_super_block))\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\tread_destination(fd, 0, sizeof(squashfs_super_block), (char *)\n\t\t&orig_sBlk);\n\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4,\n\t\t\tsizeof(squashfs_super_block) - 4) != 0)\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to \"\n\t\t\t\"match\\n\");\n\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\n\n\tif((metadata = malloc(bytes)) == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"read_recovery_data\\n\");\n\n\tres = read_bytes(recoverfd, metadata, bytes);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < bytes)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\twrite_destination(fd, 0, sizeof(squashfs_super_block), (char *) &sBlk);\n\n\twrite_destination(fd, sBlk.inode_table_start, bytes, metadata);\n\n\tclose(recoverfd);\n\tclose(fd);\n\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\",\n\t\trecovery_file);\n\t\n\texit(0);\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 4.1-CVS (2009/09/20)\\n\");\\\n\tprintf(\"copyright (C) 2009 Phillip Lougher <phillip@lougher.demon.co.uk>\\n\\n\"); \\\n\tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint nopad = FALSE, keep_as_directory = FALSE;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT,\n\t\twriteb_mbytes = WRITER_BUFFER_DEFAULT,\n\t\tfragmentb_mbytes = FRAGMENT_BUFFER_DEFAULT;\n\tint s_minor = SQUASHFS_MINOR;\n\n\tpthread_mutex_init(&progress_mutex, NULL);\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-comp\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -comp missing compression type\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tcomp_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-pf\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -pf missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_file(&pseudo, argv[i]) == FALSE)\n\t\t\t\texit(1);\n\t\t} else if(strcmp(argv[i], \"-p\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -p missing pseudo file definition\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_def(&pseudo, argv[i]) == FALSE)\n\t\t\t\texit(1);\n\t\t} else if(strcmp(argv[i], \"-recover\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\n\t\t\trecover = FALSE;\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = FALSE;\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\n\t\t\tsparse_files = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid \"\n\t\t\t\t\t\"processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte \"\n\t\t\t\t\t\"or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-fragment-queue\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(fragmentb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -fragment-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragmentb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -fragment-queue should be 1 \"\n\t\t\t\t\t\"megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -b missing block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_size = strtol(argv[i], &b, 10);\n\t\t\tif(*b == 'm' || *b == 'M')\n\t\t\t\tblock_size *= 1048576;\n\t\t\telse if(*b == 'k' || *b == 'K')\n\t\t\t\tblock_size *= 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tERROR(\"%s: -b invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or \"\n\t\t\t\t\t\"not between 4096 and 1Mbyte\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or \"\n\t\t\t\t\t\t\"unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or \"\n\t\t\t\t\t\t\"unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0) {\n\t\t\tsilent = FALSE;\n\t\t\tprogress = FALSE;\n\t\t}\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] \"\n\t\t\t\t\"[-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nFilesystem build options:\\n\");\n\t\t\tERROR(\"-comp <comp>\\t\\tselect <comp> compression\\n\");\n\t\t\tERROR(\"\\t\\t\\tCompressors available:\\n\");\n\t\t\tdisplay_compressors(\"\\t\\t\\t\", COMP_DEFAULT);\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to \"\n\t\t\t\t\"<block_size>.  Default %d bytes\\n\",\n\t\t\t\tSQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem \"\n\t\t\t\t\"exportable via NFS\\n\");\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for \"\n\t\t\t\t\"files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate \"\n\t\t\t\t\"checking\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple \"\n\t\t\t\t\"of 4K\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is \"\n\t\t\t\t\"specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, \"\n\t\t\t\t\"rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"\\nFilesystem filter options:\\n\");\n\t\t\tERROR(\"-p <pseudo-definition>\\tAdd pseudo file definition\\n\");\n\t\t\tERROR(\"-pf <pseudo-file>\\tAdd list of pseudo file definitions\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to \"\n\t\t\t\t\"priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  \"\n\t\t\t\t\"Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.\"\n\t\t\t\t\"  One per line\\n\");\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards \"\n\t\t\t\t\"(globbing) to be used in\\n\\t\\t\\texclude \"\n\t\t\t\t\"dirs/files\\n\");\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to \"\n\t\t\t\t\"be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n\t\t\tERROR(\"\\nFilesystem append options:\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing \"\n\t\t\t\t\"filesystem\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source \"\n\t\t\t\t\"files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in \"\n\t\t\t\t\"the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new \"\n\t\t\t\t\"source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"\\nMksquashfs runtime options:\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and \"\n\t\t\t\t\"copyright message\\n\");\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data \"\n\t\t\t\t\"using recovery file <name>\\n\");\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery \"\n\t\t\t\t\"file\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress \"\n\t\t\t\t\"bar\\n\");\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.\"\n\t\t\t\t\"  By default will use number of\\n\");\n\t\t\tERROR(\"\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tREADER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tWRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-fragment-queue <size>\\tSet fagment queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tFRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\nMiscellaneous options:\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for \"\n\t\t\t\t\"-noF\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\treader_buffer_size = readb_mbytes << (20 - block_log);\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\tfragment_buffer_size = fragmentb_mbytes << (20 - block_log);\n\n\tfor(i = 0; i < source; i++)\n\t\tif(lstat(source_path[i], &source_buf) == -1) {\n\t\t\tfprintf(stderr, \"Cannot stat source directory \\\"%s\\\" \"\n\t\t\t\t\"because %s\\n\", source_path[i],\n\t\t\t\tstrerror(errno));\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tfd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR,\n\t\t\t\tS_IRWXU);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as \"\n\t\t\t\t\t\"destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tfd = open(argv[source + 1], (delete ? O_TRUNC : 0) |\n\t\t\t\tO_RDWR);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not open regular file for \"\n\t\t\t\t\t\"writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tsignal(SIGTERM, sighandler2);\n\tsignal(SIGINT, sighandler2);\n\n\t/* process the exclude files - must be done afer destination file has\n\t * been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\t\tif(old_exclude)\n\t\t\t\t\t\told_add_exclude(filename);\n\t\t\t\t\telse\n\t\t\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-sort\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-comp\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc)\n\t\t\tif(old_exclude)\n\t\t\t\told_add_exclude(argv[i++]);\n\t\t\telse\n\t\t\t\tadd_exclude(argv[i++]);\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-ef\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-comp\") == 0)\n\t\t\ti++;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(!delete) {\n\t        comp = read_super(fd, &sBlk, argv[source + 1]);\n\t        if(comp == NULL) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\ts_minor = sBlk.s_minor;\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t} else {\n\t\tcomp = lookup_compressor(comp_name);\n\t\tif(!comp->supported) {\n\t\t\tERROR(\"FATAL_ERROR: Compressor \\\"%s\\\" is not \"\n\t\t\t\t\"supported!\\n\", comp_name);\n\t\t\tERROR(\"Compressors available:\\n\");\n\t\t\tdisplay_compressors(\"\", COMP_DEFAULT);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t}\n\n\tinitialise_threads();\n\n\tif(delete) {\n\t\tprintf(\"Creating %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\tSQUASHFS_MAJOR, s_minor, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset,\n\t\t\tinode_dir_file_size, root_inode_size,\n\t\t\tinode_dir_start_block, uncompressed_data,\n\t\t\tcompressed_data, inode_dir_inode_number,\n\t\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start =\n\t\t\tSQUASHFS_INODE_BLK(sBlk.root_inode),\n\t\t\troot_inode_offset =\n\t\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table,\n\t\t\t\t&data_cache, &directory_table,\n\t\t\t\t&directory_data_cache, &last_directory_block,\n\t\t\t\t&inode_dir_offset, &inode_dir_file_size,\n\t\t\t\t&root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count,\n\t\t\t\t&fifo_count, &sock_count, &total_bytes,\n\t\t\t\t&total_inode_bytes, &total_directory_bytes,\n\t\t\t\t&inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry,\n\t\t\t\t&fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = realloc((char *) fragment_table,\n\t\t\t\t((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1))\n\t\t\t\t * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %d.%d filesystem on %s, block \"\n\t\t\t\"size %d\\n\", SQUASHFS_MAJOR, s_minor, argv[source + 1],\n\t\t\tblock_size);\n\t\tprintf(\"All -b, -noI, -noD, -noF, no-duplicates, no-fragments, \"\n\t\t\t\"-always-use-fragments,\\n-exportable and -comp options \"\n\t\t\t\"ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with \"\n\t\t\t\"-noappend specified!\\n\\n\");\n\n\t\tcompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t(SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tscache_bytes = root_inode_offset + root_inode_size;\n\t\tsdirectory_cache_bytes = uncompressed_data;\n\t\tsdata_cache = malloc(scache_bytes);\n\t\tsdirectory_data_cache = malloc(sdirectory_cache_bytes);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache +\n\t\t\tcompressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes +\n\t\t\tcompressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\tsid_count = id_count;\n\t\twrite_recovery_data(&sBlk);\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_destination(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/*\n\t\t * set the filesystem state up to be able to append to the\n\t\t * original filesystem.  The filesystem state differs depending\n\t\t * on whether we're appending to the original root directory, or\n\t\t * if the original root directory becomes a sub-directory\n\t\t * (root-becomes specified on command line, here root_name !=\n\t\t * NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\tsdirectory_bytes = last_directory_block;\n\t\t\tsdirectory_compressed_bytes = 0;\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache +\n\t\t\t\tcompressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode,\n\t\t\t\tinode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\tsdirectory_compressed_bytes = last_directory_block -\n\t\t\t\tinode_dir_start_block;\n\t\t\tsdirectory_compressed =\n\t\t\t\tmalloc(sdirectory_compressed_bytes);\n\t\t\tmemcpy(sdirectory_compressed, directory_table +\n\t\t\t\tinode_dir_start_block,\n\t\t\t\tsdirectory_compressed_bytes); \n\t\t\tsdirectory_bytes = inode_dir_start_block;\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count +\n\t\t\tfifo_count + sock_count;\n\t}\n\n\tif(path || stickypath) {\n\t\tpaths = init_subdir();\n\t\tif(path)\n\t\t\tpaths = add_subdir(paths, path);\n\t\tif(stickypath)\n\t\t\tpaths = add_subdir(paths, stickypath);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = s_minor;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, no_fragments,\n\t\talways_use_fragments, duplicate_checking, exportable);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\tif(progress && estimated_uncompressed) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(interrupted < 2) {\n\t\tunlock_fragments();\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\twhile(fragments_outstanding) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tsched_yield();\n\t\t\tpthread_mutex_lock(&fragment_mutex);\n\t\t}\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() :\n\t\tSQUASHFS_INVALID_BLK;\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\",\n\t\tsBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\",\n\t\t\tsBlk.lookup_table_start);\n\n\tsBlk.no_ids = id_count;\n\tsBlk.id_table_start = write_id_table();\n\n\tsBlk.bytes_used = bytes;\n\n\tsBlk.compression = comp->id;\n\n\t/* Xattrs are not currently supported */\n\tsBlk.xattr_table_start = SQUASHFS_INVALID_BLK;\n\n\tSQUASHFS_INSWAP_SUPER_BLOCK(&sBlk); \n\twrite_destination(fd, SQUASHFS_START, sizeof(squashfs_super_block),\n\t\t(char *) &sBlk);\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_destination(fd, bytes, 4096 - i, temp);\n\t}\n\n\tclose(fd);\n\n\tdelete_pseudo_files();\n\n\tif(recovery_file[0] != '\\0')\n\t\tunlink(recovery_file);\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%sSquashfs %d.%d filesystem, %s compressed, data block size\"\n\t\t\" %d\\n\", exportable ? \"Exportable \" : \"\", SQUASHFS_MAJOR,\n\t\tSQUASHFS_MINOR, comp->name, block_size);\n\tprintf(\"\\t%s data, %s metadata, %s fragments\\n\",\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" :\n\t\t\"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" :\n\t\t\"compressed\");\n\tprintf(\"\\tduplicates are %sremoved\\n\", duplicate_checking ? \"\" :\n\t\t\"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0,\n\t\tbytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0,\n\t\ttotal_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0,\n\t\ttotal_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count -\n\t\t\tdup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of ids (unique uids + gids) %d\\n\", id_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_UID) {\n\t\t\tstruct passwd *user = getpwuid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" :\n\t\t\t\tuser->pw_name, id_table[i]->id);\n\t\t}\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_GID) {\n\t\t\tstruct group *group = getgrgid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" :\n\t\t\t\tgroup->gr_name, id_table[i]->id);\n\t\t}\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/mksquashfs.h",
    "content": "#ifndef MKSQUASHFS_H\n#define MKSQUASHFS_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define SQUASHFS_SWAP_SHORTS(s, d, n) swap_le16_num(s, d, n)\n#define SQUASHFS_SWAP_INTS(s, d, n) swap_le32_num(s, d, n)\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) swap_le64_num(s, d, n)\n\n#define SWAP_LE16(s, d, field)\tswap_le16(&((s)->field), &((d)->field))\n#define SWAP_LE32(s, d, field)\tswap_le32(&((s)->field), &((d)->field))\n#define SWAP_LE64(s, d, field)\tswap_le64(&((s)->field), &((d)->field))\n#define SWAP_LES16(s, d, field)\tswap_le16((unsigned short *) &((s)->field), \\\n\t\t\t\t(unsigned short *) &((d)->field))\n#else\n#define SQUASHFS_MEMCPY(s, d, n)\tmemcpy(d, s, n)\n#define SQUASHFS_SWAP_SHORTS(s, d, n)\tmemcpy(d, s, n * sizeof(short))\n#define SQUASHFS_SWAP_INTS(s, d, n)\tmemcpy(d, s, n * sizeof(int))\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) \\\n\t\t\t\t\tmemcpy(d, s, n * sizeof(long long))\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/pseudo.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * pseudo.c\n */\n\n#include <pwd.h>\n#include <grp.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <stdlib.h>\n#include <sys/types.h>\n#include <sys/wait.h>\n\n#include \"pseudo.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\n#define TRUE 1\n#define FALSE 0\n\nstruct pseudo_dev **pseudo_file = NULL;\nint pseudo_count = 0;\n\nstatic void dump_pseudo(struct pseudo *pseudo, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tfor(i = 0; i < pseudo->names; i++) {\n\t\tstruct pseudo_entry *entry = &pseudo->name[i];\n\t\tif(string)\n\t\t\tstrcat(strcat(strcpy(path, string), \"/\"), entry->name);\n\t\telse\n\t\t\tstrcpy(path, entry->name);\n\t\tif(entry->pseudo == NULL)\n\t\t\tERROR(\"%s %c %o %d %d %d %d\\n\", path, entry->dev->type,\n\t\t\t\tentry->dev->mode, entry->dev->uid,\n\t\t\t\tentry->dev->gid, entry->dev->major,\n\t\t\t\tentry->dev->minor);\n\t\telse\n\t\t\tdump_pseudo(entry->pseudo, path);\n\t}\n}\n\n\nstatic char *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\n/*\n * Add pseudo device target to the set of pseudo devices.  Pseudo_dev\n * describes the pseudo device attributes.\n */\nstruct pseudo *add_pseudo(struct pseudo *pseudo, struct pseudo_dev *pseudo_dev,\n\tchar *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i;\n\n\ttarget = get_component(target, targname);\n\n\tif(pseudo == NULL) {\n\t\tif((pseudo = malloc(sizeof(struct pseudo))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate pseudo file\\n\");\n\n\t\tpseudo->names = 0;\n\t\tpseudo->count = 0;\n\t\tpseudo->name = NULL;\n\t}\n\n\tfor(i = 0; i < pseudo->names; i++)\n\t\tif(strcmp(pseudo->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == pseudo->names) {\n\t\t/* allocate new name entry */\n\t\tpseudo->names ++;\n\t\tpseudo->name = realloc(pseudo->name, (i + 1) *\n\t\t\tsizeof(struct pseudo_entry));\n\t\tif(pseudo->name == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate pseudo file\\n\");\n\t\tpseudo->name[i].name = strdup(targname);\n\n\t\tif(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component */\n\t\t\tpseudo->name[i].pseudo = NULL;\n\t\t\tpseudo->name[i].pathname = strdup(alltarget);\n\t\t\tpseudo->name[i].dev = pseudo_dev;\n\t\t} else {\n\t\t\t/* recurse adding child components */\n\t\t\tpseudo->name[i].dev = NULL;\n\t\t\tpseudo->name[i].pseudo = add_pseudo(NULL, pseudo_dev,\n\t\t\t\ttarget, alltarget);\n\t\t}\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(pseudo->name[i].pseudo == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing pseudo file.\n\t\t\t */\n\t\t\tif(target[0] != '\\0') {\n\t\t\t\t/* entry must exist as a 'd' type pseudo file */\n\t\t\t\tif(pseudo->name[i].dev->type == 'd')\n\t\t\t\t\t/* recurse adding child components */\n\t\t\t\t\tpseudo->name[i].pseudo =\n\t\t\t\t\t\tadd_pseudo(NULL, pseudo_dev,\n\t\t\t\t\t\ttarget, alltarget);\n\t\t\t\telse\n\t\t\t\t\tERROR(\"%s already exists as a non \"\n\t\t\t\t\t\t\"directory.  Ignoring %s!\\n\",\n\t\t\t\t\t\t targname, alltarget);\n\t\t\t} else if(memcmp(pseudo_dev, pseudo->name[i].dev,\n\t\t\t\t\tsizeof(struct pseudo_dev)) != 0)\n\t\t\t\tERROR(\"%s already exists as a different pseudo \"\n\t\t\t\t\t\"definition.  Ignoring!\\n\", alltarget);\n\t\t\telse ERROR(\"%s already exists as an identical \"\n\t\t\t\t\t\"pseudo definition!\\n\", alltarget);\n\t\t} else {\n\t\t\t/* sub-directory exists which means this can only be a\n\t\t\t * 'd' type pseudo file */\n\t\t\tif(target[0] == '\\0') {\n\t\t\t\tif(pseudo->name[i].dev == NULL &&\n\t\t\t\t\t\tpseudo_dev->type == 'd') {\n\t\t\t\t\tpseudo->name[i].pathname =\n\t\t\t\t\t\tstrdup(alltarget);\n\t\t\t\t\tpseudo->name[i].dev = pseudo_dev;\n\t\t\t\t} else\n\t\t\t\t\tERROR(\"%s already exists as a \"\n\t\t\t\t\t\t\"directory.  Ignoring %s!\\n\",\n\t\t\t\t\t\ttargname, alltarget);\n\t\t\t} else\n\t\t\t\t/* recurse adding child components */\n\t\t\t\tadd_pseudo(pseudo->name[i].pseudo, pseudo_dev,\n\t\t\t\t\ttarget, alltarget);\n\t\t}\n\t}\n\n\treturn pseudo;\n}\n\n\n/*\n * Find subdirectory in pseudo directory referenced by pseudo, matching\n * filename.  If filename doesn't exist or if filename is a leaf file\n * return NULL\n */\nstruct pseudo *pseudo_subdir(char *filename, struct pseudo *pseudo)\n{\n\tint i;\n\n\tif(pseudo == NULL)\n\t\treturn NULL;\n\n\tfor(i = 0; i < pseudo->names; i++)\n\t\tif(strcmp(filename, pseudo->name[i].name) == 0)\n\t\t\treturn pseudo->name[i].pseudo;\n\n\treturn NULL;\n}\n\n\nstruct pseudo_entry *pseudo_readdir(struct pseudo *pseudo)\n{\n\tif(pseudo == NULL)\n\t\treturn NULL;\n\n\twhile(pseudo->count < pseudo->names) {\n\t\tif(pseudo->name[pseudo->count].dev != NULL)\n\t\t\treturn &pseudo->name[pseudo->count++];\n\t\telse\n\t\t\tpseudo->count++;\n\t}\n\n\treturn NULL;\n}\n\n\nint exec_file(char *command, struct pseudo_dev *dev)\n{\n\tint child, res;\n\tstatic pid_t pid = -1;\n\tint pipefd[2];\n#ifdef USE_TMP_FILE\n\tchar filename[1024];\n\tint status;\n\tstatic int number = 0;\n#endif\n\n\tif(pid == -1)\n\t\tpid = getpid();\n\n#ifdef USE_TMP_FILE\n\tsprintf(filename, \"/tmp/squashfs_pseudo_%d_%d\", pid, number ++);\n\tpipefd[1] = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);\n\tif(pipefd[1] == -1) {\n\t\tprintf(\"open failed\\n\");\n\t\treturn -1;\n\t}\n#else\n\tres = pipe(pipefd);\n\tif(res == -1) {\n\t\tprintf(\"pipe failed\\n\");\n\t\treturn -1;\n\t}\n#endif\n\n\tchild = fork();\n\tif(child == -1) {\n\t\tprintf(\"fork failed\\n\");\n\t\tgoto failed;\n\t}\n\n\tif(child == 0) {\n\t\tclose(STDOUT_FILENO);\n\t\tres = dup(pipefd[1]);\n\t\tif(res == -1) {\n\t\t\tprintf(\"dup failed\\n\");\n\t\t\texit(EXIT_FAILURE);\n\t\t}\n\t\texecl(\"/bin/sh\", \"sh\", \"-c\", command, (char *) NULL);\n\t\tprintf(\"execl failed\\n\");\n\t\texit(EXIT_FAILURE);\n\t}\n\n#ifdef USE_TMP_FILE\n\tres = waitpid(child, &status, 0);\n\tclose(pipefd[1]);\n\tif(res != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0) {\n\t\tdev->filename = strdup(filename);\n\t\treturn 0;\n\t}\nfailed:\n\tunlink(filename);\n\treturn -1;\n#else\n\tclose(pipefd[1]);\n\tdev->fd = pipefd[0];\n\tdev->child = child;\n\treturn 0;\nfailed:\n\treturn -1;\n#endif\n}\n\n\nvoid add_pseudo_file(struct pseudo_dev *dev)\n{\n\tpseudo_file = realloc(pseudo_file, (pseudo_count + 1) *\n\t\tsizeof(struct pseudo_dev *));\n\tif(pseudo_file == NULL)\n\t\tBAD_ERROR(\"Failed to realloc pseudo_file\\n\");\n\n\tdev->pseudo_id = pseudo_count;\n\tpseudo_file[pseudo_count ++] = dev;\n}\n\n\nvoid delete_pseudo_files()\n{\n#ifdef USE_TMP_FILE\n\tint i;\n\n\tfor(i = 0; i < pseudo_count; i++)\n\t\tunlink(pseudo_file[i]->filename);\n#endif\n}\n\n\nstruct pseudo_dev *get_pseudo_file(int pseudo_id)\n{\n\treturn pseudo_file[pseudo_id];\n}\n\n\nint read_pseudo_def(struct pseudo **pseudo, char *def)\n{\n\tint n, bytes;\n\tunsigned int major = 0, minor = 0, mode;\n\tchar filename[2048], type, suid[100], sgid[100], *ptr;\n\tlong long uid, gid;\n\tstruct pseudo_dev *dev;\n\n\tn = sscanf(def, \"%s %c %o %s %s %n\", filename, &type, &mode, suid,\n\t\t\tsgid, &bytes);\n\n\tif(n < 5) {\n\t\tERROR(\"Not enough or invalid arguments in pseudo file \"\n\t\t\t\"definition\\n\");\n\t\tgoto error;\n\t}\n\n\tswitch(type) {\n\tcase 'b':\n\tcase 'c':\n\t\tn = sscanf(def + bytes,  \"%u %u\", &major, &minor);\n\n\t\tif(n < 2) {\n\t\t\tERROR(\"Not enough or invalid arguments in pseudo file \"\n\t\t\t\t\"definition\\n\");\n\t\t\tgoto error;\n\t\t}\t\n\t\t\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range\\n\", major);\n\t\t\tgoto error;\n\t\t}\n\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range\\n\", minor);\n\t\t\tgoto error;\n\t\t}\n\n\tcase 'f':\n\t\tif(def[bytes] == '\\0') {\n\t\t\tERROR(\"Not enough arguments in pseudo file \"\n\t\t\t\t\"definition\\n\");\n\t\t\tgoto error;\n\t\t}\t\n\t\tbreak;\n\tcase 'd':\n\tcase 'm':\n\t\tbreak;\n\tdefault:\n\t\tERROR(\"Unsupported type %c\\n\", type);\n\t\tgoto error;\n\t}\n\n\n\tif(mode > 0777) {\n\t\tERROR(\"Mode %o out of range\\n\", mode);\n\t\tgoto error;\n\t}\n\n\tuid = strtoll(suid, &ptr, 10);\n\tif(*ptr == '\\0') {\n\t\tif(uid < 0 || uid > ((1LL << 32) - 1)) {\n\t\t\tERROR(\"Uid %s out of range\\n\", suid);\n\t\t\tgoto error;\n\t\t}\n\t} else {\n\t\tstruct passwd *pwuid = getpwnam(suid);\n\t\tif(pwuid)\n\t\t\tuid = pwuid->pw_uid;\n\t\telse {\n\t\t\tERROR(\"Uid %s invalid uid or unknown user\\n\", suid);\n\t\t\tgoto error;\n\t\t}\n\t}\n\t\t\n\tgid = strtoll(sgid, &ptr, 10);\n\tif(*ptr == '\\0') {\n\t\tif(gid < 0 || gid > ((1LL << 32) - 1)) {\n\t\t\tERROR(\"Gid %s out of range\\n\", sgid);\n\t\t\tgoto error;\n\t\t}\n\t} else {\n\t\tstruct group *grgid = getgrnam(sgid);\n\t\tif(grgid)\n\t\t\tgid = grgid->gr_gid;\n\t\telse {\n\t\t\tERROR(\"Gid %s invalid uid or unknown user\\n\", sgid);\n\t\t\tgoto error;\n\t\t}\n\t}\n\n\tswitch(type) {\n\tcase 'b':\n\t\tmode |= S_IFBLK;\n\t\tbreak;\n\tcase 'c':\n\t\tmode |= S_IFCHR;\n\t\tbreak;\n\tcase 'd':\n\t\tmode |= S_IFDIR;\n\t\tbreak;\n\tcase 'f':\n\t\tmode |= S_IFREG;\n\t\tbreak;\n\t}\n\n\tdev = malloc(sizeof(struct pseudo_dev));\n\tif(dev == NULL)\n\t\tBAD_ERROR(\"Failed to create pseudo_dev\\n\");\n\n\tdev->type = type;\n\tdev->mode = mode;\n\tdev->uid = uid;\n\tdev->gid = gid;\n\tdev->major = major;\n\tdev->minor = minor;\n\n\tif(type == 'f') {\n\t\tint res;\n\n\t\tprintf(\"Executing dynamic pseudo file\\n\");\n\t\tprintf(\"\\t\\\"%s\\\"\\n\", def);\n\t\tres = exec_file(def + bytes, dev);\n\t\tif(res == -1) {\n\t\t\tERROR(\"Failed to execute dynamic pseudo file definition\"\n\t\t\t\t\" \\\"%s\\\"\\n\", def);\n\t\t\treturn FALSE;\n\t\t}\n\t\tadd_pseudo_file(dev);\n\t}\n\n\t*pseudo = add_pseudo(*pseudo, dev, filename, filename);\n\n\treturn TRUE;\n\nerror:\n\tERROR(\"Bad pseudo file definition \\\"%s\\\"\\n\", def);\n\treturn FALSE;\n}\n\t\t\n\nint read_pseudo_file(struct pseudo **pseudo, char *filename)\n{\n\tFILE *fd;\n\tchar line[2048];\n\tint res = TRUE;\n\n\tfd = fopen(filename, \"r\");\n\tif(fd == NULL) {\n\t\tERROR(\"Could not open pseudo device file \\\"%s\\\" because %s\\n\",\n\t\t\t\tfilename, strerror(errno));\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%2047[^\\n]\\n\", line) > 0) {\n\t\tres = read_pseudo_def(pseudo, line);\n\t\tif(res == FALSE)\n\t\t\tbreak;\n\t};\n\tfclose(fd);\n\treturn res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/pseudo.h",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * pseudo.h\n */\nstruct pseudo_dev {\n\tchar\t\ttype;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tgid;\n\tunsigned int\tmajor;\n\tunsigned int\tminor;\n\tint\t\tpseudo_id;\n\tint\t\tfd;\n\tint\t\tchild;\n#ifdef USE_TMP_FILE\n\tchar\t\t*filename;\n#endif\n};\n\nstruct pseudo_entry {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct pseudo\t\t*pseudo;\n\tstruct pseudo_dev\t*dev;\n};\n\t\nstruct pseudo {\n\tint\t\t\tnames;\n\tint\t\t\tcount;\n\tstruct pseudo_entry\t*name;\n};\n\nextern int read_pseudo_def(struct pseudo **, char *);\nextern int read_pseudo_file(struct pseudo **, char *);\nextern struct pseudo *pseudo_subdir(char *, struct pseudo *);\nextern struct pseudo_entry *pseudo_readdir(struct pseudo *);\nextern struct pseudo_dev *get_pseudo_file(int);\nextern void delete_pseudo_files();\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_destination(int, long long, int, char *);\nextern int add_file(long long, long long, long long, unsigned int *, int,\n\tunsigned int, int, int);\nextern void *create_id(unsigned int);\nextern unsigned int get_uid(unsigned int);\nextern unsigned int get_guid(unsigned int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n#include \"global.h\"\n#include \"compressor.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstatic struct compressor *comp;\n\nint read_block(int fd, long long start, long long *next, void *block,\n\tsquashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tread_destination(fd, start, 2, (char *)&c_byte);\n\tSQUASHFS_INSWAP_SHORTS(&c_byte, 1);\n\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint error, res;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_destination(fd, start + offset, c_byte, buffer);\n\n\t\tres = comp->uncompress(block, buffer, c_byte,\n\t\t\tSQUASHFS_METADATA_SIZE, &error);\n\t\tif(res == -1) {\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn res;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_destination(fd, start + offset, c_byte, block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end,\n\tlong long root_inode_start, int root_inode_offset,\n\tsquashfs_super_block *sBlk, squashfs_inode_header *dir_inode,\n\tunsigned char **inode_table, unsigned int *root_inode_block,\n\tunsigned int *root_inode_size, long long *uncompressed_file,\n\tunsigned int *uncompressed_directory, int *file_count, int *sym_count,\n\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\tunsigned int *id_table)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start \"\n\t\t\"0x%llx\\n\", start, end, root_inode_start);\n\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx \"\n\t\t\t\t\"containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE) {\n\t\t\t*inode_table = realloc(*inode_table, size\n\t\t\t\t+= SQUASHFS_METADATA_SIZE);\n\t\t\tif(*inode_table == NULL)\n\t\t\t\treturn FALSE;\n\t\t}\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tbyte = read_block(fd, start, &start, *inode_table + bytes,\n\t\t\tsBlk);\n\t\tif(byte == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain\n\t * the last directory start block index.  This is used when calculating\n\t * the total uncompressed directory size.  The directory bytes in the\n\t * last * block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base,\n\t\t\t(squashfs_base_inode_header *) (*inode_table + bytes));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir,\n\t\t\t(squashfs_dir_inode_header *) (*inode_table + bytes));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir,\n\t\t\t(squashfs_ldir_inode_header *) (*inode_table + bytes));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\tget_uid(id_table[dir_inode->base.uid]);\n\tget_guid(id_table[dir_inode->base.guid]);\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode,\n\t\t\t(squashfs_reg_inode_header *) cur_ptr);\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position \"\n\t\t\t\"0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\tinode.inode_type);\n\n\t\tget_uid(id_table[inode.uid]);\n\t\tget_guid(id_table[inode.guid]);\n\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? 0 :\n\t\t\t\t\tinode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >>\n\t\t\t\t\tsBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, \"\n\t\t\t\t\t\"file_size %d, blocks %d\\n\",\n\t\t\t\t\tinode.file_size, blocks);\n\n\t\t\t\tblock_list = malloc(blocks *\n\t\t\t\t\tsizeof(unsigned int));\n\t\t\t\tif(block_list == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list \"\n\t\t\t\t\t\t\"malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tSQUASHFS_SWAP_INTS(block_list,\n\t\t\t\t\t(unsigned int *) cur_ptr, blocks);\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes +=\n\t\t\t\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t\t(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes,\n\t\t\t\t\tblock_list, blocks, inode.fragment,\n\t\t\t\t\tinode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode,\n\t\t\t\t\t(squashfs_lreg_inode_header *) cur_ptr);\n\n\t\t\t\tfrag_bytes = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? 0 :\n\t\t\t\t\tinode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t\t?  (inode.file_size +\n\t\t\t\t\tsBlk->block_size - 1) >>\n\t\t\t\t\tsBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular \"\n\t\t\t\t\t\"file, file_size %lld, blocks %d\\n\",\n\t\t\t\t\tinode.file_size, blocks);\n\n\t\t\t\tblock_list = malloc(blocks *\n\t\t\t\t\tsizeof(unsigned int));\n\t\t\t\tif(block_list == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list \"\n\t\t\t\t\t\t\"malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tSQUASHFS_SWAP_INTS(block_list,\n\t\t\t\t\t(unsigned int *) cur_ptr, blocks);\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes +=\n\t\t\t\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t\t(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes,\n\t\t\t\t\tblock_list, blocks, inode.fragment,\n\t\t\t\t\tinode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep,\n\t\t\t\t\t(squashfs_symlink_inode_header *)\n\t\t\t\t\tcur_ptr);\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode,\n\t\t\t\t\t(squashfs_dir_inode_header *) cur_ptr);\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory +=\n\t\t\t\t\tdir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode,\n\t\t\t\t\t(squashfs_ldir_inode_header *) cur_ptr);\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory +=\n\t\t\t\t\tdir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index,\n\t\t\t\t\t\t(squashfs_dir_index *) cur_ptr);\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) +\n\t\t\t\t\t\tindex.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in \"\n\t\t\t\t\t\"scan_inode_table!\\n\",\n\t\t\t\t\tinode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nstruct compressor *read_super(int fd, squashfs_super_block *sBlk, char *source)\n{\n\tread_destination(fd, SQUASHFS_START, sizeof(squashfs_super_block),\n\t\t(char *) sBlk);\n\tSQUASHFS_INSWAP_SUPER_BLOCK(sBlk);\n\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP)\n\t\t\tERROR(\"Pre 4.0 big-endian filesystem on %s, appending\"\n\t\t\t\t\" to this is unsupported\\n\", source);\n\t\telse\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n\t\t\t\tsource);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 4)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.\"\n\t\t\t\t\"  Appending\\nto SQUASHFS %d.%d filesystems is \"\n\t\t\t\t\"not supported.  Please convert it to a \"\n\t\t\t\t\"SQUASHFS 4 filesystem\\n\", source,\n\t\t\t\tsBlk->s_major,\n\t\t\t\tsBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Filesystem on %s is %d.%d, which is a later \"\n\t\t\t\t\"filesystem version than I support\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the compression type */\n\tcomp = lookup_compressor_id(sBlk->compression);\n\tif(!comp->supported) {\n\t\tERROR(\"Filesystem on %s uses %s compression, this is\"\n\t\t\t\"unsupported by this version\\n\", source, comp->name);\n\t\tdisplay_compressors(\"\", \"\");\n\t\tgoto failed_mount;\n\t}\n\n\tprintf(\"Found a valid %sSQUASHFS superblock on %s.\\n\",\n\t\tSQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", source);\n\tprintf(\"\\tCompression used %s\\n\", comp->name);\n\tprintf(\"\\tInodes are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\",\n\t\tSQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\",\n\t\tSQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\",\n\t\tSQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\",\n\t\tsBlk->bytes_used / 1024.0, sBlk->bytes_used\n\t\t/ (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of ids %d\\n\", sBlk->no_ids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\",\n\t\tsBlk->directory_table_start);\n\tTRACE(\"sBlk->id_table_start %llx\\n\", sBlk->id_table_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %llx\\n\", sBlk->lookup_table_start);\n\tprintf(\"\\n\");\n\n\treturn comp;\n\nfailed_mount:\n\treturn NULL;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries,\n\tunsigned int directory_start_block, int offset, int size,\n\tunsigned int *last_directory_block, squashfs_super_block *sBlk,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block,\n\t\tlast_start_block = start; \n\n\tsize += offset;\n\tdirectory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) &\n\t\t~(SQUASHFS_METADATA_SIZE - 1));\n\tif(directory_table == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so \"\n\t\t\t\"far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tbyte = read_block(fd, start, &start, directory_table + bytes,\n\t\t\tsBlk);\n\t\tif(byte == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh,\n\t\t\t(squashfs_dir_header *) (directory_table + bytes));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position \"\n\t\t\t\"0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire,\n\t\t\t\t(squashfs_dir_entry *)\n\t\t\t\t(directory_table + bytes));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, \"\n\t\t\t\t\"inode %x:%x, type 0x%x\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name,\n\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n\t\t\t\tdire->offset), dirh.inode_number +\n\t\t\t\tdire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block -\n\t\tsBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nunsigned int *read_id_table(int fd, squashfs_super_block *sBlk)\n{\n\tint indexes = SQUASHFS_ID_BLOCKS(sBlk->no_ids);\n\tlong long index[indexes];\n\tint bytes = SQUASHFS_ID_BYTES(sBlk->no_ids);\n\tunsigned int *id_table;\n\tint i;\n\n\tid_table = malloc(bytes);\n\tif(id_table == NULL) {\n\t\tERROR(\"Failed to allocate id table\\n\");\n\t\treturn NULL;\n\t}\n\n\tread_destination(fd, sBlk->id_table_start,\n\t\tSQUASHFS_ID_BLOCK_BYTES(sBlk->no_ids), (char *) index);\n\tSQUASHFS_INSWAP_ID_BLOCKS(index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) id_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read id table block %d, from 0x%llx, length %d\\n\", i,\n\t\t\tindex[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read id table block %d, from 0x%llx, \"\n\t\t\t\t\"length %d\\n\", i, index[i], length);\n\t\t\tfree(id_table);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_INTS(id_table, sBlk->no_ids);\n\n\tfor(i = 0; i < sBlk->no_ids; i++) {\n\t\tTRACE(\"Adding id %d to id tables\\n\", id_table[i]);\n\t\tcreate_id(id_table[i]);\n\t}\n\n\treturn id_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk,\n\tsquashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk->fragments, indexes,\n\t\tsBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\t*fragment_table = malloc(sBlk->fragments *\n\t\tsizeof(squashfs_fragment_entry));\n\tif(*fragment_table == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tread_destination(fd, sBlk->fragment_table_start,\n\t\tSQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments),\n\t\t(char *) fragment_table_index);\n\tSQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((unsigned char *) *fragment_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read fragment table block %d, from \"\n\t\t\t\t\"0x%llx, length %d\\n\", i,\n\t\t\t\tfragment_table_index[i], length);\n\t\t\tfree(*fragment_table);\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tfor(i = 0; i < sBlk->fragments; i++)\n\t\tSQUASHFS_INSWAP_FRAGMENT_ENTRY(&(*fragment_table)[i]);\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, squashfs_super_block *sBlk,\n\tsquashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\t*inode_lookup_table = malloc(lookup_bytes);\n\tif(*inode_lookup_table == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tread_destination(fd, sBlk->lookup_table_start,\n\t\tSQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);\n\tSQUASHFS_INSWAP_LONG_LONGS(index, indexes);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) *inode_lookup_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length \"\n\t\t\t\"%d\\n\", i, index[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read inode lookup table block %d, \"\n\t\t\t\t\"from 0x%llx, length %d\\n\", i, index[i],\n\t\t\t\tlength);\n\t\t\tfree(*inode_lookup_table);\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_LONG_LONGS(*inode_lookup_table, sBlk->inodes);\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk,\n\tchar **cinode_table, char **data_cache, char **cdirectory_table,\n\tchar **directory_data_cache, unsigned int *last_directory_block,\n\tunsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block,\n\tint *file_count, int *sym_count, int *dev_count, int *dir_count,\n\tint *fifo_count, int *sock_count, long long *uncompressed_file,\n\tunsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\tunsigned int *inode_dir_inode_number,\n\tunsigned int *inode_dir_parent_inode,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\tsquashfs_fragment_entry **fragment_table,\n\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start;\n\tlong long end = sBlk->directory_table_start;\n\tlong long root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk->root_inode);\n\tunsigned int root_inode_block, files;\n\tsquashfs_inode_header inode;\n\tunsigned int *id_table;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tid_table = read_id_table(fd, sBlk);\n\tif(id_table == NULL)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start,\n\t\t\troot_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file,\n\t\t\tuncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count, id_table))\n\t\t\t== 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE ||\n\t\t\tinode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tdirectory_table = squashfs_readdir(fd, !root_name,\n\t\t\t*inode_dir_start_block, *inode_dir_offset,\n\t\t\t*inode_dir_file_size, last_directory_block, sBlk,\n\t\t\tpush_directory_entry);\n\t\tif(directory_table == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\"\n\t\t\t\t\"\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\t*cinode_table = malloc(root_inode_start);\n\t\tif(*cinode_table == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for \"\n\t\t\t\t\"existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_destination(fd, start, root_inode_start, *cinode_table);\n\n\t\t*cdirectory_table = malloc(*last_directory_block);\n\t\tif(*cdirectory_table == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for \"\n\t\t\t\t\"existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_destination(fd, sBlk->directory_table_start,\n\t\t\t*last_directory_block, *cdirectory_table);\n\n\t\t*data_cache = malloc(root_inode_offset + *root_inode_size);\n\t\tif(*data_cache == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block,\n\t\t\troot_inode_offset + *root_inode_size);\n\n\t\t*directory_data_cache = malloc(*inode_dir_offset +\n\t\t\t*inode_dir_file_size);\n\t\tif(*directory_data_cache == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory \"\n\t\t\t\t\"cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table,\n\t\t\t*inode_dir_offset + *inode_dir_file_size);\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/read_fs.h",
    "content": "#ifndef READ_FS_H\n#define READ_FS_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.h\n *\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define SQUASHFS_SWAP_SHORTS(d, s, n) swap_le16_num(s, d, n)\n#define SQUASHFS_SWAP_INTS(d, s, n) swap_le32_num(s, d, n)\n#define SQUASHFS_SWAP_LONG_LONGS(d, s, n) swap_le64_num(s, d, n)\n\n#define SWAP_LE16(d, s, field)\tswap_le16(&((s)->field), &((d)->field))\n#define SWAP_LE32(d, s, field)\tswap_le32(&((s)->field), &((d)->field))\n#define SWAP_LE64(d, s, field)\tswap_le64(&((s)->field), &((d)->field))\n#define SWAP_LES16(d, s, field)\tswap_le16((unsigned short *) &((s)->field), \\\n\t\t\t\t(unsigned short *) &((d)->field))\n#else\n#define SQUASHFS_MEMCPY(d, s, n)\tmemcpy(d, s, n)\n#define SQUASHFS_SWAP_SHORTS(d, s, n)\tmemcpy(d, s, n * sizeof(short))\n#define SQUASHFS_SWAP_INTS(d, s, n)\tmemcpy(d, s, n * sizeof(int))\n#define SQUASHFS_SWAP_LONG_LONGS(d, s, n) \\\n\t\t\t\t\tmemcpy(d, s, n * sizeof(long long))\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority,\n\t\t\t\tfilename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 ||\n\t\t\tstrncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino \"\n\t\t\t\"%llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is \"\n\t\t\t\"supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry\");\n\t        ERROR(\" should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to \"\n\t\t\t\"$PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source \"\n\t\t\t\"directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory \"\n\t\t\t\"test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more \"\n\t\t\t\"than one source entry!  Please use an absolute path.\"\n\t\t\t\"\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority,\n\tstruct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->inode->root_entry)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent,\n\t\t\t\t\tget_priority(dir_ent->pathname, buf,\n\t\t\t\t\tpriority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority,\n\t\t\t\t\tbuf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source,\n\t\t\t\tsource_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of \"\n\t\t\t\t\"-32767:32768 - skipping...\\n\", sort_filename,\n\t\t\t\tpriority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\twrite_file(&inode, entry->dir, &duplicate_file);\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\"\n\t\t\t\t\t\"\\n\", entry->dir->pathname,\n\t\t\t\t\t(long long)\n\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes \"\n\t\t\t\t\t\"LINK\\n\", entry->dir->pathname,\n\t\t\t\t\t(long long)\n\t\t\t\t\tentry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n};\n\nstruct inode_info {\n\tstruct stat\t\tbuf;\n\tstruct inode_info\t*next;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\tnlink;\n\tint\t\t\tpseudo_id;\n\tchar\t\t\ttype;\n\tchar\t\t\tread;\n\tchar\t\t\troot_entry;\n\tchar\t\t\tpseudo_file;\n};\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/squashfs_compat.h",
    "content": "#ifndef SQUASHFS_COMPAT\n#define SQUASHFS_COMPAT\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_compat.h\n */\n\n/*\n * definitions for structures on disk - layout 3.x\n */\n\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\nstruct squashfs_super_block_3 {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index_3 {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER_3\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index_3\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_3 {\n\tstruct squashfs_base_inode_header_3\tbase;\n\tstruct squashfs_dev_inode_header_3\tdev;\n\tstruct squashfs_symlink_inode_header_3\tsymlink;\n\tstruct squashfs_reg_inode_header_3\treg;\n\tstruct squashfs_lreg_inode_header_3\tlreg;\n\tstruct squashfs_dir_inode_header_3\tdir;\n\tstruct squashfs_ldir_inode_header_3\tldir;\n\tstruct squashfs_ipc_inode_header_3\tipc;\n};\n\t\nstruct squashfs_dir_entry_3 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header_3 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_3 {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\n\ntypedef struct squashfs_super_block_3 squashfs_super_block_3;\ntypedef struct squashfs_dir_index_3 squashfs_dir_index_3;\ntypedef struct squashfs_base_inode_header_3 squashfs_base_inode_header_3;\ntypedef struct squashfs_ipc_inode_header_3 squashfs_ipc_inode_header_3;\ntypedef struct squashfs_dev_inode_header_3 squashfs_dev_inode_header_3;\ntypedef struct squashfs_symlink_inode_header_3 squashfs_symlink_inode_header_3;\ntypedef struct squashfs_reg_inode_header_3 squashfs_reg_inode_header_3;\ntypedef struct squashfs_lreg_inode_header_3 squashfs_lreg_inode_header_3;\ntypedef struct squashfs_dir_inode_header_3 squashfs_dir_inode_header_3;\ntypedef struct squashfs_ldir_inode_header_3 squashfs_ldir_inode_header_3;\ntypedef struct squashfs_dir_entry_3 squashfs_dir_entry_3;\ntypedef struct squashfs_dir_header_3 squashfs_dir_header_3;\ntypedef struct squashfs_fragment_entry_3 squashfs_fragment_entry_3;\ntypedef union squashfs_inode_header_3 squashfs_inode_header_3;\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block_3));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_3(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_3))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_3)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_3));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_3));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_3));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T_3(s, d) SQUASHFS_SWAP_LONG_LONGS_3(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_3));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_3(A)\t((A) * sizeof(struct squashfs_fragment_entry_3))\n\n#define SQUASHFS_FRAGMENT_INDEX_3(A)\t(SQUASHFS_FRAGMENT_BYTES_3(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_3(A)\t(SQUASHFS_FRAGMENT_BYTES_3(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_3(A)\t((SQUASHFS_FRAGMENT_BYTES_3(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_3(A)\t(SQUASHFS_FRAGMENT_INDEXES_3(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/*\n * definitions for structures on disk - layout 1.x\n */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\ntypedef union squashfs_inode_header_1 squashfs_inode_header_1;\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n/*\n * definitions for structures on disk - layout 2.x\n */\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\ntypedef union squashfs_inode_header_2 squashfs_inode_header_2;\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS_3(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t((A) * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t4\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_IDS\t\t\t65536\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_MKFLAGS(noi, nod, nof, no_frag, always_frag, \\\n\t\tduplicate_checking, exportable)\t(noi | (nod << 1) | \\\n\t\t(nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6) | (exportable << 7))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n#define SQUASHFS_LSYMLINK_TYPE\t\t10\n#define SQUASHFS_LBLKDEV_TYPE\t\t11\n#define SQUASHFS_LCHRDEV_TYPE\t\t12\n#define SQUASHFS_LFIFO_TYPE\t\t13\n#define SQUASHFS_LSOCKET_TYPE\t\t14\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode_t))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* uid lookup table defines */\n#define SQUASHFS_ID_BYTES(A)\t((A) * sizeof(unsigned int))\n\n#define SQUASHFS_ID_BLOCK(A)\t\t(SQUASHFS_ID_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCK_OFFSET(A)\t\t(SQUASHFS_ID_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCKS(A)\t((SQUASHFS_ID_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCK_BYTES(A)\t(SQUASHFS_ID_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\n#define ZLIB_COMPRESSION\t1\n#define LZMA_COMPRESSION\t2\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned short\t\tcompression;\n\tunsigned short\t\tblock_log;\n\tunsigned short\t\tflags;\n\tunsigned short\t\tno_ids;\n\tunsigned short\t\ts_major;\n\tunsigned short\t\ts_minor;\n\tsquashfs_inode_t\troot_inode;\n\tlong long\t\tbytes_used;\n\tlong long\t\tid_table_start;\n\tlong long\t\txattr_table_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n};\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\tname[0];\n};\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned short\t\tinode_type;\t\\\n\tunsigned short\t\tmode;\t\\\n\tunsigned short\t\tuid;\t\t\\\n\tunsigned short\t\tguid;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n};\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n};\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\trdev;\n};\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n};\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned int\t\tblock_list[0];\n};\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tlong long\t\tfile_size;\n\tlong long\t\tsparse;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\txattr;\n\tunsigned int\t\tblock_list[0];\n};\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tfile_size;\n\tunsigned short\t\toffset;\n\tunsigned int\t\tparent_inode;\n};\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n\tunsigned short\t\ti_count;\n\tunsigned short\t\toffset;\n\tunsigned int\t\txattr;\n\tstruct squashfs_dir_index\tindex[0];\n};\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned short\t\toffset;\n\tshort\t\t\tinode_number;\n\tunsigned short\t\ttype;\n\tunsigned short\t\tsize;\n\tchar\t\t\tname[0];\n};\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n};\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tunused;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/squashfs_swap.h",
    "content": "#ifndef SQUASHFS_SWAP_H\n#define SQUASHFS_SWAP_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_swap.h\n */\n\n/*\n * macros to convert each stucture from big endian to little endian\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\nextern void swap_le16(unsigned short *, unsigned short *);\nextern void swap_le32(unsigned int *, unsigned int *);\nextern void swap_le64(long long *, long long *);\nextern void swap_le16_num(unsigned short *, unsigned short *, int);\nextern void swap_le32_num(unsigned int *, unsigned int *, int);\nextern void swap_le64_num(long long *, long long *, int);\nextern unsigned short inswap_le16(unsigned short);\nextern unsigned int inswap_le32(unsigned int);\nextern long long inswap_le64(long long);\nextern void inswap_le16_num(unsigned short *, int);\nextern void inswap_le32_num(unsigned int *, int);\nextern void inswap_le64_num(long long *, int);\n\n#define _SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##32(s, d, s_magic);\\\n\tSWAP_FUNC##32(s, d, inodes);\\\n\tSWAP_FUNC##32(s, d, mkfs_time);\\\n\tSWAP_FUNC##32(s, d, block_size);\\\n\tSWAP_FUNC##32(s, d, fragments);\\\n\tSWAP_FUNC##16(s, d, compression);\\\n\tSWAP_FUNC##16(s, d, block_log);\\\n\tSWAP_FUNC##16(s, d, flags);\\\n\tSWAP_FUNC##16(s, d, no_ids);\\\n\tSWAP_FUNC##16(s, d, s_major);\\\n\tSWAP_FUNC##16(s, d, s_minor);\\\n\tSWAP_FUNC##64(s, d, root_inode);\\\n\tSWAP_FUNC##64(s, d, bytes_used);\\\n\tSWAP_FUNC##64(s, d, id_table_start);\\\n\tSWAP_FUNC##64(s, d, xattr_table_start);\\\n\tSWAP_FUNC##64(s, d, inode_table_start);\\\n\tSWAP_FUNC##64(s, d, directory_table_start);\\\n\tSWAP_FUNC##64(s, d, fragment_table_start);\\\n\tSWAP_FUNC##64(s, d, lookup_table_start);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##32(s, d, index);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, size);\\\n}\n\n#define _SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n}\n\n#define _SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n}\n\n#define _SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##32(s, d, rdev);\\\n}\n\n#define _SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##32(s, d, symlink_size);\\\n}\n\n#define _SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, fragment);\\\n\tSWAP_FUNC##32(s, d, offset);\\\n\tSWAP_FUNC##32(s, d, file_size);\\\n}\n\n#define _SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##64(s, d, start_block);\\\n\tSWAP_FUNC##64(s, d, file_size);\\\n\tSWAP_FUNC##64(s, d, sparse);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##32(s, d, fragment);\\\n\tSWAP_FUNC##32(s, d, offset);\\\n\tSWAP_FUNC##32(s, d, xattr);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##16(s, d, file_size);\\\n\tSWAP_FUNC##16(s, d, offset);\\\n\tSWAP_FUNC##32(s, d, parent_inode);\\\n}\n\n#define _SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, inode_type);\\\n\tSWAP_FUNC##16(s, d, mode);\\\n\tSWAP_FUNC##16(s, d, uid);\\\n\tSWAP_FUNC##16(s, d, guid);\\\n\tSWAP_FUNC##32(s, d, mtime);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n\tSWAP_FUNC##32(s, d, nlink);\\\n\tSWAP_FUNC##32(s, d, file_size);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, parent_inode);\\\n\tSWAP_FUNC##16(s, d, i_count);\\\n\tSWAP_FUNC##16(s, d, offset);\\\n\tSWAP_FUNC##32(s, d, xattr);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##16(s, d, offset);\\\n\tSWAP_FUNC##S16(s, d, inode_number);\\\n\tSWAP_FUNC##16(s, d, type);\\\n\tSWAP_FUNC##16(s, d, size);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##32(s, d, count);\\\n\tSWAP_FUNC##32(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, inode_number);\\\n}\n\n#define _SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC##64(s, d, start_block);\\\n\tSWAP_FUNC##32(s, d, size);\\\n}\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d)\t\\\n\t\t\t_SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \\\n\t\t\t_SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#define SQUASHFS_INSWAP_SUPER_BLOCK(s) \\\n\t\t\t_SQUASHFS_SWAP_SUPER_BLOCK(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_INDEX(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INDEX(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_BASE_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_BASE_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_IPC_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_IPC_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DEV_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DEV_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_REG_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_REG_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LREG_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LREG_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LDIR_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_ENTRY(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_ENTRY(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s) \\\n\t\t\t_SQUASHFS_SWAP_FRAGMENT_ENTRY(s, s, INSWAP_LE)\n#define INSWAP_LE16(s, d, field)\t(s)->field = inswap_le16((s)->field)\n#define INSWAP_LE32(s, d, field)\t(s)->field = inswap_le32((s)->field)\n#define INSWAP_LE64(s, d, field)\t(s)->field = inswap_le64((s)->field)\n#define INSWAP_LES16(s, d, field) \\\n\t\t(s)->field = (short) inswap_le16((unsigned short) (s)->field)\n#define SQUASHFS_INSWAP_INODE_T(s) s = inswap_le64(s)\n#define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_ID_BLOCKS(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_SHORTS(s, n) inswap_le16_num(s, n)\n#define SQUASHFS_INSWAP_INTS(s, n) inswap_le32_num(s, n)\n#define SQUASHFS_INSWAP_LONG_LONGS(s, n) inswap_le64_num(s, n)\n#else\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d)\t\\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#define SQUASHFS_INSWAP_SUPER_BLOCK(s)\n#define SQUASHFS_INSWAP_DIR_INDEX(s)\n#define SQUASHFS_INSWAP_BASE_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_IPC_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DEV_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_REG_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LREG_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DIR_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DIR_ENTRY(s)\n#define SQUASHFS_INSWAP_DIR_HEADER(s)\n#define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s)\n#define SQUASHFS_INSWAP_INODE_T(s)\n#define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n)\n#define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n)\n#define SQUASHFS_INSWAP_ID_BLOCKS(s, n)\n#define SQUASHFS_INSWAP_SHORTS(s, n)\n#define SQUASHFS_INSWAP_INTS(s, n)\n#define SQUASHFS_INSWAP_LONG_LONGS(s, n)\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/swap.c",
    "content": "/*\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * swap.c\n */\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#if __BYTE_ORDER == __BIG_ENDIAN\nvoid swap_le16(unsigned short *src, unsigned short *dest)\n{\n\tunsigned char *s = (unsigned char *) src;\n\tunsigned char *d = (unsigned char *) dest;\n\n\td[0] = s[1];\n\td[1] = s[0];\n}\n\n\nvoid swap_le32(unsigned int *src, unsigned int *dest)\n{\n\tunsigned char *s = (unsigned char *) src;\n\tunsigned char *d = (unsigned char *) dest;\n\n\td[0] = s[3];\n\td[1] = s[2];\n\td[2] = s[1];\n\td[3] = s[0];\n}\n\n\nvoid swap_le64(long long *src, long long *dest)\n{\n\tunsigned char *s = (unsigned char *) src;\n\tunsigned char *d = (unsigned char *) dest;\n\n\td[0] = s[7];\n\td[1] = s[6];\n\td[2] = s[5];\n\td[3] = s[4];\n\td[4] = s[3];\n\td[5] = s[2];\n\td[6] = s[1];\n\td[7] = s[0];\n}\n\n\nunsigned short inswap_le16(unsigned short num)\n{\n\treturn (num >> 8) |\n\t\t((num & 0xff) << 8);\n}\n\n\nunsigned int inswap_le32(unsigned int num)\n{\n\treturn (num >> 24) |\n\t\t((num & 0xff0000) >> 8) |\n\t\t((num & 0xff00) << 8) |\n\t\t((num & 0xff) << 24);\n}\n\n\nlong long inswap_le64(long long n)\n{\n\tunsigned long long num = n;\n\n\treturn (num >> 56) |\n\t\t((num & 0xff000000000000LL) >> 40) |\n\t\t((num & 0xff0000000000LL) >> 24) |\n\t\t((num & 0xff00000000LL) >> 8) |\n\t\t((num & 0xff000000) << 8) |\n\t\t((num & 0xff0000) << 24) |\n\t\t((num & 0xff00) << 40) |\n\t\t((num & 0xff) << 56);\n}\n\n\n#define SWAP_LE_NUM(BITS, TYPE) \\\nvoid swap_le##BITS##_num(TYPE *s, TYPE *d, int n) \\\n{\\\n\tint i;\\\n\tfor(i = 0; i < n; i++, s++, d++)\\\n\t\tswap_le##BITS(s, d);\\\n}\n\nSWAP_LE_NUM(16, unsigned short)\nSWAP_LE_NUM(32, unsigned int)\nSWAP_LE_NUM(64, long long)\n\n#define INSWAP_LE_NUM(BITS, TYPE) \\\nvoid inswap_le##BITS##_num(TYPE *s, int n) \\\n{\\\n\tint i;\\\n\tfor(i = 0; i < n; i++)\\\n\t\ts[i] = inswap_le##BITS(s[i]);\\\n}\n\nINSWAP_LE_NUM(16, unsigned short)\nINSWAP_LE_NUM(32, unsigned int)\nINSWAP_LE_NUM(64, long long)\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/unsquash-1.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-1.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nvoid read_block_list_1(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tTRACE(\"read_block_list: blocks %d\\n\", blocks);\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS_3((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) |\n\t\t\t(SQUASHFS_COMPRESSED(block_size) ? 0 :\n\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nint read_fragment_table_1()\n{\n\tTRACE(\"read_fragment_table\\n\");\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_1 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"read_inode: inode table block %lld not found\\n\", start); \n\t\treturn NULL;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[(header.base.inode_type - 1) /\n\t\tSQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) %\n\t\t\tSQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n\n\ti.gid = header.base.guid == 15 ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\ti.sparse = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_1),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_1!\\n\",\n\t\t\t\theader.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_1(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\tif(((*i) = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes,\n\t\t\t\t\tsizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes,\n\t\t\t\t\tsizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc \"\n\t\t\t\t\t\t\"failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint read_uids_guids_1()\n{\n\tint res;\n\n\tTRACE(\"read_uids_guids: no_uids %d, no_guids %d\\n\", sBlk.no_uids,\n\t\tsBlk.no_guids);\n\n\tuid_table = malloc((sBlk.no_uids + sBlk.no_guids) *\n\t\tsizeof(unsigned int));\n\tif(uid_table == NULL) {\n\t\tERROR(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\t\treturn FALSE;\n\t}\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tres = read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t* sizeof(unsigned int), (char *) suid_table);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read uid/gid table\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_INTS_3(uid_table, suid_table,\n\t\t\tsBlk.no_uids + sBlk.no_guids);\n\t} else {\n\t\tres = read_bytes(sBlk.uid_start, (sBlk.no_uids + sBlk.no_guids)\n\t\t\t* sizeof(unsigned int), (char *) uid_table);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read uid/gid table\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/unsquash-2.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-2.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nstatic squashfs_fragment_entry_2 *fragment_table;\n\nvoid read_block_list_2(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tTRACE(\"read_block_list: blocks %d\\n\", blocks);\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS_3(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nint read_fragment_table_2()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.fragments, indexes,\n\t\tsBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn TRUE;\n\n\tfragment_table = malloc(sBlk.fragments *\n\t\tsizeof(squashfs_fragment_entry_2));\n\tif(fragment_table == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\t res = read_bytes(sBlk.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments),\n\t\t\t(char *) sfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index,\n\t\t\tsfragment_table_index, indexes);\n\t} else {\n\t\tres = read_bytes(sBlk.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.fragments),\n\t\t\t(char *) fragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%x, length %d\\n\", i,\n\t\t\tfragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table block\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment),\n\t\t\t\t(&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment,\n\t\t\t\tsizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_2(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_2 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"read_inode: inode table block %lld not found\\n\", start); \n\t\treturn NULL;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr,\n\t\t\t\t\tsizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr,\n\t\t\t\t\tsizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log : inode->file_size >>\n\t\t\t\tsBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_2),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode_header_2!\\n\",\n\t\t\t\theader.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/unsquash-3.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-3.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nstatic squashfs_fragment_entry_3 *fragment_table;\n\nint read_fragment_table_3()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES_3(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.fragments, indexes,\n\t\tsBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn TRUE;\n\n\tif((fragment_table = malloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry_3))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tres = read_bytes(sBlk.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.fragments),\n\t\t\t(char *) sfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_3(fragment_table_index,\n\t\t\tsfragment_table_index, indexes);\n\t} else {\n\t\tres = read_bytes(sBlk.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.fragments),\n\t\t\t(char *) fragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table block\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_3 sfragment;\n\t\tfor(i = 0; i < sBlk.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_3((&sfragment),\n\t\t\t\t(&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment,\n\t\t\t\tsizeof(squashfs_fragment_entry_3));\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_3(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_3 *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_3(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header_3 header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"read_inode: inode table block %lld not found\\n\", start); \n\t\treturn NULL;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_3 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_3(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_3));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_3 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_3(&header.dir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_3 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_3(&header.ldir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr,\n\t\t\t\t\tsizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_3 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_3(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log :\n\t\t\t\tinode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 1;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header_3 *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER_3(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log :\n\t\t\t\tinode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 1;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_3 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_3 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_3),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_3 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_3 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_3(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\",\n\t\t\t\theader.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_3(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header_3 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_3) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry_3 *dire = (squashfs_dir_entry_3 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\tif((*i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_3 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_3(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_3 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes,\n\t\t\t\t\tsizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_3(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes,\n\t\t\t\t\tsizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc \"\n\t\t\t\t\t\t\"failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/unsquash-4.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-4.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n\nstatic struct squashfs_fragment_entry *fragment_table;\nstatic unsigned int *id_table;\n\nint read_fragment_table_4()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.fragments, indexes,\n\t\tsBlk.fragment_table_start);\n\n\tif(sBlk.fragments == 0)\n\t\treturn TRUE;\n\n\tif((fragment_table = malloc(sBlk.fragments *\n\t\t\tsizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tres = read_bytes(sBlk.fragment_table_start,\n\t\tSQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.fragments),\n\t\t(char *) fragment_table_index);\n\tif(res == FALSE) {\n\t\tERROR(\"read_fragment_table: failed to read fragment table \"\n\t\t\t\"index\\n\");\n\t\treturn FALSE;\n\t}\n\tSQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < sBlk.fragments; i++) \n\t\tSQUASHFS_INSWAP_FRAGMENT_ENTRY(&fragment_table[i]);\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_4(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_4(unsigned int start_block, unsigned int offset)\n{\n\tstatic squashfs_inode_header header;\n\tlong long start = sBlk.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"read_inode: inode table block %lld not found\\n\", start); \t\t\n\t\treturn NULL;\n\t}\n\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base,\n\t\t(squashfs_base_inode_header *) block_ptr);\n\n\ti.uid = (uid_t) id_table[header.base.uid];\n\ti.gid = (uid_t) id_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inode,\n\t\t\t\t(squashfs_dir_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inode,\n\t\t\t\t(squashfs_ldir_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode,\n\t\t\t\t(squashfs_reg_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log :\n\t\t\t\tinode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode,\n\t\t\t\t(squashfs_lreg_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.block_size - 1) >>\n\t\t\t\tsBlk.block_log :\n\t\t\t\tinode->file_size >> sBlk.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = inode->sparse != 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\tcase SQUASHFS_LSYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inode = &header.symlink;\n\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inode,\n\t\t\t\t(squashfs_symlink_inode_header *) block_ptr);\n\n\t\t\ti.symlink = malloc(inode->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header),\n\t\t\t\tinode->symlink_size);\n\t\t\ti.symlink[inode->symlink_size] = '\\0';\n\t\t\ti.data = inode->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE:\n \t\tcase SQUASHFS_LBLKDEV_TYPE:\n\t \tcase SQUASHFS_LCHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inode = &header.dev;\n\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inode,\n\t\t\t\t(squashfs_dev_inode_header *) block_ptr);\n\n\t\t\ti.data = inode->rdev;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\tcase SQUASHFS_LFIFO_TYPE:\n\t\tcase SQUASHFS_LSOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in read_inode!\\n\",\n\t\t\t\theader.base.inode_type);\n\t\t\treturn NULL;\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_4(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\tif((*i = s_ops.read_inode(block_start, offset)) == NULL) {\n\t\tERROR(\"squashfs_opendir: failed to read directory inode %d\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tstart = sBlk.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\",\n\t\t\tblock_start);\n\t\treturn NULL;\n\t}\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, (squashfs_dir_header *)\n\t\t\t(directory_table + bytes));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, (squashfs_dir_entry *)\n\t\t\t\t(directory_table + bytes));\n\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc \"\n\t\t\t\t\t\t\"failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint read_uids_guids_4()\n{\n\tint res, i, indexes = SQUASHFS_ID_BLOCKS(sBlk.no_ids);\n\tlong long id_index_table[indexes];\n\n\tTRACE(\"read_uids_guids: no_ids %d\\n\", sBlk.no_ids);\n\n\tid_table = malloc(SQUASHFS_ID_BYTES(sBlk.no_ids));\n\tif(id_table == NULL) {\n\t\tERROR(\"read_uids_guids: failed to allocate id table\\n\");\n\t\treturn FALSE;\n\t}\n\n\tres = read_bytes(sBlk.id_table_start,\n\t\tSQUASHFS_ID_BLOCK_BYTES(sBlk.no_ids), (char *) id_index_table);\n\tif(res == FALSE) {\n\t\tERROR(\"read_uids_guids: failed to read id index table\\n\");\n\t\treturn FALSE;\n\t}\n\tSQUASHFS_INSWAP_ID_BLOCKS(id_index_table, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tres = read_block(id_index_table[i], NULL,\n\t\t\t((char *) id_table) + i * SQUASHFS_METADATA_SIZE);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read id table block\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_INTS(id_table, sBlk.no_ids);\n\n\treturn TRUE;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_swap.h\"\n#include \"squashfs_compat.h\"\n#include \"read_fs.h\"\n#include \"compressor.h\"\n\n#include <sys/sysinfo.h>\n\nstruct cache *fragment_cache, *data_cache;\nstruct queue *to_reader, *to_deflate, *to_writer, *from_writer;\npthread_t *thread, *deflator_thread;\npthread_mutex_t\tfragment_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n\nstruct super_block sBlk;\nsquashfs_operations s_ops;\nstruct compressor *comp;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nunsigned int block_log;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE;\nint use_regex = FALSE;\nchar **created_inode;\nint root_process;\nint columns;\nint rotate = 0;\npthread_mutex_t\tscreen_mutex;\npthread_cond_t progress_wait;\nint progress = TRUE, progress_enabled = FALSE;\nunsigned int total_blocks = 0, total_files = 0, total_inodes = 0;\nunsigned int cur_blocks = 0;\nint inode_number = 1;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0}\n};\n\nvoid progress_bar(long long current, long long max, int columns);\nvoid update_progress_bar();\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\treturn NULL;\n\n\tif((queue->data = malloc(sizeof(void *) * (size + 1))) == NULL) {\n\t\tfree(queue);\n\t\treturn NULL;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tint hash = CALCULATE_HASH(entry->block);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->block)] =\n\t\t\tentry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(cache->free_list) {\n\t\tentry->free_next = cache->free_list;\n\t\tentry->free_prev = cache->free_list->free_prev;\n\t\tcache->free_list->free_prev->free_next = entry;\n\t\tcache->free_list->free_prev = entry;\n\t} else {\n\t\tcache->free_list = entry;\n\t\tentry->free_prev = entry->free_next = entry;\n\t}\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->free_prev == NULL && entry->free_next == NULL)\n\t\t/* not in free list */\n\t\treturn;\n\telse if(entry->free_prev == entry && entry->free_next == entry) {\n\t\t/* only this entry in the free list */\n\t\tcache->free_list = NULL;\n\t} else {\n\t\t/* more than one entry in the free list */\n\t\tentry->free_next->free_prev = entry->free_prev;\n\t\tentry->free_prev->free_next = entry->free_next;\n\t\tif(cache->free_list == entry)\n\t\t\tcache->free_list = entry->free_next;\n\t}\n\n\tentry->free_prev = entry->free_next = NULL;\n}\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\treturn NULL;\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct cache_entry *) * 65536);\n\tcache->wait_free = FALSE;\n\tcache->wait_pending = FALSE;\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\tpthread_cond_init(&cache->wait_for_pending, NULL);\n\n\treturn cache;\n}\n\n\nstruct cache_entry *cache_get(struct cache *cache, long long block, int size)\n{\n\t/*\n\t * Get a block out of the cache.  If the block isn't in the cache\n \t * it is added and queued to the reader() and deflate() threads for\n \t * reading off disk and decompression.  The cache grows until max_blocks\n \t * is reached, once this occurs existing discarded blocks on the free\n \t * list are reused\n \t */\n\tint hash = CALCULATE_HASH(block);\n\tstruct cache_entry *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->block == block)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/*\n \t\t *found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(cache, entry);\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t} else {\n\t\t/*\n \t\t * not in the cache\n\t\t *\n\t\t * first try to allocate new block\n\t\t */\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\tentry = malloc(sizeof(struct cache_entry));\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->data = malloc(cache->buffer_size);\n\t\t\tif(entry->data == NULL) {\n\t\t\t\tfree(entry);\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t} else {\n\t\t\t/*\n\t\t\t * try to get from free list\n\t\t\t */\n\t\t\twhile(cache->free_list == NULL) {\n\t\t\t\tcache->wait_free = TRUE;\n\t\t\t\tpthread_cond_wait(&cache->wait_for_free,\n\t\t\t\t\t&cache->mutex);\n\t\t\t}\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(cache, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t}\n\n\t\t/*\n\t\t * initialise block and insert into the hash table\n\t\t */\n\t\tentry->block = block;\n\t\tentry->size = size;\n\t\tentry->used = 1;\n\t\tentry->error = FALSE;\n\t\tentry->pending = TRUE;\n\t\tinsert_hash_table(cache, entry);\n\n\t\t/*\n\t\t * queue to read thread to read and ultimately (via the\n\t\t * decompress threads) decompress the buffer\n \t\t */\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t\tqueue_put(to_reader, entry);\n\t}\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\treturn NULL;\n}\n\n\t\nvoid cache_block_ready(struct cache_entry *entry, int error)\n{\n\t/*\n\t * mark cache entry as being complete, reading and (if necessary)\n \t * decompression has taken place, and the buffer is valid for use.\n \t * If an error occurs reading or decompressing, the buffer also \n \t * becomes ready but with an error...\n \t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\tentry->pending = FALSE;\n\tentry->error = error;\n\n\t/*\n\t * if the wait_pending flag is set, one or more threads may be waiting\n\t * on this buffer\n\t */\n\tif(entry->cache->wait_pending) {\n\t\tentry->cache->wait_pending = FALSE;\n\t\tpthread_cond_broadcast(&entry->cache->wait_for_pending);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_wait(struct cache_entry *entry)\n{\n\t/*\n\t * wait for this cache entry to become ready, when reading and (if\n\t * necessary) decompression has taken place\n\t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\twhile(entry->pending) {\n\t\tentry->cache->wait_pending = TRUE;\n\t\tpthread_cond_wait(&entry->cache->wait_for_pending,\n\t\t\t&entry->cache->mutex);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_put(struct cache_entry *entry)\n{\n\t/*\n\t * finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and is put onto the free list.  As it remains\n \t * accessible via the hash table it can be found getting a new lease of\n \t * life before it is reused.\n \t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tinsert_free_list(entry->cache, entry);\n\n\t\t/*\n\t\t * if the wait_free flag is set, one or more threads may be\n\t\t * waiting on this buffer\n\t\t */\n\t\tif(entry->cache->wait_free) {\n\t\t\tentry->cache->wait_free = FALSE;\n\t\t\tpthread_cond_broadcast(&entry->cache->wait_for_free);\n\t\t}\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\tif((user = getpwuid(inode->uid)) == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tif((group = getgrgid(inode->gid)) == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) -\n\t\t\t\tstrlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0,\n\t\t\t\tinode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) -\n\t\t\t\tstrlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \",\n\t\t\t\t(int) inode->data >> 8, (int) inode->data &\n\t\t\t\t0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1,\n\t\tt->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n\nint add_entry(struct hash_table_entry *hash_table[], long long start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], long long start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\tint res, count;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte,\n\t\tbytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = read(fd, buff + count, bytes - count);\n\t\tif(res < 1) {\n\t\t\tif(res == 0) {\n\t\t\t\tERROR(\"Read on filesystem failed because EOF\\n\");\n\t\t\t\treturn FALSE;\n\t\t\t} else if(errno != EINTR) {\n\t\t\t\tERROR(\"Read on filesystem failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn FALSE;\n\t\t\t} else\n\t\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start,\n\t\tSQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ?\n\t\t\"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint error, res;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tres = comp->uncompress(block, buffer, c_byte,\n\t\t\tSQUASHFS_METADATA_SIZE, &error);\n\n\t\tif(res == -1) {\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn res;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\tERROR(\"read_block: failed to read block @0x%llx\\n\", start);\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint error, res;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start,\n\t\tc_byte, SQUASHFS_COMPRESSED_BLOCK(size) ? \"compressed\" :\n\t\t\"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\tgoto failed;\n\n\t\tres = comp->uncompress(block, data, c_byte, block_size, &error);\n\n\t\tif(res == -1) {\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\t\tgoto failed;\n\t\t}\n\n\t\treturn res;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\n\t\treturn c_byte;\n\t}\n\nfailed:\n\tERROR(\"read_data_block: failed to read block @0x%llx, size %d\\n\", start,\n\t\tc_byte);\n\treturn FALSE;\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\tTRACE(\"uncompress_inode_table: start %lld, end %lld\\n\", start, end);\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory \"\n\t\t\t\t\"in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tres = read_block(start, &start, inode_table + bytes);\n\t\tif(res == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read \"\n\t\t\t\t\"block \\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time,\n\tunsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids \"\n\t\t\t\t\"on %s, because %s\\n\", pathname,\n\t\t\t\tstrerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint write_bytes(int fd, char *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = write(fd, buff + count, bytes - count);\n\t\tif(res == -1) {\n\t\t\tif(errno != EINTR) {\n\t\t\t\tERROR(\"Write on output file failed because \"\n\t\t\t\t\t\"%s\\n\", strerror(errno));\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data = NULL;\n\nint write_block(int file_fd, char *buffer, int size, int hole, int sparse)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(sparse && lseek_broken == FALSE) {\n\t\t\t int error = lseek(file_fd, off, SEEK_CUR);\n\t\t\t if(error == -1)\n\t\t\t\t/* failed to seek beyond end of file */\n\t\t\t\tlseek_broken = TRUE;\n\t\t}\n\n\t\tif((sparse == FALSE || lseek_broken) && zero_data == NULL) {\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc \"\n\t\t\t\t\t\"zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t}\n\n\t\tif(sparse == FALSE || lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size :\n\t\t\t\t\thole;\n\t\t\t\tif(write_bytes(file_fd, zero_data, avail_bytes)\n\t\t\t\t\t\t== -1)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t}\n\n\tif(write_bytes(file_fd, buffer, size) == -1)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\nint write_file(struct inode *inode, char *pathname)\n{\n\tunsigned int file_fd, i;\n\tunsigned int *block_list;\n\tint file_end = inode->data / block_size;\n\tlong long start = inode->start;\n\tstruct squashfs_file *file;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", inode->blocks);\n\n\tfile_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0),\n\t\t(mode_t) inode->mode & 0777);\n\tif(file_fd == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif((block_list = malloc(inode->blocks * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc block list\\n\");\n\n\ts_ops.read_block_list(block_list, inode->block_ptr, inode->blocks);\n\n\tif((file = malloc(sizeof(struct squashfs_file))) == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\n\t/*\n\t * the writer thread is queued a squashfs_file structure describing the\n \t * file.  If the file has one or more blocks or a fragments they are\n \t * queued separately (references to blocks in the cache).\n \t */\n\tfile->fd = file_fd;\n\tfile->file_size = inode->data;\n\tfile->mode = inode->mode;\n\tfile->gid = inode->gid;\n\tfile->uid = inode->uid;\n\tfile->time = inode->time;\n\tfile->pathname = strdup(pathname);\n\tfile->blocks = inode->blocks + (inode->frag_bytes > 0);\n\tfile->sparse = inode->sparse;\n\tqueue_put(to_writer, file);\n\n\tfor(i = 0; i < inode->blocks; i++) {\n\t\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\tblock->offset = 0;\n\t\tblock->size = i == file_end ? inode->data & (block_size - 1) :\n\t\t\tblock_size;\n\t\tif(block_list[i] == 0) /* sparse file */\n\t\t\tblock->buffer = NULL;\n\t\telse {\n\t\t\tblock->buffer = cache_get(data_cache, start,\n\t\t\t\tblock_list[i]);\n\t\t\tif(block->buffer == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_file: cache_get failed\\n\");\n\t\t\tstart += c_byte;\n\t\t}\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tif(inode->frag_bytes) {\n\t\tint size;\n\t\tlong long start;\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\ts_ops.read_fragment(inode->fragment, &start, &size);\n\t\tblock->buffer = cache_get(fragment_cache, start, size);\n\t\tif(block->buffer == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: cache_get failed\\n\");\n\t\tblock->offset = inode->offset;\n\t\tblock->size = inode->frag_bytes;\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tfree(block_list);\n\treturn TRUE;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, \"\n\t\t\t\t\"because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, \"\n\t\t\t\t\"blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i, pathname))\n\t\t\t\tfile_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %lld\\n\",\n\t\t\t\ti->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink \"\n\t\t\t\t\t\"%s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change \"\n\t\t\t\t\t\t\"uid and gids on %s, because \"\n\t\t\t\t\t\t\"%s\\n\", pathname,\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%llx\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\t\tmakedev((i->data >> 8) & 0xff,\n\t\t\t\t\t\ti->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create \"\n\t\t\t\t\t\t\"%s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid,\n\t\t\t\t\ti->gid, i->time, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s \"\n\t\t\t\t\t\"device %s, because you're not \"\n\t\t\t\t\t\"superuser!\\n\", chrdev ? \"character\" :\n\t\t\t\t\t\"block\", pathname);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, \"\n\t\t\t\t\t\"because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid,\n\t\t\t\ti->time, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\",\n\t\t\t\ti->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\tTRACE(\"uncompress_directory_table: start %lld, end %lld\\n\", start, end);\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table =\n\t\t\t\trealloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of \"\n\t\t\t\t\"memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\",\n\t\t\t\tstart);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tres = read_block(start, &start, directory_table + bytes);\n\t\tif(res == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to \"\n\t\t\t\t\"read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tif((paths = malloc(sizeof(struct pathname))) == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/*\n\t\t * allocate new name entry\n\t\t */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) *\n\t\t\tsizeof(struct path_entry));\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\terror = regcomp(paths->name[i].preg, targname,\n\t\t\t\tREG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, \"\n\t\t\t\t\t\"because %s\\n\", targname, alltarget,\n\t\t\t\t\tstr);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/*\n\t\t\t * at leaf pathname component\n\t\t\t*/\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/*\n\t\t\t * recurse adding child components\n\t\t\t */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/*\n\t\t * existing matching entry\n\t\t */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/*\n\t\t\t * No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing extract which subsumes\n\t\t\t * the extract currently being added, in which case stop\n\t\t\t * adding components\n\t\t\t */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/*\n\t\t\t * at leaf pathname component and child components exist\n\t\t\t * from more specific extracts, delete as they're\n\t\t\t * subsumed by this extract\n\t\t\t */\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/*\n\t\t\t * recurse adding child components\n\t\t\t */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames));\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0)\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) +\n\t\t(paths->count + PATHS_ALLOC_SIZE) * sizeof(struct pathname *));\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0,\n\t\t\t\tNULL, 0) == 0 : fnmatch(path->name[i].name,\n\t\t\t\tname, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) ==\n\t\t\t\t0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/*\n\t\t\t\t * match on a leaf component, any subdirectories\n\t\t\t\t * will implicitly match, therefore return an\n\t\t\t\t * empty new search set\n\t\t\t\t */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/*\n\t\t\t\t * match on a non-leaf component, add any\n\t\t\t\t * subdirectories to the new set of\n\t\t\t\t * subdirectories to scan for this name\n\t\t\t\t */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/*\n\t\t * no matching names found, delete empty search set, and return\n\t\t * FALSE\n\t\t */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/*\n\t* one or more matches with sub-directories found (no leaf matches),\n\t* return new search set and return TRUE\n\t*/\n\treturn TRUE;\n\nempty_set:\n\t/*\n\t * found matching leaf exclude, return empty search set and return TRUE\n\t */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nint pre_scan(char *parent_name, unsigned int start_block, unsigned int offset,\n\tstruct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(dir == NULL) {\n\t\tERROR(\"pre_scan: Failed to read directory %s (%x:%x)\\n\",\n\t\t\tparent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"pre_scan: name %s, start_block %d, offset %d, type %d\\n\",\n\t\t\tname, start_block, offset, type);\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tpre_scan(parent_name, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif(type == SQUASHFS_FILE_TYPE ||\n\t\t\t\t\ttype == SQUASHFS_LREG_TYPE) {\n\t\t\t\tif((i = s_ops.read_inode(start_block, offset))\n\t\t\t\t\t\t== NULL) {\n\t\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif(created_inode[i->inode_number - 1] == NULL) {\n\t\t\t\t\tcreated_inode[i->inode_number - 1] =\n\t\t\t\t\t\t(char *) i;\n\t\t\t\t\ttotal_blocks += (i->data +\n\t\t\t\t\t\t(block_size - 1)) >> block_log;\n\t\t\t\t}\n\t\t\t\ttotal_files ++;\n\t\t\t}\n\t\t\ttotal_inodes ++;\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tsquashfs_closedir(dir);\n\n\treturn TRUE;\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset,\n\tstruct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\",\n\t\t\tparent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(lsonly || info)\n\t\tprint_filename(parent_name, i);\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 &&\n\t\t\t(!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\",\n\t\t\tparent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\",\n\t\t\tname, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif((i = s_ops.read_inode(start_block, offset)) == NULL) {\n\t\t\t\tERROR(\"failed to read header\\n\");\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly) {\n\t\t\t\tcreate_inode(pathname, i);\n\t\t\t\tupdate_progress_bar();\n\t\t\t\t}\n\n\t\t\tif(i->type == SQUASHFS_SYMLINK_TYPE ||\n\t\t\t\t\ti->type == SQUASHFS_LSYMLINK_TYPE)\n\t\t\t\tfree(i->symlink);\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tif(!lsonly)\n\t\tset_attributes(parent_name, dir->mode, dir->uid, dir->guid,\n\t\t\tdir->mtime, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %sSQUASHFS %d:%d superblock on %s.\\n\",\n\t\tsBlk.s_major == 4 ? \"\" : swap ? \"little endian \" :\n\t\t\"big endian \", sBlk.s_major, sBlk.s_minor, source);\n#else\n\tprintf(\"Found a valid %sSQUASHFS %d:%d superblock on %s.\\n\",\n\t\tsBlk.s_major == 4 ? \"\" : swap ? \"big endian \" :\n\t\t\"little endian \", sBlk.s_major, sBlk.s_minor, source);\n#endif\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str :\n\t\t\"failed to get time\\n\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\",\n\t\tsBlk.bytes_used / 1024.0, sBlk.bytes_used / (1024.0 * 1024.0));\n\tif(sBlk.s_major == 4)\n\t\tprintf(\"Compression %s\\n\", comp->name);\n\tprintf(\"Block size %d\\n\", sBlk.block_size);\n\tprintf(\"Filesystem is %sexportable via NFS\\n\",\n\t\tSQUASHFS_EXPORTABLE(sBlk.flags) ? \"\" : \"not \");\n\n\tprintf(\"Inodes are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_INODES(sBlk.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_DATA(sBlk.flags) ? \"un\" : \"\");\n\tif(sBlk.s_major > 1 && !SQUASHFS_NO_FRAGMENTS(sBlk.flags))\n\t\tprintf(\"Fragments are %scompressed\\n\",\n\t\t\tSQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags) ? \"un\" :\n\t\t\t\"\");\n\tprintf(\"Check data is %spresent in the filesystem\\n\",\n\t\tSQUASHFS_CHECK_DATA(sBlk.flags) ? \"\" : \"not \");\n\tif(sBlk.s_major > 1) {\n\t\tprintf(\"Fragments are %spresent in the filesystem\\n\",\n\t\t\tSQUASHFS_NO_FRAGMENTS(sBlk.flags) ? \"not \" : \"\");\n\t\tprintf(\"Always_use_fragments option is %sspecified\\n\",\n\t\t\tSQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags) ? \"\" : \"not \");\n\t} else\n\t\tprintf(\"Fragments are not supported by the filesystem\\n\");\n\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\",\n\t\t\tSQUASHFS_DUPLICATES(sBlk.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\tif(sBlk.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.fragments);\n\tprintf(\"Number of inodes %d\\n\", sBlk.inodes);\n\tif(sBlk.s_major == 4)\n\t\tprintf(\"Number of ids %d\\n\", sBlk.no_ids);\n\telse {\n\t\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\t\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\t}\n\n\tTRACE(\"sBlk.inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk.directory_table_start 0x%llx\\n\",\n\t\tsBlk.directory_table_start);\n\tif(sBlk.s_major == 4)\n\t\tTRACE(\"sBlk.id_table_start 0x%llx\\n\", sBlk.id_table_start);\n\telse {\n\t\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\t\tTRACE(\"sBlk.guid_start 0x%llx\\n\", sBlk.guid_start);\n\t}\n\tif(sBlk.s_major > 1)\n\t\tTRACE(\"sBlk.fragment_table_start 0x%llx\\n\\n\",\n\t\t\tsBlk.fragment_table_start);\n}\n\n\nint read_super(char *source)\n{\n\tsquashfs_super_block_3 sBlk_3;\n\tsquashfs_super_block sBlk_4;\n\n\t/*\n\t * Try to read a Squashfs 4 superblock\n\t */\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block),\n\t\t(char *) &sBlk_4);\n\tswap = sBlk_4.s_magic != SQUASHFS_MAGIC;\n\tSQUASHFS_INSWAP_SUPER_BLOCK(&sBlk_4);\n\n\tif(sBlk_4.s_magic == SQUASHFS_MAGIC && sBlk_4.s_major == 4 &&\n\t\t\tsBlk_4.s_minor == 0) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir_4;\n\t\ts_ops.read_fragment = read_fragment_4;\n\t\ts_ops.read_fragment_table = read_fragment_table_4;\n\t\ts_ops.read_block_list = read_block_list_2;\n\t\ts_ops.read_inode = read_inode_4;\n\t\ts_ops.read_uids_guids = read_uids_guids_4;\n\t\tmemcpy(&sBlk, &sBlk_4, sizeof(sBlk_4));\n\n\t\t/*\n\t\t * Check the compression type\n\t\t */\n\t\tcomp = lookup_compressor_id(sBlk.compression);\n\t\tif(!comp->supported) {\n\t\t\tERROR(\"Filesystem uses %s compression, this is \"\n\t\t\t\t\"unsupported by this version\\n\", comp->name);\n\t\t\tERROR(\"Decompressors available:\\n\");\n\t\t\tdisplay_compressors(\"\", \"\");\n\t\t\tgoto failed_mount;\n\t\t}\n\t\treturn TRUE;\n\t}\n\n\t/*\n \t * Not a Squashfs 4 superblock, try to read a squashfs 3 superblock\n \t * (compatible with 1 and 2 filesystems)\n \t */\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block_3),\n\t\t(char *) &sBlk_3);\n\n\t/*\n\t * Check it is a SQUASHFS superblock\n\t */\n\tswap = 0;\n\tif(sBlk_3.s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk_3.s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block_3 sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem \"\n\t\t\t\t\"on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK_3(&sblk, &sBlk_3);\n\t\t\tmemcpy(&sBlk_3, &sblk, sizeof(squashfs_super_block_3));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n\t\t\t\tsource);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\tsBlk.s_magic = sBlk_3.s_magic;\n\tsBlk.inodes = sBlk_3.inodes;\n\tsBlk.mkfs_time = sBlk_3.mkfs_time;\n\tsBlk.block_size = sBlk_3.block_size;\n\tsBlk.fragments = sBlk_3.fragments;\n\tsBlk.block_log = sBlk_3.block_log;\n\tsBlk.flags = sBlk_3.flags;\n\tsBlk.s_major = sBlk_3.s_major;\n\tsBlk.s_minor = sBlk_3.s_minor;\n\tsBlk.root_inode = sBlk_3.root_inode;\n\tsBlk.bytes_used = sBlk_3.bytes_used;\n\tsBlk.inode_table_start = sBlk_3.inode_table_start;\n\tsBlk.directory_table_start = sBlk_3.directory_table_start;\n\tsBlk.fragment_table_start = sBlk_3.fragment_table_start;\n\tsBlk.lookup_table_start = sBlk_3.lookup_table_start;\n\tsBlk.no_uids = sBlk_3.no_uids;\n\tsBlk.no_guids = sBlk_3.no_guids;\n\tsBlk.uid_start = sBlk_3.uid_start;\n\tsBlk.guid_start = sBlk_3.guid_start;\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s_major == 1 || sBlk.s_major == 2) {\n\t\tsBlk.bytes_used = sBlk_3.bytes_used_2;\n\t\tsBlk.uid_start = sBlk_3.uid_start_2;\n\t\tsBlk.guid_start = sBlk_3.guid_start_2;\n\t\tsBlk.inode_table_start = sBlk_3.inode_table_start_2;\n\t\tsBlk.directory_table_start = sBlk_3.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s_major == 1) {\n\t\t\tsBlk.block_size = sBlk_3.block_size_1;\n\t\t\tsBlk.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_1;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t\t} else {\n\t\t\tsBlk.fragment_table_start =\n\t\t\t\tsBlk_3.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_1;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list_2;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t\t}\n\t} else if(sBlk.s_major == 3) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir_3;\n\t\ts_ops.read_fragment = read_fragment_3;\n\t\ts_ops.read_fragment_table = read_fragment_table_3;\n\t\ts_ops.read_block_list = read_block_list_2;\n\t\ts_ops.read_inode = read_inode_3;\n\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s_major,\n\t\t\tsBlk.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\t/*\n\t * 1.x, 2.x and 3.x filesystems use gzip compression.  Gzip is always\n\t * suppported.\n\t */\n\tcomp = lookup_compressor(\"gzip\");\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tif((fd = fopen(filename, \"r\")) == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename,\n\t\t\tstrerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n/*\n * reader thread.  This thread processes read requests queued by the\n * cache_get() routine.\n */\nvoid *reader(void *arg)\n{\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_reader);\n\t\tint res = read_bytes(entry->block,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size),\n\t\t\tentry->data);\n\n\t\tif(res && SQUASHFS_COMPRESSED_BLOCK(entry->size))\n\t\t\t/*\n\t\t\t * queue successfully read block to the deflate\n\t\t\t * thread(s) for further processing\n \t\t\t */\n\t\t\tqueue_put(to_deflate, entry);\n\t\telse\n\t\t\t/*\n\t\t\t * block has either been successfully read and is\n\t\t\t * uncompressed, or an error has occurred, clear pending\n\t\t\t * flag, set error appropriately, and wake up any\n\t\t\t * threads waiting on this buffer\n\t\t\t */\n\t\t\tcache_block_ready(entry, !res);\n\t}\n}\n\n\n/*\n * writer thread.  This processes file write requests queued by the\n * write_file() routine.\n */\nvoid *writer(void *arg)\n{\n\tint i;\n\n\twhile(1) {\n\t\tstruct squashfs_file *file = queue_get(to_writer);\n\t\tint file_fd;\n\t\tint hole = 0;\n\t\tint failed = FALSE;\n\t\tint error;\n\n\t\tif(file == NULL) {\n\t\t\tqueue_put(from_writer, NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\tTRACE(\"writer: regular file, blocks %d\\n\", file->blocks);\n\n\t\tfile_fd = file->fd;\n\n\t\tfor(i = 0; i < file->blocks; i++, cur_blocks ++) {\n\t\t\tstruct file_entry *block = queue_get(to_writer);\n\n\t\t\tif(block->buffer == 0) { /* sparse file */\n\t\t\t\thole += block->size;\n\t\t\t\tfree(block);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcache_block_wait(block->buffer);\n\n\t\t\tif(block->buffer->error)\n\t\t\t\tfailed = TRUE;\n\n\t\t\tif(failed)\n\t\t\t\tcontinue;\n\n\t\t\terror = write_block(file_fd, block->buffer->data +\n\t\t\t\tblock->offset, block->size, hole, file->sparse);\n\n\t\t\tif(error == FALSE) {\n\t\t\t\tERROR(\"writer: failed to write data block %d\\n\",\n\t\t\t\t\ti);\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\n\t\t\thole = 0;\n\t\t\tcache_block_put(block->buffer);\n\t\t\tfree(block);\n\t\t}\n\n\t\tif(hole && failed == FALSE) {\n\t\t\t/*\n\t\t\t * corner case for hole extending to end of file\n\t\t\t */\n\t\t\tif(file->sparse == FALSE ||\n\t\t\t\t\tlseek(file_fd, hole, SEEK_CUR) == -1) {\n\t\t\t\t/*\n\t\t\t\t * for files which we don't want to write\n\t\t\t\t * sparsely, or for broken lseeks which cannot\n\t\t\t\t * seek beyond end of file, write_block will do\n\t\t\t\t * the right thing\n\t\t\t\t */\n\t\t\t\thole --;\n\t\t\t\tif(write_block(file_fd, \"\\0\", 1, hole,\n\t\t\t\t\t\tfile->sparse) == FALSE) {\n\t\t\t\t\tERROR(\"writer: failed to write sparse \"\n\t\t\t\t\t\t\"data block\\n\");\n\t\t\t\t\tfailed = TRUE;\n\t\t\t\t}\n\t\t\t} else if(ftruncate(file_fd, file->file_size) == -1) {\n\t\t\t\tERROR(\"writer: failed to write sparse data \"\n\t\t\t\t\t\"block\\n\");\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\t\t}\n\n\t\tclose(file_fd);\n\t\tif(failed == FALSE)\n\t\t\tset_attributes(file->pathname, file->mode, file->uid,\n\t\t\t\tfile->gid, file->time, force);\n\t\telse {\n\t\t\tERROR(\"Failed to write %s, skipping\\n\", file->pathname);\n\t\t\tunlink(file->pathname);\n\t\t}\n\t\tfree(file->pathname);\n\t\tfree(file);\n\n\t}\n}\n\n\n/*\n * decompress thread.  This decompresses buffers queued by the read thread\n */\nvoid *deflator(void *arg)\n{\n\tchar tmp[block_size];\n\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_deflate);\n\t\tint error, res;\n\n\t\tres = comp->uncompress(tmp, entry->data,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size), block_size,\n\t\t\t&error);\n\n\t\tif(res == -1)\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\telse\n\t\t\tmemcpy(entry->data, tmp, res);\n\n\t\t/*\n\t\t * block has been either successfully decompressed, or an error\n \t\t * occurred, clear pending flag, set error appropriately and\n \t\t * wake up any threads waiting on this block\n \t\t */ \n\t\tcache_block_ready(entry, res == -1);\n\t}\n}\n\n\nvoid *progress_thread(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&screen_mutex);\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) *\n\t\t\t1000;\n\t\tpthread_cond_timedwait(&progress_wait, &screen_mutex,\n\t\t\t&timespec);\n\t\tif(progress_enabled)\n\t\t\tprogress_bar(sym_count + dev_count +\n\t\t\t\tfifo_count + cur_blocks, total_inodes -\n\t\t\t\ttotal_files + total_blocks, columns);\n\t}\n}\n\n\nvoid initialise_threads(int fragment_buffer_size, int data_buffer_size)\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\tint all_buffers_size = fragment_buffer_size + data_buffer_size;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\"\n\t\t\t\"\\n\");\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  \"\n\t\t\t\t\"Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = get_nprocs();\n#endif\n\t}\n\n\tif((thread = malloc((3 + processors) * sizeof(pthread_t))) == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[3];\n\n\tto_reader = queue_init(all_buffers_size);\n\tto_deflate = queue_init(all_buffers_size);\n\tto_writer = queue_init(1000);\n\tfrom_writer = queue_init(1);\n\tfragment_cache = cache_init(block_size, fragment_buffer_size);\n\tdata_cache = cache_init(block_size, data_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&thread[2], NULL, progress_thread, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) !=\n\t\t\t\t 0)\n\t\t\tEXIT_UNSQUASH(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel unsquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\"\n\t\t\t\"\\n\");\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid update_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits = floor(log10(max)) + 1;\n\tint used = max_digits * 2 + 11;\n\tint hashes = (current * (columns - used)) / max;\n\tint spaces = columns - used - hashes;\n\tstatic int tty = -1;\n\n\tif((current > max) || (columns - used < 0))\n\t\treturn;\n\n\tif(tty == -1)\n\t\ttty = isatty(STDOUT_FILENO);\n\tif(!tty) {\n\t\tstatic long long previous = -1;\n\n\t\t/* Updating much more frequently than this results in huge\n\t\t * log files. */\n\t\tif((current % 100) != 0 && current != max)\n\t\t\treturn;\n\t\t/* Don't update just to rotate the spinner. */\n\t\tif(current == previous)\n\t\t\treturn;\n\t\tprevious = current;\n\t}\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 4.1-CVS (2009/08/30)\\n\");\\\n\tprintf(\"copyright (C) 2009 Phillip Lougher <phillip@lougher.demon.co.uk>\"\\\n\t\t\"\\n\\n\");\\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\"\\\n\t\t\"\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\"\\\n\t\t\"\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\"\\\n\t\t\"\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\"\\\n\t\t\"\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tint n;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\tint fragment_buffer_size = FRAGMENT_BUFFER_DEFAULT;\n\tint data_buffer_size = DATA_BUFFER_DEFAULT;\n\tchar *b;\n\n\tpthread_mutex_init(&screen_mutex, NULL);\n\troot_process = geteuid() == 0;\n\tif(root_process)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-n\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-processors\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-p\") == 0) {\n\t\t\tif((++i == argc) || \n\t\t\t\t\t(processors = strtol(argv[i], &b, 10),\n\t\t\t\t\t*b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid \"\n\t\t\t\t\t\"processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-data-queue\") == 0 ||\n\t\t\t\t\t strcmp(argv[i], \"-da\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(data_buffer_size = strtol(argv[i], &b,\n\t\t\t\t\t 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -data-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(data_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -data-queue should be 1 Mbyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-frag-queue\") == 0 ||\n\t\t\t\t\tstrcmp(argv[i], \"-fr\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(fragment_buffer_size = strtol(argv[i],\n\t\t\t\t\t &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -frag-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragment_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -frag-queue should be 1 Mbyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-r\") == 0)\n\t\t\tuse_regex = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(lsonly || info)\n\t\tprogress = FALSE;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or \"\n\t\t\t\t\"files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and \"\n\t\t\t\t\"copyright information\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, \"\n\t\t\t\t\"default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-n[o-progress]\\t\\tdon't display the progress \"\n\t\t\t\t\"bar\\n\");\n\t\t\tERROR(\"\\t-p[rocessors] <number>\\tuse <number> \"\n\t\t\t\t\"processors.  By default will use\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tnumber of processors available\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are \"\n\t\t\t\t\"unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are \"\n\t\t\t\t\"unsquashed with file\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file \"\n\t\t\t\t\"attributes (like\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then \"\n\t\t\t\t\"overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock \"\n\t\t\t\t\"information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or \"\n\t\t\t\t\"files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-da[ta-queue] <size>\\tSet data queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d\\n\\t\\t\\t\\tMbytes\\n\",\n\t\t\t\tDATA_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-fr[ag-queue] <size>\\tSet fagment queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d\\n\\t\\t\\t\\t Mbytes\\n\",\n\t\t\t\tFRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX \"\n\t\t\t\t\"regular expressions\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\trather than use the default shell \"\n\t\t\t\t\"wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t\tERROR(\"\\nDecompressors available:\\n\");\n\t\t\tdisplay_compressors(\"\", \"\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i],\n\t\t\tstrerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tblock_size = sBlk.block_size;\n\tblock_log = sBlk.block_log;\n\n\tfragment_buffer_size <<= 20 - block_log;\n\tdata_buffer_size <<= 20 - block_log;\n\tinitialise_threads(fragment_buffer_size, data_buffer_size);\n\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate data\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tif(s_ops.read_uids_guids() == FALSE)\n\t\tEXIT_UNSQUASH(\"failed to uid/gid table\\n\");\n\n\tif(s_ops.read_fragment_table() == FALSE)\n\t\tEXIT_UNSQUASH(\"failed to read fragment table\\n\");\n\n\tuncompress_inode_table(sBlk.inode_table_start,\n\t\tsBlk.directory_table_start);\n\n\tuncompress_directory_table(sBlk.directory_table_start,\n\t\tsBlk.fragment_table_start);\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tpre_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode),\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\tinode_number = 1;\n\n\tprintf(\"%d inodes (%d blocks) to write\\n\\n\", total_inodes,\n\t\ttotal_inodes - total_files + total_blocks);\n\n\tif(progress)\n\t\tenable_progress_bar();\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode),\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode), paths);\n\n\tqueue_put(to_writer, NULL);\n\tqueue_get(from_writer);\n\n\tif(progress) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(sym_count + dev_count + fifo_count + cur_blocks,\n\t\t\ttotal_inodes - total_files + total_blocks, columns);\n\t}\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.0-realtek/unsquashfs.h",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs.h\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <sys/mman.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n#include <signal.h>\n#include <pthread.h>\n#include <math.h>\n#include <sys/ioctl.h>\n#include <sys/time.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"global.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\t\tprintf(\"\\n\"); \\\n\t\t\t\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tif(progress_enabled) \\\n\t\t\t\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\n/*\n * Unified superblock containing fields for all superblocks\n */\nstruct super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tmkfs_time;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned short\t\tcompression;\n\tunsigned short\t\tblock_log;\n\tunsigned short\t\tflags;\n\tunsigned short\t\tno_ids;\n\tunsigned short\t\ts_major;\n\tunsigned short\t\ts_minor;\n\tsquashfs_inode_t\troot_inode;\n\tlong long\t\tbytes_used;\n\tlong long\t\tid_table_start;\n\tlong long\t\txattr_table_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n\t/* fields only used by squashfs 3 and earlier layouts */\n\tunsigned int\t\tno_uids;\n\tunsigned int\t\tno_guids;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n};\n\nstruct hash_table_entry {\n\tlong long\tstart;\n\tint\t\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar *symlink;\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n\tchar sparse;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(unsigned int block_start, unsigned int offset, struct inode **i);\n\tvoid (*read_fragment)(unsigned int fragment, long long *start_block, int *size);\n\tint (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, char *block_ptr, int blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block, unsigned int offset);\n\tint (*read_uids_guids)();\n} squashfs_operations;\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tint\twait_free;\n\tint\twait_pending;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tpthread_cond_t wait_for_pending;\n\tstruct cache_entry *free_list;\n\tstruct cache_entry *hash_table[65536];\n};\n\n/* struct describing a cache entry passed between threads */\nstruct cache_entry {\n\tstruct cache *cache;\n\tlong long block;\n\tint\tsize;\n\tint\tused;\n\tint error;\n\tint\tpending;\n\tstruct cache_entry *hash_next;\n\tstruct cache_entry *hash_prev;\n\tstruct cache_entry *free_next;\n\tstruct cache_entry *free_prev;\n\tchar *data;\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\tsize;\n\tint\treadp;\n\tint\twritep;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t empty;\n\tpthread_cond_t full;\n\tvoid **data;\n};\n\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 256\n/* default size of data buffer in Mbytes */\n#define DATA_BUFFER_DEFAULT 256\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\nstruct file_entry {\n\tint offset;\n\tint size;\n\tstruct cache_entry *buffer;\n};\n\n\nstruct squashfs_file {\n\tint fd;\n\tint blocks;\n\tlong long file_size;\n\tint mode;\n\tuid_t uid;\n\tgid_t gid;\n\ttime_t time;\n\tchar *pathname;\n\tchar sparse;\n};\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\n/* globals */\nextern struct super_block sBlk;\nextern squashfs_operations s_ops;\nextern int swap;\nextern char *inode_table, *directory_table;\nextern struct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nextern unsigned int *uid_table, *guid_table;\nextern pthread_mutex_t screen_mutex;\nextern int progress_enabled;\nextern int inode_number;\nextern int lookup_type[];\n\n/* unsquashfs.c */\nextern int lookup_entry(struct hash_table_entry **, long long);\nextern int read_bytes(long long, int, char *);\nextern int read_block(long long, long long *, char *);\n\n/* unsquash-1.c */\nextern void read_block_list_1(unsigned int *, char *, int);\nextern int read_fragment_table_1();\nextern struct inode *read_inode_1(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_1(unsigned int, unsigned int, struct inode **);\nextern int read_uids_guids_1();\n\n/* unsquash-2.c */\nextern void read_block_list_2(unsigned int *, char *, int);\nextern int read_fragment_table_2();\nextern void read_fragment_2(unsigned int, long long *, int *);\nextern struct inode *read_inode_2(unsigned int, unsigned int);\n\n/* unsquash-3.c */\nextern int read_fragment_table_3();\nextern void read_fragment_3(unsigned int, long long *, int *);\nextern struct inode *read_inode_3(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_3(unsigned int, unsigned int, struct inode **);\n\n/* unsquash-4.c */\nextern int read_fragment_table_4();\nextern void read_fragment_4(unsigned int, long long *, int *);\nextern struct inode *read_inode_4(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_4(unsigned int, unsigned int, struct inode **);\nextern int read_uids_guids_4();\n"
  },
  {
    "path": "src/others/squashfs-4.2/ACKNOWLEDGEMENTS",
    "content": "\t\t\tACKNOWLEDGEMENTS\n\nThanks to everyone who have download squashfs.  I appreciate people\nusing it, and any feedback you have.\n\nThe following have provided useful feedback, which has guided\nsome of the extra features in squashfs.  This is a randomly ordered\n(roughly in chronological order) list, which is updated when\nI remember...\n\n\nAcknowledgements for Squashfs 4.2\n---------------------------------\n\nThanks to Lasse Collin (http://tukaani.org/xz/) for mainlining XZ\ndecompression support.\n\nAcknowledgements for Squashfs 4.1\n---------------------------------\n\nThanks to Chan Jeong <chan.jeong@lge.com> and LG for the patches to support LZO\ncompression.\n\nAcknowledgements for Squashfs 4.0\n---------------------------------\n\nThanks to Tim Bird and CELF (Consumer Electronics Linux Forum) for helping\nfund mainstreaming of Squashfs into the 2.6.29 kernel and the \nchanges to the Squashfs tools to support the new 4.0 file system layout.\n\nAcknowledgements for Squashfs-3.3\n------------------------------------\n\nPeter Korsgaard and others sent patches updating Squashfs to changes in the\nVFS interface for 2.6.22/2.6.23/2.6.24-rc1.  Peter also sent some small patches\nfor the Squashfs kernel code.\n\nVito Di Leo sent a patch extending Mksquashfs to support regex filters.\nWhile his patched worked, it unfortunately made it easy to make Mksquashfs\nperform unpredictably with poorly choosen regex expressions.  It, however,\nencouraged myself to add support for wildcard pattern matching and regex\nfilters in a different way.\n\nAcknowledgements for Squashfs-3.2-r2\n------------------------------------\n\nJunjiro Okajima discovered a couple of SMP issues, thanks.\n\nJunjiro Okajima and Tomas Matejicek have produced some good LZMA patches\nfor Squashfs.\n\nAcknowledgements for Squashfs-3.2\n---------------------------------\n\nPeter Korsgaard sent a patch updating Squashfs to changes in the VFS interface\nin Linux 2.6.20.\n\nAcknowledgements for Squashfs-3.1\n---------------------------------\n\nKenneth Duda and Ed Swierk of Arastra Inc. identified numerous bugs with\nSquashfs, and provided patches which were the basis for some of the\nfixes.  In particular they identified the fragment rounding bug, the\nNFS bug, the initrd bug, and helped identify the 4K stack overflow bug.\n\nScott James Remnant (Ubuntu) also identified the fragment rounding bug,\nand he also provided a patch.\n\nMing Zhang identified the Lseek bug in Mksquashfs.  His tests on the\nperformance of Mksquashfs on SMP systems encouraged the rewrite of\nMksquashfs.\n\nPeter Korsgaard, Daniel Olivera and Zilvinas Valinskas noticed\nSquashfs 3.0 didn't compile on Linux-2.6.18-rc[1-4] due to changes\nin the Linux VFS interfaces, and provided patches.\n\nTomas Matejicek (SLAX) suggested the -force option on Unsquashfs, and noticed\nUnsquashfs didn't return the correct exit status.\n\nYann Le Doare reported a kernel oops and provided a Qemu image that led\nto the identification of the simultaneously accessing multiply mounted Squashfs\nfilesystems bug.\n\n\nOlder acknowledgements\n----------------------\n\nMark Robson - pointed out early on that initrds didn't work\n\nAdam Warner - pointed out that greater than 2GB filesystems didn't work.\n\nJohn Sutton - raised the problem when archiving the entire filesystem\n(/) there was no way to prevent /proc being archived.  This prompted\nexclude files.\n\nMartin Mueller (LinuxTV) - noticed that the filesystem length in the\nsuperblock doesn't match the output filesystem length.  This is due to\npadding to a 4K boundary.  This prompted the addition of the -nopad option.\nHe also reported a problem where 32K block filesystems hung when used as\ninitrds.\n\nArkadiusz Patyk (Polish Linux Distribution - PLD) reported a problem where 32K\nblock filesystems hung when used as a root filesystem mounted as a loopback\ndevice.\n\nJoe Blow emailed me that I'd forgotten to put anything in the README about\nmounting the squashfs filesystem.\n\nDavid Fox (Lindows) noticed that the exit codes returned by Mksquashfs were\nwrong.  He also noticed that a lot of time was spent in the duplicate scan\nroutine.\n\nCameron Rich complained that Squashfs did not support FIFOs or sockets.\n\nSteve Chadsey and Thomas Weissmuller noticed that files larger than the\navailable memory could not be compressed by Mksquashfs.\n\n\"Ptwahyu\" and \"Hoan\" (I have no full names and I don't like giving people's\nemail addresses), noticed that Mksquashfs 1.3 SEGV'd occasionally.  Even though\nI had already noticed this bug, it is useful to be informed by other people.\n\nDon Elwell, Murray Jensen and Cameron Rich, have all sent in patches.  Thanks,\nI have not had time to do anything about them yet...\n\nDrew Scott Daniels has been a good advocate for Squashfs.\n\nErik Andersen has made some nice suggestions, unfortunately, I have\nnot had time to implement anything.\n\nArtemiy I. Pavlov has written a useful LDP mini-howto for Squashfs\n(http://linuxdoc.artemio.net/squashfs).\n\nYves Combe reported the Apple G5 bug, when using Squashfs for\nhis PPC Knoppix-mib livecd project.\n\nJaco Greeff (mklivecd project, and maintainer of the Mandrake\nsquashfs-tools package) suggested the new mksquashfs -ef option, and the\nstandalone build for mksquashfs.\n\nMike Schaudies made a donation.\n\nArkadiusz Patyk from the Polish Linux Distribution reported that Squashfs\ndidn't work on amd64 machines. He gave me an account on a PLD amd64 machine\nwhich allowed myself to track down these bugs.\n\nMiles Roper, Peter Kjellerstedt and Willy Tarreau reported that release 2.1 did\nnot compile with gcc < 3.x.\n\nMarcel J.E. Mol reported lack of kernel memory issues when using Squashfs\non small memory embedded systems.  This prompted the addition of the embedded\nsystem kernel configuration options.\n\nEra Scarecrow noticed that Mksquashfs had not been updated to reflect that\nsmaller than 4K blocks are no longer supported.\n\nKenichi Shima reported the Kconfig file had not been updated to 2.2.\n\nAaron Ten Clay made a donation!\n\nTomas Matejicek (SLAX) made a donation!\n"
  },
  {
    "path": "src/others/squashfs-4.2/CHANGES",
    "content": "\t\t\tSQUASHFS CHANGE LOG\n\n4.2\t28 FEB 2011\tXZ compression, and compression options support\n\n\t1. Filesystem improvements:\n\n\t    1.1 Added XZ compression\n\t    1.2 Added compression options support\n\n\t2. Miscellaneous improvements/bug fixes\n\n\t    1.1 Add missing NO_XATTR filesystem flag to indicate no-xattrs\n\t\toption was specified and no xattrs should be stored when\n\t\tappending.\n\t    1.2 Add suppport in Unquashfs -stat option for displaying\n\t\tNO_XATTR flag.\n\t    1.3 Remove checkdata entry from Unsquashfs -stat option if a 4.0\n\t\tfilesystem - checkdata is no longer supported.\n\t    1.4 Fix appending bug when appending to an empty filesystem - this\n\t\twould be incorrectly treated as an error.\n\t    1.5 Use glibc sys/xattr.h include rather than using attr/xattr.h\n\t\twhich isn't present by default on some distributions.\n\t    1.6 Unsquashfs, fix block calculation error with regular files when\n\t\tfile size is between 2^32-block_size+1 and 2^32-1.\n\t    1.7 Unsquashfs, fix sparse file writing when holes are larger than\n\t\t2^31-1.\n\t    1.8 Add external CFLAGS and LDFLAGS support to Makefile, and allow\n\t\tbuild options to be specified on command line.  Also don't\n\t\tover-write passed in CFLAGS definition.\n\t\n\n4.1\t19 SEPT 2010\tMajor filesystem and tools improvements\n\n\t1. Filesystem improvements:\n\n\t    1.1 Extended attribute support\n\t    1.2 New compression framework\n\t    1.3 Support for LZO compression\n\t    1.4 Support for LZMA compression (not yet in mainline)\n\n\t2. Mksquashfs improvements:\n\n\t    1.1 Enhanced pseudo file support\n\t    1.2 New options for choosing compression algorithm used\n\t    1.3 New options for controlling extended attributes\n\t    1.4 Fix misalignment issues with memcpy etc. seen on ARM\n\t    1.5 Fix floating point error in progress_bar when max == 0\n\t    1.6 Removed use of get_nproc() call unavailable in ulibc\n\t    1.7 Reorganised help text\n\t  \n\t3. Unsquashfs improvements:\n\n\t    1.1 New options for controlling extended attributes\n\t    1.2 Fix misalignment issues with memcpy etc. seen on ARM\n\t    1.3 Fix floating point error in progress_bar when max == 0\n\t    1.4 Removed use of get_nproc() call unavailable in ulibc\n\n\t  \n4.0\t5 APR 2009\tMajor filesystems improvements\n\n\t1. Kernel code improvements:\n\n\t    1.1 Fixed little endian layout adopted.  All swapping macros\n\t\tremoved, and in-line swapping added for big-endian\n\t\tarchitectures.\n\t    1.2 Kernel code substantially improved and restructured.\n\t    1.3 Kernel code split into separate files along functional lines.\n\t    1.4 Vmalloc usage removed, and code changed to use separately\n\t\tallocated 4K buffers\n\n\t2. Unsquashfs improvements:\n\n\t    2.1 Support for 4.0 filesystems added.\n\t    2.2 Swapping macros rewritten.\n\t    2.3 Unsquashfs code restructured and split into separate files.\n\n\t3. Mksquashfs improvements:\n\n\t    3.1 Swapping macros rewritten.  Fixed little-endian layout allows\n\t\tcode to be optimised and only added at compile time for\n\t\tbig endian systems.\n\t    3.2 Support for pseudo files added.\n\t \n3.4\t26 AUG 2008\tPerformance improvements to Unsquashfs, Mksquashfs\n\t\t\tand the kernel code.  Plus many small bug fixes.\n\n\t1. Kernel code improvements:\n\n\t    1.1 Internal Squashfs kernel metadata and fragment cache\n\t\timplementations have been merged and optimised.  Spinlocks are\n\t\tnow used, locks are held for smaller periods and wakeups have\n\t\tbeen minimised.  Small race condition fixed where if two or\n\t\tmore processes tried to read the same cache block\n\t\tsimultaneously they would both read and decompress it.  10-20%+\n\t\tspeed improvement has been seen on tests.\n\t    1.2 NFS export code rewritten following VFS changes in\n\t\tlinux-2.6.24.\n\t    1.3 New patches for linux-2.6.25, linux-2.6.26, and linux-2.6.27.\n\t\tFixed patch for linux-2.6.24.\n\t    1.4 Fixed small buffer_head leak in squashfs_read_data when\n\t\thandling badly corrupted filesystems.\n\t    1.5 Fixed bug in get_dir_index_using_offset.\n\n\t2. Unsquashfs improvements:\n\n\t    2.1 Unsquashfs has been parallelised.  Filesystem reading, writing\n\t\tand decompression is now multi-threaded.  Up to 40% speed\n\t\timprovement seen on tests.\n\t    2.2 Unsquashfs now has a progress bar.  Use -no-progress to\n\t\tdisable it.\n\t    2.3 Fixed small bug where unistd.h wasn't being included on\n\t\tsome distributions, leading to lseek being used rather than\n\t\tlseek64 - which meant on these distributions Unsquashfs\n\t\tcouldn't unsquash filesystems larger than 4GB.\n\n       3. Mksquashfs improvements:\n\n\t    3.1 Removed some small remaining parallelisation bottlenecks.\n\t\tDepending on source filesystem, up to 10%+ speed improvement.\n\t    3.2 Progress bar improved, and moved to separate thread.\n\t    3.3 Sparse file handling bug in Mksquashfs 3.3 fixed.\n\t    3.4 Two rare appending restore bugs fixed (when ^C hit twice).\n\n\n3.3\t1 NOV 2007\tIncrease in block size, sparse file support,\n\t\t\tMksquashfs and Unsquashfs extended to use\n\t\t\tpattern matching in exclude/extract files, plus\n\t\t\tmany more improvements and bug fixes.\n\n\t1. Filesystem improvements:\n\n\t     1.1. Maximum block size has been increased to 1Mbyte, and the\n\t    \t  default block size has been increased to 128 Kbytes.\n\t\t  This improves compression.\n\n\t     1.2. Sparse files are now supported.  Sparse files are files\n\t\t  which have large areas of unallocated data commonly called\n\t\t  holes.  These files are now detected by Squashfs and stored\n\t\t  more efficiently.  This improves compression and read\n\t\t  performance for sparse files.\n\n\t2. Mksquashfs improvements:\n\n\t   2.1.  Exclude files have been extended to use wildcard pattern\n\t\t matching and regular expressions.  Support has also been\n\t\t added for non-anchored excludes, which means it is\n\t\t now possible to specify excludes which match anywhere\n\t\t in the filesystem (i.e. leaf files), rather than always\n\t\t having to specify exclude files starting from the root\n\t\t directory (anchored excludes).\n\n\t   2.2.  Recovery files are now created when appending to existing\n\t\t Squashfs filesystems.  This allows the original filesystem\n\t\t to be recovered if Mksquashfs aborts unexpectedly\n\t\t (i.e. power failure).\n\n\t3. Unsquashfs improvements:\n\n\t    3.1. Multiple extract files can now be specified on the\n\t\t command line, and the files/directories to be extracted can\n\t\t now also be given in a file.\n\n\t    3.2. Extract files have been extended to use wildcard pattern\n\t\t matching and regular expressions.\n\n\t    3.3. Filename printing has been enhanced and Unquashfs can\n\t\t now display filenames with file attributes\n\t\t ('ls -l' style output).\n\n\t    3.4. A -stat option has been added which displays the filesystem\n\t\t superblock information.\n\n\t    3.5. Unsquashfs now supports 1.x filesystems.\n\n\t4. Miscellaneous improvements/bug fixes:\n\n\t    4.1. Squashfs kernel code improved to use SetPageError in\n\t\t squashfs_readpage() if I/O error occurs.\n\n\t    4.2. Fixed Squashfs kernel code bug preventing file\n\t\t seeking beyond 2GB.\n\n\t    4.3. Mksquashfs now detects file size changes between\n\t\t first phase directory scan and second phase filesystem create.\n\t\t It also deals better with file I/O errors.\n\n\n3.2-r2\t15 JAN 2007\tKernel patch update and progress bar bug fix\n\n\t1. Kernel patches 2.6.19/2.6.20 have been updated to use\n\t   const structures and mutexes rather than older semaphores.\n\t2. Minor SMP bug fixes.\n\t3. Progress bar broken on x86-64.  Fixed.\n\n3.2\t2 JAN 2007\tNFS support, improvements to the Squashfs-tools, major\n\t\t\tbug fixes, lots of small improvements/bug fixes, and new\n\t\t\tkernel patches.\n\n\tImprovements:\n\n\t1. Squashfs filesystems can now be exported via NFS.\n\t2. Unsquashfs now supports 2.x filesystems.\n\t3. Mksquashfs now displays a progress bar.\n\t4. Squashfs kernel code has been hardened against accidently or\n\t   maliciously corrupted Squashfs filesystems.\n\n\tBug fixes:\n\n\t5. Race condition occurring on S390 in readpage() fixed.\n\t6. Odd behaviour of MIPS memcpy in read_data() routine worked-around.\n\t7. Missing cache_flush in Squashfs symlink_readpage() added.\n\t\n\n3.1-r2\t30 AUG 2006\tMksquashfs -sort bug fix\n\n\t\t\tA code optimisation after testing unfortunately\n\t\t\tbroke sorting in Mksquashfs.  This has been fixed.\n\n3.1\t19 AUG 2006\tThis release has some major improvements to\n\t\t\tthe squashfs-tools, a couple of major bug\n\t\t\tfixes, lots of small improvements/bug fixes,\n\t\t\tand new kernel patches.\n\n\t\t\t\n\t1. Mksquashfs has been rewritten to be multi-threaded.  It\n\t   has the following improvements\n\n\t   1.1. Parallel compression.  By default as many compression and\n\t\tfragment compression threads are created as there are available\n\t\tprocessors.  This significantly speeds up performance on SMP\n\t\tsystems.\n\t   1.2. File input and filesystem output is peformed in parallel on\n\t\tseparate threads to maximise I/O performance.  Even on single\n\t\tprocessor systems this speeds up performance by at least 10%.\n\t   1.3. Appending has been significantly improved, and files within the\n\t\tfilesystem being appended to are no longer scanned and\n\t\tchecksummed.  This significantly improves append time for large\n\t\tfilesystems.\n\t   1.4. File duplicate checking has been optimised, and split into two\n\t\tseparate phases.  Only files which are considered possible\n\t\tduplicates after the first phase are checksummed and cached in\n\t\tmemory.\n\t   1.5\tThe use of swap memory was found to significantly impact\n\t\tperformance. The amount of memory used to cache files is now a\n\t\tcommand line option, by default this is 512 Mbytes.\n \n\t2. Unsquashfs has the following improvements\n\n\t   2.1  Unsquashfs now allows you to specify the filename or the\n\t\tdirectory within the Squashfs filesystem that is to be\n\t\textracted, rather than always extracting the entire filesystem.\n\t   2.2  A new -force option has been added which forces Unsquashfs to\n\t\toutput to the destination directory even if files and directories\n\t\talready exist in the destination directory.  This allows you to\n\t\tupdate an already existing directory tree, or to Unsquashfs to\n\t\ta partially filled directory tree.  Without the -force option\n\t\tUnsquashfs will refuse to output.\n\n\t3.  The following major bug fixes have been made\n\n\t  3.1  \tA fragment table rounding bug has been fixed in Mksquashfs.\n\t\tPreviously if the number of fragments in the filesystem\n\t\twere a multiple of 512, Mksquashfs would generate an\n\t\tincorrect filesystem.\n\t  3.2  \tA rare SMP bug which occurred when simultaneously acccessing\n\t\tmultiply mounted Squashfs filesystems has been fixed.\n\n\t4. Miscellaneous improvements/bug fixes\n\n\t  4.1\tKernel code stack usage has been reduced.  This is to ensure\n\t\tSquashfs works with 4K stacks.\n\t  4.2   Readdir (Squashfs kernel code) has been fixed to always\n\t\treturn 0, rather than the number of directories read.  Squashfs\n\t\tshould now interact better with NFS.\n\t  4.3\tLseek bug in Mksquashfs when appending to larger than 4GB\n\t\tfilesystems fixed.\n\t  4.4\tSquashfs 2.x initrds can now been mounted.\n\t  4.5\tUnsquashfs exit status fixed.\n\t  4.6\tNew patches for linux-2.6.18 and linux-2.4.33.\n\n\t\n3.0\t15 MAR 2006\tMajor filesystem improvements\n\n\t1. Filesystems are no longer limited to 4 GB.  In\n\t   theory 2^64 or 4 exabytes is now supported.\n\t2. Files are no longer limited to 4 GB.  In theory the maximum\n\t   file size is 4 exabytes.\n\t3. Metadata (inode table and directory tables) are no longer\n\t   restricted to 16 Mbytes.\n\t4. Hardlinks are now suppported.\n\t5. Nlink counts are now supported.\n\t6. Readdir now returns '.' and '..' entries.\n\t7. Special support for files larger than 256 MB has been added to\n\t   the Squashfs kernel code for faster read access.\n\t8. Inode numbers are now stored within the inode rather than being\n\t   computed from inode location on disk (this is not so much an\n\t   improvement, but a change forced by the previously listed\n\t   improvements).\n\n2.2-r2\t8 SEPT 2005\tSecond release of 2.2, this release fixes a couple\n\t\t\tof small bugs, a couple of small documentation\n\t\t\tmistakes, and adds a patch for kernel 2.6.13. \n\n\t1. Mksquashfs now deletes the output filesystem image file if an\n\t   error occurs whilst generating the filesystem.  Previously on\n\t   error the image file was left empty or partially written.\n\t2. Updated mksquashfs so that it doesn't allow you to generate\n\t   filesystems with block sizes smaller than 4K.  Squashfs hasn't\n\t   supported block sizes less than 4K since 2.0-alpha.\n\t3. Mksquashfs now ignores missing files/directories in sort files.\n\t   This was the original behaviour before 2.2.\n\t4. Fixed small mistake in fs/Kconfig where the version was still\n\t   listed as 2.0.\n\t5. Updated ACKNOWLEDGEMENTS file.\n\n\n2.2\t3 JUL 2005\tThis release has some small improvements, bug fixes\n\t\t\tand patches for new kernels.\n\n\t1. Sort routine re-worked and debugged from release 2.1.  It now allows\n\t   you to give Mkisofs style sort files and checks for filenames that\n\t   don't match anything.  Sort priority has also been changed to\n\t   conform to Mkisofs usage, highest priority files are now placed\n\t   at the start of the filesystem (this means they will be on the\n\t   inside of a CD or DVD).\n\t2. New Configure options for embedded systems (memory constrained\n\t   systems).  See INSTALL file for further details.\n\t3. Directory index bug fixed where chars were treated as signed on\n           some architectures.  A file would not be found in the rare case\n\t   that the filename started with a chracter greater than 127.\n\t4. Bug introduced into the read_data() routine when sped up to use data\n\t   block queueing fixed.  If the second or later block resulted in an\n\t   I/O error this was not checked.\n\t5. Append bug introduced in 2.1 fixed.  The code to compute the new\n\t   compressed and uncompressed directory parts after appending was\n\t   wrong.\n\t6. Metadata block length read routine altered to not perform a\n\t   misaligned short read.  This was to fix reading on an ARM7 running\n\t   uCLinux without a misaligned read interrupt handler.\n\t7. Checkdata bug introduced in 2.1 fixed.\n\t\n\n2.1-r2  15 DEC 2004\tCode changed so it can be compiled with gcc 2.x\n\n\t1.  In some of the code added for release 2.1 I unknowingly used some\n\t    gcc extensions only supported by 3.x compilers.  I have received\n\t    a couple of reports that the 2.1 release doesn't build on 2.x and so\n\t    people are clearly still using gcc 2.x.  The code has been\n\t    rewritten to remove these extensions.\n\n2.1\t10 DEC 2004\tSignificantly improved directory handling plus numerous\n\t\t\tother smaller improvements\n\n\t1.  Fast indexed directories implemented.  These speed up directory\n\t    operations (ls, file lookup etc.) significantly for directories\n\t    larger than 8 KB.\n\t2.  All directories are now sorted in alphabetical order.  This again\n\t    speeds up directory operations, and in some cases it also results in\n\t    a small compression improvement (greater data similarity between\n\t    files with alphabetically similar names).\n\t3.  Maximum directory size increased from 512 KB to 128 MB.\n\t4.  Duplicate fragment checking and appending optimised in mksquashfs,\n\t    depending on filesystem, this is now up to 25% faster.\n\t5.  Mksquashfs help information reformatted and reorganised.\n\t6.  The Squashfs version and release date is now printed at kernel\n\t    boot-time or module insertion.  This addition will hopefully help\n\t    to reduce the growing problem where the Squashfs version supported\n\t    by a kernel is unknown and the kernel source is unavailable.\n        7.  New PERFORMANCE.README file.\n\t8.  New -2.0 mksquashfs option.\n\t9.  CHANGES file reorganised.\n\t10. README file reorganised, clarified and updated to include the 2.0\n\t    mksquashfs options.\n\t11. New patch for Linux 2.6.9.\n\t12. New patch for Linux 2.4.28.\n\n2.0r2\t29 AUG 2004\tWorkaround for kernel bug in kernels 2.6.8 and newer\n\t\t\tadded\n\n\t1. New patch for kernel 2.6.8.1.  This includes a workaround for a\n\t   kernel bug introduced in 2.6.7bk14, which is present in all later\n\t   versions of the kernel.  \n\n\t   If you're using a 2.6.8 kernel or later then you must use this\n\t   2.6.8.1 patch.  If you've experienced hangs or oopses using Squashfs\n\t   with a 2.6.8 or later kernel then you've hit this bug, and this\n\t   patch will fix it.\n\n\t   It is worth mentioning that this kernel bug potentially affects\n\t   other filesystems.  If you receive odd results with other\n\t   filesystems you may be experiencing this bug with that filesystem.\n\t   I submitted a patch but this has not yet gone into the\n\t   kernel, hopefully the bug will be fixed in later kernels. \n\n2.0\t13 JULY 2004\tA couple of new options, and some bug fixes\n\n\t1. New mksquashfs -all-root, -root-owned, -force-uid, and -force-gid\n\t   options.  These allow the uids/gids of files in the generated\n\t   filesystem to be specified, overriding the uids/gids in the\n\t   source filesystem.\n\t2. Initrds are now supported for kernels 2.6.x.\n\t3. amd64 bug fixes.  If you use an amd64, please read the README-AMD64\n\t   file.\n\t4. Check-data and gid bug fixes.  With 2.0-alpha when mounting 1.x\n\t   filesystems in certain cases file gids were corrupted.\n\t5. New patch for Linux 2.6.7.\n\n2.0-ALPHA\t21 MAY 2004\tFilesystem changes and compression improvements\n\n\t1. Squashfs 2.0 has added the concept of fragment blocks.\n           Files smaller than the file block size and optionally the\n\t   remainder of files that do not fit fully into a block (i.e. the\n\t   last 32K in a 96K file) are packed into shared fragments and\n\t   compressed together.  This achieves on average 5 - 20% better\n\t   compression than Squashfs 1.x.\n\t2. The maximum block size has been increased to 64K (in the ALPHA\n\t   version of Squashfs 2.0).\n\t3. The maximum number of UIDs has been increased to 256 (from 48 in\n\t   1.x).\n\t4. The maximum number of GIDs has been increased to 256 (from 15 in\n\t   1.x).\n\t5. Removal of sleep_on() function call in 2.6.x patch, to allow Squashfs\n\t   to work on the Fedora rc2 kernel.\n\t6. Numerous small bug fixes have been made.\n\n1.3r3\t18 JAN 2004\tThird release of 1.3, this adds a new mksquashfs option,\n\t\t\tsome bug fixes, and extra patches for new kernels\n\n\t1. New mksquashfs -ef exclude option.  This option reads the exclude\n\t   dirs/files from an exclude file, one exclude dir/file per line.  This\n\t   avoids the command line size limit when using the -e exclude option,\n\t2. When appending to existing filesystems, if mksquashfs experiences a\n\t   fatal error (e.g. out of space when adding to the destination), the\n\t   original filesystem is restored,\n\t3. Mksquashfs now builds standalone, without the kernel needing to be\n\t   patched.\n\t4. Bug fix in the kernel squashfs filesystem, where the pages being\n\t   filled were not kmapped.  This seems to only have caused problems\n\t   on an Apple G5,\n\t5. New patch for Linux 2.4.24,\n\n\t6. New patch for Linux 2.6.1, this replaces the patch for 2.6.0-test7.\n\n1.3r2\t14 OCT 2003\tSecond release of 1.3, bug fixes and extra patches for\n\t\t        new kernels\n\n\t1. Bug fix in routine that adds files to the filesystem being\n\t   generated in mksquashfs.  This bug was introduced in 1.3\n\t   (not enough testing...) when I rewrote it to handle files larger\n\t   than available memory.  This bug caused a SEGV, so if you've ever\n\t   got that, it is now fixed,\n\t2. Long running bug where ls -s and du reported wrong block size\n\t   fixed.  I'm pretty sure this used to work many kernel versions ago\n\t   (2.4.7) but it broke somewhere along the line since then,\n\t3. New patch for Linux 2.4.22,\n\t4. New patch for 2.6.0-test7, this replaces the patch for 2.6.0-test1.\n\n1.3\t29 JUL 2003\tFIFO/Socket support added plus optimisations and\n\t\t        improvements\n\n\t1. FIFOs and Socket inodes are now supported,\n\t2. Mksquashfs can now compress files larger than available\n\t   memory,\n\t3. File duplicate check routine optimised,\n\t4. Exit codes fixed in Mksquashfs,\n\t5. Patch for Linux 2.4.21,\n\t6. Patch for Linux 2.6.0-test1.  Hopefully, this will work for\n\t   the next few releases of 2.6.0-testx, otherwise, I'll be\n\t   releasing a lot of updates to the 2.6.0 patch...\n\n1.2\t13 MAR 2003\tAppend feature and new mksquashfs options added\n\n\tMksquashfs can now add to existing squashfs filesystems.  Three extra\n\toptions \"-noappend\", \"-keep-as-directory\", and \"root-becomes\"\n\thave been added.\n\n\tThe append option with file duplicate detection, means squashfs can be\n\tused as a simple versioning archiving filesystem. A squashfs\n\tfilesystem can be created with for example the linux-2.4.19 source.\n\tAppending the linux-2.4.20 source will create a filesystem with the\n\ttwo source trees, but only the changed files will take extra room,\n\tthe unchanged files will be detected as duplicates.\n\n\tSee the README file for usage changes.\n\n1.1b\t16 JAN 2003\tBug fix release\n\n\tFixed readpage deadlock bug.  This was a rare deadlock bug that\n\thappened when pushing pages into the page cache when using greater\n\tthan 4K blocks.  I never got this bug when I tested the filesystem,\n\tbut two people emailed me on the same day about the problem!\n\tI fixed it by using a page cache function that wasn't there when\n\tI originally did the work, which was nice :-)\n\n1.1\t8 JAN 2003\tAdded features\n\n\t1. Kernel squashfs can now mount different byte order filesystems.\n\t2. Additional features added to mksquashfs.  Mksquashfs now supports\n\t   exclude files and multiple source files/directories can be\n\t   specified.  A nopad option has also been added, which\n\t   informs mksquashfs not to pad filesystems to a multiple of 4K.\n\t   See README for mksquashfs usage changes.\n\t3. Greater than 2GB filesystems bug fix.  Filesystems greater than 2GB\n\t   can now be created.\n\n1.0c \t14 NOV 2002\tBug fix release\n\n\tFixed bugs with initrds and device nodes\n\n1.0 \t23 OCT 2002\tInitial release\n"
  },
  {
    "path": "src/others/squashfs-4.2/COPYING",
    "content": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n\t\t    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n\t    How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) 19yy  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) 19yy name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "src/others/squashfs-4.2/DONATIONS",
    "content": "Help sponsor Squashfs development!\n\nMaintaining and improving Squashfs is a lot of work, but Squashfs is one of\nthe only widely used Linux file systems that has no company backing.  Squashfs\ndevelopment is funded soley by the author, partially supported by donations\nfrom companies and individuals that want to improve Squashfs for themselves\nand others.\n\nMainlining of Squashfs only became possible when CELF (Consumer Electronics\nLinux Forum) offered to contribute to the costs, which allowed the author\nto work full-time on the project.\n\nThere's lots of exciting new improvements to Squashfs in the pipeline, and\nif your company is a serious user of Squashfs, please consider accelerating\ndevelopment of Squashfs by donating.\n\nDonatations can be made from the Squashfs sourceforge homepage, or if you\nprefer by contacting the author privately.\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/INSTALL",
    "content": "\t\t\tINSTALLING SQUASHFS\n\nThe squashfs4.2.tar.gz file contains the squashfs-tools directory containing\nmksquashfs and unsquashfs.\n\n1. Kernel support\n-----------------\n\nThis release is for 2.6.29 and newer kernels.  Kernel patching is not necessary.\n\nExtended attribute support requires 2.6.35 or newer.  File systems with\nextended attributes can be mounted on 2.6.29 and newer kernels (the\nextended attributes will be ignored with a warning).\n\nLZO compression support requires 2.6.36 or newer kernels.\n\nXZ compression support requires 2.6.38 or newer kernels.\n\n2. Building squashfs tools\n--------------------------\n\nThe squashfs-tools directory contains the mksquashfs and unsquashfs programs.\nThese can be made by typing make (or make install to install in /usr/local/bin).\n\nBy default the tools are built with GZIP compression and extended attribute\nsupport.  Read the Makefile in squashfs-tools/ for instructions on building\nLZO and XZ compression support, and for instructions on disabling GZIP\nand extended attribute support if desired.\n"
  },
  {
    "path": "src/others/squashfs-4.2/Makefile",
    "content": "all:\n\tmake -C squashfs-tools\n\tcp squashfs-tools/unsquashfs .\n\tcp squashfs-tools/mksquashfs .\n\nclean:\n\tmake -C squashfs-tools clean\n\trm -f unsquashfs mksquashfs\n"
  },
  {
    "path": "src/others/squashfs-4.2/OLD-READMEs/README-2.0",
    "content": "NOTE:  This the original README for version 2.0.  It is retained as it\ncontains information about the fragment design.  A description of the new 2.0\nmksquashfs options has been added to the main README file, and that\nfile should now be consulted for these.\n\n\tSQUASHFS 2.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2004 Phillip Lougher (plougher@users.sourceforge.net)\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to the final release of Squashfs version 2.0!  A lot of changes to the\nfilesystem have been made under the bonnet (hood).  Squashfs 2.0 uses fragment\nblocks and larger blocks (64K) to improve compression ratio by about 5 - 20%\nover Squashfs 1.0 depending on the files being compressed.  Using fragment\nblocks allows Squashfs 2.0 to achieve better compression than cloop and similar\ncompression to tgz files while retaining the I/O efficiency of a compressed\nfilesystem.\n\nDetailed changes:\n\n1. Squashfs 2.0 has added the concept of fragment blocks (see later discussion).\n   Files smaller than the file block size (64K in Squashfs 2.0) and optionally\n   the remainder of files that do not fit fully into a block (i.e. the last 32K\n   in a 96K file) are packed into shared fragments and compressed together.\n   This achieves on average 5 - 20% better compression than Squashfs 1.x.\n\n2. The maximum block size has been increased to 64K.\n\n3. The maximum number of UIDs has been increased to 256 (from 48 in 1.x).\n\n4. The maximum number of GIDs has been increased to 256 (from 15 in 1.x).\n\n5. New mksquashfs -all-root, -root-owned, -force-uid, and -force-gid\n   options.  These allow the uids/gids of files in the generated\n   filesystem to be specified, overriding the uids/gids in the\n   source filesystem.\n\n6. Initrds are now supported for kernels 2.6.x.\n\n7. Removal of sleep_on() function call in 2.6.x patch, to allow Squashfs\n   to work on the Fedora rc2 kernel.\n\n8. AMD64, check-data and gid bug fixes.\n\n9. Numerous small bug fixes have been made.\n\n10. New patch for Linux 2.6.7.\n\n\nNew Squashfs 2.0 options\n------------------------\n\n-noF or -noFragmentCompression\n\n\tDo not compress the fragments.  Added for compatibility with noI and\n\tnoD, probably not that useful.\n\n-no-fragments\n\n\tDo not use fragment blocks, and rather generate a filesystem\n\tsimilar to a Squashfs 1.x filesystem.  It will of course still\n\tbe a Squashfs 2.0 filesystem but without fragments, and so\n\tit won't be mountable on a Squashfs 1.x system.\n\n-always-use-fragments\n\n\tBy default only small files less than the block size are packed into\n\tfragment blocks.  The ends of files which do not fit fully into a block,\n\tare NOT by default packed into fragments.  To illustrate this, a\n\t100K file has an initial 64K block and a 36K remainder.  This\n\t36K remainder is not packed into a fragment by default.  This is\n\tbecause to do so leads to a 10 - 20% drop in sequential I/O\n\tperformance, as a disk head seek is needed to seek to the initial\n\tfile data and another disk seek is need to seek to the fragment\n\tblock.\n\n\tSpecify this option if you want file remainders to be packed into\n\tfragment blocks.  Doing so may increase the compression obtained\n\tBUT at the expense of I/O speed.\n\n-no-duplicates\n\n\tDo not detect duplicate files.\n\n-all-root\n-root-owned\n\n\tThese options (both do exactly the same thing), force all file\n\tuids/gids in the generated Squashfs filesystem to be root.\n\tThis allows root owned filesystems to be built without root access\n\ton the host machine.\n\n-force-uid uid\n\n\tThis option forces all files in the generated Squashfs filesystem to\n\tbe owned by the specified uid.  The uid can be specified either by\n\tname (i.e. \"root\") or by number.\n\n-force-gid gid\n\n\tThis option forces all files in the generated Squashfs filesystem to\n\tbe group owned by the specified gid.  The gid can be specified either by\n\tname (i.e. \"root\") or by number.\n\n\nCompression improvements example\n--------------------------------\n\nThe following is the compression results obtained compressing the 2.6.6\nlinux kernel source using CRAMFS, Cloop (with iso filesystem), Squashfs 1.3 and\nSquashfs 2.0 (results generated using big-endian filesystems).\n\nIn decreasing order of size:\n\n\tCRAMFS\t\t62791680 bytes (59.9M)\n\tSquashfs 1.x\t51351552 bytes (48.9M)\n\tCloop\t\t46118681 bytes (44.0M)\n\tSquashfs 2.0\t45604854 bytes (43.5M)\n\n\nThe Squashfs 1.x filesystem is 12.6% larger than the new 2.0 filesystem.\nThe cloop filesystem is 1.1% larger than the Squashfs 2.0 filesystem.\n\n\nFragment blocks in Squashfs 2.0\n-------------------------------\n\nSquashfs like all other compressed filesystems compresses files individually\non a block by block basis.  This is performed to allow mounting and\nde-compression of files on a block by block basis without requiring the entire\nfilesystem to be decompressed.  This is in contrast to data-based compression\nschemes which compress without understanding the underlying filesystem (i.e.\ncloop and tgz files) and which, therefore, do not compress files individually.\nEach approach has advantages and disadvantages, data-based systems have better\ncompression because compression is always performed at the maximum block size\n(64K in cloop) irrespective of the size of each file (which could be less than\nthe block size).  Compressed filesystems tend to be faster at I/O because\nthey understand the filesystem and therefore employ better caching stategies\nand read less un-needed data from the filesystem.\n\nFragment blocks in Squashfs 2.0 solves this problem by packing files (and\noptionally the ends of files) which are smaller than the block size into\nshared blocks, which are compressed together.  For example five files each of\n10K will be packed into one shared fragment of 50K and compressed together,\nrather than being compressed in five 10K blocks.\n\nThis scheme produces a hybrid filesystem, retaining the I/O efficiency\nof a compressed filesystem, while obtaining the compression efficiency\nof data-based schemes by compressing small files together.\n\n\nSquashfs 1.x and Squashfs 2.0 compatibility\n-------------------------------------------\n\nAppending to Squashfs 1.x filesystems is not supported.  If you wish to append\nto 1.x filesystems, then either use the original mksquashfs, or convert them\nto Squashfs 2.0 by mounting the filesystem and running the 2.0 mksquashfs\non the mounted filesystem.\n\nMounting Squashfs 1.x filesystems IS supported by the 2.0 kernel patch.\n"
  },
  {
    "path": "src/others/squashfs-4.2/OLD-READMEs/README-2.1",
    "content": "\tSQUASHFS 2.1 - A squashed read-only filesystem for Linux\n\n\tCopyright 2004 Phillip Lougher (plougher@users.sourceforge.net)\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 2.1-r2.  Squashfs 2.1 introduces indexed\ndirectories which considerably speed up directory lookup (ls, find etc.) for\ndirectories which are greater than 8K in size.  All directories are now also\nsorted alphabetically which further speeds up directory lookup.  Many smaller\nimprovements have also been made to this release, please see the CHANGES file\nentry for detailed changes.\n\n1. DIRECTORY SPEED IMPROVEMENT EXAMPLES\n---------------------------------------\n\nTo give an indication of the directory speed improvements a number of test\nresults are shown here.  There is in addition a new PERFORMANCE.README file\nwhich gives details of I/O and lookup performance for Squashfs 2.1 against\nthe Zisofs, Cloop and CRAMFS filesystems.\n\nexample 1:\n\nFilesystems generated from a single directory of 72,784 files (2.6 MB\ndirectory size).  Each file is 10 bytes in size (the test is directory\nlookup and so the file size isn't an issue).  The ext3 uncompressed\ndirectory size is 288 MB (presumably because of one file per block).\n\nZisofs compressed size        153.50 MB\nCloop (isofs) compressed size 1.74 MB\nSquashfs2.1 compressed size   612 KB (0.60 MB)\n\nTime taken to perform \"ls -lR --color=always | cat > /dev/null\" on\nfilesystems mounted on hard disk.\n\nZisofs       35 minutes 7.895 seconds (User 7.868 secs, Sys 34 mins 5.621 secs)\nCloop        35 minutes 12.765 seconds (User 7.771 secs, Sys 34 mins 3.869 secs)\nSquashfs2.1  19 seconds (User 5.119 secs, Sys 14.547 secs)\n\nexample 2:\n\nFilesystems were generated from the Ubuntu Warty livecd (original uncompressed\nsize on ext3 is 1.4 GB).\n\nZisofs compressed size        589.81 MB\nCloop (isofs) compressed size 471.19 MB\nSquashfs2.0 compressed size   448.58 MB\nSquashfs2.1 compressed size   448.58 MB\n\nTime taken to perform \"ls -lR --color=always | cat > /dev/null\" on\nfilesystems mounted on hard disk.\n\nZisofs        49.875 seconds (User time 2.589 secs, Sys 11.194 secs)\nCloop         20.797 seconds (User time 2.706 secs, Sys 13.496 secs)\nSquashfs2.0   16.556 seconds (User time 2.424 secs, Sys 10.371 secs)\nSquashfs2.1   10.143 seconds (User time 2.475 secs, Sys 4.440 secs)\n\n\nNOTE: the usual warnings apply to these results, they are provided for\nillustrative purposes only, and due to different hardware and/or file data, you\nmay obtain different results.  As such the results are provided \"as is\" without\nany warranty (either express or implied) and you assume all risks as to their\nquality and accuracy.\n\n2. NEW MKSQUASHFS OPTIONS\n-------------------------\n\nThere is only one extra option \"-2.0\".  This tells mksquashfs to generate\na filesystem which is mountable with Squashfs version 2.0.\n\n3. APPENDING AND MOUNTING SQUASHFS 2.0 FILESYSTEMS\n--------------------------------------------------\n\nMounting 2.0 filesystems is supported by Squashfs 2.1.  In addition\nmksquashfs v2.1 can append to 2.0 filesystems, although the generated\nfilesystem will still be a 2.0 filesystem.\n\n4. DONATIONS\n------------\n\nIf you find Squashfs useful then please consider making a donation,\nparticularly if you use Squashfs in a commercial product.  Please consider\ngiving something back especially if you're making money from it.\n\nOff the Squashfs subject somewhat I'm currently looking for another\njob doing Linux kernel or filesystems work.  If you know of any such\nwork that can be performed from the UK then please get in touch.  Thanks.\n"
  },
  {
    "path": "src/others/squashfs-4.2/OLD-READMEs/README-3.0",
    "content": "\tSQUASHFS 3.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2006 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to the first release of Squashfs version 3.0.  Squashfs 3.0 has the\nthe following improvements to 2.x.\n\n\t1. Filesystems are no longer limited to 4 GB.  In\n\t   theory 2^64 or 4 exabytes is now supported.\n\n\t2. Files are no longer limited to 4 GB.  In theory the maximum\n\t   file size is 4 exabytes.\n\n\t3. Metadata (inode table and directory tables) are no longer\n\t   restricted to 16 Mbytes.\n\n\t4. Hardlinks are now suppported.\n\n\t5. Nlink counts are now supported.\n\n\t6. Readdir now returns '.' and '..' entries.\n\n\t7. Special support for files larger than 256 MB has been added to\n\t   the Squashfs kernel code for faster read access.\n\n\t8. Inode numbers are now stored within the inode rather than being\n\t   computed from inode location on disk (this is not so much an\n\t   improvement, but a change forced by the previously listed\n\t   improvements).\n\nThere is a new Unsquashfs utility (in squashfs-tools) than can be used to\ndecompress a filesystem without mounting it.\n\nSquashfs 3.0 supports 2.x filesystems.  Support for 1.x filesystems\nwill be added in the future.\n\n1. UNSQUASHFS\n-------------\n\nUnsquashfs has the following options:\n\nSYNTAX: unsquashfs [-ls | -dest] filesystem\n\t-version\t\tprint version, licence and copyright information\n\t-info\t\t\tprint files as they are unsquashed\n\t-ls\t\t\tlist filesystem only\n\t-dest <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\nThe \"-ls\" option can be used to list the contents of a filesystem without\ndecompressing the filesystem data itself.\n\nThe \"-info\" option forces Unsquashfs to print each file as it is decompressed.\n\nThe \"-dest\" option specifies the directory that is used to decompress\nthe filesystem data.  If this option is not given then the filesystem is\ndecompressed to the directory \"squashfs-root\" in the current working directory.\n\nUnsquashfs can decompress 3.0 filesystems.  Support for 2.x and 1.x\nfilesystems will be added in the future.\n"
  },
  {
    "path": "src/others/squashfs-4.2/OLD-READMEs/README-3.1",
    "content": "\tSQUASHFS 3.1 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2006 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.1-r2.  Squashfs 3.1 has major improvements to\nthe Squashfs tools (Mksquashfs and Unsquashfs), some major bug fixes, new\nkernel patches, and various other smaller improvements and bug fixes.\nPlease see the CHANGES file for a detailed list.\n\n1. MKSQUASHFS\n-------------\n\nMksquashfs has been rewritten and it is now multi-threaded.  It offers\nthe following improvements:\n\n1. Parallel compression.  By default as many compression and fragment\ncompression threads are created as there are available processors.\nThis significantly speeds up performance on SMP systems.\n\n2. File input and filesystem output is peformed in parallel on separate\nthreads to maximise I/O performance.  Even on single processor systems\nthis speeds up performance by at least 10%.\n\n3. Appending has been significantly improved, and files within the\nfilesystem being appended to are no longer scanned and checksummed.  This\nsignificantly improves append time for large filesystems.\n\n4. File duplicate checking has been optimised, and split into two separate\nphases.  Only files which are considered possible duplicates after the\nfirst phase are checksummed and cached in memory.\n\n5. The use of swap memory was found to significantly impact performance. The\namount of memory used to cache the file is now a command line option, by default\nthis is 512 Mbytes.\n\n1.1 NEW COMMAND LINE OPTIONS\n----------------------------\n\nThe new Mksquashfs program has a couple of extra command line options\nwhich can be used to control the new features:\n\n-processors <processors>\n\nThis specifies the number of processors used by Mksquashfs.\nBy default this is the number of available processors.\n\n-read_queue <size in Mbytes>\n\nThis specifies the size of the file input queue used by the reader thread.\nThis defaults to 64 Mbytes.\n\n-write_queue <size in Mbytes>\n\nThis specifies the size of the filesystem output queue used by the\nwriter thread.  It also specifies the maximum cache used in file\nduplicate detection (the output queue is shared between these tasks).\nThis defaults to 512 Mbytes.\n\n1.2 PERFORMANCE RESULTS\n-----------------------\n\nThe following results give an indication of the speed improvements.  Two\nexample filesystems were tested, a liveCD filesystem (about 1.8 Gbytes\nuncompressed), and my home directory consisting largely of text files\n(about 1.3 Gbytes uncompressed).  Tests were run on a single core\nand a dual core system.\n\nDual Core (AMDx2 3800+) system:\nSource directories on ext3.\n\nLiveCD, old mksquashfs:\n\nreal    11m48.401s\nuser    9m27.056s\nsys     0m15.281s\n\nLiveCD, new par_mksquashfs:\n\nreal    4m8.736s\nuser    7m11.771s\nsys     0m27.749s\n\n\"Home\", old mksquashfs:\n\nreal    4m34.360s\nuser    3m54.007s\nsys     0m32.155s\n\n\"Home\", new par_mksquashfs:\n\nreal    1m27.381s\nuser    2m7.304s\nsys     0m17.234s\n\nSingle Core PowerBook (PowerPC G4 1.5 GHz Ubuntu Linux)\nSource directories on ext3.\n\nLiveCD, old mksquashs:\n\nreal    11m38.472s\nuser    9m6.137s\nsys     0m23.799s\n\nLiveCD,  par_mksquashfs:\n\nreal    10m5.572s\nuser    8m59.921s\nsys     0m16.145s\n\n\"Home\", old mksquashfs:\n\nreal    3m42.298s\nuser    2m49.478s\nsys     0m13.675s\n\n\"Home\", new par_mksquashfs:\n\nreal    3m9.178s\nuser    2m50.699s\nsys     0m9.069s\n\nI'll be interested in any performance results obtained, especially from SMP\nmachines larger than my dual-core AMD box, as this will give an indication of\nthe scalability of the code.  Obviously, I'm also interested in any problems,\ndeadlocks, low performance etc.\n\n2. UNSQUASHFS\n-------------\n\nUnsquashfs now allows you to specify the filename or directory that is to be\nextracted from the Squashfs filesystem, rather than always extracting the\nentire filesystem.  It also has a new \"-force\" option, and all options can be\nspecified in a short form (-i rather than -info).\n\nThe Unsquashfs usage info is now:\n\nSYNTAX: ./unsquashfs [options] filesystem [directory or file to extract]\n\t-v[ersion]\t\tprint version, licence and copyright information\n\t-i[nfo]\t\t\tprint files as they are unsquashed\n\t-l[s]\t\t\tlist filesystem only\n\t-d[est] <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\t-f[orce]\t\tif file already exists then overwrite\n\nTo extract a subset of the filesystem, the filename or directory\ntree that is to be extracted can now be specified on the command line.  The\nfile/directory should be specified using the full path to the file/directory\nas it appears within the Squashfs filesystem.  The file/directory will also be\nextracted to that position within the specified destination directory.\n\nThe new \"-force\" option forces Unsquashfs to output to the destination\ndirectory even if files or directories already exist.  This allows you\nto update an existing directory tree, or to Unsquashfs to a partially\nfilled directory.  Without the \"-force\" option, Unsquashfs will\nrefuse to overwrite any existing files, or to create any directories if they\nalready exist.  This is done to protect data in case of mistakes, and\nso the \"-force\" option should be used with caution.\n"
  },
  {
    "path": "src/others/squashfs-4.2/OLD-READMEs/README-3.2",
    "content": "\tSQUASHFS 3.2 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.org.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 3.2.  Squashfs 3.2 has support for NFS exporting,\nsome improvements to the Squashfs tools (Mksquashfs and Unsquashfs), some\nmajor bug fixes, new kernel patches, and various other smaller improvements\nand bug fixes.  Please see the CHANGES file for a detailed list.\n\n1. MKSQUASHFS\n-------------\n\nNew command line options:\n\n-no-exports\n\n\tSquashfs now supports NFS exports.  By default the additional\n\tinformation necessary is added to the filesystem by Mksquashfs.  If you\n\tdo not wish this extra information, then this option can be specified.\n\tThis will save a couple of bytes per file, and the filesystem\n\twill be identical to Squashfs 3.1.\n\n-no-progress\n\n\tMksquashfs by default now displays a progress bar. This option disables\n\tit.\n\n2. UNSQUASHFS\n-------------\n\n\tUnsquashfs now supports Squashfs 2.x filesystems.\n"
  },
  {
    "path": "src/others/squashfs-4.2/OLD-READMEs/README-3.3",
    "content": "\tSQUASHFS 3.3 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2007 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to another release of Squashfs.  This is the 22nd release in just\nover five years of work.  Squashfs 3.3 has lots of nice improvements,\nboth to the filesystem itself (bigger blocks, and sparse files), but\nalso to the Squashfs-tools Mksquashfs and Unsquashfs.  As usual the\nCHANGES file has a detailed list of all the improvements.\n\nFollowing is a description of the changes to  the Squashfs tools, usage\nguides to the new options, and a summary of the new options.\n\n1. MKSQUASHFS - EXTENDED EXCLUDE FILE HANDLING\n----------------------------------------------\n\n1. Extended wildcard pattern matching now supported in exclude files\n\n  Enabled by specifying -wildcards option\n\n  Supports both anchored and non-anchored exclude files.\n\n1.1 Anchored excludes\n\n  Similar to existing exclude files except with wildcards.  Exclude\n  file matches from root of source directories.\n\n  Examples:\n\n  1. mksquashfs example image.sqsh -wildcards -e 'test/*.gz'\n\n     Exclude all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. mksquashfs example image.sqsh -wildcards -e '*/[Tt]est/example*'\n\n     Exclude all files beginning with \"example\" inside directories called\n     \"Test\" or \"test\", that occur inside any top level directory.\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -wildcards -e 'test/!(*data*).gz'\n\n     Exclude all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\n1.2 Non-anchored excludes\n\n  By default excludes match from the top level directory, but it is\n  often useful to exclude a file matching anywhere in the source directories.\n  For this non-anchored excludes can be used, specified by pre-fixing the\n  exclude with \"...\".\n\n  Examples:\n\n  1. mksquashfs example image.sqsh -wildcards -e '... *.gz'\n\n     Exclude files matching \"*.gz\" anywhere in the source directories.\n     For example this will match \"example.gz\", \"test/example.gz\", and\n     \"test/test/example.gz\".\n\n  2. mksquashfs example image.sqsh -wildcards -e '... [Tt]est/*.gz'\n\n     Exclude files matching \"*.gz\" inside directories called \"Test\" or\n     \"test\" that occur anywhere in the source directories.\n\n  Again, using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -wildcards -e '... !(*data*).gz'\n\n     Exclude all files matching \"*.gz\" anywhere in the source directories,\n     except those with \"data\" in the name.\n\n2. Regular expression pattern matching now supported in exclude files\n\n  Enabled by specifying -regex option.  Identical behaviour to wild\ncard pattern matching, except patterns are considered to be regular\nexpressions.\n\n  Supports both anchored and non-anchored exclude files.\n\n\n2. MKSQUASHFS - NEW RECOVERY FILE FEATURE\n-----------------------------------------\n\nRecovery files are now created when appending to existing Squashfs\nfilesystems.  This allows the original filesystem to be recovered\nif Mksquashfs aborts unexpectedly (i.e. power failure).\n\nThe recovery files are called squashfs_recovery_xxx_yyy, where\n\"xxx\" is the name of the filesystem being appended to, and \"yyy\" is a\nnumber to guarantee filename uniqueness (the PID of the parent Mksquashfs\nprocess).\n\nNormally if Mksquashfs exits correctly the recovery file is deleted to\navoid cluttering the filesystem.  If Mksquashfs aborts, the \"-recover\"\noption can be used to recover the filesystem, giving the previously\ncreated recovery file as a parameter, i.e.\n\nmksquashfs dummy image.sqsh -recover squashfs_recovery_image.sqsh_1234\n\nThe writing of the recovery file can be disabled by specifying the\n\"-no-recovery\" option.\n\n\n3. UNSQUASHFS - EXTENDED EXTRACT FILE HANDLING\n----------------------------------------------\n\n1. Multiple extract files can now be specified on the command line, and the\nfiles/directories to be extracted can now also be given in a file.\n\nTo specify a file containing the extract files use the \"-e[f]\" option.\n\n2. Extended wildcard pattern matching now supported in extract files\n\n  Enabled by default.  Similar to existing extract files except with\nwildcards.\n\n  Examples:\n\n  1. unsquashfs image.sqsh 'test/*.gz'\n\n     Extract all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. unsquashfs image.sqsh '[Tt]est/example*'\n\n     Extract all files beginning with \"example\" inside top level directories\n     called \"Test\" or \"test\".\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. unsquashfs image.sqsh 'test/!(*data*).gz'\n\n     Extract all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\n3. Regular expression pattern matching now supported in extract files\n\n  Enabled by specifying -r[egex] option.  Identical behaviour to wild\ncard pattern matching, except patterns are considered to be regular\nexpressions.\n\n4. UNSQUASHFS - EXTENDED FILENAME PRINTING\n------------------------------------------\n\nFilename printing has been enhanced and Unquashfs can now display filenames\nwith file attributes ('ls -l' style output).\n\nNew options:\n\n  -ll[s]\n\n   list filesystem with file attributes, but don't unsquash\n\n  -li[nfo]\n\n   print files as they are unsquashed with file attributes\n\n\n5. UNSQUASHFS - MISCELLANEOUS OPTIONS\n-------------------------------------\n\n   -s[tat]\n\n   Display the filesystem superblock information.  This is useful to\n   discover the filesystem version, byte ordering, whether it has an\n   NFS export table, and what options were used to compress\n   the filesystem.\n"
  },
  {
    "path": "src/others/squashfs-4.2/OLD-READMEs/README-4.0",
    "content": "\tSQUASHFS 4.0 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2009 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs 4.0.  This is an initial tools only release to\nsupport users of the 2.6.29 kernel, following the mainlining of Squashfs\nearlier this year.\n\nLater releases will probably contain kernel patches supporting 4.0\nlayouts for earlier kernels.\n\nNew Mksquashfs options\n----------------------\n\nMksquashfs now supports pseudo files, these allow fake directories, character\nand block devices to be specified and added to the Squashfs filesystem being\nbuilt, rather than requiring them to be present in the source directories.\nThis, for example, allows device nodes to be added to the filesystem without\nrequiring root access.\n\nTwo options are supported, -p allows one pseudo file to be specified on the\ncommand line, and -pf allows a pseudo file to be specified containing a\nlist of pseduo definitions, one per line.\n\nPseudo device nodes are specified using 7 arguments\n\nFilename type mode uid gid major minor\n\nWhere type is either\n\tb - for block devices, and\n\tc - for character devices\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nUid and gid can be either specified as a decimal number, or by name.\n\nFor example:\n\n/dev/chr_dev c 666 root root 100 1\n/dev/blk_dev b 444 0 0 200 200\n\nDirectories are specified using 5 arguments\n\nFilename type mode uid gid\n\nWhere type is d.\n"
  },
  {
    "path": "src/others/squashfs-4.2/OLD-READMEs/README-4.1",
    "content": "\tSQUASHFS 4.1 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2010 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs 4.1.  This is a tools only release, support for Squashfs\nfile systems is in mainline (2.6.29 and later).\n\nNew features in Squashfs-tools 4.1\n----------------------------------\n\n  1. Support for extended attributes\n  2. Support for LZMA and LZO compression\n  3. New pseudo file features\n\nCompatiblity\n------------\n\nMksquashfs 4.1 generates 4.0 filesystems.  These filesystems are fully\ncompatible/interchangable with filesystems generated by Mksquashfs 4.0 and are\nmountable on 2.6.29 and later kernels.\n\nExtended attributes (xattrs)\n----------------------------\n\nSquashfs file systems now have extended attribute support.  The\nextended attribute implementation has the following features:\n\n1. Layout can store up to 2^48 bytes of compressed xattr data.\n2. Number of xattrs per inode unlimited.\n3. Total size of xattr data per inode 2^48 bytes of compressed data.\n4. Up to 4 Gbytes of data per xattr value.\n5. Inline and out-of-line xattr values supported for higher performance\n   in xattr scanning (listxattr & getxattr), and to allow xattr value\n   de-duplication.\n6. Both whole inode xattr duplicate detection and individual xattr value\n   duplicate detection supported.  These can obviously nest, file C's\n   xattrs can be a complete duplicate of file B, and file B's xattrs\n   can be a partial duplicate of file A.\n7. Xattr name prefix types stored, allowing the redundant \"user.\", \"trusted.\"\n   etc. characters to be eliminated and more concisely stored.\n8. Support for files, directories, symbolic links, device nodes, fifos\n   and sockets.\n\nExtended attribute support is in 2.6.35 and later kernels.  File systems\nwith extended attributes can be mounted on 2.6.29 and later kernels, the\nextended attributes will be ignored with a warning.\n\nLZMA and LZO compression\n------------------------\n\nSquashfs now supports LZMA and LZO compression.\n\nLZO support is in 2.6.36 and newer kernels.  LZMA is not yet in mainline.\n\nNew Mksquashfs options\n----------------------\n\n-comp <comp>\n\n    Select <comp> compression.  \n\n    The compression algorithms supported by the build of Mksquashfs can be\n    found by typing mksquashfs without any arguments.  The compressors available\n    are displayed at the end of the help message, e.g.\n\n    Compressors available:\n\tgzip (default)\n\tlzma\n\tlzo\n\n    The default compression used when -comp isn't specified on the command line\n    is indicated by \"(default)\".\n\n-no-xattrs\n    Don't store extended attributes\n\n-xattrs\n    Store extended attributes\n\n    The default behaviour of Mksquashfs with respect to extended attribute\n    storage is build time selectable.  The Mksquashfs help message indicates\n    whether extended attributes are stored or not, e.g.\n\n\t-no-xattrs\t\tdon't store extended attributes\n\t-xattrs\t\t\tstore extended attributes (default)\n\n    shows that extended attributes are stored by default, and can be disabled\n    by the -no-xattrs option.\n\n\t-no-xattrs\t\tdon't store extended attributes (default)\n\t-xattrs\t\t\tstore extended attributes \n\n    shows that extended attributes are not stored by default, storage can be\n    enabled by the -xattrs option.\n\n\n-noX\n-noXattrCompression\n    Don't compress extended attributes\n\n\nNew Unsquashfs options\n----------------------\n\n-n[o-xattrs]\n    Don't extract xattrs in filesystem\n\n-x[attrs]\n    Extract xattrs in filesystem\n\n    The default behaviour of Unsquashfs with respect to extended attributes\n    is build time selectable.  The Unsquashfs help message indicates whether\n    extended attributes are stored or not, e.g.\n\n\t-no[-xattrs]\t\tdon't extract xattrs in file system\n\t-x[attrs]\t\textract xattrs in file system (default)\n\n    shows that xattrs are extracted by default.\n\n\t-no[-xattrs]\t\tdon't extract xattrs in file system (default)\n\t-x[attrs]\t\textract xattrs in file system\n\n    shows that xattrs are not extracted by default.\n\n\nNew pseudo file support\n-----------------------\n\nMksquashfs supports pseudo files, these allow fake files, directories, character\nand block devices to be specified and added to the Squashfs filesystem being\nbuilt, rather than requiring them to be present in the source directories.\nThis, for example, allows device nodes to be added to the filesystem without\nrequiring root access.\n\nMksquashfs 4.1 adds support for \"dynamic pseudo files\" and a modify operation.\nDynamic pseudo files allow files to be dynamically created when Mksquashfs\nis run, their contents being the result of running a command or piece of\nshell script.  The modifiy operation allows the mode/uid/gid of an existing\nfile in the source filesystem to be modified.\n\nTwo Mksquashfs options are supported, -p allows one pseudo file to be specified\non the command line, and -pf allows a pseudo file to be specified containing a\nlist of pseduo definitions, one per line.\n\nPseudo operations\n-----------------\n\n1. Creating a dynamic file\n--------------------------\n\nPseudo definition\n\nFilename f mode uid gid command\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nuid and gid can be either specified as a decimal number, or by name.\n\ncommand can be an executable or a piece of shell script, and it is executed\nby running \"/bin/sh -c command\".   The stdout becomes the contents of\n\"Filename\".\n\nExamples:\n\nRunning a basic command\n-----------------------\n\n/somedir/dmesg f 444 root root dmesg\n\ncreates a file \"/somedir/dmesg\" containing the output from dmesg.\n\nExecuting shell script\n----------------------\n\nRELEASE f 444 root root \\\n\t\tif [ ! -e /tmp/ver ]; then \\\n\t\t\techo 0 > /tmp/ver; \\\n\t\tfi; \\\n                ver=`cat /tmp/ver`; \\\n                ver=$((ver +1)); \\\n                echo $ver > /tmp/ver; \\\n                echo -n `cat /tmp/release`; \\\n                echo \"-dev #\"$ver `date` \"Build host\" `hostname`\n\nCreates a file RELEASE containing the release name, date, build host, and\nan incrementing version number.  The incrementing version is a side-effect\nof executing the shell script, and ensures every time Mksquashfs is run a\nnew version number is used without requiring any other shell scripting.\n\nThe above example also shows that commands can be split across multiple lines\nusing \"\\\".  Obviously as the script will be presented to the shell as a single\nline, a semicolon is need to separate individual shell commands within the\nshell script.\n\nReading from a device (or fifo/named socket)\n--------------------------------------------\n\ninput f 444 root root dd if=/dev/sda1 bs=1024 count=10\n\nCopies 10K from the device /dev/sda1 into the file input.  Ordinarily Mksquashfs\ngiven a device, fifo, or named socket will place that special file within the\nSquashfs filesystem, the above allows input from these special files to be\ncaptured and placed in the Squashfs filesystem.\n\n2. Creating a block or character device\n---------------------------------------\n\nPseudo definition\n\nFilename type mode uid gid major minor\n\nWhere type is either\n\tb - for block devices, and\n\tc - for character devices\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nuid and gid can be either specified as a decimal number, or by name.\n\nFor example:\n\n/dev/chr_dev c 666 root root 100 1\n/dev/blk_dev b 666 0 0 200 200\n\ncreates a character device \"/dev/chr_dev\" with major:minor 100:1 and\na block device \"/dev/blk_dev\" with major:minor 200:200, both with root\nuid/gid and a mode of rw-rw-rw.\n\n3. Creating a directory\n-----------------------\n\nPseudo definition\n\nFilename d mode uid gid\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nuid and gid can be either specified as a decimal number, or by name.\n\nFor example:\n\n/pseudo_dir d 666 root root\n\ncreates a directory \"/pseudo_dir\" with root uid/gid and mode of rw-rw-rw.\n\n4. Modifying attributes of an existing file\n-------------------------------------------\n\nPseudo definition\n\nFilename m mode uid gid\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nuid and gid can be either specified as a decimal number, or by name.\n\nFor example:\n\ndmesg m 666 root root\n\nChanges the attributes of the file \"dmesg\" in the filesystem to have\nroot uid/gid and a mode of rw-rw-rw, overriding the attributes obtained\nfrom the source filesystem.\n"
  },
  {
    "path": "src/others/squashfs-4.2/OLD-READMEs/README-AMD64",
    "content": "Information for amd64 users\n---------------------------\n\nAll releases of Squashfs prior to 2.0 generate incorrect\nfilesystems on amd64 machines.  Filesystems created on amd64 machines work\ncorrectly on amd64 machines, but cannot be mounted on non-amd64 machines.\nLikewise, filesystems created on non-amd64 machines cannot be mounted on amd64\nmachines.  This bug is caused by the different size of the \"time_t\" definition\nused in SquashFS filesystem structures.\n\nThis bug is fixed in releases 2.0 and newer.  However, all amd64 filesystems\ngenerated by previous releases will not be mountable on amd64 machines\nwith newer releases.  If you have amd64 filesystems generated with mksquashfs\nversion 2.0-alpha or older, it is important that you recreate the filesystem.\nThis can be performed by mounting the filesystem using a kernel with the\noriginal patch (i.e. a 2.0-alpha or older patch) and running the NEW (i.e. this\nrelease) mksquashfs tool to create a new SquashFS filesystem.\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/PERFORMANCE.README",
    "content": "GENERAL INFORMATION ON PERFORMANCE TESTS\n----------------------------------------\n\nThe following performance tests were based on two file sets: the\nliveCD filesystem from the Ubuntu liveCD (Warty release), and the\nliveCD filesystem from the Damn Small Linux liveCD (release 0.8.4).\nThe Ubuntu liveCD filesystem was used to test filesystem performance\nfrom CDROM and hard disk for Zisofs, Cloop, Squashfs 2.0 and Squashfs2.1.\nCRAMFS filesystem performance could not be tested for this filesystem\nbacause it exceeds the maximum supported size of CRAMFS.  To test\nCRAMFS performance against Squashfs, the liveCD filesystem from\nDamn Small Linux was used.\n\nNOTE: the usual warnings apply to these results, they are provided for\nillustrative purposes only, and due to different hardware and/or file data, you\nmay obtain different results.  As such the results are provided \"as is\" without\nany warranty (either express or implied) and you assume all risks as to their\nquality and accuracy.\n\n1. Ubuntu liveCD performance tests\n\n   ext3 uncompressed size      1.4 GB\n   Zisofs compressed size      589.81 MB\n   Cloop compressed size       471.89 MB\n   Squashfs2.0 compressed size 448.58 MB\n   Squashfs2.1 compressed size 448.58 MB\n\n1.1 Performance tests from CDROM\n\n1.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  Zisofs       49.88 seconds (User 2.60 secs, Sys 11.19 secs)\n  Cloop        20.80 seconds (User 2.71 secs, Sys 13.50 secs)\n  Squashfs2.0  16.56 seconds (User 2.42 secs, Sys 10.37 secs)\n  Squashfs2.1  10.14 seconds (User 2.48 secs, Sys 4.44 secs)\n\n1.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  Zisofs       27 minutes 28.54 seconds (User 3.00 secs, Sys 1 min 4.80 secs)\n  Cloop        5 minutes 55.72 seconds (User 2.90 secs, Sys 3 min 37.90 secs)\n  Squashfs2.0  5 minutes 20.87 seconds (User 2.33 secs, Sys 56.98 secs)\n  Squashfs2.1  5 minutes 15.46 seconds (user 2.28 secs, Sys 51.12 secs)\n\n1.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n  Zisofs       101 minutes 29.65 seconds (User 5.33 secs, Sys  1 min 17.20 secs)\n  Cloop        35 minutes 27.51 seconds (user 5.93 secs, Sys 4 mins 30.23 secs)\n  Squashfs2.0  21 minutes 53.05 seconds (user 5.71 secs, Sys 2 mins 36.59 secs)\n  Squashfs2.1  21 minutes 46.99 seconds (User 5.80 secs, Sys 2 mins 31.88 secs)\n\n\n1.2 Performance tests from Hard disk\n\n1.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk \n\n  Zisofs       17.29 seconds (User 2.62 secs, Sys 11.08 secs)\n  Cloop        16.46 seconds (User 2.63 secs, Sys 13.41 secs)\n  Squashfs2.0  13.75 seconds (User 2.44 secs, Sys 11.00 secs)\n  Squashfs2.1  6.94 seconds (User 2.44 secs, Sys 4.48 secs)\n\n1.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk\n\n  Zisofs       1 minute 21.47 seconds (User 2.73 secs, Sys 54.44 secs)\n  Cloop        1 minute 34.06 seconds (user 2.85 secs, Sys 1 min 12.13 secs)\n  Squashfs2.0  1 minute 21.22 seconds (User 2.42 secs, Sys 56.21 secs)\n  Squashfs2.1  1 minute 15.46 seconds (User 2.36 secs, Sys 49.78 secs)\n\n1.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk\n\n  Zisofs       11 minutes 13.64 seconds (User 5.08 secs, Sys 52.62 secs)\n  Cloop        5 minutes 37.93 seconds (user 6 secs, Sys 2 mins 22.38 secs)\n  Squashfs2.0  5 minutes 7.11 seconds (user 5.63 secs, Sys 2 mins 35.23 secs)\n  Squashfs2.1  5 minutes 1.87 seconds (User 5.71 secs, Sys 2 mins 29.98 secs)\n\n\n2. Damn Small Linux liveCD performance tests\n\n   ext3 uncompressed size      126 MB\n   CRAMFS compressed size      52.19 MB\n   Squashfs2.0 compressed size 46.52 MB\n   Squashfs2.1 compressed size 46.52 MB\n\n2.1 Performance tests from CDROM\n\n2.1.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from CDROM\n\n  CRAMFS       10.85 seconds (User 0.39 secs, Sys 0.98 secs)\n  Squashfs2.0  2.97 seconds (User 0.36 secs, Sys 2.15 secs)\n  Squashfs2.1  2.43 seconds (User 0.40 secs, Sys 1.42 secs)\n\n2.1.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from CDROM\n\n  CRAMFS       55.38 seconds (User 0.34 secs, Sys 6.98 secs)\n  Squashfs2.0  35.99 seconds (User 0.30 secs, Sys 6.35 secs)\n  Squashfs2.1  33.83 seconds (User 0.26 secs, Sys 5.56 secs)\n\n2.1.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from CDROM\n\n\n  CRAMFS        3 minutes 1.68 seconds (User 0.54 secs, Sys 9.51 secs)\n  Squashfs2.0   1 minute 39.45 seconds (User 0.57 secs, Sys 13.14 secs)\n  Squashfs2.1   1 minute 38.41 seconds (User 0.58 secs, Sys 13.08 secs)\n\n2.2 Performance tests from Hard disk\n\n2.2.1 Directory Lookup performance\n\n  Time taken to perform \"ls -lR --color=alawys | cat > /dev/null\" on filesystem\n  mounted from Hard disk\n\n  CRAMFS       1.77 seconds (User 0.53 secs, Sys 1.21 secs)\n  Squashfs2.0  2.67 seconds (User 0.41 secs, Sys 2.25 secs)\n  Squashfs2.1  1.87 seconds (User 0.41 secs, Sys 1.46 secs)\n\n2.2.2 Sequential I/O performance\n\n  Time taken to perform \"tar cf - | cat > /dev/null\" on filesystem mounted\n  from Hard disk \n\n  CRAMFS       6.80 seconds (User 0.36 secs, Sys 6.02 secs)\n  Squashfs2.0  7.23 seconds (User 0.29 secs, Sys 6.62 secs)\n  Squashfs2.1  6.53 seconds (User 0.31 secs, Sys 5.82 secs)\n\n2.2.3 Random I/O performance\n\n  Random access pattern generated by \"find /mnt -type f -printf \"%s %p\\n\" | sort\n  -g | awk '{ printf $2 }' > /tmp/sort\n\n  Time taken to perform \"cpio -o --quiet -H newc < /tmp/sort > /dev/null\"\n  on filesystem mounted from Hard disk \n\n\n  CRAMFS       28.55 seconds (User 0.49 secs, Sys 6.49 secs)\n  Squashfs2.0  25.44 seconds (User 0.58 secs, Sys 13.17 secs)\n  Squashfs2.1  24.72 seconds (User 0.56 secs, Sys 13.15 secs)\n"
  },
  {
    "path": "src/others/squashfs-4.2/README",
    "content": "\tSQUASHFS 4.2 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2011 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs version 4.2.  Please read the README-4.2 and CHANGES files\nfor details of changes.\n\nSquashfs is a highly compressed read-only filesystem for Linux.\nIt uses zlib compression to compress both files, inodes and directories.\nInodes in the system are very small and all blocks are packed to minimise\ndata overhead. Block sizes greater than 4K are supported up to a maximum\nof 1Mbytes (default block size 128K).\n\nSquashfs is intended for general read-only filesystem use, for archival\nuse (i.e. in cases where a .tar.gz file may be used), and in constrained\nblock device/memory systems (e.g. embedded systems) where low overhead is\nneeded.\n\n1. SQUASHFS OVERVIEW\n--------------------\n\n1. Data, inodes and directories are compressed.\n\n2. Squashfs stores full uid/gids (32 bits), and file creation time.\n\n3. In theory files up to 2^64 bytes are supported.  In theory filesystems can\n   be up to 2^64 bytes.\n\n4. Inode and directory data are highly compacted, and packed on byte\n   boundaries.  Each compressed inode is on average 8 bytes in length\n   (the exact length varies on file type, i.e. regular file, directory,\n   symbolic link, and block/char device inodes have different sizes).\n\n5. Squashfs can use block sizes up to 1Mbyte (the default size is 128K).\n   Using 128K blocks achieves greater compression ratios than the normal\n   4K block size.\n\n6. File duplicates are detected and removed.\n\n1.1 Extended attributes (xattrs)\n--------------------------------\n\nSquashfs filesystems now have extended attribute support.  The\nextended attribute implementation has the following features:\n\n1. Layout can store up to 2^48 bytes of compressed xattr data.\n2. Number of xattrs per inode unlimited.\n3. Total size of xattr data per inode 2^48 bytes of compressed data.\n4. Up to 4 Gbytes of data per xattr value.\n5. Inline and out-of-line xattr values supported for higher performance\n   in xattr scanning (listxattr & getxattr), and to allow xattr value\n   de-duplication.\n6. Both whole inode xattr duplicate detection and individual xattr value\n   duplicate detection supported.  These can obviously nest, file C's\n   xattrs can be a complete duplicate of file B, and file B's xattrs\n   can be a partial duplicate of file A.\n7. Xattr name prefix types stored, allowing the redundant \"user.\", \"trusted.\"\n   etc. characters to be eliminated and more concisely stored.\n8. Support for files, directories, symbolic links, device nodes, fifos\n   and sockets.\n\nExtended attribute support is in 2.6.35 and later kernels.  Filesystems\nwith extended attributes can be mounted on 2.6.29 and later kernels, the\nextended attributes will be ignored with a warning.\n\n2. USING SQUASHFS\n-----------------\n\nSquashfs filesystems should be mounted with 'mount' with the filesystem type\n'squashfs'.  If the filesystem is on a block device, the filesystem can be\nmounted directly, e.g.\n\n%mount -t squashfs /dev/sda1 /mnt\n\nWill mount the squashfs filesystem on \"/dev/sda1\" under the directory \"/mnt\".\n\nIf the squashfs filesystem has been written to a file, the loopback device\ncan be used to mount it (loopback support must be in the kernel), e.g.\n\n%mount -t squashfs image /mnt -o loop\n\nWill mount the squashfs filesystem in the file \"image\" under\nthe directory \"/mnt\".\n\n\n3. MKSQUASHFS\n-------------\n\n3.1 Mksquashfs options and overview.\n------------------------------------\n\nAs squashfs is a read-only filesystem, the mksquashfs program must be used to\ncreate populated squashfs filesystems.\n\nSYNTAX:./mksquashfs source1 source2 ...  dest [options] [-e list of exclude\ndirs/files]\n\nFilesystem build options:\n-comp <comp>\t\tselect <comp> compression\n\t\t\tCompressors available:\n\t\t\t\tgzip (default)\n\t\t\t\tlzo\n\t\t\t\txz\n-b <block_size>\t\tset data block to <block_size>.  Default 131072 bytes\n-no-exports\t\tdon't make the filesystem exportable via NFS\n-no-sparse\t\tdon't detect sparse files\n-no-xattrs\t\tdon't store extended attributes\n-xattrs\t\t\tstore extended attributes (default)\n-noI\t\t\tdo not compress inode table\n-noD\t\t\tdo not compress data blocks\n-noF\t\t\tdo not compress fragment blocks\n-noX\t\t\tdo not compress extended attributes\n-no-fragments\t\tdo not use fragments\n-always-use-fragments\tuse fragment blocks for files larger than block size\n-no-duplicates\t\tdo not perform duplicate checking\n-all-root\t\tmake all files owned by root\n-force-uid uid\t\tset all file uids to uid\n-force-gid gid\t\tset all file gids to gid\n-nopad\t\t\tdo not pad filesystem to a multiple of 4K\n-keep-as-directory\tif one source directory is specified, create a root\n\t\t\tdirectory containing that directory, rather than the\n\t\t\tcontents of the directory\n\nFilesystem filter options:\n-p <pseudo-definition>\tAdd pseudo file definition\n-pf <pseudo-file>\tAdd list of pseudo file definitions\n-sort <sort_file>\tsort files according to priorities in <sort_file>.  One\n\t\t\tfile or dir with priority per line.  Priority -32768 to\n\t\t\t32767, default priority 0\n-ef <exclude_file>\tlist of exclude dirs/files.  One per line\n-wildcards\t\tAllow extended shell wildcards (globbing) to be used in\n\t\t\texclude dirs/files\n-regex\t\t\tAllow POSIX regular expressions to be used in exclude\n\t\t\tdirs/files\n\nFilesystem append options:\n-noappend\t\tdo not append to existing filesystem\n-root-becomes <name>\twhen appending source files/directories, make the\n\t\t\toriginal root become a subdirectory in the new root\n\t\t\tcalled <name>, rather than adding the new source items\n\t\t\tto the original root\n\nMksquashfs runtime options:\n-version\t\tprint version, licence and copyright message\n-recover <name>\t\trecover filesystem data using recovery file <name>\n-no-recovery\t\tdon't generate a recovery file\n-info\t\t\tprint files written to filesystem\n-no-progress\t\tdon't display the progress bar\n-processors <number>\tUse <number> processors.  By default will use number of\n\t\t\tprocessors available\n-read-queue <size>\tSet input queue to <size> Mbytes.  Default 64 Mbytes\n-write-queue <size>\tSet output queue to <size> Mbytes.  Default 512 Mbytes\n-fragment-queue <size>\tSet fragment queue to <size> Mbytes.  Default 64 Mbytes\n\nMiscellaneous options:\n-root-owned\t\talternative name for -all-root\n-noInodeCompression\talternative name for -noI\n-noDataCompression\talternative name for -noD\n-noFragmentCompression\talternative name for -noF\n-noXattrCompression\talternative name for -noX\n\nCompressors available and compressor specific options:\n\tgzip (no options) (default)\n\tlzo (no options)\n\txz\n\t  -Xbcj filter1,filter2,...,filterN\n\t\tCompress using filter1,filter2,...,filterN in turn\n\t\t(in addition to no filter), and choose the best compression.\n\t\tAvailable filters: x86, arm, armthumb, powerpc, sparc, ia64\n\t  -Xdict-size <dict-size>\n\t\tUse <dict-size> as the XZ dictionary size.  The dictionary size\n\t\tcan be specified as a percentage of the block size, or as an\n\t\tabsolute value.  The dictionary size must be less than or equal\n\t\tto the block size and 8192 bytes or larger.  It must also be\n\t\tstorable in the xz header as either 2^n or as 2^n+2^(n+1).\n\t\tExample dict-sizes are 75%, 50%, 37.5%, 25%, or 32K, 16K, 8K\n\t\tetc.\n\n\nSource1 source2 ... are the source directories/files containing the\nfiles/directories that will form the squashfs filesystem.  If a single\ndirectory is specified (i.e. mksquashfs source output_fs) the squashfs\nfilesystem will consist of that directory, with the top-level root\ndirectory corresponding to the source directory.\n\nIf multiple source directories or files are specified, mksquashfs will merge\nthe specified sources into a single filesystem, with the root directory\ncontaining each of the source files/directories.  The name of each directory\nentry will be the basename of the source path.   If more than one source\nentry maps to the same name, the conflicts are named xxx_1, xxx_2, etc. where\nxxx is the original name.\n\nTo make this clear, take two example directories.  Source directory\n\"/home/phillip/test\" contains  \"file1\", \"file2\" and \"dir1\".\nSource directory \"goodies\" contains \"goodies1\", \"goodies2\" and \"goodies3\".\n\nusage example 1:\n\n%mksquashfs /home/phillip/test output_fs\n\nThis will generate a squashfs filesystem with root entries\n\"file1\", \"file2\" and \"dir1\".\n\nexample 2:\n\n%mksquashfs /home/phillip/test goodies output_fs\n\nThis will create a squashfs filesystem with the root containing\nentries \"test\" and \"goodies\" corresponding to the source\ndirectories \"/home/phillip/test\" and \"goodies\".\n\nexample 3:\n\n%mksquashfs /home/phillip/test goodies test output_fs\n\nThis is the same as the previous example, except a third\nsource directory \"test\" has been specified.  This conflicts\nwith the first directory named \"test\" and will be renamed \"test_1\".\n\nMultiple sources allow filesystems to be generated without needing to\ncopy all source files into a common directory.  This simplifies creating\nfilesystems.\n\nThe -keep-as-directory option can be used when only one source directory\nis specified, and you wish the root to contain that directory, rather than\nthe contents of the directory.  For example:\n\nexample 4:\n\n%mksquashfs /home/phillip/test output_fs -keep-as-directory\n\nThis is the same as example 1, except for -keep-as-directory.\nThis will generate a root directory containing directory \"test\",\nrather than the \"test\" directory contents \"file1\", \"file2\" and \"dir1\".\n\nThe Dest argument is the destination where the squashfs filesystem will be\nwritten.  This can either be a conventional file or a block device.  If the file\ndoesn't exist it will be created, if it does exist and a squashfs\nfilesystem exists on it, mksquashfs will append.  The -noappend option will\nwrite a new filesystem irrespective of whether an existing filesystem is\npresent.\n\n3.2 Changing compression algorithm and compression specific options\n-------------------------------------------------------------------\n\nBy default Mksquashfs will compress using the gzip compression\nalgorithm.  This algorithm offers a good trade-off between compression\nratio, and memory and time taken to decompress.\n\nSquashfs also supports LZO and XZ (LZMA2) compression.  LZO offers worse\ncompression ratio than gzip, but is faster to decompress.  XZ offers better\ncompression ratio than gzip, but at the expense of greater memory and time\nto decompress (and significantly more time to compress).\n\nIf you're not building the squashfs-tools and kernel from source, then\nthe tools and kernel may or may not have been built with support for LZO or\nXZ compression.  The compression algorithms supported by the build of\nMksquashfs can be found by typing mksquashfs without any arguments.  The\ncompressors available are displayed at the end of the help message, e.g. \n\nCompressors available and compressor specific options:\n        gzip (no options) (default)\n        lzo (no options)\n        xz\n          -Xbcj filter1,filter2,...,filterN\n                Compress using filter1,filter2,...,filterN in turn\n                (in addition to no filter), and choose the best compression.\n                Available filters: x86, arm, armthumb, powerpc, sparc, ia64\n          -Xdict-size <dict-size>\n                Use <dict-size> as the XZ dictionary size.  The dictionary size\n                can be specified as a percentage of the block size, or as an\n                absolute value.  The dictionary size must be less than or equal\n                to the block size and 8192 bytes or larger.  It must also be\n                storable in the xz header as either 2^n or as 2^n+2^(n+1).\n                Example dict-sizes are 75%, 50%, 37.5%, 25%, or 32K, 16K, 8K\n                etc.\n\nIf the compressor offers compression specific options then these\noptions are also displayed (.i.e. in the above XZ is shown with two\ncompression specific options).\n\n3.3 Changing global compression defaults used in mksquashfs\n-----------------------------------------------------------\n\nThere are a large number of options that can be used to control the \ncompression in mksquashfs.  By and large the defaults are the most\noptimum settings and should only be changed in exceptional circumstances!\n\nThe -noI, -noD and -noF options (also -noInodeCompression, -noDataCompression\nand -noFragmentCompression) can be used to force mksquashfs to not compress\ninodes/directories, data and fragments respectively.  Giving all options\ngenerates an uncompressed filesystem.\n\nThe -no-fragments tells mksquashfs to not generate fragment blocks, and rather\ngenerate a filesystem similar to a Squashfs 1.x filesystem.  It will of course\nstill be a Squashfs 3.1 filesystem but without fragments, and so it won't be\nmountable on a Squashfs 1.x system.\n\nThe -always-use-fragments option tells mksquashfs to always generate\nfragments for files irrespective of the file length.  By default only small\nfiles less than the block size are packed into fragment blocks.  The ends of\nfiles which do not fit fully into a block, are NOT by default packed into\nfragments.  To illustrate this, a 100K file has an initial 64K block and a 36K\nremainder.  This 36K remainder is not packed into a fragment by default.  This\nis because to do so leads to a 10 - 20% drop in sequential I/O performance, as a\ndisk head seek is needed to seek to the initial file data and another disk seek\nis need to seek to the fragment block.  Specify this option if you want file\nremainders to be packed into fragment blocks.  Doing so may increase the\ncompression obtained BUT at the expense of I/O speed.\n\nThe -no-duplicates option tells mksquashfs to not check the files being\nadded to the filesystem for duplicates.  This can result in quicker filesystem\ngeneration and appending although obviously compression will suffer badly if\nthere is a lot of duplicate files.\n\nThe -b option allows the block size to be selected, both \"K\" and \"M\" postfixes\nare supported, this can be either 4K, 8K, 16K, 32K, 64K, 128K, 256K, 512K or\n1M bytes.\n\n3.4 Specifying the UIDs/GIDs used in the filesystem\n---------------------------------------------------\n\nBy default files in the generated filesystem inherit the UID and GID ownership\nof the original file.  However,  mksquashfs provides a number of options which\ncan be used to override the ownership.\n\nThe options -all-root and -root-owned (both do exactly the same thing) force all\nfile uids/gids in the generated Squashfs filesystem to be root.  This allows\nroot owned filesystems to be built without root access on the host machine.\n\nThe \"-force-uid uid\"  option forces all files in the generated Squashfs\nfilesystem to be owned by the specified uid.  The uid can be specified either by\nname (i.e. \"root\") or by number.\n\nThe \"-force-gid gid\" option forces all files in the generated Squashfs\nfilesystem to be group owned by the specified gid.  The gid can be specified\neither by name (i.e. \"root\") or by number.\n\n3.5 Excluding files from the filesystem\n---------------------------------------\n\nThe -e and -ef options allow files/directories to be specified which are\nexcluded from the output filesystem.  The -e option takes the exclude\nfiles/directories from the command line, the -ef option takes the\nexlude files/directories from the specified exclude file, one file/directory\nper line.\n\nTwo styles of exclude file matching are supported: basic exclude matching, and\nextended wildcard matching.  Basic exclude matching is a legacy feature\nretained for backwards compatibility with earlier versions of Mksquashfs.\nExtended wildcard matching should be used in preference.\n\n3.5.1 Basic exclude matching\n\nEach exclude file is treated as an exact match of a file/directory in\nthe source directories.  If an exclude file/directory is absolute (i.e.\nprefixed with /, ../, or ./) the entry is treated as absolute, however, if an\nexclude file/directory is relative, it is treated as being relative to each of\nthe sources in turn, i.e.\n\n%mksquashfs /tmp/source1 source2  output_fs -e ex1 /tmp/source1/ex2 out/ex3\n\nWill generate exclude files /tmp/source1/ex2, /tmp/source1/ex1, source2/ex1,\n/tmp/source1/out/ex3 and source2/out/ex3.\n\n3.5.2 Extended exclude file handling\n\nExtended exclude file matching treats each exclude file as a wildcard or\nregex expression.  To enable wildcard matching specify the -wildcards\noption, and to enable regex matching specify the -regex option.  In most\ncases the -wildcards option should be used rather than -regex because wildcard\nmatching behaviour is significantly easier to understand!\n\nIn addition to wildcards/regex expressions, exclude files can be \"anchored\" or\n\"non-anchored\".  An anchored exclude is one which matches from the root of the\ndirectory and nowhere else, a non-anchored exclude matches anywhere.  For\nexample given the directory hierarchy \"a/b/c/a/b\", the anchored exclude\n\"a/b\" will match \"a/b\" at the root of the directory hierarchy, but\nit will not match the \"/a/b\" sub-directory within directory \"c\", whereas a\nnon-anchored exclude would.\n\nA couple of examples should make this clearer.\n \nAnchored excludes\n\n  1. mksquashfs example image.sqsh -wildcards -e 'test/*.gz'\n\n     Exclude all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. mksquashfs example image.sqsh -wildcards -e '*/[Tt]est/example*'\n\n     Exclude all files beginning with \"example\" inside directories called\n     \"Test\" or \"test\", that occur inside any top level directory.\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -wildcards -e 'test/!(*data*).gz'\n\n     Exclude all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\nNon-anchored excludes\n\n  By default excludes match from the top level directory, but it is\n  often useful to exclude a file matching anywhere in the source directories.\n  For this non-anchored excludes can be used, specified by pre-fixing the\n  exclude with \"...\".\n\n  Examples:\n\n  1. mksquashfs example image.sqsh -wildcards -e '... *.gz'\n\n     Exclude files matching \"*.gz\" anywhere in the source directories.\n     For example this will match \"example.gz\", \"test/example.gz\", and\n     \"test/test/example.gz\".\n\n  2. mksquashfs example image.sqsh -wildcards -e '... [Tt]est/*.gz'\n\n     Exclude files matching \"*.gz\" inside directories called \"Test\" or\n     \"test\" that occur anywhere in the source directories.\n\n  Again, using extended wildcards, negative matching is also possible.\n\n  3. mksquashfs example image.sqsh -wildcards -e '... !(*data*).gz'\n\n     Exclude all files matching \"*.gz\" anywhere in the source directories,\n     except those with \"data\" in the name.\n\n3.5.3 Exclude files summary\n\nThe -e and -ef exclude options are usefully used in archiving the entire\nfilesystem, where it is wished to avoid archiving /proc, and the filesystem\nbeing generated, i.e.\n\n%mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh\n\nMultiple -ef options can be specified on the command line, and the -ef\noption can be used in conjuction with the -e option.\n\n3.6 Appending to squashfs filesystems\n-------------------------------------\n\nRunning squashfs with the destination directory containing an existing\nfilesystem will add the source items to the existing filesystem.  By default,\nthe source items are added to the existing root directory.\n\nTo make this clear... An existing filesystem \"image\" contains root entries\n\"old1\", and \"old2\".  Source directory \"/home/phillip/test\" contains  \"file1\",\n\"file2\" and \"dir1\".\n\nexample 1:\n\n%mksquashfs /home/phillip/test image\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", \"file1\", \"file2\" and\n\"dir1\"\n\nexample 2:\n\n%mksquashfs /home/phillip/test image -keep-as-directory\n\nWill create a new \"image\" with root entries \"old1\", \"old2\", and \"test\".\nAs shown in the previous section, for single source directories\n'-keep-as-directory' adds the source directory rather than the\ncontents of the directory.\n\nexample 3:\n\n%mksquashfs /home/phillip/test image -keep-as-directory -root-becomes\noriginal-root\n\nWill create a new \"image\" with root entries \"original-root\", and \"test\".  The\n'-root-becomes' option specifies that the original root becomes a subdirectory\nin the new root, with the specified name.\n\nThe append option with file duplicate detection, means squashfs can be\nused as a simple versioning archiving filesystem. A squashfs filesystem can\nbe created with for example the linux-2.4.19 source.  Appending the linux-2.4.20\nsource will create a filesystem with the two source trees, but only the\nchanged files will take extra room, the unchanged files will be detected as\nduplicates.\n\n3.7 Appending recovery file feature\n-----------------------------------\n\nRecovery files are created when appending to existing Squashfs\nfilesystems.  This allows the original filesystem to be recovered\nif Mksquashfs aborts unexpectedly (i.e. power failure).\n\nThe recovery files are called squashfs_recovery_xxx_yyy, where\n\"xxx\" is the name of the filesystem being appended to, and \"yyy\" is a\nnumber to guarantee filename uniqueness (the PID of the parent Mksquashfs\nprocess).\n\nNormally if Mksquashfs exits correctly the recovery file is deleted to\navoid cluttering the filesystem.  If Mksquashfs aborts, the \"-recover\"\noption can be used to recover the filesystem, giving the previously\ncreated recovery file as a parameter, i.e.\n\nmksquashfs dummy image.sqsh -recover squashfs_recovery_image.sqsh_1234\n\nThe writing of the recovery file can be disabled by specifying the\n\"-no-recovery\" option.\n\n3.8 Pseudo file support\n-----------------------\n\nMksquashfs supports pseudo files, these allow fake files, directories, character\nand block devices to be specified and added to the Squashfs filesystem being\nbuilt, rather than requiring them to be present in the source directories.\nThis, for example, allows device nodes to be added to the filesystem without\nrequiring root access.\n\nMksquashfs 4.1 adds support for \"dynamic pseudo files\" and a modify operation.\nDynamic pseudo files allow files to be dynamically created when Mksquashfs\nis run, their contents being the result of running a command or piece of\nshell script.  The modifiy operation allows the mode/uid/gid of an existing\nfile in the source filesystem to be modified.\n\nTwo Mksquashfs options are supported, -p allows one pseudo file to be specified\non the command line, and -pf allows a pseudo file to be specified containing a\nlist of pseduo definitions, one per line.\n\nPseudo operations\n-----------------\n\n3.8.1. Creating a dynamic file\n--------------------------\n\nPseudo definition\n\nFilename f mode uid gid command\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nuid and gid can be either specified as a decimal number, or by name.\n\ncommand can be an executable or a piece of shell script, and it is executed\nby running \"/bin/sh -c command\".   The stdout becomes the contents of\n\"Filename\".\n\nExamples:\n\nRunning a basic command\n-----------------------\n\n/somedir/dmesg f 444 root root dmesg\n\ncreates a file \"/somedir/dmesg\" containing the output from dmesg.\n\nExecuting shell script\n----------------------\n\nRELEASE f 444 root root \\\n\t\tif [ ! -e /tmp/ver ]; then \\\n\t\t\techo 0 > /tmp/ver; \\\n\t\tfi; \\\n                ver=`cat /tmp/ver`; \\\n                ver=$((ver +1)); \\\n                echo $ver > /tmp/ver; \\\n                echo -n `cat /tmp/release`; \\\n                echo \"-dev #\"$ver `date` \"Build host\" `hostname`\n\nCreates a file RELEASE containing the release name, date, build host, and\nan incrementing version number.  The incrementing version is a side-effect\nof executing the shell script, and ensures every time Mksquashfs is run a\nnew version number is used without requiring any other shell scripting.\n\nThe above example also shows that commands can be split across multiple lines\nusing \"\\\".  Obviously as the script will be presented to the shell as a single\nline, a semicolon is need to separate individual shell commands within the\nshell script.\n\nReading from a device (or fifo/named socket)\n--------------------------------------------\n\ninput f 444 root root dd if=/dev/sda1 bs=1024 count=10\n\nCopies 10K from the device /dev/sda1 into the file input.  Ordinarily Mksquashfs\ngiven a device, fifo, or named socket will place that special file within the\nSquashfs filesystem, the above allows input from these special files to be\ncaptured and placed in the Squashfs filesystem.\n\n3.8.2. Creating a block or character device\n---------------------------------------\n\nPseudo definition\n\nFilename type mode uid gid major minor\n\nWhere type is either\n\tb - for block devices, and\n\tc - for character devices\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nuid and gid can be either specified as a decimal number, or by name.\n\nFor example:\n\n/dev/chr_dev c 666 root root 100 1\n/dev/blk_dev b 666 0 0 200 200\n\ncreates a character device \"/dev/chr_dev\" with major:minor 100:1 and\na block device \"/dev/blk_dev\" with major:minor 200:200, both with root\nuid/gid and a mode of rw-rw-rw.\n\n3.8.3. Creating a directory\n-----------------------\n\nPseudo definition\n\nFilename d mode uid gid\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nuid and gid can be either specified as a decimal number, or by name.\n\nFor example:\n\n/pseudo_dir d 666 root root\n\ncreates a directory \"/pseudo_dir\" with root uid/gid and mode of rw-rw-rw.\n\n4.8.4. Modifying attributes of an existing file\n-------------------------------------------\n\nPseudo definition\n\nFilename m mode uid gid\n\nmode is the octal mode specifier, similar to that expected by chmod.\n\nuid and gid can be either specified as a decimal number, or by name.\n\nFor example:\n\ndmesg m 666 root root\n\nChanges the attributes of the file \"dmesg\" in the filesystem to have\nroot uid/gid and a mode of rw-rw-rw, overriding the attributes obtained\nfrom the source filesystem.\n\n3.9 Miscellaneous options\n-------------------------\n\nThe -info option displays the files/directories as they are compressed and\nadded to the filesystem.  The original uncompressed size of each file\nis printed, along with DUPLICATE if the file is a duplicate of a\nfile in the filesystem.\n\nThe -nopad option informs mksquashfs to not pad the filesystem to a 4K multiple.\nThis is performed by default to enable the output filesystem file to be mounted\nby loopback, which requires files to be a 4K multiple.  If the filesystem is\nbeing written to a block device, or is to be stored in a bootimage, the extra\npad bytes are not needed.\n\n4. UNSQUASHFS\n-------------\n\nUnsquashfs allows you to decompress and extract a Squashfs filesystem without\nmounting it.  It can extract the entire filesystem, or a specific\nfile or directory.\n\nThe Unsquashfs usage info is:\n\nSYNTAX: unsquashfs [options] filesystem [directories or files to extract]\n\t-v[ersion]\t\tprint version, licence and copyright information\n\t-d[est] <pathname>\tunsquash to <pathname>, default \"squashfs-root\"\n\t-n[o-progress]\t\tdon't display the progress bar\n\t-no[-xattrs]\t\tdon't extract xattrs in file system\n\t-x[attrs]\t\textract xattrs in file system (default)\n\t-p[rocessors] <number>\tuse <number> processors.  By default will use\n\t\t\t\tnumber of processors available\n\t-i[nfo]\t\t\tprint files as they are unsquashed\n\t-li[nfo]\t\tprint files as they are unsquashed with file\n\t\t\t\tattributes (like ls -l output)\n\t-l[s]\t\t\tlist filesystem, but don't unsquash\n\t-ll[s]\t\t\tlist filesystem with file attributes (like\n\t\t\t\tls -l output), but don't unsquash\n\t-f[orce]\t\tif file already exists then overwrite\n\t-s[tat]\t\t\tdisplay filesystem superblock information\n\t-e[f] <extract file>\tlist of directories or files to extract.\n\t\t\t\tOne per line\n\t-da[ta-queue] <size>\tSet data queue to <size> Mbytes.  Default 256\n\t\t\t\tMbytes\n\t-fr[ag-queue] <size>\tSet fagment queue to <size> Mbytes.  Default 256\n\t\t\t\t Mbytes\n\t-r[egex]\t\ttreat extract names as POSIX regular expressions\n\t\t\t\trather than use the default shell wildcard\n\t\t\t\texpansion (globbing)\n\nDecompressors available:\n\tgzip\n\tlzma\n\txz\t\n\n\nTo extract a subset of the filesystem, the filenames or directory\ntrees that are to be extracted can be specified on the command line.  The\nfiles/directories should be specified using the full path to the\nfiles/directories as they appear within the Squashfs filesystem.  The\nfiles/directories will also be extracted to those positions within the specified\ndestination directory.\n\nThe extract files can also be given in a file using the \"-e[f]\" option.\n\nSimilarly to Mksquashfs, wildcard matching is performed on the extract\nfiles.  Wildcard matching is enabled by default.\n\nExamples:\n\n  1. unsquashfs image.sqsh 'test/*.gz'\n\n     Extract all files matching \"*.gz\" in the top level directory \"test\".\n\n  2. unsquashfs image.sqsh '[Tt]est/example*'\n\n     Extract all files beginning with \"example\" inside top level directories\n     called \"Test\" or \"test\".\n\n  Using extended wildcards, negative matching is also possible.\n\n  3. unsquashfs image.sqsh 'test/!(*data*).gz'\n\n     Extract all files matching \"*.gz\" in top level directory \"test\",\n     except those with \"data\" in the name.\n\n\n4.1 Unsquashfs options\n----------------------\n\nThe \"-ls\" option can be used to list the contents of a filesystem without\ndecompressing the filesystem data itself.  The \"-lls\" option is similar\nbut it also displays file attributes (ls -l style output).\n\nThe \"-info\" option forces Unsquashfs to print each file as it is decompressed.\nThe -\"linfo\" is similar but it also displays file attributes.\n\nThe \"-dest\" option specifies the directory that is used to decompress\nthe filesystem data.  If this option is not given then the filesystem is\ndecompressed to the directory \"squashfs-root\" in the current working directory.\n\nThe \"-force\" option forces Unsquashfs to output to the destination\ndirectory even if files or directories already exist.  This allows you\nto update an existing directory tree, or to Unsquashfs to a partially\nfilled directory.  Without the \"-force\" option, Unsquashfs will\nrefuse to overwrite any existing files, or to create any directories if they\nalready exist.  This is done to protect data in case of mistakes, and\nso the \"-force\" option should be used with caution.\n\nThe \"-stat\" option displays filesystem superblock information.  This is\nuseful to discover the filesystem version, byte ordering, whether it has a NFS\nexport table, and what options were used to compress the filesystem, etc.\n\nUnsquashfs can decompress all Squashfs filesystem versions, 1.x, 2.x and 3.x\nfilesystems.\n\n5. FILESYSTEM LAYOUT\n--------------------\n\nA squashfs filesystem consists of a maximum of nine parts, packed together on a\nbyte alignment:\n\n\t ---------------\n\t|  superblock \t|\n\t|---------------|\n\t|  compression  |\n\t|    options    |\n\t|---------------|\n\t|  datablocks   |\n\t|  & fragments  |\n\t|---------------|\n\t|  inode table\t|\n\t|---------------|\n\t|   directory\t|\n\t|     table     |\n\t|---------------|\n\t|   fragment\t|\n\t|    table      |\n\t|---------------|\n\t|    export     |\n\t|    table      |\n\t|---------------|\n\t|    uid/gid\t|\n\t|  lookup table\t|\n\t|---------------|\n\t|     xattr     |\n\t|     table\t|\n\t ---------------\n\nCompressed data blocks are written to the filesystem as files are read from\nthe source directory, and checked for duplicates.  Once all file data has been\nwritten the completed inode, directory, fragment, export and uid/gid lookup\ntables are written.\n\n5.1 Compression options\n-----------------------\n\nCompressors can optionally support compression specific options (e.g.\ndictionary size).  If non-default compression options have been used, then\nthese are stored here.\n\n5.2 Inodes\n----------\n\nMetadata (inodes and directories) are compressed in 8Kbyte blocks.  Each\ncompressed block is prefixed by a two byte length, the top bit is set if the\nblock is uncompressed.  A block will be uncompressed if the -noI option is set,\nor if the compressed block was larger than the uncompressed block.\n\nInodes are packed into the metadata blocks, and are not aligned to block\nboundaries, therefore inodes overlap compressed blocks.  Inodes are identified\nby a 48-bit number which encodes the location of the compressed metadata block\ncontaining the inode, and the byte offset into that block where the inode is\nplaced (<block, offset>).\n\nTo maximise compression there are different inodes for each file type\n(regular file, directory, device, etc.), the inode contents and length\nvarying with the type.\n\nTo further maximise compression, two types of regular file inode and\ndirectory inode are defined: inodes optimised for frequently occurring\nregular files and directories, and extended types where extra\ninformation has to be stored.\n\n5.3 Directories\n---------------\n\nLike inodes, directories are packed into compressed metadata blocks, stored\nin a directory table.  Directories are accessed using the start address of\nthe metablock containing the directory and the offset into the\ndecompressed block (<block, offset>).\n\nDirectories are organised in a slightly complex way, and are not simply\na list of file names.  The organisation takes advantage of the\nfact that (in most cases) the inodes of the files will be in the same\ncompressed metadata block, and therefore, can share the start block.\nDirectories are therefore organised in a two level list, a directory\nheader containing the shared start block value, and a sequence of directory\nentries, each of which share the shared start block.  A new directory header\nis written once/if the inode start block changes.  The directory\nheader/directory entry list is repeated as many times as necessary.\n\nDirectories are sorted, and can contain a directory index to speed up\nfile lookup.  Directory indexes store one entry per metablock, each entry\nstoring the index/filename mapping to the first directory header\nin each metadata block.  Directories are sorted in alphabetical order,\nand at lookup the index is scanned linearly looking for the first filename\nalphabetically larger than the filename being looked up.  At this point the\nlocation of the metadata block the filename is in has been found.\nThe general idea of the index is ensure only one metadata block needs to be\ndecompressed to do a lookup irrespective of the length of the directory.\nThis scheme has the advantage that it doesn't require extra memory overhead\nand doesn't require much extra storage on disk.\n\n5.4 File data\n-------------\n\nRegular files consist of a sequence of contiguous compressed blocks, and/or a\ncompressed fragment block (tail-end packed block).   The compressed size\nof each datablock is stored in a block list contained within the\nfile inode.\n\nTo speed up access to datablocks when reading 'large' files (256 Mbytes or\nlarger), the code implements an index cache that caches the mapping from\nblock index to datablock location on disk.\n\nThe index cache allows Squashfs to handle large files (up to 1.75 TiB) while\nretaining a simple and space-efficient block list on disk.  The cache\nis split into slots, caching up to eight 224 GiB files (128 KiB blocks).\nLarger files use multiple slots, with 1.75 TiB files using all 8 slots.\nThe index cache is designed to be memory efficient, and by default uses\n16 KiB.\n\n5.5 Fragment lookup table\n-------------------------\n\nRegular files can contain a fragment index which is mapped to a fragment\nlocation on disk and compressed size using a fragment lookup table.  This\nfragment lookup table is itself stored compressed into metadata blocks.\nA second index table is used to locate these.  This second index table for\nspeed of access (and because it is small) is read at mount time and cached\nin memory.\n\n5.6 Uid/gid lookup table\n------------------------\n\nFor space efficiency regular files store uid and gid indexes, which are\nconverted to 32-bit uids/gids using an id look up table.  This table is\nstored compressed into metadata blocks.  A second index table is used to\nlocate these.  This second index table for speed of access (and because it\nis small) is read at mount time and cached in memory.\n\n5.7 Export table\n----------------\n\nTo enable Squashfs filesystems to be exportable (via NFS etc.) filesystems\ncan optionally (disabled with the -no-exports Mksquashfs option) contain\nan inode number to inode disk location lookup table.  This is required to\nenable Squashfs to map inode numbers passed in filehandles to the inode\nlocation on disk, which is necessary when the export code reinstantiates\nexpired/flushed inodes.\n\nThis table is stored compressed into metadata blocks.  A second index table is\nused to locate these.  This second index table for speed of access (and because\nit is small) is read at mount time and cached in memory.\n\n5.8 Xattr table\n---------------\n\nThe xattr table contains extended attributes for each inode.  The xattrs\nfor each inode are stored in a list, each list entry containing a type,\nname and value field.  The type field encodes the xattr prefix\n(\"user.\", \"trusted.\" etc) and it also encodes how the name/value fields\nshould be interpreted.  Currently the type indicates whether the value\nis stored inline (in which case the value field contains the xattr value),\nor if it is stored out of line (in which case the value field stores a\nreference to where the actual value is stored).  This allows large values\nto be stored out of line improving scanning and lookup performance and it\nalso allows values to be de-duplicated, the value being stored once, and\nall other occurences holding an out of line reference to that value.\n\nThe xattr lists are packed into compressed 8K metadata blocks.\nTo reduce overhead in inodes, rather than storing the on-disk\nlocation of the xattr list inside each inode, a 32-bit xattr id\nis stored.  This xattr id is mapped into the location of the xattr\nlist using a second xattr id lookup table.\n\n6. AUTHOR INFO\n--------------\n\nSquashfs was written by Phillip Lougher, email phillip@lougher.demon.co.uk,\nin Chepstow, Wales, UK.   If you like the program, or have any problems,\nthen please email me, as it's nice to get feedback!\n"
  },
  {
    "path": "src/others/squashfs-4.2/README-4.2",
    "content": "\tSQUASHFS 4.2 - A squashed read-only filesystem for Linux\n\n\tCopyright 2002-2011 Phillip Lougher <phillip@lougher.demon.co.uk>\n\n\tReleased under the GPL licence (version 2 or later).\n\nWelcome to Squashfs 4.2.  This is a tools only release, support for Squashfs\nfilesystems is in mainline (2.6.29 and later).\n\nNew features in Squashfs-tools 4.2\n----------------------------------\n\n  1. Support for XZ compression\n  2. Support for compressor specific options\n\nCompatiblity\n------------\n\nMksquashfs 4.2 generates 4.0 filesystems.  These filesystems are fully\ncompatible/interchangable with filesystems generated by Mksquashfs 4.0 and are\nmountable on 2.6.29 and later kernels.\n\nXZ compression\n--------------\n\nSquashfs now supports XZ compression.  \n\nXZ support is in 2.6.38 and newer kernels.\n\nNew Mksquashfs options\n----------------------\n\n-X<compressor-option>\n\n  Compression algorithms can now support compression specific options.  These\noptions are prefixed by -X, and are passed to the compressor for handling.\n\n  The compression specific options supported by each compressor can be\nfound by typing mksquashfs without any arguments.  They are displayed at the\nend of the help message, e.g. \n\nCompressors available and compressor specific options:\n\tgzip (no options) (default)\n\tlzo (no options)\n\txz\n\t  -Xbcj filter1,filter2,...,filterN\n\t\tCompress using filter1,filter2,...,filterN in turn\n\t\t(in addition to no filter), and choose the best compression.\n\t\tAvailable filters: x86, arm, armthumb, powerpc, sparc, ia64\n\t  -Xdict-size <dict-size>\n\t\tUse <dict-size> as the XZ dictionary size.  The dictionary size\n\t\tcan be specified as a percentage of the block size, or as an\n\t\tabsolute value.  The dictionary size must be less than or equal\n\t\tto the block size and 8192 bytes or larger.  It must also be\n\t\tstorable in the xz header as either 2^n or as 2^n+2^(n+1).\n\t\tExample dict-sizes are 75%, 50%, 37.5%, 25%, or 32K, 16K, 8K\n\t\tetc.\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/.built",
    "content": ""
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/.built_check",
    "content": ""
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/.configured",
    "content": ""
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/.prepared1a23cc84ca172080ca2c2f332cb31052",
    "content": ""
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/.prepared1a23cc84ca172080ca2c2f332cb31052_check",
    "content": ""
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/7zC.txt",
    "content": "7z ANSI-C Decoder 4.62\n----------------------\n\n7z ANSI-C provides 7z/LZMA decoding.\n7z ANSI-C version is simplified version ported from C++ code.\n\nLZMA is default and general compression method of 7z format\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \ncompression ratio and very fast decompression.\n\n\nLICENSE\n-------\n\n7z ANSI-C Decoder is part of the LZMA SDK.\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\n\nFiles\n---------------------\n\n7zDecode.*   - Low level 7z decoding\n7zExtract.*  - High level 7z decoding\n7zHeader.*   - .7z format constants\n7zIn.*       - .7z archive opening\n7zItem.*     - .7z structures\n7zMain.c     - Test application\n\n\nHow To Use\n----------\n\nYou must download 7-Zip program from www.7-zip.org.\n\nYou can create .7z archive with 7z.exe or 7za.exe:\n\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255\n\nIf you have big number of files in archive, and you need fast extracting, \nyou can use partly-solid archives:\n  \n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\n\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \n512KB for extracting one file from such archive.\n\n\nLimitations of current version of 7z ANSI-C Decoder\n---------------------------------------------------\n\n - It reads only \"FileName\", \"Size\", \"LastWriteTime\" and \"CRC\" information for each file in archive.\n - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\n \nThese limitations will be fixed in future versions.\n\n\nUsing 7z ANSI-C Decoder Test application:\n-----------------------------------------\n\nUsage: 7zDec <command> <archive_name>\n\n<Command>:\n  e: Extract files from archive\n  l: List contents of archive\n  t: Test integrity of archive\n\nExample: \n\n  7zDec l archive.7z\n\nlists contents of archive.7z\n\n  7zDec e archive.7z\n\nextracts files from archive.7z to current folder.\n\n\nHow to use .7z Decoder\n----------------------\n\nMemory allocation\n~~~~~~~~~~~~~~~~~\n\n7z Decoder uses two memory pools:\n1) Temporary pool\n2) Main pool\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\n\n\nSteps for using 7z decoder\n--------------------------\n\nUse code at 7zMain.c as example.\n\n1) Declare variables:\n  inStream                 /* implements ILookInStream interface */\n  CSzArEx db;              /* 7z archive database structure */\n  ISzAlloc allocImp;       /* memory functions for main pool */\n  ISzAlloc allocTempImp;   /* memory functions for temporary pool */\n\n2) call CrcGenerateTable(); function to initialize CRC structures.\n\n3) call SzArEx_Init(&db); function to initialize db structures.\n\n4) call SzArEx_Open(&db, inStream, &allocMain, &allocTemp) to open archive\n\nThis function opens archive \"inStream\" and reads headers to \"db\".\nAll items in \"db\" will be allocated with \"allocMain\" functions.\nSzArEx_Open function allocates and frees temporary structures by \"allocTemp\" functions.\n\n5) List items or Extract items\n\n  Listing code:\n  ~~~~~~~~~~~~~\n    {\n      UInt32 i;\n      for (i = 0; i < db.db.NumFiles; i++)\n      {\n        CFileItem *f = db.db.Files + i;\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\n      }\n    }\n\n  Extracting code:\n  ~~~~~~~~~~~~~~~~\n\n  SZ_RESULT SzAr_Extract(\n    CArchiveDatabaseEx *db,\n    ILookInStream *inStream, \n    UInt32 fileIndex,         /* index of file */\n    UInt32 *blockIndex,       /* index of solid block */\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\n    size_t *outBufferSize,    /* buffer size for output buffer */\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\n    ISzAlloc *allocMain,\n    ISzAlloc *allocTemp);\n\n  If you need to decompress more than one file, you can send these values from previous call:\n    blockIndex, \n    outBuffer, \n    outBufferSize,\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \n  it will increase decompression speed.\n\n  After decompressing you must free \"outBuffer\":\n  allocImp.Free(outBuffer);\n\n6) call SzArEx_Free(&db, allocImp.Free) to free allocated items in \"db\".\n\n\n\n\nMemory requirements for .7z decoding \n------------------------------------\n\nMemory usage for Archive opening:\n  - Temporary pool:\n     - Memory for uncompressed .7z headers\n     - some other temporary blocks\n  - Main pool:\n     - Memory for database: \n       Estimated size of one file structures in solid archive:\n         - Size (4 or 8 Bytes)\n         - CRC32 (4 bytes)\n         - LastWriteTime (8 bytes)\n         - Some file information (4 bytes)\n         - File Name (variable length) + pointer + allocation structures\n\nMemory usage for archive Decompressing:\n  - Temporary pool:\n     - Memory for LZMA decompressing structures\n  - Main pool:\n     - Memory for decompressed solid block\n     - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these \n       temprorary buffers can be about 15% of solid block size. \n  \n\n7z Decoder doesn't allocate memory for compressed blocks. \nInstead of this, you must allocate buffer with desired \nsize before calling 7z Decoder. Use 7zMain.c as example.\n\n\nDefines\n-------\n\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\n\n\n---\n\nhttp://www.7-zip.org\nhttp://www.7-zip.org/sdk.html\nhttp://www.7-zip.org/support.html\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\n-----------------------------------\n\nThis file contains description of 7z archive format. \n7z archive can contain files compressed with any method.\nSee \"Methods.txt\" for description for defined compressing methods.\n\n\nFormat structure Overview\n-------------------------\n\nSome fields can be optional.\n\nArchive structure\n~~~~~~~~~~~~~~~~~  \nSignatureHeader\n[PackedStreams]\n[PackedStreamsForHeaders]\n[\n  Header \n  or \n  {\n    Packed Header\n    HeaderInfo\n  }\n]\n\n\n\nHeader structure\n~~~~~~~~~~~~~~~~  \n{\n  ArchiveProperties\n  AdditionalStreams\n  {\n    PackInfo\n    {\n      PackPos\n      NumPackStreams\n      Sizes[NumPackStreams]\n      CRCs[NumPackStreams]\n    }\n    CodersInfo\n    {\n      NumFolders\n      Folders[NumFolders]\n      {\n        NumCoders\n        CodersInfo[NumCoders]\n        {\n          ID\n          NumInStreams;\n          NumOutStreams;\n          PropertiesSize\n          Properties[PropertiesSize]\n        }\n        NumBindPairs\n        BindPairsInfo[NumBindPairs]\n        {\n          InIndex;\n          OutIndex;\n        }\n        PackedIndices\n      }\n      UnPackSize[Folders][Folders.NumOutstreams]\n      CRCs[NumFolders]\n    }\n    SubStreamsInfo\n    {\n      NumUnPackStreamsInFolders[NumFolders];\n      UnPackSizes[]\n      CRCs[]\n    }\n  }\n  MainStreamsInfo\n  {\n    (Same as in AdditionalStreams)\n  }\n  FilesInfo\n  {\n    NumFiles\n    Properties[]\n    {\n      ID\n      Size\n      Data\n    }\n  }\n}\n\nHeaderInfo structure\n~~~~~~~~~~~~~~~~~~~~\n{\n  (Same as in AdditionalStreams)\n}\n\n\n\nNotes about Notation and encoding\n---------------------------------\n\n7z uses little endian encoding.\n\n7z archive format has optional headers that are marked as\n[]\nHeader\n[]\n\nREAL_UINT64 means real UINT64.\n\nUINT64 means real UINT64 encoded with the following scheme:\n\n  Size of encoding sequence depends from first byte:\n  First_Byte  Extra_Bytes        Value\n  (binary)   \n  0xxxxxxx               : ( xxxxxxx           )\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\n  ...\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\n  11111110    BYTE y[7]  :                         y\n  11111111    BYTE y[8]  :                         y\n\n\n\nProperty IDs\n------------\n\n0x00 = kEnd,\n\n0x01 = kHeader,\n\n0x02 = kArchiveProperties,\n    \n0x03 = kAdditionalStreamsInfo,\n0x04 = kMainStreamsInfo,\n0x05 = kFilesInfo,\n    \n0x06 = kPackInfo,\n0x07 = kUnPackInfo,\n0x08 = kSubStreamsInfo,\n\n0x09 = kSize,\n0x0A = kCRC,\n\n0x0B = kFolder,\n\n0x0C = kCodersUnPackSize,\n0x0D = kNumUnPackStream,\n\n0x0E = kEmptyStream,\n0x0F = kEmptyFile,\n0x10 = kAnti,\n\n0x11 = kName,\n0x12 = kCreationTime,\n0x13 = kLastAccessTime,\n0x14 = kLastWriteTime,\n0x15 = kWinAttributes,\n0x16 = kComment,\n\n0x17 = kEncodedHeader,\n\n\n7z format headers\n-----------------\n\nSignatureHeader\n~~~~~~~~~~~~~~~\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\n\n  ArchiveVersion\n  {\n    BYTE Major;   // now = 0\n    BYTE Minor;   // now = 2\n  };\n\n  UINT32 StartHeaderCRC;\n\n  StartHeader\n  {\n    REAL_UINT64 NextHeaderOffset\n    REAL_UINT64 NextHeaderSize\n    UINT32 NextHeaderCRC\n  }\n\n\n...........................\n\n\nArchiveProperties\n~~~~~~~~~~~~~~~~~\nBYTE NID::kArchiveProperties (0x02)\nfor (;;)\n{\n  BYTE PropertyType;\n  if (aType == 0)\n    break;\n  UINT64 PropertySize;\n  BYTE PropertyData[PropertySize];\n}\n\n\nDigests (NumStreams)\n~~~~~~~~~~~~~~~~~~~~~\n  BYTE AllAreDefined\n  if (AllAreDefined == 0)\n  {\n    for(NumStreams)\n      BIT Defined\n  }\n  UINT32 CRCs[NumDefined]\n\n\nPackInfo\n~~~~~~~~~~~~\n  BYTE NID::kPackInfo  (0x06)\n  UINT64 PackPos\n  UINT64 NumPackStreams\n\n  []\n  BYTE NID::kSize    (0x09)\n  UINT64 PackSizes[NumPackStreams]\n  []\n\n  []\n  BYTE NID::kCRC      (0x0A)\n  PackStreamDigests[NumPackStreams]\n  []\n\n  BYTE NID::kEnd\n\n\nFolder\n~~~~~~\n  UINT64 NumCoders;\n  for (NumCoders)\n  {\n    BYTE \n    {\n      0:3 DecompressionMethod.IDSize\n      4:\n        0 - IsSimple\n        1 - Is not simple\n      5:\n        0 - No Attributes\n        1 - There Are Attributes\n      7:\n        0 - Last Method in Alternative_Method_List\n        1 - There are more alternative methods\n    } \n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\n    if (!IsSimple)\n    {\n      UINT64 NumInStreams;\n      UINT64 NumOutStreams;\n    }\n    if (DecompressionMethod[0] != 0)\n    {\n      UINT64 PropertiesSize\n      BYTE Properties[PropertiesSize]\n    }\n  }\n    \n  NumBindPairs = NumOutStreamsTotal - 1;\n\n  for (NumBindPairs)\n  {\n    UINT64 InIndex;\n    UINT64 OutIndex;\n  }\n\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\n  if (NumPackedStreams > 1)\n    for(NumPackedStreams)\n    {\n      UINT64 Index;\n    };\n\n\n\n\nCoders Info\n~~~~~~~~~~~\n\n  BYTE NID::kUnPackInfo  (0x07)\n\n\n  BYTE NID::kFolder  (0x0B)\n  UINT64 NumFolders\n  BYTE External\n  switch(External)\n  {\n    case 0:\n      Folders[NumFolders]\n    case 1:\n      UINT64 DataStreamIndex\n  }\n\n\n  BYTE ID::kCodersUnPackSize  (0x0C)\n  for(Folders)\n    for(Folder.NumOutStreams)\n     UINT64 UnPackSize;\n\n\n  []\n  BYTE NID::kCRC   (0x0A)\n  UnPackDigests[NumFolders]\n  []\n\n  \n\n  BYTE NID::kEnd\n\n\n\nSubStreams Info\n~~~~~~~~~~~~~~\n  BYTE NID::kSubStreamsInfo; (0x08)\n\n  []\n  BYTE NID::kNumUnPackStream; (0x0D)\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\n  []\n\n\n  []\n  BYTE NID::kSize  (0x09)\n  UINT64 UnPackSizes[]\n  []\n\n\n  []\n  BYTE NID::kCRC  (0x0A)\n  Digests[Number of streams with unknown CRC]\n  []\n\n  \n  BYTE NID::kEnd\n\n\nStreams Info\n~~~~~~~~~~~~\n\n  []\n  PackInfo\n  []\n\n\n  []\n  CodersInfo\n  []\n\n\n  []\n  SubStreamsInfo\n  []\n\n  BYTE NID::kEnd\n\n\nFilesInfo\n~~~~~~~~~\n  BYTE NID::kFilesInfo;  (0x05)\n  UINT64 NumFiles\n\n  for (;;)\n  {\n    BYTE PropertyType;\n    if (aType == 0)\n      break;\n\n    UINT64 Size;\n\n    switch(PropertyType)\n    {\n      kEmptyStream:   (0x0E)\n        for(NumFiles)\n          BIT IsEmptyStream\n\n      kEmptyFile:     (0x0F)\n        for(EmptyStreams)\n          BIT IsEmptyFile\n\n      kAnti:          (0x10)\n        for(EmptyStreams)\n          BIT IsAntiFile\n      \n      case kCreationTime:   (0x12)\n      case kLastAccessTime: (0x13)\n      case kLastWriteTime:  (0x14)\n        BYTE AllAreDefined\n        if (AllAreDefined == 0)\n        {\n          for(NumFiles)\n            BIT TimeDefined\n        }\n        BYTE External;\n        if(External != 0)\n          UINT64 DataIndex\n        []\n        for(Definded Items)\n          UINT32 Time\n        []\n      \n      kNames:     (0x11)\n        BYTE External;\n        if(External != 0)\n          UINT64 DataIndex\n        []\n        for(Files)\n        {\n          wchar_t Names[NameSize];\n          wchar_t 0;\n        }\n        []\n\n      kAttributes:  (0x15)\n        BYTE AllAreDefined\n        if (AllAreDefined == 0)\n        {\n          for(NumFiles)\n            BIT AttributesAreDefined\n        }\n        BYTE External;\n        if(External != 0)\n          UINT64 DataIndex\n        []\n        for(Definded Attributes)\n          UINT32 Attributes\n        []\n    }\n  }\n\n\nHeader\n~~~~~~\n  BYTE NID::kHeader (0x01)\n\n  []\n  ArchiveProperties\n  []\n\n  []\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\n  StreamsInfo\n  []\n\n  []\n  BYTE NID::kMainStreamsInfo;    (0x04)\n  StreamsInfo\n  []\n\n  []\n  FilesInfo\n  []\n\n  BYTE NID::kEnd\n\n\nHeaderInfo\n~~~~~~~~~~\n  []\n  BYTE NID::kEncodedHeader; (0x17)\n  StreamsInfo for Encoded Header\n  []\n\n\n---\nEnd of document\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/7zBuf.c",
    "content": "/* 7zBuf.c -- Byte Buffer\n2008-03-28\nIgor Pavlov\nPublic domain */\n\n#include \"7zBuf.h\"\n\nvoid Buf_Init(CBuf *p)\n{\n  p->data = 0;\n  p->size = 0;\n}\n\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)\n{\n  p->size = 0;\n  if (size == 0)\n  {\n    p->data = 0;\n    return 1;\n  }\n  p->data = (Byte *)alloc->Alloc(alloc, size);\n  if (p->data != 0)\n  {\n    p->size = size;\n    return 1;\n  }\n  return 0;\n}\n\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc)\n{\n  alloc->Free(alloc, p->data);\n  p->data = 0;\n  p->size = 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/7zBuf.h",
    "content": "/* 7zBuf.h -- Byte Buffer\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_BUF_H\n#define __7Z_BUF_H\n\n#include \"Types.h\"\n\ntypedef struct\n{\n  Byte *data;\n  size_t size;\n} CBuf;\n\nvoid Buf_Init(CBuf *p);\nint Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);\nvoid Buf_Free(CBuf *p, ISzAlloc *alloc);\n\ntypedef struct\n{\n  Byte *data;\n  size_t size;\n  size_t pos;\n} CDynBuf;\n\nvoid DynBuf_Construct(CDynBuf *p);\nvoid DynBuf_SeekToBeg(CDynBuf *p);\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/7zBuf2.c",
    "content": "/* 7zBuf2.c -- Byte Buffer\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include <string.h>\n#include \"7zBuf.h\"\n\nvoid DynBuf_Construct(CDynBuf *p)\n{\n  p->data = 0;\n  p->size = 0;\n  p->pos = 0;\n}\n\nvoid DynBuf_SeekToBeg(CDynBuf *p)\n{\n  p->pos = 0;\n}\n\nint DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)\n{\n  if (size > p->size - p->pos)\n  {\n    size_t newSize = p->pos + size;\n    Byte *data;\n    newSize += newSize / 4;\n    data = (Byte *)alloc->Alloc(alloc, newSize);\n    if (data == 0)\n      return 0;\n    p->size = newSize;\n    memcpy(data, p->data, p->pos);\n    alloc->Free(alloc, p->data);\n    p->data = data;\n  }\n  memcpy(p->data + p->pos, buf, size);\n  p->pos += size;\n  return 1;\n}\n\nvoid DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)\n{\n  alloc->Free(alloc, p->data);\n  p->data = 0;\n  p->size = 0;\n  p->pos = 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/7zCrc.c",
    "content": "/* 7zCrc.c -- CRC32 calculation\n2008-08-05\nIgor Pavlov\nPublic domain */\n\n#include \"7zCrc.h\"\n\n#define kCrcPoly 0xEDB88320\nUInt32 g_CrcTable[256];\n\nvoid MY_FAST_CALL CrcGenerateTable(void)\n{\n  UInt32 i;\n  for (i = 0; i < 256; i++)\n  {\n    UInt32 r = i;\n    int j;\n    for (j = 0; j < 8; j++)\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\n    g_CrcTable[i] = r;\n  }\n}\n\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)\n{\n  const Byte *p = (const Byte *)data;\n  for (; size > 0 ; size--, p++)\n    v = CRC_UPDATE_BYTE(v, *p);\n  return v;\n}\n\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)\n{\n  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/7zCrc.h",
    "content": "/* 7zCrc.h -- CRC32 calculation\n2008-03-13\nIgor Pavlov\nPublic domain */\n\n#ifndef __7Z_CRC_H\n#define __7Z_CRC_H\n\n#include <stddef.h>\n\n#include \"Types.h\"\n\nextern UInt32 g_CrcTable[];\n\nvoid MY_FAST_CALL CrcGenerateTable(void);\n\n#define CRC_INIT_VAL 0xFFFFFFFF\n#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)\n#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))\n\nUInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);\nUInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/7zFile.c",
    "content": "/* 7zFile.c -- File IO\n2008-11-22 : Igor Pavlov : Public domain */\n\n#include \"7zFile.h\"\n\n#ifndef USE_WINDOWS_FILE\n\n#include <errno.h>\n\n#endif\n\n#ifdef USE_WINDOWS_FILE\n\n/*\n   ReadFile and WriteFile functions in Windows have BUG:\n   If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\n   from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\n   (Insufficient system resources exist to complete the requested service).\n   Probably in some version of Windows there are problems with other sizes:\n   for 32 MB (maybe also for 16 MB).\n   And message can be \"Network connection was lost\"\n*/\n\n#define kChunkSizeMax (1 << 22)\n\n#endif\n\nvoid File_Construct(CSzFile *p)\n{\n  #ifdef USE_WINDOWS_FILE\n  p->handle = INVALID_HANDLE_VALUE;\n  #else\n  p->file = NULL;\n  #endif\n}\n\nstatic WRes File_Open(CSzFile *p, const char *name, int writeMode)\n{\n  #ifdef USE_WINDOWS_FILE\n  p->handle = CreateFileA(name,\n      writeMode ? GENERIC_WRITE : GENERIC_READ,\n      FILE_SHARE_READ, NULL,\n      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\n      FILE_ATTRIBUTE_NORMAL, NULL);\n  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\n  #else\n  p->file = fopen(name, writeMode ? \"wb+\" : \"rb\");\n  return (p->file != 0) ? 0 : errno;\n  #endif\n}\n\nWRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }\nWRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }\n\nWRes File_Close(CSzFile *p)\n{\n  #ifdef USE_WINDOWS_FILE\n  if (p->handle != INVALID_HANDLE_VALUE)\n  {\n    if (!CloseHandle(p->handle))\n      return GetLastError();\n    p->handle = INVALID_HANDLE_VALUE;\n  }\n  #else\n  if (p->file != NULL)\n  {\n    int res = fclose(p->file);\n    if (res != 0)\n      return res;\n    p->file = NULL;\n  }\n  #endif\n  return 0;\n}\n\nWRes File_Read(CSzFile *p, void *data, size_t *size)\n{\n  size_t originalSize = *size;\n  if (originalSize == 0)\n    return 0;\n\n  #ifdef USE_WINDOWS_FILE\n\n  *size = 0;\n  do\n  {\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\n    DWORD processed = 0;\n    BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);\n    data = (void *)((Byte *)data + processed);\n    originalSize -= processed;\n    *size += processed;\n    if (!res)\n      return GetLastError();\n    if (processed == 0)\n      break;\n  }\n  while (originalSize > 0);\n  return 0;\n\n  #else\n  \n  *size = fread(data, 1, originalSize, p->file);\n  if (*size == originalSize)\n    return 0;\n  return ferror(p->file);\n  \n  #endif\n}\n\nWRes File_Write(CSzFile *p, const void *data, size_t *size)\n{\n  size_t originalSize = *size;\n  if (originalSize == 0)\n    return 0;\n  \n  #ifdef USE_WINDOWS_FILE\n\n  *size = 0;\n  do\n  {\n    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;\n    DWORD processed = 0;\n    BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);\n    data = (void *)((Byte *)data + processed);\n    originalSize -= processed;\n    *size += processed;\n    if (!res)\n      return GetLastError();\n    if (processed == 0)\n      break;\n  }\n  while (originalSize > 0);\n  return 0;\n\n  #else\n\n  *size = fwrite(data, 1, originalSize, p->file);\n  if (*size == originalSize)\n    return 0;\n  return ferror(p->file);\n  \n  #endif\n}\n\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)\n{\n  #ifdef USE_WINDOWS_FILE\n\n  LARGE_INTEGER value;\n  DWORD moveMethod;\n  value.LowPart = (DWORD)*pos;\n  value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */\n  switch (origin)\n  {\n    case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;\n    case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;\n    case SZ_SEEK_END: moveMethod = FILE_END; break;\n    default: return ERROR_INVALID_PARAMETER;\n  }\n  value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);\n  if (value.LowPart == 0xFFFFFFFF)\n  {\n    WRes res = GetLastError();\n    if (res != NO_ERROR)\n      return res;\n  }\n  *pos = ((Int64)value.HighPart << 32) | value.LowPart;\n  return 0;\n\n  #else\n  \n  int moveMethod;\n  int res;\n  switch (origin)\n  {\n    case SZ_SEEK_SET: moveMethod = SEEK_SET; break;\n    case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;\n    case SZ_SEEK_END: moveMethod = SEEK_END; break;\n    default: return 1;\n  }\n  res = fseek(p->file, (long)*pos, moveMethod);\n  *pos = ftell(p->file);\n  return res;\n  \n  #endif\n}\n\nWRes File_GetLength(CSzFile *p, UInt64 *length)\n{\n  #ifdef USE_WINDOWS_FILE\n  \n  DWORD sizeHigh;\n  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);\n  if (sizeLow == 0xFFFFFFFF)\n  {\n    DWORD res = GetLastError();\n    if (res != NO_ERROR)\n      return res;\n  }\n  *length = (((UInt64)sizeHigh) << 32) + sizeLow;\n  return 0;\n  \n  #else\n  \n  long pos = ftell(p->file);\n  int res = fseek(p->file, 0, SEEK_END);\n  *length = ftell(p->file);\n  fseek(p->file, pos, SEEK_SET);\n  return res;\n  \n  #endif\n}\n\n\n/* ---------- FileSeqInStream ---------- */\n\nstatic SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)\n{\n  CFileSeqInStream *p = (CFileSeqInStream *)pp;\n  return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;\n}\n\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p)\n{\n  p->s.Read = FileSeqInStream_Read;\n}\n\n\n/* ---------- FileInStream ---------- */\n\nstatic SRes FileInStream_Read(void *pp, void *buf, size_t *size)\n{\n  CFileInStream *p = (CFileInStream *)pp;\n  return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;\n}\n\nstatic SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)\n{\n  CFileInStream *p = (CFileInStream *)pp;\n  return File_Seek(&p->file, pos, origin);\n}\n\nvoid FileInStream_CreateVTable(CFileInStream *p)\n{\n  p->s.Read = FileInStream_Read;\n  p->s.Seek = FileInStream_Seek;\n}\n\n\n/* ---------- FileOutStream ---------- */\n\nstatic size_t FileOutStream_Write(void *pp, const void *data, size_t size)\n{\n  CFileOutStream *p = (CFileOutStream *)pp;\n  File_Write(&p->file, data, &size);\n  return size;\n}\n\nvoid FileOutStream_CreateVTable(CFileOutStream *p)\n{\n  p->s.Write = FileOutStream_Write;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/7zFile.h",
    "content": "/* 7zFile.h -- File IO\n2008-11-22 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_FILE_H\n#define __7Z_FILE_H\n\n#ifdef _WIN32\n#define USE_WINDOWS_FILE\n#endif\n\n#ifdef USE_WINDOWS_FILE\n#include <windows.h>\n#else\n#include <stdio.h>\n#endif\n\n#include \"Types.h\"\n\n\n/* ---------- File ---------- */\n\ntypedef struct\n{\n  #ifdef USE_WINDOWS_FILE\n  HANDLE handle;\n  #else\n  FILE *file;\n  #endif\n} CSzFile;\n\nvoid File_Construct(CSzFile *p);\nWRes InFile_Open(CSzFile *p, const char *name);\nWRes OutFile_Open(CSzFile *p, const char *name);\nWRes File_Close(CSzFile *p);\n\n/* reads max(*size, remain file's size) bytes */\nWRes File_Read(CSzFile *p, void *data, size_t *size);\n\n/* writes *size bytes */\nWRes File_Write(CSzFile *p, const void *data, size_t *size);\n\nWRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);\nWRes File_GetLength(CSzFile *p, UInt64 *length);\n\n\n/* ---------- FileInStream ---------- */\n\ntypedef struct\n{\n  ISeqInStream s;\n  CSzFile file;\n} CFileSeqInStream;\n\nvoid FileSeqInStream_CreateVTable(CFileSeqInStream *p);\n\n\ntypedef struct\n{\n  ISeekInStream s;\n  CSzFile file;\n} CFileInStream;\n\nvoid FileInStream_CreateVTable(CFileInStream *p);\n\n\ntypedef struct\n{\n  ISeqOutStream s;\n  CSzFile file;\n} CFileOutStream;\n\nvoid FileOutStream_CreateVTable(CFileOutStream *p);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/7zStream.c",
    "content": "/* 7zStream.c -- 7z Stream functions\n2008-11-23 : Igor Pavlov : Public domain */\n\n#include <string.h>\n\n#include \"Types.h\"\n\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)\n{\n  while (size != 0)\n  {\n    size_t processed = size;\n    RINOK(stream->Read(stream, buf, &processed));\n    if (processed == 0)\n      return errorType;\n    buf = (void *)((Byte *)buf + processed);\n    size -= processed;\n  }\n  return SZ_OK;\n}\n\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)\n{\n  return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\n}\n\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)\n{\n  size_t processed = 1;\n  RINOK(stream->Read(stream, buf, &processed));\n  return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;\n}\n\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)\n{\n  Int64 t = offset;\n  return stream->Seek(stream, &t, SZ_SEEK_SET);\n}\n\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)\n{\n  void *lookBuf;\n  if (*size == 0)\n    return SZ_OK;\n  RINOK(stream->Look(stream, &lookBuf, size));\n  memcpy(buf, lookBuf, *size);\n  return stream->Skip(stream, *size);\n}\n\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)\n{\n  while (size != 0)\n  {\n    size_t processed = size;\n    RINOK(stream->Read(stream, buf, &processed));\n    if (processed == 0)\n      return errorType;\n    buf = (void *)((Byte *)buf + processed);\n    size -= processed;\n  }\n  return SZ_OK;\n}\n\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)\n{\n  return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\n}\n\nstatic SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)\n{\n  SRes res = SZ_OK;\n  CLookToRead *p = (CLookToRead *)pp;\n  size_t size2 = p->size - p->pos;\n  if (size2 == 0 && *size > 0)\n  {\n    p->pos = 0;\n    size2 = LookToRead_BUF_SIZE;\n    res = p->realStream->Read(p->realStream, p->buf, &size2);\n    p->size = size2;\n  }\n  if (size2 < *size)\n    *size = size2;\n  *buf = p->buf + p->pos;\n  return res;\n}\n\nstatic SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)\n{\n  SRes res = SZ_OK;\n  CLookToRead *p = (CLookToRead *)pp;\n  size_t size2 = p->size - p->pos;\n  if (size2 == 0 && *size > 0)\n  {\n    p->pos = 0;\n    if (*size > LookToRead_BUF_SIZE)\n      *size = LookToRead_BUF_SIZE;\n    res = p->realStream->Read(p->realStream, p->buf, size);\n    size2 = p->size = *size;\n  }\n  if (size2 < *size)\n    *size = size2;\n  *buf = p->buf + p->pos;\n  return res;\n}\n\nstatic SRes LookToRead_Skip(void *pp, size_t offset)\n{\n  CLookToRead *p = (CLookToRead *)pp;\n  p->pos += offset;\n  return SZ_OK;\n}\n\nstatic SRes LookToRead_Read(void *pp, void *buf, size_t *size)\n{\n  CLookToRead *p = (CLookToRead *)pp;\n  size_t rem = p->size - p->pos;\n  if (rem == 0)\n    return p->realStream->Read(p->realStream, buf, size);\n  if (rem > *size)\n    rem = *size;\n  memcpy(buf, p->buf + p->pos, rem);\n  p->pos += rem;\n  *size = rem;\n  return SZ_OK;\n}\n\nstatic SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)\n{\n  CLookToRead *p = (CLookToRead *)pp;\n  p->pos = p->size = 0;\n  return p->realStream->Seek(p->realStream, pos, origin);\n}\n\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead)\n{\n  p->s.Look = lookahead ?\n      LookToRead_Look_Lookahead :\n      LookToRead_Look_Exact;\n  p->s.Skip = LookToRead_Skip;\n  p->s.Read = LookToRead_Read;\n  p->s.Seek = LookToRead_Seek;\n}\n\nvoid LookToRead_Init(CLookToRead *p)\n{\n  p->pos = p->size = 0;\n}\n\nstatic SRes SecToLook_Read(void *pp, void *buf, size_t *size)\n{\n  CSecToLook *p = (CSecToLook *)pp;\n  return LookInStream_LookRead(p->realStream, buf, size);\n}\n\nvoid SecToLook_CreateVTable(CSecToLook *p)\n{\n  p->s.Read = SecToLook_Read;\n}\n\nstatic SRes SecToRead_Read(void *pp, void *buf, size_t *size)\n{\n  CSecToRead *p = (CSecToRead *)pp;\n  return p->realStream->Read(p->realStream, buf, size);\n}\n\nvoid SecToRead_CreateVTable(CSecToRead *p)\n{\n  p->s.Read = SecToRead_Read;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/7zVersion.h",
    "content": "#define MY_VER_MAJOR 4\n#define MY_VER_MINOR 65\n#define MY_VER_BUILD 0\n#define MY_VERSION \"4.65\"\n#define MY_DATE \"2009-02-03\"\n#define MY_COPYRIGHT \": Igor Pavlov : Public domain\"\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \" \" MY_COPYRIGHT \" : \" MY_DATE\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Alloc.c",
    "content": "/* Alloc.c -- Memory allocation functions\n2008-09-24\nIgor Pavlov\nPublic domain */\n\n#ifdef _WIN32\n#include <windows.h>\n#endif\n#include <stdlib.h>\n\n#include \"Alloc.h\"\n\n/* #define _SZ_ALLOC_DEBUG */\n\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\n#ifdef _SZ_ALLOC_DEBUG\n#include <stdio.h>\nint g_allocCount = 0;\nint g_allocCountMid = 0;\nint g_allocCountBig = 0;\n#endif\n\nvoid *MyAlloc(size_t size)\n{\n  if (size == 0)\n    return 0;\n  #ifdef _SZ_ALLOC_DEBUG\n  {\n    void *p = malloc(size);\n    fprintf(stderr, \"\\nAlloc %10d bytes, count = %10d,  addr = %8X\", size, g_allocCount++, (unsigned)p);\n    return p;\n  }\n  #else\n  return malloc(size);\n  #endif\n}\n\nvoid MyFree(void *address)\n{\n  #ifdef _SZ_ALLOC_DEBUG\n  if (address != 0)\n    fprintf(stderr, \"\\nFree; count = %10d,  addr = %8X\", --g_allocCount, (unsigned)address);\n  #endif\n  free(address);\n}\n\n#ifdef _WIN32\n\nvoid *MidAlloc(size_t size)\n{\n  if (size == 0)\n    return 0;\n  #ifdef _SZ_ALLOC_DEBUG\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\n  #endif\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\n}\n\nvoid MidFree(void *address)\n{\n  #ifdef _SZ_ALLOC_DEBUG\n  if (address != 0)\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\n  #endif\n  if (address == 0)\n    return;\n  VirtualFree(address, 0, MEM_RELEASE);\n}\n\n#ifndef MEM_LARGE_PAGES\n#undef _7ZIP_LARGE_PAGES\n#endif\n\n#ifdef _7ZIP_LARGE_PAGES\nSIZE_T g_LargePageSize = 0;\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\n#endif\n\nvoid SetLargePageSize()\n{\n  #ifdef _7ZIP_LARGE_PAGES\n  SIZE_T size = 0;\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\n        GetProcAddress(GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\n  if (largePageMinimum == 0)\n    return;\n  size = largePageMinimum();\n  if (size == 0 || (size & (size - 1)) != 0)\n    return;\n  g_LargePageSize = size;\n  #endif\n}\n\n\nvoid *BigAlloc(size_t size)\n{\n  if (size == 0)\n    return 0;\n  #ifdef _SZ_ALLOC_DEBUG\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\n  #endif\n  \n  #ifdef _7ZIP_LARGE_PAGES\n  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))\n  {\n    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\n    if (res != 0)\n      return res;\n  }\n  #endif\n  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\n}\n\nvoid BigFree(void *address)\n{\n  #ifdef _SZ_ALLOC_DEBUG\n  if (address != 0)\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\n  #endif\n  \n  if (address == 0)\n    return;\n  VirtualFree(address, 0, MEM_RELEASE);\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Alloc.h",
    "content": "/* Alloc.h -- Memory allocation functions\n2008-03-13\nIgor Pavlov\nPublic domain */\n\n#ifndef __COMMON_ALLOC_H\n#define __COMMON_ALLOC_H\n\n#include <stddef.h>\n\nvoid *MyAlloc(size_t size);\nvoid MyFree(void *address);\n\n#ifdef _WIN32\n\nvoid SetLargePageSize();\n\nvoid *MidAlloc(size_t size);\nvoid MidFree(void *address);\nvoid *BigAlloc(size_t size);\nvoid BigFree(void *address);\n\n#else\n\n#define MidAlloc(size) MyAlloc(size)\n#define MidFree(address) MyFree(address)\n#define BigAlloc(size) MyAlloc(size)\n#define BigFree(address) MyFree(address)\n\n#endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** DO NOT EDIT **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=7z - Win32 Debug\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n!MESSAGE use the Export Makefile command and run\n!MESSAGE \n!MESSAGE NMAKE /f \"7z.mak\".\n!MESSAGE \n!MESSAGE You can specify a configuration when running NMAKE\n!MESSAGE by defining the macro CFG on the command line. For example:\n!MESSAGE \n!MESSAGE NMAKE /f \"7z.mak\" CFG=\"7z - Win32 Debug\"\n!MESSAGE \n!MESSAGE Possible choices for configuration are:\n!MESSAGE \n!MESSAGE \"7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \"7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n\n!IF  \"$(CFG)\" == \"7z - Win32 Release\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \"Release\"\n# PROP BASE Intermediate_Dir \"Release\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \"Release\"\n# PROP Intermediate_Dir \"Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n# ADD CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /FAs /YX /FD /c\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\n# ADD RSC /l 0x419 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\" /opt:NOWIN98\n# SUBTRACT LINK32 /pdb:none\n\n!ELSEIF  \"$(CFG)\" == \"7z - Win32 Debug\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 1\n# PROP BASE Output_Dir \"Debug\"\n# PROP BASE Intermediate_Dir \"Debug\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 1\n# PROP Output_Dir \"Debug\"\n# PROP Intermediate_Dir \"Debug\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_SZ_ALLOC_DEBUG2\" /D \"_SZ_NO_INT_64_A\" /YX /FD /GZ /c\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\n# ADD RSC /l 0x419 /d \"_DEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\n\n!ENDIF \n\n# Begin Target\n\n# Name \"7z - Win32 Release\"\n# Name \"7z - Win32 Debug\"\n# Begin Group \"Common\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\7zBuf.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\7zBuf.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\7zCrc.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\7zCrc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\7zFile.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\7zFile.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\7zStream.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Bcj2.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Bcj2.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Bra.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Bra86.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\LzmaDec.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\LzmaDec.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Types.h\n# End Source File\n# End Group\n# Begin Source File\n\nSOURCE=.\\7zAlloc.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zAlloc.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zDecode.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zDecode.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zExtract.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zExtract.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zHeader.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zHeader.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zIn.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zIn.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zItem.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zItem.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\7zMain.c\n# End Source File\n# End Target\n# End Project\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n###############################################################################\n\nProject: \"7z\"=.\\7z.dsp - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nGlobal:\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<3>\n{{{\n}}}\n\n###############################################################################\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zAlloc.c",
    "content": "/* 7zAlloc.c -- Allocation functions\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include <stdlib.h>\n#include \"7zAlloc.h\"\n\n/* #define _SZ_ALLOC_DEBUG */\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\n\n#ifdef _SZ_ALLOC_DEBUG\n\n#ifdef _WIN32\n#include <windows.h>\n#endif\n\n#include <stdio.h>\nint g_allocCount = 0;\nint g_allocCountTemp = 0;\n\n#endif\n\nvoid *SzAlloc(void *p, size_t size)\n{\n  p = p;\n  if (size == 0)\n    return 0;\n  #ifdef _SZ_ALLOC_DEBUG\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\n  g_allocCount++;\n  #endif\n  return malloc(size);\n}\n\nvoid SzFree(void *p, void *address)\n{\n  p = p;\n  #ifdef _SZ_ALLOC_DEBUG\n  if (address != 0)\n  {\n    g_allocCount--;\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\n  }\n  #endif\n  free(address);\n}\n\nvoid *SzAllocTemp(void *p, size_t size)\n{\n  p = p;\n  if (size == 0)\n    return 0;\n  #ifdef _SZ_ALLOC_DEBUG\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\n  g_allocCountTemp++;\n  #ifdef _WIN32\n  return HeapAlloc(GetProcessHeap(), 0, size);\n  #endif\n  #endif\n  return malloc(size);\n}\n\nvoid SzFreeTemp(void *p, void *address)\n{\n  p = p;\n  #ifdef _SZ_ALLOC_DEBUG\n  if (address != 0)\n  {\n    g_allocCountTemp--;\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\n  }\n  #ifdef _WIN32\n  HeapFree(GetProcessHeap(), 0, address);\n  return;\n  #endif\n  #endif\n  free(address);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zAlloc.h",
    "content": "/* 7zAlloc.h -- Allocation functions\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_ALLOC_H\n#define __7Z_ALLOC_H\n\n#include <stddef.h>\n\nvoid *SzAlloc(void *p, size_t size);\nvoid SzFree(void *p, void *address);\n\nvoid *SzAllocTemp(void *p, size_t size);\nvoid SzFreeTemp(void *p, void *address);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zDecode.c",
    "content": "/* 7zDecode.c -- Decoding from 7z folder\n2008-11-23 : Igor Pavlov : Public domain */\n\n#include <string.h>\n\n#include \"../../Bcj2.h\"\n#include \"../../Bra.h\"\n#include \"../../LzmaDec.h\"\n#include \"7zDecode.h\"\n\n#define k_Copy 0\n#define k_LZMA 0x30101\n#define k_BCJ 0x03030103\n#define k_BCJ2 0x0303011B\n\nstatic SRes SzDecodeLzma(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)\n{\n  CLzmaDec state;\n  SRes res = SZ_OK;\n\n  LzmaDec_Construct(&state);\n  RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));\n  state.dic = outBuffer;\n  state.dicBufSize = outSize;\n  LzmaDec_Init(&state);\n\n  for (;;)\n  {\n    Byte *inBuf = NULL;\n    size_t lookahead = (1 << 18);\n    if (lookahead > inSize)\n      lookahead = (size_t)inSize;\n    res = inStream->Look((void *)inStream, (void **)&inBuf, &lookahead);\n    if (res != SZ_OK)\n      break;\n\n    {\n      SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;\n      ELzmaStatus status;\n      res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);\n      lookahead -= inProcessed;\n      inSize -= inProcessed;\n      if (res != SZ_OK)\n        break;\n      if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))\n      {\n        if (state.dicBufSize != outSize || lookahead != 0 ||\n            (status != LZMA_STATUS_FINISHED_WITH_MARK &&\n             status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))\n          res = SZ_ERROR_DATA;\n        break;\n      }\n      res = inStream->Skip((void *)inStream, inProcessed);\n      if (res != SZ_OK)\n        break;\n    }\n  }\n\n  LzmaDec_FreeProbs(&state, allocMain);\n  return res;\n}\n\nstatic SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)\n{\n  while (inSize > 0)\n  {\n    void *inBuf;\n    size_t curSize = (1 << 18);\n    if (curSize > inSize)\n      curSize = (size_t)inSize;\n    RINOK(inStream->Look((void *)inStream, (void **)&inBuf, &curSize));\n    if (curSize == 0)\n      return SZ_ERROR_INPUT_EOF;\n    memcpy(outBuffer, inBuf, curSize);\n    outBuffer += curSize;\n    inSize -= curSize;\n    RINOK(inStream->Skip((void *)inStream, curSize));\n  }\n  return SZ_OK;\n}\n\n#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)\n#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)\n#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)\n#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)\n\nSRes CheckSupportedFolder(const CSzFolder *f)\n{\n  if (f->NumCoders < 1 || f->NumCoders > 4)\n    return SZ_ERROR_UNSUPPORTED;\n  if (IS_UNSUPPORTED_CODER(f->Coders[0]))\n    return SZ_ERROR_UNSUPPORTED;\n  if (f->NumCoders == 1)\n  {\n    if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)\n      return SZ_ERROR_UNSUPPORTED;\n    return SZ_OK;\n  }\n  if (f->NumCoders == 2)\n  {\n    if (IS_NO_BCJ(f->Coders[1]) ||\n        f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||\n        f->NumBindPairs != 1 ||\n        f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)\n      return SZ_ERROR_UNSUPPORTED;\n    return SZ_OK;\n  }\n  if (f->NumCoders == 4)\n  {\n    if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||\n        IS_UNSUPPORTED_CODER(f->Coders[2]) ||\n        IS_NO_BCJ2(f->Coders[3]))\n      return SZ_ERROR_UNSUPPORTED;\n    if (f->NumPackStreams != 4 ||\n        f->PackStreams[0] != 2 ||\n        f->PackStreams[1] != 6 ||\n        f->PackStreams[2] != 1 ||\n        f->PackStreams[3] != 0 ||\n        f->NumBindPairs != 3 ||\n        f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||\n        f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||\n        f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)\n      return SZ_ERROR_UNSUPPORTED;\n    return SZ_OK;\n  }\n  return SZ_ERROR_UNSUPPORTED;\n}\n\nUInt64 GetSum(const UInt64 *values, UInt32 index)\n{\n  UInt64 sum = 0;\n  UInt32 i;\n  for (i = 0; i < index; i++)\n    sum += values[i];\n  return sum;\n}\n\nSRes SzDecode2(const UInt64 *packSizes, const CSzFolder *folder,\n    ILookInStream *inStream, UInt64 startPos,\n    Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,\n    Byte *tempBuf[])\n{\n  UInt32 ci;\n  SizeT tempSizes[3] = { 0, 0, 0};\n  SizeT tempSize3 = 0;\n  Byte *tempBuf3 = 0;\n\n  RINOK(CheckSupportedFolder(folder));\n\n  for (ci = 0; ci < folder->NumCoders; ci++)\n  {\n    CSzCoderInfo *coder = &folder->Coders[ci];\n\n    if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)\n    {\n      UInt32 si = 0;\n      UInt64 offset;\n      UInt64 inSize;\n      Byte *outBufCur = outBuffer;\n      SizeT outSizeCur = outSize;\n      if (folder->NumCoders == 4)\n      {\n        UInt32 indices[] = { 3, 2, 0 };\n        UInt64 unpackSize = folder->UnpackSizes[ci];\n        si = indices[ci];\n        if (ci < 2)\n        {\n          Byte *temp;\n          outSizeCur = (SizeT)unpackSize;\n          if (outSizeCur != unpackSize)\n            return SZ_ERROR_MEM;\n          temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);\n          if (temp == 0 && outSizeCur != 0)\n            return SZ_ERROR_MEM;\n          outBufCur = tempBuf[1 - ci] = temp;\n          tempSizes[1 - ci] = outSizeCur;\n        }\n        else if (ci == 2)\n        {\n          if (unpackSize > outSize) /* check it */\n            return SZ_ERROR_PARAM;\n          tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);\n          tempSize3 = outSizeCur = (SizeT)unpackSize;\n        }\n        else\n          return SZ_ERROR_UNSUPPORTED;\n      }\n      offset = GetSum(packSizes, si);\n      inSize = packSizes[si];\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\n\n      if (coder->MethodID == k_Copy)\n      {\n        if (inSize != outSizeCur) /* check it */\n          return SZ_ERROR_DATA;\n        RINOK(SzDecodeCopy(inSize, inStream, outBufCur));\n      }\n      else\n      {\n        RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));\n      }\n    }\n    else if (coder->MethodID == k_BCJ)\n    {\n      UInt32 state;\n      if (ci != 1)\n        return SZ_ERROR_UNSUPPORTED;\n      x86_Convert_Init(state);\n      x86_Convert(outBuffer, outSize, 0, &state, 0);\n    }\n    else if (coder->MethodID == k_BCJ2)\n    {\n      UInt64 offset = GetSum(packSizes, 1);\n      UInt64 s3Size = packSizes[1];\n      SRes res;\n      if (ci != 3)\n        return SZ_ERROR_UNSUPPORTED;\n      RINOK(LookInStream_SeekTo(inStream, startPos + offset));\n      tempSizes[2] = (SizeT)s3Size;\n      if (tempSizes[2] != s3Size)\n        return SZ_ERROR_MEM;\n      tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);\n      if (tempBuf[2] == 0 && tempSizes[2] != 0)\n        return SZ_ERROR_MEM;\n      res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);\n      RINOK(res)\n\n      res = Bcj2_Decode(\n          tempBuf3, tempSize3,\n          tempBuf[0], tempSizes[0],\n          tempBuf[1], tempSizes[1],\n          tempBuf[2], tempSizes[2],\n          outBuffer, outSize);\n      RINOK(res)\n    }\n    else\n      return SZ_ERROR_UNSUPPORTED;\n  }\n  return SZ_OK;\n}\n\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\n    ILookInStream *inStream, UInt64 startPos,\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)\n{\n  Byte *tempBuf[3] = { 0, 0, 0};\n  int i;\n  SRes res = SzDecode2(packSizes, folder, inStream, startPos,\n      outBuffer, (SizeT)outSize, allocMain, tempBuf);\n  for (i = 0; i < 3; i++)\n    IAlloc_Free(allocMain, tempBuf[i]);\n  return res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zDecode.h",
    "content": "/* 7zDecode.h -- Decoding from 7z folder\n2008-11-23 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_DECODE_H\n#define __7Z_DECODE_H\n\n#include \"7zItem.h\"\n\nSRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,\n    ILookInStream *stream, UInt64 startPos,\n    Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zExtract.c",
    "content": "/* 7zExtract.c -- Extracting from 7z archive\n2008-11-23 : Igor Pavlov : Public domain */\n\n#include \"../../7zCrc.h\"\n#include \"7zDecode.h\"\n#include \"7zExtract.h\"\n\nSRes SzAr_Extract(\n    const CSzArEx *p,\n    ILookInStream *inStream,\n    UInt32 fileIndex,\n    UInt32 *blockIndex,\n    Byte **outBuffer,\n    size_t *outBufferSize,\n    size_t *offset,\n    size_t *outSizeProcessed,\n    ISzAlloc *allocMain,\n    ISzAlloc *allocTemp)\n{\n  UInt32 folderIndex = p->FileIndexToFolderIndexMap[fileIndex];\n  SRes res = SZ_OK;\n  *offset = 0;\n  *outSizeProcessed = 0;\n  if (folderIndex == (UInt32)-1)\n  {\n    IAlloc_Free(allocMain, *outBuffer);\n    *blockIndex = folderIndex;\n    *outBuffer = 0;\n    *outBufferSize = 0;\n    return SZ_OK;\n  }\n\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\n  {\n    CSzFolder *folder = p->db.Folders + folderIndex;\n    UInt64 unpackSizeSpec = SzFolder_GetUnpackSize(folder);\n    size_t unpackSize = (size_t)unpackSizeSpec;\n    UInt64 startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);\n\n    if (unpackSize != unpackSizeSpec)\n      return SZ_ERROR_MEM;\n    *blockIndex = folderIndex;\n    IAlloc_Free(allocMain, *outBuffer);\n    *outBuffer = 0;\n    \n    RINOK(LookInStream_SeekTo(inStream, startOffset));\n    \n    if (res == SZ_OK)\n    {\n      *outBufferSize = unpackSize;\n      if (unpackSize != 0)\n      {\n        *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unpackSize);\n        if (*outBuffer == 0)\n          res = SZ_ERROR_MEM;\n      }\n      if (res == SZ_OK)\n      {\n        res = SzDecode(p->db.PackSizes +\n          p->FolderStartPackStreamIndex[folderIndex], folder,\n          inStream, startOffset,\n          *outBuffer, unpackSize, allocTemp);\n        if (res == SZ_OK)\n        {\n          if (folder->UnpackCRCDefined)\n          {\n            if (CrcCalc(*outBuffer, unpackSize) != folder->UnpackCRC)\n              res = SZ_ERROR_CRC;\n          }\n        }\n      }\n    }\n  }\n  if (res == SZ_OK)\n  {\n    UInt32 i;\n    CSzFileItem *fileItem = p->db.Files + fileIndex;\n    *offset = 0;\n    for (i = p->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\n      *offset += (UInt32)p->db.Files[i].Size;\n    *outSizeProcessed = (size_t)fileItem->Size;\n    if (*offset + *outSizeProcessed > *outBufferSize)\n      return SZ_ERROR_FAIL;\n    {\n      if (fileItem->FileCRCDefined)\n      {\n        if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)\n          res = SZ_ERROR_CRC;\n      }\n    }\n  }\n  return res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zExtract.h",
    "content": "/* 7zExtract.h -- Extracting from 7z archive\n2008-11-23 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_EXTRACT_H\n#define __7Z_EXTRACT_H\n\n#include \"7zIn.h\"\n\n/*\n  SzExtract extracts file from archive\n\n  *outBuffer must be 0 before first call for each new archive.\n\n  Extracting cache:\n    If you need to decompress more than one file, you can send\n    these values from previous call:\n      *blockIndex,\n      *outBuffer,\n      *outBufferSize\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid,\n    it will increase decompression speed.\n  \n    If you use external function, you can declare these 3 cache variables\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\n    \n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\n*/\n\nSRes SzAr_Extract(\n    const CSzArEx *db,\n    ILookInStream *inStream,\n    UInt32 fileIndex,         /* index of file */\n    UInt32 *blockIndex,       /* index of solid block */\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\n    size_t *outBufferSize,    /* buffer size for output buffer */\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\n    ISzAlloc *allocMain,\n    ISzAlloc *allocTemp);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zHeader.c",
    "content": "/*  7zHeader.c -- 7z Headers\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include \"7zHeader.h\"\n\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zHeader.h",
    "content": "/* 7zHeader.h -- 7z Headers\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_HEADER_H\n#define __7Z_HEADER_H\n\n#include \"../../Types.h\"\n\n#define k7zSignatureSize 6\nextern Byte k7zSignature[k7zSignatureSize];\n\n#define k7zMajorVersion 0\n\n#define k7zStartHeaderSize 0x20\n\nenum EIdEnum\n{\n  k7zIdEnd,\n    \n  k7zIdHeader,\n    \n  k7zIdArchiveProperties,\n    \n  k7zIdAdditionalStreamsInfo,\n  k7zIdMainStreamsInfo,\n  k7zIdFilesInfo,\n  \n  k7zIdPackInfo,\n  k7zIdUnpackInfo,\n  k7zIdSubStreamsInfo,\n  \n  k7zIdSize,\n  k7zIdCRC,\n  \n  k7zIdFolder,\n  \n  k7zIdCodersUnpackSize,\n  k7zIdNumUnpackStream,\n  \n  k7zIdEmptyStream,\n  k7zIdEmptyFile,\n  k7zIdAnti,\n  \n  k7zIdName,\n  k7zIdCTime,\n  k7zIdATime,\n  k7zIdMTime,\n  k7zIdWinAttributes,\n  k7zIdComment,\n  \n  k7zIdEncodedHeader,\n  \n  k7zIdStartPos,\n  k7zIdDummy\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zIn.c",
    "content": "/* 7zIn.c -- 7z Input functions\n2008-12-31 : Igor Pavlov : Public domain */\n\n#include \"../../7zCrc.h\"\n#include \"../../CpuArch.h\"\n\n#include \"7zDecode.h\"\n#include \"7zIn.h\"\n\n#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }\n\n#define NUM_FOLDER_CODERS_MAX 32\n#define NUM_CODER_STREAMS_MAX 32\n\nvoid SzArEx_Init(CSzArEx *p)\n{\n  SzAr_Init(&p->db);\n  p->FolderStartPackStreamIndex = 0;\n  p->PackStreamStartPositions = 0;\n  p->FolderStartFileIndex = 0;\n  p->FileIndexToFolderIndexMap = 0;\n}\n\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)\n{\n  IAlloc_Free(alloc, p->FolderStartPackStreamIndex);\n  IAlloc_Free(alloc, p->PackStreamStartPositions);\n  IAlloc_Free(alloc, p->FolderStartFileIndex);\n  IAlloc_Free(alloc, p->FileIndexToFolderIndexMap);\n  SzAr_Free(&p->db, alloc);\n  SzArEx_Init(p);\n}\n\n/*\nUInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\n{\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\n}\n\nUInt64 GetFilePackSize(int fileIndex) const\n{\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\n  if (folderIndex >= 0)\n  {\n    const CSzFolder &folderInfo = Folders[folderIndex];\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\n    return GetFolderFullPackSize(folderIndex);\n  }\n  return 0;\n}\n*/\n\n#define MY_ALLOC(T, p, size, alloc) { if ((size) == 0) p = 0; else \\\n  if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == 0) return SZ_ERROR_MEM; }\n\nstatic SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)\n{\n  UInt32 startPos = 0;\n  UInt64 startPosSize = 0;\n  UInt32 i;\n  UInt32 folderIndex = 0;\n  UInt32 indexInFolder = 0;\n  MY_ALLOC(UInt32, p->FolderStartPackStreamIndex, p->db.NumFolders, alloc);\n  for (i = 0; i < p->db.NumFolders; i++)\n  {\n    p->FolderStartPackStreamIndex[i] = startPos;\n    startPos += p->db.Folders[i].NumPackStreams;\n  }\n\n  MY_ALLOC(UInt64, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);\n\n  for (i = 0; i < p->db.NumPackStreams; i++)\n  {\n    p->PackStreamStartPositions[i] = startPosSize;\n    startPosSize += p->db.PackSizes[i];\n  }\n\n  MY_ALLOC(UInt32, p->FolderStartFileIndex, p->db.NumFolders, alloc);\n  MY_ALLOC(UInt32, p->FileIndexToFolderIndexMap, p->db.NumFiles, alloc);\n\n  for (i = 0; i < p->db.NumFiles; i++)\n  {\n    CSzFileItem *file = p->db.Files + i;\n    int emptyStream = !file->HasStream;\n    if (emptyStream && indexInFolder == 0)\n    {\n      p->FileIndexToFolderIndexMap[i] = (UInt32)-1;\n      continue;\n    }\n    if (indexInFolder == 0)\n    {\n      /*\n      v3.13 incorrectly worked with empty folders\n      v4.07: Loop for skipping empty folders\n      */\n      for (;;)\n      {\n        if (folderIndex >= p->db.NumFolders)\n          return SZ_ERROR_ARCHIVE;\n        p->FolderStartFileIndex[folderIndex] = i;\n        if (p->db.Folders[folderIndex].NumUnpackStreams != 0)\n          break;\n        folderIndex++;\n      }\n    }\n    p->FileIndexToFolderIndexMap[i] = folderIndex;\n    if (emptyStream)\n      continue;\n    indexInFolder++;\n    if (indexInFolder >= p->db.Folders[folderIndex].NumUnpackStreams)\n    {\n      folderIndex++;\n      indexInFolder = 0;\n    }\n  }\n  return SZ_OK;\n}\n\n\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)\n{\n  return p->dataPos +\n    p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\n}\n\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize)\n{\n  UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];\n  CSzFolder *folder = p->db.Folders + folderIndex;\n  UInt64 size = 0;\n  UInt32 i;\n  for (i = 0; i < folder->NumPackStreams; i++)\n  {\n    UInt64 t = size + p->db.PackSizes[packStreamIndex + i];\n    if (t < size) /* check it */\n      return SZ_ERROR_FAIL;\n    size = t;\n  }\n  *resSize = size;\n  return SZ_OK;\n}\n\n\n/*\nSRes SzReadTime(const CObjectVector<CBuf> &dataVector,\n    CObjectVector<CSzFileItem> &files, UInt64 type)\n{\n  CBoolVector boolVector;\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\n\n  CStreamSwitch streamSwitch;\n  RINOK(streamSwitch.Set(this, &dataVector));\n\n  for (int i = 0; i < files.Size(); i++)\n  {\n    CSzFileItem &file = files[i];\n    CArchiveFileTime fileTime;\n    bool defined = boolVector[i];\n    if (defined)\n    {\n      UInt32 low, high;\n      RINOK(SzReadUInt32(low));\n      RINOK(SzReadUInt32(high));\n      fileTime.dwLowDateTime = low;\n      fileTime.dwHighDateTime = high;\n    }\n    switch(type)\n    {\n      case k7zIdCTime: file.IsCTimeDefined = defined; if (defined) file.CTime = fileTime; break;\n      case k7zIdATime: file.IsATimeDefined = defined; if (defined) file.ATime = fileTime; break;\n      case k7zIdMTime: file.IsMTimeDefined = defined; if (defined) file.MTime = fileTime; break;\n    }\n  }\n  return SZ_OK;\n}\n*/\n\nstatic int TestSignatureCandidate(Byte *testBytes)\n{\n  size_t i;\n  for (i = 0; i < k7zSignatureSize; i++)\n    if (testBytes[i] != k7zSignature[i])\n      return 0;\n  return 1;\n}\n\ntypedef struct _CSzState\n{\n  Byte *Data;\n  size_t Size;\n}CSzData;\n\nstatic SRes SzReadByte(CSzData *sd, Byte *b)\n{\n  if (sd->Size == 0)\n    return SZ_ERROR_ARCHIVE;\n  sd->Size--;\n  *b = *sd->Data++;\n  return SZ_OK;\n}\n\nstatic SRes SzReadBytes(CSzData *sd, Byte *data, size_t size)\n{\n  size_t i;\n  for (i = 0; i < size; i++)\n  {\n    RINOK(SzReadByte(sd, data + i));\n  }\n  return SZ_OK;\n}\n\nstatic SRes SzReadUInt32(CSzData *sd, UInt32 *value)\n{\n  int i;\n  *value = 0;\n  for (i = 0; i < 4; i++)\n  {\n    Byte b;\n    RINOK(SzReadByte(sd, &b));\n    *value |= ((UInt32)(b) << (8 * i));\n  }\n  return SZ_OK;\n}\n\nstatic SRes SzReadNumber(CSzData *sd, UInt64 *value)\n{\n  Byte firstByte;\n  Byte mask = 0x80;\n  int i;\n  RINOK(SzReadByte(sd, &firstByte));\n  *value = 0;\n  for (i = 0; i < 8; i++)\n  {\n    Byte b;\n    if ((firstByte & mask) == 0)\n    {\n      UInt64 highPart = firstByte & (mask - 1);\n      *value += (highPart << (8 * i));\n      return SZ_OK;\n    }\n    RINOK(SzReadByte(sd, &b));\n    *value |= ((UInt64)b << (8 * i));\n    mask >>= 1;\n  }\n  return SZ_OK;\n}\n\nstatic SRes SzReadNumber32(CSzData *sd, UInt32 *value)\n{\n  UInt64 value64;\n  RINOK(SzReadNumber(sd, &value64));\n  if (value64 >= 0x80000000)\n    return SZ_ERROR_UNSUPPORTED;\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\n    return SZ_ERROR_UNSUPPORTED;\n  *value = (UInt32)value64;\n  return SZ_OK;\n}\n\nstatic SRes SzReadID(CSzData *sd, UInt64 *value)\n{\n  return SzReadNumber(sd, value);\n}\n\nstatic SRes SzSkeepDataSize(CSzData *sd, UInt64 size)\n{\n  if (size > sd->Size)\n    return SZ_ERROR_ARCHIVE;\n  sd->Size -= (size_t)size;\n  sd->Data += (size_t)size;\n  return SZ_OK;\n}\n\nstatic SRes SzSkeepData(CSzData *sd)\n{\n  UInt64 size;\n  RINOK(SzReadNumber(sd, &size));\n  return SzSkeepDataSize(sd, size);\n}\n\nstatic SRes SzReadArchiveProperties(CSzData *sd)\n{\n  for (;;)\n  {\n    UInt64 type;\n    RINOK(SzReadID(sd, &type));\n    if (type == k7zIdEnd)\n      break;\n    SzSkeepData(sd);\n  }\n  return SZ_OK;\n}\n\nstatic SRes SzWaitAttribute(CSzData *sd, UInt64 attribute)\n{\n  for (;;)\n  {\n    UInt64 type;\n    RINOK(SzReadID(sd, &type));\n    if (type == attribute)\n      return SZ_OK;\n    if (type == k7zIdEnd)\n      return SZ_ERROR_ARCHIVE;\n    RINOK(SzSkeepData(sd));\n  }\n}\n\nstatic SRes SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\n{\n  Byte b = 0;\n  Byte mask = 0;\n  size_t i;\n  MY_ALLOC(Byte, *v, numItems, alloc);\n  for (i = 0; i < numItems; i++)\n  {\n    if (mask == 0)\n    {\n      RINOK(SzReadByte(sd, &b));\n      mask = 0x80;\n    }\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\n    mask >>= 1;\n  }\n  return SZ_OK;\n}\n\nstatic SRes SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)\n{\n  Byte allAreDefined;\n  size_t i;\n  RINOK(SzReadByte(sd, &allAreDefined));\n  if (allAreDefined == 0)\n    return SzReadBoolVector(sd, numItems, v, alloc);\n  MY_ALLOC(Byte, *v, numItems, alloc);\n  for (i = 0; i < numItems; i++)\n    (*v)[i] = 1;\n  return SZ_OK;\n}\n\nstatic SRes SzReadHashDigests(\n    CSzData *sd,\n    size_t numItems,\n    Byte **digestsDefined,\n    UInt32 **digests,\n    ISzAlloc *alloc)\n{\n  size_t i;\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, alloc));\n  MY_ALLOC(UInt32, *digests, numItems, alloc);\n  for (i = 0; i < numItems; i++)\n    if ((*digestsDefined)[i])\n    {\n      RINOK(SzReadUInt32(sd, (*digests) + i));\n    }\n  return SZ_OK;\n}\n\nstatic SRes SzReadPackInfo(\n    CSzData *sd,\n    UInt64 *dataOffset,\n    UInt32 *numPackStreams,\n    UInt64 **packSizes,\n    Byte **packCRCsDefined,\n    UInt32 **packCRCs,\n    ISzAlloc *alloc)\n{\n  UInt32 i;\n  RINOK(SzReadNumber(sd, dataOffset));\n  RINOK(SzReadNumber32(sd, numPackStreams));\n\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\n\n  MY_ALLOC(UInt64, *packSizes, (size_t)*numPackStreams, alloc);\n\n  for (i = 0; i < *numPackStreams; i++)\n  {\n    RINOK(SzReadNumber(sd, (*packSizes) + i));\n  }\n\n  for (;;)\n  {\n    UInt64 type;\n    RINOK(SzReadID(sd, &type));\n    if (type == k7zIdEnd)\n      break;\n    if (type == k7zIdCRC)\n    {\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));\n      continue;\n    }\n    RINOK(SzSkeepData(sd));\n  }\n  if (*packCRCsDefined == 0)\n  {\n    MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, alloc);\n    MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, alloc);\n    for (i = 0; i < *numPackStreams; i++)\n    {\n      (*packCRCsDefined)[i] = 0;\n      (*packCRCs)[i] = 0;\n    }\n  }\n  return SZ_OK;\n}\n\nstatic SRes SzReadSwitch(CSzData *sd)\n{\n  Byte external;\n  RINOK(SzReadByte(sd, &external));\n  return (external == 0) ? SZ_OK: SZ_ERROR_UNSUPPORTED;\n}\n\nstatic SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)\n{\n  UInt32 numCoders, numBindPairs, numPackStreams, i;\n  UInt32 numInStreams = 0, numOutStreams = 0;\n  \n  RINOK(SzReadNumber32(sd, &numCoders));\n  if (numCoders > NUM_FOLDER_CODERS_MAX)\n    return SZ_ERROR_UNSUPPORTED;\n  folder->NumCoders = numCoders;\n  \n  MY_ALLOC(CSzCoderInfo, folder->Coders, (size_t)numCoders, alloc);\n\n  for (i = 0; i < numCoders; i++)\n    SzCoderInfo_Init(folder->Coders + i);\n\n  for (i = 0; i < numCoders; i++)\n  {\n    Byte mainByte;\n    CSzCoderInfo *coder = folder->Coders + i;\n    {\n      unsigned idSize, j;\n      Byte longID[15];\n      RINOK(SzReadByte(sd, &mainByte));\n      idSize = (unsigned)(mainByte & 0xF);\n      RINOK(SzReadBytes(sd, longID, idSize));\n      if (idSize > sizeof(coder->MethodID))\n        return SZ_ERROR_UNSUPPORTED;\n      coder->MethodID = 0;\n      for (j = 0; j < idSize; j++)\n        coder->MethodID |= (UInt64)longID[idSize - 1 - j] << (8 * j);\n\n      if ((mainByte & 0x10) != 0)\n      {\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\n        if (coder->NumInStreams > NUM_CODER_STREAMS_MAX ||\n            coder->NumOutStreams > NUM_CODER_STREAMS_MAX)\n          return SZ_ERROR_UNSUPPORTED;\n      }\n      else\n      {\n        coder->NumInStreams = 1;\n        coder->NumOutStreams = 1;\n      }\n      if ((mainByte & 0x20) != 0)\n      {\n        UInt64 propertiesSize = 0;\n        RINOK(SzReadNumber(sd, &propertiesSize));\n        if (!Buf_Create(&coder->Props, (size_t)propertiesSize, alloc))\n          return SZ_ERROR_MEM;\n        RINOK(SzReadBytes(sd, coder->Props.data, (size_t)propertiesSize));\n      }\n    }\n    while ((mainByte & 0x80) != 0)\n    {\n      RINOK(SzReadByte(sd, &mainByte));\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\n      if ((mainByte & 0x10) != 0)\n      {\n        UInt32 n;\n        RINOK(SzReadNumber32(sd, &n));\n        RINOK(SzReadNumber32(sd, &n));\n      }\n      if ((mainByte & 0x20) != 0)\n      {\n        UInt64 propertiesSize = 0;\n        RINOK(SzReadNumber(sd, &propertiesSize));\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\n      }\n    }\n    numInStreams += coder->NumInStreams;\n    numOutStreams += coder->NumOutStreams;\n  }\n\n  if (numOutStreams == 0)\n    return SZ_ERROR_UNSUPPORTED;\n\n  folder->NumBindPairs = numBindPairs = numOutStreams - 1;\n  MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, alloc);\n\n  for (i = 0; i < numBindPairs; i++)\n  {\n    CBindPair *bp = folder->BindPairs + i;\n    RINOK(SzReadNumber32(sd, &bp->InIndex));\n    RINOK(SzReadNumber32(sd, &bp->OutIndex));\n  }\n\n  if (numInStreams < numBindPairs)\n    return SZ_ERROR_UNSUPPORTED;\n\n  folder->NumPackStreams = numPackStreams = numInStreams - numBindPairs;\n  MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackStreams, alloc);\n\n  if (numPackStreams == 1)\n  {\n    for (i = 0; i < numInStreams ; i++)\n      if (SzFolder_FindBindPairForInStream(folder, i) < 0)\n        break;\n    if (i == numInStreams)\n      return SZ_ERROR_UNSUPPORTED;\n    folder->PackStreams[0] = i;\n  }\n  else\n    for (i = 0; i < numPackStreams; i++)\n    {\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\n    }\n  return SZ_OK;\n}\n\nstatic SRes SzReadUnpackInfo(\n    CSzData *sd,\n    UInt32 *numFolders,\n    CSzFolder **folders,  /* for alloc */\n    ISzAlloc *alloc,\n    ISzAlloc *allocTemp)\n{\n  UInt32 i;\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\n  RINOK(SzReadNumber32(sd, numFolders));\n  {\n    RINOK(SzReadSwitch(sd));\n\n    MY_ALLOC(CSzFolder, *folders, (size_t)*numFolders, alloc);\n\n    for (i = 0; i < *numFolders; i++)\n      SzFolder_Init((*folders) + i);\n\n    for (i = 0; i < *numFolders; i++)\n    {\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, alloc));\n    }\n  }\n\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnpackSize));\n\n  for (i = 0; i < *numFolders; i++)\n  {\n    UInt32 j;\n    CSzFolder *folder = (*folders) + i;\n    UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);\n\n    MY_ALLOC(UInt64, folder->UnpackSizes, (size_t)numOutStreams, alloc);\n\n    for (j = 0; j < numOutStreams; j++)\n    {\n      RINOK(SzReadNumber(sd, folder->UnpackSizes + j));\n    }\n  }\n\n  for (;;)\n  {\n    UInt64 type;\n    RINOK(SzReadID(sd, &type));\n    if (type == k7zIdEnd)\n      return SZ_OK;\n    if (type == k7zIdCRC)\n    {\n      SRes res;\n      Byte *crcsDefined = 0;\n      UInt32 *crcs = 0;\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);\n      if (res == SZ_OK)\n      {\n        for (i = 0; i < *numFolders; i++)\n        {\n          CSzFolder *folder = (*folders) + i;\n          folder->UnpackCRCDefined = crcsDefined[i];\n          folder->UnpackCRC = crcs[i];\n        }\n      }\n      IAlloc_Free(allocTemp, crcs);\n      IAlloc_Free(allocTemp, crcsDefined);\n      RINOK(res);\n      continue;\n    }\n    RINOK(SzSkeepData(sd));\n  }\n}\n\nstatic SRes SzReadSubStreamsInfo(\n    CSzData *sd,\n    UInt32 numFolders,\n    CSzFolder *folders,\n    UInt32 *numUnpackStreams,\n    UInt64 **unpackSizes,\n    Byte **digestsDefined,\n    UInt32 **digests,\n    ISzAlloc *allocTemp)\n{\n  UInt64 type = 0;\n  UInt32 i;\n  UInt32 si = 0;\n  UInt32 numDigests = 0;\n\n  for (i = 0; i < numFolders; i++)\n    folders[i].NumUnpackStreams = 1;\n  *numUnpackStreams = numFolders;\n\n  for (;;)\n  {\n    RINOK(SzReadID(sd, &type));\n    if (type == k7zIdNumUnpackStream)\n    {\n      *numUnpackStreams = 0;\n      for (i = 0; i < numFolders; i++)\n      {\n        UInt32 numStreams;\n        RINOK(SzReadNumber32(sd, &numStreams));\n        folders[i].NumUnpackStreams = numStreams;\n        *numUnpackStreams += numStreams;\n      }\n      continue;\n    }\n    if (type == k7zIdCRC || type == k7zIdSize)\n      break;\n    if (type == k7zIdEnd)\n      break;\n    RINOK(SzSkeepData(sd));\n  }\n\n  if (*numUnpackStreams == 0)\n  {\n    *unpackSizes = 0;\n    *digestsDefined = 0;\n    *digests = 0;\n  }\n  else\n  {\n    *unpackSizes = (UInt64 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt64));\n    RINOM(*unpackSizes);\n    *digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(Byte));\n    RINOM(*digestsDefined);\n    *digests = (UInt32 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt32));\n    RINOM(*digests);\n  }\n\n  for (i = 0; i < numFolders; i++)\n  {\n    /*\n    v3.13 incorrectly worked with empty folders\n    v4.07: we check that folder is empty\n    */\n    UInt64 sum = 0;\n    UInt32 j;\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\n    if (numSubstreams == 0)\n      continue;\n    if (type == k7zIdSize)\n    for (j = 1; j < numSubstreams; j++)\n    {\n      UInt64 size;\n      RINOK(SzReadNumber(sd, &size));\n      (*unpackSizes)[si++] = size;\n      sum += size;\n    }\n    (*unpackSizes)[si++] = SzFolder_GetUnpackSize(folders + i) - sum;\n  }\n  if (type == k7zIdSize)\n  {\n    RINOK(SzReadID(sd, &type));\n  }\n\n  for (i = 0; i < *numUnpackStreams; i++)\n  {\n    (*digestsDefined)[i] = 0;\n    (*digests)[i] = 0;\n  }\n\n\n  for (i = 0; i < numFolders; i++)\n  {\n    UInt32 numSubstreams = folders[i].NumUnpackStreams;\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\n      numDigests += numSubstreams;\n  }\n\n \n  si = 0;\n  for (;;)\n  {\n    if (type == k7zIdCRC)\n    {\n      int digestIndex = 0;\n      Byte *digestsDefined2 = 0;\n      UInt32 *digests2 = 0;\n      SRes res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp);\n      if (res == SZ_OK)\n      {\n        for (i = 0; i < numFolders; i++)\n        {\n          CSzFolder *folder = folders + i;\n          UInt32 numSubstreams = folder->NumUnpackStreams;\n          if (numSubstreams == 1 && folder->UnpackCRCDefined)\n          {\n            (*digestsDefined)[si] = 1;\n            (*digests)[si] = folder->UnpackCRC;\n            si++;\n          }\n          else\n          {\n            UInt32 j;\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\n            {\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\n              (*digests)[si] = digests2[digestIndex];\n              si++;\n            }\n          }\n        }\n      }\n      IAlloc_Free(allocTemp, digestsDefined2);\n      IAlloc_Free(allocTemp, digests2);\n      RINOK(res);\n    }\n    else if (type == k7zIdEnd)\n      return SZ_OK;\n    else\n    {\n      RINOK(SzSkeepData(sd));\n    }\n    RINOK(SzReadID(sd, &type));\n  }\n}\n\n\nstatic SRes SzReadStreamsInfo(\n    CSzData *sd,\n    UInt64 *dataOffset,\n    CSzAr *p,\n    UInt32 *numUnpackStreams,\n    UInt64 **unpackSizes, /* allocTemp */\n    Byte **digestsDefined,   /* allocTemp */\n    UInt32 **digests,        /* allocTemp */\n    ISzAlloc *alloc,\n    ISzAlloc *allocTemp)\n{\n  for (;;)\n  {\n    UInt64 type;\n    RINOK(SzReadID(sd, &type));\n    if ((UInt64)(int)type != type)\n      return SZ_ERROR_UNSUPPORTED;\n    switch((int)type)\n    {\n      case k7zIdEnd:\n        return SZ_OK;\n      case k7zIdPackInfo:\n      {\n        RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,\n            &p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc));\n        break;\n      }\n      case k7zIdUnpackInfo:\n      {\n        RINOK(SzReadUnpackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));\n        break;\n      }\n      case k7zIdSubStreamsInfo:\n      {\n        RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,\n            numUnpackStreams, unpackSizes, digestsDefined, digests, allocTemp));\n        break;\n      }\n      default:\n        return SZ_ERROR_UNSUPPORTED;\n    }\n  }\n}\n\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\n\nstatic SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, ISzAlloc *alloc)\n{\n  UInt32 i;\n  for (i = 0; i < numFiles; i++)\n  {\n    UInt32 len = 0;\n    UInt32 pos = 0;\n    CSzFileItem *file = files + i;\n    while (pos + 2 <= sd->Size)\n    {\n      int numAdds;\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\n      pos += 2;\n      len++;\n      if (value == 0)\n        break;\n      if (value < 0x80)\n        continue;\n      if (value >= 0xD800 && value < 0xE000)\n      {\n        UInt32 c2;\n        if (value >= 0xDC00)\n          return SZ_ERROR_ARCHIVE;\n        if (pos + 2 > sd->Size)\n          return SZ_ERROR_ARCHIVE;\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\n        pos += 2;\n        if (c2 < 0xDC00 || c2 >= 0xE000)\n          return SZ_ERROR_ARCHIVE;\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\n      }\n      for (numAdds = 1; numAdds < 5; numAdds++)\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\n          break;\n      len += numAdds;\n    }\n\n    MY_ALLOC(char, file->Name, (size_t)len, alloc);\n\n    len = 0;\n    while (2 <= sd->Size)\n    {\n      int numAdds;\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\n      SzSkeepDataSize(sd, 2);\n      if (value < 0x80)\n      {\n        file->Name[len++] = (char)value;\n        if (value == 0)\n          break;\n        continue;\n      }\n      if (value >= 0xD800 && value < 0xE000)\n      {\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\n        SzSkeepDataSize(sd, 2);\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\n      }\n      for (numAdds = 1; numAdds < 5; numAdds++)\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\n          break;\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\n      do\n      {\n        numAdds--;\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\n      }\n      while (numAdds > 0);\n\n      len += numAdds;\n    }\n  }\n  return SZ_OK;\n}\n\nstatic SRes SzReadHeader2(\n    CSzArEx *p,   /* allocMain */\n    CSzData *sd,\n    UInt64 **unpackSizes,  /* allocTemp */\n    Byte **digestsDefined,    /* allocTemp */\n    UInt32 **digests,         /* allocTemp */\n    Byte **emptyStreamVector, /* allocTemp */\n    Byte **emptyFileVector,   /* allocTemp */\n    Byte **lwtVector,         /* allocTemp */\n    ISzAlloc *allocMain,\n    ISzAlloc *allocTemp)\n{\n  UInt64 type;\n  UInt32 numUnpackStreams = 0;\n  UInt32 numFiles = 0;\n  CSzFileItem *files = 0;\n  UInt32 numEmptyStreams = 0;\n  UInt32 i;\n\n  RINOK(SzReadID(sd, &type));\n\n  if (type == k7zIdArchiveProperties)\n  {\n    RINOK(SzReadArchiveProperties(sd));\n    RINOK(SzReadID(sd, &type));\n  }\n \n \n  if (type == k7zIdMainStreamsInfo)\n  {\n    RINOK(SzReadStreamsInfo(sd,\n        &p->dataPos,\n        &p->db,\n        &numUnpackStreams,\n        unpackSizes,\n        digestsDefined,\n        digests, allocMain, allocTemp));\n    p->dataPos += p->startPosAfterHeader;\n    RINOK(SzReadID(sd, &type));\n  }\n\n  if (type == k7zIdEnd)\n    return SZ_OK;\n  if (type != k7zIdFilesInfo)\n    return SZ_ERROR_ARCHIVE;\n  \n  RINOK(SzReadNumber32(sd, &numFiles));\n  p->db.NumFiles = numFiles;\n\n  MY_ALLOC(CSzFileItem, files, (size_t)numFiles, allocMain);\n\n  p->db.Files = files;\n  for (i = 0; i < numFiles; i++)\n    SzFile_Init(files + i);\n\n  for (;;)\n  {\n    UInt64 type;\n    UInt64 size;\n    RINOK(SzReadID(sd, &type));\n    if (type == k7zIdEnd)\n      break;\n    RINOK(SzReadNumber(sd, &size));\n\n    if ((UInt64)(int)type != type)\n    {\n      RINOK(SzSkeepDataSize(sd, size));\n    }\n    else\n    switch((int)type)\n    {\n      case k7zIdName:\n      {\n        RINOK(SzReadSwitch(sd));\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain))\n        break;\n      }\n      case k7zIdEmptyStream:\n      {\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp));\n        numEmptyStreams = 0;\n        for (i = 0; i < numFiles; i++)\n          if ((*emptyStreamVector)[i])\n            numEmptyStreams++;\n        break;\n      }\n      case k7zIdEmptyFile:\n      {\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp));\n        break;\n      }\n      case k7zIdMTime:\n      {\n        RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));\n        RINOK(SzReadSwitch(sd));\n        for (i = 0; i < numFiles; i++)\n        {\n          CSzFileItem *f = &files[i];\n          Byte defined = (*lwtVector)[i];\n          f->MTimeDefined = defined;\n          f->MTime.Low = f->MTime.High = 0;\n          if (defined)\n          {\n            RINOK(SzReadUInt32(sd, &f->MTime.Low));\n            RINOK(SzReadUInt32(sd, &f->MTime.High));\n          }\n        }\n        break;\n      }\n      default:\n      {\n        RINOK(SzSkeepDataSize(sd, size));\n      }\n    }\n  }\n\n  {\n    UInt32 emptyFileIndex = 0;\n    UInt32 sizeIndex = 0;\n    for (i = 0; i < numFiles; i++)\n    {\n      CSzFileItem *file = files + i;\n      file->IsAnti = 0;\n      if (*emptyStreamVector == 0)\n        file->HasStream = 1;\n      else\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\n      if (file->HasStream)\n      {\n        file->IsDir = 0;\n        file->Size = (*unpackSizes)[sizeIndex];\n        file->FileCRC = (*digests)[sizeIndex];\n        file->FileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\n        sizeIndex++;\n      }\n      else\n      {\n        if (*emptyFileVector == 0)\n          file->IsDir = 1;\n        else\n          file->IsDir = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\n        emptyFileIndex++;\n        file->Size = 0;\n        file->FileCRCDefined = 0;\n      }\n    }\n  }\n  return SzArEx_Fill(p, allocMain);\n}\n\nstatic SRes SzReadHeader(\n    CSzArEx *p,\n    CSzData *sd,\n    ISzAlloc *allocMain,\n    ISzAlloc *allocTemp)\n{\n  UInt64 *unpackSizes = 0;\n  Byte *digestsDefined = 0;\n  UInt32 *digests = 0;\n  Byte *emptyStreamVector = 0;\n  Byte *emptyFileVector = 0;\n  Byte *lwtVector = 0;\n  SRes res = SzReadHeader2(p, sd,\n      &unpackSizes, &digestsDefined, &digests,\n      &emptyStreamVector, &emptyFileVector, &lwtVector,\n      allocMain, allocTemp);\n  IAlloc_Free(allocTemp, unpackSizes);\n  IAlloc_Free(allocTemp, digestsDefined);\n  IAlloc_Free(allocTemp, digests);\n  IAlloc_Free(allocTemp, emptyStreamVector);\n  IAlloc_Free(allocTemp, emptyFileVector);\n  IAlloc_Free(allocTemp, lwtVector);\n  return res;\n}\n\nstatic SRes SzReadAndDecodePackedStreams2(\n    ILookInStream *inStream,\n    CSzData *sd,\n    CBuf *outBuffer,\n    UInt64 baseOffset,\n    CSzAr *p,\n    UInt64 **unpackSizes,\n    Byte **digestsDefined,\n    UInt32 **digests,\n    ISzAlloc *allocTemp)\n{\n\n  UInt32 numUnpackStreams = 0;\n  UInt64 dataStartPos;\n  CSzFolder *folder;\n  UInt64 unpackSize;\n  SRes res;\n\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,\n      &numUnpackStreams,  unpackSizes, digestsDefined, digests,\n      allocTemp, allocTemp));\n  \n  dataStartPos += baseOffset;\n  if (p->NumFolders != 1)\n    return SZ_ERROR_ARCHIVE;\n\n  folder = p->Folders;\n  unpackSize = SzFolder_GetUnpackSize(folder);\n  \n  RINOK(LookInStream_SeekTo(inStream, dataStartPos));\n\n  if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))\n    return SZ_ERROR_MEM;\n  \n  res = SzDecode(p->PackSizes, folder,\n          inStream, dataStartPos,\n          outBuffer->data, (size_t)unpackSize, allocTemp);\n  RINOK(res);\n  if (folder->UnpackCRCDefined)\n    if (CrcCalc(outBuffer->data, (size_t)unpackSize) != folder->UnpackCRC)\n      return SZ_ERROR_CRC;\n  return SZ_OK;\n}\n\nstatic SRes SzReadAndDecodePackedStreams(\n    ILookInStream *inStream,\n    CSzData *sd,\n    CBuf *outBuffer,\n    UInt64 baseOffset,\n    ISzAlloc *allocTemp)\n{\n  CSzAr p;\n  UInt64 *unpackSizes = 0;\n  Byte *digestsDefined = 0;\n  UInt32 *digests = 0;\n  SRes res;\n  SzAr_Init(&p);\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,\n    &p, &unpackSizes, &digestsDefined, &digests,\n    allocTemp);\n  SzAr_Free(&p, allocTemp);\n  IAlloc_Free(allocTemp, unpackSizes);\n  IAlloc_Free(allocTemp, digestsDefined);\n  IAlloc_Free(allocTemp, digests);\n  return res;\n}\n\nstatic SRes SzArEx_Open2(\n    CSzArEx *p,\n    ILookInStream *inStream,\n    ISzAlloc *allocMain,\n    ISzAlloc *allocTemp)\n{\n  Byte header[k7zStartHeaderSize];\n  UInt64 nextHeaderOffset, nextHeaderSize;\n  size_t nextHeaderSizeT;\n  UInt32 nextHeaderCRC;\n  CBuf buffer;\n  SRes res;\n\n  RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));\n\n  if (!TestSignatureCandidate(header))\n    return SZ_ERROR_NO_ARCHIVE;\n  if (header[6] != k7zMajorVersion)\n    return SZ_ERROR_UNSUPPORTED;\n\n  nextHeaderOffset = GetUi64(header + 12);\n  nextHeaderSize = GetUi64(header + 20);\n  nextHeaderCRC = GetUi32(header + 28);\n\n  p->startPosAfterHeader = k7zStartHeaderSize;\n  \n  if (CrcCalc(header + 12, 20) != GetUi32(header + 8))\n    return SZ_ERROR_CRC;\n\n  nextHeaderSizeT = (size_t)nextHeaderSize;\n  if (nextHeaderSizeT != nextHeaderSize)\n    return SZ_ERROR_MEM;\n  if (nextHeaderSizeT == 0)\n    return SZ_OK;\n  if (nextHeaderOffset > nextHeaderOffset + nextHeaderSize ||\n      nextHeaderOffset > nextHeaderOffset + nextHeaderSize + k7zStartHeaderSize)\n    return SZ_ERROR_NO_ARCHIVE;\n\n  {\n    Int64 pos = 0;\n    RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));\n    if ((UInt64)pos < nextHeaderOffset ||\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset ||\n        (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)\n      return SZ_ERROR_INPUT_EOF;\n  }\n\n  RINOK(LookInStream_SeekTo(inStream, k7zStartHeaderSize + nextHeaderOffset));\n\n  if (!Buf_Create(&buffer, nextHeaderSizeT, allocTemp))\n    return SZ_ERROR_MEM;\n\n  res = LookInStream_Read(inStream, buffer.data, nextHeaderSizeT);\n  if (res == SZ_OK)\n  {\n    res = SZ_ERROR_ARCHIVE;\n    if (CrcCalc(buffer.data, nextHeaderSizeT) == nextHeaderCRC)\n    {\n      CSzData sd;\n      UInt64 type;\n      sd.Data = buffer.data;\n      sd.Size = buffer.size;\n      res = SzReadID(&sd, &type);\n      if (res == SZ_OK)\n      {\n        if (type == k7zIdEncodedHeader)\n        {\n          CBuf outBuffer;\n          Buf_Init(&outBuffer);\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, p->startPosAfterHeader, allocTemp);\n          if (res != SZ_OK)\n            Buf_Free(&outBuffer, allocTemp);\n          else\n          {\n            Buf_Free(&buffer, allocTemp);\n            buffer.data = outBuffer.data;\n            buffer.size = outBuffer.size;\n            sd.Data = buffer.data;\n            sd.Size = buffer.size;\n            res = SzReadID(&sd, &type);\n          }\n        }\n      }\n      if (res == SZ_OK)\n      {\n        if (type == k7zIdHeader)\n          res = SzReadHeader(p, &sd, allocMain, allocTemp);\n        else\n          res = SZ_ERROR_UNSUPPORTED;\n      }\n    }\n  }\n  Buf_Free(&buffer, allocTemp);\n  return res;\n}\n\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)\n{\n  SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);\n  if (res != SZ_OK)\n    SzArEx_Free(p, allocMain);\n  return res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zIn.h",
    "content": "/* 7zIn.h -- 7z Input functions\n2008-11-23 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_IN_H\n#define __7Z_IN_H\n\n#include \"7zHeader.h\"\n#include \"7zItem.h\"\n\ntypedef struct\n{\n  CSzAr db;\n  \n  UInt64 startPosAfterHeader;\n  UInt64 dataPos;\n\n  UInt32 *FolderStartPackStreamIndex;\n  UInt64 *PackStreamStartPositions;\n  UInt32 *FolderStartFileIndex;\n  UInt32 *FileIndexToFolderIndexMap;\n} CSzArEx;\n\nvoid SzArEx_Init(CSzArEx *p);\nvoid SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);\nUInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);\nint SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);\n\n/*\nErrors:\nSZ_ERROR_NO_ARCHIVE\nSZ_ERROR_ARCHIVE\nSZ_ERROR_UNSUPPORTED\nSZ_ERROR_MEM\nSZ_ERROR_CRC\nSZ_ERROR_INPUT_EOF\nSZ_ERROR_FAIL\n*/\n\nSRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);\n \n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zItem.c",
    "content": "/* 7zItem.c -- 7z Items\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include \"7zItem.h\"\n\nvoid SzCoderInfo_Init(CSzCoderInfo *p)\n{\n  Buf_Init(&p->Props);\n}\n\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc)\n{\n  Buf_Free(&p->Props, alloc);\n  SzCoderInfo_Init(p);\n}\n\nvoid SzFolder_Init(CSzFolder *p)\n{\n  p->Coders = 0;\n  p->BindPairs = 0;\n  p->PackStreams = 0;\n  p->UnpackSizes = 0;\n  p->NumCoders = 0;\n  p->NumBindPairs = 0;\n  p->NumPackStreams = 0;\n  p->UnpackCRCDefined = 0;\n  p->UnpackCRC = 0;\n  p->NumUnpackStreams = 0;\n}\n\nvoid SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)\n{\n  UInt32 i;\n  if (p->Coders)\n    for (i = 0; i < p->NumCoders; i++)\n      SzCoderInfo_Free(&p->Coders[i], alloc);\n  IAlloc_Free(alloc, p->Coders);\n  IAlloc_Free(alloc, p->BindPairs);\n  IAlloc_Free(alloc, p->PackStreams);\n  IAlloc_Free(alloc, p->UnpackSizes);\n  SzFolder_Init(p);\n}\n\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p)\n{\n  UInt32 result = 0;\n  UInt32 i;\n  for (i = 0; i < p->NumCoders; i++)\n    result += p->Coders[i].NumOutStreams;\n  return result;\n}\n\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex)\n{\n  UInt32 i;\n  for (i = 0; i < p->NumBindPairs; i++)\n    if (p->BindPairs[i].InIndex == inStreamIndex)\n      return i;\n  return -1;\n}\n\n\nint SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)\n{\n  UInt32 i;\n  for (i = 0; i < p->NumBindPairs; i++)\n    if (p->BindPairs[i].OutIndex == outStreamIndex)\n      return i;\n  return -1;\n}\n\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p)\n{\n  int i = (int)SzFolder_GetNumOutStreams(p);\n  if (i == 0)\n    return 0;\n  for (i--; i >= 0; i--)\n    if (SzFolder_FindBindPairForOutStream(p, i) < 0)\n      return p->UnpackSizes[i];\n  /* throw 1; */\n  return 0;\n}\n\nvoid SzFile_Init(CSzFileItem *p)\n{\n  p->HasStream = 1;\n  p->IsDir = 0;\n  p->IsAnti = 0;\n  p->FileCRCDefined = 0;\n  p->MTimeDefined = 0;\n  p->Name = 0;\n}\n\nstatic void SzFile_Free(CSzFileItem *p, ISzAlloc *alloc)\n{\n  IAlloc_Free(alloc, p->Name);\n  SzFile_Init(p);\n}\n\nvoid SzAr_Init(CSzAr *p)\n{\n  p->PackSizes = 0;\n  p->PackCRCsDefined = 0;\n  p->PackCRCs = 0;\n  p->Folders = 0;\n  p->Files = 0;\n  p->NumPackStreams = 0;\n  p->NumFolders = 0;\n  p->NumFiles = 0;\n}\n\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc)\n{\n  UInt32 i;\n  if (p->Folders)\n    for (i = 0; i < p->NumFolders; i++)\n      SzFolder_Free(&p->Folders[i], alloc);\n  if (p->Files)\n    for (i = 0; i < p->NumFiles; i++)\n      SzFile_Free(&p->Files[i], alloc);\n  IAlloc_Free(alloc, p->PackSizes);\n  IAlloc_Free(alloc, p->PackCRCsDefined);\n  IAlloc_Free(alloc, p->PackCRCs);\n  IAlloc_Free(alloc, p->Folders);\n  IAlloc_Free(alloc, p->Files);\n  SzAr_Init(p);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zItem.h",
    "content": "/* 7zItem.h -- 7z Items\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_ITEM_H\n#define __7Z_ITEM_H\n\n#include \"../../7zBuf.h\"\n\ntypedef struct\n{\n  UInt32 NumInStreams;\n  UInt32 NumOutStreams;\n  UInt64 MethodID;\n  CBuf Props;\n} CSzCoderInfo;\n\nvoid SzCoderInfo_Init(CSzCoderInfo *p);\nvoid SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc);\n\ntypedef struct\n{\n  UInt32 InIndex;\n  UInt32 OutIndex;\n} CBindPair;\n\ntypedef struct\n{\n  CSzCoderInfo *Coders;\n  CBindPair *BindPairs;\n  UInt32 *PackStreams;\n  UInt64 *UnpackSizes;\n  UInt32 NumCoders;\n  UInt32 NumBindPairs;\n  UInt32 NumPackStreams;\n  int UnpackCRCDefined;\n  UInt32 UnpackCRC;\n\n  UInt32 NumUnpackStreams;\n} CSzFolder;\n\nvoid SzFolder_Init(CSzFolder *p);\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\nint SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);\nUInt32 SzFolder_GetNumOutStreams(CSzFolder *p);\nUInt64 SzFolder_GetUnpackSize(CSzFolder *p);\n\ntypedef struct\n{\n  UInt32 Low;\n  UInt32 High;\n} CNtfsFileTime;\n\ntypedef struct\n{\n  CNtfsFileTime MTime;\n  UInt64 Size;\n  char *Name;\n  UInt32 FileCRC;\n\n  Byte HasStream;\n  Byte IsDir;\n  Byte IsAnti;\n  Byte FileCRCDefined;\n  Byte MTimeDefined;\n} CSzFileItem;\n\nvoid SzFile_Init(CSzFileItem *p);\n\ntypedef struct\n{\n  UInt64 *PackSizes;\n  Byte *PackCRCsDefined;\n  UInt32 *PackCRCs;\n  CSzFolder *Folders;\n  CSzFileItem *Files;\n  UInt32 NumPackStreams;\n  UInt32 NumFolders;\n  UInt32 NumFiles;\n} CSzAr;\n\nvoid SzAr_Init(CSzAr *p);\nvoid SzAr_Free(CSzAr *p, ISzAlloc *alloc);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/7zMain.c",
    "content": "/* 7zMain.c - Test application for 7z Decoder\n2008-11-23 : Igor Pavlov : Public domain */\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n#include \"../../7zCrc.h\"\n#include \"../../7zFile.h\"\n#include \"../../7zVersion.h\"\n\n#include \"7zAlloc.h\"\n#include \"7zExtract.h\"\n#include \"7zIn.h\"\n\nstatic void ConvertNumberToString(UInt64 value, char *s)\n{\n  char temp[32];\n  int pos = 0;\n  do\n  {\n    temp[pos++] = (char)('0' + (int)(value % 10));\n    value /= 10;\n  }\n  while (value != 0);\n  do\n    *s++ = temp[--pos];\n  while (pos > 0);\n  *s = '\\0';\n}\n\n#define PERIOD_4 (4 * 365 + 1)\n#define PERIOD_100 (PERIOD_4 * 25 - 1)\n#define PERIOD_400 (PERIOD_100 * 4 + 1)\n\nstatic void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)\n{\n  unsigned year, mon, day, hour, min, sec;\n  UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n  unsigned temp;\n  UInt32 v;\n  v64 /= 10000000;\n  sec = (unsigned)(v64 % 60);\n  v64 /= 60;\n  min = (unsigned)(v64 % 60);\n  v64 /= 60;\n  hour = (unsigned)(v64 % 24);\n  v64 /= 24;\n\n  v = (UInt32)v64;\n\n  year = (unsigned)(1601 + v / PERIOD_400 * 400);\n  v %= PERIOD_400;\n\n  temp = (unsigned)(v / PERIOD_100);\n  if (temp == 4)\n    temp = 3;\n  year += temp * 100;\n  v -= temp * PERIOD_100;\n\n  temp = v / PERIOD_4;\n  if (temp == 25)\n    temp = 24;\n  year += temp * 4;\n  v -= temp * PERIOD_4;\n\n  temp = v / 365;\n  if (temp == 4)\n    temp = 3;\n  year += temp;\n  v -= temp * 365;\n\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\n    ms[1] = 29;\n  for (mon = 1; mon <= 12; mon++)\n  {\n    unsigned s = ms[mon - 1];\n    if (v < s)\n      break;\n    v -= s;\n  }\n  day = (unsigned)v + 1;\n  sprintf(s, \"%04d-%02d-%02d %02d:%02d:%02d\", year, mon, day, hour, min, sec);\n}\n\nvoid PrintError(char *sz)\n{\n  printf(\"\\nERROR: %s\\n\", sz);\n}\n\nint MY_CDECL main(int numargs, char *args[])\n{\n  CFileInStream archiveStream;\n  CLookToRead lookStream;\n  CSzArEx db;\n  SRes res;\n  ISzAlloc allocImp;\n  ISzAlloc allocTempImp;\n\n  printf(\"\\n7z ANSI-C Decoder \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\n  if (numargs == 1)\n  {\n    printf(\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\n      \"<Commands>\\n\"\n      \"  e: Extract files from archive\\n\"\n      \"  l: List contents of archive\\n\"\n      \"  t: Test integrity of archive\\n\");\n    return 0;\n  }\n  if (numargs < 3)\n  {\n    PrintError(\"incorrect command\");\n    return 1;\n  }\n\n  if (InFile_Open(&archiveStream.file, args[2]))\n  {\n    PrintError(\"can not open input file\");\n    return 1;\n  }\n\n  \n  FileInStream_CreateVTable(&archiveStream);\n  LookToRead_CreateVTable(&lookStream, False);\n  \n  lookStream.realStream = &archiveStream.s;\n  LookToRead_Init(&lookStream);\n\n  allocImp.Alloc = SzAlloc;\n  allocImp.Free = SzFree;\n\n  allocTempImp.Alloc = SzAllocTemp;\n  allocTempImp.Free = SzFreeTemp;\n\n  CrcGenerateTable();\n\n  SzArEx_Init(&db);\n  res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);\n  if (res == SZ_OK)\n  {\n    char *command = args[1];\n    int listCommand = 0, testCommand = 0, extractCommand = 0;\n    if (strcmp(command, \"l\") == 0) listCommand = 1;\n    else if (strcmp(command, \"t\") == 0) testCommand = 1;\n    else if (strcmp(command, \"e\") == 0) extractCommand = 1;\n\n    if (listCommand)\n    {\n      UInt32 i;\n      for (i = 0; i < db.db.NumFiles; i++)\n      {\n        CSzFileItem *f = db.db.Files + i;\n        char s[32], t[32];\n        ConvertNumberToString(f->Size, s);\n        if (f->MTimeDefined)\n          ConvertFileTimeToString(&f->MTime, t);\n        else\n          strcpy(t, \"                   \");\n\n        printf(\"%s %10s  %s\\n\", t, s, f->Name);\n      }\n    }\n    else if (testCommand || extractCommand)\n    {\n      UInt32 i;\n\n      /*\n      if you need cache, use these 3 variables.\n      if you use external function, you can make these variable as static.\n      */\n      UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */\n      Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */\n      size_t outBufferSize = 0;  /* it can have any value before first call (if outBuffer = 0) */\n\n      printf(\"\\n\");\n      for (i = 0; i < db.db.NumFiles; i++)\n      {\n        size_t offset;\n        size_t outSizeProcessed;\n        CSzFileItem *f = db.db.Files + i;\n        if (f->IsDir)\n          printf(\"Directory \");\n        else\n          printf(testCommand ?\n            \"Testing   \":\n            \"Extracting\");\n        printf(\" %s\", f->Name);\n        if (f->IsDir)\n        {\n          printf(\"\\n\");\n          continue;\n        }\n        res = SzAr_Extract(&db, &lookStream.s, i,\n            &blockIndex, &outBuffer, &outBufferSize,\n            &offset, &outSizeProcessed,\n            &allocImp, &allocTempImp);\n        if (res != SZ_OK)\n          break;\n        if (!testCommand)\n        {\n          CSzFile outFile;\n          size_t processedSize;\n          char *fileName = f->Name;\n          size_t nameLen = strlen(f->Name);\n          for (; nameLen > 0; nameLen--)\n            if (f->Name[nameLen - 1] == '/')\n            {\n              fileName = f->Name + nameLen;\n              break;\n            }\n            \n          if (OutFile_Open(&outFile, fileName))\n          {\n            PrintError(\"can not open output file\");\n            res = SZ_ERROR_FAIL;\n            break;\n          }\n          processedSize = outSizeProcessed;\n          if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 ||\n              processedSize != outSizeProcessed)\n          {\n            PrintError(\"can not write output file\");\n            res = SZ_ERROR_FAIL;\n            break;\n          }\n          if (File_Close(&outFile))\n          {\n            PrintError(\"can not close output file\");\n            res = SZ_ERROR_FAIL;\n            break;\n          }\n        }\n        printf(\"\\n\");\n      }\n      IAlloc_Free(&allocImp, outBuffer);\n    }\n    else\n    {\n      PrintError(\"incorrect command\");\n      res = SZ_ERROR_FAIL;\n    }\n  }\n  SzArEx_Free(&db, &allocImp);\n\n  File_Close(&archiveStream.file);\n  if (res == SZ_OK)\n  {\n    printf(\"\\nEverything is Ok\\n\");\n    return 0;\n  }\n  if (res == SZ_ERROR_UNSUPPORTED)\n    PrintError(\"decoder doesn't support this archive\");\n  else if (res == SZ_ERROR_MEM)\n    PrintError(\"can not allocate memory\");\n  else if (res == SZ_ERROR_CRC)\n    PrintError(\"CRC error\");\n  else\n    printf(\"\\nERROR #%d\\n\", res);\n  return 1;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/makefile",
    "content": "MY_STATIC_LINK=1\n\nPROG = 7zDec.exe\n\nC_OBJS = \\\n  $O\\7zBuf.obj \\\n  $O\\7zBuf2.obj \\\n  $O\\7zCrc.obj \\\n  $O\\LzmaDec.obj \\\n  $O\\Bra86.obj \\\n  $O\\Bcj2.obj \\\n  $O\\7zFile.obj \\\n  $O\\7zStream.obj \\\n\n7Z_OBJS = \\\n  $O\\7zAlloc.obj \\\n  $O\\7zDecode.obj \\\n  $O\\7zExtract.obj \\\n  $O\\7zHeader.obj \\\n  $O\\7zIn.obj \\\n  $O\\7zItem.obj \\\n  $O\\7zMain.obj \\\n\nOBJS = \\\n  $(7Z_OBJS) \\\n  $(C_OBJS) \\\n\n!include \"../../../CPP/Build.mak\"\n\n$(7Z_OBJS): $(*B).c\n\t$(COMPL_O1)\n$(C_OBJS): ../../$(*B).c\n\t$(COMPL_O2)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Archive/7z/makefile.gcc",
    "content": "PROG = 7zDec\nCXX = g++\nLIB =\nRM = rm -f\nCFLAGS = -c -O2 -Wall\n\nOBJS = 7zAlloc.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o 7zFile.o 7zStream.o\n\nall: $(PROG)\n\n$(PROG): $(OBJS)\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\n\n7zAlloc.o: 7zAlloc.c\n\t$(CXX) $(CFLAGS) 7zAlloc.c\n\n7zBuf.o: ../../7zBuf.c\n\t$(CXX) $(CFLAGS) ../../7zBuf.c\n\n7zBuf2.o: ../../7zBuf2.c\n\t$(CXX) $(CFLAGS) ../../7zBuf2.c\n\n7zCrc.o: ../../7zCrc.c\n\t$(CXX) $(CFLAGS) ../../7zCrc.c\n\n7zDecode.o: 7zDecode.c\n\t$(CXX) $(CFLAGS) 7zDecode.c\n\n7zExtract.o: 7zExtract.c\n\t$(CXX) $(CFLAGS) 7zExtract.c\n\n7zHeader.o: 7zHeader.c\n\t$(CXX) $(CFLAGS) 7zHeader.c\n\n7zIn.o: 7zIn.c\n\t$(CXX) $(CFLAGS) 7zIn.c\n\n7zItem.o: 7zItem.c\n\t$(CXX) $(CFLAGS) 7zItem.c\n\n7zMain.o: 7zMain.c\n\t$(CXX) $(CFLAGS) 7zMain.c\n\nLzmaDec.o: ../../LzmaDec.c\n\t$(CXX) $(CFLAGS) ../../LzmaDec.c\n\nBra86.o: ../../Bra86.c\n\t$(CXX) $(CFLAGS) ../../Bra86.c\n\nBcj2.o: ../../Bcj2.c\n\t$(CXX) $(CFLAGS) ../../Bcj2.c\n\n7zFile.o: ../../7zFile.c\n\t$(CXX) $(CFLAGS) ../../7zFile.c\n\n7zStream.o: ../../7zStream.c\n\t$(CXX) $(CFLAGS) ../../7zStream.c\n\nclean:\n\t-$(RM) $(PROG) $(OBJS)\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Bcj2.c",
    "content": "/* Bcj2.c -- Converter for x86 code (BCJ2)\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include \"Bcj2.h\"\n\n#ifdef _LZMA_PROB32\n#define CProb UInt32\n#else\n#define CProb UInt16\n#endif\n\n#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)\n#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))\n\n#define kNumTopBits 24\n#define kTopValue ((UInt32)1 << kNumTopBits)\n\n#define kNumBitModelTotalBits 11\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\n#define kNumMoveBits 5\n\n#define RC_READ_BYTE (*buffer++)\n#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }\n#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \\\n  { int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }}\n\n#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }\n\n#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\n#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;\n\nint Bcj2_Decode(\n    const Byte *buf0, SizeT size0,\n    const Byte *buf1, SizeT size1,\n    const Byte *buf2, SizeT size2,\n    const Byte *buf3, SizeT size3,\n    Byte *outBuf, SizeT outSize)\n{\n  CProb p[256 + 2];\n  SizeT inPos = 0, outPos = 0;\n\n  const Byte *buffer, *bufferLim;\n  UInt32 range, code;\n  Byte prevByte = 0;\n\n  unsigned int i;\n  for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)\n    p[i] = kBitModelTotal >> 1;\n\n  buffer = buf3;\n  bufferLim = buffer + size3;\n  RC_INIT2\n\n  if (outSize == 0)\n    return SZ_OK;\n\n  for (;;)\n  {\n    Byte b;\n    CProb *prob;\n    UInt32 bound;\n    UInt32 ttt;\n\n    SizeT limit = size0 - inPos;\n    if (outSize - outPos < limit)\n      limit = outSize - outPos;\n    while (limit != 0)\n    {\n      Byte b = buf0[inPos];\n      outBuf[outPos++] = b;\n      if (IsJ(prevByte, b))\n        break;\n      inPos++;\n      prevByte = b;\n      limit--;\n    }\n\n    if (limit == 0 || outPos == outSize)\n      break;\n\n    b = buf0[inPos++];\n\n    if (b == 0xE8)\n      prob = p + prevByte;\n    else if (b == 0xE9)\n      prob = p + 256;\n    else\n      prob = p + 257;\n\n    IF_BIT_0(prob)\n    {\n      UPDATE_0(prob)\n      prevByte = b;\n    }\n    else\n    {\n      UInt32 dest;\n      const Byte *v;\n      UPDATE_1(prob)\n      if (b == 0xE8)\n      {\n        v = buf1;\n        if (size1 < 4)\n          return SZ_ERROR_DATA;\n        buf1 += 4;\n        size1 -= 4;\n      }\n      else\n      {\n        v = buf2;\n        if (size2 < 4)\n          return SZ_ERROR_DATA;\n        buf2 += 4;\n        size2 -= 4;\n      }\n      dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |\n          ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);\n      outBuf[outPos++] = (Byte)dest;\n      if (outPos == outSize)\n        break;\n      outBuf[outPos++] = (Byte)(dest >> 8);\n      if (outPos == outSize)\n        break;\n      outBuf[outPos++] = (Byte)(dest >> 16);\n      if (outPos == outSize)\n        break;\n      outBuf[outPos++] = prevByte = (Byte)(dest >> 24);\n    }\n  }\n  return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Bcj2.h",
    "content": "/* Bcj2.h -- Converter for x86 code (BCJ2)\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __BCJ2_H\n#define __BCJ2_H\n\n#include \"Types.h\"\n\n/*\nConditions:\n  outSize <= FullOutputSize,\n  where FullOutputSize is full size of output stream of x86_2 filter.\n\nIf buf0 overlaps outBuf, there are two required conditions:\n  1) (buf0 >= outBuf)\n  2) (buf0 + size0 >= outBuf + FullOutputSize).\n\nReturns:\n  SZ_OK\n  SZ_ERROR_DATA - Data error\n*/\n\nint Bcj2_Decode(\n    const Byte *buf0, SizeT size0,\n    const Byte *buf1, SizeT size1,\n    const Byte *buf2, SizeT size2,\n    const Byte *buf3, SizeT size3,\n    Byte *outBuf, SizeT outSize);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Bra.c",
    "content": "/* Bra.c -- Converters for RISC code\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include \"Bra.h\"\n\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\n{\n  SizeT i;\n  if (size < 4)\n    return 0;\n  size -= 4;\n  ip += 8;\n  for (i = 0; i <= size; i += 4)\n  {\n    if (data[i + 3] == 0xEB)\n    {\n      UInt32 dest;\n      UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);\n      src <<= 2;\n      if (encoding)\n        dest = ip + (UInt32)i + src;\n      else\n        dest = src - (ip + (UInt32)i);\n      dest >>= 2;\n      data[i + 2] = (Byte)(dest >> 16);\n      data[i + 1] = (Byte)(dest >> 8);\n      data[i + 0] = (Byte)dest;\n    }\n  }\n  return i;\n}\n\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\n{\n  SizeT i;\n  if (size < 4)\n    return 0;\n  size -= 4;\n  ip += 4;\n  for (i = 0; i <= size; i += 2)\n  {\n    if ((data[i + 1] & 0xF8) == 0xF0 &&\n        (data[i + 3] & 0xF8) == 0xF8)\n    {\n      UInt32 dest;\n      UInt32 src =\n        (((UInt32)data[i + 1] & 0x7) << 19) |\n        ((UInt32)data[i + 0] << 11) |\n        (((UInt32)data[i + 3] & 0x7) << 8) |\n        (data[i + 2]);\n      \n      src <<= 1;\n      if (encoding)\n        dest = ip + (UInt32)i + src;\n      else\n        dest = src - (ip + (UInt32)i);\n      dest >>= 1;\n      \n      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));\n      data[i + 0] = (Byte)(dest >> 11);\n      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));\n      data[i + 2] = (Byte)dest;\n      i += 2;\n    }\n  }\n  return i;\n}\n\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\n{\n  SizeT i;\n  if (size < 4)\n    return 0;\n  size -= 4;\n  for (i = 0; i <= size; i += 4)\n  {\n    if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)\n    {\n      UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |\n        ((UInt32)data[i + 1] << 16) |\n        ((UInt32)data[i + 2] << 8) |\n        ((UInt32)data[i + 3] & (~3));\n      \n      UInt32 dest;\n      if (encoding)\n        dest = ip + (UInt32)i + src;\n      else\n        dest = src - (ip + (UInt32)i);\n      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));\n      data[i + 1] = (Byte)(dest >> 16);\n      data[i + 2] = (Byte)(dest >> 8);\n      data[i + 3] &= 0x3;\n      data[i + 3] |= dest;\n    }\n  }\n  return i;\n}\n\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\n{\n  UInt32 i;\n  if (size < 4)\n    return 0;\n  size -= 4;\n  for (i = 0; i <= size; i += 4)\n  {\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\n    {\n      UInt32 src =\n        ((UInt32)data[i + 0] << 24) |\n        ((UInt32)data[i + 1] << 16) |\n        ((UInt32)data[i + 2] << 8) |\n        ((UInt32)data[i + 3]);\n      UInt32 dest;\n      \n      src <<= 2;\n      if (encoding)\n        dest = ip + i + src;\n      else\n        dest = src - (ip + i);\n      dest >>= 2;\n      \n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\n\n      data[i + 0] = (Byte)(dest >> 24);\n      data[i + 1] = (Byte)(dest >> 16);\n      data[i + 2] = (Byte)(dest >> 8);\n      data[i + 3] = (Byte)dest;\n    }\n  }\n  return i;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Bra.h",
    "content": "/* Bra.h -- Branch converters for executables\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __BRA_H\n#define __BRA_H\n\n#include \"Types.h\"\n\n/*\nThese functions convert relative addresses to absolute addresses\nin CALL instructions to increase the compression ratio.\n  \n  In:\n    data     - data buffer\n    size     - size of data\n    ip       - current virtual Instruction Pinter (IP) value\n    state    - state variable for x86 converter\n    encoding - 0 (for decoding), 1 (for encoding)\n  \n  Out:\n    state    - state variable for x86 converter\n\n  Returns:\n    The number of processed bytes. If you call these functions with multiple calls,\n    you must start next call with first byte after block of processed bytes.\n  \n  Type   Endian  Alignment  LookAhead\n  \n  x86    little      1          4\n  ARMT   little      2          2\n  ARM    little      4          0\n  PPC     big        4          0\n  SPARC   big        4          0\n  IA64   little     16          0\n\n  size must be >= Alignment + LookAhead, if it's not last block.\n  If (size < Alignment + LookAhead), converter returns 0.\n\n  Example:\n\n    UInt32 ip = 0;\n    for ()\n    {\n      ; size must be >= Alignment + LookAhead, if it's not last block\n      SizeT processed = Convert(data, size, ip, 1);\n      data += processed;\n      size -= processed;\n      ip += processed;\n    }\n*/\n\n#define x86_Convert_Init(state) { state = 0; }\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);\nSizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\nSizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\nSizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\nSizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Bra86.c",
    "content": "/* Bra86.c -- Converter for x86 code (BCJ)\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include \"Bra.h\"\n\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\n\nconst Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\n\nSizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)\n{\n  SizeT bufferPos = 0, prevPosT;\n  UInt32 prevMask = *state & 0x7;\n  if (size < 5)\n    return 0;\n  ip += 5;\n  prevPosT = (SizeT)0 - 1;\n\n  for (;;)\n  {\n    Byte *p = data + bufferPos;\n    Byte *limit = data + size - 4;\n    for (; p < limit; p++)\n      if ((*p & 0xFE) == 0xE8)\n        break;\n    bufferPos = (SizeT)(p - data);\n    if (p >= limit)\n      break;\n    prevPosT = bufferPos - prevPosT;\n    if (prevPosT > 3)\n      prevMask = 0;\n    else\n    {\n      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\n      if (prevMask != 0)\n      {\n        Byte b = p[4 - kMaskToBitNumber[prevMask]];\n        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\n        {\n          prevPosT = bufferPos;\n          prevMask = ((prevMask << 1) & 0x7) | 1;\n          bufferPos++;\n          continue;\n        }\n      }\n    }\n    prevPosT = bufferPos;\n\n    if (Test86MSByte(p[4]))\n    {\n      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\n      UInt32 dest;\n      for (;;)\n      {\n        Byte b;\n        int index;\n        if (encoding)\n          dest = (ip + (UInt32)bufferPos) + src;\n        else\n          dest = src - (ip + (UInt32)bufferPos);\n        if (prevMask == 0)\n          break;\n        index = kMaskToBitNumber[prevMask] * 8;\n        b = (Byte)(dest >> (24 - index));\n        if (!Test86MSByte(b))\n          break;\n        src = dest ^ ((1 << (32 - index)) - 1);\n      }\n      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\n      p[3] = (Byte)(dest >> 16);\n      p[2] = (Byte)(dest >> 8);\n      p[1] = (Byte)dest;\n      bufferPos += 5;\n    }\n    else\n    {\n      prevMask = ((prevMask << 1) & 0x7) | 1;\n      bufferPos++;\n    }\n  }\n  prevPosT = bufferPos - prevPosT;\n  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\n  return bufferPos;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/BraIA64.c",
    "content": "/* BraIA64.c -- Converter for IA-64 code\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include \"Bra.h\"\n\nstatic const Byte kBranchTable[32] =\n{\n  0, 0, 0, 0, 0, 0, 0, 0,\n  0, 0, 0, 0, 0, 0, 0, 0,\n  4, 4, 6, 6, 0, 0, 7, 7,\n  4, 4, 0, 0, 4, 4, 0, 0\n};\n\nSizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)\n{\n  SizeT i;\n  if (size < 16)\n    return 0;\n  size -= 16;\n  for (i = 0; i <= size; i += 16)\n  {\n    UInt32 instrTemplate = data[i] & 0x1F;\n    UInt32 mask = kBranchTable[instrTemplate];\n    UInt32 bitPos = 5;\n    int slot;\n    for (slot = 0; slot < 3; slot++, bitPos += 41)\n    {\n      UInt32 bytePos, bitRes;\n      UInt64 instruction, instNorm;\n      int j;\n      if (((mask >> slot) & 1) == 0)\n        continue;\n      bytePos = (bitPos >> 3);\n      bitRes = bitPos & 0x7;\n      instruction = 0;\n      for (j = 0; j < 6; j++)\n        instruction += (UInt64)data[i + j + bytePos] << (8 * j);\n\n      instNorm = instruction >> bitRes;\n      if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)\n      {\n        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);\n        UInt32 dest;\n        src |= ((UInt32)(instNorm >> 36) & 1) << 20;\n        \n        src <<= 4;\n        \n        if (encoding)\n          dest = ip + (UInt32)i + src;\n        else\n          dest = src - (ip + (UInt32)i);\n        \n        dest >>= 4;\n        \n        instNorm &= ~((UInt64)(0x8FFFFF) << 13);\n        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);\n        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));\n        \n        instruction &= (1 << bitRes) - 1;\n        instruction |= (instNorm << bitRes);\n        for (j = 0; j < 6; j++)\n          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));\n      }\n    }\n  }\n  return i;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/CpuArch.h",
    "content": "/* CpuArch.h\n2008-08-05\nIgor Pavlov\nPublic domain */\n\n#ifndef __CPUARCH_H\n#define __CPUARCH_H\n\n/*\nLITTLE_ENDIAN_UNALIGN means:\n  1) CPU is LITTLE_ENDIAN\n  2) it's allowed to make unaligned memory accesses\nif LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know\nabout these properties of platform.\n*/\n\n#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\n#define LITTLE_ENDIAN_UNALIGN\n#endif\n\n#ifdef LITTLE_ENDIAN_UNALIGN\n\n#define GetUi16(p) (*(const UInt16 *)(p))\n#define GetUi32(p) (*(const UInt32 *)(p))\n#define GetUi64(p) (*(const UInt64 *)(p))\n#define SetUi32(p, d) *(UInt32 *)(p) = (d);\n\n#else\n\n#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))\n\n#define GetUi32(p) ( \\\n             ((const Byte *)(p))[0]        | \\\n    ((UInt32)((const Byte *)(p))[1] <<  8) | \\\n    ((UInt32)((const Byte *)(p))[2] << 16) | \\\n    ((UInt32)((const Byte *)(p))[3] << 24))\n\n#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))\n\n#define SetUi32(p, d) { UInt32 _x_ = (d); \\\n    ((Byte *)(p))[0] = (Byte)_x_; \\\n    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \\\n    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \\\n    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }\n\n#endif\n\n#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)\n\n#pragma intrinsic(_byteswap_ulong)\n#pragma intrinsic(_byteswap_uint64)\n#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))\n#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))\n\n#else\n\n#define GetBe32(p) ( \\\n    ((UInt32)((const Byte *)(p))[0] << 24) | \\\n    ((UInt32)((const Byte *)(p))[1] << 16) | \\\n    ((UInt32)((const Byte *)(p))[2] <<  8) | \\\n             ((const Byte *)(p))[3] )\n\n#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))\n\n#endif\n\n#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzFind.c",
    "content": "/* LzFind.c -- Match finder for LZ algorithms\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include <string.h>\n\n#include \"LzFind.h\"\n#include \"LzHash.h\"\n\n#define kEmptyHashValue 0\n#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\n#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\n#define kNormalizeMask (~(kNormalizeStepMin - 1))\n#define kMaxHistorySize ((UInt32)3 << 30)\n\n#define kStartMaxLen 3\n\nstatic void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)\n{\n  if (!p->directInput)\n  {\n    alloc->Free(alloc, p->bufferBase);\n    p->bufferBase = 0;\n  }\n}\n\n/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */\n\nstatic int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)\n{\n  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;\n  if (p->directInput)\n  {\n    p->blockSize = blockSize;\n    return 1;\n  }\n  if (p->bufferBase == 0 || p->blockSize != blockSize)\n  {\n    LzInWindow_Free(p, alloc);\n    p->blockSize = blockSize;\n    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\n  }\n  return (p->bufferBase != 0);\n}\n\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\nByte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\n\nUInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\n\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)\n{\n  p->posLimit -= subValue;\n  p->pos -= subValue;\n  p->streamPos -= subValue;\n}\n\nstatic void MatchFinder_ReadBlock(CMatchFinder *p)\n{\n  if (p->streamEndWasReached || p->result != SZ_OK)\n    return;\n  for (;;)\n  {\n    Byte *dest = p->buffer + (p->streamPos - p->pos);\n    size_t size = (p->bufferBase + p->blockSize - dest);\n    if (size == 0)\n      return;\n    p->result = p->stream->Read(p->stream, dest, &size);\n    if (p->result != SZ_OK)\n      return;\n    if (size == 0)\n    {\n      p->streamEndWasReached = 1;\n      return;\n    }\n    p->streamPos += (UInt32)size;\n    if (p->streamPos - p->pos > p->keepSizeAfter)\n      return;\n  }\n}\n\nvoid MatchFinder_MoveBlock(CMatchFinder *p)\n{\n  memmove(p->bufferBase,\n    p->buffer - p->keepSizeBefore,\n    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\n  p->buffer = p->bufferBase + p->keepSizeBefore;\n}\n\nint MatchFinder_NeedMove(CMatchFinder *p)\n{\n  /* if (p->streamEndWasReached) return 0; */\n  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\n}\n\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p)\n{\n  if (p->streamEndWasReached)\n    return;\n  if (p->keepSizeAfter >= p->streamPos - p->pos)\n    MatchFinder_ReadBlock(p);\n}\n\nstatic void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)\n{\n  if (MatchFinder_NeedMove(p))\n    MatchFinder_MoveBlock(p);\n  MatchFinder_ReadBlock(p);\n}\n\nstatic void MatchFinder_SetDefaultSettings(CMatchFinder *p)\n{\n  p->cutValue = 32;\n  p->btMode = 1;\n  p->numHashBytes = 4;\n  /* p->skipModeBits = 0; */\n  p->directInput = 0;\n  p->bigHash = 0;\n}\n\n#define kCrcPoly 0xEDB88320\n\nvoid MatchFinder_Construct(CMatchFinder *p)\n{\n  UInt32 i;\n  p->bufferBase = 0;\n  p->directInput = 0;\n  p->hash = 0;\n  MatchFinder_SetDefaultSettings(p);\n\n  for (i = 0; i < 256; i++)\n  {\n    UInt32 r = i;\n    int j;\n    for (j = 0; j < 8; j++)\n      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\n    p->crc[i] = r;\n  }\n}\n\nstatic void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\n{\n  alloc->Free(alloc, p->hash);\n  p->hash = 0;\n}\n\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\n{\n  MatchFinder_FreeThisClassMemory(p, alloc);\n  LzInWindow_Free(p, alloc);\n}\n\nstatic CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\n{\n  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\n  if (sizeInBytes / sizeof(CLzRef) != num)\n    return 0;\n  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\n}\n\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\n    ISzAlloc *alloc)\n{\n  UInt32 sizeReserv;\n  if (historySize > kMaxHistorySize)\n  {\n    MatchFinder_Free(p, alloc);\n    return 0;\n  }\n  sizeReserv = historySize >> 1;\n  if (historySize > ((UInt32)2 << 30))\n    sizeReserv = historySize >> 2;\n  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\n\n  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\n  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\n  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\n  if (LzInWindow_Create(p, sizeReserv, alloc))\n  {\n    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\n    UInt32 hs;\n    p->matchMaxLen = matchMaxLen;\n    {\n      p->fixedHashSize = 0;\n      if (p->numHashBytes == 2)\n        hs = (1 << 16) - 1;\n      else\n      {\n        hs = historySize - 1;\n        hs |= (hs >> 1);\n        hs |= (hs >> 2);\n        hs |= (hs >> 4);\n        hs |= (hs >> 8);\n        hs >>= 1;\n        /* hs >>= p->skipModeBits; */\n        hs |= 0xFFFF; /* don't change it! It's required for Deflate */\n        if (hs > (1 << 24))\n        {\n          if (p->numHashBytes == 3)\n            hs = (1 << 24) - 1;\n          else\n            hs >>= 1;\n        }\n      }\n      p->hashMask = hs;\n      hs++;\n      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;\n      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;\n      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;\n      hs += p->fixedHashSize;\n    }\n\n    {\n      UInt32 prevSize = p->hashSizeSum + p->numSons;\n      UInt32 newSize;\n      p->historySize = historySize;\n      p->hashSizeSum = hs;\n      p->cyclicBufferSize = newCyclicBufferSize;\n      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\n      newSize = p->hashSizeSum + p->numSons;\n      if (p->hash != 0 && prevSize == newSize)\n        return 1;\n      MatchFinder_FreeThisClassMemory(p, alloc);\n      p->hash = AllocRefs(newSize, alloc);\n      if (p->hash != 0)\n      {\n        p->son = p->hash + p->hashSizeSum;\n        return 1;\n      }\n    }\n  }\n  MatchFinder_Free(p, alloc);\n  return 0;\n}\n\nstatic void MatchFinder_SetLimits(CMatchFinder *p)\n{\n  UInt32 limit = kMaxValForNormalize - p->pos;\n  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\n  if (limit2 < limit)\n    limit = limit2;\n  limit2 = p->streamPos - p->pos;\n  if (limit2 <= p->keepSizeAfter)\n  {\n    if (limit2 > 0)\n      limit2 = 1;\n  }\n  else\n    limit2 -= p->keepSizeAfter;\n  if (limit2 < limit)\n    limit = limit2;\n  {\n    UInt32 lenLimit = p->streamPos - p->pos;\n    if (lenLimit > p->matchMaxLen)\n      lenLimit = p->matchMaxLen;\n    p->lenLimit = lenLimit;\n  }\n  p->posLimit = p->pos + limit;\n}\n\nvoid MatchFinder_Init(CMatchFinder *p)\n{\n  UInt32 i;\n  for (i = 0; i < p->hashSizeSum; i++)\n    p->hash[i] = kEmptyHashValue;\n  p->cyclicBufferPos = 0;\n  p->buffer = p->bufferBase;\n  p->pos = p->streamPos = p->cyclicBufferSize;\n  p->result = SZ_OK;\n  p->streamEndWasReached = 0;\n  MatchFinder_ReadBlock(p);\n  MatchFinder_SetLimits(p);\n}\n\nstatic UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\n{\n  return (p->pos - p->historySize - 1) & kNormalizeMask;\n}\n\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\n{\n  UInt32 i;\n  for (i = 0; i < numItems; i++)\n  {\n    UInt32 value = items[i];\n    if (value <= subValue)\n      value = kEmptyHashValue;\n    else\n      value -= subValue;\n    items[i] = value;\n  }\n}\n\nstatic void MatchFinder_Normalize(CMatchFinder *p)\n{\n  UInt32 subValue = MatchFinder_GetSubValue(p);\n  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\n  MatchFinder_ReduceOffsets(p, subValue);\n}\n\nstatic void MatchFinder_CheckLimits(CMatchFinder *p)\n{\n  if (p->pos == kMaxValForNormalize)\n    MatchFinder_Normalize(p);\n  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)\n    MatchFinder_CheckAndMoveAndRead(p);\n  if (p->cyclicBufferPos == p->cyclicBufferSize)\n    p->cyclicBufferPos = 0;\n  MatchFinder_SetLimits(p);\n}\n\nstatic UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\n    UInt32 *distances, UInt32 maxLen)\n{\n  son[_cyclicBufferPos] = curMatch;\n  for (;;)\n  {\n    UInt32 delta = pos - curMatch;\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\n      return distances;\n    {\n      const Byte *pb = cur - delta;\n      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];\n      if (pb[maxLen] == cur[maxLen] && *pb == *cur)\n      {\n        UInt32 len = 0;\n        while (++len != lenLimit)\n          if (pb[len] != cur[len])\n            break;\n        if (maxLen < len)\n        {\n          *distances++ = maxLen = len;\n          *distances++ = delta - 1;\n          if (len == lenLimit)\n            return distances;\n        }\n      }\n    }\n  }\n}\n\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,\n    UInt32 *distances, UInt32 maxLen)\n{\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\n  UInt32 len0 = 0, len1 = 0;\n  for (;;)\n  {\n    UInt32 delta = pos - curMatch;\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\n    {\n      *ptr0 = *ptr1 = kEmptyHashValue;\n      return distances;\n    }\n    {\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\n      const Byte *pb = cur - delta;\n      UInt32 len = (len0 < len1 ? len0 : len1);\n      if (pb[len] == cur[len])\n      {\n        if (++len != lenLimit && pb[len] == cur[len])\n          while (++len != lenLimit)\n            if (pb[len] != cur[len])\n              break;\n        if (maxLen < len)\n        {\n          *distances++ = maxLen = len;\n          *distances++ = delta - 1;\n          if (len == lenLimit)\n          {\n            *ptr1 = pair[0];\n            *ptr0 = pair[1];\n            return distances;\n          }\n        }\n      }\n      if (pb[len] < cur[len])\n      {\n        *ptr1 = curMatch;\n        ptr1 = pair + 1;\n        curMatch = *ptr1;\n        len1 = len;\n      }\n      else\n      {\n        *ptr0 = curMatch;\n        ptr0 = pair;\n        curMatch = *ptr0;\n        len0 = len;\n      }\n    }\n  }\n}\n\nstatic void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)\n{\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\n  UInt32 len0 = 0, len1 = 0;\n  for (;;)\n  {\n    UInt32 delta = pos - curMatch;\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\n    {\n      *ptr0 = *ptr1 = kEmptyHashValue;\n      return;\n    }\n    {\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\n      const Byte *pb = cur - delta;\n      UInt32 len = (len0 < len1 ? len0 : len1);\n      if (pb[len] == cur[len])\n      {\n        while (++len != lenLimit)\n          if (pb[len] != cur[len])\n            break;\n        {\n          if (len == lenLimit)\n          {\n            *ptr1 = pair[0];\n            *ptr0 = pair[1];\n            return;\n          }\n        }\n      }\n      if (pb[len] < cur[len])\n      {\n        *ptr1 = curMatch;\n        ptr1 = pair + 1;\n        curMatch = *ptr1;\n        len1 = len;\n      }\n      else\n      {\n        *ptr0 = curMatch;\n        ptr0 = pair;\n        curMatch = *ptr0;\n        len0 = len;\n      }\n    }\n  }\n}\n\n#define MOVE_POS \\\n  ++p->cyclicBufferPos; \\\n  p->buffer++; \\\n  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);\n\n#define MOVE_POS_RET MOVE_POS return offset;\n\nstatic void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\n\n#define GET_MATCHES_HEADER2(minLen, ret_op) \\\n  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\\n  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\\n  cur = p->buffer;\n\n#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)\n#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)\n\n#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue\n\n#define GET_MATCHES_FOOTER(offset, maxLen) \\\n  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \\\n  distances + offset, maxLen) - distances); MOVE_POS_RET;\n\n#define SKIP_FOOTER \\\n  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\n\nstatic UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\n{\n  UInt32 offset;\n  GET_MATCHES_HEADER(2)\n  HASH2_CALC;\n  curMatch = p->hash[hashValue];\n  p->hash[hashValue] = p->pos;\n  offset = 0;\n  GET_MATCHES_FOOTER(offset, 1)\n}\n\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\n{\n  UInt32 offset;\n  GET_MATCHES_HEADER(3)\n  HASH_ZIP_CALC;\n  curMatch = p->hash[hashValue];\n  p->hash[hashValue] = p->pos;\n  offset = 0;\n  GET_MATCHES_FOOTER(offset, 2)\n}\n\nstatic UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\n{\n  UInt32 hash2Value, delta2, maxLen, offset;\n  GET_MATCHES_HEADER(3)\n\n  HASH3_CALC;\n\n  delta2 = p->pos - p->hash[hash2Value];\n  curMatch = p->hash[kFix3HashSize + hashValue];\n  \n  p->hash[hash2Value] =\n  p->hash[kFix3HashSize + hashValue] = p->pos;\n\n\n  maxLen = 2;\n  offset = 0;\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\n  {\n    for (; maxLen != lenLimit; maxLen++)\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\n        break;\n    distances[0] = maxLen;\n    distances[1] = delta2 - 1;\n    offset = 2;\n    if (maxLen == lenLimit)\n    {\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\n      MOVE_POS_RET;\n    }\n  }\n  GET_MATCHES_FOOTER(offset, maxLen)\n}\n\nstatic UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\n{\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\n  GET_MATCHES_HEADER(4)\n\n  HASH4_CALC;\n\n  delta2 = p->pos - p->hash[                hash2Value];\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\n  curMatch = p->hash[kFix4HashSize + hashValue];\n  \n  p->hash[                hash2Value] =\n  p->hash[kFix3HashSize + hash3Value] =\n  p->hash[kFix4HashSize + hashValue] = p->pos;\n\n  maxLen = 1;\n  offset = 0;\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\n  {\n    distances[0] = maxLen = 2;\n    distances[1] = delta2 - 1;\n    offset = 2;\n  }\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\n  {\n    maxLen = 3;\n    distances[offset + 1] = delta3 - 1;\n    offset += 2;\n    delta2 = delta3;\n  }\n  if (offset != 0)\n  {\n    for (; maxLen != lenLimit; maxLen++)\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\n        break;\n    distances[offset - 2] = maxLen;\n    if (maxLen == lenLimit)\n    {\n      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\n      MOVE_POS_RET;\n    }\n  }\n  if (maxLen < 3)\n    maxLen = 3;\n  GET_MATCHES_FOOTER(offset, maxLen)\n}\n\nstatic UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\n{\n  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\n  GET_MATCHES_HEADER(4)\n\n  HASH4_CALC;\n\n  delta2 = p->pos - p->hash[                hash2Value];\n  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\n  curMatch = p->hash[kFix4HashSize + hashValue];\n\n  p->hash[                hash2Value] =\n  p->hash[kFix3HashSize + hash3Value] =\n  p->hash[kFix4HashSize + hashValue] = p->pos;\n\n  maxLen = 1;\n  offset = 0;\n  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\n  {\n    distances[0] = maxLen = 2;\n    distances[1] = delta2 - 1;\n    offset = 2;\n  }\n  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\n  {\n    maxLen = 3;\n    distances[offset + 1] = delta3 - 1;\n    offset += 2;\n    delta2 = delta3;\n  }\n  if (offset != 0)\n  {\n    for (; maxLen != lenLimit; maxLen++)\n      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\n        break;\n    distances[offset - 2] = maxLen;\n    if (maxLen == lenLimit)\n    {\n      p->son[p->cyclicBufferPos] = curMatch;\n      MOVE_POS_RET;\n    }\n  }\n  if (maxLen < 3)\n    maxLen = 3;\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\n    distances + offset, maxLen) - (distances));\n  MOVE_POS_RET\n}\n\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\n{\n  UInt32 offset;\n  GET_MATCHES_HEADER(3)\n  HASH_ZIP_CALC;\n  curMatch = p->hash[hashValue];\n  p->hash[hashValue] = p->pos;\n  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\n    distances, 2) - (distances));\n  MOVE_POS_RET\n}\n\nstatic void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\n{\n  do\n  {\n    SKIP_HEADER(2)\n    HASH2_CALC;\n    curMatch = p->hash[hashValue];\n    p->hash[hashValue] = p->pos;\n    SKIP_FOOTER\n  }\n  while (--num != 0);\n}\n\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\n{\n  do\n  {\n    SKIP_HEADER(3)\n    HASH_ZIP_CALC;\n    curMatch = p->hash[hashValue];\n    p->hash[hashValue] = p->pos;\n    SKIP_FOOTER\n  }\n  while (--num != 0);\n}\n\nstatic void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\n{\n  do\n  {\n    UInt32 hash2Value;\n    SKIP_HEADER(3)\n    HASH3_CALC;\n    curMatch = p->hash[kFix3HashSize + hashValue];\n    p->hash[hash2Value] =\n    p->hash[kFix3HashSize + hashValue] = p->pos;\n    SKIP_FOOTER\n  }\n  while (--num != 0);\n}\n\nstatic void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\n{\n  do\n  {\n    UInt32 hash2Value, hash3Value;\n    SKIP_HEADER(4)\n    HASH4_CALC;\n    curMatch = p->hash[kFix4HashSize + hashValue];\n    p->hash[                hash2Value] =\n    p->hash[kFix3HashSize + hash3Value] = p->pos;\n    p->hash[kFix4HashSize + hashValue] = p->pos;\n    SKIP_FOOTER\n  }\n  while (--num != 0);\n}\n\nstatic void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\n{\n  do\n  {\n    UInt32 hash2Value, hash3Value;\n    SKIP_HEADER(4)\n    HASH4_CALC;\n    curMatch = p->hash[kFix4HashSize + hashValue];\n    p->hash[                hash2Value] =\n    p->hash[kFix3HashSize + hash3Value] =\n    p->hash[kFix4HashSize + hashValue] = p->pos;\n    p->son[p->cyclicBufferPos] = curMatch;\n    MOVE_POS\n  }\n  while (--num != 0);\n}\n\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\n{\n  do\n  {\n    SKIP_HEADER(3)\n    HASH_ZIP_CALC;\n    curMatch = p->hash[hashValue];\n    p->hash[hashValue] = p->pos;\n    p->son[p->cyclicBufferPos] = curMatch;\n    MOVE_POS\n  }\n  while (--num != 0);\n}\n\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\n{\n  vTable->Init = (Mf_Init_Func)MatchFinder_Init;\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\n  if (!p->btMode)\n  {\n    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\n    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\n  }\n  else if (p->numHashBytes == 2)\n  {\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;\n    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;\n  }\n  else if (p->numHashBytes == 3)\n  {\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\n    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\n  }\n  else\n  {\n    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\n    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\n  }\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzFind.h",
    "content": "/* LzFind.h -- Match finder for LZ algorithms\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __LZFIND_H\n#define __LZFIND_H\n\n#include \"Types.h\"\n\ntypedef UInt32 CLzRef;\n\ntypedef struct _CMatchFinder\n{\n  Byte *buffer;\n  UInt32 pos;\n  UInt32 posLimit;\n  UInt32 streamPos;\n  UInt32 lenLimit;\n\n  UInt32 cyclicBufferPos;\n  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\n\n  UInt32 matchMaxLen;\n  CLzRef *hash;\n  CLzRef *son;\n  UInt32 hashMask;\n  UInt32 cutValue;\n\n  Byte *bufferBase;\n  ISeqInStream *stream;\n  int streamEndWasReached;\n\n  UInt32 blockSize;\n  UInt32 keepSizeBefore;\n  UInt32 keepSizeAfter;\n\n  UInt32 numHashBytes;\n  int directInput;\n  int btMode;\n  /* int skipModeBits; */\n  int bigHash;\n  UInt32 historySize;\n  UInt32 fixedHashSize;\n  UInt32 hashSizeSum;\n  UInt32 numSons;\n  SRes result;\n  UInt32 crc[256];\n} CMatchFinder;\n\n#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\n#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\n\n#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\n\nint MatchFinder_NeedMove(CMatchFinder *p);\nByte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\nvoid MatchFinder_MoveBlock(CMatchFinder *p);\nvoid MatchFinder_ReadIfRequired(CMatchFinder *p);\n\nvoid MatchFinder_Construct(CMatchFinder *p);\n\n/* Conditions:\n     historySize <= 3 GB\n     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB\n*/\nint MatchFinder_Create(CMatchFinder *p, UInt32 historySize,\n    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\n    ISzAlloc *alloc);\nvoid MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\nvoid MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\nvoid MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\n\nUInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\n    UInt32 *distances, UInt32 maxLen);\n\n/*\nConditions:\n  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.\n  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function\n*/\n\ntypedef void (*Mf_Init_Func)(void *object);\ntypedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\ntypedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\ntypedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\ntypedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\ntypedef void (*Mf_Skip_Func)(void *object, UInt32);\n\ntypedef struct _IMatchFinder\n{\n  Mf_Init_Func Init;\n  Mf_GetIndexByte_Func GetIndexByte;\n  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\n  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\n  Mf_GetMatches_Func GetMatches;\n  Mf_Skip_Func Skip;\n} IMatchFinder;\n\nvoid MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\n\nvoid MatchFinder_Init(CMatchFinder *p);\nUInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\nUInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\nvoid Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\nvoid Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzFindMt.c",
    "content": "/* LzFindMt.c -- multithreaded Match finder for LZ algorithms\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include \"LzHash.h\"\n\n#include \"LzFindMt.h\"\n\nvoid MtSync_Construct(CMtSync *p)\n{\n  p->wasCreated = False;\n  p->csWasInitialized = False;\n  p->csWasEntered = False;\n  Thread_Construct(&p->thread);\n  Event_Construct(&p->canStart);\n  Event_Construct(&p->wasStarted);\n  Event_Construct(&p->wasStopped);\n  Semaphore_Construct(&p->freeSemaphore);\n  Semaphore_Construct(&p->filledSemaphore);\n}\n\nvoid MtSync_GetNextBlock(CMtSync *p)\n{\n  if (p->needStart)\n  {\n    p->numProcessedBlocks = 1;\n    p->needStart = False;\n    p->stopWriting = False;\n    p->exit = False;\n    Event_Reset(&p->wasStarted);\n    Event_Reset(&p->wasStopped);\n\n    Event_Set(&p->canStart);\n    Event_Wait(&p->wasStarted);\n  }\n  else\n  {\n    CriticalSection_Leave(&p->cs);\n    p->csWasEntered = False;\n    p->numProcessedBlocks++;\n    Semaphore_Release1(&p->freeSemaphore);\n  }\n  Semaphore_Wait(&p->filledSemaphore);\n  CriticalSection_Enter(&p->cs);\n  p->csWasEntered = True;\n}\n\n/* MtSync_StopWriting must be called if Writing was started */\n\nvoid MtSync_StopWriting(CMtSync *p)\n{\n  UInt32 myNumBlocks = p->numProcessedBlocks;\n  if (!Thread_WasCreated(&p->thread) || p->needStart)\n    return;\n  p->stopWriting = True;\n  if (p->csWasEntered)\n  {\n    CriticalSection_Leave(&p->cs);\n    p->csWasEntered = False;\n  }\n  Semaphore_Release1(&p->freeSemaphore);\n \n  Event_Wait(&p->wasStopped);\n\n  while (myNumBlocks++ != p->numProcessedBlocks)\n  {\n    Semaphore_Wait(&p->filledSemaphore);\n    Semaphore_Release1(&p->freeSemaphore);\n  }\n  p->needStart = True;\n}\n\nvoid MtSync_Destruct(CMtSync *p)\n{\n  if (Thread_WasCreated(&p->thread))\n  {\n    MtSync_StopWriting(p);\n    p->exit = True;\n    if (p->needStart)\n      Event_Set(&p->canStart);\n    Thread_Wait(&p->thread);\n    Thread_Close(&p->thread);\n  }\n  if (p->csWasInitialized)\n  {\n    CriticalSection_Delete(&p->cs);\n    p->csWasInitialized = False;\n  }\n\n  Event_Close(&p->canStart);\n  Event_Close(&p->wasStarted);\n  Event_Close(&p->wasStopped);\n  Semaphore_Close(&p->freeSemaphore);\n  Semaphore_Close(&p->filledSemaphore);\n\n  p->wasCreated = False;\n}\n\n#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }\n\nstatic SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\n{\n  if (p->wasCreated)\n    return SZ_OK;\n\n  RINOK_THREAD(CriticalSection_Init(&p->cs));\n  p->csWasInitialized = True;\n\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));\n  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));\n  \n  RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));\n  RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));\n\n  p->needStart = True;\n  \n  RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));\n  p->wasCreated = True;\n  return SZ_OK;\n}\n\nstatic SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\n{\n  SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\n  if (res != SZ_OK)\n    MtSync_Destruct(p);\n  return res;\n}\n\nvoid MtSync_Init(CMtSync *p) { p->needStart = True; }\n\n#define kMtMaxValForNormalize 0xFFFFFFFF\n\n#define DEF_GetHeads2(name, v, action) \\\nstatic void GetHeads ## name(const Byte *p, UInt32 pos, \\\nUInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \\\n{ action; for (; numHeads != 0; numHeads--) { \\\nconst UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\n\n#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)\n\nDEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )\nDEF_GetHeads(3,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\nDEF_GetHeads(4,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)\nDEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\nDEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)\n\nvoid HashThreadFunc(CMatchFinderMt *mt)\n{\n  CMtSync *p = &mt->hashSync;\n  for (;;)\n  {\n    UInt32 numProcessedBlocks = 0;\n    Event_Wait(&p->canStart);\n    Event_Set(&p->wasStarted);\n    for (;;)\n    {\n      if (p->exit)\n        return;\n      if (p->stopWriting)\n      {\n        p->numProcessedBlocks = numProcessedBlocks;\n        Event_Set(&p->wasStopped);\n        break;\n      }\n\n      {\n        CMatchFinder *mf = mt->MatchFinder;\n        if (MatchFinder_NeedMove(mf))\n        {\n          CriticalSection_Enter(&mt->btSync.cs);\n          CriticalSection_Enter(&mt->hashSync.cs);\n          {\n            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);\n            const Byte *afterPtr;\n            MatchFinder_MoveBlock(mf);\n            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);\n            mt->pointerToCurPos -= beforePtr - afterPtr;\n            mt->buffer -= beforePtr - afterPtr;\n          }\n          CriticalSection_Leave(&mt->btSync.cs);\n          CriticalSection_Leave(&mt->hashSync.cs);\n          continue;\n        }\n\n        Semaphore_Wait(&p->freeSemaphore);\n\n        MatchFinder_ReadIfRequired(mf);\n        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))\n        {\n          UInt32 subValue = (mf->pos - mf->historySize - 1);\n          MatchFinder_ReduceOffsets(mf, subValue);\n          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);\n        }\n        {\n          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\n          UInt32 num = mf->streamPos - mf->pos;\n          heads[0] = 2;\n          heads[1] = num;\n          if (num >= mf->numHashBytes)\n          {\n            num = num - mf->numHashBytes + 1;\n            if (num > kMtHashBlockSize - 2)\n              num = kMtHashBlockSize - 2;\n            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);\n            heads[0] += num;\n          }\n          mf->pos += num;\n          mf->buffer += num;\n        }\n      }\n\n      Semaphore_Release1(&p->filledSemaphore);\n    }\n  }\n}\n\nvoid MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\n{\n  MtSync_GetNextBlock(&p->hashSync);\n  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\n  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];\n  p->hashNumAvail = p->hashBuf[p->hashBufPos++];\n}\n\n#define kEmptyHashValue 0\n\n/* #define MFMT_GM_INLINE */\n\n#ifdef MFMT_GM_INLINE\n\n#define NO_INLINE MY_FAST_CALL\n\nInt32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,\n    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\n    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\n{\n  do\n  {\n  UInt32 *distances = _distances + 1;\n  UInt32 curMatch = pos - *hash++;\n\n  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;\n  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);\n  UInt32 len0 = 0, len1 = 0;\n  UInt32 cutValue = _cutValue;\n  UInt32 maxLen = _maxLen;\n  for (;;)\n  {\n    UInt32 delta = pos - curMatch;\n    if (cutValue-- == 0 || delta >= _cyclicBufferSize)\n    {\n      *ptr0 = *ptr1 = kEmptyHashValue;\n      break;\n    }\n    {\n      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);\n      const Byte *pb = cur - delta;\n      UInt32 len = (len0 < len1 ? len0 : len1);\n      if (pb[len] == cur[len])\n      {\n        if (++len != lenLimit && pb[len] == cur[len])\n          while (++len != lenLimit)\n            if (pb[len] != cur[len])\n              break;\n        if (maxLen < len)\n        {\n          *distances++ = maxLen = len;\n          *distances++ = delta - 1;\n          if (len == lenLimit)\n          {\n            *ptr1 = pair[0];\n            *ptr0 = pair[1];\n            break;\n          }\n        }\n      }\n      if (pb[len] < cur[len])\n      {\n        *ptr1 = curMatch;\n        ptr1 = pair + 1;\n        curMatch = *ptr1;\n        len1 = len;\n      }\n      else\n      {\n        *ptr0 = curMatch;\n        ptr0 = pair;\n        curMatch = *ptr0;\n        len0 = len;\n      }\n    }\n  }\n  pos++;\n  _cyclicBufferPos++;\n  cur++;\n  {\n    UInt32 num = (UInt32)(distances - _distances);\n    *_distances = num - 1;\n    _distances += num;\n    limit -= num;\n  }\n  }\n  while (limit > 0 && --size != 0);\n  *posRes = pos;\n  return limit;\n}\n\n#endif\n\nvoid BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\n{\n  UInt32 numProcessed = 0;\n  UInt32 curPos = 2;\n  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\n  distances[1] = p->hashNumAvail;\n  while (curPos < limit)\n  {\n    if (p->hashBufPos == p->hashBufPosLimit)\n    {\n      MatchFinderMt_GetNextBlock_Hash(p);\n      distances[1] = numProcessed + p->hashNumAvail;\n      if (p->hashNumAvail >= p->numHashBytes)\n        continue;\n      for (; p->hashNumAvail != 0; p->hashNumAvail--)\n        distances[curPos++] = 0;\n      break;\n    }\n    {\n      UInt32 size = p->hashBufPosLimit - p->hashBufPos;\n      UInt32 lenLimit = p->matchMaxLen;\n      UInt32 pos = p->pos;\n      UInt32 cyclicBufferPos = p->cyclicBufferPos;\n      if (lenLimit >= p->hashNumAvail)\n        lenLimit = p->hashNumAvail;\n      {\n        UInt32 size2 = p->hashNumAvail - lenLimit + 1;\n        if (size2 < size)\n          size = size2;\n        size2 = p->cyclicBufferSize - cyclicBufferPos;\n        if (size2 < size)\n          size = size2;\n      }\n      #ifndef MFMT_GM_INLINE\n      while (curPos < limit && size-- != 0)\n      {\n        UInt32 *startDistances = distances + curPos;\n        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],\n          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\n          startDistances + 1, p->numHashBytes - 1) - startDistances);\n        *startDistances = num - 1;\n        curPos += num;\n        cyclicBufferPos++;\n        pos++;\n        p->buffer++;\n      }\n      #else\n      {\n        UInt32 posRes;\n        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\n          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);\n        p->hashBufPos += posRes - pos;\n        cyclicBufferPos += posRes - pos;\n        p->buffer += posRes - pos;\n        pos = posRes;\n      }\n      #endif\n\n      numProcessed += pos - p->pos;\n      p->hashNumAvail -= pos - p->pos;\n      p->pos = pos;\n      if (cyclicBufferPos == p->cyclicBufferSize)\n        cyclicBufferPos = 0;\n      p->cyclicBufferPos = cyclicBufferPos;\n    }\n  }\n  distances[0] = curPos;\n}\n\nvoid BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\n{\n  CMtSync *sync = &p->hashSync;\n  if (!sync->needStart)\n  {\n    CriticalSection_Enter(&sync->cs);\n    sync->csWasEntered = True;\n  }\n  \n  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);\n\n  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\n  {\n    UInt32 subValue = p->pos - p->cyclicBufferSize;\n    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);\n    p->pos -= subValue;\n  }\n\n  if (!sync->needStart)\n  {\n    CriticalSection_Leave(&sync->cs);\n    sync->csWasEntered = False;\n  }\n}\n\nvoid BtThreadFunc(CMatchFinderMt *mt)\n{\n  CMtSync *p = &mt->btSync;\n  for (;;)\n  {\n    UInt32 blockIndex = 0;\n    Event_Wait(&p->canStart);\n    Event_Set(&p->wasStarted);\n    for (;;)\n    {\n      if (p->exit)\n        return;\n      if (p->stopWriting)\n      {\n        p->numProcessedBlocks = blockIndex;\n        MtSync_StopWriting(&mt->hashSync);\n        Event_Set(&p->wasStopped);\n        break;\n      }\n      Semaphore_Wait(&p->freeSemaphore);\n      BtFillBlock(mt, blockIndex++);\n      Semaphore_Release1(&p->filledSemaphore);\n    }\n  }\n}\n\nvoid MatchFinderMt_Construct(CMatchFinderMt *p)\n{\n  p->hashBuf = 0;\n  MtSync_Construct(&p->hashSync);\n  MtSync_Construct(&p->btSync);\n}\n\nvoid MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\n{\n  alloc->Free(alloc, p->hashBuf);\n  p->hashBuf = 0;\n}\n\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\n{\n  MtSync_Destruct(&p->hashSync);\n  MtSync_Destruct(&p->btSync);\n  MatchFinderMt_FreeMem(p, alloc);\n}\n\n#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\n#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\n\nstatic unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\nstatic unsigned MY_STD_CALL BtThreadFunc2(void *p)\n{\n  Byte allocaDummy[0x180];\n  int i = 0;\n  for (i = 0; i < 16; i++)\n    allocaDummy[i] = (Byte)i;\n  BtThreadFunc((CMatchFinderMt *)p);\n  return 0;\n}\n\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\n{\n  CMatchFinder *mf = p->MatchFinder;\n  p->historySize = historySize;\n  if (kMtBtBlockSize <= matchMaxLen * 4)\n    return SZ_ERROR_PARAM;\n  if (p->hashBuf == 0)\n  {\n    p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\n    if (p->hashBuf == 0)\n      return SZ_ERROR_MEM;\n    p->btBuf = p->hashBuf + kHashBufferSize;\n  }\n  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);\n  keepAddBufferAfter += kMtHashBlockSize;\n  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))\n    return SZ_ERROR_MEM;\n\n  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));\n  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));\n  return SZ_OK;\n}\n\n/* Call it after ReleaseStream / SetStream */\nvoid MatchFinderMt_Init(CMatchFinderMt *p)\n{\n  CMatchFinder *mf = p->MatchFinder;\n  p->btBufPos = p->btBufPosLimit = 0;\n  p->hashBufPos = p->hashBufPosLimit = 0;\n  MatchFinder_Init(mf);\n  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);\n  p->btNumAvailBytes = 0;\n  p->lzPos = p->historySize + 1;\n\n  p->hash = mf->hash;\n  p->fixedHashSize = mf->fixedHashSize;\n  p->crc = mf->crc;\n\n  p->son = mf->son;\n  p->matchMaxLen = mf->matchMaxLen;\n  p->numHashBytes = mf->numHashBytes;\n  p->pos = mf->pos;\n  p->buffer = mf->buffer;\n  p->cyclicBufferPos = mf->cyclicBufferPos;\n  p->cyclicBufferSize = mf->cyclicBufferSize;\n  p->cutValue = mf->cutValue;\n}\n\n/* ReleaseStream is required to finish multithreading */\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p)\n{\n  MtSync_StopWriting(&p->btSync);\n  /* p->MatchFinder->ReleaseStream(); */\n}\n\nvoid MatchFinderMt_Normalize(CMatchFinderMt *p)\n{\n  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\n  p->lzPos = p->historySize + 1;\n}\n\nvoid MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\n{\n  UInt32 blockIndex;\n  MtSync_GetNextBlock(&p->btSync);\n  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);\n  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;\n  p->btBufPosLimit += p->btBuf[p->btBufPos++];\n  p->btNumAvailBytes = p->btBuf[p->btBufPos++];\n  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)\n    MatchFinderMt_Normalize(p);\n}\n\nconst Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\n{\n  return p->pointerToCurPos;\n}\n\n#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\n\nUInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\n{\n  GET_NEXT_BLOCK_IF_REQUIRED;\n  return p->btNumAvailBytes;\n}\n\nByte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)\n{\n  return p->pointerToCurPos[index];\n}\n\nUInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\n{\n  UInt32 hash2Value, curMatch2;\n  UInt32 *hash = p->hash;\n  const Byte *cur = p->pointerToCurPos;\n  UInt32 lzPos = p->lzPos;\n  MT_HASH2_CALC\n      \n  curMatch2 = hash[hash2Value];\n  hash[hash2Value] = lzPos;\n\n  if (curMatch2 >= matchMinPos)\n    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\n    {\n      *distances++ = 2;\n      *distances++ = lzPos - curMatch2 - 1;\n    }\n  return distances;\n}\n\nUInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\n{\n  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;\n  UInt32 *hash = p->hash;\n  const Byte *cur = p->pointerToCurPos;\n  UInt32 lzPos = p->lzPos;\n  MT_HASH3_CALC\n\n  curMatch2 = hash[                hash2Value];\n  curMatch3 = hash[kFix3HashSize + hash3Value];\n  \n  hash[                hash2Value] =\n  hash[kFix3HashSize + hash3Value] =\n    lzPos;\n\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\n  {\n    distances[1] = lzPos - curMatch2 - 1;\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\n    {\n      distances[0] = 3;\n      return distances + 2;\n    }\n    distances[0] = 2;\n    distances += 2;\n  }\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\n  {\n    *distances++ = 3;\n    *distances++ = lzPos - curMatch3 - 1;\n  }\n  return distances;\n}\n\n/*\nUInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\n{\n  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;\n  UInt32 *hash = p->hash;\n  const Byte *cur = p->pointerToCurPos;\n  UInt32 lzPos = p->lzPos;\n  MT_HASH4_CALC\n      \n  curMatch2 = hash[                hash2Value];\n  curMatch3 = hash[kFix3HashSize + hash3Value];\n  curMatch4 = hash[kFix4HashSize + hash4Value];\n  \n  hash[                hash2Value] =\n  hash[kFix3HashSize + hash3Value] =\n  hash[kFix4HashSize + hash4Value] =\n    lzPos;\n\n  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\n  {\n    distances[1] = lzPos - curMatch2 - 1;\n    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\n    {\n      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\n      return distances + 2;\n    }\n    distances[0] = 2;\n    distances += 2;\n  }\n  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\n  {\n    distances[1] = lzPos - curMatch3 - 1;\n    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])\n    {\n      distances[0] = 4;\n      return distances + 2;\n    }\n    distances[0] = 3;\n    distances += 2;\n  }\n\n  if (curMatch4 >= matchMinPos)\n    if (\n      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&\n      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]\n      )\n    {\n      *distances++ = 4;\n      *distances++ = lzPos - curMatch4 - 1;\n    }\n  return distances;\n}\n*/\n\n#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\n\nUInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\n{\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\n  UInt32 len = *btBuf++;\n  p->btBufPos += 1 + len;\n  p->btNumAvailBytes--;\n  {\n    UInt32 i;\n    for (i = 0; i < len; i += 2)\n    {\n      *distances++ = *btBuf++;\n      *distances++ = *btBuf++;\n    }\n  }\n  INCREASE_LZ_POS\n  return len;\n}\n\nUInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\n{\n  const UInt32 *btBuf = p->btBuf + p->btBufPos;\n  UInt32 len = *btBuf++;\n  p->btBufPos += 1 + len;\n\n  if (len == 0)\n  {\n    if (p->btNumAvailBytes-- >= 4)\n      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\n  }\n  else\n  {\n    /* Condition: there are matches in btBuf with length < p->numHashBytes */\n    UInt32 *distances2;\n    p->btNumAvailBytes--;\n    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\n    do\n    {\n      *distances2++ = *btBuf++;\n      *distances2++ = *btBuf++;\n    }\n    while ((len -= 2) != 0);\n    len  = (UInt32)(distances2 - (distances));\n  }\n  INCREASE_LZ_POS\n  return len;\n}\n\n#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED\n#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\n#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);\n\nvoid MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\n{\n  SKIP_HEADER2 { p->btNumAvailBytes--;\n  SKIP_FOOTER\n}\n\nvoid MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\n{\n  SKIP_HEADER(2)\n      UInt32 hash2Value;\n      MT_HASH2_CALC\n      hash[hash2Value] = p->lzPos;\n  SKIP_FOOTER\n}\n\nvoid MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\n{\n  SKIP_HEADER(3)\n      UInt32 hash2Value, hash3Value;\n      MT_HASH3_CALC\n      hash[kFix3HashSize + hash3Value] =\n      hash[                hash2Value] =\n        p->lzPos;\n  SKIP_FOOTER\n}\n\n/*\nvoid MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\n{\n  SKIP_HEADER(4)\n      UInt32 hash2Value, hash3Value, hash4Value;\n      MT_HASH4_CALC\n      hash[kFix4HashSize + hash4Value] =\n      hash[kFix3HashSize + hash3Value] =\n      hash[                hash2Value] =\n        p->lzPos;\n  SKIP_FOOTER\n}\n*/\n\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\n{\n  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\n  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;\n  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\n  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\n  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\n  switch(p->MatchFinder->numHashBytes)\n  {\n    case 2:\n      p->GetHeadsFunc = GetHeads2;\n      p->MixMatchesFunc = (Mf_Mix_Matches)0;\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\n      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\n      break;\n    case 3:\n      p->GetHeadsFunc = GetHeads3;\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;\n      break;\n    default:\n    /* case 4: */\n      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\n      /* p->GetHeadsFunc = GetHeads4; */\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\n      break;\n    /*\n    default:\n      p->GetHeadsFunc = GetHeads5;\n      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;\n      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;\n      break;\n    */\n  }\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzFindMt.h",
    "content": "/* LzFindMt.h -- multithreaded Match finder for LZ algorithms\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __LZFINDMT_H\n#define __LZFINDMT_H\n\n#include \"Threads.h\"\n#include \"LzFind.h\"\n\n#define kMtHashBlockSize (1 << 13)\n#define kMtHashNumBlocks (1 << 3)\n#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)\n\n#define kMtBtBlockSize (1 << 14)\n#define kMtBtNumBlocks (1 << 6)\n#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)\n\ntypedef struct _CMtSync\n{\n  Bool wasCreated;\n  Bool needStart;\n  Bool exit;\n  Bool stopWriting;\n\n  CThread thread;\n  CAutoResetEvent canStart;\n  CAutoResetEvent wasStarted;\n  CAutoResetEvent wasStopped;\n  CSemaphore freeSemaphore;\n  CSemaphore filledSemaphore;\n  Bool csWasInitialized;\n  Bool csWasEntered;\n  CCriticalSection cs;\n  UInt32 numProcessedBlocks;\n} CMtSync;\n\ntypedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);\n\n/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */\n#define kMtCacheLineDummy 128\n\ntypedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,\n  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);\n\ntypedef struct _CMatchFinderMt\n{\n  /* LZ */\n  const Byte *pointerToCurPos;\n  UInt32 *btBuf;\n  UInt32 btBufPos;\n  UInt32 btBufPosLimit;\n  UInt32 lzPos;\n  UInt32 btNumAvailBytes;\n\n  UInt32 *hash;\n  UInt32 fixedHashSize;\n  UInt32 historySize;\n  const UInt32 *crc;\n\n  Mf_Mix_Matches MixMatchesFunc;\n  \n  /* LZ + BT */\n  CMtSync btSync;\n  Byte btDummy[kMtCacheLineDummy];\n\n  /* BT */\n  UInt32 *hashBuf;\n  UInt32 hashBufPos;\n  UInt32 hashBufPosLimit;\n  UInt32 hashNumAvail;\n\n  CLzRef *son;\n  UInt32 matchMaxLen;\n  UInt32 numHashBytes;\n  UInt32 pos;\n  Byte *buffer;\n  UInt32 cyclicBufferPos;\n  UInt32 cyclicBufferSize; /* it must be historySize + 1 */\n  UInt32 cutValue;\n\n  /* BT + Hash */\n  CMtSync hashSync;\n  /* Byte hashDummy[kMtCacheLineDummy]; */\n  \n  /* Hash */\n  Mf_GetHeads GetHeadsFunc;\n  CMatchFinder *MatchFinder;\n} CMatchFinderMt;\n\nvoid MatchFinderMt_Construct(CMatchFinderMt *p);\nvoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);\nSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);\nvoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\nvoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzHash.h",
    "content": "/* LzHash.h -- HASH functions for LZ algorithms\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __LZHASH_H\n#define __LZHASH_H\n\n#define kHash2Size (1 << 10)\n#define kHash3Size (1 << 16)\n#define kHash4Size (1 << 20)\n\n#define kFix3HashSize (kHash2Size)\n#define kFix4HashSize (kHash2Size + kHash3Size)\n#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\n\n#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\n\n#define HASH3_CALC { \\\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\n  hash2Value = temp & (kHash2Size - 1); \\\n  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\n\n#define HASH4_CALC { \\\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\n  hash2Value = temp & (kHash2Size - 1); \\\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\n  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\n\n#define HASH5_CALC { \\\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\n  hash2Value = temp & (kHash2Size - 1); \\\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\\n  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\\n  hash4Value &= (kHash4Size - 1); }\n\n/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\n#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\n\n\n#define MT_HASH2_CALC \\\n  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\n\n#define MT_HASH3_CALC { \\\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\n  hash2Value = temp & (kHash2Size - 1); \\\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\n\n#define MT_HASH4_CALC { \\\n  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\\n  hash2Value = temp & (kHash2Size - 1); \\\n  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\\n  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaDec.c",
    "content": "/* LzmaDec.c -- LZMA Decoder\n2008-11-06 : Igor Pavlov : Public domain */\n\n#include \"LzmaDec.h\"\n\n#include <string.h>\n\n#define kNumTopBits 24\n#define kTopValue ((UInt32)1 << kNumTopBits)\n\n#define kNumBitModelTotalBits 11\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\n#define kNumMoveBits 5\n\n#define RC_INIT_SIZE 5\n\n#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }\n\n#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\n#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));\n#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));\n#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \\\n  { UPDATE_0(p); i = (i + i); A0; } else \\\n  { UPDATE_1(p); i = (i + i) + 1; A1; }\n#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)\n\n#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }\n#define TREE_DECODE(probs, limit, i) \\\n  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }\n\n/* #define _LZMA_SIZE_OPT */\n\n#ifdef _LZMA_SIZE_OPT\n#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)\n#else\n#define TREE_6_DECODE(probs, i) \\\n  { i = 1; \\\n  TREE_GET_BIT(probs, i); \\\n  TREE_GET_BIT(probs, i); \\\n  TREE_GET_BIT(probs, i); \\\n  TREE_GET_BIT(probs, i); \\\n  TREE_GET_BIT(probs, i); \\\n  TREE_GET_BIT(probs, i); \\\n  i -= 0x40; }\n#endif\n\n#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\n\n#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\n#define UPDATE_0_CHECK range = bound;\n#define UPDATE_1_CHECK range -= bound; code -= bound;\n#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \\\n  { UPDATE_0_CHECK; i = (i + i); A0; } else \\\n  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }\n#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)\n#define TREE_DECODE_CHECK(probs, limit, i) \\\n  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }\n\n\n#define kNumPosBitsMax 4\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\n\n#define kLenNumLowBits 3\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\n#define kLenNumMidBits 3\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\n#define kLenNumHighBits 8\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\n\n#define LenChoice 0\n#define LenChoice2 (LenChoice + 1)\n#define LenLow (LenChoice2 + 1)\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols)\n\n\n#define kNumStates 12\n#define kNumLitStates 7\n\n#define kStartPosModelIndex 4\n#define kEndPosModelIndex 14\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\n\n#define kNumPosSlotBits 6\n#define kNumLenToPosStates 4\n\n#define kNumAlignBits 4\n#define kAlignTableSize (1 << kNumAlignBits)\n\n#define kMatchMinLen 2\n#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\n\n#define IsMatch 0\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\n#define IsRepG0 (IsRep + kNumStates)\n#define IsRepG1 (IsRepG0 + kNumStates)\n#define IsRepG2 (IsRepG1 + kNumStates)\n#define IsRep0Long (IsRepG2 + kNumStates)\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\n#define LenCoder (Align + kAlignTableSize)\n#define RepLenCoder (LenCoder + kNumLenProbs)\n#define Literal (RepLenCoder + kNumLenProbs)\n\n#define LZMA_BASE_SIZE 1846\n#define LZMA_LIT_SIZE 768\n\n#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\n\n#if Literal != LZMA_BASE_SIZE\nStopCompilingDueBUG\n#endif\n\nstatic const Byte kLiteralNextStates[kNumStates * 2] =\n{\n  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\n  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\n};\n\n#define LZMA_DIC_MIN (1 << 12)\n\n/* First LZMA-symbol is always decoded.\nAnd it decodes new LZMA-symbols while (buf < bufLimit), but \"buf\" is without last normalization\nOut:\n  Result:\n    SZ_OK - OK\n    SZ_ERROR_DATA - Error\n  p->remainLen:\n    < kMatchSpecLenStart : normal remain\n    = kMatchSpecLenStart : finished\n    = kMatchSpecLenStart + 1 : Flush marker\n    = kMatchSpecLenStart + 2 : State Init Marker\n*/\n\nstatic int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\n{\n  CLzmaProb *probs = p->probs;\n\n  unsigned state = p->state;\n  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];\n  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;\n  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;\n  unsigned lc = p->prop.lc;\n\n  Byte *dic = p->dic;\n  SizeT dicBufSize = p->dicBufSize;\n  SizeT dicPos = p->dicPos;\n  \n  UInt32 processedPos = p->processedPos;\n  UInt32 checkDicSize = p->checkDicSize;\n  unsigned len = 0;\n\n  const Byte *buf = p->buf;\n  UInt32 range = p->range;\n  UInt32 code = p->code;\n\n  do\n  {\n    CLzmaProb *prob;\n    UInt32 bound;\n    unsigned ttt;\n    unsigned posState = processedPos & pbMask;\n\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\n    IF_BIT_0(prob)\n    {\n      unsigned symbol;\n      UPDATE_0(prob);\n      prob = probs + Literal;\n      if (checkDicSize != 0 || processedPos != 0)\n        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\n        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\n\n      if (state < kNumLitStates)\n      {\n        symbol = 1;\n        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\n      }\n      else\n      {\n        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\n        unsigned offs = 0x100;\n        symbol = 1;\n        do\n        {\n          unsigned bit;\n          CLzmaProb *probLit;\n          matchByte <<= 1;\n          bit = (matchByte & offs);\n          probLit = prob + offs + bit + symbol;\n          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\n        }\n        while (symbol < 0x100);\n      }\n      dic[dicPos++] = (Byte)symbol;\n      processedPos++;\n\n      state = kLiteralNextStates[state];\n      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\n      continue;\n    }\n    else\n    {\n      UPDATE_1(prob);\n      prob = probs + IsRep + state;\n      IF_BIT_0(prob)\n      {\n        UPDATE_0(prob);\n        state += kNumStates;\n        prob = probs + LenCoder;\n      }\n      else\n      {\n        UPDATE_1(prob);\n        if (checkDicSize == 0 && processedPos == 0)\n          return SZ_ERROR_DATA;\n        prob = probs + IsRepG0 + state;\n        IF_BIT_0(prob)\n        {\n          UPDATE_0(prob);\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\n          IF_BIT_0(prob)\n          {\n            UPDATE_0(prob);\n            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\n            dicPos++;\n            processedPos++;\n            state = state < kNumLitStates ? 9 : 11;\n            continue;\n          }\n          UPDATE_1(prob);\n        }\n        else\n        {\n          UInt32 distance;\n          UPDATE_1(prob);\n          prob = probs + IsRepG1 + state;\n          IF_BIT_0(prob)\n          {\n            UPDATE_0(prob);\n            distance = rep1;\n          }\n          else\n          {\n            UPDATE_1(prob);\n            prob = probs + IsRepG2 + state;\n            IF_BIT_0(prob)\n            {\n              UPDATE_0(prob);\n              distance = rep2;\n            }\n            else\n            {\n              UPDATE_1(prob);\n              distance = rep3;\n              rep3 = rep2;\n            }\n            rep2 = rep1;\n          }\n          rep1 = rep0;\n          rep0 = distance;\n        }\n        state = state < kNumLitStates ? 8 : 11;\n        prob = probs + RepLenCoder;\n      }\n      {\n        unsigned limit, offset;\n        CLzmaProb *probLen = prob + LenChoice;\n        IF_BIT_0(probLen)\n        {\n          UPDATE_0(probLen);\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\n          offset = 0;\n          limit = (1 << kLenNumLowBits);\n        }\n        else\n        {\n          UPDATE_1(probLen);\n          probLen = prob + LenChoice2;\n          IF_BIT_0(probLen)\n          {\n            UPDATE_0(probLen);\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\n            offset = kLenNumLowSymbols;\n            limit = (1 << kLenNumMidBits);\n          }\n          else\n          {\n            UPDATE_1(probLen);\n            probLen = prob + LenHigh;\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\n            limit = (1 << kLenNumHighBits);\n          }\n        }\n        TREE_DECODE(probLen, limit, len);\n        len += offset;\n      }\n\n      if (state >= kNumStates)\n      {\n        UInt32 distance;\n        prob = probs + PosSlot +\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);\n        TREE_6_DECODE(prob, distance);\n        if (distance >= kStartPosModelIndex)\n        {\n          unsigned posSlot = (unsigned)distance;\n          int numDirectBits = (int)(((distance >> 1) - 1));\n          distance = (2 | (distance & 1));\n          if (posSlot < kEndPosModelIndex)\n          {\n            distance <<= numDirectBits;\n            prob = probs + SpecPos + distance - posSlot - 1;\n            {\n              UInt32 mask = 1;\n              unsigned i = 1;\n              do\n              {\n                GET_BIT2(prob + i, i, ; , distance |= mask);\n                mask <<= 1;\n              }\n              while (--numDirectBits != 0);\n            }\n          }\n          else\n          {\n            numDirectBits -= kNumAlignBits;\n            do\n            {\n              NORMALIZE\n              range >>= 1;\n              \n              {\n                UInt32 t;\n                code -= range;\n                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */\n                distance = (distance << 1) + (t + 1);\n                code += range & t;\n              }\n              /*\n              distance <<= 1;\n              if (code >= range)\n              {\n                code -= range;\n                distance |= 1;\n              }\n              */\n            }\n            while (--numDirectBits != 0);\n            prob = probs + Align;\n            distance <<= kNumAlignBits;\n            {\n              unsigned i = 1;\n              GET_BIT2(prob + i, i, ; , distance |= 1);\n              GET_BIT2(prob + i, i, ; , distance |= 2);\n              GET_BIT2(prob + i, i, ; , distance |= 4);\n              GET_BIT2(prob + i, i, ; , distance |= 8);\n            }\n            if (distance == (UInt32)0xFFFFFFFF)\n            {\n              len += kMatchSpecLenStart;\n              state -= kNumStates;\n              break;\n            }\n          }\n        }\n        rep3 = rep2;\n        rep2 = rep1;\n        rep1 = rep0;\n        rep0 = distance + 1;\n        if (checkDicSize == 0)\n        {\n          if (distance >= processedPos)\n            return SZ_ERROR_DATA;\n        }\n        else if (distance >= checkDicSize)\n          return SZ_ERROR_DATA;\n        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\n        /* state = kLiteralNextStates[state]; */\n      }\n\n      len += kMatchMinLen;\n\n      if (limit == dicPos)\n        return SZ_ERROR_DATA;\n      {\n        SizeT rem = limit - dicPos;\n        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\n        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\n\n        processedPos += curLen;\n\n        len -= curLen;\n        if (pos + curLen <= dicBufSize)\n        {\n          Byte *dest = dic + dicPos;\n          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;\n          const Byte *lim = dest + curLen;\n          dicPos += curLen;\n          do\n            *(dest) = (Byte)*(dest + src);\n          while (++dest != lim);\n        }\n        else\n        {\n          do\n          {\n            dic[dicPos++] = dic[pos];\n            if (++pos == dicBufSize)\n              pos = 0;\n          }\n          while (--curLen != 0);\n        }\n      }\n    }\n  }\n  while (dicPos < limit && buf < bufLimit);\n  NORMALIZE;\n  p->buf = buf;\n  p->range = range;\n  p->code = code;\n  p->remainLen = len;\n  p->dicPos = dicPos;\n  p->processedPos = processedPos;\n  p->reps[0] = rep0;\n  p->reps[1] = rep1;\n  p->reps[2] = rep2;\n  p->reps[3] = rep3;\n  p->state = state;\n\n  return SZ_OK;\n}\n\nstatic void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)\n{\n  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)\n  {\n    Byte *dic = p->dic;\n    SizeT dicPos = p->dicPos;\n    SizeT dicBufSize = p->dicBufSize;\n    unsigned len = p->remainLen;\n    UInt32 rep0 = p->reps[0];\n    if (limit - dicPos < len)\n      len = (unsigned)(limit - dicPos);\n\n    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\n      p->checkDicSize = p->prop.dicSize;\n\n    p->processedPos += len;\n    p->remainLen -= len;\n    while (len-- != 0)\n    {\n      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\n      dicPos++;\n    }\n    p->dicPos = dicPos;\n  }\n}\n\nstatic int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\n{\n  do\n  {\n    SizeT limit2 = limit;\n    if (p->checkDicSize == 0)\n    {\n      UInt32 rem = p->prop.dicSize - p->processedPos;\n      if (limit - p->dicPos > rem)\n        limit2 = p->dicPos + rem;\n    }\n    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\n    if (p->processedPos >= p->prop.dicSize)\n      p->checkDicSize = p->prop.dicSize;\n    LzmaDec_WriteRem(p, limit);\n  }\n  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\n\n  if (p->remainLen > kMatchSpecLenStart)\n  {\n    p->remainLen = kMatchSpecLenStart;\n  }\n  return 0;\n}\n\ntypedef enum\n{\n  DUMMY_ERROR, /* unexpected end of input stream */\n  DUMMY_LIT,\n  DUMMY_MATCH,\n  DUMMY_REP\n} ELzmaDummy;\n\nstatic ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)\n{\n  UInt32 range = p->range;\n  UInt32 code = p->code;\n  const Byte *bufLimit = buf + inSize;\n  CLzmaProb *probs = p->probs;\n  unsigned state = p->state;\n  ELzmaDummy res;\n\n  {\n    CLzmaProb *prob;\n    UInt32 bound;\n    unsigned ttt;\n    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\n\n    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;\n    IF_BIT_0_CHECK(prob)\n    {\n      UPDATE_0_CHECK\n\n      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */\n\n      prob = probs + Literal;\n      if (p->checkDicSize != 0 || p->processedPos != 0)\n        prob += (LZMA_LIT_SIZE *\n          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\n          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\n\n      if (state < kNumLitStates)\n      {\n        unsigned symbol = 1;\n        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);\n      }\n      else\n      {\n        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\n            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\n        unsigned offs = 0x100;\n        unsigned symbol = 1;\n        do\n        {\n          unsigned bit;\n          CLzmaProb *probLit;\n          matchByte <<= 1;\n          bit = (matchByte & offs);\n          probLit = prob + offs + bit + symbol;\n          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)\n        }\n        while (symbol < 0x100);\n      }\n      res = DUMMY_LIT;\n    }\n    else\n    {\n      unsigned len;\n      UPDATE_1_CHECK;\n\n      prob = probs + IsRep + state;\n      IF_BIT_0_CHECK(prob)\n      {\n        UPDATE_0_CHECK;\n        state = 0;\n        prob = probs + LenCoder;\n        res = DUMMY_MATCH;\n      }\n      else\n      {\n        UPDATE_1_CHECK;\n        res = DUMMY_REP;\n        prob = probs + IsRepG0 + state;\n        IF_BIT_0_CHECK(prob)\n        {\n          UPDATE_0_CHECK;\n          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;\n          IF_BIT_0_CHECK(prob)\n          {\n            UPDATE_0_CHECK;\n            NORMALIZE_CHECK;\n            return DUMMY_REP;\n          }\n          else\n          {\n            UPDATE_1_CHECK;\n          }\n        }\n        else\n        {\n          UPDATE_1_CHECK;\n          prob = probs + IsRepG1 + state;\n          IF_BIT_0_CHECK(prob)\n          {\n            UPDATE_0_CHECK;\n          }\n          else\n          {\n            UPDATE_1_CHECK;\n            prob = probs + IsRepG2 + state;\n            IF_BIT_0_CHECK(prob)\n            {\n              UPDATE_0_CHECK;\n            }\n            else\n            {\n              UPDATE_1_CHECK;\n            }\n          }\n        }\n        state = kNumStates;\n        prob = probs + RepLenCoder;\n      }\n      {\n        unsigned limit, offset;\n        CLzmaProb *probLen = prob + LenChoice;\n        IF_BIT_0_CHECK(probLen)\n        {\n          UPDATE_0_CHECK;\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\n          offset = 0;\n          limit = 1 << kLenNumLowBits;\n        }\n        else\n        {\n          UPDATE_1_CHECK;\n          probLen = prob + LenChoice2;\n          IF_BIT_0_CHECK(probLen)\n          {\n            UPDATE_0_CHECK;\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\n            offset = kLenNumLowSymbols;\n            limit = 1 << kLenNumMidBits;\n          }\n          else\n          {\n            UPDATE_1_CHECK;\n            probLen = prob + LenHigh;\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\n            limit = 1 << kLenNumHighBits;\n          }\n        }\n        TREE_DECODE_CHECK(probLen, limit, len);\n        len += offset;\n      }\n\n      if (state < 4)\n      {\n        unsigned posSlot;\n        prob = probs + PosSlot +\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<\n            kNumPosSlotBits);\n        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\n        if (posSlot >= kStartPosModelIndex)\n        {\n          int numDirectBits = ((posSlot >> 1) - 1);\n\n          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\n\n          if (posSlot < kEndPosModelIndex)\n          {\n            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;\n          }\n          else\n          {\n            numDirectBits -= kNumAlignBits;\n            do\n            {\n              NORMALIZE_CHECK\n              range >>= 1;\n              code -= range & (((code - range) >> 31) - 1);\n              /* if (code >= range) code -= range; */\n            }\n            while (--numDirectBits != 0);\n            prob = probs + Align;\n            numDirectBits = kNumAlignBits;\n          }\n          {\n            unsigned i = 1;\n            do\n            {\n              GET_BIT_CHECK(prob + i, i);\n            }\n            while (--numDirectBits != 0);\n          }\n        }\n      }\n    }\n  }\n  NORMALIZE_CHECK;\n  return res;\n}\n\n\nstatic void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\n{\n  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\n  p->range = 0xFFFFFFFF;\n  p->needFlush = 0;\n}\n\nvoid LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\n{\n  p->needFlush = 1;\n  p->remainLen = 0;\n  p->tempBufSize = 0;\n\n  if (initDic)\n  {\n    p->processedPos = 0;\n    p->checkDicSize = 0;\n    p->needInitState = 1;\n  }\n  if (initState)\n    p->needInitState = 1;\n}\n\nvoid LzmaDec_Init(CLzmaDec *p)\n{\n  p->dicPos = 0;\n  LzmaDec_InitDicAndState(p, True, True);\n}\n\nstatic void LzmaDec_InitStateReal(CLzmaDec *p)\n{\n  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\n  UInt32 i;\n  CLzmaProb *probs = p->probs;\n  for (i = 0; i < numProbs; i++)\n    probs[i] = kBitModelTotal >> 1;\n  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;\n  p->state = 0;\n  p->needInitState = 0;\n}\n\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,\n    ELzmaFinishMode finishMode, ELzmaStatus *status)\n{\n  SizeT inSize = *srcLen;\n  (*srcLen) = 0;\n  LzmaDec_WriteRem(p, dicLimit);\n  \n  *status = LZMA_STATUS_NOT_SPECIFIED;\n\n  while (p->remainLen != kMatchSpecLenStart)\n  {\n      int checkEndMarkNow;\n\n      if (p->needFlush != 0)\n      {\n        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\n          p->tempBuf[p->tempBufSize++] = *src++;\n        if (p->tempBufSize < RC_INIT_SIZE)\n        {\n          *status = LZMA_STATUS_NEEDS_MORE_INPUT;\n          return SZ_OK;\n        }\n        if (p->tempBuf[0] != 0)\n          return SZ_ERROR_DATA;\n\n        LzmaDec_InitRc(p, p->tempBuf);\n        p->tempBufSize = 0;\n      }\n\n      checkEndMarkNow = 0;\n      if (p->dicPos >= dicLimit)\n      {\n        if (p->remainLen == 0 && p->code == 0)\n        {\n          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;\n          return SZ_OK;\n        }\n        if (finishMode == LZMA_FINISH_ANY)\n        {\n          *status = LZMA_STATUS_NOT_FINISHED;\n          return SZ_OK;\n        }\n        if (p->remainLen != 0)\n        {\n          *status = LZMA_STATUS_NOT_FINISHED;\n          return SZ_ERROR_DATA;\n        }\n        checkEndMarkNow = 1;\n      }\n\n      if (p->needInitState)\n        LzmaDec_InitStateReal(p);\n  \n      if (p->tempBufSize == 0)\n      {\n        SizeT processed;\n        const Byte *bufLimit;\n        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\n        {\n          int dummyRes = LzmaDec_TryDummy(p, src, inSize);\n          if (dummyRes == DUMMY_ERROR)\n          {\n            memcpy(p->tempBuf, src, inSize);\n            p->tempBufSize = (unsigned)inSize;\n            (*srcLen) += inSize;\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\n            return SZ_OK;\n          }\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\n          {\n            *status = LZMA_STATUS_NOT_FINISHED;\n            return SZ_ERROR_DATA;\n          }\n          bufLimit = src;\n        }\n        else\n          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;\n        p->buf = src;\n        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)\n          return SZ_ERROR_DATA;\n        processed = (SizeT)(p->buf - src);\n        (*srcLen) += processed;\n        src += processed;\n        inSize -= processed;\n      }\n      else\n      {\n        unsigned rem = p->tempBufSize, lookAhead = 0;\n        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)\n          p->tempBuf[rem++] = src[lookAhead++];\n        p->tempBufSize = rem;\n        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)\n        {\n          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);\n          if (dummyRes == DUMMY_ERROR)\n          {\n            (*srcLen) += lookAhead;\n            *status = LZMA_STATUS_NEEDS_MORE_INPUT;\n            return SZ_OK;\n          }\n          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)\n          {\n            *status = LZMA_STATUS_NOT_FINISHED;\n            return SZ_ERROR_DATA;\n          }\n        }\n        p->buf = p->tempBuf;\n        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\n          return SZ_ERROR_DATA;\n        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\n        (*srcLen) += lookAhead;\n        src += lookAhead;\n        inSize -= lookAhead;\n        p->tempBufSize = 0;\n      }\n  }\n  if (p->code == 0)\n    *status = LZMA_STATUS_FINISHED_WITH_MARK;\n  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;\n}\n\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)\n{\n  SizeT outSize = *destLen;\n  SizeT inSize = *srcLen;\n  *srcLen = *destLen = 0;\n  for (;;)\n  {\n    SizeT inSizeCur = inSize, outSizeCur, dicPos;\n    ELzmaFinishMode curFinishMode;\n    SRes res;\n    if (p->dicPos == p->dicBufSize)\n      p->dicPos = 0;\n    dicPos = p->dicPos;\n    if (outSize > p->dicBufSize - dicPos)\n    {\n      outSizeCur = p->dicBufSize;\n      curFinishMode = LZMA_FINISH_ANY;\n    }\n    else\n    {\n      outSizeCur = dicPos + outSize;\n      curFinishMode = finishMode;\n    }\n\n    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);\n    src += inSizeCur;\n    inSize -= inSizeCur;\n    *srcLen += inSizeCur;\n    outSizeCur = p->dicPos - dicPos;\n    memcpy(dest, p->dic + dicPos, outSizeCur);\n    dest += outSizeCur;\n    outSize -= outSizeCur;\n    *destLen += outSizeCur;\n    if (res != 0)\n      return res;\n    if (outSizeCur == 0 || outSize == 0)\n      return SZ_OK;\n  }\n}\n\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\n{\n  alloc->Free(alloc, p->probs);\n  p->probs = 0;\n}\n\nstatic void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\n{\n  alloc->Free(alloc, p->dic);\n  p->dic = 0;\n}\n\nvoid LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\n{\n  LzmaDec_FreeProbs(p, alloc);\n  LzmaDec_FreeDict(p, alloc);\n}\n\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)\n{\n  UInt32 dicSize;\n  Byte d;\n  \n  if (size < LZMA_PROPS_SIZE)\n    return SZ_ERROR_UNSUPPORTED;\n  else\n    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);\n \n  if (dicSize < LZMA_DIC_MIN)\n    dicSize = LZMA_DIC_MIN;\n  p->dicSize = dicSize;\n\n  d = data[0];\n  if (d >= (9 * 5 * 5))\n    return SZ_ERROR_UNSUPPORTED;\n\n  p->lc = d % 9;\n  d /= 9;\n  p->pb = d / 5;\n  p->lp = d % 5;\n\n  return SZ_OK;\n}\n\nstatic SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\n{\n  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\n  if (p->probs == 0 || numProbs != p->numProbs)\n  {\n    LzmaDec_FreeProbs(p, alloc);\n    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\n    p->numProbs = numProbs;\n    if (p->probs == 0)\n      return SZ_ERROR_MEM;\n  }\n  return SZ_OK;\n}\n\nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\n{\n  CLzmaProps propNew;\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\n  p->prop = propNew;\n  return SZ_OK;\n}\n\nSRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)\n{\n  CLzmaProps propNew;\n  SizeT dicBufSize;\n  RINOK(LzmaProps_Decode(&propNew, props, propsSize));\n  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\n  dicBufSize = propNew.dicSize;\n  if (p->dic == 0 || dicBufSize != p->dicBufSize)\n  {\n    LzmaDec_FreeDict(p, alloc);\n    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\n    if (p->dic == 0)\n    {\n      LzmaDec_FreeProbs(p, alloc);\n      return SZ_ERROR_MEM;\n    }\n  }\n  p->dicBufSize = dicBufSize;\n  p->prop = propNew;\n  return SZ_OK;\n}\n\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\n    ELzmaStatus *status, ISzAlloc *alloc)\n{\n  CLzmaDec p;\n  SRes res;\n  SizeT inSize = *srcLen;\n  SizeT outSize = *destLen;\n  *srcLen = *destLen = 0;\n  if (inSize < RC_INIT_SIZE)\n    return SZ_ERROR_INPUT_EOF;\n\n  LzmaDec_Construct(&p);\n  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\n  if (res != 0)\n    return res;\n  p.dic = dest;\n  p.dicBufSize = outSize;\n\n  LzmaDec_Init(&p);\n  \n  *srcLen = inSize;\n  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\n\n  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\n    res = SZ_ERROR_INPUT_EOF;\n\n  (*destLen) = p.dicPos;\n  LzmaDec_FreeProbs(&p, alloc);\n  return res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaDec.h",
    "content": "/* LzmaDec.h -- LZMA Decoder\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __LZMADEC_H\n#define __LZMADEC_H\n\n#include \"Types.h\"\n\n/* #define _LZMA_PROB32 */\n/* _LZMA_PROB32 can increase the speed on some CPUs,\n   but memory usage for CLzmaDec::probs will be doubled in that case */\n\n#ifdef _LZMA_PROB32\n#define CLzmaProb UInt32\n#else\n#define CLzmaProb UInt16\n#endif\n\n\n/* ---------- LZMA Properties ---------- */\n\n#define LZMA_PROPS_SIZE 5\n\ntypedef struct _CLzmaProps\n{\n  unsigned lc, lp, pb;\n  UInt32 dicSize;\n} CLzmaProps;\n\n/* LzmaProps_Decode - decodes properties\nReturns:\n  SZ_OK\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\n*/\n\nSRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);\n\n\n/* ---------- LZMA Decoder state ---------- */\n\n/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.\n   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */\n\n#define LZMA_REQUIRED_INPUT_MAX 20\n\ntypedef struct\n{\n  CLzmaProps prop;\n  CLzmaProb *probs;\n  Byte *dic;\n  const Byte *buf;\n  UInt32 range, code;\n  SizeT dicPos;\n  SizeT dicBufSize;\n  UInt32 processedPos;\n  UInt32 checkDicSize;\n  unsigned state;\n  UInt32 reps[4];\n  unsigned remainLen;\n  int needFlush;\n  int needInitState;\n  UInt32 numProbs;\n  unsigned tempBufSize;\n  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];\n} CLzmaDec;\n\n#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }\n\nvoid LzmaDec_Init(CLzmaDec *p);\n\n/* There are two types of LZMA streams:\n     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.\n     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */\n\ntypedef enum\n{\n  LZMA_FINISH_ANY,   /* finish at any point */\n  LZMA_FINISH_END    /* block must be finished at the end */\n} ELzmaFinishMode;\n\n/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!\n\n   You must use LZMA_FINISH_END, when you know that current output buffer\n   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.\n\n   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,\n   and output value of destLen will be less than output buffer size limit.\n   You can check status result also.\n\n   You can use multiple checks to test data integrity after full decompression:\n     1) Check Result and \"status\" variable.\n     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\n     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.\n        You must use correct finish mode in that case. */\n\ntypedef enum\n{\n  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */\n  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */\n  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */\n  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */\n  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */\n} ELzmaStatus;\n\n/* ELzmaStatus is used only as output value for function call */\n\n\n/* ---------- Interfaces ---------- */\n\n/* There are 3 levels of interfaces:\n     1) Dictionary Interface\n     2) Buffer Interface\n     3) One Call Interface\n   You can select any of these interfaces, but don't mix functions from different\n   groups for same object. */\n\n\n/* There are two variants to allocate state for Dictionary Interface:\n     1) LzmaDec_Allocate / LzmaDec_Free\n     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs\n   You can use variant 2, if you set dictionary buffer manually.\n   For Buffer Interface you must always use variant 1.\n\nLzmaDec_Allocate* can return:\n  SZ_OK\n  SZ_ERROR_MEM         - Memory allocation error\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\n*/\n   \nSRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);\nvoid LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);\n\nSRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);\nvoid LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);\n\n/* ---------- Dictionary Interface ---------- */\n\n/* You can use it, if you want to eliminate the overhead for data copying from\n   dictionary to some other external buffer.\n   You must work with CLzmaDec variables directly in this interface.\n\n   STEPS:\n     LzmaDec_Constr()\n     LzmaDec_Allocate()\n     for (each new stream)\n     {\n       LzmaDec_Init()\n       while (it needs more decompression)\n       {\n         LzmaDec_DecodeToDic()\n         use data from CLzmaDec::dic and update CLzmaDec::dicPos\n       }\n     }\n     LzmaDec_Free()\n*/\n\n/* LzmaDec_DecodeToDic\n   \n   The decoding to internal dictionary buffer (CLzmaDec::dic).\n   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!\n\nfinishMode:\n  It has meaning only if the decoding reaches output limit (dicLimit).\n  LZMA_FINISH_ANY - Decode just dicLimit bytes.\n  LZMA_FINISH_END - Stream must be finished after dicLimit.\n\nReturns:\n  SZ_OK\n    status:\n      LZMA_STATUS_FINISHED_WITH_MARK\n      LZMA_STATUS_NOT_FINISHED\n      LZMA_STATUS_NEEDS_MORE_INPUT\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\n  SZ_ERROR_DATA - Data error\n*/\n\nSRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\n\n\n/* ---------- Buffer Interface ---------- */\n\n/* It's zlib-like interface.\n   See LzmaDec_DecodeToDic description for information about STEPS and return results,\n   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need\n   to work with CLzmaDec variables manually.\n\nfinishMode:\n  It has meaning only if the decoding reaches output limit (*destLen).\n  LZMA_FINISH_ANY - Decode just destLen bytes.\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\n*/\n\nSRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,\n    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);\n\n\n/* ---------- One Call Interface ---------- */\n\n/* LzmaDecode\n\nfinishMode:\n  It has meaning only if the decoding reaches output limit (*destLen).\n  LZMA_FINISH_ANY - Decode just destLen bytes.\n  LZMA_FINISH_END - Stream must be finished after (*destLen).\n\nReturns:\n  SZ_OK\n    status:\n      LZMA_STATUS_FINISHED_WITH_MARK\n      LZMA_STATUS_NOT_FINISHED\n      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\n  SZ_ERROR_DATA - Data error\n  SZ_ERROR_MEM  - Memory allocation error\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\n  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\n*/\n\nSRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\n    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\n    ELzmaStatus *status, ISzAlloc *alloc);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaEnc.c",
    "content": "/* LzmaEnc.c -- LZMA Encoder\n2009-02-02 : Igor Pavlov : Public domain */\n\n#include <string.h>\n\n/* #define SHOW_STAT */\n/* #define SHOW_STAT2 */\n\n#if defined(SHOW_STAT) || defined(SHOW_STAT2)\n#include <stdio.h>\n#endif\n\n#include \"LzmaEnc.h\"\n\n#include \"LzFind.h\"\n#ifdef COMPRESS_MF_MT\n#include \"LzFindMt.h\"\n#endif\n\n#ifdef SHOW_STAT\nstatic int ttt = 0;\n#endif\n\n#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)\n\n#define kBlockSize (9 << 10)\n#define kUnpackBlockSize (1 << 18)\n#define kMatchArraySize (1 << 21)\n#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)\n\n#define kNumMaxDirectBits (31)\n\n#define kNumTopBits 24\n#define kTopValue ((UInt32)1 << kNumTopBits)\n\n#define kNumBitModelTotalBits 11\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\n#define kNumMoveBits 5\n#define kProbInitValue (kBitModelTotal >> 1)\n\n#define kNumMoveReducingBits 4\n#define kNumBitPriceShiftBits 4\n#define kBitPrice (1 << kNumBitPriceShiftBits)\n\nvoid LzmaEncProps_Init(CLzmaEncProps *p)\n{\n  p->level = 5;\n  p->dictSize = p->mc = 0;\n  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\n  p->writeEndMark = 0;\n}\n\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p)\n{\n  int level = p->level;\n  if (level < 0) level = 5;\n  p->level = level;\n  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));\n  if (p->lc < 0) p->lc = 3;\n  if (p->lp < 0) p->lp = 0;\n  if (p->pb < 0) p->pb = 2;\n  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);\n  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);\n  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);\n  if (p->numHashBytes < 0) p->numHashBytes = 4;\n  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\n  if (p->numThreads < 0)\n    p->numThreads =\n      #ifdef COMPRESS_MF_MT\n      ((p->btMode && p->algo) ? 2 : 1);\n      #else\n      1;\n      #endif\n}\n\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)\n{\n  CLzmaEncProps props = *props2;\n  LzmaEncProps_Normalize(&props);\n  return props.dictSize;\n}\n\n/* #define LZMA_LOG_BSR */\n/* Define it for Intel's CPU */\n\n\n#ifdef LZMA_LOG_BSR\n\n#define kDicLogSizeMaxCompress 30\n\n#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }\n\nUInt32 GetPosSlot1(UInt32 pos)\n{\n  UInt32 res;\n  BSR2_RET(pos, res);\n  return res;\n}\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\n#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }\n\n#else\n\n#define kNumLogBits (9 + (int)sizeof(size_t) / 2)\n#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)\n\nvoid LzmaEnc_FastPosInit(Byte *g_FastPos)\n{\n  int c = 2, slotFast;\n  g_FastPos[0] = 0;\n  g_FastPos[1] = 1;\n  \n  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)\n  {\n    UInt32 k = (1 << ((slotFast >> 1) - 1));\n    UInt32 j;\n    for (j = 0; j < k; j++, c++)\n      g_FastPos[c] = (Byte)slotFast;\n  }\n}\n\n#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \\\n  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \\\n  res = p->g_FastPos[pos >> i] + (i * 2); }\n/*\n#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \\\n  p->g_FastPos[pos >> 6] + 12 : \\\n  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }\n*/\n\n#define GetPosSlot1(pos) p->g_FastPos[pos]\n#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }\n#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }\n\n#endif\n\n\n#define LZMA_NUM_REPS 4\n\ntypedef unsigned CState;\n\ntypedef struct _COptimal\n{\n  UInt32 price;\n\n  CState state;\n  int prev1IsChar;\n  int prev2;\n\n  UInt32 posPrev2;\n  UInt32 backPrev2;\n\n  UInt32 posPrev;\n  UInt32 backPrev;\n  UInt32 backs[LZMA_NUM_REPS];\n} COptimal;\n\n#define kNumOpts (1 << 12)\n\n#define kNumLenToPosStates 4\n#define kNumPosSlotBits 6\n#define kDicLogSizeMin 0\n#define kDicLogSizeMax 32\n#define kDistTableSizeMax (kDicLogSizeMax * 2)\n\n\n#define kNumAlignBits 4\n#define kAlignTableSize (1 << kNumAlignBits)\n#define kAlignMask (kAlignTableSize - 1)\n\n#define kStartPosModelIndex 4\n#define kEndPosModelIndex 14\n#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)\n\n#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\n\n#ifdef _LZMA_PROB32\n#define CLzmaProb UInt32\n#else\n#define CLzmaProb UInt16\n#endif\n\n#define LZMA_PB_MAX 4\n#define LZMA_LC_MAX 8\n#define LZMA_LP_MAX 4\n\n#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)\n\n\n#define kLenNumLowBits 3\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\n#define kLenNumMidBits 3\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\n#define kLenNumHighBits 8\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\n\n#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)\n\n#define LZMA_MATCH_LEN_MIN 2\n#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)\n\n#define kNumStates 12\n\ntypedef struct\n{\n  CLzmaProb choice;\n  CLzmaProb choice2;\n  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];\n  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];\n  CLzmaProb high[kLenNumHighSymbols];\n} CLenEnc;\n\ntypedef struct\n{\n  CLenEnc p;\n  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\n  UInt32 tableSize;\n  UInt32 counters[LZMA_NUM_PB_STATES_MAX];\n} CLenPriceEnc;\n\ntypedef struct _CRangeEnc\n{\n  UInt32 range;\n  Byte cache;\n  UInt64 low;\n  UInt64 cacheSize;\n  Byte *buf;\n  Byte *bufLim;\n  Byte *bufBase;\n  ISeqOutStream *outStream;\n  UInt64 processed;\n  SRes res;\n} CRangeEnc;\n\ntypedef struct _CSeqInStreamBuf\n{\n  ISeqInStream funcTable;\n  const Byte *data;\n  SizeT rem;\n} CSeqInStreamBuf;\n\nstatic SRes MyRead(void *pp, void *data, size_t *size)\n{\n  size_t curSize = *size;\n  CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;\n  if (p->rem < curSize)\n    curSize = p->rem;\n  memcpy(data, p->data, curSize);\n  p->rem -= curSize;\n  p->data += curSize;\n  *size = curSize;\n  return SZ_OK;\n}\n\ntypedef struct\n{\n  CLzmaProb *litProbs;\n\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\n  CLzmaProb isRep[kNumStates];\n  CLzmaProb isRepG0[kNumStates];\n  CLzmaProb isRepG1[kNumStates];\n  CLzmaProb isRepG2[kNumStates];\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\n\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\n  \n  CLenPriceEnc lenEnc;\n  CLenPriceEnc repLenEnc;\n\n  UInt32 reps[LZMA_NUM_REPS];\n  UInt32 state;\n} CSaveState;\n\ntypedef struct _CLzmaEnc\n{\n  IMatchFinder matchFinder;\n  void *matchFinderObj;\n\n  #ifdef COMPRESS_MF_MT\n  Bool mtMode;\n  CMatchFinderMt matchFinderMt;\n  #endif\n\n  CMatchFinder matchFinderBase;\n\n  #ifdef COMPRESS_MF_MT\n  Byte pad[128];\n  #endif\n  \n  UInt32 optimumEndIndex;\n  UInt32 optimumCurrentIndex;\n\n  UInt32 longestMatchLength;\n  UInt32 numPairs;\n  UInt32 numAvail;\n  COptimal opt[kNumOpts];\n  \n  #ifndef LZMA_LOG_BSR\n  Byte g_FastPos[1 << kNumLogBits];\n  #endif\n\n  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\n  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];\n  UInt32 numFastBytes;\n  UInt32 additionalOffset;\n  UInt32 reps[LZMA_NUM_REPS];\n  UInt32 state;\n\n  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\n  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];\n  UInt32 alignPrices[kAlignTableSize];\n  UInt32 alignPriceCount;\n\n  UInt32 distTableSize;\n\n  unsigned lc, lp, pb;\n  unsigned lpMask, pbMask;\n\n  CLzmaProb *litProbs;\n\n  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\n  CLzmaProb isRep[kNumStates];\n  CLzmaProb isRepG0[kNumStates];\n  CLzmaProb isRepG1[kNumStates];\n  CLzmaProb isRepG2[kNumStates];\n  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];\n\n  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];\n  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];\n  CLzmaProb posAlignEncoder[1 << kNumAlignBits];\n  \n  CLenPriceEnc lenEnc;\n  CLenPriceEnc repLenEnc;\n\n  unsigned lclp;\n\n  Bool fastMode;\n  \n  CRangeEnc rc;\n\n  Bool writeEndMark;\n  UInt64 nowPos64;\n  UInt32 matchPriceCount;\n  Bool finished;\n  Bool multiThread;\n\n  SRes result;\n  UInt32 dictSize;\n  UInt32 matchFinderCycles;\n\n  ISeqInStream *inStream;\n  CSeqInStreamBuf seqBufInStream;\n\n  CSaveState saveState;\n} CLzmaEnc;\n\nvoid LzmaEnc_SaveState(CLzmaEncHandle pp)\n{\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n  CSaveState *dest = &p->saveState;\n  int i;\n  dest->lenEnc = p->lenEnc;\n  dest->repLenEnc = p->repLenEnc;\n  dest->state = p->state;\n\n  for (i = 0; i < kNumStates; i++)\n  {\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\n  }\n  for (i = 0; i < kNumLenToPosStates; i++)\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\n  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));\n}\n\nvoid LzmaEnc_RestoreState(CLzmaEncHandle pp)\n{\n  CLzmaEnc *dest = (CLzmaEnc *)pp;\n  const CSaveState *p = &dest->saveState;\n  int i;\n  dest->lenEnc = p->lenEnc;\n  dest->repLenEnc = p->repLenEnc;\n  dest->state = p->state;\n\n  for (i = 0; i < kNumStates; i++)\n  {\n    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));\n    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));\n  }\n  for (i = 0; i < kNumLenToPosStates; i++)\n    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));\n  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));\n  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));\n  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));\n  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));\n  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\n  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\n  memcpy(dest->reps, p->reps, sizeof(p->reps));\n  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));\n}\n\nSRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)\n{\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n  CLzmaEncProps props = *props2;\n  LzmaEncProps_Normalize(&props);\n\n  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||\n      props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))\n    return SZ_ERROR_PARAM;\n  p->dictSize = props.dictSize;\n  p->matchFinderCycles = props.mc;\n  {\n    unsigned fb = props.fb;\n    if (fb < 5)\n      fb = 5;\n    if (fb > LZMA_MATCH_LEN_MAX)\n      fb = LZMA_MATCH_LEN_MAX;\n    p->numFastBytes = fb;\n  }\n  p->lc = props.lc;\n  p->lp = props.lp;\n  p->pb = props.pb;\n  p->fastMode = (props.algo == 0);\n  p->matchFinderBase.btMode = props.btMode;\n  {\n    UInt32 numHashBytes = 4;\n    if (props.btMode)\n    {\n      if (props.numHashBytes < 2)\n        numHashBytes = 2;\n      else if (props.numHashBytes < 4)\n        numHashBytes = props.numHashBytes;\n    }\n    p->matchFinderBase.numHashBytes = numHashBytes;\n  }\n\n  p->matchFinderBase.cutValue = props.mc;\n\n  p->writeEndMark = props.writeEndMark;\n\n  #ifdef COMPRESS_MF_MT\n  /*\n  if (newMultiThread != _multiThread)\n  {\n    ReleaseMatchFinder();\n    _multiThread = newMultiThread;\n  }\n  */\n  p->multiThread = (props.numThreads > 1);\n  #endif\n\n  return SZ_OK;\n}\n\nstatic const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\nstatic const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\nstatic const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\nstatic const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\n\n#define IsCharState(s) ((s) < 7)\n\n#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)\n\n#define kInfinityPrice (1 << 30)\n\nstatic void RangeEnc_Construct(CRangeEnc *p)\n{\n  p->outStream = 0;\n  p->bufBase = 0;\n}\n\n#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)\n\n#define RC_BUF_SIZE (1 << 16)\nstatic int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)\n{\n  if (p->bufBase == 0)\n  {\n    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);\n    if (p->bufBase == 0)\n      return 0;\n    p->bufLim = p->bufBase + RC_BUF_SIZE;\n  }\n  return 1;\n}\n\nstatic void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)\n{\n  alloc->Free(alloc, p->bufBase);\n  p->bufBase = 0;\n}\n\nstatic void RangeEnc_Init(CRangeEnc *p)\n{\n  /* Stream.Init(); */\n  p->low = 0;\n  p->range = 0xFFFFFFFF;\n  p->cacheSize = 1;\n  p->cache = 0;\n\n  p->buf = p->bufBase;\n\n  p->processed = 0;\n  p->res = SZ_OK;\n}\n\nstatic void RangeEnc_FlushStream(CRangeEnc *p)\n{\n  size_t num;\n  if (p->res != SZ_OK)\n    return;\n  num = p->buf - p->bufBase;\n  if (num != p->outStream->Write(p->outStream, p->bufBase, num))\n    p->res = SZ_ERROR_WRITE;\n  p->processed += num;\n  p->buf = p->bufBase;\n}\n\nstatic void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)\n{\n  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)\n  {\n    Byte temp = p->cache;\n    do\n    {\n      Byte *buf = p->buf;\n      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));\n      p->buf = buf;\n      if (buf == p->bufLim)\n        RangeEnc_FlushStream(p);\n      temp = 0xFF;\n    }\n    while (--p->cacheSize != 0);\n    p->cache = (Byte)((UInt32)p->low >> 24);\n  }\n  p->cacheSize++;\n  p->low = (UInt32)p->low << 8;\n}\n\nstatic void RangeEnc_FlushData(CRangeEnc *p)\n{\n  int i;\n  for (i = 0; i < 5; i++)\n    RangeEnc_ShiftLow(p);\n}\n\nstatic void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)\n{\n  do\n  {\n    p->range >>= 1;\n    p->low += p->range & (0 - ((value >> --numBits) & 1));\n    if (p->range < kTopValue)\n    {\n      p->range <<= 8;\n      RangeEnc_ShiftLow(p);\n    }\n  }\n  while (numBits != 0);\n}\n\nstatic void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)\n{\n  UInt32 ttt = *prob;\n  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;\n  if (symbol == 0)\n  {\n    p->range = newBound;\n    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;\n  }\n  else\n  {\n    p->low += newBound;\n    p->range -= newBound;\n    ttt -= ttt >> kNumMoveBits;\n  }\n  *prob = (CLzmaProb)ttt;\n  if (p->range < kTopValue)\n  {\n    p->range <<= 8;\n    RangeEnc_ShiftLow(p);\n  }\n}\n\nstatic void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)\n{\n  symbol |= 0x100;\n  do\n  {\n    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);\n    symbol <<= 1;\n  }\n  while (symbol < 0x10000);\n}\n\nstatic void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)\n{\n  UInt32 offs = 0x100;\n  symbol |= 0x100;\n  do\n  {\n    matchByte <<= 1;\n    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);\n    symbol <<= 1;\n    offs &= ~(matchByte ^ symbol);\n  }\n  while (symbol < 0x10000);\n}\n\nvoid LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\n{\n  UInt32 i;\n  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))\n  {\n    const int kCyclesBits = kNumBitPriceShiftBits;\n    UInt32 w = i;\n    UInt32 bitCount = 0;\n    int j;\n    for (j = 0; j < kCyclesBits; j++)\n    {\n      w = w * w;\n      bitCount <<= 1;\n      while (w >= ((UInt32)1 << 16))\n      {\n        w >>= 1;\n        bitCount++;\n      }\n    }\n    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);\n  }\n}\n\n\n#define GET_PRICE(prob, symbol) \\\n  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\n\n#define GET_PRICEa(prob, symbol) \\\n  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];\n\n#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]\n#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\n\n#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]\n#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\n\nstatic UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)\n{\n  UInt32 price = 0;\n  symbol |= 0x100;\n  do\n  {\n    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);\n    symbol <<= 1;\n  }\n  while (symbol < 0x10000);\n  return price;\n}\n\nstatic UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)\n{\n  UInt32 price = 0;\n  UInt32 offs = 0x100;\n  symbol |= 0x100;\n  do\n  {\n    matchByte <<= 1;\n    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);\n    symbol <<= 1;\n    offs &= ~(matchByte ^ symbol);\n  }\n  while (symbol < 0x10000);\n  return price;\n}\n\n\nstatic void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\n{\n  UInt32 m = 1;\n  int i;\n  for (i = numBitLevels; i != 0;)\n  {\n    UInt32 bit;\n    i--;\n    bit = (symbol >> i) & 1;\n    RangeEnc_EncodeBit(rc, probs + m, bit);\n    m = (m << 1) | bit;\n  }\n}\n\nstatic void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)\n{\n  UInt32 m = 1;\n  int i;\n  for (i = 0; i < numBitLevels; i++)\n  {\n    UInt32 bit = symbol & 1;\n    RangeEnc_EncodeBit(rc, probs + m, bit);\n    m = (m << 1) | bit;\n    symbol >>= 1;\n  }\n}\n\nstatic UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\n{\n  UInt32 price = 0;\n  symbol |= (1 << numBitLevels);\n  while (symbol != 1)\n  {\n    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);\n    symbol >>= 1;\n  }\n  return price;\n}\n\nstatic UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\n{\n  UInt32 price = 0;\n  UInt32 m = 1;\n  int i;\n  for (i = numBitLevels; i != 0; i--)\n  {\n    UInt32 bit = symbol & 1;\n    symbol >>= 1;\n    price += GET_PRICEa(probs[m], bit);\n    m = (m << 1) | bit;\n  }\n  return price;\n}\n\n\nstatic void LenEnc_Init(CLenEnc *p)\n{\n  unsigned i;\n  p->choice = p->choice2 = kProbInitValue;\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)\n    p->low[i] = kProbInitValue;\n  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)\n    p->mid[i] = kProbInitValue;\n  for (i = 0; i < kLenNumHighSymbols; i++)\n    p->high[i] = kProbInitValue;\n}\n\nstatic void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)\n{\n  if (symbol < kLenNumLowSymbols)\n  {\n    RangeEnc_EncodeBit(rc, &p->choice, 0);\n    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);\n  }\n  else\n  {\n    RangeEnc_EncodeBit(rc, &p->choice, 1);\n    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)\n    {\n      RangeEnc_EncodeBit(rc, &p->choice2, 0);\n      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);\n    }\n    else\n    {\n      RangeEnc_EncodeBit(rc, &p->choice2, 1);\n      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);\n    }\n  }\n}\n\nstatic void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)\n{\n  UInt32 a0 = GET_PRICE_0a(p->choice);\n  UInt32 a1 = GET_PRICE_1a(p->choice);\n  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);\n  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);\n  UInt32 i = 0;\n  for (i = 0; i < kLenNumLowSymbols; i++)\n  {\n    if (i >= numSymbols)\n      return;\n    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);\n  }\n  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)\n  {\n    if (i >= numSymbols)\n      return;\n    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);\n  }\n  for (; i < numSymbols; i++)\n    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);\n}\n\nstatic void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)\n{\n  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);\n  p->counters[posState] = p->tableSize;\n}\n\nstatic void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)\n{\n  UInt32 posState;\n  for (posState = 0; posState < numPosStates; posState++)\n    LenPriceEnc_UpdateTable(p, posState, ProbPrices);\n}\n\nstatic void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)\n{\n  LenEnc_Encode(&p->p, rc, symbol, posState);\n  if (updatePrice)\n    if (--p->counters[posState] == 0)\n      LenPriceEnc_UpdateTable(p, posState, ProbPrices);\n}\n\n\n\n\nstatic void MovePos(CLzmaEnc *p, UInt32 num)\n{\n  #ifdef SHOW_STAT\n  ttt += num;\n  printf(\"\\n MovePos %d\", num);\n  #endif\n  if (num != 0)\n  {\n    p->additionalOffset += num;\n    p->matchFinder.Skip(p->matchFinderObj, num);\n  }\n}\n\nstatic UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)\n{\n  UInt32 lenRes = 0, numPairs;\n  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\n  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);\n  #ifdef SHOW_STAT\n  printf(\"\\n i = %d numPairs = %d    \", ttt, numPairs / 2);\n  ttt++;\n  {\n    UInt32 i;\n    for (i = 0; i < numPairs; i += 2)\n      printf(\"%2d %6d   | \", p->matches[i], p->matches[i + 1]);\n  }\n  #endif\n  if (numPairs > 0)\n  {\n    lenRes = p->matches[numPairs - 2];\n    if (lenRes == p->numFastBytes)\n    {\n      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\n      UInt32 distance = p->matches[numPairs - 1] + 1;\n      UInt32 numAvail = p->numAvail;\n      if (numAvail > LZMA_MATCH_LEN_MAX)\n        numAvail = LZMA_MATCH_LEN_MAX;\n      {\n        const Byte *pby2 = pby - distance;\n        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\n      }\n    }\n  }\n  p->additionalOffset++;\n  *numDistancePairsRes = numPairs;\n  return lenRes;\n}\n\n\n#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;\n#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;\n#define IsShortRep(p) ((p)->backPrev == 0)\n\nstatic UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)\n{\n  return\n    GET_PRICE_0(p->isRepG0[state]) +\n    GET_PRICE_0(p->isRep0Long[state][posState]);\n}\n\nstatic UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)\n{\n  UInt32 price;\n  if (repIndex == 0)\n  {\n    price = GET_PRICE_0(p->isRepG0[state]);\n    price += GET_PRICE_1(p->isRep0Long[state][posState]);\n  }\n  else\n  {\n    price = GET_PRICE_1(p->isRepG0[state]);\n    if (repIndex == 1)\n      price += GET_PRICE_0(p->isRepG1[state]);\n    else\n    {\n      price += GET_PRICE_1(p->isRepG1[state]);\n      price += GET_PRICE(p->isRepG2[state], repIndex - 2);\n    }\n  }\n  return price;\n}\n\nstatic UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)\n{\n  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +\n    GetPureRepPrice(p, repIndex, state, posState);\n}\n\nstatic UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)\n{\n  UInt32 posMem = p->opt[cur].posPrev;\n  UInt32 backMem = p->opt[cur].backPrev;\n  p->optimumEndIndex = cur;\n  do\n  {\n    if (p->opt[cur].prev1IsChar)\n    {\n      MakeAsChar(&p->opt[posMem])\n      p->opt[posMem].posPrev = posMem - 1;\n      if (p->opt[cur].prev2)\n      {\n        p->opt[posMem - 1].prev1IsChar = False;\n        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;\n        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;\n      }\n    }\n    {\n      UInt32 posPrev = posMem;\n      UInt32 backCur = backMem;\n      \n      backMem = p->opt[posPrev].backPrev;\n      posMem = p->opt[posPrev].posPrev;\n      \n      p->opt[posPrev].backPrev = backCur;\n      p->opt[posPrev].posPrev = cur;\n      cur = posPrev;\n    }\n  }\n  while (cur != 0);\n  *backRes = p->opt[0].backPrev;\n  p->optimumCurrentIndex  = p->opt[0].posPrev;\n  return p->optimumCurrentIndex;\n}\n\n#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)\n\nstatic UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)\n{\n  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;\n  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\n  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];\n  UInt32 *matches;\n  const Byte *data;\n  Byte curByte, matchByte;\n  if (p->optimumEndIndex != p->optimumCurrentIndex)\n  {\n    const COptimal *opt = &p->opt[p->optimumCurrentIndex];\n    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;\n    *backRes = opt->backPrev;\n    p->optimumCurrentIndex = opt->posPrev;\n    return lenRes;\n  }\n  p->optimumCurrentIndex = p->optimumEndIndex = 0;\n  \n  if (p->additionalOffset == 0)\n    mainLen = ReadMatchDistances(p, &numPairs);\n  else\n  {\n    mainLen = p->longestMatchLength;\n    numPairs = p->numPairs;\n  }\n\n  numAvail = p->numAvail;\n  if (numAvail < 2)\n  {\n    *backRes = (UInt32)(-1);\n    return 1;\n  }\n  if (numAvail > LZMA_MATCH_LEN_MAX)\n    numAvail = LZMA_MATCH_LEN_MAX;\n\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\n  repMaxIndex = 0;\n  for (i = 0; i < LZMA_NUM_REPS; i++)\n  {\n    UInt32 lenTest;\n    const Byte *data2;\n    reps[i] = p->reps[i];\n    data2 = data - (reps[i] + 1);\n    if (data[0] != data2[0] || data[1] != data2[1])\n    {\n      repLens[i] = 0;\n      continue;\n    }\n    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\n    repLens[i] = lenTest;\n    if (lenTest > repLens[repMaxIndex])\n      repMaxIndex = i;\n  }\n  if (repLens[repMaxIndex] >= p->numFastBytes)\n  {\n    UInt32 lenRes;\n    *backRes = repMaxIndex;\n    lenRes = repLens[repMaxIndex];\n    MovePos(p, lenRes - 1);\n    return lenRes;\n  }\n\n  matches = p->matches;\n  if (mainLen >= p->numFastBytes)\n  {\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\n    MovePos(p, mainLen - 1);\n    return mainLen;\n  }\n  curByte = *data;\n  matchByte = *(data - (reps[0] + 1));\n\n  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)\n  {\n    *backRes = (UInt32)-1;\n    return 1;\n  }\n\n  p->opt[0].state = (CState)p->state;\n\n  posState = (position & p->pbMask);\n\n  {\n    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\n    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +\n        (!IsCharState(p->state) ?\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\n  }\n\n  MakeAsChar(&p->opt[1]);\n\n  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);\n  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);\n\n  if (matchByte == curByte)\n  {\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);\n    if (shortRepPrice < p->opt[1].price)\n    {\n      p->opt[1].price = shortRepPrice;\n      MakeAsShortRep(&p->opt[1]);\n    }\n  }\n  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);\n\n  if (lenEnd < 2)\n  {\n    *backRes = p->opt[1].backPrev;\n    return 1;\n  }\n\n  p->opt[1].posPrev = 0;\n  for (i = 0; i < LZMA_NUM_REPS; i++)\n    p->opt[0].backs[i] = reps[i];\n\n  len = lenEnd;\n  do\n    p->opt[len--].price = kInfinityPrice;\n  while (len >= 2);\n\n  for (i = 0; i < LZMA_NUM_REPS; i++)\n  {\n    UInt32 repLen = repLens[i];\n    UInt32 price;\n    if (repLen < 2)\n      continue;\n    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);\n    do\n    {\n      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];\n      COptimal *opt = &p->opt[repLen];\n      if (curAndLenPrice < opt->price)\n      {\n        opt->price = curAndLenPrice;\n        opt->posPrev = 0;\n        opt->backPrev = i;\n        opt->prev1IsChar = False;\n      }\n    }\n    while (--repLen >= 2);\n  }\n\n  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);\n\n  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\n  if (len <= mainLen)\n  {\n    UInt32 offs = 0;\n    while (len > matches[offs])\n      offs += 2;\n    for (; ; len++)\n    {\n      COptimal *opt;\n      UInt32 distance = matches[offs + 1];\n\n      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];\n      UInt32 lenToPosState = GetLenToPosState(len);\n      if (distance < kNumFullDistances)\n        curAndLenPrice += p->distancesPrices[lenToPosState][distance];\n      else\n      {\n        UInt32 slot;\n        GetPosSlot2(distance, slot);\n        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];\n      }\n      opt = &p->opt[len];\n      if (curAndLenPrice < opt->price)\n      {\n        opt->price = curAndLenPrice;\n        opt->posPrev = 0;\n        opt->backPrev = distance + LZMA_NUM_REPS;\n        opt->prev1IsChar = False;\n      }\n      if (len == matches[offs])\n      {\n        offs += 2;\n        if (offs == numPairs)\n          break;\n      }\n    }\n  }\n\n  cur = 0;\n\n    #ifdef SHOW_STAT2\n    if (position >= 0)\n    {\n      unsigned i;\n      printf(\"\\n pos = %4X\", position);\n      for (i = cur; i <= lenEnd; i++)\n      printf(\"\\nprice[%4X] = %d\", position - cur + i, p->opt[i].price);\n    }\n    #endif\n\n  for (;;)\n  {\n    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;\n    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;\n    Bool nextIsChar;\n    Byte curByte, matchByte;\n    const Byte *data;\n    COptimal *curOpt;\n    COptimal *nextOpt;\n\n    cur++;\n    if (cur == lenEnd)\n      return Backward(p, backRes, cur);\n\n    newLen = ReadMatchDistances(p, &numPairs);\n    if (newLen >= p->numFastBytes)\n    {\n      p->numPairs = numPairs;\n      p->longestMatchLength = newLen;\n      return Backward(p, backRes, cur);\n    }\n    position++;\n    curOpt = &p->opt[cur];\n    posPrev = curOpt->posPrev;\n    if (curOpt->prev1IsChar)\n    {\n      posPrev--;\n      if (curOpt->prev2)\n      {\n        state = p->opt[curOpt->posPrev2].state;\n        if (curOpt->backPrev2 < LZMA_NUM_REPS)\n          state = kRepNextStates[state];\n        else\n          state = kMatchNextStates[state];\n      }\n      else\n        state = p->opt[posPrev].state;\n      state = kLiteralNextStates[state];\n    }\n    else\n      state = p->opt[posPrev].state;\n    if (posPrev == cur - 1)\n    {\n      if (IsShortRep(curOpt))\n        state = kShortRepNextStates[state];\n      else\n        state = kLiteralNextStates[state];\n    }\n    else\n    {\n      UInt32 pos;\n      const COptimal *prevOpt;\n      if (curOpt->prev1IsChar && curOpt->prev2)\n      {\n        posPrev = curOpt->posPrev2;\n        pos = curOpt->backPrev2;\n        state = kRepNextStates[state];\n      }\n      else\n      {\n        pos = curOpt->backPrev;\n        if (pos < LZMA_NUM_REPS)\n          state = kRepNextStates[state];\n        else\n          state = kMatchNextStates[state];\n      }\n      prevOpt = &p->opt[posPrev];\n      if (pos < LZMA_NUM_REPS)\n      {\n        UInt32 i;\n        reps[0] = prevOpt->backs[pos];\n        for (i = 1; i <= pos; i++)\n          reps[i] = prevOpt->backs[i - 1];\n        for (; i < LZMA_NUM_REPS; i++)\n          reps[i] = prevOpt->backs[i];\n      }\n      else\n      {\n        UInt32 i;\n        reps[0] = (pos - LZMA_NUM_REPS);\n        for (i = 1; i < LZMA_NUM_REPS; i++)\n          reps[i] = prevOpt->backs[i - 1];\n      }\n    }\n    curOpt->state = (CState)state;\n\n    curOpt->backs[0] = reps[0];\n    curOpt->backs[1] = reps[1];\n    curOpt->backs[2] = reps[2];\n    curOpt->backs[3] = reps[3];\n\n    curPrice = curOpt->price;\n    nextIsChar = False;\n    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\n    curByte = *data;\n    matchByte = *(data - (reps[0] + 1));\n\n    posState = (position & p->pbMask);\n\n    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);\n    {\n      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));\n      curAnd1Price +=\n        (!IsCharState(state) ?\n          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :\n          LitEnc_GetPrice(probs, curByte, p->ProbPrices));\n    }\n\n    nextOpt = &p->opt[cur + 1];\n\n    if (curAnd1Price < nextOpt->price)\n    {\n      nextOpt->price = curAnd1Price;\n      nextOpt->posPrev = cur;\n      MakeAsChar(nextOpt);\n      nextIsChar = True;\n    }\n\n    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);\n    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);\n    \n    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))\n    {\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);\n      if (shortRepPrice <= nextOpt->price)\n      {\n        nextOpt->price = shortRepPrice;\n        nextOpt->posPrev = cur;\n        MakeAsShortRep(nextOpt);\n        nextIsChar = True;\n      }\n    }\n    numAvailFull = p->numAvail;\n    {\n      UInt32 temp = kNumOpts - 1 - cur;\n      if (temp < numAvailFull)\n        numAvailFull = temp;\n    }\n\n    if (numAvailFull < 2)\n      continue;\n    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);\n\n    if (!nextIsChar && matchByte != curByte) /* speed optimization */\n    {\n      /* try Literal + rep0 */\n      UInt32 temp;\n      UInt32 lenTest2;\n      const Byte *data2 = data - (reps[0] + 1);\n      UInt32 limit = p->numFastBytes + 1;\n      if (limit > numAvailFull)\n        limit = numAvailFull;\n\n      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);\n      lenTest2 = temp - 1;\n      if (lenTest2 >= 2)\n      {\n        UInt32 state2 = kLiteralNextStates[state];\n        UInt32 posStateNext = (position + 1) & p->pbMask;\n        UInt32 nextRepMatchPrice = curAnd1Price +\n            GET_PRICE_1(p->isMatch[state2][posStateNext]) +\n            GET_PRICE_1(p->isRep[state2]);\n        /* for (; lenTest2 >= 2; lenTest2--) */\n        {\n          UInt32 curAndLenPrice;\n          COptimal *opt;\n          UInt32 offset = cur + 1 + lenTest2;\n          while (lenEnd < offset)\n            p->opt[++lenEnd].price = kInfinityPrice;\n          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\n          opt = &p->opt[offset];\n          if (curAndLenPrice < opt->price)\n          {\n            opt->price = curAndLenPrice;\n            opt->posPrev = cur + 1;\n            opt->backPrev = 0;\n            opt->prev1IsChar = True;\n            opt->prev2 = False;\n          }\n        }\n      }\n    }\n    \n    startLen = 2; /* speed optimization */\n    {\n    UInt32 repIndex;\n    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)\n    {\n      UInt32 lenTest;\n      UInt32 lenTestTemp;\n      UInt32 price;\n      const Byte *data2 = data - (reps[repIndex] + 1);\n      if (data[0] != data2[0] || data[1] != data2[1])\n        continue;\n      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\n      while (lenEnd < cur + lenTest)\n        p->opt[++lenEnd].price = kInfinityPrice;\n      lenTestTemp = lenTest;\n      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);\n      do\n      {\n        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];\n        COptimal *opt = &p->opt[cur + lenTest];\n        if (curAndLenPrice < opt->price)\n        {\n          opt->price = curAndLenPrice;\n          opt->posPrev = cur;\n          opt->backPrev = repIndex;\n          opt->prev1IsChar = False;\n        }\n      }\n      while (--lenTest >= 2);\n      lenTest = lenTestTemp;\n      \n      if (repIndex == 0)\n        startLen = lenTest + 1;\n        \n      /* if (_maxMode) */\n        {\n          UInt32 lenTest2 = lenTest + 1;\n          UInt32 limit = lenTest2 + p->numFastBytes;\n          UInt32 nextRepMatchPrice;\n          if (limit > numAvailFull)\n            limit = numAvailFull;\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\n          lenTest2 -= lenTest + 1;\n          if (lenTest2 >= 2)\n          {\n            UInt32 state2 = kRepNextStates[state];\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\n            UInt32 curAndLenCharPrice =\n                price + p->repLenEnc.prices[posState][lenTest - 2] +\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\n                    data[lenTest], data2[lenTest], p->ProbPrices);\n            state2 = kLiteralNextStates[state2];\n            posStateNext = (position + lenTest + 1) & p->pbMask;\n            nextRepMatchPrice = curAndLenCharPrice +\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\n                GET_PRICE_1(p->isRep[state2]);\n            \n            /* for (; lenTest2 >= 2; lenTest2--) */\n            {\n              UInt32 curAndLenPrice;\n              COptimal *opt;\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\n              while (lenEnd < offset)\n                p->opt[++lenEnd].price = kInfinityPrice;\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\n              opt = &p->opt[offset];\n              if (curAndLenPrice < opt->price)\n              {\n                opt->price = curAndLenPrice;\n                opt->posPrev = cur + lenTest + 1;\n                opt->backPrev = 0;\n                opt->prev1IsChar = True;\n                opt->prev2 = True;\n                opt->posPrev2 = cur;\n                opt->backPrev2 = repIndex;\n              }\n            }\n          }\n        }\n    }\n    }\n    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */\n    if (newLen > numAvail)\n    {\n      newLen = numAvail;\n      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);\n      matches[numPairs] = newLen;\n      numPairs += 2;\n    }\n    if (newLen >= startLen)\n    {\n      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\n      UInt32 offs, curBack, posSlot;\n      UInt32 lenTest;\n      while (lenEnd < cur + newLen)\n        p->opt[++lenEnd].price = kInfinityPrice;\n\n      offs = 0;\n      while (startLen > matches[offs])\n        offs += 2;\n      curBack = matches[offs + 1];\n      GetPosSlot2(curBack, posSlot);\n      for (lenTest = /*2*/ startLen; ; lenTest++)\n      {\n        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\n        UInt32 lenToPosState = GetLenToPosState(lenTest);\n        COptimal *opt;\n        if (curBack < kNumFullDistances)\n          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];\n        else\n          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];\n        \n        opt = &p->opt[cur + lenTest];\n        if (curAndLenPrice < opt->price)\n        {\n          opt->price = curAndLenPrice;\n          opt->posPrev = cur;\n          opt->backPrev = curBack + LZMA_NUM_REPS;\n          opt->prev1IsChar = False;\n        }\n\n        if (/*_maxMode && */lenTest == matches[offs])\n        {\n          /* Try Match + Literal + Rep0 */\n          const Byte *data2 = data - (curBack + 1);\n          UInt32 lenTest2 = lenTest + 1;\n          UInt32 limit = lenTest2 + p->numFastBytes;\n          UInt32 nextRepMatchPrice;\n          if (limit > numAvailFull)\n            limit = numAvailFull;\n          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\n          lenTest2 -= lenTest + 1;\n          if (lenTest2 >= 2)\n          {\n            UInt32 state2 = kMatchNextStates[state];\n            UInt32 posStateNext = (position + lenTest) & p->pbMask;\n            UInt32 curAndLenCharPrice = curAndLenPrice +\n                GET_PRICE_0(p->isMatch[state2][posStateNext]) +\n                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),\n                    data[lenTest], data2[lenTest], p->ProbPrices);\n            state2 = kLiteralNextStates[state2];\n            posStateNext = (posStateNext + 1) & p->pbMask;\n            nextRepMatchPrice = curAndLenCharPrice +\n                GET_PRICE_1(p->isMatch[state2][posStateNext]) +\n                GET_PRICE_1(p->isRep[state2]);\n            \n            /* for (; lenTest2 >= 2; lenTest2--) */\n            {\n              UInt32 offset = cur + lenTest + 1 + lenTest2;\n              UInt32 curAndLenPrice;\n              COptimal *opt;\n              while (lenEnd < offset)\n                p->opt[++lenEnd].price = kInfinityPrice;\n              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\n              opt = &p->opt[offset];\n              if (curAndLenPrice < opt->price)\n              {\n                opt->price = curAndLenPrice;\n                opt->posPrev = cur + lenTest + 1;\n                opt->backPrev = 0;\n                opt->prev1IsChar = True;\n                opt->prev2 = True;\n                opt->posPrev2 = cur;\n                opt->backPrev2 = curBack + LZMA_NUM_REPS;\n              }\n            }\n          }\n          offs += 2;\n          if (offs == numPairs)\n            break;\n          curBack = matches[offs + 1];\n          if (curBack >= kNumFullDistances)\n            GetPosSlot2(curBack, posSlot);\n        }\n      }\n    }\n  }\n}\n\n#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))\n\nstatic UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)\n{\n  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;\n  const Byte *data;\n  const UInt32 *matches;\n\n  if (p->additionalOffset == 0)\n    mainLen = ReadMatchDistances(p, &numPairs);\n  else\n  {\n    mainLen = p->longestMatchLength;\n    numPairs = p->numPairs;\n  }\n\n  numAvail = p->numAvail;\n  *backRes = (UInt32)-1;\n  if (numAvail < 2)\n    return 1;\n  if (numAvail > LZMA_MATCH_LEN_MAX)\n    numAvail = LZMA_MATCH_LEN_MAX;\n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\n\n  repLen = repIndex = 0;\n  for (i = 0; i < LZMA_NUM_REPS; i++)\n  {\n    UInt32 len;\n    const Byte *data2 = data - (p->reps[i] + 1);\n    if (data[0] != data2[0] || data[1] != data2[1])\n      continue;\n    for (len = 2; len < numAvail && data[len] == data2[len]; len++);\n    if (len >= p->numFastBytes)\n    {\n      *backRes = i;\n      MovePos(p, len - 1);\n      return len;\n    }\n    if (len > repLen)\n    {\n      repIndex = i;\n      repLen = len;\n    }\n  }\n\n  matches = p->matches;\n  if (mainLen >= p->numFastBytes)\n  {\n    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;\n    MovePos(p, mainLen - 1);\n    return mainLen;\n  }\n\n  mainDist = 0; /* for GCC */\n  if (mainLen >= 2)\n  {\n    mainDist = matches[numPairs - 1];\n    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)\n    {\n      if (!ChangePair(matches[numPairs - 3], mainDist))\n        break;\n      numPairs -= 2;\n      mainLen = matches[numPairs - 2];\n      mainDist = matches[numPairs - 1];\n    }\n    if (mainLen == 2 && mainDist >= 0x80)\n      mainLen = 1;\n  }\n\n  if (repLen >= 2 && (\n        (repLen + 1 >= mainLen) ||\n        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||\n        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))\n  {\n    *backRes = repIndex;\n    MovePos(p, repLen - 1);\n    return repLen;\n  }\n  \n  if (mainLen < 2 || numAvail <= 2)\n    return 1;\n\n  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);\n  if (p->longestMatchLength >= 2)\n  {\n    UInt32 newDistance = matches[p->numPairs - 1];\n    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||\n        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||\n        (p->longestMatchLength > mainLen + 1) ||\n        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))\n      return 1;\n  }\n  \n  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\n  for (i = 0; i < LZMA_NUM_REPS; i++)\n  {\n    UInt32 len, limit;\n    const Byte *data2 = data - (p->reps[i] + 1);\n    if (data[0] != data2[0] || data[1] != data2[1])\n      continue;\n    limit = mainLen - 1;\n    for (len = 2; len < limit && data[len] == data2[len]; len++);\n    if (len >= limit)\n      return 1;\n  }\n  *backRes = mainDist + LZMA_NUM_REPS;\n  MovePos(p, mainLen - 2);\n  return mainLen;\n}\n\nstatic void WriteEndMarker(CLzmaEnc *p, UInt32 posState)\n{\n  UInt32 len;\n  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\n  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\n  p->state = kMatchNextStates[p->state];\n  len = LZMA_MATCH_LEN_MIN;\n  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\n  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);\n  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);\n  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);\n}\n\nstatic SRes CheckErrors(CLzmaEnc *p)\n{\n  if (p->result != SZ_OK)\n    return p->result;\n  if (p->rc.res != SZ_OK)\n    p->result = SZ_ERROR_WRITE;\n  if (p->matchFinderBase.result != SZ_OK)\n    p->result = SZ_ERROR_READ;\n  if (p->result != SZ_OK)\n    p->finished = True;\n  return p->result;\n}\n\nstatic SRes Flush(CLzmaEnc *p, UInt32 nowPos)\n{\n  /* ReleaseMFStream(); */\n  p->finished = True;\n  if (p->writeEndMark)\n    WriteEndMarker(p, nowPos & p->pbMask);\n  RangeEnc_FlushData(&p->rc);\n  RangeEnc_FlushStream(&p->rc);\n  return CheckErrors(p);\n}\n\nstatic void FillAlignPrices(CLzmaEnc *p)\n{\n  UInt32 i;\n  for (i = 0; i < kAlignTableSize; i++)\n    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);\n  p->alignPriceCount = 0;\n}\n\nstatic void FillDistancesPrices(CLzmaEnc *p)\n{\n  UInt32 tempPrices[kNumFullDistances];\n  UInt32 i, lenToPosState;\n  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)\n  {\n    UInt32 posSlot = GetPosSlot1(i);\n    UInt32 footerBits = ((posSlot >> 1) - 1);\n    UInt32 base = ((2 | (posSlot & 1)) << footerBits);\n    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);\n  }\n\n  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\n  {\n    UInt32 posSlot;\n    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];\n    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];\n    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)\n      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);\n    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)\n      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);\n\n    {\n      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];\n      UInt32 i;\n      for (i = 0; i < kStartPosModelIndex; i++)\n        distancesPrices[i] = posSlotPrices[i];\n      for (; i < kNumFullDistances; i++)\n        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];\n    }\n  }\n  p->matchPriceCount = 0;\n}\n\nvoid LzmaEnc_Construct(CLzmaEnc *p)\n{\n  RangeEnc_Construct(&p->rc);\n  MatchFinder_Construct(&p->matchFinderBase);\n  #ifdef COMPRESS_MF_MT\n  MatchFinderMt_Construct(&p->matchFinderMt);\n  p->matchFinderMt.MatchFinder = &p->matchFinderBase;\n  #endif\n\n  {\n    CLzmaEncProps props;\n    LzmaEncProps_Init(&props);\n    LzmaEnc_SetProps(p, &props);\n  }\n\n  #ifndef LZMA_LOG_BSR\n  LzmaEnc_FastPosInit(p->g_FastPos);\n  #endif\n\n  LzmaEnc_InitPriceTables(p->ProbPrices);\n  p->litProbs = 0;\n  p->saveState.litProbs = 0;\n}\n\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)\n{\n  void *p;\n  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));\n  if (p != 0)\n    LzmaEnc_Construct((CLzmaEnc *)p);\n  return p;\n}\n\nvoid LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)\n{\n  alloc->Free(alloc, p->litProbs);\n  alloc->Free(alloc, p->saveState.litProbs);\n  p->litProbs = 0;\n  p->saveState.litProbs = 0;\n}\n\nvoid LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  #ifdef COMPRESS_MF_MT\n  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);\n  #endif\n  MatchFinder_Free(&p->matchFinderBase, allocBig);\n  LzmaEnc_FreeLits(p, alloc);\n  RangeEnc_Free(&p->rc, alloc);\n}\n\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);\n  alloc->Free(alloc, p);\n}\n\nstatic SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)\n{\n  UInt32 nowPos32, startPos32;\n  if (p->inStream != 0)\n  {\n    p->matchFinderBase.stream = p->inStream;\n    p->matchFinder.Init(p->matchFinderObj);\n    p->inStream = 0;\n  }\n\n  if (p->finished)\n    return p->result;\n  RINOK(CheckErrors(p));\n\n  nowPos32 = (UInt32)p->nowPos64;\n  startPos32 = nowPos32;\n\n  if (p->nowPos64 == 0)\n  {\n    UInt32 numPairs;\n    Byte curByte;\n    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\n      return Flush(p, nowPos32);\n    ReadMatchDistances(p, &numPairs);\n    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);\n    p->state = kLiteralNextStates[p->state];\n    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);\n    LitEnc_Encode(&p->rc, p->litProbs, curByte);\n    p->additionalOffset--;\n    nowPos32++;\n  }\n\n  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)\n  for (;;)\n  {\n    UInt32 pos, len, posState;\n\n    if (p->fastMode)\n      len = GetOptimumFast(p, &pos);\n    else\n      len = GetOptimum(p, nowPos32, &pos);\n\n    #ifdef SHOW_STAT2\n    printf(\"\\n pos = %4X,   len = %d   pos = %d\", nowPos32, len, pos);\n    #endif\n\n    posState = nowPos32 & p->pbMask;\n    if (len == 1 && pos == (UInt32)-1)\n    {\n      Byte curByte;\n      CLzmaProb *probs;\n      const Byte *data;\n\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);\n      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\n      curByte = *data;\n      probs = LIT_PROBS(nowPos32, *(data - 1));\n      if (IsCharState(p->state))\n        LitEnc_Encode(&p->rc, probs, curByte);\n      else\n        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));\n      p->state = kLiteralNextStates[p->state];\n    }\n    else\n    {\n      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);\n      if (pos < LZMA_NUM_REPS)\n      {\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);\n        if (pos == 0)\n        {\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);\n          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));\n        }\n        else\n        {\n          UInt32 distance = p->reps[pos];\n          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);\n          if (pos == 1)\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);\n          else\n          {\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);\n            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);\n            if (pos == 3)\n              p->reps[3] = p->reps[2];\n            p->reps[2] = p->reps[1];\n          }\n          p->reps[1] = p->reps[0];\n          p->reps[0] = distance;\n        }\n        if (len == 1)\n          p->state = kShortRepNextStates[p->state];\n        else\n        {\n          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\n          p->state = kRepNextStates[p->state];\n        }\n      }\n      else\n      {\n        UInt32 posSlot;\n        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);\n        p->state = kMatchNextStates[p->state];\n        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);\n        pos -= LZMA_NUM_REPS;\n        GetPosSlot(pos, posSlot);\n        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);\n        \n        if (posSlot >= kStartPosModelIndex)\n        {\n          UInt32 footerBits = ((posSlot >> 1) - 1);\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\n          UInt32 posReduced = pos - base;\n\n          if (posSlot < kEndPosModelIndex)\n            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);\n          else\n          {\n            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\n            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);\n            p->alignPriceCount++;\n          }\n        }\n        p->reps[3] = p->reps[2];\n        p->reps[2] = p->reps[1];\n        p->reps[1] = p->reps[0];\n        p->reps[0] = pos;\n        p->matchPriceCount++;\n      }\n    }\n    p->additionalOffset -= len;\n    nowPos32 += len;\n    if (p->additionalOffset == 0)\n    {\n      UInt32 processed;\n      if (!p->fastMode)\n      {\n        if (p->matchPriceCount >= (1 << 7))\n          FillDistancesPrices(p);\n        if (p->alignPriceCount >= kAlignTableSize)\n          FillAlignPrices(p);\n      }\n      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)\n        break;\n      processed = nowPos32 - startPos32;\n      if (useLimits)\n      {\n        if (processed + kNumOpts + 300 >= maxUnpackSize ||\n            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)\n          break;\n      }\n      else if (processed >= (1 << 15))\n      {\n        p->nowPos64 += nowPos32 - startPos32;\n        return CheckErrors(p);\n      }\n    }\n  }\n  p->nowPos64 += nowPos32 - startPos32;\n  return Flush(p, nowPos32);\n}\n\n#define kBigHashDicLimit ((UInt32)1 << 24)\n\nstatic SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  UInt32 beforeSize = kNumOpts;\n  Bool btMode;\n  if (!RangeEnc_Alloc(&p->rc, alloc))\n    return SZ_ERROR_MEM;\n  btMode = (p->matchFinderBase.btMode != 0);\n  #ifdef COMPRESS_MF_MT\n  p->mtMode = (p->multiThread && !p->fastMode && btMode);\n  #endif\n\n  {\n    unsigned lclp = p->lc + p->lp;\n    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)\n    {\n      LzmaEnc_FreeLits(p, alloc);\n      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\n      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\n      if (p->litProbs == 0 || p->saveState.litProbs == 0)\n      {\n        LzmaEnc_FreeLits(p, alloc);\n        return SZ_ERROR_MEM;\n      }\n      p->lclp = lclp;\n    }\n  }\n\n  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);\n\n  if (beforeSize + p->dictSize < keepWindowSize)\n    beforeSize = keepWindowSize - p->dictSize;\n\n  #ifdef COMPRESS_MF_MT\n  if (p->mtMode)\n  {\n    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));\n    p->matchFinderObj = &p->matchFinderMt;\n    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);\n  }\n  else\n  #endif\n  {\n    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))\n      return SZ_ERROR_MEM;\n    p->matchFinderObj = &p->matchFinderBase;\n    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);\n  }\n  return SZ_OK;\n}\n\nvoid LzmaEnc_Init(CLzmaEnc *p)\n{\n  UInt32 i;\n  p->state = 0;\n  for (i = 0 ; i < LZMA_NUM_REPS; i++)\n    p->reps[i] = 0;\n\n  RangeEnc_Init(&p->rc);\n\n\n  for (i = 0; i < kNumStates; i++)\n  {\n    UInt32 j;\n    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)\n    {\n      p->isMatch[i][j] = kProbInitValue;\n      p->isRep0Long[i][j] = kProbInitValue;\n    }\n    p->isRep[i] = kProbInitValue;\n    p->isRepG0[i] = kProbInitValue;\n    p->isRepG1[i] = kProbInitValue;\n    p->isRepG2[i] = kProbInitValue;\n  }\n\n  {\n    UInt32 num = 0x300 << (p->lp + p->lc);\n    for (i = 0; i < num; i++)\n      p->litProbs[i] = kProbInitValue;\n  }\n\n  {\n    for (i = 0; i < kNumLenToPosStates; i++)\n    {\n      CLzmaProb *probs = p->posSlotEncoder[i];\n      UInt32 j;\n      for (j = 0; j < (1 << kNumPosSlotBits); j++)\n        probs[j] = kProbInitValue;\n    }\n  }\n  {\n    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\n      p->posEncoders[i] = kProbInitValue;\n  }\n\n  LenEnc_Init(&p->lenEnc.p);\n  LenEnc_Init(&p->repLenEnc.p);\n\n  for (i = 0; i < (1 << kNumAlignBits); i++)\n    p->posAlignEncoder[i] = kProbInitValue;\n\n  p->optimumEndIndex = 0;\n  p->optimumCurrentIndex = 0;\n  p->additionalOffset = 0;\n\n  p->pbMask = (1 << p->pb) - 1;\n  p->lpMask = (1 << p->lp) - 1;\n}\n\nvoid LzmaEnc_InitPrices(CLzmaEnc *p)\n{\n  if (!p->fastMode)\n  {\n    FillDistancesPrices(p);\n    FillAlignPrices(p);\n  }\n\n  p->lenEnc.tableSize =\n  p->repLenEnc.tableSize =\n      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;\n  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);\n  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);\n}\n\nstatic SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  UInt32 i;\n  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)\n    if (p->dictSize <= ((UInt32)1 << i))\n      break;\n  p->distTableSize = i * 2;\n\n  p->finished = False;\n  p->result = SZ_OK;\n  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));\n  LzmaEnc_Init(p);\n  LzmaEnc_InitPrices(p);\n  p->nowPos64 = 0;\n  return SZ_OK;\n}\n\nstatic SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,\n    ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n  p->inStream = inStream;\n  p->rc.outStream = outStream;\n  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);\n}\n\nSRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,\n    ISeqInStream *inStream, UInt32 keepWindowSize,\n    ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n  p->inStream = inStream;\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\n}\n\nstatic void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)\n{\n  p->seqBufInStream.funcTable.Read = MyRead;\n  p->seqBufInStream.data = src;\n  p->seqBufInStream.rem = srcLen;\n}\n\nSRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\n    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n  LzmaEnc_SetInputBuf(p, src, srcLen);\n  p->inStream = &p->seqBufInStream.funcTable;\n  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\n}\n\nvoid LzmaEnc_Finish(CLzmaEncHandle pp)\n{\n  #ifdef COMPRESS_MF_MT\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n  if (p->mtMode)\n    MatchFinderMt_ReleaseStream(&p->matchFinderMt);\n  #else\n  pp = pp;\n  #endif\n}\n\ntypedef struct _CSeqOutStreamBuf\n{\n  ISeqOutStream funcTable;\n  Byte *data;\n  SizeT rem;\n  Bool overflow;\n} CSeqOutStreamBuf;\n\nstatic size_t MyWrite(void *pp, const void *data, size_t size)\n{\n  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;\n  if (p->rem < size)\n  {\n    size = p->rem;\n    p->overflow = True;\n  }\n  memcpy(p->data, data, size);\n  p->rem -= size;\n  p->data += size;\n  return size;\n}\n\n\nUInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)\n{\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\n  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\n}\n\nconst Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)\n{\n  const CLzmaEnc *p = (CLzmaEnc *)pp;\n  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\n}\n\nSRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\n    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)\n{\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n  UInt64 nowPos64;\n  SRes res;\n  CSeqOutStreamBuf outStream;\n\n  outStream.funcTable.Write = MyWrite;\n  outStream.data = dest;\n  outStream.rem = *destLen;\n  outStream.overflow = False;\n\n  p->writeEndMark = False;\n  p->finished = False;\n  p->result = SZ_OK;\n\n  if (reInit)\n    LzmaEnc_Init(p);\n  LzmaEnc_InitPrices(p);\n  nowPos64 = p->nowPos64;\n  RangeEnc_Init(&p->rc);\n  p->rc.outStream = &outStream.funcTable;\n\n  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);\n  \n  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);\n  *destLen -= outStream.rem;\n  if (outStream.overflow)\n    return SZ_ERROR_OUTPUT_EOF;\n\n  return res;\n}\n\nSRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\n    ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n  SRes res = SZ_OK;\n\n  #ifdef COMPRESS_MF_MT\n  Byte allocaDummy[0x300];\n  int i = 0;\n  for (i = 0; i < 16; i++)\n    allocaDummy[i] = (Byte)i;\n  #endif\n\n  RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));\n\n  for (;;)\n  {\n    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);\n    if (res != SZ_OK || p->finished != 0)\n      break;\n    if (progress != 0)\n    {\n      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));\n      if (res != SZ_OK)\n      {\n        res = SZ_ERROR_PROGRESS;\n        break;\n      }\n    }\n  }\n  LzmaEnc_Finish(pp);\n  return res;\n}\n\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)\n{\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n  int i;\n  UInt32 dictSize = p->dictSize;\n  if (*size < LZMA_PROPS_SIZE)\n    return SZ_ERROR_PARAM;\n  *size = LZMA_PROPS_SIZE;\n  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);\n\n  for (i = 11; i <= 30; i++)\n  {\n    if (dictSize <= ((UInt32)2 << i))\n    {\n      dictSize = (2 << i);\n      break;\n    }\n    if (dictSize <= ((UInt32)3 << i))\n    {\n      dictSize = (3 << i);\n      break;\n    }\n  }\n\n  for (i = 0; i < 4; i++)\n    props[1 + i] = (Byte)(dictSize >> (8 * i));\n  return SZ_OK;\n}\n\nSRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  SRes res;\n  CLzmaEnc *p = (CLzmaEnc *)pp;\n\n  CSeqOutStreamBuf outStream;\n\n  LzmaEnc_SetInputBuf(p, src, srcLen);\n\n  outStream.funcTable.Write = MyWrite;\n  outStream.data = dest;\n  outStream.rem = *destLen;\n  outStream.overflow = False;\n\n  p->writeEndMark = writeEndMark;\n  res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,\n      progress, alloc, allocBig);\n\n  *destLen -= outStream.rem;\n  if (outStream.overflow)\n    return SZ_ERROR_OUTPUT_EOF;\n  return res;\n}\n\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\n{\n  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);\n  SRes res;\n  if (p == 0)\n    return SZ_ERROR_MEM;\n\n  res = LzmaEnc_SetProps(p, props);\n  if (res == SZ_OK)\n  {\n    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);\n    if (res == SZ_OK)\n      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,\n          writeEndMark, progress, alloc, allocBig);\n  }\n\n  LzmaEnc_Destroy(p, alloc, allocBig);\n  return res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaEnc.h",
    "content": "/*  LzmaEnc.h -- LZMA Encoder\n2008-10-04 : Igor Pavlov : Public domain */\n\n#ifndef __LZMAENC_H\n#define __LZMAENC_H\n\n#include \"Types.h\"\n\n#define LZMA_PROPS_SIZE 5\n\ntypedef struct _CLzmaEncProps\n{\n  int level;       /*  0 <= level <= 9 */\n  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version\n                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version\n                       default = (1 << 24) */\n  int lc;          /* 0 <= lc <= 8, default = 3 */\n  int lp;          /* 0 <= lp <= 4, default = 0 */\n  int pb;          /* 0 <= pb <= 4, default = 2 */\n  int algo;        /* 0 - fast, 1 - normal, default = 1 */\n  int fb;          /* 5 <= fb <= 273, default = 32 */\n  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */\n  int numHashBytes; /* 2, 3 or 4, default = 4 */\n  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */\n  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */\n  int numThreads;  /* 1 or 2, default = 2 */\n} CLzmaEncProps;\n\nvoid LzmaEncProps_Init(CLzmaEncProps *p);\nvoid LzmaEncProps_Normalize(CLzmaEncProps *p);\nUInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);\n\n\n/* ---------- CLzmaEncHandle Interface ---------- */\n\n/* LzmaEnc_* functions can return the following exit codes:\nReturns:\n  SZ_OK           - OK\n  SZ_ERROR_MEM    - Memory allocation error\n  SZ_ERROR_PARAM  - Incorrect paramater in props\n  SZ_ERROR_WRITE  - Write callback error.\n  SZ_ERROR_PROGRESS - some break from progress callback\n  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)\n*/\n\ntypedef void * CLzmaEncHandle;\n\nCLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);\nvoid LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);\nSRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);\nSRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);\nSRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\nSRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\n    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\n\n/* ---------- One Call Interface ---------- */\n\n/* LzmaEncode\nReturn code:\n  SZ_OK               - OK\n  SZ_ERROR_MEM        - Memory allocation error\n  SZ_ERROR_PARAM      - Incorrect paramater\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\n*/\n\nSRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\n    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaLib/LzmaLib.def",
    "content": "EXPORTS\n  LzmaCompress\n  LzmaUncompress\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaLib/LzmaLib.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaLib\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** DO NOT EDIT **\n\n# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\n\nCFG=LzmaLib - Win32 Debug\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n!MESSAGE use the Export Makefile command and run\n!MESSAGE \n!MESSAGE NMAKE /f \"LzmaLib.mak\".\n!MESSAGE \n!MESSAGE You can specify a configuration when running NMAKE\n!MESSAGE by defining the macro CFG on the command line. For example:\n!MESSAGE \n!MESSAGE NMAKE /f \"LzmaLib.mak\" CFG=\"LzmaLib - Win32 Debug\"\n!MESSAGE \n!MESSAGE Possible choices for configuration are:\n!MESSAGE \n!MESSAGE \"LzmaLib - Win32 Release\" (based on \"Win32 (x86) Dynamic-Link Library\")\n!MESSAGE \"LzmaLib - Win32 Debug\" (based on \"Win32 (x86) Dynamic-Link Library\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nMTL=midl.exe\nRSC=rc.exe\n\n!IF  \"$(CFG)\" == \"LzmaLib - Win32 Release\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \"Release\"\n# PROP BASE Intermediate_Dir \"Release\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \"Release\"\n# PROP Intermediate_Dir \"Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /c\n# ADD CPP /nologo /Gr /MT /W3 /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /c\n# SUBTRACT CPP /YX\n# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\n# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\n# ADD RSC /l 0x419 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /opt:NOWIN98\n# SUBTRACT LINK32 /pdb:none\n\n!ELSEIF  \"$(CFG)\" == \"LzmaLib - Win32 Debug\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 1\n# PROP BASE Output_Dir \"Debug\"\n# PROP BASE Intermediate_Dir \"Debug\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 1\n# PROP Output_Dir \"Debug\"\n# PROP Intermediate_Dir \"Debug\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /YX /FD /GZ /c\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_WINDOWS\" /D \"_MBCS\" /D \"_USRDLL\" /D \"LZMALIB_EXPORTS\" /D \"COMPRESS_MF_MT\" /FD /GZ /c\n# SUBTRACT CPP /YX\n# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\n# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\n# ADD RSC /l 0x419 /d \"_DEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:\"C:\\Util\\LZMA.dll\" /pdbtype:sept\n\n!ENDIF \n\n# Begin Target\n\n# Name \"LzmaLib - Win32 Release\"\n# Name \"LzmaLib - Win32 Debug\"\n# Begin Group \"Spec\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=.\\LzmaLib.def\n# End Source File\n# Begin Source File\n\nSOURCE=.\\LzmaLibExports.c\n# End Source File\n# End Group\n# Begin Source File\n\nSOURCE=..\\Alloc.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\Alloc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\IStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzFind.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzFind.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzFindMt.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzFindMt.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzHash.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaDec.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaDec.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaEnc.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaEnc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaLib.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaLib.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\resource.rc\n# End Source File\n# Begin Source File\n\nSOURCE=..\\Threads.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\Threads.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\Types.h\n# End Source File\n# End Target\n# End Project\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaLib/LzmaLib.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n###############################################################################\n\nProject: \"LzmaLib\"=.\\LzmaLib.dsp - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nGlobal:\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<3>\n{{{\n}}}\n\n###############################################################################\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaLib/LzmaLibExports.c",
    "content": "/* LzmaLibExports.c -- LZMA library DLL Entry point\n2008-10-04 : Igor Pavlov : Public domain */\n\n#include <windows.h>\n\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\n{\n  hInstance = hInstance;\n  dwReason = dwReason;\n  lpReserved = lpReserved;\n  return TRUE;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaLib/makefile",
    "content": "MY_STATIC_LINK=1\nSLIB = sLZMA.lib\nPROG = LZMA.dll\nSLIBPATH = $O\\$(SLIB)\n\nDEF_FILE = LzmaLib.def\nCFLAGS = $(CFLAGS) \\\n  -DCOMPRESS_MF_MT \\\n\nLIBS = $(LIBS) oleaut32.lib\n\nLIB_OBJS = \\\n  $O\\LzmaLibExports.obj \\\n\nC_OBJS = \\\n  $O\\Alloc.obj \\\n  $O\\LzFind.obj \\\n  $O\\LzFindMt.obj \\\n  $O\\LzmaDec.obj \\\n  $O\\LzmaEnc.obj \\\n  $O\\LzmaLib.obj \\\n  $O\\Threads.obj \\\n\nOBJS = \\\n  $(LIB_OBJS) \\\n  $(C_OBJS) \\\n  $O\\resource.res\n\n!include \"../../CPP/Build.mak\"\n\n$(SLIBPATH): $O $(OBJS)\n\tlib -out:$(SLIBPATH) $(OBJS) $(LIBS)\n\n$(LIB_OBJS): $(*B).c\n\t$(COMPL_O2)\n$(C_OBJS): ../$(*B).c\n\t$(COMPL_O2)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaLib/resource.rc",
    "content": "#include \"../../CPP/7zip/MyVersionInfo.rc\"\n\nMY_VERSION_INFO_DLL(\"LZMA library\", \"LZMA\")\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaLib.c",
    "content": "/* LzmaLib.c -- LZMA library wrapper\n2008-08-05\nIgor Pavlov\nPublic domain */\n\n#include \"LzmaEnc.h\"\n#include \"LzmaDec.h\"\n#include \"Alloc.h\"\n#include \"LzmaLib.h\"\n\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  srcLen,\n  unsigned char *outProps, size_t *outPropsSize,\n  int level, /* 0 <= level <= 9, default = 5 */\n  unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */\n  int lc, /* 0 <= lc <= 8, default = 3  */\n  int lp, /* 0 <= lp <= 4, default = 0  */\n  int pb, /* 0 <= pb <= 4, default = 2  */\n  int fb,  /* 5 <= fb <= 273, default = 32 */\n  int numThreads /* 1 or 2, default = 2 */\n)\n{\n  CLzmaEncProps props;\n  LzmaEncProps_Init(&props);\n  props.level = level;\n  props.dictSize = dictSize;\n  props.lc = lc;\n  props.lp = lp;\n  props.pb = pb;\n  props.fb = fb;\n  props.numThreads = numThreads;\n\n  return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,\n      NULL, &g_Alloc, &g_Alloc);\n}\n\n\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t  *destLen, const unsigned char *src, size_t  *srcLen,\n  const unsigned char *props, size_t propsSize)\n{\n  ELzmaStatus status;\n  return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaLib.h",
    "content": "/* LzmaLib.h -- LZMA library interface\n2008-08-05\nIgor Pavlov\nPublic domain */\n\n#ifndef __LZMALIB_H\n#define __LZMALIB_H\n\n#include \"Types.h\"\n\n#ifdef __cplusplus\n  #define MY_EXTERN_C extern \"C\"\n#else\n  #define MY_EXTERN_C extern\n#endif\n\n#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL\n\n#define LZMA_PROPS_SIZE 5\n\n/*\nRAM requirements for LZMA:\n  for compression:   (dictSize * 11.5 + 6 MB) + state_size\n  for decompression: dictSize + state_size\n    state_size = (4 + (1.5 << (lc + lp))) KB\n    by default (lc=3, lp=0), state_size = 16 KB.\n\nLZMA properties (5 bytes) format\n    Offset Size  Description\n      0     1    lc, lp and pb in encoded form.\n      1     4    dictSize (little endian).\n*/\n\n/*\nLzmaCompress\n------------\n\noutPropsSize -\n     In:  the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\n     Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.\n\n  LZMA Encoder will use defult values for any parameter, if it is\n  -1  for any from: level, loc, lp, pb, fb, numThreads\n   0  for dictSize\n  \nlevel - compression level: 0 <= level <= 9;\n\n  level dictSize algo  fb\n    0:    16 KB   0    32\n    1:    64 KB   0    32\n    2:   256 KB   0    32\n    3:     1 MB   0    32\n    4:     4 MB   0    32\n    5:    16 MB   1    32\n    6:    32 MB   1    32\n    7+:   64 MB   1    64\n \n  The default value for \"level\" is 5.\n\n  algo = 0 means fast method\n  algo = 1 means normal method\n\ndictSize - The dictionary size in bytes. The maximum value is\n        128 MB = (1 << 27) bytes for 32-bit version\n          1 GB = (1 << 30) bytes for 64-bit version\n     The default value is 16 MB = (1 << 24) bytes.\n     It's recommended to use the dictionary that is larger than 4 KB and\n     that can be calculated as (1 << N) or (3 << N) sizes.\n\nlc - The number of literal context bits (high bits of previous literal).\n     It can be in the range from 0 to 8. The default value is 3.\n     Sometimes lc=4 gives the gain for big files.\n\nlp - The number of literal pos bits (low bits of current position for literals).\n     It can be in the range from 0 to 4. The default value is 0.\n     The lp switch is intended for periodical data when the period is equal to 2^lp.\n     For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's\n     better to set lc=0, if you change lp switch.\n\npb - The number of pos bits (low bits of current position).\n     It can be in the range from 0 to 4. The default value is 2.\n     The pb switch is intended for periodical data when the period is equal 2^pb.\n\nfb - Word size (the number of fast bytes).\n     It can be in the range from 5 to 273. The default value is 32.\n     Usually, a big number gives a little bit better compression ratio and\n     slower compression process.\n\nnumThreads - The number of thereads. 1 or 2. The default value is 2.\n     Fast mode (algo = 0) can use only 1 thread.\n\nOut:\n  destLen  - processed output size\nReturns:\n  SZ_OK               - OK\n  SZ_ERROR_MEM        - Memory allocation error\n  SZ_ERROR_PARAM      - Incorrect paramater\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\n*/\n\nMY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,\n  unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */\n  int level,      /* 0 <= level <= 9, default = 5 */\n  unsigned dictSize,  /* default = (1 << 24) */\n  int lc,        /* 0 <= lc <= 8, default = 3  */\n  int lp,        /* 0 <= lp <= 4, default = 0  */\n  int pb,        /* 0 <= pb <= 4, default = 2  */\n  int fb,        /* 5 <= fb <= 273, default = 32 */\n  int numThreads /* 1 or 2, default = 2 */\n  );\n\n/*\nLzmaUncompress\n--------------\nIn:\n  dest     - output data\n  destLen  - output data size\n  src      - input data\n  srcLen   - input data size\nOut:\n  destLen  - processed output size\n  srcLen   - processed input size\nReturns:\n  SZ_OK                - OK\n  SZ_ERROR_DATA        - Data error\n  SZ_ERROR_MEM         - Memory allocation arror\n  SZ_ERROR_UNSUPPORTED - Unsupported properties\n  SZ_ERROR_INPUT_EOF   - it needs more bytes in input buffer (src)\n*/\n\nMY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,\n  const unsigned char *props, size_t propsSize);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaUtil/Lzma86Dec.c",
    "content": "/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder\n2008-04-07\nIgor Pavlov\nPublic domain */\n\n#include \"Lzma86Dec.h\"\n\n#include \"../Alloc.h\"\n#include \"../Bra.h\"\n#include \"../LzmaDec.h\"\n\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\n\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)\n{\n  unsigned i;\n  if (srcLen < LZMA86_HEADER_SIZE)\n    return SZ_ERROR_INPUT_EOF;\n  *unpackSize = 0;\n  for (i = 0; i < sizeof(UInt64); i++)\n    *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);\n  return SZ_OK;\n}\n\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)\n{\n  SRes res;\n  int useFilter;\n  SizeT inSizePure;\n  ELzmaStatus status;\n\n  if (*srcLen < LZMA86_HEADER_SIZE)\n    return SZ_ERROR_INPUT_EOF;\n\n  useFilter = src[0];\n\n  if (useFilter > 1)\n  {\n    *destLen = 0;\n    return SZ_ERROR_UNSUPPORTED;\n  }\n\n  inSizePure = *srcLen - LZMA86_HEADER_SIZE;\n  res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,\n      src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);\n  *srcLen = inSizePure + LZMA86_HEADER_SIZE;\n  if (res != SZ_OK)\n    return res;\n  if (useFilter == 1)\n  {\n    UInt32 x86State;\n    x86_Convert_Init(x86State);\n    x86_Convert(dest, *destLen, 0, &x86State, 0);\n  }\n  return SZ_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaUtil/Lzma86Dec.h",
    "content": "/* Lzma86Dec.h -- LZMA + x86 (BCJ) Filter Decoder\n2008-08-05\nIgor Pavlov\nPublic domain */\n\n#ifndef __LZMA86DEC_H\n#define __LZMA86DEC_H\n\n#include \"../Types.h\"\n\n/*\nLzma86_GetUnpackSize:\n  In:\n    src      - input data\n    srcLen   - input data size\n  Out:\n    unpackSize - size of uncompressed stream\n  Return code:\n    SZ_OK               - OK\n    SZ_ERROR_INPUT_EOF  - Error in headers\n*/\n\nSRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);\n\n/*\nLzma86_Decode:\n  In:\n    dest     - output data\n    destLen  - output data size\n    src      - input data\n    srcLen   - input data size\n  Out:\n    destLen  - processed output size\n    srcLen   - processed input size\n  Return code:\n    SZ_OK           - OK\n    SZ_ERROR_DATA  - Data error\n    SZ_ERROR_MEM   - Memory allocation error\n    SZ_ERROR_UNSUPPORTED - unsupported file\n    SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer\n*/\n\nSRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaUtil/Lzma86Enc.c",
    "content": "/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder\n2008-08-05\nIgor Pavlov\nPublic domain */\n\n#include <string.h>\n\n#include \"Lzma86Enc.h\"\n\n#include \"../Alloc.h\"\n#include \"../Bra.h\"\n#include \"../LzmaEnc.h\"\n\n#define SZE_OUT_OVERFLOW SZE_DATA_ERROR\n\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\n#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)\n#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)\n\nint Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\n    int level, UInt32 dictSize, int filterMode)\n{\n  size_t outSize2 = *destLen;\n  Byte *filteredStream;\n  Bool useFilter;\n  int mainResult = SZ_ERROR_OUTPUT_EOF;\n  CLzmaEncProps props;\n  LzmaEncProps_Init(&props);\n  props.level = level;\n  props.dictSize = dictSize;\n  \n  *destLen = 0;\n  if (outSize2 < LZMA86_HEADER_SIZE)\n    return SZ_ERROR_OUTPUT_EOF;\n\n  {\n    int i;\n    UInt64 t = srcLen;\n    for (i = 0; i < 8; i++, t >>= 8)\n      dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;\n  }\n\n  filteredStream = 0;\n  useFilter = (filterMode != SZ_FILTER_NO);\n  if (useFilter)\n  {\n    if (srcLen != 0)\n    {\n      filteredStream = (Byte *)MyAlloc(srcLen);\n      if (filteredStream == 0)\n        return SZ_ERROR_MEM;\n      memcpy(filteredStream, src, srcLen);\n    }\n    {\n      UInt32 x86State;\n      x86_Convert_Init(x86State);\n      x86_Convert(filteredStream, srcLen, 0, &x86State, 1);\n    }\n  }\n\n  {\n    size_t minSize = 0;\n    Bool bestIsFiltered = False;\n\n    /* passes for SZ_FILTER_AUTO:\n        0 - BCJ + LZMA\n        1 - LZMA\n        2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.\n    */\n    int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\n\n    int i;\n    for (i = 0; i < numPasses; i++)\n    {\n      size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;\n      size_t outPropsSize = 5;\n      SRes curRes;\n      Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);\n      if (curModeIsFiltered && !bestIsFiltered)\n        break;\n      if (useFilter && i == 0)\n        curModeIsFiltered = True;\n      \n      curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,\n          curModeIsFiltered ? filteredStream : src, srcLen,\n          &props, dest + 1, &outPropsSize, 0,\n          NULL, &g_Alloc, &g_Alloc);\n      \n      if (curRes != SZ_ERROR_OUTPUT_EOF)\n      {\n        if (curRes != SZ_OK)\n        {\n          mainResult = curRes;\n          break;\n        }\n        if (outSizeProcessed <= minSize || mainResult != SZ_OK)\n        {\n          minSize = outSizeProcessed;\n          bestIsFiltered = curModeIsFiltered;\n          mainResult = SZ_OK;\n        }\n      }\n    }\n    dest[0] = (bestIsFiltered ? 1 : 0);\n    *destLen = LZMA86_HEADER_SIZE + minSize;\n  }\n  if (useFilter)\n    MyFree(filteredStream);\n  return mainResult;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaUtil/Lzma86Enc.h",
    "content": "/* Lzma86Enc.h -- LZMA + x86 (BCJ) Filter Encoder\n2008-08-05\nIgor Pavlov\nPublic domain */\n\n#ifndef __LZMA86ENC_H\n#define __LZMA86ENC_H\n\n#include \"../Types.h\"\n\n/*\nIt's an example for LZMA + x86 Filter use.\nYou can use .lzma86 extension, if you write that stream to file.\n.lzma86 header adds one additional byte to standard .lzma header.\n.lzma86 header (14 bytes):\n  Offset Size  Description\n    0     1    = 0 - no filter,\n               = 1 - x86 filter\n    1     1    lc, lp and pb in encoded form\n    2     4    dictSize (little endian)\n    6     8    uncompressed size (little endian)\n\n\nLzma86_Encode\n-------------\nlevel - compression level: 0 <= level <= 9, the default value for \"level\" is 5.\n\n\ndictSize - The dictionary size in bytes. The maximum value is\n        128 MB = (1 << 27) bytes for 32-bit version\n          1 GB = (1 << 30) bytes for 64-bit version\n     The default value is 16 MB = (1 << 24) bytes, for level = 5.\n     It's recommended to use the dictionary that is larger than 4 KB and\n     that can be calculated as (1 << N) or (3 << N) sizes.\n     For better compression ratio dictSize must be >= inSize.\n\nfilterMode:\n    SZ_FILTER_NO   - no Filter\n    SZ_FILTER_YES  - x86 Filter\n    SZ_FILTER_AUTO - it tries both alternatives to select best.\n              Encoder will use 2 or 3 passes:\n              2 passes when FILTER_NO provides better compression.\n              3 passes when FILTER_YES provides better compression.\n\nLzma86Encode allocates Data with MyAlloc functions.\nRAM Requirements for compressing:\n  RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize\n      filterMode     FilterBlockSize\n     SZ_FILTER_NO         0\n     SZ_FILTER_YES      inSize\n     SZ_FILTER_AUTO     inSize\n\n\nReturn code:\n  SZ_OK               - OK\n  SZ_ERROR_MEM        - Memory allocation error\n  SZ_ERROR_PARAM      - Incorrect paramater\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\n*/\n\nenum ESzFilterMode\n{\n  SZ_FILTER_NO,\n  SZ_FILTER_YES,\n  SZ_FILTER_AUTO\n};\n\nSRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,\n    int level, UInt32 dictSize, int filterMode);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaUtil/LzmaUtil.c",
    "content": "/* LzmaUtil.c -- Test application for LZMA compression\n2008-11-23 : Igor Pavlov : Public domain */\n\n#define _CRT_SECURE_NO_WARNINGS\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"../Alloc.h\"\n#include \"../7zFile.h\"\n#include \"../7zVersion.h\"\n#include \"../LzmaDec.h\"\n#include \"../LzmaEnc.h\"\n\nconst char *kCantReadMessage = \"Can not read input file\";\nconst char *kCantWriteMessage = \"Can not write output file\";\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\nconst char *kDataErrorMessage = \"Data error\";\n\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\nvoid PrintHelp(char *buffer)\n{\n  strcat(buffer, \"\\nLZMA Utility \" MY_VERSION_COPYRIGHT_DATE \"\\n\"\n      \"\\nUsage:  lzma <e|d> inputFile outputFile\\n\"\n             \"  e: encode file\\n\"\n             \"  d: decode file\\n\");\n}\n\nint PrintError(char *buffer, const char *message)\n{\n  strcat(buffer, \"\\nError: \");\n  strcat(buffer, message);\n  strcat(buffer, \"\\n\");\n  return 1;\n}\n\nint PrintErrorNumber(char *buffer, SRes val)\n{\n  sprintf(buffer + strlen(buffer), \"\\nError code: %x\\n\", (unsigned)val);\n  return 1;\n}\n\nint PrintUserError(char *buffer)\n{\n  return PrintError(buffer, \"Incorrect command\");\n}\n\n#define IN_BUF_SIZE (1 << 16)\n#define OUT_BUF_SIZE (1 << 16)\n\nstatic SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,\n    UInt64 unpackSize)\n{\n  int thereIsSize = (unpackSize != (UInt64)(Int64)-1);\n  Byte inBuf[IN_BUF_SIZE];\n  Byte outBuf[OUT_BUF_SIZE];\n  size_t inPos = 0, inSize = 0, outPos = 0;\n  LzmaDec_Init(state);\n  for (;;)\n  {\n    if (inPos == inSize)\n    {\n      inSize = IN_BUF_SIZE;\n      RINOK(inStream->Read(inStream, inBuf, &inSize));\n      inPos = 0;\n    }\n    {\n      SRes res;\n      SizeT inProcessed = inSize - inPos;\n      SizeT outProcessed = OUT_BUF_SIZE - outPos;\n      ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\n      ELzmaStatus status;\n      if (thereIsSize && outProcessed > unpackSize)\n      {\n        outProcessed = (SizeT)unpackSize;\n        finishMode = LZMA_FINISH_END;\n      }\n      \n      res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,\n        inBuf + inPos, &inProcessed, finishMode, &status);\n      inPos += inProcessed;\n      outPos += outProcessed;\n      unpackSize -= outProcessed;\n      \n      if (outStream)\n        if (outStream->Write(outStream, outBuf, outPos) != outPos)\n          return SZ_ERROR_WRITE;\n        \n      outPos = 0;\n      \n      if (res != SZ_OK || thereIsSize && unpackSize == 0)\n        return res;\n      \n      if (inProcessed == 0 && outProcessed == 0)\n      {\n        if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)\n          return SZ_ERROR_DATA;\n        return res;\n      }\n    }\n  }\n}\n\nstatic SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)\n{\n  UInt64 unpackSize;\n  int i;\n  SRes res = 0;\n\n  CLzmaDec state;\n\n  /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */\n  unsigned char header[LZMA_PROPS_SIZE + 8];\n\n  /* Read and parse header */\n\n  RINOK(SeqInStream_Read(inStream, header, sizeof(header)));\n\n  unpackSize = 0;\n  for (i = 0; i < 8; i++)\n    unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);\n\n  LzmaDec_Construct(&state);\n  RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));\n  res = Decode2(&state, outStream, inStream, unpackSize);\n  LzmaDec_Free(&state, &g_Alloc);\n  return res;\n}\n\nstatic SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)\n{\n  CLzmaEncHandle enc;\n  SRes res;\n  CLzmaEncProps props;\n\n  rs = rs;\n\n  enc = LzmaEnc_Create(&g_Alloc);\n  if (enc == 0)\n    return SZ_ERROR_MEM;\n\n  LzmaEncProps_Init(&props);\n  res = LzmaEnc_SetProps(enc, &props);\n\n  if (res == SZ_OK)\n  {\n    Byte header[LZMA_PROPS_SIZE + 8];\n    size_t headerSize = LZMA_PROPS_SIZE;\n    int i;\n\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\n    for (i = 0; i < 8; i++)\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\n    if (outStream->Write(outStream, header, headerSize) != headerSize)\n      res = SZ_ERROR_WRITE;\n    else\n    {\n      if (res == SZ_OK)\n        res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);\n    }\n  }\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\n  return res;\n}\n\nint main2(int numArgs, const char *args[], char *rs)\n{\n  CFileSeqInStream inStream;\n  CFileOutStream outStream;\n  char c;\n  int res;\n  int encodeMode;\n  Bool useOutFile = False;\n\n  FileSeqInStream_CreateVTable(&inStream);\n  File_Construct(&inStream.file);\n\n  FileOutStream_CreateVTable(&outStream);\n  File_Construct(&outStream.file);\n\n  if (numArgs == 1)\n  {\n    PrintHelp(rs);\n    return 0;\n  }\n\n  if (numArgs < 3 || numArgs > 4 || strlen(args[1]) != 1)\n    return PrintUserError(rs);\n\n  c = args[1][0];\n  encodeMode = (c == 'e' || c == 'E');\n  if (!encodeMode && c != 'd' && c != 'D')\n    return PrintUserError(rs);\n\n  {\n    size_t t4 = sizeof(UInt32);\n    size_t t8 = sizeof(UInt64);\n    if (t4 != 4 || t8 != 8)\n      return PrintError(rs, \"Incorrect UInt32 or UInt64\");\n  }\n\n  if (InFile_Open(&inStream.file, args[2]) != 0)\n    return PrintError(rs, \"Can not open input file\");\n\n  if (numArgs > 3)\n  {\n    useOutFile = True;\n    if (OutFile_Open(&outStream.file, args[3]) != 0)\n      return PrintError(rs, \"Can not open output file\");\n  }\n  else if (encodeMode)\n    PrintUserError(rs);\n\n  if (encodeMode)\n  {\n    UInt64 fileSize;\n    File_GetLength(&inStream.file, &fileSize);\n    res = Encode(&outStream.s, &inStream.s, fileSize, rs);\n  }\n  else\n  {\n    res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL);\n  }\n\n  if (useOutFile)\n    File_Close(&outStream.file);\n  File_Close(&inStream.file);\n\n  if (res != SZ_OK)\n  {\n    if (res == SZ_ERROR_MEM)\n      return PrintError(rs, kCantAllocateMessage);\n    else if (res == SZ_ERROR_DATA)\n      return PrintError(rs, kDataErrorMessage);\n    else if (res == SZ_ERROR_WRITE)\n      return PrintError(rs, kCantWriteMessage);\n    else if (res == SZ_ERROR_READ)\n      return PrintError(rs, kCantReadMessage);\n    return PrintErrorNumber(rs, res);\n  }\n  return 0;\n}\n\nint MY_CDECL main(int numArgs, const char *args[])\n{\n  char rs[800] = { 0 };\n  int res = main2(numArgs, args, rs);\n  printf(rs);\n  return res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaUtil/LzmaUtil.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"LzmaUtil\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** DO NOT EDIT **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=LzmaUtil - Win32 Debug\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n!MESSAGE use the Export Makefile command and run\n!MESSAGE \n!MESSAGE NMAKE /f \"LzmaUtil.mak\".\n!MESSAGE \n!MESSAGE You can specify a configuration when running NMAKE\n!MESSAGE by defining the macro CFG on the command line. For example:\n!MESSAGE \n!MESSAGE NMAKE /f \"LzmaUtil.mak\" CFG=\"LzmaUtil - Win32 Debug\"\n!MESSAGE \n!MESSAGE Possible choices for configuration are:\n!MESSAGE \n!MESSAGE \"LzmaUtil - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \"LzmaUtil - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n\n!IF  \"$(CFG)\" == \"LzmaUtil - Win32 Release\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \"Release\"\n# PROP BASE Intermediate_Dir \"Release\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \"Release\"\n# PROP Intermediate_Dir \"Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n# ADD CPP /nologo /MT /W3 /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /c\n# SUBTRACT CPP /YX\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\n# ADD RSC /l 0x419 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\util\\lzmac.exe\"\n\n!ELSEIF  \"$(CFG)\" == \"LzmaUtil - Win32 Debug\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 1\n# PROP BASE Output_Dir \"Debug\"\n# PROP BASE Intermediate_Dir \"Debug\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 1\n# PROP Output_Dir \"Debug\"\n# PROP Intermediate_Dir \"Debug\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /FD /GZ /c\n# SUBTRACT CPP /YX\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\n# ADD RSC /l 0x419 /d \"_DEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\util\\lzmac.exe\" /pdbtype:sept\n\n!ENDIF \n\n# Begin Target\n\n# Name \"LzmaUtil - Win32 Release\"\n# Name \"LzmaUtil - Win32 Debug\"\n# Begin Source File\n\nSOURCE=..\\7zFile.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\7zFile.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\7zStream.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\7zVersion.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\Alloc.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\Alloc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\CpuArch.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzFind.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzFind.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzFindMt.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzFindMt.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzHash.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaDec.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaDec.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaEnc.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaEnc.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\LzmaUtil.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\Threads.c\n# End Source File\n# Begin Source File\n\nSOURCE=..\\Threads.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\Types.h\n# End Source File\n# End Target\n# End Project\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaUtil/LzmaUtil.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n###############################################################################\n\nProject: \"LzmaUtil\"=.\\LzmaUtil.dsp - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nGlobal:\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<3>\n{{{\n}}}\n\n###############################################################################\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaUtil/makefile",
    "content": "MY_STATIC_LINK=1\nPROG = LZMAc.exe\n\nCFLAGS = $(CFLAGS) \\\n  -DCOMPRESS_MF_MT \\\n\nLIB_OBJS = \\\n  $O\\LzmaUtil.obj \\\n\nC_OBJS = \\\n  $O\\Alloc.obj \\\n  $O\\LzFind.obj \\\n  $O\\LzFindMt.obj \\\n  $O\\LzmaDec.obj \\\n  $O\\LzmaEnc.obj \\\n  $O\\7zFile.obj \\\n  $O\\7zStream.obj \\\n  $O\\Threads.obj \\\n\nOBJS = \\\n  $(LIB_OBJS) \\\n  $(C_OBJS) \\\n\n!include \"../../CPP/Build.mak\"\n\n$(LIB_OBJS): $(*B).c\n\t$(COMPL_O2)\n$(C_OBJS): ../$(*B).c\n\t$(COMPL_O2)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/LzmaUtil/makefile.gcc",
    "content": "PROG = lzma\nCC = gcc\nLIB = liblzma.a\nRM = rm -f\nCFLAGS = -c -O2 -Wall\nAR = ar\nRANLIB = ranlib\n\nOBJS = \\\n  Alloc.o \\\n  LzFind.o \\\n  LzmaDec.o \\\n  LzmaEnc.o \\\n  LzmaLib.o \\\n  7zFile.o \\\n  7zStream.o \\\n\nall: $(PROG)\n\n$(PROG): LzmaUtil.o $(LIB)\n\t$(CC) -o $(PROG) $(LDFLAGS) $< $(LIB)\n\nLzmaUtil.o: LzmaUtil.c\n\t$(CC) $(CFLAGS) LzmaUtil.c\n\n$(LIB): $(OBJS)\n\trm -f $@\n\t$(AR) rcu $@ $(OBJS)\n\t$(RANLIB) $@\n\nAlloc.o: ../Alloc.c\n\t$(CC) $(CFLAGS) ../Alloc.c\n\nLzFind.o: ../LzFind.c\n\t$(CC) $(CFLAGS) ../LzFind.c\n\nLzmaDec.o: ../LzmaDec.c\n\t$(CC) $(CFLAGS) ../LzmaDec.c\n\nLzmaEnc.o: ../LzmaEnc.c\n\t$(CC) $(CFLAGS) ../LzmaEnc.c\n\nLzmaLib.o: ../LzmaLib.c\n\t$(CC) $(CFLAGS) ../LzmaLib.c\n\n7zFile.o: ../7zFile.c\n\t$(CC) $(CFLAGS) ../7zFile.c\n\n7zStream.o: ../7zStream.c\n\t$(CC) $(CFLAGS) ../7zStream.c\n\nclean:\n\t-$(RM) $(PROG) *.o *.a\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Threads.c",
    "content": "/* Threads.c -- multithreading library\n2008-08-05\nIgor Pavlov\nPublic domain */\n\n#include \"Threads.h\"\n#include <process.h>\n\nstatic WRes GetError()\n{\n  DWORD res = GetLastError();\n  return (res) ? (WRes)(res) : 1;\n}\n\nWRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }\nWRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }\n\nstatic WRes MyCloseHandle(HANDLE *h)\n{\n  if (*h != NULL)\n    if (!CloseHandle(*h))\n      return GetError();\n  *h = NULL;\n  return 0;\n}\n\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\n{\n  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\n  thread->handle =\n    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */\n    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);\n    /* maybe we must use errno here, but probably GetLastError() is also OK. */\n  return HandleToWRes(thread->handle);\n}\n\nWRes WaitObject(HANDLE h)\n{\n  return (WRes)WaitForSingleObject(h, INFINITE);\n}\n\nWRes Thread_Wait(CThread *thread)\n{\n  if (thread->handle == NULL)\n    return 1;\n  return WaitObject(thread->handle);\n}\n\nWRes Thread_Close(CThread *thread)\n{\n  return MyCloseHandle(&thread->handle);\n}\n\nWRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)\n{\n  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);\n  return HandleToWRes(p->handle);\n}\n\nWRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)\n  { return Event_Create(p, TRUE, initialSignaled); }\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)\n  { return ManualResetEvent_Create(p, 0); }\n\nWRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)\n  { return Event_Create(p, FALSE, initialSignaled); }\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)\n  { return AutoResetEvent_Create(p, 0); }\n\nWRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }\nWRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }\nWRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }\nWRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }\n\n\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)\n{\n  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);\n  return HandleToWRes(p->handle);\n}\n\nWRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)\n{\n  return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));\n}\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)\n{\n  return Semaphore_Release(p, (LONG)releaseCount, NULL);\n}\nWRes Semaphore_Release1(CSemaphore *p)\n{\n  return Semaphore_ReleaseN(p, 1);\n}\n\nWRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }\nWRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }\n\nWRes CriticalSection_Init(CCriticalSection *p)\n{\n  /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\n  __try\n  {\n    InitializeCriticalSection(p);\n    /* InitializeCriticalSectionAndSpinCount(p, 0); */\n  }\n  __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }\n  return 0;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Threads.h",
    "content": "/* Threads.h -- multithreading library\n2008-11-22 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_THRESDS_H\n#define __7Z_THRESDS_H\n\n#include \"Types.h\"\n\ntypedef struct _CThread\n{\n  HANDLE handle;\n} CThread;\n\n#define Thread_Construct(thread) (thread)->handle = NULL\n#define Thread_WasCreated(thread) ((thread)->handle != NULL)\n \ntypedef unsigned THREAD_FUNC_RET_TYPE;\n#define THREAD_FUNC_CALL_TYPE MY_STD_CALL\n#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\n\nWRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);\nWRes Thread_Wait(CThread *thread);\nWRes Thread_Close(CThread *thread);\n\ntypedef struct _CEvent\n{\n  HANDLE handle;\n} CEvent;\n\ntypedef CEvent CAutoResetEvent;\ntypedef CEvent CManualResetEvent;\n\n#define Event_Construct(event) (event)->handle = NULL\n#define Event_IsCreated(event) ((event)->handle != NULL)\n\nWRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);\nWRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);\nWRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);\nWRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);\nWRes Event_Set(CEvent *event);\nWRes Event_Reset(CEvent *event);\nWRes Event_Wait(CEvent *event);\nWRes Event_Close(CEvent *event);\n\n\ntypedef struct _CSemaphore\n{\n  HANDLE handle;\n} CSemaphore;\n\n#define Semaphore_Construct(p) (p)->handle = NULL\n\nWRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);\nWRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\nWRes Semaphore_Release1(CSemaphore *p);\nWRes Semaphore_Wait(CSemaphore *p);\nWRes Semaphore_Close(CSemaphore *p);\n\n\ntypedef CRITICAL_SECTION CCriticalSection;\n\nWRes CriticalSection_Init(CCriticalSection *p);\n#define CriticalSection_Delete(p) DeleteCriticalSection(p)\n#define CriticalSection_Enter(p) EnterCriticalSection(p)\n#define CriticalSection_Leave(p) LeaveCriticalSection(p)\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/C/Types.h",
    "content": "/* Types.h -- Basic types\n2008-11-23 : Igor Pavlov : Public domain */\n\n#ifndef __7Z_TYPES_H\n#define __7Z_TYPES_H\n\n#include <stddef.h>\n\n#ifdef _WIN32\n#include <windows.h>\n#endif\n\n#define SZ_OK 0\n\n#define SZ_ERROR_DATA 1\n#define SZ_ERROR_MEM 2\n#define SZ_ERROR_CRC 3\n#define SZ_ERROR_UNSUPPORTED 4\n#define SZ_ERROR_PARAM 5\n#define SZ_ERROR_INPUT_EOF 6\n#define SZ_ERROR_OUTPUT_EOF 7\n#define SZ_ERROR_READ 8\n#define SZ_ERROR_WRITE 9\n#define SZ_ERROR_PROGRESS 10\n#define SZ_ERROR_FAIL 11\n#define SZ_ERROR_THREAD 12\n\n#define SZ_ERROR_ARCHIVE 16\n#define SZ_ERROR_NO_ARCHIVE 17\n\ntypedef int SRes;\n\n#ifdef _WIN32\ntypedef DWORD WRes;\n#else\ntypedef int WRes;\n#endif\n\n#ifndef RINOK\n#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\n#endif\n\ntypedef unsigned char Byte;\ntypedef short Int16;\ntypedef unsigned short UInt16;\n\n#ifdef _LZMA_UINT32_IS_ULONG\ntypedef long Int32;\ntypedef unsigned long UInt32;\n#else\ntypedef int Int32;\ntypedef unsigned int UInt32;\n#endif\n\n#ifdef _SZ_NO_INT_64\n\n/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\n   NOTES: Some code will work incorrectly in that case! */\n\ntypedef long Int64;\ntypedef unsigned long UInt64;\n\n#else\n\n#if defined(_MSC_VER) || defined(__BORLANDC__)\ntypedef __int64 Int64;\ntypedef unsigned __int64 UInt64;\n#else\ntypedef long long int Int64;\ntypedef unsigned long long int UInt64;\n#endif\n\n#endif\n\n#ifdef _LZMA_NO_SYSTEM_SIZE_T\ntypedef UInt32 SizeT;\n#else\ntypedef size_t SizeT;\n#endif\n\ntypedef int Bool;\n#define True 1\n#define False 0\n\n\n#ifdef _MSC_VER\n\n#if _MSC_VER >= 1300\n#define MY_NO_INLINE __declspec(noinline)\n#else\n#define MY_NO_INLINE\n#endif\n\n#define MY_CDECL __cdecl\n#define MY_STD_CALL __stdcall\n#define MY_FAST_CALL MY_NO_INLINE __fastcall\n\n#else\n\n#define MY_CDECL\n#define MY_STD_CALL\n#define MY_FAST_CALL\n\n#endif\n\n\n/* The following interfaces use first parameter as pointer to structure */\n\ntypedef struct\n{\n  SRes (*Read)(void *p, void *buf, size_t *size);\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\n       (output(*size) < input(*size)) is allowed */\n} ISeqInStream;\n\n/* it can return SZ_ERROR_INPUT_EOF */\nSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\nSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\nSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\n\ntypedef struct\n{\n  size_t (*Write)(void *p, const void *buf, size_t size);\n    /* Returns: result - the number of actually written bytes.\n       (result < size) means error */\n} ISeqOutStream;\n\ntypedef enum\n{\n  SZ_SEEK_SET = 0,\n  SZ_SEEK_CUR = 1,\n  SZ_SEEK_END = 2\n} ESzSeek;\n\ntypedef struct\n{\n  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\n} ISeekInStream;\n\ntypedef struct\n{\n  SRes (*Look)(void *p, void **buf, size_t *size);\n    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\n       (output(*size) > input(*size)) is not allowed\n       (output(*size) < input(*size)) is allowed */\n  SRes (*Skip)(void *p, size_t offset);\n    /* offset must be <= output(*size) of Look */\n\n  SRes (*Read)(void *p, void *buf, size_t *size);\n    /* reads directly (without buffer). It's same as ISeqInStream::Read */\n  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\n} ILookInStream;\n\nSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\nSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\n\n/* reads via ILookInStream::Read */\nSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\nSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\n\n#define LookToRead_BUF_SIZE (1 << 14)\n\ntypedef struct\n{\n  ILookInStream s;\n  ISeekInStream *realStream;\n  size_t pos;\n  size_t size;\n  Byte buf[LookToRead_BUF_SIZE];\n} CLookToRead;\n\nvoid LookToRead_CreateVTable(CLookToRead *p, int lookahead);\nvoid LookToRead_Init(CLookToRead *p);\n\ntypedef struct\n{\n  ISeqInStream s;\n  ILookInStream *realStream;\n} CSecToLook;\n\nvoid SecToLook_CreateVTable(CSecToLook *p);\n\ntypedef struct\n{\n  ISeqInStream s;\n  ILookInStream *realStream;\n} CSecToRead;\n\nvoid SecToRead_CreateVTable(CSecToRead *p);\n\ntypedef struct\n{\n  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\n    /* Returns: result. (result != SZ_OK) means break.\n       Value (UInt64)(Int64)-1 for size means unknown value. */\n} ICompressProgress;\n\ntypedef struct\n{\n  void *(*Alloc)(void *p, size_t size);\n  void (*Free)(void *p, void *address); /* address can be 0 */\n} ISzAlloc;\n\n#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\n#define IAlloc_Free(p, a) (p)->Free((p), a)\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zCompressionMode.cpp",
    "content": "// CompressionMethod.cpp\n\n#include \"StdAfx.h\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zCompressionMode.h",
    "content": "// 7zCompressionMode.h\n\n#ifndef __7Z_COMPRESSION_MODE_H\n#define __7Z_COMPRESSION_MODE_H\n\n#include \"../../../Common/MyString.h\"\n\n#include \"../../../Windows/PropVariant.h\"\n\n#include \"../../Common/MethodProps.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nstruct CMethodFull: public CMethod\n{\n  UInt32 NumInStreams;\n  UInt32 NumOutStreams;\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\n};\n\nstruct CBind\n{\n  UInt32 InCoder;\n  UInt32 InStream;\n  UInt32 OutCoder;\n  UInt32 OutStream;\n};\n\nstruct CCompressionMethodMode\n{\n  CObjectVector<CMethodFull> Methods;\n  CRecordVector<CBind> Binds;\n  #ifdef COMPRESS_MT\n  UInt32 NumThreads;\n  #endif\n  bool PasswordIsDefined;\n  UString Password;\n\n  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }\n  CCompressionMethodMode(): PasswordIsDefined(false)\n      #ifdef COMPRESS_MT\n      , NumThreads(1)\n      #endif\n  {}\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zDecode.cpp",
    "content": "// 7zDecode.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../Common/LimitedStreams.h\"\n#include \"../../Common/LockedStream.h\"\n#include \"../../Common/ProgressUtils.h\"\n#include \"../../Common/StreamObjects.h\"\n\n#include \"7zDecode.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nstatic void ConvertFolderItemInfoToBindInfo(const CFolder &folder,\n    CBindInfoEx &bindInfo)\n{\n  bindInfo.Clear();\n  int i;\n  for (i = 0; i < folder.BindPairs.Size(); i++)\n  {\n    NCoderMixer::CBindPair bindPair;\n    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;\n    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;\n    bindInfo.BindPairs.Add(bindPair);\n  }\n  UInt32 outStreamIndex = 0;\n  for (i = 0; i < folder.Coders.Size(); i++)\n  {\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\n    const CCoderInfo &coderInfo = folder.Coders[i];\n    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;\n    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;\n    bindInfo.Coders.Add(coderStreamsInfo);\n    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);\n    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)\n      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)\n        bindInfo.OutStreams.Add(outStreamIndex);\n  }\n  for (i = 0; i < folder.PackStreams.Size(); i++)\n    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);\n}\n\nstatic bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1,\n    const NCoderMixer::CCoderStreamsInfo &a2)\n{\n  return (a1.NumInStreams == a2.NumInStreams) &&\n    (a1.NumOutStreams == a2.NumOutStreams);\n}\n\nstatic bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)\n{\n  return (a1.InIndex == a2.InIndex) &&\n    (a1.OutIndex == a2.OutIndex);\n}\n\nstatic bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)\n{\n  if (a1.Coders.Size() != a2.Coders.Size())\n    return false;\n  int i;\n  for (i = 0; i < a1.Coders.Size(); i++)\n    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))\n      return false;\n  if (a1.BindPairs.Size() != a2.BindPairs.Size())\n    return false;\n  for (i = 0; i < a1.BindPairs.Size(); i++)\n    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))\n      return false;\n  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)\n    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])\n      return false;\n  if (a1.InStreams.Size() != a2.InStreams.Size())\n    return false;\n  if (a1.OutStreams.Size() != a2.OutStreams.Size())\n    return false;\n  return true;\n}\n\nCDecoder::CDecoder(bool multiThread)\n{\n  #ifndef _ST_MODE\n  multiThread = true;\n  #endif\n  _multiThread = multiThread;\n  _bindInfoExPrevIsDefined = false;\n}\n\nHRESULT CDecoder::Decode(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    IInStream *inStream,\n    UInt64 startPos,\n    const UInt64 *packSizes,\n    const CFolder &folderInfo,\n    ISequentialOutStream *outStream,\n    ICompressProgressInfo *compressProgress\n    #ifndef _NO_CRYPTO\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\n    #endif\n    #ifdef COMPRESS_MT\n    , bool mtMode, UInt32 numThreads\n    #endif\n    )\n{\n  if (!folderInfo.CheckStructure())\n    return E_NOTIMPL;\n  #ifndef _NO_CRYPTO\n  passwordIsDefined = false;\n  #endif\n  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;\n  \n  CLockedInStream lockedInStream;\n  lockedInStream.Init(inStream);\n  \n  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)\n  {\n    CLockedSequentialInStreamImp *lockedStreamImpSpec = new\n        CLockedSequentialInStreamImp;\n    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;\n    lockedStreamImpSpec->Init(&lockedInStream, startPos);\n    startPos += packSizes[j];\n    \n    CLimitedSequentialInStream *streamSpec = new\n        CLimitedSequentialInStream;\n    CMyComPtr<ISequentialInStream> inStream = streamSpec;\n    streamSpec->SetStream(lockedStreamImp);\n    streamSpec->Init(packSizes[j]);\n    inStreams.Add(inStream);\n  }\n  \n  int numCoders = folderInfo.Coders.Size();\n  \n  CBindInfoEx bindInfo;\n  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);\n  bool createNewCoders;\n  if (!_bindInfoExPrevIsDefined)\n    createNewCoders = true;\n  else\n    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);\n  if (createNewCoders)\n  {\n    int i;\n    _decoders.Clear();\n    // _decoders2.Clear();\n    \n    _mixerCoder.Release();\n\n    if (_multiThread)\n    {\n      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;\n      _mixerCoder = _mixerCoderMTSpec;\n      _mixerCoderCommon = _mixerCoderMTSpec;\n    }\n    else\n    {\n      #ifdef _ST_MODE\n      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;\n      _mixerCoder = _mixerCoderSTSpec;\n      _mixerCoderCommon = _mixerCoderSTSpec;\n      #endif\n    }\n    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));\n    \n    for (i = 0; i < numCoders; i++)\n    {\n      const CCoderInfo &coderInfo = folderInfo.Coders[i];\n\n  \n      CMyComPtr<ICompressCoder> decoder;\n      CMyComPtr<ICompressCoder2> decoder2;\n      RINOK(CreateCoder(\n          EXTERNAL_CODECS_LOC_VARS\n          coderInfo.MethodID, decoder, decoder2, false));\n      CMyComPtr<IUnknown> decoderUnknown;\n      if (coderInfo.IsSimpleCoder())\n      {\n        if (decoder == 0)\n          return E_NOTIMPL;\n\n        decoderUnknown = (IUnknown *)decoder;\n        \n        if (_multiThread)\n          _mixerCoderMTSpec->AddCoder(decoder);\n        #ifdef _ST_MODE\n        else\n          _mixerCoderSTSpec->AddCoder(decoder, false);\n        #endif\n      }\n      else\n      {\n        if (decoder2 == 0)\n          return E_NOTIMPL;\n        decoderUnknown = (IUnknown *)decoder2;\n        if (_multiThread)\n          _mixerCoderMTSpec->AddCoder2(decoder2);\n        #ifdef _ST_MODE\n        else\n          _mixerCoderSTSpec->AddCoder2(decoder2, false);\n        #endif\n      }\n      _decoders.Add(decoderUnknown);\n      #ifdef EXTERNAL_CODECS\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\n      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\n      if (setCompressCodecsInfo)\n      {\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\n      }\n      #endif\n    }\n    _bindInfoExPrev = bindInfo;\n    _bindInfoExPrevIsDefined = true;\n  }\n  int i;\n  _mixerCoderCommon->ReInit();\n  \n  UInt32 packStreamIndex = 0, unpackStreamIndex = 0;\n  UInt32 coderIndex = 0;\n  // UInt32 coder2Index = 0;\n  \n  for (i = 0; i < numCoders; i++)\n  {\n    const CCoderInfo &coderInfo = folderInfo.Coders[i];\n    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];\n    \n    {\n      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\n      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\n      if (setDecoderProperties)\n      {\n        const CByteBuffer &props = coderInfo.Props;\n        size_t size = props.GetCapacity();\n        if (size > 0xFFFFFFFF)\n          return E_NOTIMPL;\n        if (size > 0)\n        {\n          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)props, (UInt32)size));\n        }\n      }\n    }\n\n    #ifdef COMPRESS_MT\n    if (mtMode)\n    {\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\n      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\n      if (setCoderMt)\n      {\n        RINOK(setCoderMt->SetNumberOfThreads(numThreads));\n      }\n    }\n    #endif\n\n    #ifndef _NO_CRYPTO\n    {\n      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\n      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\n      if (cryptoSetPassword)\n      {\n        if (getTextPassword == 0)\n          return E_FAIL;\n        CMyComBSTR passwordBSTR;\n        RINOK(getTextPassword->CryptoGetTextPassword(&passwordBSTR));\n        CByteBuffer buffer;\n        passwordIsDefined = true;\n        const UString password(passwordBSTR);\n        const UInt32 sizeInBytes = password.Length() * 2;\n        buffer.SetCapacity(sizeInBytes);\n        for (int i = 0; i < password.Length(); i++)\n        {\n          wchar_t c = password[i];\n          ((Byte *)buffer)[i * 2] = (Byte)c;\n          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\n        }\n        RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\n      }\n    }\n    #endif\n\n    coderIndex++;\n    \n    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;\n    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;\n    CRecordVector<const UInt64 *> packSizesPointers;\n    CRecordVector<const UInt64 *> unpackSizesPointers;\n    packSizesPointers.Reserve(numInStreams);\n    unpackSizesPointers.Reserve(numOutStreams);\n    UInt32 j;\n    for (j = 0; j < numOutStreams; j++, unpackStreamIndex++)\n      unpackSizesPointers.Add(&folderInfo.UnpackSizes[unpackStreamIndex]);\n    \n    for (j = 0; j < numInStreams; j++, packStreamIndex++)\n    {\n      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);\n      if (bindPairIndex >= 0)\n        packSizesPointers.Add(\n        &folderInfo.UnpackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);\n      else\n      {\n        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);\n        if (index < 0)\n          return E_FAIL;\n        packSizesPointers.Add(&packSizes[index]);\n      }\n    }\n    \n    _mixerCoderCommon->SetCoderInfo(i,\n        &packSizesPointers.Front(),\n        &unpackSizesPointers.Front());\n  }\n  UInt32 mainCoder, temp;\n  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);\n\n  if (_multiThread)\n    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);\n  /*\n  else\n    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;\n  */\n  \n  if (numCoders == 0)\n    return 0;\n  CRecordVector<ISequentialInStream *> inStreamPointers;\n  inStreamPointers.Reserve(inStreams.Size());\n  for (i = 0; i < inStreams.Size(); i++)\n    inStreamPointers.Add(inStreams[i]);\n  ISequentialOutStream *outStreamPointer = outStream;\n  return _mixerCoder->Code(&inStreamPointers.Front(), NULL,\n    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zDecode.h",
    "content": "// 7zDecode.h\n\n#ifndef __7Z_DECODE_H\n#define __7Z_DECODE_H\n\n#include \"../../IStream.h\"\n#include \"../../IPassword.h\"\n\n#include \"../Common/CoderMixer2.h\"\n#include \"../Common/CoderMixer2MT.h\"\n#ifdef _ST_MODE\n#include \"../Common/CoderMixer2ST.h\"\n#endif\n\n#include \"../../Common/CreateCoder.h\"\n\n#include \"7zItem.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nstruct CBindInfoEx: public NCoderMixer::CBindInfo\n{\n  CRecordVector<CMethodId> CoderMethodIDs;\n  void Clear()\n  {\n    CBindInfo::Clear();\n    CoderMethodIDs.Clear();\n  }\n};\n\nclass CDecoder\n{\n  bool _bindInfoExPrevIsDefined;\n  CBindInfoEx _bindInfoExPrev;\n  \n  bool _multiThread;\n  #ifdef _ST_MODE\n  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;\n  #endif\n  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;\n  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;\n  \n  CMyComPtr<ICompressCoder2> _mixerCoder;\n  CObjectVector<CMyComPtr<IUnknown> > _decoders;\n  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;\npublic:\n  CDecoder(bool multiThread);\n  HRESULT Decode(\n      DECL_EXTERNAL_CODECS_LOC_VARS\n      IInStream *inStream,\n      UInt64 startPos,\n      const UInt64 *packSizes,\n      const CFolder &folder,\n      ISequentialOutStream *outStream,\n      ICompressProgressInfo *compressProgress\n      #ifndef _NO_CRYPTO\n      , ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined\n      #endif\n      #ifdef COMPRESS_MT\n      , bool mtMode, UInt32 numThreads\n      #endif\n      );\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zEncode.cpp",
    "content": "// Encode.cpp\n\n#include \"StdAfx.h\"\n\n#include \"7zEncode.h\"\n#include \"7zSpecStream.h\"\n\n#include \"../../IPassword.h\"\n#include \"../../Common/ProgressUtils.h\"\n#include \"../../Common/LimitedStreams.h\"\n#include \"../../Common/InOutTempBuffer.h\"\n#include \"../../Common/StreamObjects.h\"\n#include \"../../Common/CreateCoder.h\"\n#include \"../../Common/FilterCoder.h\"\n\nstatic const UInt64 k_AES = 0x06F10701;\nstatic const UInt64 k_BCJ  = 0x03030103;\nstatic const UInt64 k_BCJ2 = 0x0303011B;\n\nnamespace NArchive {\nnamespace N7z {\n\nstatic void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,\n    const CRecordVector<CMethodId> decompressionMethods,\n    CFolder &folder)\n{\n  folder.Coders.Clear();\n  // bindInfo.CoderMethodIDs.Clear();\n  // folder.OutStreams.Clear();\n  folder.PackStreams.Clear();\n  folder.BindPairs.Clear();\n  int i;\n  for (i = 0; i < bindInfo.BindPairs.Size(); i++)\n  {\n    CBindPair bindPair;\n    bindPair.InIndex = bindInfo.BindPairs[i].InIndex;\n    bindPair.OutIndex = bindInfo.BindPairs[i].OutIndex;\n    folder.BindPairs.Add(bindPair);\n  }\n  for (i = 0; i < bindInfo.Coders.Size(); i++)\n  {\n    CCoderInfo coderInfo;\n    const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];\n    coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;\n    coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;\n    coderInfo.MethodID = decompressionMethods[i];\n    folder.Coders.Add(coderInfo);\n  }\n  for (i = 0; i < bindInfo.InStreams.Size(); i++)\n    folder.PackStreams.Add(bindInfo.InStreams[i]);\n}\n\nHRESULT CEncoder::CreateMixerCoder(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    const UInt64 *inSizeForReduce)\n{\n  _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;\n  _mixerCoder = _mixerCoderSpec;\n  RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));\n  for (int i = 0; i < _options.Methods.Size(); i++)\n  {\n    const CMethodFull &methodFull = _options.Methods[i];\n    _codersInfo.Add(CCoderInfo());\n    CCoderInfo &encodingInfo = _codersInfo.Back();\n    encodingInfo.MethodID = methodFull.Id;\n    CMyComPtr<ICompressCoder> encoder;\n    CMyComPtr<ICompressCoder2> encoder2;\n    \n\n    RINOK(CreateCoder(\n        EXTERNAL_CODECS_LOC_VARS\n        methodFull.Id, encoder, encoder2, true));\n\n    if (!encoder && !encoder2)\n      return E_FAIL;\n\n    CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;\n   \n    #ifdef COMPRESS_MT\n    {\n      CMyComPtr<ICompressSetCoderMt> setCoderMt;\n      encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);\n      if (setCoderMt)\n      {\n        RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));\n      }\n    }\n    #endif\n        \n\n    RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon));\n\n    /*\n    CMyComPtr<ICryptoResetSalt> resetSalt;\n    encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);\n    if (resetSalt != NULL)\n    {\n      resetSalt->ResetSalt();\n    }\n    */\n\n    #ifdef EXTERNAL_CODECS\n    CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\n    encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\n    if (setCompressCodecsInfo)\n    {\n      RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));\n    }\n    #endif\n    \n    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;\n    encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);\n\n    if (cryptoSetPassword)\n    {\n      CByteBuffer buffer;\n      const UInt32 sizeInBytes = _options.Password.Length() * 2;\n      buffer.SetCapacity(sizeInBytes);\n      for (int i = 0; i < _options.Password.Length(); i++)\n      {\n        wchar_t c = _options.Password[i];\n        ((Byte *)buffer)[i * 2] = (Byte)c;\n        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);\n      }\n      RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));\n    }\n\n    if (encoder)\n      _mixerCoderSpec->AddCoder(encoder);\n    else\n      _mixerCoderSpec->AddCoder2(encoder2);\n  }\n  return S_OK;\n}\n\nHRESULT CEncoder::Encode(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    ISequentialInStream *inStream,\n    const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\n    CFolder &folderItem,\n    ISequentialOutStream *outStream,\n    CRecordVector<UInt64> &packSizes,\n    ICompressProgressInfo *compressProgress)\n{\n  RINOK(EncoderConstr());\n\n  if (_mixerCoderSpec == NULL)\n  {\n    RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));\n  }\n  _mixerCoderSpec->ReInit();\n  // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);\n\n  CObjectVector<CInOutTempBuffer> inOutTempBuffers;\n  CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;\n  CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;\n  int numMethods = _bindInfo.Coders.Size();\n  int i;\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\n  {\n    inOutTempBuffers.Add(CInOutTempBuffer());\n    inOutTempBuffers.Back().Create();\n    inOutTempBuffers.Back().InitWriting();\n  }\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\n  {\n    CSequentialOutTempBufferImp *tempBufferSpec =\n        new CSequentialOutTempBufferImp;\n    CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;\n    tempBufferSpec->Init(&inOutTempBuffers[i - 1]);\n    tempBuffers.Add(tempBuffer);\n    tempBufferSpecs.Add(tempBufferSpec);\n  }\n\n  for (i = 0; i < numMethods; i++)\n    _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);\n\n  if (_bindInfo.InStreams.IsEmpty())\n    return E_FAIL;\n  UInt32 mainCoderIndex, mainStreamIndex;\n  _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);\n  \n  if (inStreamSize != NULL)\n  {\n    CRecordVector<const UInt64 *> sizePointers;\n    for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)\n      if (i == mainStreamIndex)\n        sizePointers.Add(inStreamSize);\n      else\n        sizePointers.Add(NULL);\n    _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);\n  }\n\n  \n  // UInt64 outStreamStartPos;\n  // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));\n  \n  CSequentialInStreamSizeCount2 *inStreamSizeCountSpec =\n      new CSequentialInStreamSizeCount2;\n  CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;\n  CSequentialOutStreamSizeCount *outStreamSizeCountSpec =\n      new CSequentialOutStreamSizeCount;\n  CMyComPtr<ISequentialOutStream> outStreamSizeCount = outStreamSizeCountSpec;\n\n  inStreamSizeCountSpec->Init(inStream);\n  outStreamSizeCountSpec->SetStream(outStream);\n  outStreamSizeCountSpec->Init();\n\n  CRecordVector<ISequentialInStream *> inStreamPointers;\n  CRecordVector<ISequentialOutStream *> outStreamPointers;\n  inStreamPointers.Add(inStreamSizeCount);\n  outStreamPointers.Add(outStreamSizeCount);\n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\n    outStreamPointers.Add(tempBuffers[i - 1]);\n\n  for (i = 0; i < _codersInfo.Size(); i++)\n  {\n    CCoderInfo &encodingInfo = _codersInfo[i];\n    \n    CMyComPtr<ICryptoResetInitVector> resetInitVector;\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);\n    if (resetInitVector != NULL)\n    {\n      resetInitVector->ResetInitVector();\n    }\n\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\n    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\n    if (writeCoderProperties != NULL)\n    {\n      CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\n      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\n      outStreamSpec->Init();\n      writeCoderProperties->WriteCoderProperties(outStream);\n      size_t size = outStreamSpec->GetSize();\n      encodingInfo.Props.SetCapacity(size);\n      memmove(encodingInfo.Props, outStreamSpec->GetBuffer(), size);\n    }\n  }\n\n  UInt32 progressIndex = mainCoderIndex;\n\n  for (i = 0; i < _codersInfo.Size(); i++)\n  {\n    const CCoderInfo &e = _codersInfo[i];\n    if ((e.MethodID == k_BCJ || e.MethodID == k_BCJ2) && i + 1 < _codersInfo.Size())\n      progressIndex = i + 1;\n  }\n\n  _mixerCoderSpec->SetProgressCoderIndex(progressIndex);\n  \n  RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,\n    &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));\n  \n  ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods,\n      folderItem);\n  \n  packSizes.Add(outStreamSizeCountSpec->GetSize());\n  \n  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)\n  {\n    CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];\n    inOutTempBuffer.FlushWrite();\n    inOutTempBuffer.InitReading();\n    inOutTempBuffer.WriteToStream(outStream);\n    packSizes.Add(inOutTempBuffer.GetDataSize());\n  }\n  \n  for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)\n  {\n    int binder = _bindInfo.FindBinderForInStream(\n        _bindReverseConverter->DestOutToSrcInMap[i]);\n    UInt64 streamSize;\n    if (binder < 0)\n      streamSize = inStreamSizeCountSpec->GetSize();\n    else\n      streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);\n    folderItem.UnpackSizes.Add(streamSize);\n  }\n  for (i = numMethods - 1; i >= 0; i--)\n    folderItem.Coders[numMethods - 1 - i].Props = _codersInfo[i].Props;\n  return S_OK;\n}\n\n\nCEncoder::CEncoder(const CCompressionMethodMode &options):\n  _bindReverseConverter(0),\n  _constructed(false)\n{\n  if (options.IsEmpty())\n    throw 1;\n\n  _options = options;\n  _mixerCoderSpec = NULL;\n}\n\nHRESULT CEncoder::EncoderConstr()\n{\n  if (_constructed)\n    return S_OK;\n  if (_options.Methods.IsEmpty())\n  {\n    // it has only password method;\n    if (!_options.PasswordIsDefined)\n      throw 1;\n    if (!_options.Binds.IsEmpty())\n      throw 1;\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\n    CMethodFull method;\n    \n    method.NumInStreams = 1;\n    method.NumOutStreams = 1;\n    coderStreamsInfo.NumInStreams = 1;\n    coderStreamsInfo.NumOutStreams = 1;\n    method.Id = k_AES;\n    \n    _options.Methods.Add(method);\n    _bindInfo.Coders.Add(coderStreamsInfo);\n  \n    _bindInfo.InStreams.Add(0);\n    _bindInfo.OutStreams.Add(0);\n  }\n  else\n  {\n\n  UInt32 numInStreams = 0, numOutStreams = 0;\n  int i;\n  for (i = 0; i < _options.Methods.Size(); i++)\n  {\n    const CMethodFull &methodFull = _options.Methods[i];\n    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\n    coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;\n    coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;\n    if (_options.Binds.IsEmpty())\n    {\n      if (i < _options.Methods.Size() - 1)\n      {\n        NCoderMixer::CBindPair bindPair;\n        bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;\n        bindPair.OutIndex = numOutStreams;\n        _bindInfo.BindPairs.Add(bindPair);\n      }\n      else\n        _bindInfo.OutStreams.Insert(0, numOutStreams);\n      for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)\n        _bindInfo.OutStreams.Add(numOutStreams + j);\n    }\n    \n    numInStreams += coderStreamsInfo.NumInStreams;\n    numOutStreams += coderStreamsInfo.NumOutStreams;\n\n    _bindInfo.Coders.Add(coderStreamsInfo);\n  }\n\n  if (!_options.Binds.IsEmpty())\n  {\n    for (i = 0; i < _options.Binds.Size(); i++)\n    {\n      NCoderMixer::CBindPair bindPair;\n      const CBind &bind = _options.Binds[i];\n      bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;\n      bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;\n      _bindInfo.BindPairs.Add(bindPair);\n    }\n    for (i = 0; i < (int)numOutStreams; i++)\n      if (_bindInfo.FindBinderForOutStream(i) == -1)\n        _bindInfo.OutStreams.Add(i);\n  }\n\n  for (i = 0; i < (int)numInStreams; i++)\n    if (_bindInfo.FindBinderForInStream(i) == -1)\n      _bindInfo.InStreams.Add(i);\n\n  if (_bindInfo.InStreams.IsEmpty())\n    throw 1; // this is error\n\n  // Make main stream first in list\n  int inIndex = _bindInfo.InStreams[0];\n  for (;;)\n  {\n    UInt32 coderIndex, coderStreamIndex;\n    _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);\n    UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);\n    int binder = _bindInfo.FindBinderForOutStream(outIndex);\n    if (binder >= 0)\n    {\n      inIndex = _bindInfo.BindPairs[binder].InIndex;\n      continue;\n    }\n    for (i = 0; i < _bindInfo.OutStreams.Size(); i++)\n      if (_bindInfo.OutStreams[i] == outIndex)\n      {\n        _bindInfo.OutStreams.Delete(i);\n        _bindInfo.OutStreams.Insert(0, outIndex);\n        break;\n      }\n    break;\n  }\n\n  if (_options.PasswordIsDefined)\n  {\n    int numCryptoStreams = _bindInfo.OutStreams.Size();\n\n    for (i = 0; i < numCryptoStreams; i++)\n    {\n      NCoderMixer::CBindPair bindPair;\n      bindPair.InIndex = numInStreams + i;\n      bindPair.OutIndex = _bindInfo.OutStreams[i];\n      _bindInfo.BindPairs.Add(bindPair);\n    }\n    _bindInfo.OutStreams.Clear();\n\n    /*\n    if (numCryptoStreams == 0)\n      numCryptoStreams = 1;\n    */\n\n    for (i = 0; i < numCryptoStreams; i++)\n    {\n      NCoderMixer::CCoderStreamsInfo coderStreamsInfo;\n      CMethodFull method;\n      method.NumInStreams = 1;\n      method.NumOutStreams = 1;\n      coderStreamsInfo.NumInStreams = method.NumOutStreams;\n      coderStreamsInfo.NumOutStreams = method.NumInStreams;\n      method.Id = k_AES;\n\n      _options.Methods.Add(method);\n      _bindInfo.Coders.Add(coderStreamsInfo);\n      _bindInfo.OutStreams.Add(numOutStreams + i);\n    }\n  }\n\n  }\n\n  for (int i = _options.Methods.Size() - 1; i >= 0; i--)\n  {\n    const CMethodFull &methodFull = _options.Methods[i];\n    _decompressionMethods.Add(methodFull.Id);\n  }\n\n  _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);\n  _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);\n  _constructed = true;\n  return S_OK;\n}\n\nCEncoder::~CEncoder()\n{\n  delete _bindReverseConverter;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zEncode.h",
    "content": "// 7zEncode.h\n\n#ifndef __7Z_ENCODE_H\n#define __7Z_ENCODE_H\n\n// #include \"../../Common/StreamObjects.h\"\n\n#include \"7zCompressionMode.h\"\n\n#include \"../Common/CoderMixer2.h\"\n#include \"../Common/CoderMixer2MT.h\"\n#ifdef _ST_MODE\n#include \"../Common/CoderMixer2ST.h\"\n#endif\n#include \"7zItem.h\"\n\n#include \"../../Common/CreateCoder.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nclass CEncoder\n{\n  NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;\n  CMyComPtr<ICompressCoder2> _mixerCoder;\n\n  CObjectVector<CCoderInfo> _codersInfo;\n\n  CCompressionMethodMode _options;\n  NCoderMixer::CBindInfo _bindInfo;\n  NCoderMixer::CBindInfo _decompressBindInfo;\n  NCoderMixer::CBindReverseConverter *_bindReverseConverter;\n  CRecordVector<CMethodId> _decompressionMethods;\n\n  HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS\n      const UInt64 *inSizeForReduce);\n\n  bool _constructed;\npublic:\n  CEncoder(const CCompressionMethodMode &options);\n  ~CEncoder();\n  HRESULT EncoderConstr();\n  HRESULT Encode(\n      DECL_EXTERNAL_CODECS_LOC_VARS\n      ISequentialInStream *inStream,\n      const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,\n      CFolder &folderItem,\n      ISequentialOutStream *outStream,\n      CRecordVector<UInt64> &packSizes,\n      ICompressProgressInfo *compressProgress);\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zExtract.cpp",
    "content": "// 7zExtract.cpp\n\n#include \"StdAfx.h\"\n\n#include \"7zHandler.h\"\n#include \"7zFolderOutStream.h\"\n#include \"7zDecode.h\"\n// #include \"7z1Decode.h\"\n\n#include \"../../../Common/ComTry.h\"\n#include \"../../Common/StreamObjects.h\"\n#include \"../../Common/ProgressUtils.h\"\n#include \"../../Common/LimitedStreams.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nstruct CExtractFolderInfo\n{\n  #ifdef _7Z_VOL\n  int VolumeIndex;\n  #endif\n  CNum FileIndex;\n  CNum FolderIndex;\n  CBoolVector ExtractStatuses;\n  UInt64 UnpackSize;\n  CExtractFolderInfo(\n    #ifdef _7Z_VOL\n    int volumeIndex,\n    #endif\n    CNum fileIndex, CNum folderIndex):\n    #ifdef _7Z_VOL\n    VolumeIndex(volumeIndex),\n    #endif\n    FileIndex(fileIndex),\n    FolderIndex(folderIndex),\n    UnpackSize(0)\n  {\n    if (fileIndex != kNumNoIndex)\n    {\n      ExtractStatuses.Reserve(1);\n      ExtractStatuses.Add(true);\n    }\n  };\n};\n\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\n    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)\n{\n  COM_TRY_BEGIN\n  bool testMode = (testModeSpec != 0);\n  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;\n  UInt64 importantTotalUnpacked = 0;\n\n  bool allFilesMode = (numItems == UInt32(-1));\n  if (allFilesMode)\n    numItems =\n    #ifdef _7Z_VOL\n    _refs.Size();\n    #else\n    _db.Files.Size();\n    #endif\n\n  if(numItems == 0)\n    return S_OK;\n\n  /*\n  if(_volumes.Size() != 1)\n    return E_FAIL;\n  const CVolume &volume = _volumes.Front();\n  const CArchiveDatabaseEx &_db = volume.Database;\n  IInStream *_inStream = volume.Stream;\n  */\n  \n  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;\n  for(UInt32 ii = 0; ii < numItems; ii++)\n  {\n    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];\n    UInt32 ref2Index = allFilesMode ? ii : indices[ii];\n    // const CRef2 &ref2 = _refs[ref2Index];\n\n    // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)\n    {\n      #ifdef _7Z_VOL\n      // const CRef &ref = ref2.Refs[ri];\n      const CRef &ref = _refs[ref2Index];\n\n      int volumeIndex = ref.VolumeIndex;\n      const CVolume &volume = _volumes[volumeIndex];\n      const CArchiveDatabaseEx &db = volume.Database;\n      UInt32 fileIndex = ref.ItemIndex;\n      #else\n      const CArchiveDatabaseEx &db = _db;\n      UInt32 fileIndex = ref2Index;\n      #endif\n\n      CNum folderIndex = db.FileIndexToFolderIndexMap[fileIndex];\n      if (folderIndex == kNumNoIndex)\n      {\n        extractFolderInfoVector.Add(CExtractFolderInfo(\n            #ifdef _7Z_VOL\n            volumeIndex,\n            #endif\n            fileIndex, kNumNoIndex));\n        continue;\n      }\n      if (extractFolderInfoVector.IsEmpty() ||\n        folderIndex != extractFolderInfoVector.Back().FolderIndex\n        #ifdef _7Z_VOL\n        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex\n        #endif\n        )\n      {\n        extractFolderInfoVector.Add(CExtractFolderInfo(\n            #ifdef _7Z_VOL\n            volumeIndex,\n            #endif\n            kNumNoIndex, folderIndex));\n        const CFolder &folderInfo = db.Folders[folderIndex];\n        UInt64 unpackSize = folderInfo.GetUnpackSize();\n        importantTotalUnpacked += unpackSize;\n        extractFolderInfoVector.Back().UnpackSize = unpackSize;\n      }\n      \n      CExtractFolderInfo &efi = extractFolderInfoVector.Back();\n      \n      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];\n      CNum startIndex = db.FolderStartFileIndex[folderIndex];\n      for (CNum index = efi.ExtractStatuses.Size();\n          index <= fileIndex - startIndex; index++)\n      {\n        // UInt64 unpackSize = _db.Files[startIndex + index].UnpackSize;\n        // Count partial_folder_size\n        // efi.UnpackSize += unpackSize;\n        // importantTotalUnpacked += unpackSize;\n        efi.ExtractStatuses.Add(index == fileIndex - startIndex);\n      }\n    }\n  }\n\n  extractCallback->SetTotal(importantTotalUnpacked);\n\n  CDecoder decoder(\n    #ifdef _ST_MODE\n    false\n    #else\n    true\n    #endif\n    );\n  // CDecoder1 decoder;\n\n  UInt64 currentTotalPacked = 0;\n  UInt64 currentTotalUnpacked = 0;\n  UInt64 totalFolderUnpacked;\n  UInt64 totalFolderPacked;\n\n  CLocalProgress *lps = new CLocalProgress;\n  CMyComPtr<ICompressProgressInfo> progress = lps;\n  lps->Init(extractCallback, false);\n\n  for(int i = 0; i < extractFolderInfoVector.Size(); i++,\n      currentTotalUnpacked += totalFolderUnpacked,\n      currentTotalPacked += totalFolderPacked)\n  {\n    lps->OutSize = currentTotalUnpacked;\n    lps->InSize = currentTotalPacked;\n    RINOK(lps->SetCur());\n    \n    const CExtractFolderInfo &efi = extractFolderInfoVector[i];\n    totalFolderUnpacked = efi.UnpackSize;\n\n    totalFolderPacked = 0;\n\n    CFolderOutStream *folderOutStream = new CFolderOutStream;\n    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);\n\n    #ifdef _7Z_VOL\n    const CVolume &volume = _volumes[efi.VolumeIndex];\n    const CArchiveDatabaseEx &db = volume.Database;\n    #else\n    const CArchiveDatabaseEx &db = _db;\n    #endif\n\n    CNum startIndex;\n    if (efi.FileIndex != kNumNoIndex)\n      startIndex = efi.FileIndex;\n    else\n      startIndex = db.FolderStartFileIndex[efi.FolderIndex];\n\n\n    HRESULT result = folderOutStream->Init(&db,\n        #ifdef _7Z_VOL\n        volume.StartRef2Index,\n        #else\n        0,\n        #endif\n        startIndex,\n        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);\n\n    RINOK(result);\n\n    if (efi.FileIndex != kNumNoIndex)\n      continue;\n\n    CNum folderIndex = efi.FolderIndex;\n    const CFolder &folderInfo = db.Folders[folderIndex];\n\n    totalFolderPacked = _db.GetFolderFullPackSize(folderIndex);\n\n    CNum packStreamIndex = db.FolderStartPackStreamIndex[folderIndex];\n    UInt64 folderStartPackPos = db.GetFolderStreamPos(folderIndex, 0);\n\n    #ifndef _NO_CRYPTO\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\n    if (extractCallback)\n      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\n    #endif\n\n    try\n    {\n      #ifndef _NO_CRYPTO\n      bool passwordIsDefined;\n      #endif\n\n      HRESULT result = decoder.Decode(\n          EXTERNAL_CODECS_VARS\n          #ifdef _7Z_VOL\n          volume.Stream,\n          #else\n          _inStream,\n          #endif\n          folderStartPackPos,\n          &db.PackSizes[packStreamIndex],\n          folderInfo,\n          outStream,\n          progress\n          #ifndef _NO_CRYPTO\n          , getTextPassword, passwordIsDefined\n          #endif\n          #ifdef COMPRESS_MT\n          , true, _numThreads\n          #endif\n          );\n\n      if (result == S_FALSE)\n      {\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\n        continue;\n      }\n      if (result == E_NOTIMPL)\n      {\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod));\n        continue;\n      }\n      if (result != S_OK)\n        return result;\n      if (folderOutStream->WasWritingFinished() != S_OK)\n      {\n        RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\n        continue;\n      }\n    }\n    catch(...)\n    {\n      RINOK(folderOutStream->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError));\n      continue;\n    }\n  }\n  return S_OK;\n  COM_TRY_END\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zFolderInStream.cpp",
    "content": "// 7zFolderInStream.cpp\n\n#include \"StdAfx.h\"\n\n#include \"7zFolderInStream.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nCFolderInStream::CFolderInStream()\n{\n  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;\n  _inStreamWithHash = _inStreamWithHashSpec;\n}\n\nvoid CFolderInStream::Init(IArchiveUpdateCallback *updateCallback,\n    const UInt32 *fileIndices, UInt32 numFiles)\n{\n  _updateCallback = updateCallback;\n  _numFiles = numFiles;\n  _fileIndex = 0;\n  _fileIndices = fileIndices;\n  Processed.Clear();\n  CRCs.Clear();\n  Sizes.Clear();\n  _fileIsOpen = false;\n  _currentSizeIsDefined = false;\n}\n\nHRESULT CFolderInStream::OpenStream()\n{\n  _filePos = 0;\n  while (_fileIndex < _numFiles)\n  {\n    _currentSizeIsDefined = false;\n    CMyComPtr<ISequentialInStream> stream;\n    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);\n    if (result != S_OK && result != S_FALSE)\n      return result;\n    _fileIndex++;\n    _inStreamWithHashSpec->SetStream(stream);\n    _inStreamWithHashSpec->Init();\n    if (!stream)\n    {\n      RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\n      Sizes.Add(0);\n      Processed.Add(result == S_OK);\n      AddDigest();\n      continue;\n    }\n    CMyComPtr<IStreamGetSize> streamGetSize;\n    if (stream.QueryInterface(IID_IStreamGetSize, &streamGetSize) == S_OK)\n    {\n      if(streamGetSize)\n      {\n        _currentSizeIsDefined = true;\n        RINOK(streamGetSize->GetSize(&_currentSize));\n      }\n    }\n\n    _fileIsOpen = true;\n    return S_OK;\n  }\n  return S_OK;\n}\n\nvoid CFolderInStream::AddDigest()\n{\n  CRCs.Add(_inStreamWithHashSpec->GetCRC());\n}\n\nHRESULT CFolderInStream::CloseStream()\n{\n  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));\n  _inStreamWithHashSpec->ReleaseStream();\n  _fileIsOpen = false;\n  Processed.Add(true);\n  Sizes.Add(_filePos);\n  AddDigest();\n  return S_OK;\n}\n\nSTDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize = 0;\n  while ((_fileIndex < _numFiles || _fileIsOpen) && size > 0)\n  {\n    if (_fileIsOpen)\n    {\n      UInt32 localProcessedSize;\n      RINOK(_inStreamWithHash->Read(\n          ((Byte *)data) + realProcessedSize, size, &localProcessedSize));\n      if (localProcessedSize == 0)\n      {\n        RINOK(CloseStream());\n        continue;\n      }\n      realProcessedSize += localProcessedSize;\n      _filePos += localProcessedSize;\n      size -= localProcessedSize;\n      break;\n    }\n    else\n    {\n      RINOK(OpenStream());\n    }\n  }\n  if (processedSize != 0)\n    *processedSize = realProcessedSize;\n  return S_OK;\n}\n\nSTDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)\n{\n  *value = 0;\n  int subStreamIndex = (int)subStream;\n  if (subStreamIndex < 0 || subStream > Sizes.Size())\n    return E_FAIL;\n  if (subStreamIndex < Sizes.Size())\n  {\n    *value= Sizes[subStreamIndex];\n    return S_OK;\n  }\n  if (!_currentSizeIsDefined)\n    return S_FALSE;\n  *value = _currentSize;\n  return S_OK;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zFolderInStream.h",
    "content": "// 7z/FolderInStream.h\n\n#ifndef __7Z_FOLDERINSTREAM_H\n#define __7Z_FOLDERINSTREAM_H\n\n#include \"7zItem.h\"\n#include \"7zHeader.h\"\n\n#include \"../IArchive.h\"\n#include \"../Common/InStreamWithCRC.h\"\n#include \"../../IStream.h\"\n#include \"../../ICoder.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nclass CFolderInStream:\n  public ISequentialInStream,\n  public ICompressGetSubStreamSize,\n  public CMyUnknownImp\n{\npublic:\n\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\n\n  CFolderInStream();\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\nprivate:\n  CSequentialInStreamWithCRC *_inStreamWithHashSpec;\n  CMyComPtr<ISequentialInStream> _inStreamWithHash;\n  CMyComPtr<IArchiveUpdateCallback> _updateCallback;\n\n  bool _currentSizeIsDefined;\n  UInt64 _currentSize;\n\n  bool _fileIsOpen;\n  UInt64 _filePos;\n\n  const UInt32 *_fileIndices;\n  UInt32 _numFiles;\n  UInt32 _fileIndex;\n\n  HRESULT OpenStream();\n  HRESULT CloseStream();\n  void AddDigest();\npublic:\n  void Init(IArchiveUpdateCallback *updateCallback,\n      const UInt32 *fileIndices, UInt32 numFiles);\n  CRecordVector<bool> Processed;\n  CRecordVector<UInt32> CRCs;\n  CRecordVector<UInt64> Sizes;\n  UInt64 GetFullSize() const\n  {\n    UInt64 size = 0;\n    for (int i = 0; i < Sizes.Size(); i++)\n      size += Sizes[i];\n    return size;\n  }\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zFolderOutStream.cpp",
    "content": "// 7zFolderOutStream.cpp\n\n#include \"StdAfx.h\"\n\n#include \"7zFolderOutStream.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nCFolderOutStream::CFolderOutStream()\n{\n  _outStreamWithHashSpec = new COutStreamWithCRC;\n  _outStreamWithHash = _outStreamWithHashSpec;\n}\n\nHRESULT CFolderOutStream::Init(\n    const CArchiveDatabaseEx *archiveDatabase,\n    UInt32 ref2Offset,\n    UInt32 startIndex,\n    const CBoolVector *extractStatuses,\n    IArchiveExtractCallback *extractCallback,\n    bool testMode,\n    bool checkCrc)\n{\n  _archiveDatabase = archiveDatabase;\n  _ref2Offset = ref2Offset;\n  _startIndex = startIndex;\n\n  _extractStatuses = extractStatuses;\n  _extractCallback = extractCallback;\n  _testMode = testMode;\n\n  _checkCrc = checkCrc;\n\n  _currentIndex = 0;\n  _fileIsOpen = false;\n  return WriteEmptyFiles();\n}\n\nHRESULT CFolderOutStream::OpenFile()\n{\n  Int32 askMode;\n  if((*_extractStatuses)[_currentIndex])\n    askMode = _testMode ?\n        NArchive::NExtract::NAskMode::kTest :\n        NArchive::NExtract::NAskMode::kExtract;\n  else\n    askMode = NArchive::NExtract::NAskMode::kSkip;\n  CMyComPtr<ISequentialOutStream> realOutStream;\n\n  UInt32 index = _startIndex + _currentIndex;\n  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));\n\n  _outStreamWithHashSpec->SetStream(realOutStream);\n  _outStreamWithHashSpec->Init(_checkCrc);\n  if (askMode == NArchive::NExtract::NAskMode::kExtract &&\n      (!realOutStream))\n  {\n    const CFileItem &fi = _archiveDatabase->Files[index];\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir)\n      askMode = NArchive::NExtract::NAskMode::kSkip;\n  }\n  return _extractCallback->PrepareOperation(askMode);\n}\n\nHRESULT CFolderOutStream::WriteEmptyFiles()\n{\n  for(;_currentIndex < _extractStatuses->Size(); _currentIndex++)\n  {\n    UInt32 index = _startIndex + _currentIndex;\n    const CFileItem &fi = _archiveDatabase->Files[index];\n    if (!_archiveDatabase->IsItemAnti(index) && !fi.IsDir && fi.Size != 0)\n      return S_OK;\n    RINOK(OpenFile());\n    RINOK(_extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\n    _outStreamWithHashSpec->ReleaseStream();\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP CFolderOutStream::Write(const void *data,\n    UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize = 0;\n  while(_currentIndex < _extractStatuses->Size())\n  {\n    if (_fileIsOpen)\n    {\n      UInt32 index = _startIndex + _currentIndex;\n      const CFileItem &fi = _archiveDatabase->Files[index];\n      UInt64 fileSize = fi.Size;\n      \n      UInt32 numBytesToWrite = (UInt32)MyMin(fileSize - _filePos,\n          UInt64(size - realProcessedSize));\n      \n      UInt32 processedSizeLocal;\n      RINOK(_outStreamWithHash->Write((const Byte *)data + realProcessedSize,\n            numBytesToWrite, &processedSizeLocal));\n\n      _filePos += processedSizeLocal;\n      realProcessedSize += processedSizeLocal;\n      if (_filePos == fileSize)\n      {\n        bool digestsAreEqual;\n        if (fi.CrcDefined && _checkCrc)\n          digestsAreEqual = fi.Crc == _outStreamWithHashSpec->GetCRC();\n        else\n          digestsAreEqual = true;\n\n        RINOK(_extractCallback->SetOperationResult(\n            digestsAreEqual ?\n            NArchive::NExtract::NOperationResult::kOK :\n            NArchive::NExtract::NOperationResult::kCRCError));\n        _outStreamWithHashSpec->ReleaseStream();\n        _fileIsOpen = false;\n        _currentIndex++;\n      }\n      if (realProcessedSize == size)\n      {\n        if (processedSize != NULL)\n          *processedSize = realProcessedSize;\n        return WriteEmptyFiles();\n      }\n    }\n    else\n    {\n      RINOK(OpenFile());\n      _fileIsOpen = true;\n      _filePos = 0;\n    }\n  }\n  if (processedSize != NULL)\n    *processedSize = size;\n  return S_OK;\n}\n\nHRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)\n{\n  while(_currentIndex < _extractStatuses->Size())\n  {\n    if (_fileIsOpen)\n    {\n      RINOK(_extractCallback->SetOperationResult(resultEOperationResult));\n      _outStreamWithHashSpec->ReleaseStream();\n      _fileIsOpen = false;\n      _currentIndex++;\n    }\n    else\n    {\n      RINOK(OpenFile());\n      _fileIsOpen = true;\n    }\n  }\n  return S_OK;\n}\n\nHRESULT CFolderOutStream::WasWritingFinished()\n{\n  if (_currentIndex == _extractStatuses->Size())\n    return S_OK;\n  return E_FAIL;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zFolderOutStream.h",
    "content": "// 7zFolderOutStream.h\n\n#ifndef __7Z_FOLDEROUTSTREAM_H\n#define __7Z_FOLDEROUTSTREAM_H\n\n#include \"7zIn.h\"\n\n#include \"../../IStream.h\"\n#include \"../IArchive.h\"\n#include \"../Common/OutStreamWithCRC.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nclass CFolderOutStream:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n  \n  CFolderOutStream();\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\nprivate:\n\n  COutStreamWithCRC *_outStreamWithHashSpec;\n  CMyComPtr<ISequentialOutStream> _outStreamWithHash;\n  const CArchiveDatabaseEx *_archiveDatabase;\n  const CBoolVector *_extractStatuses;\n  UInt32 _startIndex;\n  UInt32 _ref2Offset;\n  int _currentIndex;\n  // UInt64 _currentDataPos;\n  CMyComPtr<IArchiveExtractCallback> _extractCallback;\n  bool _testMode;\n\n  bool _fileIsOpen;\n\n  bool _checkCrc;\n  UInt64 _filePos;\n\n  HRESULT OpenFile();\n  HRESULT WriteEmptyFiles();\npublic:\n  HRESULT Init(\n      const CArchiveDatabaseEx *archiveDatabase,\n      UInt32 ref2Offset,\n      UInt32 startIndex,\n      const CBoolVector *extractStatuses,\n      IArchiveExtractCallback *extractCallback,\n      bool testMode,\n      bool checkCrc);\n  HRESULT FlushCorrupted(Int32 resultEOperationResult);\n  HRESULT WasWritingFinished();\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zHandler.cpp",
    "content": "// 7zHandler.cpp\n\n#include \"StdAfx.h\"\n\nextern \"C\"\n{\n  #include \"../../../../C/CpuArch.h\"\n}\n\n#include \"../../../Common/ComTry.h\"\n#include \"../../../Common/IntToString.h\"\n\n#ifdef COMPRESS_MT\n#include \"../../../Windows/System.h\"\n#endif\n\n#include \"../Common/ItemNameUtils.h\"\n\n#include \"7zHandler.h\"\n#include \"7zProperties.h\"\n\n#ifdef __7Z_SET_PROPERTIES\n#ifdef EXTRACT_ONLY\n#include \"../Common/ParseProperties.h\"\n#endif\n#endif\n\nusing namespace NWindows;\n\nextern UString ConvertMethodIdToString(UInt64 id);\n\nnamespace NArchive {\nnamespace N7z {\n\nCHandler::CHandler()\n{\n  _crcSize = 4;\n\n  #ifndef _NO_CRYPTO\n  _passwordIsDefined = false;\n  #endif\n\n  #ifdef EXTRACT_ONLY\n  #ifdef COMPRESS_MT\n  _numThreads = NSystem::GetNumberOfProcessors();\n  #endif\n  #else\n  Init();\n  #endif\n}\n\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\n{\n  *numItems = _db.Files.Size();\n  return S_OK;\n}\n\n#ifdef _SFX\n\nIMP_IInArchive_ArcProps_NO\n\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)\n{\n  return E_NOTIMPL;\n}\n\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,\n      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)\n{\n  return E_NOTIMPL;\n}\n\n\n#else\n\nSTATPROPSTG kArcProps[] =\n{\n  { NULL, kpidMethod, VT_BSTR},\n  { NULL, kpidSolid, VT_BOOL},\n  { NULL, kpidNumBlocks, VT_UI4},\n  { NULL, kpidPhySize, VT_UI8},\n  { NULL, kpidHeadersSize, VT_UI8},\n  { NULL, kpidOffset, VT_UI8}\n};\n\nSTDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)\n{\n  COM_TRY_BEGIN\n  NCOM::CPropVariant prop;\n  switch(propID)\n  {\n    case kpidMethod:\n    {\n      UString resString;\n      CRecordVector<UInt64> ids;\n      int i;\n      for (i = 0; i < _db.Folders.Size(); i++)\n      {\n        const CFolder &f = _db.Folders[i];\n        for (int j = f.Coders.Size() - 1; j >= 0; j--)\n          ids.AddToUniqueSorted(f.Coders[j].MethodID);\n      }\n\n      for (i = 0; i < ids.Size(); i++)\n      {\n        UInt64 id = ids[i];\n        UString methodName;\n        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);\n        if (methodName.IsEmpty())\n          methodName = ConvertMethodIdToString(id);\n        if (!resString.IsEmpty())\n          resString += L' ';\n        resString += methodName;\n      }\n      prop = resString;\n      break;\n    }\n    case kpidSolid: prop = _db.IsSolid(); break;\n    case kpidNumBlocks: prop = (UInt32)_db.Folders.Size(); break;\n    case kpidHeadersSize:  prop = _db.HeadersSize; break;\n    case kpidPhySize:  prop = _db.PhySize; break;\n    case kpidOffset: if (_db.ArchiveInfo.StartPosition != 0) prop = _db.ArchiveInfo.StartPosition; break;\n  }\n  prop.Detach(value);\n  return S_OK;\n  COM_TRY_END\n}\n\nIMP_IInArchive_ArcProps\n\n#endif\n\nstatic void SetPropFromUInt64Def(CUInt64DefVector &v, int index, NCOM::CPropVariant &prop)\n{\n  UInt64 value;\n  if (v.GetItem(index, value))\n  {\n    FILETIME ft;\n    ft.dwLowDateTime = (DWORD)value;\n    ft.dwHighDateTime = (DWORD)(value >> 32);\n    prop = ft;\n  }\n}\n\n#ifndef _SFX\n\nstatic UString ConvertUInt32ToString(UInt32 value)\n{\n  wchar_t buffer[32];\n  ConvertUInt64ToString(value, buffer);\n  return buffer;\n}\n\nstatic UString GetStringForSizeValue(UInt32 value)\n{\n  for (int i = 31; i >= 0; i--)\n    if ((UInt32(1) << i) == value)\n      return ConvertUInt32ToString(i);\n  UString result;\n  if (value % (1 << 20) == 0)\n  {\n    result += ConvertUInt32ToString(value >> 20);\n    result += L\"m\";\n  }\n  else if (value % (1 << 10) == 0)\n  {\n    result += ConvertUInt32ToString(value >> 10);\n    result += L\"k\";\n  }\n  else\n  {\n    result += ConvertUInt32ToString(value);\n    result += L\"b\";\n  }\n  return result;\n}\n\nstatic const UInt64 k_Copy = 0x0;\nstatic const UInt64 k_LZMA  = 0x030101;\nstatic const UInt64 k_PPMD  = 0x030401;\n\nstatic wchar_t GetHex(Byte value)\n{\n  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));\n}\nstatic inline UString GetHex2(Byte value)\n{\n  UString result;\n  result += GetHex((Byte)(value >> 4));\n  result += GetHex((Byte)(value & 0xF));\n  return result;\n}\n\n#endif\n\nstatic const UInt64 k_AES  = 0x06F10701;\n\nbool CHandler::IsEncrypted(UInt32 index2) const\n{\n  CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\n  if (folderIndex != kNumNoIndex)\n  {\n    const CFolder &folderInfo = _db.Folders[folderIndex];\n    for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\n      if (folderInfo.Coders[i].MethodID == k_AES)\n        return true;\n  }\n  return false;\n}\n\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\n{\n  COM_TRY_BEGIN\n  NCOM::CPropVariant prop;\n  \n  /*\n  const CRef2 &ref2 = _refs[index];\n  if (ref2.Refs.IsEmpty())\n    return E_FAIL;\n  const CRef &ref = ref2.Refs.Front();\n  */\n  \n  const CFileItem &item = _db.Files[index];\n  UInt32 index2 = index;\n\n  switch(propID)\n  {\n    case kpidPath:\n      if (!item.Name.IsEmpty())\n        prop = NItemName::GetOSName(item.Name);\n      break;\n    case kpidIsDir:  prop = item.IsDir; break;\n    case kpidSize:\n    {\n      prop = item.Size;\n      // prop = ref2.Size;\n      break;\n    }\n    case kpidPackSize:\n    {\n      // prop = ref2.PackSize;\n      {\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\n        if (folderIndex != kNumNoIndex)\n        {\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2)\n            prop = _db.GetFolderFullPackSize(folderIndex);\n          /*\n          else\n            prop = (UInt64)0;\n          */\n        }\n        else\n          prop = (UInt64)0;\n      }\n      break;\n    }\n    case kpidPosition:  { UInt64 v; if (_db.StartPos.GetItem(index2, v)) prop = v; break; }\n    case kpidCTime:  SetPropFromUInt64Def(_db.CTime, index2, prop); break;\n    case kpidATime:  SetPropFromUInt64Def(_db.ATime, index2, prop); break;\n    case kpidMTime:  SetPropFromUInt64Def(_db.MTime, index2, prop); break;\n    case kpidAttrib:  if (item.AttribDefined) prop = item.Attrib; break;\n    case kpidCRC:  if (item.CrcDefined) prop = item.Crc; break;\n    case kpidEncrypted:  prop = IsEncrypted(index2); break;\n    case kpidIsAnti:  prop = _db.IsItemAnti(index2); break;\n    #ifndef _SFX\n    case kpidMethod:\n      {\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\n        if (folderIndex != kNumNoIndex)\n        {\n          const CFolder &folderInfo = _db.Folders[folderIndex];\n          UString methodsString;\n          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)\n          {\n            const CCoderInfo &coderInfo = folderInfo.Coders[i];\n            if (!methodsString.IsEmpty())\n              methodsString += L' ';\n\n            {\n              UString methodName;\n              bool methodIsKnown = FindMethod(\n                  EXTERNAL_CODECS_VARS\n                  coderInfo.MethodID, methodName);\n\n              if (methodIsKnown)\n              {\n                methodsString += methodName;\n                if (coderInfo.MethodID == k_LZMA)\n                {\n                  if (coderInfo.Props.GetCapacity() >= 5)\n                  {\n                    methodsString += L\":\";\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\n                    methodsString += GetStringForSizeValue(dicSize);\n                  }\n                }\n                else if (coderInfo.MethodID == k_PPMD)\n                {\n                  if (coderInfo.Props.GetCapacity() >= 5)\n                  {\n                    Byte order = *(const Byte *)coderInfo.Props;\n                    methodsString += L\":o\";\n                    methodsString += ConvertUInt32ToString(order);\n                    methodsString += L\":mem\";\n                    UInt32 dicSize = GetUi32((const Byte *)coderInfo.Props + 1);\n                    methodsString += GetStringForSizeValue(dicSize);\n                  }\n                }\n                else if (coderInfo.MethodID == k_AES)\n                {\n                  if (coderInfo.Props.GetCapacity() >= 1)\n                  {\n                    methodsString += L\":\";\n                    const Byte *data = (const Byte *)coderInfo.Props;\n                    Byte firstByte = *data++;\n                    UInt32 numCyclesPower = firstByte & 0x3F;\n                    methodsString += ConvertUInt32ToString(numCyclesPower);\n                    /*\n                    if ((firstByte & 0xC0) != 0)\n                    {\n                      methodsString += L\":\";\n                      return S_OK;\n                      UInt32 saltSize = (firstByte >> 7) & 1;\n                      UInt32 ivSize = (firstByte >> 6) & 1;\n                      if (coderInfo.Props.GetCapacity() >= 2)\n                      {\n                        Byte secondByte = *data++;\n                        saltSize += (secondByte >> 4);\n                        ivSize += (secondByte & 0x0F);\n                      }\n                    }\n                    */\n                  }\n                }\n                else\n                {\n                  if (coderInfo.Props.GetCapacity() > 0)\n                  {\n                    methodsString += L\":[\";\n                    for (size_t bi = 0; bi < coderInfo.Props.GetCapacity(); bi++)\n                    {\n                      if (bi > 5 && bi + 1 < coderInfo.Props.GetCapacity())\n                      {\n                        methodsString += L\"..\";\n                        break;\n                      }\n                      else\n                        methodsString += GetHex2(coderInfo.Props[bi]);\n                    }\n                    methodsString += L\"]\";\n                  }\n                }\n              }\n              else\n              {\n                methodsString += ConvertMethodIdToString(coderInfo.MethodID);\n              }\n            }\n          }\n          prop = methodsString;\n        }\n      }\n      break;\n    case kpidBlock:\n      {\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\n        if (folderIndex != kNumNoIndex)\n          prop = (UInt32)folderIndex;\n      }\n      break;\n    case kpidPackedSize0:\n    case kpidPackedSize1:\n    case kpidPackedSize2:\n    case kpidPackedSize3:\n    case kpidPackedSize4:\n      {\n        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];\n        if (folderIndex != kNumNoIndex)\n        {\n          const CFolder &folderInfo = _db.Folders[folderIndex];\n          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 &&\n              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))\n          {\n            prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);\n          }\n          else\n            prop = (UInt64)0;\n        }\n        else\n          prop = (UInt64)0;\n      }\n      break;\n    #endif\n  }\n  prop.Detach(value);\n  return S_OK;\n  COM_TRY_END\n}\n\nSTDMETHODIMP CHandler::Open(IInStream *stream,\n    const UInt64 *maxCheckStartPosition,\n    IArchiveOpenCallback *openArchiveCallback)\n{\n  COM_TRY_BEGIN\n  Close();\n  #ifndef _SFX\n  _fileInfoPopIDs.Clear();\n  #endif\n  try\n  {\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;\n\n    #ifndef _NO_CRYPTO\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\n    if (openArchiveCallback)\n    {\n      openArchiveCallbackTemp.QueryInterface(\n          IID_ICryptoGetTextPassword, &getTextPassword);\n    }\n    #endif\n    CInArchive archive;\n    RINOK(archive.Open(stream, maxCheckStartPosition));\n    #ifndef _NO_CRYPTO\n    _passwordIsDefined = false;\n    UString password;\n    #endif\n    HRESULT result = archive.ReadDatabase(\n      EXTERNAL_CODECS_VARS\n      _db\n      #ifndef _NO_CRYPTO\n      , getTextPassword, _passwordIsDefined\n      #endif\n      );\n    RINOK(result);\n    _db.Fill();\n    _inStream = stream;\n  }\n  catch(...)\n  {\n    Close();\n    return S_FALSE;\n  }\n  // _inStream = stream;\n  #ifndef _SFX\n  FillPopIDs();\n  #endif\n  return S_OK;\n  COM_TRY_END\n}\n\nSTDMETHODIMP CHandler::Close()\n{\n  COM_TRY_BEGIN\n  _inStream.Release();\n  _db.Clear();\n  return S_OK;\n  COM_TRY_END\n}\n\n#ifdef __7Z_SET_PROPERTIES\n#ifdef EXTRACT_ONLY\n\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\n{\n  COM_TRY_BEGIN\n  #ifdef COMPRESS_MT\n  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();\n  _numThreads = numProcessors;\n  #endif\n\n  for (int i = 0; i < numProperties; i++)\n  {\n    UString name = names[i];\n    name.MakeUpper();\n    if (name.IsEmpty())\n      return E_INVALIDARG;\n    const PROPVARIANT &value = values[i];\n    UInt32 number;\n    int index = ParseStringToUInt32(name, number);\n    if (index == 0)\n    {\n      if(name.Left(2).CompareNoCase(L\"MT\") == 0)\n      {\n        #ifdef COMPRESS_MT\n        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\n        #endif\n        continue;\n      }\n      else\n        return E_INVALIDARG;\n    }\n  }\n  return S_OK;\n  COM_TRY_END\n}\n\n#endif\n#endif\n\nIMPL_ISetCompressCodecsInfo\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zHandler.h",
    "content": "// 7z/Handler.h\n\n#ifndef __7Z_HANDLER_H\n#define __7Z_HANDLER_H\n\n#include \"../../ICoder.h\"\n#include \"../IArchive.h\"\n#include \"7zIn.h\"\n\n#include \"7zCompressionMode.h\"\n\n#include \"../../Common/CreateCoder.h\"\n\n#ifndef EXTRACT_ONLY\n#include \"../Common/HandlerOut.h\"\n#endif\n\nnamespace NArchive {\nnamespace N7z {\n\n#ifndef __7Z_SET_PROPERTIES\n\n#ifdef EXTRACT_ONLY\n#ifdef COMPRESS_MT\n#define __7Z_SET_PROPERTIES\n#endif\n#else\n#define __7Z_SET_PROPERTIES\n#endif\n\n#endif\n\n\nclass CHandler:\n  #ifndef EXTRACT_ONLY\n  public NArchive::COutHandler,\n  #endif\n  public IInArchive,\n  #ifdef __7Z_SET_PROPERTIES\n  public ISetProperties,\n  #endif\n  #ifndef EXTRACT_ONLY\n  public IOutArchive,\n  #endif\n  PUBLIC_ISetCompressCodecsInfo\n  public CMyUnknownImp\n{\npublic:\n  MY_QUERYINTERFACE_BEGIN2(IInArchive)\n  #ifdef __7Z_SET_PROPERTIES\n  MY_QUERYINTERFACE_ENTRY(ISetProperties)\n  #endif\n  #ifndef EXTRACT_ONLY\n  MY_QUERYINTERFACE_ENTRY(IOutArchive)\n  #endif\n  QUERY_ENTRY_ISetCompressCodecsInfo\n  MY_QUERYINTERFACE_END\n  MY_ADDREF_RELEASE\n\n  INTERFACE_IInArchive(;)\n\n  #ifdef __7Z_SET_PROPERTIES\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);\n  #endif\n\n  #ifndef EXTRACT_ONLY\n  INTERFACE_IOutArchive(;)\n  #endif\n\n  DECL_ISetCompressCodecsInfo\n\n  CHandler();\n\nprivate:\n  CMyComPtr<IInStream> _inStream;\n  NArchive::N7z::CArchiveDatabaseEx _db;\n  #ifndef _NO_CRYPTO\n  bool _passwordIsDefined;\n  #endif\n\n  #ifdef EXTRACT_ONLY\n  \n  #ifdef COMPRESS_MT\n  UInt32 _numThreads;\n  #endif\n\n  UInt32 _crcSize;\n\n  #else\n  \n  CRecordVector<CBind> _binds;\n\n  HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);\n\n  HRESULT SetCompressionMethod(CCompressionMethodMode &method,\n      CObjectVector<COneMethodInfo> &methodsInfo\n      #ifdef COMPRESS_MT\n      , UInt32 numThreads\n      #endif\n      );\n\n  HRESULT SetCompressionMethod(\n      CCompressionMethodMode &method,\n      CCompressionMethodMode &headerMethod);\n\n  #endif\n\n  bool IsEncrypted(UInt32 index2) const;\n  #ifndef _SFX\n\n  CRecordVector<UInt64> _fileInfoPopIDs;\n  void FillPopIDs();\n\n  #endif\n\n  DECL_EXTERNAL_CODECS_VARS\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zHandlerOut.cpp",
    "content": "// 7zHandlerOut.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../../Windows/PropVariant.h\"\n\n#include \"../../../Common/ComTry.h\"\n#include \"../../../Common/StringToInt.h\"\n\n#include \"../../ICoder.h\"\n\n#include \"../Common/ItemNameUtils.h\"\n#include \"../Common/ParseProperties.h\"\n\n#include \"7zHandler.h\"\n#include \"7zOut.h\"\n#include \"7zUpdate.h\"\n\nusing namespace NWindows;\n\nnamespace NArchive {\nnamespace N7z {\n\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\nstatic const wchar_t *kCopyMethod = L\"Copy\";\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\n\nstatic const UInt32 kLzmaAlgorithmX5 = 1;\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\nstatic const UInt32 kNumFastBytesForHeaders = 273;\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5;\n\nstatic inline bool IsCopyMethod(const UString &methodName)\n  { return (methodName.CompareNoCase(kCopyMethod) == 0); }\n\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\n{\n  *type = NFileTimeType::kWindows;\n  return S_OK;\n}\n\nHRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode,\n    IArchiveUpdateCallback *updateCallback)\n{\n  CMyComPtr<ICryptoGetTextPassword2> getTextPassword;\n  if (!getTextPassword)\n  {\n    CMyComPtr<IArchiveUpdateCallback> udateCallback2(updateCallback);\n    udateCallback2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);\n  }\n  \n  if (getTextPassword)\n  {\n    CMyComBSTR password;\n    Int32 passwordIsDefined;\n    RINOK(getTextPassword->CryptoGetTextPassword2(\n        &passwordIsDefined, &password));\n    methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);\n    if (methodMode.PasswordIsDefined)\n      methodMode.Password = password;\n  }\n  else\n    methodMode.PasswordIsDefined = false;\n  return S_OK;\n}\n\nHRESULT CHandler::SetCompressionMethod(\n    CCompressionMethodMode &methodMode,\n    CCompressionMethodMode &headerMethod)\n{\n  HRESULT res = SetCompressionMethod(methodMode, _methods\n  #ifdef COMPRESS_MT\n  , _numThreads\n  #endif\n  );\n  RINOK(res);\n  methodMode.Binds = _binds;\n\n  if (_compressHeaders)\n  {\n    // headerMethod.Methods.Add(methodMode.Methods.Back());\n\n    CObjectVector<COneMethodInfo> headerMethodInfoVector;\n    COneMethodInfo oneMethodInfo;\n    oneMethodInfo.MethodName = kLZMAMethodName;\n    {\n      CProp prop;\n      prop.Id = NCoderPropID::kMatchFinder;\n      prop.Value = kLzmaMatchFinderForHeaders;\n      oneMethodInfo.Props.Add(prop);\n    }\n    {\n      CProp prop;\n      prop.Id = NCoderPropID::kAlgorithm;\n      prop.Value = kAlgorithmForHeaders;\n      oneMethodInfo.Props.Add(prop);\n    }\n    {\n      CProp prop;\n      prop.Id = NCoderPropID::kNumFastBytes;\n      prop.Value = (UInt32)kNumFastBytesForHeaders;\n      oneMethodInfo.Props.Add(prop);\n    }\n    {\n      CProp prop;\n      prop.Id = NCoderPropID::kDictionarySize;\n      prop.Value = (UInt32)kDictionaryForHeaders;\n      oneMethodInfo.Props.Add(prop);\n    }\n    headerMethodInfoVector.Add(oneMethodInfo);\n    HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector\n      #ifdef COMPRESS_MT\n      ,1\n      #endif\n    );\n    RINOK(res);\n  }\n  return S_OK;\n}\n\nHRESULT CHandler::SetCompressionMethod(\n    CCompressionMethodMode &methodMode,\n    CObjectVector<COneMethodInfo> &methodsInfo\n    #ifdef COMPRESS_MT\n    , UInt32 numThreads\n    #endif\n    )\n{\n  UInt32 level = _level;\n  \n  if (methodsInfo.IsEmpty())\n  {\n    COneMethodInfo oneMethodInfo;\n    oneMethodInfo.MethodName = ((level == 0) ? kCopyMethod : kDefaultMethodName);\n    methodsInfo.Add(oneMethodInfo);\n  }\n\n  bool needSolid = false;\n  for(int i = 0; i < methodsInfo.Size(); i++)\n  {\n    COneMethodInfo &oneMethodInfo = methodsInfo[i];\n    SetCompressionMethod2(oneMethodInfo\n      #ifdef COMPRESS_MT\n      , numThreads\n      #endif\n      );\n\n    if (!IsCopyMethod(oneMethodInfo.MethodName))\n      needSolid = true;\n\n    CMethodFull methodFull;\n\n    if (!FindMethod(\n        EXTERNAL_CODECS_VARS\n        oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams))\n      return E_INVALIDARG;\n    methodFull.Props = oneMethodInfo.Props;\n    methodMode.Methods.Add(methodFull);\n\n    if (!_numSolidBytesDefined)\n    {\n      for (int j = 0; j < methodFull.Props.Size(); j++)\n      {\n        const CProp &prop = methodFull.Props[j];\n        if ((prop.Id == NCoderPropID::kDictionarySize ||\n             prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4)\n        {\n          _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7;\n          const UInt64 kMinSize = (1 << 24);\n          if (_numSolidBytes < kMinSize)\n            _numSolidBytes = kMinSize;\n          _numSolidBytesDefined = true;\n          break;\n        }\n      }\n    }\n  }\n\n  if (!needSolid && !_numSolidBytesDefined)\n  {\n    _numSolidBytesDefined = true;\n    _numSolidBytes  = 0;\n  }\n  return S_OK;\n}\n\nstatic HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, bool writeTime, PROPID propID, UInt64 &ft, bool &ftDefined)\n{\n  ft = 0;\n  ftDefined = false;\n  if (!writeTime)\n    return S_OK;\n  NCOM::CPropVariant prop;\n  RINOK(updateCallback->GetProperty(index, propID, &prop));\n  if (prop.vt == VT_FILETIME)\n  {\n    ft = prop.filetime.dwLowDateTime | ((UInt64)prop.filetime.dwHighDateTime << 32);\n    ftDefined = true;\n  }\n  else if (prop.vt != VT_EMPTY)\n    return E_INVALIDARG;\n  return S_OK;\n}\n\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\n    IArchiveUpdateCallback *updateCallback)\n{\n  COM_TRY_BEGIN\n\n  const CArchiveDatabaseEx *db = 0;\n  #ifdef _7Z_VOL\n  if(_volumes.Size() > 1)\n    return E_FAIL;\n  const CVolume *volume = 0;\n  if (_volumes.Size() == 1)\n  {\n    volume = &_volumes.Front();\n    db = &volume->Database;\n  }\n  #else\n  if (_inStream != 0)\n    db = &_db;\n  #endif\n\n  CObjectVector<CUpdateItem> updateItems;\n  \n  for (UInt32 i = 0; i < numItems; i++)\n  {\n    Int32 newData;\n    Int32 newProperties;\n    UInt32 indexInArchive;\n    if (!updateCallback)\n      return E_FAIL;\n    RINOK(updateCallback->GetUpdateItemInfo(i, &newData, &newProperties, &indexInArchive));\n    CUpdateItem ui;\n    ui.NewProperties = IntToBool(newProperties);\n    ui.NewData = IntToBool(newData);\n    ui.IndexInArchive = indexInArchive;\n    ui.IndexInClient = i;\n    ui.IsAnti = false;\n    ui.Size = 0;\n\n    if (ui.IndexInArchive != -1)\n    {\n      const CFileItem &fi = db->Files[ui.IndexInArchive];\n      ui.Name = fi.Name;\n      ui.IsDir = fi.IsDir;\n      ui.Size = fi.Size;\n      ui.IsAnti = db->IsItemAnti(ui.IndexInArchive);\n      \n      ui.CTimeDefined = db->CTime.GetItem(ui.IndexInArchive, ui.CTime);\n      ui.ATimeDefined = db->ATime.GetItem(ui.IndexInArchive, ui.ATime);\n      ui.MTimeDefined = db->MTime.GetItem(ui.IndexInArchive, ui.MTime);\n    }\n\n    if (ui.NewProperties)\n    {\n      bool nameIsDefined;\n      bool folderStatusIsDefined;\n      {\n        NCOM::CPropVariant prop;\n        RINOK(updateCallback->GetProperty(i, kpidAttrib, &prop));\n        if (prop.vt == VT_EMPTY)\n          ui.AttribDefined = false;\n        else if (prop.vt != VT_UI4)\n          return E_INVALIDARG;\n        else\n        {\n          ui.Attrib = prop.ulVal;\n          ui.AttribDefined = true;\n        }\n      }\n      \n      // we need MTime to sort files.\n      RINOK(GetTime(updateCallback, i, WriteCTime, kpidCTime, ui.CTime, ui.CTimeDefined));\n      RINOK(GetTime(updateCallback, i, WriteATime, kpidATime, ui.ATime, ui.ATimeDefined));\n      RINOK(GetTime(updateCallback, i, true,       kpidMTime, ui.MTime, ui.MTimeDefined));\n\n      {\n        NCOM::CPropVariant prop;\n        RINOK(updateCallback->GetProperty(i, kpidPath, &prop));\n        if (prop.vt == VT_EMPTY)\n          nameIsDefined = false;\n        else if (prop.vt != VT_BSTR)\n          return E_INVALIDARG;\n        else\n        {\n          ui.Name = NItemName::MakeLegalName(prop.bstrVal);\n          nameIsDefined = true;\n        }\n      }\n      {\n        NCOM::CPropVariant prop;\n        RINOK(updateCallback->GetProperty(i, kpidIsDir, &prop));\n        if (prop.vt == VT_EMPTY)\n          folderStatusIsDefined = false;\n        else if (prop.vt != VT_BOOL)\n          return E_INVALIDARG;\n        else\n        {\n          ui.IsDir = (prop.boolVal != VARIANT_FALSE);\n          folderStatusIsDefined = true;\n        }\n      }\n\n      {\n        NCOM::CPropVariant prop;\n        RINOK(updateCallback->GetProperty(i, kpidIsAnti, &prop));\n        if (prop.vt == VT_EMPTY)\n          ui.IsAnti = false;\n        else if (prop.vt != VT_BOOL)\n          return E_INVALIDARG;\n        else\n          ui.IsAnti = (prop.boolVal != VARIANT_FALSE);\n      }\n\n      if (ui.IsAnti)\n      {\n        ui.AttribDefined = false;\n\n        ui.CTimeDefined = false;\n        ui.ATimeDefined = false;\n        ui.MTimeDefined = false;\n        \n        ui.Size = 0;\n      }\n\n      if (!folderStatusIsDefined && ui.AttribDefined)\n        ui.SetDirStatusFromAttrib();\n    }\n\n    if (ui.NewData)\n    {\n      NCOM::CPropVariant prop;\n      RINOK(updateCallback->GetProperty(i, kpidSize, &prop));\n      if (prop.vt != VT_UI8)\n        return E_INVALIDARG;\n      ui.Size = (UInt64)prop.uhVal.QuadPart;\n      if (ui.Size != 0 && ui.IsAnti)\n        return E_INVALIDARG;\n    }\n    updateItems.Add(ui);\n  }\n\n  CCompressionMethodMode methodMode, headerMethod;\n  RINOK(SetCompressionMethod(methodMode, headerMethod));\n  #ifdef COMPRESS_MT\n  methodMode.NumThreads = _numThreads;\n  headerMethod.NumThreads = 1;\n  #endif\n\n  RINOK(SetPassword(methodMode, updateCallback));\n\n  bool compressMainHeader = _compressHeaders;  // check it\n\n  bool encryptHeaders = false;\n\n  if (methodMode.PasswordIsDefined)\n  {\n    if (_encryptHeadersSpecified)\n      encryptHeaders = _encryptHeaders;\n    #ifndef _NO_CRYPTO\n    else\n      encryptHeaders = _passwordIsDefined;\n    #endif\n    compressMainHeader = true;\n    if(encryptHeaders)\n      RINOK(SetPassword(headerMethod, updateCallback));\n  }\n\n  if (numItems < 2)\n    compressMainHeader = false;\n\n  CUpdateOptions options;\n  options.Method = &methodMode;\n  options.HeaderMethod = (_compressHeaders || encryptHeaders) ? &headerMethod : 0;\n  options.UseFilters = _level != 0 && _autoFilter;\n  options.MaxFilter = _level >= 8;\n\n  options.HeaderOptions.CompressMainHeader = compressMainHeader;\n  options.HeaderOptions.WriteCTime = WriteCTime;\n  options.HeaderOptions.WriteATime = WriteATime;\n  options.HeaderOptions.WriteMTime = WriteMTime;\n  \n  options.NumSolidFiles = _numSolidFiles;\n  options.NumSolidBytes = _numSolidBytes;\n  options.SolidExtension = _solidExtension;\n  options.RemoveSfxBlock = _removeSfxBlock;\n  options.VolumeMode = _volumeMode;\n\n  COutArchive archive;\n  CArchiveDatabase newDatabase;\n  HRESULT res = Update(\n      EXTERNAL_CODECS_VARS\n      #ifdef _7Z_VOL\n      volume ? volume->Stream: 0,\n      volume ? db : 0,\n      #else\n      _inStream,\n      db,\n      #endif\n      updateItems,\n      archive, newDatabase, outStream, updateCallback, options);\n\n  RINOK(res);\n\n  updateItems.ClearAndFree();\n\n  return archive.WriteDatabase(EXTERNAL_CODECS_VARS\n      newDatabase, options.HeaderMethod, options.HeaderOptions);\n\n  COM_TRY_END\n}\n\nstatic HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)\n{\n  stream = 0;\n  int index = ParseStringToUInt32(srcString, coder);\n  if (index == 0)\n    return E_INVALIDARG;\n  srcString.Delete(0, index);\n  if (srcString[0] == 'S')\n  {\n    srcString.Delete(0);\n    int index = ParseStringToUInt32(srcString, stream);\n    if (index == 0)\n      return E_INVALIDARG;\n    srcString.Delete(0, index);\n  }\n  return S_OK;\n}\n\nstatic HRESULT GetBindInfo(UString &srcString, CBind &bind)\n{\n  RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream));\n  if (srcString[0] != ':')\n    return E_INVALIDARG;\n  srcString.Delete(0);\n  RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream));\n  if (!srcString.IsEmpty())\n    return E_INVALIDARG;\n  return S_OK;\n}\n\nSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)\n{\n  COM_TRY_BEGIN\n  _binds.Clear();\n  BeforeSetProperty();\n\n  for (int i = 0; i < numProperties; i++)\n  {\n    UString name = names[i];\n    name.MakeUpper();\n    if (name.IsEmpty())\n      return E_INVALIDARG;\n\n    const PROPVARIANT &value = values[i];\n\n    if (name[0] == 'B')\n    {\n      name.Delete(0);\n      CBind bind;\n      RINOK(GetBindInfo(name, bind));\n      _binds.Add(bind);\n      continue;\n    }\n\n    RINOK(SetProperty(name, value));\n  }\n\n  return S_OK;\n  COM_TRY_END\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zHeader.cpp",
    "content": "// 7z/Header.cpp\n\n#include \"StdAfx.h\"\n#include \"7zHeader.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nByte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C};\n#ifdef _7Z_VOL\nByte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};\n#endif\n\nclass SignatureInitializer\n{\npublic:\n  SignatureInitializer()\n  {\n    kSignature[0]--;\n    #ifdef _7Z_VOL\n    kFinishSignature[0]--;\n    #endif\n  };\n} g_SignatureInitializer;\n\n}}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zHeader.h",
    "content": "// 7z/7zHeader.h\n\n#ifndef __7Z_HEADER_H\n#define __7Z_HEADER_H\n\n#include \"../../../Common/Types.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nconst int kSignatureSize = 6;\nextern Byte kSignature[kSignatureSize];\n\n// #define _7Z_VOL\n// 7z-MultiVolume is not finished yet.\n// It can work already, but I still do not like some\n// things of that new multivolume format.\n// So please keep it commented.\n\n#ifdef _7Z_VOL\nextern Byte kFinishSignature[kSignatureSize];\n#endif\n\nstruct CArchiveVersion\n{\n  Byte Major;\n  Byte Minor;\n};\n\nconst Byte kMajorVersion = 0;\n\nstruct CStartHeader\n{\n  UInt64 NextHeaderOffset;\n  UInt64 NextHeaderSize;\n  UInt32 NextHeaderCRC;\n};\n\nconst UInt32 kStartHeaderSize = 20;\n\n#ifdef _7Z_VOL\nstruct CFinishHeader: public CStartHeader\n{\n  UInt64 ArchiveStartOffset;  // data offset from end if that struct\n  UInt64 AdditionalStartBlockSize; // start  signature & start header size\n};\n\nconst UInt32 kFinishHeaderSize = kStartHeaderSize + 16;\n#endif\n\nnamespace NID\n{\n  enum EEnum\n  {\n    kEnd,\n\n    kHeader,\n\n    kArchiveProperties,\n    \n    kAdditionalStreamsInfo,\n    kMainStreamsInfo,\n    kFilesInfo,\n    \n    kPackInfo,\n    kUnpackInfo,\n    kSubStreamsInfo,\n\n    kSize,\n    kCRC,\n\n    kFolder,\n\n    kCodersUnpackSize,\n    kNumUnpackStream,\n\n    kEmptyStream,\n    kEmptyFile,\n    kAnti,\n\n    kName,\n    kCTime,\n    kATime,\n    kMTime,\n    kWinAttributes,\n    kComment,\n\n    kEncodedHeader,\n\n    kStartPos,\n    kDummy\n  };\n}\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zIn.cpp",
    "content": "// 7zIn.cpp\n\n#include \"StdAfx.h\"\n\nextern \"C\"\n{\n  #include \"../../../../C/7zCrc.h\"\n  #include \"../../../../C/CpuArch.h\"\n}\n\n#include \"../../Common/StreamObjects.h\"\n#include \"../../Common/StreamUtils.h\"\n\n#include \"7zDecode.h\"\n#include \"7zIn.h\"\n\n#define Get16(p) GetUi16(p)\n#define Get32(p) GetUi32(p)\n#define Get64(p) GetUi64(p)\n\n// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader\n#ifndef _SFX\n#define FORMAT_7Z_RECOVERY\n#endif\n\nnamespace NArchive {\nnamespace N7z {\n\nstatic void BoolVector_Fill_False(CBoolVector &v, int size)\n{\n  v.Clear();\n  v.Reserve(size);\n  for (int i = 0; i < size; i++)\n    v.Add(false);\n}\n\nstatic bool BoolVector_GetAndSet(CBoolVector &v, UInt32 index)\n{\n  if (index >= (UInt32)v.Size())\n    return true;\n  bool res = v[index];\n  v[index] = true;\n  return res;\n}\n\nbool CFolder::CheckStructure() const\n{\n  const int kNumCodersMax = sizeof(UInt32) * 8; // don't change it\n  const int kMaskSize = sizeof(UInt32) * 8; // it must be >= kNumCodersMax\n  const int kNumBindsMax = 32;\n\n  if (Coders.Size() > kNumCodersMax || BindPairs.Size() > kNumBindsMax)\n    return false;\n\n  {\n    CBoolVector v;\n    BoolVector_Fill_False(v, BindPairs.Size() + PackStreams.Size());\n    \n    int i;\n    for (i = 0; i < BindPairs.Size(); i++)\n      if (BoolVector_GetAndSet(v, BindPairs[i].InIndex))\n        return false;\n    for (i = 0; i < PackStreams.Size(); i++)\n      if (BoolVector_GetAndSet(v, PackStreams[i]))\n        return false;\n    \n    BoolVector_Fill_False(v, UnpackSizes.Size());\n    for (i = 0; i < BindPairs.Size(); i++)\n      if (BoolVector_GetAndSet(v, BindPairs[i].OutIndex))\n        return false;\n  }\n  \n  UInt32 mask[kMaskSize];\n  int i;\n  for (i = 0; i < kMaskSize; i++)\n    mask[i] = 0;\n\n  {\n    CIntVector inStreamToCoder, outStreamToCoder;\n    for (i = 0; i < Coders.Size(); i++)\n    {\n      CNum j;\n      const CCoderInfo &coder = Coders[i];\n      for (j = 0; j < coder.NumInStreams; j++)\n        inStreamToCoder.Add(i);\n      for (j = 0; j < coder.NumOutStreams; j++)\n        outStreamToCoder.Add(i);\n    }\n    \n    for (i = 0; i < BindPairs.Size(); i++)\n    {\n      const CBindPair &bp = BindPairs[i];\n      mask[inStreamToCoder[bp.InIndex]] |= (1 << outStreamToCoder[bp.OutIndex]);\n    }\n  }\n  \n  for (i = 0; i < kMaskSize; i++)\n    for (int j = 0; j < kMaskSize; j++)\n      if (((1 << j) & mask[i]) != 0)\n        mask[i] |= mask[j];\n\n  for (i = 0; i < kMaskSize; i++)\n    if (((1 << i) & mask[i]) != 0)\n      return false;\n\n  return true;\n}\n\nclass CInArchiveException {};\n\nstatic void ThrowException() { throw CInArchiveException(); }\nstatic inline void ThrowEndOfData()   { ThrowException(); }\nstatic inline void ThrowUnsupported() { ThrowException(); }\nstatic inline void ThrowIncorrect()   { ThrowException(); }\nstatic inline void ThrowUnsupportedVersion() { ThrowException(); }\n\n/*\nclass CInArchiveException\n{\npublic:\n  enum CCauseType\n  {\n    kUnsupportedVersion = 0,\n    kUnsupported,\n    kIncorrect,\n    kEndOfData,\n  } Cause;\n  CInArchiveException(CCauseType cause): Cause(cause) {};\n};\n\nstatic void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }\nstatic void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }\nstatic void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }\nstatic void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }\nstatic void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }\n*/\n\nclass CStreamSwitch\n{\n  CInArchive *_archive;\n  bool _needRemove;\npublic:\n  CStreamSwitch(): _needRemove(false) {}\n  ~CStreamSwitch() { Remove(); }\n  void Remove();\n  void Set(CInArchive *archive, const Byte *data, size_t size);\n  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);\n  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);\n};\n\nvoid CStreamSwitch::Remove()\n{\n  if (_needRemove)\n  {\n    _archive->DeleteByteStream();\n    _needRemove = false;\n  }\n}\n\nvoid CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)\n{\n  Remove();\n  _archive = archive;\n  _archive->AddByteStream(data, size);\n  _needRemove = true;\n}\n\nvoid CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)\n{\n  Set(archive, byteBuffer, byteBuffer.GetCapacity());\n}\n\nvoid CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)\n{\n  Remove();\n  Byte external = archive->ReadByte();\n  if (external != 0)\n  {\n    int dataIndex = (int)archive->ReadNum();\n    if (dataIndex < 0 || dataIndex >= dataVector->Size())\n      ThrowIncorrect();\n    Set(archive, (*dataVector)[dataIndex]);\n  }\n}\n\nByte CInByte2::ReadByte()\n{\n  if (_pos >= _size)\n    ThrowEndOfData();\n  return _buffer[_pos++];\n}\n\nvoid CInByte2::ReadBytes(Byte *data, size_t size)\n{\n  if (size > _size - _pos)\n    ThrowEndOfData();\n  for (size_t i = 0; i < size; i++)\n    data[i] = _buffer[_pos++];\n}\n\nvoid CInByte2::SkeepData(UInt64 size)\n{\n  if (size > _size - _pos)\n    ThrowEndOfData();\n  _pos += (size_t)size;\n}\n\nvoid CInByte2::SkeepData()\n{\n  SkeepData(ReadNumber());\n}\n\nUInt64 CInByte2::ReadNumber()\n{\n  if (_pos >= _size)\n    ThrowEndOfData();\n  Byte firstByte = _buffer[_pos++];\n  Byte mask = 0x80;\n  UInt64 value = 0;\n  for (int i = 0; i < 8; i++)\n  {\n    if ((firstByte & mask) == 0)\n    {\n      UInt64 highPart = firstByte & (mask - 1);\n      value += (highPart << (i * 8));\n      return value;\n    }\n    if (_pos >= _size)\n      ThrowEndOfData();\n    value |= ((UInt64)_buffer[_pos++] << (8 * i));\n    mask >>= 1;\n  }\n  return value;\n}\n\nCNum CInByte2::ReadNum()\n{\n  UInt64 value = ReadNumber();\n  if (value > kNumMax)\n    ThrowUnsupported();\n  return (CNum)value;\n}\n\nUInt32 CInByte2::ReadUInt32()\n{\n  if (_pos + 4 > _size)\n    ThrowEndOfData();\n  UInt32 res = Get32(_buffer + _pos);\n  _pos += 4;\n  return res;\n}\n\nUInt64 CInByte2::ReadUInt64()\n{\n  if (_pos + 8 > _size)\n    ThrowEndOfData();\n  UInt64 res = Get64(_buffer + _pos);\n  _pos += 8;\n  return res;\n}\n\nvoid CInByte2::ReadString(UString &s)\n{\n  const Byte *buf = _buffer + _pos;\n  size_t rem = (_size - _pos) / 2 * 2;\n  {\n    size_t i;\n    for (i = 0; i < rem; i += 2)\n      if (buf[i] == 0 && buf[i + 1] == 0)\n        break;\n    if (i == rem)\n      ThrowEndOfData();\n    rem = i;\n  }\n  int len = (int)(rem / 2);\n  if (len < 0 || (size_t)len * 2 != rem)\n    ThrowUnsupported();\n  wchar_t *p = s.GetBuffer(len);\n  int i;\n  for (i = 0; i < len; i++, buf += 2)\n    p[i] = (wchar_t)Get16(buf);\n  s.ReleaseBuffer(len);\n  _pos += rem + 2;\n}\n\nstatic inline bool TestSignatureCandidate(const Byte *p)\n{\n  for (int i = 0; i < kSignatureSize; i++)\n    if (p[i] != kSignature[i])\n      return false;\n  return (p[0x1A] == 0 && p[0x1B] == 0);\n}\n\nHRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\n{\n  RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));\n\n  if (TestSignatureCandidate(_header))\n    return S_OK;\n\n  CByteBuffer byteBuffer;\n  const UInt32 kBufferSize = (1 << 16);\n  byteBuffer.SetCapacity(kBufferSize);\n  Byte *buffer = byteBuffer;\n  UInt32 numPrevBytes = kHeaderSize - 1;\n  memcpy(buffer, _header + 1, numPrevBytes);\n  UInt64 curTestPos = _arhiveBeginStreamPosition + 1;\n  for (;;)\n  {\n    if (searchHeaderSizeLimit != NULL)\n      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)\n        break;\n    do\n    {\n      UInt32 numReadBytes = kBufferSize - numPrevBytes;\n      UInt32 processedSize;\n      RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));\n      numPrevBytes += processedSize;\n      if (processedSize == 0)\n        return S_FALSE;\n    }\n    while (numPrevBytes < kHeaderSize);\n    UInt32 numTests = numPrevBytes - kHeaderSize + 1;\n    for (UInt32 pos = 0; pos < numTests; pos++)\n    {\n      for (; buffer[pos] != '7' && pos < numTests; pos++);\n      if (pos == numTests)\n        break;\n      if (TestSignatureCandidate(buffer + pos))\n      {\n        memcpy(_header, buffer + pos, kHeaderSize);\n        curTestPos += pos;\n        _arhiveBeginStreamPosition = curTestPos;\n        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);\n      }\n    }\n    curTestPos += numTests;\n    numPrevBytes -= numTests;\n    memmove(buffer, buffer + numTests, numPrevBytes);\n  }\n  return S_FALSE;\n}\n\n// S_FALSE means that file is not archive\nHRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)\n{\n  HeadersSize = 0;\n  Close();\n  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))\n  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));\n  _stream = stream;\n  return S_OK;\n}\n  \nvoid CInArchive::Close()\n{\n  _stream.Release();\n}\n\nvoid CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)\n{\n  for (;;)\n  {\n    if (ReadID() == NID::kEnd)\n      break;\n    SkeepData();\n  }\n}\n\nvoid CInArchive::GetNextFolderItem(CFolder &folder)\n{\n  CNum numCoders = ReadNum();\n\n  folder.Coders.Clear();\n  folder.Coders.Reserve((int)numCoders);\n  CNum numInStreams = 0;\n  CNum numOutStreams = 0;\n  CNum i;\n  for (i = 0; i < numCoders; i++)\n  {\n    folder.Coders.Add(CCoderInfo());\n    CCoderInfo &coder = folder.Coders.Back();\n\n    {\n      Byte mainByte = ReadByte();\n      int idSize = (mainByte & 0xF);\n      Byte longID[15];\n      ReadBytes(longID, idSize);\n      if (idSize > 8)\n        ThrowUnsupported();\n      UInt64 id = 0;\n      for (int j = 0; j < idSize; j++)\n        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);\n      coder.MethodID = id;\n\n      if ((mainByte & 0x10) != 0)\n      {\n        coder.NumInStreams = ReadNum();\n        coder.NumOutStreams = ReadNum();\n      }\n      else\n      {\n        coder.NumInStreams = 1;\n        coder.NumOutStreams = 1;\n      }\n      if ((mainByte & 0x20) != 0)\n      {\n        CNum propsSize = ReadNum();\n        coder.Props.SetCapacity((size_t)propsSize);\n        ReadBytes((Byte *)coder.Props, (size_t)propsSize);\n      }\n      if ((mainByte & 0x80) != 0)\n        ThrowUnsupported();\n    }\n    numInStreams += coder.NumInStreams;\n    numOutStreams += coder.NumOutStreams;\n  }\n\n  CNum numBindPairs = numOutStreams - 1;\n  folder.BindPairs.Clear();\n  folder.BindPairs.Reserve(numBindPairs);\n  for (i = 0; i < numBindPairs; i++)\n  {\n    CBindPair bp;\n    bp.InIndex = ReadNum();\n    bp.OutIndex = ReadNum();\n    folder.BindPairs.Add(bp);\n  }\n\n  if (numInStreams < numBindPairs)\n    ThrowUnsupported();\n  CNum numPackStreams = numInStreams - numBindPairs;\n  folder.PackStreams.Reserve(numPackStreams);\n  if (numPackStreams == 1)\n  {\n    for (i = 0; i < numInStreams; i++)\n      if (folder.FindBindPairForInStream(i) < 0)\n      {\n        folder.PackStreams.Add(i);\n        break;\n      }\n    if (folder.PackStreams.Size() != 1)\n      ThrowUnsupported();\n  }\n  else\n    for (i = 0; i < numPackStreams; i++)\n      folder.PackStreams.Add(ReadNum());\n}\n\nvoid CInArchive::WaitAttribute(UInt64 attribute)\n{\n  for (;;)\n  {\n    UInt64 type = ReadID();\n    if (type == attribute)\n      return;\n    if (type == NID::kEnd)\n      ThrowIncorrect();\n    SkeepData();\n  }\n}\n\nvoid CInArchive::ReadHashDigests(int numItems,\n    CBoolVector &digestsDefined,\n    CRecordVector<UInt32> &digests)\n{\n  ReadBoolVector2(numItems, digestsDefined);\n  digests.Clear();\n  digests.Reserve(numItems);\n  for (int i = 0; i < numItems; i++)\n  {\n    UInt32 crc = 0;\n    if (digestsDefined[i])\n      crc = ReadUInt32();\n    digests.Add(crc);\n  }\n}\n\nvoid CInArchive::ReadPackInfo(\n    UInt64 &dataOffset,\n    CRecordVector<UInt64> &packSizes,\n    CBoolVector &packCRCsDefined,\n    CRecordVector<UInt32> &packCRCs)\n{\n  dataOffset = ReadNumber();\n  CNum numPackStreams = ReadNum();\n\n  WaitAttribute(NID::kSize);\n  packSizes.Clear();\n  packSizes.Reserve(numPackStreams);\n  for (CNum i = 0; i < numPackStreams; i++)\n    packSizes.Add(ReadNumber());\n\n  UInt64 type;\n  for (;;)\n  {\n    type = ReadID();\n    if (type == NID::kEnd)\n      break;\n    if (type == NID::kCRC)\n    {\n      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs);\n      continue;\n    }\n    SkeepData();\n  }\n  if (packCRCsDefined.IsEmpty())\n  {\n    BoolVector_Fill_False(packCRCsDefined, numPackStreams);\n    packCRCs.Reserve(numPackStreams);\n    packCRCs.Clear();\n    for (CNum i = 0; i < numPackStreams; i++)\n      packCRCs.Add(0);\n  }\n}\n\nvoid CInArchive::ReadUnpackInfo(\n    const CObjectVector<CByteBuffer> *dataVector,\n    CObjectVector<CFolder> &folders)\n{\n  WaitAttribute(NID::kFolder);\n  CNum numFolders = ReadNum();\n\n  {\n    CStreamSwitch streamSwitch;\n    streamSwitch.Set(this, dataVector);\n    folders.Clear();\n    folders.Reserve(numFolders);\n    for (CNum i = 0; i < numFolders; i++)\n    {\n      folders.Add(CFolder());\n      GetNextFolderItem(folders.Back());\n    }\n  }\n\n  WaitAttribute(NID::kCodersUnpackSize);\n\n  CNum i;\n  for (i = 0; i < numFolders; i++)\n  {\n    CFolder &folder = folders[i];\n    CNum numOutStreams = folder.GetNumOutStreams();\n    folder.UnpackSizes.Reserve(numOutStreams);\n    for (CNum j = 0; j < numOutStreams; j++)\n      folder.UnpackSizes.Add(ReadNumber());\n  }\n\n  for (;;)\n  {\n    UInt64 type = ReadID();\n    if (type == NID::kEnd)\n      return;\n    if (type == NID::kCRC)\n    {\n      CBoolVector crcsDefined;\n      CRecordVector<UInt32> crcs;\n      ReadHashDigests(numFolders, crcsDefined, crcs);\n      for (i = 0; i < numFolders; i++)\n      {\n        CFolder &folder = folders[i];\n        folder.UnpackCRCDefined = crcsDefined[i];\n        folder.UnpackCRC = crcs[i];\n      }\n      continue;\n    }\n    SkeepData();\n  }\n}\n\nvoid CInArchive::ReadSubStreamsInfo(\n    const CObjectVector<CFolder> &folders,\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\n    CRecordVector<UInt64> &unpackSizes,\n    CBoolVector &digestsDefined,\n    CRecordVector<UInt32> &digests)\n{\n  numUnpackStreamsInFolders.Clear();\n  numUnpackStreamsInFolders.Reserve(folders.Size());\n  UInt64 type;\n  for (;;)\n  {\n    type = ReadID();\n    if (type == NID::kNumUnpackStream)\n    {\n      for (int i = 0; i < folders.Size(); i++)\n        numUnpackStreamsInFolders.Add(ReadNum());\n      continue;\n    }\n    if (type == NID::kCRC || type == NID::kSize)\n      break;\n    if (type == NID::kEnd)\n      break;\n    SkeepData();\n  }\n\n  if (numUnpackStreamsInFolders.IsEmpty())\n    for (int i = 0; i < folders.Size(); i++)\n      numUnpackStreamsInFolders.Add(1);\n\n  int i;\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\n  {\n    // v3.13 incorrectly worked with empty folders\n    // v4.07: we check that folder is empty\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\n    if (numSubstreams == 0)\n      continue;\n    UInt64 sum = 0;\n    for (CNum j = 1; j < numSubstreams; j++)\n      if (type == NID::kSize)\n      {\n        UInt64 size = ReadNumber();\n        unpackSizes.Add(size);\n        sum += size;\n      }\n    unpackSizes.Add(folders[i].GetUnpackSize() - sum);\n  }\n  if (type == NID::kSize)\n    type = ReadID();\n\n  int numDigests = 0;\n  int numDigestsTotal = 0;\n  for (i = 0; i < folders.Size(); i++)\n  {\n    CNum numSubstreams = numUnpackStreamsInFolders[i];\n    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)\n      numDigests += numSubstreams;\n    numDigestsTotal += numSubstreams;\n  }\n\n  for (;;)\n  {\n    if (type == NID::kCRC)\n    {\n      CBoolVector digestsDefined2;\n      CRecordVector<UInt32> digests2;\n      ReadHashDigests(numDigests, digestsDefined2, digests2);\n      int digestIndex = 0;\n      for (i = 0; i < folders.Size(); i++)\n      {\n        CNum numSubstreams = numUnpackStreamsInFolders[i];\n        const CFolder &folder = folders[i];\n        if (numSubstreams == 1 && folder.UnpackCRCDefined)\n        {\n          digestsDefined.Add(true);\n          digests.Add(folder.UnpackCRC);\n        }\n        else\n          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)\n          {\n            digestsDefined.Add(digestsDefined2[digestIndex]);\n            digests.Add(digests2[digestIndex]);\n          }\n      }\n    }\n    else if (type == NID::kEnd)\n    {\n      if (digestsDefined.IsEmpty())\n      {\n        BoolVector_Fill_False(digestsDefined, numDigestsTotal);\n        digests.Clear();\n        for (int i = 0; i < numDigestsTotal; i++)\n          digests.Add(0);\n      }\n      return;\n    }\n    else\n      SkeepData();\n    type = ReadID();\n  }\n}\n\nvoid CInArchive::ReadStreamsInfo(\n    const CObjectVector<CByteBuffer> *dataVector,\n    UInt64 &dataOffset,\n    CRecordVector<UInt64> &packSizes,\n    CBoolVector &packCRCsDefined,\n    CRecordVector<UInt32> &packCRCs,\n    CObjectVector<CFolder> &folders,\n    CRecordVector<CNum> &numUnpackStreamsInFolders,\n    CRecordVector<UInt64> &unpackSizes,\n    CBoolVector &digestsDefined,\n    CRecordVector<UInt32> &digests)\n{\n  for (;;)\n  {\n    UInt64 type = ReadID();\n    if (type > ((UInt32)1 << 30))\n      ThrowIncorrect();\n    switch((UInt32)type)\n    {\n      case NID::kEnd:\n        return;\n      case NID::kPackInfo:\n      {\n        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);\n        break;\n      }\n      case NID::kUnpackInfo:\n      {\n        ReadUnpackInfo(dataVector, folders);\n        break;\n      }\n      case NID::kSubStreamsInfo:\n      {\n        ReadSubStreamsInfo(folders, numUnpackStreamsInFolders,\n            unpackSizes, digestsDefined, digests);\n        break;\n      }\n      default:\n        ThrowIncorrect();\n    }\n  }\n}\n\nvoid CInArchive::ReadBoolVector(int numItems, CBoolVector &v)\n{\n  v.Clear();\n  v.Reserve(numItems);\n  Byte b = 0;\n  Byte mask = 0;\n  for (int i = 0; i < numItems; i++)\n  {\n    if (mask == 0)\n    {\n      b = ReadByte();\n      mask = 0x80;\n    }\n    v.Add((b & mask) != 0);\n    mask >>= 1;\n  }\n}\n\nvoid CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)\n{\n  Byte allAreDefined = ReadByte();\n  if (allAreDefined == 0)\n  {\n    ReadBoolVector(numItems, v);\n    return;\n  }\n  v.Clear();\n  v.Reserve(numItems);\n  for (int i = 0; i < numItems; i++)\n    v.Add(true);\n}\n\nvoid CInArchive::ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\n    CUInt64DefVector &v, int numFiles)\n{\n  ReadBoolVector2(numFiles, v.Defined);\n\n  CStreamSwitch streamSwitch;\n  streamSwitch.Set(this, &dataVector);\n  v.Values.Reserve(numFiles);\n\n  for (int i = 0; i < numFiles; i++)\n  {\n    UInt64 t = 0;\n    if (v.Defined[i])\n      t = ReadUInt64();\n    v.Values.Add(t);\n  }\n}\n\nHRESULT CInArchive::ReadAndDecodePackedStreams(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    UInt64 baseOffset,\n    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector\n    #ifndef _NO_CRYPTO\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\n    #endif\n    )\n{\n  CRecordVector<UInt64> packSizes;\n  CBoolVector packCRCsDefined;\n  CRecordVector<UInt32> packCRCs;\n  CObjectVector<CFolder> folders;\n  \n  CRecordVector<CNum> numUnpackStreamsInFolders;\n  CRecordVector<UInt64> unpackSizes;\n  CBoolVector digestsDefined;\n  CRecordVector<UInt32> digests;\n  \n  ReadStreamsInfo(NULL,\n    dataOffset,\n    packSizes,\n    packCRCsDefined,\n    packCRCs,\n    folders,\n    numUnpackStreamsInFolders,\n    unpackSizes,\n    digestsDefined,\n    digests);\n  \n  // db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\n  \n  CNum packIndex = 0;\n  CDecoder decoder(\n    #ifdef _ST_MODE\n    false\n    #else\n    true\n    #endif\n    );\n  UInt64 dataStartPos = baseOffset + dataOffset;\n  for (int i = 0; i < folders.Size(); i++)\n  {\n    const CFolder &folder = folders[i];\n    dataVector.Add(CByteBuffer());\n    CByteBuffer &data = dataVector.Back();\n    UInt64 unpackSize64 = folder.GetUnpackSize();\n    size_t unpackSize = (size_t)unpackSize64;\n    if (unpackSize != unpackSize64)\n      ThrowUnsupported();\n    data.SetCapacity(unpackSize);\n    \n    CSequentialOutStreamImp2 *outStreamSpec = new CSequentialOutStreamImp2;\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\n    outStreamSpec->Init(data, unpackSize);\n    \n    HRESULT result = decoder.Decode(\n      EXTERNAL_CODECS_LOC_VARS\n      _stream, dataStartPos,\n      &packSizes[packIndex], folder, outStream, NULL\n      #ifndef _NO_CRYPTO\n      , getTextPassword, passwordIsDefined\n      #endif\n      #ifdef COMPRESS_MT\n      , false, 1\n      #endif\n      );\n    RINOK(result);\n    \n    if (folder.UnpackCRCDefined)\n      if (CrcCalc(data, unpackSize) != folder.UnpackCRC)\n        ThrowIncorrect();\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\n    {\n      UInt64 packSize = packSizes[packIndex++];\n      dataStartPos += packSize;\n      HeadersSize += packSize;\n    }\n  }\n  return S_OK;\n}\n\nHRESULT CInArchive::ReadHeader(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    CArchiveDatabaseEx &db\n    #ifndef _NO_CRYPTO\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\n    #endif\n    )\n{\n  UInt64 type = ReadID();\n\n  if (type == NID::kArchiveProperties)\n  {\n    ReadArchiveProperties(db.ArchiveInfo);\n    type = ReadID();\n  }\n \n  CObjectVector<CByteBuffer> dataVector;\n  \n  if (type == NID::kAdditionalStreamsInfo)\n  {\n    HRESULT result = ReadAndDecodePackedStreams(\n        EXTERNAL_CODECS_LOC_VARS\n        db.ArchiveInfo.StartPositionAfterHeader,\n        db.ArchiveInfo.DataStartPosition2,\n        dataVector\n        #ifndef _NO_CRYPTO\n        , getTextPassword, passwordIsDefined\n        #endif\n        );\n    RINOK(result);\n    db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;\n    type = ReadID();\n  }\n\n  CRecordVector<UInt64> unpackSizes;\n  CBoolVector digestsDefined;\n  CRecordVector<UInt32> digests;\n  \n  if (type == NID::kMainStreamsInfo)\n  {\n    ReadStreamsInfo(&dataVector,\n        db.ArchiveInfo.DataStartPosition,\n        db.PackSizes,\n        db.PackCRCsDefined,\n        db.PackCRCs,\n        db.Folders,\n        db.NumUnpackStreamsVector,\n        unpackSizes,\n        digestsDefined,\n        digests);\n    db.ArchiveInfo.DataStartPosition += db.ArchiveInfo.StartPositionAfterHeader;\n    type = ReadID();\n  }\n  else\n  {\n    for (int i = 0; i < db.Folders.Size(); i++)\n    {\n      db.NumUnpackStreamsVector.Add(1);\n      CFolder &folder = db.Folders[i];\n      unpackSizes.Add(folder.GetUnpackSize());\n      digestsDefined.Add(folder.UnpackCRCDefined);\n      digests.Add(folder.UnpackCRC);\n    }\n  }\n\n  db.Files.Clear();\n\n  if (type == NID::kEnd)\n    return S_OK;\n  if (type != NID::kFilesInfo)\n    ThrowIncorrect();\n  \n  CNum numFiles = ReadNum();\n  db.Files.Reserve(numFiles);\n  CNum i;\n  for (i = 0; i < numFiles; i++)\n    db.Files.Add(CFileItem());\n\n  db.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);\n  if (!db.PackSizes.IsEmpty())\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);\n  if (numFiles > 0  && !digests.IsEmpty())\n    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);\n\n  CBoolVector emptyStreamVector;\n  BoolVector_Fill_False(emptyStreamVector, (int)numFiles);\n  CBoolVector emptyFileVector;\n  CBoolVector antiFileVector;\n  CNum numEmptyStreams = 0;\n\n  for (;;)\n  {\n    UInt64 type = ReadID();\n    if (type == NID::kEnd)\n      break;\n    UInt64 size = ReadNumber();\n    size_t ppp = _inByteBack->_pos;\n    bool addPropIdToList = true;\n    bool isKnownType = true;\n    if (type > ((UInt32)1 << 30))\n      isKnownType = false;\n    else switch((UInt32)type)\n    {\n      case NID::kName:\n      {\n        CStreamSwitch streamSwitch;\n        streamSwitch.Set(this, &dataVector);\n        for (int i = 0; i < db.Files.Size(); i++)\n          _inByteBack->ReadString(db.Files[i].Name);\n        break;\n      }\n      case NID::kWinAttributes:\n      {\n        CBoolVector boolVector;\n        ReadBoolVector2(db.Files.Size(), boolVector);\n        CStreamSwitch streamSwitch;\n        streamSwitch.Set(this, &dataVector);\n        for (i = 0; i < numFiles; i++)\n        {\n          CFileItem &file = db.Files[i];\n          file.AttribDefined = boolVector[i];\n          if (file.AttribDefined)\n            file.Attrib = ReadUInt32();\n        }\n        break;\n      }\n      case NID::kEmptyStream:\n      {\n        ReadBoolVector(numFiles, emptyStreamVector);\n        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)\n          if (emptyStreamVector[i])\n            numEmptyStreams++;\n\n        BoolVector_Fill_False(emptyFileVector, numEmptyStreams);\n        BoolVector_Fill_False(antiFileVector, numEmptyStreams);\n\n        break;\n      }\n      case NID::kEmptyFile:  ReadBoolVector(numEmptyStreams, emptyFileVector); break;\n      case NID::kAnti:  ReadBoolVector(numEmptyStreams, antiFileVector); break;\n      case NID::kStartPos:  ReadUInt64DefVector(dataVector, db.StartPos, (int)numFiles); break;\n      case NID::kCTime:  ReadUInt64DefVector(dataVector, db.CTime, (int)numFiles); break;\n      case NID::kATime:  ReadUInt64DefVector(dataVector, db.ATime, (int)numFiles); break;\n      case NID::kMTime:  ReadUInt64DefVector(dataVector, db.MTime, (int)numFiles); break;\n      case NID::kDummy:\n      {\n        for (UInt64 j = 0; j < size; j++)\n          if (ReadByte() != 0)\n            ThrowIncorrect();\n        addPropIdToList = false;\n        break;\n      }\n      default:\n        addPropIdToList = isKnownType = false;\n    }\n    if (isKnownType)\n    {\n      if(addPropIdToList)\n        db.ArchiveInfo.FileInfoPopIDs.Add(type);\n    }\n    else\n      SkeepData(size);\n    bool checkRecordsSize = (db.ArchiveInfo.Version.Major > 0 ||\n        db.ArchiveInfo.Version.Minor > 2);\n    if (checkRecordsSize && _inByteBack->_pos - ppp != size)\n      ThrowIncorrect();\n  }\n\n  CNum emptyFileIndex = 0;\n  CNum sizeIndex = 0;\n\n  CNum numAntiItems = 0;\n  for (i = 0; i < numEmptyStreams; i++)\n    if (antiFileVector[i])\n      numAntiItems++;\n    \n  for (i = 0; i < numFiles; i++)\n  {\n    CFileItem &file = db.Files[i];\n    bool isAnti;\n    file.HasStream = !emptyStreamVector[i];\n    if (file.HasStream)\n    {\n      file.IsDir = false;\n      isAnti = false;\n      file.Size = unpackSizes[sizeIndex];\n      file.Crc = digests[sizeIndex];\n      file.CrcDefined = digestsDefined[sizeIndex];\n      sizeIndex++;\n    }\n    else\n    {\n      file.IsDir = !emptyFileVector[emptyFileIndex];\n      isAnti = antiFileVector[emptyFileIndex];\n      emptyFileIndex++;\n      file.Size = 0;\n      file.CrcDefined = false;\n    }\n    if (numAntiItems != 0)\n      db.IsAnti.Add(isAnti);\n  }\n  return S_OK;\n}\n\n\nvoid CArchiveDatabaseEx::FillFolderStartPackStream()\n{\n  FolderStartPackStreamIndex.Clear();\n  FolderStartPackStreamIndex.Reserve(Folders.Size());\n  CNum startPos = 0;\n  for (int i = 0; i < Folders.Size(); i++)\n  {\n    FolderStartPackStreamIndex.Add(startPos);\n    startPos += (CNum)Folders[i].PackStreams.Size();\n  }\n}\n\nvoid CArchiveDatabaseEx::FillStartPos()\n{\n  PackStreamStartPositions.Clear();\n  PackStreamStartPositions.Reserve(PackSizes.Size());\n  UInt64 startPos = 0;\n  for (int i = 0; i < PackSizes.Size(); i++)\n  {\n    PackStreamStartPositions.Add(startPos);\n    startPos += PackSizes[i];\n  }\n}\n\nvoid CArchiveDatabaseEx::FillFolderStartFileIndex()\n{\n  FolderStartFileIndex.Clear();\n  FolderStartFileIndex.Reserve(Folders.Size());\n  FileIndexToFolderIndexMap.Clear();\n  FileIndexToFolderIndexMap.Reserve(Files.Size());\n  \n  int folderIndex = 0;\n  CNum indexInFolder = 0;\n  for (int i = 0; i < Files.Size(); i++)\n  {\n    const CFileItem &file = Files[i];\n    bool emptyStream = !file.HasStream;\n    if (emptyStream && indexInFolder == 0)\n    {\n      FileIndexToFolderIndexMap.Add(kNumNoIndex);\n      continue;\n    }\n    if (indexInFolder == 0)\n    {\n      // v3.13 incorrectly worked with empty folders\n      // v4.07: Loop for skipping empty folders\n      for (;;)\n      {\n        if (folderIndex >= Folders.Size())\n          ThrowIncorrect();\n        FolderStartFileIndex.Add(i); // check it\n        if (NumUnpackStreamsVector[folderIndex] != 0)\n          break;\n        folderIndex++;\n      }\n    }\n    FileIndexToFolderIndexMap.Add(folderIndex);\n    if (emptyStream)\n      continue;\n    indexInFolder++;\n    if (indexInFolder >= NumUnpackStreamsVector[folderIndex])\n    {\n      folderIndex++;\n      indexInFolder = 0;\n    }\n  }\n}\n\nHRESULT CInArchive::ReadDatabase2(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    CArchiveDatabaseEx &db\n    #ifndef _NO_CRYPTO\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\n    #endif\n    )\n{\n  db.Clear();\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\n\n  db.ArchiveInfo.Version.Major = _header[6];\n  db.ArchiveInfo.Version.Minor = _header[7];\n\n  if (db.ArchiveInfo.Version.Major != kMajorVersion)\n    ThrowUnsupportedVersion();\n\n  UInt32 crcFromArchive = Get32(_header + 8);\n  UInt64 nextHeaderOffset = Get64(_header + 0xC);\n  UInt64 nextHeaderSize = Get64(_header + 0x14);\n  UInt32 nextHeaderCRC = Get32(_header + 0x1C);\n  UInt32 crc = CrcCalc(_header + 0xC, 20);\n\n  #ifdef FORMAT_7Z_RECOVERY\n  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)\n  {\n    UInt64 cur, cur2;\n    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));\n    const int kCheckSize = 500;\n    Byte buf[kCheckSize];\n    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));\n    int checkSize = kCheckSize;\n    if (cur2 - cur < kCheckSize)\n      checkSize = (int)(cur2 - cur);\n    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));\n    \n    RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));\n\n    int i;\n    for (i = (int)checkSize - 2; i >= 0; i--)\n      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)\n        break;\n    if (i < 0)\n      return S_FALSE;\n    nextHeaderSize = checkSize - i;\n    nextHeaderOffset = cur2 - cur + i;\n    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);\n    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));\n  }\n  #endif\n\n  #ifdef FORMAT_7Z_RECOVERY\n  crcFromArchive = crc;\n  #endif\n\n  db.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;\n\n  if (crc != crcFromArchive)\n    ThrowIncorrect();\n\n  if (nextHeaderSize == 0)\n    return S_OK;\n\n  if (nextHeaderSize > (UInt64)0xFFFFFFFF)\n    return S_FALSE;\n\n  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));\n\n  CByteBuffer buffer2;\n  buffer2.SetCapacity((size_t)nextHeaderSize);\n\n  RINOK(ReadStream_FALSE(_stream, buffer2, (size_t)nextHeaderSize));\n  HeadersSize += kHeaderSize + nextHeaderSize;\n  db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;\n\n  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)\n    ThrowIncorrect();\n  \n  CStreamSwitch streamSwitch;\n  streamSwitch.Set(this, buffer2);\n  \n  CObjectVector<CByteBuffer> dataVector;\n  \n  UInt64 type = ReadID();\n  if (type != NID::kHeader)\n  {\n    if (type != NID::kEncodedHeader)\n      ThrowIncorrect();\n    HRESULT result = ReadAndDecodePackedStreams(\n        EXTERNAL_CODECS_LOC_VARS\n        db.ArchiveInfo.StartPositionAfterHeader,\n        db.ArchiveInfo.DataStartPosition2,\n        dataVector\n        #ifndef _NO_CRYPTO\n        , getTextPassword, passwordIsDefined\n        #endif\n        );\n    RINOK(result);\n    if (dataVector.Size() == 0)\n      return S_OK;\n    if (dataVector.Size() > 1)\n      ThrowIncorrect();\n    streamSwitch.Remove();\n    streamSwitch.Set(this, dataVector.Front());\n    if (ReadID() != NID::kHeader)\n      ThrowIncorrect();\n  }\n\n  db.HeadersSize = HeadersSize;\n\n  return ReadHeader(\n    EXTERNAL_CODECS_LOC_VARS\n    db\n    #ifndef _NO_CRYPTO\n    , getTextPassword, passwordIsDefined\n    #endif\n    );\n}\n\nHRESULT CInArchive::ReadDatabase(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    CArchiveDatabaseEx &db\n    #ifndef _NO_CRYPTO\n    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\n    #endif\n    )\n{\n  try\n  {\n    return ReadDatabase2(\n      EXTERNAL_CODECS_LOC_VARS db\n      #ifndef _NO_CRYPTO\n      , getTextPassword, passwordIsDefined\n      #endif\n      );\n  }\n  catch(CInArchiveException &) { return S_FALSE; }\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zIn.h",
    "content": "// 7zIn.h\n\n#ifndef __7Z_IN_H\n#define __7Z_IN_H\n\n#include \"../../../Common/MyCom.h\"\n\n#include \"../../IPassword.h\"\n#include \"../../IStream.h\"\n\n#include \"../../Common/CreateCoder.h\"\n#include \"../../Common/InBuffer.h\"\n\n#include \"7zItem.h\"\n \nnamespace NArchive {\nnamespace N7z {\n  \nstruct CInArchiveInfo\n{\n  CArchiveVersion Version;\n  UInt64 StartPosition;\n  UInt64 StartPositionAfterHeader;\n  UInt64 DataStartPosition;\n  UInt64 DataStartPosition2;\n  CRecordVector<UInt64> FileInfoPopIDs;\n  void Clear()\n  {\n    FileInfoPopIDs.Clear();\n  }\n};\n\nstruct CArchiveDatabaseEx: public CArchiveDatabase\n{\n  CInArchiveInfo ArchiveInfo;\n  CRecordVector<UInt64> PackStreamStartPositions;\n  CRecordVector<CNum> FolderStartPackStreamIndex;\n  CRecordVector<CNum> FolderStartFileIndex;\n  CRecordVector<CNum> FileIndexToFolderIndexMap;\n\n  UInt64 HeadersSize;\n  UInt64 PhySize;\n\n  void Clear()\n  {\n    CArchiveDatabase::Clear();\n    ArchiveInfo.Clear();\n    PackStreamStartPositions.Clear();\n    FolderStartPackStreamIndex.Clear();\n    FolderStartFileIndex.Clear();\n    FileIndexToFolderIndexMap.Clear();\n\n    HeadersSize = 0;\n    PhySize = 0;\n  }\n\n  void FillFolderStartPackStream();\n  void FillStartPos();\n  void FillFolderStartFileIndex();\n\n  void Fill()\n  {\n    FillFolderStartPackStream();\n    FillStartPos();\n    FillFolderStartFileIndex();\n  }\n  \n  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const\n  {\n    return ArchiveInfo.DataStartPosition +\n        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];\n  }\n  \n  UInt64 GetFolderFullPackSize(int folderIndex) const\n  {\n    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];\n    const CFolder &folder = Folders[folderIndex];\n    UInt64 size = 0;\n    for (int i = 0; i < folder.PackStreams.Size(); i++)\n      size += PackSizes[packStreamIndex + i];\n    return size;\n  }\n  \n  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const\n  {\n    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\n  }\n\n  UInt64 GetFilePackSize(CNum fileIndex) const\n  {\n    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];\n    if (folderIndex != kNumNoIndex)\n      if (FolderStartFileIndex[folderIndex] == fileIndex)\n        return GetFolderFullPackSize(folderIndex);\n    return 0;\n  }\n};\n\nclass CInByte2\n{\n  const Byte *_buffer;\n  size_t _size;\npublic:\n  size_t _pos;\n  void Init(const Byte *buffer, size_t size)\n  {\n    _buffer = buffer;\n    _size = size;\n    _pos = 0;\n  }\n  Byte ReadByte();\n  void ReadBytes(Byte *data, size_t size);\n  void SkeepData(UInt64 size);\n  void SkeepData();\n  UInt64 ReadNumber();\n  CNum ReadNum();\n  UInt32 ReadUInt32();\n  UInt64 ReadUInt64();\n  void ReadString(UString &s);\n};\n\nclass CStreamSwitch;\n\nconst UInt32 kHeaderSize = 32;\n\nclass CInArchive\n{\n  friend class CStreamSwitch;\n\n  CMyComPtr<IInStream> _stream;\n\n  CObjectVector<CInByte2> _inByteVector;\n  CInByte2 *_inByteBack;\n \n  UInt64 _arhiveBeginStreamPosition;\n\n  Byte _header[kHeaderSize];\n\n  UInt64 HeadersSize;\n\n  void AddByteStream(const Byte *buffer, size_t size)\n  {\n    _inByteVector.Add(CInByte2());\n    _inByteBack = &_inByteVector.Back();\n    _inByteBack->Init(buffer, size);\n  }\n  \n  void DeleteByteStream()\n  {\n    _inByteVector.DeleteBack();\n    if (!_inByteVector.IsEmpty())\n      _inByteBack = &_inByteVector.Back();\n  }\n\nprivate:\n  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);\n  \n  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }\n  Byte ReadByte() { return _inByteBack->ReadByte(); }\n  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }\n  CNum ReadNum() { return _inByteBack->ReadNum(); }\n  UInt64 ReadID() { return _inByteBack->ReadNumber(); }\n  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }\n  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }\n  void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }\n  void SkeepData() { _inByteBack->SkeepData(); }\n  void WaitAttribute(UInt64 attribute);\n\n  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);\n  void GetNextFolderItem(CFolder &itemInfo);\n  void ReadHashDigests(int numItems,\n      CBoolVector &digestsDefined, CRecordVector<UInt32> &digests);\n  \n  void ReadPackInfo(\n      UInt64 &dataOffset,\n      CRecordVector<UInt64> &packSizes,\n      CBoolVector &packCRCsDefined,\n      CRecordVector<UInt32> &packCRCs);\n  \n  void ReadUnpackInfo(\n      const CObjectVector<CByteBuffer> *dataVector,\n      CObjectVector<CFolder> &folders);\n  \n  void ReadSubStreamsInfo(\n      const CObjectVector<CFolder> &folders,\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\n      CRecordVector<UInt64> &unpackSizes,\n      CBoolVector &digestsDefined,\n      CRecordVector<UInt32> &digests);\n\n  void ReadStreamsInfo(\n      const CObjectVector<CByteBuffer> *dataVector,\n      UInt64 &dataOffset,\n      CRecordVector<UInt64> &packSizes,\n      CBoolVector &packCRCsDefined,\n      CRecordVector<UInt32> &packCRCs,\n      CObjectVector<CFolder> &folders,\n      CRecordVector<CNum> &numUnpackStreamsInFolders,\n      CRecordVector<UInt64> &unpackSizes,\n      CBoolVector &digestsDefined,\n      CRecordVector<UInt32> &digests);\n\n\n  void ReadBoolVector(int numItems, CBoolVector &v);\n  void ReadBoolVector2(int numItems, CBoolVector &v);\n  void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,\n      CUInt64DefVector &v, int numFiles);\n  HRESULT ReadAndDecodePackedStreams(\n      DECL_EXTERNAL_CODECS_LOC_VARS\n      UInt64 baseOffset, UInt64 &dataOffset,\n      CObjectVector<CByteBuffer> &dataVector\n      #ifndef _NO_CRYPTO\n      , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\n      #endif\n      );\n  HRESULT ReadHeader(\n      DECL_EXTERNAL_CODECS_LOC_VARS\n      CArchiveDatabaseEx &db\n      #ifndef _NO_CRYPTO\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\n      #endif\n      );\n  HRESULT ReadDatabase2(\n      DECL_EXTERNAL_CODECS_LOC_VARS\n      CArchiveDatabaseEx &db\n      #ifndef _NO_CRYPTO\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\n      #endif\n      );\npublic:\n  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive\n  void Close();\n\n  HRESULT ReadDatabase(\n      DECL_EXTERNAL_CODECS_LOC_VARS\n      CArchiveDatabaseEx &db\n      #ifndef _NO_CRYPTO\n      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined\n      #endif\n      );\n};\n  \n}}\n  \n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zItem.h",
    "content": "// 7zItem.h\n\n#ifndef __7Z_ITEM_H\n#define __7Z_ITEM_H\n\n#include \"../../../Common/Buffer.h\"\n#include \"../../../Common/MyString.h\"\n\n#include \"../../Common/MethodId.h\"\n\n#include \"7zHeader.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\ntypedef UInt32 CNum;\nconst CNum kNumMax     = 0x7FFFFFFF;\nconst CNum kNumNoIndex = 0xFFFFFFFF;\n\nstruct CCoderInfo\n{\n  CMethodId MethodID;\n  CByteBuffer Props;\n  CNum NumInStreams;\n  CNum NumOutStreams;\n  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }\n};\n\nstruct CBindPair\n{\n  CNum InIndex;\n  CNum OutIndex;\n};\n\nstruct CFolder\n{\n  CObjectVector<CCoderInfo> Coders;\n  CRecordVector<CBindPair> BindPairs;\n  CRecordVector<CNum> PackStreams;\n  CRecordVector<UInt64> UnpackSizes;\n  UInt32 UnpackCRC;\n  bool UnpackCRCDefined;\n\n  CFolder(): UnpackCRCDefined(false) {}\n\n  UInt64 GetUnpackSize() const // test it\n  {\n    if (UnpackSizes.IsEmpty())\n      return 0;\n    for (int i = UnpackSizes.Size() - 1; i >= 0; i--)\n      if (FindBindPairForOutStream(i) < 0)\n        return UnpackSizes[i];\n    throw 1;\n  }\n\n  CNum GetNumOutStreams() const\n  {\n    CNum result = 0;\n    for (int i = 0; i < Coders.Size(); i++)\n      result += Coders[i].NumOutStreams;\n    return result;\n  }\n\n  int FindBindPairForInStream(CNum inStreamIndex) const\n  {\n    for(int i = 0; i < BindPairs.Size(); i++)\n      if (BindPairs[i].InIndex == inStreamIndex)\n        return i;\n    return -1;\n  }\n  int FindBindPairForOutStream(CNum outStreamIndex) const\n  {\n    for(int i = 0; i < BindPairs.Size(); i++)\n      if (BindPairs[i].OutIndex == outStreamIndex)\n        return i;\n    return -1;\n  }\n  int FindPackStreamArrayIndex(CNum inStreamIndex) const\n  {\n    for(int i = 0; i < PackStreams.Size(); i++)\n      if (PackStreams[i] == inStreamIndex)\n        return i;\n    return -1;\n  }\n\n  bool CheckStructure() const;\n};\n\nstruct CUInt64DefVector\n{\n  CRecordVector<UInt64> Values;\n  CRecordVector<bool> Defined;\n  \n  void Clear()\n  {\n    Values.Clear();\n    Defined.Clear();\n  }\n  \n  void ReserveDown()\n  {\n    Values.ReserveDown();\n    Values.ReserveDown();\n  }\n\n  bool GetItem(int index, UInt64 &value) const\n  {\n    if (index < Defined.Size() && Defined[index])\n    {\n      value = Values[index];\n      return true;\n    }\n    value = 0;\n    return false;\n  }\n  \n  void SetItem(int index, bool defined, UInt64 value)\n  {\n    while (index >= Defined.Size())\n      Defined.Add(false);\n    Defined[index] = defined;\n    if (!defined)\n      return;\n    while (index >= Values.Size())\n      Values.Add(0);\n    Values[index] = value;\n  }\n\n  bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }\n};\n\nstruct CFileItem\n{\n  UInt64 Size;\n  UInt32 Attrib;\n  UInt32 Crc;\n  UString Name;\n\n  bool HasStream; // Test it !!! it means that there is\n                  // stream in some folder. It can be empty stream\n  bool IsDir;\n  bool CrcDefined;\n  bool AttribDefined;\n\n  CFileItem():\n    HasStream(true),\n    IsDir(false),\n    CrcDefined(false),\n    AttribDefined(false)\n      {}\n  void SetAttrib(UInt32 attrib)\n  {\n    AttribDefined = true;\n    Attrib = attrib;\n  }\n};\n\nstruct CFileItem2\n{\n  UInt64 CTime;\n  UInt64 ATime;\n  UInt64 MTime;\n  UInt64 StartPos;\n  bool CTimeDefined;\n  bool ATimeDefined;\n  bool MTimeDefined;\n  bool StartPosDefined;\n  bool IsAnti;\n};\n\nstruct CArchiveDatabase\n{\n  CRecordVector<UInt64> PackSizes;\n  CRecordVector<bool> PackCRCsDefined;\n  CRecordVector<UInt32> PackCRCs;\n  CObjectVector<CFolder> Folders;\n  CRecordVector<CNum> NumUnpackStreamsVector;\n  CObjectVector<CFileItem> Files;\n\n  CUInt64DefVector CTime;\n  CUInt64DefVector ATime;\n  CUInt64DefVector MTime;\n  CUInt64DefVector StartPos;\n  CRecordVector<bool> IsAnti;\n\n  void Clear()\n  {\n    PackSizes.Clear();\n    PackCRCsDefined.Clear();\n    PackCRCs.Clear();\n    Folders.Clear();\n    NumUnpackStreamsVector.Clear();\n    Files.Clear();\n    CTime.Clear();\n    ATime.Clear();\n    MTime.Clear();\n    StartPos.Clear();\n    IsAnti.Clear();\n  }\n\n  void ReserveDown()\n  {\n    PackSizes.ReserveDown();\n    PackCRCsDefined.ReserveDown();\n    PackCRCs.ReserveDown();\n    Folders.ReserveDown();\n    NumUnpackStreamsVector.ReserveDown();\n    Files.ReserveDown();\n    CTime.ReserveDown();\n    ATime.ReserveDown();\n    MTime.ReserveDown();\n    StartPos.ReserveDown();\n    IsAnti.ReserveDown();\n  }\n\n  bool IsEmpty() const\n  {\n    return (PackSizes.IsEmpty() &&\n      PackCRCsDefined.IsEmpty() &&\n      PackCRCs.IsEmpty() &&\n      Folders.IsEmpty() &&\n      NumUnpackStreamsVector.IsEmpty() &&\n      Files.IsEmpty());\n  }\n\n  bool CheckNumFiles() const\n  {\n    int size = Files.Size();\n    return (\n      CTime.CheckSize(size) &&\n      ATime.CheckSize(size) &&\n      MTime.CheckSize(size) &&\n      StartPos.CheckSize(size) &&\n      (size == IsAnti.Size() || IsAnti.Size() == 0));\n  }\n\n  bool IsSolid() const\n  {\n    for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)\n      if (NumUnpackStreamsVector[i] > 1)\n        return true;\n    return false;\n  }\n  bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }\n  void SetItemAnti(int index, bool isAnti)\n  {\n    while (index >= IsAnti.Size())\n      IsAnti.Add(false);\n    IsAnti[index] = isAnti;\n  }\n\n  void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;\n  void AddFile(const CFileItem &file, const CFileItem2 &file2);\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zOut.cpp",
    "content": "// 7zOut.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../../Common/AutoPtr.h\"\n#include \"../../Common/StreamObjects.h\"\n\n#include \"7zOut.h\"\n\nextern \"C\"\n{\n#include \"../../../../C/7zCrc.h\"\n}\n\nstatic HRESULT WriteBytes(ISequentialOutStream *stream, const void *data, size_t size)\n{\n  while (size > 0)\n  {\n    UInt32 curSize = (UInt32)MyMin(size, (size_t)0xFFFFFFFF);\n    UInt32 processedSize;\n    RINOK(stream->Write(data, curSize, &processedSize));\n    if (processedSize == 0)\n      return E_FAIL;\n    data = (const void *)((const Byte *)data + processedSize);\n    size -= processedSize;\n  }\n  return S_OK;\n}\n\nnamespace NArchive {\nnamespace N7z {\n\nHRESULT COutArchive::WriteDirect(const void *data, UInt32 size)\n{\n  return ::WriteBytes(SeqStream, data, size);\n}\n\nHRESULT COutArchive::WriteSignature()\n{\n  Byte buf[8];\n  memcpy(buf, kSignature, kSignatureSize);\n  buf[kSignatureSize] = kMajorVersion;\n  buf[kSignatureSize + 1] = 3;\n  return WriteDirect(buf, 8);\n}\n\n#ifdef _7Z_VOL\nHRESULT COutArchive::WriteFinishSignature()\n{\n  RINOK(WriteDirect(kFinishSignature, kSignatureSize));\n  CArchiveVersion av;\n  av.Major = kMajorVersion;\n  av.Minor = 2;\n  RINOK(WriteDirectByte(av.Major));\n  return WriteDirectByte(av.Minor);\n}\n#endif\n\nstatic void SetUInt32(Byte *p, UInt32 d)\n{\n  for (int i = 0; i < 4; i++, d >>= 8)\n    p[i] = (Byte)d;\n}\n\nstatic void SetUInt64(Byte *p, UInt64 d)\n{\n  for (int i = 0; i < 8; i++, d >>= 8)\n    p[i] = (Byte)d;\n}\n\nHRESULT COutArchive::WriteStartHeader(const CStartHeader &h)\n{\n  Byte buf[24];\n  SetUInt64(buf + 4, h.NextHeaderOffset);\n  SetUInt64(buf + 12, h.NextHeaderSize);\n  SetUInt32(buf + 20, h.NextHeaderCRC);\n  SetUInt32(buf, CrcCalc(buf + 4, 20));\n  return WriteDirect(buf, 24);\n}\n\n#ifdef _7Z_VOL\nHRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)\n{\n  CCRC crc;\n  crc.UpdateUInt64(h.NextHeaderOffset);\n  crc.UpdateUInt64(h.NextHeaderSize);\n  crc.UpdateUInt32(h.NextHeaderCRC);\n  crc.UpdateUInt64(h.ArchiveStartOffset);\n  crc.UpdateUInt64(h.AdditionalStartBlockSize);\n  RINOK(WriteDirectUInt32(crc.GetDigest()));\n  RINOK(WriteDirectUInt64(h.NextHeaderOffset));\n  RINOK(WriteDirectUInt64(h.NextHeaderSize));\n  RINOK(WriteDirectUInt32(h.NextHeaderCRC));\n  RINOK(WriteDirectUInt64(h.ArchiveStartOffset));\n  return WriteDirectUInt64(h.AdditionalStartBlockSize);\n}\n#endif\n\nHRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)\n{\n  Close();\n  #ifdef _7Z_VOL\n  // endMarker = false;\n  _endMarker = endMarker;\n  #endif\n  SeqStream = stream;\n  if (!endMarker)\n  {\n    SeqStream.QueryInterface(IID_IOutStream, &Stream);\n    if (!Stream)\n    {\n      return E_NOTIMPL;\n      // endMarker = true;\n    }\n  }\n  #ifdef _7Z_VOL\n  if (endMarker)\n  {\n    /*\n    CStartHeader sh;\n    sh.NextHeaderOffset = (UInt32)(Int32)-1;\n    sh.NextHeaderSize = (UInt32)(Int32)-1;\n    sh.NextHeaderCRC = 0;\n    WriteStartHeader(sh);\n    */\n  }\n  else\n  #endif\n  {\n    if (!Stream)\n      return E_FAIL;\n    RINOK(WriteSignature());\n    RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));\n  }\n  return S_OK;\n}\n\nvoid COutArchive::Close()\n{\n  SeqStream.Release();\n  Stream.Release();\n}\n\nHRESULT COutArchive::SkeepPrefixArchiveHeader()\n{\n  #ifdef _7Z_VOL\n  if (_endMarker)\n    return S_OK;\n  #endif\n  return Stream->Seek(24, STREAM_SEEK_CUR, NULL);\n}\n\nUInt64 COutArchive::GetPos() const\n{\n  if (_countMode)\n    return _countSize;\n  if (_writeToStream)\n    return _outByte.GetProcessedSize();\n  return _outByte2.GetPos();\n}\n\nvoid COutArchive::WriteBytes(const void *data, size_t size)\n{\n  if (_countMode)\n    _countSize += size;\n  else if (_writeToStream)\n  {\n    _outByte.WriteBytes(data, size);\n    _crc = CrcUpdate(_crc, data, size);\n  }\n  else\n    _outByte2.WriteBytes(data, size);\n}\n\nvoid COutArchive::WriteByte(Byte b)\n{\n  if (_countMode)\n    _countSize++;\n  else if (_writeToStream)\n  {\n    _outByte.WriteByte(b);\n    _crc = CRC_UPDATE_BYTE(_crc, b);\n  }\n  else\n    _outByte2.WriteByte(b);\n}\n\nvoid COutArchive::WriteUInt32(UInt32 value)\n{\n  for (int i = 0; i < 4; i++)\n  {\n    WriteByte((Byte)value);\n    value >>= 8;\n  }\n}\n\nvoid COutArchive::WriteUInt64(UInt64 value)\n{\n  for (int i = 0; i < 8; i++)\n  {\n    WriteByte((Byte)value);\n    value >>= 8;\n  }\n}\n\nvoid COutArchive::WriteNumber(UInt64 value)\n{\n  Byte firstByte = 0;\n  Byte mask = 0x80;\n  int i;\n  for (i = 0; i < 8; i++)\n  {\n    if (value < ((UInt64(1) << ( 7  * (i + 1)))))\n    {\n      firstByte |= Byte(value >> (8 * i));\n      break;\n    }\n    firstByte |= mask;\n    mask >>= 1;\n  }\n  WriteByte(firstByte);\n  for (;i > 0; i--)\n  {\n    WriteByte((Byte)value);\n    value >>= 8;\n  }\n}\n\nstatic UInt32 GetBigNumberSize(UInt64 value)\n{\n  int i;\n  for (i = 1; i < 9; i++)\n    if (value < (((UInt64)1 << (i * 7))))\n      break;\n  return i;\n}\n\n#ifdef _7Z_VOL\nUInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)\n{\n  UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;\n  if (nameLength != 0)\n  {\n    nameLength = (nameLength + 1) * 2;\n    result += nameLength + GetBigNumberSize(nameLength) + 2;\n  }\n  if (props)\n  {\n    result += 20;\n  }\n  if (result >= 128)\n    result++;\n  result += kSignatureSize + 2 + kFinishHeaderSize;\n  return result;\n}\n\nUInt64 COutArchive::GetVolPureSize(UInt64 volSize, int nameLength, bool props)\n{\n  UInt32 headersSizeBase = COutArchive::GetVolHeadersSize(1, nameLength, props);\n  int testSize;\n  if (volSize > headersSizeBase)\n    testSize = volSize - headersSizeBase;\n  else\n    testSize = 1;\n  UInt32 headersSize = COutArchive::GetVolHeadersSize(testSize, nameLength, props);\n  UInt64 pureSize = 1;\n  if (volSize > headersSize)\n    pureSize = volSize - headersSize;\n  return pureSize;\n}\n#endif\n\nvoid COutArchive::WriteFolder(const CFolder &folder)\n{\n  WriteNumber(folder.Coders.Size());\n  int i;\n  for (i = 0; i < folder.Coders.Size(); i++)\n  {\n    const CCoderInfo &coder = folder.Coders[i];\n    {\n      size_t propsSize = coder.Props.GetCapacity();\n      \n      UInt64 id = coder.MethodID;\n      int idSize;\n      for (idSize = 1; idSize < sizeof(id); idSize++)\n        if ((id >> (8 * idSize)) == 0)\n          break;\n      BYTE longID[15];\n      for (int t = idSize - 1; t >= 0 ; t--, id >>= 8)\n        longID[t] = (Byte)(id & 0xFF);\n      Byte b;\n      b = (Byte)(idSize & 0xF);\n      bool isComplex = !coder.IsSimpleCoder();\n      b |= (isComplex ? 0x10 : 0);\n      b |= ((propsSize != 0) ? 0x20 : 0 );\n      WriteByte(b);\n      WriteBytes(longID, idSize);\n      if (isComplex)\n      {\n        WriteNumber(coder.NumInStreams);\n        WriteNumber(coder.NumOutStreams);\n      }\n      if (propsSize == 0)\n        continue;\n      WriteNumber(propsSize);\n      WriteBytes(coder.Props, propsSize);\n    }\n  }\n  for (i = 0; i < folder.BindPairs.Size(); i++)\n  {\n    const CBindPair &bindPair = folder.BindPairs[i];\n    WriteNumber(bindPair.InIndex);\n    WriteNumber(bindPair.OutIndex);\n  }\n  if (folder.PackStreams.Size() > 1)\n    for (i = 0; i < folder.PackStreams.Size(); i++)\n    {\n      WriteNumber(folder.PackStreams[i]);\n    }\n}\n\nvoid COutArchive::WriteBoolVector(const CBoolVector &boolVector)\n{\n  Byte b = 0;\n  Byte mask = 0x80;\n  for (int i = 0; i < boolVector.Size(); i++)\n  {\n    if (boolVector[i])\n      b |= mask;\n    mask >>= 1;\n    if (mask == 0)\n    {\n      WriteByte(b);\n      mask = 0x80;\n      b = 0;\n    }\n  }\n  if (mask != 0x80)\n    WriteByte(b);\n}\n\n\nvoid COutArchive::WriteHashDigests(\n    const CRecordVector<bool> &digestsDefined,\n    const CRecordVector<UInt32> &digests)\n{\n  int numDefined = 0;\n  int i;\n  for (i = 0; i < digestsDefined.Size(); i++)\n    if (digestsDefined[i])\n      numDefined++;\n  if (numDefined == 0)\n    return;\n\n  WriteByte(NID::kCRC);\n  if (numDefined == digestsDefined.Size())\n    WriteByte(1);\n  else\n  {\n    WriteByte(0);\n    WriteBoolVector(digestsDefined);\n  }\n  for (i = 0; i < digests.Size(); i++)\n    if (digestsDefined[i])\n      WriteUInt32(digests[i]);\n}\n\nvoid COutArchive::WritePackInfo(\n    UInt64 dataOffset,\n    const CRecordVector<UInt64> &packSizes,\n    const CRecordVector<bool> &packCRCsDefined,\n    const CRecordVector<UInt32> &packCRCs)\n{\n  if (packSizes.IsEmpty())\n    return;\n  WriteByte(NID::kPackInfo);\n  WriteNumber(dataOffset);\n  WriteNumber(packSizes.Size());\n  WriteByte(NID::kSize);\n  for (int i = 0; i < packSizes.Size(); i++)\n    WriteNumber(packSizes[i]);\n\n  WriteHashDigests(packCRCsDefined, packCRCs);\n  \n  WriteByte(NID::kEnd);\n}\n\nvoid COutArchive::WriteUnpackInfo(const CObjectVector<CFolder> &folders)\n{\n  if (folders.IsEmpty())\n    return;\n\n  WriteByte(NID::kUnpackInfo);\n\n  WriteByte(NID::kFolder);\n  WriteNumber(folders.Size());\n  {\n    WriteByte(0);\n    for (int i = 0; i < folders.Size(); i++)\n      WriteFolder(folders[i]);\n  }\n  \n  WriteByte(NID::kCodersUnpackSize);\n  int i;\n  for (i = 0; i < folders.Size(); i++)\n  {\n    const CFolder &folder = folders[i];\n    for (int j = 0; j < folder.UnpackSizes.Size(); j++)\n      WriteNumber(folder.UnpackSizes[j]);\n  }\n\n  CRecordVector<bool> unpackCRCsDefined;\n  CRecordVector<UInt32> unpackCRCs;\n  for (i = 0; i < folders.Size(); i++)\n  {\n    const CFolder &folder = folders[i];\n    unpackCRCsDefined.Add(folder.UnpackCRCDefined);\n    unpackCRCs.Add(folder.UnpackCRC);\n  }\n  WriteHashDigests(unpackCRCsDefined, unpackCRCs);\n\n  WriteByte(NID::kEnd);\n}\n\nvoid COutArchive::WriteSubStreamsInfo(\n    const CObjectVector<CFolder> &folders,\n    const CRecordVector<CNum> &numUnpackStreamsInFolders,\n    const CRecordVector<UInt64> &unpackSizes,\n    const CRecordVector<bool> &digestsDefined,\n    const CRecordVector<UInt32> &digests)\n{\n  WriteByte(NID::kSubStreamsInfo);\n\n  int i;\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\n  {\n    if (numUnpackStreamsInFolders[i] != 1)\n    {\n      WriteByte(NID::kNumUnpackStream);\n      for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\n        WriteNumber(numUnpackStreamsInFolders[i]);\n      break;\n    }\n  }\n \n\n  bool needFlag = true;\n  CNum index = 0;\n  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)\n    for (CNum j = 0; j < numUnpackStreamsInFolders[i]; j++)\n    {\n      if (j + 1 != numUnpackStreamsInFolders[i])\n      {\n        if (needFlag)\n          WriteByte(NID::kSize);\n        needFlag = false;\n        WriteNumber(unpackSizes[index]);\n      }\n      index++;\n    }\n\n  CRecordVector<bool> digestsDefined2;\n  CRecordVector<UInt32> digests2;\n\n  int digestIndex = 0;\n  for (i = 0; i < folders.Size(); i++)\n  {\n    int numSubStreams = (int)numUnpackStreamsInFolders[i];\n    if (numSubStreams == 1 && folders[i].UnpackCRCDefined)\n      digestIndex++;\n    else\n      for (int j = 0; j < numSubStreams; j++, digestIndex++)\n      {\n        digestsDefined2.Add(digestsDefined[digestIndex]);\n        digests2.Add(digests[digestIndex]);\n      }\n  }\n  WriteHashDigests(digestsDefined2, digests2);\n  WriteByte(NID::kEnd);\n}\n\nvoid COutArchive::SkipAlign(unsigned /* pos */, unsigned /* alignSize */)\n{\n  return;\n}\n\n/*\n7-Zip 4.50 - 4.58 contain BUG, so they do not support .7z archives with Unknown field.\n\nvoid COutArchive::SkipAlign(unsigned pos, unsigned alignSize)\n{\n  pos += (unsigned)GetPos();\n  pos &= (alignSize - 1);\n  if (pos == 0)\n    return;\n  unsigned skip = alignSize - pos;\n  if (skip < 2)\n    skip += alignSize;\n  skip -= 2;\n  WriteByte(NID::kDummy);\n  WriteByte((Byte)skip);\n  for (unsigned i = 0; i < skip; i++)\n    WriteByte(0);\n}\n*/\n\nvoid COutArchive::WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize)\n{\n  const UInt64 bvSize = (numDefined == v.Size()) ? 0 : (v.Size() + 7) / 8;\n  const UInt64 dataSize = (UInt64)numDefined * itemSize + bvSize + 2;\n  SkipAlign(3 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), itemSize);\n\n  WriteByte(type);\n  WriteNumber(dataSize);\n  if (numDefined == v.Size())\n    WriteByte(1);\n  else\n  {\n    WriteByte(0);\n    WriteBoolVector(v);\n  }\n  WriteByte(0);\n}\n\nvoid COutArchive::WriteUInt64DefVector(const CUInt64DefVector &v, Byte type)\n{\n  int numDefined = 0;\n\n  int i;\n  for (i = 0; i < v.Defined.Size(); i++)\n    if (v.Defined[i])\n      numDefined++;\n\n  if (numDefined == 0)\n    return;\n\n  WriteAlignedBoolHeader(v.Defined, numDefined, type, 8);\n  \n  for (i = 0; i < v.Defined.Size(); i++)\n    if (v.Defined[i])\n      WriteUInt64(v.Values[i]);\n}\n\nHRESULT COutArchive::EncodeStream(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    CEncoder &encoder, const Byte *data, size_t dataSize,\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\n{\n  CSequentialInStreamImp *streamSpec = new CSequentialInStreamImp;\n  CMyComPtr<ISequentialInStream> stream = streamSpec;\n  streamSpec->Init(data, dataSize);\n  CFolder folderItem;\n  folderItem.UnpackCRCDefined = true;\n  folderItem.UnpackCRC = CrcCalc(data, dataSize);\n  UInt64 dataSize64 = dataSize;\n  RINOK(encoder.Encode(\n      EXTERNAL_CODECS_LOC_VARS\n      stream, NULL, &dataSize64, folderItem, SeqStream, packSizes, NULL))\n  folders.Add(folderItem);\n  return S_OK;\n}\n\nHRESULT COutArchive::EncodeStream(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    CEncoder &encoder, const CByteBuffer &data,\n    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)\n{\n  return EncodeStream(\n      EXTERNAL_CODECS_LOC_VARS\n      encoder, data, data.GetCapacity(), packSizes, folders);\n}\n\nvoid COutArchive::WriteHeader(\n    const CArchiveDatabase &db,\n    const CHeaderOptions &headerOptions,\n    UInt64 &headerOffset)\n{\n  int i;\n  \n  UInt64 packedSize = 0;\n  for (i = 0; i < db.PackSizes.Size(); i++)\n    packedSize += db.PackSizes[i];\n\n  headerOffset = packedSize;\n\n  WriteByte(NID::kHeader);\n\n  // Archive Properties\n\n  if (db.Folders.Size() > 0)\n  {\n    WriteByte(NID::kMainStreamsInfo);\n    WritePackInfo(0, db.PackSizes,\n        db.PackCRCsDefined,\n        db.PackCRCs);\n\n    WriteUnpackInfo(db.Folders);\n\n    CRecordVector<UInt64> unpackSizes;\n    CRecordVector<bool> digestsDefined;\n    CRecordVector<UInt32> digests;\n    for (i = 0; i < db.Files.Size(); i++)\n    {\n      const CFileItem &file = db.Files[i];\n      if (!file.HasStream)\n        continue;\n      unpackSizes.Add(file.Size);\n      digestsDefined.Add(file.CrcDefined);\n      digests.Add(file.Crc);\n    }\n\n    WriteSubStreamsInfo(\n        db.Folders,\n        db.NumUnpackStreamsVector,\n        unpackSizes,\n        digestsDefined,\n        digests);\n    WriteByte(NID::kEnd);\n  }\n\n  if (db.Files.IsEmpty())\n  {\n    WriteByte(NID::kEnd);\n    return;\n  }\n\n  WriteByte(NID::kFilesInfo);\n  WriteNumber(db.Files.Size());\n\n  {\n  /* ---------- Empty Streams ---------- */\n  CBoolVector emptyStreamVector;\n  emptyStreamVector.Reserve(db.Files.Size());\n  int numEmptyStreams = 0;\n  for (i = 0; i < db.Files.Size(); i++)\n    if (db.Files[i].HasStream)\n      emptyStreamVector.Add(false);\n    else\n    {\n      emptyStreamVector.Add(true);\n      numEmptyStreams++;\n    }\n  if (numEmptyStreams > 0)\n  {\n    WriteByte(NID::kEmptyStream);\n    WriteNumber((emptyStreamVector.Size() + 7) / 8);\n    WriteBoolVector(emptyStreamVector);\n\n    CBoolVector emptyFileVector, antiVector;\n    emptyFileVector.Reserve(numEmptyStreams);\n    antiVector.Reserve(numEmptyStreams);\n    CNum numEmptyFiles = 0, numAntiItems = 0;\n    for (i = 0; i < db.Files.Size(); i++)\n    {\n      const CFileItem &file = db.Files[i];\n      if (!file.HasStream)\n      {\n        emptyFileVector.Add(!file.IsDir);\n        if (!file.IsDir)\n          numEmptyFiles++;\n        bool isAnti = db.IsItemAnti(i);\n        antiVector.Add(isAnti);\n        if (isAnti)\n          numAntiItems++;\n      }\n    }\n\n    if (numEmptyFiles > 0)\n    {\n      WriteByte(NID::kEmptyFile);\n      WriteNumber((emptyFileVector.Size() + 7) / 8);\n      WriteBoolVector(emptyFileVector);\n    }\n\n    if (numAntiItems > 0)\n    {\n      WriteByte(NID::kAnti);\n      WriteNumber((antiVector.Size() + 7) / 8);\n      WriteBoolVector(antiVector);\n    }\n  }\n  }\n\n\n  {\n    /* ---------- Names ---------- */\n    \n    int numDefined = 0;\n    size_t namesDataSize = 0;\n    for (int i = 0; i < db.Files.Size(); i++)\n    {\n      const UString &name = db.Files[i].Name;\n      if (!name.IsEmpty())\n        numDefined++;\n      namesDataSize += (name.Length() + 1) * 2;\n    }\n    \n    if (numDefined > 0)\n    {\n      namesDataSize++;\n      SkipAlign(2 + GetBigNumberSize(namesDataSize), 2);\n\n      WriteByte(NID::kName);\n      WriteNumber(namesDataSize);\n      WriteByte(0);\n      for (int i = 0; i < db.Files.Size(); i++)\n      {\n        const UString &name = db.Files[i].Name;\n        for (int t = 0; t <= name.Length(); t++)\n        {\n          wchar_t c = name[t];\n          WriteByte((Byte)c);\n          WriteByte((Byte)(c >> 8));\n        }\n      }\n    }\n  }\n\n  if (headerOptions.WriteCTime) WriteUInt64DefVector(db.CTime, NID::kCTime);\n  if (headerOptions.WriteATime) WriteUInt64DefVector(db.ATime, NID::kATime);\n  if (headerOptions.WriteMTime) WriteUInt64DefVector(db.MTime, NID::kMTime);\n  WriteUInt64DefVector(db.StartPos, NID::kStartPos);\n  \n  {\n    /* ---------- Write Attrib ---------- */\n    CBoolVector boolVector;\n    boolVector.Reserve(db.Files.Size());\n    int numDefined = 0;\n    for (i = 0; i < db.Files.Size(); i++)\n    {\n      bool defined = db.Files[i].AttribDefined;\n      boolVector.Add(defined);\n      if (defined)\n        numDefined++;\n    }\n    if (numDefined > 0)\n    {\n      WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttributes, 4);\n      for (i = 0; i < db.Files.Size(); i++)\n      {\n        const CFileItem &file = db.Files[i];\n        if (file.AttribDefined)\n          WriteUInt32(file.Attrib);\n      }\n    }\n  }\n\n  WriteByte(NID::kEnd); // for files\n  WriteByte(NID::kEnd); // for headers\n}\n\nHRESULT COutArchive::WriteDatabase(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    const CArchiveDatabase &db,\n    const CCompressionMethodMode *options,\n    const CHeaderOptions &headerOptions)\n{\n  if (!db.CheckNumFiles())\n    return E_FAIL;\n\n  UInt64 headerOffset;\n  UInt32 headerCRC;\n  UInt64 headerSize;\n  if (db.IsEmpty())\n  {\n    headerSize = 0;\n    headerOffset = 0;\n    headerCRC = CrcCalc(0, 0);\n  }\n  else\n  {\n    bool encodeHeaders = false;\n    if (options != 0)\n      if (options->IsEmpty())\n        options = 0;\n    if (options != 0)\n      if (options->PasswordIsDefined || headerOptions.CompressMainHeader)\n        encodeHeaders = true;\n\n    _outByte.SetStream(SeqStream);\n    _outByte.Init();\n    _crc = CRC_INIT_VAL;\n    _countMode = encodeHeaders;\n    _writeToStream = true;\n    _countSize = 0;\n    WriteHeader(db, headerOptions, headerOffset);\n\n    if (encodeHeaders)\n    {\n      CByteBuffer buf;\n      buf.SetCapacity(_countSize);\n      _outByte2.Init((Byte *)buf, _countSize);\n      \n      _countMode = false;\n      _writeToStream = false;\n      WriteHeader(db, headerOptions, headerOffset);\n      \n      if (_countSize != _outByte2.GetPos())\n        return E_FAIL;\n\n      CCompressionMethodMode encryptOptions;\n      encryptOptions.PasswordIsDefined = options->PasswordIsDefined;\n      encryptOptions.Password = options->Password;\n      CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions);\n      CRecordVector<UInt64> packSizes;\n      CObjectVector<CFolder> folders;\n      RINOK(EncodeStream(\n          EXTERNAL_CODECS_LOC_VARS\n          encoder, (const Byte *)buf,\n          _countSize, packSizes, folders));\n\n      _writeToStream = true;\n      \n      if (folders.Size() == 0)\n        throw 1;\n\n      WriteID(NID::kEncodedHeader);\n      WritePackInfo(headerOffset, packSizes,\n        CRecordVector<bool>(), CRecordVector<UInt32>());\n      WriteUnpackInfo(folders);\n      WriteByte(NID::kEnd);\n      for (int i = 0; i < packSizes.Size(); i++)\n        headerOffset += packSizes[i];\n    }\n    RINOK(_outByte.Flush());\n    headerCRC = CRC_GET_DIGEST(_crc);\n    headerSize = _outByte.GetProcessedSize();\n  }\n  #ifdef _7Z_VOL\n  if (_endMarker)\n  {\n    CFinishHeader h;\n    h.NextHeaderSize = headerSize;\n    h.NextHeaderCRC = headerCRC;\n    h.NextHeaderOffset =\n        UInt64(0) - (headerSize +\n        4 + kFinishHeaderSize);\n    h.ArchiveStartOffset = h.NextHeaderOffset - headerOffset;\n    h.AdditionalStartBlockSize = 0;\n    RINOK(WriteFinishHeader(h));\n    return WriteFinishSignature();\n  }\n  else\n  #endif\n  {\n    CStartHeader h;\n    h.NextHeaderSize = headerSize;\n    h.NextHeaderCRC = headerCRC;\n    h.NextHeaderOffset = headerOffset;\n    RINOK(Stream->Seek(_prefixHeaderPos, STREAM_SEEK_SET, NULL));\n    return WriteStartHeader(h);\n  }\n}\n\nvoid CArchiveDatabase::GetFile(int index, CFileItem &file, CFileItem2 &file2) const\n{\n  file = Files[index];\n  file2.CTimeDefined = CTime.GetItem(index, file2.CTime);\n  file2.ATimeDefined = ATime.GetItem(index, file2.ATime);\n  file2.MTimeDefined = MTime.GetItem(index, file2.MTime);\n  file2.StartPosDefined = StartPos.GetItem(index, file2.StartPos);\n  file2.IsAnti = IsItemAnti(index);\n}\n\nvoid CArchiveDatabase::AddFile(const CFileItem &file, const CFileItem2 &file2)\n{\n  int index = Files.Size();\n  CTime.SetItem(index, file2.CTimeDefined, file2.CTime);\n  ATime.SetItem(index, file2.ATimeDefined, file2.ATime);\n  MTime.SetItem(index, file2.MTimeDefined, file2.MTime);\n  StartPos.SetItem(index, file2.StartPosDefined, file2.StartPos);\n  SetItemAnti(index, file2.IsAnti);\n  Files.Add(file);\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zOut.h",
    "content": "// 7z/Out.h\n\n#ifndef __7Z_OUT_H\n#define __7Z_OUT_H\n\n#include \"7zHeader.h\"\n#include \"7zItem.h\"\n#include \"7zCompressionMode.h\"\n#include \"7zEncode.h\"\n\n#include \"../../Common/OutBuffer.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nclass CWriteBufferLoc\n{\n  Byte *_data;\n  size_t _size;\n  size_t _pos;\npublic:\n  CWriteBufferLoc(): _size(0), _pos(0) {}\n  void Init(Byte *data, size_t size)\n  {\n    _data = data;\n    _size = size;\n    _pos = 0;\n  }\n  void WriteBytes(const void *data, size_t size)\n  {\n    if (size > _size - _pos)\n      throw 1;\n    memcpy(_data + _pos, data, size);\n    _pos += size;\n  }\n  void WriteByte(Byte b)\n  {\n    if (_size == _pos)\n      throw 1;\n    _data[_pos++] = b;\n  }\n  size_t GetPos() const { return _pos; }\n};\n\nstruct CHeaderOptions\n{\n  bool CompressMainHeader;\n  bool WriteCTime;\n  bool WriteATime;\n  bool WriteMTime;\n\n  CHeaderOptions():\n      CompressMainHeader(true),\n      WriteCTime(false),\n      WriteATime(false),\n      WriteMTime(true)\n      {}\n};\n\nclass COutArchive\n{\n  UInt64 _prefixHeaderPos;\n\n  HRESULT WriteDirect(const void *data, UInt32 size);\n  \n  UInt64 GetPos() const;\n  void WriteBytes(const void *data, size_t size);\n  void WriteBytes(const CByteBuffer &data) { WriteBytes(data, data.GetCapacity()); }\n  void WriteByte(Byte b);\n  void WriteUInt32(UInt32 value);\n  void WriteUInt64(UInt64 value);\n  void WriteNumber(UInt64 value);\n  void WriteID(UInt64 value) { WriteNumber(value); }\n\n  void WriteFolder(const CFolder &folder);\n  HRESULT WriteFileHeader(const CFileItem &itemInfo);\n  void WriteBoolVector(const CBoolVector &boolVector);\n  void WriteHashDigests(\n      const CRecordVector<bool> &digestsDefined,\n      const CRecordVector<UInt32> &hashDigests);\n\n  void WritePackInfo(\n      UInt64 dataOffset,\n      const CRecordVector<UInt64> &packSizes,\n      const CRecordVector<bool> &packCRCsDefined,\n      const CRecordVector<UInt32> &packCRCs);\n\n  void WriteUnpackInfo(const CObjectVector<CFolder> &folders);\n\n  void WriteSubStreamsInfo(\n      const CObjectVector<CFolder> &folders,\n      const CRecordVector<CNum> &numUnpackStreamsInFolders,\n      const CRecordVector<UInt64> &unpackSizes,\n      const CRecordVector<bool> &digestsDefined,\n      const CRecordVector<UInt32> &hashDigests);\n\n  void SkipAlign(unsigned pos, unsigned alignSize);\n  void WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize);\n  void WriteUInt64DefVector(const CUInt64DefVector &v, Byte type);\n\n  HRESULT EncodeStream(\n      DECL_EXTERNAL_CODECS_LOC_VARS\n      CEncoder &encoder, const Byte *data, size_t dataSize,\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\n  HRESULT EncodeStream(\n      DECL_EXTERNAL_CODECS_LOC_VARS\n      CEncoder &encoder, const CByteBuffer &data,\n      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);\n  void WriteHeader(\n      const CArchiveDatabase &db,\n      const CHeaderOptions &headerOptions,\n      UInt64 &headerOffset);\n  \n  bool _countMode;\n  bool _writeToStream;\n  size_t _countSize;\n  UInt32 _crc;\n  COutBuffer _outByte;\n  CWriteBufferLoc _outByte2;\n\n  #ifdef _7Z_VOL\n  bool _endMarker;\n  #endif\n\n  HRESULT WriteSignature();\n  #ifdef _7Z_VOL\n  HRESULT WriteFinishSignature();\n  #endif\n  HRESULT WriteStartHeader(const CStartHeader &h);\n  #ifdef _7Z_VOL\n  HRESULT WriteFinishHeader(const CFinishHeader &h);\n  #endif\n  CMyComPtr<IOutStream> Stream;\npublic:\n\n  COutArchive() { _outByte.Create(1 << 16); }\n  CMyComPtr<ISequentialOutStream> SeqStream;\n  HRESULT Create(ISequentialOutStream *stream, bool endMarker);\n  void Close();\n  HRESULT SkeepPrefixArchiveHeader();\n  HRESULT WriteDatabase(\n      DECL_EXTERNAL_CODECS_LOC_VARS\n      const CArchiveDatabase &db,\n      const CCompressionMethodMode *options,\n      const CHeaderOptions &headerOptions);\n\n  #ifdef _7Z_VOL\n  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);\n  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);\n  #endif\n\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zProperties.cpp",
    "content": "// 7zProperties.cpp\n\n#include \"StdAfx.h\"\n\n#include \"7zProperties.h\"\n#include \"7zHeader.h\"\n#include \"7zHandler.h\"\n\n// #define _MULTI_PACK\n\nnamespace NArchive {\nnamespace N7z {\n\nstruct CPropMap\n{\n  UInt64 FilePropID;\n  STATPROPSTG StatPROPSTG;\n};\n\nCPropMap kPropMap[] =\n{\n  { NID::kName, NULL, kpidPath, VT_BSTR},\n  { NID::kSize, NULL, kpidSize, VT_UI8},\n  { NID::kPackInfo, NULL, kpidPackSize, VT_UI8},\n  \n  #ifdef _MULTI_PACK\n  { 100, L\"Pack0\", kpidPackedSize0, VT_UI8},\n  { 101, L\"Pack1\", kpidPackedSize1, VT_UI8},\n  { 102, L\"Pack2\", kpidPackedSize2, VT_UI8},\n  { 103, L\"Pack3\", kpidPackedSize3, VT_UI8},\n  { 104, L\"Pack4\", kpidPackedSize4, VT_UI8},\n  #endif\n\n  { NID::kCTime, NULL, kpidCTime, VT_FILETIME},\n  { NID::kMTime, NULL, kpidMTime, VT_FILETIME},\n  { NID::kATime, NULL, kpidATime, VT_FILETIME},\n  { NID::kWinAttributes, NULL, kpidAttrib, VT_UI4},\n  { NID::kStartPos, NULL, kpidPosition, VT_UI4},\n\n  { NID::kCRC, NULL, kpidCRC, VT_UI4},\n  \n  { NID::kAnti, NULL, kpidIsAnti, VT_BOOL},\n\n  #ifndef _SFX\n  { 97, NULL, kpidEncrypted, VT_BOOL},\n  { 98, NULL, kpidMethod, VT_BSTR},\n  { 99, NULL, kpidBlock, VT_UI4}\n  #endif\n};\n\nstatic const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);\n\nstatic int FindPropInMap(UInt64 filePropID)\n{\n  for (int i = 0; i < kPropMapSize; i++)\n    if (kPropMap[i].FilePropID == filePropID)\n      return i;\n  return -1;\n}\n\nstatic void CopyOneItem(CRecordVector<UInt64> &src,\n    CRecordVector<UInt64> &dest, UInt32 item)\n{\n  for (int i = 0; i < src.Size(); i++)\n    if (src[i] == item)\n    {\n      dest.Add(item);\n      src.Delete(i);\n      return;\n    }\n}\n\nstatic void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)\n{\n  for (int i = 0; i < src.Size(); i++)\n    if (src[i] == item)\n    {\n      src.Delete(i);\n      return;\n    }\n}\n\nstatic void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)\n{\n  for (int i = 0; i < dest.Size(); i++)\n    if (dest[i] == item)\n    {\n      dest.Delete(i);\n      break;\n    }\n  dest.Insert(0, item);\n}\n\nvoid CHandler::FillPopIDs()\n{\n  _fileInfoPopIDs.Clear();\n\n  #ifdef _7Z_VOL\n  if(_volumes.Size() < 1)\n    return;\n  const CVolume &volume = _volumes.Front();\n  const CArchiveDatabaseEx &_db = volume.Database;\n  #endif\n\n  CRecordVector<UInt64> fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;\n\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);\n  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);\n\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);\n  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);\n  _fileInfoPopIDs += fileInfoPopIDs;\n \n  #ifndef _SFX\n  _fileInfoPopIDs.Add(97);\n  _fileInfoPopIDs.Add(98);\n  _fileInfoPopIDs.Add(99);\n  #endif\n  #ifdef _MULTI_PACK\n  _fileInfoPopIDs.Add(100);\n  _fileInfoPopIDs.Add(101);\n  _fileInfoPopIDs.Add(102);\n  _fileInfoPopIDs.Add(103);\n  _fileInfoPopIDs.Add(104);\n  #endif\n\n  #ifndef _SFX\n  InsertToHead(_fileInfoPopIDs, NID::kMTime);\n  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);\n  InsertToHead(_fileInfoPopIDs, NID::kSize);\n  InsertToHead(_fileInfoPopIDs, NID::kName);\n  #endif\n}\n\nSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)\n{\n  *numProperties = _fileInfoPopIDs.Size();\n  return S_OK;\n}\n\nSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)\n{\n  if ((int)index >= _fileInfoPopIDs.Size())\n    return E_INVALIDARG;\n  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);\n  if (indexInMap == -1)\n    return E_INVALIDARG;\n  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;\n  *propID = srcItem.propid;\n  *varType = srcItem.vt;\n  *name = 0;\n  return S_OK;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zProperties.h",
    "content": "// 7zProperties.h\n\n#ifndef __7Z_PROPERTIES_H\n#define __7Z_PROPERTIES_H\n\n#include \"../../PropID.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nenum\n{\n  kpidPackedSize0 = kpidUserDefined,\n  kpidPackedSize1,\n  kpidPackedSize2,\n  kpidPackedSize3,\n  kpidPackedSize4\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zRegister.cpp",
    "content": "// 7zRegister.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../Common/RegisterArc.h\"\n\n#include \"7zHandler.h\"\nstatic IInArchive *CreateArc() { return new NArchive::N7z::CHandler;  }\n#ifndef EXTRACT_ONLY\nstatic IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler;  }\n#else\n#define CreateArcOut 0\n#endif\n\nstatic CArcInfo g_ArcInfo =\n  { L\"7z\", L\"7z\", 0, 7, {'7' + 1 , 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };\n\nREGISTER_ARC_DEC_SIG(7z)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zSpecStream.cpp",
    "content": "// 7zSpecStream.cpp\n\n#include \"StdAfx.h\"\n\n#include \"7zSpecStream.h\"\n\nSTDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize;\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\n  _size += realProcessedSize;\n  if (processedSize != 0)\n    *processedSize = realProcessedSize;\n  return result;\n}\n\nSTDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(\n    UInt64 subStream, UInt64 *value)\n{\n  if (_getSubStreamSize == NULL)\n    return E_NOTIMPL;\n  return  _getSubStreamSize->GetSubStreamSize(subStream, value);\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zSpecStream.h",
    "content": "// 7zSpecStream.h\n\n#ifndef __7Z_SPEC_STREAM_H\n#define __7Z_SPEC_STREAM_H\n\n#include \"../../IStream.h\"\n#include \"../../ICoder.h\"\n#include \"../../../Common/MyCom.h\"\n\nclass CSequentialInStreamSizeCount2:\n  public ISequentialInStream,\n  public ICompressGetSubStreamSize,\n  public CMyUnknownImp\n{\n  CMyComPtr<ISequentialInStream> _stream;\n  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;\n  UInt64 _size;\npublic:\n  void Init(ISequentialInStream *stream)\n  {\n    _stream = stream;\n    _getSubStreamSize = 0;\n    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);\n    _size = 0;\n  }\n  UInt64 GetSize() const { return _size; }\n\n  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zUpdate.cpp",
    "content": "// 7zUpdate.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../Common/LimitedStreams.h\"\n#include \"../../Common/ProgressUtils.h\"\n\n#include \"../../Compress/CopyCoder.h\"\n\n#include \"../Common/ItemNameUtils.h\"\n\n#include \"7zEncode.h\"\n#include \"7zFolderInStream.h\"\n#include \"7zHandler.h\"\n#include \"7zOut.h\"\n#include \"7zUpdate.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nstatic const wchar_t *kMatchFinderForBCJ2_LZMA = L\"BT2\";\nstatic const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;\nstatic const UInt32 kAlgorithmForBCJ2_LZMA = 1;\nstatic const UInt32 kNumFastBytesForBCJ2_LZMA = 64;\n\nstatic HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream,\n    UInt64 position, UInt64 size, ICompressProgressInfo *progress)\n{\n  RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));\n  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;\n  CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);\n  streamSpec->SetStream(inStream);\n  streamSpec->Init(size);\n\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\n  RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));\n  return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);\n}\n\nstatic int GetReverseSlashPos(const UString &name)\n{\n  int slashPos = name.ReverseFind(L'/');\n  #ifdef _WIN32\n  int slash1Pos = name.ReverseFind(L'\\\\');\n  slashPos = MyMax(slashPos, slash1Pos);\n  #endif\n  return slashPos;\n}\n\nint CUpdateItem::GetExtensionPos() const\n{\n  int slashPos = GetReverseSlashPos(Name);\n  int dotPos = Name.ReverseFind(L'.');\n  if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\n    return Name.Length();\n  return dotPos + 1;\n}\n\nUString CUpdateItem::GetExtension() const\n{\n  return Name.Mid(GetExtensionPos());\n}\n\n#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }\n\nstatic int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)\n{\n  size_t c1 = a1.GetCapacity();\n  size_t c2 = a2.GetCapacity();\n  RINOZ(MyCompare(c1, c2));\n  for (size_t i = 0; i < c1; i++)\n    RINOZ(MyCompare(a1[i], a2[i]));\n  return 0;\n}\n\nstatic int CompareCoders(const CCoderInfo &c1, const CCoderInfo &c2)\n{\n  RINOZ(MyCompare(c1.NumInStreams, c2.NumInStreams));\n  RINOZ(MyCompare(c1.NumOutStreams, c2.NumOutStreams));\n  RINOZ(MyCompare(c1.MethodID, c2.MethodID));\n  return CompareBuffers(c1.Props, c2.Props);\n}\n\nstatic int CompareBindPairs(const CBindPair &b1, const CBindPair &b2)\n{\n  RINOZ(MyCompare(b1.InIndex, b2.InIndex));\n  return MyCompare(b1.OutIndex, b2.OutIndex);\n}\n\nstatic int CompareFolders(const CFolder &f1, const CFolder &f2)\n{\n  int s1 = f1.Coders.Size();\n  int s2 = f2.Coders.Size();\n  RINOZ(MyCompare(s1, s2));\n  int i;\n  for (i = 0; i < s1; i++)\n    RINOZ(CompareCoders(f1.Coders[i], f2.Coders[i]));\n  s1 = f1.BindPairs.Size();\n  s2 = f2.BindPairs.Size();\n  RINOZ(MyCompare(s1, s2));\n  for (i = 0; i < s1; i++)\n    RINOZ(CompareBindPairs(f1.BindPairs[i], f2.BindPairs[i]));\n  return 0;\n}\n\nstatic int CompareFiles(const CFileItem &f1, const CFileItem &f2)\n{\n  return MyStringCompareNoCase(f1.Name, f2.Name);\n}\n\nstatic int CompareFolderRefs(const int *p1, const int *p2, void *param)\n{\n  int i1 = *p1;\n  int i2 = *p2;\n  const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param;\n  RINOZ(CompareFolders(\n      db.Folders[i1],\n      db.Folders[i2]));\n  RINOZ(MyCompare(\n      db.NumUnpackStreamsVector[i1],\n      db.NumUnpackStreamsVector[i2]));\n  if (db.NumUnpackStreamsVector[i1] == 0)\n    return 0;\n  return CompareFiles(\n      db.Files[db.FolderStartFileIndex[i1]],\n      db.Files[db.FolderStartFileIndex[i2]]);\n}\n\n////////////////////////////////////////////////////////////\n\nstatic int CompareEmptyItems(const int *p1, const int *p2, void *param)\n{\n  const CObjectVector<CUpdateItem> &updateItems = *(const CObjectVector<CUpdateItem> *)param;\n  const CUpdateItem &u1 = updateItems[*p1];\n  const CUpdateItem &u2 = updateItems[*p2];\n  if (u1.IsDir != u2.IsDir)\n    return (u1.IsDir) ? 1 : -1;\n  if (u1.IsDir)\n  {\n    if (u1.IsAnti != u2.IsAnti)\n      return (u1.IsAnti ? 1 : -1);\n    int n = MyStringCompareNoCase(u1.Name, u2.Name);\n    return -n;\n  }\n  if (u1.IsAnti != u2.IsAnti)\n    return (u1.IsAnti ? 1 : -1);\n  return MyStringCompareNoCase(u1.Name, u2.Name);\n}\n\nstatic const char *g_Exts =\n  \" lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo\"\n  \" zip jar ear war msi\"\n  \" 3gp avi mov mpeg mpg mpe wmv\"\n  \" aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav\"\n  \" swf \"\n  \" chm hxi hxs\"\n  \" gif jpeg jpg jp2 png tiff  bmp ico psd psp\"\n  \" awg ps eps cgm dxf svg vrml wmf emf ai md\"\n  \" cad dwg pps key sxi\"\n  \" max 3ds\"\n  \" iso bin nrg mdf img pdi tar cpio xpi\"\n  \" vfd vhd vud vmc vsv\"\n  \" vmdk dsk nvram vmem vmsd vmsn vmss vmtm\"\n  \" inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def\"\n  \" f77 f f90 f95\"\n  \" asm sql manifest dep \"\n  \" mak clw csproj vcproj sln dsp dsw \"\n  \" class \"\n  \" bat cmd\"\n  \" xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml\"\n  \" awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs\"\n  \" text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf\"\n  \" sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf\"\n  \" abw afp cwk lwp wpd wps wpt wrf wri\"\n  \" abf afm bdf fon mgf otf pcf pfa snf ttf\"\n  \" dbf mdb nsf ntf wdb db fdb gdb\"\n  \" exe dll ocx vbx sfx sys tlb awx com obj lib out o so \"\n  \" pdb pch idb ncb opt\";\n\nint GetExtIndex(const char *ext)\n{\n  int extIndex = 1;\n  const char *p = g_Exts;\n  for (;;)\n  {\n    char c = *p++;\n    if (c == 0)\n      return extIndex;\n    if (c == ' ')\n      continue;\n    int pos = 0;\n    for (;;)\n    {\n      char c2 = ext[pos++];\n      if (c2 == 0 && (c == 0 || c == ' '))\n        return extIndex;\n      if (c != c2)\n        break;\n      c = *p++;\n    }\n    extIndex++;\n    for (;;)\n    {\n      if (c == 0)\n        return extIndex;\n      if (c == ' ')\n        break;\n      c = *p++;\n    }\n  }\n}\n\nstruct CRefItem\n{\n  const CUpdateItem *UpdateItem;\n  UInt32 Index;\n  UInt32 ExtensionPos;\n  UInt32 NamePos;\n  int ExtensionIndex;\n  CRefItem(UInt32 index, const CUpdateItem &ui, bool sortByType):\n    UpdateItem(&ui),\n    Index(index),\n    ExtensionPos(0),\n    NamePos(0),\n    ExtensionIndex(0)\n  {\n    if (sortByType)\n    {\n      int slashPos = GetReverseSlashPos(ui.Name);\n      NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0);\n      int dotPos = ui.Name.ReverseFind(L'.');\n      if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))\n        ExtensionPos = ui.Name.Length();\n      else\n      {\n        ExtensionPos = dotPos + 1;\n        UString us = ui.Name.Mid(ExtensionPos);\n        if (!us.IsEmpty())\n        {\n          us.MakeLower();\n          int i;\n          AString s;\n          for (i = 0; i < us.Length(); i++)\n          {\n            wchar_t c = us[i];\n            if (c >= 0x80)\n              break;\n            s += (char)c;\n          }\n          if (i == us.Length())\n            ExtensionIndex = GetExtIndex(s);\n          else\n            ExtensionIndex = 0;\n        }\n      }\n    }\n  }\n};\n\nstatic int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *param)\n{\n  const CRefItem &a1 = *p1;\n  const CRefItem &a2 = *p2;\n  const CUpdateItem &u1 = *a1.UpdateItem;\n  const CUpdateItem &u2 = *a2.UpdateItem;\n  int n;\n  if (u1.IsDir != u2.IsDir)\n    return (u1.IsDir) ? 1 : -1;\n  if (u1.IsDir)\n  {\n    if (u1.IsAnti != u2.IsAnti)\n      return (u1.IsAnti ? 1 : -1);\n    n = MyStringCompareNoCase(u1.Name, u2.Name);\n    return -n;\n  }\n  bool sortByType = *(bool *)param;\n  if (sortByType)\n  {\n    RINOZ(MyCompare(a1.ExtensionIndex, a2.ExtensionIndex))\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos));\n    RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos));\n    if (!u1.MTimeDefined && u2.MTimeDefined) return 1;\n    if (u1.MTimeDefined && !u2.MTimeDefined) return -1;\n    if (u1.MTimeDefined && u2.MTimeDefined) RINOZ(MyCompare(u1.MTime, u2.MTime));\n    RINOZ(MyCompare(u1.Size, u2.Size))\n  }\n  return MyStringCompareNoCase(u1.Name, u2.Name);\n}\n\nstruct CSolidGroup\n{\n  CCompressionMethodMode Method;\n  CRecordVector<UInt32> Indices;\n};\n\nstatic wchar_t *g_ExeExts[] =\n{\n  L\"dll\",\n  L\"exe\",\n  L\"ocx\",\n  L\"sfx\",\n  L\"sys\"\n};\n\nstatic bool IsExeFile(const UString &ext)\n{\n  for (int i = 0; i < sizeof(g_ExeExts) / sizeof(g_ExeExts[0]); i++)\n    if (ext.CompareNoCase(g_ExeExts[i]) == 0)\n      return true;\n  return false;\n}\n\nstatic const UInt64 k_LZMA  = 0x030101;\nstatic const UInt64 k_BCJ   = 0x03030103;\nstatic const UInt64 k_BCJ2  = 0x0303011B;\n\nstatic bool GetMethodFull(UInt64 methodID,\n    UInt32 numInStreams, CMethodFull &methodResult)\n{\n  methodResult.Id = methodID;\n  methodResult.NumInStreams = numInStreams;\n  methodResult.NumOutStreams = 1;\n  return true;\n}\n\nstatic bool MakeExeMethod(const CCompressionMethodMode &method,\n    bool bcj2Filter, CCompressionMethodMode &exeMethod)\n{\n  exeMethod = method;\n  if (bcj2Filter)\n  {\n    CMethodFull methodFull;\n    if (!GetMethodFull(k_BCJ2, 4, methodFull))\n      return false;\n    exeMethod.Methods.Insert(0, methodFull);\n    if (!GetMethodFull(k_LZMA, 1, methodFull))\n      return false;\n    {\n      CProp prop;\n      prop.Id = NCoderPropID::kAlgorithm;\n      prop.Value = kAlgorithmForBCJ2_LZMA;\n      methodFull.Props.Add(prop);\n    }\n    {\n      CProp prop;\n      prop.Id = NCoderPropID::kMatchFinder;\n      prop.Value = kMatchFinderForBCJ2_LZMA;\n      methodFull.Props.Add(prop);\n    }\n    {\n      CProp prop;\n      prop.Id = NCoderPropID::kDictionarySize;\n      prop.Value = kDictionaryForBCJ2_LZMA;\n      methodFull.Props.Add(prop);\n    }\n    {\n      CProp prop;\n      prop.Id = NCoderPropID::kNumFastBytes;\n      prop.Value = kNumFastBytesForBCJ2_LZMA;\n      methodFull.Props.Add(prop);\n    }\n\n    exeMethod.Methods.Add(methodFull);\n    exeMethod.Methods.Add(methodFull);\n    CBind bind;\n\n    bind.OutCoder = 0;\n    bind.InStream = 0;\n\n    bind.InCoder = 1;\n    bind.OutStream = 0;\n    exeMethod.Binds.Add(bind);\n\n    bind.InCoder = 2;\n    bind.OutStream = 1;\n    exeMethod.Binds.Add(bind);\n\n    bind.InCoder = 3;\n    bind.OutStream = 2;\n    exeMethod.Binds.Add(bind);\n  }\n  else\n  {\n    CMethodFull methodFull;\n    if (!GetMethodFull(k_BCJ, 1, methodFull))\n      return false;\n    exeMethod.Methods.Insert(0, methodFull);\n    CBind bind;\n    bind.OutCoder = 0;\n    bind.InStream = 0;\n    bind.InCoder = 1;\n    bind.OutStream = 0;\n    exeMethod.Binds.Add(bind);\n  }\n  return true;\n}\n\nstatic void SplitFilesToGroups(\n    const CCompressionMethodMode &method,\n    bool useFilters, bool maxFilter,\n    const CObjectVector<CUpdateItem> &updateItems,\n    CObjectVector<CSolidGroup> &groups)\n{\n  if (method.Methods.Size() != 1 || method.Binds.Size() != 0)\n    useFilters = false;\n  groups.Clear();\n  groups.Add(CSolidGroup());\n  groups.Add(CSolidGroup());\n  CSolidGroup &generalGroup = groups[0];\n  CSolidGroup &exeGroup = groups[1];\n  generalGroup.Method = method;\n  int i;\n  for (i = 0; i < updateItems.Size(); i++)\n  {\n    const CUpdateItem &ui = updateItems[i];\n    if (!ui.NewData)\n      continue;\n    if (!ui.HasStream())\n      continue;\n    if (useFilters)\n    {\n      const UString name = ui.Name;\n      int dotPos = name.ReverseFind(L'.');\n      if (dotPos >= 0)\n      {\n        UString ext = name.Mid(dotPos + 1);\n        if (IsExeFile(ext))\n        {\n          exeGroup.Indices.Add(i);\n          continue;\n        }\n      }\n    }\n    generalGroup.Indices.Add(i);\n  }\n  if (exeGroup.Indices.Size() > 0)\n    if (!MakeExeMethod(method, maxFilter, exeGroup.Method))\n      exeGroup.Method = method;\n  for (i = 0; i < groups.Size();)\n    if (groups[i].Indices.Size() == 0)\n      groups.Delete(i);\n    else\n      i++;\n}\n\nstatic void FromUpdateItemToFileItem(const CUpdateItem &ui,\n    CFileItem &file, CFileItem2 &file2)\n{\n  file.Name = NItemName::MakeLegalName(ui.Name);\n  if (ui.AttribDefined)\n    file.SetAttrib(ui.Attrib);\n  \n  file2.CTime = ui.CTime;  file2.CTimeDefined = ui.CTimeDefined;\n  file2.ATime = ui.ATime;  file2.ATimeDefined = ui.ATimeDefined;\n  file2.MTime = ui.MTime;  file2.MTimeDefined = ui.MTimeDefined;\n  file2.IsAnti = ui.IsAnti;\n  file2.StartPosDefined = false;\n\n  file.Size = ui.Size;\n  file.IsDir = ui.IsDir;\n  file.HasStream = ui.HasStream();\n}\n\nstatic HRESULT Update2(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    IInStream *inStream,\n    const CArchiveDatabaseEx *db,\n    const CObjectVector<CUpdateItem> &updateItems,\n    COutArchive &archive,\n    CArchiveDatabase &newDatabase,\n    ISequentialOutStream *seqOutStream,\n    IArchiveUpdateCallback *updateCallback,\n    const CUpdateOptions &options)\n{\n  UInt64 numSolidFiles = options.NumSolidFiles;\n  if (numSolidFiles == 0)\n    numSolidFiles = 1;\n  /*\n  CMyComPtr<IOutStream> outStream;\n  RINOK(seqOutStream->QueryInterface(IID_IOutStream, (void **)&outStream));\n  if (!outStream)\n    return E_NOTIMPL;\n  */\n\n  UInt64 startBlockSize = db != 0 ? db->ArchiveInfo.StartPosition: 0;\n  if (startBlockSize > 0 && !options.RemoveSfxBlock)\n  {\n    RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));\n  }\n\n  CRecordVector<int> fileIndexToUpdateIndexMap;\n  if (db != 0)\n  {\n    fileIndexToUpdateIndexMap.Reserve(db->Files.Size());\n    for (int i = 0; i < db->Files.Size(); i++)\n      fileIndexToUpdateIndexMap.Add(-1);\n  }\n  int i;\n  for(i = 0; i < updateItems.Size(); i++)\n  {\n    int index = updateItems[i].IndexInArchive;\n    if (index != -1)\n      fileIndexToUpdateIndexMap[index] = i;\n  }\n\n  CRecordVector<int> folderRefs;\n  if (db != 0)\n  {\n    for(i = 0; i < db->Folders.Size(); i++)\n    {\n      CNum indexInFolder = 0;\n      CNum numCopyItems = 0;\n      CNum numUnpackStreams = db->NumUnpackStreamsVector[i];\n      for (CNum fileIndex = db->FolderStartFileIndex[i];\n      indexInFolder < numUnpackStreams; fileIndex++)\n      {\n        if (db->Files[fileIndex].HasStream)\n        {\n          indexInFolder++;\n          int updateIndex = fileIndexToUpdateIndexMap[fileIndex];\n          if (updateIndex >= 0)\n            if (!updateItems[updateIndex].NewData)\n              numCopyItems++;\n        }\n      }\n      if (numCopyItems != numUnpackStreams && numCopyItems != 0)\n        return E_NOTIMPL; // It needs repacking !!!\n      if (numCopyItems > 0)\n        folderRefs.Add(i);\n    }\n    folderRefs.Sort(CompareFolderRefs, (void *)db);\n  }\n\n  ////////////////////////////\n\n  RINOK(archive.Create(seqOutStream, false));\n  RINOK(archive.SkeepPrefixArchiveHeader());\n  UInt64 complexity = 0;\n  for(i = 0; i < folderRefs.Size(); i++)\n    complexity += db->GetFolderFullPackSize(folderRefs[i]);\n  UInt64 inSizeForReduce = 0;\n  for(i = 0; i < updateItems.Size(); i++)\n  {\n    const CUpdateItem &ui = updateItems[i];\n    if (ui.NewData)\n    {\n      complexity += ui.Size;\n      if (numSolidFiles == 1)\n      {\n        if (ui.Size > inSizeForReduce)\n          inSizeForReduce = ui.Size;\n      }\n      else\n        inSizeForReduce += ui.Size;\n    }\n  }\n  RINOK(updateCallback->SetTotal(complexity));\n  complexity = 0;\n  RINOK(updateCallback->SetCompleted(&complexity));\n\n\n  CLocalProgress *lps = new CLocalProgress;\n  CMyComPtr<ICompressProgressInfo> progress = lps;\n  lps->Init(updateCallback, true);\n\n  /////////////////////////////////////////\n  // Write Copy Items\n\n  for(i = 0; i < folderRefs.Size(); i++)\n  {\n    int folderIndex = folderRefs[i];\n    \n    lps->ProgressOffset = complexity;\n    UInt64 packSize = db->GetFolderFullPackSize(folderIndex);\n    RINOK(WriteRange(inStream, archive.SeqStream,\n        db->GetFolderStreamPos(folderIndex, 0), packSize, progress));\n    complexity += packSize;\n    \n    const CFolder &folder = db->Folders[folderIndex];\n    CNum startIndex = db->FolderStartPackStreamIndex[folderIndex];\n    for (int j = 0; j < folder.PackStreams.Size(); j++)\n    {\n      newDatabase.PackSizes.Add(db->PackSizes[startIndex + j]);\n      // newDatabase.PackCRCsDefined.Add(db.PackCRCsDefined[startIndex + j]);\n      // newDatabase.PackCRCs.Add(db.PackCRCs[startIndex + j]);\n    }\n    newDatabase.Folders.Add(folder);\n\n    CNum numUnpackStreams = db->NumUnpackStreamsVector[folderIndex];\n    newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\n\n    CNum indexInFolder = 0;\n    for (CNum fi = db->FolderStartFileIndex[folderIndex];\n        indexInFolder < numUnpackStreams; fi++)\n    {\n      CFileItem file;\n      CFileItem2 file2;\n      db->GetFile(fi, file, file2);\n      if (file.HasStream)\n      {\n        indexInFolder++;\n        int updateIndex = fileIndexToUpdateIndexMap[fi];\n        if (updateIndex >= 0)\n        {\n          const CUpdateItem &ui = updateItems[updateIndex];\n          if (ui.NewProperties)\n          {\n            CFileItem uf;\n            FromUpdateItemToFileItem(ui, uf, file2);\n            uf.Size = file.Size;\n            uf.Crc = file.Crc;\n            uf.CrcDefined = file.CrcDefined;\n            uf.HasStream = file.HasStream;\n            file = uf;\n          }\n        }\n        newDatabase.AddFile(file, file2);\n      }\n    }\n  }\n\n  folderRefs.ClearAndFree();\n  fileIndexToUpdateIndexMap.ClearAndFree();\n\n  /////////////////////////////////////////\n  // Compress New Files\n\n  CObjectVector<CSolidGroup> groups;\n  SplitFilesToGroups(*options.Method, options.UseFilters, options.MaxFilter,\n      updateItems, groups);\n\n  const UInt32 kMinReduceSize = (1 << 16);\n  if (inSizeForReduce < kMinReduceSize)\n    inSizeForReduce = kMinReduceSize;\n\n  for (int groupIndex = 0; groupIndex < groups.Size(); groupIndex++)\n  {\n    const CSolidGroup &group = groups[groupIndex];\n    int numFiles = group.Indices.Size();\n    if (numFiles == 0)\n      continue;\n    CRecordVector<CRefItem> refItems;\n    refItems.Reserve(numFiles);\n    bool sortByType = (numSolidFiles > 1);\n    for (i = 0; i < numFiles; i++)\n      refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType));\n    refItems.Sort(CompareUpdateItems, (void *)&sortByType);\n    \n    CRecordVector<UInt32> indices;\n    indices.Reserve(numFiles);\n\n    for (i = 0; i < numFiles; i++)\n    {\n      UInt32 index = refItems[i].Index;\n      indices.Add(index);\n      /*\n      const CUpdateItem &ui = updateItems[index];\n      CFileItem file;\n      if (ui.NewProperties)\n        FromUpdateItemToFileItem(ui, file);\n      else\n        file = db.Files[ui.IndexInArchive];\n      if (file.IsAnti || file.IsDir)\n        return E_FAIL;\n      newDatabase.Files.Add(file);\n      */\n    }\n    \n    CEncoder encoder(group.Method);\n\n    for (i = 0; i < numFiles;)\n    {\n      UInt64 totalSize = 0;\n      int numSubFiles;\n      UString prevExtension;\n      for (numSubFiles = 0; i + numSubFiles < numFiles &&\n          numSubFiles < numSolidFiles; numSubFiles++)\n      {\n        const CUpdateItem &ui = updateItems[indices[i + numSubFiles]];\n        totalSize += ui.Size;\n        if (totalSize > options.NumSolidBytes)\n          break;\n        if (options.SolidExtension)\n        {\n          UString ext = ui.GetExtension();\n          if (numSubFiles == 0)\n            prevExtension = ext;\n          else\n            if (ext.CompareNoCase(prevExtension) != 0)\n              break;\n        }\n      }\n      if (numSubFiles < 1)\n        numSubFiles = 1;\n\n      CFolderInStream *inStreamSpec = new CFolderInStream;\n      CMyComPtr<ISequentialInStream> solidInStream(inStreamSpec);\n      inStreamSpec->Init(updateCallback, &indices[i], numSubFiles);\n      \n      CFolder folderItem;\n\n      int startPackIndex = newDatabase.PackSizes.Size();\n      RINOK(encoder.Encode(\n          EXTERNAL_CODECS_LOC_VARS\n          solidInStream, NULL, &inSizeForReduce, folderItem,\n          archive.SeqStream, newDatabase.PackSizes, progress));\n\n      for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)\n        lps->OutSize += newDatabase.PackSizes[startPackIndex];\n\n      lps->InSize += folderItem.GetUnpackSize();\n      // for()\n      // newDatabase.PackCRCsDefined.Add(false);\n      // newDatabase.PackCRCs.Add(0);\n      \n      newDatabase.Folders.Add(folderItem);\n      \n      CNum numUnpackStreams = 0;\n      for (int subIndex = 0; subIndex < numSubFiles; subIndex++)\n      {\n        const CUpdateItem &ui = updateItems[indices[i + subIndex]];\n        CFileItem file;\n        CFileItem2 file2;\n        if (ui.NewProperties)\n          FromUpdateItemToFileItem(ui, file, file2);\n        else\n          db->GetFile(ui.IndexInArchive, file, file2);\n        if (file2.IsAnti || file.IsDir)\n          return E_FAIL;\n        \n        /*\n        CFileItem &file = newDatabase.Files[\n              startFileIndexInDatabase + i + subIndex];\n        */\n        if (!inStreamSpec->Processed[subIndex])\n        {\n          continue;\n          // file.Name += L\".locked\";\n        }\n\n        file.Crc = inStreamSpec->CRCs[subIndex];\n        file.Size = inStreamSpec->Sizes[subIndex];\n        if (file.Size != 0)\n        {\n          file.CrcDefined = true;\n          file.HasStream = true;\n          numUnpackStreams++;\n        }\n        else\n        {\n          file.CrcDefined = false;\n          file.HasStream = false;\n        }\n        newDatabase.AddFile(file, file2);\n      }\n      // numUnpackStreams = 0 is very bad case for locked files\n      // v3.13 doesn't understand it.\n      newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);\n      i += numSubFiles;\n    }\n  }\n\n  groups.ClearAndFree();\n\n  {\n    /////////////////////////////////////////\n    // Write Empty Files & Folders\n    \n    CRecordVector<int> emptyRefs;\n    for(i = 0; i < updateItems.Size(); i++)\n    {\n      const CUpdateItem &ui = updateItems[i];\n      if (ui.NewData)\n      {\n        if (ui.HasStream())\n          continue;\n      }\n      else\n        if (ui.IndexInArchive != -1)\n          if (db->Files[ui.IndexInArchive].HasStream)\n            continue;\n      emptyRefs.Add(i);\n    }\n    emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);\n    for (i = 0; i < emptyRefs.Size(); i++)\n    {\n      const CUpdateItem &ui = updateItems[emptyRefs[i]];\n      CFileItem file;\n      CFileItem2 file2;\n      if (ui.NewProperties)\n        FromUpdateItemToFileItem(ui, file, file2);\n      else\n        db->GetFile(ui.IndexInArchive, file, file2);\n      newDatabase.AddFile(file, file2);\n    }\n  }\n    \n  newDatabase.ReserveDown();\n  return S_OK;\n}\n\nHRESULT Update(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    IInStream *inStream,\n    const CArchiveDatabaseEx *db,\n    const CObjectVector<CUpdateItem> &updateItems,\n    COutArchive &archive,\n    CArchiveDatabase &newDatabase,\n    ISequentialOutStream *seqOutStream,\n    IArchiveUpdateCallback *updateCallback,\n    const CUpdateOptions &options)\n{\n  return Update2(\n        EXTERNAL_CODECS_LOC_VARS\n        inStream, db, updateItems,\n        archive, newDatabase, seqOutStream, updateCallback, options);\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/7zUpdate.h",
    "content": "// 7zUpdate.h\n\n#ifndef __7Z_UPDATE_H\n#define __7Z_UPDATE_H\n\n#include \"7zIn.h\"\n#include \"7zOut.h\"\n#include \"7zCompressionMode.h\"\n\n#include \"../IArchive.h\"\n\nnamespace NArchive {\nnamespace N7z {\n\nstruct CUpdateItem\n{\n  int IndexInArchive;\n  int IndexInClient;\n  \n  UInt64 CTime;\n  UInt64 ATime;\n  UInt64 MTime;\n\n  UInt64 Size;\n  UString Name;\n\n  UInt32 Attrib;\n  \n  bool NewData;\n  bool NewProperties;\n\n  bool IsAnti;\n  bool IsDir;\n\n  bool AttribDefined;\n  bool CTimeDefined;\n  bool ATimeDefined;\n  bool MTimeDefined;\n\n  bool HasStream() const { return !IsDir && !IsAnti && Size != 0; }\n\n  CUpdateItem():\n      IsAnti(false),\n      IsDir(false),\n      AttribDefined(false),\n      CTimeDefined(false),\n      ATimeDefined(false),\n      MTimeDefined(false)\n      {}\n  void SetDirStatusFromAttrib() { IsDir = ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0); };\n\n  int GetExtensionPos() const;\n  UString GetExtension() const;\n};\n\nstruct CUpdateOptions\n{\n  const CCompressionMethodMode *Method;\n  const CCompressionMethodMode *HeaderMethod;\n  bool UseFilters;\n  bool MaxFilter;\n\n  CHeaderOptions HeaderOptions;\n\n  UInt64 NumSolidFiles;\n  UInt64 NumSolidBytes;\n  bool SolidExtension;\n  bool RemoveSfxBlock;\n  bool VolumeMode;\n};\n\nHRESULT Update(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    IInStream *inStream,\n    const CArchiveDatabaseEx *db,\n    const CObjectVector<CUpdateItem> &updateItems,\n    COutArchive &archive,\n    CArchiveDatabase &newDatabase,\n    ISequentialOutStream *seqOutStream,\n    IArchiveUpdateCallback *updateCallback,\n    const CUpdateOptions &options);\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\n\n#include \"StdAfx.h\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/7z/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Archive.def",
    "content": "EXPORTS\n  CreateObject PRIVATE\n  GetHandlerProperty PRIVATE\n  GetNumberOfFormats PRIVATE\n  GetHandlerProperty2 PRIVATE\n  CreateObject PRIVATE\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Archive2.def",
    "content": "EXPORTS\n  CreateObject PRIVATE\n  GetHandlerProperty PRIVATE\n  GetNumberOfFormats PRIVATE\n  GetHandlerProperty2 PRIVATE\n  CreateObject PRIVATE\n  GetNumberOfMethods PRIVATE\n  GetMethodProperty PRIVATE\n  SetLargePageMode PRIVATE\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/ArchiveExports.cpp",
    "content": "// ArchiveExports.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../Common/ComTry.h\"\n#include \"../../Common/Types.h\"\n#include \"../../Windows/PropVariant.h\"\n#include \"../Common/RegisterArc.h\"\n\n#include \"IArchive.h\"\n#include \"../ICoder.h\"\n#include \"../IPassword.h\"\n\nstatic const unsigned int kNumArcsMax = 32;\nstatic unsigned int g_NumArcs = 0;\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\nvoid RegisterArc(const CArcInfo *arcInfo)\n{\n  if (g_NumArcs < kNumArcsMax)\n    g_Arcs[g_NumArcs++] = arcInfo;\n}\n\nDEFINE_GUID(CLSID_CArchiveHandler,\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\n\n#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])\n\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\n{\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\n    value->vt = VT_BSTR;\n  return S_OK;\n}\n\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\n{\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\n}\n\nint FindFormatCalssId(const GUID *clsID)\n{\n  GUID cls = *clsID;\n  CLS_ARC_ID_ITEM(cls) = 0;\n  if (cls != CLSID_CArchiveHandler)\n    return -1;\n  Byte id = CLS_ARC_ID_ITEM(*clsID);\n  for (unsigned i = 0; i < g_NumArcs; i++)\n    if (g_Arcs[i]->ClassId == id)\n      return (int)i;\n  return -1;\n}\n\nSTDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)\n{\n  COM_TRY_BEGIN\n  {\n    int needIn = (*iid == IID_IInArchive);\n    int needOut = (*iid == IID_IOutArchive);\n    if (!needIn && !needOut)\n      return E_NOINTERFACE;\n    int formatIndex = FindFormatCalssId(clsid);\n    if (formatIndex < 0)\n      return CLASS_E_CLASSNOTAVAILABLE;\n    \n    const CArcInfo &arc = *g_Arcs[formatIndex];\n    if (needIn)\n    {\n      *outObject = arc.CreateInArchive();\n      ((IInArchive *)*outObject)->AddRef();\n    }\n    else\n    {\n      if (!arc.CreateOutArchive)\n        return CLASS_E_CLASSNOTAVAILABLE;\n      *outObject = arc.CreateOutArchive();\n      ((IOutArchive *)*outObject)->AddRef();\n    }\n  }\n  COM_TRY_END\n  return S_OK;\n}\n\nSTDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)\n{\n  if (formatIndex >= g_NumArcs)\n    return E_INVALIDARG;\n  const CArcInfo &arc = *g_Arcs[formatIndex];\n  NWindows::NCOM::CPropVariant prop;\n  switch(propID)\n  {\n    case NArchive::kName:\n      prop = arc.Name;\n      break;\n    case NArchive::kClassID:\n    {\n      GUID clsId = CLSID_CArchiveHandler;\n      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;\n      return SetPropGUID(clsId, value);\n    }\n    case NArchive::kExtension:\n      if (arc.Ext != 0)\n        prop = arc.Ext;\n      break;\n    case NArchive::kAddExtension:\n      if (arc.AddExt != 0)\n        prop = arc.AddExt;\n      break;\n    case NArchive::kUpdate:\n      prop = (bool)(arc.CreateOutArchive != 0);\n      break;\n    case NArchive::kKeepName:\n      prop = arc.KeepName;\n      break;\n    case NArchive::kStartSignature:\n      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);\n  }\n  prop.Detach(value);\n  return S_OK;\n}\n\nSTDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)\n{\n  return GetHandlerProperty2(0, propID, value);\n}\n\nSTDAPI GetNumberOfFormats(UINT32 *numFormats)\n{\n  *numFormats = g_NumArcs;\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/CoderMixer2.cpp",
    "content": "// CoderMixer2.cpp\n\n#include \"StdAfx.h\"\n\n#include \"CoderMixer2.h\"\n\nnamespace NCoderMixer {\n\nCBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):\n  _srcBindInfo(srcBindInfo)\n{\n  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);\n\n  UInt32  j;\n  for (j = 0; j < NumSrcInStreams; j++)\n  {\n    _srcInToDestOutMap.Add(0);\n    DestOutToSrcInMap.Add(0);\n  }\n  for (j = 0; j < _numSrcOutStreams; j++)\n  {\n    _srcOutToDestInMap.Add(0);\n    _destInToSrcOutMap.Add(0);\n  }\n\n  UInt32 destInOffset = 0;\n  UInt32 destOutOffset = 0;\n  UInt32 srcInOffset = NumSrcInStreams;\n  UInt32 srcOutOffset = _numSrcOutStreams;\n\n  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)\n  {\n    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];\n\n    srcInOffset -= srcCoderInfo.NumInStreams;\n    srcOutOffset -= srcCoderInfo.NumOutStreams;\n    \n    UInt32 j;\n    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)\n    {\n      UInt32 index = srcInOffset + j;\n      _srcInToDestOutMap[index] = destOutOffset;\n      DestOutToSrcInMap[destOutOffset] = index;\n    }\n    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)\n    {\n      UInt32 index = srcOutOffset + j;\n      _srcOutToDestInMap[index] = destInOffset;\n      _destInToSrcOutMap[destInOffset] = index;\n    }\n  }\n}\n\nvoid CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)\n{\n  destBindInfo.Coders.Clear();\n  destBindInfo.BindPairs.Clear();\n  destBindInfo.InStreams.Clear();\n  destBindInfo.OutStreams.Clear();\n\n  int i;\n  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)\n  {\n    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];\n    CCoderStreamsInfo destCoderInfo;\n    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;\n    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;\n    destBindInfo.Coders.Add(destCoderInfo);\n  }\n  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)\n  {\n    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];\n    CBindPair destBindPair;\n    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];\n    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];\n    destBindInfo.BindPairs.Add(destBindPair);\n  }\n  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)\n    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);\n  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)\n    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);\n}\n\nCCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams):\n    NumInStreams(numInStreams),\n    NumOutStreams(numOutStreams)\n{\n  InSizes.Reserve(NumInStreams);\n  InSizePointers.Reserve(NumInStreams);\n  OutSizePointers.Reserve(NumOutStreams);\n  OutSizePointers.Reserve(NumOutStreams);\n}\n\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\n{\n  sizes.Clear();\n  sizePointers.Clear();\n  for(UInt32 i = 0; i < numItems; i++)\n  {\n    if (srcSizes == 0 || srcSizes[i] == NULL)\n    {\n      sizes.Add(0);\n      sizePointers.Add(NULL);\n    }\n    else\n    {\n      sizes.Add(*srcSizes[i]);\n      sizePointers.Add(&sizes.Back());\n    }\n  }\n}\n\nvoid CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,\n      const UInt64 **outSizes)\n{\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\n}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/CoderMixer2.h",
    "content": "// CoderMixer2.h\n\n#ifndef __CODER_MIXER2_H\n#define __CODER_MIXER2_H\n\n#include \"../../../Common/MyVector.h\"\n#include \"../../../Common/Types.h\"\n#include \"../../../Common/MyCom.h\"\n#include \"../../ICoder.h\"\n\nnamespace NCoderMixer {\n\nstruct CBindPair\n{\n  UInt32 InIndex;\n  UInt32 OutIndex;\n};\n\nstruct CCoderStreamsInfo\n{\n  UInt32 NumInStreams;\n  UInt32 NumOutStreams;\n};\n\nstruct CBindInfo\n{\n  CRecordVector<CCoderStreamsInfo> Coders;\n  CRecordVector<CBindPair> BindPairs;\n  CRecordVector<UInt32> InStreams;\n  CRecordVector<UInt32> OutStreams;\n\n  void Clear()\n  {\n    Coders.Clear();\n    BindPairs.Clear();\n    InStreams.Clear();\n    OutStreams.Clear();\n  }\n\n  /*\n  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const\n  {\n    UInt32 numOutStreams = 0;\n    for (UInt32 i = 0; i < coderIndex; i++)\n      numOutStreams += Coders[i].NumOutStreams;\n    return numOutStreams;\n  }\n  */\n\n\n  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const\n  {\n    numInStreams = 0;\n    numOutStreams = 0;\n    for (int i = 0; i < Coders.Size(); i++)\n    {\n      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];\n      numInStreams += coderStreamsInfo.NumInStreams;\n      numOutStreams += coderStreamsInfo.NumOutStreams;\n    }\n  }\n\n  int FindBinderForInStream(UInt32 inStream) const\n  {\n    for (int i = 0; i < BindPairs.Size(); i++)\n      if (BindPairs[i].InIndex == inStream)\n        return i;\n    return -1;\n  }\n  int FindBinderForOutStream(UInt32 outStream) const\n  {\n    for (int i = 0; i < BindPairs.Size(); i++)\n      if (BindPairs[i].OutIndex == outStream)\n        return i;\n    return -1;\n  }\n\n  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const\n  {\n    UInt32 streamIndex = 0;\n    for (UInt32 i = 0; i < coderIndex; i++)\n      streamIndex += Coders[i].NumInStreams;\n    return streamIndex;\n  }\n\n  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const\n  {\n    UInt32 streamIndex = 0;\n    for (UInt32 i = 0; i < coderIndex; i++)\n      streamIndex += Coders[i].NumOutStreams;\n    return streamIndex;\n  }\n\n\n  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,\n      UInt32 &coderStreamIndex) const\n  {\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\n    {\n      UInt32 curSize = Coders[coderIndex].NumInStreams;\n      if (streamIndex < curSize)\n      {\n        coderStreamIndex = streamIndex;\n        return;\n      }\n      streamIndex -= curSize;\n    }\n    throw 1;\n  }\n  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,\n      UInt32 &coderStreamIndex) const\n  {\n    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)\n    {\n      UInt32 curSize = Coders[coderIndex].NumOutStreams;\n      if (streamIndex < curSize)\n      {\n        coderStreamIndex = streamIndex;\n        return;\n      }\n      streamIndex -= curSize;\n    }\n    throw 1;\n  }\n};\n\nclass CBindReverseConverter\n{\n  UInt32 _numSrcOutStreams;\n  NCoderMixer::CBindInfo _srcBindInfo;\n  CRecordVector<UInt32> _srcInToDestOutMap;\n  CRecordVector<UInt32> _srcOutToDestInMap;\n  CRecordVector<UInt32> _destInToSrcOutMap;\npublic:\n  UInt32 NumSrcInStreams;\n  CRecordVector<UInt32> DestOutToSrcInMap;\n\n  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);\n  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);\n};\n\nstruct CCoderInfo2\n{\n  CMyComPtr<ICompressCoder> Coder;\n  CMyComPtr<ICompressCoder2> Coder2;\n  UInt32 NumInStreams;\n  UInt32 NumOutStreams;\n\n  CRecordVector<UInt64> InSizes;\n  CRecordVector<UInt64> OutSizes;\n  CRecordVector<const UInt64 *> InSizePointers;\n  CRecordVector<const UInt64 *> OutSizePointers;\n\n  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\n\n  HRESULT QueryInterface(REFGUID iid, void** pp) const\n  {\n    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;\n    return p->QueryInterface(iid, pp);\n  }\n};\n\nclass CCoderMixer2\n{\npublic:\n  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;\n  virtual void ReInit() = 0;\n  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;\n};\n\n}\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/CoderMixer2MT.cpp",
    "content": "// CoderMixer2MT.cpp\n\n#include \"StdAfx.h\"\n\n#include \"CoderMixer2MT.h\"\n\nnamespace NCoderMixer {\n\nCCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams):\n    CCoderInfo2(numInStreams, numOutStreams)\n{\n  InStreams.Reserve(NumInStreams);\n  InStreamPointers.Reserve(NumInStreams);\n  OutStreams.Reserve(NumOutStreams);\n  OutStreamPointers.Reserve(NumOutStreams);\n}\n\nvoid CCoder2::Execute() { Code(NULL); }\n\nvoid CCoder2::Code(ICompressProgressInfo *progress)\n{\n  InStreamPointers.Clear();\n  OutStreamPointers.Clear();\n  UInt32 i;\n  for (i = 0; i < NumInStreams; i++)\n  {\n    if (InSizePointers[i] != NULL)\n      InSizePointers[i] = &InSizes[i];\n    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);\n  }\n  for (i = 0; i < NumOutStreams; i++)\n  {\n    if (OutSizePointers[i] != NULL)\n      OutSizePointers[i] = &OutSizes[i];\n    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);\n  }\n  if (Coder)\n    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],\n        InSizePointers[0], OutSizePointers[0], progress);\n  else\n    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,\n      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);\n  {\n    int i;\n    for (i = 0; i < InStreams.Size(); i++)\n      InStreams[i].Release();\n    for (i = 0; i < OutStreams.Size(); i++)\n      OutStreams[i].Release();\n  }\n}\n\nstatic void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,\n    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)\n{\n  sizes.Clear();\n  sizePointers.Clear();\n  for(UInt32 i = 0; i < numItems; i++)\n  {\n    if (srcSizes == 0 || srcSizes[i] == NULL)\n    {\n      sizes.Add(0);\n      sizePointers.Add(NULL);\n    }\n    else\n    {\n      sizes.Add(*srcSizes[i]);\n      sizePointers.Add(&sizes.Back());\n    }\n  }\n}\n\n\nvoid CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)\n{\n  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);\n  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);\n}\n\n//////////////////////////////////////\n// CCoderMixer2MT\n\nHRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)\n{\n  _bindInfo = bindInfo;\n  _streamBinders.Clear();\n  for(int i = 0; i < _bindInfo.BindPairs.Size(); i++)\n  {\n    _streamBinders.Add(CStreamBinder());\n    RINOK(_streamBinders.Back().CreateEvents());\n  }\n  return S_OK;\n}\n\nvoid CCoderMixer2MT::AddCoderCommon()\n{\n  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];\n  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);\n  _coders.Add(threadCoderInfo);\n}\n\nvoid CCoderMixer2MT::AddCoder(ICompressCoder *coder)\n{\n  AddCoderCommon();\n  _coders.Back().Coder = coder;\n}\n\nvoid CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)\n{\n  AddCoderCommon();\n  _coders.Back().Coder2 = coder;\n}\n\n\nvoid CCoderMixer2MT::ReInit()\n{\n  for(int i = 0; i < _streamBinders.Size(); i++)\n    _streamBinders[i].ReInit();\n}\n\n\nHRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams)\n{\n  /*\n  if (_coders.Size() != _bindInfo.Coders.Size())\n    throw 0;\n  */\n  int i;\n  for(i = 0; i < _coders.Size(); i++)\n  {\n    CCoder2 &coderInfo = _coders[i];\n    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];\n    coderInfo.InStreams.Clear();\n    UInt32 j;\n    for(j = 0; j < coderStreamsInfo.NumInStreams; j++)\n      coderInfo.InStreams.Add(NULL);\n    coderInfo.OutStreams.Clear();\n    for(j = 0; j < coderStreamsInfo.NumOutStreams; j++)\n      coderInfo.OutStreams.Add(NULL);\n  }\n\n  for(i = 0; i < _bindInfo.BindPairs.Size(); i++)\n  {\n    const CBindPair &bindPair = _bindInfo.BindPairs[i];\n    UInt32 inCoderIndex, inCoderStreamIndex;\n    UInt32 outCoderIndex, outCoderStreamIndex;\n    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);\n    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);\n\n    _streamBinders[i].CreateStreams(\n        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],\n        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);\n  }\n\n  for(i = 0; i < _bindInfo.InStreams.Size(); i++)\n  {\n    UInt32 inCoderIndex, inCoderStreamIndex;\n    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);\n    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];\n  }\n  \n  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)\n  {\n    UInt32 outCoderIndex, outCoderStreamIndex;\n    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);\n    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];\n  }\n  return S_OK;\n}\n\nHRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)\n{\n  for (int i = 0; i < _coders.Size(); i++)\n    if (_coders[i].Result == code)\n      return code;\n  return S_OK;\n}\n\nSTDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,\n      const UInt64 ** /* inSizes */,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 ** /* outSizes */,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress)\n{\n  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||\n      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())\n    return E_INVALIDARG;\n\n  Init(inStreams, outStreams);\n\n  int i;\n  for (i = 0; i < _coders.Size(); i++)\n    if (i != _progressCoderIndex)\n    {\n      RINOK(_coders[i].Create());\n    }\n\n  for (i = 0; i < _coders.Size(); i++)\n    if (i != _progressCoderIndex)\n      _coders[i].Start();\n\n  _coders[_progressCoderIndex].Code(progress);\n\n  for (i = 0; i < _coders.Size(); i++)\n    if (i != _progressCoderIndex)\n      _coders[i].WaitFinish();\n\n  RINOK(ReturnIfError(E_ABORT));\n  RINOK(ReturnIfError(E_OUTOFMEMORY));\n\n  for (i = 0; i < _coders.Size(); i++)\n  {\n    HRESULT result = _coders[i].Result;\n    if (result != S_OK && result != E_FAIL && result != S_FALSE)\n      return result;\n  }\n\n  RINOK(ReturnIfError(S_FALSE));\n\n  for (i = 0; i < _coders.Size(); i++)\n  {\n    HRESULT result = _coders[i].Result;\n    if (result != S_OK)\n      return result;\n  }\n  return S_OK;\n}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/CoderMixer2MT.h",
    "content": "// CoderMixer2MT.h\n\n#ifndef __CODER_MIXER2_MT_H\n#define __CODER_MIXER2_MT_H\n\n#include \"CoderMixer2.h\"\n#include \"../../../Common/MyCom.h\"\n#include \"../../Common/StreamBinder.h\"\n#include \"../../Common/VirtThread.h\"\n\nnamespace NCoderMixer {\n\nstruct CCoder2: public CCoderInfo2, public CVirtThread\n{\n  HRESULT Result;\n  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;\n  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;\n  CRecordVector<ISequentialInStream*> InStreamPointers;\n  CRecordVector<ISequentialOutStream*> OutStreamPointers;\n\n  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);\n  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);\n  virtual void Execute();\n  void Code(ICompressProgressInfo *progress);\n};\n\n\n/*\n  SetBindInfo()\n  for each coder\n    AddCoder[2]()\n  SetProgressIndex(UInt32 coderIndex);\n \n  for each file\n  {\n    ReInit()\n    for each coder\n      SetCoderInfo\n    Code\n  }\n*/\n\nclass CCoderMixer2MT:\n  public ICompressCoder2,\n  public CCoderMixer2,\n  public CMyUnknownImp\n{\n  CBindInfo _bindInfo;\n  CObjectVector<CStreamBinder> _streamBinders;\n  int _progressCoderIndex;\n\n  void AddCoderCommon();\n  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);\n  HRESULT ReturnIfError(HRESULT code);\npublic:\n  CObjectVector<CCoder2> _coders;\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress);\n\n  HRESULT SetBindInfo(const CBindInfo &bindInfo);\n  void AddCoder(ICompressCoder *coder);\n  void AddCoder2(ICompressCoder2 *coder);\n  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }\n\n  void ReInit();\n  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)\n    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }\n  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const\n    {  return _streamBinders[binderIndex].ProcessedSize; }\n};\n\n}\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/CrossThreadProgress.cpp",
    "content": "// CrossThreadProgress.cpp\n\n#include \"StdAfx.h\"\n\n#include \"CrossThreadProgress.h\"\n\nSTDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\n{\n  InSize = inSize;\n  OutSize = outSize;\n  ProgressEvent.Set();\n  WaitEvent.Lock();\n  return Result;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/CrossThreadProgress.h",
    "content": "// CrossThreadProgress.h\n\n#ifndef __CROSSTHREADPROGRESS_H\n#define __CROSSTHREADPROGRESS_H\n\n#include \"../../ICoder.h\"\n#include \"../../../Windows/Synchronization.h\"\n#include \"../../../Common/MyCom.h\"\n\nclass CCrossThreadProgress:\n  public ICompressProgressInfo,\n  public CMyUnknownImp\n{\npublic:\n  const UInt64 *InSize;\n  const UInt64 *OutSize;\n  HRESULT Result;\n  NWindows::NSynchronization::CAutoResetEvent ProgressEvent;\n  NWindows::NSynchronization::CAutoResetEvent WaitEvent;\n\n  HRes Create()\n  {\n    RINOK(ProgressEvent.CreateIfNotCreated());\n    return WaitEvent.CreateIfNotCreated();\n  }\n  void Init()\n  {\n    ProgressEvent.Reset();\n    WaitEvent.Reset();\n  }\n\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/DummyOutStream.cpp",
    "content": "// DummyOutStream.cpp\n\n#include \"StdAfx.h\"\n\n#include \"DummyOutStream.h\"\n\nSTDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize;\n  HRESULT result;\n  if(!_stream)\n  {\n    realProcessedSize = size;\n    result = S_OK;\n  }\n  else\n    result = _stream->Write(data, size, &realProcessedSize);\n  _size += realProcessedSize;\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return result;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/DummyOutStream.h",
    "content": "// DummyOutStream.h\n\n#ifndef __DUMMYOUTSTREAM_H\n#define __DUMMYOUTSTREAM_H\n\n#include \"../../IStream.h\"\n#include \"Common/MyCom.h\"\n\nclass CDummyOutStream:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\n  CMyComPtr<ISequentialOutStream> _stream;\n  UInt64 _size;\npublic:\n  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }\n  void ReleaseStream() { _stream.Release(); }\n  void Init() { _size = 0; }\n  MY_UNKNOWN_IMP\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  UInt64 GetSize() const { return _size; }\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/HandlerOut.cpp",
    "content": "// HandlerOut.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../../Common/StringToInt.h\"\n\n#include \"../../../Windows/PropVariant.h\"\n\n#ifdef COMPRESS_MT\n#include \"../../../Windows/System.h\"\n#endif\n\n#include \"../../ICoder.h\"\n\n#include \"../Common/ParseProperties.h\"\n\n#include \"HandlerOut.h\"\n\nusing namespace NWindows;\n\nnamespace NArchive {\n\nstatic const wchar_t *kCopyMethod = L\"Copy\";\nstatic const wchar_t *kLZMAMethodName = L\"LZMA\";\nstatic const wchar_t *kLZMA2MethodName = L\"LZMA2\";\nstatic const wchar_t *kBZip2MethodName = L\"BZip2\";\nstatic const wchar_t *kPpmdMethodName = L\"PPMd\";\nstatic const wchar_t *kDeflateMethodName = L\"Deflate\";\nstatic const wchar_t *kDeflate64MethodName = L\"Deflate64\";\n\nstatic const wchar_t *kLzmaMatchFinderX1 = L\"HC4\";\nstatic const wchar_t *kLzmaMatchFinderX5 = L\"BT4\";\n\nstatic const UInt32 kLzmaAlgoX1 = 0;\nstatic const UInt32 kLzmaAlgoX5 = 1;\n\nstatic const UInt32 kLzmaDicSizeX1 = 1 << 16;\nstatic const UInt32 kLzmaDicSizeX3 = 1 << 20;\nstatic const UInt32 kLzmaDicSizeX5 = 1 << 24;\nstatic const UInt32 kLzmaDicSizeX7 = 1 << 25;\nstatic const UInt32 kLzmaDicSizeX9 = 1 << 26;\n\nstatic const UInt32 kLzmaFastBytesX1 = 32;\nstatic const UInt32 kLzmaFastBytesX7 = 64;\n\nstatic const UInt32 kPpmdMemSizeX1 = (1 << 22);\nstatic const UInt32 kPpmdMemSizeX5 = (1 << 24);\nstatic const UInt32 kPpmdMemSizeX7 = (1 << 26);\nstatic const UInt32 kPpmdMemSizeX9 = (192 << 20);\n\nstatic const UInt32 kPpmdOrderX1 = 4;\nstatic const UInt32 kPpmdOrderX5 = 6;\nstatic const UInt32 kPpmdOrderX7 = 16;\nstatic const UInt32 kPpmdOrderX9 = 32;\n\nstatic const UInt32 kDeflateAlgoX1 = 0;\nstatic const UInt32 kDeflateAlgoX5 = 1;\n\nstatic const UInt32 kDeflateFastBytesX1 = 32;\nstatic const UInt32 kDeflateFastBytesX7 = 64;\nstatic const UInt32 kDeflateFastBytesX9 = 128;\n\nstatic const UInt32 kDeflatePassesX1 = 1;\nstatic const UInt32 kDeflatePassesX7 = 3;\nstatic const UInt32 kDeflatePassesX9 = 10;\n\nstatic const UInt32 kBZip2NumPassesX1 = 1;\nstatic const UInt32 kBZip2NumPassesX7 = 2;\nstatic const UInt32 kBZip2NumPassesX9 = 7;\n\nstatic const UInt32 kBZip2DicSizeX1 = 100000;\nstatic const UInt32 kBZip2DicSizeX3 = 500000;\nstatic const UInt32 kBZip2DicSizeX5 = 900000;\n\nstatic const wchar_t *kDefaultMethodName = kLZMAMethodName;\n\nstatic const wchar_t *kLzmaMatchFinderForHeaders = L\"BT2\";\nstatic const UInt32 kDictionaryForHeaders = 1 << 20;\nstatic const UInt32 kNumFastBytesForHeaders = 273;\nstatic const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5;\n\nstatic bool AreEqual(const UString &methodName, const wchar_t *s)\n  { return (methodName.CompareNoCase(s) == 0); }\n\nstatic inline bool IsLZMAMethod(const UString &methodName)\n{\n  return\n    AreEqual(methodName, kLZMAMethodName) ||\n    AreEqual(methodName, kLZMA2MethodName);\n}\n\nstatic inline bool IsBZip2Method(const UString &methodName)\n  { return AreEqual(methodName, kBZip2MethodName); }\n\nstatic inline bool IsPpmdMethod(const UString &methodName)\n  { return AreEqual(methodName, kPpmdMethodName); }\n\nstatic inline bool IsDeflateMethod(const UString &methodName)\n{\n  return\n    AreEqual(methodName, kDeflateMethodName) ||\n    AreEqual(methodName, kDeflate64MethodName);\n}\n\nstruct CNameToPropID\n{\n  PROPID PropID;\n  VARTYPE VarType;\n  const wchar_t *Name;\n};\n\nCNameToPropID g_NameToPropID[] =\n{\n  { NCoderPropID::kOrder, VT_UI4, L\"O\" },\n  { NCoderPropID::kPosStateBits, VT_UI4, L\"PB\" },\n  { NCoderPropID::kLitContextBits, VT_UI4, L\"LC\" },\n  { NCoderPropID::kLitPosBits, VT_UI4, L\"LP\" },\n  { NCoderPropID::kEndMarker, VT_BOOL, L\"eos\" },\n\n  { NCoderPropID::kNumPasses, VT_UI4, L\"Pass\" },\n  { NCoderPropID::kNumFastBytes, VT_UI4, L\"fb\" },\n  { NCoderPropID::kMatchFinderCycles, VT_UI4, L\"mc\" },\n  { NCoderPropID::kAlgorithm, VT_UI4, L\"a\" },\n  { NCoderPropID::kMatchFinder, VT_BSTR, L\"mf\" },\n  { NCoderPropID::kNumThreads, VT_UI4, L\"mt\" }\n};\n\nstatic bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp)\n{\n  if (varType == srcProp.vt)\n  {\n    destProp = srcProp;\n    return true;\n  }\n  if (varType == VT_UI1)\n  {\n    if (srcProp.vt == VT_UI4)\n    {\n      UInt32 value = srcProp.ulVal;\n      if (value > 0xFF)\n        return false;\n      destProp = (Byte)value;\n      return true;\n    }\n  }\n  else if (varType == VT_BOOL)\n  {\n    bool res;\n    if (SetBoolProperty(res, srcProp) != S_OK)\n      return false;\n    destProp = res;\n    return true;\n  }\n  return false;\n}\n    \nstatic int FindPropIdFromStringName(const UString &name)\n{\n  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)\n    if (name.CompareNoCase(g_NameToPropID[i].Name) == 0)\n      return i;\n  return -1;\n}\n\nstatic void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID,\n    const NWindows::NCOM::CPropVariant &value)\n{\n  for (int j = 0; j < oneMethodInfo.Props.Size(); j++)\n    if (oneMethodInfo.Props[j].Id == propID)\n      return;\n  CProp prop;\n  prop.Id = propID;\n  prop.Value = value;\n  oneMethodInfo.Props.Add(prop);\n}\n\nvoid COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo\n    #ifdef COMPRESS_MT\n    , UInt32 numThreads\n    #endif\n    )\n{\n  UInt32 level = _level;\n  if (oneMethodInfo.MethodName.IsEmpty())\n    oneMethodInfo.MethodName = kDefaultMethodName;\n  \n  if (IsLZMAMethod(oneMethodInfo.MethodName))\n  {\n    UInt32 dicSize =\n      (level >= 9 ? kLzmaDicSizeX9 :\n      (level >= 7 ? kLzmaDicSizeX7 :\n      (level >= 5 ? kLzmaDicSizeX5 :\n      (level >= 3 ? kLzmaDicSizeX3 :\n                    kLzmaDicSizeX1))));\n    \n    UInt32 algo =\n      (level >= 5 ? kLzmaAlgoX5 :\n                    kLzmaAlgoX1);\n    \n    UInt32 fastBytes =\n      (level >= 7 ? kLzmaFastBytesX7 :\n                    kLzmaFastBytesX1);\n    \n    const wchar_t *matchFinder =\n      (level >= 5 ? kLzmaMatchFinderX5 :\n                    kLzmaMatchFinderX1);\n    \n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);\n    #ifdef COMPRESS_MT\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\n    #endif\n  }\n  else if (IsDeflateMethod(oneMethodInfo.MethodName))\n  {\n    UInt32 fastBytes =\n      (level >= 9 ? kDeflateFastBytesX9 :\n      (level >= 7 ? kDeflateFastBytesX7 :\n                    kDeflateFastBytesX1));\n    \n    UInt32 numPasses =\n      (level >= 9 ? kDeflatePassesX9 :\n      (level >= 7 ? kDeflatePassesX7 :\n                    kDeflatePassesX1));\n    \n    UInt32 algo =\n      (level >= 5 ? kDeflateAlgoX5 :\n                    kDeflateAlgoX1);\n    \n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\n  }\n  else if (IsBZip2Method(oneMethodInfo.MethodName))\n  {\n    UInt32 numPasses =\n      (level >= 9 ? kBZip2NumPassesX9 :\n      (level >= 7 ? kBZip2NumPassesX7 :\n                    kBZip2NumPassesX1));\n    \n    UInt32 dicSize =\n      (level >= 5 ? kBZip2DicSizeX5 :\n      (level >= 3 ? kBZip2DicSizeX3 :\n                    kBZip2DicSizeX1));\n    \n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);\n    #ifdef COMPRESS_MT\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);\n    #endif\n  }\n  else if (IsPpmdMethod(oneMethodInfo.MethodName))\n  {\n    UInt32 useMemSize =\n      (level >= 9 ? kPpmdMemSizeX9 :\n      (level >= 7 ? kPpmdMemSizeX7 :\n      (level >= 5 ? kPpmdMemSizeX5 :\n                    kPpmdMemSizeX1)));\n    \n    UInt32 order =\n      (level >= 9 ? kPpmdOrderX9 :\n      (level >= 7 ? kPpmdOrderX7 :\n      (level >= 5 ? kPpmdOrderX5 :\n                    kPpmdOrderX1)));\n    \n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize);\n    SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order);\n  }\n}\n\nstatic void SplitParams(const UString &srcString, UStringVector &subStrings)\n{\n  subStrings.Clear();\n  UString name;\n  int len = srcString.Length();\n  if (len == 0)\n    return;\n  for (int i = 0; i < len; i++)\n  {\n    wchar_t c = srcString[i];\n    if (c == L':')\n    {\n      subStrings.Add(name);\n      name.Empty();\n    }\n    else\n      name += c;\n  }\n  subStrings.Add(name);\n}\n\nstatic void SplitParam(const UString &param, UString &name, UString &value)\n{\n  int eqPos = param.Find(L'=');\n  if (eqPos >= 0)\n  {\n    name = param.Left(eqPos);\n    value = param.Mid(eqPos + 1);\n    return;\n  }\n  for(int i = 0; i < param.Length(); i++)\n  {\n    wchar_t c = param[i];\n    if (c >= L'0' && c <= L'9')\n    {\n      name = param.Left(i);\n      value = param.Mid(i);\n      return;\n    }\n  }\n  name = param;\n}\n\nHRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value)\n{\n  CProp prop;\n  if (name.CompareNoCase(L\"D\") == 0 ||\n      name.CompareNoCase(L\"MEM\") == 0)\n  {\n    UInt32 dicSize;\n    RINOK(ParsePropDictionaryValue(value, dicSize));\n    prop.Id = (name.CompareNoCase(L\"D\") == 0) ?\n        NCoderPropID::kDictionarySize :\n        NCoderPropID::kUsedMemorySize;\n    prop.Value = dicSize;\n  }\n  else\n  {\n    int index = FindPropIdFromStringName(name);\n    if (index < 0)\n      return E_INVALIDARG;\n    \n    const CNameToPropID &nameToPropID = g_NameToPropID[index];\n    prop.Id = nameToPropID.PropID;\n    \n    NCOM::CPropVariant propValue;\n    \n    if (nameToPropID.VarType == VT_BSTR)\n      propValue = value;\n    else if (nameToPropID.VarType == VT_BOOL)\n    {\n      bool res;\n      if (!StringToBool(value, res))\n        return E_INVALIDARG;\n      propValue = res;\n    }\n    else\n    {\n      UInt32 number;\n      if (ParseStringToUInt32(value, number) == value.Length())\n        propValue = number;\n      else\n        propValue = value;\n    }\n    \n    if (!ConvertProperty(propValue, nameToPropID.VarType, prop.Value))\n      return E_INVALIDARG;\n  }\n  oneMethodInfo.Props.Add(prop);\n  return S_OK;\n}\n\nHRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString)\n{\n  UStringVector params;\n  SplitParams(srcString, params);\n  if (params.Size() > 0)\n    oneMethodInfo.MethodName = params[0];\n  for (int i = 1; i < params.Size(); i++)\n  {\n    const UString &param = params[i];\n    UString name, value;\n    SplitParam(param, name, value);\n    RINOK(SetParam(oneMethodInfo, name, value));\n  }\n  return S_OK;\n}\n\nHRESULT COutHandler::SetSolidSettings(const UString &s)\n{\n  UString s2 = s;\n  s2.MakeUpper();\n  for (int i = 0; i < s2.Length();)\n  {\n    const wchar_t *start = ((const wchar_t *)s2) + i;\n    const wchar_t *end;\n    UInt64 v = ConvertStringToUInt64(start, &end);\n    if (start == end)\n    {\n      if (s2[i++] != 'E')\n        return E_INVALIDARG;\n      _solidExtension = true;\n      continue;\n    }\n    i += (int)(end - start);\n    if (i == s2.Length())\n      return E_INVALIDARG;\n    wchar_t c = s2[i++];\n    switch(c)\n    {\n      case 'F':\n        if (v < 1)\n          v = 1;\n        _numSolidFiles = v;\n        break;\n      case 'B':\n        _numSolidBytes = v;\n        _numSolidBytesDefined = true;\n        break;\n      case 'K':\n        _numSolidBytes = (v << 10);\n        _numSolidBytesDefined = true;\n        break;\n      case 'M':\n        _numSolidBytes = (v << 20);\n        _numSolidBytesDefined = true;\n        break;\n      case 'G':\n        _numSolidBytes = (v << 30);\n        _numSolidBytesDefined = true;\n        break;\n      default:\n        return E_INVALIDARG;\n    }\n  }\n  return S_OK;\n}\n\nHRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)\n{\n  bool isSolid;\n  switch(value.vt)\n  {\n    case VT_EMPTY:\n      isSolid = true;\n      break;\n    case VT_BOOL:\n      isSolid = (value.boolVal != VARIANT_FALSE);\n      break;\n    case VT_BSTR:\n      if (StringToBool(value.bstrVal, isSolid))\n        break;\n      return SetSolidSettings(value.bstrVal);\n    default:\n      return E_INVALIDARG;\n  }\n  if (isSolid)\n    InitSolid();\n  else\n    _numSolidFiles = 1;\n  return S_OK;\n}\n\nvoid COutHandler::Init()\n{\n  _removeSfxBlock = false;\n  _compressHeaders = true;\n  _encryptHeadersSpecified = false;\n  _encryptHeaders = false;\n  \n  WriteCTime = false;\n  WriteATime = false;\n  WriteMTime = true;\n  \n  #ifdef COMPRESS_MT\n  _numThreads = NWindows::NSystem::GetNumberOfProcessors();\n  #endif\n  \n  _level = 5;\n  _autoFilter = true;\n  _volumeMode = false;\n  _crcSize = 4;\n  InitSolid();\n}\n\nvoid COutHandler::BeforeSetProperty()\n{\n  Init();\n  #ifdef COMPRESS_MT\n  numProcessors = NSystem::GetNumberOfProcessors();\n  #endif\n\n  mainDicSize = 0xFFFFFFFF;\n  mainDicMethodIndex = 0xFFFFFFFF;\n  minNumber = 0;\n  _crcSize = 4;\n}\n\nHRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)\n{\n  UString name = nameSpec;\n  name.MakeUpper();\n  if (name.IsEmpty())\n    return E_INVALIDARG;\n  \n  if (name[0] == 'X')\n  {\n    name.Delete(0);\n    _level = 9;\n    return ParsePropValue(name, value, _level);\n  }\n  \n  if (name[0] == L'S')\n  {\n    name.Delete(0);\n    if (name.IsEmpty())\n      return SetSolidSettings(value);\n    if (value.vt != VT_EMPTY)\n      return E_INVALIDARG;\n    return SetSolidSettings(name);\n  }\n  \n  if (name == L\"CRC\")\n  {\n    _crcSize = 4;\n    name.Delete(0, 3);\n    return ParsePropValue(name, value, _crcSize);\n  }\n  \n  UInt32 number;\n  int index = ParseStringToUInt32(name, number);\n  UString realName = name.Mid(index);\n  if (index == 0)\n  {\n    if(name.Left(2).CompareNoCase(L\"MT\") == 0)\n    {\n      #ifdef COMPRESS_MT\n      RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));\n      #endif\n      return S_OK;\n    }\n    if (name.CompareNoCase(L\"RSFX\") == 0)  return SetBoolProperty(_removeSfxBlock, value);\n    if (name.CompareNoCase(L\"F\") == 0) return SetBoolProperty(_autoFilter, value);\n    if (name.CompareNoCase(L\"HC\") == 0) return SetBoolProperty(_compressHeaders, value);\n    if (name.CompareNoCase(L\"HCF\") == 0)\n    {\n      bool compressHeadersFull = true;\n      RINOK(SetBoolProperty(compressHeadersFull, value));\n      if (!compressHeadersFull)\n        return E_INVALIDARG;\n      return S_OK;\n    }\n    if (name.CompareNoCase(L\"HE\") == 0)\n    {\n      RINOK(SetBoolProperty(_encryptHeaders, value));\n      _encryptHeadersSpecified = true;\n      return S_OK;\n    }\n    if (name.CompareNoCase(L\"TC\") == 0) return SetBoolProperty(WriteCTime, value);\n    if (name.CompareNoCase(L\"TA\") == 0) return SetBoolProperty(WriteATime, value);\n    if (name.CompareNoCase(L\"TM\") == 0) return SetBoolProperty(WriteMTime, value);\n    if (name.CompareNoCase(L\"V\") == 0) return SetBoolProperty(_volumeMode, value);\n    number = 0;\n  }\n  if (number > 10000)\n    return E_FAIL;\n  if (number < minNumber)\n    return E_INVALIDARG;\n  number -= minNumber;\n  for(int j = _methods.Size(); j <= (int)number; j++)\n  {\n    COneMethodInfo oneMethodInfo;\n    _methods.Add(oneMethodInfo);\n  }\n  \n  COneMethodInfo &oneMethodInfo = _methods[number];\n  \n  if (realName.Length() == 0)\n  {\n    if (value.vt != VT_BSTR)\n      return E_INVALIDARG;\n    \n    RINOK(SetParams(oneMethodInfo, value.bstrVal));\n  }\n  else\n  {\n    CProp prop;\n    if (realName.Left(1).CompareNoCase(L\"D\") == 0)\n    {\n      UInt32 dicSize;\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize));\n      prop.Id = NCoderPropID::kDictionarySize;\n      prop.Value = dicSize;\n      if (number <= mainDicMethodIndex)\n        mainDicSize = dicSize;\n    }\n    else if (realName.Left(1).CompareNoCase(L\"C\") == 0)\n    {\n      UInt32 blockSize;\n      RINOK(ParsePropDictionaryValue(realName.Mid(1), value, blockSize));\n      prop.Id = NCoderPropID::kBlockSize;\n      prop.Value = blockSize;\n    }\n    else if (realName.Left(3).CompareNoCase(L\"MEM\") == 0)\n    {\n      UInt32 dicSize;\n      RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize));\n      prop.Id = NCoderPropID::kUsedMemorySize;\n      prop.Value = dicSize;\n      if (number <= mainDicMethodIndex)\n        mainDicSize = dicSize;\n    }\n    else\n    {\n      int index = FindPropIdFromStringName(realName);\n      if (index < 0)\n        return E_INVALIDARG;\n      const CNameToPropID &nameToPropID = g_NameToPropID[index];\n      prop.Id = nameToPropID.PropID;\n      if (!ConvertProperty(value, nameToPropID.VarType, prop.Value))\n        return E_INVALIDARG;\n    }\n    oneMethodInfo.Props.Add(prop);\n  }\n  return S_OK;\n}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/HandlerOut.h",
    "content": "// HandlerOut.h\n\n#ifndef __HANDLER_OUT_H\n#define __HANDLER_OUT_H\n\n#include \"../../../Common/MyString.h\"\n#include \"../../Common/MethodProps.h\"\n\nnamespace NArchive {\n\nstruct COneMethodInfo\n{\n  CObjectVector<CProp> Props;\n  UString MethodName;\n};\n\nclass COutHandler\n{\npublic:\n  HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);\n  \n  HRESULT SetSolidSettings(const UString &s);\n  HRESULT SetSolidSettings(const PROPVARIANT &value);\n\n  #ifdef COMPRESS_MT\n  UInt32 _numThreads;\n  #endif\n\n  UInt32 _crcSize;\n\n  CObjectVector<COneMethodInfo> _methods;\n  bool _removeSfxBlock;\n  \n  UInt64 _numSolidFiles;\n  UInt64 _numSolidBytes;\n  bool _numSolidBytesDefined;\n  bool _solidExtension;\n\n  bool _compressHeaders;\n  bool _encryptHeadersSpecified;\n  bool _encryptHeaders;\n\n  bool WriteCTime;\n  bool WriteATime;\n  bool WriteMTime;\n\n  bool _autoFilter;\n  UInt32 _level;\n\n  bool _volumeMode;\n\n  HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value);\n  HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);\n\n  void SetCompressionMethod2(COneMethodInfo &oneMethodInfo\n      #ifdef COMPRESS_MT\n      , UInt32 numThreads\n      #endif\n      );\n\n  void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }\n  void InitSolidSize()  { _numSolidBytes = (UInt64)(Int64)(-1); }\n  void InitSolid()\n  {\n    InitSolidFiles();\n    InitSolidSize();\n    _solidExtension = false;\n    _numSolidBytesDefined = false;\n  }\n\n  void Init();\n\n  COutHandler() { Init(); }\n\n  void BeforeSetProperty();\n\n  UInt32 minNumber;\n  UInt32 numProcessors;\n  UInt32 mainDicSize;\n  UInt32 mainDicMethodIndex;\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/InStreamWithCRC.cpp",
    "content": "// InStreamWithCRC.cpp\n\n#include \"StdAfx.h\"\n\n#include \"InStreamWithCRC.h\"\n\nSTDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize;\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\n  _size += realProcessedSize;\n  if (size > 0 && realProcessedSize == 0)\n    _wasFinished = true;\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return result;\n}\n\nSTDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize;\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\n  if (size > 0 && realProcessedSize == 0)\n    _wasFinished = true;\n  _size += realProcessedSize;\n  _crc = CrcUpdate(_crc, data, realProcessedSize);\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return result;\n}\n\nSTDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\n{\n  if (seekOrigin != STREAM_SEEK_SET || offset != 0)\n    return E_FAIL;\n  _size = 0;\n  _crc = CRC_INIT_VAL;\n  return _stream->Seek(offset, seekOrigin, newPosition);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/InStreamWithCRC.h",
    "content": "// InStreamWithCRC.h\n\n#ifndef __INSTREAMWITHCRC_H\n#define __INSTREAMWITHCRC_H\n\n#include \"../../../Common/MyCom.h\"\n#include \"../../IStream.h\"\n\nextern \"C\"\n{\n#include \"../../../../C/7zCrc.h\"\n}\n\nclass CSequentialInStreamWithCRC:\n  public ISequentialInStream,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\nprivate:\n  CMyComPtr<ISequentialInStream> _stream;\n  UInt64 _size;\n  UInt32 _crc;\n  bool _wasFinished;\npublic:\n  void SetStream(ISequentialInStream *stream) { _stream = stream;  }\n  void Init()\n  {\n    _size = 0;\n    _wasFinished = false;\n    _crc = CRC_INIT_VAL;\n  }\n  void ReleaseStream() { _stream.Release(); }\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\n  UInt64 GetSize() const { return _size; }\n  bool WasFinished() const { return _wasFinished; }\n};\n\nclass CInStreamWithCRC:\n  public IInStream,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP1(IInStream)\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\nprivate:\n  CMyComPtr<IInStream> _stream;\n  UInt64 _size;\n  UInt32 _crc;\n  bool _wasFinished;\npublic:\n  void SetStream(IInStream *stream) { _stream = stream;  }\n  void Init()\n  {\n    _size = 0;\n    _wasFinished = false;\n    _crc = CRC_INIT_VAL;\n  }\n  void ReleaseStream() { _stream.Release(); }\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\n  UInt64 GetSize() const { return _size; }\n  bool WasFinished() const { return _wasFinished; }\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/ItemNameUtils.cpp",
    "content": "// Archive/Common/ItemNameUtils.cpp\n\n#include \"StdAfx.h\"\n\n#include \"ItemNameUtils.h\"\n\nnamespace NArchive {\nnamespace NItemName {\n\nstatic const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;\nstatic const wchar_t kDirDelimiter = L'/';\n\nUString MakeLegalName(const UString &name)\n{\n  UString zipName = name;\n  zipName.Replace(kOSDirDelimiter, kDirDelimiter);\n  return zipName;\n}\n\nUString GetOSName(const UString &name)\n{\n  UString newName = name;\n  newName.Replace(kDirDelimiter, kOSDirDelimiter);\n  return newName;\n}\n\nUString GetOSName2(const UString &name)\n{\n  if (name.IsEmpty())\n    return UString();\n  UString newName = GetOSName(name);\n  if (newName[newName.Length() - 1] == kOSDirDelimiter)\n    newName.Delete(newName.Length() - 1);\n  return newName;\n}\n\nbool HasTailSlash(const AString &name, UINT codePage)\n{\n  if (name.IsEmpty())\n    return false;\n  LPCSTR prev =\n  #ifdef _WIN32\n    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);\n  #else\n    (LPCSTR)(name) + (name.Length() - 1);\n  #endif\n  return (*prev == '/');\n}\n\n#ifndef _WIN32\nUString WinNameToOSName(const UString &name)\n{\n  UString newName = name;\n  newName.Replace(L'\\\\', kOSDirDelimiter);\n  return newName;\n}\n#endif\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/ItemNameUtils.h",
    "content": "// Archive/Common/ItemNameUtils.h\n\n#ifndef __ARCHIVE_ITEMNAMEUTILS_H\n#define __ARCHIVE_ITEMNAMEUTILS_H\n\n#include \"../../../Common/MyString.h\"\n\nnamespace NArchive {\nnamespace NItemName {\n\n  UString MakeLegalName(const UString &name);\n  UString GetOSName(const UString &name);\n  UString GetOSName2(const UString &name);\n  bool HasTailSlash(const AString &name, UINT codePage);\n\n  #ifdef _WIN32\n  inline UString WinNameToOSName(const UString &name)  { return name; }\n  #else\n  UString WinNameToOSName(const UString &name);\n  #endif\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/MultiStream.cpp",
    "content": "// MultiStream.cpp\n\n#include \"StdAfx.h\"\n\n#include \"MultiStream.h\"\n\nSTDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  if(processedSize != NULL)\n    *processedSize = 0;\n  while(_streamIndex < Streams.Size() && size > 0)\n  {\n    CSubStreamInfo &s = Streams[_streamIndex];\n    if (_pos == s.Size)\n    {\n      _streamIndex++;\n      _pos = 0;\n      continue;\n    }\n    RINOK(s.Stream->Seek(s.Pos + _pos, STREAM_SEEK_SET, 0));\n    UInt32 sizeToRead = UInt32(MyMin((UInt64)size, s.Size - _pos));\n    UInt32 realProcessed;\n    HRESULT result = s.Stream->Read(data, sizeToRead, &realProcessed);\n    data = (void *)((Byte *)data + realProcessed);\n    size -= realProcessed;\n    if(processedSize != NULL)\n      *processedSize += realProcessed;\n    _pos += realProcessed;\n    _seekPos += realProcessed;\n    RINOK(result);\n    break;\n  }\n  return S_OK;\n}\n  \nSTDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin,\n    UInt64 *newPosition)\n{\n  UInt64 newPos;\n  switch(seekOrigin)\n  {\n    case STREAM_SEEK_SET:\n      newPos = offset;\n      break;\n    case STREAM_SEEK_CUR:\n      newPos = _seekPos + offset;\n      break;\n    case STREAM_SEEK_END:\n      newPos = _totalLength + offset;\n      break;\n    default:\n      return STG_E_INVALIDFUNCTION;\n  }\n  _seekPos = 0;\n  for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++)\n  {\n    UInt64 size = Streams[_streamIndex].Size;\n    if (newPos < _seekPos + size)\n    {\n      _pos = newPos - _seekPos;\n      _seekPos += _pos;\n      if (newPosition != 0)\n        *newPosition = newPos;\n      return S_OK;\n    }\n    _seekPos += size;\n  }\n  if (newPos == _seekPos)\n  {\n    if (newPosition != 0)\n      *newPosition = newPos;\n    return S_OK;\n  }\n  return E_FAIL;\n}\n\n\n/*\nclass COutVolumeStream:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\n  int _volIndex;\n  UInt64 _volSize;\n  UInt64 _curPos;\n  CMyComPtr<ISequentialOutStream> _volumeStream;\n  COutArchive _archive;\n  CCRC _crc;\n\npublic:\n  MY_UNKNOWN_IMP\n\n  CFileItem _file;\n  CUpdateOptions _options;\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\n  void Init(IArchiveUpdateCallback2 *volumeCallback,\n      const UString &name)\n  {\n    _file.Name = name;\n    _file.IsStartPosDefined = true;\n    _file.StartPos = 0;\n    \n    VolumeCallback = volumeCallback;\n    _volIndex = 0;\n    _volSize = 0;\n  }\n  \n  HRESULT Flush();\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\nHRESULT COutVolumeStream::Flush()\n{\n  if (_volumeStream)\n  {\n    _file.UnPackSize = _curPos;\n    _file.FileCRC = _crc.GetDigest();\n    RINOK(WriteVolumeHeader(_archive, _file, _options));\n    _archive.Close();\n    _volumeStream.Release();\n    _file.StartPos += _file.UnPackSize;\n  }\n  return S_OK;\n}\n*/\n\n/*\nSTDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  if(processedSize != NULL)\n    *processedSize = 0;\n  while(size > 0)\n  {\n    if (_streamIndex >= Streams.Size())\n    {\n      CSubStreamInfo subStream;\n      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));\n      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));\n      subStream.Pos = 0;\n      Streams.Add(subStream);\n      continue;\n    }\n    CSubStreamInfo &subStream = Streams[_streamIndex];\n    if (_offsetPos >= subStream.Size)\n    {\n      _offsetPos -= subStream.Size;\n      _streamIndex++;\n      continue;\n    }\n    if (_offsetPos != subStream.Pos)\n    {\n      CMyComPtr<IOutStream> outStream;\n      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\n      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\n      subStream.Pos = _offsetPos;\n    }\n\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);\n    UInt32 realProcessed;\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\n    data = (void *)((Byte *)data + realProcessed);\n    size -= realProcessed;\n    subStream.Pos += realProcessed;\n    _offsetPos += realProcessed;\n    _absPos += realProcessed;\n    if (_absPos > _length)\n      _length = _absPos;\n    if(processedSize != NULL)\n      *processedSize += realProcessed;\n    if (subStream.Pos == subStream.Size)\n    {\n      _streamIndex++;\n      _offsetPos = 0;\n    }\n    if (realProcessed != curSize && realProcessed == 0)\n      return E_FAIL;\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\n{\n  if(seekOrigin >= 3)\n    return STG_E_INVALIDFUNCTION;\n  switch(seekOrigin)\n  {\n    case STREAM_SEEK_SET:\n      _absPos = offset;\n      break;\n    case STREAM_SEEK_CUR:\n      _absPos += offset;\n      break;\n    case STREAM_SEEK_END:\n      _absPos = _length + offset;\n      break;\n  }\n  _offsetPos = _absPos;\n  _streamIndex = 0;\n  return S_OK;\n}\n*/\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/MultiStream.h",
    "content": "// MultiStream.h\n\n#ifndef __MULTISTREAM_H\n#define __MULTISTREAM_H\n\n#include \"../../../Common/MyCom.h\"\n#include \"../../../Common/MyVector.h\"\n#include \"../../Archive/IArchive.h\"\n\nclass CMultiStream:\n  public IInStream,\n  public CMyUnknownImp\n{\n  int _streamIndex;\n  UInt64 _pos;\n  UInt64 _seekPos;\n  UInt64 _totalLength;\npublic:\n  struct CSubStreamInfo\n  {\n    CMyComPtr<IInStream> Stream;\n    UInt64 Pos;\n    UInt64 Size;\n  };\n  CObjectVector<CSubStreamInfo> Streams;\n  void Init()\n  {\n    _streamIndex = 0;\n    _pos = 0;\n    _seekPos = 0;\n    _totalLength = 0;\n    for (int i = 0; i < Streams.Size(); i++)\n      _totalLength += Streams[i].Size;\n  }\n\n  MY_UNKNOWN_IMP1(IInStream)\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\n};\n\n/*\nclass COutMultiStream:\n  public IOutStream,\n  public CMyUnknownImp\n{\n  int _streamIndex; // required stream\n  UInt64 _offsetPos; // offset from start of _streamIndex index\n  UInt64 _absPos;\n  UInt64 _length;\n\n  struct CSubStreamInfo\n  {\n    CMyComPtr<ISequentialOutStream> Stream;\n    UInt64 Size;\n    UInt64 Pos;\n };\n  CObjectVector<CSubStreamInfo> Streams;\npublic:\n  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\n  void Init()\n  {\n    _streamIndex = 0;\n    _offsetPos = 0;\n    _absPos = 0;\n    _length = 0;\n  }\n\n  MY_UNKNOWN_IMP1(IOutStream)\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\n};\n*/\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp",
    "content": "// OutStreamWithCRC.cpp\n\n#include \"StdAfx.h\"\n\n#include \"OutStreamWithCRC.h\"\n\nSTDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize;\n  HRESULT result;\n  if(!_stream)\n  {\n    realProcessedSize = size;\n    result = S_OK;\n  }\n  else\n    result = _stream->Write(data, size, &realProcessedSize);\n  if (_calculate)\n    _crc = CrcUpdate(_crc, data, realProcessedSize);\n  _size += realProcessedSize;\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return result;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/OutStreamWithCRC.h",
    "content": "// OutStreamWithCRC.h\n\n#ifndef __OUT_STREAM_WITH_CRC_H\n#define __OUT_STREAM_WITH_CRC_H\n\n#include \"../../../Common/MyCom.h\"\n#include \"../../IStream.h\"\n\nextern \"C\"\n{\n#include \"../../../../C/7zCrc.h\"\n}\n\nclass COutStreamWithCRC:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\n  CMyComPtr<ISequentialOutStream> _stream;\n  UInt64 _size;\n  UInt32 _crc;\n  bool _calculate;\npublic:\n  MY_UNKNOWN_IMP\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\n  void ReleaseStream() { _stream.Release(); }\n  void Init(bool calculate = true)\n  {\n    _size = 0;\n    _calculate = calculate;\n    _crc = CRC_INIT_VAL;\n  }\n  void InitCRC() { _crc = CRC_INIT_VAL; }\n  UInt64 GetSize() const { return _size; }\n  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/ParseProperties.cpp",
    "content": "// ParseProperties.cpp\n\n#include \"StdAfx.h\"\n\n#include \"ParseProperties.h\"\n\n#include \"Common/StringToInt.h\"\n#include \"Common/MyCom.h\"\n\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\n{\n  if (prop.vt == VT_UI4)\n  {\n    if (!name.IsEmpty())\n      return E_INVALIDARG;\n    resValue = prop.ulVal;\n  }\n  else if (prop.vt == VT_EMPTY)\n  {\n    if(!name.IsEmpty())\n    {\n      const wchar_t *start = name;\n      const wchar_t *end;\n      UInt64 v = ConvertStringToUInt64(start, &end);\n      if (end - start != name.Length())\n        return E_INVALIDARG;\n      resValue = (UInt32)v;\n    }\n  }\n  else\n    return E_INVALIDARG;\n  return S_OK;\n}\n\nstatic const int kLogarithmicSizeLimit = 32;\nstatic const wchar_t kByteSymbol = L'B';\nstatic const wchar_t kKiloByteSymbol = L'K';\nstatic const wchar_t kMegaByteSymbol = L'M';\n\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize)\n{\n  UString srcString = srcStringSpec;\n  srcString.MakeUpper();\n\n  const wchar_t *start = srcString;\n  const wchar_t *end;\n  UInt64 number = ConvertStringToUInt64(start, &end);\n  int numDigits = (int)(end - start);\n  if (numDigits == 0 || srcString.Length() > numDigits + 1)\n    return E_INVALIDARG;\n  if (srcString.Length() == numDigits)\n  {\n    if (number >= kLogarithmicSizeLimit)\n      return E_INVALIDARG;\n    dicSize = (UInt32)1 << (int)number;\n    return S_OK;\n  }\n  switch (srcString[numDigits])\n  {\n    case kByteSymbol:\n      if (number >= ((UInt64)1 << kLogarithmicSizeLimit))\n        return E_INVALIDARG;\n      dicSize = (UInt32)number;\n      break;\n    case kKiloByteSymbol:\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 10)))\n        return E_INVALIDARG;\n      dicSize = (UInt32)(number << 10);\n      break;\n    case kMegaByteSymbol:\n      if (number >= ((UInt64)1 << (kLogarithmicSizeLimit - 20)))\n        return E_INVALIDARG;\n      dicSize = (UInt32)(number << 20);\n      break;\n    default:\n      return E_INVALIDARG;\n  }\n  return S_OK;\n}\n\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue)\n{\n  if (name.IsEmpty())\n  {\n    if (prop.vt == VT_UI4)\n    {\n      UInt32 logDicSize = prop.ulVal;\n      if (logDicSize >= 32)\n        return E_INVALIDARG;\n      resValue = (UInt32)1 << logDicSize;\n      return S_OK;\n    }\n    if (prop.vt == VT_BSTR)\n      return ParsePropDictionaryValue(prop.bstrVal, resValue);\n    return E_INVALIDARG;\n  }\n  return ParsePropDictionaryValue(name, resValue);\n}\n\nbool StringToBool(const UString &s, bool &res)\n{\n  if (s.IsEmpty() || s.CompareNoCase(L\"ON\") == 0 || s.Compare(L\"+\") == 0)\n  {\n    res = true;\n    return true;\n  }\n  if (s.CompareNoCase(L\"OFF\") == 0 || s.Compare(L\"-\") == 0)\n  {\n    res = false;\n    return true;\n  }\n  return false;\n}\n\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value)\n{\n  switch(value.vt)\n  {\n    case VT_EMPTY:\n      dest = true;\n      return S_OK;\n    case VT_BOOL:\n      dest = (value.boolVal != VARIANT_FALSE);\n      return S_OK;\n    /*\n    case VT_UI4:\n      dest = (value.ulVal != 0);\n      break;\n    */\n    case VT_BSTR:\n      return StringToBool(value.bstrVal, dest) ?  S_OK : E_INVALIDARG;\n  }\n  return E_INVALIDARG;\n}\n\nint ParseStringToUInt32(const UString &srcString, UInt32 &number)\n{\n  const wchar_t *start = srcString;\n  const wchar_t *end;\n  UInt64 number64 = ConvertStringToUInt64(start, &end);\n  if (number64 > 0xFFFFFFFF)\n  {\n    number = 0;\n    return 0;\n  }\n  number = (UInt32)number64;\n  return (int)(end - start);\n}\n\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads)\n{\n  if (name.IsEmpty())\n  {\n    switch(prop.vt)\n    {\n      case VT_UI4:\n        numThreads = prop.ulVal;\n        break;\n      default:\n      {\n        bool val;\n        RINOK(SetBoolProperty(val, prop));\n        numThreads = (val ? defaultNumThreads : 1);\n        break;\n      }\n    }\n  }\n  else\n  {\n    UInt32 number;\n    int index = ParseStringToUInt32(name, number);\n    if (index != name.Length())\n      return E_INVALIDARG;\n    numThreads = number;\n  }\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/ParseProperties.h",
    "content": "// ParseProperties.h\n\n#ifndef __PARSEPROPERTIES_H\n#define __PARSEPROPERTIES_H\n\n#include \"Common/MyString.h\"\n#include \"Common/Types.h\"\n\nHRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\nHRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);\nHRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);\n\nbool StringToBool(const UString &s, bool &res);\nHRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);\nint ParseStringToUInt32(const UString &srcString, UInt32 &number);\nHRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Common/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/DllExports2.cpp",
    "content": "// DLLExports.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../Common/MyInitGuid.h\"\n#include \"../../Common/ComTry.h\"\n#include \"../../Common/Types.h\"\n#include \"../../Windows/PropVariant.h\"\n#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\nextern \"C\"\n{\n#include \"../../../C/Alloc.h\"\n}\n#endif\n\n#include \"IArchive.h\"\n#include \"../ICoder.h\"\n#include \"../IPassword.h\"\n\nHINSTANCE g_hInstance;\n#ifndef _UNICODE\n#ifdef _WIN32\nbool g_IsNT = false;\nstatic bool IsItWindowsNT()\n{\n  OSVERSIONINFO versionInfo;\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\n  if (!::GetVersionEx(&versionInfo))\n    return false;\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\n}\n#endif\n#endif\n\nextern \"C\"\nBOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)\n{\n  if (dwReason == DLL_PROCESS_ATTACH)\n  {\n    g_hInstance = hInstance;\n    #ifndef _UNICODE\n    #ifdef _WIN32\n    g_IsNT = IsItWindowsNT();\n    #endif\n    #endif\n  }\n  return TRUE;\n}\n\nDEFINE_GUID(CLSID_CArchiveHandler,\n0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);\n\nstatic const UInt16 kDecodeId = 0x2790;\n\nDEFINE_GUID(CLSID_CCodec,\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\n\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);\nSTDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);\n\nSTDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)\n{\n  // COM_TRY_BEGIN\n  *outObject = 0;\n  if (*iid == IID_ICompressCoder || *iid == IID_ICompressCoder2 || *iid == IID_ICompressFilter)\n  {\n    return CreateCoder(clsid, iid, outObject);\n  }\n  else\n  {\n    return CreateArchiver(clsid, iid, outObject);\n  }\n  // COM_TRY_END\n}\n\nSTDAPI SetLargePageMode()\n{\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\n  SetLargePageSize();\n  #endif\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/IArchive.h",
    "content": "// IArchive.h\n\n#ifndef __IARCHIVE_H\n#define __IARCHIVE_H\n\n#include \"../IStream.h\"\n#include \"../IProgress.h\"\n#include \"../PropID.h\"\n\n#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)\n#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)\n\nnamespace NFileTimeType\n{\n  enum EEnum\n  {\n    kWindows,\n    kUnix,\n    kDOS\n  };\n}\n\nnamespace NArchive\n{\n  enum\n  {\n    kName = 0,\n    kClassID,\n    kExtension,\n    kAddExtension,\n    kUpdate,\n    kKeepName,\n    kStartSignature,\n    kFinishSignature,\n    kAssociate\n  };\n\n  namespace NExtract\n  {\n    namespace NAskMode\n    {\n      enum\n      {\n        kExtract = 0,\n        kTest,\n        kSkip\n      };\n    }\n    namespace NOperationResult\n    {\n      enum\n      {\n        kOK = 0,\n        kUnSupportedMethod,\n        kDataError,\n        kCRCError\n      };\n    }\n  }\n  namespace NUpdate\n  {\n    namespace NOperationResult\n    {\n      enum\n      {\n        kOK = 0,\n        kError\n      };\n    }\n  }\n}\n\n#define INTERFACE_IArchiveOpenCallback(x) \\\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) x; \\\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) x; \\\n\nARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)\n{\n  INTERFACE_IArchiveOpenCallback(PURE);\n};\n\n\n#define INTERFACE_IArchiveExtractCallback(x) \\\n  INTERFACE_IProgress(x) \\\n  /* GetStream OUT: S_OK - OK, S_FALSE - skeep this file */ \\\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream,  Int32 askExtractMode) x; \\\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode) x; \\\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) x; \\\n\nARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)\n{\n  INTERFACE_IArchiveExtractCallback(PURE)\n};\n\n\n#define INTERFACE_IArchiveOpenVolumeCallback(x) \\\n  STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) x; \\\n  STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) x; \\\n\nARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)\n{\n  INTERFACE_IArchiveOpenVolumeCallback(PURE);\n};\n\n\nARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)\n{\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;\n};\n\n\nARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)\n{\n  STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;\n};\n\n\n/*\nIInArchive::Extract:\n  indices must be sorted\n  numItems = 0xFFFFFFFF means \"all files\"\n  testMode != 0 means \"test files without writing to outStream\"\n*/\n\n#define INTERFACE_IInArchive(x) \\\n  STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \\\n  STDMETHOD(Close)() x; \\\n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \\\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \\\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \\\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \\\n  STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \\\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \\\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;\n\nARCHIVE_INTERFACE(IInArchive, 0x60)\n{\n  INTERFACE_IInArchive(PURE)\n};\n\n\n#define INTERFACE_IArchiveUpdateCallback(x) \\\n  INTERFACE_IProgress(x); \\\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,  \\\n      Int32 *newData, /*1 - new data, 0 - old data */ \\\n      Int32 *newProperties, /* 1 - new properties, 0 - old properties */ \\\n      UInt32 *indexInArchive /* -1 if there is no in archive, or if doesn't matter */ \\\n      )  x; \\\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \\\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) x; \\\n  STDMETHOD(SetOperationResult)(Int32 operationResult) x; \\\n\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)\n{\n  INTERFACE_IArchiveUpdateCallback(PURE);\n};\n\n#define INTERFACE_IArchiveUpdateCallback2(x) \\\n  INTERFACE_IArchiveUpdateCallback(x) \\\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) x; \\\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) x; \\\n\nARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)\n{\n  INTERFACE_IArchiveUpdateCallback2(PURE);\n};\n\n\n#define INTERFACE_IOutArchive(x) \\\n  STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \\\n  STDMETHOD(GetFileTimeType)(UInt32 *type) x;\n\nARCHIVE_INTERFACE(IOutArchive, 0xA0)\n{\n  INTERFACE_IOutArchive(PURE)\n};\n\n\nARCHIVE_INTERFACE(ISetProperties, 0x03)\n{\n  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;\n};\n\n\n#define IMP_IInArchive_GetProp(k) \\\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\n    const STATPROPSTG &srcItem = k[index]; \\\n    *propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \\\n\n#define IMP_IInArchive_GetProp_WITH_NAME(k) \\\n  (UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \\\n    { if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \\\n    const STATPROPSTG &srcItem = k[index]; \\\n    *propID = srcItem.propid; *varType = srcItem.vt; \\\n    if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \\\n\n#define IMP_IInArchive_Props \\\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)\n\n#define IMP_IInArchive_Props_WITH_NAME \\\n  STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \\\n    { *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \\\n  STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)\n\n\n#define IMP_IInArchive_ArcProps \\\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)\n\n#define IMP_IInArchive_ArcProps_WITH_NAME \\\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\n    { *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \\\n  STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kArcProps)\n\n#define IMP_IInArchive_ArcProps_NO \\\n  STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \\\n    { *numProperties = 0; return S_OK; } \\\n  STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \\\n    { return E_NOTIMPL; } \\\n  STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \\\n    { value->vt = VT_EMPTY; return S_OK; }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Lzma/LzmaArcRegister.cpp",
    "content": "// LzmaArcRegister.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../Common/RegisterArc.h\"\n\n#include \"LzmaHandler.h\"\n\nstatic IInArchive *CreateArc() { return new NArchive::NLzma::CHandler;  }\n\nstatic CArcInfo g_ArcInfo =\n  { L\"Lzma\", L\"lzma lzma86\", 0, 0xA, {0 }, 0, true, CreateArc, NULL };\n\nREGISTER_ARC(Lzma)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.cpp",
    "content": "// LzmaFiltersDecode.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LzmaFiltersDecode.h\"\n\nnamespace NArchive {\nnamespace NLzma {\n\nstatic const UInt64 k_LZMA = 0x030101;\nstatic const UInt64 k_BCJ = 0x03030103;\n  \nHRESULT CDecoder::Code(\n    DECL_EXTERNAL_CODECS_LOC_VARS\n    const CHeader &block,\n    ISequentialInStream *inStream, ISequentialOutStream *outStream,\n    UInt64 *inProcessedSize, ICompressProgressInfo *progress)\n{\n  *inProcessedSize = (UInt64)(Int64)-1;\n\n  if (block.FilterMethod > 1)\n    return E_NOTIMPL;\n\n  if (!_lzmaDecoder)\n  {\n    RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_LZMA, _lzmaDecoder, false));\n    if (_lzmaDecoder == 0)\n      return E_NOTIMPL;\n  }\n\n  {\n    CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;\n    _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);\n    if (!setDecoderProperties)\n      return E_NOTIMPL;\n    RINOK(setDecoderProperties->SetDecoderProperties2(block.LzmaProps, 5));\n  }\n\n  bool filteredMode = (block.FilterMethod == 1);\n\n  CMyComPtr<ICompressSetOutStream> setOutStream;\n\n  if (filteredMode)\n  {\n    if (!_bcjStream)\n    {\n      CMyComPtr<ICompressCoder> coder;\n      RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_BCJ, coder, false));\n      if (!coder)\n        return E_NOTIMPL;\n      coder.QueryInterface(IID_ISequentialOutStream, &_bcjStream);\n      if (!_bcjStream)\n        return E_NOTIMPL;\n    }\n\n    _bcjStream.QueryInterface(IID_ICompressSetOutStream, &setOutStream);\n    if (!setOutStream)\n      return E_NOTIMPL;\n    RINOK(setOutStream->SetOutStream(outStream));\n    outStream = _bcjStream;\n  }\n\n  const UInt64 *unpackSize = block.HasUnpackSize() ? &block.UnpackSize : NULL;\n  RINOK(_lzmaDecoder->Code(inStream, outStream, NULL, unpackSize, progress));\n\n  if (filteredMode)\n  {\n    CMyComPtr<IOutStreamFlush> flush;\n    _bcjStream.QueryInterface(IID_IOutStreamFlush, &flush);\n    if (flush)\n    {\n      RINOK(flush->Flush());\n    }\n    RINOK(setOutStream->ReleaseOutStream());\n  }\n\n  CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;\n  _lzmaDecoder.QueryInterface(IID_ICompressGetInStreamProcessedSize, &getInStreamProcessedSize);\n  if (getInStreamProcessedSize)\n  {\n    RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(inProcessedSize));\n  }\n  return S_OK;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Lzma/LzmaFiltersDecode.h",
    "content": "// LzmaFiltersDecode.h\n\n#ifndef __LZMA_FILTERS_DECODE_H\n#define __LZMA_FILTERS_DECODE_H\n\n#include \"../../Common/CreateCoder.h\"\n\n#include \"LzmaItem.h\"\n\nnamespace NArchive {\nnamespace NLzma {\n\nclass CDecoder\n{\n  CMyComPtr<ICompressCoder> _lzmaDecoder;\n  CMyComPtr<ISequentialOutStream> _bcjStream;\npublic:\n  HRESULT Code(DECL_EXTERNAL_CODECS_LOC_VARS\n      const CHeader &block,\n      ISequentialInStream *inStream, ISequentialOutStream *outStream,\n      UInt64 *inProcessedSize, ICompressProgressInfo *progress);\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Lzma/LzmaHandler.cpp",
    "content": "// LzmaHandler.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LzmaHandler.h\"\n\n#include \"Common/Defs.h\"\n#include \"Common/StringConvert.h\"\n#include \"Common/ComTry.h\"\n#include \"Common/IntToString.h\"\n\n#include \"Windows/PropVariant.h\"\n\n#include \"../../Common/ProgressUtils.h\"\n#include \"../../Common/StreamUtils.h\"\n#include \"../Common/DummyOutStream.h\"\n\n#include \"LzmaFiltersDecode.h\"\n\nnamespace NArchive {\nnamespace NLzma {\n\nSTATPROPSTG kProps[] =\n{\n  { NULL, kpidSize, VT_UI8},\n  { NULL, kpidPackSize, VT_UI8},\n  { NULL, kpidMethod, VT_UI1}\n};\n\nIMP_IInArchive_Props\nIMP_IInArchive_ArcProps_NO\n\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\n{\n  *numItems = 1;\n  return S_OK;\n}\n\nstatic void ConvertUInt32ToString(UInt32 value, wchar_t *s)\n{\n  ConvertUInt64ToString(value, s + MyStringLen(s));\n}\n\nstatic void DictSizeToString(UInt32 value, wchar_t *s)\n{\n  for (int i = 0; i <= 31; i++)\n    if ((UInt32(1) << i) == value)\n    {\n      ConvertUInt32ToString(i, s);\n      return;\n    }\n  wchar_t c = L'b';\n  if ((value & ((1 << 20) - 1)) == 0)\n  {\n    value >>= 20;\n    c = L'm';\n  }\n  else if ((value & ((1 << 10) - 1)) == 0)\n  {\n    value >>= 10;\n    c = L'k';\n  }\n  ConvertUInt32ToString(value, s);\n  int p = MyStringLen(s);\n  s[p++] = c;\n  s[p++] = L'\\0';\n}\n\nstatic void MyStrCat(wchar_t *d, const wchar_t *s)\n{\n  MyStringCopy(d + MyStringLen(d), s);\n}\n\nSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)\n{\n  if (index != 0)\n    return E_INVALIDARG;\n  NWindows::NCOM::CPropVariant propVariant;\n  switch(propID)\n  {\n    case kpidSize:\n      if (m_StreamInfo.HasUnpackSize())\n        propVariant = (UInt64)m_StreamInfo.UnpackSize;\n      break;\n    case kpidPackSize:\n      propVariant = (UInt64)m_PackSize;\n      break;\n    case kpidMethod:\n    {\n      wchar_t s[64];\n      s[0] = '\\0';\n      if (m_StreamInfo.IsThereFilter)\n      {\n        const wchar_t *f;\n        if (m_StreamInfo.FilterMethod == 0)\n          f = L\"Copy\";\n        else if (m_StreamInfo.FilterMethod == 1)\n          f = L\"BCJ\";\n        else\n          f = L\"Unknown\";\n        MyStrCat(s, f);\n        MyStrCat(s, L\" \");\n      }\n      MyStrCat(s, L\"LZMA:\");\n      DictSizeToString(m_StreamInfo.GetDicSize(), s);\n      propVariant = s;\n      break;\n    }\n  }\n  propVariant.Detach(value);\n  return S_OK;\n}\n\nSTDMETHODIMP CHandler::Open(IInStream *inStream,\n    const UInt64 * /* maxCheckStartPosition */,\n    IArchiveOpenCallback * /* openArchiveCallback */)\n{\n  {\n    RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));\n\n    HRESULT res = ReadStreamHeader(inStream, m_StreamInfo);\n    if (res != S_OK)\n      return S_FALSE;\n    \n    Byte b;\n    RINOK(ReadStream_FALSE(inStream, &b, 1));\n    if (b != 0)\n      return S_FALSE;\n\n    UInt64 endPos;\n    RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));\n    m_PackSize = endPos - m_StreamStartPosition - m_StreamInfo.GetHeaderSize();\n\n    m_Stream = inStream;\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP CHandler::Close()\n{\n  m_Stream.Release();\n  return S_OK;\n}\n\n\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\n    Int32 _aTestMode, IArchiveExtractCallback *extractCallback)\n{\n  COM_TRY_BEGIN\n  bool allFilesMode = (numItems == UInt32(-1));\n  if (!allFilesMode)\n  {\n    if (numItems == 0)\n      return S_OK;\n    if (numItems != 1)\n      return E_INVALIDARG;\n    if (indices[0] != 0)\n      return E_INVALIDARG;\n  }\n\n  bool testMode = (_aTestMode != 0);\n\n  RINOK(extractCallback->SetTotal(m_PackSize));\n    \n  UInt64 currentTotalPacked = 0;\n\n  CDummyOutStream *outStreamSpec = new CDummyOutStream;\n  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\n\n  {\n    CMyComPtr<ISequentialOutStream> realOutStream;\n    Int32 askMode = testMode ?\n        NArchive::NExtract::NAskMode::kTest :\n        NArchive::NExtract::NAskMode::kExtract;\n    \n    RINOK(extractCallback->GetStream(0, &realOutStream, askMode));\n\n    outStreamSpec->SetStream(realOutStream);\n    outStreamSpec->Init();\n    if(!testMode && !realOutStream)\n      return S_OK;\n    extractCallback->PrepareOperation(askMode);\n  }\n  \n  CLocalProgress *lps = new CLocalProgress;\n  CMyComPtr<ICompressProgressInfo> progress = lps;\n  lps->Init(extractCallback, true);\n\n  CDecoder decoder;\n  RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL));\n  UInt64 streamPos = m_StreamStartPosition;\n  Int32 opRes = NArchive::NExtract::NOperationResult::kOK;\n  bool firstItem = true;\n  for (;;)\n  {\n    CHeader st;\n    HRESULT result = ReadStreamHeader(m_Stream, st);\n    if (result != S_OK)\n    {\n      if (firstItem)\n        return E_FAIL;\n      break;\n    }\n    firstItem = false;\n\n    lps->OutSize = outStreamSpec->GetSize();\n    lps->InSize = currentTotalPacked;\n    RINOK(lps->SetCur());\n    \n    streamPos += st.GetHeaderSize();\n    UInt64 packProcessed;\n\n    {\n      result = decoder.Code(\n          EXTERNAL_CODECS_VARS\n          st, m_Stream, outStream, &packProcessed, progress);\n      if (result == E_NOTIMPL)\n      {\n        opRes = NArchive::NExtract::NOperationResult::kUnSupportedMethod;\n        break;\n      }\n      if (result == S_FALSE)\n      {\n        opRes = NArchive::NExtract::NOperationResult::kDataError;\n        break;\n      }\n      RINOK(result);\n    }\n\n    if (packProcessed == (UInt64)(Int64)-1)\n      break;\n    RINOK(m_Stream->Seek(streamPos + packProcessed, STREAM_SEEK_SET, NULL));\n    currentTotalPacked += packProcessed;\n    streamPos += packProcessed;\n  }\n  outStream.Release();\n  return extractCallback->SetOperationResult(opRes);\n  COM_TRY_END\n}\n\nIMPL_ISetCompressCodecsInfo\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Lzma/LzmaHandler.h",
    "content": "// Lzma/Handler.h\n\n#ifndef __GZIP_HANDLER_H\n#define __GZIP_HANDLER_H\n\n#include \"Common/MyCom.h\"\n\n#include \"../IArchive.h\"\n#include \"../../Common/CreateCoder.h\"\n\n#include \"LzmaIn.h\"\n\nnamespace NArchive {\nnamespace NLzma {\n\n// const UInt64 k_LZMA = 0x030101;\n\nclass CHandler:\n  public IInArchive,\n  PUBLIC_ISetCompressCodecsInfo\n  public CMyUnknownImp\n{\npublic:\n  MY_QUERYINTERFACE_BEGIN\n  MY_QUERYINTERFACE_ENTRY(IInArchive)\n  QUERY_ENTRY_ISetCompressCodecsInfo\n  MY_QUERYINTERFACE_END\n  MY_ADDREF_RELEASE\n\n  STDMETHOD(Open)(IInStream *inStream,\n      const UInt64 *maxCheckStartPosition,\n      IArchiveOpenCallback *openArchiveCallback);\n  STDMETHOD(Close)();\n  \n  STDMETHOD(GetNumberOfItems)(UInt32 *numItems);\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID,  PROPVARIANT *value);\n  STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems,\n      Int32 testMode, IArchiveExtractCallback *extractCallback);\n\n  STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);\n\n  STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties);\n  STDMETHOD(GetPropertyInfo)(UInt32 index,\n      BSTR *name, PROPID *propID, VARTYPE *varType);\n\n  STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties);\n  STDMETHOD(GetArchivePropertyInfo)(UInt32 index,\n      BSTR *name, PROPID *propID, VARTYPE *varType);\n\n  UString GetMethodString();\npublic:\n  CHandler() {  }\n\nprivate:\n  CHeader m_StreamInfo;\n  UInt64 m_StreamStartPosition;\n  UInt64 m_PackSize;\n\n  CMyComPtr<IInStream> m_Stream;\n\n  DECL_EXTERNAL_CODECS_VARS\n\n  DECL_ISetCompressCodecsInfo\n\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Lzma/LzmaIn.cpp",
    "content": "// Archive/LzmaIn.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LzmaIn.h\"\n\n#include \"../../Common/StreamUtils.h\"\n\nnamespace NArchive {\nnamespace NLzma {\n \nstatic bool CheckDictSize(const Byte *p)\n{\n  UInt32 dicSize = GetUi32(p);\n  int i;\n  for (i = 1; i <= 30; i++)\n    if (dicSize == ((UInt32)2 << i) || dicSize == ((UInt32)3 << i))\n      return true;\n  return false;\n}\n\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &block)\n{\n  Byte sig[5 + 9];\n  RINOK(ReadStream_FALSE(inStream, sig, 5 + 8));\n\n  const Byte kMaxProp0Val = 5 * 5 * 9 - 1;\n  if (sig[0] > kMaxProp0Val)\n    return S_FALSE;\n\n  for (int i = 0; i < 5; i++)\n    block.LzmaProps[i] = sig[i];\n  \n  block.IsThereFilter = false;\n  block.FilterMethod = 0;\n\n  if (!CheckDictSize(sig + 1))\n  {\n    if (sig[0] > 1 || sig[1] > kMaxProp0Val)\n      return S_FALSE;\n    block.IsThereFilter = true;\n    block.FilterMethod = sig[0];\n    for (int i = 0; i < 5; i++)\n      block.LzmaProps[i] = sig[i + 1];\n    if (!CheckDictSize(block.LzmaProps + 1))\n      return S_FALSE;\n    RINOK(ReadStream_FALSE(inStream, sig + 5 + 8, 1));\n  }\n  UInt32 unpOffset = 5 + (block.IsThereFilter ? 1 : 0);\n  block.UnpackSize = GetUi64(sig + unpOffset);\n  if (block.HasUnpackSize() && block.UnpackSize >= ((UInt64)1 << 56))\n    return S_FALSE;\n  return S_OK;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Lzma/LzmaIn.h",
    "content": "// Archive/LzmaIn.h\n\n#ifndef __ARCHIVE_LZMA_IN_H\n#define __ARCHIVE_LZMA_IN_H\n\n#include \"LzmaItem.h\"\n#include \"../../IStream.h\"\n\nnamespace NArchive {\nnamespace NLzma {\n\nHRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &st);\n\n}}\n  \n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Lzma/LzmaItem.h",
    "content": "// Archive/LzmaItem.h\n\n#ifndef __ARCHIVE_LZMA_ITEM_H\n#define __ARCHIVE_LZMA_ITEM_H\n\n#include \"Common/Types.h\"\n\n#include \"../../../../C/CpuArch.h\"\n\nnamespace NArchive {\nnamespace NLzma {\n\nstruct CHeader\n{\n  UInt64 UnpackSize;\n  bool IsThereFilter;\n  Byte FilterMethod;\n  Byte LzmaProps[5];\n\n  UInt32 GetDicSize() const { return GetUi32(LzmaProps + 1); }\n  bool HasUnpackSize() const { return (UnpackSize != (UInt64)(Int64)-1);  }\n  unsigned GetHeaderSize() const { return 5 + 8 + (IsThereFilter ? 1 : 0); }\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Lzma/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Split/SplitHandler.cpp",
    "content": "// SplitHandler.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Common/ComTry.h\"\n#include \"Common/Defs.h\"\n#include \"Common/NewHandler.h\"\n#include \"Common/StringConvert.h\"\n\n#include \"Windows/PropVariant.h\"\n#include \"Windows/Time.h\"\n\n#include \"../../Common/ProgressUtils.h\"\n\n#include \"../../Compress/CopyCoder.h\"\n\n#include \"../Common/ItemNameUtils.h\"\n#include \"../Common/MultiStream.h\"\n\n#include \"SplitHandler.h\"\n\nusing namespace NWindows;\nusing namespace NTime;\n\nnamespace NArchive {\nnamespace NSplit {\n\nSTATPROPSTG kProps[] =\n{\n  { NULL, kpidPath, VT_BSTR},\n  { NULL, kpidSize, VT_UI8},\n  { NULL, kpidPackSize, VT_UI8},\n};\n\nIMP_IInArchive_Props\nIMP_IInArchive_ArcProps_NO\n\nclass CSeqName\n{\npublic:\n  UString _unchangedPart;\n  UString _changedPart;\n  bool _splitStyle;\n  UString GetNextName()\n  {\n    UString newName;\n    if (_splitStyle)\n    {\n      int i;\n      int numLetters = _changedPart.Length();\n      for (i = numLetters - 1; i >= 0; i--)\n      {\n        wchar_t c = _changedPart[i];\n        if (c == 'z')\n        {\n          c = 'a';\n          newName = c + newName;\n          continue;\n        }\n        else if (c == 'Z')\n        {\n          c = 'A';\n          newName = c + newName;\n          continue;\n        }\n        c++;\n        if ((c == 'z' || c == 'Z') && i == 0)\n        {\n          _unchangedPart += c;\n          wchar_t newChar = (c == 'z') ? L'a' : L'A';\n          newName.Empty();\n          numLetters++;\n          for (int k = 0; k < numLetters; k++)\n            newName += newChar;\n          break;\n        }\n        newName = c + newName;\n        i--;\n        for (; i >= 0; i--)\n          newName = _changedPart[i] + newName;\n        break;\n      }\n    }\n    else\n    {\n      int i;\n      int numLetters = _changedPart.Length();\n      for (i = numLetters - 1; i >= 0; i--)\n      {\n        wchar_t c = _changedPart[i];\n        if (c == L'9')\n        {\n          c = L'0';\n          newName = c + newName;\n          if (i == 0)\n            newName = UString(L'1') + newName;\n          continue;\n        }\n        c++;\n        newName = c + newName;\n        i--;\n        for (; i >= 0; i--)\n          newName = _changedPart[i] + newName;\n        break;\n      }\n    }\n    _changedPart = newName;\n    return _unchangedPart + _changedPart;\n  }\n};\n\nSTDMETHODIMP CHandler::Open(IInStream *stream,\n    const UInt64 * /* maxCheckStartPosition */,\n    IArchiveOpenCallback *openArchiveCallback)\n{\n  COM_TRY_BEGIN\n  Close();\n  if (openArchiveCallback == 0)\n    return S_FALSE;\n  // try\n  {\n    CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;\n    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openArchiveCallback;\n    if (openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback,\n        &openVolumeCallback) != S_OK)\n      return S_FALSE;\n    \n    {\n      NCOM::CPropVariant prop;\n      RINOK(openVolumeCallback->GetProperty(kpidName, &prop));\n      if (prop.vt != VT_BSTR)\n        return S_FALSE;\n      _name = prop.bstrVal;\n    }\n    \n    int dotPos = _name.ReverseFind('.');\n    UString prefix, ext;\n    if (dotPos >= 0)\n    {\n      prefix = _name.Left(dotPos + 1);\n      ext = _name.Mid(dotPos + 1);\n    }\n    else\n      ext = _name;\n    UString extBig = ext;\n    extBig.MakeUpper();\n\n    CSeqName seqName;\n\n    int numLetters = 2;\n    bool splitStyle = false;\n    if (extBig.Right(2) == L\"AA\")\n    {\n      splitStyle = true;\n      while (numLetters < extBig.Length())\n      {\n        if (extBig[extBig.Length() - numLetters - 1] != 'A')\n          break;\n        numLetters++;\n      }\n    }\n    else if (ext.Right(2) == L\"01\")\n    {\n      while (numLetters < extBig.Length())\n      {\n        if (extBig[extBig.Length() - numLetters - 1] != '0')\n          break;\n        numLetters++;\n      }\n      if (numLetters != ext.Length())\n        return S_FALSE;\n    }\n    else\n      return S_FALSE;\n\n    _streams.Add(stream);\n\n    seqName._unchangedPart = prefix + ext.Left(extBig.Length() - numLetters);\n    seqName._changedPart = ext.Right(numLetters);\n    seqName._splitStyle = splitStyle;\n\n    if (prefix.Length() < 1)\n      _subName = L\"file\";\n    else\n      _subName = prefix.Left(prefix.Length() - 1);\n\n    _totalSize = 0;\n    UInt64 size;\n    {\n      NCOM::CPropVariant prop;\n      RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\n      if (prop.vt != VT_UI8)\n        return E_INVALIDARG;\n      size = prop.uhVal.QuadPart;\n    }\n    _totalSize += size;\n    _sizes.Add(size);\n    \n    if (openArchiveCallback != NULL)\n    {\n      UInt64 numFiles = _streams.Size();\n      RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\n    }\n\n    for (;;)\n    {\n      UString fullName = seqName.GetNextName();\n      CMyComPtr<IInStream> nextStream;\n      HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);\n      if (result == S_FALSE)\n        break;\n      if (result != S_OK)\n        return result;\n      if (!stream)\n        break;\n      {\n        NCOM::CPropVariant prop;\n        RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));\n        if (prop.vt != VT_UI8)\n          return E_INVALIDARG;\n        size = prop.uhVal.QuadPart;\n      }\n      _totalSize += size;\n      _sizes.Add(size);\n      _streams.Add(nextStream);\n      if (openArchiveCallback != NULL)\n      {\n        UInt64 numFiles = _streams.Size();\n        RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));\n      }\n    }\n  }\n  /*\n  catch(...)\n  {\n    return S_FALSE;\n  }\n  */\n  return S_OK;\n  COM_TRY_END\n}\n\nSTDMETHODIMP CHandler::Close()\n{\n  _sizes.Clear();\n  _streams.Clear();\n  return S_OK;\n}\n\nSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)\n{\n  *numItems = _streams.IsEmpty() ? 0 : 1;\n  return S_OK;\n}\n\nSTDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)\n{\n  NWindows::NCOM::CPropVariant prop;\n  switch(propID)\n  {\n    case kpidPath:\n      prop = _subName;\n      break;\n    case kpidSize:\n    case kpidPackSize:\n      prop = _totalSize;\n      break;\n  }\n  prop.Detach(value);\n  return S_OK;\n}\n\nSTDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,\n    Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback)\n{\n  COM_TRY_BEGIN\n\n  if (numItems != UInt32(-1))\n  {\n    if (numItems != 1)\n      return E_INVALIDARG;\n    if (indices[0] != 0)\n      return E_INVALIDARG;\n  }\n  bool testMode = (_aTestMode != 0);\n  CMyComPtr<IArchiveExtractCallback> extractCallback = _anExtractCallback;\n  extractCallback->SetTotal(_totalSize);\n  \n  /*\n  CMyComPtr<IArchiveVolumeExtractCallback> volumeExtractCallback;\n  if (extractCallback.QueryInterface(&volumeExtractCallback) != S_OK)\n    return E_FAIL;\n  */\n\n  UInt64 currentTotalSize = 0;\n  UInt64 currentItemSize;\n\n  RINOK(extractCallback->SetCompleted(&currentTotalSize));\n  CMyComPtr<ISequentialOutStream> realOutStream;\n  Int32 askMode;\n  askMode = testMode ? NArchive::NExtract::NAskMode::kTest :\n  NArchive::NExtract::NAskMode::kExtract;\n  Int32 index = 0;\n  RINOK(extractCallback->GetStream(index, &realOutStream, askMode));\n  \n  RINOK(extractCallback->PrepareOperation(askMode));\n  if (testMode)\n  {\n    RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK));\n    return S_OK;\n  }\n  \n  if (!testMode && (!realOutStream))\n    return S_OK;\n\n  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;\n  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;\n\n  CLocalProgress *lps = new CLocalProgress;\n  CMyComPtr<ICompressProgressInfo> progress = lps;\n  lps->Init(extractCallback, false);\n\n  for (int i = 0; i < _streams.Size(); i++, currentTotalSize += currentItemSize)\n  {\n    lps->InSize = lps->OutSize = currentTotalSize;\n    RINOK(lps->SetCur());\n    IInStream *inStream = _streams[i];\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\n    RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));\n    currentItemSize = copyCoderSpec->TotalSize;\n  }\n  realOutStream.Release();\n  return extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK);\n  COM_TRY_END\n}\n\nSTDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)\n{\n  if (index != 0)\n    return E_INVALIDARG;\n  *stream = 0;\n  CMultiStream *streamSpec = new CMultiStream;\n  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;\n  for (int i = 0; i < _streams.Size(); i++)\n  {\n    CMultiStream::CSubStreamInfo subStreamInfo;\n    subStreamInfo.Stream = _streams[i];\n    subStreamInfo.Pos = 0;\n    subStreamInfo.Size = _sizes[i];\n    streamSpec->Streams.Add(subStreamInfo);\n  }\n  streamSpec->Init();\n  *stream = streamTemp.Detach();\n  return S_OK;\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Split/SplitHandler.h",
    "content": "// Split/Handler.h\n\n#ifndef __SPLIT_HANDLER_H\n#define __SPLIT_HANDLER_H\n\n#include \"Common/MyCom.h\"\n#include \"Common/MyString.h\"\n#include \"../IArchive.h\"\n\nnamespace NArchive {\nnamespace NSplit {\n\nclass CHandler:\n  public IInArchive,\n  public IInArchiveGetStream,\n  // public IOutArchive,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)\n\n  INTERFACE_IInArchive(;)\n\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);\n\nprivate:\n  UString _subName;\n  UString _name;\n  CObjectVector<CMyComPtr<IInStream> > _streams;\n  CRecordVector<UInt64> _sizes;\n\n  UInt64 _totalSize;\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Split/SplitHandlerOut.cpp",
    "content": "// Split/OutHandler.cpp\n\n#include \"StdAfx.h\"\n\n#include \"SplitHandler.h\"\n#include \"../../../Windows/PropVariant.h\"\n#include \"../../../Common/ComTry.h\"\n#include \"../../../Common/StringToInt.h\"\n\nusing namespace NWindows;\n\nnamespace NArchive {\nnamespace NSplit {\n\n/*\nSTDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)\n{\n  *type = NFileTimeType::kWindows;\n  return S_OK;\n}\n\nSTDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,\n    IArchiveUpdateCallback *updateCallback)\n{\n  COM_TRY_BEGIN\n\n  if (numItems != 1)\n    return E_INVALIDARG;\n\n  UInt64 volumeSize = 0;\n\n  CMyComPtr<IArchiveUpdateCallback2> callback2;\n  updateCallback->QueryInterface(IID_IArchiveUpdateCallback2,\n      (void **)&callback2);\n\n  RINOK(callback2->GetVolumeSize(0, &volumeSize));\n\n  Int32 newData;\n  Int32 newProperties;\n  UInt32 indexInArchive;\n  if (!updateCallback)\n    return E_FAIL;\n\n  UInt32 fileIndex = 0;\n  RINOK(updateCallback->GetUpdateItemInfo(fileIndex,\n    &newData, &newProperties, &indexInArchive));\n\n  if (newProperties != 0)\n  {\n    {\n      NCOM::CPropVariant prop;\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsFolder, &prop));\n      if (prop.vt == VT_EMPTY)\n      {\n      }\n      else if (prop.vt != VT_BOOL)\n        return E_INVALIDARG;\n      else\n      {\n        if (prop.boolVal != VARIANT_FALSE)\n          return E_INVALIDARG;\n      }\n    }\n    {\n      NCOM::CPropVariant prop;\n      RINOK(updateCallback->GetProperty(fileIndex, kpidIsAnti, &prop));\n      if (prop.vt == VT_EMPTY)\n      {\n      }\n      else if (prop.vt != VT_BOOL)\n        return E_INVALIDARG;\n      else\n      {\n        if (prop.boolVal != VARIANT_FALSE)\n          return E_INVALIDARG;\n      }\n    }\n  }\n  UInt64 newSize;\n  bool thereIsCopyData = false;\n  if (newData != 0)\n  {\n    NCOM::CPropVariant prop;\n    RINOK(updateCallback->GetProperty(fileIndex, kpidSize, &prop));\n    if (prop.vt != VT_UI8)\n      return E_INVALIDARG;\n    newSize = prop.uhVal.QuadPart;\n  }\n  else\n    thereIsCopyData = true;\n\n  UInt64 pos = 0;\n  while(pos < newSize)\n  {\n\n  }\n  return S_OK;\n  COM_TRY_END\n}\n*/\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Split/SplitRegister.cpp",
    "content": "// SplitRegister.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../Common/RegisterArc.h\"\n\n#include \"SplitHandler.h\"\nstatic IInArchive *CreateArc() { return new NArchive::NSplit::CHandler;  }\n/*\n#ifndef EXTRACT_ONLY\nstatic IOutArchive *CreateArcOut() { return new NArchive::NSplit::CHandler;  }\n#else\n#define CreateArcOut 0\n#endif\n*/\n\nstatic CArcInfo g_ArcInfo =\n{ L\"Split\", L\"001\", 0, 0xEA, { 0 }, 0, false, CreateArc, 0 };\n\nREGISTER_ARC(Split)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/Split/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Archive/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../Common/MyWindows.h\"\n#include \"../../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Alone7z/Alone.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Alone\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** DO NOT EDIT **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=Alone - Win32 DebugU\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n!MESSAGE use the Export Makefile command and run\n!MESSAGE \n!MESSAGE NMAKE /f \"Alone.mak\".\n!MESSAGE \n!MESSAGE You can specify a configuration when running NMAKE\n!MESSAGE by defining the macro CFG on the command line. For example:\n!MESSAGE \n!MESSAGE NMAKE /f \"Alone.mak\" CFG=\"Alone - Win32 DebugU\"\n!MESSAGE \n!MESSAGE Possible choices for configuration are:\n!MESSAGE \n!MESSAGE \"Alone - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \"Alone - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \"Alone - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \"Alone - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \"Release\"\n# PROP BASE Intermediate_Dir \"Release\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \"Release\"\n# PROP Intermediate_Dir \"Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\n# ADD RSC /l 0x419 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\n# SUBTRACT LINK32 /pdb:none\n\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 1\n# PROP BASE Output_Dir \"Debug\"\n# PROP BASE Intermediate_Dir \"Debug\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 1\n# PROP Output_Dir \"Debug\"\n# PROP Intermediate_Dir \"Debug\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\n# ADD RSC /l 0x419 /d \"_DEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\n\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \"ReleaseU\"\n# PROP BASE Intermediate_Dir \"ReleaseU\"\n# PROP BASE Ignore_Export_Lib 0\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \"ReleaseU\"\n# PROP Intermediate_Dir \"ReleaseU\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\n# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\n# ADD RSC /l 0x419 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /opt:NOWIN98\n# SUBTRACT BASE LINK32 /pdb:none\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /opt:NOWIN98\n# SUBTRACT LINK32 /pdb:none\n\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 1\n# PROP BASE Output_Dir \"DebugU\"\n# PROP BASE Intermediate_Dir \"DebugU\"\n# PROP BASE Ignore_Export_Lib 0\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 1\n# PROP Output_Dir \"DebugU\"\n# PROP Intermediate_Dir \"DebugU\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\n# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"COMPRESS_MT\" /D \"_NO_CRYPTO\" /D \"BREAK_HANDLER\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\n# ADD RSC /l 0x419 /d \"_DEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za.exe\" /pdbtype:sept\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7zr.exe\" /pdbtype:sept\n\n!ENDIF \n\n# Begin Target\n\n# Name \"Alone - Win32 Release\"\n# Name \"Alone - Win32 Debug\"\n# Name \"Alone - Win32 ReleaseU\"\n# Name \"Alone - Win32 DebugU\"\n# Begin Group \"Console\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\ArError.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\CompressionMode.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\ConsoleClose.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\ExtractCallbackConsole.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\List.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\List.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\Main.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\MainAr.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\OpenCallbackConsole.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\PercentPrinter.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\UpdateCallbackConsole.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Console\\UserInputUtils.h\n# End Source File\n# End Group\n# Begin Group \"Spec\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=.\\resource.rc\n# End Source File\n# Begin Source File\n\nSOURCE=.\\StdAfx.cpp\n# ADD CPP /Yc\"StdAfx.h\"\n# End Source File\n# Begin Source File\n\nSOURCE=.\\StdAfx.h\n# End Source File\n# End Group\n# Begin Group \"Common\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\AutoPtr.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Buffer.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\ComTry.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\CRC.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Defs.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\DynamicBuffer.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\IntToString.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\ListFileUtils.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\ListFileUtils.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyCom.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyException.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyGuidDef.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyInitGuid.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyString.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyString.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyUnknown.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyVector.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyWindows.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyWindows.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\NewHandler.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Random.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Random.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StdInStream.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StdInStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StdOutStream.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StdOutStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringConvert.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringToInt.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Types.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\UTFConvert.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\UTFConvert.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Wildcard.h\n# End Source File\n# End Group\n# Begin Group \"Windows\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Defs.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Device.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\DLL.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Error.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Error.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileDir.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileFind.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileIO.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileName.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Handle.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\MemoryLock.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\MemoryLock.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\System.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\System.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Thread.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Time.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Time.h\n# End Source File\n# End Group\n# Begin Group \"7zip Common\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\Common\\CreateCoder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\CreateCoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\CrossThreadProgress.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FilePathAutoRename.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FilePathAutoRename.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FileStreams.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FileStreams.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FilterCoder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FilterCoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\InBuffer.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\InBuffer.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\InOutTempBuffer.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\InOutTempBuffer.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\LimitedStreams.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\LimitedStreams.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\LockedStream.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\LockedStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\MethodId.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\MethodId.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\MethodProps.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\MethodProps.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\OffsetStream.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\OffsetStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\OutBuffer.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\OutBuffer.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\ProgressMt.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\ProgressMt.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\ProgressUtils.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\ProgressUtils.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\RegisterArc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\RegisterCodec.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\StreamBinder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\StreamBinder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\StreamObjects.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\StreamObjects.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\StreamUtils.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\StreamUtils.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\VirtThread.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\VirtThread.h\n# End Source File\n# End Group\n# Begin Group \"Compress\"\n\n# PROP Default_Filter \"\"\n# Begin Group \"LZMA_Alone\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBench.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\LZMA_Alone\\LzmaBenchCon.h\n# End Source File\n# End Group\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\Bcj2Coder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\Bcj2Coder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\Bcj2Register.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\BcjCoder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\BcjCoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\BcjRegister.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\BranchCoder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\BranchCoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\BranchMisc.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\BranchMisc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\BranchRegister.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\ByteSwap.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\ByteSwap.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\ByteSwapRegister.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\CopyCoder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\CopyCoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\CopyRegister.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\LzmaDecoder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\LzmaDecoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\LzmaEncoder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\LzmaEncoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\LzmaRegister.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\RangeCoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\RangeCoderBit.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\RangeCoderBitTree.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Compress\\RangeCoderOpt.h\n# End Source File\n# End Group\n# Begin Group \"Archive\"\n\n# PROP Default_Filter \"\"\n# Begin Group \"7z\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zCompressionMode.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zDecode.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zDecode.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zEncode.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zEncode.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zExtract.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zFolderInStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zFolderOutStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zHandler.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zHandler.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zHandlerOut.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zHeader.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zHeader.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zIn.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zIn.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zItem.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zOut.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zOut.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zProperties.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zProperties.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zRegister.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zSpecStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\7z\\7zUpdate.h\n# End Source File\n# End Group\n# Begin Group \"Archive Common\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\CoderMixer2MT.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\DummyOutStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\HandlerOut.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\InStreamWithCRC.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\ItemNameUtils.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\MultiStream.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\MultiStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\OutStreamWithCRC.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Common\\ParseProperties.h\n# End Source File\n# End Group\n# Begin Group \"split\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Split\\SplitHandler.h\n# End Source File\n# End Group\n# Begin Group \"LZM\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Lzma\\LzmaArcRegister.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Lzma\\LzmaFiltersDecode.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Lzma\\LzmaHandler.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Lzma\\LzmaIn.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Archive\\Lzma\\LzmaItem.h\n# End Source File\n# End Group\n# End Group\n# Begin Group \"UI Common\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\ArchiveCommandLine.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\ArchiveExtractCallback.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\ArchiveOpenCallback.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\DefaultName.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\DefaultName.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\EnumDirItems.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\Extract.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\Extract.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\ExtractingFilePath.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\LoadCodecs.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\OpenArchive.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\OpenArchive.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\Property.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\PropIDUtils.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\SetProperties.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\SetProperties.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\SortUtils.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\SortUtils.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\TempFiles.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\TempFiles.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\Update.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\Update.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\UpdateAction.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\UpdateAction.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\UpdateCallback.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\UpdatePair.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\UpdatePair.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\UpdateProduce.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\WorkDir.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\UI\\Common\\WorkDir.h\n# End Source File\n# End Group\n# Begin Group \"7-zip\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\ICoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\IMyUnknown.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\IPassword.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\IProgress.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\IStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\PropID.h\n# End Source File\n# End Group\n# Begin Group \"C\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Bra.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Bra.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\BraIA64.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\IStream.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Compress\\Lz\\LzHash.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\n\n!IF  \"$(CFG)\" == \"Alone - Win32 Release\"\n\n# ADD CPP /O2\n# SUBTRACT CPP /YX /Yc /Yu\n\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 Debug\"\n\n# SUBTRACT CPP /YX /Yc /Yu\n\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 ReleaseU\"\n\n# SUBTRACT CPP /YX /Yc /Yu\n\n!ELSEIF  \"$(CFG)\" == \"Alone - Win32 DebugU\"\n\n# SUBTRACT CPP /YX /Yc /Yu\n\n!ENDIF \n\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Threads.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Threads.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Types.h\n# End Source File\n# End Group\n# End Target\n# End Project\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Alone7z/Alone.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n###############################################################################\n\nProject: \"Alone\"=.\\Alone.dsp - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nGlobal:\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<3>\n{{{\n}}}\n\n###############################################################################\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Alone7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\n\n#include \"StdAfx.h\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Alone7z/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Alone7z/makefile",
    "content": "PROG = 7za.exe\nLIBS = $(LIBS) user32.lib oleaut32.lib Advapi32.lib\n\nCFLAGS = $(CFLAGS) -I ../../../ \\\n  -D_NO_CRYPTO \\\n  -DWIN_LONG_PATH \\\n  -DCOMPRESS_MT \\\n  -DCOMPRESS_MF_MT \\\n  -D_NO_CRYPTO \\\n  -DBREAK_HANDLER \\\n  -DBENCH_MT \\\n\n\nCONSOLE_OBJS = \\\n  $O\\ConsoleClose.obj \\\n  $O\\ExtractCallbackConsole.obj \\\n  $O\\List.obj \\\n  $O\\Main.obj \\\n  $O\\MainAr.obj \\\n  $O\\OpenCallbackConsole.obj \\\n  $O\\PercentPrinter.obj \\\n  $O\\UpdateCallbackConsole.obj \\\n  $O\\UserInputUtils.obj \\\n\nCOMMON_OBJS = \\\n  $O\\CommandLineParser.obj \\\n  $O\\CRC.obj \\\n  $O\\IntToString.obj \\\n  $O\\ListFileUtils.obj \\\n  $O\\NewHandler.obj \\\n  $O\\StdInStream.obj \\\n  $O\\StdOutStream.obj \\\n  $O\\MyString.obj \\\n  $O\\StringConvert.obj \\\n  $O\\StringToInt.obj \\\n  $O\\UTFConvert.obj \\\n  $O\\MyVector.obj \\\n  $O\\Wildcard.obj \\\n\nWIN_OBJS = \\\n  $O\\DLL.obj \\\n  $O\\Error.obj \\\n  $O\\FileDir.obj \\\n  $O\\FileFind.obj \\\n  $O\\FileIO.obj \\\n  $O\\FileName.obj \\\n  $O\\MemoryLock.obj \\\n  $O\\PropVariant.obj \\\n  $O\\PropVariantConversions.obj \\\n  $O\\Synchronization.obj \\\n  $O\\System.obj \\\n  $O\\Time.obj \\\n\n7ZIP_COMMON_OBJS = \\\n  $O\\CreateCoder.obj \\\n  $O\\FilePathAutoRename.obj \\\n  $O\\FileStreams.obj \\\n  $O\\InBuffer.obj \\\n  $O\\InOutTempBuffer.obj \\\n  $O\\FilterCoder.obj \\\n  $O\\LimitedStreams.obj \\\n  $O\\LockedStream.obj \\\n  $O\\MethodId.obj \\\n  $O\\MethodProps.obj \\\n  $O\\OffsetStream.obj \\\n  $O\\OutBuffer.obj \\\n  $O\\ProgressUtils.obj \\\n  $O\\StreamBinder.obj \\\n  $O\\StreamObjects.obj \\\n  $O\\StreamUtils.obj \\\n  $O\\VirtThread.obj \\\n\nUI_COMMON_OBJS = \\\n  $O\\ArchiveCommandLine.obj \\\n  $O\\ArchiveExtractCallback.obj \\\n  $O\\ArchiveOpenCallback.obj \\\n  $O\\DefaultName.obj \\\n  $O\\EnumDirItems.obj \\\n  $O\\Extract.obj \\\n  $O\\ExtractingFilePath.obj \\\n  $O\\LoadCodecs.obj \\\n  $O\\OpenArchive.obj \\\n  $O\\PropIDUtils.obj \\\n  $O\\SetProperties.obj \\\n  $O\\SortUtils.obj \\\n  $O\\TempFiles.obj \\\n  $O\\Update.obj \\\n  $O\\UpdateAction.obj \\\n  $O\\UpdateCallback.obj \\\n  $O\\UpdatePair.obj \\\n  $O\\UpdateProduce.obj \\\n  $O\\WorkDir.obj \\\n\nAR_COMMON_OBJS = \\\n  $O\\CoderMixer2.obj \\\n  $O\\CoderMixer2MT.obj \\\n  $O\\CrossThreadProgress.obj \\\n  $O\\DummyOutStream.obj \\\n  $O\\HandlerOut.obj \\\n  $O\\InStreamWithCRC.obj \\\n  $O\\ItemNameUtils.obj \\\n  $O\\MultiStream.obj \\\n  $O\\OutStreamWithCRC.obj \\\n  $O\\ParseProperties.obj \\\n\n\n7Z_OBJS = \\\n  $O\\7zCompressionMode.obj \\\n  $O\\7zDecode.obj \\\n  $O\\7zEncode.obj \\\n  $O\\7zExtract.obj \\\n  $O\\7zFolderInStream.obj \\\n  $O\\7zFolderOutStream.obj \\\n  $O\\7zHandler.obj \\\n  $O\\7zHandlerOut.obj \\\n  $O\\7zHeader.obj \\\n  $O\\7zIn.obj \\\n  $O\\7zOut.obj \\\n  $O\\7zProperties.obj \\\n  $O\\7zRegister.obj \\\n  $O\\7zSpecStream.obj \\\n  $O\\7zUpdate.obj \\\n\nLZM_OBJS = \\\n  $O\\LzmaArcRegister.obj \\\n  $O\\LzmaFiltersDecode.obj \\\n  $O\\LzmaHandler.obj \\\n  $O\\LzmaIn.obj \\\n\nSPLIT_OBJS = \\\n  $O\\SplitHandler.obj \\\n  $O\\SplitHandlerOut.obj \\\n  $O\\SplitRegister.obj \\\n\nCOMPRESS_OBJS = \\\n  $O\\Bcj2Coder.obj \\\n  $O\\Bcj2Register.obj \\\n  $O\\BcjCoder.obj \\\n  $O\\BcjRegister.obj \\\n  $O\\BranchCoder.obj \\\n  $O\\BranchMisc.obj \\\n  $O\\BranchRegister.obj \\\n  $O\\ByteSwap.obj \\\n  $O\\ByteSwapRegister.obj \\\n  $O\\CopyCoder.obj \\\n  $O\\CopyRegister.obj \\\n  $O\\LzmaDecoder.obj \\\n  $O\\LzmaEncoder.obj \\\n  $O\\LzmaRegister.obj \\\n\nLZMA_BENCH_OBJS = \\\n  $O\\LzmaBench.obj \\\n  $O\\LzmaBenchCon.obj \\\n\nC_OBJS = \\\n  $O\\7zCrc.obj \\\n  $O\\Bra.obj \\\n  $O\\Bra86.obj \\\n  $O\\BraIA64.obj \\\n  $O\\Alloc.obj \\\n  $O\\LzmaDec.obj \\\n  $O\\LzmaEnc.obj \\\n  $O\\LzFind.obj \\\n  $O\\LzFindMt.obj \\\n  $O\\Threads.obj \\\n\nOBJS = \\\n  $O\\StdAfx.obj \\\n  $(CONSOLE_OBJS) \\\n  $(COMMON_OBJS) \\\n  $(WIN_OBJS) \\\n  $(7ZIP_COMMON_OBJS) \\\n  $(UI_COMMON_OBJS) \\\n  $(AR_COMMON_OBJS) \\\n  $(7Z_OBJS) \\\n  $(LZM_OBJS) \\\n  $(SPLIT_OBJS) \\\n  $(COMPRESS_OBJS) \\\n  $(LZMA_BENCH_OBJS) \\\n  $(C_OBJS) \\\n  $(CRC_OBJS) \\\n  $O\\resource.res\n\n\n!include \"../../../Build.mak\"\n\n$(CONSOLE_OBJS): ../../UI/Console/$(*B).cpp\n\t$(COMPL)\n\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\n\t$(COMPL)\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\n\t$(COMPL)\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\n\t$(COMPL)\n$(UI_COMMON_OBJS): ../../UI/Common/$(*B).cpp\n\t$(COMPL)\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\n\t$(COMPL)\n\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\n\t$(COMPL)\n$(LZM_OBJS): ../../Archive/Lzma/$(*B).cpp\n\t$(COMPL)\n$(SPLIT_OBJS): ../../Archive/Split/$(*B).cpp\n\t$(COMPL)\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\n\t$(COMPL_O2)\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\n\t$(COMPL)\n$(C_OBJS): ../../../../C/$(*B).c\n\t$(COMPL_O2)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Alone7z/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\n\nMY_VERSION_INFO_APP(\"7-Zip Standalone Console\", \"7za\")\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Format7zExtractR/StdAfx.cpp",
    "content": "// StdAfx.cpp\n\n#include \"StdAfx.h\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Format7zExtractR/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Format7zExtractR/makefile",
    "content": "PROG = 7zxr.dll\nDEF_FILE = ../../Archive/Archive2.def\nLIBS = $(LIBS) user32.lib oleaut32.lib\nCFLAGS = $(CFLAGS) -I ../../../ \\\n  -DEXTRACT_ONLY \\\n  -DCOMPRESS_MT \\\n  -D_NO_CRYPTO\n\nCOMMON_OBJS = \\\n  $O\\CRC.obj \\\n  $O\\IntToString.obj \\\n  $O\\NewHandler.obj \\\n  $O\\MyString.obj \\\n  $O\\StringConvert.obj \\\n  $O\\StringToInt.obj \\\n  $O\\MyVector.obj \\\n  $O\\Wildcard.obj \\\n\nWIN_OBJS = \\\n  $O\\FileDir.obj \\\n  $O\\FileFind.obj \\\n  $O\\FileIO.obj \\\n  $O\\PropVariant.obj \\\n  $O\\Synchronization.obj \\\n  $O\\System.obj \\\n\n7ZIP_COMMON_OBJS = \\\n  $O\\CreateCoder.obj \\\n  $O\\InBuffer.obj \\\n  $O\\InOutTempBuffer.obj \\\n  $O\\FilterCoder.obj \\\n  $O\\LimitedStreams.obj \\\n  $O\\LockedStream.obj \\\n  $O\\MethodId.obj \\\n  $O\\MethodProps.obj \\\n  $O\\OutBuffer.obj \\\n  $O\\ProgressUtils.obj \\\n  $O\\StreamBinder.obj \\\n  $O\\StreamObjects.obj \\\n  $O\\StreamUtils.obj \\\n  $O\\VirtThread.obj \\\n\nAR_OBJS = \\\n  $O\\ArchiveExports.obj \\\n  $O\\DllExports2.obj \\\n\nAR_COMMON_OBJS = \\\n  $O\\CoderMixer2.obj \\\n  $O\\CoderMixer2MT.obj \\\n  $O\\CrossThreadProgress.obj \\\n  $O\\HandlerOut.obj \\\n  $O\\ItemNameUtils.obj \\\n  $O\\OutStreamWithCRC.obj \\\n  $O\\ParseProperties.obj \\\n\n\n7Z_OBJS = \\\n  $O\\7zCompressionMode.obj \\\n  $O\\7zDecode.obj \\\n  $O\\7zExtract.obj \\\n  $O\\7zFolderOutStream.obj \\\n  $O\\7zHandler.obj \\\n  $O\\7zHeader.obj \\\n  $O\\7zIn.obj \\\n  $O\\7zProperties.obj \\\n  $O\\7zRegister.obj \\\n\n\nCOMPRESS_OBJS = \\\n  $O\\CodecExports.obj \\\n  $O\\Bcj2Coder.obj \\\n  $O\\Bcj2Register.obj \\\n  $O\\BcjCoder.obj \\\n  $O\\BcjRegister.obj \\\n  $O\\BranchCoder.obj \\\n  $O\\BranchMisc.obj \\\n  $O\\BranchRegister.obj \\\n  $O\\ByteSwap.obj \\\n  $O\\ByteSwapRegister.obj \\\n  $O\\CopyCoder.obj \\\n  $O\\CopyRegister.obj \\\n  $O\\LzmaDecoder.obj \\\n  $O\\LzmaRegister.obj \\\n\nC_OBJS = \\\n  $O\\7zCrc.obj \\\n  $O\\Alloc.obj \\\n  $O\\Bra.obj \\\n  $O\\Bra86.obj \\\n  $O\\BraIA64.obj \\\n  $O\\LzmaDec.obj \\\n  $O\\Threads.obj \\\n\nOBJS = \\\n  $O\\StdAfx.obj \\\n  $(CONSOLE_OBJS) \\\n  $(COMMON_OBJS) \\\n  $(WIN_OBJS) \\\n  $(7ZIP_COMMON_OBJS) \\\n  $(AR_OBJS) \\\n  $(AR_COMMON_OBJS) \\\n  $(7Z_OBJS) \\\n  $(COMPRESS_OBJS) \\\n  $(C_OBJS) \\\n  $O\\resource.res\n\n\n!include \"../../../Build.mak\"\n\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\n\t$(COMPL)\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\n\t$(COMPL)\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\n\t$(COMPL)\n$(AR_OBJS): ../../Archive/$(*B).cpp\n\t$(COMPL)\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\n\t$(COMPL)\n\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\n\t$(COMPL)\n\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\n\t$(COMPL_O2)\n\n$(C_OBJS): ../../../../C/$(*B).c\n\t$(COMPL_O2)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Format7zExtractR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\n\nMY_VERSION_INFO_DLL(\"7z Standalone Extracting Plugin\", \"7zxr\")\n\n101  ICON  \"../../Archive/Icons/7z.ico\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Format7zR/StdAfx.cpp",
    "content": "// StdAfx.cpp\n\n#include \"StdAfx.h\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Format7zR/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Format7zR/makefile",
    "content": "PROG = 7zra.dll\nDEF_FILE = ../../Archive/Archive2.def\nLIBS = $(LIBS) user32.lib oleaut32.lib\nCFLAGS = $(CFLAGS) -I ../../../ \\\n  -DCOMPRESS_MT \\\n  -DCOMPRESS_MF_MT \\\n  -D_NO_CRYPTO\n\nCOMMON_OBJS = \\\n  $O\\CRC.obj \\\n  $O\\IntToString.obj \\\n  $O\\NewHandler.obj \\\n  $O\\MyString.obj \\\n  $O\\StringConvert.obj \\\n  $O\\StringToInt.obj \\\n  $O\\MyVector.obj \\\n  $O\\Wildcard.obj \\\n\nWIN_OBJS = \\\n  $O\\FileDir.obj \\\n  $O\\FileFind.obj \\\n  $O\\FileIO.obj \\\n  $O\\PropVariant.obj \\\n  $O\\Synchronization.obj \\\n  $O\\System.obj \\\n\n7ZIP_COMMON_OBJS = \\\n  $O\\CreateCoder.obj \\\n  $O\\InBuffer.obj \\\n  $O\\InOutTempBuffer.obj \\\n  $O\\FilterCoder.obj \\\n  $O\\LimitedStreams.obj \\\n  $O\\LockedStream.obj \\\n  $O\\MethodId.obj \\\n  $O\\MethodProps.obj \\\n  $O\\OutBuffer.obj \\\n  $O\\ProgressUtils.obj \\\n  $O\\StreamBinder.obj \\\n  $O\\StreamObjects.obj \\\n  $O\\StreamUtils.obj \\\n  $O\\VirtThread.obj \\\n\nAR_OBJS = \\\n  $O\\ArchiveExports.obj \\\n  $O\\DllExports2.obj \\\n\nAR_COMMON_OBJS = \\\n  $O\\CoderMixer2.obj \\\n  $O\\CoderMixer2MT.obj \\\n  $O\\CrossThreadProgress.obj \\\n  $O\\HandlerOut.obj \\\n  $O\\InStreamWithCRC.obj \\\n  $O\\ItemNameUtils.obj \\\n  $O\\OutStreamWithCRC.obj \\\n  $O\\ParseProperties.obj \\\n\n\n7Z_OBJS = \\\n  $O\\7zCompressionMode.obj \\\n  $O\\7zDecode.obj \\\n  $O\\7zEncode.obj \\\n  $O\\7zExtract.obj \\\n  $O\\7zFolderInStream.obj \\\n  $O\\7zFolderOutStream.obj \\\n  $O\\7zHandler.obj \\\n  $O\\7zHandlerOut.obj \\\n  $O\\7zHeader.obj \\\n  $O\\7zIn.obj \\\n  $O\\7zOut.obj \\\n  $O\\7zProperties.obj \\\n  $O\\7zSpecStream.obj \\\n  $O\\7zUpdate.obj \\\n  $O\\7zRegister.obj \\\n\n\nCOMPRESS_OBJS = \\\n  $O\\CodecExports.obj \\\n  $O\\Bcj2Coder.obj \\\n  $O\\Bcj2Register.obj \\\n  $O\\BcjCoder.obj \\\n  $O\\BcjRegister.obj \\\n  $O\\BranchCoder.obj \\\n  $O\\BranchMisc.obj \\\n  $O\\BranchRegister.obj \\\n  $O\\ByteSwap.obj \\\n  $O\\ByteSwapRegister.obj \\\n  $O\\CopyCoder.obj \\\n  $O\\CopyRegister.obj \\\n  $O\\LzmaDecoder.obj \\\n  $O\\LzmaEncoder.obj \\\n  $O\\LzmaRegister.obj \\\n\nC_OBJS = \\\n  $O\\7zCrc.obj \\\n  $O\\Alloc.obj \\\n  $O\\Bra.obj \\\n  $O\\Bra86.obj \\\n  $O\\BraIA64.obj \\\n  $O\\LzFind.obj \\\n  $O\\LzFindMt.obj \\\n  $O\\LzmaDec.obj \\\n  $O\\LzmaEnc.obj \\\n  $O\\Threads.obj \\\n\nOBJS = \\\n  $O\\StdAfx.obj \\\n  $(CONSOLE_OBJS) \\\n  $(COMMON_OBJS) \\\n  $(WIN_OBJS) \\\n  $(7ZIP_COMMON_OBJS) \\\n  $(AR_OBJS) \\\n  $(AR_COMMON_OBJS) \\\n  $(7Z_OBJS) \\\n  $(COMPRESS_OBJS) \\\n  $(C_OBJS) \\\n  $O\\resource.res\n\n\n!include \"../../../Build.mak\"\n\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\n\t$(COMPL)\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\n\t$(COMPL)\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\n\t$(COMPL)\n$(AR_OBJS): ../../Archive/$(*B).cpp\n\t$(COMPL)\n$(AR_COMMON_OBJS): ../../Archive/Common/$(*B).cpp\n\t$(COMPL)\n\n$(7Z_OBJS): ../../Archive/7z/$(*B).cpp\n\t$(COMPL)\n\n$(COMPRESS_OBJS): ../../Compress/$(*B).cpp\n\t$(COMPL_O2)\n\n$(C_OBJS): ../../../../C/$(*B).c\n\t$(COMPL_O2)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Bundles/Format7zR/resource.rc",
    "content": "#include \"../../MyVersionInfo.rc\"\n\nMY_VERSION_INFO_DLL(\"7z Standalone Plugin\", \"7zr\")\n\n101  ICON  \"../../Archive/Icons/7z.ico\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/CreateCoder.cpp",
    "content": "// CreateCoder.cpp\n\n#include \"StdAfx.h\"\n\n#include \"CreateCoder.h\"\n\n#include \"../../Windows/PropVariant.h\"\n#include \"../../Windows/Defs.h\"\n#include \"FilterCoder.h\"\n#include \"RegisterCodec.h\"\n\nstatic const unsigned int kNumCodecsMax = 64;\nunsigned int g_NumCodecs = 0;\nconst CCodecInfo *g_Codecs[kNumCodecsMax];\nvoid RegisterCodec(const CCodecInfo *codecInfo)\n{\n  if (g_NumCodecs < kNumCodecsMax)\n    g_Codecs[g_NumCodecs++] = codecInfo;\n}\n\n#ifdef EXTERNAL_CODECS\nstatic HRESULT ReadNumberOfStreams(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, UInt32 &res)\n{\n  NWindows::NCOM::CPropVariant prop;\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\n  if (prop.vt == VT_EMPTY)\n    res = 1;\n  else if (prop.vt == VT_UI4)\n    res = prop.ulVal;\n  else\n    return E_INVALIDARG;\n  return S_OK;\n}\n\nstatic HRESULT ReadIsAssignedProp(ICompressCodecsInfo *codecsInfo, UInt32 index, PROPID propID, bool &res)\n{\n  NWindows::NCOM::CPropVariant prop;\n  RINOK(codecsInfo->GetProperty(index, propID, &prop));\n  if (prop.vt == VT_EMPTY)\n    res = true;\n  else if (prop.vt == VT_BOOL)\n    res = VARIANT_BOOLToBool(prop.boolVal);\n  else\n    return E_INVALIDARG;\n  return S_OK;\n}\n\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs)\n{\n  UInt32 num;\n  RINOK(codecsInfo->GetNumberOfMethods(&num));\n  for (UInt32 i = 0; i < num; i++)\n  {\n    CCodecInfoEx info;\n    NWindows::NCOM::CPropVariant prop;\n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kID, &prop));\n    // if (prop.vt != VT_BSTR)\n    // info.Id.IDSize = (Byte)SysStringByteLen(prop.bstrVal);\n    // memmove(info.Id.ID, prop.bstrVal, info.Id.IDSize);\n    if (prop.vt != VT_UI8)\n    {\n      continue; // old Interface\n      // return E_INVALIDARG;\n    }\n    info.Id = prop.uhVal.QuadPart;\n    prop.Clear();\n    \n    RINOK(codecsInfo->GetProperty(i, NMethodPropID::kName, &prop));\n    if (prop.vt == VT_BSTR)\n      info.Name = prop.bstrVal;\n    else if (prop.vt != VT_EMPTY)\n      return E_INVALIDARG;;\n    \n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kInStreams, info.NumInStreams));\n    RINOK(ReadNumberOfStreams(codecsInfo, i, NMethodPropID::kOutStreams, info.NumOutStreams));\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kEncoderIsAssigned, info.EncoderIsAssigned));\n    RINOK(ReadIsAssignedProp(codecsInfo, i, NMethodPropID::kDecoderIsAssigned, info.DecoderIsAssigned));\n    \n    externalCodecs.Add(info);\n  }\n  return S_OK;\n}\n\n#endif\n\nbool FindMethod(\n  #ifdef EXTERNAL_CODECS\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\n  #endif\n  const UString &name,\n  CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams)\n{\n  UInt32 i;\n  for (i = 0; i < g_NumCodecs; i++)\n  {\n    const CCodecInfo &codec = *g_Codecs[i];\n    if (name.CompareNoCase(codec.Name) == 0)\n    {\n      methodId = codec.Id;\n      numInStreams = codec.NumInStreams;\n      numOutStreams = 1;\n      return true;\n    }\n  }\n  #ifdef EXTERNAL_CODECS\n  if (externalCodecs)\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\n    {\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\n      if (codec.Name.CompareNoCase(name) == 0)\n      {\n        methodId = codec.Id;\n        numInStreams = codec.NumInStreams;\n        numOutStreams = codec.NumOutStreams;\n        return true;\n      }\n    }\n  #endif\n  return false;\n}\n\nbool FindMethod(\n  #ifdef EXTERNAL_CODECS\n  ICompressCodecsInfo * /* codecsInfo */, const CObjectVector<CCodecInfoEx> *externalCodecs,\n  #endif\n  CMethodId methodId, UString &name)\n{\n  UInt32 i;\n  for (i = 0; i < g_NumCodecs; i++)\n  {\n    const CCodecInfo &codec = *g_Codecs[i];\n    if (methodId == codec.Id)\n    {\n      name = codec.Name;\n      return true;\n    }\n  }\n  #ifdef EXTERNAL_CODECS\n  if (externalCodecs)\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\n    {\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\n      if (methodId == codec.Id)\n      {\n        name = codec.Name;\n        return true;\n      }\n    }\n  #endif\n  return false;\n}\n\nHRESULT CreateCoder(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  CMethodId methodId,\n  CMyComPtr<ICompressFilter> &filter,\n  CMyComPtr<ICompressCoder> &coder,\n  CMyComPtr<ICompressCoder2> &coder2,\n  bool encode, bool onlyCoder)\n{\n  bool created = false;\n  UInt32 i;\n  for (i = 0; i < g_NumCodecs; i++)\n  {\n    const CCodecInfo &codec = *g_Codecs[i];\n    if (codec.Id == methodId)\n    {\n      if (encode)\n      {\n        if (codec.CreateEncoder)\n        {\n          void *p = codec.CreateEncoder();\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\n          else coder2 = (ICompressCoder2 *)p;\n          created = (p != 0);\n          break;\n        }\n      }\n      else\n        if (codec.CreateDecoder)\n        {\n          void *p = codec.CreateDecoder();\n          if (codec.IsFilter) filter = (ICompressFilter *)p;\n          else if (codec.NumInStreams == 1) coder = (ICompressCoder *)p;\n          else coder2 = (ICompressCoder2 *)p;\n          created = (p != 0);\n          break;\n        }\n    }\n  }\n\n  #ifdef EXTERNAL_CODECS\n  if (!created && externalCodecs)\n    for (i = 0; i < (UInt32)externalCodecs->Size(); i++)\n    {\n      const CCodecInfoEx &codec = (*externalCodecs)[i];\n      if (codec.Id == methodId)\n      {\n        if (encode)\n        {\n          if (codec.EncoderIsAssigned)\n          {\n            if (codec.IsSimpleCodec())\n            {\n              HRESULT result = codecsInfo->CreateEncoder(i, &IID_ICompressCoder, (void **)&coder);\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\n                return result;\n              if (!coder)\n              {\n                RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressFilter, (void **)&filter));\n              }\n            }\n            else\n            {\n              RINOK(codecsInfo->CreateEncoder(i, &IID_ICompressCoder2, (void **)&coder2));\n            }\n            break;\n          }\n        }\n        else\n          if (codec.DecoderIsAssigned)\n          {\n            if (codec.IsSimpleCodec())\n            {\n              HRESULT result = codecsInfo->CreateDecoder(i, &IID_ICompressCoder, (void **)&coder);\n              if (result != S_OK && result != E_NOINTERFACE && result != CLASS_E_CLASSNOTAVAILABLE)\n                return result;\n              if (!coder)\n              {\n                RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressFilter, (void **)&filter));\n              }\n            }\n            else\n            {\n              RINOK(codecsInfo->CreateDecoder(i, &IID_ICompressCoder2, (void **)&coder2));\n            }\n            break;\n          }\n      }\n    }\n  #endif\n\n  if (onlyCoder && filter)\n  {\n    CFilterCoder *coderSpec = new CFilterCoder;\n    coder = coderSpec;\n    coderSpec->Filter = filter;\n  }\n  return S_OK;\n}\n\nHRESULT CreateCoder(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  CMethodId methodId,\n  CMyComPtr<ICompressCoder> &coder,\n  CMyComPtr<ICompressCoder2> &coder2,\n  bool encode)\n{\n  CMyComPtr<ICompressFilter> filter;\n  return CreateCoder(\n    EXTERNAL_CODECS_LOC_VARS\n    methodId,\n    filter, coder, coder2, encode, true);\n}\n\nHRESULT CreateCoder(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  CMethodId methodId,\n  CMyComPtr<ICompressCoder> &coder, bool encode)\n{\n  CMyComPtr<ICompressFilter> filter;\n  CMyComPtr<ICompressCoder2> coder2;\n  return CreateCoder(\n    EXTERNAL_CODECS_LOC_VARS\n    methodId,\n    coder, coder2, encode);\n}\n\nHRESULT CreateFilter(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  CMethodId methodId,\n  CMyComPtr<ICompressFilter> &filter,\n  bool encode)\n{\n  CMyComPtr<ICompressCoder> coder;\n  CMyComPtr<ICompressCoder2> coder2;\n  return CreateCoder(\n    EXTERNAL_CODECS_LOC_VARS\n    methodId,\n    filter, coder, coder2, encode, false);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/CreateCoder.h",
    "content": "// CreateCoder.h\n\n#ifndef __CREATECODER_H\n#define __CREATECODER_H\n\n#include \"Common/MyCom.h\"\n#include \"Common/MyString.h\"\n#include \"../ICoder.h\"\n\n#include \"MethodId.h\"\n\n#ifdef EXTERNAL_CODECS\n\nstruct CCodecInfoEx\n{\n  UString Name;\n  CMethodId Id;\n  UInt32 NumInStreams;\n  UInt32 NumOutStreams;\n  bool EncoderIsAssigned;\n  bool DecoderIsAssigned;\n  bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }\n  CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}\n};\n\nHRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);\n\n#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,\n#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)\n#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);\n#define IMPL_ISetCompressCodecsInfo2(x) \\\nSTDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \\\n  COM_TRY_BEGIN _codecsInfo = compressCodecsInfo;  return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }\n#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)\n\n#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs\n\n#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,\n\n#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs\n#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs\n\n#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,\n#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,\n\n#else\n\n#define PUBLIC_ISetCompressCodecsInfo\n#define QUERY_ENTRY_ISetCompressCodecsInfo\n#define DECL_ISetCompressCodecsInfo\n#define IMPL_ISetCompressCodecsInfo\n#define EXTERNAL_CODECS_VARS2\n#define DECL_EXTERNAL_CODECS_VARS\n#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2\n#define DECL_EXTERNAL_CODECS_LOC_VARS2\n#define EXTERNAL_CODECS_LOC_VARS2\n#define DECL_EXTERNAL_CODECS_LOC_VARS\n#define EXTERNAL_CODECS_LOC_VARS\n\n#endif\n\nbool FindMethod(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);\n\nbool FindMethod(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  CMethodId methodId, UString &name);\n\n\nHRESULT CreateCoder(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  CMethodId methodId,\n  CMyComPtr<ICompressFilter> &filter,\n  CMyComPtr<ICompressCoder> &coder,\n  CMyComPtr<ICompressCoder2> &coder2,\n  bool encode, bool onlyCoder);\n\nHRESULT CreateCoder(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  CMethodId methodId,\n  CMyComPtr<ICompressCoder> &coder,\n  CMyComPtr<ICompressCoder2> &coder2,\n  bool encode);\n\nHRESULT CreateCoder(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  CMethodId methodId,\n  CMyComPtr<ICompressCoder> &coder, bool encode);\n\nHRESULT CreateFilter(\n  DECL_EXTERNAL_CODECS_LOC_VARS\n  CMethodId methodId,\n  CMyComPtr<ICompressFilter> &filter,\n  bool encode);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/FilePathAutoRename.cpp",
    "content": "// FilePathAutoRename.cpp\n\n#include \"StdAfx.h\"\n#include \"FilePathAutoRename.h\"\n\n#include \"Common/Defs.h\"\n#include \"Common/IntToString.h\"\n\n#include \"Windows/FileName.h\"\n#include \"Windows/FileFind.h\"\n\nusing namespace NWindows;\n\nstatic bool MakeAutoName(const UString &name,\n    const UString &extension, int value, UString &path)\n{\n  wchar_t number[32];\n  ConvertUInt64ToString(value, number);\n  path = name;\n  path += number;\n  path += extension;\n  return NFile::NFind::DoesFileExist(path);\n}\n\nbool AutoRenamePath(UString &fullProcessedPath)\n{\n  UString path;\n  int dotPos = fullProcessedPath.ReverseFind(L'.');\n\n  int slashPos = fullProcessedPath.ReverseFind(L'/');\n  #ifdef _WIN32\n  int slash1Pos = fullProcessedPath.ReverseFind(L'\\\\');\n  slashPos = MyMax(slashPos, slash1Pos);\n  #endif\n\n  UString name, extension;\n  if (dotPos > slashPos &&  dotPos > 0)\n  {\n    name = fullProcessedPath.Left(dotPos);\n    extension = fullProcessedPath.Mid(dotPos);\n  }\n  else\n    name = fullProcessedPath;\n  name += L'_';\n  int indexLeft = 1, indexRight = (1 << 30);\n  while (indexLeft != indexRight)\n  {\n    int indexMid = (indexLeft + indexRight) / 2;\n    if (MakeAutoName(name, extension, indexMid, path))\n      indexLeft = indexMid + 1;\n    else\n      indexRight = indexMid;\n  }\n  if (MakeAutoName(name, extension, indexRight, fullProcessedPath))\n    return false;\n  return true;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/FilePathAutoRename.h",
    "content": "// Util/FilePathAutoRename.h\n\n#ifndef __FILEPATHAUTORENAME_H\n#define __FILEPATHAUTORENAME_H\n\n#include \"Common/MyString.h\"\n\nbool AutoRenamePath(UString &fullProcessedPath);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\n\n#include \"StdAfx.h\"\n\n#ifndef _WIN32\n#include <fcntl.h>\n#include <unistd.h>\n#include <errno.h>\n#endif\n\n#include \"FileStreams.h\"\n\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\n{\n  #ifdef _WIN32\n  if (result)\n    return S_OK;\n  DWORD lastError = ::GetLastError();\n  if (lastError == 0)\n    return E_FAIL;\n  return HRESULT_FROM_WIN32(lastError);\n  #else\n  return result ? S_OK: E_FAIL;\n  #endif\n}\n\nbool CInFileStream::Open(LPCTSTR fileName)\n{\n  return File.Open(fileName);\n}\n\n#ifdef USE_WIN_FILE\n#ifndef _UNICODE\nbool CInFileStream::Open(LPCWSTR fileName)\n{\n  return File.Open(fileName);\n}\n#endif\n#endif\n\nbool CInFileStream::OpenShared(LPCTSTR fileName, bool shareForWrite)\n{\n  return File.OpenShared(fileName, shareForWrite);\n}\n\n#ifdef USE_WIN_FILE\n#ifndef _UNICODE\nbool CInFileStream::OpenShared(LPCWSTR fileName, bool shareForWrite)\n{\n  return File.OpenShared(fileName, shareForWrite);\n}\n#endif\n#endif\n\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  #ifdef USE_WIN_FILE\n  \n  UInt32 realProcessedSize;\n  bool result = File.ReadPart(data, size, realProcessedSize);\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return ConvertBoolToHRESULT(result);\n  \n  #else\n  \n  if(processedSize != NULL)\n    *processedSize = 0;\n  ssize_t res = File.Read(data, (size_t)size);\n  if (res == -1)\n    return E_FAIL;\n  if(processedSize != NULL)\n    *processedSize = (UInt32)res;\n  return S_OK;\n\n  #endif\n}\n\n#ifndef _WIN32_WCE\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  #ifdef _WIN32\n  UInt32 realProcessedSize;\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE),\n      data, size, (DWORD *)&realProcessedSize, NULL);\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\n    return S_OK;\n  return ConvertBoolToHRESULT(res != FALSE);\n  \n  #else\n\n  if(processedSize != NULL)\n    *processedSize = 0;\n  ssize_t res;\n  do\n  {\n    res = read(0, data, (size_t)size);\n  }\n  while (res < 0 && (errno == EINTR));\n  if (res == -1)\n    return E_FAIL;\n  if(processedSize != NULL)\n    *processedSize = (UInt32)res;\n  return S_OK;\n  \n  #endif\n}\n  \n#endif\n\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin,\n    UInt64 *newPosition)\n{\n  if(seekOrigin >= 3)\n    return STG_E_INVALIDFUNCTION;\n\n  #ifdef USE_WIN_FILE\n\n  UInt64 realNewPosition;\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\n  if(newPosition != NULL)\n    *newPosition = realNewPosition;\n  return ConvertBoolToHRESULT(result);\n  \n  #else\n  \n  off_t res = File.Seek(offset, seekOrigin);\n  if (res == -1)\n    return E_FAIL;\n  if(newPosition != NULL)\n    *newPosition = (UInt64)res;\n  return S_OK;\n  \n  #endif\n}\n\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\n{\n  return ConvertBoolToHRESULT(File.GetLength(*size));\n}\n\n\n//////////////////////////\n// COutFileStream\n\nHRESULT COutFileStream::Close()\n{\n  return ConvertBoolToHRESULT(File.Close());\n}\n\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  #ifdef USE_WIN_FILE\n\n  UInt32 realProcessedSize;\n  bool result = File.WritePart(data, size, realProcessedSize);\n  ProcessedSize += realProcessedSize;\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return ConvertBoolToHRESULT(result);\n  \n  #else\n  \n  if(processedSize != NULL)\n    *processedSize = 0;\n  ssize_t res = File.Write(data, (size_t)size);\n  if (res == -1)\n    return E_FAIL;\n  if(processedSize != NULL)\n    *processedSize = (UInt32)res;\n  ProcessedSize += res;\n  return S_OK;\n  \n  #endif\n}\n  \nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\n{\n  if(seekOrigin >= 3)\n    return STG_E_INVALIDFUNCTION;\n  #ifdef USE_WIN_FILE\n\n  UInt64 realNewPosition;\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\n  if(newPosition != NULL)\n    *newPosition = realNewPosition;\n  return ConvertBoolToHRESULT(result);\n  \n  #else\n  \n  off_t res = File.Seek(offset, seekOrigin);\n  if (res == -1)\n    return E_FAIL;\n  if(newPosition != NULL)\n    *newPosition = (UInt64)res;\n  return S_OK;\n  \n  #endif\n}\n\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\n{\n  #ifdef USE_WIN_FILE\n  UInt64 currentPos;\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\n    return E_FAIL;\n  bool result = File.SetLength(newSize);\n  UInt64 currentPos2;\n  result = result && File.Seek(currentPos, currentPos2);\n  return result ? S_OK : E_FAIL;\n  #else\n  return E_FAIL;\n  #endif\n}\n\n#ifndef _WIN32_WCE\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  if(processedSize != NULL)\n    *processedSize = 0;\n\n  #ifdef _WIN32\n  UInt32 realProcessedSize;\n  BOOL res = TRUE;\n  if (size > 0)\n  {\n    // Seems that Windows doesn't like big amounts writing to stdout.\n    // So we limit portions by 32KB.\n    UInt32 sizeTemp = (1 << 15);\n    if (sizeTemp > size)\n      sizeTemp = size;\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\n    size -= realProcessedSize;\n    data = (const void *)((const Byte *)data + realProcessedSize);\n    if(processedSize != NULL)\n      *processedSize += realProcessedSize;\n  }\n  return ConvertBoolToHRESULT(res != FALSE);\n\n  #else\n  \n  ssize_t res;\n  do\n  {\n    res = write(1, data, (size_t)size);\n  }\n  while (res < 0 && (errno == EINTR));\n  if (res == -1)\n    return E_FAIL;\n  if(processedSize != NULL)\n    *processedSize = (UInt32)res;\n  return S_OK;\n  \n  return S_OK;\n  #endif\n}\n  \n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\n\n#ifndef __FILESTREAMS_H\n#define __FILESTREAMS_H\n\n#ifdef _WIN32\n#define USE_WIN_FILE\n#endif\n\n#ifdef USE_WIN_FILE\n#include \"../../Windows/FileIO.h\"\n#else\n#include \"../../Common/C_FileIO.h\"\n#endif\n\n#include \"../IStream.h\"\n#include \"../../Common/MyCom.h\"\n\nclass CInFileStream:\n  public IInStream,\n  public IStreamGetSize,\n  public CMyUnknownImp\n{\npublic:\n  #ifdef USE_WIN_FILE\n  NWindows::NFile::NIO::CInFile File;\n  #else\n  NC::NFile::NIO::CInFile File;\n  #endif\n  CInFileStream() {}\n  virtual ~CInFileStream() {}\n\n  bool Open(LPCTSTR fileName);\n  #ifdef USE_WIN_FILE\n  #ifndef _UNICODE\n  bool Open(LPCWSTR fileName);\n  #endif\n  #endif\n\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\n  #ifdef USE_WIN_FILE\n  #ifndef _UNICODE\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\n  #endif\n  #endif\n\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\n\n  STDMETHOD(GetSize)(UInt64 *size);\n};\n\n#ifndef _WIN32_WCE\nclass CStdInFileStream:\n  public ISequentialInStream,\n  public CMyUnknownImp\n{\npublic:\n  // HANDLE File;\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\n  MY_UNKNOWN_IMP\n\n  virtual ~CStdInFileStream() {}\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n};\n#endif\n\nclass COutFileStream:\n  public IOutStream,\n  public CMyUnknownImp\n{\npublic:\n  #ifdef USE_WIN_FILE\n  NWindows::NFile::NIO::COutFile File;\n  #else\n  NC::NFile::NIO::COutFile File;\n  #endif\npublic:\n  virtual ~COutFileStream() {}\n  bool Create(LPCTSTR fileName, bool createAlways)\n  {\n    ProcessedSize = 0;\n    return File.Create(fileName, createAlways);\n  }\n  bool Open(LPCTSTR fileName, DWORD creationDisposition)\n  {\n    ProcessedSize = 0;\n    return File.Open(fileName, creationDisposition);\n  }\n  #ifdef USE_WIN_FILE\n  #ifndef _UNICODE\n  bool Create(LPCWSTR fileName, bool createAlways)\n  {\n    ProcessedSize = 0;\n    return File.Create(fileName, createAlways);\n  }\n  bool Open(LPCWSTR fileName, DWORD creationDisposition)\n  {\n    ProcessedSize = 0;\n    return File.Open(fileName, creationDisposition);\n  }\n  #endif\n  #endif\n\n  HRESULT Close();\n  \n  UInt64 ProcessedSize;\n\n  #ifdef USE_WIN_FILE\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\n  {\n    return File.SetTime(cTime, aTime, mTime);\n  }\n  bool SetMTime(const FILETIME *mTime) {  return File.SetMTime(mTime); }\n  #endif\n\n\n  MY_UNKNOWN_IMP1(IOutStream)\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\n  STDMETHOD(SetSize)(Int64 newSize);\n};\n\n#ifndef _WIN32_WCE\nclass CStdOutFileStream:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n\n  virtual ~CStdOutFileStream() {}\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n#endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/FilterCoder.cpp",
    "content": "// FilterCoder.cpp\n\n#include \"StdAfx.h\"\n\n#include \"FilterCoder.h\"\nextern \"C\"\n{\n#include \"../../../C/Alloc.h\"\n}\n#include \"../../Common/Defs.h\"\n#include \"StreamUtils.h\"\n\nstatic const UInt32 kBufferSize = 1 << 17;\n\nCFilterCoder::CFilterCoder()\n{\n  _buffer = (Byte *)::MidAlloc(kBufferSize);\n}\n\nCFilterCoder::~CFilterCoder()\n{\n  ::MidFree(_buffer);\n}\n\nHRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)\n{\n  if (_outSizeIsDefined)\n  {\n    UInt64 remSize = _outSize - _nowPos64;\n    if (size > remSize)\n      size = (UInt32)remSize;\n  }\n  RINOK(WriteStream(outStream, _buffer, size));\n  _nowPos64 += size;\n  return S_OK;\n}\n\n\nSTDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,\n      ICompressProgressInfo *progress)\n{\n  RINOK(Init());\n  UInt32 bufferPos = 0;\n  _outSizeIsDefined = (outSize != 0);\n  if (_outSizeIsDefined)\n    _outSize = *outSize;\n\n  while(NeedMore())\n  {\n    size_t processedSize = kBufferSize - bufferPos;\n    \n    // Change it: It can be optimized using ReadPart\n    RINOK(ReadStream(inStream, _buffer + bufferPos, &processedSize));\n    \n    UInt32 endPos = bufferPos + (UInt32)processedSize;\n\n    bufferPos = Filter->Filter(_buffer, endPos);\n    if (bufferPos > endPos)\n    {\n      for (; endPos< bufferPos; endPos++)\n        _buffer[endPos] = 0;\n      bufferPos = Filter->Filter(_buffer, endPos);\n    }\n\n    if (bufferPos == 0)\n    {\n      if (endPos > 0)\n        return WriteWithLimit(outStream, endPos);\n      return S_OK;\n    }\n    RINOK(WriteWithLimit(outStream, bufferPos));\n    if (progress != NULL)\n    {\n      RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));\n    }\n    UInt32 i = 0;\n    while(bufferPos < endPos)\n      _buffer[i++] = _buffer[bufferPos++];\n    bufferPos = i;\n  }\n  return S_OK;\n}\n\n// #ifdef _ST_MODE\nSTDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)\n{\n  _bufferPos = 0;\n  _outStream = outStream;\n  return Init();\n}\n\nSTDMETHODIMP CFilterCoder::ReleaseOutStream()\n{\n  _outStream.Release();\n  return S_OK;\n};\n\n\nSTDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 processedSizeTotal = 0;\n  while(size > 0)\n  {\n    UInt32 sizeMax = kBufferSize - _bufferPos;\n    UInt32 sizeTemp = size;\n    if (sizeTemp > sizeMax)\n      sizeTemp = sizeMax;\n    memmove(_buffer + _bufferPos, data, sizeTemp);\n    size -= sizeTemp;\n    processedSizeTotal += sizeTemp;\n    data = (const Byte *)data + sizeTemp;\n    UInt32 endPos = _bufferPos + sizeTemp;\n    _bufferPos = Filter->Filter(_buffer, endPos);\n    if (_bufferPos == 0)\n    {\n      _bufferPos = endPos;\n      break;\n    }\n    if (_bufferPos > endPos)\n    {\n      if (size != 0)\n        return E_FAIL;\n      break;\n    }\n    RINOK(WriteWithLimit(_outStream, _bufferPos));\n    UInt32 i = 0;\n    while(_bufferPos < endPos)\n      _buffer[i++] = _buffer[_bufferPos++];\n    _bufferPos = i;\n  }\n  if (processedSize != NULL)\n    *processedSize = processedSizeTotal;\n  return S_OK;\n}\n\nSTDMETHODIMP CFilterCoder::Flush()\n{\n  if (_bufferPos != 0)\n  {\n    UInt32 endPos = Filter->Filter(_buffer, _bufferPos);\n    if (endPos > _bufferPos)\n    {\n      for (; _bufferPos < endPos; _bufferPos++)\n        _buffer[_bufferPos] = 0;\n      if (Filter->Filter(_buffer, endPos) != endPos)\n        return E_FAIL;\n    }\n    RINOK(WriteStream(_outStream, _buffer, _bufferPos));\n    _bufferPos = 0;\n  }\n  CMyComPtr<IOutStreamFlush> flush;\n  _outStream.QueryInterface(IID_IOutStreamFlush, &flush);\n  if (flush)\n    return  flush->Flush();\n  return S_OK;\n}\n\n\nSTDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)\n{\n  _convertedPosBegin = _convertedPosEnd = _bufferPos = 0;\n  _inStream = inStream;\n  return Init();\n}\n\nSTDMETHODIMP CFilterCoder::ReleaseInStream()\n{\n  _inStream.Release();\n  return S_OK;\n};\n\nSTDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 processedSizeTotal = 0;\n  while(size > 0)\n  {\n    if (_convertedPosBegin != _convertedPosEnd)\n    {\n      UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);\n      memmove(data, _buffer + _convertedPosBegin, sizeTemp);\n      _convertedPosBegin += sizeTemp;\n      data = (void *)((Byte *)data + sizeTemp);\n      size -= sizeTemp;\n      processedSizeTotal += sizeTemp;\n      break;\n    }\n    int i;\n    for (i = 0; _convertedPosEnd + i < _bufferPos; i++)\n      _buffer[i] = _buffer[i + _convertedPosEnd];\n    _bufferPos = i;\n    _convertedPosBegin = _convertedPosEnd = 0;\n    size_t processedSizeTemp = kBufferSize - _bufferPos;\n    RINOK(ReadStream(_inStream, _buffer + _bufferPos, &processedSizeTemp));\n    _bufferPos = _bufferPos + (UInt32)processedSizeTemp;\n    _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\n    if (_convertedPosEnd == 0)\n    {\n      if (_bufferPos == 0)\n        break;\n      else\n      {\n        _convertedPosEnd = _bufferPos; // check it\n        continue;\n      }\n    }\n    if (_convertedPosEnd > _bufferPos)\n    {\n      for (; _bufferPos < _convertedPosEnd; _bufferPos++)\n        _buffer[_bufferPos] = 0;\n      _convertedPosEnd = Filter->Filter(_buffer, _bufferPos);\n    }\n  }\n  if (processedSize != NULL)\n    *processedSize = processedSizeTotal;\n  return S_OK;\n}\n\n// #endif // _ST_MODE\n\n#ifndef _NO_CRYPTO\nSTDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)\n{\n  return _setPassword->CryptoSetPassword(data, size);\n}\n#endif\n\n#ifndef EXTRACT_ONLY\nSTDMETHODIMP CFilterCoder::SetCoderProperties(const PROPID *propIDs,\n      const PROPVARIANT *properties, UInt32 numProperties)\n{\n  return _SetCoderProperties->SetCoderProperties(propIDs, properties, numProperties);\n}\n\nSTDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)\n{\n  return _writeCoderProperties->WriteCoderProperties(outStream);\n}\n\n/*\nSTDMETHODIMP CFilterCoder::ResetSalt()\n{\n  return _CryptoResetSalt->ResetSalt();\n}\n*/\n\nSTDMETHODIMP CFilterCoder::ResetInitVector()\n{\n  return _CryptoResetInitVector->ResetInitVector();\n}\n#endif\n\nSTDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)\n{\n  return _setDecoderProperties->SetDecoderProperties2(data, size);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/FilterCoder.h",
    "content": "// FilterCoder.h\n\n#ifndef __FILTERCODER_H\n#define __FILTERCODER_H\n\n#include \"../../Common/MyCom.h\"\n#include \"../ICoder.h\"\n#include \"../IPassword.h\"\n\n#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \\\n{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \\\n*outObject = (void *)(i *)this; AddRef(); return S_OK; }\n\nclass CFilterCoder:\n  public ICompressCoder,\n  // #ifdef _ST_MODE\n  public ICompressSetInStream,\n  public ISequentialInStream,\n  public ICompressSetOutStream,\n  public ISequentialOutStream,\n  public IOutStreamFlush,\n  // #endif\n\n  #ifndef _NO_CRYPTO\n  public ICryptoSetPassword,\n  #endif\n  #ifndef EXTRACT_ONLY\n  public ICompressSetCoderProperties,\n  public ICompressWriteCoderProperties,\n  // public ICryptoResetSalt,\n  public ICryptoResetInitVector,\n  #endif\n  public ICompressSetDecoderProperties2,\n  public CMyUnknownImp\n{\nprotected:\n  Byte *_buffer;\n  // #ifdef _ST_MODE\n  CMyComPtr<ISequentialInStream> _inStream;\n  CMyComPtr<ISequentialOutStream> _outStream;\n  UInt32 _bufferPos;\n  UInt32 _convertedPosBegin;\n  UInt32 _convertedPosEnd;\n  // #endif\n  bool _outSizeIsDefined;\n  UInt64 _outSize;\n  UInt64 _nowPos64;\n\n  HRESULT Init()\n  {\n    _nowPos64 = 0;\n    _outSizeIsDefined = false;\n    return Filter->Init();\n  }\n\n  CMyComPtr<ICryptoSetPassword> _setPassword;\n  #ifndef EXTRACT_ONLY\n  CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;\n  CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;\n  // CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;\n  CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;\n  #endif\n  CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;\npublic:\n  CMyComPtr<ICompressFilter> Filter;\n\n  CFilterCoder();\n  ~CFilterCoder();\n  HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);\n  bool NeedMore() const\n    { return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }\n\npublic:\n  MY_QUERYINTERFACE_BEGIN\n    MY_QUERYINTERFACE_ENTRY(ICompressCoder)\n    // #ifdef _ST_MODE\n    MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)\n    MY_QUERYINTERFACE_ENTRY(ISequentialInStream)\n\n    MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)\n    MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)\n    MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)\n    // #endif\n\n    #ifndef _NO_CRYPTO\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)\n    #endif\n\n    #ifndef EXTRACT_ONLY\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)\n    // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)\n    MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)\n    #endif\n\n    MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)\n  MY_QUERYINTERFACE_END\n  MY_ADDREF_RELEASE\n  STDMETHOD(Code)(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\n      ICompressProgressInfo *progress);\n  // #ifdef _ST_MODE\n  STDMETHOD(ReleaseInStream)();\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \\\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\n  STDMETHOD(ReleaseOutStream)();\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Flush)();\n  // #endif\n\n  #ifndef _NO_CRYPTO\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);\n  #endif\n  #ifndef EXTRACT_ONLY\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\n      const PROPVARIANT *properties, UInt32 numProperties);\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\n  // STDMETHOD(ResetSalt)();\n  STDMETHOD(ResetInitVector)();\n  #endif\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\n};\n\n// #ifdef _ST_MODE\nclass CInStreamReleaser\n{\npublic:\n  CFilterCoder *FilterCoder;\n  CInStreamReleaser(): FilterCoder(0) {}\n  ~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }\n};\n\nclass COutStreamReleaser\n{\npublic:\n  CFilterCoder *FilterCoder;\n  COutStreamReleaser(): FilterCoder(0) {}\n  ~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }\n};\n// #endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\n\n#include \"StdAfx.h\"\n\n#include \"InBuffer.h\"\n\nextern \"C\"\n{\n  #include \"../../../C/Alloc.h\"\n}\n\nCInBuffer::CInBuffer():\n  _buffer(0),\n  _bufferLimit(0),\n  _bufferBase(0),\n  _stream(0),\n  _bufferSize(0)\n{}\n\nbool CInBuffer::Create(UInt32 bufferSize)\n{\n  const UInt32 kMinBlockSize = 1;\n  if (bufferSize < kMinBlockSize)\n    bufferSize = kMinBlockSize;\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\n    return true;\n  Free();\n  _bufferSize = bufferSize;\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\n  return (_bufferBase != 0);\n}\n\nvoid CInBuffer::Free()\n{\n  ::MidFree(_bufferBase);\n  _bufferBase = 0;\n}\n\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\n{\n  _stream = stream;\n}\n\nvoid CInBuffer::Init()\n{\n  _processedSize = 0;\n  _buffer = _bufferBase;\n  _bufferLimit = _buffer;\n  _wasFinished = false;\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = S_OK;\n  #endif\n}\n\nbool CInBuffer::ReadBlock()\n{\n  #ifdef _NO_EXCEPTIONS\n  if (ErrorCode != S_OK)\n    return false;\n  #endif\n  if (_wasFinished)\n    return false;\n  _processedSize += (_buffer - _bufferBase);\n  UInt32 numProcessedBytes;\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = result;\n  #else\n  if (result != S_OK)\n    throw CInBufferException(result);\n  #endif\n  _buffer = _bufferBase;\n  _bufferLimit = _buffer + numProcessedBytes;\n  _wasFinished = (numProcessedBytes == 0);\n  return (!_wasFinished);\n}\n\nByte CInBuffer::ReadBlock2()\n{\n  if(!ReadBlock())\n    return 0xFF;\n  return *_buffer++;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\n\n#ifndef __INBUFFER_H\n#define __INBUFFER_H\n\n#include \"../IStream.h\"\n#include \"../../Common/MyCom.h\"\n#include \"../../Common/MyException.h\"\n\n#ifndef _NO_EXCEPTIONS\nstruct CInBufferException: public CSystemException\n{\n  CInBufferException(HRESULT errorCode): CSystemException(errorCode) {}\n};\n#endif\n\nclass CInBuffer\n{\n  Byte *_buffer;\n  Byte *_bufferLimit;\n  Byte *_bufferBase;\n  CMyComPtr<ISequentialInStream> _stream;\n  UInt64 _processedSize;\n  UInt32 _bufferSize;\n  bool _wasFinished;\n\n  bool ReadBlock();\n  Byte ReadBlock2();\n\npublic:\n  #ifdef _NO_EXCEPTIONS\n  HRESULT ErrorCode;\n  #endif\n\n  CInBuffer();\n  ~CInBuffer() { Free(); }\n\n  bool Create(UInt32 bufferSize);\n  void Free();\n  \n  void SetStream(ISequentialInStream *stream);\n  void Init();\n  void ReleaseStream() { _stream.Release(); }\n\n  bool ReadByte(Byte &b)\n  {\n    if (_buffer >= _bufferLimit)\n      if (!ReadBlock())\n        return false;\n    b = *_buffer++;\n    return true;\n  }\n  Byte ReadByte()\n  {\n    if (_buffer >= _bufferLimit)\n      return ReadBlock2();\n    return *_buffer++;\n  }\n  UInt32 ReadBytes(Byte *buf, UInt32 size)\n  {\n    if ((UInt32)(_bufferLimit - _buffer) >= size)\n    {\n      for (UInt32 i = 0; i < size; i++)\n        buf[i] = _buffer[i];\n      _buffer += size;\n      return size;\n    }\n    for (UInt32 i = 0; i < size; i++)\n    {\n      if (_buffer >= _bufferLimit)\n        if (!ReadBlock())\n          return i;\n      buf[i] = *_buffer++;\n    }\n    return size;\n  }\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\n  bool WasFinished() const { return _wasFinished; }\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/InOutTempBuffer.cpp",
    "content": "// InOutTempBuffer.cpp\n\n#include \"StdAfx.h\"\n\n#include \"InOutTempBuffer.h\"\n#include \"../../Common/Defs.h\"\n// #include \"Windows/Defs.h\"\n\n#include \"StreamUtils.h\"\n\nusing namespace NWindows;\nusing namespace NFile;\nusing namespace NDirectory;\n\nstatic UInt32 kTmpBufferMemorySize = (1 << 20);\n\nstatic LPCTSTR kTempFilePrefixString = TEXT(\"iot\");\n\nCInOutTempBuffer::CInOutTempBuffer():\n  _buffer(NULL)\n{\n}\n\nvoid CInOutTempBuffer::Create()\n{\n  _buffer = new Byte[kTmpBufferMemorySize];\n}\n\nCInOutTempBuffer::~CInOutTempBuffer()\n{\n  delete []_buffer;\n}\nvoid CInOutTempBuffer::InitWriting()\n{\n  _bufferPosition = 0;\n  _tmpFileCreated = false;\n  _fileSize = 0;\n}\n\nbool CInOutTempBuffer::WriteToFile(const void *data, UInt32 size)\n{\n  if (size == 0)\n    return true;\n  if(!_tmpFileCreated)\n  {\n    CSysString tempDirPath;\n    if(!MyGetTempPath(tempDirPath))\n      return false;\n    if (_tempFile.Create(tempDirPath, kTempFilePrefixString, _tmpFileName) == 0)\n      return false;\n    // _outFile.SetOpenCreationDispositionCreateAlways();\n    if(!_outFile.Create(_tmpFileName, true))\n      return false;\n    _tmpFileCreated = true;\n  }\n  UInt32 processedSize;\n  if(!_outFile.Write(data, size, processedSize))\n    return false;\n  _fileSize += processedSize;\n  return (processedSize == size);\n}\n\nbool CInOutTempBuffer::FlushWrite()\n{\n  return _outFile.Close();\n}\n\nbool CInOutTempBuffer::Write(const void *data, UInt32 size)\n{\n  if(_bufferPosition < kTmpBufferMemorySize)\n  {\n    UInt32 curSize = MyMin(kTmpBufferMemorySize - _bufferPosition, size);\n    memmove(_buffer + _bufferPosition, (const Byte *)data, curSize);\n    _bufferPosition += curSize;\n    size -= curSize;\n    data = ((const Byte *)data) + curSize;\n    _fileSize += curSize;\n  }\n  return WriteToFile(data, size);\n}\n\nbool CInOutTempBuffer::InitReading()\n{\n  _currentPositionInBuffer = 0;\n  if(_tmpFileCreated)\n    return _inFile.Open(_tmpFileName);\n  return true;\n}\n\nHRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream)\n{\n  if (_currentPositionInBuffer < _bufferPosition)\n  {\n    UInt32 sizeToWrite = _bufferPosition - _currentPositionInBuffer;\n    RINOK(WriteStream(stream, _buffer + _currentPositionInBuffer, sizeToWrite));\n    _currentPositionInBuffer += sizeToWrite;\n  }\n  if (!_tmpFileCreated)\n    return true;\n  for (;;)\n  {\n    UInt32 localProcessedSize;\n    if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize))\n      return E_FAIL;\n    if (localProcessedSize == 0)\n      return S_OK;\n    RINOK(WriteStream(stream, _buffer, localProcessedSize));\n  }\n}\n\nSTDMETHODIMP CSequentialOutTempBufferImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  if (!_buffer->Write(data, size))\n  {\n    if (processedSize != NULL)\n      *processedSize = 0;\n    return E_FAIL;\n  }\n  if (processedSize != NULL)\n    *processedSize = size;\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/InOutTempBuffer.h",
    "content": "// Util/InOutTempBuffer.h\n\n#ifndef __IN_OUT_TEMP_BUFFER_H\n#define __IN_OUT_TEMP_BUFFER_H\n\n#include \"../../Windows/FileIO.h\"\n#include \"../../Windows/FileDir.h\"\n#include \"../../Common/MyCom.h\"\n\n#include \"../IStream.h\"\n\nclass CInOutTempBuffer\n{\n  NWindows::NFile::NDirectory::CTempFile _tempFile;\n  NWindows::NFile::NIO::COutFile _outFile;\n  NWindows::NFile::NIO::CInFile _inFile;\n  Byte *_buffer;\n  UInt32 _bufferPosition;\n  UInt32 _currentPositionInBuffer;\n  CSysString _tmpFileName;\n  bool _tmpFileCreated;\n\n  UInt64 _fileSize;\n\n  bool WriteToFile(const void *data, UInt32 size);\npublic:\n  CInOutTempBuffer();\n  ~CInOutTempBuffer();\n  void Create();\n\n  void InitWriting();\n  bool Write(const void *data, UInt32 size);\n  UInt64 GetDataSize() const { return _fileSize; }\n  bool FlushWrite();\n  bool InitReading();\n  HRESULT WriteToStream(ISequentialOutStream *stream);\n};\n\nclass CSequentialOutTempBufferImp:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\n  CInOutTempBuffer *_buffer;\npublic:\n  // CSequentialOutStreamImp(): _size(0) {}\n  // UInt32 _size;\n  void Init(CInOutTempBuffer *buffer)  { _buffer = buffer; }\n  // UInt32 GetSize() const { return _size; }\n\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/LimitedStreams.cpp",
    "content": "// LimitedStreams.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LimitedStreams.h\"\n#include \"../../Common/Defs.h\"\n\nSTDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize = 0;\n  UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size);\n  HRESULT result = S_OK;\n  if (sizeToRead > 0)\n  {\n    result = _stream->Read(data, sizeToRead, &realProcessedSize);\n    _pos += realProcessedSize;\n    if (realProcessedSize == 0)\n      _wasFinished = true;\n  }\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return result;\n}\n\nSTDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  HRESULT result = S_OK;\n  if (processedSize != NULL)\n    *processedSize = 0;\n  if (size > _size)\n  {\n    size = (UInt32)_size;\n    if (size == 0)\n    {\n      _overflow = true;\n      return E_FAIL;\n    }\n  }\n  if (_stream)\n    result = _stream->Write(data, size, &size);\n  _size -= size;\n  if (processedSize != NULL)\n    *processedSize = size;\n  return result;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/LimitedStreams.h",
    "content": "// LimitedStreams.h\n\n#ifndef __LIMITEDSTREAMS_H\n#define __LIMITEDSTREAMS_H\n\n#include \"../../Common/MyCom.h\"\n#include \"../IStream.h\"\n\nclass CLimitedSequentialInStream:\n  public ISequentialInStream,\n  public CMyUnknownImp\n{\n  CMyComPtr<ISequentialInStream> _stream;\n  UInt64 _size;\n  UInt64 _pos;\n  bool _wasFinished;\npublic:\n  void SetStream(ISequentialInStream *stream) { _stream = stream; }\n  void Init(UInt64 streamSize)\n  {\n    _size = streamSize;\n    _pos = 0;\n    _wasFinished = false;\n  }\n \n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  UInt64 GetSize() const { return _pos; }\n  bool WasFinished() const { return _wasFinished; }\n};\n\nclass CLimitedSequentialOutStream:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\n  CMyComPtr<ISequentialOutStream> _stream;\n  UInt64 _size;\n  bool _overflow;\npublic:\n  MY_UNKNOWN_IMP\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\n  void ReleaseStream() { _stream.Release(); }\n  void Init(UInt64 size)\n  {\n    _size = size;\n    _overflow = false;\n  }\n  bool IsFinishedOK() const { return (_size == 0 && !_overflow); }\n  UInt64 GetRem() const { return _size; }\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/LockedStream.cpp",
    "content": "// LockedStream.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LockedStream.h\"\n\nHRESULT CLockedInStream::Read(UInt64 startPos, void *data, UInt32 size,\n  UInt32 *processedSize)\n{\n  NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);\n  RINOK(_stream->Seek(startPos, STREAM_SEEK_SET, NULL));\n  return _stream->Read(data, size, processedSize);\n}\n\nSTDMETHODIMP CLockedSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize = 0;\n  HRESULT result = _lockedInStream->Read(_pos, data, size, &realProcessedSize);\n  _pos += realProcessedSize;\n  if (processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return result;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/LockedStream.h",
    "content": "// LockedStream.h\n\n#ifndef __LOCKEDSTREAM_H\n#define __LOCKEDSTREAM_H\n\n#include \"../../Windows/Synchronization.h\"\n#include \"../../Common/MyCom.h\"\n#include \"../IStream.h\"\n\nclass CLockedInStream\n{\n  CMyComPtr<IInStream> _stream;\n  NWindows::NSynchronization::CCriticalSection _criticalSection;\npublic:\n  void Init(IInStream *stream)\n    { _stream = stream; }\n  HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);\n};\n\nclass CLockedSequentialInStreamImp:\n  public ISequentialInStream,\n  public CMyUnknownImp\n{\n  CLockedInStream *_lockedInStream;\n  UInt64 _pos;\npublic:\n  void Init(CLockedInStream *lockedInStream, UInt64 startPos)\n  {\n    _lockedInStream = lockedInStream;\n    _pos = startPos;\n  }\n\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/MethodId.cpp",
    "content": "// MethodId.cpp\n\n#include \"StdAfx.h\"\n\n#include \"MethodId.h\"\n#include \"../../Common/MyString.h\"\n\nstatic inline wchar_t GetHex(Byte value)\n{\n  return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\n}\n\nUString ConvertMethodIdToString(UInt64 id)\n{\n  wchar_t s[32];\n  int len = 32;\n  s[--len] = 0;\n  do\n  {\n    s[--len] = GetHex((Byte)id & 0xF);\n    id >>= 4;\n    s[--len] = GetHex((Byte)id & 0xF);\n    id >>= 4;\n  }\n  while (id != 0);\n  return s + len;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/MethodId.h",
    "content": "// MethodId.h\n\n#ifndef __7Z_METHOD_ID_H\n#define __7Z_METHOD_ID_H\n\n#include \"../../Common/Types.h\"\n\ntypedef UInt64 CMethodId;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/MethodProps.cpp",
    "content": "// MethodProps.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../Common/MyCom.h\"\n\n#include \"../ICoder.h\"\n\n#include \"MethodProps.h\"\n\nstatic UInt64 k_LZMA = 0x030101;\n// static UInt64 k_LZMA2 = 0x030102;\n\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder)\n{\n  bool tryReduce = false;\n  UInt32 reducedDictionarySize = 1 << 10;\n  if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */))\n  {\n    for (;;)\n    {\n      const UInt32 step = (reducedDictionarySize >> 1);\n      if (reducedDictionarySize >= *inSizeForReduce)\n      {\n        tryReduce = true;\n        break;\n      }\n      reducedDictionarySize += step;\n      if (reducedDictionarySize >= *inSizeForReduce)\n      {\n        tryReduce = true;\n        break;\n      }\n      if (reducedDictionarySize >= ((UInt32)3 << 30))\n        break;\n      reducedDictionarySize += step;\n    }\n  }\n\n  {\n    int numProps = method.Props.Size();\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\n    coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\n    if (setCoderProperties == NULL)\n    {\n      if (numProps != 0)\n        return E_INVALIDARG;\n    }\n    else\n    {\n      CRecordVector<PROPID> propIDs;\n      NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps];\n      HRESULT res = S_OK;\n      try\n      {\n        for (int i = 0; i < numProps; i++)\n        {\n          const CProp &prop = method.Props[i];\n          propIDs.Add(prop.Id);\n          NWindows::NCOM::CPropVariant &value = values[i];\n          value = prop.Value;\n          // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal)\n          if (tryReduce)\n            if (prop.Id == NCoderPropID::kDictionarySize)\n              if (value.vt == VT_UI4)\n                if (reducedDictionarySize < value.ulVal)\n            value.ulVal = reducedDictionarySize;\n        }\n        CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\n        coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);\n        res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps);\n      }\n      catch(...)\n      {\n        delete []values;\n        throw;\n      }\n      delete []values;\n      RINOK(res);\n    }\n  }\n \n  /*\n  CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\n  coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);\n  if (writeCoderProperties != NULL)\n  {\n    CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;\n    CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);\n    outStreamSpec->Init();\n    RINOK(writeCoderProperties->WriteCoderProperties(outStream));\n    size_t size = outStreamSpec->GetSize();\n    filterProps.SetCapacity(size);\n    memmove(filterProps, outStreamSpec->GetBuffer(), size);\n  }\n  */\n  return S_OK;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/MethodProps.h",
    "content": "// MethodProps.h\n\n#ifndef __7Z_METHOD_PROPS_H\n#define __7Z_METHOD_PROPS_H\n\n#include \"../../Common/MyVector.h\"\n\n#include \"../../Windows/PropVariant.h\"\n\n#include \"MethodId.h\"\n\nstruct CProp\n{\n  PROPID Id;\n  NWindows::NCOM::CPropVariant Value;\n};\n\nstruct CMethod\n{\n  CMethodId Id;\n  CObjectVector<CProp> Props;\n};\n\nstruct CMethodsMode\n{\n  CObjectVector<CMethod> Methods;\n  #ifdef COMPRESS_MT\n  UInt32 NumThreads;\n  #endif\n\n  CMethodsMode()\n      #ifdef COMPRESS_MT\n      : NumThreads(1)\n      #endif\n  {}\n  bool IsEmpty() const { return Methods.IsEmpty() ; }\n};\n\nHRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/OffsetStream.cpp",
    "content": "// OffsetStream.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Common/Defs.h\"\n#include \"OffsetStream.h\"\n\nHRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)\n{\n  _offset = offset;\n  _stream = stream;\n  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);\n}\n\nSTDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  return _stream->Write(data, size, processedSize);\n}\n\nSTDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,\n    UInt64 *newPosition)\n{\n  UInt64 absoluteNewPosition;\n  if (seekOrigin == STREAM_SEEK_SET)\n    offset += _offset;\n  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);\n  if (newPosition != NULL)\n    *newPosition = absoluteNewPosition - _offset;\n  return result;\n}\n\nSTDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)\n{\n  return _stream->SetSize(_offset + newSize);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/OffsetStream.h",
    "content": "// OffsetStream.h\n\n#ifndef __OFFSETSTREAM_H\n#define __OFFSETSTREAM_H\n\n#include \"Common/MyCom.h\"\n#include \"../IStream.h\"\n\nclass COffsetOutStream:\n  public IOutStream,\n  public CMyUnknownImp\n{\n  UInt64 _offset;\n  CMyComPtr<IOutStream> _stream;\npublic:\n  HRESULT Init(IOutStream *stream, UInt64 offset);\n  \n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\n  STDMETHOD(SetSize)(Int64 newSize);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\n\n#include \"StdAfx.h\"\n\n#include \"OutBuffer.h\"\n\nextern \"C\"\n{\n  #include \"../../../C/Alloc.h\"\n}\n\nbool COutBuffer::Create(UInt32 bufferSize)\n{\n  const UInt32 kMinBlockSize = 1;\n  if (bufferSize < kMinBlockSize)\n    bufferSize = kMinBlockSize;\n  if (_buffer != 0 && _bufferSize == bufferSize)\n    return true;\n  Free();\n  _bufferSize = bufferSize;\n  _buffer = (Byte *)::MidAlloc(bufferSize);\n  return (_buffer != 0);\n}\n\nvoid COutBuffer::Free()\n{\n  ::MidFree(_buffer);\n  _buffer = 0;\n}\n\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\n{\n  _stream = stream;\n}\n\nvoid COutBuffer::Init()\n{\n  _streamPos = 0;\n  _limitPos = _bufferSize;\n  _pos = 0;\n  _processedSize = 0;\n  _overDict = false;\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = S_OK;\n  #endif\n}\n\nUInt64 COutBuffer::GetProcessedSize() const\n{\n  UInt64 res = _processedSize + _pos - _streamPos;\n  if (_streamPos > _pos)\n    res += _bufferSize;\n  return res;\n}\n\n\nHRESULT COutBuffer::FlushPart()\n{\n  // _streamPos < _bufferSize\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\n  HRESULT result = S_OK;\n  #ifdef _NO_EXCEPTIONS\n  result = ErrorCode;\n  #endif\n  if (_buffer2 != 0)\n  {\n    memmove(_buffer2, _buffer + _streamPos, size);\n    _buffer2 += size;\n  }\n\n  if (_stream != 0\n      #ifdef _NO_EXCEPTIONS\n      && (ErrorCode == S_OK)\n      #endif\n     )\n  {\n    UInt32 processedSize = 0;\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\n    size = processedSize;\n  }\n  _streamPos += size;\n  if (_streamPos == _bufferSize)\n    _streamPos = 0;\n  if (_pos == _bufferSize)\n  {\n    _overDict = true;\n    _pos = 0;\n  }\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\n  _processedSize += size;\n  return result;\n}\n\nHRESULT COutBuffer::Flush()\n{\n  #ifdef _NO_EXCEPTIONS\n  if (ErrorCode != S_OK)\n    return ErrorCode;\n  #endif\n\n  while(_streamPos != _pos)\n  {\n    HRESULT result = FlushPart();\n    if (result != S_OK)\n      return result;\n  }\n  return S_OK;\n}\n\nvoid COutBuffer::FlushWithCheck()\n{\n  HRESULT result = Flush();\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = result;\n  #else\n  if (result != S_OK)\n    throw COutBufferException(result);\n  #endif\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\n\n#ifndef __OUTBUFFER_H\n#define __OUTBUFFER_H\n\n#include \"../IStream.h\"\n#include \"../../Common/MyCom.h\"\n#include \"../../Common/MyException.h\"\n\n#ifndef _NO_EXCEPTIONS\nstruct COutBufferException: public CSystemException\n{\n  COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}\n};\n#endif\n\nclass COutBuffer\n{\nprotected:\n  Byte *_buffer;\n  UInt32 _pos;\n  UInt32 _limitPos;\n  UInt32 _streamPos;\n  UInt32 _bufferSize;\n  CMyComPtr<ISequentialOutStream> _stream;\n  UInt64 _processedSize;\n  Byte  *_buffer2;\n  bool _overDict;\n\n  HRESULT FlushPart();\npublic:\n  #ifdef _NO_EXCEPTIONS\n  HRESULT ErrorCode;\n  #endif\n\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\n  ~COutBuffer() { Free(); }\n  \n  bool Create(UInt32 bufferSize);\n  void Free();\n\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\n  void SetStream(ISequentialOutStream *stream);\n  void Init();\n  HRESULT Flush();\n  void FlushWithCheck();\n  void ReleaseStream() {  _stream.Release(); }\n\n  void WriteByte(Byte b)\n  {\n    _buffer[_pos++] = b;\n    if(_pos == _limitPos)\n      FlushWithCheck();\n  }\n  void WriteBytes(const void *data, size_t size)\n  {\n    for (size_t i = 0; i < size; i++)\n      WriteByte(((const Byte *)data)[i]);\n  }\n\n  UInt64 GetProcessedSize() const;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/ProgressUtils.cpp",
    "content": "// ProgressUtils.h\n\n#include \"StdAfx.h\"\n\n#include \"ProgressUtils.h\"\n\nCLocalProgress::CLocalProgress()\n{\n  ProgressOffset = InSize = OutSize = 0;\n  SendRatio = SendProgress = true;\n}\n\nvoid CLocalProgress::Init(IProgress *progress, bool inSizeIsMain)\n{\n  _ratioProgress.Release();\n  _progress = progress;\n  _progress.QueryInterface(IID_ICompressProgressInfo, &_ratioProgress);\n  _inSizeIsMain = inSizeIsMain;\n}\n\nSTDMETHODIMP CLocalProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\n{\n  UInt64 inSizeNew = InSize, outSizeNew = OutSize;\n  if (inSize)\n    inSizeNew += (*inSize);\n  if (outSize)\n    outSizeNew += (*outSize);\n  if (SendRatio && _ratioProgress)\n  {\n    RINOK(_ratioProgress->SetRatioInfo(&inSizeNew, &outSizeNew));\n  }\n  inSizeNew += ProgressOffset;\n  outSizeNew += ProgressOffset;\n  if (SendProgress)\n    return _progress->SetCompleted(_inSizeIsMain ? &inSizeNew : &outSizeNew);\n  return S_OK;\n}\n\nHRESULT CLocalProgress::SetCur()\n{\n  return SetRatioInfo(NULL, NULL);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/ProgressUtils.h",
    "content": "// ProgressUtils.h\n\n#ifndef __PROGRESSUTILS_H\n#define __PROGRESSUTILS_H\n\n#include \"../../Common/MyCom.h\"\n\n#include \"../ICoder.h\"\n#include \"../IProgress.h\"\n\nclass CLocalProgress:\n  public ICompressProgressInfo,\n  public CMyUnknownImp\n{\n  CMyComPtr<IProgress> _progress;\n  CMyComPtr<ICompressProgressInfo> _ratioProgress;\n  bool _inSizeIsMain;\npublic:\n  UInt64 ProgressOffset;\n  UInt64 InSize;\n  UInt64 OutSize;\n  bool SendRatio;\n  bool SendProgress;\n\n  CLocalProgress();\n  void Init(IProgress *progress, bool inSizeIsMain);\n  HRESULT SetCur();\n\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/RegisterArc.h",
    "content": "// RegisterArc.h\n\n#ifndef __REGISTERARC_H\n#define __REGISTERARC_H\n\n#include \"../Archive/IArchive.h\"\n\ntypedef IInArchive * (*CreateInArchiveP)();\ntypedef IOutArchive * (*CreateOutArchiveP)();\n\nstruct CArcInfo\n{\n  const wchar_t *Name;\n  const wchar_t *Ext;\n  const wchar_t *AddExt;\n  Byte ClassId;\n  Byte Signature[16];\n  int SignatureSize;\n  bool KeepName;\n  CreateInArchiveP CreateInArchive;\n  CreateOutArchiveP CreateOutArchive;\n};\n\nvoid RegisterArc(const CArcInfo *arcInfo);\n\n#define REGISTER_ARC_NAME(x) CRegister ## x\n\n#define REGISTER_ARC_DEC_SIG(x) struct REGISTER_ARC_NAME(x) { \\\n    REGISTER_ARC_NAME(x)() { g_ArcInfo.Signature[0]--; RegisterArc(&g_ArcInfo); }}; \\\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\n\n#define REGISTER_ARC(x) struct REGISTER_ARC_NAME(x) { \\\n    REGISTER_ARC_NAME(x)() { RegisterArc(&g_ArcInfo); }}; \\\n    static REGISTER_ARC_NAME(x) g_RegisterArc;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/RegisterCodec.h",
    "content": "// RegisterCodec.h\n\n#ifndef __REGISTERCODEC_H\n#define __REGISTERCODEC_H\n\n#include \"../Common/MethodId.h\"\n\ntypedef void * (*CreateCodecP)();\nstruct CCodecInfo\n{\n  CreateCodecP CreateDecoder;\n  CreateCodecP CreateEncoder;\n  CMethodId Id;\n  const wchar_t *Name;\n  UInt32 NumInStreams;\n  bool IsFilter;\n};\n\nvoid RegisterCodec(const CCodecInfo *codecInfo);\n\n#define REGISTER_CODEC_NAME(x) CRegisterCodec ## x\n\n#define REGISTER_CODEC(x) struct REGISTER_CODEC_NAME(x) { \\\n    REGISTER_CODEC_NAME(x)() { RegisterCodec(&g_CodecInfo); }}; \\\n    static REGISTER_CODEC_NAME(x) g_RegisterCodec;\n\n#define REGISTER_CODECS_NAME(x) CRegisterCodecs ## x\n#define REGISTER_CODECS(x) struct REGISTER_CODECS_NAME(x) { \\\n    REGISTER_CODECS_NAME(x)() { for (int i = 0; i < sizeof(g_CodecsInfo) / sizeof(g_CodecsInfo[0]); i++) \\\n    RegisterCodec(&g_CodecsInfo[i]); }}; \\\n    static REGISTER_CODECS_NAME(x) g_RegisterCodecs;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../Common/MyWindows.h\"\n#include \"../../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/StreamBinder.cpp",
    "content": "// StreamBinder.cpp\n\n#include \"StdAfx.h\"\n\n#include \"StreamBinder.h\"\n#include \"../../Common/Defs.h\"\n#include \"../../Common/MyCom.h\"\n\nusing namespace NWindows;\nusing namespace NSynchronization;\n\nclass CSequentialInStreamForBinder:\n  public ISequentialInStream,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\nprivate:\n  CStreamBinder *m_StreamBinder;\npublic:\n  ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); }\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\n};\n\nSTDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\n  { return m_StreamBinder->Read(data, size, processedSize); }\n\nclass CSequentialOutStreamForBinder:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n\nprivate:\n  CStreamBinder *m_StreamBinder;\npublic:\n  ~CSequentialOutStreamForBinder() {  m_StreamBinder->CloseWrite(); }\n  void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; }\n};\n\nSTDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\n  { return m_StreamBinder->Write(data, size, processedSize); }\n\n\n//////////////////////////\n// CStreamBinder\n// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished.\n\nHRes CStreamBinder::CreateEvents()\n{\n  RINOK(_allBytesAreWritenEvent.Create(true));\n  RINOK(_thereAreBytesToReadEvent.Create());\n  return _readStreamIsClosedEvent.Create();\n}\n\nvoid CStreamBinder::ReInit()\n{\n  _thereAreBytesToReadEvent.Reset();\n  _readStreamIsClosedEvent.Reset();\n  ProcessedSize = 0;\n}\n\n\n  \nvoid CStreamBinder::CreateStreams(ISequentialInStream **inStream,\n      ISequentialOutStream **outStream)\n{\n  CSequentialInStreamForBinder *inStreamSpec = new\n      CSequentialInStreamForBinder;\n  CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\n  inStreamSpec->SetBinder(this);\n  *inStream = inStreamLoc.Detach();\n\n  CSequentialOutStreamForBinder *outStreamSpec = new\n      CSequentialOutStreamForBinder;\n  CMyComPtr<ISequentialOutStream> outStreamLoc(outStreamSpec);\n  outStreamSpec->SetBinder(this);\n  *outStream = outStreamLoc.Detach();\n\n  _buffer = NULL;\n  _bufferSize= 0;\n  ProcessedSize = 0;\n}\n\nHRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 sizeToRead = size;\n  if (size > 0)\n  {\n    RINOK(_thereAreBytesToReadEvent.Lock());\n    sizeToRead = MyMin(_bufferSize, size);\n    if (_bufferSize > 0)\n    {\n      memcpy(data, _buffer, sizeToRead);\n      _buffer = ((const Byte *)_buffer) + sizeToRead;\n      _bufferSize -= sizeToRead;\n      if (_bufferSize == 0)\n      {\n        _thereAreBytesToReadEvent.Reset();\n        _allBytesAreWritenEvent.Set();\n      }\n    }\n  }\n  if (processedSize != NULL)\n    *processedSize = sizeToRead;\n  ProcessedSize += sizeToRead;\n  return S_OK;\n}\n\nvoid CStreamBinder::CloseRead()\n{\n  _readStreamIsClosedEvent.Set();\n}\n\nHRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  if (size > 0)\n  {\n    _buffer = data;\n    _bufferSize = size;\n    _allBytesAreWritenEvent.Reset();\n    _thereAreBytesToReadEvent.Set();\n\n    HANDLE events[2];\n    events[0] = _allBytesAreWritenEvent;\n    events[1] = _readStreamIsClosedEvent;\n    DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);\n    if (waitResult != WAIT_OBJECT_0 + 0)\n    {\n      // ReadingWasClosed = true;\n      return S_FALSE;\n    }\n    // if(!_allBytesAreWritenEvent.Lock())\n    //   return E_FAIL;\n  }\n  if (processedSize != NULL)\n    *processedSize = size;\n  return S_OK;\n}\n\nvoid CStreamBinder::CloseWrite()\n{\n  // _bufferSize must be = 0\n  _thereAreBytesToReadEvent.Set();\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/StreamBinder.h",
    "content": "// StreamBinder.h\n\n#ifndef __STREAMBINDER_H\n#define __STREAMBINDER_H\n\n#include \"../IStream.h\"\n#include \"../../Windows/Synchronization.h\"\n\nclass CStreamBinder\n{\n  NWindows::NSynchronization::CManualResetEvent _allBytesAreWritenEvent;\n  NWindows::NSynchronization::CManualResetEvent _thereAreBytesToReadEvent;\n  NWindows::NSynchronization::CManualResetEvent _readStreamIsClosedEvent;\n  UInt32 _bufferSize;\n  const void *_buffer;\npublic:\n  // bool ReadingWasClosed;\n  UInt64 ProcessedSize;\n  CStreamBinder() {}\n  HRes CreateEvents();\n\n  void CreateStreams(ISequentialInStream **inStream,\n      ISequentialOutStream **outStream);\n  HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);\n  void CloseRead();\n\n  HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize);\n  void CloseWrite();\n  void ReInit();\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/StreamObjects.cpp",
    "content": "// StreamObjects.cpp\n\n#include \"StdAfx.h\"\n\n#include \"StreamObjects.h\"\n#include \"../../Common/Defs.h\"\n\n\nSTDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  size_t rem = _size - _pos;\n  if (size < rem)\n    rem = (size_t)size;\n  memcpy(data, _dataPointer + _pos, rem);\n  _pos += rem;\n  if (processedSize != NULL)\n    *processedSize = (UInt32)rem;\n  return S_OK;\n}\n\n\nvoid CWriteBuffer::Write(const void *data, size_t size)\n{\n  size_t newCapacity = _size + size;\n  _buffer.EnsureCapacity(newCapacity);\n  memcpy(_buffer + _size, data, size);\n  _size += size;\n}\n\nSTDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  _writeBuffer.Write(data, (size_t)size);\n  if(processedSize != NULL)\n    *processedSize = size;\n  return S_OK;\n}\n\nSTDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  size_t rem = _size - _pos;\n  if (size < rem)\n    rem = (size_t)size;\n  memcpy(_buffer + _pos, data, rem);\n  _pos += rem;\n  if (processedSize != NULL)\n    *processedSize = (UInt32)rem;\n  return (rem == size ? S_OK : E_FAIL);\n}\n\nSTDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize;\n  HRESULT result = _stream->Read(data, size, &realProcessedSize);\n  _size += realProcessedSize;\n  if (processedSize != 0)\n    *processedSize = realProcessedSize;\n  return result;\n}\n\nSTDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 realProcessedSize;\n  HRESULT result = _stream->Write(data, size, &realProcessedSize);\n  _size += realProcessedSize;\n  if (processedSize != 0)\n    *processedSize = realProcessedSize;\n  return result;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/StreamObjects.h",
    "content": "// StreamObjects.h\n\n#ifndef __STREAMOBJECTS_H\n#define __STREAMOBJECTS_H\n\n#include \"../../Common/DynamicBuffer.h\"\n#include \"../../Common/MyCom.h\"\n#include \"../IStream.h\"\n\nclass CSequentialInStreamImp:\n  public ISequentialInStream,\n  public CMyUnknownImp\n{\n  const Byte *_dataPointer;\n  size_t _size;\n  size_t _pos;\n\npublic:\n  void Init(const Byte *dataPointer, size_t size)\n  {\n    _dataPointer = dataPointer;\n    _size = size;\n    _pos = 0;\n  }\n\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n};\n\n\nclass CWriteBuffer\n{\n  CByteDynamicBuffer _buffer;\n  size_t _size;\npublic:\n  CWriteBuffer(): _size(0) {}\n  void Init() { _size = 0;  }\n  void Write(const void *data, size_t size);\n  size_t GetSize() const { return _size; }\n  const CByteDynamicBuffer& GetBuffer() const { return _buffer; }\n};\n\nclass CSequentialOutStreamImp:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\n  CWriteBuffer _writeBuffer;\npublic:\n  void Init() { _writeBuffer.Init(); }\n  size_t GetSize() const { return _writeBuffer.GetSize(); }\n  const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); }\n\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\nclass CSequentialOutStreamImp2:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\n  Byte *_buffer;\n  size_t _size;\n  size_t _pos;\npublic:\n\n  void Init(Byte *buffer, size_t size)\n  {\n    _buffer = buffer;\n    _pos = 0;\n    _size = size;\n  }\n\n  size_t GetPos() const { return _pos; }\n\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\nclass CSequentialInStreamSizeCount:\n  public ISequentialInStream,\n  public CMyUnknownImp\n{\n  CMyComPtr<ISequentialInStream> _stream;\n  UInt64 _size;\npublic:\n  void Init(ISequentialInStream *stream)\n  {\n    _stream = stream;\n    _size = 0;\n  }\n  UInt64 GetSize() const { return _size; }\n\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n};\n\nclass CSequentialOutStreamSizeCount:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\n  CMyComPtr<ISequentialOutStream> _stream;\n  UInt64 _size;\npublic:\n  void SetStream(ISequentialOutStream *stream) { _stream = stream; }\n  void Init() { _size = 0; }\n  UInt64 GetSize() const { return _size; }\n\n  MY_UNKNOWN_IMP\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\n\n#include \"StdAfx.h\"\n\n#include \"StreamUtils.h\"\n\nstatic const UInt32 kBlockSize = ((UInt32)1 << 31);\n\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *processedSize)\n{\n  size_t size = *processedSize;\n  *processedSize = 0;\n  while (size != 0)\n  {\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\n    UInt32 processedSizeLoc;\n    HRESULT res = stream->Read(data, curSize, &processedSizeLoc);\n    *processedSize += processedSizeLoc;\n    data = (void *)((Byte *)data + processedSizeLoc);\n    size -= processedSizeLoc;\n    RINOK(res);\n    if (processedSizeLoc == 0)\n      return S_OK;\n  }\n  return S_OK;\n}\n\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size)\n{\n  size_t processedSize = size;\n  RINOK(ReadStream(stream, data, &processedSize));\n  return (size == processedSize) ? S_OK : S_FALSE;\n}\n\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size)\n{\n  size_t processedSize = size;\n  RINOK(ReadStream(stream, data, &processedSize));\n  return (size == processedSize) ? S_OK : E_FAIL;\n}\n\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size)\n{\n  while (size != 0)\n  {\n    UInt32 curSize = (size < kBlockSize) ? (UInt32)size : kBlockSize;\n    UInt32 processedSizeLoc;\n    HRESULT res = stream->Write(data, curSize, &processedSizeLoc);\n    data = (const void *)((const Byte *)data + processedSizeLoc);\n    size -= processedSizeLoc;\n    RINOK(res);\n    if (processedSizeLoc == 0)\n      return E_FAIL;\n  }\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\n\n#ifndef __STREAMUTILS_H\n#define __STREAMUTILS_H\n\n#include \"../IStream.h\"\n\nHRESULT ReadStream(ISequentialInStream *stream, void *data, size_t *size);\nHRESULT ReadStream_FALSE(ISequentialInStream *stream, void *data, size_t size);\nHRESULT ReadStream_FAIL(ISequentialInStream *stream, void *data, size_t size);\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, size_t size);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/VirtThread.cpp",
    "content": "// VirtThread.cpp\n\n#include \"StdAfx.h\"\n\n#include \"VirtThread.h\"\n\nstatic THREAD_FUNC_DECL CoderThread(void *p)\n{\n  for (;;)\n  {\n    CVirtThread *t = (CVirtThread *)p;\n    t->StartEvent.Lock();\n    if (t->ExitEvent)\n      return 0;\n    t->Execute();\n    t->FinishedEvent.Set();\n  }\n}\n\nWRes CVirtThread::Create()\n{\n  RINOK(StartEvent.CreateIfNotCreated());\n  RINOK(FinishedEvent.CreateIfNotCreated());\n  StartEvent.Reset();\n  FinishedEvent.Reset();\n  ExitEvent = false;\n  if (Thread.IsCreated())\n    return S_OK;\n  return Thread.Create(CoderThread, this);\n}\n\nvoid CVirtThread::Start()\n{\n  ExitEvent = false;\n  StartEvent.Set();\n}\n\nCVirtThread::~CVirtThread()\n{\n  ExitEvent = true;\n  if (StartEvent.IsCreated())\n    StartEvent.Set();\n  Thread.Wait();\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Common/VirtThread.h",
    "content": "// VirtThread.h\n\n#ifndef __VIRTTHREAD_H\n#define __VIRTTHREAD_H\n\n#include \"../../Windows/Synchronization.h\"\n#include \"../../Windows/Thread.h\"\n\nstruct CVirtThread\n{\n  NWindows::NSynchronization::CAutoResetEvent StartEvent;\n  NWindows::NSynchronization::CAutoResetEvent FinishedEvent;\n  NWindows::CThread Thread;\n  bool ExitEvent;\n\n  ~CVirtThread();\n  WRes Create();\n  void Start();\n  void WaitFinish() { FinishedEvent.Lock(); }\n  virtual void Execute() = 0;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/Bcj2Coder.cpp",
    "content": "// Bcj2Coder.cpp\n\n#include \"StdAfx.h\"\n\nextern \"C\"\n{\n#include \"../../../C/Alloc.h\"\n}\n\n#include \"Bcj2Coder.h\"\n\nnamespace NCompress {\nnamespace NBcj2 {\n\ninline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }\ninline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }\ninline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }\n\n#ifndef EXTRACT_ONLY\n\nstatic const int kBufferSize = 1 << 17;\n\nstatic bool inline Test86MSByte(Byte b)\n{\n  return (b == 0 || b == 0xFF);\n}\n\nbool CEncoder::Create()\n{\n  if (!_mainStream.Create(1 << 16))\n    return false;\n  if (!_callStream.Create(1 << 20))\n    return false;\n  if (!_jumpStream.Create(1 << 20))\n    return false;\n  if (!_rangeEncoder.Create(1 << 20))\n    return false;\n  if (_buffer == 0)\n  {\n    _buffer = (Byte *)MidAlloc(kBufferSize);\n    if (_buffer == 0)\n      return false;\n  }\n  return true;\n}\n\nCEncoder::~CEncoder()\n{\n  ::MidFree(_buffer);\n}\n\nHRESULT CEncoder::Flush()\n{\n  RINOK(_mainStream.Flush());\n  RINOK(_callStream.Flush());\n  RINOK(_jumpStream.Flush());\n  _rangeEncoder.FlushData();\n  return _rangeEncoder.FlushStream();\n}\n\nconst UInt32 kDefaultLimit = (1 << 24);\n\nHRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 ** /* outSizes */,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress)\n{\n  if (numInStreams != 1 || numOutStreams != 4)\n    return E_INVALIDARG;\n\n  if (!Create())\n    return E_OUTOFMEMORY;\n\n  bool sizeIsDefined = false;\n  UInt64 inSize = 0;\n  if (inSizes != NULL)\n    if (inSizes[0] != NULL)\n    {\n      inSize = *inSizes[0];\n      if (inSize <= kDefaultLimit)\n        sizeIsDefined = true;\n    }\n\n  ISequentialInStream *inStream = inStreams[0];\n\n  _mainStream.SetStream(outStreams[0]);\n  _mainStream.Init();\n  _callStream.SetStream(outStreams[1]);\n  _callStream.Init();\n  _jumpStream.SetStream(outStreams[2]);\n  _jumpStream.Init();\n  _rangeEncoder.SetStream(outStreams[3]);\n  _rangeEncoder.Init();\n  for (int i = 0; i < 256 + 2; i++)\n    _statusEncoder[i].Init();\n  CCoderReleaser releaser(this);\n\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\n  {\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\n  }\n\n  UInt32 nowPos = 0;\n  UInt64 nowPos64 = 0;\n  UInt32 bufferPos = 0;\n\n  Byte prevByte = 0;\n\n  UInt64 subStreamIndex = 0;\n  UInt64 subStreamStartPos  = 0;\n  UInt64 subStreamEndPos = 0;\n\n  for (;;)\n  {\n    UInt32 processedSize = 0;\n    for (;;)\n    {\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\n      UInt32 processedSizeLoc;\n      if (size == 0)\n        break;\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\n      if (processedSizeLoc == 0)\n        break;\n      processedSize += processedSizeLoc;\n    }\n    UInt32 endPos = bufferPos + processedSize;\n    \n    if (endPos < 5)\n    {\n      // change it\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\n      {\n        Byte b = _buffer[bufferPos];\n        _mainStream.WriteByte(b);\n        UInt32 index;\n        if (b == 0xE8)\n          index = prevByte;\n        else if (b == 0xE9)\n          index = 256;\n        else if (IsJcc(prevByte, b))\n          index = 257;\n        else\n        {\n          prevByte = b;\n          continue;\n        }\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\n        prevByte = b;\n      }\n      return Flush();\n    }\n\n    bufferPos = 0;\n\n    UInt32 limit = endPos - 5;\n    while(bufferPos <= limit)\n    {\n      Byte b = _buffer[bufferPos];\n      _mainStream.WriteByte(b);\n      if (!IsJ(prevByte, b))\n      {\n        bufferPos++;\n        prevByte = b;\n        continue;\n      }\n      Byte nextByte = _buffer[bufferPos + 4];\n      UInt32 src =\n        (UInt32(nextByte) << 24) |\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\n        (_buffer[bufferPos + 1]);\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\n      // if (Test86MSByte(nextByte))\n      bool convert;\n      if (getSubStreamSize != NULL)\n      {\n        UInt64 currentPos = (nowPos64 + bufferPos);\n        while (subStreamEndPos < currentPos)\n        {\n          UInt64 subStreamSize;\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\n          if (result == S_OK)\n          {\n            subStreamStartPos = subStreamEndPos;\n            subStreamEndPos += subStreamSize;\n            subStreamIndex++;\n          }\n          else if (result == S_FALSE || result == E_NOTIMPL)\n          {\n            getSubStreamSize.Release();\n            subStreamStartPos = 0;\n            subStreamEndPos = subStreamStartPos - 1;\n          }\n          else\n            return result;\n        }\n        if (getSubStreamSize == NULL)\n        {\n          if (sizeIsDefined)\n            convert = (dest < inSize);\n          else\n            convert = Test86MSByte(nextByte);\n        }\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\n          convert = Test86MSByte(nextByte);\n        else\n        {\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\n        }\n      }\n      else if (sizeIsDefined)\n        convert = (dest < inSize);\n      else\n        convert = Test86MSByte(nextByte);\n      unsigned index = GetIndex(prevByte, b);\n      if (convert)\n      {\n        _statusEncoder[index].Encode(&_rangeEncoder, 1);\n        bufferPos += 5;\n        COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\n        for (int i = 24; i >= 0; i -= 8)\n          s.WriteByte((Byte)(dest >> i));\n        prevByte = nextByte;\n      }\n      else\n      {\n        _statusEncoder[index].Encode(&_rangeEncoder, 0);\n        bufferPos++;\n        prevByte = b;\n      }\n    }\n    nowPos += bufferPos;\n    nowPos64 += bufferPos;\n\n    if (progress != NULL)\n    {\n      /*\n      const UInt64 compressedSize =\n        _mainStream.GetProcessedSize() +\n        _callStream.GetProcessedSize() +\n        _jumpStream.GetProcessedSize() +\n        _rangeEncoder.GetProcessedSize();\n      */\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\n    }\n \n    UInt32 i = 0;\n    while(bufferPos < endPos)\n      _buffer[i++] = _buffer[bufferPos++];\n    bufferPos = i;\n  }\n}\n\nSTDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress)\n{\n  try\n  {\n    return CodeReal(inStreams, inSizes, numInStreams,\n      outStreams, outSizes,numOutStreams, progress);\n  }\n  catch(const COutBufferException &e) { return e.ErrorCode; }\n  catch(...) { return S_FALSE; }\n}\n\n#endif\n\nHRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,\n      const UInt64 ** /* inSizes */,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 ** /* outSizes */,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress)\n{\n  if (numInStreams != 4 || numOutStreams != 1)\n    return E_INVALIDARG;\n\n  if (!_mainInStream.Create(1 << 16))\n    return E_OUTOFMEMORY;\n  if (!_callStream.Create(1 << 20))\n    return E_OUTOFMEMORY;\n  if (!_jumpStream.Create(1 << 16))\n    return E_OUTOFMEMORY;\n  if (!_rangeDecoder.Create(1 << 20))\n    return E_OUTOFMEMORY;\n  if (!_outStream.Create(1 << 16))\n    return E_OUTOFMEMORY;\n\n  _mainInStream.SetStream(inStreams[0]);\n  _callStream.SetStream(inStreams[1]);\n  _jumpStream.SetStream(inStreams[2]);\n  _rangeDecoder.SetStream(inStreams[3]);\n  _outStream.SetStream(outStreams[0]);\n\n  _mainInStream.Init();\n  _callStream.Init();\n  _jumpStream.Init();\n  _rangeDecoder.Init();\n  _outStream.Init();\n\n  for (int i = 0; i < 256 + 2; i++)\n    _statusDecoder[i].Init();\n\n  CCoderReleaser releaser(this);\n\n  Byte prevByte = 0;\n  UInt32 processedBytes = 0;\n  for (;;)\n  {\n    if (processedBytes >= (1 << 20) && progress != NULL)\n    {\n      /*\n      const UInt64 compressedSize =\n        _mainInStream.GetProcessedSize() +\n        _callStream.GetProcessedSize() +\n        _jumpStream.GetProcessedSize() +\n        _rangeDecoder.GetProcessedSize();\n      */\n      const UInt64 nowPos64 = _outStream.GetProcessedSize();\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\n      processedBytes = 0;\n    }\n    UInt32 i;\n    Byte b = 0;\n    const UInt32 kBurstSize = (1 << 18);\n    for (i = 0; i < kBurstSize; i++)\n    {\n      if (!_mainInStream.ReadByte(b))\n        return Flush();\n      _outStream.WriteByte(b);\n      if (IsJ(prevByte, b))\n        break;\n      prevByte = b;\n    }\n    processedBytes += i;\n    if (i == kBurstSize)\n      continue;\n    unsigned index = GetIndex(prevByte, b);\n    if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)\n    {\n      UInt32 src = 0;\n      CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;\n      for (int i = 0; i < 4; i++)\n      {\n        Byte b0;\n        if(!s.ReadByte(b0))\n          return S_FALSE;\n        src <<= 8;\n        src |= ((UInt32)b0);\n      }\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\n      _outStream.WriteByte((Byte)(dest));\n      _outStream.WriteByte((Byte)(dest >> 8));\n      _outStream.WriteByte((Byte)(dest >> 16));\n      _outStream.WriteByte((Byte)(dest >> 24));\n      prevByte = (Byte)(dest >> 24);\n      processedBytes += 4;\n    }\n    else\n      prevByte = b;\n  }\n}\n\nSTDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress)\n{\n  try\n  {\n    return CodeReal(inStreams, inSizes, numInStreams,\n        outStreams, outSizes,numOutStreams, progress);\n  }\n  catch(const CInBufferException &e) { return e.ErrorCode; }\n  catch(const COutBufferException &e) { return e.ErrorCode; }\n  catch(...) { return S_FALSE; }\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/Bcj2Coder.h",
    "content": "// Bcj2Coder.h\n\n#ifndef __COMPRESS_BCJ2_CODER_H\n#define __COMPRESS_BCJ2_CODER_H\n\n#include \"../../Common/MyCom.h\"\n\n#include \"../ICoder.h\"\n\n#include \"RangeCoderBit.h\"\n\nnamespace NCompress {\nnamespace NBcj2 {\n\nconst int kNumMoveBits = 5;\n\n#ifndef EXTRACT_ONLY\n\nclass CEncoder:\n  public ICompressCoder2,\n  public CMyUnknownImp\n{\n  Byte *_buffer;\npublic:\n  CEncoder(): _buffer(0) {};\n  ~CEncoder();\n  bool Create();\n\n  COutBuffer _mainStream;\n  COutBuffer _callStream;\n  COutBuffer _jumpStream;\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];\n\n  HRESULT Flush();\n  void ReleaseStreams()\n  {\n    _mainStream.ReleaseStream();\n    _callStream.ReleaseStream();\n    _jumpStream.ReleaseStream();\n    _rangeEncoder.ReleaseStream();\n  }\n\n  class CCoderReleaser\n  {\n    CEncoder *_coder;\n  public:\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\n  };\n\npublic:\n\n  MY_UNKNOWN_IMP\n\n  HRESULT CodeReal(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress);\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress);\n};\n\n#endif\n\nclass CDecoder:\n  public ICompressCoder2,\n  public CMyUnknownImp\n{\npublic:\n  CInBuffer _mainInStream;\n  CInBuffer _callStream;\n  CInBuffer _jumpStream;\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];\n\n  COutBuffer _outStream;\n\n  void ReleaseStreams()\n  {\n    _mainInStream.ReleaseStream();\n    _callStream.ReleaseStream();\n    _jumpStream.ReleaseStream();\n    _rangeDecoder.ReleaseStream();\n    _outStream.ReleaseStream();\n  }\n\n  HRESULT Flush() { return _outStream.Flush(); }\n  class CCoderReleaser\n  {\n    CDecoder *_coder;\n  public:\n    CCoderReleaser(CDecoder *coder): _coder(coder) {}\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\n  };\n\npublic:\n  MY_UNKNOWN_IMP\n  HRESULT CodeReal(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress);\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress);\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/Bcj2Register.cpp",
    "content": "// Bcj2Register.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../Common/RegisterCodec.h\"\n\n#include \"Bcj2Coder.h\"\n\nstatic void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }\n#ifndef EXTRACT_ONLY\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder());  }\n#else\n#define CreateCodecOut 0\n#endif\n\nstatic CCodecInfo g_CodecInfo =\n  { CreateCodec, CreateCodecOut, 0x0303011B, L\"BCJ2\", 4, false };\n\nREGISTER_CODEC(BCJ2)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/BcjCoder.cpp",
    "content": "// BcjCoder.cpp\n\n#include \"StdAfx.h\"\n\n#include \"BcjCoder.h\"\n\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\n{\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);\n}\n\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\n{\n  return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/BcjCoder.h",
    "content": "// BcjCoder.h\n\n#ifndef __COMPRESS_BCJ_CODER_H\n#define __COMPRESS_BCJ_CODER_H\n\nextern \"C\"\n{\n#include \"../../../C/Bra.h\"\n}\n\n#include \"BranchCoder.h\"\n\nstruct CBranch86\n{\n  UInt32 _prevMask;\n  void x86Init() { x86_Convert_Init(_prevMask); }\n};\n\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 ,\n    virtual void SubInit() { x86Init(); })\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/BcjRegister.cpp",
    "content": "// BcjRegister.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../Common/RegisterCodec.h\"\n\n#include \"BcjCoder.h\"\n\nstatic void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }\n#ifndef EXTRACT_ONLY\nstatic void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder());  }\n#else\n#define CreateCodecOut 0\n#endif\n\nstatic CCodecInfo g_CodecInfo =\n  { CreateCodec, CreateCodecOut, 0x03030103, L\"BCJ\", 1, true };\n\nREGISTER_CODEC(BCJ)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\n\n#include \"StdAfx.h\"\n\n#include \"BranchCoder.h\"\n\nSTDMETHODIMP CBranchConverter::Init()\n{\n  _bufferPos = 0;\n  SubInit();\n  return S_OK;\n}\n\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\n{\n  UInt32 processedSize = SubFilter(data, size);\n  _bufferPos += processedSize;\n  return processedSize;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/BranchCoder.h",
    "content": "// BranchCoder.h\n\n#ifndef __COMPRESS_BRANCH_CODER_H\n#define __COMPRESS_BRANCH_CODER_H\n\n#include \"../../Common/MyCom.h\"\n\n#include \"../ICoder.h\"\n\nclass CBranchConverter:\n  public ICompressFilter,\n  public CMyUnknownImp\n{\nprotected:\n  UInt32 _bufferPos;\n  virtual void SubInit() {}\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\npublic:\n  MY_UNKNOWN_IMP;\n  STDMETHOD(Init)();\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\n};\n\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\n\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); };\n\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\n\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};\n\n#define MyClassA(Name, id, subId)  \\\nMyClassEncoderA(Name ## _Encoder) \\\nMyClassDecoderA(Name ## _Decoder)\n\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/BranchMisc.cpp",
    "content": "// BranchMisc.cpp\n\n#include \"StdAfx.h\"\n\nextern \"C\"\n{\n#include \"../../../C/Bra.h\"\n}\n\n#include \"BranchMisc.h\"\n\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); }\n\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\n  { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); }\n\nUInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size)\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); }\n\nUInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size)\n  { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); }\n\nUInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size)\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); }\n\nUInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size)\n  { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); }\n\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); }\n\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\n  { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); }\n\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\n  { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); }\n\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\n  {  return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); }\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/BranchMisc.h",
    "content": "// BranchMisc.h\n\n#ifndef __COMPRESS_BRANCH_MISC_H\n#define __COMPRESS_BRANCH_MISC_H\n\n#include \"BranchCoder.h\"\n\nMyClassA(BC_ARM,   0x05, 1)\nMyClassA(BC_ARMT,  0x07, 1)\nMyClassA(BC_PPC,   0x02, 5)\nMyClassA(BC_SPARC, 0x08, 5)\nMyClassA(BC_IA64,  0x04, 1)\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/BranchRegister.cpp",
    "content": "// BranchRegister.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../Common/RegisterCodec.h\"\n\n#include \"BranchMisc.h\"\n\n#define CREATE_CODEC(x) \\\n  static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \\\n  static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }\n\nCREATE_CODEC(BC_PPC)\nCREATE_CODEC(BC_IA64)\nCREATE_CODEC(BC_ARM)\nCREATE_CODEC(BC_ARMT)\nCREATE_CODEC(BC_SPARC)\n\n#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true  }\n\nstatic CCodecInfo g_CodecsInfo[] =\n{\n  METHOD_ITEM(BC_PPC,   0x02, 0x05, L\"PPC\"),\n  METHOD_ITEM(BC_IA64,  0x04, 1, L\"IA64\"),\n  METHOD_ITEM(BC_ARM,   0x05, 1, L\"ARM\"),\n  METHOD_ITEM(BC_ARMT,  0x07, 1, L\"ARMT\"),\n  METHOD_ITEM(BC_SPARC, 0x08, 0x05, L\"SPARC\")\n};\n\nREGISTER_CODECS(Branch)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/ByteSwap.cpp",
    "content": "// ByteSwap.cpp\n\n#include \"StdAfx.h\"\n\n#include \"ByteSwap.h\"\n\nSTDMETHODIMP CByteSwap2::Init() { return S_OK; }\n\nSTDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)\n{\n  const UInt32 kStep = 2;\n  UInt32 i;\n  for (i = 0; i + kStep <= size; i += kStep)\n  {\n    Byte b = data[i];\n    data[i] = data[i + 1];\n    data[i + 1] = b;\n  }\n  return i;\n}\n\nSTDMETHODIMP CByteSwap4::Init() { return S_OK; }\n\nSTDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)\n{\n  const UInt32 kStep = 4;\n  UInt32 i;\n  for (i = 0; i + kStep <= size; i += kStep)\n  {\n    Byte b0 = data[i];\n    Byte b1 = data[i + 1];\n    data[i] = data[i + 3];\n    data[i + 1] = data[i + 2];\n    data[i + 2] = b1;\n    data[i + 3] = b0;\n  }\n  return i;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/ByteSwap.h",
    "content": "// ByteSwap.h\n\n#ifndef __COMPRESS_BYTE_SWAP_H\n#define __COMPRESS_BYTE_SWAP_H\n\n#include \"../../Common/MyCom.h\"\n\n#include \"../ICoder.h\"\n\nclass CByteSwap2:\n  public ICompressFilter,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n  STDMETHOD(Init)();\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\n};\n\nclass CByteSwap4:\n  public ICompressFilter,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n  STDMETHOD(Init)();\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/ByteSwapRegister.cpp",
    "content": "// ByteSwapRegister.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../Common/RegisterCodec.h\"\n\n#include \"ByteSwap.h\"\n\nstatic void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }\nstatic void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }\n\nstatic CCodecInfo g_CodecsInfo[] =\n{\n  { CreateCodec2, CreateCodec4, 0x020302, L\"Swap2\", 1, true },\n  { CreateCodec4, CreateCodec4, 0x020304, L\"Swap4\", 1, true }\n};\n\nREGISTER_CODECS(ByteSwap)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/CodecExports.cpp",
    "content": "// CodecExports.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../Common/ComTry.h\"\n#include \"../../Windows/PropVariant.h\"\n#include \"../Common/RegisterCodec.h\"\n#include \"../ICoder.h\"\n\nextern unsigned int g_NumCodecs;\nextern const CCodecInfo *g_Codecs[];\n\nstatic const UInt16 kDecodeId = 0x2790;\n\nDEFINE_GUID(CLSID_CCodec,\n0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\n\nstatic inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)\n{\n  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)\n    value->vt = VT_BSTR;\n  return S_OK;\n}\n\nstatic inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)\n{\n  return SetPropString((const char *)&guid, sizeof(GUID), value);\n}\n\nstatic HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)\n{\n  GUID clsId = CLSID_CCodec;\n  for (int i = 0; i < sizeof(id); i++, id >>= 8)\n    clsId.Data4[i] = (Byte)(id & 0xFF);\n  if (encode)\n    clsId.Data3++;\n  return SetPropGUID(clsId, value);\n}\n\nstatic HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)\n{\n  index = -1;\n  if (clsID->Data1 != CLSID_CCodec.Data1 ||\n      clsID->Data2 != CLSID_CCodec.Data2 ||\n      (clsID->Data3 & ~1) != kDecodeId)\n    return S_OK;\n  encode = (clsID->Data3 != kDecodeId);\n  UInt64 id = 0;\n  for (int j = 0; j < 8; j++)\n    id |= ((UInt64)clsID->Data4[j]) << (8 * j);\n  for (unsigned i = 0; i < g_NumCodecs; i++)\n  {\n    const CCodecInfo &codec = *g_Codecs[i];\n    if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)\n      continue;\n    if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\n        codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\n      return E_NOINTERFACE;\n    index = i;\n    return S_OK;\n  }\n  return S_OK;\n}\n\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)\n{\n  COM_TRY_BEGIN\n  *outObject = 0;\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\n  const CCodecInfo &codec = *g_Codecs[index];\n  if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||\n      codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)\n    return E_NOINTERFACE;\n  if (encode)\n  {\n    if (!codec.CreateEncoder)\n      return CLASS_E_CLASSNOTAVAILABLE;\n    *outObject = codec.CreateEncoder();\n  }\n  else\n  {\n    if (!codec.CreateDecoder)\n      return CLASS_E_CLASSNOTAVAILABLE;\n    *outObject = codec.CreateDecoder();\n  }\n  if (isCoder)\n    ((ICompressCoder *)*outObject)->AddRef();\n  else if (isCoder2)\n    ((ICompressCoder2 *)*outObject)->AddRef();\n  else\n    ((ICompressFilter *)*outObject)->AddRef();\n  return S_OK;\n  COM_TRY_END\n}\n\nSTDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)\n{\n  *outObject = 0;\n  bool isCoder = (*iid == IID_ICompressCoder) != 0;\n  bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;\n  bool isFilter = (*iid == IID_ICompressFilter) != 0;\n  if (!isCoder && !isCoder2 && !isFilter)\n    return E_NOINTERFACE;\n  bool encode;\n  int codecIndex;\n  HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);\n  if (res != S_OK)\n    return res;\n  if (codecIndex < 0)\n    return CLASS_E_CLASSNOTAVAILABLE;\n  return CreateCoder2(encode, codecIndex, iid, outObject);\n}\n\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)\n{\n  ::VariantClear((VARIANTARG *)value);\n  const CCodecInfo &codec = *g_Codecs[codecIndex];\n  switch(propID)\n  {\n    case NMethodPropID::kID:\n    {\n      value->uhVal.QuadPart = (UInt64)codec.Id;\n      value->vt = VT_UI8;\n      break;\n    }\n    case NMethodPropID::kName:\n      if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)\n        value->vt = VT_BSTR;\n      break;\n    case NMethodPropID::kDecoder:\n      if (codec.CreateDecoder)\n        return SetClassID(codec.Id, false, value);\n      break;\n    case NMethodPropID::kEncoder:\n      if (codec.CreateEncoder)\n        return SetClassID(codec.Id, true, value);\n      break;\n    case NMethodPropID::kInStreams:\n    {\n      if (codec.NumInStreams != 1)\n      {\n        value->vt = VT_UI4;\n        value->ulVal = (ULONG)codec.NumInStreams;\n      }\n      break;\n    }\n  }\n  return S_OK;\n}\n\nSTDAPI GetNumberOfMethods(UINT32 *numCodecs)\n{\n  *numCodecs = g_NumCodecs;\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/CopyCoder.cpp",
    "content": "// Compress/CopyCoder.cpp\n\n#include \"StdAfx.h\"\n\nextern \"C\"\n{\n#include \"../../../C/Alloc.h\"\n}\n\n#include \"../Common/StreamUtils.h\"\n\n#include \"CopyCoder.h\"\n\nnamespace NCompress {\n\nstatic const UInt32 kBufferSize = 1 << 17;\n\nCCopyCoder::~CCopyCoder()\n{\n  ::MidFree(_buffer);\n}\n\nSTDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,\n    ISequentialOutStream *outStream,\n    const UInt64 * /* inSize */, const UInt64 *outSize,\n    ICompressProgressInfo *progress)\n{\n  if (_buffer == 0)\n  {\n    _buffer = (Byte *)::MidAlloc(kBufferSize);\n    if (_buffer == 0)\n      return E_OUTOFMEMORY;\n  }\n\n  TotalSize = 0;\n  for (;;)\n  {\n    UInt32 realProcessedSize;\n    UInt32 size = kBufferSize;\n    if (outSize != 0)\n      if (size > *outSize - TotalSize)\n        size = (UInt32)(*outSize - TotalSize);\n    RINOK(inStream->Read(_buffer, size, &realProcessedSize));\n    if (realProcessedSize == 0)\n      break;\n    RINOK(WriteStream(outStream, _buffer, realProcessedSize));\n    TotalSize += realProcessedSize;\n    if (progress != NULL)\n    {\n      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));\n    }\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)\n{\n  *value = TotalSize;\n  return S_OK;\n}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/CopyCoder.h",
    "content": "// Compress/CopyCoder.h\n\n#ifndef __COMPRESS_COPY_CODER_H\n#define __COMPRESS_COPY_CODER_H\n\n#include \"../../Common/MyCom.h\"\n\n#include \"../ICoder.h\"\n\nnamespace NCompress {\n\nclass CCopyCoder:\n  public ICompressCoder,\n  public ICompressGetInStreamProcessedSize,\n  public CMyUnknownImp\n{\n  Byte *_buffer;\npublic:\n  UInt64 TotalSize;\n  CCopyCoder(): TotalSize(0) , _buffer(0) {};\n  ~CCopyCoder();\n\n  MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)\n\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/CopyRegister.cpp",
    "content": "// CopyRegister.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../Common/RegisterCodec.h\"\n\n#include \"CopyCoder.h\"\n\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }\n\nstatic CCodecInfo g_CodecInfo =\n{ CreateCodec, CreateCodec, 0x00, L\"Copy\", 1, false };\n\nREGISTER_CODEC(Copy)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** DO NOT EDIT **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=AloneLZMA - Win32 DebugU\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n!MESSAGE use the Export Makefile command and run\n!MESSAGE \n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\n!MESSAGE \n!MESSAGE You can specify a configuration when running NMAKE\n!MESSAGE by defining the macro CFG on the command line. For example:\n!MESSAGE \n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\n!MESSAGE \n!MESSAGE Possible choices for configuration are:\n!MESSAGE \n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \"Release\"\n# PROP BASE Intermediate_Dir \"Release\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \"Release\"\n# PROP Intermediate_Dir \"Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /FAcs /Yu\"StdAfx.h\" /FD /c\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\n# ADD RSC /l 0x419 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\n# SUBTRACT LINK32 /pdb:none\n\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 1\n# PROP BASE Output_Dir \"Debug\"\n# PROP BASE Intermediate_Dir \"Debug\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 1\n# PROP Output_Dir \"Debug\"\n# PROP Intermediate_Dir \"Debug\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\n# ADD RSC /l 0x419 /d \"_DEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\n\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \"ReleaseU\"\n# PROP BASE Intermediate_Dir \"ReleaseU\"\n# PROP BASE Ignore_Export_Lib 0\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \"ReleaseU\"\n# PROP Intermediate_Dir \"ReleaseU\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /c\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\n# ADD RSC /l 0x419 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\n# SUBTRACT BASE LINK32 /pdb:none\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\n# SUBTRACT LINK32 /pdb:none\n\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 1\n# PROP BASE Output_Dir \"DebugU\"\n# PROP BASE Intermediate_Dir \"DebugU\"\n# PROP BASE Ignore_Export_Lib 0\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 1\n# PROP Output_Dir \"DebugU\"\n# PROP Intermediate_Dir \"DebugU\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /D \"COMPRESS_MF_MT\" /D \"BENCH_MT\" /Yu\"StdAfx.h\" /FD /GZ /c\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\n# ADD RSC /l 0x419 /d \"_DEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\n\n!ENDIF \n\n# Begin Target\n\n# Name \"AloneLZMA - Win32 Release\"\n# Name \"AloneLZMA - Win32 Debug\"\n# Name \"AloneLZMA - Win32 ReleaseU\"\n# Name \"AloneLZMA - Win32 DebugU\"\n# Begin Group \"Spec\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=.\\StdAfx.cpp\n# ADD CPP /Yc\"StdAfx.h\"\n# End Source File\n# Begin Source File\n\nSOURCE=.\\StdAfx.h\n# End Source File\n# End Group\n# Begin Group \"Compress\"\n\n# PROP Default_Filter \"\"\n# Begin Group \"LZMA\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\LzmaDecoder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaDecoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaEncoder.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\LzmaEncoder.h\n# End Source File\n# End Group\n# End Group\n# Begin Group \"Windows\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileIO.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Synchronization.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Synchronization.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\System.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\System.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Thread.h\n# End Source File\n# End Group\n# Begin Group \"Common\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\CRC.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Defs.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\Defs.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\IntToString.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyCom.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyString.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyString.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyVector.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyWindows.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\NewHandler.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringConvert.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringToInt.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Types.h\n# End Source File\n# End Group\n# Begin Group \"7zip Common\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FileStreams.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FileStreams.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\InBuffer.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\InBuffer.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\OutBuffer.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\OutBuffer.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\StreamUtils.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\StreamUtils.h\n# End Source File\n# End Group\n# Begin Group \"C\"\n\n# PROP Default_Filter \"\"\n# Begin Group \"LzmaUtil\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Dec.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaUtil\\Lzma86Enc.h\n# End Source File\n# End Group\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\7zCrc.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\7zCrc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Alloc.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Alloc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Bra.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Bra86.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzFind.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzFind.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzFindMt.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzHash.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaDec.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\LzmaEnc.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Threads.c\n# SUBTRACT CPP /YX /Yc /Yu\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Threads.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\..\\C\\Types.h\n# End Source File\n# End Group\n# Begin Source File\n\nSOURCE=..\\..\\ICoder.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\LzmaAlone.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=.\\LzmaBench.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=.\\LzmaBench.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\LzmaBenchCon.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=.\\LzmaBenchCon.h\n# End Source File\n# End Target\n# End Project\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n###############################################################################\n\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nGlobal:\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<3>\n{{{\n}}}\n\n###############################################################################\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/Exception.h",
    "content": "/* A couple of exceptions for lzmp.\n *\n * Copyright (C) 2005 Ville Koskinen\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2\n * of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n */\n\n#ifndef _EXCEPTION_H_\n#define _EXCEPTION_H_\n\n#include <string>\nusing std::string;\n\nclass Exception\n{\nprivate:\n\tstring message;\npublic:\n\tException(char *what): message(what) { }\n\tException(string what): message(what) { }\n\n\t~Exception() { }\n\n\tstring what(void) { return message; }\n};\n\nclass ArgumentException: public Exception\n{\npublic:\n\tArgumentException(char *what): Exception(what) { }\n\tArgumentException(string what): Exception(what) { }\n\n\t~ArgumentException() { }\n};\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/MyInitGuid.h\"\n\n#include <stdio.h>\n\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\n#include <fcntl.h>\n#include <io.h>\n#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)\n#else\n#define MY_SET_BINARY_MODE(file)\n#endif\n\n#include \"../../../Common/CommandLineParser.h\"\n#include \"../../../Common/StringConvert.h\"\n#include \"../../../Common/StringToInt.h\"\n\n#include \"../../Common/FileStreams.h\"\n#include \"../../Common/StreamUtils.h\"\n\n#include \"../LzmaDecoder.h\"\n#include \"../LzmaEncoder.h\"\n\n#include \"LzmaBenchCon.h\"\n\n#ifdef COMPRESS_MF_MT\n#include \"../../../Windows/System.h\"\n#endif\n\nextern \"C\"\n{\n  #include \"../../../../C/7zVersion.h\"\n  #include \"../../../../C/Alloc.h\"\n  #include \"../../../../C/LzmaUtil/Lzma86Dec.h\"\n  #include \"../../../../C/LzmaUtil/Lzma86Enc.h\"\n}\n\nusing namespace NCommandLineParser;\n\n#ifdef _WIN32\nbool g_IsNT = false;\nstatic inline bool IsItWindowsNT()\n{\n  OSVERSIONINFO versionInfo;\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\n  if (!::GetVersionEx(&versionInfo))\n    return false;\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\n}\n#endif\n\nstatic const char *kCantAllocate = \"Can not allocate memory\";\nstatic const char *kReadError = \"Read error\";\nstatic const char *kWriteError = \"Write error\";\n\nnamespace NKey {\nenum Enum\n{\n  kHelp1 = 0,\n  kHelp2,\n  kAlgo,\n  kDict,\n  kFb,\n  kMc,\n  kLc,\n  kLp,\n  kPb,\n  kMatchFinder,\n  kMultiThread,\n  kEOS,\n  kStdIn,\n  kStdOut,\n  kFilter86\n};\n}\n\nstatic const CSwitchForm kSwitchForms[] =\n{\n  { L\"?\",  NSwitchType::kSimple, false },\n  { L\"H\",  NSwitchType::kSimple, false },\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"MC\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"MT\", NSwitchType::kUnLimitedPostString, false, 0 },\n  { L\"EOS\", NSwitchType::kSimple, false },\n  { L\"SI\",  NSwitchType::kSimple, false },\n  { L\"SO\",  NSwitchType::kSimple, false },\n  { L\"F86\",  NSwitchType::kPostChar, false, 0, 0, L\"+\" }\n};\n\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\n\nstatic void PrintHelp()\n{\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\n             \"  e: encode file\\n\"\n             \"  d: decode file\\n\"\n             \"  b: Benchmark\\n\"\n    \"<Switches>\\n\"\n    \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\"\n    \"  -d{N}:  set dictionary size - [12, 30], default: 23 (8MB)\\n\"\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\n    \"  -mc{N}: set number of cycles for match finder\\n\"\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\\n\"\n    \"  -mt{N}: set number of CPU threads\\n\"\n    \"  -eos:   write End Of Stream marker\\n\"\n    \"  -si:    read data from stdin\\n\"\n    \"  -so:    write data to stdout\\n\"\n    );\n}\n\nstatic void PrintHelpAndExit(const char *s)\n{\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\n  PrintHelp();\n  throw -1;\n}\n\nstatic void IncorrectCommand()\n{\n  PrintHelpAndExit(\"Incorrect command\");\n}\n\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[],\n    UStringVector &strings)\n{\n  for(int i = 1; i < numArguments; i++)\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\n}\n\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\n{\n  value = 0;\n  if (MyStringLen(s) == 0)\n    return false;\n  const wchar_t *end;\n  UInt64 res = ConvertStringToUInt64(s, &end);\n  if (*end != L'\\0')\n    return false;\n  if (res > 0xFFFFFFFF)\n    return false;\n  value = UInt32(res);\n  return true;\n}\n\nstatic void ParseUInt32(const CParser &parser, int index, UInt32 &res)\n{\n  if (parser[index].ThereIs)\n    if (!GetNumber(parser[index].PostStrings[0], res))\n      IncorrectCommand();\n}\n\nint main2(int n, const char *args[])\n{\n  #ifdef _WIN32\n  g_IsNT = IsItWindowsNT();\n  #endif\n\n  fprintf(stderr, \"\\nLZMA \" MY_VERSION_COPYRIGHT_DATE \"\\n\");\n\n  if (n == 1)\n  {\n    PrintHelp();\n    return 0;\n  }\n\n  bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);\n  if (unsupportedTypes)\n  {\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\n    return 1;\n  }\n\n  UStringVector commandStrings;\n  WriteArgumentsToStringList(n, args, commandStrings);\n  CParser parser(kNumSwitches);\n  try\n  {\n    parser.ParseStrings(kSwitchForms, commandStrings);\n  }\n  catch(...)\n  {\n    IncorrectCommand();\n  }\n\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\n  {\n    PrintHelp();\n    return 0;\n  }\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\n\n  int paramIndex = 0;\n  if (paramIndex >= nonSwitchStrings.Size())\n    IncorrectCommand();\n  const UString &command = nonSwitchStrings[paramIndex++];\n\n  bool dictDefined = false;\n  UInt32 dict = (UInt32)-1;\n  if(parser[NKey::kDict].ThereIs)\n  {\n    UInt32 dicLog;\n    if (!GetNumber(parser[NKey::kDict].PostStrings[0], dicLog))\n      IncorrectCommand();\n    dict = 1 << dicLog;\n    dictDefined = true;\n  }\n  UString mf = L\"BT4\";\n  if (parser[NKey::kMatchFinder].ThereIs)\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\n\n  UInt32 numThreads = (UInt32)-1;\n\n  #ifdef COMPRESS_MF_MT\n  if (parser[NKey::kMultiThread].ThereIs)\n  {\n    UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\n    const UString &s = parser[NKey::kMultiThread].PostStrings[0];\n    if (s.IsEmpty())\n      numThreads = numCPUs;\n    else\n      if (!GetNumber(s, numThreads))\n        IncorrectCommand();\n  }\n  #endif\n\n  if (command.CompareNoCase(L\"b\") == 0)\n  {\n    const UInt32 kNumDefaultItereations = 1;\n    UInt32 numIterations = kNumDefaultItereations;\n    {\n      if (paramIndex < nonSwitchStrings.Size())\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\n          numIterations = kNumDefaultItereations;\n    }\n    return LzmaBenchCon(stderr, numIterations, numThreads, dict);\n  }\n\n  if (numThreads == (UInt32)-1)\n    numThreads = 1;\n\n  bool encodeMode = false;\n  if (command.CompareNoCase(L\"e\") == 0)\n    encodeMode = true;\n  else if (command.CompareNoCase(L\"d\") == 0)\n    encodeMode = false;\n  else\n    IncorrectCommand();\n\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\n\n  CMyComPtr<ISequentialInStream> inStream;\n  CInFileStream *inStreamSpec = 0;\n  if (stdInMode)\n  {\n    inStream = new CStdInFileStream;\n    MY_SET_BINARY_MODE(stdin);\n  }\n  else\n  {\n    if (paramIndex >= nonSwitchStrings.Size())\n      IncorrectCommand();\n    const UString &inputName = nonSwitchStrings[paramIndex++];\n    inStreamSpec = new CInFileStream;\n    inStream = inStreamSpec;\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\n    {\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\",\n          (const char *)GetOemString(inputName));\n      return 1;\n    }\n  }\n\n  CMyComPtr<ISequentialOutStream> outStream;\n  COutFileStream *outStreamSpec = NULL;\n  if (stdOutMode)\n  {\n    outStream = new CStdOutFileStream;\n    MY_SET_BINARY_MODE(stdout);\n  }\n  else\n  {\n    if (paramIndex >= nonSwitchStrings.Size())\n      IncorrectCommand();\n    const UString &outputName = nonSwitchStrings[paramIndex++];\n    outStreamSpec = new COutFileStream;\n    outStream = outStreamSpec;\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\n    {\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\",\n        (const char *)GetOemString(outputName));\n      return 1;\n    }\n  }\n\n  if (parser[NKey::kFilter86].ThereIs)\n  {\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\n      throw \"Can not use stdin in this mode\";\n    UInt64 fileSize;\n    inStreamSpec->File.GetLength(fileSize);\n    if (fileSize > 0xF0000000)\n      throw \"File is too big\";\n    size_t inSize = (size_t)fileSize;\n    Byte *inBuffer = 0;\n    if (inSize != 0)\n    {\n      inBuffer = (Byte *)MyAlloc((size_t)inSize);\n      if (inBuffer == 0)\n        throw kCantAllocate;\n    }\n    \n    if (ReadStream_FAIL(inStream, inBuffer, inSize) != S_OK)\n      throw \"Can not read\";\n\n    Byte *outBuffer = 0;\n    size_t outSize;\n    if (encodeMode)\n    {\n      // we allocate 105% of original size for output buffer\n      outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\n      if (outSize != 0)\n      {\n        outBuffer = (Byte *)MyAlloc((size_t)outSize);\n        if (outBuffer == 0)\n          throw kCantAllocate;\n      }\n      if (!dictDefined)\n        dict = 1 << 23;\n      int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,\n          5, dict, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);\n      if (res != 0)\n      {\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\n        return 1;\n      }\n    }\n    else\n    {\n      UInt64 outSize64;\n      if (Lzma86_GetUnpackSize(inBuffer, inSize, &outSize64) != 0)\n        throw \"data error\";\n      outSize = (size_t)outSize64;\n      if (outSize != outSize64)\n        throw \"too big\";\n      if (outSize != 0)\n      {\n        outBuffer = (Byte *)MyAlloc(outSize);\n        if (outBuffer == 0)\n          throw kCantAllocate;\n      }\n      int res = Lzma86_Decode(outBuffer, &outSize, inBuffer, &inSize);\n      if (inSize != (size_t)fileSize)\n        throw \"incorrect processed size\";\n      if (res != 0)\n        throw \"LzmaDecoder error\";\n    }\n    if (WriteStream(outStream, outBuffer, outSize) != S_OK)\n      throw kWriteError;\n    MyFree(outBuffer);\n    MyFree(inBuffer);\n    return 0;\n  }\n\n\n  UInt64 fileSize;\n  if (encodeMode)\n  {\n    NCompress::NLzma::CEncoder *encoderSpec = new NCompress::NLzma::CEncoder;\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\n\n    if (!dictDefined)\n      dict = 1 << 23;\n\n    UInt32 pb = 2;\n    UInt32 lc = 3; // = 0; for 32-bit data\n    UInt32 lp = 0; // = 2; for 32-bit data\n    UInt32 algo = 1;\n    UInt32 fb = 128;\n    UInt32 mc = 16 + fb / 2;\n    bool mcDefined = false;\n\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\n \n    ParseUInt32(parser, NKey::kAlgo, algo);\n    ParseUInt32(parser, NKey::kFb, fb);\n    ParseUInt32(parser, NKey::kLc, lc);\n    ParseUInt32(parser, NKey::kLp, lp);\n    ParseUInt32(parser, NKey::kPb, pb);\n\n    mcDefined = parser[NKey::kMc].ThereIs;\n    if (mcDefined)\n      if (!GetNumber(parser[NKey::kMc].PostStrings[0], mc))\n        IncorrectCommand();\n    \n    PROPID propIDs[] =\n    {\n      NCoderPropID::kDictionarySize,\n      NCoderPropID::kPosStateBits,\n      NCoderPropID::kLitContextBits,\n      NCoderPropID::kLitPosBits,\n      NCoderPropID::kAlgorithm,\n      NCoderPropID::kNumFastBytes,\n      NCoderPropID::kMatchFinder,\n      NCoderPropID::kEndMarker,\n      NCoderPropID::kNumThreads,\n      NCoderPropID::kMatchFinderCycles,\n    };\n    const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);\n\n    PROPVARIANT props[kNumPropsMax];\n    for (int p = 0; p < 6; p++)\n      props[p].vt = VT_UI4;\n\n    props[0].ulVal = (UInt32)dict;\n    props[1].ulVal = (UInt32)pb;\n    props[2].ulVal = (UInt32)lc;\n    props[3].ulVal = (UInt32)lp;\n    props[4].ulVal = (UInt32)algo;\n    props[5].ulVal = (UInt32)fb;\n\n    props[6].vt = VT_BSTR;\n    props[6].bstrVal = (BSTR)(const wchar_t *)mf;\n\n    props[7].vt = VT_BOOL;\n    props[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\n\n    props[8].vt = VT_UI4;\n    props[8].ulVal = (UInt32)numThreads;\n\n    // it must be last in property list\n    props[9].vt = VT_UI4;\n    props[9].ulVal = (UInt32)mc;\n\n    int numProps = kNumPropsMax;\n    if (!mcDefined)\n      numProps--;\n\n    if (encoderSpec->SetCoderProperties(propIDs, props, numProps) != S_OK)\n      IncorrectCommand();\n    encoderSpec->WriteCoderProperties(outStream);\n\n    if (eos || stdInMode)\n      fileSize = (UInt64)(Int64)-1;\n    else\n      inStreamSpec->File.GetLength(fileSize);\n\n    for (int i = 0; i < 8; i++)\n    {\n      Byte b = Byte(fileSize >> (8 * i));\n      if (outStream->Write(&b, 1, 0) != S_OK)\n      {\n        fprintf(stderr, kWriteError);\n        return 1;\n      }\n    }\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\n    if (result == E_OUTOFMEMORY)\n    {\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\n      return 1;\n    }\n    else if (result != S_OK)\n    {\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\n      return 1;\n    }\n  }\n  else\n  {\n    NCompress::NLzma::CDecoder *decoderSpec = new NCompress::NLzma::CDecoder;\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\n    decoderSpec->FinishStream = true;\n    const UInt32 kPropertiesSize = 5;\n    Byte header[kPropertiesSize + 8];\n    if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)\n    {\n      fprintf(stderr, kReadError);\n      return 1;\n    }\n    if (decoderSpec->SetDecoderProperties2(header, kPropertiesSize) != S_OK)\n    {\n      fprintf(stderr, \"SetDecoderProperties error\");\n      return 1;\n    }\n    fileSize = 0;\n    for (int i = 0; i < 8; i++)\n      fileSize |= ((UInt64)header[kPropertiesSize + i]) << (8 * i);\n\n    if (decoder->Code(inStream, outStream, 0, (fileSize == (UInt64)(Int64)-1) ? 0 : &fileSize, 0) != S_OK)\n    {\n      fprintf(stderr, \"Decoder error\");\n      return 1;\n    }\n  }\n  if (outStreamSpec != NULL)\n  {\n    if (outStreamSpec->Close() != S_OK)\n    {\n      fprintf(stderr, \"File closing error\");\n      return 1;\n    }\n  }\n  return 0;\n}\n\nint MY_CDECL main(int n, const char *args[])\n{\n  try { return main2(n, args); }\n  catch(const char *s)\n  {\n    fprintf(stderr, \"\\nError: %s\\n\", s);\n    return 1;\n  }\n  catch(...)\n  {\n    fprintf(stderr, \"\\nError\\n\");\n    return 1;\n  }\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LzmaBench.h\"\n\n#ifndef _WIN32\n#define USE_POSIX_TIME\n#define USE_POSIX_TIME2\n#endif\n\n#ifdef USE_POSIX_TIME\n#include <time.h>\n#ifdef USE_POSIX_TIME2\n#include <sys/time.h>\n#endif\n#endif\n\n#ifdef _WIN32\n#define USE_ALLOCA\n#endif\n\n#ifdef USE_ALLOCA\n#ifdef _WIN32\n#include <malloc.h>\n#else\n#include <stdlib.h>\n#endif\n#endif\n\nextern \"C\"\n{\n#include \"../../../../C/7zCrc.h\"\n#include \"../../../../C/Alloc.h\"\n}\n\n#include \"../../../Common/MyCom.h\"\n\n#ifdef BENCH_MT\n#include \"../../../Windows/Synchronization.h\"\n#include \"../../../Windows/Thread.h\"\n#endif\n\n#ifdef EXTERNAL_LZMA\n#include \"../../../Windows/PropVariant.h\"\n#include \"../../ICoder.h\"\n#else\n#include \"../LzmaDecoder.h\"\n#include \"../LzmaEncoder.h\"\n#endif\n\nstatic const UInt32 kUncompressMinBlockSize = 1 << 26;\nstatic const UInt32 kAdditionalSize = (1 << 16);\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\nstatic const UInt32 kMaxLzmaPropSize = 5;\n\nclass CBaseRandomGenerator\n{\n  UInt32 A1;\n  UInt32 A2;\npublic:\n  CBaseRandomGenerator() { Init(); }\n  void Init() { A1 = 362436069; A2 = 521288629;}\n  UInt32 GetRnd()\n  {\n    return\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\n  }\n};\n\nclass CBenchBuffer\n{\npublic:\n  size_t BufferSize;\n  Byte *Buffer;\n  CBenchBuffer(): Buffer(0) {}\n  virtual ~CBenchBuffer() { Free(); }\n  void Free()\n  {\n    ::MidFree(Buffer);\n    Buffer = 0;\n  }\n  bool Alloc(size_t bufferSize)\n  {\n    if (Buffer != 0 && BufferSize == bufferSize)\n      return true;\n    Free();\n    Buffer = (Byte *)::MidAlloc(bufferSize);\n    BufferSize = bufferSize;\n    return (Buffer != 0);\n  }\n};\n\nclass CBenchRandomGenerator: public CBenchBuffer\n{\n  CBaseRandomGenerator *RG;\npublic:\n  void Set(CBaseRandomGenerator *rg) { RG = rg; }\n  UInt32 GetVal(UInt32 &res, int numBits)\n  {\n    UInt32 val = res & (((UInt32)1 << numBits) - 1);\n    res >>= numBits;\n    return val;\n  }\n  UInt32 GetLen(UInt32 &res)\n  {\n    UInt32 len = GetVal(res, 2);\n    return GetVal(res, 1 + len);\n  }\n  void Generate()\n  {\n    UInt32 pos = 0;\n    UInt32 rep0 = 1;\n    while (pos < BufferSize)\n    {\n      UInt32 res = RG->GetRnd();\n      res >>= 1;\n      if (GetVal(res, 1) == 0 || pos < 1024)\n        Buffer[pos++] = (Byte)(res & 0xFF);\n      else\n      {\n        UInt32 len;\n        len = 1 + GetLen(res);\n        if (GetVal(res, 3) != 0)\n        {\n          len += GetLen(res);\n          do\n          {\n            UInt32 ppp = GetVal(res, 5) + 6;\n            res = RG->GetRnd();\n            if (ppp > 30)\n              continue;\n            rep0 = /* (1 << ppp) +*/  GetVal(res, ppp);\n            res = RG->GetRnd();\n          }\n          while (rep0 >= pos);\n          rep0++;\n        }\n\n        for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)\n          Buffer[pos] = Buffer[pos - rep0];\n      }\n    }\n  }\n};\n\n\nclass CBenchmarkInStream:\n  public ISequentialInStream,\n  public CMyUnknownImp\n{\n  const Byte *Data;\n  size_t Pos;\n  size_t Size;\npublic:\n  MY_UNKNOWN_IMP\n  void Init(const Byte *data, size_t size)\n  {\n    Data = data;\n    Size = size;\n    Pos = 0;\n  }\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n};\n\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  size_t remain = Size - Pos;\n  UInt32 kMaxBlockSize = (1 << 20);\n  if (size > kMaxBlockSize)\n    size = kMaxBlockSize;\n  if (size > remain)\n    size = (UInt32)remain;\n  for (UInt32 i = 0; i < size; i++)\n    ((Byte *)data)[i] = Data[Pos + i];\n  Pos += size;\n  if(processedSize != NULL)\n    *processedSize = size;\n  return S_OK;\n}\n  \nclass CBenchmarkOutStream:\n  public ISequentialOutStream,\n  public CBenchBuffer,\n  public CMyUnknownImp\n{\n  // bool _overflow;\npublic:\n  UInt32 Pos;\n  // CBenchmarkOutStream(): _overflow(false) {}\n  void Init()\n  {\n    // _overflow = false;\n    Pos = 0;\n  }\n  MY_UNKNOWN_IMP\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  size_t curSize = BufferSize - Pos;\n  if (curSize > size)\n    curSize = size;\n  memcpy(Buffer + Pos, data, curSize);\n  Pos += (UInt32)curSize;\n  if(processedSize != NULL)\n    *processedSize = (UInt32)curSize;\n  if (curSize != size)\n  {\n    // _overflow = true;\n    return E_FAIL;\n  }\n  return S_OK;\n}\n  \nclass CCrcOutStream:\n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\npublic:\n  UInt32 Crc;\n  MY_UNKNOWN_IMP\n  void Init() { Crc = CRC_INIT_VAL; }\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  Crc = CrcUpdate(Crc, data, size);\n  if (processedSize != NULL)\n    *processedSize = size;\n  return S_OK;\n}\n  \nstatic UInt64 GetTimeCount()\n{\n  #ifdef USE_POSIX_TIME\n  #ifdef USE_POSIX_TIME2\n  timeval v;\n  if (gettimeofday(&v, 0) == 0)\n    return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;\n  return (UInt64)time(NULL) * 1000000;\n  #else\n  return time(NULL);\n  #endif\n  #else\n  /*\n  LARGE_INTEGER value;\n  if (::QueryPerformanceCounter(&value))\n    return value.QuadPart;\n  */\n  return GetTickCount();\n  #endif\n}\n\nstatic UInt64 GetFreq()\n{\n  #ifdef USE_POSIX_TIME\n  #ifdef USE_POSIX_TIME2\n  return 1000000;\n  #else\n  return 1;\n  #endif\n  #else\n  /*\n  LARGE_INTEGER value;\n  if (::QueryPerformanceFrequency(&value))\n    return value.QuadPart;\n  */\n  return 1000;\n  #endif\n}\n\n#ifndef USE_POSIX_TIME\nstatic inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }\n#endif\nstatic UInt64 GetUserTime()\n{\n  #ifdef USE_POSIX_TIME\n  return clock();\n  #else\n  FILETIME creationTime, exitTime, kernelTime, userTime;\n  if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)\n    return GetTime64(userTime) + GetTime64(kernelTime);\n  return (UInt64)GetTickCount() * 10000;\n  #endif\n}\n\nstatic UInt64 GetUserFreq()\n{\n  #ifdef USE_POSIX_TIME\n  return CLOCKS_PER_SEC;\n  #else\n  return 10000000;\n  #endif\n}\n\nclass CBenchProgressStatus\n{\n  #ifdef BENCH_MT\n  NWindows::NSynchronization::CCriticalSection CS;\n  #endif\npublic:\n  HRESULT Res;\n  bool EncodeMode;\n  void SetResult(HRESULT res)\n  {\n    #ifdef BENCH_MT\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\n    #endif\n    Res = res;\n  }\n  HRESULT GetResult()\n  {\n    #ifdef BENCH_MT\n    NWindows::NSynchronization::CCriticalSectionLock lock(CS);\n    #endif\n    return Res;\n  }\n};\n\nclass CBenchProgressInfo:\n  public ICompressProgressInfo,\n  public CMyUnknownImp\n{\npublic:\n  CBenchProgressStatus *Status;\n  CBenchInfo BenchInfo;\n  HRESULT Res;\n  IBenchCallback *callback;\n  CBenchProgressInfo(): callback(0) {}\n  MY_UNKNOWN_IMP\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\n};\n\nvoid SetStartTime(CBenchInfo &bi)\n{\n  bi.GlobalFreq = GetFreq();\n  bi.UserFreq = GetUserFreq();\n  bi.GlobalTime = ::GetTimeCount();\n  bi.UserTime = ::GetUserTime();\n}\n\nvoid SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)\n{\n  dest.GlobalFreq = GetFreq();\n  dest.UserFreq = GetUserFreq();\n  dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;\n  dest.UserTime = ::GetUserTime() - biStart.UserTime;\n}\n\nSTDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\n{\n  HRESULT res = Status->GetResult();\n  if (res != S_OK)\n    return res;\n  if (!callback)\n    return res;\n  CBenchInfo info = BenchInfo;\n  SetFinishTime(BenchInfo, info);\n  if (Status->EncodeMode)\n  {\n    info.UnpackSize = *inSize;\n    info.PackSize = *outSize;\n    res = callback->SetEncodeResult(info, false);\n  }\n  else\n  {\n    info.PackSize = BenchInfo.PackSize + *inSize;\n    info.UnpackSize = BenchInfo.UnpackSize + *outSize;\n    res = callback->SetDecodeResult(info, false);\n  }\n  if (res != S_OK)\n    Status->SetResult(res);\n  return res;\n}\n\nstatic const int kSubBits = 8;\n\nstatic UInt32 GetLogSize(UInt32 size)\n{\n  for (int i = kSubBits; i < 32; i++)\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\n        return (i << kSubBits) + j;\n  return (32 << kSubBits);\n}\n\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\n{\n  while (v1 > 1000000)\n  {\n    v1 >>= 1;\n    v2 >>= 1;\n  }\n}\n\nUInt64 GetUsage(const CBenchInfo &info)\n{\n  UInt64 userTime = info.UserTime;\n  UInt64 userFreq = info.UserFreq;\n  UInt64 globalTime = info.GlobalTime;\n  UInt64 globalFreq = info.GlobalFreq;\n  NormalizeVals(userTime, userFreq);\n  NormalizeVals(globalFreq, globalTime);\n  if (userFreq == 0)\n    userFreq = 1;\n  if (globalTime == 0)\n    globalTime = 1;\n  return userTime * globalFreq * 1000000 / userFreq / globalTime;\n}\n\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)\n{\n  UInt64 userTime = info.UserTime;\n  UInt64 userFreq = info.UserFreq;\n  UInt64 globalTime = info.GlobalTime;\n  UInt64 globalFreq = info.GlobalFreq;\n  NormalizeVals(userFreq, userTime);\n  NormalizeVals(globalTime, globalFreq);\n  if (globalFreq == 0)\n    globalFreq = 1;\n  if (userTime == 0)\n    userTime = 1;\n  return userFreq * globalTime / globalFreq *  rating / userTime;\n}\n\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\n{\n  UInt64 elTime = elapsedTime;\n  NormalizeVals(freq, elTime);\n  if (elTime == 0)\n    elTime = 1;\n  return value * freq / elTime;\n}\n\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)\n{\n  UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);\n  UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits));\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\n  return MyMultDiv64(numCommands, elapsedTime, freq);\n}\n\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)\n{\n  UInt64 numCommands = (inSize * 200 + outSize * 4) * numIterations;\n  return MyMultDiv64(numCommands, elapsedTime, freq);\n}\n\n#ifdef EXTERNAL_LZMA\ntypedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID,\n    const GUID *interfaceID, void **outObject);\n#endif\n\nstruct CEncoderInfo;\n\nstruct CEncoderInfo\n{\n  #ifdef BENCH_MT\n  NWindows::CThread thread[2];\n  #endif\n  CMyComPtr<ICompressCoder> encoder;\n  CBenchProgressInfo *progressInfoSpec[2];\n  CMyComPtr<ICompressProgressInfo> progressInfo[2];\n  UInt32 NumIterations;\n  #ifdef USE_ALLOCA\n  size_t AllocaSize;\n  #endif\n\n  struct CDecoderInfo\n  {\n    CEncoderInfo *Encoder;\n    UInt32 DecoderIndex;\n    #ifdef USE_ALLOCA\n    size_t AllocaSize;\n    #endif\n    bool CallbackMode;\n  };\n  CDecoderInfo decodersInfo[2];\n\n  CMyComPtr<ICompressCoder> decoders[2];\n  HRESULT Results[2];\n  CBenchmarkOutStream *outStreamSpec;\n  CMyComPtr<ISequentialOutStream> outStream;\n  IBenchCallback *callback;\n  UInt32 crc;\n  UInt32 kBufferSize;\n  UInt32 compressedSize;\n  CBenchRandomGenerator rg;\n  CBenchmarkOutStream *propStreamSpec;\n  CMyComPtr<ISequentialOutStream> propStream;\n  HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);\n  HRESULT Encode();\n  HRESULT Decode(UInt32 decoderIndex);\n\n  CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}\n\n  #ifdef BENCH_MT\n  static THREAD_FUNC_DECL EncodeThreadFunction(void *param)\n  {\n    CEncoderInfo *encoder = (CEncoderInfo *)param;\n    #ifdef USE_ALLOCA\n    alloca(encoder->AllocaSize);\n    #endif\n    HRESULT res = encoder->Encode();\n    encoder->Results[0] = res;\n    if (res != S_OK)\n      encoder->progressInfoSpec[0]->Status->SetResult(res);\n\n    return 0;\n  }\n  static THREAD_FUNC_DECL DecodeThreadFunction(void *param)\n  {\n    CDecoderInfo *decoder = (CDecoderInfo *)param;\n    #ifdef USE_ALLOCA\n    alloca(decoder->AllocaSize);\n    #endif\n    CEncoderInfo *encoder = decoder->Encoder;\n    encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);\n    return 0;\n  }\n\n  HRESULT CreateEncoderThread()\n  {\n    return thread[0].Create(EncodeThreadFunction, this);\n  }\n\n  HRESULT CreateDecoderThread(int index, bool callbackMode\n      #ifdef USE_ALLOCA\n      , size_t allocaSize\n      #endif\n      )\n  {\n    CDecoderInfo &decoder = decodersInfo[index];\n    decoder.DecoderIndex = index;\n    decoder.Encoder = this;\n    #ifdef USE_ALLOCA\n    decoder.AllocaSize = allocaSize;\n    #endif\n    decoder.CallbackMode = callbackMode;\n    return thread[index].Create(DecodeThreadFunction, &decoder);\n  }\n  #endif\n};\n\nHRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)\n{\n  rg.Set(rgLoc);\n  kBufferSize = dictionarySize + kAdditionalSize;\n  UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\n  if (!rg.Alloc(kBufferSize))\n    return E_OUTOFMEMORY;\n  rg.Generate();\n  crc = CrcCalc(rg.Buffer, rg.BufferSize);\n\n  outStreamSpec = new CBenchmarkOutStream;\n  if (!outStreamSpec->Alloc(kCompressedBufferSize))\n    return E_OUTOFMEMORY;\n\n  outStream = outStreamSpec;\n\n  propStreamSpec = 0;\n  if (!propStream)\n  {\n    propStreamSpec = new CBenchmarkOutStream;\n    propStream = propStreamSpec;\n  }\n  if (!propStreamSpec->Alloc(kMaxLzmaPropSize))\n    return E_OUTOFMEMORY;\n  propStreamSpec->Init();\n  \n  PROPID propIDs[] =\n  {\n    NCoderPropID::kDictionarySize,\n    NCoderPropID::kMultiThread\n  };\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\n  PROPVARIANT properties[kNumProps];\n  properties[0].vt = VT_UI4;\n  properties[0].ulVal = (UInt32)dictionarySize;\n\n  properties[1].vt = VT_BOOL;\n  properties[1].boolVal = (numThreads > 1) ? VARIANT_TRUE : VARIANT_FALSE;\n\n  {\n    CMyComPtr<ICompressSetCoderProperties> setCoderProperties;\n    RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));\n    if (!setCoderProperties)\n      return E_FAIL;\n    RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, kNumProps));\n\n    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;\n    encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);\n    if (writeCoderProperties)\n    {\n      RINOK(writeCoderProperties->WriteCoderProperties(propStream));\n    }\n  }\n  return S_OK;\n}\n\nHRESULT CEncoderInfo::Encode()\n{\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\n  inStreamSpec->Init(rg.Buffer, rg.BufferSize);\n  outStreamSpec->Init();\n\n  RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));\n  compressedSize = outStreamSpec->Pos;\n  encoder.Release();\n  return S_OK;\n}\n\nHRESULT CEncoderInfo::Decode(UInt32 decoderIndex)\n{\n  CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\n  CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];\n\n  CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;\n  decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);\n  if (!compressSetDecoderProperties)\n    return E_FAIL;\n\n  CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\n  CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\n    \n  CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];\n  pi->BenchInfo.UnpackSize = 0;\n  pi->BenchInfo.PackSize = 0;\n\n  for (UInt32 j = 0; j < NumIterations; j++)\n  {\n    inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\n    crcOutStreamSpec->Init();\n    \n    RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));\n    UInt64 outSize = kBufferSize;\n    RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));\n    if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)\n      return S_FALSE;\n    pi->BenchInfo.UnpackSize += kBufferSize;\n    pi->BenchInfo.PackSize += compressedSize;\n  }\n  decoder.Release();\n  return S_OK;\n}\n\nstatic const UInt32 kNumThreadsMax = (1 << 16);\n\nstruct CBenchEncoders\n{\n  CEncoderInfo *encoders;\n  CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }\n  ~CBenchEncoders() { delete []encoders; }\n};\n\nHRESULT LzmaBench(\n  #ifdef EXTERNAL_LZMA\n  CCodecs *codecs,\n  #endif\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)\n{\n  UInt32 numEncoderThreads =\n    #ifdef BENCH_MT\n    (numThreads > 1 ? numThreads / 2 : 1);\n    #else\n    1;\n    #endif\n  UInt32 numSubDecoderThreads =\n    #ifdef BENCH_MT\n    (numThreads > 1 ? 2 : 1);\n    #else\n    1;\n    #endif\n  if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)\n  {\n    return E_INVALIDARG;\n  }\n\n  CBenchEncoders encodersSpec(numEncoderThreads);\n  CEncoderInfo *encoders = encodersSpec.encoders;\n\n  #ifdef EXTERNAL_LZMA\n  UString name = L\"LZMA\";\n  #endif\n\n  UInt32 i;\n  for (i = 0; i < numEncoderThreads; i++)\n  {\n    CEncoderInfo &encoder = encoders[i];\n    encoder.callback = (i == 0) ? callback : 0;\n\n    #ifdef EXTERNAL_LZMA\n    RINOK(codecs->CreateCoder(name, true, encoder.encoder));\n    #else\n    encoder.encoder = new NCompress::NLzma::CEncoder;\n    #endif\n    for (UInt32 j = 0; j < numSubDecoderThreads; j++)\n    {\n      #ifdef EXTERNAL_LZMA\n      RINOK(codecs->CreateCoder(name, false, encoder.decoders[j]));\n      #else\n      encoder.decoders[j] = new NCompress::NLzma::CDecoder;\n      #endif\n    }\n  }\n\n  CBaseRandomGenerator rg;\n  rg.Init();\n  for (i = 0; i < numEncoderThreads; i++)\n  {\n    RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));\n  }\n\n  CBenchProgressStatus status;\n  status.Res = S_OK;\n  status.EncodeMode = true;\n\n  for (i = 0; i < numEncoderThreads; i++)\n  {\n    CEncoderInfo &encoder = encoders[i];\n    for (int j = 0; j < 2; j++)\n    {\n      encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;\n      encoder.progressInfoSpec[j]->Status = &status;\n    }\n    if (i == 0)\n    {\n      encoder.progressInfoSpec[0]->callback = callback;\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\n    }\n\n    #ifdef BENCH_MT\n    if (numEncoderThreads > 1)\n    {\n      #ifdef USE_ALLOCA\n      encoder.AllocaSize = (i * 16 * 21) & 0x7FF;\n      #endif\n      RINOK(encoder.CreateEncoderThread())\n    }\n    else\n    #endif\n    {\n      RINOK(encoder.Encode());\n    }\n  }\n  #ifdef BENCH_MT\n  if (numEncoderThreads > 1)\n    for (i = 0; i < numEncoderThreads; i++)\n      encoders[i].thread[0].Wait();\n  #endif\n\n  RINOK(status.Res);\n\n  CBenchInfo info;\n\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\n  info.UnpackSize = 0;\n  info.PackSize = 0;\n  info.NumIterations = 1; // progressInfoSpec->NumIterations;\n  for (i = 0; i < numEncoderThreads; i++)\n  {\n    CEncoderInfo &encoder = encoders[i];\n    info.UnpackSize += encoder.kBufferSize;\n    info.PackSize += encoder.compressedSize;\n  }\n  RINOK(callback->SetEncodeResult(info, true));\n\n\n  status.Res = S_OK;\n  status.EncodeMode = false;\n\n  UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;\n  for (i = 0; i < numEncoderThreads; i++)\n  {\n    CEncoderInfo &encoder = encoders[i];\n    encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;\n\n    if (i == 0)\n    {\n      encoder.progressInfoSpec[0]->callback = callback;\n      encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;\n      SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);\n    }\n\n    #ifdef BENCH_MT\n    if (numDecoderThreads > 1)\n    {\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\n      {\n        HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)\n            #ifdef USE_ALLOCA\n            , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF\n            #endif\n            );\n        RINOK(res);\n      }\n    }\n    else\n    #endif\n    {\n      RINOK(encoder.Decode(0));\n    }\n  }\n  #ifdef BENCH_MT\n  HRESULT res = S_OK;\n  if (numDecoderThreads > 1)\n    for (i = 0; i < numEncoderThreads; i++)\n      for (UInt32 j = 0; j < numSubDecoderThreads; j++)\n      {\n        CEncoderInfo &encoder = encoders[i];\n        encoder.thread[j].Wait();\n        if (encoder.Results[j] != S_OK)\n          res = encoder.Results[j];\n      }\n  RINOK(res);\n  #endif\n  RINOK(status.Res);\n  SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);\n  info.UnpackSize = 0;\n  info.PackSize = 0;\n  info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;\n  for (i = 0; i < numEncoderThreads; i++)\n  {\n    CEncoderInfo &encoder = encoders[i];\n    info.UnpackSize += encoder.kBufferSize;\n    info.PackSize += encoder.compressedSize;\n  }\n  RINOK(callback->SetDecodeResult(info, false));\n  RINOK(callback->SetDecodeResult(info, true));\n  return S_OK;\n}\n\n\ninline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)\n{\n  UInt32 hs = dictionary - 1;\n  hs |= (hs >> 1);\n  hs |= (hs >> 2);\n  hs |= (hs >> 4);\n  hs |= (hs >> 8);\n  hs >>= 1;\n  hs |= 0xFFFF;\n  if (hs > (1 << 24))\n    hs >>= 1;\n  hs++;\n  return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +\n      (1 << 20) + (multiThread ? (6 << 20) : 0);\n}\n\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)\n{\n  const UInt32 kBufferSize = dictionary;\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2);\n  UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;\n  UInt32 numBigThreads = numThreads / numSubThreads;\n  return (kBufferSize + kCompressedBufferSize +\n    GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;\n}\n\nstatic bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)\n{\n  for (UInt32 i = 0; i < numCycles; i++)\n    if (CrcCalc(data, size) != crcBase)\n      return false;\n  return true;\n}\n\n#ifdef BENCH_MT\nstruct CCrcInfo\n{\n  NWindows::CThread Thread;\n  const Byte *Data;\n  UInt32 Size;\n  UInt32 NumCycles;\n  UInt32 Crc;\n  bool Res;\n  void Wait()\n  {\n    Thread.Wait();\n    Thread.Close();\n  }\n};\n\nstatic THREAD_FUNC_DECL CrcThreadFunction(void *param)\n{\n  CCrcInfo *p = (CCrcInfo *)param;\n  p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);\n  return 0;\n}\n\nstruct CCrcThreads\n{\n  UInt32 NumThreads;\n  CCrcInfo *Items;\n  CCrcThreads(): Items(0), NumThreads(0) {}\n  void WaitAll()\n  {\n    for (UInt32 i = 0; i < NumThreads; i++)\n      Items[i].Wait();\n    NumThreads = 0;\n  }\n  ~CCrcThreads()\n  {\n    WaitAll();\n    delete []Items;\n  }\n};\n#endif\n\nstatic UInt32 CrcCalc1(const Byte *buf, UInt32 size)\n{\n  UInt32 crc = CRC_INIT_VAL;;\n  for (UInt32 i = 0; i < size; i++)\n    crc = CRC_UPDATE_BYTE(crc, buf[i]);\n  return CRC_GET_DIGEST(crc);\n}\n\nstatic void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\n{\n  for (UInt32 i = 0; i < size; i++)\n    buf[i] = (Byte)RG.GetRnd();\n}\n\nstatic UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)\n{\n  RandGen(buf, size, RG);\n  return CrcCalc1(buf, size);\n}\n\nbool CrcInternalTest()\n{\n  CBenchBuffer buffer;\n  const UInt32 kBufferSize0 = (1 << 8);\n  const UInt32 kBufferSize1 = (1 << 10);\n  const UInt32 kCheckSize = (1 << 5);\n  if (!buffer.Alloc(kBufferSize0 + kBufferSize1))\n    return false;\n  Byte *buf = buffer.Buffer;\n  UInt32 i;\n  for (i = 0; i < kBufferSize0; i++)\n    buf[i] = (Byte)i;\n  UInt32 crc1 = CrcCalc1(buf, kBufferSize0);\n  if (crc1 != 0x29058C73)\n    return false;\n  CBaseRandomGenerator RG;\n  RandGen(buf + kBufferSize0, kBufferSize1, RG);\n  for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)\n    for (UInt32 j = 0; j < kCheckSize; j++)\n      if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))\n        return false;\n  return true;\n}\n\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)\n{\n  if (numThreads == 0)\n    numThreads = 1;\n\n  CBenchBuffer buffer;\n  size_t totalSize = (size_t)bufferSize * numThreads;\n  if (totalSize / numThreads != bufferSize)\n    return E_OUTOFMEMORY;\n  if (!buffer.Alloc(totalSize))\n    return E_OUTOFMEMORY;\n\n  Byte *buf = buffer.Buffer;\n  CBaseRandomGenerator RG;\n  UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;\n\n  UInt64 timeVal;\n  #ifdef BENCH_MT\n  CCrcThreads threads;\n  if (numThreads > 1)\n  {\n    threads.Items = new CCrcInfo[numThreads];\n    UInt32 i;\n    for (i = 0; i < numThreads; i++)\n    {\n      CCrcInfo &info = threads.Items[i];\n      Byte *data = buf + (size_t)bufferSize * i;\n      info.Data = data;\n      info.NumCycles = numCycles;\n      info.Size = bufferSize;\n      info.Crc = RandGenCrc(data, bufferSize, RG);\n    }\n    timeVal = GetTimeCount();\n    for (i = 0; i < numThreads; i++)\n    {\n      CCrcInfo &info = threads.Items[i];\n      RINOK(info.Thread.Create(CrcThreadFunction, &info));\n      threads.NumThreads++;\n    }\n    threads.WaitAll();\n    for (i = 0; i < numThreads; i++)\n      if (!threads.Items[i].Res)\n        return S_FALSE;\n  }\n  else\n  #endif\n  {\n    UInt32 crc = RandGenCrc(buf, bufferSize, RG);\n    timeVal = GetTimeCount();\n    if (!CrcBig(buf, bufferSize, numCycles, crc))\n      return S_FALSE;\n  }\n  timeVal = GetTimeCount() - timeVal;\n  if (timeVal == 0)\n    timeVal = 1;\n\n  UInt64 size = (UInt64)numCycles * totalSize;\n  speed = MyMultDiv64(size, timeVal, GetFreq());\n  return S_OK;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\n\n#ifndef __LZMABENCH_H\n#define __LZMABENCH_H\n\n#include <stdio.h>\n#include \"../../../Common/Types.h\"\n#ifdef EXTERNAL_LZMA\n#include \"../../UI/Common/LoadCodecs.h\"\n#endif\n\nstruct CBenchInfo\n{\n  UInt64 GlobalTime;\n  UInt64 GlobalFreq;\n  UInt64 UserTime;\n  UInt64 UserFreq;\n  UInt64 UnpackSize;\n  UInt64 PackSize;\n  UInt32 NumIterations;\n  CBenchInfo(): NumIterations(0) {}\n};\n\nstruct IBenchCallback\n{\n  virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;\n  virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;\n};\n\nUInt64 GetUsage(const CBenchInfo &benchOnfo);\nUInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);\nUInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);\nUInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);\n\nHRESULT LzmaBench(\n  #ifdef EXTERNAL_LZMA\n  CCodecs *codecs,\n  #endif\n  UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);\n\nconst int kBenchMinDicLogSize = 18;\n\nUInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);\n\nbool CrcInternalTest();\nHRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp",
    "content": "// LzmaBenchCon.cpp\n\n#include \"StdAfx.h\"\n\n#include <stdio.h>\n\n#include \"LzmaBench.h\"\n#include \"LzmaBenchCon.h\"\n#include \"../../../Common/IntToString.h\"\n\n#if defined(BENCH_MT) || defined(_WIN32)\n#include \"../../../Windows/System.h\"\n#endif\n\n#ifdef BREAK_HANDLER\n#include \"../../UI/Console/ConsoleClose.h\"\n#endif\n#include \"../../../Common/MyCom.h\"\n\nstruct CTotalBenchRes\n{\n  UInt64 NumIterations;\n  UInt64 Rating;\n  UInt64 Usage;\n  UInt64 RPU;\n  void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }\n  void Normalize()\n  {\n    if (NumIterations == 0)\n      return;\n    Rating /= NumIterations;\n    Usage /= NumIterations;\n    RPU /= NumIterations;\n    NumIterations = 1;\n  }\n  void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)\n  {\n    Rating = (r1.Rating + r2.Rating) / 2;\n    Usage = (r1.Usage + r2.Usage) / 2;\n    RPU = (r1.RPU + r2.RPU) / 2;\n    NumIterations = (r1.NumIterations + r2.NumIterations) / 2;\n  }\n};\n\nstruct CBenchCallback: public IBenchCallback\n{\n  CTotalBenchRes EncodeRes;\n  CTotalBenchRes DecodeRes;\n  FILE *f;\n  void Init() { EncodeRes.Init(); DecodeRes.Init(); }\n  void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }\n  UInt32 dictionarySize;\n  HRESULT SetEncodeResult(const CBenchInfo &info, bool final);\n  HRESULT SetDecodeResult(const CBenchInfo &info, bool final);\n};\n\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\n{\n  while (v1 > 1000000)\n  {\n    v1 >>= 1;\n    v2 >>= 1;\n  }\n}\n\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)\n{\n  UInt64 elTime = elapsedTime;\n  NormalizeVals(freq, elTime);\n  if (elTime == 0)\n    elTime = 1;\n  return value * freq / elTime;\n}\n\nstatic void PrintNumber(FILE *f, UInt64 value, int size)\n{\n  char s[32];\n  ConvertUInt64ToString(value, s);\n  fprintf(f, \" \");\n  for (int len = (int)strlen(s); len < size; len++)\n    fprintf(f, \" \");\n  fprintf(f, \"%s\", s);\n}\n\nstatic void PrintRating(FILE *f, UInt64 rating)\n{\n  PrintNumber(f, rating / 1000000, 6);\n}\n\nstatic void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)\n{\n  PrintNumber(f, (usage + 5000) / 10000, 5);\n  PrintRating(f, rpu);\n  PrintRating(f, rating);\n}\n\n\nstatic void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)\n{\n  UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);\n  PrintNumber(f, speed / 1024, 7);\n  UInt64 usage = GetUsage(info);\n  UInt64 rpu = GetRatingPerUsage(info, rating);\n  PrintResults(f, usage, rpu, rating);\n  res.NumIterations++;\n  res.RPU += rpu;\n  res.Rating += rating;\n  res.Usage += usage;\n}\n\nstatic void PrintTotals(FILE *f, const CTotalBenchRes &res)\n{\n  fprintf(f, \"       \");\n  PrintResults(f, res.Usage, res.RPU, res.Rating);\n}\n\n\nHRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)\n{\n  #ifdef BREAK_HANDLER\n  if (NConsoleClose::TestBreakSignal())\n    return E_ABORT;\n  #endif\n\n  if (final)\n  {\n    UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);\n    PrintResults(f, info, rating, EncodeRes);\n  }\n  return S_OK;\n}\n\nstatic const char *kSep = \"  | \";\n\n\nHRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)\n{\n  #ifdef BREAK_HANDLER\n  if (NConsoleClose::TestBreakSignal())\n    return E_ABORT;\n  #endif\n  if (final)\n  {\n    UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);\n    fprintf(f, kSep);\n    CBenchInfo info2 = info;\n    info2.UnpackSize *= info2.NumIterations;\n    info2.PackSize *= info2.NumIterations;\n    info2.NumIterations = 1;\n    PrintResults(f, info2, rating, DecodeRes);\n  }\n  return S_OK;\n}\n\nstatic void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)\n{\n  fprintf(f, \"\\nRAM %s \", sizeString);\n  PrintNumber(f, (size >> 20), 5);\n  fprintf(f, \" MB,  # %s %3d\", threadsString, (unsigned int)numThreads);\n}\n\nHRESULT LzmaBenchCon(\n  #ifdef EXTERNAL_LZMA\n  CCodecs *codecs,\n  #endif\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\n{\n  if (!CrcInternalTest())\n    return S_FALSE;\n  #ifdef BENCH_MT\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();  //\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\n  if (numThreads == (UInt32)-1)\n    numThreads = numCPUs;\n  if (numThreads > 1)\n    numThreads &= ~1;\n  if (dictionary == (UInt32)-1)\n  {\n    int dicSizeLog;\n    for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)\n      if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)\n        break;\n    dictionary = (1 << dicSizeLog);\n  }\n  #else\n  if (dictionary == (UInt32)-1)\n    dictionary = (1 << 22);\n  numThreads = 1;\n  #endif\n\n  PrintRequirements(f, \"usage:\", GetBenchMemoryUsage(numThreads, dictionary), \"Benchmark threads:   \", numThreads);\n\n  CBenchCallback callback;\n  callback.Init();\n  callback.f = f;\n  \n  fprintf(f, \"\\n\\nDict        Compressing          |        Decompressing\\n   \");\n  int j;\n  for (j = 0; j < 2; j++)\n  {\n    fprintf(f, \"   Speed Usage    R/U Rating\");\n    if (j == 0)\n      fprintf(f, kSep);\n  }\n  fprintf(f, \"\\n   \");\n  for (j = 0; j < 2; j++)\n  {\n    fprintf(f, \"    KB/s     %%   MIPS   MIPS\");\n    if (j == 0)\n      fprintf(f, kSep);\n  }\n  fprintf(f, \"\\n\\n\");\n  for (UInt32 i = 0; i < numIterations; i++)\n  {\n    const int kStartDicLog = 22;\n    int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;\n    while (((UInt32)1 << pow) > dictionary)\n      pow--;\n    for (; ((UInt32)1 << pow) <= dictionary; pow++)\n    {\n      fprintf(f, \"%2d:\", pow);\n      callback.dictionarySize = (UInt32)1 << pow;\n      HRESULT res = LzmaBench(\n        #ifdef EXTERNAL_LZMA\n        codecs,\n        #endif\n        numThreads, callback.dictionarySize, &callback);\n      fprintf(f, \"\\n\");\n      RINOK(res);\n    }\n  }\n  callback.Normalize();\n  fprintf(f, \"----------------------------------------------------------------\\nAvr:\");\n  PrintTotals(f, callback.EncodeRes);\n  fprintf(f, \"     \");\n  PrintTotals(f, callback.DecodeRes);\n  fprintf(f, \"\\nTot:\");\n  CTotalBenchRes midRes;\n  midRes.SetMid(callback.EncodeRes, callback.DecodeRes);\n  PrintTotals(f, midRes);\n  fprintf(f, \"\\n\");\n  return S_OK;\n}\n\nstruct CTempValues\n{\n  UInt64 *Values;\n  CTempValues(UInt32 num) { Values = new UInt64[num]; }\n  ~CTempValues() { delete []Values; }\n};\n\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)\n{\n  if (!CrcInternalTest())\n    return S_FALSE;\n\n  #ifdef BENCH_MT\n  UInt64 ramSize = NWindows::NSystem::GetRamSize();\n  UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();\n  PrintRequirements(f, \"size: \", ramSize, \"CPU hardware threads:\", numCPUs);\n  if (numThreads == (UInt32)-1)\n    numThreads = numCPUs;\n  #else\n  numThreads = 1;\n  #endif\n  if (dictionary == (UInt32)-1)\n    dictionary = (1 << 24);\n\n  CTempValues speedTotals(numThreads);\n  fprintf(f, \"\\n\\nSize\");\n  for (UInt32 ti = 0; ti < numThreads; ti++)\n  {\n    fprintf(f, \" %5d\", ti + 1);\n    speedTotals.Values[ti] = 0;\n  }\n  fprintf(f, \"\\n\\n\");\n\n  UInt64 numSteps = 0;\n  for (UInt32 i = 0; i < numIterations; i++)\n  {\n    for (int pow = 10; pow < 32; pow++)\n    {\n      UInt32 bufSize = (UInt32)1 << pow;\n      if (bufSize > dictionary)\n        break;\n      fprintf(f, \"%2d: \", pow);\n      UInt64 speed;\n      for (UInt32 ti = 0; ti < numThreads; ti++)\n      {\n        #ifdef BREAK_HANDLER\n        if (NConsoleClose::TestBreakSignal())\n          return E_ABORT;\n        #endif\n        RINOK(CrcBench(ti + 1, bufSize, speed));\n        PrintNumber(f, (speed >> 20), 5);\n        speedTotals.Values[ti] += speed;\n      }\n      fprintf(f, \"\\n\");\n      numSteps++;\n    }\n  }\n  if (numSteps != 0)\n  {\n    fprintf(f, \"\\nAvg:\");\n    for (UInt32 ti = 0; ti < numThreads; ti++)\n      PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);\n    fprintf(f, \"\\n\");\n  }\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h",
    "content": "// LzmaBenchCon.h\n\n#ifndef __LZMABENCHCON_H\n#define __LZMABENCHCON_H\n\n#include <stdio.h>\n#include \"../../../Common/Types.h\"\n#ifdef EXTERNAL_LZMA\n#include \"../../UI/Common/LoadCodecs.h\"\n#endif\nHRESULT LzmaBenchCon(\n  #ifdef EXTERNAL_LZMA\n  CCodecs *codecs,\n  #endif\n  FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\n\nHRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\n\n#include \"StdAfx.h\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzma_version.h",
    "content": "#ifndef LZMA_VERSION_H\n#define LZMA_VERSION_H\n\n/*\n    Version and copyright information used by LZMA utils.\n*/\n\nstatic const char *LZMA_SDK_VERSION_STRING = \"4.43\";\n\nstatic const char *LZMA_SDK_COPYRIGHT_STRING =\n\t\t\"Copyright (C) 1999-2006 Igor Pavlov\";\n\nstatic const char *LZMA_SDK_COPYRIGHT_INFO =\n\t\t\"  See http://7-zip.org/sdk.html or the documentation of LZMA SDK for\\n\"\n\t\t\"  the license. For reference, the version 4.43 is free software\\n\"\n\t\t\"  licensed under the GNU LGPL.\";\n\n\nstatic const char *LZMA_UTILS_VERSION_STRING = PACKAGE_VERSION;\n\nstatic const char *LZMA_UTILS_COPYRIGHT_STRING =\n\t\t\"Copyright (C) 2006 Lasse Collin\";\n\nstatic const char *LZMA_UTILS_COPYRIGHT_INFO =\n\t\t\"This program comes with ABSOLUTELY NO WARRANTY.\\n\"\n\t\t\"You may redistribute copies of this program\\n\"\n\t\t\"under the terms of the GNU General Public License.\\n\"\n\t\t\"For more information about these matters, see the file \"\n\t\t\"named COPYING.\\n\";\n\n#endif /* ifndef LZMA_VERSION_H */\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzmp.cpp",
    "content": "/*\n * LZMA command line tool similar to gzip to encode and decode LZMA files.\n *\n * Copyright (C) 2005 Ville Koskinen\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2\n * of the License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,\n * USA.\n */\n\n#include \"../../../Common/MyInitGuid.h\"\n\n#include <iostream>\nusing std::cout;\nusing std::cerr;\nusing std::endl;\n\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n\n#include <string>\nusing std::string;\n#include <vector>\nusing std::vector;\ntypedef vector<string> stringVector;\n\n#include <unistd.h>\n#include <getopt.h>\n#include <signal.h>\n\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <utime.h>\n#include <sys/time.h> // futimes()\n\n// For Solaris\n#ifndef HAVE_FUTIMES\n//#define futimes(fd, tv) futimesat(fd, NULL, tv)\n#endif\n\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\n#include <fcntl.h>\n#include <io.h>\n#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)\n#else\n#define MY_SET_BINARY_MODE(file)\n#endif\n\n#include \"../../../7zip/Common/FileStreams.h\"\n\n#include \"../../../Common/Types.h\"\n\n#include \"../../../7zip/Compress/LzmaDecoder.h\"\n#include \"../../../7zip/Compress/LzmaEncoder.h\"\n\n#include \"Exception.h\"\n\n#include \"lzma_version.h\"\n\nnamespace lzma {\n\nconst char *PROGRAM_VERSION = PACKAGE_VERSION;\nconst char *PROGRAM_COPYRIGHT = \"Copyright (C) 2006 Ville Koskinen\";\n\n/* LZMA_Alone switches:\n    -a{N}:  set compression mode - [0, 2], default: 2 (max)\n    -d{N}:  set dictionary - [0,28], default: 23 (8MB)\n    -fb{N}: set number of fast bytes - [5, 255], default: 128\n    -lc{N}: set number of literal context bits - [0, 8], default: 3\n    -lp{N}: set number of literal pos bits - [0, 4], default: 0\n    -pb{N}: set number of pos bits - [0, 4], default: 2\n    -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, bt4b, pat2r, pat2,\n                pat2h, pat3h, pat4h, hc3, hc4], default: bt4\n*/\n\nstruct lzma_option {\n\tshort compression_mode;\t\t\t// -a\n\tshort dictionary;\t\t\t// -d\n\tshort fast_bytes;\t\t\t// -fb\n\twchar_t *match_finder;\t\t\t// -mf\n\tshort literal_context_bits;\t\t// -lc\n\tshort literal_pos_bits;\t\t\t// -lp\n\tshort pos_bits;\t\t\t\t// -pb\n};\n\n/* The following is a mapping from gzip/bzip2 style -1 .. -9 compression modes\n * to the corresponding LZMA compression modes. Thanks, Larhzu, for coining\n * these. */\nconst lzma_option option_mapping[] = {\n\t{ 0,  0,  0,    NULL, 0, 0, 0},\t\t// -0 (needed for indexing)\n\t{ 0, 16, 64,  L\"hc4\", 3, 0, 2},\t\t// -1\n\t{ 0, 20, 64,  L\"hc4\", 3, 0, 2},\t\t// -2\n\t{ 1, 19, 64,  L\"bt4\", 3, 0, 2},\t\t// -3\n\t{ 2, 20, 64,  L\"bt4\", 3, 0, 2},\t\t// -4\n\t{ 2, 21, 128, L\"bt4\", 3, 0, 2},\t\t// -5\n\t{ 2, 22, 128, L\"bt4\", 3, 0, 2},\t\t// -6\n\t{ 2, 23, 128, L\"bt4\", 3, 0, 2},\t\t// -7\n\t{ 2, 24, 255, L\"bt4\", 3, 0, 2},\t\t// -8\n\t{ 2, 25, 255, L\"bt4\", 3, 0, 2},\t\t// -9\n};\n\nstruct extension_pair {\n\tchar *from;\n\tchar *to;\n};\n\nconst extension_pair known_extensions[] = {\n\t{ \".lzma\", \"\" },\n\t{ \".tlz\", \".tar\" },\n\t{ NULL, NULL }\n};\n\n/* Sorry, I just happen to like enumerations. */\nenum PROGRAM_MODE {\n\tPM_COMPRESS = 0,\n\tPM_DECOMPRESS,\n\tPM_TEST,\n\tPM_HELP,\n\tPM_LICENSE,\n\tPM_VERSION\n};\n\nenum {\n\tSTATUS_OK = 0,\n\tSTATUS_ERROR = 1,\n\tSTATUS_WARNING = 2\n};\n\n/* getopt options. */\n/* struct option { name, has_arg, flag, val } */\nconst struct option long_options[] = {\n\t{ \"stdout\", 0, 0, 'c' },\n\t{ \"decompress\", 0, 0, 'd' },\n\t{ \"compress\", 0, 0, 'z' },\n\t{ \"keep\", 0, 0, 'k' },\n\t{ \"force\", 0, 0, 'f' },\n\t{ \"test\", 0, 0, 't' },\n\t{ \"suffix\", 1, 0, 'S' },\n\t{ \"quiet\", 0, 0, 'q' },\n\t{ \"verbose\", 0, 0, 'v' },\n\t{ \"help\", 0, 0, 'h' },\n\t{ \"license\", 0, 0, 'L' },\n\t{ \"version\", 0, 0, 'V' },\n\t{ \"fast\", 0, 0, '1' },\n\t{ \"best\", 0, 0, '9' },\n\t{ 0, 0, 0, 0 }\n};\n\n/* getopt option string (for the above options). */\nconst char option_string[] = \"cdzkftS:qvhLV123456789A:D:F:\";\n\n/* Defaults. */\nPROGRAM_MODE program_mode = PM_COMPRESS;\nint\tverbosity\t\t\t= 0;\nbool\tstdinput\t\t\t= false;\nbool\tstdoutput\t\t\t= false;\nbool\tkeep\t\t\t\t= false;\nbool\tforce\t\t\t\t= false;\nint\tcompression_mode\t\t= 7;\n//char\t*suffix\t\t\t\t= strdup(\".lzma\");\nchar\t*suffix\t\t\t\t= strdup(known_extensions[0].from);\nlzma_option\tadvanced_options \t= { -1, -1, -1, NULL, -1, -1, -1 };\n\nvoid print_help(const char *const argv0)\n{\n\t// Help goes to stdout while other messages go to stderr.\n\tcout << \"\\nlzma \" << PROGRAM_VERSION\n\t\t<< \" \" << PROGRAM_COPYRIGHT << \"\\n\"\n\t\t\"Based on LZMA SDK \" << LZMA_SDK_VERSION_STRING << \" \"\n\t\t<< LZMA_SDK_COPYRIGHT_STRING\n\t\t<< \"\\n\\nUsage: \" << argv0\n\t\t<< \" [flags and input files in any order]\\n\"\n\"  -c --stdout       output to standard output\\n\"\n\"  -d --decompress   force decompression\\n\"\n\"  -z --compress     force compression\\n\"\n\"  -k --keep         keep (don't delete) input files\\n\"\n\"  -f --force        force overwrite of output file and compress links\\n\"\n\"  -t --test         test compressed file integrity\\n\"\n\"  -S .suf  --suffix .suf   use suffix .suf on compressed files\\n\"\n\"  -q --quiet        suppress error messages\\n\"\n\"  -v --verbose      be verbose\\n\"\n\"  -h --help         print this message\\n\"\n\"  -L --license      display the license information\\n\"\n\"  -V --version      display version numbers of LZMA SDK and lzma\\n\"\n\"  -1 .. -2          fast compression\\n\"\n\"  -3 .. -9          good to excellent compression. -7 is the default.\\n\"\n\"     --fast         alias for -1\\n\"\n\"     --best         alias for -9 (usually *not* what you want)\\n\\n\"\n\"  Memory usage depends a lot on the chosen compression mode -1 .. -9.\\n\"\n\"  See the man page lzma(1) for details.\\n\\n\";\n}\n\nvoid print_license(void)\n{\n\tcout << \"\\n  LZMA command line tool \" << PROGRAM_VERSION << \" - \"\n\t\t<< PROGRAM_COPYRIGHT\n\t\t<< \"\\n  LZMA SDK \" << LZMA_SDK_VERSION_STRING << \" - \"\n\t\t<< LZMA_SDK_COPYRIGHT_STRING\n\t\t<< \"\\n  This program is a part of the LZMA utils package.\\n\"\n\t\t\"  http://tukaani.org/lzma/\\n\\n\"\n\"  This program is free software; you can redistribute it and/or\\n\"\n\"  modify it under the terms of the GNU General Public License\\n\"\n\"  as published by the Free Software Foundation; either version 2\\n\"\n\"  of the License, or (at your option) any later version.\\n\"\n\"\\n\"\n\"  This program is distributed in the hope that it will be useful,\\n\"\n\"  but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\"\n\"  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\"\n\"  GNU General Public License for more details.\\n\"\n\"\\n\";\n}\n\nvoid print_version(void)\n{\n\tcout << \"LZMA command line tool \" << PROGRAM_VERSION << \"\\n\"\n\t\t<< \"LZMA SDK \" << LZMA_SDK_VERSION_STRING << \"\\n\";\n}\n\nshort str2int (const char *str, const int &min, const int &max)\n{\n\tint value = -1;\n\tchar *endptr = NULL;\n\tif (str == NULL || str[0] == '\\0')\n\t\tthrow ArgumentException(\"Invalid integer option\");\n\tvalue = strtol (str, &endptr, 10);\n\tif (*endptr != '\\0' || value < min || value > max)\n\t\tthrow ArgumentException(\"Invalid integer option\");\n\treturn value;\n}\n\nvoid parse_options(int argc, char **argv, stringVector &filenames)\n{\n\t/* Snatched from getopt(3). */\n\tint c;\n\n\t/* Check how we were called */\n\t{\n\t\tchar *p = strrchr (argv[0], '/'); // Remove path prefix, if any\n\t\tif (p++ == NULL)\n\t\t\tp = argv[0];\n\t\tif (strstr (p, \"un\") != NULL) {\n\t\t\tprogram_mode = PM_DECOMPRESS;\n\t\t} else if (strstr (p, \"cat\") != NULL) {\n\t\t\tprogram_mode = PM_DECOMPRESS;\n\t\t\tstdoutput = true;\n\t\t}\n\t}\n\n\twhile (-1 != (c = getopt_long(argc, argv, option_string,\n\t\t\tlong_options, NULL))) {\n\t\tswitch (c) {\n\t\t\t// stdout\n\t\t\tcase 'c':\n\t\t\t\tstdoutput = true;\n\t\t\t\tbreak;\n\n\t\t\t// decompress\n\t\t\tcase 'd':\n\t\t\t\tprogram_mode = PM_DECOMPRESS;\n\t\t\t\tbreak;\n\n\t\t\t// compress\n\t\t\tcase 'z':\n\t\t\t\tprogram_mode = PM_COMPRESS;\n\t\t\t\tbreak;\n\n\t\t\t// keep\n\t\t\tcase 'k':\n\t\t\t\tkeep = true;\n\t\t\t\tbreak;\n\n\t\t\t// force\n\t\t\tcase 'f':\n\t\t\t\tforce = true;\n\t\t\t\tbreak;\n\n\t\t\t// test\n\t\t\tcase 't':\n\t\t\t\tprogram_mode = PM_TEST;\n\t\t\t\tbreak;\n\n\t\t\t// suffix\n\t\t\tcase 'S':\n\t\t\t\tif (optarg) {\n\t\t\t\t\tfree(suffix);\n\t\t\t\t\tsuffix = strdup(optarg);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\t// quiet\n\t\t\tcase 'q':\n\t\t\t\tverbosity = 0;\n\t\t\t\tbreak;\n\n\t\t\t// verbose\n\t\t\tcase 'v':\n\t\t\t\tverbosity++;\n\t\t\t\tbreak;\n\n\t\t\t// help\n\t\t\tcase 'h':\n\t\t\t\tprogram_mode = PM_HELP;\n\t\t\t\tbreak;\n\n\t\t\t// license\n\t\t\tcase 'L':\n\t\t\t\tprogram_mode = PM_LICENSE;\n\t\t\t\tbreak;\n\n\t\t\t// version\n\t\t\tcase 'V':\n\t\t\t\tprogram_mode = PM_VERSION;\n\t\t\t\tbreak;\n\n\t\t\tcase '1': case '2': case '3': case '4': case '5':\n\t\t\tcase '6': case '7': case '8': case '9':\n\t\t\t\tcompression_mode = c - '0';\n\t\t\t\tbreak;\n\n\t\t\t// Advanced options //\n\t\t\t// Compression mode\n\t\t\tcase 'A':\n\t\t\t\tadvanced_options.compression_mode =\n\t\t\t\t\t\tstr2int (optarg, 0, 2);\n\t\t\t\tbreak;\n\n\t\t\t// Dictionary size\n\t\t\tcase 'D':\n\t\t\t\tadvanced_options.dictionary =\n\t\t\t\t\t\tstr2int (optarg, 0, 28);\n\t\t\t\tbreak;\n\n\t\t\t// Fast bytes\n\t\t\tcase 'F':\n\t\t\t\tadvanced_options.fast_bytes =\n\t\t\t\t\t\tstr2int (optarg, 0, 273);\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tthrow ArgumentException(\"\");\n\t\t\t\tbreak;\n\t\t} // switch(c)\n\t} // while(1)\n\n\tfor (int i = optind; i < argc; i++) {\n\t\tif (strcmp(\"-\", argv[i]) == 0)\n\t\t\tcontinue;\n\t\tfilenames.push_back(argv[i]);\n\t}\n} // parse_options\n\nvoid set_encoder_properties(NCompress::NLzma::CEncoder *encoder,\n\t\tlzma_option &opt)\n{\n\t/* Almost verbatim from LzmaAlone.cpp. */\n\t    PROPID propIDs[] =\n\t{\n\t\tNCoderPropID::kDictionarySize,\n\t\tNCoderPropID::kPosStateBits,\n\t\tNCoderPropID::kLitContextBits,\n\t\tNCoderPropID::kLitPosBits,\n\t\tNCoderPropID::kAlgorithm,\n\t\tNCoderPropID::kNumFastBytes,\n\t\tNCoderPropID::kMatchFinder,\n\t\tNCoderPropID::kEndMarker\n\t};\n\tconst int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\n#define VALUE(x) (advanced_options.x >= 0 ? advanced_options.x : opt.x)\n\tPROPVARIANT properties[kNumProps];\n\tfor (int p = 0; p < 6; p++)\n\t\tproperties[p].vt = VT_UI4;\n\tproperties[0].ulVal = UInt32(1 << VALUE (dictionary));\n\tproperties[1].ulVal = UInt32(VALUE (pos_bits));\n\tproperties[2].ulVal = UInt32(VALUE (literal_context_bits));\n\tproperties[3].ulVal = UInt32(VALUE (literal_pos_bits));\n\tproperties[4].ulVal = UInt32(VALUE (compression_mode));\n\tproperties[5].ulVal = UInt32(VALUE (fast_bytes));\n#undef VALUE\n\n\tproperties[6].vt = VT_BSTR;\n\tproperties[6].bstrVal = (BSTR)opt.match_finder;\n\n\tproperties[7].vt = VT_BOOL;\n\tproperties[7].boolVal = stdinput ? VARIANT_TRUE : VARIANT_FALSE;\n\n\tif (encoder->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\n\t\tthrow Exception(\"SetCoderProperties() error\");\n}\n\nvoid encode(NCompress::NLzma::CEncoder *encoderSpec,\n\t\tCMyComPtr<ISequentialInStream> inStream,\n\t\tCMyComPtr<ISequentialOutStream> outStream,\n\t\tlzma_option encoder_options,\n\t\tUInt64 fileSize)\n{\n\tset_encoder_properties(encoderSpec, encoder_options);\n\n\tencoderSpec->WriteCoderProperties(outStream);\n\n\tfor (int i = 0; i < 8; i++)\n\t{\n\t\tByte b = Byte(fileSize >> (8 * i));\n\t\tif (outStream->Write(&b, sizeof(b), 0) != S_OK)\n\t\t\tthrow Exception(\"Write error while encoding\");\n\t}\n\n\tHRESULT result = encoderSpec->Code(inStream, outStream, 0, 0, 0);\n\n\tif (result == E_OUTOFMEMORY)\n\t\tthrow Exception(\"Cannot allocate memory\");\n\telse if (result != S_OK) {\n\t\tchar buffer[33];\n\t\tsnprintf(buffer, 33, \"%d\", (unsigned int)result);\n\t\tthrow Exception(string(\"Encoder error: \") + buffer);\n\t}\n}\n\nvoid decode(NCompress::NLzma::CDecoder *decoderSpec,\n\t\tCMyComPtr<ISequentialInStream> inStream,\n\t\tCMyComPtr<ISequentialOutStream> outStream)\n{\n\tconst UInt32 kPropertiesSize = 5;\n\tByte properties[kPropertiesSize];\n\tUInt32 processedSize;\n\tUInt64 fileSize = 0;\n\n\tif (inStream->Read(properties, kPropertiesSize, &processedSize) != S_OK)\n\t\tthrow Exception(\"Read error\");\n\tif (processedSize != kPropertiesSize)\n\t\tthrow Exception(\"Read error\");\n\tif (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)\n\t\tthrow Exception(\"SetDecoderProperties() error\");\n\n\tfor (int i = 0; i < 8; i++)\n\t{\n\t\tByte b;\n\n\t\tif (inStream->Read(&b, sizeof(b), &processedSize) != S_OK)\n\t\t\tthrow Exception(\"Read error\");\n\t\tif (processedSize != 1)\n\t\t\tthrow Exception(\"Read error\");\n\n\t\tfileSize |= ((UInt64)b) << (8 * i);\n\t}\n\n\tif (decoderSpec->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\n\t\tthrow Exception(\"Decoder error\");\n}\n\nint open_instream(const string infile,\n\t\tCMyComPtr<ISequentialInStream> &inStream,\n\t\tUInt64 &fileSize)\n{\n\tCInFileStream *inStreamSpec = new CInFileStream;\n\tinStream = inStreamSpec;\n\tif (!inStreamSpec->Open(infile.c_str()))\n\t\tthrow Exception(\"Cannot open input file \" + infile);\n\n\tinStreamSpec->File.GetLength(fileSize);\n\n\treturn inStreamSpec->File.GetHandle();\n}\n\nint open_outstream(const string outfile,\n\t\tCMyComPtr<ISequentialOutStream> &outStream)\n{\n\tCOutFileStream *outStreamSpec = new COutFileStream;\n\toutStream = outStreamSpec;\n\n\tbool open_by_force = (program_mode == PM_TEST) | force;\n\n\tif (!outStreamSpec->Create(outfile.c_str(), open_by_force))\n\t\tthrow Exception(\"Cannot open output file \" + outfile);\n\n\treturn outStreamSpec->File.GetHandle();\n}\n\ndouble get_ratio(int inhandle, int outhandle)\n{\n\tstruct stat in_stats, out_stats;\n\tfstat(inhandle, &in_stats);\n\tfstat(outhandle, &out_stats);\n\n\treturn (double)out_stats.st_size / (double)in_stats.st_size;\n}\n\nmode_t get_file_mode(string filename)\n{\n\tstruct stat in_stat;\n\tlstat(filename.c_str(), &in_stat);\n\n\treturn in_stat.st_mode;\n}\n\nbool string_ends_with(string str, string ending)\n{\n\treturn equal(ending.rbegin(), ending.rend(), str.rbegin());\n}\n\nbool extension_is_known(string filename)\n{\n\tbool known_format = false;\n\textension_pair extension; int i = 1;\n\n\textension = known_extensions[0];\n\twhile (extension.from != NULL) {\n\t\tif (string_ends_with(filename, extension.from)) {\n\t\t\tknown_format = true;\n\t\t\tbreak;\n\t\t}\n\t\textension = known_extensions[i];\n\t\ti++;\n\t}\n\n\tif (!known_format) {\n\t\tif (!string_ends_with(filename, suffix)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\nstring replace_extension(string filename)\n{\n\tint suffix_starts_at = filename.length() - strlen (suffix);\n\tstring from_suffix = filename.substr(suffix_starts_at, strlen (suffix));\n\tstring ret = filename.substr(0, suffix_starts_at);\n\textension_pair extension; int i = 1;\n\n\tbool found_replacement = false;\n\textension = known_extensions[0];\n\twhile (extension.from != NULL) {\n\t\tif (from_suffix.compare(extension.from) == 0) {\n\t\t\tret += extension.to;\n\t\t\tfound_replacement = true;\n\t\t\tbreak;\n\t\t}\n\n\t\textension = known_extensions[i];\n\t\ti++;\n\t}\n\n\treturn ret;\n}\n\nstring pretty_print_status(string filename, string output_filename,\n\t\tstring ratio)\n{\n\tstring ret = \"\";\n\n\tret += filename;\n\tret += \":\\t \";\n\n\tif (program_mode == PM_TEST) {\n\t\tret += \"decoded succesfully\";\n\n\t\treturn ret;\n\t}\n\n\tif (!stdinput && !stdoutput) {\n\t\tret += ratio;\n\t\tret += \" -- \";\n\t}\n\n\tif (program_mode == PM_COMPRESS) {\n\t\tif (keep) {\n\t\t\tret += \"encoded succesfully\";\n\n\t\t\treturn ret;\n\t\t}\n\n\t\tret += \"replaced with \";\n\t\tret += output_filename;\n\n\t\treturn ret;\n\t}\n\n\tif (program_mode == PM_DECOMPRESS) {\n\t\tif (keep) {\n\t\t\tret += \"decoded succesfully\";\n\n\t\t\treturn ret;\n\t\t}\n\n\t\tret += \"replaced with \";\n\t\tret += output_filename;\n\n\t\treturn ret;\n\t}\n\n\treturn ret;\n}\n\nstatic string archive_name; // I know, it is crude, but I haven't found any other\n    // way then making a global variable to transfer filename to handler\n\nvoid signal_handler (int signum)\n{\n    unlink (archive_name.c_str()); // deleting\n    signal (signum, SIG_DFL); // we return the default function to used signal\n    kill (getpid(), signum); // and then send this signal to the process again\n}\n\n} // namespace lzma\n\n\nint main(int argc, char **argv)\n{\n\tusing namespace lzma;\n\tusing std::cerr;\n\n\tstringVector filenames;\n\n\tsignal (SIGTERM,signal_handler);\n\tsignal (SIGHUP,signal_handler);\n\tsignal (SIGINT,signal_handler);\n\n\ttry {\n\t\tparse_options(argc, argv, filenames);\n\t}\n\tcatch (...) {\n\t\treturn STATUS_ERROR;\n\t}\n\n\tif (program_mode == PM_HELP) {\n\t\tprint_help(argv[0]);\n\t\treturn STATUS_OK;\n\t}\n\telse if (program_mode == PM_LICENSE) {\n\t\tprint_license();\n\t\treturn STATUS_OK;\n\t}\n\telse if (program_mode == PM_VERSION) {\n\t\tprint_version();\n\t\treturn STATUS_OK;\n\t}\n\n\tif (filenames.empty()) {\n\t\tstdinput = true;\n\t\tstdoutput = true;\n\n\t\t/* FIXME: get rid of this */\n\t\tfilenames.push_back(\"-\");\n\t}\n\n\t/* Protection: always create new files with 0600 in order to prevent\n\t * outsiders from reading incomplete data. */\n\tumask(0077);\n\n\tbool warning = false;\n\n\tfor (int i = 0; i < filenames.size(); i++) {\n\t\tCMyComPtr<ISequentialInStream> inStream;\n\t\tCMyComPtr<ISequentialOutStream> outStream;\n\t\tUInt64 fileSize = 0;\n\t\tint inhandle = 0, outhandle = 0;\n\t\tstring output_filename;\n\n\t\tif (stdinput) {\n\t\t\tinStream = new CStdInFileStream;\n\t\t\tMY_SET_BINARY_MODE(stdin);\n\t\t\tfileSize = (UInt64)(Int64)-1;\n\n\t\t\tinhandle = STDIN_FILENO;\n\n\t\t\toutStream = new CStdOutFileStream;\n\t\t\tMY_SET_BINARY_MODE(stdout);\n\n\t\t\touthandle = STDOUT_FILENO;\n\t\t}\n\t\telse {\n\t\t\tmode_t infile_mode = get_file_mode(filenames[i]);\n\t\t\tif (!S_ISREG(infile_mode)) {\n\t\t\t\tif (S_ISDIR(infile_mode)) {\n\t\t\t\t\twarning = true;\n\t\t\t\t\tcerr << argv[0] << \": \" << filenames[i] << \": \"\n\t\t\t\t\t\t<< \"cowardly refusing to work on directory\"\n\t\t\t\t\t\t<< endl;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse if (S_ISLNK(infile_mode)) {\n\t\t\t\t\tif (!stdoutput && !force) {\n\t\t\t\t\t\twarning = true;\n\n\t\t\t\t\tcerr << argv[0] << \": \" << filenames[i] << \": \"\n\t\t\t\t\t\t\t<< \"cowardly refusing to work on symbolic link \"\n\t\t\t\t\t\t\t<< \"(use --force to force encoding or decoding)\"\n\t\t\t\t\t\t\t<< endl;\n\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\twarning = true;\n\n\t\t\t\t\tcerr << argv[0] << \": \" << filenames[i] << \": \"\n\t\t\t\t\t\t<< \"doesn't exist or is not a regular file\"\n\t\t\t\t\t\t<< endl;\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Test if the file already ends with *suffix.\n\t\t\tif (program_mode == PM_COMPRESS && !force\n\t\t\t\t\t&& string_ends_with(filenames[i],\n\t\t\t\t\t\tsuffix)) {\n\t\t\t\twarning = true;\n\n\t\t\t\tcerr << filenames[i] << \" already has \"\n\t\t\t\t\t<< suffix << \" suffix -- unchanged\\n\";\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Test if the file extension is known.\n\t\t\tif (program_mode == PM_DECOMPRESS\n\t\t\t\t\t&& !extension_is_known(filenames[i])) {\n\t\t\t\twarning = true;\n\n\t\t\t\tcerr << filenames[i] << \": \"\n\t\t\t\t\t<< \" unknown suffix -- unchanged\"\n\t\t\t\t\t<< endl;\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tinhandle = open_instream(filenames[i], inStream, fileSize);\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tcerr << argv[0] << \": \" << e.what() << endl;\n\t\t\t\treturn STATUS_ERROR;\n\t\t\t}\n\n\t\t\tif (stdoutput) {\n\t\t\t\toutStream = new CStdOutFileStream;\n\t\t\t\tMY_SET_BINARY_MODE(stdout);\n\n\t\t\t\touthandle = STDOUT_FILENO;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t/* Testing mode is nothing else but decoding\n\t\t\t\t * and throwing away the result. */\n\t\t\t\tif (program_mode == PM_TEST)\n\t\t\t\t\toutput_filename = \"/dev/null\";\n\t\t\t\telse if (program_mode == PM_DECOMPRESS)\n\t\t\t\t\toutput_filename = replace_extension(filenames[i]);\n\t\t\t\telse\n\t\t\t\t\toutput_filename = filenames[i]\n\t\t\t\t\t\t\t+ suffix;\n\t\t\t\tarchive_name = output_filename;\n\n\t\t\t\ttry {\n\t\t\t\t\touthandle = open_outstream(output_filename, outStream);\n\t\t\t\t}\n\t\t\t\tcatch (Exception e) {\n\t\t\t\t\tcerr << argv[0] << \": \" << e.what() << endl;\n\t\t\t\t\treturn STATUS_ERROR;\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\t// Unless --force is specified, do not read/write compressed\n\t\t// data from/to a terminal.\n\t\tif (!force) {\n\t\t\tif (program_mode == PM_COMPRESS && isatty(outhandle)) {\n\t\t\t\tcerr << argv[0] << \": compressed data not \"\n\t\t\t\t\t\"written to a terminal. Use \"\n\t\t\t\t\t\"-f to force compression.\\n\"\n\t\t\t\t\t<< argv[0] << \": For help, type: \"\n\t\t\t\t\t<< argv[0] << \" -h\\n\";\n\t\t\t\treturn STATUS_ERROR;\n\t\t\t} else if (program_mode == PM_DECOMPRESS\n\t\t\t\t\t&& isatty(inhandle)) {\n\t\t\t\tcerr << argv[0] << \": compressed data not \"\n\t\t\t\t\t\"read from a terminal. Use \"\n\t\t\t\t\t\"-f to force decompression.\\n\"\n\t\t\t\t\t<< argv[0] << \": For help, type: \"\n\t\t\t\t\t<< argv[0] << \" -h\\n\";\n\t\t\t\treturn STATUS_ERROR;\n\t\t\t}\n\t\t}\n\n\t\tif (program_mode == PM_COMPRESS) {\n\t\t\t    NCompress::NLzma::CEncoder *encoderSpec =\n\t\t\t\t      new NCompress::NLzma::CEncoder;\n\n\t\t\tlzma_option options = option_mapping[compression_mode];\n\n\t\t\ttry {\n\t\t\t\tencode(encoderSpec, inStream, outStream, options, fileSize);\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tcerr << argv[0] << \": \" << e.what() << endl;\n\t\t\t\tunlink(output_filename.c_str());\n\t\t\t\tdelete(encoderSpec);\n\n\t\t\t\treturn STATUS_ERROR;\n\t\t\t}\n\n\t\t\tdelete(encoderSpec);\n\t\t}\n\t\telse {\t\t\t// PM_DECOMPRESS | PM_TEST\n\t\t    NCompress::NLzma::CDecoder *decoderSpec =\n\t\t        new NCompress::NLzma::CDecoder;\n\n\t\t\ttry {\n\t\t\t\tdecode(decoderSpec, inStream, outStream);\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tcerr << argv[0] << \": \" << e.what() << endl;\n\t\t\t\tunlink(output_filename.c_str());\n\t\t\t\tdelete(decoderSpec);\n\n\t\t\t\treturn STATUS_ERROR;\n\t\t\t}\n\n\t\t\tdelete(decoderSpec);\n\t\t}\n\n\t\t/* Set permissions and owners. */\n\t\tif ( (program_mode == PM_COMPRESS || program_mode == PM_DECOMPRESS )\n\t\t\t\t&& (!stdinput && !stdoutput) ) {\n\n\t\t\tint ret = 0;\n\t\t\tstruct stat file_stats;\n\t\t\tret = fstat(inhandle, &file_stats);\n\n\t\t\tret = fchmod(outhandle, file_stats.st_mode);\n\t\t\tret = fchown(outhandle, file_stats.st_uid, file_stats.st_gid);\n\t\t\t// We need to call fchmod() again, since otherwise the SUID bits\n\t\t\t// are lost.\n\t\t\tret = fchmod(outhandle, file_stats.st_mode);\n\n\t\t\tstruct timeval file_times[2];\n\t\t\t// Access time\n\t\t\tfile_times[0].tv_sec = file_stats.st_atime;\n\t\t\tfile_times[0].tv_usec = 0;\n\t\t\t// Modification time\n\t\t\tfile_times[1].tv_sec = file_stats.st_mtime;\n\t\t\tfile_times[1].tv_usec = 0;\n\n\t\t\tret = futimes(outhandle, file_times);\n\n\t\t\tif (!keep)\n\t\t\t\tunlink(filenames[i].c_str());\n\t\t}\n\n\t\tif (verbosity > 0) {\n\t\t\tif (stdoutput) {\n\t\t\t\tcerr << filenames[i] << \":\\t \";\n\t\t\t\tcerr << \"decoded succesfully\"\n\t\t\t\t\t<< endl;\n\t\t\t}\n\n\t\t\telse {\n\t\t\t\tchar buf[10] = { 0 };\n\n\t\t\t\tif (program_mode == PM_DECOMPRESS)\n\t\t\t\t\tsnprintf(buf, 10, \"%.2f%%\",\n\t\t\t\t\t\t\t(1 - get_ratio(outhandle, inhandle)) * 100);\n\t\t\t\tif (program_mode == PM_COMPRESS)\n\t\t\t\t\tsnprintf(buf, 10, \"%.2f%%\",\n\t\t\t\t\t\t\t(1 - get_ratio(inhandle, outhandle)) * 100);\n\n\t\t\t\tstring ratio = buf;\n\t\t\t\tcerr << pretty_print_status(filenames[i], output_filename,\n\t\t\t\t\t\tratio)\n\t\t\t\t\t<< endl;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (warning)\n\t\treturn STATUS_WARNING;\n\n\treturn STATUS_OK;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\nLIBS = $(LIBS) user32.lib\nCFLAGS = $(CFLAGS) \\\n  -DCOMPRESS_MF_MT \\\n  -DBENCH_MT \\\n\nLZMA_OBJS = \\\n  $O\\LzmaAlone.obj \\\n  $O\\LzmaBench.obj \\\n  $O\\LzmaBenchCon.obj \\\n\nLZMA_OPT_OBJS = \\\n  $O\\LzmaDecoder.obj \\\n  $O\\LzmaEncoder.obj \\\n\nCOMMON_OBJS = \\\n  $O\\CommandLineParser.obj \\\n  $O\\CRC.obj \\\n  $O\\IntToString.obj \\\n  $O\\MyString.obj \\\n  $O\\StringConvert.obj \\\n  $O\\StringToInt.obj \\\n  $O\\MyVector.obj\n\nWIN_OBJS = \\\n  $O\\System.obj\n\n7ZIP_COMMON_OBJS = \\\n  $O\\InBuffer.obj \\\n  $O\\OutBuffer.obj \\\n  $O\\StreamUtils.obj \\\n\nC_OBJS = \\\n  $O\\7zCrc.obj \\\n  $O\\Alloc.obj \\\n  $O\\Bra86.obj \\\n  $O\\LzFind.obj \\\n  $O\\LzFindMt.obj \\\n  $O\\LzmaDec.obj \\\n  $O\\LzmaEnc.obj \\\n  $O\\Threads.obj \\\n\nC_LZMAUTIL_OBJS = \\\n  $O\\Lzma86Dec.obj \\\n  $O\\Lzma86Enc.obj \\\n\nOBJS = \\\n  $O\\StdAfx.obj \\\n  $(LZMA_OBJS) \\\n  $(LZMA_OPT_OBJS) \\\n  $(COMMON_OBJS) \\\n  $(WIN_OBJS) \\\n  $(7ZIP_COMMON_OBJS) \\\n  $(C_OBJS) \\\n  $(C_LZMAUTIL_OBJS) \\\n  $O\\FileStreams.obj \\\n  $O\\FileIO.obj \\\n\n!include \"../../../Build.mak\"\n\n\n$(LZMA_OBJS): $(*B).cpp\n\t$(COMPL)\n$(LZMA_OPT_OBJS): ../$(*B).cpp\n\t$(COMPL_O2)\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\n\t$(COMPL)\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\n\t$(COMPL)\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\n\t$(COMPL)\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\n\t$(COMPL)\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\n\t$(COMPL)\n$(C_OBJS): ../../../../C/$(*B).c\n\t$(COMPL_O2)\n$(C_LZMAUTIL_OBJS): ../../../../C/LzmaUtil/$(*B).c\n\t$(COMPL_O2)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma_alone\nPROG2 = lzma\nCXX = g++ -O2 -Wall\nCXX_C = gcc -O2 -Wall\nLIB = -lm\nRM = rm -f\nCFLAGS = -c -I ../../../ -D_FILE_OFFSET_BITS=64 -DPACKAGE_VERSION=\"\\\"4.32.0beta3\\\"\"\n\nifdef SystemDrive\nIS_MINGW = 1\nendif\n\nifdef IS_MINGW\nFILE_IO =FileIO\nFILE_IO_2 =Windows/$(FILE_IO)\nLIB2 = -luuid\nelse\nFILE_IO =C_FileIO\nFILE_IO_2 =Common/$(FILE_IO)\nendif\n\nOBJS = \\\n  LzmaAlone.o \\\n  LzmaBench.o \\\n  LzmaBenchCon.o \\\n  LzmaDecoder.o \\\n  LzmaEncoder.o \\\n  InBuffer.o \\\n  OutBuffer.o \\\n  FileStreams.o \\\n  StreamUtils.o \\\n  $(FILE_IO).o \\\n  CommandLineParser.o \\\n  CRC.o \\\n  IntToString.o \\\n  MyString.o \\\n  StringConvert.o \\\n  StringToInt.o \\\n  MyVector.o \\\n  7zCrc.o \\\n  Alloc.o \\\n  Bra86.o \\\n  LzFind.o \\\n  LzmaDec.o \\\n  LzmaEnc.o \\\n  Lzma86Dec.o \\\n  Lzma86Enc.o \\\n\nOBJS2 = \\\n\tC_FileIO.o \\\n\tCRC.o \\\n\tAlloc.o \\\n\tFileStreams.o \\\n\tStreamUtils.o \\\n\tInBuffer.o \\\n\tOutBuffer.o \\\n\tLzmaDecoder.o \\\n\tStringConvert.o \\\n\tStringToInt.o \\\n\tLzmaEncoder.o \\\n\tLzmaDec.o \\\n\tLzmaEnc.o \\\n\tLzFind.o \\\n\t7zCrc.o \\\n\tlzmp.o\n\nall: $(PROG) $(PROG2)\n\n$(PROG): $(OBJS)\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)\n\n$(PROG2): $(OBJS2)\n\t$(CXX) -o $(PROG2) $(LDFLAGS) $(OBJS2) $(LIB)\n\nlzmp.o: lzmp.cpp\n\t$(CXX) $(CFLAGS) lzmp.cpp\n\nLzmaAlone.o: LzmaAlone.cpp\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\n\nLzmaBench.o: LzmaBench.cpp\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\n\nLzmaBenchCon.o: LzmaBenchCon.cpp\n\t$(CXX) $(CFLAGS) LzmaBenchCon.cpp\n\nLzmaDecoder.o: ../LzmaDecoder.cpp\n\t$(CXX) $(CFLAGS) ../LzmaDecoder.cpp\n\nLzmaEncoder.o: ../LzmaEncoder.cpp\n\t$(CXX) $(CFLAGS) ../LzmaEncoder.cpp\n\nInBuffer.o: ../../Common/InBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\n\nOutBuffer.o: ../../Common/OutBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\n\nFileStreams.o: ../../Common/FileStreams.cpp\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\n\nStreamUtils.o: ../../Common/StreamUtils.cpp\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\n\n$(FILE_IO).o: ../../../$(FILE_IO_2).cpp\n\t$(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp\n\n\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\n\nCRC.o: ../../../Common/CRC.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\n\nMyWindows.o: ../../../Common/MyWindows.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\n\nIntToString.o: ../../../Common/IntToString.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp\n\nMyString.o: ../../../Common/MyString.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/MyString.cpp\n\nStringConvert.o: ../../../Common/StringConvert.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\n\nStringToInt.o: ../../../Common/StringToInt.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\n\nMyVector.o: ../../../Common/MyVector.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/MyVector.cpp\n\n7zCrc.o: ../../../../C/7zCrc.c\n\t$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c\n\nAlloc.o: ../../../../C/Alloc.c\n\t$(CXX_C) $(CFLAGS) ../../../../C/Alloc.c\n\nBra86.o: ../../../../C/Bra86.c\n\t$(CXX_C) $(CFLAGS) ../../../../C/Bra86.c\n\nLzFind.o: ../../../../C/LzFind.c\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzFind.c\n\nLzmaDec.o: ../../../../C/LzmaDec.c\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaDec.c\n\nLzmaEnc.o: ../../../../C/LzmaEnc.c\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaEnc.c\n\nLzma86Dec.o: ../../../../C/LzmaUtil/Lzma86Dec.c\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Dec.c\n\nLzma86Enc.o: ../../../../C/LzmaUtil/Lzma86Enc.c\n\t$(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c\n\nclean:\n\t-$(RM) $(PROG) $(PROG2) $(OBJS)\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LzmaDecoder.cpp",
    "content": "// LzmaDecoder.cpp\n\n#include \"StdAfx.h\"\n\nextern \"C\"\n{\n#include \"../../../C/Alloc.h\"\n}\n\n#include \"../Common/StreamUtils.h\"\n\n#include \"LzmaDecoder.h\"\n\nstatic HRESULT SResToHRESULT(SRes res)\n{\n  switch(res)\n  {\n    case SZ_OK: return S_OK;\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\n    case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;\n    // case SZ_ERROR_PROGRESS: return E_ABORT;\n    case SZ_ERROR_DATA: return S_FALSE;\n  }\n  return E_FAIL;\n}\n\nnamespace NCompress {\nnamespace NLzma {\n\nstatic const UInt32 kInBufSize = 1 << 20;\n\nCDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false), FinishStream(false)\n{\n  LzmaDec_Construct(&_state);\n}\n\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\nstatic void SzFree(void *p, void *address) { p = p; MyFree(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\nCDecoder::~CDecoder()\n{\n  LzmaDec_Free(&_state, &g_Alloc);\n  MyFree(_inBuf);\n}\n\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)\n{\n  RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc)));\n\n  if (_inBuf == 0)\n  {\n    _inBuf = (Byte *)MyAlloc(kInBufSize);\n    if (_inBuf == 0)\n      return E_OUTOFMEMORY;\n  }\n\n  return S_OK;\n}\n\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) { *value = _inSizeProcessed; return S_OK; }\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; }\nSTDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; }\n\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\n{\n  _outSizeDefined = (outSize != NULL);\n  if (_outSizeDefined)\n    _outSize = *outSize;\n\n  LzmaDec_Init(&_state);\n  \n  _inPos = _inSize = 0;\n  _inSizeProcessed = _outSizeProcessed = 0;\n  return S_OK;\n}\n\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\n    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)\n{\n  if (_inBuf == 0)\n    return S_FALSE;\n  SetOutStreamSize(outSize);\n\n  for (;;)\n  {\n    if (_inPos == _inSize)\n    {\n      _inPos = _inSize = 0;\n      RINOK(inStream->Read(_inBuf, kInBufSize, &_inSize));\n    }\n\n    SizeT dicPos = _state.dicPos;\n    SizeT curSize = _state.dicBufSize - dicPos;\n    const UInt32 kStepSize = ((UInt32)1 << 22);\n    if (curSize > kStepSize)\n      curSize = (SizeT)kStepSize;\n    \n    ELzmaFinishMode finishMode = LZMA_FINISH_ANY;\n    if (_outSizeDefined)\n    {\n      const UInt64 rem = _outSize - _outSizeProcessed;\n      if (rem < curSize)\n      {\n        curSize = (SizeT)rem;\n        if (FinishStream)\n          finishMode = LZMA_FINISH_END;\n      }\n    }\n\n    SizeT inSizeProcessed = _inSize - _inPos;\n    ELzmaStatus status;\n    SRes res = LzmaDec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status);\n\n    _inPos += (UInt32)inSizeProcessed;\n    _inSizeProcessed += inSizeProcessed;\n    SizeT outSizeProcessed = _state.dicPos - dicPos;\n    _outSizeProcessed += outSizeProcessed;\n\n    bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0);\n    bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize);\n\n    if (res != 0 || _state.dicPos == _state.dicBufSize || finished || stopDecoding)\n    {\n      HRESULT res2 = WriteStream(outStream, _state.dic, _state.dicPos);\n      if (res != 0)\n        return S_FALSE;\n      RINOK(res2);\n      if (stopDecoding)\n        return S_OK;\n      if (finished)\n        return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE);\n    }\n    if (_state.dicPos == _state.dicBufSize)\n      _state.dicPos = 0;\n\n    if (progress != NULL)\n    {\n      RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed));\n    }\n  }\n}\n\n#ifndef NO_READ_FROM_CODER\n\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  if (processedSize)\n    *processedSize = 0;\n  do\n  {\n    if (_inPos == _inSize)\n    {\n      _inPos = _inSize = 0;\n      RINOK(_inStream->Read(_inBuf, kInBufSize, &_inSize));\n    }\n    {\n      SizeT inProcessed = _inSize - _inPos;\n\n      if (_outSizeDefined)\n      {\n        const UInt64 rem = _outSize - _outSizeProcessed;\n        if (rem < size)\n          size = (UInt32)rem;\n      }\n\n      SizeT outProcessed = size;\n      ELzmaStatus status;\n      SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,\n          _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);\n      _inPos += (UInt32)inProcessed;\n      _inSizeProcessed += inProcessed;\n      _outSizeProcessed += outProcessed;\n      size -= (UInt32)outProcessed;\n      data = (Byte *)data + outProcessed;\n      if (processedSize)\n        *processedSize += (UInt32)outProcessed;\n      RINOK(SResToHRESULT(res));\n      if (inProcessed == 0 && outProcessed == 0)\n        return S_OK;\n    }\n  }\n  while (size != 0);\n  return S_OK;\n}\n\n#endif\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LzmaDecoder.h",
    "content": "// LzmaDecoder.h\n\n#ifndef __LZMA_DECODER_H\n#define __LZMA_DECODER_H\n\nextern \"C\"\n{\n#include \"../../../C/LzmaDec.h\"\n}\n\n#include \"../../Common/MyCom.h\"\n#include \"../ICoder.h\"\n\nnamespace NCompress {\nnamespace NLzma {\n\nclass CDecoder:\n  public ICompressCoder,\n  public ICompressSetDecoderProperties2,\n  public ICompressGetInStreamProcessedSize,\n  #ifndef NO_READ_FROM_CODER\n  public ICompressSetInStream,\n  public ICompressSetOutStreamSize,\n  public ISequentialInStream,\n  #endif\n  public CMyUnknownImp\n{\n  CMyComPtr<ISequentialInStream> _inStream;\n  Byte *_inBuf;\n  UInt32 _inPos;\n  UInt32 _inSize;\n  CLzmaDec _state;\n  bool _outSizeDefined;\n  UInt64 _outSize;\n  UInt64 _inSizeProcessed;\n  UInt64 _outSizeProcessed;\npublic:\n\n  #ifndef NO_READ_FROM_CODER\n  MY_UNKNOWN_IMP5(\n      ICompressSetDecoderProperties2,\n      ICompressGetInStreamProcessedSize,\n      ICompressSetInStream,\n      ICompressSetOutStreamSize,\n      ISequentialInStream)\n  #else\n  MY_UNKNOWN_IMP2(\n      ICompressSetDecoderProperties2,\n      ICompressGetInStreamProcessedSize)\n  #endif\n\n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\n  STDMETHOD(ReleaseInStream)();\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\n\n  #ifndef NO_READ_FROM_CODER\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  #endif\n\n  bool FinishStream;\n\n  CDecoder();\n  virtual ~CDecoder();\n\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LzmaEncoder.cpp",
    "content": "// LzmaEncoder.cpp\n\n#include \"StdAfx.h\"\n\nextern \"C\"\n{\n#include \"../../../C/Alloc.h\"\n}\n\n#include \"../Common/StreamUtils.h\"\n\n#include \"LzmaEncoder.h\"\n\nstatic HRESULT SResToHRESULT(SRes res)\n{\n  switch(res)\n  {\n    case SZ_OK: return S_OK;\n    case SZ_ERROR_MEM: return E_OUTOFMEMORY;\n    case SZ_ERROR_PARAM: return E_INVALIDARG;\n    // case SZ_ERROR_THREAD: return E_FAIL;\n  }\n  return E_FAIL;\n}\n\nnamespace NCompress {\nnamespace NLzma {\n\nstatic const UInt32 kStreamStepSize = (UInt32)1 << 31;\n\nstatic SRes MyRead(void *object, void *data, size_t *size)\n{\n  UInt32 curSize = ((*size < kStreamStepSize) ? (UInt32)*size : kStreamStepSize);\n  HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize);\n  *size = curSize;\n  return (SRes)res;\n}\n\nstatic size_t MyWrite(void *object, const void *data, size_t size)\n{\n  CSeqOutStream *p = (CSeqOutStream *)object;\n  p->Res = WriteStream(p->RealStream, data, size);\n  if (p->Res != 0)\n    return 0;\n  return size;\n}\n\nstatic void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }\nstatic void SzBigFree(void *, void *address) { BigFree(address); }\nstatic ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };\n\nstatic void *SzAlloc(void *, size_t size) { return MyAlloc(size); }\nstatic void SzFree(void *, void *address) { MyFree(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\nCEncoder::CEncoder()\n{\n  _seqInStream.SeqInStream.Read = MyRead;\n  _seqOutStream.SeqOutStream.Write = MyWrite;\n  _encoder = 0;\n  _encoder = LzmaEnc_Create(&g_Alloc);\n  if (_encoder == 0)\n    throw 1;\n}\n\nCEncoder::~CEncoder()\n{\n  if (_encoder != 0)\n    LzmaEnc_Destroy(_encoder, &g_Alloc, &g_BigAlloc);\n}\n\ninline wchar_t GetUpperChar(wchar_t c)\n{\n  if (c >= 'a' && c <= 'z')\n    c -= 0x20;\n  return c;\n}\n\nstatic int ParseMatchFinder(const wchar_t *s, int *btMode, int *numHashBytes)\n{\n  wchar_t c = GetUpperChar(*s++);\n  if (c == L'H')\n  {\n    if (GetUpperChar(*s++) != L'C')\n      return 0;\n    int numHashBytesLoc = (int)(*s++ - L'0');\n    if (numHashBytesLoc < 4 || numHashBytesLoc > 4)\n      return 0;\n    if (*s++ != 0)\n      return 0;\n    *btMode = 0;\n    *numHashBytes = numHashBytesLoc;\n    return 1;\n  }\n  if (c != L'B')\n    return 0;\n\n  if (GetUpperChar(*s++) != L'T')\n    return 0;\n  int numHashBytesLoc = (int)(*s++ - L'0');\n  if (numHashBytesLoc < 2 || numHashBytesLoc > 4)\n    return 0;\n  c = GetUpperChar(*s++);\n  if (c != L'\\0')\n    return 0;\n  *btMode = 1;\n  *numHashBytes = numHashBytesLoc;\n  return 1;\n}\n\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,\n    const PROPVARIANT *coderProps, UInt32 numProps)\n{\n  CLzmaEncProps props;\n  LzmaEncProps_Init(&props);\n\n  for (UInt32 i = 0; i < numProps; i++)\n  {\n    const PROPVARIANT &prop = coderProps[i];\n    switch (propIDs[i])\n    {\n      case NCoderPropID::kNumFastBytes:\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.fb = prop.ulVal; break;\n      case NCoderPropID::kMatchFinderCycles:\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.mc = prop.ulVal; break;\n      case NCoderPropID::kAlgorithm:\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.algo = prop.ulVal; break;\n      case NCoderPropID::kDictionarySize:\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.dictSize = prop.ulVal; break;\n      case NCoderPropID::kPosStateBits:\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.pb = prop.ulVal; break;\n      case NCoderPropID::kLitPosBits:\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lp = prop.ulVal; break;\n      case NCoderPropID::kLitContextBits:\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.lc = prop.ulVal; break;\n      case NCoderPropID::kNumThreads:\n        if (prop.vt != VT_UI4) return E_INVALIDARG; props.numThreads = prop.ulVal; break;\n      case NCoderPropID::kMultiThread:\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.numThreads = ((prop.boolVal == VARIANT_TRUE) ? 2 : 1); break;\n      case NCoderPropID::kEndMarker:\n        if (prop.vt != VT_BOOL) return E_INVALIDARG; props.writeEndMark = (prop.boolVal == VARIANT_TRUE); break;\n      case NCoderPropID::kMatchFinder:\n        if (prop.vt != VT_BSTR) return E_INVALIDARG;\n        if (!ParseMatchFinder(prop.bstrVal, &props.btMode, &props.numHashBytes /* , &_matchFinderBase.skipModeBits */))\n          return E_INVALIDARG; break;\n      default:\n        return E_INVALIDARG;\n    }\n  }\n  return SResToHRESULT(LzmaEnc_SetProps(_encoder, &props));\n}\n\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\n{\n  Byte props[LZMA_PROPS_SIZE];\n  size_t size = LZMA_PROPS_SIZE;\n  RINOK(LzmaEnc_WriteProperties(_encoder, props, &size));\n  return WriteStream(outStream, props, size);\n}\n\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\n{\n  _seqOutStream.RealStream = outStream;\n  _seqOutStream.Res = S_OK;\n  return S_OK;\n}\n\nSTDMETHODIMP CEncoder::ReleaseOutStream()\n{\n  _seqOutStream.RealStream.Release();\n  return S_OK;\n}\n\ntypedef struct _CCompressProgressImp\n{\n  ICompressProgress p;\n  ICompressProgressInfo *Progress;\n  HRESULT Res;\n} CCompressProgressImp;\n\n#define PROGRESS_UNKNOWN_VALUE ((UInt64)(Int64)-1)\n\n#define CONVERT_PR_VAL(x) (x == PROGRESS_UNKNOWN_VALUE ? NULL : &x)\n\nSRes CompressProgress(void *pp, UInt64 inSize, UInt64 outSize)\n{\n  CCompressProgressImp *p = (CCompressProgressImp *)pp;\n  p->Res = p->Progress->SetRatioInfo(CONVERT_PR_VAL(inSize), CONVERT_PR_VAL(outSize));\n  return (SRes)p->Res;\n}\n\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,\n    const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)\n{\n  CCompressProgressImp progressImp;\n  progressImp.p.Progress = CompressProgress;\n  progressImp.Progress = progress;\n  progressImp.Res = SZ_OK;\n\n  _seqInStream.RealStream = inStream;\n  SetOutStream(outStream);\n  SRes res = LzmaEnc_Encode(_encoder, &_seqOutStream.SeqOutStream, &_seqInStream.SeqInStream, progress ? &progressImp.p : NULL, &g_Alloc, &g_BigAlloc);\n  ReleaseOutStream();\n  if (res == SZ_ERROR_WRITE && _seqOutStream.Res != S_OK)\n    return _seqOutStream.Res;\n  if (res == SZ_ERROR_PROGRESS && progressImp.Res != S_OK)\n    return progressImp.Res;\n  return SResToHRESULT(res);\n}\n  \n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LzmaEncoder.h",
    "content": "// LzmaEncoder.h\n\n#ifndef __LZMA_ENCODER_H\n#define __LZMA_ENCODER_H\n\nextern \"C\"\n{\n#include \"../../../C/LzmaEnc.h\"\n}\n\n#include \"../../Common/MyCom.h\"\n\n#include \"../ICoder.h\"\n\nnamespace NCompress {\nnamespace NLzma {\n\nstruct CSeqInStream\n{\n  ISeqInStream SeqInStream;\n  ISequentialInStream *RealStream;\n};\n\nstruct CSeqOutStream\n{\n  ISeqOutStream SeqOutStream;\n  CMyComPtr<ISequentialOutStream> RealStream;\n  HRESULT Res;\n};\n\nclass CEncoder :\n  public ICompressCoder,\n  public ICompressSetOutStream,\n  public ICompressSetCoderProperties,\n  public ICompressWriteCoderProperties,\n  public CMyUnknownImp\n{\n  CLzmaEncHandle _encoder;\n \n  CSeqInStream _seqInStream;\n  CSeqOutStream _seqOutStream;\n\npublic:\n  CEncoder();\n\n  MY_UNKNOWN_IMP3(\n      ICompressSetOutStream,\n      ICompressSetCoderProperties,\n      ICompressWriteCoderProperties\n      )\n    \n  STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,\n      const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\n  STDMETHOD(ReleaseOutStream)();\n\n  virtual ~CEncoder();\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/LzmaRegister.cpp",
    "content": "// LzmaRegister.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../Common/RegisterCodec.h\"\n\n#include \"LzmaDecoder.h\"\n\nstatic void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CDecoder); }\n#ifndef EXTRACT_ONLY\n#include \"LzmaEncoder.h\"\nstatic void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CEncoder);  }\n#else\n#define CreateCodecOut 0\n#endif\n\nstatic CCodecInfo g_CodecInfo =\n  { CreateCodec, CreateCodecOut, 0x030101, L\"LZMA\", 1, false };\n\nREGISTER_CODEC(LZMA)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/RangeCoder.h",
    "content": "// Compress/RangeCoder.h\n\n#ifndef __COMPRESS_RANGE_CODER_H\n#define __COMPRESS_RANGE_CODER_H\n\n#include \"../Common/InBuffer.h\"\n#include \"../Common/OutBuffer.h\"\n\nnamespace NCompress {\nnamespace NRangeCoder {\n\nconst int kNumTopBits = 24;\nconst UInt32 kTopValue = (1 << kNumTopBits);\n\nclass CEncoder\n{\n  UInt32 _cacheSize;\n  Byte _cache;\npublic:\n  UInt64 Low;\n  UInt32 Range;\n  COutBuffer Stream;\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\n\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\n  void Init()\n  {\n    Stream.Init();\n    Low = 0;\n    Range = 0xFFFFFFFF;\n    _cacheSize = 1;\n    _cache = 0;\n  }\n\n  void FlushData()\n  {\n    // Low += 1;\n    for(int i = 0; i < 5; i++)\n      ShiftLow();\n  }\n\n  HRESULT FlushStream() { return Stream.Flush();  }\n\n  void ReleaseStream() { Stream.ReleaseStream(); }\n\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\n  {\n    Low += start * (Range /= total);\n    Range *= size;\n    while (Range < kTopValue)\n    {\n      Range <<= 8;\n      ShiftLow();\n    }\n  }\n\n  void ShiftLow()\n  {\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)\n    {\n      Byte temp = _cache;\n      do\n      {\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\n        temp = 0xFF;\n      }\n      while(--_cacheSize != 0);\n      _cache = (Byte)((UInt32)Low >> 24);\n    }\n    _cacheSize++;\n    Low = (UInt32)Low << 8;\n  }\n  \n  void EncodeDirectBits(UInt32 value, int numBits)\n  {\n    for (numBits--; numBits >= 0; numBits--)\n    {\n      Range >>= 1;\n      Low += Range & (0 - ((value >> numBits) & 1));\n      if (Range < kTopValue)\n      {\n        Range <<= 8;\n        ShiftLow();\n      }\n    }\n  }\n\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\n  {\n    UInt32 newBound = (Range >> numTotalBits) * size0;\n    if (symbol == 0)\n      Range = newBound;\n    else\n    {\n      Low += newBound;\n      Range -= newBound;\n    }\n    while (Range < kTopValue)\n    {\n      Range <<= 8;\n      ShiftLow();\n    }\n  }\n\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\n};\n\nclass CDecoder\n{\npublic:\n  CInBuffer Stream;\n  UInt32 Range;\n  UInt32 Code;\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\n\n  void Normalize()\n  {\n    while (Range < kTopValue)\n    {\n      Code = (Code << 8) | Stream.ReadByte();\n      Range <<= 8;\n    }\n  }\n  \n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\n  void Init()\n  {\n    Stream.Init();\n    Code = 0;\n    Range = 0xFFFFFFFF;\n    for(int i = 0; i < 5; i++)\n      Code = (Code << 8) | Stream.ReadByte();\n  }\n\n  void ReleaseStream() { Stream.ReleaseStream(); }\n\n  UInt32 GetThreshold(UInt32 total)\n  {\n    return (Code) / ( Range /= total);\n  }\n\n  void Decode(UInt32 start, UInt32 size)\n  {\n    Code -= start * Range;\n    Range *= size;\n    Normalize();\n  }\n\n  UInt32 DecodeDirectBits(int numTotalBits)\n  {\n    UInt32 range = Range;\n    UInt32 code = Code;\n    UInt32 result = 0;\n    for (int i = numTotalBits; i != 0; i--)\n    {\n      range >>= 1;\n      /*\n      result <<= 1;\n      if (code >= range)\n      {\n        code -= range;\n        result |= 1;\n      }\n      */\n      UInt32 t = (code - range) >> 31;\n      code -= range & (t - 1);\n      result = (result << 1) | (1 - t);\n\n      if (range < kTopValue)\n      {\n        code = (code << 8) | Stream.ReadByte();\n        range <<= 8;\n      }\n    }\n    Range = range;\n    Code = code;\n    return result;\n  }\n\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\n  {\n    UInt32 newBound = (Range >> numTotalBits) * size0;\n    UInt32 symbol;\n    if (Code < newBound)\n    {\n      symbol = 0;\n      Range = newBound;\n    }\n    else\n    {\n      symbol = 1;\n      Code -= newBound;\n      Range -= newBound;\n    }\n    Normalize();\n    return symbol;\n  }\n\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/RangeCoderBit.h",
    "content": "// Compress/RangeCoderBit.h\n\n#ifndef __COMPRESS_RANGE_CODER_BIT_H\n#define __COMPRESS_RANGE_CODER_BIT_H\n\n#include \"RangeCoder.h\"\n\nnamespace NCompress {\nnamespace NRangeCoder {\n\nconst int kNumBitModelTotalBits  = 11;\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\n\nconst int kNumMoveReducingBits = 4;\n\nconst int kNumBitPriceShiftBits = 4;\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\n\nextern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\n\ntemplate <int numMoveBits>\nclass CBitModel\n{\npublic:\n  UInt32 Prob;\n  void UpdateModel(UInt32 symbol)\n  {\n    /*\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\n    */\n    if (symbol == 0)\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\n    else\n      Prob -= (Prob) >> numMoveBits;\n  }\npublic:\n  void Init() { Prob = kBitModelTotal / 2; }\n};\n\ntemplate <int numMoveBits>\nclass CBitEncoder: public CBitModel<numMoveBits>\n{\npublic:\n  void Encode(CEncoder *encoder, UInt32 symbol)\n  {\n    /*\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\n    this->UpdateModel(symbol);\n    */\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\n    if (symbol == 0)\n    {\n      encoder->Range = newBound;\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\n    }\n    else\n    {\n      encoder->Low += newBound;\n      encoder->Range -= newBound;\n      this->Prob -= (this->Prob) >> numMoveBits;\n    }\n    if (encoder->Range < kTopValue)\n    {\n      encoder->Range <<= 8;\n      encoder->ShiftLow();\n    }\n  }\n  UInt32 GetPrice(UInt32 symbol) const\n  {\n    return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\n  }\n  UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; }\n  UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; }\n};\n\n\ntemplate <int numMoveBits>\nclass CBitDecoder: public CBitModel<numMoveBits>\n{\npublic:\n  UInt32 Decode(CDecoder *decoder)\n  {\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\n    if (decoder->Code < newBound)\n    {\n      decoder->Range = newBound;\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\n      if (decoder->Range < kTopValue)\n      {\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\n        decoder->Range <<= 8;\n      }\n      return 0;\n    }\n    else\n    {\n      decoder->Range -= newBound;\n      decoder->Code -= newBound;\n      this->Prob -= (this->Prob) >> numMoveBits;\n      if (decoder->Range < kTopValue)\n      {\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\n        decoder->Range <<= 8;\n      }\n      return 1;\n    }\n  }\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/Compress/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../Common/MyWindows.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/ICoder.h",
    "content": "// ICoder.h\n\n#ifndef __ICODER_H\n#define __ICODER_H\n\n#include \"IStream.h\"\n\n#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)\n\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\n{\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\n};\n\nCODER_INTERFACE(ICompressCoder, 0x05)\n{\n  STDMETHOD(Code)(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream,\n      const UInt64 *inSize,\n      const UInt64 *outSize,\n      ICompressProgressInfo *progress) PURE;\n};\n\nCODER_INTERFACE(ICompressCoder2, 0x18)\n{\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress) PURE;\n};\n\nnamespace NCoderPropID\n{\n  enum EEnum\n  {\n    kDictionarySize = 0x400,\n    kUsedMemorySize,\n    kOrder,\n    kBlockSize,\n    kPosStateBits = 0x440,\n    kLitContextBits,\n    kLitPosBits,\n    kNumFastBytes = 0x450,\n    kMatchFinder,\n    kMatchFinderCycles,\n    kNumPasses = 0x460,\n    kAlgorithm = 0x470,\n    kMultiThread = 0x480,\n    kNumThreads,\n    kEndMarker = 0x490\n  };\n}\n\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\n{\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\n};\n\n/*\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\n{\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\n};\n*/\n\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\n{\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\n};\n\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\n{\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\n};\n\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\n{\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\n};\n\nCODER_INTERFACE(ICompressSetCoderMt, 0x25)\n{\n  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\n};\n\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\n{\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\n};\n\nCODER_INTERFACE(ICompressSetInStream, 0x31)\n{\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\n  STDMETHOD(ReleaseInStream)() PURE;\n};\n\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\n{\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\n  STDMETHOD(ReleaseOutStream)() PURE;\n};\n\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\n{\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\n};\n\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\n{\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\n};\n\nCODER_INTERFACE(ICompressFilter, 0x40)\n{\n  STDMETHOD(Init)() PURE;\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\n  // Filter return outSize (UInt32)\n  // if (outSize <= size): Filter have converted outSize bytes\n  // if (outSize > size): Filter have not converted anything.\n  //      and it needs at least outSize bytes to convert one block\n  //      (it's for crypto block algorithms).\n};\n\nCODER_INTERFACE(ICompressCodecsInfo, 0x60)\n{\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;\n};\nCODER_INTERFACE(ISetCompressCodecsInfo, 0x61)\n{\n  STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;\n};\n\nCODER_INTERFACE(ICryptoProperties, 0x80)\n{\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\n};\n\n/*\nCODER_INTERFACE(ICryptoResetSalt, 0x88)\n{\n  STDMETHOD(ResetSalt)() PURE;\n};\n*/\n\nCODER_INTERFACE(ICryptoResetInitVector, 0x8C)\n{\n  STDMETHOD(ResetInitVector)() PURE;\n};\n\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\n{\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\n};\n\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\n{\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\n};\n\n//////////////////////\n// It's for DLL file\nnamespace NMethodPropID\n{\n  enum EEnum\n  {\n    kID,\n    kName,\n    kDecoder,\n    kEncoder,\n    kInStreams,\n    kOutStreams,\n    kDescription,\n    kDecoderIsAssigned,\n    kEncoderIsAssigned\n  };\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/IDecl.h",
    "content": "// IDecl.h\n\n#ifndef __IDECL_H\n#define __IDECL_H\n\n#include \"../Common/MyUnknown.h\"\n\n#define DECL_INTERFACE_SUB(i, base, groupId, subId) \\\nDEFINE_GUID(IID_ ## i, \\\n0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \\\nstruct i: public base\n\n#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/IPassword.h",
    "content": "// IPassword.h\n\n#ifndef __IPASSWORD_H\n#define __IPASSWORD_H\n\n#include \"../Common/MyUnknown.h\"\n#include \"../Common/Types.h\"\n\n#include \"IDecl.h\"\n\n#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)\n\nPASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)\n{\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;\n};\n\nPASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)\n{\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;\n};\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/IProgress.h",
    "content": "// Interface/IProgress.h\n\n#ifndef __IPROGRESS_H\n#define __IPROGRESS_H\n\n#include \"../Common/MyUnknown.h\"\n#include \"../Common/Types.h\"\n\n#include \"IDecl.h\"\n\n#define INTERFACE_IProgress(x) \\\n  STDMETHOD(SetTotal)(UInt64 total) x; \\\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) x; \\\n\nDECL_INTERFACE(IProgress, 0, 5)\n{\n  INTERFACE_IProgress(PURE)\n};\n\n/*\n// {23170F69-40C1-278A-0000-000000050002}\nDEFINE_GUID(IID_IProgress2,\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000050002\")\nIProgress2: public IUnknown\n{\npublic:\n  STDMETHOD(SetTotal)(const UInt64 *total) PURE;\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;\n};\n*/\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/IStream.h",
    "content": "// IStream.h\n\n#ifndef __ISTREAM_H\n#define __ISTREAM_H\n\n#include \"../Common/MyUnknown.h\"\n#include \"../Common/Types.h\"\n\n#include \"IDecl.h\"\n\n#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\n\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\n{\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\n  /*\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\n    then there are no more bytes in stream.\n  if (size > 0) && there are bytes in stream,\n  this function must read at least 1 byte.\n  This function is allowed to read less than number of remaining bytes in stream.\n  You must call Read function in loop, if you need exact amount of data\n  */\n};\n\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\n{\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\n  /*\n  if (size > 0) this function must write at least 1 byte.\n  This function is allowed to write less than \"size\".\n  You must call Write function in loop, if you need to write exact amount of data\n  */\n};\n\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\n{\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\n};\n\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\n{\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\n};\n\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\n{\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\n};\n\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\n{\n  STDMETHOD(Flush)() PURE;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/MyVersion.h",
    "content": "#define MY_VER_MAJOR 4\n#define MY_VER_MINOR 65\n#define MY_VER_BUILD 0\n#define MY_VERSION \"4.65\"\n#define MY_7ZIP_VERSION \"7-Zip 4.65\"\n#define MY_DATE \"2009-02-03\"\n#define MY_COPYRIGHT \"Copyright (c) 1999-2009 Igor Pavlov\"\n#define MY_VERSION_COPYRIGHT_DATE MY_VERSION \"  \" MY_COPYRIGHT \"  \" MY_DATE\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/MyVersionInfo.rc",
    "content": "#include <WinVer.h>\n#include \"MyVersion.h\"\n\n#define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0\n\n#ifdef DEBUG\n#define DBG_FL VS_FF_DEBUG\n#else\n#define DBG_FL 0\n#endif\n\n#define MY_VERSION_INFO(fileType, descr, intName, origName)  \\\nLANGUAGE 9, 1 \\\n1 VERSIONINFO \\\n  FILEVERSION MY_VER \\\n  PRODUCTVERSION MY_VER \\\n  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK \\\n  FILEFLAGS DBG_FL \\\n  FILEOS VOS_NT_WINDOWS32 \\\n  FILETYPE fileType \\\n  FILESUBTYPE 0x0L \\\nBEGIN \\\n    BLOCK \"StringFileInfo\" \\\n    BEGIN  \\\n        BLOCK \"040904b0\" \\\n        BEGIN \\\n            VALUE \"CompanyName\", \"Igor Pavlov\" \\\n            VALUE \"FileDescription\", descr \\\n            VALUE \"FileVersion\", MY_VERSION  \\\n            VALUE \"InternalName\", intName \\\n            VALUE \"LegalCopyright\", MY_COPYRIGHT \\\n            VALUE \"OriginalFilename\", origName \\\n            VALUE \"ProductName\", \"7-Zip\" \\\n            VALUE \"ProductVersion\", MY_VERSION \\\n        END \\\n    END \\\n    BLOCK \"VarFileInfo\" \\\n    BEGIN \\\n        VALUE \"Translation\", 0x409, 1200 \\\n    END \\\nEND\n\n#define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(VFT_APP, descr, intName, intName \".exe\")\n\n#define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(VFT_DLL, descr, intName, intName \".dll\")\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/PropID.h",
    "content": "// PropID.h\n\n#ifndef __7ZIP_PROPID_H\n#define __7ZIP_PROPID_H\n\nenum\n{\n  kpidNoProperty = 0,\n  \n  kpidHandlerItemIndex = 2,\n  kpidPath,\n  kpidName,\n  kpidExtension,\n  kpidIsDir,\n  kpidSize,\n  kpidPackSize,\n  kpidAttrib,\n  kpidCTime,\n  kpidATime,\n  kpidMTime,\n  kpidSolid,\n  kpidCommented,\n  kpidEncrypted,\n  kpidSplitBefore,\n  kpidSplitAfter,\n  kpidDictionarySize,\n  kpidCRC,\n  kpidType,\n  kpidIsAnti,\n  kpidMethod,\n  kpidHostOS,\n  kpidFileSystem,\n  kpidUser,\n  kpidGroup,\n  kpidBlock,\n  kpidComment,\n  kpidPosition,\n  kpidPrefix,\n  kpidNumSubDirs,\n  kpidNumSubFiles,\n  kpidUnpackVer,\n  kpidVolume,\n  kpidIsVolume,\n  kpidOffset,\n  kpidLinks,\n  kpidNumBlocks,\n  kpidNumVolumes,\n  kpidTimeType,\n  kpidBit64,\n  kpidBigEndian,\n  kpidCpu,\n  kpidPhySize,\n  kpidHeadersSize,\n  kpidChecksum,\n  kpidCharacts,\n  kpidVa,\n\n  kpidTotalSize = 0x1100,\n  kpidFreeSpace,\n  kpidClusterSize,\n  kpidVolumeName,\n\n  kpidLocalName = 0x1200,\n  kpidProvider,\n\n  kpidUserDefined = 0x10000\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Client7z/Client7z.cpp",
    "content": "// Client7z.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Common/IntToString.h\"\n#include \"Common/MyInitGuid.h\"\n#include \"Common/StringConvert.h\"\n\n#include \"Windows/DLL.h\"\n#include \"Windows/FileDir.h\"\n#include \"Windows/FileFind.h\"\n#include \"Windows/FileName.h\"\n#include \"Windows/PropVariant.h\"\n#include \"Windows/PropVariantConversions.h\"\n\n#include \"../../Common/FileStreams.h\"\n\n#include \"../../Archive/IArchive.h\"\n\n#include \"../../IPassword.h\"\n#include \"../../MyVersion.h\"\n\n// use another CLSIDs, if you want to support other formats (zip, rar, ...).\n// {23170F69-40C1-278A-1000-000110070000}\nDEFINE_GUID(CLSID_CFormat7z,\n  0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);\n\nusing namespace NWindows;\n\n#define kDllName \"7z.dll\"\n\nstatic const char *kCopyrightString = MY_7ZIP_VERSION\n\" (\"  kDllName \" client) \"\nMY_COPYRIGHT \" \" MY_DATE;\n\nstatic const char *kHelpString =\n\"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\\n\"\n\"Examples:\\n\"\n\"  Client7z.exe a archive.7z f1.txt f2.txt  : compress two files to archive.7z\\n\"\n\"  Client7z.exe l archive.7z   : List contents of archive.7z\\n\"\n\"  Client7z.exe x archive.7z   : eXtract files from archive.7z\\n\";\n\n\ntypedef UINT32 (WINAPI * CreateObjectFunc)(\n    const GUID *clsID,\n    const GUID *interfaceID,\n    void **outObject);\n\n#ifdef _WIN32\n#ifndef _UNICODE\nbool g_IsNT = false;\nstatic inline bool IsItWindowsNT()\n{\n  OSVERSIONINFO versionInfo;\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\n  if (!::GetVersionEx(&versionInfo))\n    return false;\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\n}\n#endif\n#endif\n\nvoid PrintString(const UString &s)\n{\n  printf(\"%s\", (LPCSTR)GetOemString(s));\n}\n\nvoid PrintString(const AString &s)\n{\n  printf(\"%s\", (LPCSTR)s);\n}\n\nvoid PrintNewLine()\n{\n  PrintString(\"\\n\");\n}\n\nvoid PrintStringLn(const AString &s)\n{\n  PrintString(s);\n  PrintNewLine();\n}\n\nvoid PrintError(const AString &s)\n{\n  PrintNewLine();\n  PrintString(s);\n  PrintNewLine();\n}\n\nstatic HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\n{\n  NCOM::CPropVariant prop;\n  RINOK(archive->GetProperty(index, propID, &prop));\n  if (prop.vt == VT_BOOL)\n    result = VARIANT_BOOLToBool(prop.boolVal);\n  else if (prop.vt == VT_EMPTY)\n    result = false;\n  else\n    return E_FAIL;\n  return S_OK;\n}\n\nstatic HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\n{\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\n}\n\n\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\n\n\n//////////////////////////////////////////////////////////////\n// Archive Open callback class\n\n\nclass CArchiveOpenCallback:\n  public IArchiveOpenCallback,\n  public ICryptoGetTextPassword,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\n\n  STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);\n  STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);\n\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\n\n  bool PasswordIsDefined;\n  UString Password;\n\n  CArchiveOpenCallback() : PasswordIsDefined(false) {}\n};\n\nSTDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)\n{\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)\n{\n  return S_OK;\n}\n  \nSTDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)\n{\n  if (!PasswordIsDefined)\n  {\n    // You can ask real password here from user\n    // Password = GetPassword(OutStream);\n    // PasswordIsDefined = true;\n    PrintError(\"Password is not defined\");\n    return E_ABORT;\n  }\n  return StringToBstr(Password, password);\n}\n\n\n//////////////////////////////////////////////////////////////\n// Archive Extracting callback class\n\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\n\nstatic const char *kTestingString    =  \"Testing     \";\nstatic const char *kExtractingString =  \"Extracting  \";\nstatic const char *kSkippingString   =  \"Skipping    \";\n\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\nstatic const char *kCRCFailed = \"CRC Failed\";\nstatic const char *kDataError = \"Data Error\";\nstatic const char *kUnknownError = \"Unknown Error\";\n\nclass CArchiveExtractCallback:\n  public IArchiveExtractCallback,\n  public ICryptoGetTextPassword,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP1(ICryptoGetTextPassword)\n\n  // IProgress\n  STDMETHOD(SetTotal)(UInt64 size);\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\n\n  // IArchiveExtractCallback\n  STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);\n  STDMETHOD(PrepareOperation)(Int32 askExtractMode);\n  STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);\n\n  // ICryptoGetTextPassword\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\n\nprivate:\n  CMyComPtr<IInArchive> _archiveHandler;\n  UString _directoryPath;  // Output directory\n  UString _filePath;       // name inside arcvhive\n  UString _diskFilePath;   // full path to file on disk\n  bool _extractMode;\n  struct CProcessedFileInfo\n  {\n    FILETIME MTime;\n    UInt32 Attrib;\n    bool isDir;\n    bool AttribDefined;\n    bool MTimeDefined;\n  } _processedFileInfo;\n\n  COutFileStream *_outFileStreamSpec;\n  CMyComPtr<ISequentialOutStream> _outFileStream;\n\npublic:\n  void Init(IInArchive *archiveHandler, const UString &directoryPath);\n\n  UInt64 NumErrors;\n  bool PasswordIsDefined;\n  UString Password;\n\n  CArchiveExtractCallback() : PasswordIsDefined(false) {}\n};\n\nvoid CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)\n{\n  NumErrors = 0;\n  _archiveHandler = archiveHandler;\n  _directoryPath = directoryPath;\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\n}\n\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)\n{\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)\n{\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,\n    ISequentialOutStream **outStream, Int32 askExtractMode)\n{\n  *outStream = 0;\n  _outFileStream.Release();\n\n  {\n    // Get Name\n    NCOM::CPropVariant prop;\n    RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));\n    \n    UString fullPath;\n    if (prop.vt == VT_EMPTY)\n      fullPath = kEmptyFileAlias;\n    else\n    {\n      if (prop.vt != VT_BSTR)\n        return E_FAIL;\n      fullPath = prop.bstrVal;\n    }\n    _filePath = fullPath;\n  }\n\n  if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)\n    return S_OK;\n\n  {\n    // Get Attrib\n    NCOM::CPropVariant prop;\n    RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\n    if (prop.vt == VT_EMPTY)\n    {\n      _processedFileInfo.Attrib = 0;\n      _processedFileInfo.AttribDefined = false;\n    }\n    else\n    {\n      if (prop.vt != VT_UI4)\n        return E_FAIL;\n      _processedFileInfo.Attrib = prop.ulVal;\n      _processedFileInfo.AttribDefined = true;\n    }\n  }\n\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir));\n\n  {\n    // Get Modified Time\n    NCOM::CPropVariant prop;\n    RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));\n    _processedFileInfo.MTimeDefined = false;\n    switch(prop.vt)\n    {\n      case VT_EMPTY:\n        // _processedFileInfo.MTime = _utcMTimeDefault;\n        break;\n      case VT_FILETIME:\n        _processedFileInfo.MTime = prop.filetime;\n        _processedFileInfo.MTimeDefined = true;\n        break;\n      default:\n        return E_FAIL;\n    }\n\n  }\n  {\n    // Get Size\n    NCOM::CPropVariant prop;\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\n    bool newFileSizeDefined = (prop.vt != VT_EMPTY);\n    UInt64 newFileSize;\n    if (newFileSizeDefined)\n      newFileSize = ConvertPropVariantToUInt64(prop);\n  }\n\n  \n  {\n    // Create folders for file\n    int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);\n    if (slashPos >= 0)\n      NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));\n  }\n\n  UString fullProcessedPath = _directoryPath + _filePath;\n  _diskFilePath = fullProcessedPath;\n\n  if (_processedFileInfo.isDir)\n  {\n    NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);\n  }\n  else\n  {\n    NFile::NFind::CFileInfoW fi;\n    if (NFile::NFind::FindFile(fullProcessedPath, fi))\n    {\n      if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\n      {\n        PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath);\n        return E_ABORT;\n      }\n    }\n    \n    _outFileStreamSpec = new COutFileStream;\n    CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\n    if (!_outFileStreamSpec->Open(fullProcessedPath, CREATE_ALWAYS))\n    {\n      PrintString((UString)L\"can not open output file \" + fullProcessedPath);\n      return E_ABORT;\n    }\n    _outFileStream = outStreamLoc;\n    *outStream = outStreamLoc.Detach();\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\n{\n  _extractMode = false;\n  switch (askExtractMode)\n  {\n    case NArchive::NExtract::NAskMode::kExtract:  _extractMode = true; break;\n  };\n  switch (askExtractMode)\n  {\n    case NArchive::NExtract::NAskMode::kExtract:  PrintString(kExtractingString); break;\n    case NArchive::NExtract::NAskMode::kTest:  PrintString(kTestingString); break;\n    case NArchive::NExtract::NAskMode::kSkip:  PrintString(kSkippingString); break;\n  };\n  PrintString(_filePath);\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\n{\n  switch(operationResult)\n  {\n    case NArchive::NExtract::NOperationResult::kOK:\n      break;\n    default:\n    {\n      NumErrors++;\n      PrintString(\"     \");\n      switch(operationResult)\n      {\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\n          PrintString(kUnsupportedMethod);\n          break;\n        case NArchive::NExtract::NOperationResult::kCRCError:\n          PrintString(kCRCFailed);\n          break;\n        case NArchive::NExtract::NOperationResult::kDataError:\n          PrintString(kDataError);\n          break;\n        default:\n          PrintString(kUnknownError);\n      }\n    }\n  }\n\n  if (_outFileStream != NULL)\n  {\n    if (_processedFileInfo.MTimeDefined)\n      _outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);\n    RINOK(_outFileStreamSpec->Close());\n  }\n  _outFileStream.Release();\n  if (_extractMode && _processedFileInfo.AttribDefined)\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);\n  PrintNewLine();\n  return S_OK;\n}\n\n\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\n{\n  if (!PasswordIsDefined)\n  {\n    // You can ask real password here from user\n    // Password = GetPassword(OutStream);\n    // PasswordIsDefined = true;\n    PrintError(\"Password is not defined\");\n    return E_ABORT;\n  }\n  return StringToBstr(Password, password);\n}\n\n\n\n//////////////////////////////////////////////////////////////\n// Archive Creating callback class\n\nstruct CDirItem\n{\n  UInt64 Size;\n  FILETIME CTime;\n  FILETIME ATime;\n  FILETIME MTime;\n  UString Name;\n  UString FullPath;\n  UInt32 Attrib;\n\n  bool isDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\n};\n\nclass CArchiveUpdateCallback:\n  public IArchiveUpdateCallback2,\n  public ICryptoGetTextPassword2,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2)\n\n  // IProgress\n  STDMETHOD(SetTotal)(UInt64 size);\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\n\n  // IUpdateCallback2\n  STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);\n  STDMETHOD(GetUpdateItemInfo)(UInt32 index,\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\n  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);\n  STDMETHOD(SetOperationResult)(Int32 operationResult);\n  STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);\n  STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);\n\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\n\npublic:\n  CRecordVector<UInt64> VolumesSizes;\n  UString VolName;\n  UString VolExt;\n\n  UString DirPrefix;\n  const CObjectVector<CDirItem> *DirItems;\n\n  bool PasswordIsDefined;\n  UString Password;\n  bool AskPassword;\n\n  bool m_NeedBeClosed;\n\n  UStringVector FailedFiles;\n  CRecordVector<HRESULT> FailedCodes;\n\n  CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {};\n\n  ~CArchiveUpdateCallback() { Finilize(); }\n  HRESULT Finilize();\n\n  void Init(const CObjectVector<CDirItem> *dirItems)\n  {\n    DirItems = dirItems;\n    m_NeedBeClosed = false;\n    FailedFiles.Clear();\n    FailedCodes.Clear();\n  }\n};\n\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */)\n{\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */)\n{\n  return S_OK;\n}\n\n\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)\n{\n  return E_NOTIMPL;\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */,\n      Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)\n{\n  if (newData != NULL)\n    *newData = BoolToInt(true);\n  if (newProperties != NULL)\n    *newProperties = BoolToInt(true);\n  if (indexInArchive != NULL)\n    *indexInArchive = (UInt32)-1;\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\n{\n  NWindows::NCOM::CPropVariant prop;\n  \n  if (propID == kpidIsAnti)\n  {\n    prop = false;\n    prop.Detach(value);\n    return S_OK;\n  }\n\n  {\n    const CDirItem &dirItem = (*DirItems)[index];\n    switch(propID)\n    {\n      case kpidPath:  prop = dirItem.Name; break;\n      case kpidIsDir:  prop = dirItem.isDir(); break;\n      case kpidSize:  prop = dirItem.Size; break;\n      case kpidAttrib:  prop = dirItem.Attrib; break;\n      case kpidCTime:  prop = dirItem.CTime; break;\n      case kpidATime:  prop = dirItem.ATime; break;\n      case kpidMTime:  prop = dirItem.MTime; break;\n    }\n  }\n  prop.Detach(value);\n  return S_OK;\n}\n\nHRESULT CArchiveUpdateCallback::Finilize()\n{\n  if (m_NeedBeClosed)\n  {\n    PrintNewLine();\n    m_NeedBeClosed = false;\n  }\n  return S_OK;\n}\n\nstatic void GetStream2(const wchar_t *name)\n{\n  PrintString(\"Compressing  \");\n  if (name[0] == 0)\n    name = kEmptyFileAlias;\n  PrintString(name);\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\n{\n  RINOK(Finilize());\n\n  const CDirItem &dirItem = (*DirItems)[index];\n  GetStream2(dirItem.Name);\n \n  if (dirItem.isDir())\n    return S_OK;\n\n  {\n    CInFileStream *inStreamSpec = new CInFileStream;\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\n    UString path = DirPrefix + dirItem.FullPath;\n    if (!inStreamSpec->Open(path))\n    {\n      DWORD sysError = ::GetLastError();\n      FailedCodes.Add(sysError);\n      FailedFiles.Add(path);\n      // if (systemError == ERROR_SHARING_VIOLATION)\n      {\n        PrintNewLine();\n        PrintError(\"WARNING: can't open file\");\n        // PrintString(NError::MyFormatMessageW(systemError));\n        return S_FALSE;\n      }\n      // return sysError;\n    }\n    *inStream = inStreamLoc.Detach();\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */)\n{\n  m_NeedBeClosed = true;\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\n{\n  if (VolumesSizes.Size() == 0)\n    return S_FALSE;\n  if (index >= (UInt32)VolumesSizes.Size())\n    index = VolumesSizes.Size() - 1;\n  *size = VolumesSizes[index];\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\n{\n  wchar_t temp[32];\n  ConvertUInt64ToString(index + 1, temp);\n  UString res = temp;\n  while (res.Length() < 2)\n    res = UString(L'0') + res;\n  UString fileName = VolName;\n  fileName += L'.';\n  fileName += res;\n  fileName += VolExt;\n  COutFileStream *streamSpec = new COutFileStream;\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\n  if (!streamSpec->Create(fileName, false))\n    return ::GetLastError();\n  *volumeStream = streamLoc.Detach();\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\n{\n  if (!PasswordIsDefined)\n  {\n    if (AskPassword)\n    {\n      // You can ask real password here from user\n      // Password = GetPassword(OutStream);\n      // PasswordIsDefined = true;\n      PrintError(\"Password is not defined\");\n      return E_ABORT;\n    }\n  }\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\n  return StringToBstr(Password, password);\n}\n\n\n\n//////////////////////////////////////////////////////////////////////////\n// Main function\n\nint MY_CDECL main(int argc, char* argv[])\n{\n  #ifdef _WIN32\n  #ifndef _UNICODE\n  g_IsNT = IsItWindowsNT();\n  #endif\n  #endif\n\n  PrintStringLn(kCopyrightString);\n\n  if (argc < 3)\n  {\n    PrintStringLn(kHelpString);\n    return 1;\n  }\n  NWindows::NDLL::CLibrary library;\n  if (!library.Load(TEXT(kDllName)))\n  {\n    PrintError(\"Can not load library\");\n    return 1;\n  }\n  CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress(\"CreateObject\");\n  if (createObjectFunc == 0)\n  {\n    PrintError(\"Can not get CreateObject\");\n    return 1;\n  }\n\n  AString command = argv[1];\n  command.MakeLower();\n  UString archiveName = GetUnicodeString(argv[2], CP_OEMCP);\n  if (command.Compare(\"a\") == 0)\n  {\n    // create archive command\n    if (argc < 4)\n    {\n      PrintStringLn(kHelpString);\n      return 1;\n    }\n    CObjectVector<CDirItem> dirItems;\n    int i;\n    for (i = 3; i < argc; i++)\n    {\n      CDirItem di;\n      UString name = GetUnicodeString(argv[i], CP_OEMCP);\n      \n      NFile::NFind::CFileInfoW fi;\n      if (!NFile::NFind::FindFile(name, fi))\n      {\n        PrintString(UString(L\"Can't find file\") + name);\n        return 1;\n      }\n\n      di.Attrib = fi.Attrib;\n      di.Size = fi.Size;\n      di.CTime = fi.CTime;\n      di.ATime = fi.ATime;\n      di.MTime = fi.MTime;\n      di.Name = name;\n      di.FullPath = name;\n      dirItems.Add(di);\n    }\n    COutFileStream *outFileStreamSpec = new COutFileStream;\n    CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;\n    if (!outFileStreamSpec->Create(archiveName, false))\n    {\n      PrintError(\"can't create archive file\");\n      return 1;\n    }\n\n    CMyComPtr<IOutArchive> outArchive;\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)\n    {\n      PrintError(\"Can not get class object\");\n      return 1;\n    }\n\n    CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\n    CMyComPtr<IArchiveUpdateCallback2> updateCallback(updateCallbackSpec);\n    updateCallbackSpec->Init(&dirItems);\n    // updateCallbackSpec->PasswordIsDefined = true;\n    // updateCallbackSpec->Password = L\"1\";\n\n    HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);\n    updateCallbackSpec->Finilize();\n    if (result != S_OK)\n    {\n      PrintError(\"Update Error\");\n      return 1;\n    }\n    for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)\n    {\n      PrintNewLine();\n      PrintString((UString)L\"Error for file: \" + updateCallbackSpec->FailedFiles[i]);\n    }\n    if (updateCallbackSpec->FailedFiles.Size() != 0)\n      return 1;\n  }\n  else\n  {\n    if (argc != 3)\n    {\n      PrintStringLn(kHelpString);\n      return 1;\n    }\n\n    bool listCommand;\n    if (command.Compare(\"l\") == 0)\n      listCommand = true;\n    else if (command.Compare(\"x\") == 0)\n      listCommand = false;\n    else\n    {\n      PrintError(\"incorrect command\");\n      return 1;\n    }\n  \n    CMyComPtr<IInArchive> archive;\n    if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)\n    {\n      PrintError(\"Can not get class object\");\n      return 1;\n    }\n    \n    CInFileStream *fileSpec = new CInFileStream;\n    CMyComPtr<IInStream> file = fileSpec;\n    \n    if (!fileSpec->Open(archiveName))\n    {\n      PrintError(\"Can not open archive file\");\n      return 1;\n    }\n\n    {\n      CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;\n      CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);\n      openCallbackSpec->PasswordIsDefined = false;\n      // openCallbackSpec->PasswordIsDefined = true;\n      // openCallbackSpec->Password = L\"1\";\n      \n      if (archive->Open(file, 0, openCallback) != S_OK)\n      {\n        PrintError(\"Can not open archive\");\n        return 1;\n      }\n    }\n    \n    if (listCommand)\n    {\n      // List command\n      UInt32 numItems = 0;\n      archive->GetNumberOfItems(&numItems);\n      for (UInt32 i = 0; i < numItems; i++)\n      {\n        {\n          // Get uncompressed size of file\n          NWindows::NCOM::CPropVariant prop;\n          archive->GetProperty(i, kpidSize, &prop);\n          UString s = ConvertPropVariantToString(prop);\n          PrintString(s);\n          PrintString(\"  \");\n        }\n        {\n          // Get name of file\n          NWindows::NCOM::CPropVariant prop;\n          archive->GetProperty(i, kpidPath, &prop);\n          UString s = ConvertPropVariantToString(prop);\n          PrintString(s);\n        }\n        PrintString(\"\\n\");\n      }\n    }\n    else\n    {\n      // Extract command\n      CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\n      CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);\n      extractCallbackSpec->Init(archive, L\"\"); // second parameter is output folder path\n      extractCallbackSpec->PasswordIsDefined = false;\n      // extractCallbackSpec->PasswordIsDefined = true;\n      // extractCallbackSpec->Password = L\"1\";\n      HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);\n      if (result != S_OK)\n      {\n        PrintError(\"Extract Error\");\n        return 1;\n      }\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Client7z/Client7z.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"Client7z\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** DO NOT EDIT **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=Client7z - Win32 Debug\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n!MESSAGE use the Export Makefile command and run\n!MESSAGE \n!MESSAGE NMAKE /f \"Client7z.mak\".\n!MESSAGE \n!MESSAGE You can specify a configuration when running NMAKE\n!MESSAGE by defining the macro CFG on the command line. For example:\n!MESSAGE \n!MESSAGE NMAKE /f \"Client7z.mak\" CFG=\"Client7z - Win32 Debug\"\n!MESSAGE \n!MESSAGE Possible choices for configuration are:\n!MESSAGE \n!MESSAGE \"Client7z - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \"Client7z - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n\n!IF  \"$(CFG)\" == \"Client7z - Win32 Release\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \"Release\"\n# PROP BASE Intermediate_Dir \"Release\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \"Release\"\n# PROP Intermediate_Dir \"Release\"\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /c\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\n# ADD RSC /l 0x419 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n\n!ELSEIF  \"$(CFG)\" == \"Client7z - Win32 Debug\"\n\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 1\n# PROP BASE Output_Dir \"Debug\"\n# PROP BASE Intermediate_Dir \"Debug\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 1\n# PROP Output_Dir \"Debug\"\n# PROP Intermediate_Dir \"Debug\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /Yu\"stdafx.h\" /FD /GZ /c\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\n# ADD RSC /l 0x419 /d \"_DEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n\n!ENDIF \n\n# Begin Target\n\n# Name \"Client7z - Win32 Release\"\n# Name \"Client7z - Win32 Debug\"\n# Begin Group \"Spec\"\n\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n# Begin Source File\n\nSOURCE=.\\StdAfx.cpp\n# ADD CPP /Yc\"stdafx.h\"\n# End Source File\n# Begin Source File\n\nSOURCE=.\\StdAfx.h\n# End Source File\n# End Group\n# Begin Group \"Windows\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\DLL.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\DLL.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileDir.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileDir.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileFind.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileFind.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileIO.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileName.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\FileName.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\PropVariant.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\PropVariant.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Windows\\PropVariantConversions.h\n# End Source File\n# End Group\n# Begin Group \"Common\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\IntToString.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\IntToString.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyString.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyString.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyVector.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\MyVector.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\NewHandler.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\StringConvert.h\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Wildcard.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\..\\Common\\Wildcard.h\n# End Source File\n# End Group\n# Begin Group \"7zip Common\"\n\n# PROP Default_Filter \"\"\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FileStreams.cpp\n# End Source File\n# Begin Source File\n\nSOURCE=..\\..\\Common\\FileStreams.h\n# End Source File\n# End Group\n# Begin Source File\n\nSOURCE=.\\Client7z.cpp\n# End Source File\n# End Target\n# End Project\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Client7z/Client7z.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n###############################################################################\n\nProject: \"Client7z\"=.\\Client7z.dsp - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nGlobal:\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<3>\n{{{\n}}}\n\n###############################################################################\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Client7z/StdAfx.cpp",
    "content": "// StdAfx.cpp\n\n#include \"StdAfx.h\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Client7z/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include <windows.h>\n#include <stdio.h>\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Client7z/makefile",
    "content": "PROG = 7z.exe\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\nCFLAGS = $(CFLAGS) -I ../../../\n\nCONSOLE_OBJS = \\\n  $O\\Client7z.obj \\\n\nCOMMON_OBJS = \\\n  $O\\IntToString.obj \\\n  $O\\NewHandler.obj \\\n  $O\\MyString.obj \\\n  $O\\StringConvert.obj \\\n  $O\\StringToInt.obj \\\n  $O\\MyVector.obj \\\n  $O\\Wildcard.obj \\\n\nWIN_OBJS = \\\n  $O\\DLL.obj \\\n  $O\\FileDir.obj \\\n  $O\\FileFind.obj \\\n  $O\\FileIO.obj \\\n  $O\\FileName.obj \\\n  $O\\PropVariant.obj \\\n  $O\\PropVariantConversions.obj \\\n\n7ZIP_COMMON_OBJS = \\\n  $O\\FileStreams.obj \\\n\nOBJS = \\\n  $O\\StdAfx.obj \\\n  $(CONSOLE_OBJS) \\\n  $(COMMON_OBJS) \\\n  $(WIN_OBJS) \\\n  $(7ZIP_COMMON_OBJS) \\\n\n!include \"../../../Build.mak\"\n\n$(CONSOLE_OBJS): $(*B).cpp\n\t$(COMPL)\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\n\t$(COMPL)\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\n\t$(COMPL)\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\n\t$(COMPL)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ArchiveCommandLine.cpp",
    "content": "// ArchiveCommandLine.cpp\n\n#include \"StdAfx.h\"\n\n#ifdef _WIN32\n#include <io.h>\n#endif\n#include <stdio.h>\n\n#include \"Common/ListFileUtils.h\"\n#include \"Common/StringConvert.h\"\n#include \"Common/StringToInt.h\"\n\n#include \"Windows/FileName.h\"\n#include \"Windows/FileDir.h\"\n#ifdef _WIN32\n#include \"Windows/FileMapping.h\"\n#include \"Windows/Synchronization.h\"\n#endif\n\n#include \"ArchiveCommandLine.h\"\n#include \"UpdateAction.h\"\n#include \"Update.h\"\n#include \"SortUtils.h\"\n#include \"EnumDirItems.h\"\n\nextern bool g_CaseSensitive;\n\n#if _MSC_VER >= 1400\n#define MY_isatty_fileno(x) _isatty(_fileno(x))\n#else\n#define MY_isatty_fileno(x) isatty(fileno(x))\n#endif\n\n#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);\n\nusing namespace NCommandLineParser;\nusing namespace NWindows;\nusing namespace NFile;\n\nnamespace NKey {\nenum Enum\n{\n  kHelp1 = 0,\n  kHelp2,\n  kHelp3,\n  kDisableHeaders,\n  kDisablePercents,\n  kArchiveType,\n  kYes,\n  #ifndef _NO_CRYPTO\n  kPassword,\n  #endif\n  kProperty,\n  kOutputDir,\n  kWorkingDir,\n  kInclude,\n  kExclude,\n  kArInclude,\n  kArExclude,\n  kNoArName,\n  kUpdate,\n  kVolume,\n  kRecursed,\n  kSfx,\n  kStdIn,\n  kStdOut,\n  kOverwrite,\n  kEmail,\n  kShowDialog,\n  kLargePages,\n  kCharSet,\n  kTechMode,\n  kShareForWrite,\n  kCaseSensitive\n};\n\n}\n\n\nstatic const wchar_t kRecursedIDChar = 'R';\nstatic const wchar_t *kRecursedPostCharSet = L\"0-\";\n\nnamespace NRecursedPostCharIndex {\n  enum EEnum\n  {\n    kWildCardRecursionOnly = 0,\n    kNoRecursion = 1\n  };\n}\n\nstatic const char kImmediateNameID = '!';\nstatic const char kMapNameID = '#';\nstatic const char kFileListID = '@';\n\nstatic const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be\nstatic const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be\n\nstatic const wchar_t *kOverwritePostCharSet = L\"asut\";\n\nNExtract::NOverwriteMode::EEnum k_OverwriteModes[] =\n{\n  NExtract::NOverwriteMode::kWithoutPrompt,\n  NExtract::NOverwriteMode::kSkipExisting,\n  NExtract::NOverwriteMode::kAutoRename,\n  NExtract::NOverwriteMode::kAutoRenameExisting\n};\n\nstatic const CSwitchForm kSwitchForms[] =\n  {\n    { L\"?\",  NSwitchType::kSimple, false },\n    { L\"H\",  NSwitchType::kSimple, false },\n    { L\"-HELP\",  NSwitchType::kSimple, false },\n    { L\"BA\", NSwitchType::kSimple, false },\n    { L\"BD\", NSwitchType::kSimple, false },\n    { L\"T\",  NSwitchType::kUnLimitedPostString, false, 1 },\n    { L\"Y\",  NSwitchType::kSimple, false },\n    #ifndef _NO_CRYPTO\n    { L\"P\",  NSwitchType::kUnLimitedPostString, false, 0 },\n    #endif\n    { L\"M\",  NSwitchType::kUnLimitedPostString, true, 1 },\n    { L\"O\",  NSwitchType::kUnLimitedPostString, false, 1 },\n    { L\"W\",  NSwitchType::kUnLimitedPostString, false, 0 },\n    { L\"I\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\n    { L\"X\",  NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\n    { L\"AI\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\n    { L\"AX\", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},\n    { L\"AN\", NSwitchType::kSimple, false },\n    { L\"U\",  NSwitchType::kUnLimitedPostString, true, 1},\n    { L\"V\",  NSwitchType::kUnLimitedPostString, true, 1},\n    { L\"R\",  NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },\n    { L\"SFX\", NSwitchType::kUnLimitedPostString, false, 0 },\n    { L\"SI\", NSwitchType::kUnLimitedPostString, false, 0 },\n    { L\"SO\", NSwitchType::kSimple, false, 0 },\n    { L\"AO\", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},\n    { L\"SEML\", NSwitchType::kUnLimitedPostString, false, 0},\n    { L\"AD\",  NSwitchType::kSimple, false },\n    { L\"SLP\", NSwitchType::kUnLimitedPostString, false, 0},\n    { L\"SCS\", NSwitchType::kUnLimitedPostString, false, 0},\n    { L\"SLT\", NSwitchType::kSimple, false },\n    { L\"SSW\", NSwitchType::kSimple, false },\n    { L\"SSC\", NSwitchType::kPostChar, false, 0, 0, L\"-\" }\n  };\n\nstatic const CCommandForm g_CommandForms[] =\n{\n  { L\"A\", false },\n  { L\"U\", false },\n  { L\"D\", false },\n  { L\"T\", false },\n  { L\"E\", false },\n  { L\"X\", false },\n  { L\"L\", false },\n  { L\"B\", false },\n  { L\"I\", false }\n};\n\nstatic const int kNumCommandForms = sizeof(g_CommandForms) /  sizeof(g_CommandForms[0]);\n\nstatic const wchar_t *kUniversalWildcard = L\"*\";\nstatic const int kMinNonSwitchWords = 1;\nstatic const int kCommandIndex = 0;\n\n// ---------------------------\n// exception messages\n\nstatic const char *kUserErrorMessage  = \"Incorrect command line\";\nstatic const char *kIncorrectListFile = \"Incorrect item in listfile.\\nCheck charset encoding and -scs switch.\";\nstatic const char *kIncorrectWildCardInListFile = \"Incorrect wildcard in listfile\";\nstatic const char *kIncorrectWildCardInCommandLine  = \"Incorrect wildcard in command line\";\nstatic const char *kTerminalOutError = \"I won't write compressed data to a terminal\";\nstatic const char *kSameTerminalError = \"I won't write data and program's messages to same terminal\";\n\nstatic void ThrowException(const char *errorMessage)\n{\n  throw CArchiveCommandLineException(errorMessage);\n};\n\nstatic void ThrowUserErrorException()\n{\n  ThrowException(kUserErrorMessage);\n};\n\n// ---------------------------\n\nbool CArchiveCommand::IsFromExtractGroup() const\n{\n  switch(CommandType)\n  {\n    case NCommandType::kTest:\n    case NCommandType::kExtract:\n    case NCommandType::kFullExtract:\n      return true;\n    default:\n      return false;\n  }\n}\n\nNExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const\n{\n  switch(CommandType)\n  {\n    case NCommandType::kTest:\n    case NCommandType::kFullExtract:\n      return NExtract::NPathMode::kFullPathnames;\n    default:\n      return NExtract::NPathMode::kNoPathnames;\n  }\n}\n\nbool CArchiveCommand::IsFromUpdateGroup() const\n{\n  return (CommandType == NCommandType::kAdd ||\n    CommandType == NCommandType::kUpdate ||\n    CommandType == NCommandType::kDelete);\n}\n\nstatic NRecursedType::EEnum GetRecursedTypeFromIndex(int index)\n{\n  switch (index)\n  {\n    case NRecursedPostCharIndex::kWildCardRecursionOnly:\n      return NRecursedType::kWildCardOnlyRecursed;\n    case NRecursedPostCharIndex::kNoRecursion:\n      return NRecursedType::kNonRecursed;\n    default:\n      return NRecursedType::kRecursed;\n  }\n}\n\nstatic bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)\n{\n  UString commandStringUpper = commandString;\n  commandStringUpper.MakeUpper();\n  UString postString;\n  int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper,\n      postString) ;\n  if (commandIndex < 0)\n    return false;\n  command.CommandType = (NCommandType::EEnum)commandIndex;\n  return true;\n}\n\n// ------------------------------------------------------------------\n// filenames functions\n\nstatic bool AddNameToCensor(NWildcard::CCensor &wildcardCensor,\n    const UString &name, bool include, NRecursedType::EEnum type)\n{\n  bool isWildCard = DoesNameContainWildCard(name);\n  bool recursed = false;\n\n  switch (type)\n  {\n    case NRecursedType::kWildCardOnlyRecursed:\n      recursed = isWildCard;\n      break;\n    case NRecursedType::kRecursed:\n      recursed = true;\n      break;\n    case NRecursedType::kNonRecursed:\n      recursed = false;\n      break;\n  }\n  wildcardCensor.AddItem(include, name, recursed);\n  return true;\n}\n\nstatic void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,\n    LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)\n{\n  UStringVector names;\n  if (!ReadNamesFromListFile(fileName, names, codePage))\n    throw kIncorrectListFile;\n  for (int i = 0; i < names.Size(); i++)\n    if (!AddNameToCensor(wildcardCensor, names[i], include, type))\n      throw kIncorrectWildCardInListFile;\n}\n\nstatic void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor,\n    const UString &name, bool include, NRecursedType::EEnum recursedType)\n{\n  if (!AddNameToCensor(wildcardCensor, name, include, recursedType))\n    throw kIncorrectWildCardInCommandLine;\n}\n\nstatic void AddToCensorFromNonSwitchesStrings(\n    int startIndex,\n    NWildcard::CCensor &wildcardCensor,\n    const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,\n    bool thereAreSwitchIncludes, UINT codePage)\n{\n  if (nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes))\n    AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);\n  for (int i = startIndex; i < nonSwitchStrings.Size(); i++)\n  {\n    const UString &s = nonSwitchStrings[i];\n    if (s[0] == kFileListID)\n      AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);\n    else\n      AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);\n  }\n}\n\n#ifdef _WIN32\nstatic void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor,\n    const UString &switchParam, bool include,\n    NRecursedType::EEnum commonRecursedType)\n{\n  int splitPos = switchParam.Find(L':');\n  if (splitPos < 0)\n    ThrowUserErrorException();\n  UString mappingName = switchParam.Left(splitPos);\n  \n  UString switchParam2 = switchParam.Mid(splitPos + 1);\n  splitPos = switchParam2.Find(L':');\n  if (splitPos < 0)\n    ThrowUserErrorException();\n  \n  UString mappingSize = switchParam2.Left(splitPos);\n  UString eventName = switchParam2.Mid(splitPos + 1);\n  \n  UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);\n  UInt32 dataSize = (UInt32)dataSize64;\n  {\n    CFileMapping fileMapping;\n    if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName)))\n      ThrowException(\"Can not open mapping\");\n    LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize);\n    if (data == NULL)\n      ThrowException(\"MapViewOfFile error\");\n    try\n    {\n      const wchar_t *curData = (const wchar_t *)data;\n      if (*curData != 0)\n        ThrowException(\"Incorrect mapping data\");\n      UInt32 numChars = dataSize / sizeof(wchar_t);\n      UString name;\n      for (UInt32 i = 1; i < numChars; i++)\n      {\n        wchar_t c = curData[i];\n        if (c == L'\\0')\n        {\n          AddCommandLineWildCardToCensr(wildcardCensor,\n              name, include, commonRecursedType);\n          name.Empty();\n        }\n        else\n          name += c;\n      }\n      if (!name.IsEmpty())\n        ThrowException(\"data error\");\n    }\n    catch(...)\n    {\n      UnmapViewOfFile(data);\n      throw;\n    }\n    UnmapViewOfFile(data);\n  }\n  \n  {\n    NSynchronization::CManualResetEvent event;\n    if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)\n      event.Set();\n  }\n}\n#endif\n\nstatic void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,\n    const UStringVector &strings, bool include,\n    NRecursedType::EEnum commonRecursedType, UINT codePage)\n{\n  for (int i = 0; i < strings.Size(); i++)\n  {\n    const UString &name = strings[i];\n    NRecursedType::EEnum recursedType;\n    int pos = 0;\n    if (name.Length() < kSomeCludePostStringMinSize)\n      ThrowUserErrorException();\n    if (::MyCharUpper(name[pos]) == kRecursedIDChar)\n    {\n      pos++;\n      int index = UString(kRecursedPostCharSet).Find(name[pos]);\n      recursedType = GetRecursedTypeFromIndex(index);\n      if (index >= 0)\n        pos++;\n    }\n    else\n      recursedType = commonRecursedType;\n    if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)\n      ThrowUserErrorException();\n    UString tail = name.Mid(pos + 1);\n    if (name[pos] == kImmediateNameID)\n      AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);\n    else if (name[pos] == kFileListID)\n      AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);\n    #ifdef _WIN32\n    else if (name[pos] == kMapNameID)\n      ParseMapWithPaths(wildcardCensor, tail, include, recursedType);\n    #endif\n    else\n      ThrowUserErrorException();\n  }\n}\n\n#ifdef _WIN32\n\n// This code converts all short file names to long file names.\n\nstatic void ConvertToLongName(const UString &prefix, UString &name)\n{\n  if (name.IsEmpty() || DoesNameContainWildCard(name))\n    return;\n  NFind::CFileInfoW fileInfo;\n  if (NFind::FindFile(prefix + name, fileInfo))\n    name = fileInfo.Name;\n}\n\nstatic void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)\n{\n  for (int i = 0; i < items.Size(); i++)\n  {\n    NWildcard::CItem &item = items[i];\n    if (item.Recursive || item.PathParts.Size() != 1)\n      continue;\n    ConvertToLongName(prefix, item.PathParts.Front());\n  }\n}\n\nstatic void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)\n{\n  ConvertToLongNames(prefix, node.IncludeItems);\n  ConvertToLongNames(prefix, node.ExcludeItems);\n  int i;\n  for (i = 0; i < node.SubNodes.Size(); i++)\n    ConvertToLongName(prefix, node.SubNodes[i].Name);\n  // mix folders with same name\n  for (i = 0; i < node.SubNodes.Size(); i++)\n  {\n    NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];\n    for (int j = i + 1; j < node.SubNodes.Size();)\n    {\n      const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];\n      if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)\n      {\n        nextNode1.IncludeItems += nextNode2.IncludeItems;\n        nextNode1.ExcludeItems += nextNode2.ExcludeItems;\n        node.SubNodes.Delete(j);\n      }\n      else\n        j++;\n    }\n  }\n  for (i = 0; i < node.SubNodes.Size(); i++)\n  {\n    NWildcard::CCensorNode &nextNode = node.SubNodes[i];\n    ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode);\n  }\n}\n\nstatic void ConvertToLongNames(NWildcard::CCensor &censor)\n{\n  for (int i = 0; i < censor.Pairs.Size(); i++)\n  {\n    NWildcard::CPair &pair = censor.Pairs[i];\n    ConvertToLongNames(pair.Prefix, pair.Head);\n  }\n}\n\n#endif\n\nstatic NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)\n{\n  switch(i)\n  {\n    case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;\n    case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;\n    case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;\n    case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;\n  }\n  throw 98111603;\n}\n\nconst UString kUpdatePairStateIDSet = L\"PQRXYZW\";\nconst int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};\n\nconst UString kUpdatePairActionIDSet = L\"0123\"; //Ignore, Copy, Compress, Create Anti\n\nconst wchar_t *kUpdateIgnoreItselfPostStringID = L\"-\";\nconst wchar_t kUpdateNewArchivePostCharID = '!';\n\n\nstatic bool ParseUpdateCommandString2(const UString &command,\n    NUpdateArchive::CActionSet &actionSet, UString &postString)\n{\n  for (int i = 0; i < command.Length();)\n  {\n    wchar_t c = MyCharUpper(command[i]);\n    int statePos = kUpdatePairStateIDSet.Find(c);\n    if (statePos < 0)\n    {\n      postString = command.Mid(i);\n      return true;\n    }\n    i++;\n    if (i >= command.Length())\n      return false;\n    int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));\n    if (actionPos < 0)\n      return false;\n    actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);\n    if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)\n      return false;\n    i++;\n  }\n  postString.Empty();\n  return true;\n}\n\nstatic void ParseUpdateCommandString(CUpdateOptions &options,\n    const UStringVector &updatePostStrings,\n    const NUpdateArchive::CActionSet &defaultActionSet)\n{\n  for (int i = 0; i < updatePostStrings.Size(); i++)\n  {\n    const UString &updateString = updatePostStrings[i];\n    if (updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)\n    {\n      if (options.UpdateArchiveItself)\n      {\n        options.UpdateArchiveItself = false;\n        options.Commands.Delete(0);\n      }\n    }\n    else\n    {\n      NUpdateArchive::CActionSet actionSet = defaultActionSet;\n\n      UString postString;\n      if (!ParseUpdateCommandString2(updateString, actionSet, postString))\n        ThrowUserErrorException();\n      if (postString.IsEmpty())\n      {\n        if (options.UpdateArchiveItself)\n          options.Commands[0].ActionSet = actionSet;\n      }\n      else\n      {\n        if (MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)\n          ThrowUserErrorException();\n        CUpdateArchiveCommand uc;\n        UString archivePath = postString.Mid(1);\n        if (archivePath.IsEmpty())\n          ThrowUserErrorException();\n        uc.UserArchivePath = archivePath;\n        uc.ActionSet = actionSet;\n        options.Commands.Add(uc);\n      }\n    }\n  }\n}\n\nstatic const char kByteSymbol = 'B';\nstatic const char kKiloSymbol = 'K';\nstatic const char kMegaSymbol = 'M';\nstatic const char kGigaSymbol = 'G';\n\nstatic bool ParseComplexSize(const UString &src, UInt64 &result)\n{\n  UString s = src;\n  s.MakeUpper();\n\n  const wchar_t *start = s;\n  const wchar_t *end;\n  UInt64 number = ConvertStringToUInt64(start, &end);\n  int numDigits = (int)(end - start);\n  if (numDigits == 0 || s.Length() > numDigits + 1)\n    return false;\n  if (s.Length() == numDigits)\n  {\n    result = number;\n    return true;\n  }\n  int numBits;\n  switch (s[numDigits])\n  {\n    case kByteSymbol:\n      result = number;\n      return true;\n    case kKiloSymbol:\n      numBits = 10;\n      break;\n    case kMegaSymbol:\n      numBits = 20;\n      break;\n    case kGigaSymbol:\n      numBits = 30;\n      break;\n    default:\n      return false;\n  }\n  if (number >= ((UInt64)1 << (64 - numBits)))\n    return false;\n  result = number << numBits;\n  return true;\n}\n\nstatic void SetAddCommandOptions(\n    NCommandType::EEnum commandType,\n    const CParser &parser,\n    CUpdateOptions &options)\n{\n  NUpdateArchive::CActionSet defaultActionSet;\n  switch(commandType)\n  {\n    case NCommandType::kAdd:\n      defaultActionSet = NUpdateArchive::kAddActionSet;\n      break;\n    case NCommandType::kDelete:\n      defaultActionSet = NUpdateArchive::kDeleteActionSet;\n      break;\n    default:\n      defaultActionSet = NUpdateArchive::kUpdateActionSet;\n  }\n  \n  options.UpdateArchiveItself = true;\n  \n  options.Commands.Clear();\n  CUpdateArchiveCommand updateMainCommand;\n  updateMainCommand.ActionSet = defaultActionSet;\n  options.Commands.Add(updateMainCommand);\n  if (parser[NKey::kUpdate].ThereIs)\n    ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings,\n        defaultActionSet);\n  if (parser[NKey::kWorkingDir].ThereIs)\n  {\n    const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];\n    if (postString.IsEmpty())\n      NDirectory::MyGetTempPath(options.WorkingDir);\n    else\n      options.WorkingDir = postString;\n  }\n  options.SfxMode = parser[NKey::kSfx].ThereIs;\n  if (options.SfxMode)\n    options.SfxModule = parser[NKey::kSfx].PostStrings[0];\n\n  if (parser[NKey::kVolume].ThereIs)\n  {\n    const UStringVector &sv = parser[NKey::kVolume].PostStrings;\n    for (int i = 0; i < sv.Size(); i++)\n    {\n      UInt64 size;\n      if (!ParseComplexSize(sv[i], size))\n        ThrowException(\"Incorrect volume size\");\n      options.VolumesSizes.Add(size);\n    }\n  }\n}\n\nstatic void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)\n{\n  if (parser[NKey::kProperty].ThereIs)\n  {\n    // options.MethodMode.Properties.Clear();\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\n    {\n      CProperty property;\n      const UString &postString = parser[NKey::kProperty].PostStrings[i];\n      int index = postString.Find(L'=');\n      if (index < 0)\n        property.Name = postString;\n      else\n      {\n        property.Name = postString.Left(index);\n        property.Value = postString.Mid(index + 1);\n      }\n      properties.Add(property);\n    }\n  }\n}\n\nCArchiveCommandLineParser::CArchiveCommandLineParser():\n  parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}\n\nvoid CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,\n    CArchiveCommandLineOptions &options)\n{\n  try\n  {\n    parser.ParseStrings(kSwitchForms, commandStrings);\n  }\n  catch(...)\n  {\n    ThrowUserErrorException();\n  }\n\n  options.IsInTerminal = MY_IS_TERMINAL(stdin);\n  options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);\n  options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);\n  options.StdOutMode = parser[NKey::kStdOut].ThereIs;\n  options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;\n  options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs  || parser[NKey::kHelp3].ThereIs;\n\n  #ifdef _WIN32\n  options.LargePages = false;\n  if (parser[NKey::kLargePages].ThereIs)\n  {\n    const UString &postString = parser[NKey::kLargePages].PostStrings.Front();\n    if (postString.IsEmpty())\n      options.LargePages = true;\n  }\n  #endif\n}\n\nstruct CCodePagePair\n{\n  const wchar_t *Name;\n  UINT CodePage;\n};\n\nstatic CCodePagePair g_CodePagePairs[] =\n{\n  { L\"UTF-8\", CP_UTF8 },\n  { L\"WIN\",   CP_ACP },\n  { L\"DOS\",   CP_OEMCP }\n};\n\nstatic const int kNumCodePages = sizeof(g_CodePagePairs) / sizeof(g_CodePagePairs[0]);\n\nstatic bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)\n{\n  const wchar_t *end;\n  UInt64 number = ConvertStringToUInt64(s, &end);\n  if (*end != 0)\n    return false;\n  if (number > (UInt32)0xFFFFFFFF)\n    return false;\n  v = (UInt32)number;\n  return true;\n}\n\nvoid CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)\n{\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\n  int numNonSwitchStrings = nonSwitchStrings.Size();\n  if (numNonSwitchStrings < kMinNonSwitchWords)\n    ThrowUserErrorException();\n\n  if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))\n    ThrowUserErrorException();\n\n  options.TechMode = parser[NKey::kTechMode].ThereIs;\n\n  if (parser[NKey::kCaseSensitive].ThereIs)\n    g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);\n\n  NRecursedType::EEnum recursedType;\n  if (parser[NKey::kRecursed].ThereIs)\n    recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);\n  else\n    recursedType = NRecursedType::kNonRecursed;\n\n  UINT codePage = CP_UTF8;\n  if (parser[NKey::kCharSet].ThereIs)\n  {\n    UString name = parser[NKey::kCharSet].PostStrings.Front();\n    name.MakeUpper();\n    int i;\n    for (i = 0; i < kNumCodePages; i++)\n    {\n      const CCodePagePair &pair = g_CodePagePairs[i];\n      if (name.Compare(pair.Name) == 0)\n      {\n        codePage = pair.CodePage;\n        break;\n      }\n    }\n    if (i >= kNumCodePages)\n      ThrowUserErrorException();\n  }\n\n  bool thereAreSwitchIncludes = false;\n  if (parser[NKey::kInclude].ThereIs)\n  {\n    thereAreSwitchIncludes = true;\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\n        parser[NKey::kInclude].PostStrings, true, recursedType, codePage);\n  }\n  if (parser[NKey::kExclude].ThereIs)\n    AddSwitchWildCardsToCensor(options.WildcardCensor,\n        parser[NKey::kExclude].PostStrings, false, recursedType, codePage);\n \n  int curCommandIndex = kCommandIndex + 1;\n  bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs &&\n      options.Command.CommandType != NCommandType::kBenchmark &&\n      options.Command.CommandType != NCommandType::kInfo;\n  if (thereIsArchiveName)\n  {\n    if (curCommandIndex >= numNonSwitchStrings)\n      ThrowUserErrorException();\n    options.ArchiveName = nonSwitchStrings[curCommandIndex++];\n  }\n\n  AddToCensorFromNonSwitchesStrings(\n      curCommandIndex, options.WildcardCensor,\n      nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);\n\n  options.YesToAll = parser[NKey::kYes].ThereIs;\n\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\n\n  #ifndef _NO_CRYPTO\n  options.PasswordEnabled = parser[NKey::kPassword].ThereIs;\n  if (options.PasswordEnabled)\n    options.Password = parser[NKey::kPassword].PostStrings[0];\n  #endif\n\n  options.StdInMode = parser[NKey::kStdIn].ThereIs;\n  options.ShowDialog = parser[NKey::kShowDialog].ThereIs;\n\n  if (parser[NKey::kArchiveType].ThereIs)\n    options.ArcType = parser[NKey::kArchiveType].PostStrings[0];\n\n  if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\n  {\n    if (options.StdInMode)\n      ThrowException(\"Reading archives from stdin is not implemented\");\n    if (!options.WildcardCensor.AllAreRelative())\n      ThrowException(\"Cannot use absolute pathnames for this command\");\n\n    NWildcard::CCensor archiveWildcardCensor;\n\n    if (parser[NKey::kArInclude].ThereIs)\n    {\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\n        parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);\n    }\n    if (parser[NKey::kArExclude].ThereIs)\n      AddSwitchWildCardsToCensor(archiveWildcardCensor,\n      parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);\n\n    if (thereIsArchiveName)\n      AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);\n\n    #ifdef _WIN32\n    ConvertToLongNames(archiveWildcardCensor);\n    #endif\n\n    archiveWildcardCensor.ExtendExclude();\n\n    UStringVector archivePaths;\n\n    {\n      CDirItems dirItems;\n      {\n        UStringVector errorPaths;\n        CRecordVector<DWORD> errorCodes;\n        HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);\n        if (res != S_OK || errorPaths.Size() > 0)\n          throw \"cannot find archive\";\n      }\n      for (int i = 0; i < dirItems.Items.Size(); i++)\n      {\n        const CDirItem &dirItem = dirItems.Items[i];\n        if (!dirItem.IsDir())\n          archivePaths.Add(dirItems.GetPhyPath(i));\n      }\n    }\n\n    if (archivePaths.Size() == 0)\n      throw \"there is no such archive\";\n\n    UStringVector archivePathsFull;\n\n    int i;\n    for (i = 0; i < archivePaths.Size(); i++)\n    {\n      UString fullPath;\n      NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);\n      archivePathsFull.Add(fullPath);\n    }\n    CIntVector indices;\n    SortFileNames(archivePathsFull, indices);\n    options.ArchivePathsSorted.Reserve(indices.Size());\n    options.ArchivePathsFullSorted.Reserve(indices.Size());\n    for (i = 0; i < indices.Size(); i++)\n    {\n      options.ArchivePathsSorted.Add(archivePaths[indices[i]]);\n      options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);\n    }\n\n    if (isExtractGroupCommand)\n    {\n      SetMethodOptions(parser, options.ExtractProperties);\n      if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)\n        throw kSameTerminalError;\n      if (parser[NKey::kOutputDir].ThereIs)\n      {\n        options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];\n        NFile::NName::NormalizeDirPathPrefix(options.OutputDir);\n      }\n\n      options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;\n      if (parser[NKey::kOverwrite].ThereIs)\n        options.OverwriteMode =\n            k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];\n      else if (options.YesToAll)\n        options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\n    }\n  }\n  else if (options.Command.IsFromUpdateGroup())\n  {\n    CUpdateOptions &updateOptions = options.UpdateOptions;\n\n    SetAddCommandOptions(options.Command.CommandType, parser, updateOptions);\n    \n    SetMethodOptions(parser, updateOptions.MethodMode.Properties);\n\n    if (parser[NKey::kShareForWrite].ThereIs)\n      updateOptions.OpenShareForWrite = true;\n\n    options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;\n\n    if (options.EnablePercents)\n    {\n      if ((options.StdOutMode && !options.IsStdErrTerminal) ||\n         (!options.StdOutMode && !options.IsStdOutTerminal))\n        options.EnablePercents = false;\n    }\n\n    updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;\n    if (updateOptions.EMailMode)\n    {\n      updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();\n      if (updateOptions.EMailAddress.Length() > 0)\n        if (updateOptions.EMailAddress[0] == L'.')\n        {\n          updateOptions.EMailRemoveAfter = true;\n          updateOptions.EMailAddress.Delete(0);\n        }\n    }\n\n    updateOptions.StdOutMode = options.StdOutMode;\n    updateOptions.StdInMode = options.StdInMode;\n\n    if (updateOptions.StdOutMode && updateOptions.EMailMode)\n      throw \"stdout mode and email mode cannot be combined\";\n    if (updateOptions.StdOutMode && options.IsStdOutTerminal)\n      throw kTerminalOutError;\n    if (updateOptions.StdInMode)\n      updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();\n\n    #ifdef _WIN32\n    ConvertToLongNames(options.WildcardCensor);\n    #endif\n  }\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\n  {\n    options.NumThreads = (UInt32)-1;\n    options.DictionarySize = (UInt32)-1;\n    options.NumIterations = 1;\n    if (curCommandIndex < numNonSwitchStrings)\n    {\n      if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))\n        ThrowUserErrorException();\n    }\n    for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)\n    {\n      UString postString = parser[NKey::kProperty].PostStrings[i];\n      postString.MakeUpper();\n      if (postString.Length() < 2)\n        ThrowUserErrorException();\n      if (postString[0] == 'D')\n      {\n        int pos = 1;\n        if (postString[pos] == '=')\n          pos++;\n        UInt32 logSize;\n        if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))\n          ThrowUserErrorException();\n        if (logSize > 31)\n          ThrowUserErrorException();\n        options.DictionarySize = 1 << logSize;\n      }\n      else if (postString[0] == 'M' && postString[1] == 'T' )\n      {\n        int pos = 2;\n        if (postString[pos] == '=')\n          pos++;\n        if (postString[pos] != 0)\n          if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))\n            ThrowUserErrorException();\n      }\n      else if (postString[0] == 'M' && postString[1] == '=' )\n      {\n        int pos = 2;\n        if (postString[pos] != 0)\n          options.Method = postString.Mid(2);\n      }\n      else\n        ThrowUserErrorException();\n    }\n  }\n  else if (options.Command.CommandType == NCommandType::kInfo)\n  {\n  }\n  else\n    ThrowUserErrorException();\n  options.WildcardCensor.ExtendExclude();\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ArchiveCommandLine.h",
    "content": "// ArchiveCommandLine.h\n\n#ifndef __ARCHIVECOMMANDLINE_H\n#define __ARCHIVECOMMANDLINE_H\n\n#include \"Common/Wildcard.h\"\n#include \"Common/CommandLineParser.h\"\n\n#include \"Extract.h\"\n#include \"Update.h\"\n\nstruct CArchiveCommandLineException: public AString\n{\n  CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {}\n};\n\nnamespace NCommandType { enum EEnum\n{\n  kAdd = 0,\n  kUpdate,\n  kDelete,\n  kTest,\n  kExtract,\n  kFullExtract,\n  kList,\n  kBenchmark,\n  kInfo\n};}\n\nnamespace NRecursedType { enum EEnum\n{\n  kRecursed,\n  kWildCardOnlyRecursed,\n  kNonRecursed\n};}\n\nstruct CArchiveCommand\n{\n  NCommandType::EEnum CommandType;\n  bool IsFromExtractGroup() const;\n  bool IsFromUpdateGroup() const;\n  bool IsTestMode() const { return CommandType == NCommandType::kTest; }\n  NExtract::NPathMode::EEnum GetPathMode() const;\n};\n\nstruct CArchiveCommandLineOptions\n{\n  bool HelpMode;\n\n  #ifdef _WIN32\n  bool LargePages;\n  #endif\n\n  bool IsInTerminal;\n  bool IsStdOutTerminal;\n  bool IsStdErrTerminal;\n  bool StdInMode;\n  bool StdOutMode;\n  bool EnableHeaders;\n\n  bool YesToAll;\n  bool ShowDialog;\n  // NWildcard::CCensor ArchiveWildcardCensor;\n  NWildcard::CCensor WildcardCensor;\n\n  CArchiveCommand Command;\n  UString ArchiveName;\n\n  #ifndef _NO_CRYPTO\n  bool PasswordEnabled;\n  UString Password;\n  #endif\n\n  bool TechMode;\n  // Extract\n  bool AppendName;\n  UString OutputDir;\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\n  UStringVector ArchivePathsSorted;\n  UStringVector ArchivePathsFullSorted;\n  CObjectVector<CProperty> ExtractProperties;\n\n  CUpdateOptions UpdateOptions;\n  UString ArcType;\n  bool EnablePercents;\n\n  // Benchmark\n  UInt32 NumIterations;\n  UInt32 NumThreads;\n  UInt32 DictionarySize;\n  UString Method;\n\n\n  CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};\n};\n\nclass CArchiveCommandLineParser\n{\n  NCommandLineParser::CParser parser;\npublic:\n  CArchiveCommandLineParser();\n  void Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options);\n  void Parse2(CArchiveCommandLineOptions &options);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp",
    "content": "// ArchiveExtractCallback.cpp\n\n#include \"StdAfx.h\"\n\n#include \"ArchiveExtractCallback.h\"\n\n#include \"Common/Wildcard.h\"\n#include \"Common/StringConvert.h\"\n#include \"Common/ComTry.h\"\n\n#include \"Windows/FileDir.h\"\n#include \"Windows/FileFind.h\"\n#include \"Windows/Time.h\"\n#include \"Windows/Defs.h\"\n#include \"Windows/PropVariant.h\"\n\n#include \"Windows/PropVariantConversions.h\"\n\n#include \"../../Common/FilePathAutoRename.h\"\n\n#include \"../Common/ExtractingFilePath.h\"\n#include \"OpenArchive.h\"\n\nusing namespace NWindows;\n\nstatic const wchar_t *kCantAutoRename = L\"ERROR: Can not create file with auto name\";\nstatic const wchar_t *kCantRenameFile = L\"ERROR: Can not rename existing file \";\nstatic const wchar_t *kCantDeleteOutputFile = L\"ERROR: Can not delete output file \";\n\n\nvoid CArchiveExtractCallback::Init(\n    IInArchive *archiveHandler,\n    IFolderArchiveExtractCallback *extractCallback2,\n    bool stdOutMode,\n    const UString &directoryPath,\n    const UStringVector &removePathParts,\n    const UString &itemDefaultName,\n    const FILETIME &utcMTimeDefault,\n    UInt32 attributesDefault,\n    UInt64 packSize)\n{\n  _stdOutMode = stdOutMode;\n  _numErrors = 0;\n  _unpTotal = 1;\n  _packTotal = packSize;\n\n  _extractCallback2 = extractCallback2;\n  _compressProgress.Release();\n  _extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);\n\n  LocalProgressSpec->Init(extractCallback2, true);\n  LocalProgressSpec->SendProgress = false;\n\n  _itemDefaultName = itemDefaultName;\n  _utcMTimeDefault = utcMTimeDefault;\n  _attributesDefault = attributesDefault;\n  _removePathParts = removePathParts;\n  _archiveHandler = archiveHandler;\n  _directoryPath = directoryPath;\n  NFile::NName::NormalizeDirPathPrefix(_directoryPath);\n}\n\nSTDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)\n{\n  COM_TRY_BEGIN\n  _unpTotal = size;\n  if (!_multiArchives && _extractCallback2)\n    return _extractCallback2->SetTotal(size);\n  return S_OK;\n  COM_TRY_END\n}\n\nstatic void NormalizeVals(UInt64 &v1, UInt64 &v2)\n{\n  const UInt64 kMax = (UInt64)1 << 31;\n  while (v1 > kMax)\n  {\n    v1 >>= 1;\n    v2 >>= 1;\n  }\n}\n\nstatic UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)\n{\n  NormalizeVals(packTotal, unpTotal);\n  NormalizeVals(unpCur, unpTotal);\n  if (unpTotal == 0)\n    unpTotal = 1;\n  return unpCur * packTotal / unpTotal;\n}\n\nSTDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)\n{\n  COM_TRY_BEGIN\n  if (!_extractCallback2)\n    return S_OK;\n\n  if (_multiArchives)\n  {\n    if (completeValue != NULL)\n    {\n      UInt64 packCur = LocalProgressSpec->InSize + MyMultDiv64(*completeValue, _unpTotal, _packTotal);\n      return _extractCallback2->SetCompleted(&packCur);\n    }\n  }\n  return _extractCallback2->SetCompleted(completeValue);\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\n{\n  COM_TRY_BEGIN\n  return _localProgress->SetRatioInfo(inSize, outSize);\n  COM_TRY_END\n}\n\nvoid CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)\n{\n  fullPath = _directoryPath;\n  for(int i = 0; i < dirPathParts.Size(); i++)\n  {\n    if (i > 0)\n      fullPath += wchar_t(NFile::NName::kDirDelimiter);\n    fullPath += dirPathParts[i];\n    NFile::NDirectory::MyCreateDirectory(fullPath);\n  }\n}\n\nstatic UString MakePathNameFromParts(const UStringVector &parts)\n{\n  UString result;\n  for(int i = 0; i < parts.Size(); i++)\n  {\n    if(i != 0)\n      result += wchar_t(NFile::NName::kDirDelimiter);\n    result += parts[i];\n  }\n  return result;\n}\n\n\nHRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)\n{\n  filetimeIsDefined = false;\n  NCOM::CPropVariant prop;\n  RINOK(_archiveHandler->GetProperty(index, propID, &prop));\n  if (prop.vt == VT_FILETIME)\n  {\n    filetime = prop.filetime;\n    filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);\n  }\n  else if (prop.vt != VT_EMPTY)\n    return E_FAIL;\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)\n{\n  COM_TRY_BEGIN\n  *outStream = 0;\n  _outFileStream.Release();\n\n  _encrypted = false;\n  _isSplit = false;\n  _curSize = 0;\n\n  UString fullPath;\n\n  RINOK(GetArchiveItemPath(_archiveHandler, index, _itemDefaultName, fullPath));\n  RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDir));\n\n  _filePath = fullPath;\n\n  {\n    NCOM::CPropVariant prop;\n    RINOK(_archiveHandler->GetProperty(index, kpidPosition, &prop));\n    if (prop.vt != VT_EMPTY)\n    {\n      if (prop.vt != VT_UI8)\n        return E_FAIL;\n      _position = prop.uhVal.QuadPart;\n      _isSplit = true;\n    }\n  }\n    \n  RINOK(IsArchiveItemProp(_archiveHandler, index, kpidEncrypted, _encrypted));\n\n  bool newFileSizeDefined;\n  UInt64 newFileSize;\n  {\n    NCOM::CPropVariant prop;\n    RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));\n    newFileSizeDefined = (prop.vt != VT_EMPTY);\n    if (newFileSizeDefined)\n    {\n      newFileSize = ConvertPropVariantToUInt64(prop);\n      _curSize = newFileSize;\n    }\n  }\n\n  if(askExtractMode == NArchive::NExtract::NAskMode::kExtract)\n  {\n    if (_stdOutMode)\n    {\n      CMyComPtr<ISequentialOutStream> outStreamLoc = new CStdOutFileStream;\n      *outStream = outStreamLoc.Detach();\n      return S_OK;\n    }\n\n    {\n      NCOM::CPropVariant prop;\n      RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));\n      if (prop.vt == VT_EMPTY)\n      {\n        _processedFileInfo.Attributes = _attributesDefault;\n        _processedFileInfo.AttributesAreDefined = false;\n      }\n      else\n      {\n        if (prop.vt != VT_UI4)\n          return E_FAIL;\n        _processedFileInfo.Attributes = prop.ulVal;\n        _processedFileInfo.AttributesAreDefined = true;\n      }\n    }\n\n    RINOK(GetTime(index, kpidCTime, _processedFileInfo.CTime, _processedFileInfo.CTimeDefined));\n    RINOK(GetTime(index, kpidATime, _processedFileInfo.ATime, _processedFileInfo.ATimeDefined));\n    RINOK(GetTime(index, kpidMTime, _processedFileInfo.MTime, _processedFileInfo.MTimeDefined));\n\n    bool isAnti = false;\n    RINOK(IsArchiveItemProp(_archiveHandler, index, kpidIsAnti, isAnti));\n\n    UStringVector pathParts;\n    SplitPathToParts(fullPath, pathParts);\n    \n    if(pathParts.IsEmpty())\n      return E_FAIL;\n    int numRemovePathParts = 0;\n    switch(_pathMode)\n    {\n      case NExtract::NPathMode::kFullPathnames:\n        break;\n      case NExtract::NPathMode::kCurrentPathnames:\n      {\n        numRemovePathParts = _removePathParts.Size();\n        if (pathParts.Size() <= numRemovePathParts)\n          return E_FAIL;\n        for (int i = 0; i < numRemovePathParts; i++)\n          if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0)\n            return E_FAIL;\n        break;\n      }\n      case NExtract::NPathMode::kNoPathnames:\n      {\n        numRemovePathParts = pathParts.Size() - 1;\n        break;\n      }\n    }\n    pathParts.Delete(0, numRemovePathParts);\n    MakeCorrectPath(pathParts);\n    UString processedPath = MakePathNameFromParts(pathParts);\n    if (!isAnti)\n    {\n      if (!_processedFileInfo.IsDir)\n      {\n        if (!pathParts.IsEmpty())\n          pathParts.DeleteBack();\n      }\n    \n      if (!pathParts.IsEmpty())\n      {\n        UString fullPathNew;\n        CreateComplexDirectory(pathParts, fullPathNew);\n        if (_processedFileInfo.IsDir)\n          NFile::NDirectory::SetDirTime(fullPathNew,\n            (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\n            (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\n            (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\n      }\n    }\n\n\n    UString fullProcessedPath = _directoryPath + processedPath;\n\n    if(_processedFileInfo.IsDir)\n    {\n      _diskFilePath = fullProcessedPath;\n      if (isAnti)\n        NFile::NDirectory::MyRemoveDirectory(_diskFilePath);\n      return S_OK;\n    }\n\n    if (!_isSplit)\n    {\n    NFile::NFind::CFileInfoW fileInfo;\n    if(NFile::NFind::FindFile(fullProcessedPath, fileInfo))\n    {\n      switch(_overwriteMode)\n      {\n        case NExtract::NOverwriteMode::kSkipExisting:\n          return S_OK;\n        case NExtract::NOverwriteMode::kAskBefore:\n        {\n          Int32 overwiteResult;\n          RINOK(_extractCallback2->AskOverwrite(\n              fullProcessedPath, &fileInfo.MTime, &fileInfo.Size, fullPath,\n              _processedFileInfo.MTimeDefined ? &_processedFileInfo.MTime : NULL,\n              newFileSizeDefined ? &newFileSize : NULL,\n              &overwiteResult))\n\n          switch(overwiteResult)\n          {\n            case NOverwriteAnswer::kCancel:\n              return E_ABORT;\n            case NOverwriteAnswer::kNo:\n              return S_OK;\n            case NOverwriteAnswer::kNoToAll:\n              _overwriteMode = NExtract::NOverwriteMode::kSkipExisting;\n              return S_OK;\n            case NOverwriteAnswer::kYesToAll:\n              _overwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;\n              break;\n            case NOverwriteAnswer::kYes:\n              break;\n            case NOverwriteAnswer::kAutoRename:\n              _overwriteMode = NExtract::NOverwriteMode::kAutoRename;\n              break;\n            default:\n              return E_FAIL;\n          }\n        }\n      }\n      if (_overwriteMode == NExtract::NOverwriteMode::kAutoRename)\n      {\n        if (!AutoRenamePath(fullProcessedPath))\n        {\n          UString message = UString(kCantAutoRename) + fullProcessedPath;\n          RINOK(_extractCallback2->MessageError(message));\n          return E_FAIL;\n        }\n      }\n      else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)\n      {\n        UString existPath = fullProcessedPath;\n        if (!AutoRenamePath(existPath))\n        {\n          UString message = kCantAutoRename + fullProcessedPath;\n          RINOK(_extractCallback2->MessageError(message));\n          return E_FAIL;\n        }\n        if(!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))\n        {\n          UString message = UString(kCantRenameFile) + fullProcessedPath;\n          RINOK(_extractCallback2->MessageError(message));\n          return E_FAIL;\n        }\n      }\n      else\n        if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))\n        {\n          UString message = UString(kCantDeleteOutputFile) +  fullProcessedPath;\n          RINOK(_extractCallback2->MessageError(message));\n          return S_OK;\n          // return E_FAIL;\n        }\n    }\n    }\n    if (!isAnti)\n    {\n      _outFileStreamSpec = new COutFileStream;\n      CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);\n      if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))\n      {\n        // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)\n        {\n          UString message = L\"can not open output file \" + fullProcessedPath;\n          RINOK(_extractCallback2->MessageError(message));\n          return S_OK;\n        }\n      }\n      if (_isSplit)\n      {\n        RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));\n      }\n      _outFileStream = outStreamLoc;\n      *outStream = outStreamLoc.Detach();\n    }\n    _diskFilePath = fullProcessedPath;\n  }\n  else\n  {\n    *outStream = NULL;\n  }\n  return S_OK;\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)\n{\n  COM_TRY_BEGIN\n  _extractMode = false;\n  switch (askExtractMode)\n  {\n    case NArchive::NExtract::NAskMode::kExtract:\n      _extractMode = true;\n  };\n  return _extractCallback2->PrepareOperation(_filePath, _processedFileInfo.IsDir,\n      askExtractMode, _isSplit ? &_position: 0);\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)\n{\n  COM_TRY_BEGIN\n  switch(operationResult)\n  {\n    case NArchive::NExtract::NOperationResult::kOK:\n    case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\n    case NArchive::NExtract::NOperationResult::kCRCError:\n    case NArchive::NExtract::NOperationResult::kDataError:\n      break;\n    default:\n      _outFileStream.Release();\n      return E_FAIL;\n  }\n  if (_outFileStream != NULL)\n  {\n    _outFileStreamSpec->SetTime(\n        (WriteCTime && _processedFileInfo.CTimeDefined) ? &_processedFileInfo.CTime : NULL,\n        (WriteATime && _processedFileInfo.ATimeDefined) ? &_processedFileInfo.ATime : NULL,\n        (WriteMTime && _processedFileInfo.MTimeDefined) ? &_processedFileInfo.MTime : &_utcMTimeDefault);\n    _curSize = _outFileStreamSpec->ProcessedSize;\n    RINOK(_outFileStreamSpec->Close());\n    _outFileStream.Release();\n  }\n  UnpackSize += _curSize;\n  if (_processedFileInfo.IsDir)\n    NumFolders++;\n  else\n    NumFiles++;\n\n  if (_extractMode && _processedFileInfo.AttributesAreDefined)\n    NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes);\n  RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));\n  return S_OK;\n  COM_TRY_END\n}\n\n/*\nSTDMETHODIMP CArchiveExtractCallback::GetInStream(\n    const wchar_t *name, ISequentialInStream **inStream)\n{\n  COM_TRY_BEGIN\n  CInFileStream *inFile = new CInFileStream;\n  CMyComPtr<ISequentialInStream> inStreamTemp = inFile;\n  if (!inFile->Open(_srcDirectoryPrefix + name))\n    return ::GetLastError();\n  *inStream = inStreamTemp.Detach();\n  return S_OK;\n  COM_TRY_END\n}\n*/\n\nSTDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)\n{\n  COM_TRY_BEGIN\n  if (!_cryptoGetTextPassword)\n  {\n    RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword,\n        &_cryptoGetTextPassword));\n  }\n  return _cryptoGetTextPassword->CryptoGetTextPassword(password);\n  COM_TRY_END\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ArchiveExtractCallback.h",
    "content": "// ArchiveExtractCallback.h\n\n#ifndef __ARCHIVEEXTRACTCALLBACK_H\n#define __ARCHIVEEXTRACTCALLBACK_H\n\n#include \"../../Archive/IArchive.h\"\n#include \"IFileExtractCallback.h\"\n\n#include \"Common/MyString.h\"\n#include \"Common/MyCom.h\"\n\n#include \"../../Common/FileStreams.h\"\n#include \"../../Common/ProgressUtils.h\"\n#include \"../../IPassword.h\"\n\n#include \"ExtractMode.h\"\n\nclass CArchiveExtractCallback:\n  public IArchiveExtractCallback,\n  // public IArchiveVolumeExtractCallback,\n  public ICryptoGetTextPassword,\n  public ICompressProgressInfo,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP2(ICryptoGetTextPassword, ICompressProgressInfo)\n  // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)\n\n  INTERFACE_IArchiveExtractCallback(;)\n\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\n\n  // IArchiveVolumeExtractCallback\n  // STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);\n\n  // ICryptoGetTextPassword\n  STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);\n\nprivate:\n  CMyComPtr<IInArchive> _archiveHandler;\n  CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;\n  CMyComPtr<ICompressProgressInfo> _compressProgress;\n  CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;\n  UString _directoryPath;\n  NExtract::NPathMode::EEnum _pathMode;\n  NExtract::NOverwriteMode::EEnum _overwriteMode;\n\n  UString _filePath;\n  UInt64 _position;\n  bool _isSplit;\n\n  UString _diskFilePath;\n\n  bool _extractMode;\n\n  bool WriteCTime;\n  bool WriteATime;\n  bool WriteMTime;\n\n  bool _encrypted;\n\n  struct CProcessedFileInfo\n  {\n    FILETIME CTime;\n    FILETIME ATime;\n    FILETIME MTime;\n    UInt32 Attributes;\n  \n    bool CTimeDefined;\n    bool ATimeDefined;\n    bool MTimeDefined;\n\n    bool IsDir;\n    bool AttributesAreDefined;\n  } _processedFileInfo;\n\n  UInt64 _curSize;\n  COutFileStream *_outFileStreamSpec;\n  CMyComPtr<ISequentialOutStream> _outFileStream;\n  UStringVector _removePathParts;\n\n  UString _itemDefaultName;\n  FILETIME _utcMTimeDefault;\n  UInt32 _attributesDefault;\n  bool _stdOutMode;\n\n  void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);\n  HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);\npublic:\n  CArchiveExtractCallback():\n      WriteCTime(true),\n      WriteATime(true),\n      WriteMTime(true),\n      _multiArchives(false)\n  {\n    LocalProgressSpec = new CLocalProgress();\n    _localProgress = LocalProgressSpec;\n  }\n\n  CLocalProgress *LocalProgressSpec;\n  CMyComPtr<ICompressProgressInfo> _localProgress;\n  UInt64 _packTotal;\n  UInt64 _unpTotal;\n\n  bool _multiArchives;\n  UInt64 NumFolders;\n  UInt64 NumFiles;\n  UInt64 UnpackSize;\n  \n  void InitForMulti(bool multiArchives,\n      NExtract::NPathMode::EEnum pathMode,\n      NExtract::NOverwriteMode::EEnum overwriteMode)\n  {\n    _multiArchives = multiArchives; NumFolders = NumFiles = UnpackSize = 0;\n    _pathMode = pathMode;\n    _overwriteMode = overwriteMode;\n  }\n\n  void Init(\n      IInArchive *archiveHandler,\n      IFolderArchiveExtractCallback *extractCallback2,\n      bool stdOutMode,\n      const UString &directoryPath,\n      const UStringVector &removePathParts,\n      const UString &itemDefaultName,\n      const FILETIME &utcMTimeDefault,\n      UInt32 attributesDefault,\n      UInt64 packSize);\n\n  UInt64 _numErrors;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ArchiveName.cpp",
    "content": "// ArchiveName.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Windows/FileFind.h\"\n#include \"Windows/FileDir.h\"\n\nusing namespace NWindows;\n\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)\n{\n  UString resultName = L\"Archive\";\n  if (fromPrev)\n  {\n    UString dirPrefix;\n    if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))\n    {\n      if (dirPrefix.Length() > 0)\n        if (dirPrefix[dirPrefix.Length() - 1] == WCHAR_PATH_SEPARATOR)\n        {\n          dirPrefix.Delete(dirPrefix.Length() - 1);\n          NFile::NFind::CFileInfoW fileInfo;\n          if (NFile::NFind::FindFile(dirPrefix, fileInfo))\n            resultName = fileInfo.Name;\n        }\n    }\n  }\n  else\n  {\n    NFile::NFind::CFileInfoW fileInfo;\n    if (!NFile::NFind::FindFile(srcName, fileInfo))\n      return resultName;\n    resultName = fileInfo.Name;\n    if (!fileInfo.IsDir() && !keepName)\n    {\n      int dotPos = resultName.ReverseFind('.');\n      if (dotPos > 0)\n      {\n        UString archiveName2 = resultName.Left(dotPos);\n        if (archiveName2.ReverseFind('.') < 0)\n          resultName = archiveName2;\n      }\n    }\n  }\n  return resultName;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ArchiveName.h",
    "content": "// ArchiveName.h\n\n#ifndef __ARCHIVENAME_H\n#define __ARCHIVENAME_H\n\n#include \"Common/MyString.h\"\n\nUString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp",
    "content": "// ArchiveOpenCallback.cpp\n\n#include \"StdAfx.h\"\n\n#include \"ArchiveOpenCallback.h\"\n\n#include \"Common/StringConvert.h\"\n#include \"Common/ComTry.h\"\n#include \"Windows/PropVariant.h\"\n\n#include \"../../Common/FileStreams.h\"\n\nusing namespace NWindows;\n\nSTDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)\n{\n  COM_TRY_BEGIN\n  if (ReOpenCallback)\n    return ReOpenCallback->SetTotal(files, bytes);\n  if (!Callback)\n    return S_OK;\n  return Callback->Open_SetTotal(files, bytes);\n  COM_TRY_END\n}\n\nSTDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)\n{\n  COM_TRY_BEGIN\n  if (ReOpenCallback)\n    return ReOpenCallback->SetCompleted(files, bytes);\n  if (!Callback)\n    return S_OK;\n  return Callback->Open_SetCompleted(files, bytes);\n  COM_TRY_END\n}\n  \nSTDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)\n{\n  COM_TRY_BEGIN\n  NCOM::CPropVariant prop;\n  if (_subArchiveMode)\n    switch(propID)\n    {\n      case kpidName: prop = _subArchiveName; break;\n    }\n  else\n    switch(propID)\n    {\n      case kpidName:  prop = _fileInfo.Name; break;\n      case kpidIsDir:  prop = _fileInfo.IsDir(); break;\n      case kpidSize:  prop = _fileInfo.Size; break;\n      case kpidAttrib:  prop = (UInt32)_fileInfo.Attrib; break;\n      case kpidCTime:  prop = _fileInfo.CTime; break;\n      case kpidATime:  prop = _fileInfo.ATime; break;\n      case kpidMTime:  prop = _fileInfo.MTime; break;\n    }\n  prop.Detach(value);\n  return S_OK;\n  COM_TRY_END\n}\n\nint COpenCallbackImp::FindName(const UString &name)\n{\n  for (int i = 0; i < FileNames.Size(); i++)\n    if (name.CompareNoCase(FileNames[i]) == 0)\n      return i;\n  return -1;\n}\n\nstruct CInFileStreamVol: public CInFileStream\n{\n  UString Name;\n  COpenCallbackImp *OpenCallbackImp;\n  CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;\n  ~CInFileStreamVol()\n  {\n    int index = OpenCallbackImp->FindName(Name);\n    if (index >= 0)\n      OpenCallbackImp->FileNames.Delete(index);\n  }\n};\n\nSTDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)\n{\n  COM_TRY_BEGIN\n  if (_subArchiveMode)\n    return S_FALSE;\n  if (Callback)\n  {\n    RINOK(Callback->Open_CheckBreak());\n  }\n  *inStream = NULL;\n  UString fullPath = _folderPrefix + name;\n  if (!NFile::NFind::FindFile(fullPath, _fileInfo))\n    return S_FALSE;\n  if (_fileInfo.IsDir())\n    return S_FALSE;\n  CInFileStreamVol *inFile = new CInFileStreamVol;\n  CMyComPtr<IInStream> inStreamTemp = inFile;\n  if (!inFile->Open(fullPath))\n    return ::GetLastError();\n  *inStream = inStreamTemp.Detach();\n  inFile->Name = name;\n  inFile->OpenCallbackImp = this;\n  inFile->OpenCallbackRef = this;\n  FileNames.Add(name);\n  TotalSize += _fileInfo.Size;\n  return S_OK;\n  COM_TRY_END\n}\n\n#ifndef _NO_CRYPTO\nSTDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)\n{\n  COM_TRY_BEGIN\n  if (ReOpenCallback)\n  {\n    CMyComPtr<ICryptoGetTextPassword> getTextPassword;\n    ReOpenCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);\n    if (getTextPassword)\n      return getTextPassword->CryptoGetTextPassword(password);\n  }\n  if (!Callback)\n    return E_NOTIMPL;\n  return Callback->Open_CryptoGetTextPassword(password);\n  COM_TRY_END\n}\n#endif\n  \n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ArchiveOpenCallback.h",
    "content": "// ArchiveOpenCallback.h\n\n#ifndef __ARCHIVE_OPEN_CALLBACK_H\n#define __ARCHIVE_OPEN_CALLBACK_H\n\n#include \"Common/MyString.h\"\n#include \"Common/MyCom.h\"\n#include \"Windows/FileFind.h\"\n\n#ifndef _NO_CRYPTO\n#include \"../../IPassword.h\"\n#endif\n#include \"../../Archive/IArchive.h\"\n\n#ifdef _NO_CRYPTO\n\n#define INTERFACE_IOpenCallbackUI_Crypto(x)\n\n#else\n\n#define INTERFACE_IOpenCallbackUI_Crypto(x) \\\n  virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x; \\\n  virtual HRESULT Open_GetPasswordIfAny(UString &password) x; \\\n  virtual bool Open_WasPasswordAsked() x; \\\n  virtual void Open_ClearPasswordWasAskedFlag() x; \\\n  \n#endif\n\n#define INTERFACE_IOpenCallbackUI(x) \\\n  virtual HRESULT Open_CheckBreak() x; \\\n  virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x; \\\n  virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) x; \\\n  INTERFACE_IOpenCallbackUI_Crypto(x)\n\nstruct IOpenCallbackUI\n{\n  INTERFACE_IOpenCallbackUI(=0)\n};\n\nclass COpenCallbackImp:\n  public IArchiveOpenCallback,\n  public IArchiveOpenVolumeCallback,\n  public IArchiveOpenSetSubArchiveName,\n  #ifndef _NO_CRYPTO\n  public ICryptoGetTextPassword,\n  #endif\n  public CMyUnknownImp\n{\npublic:\n  #ifndef _NO_CRYPTO\n  MY_UNKNOWN_IMP3(\n      IArchiveOpenVolumeCallback,\n      ICryptoGetTextPassword,\n      IArchiveOpenSetSubArchiveName\n      )\n  #else\n  MY_UNKNOWN_IMP2(\n      IArchiveOpenVolumeCallback,\n      IArchiveOpenSetSubArchiveName\n      )\n  #endif\n\n  INTERFACE_IArchiveOpenCallback(;)\n  INTERFACE_IArchiveOpenVolumeCallback(;)\n\n  #ifndef _NO_CRYPTO\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\n  #endif\n\n  STDMETHOD(SetSubArchiveName(const wchar_t *name))\n  {\n    _subArchiveMode = true;\n    _subArchiveName = name;\n    return  S_OK;\n  }\n\nprivate:\n  UString _folderPrefix;\n  NWindows::NFile::NFind::CFileInfoW _fileInfo;\n  bool _subArchiveMode;\n  UString _subArchiveName;\npublic:\n  UStringVector FileNames;\n  IOpenCallbackUI *Callback;\n  CMyComPtr<IArchiveOpenCallback> ReOpenCallback;\n  UInt64 TotalSize;\n\n  COpenCallbackImp(): Callback(NULL) {}\n  void Init(const UString &folderPrefix,  const UString &fileName)\n  {\n    _folderPrefix = folderPrefix;\n    if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))\n      throw 1;\n    FileNames.Clear();\n    _subArchiveMode = false;\n    TotalSize = 0;\n  }\n  int FindName(const UString &name);\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/DefaultName.cpp",
    "content": "// DefaultName.cpp\n\n#include \"StdAfx.h\"\n\n#include \"DefaultName.h\"\n\nstatic UString GetDefaultName3(const UString &fileName,\n    const UString &extension, const UString &addSubExtension)\n{\n  int extLength = extension.Length();\n  int fileNameLength = fileName.Length();\n  if (fileNameLength > extLength + 1)\n  {\n    int dotPos = fileNameLength - (extLength + 1);\n    if (fileName[dotPos] == '.')\n      if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)\n        return fileName.Left(dotPos) + addSubExtension;\n  }\n  int dotPos = fileName.ReverseFind(L'.');\n  if (dotPos > 0)\n    return fileName.Left(dotPos) + addSubExtension;\n\n  if (addSubExtension.IsEmpty())\n    return fileName + L\"~\";\n  else\n    return fileName + addSubExtension;\n}\n\nUString GetDefaultName2(const UString &fileName,\n    const UString &extension, const UString &addSubExtension)\n{\n  UString name = GetDefaultName3(fileName, extension, addSubExtension);\n  name.TrimRight();\n  return name;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/DefaultName.h",
    "content": "// DefaultName.h\n\n#ifndef __DEFAULTNAME_H\n#define __DEFAULTNAME_H\n\n#include \"Common/MyString.h\"\n\nUString GetDefaultName2(const UString &fileName,\n    const UString &extension, const UString &addSubExtension);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/DirItem.h",
    "content": "// DirItem.h\n\n#ifndef __DIR_ITEM_H\n#define __DIR_ITEM_H\n\n#include \"Common/MyString.h\"\n#include \"Common/Types.h\"\n#include \"../../Archive/IArchive.h\"\n\nstruct CDirItem\n{\n  UInt64 Size;\n  FILETIME CTime;\n  FILETIME ATime;\n  FILETIME MTime;\n  UString Name;\n  UInt32 Attrib;\n  int PhyParent;\n  int LogParent;\n  \n  CDirItem(): PhyParent(-1), LogParent(-1) {}\n  bool IsDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }\n};\n\nclass CDirItems\n{\n  UStringVector Prefixes;\n  CIntVector PhyParents;\n  CIntVector LogParents;\n\n  UString GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const;\npublic:\n  CObjectVector<CDirItem> Items;\n\n  int GetNumFolders() const { return Prefixes.Size(); }\n  UString GetPhyPath(int index) const;\n  UString GetLogPath(int index) const;\n\n  int AddPrefix(int phyParent, int logParent, const UString &prefix);\n  void DeleteLastPrefix();\n\n  void EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\n\n  void EnumerateDirItems2(\n    const UString &phyPrefix,\n    const UString &logPrefix,\n    const UStringVector &filePaths,\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);\n\n  void ReserveDown();\n};\n\nstruct CArcItem\n{\n  UInt64 Size;\n  FILETIME MTime;\n  UString Name;\n  bool IsDir;\n  bool SizeDefined;\n  bool Censored;\n  UInt32 IndexInServer;\n  int TimeType;\n  \n  CArcItem(): IsDir(false), SizeDefined(false), Censored(false), TimeType(-1) {}\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/EnumDirItems.cpp",
    "content": "// EnumDirItems.cpp\n\n#include \"StdAfx.h\"\n\n#include <stdio.h>\n\n#include \"Common/StringConvert.h\"\n#include \"Common/Wildcard.h\"\n#include \"Common/MyCom.h\"\n\n#include \"EnumDirItems.h\"\n\nusing namespace NWindows;\nusing namespace NFile;\nusing namespace NName;\n\nvoid AddDirFileInfo(int phyParent, int logParent,\n    const NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems)\n{\n  CDirItem di;\n  di.Size = fi.Size;\n  di.CTime = fi.CTime;\n  di.ATime = fi.ATime;\n  di.MTime = fi.MTime;\n  di.Attrib = fi.Attrib;\n  di.PhyParent = phyParent;\n  di.LogParent = logParent;\n  di.Name = fi.Name;\n  dirItems.Add(di);\n}\n\nUString CDirItems::GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const\n{\n  UString path;\n  int len = name.Length();\n  int i;\n  for (i = index; i >= 0; i = parents[i])\n    len += Prefixes[i].Length();\n  int totalLen = len;\n  wchar_t *p = path.GetBuffer(len);\n  p[len] = 0;\n  len -= name.Length();\n  memcpy(p + len, (const wchar_t *)name, name.Length() * sizeof(wchar_t));\n  for (i = index; i >= 0; i = parents[i])\n  {\n    const UString &s = Prefixes[i];\n    len -= s.Length();\n    memcpy(p + len, (const wchar_t *)s, s.Length() * sizeof(wchar_t));\n  }\n  path.ReleaseBuffer(totalLen);\n  return path;\n}\n\nUString CDirItems::GetPhyPath(int index) const\n{\n  const CDirItem &di = Items[index];\n  return GetPrefixesPath(PhyParents, di.PhyParent, di.Name);\n}\n\nUString CDirItems::GetLogPath(int index) const\n{\n  const CDirItem &di = Items[index];\n  return GetPrefixesPath(LogParents, di.LogParent, di.Name);\n}\n\nvoid CDirItems::ReserveDown()\n{\n  Prefixes.ReserveDown();\n  PhyParents.ReserveDown();\n  LogParents.ReserveDown();\n  Items.ReserveDown();\n}\n\nint CDirItems::AddPrefix(int phyParent, int logParent, const UString &prefix)\n{\n  PhyParents.Add(phyParent);\n  LogParents.Add(logParent);\n  return Prefixes.Add(prefix);\n}\n\nvoid CDirItems::DeleteLastPrefix()\n{\n  PhyParents.DeleteBack();\n  LogParents.DeleteBack();\n  Prefixes.DeleteBack();\n}\n\nvoid CDirItems::EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,\n    UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\n{\n  NFind::CEnumeratorW enumerator(phyPrefix + (wchar_t)kAnyStringWildcard);\n  for (;;)\n  {\n    NFind::CFileInfoW fi;\n    bool found;\n    if (!enumerator.Next(fi, found))\n    {\n      errorCodes.Add(::GetLastError());\n      errorPaths.Add(phyPrefix);\n      return;\n    }\n    if (!found)\n      break;\n    AddDirFileInfo(phyParent, logParent, fi, Items);\n    if (fi.IsDir())\n    {\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\n      int parent = AddPrefix(phyParent, logParent, name2);\n      EnumerateDirectory(parent, parent, phyPrefix + name2, errorPaths, errorCodes);\n    }\n  }\n}\n\nvoid CDirItems::EnumerateDirItems2(const UString &phyPrefix, const UString &logPrefix,\n    const UStringVector &filePaths, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)\n{\n  int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, phyPrefix);\n  int logParent = logPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, logPrefix);\n\n  for (int i = 0; i < filePaths.Size(); i++)\n  {\n    const UString &filePath = filePaths[i];\n    NFind::CFileInfoW fi;\n    const UString phyPath = phyPrefix + filePath;\n    if (!NFind::FindFile(phyPath, fi))\n    {\n      errorCodes.Add(::GetLastError());\n      errorPaths.Add(phyPath);\n      continue;\n    }\n    int delimiter = filePath.ReverseFind((wchar_t)kDirDelimiter);\n    UString phyPrefixCur;\n    int phyParentCur = phyParent;\n    if (delimiter >= 0)\n    {\n      phyPrefixCur = filePath.Left(delimiter + 1);\n      phyParentCur = AddPrefix(phyParent, logParent, phyPrefixCur);\n    }\n    AddDirFileInfo(phyParentCur, logParent, fi, Items);\n    if (fi.IsDir())\n    {\n      const UString name2 = fi.Name + (wchar_t)kDirDelimiter;\n      int parent = AddPrefix(phyParentCur, logParent, name2);\n      EnumerateDirectory(parent, parent, phyPrefix + phyPrefixCur + name2, errorPaths, errorCodes);\n    }\n  }\n  ReserveDown();\n}\n\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\n    int phyParent, int logParent, const UString &phyPrefix,\n    const UStringVector &addArchivePrefix,\n    CDirItems &dirItems,\n    bool enterToSubFolders,\n    IEnumDirItemCallback *callback,\n    UStringVector &errorPaths,\n    CRecordVector<DWORD> &errorCodes);\n\nstatic HRESULT EnumerateDirItems_Spec(const NWildcard::CCensorNode &curNode,\n    int phyParent, int logParent, const UString &curFolderName,\n    const UString &phyPrefix,\n    const UStringVector &addArchivePrefix,\n    CDirItems &dirItems,\n    bool enterToSubFolders,\n    IEnumDirItemCallback *callback,\n    UStringVector &errorPaths,\n    CRecordVector<DWORD> &errorCodes)\n  \n{\n  const UString name2 = curFolderName + (wchar_t)kDirDelimiter;\n  int parent = dirItems.AddPrefix(phyParent, logParent, name2);\n  int numItems = dirItems.Items.Size();\n  HRESULT res = EnumerateDirItems(curNode, parent, parent, phyPrefix + name2,\n    addArchivePrefix, dirItems, enterToSubFolders, callback, errorPaths, errorCodes);\n  if (numItems == dirItems.Items.Size())\n    dirItems.DeleteLastPrefix();\n  return res;\n}\n\n\nstatic HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,\n    int phyParent, int logParent, const UString &phyPrefix,\n    const UStringVector &addArchivePrefix,  // prefix from curNode\n    CDirItems &dirItems,\n    bool enterToSubFolders,\n    IEnumDirItemCallback *callback,\n    UStringVector &errorPaths,\n    CRecordVector<DWORD> &errorCodes)\n{\n  if (!enterToSubFolders)\n    if (curNode.NeedCheckSubDirs())\n      enterToSubFolders = true;\n  if (callback)\n    RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\n\n  // try direct_names case at first\n  if (addArchivePrefix.IsEmpty() && !enterToSubFolders)\n  {\n    // check that all names are direct\n    int i;\n    for (i = 0; i < curNode.IncludeItems.Size(); i++)\n    {\n      const NWildcard::CItem &item = curNode.IncludeItems[i];\n      if (item.Recursive || item.PathParts.Size() != 1)\n        break;\n      const UString &name = item.PathParts.Front();\n      if (name.IsEmpty() || DoesNameContainWildCard(name))\n        break;\n    }\n    if (i == curNode.IncludeItems.Size())\n    {\n      // all names are direct (no wildcards)\n      // so we don't need file_system's dir enumerator\n      CRecordVector<bool> needEnterVector;\n      for (i = 0; i < curNode.IncludeItems.Size(); i++)\n      {\n        const NWildcard::CItem &item = curNode.IncludeItems[i];\n        const UString &name = item.PathParts.Front();\n        const UString fullPath = phyPrefix + name;\n        NFind::CFileInfoW fi;\n        if (!NFind::FindFile(fullPath, fi))\n        {\n          errorCodes.Add(::GetLastError());\n          errorPaths.Add(fullPath);\n          continue;\n        }\n        bool isDir = fi.IsDir();\n        if (isDir && !item.ForDir || !isDir && !item.ForFile)\n        {\n          errorCodes.Add((DWORD)E_FAIL);\n          errorPaths.Add(fullPath);\n          continue;\n        }\n        {\n          UStringVector pathParts;\n          pathParts.Add(fi.Name);\n          if (curNode.CheckPathToRoot(false, pathParts, !isDir))\n            continue;\n        }\n        AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\n        if (!isDir)\n          continue;\n        \n        UStringVector addArchivePrefixNew;\n        const NWildcard::CCensorNode *nextNode = 0;\n        int index = curNode.FindSubNode(name);\n        if (index >= 0)\n        {\n          for (int t = needEnterVector.Size(); t <= index; t++)\n            needEnterVector.Add(true);\n          needEnterVector[index] = false;\n          nextNode = &curNode.SubNodes[index];\n        }\n        else\n        {\n          nextNode = &curNode;\n          addArchivePrefixNew.Add(name); // don't change it to fi.Name. It's for shortnames support\n        }\n\n        RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix,\n            addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes));\n      }\n      for (i = 0; i < curNode.SubNodes.Size(); i++)\n      {\n        if (i < needEnterVector.Size())\n          if (!needEnterVector[i])\n            continue;\n        const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];\n        const UString fullPath = phyPrefix + nextNode.Name;\n        NFind::CFileInfoW fi;\n        if (!NFind::FindFile(fullPath, fi))\n        {\n          if (!nextNode.AreThereIncludeItems())\n            continue;\n          errorCodes.Add(::GetLastError());\n          errorPaths.Add(fullPath);\n          continue;\n        }\n        if (!fi.IsDir())\n        {\n          errorCodes.Add((DWORD)E_FAIL);\n          errorPaths.Add(fullPath);\n          continue;\n        }\n\n        RINOK(EnumerateDirItems_Spec(nextNode, phyParent, logParent, fi.Name, phyPrefix,\n            UStringVector(), dirItems, false, callback, errorPaths, errorCodes));\n      }\n      return S_OK;\n    }\n  }\n\n\n  NFind::CEnumeratorW enumerator(phyPrefix + wchar_t(kAnyStringWildcard));\n  for (int ttt = 0; ; ttt++)\n  {\n    NFind::CFileInfoW fi;\n    bool found;\n    if (!enumerator.Next(fi, found))\n    {\n      errorCodes.Add(::GetLastError());\n      errorPaths.Add(phyPrefix);\n      break;\n    }\n    if (!found)\n      break;\n\n    if (callback && (ttt & 0xFF) == 0xFF)\n      RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));\n    const UString &name = fi.Name;\n    bool enterToSubFolders2 = enterToSubFolders;\n    UStringVector addArchivePrefixNew = addArchivePrefix;\n    addArchivePrefixNew.Add(name);\n    {\n      UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);\n      if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fi.IsDir()))\n        continue;\n    }\n    if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir()))\n    {\n      AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);\n      if (fi.IsDir())\n        enterToSubFolders2 = true;\n    }\n    if (!fi.IsDir())\n      continue;\n\n    const NWildcard::CCensorNode *nextNode = 0;\n    if (addArchivePrefix.IsEmpty())\n    {\n      int index = curNode.FindSubNode(name);\n      if (index >= 0)\n        nextNode = &curNode.SubNodes[index];\n    }\n    if (!enterToSubFolders2 && nextNode == 0)\n      continue;\n\n    addArchivePrefixNew = addArchivePrefix;\n    if (nextNode == 0)\n    {\n      nextNode = &curNode;\n      addArchivePrefixNew.Add(name);\n    }\n\n    RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, name, phyPrefix,\n        addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));\n  }\n  return S_OK;\n}\n\nHRESULT EnumerateItems(\n    const NWildcard::CCensor &censor,\n    CDirItems &dirItems,\n    IEnumDirItemCallback *callback,\n    UStringVector &errorPaths,\n    CRecordVector<DWORD> &errorCodes)\n{\n  for (int i = 0; i < censor.Pairs.Size(); i++)\n  {\n    const NWildcard::CPair &pair = censor.Pairs[i];\n    int phyParent = pair.Prefix.IsEmpty() ? -1 : dirItems.AddPrefix(-1, -1, pair.Prefix);\n    RINOK(EnumerateDirItems(pair.Head, phyParent, -1, pair.Prefix, UStringVector(), dirItems, false,\n        callback, errorPaths, errorCodes));\n  }\n  dirItems.ReserveDown();\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/EnumDirItems.h",
    "content": "// EnumDirItems.h\n\n#ifndef __ENUM_DIR_ITEMS_H\n#define __ENUM_DIR_ITEMS_H\n\n#include \"Common/Wildcard.h\"\n#include \"Windows/FileFind.h\"\n#include \"DirItem.h\"\n\nvoid AddDirFileInfo(int phyParent, int logParent,\n    const NWindows::NFile::NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems);\n\nstruct IEnumDirItemCallback\n{\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) = 0;\n};\n\nHRESULT EnumerateItems(\n    const NWildcard::CCensor &censor,\n    CDirItems &dirItems,\n    IEnumDirItemCallback *callback,\n    UStringVector &errorPaths,\n    CRecordVector<DWORD> &errorCodes);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ExitCode.h",
    "content": "// ExitCode.h\n\n#ifndef __EXIT_CODE_H\n#define __EXIT_CODE_H\n\nnamespace NExitCode {\n\nenum EEnum {\n\n  kSuccess       = 0,     // Successful operation\n  kWarning       = 1,     // Non fatal error(s) occurred\n  kFatalError    = 2,     // A fatal error occurred\n  // kCRCError      = 3,     // A CRC error occurred when unpacking\n  // kLockedArchive = 4,     // Attempt to modify an archive previously locked\n  // kWriteError    = 5,     // Write to disk error\n  // kOpenError     = 6,     // Open file error\n  kUserError     = 7,     // Command line option error\n  kMemoryError   = 8,     // Not enough memory for operation\n  // kCreateFileError = 9,     // Create file error\n  \n  kUserBreak     = 255   // User stopped the process\n\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/Extract.cpp",
    "content": "// Extract.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Extract.h\"\n\n#include \"Windows/Defs.h\"\n#include \"Windows/FileDir.h\"\n\n#include \"OpenArchive.h\"\n#include \"SetProperties.h\"\n\nusing namespace NWindows;\n\nstatic HRESULT DecompressArchive(\n    IInArchive *archive,\n    UInt64 packSize,\n    const NWildcard::CCensorNode &wildcardCensor,\n    const CExtractOptions &options,\n    IExtractCallbackUI *callback,\n    CArchiveExtractCallback *extractCallbackSpec,\n    UString &errorMessage)\n{\n  CRecordVector<UInt32> realIndices;\n  UInt32 numItems;\n  RINOK(archive->GetNumberOfItems(&numItems));\n\n  for(UInt32 i = 0; i < numItems; i++)\n  {\n    UString filePath;\n    RINOK(GetArchiveItemPath(archive, i, options.DefaultItemName, filePath));\n    bool isFolder;\n    RINOK(IsArchiveItemFolder(archive, i, isFolder));\n    if (!wildcardCensor.CheckPath(filePath, !isFolder))\n      continue;\n    realIndices.Add(i);\n  }\n  if (realIndices.Size() == 0)\n  {\n    callback->ThereAreNoFiles();\n    return S_OK;\n  }\n\n  UStringVector removePathParts;\n\n  UString outDir = options.OutputDir;\n  outDir.Replace(L\"*\", options.DefaultItemName);\n  #ifdef _WIN32\n  outDir.TrimRight();\n  #endif\n\n  if(!outDir.IsEmpty())\n    if(!NFile::NDirectory::CreateComplexDirectory(outDir))\n    {\n      HRESULT res = ::GetLastError();\n      if (res == S_OK)\n        res = E_FAIL;\n      errorMessage = ((UString)L\"Can not create output directory \") + outDir;\n      return res;\n    }\n\n  extractCallbackSpec->Init(\n      archive,\n      callback,\n      options.StdOutMode,\n      outDir,\n      removePathParts,\n      options.DefaultItemName,\n      options.ArchiveFileInfo.MTime,\n      options.ArchiveFileInfo.Attrib,\n      packSize);\n\n  #ifdef COMPRESS_MT\n  RINOK(SetProperties(archive, options.Properties));\n  #endif\n\n  HRESULT result = archive->Extract(&realIndices.Front(),\n    realIndices.Size(), options.TestMode? 1: 0, extractCallbackSpec);\n\n  return callback->ExtractResult(result);\n}\n\nHRESULT DecompressArchives(\n    CCodecs *codecs, const CIntVector &formatIndices,\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\n    const NWildcard::CCensorNode &wildcardCensor,\n    const CExtractOptions &optionsSpec,\n    IOpenCallbackUI *openCallback,\n    IExtractCallbackUI *extractCallback,\n    UString &errorMessage,\n    CDecompressStat &stat)\n{\n  stat.Clear();\n  CExtractOptions options = optionsSpec;\n  int i;\n  UInt64 totalPackSize = 0;\n  CRecordVector<UInt64> archiveSizes;\n  for (i = 0; i < archivePaths.Size(); i++)\n  {\n    const UString &archivePath = archivePaths[i];\n    NFile::NFind::CFileInfoW fi;\n    if (!NFile::NFind::FindFile(archivePath, fi))\n      throw \"there is no such archive\";\n    if (fi.IsDir())\n      throw \"can't decompress folder\";\n    archiveSizes.Add(fi.Size);\n    totalPackSize += fi.Size;\n  }\n  CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;\n  CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);\n  bool multi = (archivePaths.Size() > 1);\n  extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);\n  if (multi)\n  {\n    RINOK(extractCallback->SetTotal(totalPackSize));\n  }\n  for (i = 0; i < archivePaths.Size(); i++)\n  {\n    const UString &archivePath = archivePaths[i];\n    NFile::NFind::CFileInfoW fi;\n    if (!NFile::NFind::FindFile(archivePath, fi))\n      throw \"there is no such archive\";\n\n    if (fi.IsDir())\n      throw \"there is no such archive\";\n\n    options.ArchiveFileInfo = fi;\n\n    #ifndef _NO_CRYPTO\n    openCallback->Open_ClearPasswordWasAskedFlag();\n    #endif\n\n    RINOK(extractCallback->BeforeOpen(archivePath));\n    CArchiveLink archiveLink;\n\n    CIntVector formatIndices2 = formatIndices;\n    #ifndef _SFX\n    if (formatIndices.IsEmpty())\n    {\n      int pos = archivePath.ReverseFind(L'.');\n      if (pos >= 0)\n      {\n        UString s = archivePath.Mid(pos + 1);\n        int index = codecs->FindFormatForExtension(s);\n        if (index >= 0 && s == L\"001\")\n        {\n          s = archivePath.Left(pos);\n          pos = s.ReverseFind(L'.');\n          if (pos >= 0)\n          {\n            int index2 = codecs->FindFormatForExtension(s.Mid(pos + 1));\n            if (index2 >= 0 && s.CompareNoCase(L\"rar\") != 0)\n            {\n              formatIndices2.Add(index2);\n              formatIndices2.Add(index);\n            }\n          }\n        }\n      }\n    }\n    #endif\n    HRESULT result = MyOpenArchive(codecs, formatIndices2, archivePath, archiveLink, openCallback);\n    if (result == E_ABORT)\n      return result;\n\n    bool crypted = false;\n    #ifndef _NO_CRYPTO\n    crypted = openCallback->Open_WasPasswordAsked();\n    #endif\n\n    RINOK(extractCallback->OpenResult(archivePath, result, crypted));\n    if (result != S_OK)\n      continue;\n\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\n    {\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\n      if (index >= 0 && index > i)\n      {\n        archivePaths.Delete(index);\n        archivePathsFull.Delete(index);\n        totalPackSize -= archiveSizes[index];\n        archiveSizes.Delete(index);\n      }\n    }\n    if (archiveLink.VolumePaths.Size() != 0)\n    {\n      totalPackSize += archiveLink.VolumesSize;\n      RINOK(extractCallback->SetTotal(totalPackSize));\n    }\n\n    #ifndef _NO_CRYPTO\n    UString password;\n    RINOK(openCallback->Open_GetPasswordIfAny(password));\n    if (!password.IsEmpty())\n    {\n      RINOK(extractCallback->SetPassword(password));\n    }\n    #endif\n\n    options.DefaultItemName = archiveLink.GetDefaultItemName();\n    RINOK(DecompressArchive(\n        archiveLink.GetArchive(),\n        fi.Size + archiveLink.VolumesSize,\n        wildcardCensor, options, extractCallback, extractCallbackSpec, errorMessage));\n    extractCallbackSpec->LocalProgressSpec->InSize += fi.Size +\n        archiveLink.VolumesSize;\n    extractCallbackSpec->LocalProgressSpec->OutSize = extractCallbackSpec->UnpackSize;\n    if (!errorMessage.IsEmpty())\n      return E_FAIL;\n  }\n  stat.NumFolders = extractCallbackSpec->NumFolders;\n  stat.NumFiles = extractCallbackSpec->NumFiles;\n  stat.UnpackSize = extractCallbackSpec->UnpackSize;\n  stat.NumArchives = archivePaths.Size();\n  stat.PackSize = extractCallbackSpec->LocalProgressSpec->InSize;\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/Extract.h",
    "content": "// Extract.h\n\n#ifndef __EXTRACT_H\n#define __EXTRACT_H\n\n#include \"Common/Wildcard.h\"\n#include \"Windows/FileFind.h\"\n\n#include \"../../Archive/IArchive.h\"\n\n#include \"ArchiveExtractCallback.h\"\n#include \"ArchiveOpenCallback.h\"\n#include \"ExtractMode.h\"\n#include \"Property.h\"\n\n#include \"../Common/LoadCodecs.h\"\n\nclass CExtractOptions\n{\npublic:\n  bool StdOutMode;\n  bool TestMode;\n  NExtract::NPathMode::EEnum PathMode;\n\n  UString OutputDir;\n  bool YesToAll;\n  UString DefaultItemName;\n  NWindows::NFile::NFind::CFileInfoW ArchiveFileInfo;\n  \n  // bool ShowDialog;\n  // bool PasswordEnabled;\n  // UString Password;\n  #ifdef COMPRESS_MT\n  CObjectVector<CProperty> Properties;\n  #endif\n\n  NExtract::NOverwriteMode::EEnum OverwriteMode;\n\n  #ifdef EXTERNAL_CODECS\n  CCodecs *Codecs;\n  #endif\n\n  CExtractOptions():\n      StdOutMode(false),\n      YesToAll(false),\n      TestMode(false),\n      PathMode(NExtract::NPathMode::kFullPathnames),\n      OverwriteMode(NExtract::NOverwriteMode::kAskBefore)\n      {}\n\n  /*\n    bool FullPathMode() const { return (ExtractMode == NExtractMode::kTest) ||\n    (ExtractMode == NExtractMode::kFullPath); }\n  */\n};\n\nstruct CDecompressStat\n{\n  UInt64 NumArchives;\n  UInt64 UnpackSize;\n  UInt64 PackSize;\n  UInt64 NumFolders;\n  UInt64 NumFiles;\n  void Clear() { NumArchives = PackSize = UnpackSize = NumFolders = NumFiles = 0; }\n};\n\nHRESULT DecompressArchives(\n    CCodecs *codecs, const CIntVector &formatIndices,\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\n    const NWildcard::CCensorNode &wildcardCensor,\n    const CExtractOptions &options,\n    IOpenCallbackUI *openCallback,\n    IExtractCallbackUI *extractCallback,\n    UString &errorMessage,\n    CDecompressStat &stat);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ExtractMode.h",
    "content": "// ExtractMode.h\n\n#ifndef __EXTRACT_MODE_H\n#define __EXTRACT_MODE_H\n\nnamespace NExtract {\n  \n  namespace NPathMode\n  {\n    enum EEnum\n    {\n      kFullPathnames,\n      kCurrentPathnames,\n      kNoPathnames\n    };\n  }\n  \n  namespace NOverwriteMode\n  {\n    enum EEnum\n    {\n      kAskBefore,\n      kWithoutPrompt,\n      kSkipExisting,\n      kAutoRename,\n      kAutoRenameExisting\n    };\n  }\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ExtractingFilePath.cpp",
    "content": "// ExtractingFilePath.cpp\n\n#include \"StdAfx.h\"\n#include \"ExtractingFilePath.h\"\n\nstatic UString ReplaceIncorrectChars(const UString &s)\n{\n  #ifdef _WIN32\n  UString res;\n  for (int i = 0; i < s.Length(); i++)\n  {\n    wchar_t c = s[i];\n    if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>'  || c == '|' || c == ':' || c == '\"')\n      c = '_';\n    res += c;\n  }\n  res.TrimRight();\n  return res;\n  #else\n  return s;\n  #endif\n}\n\n#ifdef _WIN32\nstatic const wchar_t *g_ReservedNames[] =\n{\n  L\"CON\", L\"PRN\", L\"AUX\", L\"NUL\"\n};\n\nstatic bool CheckTail(const UString &name, int len)\n{\n  int dotPos = name.Find(L'.');\n  if (dotPos < 0)\n    dotPos = name.Length();\n  UString s = name.Left(dotPos);\n  s.TrimRight();\n  return (s.Length() != len);\n}\n\nstatic bool CheckNameNum(const UString &name, const wchar_t *reservedName)\n{\n  int len = MyStringLen(reservedName);\n  if (name.Length() <= len)\n    return true;\n  if (name.Left(len).CompareNoCase(reservedName) != 0)\n    return true;\n  wchar_t c = name[len];\n  if (c < L'0' || c > L'9')\n    return true;\n  return CheckTail(name, len + 1);\n}\n\nstatic bool IsSupportedName(const UString &name)\n{\n  for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++)\n  {\n    const wchar_t *reservedName = g_ReservedNames[i];\n    int len = MyStringLen(reservedName);\n    if (name.Length() < len)\n      continue;\n    if (name.Left(len).CompareNoCase(reservedName) != 0)\n      continue;\n    if (!CheckTail(name, len))\n      return false;\n  }\n  if (!CheckNameNum(name, L\"COM\"))\n    return false;\n  return CheckNameNum(name, L\"LPT\");\n}\n#endif\n\nstatic UString GetCorrectFileName(const UString &path)\n{\n  if (path == L\"..\" || path == L\".\")\n    return UString();\n  return ReplaceIncorrectChars(path);\n}\n\nvoid MakeCorrectPath(UStringVector &pathParts)\n{\n  for (int i = 0; i < pathParts.Size();)\n  {\n    UString &s = pathParts[i];\n    s = GetCorrectFileName(s);\n    if (s.IsEmpty())\n      pathParts.Delete(i);\n    else\n    {\n      #ifdef _WIN32\n      if (!IsSupportedName(s))\n        s = (UString)L\"_\" + s;\n      #endif\n      i++;\n    }\n  }\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ExtractingFilePath.h",
    "content": "// ExtractingFilePath.h\n\n#ifndef __EXTRACTINGFILEPATH_H\n#define __EXTRACTINGFILEPATH_H\n\n#include \"Common/MyString.h\"\n\nvoid MakeCorrectPath(UStringVector &pathParts);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/IFileExtractCallback.h",
    "content": "// IFileExtractCallback.h\n\n#ifndef __IFILEEXTRACTCALLBACK_H\n#define __IFILEEXTRACTCALLBACK_H\n\n#include \"Common/MyString.h\"\n#include \"../../IDecl.h\"\n\nnamespace NOverwriteAnswer\n{\n  enum EEnum\n  {\n    kYes,\n    kYesToAll,\n    kNo,\n    kNoToAll,\n    kAutoRename,\n    kCancel\n  };\n}\n\nDECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)\n{\npublic:\n  STDMETHOD(AskOverwrite)(\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\n      Int32 *answer) PURE;\n  STDMETHOD(PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position) PURE;\n  STDMETHOD(MessageError)(const wchar_t *message) PURE;\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE;\n};\n\nstruct IExtractCallbackUI: IFolderArchiveExtractCallback\n{\n  virtual HRESULT BeforeOpen(const wchar_t *name) = 0;\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted) = 0;\n  virtual HRESULT ThereAreNoFiles() = 0;\n  virtual HRESULT ExtractResult(HRESULT result) = 0;\n\n  #ifndef _NO_CRYPTO\n  virtual HRESULT SetPassword(const UString &password) = 0;\n  #endif\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/LoadCodecs.cpp",
    "content": "// LoadCodecs.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LoadCodecs.h\"\n\n#include \"../../../Common/MyCom.h\"\n#ifdef NEW_FOLDER_INTERFACE\n#include \"../../../Common/StringToInt.h\"\n#endif\n#include \"../../../Windows/PropVariant.h\"\n\n#include \"../../ICoder.h\"\n#include \"../../Common/RegisterArc.h\"\n\n#ifdef EXTERNAL_CODECS\n#include \"../../../Windows/FileFind.h\"\n#include \"../../../Windows/DLL.h\"\n#ifdef NEW_FOLDER_INTERFACE\n#include \"../../../Windows/ResourceString.h\"\nstatic const UINT kIconTypesResId = 100;\n#endif\n\n#ifdef _WIN32\n#include \"Windows/Registry.h\"\n#endif\n\nusing namespace NWindows;\nusing namespace NFile;\n\n#ifdef _WIN32\nextern HINSTANCE g_hInstance;\n#endif\n\nstatic CSysString GetLibraryFolderPrefix()\n{\n  #ifdef _WIN32\n  TCHAR fullPath[MAX_PATH + 1];\n  ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);\n  CSysString path = fullPath;\n  int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\n  return path.Left(pos + 1);\n  #else\n  return CSysString(); // FIX IT\n  #endif\n}\n\n#define kCodecsFolderName TEXT(\"Codecs\")\n#define kFormatsFolderName TEXT(\"Formats\")\nstatic const TCHAR *kMainDll = TEXT(\"7z.dll\");\n\n#ifdef _WIN32\nstatic LPCTSTR kRegistryPath = TEXT(\"Software\") TEXT(STRING_PATH_SEPARATOR) TEXT(\"7-zip\");\nstatic LPCTSTR kProgramPathValue = TEXT(\"Path\");\nstatic bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)\n{\n  NRegistry::CKey key;\n  if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)\n    if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)\n    {\n      NName::NormalizeDirPathPrefix(path);\n      return true;\n    }\n  return false;\n}\n\n#endif\n\nCSysString GetBaseFolderPrefixFromRegistry()\n{\n  CSysString moduleFolderPrefix = GetLibraryFolderPrefix();\n  NFind::CFileInfo fi;\n  if (NFind::FindFile(moduleFolderPrefix + kMainDll, fi))\n    if (!fi.IsDir())\n      return moduleFolderPrefix;\n  if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fi))\n    if (fi.IsDir())\n      return moduleFolderPrefix;\n  if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fi))\n    if (fi.IsDir())\n      return moduleFolderPrefix;\n  #ifdef _WIN32\n  CSysString path;\n  if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))\n    return path;\n  if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))\n    return path;\n  #endif\n  return moduleFolderPrefix;\n}\n\ntypedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);\ntypedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats);\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);\ntypedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PROPVARIANT *value);\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, void **outObject);\ntypedef UInt32 (WINAPI *SetLargePageModeFunc)();\n\n\nstatic HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 index,\n    PROPID propId, CLSID &clsId, bool &isAssigned)\n{\n  NWindows::NCOM::CPropVariant prop;\n  isAssigned = false;\n  RINOK(getMethodProperty(index, propId, &prop));\n  if (prop.vt == VT_BSTR)\n  {\n    isAssigned = true;\n    clsId = *(const GUID *)prop.bstrVal;\n  }\n  else if (prop.vt != VT_EMPTY)\n    return E_FAIL;\n  return S_OK;\n}\n\nHRESULT CCodecs::LoadCodecs()\n{\n  CCodecLib &lib = Libs.Back();\n  lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress(\"GetMethodProperty\");\n  if (lib.GetMethodProperty == NULL)\n    return S_OK;\n\n  UInt32 numMethods = 1;\n  GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProcAddress(\"GetNumberOfMethods\");\n  if (getNumberOfMethodsFunc != NULL)\n  {\n    RINOK(getNumberOfMethodsFunc(&numMethods));\n  }\n\n  for(UInt32 i = 0; i < numMethods; i++)\n  {\n    CDllCodecInfo info;\n    info.LibIndex = Libs.Size() - 1;\n    info.CodecIndex = i;\n\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));\n    RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));\n\n    Codecs.Add(info);\n  }\n  return S_OK;\n}\n\nstatic HRESULT ReadProp(\n    GetHandlerPropertyFunc getProp,\n    GetHandlerPropertyFunc2 getProp2,\n    UInt32 index, PROPID propID, NCOM::CPropVariant &prop)\n{\n  if (getProp2)\n    return getProp2(index, propID, &prop);;\n  return getProp(propID, &prop);\n}\n\nstatic HRESULT ReadBoolProp(\n    GetHandlerPropertyFunc getProp,\n    GetHandlerPropertyFunc2 getProp2,\n    UInt32 index, PROPID propID, bool &res)\n{\n  NCOM::CPropVariant prop;\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\n  if (prop.vt == VT_BOOL)\n    res = VARIANT_BOOLToBool(prop.boolVal);\n  else if (prop.vt != VT_EMPTY)\n    return E_FAIL;\n  return S_OK;\n}\n\nstatic HRESULT ReadStringProp(\n    GetHandlerPropertyFunc getProp,\n    GetHandlerPropertyFunc2 getProp2,\n    UInt32 index, PROPID propID, UString &res)\n{\n  NCOM::CPropVariant prop;\n  RINOK(ReadProp(getProp, getProp2, index, propID, prop));\n  if (prop.vt == VT_BSTR)\n    res = prop.bstrVal;\n  else if (prop.vt != VT_EMPTY)\n    return E_FAIL;\n  return S_OK;\n}\n\n#endif\n\nstatic const unsigned int kNumArcsMax = 32;\nstatic unsigned int g_NumArcs = 0;\nstatic const CArcInfo *g_Arcs[kNumArcsMax];\nvoid RegisterArc(const CArcInfo *arcInfo)\n{\n  if (g_NumArcs < kNumArcsMax)\n    g_Arcs[g_NumArcs++] = arcInfo;\n}\n\nstatic void SplitString(const UString &srcString, UStringVector &destStrings)\n{\n  destStrings.Clear();\n  UString s;\n  int len = srcString.Length();\n  if (len == 0)\n    return;\n  for (int i = 0; i < len; i++)\n  {\n    wchar_t c = srcString[i];\n    if (c == L' ')\n    {\n      if (!s.IsEmpty())\n      {\n        destStrings.Add(s);\n        s.Empty();\n      }\n    }\n    else\n      s += c;\n  }\n  if (!s.IsEmpty())\n    destStrings.Add(s);\n}\n\nvoid CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt)\n{\n  UStringVector exts, addExts;\n  SplitString(ext, exts);\n  if (addExt != 0)\n    SplitString(addExt, addExts);\n  for (int i = 0; i < exts.Size(); i++)\n  {\n    CArcExtInfo extInfo;\n    extInfo.Ext = exts[i];\n    if (i < addExts.Size())\n    {\n      extInfo.AddExt = addExts[i];\n      if (extInfo.AddExt == L\"*\")\n        extInfo.AddExt.Empty();\n    }\n    Exts.Add(extInfo);\n  }\n}\n\n#ifdef EXTERNAL_CODECS\n\nHRESULT CCodecs::LoadFormats()\n{\n  const NDLL::CLibrary &lib = Libs.Back().Lib;\n  GetHandlerPropertyFunc getProp = 0;\n  GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)\n      lib.GetProcAddress(\"GetHandlerProperty2\");\n  if (getProp2 == NULL)\n  {\n    getProp = (GetHandlerPropertyFunc)\n        lib.GetProcAddress(\"GetHandlerProperty\");\n    if (getProp == NULL)\n      return S_OK;\n  }\n\n  UInt32 numFormats = 1;\n  GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)\n    lib.GetProcAddress(\"GetNumberOfFormats\");\n  if (getNumberOfFormats != NULL)\n  {\n    RINOK(getNumberOfFormats(&numFormats));\n  }\n  if (getProp2 == NULL)\n    numFormats = 1;\n\n  for(UInt32 i = 0; i < numFormats; i++)\n  {\n    CArcInfoEx item;\n    item.LibIndex = Libs.Size() - 1;\n    item.FormatIndex = i;\n\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));\n\n    NCOM::CPropVariant prop;\n    if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)\n      continue;\n    if (prop.vt != VT_BSTR)\n      continue;\n    item.ClassID = *(const GUID *)prop.bstrVal;\n    prop.Clear();\n\n    UString ext, addExt;\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));\n    RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));\n    item.AddExts(ext, addExt);\n\n    ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);\n    if (item.UpdateEnabled)\n      ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);\n    \n    if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)\n      if (prop.vt == VT_BSTR)\n      {\n        UINT len = ::SysStringByteLen(prop.bstrVal);\n        item.StartSignature.SetCapacity(len);\n        memmove(item.StartSignature, prop.bstrVal, len);\n      }\n    Formats.Add(item);\n  }\n  return S_OK;\n}\n\n#ifdef NEW_FOLDER_INTERFACE\nvoid CCodecLib::LoadIcons()\n{\n  UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId);\n  UStringVector pairs;\n  SplitString(iconTypes, pairs);\n  for (int i = 0; i < pairs.Size(); i++)\n  {\n    const UString &s = pairs[i];\n    int pos = s.Find(L':');\n    if (pos < 0)\n      continue;\n    CIconPair iconPair;\n    const wchar_t *end;\n    UString num = s.Mid(pos + 1);\n    iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);\n    if (*end != L'\\0')\n      continue;\n    iconPair.Ext = s.Left(pos);\n    IconPairs.Add(iconPair);\n  }\n}\n\nint CCodecLib::FindIconIndex(const UString &ext) const\n{\n  for (int i = 0; i < IconPairs.Size(); i++)\n  {\n    const CIconPair &pair = IconPairs[i];\n    if (ext.CompareNoCase(pair.Ext) == 0)\n      return pair.IconIndex;\n  }\n  return -1;\n}\n#endif\n\n#ifdef _7ZIP_LARGE_PAGES\nextern \"C\"\n{\n  extern SIZE_T g_LargePageSize;\n}\n#endif\n\nHRESULT CCodecs::LoadDll(const CSysString &dllPath)\n{\n  {\n    NDLL::CLibrary library;\n    if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))\n      return S_OK;\n  }\n  Libs.Add(CCodecLib());\n  CCodecLib &lib = Libs.Back();\n  #ifdef NEW_FOLDER_INTERFACE\n  lib.Path = dllPath;\n  #endif\n  bool used = false;\n  HRESULT res = S_OK;\n  if (lib.Lib.Load(dllPath))\n  {\n    #ifdef NEW_FOLDER_INTERFACE\n    lib.LoadIcons();\n    #endif\n\n    #ifdef _7ZIP_LARGE_PAGES\n    if (g_LargePageSize != 0)\n    {\n      SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProcAddress(\"SetLargePageMode\");\n      if (setLargePageMode != 0)\n        setLargePageMode();\n    }\n    #endif\n\n    lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress(\"CreateObject\");\n    if (lib.CreateObject != 0)\n    {\n      int startSize = Codecs.Size();\n      res = LoadCodecs();\n      used = (Codecs.Size() != startSize);\n      if (res == S_OK)\n      {\n        startSize = Formats.Size();\n        res = LoadFormats();\n        used = used || (Formats.Size() != startSize);\n      }\n    }\n  }\n  if (!used)\n    Libs.DeleteBack();\n  return res;\n}\n\nHRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)\n{\n  NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT(\"*\")));\n  NFile::NFind::CFileInfo fi;\n  while (enumerator.Next(fi))\n  {\n    if (fi.IsDir())\n      continue;\n    RINOK(LoadDll(folderPrefix + fi.Name));\n  }\n  return S_OK;\n}\n\n#endif\n\n#ifndef _SFX\nstatic inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)\n{\n  bb.SetCapacity(size);\n  memmove((Byte *)bb, data, size);\n}\n#endif\n\nHRESULT CCodecs::Load()\n{\n  Formats.Clear();\n  #ifdef EXTERNAL_CODECS\n  Codecs.Clear();\n  #endif\n  for (UInt32 i = 0; i < g_NumArcs; i++)\n  {\n    const CArcInfo &arc = *g_Arcs[i];\n    CArcInfoEx item;\n    item.Name = arc.Name;\n    item.CreateInArchive = arc.CreateInArchive;\n    item.CreateOutArchive = arc.CreateOutArchive;\n    item.AddExts(arc.Ext, arc.AddExt);\n    item.UpdateEnabled = (arc.CreateOutArchive != 0);\n    item.KeepName = arc.KeepName;\n\n    #ifndef _SFX\n    SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);\n    #endif\n    Formats.Add(item);\n  }\n  #ifdef EXTERNAL_CODECS\n  const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();\n  RINOK(LoadDll(baseFolder + kMainDll));\n  RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));\n  RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));\n  #endif\n  return S_OK;\n}\n\n#ifndef _SFX\n\nint CCodecs::FindFormatForArchiveName(const UString &arcPath) const\n{\n  int slashPos1 = arcPath.ReverseFind(WCHAR_PATH_SEPARATOR);\n  int slashPos2 = arcPath.ReverseFind(L'.');\n  int dotPos = arcPath.ReverseFind(L'.');\n  if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)\n    return -1;\n  UString ext = arcPath.Mid(dotPos + 1);\n  for (int i = 0; i < Formats.Size(); i++)\n  {\n    const CArcInfoEx &arc = Formats[i];\n    if (!arc.UpdateEnabled)\n      continue;\n    // if (arc.FindExtension(ext) >= 0)\n    UString mainExt = arc.GetMainExt();\n    if (!mainExt.IsEmpty() && ext.CompareNoCase(mainExt) == 0)\n      return i;\n  }\n  return -1;\n}\n\nint CCodecs::FindFormatForExtension(const UString &ext) const\n{\n  if (ext.IsEmpty())\n    return -1;\n  for (int i = 0; i < Formats.Size(); i++)\n    if (Formats[i].FindExtension(ext) >= 0)\n      return i;\n  return -1;\n}\n\nint CCodecs::FindFormatForArchiveType(const UString &arcType) const\n{\n  for (int i = 0; i < Formats.Size(); i++)\n    if (Formats[i].Name.CompareNoCase(arcType) == 0)\n      return i;\n  return -1;\n}\n\nbool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const\n{\n  formatIndices.Clear();\n  for (int pos = 0; pos < arcType.Length();)\n  {\n    int pos2 = arcType.Find('.', pos);\n    if (pos2 < 0)\n      pos2 = arcType.Length();\n    const UString name = arcType.Mid(pos, pos2 - pos);\n    int index = FindFormatForArchiveType(name);\n    if (index < 0 && name != L\"*\")\n    {\n      formatIndices.Clear();\n      return false;\n    }\n    formatIndices.Add(index);\n    pos = pos2 + 1;\n  }\n  return true;\n}\n\n#endif\n\n#ifdef EXTERNAL_CODECS\n\n#ifdef EXPORT_CODECS\nextern unsigned int g_NumCodecs;\nSTDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);\nSTDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);\n// STDAPI GetNumberOfMethods(UInt32 *numCodecs);\n#endif\n\nSTDMETHODIMP CCodecs::GetNumberOfMethods(UInt32 *numMethods)\n{\n  *numMethods =\n      #ifdef EXPORT_CODECS\n      g_NumCodecs +\n      #endif\n      Codecs.Size();\n  return S_OK;\n}\n\nSTDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\n{\n  #ifdef EXPORT_CODECS\n  if (index < g_NumCodecs)\n    return GetMethodProperty(index, propID, value);\n  #endif\n\n  const CDllCodecInfo &ci = Codecs[index\n      #ifdef EXPORT_CODECS\n      - g_NumCodecs\n      #endif\n      ];\n\n  if (propID == NMethodPropID::kDecoderIsAssigned)\n  {\n    NWindows::NCOM::CPropVariant propVariant;\n    propVariant = ci.DecoderIsAssigned;\n    propVariant.Detach(value);\n    return S_OK;\n  }\n  if (propID == NMethodPropID::kEncoderIsAssigned)\n  {\n    NWindows::NCOM::CPropVariant propVariant;\n    propVariant = ci.EncoderIsAssigned;\n    propVariant.Detach(value);\n    return S_OK;\n  }\n  return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);\n}\n\nSTDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)\n{\n  #ifdef EXPORT_CODECS\n  if (index < g_NumCodecs)\n    return CreateCoder2(false, index, iid, coder);\n  #endif\n  const CDllCodecInfo &ci = Codecs[index\n      #ifdef EXPORT_CODECS\n      - g_NumCodecs\n      #endif\n      ];\n  if (ci.DecoderIsAssigned)\n    return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder);\n  return S_OK;\n}\n\nSTDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)\n{\n  #ifdef EXPORT_CODECS\n  if (index < g_NumCodecs)\n    return CreateCoder2(true, index, iid, coder);\n  #endif\n  const CDllCodecInfo &ci = Codecs[index\n      #ifdef EXPORT_CODECS\n      - g_NumCodecs\n      #endif\n      ];\n  if (ci.EncoderIsAssigned)\n    return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder);\n  return S_OK;\n}\n\nHRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const\n{\n  for (int i = 0; i < Codecs.Size(); i++)\n  {\n    const CDllCodecInfo &codec = Codecs[i];\n    if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigned)\n      continue;\n    const CCodecLib &lib = Libs[codec.LibIndex];\n    UString res;\n    NWindows::NCOM::CPropVariant prop;\n    RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop));\n    if (prop.vt == VT_BSTR)\n      res = prop.bstrVal;\n    else if (prop.vt != VT_EMPTY)\n      continue;\n    if (name.CompareNoCase(res) == 0)\n      return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICompressCoder, (void **)&coder);\n  }\n  return CLASS_E_CLASSNOTAVAILABLE;\n}\n\nint CCodecs::GetCodecLibIndex(UInt32 index)\n{\n  #ifdef EXPORT_CODECS\n  if (index < g_NumCodecs)\n    return -1;\n  #endif\n  #ifdef EXTERNAL_CODECS\n  const CDllCodecInfo &ci = Codecs[index\n      #ifdef EXPORT_CODECS\n      - g_NumCodecs\n      #endif\n      ];\n  return ci.LibIndex;\n  #else\n  return -1;\n  #endif\n}\n\nbool CCodecs::GetCodecEncoderIsAssigned(UInt32 index)\n{\n  #ifdef EXPORT_CODECS\n  if (index < g_NumCodecs)\n  {\n    NWindows::NCOM::CPropVariant prop;\n    if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK)\n      if (prop.vt != VT_EMPTY)\n        return true;\n    return false;\n  }\n  #endif\n  #ifdef EXTERNAL_CODECS\n  const CDllCodecInfo &ci = Codecs[index\n      #ifdef EXPORT_CODECS\n      - g_NumCodecs\n      #endif\n      ];\n  return ci.EncoderIsAssigned;\n  #else\n  return false;\n  #endif\n}\n\nHRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id)\n{\n  UString s;\n  NWindows::NCOM::CPropVariant prop;\n  RINOK(GetProperty(index, NMethodPropID::kID, &prop));\n  if (prop.vt != VT_UI8)\n    return E_INVALIDARG;\n  id = prop.uhVal.QuadPart;\n  return S_OK;\n}\n\nUString CCodecs::GetCodecName(UInt32 index)\n{\n  UString s;\n  NWindows::NCOM::CPropVariant prop;\n  if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK)\n    if (prop.vt == VT_BSTR)\n      s = prop.bstrVal;\n  return s;\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/LoadCodecs.h",
    "content": "// LoadCodecs.h\n\n#ifndef __LOADCODECS_H\n#define __LOADCODECS_H\n\n#include \"../../../Common/Types.h\"\n#include \"../../../Common/MyCom.h\"\n#include \"../../../Common/MyString.h\"\n#include \"../../../Common/Buffer.h\"\n#include \"../../ICoder.h\"\n\n#ifdef EXTERNAL_CODECS\n#include \"../../../Windows/DLL.h\"\n#endif\n\nstruct CDllCodecInfo\n{\n  CLSID Encoder;\n  CLSID Decoder;\n  bool EncoderIsAssigned;\n  bool DecoderIsAssigned;\n  int LibIndex;\n  UInt32 CodecIndex;\n};\n\n#include \"../../Archive/IArchive.h\"\n\ntypedef IInArchive * (*CreateInArchiveP)();\ntypedef IOutArchive * (*CreateOutArchiveP)();\n\nstruct CArcExtInfo\n{\n  UString Ext;\n  UString AddExt;\n  CArcExtInfo() {}\n  CArcExtInfo(const UString &ext): Ext(ext) {}\n  CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}\n};\n\n\nstruct CArcInfoEx\n{\n  #ifdef EXTERNAL_CODECS\n  int LibIndex;\n  UInt32 FormatIndex;\n  CLSID ClassID;\n  #endif\n  bool UpdateEnabled;\n  CreateInArchiveP CreateInArchive;\n  CreateOutArchiveP CreateOutArchive;\n  UString Name;\n  CObjectVector<CArcExtInfo> Exts;\n  #ifndef _SFX\n  CByteBuffer StartSignature;\n  // CByteBuffer FinishSignature;\n  #ifdef NEW_FOLDER_INTERFACE\n  UStringVector AssociateExts;\n  #endif\n  #endif\n  bool KeepName;\n  UString GetMainExt() const\n  {\n    if (Exts.IsEmpty())\n      return UString();\n    return Exts[0].Ext;\n  }\n  int FindExtension(const UString &ext) const\n  {\n    for (int i = 0; i < Exts.Size(); i++)\n      if (ext.CompareNoCase(Exts[i].Ext) == 0)\n        return i;\n    return -1;\n  }\n  UString GetAllExtensions() const\n  {\n    UString s;\n    for (int i = 0; i < Exts.Size(); i++)\n    {\n      if (i > 0)\n        s += ' ';\n      s += Exts[i].Ext;\n    }\n    return s;\n  }\n\n  void AddExts(const wchar_t* ext, const wchar_t* addExt);\n\n  CArcInfoEx():\n    #ifdef EXTERNAL_CODECS\n    LibIndex(-1),\n    #endif\n    UpdateEnabled(false),\n    CreateInArchive(0), CreateOutArchive(0),\n    KeepName(false)\n    #ifndef _SFX\n    #endif\n  {}\n};\n\n#ifdef EXTERNAL_CODECS\ntypedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);\ntypedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);\n\n\nstruct CCodecLib\n{\n  NWindows::NDLL::CLibrary Lib;\n  GetMethodPropertyFunc GetMethodProperty;\n  CreateObjectFunc CreateObject;\n  #ifdef NEW_FOLDER_INTERFACE\n  struct CIconPair\n  {\n    UString Ext;\n    UInt32 IconIndex;\n  };\n  CSysString Path;\n  CObjectVector<CIconPair> IconPairs;\n  void LoadIcons();\n  int FindIconIndex(const UString &ext) const;\n  #endif\n  CCodecLib(): GetMethodProperty(0) {}\n};\n#endif\n\nclass CCodecs:\n  #ifdef EXTERNAL_CODECS\n  public ICompressCodecsInfo,\n  #else\n  public IUnknown,\n  #endif\n  public CMyUnknownImp\n{\npublic:\n  #ifdef EXTERNAL_CODECS\n  CObjectVector<CCodecLib> Libs;\n  CObjectVector<CDllCodecInfo> Codecs;\n  HRESULT LoadCodecs();\n  HRESULT LoadFormats();\n  HRESULT LoadDll(const CSysString &path);\n  HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);\n\n  HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const\n  {\n    return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);\n  }\n  #endif\n\npublic:\n  CObjectVector<CArcInfoEx> Formats;\n  HRESULT Load();\n  \n  #ifndef _SFX\n  int FindFormatForArchiveName(const UString &arcPath) const;\n  int FindFormatForExtension(const UString &ext) const;\n  int FindFormatForArchiveType(const UString &arcType) const;\n  bool FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const;\n  #endif\n\n  MY_UNKNOWN_IMP\n\n  #ifdef EXTERNAL_CODECS\n  STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods);\n  STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);\n  STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder);\n  STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder);\n  #endif\n\n  int GetCodecLibIndex(UInt32 index);\n  bool GetCodecEncoderIsAssigned(UInt32 index);\n  HRESULT GetCodecId(UInt32 index, UInt64 &id);\n  UString GetCodecName(UInt32 index);\n\n  HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const\n  {\n    const CArcInfoEx &ai = Formats[formatIndex];\n    #ifdef EXTERNAL_CODECS\n    if (ai.LibIndex < 0)\n    #endif\n    {\n      archive = ai.CreateInArchive();\n      return S_OK;\n    }\n    #ifdef EXTERNAL_CODECS\n    return CreateArchiveHandler(ai, (void **)&archive, false);\n    #endif\n  }\n  HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const\n  {\n    const CArcInfoEx &ai = Formats[formatIndex];\n    #ifdef EXTERNAL_CODECS\n    if (ai.LibIndex < 0)\n    #endif\n    {\n      archive = ai.CreateOutArchive();\n      return S_OK;\n    }\n    #ifdef EXTERNAL_CODECS\n    return CreateArchiveHandler(ai, (void **)&archive, true);\n    #endif\n  }\n  int FindOutFormatFromName(const UString &name) const\n  {\n    for (int i = 0; i < Formats.Size(); i++)\n    {\n      const CArcInfoEx &arc = Formats[i];\n      if (!arc.UpdateEnabled)\n        continue;\n      if (arc.Name.CompareNoCase(name) == 0)\n        return i;\n    }\n    return -1;\n  }\n\n  #ifdef EXTERNAL_CODECS\n  HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;\n  #endif\n\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/OpenArchive.cpp",
    "content": "// OpenArchive.cpp\n\n#include \"StdAfx.h\"\n\n#include \"OpenArchive.h\"\n\n#include \"Common/Wildcard.h\"\n\n#include \"Windows/FileName.h\"\n#include \"Windows/FileDir.h\"\n#include \"Windows/Defs.h\"\n#include \"Windows/PropVariant.h\"\n\n#include \"../../Common/FileStreams.h\"\n#include \"../../Common/StreamUtils.h\"\n\n#include \"Common/StringConvert.h\"\n\n#include \"DefaultName.h\"\n\nusing namespace NWindows;\n\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result)\n{\n  NCOM::CPropVariant prop;\n  RINOK(archive->GetProperty(index, kpidPath, &prop));\n  if(prop.vt == VT_BSTR)\n    result = prop.bstrVal;\n  else if (prop.vt == VT_EMPTY)\n    result.Empty();\n  else\n    return E_FAIL;\n  return S_OK;\n}\n\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result)\n{\n  RINOK(GetArchiveItemPath(archive, index, result));\n  if (result.IsEmpty())\n  {\n    result = defaultName;\n    NCOM::CPropVariant prop;\n    RINOK(archive->GetProperty(index, kpidExtension, &prop));\n    if (prop.vt == VT_BSTR)\n    {\n      result += L'.';\n      result += prop.bstrVal;\n    }\n    else if (prop.vt != VT_EMPTY)\n      return E_FAIL;\n  }\n  return S_OK;\n}\n\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\n    const FILETIME &defaultFileTime, FILETIME &fileTime)\n{\n  NCOM::CPropVariant prop;\n  RINOK(archive->GetProperty(index, kpidMTime, &prop));\n  if (prop.vt == VT_FILETIME)\n    fileTime = prop.filetime;\n  else if (prop.vt == VT_EMPTY)\n    fileTime = defaultFileTime;\n  else\n    return E_FAIL;\n  return S_OK;\n}\n\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)\n{\n  NCOM::CPropVariant prop;\n  RINOK(archive->GetProperty(index, propID, &prop));\n  if(prop.vt == VT_BOOL)\n    result = VARIANT_BOOLToBool(prop.boolVal);\n  else if (prop.vt == VT_EMPTY)\n    result = false;\n  else\n    return E_FAIL;\n  return S_OK;\n}\n\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)\n{\n  return IsArchiveItemProp(archive, index, kpidIsDir, result);\n}\n\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result)\n{\n  return IsArchiveItemProp(archive, index, kpidIsAnti, result);\n}\n\n// Static-SFX (for Linux) can be big.\nconst UInt64 kMaxCheckStartPosition = 1 << 22;\n\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback)\n{\n  CInFileStream *inStreamSpec = new CInFileStream;\n  CMyComPtr<IInStream> inStream(inStreamSpec);\n  inStreamSpec->Open(fileName);\n  return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\n}\n\n#ifndef _SFX\nstatic inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)\n{\n  for (size_t i = 0; i < size; i++)\n    if (p1[i] != p2[i])\n      return false;\n  return true;\n}\n#endif\n\nHRESULT OpenArchive(\n    CCodecs *codecs,\n    int arcTypeIndex,\n    IInStream *inStream,\n    const UString &fileName,\n    IInArchive **archiveResult,\n    int &formatIndex,\n    UString &defaultItemName,\n    IArchiveOpenCallback *openArchiveCallback)\n{\n  *archiveResult = NULL;\n  UString extension;\n  {\n    int dotPos = fileName.ReverseFind(L'.');\n    if (dotPos >= 0)\n      extension = fileName.Mid(dotPos + 1);\n  }\n  CIntVector orderIndices;\n  if (arcTypeIndex >= 0)\n    orderIndices.Add(arcTypeIndex);\n  else\n  {\n\n  int i;\n  int numFinded = 0;\n  for (i = 0; i < codecs->Formats.Size(); i++)\n    if (codecs->Formats[i].FindExtension(extension) >= 0)\n      orderIndices.Insert(numFinded++, i);\n    else\n      orderIndices.Add(i);\n  \n  #ifndef _SFX\n  if (numFinded != 1)\n  {\n    CIntVector orderIndices2;\n    CByteBuffer byteBuffer;\n    const size_t kBufferSize = (1 << 21);\n    byteBuffer.SetCapacity(kBufferSize);\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\n    size_t processedSize = kBufferSize;\n    RINOK(ReadStream(inStream, byteBuffer, &processedSize));\n    if (processedSize == 0)\n      return S_FALSE;\n\n    const Byte *buf = byteBuffer;\n    Byte hash[1 << 16];\n    memset(hash, 0xFF, 1 << 16);\n    Byte prevs[256];\n    if (orderIndices.Size() > 255)\n      return S_FALSE;\n    int i;\n    for (i = 0; i < orderIndices.Size(); i++)\n    {\n      const CArcInfoEx &ai = codecs->Formats[orderIndices[i]];\n      const CByteBuffer &sig = ai.StartSignature;\n      if (sig.GetCapacity() < 2)\n        continue;\n      UInt32 v = sig[0] | ((UInt32)sig[1] << 8);\n      prevs[i] = hash[v];\n      hash[v] = (Byte)i;\n    }\n\n    processedSize--;\n    for (UInt32 pos = 0; pos < processedSize; pos++)\n    {\n      for (; pos < processedSize && hash[buf[pos] | ((UInt32)buf[pos + 1] << 8)] == 0xFF; pos++);\n      if (pos == processedSize)\n        break;\n      UInt32 v = buf[pos] | ((UInt32)buf[pos + 1] << 8);\n      Byte *ptr = &hash[v];\n      int i = *ptr;\n      do\n      {\n        int index = orderIndices[i];\n        const CArcInfoEx &ai = codecs->Formats[index];\n        const CByteBuffer &sig = ai.StartSignature;\n        if (sig.GetCapacity() != 0 && pos + sig.GetCapacity() <= processedSize + 1)\n          if (TestSignature(buf + pos, sig, sig.GetCapacity()))\n          {\n            orderIndices2.Add(index);\n            orderIndices[i] = 0xFF;\n            *ptr = prevs[i];\n          }\n        ptr = &prevs[i];\n        i = *ptr;\n      }\n      while (i != 0xFF);\n    }\n    \n    for (i = 0; i < orderIndices.Size(); i++)\n    {\n      int val = orderIndices[i];\n      if (val != 0xFF)\n        orderIndices2.Add(val);\n    }\n    orderIndices = orderIndices2;\n\n    if (orderIndices.Size() >= 2)\n    {\n      int isoIndex = codecs->FindFormatForArchiveType(L\"iso\");\n      int udfIndex = codecs->FindFormatForArchiveType(L\"udf\");\n      int iIso = -1;\n      int iUdf = -1;\n      for (int i = 0; i < orderIndices.Size(); i++)\n      {\n        if (orderIndices[i] == isoIndex) iIso = i;\n        if (orderIndices[i] == udfIndex) iUdf = i;\n      }\n      if (iUdf == iIso + 1)\n      {\n        orderIndices[iUdf] = isoIndex;\n        orderIndices[iIso] = udfIndex;\n      }\n    }\n  }\n  else if (extension == L\"000\" || extension == L\"001\")\n  {\n    CByteBuffer byteBuffer;\n    const size_t kBufferSize = (1 << 10);\n    byteBuffer.SetCapacity(kBufferSize);\n    Byte *buffer = byteBuffer;\n    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));\n    size_t processedSize = kBufferSize;\n    RINOK(ReadStream(inStream, buffer, &processedSize));\n    if (processedSize >= 16)\n    {\n      Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};\n      if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] & 1) != 0)\n      {\n        for (int i = 0; i < orderIndices.Size(); i++)\n        {\n          int index = orderIndices[i];\n          const CArcInfoEx &ai = codecs->Formats[index];\n          if (ai.Name.CompareNoCase(L\"rar\") != 0)\n            continue;\n          orderIndices.Delete(i--);\n          orderIndices.Insert(0, index);\n          break;\n        }\n      }\n    }\n  }\n  #endif\n  }\n\n  for(int i = 0; i < orderIndices.Size(); i++)\n  {\n    inStream->Seek(0, STREAM_SEEK_SET, NULL);\n\n    CMyComPtr<IInArchive> archive;\n\n    formatIndex = orderIndices[i];\n    RINOK(codecs->CreateInArchive(formatIndex, archive));\n    if (!archive)\n      continue;\n\n    #ifdef EXTERNAL_CODECS\n    {\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\n      archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\n      if (setCompressCodecsInfo)\n      {\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\n      }\n    }\n    #endif\n\n    HRESULT result = archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);\n    if (result == S_FALSE)\n      continue;\n    RINOK(result);\n    *archiveResult = archive.Detach();\n    const CArcInfoEx &format = codecs->Formats[formatIndex];\n    if (format.Exts.Size() == 0)\n    {\n      defaultItemName = GetDefaultName2(fileName, L\"\", L\"\");\n    }\n    else\n    {\n      int subExtIndex = format.FindExtension(extension);\n      if (subExtIndex < 0)\n        subExtIndex = 0;\n      defaultItemName = GetDefaultName2(fileName,\n          format.Exts[subExtIndex].Ext,\n          format.Exts[subExtIndex].AddExt);\n    }\n    return S_OK;\n  }\n  return S_FALSE;\n}\n\nHRESULT OpenArchive(\n    CCodecs *codecs,\n    int arcTypeIndex,\n    const UString &filePath,\n    IInArchive **archiveResult,\n    int &formatIndex,\n    UString &defaultItemName,\n    IArchiveOpenCallback *openArchiveCallback)\n{\n  CInFileStream *inStreamSpec = new CInFileStream;\n  CMyComPtr<IInStream> inStream(inStreamSpec);\n  if (!inStreamSpec->Open(filePath))\n    return GetLastError();\n  return OpenArchive(codecs, arcTypeIndex, inStream, ExtractFileNameFromPath(filePath),\n    archiveResult, formatIndex,\n    defaultItemName, openArchiveCallback);\n}\n\nstatic void MakeDefaultName(UString &name)\n{\n  int dotPos = name.ReverseFind(L'.');\n  if (dotPos < 0)\n    return;\n  UString ext = name.Mid(dotPos + 1);\n  if (ext.IsEmpty())\n    return;\n  for (int pos = 0; pos < ext.Length(); pos++)\n    if (ext[pos] < L'0' || ext[pos] > L'9')\n      return;\n  name = name.Left(dotPos);\n}\n\nHRESULT OpenArchive(\n    CCodecs *codecs,\n    const CIntVector &formatIndices,\n    const UString &fileName,\n    IInArchive **archive0,\n    IInArchive **archive1,\n    int &formatIndex0,\n    int &formatIndex1,\n    UString &defaultItemName0,\n    UString &defaultItemName1,\n    IArchiveOpenCallback *openArchiveCallback)\n{\n  if (formatIndices.Size() >= 3)\n    return E_NOTIMPL;\n  \n  int arcTypeIndex = -1;\n  if (formatIndices.Size() >= 1)\n    arcTypeIndex = formatIndices[formatIndices.Size() - 1];\n  \n  HRESULT result = OpenArchive(codecs, arcTypeIndex, fileName,\n    archive0, formatIndex0, defaultItemName0, openArchiveCallback);\n  RINOK(result);\n\n  if (formatIndices.Size() == 1)\n    return S_OK;\n  arcTypeIndex = -1;\n  if (formatIndices.Size() >= 2)\n    arcTypeIndex = formatIndices[formatIndices.Size() - 2];\n\n  HRESULT resSpec = (formatIndices.Size() == 0 ? S_OK : E_NOTIMPL);\n\n  CMyComPtr<IInArchiveGetStream> getStream;\n  result = (*archive0)->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream);\n  if (result != S_OK || !getStream)\n    return resSpec;\n\n  CMyComPtr<ISequentialInStream> subSeqStream;\n  result = getStream->GetStream(0, &subSeqStream);\n  if (result != S_OK || !subSeqStream)\n    return resSpec;\n\n  CMyComPtr<IInStream> subStream;\n  result = subSeqStream.QueryInterface(IID_IInStream, &subStream);\n  if (result != S_OK || !subStream)\n    return resSpec;\n\n  UInt32 numItems;\n  RINOK((*archive0)->GetNumberOfItems(&numItems));\n  if (numItems < 1)\n    return resSpec;\n\n  UString subPath;\n  RINOK(GetArchiveItemPath(*archive0, 0, subPath))\n  if (subPath.IsEmpty())\n  {\n    MakeDefaultName(defaultItemName0);\n    subPath = defaultItemName0;\n    const CArcInfoEx &format = codecs->Formats[formatIndex0];\n    if (format.Name.CompareNoCase(L\"7z\") == 0)\n    {\n      if (subPath.Right(3).CompareNoCase(L\".7z\") != 0)\n        subPath += L\".7z\";\n    }\n  }\n  else\n    subPath = ExtractFileNameFromPath(subPath);\n\n  CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;\n  openArchiveCallback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);\n  if (setSubArchiveName)\n    setSubArchiveName->SetSubArchiveName(subPath);\n\n  result = OpenArchive(codecs, arcTypeIndex, subStream, subPath,\n      archive1, formatIndex1, defaultItemName1, openArchiveCallback);\n  resSpec = (formatIndices.Size() == 0 ? S_OK : S_FALSE);\n  if (result != S_OK)\n    return resSpec;\n  return S_OK;\n}\n\nstatic void SetCallback(const UString &archiveName,\n    IOpenCallbackUI *openCallbackUI,\n    IArchiveOpenCallback *reOpenCallback,\n    CMyComPtr<IArchiveOpenCallback> &openCallback)\n{\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\n  openCallback = openCallbackSpec;\n  openCallbackSpec->Callback = openCallbackUI;\n  openCallbackSpec->ReOpenCallback = reOpenCallback;\n\n  UString fullName;\n  int fileNamePartStartIndex;\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\n  openCallbackSpec->Init(\n      fullName.Left(fileNamePartStartIndex),\n      fullName.Mid(fileNamePartStartIndex));\n}\n\nHRESULT MyOpenArchive(\n    CCodecs *codecs,\n    int arcTypeIndex,\n    const UString &archiveName,\n    IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI)\n{\n  CMyComPtr<IArchiveOpenCallback> openCallback;\n  SetCallback(archiveName, openCallbackUI, NULL, openCallback);\n  int formatInfo;\n  return OpenArchive(codecs, arcTypeIndex, archiveName, archive, formatInfo, defaultItemName, openCallback);\n}\n\nHRESULT MyOpenArchive(\n    CCodecs *codecs,\n    const CIntVector &formatIndices,\n    const UString &archiveName,\n    IInArchive **archive0,\n    IInArchive **archive1,\n    UString &defaultItemName0,\n    UString &defaultItemName1,\n    UStringVector &volumePaths,\n    UInt64 &volumesSize,\n    IOpenCallbackUI *openCallbackUI)\n{\n  volumesSize = 0;\n  COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;\n  CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;\n  openCallbackSpec->Callback = openCallbackUI;\n\n  UString fullName;\n  int fileNamePartStartIndex;\n  NFile::NDirectory::MyGetFullPathName(archiveName, fullName, fileNamePartStartIndex);\n  UString prefix = fullName.Left(fileNamePartStartIndex);\n  UString name = fullName.Mid(fileNamePartStartIndex);\n  openCallbackSpec->Init(prefix, name);\n\n  int formatIndex0, formatIndex1;\n  RINOK(OpenArchive(codecs, formatIndices, archiveName,\n      archive0,\n      archive1,\n      formatIndex0,\n      formatIndex1,\n      defaultItemName0,\n      defaultItemName1,\n      openCallback));\n  volumePaths.Add(prefix + name);\n  for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)\n    volumePaths.Add(prefix + openCallbackSpec->FileNames[i]);\n  volumesSize = openCallbackSpec->TotalSize;\n  return S_OK;\n}\n\nHRESULT CArchiveLink::Close()\n{\n  if (Archive1 != 0)\n    RINOK(Archive1->Close());\n  if (Archive0 != 0)\n    RINOK(Archive0->Close());\n  IsOpen = false;\n  return S_OK;\n}\n\nvoid CArchiveLink::Release()\n{\n  IsOpen = false;\n  Archive1.Release();\n  Archive0.Release();\n}\n\nHRESULT OpenArchive(\n    CCodecs *codecs,\n    const CIntVector &formatIndices,\n    const UString &archiveName,\n    CArchiveLink &archiveLink,\n    IArchiveOpenCallback *openCallback)\n{\n  HRESULT res = OpenArchive(codecs, formatIndices, archiveName,\n    &archiveLink.Archive0, &archiveLink.Archive1,\n    archiveLink.FormatIndex0, archiveLink.FormatIndex1,\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\n    openCallback);\n  archiveLink.IsOpen = (res == S_OK);\n  return res;\n}\n\nHRESULT MyOpenArchive(CCodecs *codecs,\n    const CIntVector &formatIndices,\n    const UString &archiveName,\n    CArchiveLink &archiveLink,\n    IOpenCallbackUI *openCallbackUI)\n{\n  HRESULT res = MyOpenArchive(codecs, formatIndices, archiveName,\n    &archiveLink.Archive0, &archiveLink.Archive1,\n    archiveLink.DefaultItemName0, archiveLink.DefaultItemName1,\n    archiveLink.VolumePaths,\n    archiveLink.VolumesSize,\n    openCallbackUI);\n  archiveLink.IsOpen = (res == S_OK);\n  return res;\n}\n\nHRESULT ReOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, const UString &fileName,\n    IArchiveOpenCallback *openCallback)\n{\n  if (archiveLink.GetNumLevels() > 1)\n    return E_NOTIMPL;\n\n  if (archiveLink.GetNumLevels() == 0)\n    return MyOpenArchive(codecs, CIntVector(), fileName, archiveLink, 0);\n\n  CMyComPtr<IArchiveOpenCallback> openCallbackNew;\n  SetCallback(fileName, NULL, openCallback, openCallbackNew);\n\n  HRESULT res = ReOpenArchive(archiveLink.GetArchive(), fileName, openCallbackNew);\n  archiveLink.IsOpen = (res == S_OK);\n  return res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/OpenArchive.h",
    "content": "// OpenArchive.h\n\n#ifndef __OPENARCHIVE_H\n#define __OPENARCHIVE_H\n\n#include \"Common/MyString.h\"\n#include \"Windows/FileFind.h\"\n\n#include \"../../Archive/IArchive.h\"\n#include \"LoadCodecs.h\"\n#include \"ArchiveOpenCallback.h\"\n\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, UString &result);\nHRESULT GetArchiveItemPath(IInArchive *archive, UInt32 index, const UString &defaultName, UString &result);\nHRESULT GetArchiveItemFileTime(IInArchive *archive, UInt32 index,\n    const FILETIME &defaultFileTime, FILETIME &fileTime);\nHRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result);\nHRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result);\nHRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result);\n\nstruct ISetSubArchiveName\n{\n  virtual void SetSubArchiveName(const wchar_t *name) = 0;\n};\n\nHRESULT OpenArchive(\n    CCodecs *codecs,\n    int arcTypeIndex,\n    IInStream *inStream,\n    const UString &fileName,\n    IInArchive **archiveResult,\n    int &formatIndex,\n    UString &defaultItemName,\n    IArchiveOpenCallback *openArchiveCallback);\n\nHRESULT OpenArchive(\n    CCodecs *codecs,\n    int arcTypeIndex,\n    const UString &filePath,\n    IInArchive **archive,\n    int &formatIndex,\n    UString &defaultItemName,\n    IArchiveOpenCallback *openArchiveCallback);\n\nHRESULT OpenArchive(\n    CCodecs *codecs,\n    const CIntVector &formatIndices,\n    const UString &filePath,\n    IInArchive **archive0,\n    IInArchive **archive1,\n    int &formatIndex0,\n    int &formatIndex1,\n    UString &defaultItemName0,\n    UString &defaultItemName1,\n    IArchiveOpenCallback *openArchiveCallback);\n\n\nHRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback);\n\nstruct CArchiveLink\n{\n  CMyComPtr<IInArchive> Archive0;\n  CMyComPtr<IInArchive> Archive1;\n  UString DefaultItemName0;\n  UString DefaultItemName1;\n\n  int FormatIndex0;\n  int FormatIndex1;\n  \n  UStringVector VolumePaths;\n\n  bool IsOpen;\n  UInt64 VolumesSize;\n\n  int GetNumLevels() const\n  {\n    int result = 0;\n    if (Archive0)\n    {\n      result++;\n      if (Archive1)\n        result++;\n    }\n    return result;\n  }\n\n  CArchiveLink(): IsOpen(false), VolumesSize(0) {};\n\n  IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; }\n  UString GetDefaultItemName()  { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; }\n  int GetArchiverIndex() const { return Archive1 != 0 ? FormatIndex1: FormatIndex0; }\n  HRESULT Close();\n  void Release();\n};\n\nHRESULT OpenArchive(\n    CCodecs *codecs,\n    const CIntVector &formatIndices,\n    const UString &archiveName,\n    CArchiveLink &archiveLink,\n    IArchiveOpenCallback *openCallback);\n\nHRESULT MyOpenArchive(\n    CCodecs *codecs,\n    const CIntVector &formatIndices,\n    const UString &archiveName,\n    CArchiveLink &archiveLink,\n    IOpenCallbackUI *openCallbackUI);\n\nHRESULT ReOpenArchive(\n    CCodecs *codecs,\n    CArchiveLink &archiveLink,\n    const UString &fileName,\n    IArchiveOpenCallback *openCallback);\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/PropIDUtils.cpp",
    "content": "// PropIDUtils.cpp\n\n#include \"StdAfx.h\"\n\n#include \"PropIDUtils.h\"\n\n#include \"Common/IntToString.h\"\n#include \"Common/StringConvert.h\"\n\n#include \"Windows/FileFind.h\"\n#include \"Windows/PropVariantConversions.h\"\n\n#include \"../../PropID.h\"\n\nusing namespace NWindows;\n\nstatic UString ConvertUInt32ToString(UInt32 value)\n{\n  wchar_t buffer[32];\n  ConvertUInt64ToString(value, buffer);\n  return buffer;\n}\n\nstatic void ConvertUInt32ToHex(UInt32 value, wchar_t *s)\n{\n  for (int i = 0; i < 8; i++)\n  {\n    int t = value & 0xF;\n    value >>= 4;\n    s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));\n  }\n  s[8] = L'\\0';\n}\n\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full)\n{\n  switch(propID)\n  {\n    case kpidCTime:\n    case kpidATime:\n    case kpidMTime:\n    {\n      if (propVariant.vt != VT_FILETIME)\n        return UString(); // It is error;\n      FILETIME localFileTime;\n      if (propVariant.filetime.dwHighDateTime == 0 &&\n          propVariant.filetime.dwLowDateTime == 0)\n        return UString();\n      if (!::FileTimeToLocalFileTime(&propVariant.filetime, &localFileTime))\n        return UString(); // It is error;\n      return ConvertFileTimeToString(localFileTime, true, full);\n    }\n    case kpidCRC:\n    {\n      if(propVariant.vt != VT_UI4)\n        break;\n      wchar_t temp[12];\n      ConvertUInt32ToHex(propVariant.ulVal, temp);\n      return temp;\n    }\n    case kpidAttrib:\n    {\n      if(propVariant.vt != VT_UI4)\n        break;\n      UString result;\n      UInt32 attributes = propVariant.ulVal;\n      if (NFile::NFind::NAttributes::IsReadOnly(attributes)) result += L'R';\n      if (NFile::NFind::NAttributes::IsHidden(attributes)) result += L'H';\n      if (NFile::NFind::NAttributes::IsSystem(attributes)) result += L'S';\n      if (NFile::NFind::NAttributes::IsDir(attributes)) result += L'D';\n      if (NFile::NFind::NAttributes::IsArchived(attributes)) result += L'A';\n      if (NFile::NFind::NAttributes::IsCompressed(attributes)) result += L'C';\n      if (NFile::NFind::NAttributes::IsEncrypted(attributes)) result += L'E';\n      return result;\n    }\n    case kpidDictionarySize:\n    {\n      if(propVariant.vt != VT_UI4)\n        break;\n      UInt32 size = propVariant.ulVal;\n      if (size % (1 << 20) == 0)\n        return ConvertUInt32ToString(size >> 20) + L\"MB\";\n      if (size % (1 << 10) == 0)\n        return ConvertUInt32ToString(size >> 10) + L\"KB\";\n      return ConvertUInt32ToString(size);\n    }\n  }\n  return ConvertPropVariantToString(propVariant);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/PropIDUtils.h",
    "content": "// PropIDUtils.h\n\n#ifndef __PROPIDUTILS_H\n#define __PROPIDUTILS_H\n\n#include \"Common/MyString.h\"\n\nUString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/Property.h",
    "content": "// Property.h\n\n#ifndef __PROPERTY_H\n#define __PROPERTY_H\n\n#include \"Common/MyString.h\"\n\nstruct CProperty\n{\n  UString Name;\n  UString Value;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/SetProperties.cpp",
    "content": "// SetProperties.cpp\n\n#include \"StdAfx.h\"\n\n#include \"SetProperties.h\"\n\n#include \"Windows/PropVariant.h\"\n#include \"Common/MyString.h\"\n#include \"Common/StringToInt.h\"\n#include \"Common/MyCom.h\"\n\n#include \"../../Archive/IArchive.h\"\n\nusing namespace NWindows;\nusing namespace NCOM;\n\nstatic void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)\n{\n  const wchar_t *endPtr;\n  UInt64 result = ConvertStringToUInt64(s, &endPtr);\n  if (endPtr - (const wchar_t *)s != s.Length())\n    prop = s;\n  else if (result <= 0xFFFFFFFF)\n    prop = (UInt32)result;\n  else\n    prop = result;\n}\n\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)\n{\n  if (properties.IsEmpty())\n    return S_OK;\n  CMyComPtr<ISetProperties> setProperties;\n  unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);\n  if (!setProperties)\n    return S_OK;\n\n  UStringVector realNames;\n  CPropVariant *values = new CPropVariant[properties.Size()];\n  try\n  {\n    int i;\n    for(i = 0; i < properties.Size(); i++)\n    {\n      const CProperty &property = properties[i];\n      NCOM::CPropVariant propVariant;\n      UString name = property.Name;\n      if (property.Value.IsEmpty())\n      {\n        if (!name.IsEmpty())\n        {\n          wchar_t c = name[name.Length() - 1];\n          if (c == L'-')\n            propVariant = false;\n          else if (c == L'+')\n            propVariant = true;\n          if (propVariant.vt != VT_EMPTY)\n            name = name.Left(name.Length() - 1);\n        }\n      }\n      else\n        ParseNumberString(property.Value, propVariant);\n      realNames.Add(name);\n      values[i] = propVariant;\n    }\n    CRecordVector<const wchar_t *> names;\n    for(i = 0; i < realNames.Size(); i++)\n      names.Add((const wchar_t *)realNames[i]);\n    \n    RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));\n  }\n  catch(...)\n  {\n    delete []values;\n    throw;\n  }\n  delete []values;\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/SetProperties.h",
    "content": "// SetProperties.h\n\n#ifndef __SETPROPERTIES_H\n#define __SETPROPERTIES_H\n\n#include \"Property.h\"\n\nHRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/SortUtils.cpp",
    "content": "// SortUtils.cpp\n\n#include \"StdAfx.h\"\n\n#include \"SortUtils.h\"\n#include \"Common/Wildcard.h\"\n\nstatic int CompareStrings(const int *p1, const int *p2, void *param)\n{\n  const UStringVector &strings = *(const UStringVector *)param;\n  return CompareFileNames(strings[*p1], strings[*p2]);\n}\n\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices)\n{\n  indices.Clear();\n  int numItems = strings.Size();\n  indices.Reserve(numItems);\n  for(int i = 0; i < numItems; i++)\n    indices.Add(i);\n  indices.Sort(CompareStrings, (void *)&strings);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/SortUtils.h",
    "content": "// SortUtils.h\n\n#ifndef __SORTUTLS_H\n#define __SORTUTLS_H\n\n#include \"Common/MyString.h\"\n\nvoid SortFileNames(const UStringVector &strings, CIntVector &indices);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/StdAfx.h",
    "content": "// stdafx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/TempFiles.cpp",
    "content": "// TempFiles.cpp\n\n#include \"StdAfx.h\"\n\n#include \"TempFiles.h\"\n\n#include \"Windows/FileDir.h\"\n#include \"Windows/FileIO.h\"\n\nusing namespace NWindows;\nusing namespace NFile;\n\nvoid CTempFiles::Clear()\n{\n  while(!Paths.IsEmpty())\n  {\n    NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());\n    Paths.DeleteBack();\n  }\n}\n\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/TempFiles.h",
    "content": "// TempFiles.h\n\n#ifndef __TEMPFILES_H\n#define __TEMPFILES_H\n\n#include \"Common/MyString.h\"\n\nclass CTempFiles\n{\n  void Clear();\npublic:\n  UStringVector Paths;\n  ~CTempFiles() { Clear(); }\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/Update.cpp",
    "content": "// Update.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Update.h\"\n\n#include \"Common/IntToString.h\"\n#include \"Common/StringConvert.h\"\n\n#ifdef _WIN32\n#include \"Windows/DLL.h\"\n#endif\n\n#include \"Windows/FileDir.h\"\n#include \"Windows/FileFind.h\"\n#include \"Windows/FileName.h\"\n#include \"Windows/PropVariant.h\"\n#include \"Windows/PropVariantConversions.h\"\n#include \"Windows/Time.h\"\n\n#include \"../../Common/FileStreams.h\"\n\n#include \"../../Compress/CopyCoder.h\"\n\n#include \"../Common/DirItem.h\"\n#include \"../Common/EnumDirItems.h\"\n#include \"../Common/OpenArchive.h\"\n#include \"../Common/UpdateProduce.h\"\n\n#include \"EnumDirItems.h\"\n#include \"SetProperties.h\"\n#include \"TempFiles.h\"\n#include \"UpdateCallback.h\"\n\nstatic const char *kUpdateIsNotSupoorted =\n  \"update operations are not supported for this archive\";\n\nusing namespace NWindows;\nusing namespace NCOM;\nusing namespace NFile;\nusing namespace NName;\n\nstatic const wchar_t *kTempFolderPrefix = L\"7zE\";\n\nusing namespace NUpdateArchive;\n\nstatic HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)\n{\n  CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;\n  return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);\n}\n\nclass COutMultiVolStream:\n  public IOutStream,\n  public CMyUnknownImp\n{\n  int _streamIndex; // required stream\n  UInt64 _offsetPos; // offset from start of _streamIndex index\n  UInt64 _absPos;\n  UInt64 _length;\n\n  struct CSubStreamInfo\n  {\n    COutFileStream *StreamSpec;\n    CMyComPtr<IOutStream> Stream;\n    UString Name;\n    UInt64 Pos;\n    UInt64 RealSize;\n  };\n  CObjectVector<CSubStreamInfo> Streams;\npublic:\n  // CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;\n  CRecordVector<UInt64> Sizes;\n  UString Prefix;\n  CTempFiles *TempFiles;\n\n  void Init()\n  {\n    _streamIndex = 0;\n    _offsetPos = 0;\n    _absPos = 0;\n    _length = 0;\n  }\n\n  HRESULT Close();\n\n  MY_UNKNOWN_IMP1(IOutStream)\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\n  STDMETHOD(SetSize)(Int64 newSize);\n};\n\n// static NSynchronization::CCriticalSection g_TempPathsCS;\n\nHRESULT COutMultiVolStream::Close()\n{\n  HRESULT res = S_OK;\n  for (int i = 0; i < Streams.Size(); i++)\n  {\n    CSubStreamInfo &s = Streams[i];\n    if (s.StreamSpec)\n    {\n      HRESULT res2 = s.StreamSpec->Close();\n      if (res2 != S_OK)\n        res = res2;\n    }\n  }\n  return res;\n}\n\nSTDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  if(processedSize != NULL)\n    *processedSize = 0;\n  while(size > 0)\n  {\n    if (_streamIndex >= Streams.Size())\n    {\n      CSubStreamInfo subStream;\n\n      wchar_t temp[32];\n      ConvertUInt64ToString(_streamIndex + 1, temp);\n      UString res = temp;\n      while (res.Length() < 3)\n        res = UString(L'0') + res;\n      UString name = Prefix + res;\n      subStream.StreamSpec = new COutFileStream;\n      subStream.Stream = subStream.StreamSpec;\n      if(!subStream.StreamSpec->Create(name, false))\n        return ::GetLastError();\n      {\n        // NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);\n        TempFiles->Paths.Add(name);\n      }\n\n      subStream.Pos = 0;\n      subStream.RealSize = 0;\n      subStream.Name = name;\n      Streams.Add(subStream);\n      continue;\n    }\n    CSubStreamInfo &subStream = Streams[_streamIndex];\n\n    int index = _streamIndex;\n    if (index >= Sizes.Size())\n      index = Sizes.Size() - 1;\n    UInt64 volSize = Sizes[index];\n\n    if (_offsetPos >= volSize)\n    {\n      _offsetPos -= volSize;\n      _streamIndex++;\n      continue;\n    }\n    if (_offsetPos != subStream.Pos)\n    {\n      // CMyComPtr<IOutStream> outStream;\n      // RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));\n      RINOK(subStream.Stream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));\n      subStream.Pos = _offsetPos;\n    }\n\n    UInt32 curSize = (UInt32)MyMin((UInt64)size, volSize - subStream.Pos);\n    UInt32 realProcessed;\n    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));\n    data = (void *)((Byte *)data + realProcessed);\n    size -= realProcessed;\n    subStream.Pos += realProcessed;\n    _offsetPos += realProcessed;\n    _absPos += realProcessed;\n    if (_absPos > _length)\n      _length = _absPos;\n    if (_offsetPos > subStream.RealSize)\n      subStream.RealSize = _offsetPos;\n    if(processedSize != NULL)\n      *processedSize += realProcessed;\n    if (subStream.Pos == volSize)\n    {\n      _streamIndex++;\n      _offsetPos = 0;\n    }\n    if (realProcessed == 0 && curSize != 0)\n      return E_FAIL;\n    break;\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\n{\n  if(seekOrigin >= 3)\n    return STG_E_INVALIDFUNCTION;\n  switch(seekOrigin)\n  {\n    case STREAM_SEEK_SET:\n      _absPos = offset;\n      break;\n    case STREAM_SEEK_CUR:\n      _absPos += offset;\n      break;\n    case STREAM_SEEK_END:\n      _absPos = _length + offset;\n      break;\n  }\n  _offsetPos = _absPos;\n  if (newPosition != NULL)\n    *newPosition = _absPos;\n  _streamIndex = 0;\n  return S_OK;\n}\n\nSTDMETHODIMP COutMultiVolStream::SetSize(Int64 newSize)\n{\n  if (newSize < 0)\n    return E_INVALIDARG;\n  int i = 0;\n  while (i < Streams.Size())\n  {\n    CSubStreamInfo &subStream = Streams[i++];\n    if ((UInt64)newSize < subStream.RealSize)\n    {\n      RINOK(subStream.Stream->SetSize(newSize));\n      subStream.RealSize = newSize;\n      break;\n    }\n    newSize -= subStream.RealSize;\n  }\n  while (i < Streams.Size())\n  {\n    {\n      CSubStreamInfo &subStream = Streams.Back();\n      subStream.Stream.Release();\n      NDirectory::DeleteFileAlways(subStream.Name);\n    }\n    Streams.DeleteBack();\n  }\n  _offsetPos = _absPos;\n  _streamIndex = 0;\n  _length = newSize;\n  return S_OK;\n}\n\nstatic const wchar_t *kDefaultArchiveType = L\"7z\";\nstatic const wchar_t *kSFXExtension =\n  #ifdef _WIN32\n    L\"exe\";\n  #else\n    L\"\";\n  #endif\n\nbool CUpdateOptions::Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath)\n{\n  if (formatIndices.Size() > 1)\n    return false;\n  int arcTypeIndex = -1;\n  if (formatIndices.Size() != 0)\n    arcTypeIndex = formatIndices[0];\n  if (arcTypeIndex >= 0)\n    MethodMode.FormatIndex = arcTypeIndex;\n  else\n  {\n    MethodMode.FormatIndex = codecs->FindFormatForArchiveName(arcPath);\n    if (MethodMode.FormatIndex < 0)\n      MethodMode.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArchiveType);\n  }\n  if (MethodMode.FormatIndex < 0)\n    return false;\n  const CArcInfoEx &arcInfo = codecs->Formats[MethodMode.FormatIndex];\n  if (!arcInfo.UpdateEnabled)\n    return false;\n  UString typeExt = arcInfo.GetMainExt();\n  UString ext = typeExt;\n  if (SfxMode)\n    ext = kSFXExtension;\n  ArchivePath.BaseExtension = ext;\n  ArchivePath.VolExtension = typeExt;\n  ArchivePath.ParseFromPath(arcPath);\n  for (int i = 0; i < Commands.Size(); i++)\n  {\n    CUpdateArchiveCommand &uc = Commands[i];\n    uc.ArchivePath.BaseExtension = ext;\n    uc.ArchivePath.VolExtension = typeExt;\n    uc.ArchivePath.ParseFromPath(uc.UserArchivePath);\n  }\n  return true;\n}\n\n/*\nstruct CUpdateProduceCallbackImp: public IUpdateProduceCallback\n{\n  const CObjectVector<CArcItem> *_arcItems;\n  IUpdateCallbackUI *_callback;\n  \n  CUpdateProduceCallbackImp(const CObjectVector<CArcItem> *a, \n      IUpdateCallbackUI *callback): _arcItems(a), _callback(callback) {}\n  virtual HRESULT ShowDeleteFile(int arcIndex);\n};\n\nHRESULT CUpdateProduceCallbackImp::ShowDeleteFile(int arcIndex)\n{\n  return _callback->ShowDeleteFile((*_arcItems)[arcIndex].Name);\n}\n*/\n\nstatic HRESULT Compress(\n    CCodecs *codecs,\n    const CActionSet &actionSet,\n    IInArchive *archive,\n    const CCompressionMethodMode &compressionMethod,\n    CArchivePath &archivePath,\n    const CObjectVector<CArcItem> &arcItems,\n    bool shareForWrite,\n    bool stdInMode,\n    /* const UString & stdInFileName, */\n    bool stdOutMode,\n    const CDirItems &dirItems,\n    bool sfxMode,\n    const UString &sfxModule,\n    const CRecordVector<UInt64> &volumesSizes,\n    CTempFiles &tempFiles,\n    CUpdateErrorInfo &errorInfo,\n    IUpdateCallbackUI *callback)\n{\n  CMyComPtr<IOutArchive> outArchive;\n  if(archive != NULL)\n  {\n    CMyComPtr<IInArchive> archive2 = archive;\n    HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);\n    if(result != S_OK)\n      throw kUpdateIsNotSupoorted;\n  }\n  else\n  {\n    RINOK(codecs->CreateOutArchive(compressionMethod.FormatIndex, outArchive));\n\n    #ifdef EXTERNAL_CODECS\n    {\n      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;\n      outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);\n      if (setCompressCodecsInfo)\n      {\n        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));\n      }\n    }\n    #endif\n  }\n  if (outArchive == 0)\n    throw kUpdateIsNotSupoorted;\n  \n  NFileTimeType::EEnum fileTimeType;\n  UInt32 value;\n  RINOK(outArchive->GetFileTimeType(&value));\n\n  switch(value)\n  {\n    case NFileTimeType::kWindows:\n    case NFileTimeType::kUnix:\n    case NFileTimeType::kDOS:\n      fileTimeType = (NFileTimeType::EEnum)value;\n      break;\n    default:\n      return E_FAIL;\n  }\n\n  CRecordVector<CUpdatePair2> updatePairs2;\n\n  {\n    CRecordVector<CUpdatePair> updatePairs;\n    GetUpdatePairInfoList(dirItems, arcItems, fileTimeType, updatePairs); // must be done only once!!!\n    // CUpdateProduceCallbackImp upCallback(&arcItems, callback);\n    UpdateProduce(updatePairs, actionSet, updatePairs2, NULL /* &upCallback */);\n  }\n\n  UInt32 numFiles = 0;\n  for (int i = 0; i < updatePairs2.Size(); i++)\n    if (updatePairs2[i].NewData)\n      numFiles++;\n  \n  RINOK(callback->SetNumFiles(numFiles));\n\n  \n  CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;\n  CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);\n  \n  updateCallbackSpec->ShareForWrite = shareForWrite;\n  updateCallbackSpec->StdInMode = stdInMode;\n  updateCallbackSpec->Callback = callback;\n  updateCallbackSpec->DirItems = &dirItems;\n  updateCallbackSpec->ArcItems = &arcItems;\n  updateCallbackSpec->UpdatePairs = &updatePairs2;\n\n  CMyComPtr<ISequentialOutStream> outStream;\n\n  const UString &archiveName = archivePath.GetFinalPath();\n  if (!stdOutMode)\n  {\n    UString resultPath;\n    int pos;\n    if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))\n      throw 1417161;\n    NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));\n  }\n\n  COutFileStream *outStreamSpec = NULL;\n  COutMultiVolStream *volStreamSpec = NULL;\n\n  if (volumesSizes.Size() == 0)\n  {\n    if (stdOutMode)\n      outStream = new CStdOutFileStream;\n    else\n    {\n      outStreamSpec = new COutFileStream;\n      outStream = outStreamSpec;\n      bool isOK = false;\n      UString realPath;\n      for (int i = 0; i < (1 << 16); i++)\n      {\n        if (archivePath.Temp)\n        {\n          if (i > 0)\n          {\n            wchar_t s[32];\n            ConvertUInt64ToString(i, s);\n            archivePath.TempPostfix = s;\n          }\n          realPath = archivePath.GetTempPath();\n        }\n        else\n          realPath = archivePath.GetFinalPath();\n        if (outStreamSpec->Create(realPath, false))\n        {\n          tempFiles.Paths.Add(realPath);\n          isOK = true;\n          break;\n        }\n        if (::GetLastError() != ERROR_FILE_EXISTS)\n          break;\n        if (!archivePath.Temp)\n          break;\n      }\n      if (!isOK)\n      {\n        errorInfo.SystemError = ::GetLastError();\n        errorInfo.FileName = realPath;\n        errorInfo.Message = L\"Can not open file\";\n        return E_FAIL;\n      }\n    }\n  }\n  else\n  {\n    if (stdOutMode)\n      return E_FAIL;\n    volStreamSpec = new COutMultiVolStream;\n    outStream = volStreamSpec;\n    volStreamSpec->Sizes = volumesSizes;\n    volStreamSpec->Prefix = archivePath.GetFinalPath() + UString(L\".\");\n    volStreamSpec->TempFiles = &tempFiles;\n    volStreamSpec->Init();\n\n    /*\n    updateCallbackSpec->VolumesSizes = volumesSizes;\n    updateCallbackSpec->VolName = archivePath.Prefix + archivePath.Name;\n    if (!archivePath.VolExtension.IsEmpty())\n      updateCallbackSpec->VolExt = UString(L'.') + archivePath.VolExtension;\n    */\n  }\n\n  RINOK(SetProperties(outArchive, compressionMethod.Properties));\n\n  if (sfxMode)\n  {\n    CInFileStream *sfxStreamSpec = new CInFileStream;\n    CMyComPtr<IInStream> sfxStream(sfxStreamSpec);\n    if (!sfxStreamSpec->Open(sfxModule))\n    {\n      errorInfo.SystemError = ::GetLastError();\n      errorInfo.Message = L\"Can't open sfx module\";\n      errorInfo.FileName = sfxModule;\n      return E_FAIL;\n    }\n\n    CMyComPtr<ISequentialOutStream> sfxOutStream;\n    COutFileStream *outStreamSpec = NULL;\n    if (volumesSizes.Size() == 0)\n      sfxOutStream = outStream;\n    else\n    {\n      outStreamSpec = new COutFileStream;\n      sfxOutStream = outStreamSpec;\n      UString realPath = archivePath.GetFinalPath();\n      if (!outStreamSpec->Create(realPath, false))\n      {\n        errorInfo.SystemError = ::GetLastError();\n        errorInfo.FileName = realPath;\n        errorInfo.Message = L\"Can not open file\";\n        return E_FAIL;\n      }\n    }\n    RINOK(CopyBlock(sfxStream, sfxOutStream));\n    if (outStreamSpec)\n    {\n      RINOK(outStreamSpec->Close());\n    }\n  }\n\n  HRESULT result = outArchive->UpdateItems(outStream, updatePairs2.Size(), updateCallback);\n  callback->Finilize();\n  RINOK(result);\n  if (outStreamSpec)\n    result = outStreamSpec->Close();\n  else if (volStreamSpec)\n    result = volStreamSpec->Close();\n  return result;\n}\n\nHRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,\n    IInArchive *archive,\n    const UString &defaultItemName,\n    const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,\n    CObjectVector<CArcItem> &arcItems)\n{\n  arcItems.Clear();\n  UInt32 numItems;\n  RINOK(archive->GetNumberOfItems(&numItems));\n  arcItems.Reserve(numItems);\n  for (UInt32 i = 0; i < numItems; i++)\n  {\n    CArcItem ai;\n\n    RINOK(GetArchiveItemPath(archive, i, ai.Name));\n    // check it: defaultItemName !!!\n    if (ai.Name.IsEmpty())\n      ai.Name = defaultItemName;\n    RINOK(IsArchiveItemFolder(archive, i, ai.IsDir));\n    ai.Censored = censor.CheckPath(ai.Name, !ai.IsDir);\n    RINOK(GetArchiveItemFileTime(archive, i, archiveFileInfo.MTime, ai.MTime));\n\n    {\n      CPropVariant prop;\n      RINOK(archive->GetProperty(i, kpidSize, &prop));\n      ai.SizeDefined = (prop.vt != VT_EMPTY);\n      if (ai.SizeDefined)\n        ai.Size = ConvertPropVariantToUInt64(prop);\n    }\n\n    {\n      CPropVariant prop;\n      RINOK(archive->GetProperty(i, kpidTimeType, &prop));\n      if (prop.vt == VT_UI4)\n      {\n        ai.TimeType = (int)(NFileTimeType::EEnum)prop.ulVal;\n        switch(ai.TimeType)\n        {\n          case NFileTimeType::kWindows:\n          case NFileTimeType::kUnix:\n          case NFileTimeType::kDOS:\n            break;\n          default:\n            return E_FAIL;\n        }\n      }\n    }\n\n    ai.IndexInServer = i;\n    arcItems.Add(ai);\n  }\n  return S_OK;\n}\n\n\nstatic HRESULT UpdateWithItemLists(\n    CCodecs *codecs,\n    CUpdateOptions &options,\n    IInArchive *archive,\n    const CObjectVector<CArcItem> &arcItems,\n    CDirItems &dirItems,\n    CTempFiles &tempFiles,\n    CUpdateErrorInfo &errorInfo,\n    IUpdateCallbackUI2 *callback)\n{\n  for(int i = 0; i < options.Commands.Size(); i++)\n  {\n    CUpdateArchiveCommand &command = options.Commands[i];\n    if (options.StdOutMode)\n    {\n      RINOK(callback->StartArchive(0, archive != 0));\n    }\n    else\n    {\n      RINOK(callback->StartArchive(command.ArchivePath.GetFinalPath(),\n          i == 0 && options.UpdateArchiveItself && archive != 0));\n    }\n\n    RINOK(Compress(\n        codecs,\n        command.ActionSet, archive,\n        options.MethodMode,\n        command.ArchivePath,\n        arcItems,\n        options.OpenShareForWrite,\n        options.StdInMode,\n        /* options.StdInFileName, */\n        options.StdOutMode,\n        dirItems,\n        options.SfxMode, options.SfxModule,\n        options.VolumesSizes,\n        tempFiles,\n        errorInfo, callback));\n\n    RINOK(callback->FinishArchive());\n  }\n  return S_OK;\n}\n\n#ifdef _WIN32\nclass CCurrentDirRestorer\n{\n  UString m_CurrentDirectory;\npublic:\n  CCurrentDirRestorer()\n    { NFile::NDirectory::MyGetCurrentDirectory(m_CurrentDirectory); }\n  ~CCurrentDirRestorer()\n    { RestoreDirectory();}\n  bool RestoreDirectory()\n    { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(m_CurrentDirectory)); }\n};\n#endif\n\nstruct CEnumDirItemUpdateCallback: public IEnumDirItemCallback\n{\n  IUpdateCallbackUI2 *Callback;\n  HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path)\n  {\n    return Callback->ScanProgress(numFolders, numFiles, path);\n  }\n};\n\n#ifdef _WIN32\ntypedef ULONG (FAR PASCAL MY_MAPISENDDOCUMENTS)(\n  ULONG_PTR ulUIParam,\n  LPSTR lpszDelimChar,\n  LPSTR lpszFilePaths,\n  LPSTR lpszFileNames,\n  ULONG ulReserved\n);\ntypedef MY_MAPISENDDOCUMENTS FAR *MY_LPMAPISENDDOCUMENTS;\n#endif\n\nHRESULT UpdateArchive(\n    CCodecs *codecs,\n    const NWildcard::CCensor &censor,\n    CUpdateOptions &options,\n    CUpdateErrorInfo &errorInfo,\n    IOpenCallbackUI *openCallback,\n    IUpdateCallbackUI2 *callback)\n{\n  if (options.StdOutMode && options.EMailMode)\n    return E_FAIL;\n\n  if (options.VolumesSizes.Size() > 0 && (options.EMailMode || options.SfxMode))\n    return E_NOTIMPL;\n\n  if (options.SfxMode)\n  {\n    CProperty property;\n    property.Name = L\"rsfx\";\n    property.Value = L\"on\";\n    options.MethodMode.Properties.Add(property);\n    if (options.SfxModule.IsEmpty())\n    {\n      errorInfo.Message = L\"sfx file is not specified\";\n      return E_FAIL;\n    }\n    UString name = options.SfxModule;\n    if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))\n    {\n      errorInfo.Message = L\"can't find specified sfx module\";\n      return E_FAIL;\n    }\n  }\n\n  const UString archiveName = options.ArchivePath.GetFinalPath();\n\n  UString defaultItemName;\n  NFind::CFileInfoW archiveFileInfo;\n\n  CArchiveLink archiveLink;\n  IInArchive *archive = 0;\n  if (NFind::FindFile(archiveName, archiveFileInfo))\n  {\n    if (archiveFileInfo.IsDir())\n      throw \"there is no such archive\";\n    if (options.VolumesSizes.Size() > 0)\n      return E_NOTIMPL;\n    CIntVector formatIndices;\n    if (options.MethodMode.FormatIndex >= 0)\n      formatIndices.Add(options.MethodMode.FormatIndex);\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, openCallback);\n    if (result == E_ABORT)\n      return result;\n    RINOK(callback->OpenResult(archiveName, result));\n    RINOK(result);\n    if (archiveLink.VolumePaths.Size() > 1)\n    {\n      errorInfo.SystemError = (DWORD)E_NOTIMPL;\n      errorInfo.Message = L\"Updating for multivolume archives is not implemented\";\n      return E_NOTIMPL;\n    }\n    archive = archiveLink.GetArchive();\n    defaultItemName = archiveLink.GetDefaultItemName();\n  }\n  else\n  {\n    /*\n    if (archiveType.IsEmpty())\n      throw \"type of archive is not specified\";\n    */\n  }\n\n  CDirItems dirItems;\n  if (options.StdInMode)\n  {\n    CDirItem di;\n    di.Name = options.StdInFileName;\n    di.Size = (UInt64)(Int64)-1;\n    di.Attrib = 0;\n    NTime::GetCurUtcFileTime(di.MTime);\n    di.CTime = di.ATime = di.MTime;\n    dirItems.Items.Add(di);\n  }\n  else\n  {\n    bool needScanning = false;\n    for(int i = 0; i < options.Commands.Size(); i++)\n      if (options.Commands[i].ActionSet.NeedScanning())\n        needScanning = true;\n    if (needScanning)\n    {\n      CEnumDirItemUpdateCallback enumCallback;\n      enumCallback.Callback = callback;\n      RINOK(callback->StartScanning());\n      UStringVector errorPaths;\n      CRecordVector<DWORD> errorCodes;\n      HRESULT res = EnumerateItems(censor, dirItems, &enumCallback, errorPaths, errorCodes);\n      for (int i = 0; i < errorPaths.Size(); i++)\n      {\n        RINOK(callback->CanNotFindError(errorPaths[i], errorCodes[i]));\n      }\n      if (res != S_OK)\n      {\n        if (res != E_ABORT)\n          errorInfo.Message = L\"Scanning error\";\n        // errorInfo.FileName = errorPath;\n        return res;\n      }\n      RINOK(callback->FinishScanning());\n    }\n  }\n\n  UString tempDirPrefix;\n  bool usesTempDir = false;\n  \n  #ifdef _WIN32\n  NDirectory::CTempDirectoryW tempDirectory;\n  if (options.EMailMode && options.EMailRemoveAfter)\n  {\n    tempDirectory.Create(kTempFolderPrefix);\n    tempDirPrefix = tempDirectory.GetPath();\n    NormalizeDirPathPrefix(tempDirPrefix);\n    usesTempDir = true;\n  }\n  #endif\n\n  CTempFiles tempFiles;\n\n  bool createTempFile = false;\n  if(!options.StdOutMode && options.UpdateArchiveItself)\n  {\n    CArchivePath &ap = options.Commands[0].ArchivePath;\n    ap = options.ArchivePath;\n    // if ((archive != 0 && !usesTempDir) || !options.WorkingDir.IsEmpty())\n    if ((archive != 0 || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)\n    {\n      createTempFile = true;\n      ap.Temp = true;\n      if (!options.WorkingDir.IsEmpty())\n      {\n        ap.TempPrefix = options.WorkingDir;\n        NormalizeDirPathPrefix(ap.TempPrefix);\n      }\n    }\n  }\n\n  for(int i = 0; i < options.Commands.Size(); i++)\n  {\n    CArchivePath &ap = options.Commands[i].ArchivePath;\n    if (usesTempDir)\n    {\n      // Check it\n      ap.Prefix = tempDirPrefix;\n      // ap.Temp = true;\n      // ap.TempPrefix = tempDirPrefix;\n    }\n    if (i > 0 || !createTempFile)\n    {\n      const UString &path = ap.GetFinalPath();\n      if (NFind::DoesFileExist(path))\n      {\n        errorInfo.SystemError = 0;\n        errorInfo.Message = L\"File already exists\";\n        errorInfo.FileName = path;\n        return E_FAIL;\n      }\n    }\n  }\n\n  CObjectVector<CArcItem> arcItems;\n  if (archive != NULL)\n  {\n    RINOK(EnumerateInArchiveItems(censor,\n        archive, defaultItemName, archiveFileInfo, arcItems));\n  }\n\n  RINOK(UpdateWithItemLists(codecs, options, archive, arcItems, dirItems,\n      tempFiles, errorInfo, callback));\n\n  if (archive != NULL)\n  {\n    RINOK(archiveLink.Close());\n    archiveLink.Release();\n  }\n\n  tempFiles.Paths.Clear();\n  if(createTempFile)\n  {\n    try\n    {\n      CArchivePath &ap = options.Commands[0].ArchivePath;\n      const UString &tempPath = ap.GetTempPath();\n      if (archive != NULL)\n        if (!NDirectory::DeleteFileAlways(archiveName))\n        {\n          errorInfo.SystemError = ::GetLastError();\n          errorInfo.Message = L\"delete file error\";\n          errorInfo.FileName = archiveName;\n          return E_FAIL;\n        }\n      if (!NDirectory::MyMoveFile(tempPath, archiveName))\n      {\n        errorInfo.SystemError = ::GetLastError();\n        errorInfo.Message = L\"move file error\";\n        errorInfo.FileName = tempPath;\n        errorInfo.FileName2 = archiveName;\n        return E_FAIL;\n      }\n    }\n    catch(...)\n    {\n      throw;\n    }\n  }\n\n  #ifdef _WIN32\n  if (options.EMailMode)\n  {\n    NDLL::CLibrary mapiLib;\n    if (!mapiLib.Load(TEXT(\"Mapi32.dll\")))\n    {\n      errorInfo.SystemError = ::GetLastError();\n      errorInfo.Message = L\"can not load Mapi32.dll\";\n      return E_FAIL;\n    }\n    MY_LPMAPISENDDOCUMENTS fnSend = (MY_LPMAPISENDDOCUMENTS)\n        mapiLib.GetProcAddress(\"MAPISendDocuments\");\n    if (fnSend == 0)\n    {\n      errorInfo.SystemError = ::GetLastError();\n      errorInfo.Message = L\"can not find MAPISendDocuments function\";\n      return E_FAIL;\n    }\n    UStringVector fullPaths;\n    int i;\n    for(i = 0; i < options.Commands.Size(); i++)\n    {\n      CArchivePath &ap = options.Commands[i].ArchivePath;\n      UString arcPath;\n      if(!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))\n      {\n        errorInfo.SystemError = ::GetLastError();\n        return E_FAIL;\n      }\n      fullPaths.Add(arcPath);\n    }\n    CCurrentDirRestorer curDirRestorer;\n    for(i = 0; i < fullPaths.Size(); i++)\n    {\n      UString arcPath = fullPaths[i];\n      UString fileName = ExtractFileNameFromPath(arcPath);\n      AString path = GetAnsiString(arcPath);\n      AString name = GetAnsiString(fileName);\n      // Warning!!! MAPISendDocuments function changes Current directory\n      fnSend(0, \";\", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0);\n    }\n  }\n  #endif\n  return S_OK;\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/Update.h",
    "content": "// Update.h\n\n#ifndef __UPDATE_H\n#define __UPDATE_H\n\n#include \"Common/Wildcard.h\"\n#include \"Windows/FileFind.h\"\n#include \"../../Archive/IArchive.h\"\n\n#include \"UpdateAction.h\"\n#include \"ArchiveOpenCallback.h\"\n#include \"UpdateCallback.h\"\n#include \"Property.h\"\n#include \"LoadCodecs.h\"\n\nstruct CArchivePath\n{\n  UString Prefix;   // path(folder) prefix including slash\n  UString Name; // base name\n  UString BaseExtension; // archive type extension or \"exe\" extension\n  UString VolExtension;  // archive type extension for volumes\n\n  bool Temp;\n  UString TempPrefix;  // path(folder) for temp location\n  UString TempPostfix;\n\n  CArchivePath(): Temp(false) {};\n  \n  void ParseFromPath(const UString &path)\n  {\n    SplitPathToParts(path, Prefix, Name);\n    if (Name.IsEmpty())\n      return;\n    int dotPos = Name.ReverseFind(L'.');\n    if (dotPos <= 0)\n      return;\n    if (dotPos == Name.Length() - 1)\n    {\n      Name = Name.Left(dotPos);\n      BaseExtension.Empty();\n      return;\n    }\n    if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0)\n    {\n      BaseExtension = Name.Mid(dotPos + 1);\n      Name = Name.Left(dotPos);\n    }\n    else\n      BaseExtension.Empty();\n  }\n\n  UString GetPathWithoutExt() const\n  {\n    return Prefix + Name;\n  }\n\n  UString GetFinalPath() const\n  {\n    UString path = GetPathWithoutExt();\n    if (!BaseExtension.IsEmpty())\n      path += UString(L'.') + BaseExtension;\n    return path;\n  }\n\n  \n  UString GetTempPath() const\n  {\n    UString path = TempPrefix + Name;\n    if (!BaseExtension.IsEmpty())\n      path += UString(L'.') + BaseExtension;\n    path += L\".tmp\";\n    path += TempPostfix;\n    return path;\n  }\n};\n\nstruct CUpdateArchiveCommand\n{\n  UString UserArchivePath;\n  CArchivePath ArchivePath;\n  NUpdateArchive::CActionSet ActionSet;\n};\n\nstruct CCompressionMethodMode\n{\n  int FormatIndex;\n  CObjectVector<CProperty> Properties;\n  CCompressionMethodMode(): FormatIndex(-1) {}\n};\n\nstruct CUpdateOptions\n{\n  CCompressionMethodMode MethodMode;\n\n  CObjectVector<CUpdateArchiveCommand> Commands;\n  bool UpdateArchiveItself;\n  CArchivePath ArchivePath;\n  \n  bool SfxMode;\n  UString SfxModule;\n  \n  bool OpenShareForWrite;\n\n  bool StdInMode;\n  UString StdInFileName;\n  bool StdOutMode;\n  \n  bool EMailMode;\n  bool EMailRemoveAfter;\n  UString EMailAddress;\n\n  UString WorkingDir;\n\n  bool Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath);\n\n  CUpdateOptions():\n    UpdateArchiveItself(true),\n    SfxMode(false),\n    StdInMode(false),\n    StdOutMode(false),\n    EMailMode(false),\n    EMailRemoveAfter(false),\n    OpenShareForWrite(false)\n      {};\n  CRecordVector<UInt64> VolumesSizes;\n};\n\nstruct CErrorInfo\n{\n  DWORD SystemError;\n  UString FileName;\n  UString FileName2;\n  UString Message;\n  // UStringVector ErrorPaths;\n  // CRecordVector<DWORD> ErrorCodes;\n  CErrorInfo(): SystemError(0) {};\n};\n\nstruct CUpdateErrorInfo: public CErrorInfo\n{\n};\n\n#define INTERFACE_IUpdateCallbackUI2(x) \\\n  INTERFACE_IUpdateCallbackUI(x) \\\n  virtual HRESULT OpenResult(const wchar_t *name, HRESULT result) x; \\\n  virtual HRESULT StartScanning() x; \\\n  virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) x; \\\n  virtual HRESULT CanNotFindError(const wchar_t *name, DWORD systemError) x; \\\n  virtual HRESULT FinishScanning() x; \\\n  virtual HRESULT StartArchive(const wchar_t *name, bool updating) x; \\\n  virtual HRESULT FinishArchive() x; \\\n\nstruct IUpdateCallbackUI2: public IUpdateCallbackUI\n{\n  INTERFACE_IUpdateCallbackUI2(=0)\n};\n\nHRESULT UpdateArchive(\n    CCodecs *codecs,\n    const NWildcard::CCensor &censor,\n    CUpdateOptions &options,\n    CUpdateErrorInfo &errorInfo,\n    IOpenCallbackUI *openCallback,\n    IUpdateCallbackUI2 *callback);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/UpdateAction.cpp",
    "content": "// UpdateAction.cpp\n\n#include \"StdAfx.h\"\n\n#include \"UpdateAction.h\"\n\nnamespace NUpdateArchive {\n\nconst CActionSet kAddActionSet =\n{\n  NPairAction::kCopy,\n  NPairAction::kCopy,\n  NPairAction::kCompress,\n  NPairAction::kCompress,\n  NPairAction::kCompress,\n  NPairAction::kCompress,\n  NPairAction::kCompress\n};\n\nconst CActionSet kUpdateActionSet =\n{\n  NPairAction::kCopy,\n  NPairAction::kCopy,\n  NPairAction::kCompress,\n  NPairAction::kCopy,\n  NPairAction::kCompress,\n  NPairAction::kCopy,\n  NPairAction::kCompress\n};\n\nconst CActionSet kFreshActionSet =\n{\n  NPairAction::kCopy,\n  NPairAction::kCopy,\n  NPairAction::kIgnore,\n  NPairAction::kCopy,\n  NPairAction::kCompress,\n  NPairAction::kCopy,\n  NPairAction::kCompress\n};\n\nconst CActionSet kSynchronizeActionSet =\n{\n  NPairAction::kCopy,\n  NPairAction::kIgnore,\n  NPairAction::kCompress,\n  NPairAction::kCopy,\n  NPairAction::kCompress,\n  NPairAction::kCopy,\n  NPairAction::kCompress,\n};\n\nconst CActionSet kDeleteActionSet =\n{\n  NPairAction::kCopy,\n  NPairAction::kIgnore,\n  NPairAction::kIgnore,\n  NPairAction::kIgnore,\n  NPairAction::kIgnore,\n  NPairAction::kIgnore,\n  NPairAction::kIgnore\n};\n\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/UpdateAction.h",
    "content": "// UpdateAction.h\n\n#ifndef __UPDATE_ACTION_H\n#define __UPDATE_ACTION_H\n\nnamespace NUpdateArchive {\n\n  namespace NPairState\n  {\n    const int kNumValues = 7;\n    enum EEnum\n    {\n      kNotMasked = 0,\n      kOnlyInArchive,\n      kOnlyOnDisk,\n      kNewInArchive,\n      kOldInArchive,\n      kSameFiles,\n      kUnknowNewerFiles\n    };\n  }\n  namespace NPairAction\n  {\n    enum EEnum\n    {\n      kIgnore = 0,\n      kCopy,\n      kCompress,\n      kCompressAsAnti\n    };\n  }\n  struct CActionSet\n  {\n    NPairAction::EEnum StateActions[NPairState::kNumValues];\n    bool NeedScanning() const\n    {\n      int i;\n      for (i = 0; i < NPairState::kNumValues; i++)\n        if (StateActions[i] == NPairAction::kCompress)\n          return true;\n      for (i = 1; i < NPairState::kNumValues; i++)\n        if (StateActions[i] != NPairAction::kIgnore)\n          return true;\n      return false;\n    }\n  };\n  extern const CActionSet kAddActionSet;\n  extern const CActionSet kUpdateActionSet;\n  extern const CActionSet kFreshActionSet;\n  extern const CActionSet kSynchronizeActionSet;\n  extern const CActionSet kDeleteActionSet;\n};\n\n\n#endif\n\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/UpdateCallback.cpp",
    "content": "// UpdateCallback.cpp\n\n#include \"StdAfx.h\"\n\n#include \"UpdateCallback.h\"\n\n#include \"Common/StringConvert.h\"\n#include \"Common/IntToString.h\"\n#include \"Common/Defs.h\"\n#include \"Common/ComTry.h\"\n\n#include \"Windows/PropVariant.h\"\n\n#include \"../../Common/FileStreams.h\"\n\nusing namespace NWindows;\n\nCArchiveUpdateCallback::CArchiveUpdateCallback():\n  Callback(0),\n  ShareForWrite(false),\n  StdInMode(false),\n  DirItems(0),\n  ArcItems(0),\n  UpdatePairs(0),\n  NewNames(0)\n  {}\n\n\nSTDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)\n{\n  COM_TRY_BEGIN\n  return Callback->SetTotal(size);\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)\n{\n  COM_TRY_BEGIN\n  return Callback->SetCompleted(completeValue);\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\n{\n  COM_TRY_BEGIN\n  return Callback->SetRatioInfo(inSize, outSize);\n  COM_TRY_END\n}\n\n\n/*\nSTATPROPSTG kProperties[] =\n{\n  { NULL, kpidPath, VT_BSTR},\n  { NULL, kpidIsDir, VT_BOOL},\n  { NULL, kpidSize, VT_UI8},\n  { NULL, kpidCTime, VT_FILETIME},\n  { NULL, kpidATime, VT_FILETIME},\n  { NULL, kpidMTime, VT_FILETIME},\n  { NULL, kpidAttrib, VT_UI4},\n  { NULL, kpidIsAnti, VT_BOOL}\n};\n\nSTDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)\n{\n  return CStatPropEnumerator::CreateEnumerator(kProperties, sizeof(kProperties) / sizeof(kProperties[0]), enumerator);\n}\n*/\n\nSTDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,\n      Int32 *newData, Int32 *newProps, UInt32 *indexInArchive)\n{\n  COM_TRY_BEGIN\n  RINOK(Callback->CheckBreak());\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\n  if (newData != NULL) *newData = BoolToInt(up.NewData);\n  if (newProps != NULL) *newProps = BoolToInt(up.NewProps);\n  if (indexInArchive != NULL)\n  {\n    *indexInArchive = (UInt32)-1;\n    if (up.ExistInArchive())\n      *indexInArchive = (ArcItems == 0) ? up.ArcIndex : (*ArcItems)[up.ArcIndex].IndexInServer;\n  }\n  return S_OK;\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)\n{\n  COM_TRY_BEGIN\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\n  NWindows::NCOM::CPropVariant prop;\n  \n  if (propID == kpidIsAnti)\n  {\n    prop = up.IsAnti;\n    prop.Detach(value);\n    return S_OK;\n  }\n\n  if (up.IsAnti)\n  {\n    switch(propID)\n    {\n      case kpidIsDir:\n      case kpidPath:\n        break;\n      case kpidSize:\n        prop = (UInt64)0;\n        prop.Detach(value);\n        return S_OK;\n      default:\n        prop.Detach(value);\n        return S_OK;\n    }\n  }\n  \n  if (up.ExistOnDisk())\n  {\n    const CDirItem &di = DirItems->Items[up.DirIndex];\n    switch(propID)\n    {\n      case kpidPath:  prop = DirItems->GetLogPath(up.DirIndex); break;\n      case kpidIsDir:  prop = di.IsDir(); break;\n      case kpidSize:  prop = di.Size; break;\n      case kpidAttrib:  prop = di.Attrib; break;\n      case kpidCTime:  prop = di.CTime; break;\n      case kpidATime:  prop = di.ATime; break;\n      case kpidMTime:  prop = di.MTime; break;\n    }\n  }\n  else\n  {\n    if (propID == kpidPath)\n    {\n      if (up.NewNameIndex >= 0)\n      {\n        prop = (*NewNames)[up.NewNameIndex];\n        prop.Detach(value);\n        return S_OK;\n      }\n    }\n    if (up.ExistInArchive() && Archive)\n    {\n      UInt32 indexInArchive;\n      if (ArcItems == 0)\n        indexInArchive = up.ArcIndex;\n      else\n        indexInArchive = (*ArcItems)[up.ArcIndex].IndexInServer;\n      return Archive->GetProperty(indexInArchive, propID, value);\n    }\n  }\n  prop.Detach(value);\n  return S_OK;\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)\n{\n  COM_TRY_BEGIN\n  const CUpdatePair2 &up = (*UpdatePairs)[index];\n  if (!up.NewData)\n    return E_FAIL;\n  \n  RINOK(Callback->CheckBreak());\n  RINOK(Callback->Finilize());\n\n  if (up.IsAnti)\n  {\n    return Callback->GetStream((*ArcItems)[up.ArcIndex].Name, true);\n  }\n  const CDirItem &di = DirItems->Items[up.DirIndex];\n  RINOK(Callback->GetStream(DirItems->GetLogPath(up.DirIndex), false));\n \n  if (di.IsDir())\n    return S_OK;\n\n  if (StdInMode)\n  {\n    CStdInFileStream *inStreamSpec = new CStdInFileStream;\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\n    *inStream = inStreamLoc.Detach();\n  }\n  else\n  {\n    CInFileStream *inStreamSpec = new CInFileStream;\n    CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);\n    const UString path = DirItems->GetPhyPath(up.DirIndex);\n    if (!inStreamSpec->OpenShared(path, ShareForWrite))\n    {\n      return Callback->OpenFileError(path, ::GetLastError());\n    }\n    *inStream = inStreamLoc.Detach();\n  }\n  return S_OK;\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult)\n{\n  COM_TRY_BEGIN\n  return Callback->SetOperationResult(operationResult);\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)\n{\n  if (VolumesSizes.Size() == 0)\n    return S_FALSE;\n  if (index >= (UInt32)VolumesSizes.Size())\n    index = VolumesSizes.Size() - 1;\n  *size = VolumesSizes[index];\n  return S_OK;\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)\n{\n  COM_TRY_BEGIN\n  wchar_t temp[32];\n  ConvertUInt64ToString(index + 1, temp);\n  UString res = temp;\n  while (res.Length() < 2)\n    res = UString(L'0') + res;\n  UString fileName = VolName;\n  fileName += L'.';\n  fileName += res;\n  fileName += VolExt;\n  COutFileStream *streamSpec = new COutFileStream;\n  CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);\n  if (!streamSpec->Create(fileName, false))\n    return ::GetLastError();\n  *volumeStream = streamLoc.Detach();\n  return S_OK;\n  COM_TRY_END\n}\n\nSTDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\n{\n  COM_TRY_BEGIN\n  return Callback->CryptoGetTextPassword2(passwordIsDefined, password);\n  COM_TRY_END\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/UpdateCallback.h",
    "content": "// UpdateCallback.h\n\n#ifndef __UPDATECALLBACK_H\n#define __UPDATECALLBACK_H\n\n#include \"Common/MyCom.h\"\n#include \"Common/MyString.h\"\n\n#include \"../../IPassword.h\"\n#include \"../../ICoder.h\"\n\n#include \"../Common/UpdatePair.h\"\n#include \"../Common/UpdateProduce.h\"\n\n#define INTERFACE_IUpdateCallbackUI(x) \\\n  virtual HRESULT SetTotal(UInt64 size) x; \\\n  virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \\\n  virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x; \\\n  virtual HRESULT CheckBreak() x; \\\n  virtual HRESULT Finilize() x; \\\n  virtual HRESULT SetNumFiles(UInt64 numFiles) x; \\\n  virtual HRESULT GetStream(const wchar_t *name, bool isAnti) x; \\\n  virtual HRESULT OpenFileError(const wchar_t *name, DWORD systemError) x; \\\n  virtual HRESULT SetOperationResult(Int32 operationResult) x; \\\n  virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x; \\\n  // virtual HRESULT ShowDeleteFile(const wchar_t *name) x; \\\n  // virtual HRESULT CloseProgress() { return S_OK; };\n\nstruct IUpdateCallbackUI\n{\n  INTERFACE_IUpdateCallbackUI(=0)\n};\n\nclass CArchiveUpdateCallback:\n  public IArchiveUpdateCallback2,\n  public ICryptoGetTextPassword2,\n  public ICompressProgressInfo,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP3(\n      IArchiveUpdateCallback2,\n      ICryptoGetTextPassword2,\n      ICompressProgressInfo)\n\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\n\n  INTERFACE_IArchiveUpdateCallback2(;)\n\n  STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);\n\npublic:\n  CRecordVector<UInt64> VolumesSizes;\n  UString VolName;\n  UString VolExt;\n\n  IUpdateCallbackUI *Callback;\n\n  bool ShareForWrite;\n  bool StdInMode;\n  const CDirItems *DirItems;\n  const CObjectVector<CArcItem> *ArcItems;\n  const CRecordVector<CUpdatePair2> *UpdatePairs;\n  const UStringVector *NewNames;\n  CMyComPtr<IInArchive> Archive;\n\n  CArchiveUpdateCallback();\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/UpdatePair.cpp",
    "content": "// UpdatePair.cpp\n\n#include \"StdAfx.h\"\n\n#include <time.h>\n\n#include \"Common/Defs.h\"\n#include \"Common/Wildcard.h\"\n#include \"Windows/Time.h\"\n\n#include \"UpdatePair.h\"\n#include \"SortUtils.h\"\n\nusing namespace NWindows;\nusing namespace NTime;\n\nstatic int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time1, const FILETIME &time2)\n{\n  switch(fileTimeType)\n  {\n    case NFileTimeType::kWindows:\n      return ::CompareFileTime(&time1, &time2);\n    case NFileTimeType::kUnix:\n      {\n        UInt32 unixTime1, unixTime2;\n        FileTimeToUnixTime(time1, unixTime1);\n        FileTimeToUnixTime(time2, unixTime2);\n        return MyCompare(unixTime1, unixTime2);\n      }\n    case NFileTimeType::kDOS:\n      {\n        UInt32 dosTime1, dosTime2;\n        FileTimeToDosTime(time1, dosTime1);\n        FileTimeToDosTime(time2, dosTime2);\n        return MyCompare(dosTime1, dosTime2);\n      }\n  }\n  throw 4191618;\n}\n\nstatic const wchar_t *kDuplicateFileNameMessage = L\"Duplicate filename:\";\nstatic const wchar_t *kNotCensoredCollisionMessaged = L\"Internal file name collision (file on disk, file in archive):\";\n\nstatic void ThrowError(const UString &message, const UString &s1, const UString &s2)\n{\n  UString m = message;\n  m += L'\\n';\n  m += s1;\n  m += L'\\n';\n  m += s2;\n  throw m;\n}\n\nstatic void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)\n{\n  for(int i = 0; i + 1 < indices.Size(); i++)\n    if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)\n      ThrowError(kDuplicateFileNameMessage, strings[indices[i]], strings[indices[i + 1]]);\n}\n\nvoid GetUpdatePairInfoList(\n    const CDirItems &dirItems,\n    const CObjectVector<CArcItem> &arcItems,\n    NFileTimeType::EEnum fileTimeType,\n    CRecordVector<CUpdatePair> &updatePairs)\n{\n  CIntVector dirIndices, arcIndices;\n  \n  int numDirItems = dirItems.Items.Size();\n  int numArcItems = arcItems.Size();\n  \n  \n  {\n    UStringVector arcNames;\n    arcNames.Reserve(numArcItems);\n    for (int i = 0; i < numArcItems; i++)\n      arcNames.Add(arcItems[i].Name);\n    SortFileNames(arcNames, arcIndices);\n    TestDuplicateString(arcNames, arcIndices);\n  }\n\n  UStringVector dirNames;\n  {\n    dirNames.Reserve(numDirItems);\n    for (int i = 0; i < numDirItems; i++)\n      dirNames.Add(dirItems.GetLogPath(i));\n    SortFileNames(dirNames, dirIndices);\n    TestDuplicateString(dirNames, dirIndices);\n  }\n  \n  int dirIndex = 0, arcIndex = 0;\n  while (dirIndex < numDirItems && arcIndex < numArcItems)\n  {\n    CUpdatePair pair;\n    int dirIndex2 = dirIndices[dirIndex];\n    int arcIndex2 = arcIndices[arcIndex];\n    const CDirItem &di = dirItems.Items[dirIndex2];\n    const CArcItem &ai = arcItems[arcIndex2];\n    int compareResult = CompareFileNames(dirNames[dirIndex2], ai.Name);\n    if (compareResult < 0)\n    {\n      pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\n      pair.DirIndex = dirIndex2;\n      dirIndex++;\n    }\n    else if (compareResult > 0)\n    {\n      pair.State = ai.Censored ?\n          NUpdateArchive::NPairState::kOnlyInArchive:\n          NUpdateArchive::NPairState::kNotMasked;\n      pair.ArcIndex = arcIndex2;\n      arcIndex++;\n    }\n    else\n    {\n      if (!ai.Censored)\n        ThrowError(kNotCensoredCollisionMessaged, dirNames[dirIndex2], ai.Name);\n      pair.DirIndex = dirIndex2;\n      pair.ArcIndex = arcIndex2;\n      switch (MyCompareTime(\n          ai.TimeType != - 1 ? (NFileTimeType::EEnum)ai.TimeType : fileTimeType,\n          di.MTime, ai.MTime))\n      {\n        case -1: pair.State = NUpdateArchive::NPairState::kNewInArchive; break;\n        case 1:  pair.State = NUpdateArchive::NPairState::kOldInArchive; break;\n        default:\n          if (ai.SizeDefined)\n            if (di.Size != ai.Size)\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\n            else\n              pair.State = NUpdateArchive::NPairState::kSameFiles;\n          else\n              pair.State = NUpdateArchive::NPairState::kUnknowNewerFiles;\n      }\n      dirIndex++;\n      arcIndex++;\n    }\n    updatePairs.Add(pair);\n  }\n\n  for (; dirIndex < numDirItems; dirIndex++)\n  {\n    CUpdatePair pair;\n    pair.State = NUpdateArchive::NPairState::kOnlyOnDisk;\n    pair.DirIndex = dirIndices[dirIndex];\n    updatePairs.Add(pair);\n  }\n  \n  for (; arcIndex < numArcItems; arcIndex++)\n  {\n    CUpdatePair pair;\n    int arcIndex2 = arcIndices[arcIndex];\n    pair.State = arcItems[arcIndex2].Censored ?\n        NUpdateArchive::NPairState::kOnlyInArchive:\n        NUpdateArchive::NPairState::kNotMasked;\n    pair.ArcIndex = arcIndex2;\n    updatePairs.Add(pair);\n  }\n\n  updatePairs.ReserveDown();\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/UpdatePair.h",
    "content": "// UpdatePair.h\n\n#ifndef __UPDATE_PAIR_H\n#define __UPDATE_PAIR_H\n\n#include \"DirItem.h\"\n#include \"UpdateAction.h\"\n\n#include \"../../Archive/IArchive.h\"\n\nstruct CUpdatePair\n{\n  NUpdateArchive::NPairState::EEnum State;\n  int ArcIndex;\n  int DirIndex;\n  CUpdatePair(): ArcIndex(-1), DirIndex(-1) {}\n};\n\nvoid GetUpdatePairInfoList(\n    const CDirItems &dirItems,\n    const CObjectVector<CArcItem> &arcItems,\n    NFileTimeType::EEnum fileTimeType,\n    CRecordVector<CUpdatePair> &updatePairs);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/UpdateProduce.cpp",
    "content": "// UpdateProduce.cpp\n\n#include \"StdAfx.h\"\n\n#include \"UpdateProduce.h\"\n\nusing namespace NUpdateArchive;\n\nstatic const char *kUpdateActionSetCollision = \"Internal collision in update action set\";\n\nvoid UpdateProduce(\n    const CRecordVector<CUpdatePair> &updatePairs,\n    const CActionSet &actionSet,\n    CRecordVector<CUpdatePair2> &operationChain,\n    IUpdateProduceCallback *callback)\n{\n  for (int i = 0; i < updatePairs.Size(); i++)\n  {\n    const CUpdatePair &pair = updatePairs[i];\n\n    CUpdatePair2 up2;\n    up2.IsAnti = false;\n    up2.DirIndex = pair.DirIndex;\n    up2.ArcIndex = pair.ArcIndex;\n    up2.NewData = up2.NewProps = true;\n    \n    switch(actionSet.StateActions[pair.State])\n    {\n      case NPairAction::kIgnore:\n        /*\n        if (pair.State != NPairState::kOnlyOnDisk)\n          IgnoreArchiveItem(m_ArchiveItems[pair.ArcIndex]);\n        // cout << \"deleting\";\n        */\n        if (callback)\n          callback->ShowDeleteFile(pair.ArcIndex);\n        continue;\n\n      case NPairAction::kCopy:\n        if (pair.State == NPairState::kOnlyOnDisk)\n          throw kUpdateActionSetCollision;\n        up2.NewData = up2.NewProps = false;\n        break;\n      \n      case NPairAction::kCompress:\n        if (pair.State == NPairState::kOnlyInArchive ||\n            pair.State == NPairState::kNotMasked)\n          throw kUpdateActionSetCollision;\n        break;\n      \n      case NPairAction::kCompressAsAnti:\n        up2.IsAnti = true;\n        break;\n    }\n    operationChain.Add(up2);\n  }\n  operationChain.ReserveDown();\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/UpdateProduce.h",
    "content": "// UpdateProduce.h\n\n#ifndef __UPDATE_PRODUCE_H\n#define __UPDATE_PRODUCE_H\n\n#include \"UpdatePair.h\"\n\nstruct CUpdatePair2\n{\n  bool NewData;\n  bool NewProps;\n  bool IsAnti;\n  \n  int DirIndex;\n  int ArcIndex;\n  int NewNameIndex;\n\n  bool ExistOnDisk() const { return DirIndex != -1; }\n  bool ExistInArchive() const { return ArcIndex != -1; }\n\n  CUpdatePair2(): IsAnti(false), DirIndex(-1), ArcIndex(-1), NewNameIndex(-1) {}\n};\n\nstruct IUpdateProduceCallback\n{\n  virtual HRESULT ShowDeleteFile(int arcIndex) = 0;\n};\n\nvoid UpdateProduce(\n    const CRecordVector<CUpdatePair> &updatePairs,\n    const NUpdateArchive::CActionSet &actionSet,\n    CRecordVector<CUpdatePair2> &operationChain,\n    IUpdateProduceCallback *callback);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/WorkDir.cpp",
    "content": "// WorkDir.cpp\n\n#include \"StdAfx.h\"\n\n#include \"WorkDir.h\"\n\n#include \"Common/StringConvert.h\"\n#include \"Common/Wildcard.h\"\n\n#include \"Windows/FileName.h\"\n#include \"Windows/FileDir.h\"\n\nstatic inline UINT GetCurrentCodePage()\n  { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\n\nusing namespace NWindows;\nusing namespace NFile;\nusing namespace NName;\n\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)\n{\n  NWorkDir::NMode::EEnum mode = workDirInfo.Mode;\n  if (workDirInfo.ForRemovableOnly)\n  {\n    mode = NWorkDir::NMode::kCurrent;\n    UString prefix = path.Left(3);\n    if (prefix[1] == L':' && prefix[2] == L'\\\\')\n    {\n      UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));\n      if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)\n        mode = workDirInfo.Mode;\n    }\n    /*\n    CParsedPath parsedPath;\n    parsedPath.ParsePath(archiveName);\n    UINT driveType = GetDriveType(parsedPath.Prefix);\n    if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))\n      mode = NZipSettings::NWorkDir::NMode::kCurrent;\n    */\n  }\n  switch(mode)\n  {\n    case NWorkDir::NMode::kCurrent:\n    {\n      return ExtractDirPrefixFromPath(path);\n    }\n    case NWorkDir::NMode::kSpecified:\n    {\n      UString tempDir = workDirInfo.Path;\n      NormalizeDirPathPrefix(tempDir);\n      return tempDir;\n    }\n    default:\n    {\n      UString tempDir;\n      if(!NFile::NDirectory::MyGetTempPath(tempDir))\n        throw 141717;\n      return tempDir;\n    }\n  }\n}\n\n\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/WorkDir.h",
    "content": "// WorkDir.h\n\n#ifndef __WORKDIR_H\n#define __WORKDIR_H\n\n#include \"ZipRegistry.h\"\n\nUString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Common/ZipRegistry.h",
    "content": "// ZipRegistry.h\n\n#ifndef __ZIPREGISTRY_H\n#define __ZIPREGISTRY_H\n\n#include \"Common/MyString.h\"\n#include \"Common/Types.h\"\n#include \"ExtractMode.h\"\n\nnamespace NExtract\n{\n  struct CInfo\n  {\n    NPathMode::EEnum PathMode;\n    NOverwriteMode::EEnum OverwriteMode;\n    UStringVector Paths;\n    bool ShowPassword;\n  };\n}\n\nnamespace NCompression {\n  \n  struct CFormatOptions\n  {\n    CSysString FormatID;\n    UString Options;\n    UString Method;\n    UString EncryptionMethod;\n    UInt32 Level;\n    UInt32 Dictionary;\n    UInt32 Order;\n    UInt32 BlockLogSize;\n    UInt32 NumThreads;\n    void ResetForLevelChange()\n    {\n      BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1);\n      Method.Empty();\n      // EncryptionMethod.Empty();\n      // Options.Empty();\n    }\n    CFormatOptions() { ResetForLevelChange(); }\n  };\n\n  struct CInfo\n  {\n    UStringVector HistoryArchives;\n    UInt32 Level;\n    UString ArchiveType;\n\n    CObjectVector<CFormatOptions> FormatOptionsVector;\n\n    bool ShowPassword;\n    bool EncryptHeaders;\n  };\n}\n\nnamespace NWorkDir{\n  \n  namespace NMode\n  {\n    enum EEnum\n    {\n      kSystem,\n      kCurrent,\n      kSpecified\n    };\n  }\n  struct CInfo\n  {\n    NMode::EEnum Mode;\n    UString Path;\n    bool ForRemovableOnly;\n    void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }\n    void SetDefault()\n    {\n      Mode = NMode::kSystem;\n      Path.Empty();\n      SetForRemovableOnlyDefault();\n    }\n  };\n}\n\nvoid SaveExtractionInfo(const NExtract::CInfo &info);\nvoid ReadExtractionInfo(NExtract::CInfo &info);\n\nvoid SaveCompressionInfo(const NCompression::CInfo &info);\nvoid ReadCompressionInfo(NCompression::CInfo &info);\n\nvoid SaveWorkDirInfo(const NWorkDir::CInfo &info);\nvoid ReadWorkDirInfo(NWorkDir::CInfo &info);\n\nvoid SaveCascadedMenu(bool enabled);\nbool ReadCascadedMenu();\n\nvoid SaveContextMenuStatus(UInt32 value);\nbool ReadContextMenuStatus(UInt32 &value);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/ConsoleClose.cpp",
    "content": "// ConsoleClose.cpp\n\n#include \"StdAfx.h\"\n\n#include \"ConsoleClose.h\"\n\nstatic int g_BreakCounter = 0;\nstatic const int kBreakAbortThreshold = 2;\n\nnamespace NConsoleClose {\n\nstatic BOOL WINAPI HandlerRoutine(DWORD ctrlType)\n{\n  if (ctrlType == CTRL_LOGOFF_EVENT)\n  {\n    // printf(\"\\nCTRL_LOGOFF_EVENT\\n\");\n    return TRUE;\n  }\n\n  g_BreakCounter++;\n  if (g_BreakCounter < kBreakAbortThreshold)\n    return TRUE;\n  return FALSE;\n  /*\n  switch(ctrlType)\n  {\n    case CTRL_C_EVENT:\n    case CTRL_BREAK_EVENT:\n      if (g_BreakCounter < kBreakAbortThreshold)\n      return TRUE;\n  }\n  return FALSE;\n  */\n}\n\nbool TestBreakSignal()\n{\n  /*\n  if (g_BreakCounter > 0)\n    return true;\n  */\n  return (g_BreakCounter > 0);\n}\n\nvoid CheckCtrlBreak()\n{\n  if (TestBreakSignal())\n    throw CCtrlBreakException();\n}\n\nCCtrlHandlerSetter::CCtrlHandlerSetter()\n{\n  if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))\n    throw \"SetConsoleCtrlHandler fails\";\n}\n\nCCtrlHandlerSetter::~CCtrlHandlerSetter()\n{\n  if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))\n    throw \"SetConsoleCtrlHandler fails\";\n}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/ConsoleClose.h",
    "content": "// ConsoleCloseUtils.h\n\n#ifndef __CONSOLECLOSEUTILS_H\n#define __CONSOLECLOSEUTILS_H\n\nnamespace NConsoleClose {\n\nbool TestBreakSignal();\n\nclass CCtrlHandlerSetter\n{\npublic:\n  CCtrlHandlerSetter();\n  virtual ~CCtrlHandlerSetter();\n};\n\nclass CCtrlBreakException\n{};\n\nvoid CheckCtrlBreak();\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp",
    "content": "// ExtractCallbackConsole.h\n\n#include \"StdAfx.h\"\n\n#include \"ExtractCallbackConsole.h\"\n#include \"UserInputUtils.h\"\n#include \"ConsoleClose.h\"\n\n#include \"Common/Wildcard.h\"\n\n#include \"Windows/FileDir.h\"\n#include \"Windows/FileFind.h\"\n#include \"Windows/Time.h\"\n#include \"Windows/Defs.h\"\n#include \"Windows/PropVariant.h\"\n#include \"Windows/Error.h\"\n#include \"Windows/PropVariantConversions.h\"\n\n#include \"../../Common/FilePathAutoRename.h\"\n\n#include \"../Common/ExtractingFilePath.h\"\n\nusing namespace NWindows;\nusing namespace NFile;\nusing namespace NDirectory;\n\nstatic const char *kTestString    =  \"Testing     \";\nstatic const char *kExtractString =  \"Extracting  \";\nstatic const char *kSkipString   =  \"Skipping    \";\n\n// static const char *kCantAutoRename = \"can not create file with auto name\\n\";\n// static const char *kCantRenameFile = \"can not rename existing file\\n\";\n// static const char *kCantDeleteOutputFile = \"can not delete output file \";\nstatic const char *kError = \"ERROR: \";\nstatic const char *kMemoryExceptionMessage = \"Can't allocate required memory!\";\n\nstatic const char *kProcessing = \"Processing archive: \";\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\nstatic const char *kNoFiles = \"No files to process\";\n\nstatic const char *kUnsupportedMethod = \"Unsupported Method\";\nstatic const char *kCrcFailed = \"CRC Failed\";\nstatic const char *kCrcFailedEncrypted = \"CRC Failed in encrypted file. Wrong password?\";\nstatic const char *kDataError = \"Data Error\";\nstatic const char *kDataErrorEncrypted = \"Data Error in encrypted file. Wrong password?\";\nstatic const char *kUnknownError = \"Unknown Error\";\n\nSTDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64)\n{\n  if (NConsoleClose::TestBreakSignal())\n    return E_ABORT;\n  return S_OK;\n}\n\nSTDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *)\n{\n  if (NConsoleClose::TestBreakSignal())\n    return E_ABORT;\n  return S_OK;\n}\n\nSTDMETHODIMP CExtractCallbackConsole::AskOverwrite(\n    const wchar_t *existName, const FILETIME *, const UInt64 *,\n    const wchar_t *newName, const FILETIME *, const UInt64 *,\n    Int32 *answer)\n{\n  (*OutStream) << \"file \" << existName <<\n    \"\\nalready exists. Overwrite with \" << endl;\n  (*OutStream) << newName;\n  \n  NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(OutStream);\n  \n  switch(overwriteAnswer)\n  {\n    case NUserAnswerMode::kQuit:  return E_ABORT;\n    case NUserAnswerMode::kNo:     *answer = NOverwriteAnswer::kNo; break;\n    case NUserAnswerMode::kNoAll:  *answer = NOverwriteAnswer::kNoToAll; break;\n    case NUserAnswerMode::kYesAll: *answer = NOverwriteAnswer::kYesToAll; break;\n    case NUserAnswerMode::kYes:    *answer = NOverwriteAnswer::kYes; break;\n    case NUserAnswerMode::kAutoRenameAll: *answer = NOverwriteAnswer::kAutoRename; break;\n    default: return E_FAIL;\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP CExtractCallbackConsole::PrepareOperation(const wchar_t *name, bool /* isFolder */, Int32 askExtractMode, const UInt64 *position)\n{\n  switch (askExtractMode)\n  {\n    case NArchive::NExtract::NAskMode::kExtract: (*OutStream) << kExtractString; break;\n    case NArchive::NExtract::NAskMode::kTest:    (*OutStream) << kTestString; break;\n    case NArchive::NExtract::NAskMode::kSkip:    (*OutStream) << kSkipString; break;\n  };\n  (*OutStream) << name;\n  if (position != 0)\n    (*OutStream) << \" <\" << *position << \">\";\n  return S_OK;\n}\n\nSTDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message)\n{\n  (*OutStream) << message << endl;\n  NumFileErrorsInCurrentArchive++;\n  NumFileErrors++;\n  return S_OK;\n}\n\nSTDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted)\n{\n  switch(operationResult)\n  {\n    case NArchive::NExtract::NOperationResult::kOK:\n      break;\n    default:\n    {\n      NumFileErrorsInCurrentArchive++;\n      NumFileErrors++;\n      (*OutStream) << \"     \";\n      switch(operationResult)\n      {\n        case NArchive::NExtract::NOperationResult::kUnSupportedMethod:\n          (*OutStream) << kUnsupportedMethod;\n          break;\n        case NArchive::NExtract::NOperationResult::kCRCError:\n          (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed);\n          break;\n        case NArchive::NExtract::NOperationResult::kDataError:\n          (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError);\n          break;\n        default:\n          (*OutStream) << kUnknownError;\n      }\n    }\n  }\n  (*OutStream) << endl;\n  return S_OK;\n}\n\n#ifndef _NO_CRYPTO\n\nHRESULT CExtractCallbackConsole::SetPassword(const UString &password)\n{\n  PasswordIsDefined = true;\n  Password = password;\n  return S_OK;\n}\n\nSTDMETHODIMP CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password)\n{\n  if (!PasswordIsDefined)\n  {\n    Password = GetPassword(OutStream);\n    PasswordIsDefined = true;\n  }\n  return StringToBstr(Password, password);\n}\n\n#endif\n\nHRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name)\n{\n  NumArchives++;\n  NumFileErrorsInCurrentArchive = 0;\n  (*OutStream) << endl << kProcessing << name << endl;\n  return S_OK;\n}\n\nHRESULT CExtractCallbackConsole::OpenResult(const wchar_t * /* name */, HRESULT result, bool encrypted)\n{\n  (*OutStream) << endl;\n  if (result != S_OK)\n  {\n    (*OutStream) << \"Error: \";\n    if (result == S_FALSE)\n    {\n      (*OutStream) << (encrypted ?\n        \"Can not open encrypted archive. Wrong password?\" :\n        \"Can not open file as archive\");\n    }\n    else\n    {\n      if (result == E_OUTOFMEMORY)\n        (*OutStream) << \"Can't allocate required memory\";\n      else\n        (*OutStream) << NError::MyFormatMessage(result);\n    }\n    (*OutStream) << endl;\n    NumArchiveErrors++;\n  }\n  return S_OK;\n}\n  \nHRESULT CExtractCallbackConsole::ThereAreNoFiles()\n{\n  (*OutStream) << endl << kNoFiles << endl;\n  return S_OK;\n}\n\nHRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)\n{\n  if (result == S_OK)\n  {\n    (*OutStream) << endl;\n    if (NumFileErrorsInCurrentArchive == 0)\n      (*OutStream) << kEverythingIsOk << endl;\n    else\n    {\n      NumArchiveErrors++;\n      (*OutStream) << \"Sub items Errors: \" << NumFileErrorsInCurrentArchive << endl;\n    }\n  }\n  if (result == S_OK)\n    return result;\n  NumArchiveErrors++;\n  if (result == E_ABORT || result == ERROR_DISK_FULL)\n    return result;\n  (*OutStream) << endl << kError;\n  if (result == E_OUTOFMEMORY)\n    (*OutStream) << kMemoryExceptionMessage;\n  else\n  {\n    UString message;\n    NError::MyFormatMessage(result, message);\n    (*OutStream) << message;\n  }\n  (*OutStream) << endl;\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/ExtractCallbackConsole.h",
    "content": "// ExtractCallbackConsole.h\n\n#ifndef __EXTRACTCALLBACKCONSOLE_H\n#define __EXTRACTCALLBACKCONSOLE_H\n\n#include \"Common/MyString.h\"\n#include \"Common/StdOutStream.h\"\n#include \"../../Common/FileStreams.h\"\n#include \"../../IPassword.h\"\n#include \"../../Archive/IArchive.h\"\n#include \"../Common/ArchiveExtractCallback.h\"\n\nclass CExtractCallbackConsole:\n  public IExtractCallbackUI,\n  #ifndef _NO_CRYPTO\n  public ICryptoGetTextPassword,\n  #endif\n  public CMyUnknownImp\n{\npublic:\n  MY_QUERYINTERFACE_BEGIN2(IFolderArchiveExtractCallback)\n  #ifndef _NO_CRYPTO\n  MY_QUERYINTERFACE_ENTRY(ICryptoGetTextPassword)\n  #endif\n  MY_QUERYINTERFACE_END\n  MY_ADDREF_RELEASE\n\n  STDMETHOD(SetTotal)(UInt64 total);\n  STDMETHOD(SetCompleted)(const UInt64 *completeValue);\n\n  // IFolderArchiveExtractCallback\n  STDMETHOD(AskOverwrite)(\n      const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,\n      const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,\n      Int32 *answer);\n  STDMETHOD (PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position);\n\n  STDMETHOD(MessageError)(const wchar_t *message);\n  STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted);\n\n  HRESULT BeforeOpen(const wchar_t *name);\n  HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted);\n  HRESULT ThereAreNoFiles();\n  HRESULT ExtractResult(HRESULT result);\n\n \n  #ifndef _NO_CRYPTO\n  HRESULT SetPassword(const UString &password);\n  STDMETHOD(CryptoGetTextPassword)(BSTR *password);\n\n  bool PasswordIsDefined;\n  UString Password;\n\n  #endif\n  \n  UInt64 NumArchives;\n  UInt64 NumArchiveErrors;\n  UInt64 NumFileErrors;\n  UInt64 NumFileErrorsInCurrentArchive;\n\n  CStdOutStream *OutStream;\n\n  void Init()\n  {\n    NumArchives = 0;\n    NumArchiveErrors = 0;\n    NumFileErrors = 0;\n    NumFileErrorsInCurrentArchive = 0;\n  }\n\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/List.cpp",
    "content": "// List.cpp\n\n#include \"StdAfx.h\"\n\n#include \"List.h\"\n#include \"ConsoleClose.h\"\n\n#include \"Common/StringConvert.h\"\n#include \"Common/StdOutStream.h\"\n#include \"Common/IntToString.h\"\n#include \"Common/MyCom.h\"\n\n#include \"Windows/PropVariant.h\"\n#include \"Windows/Defs.h\"\n#include \"Windows/PropVariantConversions.h\"\n#include \"Windows/FileDir.h\"\n#include \"Windows/Error.h\"\n\n#include \"../../Archive/IArchive.h\"\n\n#include \"../Common/PropIDUtils.h\"\n#include \"../Common/OpenArchive.h\"\n\n#include \"OpenCallbackConsole.h\"\n\nusing namespace NWindows;\n\nstruct CPropIdToName\n{\n  PROPID PropID;\n  const wchar_t *Name;\n};\n\nstatic CPropIdToName kPropIdToName[] =\n{\n  { kpidPath, L\"Path\" },\n  { kpidName, L\"Name\" },\n  { kpidIsDir, L\"Folder\" },\n  { kpidSize, L\"Size\" },\n  { kpidPackSize, L\"Packed Size\" },\n  { kpidAttrib, L\"Attributes\" },\n  { kpidCTime, L\"Created\" },\n  { kpidATime, L\"Accessed\" },\n  { kpidMTime, L\"Modified\" },\n  { kpidSolid, L\"Solid\" },\n  { kpidCommented, L\"Commented\" },\n  { kpidEncrypted, L\"Encrypted\" },\n  { kpidSplitBefore, L\"Split Before\" },\n  { kpidSplitAfter, L\"Split After\" },\n  { kpidDictionarySize, L\"Dictionary Size\" },\n  { kpidCRC, L\"CRC\" },\n  { kpidType, L\"Type\" },\n  { kpidIsAnti, L\"Anti\" },\n  { kpidMethod, L\"Method\" },\n  { kpidHostOS, L\"Host OS\" },\n  { kpidFileSystem, L\"File System\" },\n  { kpidUser, L\"User\" },\n  { kpidGroup, L\"Group\" },\n  { kpidBlock, L\"Block\" },\n  { kpidComment, L\"Comment\" },\n  { kpidPosition, L\"Position\" },\n  { kpidPrefix, L\"Prefix\" },\n  { kpidNumSubDirs, L\"Folders\" },\n  { kpidNumSubFiles, L\"Files\" },\n  { kpidUnpackVer, L\"Version\" },\n  { kpidVolume, L\"Volume\" },\n  { kpidIsVolume, L\"Multivolume\" },\n  { kpidOffset, L\"Offset\" },\n  { kpidLinks, L\"Links\" },\n  { kpidNumBlocks, L\"Blocks\" },\n  { kpidNumVolumes, L\"Volumes\" },\n\n  { kpidBit64, L\"64-bit\" },\n  { kpidBigEndian, L\"Big-endian\" },\n  { kpidCpu, L\"CPU\" },\n  { kpidPhySize, L\"Physical Size\" },\n  { kpidHeadersSize, L\"Headers Size\" },\n  { kpidChecksum, L\"Checksum\" },\n  { kpidCharacts, L\"Characteristics\" },\n  { kpidVa, L\"Virtual Address\" },\n  { kpidFreeSpace, L\"Free Space\" },\n  { kpidClusterSize, L\"Cluster Size\" }\n};\n\nstatic const char kEmptyAttribChar = '.';\n\nstatic const char *kListing = \"Listing archive: \";\nstatic const wchar_t *kFilesMessage = L\"files\";\nstatic const wchar_t *kDirsMessage = L\"folders\";\n\nstatic void GetAttribString(DWORD wa, bool isDir, char *s)\n{\n  s[0] = ((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : kEmptyAttribChar;\n  s[1] = ((wa & FILE_ATTRIBUTE_READONLY) != 0) ? 'R': kEmptyAttribChar;\n  s[2] = ((wa & FILE_ATTRIBUTE_HIDDEN) != 0) ? 'H': kEmptyAttribChar;\n  s[3] = ((wa & FILE_ATTRIBUTE_SYSTEM) != 0) ? 'S': kEmptyAttribChar;\n  s[4] = ((wa & FILE_ATTRIBUTE_ARCHIVE) != 0) ? 'A': kEmptyAttribChar;\n  s[5] = '\\0';\n}\n\nenum EAdjustment\n{\n  kLeft,\n  kCenter,\n  kRight\n};\n\nstruct CFieldInfo\n{\n  PROPID PropID;\n  UString Name;\n  EAdjustment TitleAdjustment;\n  EAdjustment TextAdjustment;\n  int PrefixSpacesWidth;\n  int Width;\n};\n\nstruct CFieldInfoInit\n{\n  PROPID PropID;\n  const wchar_t *Name;\n  EAdjustment TitleAdjustment;\n  EAdjustment TextAdjustment;\n  int PrefixSpacesWidth;\n  int Width;\n};\n\nCFieldInfoInit kStandardFieldTable[] =\n{\n  { kpidMTime, L\"   Date      Time\", kLeft, kLeft, 0, 19 },\n  { kpidAttrib, L\"Attr\", kRight, kCenter, 1, 5 },\n  { kpidSize, L\"Size\", kRight, kRight, 1, 12 },\n  { kpidPackSize, L\"Compressed\", kRight, kRight, 1, 12 },\n  { kpidPath, L\"Name\", kLeft, kLeft, 2, 24 }\n};\n\nvoid PrintSpaces(int numSpaces)\n{\n  for (int i = 0; i < numSpaces; i++)\n    g_StdOut << ' ';\n}\n\nvoid PrintString(EAdjustment adjustment, int width, const UString &textString)\n{\n  const int numSpaces = width - textString.Length();\n  int numLeftSpaces = 0;\n  switch (adjustment)\n  {\n    case kLeft:\n      numLeftSpaces = 0;\n      break;\n    case kCenter:\n      numLeftSpaces = numSpaces / 2;\n      break;\n    case kRight:\n      numLeftSpaces = numSpaces;\n      break;\n  }\n  PrintSpaces(numLeftSpaces);\n  g_StdOut << textString;\n  PrintSpaces(numSpaces - numLeftSpaces);\n}\n\nclass CFieldPrinter\n{\n  CObjectVector<CFieldInfo> _fields;\npublic:\n  void Clear() { _fields.Clear(); }\n  void Init(const CFieldInfoInit *standardFieldTable, int numItems);\n  HRESULT Init(IInArchive *archive);\n  void PrintTitle();\n  void PrintTitleLines();\n  HRESULT PrintItemInfo(IInArchive *archive,\n      const UString &defaultItemName,\n      UInt32 index,\n      bool techMode);\n  HRESULT PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\n      const UInt64 *size, const UInt64 *compressedSize);\n};\n\nvoid CFieldPrinter::Init(const CFieldInfoInit *standardFieldTable, int numItems)\n{\n  Clear();\n  for (int i = 0; i < numItems; i++)\n  {\n    CFieldInfo fieldInfo;\n    const CFieldInfoInit &fieldInfoInit = standardFieldTable[i];\n    fieldInfo.PropID = fieldInfoInit.PropID;\n    fieldInfo.Name = fieldInfoInit.Name;\n    fieldInfo.TitleAdjustment = fieldInfoInit.TitleAdjustment;\n    fieldInfo.TextAdjustment = fieldInfoInit.TextAdjustment;\n    fieldInfo.PrefixSpacesWidth = fieldInfoInit.PrefixSpacesWidth;\n    fieldInfo.Width = fieldInfoInit.Width;\n    _fields.Add(fieldInfo);\n  }\n}\n\nstatic UString GetPropName(PROPID propID, BSTR name)\n{\n  for (int i = 0; i < sizeof(kPropIdToName) / sizeof(kPropIdToName[0]); i++)\n  {\n    const CPropIdToName &propIdToName = kPropIdToName[i];\n    if (propIdToName.PropID == propID)\n      return propIdToName.Name;\n  }\n  if (name)\n    return name;\n  wchar_t s[32];\n  ConvertUInt64ToString(propID, s);\n  return s;\n}\n\nHRESULT CFieldPrinter::Init(IInArchive *archive)\n{\n  Clear();\n  UInt32 numProps;\n  RINOK(archive->GetNumberOfProperties(&numProps));\n  for (UInt32 i = 0; i < numProps; i++)\n  {\n    CMyComBSTR name;\n    PROPID propID;\n    VARTYPE vt;\n    RINOK(archive->GetPropertyInfo(i, &name, &propID, &vt));\n    CFieldInfo fieldInfo;\n    fieldInfo.PropID = propID;\n    fieldInfo.Name = GetPropName(propID, name);\n    _fields.Add(fieldInfo);\n  }\n  return S_OK;\n}\n\nvoid CFieldPrinter::PrintTitle()\n{\n  for (int i = 0; i < _fields.Size(); i++)\n  {\n    const CFieldInfo &fieldInfo = _fields[i];\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\n    PrintString(fieldInfo.TitleAdjustment,\n      ((fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width), fieldInfo.Name);\n  }\n}\n\nvoid CFieldPrinter::PrintTitleLines()\n{\n  for (int i = 0; i < _fields.Size(); i++)\n  {\n    const CFieldInfo &fieldInfo = _fields[i];\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\n    for (int i = 0; i < fieldInfo.Width; i++)\n      g_StdOut << '-';\n  }\n}\n\n\nBOOL IsFileTimeZero(CONST FILETIME *lpFileTime)\n{\n  return (lpFileTime->dwLowDateTime == 0) && (lpFileTime->dwHighDateTime == 0);\n}\n\nstatic const char *kEmptyTimeString = \"                   \";\nvoid PrintTime(const NCOM::CPropVariant &prop)\n{\n  if (prop.vt != VT_FILETIME)\n    throw \"incorrect item\";\n  if (IsFileTimeZero(&prop.filetime))\n    g_StdOut << kEmptyTimeString;\n  else\n  {\n    FILETIME localFileTime;\n    if (!FileTimeToLocalFileTime(&prop.filetime, &localFileTime))\n      throw \"FileTimeToLocalFileTime error\";\n    char s[32];\n    if (ConvertFileTimeToString(localFileTime, s, true, true))\n      g_StdOut << s;\n    else\n      g_StdOut << kEmptyTimeString;\n  }\n}\n\nHRESULT CFieldPrinter::PrintItemInfo(IInArchive *archive,\n    const UString &defaultItemName,\n    UInt32 index,\n    bool techMode)\n{\n  /*\n  if (techMode)\n  {\n    g_StdOut << \"Index = \";\n    g_StdOut << (UInt64)index;\n    g_StdOut << endl;\n  }\n  */\n  for (int i = 0; i < _fields.Size(); i++)\n  {\n    const CFieldInfo &fieldInfo = _fields[i];\n    if (!techMode)\n      PrintSpaces(fieldInfo.PrefixSpacesWidth);\n\n    NCOM::CPropVariant prop;\n    if (fieldInfo.PropID == kpidPath)\n    {\n      UString s;\n      RINOK(GetArchiveItemPath(archive, index, defaultItemName, s));\n      prop = s;\n    }\n    else\n    {\n      RINOK(archive->GetProperty(index, fieldInfo.PropID, &prop));\n    }\n    if (techMode)\n    {\n      g_StdOut << fieldInfo.Name << \" = \";\n    }\n    int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width;\n    if (prop.vt == VT_EMPTY)\n    {\n      switch(fieldInfo.PropID)\n      {\n        case kpidPath:  prop = defaultItemName; break;\n        default:\n          if (techMode)\n            g_StdOut << endl;\n          else\n            PrintSpaces(width);\n          continue;\n      }\n    }\n    if (fieldInfo.PropID == kpidMTime)\n    {\n      PrintTime(prop);\n    }\n    else if (fieldInfo.PropID == kpidAttrib)\n    {\n      if (prop.vt != VT_UI4)\n        throw \"incorrect item\";\n      UInt32 attributes = prop.ulVal;\n      bool isFolder;\n      RINOK(IsArchiveItemFolder(archive, index, isFolder));\n      char s[8];\n      GetAttribString(attributes, isFolder, s);\n      g_StdOut << s;\n    }\n    else if (prop.vt == VT_BSTR)\n    {\n      if (techMode)\n        g_StdOut << prop.bstrVal;\n      else\n        PrintString(fieldInfo.TextAdjustment, width, prop.bstrVal);\n    }\n    else\n    {\n      UString s = ConvertPropertyToString(prop, fieldInfo.PropID);\n      s.Replace(wchar_t(0xA), L' ');\n      s.Replace(wchar_t(0xD), L' ');\n\n      if (techMode)\n        g_StdOut << s;\n      else\n        PrintString(fieldInfo.TextAdjustment, width, s);\n    }\n    if (techMode)\n      g_StdOut << endl;\n  }\n  return S_OK;\n}\n\nvoid PrintNumberString(EAdjustment adjustment, int width, const UInt64 *value)\n{\n  wchar_t textString[32] = { 0 };\n  if (value != NULL)\n    ConvertUInt64ToString(*value, textString);\n  PrintString(adjustment, width, textString);\n}\n\n\nHRESULT CFieldPrinter::PrintSummaryInfo(UInt64 numFiles, UInt64 numDirs,\n    const UInt64 *size, const UInt64 *compressedSize)\n{\n  for (int i = 0; i < _fields.Size(); i++)\n  {\n    const CFieldInfo &fieldInfo = _fields[i];\n    PrintSpaces(fieldInfo.PrefixSpacesWidth);\n    NCOM::CPropVariant prop;\n    if (fieldInfo.PropID == kpidSize)\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, size);\n    else if (fieldInfo.PropID == kpidPackSize)\n      PrintNumberString(fieldInfo.TextAdjustment, fieldInfo.Width, compressedSize);\n    else if (fieldInfo.PropID == kpidPath)\n    {\n      wchar_t textString[32];\n      ConvertUInt64ToString(numFiles, textString);\n      UString temp = textString;\n      temp += L\" \";\n      temp += kFilesMessage;\n      temp += L\", \";\n      ConvertUInt64ToString(numDirs, textString);\n      temp += textString;\n      temp += L\" \";\n      temp += kDirsMessage;\n      PrintString(fieldInfo.TextAdjustment, 0, temp);\n    }\n    else\n      PrintString(fieldInfo.TextAdjustment, fieldInfo.Width, L\"\");\n  }\n  return S_OK;\n}\n\nbool GetUInt64Value(IInArchive *archive, UInt32 index, PROPID propID, UInt64 &value)\n{\n  NCOM::CPropVariant prop;\n  if (archive->GetProperty(index, propID, &prop) != S_OK)\n    throw \"GetPropertyValue error\";\n  if (prop.vt == VT_EMPTY)\n    return false;\n  value = ConvertPropVariantToUInt64(prop);\n  return true;\n}\n\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\n    const NWildcard::CCensorNode &wildcardCensor,\n    bool enableHeaders, bool techMode,\n    #ifndef _NO_CRYPTO\n    bool &passwordEnabled, UString &password,\n    #endif\n    UInt64 &numErrors)\n{\n  numErrors = 0;\n  CFieldPrinter fieldPrinter;\n  if (!techMode)\n    fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));\n\n  UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;\n  UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;\n  for (int i = 0; i < archivePaths.Size(); i++)\n  {\n    const UString &archiveName = archivePaths[i];\n    NFile::NFind::CFileInfoW fi;\n    if (!NFile::NFind::FindFile(archiveName, fi) || fi.IsDir())\n    {\n      g_StdOut << endl << \"Error: \" << archiveName << \" is not file\" << endl;\n      numErrors++;\n      continue;\n    }\n\n    CArchiveLink archiveLink;\n\n    COpenCallbackConsole openCallback;\n    openCallback.OutStream = &g_StdOut;\n\n    #ifndef _NO_CRYPTO\n\n    openCallback.PasswordIsDefined = passwordEnabled;\n    openCallback.Password = password;\n\n    #endif\n\n    HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, &openCallback);\n    if (result != S_OK)\n    {\n      if (result == E_ABORT)\n        return result;\n      g_StdOut << endl << \"Error: \" << archiveName << \": \";\n      if (result == S_FALSE)\n        g_StdOut << \"is not supported archive\";\n      else if (result == E_OUTOFMEMORY)\n        g_StdOut << \"Can't allocate required memory\";\n      else\n        g_StdOut << NError::MyFormatMessage(result);\n      g_StdOut << endl;\n      numErrors++;\n      continue;\n    }\n\n    for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)\n    {\n      int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);\n      if (index >= 0 && index > i)\n      {\n        archivePaths.Delete(index);\n        archivePathsFull.Delete(index);\n      }\n    }\n\n    IInArchive *archive = archiveLink.GetArchive();\n    const UString defaultItemName = archiveLink.GetDefaultItemName();\n\n    if (enableHeaders)\n    {\n      g_StdOut << endl << kListing << archiveName << endl << endl;\n\n      UInt32 numProps;\n      if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)\n      {\n        for (UInt32 i = 0; i < numProps; i++)\n        {\n          CMyComBSTR name;\n          PROPID propID;\n          VARTYPE vt;\n          if (archive->GetArchivePropertyInfo(i, &name, &propID, &vt) != S_OK)\n            continue;\n          NCOM::CPropVariant prop;\n          if (archive->GetArchiveProperty(propID, &prop) != S_OK)\n            continue;\n          UString s = ConvertPropertyToString(prop, propID);\n          if (!s.IsEmpty())\n            g_StdOut << GetPropName(propID, name) << \" = \" << s << endl;\n        }\n      }\n      if (techMode)\n        g_StdOut << \"----------\\n\";\n      if (numProps > 0)\n        g_StdOut << endl;\n    }\n\n    if (enableHeaders && !techMode)\n    {\n      fieldPrinter.PrintTitle();\n      g_StdOut << endl;\n      fieldPrinter.PrintTitleLines();\n      g_StdOut << endl;\n    }\n\n    if (techMode)\n    {\n      RINOK(fieldPrinter.Init(archive));\n    }\n    UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0;\n    UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;\n    UInt32 numItems;\n    RINOK(archive->GetNumberOfItems(&numItems));\n    for(UInt32 i = 0; i < numItems; i++)\n    {\n      if (NConsoleClose::TestBreakSignal())\n        return E_ABORT;\n\n      UString filePath;\n      RINOK(GetArchiveItemPath(archive, i, defaultItemName, filePath));\n\n      bool isFolder;\n      RINOK(IsArchiveItemFolder(archive, i, isFolder));\n      if (!wildcardCensor.CheckPath(filePath, !isFolder))\n        continue;\n      \n      fieldPrinter.PrintItemInfo(archive, defaultItemName, i, techMode);\n      \n      UInt64 packSize, unpackSize;\n      if (!GetUInt64Value(archive, i, kpidSize, unpackSize))\n        unpackSize = 0;\n      else\n        totalUnPackSizePointer = &totalUnPackSize;\n      if (!GetUInt64Value(archive, i, kpidPackSize, packSize))\n        packSize = 0;\n      else\n        totalPackSizePointer = &totalPackSize;\n      \n      g_StdOut << endl;\n\n      if (isFolder)\n        numDirs++;\n      else\n        numFiles++;\n      totalPackSize += packSize;\n      totalUnPackSize += unpackSize;\n    }\n    if (enableHeaders && !techMode)\n    {\n      fieldPrinter.PrintTitleLines();\n      g_StdOut << endl;\n      fieldPrinter.PrintSummaryInfo(numFiles, numDirs, totalUnPackSizePointer, totalPackSizePointer);\n      g_StdOut << endl;\n    }\n    if (totalPackSizePointer != 0)\n    {\n      totalPackSizePointer2 = &totalPackSize2;\n      totalPackSize2 += totalPackSize;\n    }\n    if (totalUnPackSizePointer != 0)\n    {\n      totalUnPackSizePointer2 = &totalUnPackSize2;\n      totalUnPackSize2 += totalUnPackSize;\n    }\n    numFiles2 += numFiles;\n    numDirs2 += numDirs;\n  }\n  if (enableHeaders && !techMode && archivePaths.Size() > 1)\n  {\n    g_StdOut << endl;\n    fieldPrinter.PrintTitleLines();\n    g_StdOut << endl;\n    fieldPrinter.PrintSummaryInfo(numFiles2, numDirs2, totalUnPackSizePointer2, totalPackSizePointer2);\n    g_StdOut << endl;\n    g_StdOut << \"Archives: \" << archivePaths.Size() << endl;\n  }\n  return S_OK;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/List.h",
    "content": "// List.h\n\n#ifndef __LIST_H\n#define __LIST_H\n\n#include \"Common/Wildcard.h\"\n#include \"../Common/LoadCodecs.h\"\n\nHRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,\n    UStringVector &archivePaths, UStringVector &archivePathsFull,\n    const NWildcard::CCensorNode &wildcardCensor,\n    bool enableHeaders, bool techMode,\n    #ifndef _NO_CRYPTO\n    bool &passwordEnabled, UString &password,\n    #endif\n    UInt64 &errors);\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/Main.cpp",
    "content": "// Main.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Common/MyInitGuid.h\"\n\n#include \"Common/CommandLineParser.h\"\n#include \"Common/MyException.h\"\n#include \"Common/IntToString.h\"\n#include \"Common/StdOutStream.h\"\n#include \"Common/StringConvert.h\"\n#include \"Common/StringToInt.h\"\n\n#include \"Windows/FileDir.h\"\n#include \"Windows/FileName.h\"\n#include \"Windows/Defs.h\"\n#include \"Windows/Error.h\"\n#ifdef _WIN32\n#include \"Windows/MemoryLock.h\"\n#endif\n\n#include \"../../IPassword.h\"\n#include \"../../ICoder.h\"\n#include \"../Common/UpdateAction.h\"\n#include \"../Common/Update.h\"\n#include \"../Common/Extract.h\"\n#include \"../Common/ArchiveCommandLine.h\"\n#include \"../Common/ExitCode.h\"\n#ifdef EXTERNAL_CODECS\n#include \"../Common/LoadCodecs.h\"\n#endif\n\n#include \"../../Compress/LZMA_Alone/LzmaBenchCon.h\"\n\n#include \"List.h\"\n#include \"OpenCallbackConsole.h\"\n#include \"ExtractCallbackConsole.h\"\n#include \"UpdateCallbackConsole.h\"\n\n#include \"../../MyVersion.h\"\n\n#if defined( _WIN32) && defined( _7ZIP_LARGE_PAGES)\nextern \"C\"\n{\n#include \"../../../../C/Alloc.h\"\n}\n#endif\n\nusing namespace NWindows;\nusing namespace NFile;\nusing namespace NCommandLineParser;\n\nHINSTANCE g_hInstance = 0;\nextern CStdOutStream *g_StdStream;\n\nstatic const char *kCopyrightString = \"\\n7-Zip\"\n#ifndef EXTERNAL_CODECS\n\" (A)\"\n#endif\n\n#ifdef _WIN64\n\" [64]\"\n#endif\n\n\" \" MY_VERSION_COPYRIGHT_DATE \"\\n\";\n\nstatic const char *kHelpString =\n    \"\\nUsage: 7z\"\n#ifdef _NO_CRYPTO\n    \"r\"\n#else\n#ifndef EXTERNAL_CODECS\n    \"a\"\n#endif\n#endif\n    \" <command> [<switches>...] <archive_name> [<file_names>...]\\n\"\n    \"       [<@listfiles...>]\\n\"\n    \"\\n\"\n    \"<Commands>\\n\"\n    \"  a: Add files to archive\\n\"\n    \"  b: Benchmark\\n\"\n    \"  d: Delete files from archive\\n\"\n    \"  e: Extract files from archive (without using directory names)\\n\"\n    \"  l: List contents of archive\\n\"\n//    \"  l[a|t][f]: List contents of archive\\n\"\n//    \"    a - with Additional fields\\n\"\n//    \"    t - with all fields\\n\"\n//    \"    f - with Full pathnames\\n\"\n    \"  t: Test integrity of archive\\n\"\n    \"  u: Update files to archive\\n\"\n    \"  x: eXtract files with full paths\\n\"\n    \"<Switches>\\n\"\n    \"  -ai[r[-|0]]{@listfile|!wildcard}: Include archives\\n\"\n    \"  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives\\n\"\n    \"  -bd: Disable percentage indicator\\n\"\n    \"  -i[r[-|0]]{@listfile|!wildcard}: Include filenames\\n\"\n    \"  -m{Parameters}: set compression Method\\n\"\n    \"  -o{Directory}: set Output directory\\n\"\n    #ifndef _NO_CRYPTO\n    \"  -p{Password}: set Password\\n\"\n    #endif\n    \"  -r[-|0]: Recurse subdirectories\\n\"\n    \"  -scs{UTF-8 | WIN | DOS}: set charset for list files\\n\"\n    \"  -sfx[{name}]: Create SFX archive\\n\"\n    \"  -si[{name}]: read data from stdin\\n\"\n    \"  -slt: show technical information for l (List) command\\n\"\n    \"  -so: write data to stdout\\n\"\n    \"  -ssc[-]: set sensitive case mode\\n\"\n    \"  -ssw: compress shared files\\n\"\n    \"  -t{Type}: Set type of archive\\n\"\n    \"  -v{Size}[b|k|m|g]: Create volumes\\n\"\n    \"  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options\\n\"\n    \"  -w[{path}]: assign Work directory. Empty path means a temporary directory\\n\"\n    \"  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames\\n\"\n    \"  -y: assume Yes on all queries\\n\";\n\n// ---------------------------\n// exception messages\n\nstatic const char *kEverythingIsOk = \"Everything is Ok\";\nstatic const char *kUserErrorMessage  = \"Incorrect command line\"; // NExitCode::kUserError\nstatic const char *kNoFormats = \"7-Zip cannot find the code that works with archives.\";\n\nstatic const wchar_t *kDefaultSfxModule = L\"7zCon.sfx\";\n\nstatic void ShowMessageAndThrowException(CStdOutStream &s, LPCSTR message, NExitCode::EEnum code)\n{\n  s << message << endl;\n  throw code;\n}\n\nstatic void PrintHelpAndExit(CStdOutStream &s) // yyy\n{\n  s << kHelpString;\n  ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError);\n}\n\n#ifndef _WIN32\nstatic void GetArguments(int numArguments, const char *arguments[], UStringVector &parts)\n{\n  parts.Clear();\n  for(int i = 0; i < numArguments; i++)\n  {\n    UString s = MultiByteToUnicodeString(arguments[i]);\n    parts.Add(s);\n  }\n}\n#endif\n\nstatic void ShowCopyrightAndHelp(CStdOutStream &s, bool needHelp)\n{\n  s << kCopyrightString;\n  // s << \"# CPUs: \" << (UInt64)NWindows::NSystem::GetNumberOfProcessors() << \"\\n\";\n  if (needHelp)\n    s << kHelpString;\n}\n\n#ifdef EXTERNAL_CODECS\nstatic void PrintString(CStdOutStream &stdStream, const AString &s, int size)\n{\n  int len = s.Length();\n  stdStream << s;\n  for (int i = len; i < size; i++)\n    stdStream << ' ';\n}\n#endif\n\nstatic void PrintString(CStdOutStream &stdStream, const UString &s, int size)\n{\n  int len = s.Length();\n  stdStream << s;\n  for (int i = len; i < size; i++)\n    stdStream << ' ';\n}\n\nstatic inline char GetHex(Byte value)\n{\n  return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));\n}\n\nconst char *kUnsupportedArcTypeMessage = \"Unsupported archive type\";\n\nint Main2(\n  #ifndef _WIN32\n  int numArguments, const char *arguments[]\n  #endif\n)\n{\n  #ifdef _WIN32\n  SetFileApisToOEM();\n  #endif\n  \n  UStringVector commandStrings;\n  #ifdef _WIN32\n  NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);\n  #else\n  GetArguments(numArguments, arguments, commandStrings);\n  #endif\n\n  if(commandStrings.Size() == 1)\n  {\n    ShowCopyrightAndHelp(g_StdOut, true);\n    return 0;\n  }\n  commandStrings.Delete(0);\n\n  CArchiveCommandLineOptions options;\n\n  CArchiveCommandLineParser parser;\n\n  parser.Parse1(commandStrings, options);\n\n  if(options.HelpMode)\n  {\n    ShowCopyrightAndHelp(g_StdOut, true);\n    return 0;\n  }\n\n  #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)\n  if (options.LargePages)\n  {\n    SetLargePageSize();\n    NSecurity::EnableLockMemoryPrivilege();\n  }\n  #endif\n\n  CStdOutStream &stdStream = options.StdOutMode ? g_StdErr : g_StdOut;\n  g_StdStream = &stdStream;\n\n  if (options.EnableHeaders)\n    ShowCopyrightAndHelp(stdStream, false);\n\n  parser.Parse2(options);\n\n  CCodecs *codecs = new CCodecs;\n  CMyComPtr<\n    #ifdef EXTERNAL_CODECS\n    ICompressCodecsInfo\n    #else\n    IUnknown\n    #endif\n    > compressCodecsInfo = codecs;\n  HRESULT result = codecs->Load();\n  if (result != S_OK)\n    throw CSystemException(result);\n\n  bool isExtractGroupCommand = options.Command.IsFromExtractGroup();\n\n  if (codecs->Formats.Size() == 0 &&\n        (isExtractGroupCommand ||\n        options.Command.CommandType == NCommandType::kList ||\n        options.Command.IsFromUpdateGroup()))\n    throw kNoFormats;\n\n  CIntVector formatIndices;\n  if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices))\n    throw kUnsupportedArcTypeMessage;\n\n  if (options.Command.CommandType == NCommandType::kInfo)\n  {\n    stdStream << endl << \"Formats:\" << endl;\n    int i;\n    for (i = 0; i < codecs->Formats.Size(); i++)\n    {\n      const CArcInfoEx &arc = codecs->Formats[i];\n      #ifdef EXTERNAL_CODECS\n      if (arc.LibIndex >= 0)\n      {\n        char s[32];\n        ConvertUInt64ToString(arc.LibIndex, s);\n        PrintString(stdStream, s, 2);\n      }\n      else\n      #endif\n        stdStream << \"  \";\n      stdStream << ' ';\n      stdStream << (char)(arc.UpdateEnabled ? 'C' : ' ');\n      stdStream << (char)(arc.KeepName ? 'K' : ' ');\n      stdStream << \"  \";\n      PrintString(stdStream, arc.Name, 6);\n      stdStream << \"  \";\n      UString s;\n      for (int t = 0; t < arc.Exts.Size(); t++)\n      {\n        const CArcExtInfo &ext = arc.Exts[t];\n        s += ext.Ext;\n        if (!ext.AddExt.IsEmpty())\n        {\n          s += L\" (\";\n          s += ext.AddExt;\n          s += L')';\n        }\n        s += L' ';\n      }\n      PrintString(stdStream, s, 14);\n      stdStream << \"  \";\n      const CByteBuffer &sig = arc.StartSignature;\n      for (size_t j = 0; j < sig.GetCapacity(); j++)\n      {\n        Byte b = sig[j];\n        if (b > 0x20 && b < 0x80)\n        {\n          stdStream << (char)b;\n        }\n        else\n        {\n          stdStream << GetHex((Byte)((b >> 4) & 0xF));\n          stdStream << GetHex((Byte)(b & 0xF));\n        }\n        stdStream << ' ';\n      }\n      stdStream << endl;\n    }\n    stdStream << endl << \"Codecs:\" << endl;\n\n    #ifdef EXTERNAL_CODECS\n    UInt32 numMethods;\n    if (codecs->GetNumberOfMethods(&numMethods) == S_OK)\n    for (UInt32 j = 0; j < numMethods; j++)\n    {\n      int libIndex = codecs->GetCodecLibIndex(j);\n      if (libIndex >= 0)\n      {\n        char s[32];\n        ConvertUInt64ToString(libIndex, s);\n        PrintString(stdStream, s, 2);\n      }\n      else\n        stdStream << \"  \";\n      stdStream << ' ';\n      stdStream << (char)(codecs->GetCodecEncoderIsAssigned(j) ? 'C' : ' ');\n      UInt64 id;\n      stdStream << \"  \";\n      HRESULT res = codecs->GetCodecId(j, id);\n      if (res != S_OK)\n        id = (UInt64)(Int64)-1;\n      char s[32];\n      ConvertUInt64ToString(id, s, 16);\n      PrintString(stdStream, s, 8);\n      stdStream << \"  \";\n      PrintString(stdStream, codecs->GetCodecName(j), 11);\n      stdStream << endl;\n      /*\n      if (res != S_OK)\n        throw \"incorrect Codec ID\";\n      */\n    }\n    #endif\n    return S_OK;\n  }\n  else if (options.Command.CommandType == NCommandType::kBenchmark)\n  {\n    if (options.Method.CompareNoCase(L\"CRC\") == 0)\n    {\n      HRESULT res = CrcBenchCon((FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\n      if (res != S_OK)\n      {\n        if (res == S_FALSE)\n        {\n          stdStream << \"\\nCRC Error\\n\";\n          return NExitCode::kFatalError;\n        }\n        throw CSystemException(res);\n      }\n    }\n    else\n    {\n      HRESULT res = LzmaBenchCon(\n        #ifdef EXTERNAL_LZMA\n        codecs,\n        #endif\n        (FILE *)stdStream, options.NumIterations, options.NumThreads, options.DictionarySize);\n      if (res != S_OK)\n      {\n        if (res == S_FALSE)\n        {\n          stdStream << \"\\nDecoding Error\\n\";\n          return NExitCode::kFatalError;\n        }\n        throw CSystemException(res);\n      }\n    }\n  }\n  else if (isExtractGroupCommand || options.Command.CommandType == NCommandType::kList)\n  {\n    if(isExtractGroupCommand)\n    {\n      CExtractCallbackConsole *ecs = new CExtractCallbackConsole;\n      CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;\n\n      ecs->OutStream = &stdStream;\n\n      #ifndef _NO_CRYPTO\n      ecs->PasswordIsDefined = options.PasswordEnabled;\n      ecs->Password = options.Password;\n      #endif\n\n      ecs->Init();\n\n      COpenCallbackConsole openCallback;\n      openCallback.OutStream = &stdStream;\n\n      #ifndef _NO_CRYPTO\n      openCallback.PasswordIsDefined = options.PasswordEnabled;\n      openCallback.Password = options.Password;\n      #endif\n\n      CExtractOptions eo;\n      eo.StdOutMode = options.StdOutMode;\n      eo.PathMode = options.Command.GetPathMode();\n      eo.TestMode = options.Command.IsTestMode();\n      eo.OverwriteMode = options.OverwriteMode;\n      eo.OutputDir = options.OutputDir;\n      eo.YesToAll = options.YesToAll;\n      #ifdef COMPRESS_MT\n      eo.Properties = options.ExtractProperties;\n      #endif\n      UString errorMessage;\n      CDecompressStat stat;\n      HRESULT result = DecompressArchives(\n          codecs,\n          formatIndices,\n          options.ArchivePathsSorted,\n          options.ArchivePathsFullSorted,\n          options.WildcardCensor.Pairs.Front().Head,\n          eo, &openCallback, ecs, errorMessage, stat);\n      if (!errorMessage.IsEmpty())\n      {\n        stdStream << endl << \"Error: \" << errorMessage;\n        if (result == S_OK)\n          result = E_FAIL;\n      }\n\n      stdStream << endl;\n      if (ecs->NumArchives > 1)\n        stdStream << \"Archives: \" << ecs->NumArchives << endl;\n      if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0)\n      {\n        if (ecs->NumArchives > 1)\n        {\n          stdStream << endl;\n          if (ecs->NumArchiveErrors != 0)\n            stdStream << \"Archive Errors: \" << ecs->NumArchiveErrors << endl;\n          if (ecs->NumFileErrors != 0)\n            stdStream << \"Sub items Errors: \" << ecs->NumFileErrors << endl;\n        }\n        if (result != S_OK)\n          throw CSystemException(result);\n        return NExitCode::kFatalError;\n      }\n      if (result != S_OK)\n        throw CSystemException(result);\n      if (stat.NumFolders != 0)\n        stdStream << \"Folders: \" << stat.NumFolders << endl;\n      if (stat.NumFiles != 1 || stat.NumFolders != 0)\n          stdStream << \"Files: \" << stat.NumFiles << endl;\n      stdStream\n           << \"Size:       \" << stat.UnpackSize << endl\n           << \"Compressed: \" << stat.PackSize << endl;\n    }\n    else\n    {\n      UInt64 numErrors = 0;\n      HRESULT result = ListArchives(\n          codecs,\n          formatIndices,\n          options.ArchivePathsSorted,\n          options.ArchivePathsFullSorted,\n          options.WildcardCensor.Pairs.Front().Head,\n          options.EnableHeaders,\n          options.TechMode,\n          #ifndef _NO_CRYPTO\n          options.PasswordEnabled,\n          options.Password,\n          #endif\n          numErrors);\n      if (numErrors > 0)\n      {\n        g_StdOut << endl << \"Errors: \" << numErrors;\n        return NExitCode::kFatalError;\n      }\n      if (result != S_OK)\n        throw CSystemException(result);\n    }\n  }\n  else if(options.Command.IsFromUpdateGroup())\n  {\n    UString workingDir;\n\n    CUpdateOptions &uo = options.UpdateOptions;\n    if (uo.SfxMode && uo.SfxModule.IsEmpty())\n      uo.SfxModule = kDefaultSfxModule;\n\n    COpenCallbackConsole openCallback;\n    openCallback.OutStream = &stdStream;\n\n    #ifndef _NO_CRYPTO\n    bool passwordIsDefined =\n        options.PasswordEnabled && !options.Password.IsEmpty();\n    openCallback.PasswordIsDefined = passwordIsDefined;\n    openCallback.Password = options.Password;\n    #endif\n\n    CUpdateCallbackConsole callback;\n    callback.EnablePercents = options.EnablePercents;\n\n    #ifndef _NO_CRYPTO\n    callback.PasswordIsDefined = passwordIsDefined;\n    callback.AskPassword = options.PasswordEnabled && options.Password.IsEmpty();\n    callback.Password = options.Password;\n    #endif\n    callback.StdOutMode = uo.StdOutMode;\n    callback.Init(&stdStream);\n\n    CUpdateErrorInfo errorInfo;\n\n    if (!uo.Init(codecs, formatIndices, options.ArchiveName))\n      throw kUnsupportedArcTypeMessage;\n    HRESULT result = UpdateArchive(codecs,\n        options.WildcardCensor, uo,\n        errorInfo, &openCallback, &callback);\n\n    int exitCode = NExitCode::kSuccess;\n    if (callback.CantFindFiles.Size() > 0)\n    {\n      stdStream << endl;\n      stdStream << \"WARNINGS for files:\" << endl << endl;\n      int numErrors = callback.CantFindFiles.Size();\n      for (int i = 0; i < numErrors; i++)\n      {\n        stdStream << callback.CantFindFiles[i] << \" : \";\n        stdStream << NError::MyFormatMessageW(callback.CantFindCodes[i]) << endl;\n      }\n      stdStream << \"----------------\" << endl;\n      stdStream << \"WARNING: Cannot find \" << numErrors << \" file\";\n      if (numErrors > 1)\n        stdStream << \"s\";\n      stdStream << endl;\n      exitCode = NExitCode::kWarning;\n    }\n\n    if (result != S_OK)\n    {\n      UString message;\n      if (!errorInfo.Message.IsEmpty())\n      {\n        message += errorInfo.Message;\n        message += L\"\\n\";\n      }\n      if (!errorInfo.FileName.IsEmpty())\n      {\n        message += errorInfo.FileName;\n        message += L\"\\n\";\n      }\n      if (!errorInfo.FileName2.IsEmpty())\n      {\n        message += errorInfo.FileName2;\n        message += L\"\\n\";\n      }\n      if (errorInfo.SystemError != 0)\n      {\n        message += NError::MyFormatMessageW(errorInfo.SystemError);\n        message += L\"\\n\";\n      }\n      if (!message.IsEmpty())\n        stdStream << L\"\\nError:\\n\" << message;\n      throw CSystemException(result);\n    }\n    int numErrors = callback.FailedFiles.Size();\n    if (numErrors == 0)\n    {\n      if (callback.CantFindFiles.Size() == 0)\n        stdStream << kEverythingIsOk << endl;\n    }\n    else\n    {\n      stdStream << endl;\n      stdStream << \"WARNINGS for files:\" << endl << endl;\n      for (int i = 0; i < numErrors; i++)\n      {\n        stdStream << callback.FailedFiles[i] << \" : \";\n        stdStream << NError::MyFormatMessageW(callback.FailedCodes[i]) << endl;\n      }\n      stdStream << \"----------------\" << endl;\n      stdStream << \"WARNING: Cannot open \" << numErrors << \" file\";\n      if (numErrors > 1)\n        stdStream << \"s\";\n      stdStream << endl;\n      exitCode = NExitCode::kWarning;\n    }\n    return exitCode;\n  }\n  else\n    PrintHelpAndExit(stdStream);\n  return 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/MainAr.cpp",
    "content": "// MainAr.cpp\n\n#include \"StdAfx.h\"\n\n// #include <locale.h>\n\n#include \"Windows/Error.h\"\n\n#include \"Common/StdOutStream.h\"\n#include \"Common/NewHandler.h\"\n#include \"Common/MyException.h\"\n#include \"Common/StringConvert.h\"\n\n#include \"../Common/ExitCode.h\"\n#include \"../Common/ArchiveCommandLine.h\"\n#include \"ConsoleClose.h\"\n\nusing namespace NWindows;\n\nCStdOutStream *g_StdStream = 0;\n\n#ifdef _WIN32\n#ifndef _UNICODE\nbool g_IsNT = false;\n#endif\n#if !defined(_UNICODE) || !defined(_WIN64)\nstatic inline bool IsItWindowsNT()\n{\n  OSVERSIONINFO versionInfo;\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\n  if (!::GetVersionEx(&versionInfo))\n    return false;\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\n}\n#endif\n#endif\n\nextern int Main2(\n  #ifndef _WIN32\n  int numArguments, const char *arguments[]\n  #endif\n);\n\nstatic const char *kExceptionErrorMessage = \"\\n\\nError:\\n\";\nstatic const char *kUserBreak  = \"\\nBreak signaled\\n\";\n\nstatic const char *kMemoryExceptionMessage = \"\\n\\nERROR: Can't allocate required memory!\\n\";\nstatic const char *kUnknownExceptionMessage = \"\\n\\nUnknown Error\\n\";\nstatic const char *kInternalExceptionMessage = \"\\n\\nInternal Error #\";\n\nint MY_CDECL main\n(\n#ifndef _WIN32\nint numArguments, const char *arguments[]\n#endif\n)\n{\n  g_StdStream = &g_StdOut;\n  #ifdef _WIN32\n  \n  #ifdef _UNICODE\n  #ifndef _WIN64\n  if (!IsItWindowsNT())\n  {\n    (*g_StdStream) << \"This program requires Windows NT/2000/2003/2008/XP/Vista\";\n    return NExitCode::kFatalError;\n  }\n  #endif\n  #else\n  g_IsNT = IsItWindowsNT();\n  #endif\n  \n  #endif\n\n  // setlocale(LC_COLLATE, \".OCP\");\n  NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;\n  int res = 0;\n  try\n  {\n    res = Main2(\n#ifndef _WIN32\n      numArguments, arguments\n#endif\n    );\n  }\n  catch(const CNewException &)\n  {\n    (*g_StdStream) << kMemoryExceptionMessage;\n    return (NExitCode::kMemoryError);\n  }\n  catch(const NConsoleClose::CCtrlBreakException &)\n  {\n    (*g_StdStream) << endl << kUserBreak;\n    return (NExitCode::kUserBreak);\n  }\n  catch(const CArchiveCommandLineException &e)\n  {\n    (*g_StdStream) << kExceptionErrorMessage << e << endl;\n    return (NExitCode::kUserError);\n  }\n  catch(const CSystemException &systemError)\n  {\n    if (systemError.ErrorCode == E_OUTOFMEMORY)\n    {\n      (*g_StdStream) << kMemoryExceptionMessage;\n      return (NExitCode::kMemoryError);\n    }\n    if (systemError.ErrorCode == E_ABORT)\n    {\n      (*g_StdStream) << endl << kUserBreak;\n      return (NExitCode::kUserBreak);\n    }\n    UString message;\n    NError::MyFormatMessage(systemError.ErrorCode, message);\n    (*g_StdStream) << endl << endl << \"System error:\" << endl <<\n        message << endl;\n    return (NExitCode::kFatalError);\n  }\n  catch(NExitCode::EEnum &exitCode)\n  {\n    (*g_StdStream) << kInternalExceptionMessage << exitCode << endl;\n    return (exitCode);\n  }\n  /*\n  catch(const NExitCode::CMultipleErrors &multipleErrors)\n  {\n    (*g_StdStream) << endl << multipleErrors.NumErrors << \" errors\" << endl;\n    return (NExitCode::kFatalError);\n  }\n  */\n  catch(const UString &s)\n  {\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\n    return (NExitCode::kFatalError);\n  }\n  catch(const AString &s)\n  {\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\n    return (NExitCode::kFatalError);\n  }\n  catch(const char *s)\n  {\n    (*g_StdStream) << kExceptionErrorMessage << s << endl;\n    return (NExitCode::kFatalError);\n  }\n  catch(int t)\n  {\n    (*g_StdStream) << kInternalExceptionMessage << t << endl;\n    return (NExitCode::kFatalError);\n  }\n  catch(...)\n  {\n    (*g_StdStream) << kUnknownExceptionMessage;\n    return (NExitCode::kFatalError);\n  }\n  return  res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/OpenCallbackConsole.cpp",
    "content": "// OpenCallbackConsole.cpp\n\n#include \"StdAfx.h\"\n\n#include \"OpenCallbackConsole.h\"\n\n#include \"ConsoleClose.h\"\n#include \"UserInputUtils.h\"\n\nHRESULT COpenCallbackConsole::Open_CheckBreak()\n{\n  if (NConsoleClose::TestBreakSignal())\n    return E_ABORT;\n  return S_OK;\n}\n\nHRESULT COpenCallbackConsole::Open_SetTotal(const UInt64 *, const UInt64 *)\n{\n  return Open_CheckBreak();\n}\n\nHRESULT COpenCallbackConsole::Open_SetCompleted(const UInt64 *, const UInt64 *)\n{\n  return Open_CheckBreak();\n}\n \n#ifndef _NO_CRYPTO\n\nHRESULT COpenCallbackConsole::Open_CryptoGetTextPassword(BSTR *password)\n{\n  PasswordWasAsked = true;\n  RINOK(Open_CheckBreak());\n  if (!PasswordIsDefined)\n  {\n    Password = GetPassword(OutStream);\n    PasswordIsDefined = true;\n  }\n  return StringToBstr(Password, password);\n}\n\nHRESULT COpenCallbackConsole::Open_GetPasswordIfAny(UString &password)\n{\n  if (PasswordIsDefined)\n    password = Password;\n  return S_OK;\n}\n\nbool COpenCallbackConsole::Open_WasPasswordAsked()\n{\n  return PasswordWasAsked;\n}\n\nvoid COpenCallbackConsole::Open_ClearPasswordWasAskedFlag()\n{\n  PasswordWasAsked = false;\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/OpenCallbackConsole.h",
    "content": "// OpenCallbackConsole.h\n\n#ifndef __OPENCALLBACKCONSOLE_H\n#define __OPENCALLBACKCONSOLE_H\n\n#include \"Common/StdOutStream.h\"\n#include \"../Common/ArchiveOpenCallback.h\"\n\nclass COpenCallbackConsole: public IOpenCallbackUI\n{\npublic:\n  INTERFACE_IOpenCallbackUI(;)\n  \n  CStdOutStream *OutStream;\n\n  #ifndef _NO_CRYPTO\n  bool PasswordIsDefined;\n  bool PasswordWasAsked;\n  UString Password;\n  COpenCallbackConsole(): PasswordIsDefined(false), PasswordWasAsked(false) {}\n  #endif\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/PercentPrinter.cpp",
    "content": "// PercentPrinter.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Common/IntToString.h\"\n#include \"Common/MyString.h\"\n\n#include \"PercentPrinter.h\"\n\nconst int kPaddingSize = 2;\nconst int kPercentsSize = 4;\nconst int kMaxExtraSize = kPaddingSize + 32 + kPercentsSize;\n\nstatic void ClearPrev(char *p, int num)\n{\n  int i;\n  for (i = 0; i < num; i++) *p++ = '\\b';\n  for (i = 0; i < num; i++) *p++ = ' ';\n  for (i = 0; i < num; i++) *p++ = '\\b';\n  *p = '\\0';\n}\n\nvoid CPercentPrinter::ClosePrint()\n{\n  if (m_NumExtraChars == 0)\n    return;\n  char s[kMaxExtraSize * 3 + 1];\n  ClearPrev(s, m_NumExtraChars);\n  (*OutStream) << s;\n  m_NumExtraChars = 0;\n}\n\nvoid CPercentPrinter::PrintString(const char *s)\n{\n  ClosePrint();\n  (*OutStream) << s;\n}\n\nvoid CPercentPrinter::PrintString(const wchar_t *s)\n{\n  ClosePrint();\n  (*OutStream) << s;\n}\n\nvoid CPercentPrinter::PrintNewLine()\n{\n  ClosePrint();\n  (*OutStream) << \"\\n\";\n}\n\nvoid CPercentPrinter::RePrintRatio()\n{\n  char s[32];\n  ConvertUInt64ToString(((m_Total == 0) ? 0 : (m_CurValue * 100 / m_Total)), s);\n  int size = (int)strlen(s);\n  s[size++] = '%';\n  s[size] = '\\0';\n\n  int extraSize = kPaddingSize + MyMax(size, kPercentsSize);\n  if (extraSize < m_NumExtraChars)\n    extraSize = m_NumExtraChars;\n\n  char fullString[kMaxExtraSize * 3];\n  char *p = fullString;\n  int i;\n  if (m_NumExtraChars == 0)\n  {\n    for (i = 0; i < extraSize; i++)\n      *p++ = ' ';\n    m_NumExtraChars = extraSize;\n  }\n\n  for (i = 0; i < m_NumExtraChars; i++)\n    *p++ = '\\b';\n  m_NumExtraChars = extraSize;\n  for (; size < m_NumExtraChars; size++)\n    *p++ = ' ';\n  MyStringCopy(p, s);\n  (*OutStream) << fullString;\n  OutStream->Flush();\n  m_PrevValue = m_CurValue;\n}\n\nvoid CPercentPrinter::PrintRatio()\n{\n  if (m_CurValue < m_PrevValue + m_MinStepSize &&\n      m_CurValue + m_MinStepSize > m_PrevValue && m_NumExtraChars != 0)\n    return;\n  RePrintRatio();\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/PercentPrinter.h",
    "content": "// PercentPrinter.h\n\n#ifndef __PERCENTPRINTER_H\n#define __PERCENTPRINTER_H\n\n#include \"Common/Types.h\"\n#include \"Common/StdOutStream.h\"\n\nclass CPercentPrinter\n{\n  UInt64 m_MinStepSize;\n  UInt64 m_PrevValue;\n  UInt64 m_CurValue;\n  UInt64 m_Total;\n  int m_NumExtraChars;\npublic:\n  CStdOutStream *OutStream;\n\n  CPercentPrinter(UInt64 minStepSize = 1): m_MinStepSize(minStepSize),\n      m_PrevValue(0), m_CurValue(0), m_Total(1), m_NumExtraChars(0) {}\n  void SetTotal(UInt64 total) { m_Total = total; m_PrevValue = 0; }\n  void SetRatio(UInt64 doneValue) { m_CurValue = doneValue; }\n  void PrintString(const char *s);\n  void PrintString(const wchar_t *s);\n  void PrintNewLine();\n  void ClosePrint();\n  void RePrintRatio();\n  void PrintRatio();\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/StdAfx.cpp",
    "content": "// StdAfx.cpp\n\n#include \"StdAfx.h\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../../../Common/MyWindows.h\"\n#include \"../../../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp",
    "content": "// UpdateCallbackConsole.cpp\n\n#include \"StdAfx.h\"\n\n#include \"UpdateCallbackConsole.h\"\n\n#include \"Windows/Error.h\"\n#ifdef COMPRESS_MT\n#include \"Windows/Synchronization.h\"\n#endif\n\n#include \"ConsoleClose.h\"\n#include \"UserInputUtils.h\"\n\nusing namespace NWindows;\n\n#ifdef COMPRESS_MT\nstatic NSynchronization::CCriticalSection g_CriticalSection;\n#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);\n#else\n#define MT_LOCK\n#endif\n\nstatic const wchar_t *kEmptyFileAlias = L\"[Content]\";\n\nstatic const char *kCreatingArchiveMessage = \"Creating archive \";\nstatic const char *kUpdatingArchiveMessage = \"Updating archive \";\nstatic const char *kScanningMessage = \"Scanning\";\n\n\nHRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)\n{\n  (*OutStream) << endl;\n  if (result != S_OK)\n    (*OutStream) << \"Error: \" << name << \" is not supported archive\" << endl;\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::StartScanning()\n{\n  (*OutStream) << kScanningMessage;\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::ScanProgress(UInt64 /* numFolders */, UInt64 /* numFiles */, const wchar_t * /* path */)\n{\n  return CheckBreak();\n}\n\nHRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)\n{\n  CantFindFiles.Add(name);\n  CantFindCodes.Add(systemError);\n  // m_PercentPrinter.ClosePrint();\n  if (!m_WarningsMode)\n  {\n    (*OutStream) << endl << endl;\n    m_PercentPrinter.PrintNewLine();\n    m_WarningsMode = true;\n  }\n  m_PercentPrinter.PrintString(name);\n  m_PercentPrinter.PrintString(\":  WARNING: \");\n  m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\n  m_PercentPrinter.PrintNewLine();\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::FinishScanning()\n{\n  (*OutStream) << endl << endl;\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)\n{\n  if(updating)\n    (*OutStream) << kUpdatingArchiveMessage;\n  else\n    (*OutStream) << kCreatingArchiveMessage;\n  if (name != 0)\n    (*OutStream) << name;\n  else\n    (*OutStream) << \"StdOut\";\n  (*OutStream) << endl << endl;\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::FinishArchive()\n{\n  (*OutStream) << endl;\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::CheckBreak()\n{\n  if (NConsoleClose::TestBreakSignal())\n    return E_ABORT;\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::Finilize()\n{\n  MT_LOCK\n  if (m_NeedBeClosed)\n  {\n    if (EnablePercents)\n    {\n      m_PercentPrinter.ClosePrint();\n    }\n    if (!StdOutMode && m_NeedNewLine)\n    {\n      m_PercentPrinter.PrintNewLine();\n      m_NeedNewLine = false;\n    }\n    m_NeedBeClosed = false;\n  }\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */)\n{\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)\n{\n  MT_LOCK\n  if (EnablePercents)\n    m_PercentPrinter.SetTotal(size);\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)\n{\n  MT_LOCK\n  if (completeValue != NULL)\n  {\n    if (EnablePercents)\n    {\n      m_PercentPrinter.SetRatio(*completeValue);\n      m_PercentPrinter.PrintRatio();\n      m_NeedBeClosed = true;\n    }\n  }\n  if (NConsoleClose::TestBreakSignal())\n    return E_ABORT;\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)\n{\n  if (NConsoleClose::TestBreakSignal())\n    return E_ABORT;\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)\n{\n  MT_LOCK\n  if (StdOutMode)\n    return S_OK;\n  if(isAnti)\n    m_PercentPrinter.PrintString(\"Anti item    \");\n  else\n    m_PercentPrinter.PrintString(\"Compressing  \");\n  if (name[0] == 0)\n    name = kEmptyFileAlias;\n  m_PercentPrinter.PrintString(name);\n  if (EnablePercents)\n    m_PercentPrinter.RePrintRatio();\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)\n{\n  MT_LOCK\n  FailedCodes.Add(systemError);\n  FailedFiles.Add(name);\n  // if (systemError == ERROR_SHARING_VIOLATION)\n  {\n    m_PercentPrinter.ClosePrint();\n    m_PercentPrinter.PrintNewLine();\n    m_PercentPrinter.PrintString(\"WARNING: \");\n    m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));\n    return S_FALSE;\n  }\n  // return systemError;\n}\n\nHRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )\n{\n  m_NeedBeClosed = true;\n  m_NeedNewLine = true;\n  return S_OK;\n}\n\nHRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)\n{\n  #ifdef _NO_CRYPTO\n\n  *passwordIsDefined = false;\n  return StringToBstr(L\"\", password);\n  \n  #else\n  \n  if (!PasswordIsDefined)\n  {\n    if (AskPassword)\n    {\n      Password = GetPassword(OutStream);\n      PasswordIsDefined = true;\n    }\n  }\n  *passwordIsDefined = BoolToInt(PasswordIsDefined);\n  return StringToBstr(Password, password);\n  \n  #endif\n  \n}\n\n/*\nHRESULT CUpdateCallbackConsole::ShowDeleteFile(const wchar_t *name)\n{\n  // MT_LOCK\n  if (StdOutMode)\n    return S_OK;\n  RINOK(Finilize());\n  m_PercentPrinter.PrintString(\"Deleting  \");\n  if (name[0] == 0)\n    name = kEmptyFileAlias;\n  m_PercentPrinter.PrintString(name);\n  if (EnablePercents)\n    m_PercentPrinter.RePrintRatio();\n  m_NeedBeClosed = true;\n  m_NeedNewLine = true;\n  return S_OK;\n}\n*/\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/UpdateCallbackConsole.h",
    "content": "// UpdateCallbackConsole.h\n\n#ifndef __UPDATECALLBACKCONSOLE_H\n#define __UPDATECALLBACKCONSOLE_H\n\n#include \"Common/MyString.h\"\n#include \"Common/StdOutStream.h\"\n#include \"PercentPrinter.h\"\n#include \"../Common/Update.h\"\n\nclass CUpdateCallbackConsole: public IUpdateCallbackUI2\n{\n  CPercentPrinter m_PercentPrinter;\n  bool m_NeedBeClosed;\n  bool m_NeedNewLine;\n\n  bool m_WarningsMode;\n\n  CStdOutStream *OutStream;\npublic:\n  bool EnablePercents;\n  bool StdOutMode;\n\n  #ifndef _NO_CRYPTO\n  bool PasswordIsDefined;\n  UString Password;\n  bool AskPassword;\n  #endif\n\n  CUpdateCallbackConsole():\n      m_PercentPrinter(1 << 16),\n      #ifndef _NO_CRYPTO\n      PasswordIsDefined(false),\n      AskPassword(false),\n      #endif\n      StdOutMode(false),\n      EnablePercents(true),\n      m_WarningsMode(false)\n      {}\n  \n  ~CUpdateCallbackConsole() { Finilize(); }\n  void Init(CStdOutStream *outStream)\n  {\n    m_NeedBeClosed = false;\n    m_NeedNewLine = false;\n    FailedFiles.Clear();\n    FailedCodes.Clear();\n    OutStream = outStream;\n    m_PercentPrinter.OutStream = outStream;\n  }\n\n  INTERFACE_IUpdateCallbackUI2(;)\n\n  UStringVector FailedFiles;\n  CRecordVector<HRESULT> FailedCodes;\n\n  UStringVector CantFindFiles;\n  CRecordVector<HRESULT> CantFindCodes;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/UserInputUtils.cpp",
    "content": "// UserInputUtils.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Common/StdInStream.h\"\n#include \"Common/StringConvert.h\"\n\n#include \"UserInputUtils.h\"\n\nstatic const char kYes = 'Y';\nstatic const char kNo = 'N';\nstatic const char kYesAll = 'A';\nstatic const char kNoAll = 'S';\nstatic const char kAutoRenameAll = 'U';\nstatic const char kQuit = 'Q';\n\nstatic const char *kFirstQuestionMessage = \"?\\n\";\nstatic const char *kHelpQuestionMessage =\n  \"(Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit? \";\n\n// return true if pressed Quite;\n\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)\n{\n  (*outStream) << kFirstQuestionMessage;\n  for(;;)\n  {\n    (*outStream) << kHelpQuestionMessage;\n    AString scannedString = g_StdIn.ScanStringUntilNewLine();\n    scannedString.Trim();\n    if(!scannedString.IsEmpty())\n      switch(::MyCharUpper(scannedString[0]))\n      {\n        case kYes:\n          return NUserAnswerMode::kYes;\n        case kNo:\n          return NUserAnswerMode::kNo;\n        case kYesAll:\n          return NUserAnswerMode::kYesAll;\n        case kNoAll:\n          return NUserAnswerMode::kNoAll;\n        case kAutoRenameAll:\n          return NUserAnswerMode::kAutoRenameAll;\n        case kQuit:\n          return NUserAnswerMode::kQuit;\n      }\n  }\n}\n\nUString GetPassword(CStdOutStream *outStream)\n{\n  (*outStream) << \"\\nEnter password:\";\n  outStream->Flush();\n  AString oemPassword = g_StdIn.ScanStringUntilNewLine();\n  return MultiByteToUnicodeString(oemPassword, CP_OEMCP);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/UserInputUtils.h",
    "content": "// UserInputUtils.h\n\n#ifndef __USERINPUTUTILS_H\n#define __USERINPUTUTILS_H\n\n#include \"Common/StdOutStream.h\"\n\nnamespace NUserAnswerMode {\n\nenum EEnum\n{\n  kYes,\n  kNo,\n  kYesAll,\n  kNoAll,\n  kAutoRenameAll,\n  kQuit\n};\n}\n\nNUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream);\nUString GetPassword(CStdOutStream *outStream);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/7zip/UI/Console/makefile",
    "content": "PROG = 7z.exe\nLIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib\nCFLAGS = $(CFLAGS) -I ../../../  \\\n  -DCOMPRESS_MT \\\n  -DWIN_LONG_PATH \\\n  -DEXTERNAL_LZMA \\\n  -DEXTERNAL_CODECS \\\n  -DBREAK_HANDLER \\\n  -DBENCH_MT \\\n  -D_7ZIP_LARGE_PAGES \\\n\nCONSOLE_OBJS = \\\n  $O\\ConsoleClose.obj \\\n  $O\\ExtractCallbackConsole.obj \\\n  $O\\List.obj \\\n  $O\\Main.obj \\\n  $O\\MainAr.obj \\\n  $O\\OpenCallbackConsole.obj \\\n  $O\\PercentPrinter.obj \\\n  $O\\UpdateCallbackConsole.obj \\\n  $O\\UserInputUtils.obj \\\n\nCOMMON_OBJS = \\\n  $O\\CommandLineParser.obj \\\n  $O\\CRC.obj \\\n  $O\\IntToString.obj \\\n  $O\\ListFileUtils.obj \\\n  $O\\NewHandler.obj \\\n  $O\\StdInStream.obj \\\n  $O\\StdOutStream.obj \\\n  $O\\MyString.obj \\\n  $O\\StringConvert.obj \\\n  $O\\StringToInt.obj \\\n  $O\\UTFConvert.obj \\\n  $O\\MyVector.obj \\\n  $O\\Wildcard.obj \\\n\nWIN_OBJS = \\\n  $O\\DLL.obj \\\n  $O\\Error.obj \\\n  $O\\FileDir.obj \\\n  $O\\FileFind.obj \\\n  $O\\FileIO.obj \\\n  $O\\FileName.obj \\\n  $O\\MemoryLock.obj \\\n  $O\\PropVariant.obj \\\n  $O\\PropVariantConversions.obj \\\n  $O\\Registry.obj \\\n  $O\\System.obj \\\n  $O\\Time.obj \\\n\n7ZIP_COMMON_OBJS = \\\n  $O\\FilePathAutoRename.obj \\\n  $O\\FileStreams.obj \\\n  $O\\ProgressUtils.obj \\\n  $O\\StreamUtils.obj \\\n\nUI_COMMON_OBJS = \\\n  $O\\ArchiveCommandLine.obj \\\n  $O\\ArchiveExtractCallback.obj \\\n  $O\\ArchiveOpenCallback.obj \\\n  $O\\DefaultName.obj \\\n  $O\\EnumDirItems.obj \\\n  $O\\Extract.obj \\\n  $O\\ExtractingFilePath.obj \\\n  $O\\LoadCodecs.obj \\\n  $O\\OpenArchive.obj \\\n  $O\\PropIDUtils.obj \\\n  $O\\SetProperties.obj \\\n  $O\\SortUtils.obj \\\n  $O\\TempFiles.obj \\\n  $O\\Update.obj \\\n  $O\\UpdateAction.obj \\\n  $O\\UpdateCallback.obj \\\n  $O\\UpdatePair.obj \\\n  $O\\UpdateProduce.obj \\\n  $O\\WorkDir.obj \\\n\nLZMA_BENCH_OBJS = \\\n  $O\\LzmaBench.obj \\\n  $O\\LzmaBenchCon.obj \\\n\nC_OBJS = \\\n  $O\\Alloc.obj \\\n  $O\\Threads.obj \\\n\n!include \"../../Crc2.mak\"\n\nOBJS = \\\n  $O\\StdAfx.obj \\\n  $(CONSOLE_OBJS) \\\n  $(COMMON_OBJS) \\\n  $(WIN_OBJS) \\\n  $(7ZIP_COMMON_OBJS) \\\n  $(UI_COMMON_OBJS) \\\n  $O\\CopyCoder.obj \\\n  $(LZMA_BENCH_OBJS) \\\n  $(C_OBJS) \\\n  $(CRC_OBJS) \\\n  $O\\resource.res\n\n!include \"../../../Build.mak\"\n\n$(CONSOLE_OBJS): $(*B).cpp\n\t$(COMPL)\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\n\t$(COMPL)\n$(WIN_OBJS): ../../../Windows/$(*B).cpp\n\t$(COMPL)\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\n\t$(COMPL)\n$(UI_COMMON_OBJS): ../Common/$(*B).cpp\n\t$(COMPL)\n$O\\CopyCoder.obj: ../../Compress/$(*B).cpp\n\t$(COMPL)\n$(LZMA_BENCH_OBJS): ../../Compress/LZMA_Alone/$(*B).cpp\n\t$(COMPL)\n$(C_OBJS): ../../../../C/$(*B).c\n\t$(COMPL_O2)\n!include \"../../Crc.mak\"\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Build.mak",
    "content": "!IFDEF CPU\n!IFNDEF NO_BUFFEROVERFLOWU\nLIBS = $(LIBS) bufferoverflowU.lib\n!ENDIF\n!ENDIF\n\n\n!IFNDEF O\n!IFDEF CPU\nO=$(CPU)\n!ELSE\nO=O\n!ENDIF\n!ENDIF\n\n!IF \"$(CPU)\" != \"IA64\"\n!IF \"$(CPU)\" != \"AMD64\"\nMY_ML = ml\n!ELSE\nMY_ML = ml64\n!ENDIF\n!ENDIF\n\nCOMPL_ASM = $(MY_ML) -c -Fo$O/ $**\n\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -WX -EHsc -Gr -Gy -GR-\n\n!IFDEF MY_STATIC_LINK\n!IFNDEF MY_SINGLE_THREAD\nCFLAGS = $(CFLAGS) -MT\n!ENDIF\n!ELSE\nCFLAGS = $(CFLAGS) -MD\n!ENDIF\n\n!IFDEF NEW_COMPILER\nCFLAGS = $(CFLAGS) -W4 -GS- -Zc:forScope\n!ELSE\nCFLAGS = $(CFLAGS) -W3\n!ENDIF\n\nCFLAGS_O1 = $(CFLAGS) -O1\nCFLAGS_O2 = $(CFLAGS) -O2\n\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF -OPT:ICF\n\n!IFDEF DEF_FILE\nLFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)\n!ENDIF\n\nPROGPATH = $O\\$(PROG)\n\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\nCOMPL_PCH  = $(CPP) $(CFLAGS_O1) -Yc\"StdAfx.h\" -Fp$O/a.pch $**\nCOMPL      = $(CPP) $(CFLAGS_O1) -Yu\"StdAfx.h\" -Fp$O/a.pch $**\n\nall: $(PROGPATH)\n\nclean:\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch\n\n$O:\n\tif not exist \"$O\" mkdir \"$O\"\n\n$(PROGPATH): $O $(OBJS) $(DEF_FILE)\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\n$O\\resource.res: $(*B).rc\n\trc -fo$@ $**\n$O\\StdAfx.obj: $(*B).cpp\n\t$(COMPL_PCH)\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/AutoPtr.h",
    "content": "// Common/AutoPtr.h\n\n#ifndef __COMMON_AUTOPTR_H\n#define __COMMON_AUTOPTR_H\n\ntemplate<class T> class CMyAutoPtr\n{\n  T *_p;\npublic:\n  CMyAutoPtr(T *p = 0) : _p(p) {}\n  CMyAutoPtr(CMyAutoPtr<T>& p): _p(p.release()) {}\n  CMyAutoPtr<T>& operator=(CMyAutoPtr<T>& p)\n  {\n    reset(p.release());\n    return (*this);\n  }\n  ~CMyAutoPtr() { delete _p; }\n  T& operator*() const { return *_p; }\n  // T* operator->() const { return (&**this); }\n  T* get() const { return _p; }\n  T* release()\n  {\n    T *tmp = _p;\n    _p = 0;\n    return tmp;\n  }\n  void reset(T* p = 0)\n  {\n    if (p != _p)\n      delete _p;\n    _p = p;\n  }\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/Buffer.h",
    "content": "// Common/Buffer.h\n\n#ifndef __COMMON_BUFFER_H\n#define __COMMON_BUFFER_H\n\n#include \"Defs.h\"\n\ntemplate <class T> class CBuffer\n{\nprotected:\n  size_t _capacity;\n  T *_items;\npublic:\n  void Free()\n  {\n    delete []_items;\n    _items = 0;\n    _capacity = 0;\n  }\n  CBuffer(): _capacity(0), _items(0) {};\n  CBuffer(const CBuffer &buffer): _capacity(0), _items(0) { *this = buffer; }\n  CBuffer(size_t size): _items(0),  _capacity(0) {  SetCapacity(size); }\n  virtual ~CBuffer() { delete []_items; }\n  operator T *() { return _items; };\n  operator const T *() const { return _items; };\n  size_t GetCapacity() const { return  _capacity; }\n  void SetCapacity(size_t newCapacity)\n  {\n    if (newCapacity == _capacity)\n      return;\n    T *newBuffer;\n    if (newCapacity > 0)\n    {\n      newBuffer = new T[newCapacity];\n      if (_capacity > 0)\n        memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T));\n    }\n    else\n      newBuffer = 0;\n    delete []_items;\n    _items = newBuffer;\n    _capacity = newCapacity;\n  }\n  CBuffer& operator=(const CBuffer &buffer)\n  {\n    Free();\n    if (buffer._capacity > 0)\n    {\n      SetCapacity(buffer._capacity);\n      memmove(_items, buffer._items, buffer._capacity * sizeof(T));\n    }\n    return *this;\n  }\n};\n\ntemplate <class T>\nbool operator==(const CBuffer<T>& b1, const CBuffer<T>& b2)\n{\n  if (b1.GetCapacity() != b2.GetCapacity())\n    return false;\n  for (size_t i = 0; i < b1.GetCapacity(); i++)\n    if (b1[i] != b2[i])\n      return false;\n  return true;\n}\n\ntemplate <class T>\nbool operator!=(const CBuffer<T>& b1, const CBuffer<T>& b2)\n{\n  return !(b1 == b2);\n}\n\ntypedef CBuffer<char> CCharBuffer;\ntypedef CBuffer<wchar_t> CWCharBuffer;\ntypedef CBuffer<unsigned char> CByteBuffer;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\n\n#include \"StdAfx.h\"\n\nextern \"C\"\n{\n#include \"../../C/7zCrc.h\"\n}\n\nstruct CCRCTableInit { CCRCTableInit() { CrcGenerateTable(); } } g_CRCTableInit;\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\n\n#include \"C_FileIO.h\"\n\n#include <fcntl.h>\n#include <unistd.h>\n\nnamespace NC {\nnamespace NFile {\nnamespace NIO {\n\nbool CFileBase::OpenBinary(const char *name, int flags)\n{\n  #ifdef O_BINARY\n  flags |= O_BINARY;\n  #endif\n  Close();\n  _handle = ::open(name, flags, 0666);\n  return _handle != -1;\n}\n\nbool CFileBase::Close()\n{\n  if (_handle == -1)\n    return true;\n  if (close(_handle) != 0)\n    return false;\n  _handle = -1;\n  return true;\n}\n\nbool CFileBase::GetLength(UInt64 &length) const\n{\n  off_t curPos = Seek(0, SEEK_CUR);\n  off_t lengthTemp = Seek(0, SEEK_END);\n  Seek(curPos, SEEK_SET);\n  length = (UInt64)lengthTemp;\n  return true;\n}\n\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\n{\n  return ::lseek(_handle, distanceToMove, moveMethod);\n}\n\n/////////////////////////\n// CInFile\n\nbool CInFile::Open(const char *name)\n{\n  return CFileBase::OpenBinary(name, O_RDONLY);\n}\n\nbool CInFile::OpenShared(const char *name, bool)\n{\n  return Open(name);\n}\n\nssize_t CInFile::Read(void *data, size_t size)\n{\n  return read(_handle, data, size);\n}\n\n/////////////////////////\n// COutFile\n\nbool COutFile::Create(const char *name, bool createAlways)\n{\n  if (createAlways)\n  {\n    Close();\n    _handle = ::creat(name, 0666);\n    return _handle != -1;\n  }\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\n}\n\nbool COutFile::Open(const char *name, DWORD creationDisposition)\n{\n  return Create(name, false);\n}\n\nssize_t COutFile::Write(const void *data, size_t size)\n{\n  return write(_handle, data, size);\n}\n\n}}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\n\n#ifndef __COMMON_C_FILEIO_H\n#define __COMMON_C_FILEIO_H\n\n#include <stdio.h>\n#include <sys/types.h>\n\n#include \"Types.h\"\n#include \"MyWindows.h\"\n\nnamespace NC {\nnamespace NFile {\nnamespace NIO {\n\nclass CFileBase\n{\nprotected:\n  int _handle;\n  bool OpenBinary(const char *name, int flags);\npublic:\n  CFileBase(): _handle(-1) {};\n  ~CFileBase() { Close(); }\n  bool Close();\n  bool GetLength(UInt64 &length) const;\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\n  int GetHandle() const { return _handle; }\n};\n\nclass CInFile: public CFileBase\n{\npublic:\n  bool Open(const char *name);\n  bool OpenShared(const char *name, bool shareForWrite);\n  ssize_t Read(void *data, size_t size);\n};\n\nclass COutFile: public CFileBase\n{\npublic:\n  bool Create(const char *name, bool createAlways);\n  bool Open(const char *name, DWORD creationDisposition);\n  ssize_t Write(const void *data, size_t size);\n};\n\n}}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/ComTry.h",
    "content": "// ComTry.h\n\n#ifndef __COM_TRY_H\n#define __COM_TRY_H\n\n#include \"MyWindows.h\"\n// #include \"Exception.h\"\n// #include \"NewHandler.h\"\n\n#define COM_TRY_BEGIN try {\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\n  \n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\n  // catch(...) { return E_FAIL; }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\n\n#include \"StdAfx.h\"\n\n#include \"CommandLineParser.h\"\n\nnamespace NCommandLineParser {\n\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\n{\n  dest1.Empty();\n  dest2.Empty();\n  bool quoteMode = false;\n  int i;\n  for (i = 0; i < src.Length(); i++)\n  {\n    wchar_t c = src[i];\n    if (c == L'\\\"')\n      quoteMode = !quoteMode;\n    else if (c == L' ' && !quoteMode)\n    {\n      i++;\n      break;\n    }\n    else\n      dest1 += c;\n  }\n  dest2 = src.Mid(i);\n}\n\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\n{\n  UString sTemp = s;\n  sTemp.Trim();\n  parts.Clear();\n  for (;;)\n  {\n    UString s1, s2;\n    SplitCommandLine(sTemp, s1, s2);\n    // s1.Trim();\n    // s2.Trim();\n    if (!s1.IsEmpty())\n      parts.Add(s1);\n    if (s2.IsEmpty())\n      break;\n    sTemp = s2;\n  }\n}\n\n\nstatic const wchar_t kSwitchID1 = '-';\n// static const wchar_t kSwitchID2 = '/';\n\nstatic const wchar_t kSwitchMinus = '-';\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\n\nstatic bool IsItSwitchChar(wchar_t c)\n{\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */);\n}\n\nCParser::CParser(int numSwitches):\n  _numSwitches(numSwitches)\n{\n  _switches = new CSwitchResult[_numSwitches];\n}\n\nCParser::~CParser()\n{\n  delete []_switches;\n}\n\nvoid CParser::ParseStrings(const CSwitchForm *switchForms,\n  const UStringVector &commandStrings)\n{\n  int numCommandStrings = commandStrings.Size();\n  bool stopSwitch = false;\n  for (int i = 0; i < numCommandStrings; i++)\n  {\n    const UString &s = commandStrings[i];\n    if (stopSwitch)\n      NonSwitchStrings.Add(s);\n    else\n      if (s == kStopSwitchParsing)\n        stopSwitch = true;\n      else\n        if (!ParseString(s, switchForms))\n          NonSwitchStrings.Add(s);\n  }\n}\n\n// if string contains switch then function updates switch structures\n// out: (string is a switch)\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\n{\n  int len = s.Length();\n  if (len == 0)\n    return false;\n  int pos = 0;\n  if (!IsItSwitchChar(s[pos]))\n    return false;\n  while (pos < len)\n  {\n    if (IsItSwitchChar(s[pos]))\n      pos++;\n    const int kNoLen = -1;\n    int matchedSwitchIndex = 0; // GCC Warning\n    int maxLen = kNoLen;\n    for (int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\n    {\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\n      if (switchLen <= maxLen || pos + switchLen > len)\n        continue;\n\n      UString temp = s + pos;\n      temp = temp.Left(switchLen);\n      if (temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\n      // if (_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\n      {\n        matchedSwitchIndex = switchIndex;\n        maxLen = switchLen;\n      }\n    }\n    if (maxLen == kNoLen)\n      throw \"maxLen == kNoLen\";\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\n      throw \"switch must be single\";\n    matchedSwitch.ThereIs = true;\n    pos += maxLen;\n    int tailSize = len - pos;\n    NSwitchType::EEnum type = switchForm.Type;\n    switch(type)\n    {\n      case NSwitchType::kPostMinus:\n        {\n          if (tailSize == 0)\n            matchedSwitch.WithMinus = false;\n          else\n          {\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\n            if (matchedSwitch.WithMinus)\n              pos++;\n          }\n          break;\n        }\n      case NSwitchType::kPostChar:\n        {\n          if (tailSize < switchForm.MinLen)\n            throw \"switch is not full\";\n          UString set = switchForm.PostCharSet;\n          const int kEmptyCharValue = -1;\n          if (tailSize == 0)\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\n          else\n          {\n            int index = set.Find(s[pos]);\n            if (index < 0)\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\n            else\n            {\n              matchedSwitch.PostCharIndex = index;\n              pos++;\n            }\n          }\n          break;\n        }\n      case NSwitchType::kLimitedPostString:\n      case NSwitchType::kUnLimitedPostString:\n        {\n          int minLen = switchForm.MinLen;\n          if (tailSize < minLen)\n            throw \"switch is not full\";\n          if (type == NSwitchType::kUnLimitedPostString)\n          {\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\n            return true;\n          }\n          int maxLen = switchForm.MaxLen;\n          UString stringSwitch = s.Mid(pos, minLen);\n          pos += minLen;\n          for (int i = minLen; i < maxLen && pos < len; i++, pos++)\n          {\n            wchar_t c = s[pos];\n            if (IsItSwitchChar(c))\n              break;\n            stringSwitch += c;\n          }\n          matchedSwitch.PostStrings.Add(stringSwitch);\n          break;\n        }\n      case NSwitchType::kSimple:\n          break;\n    }\n  }\n  return true;\n}\n\nconst CSwitchResult& CParser::operator[](size_t index) const\n{\n  return _switches[index];\n}\n\n/////////////////////////////////\n// Command parsing procedures\n\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\n    const UString &commandString, UString &postString)\n{\n  for (int i = 0; i < numCommandForms; i++)\n  {\n    const UString id = commandForms[i].IDString;\n    if (commandForms[i].PostStringMode)\n    {\n      if (commandString.Find(id) == 0)\n      {\n        postString = commandString.Mid(id.Length());\n        return i;\n      }\n    }\n    else\n      if (commandString == id)\n      {\n        postString.Empty();\n        return i;\n      }\n  }\n  return -1;\n}\n   \n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\n\n#ifndef __COMMON_COMMANDLINEPARSER_H\n#define __COMMON_COMMANDLINEPARSER_H\n\n#include \"MyString.h\"\n\nnamespace NCommandLineParser {\n\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\n\nnamespace NSwitchType {\n  enum EEnum\n  {\n    kSimple,\n    kPostMinus,\n    kLimitedPostString,\n    kUnLimitedPostString,\n    kPostChar\n  };\n}\n\nstruct CSwitchForm\n{\n  const wchar_t *IDString;\n  NSwitchType::EEnum Type;\n  bool Multi;\n  int MinLen;\n  int MaxLen;\n  const wchar_t *PostCharSet;\n};\n\nstruct CSwitchResult\n{\n  bool ThereIs;\n  bool WithMinus;\n  UStringVector PostStrings;\n  int PostCharIndex;\n  CSwitchResult(): ThereIs(false) {};\n};\n  \nclass CParser\n{\n  int _numSwitches;\n  CSwitchResult *_switches;\n  bool ParseString(const UString &s, const CSwitchForm *switchForms);\npublic:\n  UStringVector NonSwitchStrings;\n  CParser(int numSwitches);\n  ~CParser();\n  void ParseStrings(const CSwitchForm *switchForms,\n    const UStringVector &commandStrings);\n  const CSwitchResult& operator[](size_t index) const;\n};\n\n/////////////////////////////////\n// Command parsing procedures\n\nstruct CCommandForm\n{\n  wchar_t *IDString;\n  bool PostStringMode;\n};\n\n// Returns: Index of form and postString; -1, if there is no match\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms,\n    const UString &commandString, UString &postString);\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/Defs.h",
    "content": "// Common/Defs.h\n\n#ifndef __COMMON_DEFS_H\n#define __COMMON_DEFS_H\n\ntemplate <class T> inline T MyMin(T a, T b)\n  {  return a < b ? a : b; }\ntemplate <class T> inline T MyMax(T a, T b)\n  {  return a > b ? a : b; }\n\ntemplate <class T> inline int MyCompare(T a, T b)\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\n\ninline int BoolToInt(bool value)\n  { return (value ? 1: 0); }\n\ninline bool IntToBool(int value)\n  { return (value != 0); }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/DynamicBuffer.h",
    "content": "// Common/DynamicBuffer.h\n\n#ifndef __COMMON_DYNAMICBUFFER_H\n#define __COMMON_DYNAMICBUFFER_H\n\n#include \"Buffer.h\"\n\ntemplate <class T> class CDynamicBuffer: public CBuffer<T>\n{\n  void GrowLength(size_t size)\n  {\n    size_t delta;\n    if (this->_capacity > 64)\n      delta = this->_capacity / 4;\n    else if (this->_capacity > 8)\n      delta = 16;\n    else\n      delta = 4;\n    delta = MyMax(delta, size);\n    SetCapacity(this->_capacity + delta);\n  }\npublic:\n  CDynamicBuffer(): CBuffer<T>() {};\n  CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};\n  CDynamicBuffer(size_t size): CBuffer<T>(size) {};\n  CDynamicBuffer& operator=(const CDynamicBuffer &buffer)\n  {\n    this->Free();\n    if (buffer._capacity > 0)\n    {\n      SetCapacity(buffer._capacity);\n      memmove(this->_items, buffer._items, buffer._capacity * sizeof(T));\n    }\n    return *this;\n  }\n  void EnsureCapacity(size_t capacity)\n  {\n    if (this->_capacity < capacity)\n      GrowLength(capacity - this->_capacity);\n  }\n};\n\ntypedef CDynamicBuffer<char> CCharDynamicBuffer;\ntypedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;\ntypedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/IntToString.cpp",
    "content": "// Common/IntToString.cpp\n\n#include \"StdAfx.h\"\n\n#include \"IntToString.h\"\n\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base)\n{\n  if (base < 2 || base > 36)\n  {\n    *s = '\\0';\n    return;\n  }\n  char temp[72];\n  int pos = 0;\n  do\n  {\n    int delta = (int)(value % base);\n    temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10)));\n    value /= base;\n  }\n  while (value != 0);\n  do\n    *s++ = temp[--pos];\n  while (pos > 0);\n  *s = '\\0';\n}\n\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s)\n{\n  wchar_t temp[32];\n  int pos = 0;\n  do\n  {\n    temp[pos++] = (wchar_t)(L'0' + (int)(value % 10));\n    value /= 10;\n  }\n  while (value != 0);\n  do\n    *s++ = temp[--pos];\n  while (pos > 0);\n  *s = L'\\0';\n}\n\nvoid ConvertInt64ToString(Int64 value, char *s)\n{\n  if (value < 0)\n  {\n    *s++ = '-';\n    value = -value;\n  }\n  ConvertUInt64ToString(value, s);\n}\n\nvoid ConvertInt64ToString(Int64 value, wchar_t *s)\n{\n  if (value < 0)\n  {\n    *s++ = L'-';\n    value = -value;\n  }\n  ConvertUInt64ToString(value, s);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/IntToString.h",
    "content": "// Common/IntToString.h\n\n#ifndef __COMMON_INTTOSTRING_H\n#define __COMMON_INTTOSTRING_H\n\n#include <stddef.h>\n#include \"Types.h\"\n\nvoid ConvertUInt64ToString(UInt64 value, char *s, UInt32 base = 10);\nvoid ConvertUInt64ToString(UInt64 value, wchar_t *s);\n\nvoid ConvertInt64ToString(Int64 value, char *s);\nvoid ConvertInt64ToString(Int64 value, wchar_t *s);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/ListFileUtils.cpp",
    "content": "// Common/ListFileUtils.cpp\n\n#include \"StdAfx.h\"\n\n#include \"MyWindows.h\"\n#include \"../Windows/FileIO.h\"\n\n#include \"ListFileUtils.h\"\n#include \"StringConvert.h\"\n#include \"UTFConvert.h\"\n\nstatic const char kQuoteChar     = '\\\"';\nstatic void RemoveQuote(UString &s)\n{\n  if (s.Length() >= 2)\n    if (s[0] == kQuoteChar && s[s.Length() - 1] == kQuoteChar)\n      s = s.Mid(1, s.Length() - 2);\n}\n\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT codePage)\n{\n  NWindows::NFile::NIO::CInFile file;\n  if (!file.Open(fileName))\n    return false;\n  UInt64 length;\n  if (!file.GetLength(length))\n    return false;\n  if (length > ((UInt32)1 << 31))\n    return false;\n  AString s;\n  char *p = s.GetBuffer((int)length + 1);\n  UInt32 processed;\n  if (!file.Read(p, (UInt32)length, processed))\n    return false;\n  p[(UInt32)length] = 0;\n  s.ReleaseBuffer();\n  file.Close();\n\n  UString u;\n  #ifdef CP_UTF8\n  if (codePage == CP_UTF8)\n  {\n    if (!ConvertUTF8ToUnicode(s, u))\n      return false;\n  }\n  else\n  #endif\n    u = MultiByteToUnicodeString(s, codePage);\n  if (!u.IsEmpty())\n  {\n    if (u[0] == 0xFEFF)\n      u.Delete(0);\n  }\n\n  UString t;\n  for (int i = 0; i < u.Length(); i++)\n  {\n    wchar_t c = u[i];\n    if (c == L'\\n' || c == 0xD)\n    {\n      t.Trim();\n      RemoveQuote(t);\n      if (!t.IsEmpty())\n        resultStrings.Add(t);\n      t.Empty();\n    }\n    else\n      t += c;\n  }\n  t.Trim();\n  RemoveQuote(t);\n  if (!t.IsEmpty())\n    resultStrings.Add(t);\n  return true;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/ListFileUtils.h",
    "content": "// Common/ListFileUtils.h\n\n#ifndef __COMMON_LISTFILEUTILS_H\n#define __COMMON_LISTFILEUTILS_H\n\n#include \"MyString.h\"\n#include \"Types.h\"\n\nbool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyCom.h",
    "content": "// MyCom.h\n\n#ifndef __MYCOM_H\n#define __MYCOM_H\n\n#include \"MyWindows.h\"\n\n#ifndef RINOK\n#define RINOK(x) { HRESULT __result_ = (x); if (__result_ != S_OK) return __result_; }\n#endif\n\ntemplate <class T>\nclass CMyComPtr\n{\n  T* _p;\npublic:\n  // typedef T _PtrClass;\n  CMyComPtr() { _p = NULL;}\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\n  CMyComPtr(const CMyComPtr<T>& lp)\n  {\n    if ((_p = lp._p) != NULL)\n      _p->AddRef();\n  }\n  ~CMyComPtr() { if (_p) _p->Release(); }\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\n  operator T*() const {  return (T*)_p;  }\n  // T& operator*() const {  return *_p; }\n  T** operator&() { return &_p; }\n  T* operator->() const { return _p; }\n  T* operator=(T* p)\n  {\n    if (p != 0)\n      p->AddRef();\n    if (_p)\n      _p->Release();\n    _p = p;\n    return p;\n  }\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\n  bool operator!() const { return (_p == NULL); }\n  // bool operator==(T* pT) const {  return _p == pT; }\n  // Compare two objects for equivalence\n  void Attach(T* p2)\n  {\n    Release();\n    _p = p2;\n  }\n  T* Detach()\n  {\n    T* pt = _p;\n    _p = NULL;\n    return pt;\n  }\n  #ifdef _WIN32\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\n  {\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\n  }\n  #endif\n  /*\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\n  {\n    CLSID clsid;\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\n    ATLASSERT(_p == NULL);\n    if (SUCCEEDED(hr))\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\n    return hr;\n  }\n  */\n  template <class Q>\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\n  {\n    return _p->QueryInterface(iid, (void**)pp);\n  }\n};\n\n//////////////////////////////////////////////////////////\n\ninline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr)\n{\n  *bstr = ::SysAllocString(src);\n  return (*bstr != 0) ? S_OK : E_OUTOFMEMORY;\n}\n\nclass CMyComBSTR\n{\npublic:\n  BSTR m_str;\n  CMyComBSTR(): m_str(NULL) {}\n  CMyComBSTR(LPCOLESTR src) { m_str = ::SysAllocString(src); }\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\n  /*\n  CMyComBSTR(REFGUID src)\n  {\n    LPOLESTR szGuid;\n    StringFromCLSID(src, &szGuid);\n    m_str = ::SysAllocString(szGuid);\n    CoTaskMemFree(szGuid);\n  }\n  */\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\n  CMyComBSTR& operator=(const CMyComBSTR& src)\n  {\n    if (m_str != src.m_str)\n    {\n      if (m_str)\n        ::SysFreeString(m_str);\n      m_str = src.MyCopy();\n    }\n    return *this;\n  }\n  CMyComBSTR& operator=(LPCOLESTR src)\n  {\n    ::SysFreeString(m_str);\n    m_str = ::SysAllocString(src);\n    return *this;\n  }\n  unsigned int Length() const { return ::SysStringLen(m_str); }\n  operator BSTR() const { return m_str; }\n  BSTR* operator&() { return &m_str; }\n  BSTR MyCopy() const\n  {\n    int byteLen = ::SysStringByteLen(m_str);\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\n    memcpy(res, m_str, byteLen);\n    return res;\n  }\n  /*\n  void Attach(BSTR src) { m_str = src; }\n  BSTR Detach()\n  {\n    BSTR s = m_str;\n    m_str = NULL;\n    return s;\n  }\n  */\n  void Empty()\n  {\n    ::SysFreeString(m_str);\n    m_str = NULL;\n  }\n  bool operator!() const {  return (m_str == NULL); }\n};\n\n//////////////////////////////////////////////////////////\n\nclass CMyUnknownImp\n{\npublic:\n  ULONG __m_RefCount;\n  CMyUnknownImp(): __m_RefCount(0) {}\n};\n\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\n    (REFGUID iid, void **outObject) {\n\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\n\n#define MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) if (iid == IID_IUnknown) \\\n    { *outObject = (void *)(IUnknown *)(i *)this; AddRef(); return S_OK; }\n\n#define MY_QUERYINTERFACE_BEGIN2(i) MY_QUERYINTERFACE_BEGIN \\\n    MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\n    MY_QUERYINTERFACE_ENTRY(i)\n\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\n\n#define MY_ADDREF_RELEASE \\\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\n  return __m_RefCount; delete this; return 0; }\n\n#define MY_UNKNOWN_IMP_SPEC(i) \\\n  MY_QUERYINTERFACE_BEGIN \\\n  i \\\n  MY_QUERYINTERFACE_END \\\n  MY_ADDREF_RELEASE\n\n\n#define MY_UNKNOWN_IMP MY_QUERYINTERFACE_BEGIN \\\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(IUnknown) \\\n  MY_QUERYINTERFACE_END \\\n  MY_ADDREF_RELEASE\n\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i) \\\n  MY_QUERYINTERFACE_ENTRY(i) \\\n  )\n\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i2) \\\n  )\n\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i2) \\\n  MY_QUERYINTERFACE_ENTRY(i3) \\\n  )\n\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i2) \\\n  MY_QUERYINTERFACE_ENTRY(i3) \\\n  MY_QUERYINTERFACE_ENTRY(i4) \\\n  )\n\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY_UNKNOWN(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i2) \\\n  MY_QUERYINTERFACE_ENTRY(i3) \\\n  MY_QUERYINTERFACE_ENTRY(i4) \\\n  MY_QUERYINTERFACE_ENTRY(i5) \\\n  )\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyException.h",
    "content": "// Common/Exception.h\n\n#ifndef __COMMON_EXCEPTION_H\n#define __COMMON_EXCEPTION_H\n\n#include \"MyWindows.h\"\n\nstruct CSystemException\n{\n  HRESULT ErrorCode;\n  CSystemException(HRESULT errorCode): ErrorCode(errorCode) {}\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\n\n#ifndef GUID_DEFINED\n#define GUID_DEFINED\n\n#include \"Types.h\"\n\ntypedef struct {\n  UInt32 Data1;\n  UInt16 Data2;\n  UInt16 Data3;\n  unsigned char Data4[8];\n} GUID;\n\n#ifdef __cplusplus\n#define REFGUID const GUID &\n#else\n#define REFGUID const GUID *\n#endif\n\n#define REFCLSID REFGUID\n#define REFIID REFGUID\n\n#ifdef __cplusplus\ninline int operator==(REFGUID g1, REFGUID g2)\n{\n  for (int i = 0; i < (int)sizeof(g1); i++)\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\n      return 0;\n  return 1;\n}\ninline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\n#endif\n\n#ifdef __cplusplus\n  #define MY_EXTERN_C extern \"C\"\n#else\n  #define MY_EXTERN_C extern\n#endif\n\n#endif // GUID_DEFINED\n\n\n#ifdef DEFINE_GUID\n#undef DEFINE_GUID\n#endif\n\n#ifdef INITGUID\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\n#else\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\n    MY_EXTERN_C const GUID name\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\n\n#ifndef __COMMON_MYINITGUID_H\n#define __COMMON_MYINITGUID_H\n\n#ifdef _WIN32\n#include <initguid.h>\n#else\n#define INITGUID\n#include \"MyGuidDef.h\"\nDEFINE_GUID(IID_IUnknown,\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\n#endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyString.cpp",
    "content": "// Common/MyString.cpp\n\n#include \"StdAfx.h\"\n\n#ifndef _WIN32\n#include <ctype.h>\n#endif\n\n#ifndef _UNICODE\n#include \"StringConvert.h\"\n#endif\n\n#include \"MyString.h\"\n\n\n#ifdef _WIN32\n\n#ifndef _UNICODE\n\nwchar_t MyCharUpper(wchar_t c)\n{\n  if (c == 0)\n    return 0;\n  wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c);\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\n  const int kBufferSize = 4;\n  char s[kBufferSize + 1];\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\n  if (numChars == 0 || numChars > kBufferSize)\n    return c;\n  s[numChars] = 0;\n  ::CharUpperA(s);\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\n  return c;\n}\n\nwchar_t MyCharLower(wchar_t c)\n{\n  if (c == 0)\n    return 0;\n  wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c);\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return (wchar_t)(unsigned int)(UINT_PTR)res;\n  const int kBufferSize = 4;\n  char s[kBufferSize + 1];\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\n  if (numChars == 0 || numChars > kBufferSize)\n    return c;\n  s[numChars] = 0;\n  ::CharLowerA(s);\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\n  return c;\n}\n\nwchar_t * MyStringUpper(wchar_t *s)\n{\n  if (s == 0)\n    return 0;\n  wchar_t *res = CharUpperW(s);\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return res;\n  AString a = UnicodeStringToMultiByte(s);\n  a.MakeUpper();\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\n}\n\nwchar_t * MyStringLower(wchar_t *s)\n{\n  if (s == 0)\n    return 0;\n  wchar_t *res = CharLowerW(s);\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return res;\n  AString a = UnicodeStringToMultiByte(s);\n  a.MakeLower();\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\n}\n\n#endif\n\n/*\ninline int ConvertCompareResult(int r) { return r - 2; }\n\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\n{\n  int res = CompareStringW(\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1);\n  #ifdef _UNICODE\n  return ConvertCompareResult(res);\n  #else\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return ConvertCompareResult(res);\n  return MyStringCollate(UnicodeStringToMultiByte(s1),\n        UnicodeStringToMultiByte(s2));\n  #endif\n}\n\n#ifndef _WIN32_WCE\nint MyStringCollate(const char *s1, const char *s2)\n{\n  return ConvertCompareResult(CompareStringA(\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1));\n}\n\nint MyStringCollateNoCase(const char *s1, const char *s2)\n{\n  return ConvertCompareResult(CompareStringA(\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1));\n}\n#endif\n\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\n{\n  int res = CompareStringW(\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1);\n  #ifdef _UNICODE\n  return ConvertCompareResult(res);\n  #else\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return ConvertCompareResult(res);\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1),\n      UnicodeStringToMultiByte(s2));\n  #endif\n}\n*/\n\n#else\n\nwchar_t MyCharUpper(wchar_t c)\n{\n  return toupper(c);\n}\n\n/*\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\n{\n  for (;;)\n  {\n    wchar_t c1 = *s1++;\n    wchar_t c2 = *s2++;\n    wchar_t u1 = MyCharUpper(c1);\n    wchar_t u2 = MyCharUpper(c2);\n\n    if (u1 < u2) return -1;\n    if (u1 > u2) return 1;\n    if (u1 == 0) return 0;\n  }\n}\n*/\n\n#endif\n\nint MyStringCompare(const char *s1, const char *s2)\n{\n  for (;;)\n  {\n    unsigned char c1 = (unsigned char)*s1++;\n    unsigned char c2 = (unsigned char)*s2++;\n    if (c1 < c2) return -1;\n    if (c1 > c2) return 1;\n    if (c1 == 0) return 0;\n  }\n}\n\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\n{\n  for (;;)\n  {\n    wchar_t c1 = *s1++;\n    wchar_t c2 = *s2++;\n    if (c1 < c2) return -1;\n    if (c1 > c2) return 1;\n    if (c1 == 0) return 0;\n  }\n}\n\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\n{\n  for (;;)\n  {\n    wchar_t c1 = *s1++;\n    wchar_t c2 = *s2++;\n    if (c1 != c2)\n    {\n      wchar_t u1 = MyCharUpper(c1);\n      wchar_t u2 = MyCharUpper(c2);\n      if (u1 < u2) return -1;\n      if (u1 > u2) return 1;\n    }\n    if (c1 == 0) return 0;\n  }\n}\n\n/*\nint MyStringCompareNoCase(const char *s1, const char *s2)\n{\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\n}\n*/\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyString.h",
    "content": "// Common/String.h\n\n#ifndef __COMMON_STRING_H\n#define __COMMON_STRING_H\n\n#include <string.h>\n// #include <wchar.h>\n\n#include \"MyVector.h\"\n\n#ifdef _WIN32\n#include \"MyWindows.h\"\n#endif\n\ntemplate <class T>\ninline int MyStringLen(const T *s)\n{\n  int i;\n  for (i = 0; s[i] != '\\0'; i++);\n  return i;\n}\n\ntemplate <class T>\ninline T * MyStringCopy(T *dest, const T *src)\n{\n  T *destStart = dest;\n  while ((*dest++ = *src++) != 0);\n  return destStart;\n}\n\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\n  { return (p + 1); }\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\n  { return (p + 1); }\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\n  { return (p - 1); }\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\n  { return (p - 1); }\n\n#ifdef _WIN32\n\ninline char* MyStringGetNextCharPointer(char *p)\n  { return CharNextA(p); }\ninline const char* MyStringGetNextCharPointer(const char *p)\n  { return CharNextA(p); }\n\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\n  { return CharPrevA(base, p); }\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\n  { return CharPrevA(base, p); }\n\ninline char MyCharUpper(char c)\n  { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\n#ifdef _UNICODE\ninline wchar_t MyCharUpper(wchar_t c)\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }\n#else\nwchar_t MyCharUpper(wchar_t c);\n#endif\n\ninline char MyCharLower(char c)\n  { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }\n#ifdef _UNICODE\ninline wchar_t MyCharLower(wchar_t c)\n  { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }\n#else\nwchar_t MyCharLower(wchar_t c);\n#endif\n\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\n#ifdef _UNICODE\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\n#else\nwchar_t * MyStringUpper(wchar_t *s);\n#endif\n\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\n#ifdef _UNICODE\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\n#else\nwchar_t * MyStringLower(wchar_t *s);\n#endif\n\n#else // Standard-C\nwchar_t MyCharUpper(wchar_t c);\n#endif\n\n//////////////////////////////////////\n// Compare\n\n/*\n#ifndef _WIN32_WCE\nint MyStringCollate(const char *s1, const char *s2);\nint MyStringCollateNoCase(const char *s1, const char *s2);\n#endif\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\n*/\n\nint MyStringCompare(const char *s1, const char  *s2);\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\n\n// int MyStringCompareNoCase(const char *s1, const char  *s2);\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\n\ntemplate <class T>\nclass CStringBase\n{\n  void TrimLeftWithCharSet(const CStringBase &charSet)\n  {\n    const T *p = _chars;\n    while (charSet.Find(*p) >= 0 && (*p != 0))\n      p = GetNextCharPointer(p);\n    Delete(0, (int)(p - _chars));\n  }\n  void TrimRightWithCharSet(const CStringBase &charSet)\n  {\n    const T *p = _chars;\n    const T *pLast = NULL;\n    while (*p != 0)\n    {\n      if (charSet.Find(*p) >= 0)\n      {\n        if (pLast == NULL)\n          pLast = p;\n      }\n      else\n        pLast = NULL;\n      p = GetNextCharPointer(p);\n    }\n    if (pLast != NULL)\n    {\n      int i = (int)(pLast - _chars);\n      Delete(i, _length - i);\n    }\n\n  }\n  void MoveItems(int destIndex, int srcIndex)\n  {\n    memmove(_chars + destIndex, _chars + srcIndex,\n        sizeof(T) * (_length - srcIndex + 1));\n  }\n  \n  void InsertSpace(int &index, int size)\n  {\n    CorrectIndex(index);\n    GrowLength(size);\n    MoveItems(index + size, index);\n  }\n\n  static T *GetNextCharPointer(T *p)\n    { return MyStringGetNextCharPointer(p); }\n  static const T *GetNextCharPointer(const T *p)\n    { return MyStringGetNextCharPointer(p); }\n  static T *GetPrevCharPointer(T *base, T *p)\n    { return MyStringGetPrevCharPointer(base, p); }\n  static const T *GetPrevCharPointer(const T *base, const T *p)\n    { return MyStringGetPrevCharPointer(base, p); }\nprotected:\n  T *_chars;\n  int _length;\n  int _capacity;\n  \n  void SetCapacity(int newCapacity)\n  {\n    int realCapacity = newCapacity + 1;\n    if (realCapacity == _capacity)\n      return;\n    /*\n    const int kMaxStringSize = 0x20000000;\n    #ifndef _WIN32_WCE\n    if (newCapacity > kMaxStringSize || newCapacity < _length)\n      throw 1052337;\n    #endif\n    */\n    T *newBuffer = new T[realCapacity];\n    if (_capacity > 0)\n    {\n      for (int i = 0; i < _length; i++)\n        newBuffer[i] = _chars[i];\n      delete []_chars;\n    }\n    _chars = newBuffer;\n    _chars[_length] = 0;\n    _capacity = realCapacity;\n  }\n\n  void GrowLength(int n)\n  {\n    int freeSize = _capacity - _length - 1;\n    if (n <= freeSize)\n      return;\n    int delta;\n    if (_capacity > 64)\n      delta = _capacity / 2;\n    else if (_capacity > 8)\n      delta = 16;\n    else\n      delta = 4;\n    if (freeSize + delta < n)\n      delta = n - freeSize;\n    SetCapacity(_capacity + delta);\n  }\n\n  void CorrectIndex(int &index) const\n  {\n    if (index > _length)\n      index = _length;\n  }\n\npublic:\n  CStringBase(): _chars(0), _length(0), _capacity(0) { SetCapacity(3); }\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\n  {\n    SetCapacity(1);\n    _chars[0] = c;\n    _chars[1] = 0;\n    _length = 1;\n  }\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\n  {\n    int length = MyStringLen(chars);\n    SetCapacity(length);\n    MyStringCopy(_chars, chars); // can be optimized by memove()\n    _length = length;\n  }\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\n  {\n    SetCapacity(s._length);\n    MyStringCopy(_chars, s._chars);\n    _length = s._length;\n  }\n  ~CStringBase() {  delete []_chars; }\n\n  operator const T*() const { return _chars;}\n\n  // The minimum size of the character buffer in characters.\n  // This value does not include space for a null terminator.\n  T* GetBuffer(int minBufLength)\n  {\n    if (minBufLength >= _capacity)\n      SetCapacity(minBufLength);\n    return _chars;\n  }\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\n  void ReleaseBuffer(int newLength)\n  {\n    /*\n    #ifndef _WIN32_WCE\n    if (newLength >= _capacity)\n      throw 282217;\n    #endif\n    */\n    _chars[newLength] = 0;\n    _length = newLength;\n  }\n\n  CStringBase& operator=(T c)\n  {\n    Empty();\n    SetCapacity(1);\n    _chars[0] = c;\n    _chars[1] = 0;\n    _length = 1;\n    return *this;\n  }\n  CStringBase& operator=(const T *chars)\n  {\n    Empty();\n    int length = MyStringLen(chars);\n    SetCapacity(length);\n    MyStringCopy(_chars, chars);\n    _length = length;\n    return *this;\n  }\n  CStringBase& operator=(const CStringBase& s)\n  {\n    if (&s == this)\n      return *this;\n    Empty();\n    SetCapacity(s._length);\n    MyStringCopy(_chars, s._chars);\n    _length = s._length;\n    return *this;\n  }\n  \n  CStringBase& operator+=(T c)\n  {\n    GrowLength(1);\n    _chars[_length] = c;\n    _chars[++_length] = 0;\n    return *this;\n  }\n  CStringBase& operator+=(const T *s)\n  {\n    int len = MyStringLen(s);\n    GrowLength(len);\n    MyStringCopy(_chars + _length, s);\n    _length += len;\n    return *this;\n  }\n  CStringBase& operator+=(const CStringBase &s)\n  {\n    GrowLength(s._length);\n    MyStringCopy(_chars + _length, s._chars);\n    _length += s._length;\n    return *this;\n  }\n  void Empty()\n  {\n    _length = 0;\n    _chars[0] = 0;\n  }\n  int Length() const { return _length; }\n  bool IsEmpty() const { return (_length == 0); }\n\n  CStringBase Mid(int startIndex) const\n    { return Mid(startIndex, _length - startIndex); }\n  CStringBase Mid(int startIndex, int count ) const\n  {\n    if (startIndex + count > _length)\n      count = _length - startIndex;\n    \n    if (startIndex == 0 && startIndex + count == _length)\n      return *this;\n    \n    CStringBase<T> result;\n    result.SetCapacity(count);\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\n    for (int i = 0; i < count; i++)\n      result._chars[i] = _chars[startIndex + i];\n    result._chars[count] = 0;\n    result._length = count;\n    return result;\n  }\n  CStringBase Left(int count) const\n    { return Mid(0, count); }\n  CStringBase Right(int count) const\n  {\n    if (count > _length)\n      count = _length;\n    return Mid(_length - count, count);\n  }\n\n  void MakeUpper()\n    { MyStringUpper(_chars); }\n  void MakeLower()\n    { MyStringLower(_chars); }\n\n  int Compare(const CStringBase& s) const\n    { return MyStringCompare(_chars, s._chars); }\n\n  int Compare(const T *s) const\n    { return MyStringCompare(_chars, s); }\n\n  int CompareNoCase(const CStringBase& s) const\n    { return MyStringCompareNoCase(_chars, s._chars); }\n\n  int CompareNoCase(const T *s) const\n    { return MyStringCompareNoCase(_chars, s); }\n\n  /*\n  int Collate(const CStringBase& s) const\n    { return MyStringCollate(_chars, s._chars); }\n  int CollateNoCase(const CStringBase& s) const\n    { return MyStringCollateNoCase(_chars, s._chars); }\n  */\n\n  int Find(T c) const { return Find(c, 0); }\n  int Find(T c, int startIndex) const\n  {\n    T *p = _chars + startIndex;\n    for (;;)\n    {\n      if (*p == c)\n        return (int)(p - _chars);\n      if (*p == 0)\n        return -1;\n      p = GetNextCharPointer(p);\n    }\n  }\n  int Find(const CStringBase &s) const { return Find(s, 0); }\n  int Find(const CStringBase &s, int startIndex) const\n  {\n    if (s.IsEmpty())\n      return startIndex;\n    for (; startIndex < _length; startIndex++)\n    {\n      int j;\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\n        if (_chars[startIndex+j] != s._chars[j])\n          break;\n      if (j == s._length)\n        return startIndex;\n    }\n    return -1;\n  }\n  int ReverseFind(T c) const\n  {\n    if (_length == 0)\n      return -1;\n    T *p = _chars + _length - 1;\n    for (;;)\n    {\n      if (*p == c)\n        return (int)(p - _chars);\n      if (p == _chars)\n        return -1;\n      p = GetPrevCharPointer(_chars, p);\n    }\n  }\n  int FindOneOf(const CStringBase &s) const\n  {\n    for (int i = 0; i < _length; i++)\n      if (s.Find(_chars[i]) >= 0)\n        return i;\n      return -1;\n  }\n\n  void TrimLeft(T c)\n  {\n    const T *p = _chars;\n    while (c == *p)\n      p = GetNextCharPointer(p);\n    Delete(0, p - _chars);\n  }\n  private:\n  CStringBase GetTrimDefaultCharSet()\n  {\n    CStringBase<T> charSet;\n    charSet += (T)' ';\n    charSet += (T)'\\n';\n    charSet += (T)'\\t';\n    return charSet;\n  }\n  public:\n\n  void TrimLeft()\n  {\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\n  }\n  void TrimRight()\n  {\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\n  }\n  void TrimRight(T c)\n  {\n    const T *p = _chars;\n    const T *pLast = NULL;\n    while (*p != 0)\n    {\n      if (*p == c)\n      {\n        if (pLast == NULL)\n          pLast = p;\n      }\n      else\n        pLast = NULL;\n      p = GetNextCharPointer(p);\n    }\n    if (pLast != NULL)\n    {\n      int i = pLast - _chars;\n      Delete(i, _length - i);\n    }\n  }\n  void Trim()\n  {\n    TrimRight();\n    TrimLeft();\n  }\n\n  int Insert(int index, T c)\n  {\n    InsertSpace(index, 1);\n    _chars[index] = c;\n    _length++;\n    return _length;\n  }\n  int Insert(int index, const CStringBase &s)\n  {\n    CorrectIndex(index);\n    if (s.IsEmpty())\n      return _length;\n    int numInsertChars = s.Length();\n    InsertSpace(index, numInsertChars);\n    for (int i = 0; i < numInsertChars; i++)\n      _chars[index + i] = s[i];\n    _length += numInsertChars;\n    return _length;\n  }\n\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\n  int Replace(T oldChar, T newChar)\n  {\n    if (oldChar == newChar)\n      return 0;\n    int number  = 0;\n    int pos  = 0;\n    while (pos < Length())\n    {\n      pos = Find(oldChar, pos);\n      if (pos < 0)\n        break;\n      _chars[pos] = newChar;\n      pos++;\n      number++;\n    }\n    return number;\n  }\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\n  {\n    if (oldString.IsEmpty())\n      return 0;\n    if (oldString == newString)\n      return 0;\n    int oldStringLength = oldString.Length();\n    int newStringLength = newString.Length();\n    int number  = 0;\n    int pos  = 0;\n    while (pos < _length)\n    {\n      pos = Find(oldString, pos);\n      if (pos < 0)\n        break;\n      Delete(pos, oldStringLength);\n      Insert(pos, newString);\n      pos += newStringLength;\n      number++;\n    }\n    return number;\n  }\n  int Delete(int index, int count = 1 )\n  {\n    if (index + count > _length)\n      count = _length - index;\n    if (count > 0)\n    {\n      MoveItems(index, index + count);\n      _length -= count;\n    }\n    return _length;\n  }\n};\n\ntemplate <class T>\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\n{\n  CStringBase<T> result(s1);\n  result += s2;\n  return result;\n}\n\ntemplate <class T>\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\n{\n  CStringBase<T> result(s);\n  result += c;\n  return result;\n}\n\ntemplate <class T>\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\n{\n  CStringBase<T> result(c);\n  result += s;\n  return result;\n}\n\ntemplate <class T>\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\n{\n  CStringBase<T> result(s);\n  result += chars;\n  return result;\n}\n\ntemplate <class T>\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\n{\n  CStringBase<T> result(chars);\n  result += s;\n  return result;\n}\n\ntemplate <class T>\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\n  { return (s1.Compare(s2) == 0); }\n\ntemplate <class T>\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\n  { return (s1.Compare(s2) < 0); }\n\ntemplate <class T>\nbool operator==(const T *s1, const CStringBase<T>& s2)\n  { return (s2.Compare(s1) == 0); }\n\ntemplate <class T>\nbool operator==(const CStringBase<T>& s1, const T *s2)\n  { return (s1.Compare(s2) == 0); }\n\ntemplate <class T>\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\n  { return (s1.Compare(s2) != 0); }\n\ntemplate <class T>\nbool operator!=(const T *s1, const CStringBase<T>& s2)\n  { return (s2.Compare(s1) != 0); }\n\ntemplate <class T>\nbool operator!=(const CStringBase<T>& s1, const T *s2)\n  { return (s1.Compare(s2) != 0); }\n\ntypedef CStringBase<char> AString;\ntypedef CStringBase<wchar_t> UString;\n\ntypedef CObjectVector<AString> AStringVector;\ntypedef CObjectVector<UString> UStringVector;\n\n#ifdef _UNICODE\n  typedef UString CSysString;\n#else\n  typedef AString CSysString;\n#endif\n\ntypedef CObjectVector<CSysString> CSysStringVector;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyUnknown.h",
    "content": "// MyUnknown.h\n\n#ifndef __MYUNKNOWN_H\n#define __MYUNKNOWN_H\n\n#ifdef _WIN32\n\n#ifdef _WIN32_WCE\n#if (_WIN32_WCE > 300)\n#include <basetyps.h>\n#else\n#define MIDL_INTERFACE(x) struct\n#endif\n#else\n#include <basetyps.h>\n#endif\n\n#include <unknwn.h>\n\n#else\n#include \"MyWindows.h\"\n#endif\n  \n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyVector.cpp",
    "content": "// Common/MyVector.cpp\n\n#include \"StdAfx.h\"\n\n#include <string.h>\n\n#include \"MyVector.h\"\n\nCBaseRecordVector::~CBaseRecordVector() { ClearAndFree(); }\n\nvoid CBaseRecordVector::ClearAndFree()\n{\n  Clear();\n  delete []((unsigned char *)_items);\n  _capacity = 0;\n  _size = 0;\n  _items = 0;\n}\n\nvoid CBaseRecordVector::Clear() { DeleteFrom(0); }\nvoid CBaseRecordVector::DeleteBack() { Delete(_size - 1); }\nvoid CBaseRecordVector::DeleteFrom(int index) { Delete(index, _size - index); }\n\nvoid CBaseRecordVector::ReserveOnePosition()\n{\n  if (_size != _capacity)\n    return;\n  int delta = 1;\n  if (_capacity >= 64)\n    delta = _capacity / 4;\n  else if (_capacity >= 8)\n    delta = 8;\n  Reserve(_capacity + delta);\n}\n\nvoid CBaseRecordVector::Reserve(int newCapacity)\n{\n  // if (newCapacity <= _capacity)\n  if (newCapacity == _capacity)\n    return;\n  if ((unsigned)newCapacity >= ((unsigned)1 << (sizeof(unsigned) * 8 - 1)))\n    throw 1052353;\n  size_t newSize = (size_t)(unsigned)newCapacity * _itemSize;\n  if (newSize / _itemSize != (size_t)(unsigned)newCapacity)\n    throw 1052354;\n  unsigned char *p = NULL;\n  if (newSize > 0)\n  {\n    p = new unsigned char[newSize];\n    if (p == 0)\n      throw 1052355;\n    int numRecordsToMove = (_size < newCapacity ? _size : newCapacity);\n    memcpy(p, _items, _itemSize * numRecordsToMove);\n  }\n  delete [](unsigned char *)_items;\n  _items = p;\n  _capacity = newCapacity;\n}\n\nvoid CBaseRecordVector::ReserveDown()\n{\n  Reserve(_size);\n}\n\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\n{\n  memmove(((unsigned char *)_items) + destIndex * _itemSize,\n    ((unsigned char  *)_items) + srcIndex * _itemSize,\n    _itemSize * (_size - srcIndex));\n}\n\nvoid CBaseRecordVector::InsertOneItem(int index)\n{\n  ReserveOnePosition();\n  MoveItems(index + 1, index);\n  _size++;\n}\n\nvoid CBaseRecordVector::Delete(int index, int num)\n{\n  TestIndexAndCorrectNum(index, num);\n  if (num > 0)\n  {\n    MoveItems(index, index + num);\n    _size -= num;\n  }\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyVector.h",
    "content": "// Common/Vector.h\n\n#ifndef __COMMON_VECTOR_H\n#define __COMMON_VECTOR_H\n\n#include \"Defs.h\"\n\nclass CBaseRecordVector\n{\n  void MoveItems(int destIndex, int srcIndex);\nprotected:\n  int _capacity;\n  int _size;\n  void *_items;\n  size_t _itemSize;\n  \n  void ReserveOnePosition();\n  void InsertOneItem(int index);\n  void TestIndexAndCorrectNum(int index, int &num) const\n    { if (index + num > _size) num = _size - index; }\npublic:\n  CBaseRecordVector(size_t itemSize): _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\n  virtual ~CBaseRecordVector();\n  void ClearAndFree();\n  int Size() const { return _size; }\n  bool IsEmpty() const { return (_size == 0); }\n  void Reserve(int newCapacity);\n  void ReserveDown();\n  virtual void Delete(int index, int num = 1);\n  void Clear();\n  void DeleteFrom(int index);\n  void DeleteBack();\n};\n\ntemplate <class T>\nclass CRecordVector: public CBaseRecordVector\n{\npublic:\n  CRecordVector(): CBaseRecordVector(sizeof(T)){};\n  CRecordVector(const CRecordVector &v): CBaseRecordVector(sizeof(T)) { *this = v; }\n  CRecordVector& operator=(const CRecordVector &v)\n  {\n    Clear();\n    return (*this += v);\n  }\n  CRecordVector& operator+=(const CRecordVector &v)\n  {\n    int size = v.Size();\n    Reserve(Size() + size);\n    for (int i = 0; i < size; i++)\n      Add(v[i]);\n    return *this;\n  }\n  int Add(T item)\n  {\n    ReserveOnePosition();\n    ((T *)_items)[_size] = item;\n    return _size++;\n  }\n  void Insert(int index, T item)\n  {\n    InsertOneItem(index);\n    ((T *)_items)[index] = item;\n  }\n  // T* GetPointer() const { return (T*)_items; }\n  // operator const T *() const { return _items; };\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\n  T& operator[](int index) { return ((T *)_items)[index]; }\n  const T& Front() const { return operator[](0); }\n  T& Front() { return operator[](0); }\n  const T& Back() const { return operator[](_size - 1); }\n  T& Back() { return operator[](_size - 1); }\n\n  void Swap(int i, int j)\n  {\n    T temp = operator[](i);\n    operator[](i) = operator[](j);\n    operator[](j) = temp;\n  }\n\n  int FindInSorted(const T& item) const\n  {\n    int left = 0, right = Size();\n    while (left != right)\n    {\n      int mid = (left + right) / 2;\n      const T& midValue = (*this)[mid];\n      if (item == midValue)\n        return mid;\n      if (item < midValue)\n        right = mid;\n      else\n        left = mid + 1;\n    }\n    return -1;\n  }\n\n  int AddToUniqueSorted(const T& item)\n  {\n    int left = 0, right = Size();\n    while (left != right)\n    {\n      int mid = (left + right) / 2;\n      const T& midValue = (*this)[mid];\n      if (item == midValue)\n        return mid;\n      if (item < midValue)\n        right = mid;\n      else\n        left = mid + 1;\n    }\n    Insert(right, item);\n    return right;\n  }\n\n  static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param)\n  {\n    T temp = p[k];\n    for (;;)\n    {\n      int s = (k << 1);\n      if (s > size)\n        break;\n      if (s < size && compare(p + s + 1, p + s, param) > 0)\n        s++;\n      if (compare(&temp, p + s, param) >= 0)\n        break;\n      p[k] = p[s];\n      k = s;\n    }\n    p[k] = temp;\n  }\n\n  void Sort(int (*compare)(const T*, const T*, void *), void *param)\n  {\n    int size = _size;\n    if (size <= 1)\n      return;\n    T* p = (&Front()) - 1;\n    {\n      int i = size / 2;\n      do\n        SortRefDown(p, i, size, compare, param);\n      while (--i != 0);\n    }\n    do\n    {\n      T temp = p[size];\n      p[size--] = p[1];\n      p[1] = temp;\n      SortRefDown(p, 1, size, compare, param);\n    }\n    while (size > 1);\n  }\n};\n\ntypedef CRecordVector<int> CIntVector;\ntypedef CRecordVector<unsigned int> CUIntVector;\ntypedef CRecordVector<bool> CBoolVector;\ntypedef CRecordVector<unsigned char> CByteVector;\ntypedef CRecordVector<void *> CPointerVector;\n\ntemplate <class T>\nclass CObjectVector: public CPointerVector\n{\npublic:\n  CObjectVector() {};\n  ~CObjectVector() { Clear(); };\n  CObjectVector(const CObjectVector &v) { *this = v; }\n  CObjectVector& operator=(const CObjectVector &v)\n  {\n    Clear();\n    return (*this += v);\n  }\n  CObjectVector& operator+=(const CObjectVector &v)\n  {\n    int size = v.Size();\n    Reserve(Size() + size);\n    for (int i = 0; i < size; i++)\n      Add(v[i]);\n    return *this;\n  }\n  const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\n  T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\n  T& Front() { return operator[](0); }\n  const T& Front() const { return operator[](0); }\n  T& Back() { return operator[](_size - 1); }\n  const T& Back() const { return operator[](_size - 1); }\n  int Add(const T& item) { return CPointerVector::Add(new T(item)); }\n  void Insert(int index, const T& item) { CPointerVector::Insert(index, new T(item)); }\n  virtual void Delete(int index, int num = 1)\n  {\n    TestIndexAndCorrectNum(index, num);\n    for (int i = 0; i < num; i++)\n      delete (T *)(((void **)_items)[index + i]);\n    CPointerVector::Delete(index, num);\n  }\n  int Find(const T& item) const\n  {\n    for (int i = 0; i < Size(); i++)\n      if (item == (*this)[i])\n        return i;\n    return -1;\n  }\n  int FindInSorted(const T& item) const\n  {\n    int left = 0, right = Size();\n    while (left != right)\n    {\n      int mid = (left + right) / 2;\n      const T& midValue = (*this)[mid];\n      if (item == midValue)\n        return mid;\n      if (item < midValue)\n        right = mid;\n      else\n        left = mid + 1;\n    }\n    return -1;\n  }\n  int AddToSorted(const T& item)\n  {\n    int left = 0, right = Size();\n    while (left != right)\n    {\n      int mid = (left + right) / 2;\n      const T& midValue = (*this)[mid];\n      if (item == midValue)\n      {\n        right = mid + 1;\n        break;\n      }\n      if (item < midValue)\n        right = mid;\n      else\n        left = mid + 1;\n    }\n    Insert(right, item);\n    return right;\n  }\n\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param)\n    { CPointerVector::Sort(compare, param); }\n\n  static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */)\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/MyWindows.h",
    "content": "// MyWindows.h\n\n#ifndef __MYWINDOWS_H\n#define __MYWINDOWS_H\n\n#ifdef _WIN32\n\n#include <windows.h>\n\n#define CHAR_PATH_SEPARATOR '\\\\'\n#define WCHAR_PATH_SEPARATOR L'\\\\'\n#define STRING_PATH_SEPARATOR \"\\\\\"\n#define WSTRING_PATH_SEPARATOR L\"\\\\\"\n\n#else\n\n#define CHAR_PATH_SEPARATOR '/'\n#define WCHAR_PATH_SEPARATOR L'/'\n#define STRING_PATH_SEPARATOR \"/\"\n#define WSTRING_PATH_SEPARATOR L\"/\"\n\n#include <stddef.h> // for wchar_t\n#include <string.h>\n\n#include \"MyGuidDef.h\"\n\ntypedef char CHAR;\ntypedef unsigned char UCHAR;\n\n#undef BYTE\ntypedef unsigned char BYTE;\n\ntypedef short SHORT;\ntypedef unsigned short USHORT;\n\n#undef WORD\ntypedef unsigned short WORD;\ntypedef short VARIANT_BOOL;\n\ntypedef int INT;\ntypedef Int32 INT32;\ntypedef unsigned int UINT;\ntypedef UInt32 UINT32;\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\ntypedef UINT32 ULONG;\n\n#undef DWORD\ntypedef UINT32 DWORD;\n\ntypedef Int64 LONGLONG;\ntypedef UInt64 ULONGLONG;\n\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\n\ntypedef const CHAR *LPCSTR;\ntypedef CHAR TCHAR;\ntypedef const TCHAR *LPCTSTR;\ntypedef wchar_t WCHAR;\ntypedef WCHAR OLECHAR;\ntypedef const WCHAR *LPCWSTR;\ntypedef OLECHAR *BSTR;\ntypedef const OLECHAR *LPCOLESTR;\ntypedef OLECHAR *LPOLESTR;\n\ntypedef struct _FILETIME\n{\n  DWORD dwLowDateTime;\n  DWORD dwHighDateTime;\n}FILETIME;\n\n#define HRESULT LONG\n#define FAILED(Status) ((HRESULT)(Status)<0)\ntypedef ULONG PROPID;\ntypedef LONG SCODE;\n\n#define S_OK    ((HRESULT)0x00000000L)\n#define S_FALSE ((HRESULT)0x00000001L)\n#define E_NOTIMPL ((HRESULT)0x80004001L)\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\n#define E_ABORT ((HRESULT)0x80004004L)\n#define E_FAIL ((HRESULT)0x80004005L)\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\n#define E_INVALIDARG ((HRESULT)0x80070057L)\n\n#ifdef _MSC_VER\n#define STDMETHODCALLTYPE __stdcall\n#else\n#define STDMETHODCALLTYPE\n#endif\n\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\n\n#define PURE = 0\n\n#define MIDL_INTERFACE(x) struct\n\n#ifdef __cplusplus\n\n#ifndef INITGUID\n#define INITGUID\nDEFINE_GUID(IID_IUnknown,\n0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);\n#endif\nstruct IUnknown\n{\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\n  STDMETHOD_(ULONG, AddRef)() PURE;\n  STDMETHOD_(ULONG, Release)() PURE;\n  #ifndef _WIN32\n  virtual ~IUnknown() {}\n  #endif\n};\n\ntypedef IUnknown *LPUNKNOWN;\n\n#endif\n\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\n\nenum VARENUM\n{\n  VT_EMPTY = 0,\n  VT_NULL = 1,\n  VT_I2 = 2,\n  VT_I4 = 3,\n  VT_R4 = 4,\n  VT_R8 = 5,\n  VT_CY = 6,\n  VT_DATE = 7,\n  VT_BSTR = 8,\n  VT_DISPATCH = 9,\n  VT_ERROR = 10,\n  VT_BOOL = 11,\n  VT_VARIANT = 12,\n  VT_UNKNOWN = 13,\n  VT_DECIMAL = 14,\n  VT_I1 = 16,\n  VT_UI1 = 17,\n  VT_UI2 = 18,\n  VT_UI4 = 19,\n  VT_I8 = 20,\n  VT_UI8 = 21,\n  VT_INT = 22,\n  VT_UINT = 23,\n  VT_VOID = 24,\n  VT_HRESULT = 25,\n  VT_FILETIME = 64\n};\n\ntypedef unsigned short VARTYPE;\ntypedef WORD PROPVAR_PAD1;\ntypedef WORD PROPVAR_PAD2;\ntypedef WORD PROPVAR_PAD3;\n\n#ifdef __cplusplus\n\ntypedef struct tagPROPVARIANT\n{\n  VARTYPE vt;\n  PROPVAR_PAD1 wReserved1;\n  PROPVAR_PAD2 wReserved2;\n  PROPVAR_PAD3 wReserved3;\n  union\n  {\n    CHAR cVal;\n    UCHAR bVal;\n    SHORT iVal;\n    USHORT uiVal;\n    LONG lVal;\n    ULONG ulVal;\n    INT intVal;\n    UINT uintVal;\n    LARGE_INTEGER hVal;\n    ULARGE_INTEGER uhVal;\n    VARIANT_BOOL boolVal;\n    SCODE scode;\n    FILETIME filetime;\n    BSTR bstrVal;\n  };\n} PROPVARIANT;\n\ntypedef PROPVARIANT tagVARIANT;\ntypedef tagVARIANT VARIANT;\ntypedef VARIANT VARIANTARG;\n\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\n\n#endif\n\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\nMY_EXTERN_C void SysFreeString(BSTR bstr);\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\n\nMY_EXTERN_C DWORD GetLastError();\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\n\n#define CP_ACP    0\n#define CP_OEMCP  1\n\ntypedef enum tagSTREAM_SEEK\n{\n  STREAM_SEEK_SET = 0,\n  STREAM_SEEK_CUR = 1,\n  STREAM_SEEK_END = 2\n} STREAM_SEEK;\n\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\n \n#include \"StdAfx.h\"\n\n#include <stdlib.h>\n\n#include \"NewHandler.h\"\n\n// #define DEBUG_MEMORY_LEAK\n\n#ifndef DEBUG_MEMORY_LEAK\n\n#ifdef _WIN32\nvoid *\n#ifdef _MSC_VER\n__cdecl\n#endif\noperator new(size_t size)\n{\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\n  void *p = ::malloc(size);\n  if (p == 0)\n    throw CNewException();\n  return p;\n}\n\nvoid\n#ifdef _MSC_VER\n__cdecl\n#endif\noperator delete(void *p) throw()\n{\n  /*\n  if (p == 0)\n    return;\n  ::HeapFree(::GetProcessHeap(), 0, p);\n  */\n  ::free(p);\n}\n#endif\n\n#else\n\n#pragma init_seg(lib)\nconst int kDebugSize = 1000000;\nstatic void *a[kDebugSize];\nstatic int index = 0;\n\nstatic int numAllocs = 0;\nvoid * __cdecl operator new(size_t size)\n{\n  numAllocs++;\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\n  if (index == 40)\n  {\n    int t = 1;\n  }\n  if (index < kDebugSize)\n  {\n    a[index] = p;\n    index++;\n  }\n  if (p == 0)\n    throw CNewException();\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\n  return p;\n}\n\nclass CC\n{\npublic:\n  CC()\n  {\n    for (int i = 0; i < kDebugSize; i++)\n      a[i] = 0;\n  }\n  ~CC()\n  {\n    for (int i = 0; i < kDebugSize; i++)\n      if (a[i] != 0)\n        return;\n  }\n} g_CC;\n\n\nvoid __cdecl operator delete(void *p)\n{\n  if (p == 0)\n    return;\n  /*\n  for (int i = 0; i < index; i++)\n    if (a[i] == p)\n      a[i] = 0;\n  */\n  HeapFree(GetProcessHeap(), 0, p);\n  numAllocs--;\n  printf(\"Free %d\\n\", numAllocs);\n}\n\n#endif\n\n/*\nint MemErrorVC(size_t)\n{\n  throw CNewException();\n  // return 1;\n}\nCNewHandlerSetter::CNewHandlerSetter()\n{\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\n}\nCNewHandlerSetter::~CNewHandlerSetter()\n{\n  // _set_new_handler(MemErrorOldVCFunction);\n}\n*/\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\n\n#ifndef __COMMON_NEWHANDLER_H\n#define __COMMON_NEWHANDLER_H\n\nclass CNewException {};\n\n#ifdef _WIN32\nvoid\n#ifdef _MSC_VER\n__cdecl\n#endif\noperator delete(void *p) throw();\n#endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n// #include \"MyWindows.h\"\n#include \"NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/StdInStream.cpp",
    "content": "// Common/StdInStream.cpp\n\n#include \"StdAfx.h\"\n\n#include <tchar.h>\n#include \"StdInStream.h\"\n\n#ifdef _MSC_VER\n// \"was declared deprecated\" disabling\n#pragma warning(disable : 4996 )\n#endif\n\nstatic const char kIllegalChar = '\\0';\nstatic const char kNewLineChar = '\\n';\n\nstatic const char *kEOFMessage = \"Unexpected end of input stream\";\nstatic const char *kReadErrorMessage  =\"Error reading input stream\";\nstatic const char *kIllegalCharMessage = \"Illegal character in input stream\";\n\nstatic LPCTSTR kFileOpenMode = TEXT(\"r\");\n\nCStdInStream g_StdIn(stdin);\n\nbool CStdInStream::Open(LPCTSTR fileName)\n{\n  Close();\n  _stream = _tfopen(fileName, kFileOpenMode);\n  _streamIsOpen = (_stream != 0);\n  return _streamIsOpen;\n}\n\nbool CStdInStream::Close()\n{\n  if (!_streamIsOpen)\n    return true;\n  _streamIsOpen = (fclose(_stream) != 0);\n  return !_streamIsOpen;\n}\n\nCStdInStream::~CStdInStream()\n{\n  Close();\n}\n\nAString CStdInStream::ScanStringUntilNewLine()\n{\n  AString s;\n  for (;;)\n  {\n    int intChar = GetChar();\n    if (intChar == EOF)\n      throw kEOFMessage;\n    char c = char(intChar);\n    if (c == kIllegalChar)\n      throw kIllegalCharMessage;\n    if (c == kNewLineChar)\n      break;\n    s += c;\n  }\n  return s;\n}\n\nvoid CStdInStream::ReadToString(AString &resultString)\n{\n  resultString.Empty();\n  int c;\n  while ((c = GetChar()) != EOF)\n    resultString += char(c);\n}\n\nbool CStdInStream::Eof()\n{\n  return (feof(_stream) != 0);\n}\n\nint CStdInStream::GetChar()\n{\n  int c = fgetc(_stream); // getc() doesn't work in BeOS?\n  if (c == EOF && !Eof())\n    throw kReadErrorMessage;\n  return c;\n}\n\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/StdInStream.h",
    "content": "// Common/StdInStream.h\n\n#ifndef __COMMON_STDINSTREAM_H\n#define __COMMON_STDINSTREAM_H\n\n#include <stdio.h>\n\n#include \"MyString.h\"\n#include \"Types.h\"\n\nclass CStdInStream\n{\n  bool _streamIsOpen;\n  FILE *_stream;\npublic:\n  CStdInStream(): _streamIsOpen(false) {};\n  CStdInStream(FILE *stream): _streamIsOpen(false), _stream(stream) {};\n  ~CStdInStream();\n  bool Open(LPCTSTR fileName);\n  bool Close();\n\n  AString ScanStringUntilNewLine();\n  void ReadToString(AString &resultString);\n\n  bool Eof();\n  int GetChar();\n};\n\nextern CStdInStream g_StdIn;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/StdOutStream.cpp",
    "content": "// Common/StdOutStream.cpp\n\n#include \"StdAfx.h\"\n\n#include <tchar.h>\n\n#include \"StdOutStream.h\"\n#include \"IntToString.h\"\n#include \"StringConvert.h\"\n\n#ifdef _MSC_VER\n// \"was declared deprecated\" disabling\n#pragma warning(disable : 4996 )\n#endif\n\nstatic const char kNewLineChar =  '\\n';\n\nstatic const char *kFileOpenMode = \"wt\";\n\nCStdOutStream  g_StdOut(stdout);\nCStdOutStream  g_StdErr(stderr);\n\nbool CStdOutStream::Open(const char *fileName)\n{\n  Close();\n  _stream = fopen(fileName, kFileOpenMode);\n  _streamIsOpen = (_stream != 0);\n  return _streamIsOpen;\n}\n\nbool CStdOutStream::Close()\n{\n  if (!_streamIsOpen)\n    return true;\n  if (fclose(_stream) != 0)\n    return false;\n  _stream = 0;\n  _streamIsOpen = false;\n  return true;\n}\n\nbool CStdOutStream::Flush()\n{\n  return (fflush(_stream) == 0);\n}\n\nCStdOutStream::~CStdOutStream ()\n{\n  Close();\n}\n\nCStdOutStream & CStdOutStream::operator<<(CStdOutStream & (*aFunction)(CStdOutStream  &))\n{\n  (*aFunction)(*this);\n  return *this;\n}\n\nCStdOutStream & endl(CStdOutStream & outStream)\n{\n  return outStream << kNewLineChar;\n}\n\nCStdOutStream & CStdOutStream::operator<<(const char *string)\n{\n  fputs(string, _stream);\n  return *this;\n}\n\nCStdOutStream & CStdOutStream::operator<<(const wchar_t *string)\n{\n  *this << (const char *)UnicodeStringToMultiByte(string, CP_OEMCP);\n  return *this;\n}\n\nCStdOutStream & CStdOutStream::operator<<(char c)\n{\n  fputc(c, _stream);\n  return *this;\n}\n\nCStdOutStream & CStdOutStream::operator<<(int number)\n{\n  char textString[32];\n  ConvertInt64ToString(number, textString);\n  return operator<<(textString);\n}\n\nCStdOutStream & CStdOutStream::operator<<(UInt64 number)\n{\n  char textString[32];\n  ConvertUInt64ToString(number, textString);\n  return operator<<(textString);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/StdOutStream.h",
    "content": "// Common/StdOutStream.h\n\n#ifndef __COMMON_STDOUTSTREAM_H\n#define __COMMON_STDOUTSTREAM_H\n\n#include <stdio.h>\n\n#include \"Types.h\"\n\nclass CStdOutStream\n{\n  bool _streamIsOpen;\n  FILE *_stream;\npublic:\n  CStdOutStream (): _streamIsOpen(false), _stream(0) {};\n  CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};\n  ~CStdOutStream ();\n  operator FILE *() { return _stream; }\n  bool Open(const char *fileName);\n  bool Close();\n  bool Flush();\n  CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream  &));\n  CStdOutStream & operator<<(const char *string);\n  CStdOutStream & operator<<(const wchar_t *string);\n  CStdOutStream & operator<<(char c);\n  CStdOutStream & operator<<(int number);\n  CStdOutStream & operator<<(UInt64 number);\n};\n\nCStdOutStream & endl(CStdOutStream & outStream);\n\nextern CStdOutStream g_StdOut;\nextern CStdOutStream g_StdErr;\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\n\n#include \"StdAfx.h\"\n\n#include \"StringConvert.h\"\n\n#ifndef _WIN32\n#include <stdlib.h>\n#endif\n\n#ifdef _WIN32\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\n{\n  UString resultString;\n  if (!srcString.IsEmpty())\n  {\n    int numChars = MultiByteToWideChar(codePage, 0, srcString,\n      srcString.Length(), resultString.GetBuffer(srcString.Length()),\n      srcString.Length() + 1);\n    #ifndef _WIN32_WCE\n    if (numChars == 0)\n      throw 282228;\n    #endif\n    resultString.ReleaseBuffer(numChars);\n  }\n  return resultString;\n}\n\nAString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed)\n{\n  AString dest;\n  defaultCharWasUsed = false;\n  if (!s.IsEmpty())\n  {\n    int numRequiredBytes = s.Length() * 2;\n    BOOL defUsed;\n    int numChars = WideCharToMultiByte(codePage, 0, s, s.Length(),\n        dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1,\n        &defaultChar, &defUsed);\n    defaultCharWasUsed = (defUsed != FALSE);\n    #ifndef _WIN32_WCE\n    if (numChars == 0)\n      throw 282229;\n    #endif\n    dest.ReleaseBuffer(numChars);\n  }\n  return dest;\n}\n\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\n{\n  bool defaultCharWasUsed;\n  return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed);\n}\n\n#ifndef _WIN32_WCE\nAString SystemStringToOemString(const CSysString &srcString)\n{\n  AString result;\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\n  result.ReleaseBuffer();\n  return result;\n}\n#endif\n\n#else\n\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\n{\n  UString resultString;\n  for (int i = 0; i < srcString.Length(); i++)\n    resultString += wchar_t(srcString[i]);\n  /*\n  if (!srcString.IsEmpty())\n  {\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\n    resultString.ReleaseBuffer(numChars);\n  }\n  */\n  return resultString;\n}\n\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\n{\n  AString resultString;\n  for (int i = 0; i < srcString.Length(); i++)\n    resultString += char(srcString[i]);\n  /*\n  if (!srcString.IsEmpty())\n  {\n    int numRequiredBytes = srcString.Length() * 6 + 1;\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\n    resultString.ReleaseBuffer(numChars);\n  }\n  */\n  return resultString;\n}\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\n\n#ifndef __COMMON_STRINGCONVERT_H\n#define __COMMON_STRINGCONVERT_H\n\n#include \"MyWindows.h\"\n#include \"MyString.h\"\n#include \"Types.h\"\n\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage, char defaultChar, bool &defaultCharWasUsed);\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\n\n\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\n  { return unicodeString; }\ninline const UString& GetUnicodeString(const UString &unicodeString)\n  { return unicodeString; }\ninline UString GetUnicodeString(const AString &ansiString)\n  { return MultiByteToUnicodeString(ansiString); }\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\n  { return unicodeString; }\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\n  { return unicodeString; }\n\ninline const char* GetAnsiString(const char* ansiString)\n  { return ansiString; }\ninline const AString& GetAnsiString(const AString &ansiString)\n  { return ansiString; }\ninline AString GetAnsiString(const UString &unicodeString)\n  { return UnicodeStringToMultiByte(unicodeString); }\n\ninline const char* GetOemString(const char* oemString)\n  { return oemString; }\ninline const AString& GetOemString(const AString &oemString)\n  { return oemString; }\ninline AString GetOemString(const UString &unicodeString)\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\n\n\n#ifdef _UNICODE\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\n    { return unicodeString;}\n  inline const UString& GetSystemString(const UString &unicodeString)\n    { return unicodeString;}\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */)\n    { return unicodeString;}\n  inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */)\n    { return unicodeString;}\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\n  inline UString GetSystemString(const AString &multiByteString)\n    { return MultiByteToUnicodeString(multiByteString);}\n#else\n  inline const char* GetSystemString(const char *ansiString)\n    { return ansiString; }\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\n    { return multiByteString; }\n  inline const char * GetSystemString(const char *multiByteString, UINT)\n    { return multiByteString; }\n  inline AString GetSystemString(const UString &unicodeString)\n    { return UnicodeStringToMultiByte(unicodeString); }\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\n#endif\n\n#ifndef _WIN32_WCE\nAString SystemStringToOemString(const CSysString &srcString);\n#endif\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\n\n#include \"StdAfx.h\"\n\n#include \"StringToInt.h\"\n\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\n{\n  UInt64 result = 0;\n  for (;;)\n  {\n    char c = *s;\n    if (c < '0' || c > '9')\n    {\n      if (end != NULL)\n        *end = s;\n      return result;\n    }\n    result *= 10;\n    result += (c - '0');\n    s++;\n  }\n}\n\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\n{\n  UInt64 result = 0;\n  for (;;)\n  {\n    char c = *s;\n    if (c < '0' || c > '7')\n    {\n      if (end != NULL)\n        *end = s;\n      return result;\n    }\n    result <<= 3;\n    result += (c - '0');\n    s++;\n  }\n}\n\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end)\n{\n  UInt64 result = 0;\n  for (;;)\n  {\n    char c = *s;\n    UInt32 v;\n    if (c >= '0' && c <= '9') v = (c - '0');\n    else if (c >= 'A' && c <= 'F') v = 10 + (c - 'A');\n    else if (c >= 'a' && c <= 'f') v = 10 + (c - 'a');\n    else\n    {\n      if (end != NULL)\n        *end = s;\n      return result;\n    }\n    result <<= 4;\n    result |= v;\n    s++;\n  }\n}\n\n\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\n{\n  UInt64 result = 0;\n  for (;;)\n  {\n    wchar_t c = *s;\n    if (c < '0' || c > '9')\n    {\n      if (end != NULL)\n        *end = s;\n      return result;\n    }\n    result *= 10;\n    result += (c - '0');\n    s++;\n  }\n}\n\n\nInt64 ConvertStringToInt64(const char *s, const char **end)\n{\n  if (*s == '-')\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\n  return ConvertStringToUInt64(s, end);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\n\n#ifndef __COMMON_STRINGTOINT_H\n#define __COMMON_STRINGTOINT_H\n\n#include <string.h>\n#include \"Types.h\"\n\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\nUInt64 ConvertHexStringToUInt64(const char *s, const char **end);\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\n\nInt64 ConvertStringToInt64(const char *s, const char **end);\n\n#endif\n\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/Types.h",
    "content": "// Common/Types.h\n\n#ifndef __COMMON_TYPES_H\n#define __COMMON_TYPES_H\n\nextern \"C\"\n{\n#include \"../../C/Types.h\"\n}\n\ntypedef int HRes;\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/UTFConvert.cpp",
    "content": "// UTFConvert.cpp\n\n#include \"StdAfx.h\"\n\n#include \"UTFConvert.h\"\n#include \"Types.h\"\n\nstatic const Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\n\nstatic Bool Utf8_To_Utf16(wchar_t *dest, size_t *destLen, const char *src, size_t srcLen)\n{\n  size_t destPos = 0, srcPos = 0;\n  for (;;)\n  {\n    Byte c;\n    int numAdds;\n    if (srcPos == srcLen)\n    {\n      *destLen = destPos;\n      return True;\n    }\n    c = (Byte)src[srcPos++];\n\n    if (c < 0x80)\n    {\n      if (dest)\n        dest[destPos] = (wchar_t)c;\n      destPos++;\n      continue;\n    }\n    if (c < 0xC0)\n      break;\n    for (numAdds = 1; numAdds < 5; numAdds++)\n      if (c < kUtf8Limits[numAdds])\n        break;\n    UInt32 value = (c - kUtf8Limits[numAdds - 1]);\n\n    do\n    {\n      Byte c2;\n      if (srcPos == srcLen)\n        break;\n      c2 = (Byte)src[srcPos++];\n      if (c2 < 0x80 || c2 >= 0xC0)\n        break;\n      value <<= 6;\n      value |= (c2 - 0x80);\n    }\n    while (--numAdds != 0);\n    \n    if (value < 0x10000)\n    {\n      if (dest)\n        dest[destPos] = (wchar_t)value;\n      destPos++;\n    }\n    else\n    {\n      value -= 0x10000;\n      if (value >= 0x100000)\n        break;\n      if (dest)\n      {\n        dest[destPos + 0] = (wchar_t)(0xD800 + (value >> 10));\n        dest[destPos + 1] = (wchar_t)(0xDC00 + (value & 0x3FF));\n      }\n      destPos += 2;\n    }\n  }\n  *destLen = destPos;\n  return False;\n}\n\nstatic Bool Utf16_To_Utf8(char *dest, size_t *destLen, const wchar_t *src, size_t srcLen)\n{\n  size_t destPos = 0, srcPos = 0;\n  for (;;)\n  {\n    unsigned numAdds;\n    UInt32 value;\n    if (srcPos == srcLen)\n    {\n      *destLen = destPos;\n      return True;\n    }\n    value = src[srcPos++];\n    if (value < 0x80)\n    {\n      if (dest)\n        dest[destPos] = (char)value;\n      destPos++;\n      continue;\n    }\n    if (value >= 0xD800 && value < 0xE000)\n    {\n      UInt32 c2;\n      if (value >= 0xDC00 || srcPos == srcLen)\n        break;\n      c2 = src[srcPos++];\n      if (c2 < 0xDC00 || c2 >= 0xE000)\n        break;\n      value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\n    }\n    for (numAdds = 1; numAdds < 5; numAdds++)\n      if (value < (((UInt32)1) << (numAdds * 5 + 6)))\n        break;\n    if (dest)\n      dest[destPos] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\n    destPos++;\n    do\n    {\n      numAdds--;\n      if (dest)\n        dest[destPos] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\n      destPos++;\n    }\n    while (numAdds != 0);\n  }\n  *destLen = destPos;\n  return False;\n}\n\nbool ConvertUTF8ToUnicode(const AString &src, UString &dest)\n{\n  dest.Empty();\n  size_t destLen = 0;\n  Utf8_To_Utf16(NULL, &destLen, src, src.Length());\n  wchar_t *p = dest.GetBuffer((int)destLen);\n  Bool res = Utf8_To_Utf16(p, &destLen, src, src.Length());\n  p[destLen] = 0;\n  dest.ReleaseBuffer();\n  return res ? true : false;\n}\n\nbool ConvertUnicodeToUTF8(const UString &src, AString &dest)\n{\n  dest.Empty();\n  size_t destLen = 0;\n  Utf16_To_Utf8(NULL, &destLen, src, src.Length());\n  char *p = dest.GetBuffer((int)destLen);\n  Bool res = Utf16_To_Utf8(p, &destLen, src, src.Length());\n  p[destLen] = 0;\n  dest.ReleaseBuffer();\n  return res ? true : false;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/UTFConvert.h",
    "content": "// Common/UTFConvert.h\n\n#ifndef __COMMON_UTFCONVERT_H\n#define __COMMON_UTFCONVERT_H\n\n#include \"MyString.h\"\n\nbool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString);\nbool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/Wildcard.cpp",
    "content": "// Common/Wildcard.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Wildcard.h\"\n\nbool g_CaseSensitive =\n  #ifdef _WIN32\n    false;\n  #else\n    true;\n  #endif\n\nstatic const wchar_t kAnyCharsChar = L'*';\nstatic const wchar_t kAnyCharChar = L'?';\n\n#ifdef _WIN32\nstatic const wchar_t kDirDelimiter1 = L'\\\\';\n#endif\nstatic const wchar_t kDirDelimiter2 = L'/';\n\nstatic const UString kWildCardCharSet = L\"?*\";\n\nstatic const UString kIllegalWildCardFileNameChars=\n  L\"\\x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\xA\\xB\\xC\\xD\\xE\\xF\"\n  L\"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F\"\n  L\"\\\"/:<>\\\\|\";\n\n\nstatic inline bool IsCharDirLimiter(wchar_t c)\n{\n  return (\n    #ifdef _WIN32\n    c == kDirDelimiter1 ||\n    #endif\n    c == kDirDelimiter2);\n}\n\nint CompareFileNames(const UString &s1, const UString &s2)\n{\n  if (g_CaseSensitive)\n    return s1.Compare(s2);\n  return s1.CompareNoCase(s2);\n}\n\n// -----------------------------------------\n// this function compares name with mask\n// ? - any char\n// * - any char or empty\n\nstatic bool EnhancedMaskTest(const wchar_t *mask, const wchar_t *name)\n{\n  for (;;)\n  {\n    wchar_t m = *mask;\n    wchar_t c = *name;\n    if (m == 0)\n      return (c == 0);\n    if (m == kAnyCharsChar)\n    {\n      if (EnhancedMaskTest(mask + 1, name))\n        return true;\n      if (c == 0)\n        return false;\n    }\n    else\n    {\n      if (m == kAnyCharChar)\n      {\n        if (c == 0)\n          return false;\n      }\n      else if (m != c)\n        if (g_CaseSensitive || MyCharUpper(m) != MyCharUpper(c))\n          return false;\n      mask++;\n    }\n    name++;\n  }\n}\n\n// --------------------------------------------------\n// Splits path to strings\n\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts)\n{\n  pathParts.Clear();\n  UString name;\n  int len = path.Length();\n  if (len == 0)\n    return;\n  for (int i = 0; i < len; i++)\n  {\n    wchar_t c = path[i];\n    if (IsCharDirLimiter(c))\n    {\n      pathParts.Add(name);\n      name.Empty();\n    }\n    else\n      name += c;\n  }\n  pathParts.Add(name);\n}\n\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name)\n{\n  int i;\n  for (i = path.Length() - 1; i >= 0; i--)\n    if (IsCharDirLimiter(path[i]))\n      break;\n  dirPrefix = path.Left(i + 1);\n  name = path.Mid(i + 1);\n}\n\nUString ExtractDirPrefixFromPath(const UString &path)\n{\n  int i;\n  for (i = path.Length() - 1; i >= 0; i--)\n    if (IsCharDirLimiter(path[i]))\n      break;\n  return path.Left(i + 1);\n}\n\nUString ExtractFileNameFromPath(const UString &path)\n{\n  int i;\n  for (i = path.Length() - 1; i >= 0; i--)\n    if (IsCharDirLimiter(path[i]))\n      break;\n  return path.Mid(i + 1);\n}\n\n\nbool CompareWildCardWithName(const UString &mask, const UString &name)\n{\n  return EnhancedMaskTest(mask, name);\n}\n\nbool DoesNameContainWildCard(const UString &path)\n{\n  return (path.FindOneOf(kWildCardCharSet) >= 0);\n}\n\n\n// ----------------------------------------------------------'\n// NWildcard\n\nnamespace NWildcard {\n\n\n/*\nM = MaskParts.Size();\nN = TestNameParts.Size();\n\n                           File                          Dir\nForFile     req   M<=N  [N-M, N)                          -\n         nonreq   M=N   [0, M)                            -\n \nForDir      req   M<N   [0, M) ... [N-M-1, N-1)  same as ForBoth-File\n         nonreq         [0, M)                   same as ForBoth-File\n\nForBoth     req   m<=N  [0, M) ... [N-M, N)      same as ForBoth-File\n         nonreq         [0, M)                   same as ForBoth-File\n\n*/\n\nbool CItem::CheckPath(const UStringVector &pathParts, bool isFile) const\n{\n  if (!isFile && !ForDir)\n    return false;\n  int delta = (int)pathParts.Size() - (int)PathParts.Size();\n  if (delta < 0)\n    return false;\n  int start = 0;\n  int finish = 0;\n  if (isFile)\n  {\n    if (!ForDir && !Recursive && delta !=0)\n      return false;\n    if (!ForFile && delta == 0)\n      return false;\n    if (!ForDir && Recursive)\n      start = delta;\n  }\n  if (Recursive)\n  {\n    finish = delta;\n    if (isFile && !ForFile)\n      finish = delta - 1;\n  }\n  for (int d = start; d <= finish; d++)\n  {\n    int i;\n    for (i = 0; i < PathParts.Size(); i++)\n      if (!CompareWildCardWithName(PathParts[i], pathParts[i + d]))\n        break;\n    if (i == PathParts.Size())\n      return true;\n  }\n  return false;\n}\n\nint CCensorNode::FindSubNode(const UString &name) const\n{\n  for (int i = 0; i < SubNodes.Size(); i++)\n    if (CompareFileNames(SubNodes[i].Name, name) == 0)\n      return i;\n  return -1;\n}\n\nvoid CCensorNode::AddItemSimple(bool include, CItem &item)\n{\n  if (include)\n    IncludeItems.Add(item);\n  else\n    ExcludeItems.Add(item);\n}\n\nvoid CCensorNode::AddItem(bool include, CItem &item)\n{\n  if (item.PathParts.Size() <= 1)\n  {\n    AddItemSimple(include, item);\n    return;\n  }\n  const UString &front = item.PathParts.Front();\n  if (DoesNameContainWildCard(front))\n  {\n    AddItemSimple(include, item);\n    return;\n  }\n  int index = FindSubNode(front);\n  if (index < 0)\n    index = SubNodes.Add(CCensorNode(front, this));\n  item.PathParts.Delete(0);\n  SubNodes[index].AddItem(include, item);\n}\n\nvoid CCensorNode::AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir)\n{\n  CItem item;\n  SplitPathToParts(path, item.PathParts);\n  item.Recursive = recursive;\n  item.ForFile = forFile;\n  item.ForDir = forDir;\n  AddItem(include, item);\n}\n\nbool CCensorNode::NeedCheckSubDirs() const\n{\n  for (int i = 0; i < IncludeItems.Size(); i++)\n  {\n    const CItem &item = IncludeItems[i];\n    if (item.Recursive || item.PathParts.Size() > 1)\n      return true;\n  }\n  return false;\n}\n\nbool CCensorNode::AreThereIncludeItems() const\n{\n  if (IncludeItems.Size() > 0)\n    return true;\n  for (int i = 0; i < SubNodes.Size(); i++)\n    if (SubNodes[i].AreThereIncludeItems())\n      return true;\n  return false;\n}\n\nbool CCensorNode::CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const\n{\n  const CObjectVector<CItem> &items = include ? IncludeItems : ExcludeItems;\n  for (int i = 0; i < items.Size(); i++)\n    if (items[i].CheckPath(pathParts, isFile))\n      return true;\n  return false;\n}\n\nbool CCensorNode::CheckPath(UStringVector &pathParts, bool isFile, bool &include) const\n{\n  if (CheckPathCurrent(false, pathParts, isFile))\n  {\n    include = false;\n    return true;\n  }\n  include = true;\n  bool finded = CheckPathCurrent(true, pathParts, isFile);\n  if (pathParts.Size() == 1)\n    return finded;\n  int index = FindSubNode(pathParts.Front());\n  if (index >= 0)\n  {\n    UStringVector pathParts2 = pathParts;\n    pathParts2.Delete(0);\n    if (SubNodes[index].CheckPath(pathParts2, isFile, include))\n      return true;\n  }\n  return finded;\n}\n\nbool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) const\n{\n  UStringVector pathParts;\n  SplitPathToParts(path, pathParts);\n  return CheckPath(pathParts, isFile, include);\n}\n\nbool CCensorNode::CheckPath(const UString &path, bool isFile) const\n{\n  bool include;\n  if (CheckPath(path, isFile, include))\n    return include;\n  return false;\n}\n\nbool CCensorNode::CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const\n{\n  if (CheckPathCurrent(include, pathParts, isFile))\n    return true;\n  if (Parent == 0)\n    return false;\n  pathParts.Insert(0, Name);\n  return Parent->CheckPathToRoot(include, pathParts, isFile);\n}\n\n/*\nbool CCensorNode::CheckPathToRoot(bool include, const UString &path, bool isFile) const\n{\n  UStringVector pathParts;\n  SplitPathToParts(path, pathParts);\n  return CheckPathToRoot(include, pathParts, isFile);\n}\n*/\n\nvoid CCensorNode::AddItem2(bool include, const UString &path, bool recursive)\n{\n  if (path.IsEmpty())\n    return;\n  bool forFile = true;\n  bool forFolder = true;\n  UString path2 = path;\n  if (IsCharDirLimiter(path[path.Length() - 1]))\n  {\n    path2.Delete(path.Length() - 1);\n    forFile = false;\n  }\n  AddItem(include, path2, recursive, forFile, forFolder);\n}\n\nvoid CCensorNode::ExtendExclude(const CCensorNode &fromNodes)\n{\n  ExcludeItems += fromNodes.ExcludeItems;\n  for (int i = 0; i < fromNodes.SubNodes.Size(); i++)\n  {\n    const CCensorNode &node = fromNodes.SubNodes[i];\n    int subNodeIndex = FindSubNode(node.Name);\n    if (subNodeIndex < 0)\n      subNodeIndex = SubNodes.Add(CCensorNode(node.Name, this));\n    SubNodes[subNodeIndex].ExtendExclude(node);\n  }\n}\n\nint CCensor::FindPrefix(const UString &prefix) const\n{\n  for (int i = 0; i < Pairs.Size(); i++)\n    if (CompareFileNames(Pairs[i].Prefix, prefix) == 0)\n      return i;\n  return -1;\n}\n\nvoid CCensor::AddItem(bool include, const UString &path, bool recursive)\n{\n  UStringVector pathParts;\n  SplitPathToParts(path, pathParts);\n  bool forFile = true;\n  if (pathParts.Back().IsEmpty())\n  {\n    forFile = false;\n    pathParts.DeleteBack();\n  }\n  const UString &front = pathParts.Front();\n  bool isAbs = false;\n  if (front.IsEmpty())\n    isAbs = true;\n  else if (front.Length() == 2 && front[1] == L':')\n    isAbs = true;\n  else\n  {\n    for (int i = 0; i < pathParts.Size(); i++)\n    {\n      const UString &part = pathParts[i];\n      if (part == L\"..\" || part == L\".\")\n      {\n        isAbs = true;\n        break;\n      }\n    }\n  }\n  int numAbsParts = 0;\n  if (isAbs)\n    if (pathParts.Size() > 1)\n      numAbsParts = pathParts.Size() - 1;\n    else\n      numAbsParts = 1;\n  UString prefix;\n  for (int i = 0; i < numAbsParts; i++)\n  {\n    const UString &front = pathParts.Front();\n    if (DoesNameContainWildCard(front))\n      break;\n    prefix += front;\n    prefix += WCHAR_PATH_SEPARATOR;\n    pathParts.Delete(0);\n  }\n  int index = FindPrefix(prefix);\n  if (index < 0)\n    index = Pairs.Add(CPair(prefix));\n\n  CItem item;\n  item.PathParts = pathParts;\n  item.ForDir = true;\n  item.ForFile = forFile;\n  item.Recursive = recursive;\n  Pairs[index].Head.AddItem(include, item);\n}\n\nbool CCensor::CheckPath(const UString &path, bool isFile) const\n{\n  bool finded = false;\n  for (int i = 0; i < Pairs.Size(); i++)\n  {\n    bool include;\n    if (Pairs[i].Head.CheckPath(path, isFile, include))\n    {\n      if (!include)\n        return false;\n      finded = true;\n    }\n  }\n  return finded;\n}\n\nvoid CCensor::ExtendExclude()\n{\n  int i;\n  for (i = 0; i < Pairs.Size(); i++)\n    if (Pairs[i].Prefix.IsEmpty())\n      break;\n  if (i == Pairs.Size())\n    return;\n  int index = i;\n  for (i = 0; i < Pairs.Size(); i++)\n    if (index != i)\n      Pairs[i].Head.ExtendExclude(Pairs[index].Head);\n}\n\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Common/Wildcard.h",
    "content": "// Common/Wildcard.h\n\n#ifndef __COMMON_WILDCARD_H\n#define __COMMON_WILDCARD_H\n\n#include \"MyString.h\"\n\nint CompareFileNames(const UString &s1, const UString &s2);\n\nvoid SplitPathToParts(const UString &path, UStringVector &pathParts);\nvoid SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);\nUString ExtractDirPrefixFromPath(const UString &path);\nUString ExtractFileNameFromPath(const UString &path);\nbool DoesNameContainWildCard(const UString &path);\nbool CompareWildCardWithName(const UString &mask, const UString &name);\n\nnamespace NWildcard {\n\nstruct CItem\n{\n  UStringVector PathParts;\n  bool Recursive;\n  bool ForFile;\n  bool ForDir;\n  bool CheckPath(const UStringVector &pathParts, bool isFile) const;\n};\n\nclass CCensorNode\n{\n  CCensorNode *Parent;\n  bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;\n  void AddItemSimple(bool include, CItem &item);\n  bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;\npublic:\n  CCensorNode(): Parent(0) { };\n  CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };\n  UString Name;\n  CObjectVector<CCensorNode> SubNodes;\n  CObjectVector<CItem> IncludeItems;\n  CObjectVector<CItem> ExcludeItems;\n\n  int FindSubNode(const UString &path) const;\n\n  void AddItem(bool include, CItem &item);\n  void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);\n  void AddItem2(bool include, const UString &path, bool recursive);\n\n  bool NeedCheckSubDirs() const;\n  bool AreThereIncludeItems() const;\n\n  bool CheckPath(const UString &path, bool isFile, bool &include) const;\n  bool CheckPath(const UString &path, bool isFile) const;\n\n  bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;\n  // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const;\n  void ExtendExclude(const CCensorNode &fromNodes);\n};\n\nstruct CPair\n{\n  UString Prefix;\n  CCensorNode Head;\n  CPair(const UString &prefix): Prefix(prefix) { };\n};\n\nclass CCensor\n{\n  int FindPrefix(const UString &prefix) const;\npublic:\n  CObjectVector<CPair> Pairs;\n  bool AllAreRelative() const\n    { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }\n  void AddItem(bool include, const UString &path, bool recursive);\n  bool CheckPath(const UString &path, bool isFile) const;\n  void ExtendExclude();\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/DLL.cpp",
    "content": "// Windows/DLL.cpp\n\n#include \"StdAfx.h\"\n\n#include \"DLL.h\"\n#include \"Defs.h\"\n#ifndef _UNICODE\n#include \"../Common/StringConvert.h\"\n#endif\n\n#ifndef _UNICODE\nextern bool g_IsNT;\n#endif\n\nnamespace NWindows {\nnamespace NDLL {\n\nCLibrary::~CLibrary()\n{\n  Free();\n}\n\nbool CLibrary::Free()\n{\n  if (_module == 0)\n    return true;\n  // MessageBox(0, TEXT(\"\"), TEXT(\"Free\"), 0);\n  // Sleep(5000);\n  if (!::FreeLibrary(_module))\n    return false;\n  _module = 0;\n  return true;\n}\n\nbool CLibrary::LoadOperations(HMODULE newModule)\n{\n  if (newModule == NULL)\n    return false;\n  if (!Free())\n    return false;\n  _module = newModule;\n  return true;\n}\n\nbool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags)\n{\n  // MessageBox(0, fileName, TEXT(\"LoadEx\"), 0);\n  return LoadOperations(::LoadLibraryEx(fileName, NULL, flags));\n}\n\nbool CLibrary::Load(LPCTSTR fileName)\n{\n  // MessageBox(0, fileName, TEXT(\"Load\"), 0);\n  // Sleep(5000);\n  // OutputDebugString(fileName);\n  // OutputDebugString(TEXT(\"\\n\"));\n  return LoadOperations(::LoadLibrary(fileName));\n}\n\n#ifndef _UNICODE\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\nCSysString GetSysPath(LPCWSTR sysPath)\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\n\nbool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags)\n{\n  if (g_IsNT)\n    return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));\n  return LoadEx(GetSysPath(fileName), flags);\n}\nbool CLibrary::Load(LPCWSTR fileName)\n{\n  if (g_IsNT)\n    return LoadOperations(::LoadLibraryW(fileName));\n  return Load(GetSysPath(fileName));\n}\n#endif\n\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result)\n{\n  result.Empty();\n  TCHAR fullPath[MAX_PATH + 2];\n  DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1);\n  if (size <= MAX_PATH && size != 0)\n  {\n    result = fullPath;\n    return true;\n  }\n  return false;\n}\n\n#ifndef _UNICODE\nbool MyGetModuleFileName(HMODULE hModule, UString &result)\n{\n  result.Empty();\n  if (g_IsNT)\n  {\n    wchar_t fullPath[MAX_PATH + 2];\n    DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);\n    if (size <= MAX_PATH && size != 0)\n    {\n      result = fullPath;\n      return true;\n    }\n    return false;\n  }\n  CSysString resultSys;\n  if (!MyGetModuleFileName(hModule, resultSys))\n    return false;\n  result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());\n  return true;\n}\n#endif\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/DLL.h",
    "content": "// Windows/DLL.h\n\n#ifndef __WINDOWS_DLL_H\n#define __WINDOWS_DLL_H\n\n#include \"../Common/MyString.h\"\n\nnamespace NWindows {\nnamespace NDLL {\n\nclass CLibrary\n{\n  bool LoadOperations(HMODULE newModule);\nprotected:\n  HMODULE _module;\npublic:\n  operator HMODULE() const { return _module; }\n  HMODULE* operator&() { return &_module; }\n\n  CLibrary():_module(NULL) {};\n  ~CLibrary();\n  void Attach(HMODULE m)\n  {\n    Free();\n    _module = m;\n  }\n  HMODULE Detach()\n  {\n    HMODULE m = _module;\n    _module = NULL;\n    return m;\n  }\n\n  // operator HMODULE() const { return _module; };\n  bool IsLoaded() const { return (_module != NULL); };\n  bool Free();\n  bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\n  bool Load(LPCTSTR fileName);\n  #ifndef _UNICODE\n  bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);\n  bool Load(LPCWSTR fileName);\n  #endif\n  FARPROC GetProcAddress(LPCSTR procName) const\n    { return ::GetProcAddress(_module, procName); }\n};\n\nbool MyGetModuleFileName(HMODULE hModule, CSysString &result);\n#ifndef _UNICODE\nbool MyGetModuleFileName(HMODULE hModule, UString &result);\n#endif\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/Defs.h",
    "content": "// Windows/Defs.h\n\n#ifndef __WINDOWS_DEFS_H\n#define __WINDOWS_DEFS_H\n\ninline bool BOOLToBool(BOOL value)\n  { return (value != FALSE); }\n\n#ifdef _WIN32\ninline bool LRESULTToBool(LRESULT value)\n  { return (value != FALSE); }\n#endif\n\ninline BOOL BoolToBOOL(bool value)\n  { return (value ? TRUE: FALSE); }\n\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\n\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\n  { return (value != VARIANT_FALSE); }\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/Error.cpp",
    "content": "// Windows/Error.h\n\n#include \"StdAfx.h\"\n\n#include \"Windows/Error.h\"\n#ifndef _UNICODE\n#include \"Common/StringConvert.h\"\n#endif\n\n#ifndef _UNICODE\nextern bool g_IsNT;\n#endif\n\nnamespace NWindows {\nnamespace NError {\n\nbool MyFormatMessage(DWORD messageID, CSysString &message)\n{\n  LPVOID msgBuf;\n  if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |\n      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\n      NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)\n    return false;\n  message = (LPCTSTR)msgBuf;\n  ::LocalFree(msgBuf);\n  return true;\n}\n\n#ifndef _UNICODE\nbool MyFormatMessage(DWORD messageID, UString &message)\n{\n  if (g_IsNT)\n  {\n    LPVOID msgBuf;\n    if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |\n        FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,\n        NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)\n      return false;\n    message = (LPCWSTR)msgBuf;\n    ::LocalFree(msgBuf);\n    return true;\n  }\n  CSysString messageSys;\n  bool result = MyFormatMessage(messageID, messageSys);\n  message = GetUnicodeString(messageSys);\n  return result;\n}\n#endif\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/Error.h",
    "content": "// Windows/Error.h\n\n#ifndef __WINDOWS_ERROR_H\n#define __WINDOWS_ERROR_H\n\n#include \"Common/MyString.h\"\n\nnamespace NWindows {\nnamespace NError {\n\nbool MyFormatMessage(DWORD messageID, CSysString &message);\ninline CSysString MyFormatMessage(DWORD messageID)\n{\n  CSysString message;\n  MyFormatMessage(messageID, message);\n  return message;\n}\n#ifdef _UNICODE\ninline UString MyFormatMessageW(DWORD messageID)\n  { return MyFormatMessage(messageID); }\n#else\nbool MyFormatMessage(DWORD messageID, UString &message);\ninline UString MyFormatMessageW(DWORD messageID)\n{\n  UString message;\n  MyFormatMessage(messageID, message);\n  return message;\n}\n#endif\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileDir.cpp",
    "content": "// Windows/FileDir.cpp\n\n#include \"StdAfx.h\"\n\n#include \"FileDir.h\"\n#include \"FileName.h\"\n#include \"FileFind.h\"\n#include \"Defs.h\"\n#ifndef _UNICODE\n#include \"../Common/StringConvert.h\"\n#endif\n\n#ifndef _UNICODE\nextern bool g_IsNT;\n#endif\n\nnamespace NWindows {\nnamespace NFile {\n\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\n#define WIN_LONG_PATH2\n#endif\n\n// SetCurrentDirectory doesn't support \\\\?\\ prefix\n\n#ifdef WIN_LONG_PATH\nbool GetLongPathBase(LPCWSTR fileName, UString &res);\nbool GetLongPath(LPCWSTR fileName, UString &res);\n#endif\n\nnamespace NDirectory {\n\n#ifndef _UNICODE\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\nstatic UString GetUnicodePath(const CSysString &sysPath)\n  { return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }\nstatic CSysString GetSysPath(LPCWSTR sysPath)\n  { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }\n#endif\n\nbool MyGetWindowsDirectory(CSysString &path)\n{\n  UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\n  path.ReleaseBuffer();\n  return (needLength > 0 && needLength <= MAX_PATH);\n}\n\nbool MyGetSystemDirectory(CSysString &path)\n{\n  UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\n  path.ReleaseBuffer();\n  return (needLength > 0 && needLength <= MAX_PATH);\n}\n\n#ifndef _UNICODE\nbool MyGetWindowsDirectory(UString &path)\n{\n  if (g_IsNT)\n  {\n    UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\n    path.ReleaseBuffer();\n    return (needLength > 0 && needLength <= MAX_PATH);\n  }\n  CSysString sysPath;\n  if (!MyGetWindowsDirectory(sysPath))\n    return false;\n  path = GetUnicodePath(sysPath);\n  return true;\n}\n\nbool MyGetSystemDirectory(UString &path)\n{\n  if (g_IsNT)\n  {\n    UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\n    path.ReleaseBuffer();\n    return (needLength > 0 && needLength <= MAX_PATH);\n  }\n  CSysString sysPath;\n  if (!MyGetSystemDirectory(sysPath))\n    return false;\n  path = GetUnicodePath(sysPath);\n  return true;\n}\n#endif\n\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\n{\n  #ifndef _UNICODE\n  if (!g_IsNT)\n  {\n    ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\n    return false;\n  }\n  #endif\n  HANDLE hDir = ::CreateFileW(fileName, GENERIC_WRITE,\n      FILE_SHARE_READ | FILE_SHARE_WRITE,\n      NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\n  #ifdef WIN_LONG_PATH\n  if (hDir == INVALID_HANDLE_VALUE)\n  {\n    UString longPath;\n    if (GetLongPath(fileName, longPath))\n      hDir = ::CreateFileW(longPath, GENERIC_WRITE,\n        FILE_SHARE_READ | FILE_SHARE_WRITE,\n        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);\n  }\n  #endif\n\n  bool res = false;\n  if (hDir != INVALID_HANDLE_VALUE)\n  {\n    res = BOOLToBool(::SetFileTime(hDir, cTime, aTime, mTime));\n    ::CloseHandle(hDir);\n  }\n  return res;\n}\n\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)\n{\n  if (::SetFileAttributes(fileName, fileAttributes))\n    return true;\n  #ifdef WIN_LONG_PATH2\n  UString longPath;\n  if (GetLongPath(fileName, longPath))\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\n  #endif\n  return false;\n}\n\nbool MyRemoveDirectory(LPCTSTR pathName)\n{\n  if (::RemoveDirectory(pathName))\n    return true;\n  #ifdef WIN_LONG_PATH2\n  UString longPath;\n  if (GetLongPath(pathName, longPath))\n    return BOOLToBool(::RemoveDirectoryW(longPath));\n  #endif\n  return false;\n}\n\n#ifdef WIN_LONG_PATH\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2)\n{\n  if (!GetLongPathBase(s1, d1) || !GetLongPathBase(s2, d2))\n    return false;\n  if (d1.IsEmpty() && d2.IsEmpty()) return false;\n  if (d1.IsEmpty()) d1 = s1;\n  if (d2.IsEmpty()) d2 = s2;\n  return true;\n}\n#endif\n\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName)\n{\n  if (::MoveFile(existFileName, newFileName))\n    return true;\n  #ifdef WIN_LONG_PATH2\n  UString d1, d2;\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\n    return BOOLToBool(::MoveFileW(d1, d2));\n  #endif\n  return false;\n}\n\n#ifndef _UNICODE\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)\n{\n  if (!g_IsNT)\n    return MySetFileAttributes(GetSysPath(fileName), fileAttributes);\n  if (::SetFileAttributesW(fileName, fileAttributes))\n    return true;\n  #ifdef WIN_LONG_PATH\n  UString longPath;\n  if (GetLongPath(fileName, longPath))\n    return BOOLToBool(::SetFileAttributesW(longPath, fileAttributes));\n  #endif\n  return false;\n}\n\n\nbool MyRemoveDirectory(LPCWSTR pathName)\n{\n  if (!g_IsNT)\n    return MyRemoveDirectory(GetSysPath(pathName));\n  if (::RemoveDirectoryW(pathName))\n    return true;\n  #ifdef WIN_LONG_PATH\n  UString longPath;\n  if (GetLongPath(pathName, longPath))\n    return BOOLToBool(::RemoveDirectoryW(longPath));\n  #endif\n  return false;\n}\n\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)\n{\n  if (!g_IsNT)\n    return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));\n  if (::MoveFileW(existFileName, newFileName))\n    return true;\n  #ifdef WIN_LONG_PATH\n  UString d1, d2;\n  if (GetLongPaths(existFileName, newFileName, d1, d2))\n    return BOOLToBool(::MoveFileW(d1, d2));\n  #endif\n  return false;\n}\n#endif\n\nbool MyCreateDirectory(LPCTSTR pathName)\n{\n  if (::CreateDirectory(pathName, NULL))\n    return true;\n  #ifdef WIN_LONG_PATH2\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\n  {\n    UString longPath;\n    if (GetLongPath(pathName, longPath))\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\n  }\n  #endif\n  return false;\n}\n\n#ifndef _UNICODE\nbool MyCreateDirectory(LPCWSTR pathName)\n{\n  if (!g_IsNT)\n    return MyCreateDirectory(GetSysPath(pathName));\n  if (::CreateDirectoryW(pathName, NULL))\n    return true;\n  #ifdef WIN_LONG_PATH\n  if (::GetLastError() != ERROR_ALREADY_EXISTS)\n  {\n    UString longPath;\n    if (GetLongPath(pathName, longPath))\n      return BOOLToBool(::CreateDirectoryW(longPath, NULL));\n  }\n  #endif\n  return false;\n}\n#endif\n\n/*\nbool CreateComplexDirectory(LPCTSTR pathName)\n{\n  NName::CParsedPath path;\n  path.ParsePath(pathName);\n  CSysString fullPath = path.Prefix;\n  DWORD errorCode = ERROR_SUCCESS;\n  for (int i = 0; i < path.PathParts.Size(); i++)\n  {\n    const CSysString &string = path.PathParts[i];\n    if (string.IsEmpty())\n    {\n      if (i != path.PathParts.Size() - 1)\n        return false;\n      return true;\n    }\n    fullPath += path.PathParts[i];\n    if (!MyCreateDirectory(fullPath))\n    {\n      DWORD errorCode = GetLastError();\n      if (errorCode != ERROR_ALREADY_EXISTS)\n        return false;\n    }\n    fullPath += NName::kDirDelimiter;\n  }\n  return true;\n}\n*/\n\nbool CreateComplexDirectory(LPCTSTR _aPathName)\n{\n  CSysString pathName = _aPathName;\n  int pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\n  if (pos > 0 && pos == pathName.Length() - 1)\n  {\n    if (pathName.Length() == 3 && pathName[1] == ':')\n      return true; // Disk folder;\n    pathName.Delete(pos);\n  }\n  CSysString pathName2 = pathName;\n  pos = pathName.Length();\n  for (;;)\n  {\n    if (MyCreateDirectory(pathName))\n      break;\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\n    {\n      NFind::CFileInfo fileInfo;\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\n        return true;\n      if (!fileInfo.IsDir())\n        return false;\n      break;\n    }\n    pos = pathName.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));\n    if (pos < 0 || pos == 0)\n      return false;\n    if (pathName[pos - 1] == ':')\n      return false;\n    pathName = pathName.Left(pos);\n  }\n  pathName = pathName2;\n  while (pos < pathName.Length())\n  {\n    pos = pathName.Find(TEXT(CHAR_PATH_SEPARATOR), pos + 1);\n    if (pos < 0)\n      pos = pathName.Length();\n    if (!MyCreateDirectory(pathName.Left(pos)))\n      return false;\n  }\n  return true;\n}\n\n#ifndef _UNICODE\n\nbool CreateComplexDirectory(LPCWSTR _aPathName)\n{\n  UString pathName = _aPathName;\n  int pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\n  if (pos > 0 && pos == pathName.Length() - 1)\n  {\n    if (pathName.Length() == 3 && pathName[1] == L':')\n      return true; // Disk folder;\n    pathName.Delete(pos);\n  }\n  UString pathName2 = pathName;\n  pos = pathName.Length();\n  for (;;)\n  {\n    if (MyCreateDirectory(pathName))\n      break;\n    if (::GetLastError() == ERROR_ALREADY_EXISTS)\n    {\n      NFind::CFileInfoW fileInfo;\n      if (!NFind::FindFile(pathName, fileInfo)) // For network folders\n        return true;\n      if (!fileInfo.IsDir())\n        return false;\n      break;\n    }\n    pos = pathName.ReverseFind(WCHAR_PATH_SEPARATOR);\n    if (pos < 0 || pos == 0)\n      return false;\n    if (pathName[pos - 1] == L':')\n      return false;\n    pathName = pathName.Left(pos);\n  }\n  pathName = pathName2;\n  while (pos < pathName.Length())\n  {\n    pos = pathName.Find(WCHAR_PATH_SEPARATOR, pos + 1);\n    if (pos < 0)\n      pos = pathName.Length();\n    if (!MyCreateDirectory(pathName.Left(pos)))\n      return false;\n  }\n  return true;\n}\n\n#endif\n\nbool DeleteFileAlways(LPCTSTR name)\n{\n  if (!MySetFileAttributes(name, 0))\n    return false;\n  if (::DeleteFile(name))\n    return true;\n  #ifdef WIN_LONG_PATH2\n  UString longPath;\n  if (GetLongPath(name, longPath))\n    return BOOLToBool(::DeleteFileW(longPath));\n  #endif\n  return false;\n}\n\n#ifndef _UNICODE\nbool DeleteFileAlways(LPCWSTR name)\n{\n  if (!g_IsNT)\n    return DeleteFileAlways(GetSysPath(name));\n  if (!MySetFileAttributes(name, 0))\n    return false;\n  if (::DeleteFileW(name))\n    return true;\n  #ifdef WIN_LONG_PATH\n  UString longPath;\n  if (GetLongPath(name, longPath))\n    return BOOLToBool(::DeleteFileW(longPath));\n  #endif\n  return false;\n}\n#endif\n\nstatic bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)\n{\n  if (fileInfo.IsDir())\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\n}\n\nbool RemoveDirectoryWithSubItems(const CSysString &path)\n{\n  NFind::CFileInfo fileInfo;\n  CSysString pathPrefix = path + NName::kDirDelimiter;\n  {\n    NFind::CEnumerator enumerator(pathPrefix + TCHAR(NName::kAnyStringWildcard));\n    while (enumerator.Next(fileInfo))\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\n        return false;\n  }\n  if (!MySetFileAttributes(path, 0))\n    return false;\n  return MyRemoveDirectory(path);\n}\n\n#ifndef _UNICODE\nstatic bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)\n{\n  if (fileInfo.IsDir())\n    return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);\n  return DeleteFileAlways(pathPrefix + fileInfo.Name);\n}\nbool RemoveDirectoryWithSubItems(const UString &path)\n{\n  NFind::CFileInfoW fileInfo;\n  UString pathPrefix = path + UString(NName::kDirDelimiter);\n  {\n    NFind::CEnumeratorW enumerator(pathPrefix + UString(NName::kAnyStringWildcard));\n    while (enumerator.Next(fileInfo))\n      if (!RemoveDirectorySubItems2(pathPrefix, fileInfo))\n        return false;\n  }\n  if (!MySetFileAttributes(path, 0))\n    return false;\n  return MyRemoveDirectory(path);\n}\n#endif\n\n#ifndef _WIN32_WCE\n\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)\n{\n  DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);\n  shortPath.ReleaseBuffer();\n  return (needLength > 0 && needLength < MAX_PATH);\n}\n\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)\n{\n  resultPath.Empty();\n  LPTSTR fileNamePointer = 0;\n  LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);\n  DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\n  resultPath.ReleaseBuffer();\n  if (needLength == 0)\n    return false;\n  if (needLength >= MAX_PATH)\n  {\n    #ifdef WIN_LONG_PATH2\n    needLength++;\n    buffer = resultPath.GetBuffer(needLength + 1);\n    DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\n    resultPath.ReleaseBuffer();\n    if (needLength2 == 0 || needLength2 > needLength)\n    #endif\n      return false;\n  }\n  if (fileNamePointer == 0)\n    fileNamePartStartIndex = lstrlen(fileName);\n  else\n    fileNamePartStartIndex = (int)(fileNamePointer - buffer);\n  return true;\n}\n\n#ifndef _UNICODE\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)\n{\n  resultPath.Empty();\n  if (g_IsNT)\n  {\n    LPWSTR fileNamePointer = 0;\n    LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);\n    DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);\n    resultPath.ReleaseBuffer();\n    if (needLength == 0)\n      return false;\n    if (needLength >= MAX_PATH)\n    {\n      #ifdef WIN_LONG_PATH\n      needLength++;\n      buffer = resultPath.GetBuffer(needLength + 1);\n      DWORD needLength2 = ::GetFullPathNameW(fileName, needLength, buffer, &fileNamePointer);\n      resultPath.ReleaseBuffer();\n      if (needLength2 == 0 || needLength2 > needLength)\n      #endif\n        return false;\n    }\n    if (fileNamePointer == 0)\n      fileNamePartStartIndex = MyStringLen(fileName);\n    else\n      fileNamePartStartIndex = (int)(fileNamePointer - buffer);\n  }\n  else\n  {\n    CSysString sysPath;\n    if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))\n      return false;\n    UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));\n    UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));\n    fileNamePartStartIndex = resultPath1.Length();\n    resultPath = resultPath1 + resultPath2;\n  }\n  return true;\n}\n#endif\n\n\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &path)\n{\n  int index;\n  return MyGetFullPathName(fileName, path, index);\n}\n\n#ifndef _UNICODE\nbool MyGetFullPathName(LPCWSTR fileName, UString &path)\n{\n  int index;\n  return MyGetFullPathName(fileName, path, index);\n}\n#endif\n\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName)\n{\n  int index;\n  if (!MyGetFullPathName(fileName, resultName, index))\n    return false;\n  resultName = resultName.Mid(index);\n  return true;\n}\n\n#ifndef _UNICODE\nbool GetOnlyName(LPCWSTR fileName, UString &resultName)\n{\n  int index;\n  if (!MyGetFullPathName(fileName, resultName, index))\n    return false;\n  resultName = resultName.Mid(index);\n  return true;\n}\n#endif\n\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName)\n{\n  int index;\n  if (!MyGetFullPathName(fileName, resultName, index))\n    return false;\n  resultName = resultName.Left(index);\n  return true;\n}\n\n#ifndef _UNICODE\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)\n{\n  int index;\n  if (!MyGetFullPathName(fileName, resultName, index))\n    return false;\n  resultName = resultName.Left(index);\n  return true;\n}\n#endif\n\nbool MyGetCurrentDirectory(CSysString &path)\n{\n  DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\n  path.ReleaseBuffer();\n  return (needLength > 0 && needLength <= MAX_PATH);\n}\n\n#ifndef _UNICODE\nbool MySetCurrentDirectory(LPCWSTR path)\n{\n  if (g_IsNT)\n    return BOOLToBool(::SetCurrentDirectoryW(path));\n  return MySetCurrentDirectory(GetSysPath(path));\n}\nbool MyGetCurrentDirectory(UString &path)\n{\n  if (g_IsNT)\n  {\n    DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\n    path.ReleaseBuffer();\n    return (needLength > 0 && needLength <= MAX_PATH);\n  }\n  CSysString sysPath;\n  if (!MyGetCurrentDirectory(sysPath))\n    return false;\n  path = GetUnicodePath(sysPath);\n  return true;\n}\n#endif\n#endif\n\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\n  CSysString &resultPath, UINT32 &filePart)\n{\n  LPTSTR filePartPointer;\n  DWORD value = ::SearchPath(path, fileName, extension,\n    MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\n  filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);\n  resultPath.ReleaseBuffer();\n  return (value > 0 && value <= MAX_PATH);\n}\n\n#ifndef _UNICODE\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\n  UString &resultPath, UINT32 &filePart)\n{\n  if (g_IsNT)\n  {\n    LPWSTR filePartPointer = 0;\n    DWORD value = ::SearchPathW(path, fileName, extension,\n        MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);\n    filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);\n    resultPath.ReleaseBuffer();\n    return (value > 0 && value <= MAX_PATH);\n  }\n  \n  CSysString sysPath;\n  if (!MySearchPath(\n      path != 0 ? (LPCTSTR)GetSysPath(path): 0,\n      fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,\n      extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,\n      sysPath, filePart))\n    return false;\n  UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));\n  UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));\n  filePart = resultPath1.Length();\n  resultPath = resultPath1 + resultPath2;\n  return true;\n}\n#endif\n\nbool MyGetTempPath(CSysString &path)\n{\n  DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\n  path.ReleaseBuffer();\n  return (needLength > 0 && needLength <= MAX_PATH);\n}\n\n#ifndef _UNICODE\nbool MyGetTempPath(UString &path)\n{\n  path.Empty();\n  if (g_IsNT)\n  {\n    DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));\n    path.ReleaseBuffer();\n    return (needLength > 0 && needLength <= MAX_PATH);\n  }\n  CSysString sysPath;\n  if (!MyGetTempPath(sysPath))\n    return false;\n  path = GetUnicodePath(sysPath);\n  return true;\n}\n#endif\n\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)\n{\n  UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));\n  path.ReleaseBuffer();\n  return number;\n}\n\n#ifndef _UNICODE\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)\n{\n  if (g_IsNT)\n  {\n    UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));\n    path.ReleaseBuffer();\n    return number;\n  }\n  CSysString sysPath;\n  UINT number = MyGetTempFileName(\n      dirPath ? (LPCTSTR)GetSysPath(dirPath): 0,\n      prefix ? (LPCTSTR)GetSysPath(prefix): 0,\n      sysPath);\n  path = GetUnicodePath(sysPath);\n  return number;\n}\n#endif\n\nUINT CTempFile::Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath)\n{\n  Remove();\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\n  if (number != 0)\n  {\n    _fileName = resultPath;\n    _mustBeDeleted = true;\n  }\n  return number;\n}\n\nbool CTempFile::Create(LPCTSTR prefix, CSysString &resultPath)\n{\n  CSysString tempPath;\n  if (!MyGetTempPath(tempPath))\n    return false;\n  if (Create(tempPath, prefix, resultPath) != 0)\n    return true;\n  if (!MyGetWindowsDirectory(tempPath))\n    return false;\n  return (Create(tempPath, prefix, resultPath) != 0);\n}\n\nbool CTempFile::Remove()\n{\n  if (!_mustBeDeleted)\n    return true;\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\n  return !_mustBeDeleted;\n}\n\n#ifndef _UNICODE\n\nUINT CTempFileW::Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath)\n{\n  Remove();\n  UINT number = MyGetTempFileName(dirPath, prefix, resultPath);\n  if (number != 0)\n  {\n    _fileName = resultPath;\n    _mustBeDeleted = true;\n  }\n  return number;\n}\n\nbool CTempFileW::Create(LPCWSTR prefix, UString &resultPath)\n{\n  UString tempPath;\n  if (!MyGetTempPath(tempPath))\n    return false;\n  if (Create(tempPath, prefix, resultPath) != 0)\n    return true;\n  if (!MyGetWindowsDirectory(tempPath))\n    return false;\n  return (Create(tempPath, prefix, resultPath) != 0);\n}\n\nbool CTempFileW::Remove()\n{\n  if (!_mustBeDeleted)\n    return true;\n  _mustBeDeleted = !DeleteFileAlways(_fileName);\n  return !_mustBeDeleted;\n}\n\n#endif\n\nbool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)\n{\n  /*\n  CSysString prefix = tempPath + prefixChars;\n  CRandom random;\n  random.Init();\n  */\n  for (;;)\n  {\n    CTempFile tempFile;\n    if (!tempFile.Create(prefix, dirName))\n      return false;\n    if (!::DeleteFile(dirName))\n      return false;\n    /*\n    UINT32 randomNumber = random.Generate();\n    TCHAR randomNumberString[32];\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\n    dirName = prefix + randomNumberString;\n    */\n    if (NFind::DoesFileExist(dirName))\n      continue;\n    if (MyCreateDirectory(dirName))\n      return true;\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\n      return false;\n  }\n}\n\nbool CTempDirectory::Create(LPCTSTR prefix)\n{\n  Remove();\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\n}\n\n#ifndef _UNICODE\n\nbool CreateTempDirectory(LPCWSTR prefix, UString &dirName)\n{\n  /*\n  CSysString prefix = tempPath + prefixChars;\n  CRandom random;\n  random.Init();\n  */\n  for (;;)\n  {\n    CTempFileW tempFile;\n    if (!tempFile.Create(prefix, dirName))\n      return false;\n    if (!DeleteFileAlways(dirName))\n      return false;\n    /*\n    UINT32 randomNumber = random.Generate();\n    TCHAR randomNumberString[32];\n    _stprintf(randomNumberString, _T(\"%04X\"), randomNumber);\n    dirName = prefix + randomNumberString;\n    */\n    if (NFind::DoesFileExist(dirName))\n      continue;\n    if (MyCreateDirectory(dirName))\n      return true;\n    if (::GetLastError() != ERROR_ALREADY_EXISTS)\n      return false;\n  }\n}\n\nbool CTempDirectoryW::Create(LPCWSTR prefix)\n{\n  Remove();\n  return (_mustBeDeleted = CreateTempDirectory(prefix, _tempDir));\n}\n\n#endif\n\n}}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileDir.h",
    "content": "// Windows/FileDir.h\n\n#ifndef __WINDOWS_FILEDIR_H\n#define __WINDOWS_FILEDIR_H\n\n#include \"../Common/MyString.h\"\n#include \"Defs.h\"\n\nnamespace NWindows {\nnamespace NFile {\nnamespace NDirectory {\n\n#ifdef WIN_LONG_PATH\nbool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);\n#endif\n\nbool MyGetWindowsDirectory(CSysString &path);\nbool MyGetSystemDirectory(CSysString &path);\n#ifndef _UNICODE\nbool MyGetWindowsDirectory(UString &path);\nbool MyGetSystemDirectory(UString &path);\n#endif\n\nbool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\n\nbool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);\nbool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);\nbool MyRemoveDirectory(LPCTSTR pathName);\nbool MyCreateDirectory(LPCTSTR pathName);\nbool CreateComplexDirectory(LPCTSTR pathName);\nbool DeleteFileAlways(LPCTSTR name);\nbool RemoveDirectoryWithSubItems(const CSysString &path);\n\n#ifndef _UNICODE\nbool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);\nbool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);\nbool MyRemoveDirectory(LPCWSTR pathName);\nbool MyCreateDirectory(LPCWSTR pathName);\nbool CreateComplexDirectory(LPCWSTR pathName);\nbool DeleteFileAlways(LPCWSTR name);\nbool RemoveDirectoryWithSubItems(const UString &path);\n#endif\n\n#ifndef _WIN32_WCE\nbool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);\n\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,\n    int &fileNamePartStartIndex);\nbool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);\nbool GetOnlyName(LPCTSTR fileName, CSysString &resultName);\nbool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);\n#ifndef _UNICODE\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,\n    int &fileNamePartStartIndex);\nbool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);\nbool GetOnlyName(LPCWSTR fileName, UString &resultName);\nbool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);\n#endif\n\ninline bool MySetCurrentDirectory(LPCTSTR path)\n  { return BOOLToBool(::SetCurrentDirectory(path)); }\nbool MyGetCurrentDirectory(CSysString &resultPath);\n#ifndef _UNICODE\nbool MySetCurrentDirectory(LPCWSTR path);\nbool MyGetCurrentDirectory(UString &resultPath);\n#endif\n#endif\n\nbool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\n  CSysString &resultPath, UINT32 &filePart);\n#ifndef _UNICODE\nbool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\n  UString &resultPath, UINT32 &filePart);\n#endif\n\ninline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,\n  CSysString &resultPath)\n{\n  UINT32 value;\n  return MySearchPath(path, fileName, extension, resultPath, value);\n}\n\n#ifndef _UNICODE\ninline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,\n  UString &resultPath)\n{\n  UINT32 value;\n  return MySearchPath(path, fileName, extension, resultPath, value);\n}\n#endif\n\nbool MyGetTempPath(CSysString &resultPath);\n#ifndef _UNICODE\nbool MyGetTempPath(UString &resultPath);\n#endif\n\nUINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\n#ifndef _UNICODE\nUINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\n#endif\n\nclass CTempFile\n{\n  bool _mustBeDeleted;\n  CSysString _fileName;\npublic:\n  CTempFile(): _mustBeDeleted(false) {}\n  ~CTempFile() { Remove(); }\n  void DisableDeleting() { _mustBeDeleted = false; }\n  UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);\n  bool Create(LPCTSTR prefix, CSysString &resultPath);\n  bool Remove();\n};\n\n#ifdef _UNICODE\ntypedef CTempFile CTempFileW;\n#else\nclass CTempFileW\n{\n  bool _mustBeDeleted;\n  UString _fileName;\npublic:\n  CTempFileW(): _mustBeDeleted(false) {}\n  ~CTempFileW() { Remove(); }\n  void DisableDeleting() { _mustBeDeleted = false; }\n  UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);\n  bool Create(LPCWSTR prefix, UString &resultPath);\n  bool Remove();\n};\n#endif\n\nbool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);\n\nclass CTempDirectory\n{\n  bool _mustBeDeleted;\n  CSysString _tempDir;\npublic:\n  const CSysString &GetPath() const { return _tempDir; }\n  CTempDirectory(): _mustBeDeleted(false) {}\n  ~CTempDirectory() { Remove();  }\n  bool Create(LPCTSTR prefix) ;\n  bool Remove()\n  {\n    if (!_mustBeDeleted)\n      return true;\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\n    return (!_mustBeDeleted);\n  }\n  void DisableDeleting() { _mustBeDeleted = false; }\n};\n\n#ifdef _UNICODE\ntypedef CTempDirectory CTempDirectoryW;\n#else\nclass CTempDirectoryW\n{\n  bool _mustBeDeleted;\n  UString _tempDir;\npublic:\n  const UString &GetPath() const { return _tempDir; }\n  CTempDirectoryW(): _mustBeDeleted(false) {}\n  ~CTempDirectoryW() { Remove();  }\n  bool Create(LPCWSTR prefix) ;\n  bool Remove()\n  {\n    if (!_mustBeDeleted)\n      return true;\n    _mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);\n    return (!_mustBeDeleted);\n  }\n  void DisableDeleting() { _mustBeDeleted = false; }\n};\n#endif\n\n}}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileFind.cpp",
    "content": "// Windows/FileFind.cpp\n\n#include \"StdAfx.h\"\n\n#include \"FileFind.h\"\n#ifndef _UNICODE\n#include \"../Common/StringConvert.h\"\n#endif\n\n#ifndef _UNICODE\nextern bool g_IsNT;\n#endif\n\nnamespace NWindows {\nnamespace NFile {\n\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\n#define WIN_LONG_PATH2\n#endif\n\nbool GetLongPath(LPCWSTR fileName, UString &res);\n\nnamespace NFind {\n\nstatic const TCHAR kDot = TEXT('.');\n\nbool CFileInfo::IsDots() const\n{\n  if (!IsDir() || Name.IsEmpty())\n    return false;\n  if (Name[0] != kDot)\n    return false;\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\n}\n\n#ifndef _UNICODE\nbool CFileInfoW::IsDots() const\n{\n  if (!IsDir() || Name.IsEmpty())\n    return false;\n  if (Name[0] != kDot)\n    return false;\n  return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);\n}\n#endif\n\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)\n{\n  fi.Attrib = fd.dwFileAttributes;\n  fi.CTime = fd.ftCreationTime;\n  fi.ATime = fd.ftLastAccessTime;\n  fi.MTime = fd.ftLastWriteTime;\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\n  fi.Name = fd.cFileName;\n  #ifndef _WIN32_WCE\n  fi.ReparseTag = fd.dwReserved0;\n  #else\n  fi.ObjectID = fd.dwOID;\n  #endif\n}\n\n#ifndef _UNICODE\n\nstatic inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }\n\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfoW &fi)\n{\n  fi.Attrib = fd.dwFileAttributes;\n  fi.CTime = fd.ftCreationTime;\n  fi.ATime = fd.ftLastAccessTime;\n  fi.MTime = fd.ftLastWriteTime;\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\n  fi.Name = fd.cFileName;\n  #ifndef _WIN32_WCE\n  fi.ReparseTag = fd.dwReserved0;\n  #else\n  fi.ObjectID = fd.dwOID;\n  #endif\n}\n\nstatic void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi)\n{\n  fi.Attrib = fd.dwFileAttributes;\n  fi.CTime = fd.ftCreationTime;\n  fi.ATime = fd.ftLastAccessTime;\n  fi.MTime = fd.ftLastWriteTime;\n  fi.Size  = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;\n  fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage());\n  #ifndef _WIN32_WCE\n  fi.ReparseTag = fd.dwReserved0;\n  #else\n  fi.ObjectID = fd.dwOID;\n  #endif\n}\n#endif\n  \n////////////////////////////////\n// CFindFile\n\nbool CFindFile::Close()\n{\n  if (_handle == INVALID_HANDLE_VALUE)\n    return true;\n  if (!::FindClose(_handle))\n    return false;\n  _handle = INVALID_HANDLE_VALUE;\n  return true;\n}\n\n          \nbool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)\n{\n  if (!Close())\n    return false;\n  WIN32_FIND_DATA fd;\n  _handle = ::FindFirstFile(wildcard, &fd);\n  #ifdef WIN_LONG_PATH2\n  if (_handle == INVALID_HANDLE_VALUE)\n  {\n    UString longPath;\n    if (GetLongPath(wildcard, longPath))\n      _handle = ::FindFirstFileW(longPath, &fd);\n  }\n  #endif\n  if (_handle == INVALID_HANDLE_VALUE)\n    return false;\n  ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\n  return true;\n}\n\n#ifndef _UNICODE\nbool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)\n{\n  if (!Close())\n    return false;\n  if (g_IsNT)\n  {\n    WIN32_FIND_DATAW fd;\n    _handle = ::FindFirstFileW(wildcard, &fd);\n    #ifdef WIN_LONG_PATH\n    if (_handle == INVALID_HANDLE_VALUE)\n    {\n      UString longPath;\n      if (GetLongPath(wildcard, longPath))\n        _handle = ::FindFirstFileW(longPath, &fd);\n    }\n    #endif\n    if (_handle != INVALID_HANDLE_VALUE)\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\n  }\n  else\n  {\n    WIN32_FIND_DATAA fd;\n    _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard,\n        GetCurrentCodePage()), &fd);\n    if (_handle != INVALID_HANDLE_VALUE)\n      ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\n  }\n  return (_handle != INVALID_HANDLE_VALUE);\n}\n#endif\n\nbool CFindFile::FindNext(CFileInfo &fileInfo)\n{\n  WIN32_FIND_DATA fd;\n  bool result = BOOLToBool(::FindNextFile(_handle, &fd));\n  if (result)\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\n  return result;\n}\n\n#ifndef _UNICODE\nbool CFindFile::FindNext(CFileInfoW &fileInfo)\n{\n  if (g_IsNT)\n  {\n    WIN32_FIND_DATAW fd;\n    if (!::FindNextFileW(_handle, &fd))\n      return false;\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\n  }\n  else\n  {\n    WIN32_FIND_DATAA fd;\n    if (!::FindNextFileA(_handle, &fd))\n      return false;\n    ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);\n  }\n  return true;\n}\n#endif\n\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)\n{\n  CFindFile finder;\n  return finder.FindFirst(wildcard, fileInfo);\n}\n\n#ifndef _UNICODE\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)\n{\n  CFindFile finder;\n  return finder.FindFirst(wildcard, fileInfo);\n}\n#endif\n\nbool DoesFileExist(LPCTSTR name)\n{\n  CFileInfo fileInfo;\n  return FindFile(name, fileInfo);\n}\n\n#ifndef _UNICODE\nbool DoesFileExist(LPCWSTR name)\n{\n  CFileInfoW fileInfo;\n  return FindFile(name, fileInfo);\n}\n#endif\n\n/////////////////////////////////////\n// CEnumerator\n\nbool CEnumerator::NextAny(CFileInfo &fileInfo)\n{\n  if (_findFile.IsHandleAllocated())\n    return _findFile.FindNext(fileInfo);\n  else\n    return _findFile.FindFirst(_wildcard, fileInfo);\n}\n\nbool CEnumerator::Next(CFileInfo &fileInfo)\n{\n  for (;;)\n  {\n    if (!NextAny(fileInfo))\n      return false;\n    if (!fileInfo.IsDots())\n      return true;\n  }\n}\n\nbool CEnumerator::Next(CFileInfo &fileInfo, bool &found)\n{\n  if (Next(fileInfo))\n  {\n    found = true;\n    return true;\n  }\n  found = false;\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\n}\n\n#ifndef _UNICODE\nbool CEnumeratorW::NextAny(CFileInfoW &fileInfo)\n{\n  if (_findFile.IsHandleAllocated())\n    return _findFile.FindNext(fileInfo);\n  else\n    return _findFile.FindFirst(_wildcard, fileInfo);\n}\n\nbool CEnumeratorW::Next(CFileInfoW &fileInfo)\n{\n  for (;;)\n  {\n    if (!NextAny(fileInfo))\n      return false;\n    if (!fileInfo.IsDots())\n      return true;\n  }\n}\n\nbool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)\n{\n  if (Next(fileInfo))\n  {\n    found = true;\n    return true;\n  }\n  found = false;\n  return (::GetLastError() == ERROR_NO_MORE_FILES);\n}\n\n#endif\n\n////////////////////////////////\n// CFindChangeNotification\n// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.\n\nbool CFindChangeNotification::Close()\n{\n  if (!IsHandleAllocated())\n    return true;\n  if (!::FindCloseChangeNotification(_handle))\n    return false;\n  _handle = INVALID_HANDLE_VALUE;\n  return true;\n}\n           \nHANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)\n{\n  _handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);\n  #ifdef WIN_LONG_PATH2\n  if (!IsHandleAllocated())\n  {\n    UString longPath;\n    if (GetLongPath(pathName, longPath))\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\n  }\n  #endif\n  return _handle;\n}\n\n#ifndef _UNICODE\nHANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)\n{\n  if (!g_IsNT)\n    return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);\n  _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);\n  #ifdef WIN_LONG_PATH\n  if (!IsHandleAllocated())\n  {\n    UString longPath;\n    if (GetLongPath(pathName, longPath))\n      _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);\n  }\n  #endif\n  return _handle;\n}\n#endif\n\n#ifndef _WIN32_WCE\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)\n{\n  driveStrings.Clear();\n  UINT32 size = GetLogicalDriveStrings(0, NULL);\n  if (size == 0)\n    return false;\n  CSysString buffer;\n  UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size));\n  if (newSize == 0)\n    return false;\n  if (newSize > size)\n    return false;\n  CSysString string;\n  for (UINT32 i = 0; i < newSize; i++)\n  {\n    TCHAR c = buffer[i];\n    if (c == TEXT('\\0'))\n    {\n      driveStrings.Add(string);\n      string.Empty();\n    }\n    else\n      string += c;\n  }\n  if (!string.IsEmpty())\n    return false;\n  return true;\n}\n\n#ifndef _UNICODE\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings)\n{\n  driveStrings.Clear();\n  if (g_IsNT)\n  {\n    UINT32 size = GetLogicalDriveStringsW(0, NULL);\n    if (size == 0)\n      return false;\n    UString buffer;\n    UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size));\n    if (newSize == 0)\n      return false;\n    if (newSize > size)\n      return false;\n    UString string;\n    for (UINT32 i = 0; i < newSize; i++)\n    {\n      WCHAR c = buffer[i];\n      if (c == L'\\0')\n      {\n        driveStrings.Add(string);\n        string.Empty();\n      }\n      else\n        string += c;\n    }\n    return string.IsEmpty();\n  }\n  CSysStringVector driveStringsA;\n  bool res = MyGetLogicalDriveStrings(driveStringsA);\n  for (int i = 0; i < driveStringsA.Size(); i++)\n    driveStrings.Add(GetUnicodeString(driveStringsA[i]));\n  return res;\n}\n#endif\n\n#endif\n\n}}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileFind.h",
    "content": "// Windows/FileFind.h\n\n#ifndef __WINDOWS_FILEFIND_H\n#define __WINDOWS_FILEFIND_H\n\n#include \"../Common/MyString.h\"\n#include \"../Common/Types.h\"\n#include \"FileName.h\"\n#include \"Defs.h\"\n\nnamespace NWindows {\nnamespace NFile {\nnamespace NFind {\n\nnamespace NAttributes\n{\n  inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }\n  inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; }\n  inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; }\n  inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; }\n  inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }\n  inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }\n  inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }\n}\n\nclass CFileInfoBase\n{\n  bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }\npublic:\n  UInt64 Size;\n  FILETIME CTime;\n  FILETIME ATime;\n  FILETIME MTime;\n  DWORD Attrib;\n  \n  #ifndef _WIN32_WCE\n  UINT32 ReparseTag;\n  #else\n  DWORD ObjectID;\n  #endif\n\n  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }\n  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }\n  bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }\n  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }\n  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }\n  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }\n  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }\n  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }\n  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }\n  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }\n  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }\n  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }\n};\n\nclass CFileInfo: public CFileInfoBase\n{\npublic:\n  CSysString Name;\n  bool IsDots() const;\n};\n\n#ifdef _UNICODE\ntypedef CFileInfo CFileInfoW;\n#else\nclass CFileInfoW: public CFileInfoBase\n{\npublic:\n  UString Name;\n  bool IsDots() const;\n};\n#endif\n\nclass CFindFile\n{\n  friend class CEnumerator;\n  HANDLE _handle;\npublic:\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }\n  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}\n  ~CFindFile() {  Close(); }\n  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);\n  bool FindNext(CFileInfo &fileInfo);\n  #ifndef _UNICODE\n  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);\n  bool FindNext(CFileInfoW &fileInfo);\n  #endif\n  bool Close();\n};\n\nbool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);\n\nbool DoesFileExist(LPCTSTR name);\n#ifndef _UNICODE\nbool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);\nbool DoesFileExist(LPCWSTR name);\n#endif\n\nclass CEnumerator\n{\n  CFindFile _findFile;\n  CSysString _wildcard;\n  bool NextAny(CFileInfo &fileInfo);\npublic:\n  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}\n  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}\n  bool Next(CFileInfo &fileInfo);\n  bool Next(CFileInfo &fileInfo, bool &found);\n};\n\n#ifdef _UNICODE\ntypedef CEnumerator CEnumeratorW;\n#else\nclass CEnumeratorW\n{\n  CFindFile _findFile;\n  UString _wildcard;\n  bool NextAny(CFileInfoW &fileInfo);\npublic:\n  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}\n  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}\n  bool Next(CFileInfoW &fileInfo);\n  bool Next(CFileInfoW &fileInfo, bool &found);\n};\n#endif\n\nclass CFindChangeNotification\n{\n  HANDLE _handle;\npublic:\n  operator HANDLE () { return _handle; }\n  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }\n  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}\n  ~CFindChangeNotification() { Close(); }\n  bool Close();\n  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);\n  #ifndef _UNICODE\n  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);\n  #endif\n  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }\n};\n\n#ifndef _WIN32_WCE\nbool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);\n#ifndef _UNICODE\nbool MyGetLogicalDriveStrings(UStringVector &driveStrings);\n#endif\n#endif\n\n}}}\n\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\n\n#include \"StdAfx.h\"\n\n#include \"FileIO.h\"\n#include \"Defs.h\"\n#ifdef WIN_LONG_PATH\n#include \"../Common/MyString.h\"\n#endif\n#ifndef _UNICODE\n#include \"../Common/StringConvert.h\"\n#endif\n\n#ifndef _UNICODE\nextern bool g_IsNT;\n#endif\n\nnamespace NWindows {\nnamespace NFile {\n\n#if defined(WIN_LONG_PATH) && defined(_UNICODE)\n#define WIN_LONG_PATH2\n#endif\n\n#ifdef WIN_LONG_PATH\nbool GetLongPathBase(LPCWSTR s, UString &res)\n{\n  res.Empty();\n  int len = MyStringLen(s);\n  wchar_t c = s[0];\n  if (len < 1 || c == L'\\\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))\n    return true;\n  UString curDir;\n  bool isAbs = false;\n  if (len > 3)\n    isAbs = (s[1] == L':' && s[2] == L'\\\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));\n\n  if (!isAbs)\n    {\n      DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));\n      curDir.ReleaseBuffer();\n      if (needLength == 0 || needLength > MAX_PATH)\n        return false;\n      if (curDir[curDir.Length() - 1] != L'\\\\')\n        curDir += L'\\\\';\n    }\n  res = UString(L\"\\\\\\\\?\\\\\") + curDir + s;\n  return true;\n}\n\nbool GetLongPath(LPCWSTR path, UString &longPath)\n{\n  if (GetLongPathBase(path, longPath))\n    return !longPath.IsEmpty();\n  return false;\n}\n#endif\n\nnamespace NIO {\n\nCFileBase::~CFileBase() { Close(); }\n\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\n{\n  if (!Close())\n    return false;\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode,\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\n      flagsAndAttributes, (HANDLE)NULL);\n  #ifdef WIN_LONG_PATH2\n  if (_handle == INVALID_HANDLE_VALUE)\n  {\n    UString longPath;\n    if (GetLongPath(fileName, longPath))\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\n        flagsAndAttributes, (HANDLE)NULL);\n  }\n  #endif\n  return (_handle != INVALID_HANDLE_VALUE);\n}\n\n#ifndef _UNICODE\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\n{\n  if (!g_IsNT)\n    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP),\n      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\n  if (!Close())\n    return false;\n  _handle = ::CreateFileW(fileName, desiredAccess, shareMode,\n    (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\n    flagsAndAttributes, (HANDLE)NULL);\n  #ifdef WIN_LONG_PATH\n  if (_handle == INVALID_HANDLE_VALUE)\n  {\n    UString longPath;\n    if (GetLongPath(fileName, longPath))\n      _handle = ::CreateFileW(longPath, desiredAccess, shareMode,\n        (LPSECURITY_ATTRIBUTES)NULL, creationDisposition,\n        flagsAndAttributes, (HANDLE)NULL);\n  }\n  #endif\n  return (_handle != INVALID_HANDLE_VALUE);\n}\n#endif\n\nbool CFileBase::Close()\n{\n  if (_handle == INVALID_HANDLE_VALUE)\n    return true;\n  if (!::CloseHandle(_handle))\n    return false;\n  _handle = INVALID_HANDLE_VALUE;\n  return true;\n}\n\nbool CFileBase::GetPosition(UInt64 &position) const\n{\n  return Seek(0, FILE_CURRENT, position);\n}\n\nbool CFileBase::GetLength(UInt64 &length) const\n{\n  DWORD sizeHigh;\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\n  if (sizeLow == 0xFFFFFFFF)\n    if (::GetLastError() != NO_ERROR)\n      return false;\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\n  return true;\n}\n\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\n{\n  LARGE_INTEGER value;\n  value.QuadPart = distanceToMove;\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\n  if (value.LowPart == 0xFFFFFFFF)\n    if (::GetLastError() != NO_ERROR)\n      return false;\n  newPosition = value.QuadPart;\n  return true;\n}\n\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\n{\n  return Seek(position, FILE_BEGIN, newPosition);\n}\n\nbool CFileBase::SeekToBegin()\n{\n  UInt64 newPosition;\n  return Seek(0, newPosition);\n}\n\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\n{\n  return Seek(0, FILE_END, newPosition);\n}\n\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\n{\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\n  if (!::GetFileInformationByHandle(_handle, &winFileInfo))\n    return false;\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\n  fileInfo.CTime = winFileInfo.ftCreationTime;\n  fileInfo.ATime = winFileInfo.ftLastAccessTime;\n  fileInfo.MTime = winFileInfo.ftLastWriteTime;\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes;\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\n  return true;\n}\n\n/////////////////////////\n// CInFile\n\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\n\nbool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\n\nbool CInFile::Open(LPCTSTR fileName)\n  { return OpenShared(fileName, false); }\n\n#ifndef _UNICODE\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\n\nbool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)\n{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\n\nbool CInFile::Open(LPCWSTR fileName)\n  { return OpenShared(fileName, false); }\n#endif\n\n// ReadFile and WriteFile functions in Windows have BUG:\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES\n// (Insufficient system resources exist to complete the requested service).\n\n// Probably in some version of Windows there are problems with other sizes:\n// for 32 MB (maybe also for 16 MB).\n// And message can be \"Network connection was lost\"\n\nstatic UInt32 kChunkSizeMax = (1 << 22);\n\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\n{\n  if (size > kChunkSizeMax)\n    size = kChunkSizeMax;\n  DWORD processedLoc = 0;\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\n  processedSize = (UInt32)processedLoc;\n  return res;\n}\n\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\n{\n  processedSize = 0;\n  do\n  {\n    UInt32 processedLoc = 0;\n    bool res = ReadPart(data, size, processedLoc);\n    processedSize += processedLoc;\n    if (!res)\n      return false;\n    if (processedLoc == 0)\n      return true;\n    data = (void *)((unsigned char *)data + processedLoc);\n    size -= processedLoc;\n  }\n  while (size > 0);\n  return true;\n}\n\n/////////////////////////\n// COutFile\n\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\n\nstatic inline DWORD GetCreationDisposition(bool createAlways)\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\n\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\n\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\n\n#ifndef _UNICODE\n\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\n\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\n\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\n\n#endif\n\nbool COutFile::SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)\n  { return BOOLToBool(::SetFileTime(_handle, cTime, aTime, mTime)); }\n\nbool COutFile::SetMTime(const FILETIME *mTime) {  return SetTime(NULL, NULL, mTime); }\n\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\n{\n  if (size > kChunkSizeMax)\n    size = kChunkSizeMax;\n  DWORD processedLoc = 0;\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\n  processedSize = (UInt32)processedLoc;\n  return res;\n}\n\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\n{\n  processedSize = 0;\n  do\n  {\n    UInt32 processedLoc = 0;\n    bool res = WritePart(data, size, processedLoc);\n    processedSize += processedLoc;\n    if (!res)\n      return false;\n    if (processedLoc == 0)\n      return true;\n    data = (const void *)((const unsigned char *)data + processedLoc);\n    size -= processedLoc;\n  }\n  while (size > 0);\n  return true;\n}\n\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\n\nbool COutFile::SetLength(UInt64 length)\n{\n  UInt64 newPosition;\n  if (!Seek(length, newPosition))\n    return false;\n  if (newPosition != length)\n    return false;\n  return SetEndOfFile();\n}\n\n}}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\n\n#ifndef __WINDOWS_FILEIO_H\n#define __WINDOWS_FILEIO_H\n\n#include \"../Common/Types.h\"\n\nnamespace NWindows {\nnamespace NFile {\nnamespace NIO {\n\nstruct CByHandleFileInfo\n{\n  DWORD    Attributes;\n  FILETIME CTime;\n  FILETIME ATime;\n  FILETIME MTime;\n  DWORD    VolumeSerialNumber;\n  UInt64   Size;\n  DWORD    NumberOfLinks;\n  UInt64   FileIndex;\n};\n\nclass CFileBase\n{\nprotected:\n  HANDLE _handle;\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\n  #ifndef _UNICODE\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\n  #endif\n\npublic:\n  CFileBase(): _handle(INVALID_HANDLE_VALUE){};\n  ~CFileBase();\n\n  bool Close();\n\n  bool GetPosition(UInt64 &position) const;\n  bool GetLength(UInt64 &length) const;\n\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\n  bool Seek(UInt64 position, UInt64 &newPosition);\n  bool SeekToBegin();\n  bool SeekToEnd(UInt64 &newPosition);\n  \n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\n};\n\nclass CInFile: public CFileBase\n{\npublic:\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\n  bool OpenShared(LPCTSTR fileName, bool shareForWrite);\n  bool Open(LPCTSTR fileName);\n  #ifndef _UNICODE\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\n  bool OpenShared(LPCWSTR fileName, bool shareForWrite);\n  bool Open(LPCWSTR fileName);\n  #endif\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\n};\n\nclass COutFile: public CFileBase\n{\n  // DWORD m_CreationDisposition;\npublic:\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\n  bool Create(LPCTSTR fileName, bool createAlways);\n\n  #ifndef _UNICODE\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\n  bool Create(LPCWSTR fileName, bool createAlways);\n  #endif\n\n  /*\n  void SetOpenCreationDisposition(DWORD creationDisposition)\n    { m_CreationDisposition = creationDisposition; }\n  void SetOpenCreationDispositionCreateAlways()\n    { m_CreationDisposition = CREATE_ALWAYS; }\n  */\n\n  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);\n  bool SetMTime(const FILETIME *mTime);\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\n  bool SetEndOfFile();\n  bool SetLength(UInt64 length);\n};\n\n}}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileMapping.cpp",
    "content": "// Windows/FileMapping.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Windows/FileMapping.h\"\n\nnamespace NWindows {\nnamespace NFile {\nnamespace NMapping {\n\n\n\n\n}}}"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileMapping.h",
    "content": "// Windows/FileMapping.h\n\n#ifndef __WINDOWS_FILEMAPPING_H\n#define __WINDOWS_FILEMAPPING_H\n\n#include \"Windows/Handle.h\"\n#include \"Windows/Defs.h\"\n\nnamespace NWindows {\n// namespace NFile {\n// namespace NMapping {\n\nclass CFileMapping: public CHandle\n{\npublic:\n  bool Create(HANDLE file, LPSECURITY_ATTRIBUTES attributes,\n    DWORD protect, UINT64 maximumSize, LPCTSTR name)\n  {\n    _handle = ::CreateFileMapping(file, attributes,\n      protect, DWORD(maximumSize >> 32), DWORD(maximumSize), name);\n    return (_handle != NULL);\n  }\n\n  bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\n  {\n    _handle = ::OpenFileMapping(desiredAccess, BoolToBOOL(inheritHandle), name);\n    return (_handle != NULL);\n  }\n\n  LPVOID MapViewOfFile(DWORD desiredAccess, UINT64 fileOffset,\n      SIZE_T numberOfBytesToMap)\n  {\n    return ::MapViewOfFile(_handle, desiredAccess,\n        DWORD(fileOffset >> 32), DWORD(fileOffset), numberOfBytesToMap);\n  }\n\n  LPVOID MapViewOfFileEx(DWORD desiredAccess, UINT64 fileOffset,\n      SIZE_T numberOfBytesToMap, LPVOID baseAddress)\n  {\n    return ::MapViewOfFileEx(_handle, desiredAccess,\n      DWORD(fileOffset >> 32), DWORD(fileOffset),\n      numberOfBytesToMap, baseAddress);\n  }\n  \n\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileName.cpp",
    "content": "// Windows/FileName.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Windows/FileName.h\"\n#include \"Common/Wildcard.h\"\n\nnamespace NWindows {\nnamespace NFile {\nnamespace NName {\n\nvoid NormalizeDirPathPrefix(CSysString &dirPath)\n{\n  if (dirPath.IsEmpty())\n    return;\n  if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)\n    dirPath += kDirDelimiter;\n}\n\n#ifndef _UNICODE\nvoid NormalizeDirPathPrefix(UString &dirPath)\n{\n  if (dirPath.IsEmpty())\n    return;\n  if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)\n    dirPath += wchar_t(kDirDelimiter);\n}\n#endif\n\nconst wchar_t kExtensionDelimiter = L'.';\n\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\n    UString &pureName, UString &extensionDelimiter, UString &extension)\n{\n  int index = fullName.ReverseFind(kExtensionDelimiter);\n  if (index < 0)\n  {\n    pureName = fullName;\n    extensionDelimiter.Empty();\n    extension.Empty();\n  }\n  else\n  {\n    pureName = fullName.Left(index);\n    extensionDelimiter = kExtensionDelimiter;\n    extension = fullName.Mid(index + 1);\n  }\n}\n\n}}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/FileName.h",
    "content": "// Windows/FileName.h\n\n#ifndef __WINDOWS_FILENAME_H\n#define __WINDOWS_FILENAME_H\n\n#include \"../Common/MyString.h\"\n\nnamespace NWindows {\nnamespace NFile {\nnamespace NName {\n\nconst TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;\nconst TCHAR kAnyStringWildcard = '*';\n\nvoid NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\\\'\n#ifndef _UNICODE\nvoid NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\\\'\n#endif\n\nvoid SplitNameToPureNameAndExtension(const UString &fullName,\n    UString &pureName, UString &extensionDelimiter, UString &extension);\n\n}}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/Handle.h",
    "content": "// Windows/Handle.h\n\n#ifndef __WINDOWS_HANDLE_H\n#define __WINDOWS_HANDLE_H\n\nnamespace NWindows {\n\nclass CHandle\n{\nprotected:\n  HANDLE _handle;\npublic:\n  operator HANDLE() { return _handle; }\n  CHandle(): _handle(NULL) {}\n  ~CHandle() { Close(); }\n  bool Close()\n  {\n    if (_handle == NULL)\n      return true;\n    if (!::CloseHandle(_handle))\n      return false;\n    _handle = NULL;\n    return true;\n  }\n  void Attach(HANDLE handle)\n    { _handle = handle; }\n  HANDLE Detach()\n  {\n    HANDLE handle = _handle;\n    _handle = NULL;\n    return handle;\n  }\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/MemoryLock.cpp",
    "content": "// Common/MemoryLock.cpp\n\n#include \"StdAfx.h\"\n\nnamespace NWindows {\nnamespace NSecurity {\n\n#ifndef _UNICODE\ntypedef BOOL (WINAPI * OpenProcessTokenP)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);\ntypedef BOOL (WINAPI * LookupPrivilegeValueP)(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID  lpLuid);\ntypedef BOOL (WINAPI * AdjustTokenPrivilegesP)(HANDLE TokenHandle, BOOL DisableAllPrivileges,\n    PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength);\n#endif\n\n#ifdef _UNICODE\nbool EnableLockMemoryPrivilege(\n#else\nstatic bool EnableLockMemoryPrivilege2(HMODULE hModule,\n#endif\nbool enable)\n{\n  #ifndef _UNICODE\n  if (hModule == NULL)\n    return false;\n  OpenProcessTokenP openProcessToken = (OpenProcessTokenP)GetProcAddress(hModule, \"OpenProcessToken\");\n  LookupPrivilegeValueP lookupPrivilegeValue = (LookupPrivilegeValueP)GetProcAddress(hModule, \"LookupPrivilegeValueA\" );\n  AdjustTokenPrivilegesP adjustTokenPrivileges = (AdjustTokenPrivilegesP)GetProcAddress(hModule, \"AdjustTokenPrivileges\");\n  if (openProcessToken == NULL || adjustTokenPrivileges == NULL || lookupPrivilegeValue == NULL)\n    return false;\n  #endif\n\n  HANDLE token;\n  if (!\n    #ifdef _UNICODE\n    ::OpenProcessToken\n    #else\n    openProcessToken\n    #endif\n    (::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))\n    return false;\n  TOKEN_PRIVILEGES tp;\n  bool res = false;\n  if (\n    #ifdef _UNICODE\n    ::LookupPrivilegeValue\n    #else\n    lookupPrivilegeValue\n    #endif\n    (NULL, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)))\n  {\n    tp.PrivilegeCount = 1;\n    tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED: 0;\n    if (\n      #ifdef _UNICODE\n      ::AdjustTokenPrivileges\n      #else\n      adjustTokenPrivileges\n      #endif\n      (token, FALSE, &tp, 0, NULL, NULL))\n      res = (GetLastError() == ERROR_SUCCESS);\n  }\n  ::CloseHandle(token);\n  return res;\n}\n\n#ifndef _UNICODE\nbool EnableLockMemoryPrivilege(bool enable)\n{\n  HMODULE hModule = LoadLibrary(TEXT(\"Advapi32.dll\"));\n  if (hModule == NULL)\n    return false;\n  bool res = EnableLockMemoryPrivilege2(hModule, enable);\n  ::FreeLibrary(hModule);\n  return res;\n}\n#endif\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/MemoryLock.h",
    "content": "// Windows/MemoryLock.h\n\n#ifndef __WINDOWS_MEMORYLOCK_H\n#define __WINDOWS_MEMORYLOCK_H\n\nnamespace NWindows {\nnamespace NSecurity {\n\nbool EnableLockMemoryPrivilege(bool enable = true);\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/PropVariant.cpp",
    "content": "// Windows/PropVariant.cpp\n\n#include \"StdAfx.h\"\n\n#include \"PropVariant.h\"\n\n#include \"../Common/Defs.h\"\n\nnamespace NWindows {\nnamespace NCOM {\n\nCPropVariant::CPropVariant(const PROPVARIANT& varSrc)\n{\n  vt = VT_EMPTY;\n  InternalCopy(&varSrc);\n}\n\nCPropVariant::CPropVariant(const CPropVariant& varSrc)\n{\n  vt = VT_EMPTY;\n  InternalCopy(&varSrc);\n}\n\nCPropVariant::CPropVariant(BSTR bstrSrc)\n{\n  vt = VT_EMPTY;\n  *this = bstrSrc;\n}\n\nCPropVariant::CPropVariant(LPCOLESTR lpszSrc)\n{\n  vt = VT_EMPTY;\n  *this = lpszSrc;\n}\n\nCPropVariant& CPropVariant::operator=(const CPropVariant& varSrc)\n{\n  InternalCopy(&varSrc);\n  return *this;\n}\nCPropVariant& CPropVariant::operator=(const PROPVARIANT& varSrc)\n{\n  InternalCopy(&varSrc);\n  return *this;\n}\n\nCPropVariant& CPropVariant::operator=(BSTR bstrSrc)\n{\n  *this = (LPCOLESTR)bstrSrc;\n  return *this;\n}\n\nCPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)\n{\n  InternalClear();\n  vt = VT_BSTR;\n  wReserved1 = 0;\n  bstrVal = ::SysAllocString(lpszSrc);\n  if (bstrVal == NULL && lpszSrc != NULL)\n  {\n    vt = VT_ERROR;\n    scode = E_OUTOFMEMORY;\n  }\n  return *this;\n}\n\n\nCPropVariant& CPropVariant::operator=(bool bSrc)\n{\n  if (vt != VT_BOOL)\n  {\n    InternalClear();\n    vt = VT_BOOL;\n  }\n  boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE;\n  return *this;\n}\n\nCPropVariant& CPropVariant::operator=(UInt32 value)\n{\n  if (vt != VT_UI4)\n  {\n    InternalClear();\n    vt = VT_UI4;\n  }\n  ulVal = value;\n  return *this;\n}\n\nCPropVariant& CPropVariant::operator=(UInt64 value)\n{\n  if (vt != VT_UI8)\n  {\n    InternalClear();\n    vt = VT_UI8;\n  }\n  uhVal.QuadPart = value;\n  return *this;\n}\n\nCPropVariant& CPropVariant::operator=(const FILETIME &value)\n{\n  if (vt != VT_FILETIME)\n  {\n    InternalClear();\n    vt = VT_FILETIME;\n  }\n  filetime = value;\n  return *this;\n}\n\nCPropVariant& CPropVariant::operator=(Int32 value)\n{\n  if (vt != VT_I4)\n  {\n    InternalClear();\n    vt = VT_I4;\n  }\n  lVal = value;\n  \n  return *this;\n}\n\nCPropVariant& CPropVariant::operator=(Byte value)\n{\n  if (vt != VT_UI1)\n  {\n    InternalClear();\n    vt = VT_UI1;\n  }\n  bVal = value;\n  return *this;\n}\n\nCPropVariant& CPropVariant::operator=(Int16 value)\n{\n  if (vt != VT_I2)\n  {\n    InternalClear();\n    vt = VT_I2;\n  }\n  iVal = value;\n  return *this;\n}\n\n/*\nCPropVariant& CPropVariant::operator=(LONG value)\n{\n  if (vt != VT_I4)\n  {\n    InternalClear();\n    vt = VT_I4;\n  }\n  lVal = value;\n  return *this;\n}\n*/\n\nstatic HRESULT MyPropVariantClear(PROPVARIANT *propVariant)\n{\n  switch(propVariant->vt)\n  {\n    case VT_UI1:\n    case VT_I1:\n    case VT_I2:\n    case VT_UI2:\n    case VT_BOOL:\n    case VT_I4:\n    case VT_UI4:\n    case VT_R4:\n    case VT_INT:\n    case VT_UINT:\n    case VT_ERROR:\n    case VT_FILETIME:\n    case VT_UI8:\n    case VT_R8:\n    case VT_CY:\n    case VT_DATE:\n      propVariant->vt = VT_EMPTY;\n      propVariant->wReserved1 = 0;\n      return S_OK;\n  }\n  return ::VariantClear((VARIANTARG *)propVariant);\n}\n\nHRESULT CPropVariant::Clear()\n{\n  return MyPropVariantClear(this);\n}\n\nHRESULT CPropVariant::Copy(const PROPVARIANT* pSrc)\n{\n  ::VariantClear((tagVARIANT *)this);\n  switch(pSrc->vt)\n  {\n    case VT_UI1:\n    case VT_I1:\n    case VT_I2:\n    case VT_UI2:\n    case VT_BOOL:\n    case VT_I4:\n    case VT_UI4:\n    case VT_R4:\n    case VT_INT:\n    case VT_UINT:\n    case VT_ERROR:\n    case VT_FILETIME:\n    case VT_UI8:\n    case VT_R8:\n    case VT_CY:\n    case VT_DATE:\n      memmove((PROPVARIANT*)this, pSrc, sizeof(PROPVARIANT));\n      return S_OK;\n  }\n  return ::VariantCopy((tagVARIANT *)this, (tagVARIANT *)(pSrc));\n}\n\n\nHRESULT CPropVariant::Attach(PROPVARIANT* pSrc)\n{\n  HRESULT hr = Clear();\n  if (FAILED(hr))\n    return hr;\n  memcpy(this, pSrc, sizeof(PROPVARIANT));\n  pSrc->vt = VT_EMPTY;\n  return S_OK;\n}\n\nHRESULT CPropVariant::Detach(PROPVARIANT* pDest)\n{\n  HRESULT hr = MyPropVariantClear(pDest);\n  if (FAILED(hr))\n    return hr;\n  memcpy(pDest, this, sizeof(PROPVARIANT));\n  vt = VT_EMPTY;\n  return S_OK;\n}\n\nHRESULT CPropVariant::InternalClear()\n{\n  HRESULT hr = Clear();\n  if (FAILED(hr))\n  {\n    vt = VT_ERROR;\n    scode = hr;\n  }\n  return hr;\n}\n\nvoid CPropVariant::InternalCopy(const PROPVARIANT* pSrc)\n{\n  HRESULT hr = Copy(pSrc);\n  if (FAILED(hr))\n  {\n    vt = VT_ERROR;\n    scode = hr;\n  }\n}\n\nint CPropVariant::Compare(const CPropVariant &a)\n{\n  if (vt != a.vt)\n    return 0; // it's mean some bug\n  switch (vt)\n  {\n    case VT_EMPTY:\n      return 0;\n    \n    /*\n    case VT_I1:\n      return MyCompare(cVal, a.cVal);\n    */\n    case VT_UI1:\n      return MyCompare(bVal, a.bVal);\n\n    case VT_I2:\n      return MyCompare(iVal, a.iVal);\n    case VT_UI2:\n      return MyCompare(uiVal, a.uiVal);\n    \n    case VT_I4:\n      return MyCompare(lVal, a.lVal);\n    /*\n    case VT_INT:\n      return MyCompare(intVal, a.intVal);\n    */\n    case VT_UI4:\n      return MyCompare(ulVal, a.ulVal);\n    /*\n    case VT_UINT:\n      return MyCompare(uintVal, a.uintVal);\n    */\n    case VT_I8:\n      return MyCompare(hVal.QuadPart, a.hVal.QuadPart);\n    case VT_UI8:\n      return MyCompare(uhVal.QuadPart, a.uhVal.QuadPart);\n\n    case VT_BOOL:\n      return -MyCompare(boolVal, a.boolVal);\n\n    case VT_FILETIME:\n      return ::CompareFileTime(&filetime, &a.filetime);\n    case VT_BSTR:\n      return 0; // Not implemented\n      // return MyCompare(aPropVarint.cVal);\n\n    default:\n      return 0;\n  }\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/PropVariant.h",
    "content": "// Windows/PropVariant.h\n\n#ifndef __WINDOWS_PROPVARIANT_H\n#define __WINDOWS_PROPVARIANT_H\n\n#include \"../Common/MyWindows.h\"\n#include \"../Common/Types.h\"\n\nnamespace NWindows {\nnamespace NCOM {\n\nclass CPropVariant : public tagPROPVARIANT\n{\npublic:\n  CPropVariant() { vt = VT_EMPTY; wReserved1 = 0; }\n  ~CPropVariant() { Clear(); }\n  CPropVariant(const PROPVARIANT& varSrc);\n  CPropVariant(const CPropVariant& varSrc);\n  CPropVariant(BSTR bstrSrc);\n  CPropVariant(LPCOLESTR lpszSrc);\n  CPropVariant(bool bSrc) { vt = VT_BOOL; wReserved1 = 0; boolVal = (bSrc ? VARIANT_TRUE : VARIANT_FALSE); };\n  CPropVariant(UInt32 value) { vt = VT_UI4; wReserved1 = 0; ulVal = value; }\n  CPropVariant(UInt64 value) { vt = VT_UI8; wReserved1 = 0; uhVal = *(ULARGE_INTEGER*)&value; }\n  CPropVariant(const FILETIME &value) { vt = VT_FILETIME; wReserved1 = 0; filetime = value; }\n  CPropVariant(Int32 value) { vt = VT_I4; wReserved1 = 0; lVal = value; }\n  CPropVariant(Byte value) { vt = VT_UI1; wReserved1 = 0; bVal = value; }\n  CPropVariant(Int16 value) { vt = VT_I2; wReserved1 = 0; iVal = value; }\n  // CPropVariant(LONG value, VARTYPE vtSrc = VT_I4) { vt = vtSrc; lVal = value; }\n\n  CPropVariant& operator=(const CPropVariant& varSrc);\n  CPropVariant& operator=(const PROPVARIANT& varSrc);\n  CPropVariant& operator=(BSTR bstrSrc);\n  CPropVariant& operator=(LPCOLESTR lpszSrc);\n  CPropVariant& operator=(bool bSrc);\n  CPropVariant& operator=(UInt32 value);\n  CPropVariant& operator=(UInt64 value);\n  CPropVariant& operator=(const FILETIME &value);\n\n  CPropVariant& operator=(Int32 value);\n  CPropVariant& operator=(Byte value);\n  CPropVariant& operator=(Int16 value);\n  // CPropVariant& operator=(LONG  value);\n\n  HRESULT Clear();\n  HRESULT Copy(const PROPVARIANT* pSrc);\n  HRESULT Attach(PROPVARIANT* pSrc);\n  HRESULT Detach(PROPVARIANT* pDest);\n\n  HRESULT InternalClear();\n  void InternalCopy(const PROPVARIANT* pSrc);\n\n  int Compare(const CPropVariant &a1);\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/PropVariantConversions.cpp",
    "content": "// PropVariantConversions.cpp\n\n#include \"StdAfx.h\"\n\n#include \"PropVariantConversions.h\"\n\n#include \"Windows/Defs.h\"\n\n#include \"Common/StringConvert.h\"\n#include \"Common/IntToString.h\"\n\nstatic UString ConvertUInt64ToString(UInt64 value)\n{\n  wchar_t buffer[32];\n  ConvertUInt64ToString(value, buffer);\n  return buffer;\n}\n\nstatic UString ConvertInt64ToString(Int64 value)\n{\n  wchar_t buffer[32];\n  ConvertInt64ToString(value, buffer);\n  return buffer;\n}\n\nstatic char *UIntToStringSpec(char c, UInt32 value, char *s, int numPos)\n{\n  if (c != 0)\n    *s++ = c;\n  char temp[16];\n  int pos = 0;\n  do\n  {\n    temp[pos++] = (char)('0' + value % 10);\n    value /= 10;\n  }\n  while (value != 0);\n  int i;\n  for (i = 0; i < numPos - pos; i++)\n    *s++ = '0';\n  do\n    *s++ = temp[--pos];\n  while (pos > 0);\n  *s = '\\0';\n  return s;\n}\n\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)\n{\n  s[0] = '\\0';\n  SYSTEMTIME st;\n  if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))\n    return false;\n  s = UIntToStringSpec(0, st.wYear, s, 4);\n  s = UIntToStringSpec('-', st.wMonth, s, 2);\n  s = UIntToStringSpec('-', st.wDay, s, 2);\n  if (includeTime)\n  {\n    s = UIntToStringSpec(' ', st.wHour, s, 2);\n    s = UIntToStringSpec(':', st.wMinute, s, 2);\n    if (includeSeconds)\n      UIntToStringSpec(':', st.wSecond, s, 2);\n  }\n  return true;\n}\n\nUString ConvertFileTimeToString(const FILETIME &fileTime, bool includeTime, bool includeSeconds)\n{\n  char s[32];\n  ConvertFileTimeToString(fileTime, s,  includeTime, includeSeconds);\n  return GetUnicodeString(s);\n}\n \n\nUString ConvertPropVariantToString(const PROPVARIANT &prop)\n{\n  switch (prop.vt)\n  {\n    case VT_EMPTY: return UString();\n    case VT_BSTR: return prop.bstrVal;\n    case VT_UI1: return ConvertUInt64ToString(prop.bVal);\n    case VT_UI2: return ConvertUInt64ToString(prop.uiVal);\n    case VT_UI4: return ConvertUInt64ToString(prop.ulVal);\n    case VT_UI8: return ConvertUInt64ToString(prop.uhVal.QuadPart);\n    case VT_FILETIME: return ConvertFileTimeToString(prop.filetime, true, true);\n    // case VT_I1: return ConvertInt64ToString(prop.cVal);\n    case VT_I2: return ConvertInt64ToString(prop.iVal);\n    case VT_I4: return ConvertInt64ToString(prop.lVal);\n    case VT_I8: return ConvertInt64ToString(prop.hVal.QuadPart);\n    case VT_BOOL: return VARIANT_BOOLToBool(prop.boolVal) ? L\"+\" : L\"-\";\n    default:\n      #ifndef _WIN32_WCE\n      throw 150245;\n      #else\n      return UString();\n      #endif\n  }\n}\n\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &prop)\n{\n  switch (prop.vt)\n  {\n    case VT_UI1: return prop.bVal;\n    case VT_UI2: return prop.uiVal;\n    case VT_UI4: return prop.ulVal;\n    case VT_UI8: return (UInt64)prop.uhVal.QuadPart;\n    default:\n      #ifndef _WIN32_WCE\n      throw 151199;\n      #else\n      return 0;\n      #endif\n  }\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/PropVariantConversions.h",
    "content": "// Windows/PropVariantConversions.h\n\n#ifndef __PROPVARIANTCONVERSIONS_H\n#define __PROPVARIANTCONVERSIONS_H\n\n#include \"Common/Types.h\"\n#include \"Common/MyString.h\"\n\nbool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true);\nUString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true);\nUString ConvertPropVariantToString(const PROPVARIANT &propVariant);\nUInt64 ConvertPropVariantToUInt64(const PROPVARIANT &propVariant);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include \"../Common/MyWindows.h\"\n#include \"../Common/NewHandler.h\"\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/Synchronization.cpp",
    "content": "// Windows/Synchronization.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Synchronization.h\"\n\nnamespace NWindows {\nnamespace NSynchronization {\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/Synchronization.h",
    "content": "// Windows/Synchronization.h\n\n#ifndef __WINDOWS_SYNCHRONIZATION_H\n#define __WINDOWS_SYNCHRONIZATION_H\n\n#include \"Defs.h\"\n\nextern \"C\"\n{\n#include \"../../C/Threads.h\"\n}\n\n#ifdef _WIN32\n#include \"Handle.h\"\n#endif\n\nnamespace NWindows {\nnamespace NSynchronization {\n\nclass CBaseEvent\n{\nprotected:\n  ::CEvent _object;\npublic:\n  bool IsCreated() { return Event_IsCreated(&_object) != 0; }\n  operator HANDLE() { return _object.handle; }\n  CBaseEvent() { Event_Construct(&_object); }\n  ~CBaseEvent() { Close(); }\n  WRes Close() { return Event_Close(&_object); }\n  #ifdef _WIN32\n  WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\n  {\n    _object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),\n        BoolToBOOL(initiallyOwn), name);\n    if (_object.handle != 0)\n      return 0;\n    return ::GetLastError();\n  }\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\n  {\n    _object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);\n    if (_object.handle != 0)\n      return 0;\n    return ::GetLastError();\n  }\n  #endif\n\n  WRes Set() { return Event_Set(&_object); }\n  // bool Pulse() { return BOOLToBool(::PulseEvent(_handle)); }\n  WRes Reset() { return Event_Reset(&_object); }\n  WRes Lock() { return Event_Wait(&_object); }\n};\n\nclass CManualResetEvent: public CBaseEvent\n{\npublic:\n  WRes Create(bool initiallyOwn = false)\n  {\n    return ManualResetEvent_Create(&_object, initiallyOwn ? 1: 0);\n  }\n  WRes CreateIfNotCreated()\n  {\n    if (IsCreated())\n      return 0;\n    return ManualResetEvent_CreateNotSignaled(&_object);\n  }\n  #ifdef _WIN32\n  WRes CreateWithName(bool initiallyOwn, LPCTSTR name)\n  {\n    return CBaseEvent::Create(true, initiallyOwn, name);\n  }\n  #endif\n};\n\nclass CAutoResetEvent: public CBaseEvent\n{\npublic:\n  WRes Create()\n  {\n    return AutoResetEvent_CreateNotSignaled(&_object);\n  }\n  WRes CreateIfNotCreated()\n  {\n    if (IsCreated())\n      return 0;\n    return AutoResetEvent_CreateNotSignaled(&_object);\n  }\n};\n\n#ifdef _WIN32\nclass CObject: public CHandle\n{\npublic:\n  WRes Lock(DWORD timeoutInterval = INFINITE)\n    { return (::WaitForSingleObject(_handle, timeoutInterval) == WAIT_OBJECT_0 ? 0 : ::GetLastError()); }\n};\nclass CMutex: public CObject\n{\npublic:\n  WRes Create(bool initiallyOwn, LPCTSTR name = NULL,\n      LPSECURITY_ATTRIBUTES securityAttributes = NULL)\n  {\n    _handle = ::CreateMutex(securityAttributes, BoolToBOOL(initiallyOwn), name);\n    if (_handle != 0)\n      return 0;\n    return ::GetLastError();\n  }\n  WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)\n  {\n    _handle = ::OpenMutex(desiredAccess, BoolToBOOL(inheritHandle), name);\n    if (_handle != 0)\n      return 0;\n    return ::GetLastError();\n  }\n  WRes Release()\n  {\n    return ::ReleaseMutex(_handle) ? 0 : ::GetLastError();\n  }\n};\nclass CMutexLock\n{\n  CMutex *_object;\npublic:\n  CMutexLock(CMutex &object): _object(&object) { _object->Lock(); }\n  ~CMutexLock() { _object->Release(); }\n};\n#endif\n\nclass CSemaphore\n{\n  ::CSemaphore _object;\npublic:\n  CSemaphore() { Semaphore_Construct(&_object); }\n  ~CSemaphore() { Close(); }\n  WRes Close() {  return Semaphore_Close(&_object); }\n  operator HANDLE() { return _object.handle; }\n  WRes Create(UInt32 initiallyCount, UInt32 maxCount)\n  {\n    return Semaphore_Create(&_object, initiallyCount, maxCount);\n  }\n  WRes Release() { return Semaphore_Release1(&_object); }\n  WRes Release(UInt32 releaseCount) { return Semaphore_ReleaseN(&_object, releaseCount); }\n  WRes Lock() { return Semaphore_Wait(&_object); }\n};\n\nclass CCriticalSection\n{\n  ::CCriticalSection _object;\npublic:\n  CCriticalSection() { CriticalSection_Init(&_object); }\n  ~CCriticalSection() { CriticalSection_Delete(&_object); }\n  void Enter() { CriticalSection_Enter(&_object); }\n  void Leave() { CriticalSection_Leave(&_object); }\n};\n\nclass CCriticalSectionLock\n{\n  CCriticalSection *_object;\n  void Unlock()  { _object->Leave(); }\npublic:\n  CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); }\n  ~CCriticalSectionLock() { Unlock(); }\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/System.cpp",
    "content": "// Windows/System.cpp\n\n#include \"StdAfx.h\"\n\n#include \"System.h\"\n\nnamespace NWindows {\nnamespace NSystem {\n\nUInt32 GetNumberOfProcessors()\n{\n  SYSTEM_INFO systemInfo;\n  GetSystemInfo(&systemInfo);\n  return (UInt32)systemInfo.dwNumberOfProcessors;\n}\n\n#if !defined(_WIN64) && defined(__GNUC__)\n\ntypedef struct _MY_MEMORYSTATUSEX {\n  DWORD dwLength;\n  DWORD dwMemoryLoad;\n  DWORDLONG ullTotalPhys;\n  DWORDLONG ullAvailPhys;\n  DWORDLONG ullTotalPageFile;\n  DWORDLONG ullAvailPageFile;\n  DWORDLONG ullTotalVirtual;\n  DWORDLONG ullAvailVirtual;\n  DWORDLONG ullAvailExtendedVirtual;\n} MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX;\n\n#else\n\n#define MY_MEMORYSTATUSEX MEMORYSTATUSEX\n#define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX\n\n#endif\n\ntypedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer);\n\nUInt64 GetRamSize()\n{\n  MY_MEMORYSTATUSEX stat;\n  stat.dwLength = sizeof(stat);\n  #ifdef _WIN64\n  if (!::GlobalMemoryStatusEx(&stat))\n    return 0;\n  return stat.ullTotalPhys;\n  #else\n  GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP)\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")),\n        \"GlobalMemoryStatusEx\");\n  if (globalMemoryStatusEx != 0)\n    if (globalMemoryStatusEx(&stat))\n      return stat.ullTotalPhys;\n  {\n    MEMORYSTATUS stat;\n    stat.dwLength = sizeof(stat);\n    GlobalMemoryStatus(&stat);\n    return stat.dwTotalPhys;\n  }\n  #endif\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/System.h",
    "content": "// Windows/System.h\n\n#ifndef __WINDOWS_SYSTEM_H\n#define __WINDOWS_SYSTEM_H\n\n#include \"../Common/Types.h\"\n\nnamespace NWindows {\nnamespace NSystem {\n\nUInt32 GetNumberOfProcessors();\nUInt64 GetRamSize();\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/Thread.h",
    "content": "// Windows/Thread.h\n\n#ifndef __WINDOWS_THREAD_H\n#define __WINDOWS_THREAD_H\n\n#include \"Defs.h\"\n\nextern \"C\"\n{\n#include \"../../C/Threads.h\"\n}\n\nnamespace NWindows {\n\nclass CThread\n{\n  ::CThread thread;\npublic:\n  CThread() { Thread_Construct(&thread); }\n  ~CThread() { Close(); }\n  bool IsCreated() { return Thread_WasCreated(&thread) != 0; }\n  WRes Close()  { return Thread_Close(&thread); }\n  WRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\n    { return Thread_Create(&thread, startAddress, parameter); }\n  WRes Wait() { return Thread_Wait(&thread); }\n  \n  #ifdef _WIN32\n  operator HANDLE() { return thread.handle; }\n  void Attach(HANDLE handle) { thread.handle = handle; }\n  HANDLE Detach() { HANDLE h = thread.handle; thread.handle = NULL; return h; }\n  DWORD Resume() { return ::ResumeThread(thread.handle); }\n  DWORD Suspend() { return ::SuspendThread(thread.handle); }\n  bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }\n  int GetPriority() { return ::GetThreadPriority(thread.handle); }\n  bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }\n  #endif\n};\n\n}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/Time.cpp",
    "content": "// Windows/Time.cpp\n\n#include \"StdAfx.h\"\n\n#include \"Time.h\"\n#include \"Windows/Defs.h\"\n\nnamespace NWindows {\nnamespace NTime {\n\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)\n{\n  return BOOLToBool(::DosDateTimeToFileTime((UInt16)(dosTime >> 16), (UInt16)(dosTime & 0xFFFF), &fileTime));\n}\n\nstatic const UInt32 kHighDosTime = 0xFF9FBF7D;\nstatic const UInt32 kLowDosTime = 0x210000;\n\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)\n{\n  WORD datePart, timePart;\n  if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))\n  {\n    dosTime = (fileTime.dwHighDateTime >= 0x01C00000) ? kHighDosTime : kLowDosTime;\n    return false;\n  }\n  dosTime = (((UInt32)datePart) << 16) + timePart;\n  return true;\n}\n\nstatic const UInt32 kNumTimeQuantumsInSecond = 10000000;\nstatic const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;\n\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)\n{\n  UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;\n  fileTime.dwLowDateTime = (DWORD)v;\n  fileTime.dwHighDateTime = (DWORD)(v >> 32);\n}\n\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)\n{\n  UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;\n  if (winTime < kUnixTimeStartValue)\n  {\n    unixTime = 0;\n    return false;\n  }\n  winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;\n  if (winTime > 0xFFFFFFFF)\n  {\n    unixTime = 0xFFFFFFFF;\n    return false;\n  }\n  unixTime = (UInt32)winTime;\n  return true;\n}\n\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds)\n{\n  resSeconds = 0;\n  if (year < 1601 || year >= 10000 || month < 1 || month > 12 ||\n      day < 1 || day > 31 || hour > 23 || min > 59 || sec > 59)\n    return false;\n  UInt32 numYears = year - 1601;\n  UInt32 numDays = numYears * 365 + numYears / 4 - numYears / 100 + numYears / 400;\n  Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n  if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))\n    ms[1] = 29;\n  month--;\n  for (unsigned i = 0; i < month; i++)\n    numDays += ms[i];\n  numDays += day - 1;\n  resSeconds = ((UInt64)(numDays * 24 + hour) * 60 + min) * 60 + sec;\n  return true;\n}\n\nvoid GetCurUtcFileTime(FILETIME &ft)\n{\n  SYSTEMTIME st;\n  GetSystemTime(&st);\n  SystemTimeToFileTime(&st, &ft);\n}\n\n}}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CPP/Windows/Time.h",
    "content": "// Windows/Time.h\n\n#ifndef __WINDOWS_TIME_H\n#define __WINDOWS_TIME_H\n\n#include \"Common/Types.h\"\n\nnamespace NWindows {\nnamespace NTime {\n\nbool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime);\nbool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime);\nvoid UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime);\nbool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime);\nbool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,\n  unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds);\nvoid GetCurUtcFileTime(FILETIME &ft);\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\n\nnamespace SevenZip\n{\n\tclass CRC\n\t{\n\t\tpublic static readonly uint[] Table;\n\n\t\tstatic CRC()\n\t\t{\n\t\t\tTable = new uint[256];\n\t\t\tconst uint kPoly = 0xEDB88320;\n\t\t\tfor (uint i = 0; i < 256; i++)\n\t\t\t{\n\t\t\t\tuint r = i;\n\t\t\t\tfor (int j = 0; j < 8; j++)\n\t\t\t\t\tif ((r & 1) != 0)\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\n\t\t\t\t\telse\n\t\t\t\t\t\tr >>= 1;\n\t\t\t\tTable[i] = r;\n\t\t\t}\n\t\t}\n\n\t\tuint _value = 0xFFFFFFFF;\n\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\n\n\t\tpublic void UpdateByte(byte b)\n\t\t{\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\n\t\t}\n\n\t\tpublic void Update(byte[] data, uint offset, uint size)\n\t\t{\n\t\t\tfor (uint i = 0; i < size; i++)\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\n\t\t}\n\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\n\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\n\t\t{\n\t\t\tCRC crc = new CRC();\n\t\t\t// crc.Init();\n\t\t\tcrc.Update(data, offset, size);\n\t\t\treturn crc.GetDigest();\n\t\t}\n\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\n\t\t{\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\n\nusing System;\nusing System.Collections;\n\nnamespace SevenZip.CommandLineParser\n{\n\tpublic enum SwitchType\n\t{\n\t\tSimple,\n\t\tPostMinus,\n\t\tLimitedPostString,\n\t\tUnLimitedPostString,\n\t\tPostChar\n\t}\n\n\tpublic class SwitchForm\n\t{\n\t\tpublic string IDString;\n\t\tpublic SwitchType Type;\n\t\tpublic bool Multi;\n\t\tpublic int MinLen;\n\t\tpublic int MaxLen;\n\t\tpublic string PostCharSet;\n\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\n\t\t\tint minLen, int maxLen, string postCharSet)\n\t\t{\n\t\t\tIDString = idString;\n\t\t\tType = type;\n\t\t\tMulti = multi;\n\t\t\tMinLen = minLen;\n\t\t\tMaxLen = maxLen;\n\t\t\tPostCharSet = postCharSet;\n\t\t}\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\n\t\t{\n\t\t}\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\n\t\t\tthis(idString, type, multi, 0)\n\t\t{\n\t\t}\n\t}\n\n\tpublic class SwitchResult\n\t{\n\t\tpublic bool ThereIs;\n\t\tpublic bool WithMinus;\n\t\tpublic ArrayList PostStrings = new ArrayList();\n\t\tpublic int PostCharIndex;\n\t\tpublic SwitchResult()\n\t\t{\n\t\t\tThereIs = false;\n\t\t}\n\t}\n\n\tpublic class Parser\n\t{\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\n\t\tSwitchResult[] _switches;\n\n\t\tpublic Parser(int numSwitches)\n\t\t{\n\t\t\t_switches = new SwitchResult[numSwitches];\n\t\t\tfor (int i = 0; i < numSwitches; i++)\n\t\t\t\t_switches[i] = new SwitchResult();\n\t\t}\n\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\n\t\t{\n\t\t\tint len = srcString.Length;\n\t\t\tif (len == 0)\n\t\t\t\treturn false;\n\t\t\tint pos = 0;\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\n\t\t\t\treturn false;\n\t\t\twhile (pos < len)\n\t\t\t{\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\n\t\t\t\t\tpos++;\n\t\t\t\tconst int kNoLen = -1;\n\t\t\t\tint matchedSwitchIndex = 0;\n\t\t\t\tint maxLen = kNoLen;\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\n\t\t\t\t{\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\n\t\t\t\t\t\tmaxLen = switchLen;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (maxLen == kNoLen)\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\n\t\t\t\tmatchedSwitch.ThereIs = true;\n\t\t\t\tpos += maxLen;\n\t\t\t\tint tailSize = len - pos;\n\t\t\t\tSwitchType type = switchForm.Type;\n\t\t\t\tswitch (type)\n\t\t\t\t{\n\t\t\t\t\tcase SwitchType.PostMinus:\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (tailSize == 0)\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\n\t\t\t\t\t\t\t\t\tpos++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\tcase SwitchType.PostChar:\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\n\t\t\t\t\t\t\tif (tailSize == 0)\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\n\t\t\t\t\t\t\t\tif (index < 0)\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\n\t\t\t\t\t\t\t\t\tpos++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\tcase SwitchType.LimitedPostString:\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\n\t\t\t\t\t\t\tif (tailSize < minLen)\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\n\t\t\t\t\t\t\tpos += minLen;\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tstringSwitch += c;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\n\t\t}\n\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\n\t\t{\n\t\t\tint numCommandStrings = commandStrings.Length;\n\t\t\tbool stopSwitch = false;\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\n\t\t\t{\n\t\t\t\tstring s = commandStrings[i];\n\t\t\t\tif (stopSwitch)\n\t\t\t\t\tNonSwitchStrings.Add(s);\n\t\t\t\telse\n\t\t\t\t\tif (s == kStopSwitchParsing)\n\t\t\t\t\tstopSwitch = true;\n\t\t\t\telse\n\t\t\t\t\tif (!ParseString(s, switchForms))\n\t\t\t\t\tNonSwitchStrings.Add(s);\n\t\t\t}\n\t\t}\n\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\n\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\n\t\t\tout string postString)\n\t\t{\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\n\t\t\t{\n\t\t\t\tstring id = commandForms[i].IDString;\n\t\t\t\tif (commandForms[i].PostStringMode)\n\t\t\t\t{\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\n\t\t\t\t\t\treturn i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tif (commandString == id)\n\t\t\t\t{\n\t\t\t\t\tpostString = \"\";\n\t\t\t\t\treturn i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpostString = \"\";\n\t\t\treturn -1;\n\t\t}\n\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\n\t\t\tstring commandString, ArrayList indices)\n\t\t{\n\t\t\tindices.Clear();\n\t\t\tint numUsedChars = 0;\n\t\t\tfor (int i = 0; i < numForms; i++)\n\t\t\t{\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\n\t\t\t\tint currentIndex = -1;\n\t\t\t\tint len = charsSet.Chars.Length;\n\t\t\t\tfor (int j = 0; j < len; j++)\n\t\t\t\t{\n\t\t\t\t\tchar c = charsSet.Chars[j];\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\n\t\t\t\t\tif (newIndex >= 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (currentIndex >= 0)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\tcurrentIndex = j;\n\t\t\t\t\t\tnumUsedChars++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\n\t\t\t\t\treturn false;\n\t\t\t\tindices.Add(currentIndex);\n\t\t\t}\n\t\t\treturn (numUsedChars == commandString.Length);\n\t\t}\n\t\tconst char kSwitchID1 = '-';\n\t\tconst char kSwitchID2 = '/';\n\n\t\tconst char kSwitchMinus = '-';\n\t\tconst string kStopSwitchParsing = \"--\";\n\n\t\tstatic bool IsItSwitchChar(char c)\n\t\t{\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\n\t\t}\n\t}\n\n\tpublic class CommandForm\n\t{\n\t\tpublic string IDString = \"\";\n\t\tpublic bool PostStringMode = false;\n\t\tpublic CommandForm(string idString, bool postStringMode)\n\t\t{\n\t\t\tIDString = idString;\n\t\t\tPostStringMode = postStringMode;\n\t\t}\n\t}\n\n\tclass CommandSubCharsSet\n\t{\n\t\tpublic string Chars = \"\";\n\t\tpublic bool EmptyAllowed = false;\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\n\nnamespace SevenZip.Buffer\n{\n\tpublic class InBuffer\n\t{\n\t\tbyte[] m_Buffer;\n\t\tuint m_Pos;\n\t\tuint m_Limit;\n\t\tuint m_BufferSize;\n\t\tSystem.IO.Stream m_Stream;\n\t\tbool m_StreamWasExhausted;\n\t\tulong m_ProcessedSize;\n\n\t\tpublic InBuffer(uint bufferSize)\n\t\t{\n\t\t\tm_Buffer = new byte[bufferSize];\n\t\t\tm_BufferSize = bufferSize;\n\t\t}\n\n\t\tpublic void Init(System.IO.Stream stream)\n\t\t{\n\t\t\tm_Stream = stream;\n\t\t\tm_ProcessedSize = 0;\n\t\t\tm_Limit = 0;\n\t\t\tm_Pos = 0;\n\t\t\tm_StreamWasExhausted = false;\n\t\t}\n\n\t\tpublic bool ReadBlock()\n\t\t{\n\t\t\tif (m_StreamWasExhausted)\n\t\t\t\treturn false;\n\t\t\tm_ProcessedSize += m_Pos;\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\n\t\t\tm_Pos = 0;\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\n\t\t\treturn (!m_StreamWasExhausted);\n\t\t}\n\n\n\t\tpublic void ReleaseStream()\n\t\t{\n\t\t\t// m_Stream.Close(); \n\t\t\tm_Stream = null;\n\t\t}\n\n\t\tpublic bool ReadByte(byte b) // check it\n\t\t{\n\t\t\tif (m_Pos >= m_Limit)\n\t\t\t\tif (!ReadBlock())\n\t\t\t\t\treturn false;\n\t\t\tb = m_Buffer[m_Pos++];\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic byte ReadByte()\n\t\t{\n\t\t\t// return (byte)m_Stream.ReadByte();\n\t\t\tif (m_Pos >= m_Limit)\n\t\t\t\tif (!ReadBlock())\n\t\t\t\t\treturn 0xFF;\n\t\t\treturn m_Buffer[m_Pos++];\n\t\t}\n\n\t\tpublic ulong GetProcessedSize()\n\t\t{\n\t\t\treturn m_ProcessedSize + m_Pos;\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\n\nnamespace SevenZip.Buffer\n{\n\tpublic class OutBuffer\n\t{\n\t\tbyte[] m_Buffer;\n\t\tuint m_Pos;\n\t\tuint m_BufferSize;\n\t\tSystem.IO.Stream m_Stream;\n\t\tulong m_ProcessedSize;\n\n\t\tpublic OutBuffer(uint bufferSize)\n\t\t{\n\t\t\tm_Buffer = new byte[bufferSize];\n\t\t\tm_BufferSize = bufferSize;\n\t\t}\n\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\n\t\tpublic void CloseStream() { m_Stream.Close(); }\n\t\tpublic void ReleaseStream() { m_Stream = null; }\n\n\t\tpublic void Init()\n\t\t{\n\t\t\tm_ProcessedSize = 0;\n\t\t\tm_Pos = 0;\n\t\t}\n\n\t\tpublic void WriteByte(byte b)\n\t\t{\n\t\t\tm_Buffer[m_Pos++] = b;\n\t\t\tif (m_Pos >= m_BufferSize)\n\t\t\t\tFlushData();\n\t\t}\n\n\t\tpublic void FlushData()\n\t\t{\n\t\t\tif (m_Pos == 0)\n\t\t\t\treturn;\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\n\t\t\tm_Pos = 0;\n\t\t}\n\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\n\nusing System;\n\nnamespace SevenZip.Compression.LZ\n{\n\tinterface IInWindowStream\n\t{\n\t\tvoid SetStream(System.IO.Stream inStream);\n\t\tvoid Init();\n\t\tvoid ReleaseStream();\n\t\tByte GetIndexByte(Int32 index);\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\n\t\tUInt32 GetNumAvailableBytes();\n\t}\n\n\tinterface IMatchFinder : IInWindowStream\n\t{\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\n\t\tUInt32 GetMatches(UInt32[] distances);\n\t\tvoid Skip(UInt32 num);\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\n\nusing System;\n\nnamespace SevenZip.Compression.LZ\n{\n\tpublic class BinTree : InWindow, IMatchFinder\n\t{\n\t\tUInt32 _cyclicBufferPos;\n\t\tUInt32 _cyclicBufferSize = 0;\n\t\tUInt32 _matchMaxLen;\n\n\t\tUInt32[] _son;\n\t\tUInt32[] _hash;\n\n\t\tUInt32 _cutValue = 0xFF;\n\t\tUInt32 _hashMask;\n\t\tUInt32 _hashSizeSum = 0;\n\n\t\tbool HASH_ARRAY = true;\n\n\t\tconst UInt32 kHash2Size = 1 << 10;\n\t\tconst UInt32 kHash3Size = 1 << 16;\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\n\t\tconst UInt32 kStartMaxLen = 1;\n\t\tconst UInt32 kHash3Offset = kHash2Size;\n\t\tconst UInt32 kEmptyHashValue = 0;\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\n\t\n\t\tUInt32 kNumHashDirectBytes = 0;\n\t\tUInt32 kMinMatchCheck = 4;\n\t\tUInt32 kFixHashSize = kHash2Size + kHash3Size;\n\t\t\n\t\tpublic void SetType(int numHashBytes)\n\t\t{\n\t\t\tHASH_ARRAY = (numHashBytes > 2);\n\t\t\tif (HASH_ARRAY)\n\t\t\t{\n\t\t\t\tkNumHashDirectBytes = 0;\n\t\t\t\tkMinMatchCheck = 4;\n\t\t\t\tkFixHashSize = kHash2Size + kHash3Size;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tkNumHashDirectBytes = 2;\n\t\t\t\tkMinMatchCheck = 2 + 1;\n\t\t\t\tkFixHashSize = 0;\n\t\t\t}\n\t\t}\n\n\t\tpublic new void SetStream(System.IO.Stream stream) { base.SetStream(stream); }\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\n\t\t\n\t\tpublic new void Init()\n\t\t{\n\t\t\tbase.Init();\n\t\t\tfor (UInt32 i = 0; i < _hashSizeSum; i++)\n\t\t\t\t_hash[i] = kEmptyHashValue;\n\t\t\t_cyclicBufferPos = 0;\n\t\t\tReduceOffsets(-1);\n\t\t}\n\n\t\tpublic new void MovePos()\n\t\t{\n\t\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\n\t\t\t\t_cyclicBufferPos = 0;\n\t\t\tbase.MovePos();\n\t\t\tif (_pos == kMaxValForNormalize)\n\t\t\t\tNormalize();\n\t\t}\n\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\n\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\n\t\t{ return base.GetMatchLen(index, distance, limit); }\n\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\n\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\n\t\t{\n\t\t\tif (historySize > kMaxValForNormalize - 256)\n\t\t\t\tthrow new Exception();\n\t\t\t_cutValue = 16 + (matchMaxLen >> 1);\n\t\t\t\t\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\n\t\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\n\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\n\n\t\t\t_matchMaxLen = matchMaxLen;\n\n\t\t\tUInt32 cyclicBufferSize = historySize + 1;\n\t\t\tif (_cyclicBufferSize != cyclicBufferSize)\n\t\t\t\t_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];\n\n\t\t\tUInt32 hs = kBT2HashSize;\n\n\t\t\tif (HASH_ARRAY)\n\t\t\t{\n\t\t\t\ths = historySize - 1;\n\t\t\t\ths |= (hs >> 1);\n\t\t\t\ths |= (hs >> 2);\n\t\t\t\ths |= (hs >> 4);\n\t\t\t\ths |= (hs >> 8);\n\t\t\t\ths >>= 1;\n\t\t\t\ths |= 0xFFFF;\n\t\t\t\tif (hs > (1 << 24))\n\t\t\t\t\ths >>= 1;\n\t\t\t\t_hashMask = hs;\n\t\t\t\ths++;\n\t\t\t\ths += kFixHashSize;\n\t\t\t}\n\t\t\tif (hs != _hashSizeSum)\n\t\t\t\t_hash = new UInt32[_hashSizeSum = hs];\n\t\t}\n\n\t\tpublic UInt32 GetMatches(UInt32[] distances)\n\t\t{\n\t\t\tUInt32 lenLimit;\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\n\t\t\t\tlenLimit = _matchMaxLen;\n\t\t\telse\n\t\t\t{\n\t\t\t\tlenLimit = _streamPos - _pos;\n\t\t\t\tif (lenLimit < kMinMatchCheck)\n\t\t\t\t{\n\t\t\t\t\tMovePos();\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tUInt32 offset = 0;\n\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\n\t\t\tUInt32 cur = _bufferOffset + _pos;\n\t\t\tUInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\n\n\t\t\tif (HASH_ARRAY)\n\t\t\t{\n\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\n\t\t\t\thash2Value = temp & (kHash2Size - 1);\n\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\n\t\t\t\thash3Value = temp & (kHash3Size - 1);\n\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\n\t\t\t}\n\t\t\telse\n\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\n\n\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\n\t\t\tif (HASH_ARRAY)\n\t\t\t{\n\t\t\t\tUInt32 curMatch2 = _hash[hash2Value];\n\t\t\t\tUInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\n\t\t\t\t_hash[hash2Value] = _pos;\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\n\t\t\t\tif (curMatch2 > matchMinPos)\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\n\t\t\t\t\t{\n\t\t\t\t\t\tdistances[offset++] = maxLen = 2;\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\n\t\t\t\t\t}\n\t\t\t\tif (curMatch3 > matchMinPos)\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\n\t\t\t\t\t{\n\t\t\t\t\t\tif (curMatch3 == curMatch2)\n\t\t\t\t\t\t\toffset -= 2;\n\t\t\t\t\t\tdistances[offset++] = maxLen = 3;\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\n\t\t\t\t\t\tcurMatch2 = curMatch3;\n\t\t\t\t\t}\n\t\t\t\tif (offset != 0 && curMatch2 == curMatch)\n\t\t\t\t{\n\t\t\t\t\toffset -= 2;\n\t\t\t\t\tmaxLen = kStartMaxLen;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\n\n\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\n\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\n\n\t\t\tUInt32 len0, len1;\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\n\t\t\t\n\t\t\tif (kNumHashDirectBytes != 0)\n\t\t\t{\n\t\t\t\tif (curMatch > matchMinPos)\n\t\t\t\t{\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\n\t\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\n\t\t\t\t\t{\n\t\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\n\t\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tUInt32 count = _cutValue;\n\t\t\t\n\t\t\twhile(true)\n\t\t\t{\n\t\t\t\tif(curMatch <= matchMinPos || count-- == 0)\n\t\t\t\t{\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tUInt32 delta = _pos - curMatch;\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\n\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\n\t\t\t\tUInt32 len = Math.Min(len0, len1);\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\n\t\t\t\t{\n\t\t\t\t\twhile(++len != lenLimit)\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\tif (maxLen < len)\n\t\t\t\t\t{\n\t\t\t\t\t\tdistances[offset++] = maxLen = len;\n\t\t\t\t\t\tdistances[offset++] = delta - 1;\n\t\t\t\t\t\tif (len == lenLimit)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\n\t\t\t\t{\n\t\t\t\t\t_son[ptr1] = curMatch;\n\t\t\t\t\tptr1 = cyclicPos + 1;\n\t\t\t\t\tcurMatch = _son[ptr1];\n\t\t\t\t\tlen1 = len;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t_son[ptr0] = curMatch;\n\t\t\t\t\tptr0 = cyclicPos;\n\t\t\t\t\tcurMatch = _son[ptr0];\n\t\t\t\t\tlen0 = len;\n\t\t\t\t}\n\t\t\t}\n\t\t\tMovePos();\n\t\t\treturn offset;\n\t\t}\n\n\t\tpublic void Skip(UInt32 num)\n\t\t{\n\t\t\tdo\n\t\t\t{\n\t\t\t\tUInt32 lenLimit;\n\t\t\t\tif (_pos + _matchMaxLen <= _streamPos)\n\t\t\t\t\tlenLimit = _matchMaxLen;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlenLimit = _streamPos - _pos;\n\t\t\t\t\tif (lenLimit < kMinMatchCheck)\n\t\t\t\t\t{\n\t\t\t\t\t\tMovePos();\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tUInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\n\t\t\t\tUInt32 cur = _bufferOffset + _pos;\n\n\t\t\t\tUInt32 hashValue;\n\n\t\t\t\tif (HASH_ARRAY)\n\t\t\t\t{\n\t\t\t\t\tUInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];\n\t\t\t\t\tUInt32 hash2Value = temp & (kHash2Size - 1);\n\t\t\t\t\t_hash[hash2Value] = _pos;\n\t\t\t\t\ttemp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);\n\t\t\t\t\tUInt32 hash3Value = temp & (kHash3Size - 1);\n\t\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\n\t\t\t\t\thashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\thashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);\n\n\t\t\t\tUInt32 curMatch = _hash[kFixHashSize + hashValue];\n\t\t\t\t_hash[kFixHashSize + hashValue] = _pos;\n\n\t\t\t\tUInt32 ptr0 = (_cyclicBufferPos << 1) + 1;\n\t\t\t\tUInt32 ptr1 = (_cyclicBufferPos << 1);\n\n\t\t\t\tUInt32 len0, len1;\n\t\t\t\tlen0 = len1 = kNumHashDirectBytes;\n\n\t\t\t\tUInt32 count = _cutValue;\n\t\t\t\twhile (true)\n\t\t\t\t{\n\t\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tUInt32 delta = _pos - curMatch;\n\t\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\n\t\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\n\n\t\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\n\t\t\t\t\tUInt32 len = Math.Min(len0, len1);\n\t\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\n\t\t\t\t\t{\n\t\t\t\t\t\twhile (++len != lenLimit)\n\t\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tif (len == lenLimit)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\n\t\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (_bufferBase[pby1 + len] < _bufferBase[cur + len])\n\t\t\t\t\t{\n\t\t\t\t\t\t_son[ptr1] = curMatch;\n\t\t\t\t\t\tptr1 = cyclicPos + 1;\n\t\t\t\t\t\tcurMatch = _son[ptr1];\n\t\t\t\t\t\tlen1 = len;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t_son[ptr0] = curMatch;\n\t\t\t\t\t\tptr0 = cyclicPos;\n\t\t\t\t\t\tcurMatch = _son[ptr0];\n\t\t\t\t\t\tlen0 = len;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tMovePos();\n\t\t\t}\n\t\t\twhile (--num != 0);\n\t\t}\n\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\n\t\t{\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\n\t\t\t{\n\t\t\t\tUInt32 value = items[i];\n\t\t\t\tif (value <= subValue)\n\t\t\t\t\tvalue = kEmptyHashValue;\n\t\t\t\telse\n\t\t\t\t\tvalue -= subValue;\n\t\t\t\titems[i] = value;\n\t\t\t}\n\t\t}\n\n\t\tvoid Normalize()\n\t\t{\n\t\t\tUInt32 subValue = _pos - _cyclicBufferSize;\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\n\t\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\n\t\t\tReduceOffsets((Int32)subValue);\n\t\t}\n\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\n\nusing System;\n\nnamespace SevenZip.Compression.LZ\n{\n\tpublic class InWindow\n\t{\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\n\t\tSystem.IO.Stream _stream;\n\t\tUInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\n\n\t\tUInt32 _pointerToLastSafePosition;\n\n\t\tpublic UInt32 _bufferOffset;\n\n\t\tpublic UInt32 _blockSize; // Size of Allocated memory block\n\t\tpublic UInt32 _pos; // offset (from _buffer) of curent byte\n\t\tUInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos\n\t\tUInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos\n\t\tpublic UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream\n\n\t\tpublic void MoveBlock()\n\t\t{\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\n\t\t\t// we need one additional byte, since MovePos moves on 1 byte.\n\t\t\tif (offset > 0)\n\t\t\t\toffset--;\n\t\t\t\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\n\n\t\t\t// check negative offset ????\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\n\t\t\t_bufferOffset -= offset;\n\t\t}\n\n\t\tpublic virtual void ReadBlock()\n\t\t{\n\t\t\tif (_streamEndWasReached)\n\t\t\t\treturn;\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\n\t\t\t\tif (size == 0)\n\t\t\t\t\treturn;\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\n\t\t\t\tif (numReadBytes == 0)\n\t\t\t\t{\n\t\t\t\t\t_posLimit = _streamPos;\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\n\n\t\t\t\t\t_streamEndWasReached = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\n\t\t\t}\n\t\t}\n\n\t\tvoid Free() { _bufferBase = null; }\n\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\n\t\t{\n\t\t\t_keepSizeBefore = keepSizeBefore;\n\t\t\t_keepSizeAfter = keepSizeAfter;\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\n\t\t\t{\n\t\t\t\tFree();\n\t\t\t\t_blockSize = blockSize;\n\t\t\t\t_bufferBase = new Byte[_blockSize];\n\t\t\t}\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\n\t\t}\n\n\t\tpublic void SetStream(System.IO.Stream stream) { _stream = stream; }\n\t\tpublic void ReleaseStream() { _stream = null; }\n\n\t\tpublic void Init()\n\t\t{\n\t\t\t_bufferOffset = 0;\n\t\t\t_pos = 0;\n\t\t\t_streamPos = 0;\n\t\t\t_streamEndWasReached = false;\n\t\t\tReadBlock();\n\t\t}\n\n\t\tpublic void MovePos()\n\t\t{\n\t\t\t_pos++;\n\t\t\tif (_pos > _posLimit)\n\t\t\t{\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\n\t\t\t\t\tMoveBlock();\n\t\t\t\tReadBlock();\n\t\t\t}\n\t\t}\n\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\n\n\t\t// index + limit have not to exceed _keepSizeAfter;\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\n\t\t{\n\t\t\tif (_streamEndWasReached)\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\n\t\t\tdistance++;\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\n\n\t\t\tUInt32 i;\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\n\t\t\treturn i;\n\t\t}\n\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\n\n\t\tpublic void ReduceOffsets(Int32 subValue)\n\t\t{\n\t\t\t_bufferOffset += (UInt32)subValue;\n\t\t\t_posLimit -= (UInt32)subValue;\n\t\t\t_pos -= (UInt32)subValue;\n\t\t\t_streamPos -= (UInt32)subValue;\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\n\nnamespace SevenZip.Compression.LZ\n{\n\tpublic class OutWindow\n\t{\n\t\tbyte[] _buffer = null;\n\t\tuint _pos;\n\t\tuint _windowSize = 0;\n\t\tuint _streamPos;\n\t\tSystem.IO.Stream _stream;\n\n\t\tpublic uint TrainSize = 0;\n\n\t\tpublic void Create(uint windowSize)\n\t\t{\n\t\t\tif (_windowSize != windowSize)\n\t\t\t{\n\t\t\t\t// System.GC.Collect();\n\t\t\t\t_buffer = new byte[windowSize];\n\t\t\t}\n\t\t\t_windowSize = windowSize;\n\t\t\t_pos = 0;\n\t\t\t_streamPos = 0;\n\t\t}\n\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\n\t\t{\n\t\t\tReleaseStream();\n\t\t\t_stream = stream;\n\t\t\tif (!solid)\n\t\t\t{\n\t\t\t\t_streamPos = 0;\n\t\t\t\t_pos = 0;\n\t\t\t\tTrainSize = 0;\n\t\t\t}\n\t\t}\n\t\n\t\tpublic bool Train(System.IO.Stream stream)\n\t\t{\n\t\t\tlong len = stream.Length;\n\t\t\tuint size = (len < _windowSize) ? (uint)len : _windowSize;\n\t\t\tTrainSize = size;\n\t\t\tstream.Position = len - size;\n\t\t\t_streamPos = _pos = 0;\n\t\t\twhile (size > 0)\n\t\t\t{\n\t\t\t\tuint curSize = _windowSize - _pos;\n\t\t\t\tif (size < curSize)\n\t\t\t\t\tcurSize = size;\n\t\t\t\tint numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize);\n\t\t\t\tif (numReadBytes == 0)\n\t\t\t\t\treturn false;\n\t\t\t\tsize -= (uint)numReadBytes;\n\t\t\t\t_pos += (uint)numReadBytes;\n\t\t\t\t_streamPos += (uint)numReadBytes;\n\t\t\t\tif (_pos == _windowSize)\n\t\t\t\t\t_streamPos = _pos = 0;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic void ReleaseStream()\n\t\t{\n\t\t\tFlush();\n\t\t\t_stream = null;\n\t\t}\n\n\t\tpublic void Flush()\n\t\t{\n\t\t\tuint size = _pos - _streamPos;\n\t\t\tif (size == 0)\n\t\t\t\treturn;\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\n\t\t\tif (_pos >= _windowSize)\n\t\t\t\t_pos = 0;\n\t\t\t_streamPos = _pos;\n\t\t}\n\n\t\tpublic void CopyBlock(uint distance, uint len)\n\t\t{\n\t\t\tuint pos = _pos - distance - 1;\n\t\t\tif (pos >= _windowSize)\n\t\t\t\tpos += _windowSize;\n\t\t\tfor (; len > 0; len--)\n\t\t\t{\n\t\t\t\tif (pos >= _windowSize)\n\t\t\t\t\tpos = 0;\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\n\t\t\t\tif (_pos >= _windowSize)\n\t\t\t\t\tFlush();\n\t\t\t}\n\t\t}\n\n\t\tpublic void PutByte(byte b)\n\t\t{\n\t\t\t_buffer[_pos++] = b;\n\t\t\tif (_pos >= _windowSize)\n\t\t\t\tFlush();\n\t\t}\n\n\t\tpublic byte GetByte(uint distance)\n\t\t{\n\t\t\tuint pos = _pos - distance - 1;\n\t\t\tif (pos >= _windowSize)\n\t\t\t\tpos += _windowSize;\n\t\t\treturn _buffer[pos];\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\n\nnamespace SevenZip.Compression.LZMA\n{\n\tinternal abstract class Base\n\t{\n\t\tpublic const uint kNumRepDistances = 4;\n\t\tpublic const uint kNumStates = 12;\n\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\n\n\t\tpublic struct State\n\t\t{\n\t\t\tpublic uint Index;\n\t\t\tpublic void Init() { Index = 0; }\n\t\t\tpublic void UpdateChar()\n\t\t\t{\n\t\t\t\tif (Index < 4) Index = 0;\n\t\t\t\telse if (Index < 10) Index -= 3;\n\t\t\t\telse Index -= 6;\n\t\t\t}\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\n\t\t\tpublic bool IsCharState() { return Index < 7; }\n\t\t}\n\n\t\tpublic const int kNumPosSlotBits = 6;\n\t\tpublic const int kDicLogSizeMin = 0;\n\t\t// public const int kDicLogSizeMax = 30;\n\t\t// public const uint kDistTableSizeMax = kDicLogSizeMax * 2;\n\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\n\n\t\tpublic const uint kMatchMinLen = 2;\n\n\t\tpublic static uint GetLenToPosState(uint len)\n\t\t{\n\t\t\tlen -= kMatchMinLen;\n\t\t\tif (len < kNumLenToPosStates)\n\t\t\t\treturn len;\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\n\t\t}\n\n\t\tpublic const int kNumAlignBits = 4;\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\n\n\t\tpublic const uint kStartPosModelIndex = 4;\n\t\tpublic const uint kEndPosModelIndex = 14;\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\n\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\n\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\n\t\tpublic const uint kNumLitContextBitsMax = 8;\n\n\t\tpublic const int kNumPosStatesBitsMax = 4;\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\n\n\t\tpublic const int kNumLowLenBits = 3;\n\t\tpublic const int kNumMidLenBits = 3;\n\t\tpublic const int kNumHighLenBits = 8;\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\n\t\t\t\t(1 << kNumHighLenBits);\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\n\nusing System;\n\nnamespace SevenZip.Compression.LZMA\n{\n\tusing RangeCoder;\n\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\n\t{\n\t\tclass LenDecoder\n\t\t{\n\t\t\tBitDecoder m_Choice = new BitDecoder();\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\n\t\t\tuint m_NumPosStates = 0;\n\n\t\t\tpublic void Create(uint numPosStates)\n\t\t\t{\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\n\t\t\t\t{\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\n\t\t\t\t}\n\t\t\t\tm_NumPosStates = numPosStates;\n\t\t\t}\n\n\t\t\tpublic void Init()\n\t\t\t{\n\t\t\t\tm_Choice.Init();\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\n\t\t\t\t{\n\t\t\t\t\tm_LowCoder[posState].Init();\n\t\t\t\t\tm_MidCoder[posState].Init();\n\t\t\t\t}\n\t\t\t\tm_Choice2.Init();\n\t\t\t\tm_HighCoder.Init();\n\t\t\t}\n\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\n\t\t\t{\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\n\t\t\t\t\t}\n\t\t\t\t\treturn symbol;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tclass LiteralDecoder\n\t\t{\n\t\t\tstruct Decoder2\n\t\t\t{\n\t\t\t\tBitDecoder[] m_Decoders;\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\n\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\n\t\t\t\t{\n\t\t\t\t\tuint symbol = 1;\n\t\t\t\t\tdo\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\n\t\t\t\t\twhile (symbol < 0x100);\n\t\t\t\t\treturn (byte)symbol;\n\t\t\t\t}\n\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\n\t\t\t\t{\n\t\t\t\t\tuint symbol = 1;\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\n\t\t\t\t\t\tmatchByte <<= 1;\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\n\t\t\t\t\t\tif (matchBit != bit)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\twhile (symbol < 0x100)\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\twhile (symbol < 0x100);\n\t\t\t\t\treturn (byte)symbol;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tDecoder2[] m_Coders;\n\t\t\tint m_NumPrevBits;\n\t\t\tint m_NumPosBits;\n\t\t\tuint m_PosMask;\n\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\n\t\t\t{\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\n\t\t\t\t\tm_NumPosBits == numPosBits)\n\t\t\t\t\treturn;\n\t\t\t\tm_NumPosBits = numPosBits;\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\n\t\t\t\tm_NumPrevBits = numPrevBits;\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\n\t\t\t\tm_Coders = new Decoder2[numStates];\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\n\t\t\t\t\tm_Coders[i].Create();\n\t\t\t}\n\n\t\t\tpublic void Init()\n\t\t\t{\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\n\t\t\t\t\tm_Coders[i].Init();\n\t\t\t}\n\n\t\t\tuint GetState(uint pos, byte prevByte)\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\n\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\n\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\n\t\t};\n\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\n\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\n\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\n\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\n\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\n\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\n\n\t\tuint m_DictionarySize;\n\t\tuint m_DictionarySizeCheck;\n\n\t\tuint m_PosStateMask;\n\n\t\tpublic Decoder()\n\t\t{\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\n\t\t}\n\n\t\tvoid SetDictionarySize(uint dictionarySize)\n\t\t{\n\t\t\tif (m_DictionarySize != dictionarySize)\n\t\t\t{\n\t\t\t\tm_DictionarySize = dictionarySize;\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\n\t\t\t\tm_OutWindow.Create(blockSize);\n\t\t\t}\n\t\t}\n\n\t\tvoid SetLiteralProperties(int lp, int lc)\n\t\t{\n\t\t\tif (lp > 8)\n\t\t\t\tthrow new InvalidParamException();\n\t\t\tif (lc > 8)\n\t\t\t\tthrow new InvalidParamException();\n\t\t\tm_LiteralDecoder.Create(lp, lc);\n\t\t}\n\n\t\tvoid SetPosBitsProperties(int pb)\n\t\t{\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\n\t\t\t\tthrow new InvalidParamException();\n\t\t\tuint numPosStates = (uint)1 << pb;\n\t\t\tm_LenDecoder.Create(numPosStates);\n\t\t\tm_RepLenDecoder.Create(numPosStates);\n\t\t\tm_PosStateMask = numPosStates - 1;\n\t\t}\n\n\t\tbool _solid = false;\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\n\t\t{\n\t\t\tm_RangeDecoder.Init(inStream);\n\t\t\tm_OutWindow.Init(outStream, _solid);\n\n\t\t\tuint i;\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\n\t\t\t{\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\n\t\t\t\t{\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\n\t\t\t\t}\n\t\t\t\tm_IsRepDecoders[i].Init();\n\t\t\t\tm_IsRepG0Decoders[i].Init();\n\t\t\t\tm_IsRepG1Decoders[i].Init();\n\t\t\t\tm_IsRepG2Decoders[i].Init();\n\t\t\t}\n\n\t\t\tm_LiteralDecoder.Init();\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\n\t\t\t\tm_PosSlotDecoder[i].Init();\n\t\t\t// m_PosSpecDecoder.Init();\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\n\t\t\t\tm_PosDecoders[i].Init();\n\n\t\t\tm_LenDecoder.Init();\n\t\t\tm_RepLenDecoder.Init();\n\t\t\tm_PosAlignDecoder.Init();\n\t\t}\n\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\n\t\t{\n\t\t\tInit(inStream, outStream);\n\n\t\t\tBase.State state = new Base.State();\n\t\t\tstate.Init();\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\n\n\t\t\tUInt64 nowPos64 = 0;\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\n\t\t\tif (nowPos64 < outSize64)\n\t\t\t{\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\n\t\t\t\t\tthrow new DataErrorException();\n\t\t\t\tstate.UpdateChar();\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\n\t\t\t\tm_OutWindow.PutByte(b);\n\t\t\t\tnowPos64++;\n\t\t\t}\n\t\t\twhile (nowPos64 < outSize64)\n\t\t\t{\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\n\t\t\t\t\t// while(nowPos64 < next)\n\t\t\t\t{\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tbyte b;\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\n\t\t\t\t\t\tif (!state.IsCharState())\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\n\t\t\t\t\t\tstate.UpdateChar();\n\t\t\t\t\t\tnowPos64++;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tuint len;\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\n\t\t\t\t\t\t\t\t\tnowPos64++;\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tUInt32 distance;\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tdistance = rep1;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\trep2 = rep1;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\trep1 = rep0;\n\t\t\t\t\t\t\t\trep0 = distance;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\n\t\t\t\t\t\t\tstate.UpdateRep();\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trep3 = rep2;\n\t\t\t\t\t\t\trep2 = rep1;\n\t\t\t\t\t\t\trep1 = rep0;\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\n\t\t\t\t\t\t\tstate.UpdateMatch();\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\trep0 = posSlot;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tthrow new DataErrorException();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\n\t\t\t\t\t\tnowPos64 += len;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tm_OutWindow.Flush();\n\t\t\tm_OutWindow.ReleaseStream();\n\t\t\tm_RangeDecoder.ReleaseStream();\n\t\t}\n\n\t\tpublic void SetDecoderProperties(byte[] properties)\n\t\t{\n\t\t\tif (properties.Length < 5)\n\t\t\t\tthrow new InvalidParamException();\n\t\t\tint lc = properties[0] % 9;\n\t\t\tint remainder = properties[0] / 9;\n\t\t\tint lp = remainder % 5;\n\t\t\tint pb = remainder / 5;\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\n\t\t\t\tthrow new InvalidParamException();\n\t\t\tUInt32 dictionarySize = 0;\n\t\t\tfor (int i = 0; i < 4; i++)\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\n\t\t\tSetDictionarySize(dictionarySize);\n\t\t\tSetLiteralProperties(lp, lc);\n\t\t\tSetPosBitsProperties(pb);\n\t\t}\n\n\t\tpublic bool Train(System.IO.Stream stream)\n\t\t{\n\t\t\t_solid = true;\n\t\t\treturn m_OutWindow.Train(stream);\n\t\t}\n\n\t\t/*\n\t\tpublic override bool CanRead { get { return true; }}\n\t\tpublic override bool CanWrite { get { return true; }}\n\t\tpublic override bool CanSeek { get { return true; }}\n\t\tpublic override long Length { get { return 0; }}\n\t\tpublic override long Position\n\t\t{\n\t\t\tget { return 0;\t}\n\t\t\tset { }\n\t\t}\n\t\tpublic override void Flush() { }\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\n\t\t{\n\t\t}\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\tpublic override void SetLength(long value) {}\n\t\t*/\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\n\nusing System;\n\nnamespace SevenZip.Compression.LZMA\n{\n\tusing RangeCoder;\n\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\n\t{\n\t\tenum EMatchFinderType\n\t\t{\n\t\t\tBT2,\n\t\t\tBT4,\n\t\t};\n\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\n\n\t\tstatic Byte[] g_FastPos = new Byte[1 << 11];\n\n\t\tstatic Encoder()\n\t\t{\n\t\t\tconst Byte kFastSlots = 22;\n\t\t\tint c = 2;\n\t\t\tg_FastPos[0] = 0;\n\t\t\tg_FastPos[1] = 1;\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\n\t\t\t{\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\n\t\t\t\t\tg_FastPos[c] = slotFast;\n\t\t\t}\n\t\t}\n\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\n\t\t{\n\t\t\tif (pos < (1 << 11))\n\t\t\t\treturn g_FastPos[pos];\n\t\t\tif (pos < (1 << 21))\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 10] + 20);\n\t\t\treturn (UInt32)(g_FastPos[pos >> 20] + 40);\n\t\t}\n\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\n\t\t{\n\t\t\tif (pos < (1 << 17))\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\n\t\t\tif (pos < (1 << 27))\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 16] + 32);\n\t\t\treturn (UInt32)(g_FastPos[pos >> 26] + 52);\n\t\t}\n\n\t\tBase.State _state = new Base.State();\n\t\tByte _previousByte;\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\n\n\t\tvoid BaseInit()\n\t\t{\n\t\t\t_state.Init();\n\t\t\t_previousByte = 0;\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\n\t\t\t\t_repDistances[i] = 0;\n\t\t}\n\n\t\tconst int kDefaultDictionaryLogSize = 22;\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\n\n\t\tclass LiteralEncoder\n\t\t{\n\t\t\tpublic struct Encoder2\n\t\t\t{\n\t\t\t\tBitEncoder[] m_Encoders;\n\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\n\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\n\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\n\t\t\t\t{\n\t\t\t\t\tuint context = 1;\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\n\t\t\t\t\t{\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\n\t\t\t\t\t\tcontext = (context << 1) | bit;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\n\t\t\t\t{\n\t\t\t\t\tuint context = 1;\n\t\t\t\t\tbool same = true;\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\n\t\t\t\t\t{\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\n\t\t\t\t\t\tuint state = context;\n\t\t\t\t\t\tif (same)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\n\t\t\t\t\t\t\tsame = (matchBit == bit);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\n\t\t\t\t\t\tcontext = (context << 1) | bit;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\n\t\t\t\t{\n\t\t\t\t\tuint price = 0;\n\t\t\t\t\tuint context = 1;\n\t\t\t\t\tint i = 7;\n\t\t\t\t\tif (matchMode)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor (; i >= 0; i--)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\n\t\t\t\t\t\t\tif (matchBit != bit)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ti--;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (; i >= 0; i--)\n\t\t\t\t\t{\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\n\t\t\t\t\t\tcontext = (context << 1) | bit;\n\t\t\t\t\t}\n\t\t\t\t\treturn price;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tEncoder2[] m_Coders;\n\t\t\tint m_NumPrevBits;\n\t\t\tint m_NumPosBits;\n\t\t\tuint m_PosMask;\n\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\n\t\t\t{\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\n\t\t\t\t\treturn;\n\t\t\t\tm_NumPosBits = numPosBits;\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\n\t\t\t\tm_NumPrevBits = numPrevBits;\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\n\t\t\t\tm_Coders = new Encoder2[numStates];\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\n\t\t\t\t\tm_Coders[i].Create();\n\t\t\t}\n\n\t\t\tpublic void Init()\n\t\t\t{\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\n\t\t\t\t\tm_Coders[i].Init();\n\t\t\t}\n\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\n\t\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits))]; }\n\t\t}\n\n\t\tclass LenEncoder\n\t\t{\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax];\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\n\n\t\t\tpublic LenEncoder()\n\t\t\t{\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\n\t\t\t\t{\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic void Init(UInt32 numPosStates)\n\t\t\t{\n\t\t\t\t_choice.Init();\n\t\t\t\t_choice2.Init();\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\n\t\t\t\t{\n\t\t\t\t\t_lowCoder[posState].Init();\n\t\t\t\t\t_midCoder[posState].Init();\n\t\t\t\t}\n\t\t\t\t_highCoder.Init();\n\t\t\t}\n\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\n\t\t\t{\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\n\t\t\t\t{\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\n\t\t\t\t\t{\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32[] prices, UInt32 st)\n\t\t\t{\n\t\t\t\tUInt32 a0 = _choice.GetPrice0();\n\t\t\t\tUInt32 a1 = _choice.GetPrice1();\n\t\t\t\tUInt32 b0 = a1 + _choice2.GetPrice0();\n\t\t\t\tUInt32 b1 = a1 + _choice2.GetPrice1();\n\t\t\t\tUInt32 i = 0;\n\t\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\n\t\t\t\t{\n\t\t\t\t\tif (i >= numSymbols)\n\t\t\t\t\t\treturn;\n\t\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\n\t\t\t\t}\n\t\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\n\t\t\t\t{\n\t\t\t\t\tif (i >= numSymbols)\n\t\t\t\t\t\treturn;\n\t\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\n\t\t\t\t}\n\t\t\t\tfor (; i < numSymbols; i++)\n\t\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\n\t\t\t}\n\t\t};\n\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\n\n\t\tclass LenPriceTableEncoder : LenEncoder\n\t\t{\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\n\t\t\tUInt32 _tableSize;\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\n\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\n\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\n\t\t\t{\n\t\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\n\t\t\t}\n\n\t\t\tvoid UpdateTable(UInt32 posState)\n\t\t\t{\n\t\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\n\t\t\t\t_counters[posState] = _tableSize;\n\t\t\t}\n\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\n\t\t\t{\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\n\t\t\t\t\tUpdateTable(posState);\n\t\t\t}\n\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\n\t\t\t{\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\n\t\t\t\tif (--_counters[posState] == 0)\n\t\t\t\t\tUpdateTable(posState);\n\t\t\t}\n\t\t}\n\n\t\tconst UInt32 kNumOpts = 1 << 12;\n\t\tclass Optimal\n\t\t{\n\t\t\tpublic Base.State State;\n\n\t\t\tpublic bool Prev1IsChar;\n\t\t\tpublic bool Prev2;\n\n\t\t\tpublic UInt32 PosPrev2;\n\t\t\tpublic UInt32 BackPrev2;\n\n\t\t\tpublic UInt32 Price;\n\t\t\tpublic UInt32 PosPrev;\n\t\t\tpublic UInt32 BackPrev;\n\n\t\t\tpublic UInt32 Backs0;\n\t\t\tpublic UInt32 Backs1;\n\t\t\tpublic UInt32 Backs2;\n\t\t\tpublic UInt32 Backs3;\n\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\n\t\t};\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\n\t\tLZ.IMatchFinder _matchFinder = null;\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\n\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\n\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates];\n\t\t\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\n\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\n\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\n\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen * 2 + 2];\n\t\t\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\n\t\tUInt32 _longestMatchLength;\n\t\tUInt32 _numDistancePairs;\n\n\t\tUInt32 _additionalOffset;\n\n\t\tUInt32 _optimumEndIndex;\n\t\tUInt32 _optimumCurrentIndex;\n\n\t\tbool _longestMatchWasFound;\n\n\t\tUInt32[] _posSlotPrices = new UInt32[1 << (Base.kNumPosSlotBits + Base.kNumLenToPosStatesBits)];\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\n\t\tUInt32 _alignPriceCount;\n\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\n\n\t\tint _posStateBits = 2;\n\t\tUInt32 _posStateMask = (4 - 1);\n\t\tint _numLiteralPosStateBits = 0;\n\t\tint _numLiteralContextBits = 3;\n\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\n\n\t\tInt64 nowPos64;\n\t\tbool _finished;\n\t\tSystem.IO.Stream _inStream;\n\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\n\t\tbool _writeEndMark = false;\n\t\t\n\t\tbool _needReleaseMFStream;\n\n\t\tvoid Create()\n\t\t{\n\t\t\tif (_matchFinder == null)\n\t\t\t{\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\n\t\t\t\tint numHashBytes = 4;\n\t\t\t\tif (_matchFinderType == EMatchFinderType.BT2)\n\t\t\t\t\tnumHashBytes = 2;\n\t\t\t\tbt.SetType(numHashBytes);\n\t\t\t\t_matchFinder = bt;\n\t\t\t}\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\n\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\n\t\t\t\treturn;\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\n\t\t\t_dictionarySizePrev = _dictionarySize;\n\t\t\t_numFastBytesPrev = _numFastBytes;\n\t\t}\n\n\t\tpublic Encoder()\n\t\t{\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\n\t\t\t\t_optimum[i] = new Optimal();\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\n\t\t}\n\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\n\t\t{\n\t\t\t_writeEndMark = writeEndMarker;\n\t\t}\n\n\t\tvoid Init()\n\t\t{\n\t\t\tBaseInit();\n\t\t\t_rangeEncoder.Init();\n\n\t\t\tuint i;\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\n\t\t\t{\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\n\t\t\t\t{\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\n\t\t\t\t\t_isMatch[complexState].Init();\n\t\t\t\t\t_isRep0Long[complexState].Init();\n\t\t\t\t}\n\t\t\t\t_isRep[i].Init();\n\t\t\t\t_isRepG0[i].Init();\n\t\t\t\t_isRepG1[i].Init();\n\t\t\t\t_isRepG2[i].Init();\n\t\t\t}\n\t\t\t_literalEncoder.Init();\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\n\t\t\t\t_posSlotEncoder[i].Init();\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\n\t\t\t\t_posEncoders[i].Init();\n\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\n\n\t\t\t_posAlignEncoder.Init();\n\n\t\t\t_longestMatchWasFound = false;\n\t\t\t_optimumEndIndex = 0;\n\t\t\t_optimumCurrentIndex = 0;\n\t\t\t_additionalOffset = 0;\n\t\t}\n\n\t\tvoid ReadMatchDistances(out UInt32 lenRes, out UInt32 numDistancePairs)\n\t\t{\n\t\t\tlenRes = 0;\n\t\t\tnumDistancePairs = _matchFinder.GetMatches(_matchDistances);\n\t\t\tif (numDistancePairs > 0)\n\t\t\t{\n\t\t\t\tlenRes = _matchDistances[numDistancePairs - 2];\n\t\t\t\tif (lenRes == _numFastBytes)\n\t\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1],\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\n\t\t\t}\n\t\t\t_additionalOffset++;\n\t\t}\n\n\n\t\tvoid MovePos(UInt32 num)\n\t\t{\n\t\t\tif (num > 0)\n\t\t\t{\n\t\t\t\t_matchFinder.Skip(num);\n\t\t\t\t_additionalOffset += num;\n\t\t\t}\n\t\t}\n\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\n\t\t{\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\n\t\t}\n\n\t\tUInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState)\n\t\t{\n\t\t\tUInt32 price;\n\t\t\tif (repIndex == 0)\n\t\t\t{\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice0();\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tprice = _isRepG0[state.Index].GetPrice1();\n\t\t\t\tif (repIndex == 1)\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn price;\n\t\t}\n\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\n\t\t{\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\n\t\t\treturn price + GetPureRepPrice(repIndex, state, posState);\n\t\t}\n\t\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\n\t\t{\n\t\t\tUInt32 price;\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\n\t\t\tif (pos < Base.kNumFullDistances)\n\t\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\n\t\t\telse\n\t\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\n\t\t}\n\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\n\t\t{\n\t\t\t_optimumEndIndex = cur;\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\n\t\t\t\t{\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\n\t\t\t\t\tif (_optimum[cur].Prev2)\n\t\t\t\t\t{\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tUInt32 posPrev = posMem;\n\t\t\t\tUInt32 backCur = backMem;\n\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\n\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\n\t\t\t\tcur = posPrev;\n\t\t\t}\n\t\t\twhile (cur > 0);\n\t\t\tbackRes = _optimum[0].BackPrev;\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\n\t\t\treturn _optimumCurrentIndex;\n\t\t}\n\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\n\n\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\n\t\t{\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\n\t\t\t{\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\n\t\t\t\treturn lenRes;\n\t\t\t}\n\t\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\n\n\t\t\tUInt32 lenMain, numDistancePairs;\n\t\t\tif (!_longestMatchWasFound)\n\t\t\t{\n\t\t\t\tReadMatchDistances(out lenMain, out numDistancePairs);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlenMain = _longestMatchLength;\n\t\t\t\tnumDistancePairs = _numDistancePairs;\n\t\t\t\t_longestMatchWasFound = false;\n\t\t\t}\n\n\t\t\tUInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\n\t\t\tif (numAvailableBytes < 2)\n\t\t\t{\n\t\t\t\tbackRes = 0xFFFFFFFF;\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif (numAvailableBytes > Base.kMatchMaxLen)\n\t\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\n\n\t\t\tUInt32 repMaxIndex = 0;\n\t\t\tUInt32 i;\t\t\t\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\n\t\t\t{\n\t\t\t\treps[i] = _repDistances[i];\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\n\t\t\t\tif (repLens[i] > repLens[repMaxIndex])\n\t\t\t\t\trepMaxIndex = i;\n\t\t\t}\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\n\t\t\t{\n\t\t\t\tbackRes = repMaxIndex;\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\n\t\t\t\tMovePos(lenRes - 1);\n\t\t\t\treturn lenRes;\n\t\t\t}\n\n\t\t\tif (lenMain >= _numFastBytes)\n\t\t\t{\n\t\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\n\t\t\t\tMovePos(lenMain - 1);\n\t\t\t\treturn lenMain;\n\t\t\t}\n\t\t\t\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\n\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\n\n\t\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\n\t\t\t{\n\t\t\t\tbackRes = (UInt32)0xFFFFFFFF;\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\t_optimum[0].State = _state;\n\n\t\t\tUInt32 posState = (position & _posStateMask);\n\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\n\t\t\t_optimum[1].MakeAsChar();\n\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\n\n\t\t\tif (matchByte == currentByte)\n\t\t\t{\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\n\t\t\t\t{\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tUInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\n\n\t\t\tif(lenEnd < 2)\n\t\t\t{\n\t\t\t\tbackRes = _optimum[1].BackPrev;\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\t\n\t\t\t_optimum[1].PosPrev = 0;\n\n\t\t\t_optimum[0].Backs0 = reps[0];\n\t\t\t_optimum[0].Backs1 = reps[1];\n\t\t\t_optimum[0].Backs2 = reps[2];\n\t\t\t_optimum[0].Backs3 = reps[3];\n\n\t\t\tUInt32 len = lenEnd;\n\t\t\tdo\n\t\t\t\t_optimum[len--].Price = kIfinityPrice;\n\t\t\twhile (len >= 2);\n\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\n\t\t\t{\n\t\t\t\tUInt32 repLen = repLens[i];\n\t\t\t\tif (repLen < 2)\n\t\t\t\t\tcontinue;\n\t\t\t\tUInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState);\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tUInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\n\t\t\t\t\tOptimal optimum = _optimum[repLen];\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t{\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\toptimum.PosPrev = 0;\n\t\t\t\t\t\toptimum.BackPrev = i;\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twhile (--repLen >= 2);\n\t\t\t}\n\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\n\t\t\t\n\t\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\n\t\t\tif (len <= lenMain)\n\t\t\t{\n\t\t\t\tUInt32 offs = 0;\n\t\t\t\twhile (len > _matchDistances[offs])\n\t\t\t\t\toffs += 2;\n\t\t\t\tfor (; ; len++)\n\t\t\t\t{\n\t\t\t\t\tUInt32 distance = _matchDistances[offs + 1];\n\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\n\t\t\t\t\tOptimal optimum = _optimum[len];\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t{\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\toptimum.PosPrev = 0;\n\t\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\n\t\t\t\t\t}\n\t\t\t\t\tif (len == _matchDistances[offs])\n\t\t\t\t\t{\n\t\t\t\t\t\toffs += 2;\n\t\t\t\t\t\tif (offs == numDistancePairs)\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tUInt32 cur = 0;\n\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tcur++;\n\t\t\t\tif (cur == lenEnd)\n\t\t\t\t\treturn Backward(out backRes, cur);\n\t\t\t\tUInt32 newLen;\n\t\t\t\tReadMatchDistances(out newLen, out numDistancePairs);\n\t\t\t\tif (newLen >= _numFastBytes)\n\t\t\t\t{\n\t\t\t\t\t_numDistancePairs = numDistancePairs;\n\t\t\t\t\t_longestMatchLength = newLen;\n\t\t\t\t\t_longestMatchWasFound = true;\n\t\t\t\t\treturn Backward(out backRes, cur);\n\t\t\t\t}\n\t\t\t\tposition++;\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\n\t\t\t\tBase.State state;\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\n\t\t\t\t{\n\t\t\t\t\tposPrev--;\n\t\t\t\t\tif (_optimum[cur].Prev2)\n\t\t\t\t\t{\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\n\t\t\t\t\t\t\tstate.UpdateRep();\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tstate.UpdateMatch();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\n\t\t\t\t\tstate.UpdateChar();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tstate = _optimum[posPrev].State;\n\t\t\t\tif (posPrev == cur - 1)\n\t\t\t\t{\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\n\t\t\t\t\t\tstate.UpdateShortRep();\n\t\t\t\t\telse\n\t\t\t\t\t\tstate.UpdateChar();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tUInt32 pos;\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\n\t\t\t\t\t{\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\n\t\t\t\t\t\tstate.UpdateRep();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\n\t\t\t\t\t\t\tstate.UpdateRep();\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tstate.UpdateMatch();\n\t\t\t\t\t}\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (pos == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (pos == 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (pos == 2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\n\t\t\t\t\t\treps[1] = opt.Backs0;\n\t\t\t\t\t\treps[2] = opt.Backs1;\n\t\t\t\t\t\treps[3] = opt.Backs2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_optimum[cur].State = state;\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\n\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\n\n\t\t\t\tposState = (position & _posStateMask);\n\n\t\t\t\tUInt32 curAnd1Price = curPrice +\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\n\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\n\n\t\t\t\tbool nextIsChar = false;\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\n\t\t\t\t{\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\n\t\t\t\t\tnextOptimum.PosPrev = cur;\n\t\t\t\t\tnextOptimum.MakeAsChar();\n\t\t\t\t\tnextIsChar = true;\n\t\t\t\t}\n\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\n\n\t\t\t\tif (matchByte == currentByte &&\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\n\t\t\t\t{\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\n\t\t\t\t\t{\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\n\t\t\t\t\t\tnextIsChar = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\n\t\t\t\tnumAvailableBytes = numAvailableBytesFull;\n\n\t\t\t\tif (numAvailableBytes < 2)\n\t\t\t\t\tcontinue;\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\n\t\t\t\tif (!nextIsChar && matchByte != currentByte)\n\t\t\t\t{\n\t\t\t\t\t// try Literal + rep0\n\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1, _numFastBytes);\n\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\n\t\t\t\t\tif (lenTest2 >= 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tBase.State state2 = state;\n\t\t\t\t\t\tstate2.UpdateChar();\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tUInt32 offset = cur + 1 + lenTest2;\n\t\t\t\t\t\t\twhile (lenEnd < offset)\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\n\t\t\t\t\t\t\tOptimal optimum = _optimum[offset];\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tUInt32 startLen = 2; // speed optimization \n\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\n\t\t\t\t{\n\t\t\t\t\tUInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\n\t\t\t\t\tif (lenTest < 2)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\n\t\t\t\t\tdo\n\t\t\t\t\t{\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\twhile(--lenTest >= 2);\n\t\t\t\t\tlenTest = lenTestTemp;\n\n\t\t\t\t\tif (repIndex == 0)\n\t\t\t\t\t\tstartLen = lenTest + 1;\n\n\t\t\t\t\t// if (_maxMode)\n\t\t\t\t\tif (lenTest < numAvailableBytesFull)\n\t\t\t\t\t{\n\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\n\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, reps[repIndex], t);\n\t\t\t\t\t\tif (lenTest2 >= 2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tBase.State state2 = state;\n\t\t\t\t\t\t\tstate2.UpdateRep();\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)(reps[repIndex] + 1))), \n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\n\t\t\t\t\t\t\tstate2.UpdateChar();\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (newLen > numAvailableBytes)\n\t\t\t\t{\n\t\t\t\t\tnewLen = numAvailableBytes;\n\t\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\n\t\t\t\t\t_matchDistances[numDistancePairs] = newLen;\n\t\t\t\t\tnumDistancePairs += 2;\n\t\t\t\t}\n\t\t\t\tif (newLen >= startLen)\n\t\t\t\t{\n\t\t\t\t\tnormalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0();\n\t\t\t\t\twhile (lenEnd < cur + newLen)\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\n\t\t\t\t\tUInt32 offs = 0;\n\t\t\t\t\twhile (startLen > _matchDistances[offs])\n\t\t\t\t\t\toffs += 2;\n\n\t\t\t\t\tfor (UInt32 lenTest = startLen; ; lenTest++)\n\t\t\t\t\t{\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[offs + 1];\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (lenTest == _matchDistances[offs])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tUInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\n\t\t\t\t\t\t\t\tUInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t);\n\t\t\t\t\t\t\t\tif (lenTest2 >= 2)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tBase.State state2 = state;\n\t\t\t\t\t\t\t\t\tstate2.UpdateMatch();\n\t\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\n\t\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\n\t\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\n\t\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\n\t\t\t\t\t\t\t\t\t\tGetPrice(true,\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)(curBack + 1) - 1),\n\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\n\t\t\t\t\t\t\t\t\tstate2.UpdateChar();\n\t\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\n\t\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\n\t\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\n\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\toffs += 2;\n\t\t\t\t\t\t\tif (offs == numDistancePairs)\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\n\t\t{\n\t\t\tconst int kDif = 7;\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\n\t\t}\n\n\t\tvoid WriteEndMarker(UInt32 posState)\n\t\t{\n\t\t\tif (!_writeEndMark)\n\t\t\t\treturn;\n\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\n\t\t\t_state.UpdateMatch();\n\t\t\tUInt32 len = Base.kMatchMinLen;\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\n\t\t\tint footerBits = 30;\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\n\t\t}\n\n\t\tvoid Flush(UInt32 nowPos)\n\t\t{\n\t\t\tReleaseMFStream();\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\n\t\t\t_rangeEncoder.FlushData();\n\t\t\t_rangeEncoder.FlushStream();\n\t\t}\n\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\n\t\t{\n\t\t\tinSize = 0;\n\t\t\toutSize = 0;\n\t\t\tfinished = true;\n\n\t\t\tif (_inStream != null)\n\t\t\t{\n\t\t\t\t_matchFinder.SetStream(_inStream);\n\t\t\t\t_matchFinder.Init();\n\t\t\t\t_needReleaseMFStream = true;\n\t\t\t\t_inStream = null;\n\t\t\t\tif (_trainSize > 0)\n\t\t\t\t\t_matchFinder.Skip(_trainSize);\n\t\t\t}\n\n\t\t\tif (_finished)\n\t\t\t\treturn;\n\t\t\t_finished = true;\n\n\n\t\t\tInt64 progressPosValuePrev = nowPos64;\n\t\t\tif (nowPos64 == 0)\n\t\t\t{\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\n\t\t\t\t{\n\t\t\t\t\tFlush((UInt32)nowPos64);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tUInt32 len, numDistancePairs; // it's not used\n\t\t\t\tReadMatchDistances(out len, out numDistancePairs);\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\n\t\t\t\t_state.UpdateChar();\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\n\t\t\t\t_previousByte = curByte;\n\t\t\t\t_additionalOffset--;\n\t\t\t\tnowPos64++;\n\t\t\t}\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\n\t\t\t{\n\t\t\t\tFlush((UInt32)nowPos64);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tUInt32 pos;\n\t\t\t\tUInt32 len = GetOptimum((UInt32)nowPos64, out pos);\n\t\t\t\t\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\n\t\t\t\t{\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\n\t\t\t\t\tif (!_state.IsCharState())\n\t\t\t\t\t{\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\n\t\t\t\t\t_previousByte = curByte;\n\t\t\t\t\t_state.UpdateChar();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\n\t\t\t\t\t{\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\n\t\t\t\t\t\tif (pos == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\n\t\t\t\t\t\t\tif (len == 1)\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\n\t\t\t\t\t\t\tif (pos == 1)\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (len == 1)\n\t\t\t\t\t\t\t_state.UpdateShortRep();\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\n\t\t\t\t\t\t\t_state.UpdateRep();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\n\t\t\t\t\t\tif (pos != 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\n\t\t\t\t\t\t\t_repDistances[0] = distance;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\n\t\t\t\t\t\t_state.UpdateMatch();\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\n\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\n\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\n\t\t\t\t\t\t\t\t_alignPriceCount++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tUInt32 distance = pos;\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\n\t\t\t\t\t\t_repDistances[0] = distance;\n\t\t\t\t\t\t_matchPriceCount++;\n\t\t\t\t\t}\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\n\t\t\t\t}\n\t\t\t\t_additionalOffset -= len;\n\t\t\t\tnowPos64 += len;\n\t\t\t\tif (_additionalOffset == 0)\n\t\t\t\t{\n\t\t\t\t\t// if (!_fastMode)\n\t\t\t\t\tif (_matchPriceCount >= (1 << 7))\n\t\t\t\t\t\tFillDistancesPrices();\n\t\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\n\t\t\t\t\t\tFillAlignPrices();\n\t\t\t\t\tinSize = nowPos64;\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\n\t\t\t\t\t{\n\t\t\t\t\t\t_finished = false;\n\t\t\t\t\t\tfinished = false;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid ReleaseMFStream()\n\t\t{\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\n\t\t\t{\n\t\t\t\t_matchFinder.ReleaseStream();\n\t\t\t\t_needReleaseMFStream = false;\n\t\t\t}\n\t\t}\n\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\n\n\t\tvoid ReleaseStreams()\n\t\t{\n\t\t\tReleaseMFStream();\n\t\t\tReleaseOutStream();\n\t\t}\n\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\n\t\t\t\tInt64 inSize, Int64 outSize)\n\t\t{\n\t\t\t_inStream = inStream;\n\t\t\t_finished = false;\n\t\t\tCreate();\n\t\t\tSetOutStream(outStream);\n\t\t\tInit();\n\n\t\t\t// if (!_fastMode)\n\t\t\t{\n\t\t\t\tFillDistancesPrices();\n\t\t\t\tFillAlignPrices();\n\t\t\t}\n\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\n\n\t\t\tnowPos64 = 0;\n\t\t}\n\n\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\n\t\t{\n\t\t\t_needReleaseMFStream = false;\n\t\t\ttry\n\t\t\t{\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\n\t\t\t\twhile (true)\n\t\t\t\t{\n\t\t\t\t\tInt64 processedInSize;\n\t\t\t\t\tInt64 processedOutSize;\n\t\t\t\t\tbool finished;\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\n\t\t\t\t\tif (finished)\n\t\t\t\t\t\treturn;\n\t\t\t\t\tif (progress != null)\n\t\t\t\t\t{\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinally\n\t\t\t{\n\t\t\t\tReleaseStreams();\n\t\t\t}\n\t\t}\n\n\t\tconst int kPropSize = 5;\n\t\tByte[] properties = new Byte[kPropSize];\n\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\n\t\t{\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\n\t\t\tfor (int i = 0; i < 4; i++)\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\n\t\t\toutStream.Write(properties, 0, kPropSize);\n\t\t}\n\t\t\n\t\tUInt32[] tempPrices = new UInt32[Base.kNumFullDistances];\n\t\tUInt32 _matchPriceCount;\n\n\t\tvoid FillDistancesPrices()\n\t\t{\n\t\t\tfor (UInt32 i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\n\t\t\t{ \n\t\t\t\tUInt32 posSlot = GetPosSlot(i);\n\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\n\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\n\t\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, \n\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\n\t\t\t}\n\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\n\t\t\t{\n\t\t\t\tUInt32 posSlot;\n\t\t\t\tRangeCoder.BitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\n\t\t\t\n\t\t\t\tUInt32 st = (lenToPosState << Base.kNumPosSlotBits);\n\t\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\n\t\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\n\t\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\n\t\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\n\n\t\t\t\tUInt32 st2 = lenToPosState * Base.kNumFullDistances;\n\t\t\t\tUInt32 i;\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\n\t\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\n\t\t\t}\n\t\t\t_matchPriceCount = 0;\n\t\t}\n\n\t\tvoid FillAlignPrices()\n\t\t{\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\n\t\t\t_alignPriceCount = 0;\n\t\t}\n\n\n\t\tstatic string[] kMatchFinderIDs = \n\t\t{\n\t\t\t\"BT2\",\n\t\t\t\"BT4\",\n\t\t};\n\n\t\tstatic int FindMatchFinder(string s)\n\t\t{\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\n\t\t\t\tif (s == kMatchFinderIDs[m])\n\t\t\t\t\treturn m;\n\t\t\treturn -1;\n\t\t}\n\t\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\n\t\t{\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\n\t\t\t{\n\t\t\t\tobject prop = properties[i];\n\t\t\t\tswitch (propIDs[i])\n\t\t\t\t{\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!(prop is Int32))\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\n\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase CoderPropID.Algorithm:\n\t\t\t\t\t{\n\t\t\t\t\t\t/*\n\t\t\t\t\t\tif (!(prop is Int32))\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\tInt32 maximize = (Int32)prop;\n\t\t\t\t\t\t_fastMode = (maximize == 0);\n\t\t\t\t\t\t_maxMode = (maximize >= 2);\n\t\t\t\t\t\t*/\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase CoderPropID.MatchFinder:\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!(prop is String))\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\n\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\n\t\t\t\t\t\tif (m < 0)\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\n\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\n\t\t\t\t\t\t\t_matchFinder = null;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase CoderPropID.DictionarySize:\n\t\t\t\t\t{\n\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 30;\n\t\t\t\t\t\tif (!(prop is Int32))\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\n\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\n\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\n\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\n\t\t\t\t\t\tint dicLogSize;\n\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\n\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase CoderPropID.PosStateBits:\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!(prop is Int32))\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\tInt32 v = (Int32)prop;\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\t_posStateBits = (int)v;\n\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase CoderPropID.LitPosBits:\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!(prop is Int32))\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\tInt32 v = (Int32)prop;\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase CoderPropID.LitContextBits:\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!(prop is Int32))\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\tInt32 v = (Int32)prop;\n\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\n\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\n\t\t\t\t\t\t_numLiteralContextBits = (int)v;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase CoderPropID.EndMarker:\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!(prop is Boolean))\n\t\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new InvalidParamException();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tuint _trainSize = 0;\n\t\tpublic void SetTrainSize(uint trainSize)\n\t\t{\n\t\t\t_trainSize = trainSize;\n\t\t}\n\t\t\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\nusing System.IO;\nnamespace SevenZip\n{\n\tusing CommandLineParser;\n\t\n\tpublic class CDoubleStream: Stream\n\t{\n\t\tpublic System.IO.Stream s1;\n\t\tpublic System.IO.Stream s2;\n\t\tpublic int fileIndex;\n\t\tpublic long skipSize;\n\t\t\n\t\tpublic override bool CanRead { get { return true; }}\n\t\tpublic override bool CanWrite { get { return false; }}\n\t\tpublic override bool CanSeek { get { return false; }}\n\t\tpublic override long Length { get { return s1.Length + s2.Length - skipSize; } }\n\t\tpublic override long Position\n\t\t{\n\t\t\tget { return 0;\t}\n\t\t\tset { }\n\t\t}\n\t\tpublic override void Flush() { }\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \n\t\t{\n\t\t\tint numTotal = 0;\n\t\t\twhile (count > 0)\n\t\t\t{\n\t\t\t\tif (fileIndex == 0)\n\t\t\t\t{\n\t\t\t\t\tint num = s1.Read(buffer, offset, count);\n\t\t\t\t\toffset += num;\n\t\t\t\t\tcount -= num;\n\t\t\t\t\tnumTotal += num;\n\t\t\t\t\tif (num == 0)\n\t\t\t\t\t\tfileIndex++;\n\t\t\t\t}\n\t\t\t\tif (fileIndex == 1)\n\t\t\t\t{\n\t\t\t\t\tnumTotal += s2.Read(buffer, offset, count);\n\t\t\t\t\treturn numTotal;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn numTotal;\n\t\t}\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\n\t\t{\n\t\t\tthrow (new Exception(\"can't Write\"));\n\t\t}\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\n\t\t{\n\t\t\tthrow (new Exception(\"can't Seek\"));\n\t\t}\n\t\tpublic override void SetLength(long value)\n\t\t{\n\t\t\tthrow (new Exception(\"can't SetLength\"));\n\t\t}\n\t}\n\t\n\tclass LzmaAlone\n\t{\n\t\tenum Key\n\t\t{\n\t\t\tHelp1 = 0,\n\t\t\tHelp2,\n\t\t\tMode,\n\t\t\tDictionary,\n\t\t\tFastBytes,\n\t\t\tLitContext,\n\t\t\tLitPos,\n\t\t\tPosBits,\n\t\t\tMatchFinder,\n\t\t\tEOS,\n\t\t\tStdIn,\n\t\t\tStdOut,\n\t\t\tTrain\n\t\t};\n\n\t\tstatic void PrintHelp()\n\t\t{\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\n\t\t\t\t\"  e: encode file\\n\" +\n\t\t\t\t\"  d: decode file\\n\" +\n\t\t\t\t\"  b: Benchmark\\n\" +\n\t\t\t\t\"<Switches>\\n\" +\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\n\t\t\t\t\"  -d{N}:  set dictionary - [0, 29], default: 23 (8MB)\\n\" +\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\n\t\t\t\t);\n\t\t}\n\n\t\tstatic bool GetNumber(string s, out Int32 v)\n\t\t{\n\t\t\tv = 0;\n\t\t\tfor (int i = 0; i < s.Length; i++)\n\t\t\t{\n\t\t\t\tchar c = s[i];\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\treturn false;\n\t\t\t\tv *= 10;\n\t\t\t\tv += (Int32)(c - '0');\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tstatic int IncorrectCommand()\n\t\t{\n\t\t\tthrow (new Exception(\"Command line error\"));\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\n\t\t\t// return 1;\n\t\t}\n\t\tstatic int Main2(string[] args)\n\t\t{\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.61  2008-11-23\\n\");\n\n\t\t\tif (args.Length == 0)\n\t\t\t{\n\t\t\t\tPrintHelp();\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[13];\n\t\t\tint sw = 0;\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"T\", SwitchType.UnLimitedPostString, false, 1);\n\n\n\t\t\tParser parser = new Parser(sw);\n\t\t\ttry\n\t\t\t{\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\n\t\t\t}\n\t\t\tcatch\n\t\t\t{\n\t\t\t\treturn IncorrectCommand();\n\t\t\t}\n\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\n\t\t\t{\n\t\t\t\tPrintHelp();\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\n\n\t\t\tint paramIndex = 0;\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\n\t\t\t\treturn IncorrectCommand();\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\n\t\t\tcommand = command.ToLower();\n\n\t\t\tbool dictionaryIsDefined = false;\n\t\t\tInt32 dictionary = 1 << 21;\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\n\t\t\t{\n\t\t\t\tInt32 dicLog;\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\n\t\t\t\t\tIncorrectCommand();\n\t\t\t\tdictionary = (Int32)1 << dicLog;\n\t\t\t\tdictionaryIsDefined = true;\n\t\t\t}\n\t\t\tstring mf = \"bt4\";\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\n\t\t\tmf = mf.ToLower();\n\n\t\t\tif (command == \"b\")\n\t\t\t{\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary);\n\t\t\t}\n\n\t\t\tstring train = \"\";\n\t\t\tif (parser[(int)Key.Train].ThereIs)\n\t\t\t\ttrain = (string)parser[(int)Key.Train].PostStrings[0];\n\n\t\t\tbool encodeMode = false;\n\t\t\tif (command == \"e\")\n\t\t\t\tencodeMode = true;\n\t\t\telse if (command == \"d\")\n\t\t\t\tencodeMode = false;\n\t\t\telse\n\t\t\t\tIncorrectCommand();\n\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\n\n\t\t\tStream inStream = null;\n\t\t\tif (stdInMode)\n\t\t\t{\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\n\t\t\t\t\tIncorrectCommand();\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\n\t\t\t}\n\n\t\t\tFileStream outStream = null;\n\t\t\tif (stdOutMode)\n\t\t\t{\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\n\t\t\t\t\tIncorrectCommand();\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\n\t\t\t}\n\n\t\t\tFileStream trainStream = null;\n\t\t\tif (train.Length != 0)\n\t\t\t\ttrainStream = new FileStream(train, FileMode.Open, FileAccess.Read);\n\n\t\t\tif (encodeMode)\n\t\t\t{\n\t\t\t\tif (!dictionaryIsDefined)\n\t\t\t\t\tdictionary = 1 << 23;\n\n\t\t\t\tInt32 posStateBits = 2;\n\t\t\t\tInt32 litContextBits = 3; // for normal files\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\n\t\t\t\tInt32 litPosBits = 0;\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\n\t\t\t\tInt32 algorithm = 2;\n\t\t\t\tInt32 numFastBytes = 128;\n\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\n\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\n\t\t\t\t\t\tIncorrectCommand();\n\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\n\t\t\t\t\t\tIncorrectCommand();\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\n\t\t\t\t\t\tIncorrectCommand();\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\n\t\t\t\t\t\tIncorrectCommand();\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\n\t\t\t\t\t\tIncorrectCommand();\n\n\t\t\t\tCoderPropID[] propIDs = \n\t\t\t\t{\n\t\t\t\t\tCoderPropID.DictionarySize,\n\t\t\t\t\tCoderPropID.PosStateBits,\n\t\t\t\t\tCoderPropID.LitContextBits,\n\t\t\t\t\tCoderPropID.LitPosBits,\n\t\t\t\t\tCoderPropID.Algorithm,\n\t\t\t\t\tCoderPropID.NumFastBytes,\n\t\t\t\t\tCoderPropID.MatchFinder,\n\t\t\t\t\tCoderPropID.EndMarker\n\t\t\t\t};\n\t\t\t\tobject[] properties = \n\t\t\t\t{\n\t\t\t\t\t(Int32)(dictionary),\n\t\t\t\t\t(Int32)(posStateBits),\n\t\t\t\t\t(Int32)(litContextBits),\n\t\t\t\t\t(Int32)(litPosBits),\n\t\t\t\t\t(Int32)(algorithm),\n\t\t\t\t\t(Int32)(numFastBytes),\n\t\t\t\t\tmf,\n\t\t\t\t\teos\n\t\t\t\t};\n\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\n\t\t\t\tencoder.WriteCoderProperties(outStream);\n\t\t\t\tInt64 fileSize;\n\t\t\t\tif (eos || stdInMode)\n\t\t\t\t\tfileSize = -1;\n\t\t\t\telse\n\t\t\t\t\tfileSize = inStream.Length;\n\t\t\t\tfor (int i = 0; i < 8; i++)\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\n\t\t\t\tif (trainStream != null)\n\t\t\t\t{\n\t\t\t\t\tCDoubleStream doubleStream = new CDoubleStream();\n\t\t\t\t\tdoubleStream.s1 = trainStream;\n\t\t\t\t\tdoubleStream.s2 = inStream;\n\t\t\t\t\tdoubleStream.fileIndex = 0;\n\t\t\t\t\tinStream = doubleStream;\n\t\t\t\t\tlong trainFileSize = trainStream.Length;\n\t\t\t\t\tdoubleStream.skipSize = 0;\n\t\t\t\t\tif (trainFileSize > dictionary)\n\t\t\t\t\t\tdoubleStream.skipSize = trainFileSize - dictionary;\n\t\t\t\t\ttrainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);\n\t\t\t\t\tencoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));\n\t\t\t\t}\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\n\t\t\t}\n\t\t\telse if (command == \"d\")\n\t\t\t{\n\t\t\t\tbyte[] properties = new byte[5];\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\n\t\t\t\tdecoder.SetDecoderProperties(properties);\n\t\t\t\tif (trainStream != null)\n\t\t\t\t{\n\t\t\t\t\tif (!decoder.Train(trainStream))\n\t\t\t\t\t\tthrow (new Exception(\"can't train\"));\n\t\t\t\t}\n\t\t\t\tlong outSize = 0;\n\t\t\t\tfor (int i = 0; i < 8; i++)\n\t\t\t\t{\n\t\t\t\t\tint v = inStream.ReadByte();\n\t\t\t\t\tif (v < 0)\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\n\t\t\t\t}\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\n\t\t\t}\n\t\t\telse\n\t\t\t\tthrow (new Exception(\"Command Error\"));\n\t\t\treturn 0;\n\t\t}\n\n\t\t[STAThread]\n\t\tstatic int Main(string[] args)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\treturn Main2(args);\n\t\t\t}\n\t\t\tcatch (Exception e)\n\t\t\t{\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\n\t\t\t\t// throw e;\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <PropertyGroup>\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\n    <ProductVersion>8.0.50727</ProductVersion>\n    <SchemaVersion>2.0</SchemaVersion>\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\n    <OutputType>Exe</OutputType>\n    <RootNamespace>LzmaAlone</RootNamespace>\n    <AssemblyName>Lzma#</AssemblyName>\n    <WarningLevel>4</WarningLevel>\n  </PropertyGroup>\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\n    <DebugSymbols>true</DebugSymbols>\n    <DebugType>full</DebugType>\n    <Optimize>false</Optimize>\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\n  </PropertyGroup>\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\n    <DebugSymbols>false</DebugSymbols>\n    <Optimize>true</Optimize>\n    <OutputPath>.\\bin\\Release\\</OutputPath>\n    <DefineConstants>TRACE</DefineConstants>\n    <PlatformTarget>AnyCPU</PlatformTarget>\n  </PropertyGroup>\n  <ItemGroup>\n    <Reference Include=\"System\" />\n    <Reference Include=\"System.Data\" />\n    <Reference Include=\"System.Xml\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\n      <Link>Common\\CommandLineParser.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\n      <Link>Common\\CRC.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\..\\ICoder.cs\">\n      <Link>ICoder.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\n      <Link>LZ\\IMatchFinder.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\n      <Link>LZ\\LzBinTree.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\n      <Link>LZ\\LzInWindow.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\n      <Link>LZ\\LzOutWindow.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\n      <Link>LZMA\\LzmaBase.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\n      <Link>LZMA\\LzmaDecoder.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\n      <Link>LZMA\\LzmaEncoder.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\n      <Link>RangeCoder\\RangeCoder.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\n    </Compile>\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\n    </Compile>\n    <Compile Include=\"LzmaAlone.cs\">\n      <SubType>Code</SubType>\n    </Compile>\n    <Compile Include=\"LzmaBench.cs\">\n      <SubType>Code</SubType>\n    </Compile>\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\n    <Compile Include=\"Properties\\Settings.cs\">\n      <AutoGen>True</AutoGen>\n      <DependentUpon>Settings.settings</DependentUpon>\n    </Compile>\n    <None Include=\"Properties\\Settings.settings\">\n      <Generator>SettingsSingleFileGenerator</Generator>\n      <LastGenOutput>Settings.cs</LastGenOutput>\n    </None>\n    <AppDesigner Include=\"Properties\\\" />\n  </ItemGroup>\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\n</Project>"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\nMicrosoft Visual Studio Solution File, Format Version 9.00\n# Visual C# Express 2005\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug|Any CPU = Debug|Any CPU\n\t\tRelease|Any CPU = Release|Any CPU\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\n\nusing System;\nusing System.IO;\n\nnamespace SevenZip\n{\n\t/// <summary>\n\t/// LZMA Benchmark\n\t/// </summary>\n\tinternal abstract class LzmaBench\n\t{\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\n\n\t\tclass CRandomGenerator\n\t\t{\n\t\t\tUInt32 A1;\n\t\t\tUInt32 A2;\n\t\t\tpublic CRandomGenerator() { Init(); }\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\n\t\t\tpublic UInt32 GetRnd()\n\t\t\t{\n\t\t\t\treturn\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\n\t\t\t}\n\t\t};\n\n\t\tclass CBitRandomGenerator\n\t\t{\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\n\t\t\tUInt32 Value;\n\t\t\tint NumBits;\n\t\t\tpublic void Init()\n\t\t\t{\n\t\t\t\tValue = 0;\n\t\t\t\tNumBits = 0;\n\t\t\t}\n\t\t\tpublic UInt32 GetRnd(int numBits)\n\t\t\t{\n\t\t\t\tUInt32 result;\n\t\t\t\tif (NumBits > numBits)\n\t\t\t\t{\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\n\t\t\t\t\tValue >>= numBits;\n\t\t\t\t\tNumBits -= numBits;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t\tnumBits -= NumBits;\n\t\t\t\tresult = (Value << numBits);\n\t\t\t\tValue = RG.GetRnd();\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\n\t\t\t\tValue >>= numBits;\n\t\t\t\tNumBits = 32 - numBits;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t};\n\n\t\tclass CBenchRandomGenerator\n\t\t{\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\n\t\t\tUInt32 Pos;\n\t\t\tUInt32 Rep0;\n\t\t\t\n\t\t\tpublic UInt32 BufferSize;\n\t\t\tpublic Byte[] Buffer = null;\n\n\t\t\tpublic CBenchRandomGenerator() { }\n\n\t\t\tpublic void Set(UInt32 bufferSize)\n\t\t\t{\n\t\t\t\tBuffer = new Byte[bufferSize];\n\t\t\t\tPos = 0;\n\t\t\t\tBufferSize = bufferSize;\n\t\t\t}\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\n\t\t\tUInt32 GetLogRandBits(int numBits)\n\t\t\t{\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\n\t\t\t\treturn RG.GetRnd((int)len);\n\t\t\t}\n\t\t\tUInt32 GetOffset()\n\t\t\t{\n\t\t\t\tif (GetRndBit() == 0)\n\t\t\t\t\treturn GetLogRandBits(4);\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\n\t\t\t}\n\t\t\tUInt32 GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\n\t\t\tUInt32 GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\n\t\t\tpublic void Generate()\n\t\t\t{\n\t\t\t\tRG.Init();\n\t\t\t\tRep0 = 1;\n\t\t\t\twhile (Pos < BufferSize)\n\t\t\t\t{\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)RG.GetRnd(8);\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tUInt32 len;\n\t\t\t\t\t\tif (RG.GetRnd(3) == 0)\n\t\t\t\t\t\t\tlen = 1 + GetLen1();\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\tRep0 = GetOffset();\n\t\t\t\t\t\t\twhile (Rep0 >= Pos);\n\t\t\t\t\t\t\tRep0++;\n\t\t\t\t\t\t\tlen = 2 + GetLen2();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tclass CrcOutStream : System.IO.Stream\n\t\t{\n\t\t\tpublic CRC CRC = new CRC();\n\t\t\tpublic void Init() { CRC.Init(); }\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\n\n\t\t\tpublic override bool CanRead { get { return false; } }\n\t\t\tpublic override bool CanSeek { get { return false; } }\n\t\t\tpublic override bool CanWrite { get { return true; } }\n\t\t\tpublic override Int64 Length { get { return 0; } }\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\n\t\t\tpublic override void Flush() { }\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\n\t\t\tpublic override void SetLength(long value) { }\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\n\n\t\t\tpublic override void WriteByte(byte b)\n\t\t\t{\n\t\t\t\tCRC.UpdateByte(b);\n\t\t\t}\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\n\t\t\t{\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\n\t\t\t}\n\t\t};\n\n\t\tclass CProgressInfo : ICodeProgress\n\t\t{\n\t\t\tpublic Int64 ApprovedStart;\n\t\t\tpublic Int64 InSize;\n\t\t\tpublic System.DateTime Time;\n\t\t\tpublic void Init() { InSize = 0; }\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\n\t\t\t{\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\n\t\t\t\t{\n\t\t\t\t\tTime = DateTime.UtcNow;\n\t\t\t\t\tInSize = inSize;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst int kSubBits = 8;\n\n\t\tstatic UInt32 GetLogSize(UInt32 size)\n\t\t{\n\t\t\tfor (int i = kSubBits; i < 32; i++)\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\n\t\t\treturn (32 << kSubBits);\n\t\t}\n\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\n\t\t{\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\n\t\t\tUInt64 elTime = elapsedTime;\n\t\t\twhile (freq > 1000000)\n\t\t\t{\n\t\t\t\tfreq >>= 1;\n\t\t\t\telTime >>= 1;\n\t\t\t}\n\t\t\tif (elTime == 0)\n\t\t\t\telTime = 1;\n\t\t\treturn value * freq / elTime;\n\t\t}\n\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 size)\n\t\t{\n\t\t\tUInt64 t = GetLogSize(dictionarySize) - (18 << kSubBits);\n\t\t\tUInt64 numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\n\t\t}\n\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 outSize, UInt64 inSize)\n\t\t{\n\t\t\tUInt64 numCommands = inSize * 220 + outSize * 20;\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\n\t\t}\n\n\t\tstatic UInt64 GetTotalRating(\n\t\t\tUInt32 dictionarySize,\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\n\t\t\tUInt64 elapsedTimeDe,\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\n\t\t{\n\t\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\n\t\t}\n\n\t\tstatic void PrintValue(UInt64 v)\n\t\t{\n\t\t\tstring s = v.ToString();\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\n\t\t\t\tSystem.Console.Write(\" \");\n\t\t\tSystem.Console.Write(s);\n\t\t}\n\n\t\tstatic void PrintRating(UInt64 rating)\n\t\t{\n\t\t\tPrintValue(rating / 1000000);\n\t\t\tSystem.Console.Write(\" MIPS\");\n\t\t}\n\n\t\tstatic void PrintResults(\n\t\t\tUInt32 dictionarySize,\n\t\t\tUInt64 elapsedTime,\n\t\t\tUInt64 size,\n\t\t\tbool decompressMode, UInt64 secondSize)\n\t\t{\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\n\t\t\tPrintValue(speed / 1024);\n\t\t\tSystem.Console.Write(\" KB/s  \");\n\t\t\tUInt64 rating;\n\t\t\tif (decompressMode)\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\n\t\t\telse\n\t\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\n\t\t\tPrintRating(rating);\n\t\t}\n\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize)\n\t\t{\n\t\t\tif (numIterations <= 0)\n\t\t\t\treturn 0;\n\t\t\tif (dictionarySize < (1 << 18))\n\t\t\t{\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\n\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\n\n\n\t\t\tCoderPropID[] propIDs = \n\t\t\t{ \n\t\t\t\tCoderPropID.DictionarySize,\n\t\t\t};\n\t\t\tobject[] properties = \n\t\t\t{\n\t\t\t\t(Int32)(dictionarySize),\n\t\t\t};\n\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\n\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\n\t\t\tencoder.WriteCoderProperties(propStream);\n\t\t\tbyte[] propArray = propStream.ToArray();\n\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\n\n\t\t\trg.Set(kBufferSize);\n\t\t\trg.Generate();\n\t\t\tCRC crc = new CRC();\n\t\t\tcrc.Init();\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\n\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\n\n\t\t\tUInt64 totalBenchSize = 0;\n\t\t\tUInt64 totalEncodeTime = 0;\n\t\t\tUInt64 totalDecodeTime = 0;\n\t\t\tUInt64 totalCompressedSize = 0;\n\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\n\t\t\t{\n\t\t\t\tprogressInfo.Init();\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\n\n\t\t\t\tlong compressedSize = compressedStream.Position;\n\t\t\t\tif (progressInfo.InSize == 0)\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\n\n\t\t\t\tUInt64 decodeTime = 0;\n\t\t\t\tfor (int j = 0; j < 2; j++)\n\t\t\t\t{\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\n\t\t\t\t\tcrcOutStream.Init();\n\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\n\t\t\t\t\tUInt64 outSize = kBufferSize;\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\n\t\t\t\t}\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\n\t\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\n\t\t\t\tSystem.Console.Write(\"     \");\n\t\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, (ulong)compressedSize);\n\t\t\t\tSystem.Console.WriteLine();\n\n\t\t\t\ttotalBenchSize += benchSize;\n\t\t\t\ttotalEncodeTime += encodeTime;\n\t\t\t\ttotalDecodeTime += decodeTime;\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\n\t\t\t}\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\n\t\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\n\t\t\tSystem.Console.Write(\"     \");\n\t\t\tPrintResults(dictionarySize, totalDecodeTime,\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\n\t\t\tSystem.Console.WriteLine(\"    Average\");\n\t\t\treturn 0;\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\n\nusing System.Reflection;\nusing System.Runtime.CompilerServices;\n\n#endregion\n\n// General Information about an assembly is controlled through the following \n// set of attributes. Change these attribute values to modify the information\n// associated with an assembly.\n[assembly: AssemblyTitle(\"LZMA#\")]\n[assembly: AssemblyDescription(\"\")]\n[assembly: AssemblyConfiguration(\"\")]\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\n[assembly: AssemblyTrademark(\"\")]\n[assembly: AssemblyCulture(\"\")]\n\n// Version information for an assembly consists of the following four values:\n//\n//      Major Version\n//      Minor Version \n//      Build Number\n//      Revision\n//\n// You can specify all the values or you can default the Revision and Build Numbers \n// by using the '*' as shown below:\n[assembly: AssemblyVersion(\"4.12.*\")]\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\n// <autogenerated>\n//     This code was generated by a tool.\n//     Runtime Version:2.0.40607.42\n//\n//     Changes to this file may cause incorrect behavior and will be lost if\n//     the code is regenerated.\n// </autogenerated>\n//------------------------------------------------------------------------------\n\nnamespace LzmaAlone.Properties\n{\n\tusing System;\n\tusing System.IO;\n\tusing System.Resources;\n\n\t/// <summary>\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\n\t/// </summary>\n\t// This class was auto-generated by the Strongly Typed Resource Builder\n\t// class via a tool like ResGen or Visual Studio.NET.\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\n\t// with the /str option, or rebuild your VS project.\n\tclass Resources\n\t{\n\n\t\tprivate static System.Resources.ResourceManager _resMgr;\n\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\n\n\t\t/*FamANDAssem*/\n\t\tinternal Resources()\n\t\t{\n\t\t}\n\n\t\t/// <summary>\n\t\t///    Returns the cached ResourceManager instance used by this class.\n\t\t/// </summary>\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\n\t\tpublic static System.Resources.ResourceManager ResourceManager\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\tif ((_resMgr == null))\n\t\t\t\t{\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\n\t\t\t\t\t_resMgr = temp;\n\t\t\t\t}\n\t\t\t\treturn _resMgr;\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>\n\t\t///    Overrides the current thread's CurrentUICulture property for all\n\t\t///    resource lookups using this strongly typed resource class.\n\t\t/// </summary>\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\n\t\tpublic static System.Globalization.CultureInfo Culture\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\treturn _resCulture;\n\t\t\t}\n\t\t\tset\n\t\t\t{\n\t\t\t\t_resCulture = value;\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\n// <autogenerated>\n//     This code was generated by a tool.\n//     Runtime Version:2.0.40607.42\n//\n//     Changes to this file may cause incorrect behavior and will be lost if\n//     the code is regenerated.\n// </autogenerated>\n//------------------------------------------------------------------------------\n\nnamespace LzmaAlone.Properties\n{\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\n\t{\n\t\tprivate static Settings m_Value;\n\n\t\tprivate static object m_SyncObject = new object();\n\n\t\tpublic static Settings Value\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\tif ((Settings.m_Value == null))\n\t\t\t\t{\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\n\t\t\t\t\tif ((Settings.m_Value == null))\n\t\t\t\t\t{\n\t\t\t\t\t\ttry\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfinally\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn Settings.m_Value;\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\n\nnamespace SevenZip.Compression.RangeCoder\n{\n\tclass Encoder\n\t{\n\t\tpublic const uint kTopValue = (1 << 24);\n\n\t\tSystem.IO.Stream Stream;\n\n\t\tpublic UInt64 Low;\n\t\tpublic uint Range;\n\t\tuint _cacheSize;\n\t\tbyte _cache;\n\n\t\tlong StartPosition;\n\n\t\tpublic void SetStream(System.IO.Stream stream)\n\t\t{\n\t\t\tStream = stream;\n\t\t}\n\n\t\tpublic void ReleaseStream()\n\t\t{\n\t\t\tStream = null;\n\t\t}\n\n\t\tpublic void Init()\n\t\t{\n\t\t\tStartPosition = Stream.Position;\n\n\t\t\tLow = 0;\n\t\t\tRange = 0xFFFFFFFF;\n\t\t\t_cacheSize = 1;\n\t\t\t_cache = 0;\n\t\t}\n\n\t\tpublic void FlushData()\n\t\t{\n\t\t\tfor (int i = 0; i < 5; i++)\n\t\t\t\tShiftLow();\n\t\t}\n\n\t\tpublic void FlushStream()\n\t\t{\n\t\t\tStream.Flush();\n\t\t}\n\n\t\tpublic void CloseStream()\n\t\t{\n\t\t\tStream.Close();\n\t\t}\n\n\t\tpublic void Encode(uint start, uint size, uint total)\n\t\t{\n\t\t\tLow += start * (Range /= total);\n\t\t\tRange *= size;\n\t\t\twhile (Range < kTopValue)\n\t\t\t{\n\t\t\t\tRange <<= 8;\n\t\t\t\tShiftLow();\n\t\t\t}\n\t\t}\n\n\t\tpublic void ShiftLow()\n\t\t{\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\n\t\t\t{\n\t\t\t\tbyte temp = _cache;\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\n\t\t\t\t\ttemp = 0xFF;\n\t\t\t\t}\n\t\t\t\twhile (--_cacheSize != 0);\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\n\t\t\t}\n\t\t\t_cacheSize++;\n\t\t\tLow = ((uint)Low) << 8;\n\t\t}\n\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\n\t\t{\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\n\t\t\t{\n\t\t\t\tRange >>= 1;\n\t\t\t\tif (((v >> i) & 1) == 1)\n\t\t\t\t\tLow += Range;\n\t\t\t\tif (Range < kTopValue)\n\t\t\t\t{\n\t\t\t\t\tRange <<= 8;\n\t\t\t\t\tShiftLow();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\n\t\t{\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\n\t\t\tif (symbol == 0)\n\t\t\t\tRange = newBound;\n\t\t\telse\n\t\t\t{\n\t\t\t\tLow += newBound;\n\t\t\t\tRange -= newBound;\n\t\t\t}\n\t\t\twhile (Range < kTopValue)\n\t\t\t{\n\t\t\t\tRange <<= 8;\n\t\t\t\tShiftLow();\n\t\t\t}\n\t\t}\n\n\t\tpublic long GetProcessedSizeAdd()\n\t\t{\n\t\t\treturn _cacheSize +\n\t\t\t\tStream.Position - StartPosition + 4;\n\t\t\t// (long)Stream.GetProcessedSize();\n\t\t}\n\t}\n\n\tclass Decoder\n\t{\n\t\tpublic const uint kTopValue = (1 << 24);\n\t\tpublic uint Range;\n\t\tpublic uint Code;\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\n\t\tpublic System.IO.Stream Stream;\n\n\t\tpublic void Init(System.IO.Stream stream)\n\t\t{\n\t\t\t// Stream.Init(stream);\n\t\t\tStream = stream;\n\n\t\t\tCode = 0;\n\t\t\tRange = 0xFFFFFFFF;\n\t\t\tfor (int i = 0; i < 5; i++)\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\n\t\t}\n\n\t\tpublic void ReleaseStream()\n\t\t{\n\t\t\t// Stream.ReleaseStream();\n\t\t\tStream = null;\n\t\t}\n\n\t\tpublic void CloseStream()\n\t\t{\n\t\t\tStream.Close();\n\t\t}\n\n\t\tpublic void Normalize()\n\t\t{\n\t\t\twhile (Range < kTopValue)\n\t\t\t{\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\n\t\t\t\tRange <<= 8;\n\t\t\t}\n\t\t}\n\n\t\tpublic void Normalize2()\n\t\t{\n\t\t\tif (Range < kTopValue)\n\t\t\t{\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\n\t\t\t\tRange <<= 8;\n\t\t\t}\n\t\t}\n\n\t\tpublic uint GetThreshold(uint total)\n\t\t{\n\t\t\treturn Code / (Range /= total);\n\t\t}\n\n\t\tpublic void Decode(uint start, uint size, uint total)\n\t\t{\n\t\t\tCode -= start * Range;\n\t\t\tRange *= size;\n\t\t\tNormalize();\n\t\t}\n\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\n\t\t{\n\t\t\tuint range = Range;\n\t\t\tuint code = Code;\n\t\t\tuint result = 0;\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\n\t\t\t{\n\t\t\t\trange >>= 1;\n\t\t\t\t/*\n\t\t\t\tresult <<= 1;\n\t\t\t\tif (code >= range)\n\t\t\t\t{\n\t\t\t\t\tcode -= range;\n\t\t\t\t\tresult |= 1;\n\t\t\t\t}\n\t\t\t\t*/\n\t\t\t\tuint t = (code - range) >> 31;\n\t\t\t\tcode -= range & (t - 1);\n\t\t\t\tresult = (result << 1) | (1 - t);\n\n\t\t\t\tif (range < kTopValue)\n\t\t\t\t{\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\n\t\t\t\t\trange <<= 8;\n\t\t\t\t}\n\t\t\t}\n\t\t\tRange = range;\n\t\t\tCode = code;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\n\t\t{\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\n\t\t\tuint symbol;\n\t\t\tif (Code < newBound)\n\t\t\t{\n\t\t\t\tsymbol = 0;\n\t\t\t\tRange = newBound;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsymbol = 1;\n\t\t\t\tCode -= newBound;\n\t\t\t\tRange -= newBound;\n\t\t\t}\n\t\t\tNormalize();\n\t\t\treturn symbol;\n\t\t}\n\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\n\nnamespace SevenZip.Compression.RangeCoder\n{\n\tstruct BitEncoder\n\t{\n\t\tpublic const int kNumBitModelTotalBits = 11;\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\n\t\tconst int kNumMoveBits = 5;\n\t\tconst int kNumMoveReducingBits = 2;\n\t\tpublic const int kNumBitPriceShiftBits = 6;\n\n\t\tuint Prob;\n\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\n\n\t\tpublic void UpdateModel(uint symbol)\n\t\t{\n\t\t\tif (symbol == 0)\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\n\t\t\telse\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\n\t\t}\n\n\t\tpublic void Encode(Encoder encoder, uint symbol)\n\t\t{\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\n\t\t\t// UpdateModel(symbol);\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\n\t\t\tif (symbol == 0)\n\t\t\t{\n\t\t\t\tencoder.Range = newBound;\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tencoder.Low += newBound;\n\t\t\t\tencoder.Range -= newBound;\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\n\t\t\t}\n\t\t\tif (encoder.Range < Encoder.kTopValue)\n\t\t\t{\n\t\t\t\tencoder.Range <<= 8;\n\t\t\t\tencoder.ShiftLow();\n\t\t\t}\n\t\t}\n\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\n\n\t\tstatic BitEncoder()\n\t\t{\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\n\t\t\t{\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\n\t\t\t}\n\t\t}\n\n\t\tpublic uint GetPrice(uint symbol)\n\t\t{\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\n\t\t}\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\n\t}\n\n\tstruct BitDecoder\n\t{\n\t\tpublic const int kNumBitModelTotalBits = 11;\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\n\t\tconst int kNumMoveBits = 5;\n\n\t\tuint Prob;\n\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\n\t\t{\n\t\t\tif (symbol == 0)\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\n\t\t\telse\n\t\t\t\tProb -= (Prob) >> numMoveBits;\n\t\t}\n\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\n\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\n\t\t{\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\n\t\t\tif (rangeDecoder.Code < newBound)\n\t\t\t{\n\t\t\t\trangeDecoder.Range = newBound;\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\n\t\t\t\t{\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\n\t\t\t\t\trangeDecoder.Range <<= 8;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\trangeDecoder.Range -= newBound;\n\t\t\t\trangeDecoder.Code -= newBound;\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\n\t\t\t\t{\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\n\t\t\t\t\trangeDecoder.Range <<= 8;\n\t\t\t\t}\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\n\nnamespace SevenZip.Compression.RangeCoder\n{\n\tstruct BitTreeEncoder\n\t{\n\t\tBitEncoder[] Models;\n\t\tint NumBitLevels;\n\n\t\tpublic BitTreeEncoder(int numBitLevels)\n\t\t{\n\t\t\tNumBitLevels = numBitLevels;\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\n\t\t}\n\n\t\tpublic void Init()\n\t\t{\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\n\t\t\t\tModels[i].Init();\n\t\t}\n\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\n\t\t{\n\t\t\tUInt32 m = 1;\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\n\t\t\t{\n\t\t\t\tbitIndex--;\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\n\t\t\t\tm = (m << 1) | bit;\n\t\t\t}\n\t\t}\n\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\n\t\t{\n\t\t\tUInt32 m = 1;\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\n\t\t\t{\n\t\t\t\tUInt32 bit = symbol & 1;\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\n\t\t\t\tm = (m << 1) | bit;\n\t\t\t\tsymbol >>= 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\n\t\t{\n\t\t\tUInt32 price = 0;\n\t\t\tUInt32 m = 1;\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\n\t\t\t{\n\t\t\t\tbitIndex--;\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\n\t\t\t\tprice += Models[m].GetPrice(bit);\n\t\t\t\tm = (m << 1) + bit;\n\t\t\t}\n\t\t\treturn price;\n\t\t}\n\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\n\t\t{\n\t\t\tUInt32 price = 0;\n\t\t\tUInt32 m = 1;\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\n\t\t\t{\n\t\t\t\tUInt32 bit = symbol & 1;\n\t\t\t\tsymbol >>= 1;\n\t\t\t\tprice += Models[m].GetPrice(bit);\n\t\t\t\tm = (m << 1) | bit;\n\t\t\t}\n\t\t\treturn price;\n\t\t}\n\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\n\t\t\tint NumBitLevels, UInt32 symbol)\n\t\t{\n\t\t\tUInt32 price = 0;\n\t\t\tUInt32 m = 1;\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\n\t\t\t{\n\t\t\t\tUInt32 bit = symbol & 1;\n\t\t\t\tsymbol >>= 1;\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\n\t\t\t\tm = (m << 1) | bit;\n\t\t\t}\n\t\t\treturn price;\n\t\t}\n\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\n\t\t{\n\t\t\tUInt32 m = 1;\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\n\t\t\t{\n\t\t\t\tUInt32 bit = symbol & 1;\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\n\t\t\t\tm = (m << 1) | bit;\n\t\t\t\tsymbol >>= 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tstruct BitTreeDecoder\n\t{\n\t\tBitDecoder[] Models;\n\t\tint NumBitLevels;\n\n\t\tpublic BitTreeDecoder(int numBitLevels)\n\t\t{\n\t\t\tNumBitLevels = numBitLevels;\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\n\t\t}\n\n\t\tpublic void Init()\n\t\t{\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\n\t\t\t\tModels[i].Init();\n\t\t}\n\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\n\t\t{\n\t\t\tuint m = 1;\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\n\t\t\treturn m - ((uint)1 << NumBitLevels);\n\t\t}\n\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\n\t\t{\n\t\t\tuint m = 1;\n\t\t\tuint symbol = 0;\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\n\t\t\t{\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\n\t\t\t\tm <<= 1;\n\t\t\t\tm += bit;\n\t\t\t\tsymbol |= (bit << bitIndex);\n\t\t\t}\n\t\t\treturn symbol;\n\t\t}\n\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\n\t\t{\n\t\t\tuint m = 1;\n\t\t\tuint symbol = 0;\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\n\t\t\t{\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\n\t\t\t\tm <<= 1;\n\t\t\t\tm += bit;\n\t\t\t\tsymbol |= (bit << bitIndex);\n\t\t\t}\n\t\t\treturn symbol;\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\n\nusing System;\n\nnamespace SevenZip\n{\n\t/// <summary>\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\n\t/// </summary>\n\tclass DataErrorException : ApplicationException\n\t{\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\n\t}\n\n\t/// <summary>\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\n\t/// </summary>\n\tclass InvalidParamException : ApplicationException\n\t{\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\n\t}\n\n\tpublic interface ICodeProgress\n\t{\n\t\t/// <summary>\n\t\t/// Callback progress.\n\t\t/// </summary>\n\t\t/// <param name=\"inSize\">\n\t\t/// input size. -1 if unknown.\n\t\t/// </param>\n\t\t/// <param name=\"outSize\">\n\t\t/// output size. -1 if unknown.\n\t\t/// </param>\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\n\t};\n\n\tpublic interface ICoder\n\t{\n\t\t/// <summary>\n\t\t/// Codes streams.\n\t\t/// </summary>\n\t\t/// <param name=\"inStream\">\n\t\t/// input Stream.\n\t\t/// </param>\n\t\t/// <param name=\"outStream\">\n\t\t/// output Stream.\n\t\t/// </param>\n\t\t/// <param name=\"inSize\">\n\t\t/// input Size. -1 if unknown.\n\t\t/// </param>\n\t\t/// <param name=\"outSize\">\n\t\t/// output Size. -1 if unknown.\n\t\t/// </param>\n\t\t/// <param name=\"progress\">\n\t\t/// callback progress reference.\n\t\t/// </param>\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\n\t\t/// if input stream is not valid\n\t\t/// </exception>\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\n\t};\n\n\t/*\n\tpublic interface ICoder2\n\t{\n\t\t void Code(ISequentialInStream []inStreams,\n\t\t\t\tconst UInt64 []inSizes, \n\t\t\t\tISequentialOutStream []outStreams, \n\t\t\t\tUInt64 []outSizes,\n\t\t\t\tICodeProgress progress);\n\t};\n  */\n\n\t/// <summary>\n\t/// Provides the fields that represent properties idenitifiers for compressing.\n\t/// </summary>\n\tpublic enum CoderPropID\n\t{\n\t\t/// <summary>\n\t\t/// Specifies size of dictionary.\n\t\t/// </summary>\n\t\tDictionarySize = 0x400,\n\t\t/// <summary>\n\t\t/// Specifies size of memory for PPM*.\n\t\t/// </summary>\n\t\tUsedMemorySize,\n\t\t/// <summary>\n\t\t/// Specifies order for PPM methods.\n\t\t/// </summary>\n\t\tOrder,\n\t\t/// <summary>\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\n\t\t/// </summary>\n\t\tPosStateBits = 0x440,\n\t\t/// <summary>\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\n\t\t/// </summary>\n\t\tLitContextBits,\n\t\t/// <summary>\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\n\t\t/// </summary>\n\t\tLitPosBits,\n\t\t/// <summary>\n\t\t/// Specifies number of fast bytes for LZ*.\n\t\t/// </summary>\n\t\tNumFastBytes = 0x450,\n\t\t/// <summary>\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\n\t\t/// </summary>\n\t\tMatchFinder,\n\t\t/// <summary>\n\t\t/// Specifies number of passes.\n\t\t/// </summary>\n\t\tNumPasses = 0x460,\n\t\t/// <summary>\n\t\t/// Specifies number of algorithm.\n\t\t/// </summary>\n\t\tAlgorithm = 0x470,\n\t\t/// <summary>\n\t\t/// Specifies multithread mode.\n\t\t/// </summary>\n\t\tMultiThread = 0x480,\n\t\t/// <summary>\n\t\t/// Specifies mode with end marker.\n\t\t/// </summary>\n\t\tEndMarker = 0x490\n\t};\n\n\n\tpublic interface ISetCoderProperties\n\t{\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\n\t};\n\n\tpublic interface IWriteCoderProperties\n\t{\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\n\t}\n\n\tpublic interface ISetDecoderProperties\n\t{\n\t\tvoid SetDecoderProperties(byte[] properties);\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\n\npackage SevenZip;\n\npublic class CRC\n{\n\tstatic public int[] Table = new int[256];\n\t\n\tstatic\n\t{\n\t\tfor (int i = 0; i < 256; i++)\n\t\t{\n\t\t\tint r = i;\n\t\t\tfor (int j = 0; j < 8; j++)\n\t\t\t\tif ((r & 1) != 0)\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\n\t\t\t\telse\n\t\t\t\t\tr >>>= 1;\n\t\t\tTable[i] = r;\n\t\t}\n\t}\n\t\n\tint _value = -1;\n\t\n\tpublic void Init()\n\t{\n\t\t_value = -1;\n\t}\n\t\n\tpublic void Update(byte[] data, int offset, int size)\n\t{\n\t\tfor (int i = 0; i < size; i++)\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\n\t}\n\t\n\tpublic void Update(byte[] data)\n\t{\n\t\tint size = data.length;\n\t\tfor (int i = 0; i < size; i++)\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\n\t}\n\t\n\tpublic void UpdateByte(int b)\n\t{\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\n\t}\n\t\n\tpublic int GetDigest()\n\t{\n\t\treturn _value ^ (-1);\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "// LZ.BinTree\n\npackage SevenZip.Compression.LZ;\nimport java.io.IOException;\n\n\npublic class BinTree extends InWindow\n{\n\tint _cyclicBufferPos;\n\tint _cyclicBufferSize = 0;\n\tint _matchMaxLen;\n\t\n\tint[] _son;\n\tint[] _hash;\n\t\n\tint _cutValue = 0xFF;\n\tint _hashMask;\n\tint _hashSizeSum = 0;\n\t\n\tboolean HASH_ARRAY = true;\n\n\tstatic final int kHash2Size = 1 << 10;\n\tstatic final int kHash3Size = 1 << 16;\n\tstatic final int kBT2HashSize = 1 << 16;\n\tstatic final int kStartMaxLen = 1;\n\tstatic final int kHash3Offset = kHash2Size;\n\tstatic final int kEmptyHashValue = 0;\n\tstatic final int kMaxValForNormalize = (1 << 30) - 1;\n\t\n\tint kNumHashDirectBytes = 0;\n\tint kMinMatchCheck = 4;\n\tint kFixHashSize = kHash2Size + kHash3Size;\n\n\tpublic void SetType(int numHashBytes)\n\t{\n\t\tHASH_ARRAY = (numHashBytes > 2);\n\t\tif (HASH_ARRAY)\n\t\t{\n\t\t\tkNumHashDirectBytes = 0;\n\t\t\tkMinMatchCheck = 4;\n\t\t\tkFixHashSize = kHash2Size + kHash3Size;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tkNumHashDirectBytes = 2;\n\t\t\tkMinMatchCheck = 2 + 1;\n\t\t\tkFixHashSize = 0;\n\t\t}\n\t}\n\t\n\n\t\n\n\tpublic void Init() throws IOException\n\t{\n\t\tsuper.Init();\n\t\tfor (int i = 0; i < _hashSizeSum; i++)\n\t\t\t_hash[i] = kEmptyHashValue;\n\t\t_cyclicBufferPos = 0;\n\t\tReduceOffsets(-1);\n\t}\n\t\n\tpublic void MovePos() throws IOException\n\t{\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\n\t\t\t_cyclicBufferPos = 0;\n\t\tsuper.MovePos();\n\t\tif (_pos == kMaxValForNormalize)\n\t\t\tNormalize();\n\t}\n\t\n\n\t\n\t\n\t\n\t\n\t\n\t\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\n\t{\n\t\tif (historySize > kMaxValForNormalize - 256)\n\t\t\treturn false;\n\t\t_cutValue = 16 + (matchMaxLen >> 1);\n\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\n\t\t\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\n\t\t\n\t\t_matchMaxLen = matchMaxLen;\n\n\t\tint cyclicBufferSize = historySize + 1;\n\t\tif (_cyclicBufferSize != cyclicBufferSize)\n\t\t\t_son = new int[(_cyclicBufferSize = cyclicBufferSize) * 2];\n\n\t\tint hs = kBT2HashSize;\n\n\t\tif (HASH_ARRAY)\n\t\t{\n\t\t\ths = historySize - 1;\n\t\t\ths |= (hs >> 1);\n\t\t\ths |= (hs >> 2);\n\t\t\ths |= (hs >> 4);\n\t\t\ths |= (hs >> 8);\n\t\t\ths >>= 1;\n\t\t\ths |= 0xFFFF;\n\t\t\tif (hs > (1 << 24))\n\t\t\t\ths >>= 1;\n\t\t\t_hashMask = hs;\n\t\t\ths++;\n\t\t\ths += kFixHashSize;\n\t\t}\n\t\tif (hs != _hashSizeSum)\n\t\t\t_hash = new int [_hashSizeSum = hs];\n\t\treturn true;\n\t}\n\tpublic int GetMatches(int[] distances) throws IOException\n\t{\n\t\tint lenLimit;\n\t\tif (_pos + _matchMaxLen <= _streamPos)\n\t\t\tlenLimit = _matchMaxLen;\n\t\telse\n\t\t{\n\t\t\tlenLimit = _streamPos - _pos;\n\t\t\tif (lenLimit < kMinMatchCheck)\n\t\t\t{\n\t\t\t\tMovePos();\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\n\t\tint offset = 0;\n\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\n\t\tint cur = _bufferOffset + _pos;\n\t\tint maxLen = kStartMaxLen; // to avoid items for len < hashSize;\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\n\t\t\n\t\tif (HASH_ARRAY)\n\t\t{\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\n\t\t\thash2Value = temp & (kHash2Size - 1);\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\n\t\t\thash3Value = temp & (kHash3Size - 1);\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\n\t\t}\n\t\telse\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\n\n\t\tint curMatch = _hash[kFixHashSize + hashValue];\n\t\tif (HASH_ARRAY)\n\t\t{\n\t\t\tint curMatch2 = _hash[hash2Value];\n\t\t\tint curMatch3 = _hash[kHash3Offset + hash3Value];\n\t\t\t_hash[hash2Value] = _pos;\n\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\n\t\t\tif (curMatch2 > matchMinPos)\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\n\t\t\t\t{\n\t\t\t\t\tdistances[offset++] = maxLen = 2;\n\t\t\t\t\tdistances[offset++] = _pos - curMatch2 - 1;\n\t\t\t\t}\n\t\t\tif (curMatch3 > matchMinPos)\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\n\t\t\t\t{\n\t\t\t\t\tif (curMatch3 == curMatch2)\n\t\t\t\t\t\toffset -= 2;\n\t\t\t\t\tdistances[offset++] = maxLen = 3;\n\t\t\t\t\tdistances[offset++] = _pos - curMatch3 - 1;\n\t\t\t\t\tcurMatch2 = curMatch3;\n\t\t\t\t}\n\t\t\tif (offset != 0 && curMatch2 == curMatch)\n\t\t\t{\n\t\t\t\toffset -= 2;\n\t\t\t\tmaxLen = kStartMaxLen;\n\t\t\t}\n\t\t}\n\n\t\t_hash[kFixHashSize + hashValue] = _pos;\n\n\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\n\t\tint ptr1 = (_cyclicBufferPos << 1);\n\n\t\tint len0, len1;\n\t\tlen0 = len1 = kNumHashDirectBytes;\n\n\t\tif (kNumHashDirectBytes != 0)\n\t\t{\n\t\t\tif (curMatch > matchMinPos)\n\t\t\t{\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=\n\t\t\t\t\t\t_bufferBase[cur + kNumHashDirectBytes])\n\t\t\t\t{\n\t\t\t\t\tdistances[offset++] = maxLen = kNumHashDirectBytes;\n\t\t\t\t\tdistances[offset++] = _pos - curMatch - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint count = _cutValue;\n\n\t\twhile (true)\n\t\t{\n\t\t\tif (curMatch <= matchMinPos || count-- == 0)\n\t\t\t{\n\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint delta = _pos - curMatch;\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\n\t\t\t\t(_cyclicBufferPos - delta) :\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\n\n\t\t\tint pby1 = _bufferOffset + curMatch;\n\t\t\tint len = Math.min(len0, len1);\n\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\n\t\t\t{\n\t\t\t\twhile(++len != lenLimit)\n\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\n\t\t\t\t\t\tbreak;\n\t\t\t\tif (maxLen < len)\n\t\t\t\t{\n\t\t\t\t\tdistances[offset++] = maxLen = len;\n\t\t\t\t\tdistances[offset++] = delta - 1;\n\t\t\t\t\tif (len == lenLimit)\n\t\t\t\t\t{\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\n\t\t\t{\n\t\t\t\t_son[ptr1] = curMatch;\n\t\t\t\tptr1 = cyclicPos + 1;\n\t\t\t\tcurMatch = _son[ptr1];\n\t\t\t\tlen1 = len;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t_son[ptr0] = curMatch;\n\t\t\t\tptr0 = cyclicPos;\n\t\t\t\tcurMatch = _son[ptr0];\n\t\t\t\tlen0 = len;\n\t\t\t}\n\t\t}\n\t\tMovePos();\n\t\treturn offset;\n\t}\n\n\tpublic void Skip(int num) throws IOException\n\t{\n\t\tdo\n\t\t{\n\t\t\tint lenLimit;\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\n\t\t\tlenLimit = _matchMaxLen;\n\t\t\telse\n\t\t\t{\n\t\t\t\tlenLimit = _streamPos - _pos;\n\t\t\t\tif (lenLimit < kMinMatchCheck)\n\t\t\t\t{\n\t\t\t\t\tMovePos();\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tint matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\n\t\t\tint cur = _bufferOffset + _pos;\n\t\t\t\n\t\t\tint hashValue;\n\n\t\t\tif (HASH_ARRAY)\n\t\t\t{\n\t\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\n\t\t\t\tint hash2Value = temp & (kHash2Size - 1);\n\t\t\t\t_hash[hash2Value] = _pos;\n\t\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\n\t\t\t\tint hash3Value = temp & (kHash3Size - 1);\n\t\t\t\t_hash[kHash3Offset + hash3Value] = _pos;\n\t\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & _hashMask;\n\t\t\t}\n\t\t\telse\n\t\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8));\n\n\t\t\tint curMatch = _hash[kFixHashSize + hashValue];\n\t\t\t_hash[kFixHashSize + hashValue] = _pos;\n\n\t\t\tint ptr0 = (_cyclicBufferPos << 1) + 1;\n\t\t\tint ptr1 = (_cyclicBufferPos << 1);\n\n\t\t\tint len0, len1;\n\t\t\tlen0 = len1 = kNumHashDirectBytes;\n\n\t\t\tint count = _cutValue;\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tif (curMatch <= matchMinPos || count-- == 0)\n\t\t\t\t{\n\t\t\t\t\t_son[ptr0] = _son[ptr1] = kEmptyHashValue;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tint delta = _pos - curMatch;\n\t\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\n\t\t\t\t\t(_cyclicBufferPos - delta) :\n\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\n\n\t\t\t\tint pby1 = _bufferOffset + curMatch;\n\t\t\t\tint len = Math.min(len0, len1);\n\t\t\t\tif (_bufferBase[pby1 + len] == _bufferBase[cur + len])\n\t\t\t\t{\n\t\t\t\t\twhile (++len != lenLimit)\n\t\t\t\t\t\tif (_bufferBase[pby1 + len] != _bufferBase[cur + len])\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\tif (len == lenLimit)\n\t\t\t\t\t{\n\t\t\t\t\t\t_son[ptr1] = _son[cyclicPos];\n\t\t\t\t\t\t_son[ptr0] = _son[cyclicPos + 1];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ((_bufferBase[pby1 + len] & 0xFF) < (_bufferBase[cur + len] & 0xFF))\n\t\t\t\t{\n\t\t\t\t\t_son[ptr1] = curMatch;\n\t\t\t\t\tptr1 = cyclicPos + 1;\n\t\t\t\t\tcurMatch = _son[ptr1];\n\t\t\t\t\tlen1 = len;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t_son[ptr0] = curMatch;\n\t\t\t\t\tptr0 = cyclicPos;\n\t\t\t\t\tcurMatch = _son[ptr0];\n\t\t\t\t\tlen0 = len;\n\t\t\t\t}\n\t\t\t}\n\t\t\tMovePos();\n\t\t}\n\t\twhile (--num != 0);\n\t}\n\t\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\n\t{\n\t\tfor (int i = 0; i < numItems; i++)\n\t\t{\n\t\t\tint value = items[i];\n\t\t\tif (value <= subValue)\n\t\t\t\tvalue = kEmptyHashValue;\n\t\t\telse\n\t\t\t\tvalue -= subValue;\n\t\t\titems[i] = value;\n\t\t}\n\t}\n\t\n\tvoid Normalize()\n\t{\n\t\tint subValue = _pos - _cyclicBufferSize;\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\n\t\tNormalizeLinks(_hash, _hashSizeSum, subValue);\n\t\tReduceOffsets(subValue);\n\t}\n\t\n\tpublic void SetCutValue(int cutValue) { _cutValue = cutValue; }\n\n\tprivate static final int[] CrcTable = new int[256];\n\n\tstatic\n\t{\n\t\tfor (int i = 0; i < 256; i++)\n\t\t{\n\t\t\tint r = i;\n\t\t\tfor (int j = 0; j < 8; j++)\n\t\t\t\tif ((r & 1) != 0)\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\n\t\t\t\telse\n\t\t\t\t\tr >>>= 1;\n\t\t\tCrcTable[i] = r;\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindow\n\npackage SevenZip.Compression.LZ;\n\nimport java.io.IOException;\n\npublic class InWindow\n{\n\tpublic byte[] _bufferBase; // pointer to buffer with data\n\tjava.io.InputStream _stream;\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\n\t\n\tint _pointerToLastSafePosition;\n\t\n\tpublic int _bufferOffset;\n\t\n\tpublic int _blockSize;  // Size of Allocated memory block\n\tpublic int _pos;             // offset (from _buffer) of curent byte\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\n\t\n\tpublic void MoveBlock()\n\t{\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\n\t\t// we need one additional byte, since MovePos moves on 1 byte.\n\t\tif (offset > 0)\n\t\t\toffset--;\n\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\n\t\t\n\t\t// check negative offset ????\n\t\tfor (int i = 0; i < numBytes; i++)\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\n\t\t_bufferOffset -= offset;\n\t}\n\t\n\tpublic void ReadBlock() throws IOException\n\t{\n\t\tif (_streamEndWasReached)\n\t\t\treturn;\n\t\twhile (true)\n\t\t{\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\n\t\t\tif (size == 0)\n\t\t\t\treturn;\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\n\t\t\tif (numReadBytes == -1)\n\t\t\t{\n\t\t\t\t_posLimit = _streamPos;\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\n\t\t\t\t\n\t\t\t\t_streamEndWasReached = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t_streamPos += numReadBytes;\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\n\t\t}\n\t}\n\t\n\tvoid Free() { _bufferBase = null; }\n\t\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\n\t{\n\t\t_keepSizeBefore = keepSizeBefore;\n\t\t_keepSizeAfter = keepSizeAfter;\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\n\t\tif (_bufferBase == null || _blockSize != blockSize)\n\t\t{\n\t\t\tFree();\n\t\t\t_blockSize = blockSize;\n\t\t\t_bufferBase = new byte[_blockSize];\n\t\t}\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\n\t}\n\t\n\tpublic void SetStream(java.io.InputStream stream) { _stream = stream; \t}\n\tpublic void ReleaseStream() { _stream = null; }\n\n\tpublic void Init() throws IOException\n\t{\n\t\t_bufferOffset = 0;\n\t\t_pos = 0;\n\t\t_streamPos = 0;\n\t\t_streamEndWasReached = false;\n\t\tReadBlock();\n\t}\n\t\n\tpublic void MovePos() throws IOException\n\t{\n\t\t_pos++;\n\t\tif (_pos > _posLimit)\n\t\t{\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\n\t\t\t\tMoveBlock();\n\t\t\tReadBlock();\n\t\t}\n\t}\n\t\n\tpublic byte GetIndexByte(int index)\t{ return _bufferBase[_bufferOffset + _pos + index]; }\n\t\n\t// index + limit have not to exceed _keepSizeAfter;\n\tpublic int GetMatchLen(int index, int distance, int limit)\n\t{\n\t\tif (_streamEndWasReached)\n\t\t\tif ((_pos + index) + limit > _streamPos)\n\t\t\t\tlimit = _streamPos - (_pos + index);\n\t\tdistance++;\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\n\t\tint pby = _bufferOffset + _pos + index;\n\t\t\n\t\tint i;\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\n\t\treturn i;\n\t}\n\t\n\tpublic int GetNumAvailableBytes()\t{ return _streamPos - _pos; }\n\t\n\tpublic void ReduceOffsets(int subValue)\n\t{\n\t\t_bufferOffset += subValue;\n\t\t_posLimit -= subValue;\n\t\t_pos -= subValue;\n\t\t_streamPos -= subValue;\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\n\npackage SevenZip.Compression.LZ;\n\nimport java.io.IOException;\n\npublic class OutWindow\n{\n\tbyte[] _buffer;\n\tint _pos;\n\tint _windowSize = 0;\n\tint _streamPos;\n\tjava.io.OutputStream _stream;\n\t\n\tpublic void Create(int windowSize)\n\t{\n\t\tif (_buffer == null || _windowSize != windowSize)\n\t\t\t_buffer = new byte[windowSize];\n\t\t_windowSize = windowSize;\n\t\t_pos = 0;\n\t\t_streamPos = 0;\n\t}\n\t\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\n\t{\n\t\tReleaseStream();\n\t\t_stream = stream;\n\t}\n\t\n\tpublic void ReleaseStream() throws IOException\n\t{\n\t\tFlush();\n\t\t_stream = null;\n\t}\n\t\n\tpublic void Init(boolean solid)\n\t{\n\t\tif (!solid)\n\t\t{\n\t\t\t_streamPos = 0;\n\t\t\t_pos = 0;\n\t\t}\n\t}\n\t\n\tpublic void Flush() throws IOException\n\t{\n\t\tint size = _pos - _streamPos;\n\t\tif (size == 0)\n\t\t\treturn;\n\t\t_stream.write(_buffer, _streamPos, size);\n\t\tif (_pos >= _windowSize)\n\t\t\t_pos = 0;\n\t\t_streamPos = _pos;\n\t}\n\t\n\tpublic void CopyBlock(int distance, int len) throws IOException\n\t{\n\t\tint pos = _pos - distance - 1;\n\t\tif (pos < 0)\n\t\t\tpos += _windowSize;\n\t\tfor (; len != 0; len--)\n\t\t{\n\t\t\tif (pos >= _windowSize)\n\t\t\t\tpos = 0;\n\t\t\t_buffer[_pos++] = _buffer[pos++];\n\t\t\tif (_pos >= _windowSize)\n\t\t\t\tFlush();\n\t\t}\n\t}\n\t\n\tpublic void PutByte(byte b) throws IOException\n\t{\n\t\t_buffer[_pos++] = b;\n\t\tif (_pos >= _windowSize)\n\t\t\tFlush();\n\t}\n\t\n\tpublic byte GetByte(int distance)\n\t{\n\t\tint pos = _pos - distance - 1;\n\t\tif (pos < 0)\n\t\t\tpos += _windowSize;\n\t\treturn _buffer[pos];\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\n\npackage SevenZip.Compression.LZMA;\n\npublic class Base\n{\n\tpublic static final int kNumRepDistances = 4;\n\tpublic static final int kNumStates = 12;\n\t\n\tpublic static final int StateInit()\n\t{\n\t\treturn 0;\n\t}\n\t\n\tpublic static final int StateUpdateChar(int index)\n\t{\n\t\tif (index < 4) \n\t\t\treturn 0;\n\t\tif (index < 10) \n\t\t\treturn index - 3;\n\t\treturn index - 6;\n\t}\n\t\n\tpublic static final int StateUpdateMatch(int index)\n\t{\n\t\treturn (index < 7 ? 7 : 10); \n\t}\n\n\tpublic static final int StateUpdateRep(int index)\n\t{ \n\t\treturn (index < 7 ? 8 : 11); \n\t}\n\t\n\tpublic static final int StateUpdateShortRep(int index)\n\t{ \n\t\treturn (index < 7 ? 9 : 11); \n\t}\n\n\tpublic static final boolean StateIsCharState(int index)\n\t{ \n\t\treturn index < 7; \n\t}\n\t\n\tpublic static final int kNumPosSlotBits = 6;\n\tpublic static final int kDicLogSizeMin = 0;\n\t// public static final int kDicLogSizeMax = 28;\n\t// public static final int kDistTableSizeMax = kDicLogSizeMax * 2;\n\t\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\n\t\n\tpublic static final int kMatchMinLen = 2;\n\t\n\tpublic static final int GetLenToPosState(int len)\n\t{\n\t\tlen -= kMatchMinLen;\n\t\tif (len < kNumLenToPosStates)\n\t\t\treturn len;\n\t\treturn (int)(kNumLenToPosStates - 1);\n\t}\n\t\n\tpublic static final int kNumAlignBits = 4;\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\n\t\n\tpublic static final int kStartPosModelIndex = 4;\n\tpublic static final int kEndPosModelIndex = 14;\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\n\t\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\n\t\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\n\tpublic static final  int kNumLitContextBitsMax = 8;\n\t\n\tpublic static final  int kNumPosStatesBitsMax = 4;\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\n\t\n\tpublic static final  int kNumLowLenBits = 3;\n\tpublic static final  int kNumMidLenBits = 3;\n\tpublic static final  int kNumHighLenBits = 8;\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\n\t\t\t(1 << kNumHighLenBits);\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\n\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\nimport SevenZip.Compression.LZMA.Base;\nimport SevenZip.Compression.LZ.OutWindow;\nimport java.io.IOException;\n\npublic class Decoder\n{\n\tclass LenDecoder\n\t{\n\t\tshort[] m_Choice = new short[2];\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\n\t\tint m_NumPosStates = 0;\n\t\t\n\t\tpublic void Create(int numPosStates)\n\t\t{\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\n\t\t\t{\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic void Init()\n\t\t{\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\n\t\t\t{\n\t\t\t\tm_LowCoder[posState].Init();\n\t\t\t\tm_MidCoder[posState].Init();\n\t\t\t}\n\t\t\tm_HighCoder.Init();\n\t\t}\n\t\t\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\n\t\t{\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\n\t\t\tint symbol = Base.kNumLowLenSymbols;\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\n\t\t\telse\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\n\t\t\treturn symbol;\n\t\t}\n\t}\n\t\n\tclass LiteralDecoder\n\t{\n\t\tclass Decoder2\n\t\t{\n\t\t\tshort[] m_Decoders = new short[0x300];\n\t\t\t\n\t\t\tpublic void Init()\n\t\t\t{\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\n\t\t\t}\n\t\t\t\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\n\t\t\t{\n\t\t\t\tint symbol = 1;\n\t\t\t\tdo\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\n\t\t\t\twhile (symbol < 0x100);\n\t\t\t\treturn (byte)symbol;\n\t\t\t}\n\t\t\t\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\n\t\t\t{\n\t\t\t\tint symbol = 1;\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\n\t\t\t\t\tmatchByte <<= 1;\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\n\t\t\t\t\tif (matchBit != bit)\n\t\t\t\t\t{\n\t\t\t\t\t\twhile (symbol < 0x100)\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twhile (symbol < 0x100);\n\t\t\t\treturn (byte)symbol;\n\t\t\t}\n\t\t}\n\t\t\n\t\tDecoder2[] m_Coders;\n\t\tint m_NumPrevBits;\n\t\tint m_NumPosBits;\n\t\tint m_PosMask;\n\t\t\n\t\tpublic void Create(int numPosBits, int numPrevBits)\n\t\t{\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\n\t\t\t\treturn;\n\t\t\tm_NumPosBits = numPosBits;\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\n\t\t\tm_NumPrevBits = numPrevBits;\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\n\t\t\tm_Coders = new Decoder2[numStates];\n\t\t\tfor (int i = 0; i < numStates; i++)\n\t\t\t\tm_Coders[i] = new Decoder2();\n\t\t}\n\t\t\n\t\tpublic void Init()\n\t\t{\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\n\t\t\tfor (int i = 0; i < numStates; i++)\n\t\t\t\tm_Coders[i].Init();\n\t\t}\n\t\t\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\n\t\t{\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\n\t\t}\n\t}\n\t\n\tOutWindow m_OutWindow = new OutWindow();\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\n\t\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\n\t\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\n\t\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\n\t\n\tLenDecoder m_LenDecoder = new LenDecoder();\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\n\t\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\n\t\n\tint m_DictionarySize = -1;\n\tint m_DictionarySizeCheck =  -1;\n\t\n\tint m_PosStateMask;\n\t\n\tpublic Decoder()\n\t{\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\n\t}\n\t\n\tboolean SetDictionarySize(int dictionarySize)\n\t{\n\t\tif (dictionarySize < 0)\n\t\t\treturn false;\n\t\tif (m_DictionarySize != dictionarySize)\n\t\t{\n\t\t\tm_DictionarySize = dictionarySize;\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tboolean SetLcLpPb(int lc, int lp, int pb)\n\t{\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\n\t\t\treturn false;\n\t\tm_LiteralDecoder.Create(lp, lc);\n\t\tint numPosStates = 1 << pb;\n\t\tm_LenDecoder.Create(numPosStates);\n\t\tm_RepLenDecoder.Create(numPosStates);\n\t\tm_PosStateMask = numPosStates - 1;\n\t\treturn true;\n\t}\n\t\n\tvoid Init() throws IOException\n\t{\n\t\tm_OutWindow.Init(false);\n\t\t\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\n\t\t\n\t\tm_LiteralDecoder.Init();\n\t\tint i;\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\n\t\t\tm_PosSlotDecoder[i].Init();\n\t\tm_LenDecoder.Init();\n\t\tm_RepLenDecoder.Init();\n\t\tm_PosAlignDecoder.Init();\n\t\tm_RangeDecoder.Init();\n\t}\n\t\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\n\t\t\tlong outSize) throws IOException\n\t{\n\t\tm_RangeDecoder.SetStream(inStream);\n\t\tm_OutWindow.SetStream(outStream);\n\t\tInit();\n\t\t\n\t\tint state = Base.StateInit();\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\n\t\t\n\t\tlong nowPos64 = 0;\n\t\tbyte prevByte = 0;\n\t\twhile (outSize < 0 || nowPos64 < outSize)\n\t\t{\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\n\t\t\t{\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\n\t\t\t\tif (!Base.StateIsCharState(state))\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\n\t\t\t\telse\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\n\t\t\t\tm_OutWindow.PutByte(prevByte);\n\t\t\t\tstate = Base.StateUpdateChar(state);\n\t\t\t\tnowPos64++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint len;\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\n\t\t\t\t{\n\t\t\t\t\tlen = 0;\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\n\t\t\t\t\t\t\tlen = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tint distance;\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\n\t\t\t\t\t\t\tdistance = rep1;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\n\t\t\t\t\t\t\t\tdistance = rep2;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdistance = rep3;\n\t\t\t\t\t\t\t\trep3 = rep2;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\trep2 = rep1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\trep1 = rep0;\n\t\t\t\t\t\trep0 = distance;\n\t\t\t\t\t}\n\t\t\t\t\tif (len == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\trep3 = rep2;\n\t\t\t\t\trep2 = rep1;\n\t\t\t\t\trep1 = rep0;\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\n\t\t\t\t\t{\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\n\t\t\t\t\t\t\tif (rep0 < 0)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (rep0 == -1)\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\trep0 = posSlot;\n\t\t\t\t}\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\n\t\t\t\t{\n\t\t\t\t\t// m_OutWindow.Flush();\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\n\t\t\t\tnowPos64 += len;\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\n\t\t\t}\n\t\t}\n\t\tm_OutWindow.Flush();\n\t\tm_OutWindow.ReleaseStream();\n\t\tm_RangeDecoder.ReleaseStream();\n\t\treturn true;\n\t}\n\t\n\tpublic boolean SetDecoderProperties(byte[] properties)\n\t{\n\t\tif (properties.length < 5)\n\t\t\treturn false;\n\t\tint val = properties[0] & 0xFF;\n\t\tint lc = val % 9;\n\t\tint remainder = val / 9;\n\t\tint lp = remainder % 5;\n\t\tint pb = remainder / 5;\n\t\tint dictionarySize = 0;\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\n\t\tif (!SetLcLpPb(lc, lp, pb))\n\t\t\treturn false;\n\t\treturn SetDictionarySize(dictionarySize);\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\n\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\nimport SevenZip.Compression.LZMA.Base;\nimport SevenZip.Compression.LZ.BinTree;\nimport SevenZip.ICodeProgress;\nimport java.io.IOException;\n\npublic class Encoder\n{\n\tpublic static final int EMatchFinderTypeBT2 = 0;\n\tpublic static final int EMatchFinderTypeBT4 = 1;\n\n\n\n\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\n\n\tstatic byte[] g_FastPos = new byte[1 << 11];\n\n\tstatic\n\t{\n\t\tint kFastSlots = 22;\n\t\tint c = 2;\n\t\tg_FastPos[0] = 0;\n\t\tg_FastPos[1] = 1;\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\n\t\t{\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\n\t\t\tfor (int j = 0; j < k; j++, c++)\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\n\t\t}\n\t}\n\n\tstatic int GetPosSlot(int pos)\n\t{\n\t\tif (pos < (1 << 11))\n\t\t\treturn g_FastPos[pos];\n\t\tif (pos < (1 << 21))\n\t\t\treturn (g_FastPos[pos >> 10] + 20);\n\t\treturn (g_FastPos[pos >> 20] + 40);\n\t}\n\n\tstatic int GetPosSlot2(int pos)\n\t{\n\t\tif (pos < (1 << 17))\n\t\t\treturn (g_FastPos[pos >> 6] + 12);\n\t\tif (pos < (1 << 27))\n\t\t\treturn (g_FastPos[pos >> 16] + 32);\n\t\treturn (g_FastPos[pos >> 26] + 52);\n\t}\n\n\tint _state = Base.StateInit();\n\tbyte _previousByte;\n\tint[] _repDistances = new int[Base.kNumRepDistances];\n\n\tvoid BaseInit()\n\t{\n\t\t_state = Base.StateInit();\n\t\t_previousByte = 0;\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\n\t\t\t_repDistances[i] = 0;\n\t}\n\n\tstatic final int kDefaultDictionaryLogSize = 22;\n\tstatic final int kNumFastBytesDefault = 0x20;\n\n\tclass LiteralEncoder\n\t{\n\t\tclass Encoder2\n\t\t{\n\t\t\tshort[] m_Encoders = new short[0x300];\n\n\t\t\tpublic void Init() { SevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders); }\n\n\n\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\n\t\t\t{\n\t\t\t\tint context = 1;\n\t\t\t\tfor (int i = 7; i >= 0; i--)\n\t\t\t\t{\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\n\t\t\t\t\tcontext = (context << 1) | bit;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\n\t\t\t{\n\t\t\t\tint context = 1;\n\t\t\t\tboolean same = true;\n\t\t\t\tfor (int i = 7; i >= 0; i--)\n\t\t\t\t{\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\n\t\t\t\t\tint state = context;\n\t\t\t\t\tif (same)\n\t\t\t\t\t{\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\n\t\t\t\t\t\tsame = (matchBit == bit);\n\t\t\t\t\t}\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\n\t\t\t\t\tcontext = (context << 1) | bit;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\n\t\t\t{\n\t\t\t\tint price = 0;\n\t\t\t\tint context = 1;\n\t\t\t\tint i = 7;\n\t\t\t\tif (matchMode)\n\t\t\t\t{\n\t\t\t\t\tfor (; i >= 0; i--)\n\t\t\t\t\t{\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\n\t\t\t\t\t\tcontext = (context << 1) | bit;\n\t\t\t\t\t\tif (matchBit != bit)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ti--;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (; i >= 0; i--)\n\t\t\t\t{\n\t\t\t\t\tint bit = (symbol >> i) & 1;\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\n\t\t\t\t\tcontext = (context << 1) | bit;\n\t\t\t\t}\n\t\t\t\treturn price;\n\t\t\t}\n\t\t}\n\n\t\tEncoder2[] m_Coders;\n\t\tint m_NumPrevBits;\n\t\tint m_NumPosBits;\n\t\tint m_PosMask;\n\n\t\tpublic void Create(int numPosBits, int numPrevBits)\n\t\t{\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\n\t\t\t\treturn;\n\t\t\tm_NumPosBits = numPosBits;\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\n\t\t\tm_NumPrevBits = numPrevBits;\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\n\t\t\tm_Coders = new Encoder2[numStates];\n\t\t\tfor (int i = 0; i < numStates; i++)\n\t\t\t\tm_Coders[i] = new Encoder2();\n\t\t}\n\n\t\tpublic void Init()\n\t\t{\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\n\t\t\tfor (int i = 0; i < numStates; i++)\n\t\t\t\tm_Coders[i].Init();\n\t\t}\n\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\n\t}\n\n\tclass LenEncoder\n\t{\n\t\tshort[] _choice = new short[2];\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\n\n\n\t\tpublic LenEncoder()\n\t\t{\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\n\t\t\t{\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\n\t\t\t}\n\t\t}\n\n\t\tpublic void Init(int numPosStates)\n\t\t{\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\n\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\n\t\t\t{\n\t\t\t\t_lowCoder[posState].Init();\n\t\t\t\t_midCoder[posState].Init();\n\t\t\t}\n\t\t\t_highCoder.Init();\n\t\t}\n\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\n\t\t{\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\n\t\t\t{\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\n\t\t\t\t{\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic void SetPrices(int posState, int numSymbols, int[] prices, int st)\n\t\t{\n\t\t\tint a0 = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\n\t\t\tint a1 = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\n\t\t\tint b0 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\n\t\t\tint b1 = a1 + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\n\t\t\tint i = 0;\n\t\t\tfor (i = 0; i < Base.kNumLowLenSymbols; i++)\n\t\t\t{\n\t\t\t\tif (i >= numSymbols)\n\t\t\t\t\treturn;\n\t\t\t\tprices[st + i] = a0 + _lowCoder[posState].GetPrice(i);\n\t\t\t}\n\t\t\tfor (; i < Base.kNumLowLenSymbols + Base.kNumMidLenSymbols; i++)\n\t\t\t{\n\t\t\t\tif (i >= numSymbols)\n\t\t\t\t\treturn;\n\t\t\t\tprices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.kNumLowLenSymbols);\n\t\t\t}\n\t\t\tfor (; i < numSymbols; i++)\n\t\t\t\tprices[st + i] = b1 + _highCoder.GetPrice(i - Base.kNumLowLenSymbols - Base.kNumMidLenSymbols);\n\t\t}\n\t};\n\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\n\n\tclass LenPriceTableEncoder extends LenEncoder\n\t{\n\t\tint[] _prices = new int[Base.kNumLenSymbols<<Base.kNumPosStatesBitsEncodingMax];\n\t\tint _tableSize;\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\n\n\t\tpublic void SetTableSize(int tableSize) { _tableSize = tableSize; }\n\n\t\tpublic int GetPrice(int symbol, int posState)\n\t\t{\n\t\t\treturn _prices[posState * Base.kNumLenSymbols + symbol];\n\t\t}\n\n\t\tvoid UpdateTable(int posState)\n\t\t{\n\t\t\tSetPrices(posState, _tableSize, _prices, posState * Base.kNumLenSymbols);\n\t\t\t_counters[posState] = _tableSize;\n\t\t}\n\n\t\tpublic void UpdateTables(int numPosStates)\n\t\t{\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\n\t\t\t\tUpdateTable(posState);\n\t\t}\n\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\n\t\t{\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\n\t\t\tif (--_counters[posState] == 0)\n\t\t\t\tUpdateTable(posState);\n\t\t}\n\t}\n\n\tstatic final int kNumOpts = 1 << 12;\n\tclass Optimal\n\t{\n\t\tpublic int State;\n\n\t\tpublic boolean Prev1IsChar;\n\t\tpublic boolean Prev2;\n\n\t\tpublic int PosPrev2;\n\t\tpublic int BackPrev2;\n\n\t\tpublic int Price;\n\t\tpublic int PosPrev;\n\t\tpublic int BackPrev;\n\n\t\tpublic int Backs0;\n\t\tpublic int Backs1;\n\t\tpublic int Backs2;\n\t\tpublic int Backs3;\n\n\t\tpublic void MakeAsChar() { BackPrev = -1; Prev1IsChar = false; }\n\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\n\t\tpublic boolean IsShortRep() { return (BackPrev == 0); }\n\t};\n\tOptimal[] _optimum = new Optimal[kNumOpts];\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null;\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\n\n\tshort[] _isMatch = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\n\tshort[] _isRep = new short[Base.kNumStates];\n\tshort[] _isRepG0 = new short[Base.kNumStates];\n\tshort[] _isRepG1 = new short[Base.kNumStates];\n\tshort[] _isRepG2 = new short[Base.kNumStates];\n\tshort[] _isRep0Long = new short[Base.kNumStates<<Base.kNumPosStatesBitsMax];\n\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\n\n\tshort[] _posEncoders = new short[Base.kNumFullDistances-Base.kEndPosModelIndex];\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\n\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\n\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\n\n\tint[] _matchDistances = new int[Base.kMatchMaxLen*2+2];\n\n\tint _numFastBytes = kNumFastBytesDefault;\n\tint _longestMatchLength;\n\tint _numDistancePairs;\n\n\tint _additionalOffset;\n\n\tint _optimumEndIndex;\n\tint _optimumCurrentIndex;\n\n\tboolean _longestMatchWasFound;\n\n\tint[] _posSlotPrices = new int[1<<(Base.kNumPosSlotBits+Base.kNumLenToPosStatesBits)];\n\tint[] _distancesPrices = new int[Base.kNumFullDistances<<Base.kNumLenToPosStatesBits];\n\tint[] _alignPrices = new int[Base.kAlignTableSize];\n\tint _alignPriceCount;\n\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\n\n\tint _posStateBits = 2;\n\tint _posStateMask = (4 - 1);\n\tint _numLiteralPosStateBits = 0;\n\tint _numLiteralContextBits = 3;\n\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\n\tint _dictionarySizePrev = -1;\n\tint _numFastBytesPrev = -1;\n\n\tlong nowPos64;\n\tboolean _finished;\n\tjava.io.InputStream _inStream;\n\n\tint _matchFinderType = EMatchFinderTypeBT4;\n\tboolean _writeEndMark = false;\n\n\tboolean _needReleaseMFStream = false;\n\n\tvoid Create()\n\t{\n\t\tif (_matchFinder == null)\n\t\t{\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\n\t\t\tint numHashBytes = 4;\n\t\t\tif (_matchFinderType == EMatchFinderTypeBT2)\n\t\t\t\tnumHashBytes = 2;\n\t\t\tbt.SetType(numHashBytes);\n\t\t\t_matchFinder = bt;\n\t\t}\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\n\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\n\t\t\treturn;\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes, Base.kMatchMaxLen + 1);\n\t\t_dictionarySizePrev = _dictionarySize;\n\t\t_numFastBytesPrev = _numFastBytes;\n\t}\n\n\tpublic Encoder()\n\t{\n\t\tfor (int i = 0; i < kNumOpts; i++)\n\t\t\t_optimum[i] = new Optimal();\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\n\t}\n\n\tvoid SetWriteEndMarkerMode(boolean writeEndMarker)\n\t{\n\t\t_writeEndMark = writeEndMarker;\n\t}\n\n\tvoid Init()\n\t{\n\t\tBaseInit();\n\t\t_rangeEncoder.Init();\n\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\n\n\n\n\n\n\n\n\t\t_literalEncoder.Init();\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\n\t\t\t_posSlotEncoder[i].Init();\n\n\n\n\t\t_lenEncoder.Init(1 << _posStateBits);\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\n\n\t\t_posAlignEncoder.Init();\n\n\t\t_longestMatchWasFound = false;\n\t\t_optimumEndIndex = 0;\n\t\t_optimumCurrentIndex = 0;\n\t\t_additionalOffset = 0;\n\t}\n\n\tint ReadMatchDistances() throws java.io.IOException\n\t{\n\t\tint lenRes = 0;\n\t\t_numDistancePairs = _matchFinder.GetMatches(_matchDistances);\n\t\tif (_numDistancePairs > 0)\n\t\t{\n\t\t\tlenRes = _matchDistances[_numDistancePairs - 2];\n\t\t\tif (lenRes == _numFastBytes)\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[_numDistancePairs - 1],\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\n\t\t}\n\t\t_additionalOffset++;\n\t\treturn lenRes;\n\t}\n\n\tvoid MovePos(int num) throws java.io.IOException\n\t{\n\t\tif (num > 0)\n\t\t{\n\t\t\t_matchFinder.Skip(num);\n\t\t\t_additionalOffset += num;\n\t\t}\n\t}\n\n\tint GetRepLen1Price(int state, int posState)\n\t{\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\n\t}\n\n\tint GetPureRepPrice(int repIndex, int state, int posState)\n\t{\n\t\tint price;\n\t\tif (repIndex == 0)\n\t\t{\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\n\t\t\tif (repIndex == 1)\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\n\t\t\telse\n\t\t\t{\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\n\t\t\t}\n\t\t}\n\t\treturn price;\n\t}\n\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\n\t{\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\n\t\treturn price + GetPureRepPrice(repIndex, state, posState);\n\t}\n\n\tint GetPosLenPrice(int pos, int len, int posState)\n\t{\n\t\tint price;\n\t\tint lenToPosState = Base.GetLenToPosState(len);\n\t\tif (pos < Base.kNumFullDistances)\n\t\t\tprice = _distancesPrices[(lenToPosState * Base.kNumFullDistances) + pos];\n\t\telse\n\t\t\tprice = _posSlotPrices[(lenToPosState << Base.kNumPosSlotBits) + GetPosSlot2(pos)] +\n\t\t\t\t_alignPrices[pos & Base.kAlignMask];\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\n\t}\n\n\tint Backward(int cur)\n\t{\n\t\t_optimumEndIndex = cur;\n\t\tint posMem = _optimum[cur].PosPrev;\n\t\tint backMem = _optimum[cur].BackPrev;\n\t\tdo\n\t\t{\n\t\t\tif (_optimum[cur].Prev1IsChar)\n\t\t\t{\n\t\t\t\t_optimum[posMem].MakeAsChar();\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\n\t\t\t\tif (_optimum[cur].Prev2)\n\t\t\t\t{\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint posPrev = posMem;\n\t\t\tint backCur = backMem;\n\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\n\t\t\tposMem = _optimum[posPrev].PosPrev;\n\n\t\t\t_optimum[posPrev].BackPrev = backCur;\n\t\t\t_optimum[posPrev].PosPrev = cur;\n\t\t\tcur = posPrev;\n\t\t}\n\t\twhile (cur > 0);\n\t\tbackRes = _optimum[0].BackPrev;\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\n\t\treturn _optimumCurrentIndex;\n\t}\n\n\tint[] reps = new int[Base.kNumRepDistances];\n\tint[] repLens = new int[Base.kNumRepDistances];\n\tint backRes;\n\n\tint GetOptimum(int position) throws IOException\n\t{\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\n\t\t{\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\n\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\n\t\t\treturn lenRes;\n\t\t}\n\t\t_optimumCurrentIndex = _optimumEndIndex = 0;\n\n\t\tint lenMain, numDistancePairs;\n\t\tif (!_longestMatchWasFound)\n\t\t{\n\t\t\tlenMain = ReadMatchDistances();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlenMain = _longestMatchLength;\n\t\t\t_longestMatchWasFound = false;\n\t\t}\n\t\tnumDistancePairs = _numDistancePairs;\n\n\t\tint numAvailableBytes = _matchFinder.GetNumAvailableBytes() + 1;\n\t\tif (numAvailableBytes < 2)\n\t\t{\n\t\t\tbackRes = -1;\n\t\t\treturn 1;\n\t\t}\n\t\tif (numAvailableBytes > Base.kMatchMaxLen)\n\t\t\tnumAvailableBytes = Base.kMatchMaxLen;\n\n\t\tint repMaxIndex = 0;\n\t\tint i;\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\n\t\t{\n\t\t\treps[i] = _repDistances[i];\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\n\t\t\tif (repLens[i] > repLens[repMaxIndex])\n\t\t\t\trepMaxIndex = i;\n\t\t}\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\n\t\t{\n\t\t\tbackRes = repMaxIndex;\n\t\t\tint lenRes = repLens[repMaxIndex];\n\t\t\tMovePos(lenRes - 1);\n\t\t\treturn lenRes;\n\t\t}\n\n\t\tif (lenMain >= _numFastBytes)\n\t\t{\n\t\t\tbackRes = _matchDistances[numDistancePairs - 1] + Base.kNumRepDistances;\n\t\t\tMovePos(lenMain - 1);\n\t\t\treturn lenMain;\n\t\t}\n\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\n\t\tbyte matchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\n\n\t\tif (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)\n\t\t{\n\t\t\tbackRes = -1;\n\t\t\treturn 1;\n\t\t}\n\n\t\t_optimum[0].State = _state;\n\n\t\tint posState = (position & _posStateMask);\n\n\t\t_optimum[1].Price = SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\n\t\t_optimum[1].MakeAsChar();\n\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\n\n\t\tif (matchByte == currentByte)\n\t\t{\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\n\t\t\tif (shortRepPrice < _optimum[1].Price)\n\t\t\t{\n\t\t\t\t_optimum[1].Price = shortRepPrice;\n\t\t\t\t_optimum[1].MakeAsShortRep();\n\t\t\t}\n\t\t}\n\n\t\tint lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);\n\n\t\tif (lenEnd < 2)\n\t\t{\n\t\t\tbackRes = _optimum[1].BackPrev;\n\t\t\treturn 1;\n\t\t}\n\n\t\t_optimum[1].PosPrev = 0;\n\n\t\t_optimum[0].Backs0 = reps[0];\n\t\t_optimum[0].Backs1 = reps[1];\n\t\t_optimum[0].Backs2 = reps[2];\n\t\t_optimum[0].Backs3 = reps[3];\n\n\t\tint len = lenEnd;\n\t\tdo\n\t\t\t_optimum[len--].Price = kIfinityPrice;\n\t\twhile (len >= 2);\n\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\n\t\t{\n\t\t\tint repLen = repLens[i];\n\t\t\tif (repLen < 2)\n\t\t\t\tcontinue;\n\t\t\tint price = repMatchPrice + GetPureRepPrice(i, _state, posState);\n\t\t\tdo\n\t\t\t{\n\t\t\t\tint curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);\n\t\t\t\tOptimal optimum = _optimum[repLen];\n\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t{\n\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\toptimum.PosPrev = 0;\n\t\t\t\t\toptimum.BackPrev = i;\n\t\t\t\t\toptimum.Prev1IsChar = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (--repLen >= 2);\n\t\t}\n\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\n\n\t\tlen = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);\n\t\tif (len <= lenMain)\n\t\t{\n\t\t\tint offs = 0;\n\t\t\twhile (len > _matchDistances[offs])\n\t\t\t\toffs += 2;\n\t\t\tfor (; ; len++)\n\t\t\t{\n\t\t\t\tint distance = _matchDistances[offs + 1];\n\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);\n\t\t\t\tOptimal optimum = _optimum[len];\n\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t{\n\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\toptimum.PosPrev = 0;\n\t\t\t\t\toptimum.BackPrev = distance + Base.kNumRepDistances;\n\t\t\t\t\toptimum.Prev1IsChar = false;\n\t\t\t\t}\n\t\t\t\tif (len == _matchDistances[offs])\n\t\t\t\t{\n\t\t\t\t\toffs += 2;\n\t\t\t\t\tif (offs == numDistancePairs)\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint cur = 0;\n\n\t\twhile (true)\n\t\t{\n\t\t\tcur++;\n\t\t\tif (cur == lenEnd)\n\t\t\t\treturn Backward(cur);\n\t\t\tint newLen = ReadMatchDistances();\n\t\t\tnumDistancePairs = _numDistancePairs;\n\t\t\tif (newLen >= _numFastBytes)\n\t\t\t{\n\n\t\t\t\t_longestMatchLength = newLen;\n\t\t\t\t_longestMatchWasFound = true;\n\t\t\t\treturn Backward(cur);\n\t\t\t}\n\t\t\tposition++;\n\t\t\tint posPrev = _optimum[cur].PosPrev;\n\t\t\tint state;\n\t\t\tif (_optimum[cur].Prev1IsChar)\n\t\t\t{\n\t\t\t\tposPrev--;\n\t\t\t\tif (_optimum[cur].Prev2)\n\t\t\t\t{\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\n\t\t\t\t\telse\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tstate = _optimum[posPrev].State;\n\t\t\t\tstate = Base.StateUpdateChar(state);\n\t\t\t}\n\t\t\telse\n\t\t\t\tstate = _optimum[posPrev].State;\n\t\t\tif (posPrev == cur - 1)\n\t\t\t{\n\t\t\t\tif (_optimum[cur].IsShortRep())\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\n\t\t\t\telse\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint pos;\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\n\t\t\t\t{\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\n\t\t\t\t\telse\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\n\t\t\t\t}\n\t\t\t\tOptimal opt = _optimum[posPrev];\n\t\t\t\tif (pos < Base.kNumRepDistances)\n\t\t\t\t{\n\t\t\t\t\tif (pos == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\treps[0] = opt.Backs0;\n\t\t\t\t\t\treps[1] = opt.Backs1;\n\t\t\t\t\t\treps[2] = opt.Backs2;\n\t\t\t\t\t\treps[3] = opt.Backs3;\n\t\t\t\t\t}\n\t\t\t\t\telse if (pos == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\treps[0] = opt.Backs1;\n\t\t\t\t\t\treps[1] = opt.Backs0;\n\t\t\t\t\t\treps[2] = opt.Backs2;\n\t\t\t\t\t\treps[3] = opt.Backs3;\n\t\t\t\t\t}\n\t\t\t\t\telse if (pos == 2)\n\t\t\t\t\t{\n\t\t\t\t\t\treps[0] = opt.Backs2;\n\t\t\t\t\t\treps[1] = opt.Backs0;\n\t\t\t\t\t\treps[2] = opt.Backs1;\n\t\t\t\t\t\treps[3] = opt.Backs3;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\treps[0] = opt.Backs3;\n\t\t\t\t\t\treps[1] = opt.Backs0;\n\t\t\t\t\t\treps[2] = opt.Backs1;\n\t\t\t\t\t\treps[3] = opt.Backs2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\n\t\t\t\t\treps[1] = opt.Backs0;\n\t\t\t\t\treps[2] = opt.Backs1;\n\t\t\t\t\treps[3] = opt.Backs2;\n\t\t\t\t}\n\t\t\t}\n\t\t\t_optimum[cur].State = state;\n\t\t\t_optimum[cur].Backs0 = reps[0];\n\t\t\t_optimum[cur].Backs1 = reps[1];\n\t\t\t_optimum[cur].Backs2 = reps[2];\n\t\t\t_optimum[cur].Backs3 = reps[3];\n\t\t\tint curPrice = _optimum[cur].Price;\n\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\n\n\t\t\tposState = (position & _posStateMask);\n\n\t\t\tint curAnd1Price = curPrice +\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\n\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\n\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\n\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\n\n\t\t\tboolean nextIsChar = false;\n\t\t\tif (curAnd1Price < nextOptimum.Price)\n\t\t\t{\n\t\t\t\tnextOptimum.Price = curAnd1Price;\n\t\t\t\tnextOptimum.PosPrev = cur;\n\t\t\t\tnextOptimum.MakeAsChar();\n\t\t\t\tnextIsChar = true;\n\t\t\t}\n\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\n\n\t\t\tif (matchByte == currentByte &&\n\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\n\t\t\t{\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\n\t\t\t\t{\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\n\t\t\t\t\tnextOptimum.PosPrev = cur;\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\n\t\t\t\t\tnextIsChar = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\n\t\t\tnumAvailableBytes = numAvailableBytesFull;\n\n\t\t\tif (numAvailableBytes < 2)\n\t\t\t\tcontinue;\n\t\t\tif (numAvailableBytes > _numFastBytes)\n\t\t\t\tnumAvailableBytes = _numFastBytes;\n\t\t\tif (!nextIsChar && matchByte != currentByte)\n\t\t\t{\n\t\t\t\t// try Literal + rep0\n\t\t\t\tint t = Math.min(numAvailableBytesFull - 1, _numFastBytes);\n\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(0, reps[0], t);\n\t\t\t\tif (lenTest2 >= 2)\n\t\t\t\t{\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\n\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\n\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\n\t\t\t\t\t{\n\t\t\t\t\t\tint offset = cur + 1 + lenTest2;\n\t\t\t\t\t\twhile (lenEnd < offset)\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\n\t\t\t\t\t\tOptimal optimum = _optimum[offset];\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\n\t\t\t\t\t\t\toptimum.Prev2 = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tint startLen = 2; // speed optimization \n\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\n\t\t\t{\n\t\t\t\tint lenTest = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], numAvailableBytes);\n\t\t\t\tif (lenTest < 2)\n\t\t\t\t\tcontinue;\n\t\t\t\tint lenTestTemp = lenTest;\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t{\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\toptimum.PosPrev = cur;\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twhile (--lenTest >= 2);\n\t\t\t\tlenTest = lenTestTemp;\n\n\t\t\t\tif (repIndex == 0)\n\t\t\t\t\tstartLen = lenTest + 1;\n\n\t\t\t\t// if (_maxMode)\n\t\t\t\tif (lenTest < numAvailableBytesFull)\n\t\t\t\t{\n\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\n\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, reps[repIndex], t);\n\t\t\t\t\tif (lenTest2 >= 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\n\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\n\t\t\t\t\t\tint curAndLenCharPrice =\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - (reps[repIndex] + 1)),\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\n\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\n\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (newLen > numAvailableBytes)\n\t\t\t{\n\t\t\t\tnewLen = numAvailableBytes;\n\t\t\t\tfor (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) ;\n\t\t\t\t_matchDistances[numDistancePairs] = newLen;\n\t\t\t\tnumDistancePairs += 2;\n\t\t\t}\n\t\t\tif (newLen >= startLen)\n\t\t\t{\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\n\t\t\t\twhile (lenEnd < cur + newLen)\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\n\t\t\t\tint offs = 0;\n\t\t\t\twhile (startLen > _matchDistances[offs])\n\t\t\t\t\toffs += 2;\n\n\t\t\t\tfor (int lenTest = startLen; ; lenTest++)\n\t\t\t\t{\n\t\t\t\t\tint curBack = _matchDistances[offs + 1];\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t{\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\toptimum.PosPrev = cur;\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (lenTest == _matchDistances[offs])\n\t\t\t\t\t{\n\t\t\t\t\t\tif (lenTest < numAvailableBytesFull)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint t = Math.min(numAvailableBytesFull - 1 - lenTest, _numFastBytes);\n\t\t\t\t\t\t\tint lenTest2 = _matchFinder.GetMatchLen(lenTest, curBack, t);\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\n\n\t\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\n\t\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\n\t\t\t\t\t\t\t\t\tGetPrice(true,\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - (curBack + 1) - 1),\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\n\t\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\n\t\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\n\t\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\n\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\toffs += 2;\n\t\t\t\t\t\tif (offs == numDistancePairs)\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tboolean ChangePair(int smallDist, int bigDist)\n\t{\n\t\tint kDif = 7;\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\n\t}\n\n\tvoid WriteEndMarker(int posState) throws IOException\n\t{\n\t\tif (!_writeEndMark)\n\t\t\treturn;\n\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\n\t\t_state = Base.StateUpdateMatch(_state);\n\t\tint len = Base.kMatchMinLen;\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\n\t\tint lenToPosState = Base.GetLenToPosState(len);\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\n\t\tint footerBits = 30;\n\t\tint posReduced = (1 << footerBits) - 1;\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\n\t}\n\n\tvoid Flush(int nowPos) throws IOException\n\t{\n\t\tReleaseMFStream();\n\t\tWriteEndMarker(nowPos & _posStateMask);\n\t\t_rangeEncoder.FlushData();\n\t\t_rangeEncoder.FlushStream();\n\t}\n\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\n\t{\n\t\tinSize[0] = 0;\n\t\toutSize[0] = 0;\n\t\tfinished[0] = true;\n\n\t\tif (_inStream != null)\n\t\t{\n\t\t\t_matchFinder.SetStream(_inStream);\n\t\t\t_matchFinder.Init();\n\t\t\t_needReleaseMFStream = true;\n\t\t\t_inStream = null;\n\t\t}\n\n\t\tif (_finished)\n\t\t\treturn;\n\t\t_finished = true;\n\n\n\t\tlong progressPosValuePrev = nowPos64;\n\t\tif (nowPos64 == 0)\n\t\t{\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\n\t\t\t{\n\t\t\t\tFlush((int)nowPos64);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tReadMatchDistances();\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\n\t\t\t_state = Base.StateUpdateChar(_state);\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\n\t\t\t_previousByte = curByte;\n\t\t\t_additionalOffset--;\n\t\t\tnowPos64++;\n\t\t}\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\n\t\t{\n\t\t\tFlush((int)nowPos64);\n\t\t\treturn;\n\t\t}\n\t\twhile (true)\n\t\t{\n\n\t\t\tint len = GetOptimum((int)nowPos64);\n\t\t\tint pos = backRes;\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\n\t\t\tif (len == 1 && pos == -1)\n\t\t\t{\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\n\t\t\t\tif (!Base.StateIsCharState(_state))\n\t\t\t\t{\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\n\t\t\t\t_previousByte = curByte;\n\t\t\t\t_state = Base.StateUpdateChar(_state);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\n\t\t\t\tif (pos < Base.kNumRepDistances)\n\t\t\t\t{\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\n\t\t\t\t\tif (pos == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\n\t\t\t\t\t\tif (len == 1)\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\n\t\t\t\t\t\tif (pos == 1)\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (len == 1)\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\n\t\t\t\t\t}\n\t\t\t\t\tint distance = _repDistances[pos];\n\t\t\t\t\tif (pos != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\n\t\t\t\t\t\t_repDistances[0] = distance;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\n\t\t\t\t\tpos -= Base.kNumRepDistances;\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\n\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\n\t\t\t\t\t{\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\n\t\t\t\t\t\tint posReduced = pos - baseVal;\n\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\n\t\t\t\t\t\t\t_alignPriceCount++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint distance = pos;\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\n\t\t\t\t\t_repDistances[0] = distance;\n\t\t\t\t\t_matchPriceCount++;\n\t\t\t\t}\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\n\t\t\t}\n\t\t\t_additionalOffset -= len;\n\t\t\tnowPos64 += len;\n\t\t\tif (_additionalOffset == 0)\n\t\t\t{\n\t\t\t\t// if (!_fastMode)\n\t\t\t\tif (_matchPriceCount >= (1 << 7))\n\t\t\t\t\tFillDistancesPrices();\n\t\t\t\tif (_alignPriceCount >= Base.kAlignTableSize)\n\t\t\t\t\tFillAlignPrices();\n\t\t\t\tinSize[0] = nowPos64;\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\n\t\t\t\t{\n\t\t\t\t\tFlush((int)nowPos64);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\n\t\t\t\t{\n\t\t\t\t\t_finished = false;\n\t\t\t\t\tfinished[0] = false;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid ReleaseMFStream()\n\t{\n\t\tif (_matchFinder != null && _needReleaseMFStream)\n\t\t{\n\t\t\t_matchFinder.ReleaseStream();\n\t\t\t_needReleaseMFStream = false;\n\t\t}\n\t}\n\n\tvoid SetOutStream(java.io.OutputStream outStream)\n\t{ _rangeEncoder.SetStream(outStream); }\n\tvoid ReleaseOutStream()\n\t{ _rangeEncoder.ReleaseStream(); }\n\n\tvoid ReleaseStreams()\n\t{\n\t\tReleaseMFStream();\n\t\tReleaseOutStream();\n\t}\n\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\n\t\t\tlong inSize, long outSize)\n\t{\n\t\t_inStream = inStream;\n\t\t_finished = false;\n\t\tCreate();\n\t\tSetOutStream(outStream);\n\t\tInit();\n\n\t\t// if (!_fastMode)\n\t\t{\n\t\t\tFillDistancesPrices();\n\t\t\tFillAlignPrices();\n\t\t}\n\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\n\n\t\tnowPos64 = 0;\n\t}\n\n\tlong[] processedInSize = new long[1]; long[] processedOutSize = new long[1]; boolean[] finished = new boolean[1];\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\n\t{\n\t\t_needReleaseMFStream = false;\n\t\ttry\n\t\t{\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\n\t\t\twhile (true)\n\t\t\t{\n\n\n\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\n\t\t\t\tif (finished[0])\n\t\t\t\t\treturn;\n\t\t\t\tif (progress != null)\n\t\t\t\t{\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfinally\n\t\t{\n\t\t\tReleaseStreams();\n\t\t}\n\t}\n\n\tpublic static final int kPropSize = 5;\n\tbyte[] properties = new byte[kPropSize];\n\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\n\t{\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\n\t\toutStream.write(properties, 0, kPropSize);\n\t}\n\n\tint[] tempPrices = new int[Base.kNumFullDistances];\n\tint _matchPriceCount;\n\n\tvoid FillDistancesPrices()\n\t{\n\t\tfor (int i = Base.kStartPosModelIndex; i < Base.kNumFullDistances; i++)\n\t\t{\n\t\t\tint posSlot = GetPosSlot(i);\n\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\n\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\n\t\t\ttempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders,\n\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\n\t\t}\n\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\n\t\t{\n\t\t\tint posSlot;\n\t\t\tBitTreeEncoder encoder = _posSlotEncoder[lenToPosState];\n\n\t\t\tint st = (lenToPosState << Base.kNumPosSlotBits);\n\t\t\tfor (posSlot = 0; posSlot < _distTableSize; posSlot++)\n\t\t\t\t_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);\n\t\t\tfor (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)\n\t\t\t\t_posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\n\n\t\t\tint st2 = lenToPosState * Base.kNumFullDistances;\n\t\t\tint i;\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + i];\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\n\t\t\t\t_distancesPrices[st2 + i] = _posSlotPrices[st + GetPosSlot(i)] + tempPrices[i];\n\t\t}\n\t\t_matchPriceCount = 0;\n\t}\n\n\tvoid FillAlignPrices()\n\t{\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\n\t\t_alignPriceCount = 0;\n\t}\n\n\n\tpublic boolean SetAlgorithm(int algorithm)\n\t{\n\t\t/*\n\t\t_fastMode = (algorithm == 0);\n\t\t_maxMode = (algorithm >= 2);\n\t\t*/\n\t\treturn true;\n\t}\n\n\tpublic boolean SetDictionarySize(int dictionarySize)\n\t{\n\t\tint kDicLogSizeMaxCompress = 29;\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\n\t\t\treturn false;\n\t\t_dictionarySize = dictionarySize;\n\t\tint dicLogSize;\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++) ;\n\t\t_distTableSize = dicLogSize * 2;\n\t\treturn true;\n\t}\n\n\tpublic boolean SetNumFastBytes(int numFastBytes)\n\t{\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\n\t\t\treturn false;\n\t\t_numFastBytes = numFastBytes;\n\t\treturn true;\n\t}\n\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\n\t{\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\n\t\t\treturn false;\n\t\tint matchFinderIndexPrev = _matchFinderType;\n\t\t_matchFinderType = matchFinderIndex;\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\n\t\t{\n\t\t\t_dictionarySizePrev = -1;\n\t\t\t_matchFinder = null;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\n\t{\n\t\tif (\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\n\t\t\treturn false;\n\t\t_numLiteralPosStateBits = lp;\n\t\t_numLiteralContextBits = lc;\n\t\t_posStateBits = pb;\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\n\t\treturn true;\n\t}\n\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\n\t{\n\t\t_writeEndMark = endMarkerMode;\n\t}\n}\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\n\npublic class BitTreeDecoder\n{\n\tshort[] Models;\n\tint NumBitLevels;\n\t\n\tpublic BitTreeDecoder(int numBitLevels)\n\t{\n\t\tNumBitLevels = numBitLevels;\n\t\tModels = new short[1 << numBitLevels];\n\t}\n\t\n\tpublic void Init()\n\t{\n\t\tDecoder.InitBitModels(Models);\n\t}\n\t\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\n\t{\n\t\tint m = 1;\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\n\t\treturn m - (1 << NumBitLevels);\n\t}\n\t\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\n\t{\n\t\tint m = 1;\n\t\tint symbol = 0;\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\n\t\t{\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\n\t\t\tm <<= 1;\n\t\t\tm += bit;\n\t\t\tsymbol |= (bit << bitIndex);\n\t\t}\n\t\treturn symbol;\n\t}\n\t\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\n\t{\n\t\tint m = 1;\n\t\tint symbol = 0;\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\n\t\t{\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\n\t\t\tm <<= 1;\n\t\t\tm += bit;\n\t\t\tsymbol |= (bit << bitIndex);\n\t\t}\n\t\treturn symbol;\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\nimport java.io.IOException;\n\npublic class BitTreeEncoder\n{\n\tshort[] Models;\n\tint NumBitLevels;\n\t\n\tpublic BitTreeEncoder(int numBitLevels)\n\t{\n\t\tNumBitLevels = numBitLevels;\n\t\tModels = new short[1 << numBitLevels];\n\t}\n\t\n\tpublic void Init()\n\t{\n\t\tDecoder.InitBitModels(Models);\n\t}\n\t\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\n\t{\n\t\tint m = 1;\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\n\t\t{\n\t\t\tbitIndex--;\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\n\t\t\trangeEncoder.Encode(Models, m, bit);\n\t\t\tm = (m << 1) | bit;\n\t\t}\n\t}\n\t\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\n\t{\n\t\tint m = 1;\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\n\t\t{\n\t\t\tint bit = symbol & 1;\n\t\t\trangeEncoder.Encode(Models, m, bit);\n\t\t\tm = (m << 1) | bit;\n\t\t\tsymbol >>= 1;\n\t\t}\n\t}\n\t\n\tpublic int GetPrice(int symbol)\n\t{\n\t\tint price = 0;\n\t\tint m = 1;\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\n\t\t{\n\t\t\tbitIndex--;\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\n\t\t\tm = (m << 1) + bit;\n\t\t}\n\t\treturn price;\n\t}\n\t\n\tpublic int ReverseGetPrice(int symbol)\n\t{\n\t\tint price = 0;\n\t\tint m = 1;\n\t\tfor (int i = NumBitLevels; i != 0; i--)\n\t\t{\n\t\t\tint bit = symbol & 1;\n\t\t\tsymbol >>>= 1;\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\n\t\t\tm = (m << 1) | bit;\n\t\t}\n\t\treturn price;\n\t}\n\t\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\n\t\t\tint NumBitLevels, int symbol)\n\t{\n\t\tint price = 0;\n\t\tint m = 1;\n\t\tfor (int i = NumBitLevels; i != 0; i--)\n\t\t{\n\t\t\tint bit = symbol & 1;\n\t\t\tsymbol >>>= 1;\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\n\t\t\tm = (m << 1) | bit;\n\t\t}\n\t\treturn price;\n\t}\n\t\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\n\t{\n\t\tint m = 1;\n\t\tfor (int i = 0; i < NumBitLevels; i++)\n\t\t{\n\t\t\tint bit = symbol & 1;\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\n\t\t\tm = (m << 1) | bit;\n\t\t\tsymbol >>= 1;\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\nimport java.io.IOException;\n\npublic class Decoder\n{\n\tstatic final int kTopMask = ~((1 << 24) - 1);\n\t\n\tstatic final int kNumBitModelTotalBits = 11;\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\n\tstatic final int kNumMoveBits = 5;\n\t\n\tint Range;\n\tint Code;\n\n\tjava.io.InputStream Stream;\n\t\n\tpublic final void SetStream(java.io.InputStream stream)\n\t{ \n\t\tStream = stream; \n\t}\n\t\n\tpublic final void ReleaseStream()\n\t{ \n\t\tStream = null; \n\t}\n\t\n\tpublic final void Init() throws IOException\n\t{\n\t\tCode = 0;\n\t\tRange = -1;\n\t\tfor (int i = 0; i < 5; i++)\n\t\t\tCode = (Code << 8) | Stream.read();\n\t}\n\t\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\n\t{\n\t\tint result = 0;\n\t\tfor (int i = numTotalBits; i != 0; i--)\n\t\t{\n\t\t\tRange >>>= 1;\n\t\t\tint t = ((Code - Range) >>> 31);\n\t\t\tCode -= Range & (t - 1);\n\t\t\tresult = (result << 1) | (1 - t);\n\t\t\t\n\t\t\tif ((Range & kTopMask) == 0)\n\t\t\t{\n\t\t\t\tCode = (Code << 8) | Stream.read();\n\t\t\t\tRange <<= 8;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\t\n\tpublic int DecodeBit(short []probs, int index) throws IOException\n\t{\n\t\tint prob = probs[index];\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\n\t\t{\n\t\t\tRange = newBound;\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\n\t\t\tif ((Range & kTopMask) == 0)\n\t\t\t{\n\t\t\t\tCode = (Code << 8) | Stream.read();\n\t\t\t\tRange <<= 8;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tRange -= newBound;\n\t\t\tCode -= newBound;\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\n\t\t\tif ((Range & kTopMask) == 0)\n\t\t\t{\n\t\t\t\tCode = (Code << 8) | Stream.read();\n\t\t\t\tRange <<= 8;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\t}\n\t\n\tpublic static void InitBitModels(short []probs)\n\t{\n\t\tfor (int i = 0; i < probs.length; i++)\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\nimport java.io.IOException;\n\npublic class Encoder\n{\n\tstatic final int kTopMask = ~((1 << 24) - 1);\n\t\n\tstatic final int kNumBitModelTotalBits = 11;\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\n\tstatic final int kNumMoveBits = 5;\n\t\n\tjava.io.OutputStream Stream;\n\n\tlong Low;\n\tint Range;\n\tint _cacheSize;\n\tint _cache;\n\t\n\tlong _position;\n\t\n\tpublic void SetStream(java.io.OutputStream stream)\n\t{\n\t\tStream = stream;\n\t}\n\t\n\tpublic void ReleaseStream()\n\t{\n\t\tStream = null;\n\t}\n\t\n\tpublic void Init()\n\t{\n\t\t_position = 0;\n\t\tLow = 0;\n\t\tRange = -1;\n\t\t_cacheSize = 1;\n\t\t_cache = 0;\n\t}\n\t\n\tpublic void FlushData() throws IOException\n\t{\n\t\tfor (int i = 0; i < 5; i++)\n\t\t\tShiftLow();\n\t}\n\t\n\tpublic void FlushStream() throws IOException\n\t{\n\t\tStream.flush();\n\t}\n\t\n\tpublic void ShiftLow() throws IOException\n\t{\n\t\tint LowHi = (int)(Low >>> 32);\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\n\t\t{\n\t\t\t_position += _cacheSize;\n\t\t\tint temp = _cache;\n\t\t\tdo\n\t\t\t{\n\t\t\t\tStream.write(temp + LowHi);\n\t\t\t\ttemp = 0xFF;\n\t\t\t}\n\t\t\twhile(--_cacheSize != 0);\n\t\t\t_cache = (((int)Low) >>> 24);\n\t\t}\n\t\t_cacheSize++;\n\t\tLow = (Low & 0xFFFFFF) << 8;\n\t}\n\t\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\n\t{\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\n\t\t{\n\t\t\tRange >>>= 1;\n\t\t\tif (((v >>> i) & 1) == 1)\n\t\t\t\tLow += Range;\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\n\t\t\t{\n\t\t\t\tRange <<= 8;\n\t\t\t\tShiftLow();\n\t\t\t}\n\t\t}\n\t}\n\t\n\t\n\tpublic long GetProcessedSizeAdd()\n\t{\n\t\treturn _cacheSize + _position + 4;\n\t}\n\t\n\t\n\t\n\tstatic final int kNumMoveReducingBits = 2;\n\tpublic static final int kNumBitPriceShiftBits = 6;\n\t\n\tpublic static void InitBitModels(short []probs)\n\t{\n\t\tfor (int i = 0; i < probs.length; i++)\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\n\t}\n\t\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\n\t{\n\t\tint prob = probs[index];\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\n\t\tif (symbol == 0)\n\t\t{\n\t\t\tRange = newBound;\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\n\t\t}\n\t\telse\n\t\t{\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\n\t\t\tRange -= newBound;\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\n\t\t}\n\t\tif ((Range & kTopMask) == 0)\n\t\t{\n\t\t\tRange <<= 8;\n\t\t\tShiftLow();\n\t\t}\n\t}\n\t\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\n\t\n\tstatic\n\t{\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\n\t\t{\n\t\t\tint start = 1 << (kNumBits - i - 1);\n\t\t\tint end = 1 << (kNumBits - i);\n\t\t\tfor (int j = start; j < end; j++)\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\n\t\t}\n\t}\n\t\n\tstatic public int GetPrice(int Prob, int symbol)\n\t{\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\n\t}\n\tstatic public int GetPrice0(int Prob)\n\t{ \n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \n\t}\n\tstatic public int GetPrice1(int Prob)\n\t{ \n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/ICodeProgress.java",
    "content": "package SevenZip;\n\npublic interface ICodeProgress\n{\n\tpublic void SetProgress(long inSize, long outSize);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\n\npublic class LzmaAlone\n{\n\tstatic public class CommandLine\n\t{\n\t\tpublic static final int kEncode = 0;\n\t\tpublic static final int kDecode = 1;\n\t\tpublic static final int kBenchmak = 2;\n\t\t\n\t\tpublic int Command = -1;\n\t\tpublic int NumBenchmarkPasses = 10;\n\t\t\n\t\tpublic int DictionarySize = 1 << 23;\n\t\tpublic boolean DictionarySizeIsDefined = false;\n\t\t\n\t\tpublic int Lc = 3;\n\t\tpublic int Lp = 0;\n\t\tpublic int Pb = 2;\n\t\t\n\t\tpublic int Fb = 128;\n\t\tpublic boolean FbIsDefined = false;\n\t\t\n\t\tpublic boolean Eos = false;\n\t\t\n\t\tpublic int Algorithm = 2;\n\t\tpublic int MatchFinder = 1;\n\t\t\n\t\tpublic String InFile;\n\t\tpublic String OutFile;\n\t\t\n\t\tboolean ParseSwitch(String s)\n\t\t{\n\t\t\tif (s.startsWith(\"d\"))\n\t\t\t{\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\n\t\t\t\tDictionarySizeIsDefined = true;\n\t\t\t}\n\t\t\telse if (s.startsWith(\"fb\"))\n\t\t\t{\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\n\t\t\t\tFbIsDefined = true;\n\t\t\t}\n\t\t\telse if (s.startsWith(\"a\"))\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\n\t\t\telse if (s.startsWith(\"lc\"))\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\n\t\t\telse if (s.startsWith(\"lp\"))\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\n\t\t\telse if (s.startsWith(\"pb\"))\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\n\t\t\telse if (s.startsWith(\"eos\"))\n\t\t\t\tEos = true;\n\t\t\telse if (s.startsWith(\"mf\"))\n\t\t\t{\n\t\t\t\tString mfs = s.substring(2);\n\t\t\t\tif (mfs.equals(\"bt2\"))\n\t\t\t\t\tMatchFinder = 0;\n\t\t\t\telse if (mfs.equals(\"bt4\"))\n\t\t\t\t\tMatchFinder = 1;\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\n\t\t\t\t\tMatchFinder = 2;\n\t\t\t\telse\n\t\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\tpublic boolean Parse(String[] args) throws Exception\n\t\t{\n\t\t\tint pos = 0;\n\t\t\tboolean switchMode = true;\n\t\t\tfor (int i = 0; i < args.length; i++)\n\t\t\t{\n\t\t\t\tString s = args[i];\n\t\t\t\tif (s.length() == 0)\n\t\t\t\t\treturn false;\n\t\t\t\tif (switchMode)\n\t\t\t\t{\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tswitchMode = false;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (s.charAt(0) == '-')\n\t\t\t\t\t{\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\n\t\t\t\t\t\tif (sw.length() == 0)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\ttry\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (NumberFormatException e)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (pos == 0)\n\t\t\t\t{\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\n\t\t\t\t\t\tCommand = kEncode;\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\n\t\t\t\t\t\tCommand = kDecode;\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\n\t\t\t\t\t\tCommand = kBenchmak;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\telse if(pos == 1)\n\t\t\t\t{\n\t\t\t\t\tif (Command == kBenchmak)\n\t\t\t\t\t{\n\t\t\t\t\t\ttry\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (NumberFormatException e)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tInFile = s;\n\t\t\t\t}\n\t\t\t\telse if(pos == 2)\n\t\t\t\t\tOutFile = s;\n\t\t\t\telse\n\t\t\t\t\treturn false;\n\t\t\t\tpos++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}\n\t\n\t\n\tstatic void PrintHelp()\n\t{\n\t\tSystem.out.println(\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\n\t\t\t\t\"  e: encode file\\n\" +\n\t\t\t\t\"  d: decode file\\n\" +\n\t\t\t\t\"  b: Benchmark\\n\" +\n\t\t\t\t\"<Switches>\\n\" +\n\t\t\t\t// \"  -a{N}:  set compression mode - [0, 1], default: 1 (max)\\n\" +\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4], default: bt4\\n\" +\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\n\t\t\t\t);\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.61  2008-11-23\\n\");\n\t\t\n\t\tif (args.length < 1)\n\t\t{\n\t\t\tPrintHelp();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tCommandLine params = new CommandLine();\n\t\tif (!params.Parse(args))\n\t\t{\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif (params.Command == CommandLine.kBenchmak)\n\t\t{\n\t\t\tint dictionary = (1 << 21);\n\t\t\tif (params.DictionarySizeIsDefined)\n\t\t\t\tdictionary = params.DictionarySize;\n\t\t\tif (params.MatchFinder > 1)\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary);\n\t\t}\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\n\t\t{\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\n\t\t\t\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\n\t\t\t\n\t\t\tboolean eos = false;\n\t\t\tif (params.Eos)\n\t\t\t\teos = true;\n\t\t\tif (params.Command == CommandLine.kEncode)\n\t\t\t{\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\n\t\t\t\tif (!encoder.SetNumFastBytes(params.Fb))\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\n\t\t\t\tencoder.SetEndMarkerMode(eos);\n\t\t\t\tencoder.WriteCoderProperties(outStream);\n\t\t\t\tlong fileSize;\n\t\t\t\tif (eos)\n\t\t\t\t\tfileSize = -1;\n\t\t\t\telse\n\t\t\t\t\tfileSize = inFile.length();\n\t\t\t\tfor (int i = 0; i < 8; i++)\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint propertiesSize = 5;\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\n\t\t\t\tlong outSize = 0;\n\t\t\t\tfor (int i = 0; i < 8; i++)\n\t\t\t\t{\n\t\t\t\t\tint v = inStream.read();\n\t\t\t\t\tif (v < 0)\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\n\t\t\t\t}\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\n\t\t\t}\n\t\t\toutStream.flush();\n\t\t\toutStream.close();\n\t\t\tinStream.close();\n\t\t}\n\t\telse\n\t\t\tthrow new Exception(\"Incorrect command\");\n\t\treturn;\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\n\nimport java.io.ByteArrayOutputStream;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\n\npublic class LzmaBench\n{\n\tstatic final int kAdditionalSize = (1 << 21);\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\n\t\n\tstatic class CRandomGenerator\n\t{\n\t\tint A1;\n\t\tint A2;\n\t\tpublic CRandomGenerator() { Init(); }\n\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\n\t\tpublic int GetRnd()\n\t\t{\n\t\t\treturn\n\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\n\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\n\t\t}\n\t};\n\t\n\tstatic class CBitRandomGenerator\n\t{\n\t\tCRandomGenerator RG = new CRandomGenerator();\n\t\tint Value;\n\t\tint NumBits;\n\t\tpublic void Init()\n\t\t{\n\t\t\tValue = 0;\n\t\t\tNumBits = 0;\n\t\t}\n\t\tpublic int GetRnd(int numBits)\n\t\t{\n\t\t\tint result;\n\t\t\tif (NumBits > numBits)\n\t\t\t{\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\n\t\t\t\tValue >>>= numBits;\n\t\t\t\tNumBits -= numBits;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tnumBits -= NumBits;\n\t\t\tresult = (Value << numBits);\n\t\t\tValue = RG.GetRnd();\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\n\t\t\tValue >>>= numBits;\n\t\t\tNumBits = 32 - numBits;\n\t\t\treturn result;\n\t\t}\n\t};\n\t\n\tstatic class CBenchRandomGenerator\n\t{\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\n\t\tint Pos;\n\t\tint Rep0;\n\n\t\tpublic int BufferSize;\n\t\tpublic byte[] Buffer = null;\n\n\t\tpublic CBenchRandomGenerator() { }\n\t\tpublic void Set(int bufferSize)\n\t\t{\n\t\t\tBuffer = new byte[bufferSize];\n\t\t\tPos = 0;\n\t\t\tBufferSize = bufferSize;\n\t\t}\n\t\tint GetRndBit() { return RG.GetRnd(1); }\n\t\tint GetLogRandBits(int numBits)\n\t\t{\n\t\t\tint len = RG.GetRnd(numBits);\n\t\t\treturn RG.GetRnd((int)len);\n\t\t}\n\t\tint GetOffset()\n\t\t{\n\t\t\tif (GetRndBit() == 0)\n\t\t\t\treturn GetLogRandBits(4);\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\n\t\t}\n\t\tint GetLen1() { return RG.GetRnd(1 + (int)RG.GetRnd(2)); }\n\t\tint GetLen2() { return RG.GetRnd(2 + (int)RG.GetRnd(2)); }\n\t\tpublic void Generate()\n\t\t{\n\t\t\tRG.Init();\n\t\t\tRep0 = 1;\n\t\t\twhile (Pos < BufferSize)\n\t\t\t{\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint len;\n\t\t\t\t\tif (RG.GetRnd(3) == 0)\n\t\t\t\t\t\tlen = 1 + GetLen1();\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tdo\n\t\t\t\t\t\t\tRep0 = GetOffset();\n\t\t\t\t\t\twhile (Rep0 >= Pos);\n\t\t\t\t\t\tRep0++;\n\t\t\t\t\t\tlen = 2 + GetLen2();\n\t\t\t\t\t}\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - Rep0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\t\n\tstatic class CrcOutStream extends java.io.OutputStream\n\t{\n\t\tpublic CRC CRC = new CRC();\n\t\t\n\t\tpublic void Init()\n\t\t{ \n\t\t\tCRC.Init(); \n\t\t}\n\t\tpublic int GetDigest()\n\t\t{ \n\t\t\treturn CRC.GetDigest(); \n\t\t}\n\t\tpublic void write(byte[] b)\n\t\t{\n\t\t\tCRC.Update(b);\n\t\t}\n\t\tpublic void write(byte[] b, int off, int len)\n\t\t{\n\t\t\tCRC.Update(b, off, len);\n\t\t}\n\t\tpublic void write(int b)\n\t\t{\n\t\t\tCRC.UpdateByte(b);\n\t\t}\n\t};\n\n\tstatic class MyOutputStream extends java.io.OutputStream\n\t{\n\t\tbyte[] _buffer;\n\t\tint _size;\n\t\tint _pos;\n\t\t\n\t\tpublic MyOutputStream(byte[] buffer)\n\t\t{\n\t\t\t_buffer = buffer;\n\t\t\t_size = _buffer.length;\n\t\t}\n\t\t\n\t\tpublic void reset()\n\t\t{ \n\t\t\t_pos = 0; \n\t\t}\n\t\t\n\t\tpublic void write(int b) throws IOException\n\t\t{\n\t\t\tif (_pos >= _size)\n\t\t\t\tthrow new IOException(\"Error\");\n\t\t\t_buffer[_pos++] = (byte)b;\n\t\t}\n\t\t\n\t\tpublic int size()\n\t\t{\n\t\t\treturn _pos;\n\t\t}\n\t};\n\n\tstatic class MyInputStream extends java.io.InputStream\n\t{\n\t\tbyte[] _buffer;\n\t\tint _size;\n\t\tint _pos;\n\t\t\n\t\tpublic MyInputStream(byte[] buffer, int size)\n\t\t{\n\t\t\t_buffer = buffer;\n\t\t\t_size = size;\n\t\t}\n\t\t\n\t\tpublic void reset()\n\t\t{ \n\t\t\t_pos = 0; \n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (_pos >= _size)\n\t\t\t\treturn -1;\n\t\t\treturn _buffer[_pos++] & 0xFF;\n\t\t}\n\t};\n\t\n\tstatic class CProgressInfo implements ICodeProgress\n\t{\n\t\tpublic long ApprovedStart;\n\t\tpublic long InSize;\n\t\tpublic long Time;\n\t\tpublic void Init()\n\t\t{ InSize = 0; }\n\t\tpublic void SetProgress(long inSize, long outSize)\n\t\t{\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\n\t\t\t{\n\t\t\t\tTime = System.currentTimeMillis();\n\t\t\t\tInSize = inSize;\n\t\t\t}\n\t\t}\n\t}\n\tstatic final int kSubBits = 8;\n\t\n\tstatic int GetLogSize(int size)\n\t{\n\t\tfor (int i = kSubBits; i < 32; i++)\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\n\t\t\t\t\treturn (i << kSubBits) + j;\n\t\treturn (32 << kSubBits);\n\t}\n\t\n\tstatic long MyMultDiv64(long value, long elapsedTime)\n\t{\n\t\tlong freq = 1000; // ms\n\t\tlong elTime = elapsedTime;\n\t\twhile (freq > 1000000)\n\t\t{\n\t\t\tfreq >>>= 1;\n\t\t\telTime >>>= 1;\n\t\t}\n\t\tif (elTime == 0)\n\t\t\telTime = 1;\n\t\treturn value * freq / elTime;\n\t}\n\t\n\tstatic long GetCompressRating(int dictionarySize, long elapsedTime, long size)\n\t{\n\t\tlong t = GetLogSize(dictionarySize) - (18 << kSubBits);\n\t\tlong numCommandsForOne = 1060 + ((t * t * 10) >> (2 * kSubBits));\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\n\t}\n\t\n\tstatic long GetDecompressRating(long elapsedTime, long outSize, long inSize)\n\t{\n\t\tlong numCommands = inSize * 220 + outSize * 20;\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\n\t}\n\t\n\tstatic long GetTotalRating(\n\t\t\tint dictionarySize,\n\t\t\tlong elapsedTimeEn, long sizeEn,\n\t\t\tlong elapsedTimeDe,\n\t\t\tlong inSizeDe, long outSizeDe)\n\t{\n\t\treturn (GetCompressRating(dictionarySize, elapsedTimeEn, sizeEn) +\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\n\t}\n\t\n\tstatic void PrintValue(long v)\n\t{\n\t\tString s = \"\";\n\t\ts += v;\n\t\tfor (int i = 0; i + s.length() < 6; i++)\n\t\t\tSystem.out.print(\" \");\n\t\tSystem.out.print(s);\n\t}\n\t\n\tstatic void PrintRating(long rating)\n\t{\n\t\tPrintValue(rating / 1000000);\n\t\tSystem.out.print(\" MIPS\");\n\t}\n\t\n\tstatic void PrintResults(\n\t\t\tint dictionarySize,\n\t\t\tlong elapsedTime,\n\t\t\tlong size,\n\t\t\tboolean decompressMode, long secondSize)\n\t{\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\n\t\tPrintValue(speed / 1024);\n\t\tSystem.out.print(\" KB/s  \");\n\t\tlong rating;\n\t\tif (decompressMode)\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\n\t\telse\n\t\t\trating = GetCompressRating(dictionarySize, elapsedTime, size);\n\t\tPrintRating(rating);\n\t}\n\t\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize) throws Exception\n\t{\n\t\tif (numIterations <= 0)\n\t\t\treturn 0;\n\t\tif (dictionarySize < (1 << 18))\n\t\t{\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 18 (256 KB)\");\n\t\t\treturn 1;\n\t\t}\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\n\t\t\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\n\t\t\n\t\tif (!encoder.SetDictionarySize(dictionarySize))\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\n\t\t\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\n\t\t\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\n\t\tencoder.WriteCoderProperties(propStream);\n\t\tbyte[] propArray = propStream.toByteArray();\n\t\tdecoder.SetDecoderProperties(propArray);\n\t\t\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\n\n\t\trg.Set(kBufferSize);\n\t\trg.Generate();\n\t\tCRC crc = new CRC();\n\t\tcrc.Init();\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\n\t\t\n\t\tCProgressInfo progressInfo = new CProgressInfo();\n\t\tprogressInfo.ApprovedStart = dictionarySize;\n\t\t\n\t\tlong totalBenchSize = 0;\n\t\tlong totalEncodeTime = 0;\n\t\tlong totalDecodeTime = 0;\n\t\tlong totalCompressedSize = 0;\n\t\t\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\n\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\n\t\tMyInputStream inputCompressedStream = null;\n\t\tint compressedSize = 0;\n\t\tfor (int i = 0; i < numIterations; i++)\n\t\t{\n\t\t\tprogressInfo.Init();\n\t\t\tinStream.reset();\n\t\t\tcompressedStream.reset();\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\n\t\t\t\n\t\t\tif (i == 0)\n\t\t\t{\n\t\t\t\tcompressedSize = compressedStream.size();\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\n\t\t\t}\n\t\t\telse if (compressedSize != compressedStream.size())\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\n\t\t\t\t\n\t\t\tif (progressInfo.InSize == 0)\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\n\n\t\t\tlong decodeTime = 0;\n\t\t\tfor (int j = 0; j < 2; j++)\n\t\t\t{\n\t\t\t\tinputCompressedStream.reset();\n\t\t\t\tcrcOutStream.Init();\n\t\t\t\t\n\t\t\t\tlong outSize = kBufferSize;\n\t\t\t\tlong startTime = System.currentTimeMillis();\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\n\t\t\t}\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\n\t\t\tPrintResults(dictionarySize, encodeTime, benchSize, false, 0);\n\t\t\tSystem.out.print(\"     \");\n\t\t\tPrintResults(dictionarySize, decodeTime, kBufferSize, true, compressedSize);\n\t\t\tSystem.out.println();\n\t\t\t\n\t\t\ttotalBenchSize += benchSize;\n\t\t\ttotalEncodeTime += encodeTime;\n\t\t\ttotalDecodeTime += decodeTime;\n\t\t\ttotalCompressedSize += compressedSize;\n\t\t}\n\t\tSystem.out.println(\"---------------------------------------------------\");\n\t\tPrintResults(dictionarySize, totalEncodeTime, totalBenchSize, false, 0);\n\t\tSystem.out.print(\"     \");\n\t\tPrintResults(dictionarySize, totalDecodeTime,\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\n\t\tSystem.out.println(\"    Average\");\n\t\treturn 0;\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/Methods.txt",
    "content": "7-Zip method IDs (4.65)\n-----------------------\n\nEach compression or crypto method in 7z has unique binary value (ID).\nThe length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).\n\nIf you want to add some new ID, you have two ways:\n1) Write request for allocating IDs to 7-zip developers.\n2) Generate 8-bytes ID:\n\n    3F ZZ ZZ ZZ ZZ ZZ MM MM \n\n    3F              - Prefix for random IDs (1 byte)\n    ZZ ZZ ZZ ZZ ZZ  - Developer ID (5 bytes). Use real random bytes. \n                      \n    MM MM           - Method ID (2 bytes)\n\n    You can notify 7-Zip developers about your Developer ID / Method ID.\n\n    Note: Use new ID only if old codec can not decode data encoded with new version.\n\n\nList of defined IDs\n-------------------\n      \n00 - Copy\n\n02 - Common\n   03 Swap\n      - 2 Swap2\n      - 4 Swap4\n\n03 - 7z\n   01 - LZMA\n      01 - Version\n  \n   03 - Branch\n      01 - x86\n         03  - BCJ\n         1B  - BCJ2\n      02 - PPC\n         05 - PPC (Big Endian)\n      03 - Alpha\n         01 - Alpha\n      04 - IA64\n         01 - IA64\n      05 - ARM\n         01 - ARM\n      06 - M68\n         05 - M68 (Big Endian)\n      07 - ARM Thumb\n         01 - ARMT\n      08 - SPARC\n         05 - SPARC\n\n   04 - PPMD\n      01 - Version\n\n   7F -\n      01 - experimental methods.\n\n\n04 - Misc\n   00 - Reserved\n   01 - Zip\n      00 - Copy (not used). Use {00} instead\n      01 - Shrink\n      06 - Implode\n      08 - Deflate\n      09 - Deflate64\n      12 - BZip2 (not used). Use {04 02 02} instead\n   02 - BZip\n      02 - BZip2\n   03 - Rar\n      01 - Rar15\n      02 - Rar20\n      03 - Rar29\n   04 - Arj\n      01 - Arj (1,2,3)\n      02 - Arj 4\n   05 - Z\n   06 - Lzh\n   07 - Reserved for 7z\n   08 - Cab\n   09 - NSIS\n      01 - DeflateNSIS\n      02 - BZip2NSIS\n\n\n06 - Crypto \n   00 - \n   01 - AES\n      0x - AES-128\n      4x - AES-192\n      8x - AES-256\n      Cx - AES\n\n      x0 - ECB\n      x1 - CBC\n      x2 - CFB\n      x3 - OFB\n\n   07 - Reserved\n   0F - Reserved\n\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\n\n   F1 - Misc Ciphers (Combine)\n      01 - Zip\n         01 - Main Zip crypto algo\n      03 - RAR\n         02 - \n         03 - Rar29 AES-128 + (modified SHA-1)\n      07 - 7z\n         01 - AES-256 + SHA-256\n\n07 - Hash (subject to change)\n   00 - \n   01 - CRC\n   02 - SHA-1\n   03 - SHA-256\n   04 - SHA-384\n   05 - SHA-512\n\n   F0 - Misc Hash\n\n   F1 - Misc\n      03 - RAR\n         03 - Rar29 Password Hashing (modified SHA1)\n      07 - 7z \n         01 - SHA-256 Password Hashing\n    \n   \n\n\n---\nEnd of document\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/history.txt",
    "content": "HISTORY of the LZMA SDK\n-----------------------\n\n4.65           2009-02-03\n-------------------------\n- Some minor fixes\n\n\n4.63           2008-12-31\n-------------------------\n- Some minor fixes\n\n\n4.61 beta      2008-11-23\n-------------------------\n- The bug in ANSI-C LZMA Decoder was fixed:\n    If encoded stream was corrupted, decoder could access memory \n    outside of allocated range.\n- Some changes in ANSI-C 7z Decoder interfaces.\n- LZMA SDK is placed in the public domain.\n\n\n4.60 beta      2008-08-19\n-------------------------\n- Some minor fixes.\n\n\n4.59 beta      2008-08-13\n-------------------------\n- The bug was fixed:\n    LZMA Encoder in fast compression mode could access memory outside of \n    allocated range in some rare cases.\n\n\n4.58 beta      2008-05-05\n-------------------------\n- ANSI-C LZMA Decoder was rewritten for speed optimizations.\n- ANSI-C LZMA Encoder was included to LZMA SDK.\n- C++ LZMA code now is just wrapper over ANSI-C code.\n\n\n4.57           2007-12-12\n-------------------------\n- Speed optimizations in ++ LZMA Decoder. \n- Small changes for more compatibility with some C/C++ compilers.\n\n\n4.49 beta      2007-07-05\n-------------------------\n- .7z ANSI-C Decoder:\n     - now it supports BCJ and BCJ2 filters\n     - now it supports files larger than 4 GB.\n     - now it supports \"Last Write Time\" field for files.\n- C++ code for .7z archives compressing/decompressing from 7-zip \n  was included to LZMA SDK.\n  \n\n4.43           2006-06-04\n-------------------------\n- Small changes for more compatibility with some C/C++ compilers.\n  \n\n4.42           2006-05-15\n-------------------------\n- Small changes in .h files in ANSI-C version.\n  \n\n4.39 beta      2006-04-14\n-------------------------\n- The bug in versions 4.33b:4.38b was fixed:\n  C++ version of LZMA encoder could not correctly compress \n  files larger than 2 GB with HC4 match finder (-mfhc4).\n  \n\n4.37 beta      2005-04-06\n-------------------------\n- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \n\n\n4.35 beta      2005-03-02\n-------------------------\n- The bug was fixed in C++ version of LZMA Decoder:\n    If encoded stream was corrupted, decoder could access memory \n    outside of allocated range.\n\n\n4.34 beta      2006-02-27\n-------------------------\n- Compressing speed and memory requirements for compressing were increased\n- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\n\n\n4.32           2005-12-09\n-------------------------\n- Java version of LZMA SDK was included\n\n\n4.30           2005-11-20\n-------------------------\n- Compression ratio was improved in -a2 mode\n- Speed optimizations for compressing in -a2 mode\n- -fb switch now supports values up to 273\n- The bug in 7z_C (7zIn.c) was fixed:\n  It used Alloc/Free functions from different memory pools.\n  So if program used two memory pools, it worked incorrectly.\n- 7z_C: .7z format supporting was improved\n- LZMA# SDK (C#.NET version) was included\n\n\n4.27 (Updated) 2005-09-21\n-------------------------\n- Some GUIDs/interfaces in C++ were changed.\n IStream.h:\n   ISequentialInStream::Read now works as old ReadPart\n   ISequentialOutStream::Write now works as old WritePart\n\n\n4.27           2005-08-07\n-------------------------\n- The bug in LzmaDecodeSize.c was fixed:\n   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\n   decompressing worked incorrectly.\n\n\n4.26           2005-08-05\n-------------------------\n- Fixes in 7z_C code and LzmaTest.c:\n  previous versions could work incorrectly,\n  if malloc(0) returns 0\n\n\n4.23           2005-06-29\n-------------------------\n- Small fixes in C++ code\n\n\n4.22           2005-06-10\n-------------------------\n- Small fixes\n\n\n4.21           2005-06-08\n-------------------------\n- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\n- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\n    - LzmaStateDecode.h\n    - LzmaStateDecode.c\n    - LzmaStateTest.c\n- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\n\n\n4.17           2005-04-18\n-------------------------\n- New example for RAM->RAM compressing/decompressing: \n  LZMA + BCJ (filter for x86 code):\n    - LzmaRam.h\n    - LzmaRam.cpp\n    - LzmaRamDecode.h\n    - LzmaRamDecode.c\n    - -f86 switch for lzma.exe\n\n\n4.16           2005-03-29\n-------------------------\n- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \n   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\n   decoder could access memory outside of allocated range.\n- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\n  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \n  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\n- Small speed optimization in LZMA C++ code\n- filter for SPARC's code was added\n- Simplified version of .7z ANSI-C Decoder was included\n\n\n4.06           2004-09-05\n-------------------------\n- The bug in v4.05 was fixed:\n    LZMA-Encoder didn't release output stream in some cases.\n\n\n4.05           2004-08-25\n-------------------------\n- Source code of filters for x86, IA-64, ARM, ARM-Thumb \n  and PowerPC code was included to SDK\n- Some internal minor changes\n\n\n4.04           2004-07-28\n-------------------------\n- More compatibility with some C++ compilers\n\n\n4.03           2004-06-18\n-------------------------\n- \"Benchmark\" command was added. It measures compressing \n  and decompressing speed and shows rating values. \n  Also it checks hardware errors.\n\n\n4.02           2004-06-10\n-------------------------\n- C++ LZMA Encoder/Decoder code now is more portable\n  and it can be compiled by GCC on Linux.\n\n\n4.01           2004-02-15\n-------------------------\n- Some detection of data corruption was enabled.\n    LzmaDecode.c / RangeDecoderReadByte\n    .....\n    {\n      rd->ExtraBytes = 1;\n      return 0xFF;\n    }\n\n\n4.00           2004-02-13\n-------------------------\n- Original version of LZMA SDK\n\n\n\nHISTORY of the LZMA\n-------------------\n  2001-2008:  Improvements to LZMA compressing/decompressing code, \n              keeping compatibility with original LZMA format\n  1996-2001:  Development of LZMA compression format\n\n  Some milestones:\n\n  2001-08-30: LZMA compression was added to 7-Zip\n  1999-01-02: First version of 7-Zip was released\n  \n\nEnd of document\n"
  },
  {
    "path": "src/others/squashfs-4.2/lzma-4.65/lzma.txt",
    "content": "LZMA SDK 4.65\n-------------\n\nLZMA SDK provides the documentation, samples, header files, libraries, \nand tools you need to develop applications that use LZMA compression.\n\nLZMA is default and general compression method of 7z format\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \ncompression ratio and very fast decompression.\n\nLZMA is an improved version of famous LZ77 compression algorithm. \nIt was improved in way of maximum increasing of compression ratio,\nkeeping high decompression speed and low memory requirements for \ndecompressing.\n\n\n\nLICENSE\n-------\n\nLZMA SDK is written and placed in the public domain by Igor Pavlov.\n\n\nLZMA SDK Contents\n-----------------\n\nLZMA SDK includes:\n\n  - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\n\n\nUNIX/Linux version \n------------------\nTo compile C++ version of file->file LZMA encoding, go to directory\nC++/7zip/Compress/LZMA_Alone \nand call make to recompile it:\n  make -f makefile.gcc clean all\n\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\nTo compile with static libraries, you can use \nLIB = -lm -static\n\n\nFiles\n---------------------\nlzma.txt     - LZMA SDK description (this file)\n7zFormat.txt - 7z Format description\n7zC.txt      - 7z ANSI-C Decoder description\nmethods.txt  - Compression method IDs for .7z\nlzma.exe     - Compiled file->file LZMA encoder/decoder for Windows\nhistory.txt  - history of the LZMA SDK\n\n\nSource code structure\n---------------------\n\nC/  - C files\n        7zCrc*.*   - CRC code\n        Alloc.*    - Memory allocation functions\n        Bra*.*     - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\n        LzFind.*   - Match finder for LZ (LZMA) encoders \n        LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding\n        LzHash.h   - Additional file for LZ match finder\n        LzmaDec.*  - LZMA decoding\n        LzmaEnc.*  - LZMA encoding\n        LzmaLib.*  - LZMA Library for DLL calling\n        Types.h    - Basic types for another .c files\n\tThreads.*  - The code for multithreading.\n\n    LzmaLib  - LZMA Library (.DLL for Windows)\n    \n    LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).\n\n    Archive - files related to archiving\n      7z     - 7z ANSI-C Decoder\n\nCPP/ -- CPP files\n\n  Common  - common files for C++ projects\n  Windows - common files for Windows related code\n\n  7zip    - files related to 7-Zip Project\n\n    Common   - common files for 7-Zip\n\n    Compress - files related to compression/decompression\n\n      Copy         - Copy coder\n      RangeCoder   - Range Coder (special code of compression/decompression)\n      LZMA         - LZMA compression/decompression on C++\n      LZMA_Alone   - file->file LZMA compression/decompression\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\n\n    Archive - files related to archiving\n\n      Common   - common files for archive handling\n      7z       - 7z C++ Encoder/Decoder\n\n    Bundles    - Modules that are bundles of other modules\n  \n      Alone7z           - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2\n      Format7zR         - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2\n      Format7zExtractR  - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.\n\n    UI        - User Interface files\n         \n      Client7z - Test application for 7za.dll,  7zr.dll, 7zxr.dll\n      Common   - Common UI files\n      Console  - Code for console archiver\n\n\n\nCS/ - C# files\n  7zip\n    Common   - some common files for 7-Zip\n    Compress - files related to compression/decompression\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\n      LZMA         - LZMA compression/decompression\n      LzmaAlone    - file->file LZMA compression/decompression\n      RangeCoder   - Range Coder (special code of compression/decompression)\n\nJava/  - Java files\n  SevenZip\n    Compression    - files related to compression/decompression\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\n      LZMA         - LZMA compression/decompression\n      RangeCoder   - Range Coder (special code of compression/decompression)\n\n\nC/C++ source code of LZMA SDK is part of 7-Zip project.\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\n\n  http://sourceforge.net/projects/sevenzip/\n\n\n\nLZMA features\n-------------\n  - Variable dictionary size (up to 1 GB)\n  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\n  - Estimated decompressing speed: \n      - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64\n      - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC\n  - Small memory requirements for decompressing (16 KB + DictionarySize)\n  - Small code size for decompressing: 5-8 KB\n\nLZMA decoder uses only integer operations and can be \nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\n\nSome critical operations that affect the speed of LZMA decompression:\n  1) 32*16 bit integer multiply\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\n  3) 32-bit shift and arithmetic operations\n\nThe speed of LZMA decompressing mostly depends from CPU speed.\nMemory speed has no big meaning. But if your CPU has small data cache, \noverall weight of memory speed will slightly increase.\n\n\nHow To Use\n----------\n\nUsing LZMA encoder/decoder executable\n--------------------------------------\n\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\n\n  e: encode file\n\n  d: decode file\n\n  b: Benchmark. There are two tests: compressing and decompressing \n     with LZMA method. Benchmark shows rating in MIPS (million \n     instructions per second). Rating value is calculated from \n     measured speed and it is normalized with Intel's Core 2 results.\n     Also Benchmark checks possible hardware errors (RAM \n     errors in most cases). Benchmark uses these settings:\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \n     Also you can change the number of iterations. Example for 30 iterations:\n       LZMA b 30\n     Default number of iterations is 10.\n\n<Switches>\n  \n\n  -a{N}:  set compression mode 0 = fast, 1 = normal\n          default: 1 (normal)\n\n  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\n          The maximum value for dictionary size is 1 GB = 2^30 bytes.\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \n          For decompressing file compressed by LZMA method with dictionary \n          size D = 2^N you need about D bytes of memory (RAM).\n\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\n          Usually big number gives a little bit better compression ratio \n          and slower compression process.\n\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\n          Sometimes lc=4 gives gain for big files.\n\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\n          lp switch is intended for periodical data when period is \n          equal 2^N. For example, for 32-bit (4 bytes) \n          periodical data you can use lp=2. Often it's better to set lc0, \n          if you change lp switch.\n\n  -pb{N}: set number of pos bits - [0, 4], default: 2\n          pb switch is intended for periodical data \n          when period is equal 2^N.\n\n  -mf{MF_ID}: set Match Finder. Default: bt4. \n              Algorithms from hc* group doesn't provide good compression \n              ratio, but they often works pretty fast in combination with \n              fast mode (-a0).\n\n              Memory requirements depend from dictionary size \n              (parameter \"d\" in table below). \n\n               MF_ID     Memory                   Description\n\n                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\n                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\n                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\n                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\n\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \n          eos marker, since LZMA decoder knows uncompressed size \n          stored in .lzma file header.\n\n  -si:    Read data from stdin (it will write End Of Stream marker).\n  -so:    Write data to stdout\n\n\nExamples:\n\n1) LZMA e file.bin file.lzma -d16 -lc0 \n\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \nand 0 literal context bits. -lc0 allows to reduce memory requirements \nfor decompression.\n\n\n2) LZMA e file.bin file.lzma -lc0 -lp2\n\ncompresses file.bin to file.lzma with settings suitable \nfor 32-bit periodical data (for example, ARM or MIPS code).\n\n3) LZMA d file.lzma file.bin\n\ndecompresses file.lzma to file.bin.\n\n\nCompression ratio hints\n-----------------------\n\nRecommendations\n---------------\n\nTo increase the compression ratio for LZMA compressing it's desirable \nto have aligned data (if it's possible) and also it's desirable to locate\ndata in such order, where code is grouped in one place and data is \ngrouped in other place (it's better than such mixing: code, data, code,\ndata, ...).\n\n\nFilters\n-------\nYou can increase the compression ratio for some data types, using\nspecial filters before compressing. For example, it's possible to \nincrease the compression ratio on 5-10% for code for those CPU ISAs: \nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\n\nYou can find C source code of such filters in C/Bra*.* files\n\nYou can check the compression ratio gain of these filters with such \n7-Zip commands (example for ARM code):\nNo filter:\n  7z a a1.7z a.bin -m0=lzma\n\nWith filter for little-endian ARM code:\n  7z a a2.7z a.bin -m0=arm -m1=lzma        \n\nIt works in such manner:\nCompressing    = Filter_encoding + LZMA_encoding\nDecompressing  = LZMA_decoding + Filter_decoding\n\nCompressing and decompressing speed of such filters is very high,\nso it will not increase decompressing time too much.\nMoreover, it reduces decompression time for LZMA_decoding, \nsince compression ratio with filtering is higher.\n\nThese filters convert CALL (calling procedure) instructions \nfrom relative offsets to absolute addresses, so such data becomes more \ncompressible.\n\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\n\n\nLZMA compressed file format\n---------------------------\nOffset Size Description\n  0     1   Special LZMA properties (lc,lp, pb in encoded form)\n  1     4   Dictionary size (little endian)\n  5     8   Uncompressed size (little endian). -1 means unknown size\n 13         Compressed data\n\n\nANSI-C LZMA Decoder\n~~~~~~~~~~~~~~~~~~~\n\nPlease note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.\nIf you want to use old interfaces you can download previous version of LZMA SDK\nfrom sourceforge.net site.\n\nTo use ANSI-C LZMA Decoder you need the following files:\n1) LzmaDec.h + LzmaDec.c + Types.h\nLzmaUtil/LzmaUtil.c is example application that uses these files.\n\n\nMemory requirements for LZMA decoding\n-------------------------------------\n\nStack usage of LZMA decoding function for local variables is not \nlarger than 200-400 bytes.\n\nLZMA Decoder uses dictionary buffer and internal state structure.\nInternal state structure consumes\n  state_size = (4 + (1.5 << (lc + lp))) KB\nby default (lc=3, lp=0), state_size = 16 KB.\n\n\nHow To decompress data\n----------------------\n\nLZMA Decoder (ANSI-C version) now supports 2 interfaces:\n1) Single-call Decompressing\n2) Multi-call State Decompressing (zlib-like interface)\n\nYou must use external allocator:\nExample:\nvoid *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\nvoid SzFree(void *p, void *address) { p = p; free(address); }\nISzAlloc alloc = { SzAlloc, SzFree };\n\nYou can use p = p; operator to disable compiler warnings.\n\n\nSingle-call Decompressing\n-------------------------\nWhen to use: RAM->RAM decompressing\nCompile files: LzmaDec.h + LzmaDec.c + Types.h\nCompile defines: no defines\nMemory Requirements:\n  - Input buffer: compressed size\n  - Output buffer: uncompressed size\n  - LZMA Internal Structures: state_size (16 KB for default settings) \n\nInterface:\n  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\n      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, \n      ELzmaStatus *status, ISzAlloc *alloc);\n  In: \n    dest     - output data\n    destLen  - output data size\n    src      - input data\n    srcLen   - input data size\n    propData - LZMA properties  (5 bytes)\n    propSize - size of propData buffer (5 bytes)\n    finishMode - It has meaning only if the decoding reaches output limit (*destLen).\n\t LZMA_FINISH_ANY - Decode just destLen bytes.\n\t LZMA_FINISH_END - Stream must be finished after (*destLen).\n                           You can use LZMA_FINISH_END, when you know that \n                           current output buffer covers last bytes of stream. \n    alloc    - Memory allocator.\n\n  Out: \n    destLen  - processed output size \n    srcLen   - processed input size \n\n  Output:\n    SZ_OK\n      status:\n        LZMA_STATUS_FINISHED_WITH_MARK\n        LZMA_STATUS_NOT_FINISHED \n        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\n    SZ_ERROR_DATA - Data error\n    SZ_ERROR_MEM  - Memory allocation error\n    SZ_ERROR_UNSUPPORTED - Unsupported properties\n    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\n\n  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,\n  and output value of destLen will be less than output buffer size limit.\n\n  You can use multiple checks to test data integrity after full decompression:\n    1) Check Result and \"status\" variable.\n    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\n    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. \n       You must use correct finish mode in that case. */ \n\n\nMulti-call State Decompressing (zlib-like interface)\n----------------------------------------------------\n\nWhen to use: file->file decompressing \nCompile files: LzmaDec.h + LzmaDec.c + Types.h\n\nMemory Requirements:\n - Buffer for input stream: any size (for example, 16 KB)\n - Buffer for output stream: any size (for example, 16 KB)\n - LZMA Internal Structures: state_size (16 KB for default settings) \n - LZMA dictionary (dictionary size is encoded in LZMA properties header)\n\n1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:\n   unsigned char header[LZMA_PROPS_SIZE + 8];\n   ReadFile(inFile, header, sizeof(header)\n\n2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties\n\n  CLzmaDec state;\n  LzmaDec_Constr(&state);\n  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);\n  if (res != SZ_OK)\n    return res;\n\n3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop\n\n  LzmaDec_Init(&state);\n  for (;;)\n  {\n    ... \n    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, \n    \tconst Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);\n    ...\n  }\n\n\n4) Free all allocated structures\n  LzmaDec_Free(&state, &g_Alloc);\n\nFor full code example, look at C/LzmaUtil/LzmaUtil.c code.\n\n\nHow To compress data\n--------------------\n\nCompile files: LzmaEnc.h + LzmaEnc.c + Types.h +\nLzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h\n\nMemory Requirements:\n  - (dictSize * 11.5 + 6 MB) + state_size\n\nLzma Encoder can use two memory allocators:\n1) alloc - for small arrays.\n2) allocBig - for big arrays.\n\nFor example, you can use Large RAM Pages (2 MB) in allocBig allocator for \nbetter compression speed. Note that Windows has bad implementation for \nLarge RAM Pages. \nIt's OK to use same allocator for alloc and allocBig.\n\n\nSingle-call Compression with callbacks\n--------------------------------------\n\nCheck C/LzmaUtil/LzmaUtil.c as example, \n\nWhen to use: file->file decompressing \n\n1) you must implement callback structures for interfaces:\nISeqInStream\nISeqOutStream\nICompressProgress\nISzAlloc\n\nstatic void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\nstatic void SzFree(void *p, void *address) {  p = p; MyFree(address); }\nstatic ISzAlloc g_Alloc = { SzAlloc, SzFree };\n\n  CFileSeqInStream inStream;\n  CFileSeqOutStream outStream;\n\n  inStream.funcTable.Read = MyRead;\n  inStream.file = inFile;\n  outStream.funcTable.Write = MyWrite;\n  outStream.file = outFile;\n\n\n2) Create CLzmaEncHandle object;\n\n  CLzmaEncHandle enc;\n\n  enc = LzmaEnc_Create(&g_Alloc);\n  if (enc == 0)\n    return SZ_ERROR_MEM;\n\n\n3) initialize CLzmaEncProps properties;\n\n  LzmaEncProps_Init(&props);\n\n  Then you can change some properties in that structure.\n\n4) Send LZMA properties to LZMA Encoder\n\n  res = LzmaEnc_SetProps(enc, &props);\n\n5) Write encoded properties to header\n\n    Byte header[LZMA_PROPS_SIZE + 8];\n    size_t headerSize = LZMA_PROPS_SIZE;\n    UInt64 fileSize;\n    int i;\n\n    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\n    fileSize = MyGetFileLength(inFile);\n    for (i = 0; i < 8; i++)\n      header[headerSize++] = (Byte)(fileSize >> (8 * i));\n    MyWriteFileAndCheck(outFile, header, headerSize)\n\n6) Call encoding function:\n      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, \n        NULL, &g_Alloc, &g_Alloc);\n\n7) Destroy LZMA Encoder Object\n  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\n\n\nIf callback function return some error code, LzmaEnc_Encode also returns that code.\n\n\nSingle-call RAM->RAM Compression\n--------------------------------\n\nSingle-call RAM->RAM Compression is similar to Compression with callbacks,\nbut you provide pointers to buffers instead of pointers to stream callbacks:\n\nHRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\n    CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, \n    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\n\nReturn code:\n  SZ_OK               - OK\n  SZ_ERROR_MEM        - Memory allocation error \n  SZ_ERROR_PARAM      - Incorrect paramater\n  SZ_ERROR_OUTPUT_EOF - output buffer overflow\n  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\n\n\n\nLZMA Defines\n------------\n\n_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.\n\n_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for \n                 some structures will be doubled in that case.\n\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.\n\n_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.\n\n\nC++ LZMA Encoder/Decoder \n~~~~~~~~~~~~~~~~~~~~~~~~\nC++ LZMA code use COM-like interfaces. So if you want to use it, \nyou can study basics of COM/OLE.\nC++ LZMA code is just wrapper over ANSI-C code.\n\n\nC++ Notes\n~~~~~~~~~~~~~~~~~~~~~~~~\nIf you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),\nyou must check that you correctly work with \"new\" operator.\n7-Zip can be compiled with MSVC 6.0 that doesn't throw \"exception\" from \"new\" operator.\nSo 7-Zip uses \"CPP\\Common\\NewHandler.cpp\" that redefines \"new\" operator:\noperator new(size_t size)\n{\n  void *p = ::malloc(size);\n  if (p == 0)\n    throw CNewException();\n  return p;\n}\nIf you use MSCV that throws exception for \"new\" operator, you can compile without \n\"NewHandler.cpp\". So standard exception will be used. Actually some code of \n7-Zip catches any exception in internal code and converts it to HRESULT code.\nSo you don't need to catch CNewException, if you call COM interfaces of 7-Zip.\n\n---\n\nhttp://www.7-zip.org\nhttp://www.7-zip.org/sdk.html\nhttp://www.7-zip.org/support.html\n"
  },
  {
    "path": "src/others/squashfs-4.2/pseudo-file.example",
    "content": "# Pseudo file example\n\n# Mksquashfs supports pseudo files, these allow fake files, directories,\n# character and block devices to be specified and added to the Squashfs\n# filesystem being built, rather than requiring them to be present in the\n# source directories.\n#\n# This, for example, allows device nodes to be added to the filesystem without\n# requiring root access.\n\n# Mksquashfs 4.1 adds support for \"dynamic pseudo files\" and a modify operation.\n# Dynamic pseudo files allow files to be dynamically created when Mksquashfs\n# is run, their contents being the result of running a command or piece of\n# shell script.  The modifiy operation allows the mode/uid/gid of an existing\n# file in the source filesystem to be modified.\n\n# Two Mksquashfs options are supported, -p allows one pseudo file to be\n# specified #on the command line, and -pf allows a pseudo file to be specified\n# containing a list of pseduo definitions, one per line.\n\n# Pseudo file examples\n# Run mkquashfs . /tmp/img -pf pseudo-file.examples\n# to see their effect\n\n# Creating dynamic file examples\n\n# Create a file \"dmesg\" containing the output from dmesg.\ndmesg f 444 root root dmesg\n\n\n# Create a file RELEASE containing the release name, date, build host, and\n# an incrementing version number.  The incrementing version is a side-effect\n# of executing the shell script, and ensures every time Mksquashfs is run a\n# new version number is used without requiring any other shell scripting.\nRELEASE f 444 root root \\\n\t\tif [ ! -e /tmp/ver ]; then \\\n\t\t\techo 0 > /tmp/ver; \\\n\t\tfi; \\\n                ver=`cat /tmp/ver`; \\\n                ver=$((ver +1)); \\\n                echo $ver > /tmp/ver; \\\n                echo -n \"release x.x\"; \\\n                echo \"-dev #\"$ver `date` \"Build host\" `hostname`\n\n\n# Copy 10K from the device /dev/sda1 into the file input.  Ordinarily\n# Mksquashfs given a device, fifo, or named socket will place that special file\n# within the Squashfs filesystem, this allows input from these special\n# files to be captured and placed in the Squashfs filesystem.\ninput f 444 root root dd if=/dev/sda1 bs=1024 count=10\n\n\n# Creating a block or character device examples\n\n# Create a character device \"chr_dev\" with major:minor 100:1 and\n# a block device \"blk_dev\" with major:minor 200:200, both with root\n# uid/gid and a mode of rw-rw-rw.\nchr_dev c 666 root root 100 1\nblk_dev b 666 0 0 200 200\n\n\n# Creating a directory example\n\n# create a directory \"pseudo_dir\" with root uid/gid and mode of r--r--r--.\npseudo_dir d 444 root root\n\n\n# Modifying attributes of an existing file exmaple\n\n# Change the attributes of the file \"INSTALL\" in the filesystem to have\n# root uid/gid and a mode of rw-rw-rw, overriding the attributes obtained\n# from the source filesystem.\nINSTALL m 666 root root\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/Makefile",
    "content": "###############################################\n#          Compression build options          #\n###############################################\n#\n#\n############# Building gzip support ###########\n#\n# Gzip support is by default enabled, and the compression type default\n# (COMP_DEFAULT) is gzip.\n#\n# If you don't want/need gzip support then comment out the GZIP SUPPORT line\n# below, and change COMP_DEFAULT to one of the compression types you have\n# selected.\n#\n# Obviously, you must select at least one of the available gzip, lzma, lzo\n# compression types.\n#\nGZIP_SUPPORT = 1\n\n########### Building XZ support #############\n#\n# LZMA2 compression.\n#\n# XZ Utils liblzma (http://tukaani.org/xz/) is supported\n#\n# To build using XZ Utils liblzma - install the library and uncomment\n# the XZ_SUPPORT line below.\n#\nXZ_SUPPORT = 1\n\n\n############ Building LZO support ##############\n#\n# The LZO library (http://www.oberhumer.com/opensource/lzo/) is supported.\n#\n# To build using the LZO library - install the library and uncomment the\n# LZO_SUPPORT line below. If needed, uncomment and set LZO_DIR to the\n# installation prefix.\n#\n#LZO_SUPPORT = 1\n#LZO_DIR = /usr/local\n\n########### Building LZMA support #############\n#\n# LZMA1 compression.\n#\n# LZMA1 compression is deprecated, and the newer and better XZ (LZMA2)\n# compression should be used in preference.\n#\n# Both XZ Utils liblzma (http://tukaani.org/xz/) and LZMA SDK\n# (http://www.7-zip.org/sdk.html) are supported\n#\n# To build using XZ Utils liblzma - install the library and uncomment\n# the LZMA_XZ_SUPPORT line below.\n#\n# To build using the LZMA SDK (4.65 used in development, other versions may\n# work) - download and unpack it, uncomment and set LZMA_DIR to unpacked source,\n# and uncomment the LZMA_SUPPORT line below.\n#\nLZMA_XZ_SUPPORT = 1\n#LZMA_SUPPORT = 1\nLZMA_DIR = ../lzma-4.65\n\n######## Specifying default compression ########\n#\n# The next line specifies which compression algorithm is used by default\n# in Mksquashfs.  Obviously the compression algorithm must have been\n# selected to be built\n#\nCOMP_DEFAULT = gzip\n\n###############################################\n#  Extended attribute (XATTRs) build options  #\n###############################################\n#\n# Building XATTR support for Mksquashfs and Unsquashfs\n#\n# If your C library or build/target environment doesn't support XATTRs then\n# comment out the next line to build Mksquashfs and Unsquashfs without XATTR\n# support\nXATTR_SUPPORT = 1\n\n# Select whether you wish xattrs to be stored by Mksquashfs and extracted\n# by Unsquashfs by default.  If selected users can disable xattr support by\n# using the -no-xattrs option\n#\n# If unselected, Mksquashfs/Unsquashfs won't store and extract xattrs by\n# default.  Users can enable xattrs by using the -xattrs option.\nXATTR_DEFAULT = 1\n\n\n###############################################\n#        End of BUILD options section         #\n###############################################\n\nINCLUDEDIR = -I.\nINSTALL_DIR = /usr/local/bin\n\nMKSQUASHFS_OBJS = mksquashfs.o read_fs.o sort.o swap.o pseudo.o compressor.o\n\nUNSQUASHFS_OBJS = unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o \\\n\tunsquash-4.o swap.o compressor.o\n\nCFLAGS ?= -O2\nCFLAGS += $(EXTRA_CFLAGS) $(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 \\\n\t-D_LARGEFILE_SOURCE -D_GNU_SOURCE -DCOMP_DEFAULT=\\\"$(COMP_DEFAULT)\\\" \\\n\t-Wall\n\nLIBS = -lpthread -lm\nifeq ($(GZIP_SUPPORT),1)\nCFLAGS += -DGZIP_SUPPORT\nMKSQUASHFS_OBJS += gzip_wrapper.o\nUNSQUASHFS_OBJS += gzip_wrapper.o\nLIBS += -lz\nCOMPRESSORS += gzip\nendif\n\nifeq ($(LZMA_SUPPORT),1)\nLZMA_OBJS = $(LZMA_DIR)/C/Alloc.o $(LZMA_DIR)/C/LzFind.o \\\n\t$(LZMA_DIR)/C/LzmaDec.o $(LZMA_DIR)/C/LzmaEnc.o $(LZMA_DIR)/C/LzmaLib.o\nINCLUDEDIR += -I$(LZMA_DIR)/C\nCFLAGS += -DLZMA_SUPPORT\nMKSQUASHFS_OBJS += lzma_wrapper.o $(LZMA_OBJS)\nUNSQUASHFS_OBJS += lzma_wrapper.o $(LZMA_OBJS)\nCOMPRESSORS += lzma\nendif\n\nifeq ($(LZMA_XZ_SUPPORT),1)\nCFLAGS += -DLZMA_SUPPORT\nMKSQUASHFS_OBJS += lzma_xz_wrapper.o\nUNSQUASHFS_OBJS += lzma_xz_wrapper.o\nCOMPRESSORS += lzma\nendif\n\nifeq ($(XZ_SUPPORT),1)\nCFLAGS += -DXZ_SUPPORT\nMKSQUASHFS_OBJS += xz_wrapper.o\nUNSQUASHFS_OBJS += xz_wrapper.o\nCOMPRESSORS += xz\nendif\n\nifneq ($(LZMA_XZ_SUPPORT)$(XZ_SUPPORT),)\nMKSQUASHFS_OBJS += lzma_xz_options.o\nUNSQUASHFS_OBJS += lzma_xz_options.o\nifneq ($(LZMA_LIB),)\nMKSQUASHFS_OBJS += $(LZMA_LIB)\nUNSQUASHFS_OBJS += $(LZMA_LIB)\nelse\nLIBS += -llzma\nendif\nendif\n\nifeq ($(LZO_SUPPORT),1)\nCFLAGS += -DLZO_SUPPORT\nifdef LZO_DIR\nINCLUDEDIR += -I$(LZO_DIR)/include\nLZO_LIBDIR = -L$(LZO_DIR)/lib\nendif\nMKSQUASHFS_OBJS += lzo_wrapper.o\nUNSQUASHFS_OBJS += lzo_wrapper.o\nLIBS += $(LZO_LIBDIR) -llzo2\nCOMPRESSORS += lzo\nendif\n\nifeq ($(XATTR_SUPPORT),1)\nifeq ($(XATTR_DEFAULT),1)\nCFLAGS += -DXATTR_SUPPORT -DXATTR_DEFAULT\nelse\nCFLAGS += -DXATTR_SUPPORT\nendif\nMKSQUASHFS_OBJS += xattr.o read_xattrs.o\nUNSQUASHFS_OBJS += read_xattrs.o unsquashfs_xattr.o\nendif\n\n#\n# If LZMA_SUPPORT is specified then LZMA_DIR must be specified too\n#\nifeq ($(LZMA_SUPPORT),1)\nifndef LZMA_DIR\n$(error \"LZMA_SUPPORT requires LZMA_DIR to be also defined\")\nendif\nendif\n\n#\n# Both LZMA_XZ_SUPPORT and LZMA_SUPPORT cannot be specified\n#\nifeq ($(LZMA_XZ_SUPPORT),1)\nifeq ($(LZMA_SUPPORT),1)\n$(error \"Both LZMA_XZ_SUPPORT and LZMA_SUPPORT cannot be specified\")\nendif\nendif\n\n#\n# At least one compressor must have been selected\n#\nifndef COMPRESSORS\n$(error \"No compressor selected! Select one or more of GZIP, LZMA, XZ or LZO!\")\nendif\n\n#\n# COMP_DEFAULT must be a selected compressor\n#\nifeq (, $(findstring $(COMP_DEFAULT), $(COMPRESSORS)))\n$(error \"COMP_DEFAULT isn't selected to be built!\")\nendif\n\n.PHONY: all\nall: mksquashfs unsquashfs\n\nmksquashfs: $(MKSQUASHFS_OBJS)\n\t$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) $(MKSQUASHFS_OBJS) $(LIBS) -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h sort.h squashfs_swap.h \\\n\txattr.h pseudo.h compressor.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h squashfs_swap.h compressor.h \\\n\txattr.h\n\nsort.o: sort.c squashfs_fs.h sort.h mksquashfs.h\n\nswap.o: swap.c\n\npseudo.o: pseudo.c pseudo.h\n\ncompressor.o: compressor.c compressor.h squashfs_fs.h\n\nxattr.o: xattr.c xattr.h squashfs_fs.h squashfs_swap.h mksquashfs.h\n\nread_xattrs.o: read_xattrs.c xattr.h squashfs_fs.h squashfs_swap.h read_fs.h\n\ngzip_wrapper.o: gzip_wrapper.c compressor.h squashfs_fs.h\n\nlzma_wrapper.o: lzma_wrapper.c compressor.h squashfs_fs.h\n\nlzma_xz_wrapper.o: lzma_xz_wrapper.c compressor.h squashfs_fs.h\n\nlzo_wrapper.o: lzo_wrapper.c compressor.h squashfs_fs.h\n\nxz_wrapper.o: xz_wrapper.c compressor.h squashfs_fs.h\n\nunsquashfs: $(UNSQUASHFS_OBJS)\n\t$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) $(UNSQUASHFS_OBJS) $(LIBS) -o $@\n\nunsquashfs.o: unsquashfs.h unsquashfs.c squashfs_fs.h squashfs_swap.h \\\n\tsquashfs_compat.h xattr.h read_fs.h compressor.h\n\nunsquash-1.o: unsquashfs.h unsquash-1.c squashfs_fs.h squashfs_compat.h\n\nunsquash-2.o: unsquashfs.h unsquash-2.c squashfs_fs.h squashfs_compat.h\n\nunsquash-3.o: unsquashfs.h unsquash-3.c squashfs_fs.h squashfs_compat.h\n\nunsquash-4.o: unsquashfs.h unsquash-4.c squashfs_fs.h squashfs_swap.h \\\n\tread_fs.h\n\nunsquashfs_xattr.o: unsquashfs_xattr.c unsquashfs.h squashfs_fs.h xattr.h\n\n\n.PHONY: clean\nclean:\n\t-rm -f *.o mksquashfs unsquashfs\n\n.PHONY: install\ninstall: mksquashfs unsquashfs\n\tmkdir -p $(INSTALL_DIR)\n\tcp mksquashfs $(INSTALL_DIR)\n\tcp unsquashfs $(INSTALL_DIR)\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/compressor.c",
    "content": "/*\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * compressor.c\n */\n\n#include <stdio.h>\n#include <string.h>\n#include \"compressor.h\"\n#include \"squashfs_fs.h\"\n\n#ifndef GZIP_SUPPORT\nstatic struct compressor gzip_comp_ops =  {\n\tNULL, NULL, NULL, NULL, NULL, NULL, ZLIB_COMPRESSION, \"gzip\", 0\n};\n#else\nextern struct compressor gzip_comp_ops;\n#endif\n\n#ifndef LZMA_SUPPORT\nstatic struct compressor lzma_comp_ops = {\n\tNULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, LZMA_COMPRESSION,\n\t\"lzma\", 0\n};\n#else\nextern struct compressor lzma_comp_ops;\n#endif\n\n#ifndef LZO_SUPPORT\nstatic struct compressor lzo_comp_ops = {\n\tNULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, LZO_COMPRESSION, \"lzo\",\n\t0\n};\n#else\nextern struct compressor lzo_comp_ops;\n#endif\n\n#ifndef XZ_SUPPORT\nstatic struct compressor xz_comp_ops = {\n\tNULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, XZ_COMPRESSION, \"xz\", 0\n};\n#else\nextern struct compressor xz_comp_ops;\n#endif\n\n\nstatic struct compressor unknown_comp_ops = {\n\tNULL, NULL, NULL , NULL, NULL, NULL, NULL, NULL, 0, \"unknown\", 0\n};\n\n\nstruct compressor *compressor[] = {\n\t&gzip_comp_ops,\n\t&lzma_comp_ops,\n\t&lzo_comp_ops,\n\t&xz_comp_ops,\n\t&unknown_comp_ops\n};\n\n\nstruct compressor *lookup_compressor(char *name)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i]->id; i++)\n\t\tif(strcmp(compressor[i]->name, name) == 0)\n\t\t\tbreak;\n\n\treturn compressor[i];\n}\n\n\nstruct compressor *lookup_compressor_id(int id)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i]->id; i++)\n\t\tif(id == compressor[i]->id)\n\t\t\tbreak;\n\n\treturn compressor[i];\n}\n\n\nvoid display_compressors(char *indent, char *def_comp)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i]->id; i++)\n\t\tif(compressor[i]->supported)\n\t\t\tfprintf(stderr, \"%s\\t%s%s\\n\", indent,\n\t\t\t\tcompressor[i]->name,\n\t\t\t\tstrcmp(compressor[i]->name, def_comp) == 0 ?\n\t\t\t\t\" (default)\" : \"\");\n}\n\n\nvoid display_compressor_usage(char *def_comp)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i]->id; i++)\n\t\tif(compressor[i]->supported) {\n\t\t\tchar *str = strcmp(compressor[i]->name, def_comp) == 0 ?\n\t\t\t\t\" (default)\" : \"\";\n\t\t\tif(compressor[i]->usage) {\n\t\t\t\tfprintf(stderr, \"\\t%s%s\\n\",\n\t\t\t\t\tcompressor[i]->name, str);\n\t\t\t\tcompressor[i]->usage();\n\t\t\t} else\n\t\t\t\tfprintf(stderr, \"\\t%s (no options)%s\\n\",\n\t\t\t\t\tcompressor[i]->name, str);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/compressor.h",
    "content": "/*\n *\n * Copyright (c) 2009, 2010, 2011\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * compressor.h\n */\n\nstruct compressor {\n\tint (*init)(void **, int, int);\n\tint (*compress)(void *, void *, void *, int, int, int *);\n\tint (*uncompress)(void *, void *, int, int, int *);\n\tint (*options)(char **, int);\n\tint (*options_post)(int);\n\tvoid *(*dump_options)(int, int *);\n\tint (*extract_options)(int, void *, int);\n\tvoid (*usage)();\n\tint id;\n\tchar *name;\n\tint supported;\n};\n\nextern struct compressor *lookup_compressor(char *);\nextern struct compressor *lookup_compressor_id(int);\nextern void display_compressors(char *, char *);\nextern void display_compressor_usage(char *);\n\nstatic inline int compressor_init(struct compressor *comp, void **stream,\n\tint block_size, int datablock)\n{\n\tif(comp->init == NULL)\n\t\treturn 0;\n\treturn comp->init(stream, block_size, datablock);\n}\n\n\nstatic inline int compressor_compress(struct compressor *comp, void *strm,\n\tvoid *dest, void *src, int size, int block_size, int *error)\n{\n\treturn comp->compress(strm, dest, src, size, block_size, error);\n}\n\n\nstatic inline int compressor_uncompress(struct compressor *comp, void *dest,\n\tvoid *src, int size, int block_size, int *error)\n{\n\treturn comp->uncompress(dest, src, size, block_size, error);\n}\n\n\nstatic inline int compressor_options(struct compressor *comp, char *argv[],\n\tint argc)\n{\n\tif(comp->options == NULL)\n\t\treturn -1;\n\n\treturn comp->options(argv, argc);\n}\n\n\nstatic inline int compressor_options_post(struct compressor *comp, int block_size)\n{\n\tif(comp->options_post == NULL)\n\t\treturn 0;\n\treturn comp->options_post(block_size);\n}\n\n\nstatic inline void *compressor_dump_options(struct compressor *comp,\n\tint block_size, int *size)\n{\n\tif(comp->dump_options == NULL)\n\t\treturn NULL;\n\treturn comp->dump_options(block_size, size);\n}\n\n\nstatic inline int compressor_extract_options(struct compressor *comp,\n\tint block_size, void *buffer, int size)\n{\n\tif(comp->extract_options == NULL)\n\t\treturn size ? -1 : 0;\n\treturn comp->extract_options(block_size, buffer, size);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/gzip_wrapper.c",
    "content": "/*\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * gzip_wrapper.c\n */\n\n#include <stdlib.h>\n#include <zlib.h>\n\n#include \"squashfs_fs.h\"\n#include \"compressor.h\"\n\nstatic int gzip_init(void **strm, int block_size, int flags)\n{\n\tint res;\n\tz_stream *stream;\n\n\tstream = *strm = malloc(sizeof(z_stream));\n\tif(stream == NULL)\n\t\tgoto failed;\n\n\tstream->zalloc = Z_NULL;\n\tstream->zfree = Z_NULL;\n\tstream->opaque = 0;\n\n\tres = deflateInit(stream, 9);\n\tif(res != Z_OK)\n\t\tgoto failed2;\n\n\treturn 0;\n\nfailed2:\n\tfree(stream);\nfailed:\n\treturn -1;\n}\n\n\nstatic int gzip_compress(void *strm, void *d, void *s, int size, int block_size,\n\t\tint *error)\n{\n\tint res;\n\tz_stream *stream = strm;\n\n\tres = deflateReset(stream);\n\tif(res != Z_OK)\n\t\tgoto failed;\n\n\tstream->next_in = s;\n\tstream->avail_in = size;\n\tstream->next_out = d;\n\tstream->avail_out = block_size;\n\n\tres = deflate(stream, Z_FINISH);\n\tif(res == Z_STREAM_END)\n\t\t/*\n\t\t * Success, return the compressed size.\n\t\t */\n\t\treturn (int) stream->total_out;\n\tif(res == Z_OK)\n\t\t/*\n\t\t * Output buffer overflow.  Return out of buffer space\n\t\t */\n\t\treturn 0;\nfailed:\n\t/*\n\t * All other errors return failure, with the compressor\n\t * specific error code in *error\n\t */\n\t*error = res;\n\treturn -1;\n}\n\n\nstatic int gzip_uncompress(void *d, void *s, int size, int block_size, int *error)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\n\tres = uncompress(d, &bytes, s, size);\n\n\t*error = res;\n\treturn res == Z_OK ? (int) bytes : -1;\n}\n\n\nstruct compressor gzip_comp_ops = {\n\t.init = gzip_init,\n\t.compress = gzip_compress,\n\t.uncompress = gzip_uncompress,\n\t.options = NULL,\n\t.usage = NULL,\n\t.id = ZLIB_COMPRESSION,\n\t.name = \"gzip\",\n\t.supported = 1\n};\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/lzma_wrapper.c",
    "content": "/*\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * lzma_wrapper.c\n *\n * Support for LZMA1 compression using LZMA SDK (4.65 used in\n * development, other versions may work) http://www.7-zip.org/sdk.html\n */\n\n#include <LzmaLib.h>\n\n#include \"squashfs_fs.h\"\n#include \"compressor.h\"\n\n#define LZMA_HEADER_SIZE\t(LZMA_PROPS_SIZE + 8)\n\nstatic int lzma_compress(void *strm, void *dest, void *src, int size, int block_size,\n\t\tint *error)\n{\n\tunsigned char *d = dest;\n\tsize_t props_size = LZMA_PROPS_SIZE,\n\t\toutlen = block_size - LZMA_HEADER_SIZE;\n\tint res;\n\n\tres = LzmaCompress(dest + LZMA_HEADER_SIZE, &outlen, src, size, dest,\n\t\t&props_size, 5, block_size, 3, 0, 2, 32, 1);\n\t\n\tif(res == SZ_ERROR_OUTPUT_EOF) {\n\t\t/*\n\t\t * Output buffer overflow.  Return out of buffer space error\n\t\t */\n\t\treturn 0;\n\t}\n\n\tif(res != SZ_OK) {\n\t\t/*\n\t\t * All other errors return failure, with the compressor\n\t\t * specific error code in *error\n\t\t */\n\t\t*error = res;\n\t\treturn -1;\n\t}\n\n\t/*\n\t * Fill in the 8 byte little endian uncompressed size field in the\n\t * LZMA header.  8 bytes is excessively large for squashfs but\n\t * this is the standard LZMA header and which is expected by the kernel\n\t * code\n\t */\n\td[LZMA_PROPS_SIZE] = size & 255;\n\td[LZMA_PROPS_SIZE + 1] = (size >> 8) & 255;\n\td[LZMA_PROPS_SIZE + 2] = (size >> 16) & 255;\n\td[LZMA_PROPS_SIZE + 3] = (size >> 24) & 255;\n\td[LZMA_PROPS_SIZE + 4] = 0;\n\td[LZMA_PROPS_SIZE + 5] = 0;\n\td[LZMA_PROPS_SIZE + 6] = 0;\n\td[LZMA_PROPS_SIZE + 7] = 0;\n\n\t/*\n\t * Success, return the compressed size.  Outlen returned by the LZMA\n\t * compressor does not include the LZMA header space\n\t */\n\treturn outlen + LZMA_HEADER_SIZE;\n}\n\n\nstatic int lzma_uncompress(void *dest, void *src, int size, int block_size,\n\tint *error)\n{\n\tunsigned char *s = src;\n\tsize_t outlen, inlen = size - LZMA_HEADER_SIZE;\n\tint res;\n\n\toutlen = s[LZMA_PROPS_SIZE] |\n\t\t(s[LZMA_PROPS_SIZE + 1] << 8) |\n\t\t(s[LZMA_PROPS_SIZE + 2] << 16) |\n\t\t(s[LZMA_PROPS_SIZE + 3] << 24);\n\n\tres = LzmaUncompress(dest, &outlen, src + LZMA_HEADER_SIZE, &inlen, src,\n\t\tLZMA_PROPS_SIZE);\n\t\n\t*error = res;\n\treturn res == SZ_OK ? outlen : -1;\n}\n\n\nstruct compressor lzma_comp_ops = {\n\t.init = NULL,\n\t.compress = lzma_compress,\n\t.uncompress = lzma_uncompress,\n\t.options = NULL,\n\t.usage = NULL,\n\t.id = LZMA_COMPRESSION,\n\t.name = \"lzma\",\n\t.supported = 1\n};\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/lzma_xz_options.c",
    "content": "/*\n * Copyright (c) 2011\n * Jonas Gorski <jonas.gorski@gmail.com>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * lzma_options.c\n * \n * Common options for LZMA1 and 2 compressors. Based on xz_wrapper.c\n */\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <lzma.h>\n\n#include \"lzma_xz_options.h\"\n\nstatic const char const *lzmaver_str[] = { \"\", \"lzma\", \"xz\" };\n\nstatic struct lzma_xz_options options = {\n\t.flags\t\t= 0,\n\t.preset\t\t= 6,\n\t.extreme\t= 0,\n\t.lc\t\t= LZMA_OPT_LC_DEFAULT,\n\t.lp\t\t= LZMA_OPT_LP_DEFAULT,\n\t.pb\t\t= LZMA_OPT_PB_DEFAULT,\n\t.fb\t\t= LZMA_OPT_FB_DEFAULT,\n\t.dict_size\t= 0,\n};\n\nstatic float lzma_dict_percent = 0;\n\nstruct lzma_xz_options *lzma_xz_get_options(void)\n{\n\treturn &options;\n}\n\n\nint lzma_xz_options(char *argv[], int argc, int lzmaver)\n{\n\tconst char *comp_name = lzmaver_str[lzmaver];\n\t\n\tif(strcmp(argv[0], \"-Xpreset\") == 0) {\n\t\tint preset;\n\t\t\n\t\tif(argc < 2) {\n\t\t\tfprintf(stderr, \"%s: -Xpreset missing preset\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\t\n\t\tpreset = atoi(argv[1]);\n\t\t\n\t\tif (preset < 0 || preset > 9) {\n\t\t\tfprintf(stderr, \"%s: -Xpreset invalid value\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\toptions.preset = preset;\n\t\treturn 1;\n\t} else if(strcmp(argv[0], \"-Xe\") == 0) {\n\t\toptions.extreme = 1;\n\t\treturn 0;\n\t} else if(strcmp(argv[0], \"-Xlc\") == 0) {\n\t\tint lc;\n\t\t\n\t\tif(argc < 2) {\n\t\t\tfprintf(stderr, \"%s: -Xlc missing lc\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\t\n\t\tlc = atoi(argv[1]);\n\t\t\n\t\tif (lc < LZMA_OPT_LC_MIN || lc > LZMA_OPT_LC_MAX) {\n\t\t\tfprintf(stderr, \"%s: -Xlc invalid value\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\toptions.lc = lc;\n\t\treturn 1;\n\t} else if(strcmp(argv[0], \"-Xlp\") == 0) {\n\t\tint lp;\n\t\t\n\t\tif(argc < 2) {\n\t\t\tfprintf(stderr, \"%s: -Xlp missing lp\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\t\n\t\tlp = atoi(argv[1]);\n\t\t\n\t\tif (lp < LZMA_OPT_LP_MIN || lp > LZMA_OPT_LP_MAX) {\n\t\t\tfprintf(stderr, \"%s: -Xlp invalid value\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\toptions.lp = lp;\n\t\treturn 1;\n\t} else if(strcmp(argv[0], \"-Xpb\") == 0) {\n\t\tint pb;\n\t\t\n\t\tif(argc < 2) {\n\t\t\tfprintf(stderr, \"%s: -Xpb missing pb\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\t\n\t\tpb = atoi(argv[1]);\n\t\t\n\t\tif (pb < LZMA_OPT_PB_MIN || pb > LZMA_OPT_PB_MAX) {\n\t\t\tfprintf(stderr, \"%s: -Xbp invalid value\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\toptions.pb = pb;\n\t\treturn 1;\t\n\t} else if(strcmp(argv[0], \"-Xfb\") == 0) {\n\t\tint fb;\n\t\t\n\t\tif(argc < 2) {\n\t\t\tfprintf(stderr, \"%s: -Xfb missing fb\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\t\n\t\tfb = atoi(argv[1]);\n\t\t\n\t\tif (fb < LZMA_OPT_FB_MIN || fb > LZMA_OPT_FB_MAX) {\n\t\t\tfprintf(stderr, \"%s: -Xfb invalid value\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\t\toptions.fb = fb;\n\t\treturn 1;\n\t} else if(strcmp(argv[0], \"-Xdict-size\") == 0) {\n\t\tchar *b;\n\t\tfloat size;\n\n\t\tif(argc < 2) {\n\t\t\tfprintf(stderr, \"%s: -Xdict-size missing dict-size\\n\", comp_name);\n\t\t\tgoto failed;\n\t\t}\n\n\t\tsize = strtof(argv[1], &b);\n\t\tif(*b == '%') {\n\t\t\tif(size <= 0 || size > 100) {\n\t\t\t\tfprintf(stderr, \"%s: -Xdict-size percentage \"\n\t\t\t\t\t\"should be 0 < dict-size <= 100\\n\", comp_name);\n\t\t\t\tgoto failed;\n\t\t\t}\n\n\t\t\tlzma_dict_percent = size;\n\t\t\toptions.dict_size = 0;\n\t\t} else {\n\t\t\tif((float) ((int) size) != size) {\n\t\t\t\tfprintf(stderr, \"%s: -Xdict-size can't be \"\n\t\t\t\t\t\"fractional unless a percentage of the\"\n\t\t\t\t\t\" block size\\n\", comp_name);\n\t\t\t\tgoto failed;\n\t\t\t}\n\n\t\t\tlzma_dict_percent = 0;\n\t\t\toptions.dict_size = (int) size;\n\n\t\t\tif(*b == 'k' || *b == 'K')\n\t\t\t\toptions.dict_size *= 1024;\n\t\t\telse if(*b == 'm' || *b == 'M')\n\t\t\t\toptions.dict_size *= 1024 * 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tfprintf(stderr, \"%s: -Xdict-size invalid \"\n\t\t\t\t\t\"dict-size\\n\", comp_name);\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t}\n\n\t\treturn 1;\n\t}\n\t\n\treturn -1;\n\t\nfailed:\n\treturn -2;\n\n}\n\nint lzma_xz_options_post(int block_size, int lzmaver)\n{\n\tconst char *comp_name = lzmaver_str[lzmaver];\n\t/*\n\t * if -Xdict-size has been specified use this to compute the datablock\n\t * dictionary size\n\t */\n\tif(options.dict_size || lzma_dict_percent) {\n\t\tint dict_size_min = (lzmaver == 1 ? 4096 : 8192);\n\t\tint n;\n\n\t\tif(options.dict_size) {\n\t\t\tif(options.dict_size > block_size) {\n\t\t\t\tfprintf(stderr, \"%s: -Xdict-size is larger than\"\n\t\t\t\t\" block_size\\n\", comp_name);\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t} else\n\t\t\toptions.dict_size = block_size * lzma_dict_percent / 100;\n\n\t\tif(options.dict_size < dict_size_min) {\n\t\t\tfprintf(stderr, \"%s: -Xdict-size should be %i bytes \"\n\t\t\t\t\"or larger\\n\", comp_name, dict_size_min);\n\t\t\tgoto failed;\n\t\t}\n\n\t\t/*\n\t\t * dictionary_size must be storable in xz header as either\n\t\t * 2^n or as  2^n+2^(n+1)\n\t \t*/\n\t\tn = ffs(options.dict_size) - 1;\n\t\tif(options.dict_size != (1 << n) &&\n\t\t\t\toptions.dict_size != ((1 << n) + (1 << (n + 1)))) {\n\t\t\tfprintf(stderr, \"%s: -Xdict-size is an unsupported \"\n\t\t\t\t\"value, dict-size must be storable in %s \"\n\t\t\t\t\"header\\n\", comp_name, comp_name);\n\t\t\tfprintf(stderr, \"as either 2^n or as 2^n+2^(n+1).  \"\n\t\t\t\t\"Example dict-sizes are 75%%, 50%%, 37.5%%, \"\n\t\t\t\t\"25%%,\\n\");\n\t\t\tfprintf(stderr, \"or 32K, 16K, 8K etc.\\n\");\n\t\t\tgoto failed;\n\t\t}\n\n\t} else\n\t\t/* No -Xdict-size specified, use defaults */\n\t\toptions.dict_size = block_size;\n\n\treturn 0;\n\nfailed:\n\treturn -1;\n}\n\nstatic struct lzma_opts lzma_comp_opts;\n\nvoid *lzma_xz_dump_options(int block_size, int *size, int flags)\n{\n\t/* No need to store default options */\n\tif (options.preset == 6 &&\n\t\t\toptions.extreme == 0 &&\n\t\t\toptions.lc == LZMA_OPT_LC_DEFAULT &&\n\t\t\toptions.lp == LZMA_OPT_LC_DEFAULT &&\n\t\t\toptions.pb == LZMA_OPT_PB_DEFAULT &&\n\t\t\toptions.fb == 0 &&\n\t\t\toptions.dict_size == block_size &&\n\t\t\tflags == 0)\n\t\treturn NULL;\n\t\n\t*size = sizeof(struct lzma_opts);\n\n\tlzma_comp_opts.flags |= flags;\n\t\n\tif (options.extreme)\n\t\tlzma_comp_opts.flags |= LZMA_OPT_EXTREME;\n\t\n\tlzma_comp_opts.flags |= ((options.preset << LZMA_OPT_PRE_OFF) & LZMA_OPT_PRE_MASK);\n\t\n\tlzma_comp_opts.bit_opts = \n\t\t\t((options.lc << LZMA_OPT_LC_OFF) & LZMA_OPT_LC_MASK) |\n\t\t\t((options.lp << LZMA_OPT_LP_OFF) & LZMA_OPT_LP_MASK) |\n\t\t\t((options.pb << LZMA_OPT_PB_OFF) & LZMA_OPT_PB_MASK);\n\tlzma_comp_opts.fb = options.fb;\n\tlzma_comp_opts.dict_size = options.dict_size;\n\t\n\tSQUASHFS_INSWAP_LZMA_COMP_OPTS(&lzma_comp_opts);\n\t\n\treturn &lzma_comp_opts;\n}\n\nint lzma_xz_extract_options(int block_size, void *buffer, int size, int lzmaver)\n{\n\tif (size == 0) {\n\t\t/* default options */\n\t\toptions.preset = 6;\n\t\toptions.extreme = 0;\n\t\toptions.lc = LZMA_OPT_LC_DEFAULT;\n\t\toptions.lp = LZMA_OPT_LC_DEFAULT;\n\t\toptions.pb = LZMA_OPT_PB_DEFAULT;\n\t\toptions.fb = LZMA_OPT_FB_DEFAULT;\n\t\toptions.dict_size = block_size;\n\t\toptions.flags = 0;\n\t} else {\n\t\tstruct lzma_opts *comp_opts = buffer;\n\t\tint n;\n\t\t\n\t\tif (size != sizeof(struct lzma_opts))\n\t\t\tgoto failed;\n\t\t\n\t\tSQUASHFS_INSWAP_LZMA_COMP_OPTS(comp_opts);\n\t\t\n\t\toptions.flags = comp_opts->flags & LZMA_OPT_FLT_MASK;\n\t\toptions.preset  = (comp_opts->flags & LZMA_OPT_PRE_MASK) >> LZMA_OPT_PRE_OFF;\n\t\toptions.extreme = !!(comp_opts->flags & LZMA_OPT_EXTREME);\n\n\t\toptions.lc = (comp_opts->bit_opts & LZMA_OPT_LC_MASK) >> LZMA_OPT_LC_OFF;\n\t\toptions.lp = (comp_opts->bit_opts & LZMA_OPT_LP_MASK) >> LZMA_OPT_LP_OFF;\n\t\toptions.pb = (comp_opts->bit_opts & LZMA_OPT_PB_MASK) >> LZMA_OPT_PB_OFF;\n\t\toptions.fb = comp_opts->fb;\n\t\toptions.dict_size = comp_opts->dict_size;\n\t\t\n\t\t/* check that the LZMA bit options are in range */\n\t\tif (options.lc < LZMA_OPT_LC_MIN || options.lc > LZMA_OPT_LC_MAX ||\n\t\t\toptions.lp < LZMA_OPT_LP_MIN || options.lp > LZMA_OPT_LP_MAX ||\n\t\t\toptions.pb < LZMA_OPT_PB_MIN || options.pb > LZMA_OPT_PB_MAX ||\n\t\t\toptions.fb < LZMA_OPT_FB_MIN || options.fb > LZMA_OPT_FB_MAX)\n\t\t\tgoto failed;\n\n\t\t/*\n\t\t * check that the dictionary size seems correct - the dictionary\n\t\t * size should 2^n or 2^n+2^(n+1)\n\t\t */\n\t\tn = ffs(options.dict_size) - 1;\n\t\tif(options.dict_size != (1 << n) &&\n\t\t\t\toptions.dict_size != ((1 << n) + (1 << (n + 1))))\n\t\t\tgoto failed;\n\t\t\n\t}\n\t\n\treturn 0;\n\nfailed:\n\tfprintf(stderr, \"%s: error reading stored compressor options from \"\n\t\t\"filesystem!\\n\", lzmaver_str[lzmaver]);\n\treturn -1;\t\n}\n\nvoid lzma_xz_usage(int lzmaver)\n{\n\tfprintf(stderr, \"\\t  -Xpreset <preset>\\n\");\n\tfprintf(stderr, \"\\t\\tcompression preset (0-9, default 6)\\n\");\n\tfprintf(stderr, \"\\t  -Xe\\n\");\n\tfprintf(stderr, \"\\t\\tTry to improve compression ratio by using more \");\n\tfprintf(stderr, \"CPU time.\\n\");\n\tfprintf(stderr, \"\\t  -Xlc <lc>\\n\");\n\tfprintf(stderr, \"\\t\\tNumber of literal context bits (0-4, default 3)\\n\");\n\tfprintf(stderr, \"\\t  -Xlp <lp>\\n\");\n\tfprintf(stderr, \"\\t\\tNumber of literal position bits (0-4, default 0)\\n\");\n\tfprintf(stderr, \"\\t  -Xpb <pb>\\n\");\n\tfprintf(stderr, \"\\t\\tNumber of position bits (0-4, default 2)\\n\");\n\tfprintf(stderr, \"\\t  -Xnice <nice>\\n\");\n\tfprintf(stderr, \"\\t\\tNice length of a match (5-273, default 64)\\n\");\n\tfprintf(stderr, \"\\t  -Xdict-size <dict-size>\\n\");\n\tfprintf(stderr, \"\\t\\tUse <dict-size> as the %s dictionary size.  The\",\n\t\t\tlzmaver == LZMA_OPT_LZMA ? \"LZMA\" : \"XZ\");\n\tfprintf(stderr, \" dictionary size\\n\\t\\tcan be specified as a\");\n\tfprintf(stderr, \" percentage of the block size, or as an\\n\\t\\t\");\n\tfprintf(stderr, \"absolute value.  The dictionary size must be less\");\n\tfprintf(stderr, \" than or equal\\n\\t\\tto the block size and %d bytes\", \n\t\t\tlzmaver == LZMA_OPT_LZMA ? 4096 : 8192);\n\tfprintf(stderr, \" or larger.  It must also be\\n\\t\\tstorable in the lzma\");\n\tfprintf(stderr, \" header as either 2^n or as 2^n+2^(n+1).\\n\\t\\t\");\n\tfprintf(stderr, \"Example dict-sizes are 75%%, 50%%, 37.5%%, 25%%, or\");\n\tfprintf(stderr, \" 32K, 16K, 8K\\n\\t\\tetc.\\n\");\n\t\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/lzma_xz_options.h",
    "content": "#ifndef LZMA_XZ_OPTIONS_H\n#define LZMA_XZ_OPTIONS_H\n/*\n * Copyright (c) 2011\n * Jonas Gorski <jonas.gorski@gmail.com>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * lzma_options.h\n */\n\n#include <stdint.h>\n\n#ifndef linux\n#ifdef __FreeBSD__\n#include <machine/endian.h>\n#endif\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n\n\nstruct lzma_opts {\n\tuint32_t flags;\n#define LZMA_OPT_FLT_MASK\t0xffff\n#define LZMA_OPT_PRE_OFF\t16\n#define LZMA_OPT_PRE_MASK\t(0xf << LZMA_OPT_PRE_OFF)\n#define LZMA_OPT_EXTREME\t20\t\n\tuint16_t bit_opts;\n#define LZMA_OPT_LC_OFF\t\t0\n#define LZMA_OPT_LC_MASK\t(0x7 << LZMA_OPT_LC_OFF)\n#define LZMA_OPT_LP_OFF\t\t3\n#define LZMA_OPT_LP_MASK\t(0x7 << LZMA_OPT_LP_OFF)\n#define LZMA_OPT_PB_OFF\t\t6\n#define LZMA_OPT_PB_MASK\t(0x7 << LZMA_OPT_PB_OFF)\n\tuint16_t fb;\n\tuint32_t dict_size;\n};\n\n#if __BYTE_ORDER == __BIG_ENDIAN\nextern unsigned int inswap_le32(unsigned int);\n\n#define SQUASHFS_INSWAP_LZMA_COMP_OPTS(s) { \\\n\t(s)->flags = inswap_le32((s)->flags); \\\n\t(s)->bit_opts = inswap_le16((s)->bit_opts); \\\n\t(s)->fb = inswap_le16((s)->fb); \\\n\t(s)->dict_size = inswap_le32((s)->dict_size); \\\n}\n#else\n#define SQUASHFS_INSWAP_LZMA_COMP_OPTS(s)\n#endif\n\n#define MEMLIMIT (32 * 1024 * 1024)\n\n#define LZMA_OPT_LC_MIN\t\t0\n#define LZMA_OPT_LC_MAX\t\t4\n#define LZMA_OPT_LC_DEFAULT\t3\n\n#define LZMA_OPT_LP_MIN\t\t0\n#define LZMA_OPT_LP_MAX\t\t4\n#define LZMA_OPT_LP_DEFAULT\t0\n\n#define LZMA_OPT_PB_MIN\t\t0\n#define LZMA_OPT_PB_MAX\t\t4\n#define LZMA_OPT_PB_DEFAULT\t2\n\n#define LZMA_OPT_FB_MIN\t\t5\n#define LZMA_OPT_FB_MAX\t\t273\n#define LZMA_OPT_FB_DEFAULT\t64\n\nenum {\n\tLZMA_OPT_LZMA = 1,\n\tLZMA_OPT_XZ\n};\n\nstruct lzma_xz_options {\n\tint preset;\n\tint extreme;\n\tint lc;\n\tint lp;\n\tint pb;\n\tint fb;\n\tint dict_size;\n\tint flags;\n};\n\nstruct lzma_xz_options *lzma_xz_get_options(void);\n\nint lzma_xz_options(char *argv[], int argc, int lzmaver);\n\nint lzma_xz_options_post(int block_size, int lzmaver);\n\nvoid *lzma_xz_dump_options(int block_size, int *size, int flags);\n\nint lzma_xz_extract_options(int block_size, void *buffer, int size, int lzmaver);\n\nvoid lzma_xz_usage(int lzmaver);\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/lzma_xz_wrapper.c",
    "content": "/*\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * lzma_xz_wrapper.c\n *\n * Support for LZMA1 compression using XZ Utils liblzma http://tukaani.org/xz/\n */\n\n#include <stdio.h>\n#include <string.h>\n#include <lzma.h>\n\n#include \"squashfs_fs.h\"\n#include \"compressor.h\"\n#include \"lzma_xz_options.h\"\n\n#define LZMA_PROPS_SIZE 5\n#define LZMA_UNCOMP_SIZE 8\n#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + LZMA_UNCOMP_SIZE)\n\n#define LZMA_OPTIONS 5\n#define MEMLIMIT (32 * 1024 * 1024)\n\nstatic int lzma_compress(void *dummy, void *dest, void *src,  int size,\n\tint block_size, int *error)\n{\n\tuint32_t preset;\n\tunsigned char *d = (unsigned char *) dest;\n\tstruct lzma_xz_options *opts = lzma_xz_get_options();\n\n\tlzma_options_lzma opt;\n\tlzma_stream strm = LZMA_STREAM_INIT;\n\tint res;\n\n\tpreset = opts->preset;\n\n\tif (opts->extreme)\n\t\tpreset |= LZMA_PRESET_EXTREME;\n\n\tlzma_lzma_preset(&opt, opts->preset);\n\topt.lc = opts->lc;\n\topt.lp = opts->lp;\n\topt.pb = opts->pb;\n\tif (opts->fb)\n\t\topt.nice_len = opts->fb;\n\n\topt.dict_size = opts->dict_size;\n\n\tres = lzma_alone_encoder(&strm, &opt);\n\tif(res != LZMA_OK) {\n\t\tlzma_end(&strm);\n\t\tgoto failed;\n\t}\n\n\tstrm.next_out = dest;\n\tstrm.avail_out = block_size;\n\tstrm.next_in = src;\n\tstrm.avail_in = size;\n\n\tres = lzma_code(&strm, LZMA_FINISH);\n\tlzma_end(&strm);\n\n\tif(res == LZMA_STREAM_END) {\n\t\t/*\n\t \t * Fill in the 8 byte little endian uncompressed size field in\n\t\t * the LZMA header.  8 bytes is excessively large for squashfs\n\t\t * but this is the standard LZMA header and which is expected by\n\t\t * the kernel code\n\t \t */\n\n\t\td[LZMA_PROPS_SIZE] = size & 255;\n\t\td[LZMA_PROPS_SIZE + 1] = (size >> 8) & 255;\n\t\td[LZMA_PROPS_SIZE + 2] = (size >> 16) & 255;\n\t\td[LZMA_PROPS_SIZE + 3] = (size >> 24) & 255;\n\t\td[LZMA_PROPS_SIZE + 4] = 0;\n\t\td[LZMA_PROPS_SIZE + 5] = 0;\n\t\td[LZMA_PROPS_SIZE + 6] = 0;\n\t\td[LZMA_PROPS_SIZE + 7] = 0;\n\n\t\treturn (int) strm.total_out;\n\t}\n\n\tif(res == LZMA_OK)\n\t\t/*\n\t \t * Output buffer overflow.  Return out of buffer space\n\t \t */\n\t\treturn 0;\n\nfailed:\n\t/*\n\t * All other errors return failure, with the compressor\n\t * specific error code in *error\n\t */\n\t*error = res;\n\treturn -1;\n}\n\n\nstatic int lzma_uncompress(void *dest, void *src, int size, int block_size,\n\tint *error)\n{\n\tlzma_stream strm = LZMA_STREAM_INIT;\n\tint uncompressed_size = 0, res;\n\tunsigned char lzma_header[LZMA_HEADER_SIZE];\n\n\tres = lzma_alone_decoder(&strm, MEMLIMIT);\n\tif(res != LZMA_OK) {\n\t\tlzma_end(&strm);\n\t\tgoto failed;\n\t}\n\n\tmemcpy(lzma_header, src, LZMA_HEADER_SIZE);\n\tuncompressed_size = lzma_header[LZMA_PROPS_SIZE] |\n\t\t(lzma_header[LZMA_PROPS_SIZE + 1] << 8) |\n\t\t(lzma_header[LZMA_PROPS_SIZE + 2] << 16) |\n\t\t(lzma_header[LZMA_PROPS_SIZE + 3] << 24);\n\tmemset(lzma_header + LZMA_PROPS_SIZE, 255, LZMA_UNCOMP_SIZE);\n\n\tstrm.next_out = dest;\n\tstrm.avail_out = block_size;\n\tstrm.next_in = lzma_header;\n\tstrm.avail_in = LZMA_HEADER_SIZE;\n\n\tres = lzma_code(&strm, LZMA_RUN);\n\n\tif(res != LZMA_OK || strm.avail_in != 0) {\n\t\tlzma_end(&strm);\n\t\tgoto failed;\n\t}\n\n\tstrm.next_in = src + LZMA_HEADER_SIZE;\n\tstrm.avail_in = size - LZMA_HEADER_SIZE;\n\n\tres = lzma_code(&strm, LZMA_FINISH);\n\tlzma_end(&strm);\n\n\tif(res == LZMA_STREAM_END || (res == LZMA_OK &&\n\t\tstrm.total_out >= uncompressed_size && strm.avail_in == 0))\n\t\treturn uncompressed_size;\n\nfailed:\n\t*error = res;\n\treturn -1;\n}\n\nstatic int lzma_options(char *argv[], int argc)\n{\n\treturn lzma_xz_options(argv, argc, LZMA_OPT_LZMA);\n}\n\n\nstatic int lzma_options_post(int block_size)\n{\n\treturn lzma_xz_options_post(block_size, LZMA_OPT_LZMA);\n}\n\n\nstatic void *lzma_dump_options(int block_size, int *size)\n{\n\treturn lzma_xz_dump_options(block_size, size, 0);\n}\n\n\nstatic int lzma_extract_options(int block_size, void *buffer, int size)\n{\n\treturn lzma_xz_extract_options(block_size, buffer, size, LZMA_OPT_LZMA);\n}\n\n\nvoid lzma_usage()\n{\n\tlzma_xz_usage(LZMA_OPT_LZMA);\n}\n\n\nstruct compressor lzma_comp_ops = {\n\t.init = NULL,\n\t.compress = lzma_compress,\n\t.uncompress = lzma_uncompress,\n\t.options = lzma_options,\n\t.options_post = lzma_options_post,\n\t.dump_options = lzma_dump_options,\n\t.extract_options = lzma_extract_options,\n\t.usage = lzma_usage,\n\t.id = LZMA_COMPRESSION,\n\t.name = \"lzma\",\n\t.supported = 1\n};\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/lzo_wrapper.c",
    "content": "/*\n * Copyright (c) 2010 LG Electronics\n * Chan Jeong <chan.jeong@lge.com>\n *\n * All modifications Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * lzo_wrapper.c\n */\n\n#include <stdlib.h>\n#include <string.h>\n\n#include <lzo/lzoconf.h>\n#include <lzo/lzo1x.h>\n\n#include \"squashfs_fs.h\"\n#include \"compressor.h\"\n\n/* worst-case expansion calculation during compression,\n   see LZO FAQ for more information */\n#define LZO_OUTPUT_BUFFER_SIZE(size)\t(size + (size/16) + 64 + 3)\n\nstruct lzo_stream {\n\tlzo_voidp wrkmem;\n\tlzo_bytep out;\n};\n\n\nstatic int squashfs_lzo_init(void **strm, int block_size, int flags)\n{\n\tstruct lzo_stream *stream;\n\n\tif((stream = *strm = malloc(sizeof(struct lzo_stream))) == NULL)\n\t\tgoto failed;\n\t/* work memory for compression */\n\tif((stream->wrkmem = malloc(LZO1X_999_MEM_COMPRESS)) == NULL)\n\t\tgoto failed2;\n\t/* temporal output buffer */\n\tif((stream->out = malloc(LZO_OUTPUT_BUFFER_SIZE(block_size))) == NULL)\n\t\tgoto failed3;\n\n\treturn 0;\n\nfailed3:\n\tfree(stream->wrkmem);\nfailed2:\n\tfree(stream);\nfailed:\n\treturn -1;\n}\n\n\nstatic int lzo_compress(void *strm, void *d, void *s, int size, int block_size,\n\t\tint *error)\n{\n\tint res;\n\tlzo_uint outlen;\n\tstruct lzo_stream *stream = strm;\n\n\tres = lzo1x_999_compress(s, size, stream->out, &outlen, stream->wrkmem);\n\tif(res != LZO_E_OK)\n\t\tgoto failed;\n\tif(outlen >= size)\n\t\t/*\n\t\t * Output buffer overflow. Return out of buffer space\n\t\t */\n\t\treturn 0;\n\n\t/*\n\t * Success, return the compressed size.\n\t */\n\tmemcpy(d, stream->out, outlen);\n\treturn outlen;\n\nfailed:\n\t/*\n\t * All other errors return failure, with the compressor\n\t * specific error code in *error\n\t */\n\t*error = res;\n\treturn -1;\n}\n\n\nstatic int lzo_uncompress(void *d, void *s, int size, int block_size, int *error)\n{\n\tint res;\n\tlzo_uint bytes = block_size;\n\n\tres = lzo1x_decompress_safe(s, size, d, &bytes, NULL);\n\n\t*error = res;\n\treturn res == LZO_E_OK ? bytes : -1;\n}\n\n\nstruct compressor lzo_comp_ops = {\n\t.init = squashfs_lzo_init,\n\t.compress = lzo_compress,\n\t.uncompress = lzo_uncompress,\n\t.options = NULL,\n\t.usage = NULL,\n\t.id = LZO_COMPRESSION,\n\t.name = \"lzo\",\n\t.supported = 1\n};\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <stddef.h>\n#include <sys/time.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n#include <regex.h>\n#include <fnmatch.h>\n#include <sys/wait.h>\n\n#ifndef linux\n#ifndef __CYGWIN__\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#endif /* __CYGWIN__ */\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#ifdef __CYGWIN__\n#include <sys/termios.h>\n#define FNM_EXTMATCH  (1 << 5)\n#endif\n\n#ifndef FNM_EXTMATCH\n#define FNM_EXTMATCH 0\n#endif\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tprintf(\"\\n\"); \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...) \\\n\t\tdo {\\\n\t\t\t if(!silent)\\\n\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t} while(0)\n\n#define ERROR(s, args...) \\\n\t\tdo {\\\n\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t} while(0)\n\n#define EXIT_MKSQUASHFS() \\\n\t\tdo {\\\n\t\t\tif(restore)\\\n\t\t\t\trestorefs();\\\n\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\tunlink(destination_file);\\\n\t\t\texit(1);\\\n\t\t} while(0)\n\n#define BAD_ERROR(s, args...) \\\n\t\tdo {\\\n\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\tEXIT_MKSQUASHFS();\\\n\t\t} while(0)\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"mksquashfs.h\"\n#include \"sort.h\"\n#include \"pseudo.h\"\n#include \"compressor.h\"\n#include \"xattr.h\"\n\nint delete = FALSE;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint comp_opts = FALSE;\nint no_xattrs = XATTR_DEF, noX = 0;\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0;\nint silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\nint progress_enabled = FALSE;\nint sparse_files = TRUE;\nint old_exclude = TRUE;\nint use_regex = FALSE;\nint first_freelist = TRUE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned int id_count = 0;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0,\n\tsock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tstruct squashfs_dir_index\tindex;\n\tchar\t\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* exclude file handling */\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint old_excluded(char *filename, struct stat *buf);\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nstruct pathnames *paths = NULL;\nstruct pathname *path = NULL;\nstruct pathname *stickypath = NULL;\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\n\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n\n#define FRAG_SIZE 32768\n#define FRAG_INDEX (1LL << 32)\n\nstruct squashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\t*name;\n\tstruct inode_info\tinode;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* flag if we're restoring existing filesystem */\nint restoring = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is\n * cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache, *sdirectory_compressed;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, sdirectory_compressed_bytes,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* recovery file for abnormal exit on appending */\nchar recovery_file[1024] = \"\";\nint recover = TRUE;\n\n/* struct describing a cache entry passed between threads */\nstruct file_buffer {\n\tstruct cache *cache;\n\tint keep;\n\tlong long file_size;\n\tlong long index;\n\tlong long block;\n\tlong long sequence;\n\tint size;\n\tint c_byte;\n\tint used;\n\tint\tfragment;\n\tint error;\n\tstruct file_buffer *hash_next;\n\tstruct file_buffer *hash_prev;\n\tstruct file_buffer *free_next;\n\tstruct file_buffer *free_prev;\n\tstruct file_buffer *next;\n\tchar data[0];\n};\n\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n\n/* in memory uid tables */\n#define ID_ENTRIES 256\n#define ID_HASH(id) (id & (ID_ENTRIES - 1))\n#define ISA_UID 1\n#define ISA_GID 2\nstruct id {\n\tunsigned int id;\n\tint\tindex;\n\tchar\tflags;\n\tstruct id *next;\n};\nstruct id *id_hash_table[ID_ENTRIES];\nstruct id *id_table[SQUASHFS_IDS], *sid_table[SQUASHFS_IDS];\nunsigned int uid_count = 0, guid_count = 0;\nunsigned int sid_count = 0, suid_count = 0, sguid_count = 0;\n\nstruct cache *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate,\n\t*to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread, progress_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\npthread_mutex_t progress_mutex;\npthread_cond_t progress_wait;\nint rotate = 0;\nstruct pseudo *pseudo = NULL;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 64\nint writer_buffer_size;\n\n/* compression operations */\nstatic struct compressor *comp;\nint compressor_opts_parsed = 0;\nvoid *stream = NULL;\n\n/* xattr stats */\nunsigned int xattr_bytes = 0, total_xattr_bytes = 0;\n\nchar *read_from_disk(long long start, unsigned int avail_bytes);\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type);\nextern struct compressor  *read_super(int fd, struct squashfs_super_block *sBlk,\n\tchar *source);\nextern long long read_filesystem(char *root_name, int fd,\n\tstruct squashfs_super_block *sBlk, char **cinode_table, char **data_cache,\n\tchar **cdirectory_table, char **directory_data_cache,\n\tunsigned int *last_directory_block, unsigned int *inode_dir_offset,\n\tunsigned int *inode_dir_file_size, unsigned int *root_inode_size,\n\tunsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\tlong long *uncompressed_file, unsigned int *uncompressed_inode,\n\tunsigned int *uncompressed_directory,\n\tunsigned int *inode_dir_inode_number,\n\tunsigned int *inode_dir_parent_inode,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\tstruct squashfs_fragment_entry **fragment_table,\n\tsquashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *,\n\tchar *, struct dir_info *));\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo);\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info);\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag);\nextern int generate_file_priorities(struct dir_info *dir, int priority,\n\tstruct stat *buf);\nextern struct priority_entry *priority_list[65536];\nvoid progress_bar(long long current, long long max, int columns);\nlong long generic_write_table(int, void *, int, void *, int);\nvoid restorefs();\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\tgoto failed;\n\n\tqueue->data = malloc(sizeof(void *) * (size + 1));\n\tif(queue->data == NULL) {\n\t\tfree(queue);\n\t\tgoto failed;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in queue_init\\n\");\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tstruct file_buffer *free_list;\n\tstruct file_buffer *hash_table[65536];\n};\n\n\n#define INSERT_LIST(NAME, TYPE) \\\nvoid insert_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(*list) { \\\n\t\tentry->NAME##_next = *list; \\\n\t\tentry->NAME##_prev = (*list)->NAME##_prev; \\\n\t\t(*list)->NAME##_prev->NAME##_next = entry; \\\n\t\t(*list)->NAME##_prev = entry; \\\n\t} else { \\\n\t\t*list = entry; \\\n\t\tentry->NAME##_prev = entry->NAME##_next = entry; \\\n\t} \\\n}\n\n\n#define REMOVE_LIST(NAME, TYPE) \\\nvoid remove_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(entry->NAME##_prev == entry && entry->NAME##_next == entry) { \\\n\t\t/* only this entry in the list */ \\\n\t\t*list = NULL; \\\n\t} else if(entry->NAME##_prev != NULL && entry->NAME##_next != NULL) { \\\n\t\t/* more than one entry in the list */ \\\n\t\tentry->NAME##_next->NAME##_prev = entry->NAME##_prev; \\\n\t\tentry->NAME##_prev->NAME##_next = entry->NAME##_next; \\\n\t\tif(*list == entry) \\\n\t\t\t*list = entry->NAME##_next; \\\n\t} \\\n\tentry->NAME##_prev = entry->NAME##_next = NULL; \\\n}\n\n\n#define CALCULATE_HASH(start)\t(start & 0xffff) \\\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tint hash = CALCULATE_HASH(entry->index);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->index)] =\n\t\t\tentry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nINSERT_LIST(free, struct file_buffer)\n\n/* Called with the cache mutex held */\nREMOVE_LIST(free, struct file_buffer)\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\tBAD_ERROR(\"Out of memory in cache_init\\n\");\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct file_buffer *) * 65536);\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\n\treturn cache;\n}\n\n\nstruct file_buffer *cache_lookup(struct cache *cache, long long index)\n{\n\t/* Lookup block in the cache, if found return with usage count\n \t * incremented, if not found return NULL */\n\tint hash = CALCULATE_HASH(index);\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->index == index)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/* found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(&cache->free_list, entry);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n}\n\n\nstruct file_buffer *cache_get(struct cache *cache, long long index, int keep)\n{\n\t/* Get a free block out of the cache indexed on index. */\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\twhile(1) {\n\t\t/* first try to get a block from the free list */\n\t\tif(first_freelist && cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t} else if(cache->count < cache->max_buffers) {\n\t\t\t/* next try to allocate new block */\n\t\t\tentry = malloc(sizeof(struct file_buffer) +\n\t\t\t\tcache->buffer_size);\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t\tbreak;\n\t\t} else if(!first_freelist && cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t} else\n\t\t\t/* wait for a block */\n\t\t\tpthread_cond_wait(&cache->wait_for_free, &cache->mutex);\n\t}\n\n\t/* initialise block and if a keep block insert into the hash table */\n\tentry->used = 1;\n\tentry->error = FALSE;\n\tentry->keep = keep;\n\tif(keep) {\n\t\tentry->index = index;\n\t\tinsert_hash_table(cache, entry);\n\t}\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\tBAD_ERROR(\"Out of memory in cache_get\\n\");\n}\n\n\nvoid cache_rehash(struct file_buffer *entry, long long index)\n{\n\tstruct cache *cache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\tif(entry->keep)\n\t\tremove_hash_table(cache, entry);\n\tentry->keep = TRUE;\n\tentry->index = index;\n\tinsert_hash_table(cache, entry);\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\nvoid cache_block_put(struct file_buffer *entry)\n{\n\tstruct cache *cache;\n\n\t/* finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and if a keep block put onto the free list.  As keep\n \t * blocks remain accessible via the hash table they can be found\n \t * getting a new lease of life before they are reused. */\n\n\tif(entry == NULL)\n\t\treturn;\n\n\tcache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tif(entry->keep)\n\t\t\tinsert_free_list(&cache->free_list, entry);\n\t\telse {\n\t\t\tfree(entry);\n\t\t\tcache->count --;\n\t\t}\n\n\t\t/* One or more threads may be waiting on this block */\n\t\tpthread_cond_signal(&cache->wait_for_free);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) \\\n\t\t\t+ (((char *)A) - data_cache)))\n\n\ninline void inc_progress_bar()\n{\n\tcur_uncompressed ++;\n}\n\n\ninline void update_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tif(restoring++)\n\t\t/*\n\t\t * Recursive failure when trying to restore filesystem!\n\t\t * Nothing to do except to exit, otherwise we'll just appear\n\t\t * to hang.  The user should be able to restore from the\n\t\t * recovery file (which is why it was added, in case of\n\t\t * catastrophic failure in Mksquashfs)\n\t\t */\n\t\texit(1);\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tif(thread[i])\n\t\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache,\n\t\tsdirectory_cache_bytes);\n\tdirectory_cache_bytes = sdirectory_cache_bytes;\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n \tmemcpy(directory_table + directory_bytes, sdirectory_compressed,\n\t\tsdirectory_compressed_bytes);\n \tdirectory_bytes += sdirectory_compressed_bytes;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tid_count = sid_count;\n\trestore_xattrs();\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, &thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n#ifndef __CYGWIN__\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n#else\n\tcolumns = 80;\n#endif\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nint mangle2(void *strm, char *d, char *s, int size,\n\tint block_size, int uncompressed, int data_block)\n{\n\tint error, c_byte = 0;\n\n\tif(!uncompressed) {\n\t\tc_byte = compressor_compress(comp, strm, d, s, size, block_size,\n\t\t\t &error);\n\t\tif(c_byte == -1)\n\t\t\tBAD_ERROR(\"mangle2:: %s compress failed with error \"\n\t\t\t\t\"code %d\\n\", comp->name, error);\n\t}\n\n\tif(c_byte == 0 || c_byte >= size) {\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK :\n\t\t\tSQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn c_byte;\n}\n\n\nint mangle(char *d, char *s, int size, int block_size,\n\tint uncompressed, int data_block)\n{\n\treturn mangle2(stream, d, s, size, block_size, uncompressed,\n\t\tdata_block);\n}\n\n\nvoid *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tvoid *it = realloc(inode_table, inode_size +\n\t\t\t\t(SQUASHFS_METADATA_SIZE << 1) + 2);\n\t\t\tif(it == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_table = it;\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET,\n\t\t\tdata_cache, SQUASHFS_METADATA_SIZE,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, inode_table + inode_bytes, 1);\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemmove(data_cache, data_cache + SQUASHFS_METADATA_SIZE,\n\t\t\tcache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ?\n\t\t\t\t((req_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : req_size -\n\t\t\t\tdata_space;\n\n\t\t\tvoid *dc = realloc(data_cache, cache_size +\n\t\t\t\trealloc_size);\n\t\t\tif(dc == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t\t\tdata_cache = dc;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn data_cache + cache_bytes - req_size;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nint read_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = read(fd, buff + count, bytes - count);\n\t\tif(res < 1) {\n\t\t\tif(res == 0)\n\t\t\t\tgoto bytes_read;\n\t\t\telse if(errno != EINTR) {\n\t\t\t\tERROR(\"Read failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t} else\n\t\t\t\tres = 0;\n\t\t}\n\t}\n\nbytes_read:\n\treturn count;\n}\n\n\nint read_fs_bytes(int fd, long long byte, int bytes, void *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_fs_bytes: reading from position 0x%llx, bytes %d\\n\",\n\t\tbyte, bytes);\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\t\tgoto failed;\n\t}\n\n\tif(read_bytes(fd, buff, bytes) < bytes) {\n\t\tERROR(\"Read on destination failed\\n\");\n\t\tgoto failed;\n\t}\n\n\tpthread_mutex_unlock(&pos_mutex);\n\treturn 1;\n\nfailed:\n\tpthread_mutex_unlock(&pos_mutex);\n\treturn 0;\n}\n\n\nint write_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = write(fd, buff + count, bytes - count);\n\t\tif(res == -1) {\n\t\t\tif(errno != EINTR) {\n\t\t\t\tERROR(\"Write failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nvoid write_destination(int fd, long long byte, int bytes, void *buff)\n{\n\toff_t off = byte;\n\n\tif(!restoring)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(fd, buff, bytes) == -1)\n\t\tBAD_ERROR(\"Write on destination failed\\n\");\n\t\n\tif(!restoring)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tvoid *it = realloc(inode_table, inode_size +\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2));\n\t\t\tif(it == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t\tinode_table = it;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET, datap,\n\t\t\tavail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, inode_table + inode_bytes, 1); \n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_destination(fd, bytes, inode_bytes,  inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tvoid *dt = realloc(directory_table,\n\t\t\t\tdirectory_size + ((SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2));\n\t\t\tif(dt == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t\tdirectory_table = dt;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\tBLOCK_OFFSET, directoryp, avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\tdirectory_table + directory_bytes, 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_destination(fd, bytes, directory_bytes, directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_id_table()\n{\n\tunsigned int id_bytes = SQUASHFS_ID_BYTES(id_count);\n\tunsigned int p[id_count];\n\tint i;\n\n\tTRACE(\"write_id_table: ids %d, id_bytes %d\\n\", id_count, id_bytes);\n\tfor(i = 0; i < id_count; i++) {\n\t\tTRACE(\"write_id_table: id index %d, id %d\", i, id_table[i]->id);\n\t\tSQUASHFS_SWAP_INTS(&id_table[i]->id, p + i, 1);\n\t}\n\n\treturn generic_write_table(id_bytes, p, 0, NULL, noI);\n}\n\n\nstruct id *get_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = id_hash_table[hash];\n\n\tfor(; entry; entry = entry->next)\n\t\tif(entry->id == id)\n\t\t\tbreak;\n\n\treturn entry;\n}\n\n\nstruct id *create_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = malloc(sizeof(struct id));\n\tif(entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in create_id\\n\");\n\tentry->id = id;\n\tentry->index = id_count ++;\n\tentry->flags = 0;\n\tentry->next = id_hash_table[hash];\n\tid_hash_table[hash] = entry;\n\tid_table[entry->index] = entry;\n\treturn entry;\n}\n\n\nunsigned int get_uid(unsigned int uid)\n{\n\tstruct id *entry = get_id(uid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of uids!\\n\");\n\t\tentry = create_id(uid);\n\t}\n\n\tif((entry->flags & ISA_UID) == 0) {\n\t\tentry->flags |= ISA_UID;\n\t\tuid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nunsigned int get_guid(unsigned int guid)\n{\n\tstruct id *entry = get_id(guid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of gids!\\n\");\n\t\tentry = create_id(guid);\n\t}\n\n\tif((entry->flags & ISA_GID) == 0) {\n\t\tentry->flags |= ISA_GID;\n\t\tguid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_info *dir_info,\n\tstruct dir_ent *dir_ent, int type, long long byte_size,\n\tlong long start_block, unsigned int offset, unsigned int *block_list,\n\tstruct fragment *fragment, struct directory *dir_in, long long sparse)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tunion squashfs_inode_header inode_header;\n\tstruct squashfs_base_inode_header *base = &inode_header.base;\n\tvoid *inode;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = type == SQUASHFS_DIR_TYPE ?\n\t\tdir_ent->inode->inode_number :\n\t\tdir_ent->inode->inode_number + dir_inode_no;\n\tint xattr = read_xattrs(dir_ent);\n\n\tswitch(type) {\n\tcase SQUASHFS_FILE_TYPE:\n\t\tif(dir_ent->inode->nlink > 1 ||\n\t\t\t\tbyte_size >= (1LL << 32) ||\n\t\t\t\tstart_block >= (1LL << 32) ||\n\t\t\t\tsparse || IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LREG_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_DIR_TYPE:\n\t\tif(dir_info->dir_is_ldir || IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LDIR_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_SYMLINK_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LSYMLINK_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_BLKDEV_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LBLKDEV_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_CHRDEV_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LCHRDEV_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_FIFO_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LFIFO_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_SOCKET_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LSOCKET_TYPE;\n\t\tbreak;\n\t}\n\t\t\t\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((unsigned int) global_uid == -1 ?\n\t\tbuf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((unsigned int) global_gid == -1 ?\n\t\tbuf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tstruct squashfs_reg_inode_header *reg = &inode_header.reg;\n\t\tsize_t off = offsetof(struct squashfs_reg_inode_header, block_list);\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inode);\n\t\tSQUASHFS_SWAP_INTS(block_list, inode + off, offset);\n\t\tTRACE(\"File inode, file_size %lld, start_block 0x%llx, blocks \"\n\t\t\t\"%d, fragment %d, offset %d, size %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset,\n\t\t\tfragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tstruct squashfs_lreg_inode_header *reg = &inode_header.lreg;\n\t\tsize_t off = offsetof(struct squashfs_lreg_inode_header, block_list);\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(sparse && sparse >= byte_size)\n\t\t\tsparse = byte_size - 1;\n\t\treg->sparse = sparse;\n\t\treg->xattr = xattr;\n\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inode);\n\t\tSQUASHFS_SWAP_INTS(block_list, inode + off, offset);\n\t\tTRACE(\"Long file inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"blocks %d, fragment %d, offset %d, size %d, nlink %d\"\n\t\t\t\"\\n\", byte_size, start_block, offset, fragment->index,\n\t\t\tfragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tstruct squashfs_ldir_inode_header *dir = &inode_header.ldir;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\t\tdir->xattr = xattr;\n\n\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = inode + offsetof(struct squashfs_ldir_inode_header, index);\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tp += offsetof(struct squashfs_dir_index, name);\n\t\t\tmemcpy(p, index[i].name, index[i].index.size + 1);\n\t\t\tp += index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %lld, start_block \"\n\t\t\t\"0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tstruct squashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"offset 0x%x, nlink %d\\n\", byte_size, start_block,\n\t\t\toffset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tstruct squashfs_dev_inode_header *dev = &inode_header.dev;\n\t\tunsigned int major = major(buf->st_rdev);\n\t\tunsigned int minor = minor(buf->st_rdev);\n\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", major, filename,\n\t\t\t\tmajor & 0xfff);\n\t\t\tmajor &= 0xfff;\n\t\t}\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", minor, filename,\n\t\t\t\tminor & 0xfffff);\n\t\t\tminor &= 0xfffff;\n\t\t}\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (major << 8) | (minor & 0xff) |\n\t\t\t\t((minor & ~0xff) << 12);\n\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_LCHRDEV_TYPE || type == SQUASHFS_LBLKDEV_TYPE) {\n\t\tstruct squashfs_ldev_inode_header *dev = &inode_header.ldev;\n\t\tunsigned int major = major(buf->st_rdev);\n\t\tunsigned int minor = minor(buf->st_rdev);\n\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", major, filename,\n\t\t\t\tmajor & 0xfff);\n\t\t\tmajor &= 0xfff;\n\t\t}\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", minor, filename,\n\t\t\t\tminor & 0xfffff);\n\t\t\tminor &= 0xfffff;\n\t\t}\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (major << 8) | (minor & 0xff) |\n\t\t\t\t((minor & ~0xff) << 12);\n\t\tdev->xattr = xattr;\n\t\tSQUASHFS_SWAP_LDEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tstruct squashfs_symlink_inode_header *symlink = &inode_header.symlink;\n\t\tint byte;\n\t\tchar buff[65536];\n\t\tsize_t off = offsetof(struct squashfs_symlink_inode_header, symlink);\n\n\t\tbyte = readlink(filename, buff, 65536);\n\t\tif(byte == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty \"\n\t\t\t\t\"symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! \"\n\t\t\t\t\"Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tsymlink->symlink_size = byte;\n\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inode + off, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte,\n\t\t\tnlink);\n\t}\n\telse if(type == SQUASHFS_LSYMLINK_TYPE) {\n\t\tstruct squashfs_symlink_inode_header *symlink = &inode_header.symlink;\n\t\tint byte;\n\t\tchar buff[65536];\n\t\tsize_t off = offsetof(struct squashfs_symlink_inode_header, symlink);\n\n\t\tbyte = readlink(filename, buff, 65536);\n\t\tif(byte == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty \"\n\t\t\t\t\"symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! \"\n\t\t\t\t\"Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte +\n\t\t\t\t\t\tsizeof(unsigned int));\n\t\tsymlink->nlink = nlink;\n\t\tsymlink->symlink_size = byte;\n\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inode + off, buff, byte);\n\t\tSQUASHFS_SWAP_INTS(&xattr, inode + off + byte, 1);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte,\n\t\t\tnlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tstruct squashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type ==\n\t\t\tSQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t}\n\telse if(type == SQUASHFS_LFIFO_TYPE || type == SQUASHFS_LSOCKET_TYPE) {\n\t\tstruct squashfs_lipc_inode_header *ipc = &inode_header.lipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tipc->xattr = xattr;\n\t\tSQUASHFS_SWAP_LIPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type ==\n\t\t\tSQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type,\n\t\tbase->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan3_init_dir(struct directory *dir)\n{\n\tdir->buff = malloc(SQUASHFS_METADATA_SIZE);\n\tif(dir->buff == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name,\n\tint type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tstruct squashfs_dir_entry idir;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size = strlen(name);\n\tsize_t name_off = offsetof(struct squashfs_dir_entry, name);\n\n\tif(size > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\"\n\t\t\t\"\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(struct squashfs_dir_entry) + size +\n\t\t\tsizeof(struct squashfs_dir_header)\n\t\t\t>= dir->buff + dir->size) {\n\t\tbuff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE);\n\t\tif(buff == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\"\n\t\t\t\t\"\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff +\n\t\t\tbuff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block ||\n\t\t\t((dir->entry_count_p != NULL) &&\n\t\t\t((dir->p + sizeof(struct squashfs_dir_entry) + size -\n\t\t\tdir->index_count_p) > SQUASHFS_METADATA_SIZE)) ||\n\t\t\t((long long) inode_number - dir->inode_number) > 32767\n\t\t\t|| ((long long) inode_number - dir->inode_number)\n\t\t\t< -32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tstruct squashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(struct squashfs_dir_entry) + size -\n\t\t\t\t\tdir->index_count_p) >\n\t\t\t\t\tSQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0) {\n\t\t\t\t\tdir->index = realloc(dir->index,\n\t\t\t\t\t\t(dir->i_count + I_COUNT_SIZE) *\n\t\t\t\t\t\tsizeof(struct cached_dir_index));\n\t\t\t\t\tif(dir->index == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in \"\n\t\t\t\t\t\t\t\"directory index table \"\n\t\t\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t\t}\n\t\t\t\tdir->index[dir->i_count].index.index =\n\t\t\t\t\tdir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(struct squashfs_dir_index)\n\t\t\t\t\t+ size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header,\n\t\t\t\tdir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(struct squashfs_dir_header);\n\t}\n\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tSQUASHFS_SWAP_DIR_ENTRY(&idir, dir->p);\n\tstrncpy((char *) dir->p + name_off, name, size);\n\tdir->p += sizeof(struct squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info,\n\tstruct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = directory_cache_size - directory_cache_bytes;\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ?\n\t\t\t((dir_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tvoid *dc = realloc(directory_data_cache,\n\t\t\tdirectory_cache_size + realloc_size);\n\t\tif(dc == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t\tdirectory_data_cache = dc;\n\t}\n\n\tif(dir_size) {\n\t\tstruct squashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header, dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff,\n\t\t\tdir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count &&\n\t\t\t\tdir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block =\n\t\t\t\tdirectory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) <\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tvoid *dt = realloc(directory_table,\n\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2);\n\t\t\tif(dt == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t\tdirectory_table = dt;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\t\tBLOCK_OFFSET, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE,\n\t\t\t\tnoI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\tdirectory_table + directory_bytes, 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemmove(directory_data_cache, directory_data_cache +\n\t\t\tSQUASHFS_METADATA_SIZE, directory_cache_bytes -\n\t\t\tSQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tcreate_inode(inode, dir_info, dir_info->dir_ent, SQUASHFS_DIR_TYPE,\n\t\tdir_size + 3, directory_block, directory_offset, NULL, NULL,\n\t\tdir, 0);\n\n#ifdef SQUASHFS_TRACE\n\t{\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tstruct squashfs_dir_entry idir, *idirp;\n\t\t\tstruct squashfs_dir_header dirh;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((struct squashfs_dir_header *) dirp,\n\t\t\t\t&dirh);\n\t\t\tcount = dirh.count + 1;\n\t\t\tdirp += sizeof(struct squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\",\n\t\t\t\tdirh.start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (struct squashfs_dir_entry *) dirp;\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(idirp, &idir);\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type \"\n\t\t\t\t\t\"%d\\n\", buffer, idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(struct squashfs_dir_entry) + idir.size +\n\t\t\t\t\t1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nstruct file_buffer *get_fragment(struct fragment *fragment)\n{\n\tstruct squashfs_fragment_entry *disk_fragment;\n\tint res, size;\n\tlong long start_block;\n\tstruct file_buffer *buffer, *compressed_buffer;\n\n\tif(fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn NULL;\n\n\tbuffer = cache_lookup(fragment_buffer, fragment->index);\n\tif(buffer)\n\t\treturn buffer;\n\n\tcompressed_buffer = cache_lookup(writer_buffer, fragment->index +\n\t\tFRAG_INDEX);\n\n\tbuffer = cache_get(fragment_buffer, fragment->index, 1);\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\tstart_block = disk_fragment->start_block;\n\tpthread_mutex_unlock(&fragment_mutex);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint error;\n\t\tchar *data;\n\n\t\tif(compressed_buffer)\n\t\t\tdata = compressed_buffer->data;\n\t\telse\n\t\t\tdata = read_from_disk(start_block, size);\n\n\t\tres = compressor_uncompress(comp, buffer->data, data, size,\n\t\t\tblock_size, &error);\n\t\tif(res == -1)\n\t\t\tBAD_ERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t} else if(compressed_buffer)\n\t\tmemcpy(buffer->data, compressed_buffer->data, size);\n\telse {\n\t\tres = read_fs_bytes(fd, start_block, size, buffer->data);\n\t\tif(res == 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tcache_block_put(compressed_buffer);\n\n\treturn buffer;\n}\n\n\nstruct frag_locked {\n\tstruct file_buffer *buffer;\n\tint c_byte;\n\tint fragment;\n\tstruct frag_locked *fragment_prev;\n\tstruct frag_locked *fragment_next;\n};\n\nint fragments_locked = FALSE;\nstruct frag_locked *frag_locked_list = NULL;\n\nINSERT_LIST(fragment, struct frag_locked)\nREMOVE_LIST(fragment, struct frag_locked)\n\nint lock_fragments()\n{\n\tint count;\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragments_locked = TRUE;\n\tcount = fragments_outstanding;\n\tpthread_mutex_unlock(&fragment_mutex);\n\treturn count;\n}\n\n\nvoid unlock_fragments()\n{\n\tstruct frag_locked *entry;\n\tint compressed_size;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(frag_locked_list) {\n\t\tentry = frag_locked_list;\n\t\tremove_fragment_list(&frag_locked_list, entry);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->c_byte);\n\t\tfragment_table[entry->fragment].size = entry->c_byte;\n\t\tfragment_table[entry->fragment].start_block = bytes;\n\t\tentry->buffer->block = bytes;\n\t\tbytes += compressed_size;\n\t\tfragments_outstanding --;\n\t\tqueue_put(to_writer, entry->buffer);\n\t\tTRACE(\"fragment_locked writing fragment %d, compressed size %d\"\n\t\t\t\"\\n\", entry->fragment, compressed_size);\n\t\tfree(entry);\n\t}\n\tfragments_locked = FALSE;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid add_pending_fragment(struct file_buffer *write_buffer, int c_byte,\n\tint fragment)\n{\n\tstruct frag_locked *entry = malloc(sizeof(struct frag_locked));\n\tif(entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in add_pending fragment\\n\");\n\tentry->buffer = write_buffer;\n\tentry->c_byte = c_byte;\n\tentry->fragment = fragment;\n\tentry->fragment_prev = entry->fragment_next = NULL;\n\tpthread_mutex_lock(&fragment_mutex);\n\tinsert_fragment_list(&frag_locked_list, entry);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tvoid *ft = realloc(fragment_table, (fragments +\n\t\t\tFRAG_SIZE) * sizeof(struct squashfs_fragment_entry));\n\t\tif(ft == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t\tfragment_table = ft;\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].unused = 0;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tffrg = malloc(sizeof(struct fragment));\n\tif(ffrg == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = cache_get(fragment_buffer, fragments, 1);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data,\n\t\tfile_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, void *buffer, int length2,\n\tvoid *buffer2, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) /\n\t\tSQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n#ifdef SQUASHFS_TRACE\n\tlong long obytes = bytes;\n\tint olength = length;\n#endif\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + BLOCK_OFFSET, buffer + i *\n\t\t\tSQUASHFS_METADATA_SIZE , avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, cbuffer, 1);\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes,\n\t\t\tcompressed_size);\n\t\twrite_destination(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\ttotal_bytes += avail_bytes;\n\t\tlength -= avail_bytes;\n\t}\n\n\tstart_bytes = bytes;\n\tif(length2) {\n\t\twrite_destination(fd, bytes, length2, buffer2);\n\t\tbytes += length2;\n\t\ttotal_bytes += length2;\n\t}\n\t\t\n\tSQUASHFS_INSWAP_LONG_LONGS(list, meta_blocks);\n\twrite_destination(fd, bytes, sizeof(list), list);\n\tbytes += sizeof(list);\n\ttotal_bytes += sizeof(list);\n\n\tTRACE(\"generic_write_table: total uncompressed %d compressed %lld\\n\",\n\t\tolength, bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tstruct squashfs_fragment_entry p[fragments];\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments,\n\t\tfrag_bytes);\n\tfor(i = 0; i < fragments; i++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block 0x%llx, \"\n\t\t\t\"size %d\\n\", i, fragment_table[i].start_block,\n\t\t\tfragment_table[i].size);\n\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p + i);\n\t}\n\n\treturn generic_write_table(frag_bytes, p, 0, NULL, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tint res;\n\n\tres = read_fs_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\tif(res == 0)\n\t\tEXIT_MKSQUASHFS();\n\n\treturn read_from_file_buffer;\n}\n\n\nchar read_from_file_buffer2[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk2(long long start, unsigned int avail_bytes)\n{\n\tint res;\n\n\tres = read_fs_bytes(fd, start, avail_bytes, read_from_file_buffer2);\n\tif(res == 0)\n\t\tEXIT_MKSQUASHFS();\n\n\treturn read_from_file_buffer2;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l,\n\tunsigned int *blocks)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\tstruct file_buffer *write_buffer;\n\tint i;\n\n\tfor(i = 0; l; i++)  {\n\t\tbytes = SQUASHFS_COMPRESSED_SIZE_BLOCK(blocks[i]);\n\t\tif(bytes == 0) /* sparse block */\n\t\t\tcontinue;\n\t\twrite_buffer = cache_lookup(writer_buffer, start);\n\t\tif(write_buffer) {\n\t\t\tchksum = get_checksum(write_buffer->data, bytes,\n\t\t\t\tchksum);\n\t\t\tcache_block_put(write_buffer);\n\t\t} else\n\t\t\tchksum = get_checksum(read_from_disk(start, bytes),\n\t\t\t\tbytes, chksum);\n\t\tl -= bytes;\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes,\n\tunsigned int *block_listp, int blocks, unsigned int fragment,\n\tint offset, int bytes)\n{\n\tstruct fragment *frg;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset !=\n\t\t\t\tdupl_ptr->fragment->offset || bytes !=\n\t\t\t\tdupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tfrg = malloc(sizeof(struct fragment));\n\tif(frg == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && file_size ==\n\t\t\t\tdupl_ptr->fragment->size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, file_size);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag)\n{\n\tstruct file_info *dupl_ptr = malloc(sizeof(struct file_info));\n\n\tif(dupl_ptr == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes\n\t\t\t\t && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tlong long target_start, dup_start = dupl_ptr->start;\n\t\t\tint block;\n\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks *\n\t\t\t\t\tsizeof(unsigned int)) != 0)\n\t\t\t\tcontinue;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_disk(*start, bytes,\n\t\t\t\t\t*block_list);\n\t\t\t\tfragment_checksum =\n\t\t\t\t\tget_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, frag_bytes);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum ||\n\t\t\t\t\tfragment_checksum !=\n\t\t\t\t\tdupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\ttarget_start = *start;\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t((*block_list)[block]);\n\t\t\t\tstruct file_buffer *target_buffer = NULL;\n\t\t\t\tstruct file_buffer *dup_buffer = NULL;\n\t\t\t\tchar *target_data, *dup_data;\n\t\t\t\tint res;\n\n\t\t\t\tif(size == 0)\n\t\t\t\t\tcontinue;\n\t\t\t\ttarget_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\ttarget_start);\n\t\t\t\tif(target_buffer)\n\t\t\t\t\ttarget_data = target_buffer->data;\n\t\t\t\telse\n\t\t\t\t\ttarget_data =\n\t\t\t\t\t\tread_from_disk(target_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tdup_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\tdup_start);\n\t\t\t\tif(dup_buffer)\n\t\t\t\t\tdup_data = dup_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tdup_data = read_from_disk2(dup_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tres = memcmp(target_data, dup_data, size);\n\t\t\t\tcache_block_put(target_buffer);\n\t\t\t\tcache_block_put(dup_buffer);\n\t\t\t\tif(res != 0)\n\t\t\t\t\tbreak;\n\t\t\t\ttarget_start += size;\n\t\t\t\tdup_start += size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\n\t\t\t\tif(frag_bytes == 0 ||\n\t\t\t\t\t\tmemcmp(file_buffer->data,\n\t\t\t\t\t\tfrag_buffer->data +\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfrag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start \"\n\t\t\t\t\t\t\"0x%llx, size %lld, checksum \"\n\t\t\t\t\t\t\"0x%x, fragment %d, size %d, \"\n\t\t\t\t\t\t\"offset %d, checksum 0x%x\\n\",\n\t\t\t\t\t\tdupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes,\n\t\t\t\t\t\tdupl_ptr->checksum,\n\t\t\t\t\t\tdupl_ptr->fragment->index,\n\t\t\t\t\t\tfrag_bytes,\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment,\n\t\tchecksum, fragment_checksum, checksum_flag);\n}\n\n\nstatic int seq = 0;\nvoid reader_read_process(struct dir_ent *dir_ent)\n{\n\tstruct file_buffer *prev_buffer = NULL, *file_buffer;\n\tint status, res, byte, count = 0;\n\tint file = get_pseudo_file(dir_ent->inode->pseudo_id)->fd;\n\tint child = get_pseudo_file(dir_ent->inode->pseudo_id)->child;\n\tlong long bytes = 0;\n\n\twhile(1) {\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = seq ++;\n\n\t\tbyte = read_bytes(file, file_buffer->data, block_size);\n\t\tif(byte == -1)\n\t\t\tgoto read_err;\n\n\t\tfile_buffer->size = byte;\n\t\tfile_buffer->file_size = -1;\n\t\tfile_buffer->block = count ++;\n\t\tfile_buffer->error = FALSE;\n\t\tfile_buffer->fragment = FALSE;\n\t\tbytes += byte;\n\n\t\tif(byte == 0)\n\t\t\tbreak;\n\n\t\t/*\n\t\t * Update estimated_uncompressed block count.  This is done\n\t\t * on every block rather than waiting for all blocks to be\n\t\t * read incase write_file_process() is running in parallel\n\t\t * with this.  Otherwise cur uncompressed block count may\n\t\t * get ahead of the total uncompressed block count.\n\t\t */ \n\t\testimated_uncompressed ++;\n\n\t\tif(prev_buffer)\n\t\t\tqueue_put(from_reader, prev_buffer);\n\t\tprev_buffer = file_buffer;\n\t}\n\n\t/*\n \t * Update inode file size now that the size of the dynamic pseudo file\n\t * is known.  This is needed for the -info option.\n\t */\n\tdir_ent->inode->buf.st_size = bytes;\n\n\tres = waitpid(child, &status, 0);\n\tif(res == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)\n\t\tgoto read_err;\n\n\tif(prev_buffer == NULL)\n\t\tprev_buffer = file_buffer;\n\telse {\n\t\tcache_block_put(file_buffer);\n\t\tseq --;\n\t}\n\tprev_buffer->file_size = bytes;\n\tprev_buffer->fragment = !no_fragments &&\n\t\t(count == 2 || always_use_fragments) && (byte < block_size);\n\tqueue_put(from_reader, prev_buffer);\n\n\treturn;\n\nread_err:\n\tif(prev_buffer) {\n\t\tcache_block_put(file_buffer);\n\t\tseq --;\n\t\tfile_buffer = prev_buffer;\n\t}\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\n\tstruct file_buffer *file_buffer;\n\tint blocks, byte, count, expected, file, frag_block;\n\tlong long bytes, read_size;\n\n\tif(dir_ent->inode->read)\n\t\treturn;\n\n\tdir_ent->inode->read = TRUE;\nagain:\n\tbytes = 0;\n\tcount = 0;\n\tfile_buffer = NULL;\n\tread_size = buf->st_size;\n\tblocks = (read_size + block_size - 1) >> block_log;\n\tfrag_block = !no_fragments && (always_use_fragments ||\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\n\n\tfile = open(dir_ent->pathname, O_RDONLY);\n\tif(file == -1) {\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = seq ++;\n\t\tgoto read_err;\n\t}\n\n\tdo {\n\t\texpected = read_size - ((long long) count * block_size) >\n\t\t\tblock_size ? block_size :\n\t\t\tread_size - ((long long) count * block_size);\n\n\t\tif(file_buffer)\n\t\t\tqueue_put(from_reader, file_buffer);\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = seq ++;\n\n\t\t/*\n\t\t * Always try to read block_size bytes from the file rather\n\t\t * than expected bytes (which will be less than the block_size\n\t\t * at the file tail) to check that the file hasn't grown\n\t\t * since being stated.  If it is longer (or shorter) than\n\t\t * expected, then restat, and try again.  Note the special\n\t\t * case where the file is an exact multiple of the block_size\n\t\t * is dealt with later.\n\t\t */\n\t\tbyte = file_buffer->size = read_bytes(file, file_buffer->data,\n\t\t\tblock_size);\n\n\t\tfile_buffer->file_size = read_size;\n\n\t\tif(byte == -1)\n\t\t\tgoto read_err;\n\n\t\tif(byte != expected)\n\t\t\tgoto restat;\n\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->error = FALSE;\n\t\tfile_buffer->fragment = (file_buffer->block == frag_block);\n\n\t\tbytes += byte;\n\t\tcount ++;\n\t} while(count < blocks);\n\n\tif(read_size != bytes)\n\t\tgoto restat;\n\n\tif(expected == block_size) {\n\t\t/*\n\t\t * Special case where we've not tried to read past the end of\n\t\t * the file.  We expect to get EOF, i.e. the file isn't larger\n\t\t * than we expect.\n\t\t */\n\t\tchar buffer;\n\t\tint res;\n\n\t\tres = read_bytes(file, &buffer, 1);\n\t\tif(res == -1)\n\t\t\tgoto read_err;\n\n\t\tif(res != 0)\n\t\t\tgoto restat;\n\t}\n\n\tqueue_put(from_reader, file_buffer);\n\n\tclose(file);\n\n\treturn;\n\nrestat:\n\tfstat(file, &buf2);\n\tclose(file);\n\tif(read_size != buf2.st_size) {\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\n\t\tfile_buffer->error = 2;\n\t\tqueue_put(from_deflate, file_buffer);\n\t\tgoto again;\n\t}\nread_err:\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->inode->root_entry)\n\t\t\tcontinue;\n\n\t\tif(IS_PSEUDO_PROCESS(dir_ent->inode)) {\n\t\t\treader_read_process(dir_ent);\n\t\t\tcontinue;\n\t\t}\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry;\n\t\t\t\t\t\t\tentry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\n\tthread[0] = 0;\n\n\tpthread_exit(NULL);\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer,\n\t\t\t\twrite_error ? &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write_bytes(fd, file_buffer->data,\n\t\t\t\tfile_buffer->size) == -1) {\n\t\t\tERROR(\"Write on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\nint all_zero(struct file_buffer *file_buffer)\n{\n\tint i;\n\tlong entries = file_buffer->size / sizeof(long);\n\tlong *p = (long *) file_buffer->data;\n\n\tfor(i = 0; i < entries && p[i] == 0; i++);\n\n\tif(i == entries) {\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1);\n\t\t\ti < file_buffer->size && file_buffer->data[i] == 0;\n\t\t\ti++);\n\n\t\treturn i == file_buffer->size;\n\t}\n\n\treturn 0;\n}\n\n\nvoid *deflator(void *arg)\n{\n\tvoid *stream = NULL;\n\tint res, oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tres = compressor_init(comp, &stream, block_size, 1);\n\tif(res)\n\t\tBAD_ERROR(\"deflator:: compressor_init failed\\n\");\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer;\n\n\t\tif(sparse_files && all_zero(file_buffer)) { \n\t\t\tfile_buffer->c_byte = 0;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else if(file_buffer->fragment) {\n\t\t\tfile_buffer->c_byte = file_buffer->size;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else {\n\t\t\twrite_buffer = cache_get(writer_buffer, 0, 0);\n\t\t\twrite_buffer->c_byte = mangle2(stream,\n\t\t\t\twrite_buffer->data, file_buffer->data,\n\t\t\t\tfile_buffer->size, block_size, noD, 1);\n\t\t\twrite_buffer->sequence = file_buffer->sequence;\n\t\t\twrite_buffer->file_size = file_buffer->file_size;\n\t\t\twrite_buffer->block = file_buffer->block;\n\t\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t(write_buffer->c_byte);\n\t\t\twrite_buffer->fragment = FALSE;\n\t\t\twrite_buffer->error = FALSE;\n\t\t\tcache_block_put(file_buffer);\n\t\t\tqueue_put(from_deflate, write_buffer);\n\t\t}\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tvoid *stream = NULL;\n\tint res, oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tres = compressor_init(comp, &stream, block_size, 1);\n\tif(res)\n\t\tBAD_ERROR(\"frag_deflator:: compressor_init failed\\n\");\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer =\n\t\t\tcache_get(writer_buffer, file_buffer->block +\n\t\t\tFRAG_INDEX, 1);\n\n\t\tc_byte = mangle2(stream, write_buffer->data, file_buffer->data,\n\t\t\tfile_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\twrite_buffer->size = compressed_size;\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tif(fragments_locked == FALSE) {\n\t\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\t\twrite_buffer->block = bytes;\n\t\t\tbytes += compressed_size;\n\t\t\tfragments_outstanding --;\n\t\t\tqueue_put(to_writer, write_buffer);\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tTRACE(\"Writing fragment %lld, uncompressed size %d, \"\n\t\t\t\t\"compressed size %d\\n\", file_buffer->block,\n\t\t\t\tfile_buffer->size, compressed_size);\n\t\t} else {\n\t\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\t\tadd_pending_fragment(write_buffer, c_byte,\n\t\t\t\t\tfile_buffer->block);\n\t\t}\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->sequence);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int sequence = 0;\n\tint hash = BLOCK_HASH(sequence);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->sequence == sequence)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->sequence == sequence)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tsequence ++;\n\n\treturn file_buffer;\n}\n\n\nvoid *progress_thrd(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&progress_mutex);\n\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) *\n\t\t\t1000;\n\t\tpthread_cond_timedwait(&progress_wait, &progress_mutex,\n\t\t\t&timespec);\n\t\tif(progress_enabled && estimated_uncompressed)\n\t\t\tprogress_bar(cur_uncompressed, estimated_uncompressed,\n\t\t\t\tcolumns);\n\t}\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits, used, hashes, spaces;\n\tstatic int tty = -1;\n\n\tif(max == 0)\n\t\treturn;\n\n\tmax_digits = floor(log10(max)) + 1;\n\tused = max_digits * 2 + 11;\n\thashes = (current * (columns - used)) / max;\n\tspaces = columns - used - hashes;\n\n\tif((current > max) || (columns - used < 0))\n\t\treturn;\n\n\tif(tty == -1)\n\t\ttty = isatty(STDOUT_FILENO);\n\tif(!tty) {\n\t\tstatic long long previous = -1;\n\n\t\t/* Updating much more frequently than this results in huge\n\t\t * log files. */\n\t\tif((current % 100) != 0 && current != max)\n\t\t\treturn;\n\t\t/* Don't update just to rotate the spinner. */\n\t\tif(current == previous)\n\t\t\treturn;\n\t\tprevious = current;\n\t}\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0,\n\t\t NULL, &empty_fragment, NULL, 0);\n}\n\n\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint size, int *duplicate_file, struct file_buffer *file_buffer,\n\tunsigned short checksum)\n{\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment,\n\t\tfile_buffer, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\tcache_block_put(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tinc_progress_bar();\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, size, 0,\n\t\t\t0, NULL, fragment, NULL, 0);\n}\n\n\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size,\n\tstruct file_buffer *file_buffer, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum)) {\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file,\n\t\t\tfile_buffer, checksum);\n\t\treturn;\n\t}\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\tcache_block_put(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tinc_progress_bar();\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, size, 0,\n\t\t\t0, NULL, fragment, NULL, 0);\n\n\treturn;\n}\n\n\nint write_file_process(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tstruct file_buffer *read_buffer, int *duplicate_file)\n{\n\tlong long read_size, file_bytes, start;\n\tstruct fragment *fragment;\n\tunsigned int *block_list = NULL;\n\tint block = 0, status;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\t*duplicate_file = FALSE;\n\n\tlock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\twhile (1) {\n\t\tread_size = read_buffer->file_size;\n\t\tif(read_buffer->fragment && read_buffer->c_byte)\n\t\t\tfragment_buffer = read_buffer;\n\t\telse {\n\t\t\tblock_list = realloc(block_list, (block + 1) *\n\t\t\t\tsizeof(unsigned int));\n\t\t\tif(block_list == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory allocating block_list\"\n\t\t\t\t\t\"\\n\");\n\t\t\tblock_list[block ++] = read_buffer->c_byte;\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else {\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(read_size != -1)\n\t\t\tbreak;\n\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t}\n\n\tunlock_fragments();\n\tfragment = get_and_fill_fragment(fragment_buffer);\n\tcache_block_put(fragment_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment,\n\t\t\t0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, read_size, start,\n\t\t block, block_list, fragment, NULL, sparse);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(!block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tlong long file_bytes, start;\n\tstruct fragment *fragment;\n\tunsigned int *block_list;\n\tint block, status;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\t*duplicate_file = FALSE;\n\n\tblock_list = malloc(blocks * sizeof(unsigned int));\n\tif(block_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tlock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else {\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tfragment = get_and_fill_fragment(fragment_buffer);\n\tcache_block_put(fragment_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment,\n\t\t\t0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, read_size, start,\n\t\t blocks, block_list, fragment, NULL, sparse);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(!block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tint block, thresh;\n\tlong long file_bytes, dup_start, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer **buffer_list;\n\tint status, num_locked_fragments;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\tblock_list = malloc(blocks * sizeof(unsigned int));\n\tif(block_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tbuffer_list = malloc(blocks * sizeof(struct file_buffer *));\n\tif(buffer_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tnum_locked_fragments = lock_fragments();\n\n\tfile_bytes = 0;\n\tstart = dup_start = bytes;\n\tthresh = blocks > (writer_buffer_size - num_locked_fragments) ?\n\t\tblocks - (writer_buffer_size - num_locked_fragments): 0;\n\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tif(block < thresh) {\n\t\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t\t} else\n\t\t\t\t\tbuffer_list[block] = read_buffer;\n\t\t\t} else {\n\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &dup_start,\n\t\t&fragment, fragment_buffer, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tif(buffer_list[block])\n\t\t\t\tqueue_put(to_writer, buffer_list[block]);\n\t\tfragment = get_and_fill_fragment(fragment_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tcache_block_put(buffer_list[block]);\n\t\tbytes = start;\n\t\tif(thresh && !block_device) {\n\t\t\tint res;\n\n\t\t\tqueue_put(to_writer, NULL);\n\t\t\tif(queue_get(from_writer) != 0)\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\tres = ftruncate(fd, bytes);\n\t\t\tif(res != 0)\n\t\t\t\tBAD_ERROR(\"Failed to truncate dest file because\"\n\t\t\t\t\t\"  %s\\n\", strerror(errno));\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tcache_block_put(fragment_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, read_size,\n\t\tdup_start, blocks, block_listp, fragment, NULL, sparse);\n\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(thresh && !block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\tcache_block_put(buffer_list[blocks]);\n\tfree(buffer_list);\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tint status;\n\tstruct file_buffer *read_buffer;\n\tlong long read_size;\n\nagain:\n\tread_buffer = get_file_buffer(from_deflate);\n\n\tstatus = read_buffer->error;\n\tif(status) {\n\t\tcache_block_put(read_buffer);\n\t\tgoto file_err;\n\t}\n\t\n\tread_size = read_buffer->file_size;\n\n\tif(read_size == -1)\n\t\tstatus = write_file_process(inode, dir_ent, read_buffer,\n\t\t\tduplicate_file);\n\telse if(read_size == 0) {\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t\tcache_block_put(read_buffer);\n\t} else if(read_buffer->fragment && read_buffer->c_byte)\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer,\n\t\t\tduplicate_file);\n\telse if(pre_duplicate(read_size))\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\telse\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\nfile_err:\n\tif(status == 2) {\n\t\tERROR(\"File %s changed size while reading filesystem, \"\n\t\t\t\"attempting to re-read\\n\", dir_ent->pathname);\n\t\tgoto again;\n\t} else if(status == 1) {\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\",\n\t\t\tdir_ent->pathname);\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t}\n}\n\n\n#define BUFF_SIZE 8192\nchar b_buffer[BUFF_SIZE];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getcwd(b_buffer, BUFF_SIZE);\n\t\tif(result == NULL)\n\t\t\treturn NULL;\n\t\tstrcat(strcat(b_buffer, \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) ||\n\t\t\t\t((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tinode = malloc(sizeof(struct inode_info));\n\tif(inode == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\"\n\t\t\t\"\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->root_entry = FALSE;\n\tinode->pseudo_file = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\n\tif((buf->st_mode & S_IFMT) == S_IFREG)\n\t\testimated_uncompressed += (buf->st_size + block_size - 1) >>\n\t\t\tblock_log;\n\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir,\n\tstruct inode_info *inode_info, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0) {\n\t\tdir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) *\n\t\t\t\tsizeof(struct dir_ent *));\n\t\tif(dir->list == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\t}\n\n\tdir->list[dir->count] = malloc(sizeof(struct dir_ent));\n\tif(dir->list[dir->count] == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) :\n\t\tNULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count++]->our_dir = dir;\n\tdir->byte_count += strlen(name) + sizeof(struct squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tstruct dir_info *dir;\n\n\tdir = malloc(sizeof(struct dir_info));\n\tif(dir == NULL)\n\t\tBAD_ERROR(\"Out of memory in scan1_opendir\\n\");\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count\n\t\t= 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries) {\n\t\tint i;\n\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].inode.type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL,\n\t\t\t\t&old_root_entry[i].inode, dir);\n\t\t}\n\t}\n\n\twhile(index < source) {\n\t\tchar *basename = getbase(source_path[index]);\n\t\tint n, pass = 1;\n\n\t\tif(basename == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\",\n\t\t\t\tsource_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count &&\n\t\t\t\tstrcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i;\n\n\tif(dir->count < old_root_entries) {\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].inode.type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL,\n\t\t\t\t&old_root_entry[i].inode, dir);\n\t\t}\n\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tint pass = 1;\n\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count &&\n\t\t\t\tstrcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name = readdir(dir->linuxdir);\n\n\tif(d_name != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->inode->root_entry)\n\t\t\tcontinue;\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nstruct dir_ent *scan2_lookup(struct dir_info *dir, char *name)\n{\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++)\n\t\tif(strcmp(dir->list[i]->name, name) == 0)\n\t\t\treturn dir->list[i];\n\n\treturn NULL;\n}\n\n\nstruct dir_ent *scan3_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->inode->root_entry)\n\t\t\tadd_dir(dir_info->list[current_count]->inode->inode,\n\t\t\t\tdir_info->list[current_count]->inode->inode_number,\n\t\t\t\tdir_info->list[current_count]->name,\n\t\t\t\tdir_info->list[current_count]->inode->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n\tfree(dir->pathname);\n\tdir->pathname = NULL;\n}\n\n\nvoid scan2_freedir(struct dir_info *dir)\n{\n\tdir->current_count = 0;\n\tif(dir->pathname) {\n\t\tfree(dir->pathname);\n\t\tdir->pathname = NULL;\n\t}\n}\n\n\nvoid scan3_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tdir_scan2(dir_info, pseudo);\n\n\tdir_ent = malloc(sizeof(struct dir_ent));\n\tif(dir_ent == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/*\n \t\t * dummy top level directory, if multiple sources specified on\n\t\t * command line\n\t\t */\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t\tdir_ent->inode = lookup_inode(&buf);\n\t\tdir_ent->inode->pseudo_file = PSEUDO_FILE_OTHER;\n\t} else {\n\t\tif(lstat(pathname, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\",\n\t\t\t\tpathname, strerror(errno));\n\t\t\treturn;\n\t\t}\n\t\tdir_ent->inode = lookup_inode(&buf);\n\t}\n\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted) {\n\t\tint res = generate_file_priorities(dir_info, 0,\n\t\t\t&dir_info->dir_ent->inode->buf);\n\n\t\tif(res == FALSE)\n\t\t\tBAD_ERROR(\"generate_file_priorities failed\\n\");\n\t}\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tif(progress)\n\t\tenable_progress_bar();\n\tdir_scan3(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tchar filename[8192], dir_name[8192];\n\tstruct dir_info *dir = scan1_opendir(pathname);\n\n\tif(dir == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\t\tstruct dir_info *sub_dir;\n\t\tstruct stat buf;\n\t\tstruct pathnames *new;\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\",\n\t\t\t\tfilename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\"\n\t\t\t\t\"\\n\", filename, buf.st_mode & S_IFMT);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(old_exclude) {\n\t\t\tif(old_excluded(filename, &buf))\n\t\t\t\tcontinue;\n\t\t} else {\n\t\t\tif(excluded(paths, dir_name, &new))\n\t\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tsub_dir = dir_scan1(filename, new, scan1_readdir);\n\t\t\tif(sub_dir == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf),\n\t\t\tdir);\n\t}\n\n\tscan1_freedir(dir);\n\nerror:\n\treturn dir;\n}\n\n\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo)\n{\n\tstruct dir_info *sub_dir;\n\tstruct dir_ent *dir_ent;\n\tstruct pseudo_entry *pseudo_ent;\n\tstruct stat buf;\n\tstatic int pseudo_ino = 1;\n\t\n\tif(dir == NULL && (dir = scan1_opendir(\"\")) == NULL)\n\t\treturn NULL;\n\t\n\twhile((dir_ent = scan2_readdir(dir)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *name = dir_ent->name;\n\n\t\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\tdir_scan2(dir_ent->dir, pseudo_subdir(name, pseudo));\n\t}\n\n\twhile((pseudo_ent = pseudo_readdir(pseudo)) != NULL) {\n\t\tdir_ent = scan2_lookup(dir, pseudo_ent->name);\n\t\tif(pseudo_ent->dev->type == 'm') {\n\t\t\tstruct stat *buf;\n\t\t\tif(dir_ent == NULL) {\n\t\t\t\tERROR(\"Pseudo modify file \\\"%s\\\" does not exist \"\n\t\t\t\t\t\"in source filesystem.  Ignoring.\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(dir_ent->inode->root_entry) {\n\t\t\t\tERROR(\"Pseudo modify file \\\"%s\\\" is a pre-existing\"\n\t\t\t\t\t\" file in the filesystem being appended\"\n\t\t\t\t\t\"  to.  It cannot be modified. \"\n\t\t\t\t\t\"Ignoring.\\n\", pseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tbuf = &dir_ent->inode->buf;\n\t\t\tbuf->st_mode = (buf->st_mode & S_IFMT) |\n\t\t\t\tpseudo_ent->dev->mode;\n\t\t\tbuf->st_uid = pseudo_ent->dev->uid;\n\t\t\tbuf->st_gid = pseudo_ent->dev->gid;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(dir_ent) {\n\t\t\tif(dir_ent->inode->root_entry)\n\t\t\t\tERROR(\"Pseudo file \\\"%s\\\" is a pre-existing\"\n\t\t\t\t\t\" file in the filesystem being appended\"\n\t\t\t\t\t\"  to.  Ignoring.\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\telse\n\t\t\t\tERROR(\"Pseudo file \\\"%s\\\" exists in source \"\n\t\t\t\t\t\"filesystem \\\"%s\\\".\\nIgnoring, \"\n\t\t\t\t\t\"exclude it (-e/-ef) to override.\\n\",\n\t\t\t\t\tpseudo_ent->pathname,\n\t\t\t\t\tdir_ent->pathname);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(pseudo_ent->dev->type == 'd') {\n\t\t\tsub_dir = dir_scan2(NULL, pseudo_ent->pseudo);\n\t\t\tif(sub_dir == NULL) {\n\t\t\t\tERROR(\"Could not create pseudo directory \\\"%s\\\"\"\n\t\t\t\t\t\", skipping...\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = pseudo_ent->dev->mode;\n\t\tbuf.st_uid = pseudo_ent->dev->uid;\n\t\tbuf.st_gid = pseudo_ent->dev->gid;\n\t\tbuf.st_rdev = makedev(pseudo_ent->dev->major,\n\t\t\tpseudo_ent->dev->minor);\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_ino = pseudo_ino ++;\n\n\t\tif(pseudo_ent->dev->type == 'f') {\n#ifdef USE_TMP_FILE\n\t\t\tstruct stat buf2;\n\t\t\tint res = stat(pseudo_ent->dev->filename, &buf2);\n\t\t\tstruct inode_info *inode;\n\t\t\tif(res == -1) {\n\t\t\t\tERROR(\"Stat on pseudo file \\\"%s\\\" failed, \"\n\t\t\t\t\t\"skipping...\", pseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tbuf.st_size = buf2.st_size;\n\t\t\tinode = lookup_inode(&buf);\n\t\t\tinode->pseudo_file = PSEUDO_FILE_OTHER;\t\t\n\t\t\tadd_dir_entry(pseudo_ent->name,\n\t\t\t\tpseudo_ent->dev->filename, sub_dir, inode,\n\t\t\t\tdir);\n#else\n\t\t\tstruct inode_info *inode = lookup_inode(&buf);\n\t\t\tinode->pseudo_id = pseudo_ent->dev->pseudo_id;\n\t\t\tinode->pseudo_file = PSEUDO_FILE_PROCESS;\t\t\n\t\t\tadd_dir_entry(pseudo_ent->name, pseudo_ent->pathname,\n\t\t\t\tsub_dir, inode, dir);\n#endif\n\t\t} else {\n\t\t\tstruct inode_info *inode = lookup_inode(&buf);\n\t\t\tinode->pseudo_file = PSEUDO_FILE_OTHER;\t\t\n\t\t\tadd_dir_entry(pseudo_ent->name, pseudo_ent->pathname,\n\t\t\t\tsub_dir, inode, dir);\n\t\t}\n\t}\n\n\tscan2_freedir(dir);\n\tsort_directory(dir);\n\n\treturn dir;\n}\n\n\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint duplicate_file;\n\tchar *pathname = dir_info->dir_ent->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan3_init_dir(&dir);\n\t\n\twhile((dir_ent = scan3_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\t?  dir_ent->inode->inode_number :\n\t\t\tdir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\twrite_file(inode, dir_ent,\n\t\t\t\t\t\t&duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld \"\n\t\t\t\t\t\t\"bytes %s\\n\", filename,\n\t\t\t\t\t\t(long long) buf->st_size,\n\t\t\t\t\t\tduplicate_file ?  \"DUPLICATE\" :\n\t\t\t\t\t\t \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tdir_scan3(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\"\n\t\t\t\t\t\t\"\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\",dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tBAD_ERROR(\"%s unrecognised file type, \"\n\t\t\t\t\t\t\"mode is %x\\n\", filename,\n\t\t\t\t\t\tbuf->st_mode);\n\t\t\t}\n\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed \"\n\t\t\t\t\t\t\t\"size %lld bytes LINK\"\n\t\t\t\t\t\t\t\"\\n\", filename,\n\t\t\t\t\t\t\t(long long)\n\t\t\t\t\t\t\tbuf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx LINK\\n\", dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t\tupdate_progress_bar();\n\t}\n\n\twrite_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan3_freedir(&dir);\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 20; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint old_excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) &&\n\t\t\t\t(exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) { \\\n\t\texclude_paths = realloc(exclude_paths, (exclude + EXCLUDE_SIZE) \\\n\t\t\t* sizeof(struct exclude_info)); \\\n\t\tif(exclude_paths == NULL) \\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\"); \\\n\t} \\\n\texclude_paths[exclude].st_dev = buf.st_dev; \\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint old_add_exclude(char *path)\n{\n\tint i;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 ||\n\t\t\tstrncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat exclude dir/file %s because %s, \"\n\t\t\t\t\"ignoring\", path, strerror(errno));\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tERROR(\"Cannot stat exclude dir/file %s because \"\n\t\t\t\t\t\"%s, ignoring\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type)\n{\n\told_root_entry = realloc(old_root_entry,\n\t\tsizeof(struct old_root_entry_info) * (old_root_entries + 1));\n\tif(old_root_entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries \"\n\t\t\t\"reallocation\\n\");\n\n\told_root_entry[old_root_entries].name = strdup(name);\n\told_root_entry[old_root_entries].inode.inode = inode;\n\told_root_entry[old_root_entries].inode.inode_number = inode_number;\n\told_root_entry[old_root_entries].inode.type = type;\n\told_root_entry[old_root_entries++].inode.root_entry = TRUE;\n}\n\n\nvoid initialise_threads(int readb_mbytes, int writeb_mbytes,\n\tint fragmentb_mbytes)\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\tint reader_buffer_size = readb_mbytes << (20 - block_log);\n\tint fragment_buffer_size = fragmentb_mbytes << (20 - block_log);\n\n\t/*\n\t * writer_buffer_size is global because it is needed in\n\t * write_file_blocks_dup()\n\t */\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n#ifdef __CYGWIN__\n\tprocessors = atoi(getenv(\"NUMBER_OF_PROCESSORS\"));\n#else\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  \"\n\t\t\t\t\"Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = sysconf(_SC_NPROCESSORS_ONLN);\n#endif\n\t}\n#endif /* __CYGWIN__ */\n\n\tthread = malloc((2 + processors * 2) * sizeof(pthread_t));\n\tif(thread == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(fragment_buffer_size);\n\treader_buffer = cache_init(block_size, reader_buffer_size);\n\twriter_buffer = cache_init(block_size, writer_buffer_size);\n\tfragment_buffer = cache_init(block_size, fragment_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&progress_thread, NULL, progress_thrd, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) !=\n\t\t\t\t 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator,\n\t\t\t\tNULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\tvoid *it;\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tit = realloc(inode_lookup_table, lookup_bytes);\n\tif(it == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\tinode_lookup_table = it;\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number +\n\t\t\t\tdir_inode_no;\n\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(&inode->inode,\n\t\t\t\t&inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, inode_lookup_table, 0, NULL,\n\t\tnoI);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tpaths = malloc(sizeof(struct pathname));\n\t\tif(paths == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) *\n\t\t\tsizeof(struct path_entry));\n\t\tif(paths->name == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add path\\n\");\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\tif(paths->name[i].preg == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory in add_path\\n\");\n\t\t\terror = regcomp(paths->name[i].preg, targname,\n\t\t\t\tREG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, \"\n\t\t\t\t\t\"because %s\\n\", targname, alltarget,\n\t\t\t\t\tstr);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target,\n\t\t\t\talltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing exclude which subsumes\n\t\t\t * the exclude currently being added, in which case stop\n\t\t\t * adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist\n\t\t\t * from more specific excludes, delete as they're\n\t\t\t * subsumed by this exclude */\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid add_exclude(char *target)\n{\n\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 ||\n\t\t\tstrncmp(target, \"../\", 3) == 0)\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with \"\n\t\t\t\"-wildcards or -regex options\\n\");\t\n\telse if(strncmp(target, \"... \", 4) == 0)\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\n\telse\t\n\t\tpath = add_path(path, target, target);\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames));\n\tif(new == NULL)\n\t\tBAD_ERROR(\"Out of memory in init_subdir\\n\");\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0) {\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) +\n\t\t\t(paths->count + PATHS_ALLOC_SIZE) *\n\t\t\tsizeof(struct pathname *));\n\t\tif(paths == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_subdir\\n\");\n\t}\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n, res;\n\t\t\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\n\t*new = init_subdir();\n\tif(stickypath)\n\t\t*new = add_subdir(*new, stickypath);\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0,\n\t\t\t\t\tNULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name,\n\t\t\t\t\tFNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) ==\n\t\t\t\t\t 0;\n\n\t\t\tif(match && path->name[i].paths == NULL) {\n\t\t\t\t/* match on a leaf component, any subdirectories\n\t\t\t\t * in the filesystem should be excluded */\n\t\t\t\tres = TRUE;\n\t\t\t\tgoto empty_set;\n\t\t\t}\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any\n\t\t\t\t * subdirectories to the new set of\n\t\t\t\t * subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t\t/* no matching names found, return empty new search set\n\t\t\t */\n\t\t\tres = FALSE;\n\t\t\tgoto empty_set;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches).\n\t * Return new set */\n\treturn FALSE;\n\nempty_set:\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn res;\n}\n\n\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\n#define RECOVER_ID_SIZE 28\n\nvoid write_recovery_data(struct squashfs_super_block *sBlk)\n{\n\tint res, recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\n\tpid_t pid = getpid();\n\tchar *metadata;\n\tchar header[] = RECOVER_ID;\n\n\tif(recover == FALSE) {\n\t\tprintf(\"No recovery data option specified.\\n\");\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\n\t\treturn;\n\t}\n\n\tmetadata = malloc(bytes);\n\tif(metadata == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"write_recovery_data\\n\");\n\n\tres = read_fs_bytes(fd, sBlk->inode_table_start, bytes, metadata);\n\tif(res == 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\",\n\t\tgetbase(destination_file), pid);\n\trecoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);\n\tif(recoverfd == -1)\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  \"\n\t\t\t\"Aborting\\n\", strerror(errno));\n\t\t\n\tif(write_bytes(recoverfd, header, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, sBlk, sizeof(struct squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, metadata, bytes) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tclose(recoverfd);\n\tfree(metadata);\n\t\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file,\n\t\trecovery_file);\n\tprintf(\"to restore filesystem\\n\\n\");\n}\n\n\nvoid read_recovery_data(char *recovery_file, char *destination_file)\n{\n\tint fd, recoverfd, bytes;\n\tstruct squashfs_super_block orig_sBlk, sBlk;\n\tchar *metadata;\n\tint res;\n\tstruct stat buf;\n\tchar header[] = RECOVER_ID;\n\tchar header2[RECOVER_ID_SIZE];\n\n\trecoverfd = open(recovery_file, O_RDONLY);\n\tif(recoverfd == -1)\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(stat(destination_file, &buf) == -1)\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tfd = open(destination_file, O_RDWR);\n\tif(fd == -1)\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tres = read_bytes(recoverfd, header2, RECOVER_ID_SIZE);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < RECOVER_ID_SIZE)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\n\n\tres = read_bytes(recoverfd, &sBlk, sizeof(struct squashfs_super_block));\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < sizeof(struct squashfs_super_block))\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\tres = read_fs_bytes(fd, 0, sizeof(struct squashfs_super_block), &orig_sBlk);\n\tif(res == 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4,\n\t\t\tsizeof(struct squashfs_super_block) - 4) != 0)\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to \"\n\t\t\t\"match\\n\");\n\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\n\n\tmetadata = malloc(bytes);\n\tif(metadata == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"read_recovery_data\\n\");\n\n\tres = read_bytes(recoverfd, metadata, bytes);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < bytes)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\twrite_destination(fd, 0, sizeof(struct squashfs_super_block), &sBlk);\n\n\twrite_destination(fd, sBlk.inode_table_start, bytes, metadata);\n\n\tclose(recoverfd);\n\tclose(fd);\n\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\",\n\t\trecovery_file);\n\t\n\texit(0);\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 4.2 (2011/02/28)\\n\");\\\n\tprintf(\"copyright (C) 2011 Phillip Lougher \"\\\n\t\t\"<phillip@lougher.demon.co.uk>\\n\\n\"); \\\n\tprintf(\"This program is free software; you can redistribute it and/or\"\\\n\t\t\"\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\"\\\n\t\t\"\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version \"\\\n\t\t\"2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be \"\\\n\t\t\"useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty \"\\\n\t\t\"of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\"\\\n\t\t\"\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf, source_buf;\n\tint res, i;\n\tstruct squashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint nopad = FALSE, keep_as_directory = FALSE;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT,\n\t\twriteb_mbytes = WRITER_BUFFER_DEFAULT,\n\t\tfragmentb_mbytes = FRAGMENT_BUFFER_DEFAULT;\n\n\tpthread_mutex_init(&progress_mutex, NULL);\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\t/*\n\t * lookup default compressor.  Note the Makefile ensures the default\n\t * compressor has been built, and so we don't need to to check\n\t * for failure here\n\t */\n\tcomp = lookup_compressor(COMP_DEFAULT);\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-comp\") == 0) {\n\t\t\tif(compressor_opts_parsed) {\n\t\t\t\tERROR(\"%s: -comp must appear before -X options\"\n\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -comp missing compression type\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tcomp = lookup_compressor(argv[i]);\n\t\t\tif(!comp->supported) {\n\t\t\t\tERROR(\"%s: Compressor \\\"%s\\\" is not supported!\"\n\t\t\t\t\t\"\\n\", argv[0], argv[i]);\n\t\t\t\tERROR(\"%s: Compressors available:\\n\", argv[0]);\n\t\t\t\tdisplay_compressors(\"\", COMP_DEFAULT);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t} else if(strncmp(argv[i], \"-X\", 2) == 0) {\n\t\t\tint args = compressor_options(comp, argv + i, argc - i);\n\t\t\tif(args < 0) {\n\t\t\t\tif(args == -1) {\n\t\t\t\t\tERROR(\"%s: Unrecognised compressor\"\n\t\t\t\t\t\t\" option %s\\n\", argv[0],\n\t\t\t\t\t\targv[i]);\n\t\t\t\t\tERROR(\"%s: Did you forget to specify\"\n\t\t\t\t\t\t\" -comp, or specify it after\"\n\t\t\t\t\t\t\" the compressor specific\"\n\t\t\t\t\t\t\" option?\\n\", argv[0]);\n\t\t\t\t\t}\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\ti += args;\n\t\t\tcompressor_opts_parsed = 1;\n\n\t\t} else if(strcmp(argv[i], \"-pf\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -pf missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_file(&pseudo, argv[i]) == FALSE)\n\t\t\t\texit(1);\n\t\t} else if(strcmp(argv[i], \"-p\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -p missing pseudo file definition\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_def(&pseudo, argv[i]) == FALSE)\n\t\t\t\texit(1);\n\t\t} else if(strcmp(argv[i], \"-recover\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\n\t\t\trecover = FALSE;\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = FALSE;\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\n\t\t\tsparse_files = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid \"\n\t\t\t\t\t\"processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte \"\n\t\t\t\t\t\"or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-fragment-queue\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(fragmentb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -fragment-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragmentb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -fragment-queue should be 1 \"\n\t\t\t\t\t\"megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -b missing block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_size = strtol(argv[i], &b, 10);\n\t\t\tif(*b == 'm' || *b == 'M')\n\t\t\t\tblock_size *= 1048576;\n\t\t\telse if(*b == 'k' || *b == 'K')\n\t\t\t\tblock_size *= 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tERROR(\"%s: -b invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or \"\n\t\t\t\t\t\"not between 4096 and 1Mbyte\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or \"\n\t\t\t\t\t\t\"unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or \"\n\t\t\t\t\t\t\"unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noX\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noXattrCompression\") == 0)\n\t\t\tnoX = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-no-xattrs\") == 0)\n\t\t\tno_xattrs = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-xattrs\") == 0)\n\t\t\tno_xattrs = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0) {\n\t\t\tsilent = FALSE;\n\t\t\tprogress = FALSE;\n\t\t}\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] \"\n\t\t\t\t\"[-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nFilesystem build options:\\n\");\n\t\t\tERROR(\"-comp <comp>\\t\\tselect <comp> compression\\n\");\n\t\t\tERROR(\"\\t\\t\\tCompressors available:\\n\");\n\t\t\tdisplay_compressors(\"\\t\\t\\t\", COMP_DEFAULT);\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to \"\n\t\t\t\t\"<block_size>.  Default %d bytes\\n\",\n\t\t\t\tSQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem \"\n\t\t\t\t\"exportable via NFS\\n\");\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\n\t\t\tERROR(\"-no-xattrs\\t\\tdon't store extended attributes\"\n\t\t\t\tNOXOPT_STR \"\\n\");\n\t\t\tERROR(\"-xattrs\\t\\t\\tstore extended attributes\" XOPT_STR\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-noX\\t\\t\\tdo not compress extended \"\n\t\t\t\t\"attributes\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for \"\n\t\t\t\t\"files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate \"\n\t\t\t\t\"checking\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple \"\n\t\t\t\t\"of 4K\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is \"\n\t\t\t\t\"specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, \"\n\t\t\t\t\"rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"\\nFilesystem filter options:\\n\");\n\t\t\tERROR(\"-p <pseudo-definition>\\tAdd pseudo file \"\n\t\t\t\t\"definition\\n\");\n\t\t\tERROR(\"-pf <pseudo-file>\\tAdd list of pseudo file \"\n\t\t\t\t\"definitions\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to \"\n\t\t\t\t\"priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  \"\n\t\t\t\t\"Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.\"\n\t\t\t\t\"  One per line\\n\");\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards \"\n\t\t\t\t\"(globbing) to be used in\\n\\t\\t\\texclude \"\n\t\t\t\t\"dirs/files\\n\");\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to \"\n\t\t\t\t\"be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n\t\t\tERROR(\"\\nFilesystem append options:\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing \"\n\t\t\t\t\"filesystem\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source \"\n\t\t\t\t\"files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in \"\n\t\t\t\t\"the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new \"\n\t\t\t\t\"source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"\\nMksquashfs runtime options:\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and \"\n\t\t\t\t\"copyright message\\n\");\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data \"\n\t\t\t\t\"using recovery file <name>\\n\");\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery \"\n\t\t\t\t\"file\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress \"\n\t\t\t\t\"bar\\n\");\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.\"\n\t\t\t\t\"  By default will use number of\\n\");\n\t\t\tERROR(\"\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tREADER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tWRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-fragment-queue <size>\\tSet fragment queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tFRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\nMiscellaneous options:\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for \"\n\t\t\t\t\"-noF\\n\");\n\t\t\tERROR(\"-noXattrCompression\\talternative name for \"\n\t\t\t\t\"-noX\\n\");\n\t\t\tERROR(\"\\nCompressors available and compressor specific \"\n\t\t\t\t\"options:\\n\");\n\t\t\tdisplay_compressor_usage(COMP_DEFAULT);\n\t\t\texit(1);\n\t\t}\n\t}\n\n\t/*\n\t * Some compressors may need the options to be checked for validity\n\t * once all the options have been processed\n\t */\n\tres = compressor_options_post(comp, block_size);\n\tif(res)\n\t\tEXIT_MKSQUASHFS();\n\n\tfor(i = 0; i < source; i++)\n\t\tif(lstat(source_path[i], &source_buf) == -1) {\n\t\t\tfprintf(stderr, \"Cannot stat source directory \\\"%s\\\" \"\n\t\t\t\t\"because %s\\n\", source_path[i],\n\t\t\t\tstrerror(errno));\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tfd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR,\n\t\t\t\tS_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as \"\n\t\t\t\t\t\"destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tfd = open(argv[source + 1], (delete ? O_TRUNC : 0) |\n\t\t\t\tO_RDWR);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not open regular file for \"\n\t\t\t\t\t\"writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tsignal(SIGTERM, sighandler2);\n\tsignal(SIGINT, sighandler2);\n\n\t/*\n\t * process the exclude files - must be done afer destination file has\n\t * been possibly created\n\t */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\t\tif(old_exclude)\n\t\t\t\t\t\told_add_exclude(filename);\n\t\t\t\t\telse\n\t\t\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-sort\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-comp\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc)\n\t\t\tif(old_exclude)\n\t\t\t\told_add_exclude(argv[i++]);\n\t\t\telse\n\t\t\t\tadd_exclude(argv[i++]);\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tint res = read_sort_file(argv[++i], source,\n\t\t\t\t\t\t\t\tsource_path);\n\t\t\tif(res == FALSE)\n\t\t\t\tBAD_ERROR(\"Failed to read sort file\\n\");\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-ef\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-comp\") == 0)\n\t\t\ti++;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(!delete) {\n\t        comp = read_super(fd, &sBlk, argv[source + 1]);\n\t        if(comp == NULL) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tnoX = SQUASHFS_UNCOMPRESSED_XATTRS(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t\tno_xattrs = SQUASHFS_NO_XATTRS(sBlk.flags);\n\t\tcomp_opts = SQUASHFS_COMP_OPTS(sBlk.flags);\n\t}\n\n\tinitialise_threads(readb_mbytes, writeb_mbytes, fragmentb_mbytes);\n\n\tres = compressor_init(comp, &stream, SQUASHFS_METADATA_SIZE, 0);\n\tif(res)\n\t\tBAD_ERROR(\"compressor_init failed\\n\");\n\n\tif(delete) {\n\t\tint size;\n\t\tvoid *comp_data = compressor_dump_options(comp, block_size,\n\t\t\t&size);\n\n\t\tprintf(\"Creating %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\tSQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\n\t\t/*\n\t\t * store any compressor specific options after the superblock,\n\t\t * and set the COMP_OPT flag to show that the filesystem has\n\t\t * compressor specfic options\n\t\t */\n\t\tif(comp_data) {\n\t\t\tunsigned short c_byte = size | SQUASHFS_COMPRESSED_BIT;\n\t\n\t\t\tSQUASHFS_INSWAP_SHORTS(&c_byte, 1);\n\t\t\twrite_destination(fd, sizeof(struct squashfs_super_block),\n\t\t\t\tsizeof(c_byte), &c_byte);\n\t\t\twrite_destination(fd, sizeof(struct squashfs_super_block) +\n\t\t\t\tsizeof(c_byte), size, comp_data);\n\t\t\tbytes = sizeof(struct squashfs_super_block) + sizeof(c_byte)\n\t\t\t\t+ size;\n\t\t\tcomp_opts = TRUE;\n\t\t} else\t\t\t\n\t\t\tbytes = sizeof(struct squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset,\n\t\t\tinode_dir_file_size, root_inode_size,\n\t\t\tinode_dir_start_block, uncompressed_data,\n\t\t\tcompressed_data, inode_dir_inode_number,\n\t\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start =\n\t\t\tSQUASHFS_INODE_BLK(sBlk.root_inode),\n\t\t\troot_inode_offset =\n\t\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table,\n\t\t\t\t&data_cache, &directory_table,\n\t\t\t\t&directory_data_cache, &last_directory_block,\n\t\t\t\t&inode_dir_offset, &inode_dir_file_size,\n\t\t\t\t&root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count,\n\t\t\t\t&fifo_count, &sock_count, &total_bytes,\n\t\t\t\t&total_inode_bytes, &total_directory_bytes,\n\t\t\t\t&inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry,\n\t\t\t\t&fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments)) {\n\t\t\tfragment_table = realloc((char *) fragment_table,\n\t\t\t\t((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1))\n\t\t\t\t * sizeof(struct squashfs_fragment_entry)); \n\t\t\tif(fragment_table == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory in save filesystem state\\n\");\n\t\t}\n\n\t\tprintf(\"Appending to existing %d.%d filesystem on %s, block \"\n\t\t\t\"size %d\\n\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1],\n\t\t\tblock_size);\n\t\tprintf(\"All -b, -noI, -noD, -noF, -noX, no-duplicates, no-fragments, \"\n\t\t\t\"-always-use-fragments,\\n-exportable and -comp options \"\n\t\t\t\"ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with \"\n\t\t\t\"-noappend specified!\\n\\n\");\n\n\t\tcompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t(SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tscache_bytes = root_inode_offset + root_inode_size;\n\t\tsdirectory_cache_bytes = uncompressed_data;\n\t\tsdata_cache = malloc(scache_bytes);\n\t\tif(sdata_cache == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in save filesystem state\\n\");\n\t\tsdirectory_data_cache = malloc(sdirectory_cache_bytes);\n\t\tif(sdirectory_data_cache == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in save filesystem state\\n\");\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache +\n\t\t\tcompressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes +\n\t\t\tcompressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\tsid_count = id_count;\n\t\twrite_recovery_data(&sBlk);\n\t\tif(save_xattrs() == FALSE)\n\t\t\tBAD_ERROR(\"Failed to save xattrs from existing \"\n\t\t\t\t\"filesystem\\n\");\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_destination(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/*\n\t\t * set the filesystem state up to be able to append to the\n\t\t * original filesystem.  The filesystem state differs depending\n\t\t * on whether we're appending to the original root directory, or\n\t\t * if the original root directory becomes a sub-directory\n\t\t * (root-becomes specified on command line, here root_name !=\n\t\t * NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\tsdirectory_bytes = last_directory_block;\n\t\t\tsdirectory_compressed_bytes = 0;\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache +\n\t\t\t\tcompressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode,\n\t\t\t\tinode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\tsdirectory_compressed_bytes = last_directory_block -\n\t\t\t\tinode_dir_start_block;\n\t\t\tsdirectory_compressed =\n\t\t\t\tmalloc(sdirectory_compressed_bytes);\n\t\t\tif(sdirectory_compressed == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory in save filesystem \"\n\t\t\t\t\t\"state\\n\");\n\t\t\tmemcpy(sdirectory_compressed, directory_table +\n\t\t\t\tinode_dir_start_block,\n\t\t\t\tsdirectory_compressed_bytes); \n\t\t\tsdirectory_bytes = inode_dir_start_block;\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count +\n\t\t\tfifo_count + sock_count;\n\n\t\t/*\n\t\t * The default use freelist before growing cache policy behaves\n\t\t * poorly with appending - with many deplicates the caches\n\t\t * do not grow due to the fact that large queues of outstanding\n\t\t * fragments/writer blocks do not occur, leading to small caches\n\t\t * and un-uncessary performance loss to frequent cache\n\t\t * replacement in the small caches.  Therefore with appending\n\t\t * change the policy to grow the caches before reusing blocks\n\t\t * from the freelist\n\t\t */\n\t\tfirst_freelist = FALSE;\n\t}\n\n\tif(path || stickypath) {\n\t\tpaths = init_subdir();\n\t\tif(path)\n\t\t\tpaths = add_subdir(paths, path);\n\t\tif(stickypath)\n\t\t\tpaths = add_subdir(paths, stickypath);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, noX, no_fragments,\n\t\talways_use_fragments, duplicate_checking, exportable,\n\t\tno_xattrs, comp_opts);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\tif(progress && estimated_uncompressed) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(!restoring) {\n\t\tunlock_fragments();\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\twhile(fragments_outstanding) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tsched_yield();\n\t\t\tpthread_mutex_lock(&fragment_mutex);\n\t\t}\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.no_ids = id_count;\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() :\n\t\tSQUASHFS_INVALID_BLK;\n\tsBlk.id_table_start = write_id_table();\n\tsBlk.xattr_id_table_start = write_xattrs();\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\",\n\t\tsBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\",\n\t\t\tsBlk.lookup_table_start);\n\n\tsBlk.bytes_used = bytes;\n\n\tsBlk.compression = comp->id;\n\n\tSQUASHFS_INSWAP_SUPER_BLOCK(&sBlk); \n\twrite_destination(fd, SQUASHFS_START, sizeof(sBlk), &sBlk);\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_destination(fd, bytes, 4096 - i, temp);\n\t}\n\n\tclose(fd);\n\n\tdelete_pseudo_files();\n\n\tif(recovery_file[0] != '\\0')\n\t\tunlink(recovery_file);\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes +\n\t\tsizeof(struct squashfs_super_block) + total_xattr_bytes;\n\n\tprintf(\"\\n%sSquashfs %d.%d filesystem, %s compressed, data block size\"\n\t\t\" %d\\n\", exportable ? \"Exportable \" : \"\", SQUASHFS_MAJOR,\n\t\tSQUASHFS_MINOR, comp->name, block_size);\n\tprintf(\"\\t%s data, %s metadata, %s fragments, %s xattrs\\n\",\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" :\n\t\t\"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" :\n\t\t\"compressed\", no_xattrs ? \"no\" : noX ? \"uncompressed\" :\n\t\t\"compressed\");\n\tprintf(\"\\tduplicates are %sremoved\\n\", duplicate_checking ? \"\" :\n\t\t\"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0,\n\t\tbytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0,\n\t\ttotal_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0,\n\t\ttotal_directory_bytes);\n\tif(total_xattr_bytes) {\n\t\tprintf(\"Xattr table size %d bytes (%.2f Kbytes)\\n\",\n\t\t\txattr_bytes, xattr_bytes / 1024.0);\n\t\tprintf(\"\\t%.2f%% of uncompressed xattr table size (%d bytes)\\n\",\n\t\t\t((float) xattr_bytes / total_xattr_bytes) * 100.0,\n\t\t\ttotal_xattr_bytes);\n\t}\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count -\n\t\t\tdup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of ids (unique uids + gids) %d\\n\", id_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_UID) {\n\t\t\tstruct passwd *user = getpwuid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" :\n\t\t\t\tuser->pw_name, id_table[i]->id);\n\t\t}\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_GID) {\n\t\t\tstruct group *group = getgrgid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" :\n\t\t\t\tgroup->gr_name, id_table[i]->id);\n\t\t}\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/mksquashfs.h",
    "content": "#ifndef MKSQUASHFS_H\n#define MKSQUASHFS_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define SQUASHFS_SWAP_SHORTS(s, d, n) swap_le16_num(s, d, n)\n#define SQUASHFS_SWAP_INTS(s, d, n) swap_le32_num(s, d, n)\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) swap_le64_num(s, d, n)\n\n#define SWAP_LE16(s, d)\t\tswap_le16(s, d)\n#define SWAP_LE32(s, d)\t\tswap_le32(s, d)\n#define SWAP_LE64(s, d)\t\tswap_le64(s, d)\n#else\n#define SQUASHFS_MEMCPY(s, d, n)\tmemcpy(d, s, n)\n#define SQUASHFS_SWAP_SHORTS(s, d, n)\tmemcpy(d, s, n * sizeof(short))\n#define SQUASHFS_SWAP_INTS(s, d, n)\tmemcpy(d, s, n * sizeof(int))\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) \\\n\t\t\t\t\tmemcpy(d, s, n * sizeof(long long))\n#endif\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n};\n\nstruct inode_info {\n\tstruct stat\t\tbuf;\n\tstruct inode_info\t*next;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\tnlink;\n\tint\t\t\tpseudo_id;\n\tchar\t\t\ttype;\n\tchar\t\t\tread;\n\tchar\t\t\troot_entry;\n\tchar\t\t\tpseudo_file;\n};\n#endif\n\n#define PSEUDO_FILE_OTHER\t1\n#define PSEUDO_FILE_PROCESS\t2\n\n#define IS_PSEUDO(a)\t\t((a)->pseudo_file)\n#define IS_PSEUDO_PROCESS(a)\t((a)->pseudo_file & PSEUDO_FILE_PROCESS)\n#define IS_PSEUDO_OTHER(a)\t((a)->pseudo_file & PSEUDO_FILE_OTHER)\n\n/* offset of data in compressed metadata blocks (allowing room for\n * compressed size */\n#define BLOCK_OFFSET 2\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/pseudo.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * pseudo.c\n */\n\n#include <pwd.h>\n#include <grp.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <stdlib.h>\n#include <sys/types.h>\n#include <sys/wait.h>\n#include <sys/stat.h>\n\n#include \"pseudo.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\n#define EXIT_MKSQUASHFS() \\\n\t\tdo { \\\n\t\t\texit(1); \\\n\t\t} while(0)\n\n#define BAD_ERROR(s, args...) \\\n\t\tdo {\\\n\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\tEXIT_MKSQUASHFS();\\\n\t\t} while(0);\n\n#define TRUE 1\n#define FALSE 0\n\nstruct pseudo_dev **pseudo_file = NULL;\nint pseudo_count = 0;\n\nstatic void dump_pseudo(struct pseudo *pseudo, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tfor(i = 0; i < pseudo->names; i++) {\n\t\tstruct pseudo_entry *entry = &pseudo->name[i];\n\t\tif(string)\n\t\t\tstrcat(strcat(strcpy(path, string), \"/\"), entry->name);\n\t\telse\n\t\t\tstrcpy(path, entry->name);\n\t\tif(entry->pseudo == NULL)\n\t\t\tERROR(\"%s %c %o %d %d %d %d\\n\", path, entry->dev->type,\n\t\t\t\tentry->dev->mode, entry->dev->uid,\n\t\t\t\tentry->dev->gid, entry->dev->major,\n\t\t\t\tentry->dev->minor);\n\t\telse\n\t\t\tdump_pseudo(entry->pseudo, path);\n\t}\n}\n\n\nstatic char *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\n/*\n * Add pseudo device target to the set of pseudo devices.  Pseudo_dev\n * describes the pseudo device attributes.\n */\nstruct pseudo *add_pseudo(struct pseudo *pseudo, struct pseudo_dev *pseudo_dev,\n\tchar *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i;\n\n\ttarget = get_component(target, targname);\n\n\tif(pseudo == NULL) {\n\t\tif((pseudo = malloc(sizeof(struct pseudo))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate pseudo file\\n\");\n\n\t\tpseudo->names = 0;\n\t\tpseudo->count = 0;\n\t\tpseudo->name = NULL;\n\t}\n\n\tfor(i = 0; i < pseudo->names; i++)\n\t\tif(strcmp(pseudo->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == pseudo->names) {\n\t\t/* allocate new name entry */\n\t\tpseudo->names ++;\n\t\tpseudo->name = realloc(pseudo->name, (i + 1) *\n\t\t\tsizeof(struct pseudo_entry));\n\t\tif(pseudo->name == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate pseudo file\\n\");\n\t\tpseudo->name[i].name = strdup(targname);\n\n\t\tif(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component */\n\t\t\tpseudo->name[i].pseudo = NULL;\n\t\t\tpseudo->name[i].pathname = strdup(alltarget);\n\t\t\tpseudo->name[i].dev = pseudo_dev;\n\t\t} else {\n\t\t\t/* recurse adding child components */\n\t\t\tpseudo->name[i].dev = NULL;\n\t\t\tpseudo->name[i].pseudo = add_pseudo(NULL, pseudo_dev,\n\t\t\t\ttarget, alltarget);\n\t\t}\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(pseudo->name[i].pseudo == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing pseudo file.\n\t\t\t */\n\t\t\tif(target[0] != '\\0') {\n\t\t\t\t/* entry must exist as a 'd' type pseudo file */\n\t\t\t\tif(pseudo->name[i].dev->type == 'd')\n\t\t\t\t\t/* recurse adding child components */\n\t\t\t\t\tpseudo->name[i].pseudo =\n\t\t\t\t\t\tadd_pseudo(NULL, pseudo_dev,\n\t\t\t\t\t\ttarget, alltarget);\n\t\t\t\telse\n\t\t\t\t\tERROR(\"%s already exists as a non \"\n\t\t\t\t\t\t\"directory.  Ignoring %s!\\n\",\n\t\t\t\t\t\t targname, alltarget);\n\t\t\t} else if(memcmp(pseudo_dev, pseudo->name[i].dev,\n\t\t\t\t\tsizeof(struct pseudo_dev)) != 0)\n\t\t\t\tERROR(\"%s already exists as a different pseudo \"\n\t\t\t\t\t\"definition.  Ignoring!\\n\", alltarget);\n\t\t\telse ERROR(\"%s already exists as an identical \"\n\t\t\t\t\t\"pseudo definition!\\n\", alltarget);\n\t\t} else {\n\t\t\t/* sub-directory exists which means this can only be a\n\t\t\t * 'd' type pseudo file */\n\t\t\tif(target[0] == '\\0') {\n\t\t\t\tif(pseudo->name[i].dev == NULL &&\n\t\t\t\t\t\tpseudo_dev->type == 'd') {\n\t\t\t\t\tpseudo->name[i].pathname =\n\t\t\t\t\t\tstrdup(alltarget);\n\t\t\t\t\tpseudo->name[i].dev = pseudo_dev;\n\t\t\t\t} else\n\t\t\t\t\tERROR(\"%s already exists as a \"\n\t\t\t\t\t\t\"directory.  Ignoring %s!\\n\",\n\t\t\t\t\t\ttargname, alltarget);\n\t\t\t} else\n\t\t\t\t/* recurse adding child components */\n\t\t\t\tadd_pseudo(pseudo->name[i].pseudo, pseudo_dev,\n\t\t\t\t\ttarget, alltarget);\n\t\t}\n\t}\n\n\treturn pseudo;\n}\n\n\n/*\n * Find subdirectory in pseudo directory referenced by pseudo, matching\n * filename.  If filename doesn't exist or if filename is a leaf file\n * return NULL\n */\nstruct pseudo *pseudo_subdir(char *filename, struct pseudo *pseudo)\n{\n\tint i;\n\n\tif(pseudo == NULL)\n\t\treturn NULL;\n\n\tfor(i = 0; i < pseudo->names; i++)\n\t\tif(strcmp(filename, pseudo->name[i].name) == 0)\n\t\t\treturn pseudo->name[i].pseudo;\n\n\treturn NULL;\n}\n\n\nstruct pseudo_entry *pseudo_readdir(struct pseudo *pseudo)\n{\n\tif(pseudo == NULL)\n\t\treturn NULL;\n\n\twhile(pseudo->count < pseudo->names) {\n\t\tif(pseudo->name[pseudo->count].dev != NULL)\n\t\t\treturn &pseudo->name[pseudo->count++];\n\t\telse\n\t\t\tpseudo->count++;\n\t}\n\n\treturn NULL;\n}\n\n\nint exec_file(char *command, struct pseudo_dev *dev)\n{\n\tint child, res;\n\tstatic pid_t pid = -1;\n\tint pipefd[2];\n#ifdef USE_TMP_FILE\n\tchar filename[1024];\n\tint status;\n\tstatic int number = 0;\n#endif\n\n\tif(pid == -1)\n\t\tpid = getpid();\n\n#ifdef USE_TMP_FILE\n\tsprintf(filename, \"/tmp/squashfs_pseudo_%d_%d\", pid, number ++);\n\tpipefd[1] = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);\n\tif(pipefd[1] == -1) {\n\t\tprintf(\"open failed\\n\");\n\t\treturn -1;\n\t}\n#else\n\tres = pipe(pipefd);\n\tif(res == -1) {\n\t\tprintf(\"pipe failed\\n\");\n\t\treturn -1;\n\t}\n#endif\n\n\tchild = fork();\n\tif(child == -1) {\n\t\tprintf(\"fork failed\\n\");\n\t\tgoto failed;\n\t}\n\n\tif(child == 0) {\n\t\tclose(STDOUT_FILENO);\n\t\tres = dup(pipefd[1]);\n\t\tif(res == -1) {\n\t\t\tprintf(\"dup failed\\n\");\n\t\t\texit(EXIT_FAILURE);\n\t\t}\n\t\texecl(\"/bin/sh\", \"sh\", \"-c\", command, (char *) NULL);\n\t\tprintf(\"execl failed\\n\");\n\t\texit(EXIT_FAILURE);\n\t}\n\n#ifdef USE_TMP_FILE\n\tres = waitpid(child, &status, 0);\n\tclose(pipefd[1]);\n\tif(res != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0) {\n\t\tdev->filename = strdup(filename);\n\t\treturn 0;\n\t}\nfailed:\n\tunlink(filename);\n\treturn -1;\n#else\n\tclose(pipefd[1]);\n\tdev->fd = pipefd[0];\n\tdev->child = child;\n\treturn 0;\nfailed:\n\treturn -1;\n#endif\n}\n\n\nvoid add_pseudo_file(struct pseudo_dev *dev)\n{\n\tpseudo_file = realloc(pseudo_file, (pseudo_count + 1) *\n\t\tsizeof(struct pseudo_dev *));\n\tif(pseudo_file == NULL)\n\t\tBAD_ERROR(\"Failed to realloc pseudo_file\\n\");\n\n\tdev->pseudo_id = pseudo_count;\n\tpseudo_file[pseudo_count ++] = dev;\n}\n\n\nvoid delete_pseudo_files()\n{\n#ifdef USE_TMP_FILE\n\tint i;\n\n\tfor(i = 0; i < pseudo_count; i++)\n\t\tunlink(pseudo_file[i]->filename);\n#endif\n}\n\n\nstruct pseudo_dev *get_pseudo_file(int pseudo_id)\n{\n\treturn pseudo_file[pseudo_id];\n}\n\n\nint read_pseudo_def(struct pseudo **pseudo, char *def)\n{\n\tint n, bytes;\n\tunsigned int major = 0, minor = 0, mode;\n\tchar filename[2048], type, suid[100], sgid[100], *ptr;\n\tlong long uid, gid;\n\tstruct pseudo_dev *dev;\n\n\tn = sscanf(def, \"%s %c %o %s %s %n\", filename, &type, &mode, suid,\n\t\t\tsgid, &bytes);\n\n\tif(n < 5) {\n\t\tERROR(\"Not enough or invalid arguments in pseudo file \"\n\t\t\t\"definition\\n\");\n\t\tgoto error;\n\t}\n\n\tswitch(type) {\n\tcase 'b':\n\tcase 'c':\n\t\tn = sscanf(def + bytes,  \"%u %u\", &major, &minor);\n\n\t\tif(n < 2) {\n\t\t\tERROR(\"Not enough or invalid arguments in pseudo file \"\n\t\t\t\t\"definition\\n\");\n\t\t\tgoto error;\n\t\t}\t\n\t\t\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range\\n\", major);\n\t\t\tgoto error;\n\t\t}\n\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range\\n\", minor);\n\t\t\tgoto error;\n\t\t}\n\n\tcase 'f':\n\t\tif(def[bytes] == '\\0') {\n\t\t\tERROR(\"Not enough arguments in pseudo file \"\n\t\t\t\t\"definition\\n\");\n\t\t\tgoto error;\n\t\t}\t\n\t\tbreak;\n\tcase 'd':\n\tcase 'm':\n\t\tbreak;\n\tdefault:\n\t\tERROR(\"Unsupported type %c\\n\", type);\n\t\tgoto error;\n\t}\n\n\n\tif(mode > 07777) {\n\t\tERROR(\"Mode %o out of range\\n\", mode);\n\t\tgoto error;\n\t}\n\n\tuid = strtoll(suid, &ptr, 10);\n\tif(*ptr == '\\0') {\n\t\tif(uid < 0 || uid > ((1LL << 32) - 1)) {\n\t\t\tERROR(\"Uid %s out of range\\n\", suid);\n\t\t\tgoto error;\n\t\t}\n\t} else {\n\t\tstruct passwd *pwuid = getpwnam(suid);\n\t\tif(pwuid)\n\t\t\tuid = pwuid->pw_uid;\n\t\telse {\n\t\t\tERROR(\"Uid %s invalid uid or unknown user\\n\", suid);\n\t\t\tgoto error;\n\t\t}\n\t}\n\t\t\n\tgid = strtoll(sgid, &ptr, 10);\n\tif(*ptr == '\\0') {\n\t\tif(gid < 0 || gid > ((1LL << 32) - 1)) {\n\t\t\tERROR(\"Gid %s out of range\\n\", sgid);\n\t\t\tgoto error;\n\t\t}\n\t} else {\n\t\tstruct group *grgid = getgrnam(sgid);\n\t\tif(grgid)\n\t\t\tgid = grgid->gr_gid;\n\t\telse {\n\t\t\tERROR(\"Gid %s invalid uid or unknown user\\n\", sgid);\n\t\t\tgoto error;\n\t\t}\n\t}\n\n\tswitch(type) {\n\tcase 'b':\n\t\tmode |= S_IFBLK;\n\t\tbreak;\n\tcase 'c':\n\t\tmode |= S_IFCHR;\n\t\tbreak;\n\tcase 'd':\n\t\tmode |= S_IFDIR;\n\t\tbreak;\n\tcase 'f':\n\t\tmode |= S_IFREG;\n\t\tbreak;\n\t}\n\n\tdev = malloc(sizeof(struct pseudo_dev));\n\tif(dev == NULL)\n\t\tBAD_ERROR(\"Failed to create pseudo_dev\\n\");\n\n\tdev->type = type;\n\tdev->mode = mode;\n\tdev->uid = uid;\n\tdev->gid = gid;\n\tdev->major = major;\n\tdev->minor = minor;\n\n\tif(type == 'f') {\n\t\tint res;\n\n\t\tprintf(\"Executing dynamic pseudo file\\n\");\n\t\tprintf(\"\\t\\\"%s\\\"\\n\", def);\n\t\tres = exec_file(def + bytes, dev);\n\t\tif(res == -1) {\n\t\t\tERROR(\"Failed to execute dynamic pseudo file definition\"\n\t\t\t\t\" \\\"%s\\\"\\n\", def);\n\t\t\treturn FALSE;\n\t\t}\n\t\tadd_pseudo_file(dev);\n\t}\n\n\t*pseudo = add_pseudo(*pseudo, dev, filename, filename);\n\n\treturn TRUE;\n\nerror:\n\tERROR(\"Bad pseudo file definition \\\"%s\\\"\\n\", def);\n\treturn FALSE;\n}\n\t\t\n\n\n#define MAX_LINE 2048\n\nint read_pseudo_file(struct pseudo **pseudo, char *filename)\n{\n\tFILE *fd;\n\tchar *line = NULL;\n\tint size = 0;\n\tint res = TRUE;\n\n\tfd = fopen(filename, \"r\");\n\tif(fd == NULL) {\n\t\tERROR(\"Could not open pseudo device file \\\"%s\\\" because %s\\n\",\n\t\t\t\tfilename, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(1) {\n\t\tint total = 0;\n\n\t\twhile(1) {\n\t\t\tint n, err;\n\n\t\t\tif(total + MAX_LINE > size) {\n\t\t\t\tline = realloc(line, size += MAX_LINE);\n\t\t\t\tif(line == NULL) {\n\t\t\t\t\tERROR(\"No space in read_pseudo_file\\n\");\n\t\t\t\t\treturn FALSE;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\terr = fscanf(fd, \"%2047[^\\n]%n\\n\", line + total, &n);\n\t\t\tif(err <= 0)\n\t\t\t\tgoto done;\n\n\t\t\tif(line[total] == '#')\n\t\t\t\tcontinue;\n\n\t\t\tif(line[total + n - 1] != '\\\\')\n\t\t\t\tbreak;\n\n\t\t\ttotal += n - 1;\n\t\t}\t\n\n\t\tres = read_pseudo_def(pseudo, line);\n\t\tif(res == FALSE)\n\t\t\tbreak;\n\t}\n\ndone:\n\tfclose(fd);\n\tfree(line);\n\treturn res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/pseudo.h",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * pseudo.h\n */\nstruct pseudo_dev {\n\tchar\t\ttype;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tgid;\n\tunsigned int\tmajor;\n\tunsigned int\tminor;\n\tint\t\tpseudo_id;\n\tint\t\tfd;\n\tint\t\tchild;\n#ifdef USE_TMP_FILE\n\tchar\t\t*filename;\n#endif\n};\n\nstruct pseudo_entry {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct pseudo\t\t*pseudo;\n\tstruct pseudo_dev\t*dev;\n};\n\t\nstruct pseudo {\n\tint\t\t\tnames;\n\tint\t\t\tcount;\n\tstruct pseudo_entry\t*name;\n};\n\nextern int read_pseudo_def(struct pseudo **, char *);\nextern int read_pseudo_file(struct pseudo **, char *);\nextern struct pseudo *pseudo_subdir(char *, struct pseudo *);\nextern struct pseudo_entry *pseudo_readdir(struct pseudo *);\nextern struct pseudo_dev *get_pseudo_file(int);\nextern void delete_pseudo_files();\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#ifndef __CYGWIN__\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#endif\n#else\n#include <endian.h>\n#endif\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n#include \"compressor.h\"\n#include \"xattr.h\"\n\nextern int read_fs_bytes(int, long long, int, void *);\nextern int add_file(long long, long long, long long, unsigned int *, int,\n\tunsigned int, int, int);\nextern void *create_id(unsigned int);\nextern unsigned int get_uid(unsigned int);\nextern unsigned int get_guid(unsigned int);\n\nstatic struct compressor *comp;\n\nint read_block(int fd, long long start, long long *next, void *block)\n{\n\tunsigned short c_byte;\n\tint res;\n\t\n\tres = read_fs_bytes(fd, start, 2, &c_byte);\n\tif(res == 0)\n\t\treturn 0;\n\n\tSQUASHFS_INSWAP_SHORTS(&c_byte, 1);\n\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint error, res;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tres = read_fs_bytes(fd, start + 2, c_byte, buffer);\n\t\tif(res == 0)\n\t\t\treturn 0;\n\n\t\tres = compressor_uncompress(comp, block, buffer, c_byte,\n\t\t\tSQUASHFS_METADATA_SIZE, &error);\n\t\tif(res == -1) {\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + 2 + c_byte;\n\t\treturn res;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tres = read_fs_bytes(fd, start + 2, c_byte, block);\n\t\tif(res == 0)\n\t\t\treturn 0;\n\n\t\tif(next)\n\t\t\t*next = start + 2 + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end,\n\tlong long root_inode_start, int root_inode_offset,\n\tstruct squashfs_super_block *sBlk, union squashfs_inode_header *dir_inode,\n\tunsigned char **inode_table, unsigned int *root_inode_block,\n\tunsigned int *root_inode_size, long long *uncompressed_file,\n\tunsigned int *uncompressed_directory, int *file_count, int *sym_count,\n\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\tunsigned int *id_table)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tstruct squashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start \"\n\t\t\"0x%llx\\n\", start, end, root_inode_start);\n\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx \"\n\t\t\t\t\"containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE) {\n\t\t\t*inode_table = realloc(*inode_table, size\n\t\t\t\t+= SQUASHFS_METADATA_SIZE);\n\t\t\tif(*inode_table == NULL)\n\t\t\t\treturn FALSE;\n\t\t}\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tbyte = read_block(fd, start, &start, *inode_table + bytes);\n\t\tif(byte == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain\n\t * the last directory start block index.  This is used when calculating\n\t * the total uncompressed directory size.  The directory bytes in the\n\t * last * block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, *inode_table + bytes);\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir,\n\t\t\t*inode_table + bytes);\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir,\n\t\t\t*inode_table + bytes);\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\tget_uid(id_table[dir_inode->base.uid]);\n\tget_guid(id_table[dir_inode->base.guid]);\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, cur_ptr);\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position \"\n\t\t\t\"0x%x, type 0x%x\\n\",\n\t\t\t(unsigned int) (cur_ptr - *inode_table),\n\t\t\tinode.inode_type);\n\n\t\tget_uid(id_table[inode.uid]);\n\t\tget_guid(id_table[inode.guid]);\n\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? 0 :\n\t\t\t\t\tinode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >>\n\t\t\t\t\tsBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, \"\n\t\t\t\t\t\"file_size %d, blocks %d\\n\",\n\t\t\t\t\tinode.file_size, blocks);\n\n\t\t\t\tblock_list = malloc(blocks *\n\t\t\t\t\tsizeof(unsigned int));\n\t\t\t\tif(block_list == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list \"\n\t\t\t\t\t\t\"malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tSQUASHFS_SWAP_INTS(block_list, cur_ptr, blocks);\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes +=\n\t\t\t\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t\t(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes,\n\t\t\t\t\tblock_list, blocks, inode.fragment,\n\t\t\t\t\tinode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tstruct squashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, cur_ptr);\n\n\t\t\t\tfrag_bytes = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? 0 :\n\t\t\t\t\tinode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t\t?  (inode.file_size +\n\t\t\t\t\tsBlk->block_size - 1) >>\n\t\t\t\t\tsBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular \"\n\t\t\t\t\t\"file, file_size %lld, blocks %d\\n\",\n\t\t\t\t\tinode.file_size, blocks);\n\n\t\t\t\tblock_list = malloc(blocks *\n\t\t\t\t\tsizeof(unsigned int));\n\t\t\t\tif(block_list == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list \"\n\t\t\t\t\t\t\"malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tSQUASHFS_SWAP_INTS(block_list, cur_ptr, blocks);\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes +=\n\t\t\t\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t\t(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes,\n\t\t\t\t\tblock_list, blocks, inode.fragment,\n\t\t\t\t\tinode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tcase SQUASHFS_LSYMLINK_TYPE: {\n\t\t\t\tstruct squashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep,\n\t\t\t\t\tcur_ptr);\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\n\t\t\t\tif (inode.inode_type == SQUASHFS_LSYMLINK_TYPE)\n\t\t\t\t\tcur_ptr += sizeof(unsigned int);\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tstruct squashfs_dir_inode_header dir_inode;\n\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode,\n\t\t\t\t\tcur_ptr);\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory +=\n\t\t\t\t\tdir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tstruct squashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode,\n\t\t\t\t\tcur_ptr);\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory +=\n\t\t\t\t\tdir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tstruct squashfs_dir_index index;\n\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index,\n\t\t\t\t\t\tcur_ptr);\n\t\t\t\t\tcur_ptr += sizeof(struct squashfs_dir_index) +\n\t\t\t\t\t\tindex.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\t\t \tcase SQUASHFS_LBLKDEV_TYPE:\n\t\t \tcase SQUASHFS_LCHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_ldev_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_LFIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_lipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_LSOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_lipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in \"\n\t\t\t\t\t\"scan_inode_table!\\n\",\n\t\t\t\t\tinode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\treturn TRUE;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nstruct compressor *read_super(int fd, struct squashfs_super_block *sBlk, char *source)\n{\n\tint res, bytes = 0;\n\tchar buffer[SQUASHFS_METADATA_SIZE] __attribute__ ((aligned));\n\n\tres = read_fs_bytes(fd, SQUASHFS_START, sizeof(struct squashfs_super_block),\n\t\tsBlk);\n\tif(res == 0)\n\t\tgoto failed_mount;\n\n\tSQUASHFS_INSWAP_SUPER_BLOCK(sBlk);\n\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP)\n\t\t\tERROR(\"Pre 4.0 big-endian filesystem on %s, appending\"\n\t\t\t\t\" to this is unsupported\\n\", source);\n\t\telse\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n\t\t\t\tsource);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 4)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.\"\n\t\t\t\t\"  Appending\\nto SQUASHFS %d.%d filesystems is \"\n\t\t\t\t\"not supported.  Please convert it to a \"\n\t\t\t\t\"SQUASHFS 4 filesystem\\n\", source,\n\t\t\t\tsBlk->s_major,\n\t\t\t\tsBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Filesystem on %s is %d.%d, which is a later \"\n\t\t\t\t\"filesystem version than I support\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the compression type */\n\tcomp = lookup_compressor_id(sBlk->compression);\n\tif(!comp->supported) {\n\t\tERROR(\"Filesystem on %s uses %s compression, this is\"\n\t\t\t\"unsupported by this version\\n\", source, comp->name);\n\t\tERROR(\"Compressors available:\\n\");\n\t\tdisplay_compressors(\"\", \"\");\n\t\tgoto failed_mount;\n\t}\n\n\t/*\n\t * Read extended superblock information from disk.\n\t *\n\t * Read compressor specific options from disk if present, and pass\n\t * to compressor to set compressor options.\n\t *\n\t * Note, if there's no compressor options present, the compressor\n\t * is still called to set the default options (the defaults may have\n\t * been changed by the user specifying options on the command\n\t * line which need to be over-ridden).\n\t */\n\tif(SQUASHFS_COMP_OPTS(sBlk->flags)) {\n\t\tbytes = read_block(fd, sizeof(*sBlk), NULL, buffer);\n\n\t\tif(bytes == 0)\n\t\t\tgoto failed_mount;\n\t}\n\n\tres = compressor_extract_options(comp, sBlk->block_size, buffer, bytes);\n\tif(res == -1) {\n\t\tERROR(\"Compressor failed to set compressor options\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\tprintf(\"Found a valid %sSQUASHFS superblock on %s.\\n\",\n\t\tSQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", source);\n\tprintf(\"\\tCompression used %s\\n\", comp->name);\n\tprintf(\"\\tInodes are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tXattrs are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_XATTRS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\",\n\t\tSQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\",\n\t\tSQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\",\n\t\tSQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tXattrs are %sstored\\n\",\n\t\tSQUASHFS_NO_XATTRS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\",\n\t\tsBlk->bytes_used / 1024.0, sBlk->bytes_used\n\t\t/ (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of ids %d\\n\", sBlk->no_ids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\",\n\t\tsBlk->directory_table_start);\n\tTRACE(\"sBlk->id_table_start %llx\\n\", sBlk->id_table_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %llx\\n\", sBlk->lookup_table_start);\n\tTRACE(\"sBlk->xattr_id_table_start %llx\\n\", sBlk->xattr_id_table_start);\n\tprintf(\"\\n\");\n\n\treturn comp;\n\nfailed_mount:\n\treturn NULL;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries,\n\tunsigned int directory_start_block, int offset, int size,\n\tunsigned int *last_directory_block, struct squashfs_super_block *sBlk,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tstruct squashfs_dir_header dirh;\n\tchar buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1]\n\t\t__attribute__ ((aligned));\n\tstruct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block,\n\t\tlast_start_block = start; \n\n\tsize += offset;\n\tdirectory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) &\n\t\t~(SQUASHFS_METADATA_SIZE - 1));\n\tif(directory_table == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so \"\n\t\t\t\"far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tbyte = read_block(fd, start, &start, directory_table + bytes);\n\t\tif(byte == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, directory_table + bytes);\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position \"\n\t\t\t\"0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, directory_table + bytes);\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, \"\n\t\t\t\t\"inode %x:%x, type 0x%x\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name,\n\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n\t\t\t\tdire->offset), dirh.inode_number +\n\t\t\t\tdire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block -\n\t\tsBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nunsigned int *read_id_table(int fd, struct squashfs_super_block *sBlk)\n{\n\tint indexes = SQUASHFS_ID_BLOCKS(sBlk->no_ids);\n\tlong long index[indexes];\n\tint bytes = SQUASHFS_ID_BYTES(sBlk->no_ids);\n\tunsigned int *id_table;\n\tint res, i;\n\n\tid_table = malloc(bytes);\n\tif(id_table == NULL) {\n\t\tERROR(\"Failed to allocate id table\\n\");\n\t\treturn NULL;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk->id_table_start,\n\t\tSQUASHFS_ID_BLOCK_BYTES(sBlk->no_ids), index);\n\tif(res == 0) {\n\t\tfree(id_table);\n\t\treturn NULL;\n\t}\n\n\tSQUASHFS_INSWAP_ID_BLOCKS(index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) id_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read id table block %d, from 0x%llx, length %d\\n\", i,\n\t\t\tindex[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read id table block %d, from 0x%llx, \"\n\t\t\t\t\"length %d\\n\", i, index[i], length);\n\t\t\tfree(id_table);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_INTS(id_table, sBlk->no_ids);\n\n\tfor(i = 0; i < sBlk->no_ids; i++) {\n\t\tTRACE(\"Adding id %d to id tables\\n\", id_table[i]);\n\t\tcreate_id(id_table[i]);\n\t}\n\n\treturn id_table;\n}\n\n\nint read_fragment_table(int fd, struct squashfs_super_block *sBlk,\n\tstruct squashfs_fragment_entry **fragment_table)\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tlong long fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk->fragments, indexes,\n\t\tsBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\t*fragment_table = malloc(sBlk->fragments *\n\t\tsizeof(struct squashfs_fragment_entry));\n\tif(*fragment_table == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk->fragment_table_start,\n\t\tSQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments),\n\t\tfragment_table_index);\n\tif(res == 0) {\n\t\tfree(*fragment_table);\n\t\treturn 0;\n\t}\n\n\tSQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((unsigned char *) *fragment_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read fragment table block %d, from \"\n\t\t\t\t\"0x%llx, length %d\\n\", i,\n\t\t\t\tfragment_table_index[i], length);\n\t\t\tfree(*fragment_table);\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tfor(i = 0; i < sBlk->fragments; i++)\n\t\tSQUASHFS_INSWAP_FRAGMENT_ENTRY(&(*fragment_table)[i]);\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, struct squashfs_super_block *sBlk,\n\tsquashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint res, i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\t*inode_lookup_table = malloc(lookup_bytes);\n\tif(*inode_lookup_table == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk->lookup_table_start,\n\t\tSQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), index);\n\tif(res == 0) {\n\t\tfree(*inode_lookup_table);\n\t\treturn 0;\n\t}\n\n\tSQUASHFS_INSWAP_LONG_LONGS(index, indexes);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) *inode_lookup_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length \"\n\t\t\t\"%d\\n\", i, index[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read inode lookup table block %d, \"\n\t\t\t\t\"from 0x%llx, length %d\\n\", i, index[i],\n\t\t\t\tlength);\n\t\t\tfree(*inode_lookup_table);\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_LONG_LONGS(*inode_lookup_table, sBlk->inodes);\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, struct squashfs_super_block *sBlk,\n\tchar **cinode_table, char **data_cache, char **cdirectory_table,\n\tchar **directory_data_cache, unsigned int *last_directory_block,\n\tunsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block,\n\tint *file_count, int *sym_count, int *dev_count, int *dir_count,\n\tint *fifo_count, int *sock_count, long long *uncompressed_file,\n\tunsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\tunsigned int *inode_dir_inode_number,\n\tunsigned int *inode_dir_parent_inode,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\tstruct squashfs_fragment_entry **fragment_table,\n\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start;\n\tlong long end = sBlk->directory_table_start;\n\tlong long root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk->root_inode);\n\tunsigned int root_inode_block;\n\tunion squashfs_inode_header inode;\n\tunsigned int *id_table;\n\tint res;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(get_xattrs(fd, sBlk) == 0)\n\t\tgoto error;\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tid_table = read_id_table(fd, sBlk);\n\tif(id_table == NULL)\n\t\tgoto error;\n\n\tres = scan_inode_table(fd, start, end, root_inode_start,\n\t\troot_inode_offset, sBlk, &inode, &inode_table,\n\t\t&root_inode_block, root_inode_size, uncompressed_file,\n\t\tuncompressed_directory, file_count, sym_count, dev_count,\n\t\tdir_count, fifo_count, sock_count, id_table);\n\tif(res == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE ||\n\t\t\tinode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tdirectory_table = squashfs_readdir(fd, !root_name,\n\t\t\t*inode_dir_start_block, *inode_dir_offset,\n\t\t\t*inode_dir_file_size, last_directory_block, sBlk,\n\t\t\tpush_directory_entry);\n\t\tif(directory_table == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\"\n\t\t\t\t\"\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\t*cinode_table = malloc(root_inode_start);\n\t\tif(*cinode_table == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for \"\n\t\t\t\t\"existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tres = read_fs_bytes(fd, start, root_inode_start, *cinode_table);\n\t\tif(res == 0)\n\t\t\tgoto error;\n\n\t\t*cdirectory_table = malloc(*last_directory_block);\n\t\tif(*cdirectory_table == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for \"\n\t\t\t\t\"existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tres = read_fs_bytes(fd, sBlk->directory_table_start,\n\t\t\t*last_directory_block, *cdirectory_table);\n\t\tif(res == 0)\n\t\t\tgoto error;\n\n\t\t*data_cache = malloc(root_inode_offset + *root_inode_size);\n\t\tif(*data_cache == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block,\n\t\t\troot_inode_offset + *root_inode_size);\n\n\t\t*directory_data_cache = malloc(*inode_dir_offset +\n\t\t\t*inode_dir_file_size);\n\t\tif(*directory_data_cache == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory \"\n\t\t\t\t\"cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table,\n\t\t\t*inode_dir_offset + *inode_dir_file_size);\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/read_fs.h",
    "content": "#ifndef READ_FS_H\n#define READ_FS_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.h\n *\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define SQUASHFS_SWAP_SHORTS(d, s, n) swap_le16_num(s, d, n)\n#define SQUASHFS_SWAP_INTS(d, s, n) swap_le32_num(s, d, n)\n#define SQUASHFS_SWAP_LONG_LONGS(d, s, n) swap_le64_num(s, d, n)\n\n#define SWAP_LE16(d, s)\t\tswap_le16(s, d)\n#define SWAP_LE32(d, s)\t\tswap_le32(s, d)\n#define SWAP_LE64(d, s)\t\tswap_le64(s, d)\n#else\n#define SQUASHFS_MEMCPY(d, s, n)\tmemcpy(d, s, n)\n#define SQUASHFS_SWAP_SHORTS(d, s, n)\tmemcpy(d, s, n * sizeof(short))\n#define SQUASHFS_SWAP_INTS(d, s, n)\tmemcpy(d, s, n * sizeof(int))\n#define SQUASHFS_SWAP_LONG_LONGS(d, s, n) \\\n\t\t\t\t\tmemcpy(d, s, n * sizeof(long long))\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/read_xattrs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_xattrs.c\n */\n\n/*\n * Common xattr read code shared between mksquashfs and unsquashfs\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <string.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n#include \"xattr.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"read_xattrs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\nextern int read_fs_bytes(int, long long, int, void *);\nextern int read_block(int, long long, long long *, void *);\n\nstatic struct hash_entry {\n\tlong long\t\tstart;\n\tunsigned int\t\toffset;\n\tstruct hash_entry\t*next;\n} *hash_table[65536];\n\nstatic struct squashfs_xattr_id *xattr_ids;\nstatic void *xattrs = NULL;\nstatic long long xattr_table_start;\n\n/*\n * Prefix lookup table, storing mapping to/from prefix string and prefix id\n */\nstruct prefix prefix_table[] = {\n\t{ \"user.\", SQUASHFS_XATTR_USER },\n\t{ \"trusted.\", SQUASHFS_XATTR_TRUSTED },\n\t{ \"security.\", SQUASHFS_XATTR_SECURITY },\n\t{ \"\", -1 }\n};\n\n/*\n * store mapping from location of compressed block in fs ->\n * location of uncompressed block in memory\n */\nstatic int save_xattr_block(long long start, int offset)\n{\n\tstruct hash_entry *hash_entry = malloc(sizeof(*hash_entry));\n\tint hash = start & 0xffff;\n\n\tTRACE(\"save_xattr_block: start %lld, offset %d\\n\", start, offset);\n\n\tif(hash_entry == NULL) {\n\t\tERROR(\"Failed to allocate hash entry\\n\");\n\t\treturn -1;\n\t}\n\n\thash_entry->start = start;\n\thash_entry->offset = offset;\n\thash_entry->next = hash_table[hash];\n\thash_table[hash] = hash_entry;\n\n\treturn 1;\n}\n\n\n/*\n * map from location of compressed block in fs ->\n * location of uncompressed block in memory\n */\nstatic int get_xattr_block(long long start)\n{\n\tint hash = start & 0xffff;\n\tstruct hash_entry *hash_entry = hash_table[hash];\n\n\tfor(; hash_entry; hash_entry = hash_entry->next)\n\t\tif(hash_entry->start == start)\n\t\t\tbreak;\n\n\tTRACE(\"get_xattr_block: start %lld, offset %d\\n\", start,\n\t\thash_entry ? hash_entry->offset : -1);\n\n\treturn hash_entry ? hash_entry->offset : -1;\n}\n\n\n/*\n * construct the xattr_list entry from the fs xattr, including\n * mapping name and prefix into a full name\n */\nstatic int read_xattr_entry(struct xattr_list *xattr,\n\tstruct squashfs_xattr_entry *entry, void *name)\n{\n\tint i, len, type = entry->type & XATTR_PREFIX_MASK;\n\n\tfor(i = 0; prefix_table[i].type != -1; i++)\n\t\tif(prefix_table[i].type == type)\n\t\t\tbreak;\n\n\tif(prefix_table[i].type == -1) {\n\t\tERROR(\"Unrecognised type in read_xattr_entry\\n\");\n\t\treturn 0;\n\t}\n\n\tlen = strlen(prefix_table[i].prefix);\n\txattr->full_name = malloc(len + entry->size + 1);\n\tif(xattr->full_name == NULL) {\n\t\tERROR(\"Out of memory in read_xattr_entry\\n\");\n\t\treturn -1;\n\t}\n\tmemcpy(xattr->full_name, prefix_table[i].prefix, len);\n\tmemcpy(xattr->full_name + len, name, entry->size);\n\txattr->full_name[len + entry->size] = '\\0';\n\txattr->name = xattr->full_name + len;\n\txattr->size = entry->size;\n\txattr->type = type;\n\n\treturn 1;\n}\n\n\n/*\n * Read and decompress the xattr id table and the xattr metadata.\n * This is cached in memory for later use by get_xattr()\n */\nint read_xattrs_from_disk(int fd, struct squashfs_super_block *sBlk)\n{\n\tint res, bytes, i, indexes, index_bytes, ids;\n\tlong long *index, start, end;\n\tstruct squashfs_xattr_table id_table;\n\n\tTRACE(\"read_xattrs_from_disk\\n\");\n\n\tif(sBlk->xattr_id_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn SQUASHFS_INVALID_BLK;\n\n\t/*\n\t * Read xattr id table, containing start of xattr metadata and the\n\t * number of xattrs in the file system\n\t */\n\tres = read_fs_bytes(fd, sBlk->xattr_id_table_start, sizeof(id_table),\n\t\t&id_table);\n\tif(res == 0)\n\t\treturn 0;\n\n\tSQUASHFS_INSWAP_XATTR_TABLE(&id_table);\n\n\t/*\n\t * Allocate and read the index to the xattr id table metadata\n\t * blocks\n\t */\n\tids = id_table.xattr_ids;\n\txattr_table_start = id_table.xattr_table_start;\n\tindex_bytes = SQUASHFS_XATTR_BLOCK_BYTES(ids);\n\tindexes = SQUASHFS_XATTR_BLOCKS(ids);\n\tindex = malloc(index_bytes);\n\tif(index == NULL) {\n\t\tERROR(\"Failed to allocate index array\\n\");\n\t\treturn 0;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk->xattr_id_table_start + sizeof(id_table),\n\t\tindex_bytes, index);\n\tif(res ==0)\n\t\tgoto failed1;\n\n\tSQUASHFS_INSWAP_LONG_LONGS(index, indexes);\n\n\t/*\n\t * Allocate enough space for the uncompressed xattr id table, and\n\t * read and decompress it\n\t */\n\tbytes = SQUASHFS_XATTR_BYTES(ids);\n\txattr_ids = malloc(bytes);\n\tif(xattr_ids == NULL) {\n\t\tERROR(\"Failed to allocate xattr id table\\n\");\n\t\tgoto failed1;\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) xattr_ids) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read xattr id table block %d, from 0x%llx, length \"\n\t\t\t\"%d\\n\", i, index[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read xattr id table block %d, \"\n\t\t\t\t\"from 0x%llx, length %d\\n\", i, index[i],\n\t\t\t\tlength);\n\t\t\tgoto failed2;\n\t\t}\n\t}\n\n\t/*\n\t * Read and decompress the xattr metadata\n\t *\n\t * Note the first xattr id table metadata block is immediately after\n\t * the last xattr metadata block, so we can use index[0] to work out\n\t * the end of the xattr metadata\n\t */\n\tstart = xattr_table_start;\n\tend = index[0];\n\tfor(i = 0; start < end; i++) {\n\t\tint length;\n\t\tvoid *x = realloc(xattrs, (i + 1) * SQUASHFS_METADATA_SIZE);\n\t\tif(x == NULL) {\n\t\t\tERROR(\"Failed to realloc xattr data\\n\");\n\t\t\tgoto failed3;\n\t\t}\n\t\txattrs = x;\n\n\t\t/* store mapping from location of compressed block in fs ->\n\t\t * location of uncompressed block in memory */\n\t\tres = save_xattr_block(start, i * SQUASHFS_METADATA_SIZE);\n\t\tif(res == -1)\n\t\t\tgoto failed3;\n\n\t\tlength = read_block(fd, start, &start,\n\t\t\t((unsigned char *) xattrs) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read xattr block %d, length %d\\n\", i, length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read xattr block %d\\n\", i);\n\t\t\tgoto failed3;\n\t\t}\n\t}\n\n\t/* swap if necessary the xattr id entries */\n\tfor(i = 0; i < ids; i++)\n\t\tSQUASHFS_INSWAP_XATTR_ID(&xattr_ids[i]);\n\n\tfree(index);\n\n\treturn ids;\n\nfailed3:\n\tfree(xattrs);\nfailed2:\n\tfree(xattr_ids);\nfailed1:\n\tfree(index);\n\n\treturn 0;\n}\n\n\n/*\n * Construct and return the list of xattr name:value pairs for the passed xattr\n * id\n */\nstruct xattr_list *get_xattr(int i, unsigned int *count)\n{\n\tlong long start;\n\tstruct xattr_list *xattr_list = NULL;\n\tunsigned int offset;\n\tvoid *xptr;\n\tint j;\n\n\tTRACE(\"get_xattr\\n\");\n\n\t*count = xattr_ids[i].count;\n\tstart = SQUASHFS_XATTR_BLK(xattr_ids[i].xattr) + xattr_table_start;\n\toffset = SQUASHFS_XATTR_OFFSET(xattr_ids[i].xattr);\n\txptr = xattrs + get_xattr_block(start) + offset;\n\n\tTRACE(\"get_xattr: xattr_id %d, count %d, start %lld, offset %d\\n\", i,\n\t\t\t*count, start, offset);\n\n\tfor(j = 0; j < *count; j++) {\n\t\tstruct squashfs_xattr_entry entry;\n\t\tstruct squashfs_xattr_val val;\n\t\tint res;\n\n\t\txattr_list = realloc(xattr_list, (j + 1) *\n\t\t\t\t\t\tsizeof(struct xattr_list));\n\t\tif(xattr_list == NULL) {\n\t\t\tERROR(\"Out of memory in get_xattrs\\n\");\n\t\t\tgoto failed;\n\t\t}\n\t\t\t\n\t\tSQUASHFS_SWAP_XATTR_ENTRY(&entry, xptr);\n\t\txptr += sizeof(entry);\n\t\tres = read_xattr_entry(&xattr_list[j], &entry, xptr);\n\t\tif(res != 1)\n\t\t\tgoto failed;\n\t\txptr += entry.size;\n\t\t\t\n\t\tTRACE(\"get_xattr: xattr %d, type %d, size %d, name %s\\n\", j,\n\t\t\tentry.type, entry.size, xattr_list[j].full_name); \n\n\t\tif(entry.type & SQUASHFS_XATTR_VALUE_OOL) {\n\t\t\tlong long xattr;\n\t\t\tvoid *ool_xptr;\n\n\t\t\txptr += sizeof(val);\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(&xattr, xptr, 1);\n\t\t\txptr += sizeof(xattr);\t\n\t\t\tstart = SQUASHFS_XATTR_BLK(xattr) + xattr_table_start;\n\t\t\toffset = SQUASHFS_XATTR_OFFSET(xattr);\n\t\t\tool_xptr = xattrs + get_xattr_block(start) + offset;\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, ool_xptr);\n\t\t\txattr_list[j].value = ool_xptr + sizeof(val);\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, xptr);\n\t\t\txattr_list[j].value = xptr + sizeof(val);\n\t\t\txptr += sizeof(val) + val.vsize;\n\t\t}\n\n\t\tTRACE(\"get_xattr: xattr %d, vsize %d\\n\", j, val.vsize);\n\n\t\txattr_list[j].vsize = val.vsize;\n\t}\n\n\treturn xattr_list;\n\nfailed:\n\tfree(xattr_list);\n\n\treturn NULL;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include \"squashfs_fs.h\"\n#include \"mksquashfs.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...) \\\n\t\tdo { \\\n\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority,\n\t\t\t\tfilename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 ||\n\t\t\tstrncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %d, st_ino \"\n\t\t\t\"%lld\\n\", path, priority, (int) buf.st_dev,\n\t\t\t(long long) buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is \"\n\t\t\t\"supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry\");\n\t        ERROR(\" should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to \"\n\t\t\t\"$PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source \"\n\t\t\t\"directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory \"\n\t\t\t\"test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1) {\n\t\tERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more \"\n\t\t\t\"than one source entry!  Please use an absolute path.\"\n\t\t\t\"\\n\", path);\n\t\treturn FALSE;\n\t}\n\nerror:\n        ERROR(\"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        ERROR(\"This is probably because you're using the wrong file\\n\");\n        ERROR(\"path relative to the source directories\\n\");\n\t/*\n\t * Historical note\n\t * Failure to stat a sortlist entry is deliberately ignored, even\n\t * though it is an error.  Squashfs release 2.2 changed the behaviour\n\t * to treat it as a fatal error, but it was changed back to\n\t * the original behaviour to ignore it in release 2.2-r2 following\n\t * feedback from users at the time.\n\t */\n        return TRUE;\n}\n\n\nint generate_file_priorities(struct dir_info *dir, int priority,\n\tstruct stat *buf)\n{\n\tint res;\n\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->inode->root_entry)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tres = add_priority_list(dir_ent,\n\t\t\t\t\tget_priority(dir_ent->pathname, buf,\n\t\t\t\t\tpriority));\n\t\t\t\tif(res == FALSE)\n\t\t\t\t\treturn FALSE;\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tres = generate_file_priorities(dir_ent->dir,\n\t\t\t\t\tpriority, buf);\n\t\t\t\tif(res == FALSE)\n\t\t\t\t\treturn FALSE;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n\n\treturn TRUE;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint res, priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767) {\n\t\t\tres = add_sort_list(sort_filename, priority, source,\n\t\t\t\tsource_path);\n\t\t\tif(res == FALSE)\n\t\t\t\treturn FALSE;\n\t\t} else\n\t\t\tERROR(\"Sort file %s, priority %d outside range of \"\n\t\t\t\t\"-32767:32768 - skipping...\\n\", sort_filename,\n\t\t\t\tpriority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\twrite_file(&inode, entry->dir, &duplicate_file);\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\"\n\t\t\t\t\t\"\\n\", entry->dir->pathname,\n\t\t\t\t\t(long long)\n\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes \"\n\t\t\t\t\t\"LINK\\n\", entry->dir->pathname,\n\t\t\t\t\t(long long)\n\t\t\t\t\tentry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/squashfs_compat.h",
    "content": "#ifndef SQUASHFS_COMPAT\n#define SQUASHFS_COMPAT\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_compat.h\n */\n\n/*\n * definitions for structures on disk - layout 3.x\n */\n\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\nstruct squashfs_super_block_3 {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode\t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index_3 {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER_3\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tsquashfs_block\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tsquashfs_block\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index_3\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_3 {\n\tstruct squashfs_base_inode_header_3\tbase;\n\tstruct squashfs_dev_inode_header_3\tdev;\n\tstruct squashfs_symlink_inode_header_3\tsymlink;\n\tstruct squashfs_reg_inode_header_3\treg;\n\tstruct squashfs_lreg_inode_header_3\tlreg;\n\tstruct squashfs_dir_inode_header_3\tdir;\n\tstruct squashfs_ldir_inode_header_3\tldir;\n\tstruct squashfs_ipc_inode_header_3\tipc;\n};\n\t\nstruct squashfs_dir_entry_3 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header_3 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_3 {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\n\ntypedef struct squashfs_super_block_3 squashfs_super_block_3;\ntypedef struct squashfs_dir_index_3 squashfs_dir_index_3;\ntypedef struct squashfs_base_inode_header_3 squashfs_base_inode_header_3;\ntypedef struct squashfs_ipc_inode_header_3 squashfs_ipc_inode_header_3;\ntypedef struct squashfs_dev_inode_header_3 squashfs_dev_inode_header_3;\ntypedef struct squashfs_symlink_inode_header_3 squashfs_symlink_inode_header_3;\ntypedef struct squashfs_reg_inode_header_3 squashfs_reg_inode_header_3;\ntypedef struct squashfs_lreg_inode_header_3 squashfs_lreg_inode_header_3;\ntypedef struct squashfs_dir_inode_header_3 squashfs_dir_inode_header_3;\ntypedef struct squashfs_ldir_inode_header_3 squashfs_ldir_inode_header_3;\ntypedef struct squashfs_dir_entry_3 squashfs_dir_entry_3;\ntypedef struct squashfs_dir_header_3 squashfs_dir_header_3;\ntypedef struct squashfs_fragment_entry_3 squashfs_fragment_entry_3;\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block_3));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_3(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_3))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_3)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_3));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_3));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_3));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T_3(s, d) SQUASHFS_SWAP_LONG_LONGS_3(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_3));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_3(A)\t((A) * sizeof(struct squashfs_fragment_entry_3))\n\n#define SQUASHFS_FRAGMENT_INDEX_3(A)\t(SQUASHFS_FRAGMENT_BYTES_3(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_3(A)\t(SQUASHFS_FRAGMENT_BYTES_3(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_3(A)\t((SQUASHFS_FRAGMENT_BYTES_3(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_3(A)\t(SQUASHFS_FRAGMENT_INDEXES_3(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/*\n * definitions for structures on disk - layout 1.x\n */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n/*\n * definitions for structures on disk - layout 2.x\n */\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS_3(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t((A) * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t4\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/*\n * Squashfs + LZMA\n */\n\n#define SQUASHFS_MAGIC_LZMA\t\t0x71736873\n#define SQUASHFS_MAGIC_LZMA_SWAP\t0x73687371\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_IDS\t\t\t65536\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_XATTR\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n#define SQUASHFS_NOX\t\t\t8\n#define SQUASHFS_NO_XATTR\t\t9\n#define SQUASHFS_COMP_OPT\t\t10\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_UNCOMPRESSED_XATTRS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOX)\n\n#define SQUASHFS_NO_XATTRS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_XATTR)\n\n#define SQUASHFS_COMP_OPTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_COMP_OPT)\n\n#define SQUASHFS_MKFLAGS(noi, nod, nof, nox, no_frag, always_frag, \\\n\t\tduplicate_checking, exportable, no_xattr, comp_opt) (noi | \\\n\t\t(nod << 1) | (nof << 3) | (no_frag << 4) | \\\n\t\t(always_frag << 5) | (duplicate_checking << 6) | \\\n\t\t(exportable << 7) | (nox << 8) | (no_xattr << 9) | \\\n\t\t(comp_opt << 10))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n#define SQUASHFS_LSYMLINK_TYPE\t\t10\n#define SQUASHFS_LBLKDEV_TYPE\t\t11\n#define SQUASHFS_LCHRDEV_TYPE\t\t12\n#define SQUASHFS_LFIFO_TYPE\t\t13\n#define SQUASHFS_LSOCKET_TYPE\t\t14\n\n/* Xattr types */\n#define SQUASHFS_XATTR_USER\t\t0\n#define SQUASHFS_XATTR_TRUSTED\t\t1\n#define SQUASHFS_XATTR_SECURITY\t\t2\n#define SQUASHFS_XATTR_VALUE_OOL\t256\n#define SQUASHFS_XATTR_PREFIX_MASK\t0xff\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode)(((squashfs_inode) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* uid lookup table defines */\n#define SQUASHFS_ID_BYTES(A)\t((A) * sizeof(unsigned int))\n\n#define SQUASHFS_ID_BLOCK(A)\t\t(SQUASHFS_ID_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCK_OFFSET(A)\t\t(SQUASHFS_ID_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCKS(A)\t((SQUASHFS_ID_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCK_BYTES(A)\t(SQUASHFS_ID_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* xattr id lookup table defines */\n#define SQUASHFS_XATTR_BYTES(A)\t\t((A) * sizeof(struct squashfs_xattr_id))\n\n#define SQUASHFS_XATTR_BLOCK(A)\t\t(SQUASHFS_XATTR_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_XATTR_BLOCK_OFFSET(A)\t(SQUASHFS_XATTR_BYTES(A) % \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_XATTR_BLOCKS(A)\t((SQUASHFS_XATTR_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_XATTR_BLOCK_BYTES(A)\t(SQUASHFS_XATTR_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n#define SQUASHFS_XATTR_BLK(A)\t\t((unsigned int) ((A) >> 16))\n\n#define SQUASHFS_XATTR_OFFSET(A)\t((unsigned int) ((A) & 0xffff))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block;\ntypedef long long\t\tsquashfs_inode;\n\n#define ZLIB_COMPRESSION\t1\n#define LZMA_COMPRESSION\t2\n#define LZO_COMPRESSION\t\t3\n#define XZ_COMPRESSION\t\t4\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned short\t\tcompression;\n\tunsigned short\t\tblock_log;\n\tunsigned short\t\tflags;\n\tunsigned short\t\tno_ids;\n\tunsigned short\t\ts_major;\n\tunsigned short\t\ts_minor;\n\tsquashfs_inode\t\troot_inode;\n\tlong long\t\tbytes_used;\n\tlong long\t\tid_table_start;\n\tlong long\t\txattr_id_table_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n};\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\tname[0];\n};\n\nstruct squashfs_base_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n};\n\nstruct squashfs_ipc_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n};\n\nstruct squashfs_lipc_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\txattr;\n};\n\nstruct squashfs_dev_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\trdev;\n};\n\t\nstruct squashfs_ldev_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\trdev;\n\tunsigned int\t\txattr;\n};\n\t\nstruct squashfs_symlink_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n};\n\nstruct squashfs_reg_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned int\t\tblock_list[0];\n};\n\nstruct squashfs_lreg_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tsquashfs_block\t\tstart_block;\n\tlong long\t\tfile_size;\n\tlong long\t\tsparse;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\txattr;\n\tunsigned int\t\tblock_list[0];\n};\n\nstruct squashfs_dir_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tfile_size;\n\tunsigned short\t\toffset;\n\tunsigned int\t\tparent_inode;\n};\n\nstruct squashfs_ldir_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n\tunsigned short\t\ti_count;\n\tunsigned short\t\toffset;\n\tunsigned int\t\txattr;\n\tstruct squashfs_dir_index\tindex[0];\n};\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_ldev_inode_header\tldev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n\tstruct squashfs_lipc_inode_header\tlipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned short\t\toffset;\n\tshort\t\t\tinode_number;\n\tunsigned short\t\ttype;\n\tunsigned short\t\tsize;\n\tchar\t\t\tname[0];\n};\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n};\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tunused;\n};\n\nstruct squashfs_xattr_entry {\n\tunsigned short\t\ttype;\n\tunsigned short\t\tsize;\n\tchar\t\t\tdata[0];\n};\n\nstruct squashfs_xattr_val {\n\tunsigned int\t\tvsize;\n\tchar\t\t\tvalue[0];\n};\n\nstruct squashfs_xattr_id {\n\tlong long\t\txattr;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tsize;\n};\n\nstruct squashfs_xattr_table {\n\tlong long\t\txattr_table_start;\n\tunsigned int\t\txattr_ids;\n\tunsigned int\t\tunused;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/squashfs_swap.h",
    "content": "#ifndef SQUASHFS_SWAP_H\n#define SQUASHFS_SWAP_H\n/*\n * Squashfs\n *\n * Copyright (c) 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_swap.h\n */\n\n/*\n * macros to convert each stucture from big endian to little endian\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#include <stddef.h>\nextern void swap_le16(void *, void *);\nextern void swap_le32(void *, void *);\nextern void swap_le64(void *, void *);\nextern void swap_le16_num(void *, void *, int);\nextern void swap_le32_num(void *, void *, int);\nextern void swap_le64_num(void *, void *, int);\nextern unsigned short inswap_le16(unsigned short);\nextern unsigned int inswap_le32(unsigned int);\nextern long long inswap_le64(long long);\nextern void inswap_le16_num(unsigned short *, int);\nextern void inswap_le32_num(unsigned int *, int);\nextern void inswap_le64_num(long long *, int);\n\n#define _SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(32, s, d, s_magic, struct squashfs_super_block);\\\n\tSWAP_FUNC(32, s, d, inodes, struct squashfs_super_block);\\\n\tSWAP_FUNC(32, s, d, mkfs_time, struct squashfs_super_block);\\\n\tSWAP_FUNC(32, s, d, block_size, struct squashfs_super_block);\\\n\tSWAP_FUNC(32, s, d, fragments, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, compression, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, block_log, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, flags, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, no_ids, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, s_major, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, s_minor, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, root_inode, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, bytes_used, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, id_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, xattr_id_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, inode_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, directory_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, fragment_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, lookup_table_start, struct squashfs_super_block);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(32, s, d, index, struct squashfs_dir_index);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_dir_index);\\\n\tSWAP_FUNC(32, s, d, size, struct squashfs_dir_index);\\\n}\n\n#define _SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_base_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_ipc_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, xattr, struct squashfs_lipc_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(32, s, d, rdev, struct squashfs_dev_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, rdev, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, xattr, struct squashfs_ldev_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(32, s, d, symlink_size, struct squashfs_symlink_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, fragment, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, offset, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, file_size, struct squashfs_reg_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(64, s, d, start_block, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(64, s, d, file_size, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(64, s, d, sparse, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, fragment, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, offset, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, xattr, struct squashfs_lreg_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, file_size, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, offset, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, parent_inode, struct squashfs_dir_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, file_size, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, parent_inode, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, i_count, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, offset, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, xattr, struct squashfs_ldir_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, offset, struct squashfs_dir_entry);\\\n\tSWAP_FUNC##S(16, s, d, inode_number, struct squashfs_dir_entry);\\\n\tSWAP_FUNC(16, s, d, type, struct squashfs_dir_entry);\\\n\tSWAP_FUNC(16, s, d, size, struct squashfs_dir_entry);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(32, s, d, count, struct squashfs_dir_header);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_dir_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_dir_header);\\\n}\n\n#define _SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(64, s, d, start_block, struct squashfs_fragment_entry);\\\n\tSWAP_FUNC(32, s, d, size, struct squashfs_fragment_entry);\\\n}\n\n#define _SQUASHFS_SWAP_XATTR_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, type, struct squashfs_xattr_entry);\\\n\tSWAP_FUNC(16, s, d, size, struct squashfs_xattr_entry);\\\n}\n\n#define _SQUASHFS_SWAP_XATTR_VAL(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(32, s, d, vsize, struct squashfs_xattr_val);\\\n}\n\n#define _SQUASHFS_SWAP_XATTR_ID(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(64, s, d, xattr, struct squashfs_xattr_id);\\\n\tSWAP_FUNC(32, s, d, count, struct squashfs_xattr_id);\\\n\tSWAP_FUNC(32, s, d, size, struct squashfs_xattr_id);\\\n}\n\n#define _SQUASHFS_SWAP_XATTR_TABLE(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(64, s, d, xattr_table_start, struct squashfs_xattr_table);\\\n\tSWAP_FUNC(32, s, d, xattr_ids, struct squashfs_xattr_table);\\\n}\n\n/* big endian architecture copy and swap macros */\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d)\t\\\n\t\t\t_SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \\\n\t\t\t_SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_XATTR_ENTRY(s, d) \\\n\t\t\t _SQUASHFS_SWAP_XATTR_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_XATTR_VAL(s, d) \\\n\t\t\t_SQUASHFS_SWAP_XATTR_VAL(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_XATTR_ID(s, d) \\\n\t\t\t _SQUASHFS_SWAP_XATTR_ID(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_XATTR_TABLE(s, d) \\\n\t\t\t_SQUASHFS_SWAP_XATTR_TABLE(s, d, SWAP_LE)\n#define SWAP_LE(bits, s, d, field, type) \\\n\t\t\tSWAP_LE##bits(((void *)(s)) + offsetof(type, field), \\\n\t\t\t\t((void *)(d)) + offsetof(type, field))\n#define SWAP_LES(bits, s, d, field, type) \\\n\t\t\tSWAP_LE(bits, s, d, field, type)\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) \\\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n/* big endian architecture swap in-place macros */\n#define SQUASHFS_INSWAP_SUPER_BLOCK(s) \\\n\t\t\t_SQUASHFS_SWAP_SUPER_BLOCK(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_INDEX(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INDEX(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_BASE_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_BASE_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_IPC_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_IPC_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LIPC_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LIPC_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DEV_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DEV_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LDEV_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LDEV_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_REG_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_REG_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LREG_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LREG_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LDIR_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_ENTRY(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_ENTRY(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s) \\\n\t\t\t_SQUASHFS_SWAP_FRAGMENT_ENTRY(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_XATTR_ENTRY(s) \\\n\t\t\t _SQUASHFS_SWAP_XATTR_ENTRY(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_XATTR_VAL(s) \\\n\t\t\t_SQUASHFS_SWAP_XATTR_VAL(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_XATTR_ID(s) \\\n\t\t\t _SQUASHFS_SWAP_XATTR_ID(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_XATTR_TABLE(s) \\\n\t\t\t_SQUASHFS_SWAP_XATTR_TABLE(s, s, INSWAP_LE)\n#define INSWAP_LE(bits, s, d, field, type) \\\n\t\t\t(s)->field = inswap_le##bits((s)->field)\n#define INSWAP_LES(bits, s, d, field, type) \\\n\t\t\t(s)->field = (short) inswap_le##bits((unsigned short) \\\n\t\t\t\t(s)->field)\n#define SQUASHFS_INSWAP_INODE_T(s) s = inswap_le64(s)\n#define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_ID_BLOCKS(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_SHORTS(s, n) inswap_le16_num(s, n)\n#define SQUASHFS_INSWAP_INTS(s, n) inswap_le32_num(s, n)\n#define SQUASHFS_INSWAP_LONG_LONGS(s, n) inswap_le64_num(s, n)\n#else\n/* little endian architecture, just copy */\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d)\t\\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_XATTR_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_XATTR_VAL(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_XATTR_ID(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_XATTR_TABLE(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) \\\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n/* little endian architecture, data already in place so do nothing */\n#define SQUASHFS_INSWAP_SUPER_BLOCK(s)\n#define SQUASHFS_INSWAP_DIR_INDEX(s)\n#define SQUASHFS_INSWAP_BASE_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_IPC_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LIPC_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DEV_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LDEV_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_REG_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LREG_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DIR_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DIR_ENTRY(s)\n#define SQUASHFS_INSWAP_DIR_HEADER(s)\n#define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s)\n#define SQUASHFS_INSWAP_XATTR_ENTRY(s)\n#define SQUASHFS_INSWAP_XATTR_VAL(s)\n#define SQUASHFS_INSWAP_XATTR_ID(s)\n#define SQUASHFS_INSWAP_XATTR_TABLE(s)\n#define SQUASHFS_INSWAP_INODE_T(s)\n#define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n)\n#define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n)\n#define SQUASHFS_INSWAP_ID_BLOCKS(s, n)\n#define SQUASHFS_INSWAP_SHORTS(s, n)\n#define SQUASHFS_INSWAP_INTS(s, n)\n#define SQUASHFS_INSWAP_LONG_LONGS(s, n)\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/swap.c",
    "content": "/*\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * swap.c\n */\n\n#ifndef linux\n#ifndef __CYGWIN__\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#endif\n#else\n#include <endian.h>\n#endif\n\n#if __BYTE_ORDER == __BIG_ENDIAN\nvoid swap_le16(void *src, void *dest)\n{\n\tunsigned char *s = src;\n\tunsigned char *d = dest;\n\n\td[0] = s[1];\n\td[1] = s[0];\n}\n\n\nvoid swap_le32(void *src, void *dest)\n{\n\tunsigned char *s = src;\n\tunsigned char *d = dest;\n\n\td[0] = s[3];\n\td[1] = s[2];\n\td[2] = s[1];\n\td[3] = s[0];\n}\n\n\nvoid swap_le64(void *src, void *dest)\n{\n\tunsigned char *s = src;\n\tunsigned char *d = dest;\n\n\td[0] = s[7];\n\td[1] = s[6];\n\td[2] = s[5];\n\td[3] = s[4];\n\td[4] = s[3];\n\td[5] = s[2];\n\td[6] = s[1];\n\td[7] = s[0];\n}\n\n\nunsigned short inswap_le16(unsigned short num)\n{\n\treturn (num >> 8) |\n\t\t((num & 0xff) << 8);\n}\n\n\nunsigned int inswap_le32(unsigned int num)\n{\n\treturn (num >> 24) |\n\t\t((num & 0xff0000) >> 8) |\n\t\t((num & 0xff00) << 8) |\n\t\t((num & 0xff) << 24);\n}\n\n\nlong long inswap_le64(long long n)\n{\n\tunsigned long long num = n;\n\n\treturn (num >> 56) |\n\t\t((num & 0xff000000000000LL) >> 40) |\n\t\t((num & 0xff0000000000LL) >> 24) |\n\t\t((num & 0xff00000000LL) >> 8) |\n\t\t((num & 0xff000000) << 8) |\n\t\t((num & 0xff0000) << 24) |\n\t\t((num & 0xff00) << 40) |\n\t\t((num & 0xff) << 56);\n}\n\n\n#define SWAP_LE_NUM(BITS) \\\nvoid swap_le##BITS##_num(void *s, void *d, int n) \\\n{\\\n\tint i;\\\n\tfor(i = 0; i < n; i++, s += BITS / 8, d += BITS / 8)\\\n\t\tswap_le##BITS(s, d);\\\n}\n\nSWAP_LE_NUM(16)\nSWAP_LE_NUM(32)\nSWAP_LE_NUM(64)\n\n#define INSWAP_LE_NUM(BITS, TYPE) \\\nvoid inswap_le##BITS##_num(TYPE *s, int n) \\\n{\\\n\tint i;\\\n\tfor(i = 0; i < n; i++)\\\n\t\ts[i] = inswap_le##BITS(s[i]);\\\n}\n\nINSWAP_LE_NUM(16, unsigned short)\nINSWAP_LE_NUM(32, unsigned int)\nINSWAP_LE_NUM(64, long long)\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/unsquash-1.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-1.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nvoid read_block_list_1(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tTRACE(\"read_block_list: blocks %d\\n\", blocks);\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS_3((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) |\n\t\t\t(SQUASHFS_COMPRESSED(block_size) ? 0 :\n\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nint read_fragment_table_1()\n{\n\tTRACE(\"read_fragment_table\\n\");\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic union squashfs_inode_header_1 header;\n\tlong long start = sBlk.s.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"read_inode: inode table block %lld not found\\n\",\n\t\t\t start); \n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[(header.base.inode_type - 1) /\n\t\tSQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) %\n\t\t\tSQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n\n\ti.xattr = SQUASHFS_INVALID_XATTR;\n\ti.gid = header.base.guid == 15 ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.s.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (i.data + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\ti.sparse = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_1),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tEXIT_UNSQUASH(\"Unknown inode type %d in \"\n\t\t\t\t\" read_inode_header_1!\\n\",\n\t\t\t\theader.base.inode_type);\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_1(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1]\n\t\t__attribute__((aligned));\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\t*i = s_ops.read_inode(block_start, offset);\n\tstart = sBlk.s.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: directory block %d not \"\n\t\t\t\"found!\\n\", block_start);\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes;\n\n\tdir = malloc(sizeof(struct dir));\n\tif(dir == NULL)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: malloc failed!\\n\");\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->xattr = (*i)->xattr;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes,\n\t\t\t\t\tsizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes,\n\t\t\t\t\tsizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL)\n\t\t\t\t\tEXIT_UNSQUASH(\"squashfs_opendir: \"\n\t\t\t\t\t\t\"realloc failed!\\n\");\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint read_uids_guids_1()\n{\n\tint res;\n\n\tTRACE(\"read_uids_guids: no_uids %d, no_guids %d\\n\", sBlk.no_uids,\n\t\tsBlk.no_guids);\n\n\tuid_table = malloc((sBlk.no_uids + sBlk.no_guids) *\n\t\tsizeof(unsigned int));\n\tif(uid_table == NULL) {\n\t\tERROR(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\t\treturn FALSE;\n\t}\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tres = read_fs_bytes(fd, sBlk.uid_start, (sBlk.no_uids +\n\t\t\tsBlk.no_guids) * sizeof(unsigned int), suid_table);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read uid/gid table\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_INTS_3(uid_table, suid_table,\n\t\t\tsBlk.no_uids + sBlk.no_guids);\n\t} else {\n\t\tres = read_fs_bytes(fd, sBlk.uid_start, (sBlk.no_uids +\n\t\t\tsBlk.no_guids) * sizeof(unsigned int), uid_table);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read uid/gid table\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/unsquash-2.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-2.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nstatic squashfs_fragment_entry_2 *fragment_table;\n\nvoid read_block_list_2(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tTRACE(\"read_block_list: blocks %d\\n\", blocks);\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS_3(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nint read_fragment_table_2()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.s.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.s.fragments, indexes,\n\t\tsBlk.s.fragment_table_start);\n\n\tif(sBlk.s.fragments == 0)\n\t\treturn TRUE;\n\n\tfragment_table = malloc(sBlk.s.fragments *\n\t\tsizeof(squashfs_fragment_entry_2));\n\tif(fragment_table == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\t res = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.s.fragments),\n\t\t\tsfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index,\n\t\t\tsfragment_table_index, indexes);\n\t} else {\n\t\tres = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.s.fragments),\n\t\t\tfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%x, length %d\\n\", i,\n\t\t\tfragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table block\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.s.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment),\n\t\t\t\t(&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment,\n\t\t\t\tsizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_2(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic union squashfs_inode_header_2 header;\n\tlong long start = sBlk.s.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"read_inode: inode table block %lld not found\\n\",\n\t\t\tstart); \n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.xattr = SQUASHFS_INVALID_XATTR;\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.s.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr,\n\t\t\t\t\tsizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr,\n\t\t\t\t\tsizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(i.data + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log : i.data >>\n\t\t\t\tsBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_2),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tEXIT_UNSQUASH(\"Unknown inode type %d in \"\n\t\t\t\t\"read_inode_header_2!\\n\",\n\t\t\t\theader.base.inode_type);\n\t}\n\treturn &i;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/unsquash-3.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-3.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nstatic squashfs_fragment_entry_3 *fragment_table;\n\nint read_fragment_table_3()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES_3(sBlk.s.fragments);\n\tlong long fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.s.fragments, indexes,\n\t\tsBlk.s.fragment_table_start);\n\n\tif(sBlk.s.fragments == 0)\n\t\treturn TRUE;\n\n\tfragment_table = malloc(sBlk.s.fragments *\n\t\tsizeof(squashfs_fragment_entry_3));\n\tif(fragment_table == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tif(swap) {\n\t\tlong long sfragment_table_index[indexes];\n\n\t\tres = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.s.fragments),\n\t\t\tsfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_3(fragment_table_index,\n\t\t\tsfragment_table_index, indexes);\n\t} else {\n\t\tres = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.s.fragments),\n\t\t\tfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table block\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_3 sfragment;\n\t\tfor(i = 0; i < sBlk.s.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_3((&sfragment),\n\t\t\t\t(&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment,\n\t\t\t\tsizeof(squashfs_fragment_entry_3));\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_3(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_3 *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_3(unsigned int start_block, unsigned int offset)\n{\n\tstatic union squashfs_inode_header_3 header;\n\tlong long start = sBlk.s.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"read_inode: inode table block %lld not found\\n\",\n\t\t\tstart); \n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_3 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_3(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_3));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.xattr = SQUASHFS_INVALID_XATTR;\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_3 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_3(&header.dir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr,\n\t\t\t\t\tsizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_3 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_3(&header.ldir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr,\n\t\t\t\t\tsizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_3 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_3(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(i.data + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log :\n\t\t\t\ti.data >> sBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 1;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header_3 *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER_3(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log :\n\t\t\t\tinode->file_size >> sBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 1;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_3 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_3 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_3),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_3 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_3 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_3(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tEXIT_UNSQUASH(\"Unknown inode type %d in read_inode!\\n\",\n\t\t\t\theader.base.inode_type);\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_3(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header_3 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_3) + SQUASHFS_NAME_LEN + 1]\n\t\t__attribute__((aligned));\n\tsquashfs_dir_entry_3 *dire = (squashfs_dir_entry_3 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\t*i = s_ops.read_inode(block_start, offset);\n\tstart = sBlk.s.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: directory block %d not \"\n\t\t\t\"found!\\n\", block_start);\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tdir = malloc(sizeof(struct dir));\n\tif(dir == NULL)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: malloc failed!\\n\");\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->xattr = (*i)->xattr;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_3 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_3(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_3 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes,\n\t\t\t\t\tsizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_3(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes,\n\t\t\t\t\tsizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL)\n\t\t\t\t\tEXIT_UNSQUASH(\"squashfs_opendir: \"\n\t\t\t\t\t\t\"realloc failed!\\n\");\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/unsquash-4.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-4.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n\nstatic struct squashfs_fragment_entry *fragment_table;\nstatic unsigned int *id_table;\n\nint read_fragment_table_4()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.s.fragments);\n\tlong long fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.s.fragments, indexes,\n\t\tsBlk.s.fragment_table_start);\n\n\tif(sBlk.s.fragments == 0)\n\t\treturn TRUE;\n\n\tfragment_table = malloc(sBlk.s.fragments *\n\t\tsizeof(struct squashfs_fragment_entry));\n\tif(fragment_table == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tres = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\tSQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.s.fragments),\n\t\tfragment_table_index);\n\tif(res == FALSE) {\n\t\tERROR(\"read_fragment_table: failed to read fragment table \"\n\t\t\t\"index\\n\");\n\t\treturn FALSE;\n\t}\n\tSQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < sBlk.s.fragments; i++) \n\t\tSQUASHFS_INSWAP_FRAGMENT_ENTRY(&fragment_table[i]);\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_4(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tstruct squashfs_fragment_entry *fragment_entry;\n\n\tfragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_4(unsigned int start_block, unsigned int offset)\n{\n\tstatic union squashfs_inode_header header;\n\tlong long start = sBlk.s.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"read_inode: inode table block %lld not found\\n\",\n\t\t\tstart); \t\t\n\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, block_ptr);\n\n\ti.uid = (uid_t) id_table[header.base.uid];\n\ti.gid = (uid_t) id_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tstruct squashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tstruct squashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.xattr = inode->xattr;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tstruct squashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(i.data + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log :\n\t\t\t\ti.data >> sBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tstruct squashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log :\n\t\t\t\tinode->file_size >> sBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = inode->sparse != 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.xattr = inode->xattr;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\tcase SQUASHFS_LSYMLINK_TYPE: {\n\t\t\tstruct squashfs_symlink_inode_header *inode = &header.symlink;\n\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.symlink = malloc(inode->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(struct squashfs_symlink_inode_header),\n\t\t\t\tinode->symlink_size);\n\t\t\ti.symlink[inode->symlink_size] = '\\0';\n\t\t\ti.data = inode->symlink_size;\n\n\t\t\tif(header.base.inode_type == SQUASHFS_LSYMLINK_TYPE)\n\t\t\t\tSQUASHFS_SWAP_INTS(&i.xattr, block_ptr +\n\t\t\t\t\tsizeof(struct squashfs_symlink_inode_header) +\n\t\t\t\t\tinode->symlink_size, 1);\n\t\t\telse\n\t\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tstruct squashfs_dev_inode_header *inode = &header.dev;\n\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->rdev;\n\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_LBLKDEV_TYPE:\n\t \tcase SQUASHFS_LCHRDEV_TYPE: {\n\t\t\tstruct squashfs_ldev_inode_header *inode = &header.ldev;\n\n\t\t\tSQUASHFS_SWAP_LDEV_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->rdev;\n\t\t\ti.xattr = inode->xattr;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LFIFO_TYPE:\n\t\tcase SQUASHFS_LSOCKET_TYPE: {\n\t\t\tstruct squashfs_lipc_inode_header *inode = &header.lipc;\n\n\t\t\tSQUASHFS_SWAP_LIPC_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = 0;\n\t\t\ti.xattr = inode->xattr;\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t\tEXIT_UNSQUASH(\"Unknown inode type %d in read_inode!\\n\",\n\t\t\t\theader.base.inode_type);\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_4(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tstruct squashfs_dir_header dirh;\n\tchar buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1]\n\t\t__attribute__((aligned));\n\tstruct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\t*i = s_ops.read_inode(block_start, offset);\n\tstart = sBlk.s.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: directory block %d not \"\n\t\t\t\"found!\\n\", block_start);\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tdir = malloc(sizeof(struct dir));\n\tif(dir == NULL)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: malloc failed!\\n\");\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->xattr = (*i)->xattr;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, directory_table + bytes);\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, directory_table + bytes);\n\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL)\n\t\t\t\t\tEXIT_UNSQUASH(\"squashfs_opendir: \"\n\t\t\t\t\t\t\"realloc failed!\\n\");\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint read_uids_guids_4()\n{\n\tint res, i, indexes = SQUASHFS_ID_BLOCKS(sBlk.s.no_ids);\n\tlong long id_index_table[indexes];\n\n\tTRACE(\"read_uids_guids: no_ids %d\\n\", sBlk.s.no_ids);\n\n\tid_table = malloc(SQUASHFS_ID_BYTES(sBlk.s.no_ids));\n\tif(id_table == NULL) {\n\t\tERROR(\"read_uids_guids: failed to allocate id table\\n\");\n\t\treturn FALSE;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk.s.id_table_start,\n\t\tSQUASHFS_ID_BLOCK_BYTES(sBlk.s.no_ids), id_index_table);\n\tif(res == FALSE) {\n\t\tERROR(\"read_uids_guids: failed to read id index table\\n\");\n\t\treturn FALSE;\n\t}\n\tSQUASHFS_INSWAP_ID_BLOCKS(id_index_table, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tres = read_block(fd, id_index_table[i], NULL,\n\t\t\t((char *) id_table) + i * SQUASHFS_METADATA_SIZE);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read id table block\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_INTS(id_table, sBlk.s.no_ids);\n\n\treturn TRUE;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_swap.h\"\n#include \"squashfs_compat.h\"\n#include \"read_fs.h\"\n#include \"compressor.h\"\n#include \"xattr.h\"\n\n#include <sys/types.h>\n\nstruct cache *fragment_cache, *data_cache;\nstruct queue *to_reader, *to_deflate, *to_writer, *from_writer;\npthread_t *thread, *deflator_thread;\npthread_mutex_t\tfragment_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n\nstruct super_block sBlk;\nsquashfs_operations s_ops;\nstruct compressor *comp;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nunsigned int block_log;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE;\nint use_regex = FALSE;\nchar **created_inode;\nint root_process;\nint columns;\nint rotate = 0;\npthread_mutex_t\tscreen_mutex;\npthread_cond_t progress_wait;\nint progress = TRUE, progress_enabled = FALSE;\nunsigned int total_blocks = 0, total_files = 0, total_inodes = 0;\nunsigned int cur_blocks = 0;\nint inode_number = 1;\nint no_xattrs = XATTR_DEF;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0}\n};\n\nvoid progress_bar(long long current, long long max, int columns);\nvoid update_progress_bar();\n\nvoid sigwinch_handler()\n{\n#ifndef __CYGWIN__\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n#else\n\tcolumns = 80;\n#endif\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in queue_init\\n\");\n\n\tqueue->data = malloc(sizeof(void *) * (size + 1));\n\tif(queue->data == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in queue_init\\n\");\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tint hash = CALCULATE_HASH(entry->block);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->block)] =\n\t\t\tentry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(cache->free_list) {\n\t\tentry->free_next = cache->free_list;\n\t\tentry->free_prev = cache->free_list->free_prev;\n\t\tcache->free_list->free_prev->free_next = entry;\n\t\tcache->free_list->free_prev = entry;\n\t} else {\n\t\tcache->free_list = entry;\n\t\tentry->free_prev = entry->free_next = entry;\n\t}\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->free_prev == NULL && entry->free_next == NULL)\n\t\t/* not in free list */\n\t\treturn;\n\telse if(entry->free_prev == entry && entry->free_next == entry) {\n\t\t/* only this entry in the free list */\n\t\tcache->free_list = NULL;\n\t} else {\n\t\t/* more than one entry in the free list */\n\t\tentry->free_next->free_prev = entry->free_prev;\n\t\tentry->free_prev->free_next = entry->free_next;\n\t\tif(cache->free_list == entry)\n\t\t\tcache->free_list = entry->free_next;\n\t}\n\n\tentry->free_prev = entry->free_next = NULL;\n}\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in cache_init\\n\");\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct cache_entry *) * 65536);\n\tcache->wait_free = FALSE;\n\tcache->wait_pending = FALSE;\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\tpthread_cond_init(&cache->wait_for_pending, NULL);\n\n\treturn cache;\n}\n\n\nstruct cache_entry *cache_get(struct cache *cache, long long block, int size)\n{\n\t/*\n\t * Get a block out of the cache.  If the block isn't in the cache\n \t * it is added and queued to the reader() and deflate() threads for\n \t * reading off disk and decompression.  The cache grows until max_blocks\n \t * is reached, once this occurs existing discarded blocks on the free\n \t * list are reused\n \t */\n\tint hash = CALCULATE_HASH(block);\n\tstruct cache_entry *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->block == block)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/*\n \t\t * found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(cache, entry);\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t} else {\n\t\t/*\n \t\t * not in the cache\n\t\t *\n\t\t * first try to allocate new block\n\t\t */\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\tentry = malloc(sizeof(struct cache_entry));\n\t\t\tif(entry == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in cache_get\\n\");\n\t\t\tentry->data = malloc(cache->buffer_size);\n\t\t\tif(entry->data == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in cache_get\\n\");\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t} else {\n\t\t\t/*\n\t\t\t * try to get from free list\n\t\t\t */\n\t\t\twhile(cache->free_list == NULL) {\n\t\t\t\tcache->wait_free = TRUE;\n\t\t\t\tpthread_cond_wait(&cache->wait_for_free,\n\t\t\t\t\t&cache->mutex);\n\t\t\t}\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(cache, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t}\n\n\t\t/*\n\t\t * initialise block and insert into the hash table\n\t\t */\n\t\tentry->block = block;\n\t\tentry->size = size;\n\t\tentry->used = 1;\n\t\tentry->error = FALSE;\n\t\tentry->pending = TRUE;\n\t\tinsert_hash_table(cache, entry);\n\n\t\t/*\n\t\t * queue to read thread to read and ultimately (via the\n\t\t * decompress threads) decompress the buffer\n \t\t */\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t\tqueue_put(to_reader, entry);\n\t}\n\n\treturn entry;\n}\n\n\t\nvoid cache_block_ready(struct cache_entry *entry, int error)\n{\n\t/*\n\t * mark cache entry as being complete, reading and (if necessary)\n \t * decompression has taken place, and the buffer is valid for use.\n \t * If an error occurs reading or decompressing, the buffer also \n \t * becomes ready but with an error...\n \t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\tentry->pending = FALSE;\n\tentry->error = error;\n\n\t/*\n\t * if the wait_pending flag is set, one or more threads may be waiting\n\t * on this buffer\n\t */\n\tif(entry->cache->wait_pending) {\n\t\tentry->cache->wait_pending = FALSE;\n\t\tpthread_cond_broadcast(&entry->cache->wait_for_pending);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_wait(struct cache_entry *entry)\n{\n\t/*\n\t * wait for this cache entry to become ready, when reading and (if\n\t * necessary) decompression has taken place\n\t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\twhile(entry->pending) {\n\t\tentry->cache->wait_pending = TRUE;\n\t\tpthread_cond_wait(&entry->cache->wait_for_pending,\n\t\t\t&entry->cache->mutex);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_put(struct cache_entry *entry)\n{\n\t/*\n\t * finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and is put onto the free list.  As it remains\n \t * accessible via the hash table it can be found getting a new lease of\n \t * life before it is reused.\n \t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tinsert_free_list(entry->cache, entry);\n\n\t\t/*\n\t\t * if the wait_free flag is set, one or more threads may be\n\t\t * waiting on this buffer\n\t\t */\n\t\tif(entry->cache->wait_free) {\n\t\t\tentry->cache->wait_free = FALSE;\n\t\t\tpthread_cond_broadcast(&entry->cache->wait_for_free);\n\t\t}\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\tuser = getpwuid(inode->uid);\n\tif(user == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tgroup = getgrgid(inode->gid);\n\tif(group == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) -\n\t\t\t\tstrlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0,\n\t\t\t\tinode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) -\n\t\t\t\tstrlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \",\n\t\t\t\t(int) inode->data >> 8, (int) inode->data &\n\t\t\t\t0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1,\n\t\tt->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n\nvoid add_entry(struct hash_table_entry *hash_table[], long long start,\n\tint bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\thash_table_entry = malloc(sizeof(struct hash_table_entry));\n\tif(hash_table_entry == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in add_entry\\n\");\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], long long start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_fs_bytes(int fd, long long byte, int bytes, void *buff)\n{\n\toff_t off = byte;\n\tint res, count;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte,\n\t\tbytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = read(fd, buff + count, bytes - count);\n\t\tif(res < 1) {\n\t\t\tif(res == 0) {\n\t\t\t\tERROR(\"Read on filesystem failed because \"\n\t\t\t\t\t\"EOF\\n\");\n\t\t\t\treturn FALSE;\n\t\t\t} else if(errno != EINTR) {\n\t\t\t\tERROR(\"Read on filesystem failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn FALSE;\n\t\t\t} else\n\t\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(int fd, long long start, long long *next, void *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_fs_bytes(fd, start, 2, &c_byte) == FALSE)\n\t\t\tgoto failed;\n\t\tc_byte = (c_byte >> 8) | ((c_byte & 0xff) << 8);\n\t} else \n\t\tif(read_fs_bytes(fd, start, 2, &c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start,\n\t\tSQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ?\n\t\t\"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.s.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint error, res;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_fs_bytes(fd, start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tres = compressor_uncompress(comp, block, buffer, c_byte,\n\t\t\tSQUASHFS_METADATA_SIZE, &error);\n\n\t\tif(res == -1) {\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn res;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_fs_bytes(fd, start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\tERROR(\"read_block: failed to read block @0x%llx\\n\", start);\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint error, res;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start,\n\t\tc_byte, SQUASHFS_COMPRESSED_BLOCK(size) ? \"compressed\" :\n\t\t\"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_fs_bytes(fd, start, c_byte, data) == FALSE)\n\t\t\tgoto failed;\n\n\t\tres = compressor_uncompress(comp, block, data, c_byte,\n\t\t\tblock_size, &error);\n\n\t\tif(res == -1) {\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\t\tgoto failed;\n\t\t}\n\n\t\treturn res;\n\t} else {\n\t\tif(read_fs_bytes(fd, start, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\n\t\treturn c_byte;\n\t}\n\nfailed:\n\tERROR(\"read_data_block: failed to read block @0x%llx, size %d\\n\", start,\n\t\tc_byte);\n\treturn FALSE;\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\tTRACE(\"uncompress_inode_table: start %lld, end %lld\\n\", start, end);\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE) {\n\t\t\tinode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE);\n\t\t\tif(inode_table == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in \"\n\t\t\t\t\t\"uncompress_inode_table\");\n\t\t}\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tres = read_block(fd, start, &start, inode_table + bytes);\n\t\tif(res == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read \"\n\t\t\t\t\"block \\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time,\n\tunsigned int xattr, unsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\twrite_xattr(pathname, xattr);\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids \"\n\t\t\t\t\"on %s, because %s\\n\", pathname,\n\t\t\t\tstrerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint write_bytes(int fd, char *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = write(fd, buff + count, bytes - count);\n\t\tif(res == -1) {\n\t\t\tif(errno != EINTR) {\n\t\t\t\tERROR(\"Write on output file failed because \"\n\t\t\t\t\t\"%s\\n\", strerror(errno));\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data = NULL;\n\nint write_block(int file_fd, char *buffer, int size, long long hole, int sparse)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(sparse && lseek_broken == FALSE) {\n\t\t\t int error = lseek(file_fd, off, SEEK_CUR);\n\t\t\t if(error == -1)\n\t\t\t\t/* failed to seek beyond end of file */\n\t\t\t\tlseek_broken = TRUE;\n\t\t}\n\n\t\tif((sparse == FALSE || lseek_broken) && zero_data == NULL) {\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc \"\n\t\t\t\t\t\"zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t}\n\n\t\tif(sparse == FALSE || lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size :\n\t\t\t\t\thole;\n\t\t\t\tif(write_bytes(file_fd, zero_data, avail_bytes)\n\t\t\t\t\t\t== -1)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t}\n\n\tif(write_bytes(file_fd, buffer, size) == -1)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\nint write_file(struct inode *inode, char *pathname)\n{\n\tunsigned int file_fd, i;\n\tunsigned int *block_list;\n\tint file_end = inode->data / block_size;\n\tlong long start = inode->start;\n\tstruct squashfs_file *file;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", inode->blocks);\n\n\tfile_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0),\n\t\t(mode_t) inode->mode & 0777);\n\tif(file_fd == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tblock_list = malloc(inode->blocks * sizeof(unsigned int));\n\tif(block_list == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc block list\\n\");\n\n\ts_ops.read_block_list(block_list, inode->block_ptr, inode->blocks);\n\n\tfile = malloc(sizeof(struct squashfs_file));\n\tif(file == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\n\t/*\n\t * the writer thread is queued a squashfs_file structure describing the\n \t * file.  If the file has one or more blocks or a fragments they are\n \t * queued separately (references to blocks in the cache).\n \t */\n\tfile->fd = file_fd;\n\tfile->file_size = inode->data;\n\tfile->mode = inode->mode;\n\tfile->gid = inode->gid;\n\tfile->uid = inode->uid;\n\tfile->time = inode->time;\n\tfile->pathname = strdup(pathname);\n\tfile->blocks = inode->blocks + (inode->frag_bytes > 0);\n\tfile->sparse = inode->sparse;\n\tfile->xattr = inode->xattr;\n\tqueue_put(to_writer, file);\n\n\tfor(i = 0; i < inode->blocks; i++) {\n\t\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\tblock->offset = 0;\n\t\tblock->size = i == file_end ? inode->data & (block_size - 1) :\n\t\t\tblock_size;\n\t\tif(block_list[i] == 0) /* sparse file */\n\t\t\tblock->buffer = NULL;\n\t\telse {\n\t\t\tblock->buffer = cache_get(data_cache, start,\n\t\t\t\tblock_list[i]);\n\t\t\tstart += c_byte;\n\t\t}\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tif(inode->frag_bytes) {\n\t\tint size;\n\t\tlong long start;\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\ts_ops.read_fragment(inode->fragment, &start, &size);\n\t\tblock->buffer = cache_get(fragment_cache, start, size);\n\t\tblock->offset = inode->offset;\n\t\tblock->size = inode->frag_bytes;\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tfree(block_list);\n\treturn TRUE;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, \"\n\t\t\t\t\"because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, \"\n\t\t\t\t\"blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i, pathname))\n\t\t\t\tfile_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\tcase SQUASHFS_LSYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %lld\\n\",\n\t\t\t\ti->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink \"\n\t\t\t\t\t\"%s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\twrite_xattr(pathname, i->xattr);\n\t\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change \"\n\t\t\t\t\t\t\"uid and gids on %s, because \"\n\t\t\t\t\t\t\"%s\\n\", pathname,\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE:\n \t\tcase SQUASHFS_LBLKDEV_TYPE:\n\t \tcase SQUASHFS_LCHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%llx\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\t\tmakedev((i->data >> 8) & 0xff,\n\t\t\t\t\t\ti->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create \"\n\t\t\t\t\t\t\"%s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid,\n\t\t\t\t\ti->gid, i->time, i->xattr, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s \"\n\t\t\t\t\t\"device %s, because you're not \"\n\t\t\t\t\t\"superuser!\\n\", chrdev ? \"character\" :\n\t\t\t\t\t\"block\", pathname);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_LFIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, \"\n\t\t\t\t\t\"because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid,\n\t\t\t\ti->time, i->xattr, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\tcase SQUASHFS_LSOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\",\n\t\t\t\ti->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\tTRACE(\"uncompress_directory_table: start %lld, end %lld\\n\", start, end);\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE) {\n\t\t\tdirectory_table = realloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE);\n\t\t\tif(directory_table == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in \"\n\t\t\t\t\t\"uncompress_directory_table\\n\");\n\t\t}\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\",\n\t\t\t\tstart);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tres = read_block(fd, start, &start, directory_table + bytes);\n\t\tif(res == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to \"\n\t\t\t\t\"read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\tTRACE(\"add_path: adding \\\"%s\\\" extract file\\n\", target);\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tpaths = malloc(sizeof(struct pathname));\n\t\tif(paths == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/*\n\t\t * allocate new name entry\n\t\t */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) *\n\t\t\tsizeof(struct path_entry));\n\t\tif(paths->name == NULL)\n\t\t\tEXIT_UNSQUASH(\"Out of memory in add_path\\n\");\t\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\tif(paths->name[i].preg == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in add_path\\n\");\n\t\t\terror = regcomp(paths->name[i].preg, targname,\n\t\t\t\tREG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, \"\n\t\t\t\t\t\"because %s\\n\", targname, alltarget,\n\t\t\t\t\tstr);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/*\n\t\t\t * at leaf pathname component\n\t\t\t*/\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/*\n\t\t\t * recurse adding child components\n\t\t\t */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/*\n\t\t * existing matching entry\n\t\t */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/*\n\t\t\t * No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing extract which subsumes\n\t\t\t * the extract currently being added, in which case stop\n\t\t\t * adding components\n\t\t\t */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/*\n\t\t\t * at leaf pathname component and child components exist\n\t\t\t * from more specific extracts, delete as they're\n\t\t\t * subsumed by this extract\n\t\t\t */\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/*\n\t\t\t * recurse adding child components\n\t\t\t */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames));\n\tif(new == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in init_subdir\\n\");\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0) {\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) +\n\t\t\t(paths->count + PATHS_ALLOC_SIZE) *\n\t\t\tsizeof(struct pathname *));\n\t\tif(paths == NULL)\n\t\t\tEXIT_UNSQUASH(\"Out of memory in add_subdir\\n\");\n\t}\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0,\n\t\t\t\tNULL, 0) == 0 : fnmatch(path->name[i].name,\n\t\t\t\tname, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) ==\n\t\t\t\t0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/*\n\t\t\t\t * match on a leaf component, any subdirectories\n\t\t\t\t * will implicitly match, therefore return an\n\t\t\t\t * empty new search set\n\t\t\t\t */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/*\n\t\t\t\t * match on a non-leaf component, add any\n\t\t\t\t * subdirectories to the new set of\n\t\t\t\t * subdirectories to scan for this name\n\t\t\t\t */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/*\n\t\t * no matching names found, delete empty search set, and return\n\t\t * FALSE\n\t\t */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/*\n\t * one or more matches with sub-directories found (no leaf matches),\n\t * return new search set and return TRUE\n\t */\n\treturn TRUE;\n\nempty_set:\n\t/*\n\t * found matching leaf exclude, return empty search set and return TRUE\n\t */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nvoid pre_scan(char *parent_name, unsigned int start_block, unsigned int offset,\n\tstruct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"pre_scan: name %s, start_block %d, offset %d, type %d\\n\",\n\t\t\tname, start_block, offset, type);\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tpre_scan(parent_name, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif(type == SQUASHFS_FILE_TYPE ||\n\t\t\t\t\ttype == SQUASHFS_LREG_TYPE) {\n\t\t\t\ti = s_ops.read_inode(start_block, offset);\n\t\t\t\tif(created_inode[i->inode_number - 1] == NULL) {\n\t\t\t\t\tcreated_inode[i->inode_number - 1] =\n\t\t\t\t\t\t(char *) i;\n\t\t\t\t\ttotal_blocks += (i->data +\n\t\t\t\t\t\t(block_size - 1)) >> block_log;\n\t\t\t\t}\n\t\t\t\ttotal_files ++;\n\t\t\t}\n\t\t\ttotal_inodes ++;\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tsquashfs_closedir(dir);\n}\n\n\nvoid dir_scan(char *parent_name, unsigned int start_block, unsigned int offset,\n\tstruct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(lsonly || info)\n\t\tprint_filename(parent_name, i);\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 &&\n\t\t\t(!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to make directory %s, because %s\\n\",\n\t\t\tparent_name, strerror(errno));\n\t\tsquashfs_closedir(dir);\n\t\treturn;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\",\n\t\t\tname, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\ti = s_ops.read_inode(start_block, offset);\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly) {\n\t\t\t\tcreate_inode(pathname, i);\n\t\t\t\tupdate_progress_bar();\n\t\t\t\t}\n\n\t\t\tif(i->type == SQUASHFS_SYMLINK_TYPE ||\n\t\t\t\t\ti->type == SQUASHFS_LSYMLINK_TYPE)\n\t\t\t\tfree(i->symlink);\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tif(!lsonly)\n\t\tset_attributes(parent_name, dir->mode, dir->uid, dir->guid,\n\t\t\tdir->mtime, dir->xattr, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.s.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %sSQUASHFS %d:%d superblock on %s.\\n\",\n\t\tsBlk.s.s_major == 4 ? \"\" : swap ? \"little endian \" :\n\t\t\"big endian \", sBlk.s.s_major, sBlk.s.s_minor, source);\n#else\n\tprintf(\"Found a valid %sSQUASHFS %d:%d superblock on %s.\\n\",\n\t\tsBlk.s.s_major == 4 ? \"\" : swap ? \"big endian \" :\n\t\t\"little endian \", sBlk.s.s_major, sBlk.s.s_minor, source);\n#endif\n\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str :\n\t\t\"failed to get time\\n\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\",\n\t\tsBlk.s.bytes_used / 1024.0, sBlk.s.bytes_used /\n\t\t(1024.0 * 1024.0));\n\n\tif(sBlk.s.s_major == 4)\n\t\tprintf(\"Compression %s\\n\", comp->name);\n\n\tprintf(\"Block size %d\\n\", sBlk.s.block_size);\n\tprintf(\"Filesystem is %sexportable via NFS\\n\",\n\t\tSQUASHFS_EXPORTABLE(sBlk.s.flags) ? \"\" : \"not \");\n\tprintf(\"Inodes are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_INODES(sBlk.s.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_DATA(sBlk.s.flags) ? \"un\" : \"\");\n\n\tif(sBlk.s.s_major > 1) {\n\t\tif(SQUASHFS_NO_FRAGMENTS(sBlk.s.flags))\n\t\t\tprintf(\"Fragments are not stored\\n\");\n\t\telse {\n\t\t\tprintf(\"Fragments are %scompressed\\n\",\n\t\t\t\tSQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.s.flags) ?\n\t\t\t\t\"un\" : \"\");\n\t\t\tprintf(\"Always_use_fragments option is %sspecified\\n\",\n\t\t\t\tSQUASHFS_ALWAYS_FRAGMENTS(sBlk.s.flags) ? \"\" :\n\t\t\t\t\"not \");\n\t\t}\n\t}\n\n\tif(sBlk.s.s_major == 4) {\n\t\tif(SQUASHFS_NO_XATTRS(sBlk.s.flags))\n\t\t\tprintf(\"Xattrs are not stored\\n\");\n\t\telse\n\t\t\tprintf(\"Xattrs are %scompressed\\n\",\n\t\t\t\tSQUASHFS_UNCOMPRESSED_XATTRS(sBlk.s.flags) ?\n\t\t\t\t\"un\" : \"\");\n\t}\n\n\tif(sBlk.s.s_major < 4)\n\t\t\tprintf(\"Check data is %spresent in the filesystem\\n\",\n\t\t\t\tSQUASHFS_CHECK_DATA(sBlk.s.flags) ? \"\" :\n\t\t\t\t\"not \");\n\n\tif(sBlk.s.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\",\n\t\t\tSQUASHFS_DUPLICATES(sBlk.s.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\n\tif(sBlk.s.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.s.fragments);\n\n\tprintf(\"Number of inodes %d\\n\", sBlk.s.inodes);\n\n\tif(sBlk.s.s_major == 4)\n\t\tprintf(\"Number of ids %d\\n\", sBlk.s.no_ids);\n\telse {\n\t\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\t\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\t}\n\n\tTRACE(\"sBlk.s.inode_table_start 0x%llx\\n\", sBlk.s.inode_table_start);\n\tTRACE(\"sBlk.s.directory_table_start 0x%llx\\n\",\n\t\tsBlk.s.directory_table_start);\n\n\tif(sBlk.s.s_major == 4) {\n\t\tTRACE(\"sBlk.s.id_table_start 0x%llx\\n\", sBlk.s.id_table_start);\n\t\tTRACE(\"sBlk.s.xattr_id_table_start 0x%llx\\n\",\n\t\t\tsBlk.s.xattr_id_table_start);\n\t} else {\n\t\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\t\tTRACE(\"sBlk.guid_start 0x%llx\\n\", sBlk.guid_start);\n\t}\n\n\tif(sBlk.s.s_major > 1)\n\t\tTRACE(\"sBlk.s.fragment_table_start 0x%llx\\n\\n\",\n\t\t\tsBlk.s.fragment_table_start);\n}\n\n\nint read_super(char *source)\n{\n\tsquashfs_super_block_3 sBlk_3;\n\tstruct squashfs_super_block sBlk_4;\n\n\t/*\n\t * Try to read a Squashfs 4 superblock\n\t */\n\tread_fs_bytes(fd, SQUASHFS_START, sizeof(struct squashfs_super_block),\n\t\t&sBlk_4);\n\tswap = (sBlk_4.s_magic != SQUASHFS_MAGIC &&\n\t\tsBlk_4.s_magic != SQUASHFS_MAGIC_LZMA);\n\tSQUASHFS_INSWAP_SUPER_BLOCK(&sBlk_4);\n\n\tif((sBlk_4.s_magic == SQUASHFS_MAGIC || \n\t   sBlk_4.s_magic == SQUASHFS_MAGIC_LZMA) && sBlk_4.s_major == 4 &&\n\t\t\tsBlk_4.s_minor == 0) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir_4;\n\t\ts_ops.read_fragment = read_fragment_4;\n\t\ts_ops.read_fragment_table = read_fragment_table_4;\n\t\ts_ops.read_block_list = read_block_list_2;\n\t\ts_ops.read_inode = read_inode_4;\n\t\ts_ops.read_uids_guids = read_uids_guids_4;\n\t\tmemcpy(&sBlk, &sBlk_4, sizeof(sBlk_4));\n\n\t\t/*\n\t\t * Check the compression type\n\t\t */\n\t\tif (sBlk_4.s_magic == SQUASHFS_MAGIC_LZMA)\n\t\t\tcomp = lookup_compressor(\"lzma\");\n\t\telse\n\t\t\tcomp = lookup_compressor_id(sBlk.s.compression);\n\n\t\treturn TRUE;\n\t}\n\n\t/*\n \t * Not a Squashfs 4 superblock, try to read a squashfs 3 superblock\n \t * (compatible with 1 and 2 filesystems)\n \t */\n\tread_fs_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block_3),\n\t\t&sBlk_3);\n\n\t/*\n\t * Check it is a SQUASHFS superblock\n\t */\n\tswap = 0;\n\tif(sBlk_3.s_magic != SQUASHFS_MAGIC && \n\t\t\tsBlk_3.s_magic != SQUASHFS_MAGIC_LZMA) {\n\t\tif(sBlk_3.s_magic == SQUASHFS_MAGIC_SWAP || \n\t\t\t\tsBlk_3.s_magic == SQUASHFS_MAGIC_LZMA_SWAP) {\n\t\t\tsquashfs_super_block_3 sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem \"\n\t\t\t\t\"on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK_3(&sblk, &sBlk_3);\n\t\t\tmemcpy(&sBlk_3, &sblk, sizeof(squashfs_super_block_3));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n\t\t\t\tsource);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\tsBlk.s.s_magic = sBlk_3.s_magic;\n\tsBlk.s.inodes = sBlk_3.inodes;\n\tsBlk.s.mkfs_time = sBlk_3.mkfs_time;\n\tsBlk.s.block_size = sBlk_3.block_size;\n\tsBlk.s.fragments = sBlk_3.fragments;\n\tsBlk.s.block_log = sBlk_3.block_log;\n\tsBlk.s.flags = sBlk_3.flags;\n\tsBlk.s.s_major = sBlk_3.s_major;\n\tsBlk.s.s_minor = sBlk_3.s_minor;\n\tsBlk.s.root_inode = sBlk_3.root_inode;\n\tsBlk.s.bytes_used = sBlk_3.bytes_used;\n\tsBlk.s.inode_table_start = sBlk_3.inode_table_start;\n\tsBlk.s.directory_table_start = sBlk_3.directory_table_start;\n\tsBlk.s.fragment_table_start = sBlk_3.fragment_table_start;\n\tsBlk.s.lookup_table_start = sBlk_3.lookup_table_start;\n\tsBlk.no_uids = sBlk_3.no_uids;\n\tsBlk.no_guids = sBlk_3.no_guids;\n\tsBlk.uid_start = sBlk_3.uid_start;\n\tsBlk.guid_start = sBlk_3.guid_start;\n\tsBlk.s.xattr_id_table_start = SQUASHFS_INVALID_BLK;\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s.s_major == 1 || sBlk.s.s_major == 2) {\n\t\tsBlk.s.bytes_used = sBlk_3.bytes_used_2;\n\t\tsBlk.uid_start = sBlk_3.uid_start_2;\n\t\tsBlk.guid_start = sBlk_3.guid_start_2;\n\t\tsBlk.s.inode_table_start = sBlk_3.inode_table_start_2;\n\t\tsBlk.s.directory_table_start = sBlk_3.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s.s_major == 1) {\n\t\t\tsBlk.s.block_size = sBlk_3.block_size_1;\n\t\t\tsBlk.s.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_1;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t\t} else {\n\t\t\tsBlk.s.fragment_table_start =\n\t\t\t\tsBlk_3.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_1;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list_2;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t\t}\n\t} else if(sBlk.s.s_major == 3) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir_3;\n\t\ts_ops.read_fragment = read_fragment_3;\n\t\ts_ops.read_fragment_table = read_fragment_table_3;\n\t\ts_ops.read_block_list = read_block_list_2;\n\t\ts_ops.read_inode = read_inode_3;\n\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s.s_major,\n\t\t\tsBlk.s.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\t/*\n\t * 1.x, 2.x and 3.x filesystems use gzip compression.\n\t */\n\tif (sBlk.s.s_magic == SQUASHFS_MAGIC_LZMA)\n\t\tcomp = lookup_compressor(\"lzma\");\n\telse\n\t\tcomp = lookup_compressor(\"gzip\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tfd = fopen(filename, \"r\");\n\tif(fd == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename,\n\t\t\tstrerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n/*\n * reader thread.  This thread processes read requests queued by the\n * cache_get() routine.\n */\nvoid *reader(void *arg)\n{\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_reader);\n\t\tint res = read_fs_bytes(fd, entry->block,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size),\n\t\t\tentry->data);\n\n\t\tif(res && SQUASHFS_COMPRESSED_BLOCK(entry->size))\n\t\t\t/*\n\t\t\t * queue successfully read block to the deflate\n\t\t\t * thread(s) for further processing\n \t\t\t */\n\t\t\tqueue_put(to_deflate, entry);\n\t\telse\n\t\t\t/*\n\t\t\t * block has either been successfully read and is\n\t\t\t * uncompressed, or an error has occurred, clear pending\n\t\t\t * flag, set error appropriately, and wake up any\n\t\t\t * threads waiting on this buffer\n\t\t\t */\n\t\t\tcache_block_ready(entry, !res);\n\t}\n}\n\n\n/*\n * writer thread.  This processes file write requests queued by the\n * write_file() routine.\n */\nvoid *writer(void *arg)\n{\n\tint i;\n\n\twhile(1) {\n\t\tstruct squashfs_file *file = queue_get(to_writer);\n\t\tint file_fd;\n\t\tlong long hole = 0;\n\t\tint failed = FALSE;\n\t\tint error;\n\n\t\tif(file == NULL) {\n\t\t\tqueue_put(from_writer, NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\tTRACE(\"writer: regular file, blocks %d\\n\", file->blocks);\n\n\t\tfile_fd = file->fd;\n\n\t\tfor(i = 0; i < file->blocks; i++, cur_blocks ++) {\n\t\t\tstruct file_entry *block = queue_get(to_writer);\n\n\t\t\tif(block->buffer == 0) { /* sparse file */\n\t\t\t\thole += block->size;\n\t\t\t\tfree(block);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcache_block_wait(block->buffer);\n\n\t\t\tif(block->buffer->error)\n\t\t\t\tfailed = TRUE;\n\n\t\t\tif(failed)\n\t\t\t\tcontinue;\n\n\t\t\terror = write_block(file_fd, block->buffer->data +\n\t\t\t\tblock->offset, block->size, hole, file->sparse);\n\n\t\t\tif(error == FALSE) {\n\t\t\t\tERROR(\"writer: failed to write data block %d\\n\",\n\t\t\t\t\ti);\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\n\t\t\thole = 0;\n\t\t\tcache_block_put(block->buffer);\n\t\t\tfree(block);\n\t\t}\n\n\t\tif(hole && failed == FALSE) {\n\t\t\t/*\n\t\t\t * corner case for hole extending to end of file\n\t\t\t */\n\t\t\tif(file->sparse == FALSE ||\n\t\t\t\t\tlseek(file_fd, hole, SEEK_CUR) == -1) {\n\t\t\t\t/*\n\t\t\t\t * for files which we don't want to write\n\t\t\t\t * sparsely, or for broken lseeks which cannot\n\t\t\t\t * seek beyond end of file, write_block will do\n\t\t\t\t * the right thing\n\t\t\t\t */\n\t\t\t\thole --;\n\t\t\t\tif(write_block(file_fd, \"\\0\", 1, hole,\n\t\t\t\t\t\tfile->sparse) == FALSE) {\n\t\t\t\t\tERROR(\"writer: failed to write sparse \"\n\t\t\t\t\t\t\"data block\\n\");\n\t\t\t\t\tfailed = TRUE;\n\t\t\t\t}\n\t\t\t} else if(ftruncate(file_fd, file->file_size) == -1) {\n\t\t\t\tERROR(\"writer: failed to write sparse data \"\n\t\t\t\t\t\"block\\n\");\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\t\t}\n\n\t\tclose(file_fd);\n\t\tif(failed == FALSE)\n\t\t\tset_attributes(file->pathname, file->mode, file->uid,\n\t\t\t\tfile->gid, file->time, file->xattr, force);\n\t\telse {\n\t\t\tERROR(\"Failed to write %s, skipping\\n\", file->pathname);\n\t\t\tunlink(file->pathname);\n\t\t}\n\t\tfree(file->pathname);\n\t\tfree(file);\n\n\t}\n}\n\n\n/*\n * decompress thread.  This decompresses buffers queued by the read thread\n */\nvoid *deflator(void *arg)\n{\n\tchar tmp[block_size];\n\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_deflate);\n\t\tint error, res;\n\n\t\tres = compressor_uncompress(comp, tmp, entry->data,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size), block_size,\n\t\t\t&error);\n\n\t\tif(res == -1)\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\telse\n\t\t\tmemcpy(entry->data, tmp, res);\n\n\t\t/*\n\t\t * block has been either successfully decompressed, or an error\n \t\t * occurred, clear pending flag, set error appropriately and\n \t\t * wake up any threads waiting on this block\n \t\t */ \n\t\tcache_block_ready(entry, res == -1);\n\t}\n}\n\n\nvoid *progress_thread(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&screen_mutex);\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) *\n\t\t\t1000;\n\t\tpthread_cond_timedwait(&progress_wait, &screen_mutex,\n\t\t\t&timespec);\n\t\tif(progress_enabled)\n\t\t\tprogress_bar(sym_count + dev_count +\n\t\t\t\tfifo_count + cur_blocks, total_inodes -\n\t\t\t\ttotal_files + total_blocks, columns);\n\t}\n}\n\n\nvoid initialise_threads(int fragment_buffer_size, int data_buffer_size)\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\tint all_buffers_size = fragment_buffer_size + data_buffer_size;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\"\n\t\t\t\"\\n\");\n#ifdef __CYGWIN__\n\tprocessors = atoi(getenv(\"NUMBER_OF_PROCESSORS\"));\n#else\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  \"\n\t\t\t\t\"Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = sysconf(_SC_NPROCESSORS_ONLN);\n#endif\n\t}\n#endif /* __CYGWIN__ */\n\n\tthread = malloc((3 + processors) * sizeof(pthread_t));\n\tif(thread == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[3];\n\n\tto_reader = queue_init(all_buffers_size);\n\tto_deflate = queue_init(all_buffers_size);\n\tto_writer = queue_init(1000);\n\tfrom_writer = queue_init(1);\n\tfragment_cache = cache_init(block_size, fragment_buffer_size);\n\tdata_cache = cache_init(block_size, data_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&thread[2], NULL, progress_thread, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) !=\n\t\t\t\t 0)\n\t\t\tEXIT_UNSQUASH(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel unsquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\"\n\t\t\t\"\\n\");\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid update_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits, used, hashes, spaces;\n\tstatic int tty = -1;\n\n\tif(max == 0)\n\t\treturn;\n\n\tmax_digits = floor(log10(max)) + 1;\n\tused = max_digits * 2 + 11;\n\thashes = (current * (columns - used)) / max;\n\tspaces = columns - used - hashes;\n\n\tif((current > max) || (columns - used < 0))\n\t\treturn;\n\n\tif(tty == -1)\n\t\ttty = isatty(STDOUT_FILENO);\n\tif(!tty) {\n\t\tstatic long long previous = -1;\n\n\t\t/*\n\t\t * Updating much more frequently than this results in huge\n\t\t * log files.\n\t\t */\n\t\tif((current % 100) != 0 && current != max)\n\t\t\treturn;\n\t\t/* Don't update just to rotate the spinner. */\n\t\tif(current == previous)\n\t\t\treturn;\n\t\tprevious = current;\n\t}\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 4.2 (2011/02/28)\\n\");\\\n\tprintf(\"copyright (C) 2011 Phillip Lougher \"\\\n\t\t\"<phillip@lougher.demon.co.uk>\\n\\n\");\\\n    \tprintf(\"This program is free software; you can redistribute it and/or\"\\\n\t\t\"\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\"\\\n\t\t\"\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version \"\\\n\t\t\"2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be \"\\\n\t\t\"useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\"\\\n\t\t\"\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\"\\\n\t\t\"\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tint n;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\tint fragment_buffer_size = FRAGMENT_BUFFER_DEFAULT;\n\tint data_buffer_size = DATA_BUFFER_DEFAULT;\n\tchar *b;\n\n\tpthread_mutex_init(&screen_mutex, NULL);\n\troot_process = geteuid() == 0;\n\tif(root_process)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-n\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-xattrs\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-no\") == 0)\n\t\t\tno_xattrs = TRUE;\n\t\telse if(strcmp(argv[i], \"-xattrs\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-x\") == 0)\n\t\t\tno_xattrs = FALSE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-processors\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-p\") == 0) {\n\t\t\tif((++i == argc) || \n\t\t\t\t\t(processors = strtol(argv[i], &b, 10),\n\t\t\t\t\t*b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid \"\n\t\t\t\t\t\"processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-data-queue\") == 0 ||\n\t\t\t\t\t strcmp(argv[i], \"-da\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(data_buffer_size = strtol(argv[i], &b,\n\t\t\t\t\t 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -data-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(data_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -data-queue should be 1 Mbyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-frag-queue\") == 0 ||\n\t\t\t\t\tstrcmp(argv[i], \"-fr\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(fragment_buffer_size = strtol(argv[i],\n\t\t\t\t\t &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -frag-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragment_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -frag-queue should be 1 Mbyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-r\") == 0)\n\t\t\tuse_regex = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(lsonly || info)\n\t\tprogress = FALSE;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or \"\n\t\t\t\t\"files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and \"\n\t\t\t\t\"copyright information\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, \"\n\t\t\t\t\"default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-n[o-progress]\\t\\tdon't display the progress \"\n\t\t\t\t\"bar\\n\");\n\t\t\tERROR(\"\\t-no[-xattrs]\\t\\tdon't extract xattrs in file system\"\n\t\t\t\tNOXOPT_STR\"\\n\");\n\t\t\tERROR(\"\\t-x[attrs]\\t\\textract xattrs in file system\"\n\t\t\t\tXOPT_STR \"\\n\");\n\t\t\tERROR(\"\\t-p[rocessors] <number>\\tuse <number> \"\n\t\t\t\t\"processors.  By default will use\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tnumber of processors available\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are \"\n\t\t\t\t\"unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are \"\n\t\t\t\t\"unsquashed with file\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file \"\n\t\t\t\t\"attributes (like\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then \"\n\t\t\t\t\"overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock \"\n\t\t\t\t\"information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or \"\n\t\t\t\t\"files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-da[ta-queue] <size>\\tSet data queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d\\n\\t\\t\\t\\tMbytes\\n\",\n\t\t\t\tDATA_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-fr[ag-queue] <size>\\tSet fragment queue to \"\n\t\t\t\t\"<size> Mbytes.  Default\\n\\t\\t\\t\\t%d Mbytes\\n\",\n\t\t\t\tFRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX \"\n\t\t\t\t\"regular expressions\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\trather than use the default shell \"\n\t\t\t\t\"wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t\tERROR(\"\\nDecompressors available:\\n\");\n\t\t\tdisplay_compressors(\"\", \"\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i],\n\t\t\tstrerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tif(!comp->supported) {\n\t\tERROR(\"Filesystem uses %s compression, this is \"\n\t\t\t\"unsupported by this version\\n\", comp->name);\n\t\tERROR(\"Decompressors available:\\n\");\n\t\tdisplay_compressors(\"\", \"\");\n\t\texit(1);\n\t}\n\n\tblock_size = sBlk.s.block_size;\n\tblock_log = sBlk.s.block_log;\n\n\tfragment_buffer_size <<= 20 - block_log;\n\tdata_buffer_size <<= 20 - block_log;\n\tinitialise_threads(fragment_buffer_size, data_buffer_size);\n\n\tfragment_data = malloc(block_size);\n\tif(fragment_data == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tfile_data = malloc(block_size);\n\tif(file_data == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tdata = malloc(block_size);\n\tif(data == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate data\\n\");\n\n\tcreated_inode = malloc(sBlk.s.inodes * sizeof(char *));\n\tif(created_inode == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.s.inodes * sizeof(char *));\n\n\tif(s_ops.read_uids_guids() == FALSE)\n\t\tEXIT_UNSQUASH(\"failed to uid/gid table\\n\");\n\n\tif(s_ops.read_fragment_table() == FALSE)\n\t\tEXIT_UNSQUASH(\"failed to read fragment table\\n\");\n\n\tuncompress_inode_table(sBlk.s.inode_table_start,\n\t\tsBlk.s.directory_table_start);\n\n\tuncompress_directory_table(sBlk.s.directory_table_start,\n\t\tsBlk.s.fragment_table_start);\n\n\tif(no_xattrs)\n\t\tsBlk.s.xattr_id_table_start = SQUASHFS_INVALID_BLK;\n\n\tif(read_xattrs_from_disk(fd, &sBlk.s) == 0)\n\t\tEXIT_UNSQUASH(\"failed to read the xattr table\\n\");\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tpre_scan(dest, SQUASHFS_INODE_BLK(sBlk.s.root_inode),\n\t\tSQUASHFS_INODE_OFFSET(sBlk.s.root_inode), paths);\n\n\tmemset(created_inode, 0, sBlk.s.inodes * sizeof(char *));\n\tinode_number = 1;\n\n\tprintf(\"%d inodes (%d blocks) to write\\n\\n\", total_inodes,\n\t\ttotal_inodes - total_files + total_blocks);\n\n\tif(progress)\n\t\tenable_progress_bar();\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.s.root_inode),\n\t\tSQUASHFS_INODE_OFFSET(sBlk.s.root_inode), paths);\n\n\tqueue_put(to_writer, NULL);\n\tqueue_get(from_writer);\n\n\tif(progress) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(sym_count + dev_count + fifo_count + cur_blocks,\n\t\t\ttotal_inodes - total_files + total_blocks, columns);\n\t}\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/unsquashfs.h",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs.h\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <sys/mman.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n#include <signal.h>\n#include <pthread.h>\n#include <math.h>\n#include <sys/ioctl.h>\n#include <sys/time.h>\n\n#ifndef linux\n#ifndef __CYGWIN__\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#endif\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#ifdef __CYGWIN__\n#include <sys/termios.h>\n#define FNM_EXTMATCH  (1 << 5)\n#endif\n\n#ifndef FNM_EXTMATCH\n#define FNM_EXTMATCH 0\n#endif\n\n#include \"squashfs_fs.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tprintf(\"\\n\"); \\\n\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...) \\\n\t\tdo { \\\n\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\texit(1); \\\n\t\t} while(0)\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\n/*\n * Unified superblock containing fields for all superblocks\n */\nstruct super_block {\n\tstruct squashfs_super_block s;\n\t/* fields only used by squashfs 3 and earlier layouts */\n\tunsigned int\t\tno_uids;\n\tunsigned int\t\tno_guids;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n};\n\nstruct hash_table_entry {\n\tlong long\tstart;\n\tint\t\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar *symlink;\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n\tchar sparse;\n\tunsigned int xattr;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(unsigned int block_start,\n\t\tunsigned int offset, struct inode **i);\n\tvoid (*read_fragment)(unsigned int fragment, long long *start_block,\n\t\tint *size);\n\tint (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, char *block_ptr,\n\t\tint blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block,\n\t\tunsigned int offset);\n\tint (*read_uids_guids)();\n} squashfs_operations;\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tint\twait_free;\n\tint\twait_pending;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tpthread_cond_t wait_for_pending;\n\tstruct cache_entry *free_list;\n\tstruct cache_entry *hash_table[65536];\n};\n\n/* struct describing a cache entry passed between threads */\nstruct cache_entry {\n\tstruct cache *cache;\n\tlong long block;\n\tint\tsize;\n\tint\tused;\n\tint error;\n\tint\tpending;\n\tstruct cache_entry *hash_next;\n\tstruct cache_entry *hash_prev;\n\tstruct cache_entry *free_next;\n\tstruct cache_entry *free_prev;\n\tchar *data;\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\tsize;\n\tint\treadp;\n\tint\twritep;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t empty;\n\tpthread_cond_t full;\n\tvoid **data;\n};\n\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 256\n/* default size of data buffer in Mbytes */\n#define DATA_BUFFER_DEFAULT 256\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tunsigned int xattr;\n\tstruct dir_ent\t*dirs;\n};\n\nstruct file_entry {\n\tint offset;\n\tint size;\n\tstruct cache_entry *buffer;\n};\n\n\nstruct squashfs_file {\n\tint fd;\n\tint blocks;\n\tlong long file_size;\n\tint mode;\n\tuid_t uid;\n\tgid_t gid;\n\ttime_t time;\n\tchar *pathname;\n\tchar sparse;\n\tunsigned int xattr;\n};\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\n/* globals */\nextern struct super_block sBlk;\nextern squashfs_operations s_ops;\nextern int swap;\nextern char *inode_table, *directory_table;\nextern struct hash_table_entry *inode_table_hash[65536],\n\t*directory_table_hash[65536];\nextern unsigned int *uid_table, *guid_table;\nextern pthread_mutex_t screen_mutex;\nextern int progress_enabled;\nextern int inode_number;\nextern int lookup_type[];\nextern int fd;\n\n/* unsquashfs.c */\nextern int lookup_entry(struct hash_table_entry **, long long);\nextern int read_fs_bytes(int fd, long long, int, void *);\nextern int read_block(int, long long, long long *, void *);\n\n/* unsquash-1.c */\nextern void read_block_list_1(unsigned int *, char *, int);\nextern int read_fragment_table_1();\nextern struct inode *read_inode_1(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_1(unsigned int, unsigned int,\n\tstruct inode **);\nextern int read_uids_guids_1();\n\n/* unsquash-2.c */\nextern void read_block_list_2(unsigned int *, char *, int);\nextern int read_fragment_table_2();\nextern void read_fragment_2(unsigned int, long long *, int *);\nextern struct inode *read_inode_2(unsigned int, unsigned int);\n\n/* unsquash-3.c */\nextern int read_fragment_table_3();\nextern void read_fragment_3(unsigned int, long long *, int *);\nextern struct inode *read_inode_3(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_3(unsigned int, unsigned int,\n\tstruct inode **);\n\n/* unsquash-4.c */\nextern int read_fragment_table_4();\nextern void read_fragment_4(unsigned int, long long *, int *);\nextern struct inode *read_inode_4(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_4(unsigned int, unsigned int,\n\tstruct inode **);\nextern int read_uids_guids_4();\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/unsquashfs_xattr.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs_xattr.c\n */\n\n#include \"unsquashfs.h\"\n#include \"xattr.h\"\n\n#include <sys/xattr.h>\n\nextern int root_process;\n\nvoid write_xattr(char *pathname, unsigned int xattr)\n{\n\tunsigned int count;\n\tstruct xattr_list *xattr_list;\n\tint i;\n\n\tif(xattr == SQUASHFS_INVALID_XATTR ||\n\t\t\tsBlk.s.xattr_id_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn;\n\n\txattr_list = get_xattr(xattr, &count);\n\tif(xattr_list == NULL) {\n\t\tERROR(\"Failed to read xattrs for file %s\\n\", pathname);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < count; i++) {\n\t\tint prefix = xattr_list[i].type & SQUASHFS_XATTR_PREFIX_MASK;\n\n\t\tif(root_process || prefix == SQUASHFS_XATTR_USER) {\n\t\t\tint res = lsetxattr(pathname, xattr_list[i].full_name,\n\t\t\t\txattr_list[i].value, xattr_list[i].vsize, 0);\n\n\t\t\tif(res == -1)\n\t\t\t\tERROR(\"write_xattr: failed to write xattr %s\"\n\t\t\t\t\t\" for file %s because %s\\n\",\n\t\t\t\t\txattr_list[i].full_name, pathname,\n\t\t\t\t\terrno == ENOSPC || errno == EDQUOT ?\n\t\t\t\t\t\"no extended attribute space remaining \"\n\t\t\t\t\t\"on destination filesystem\" :\n\t\t\t\t\terrno == ENOTSUP ?\n\t\t\t\t\t\"extended attributes are not supported \"\n\t\t\t\t\t\"by the destination filesystem\" :\n\t\t\t\t\t\"a weird error occurred\");\n\t\t} else\n\t\t\tERROR(\"write_xattr: could not write xattr %s \"\n\t\t\t\t\t\"for file %s because you're not \"\n\t\t\t\t\t\"superuser!\\n\",\n\t\t\t\t\txattr_list[i].full_name, pathname);\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/xattr.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * xattr.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n#include <sys/xattr.h>\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"mksquashfs.h\"\n#include \"xattr.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\n/* compressed xattr table */\nstatic char *xattr_table = NULL;\nstatic unsigned int xattr_size = 0;\n\n/* cached uncompressed xattr data */\nstatic char *data_cache = NULL;\nstatic int cache_bytes = 0, cache_size = 0;\n\n/* cached uncompressed xattr id table */\nstatic struct squashfs_xattr_id *xattr_id_table = NULL;\nstatic int xattr_ids = 0;\n\n/* saved compressed xattr table */\nunsigned int sxattr_bytes = 0, stotal_xattr_bytes = 0;\n\n/* saved cached uncompressed xattr data */\nstatic char *sdata_cache = NULL;\nstatic int scache_bytes = 0;\n\n/* saved cached uncompressed xattr id table */\nstatic int sxattr_ids = 0;\n\n/* xattr hash table for value duplicate detection */\nstatic struct xattr_list *dupl[65536];\n\n/* xattr hash table for id duplicate detection */\nstatic struct dupl_id *dupl_id[65536];\n\n/* file system globals from mksquashfs.c */\nextern int no_xattrs, noX;\nextern long long bytes;\nextern int fd;\nextern unsigned int xattr_bytes, total_xattr_bytes;\n\n/* helper functions from mksquashfs.c */\nextern unsigned short get_checksum(char *, int, unsigned short);\nextern void write_destination(int, long long, int, void *);\nextern long long generic_write_table(int, void *, int, void *, int);\nextern int mangle(char *, char *, int, int, int, int);\n\n/* helper functions and definitions from read_xattrs.c */\nextern int read_xattrs_from_disk(int, struct squashfs_super_block *);\nextern struct xattr_list *get_xattr(int, unsigned int *);\nextern struct prefix prefix_table[];\n\n\nstatic int get_prefix(struct xattr_list *xattr, char *name)\n{\n\tint i;\n\n\txattr->full_name = strdup(name);\n\n\tfor(i = 0; prefix_table[i].type != -1; i++) {\n\t\tstruct prefix *p = &prefix_table[i];\n\t\tif(strncmp(xattr->full_name, p->prefix, strlen(p->prefix)) == 0)\n\t\t\tbreak;\n\t}\n\n\tif(prefix_table[i].type != -1) {\n\t\txattr->name = xattr->full_name + strlen(prefix_table[i].prefix);\n\t\txattr->size = strlen(xattr->name);\n\t}\n\n\treturn prefix_table[i].type;\n}\n\n\t\nstatic int read_xattrs_from_system(char *filename, struct xattr_list **xattrs)\n{\n\tssize_t size, vsize;\n\tchar *xattr_names, *p;\n\tint i;\n\tstruct xattr_list *xattr_list = NULL;\n\n\twhile(1) {\n\t\tsize = llistxattr(filename, NULL, 0);\n\t\tif(size <= 0) {\n\t\t\tif(size < 0 && errno != ENOTSUP)\n\t\t\t\tERROR(\"llistxattr for %s failed in read_attrs,\"\n\t\t\t\t\t\" because %s\\n\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\treturn 0;\n\t\t}\n\n\t\txattr_names = malloc(size);\n\t\tif(xattr_names == NULL) {\n\t\t\tERROR(\"Out of memory in read_attrs\\n\");\n\t\t\treturn 0;\n\t\t}\n\n\t\tsize = llistxattr(filename, xattr_names, size);\n\t\tif(size < 0) {\n\t\t\tfree(xattr_names);\n\t\t\tif(errno == ERANGE)\n\t\t\t\t/* xattr list grew?  Try again */\n\t\t\t\tcontinue;\n\t\t\telse {\n\t\t\t\tERROR(\"llistxattr for %s failed in read_attrs,\"\n\t\t\t\t\t\" because %s\\n\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\n\t\tbreak;\n\t}\n\n\tfor(i = 0, p = xattr_names; p < xattr_names + size; i++) {\n\t\tstruct xattr_list *x = realloc(xattr_list, (i + 1) *\n\t\t\t\t\t\tsizeof(struct xattr_list));\n\t\tif(x == NULL) {\n\t\t\tERROR(\"Out of memory in read_attrs\\n\");\n\t\t\tgoto failed;\n\t\t} else\n\t\t\txattr_list = x;\n\n\t\txattr_list[i].type = get_prefix(&xattr_list[i], p);\n\t\tp += strlen(p) + 1;\n\t\tif(xattr_list[i].type == -1) {\n\t\t\tERROR(\"Unrecognised xattr prefix %s\\n\",\n\t\t\t\txattr_list[i].full_name);\n\t\t\tfree(xattr_list[i].full_name);\n\t\t\ti--;\n\t\t\tcontinue;\n\t\t}\n\n\t\twhile(1) {\n\t\t\tvsize = lgetxattr(filename, xattr_list[i].full_name,\n\t\t\t\t\t\t\t\tNULL, 0);\n\t\t\tif(vsize < 0) {\n\t\t\t\tERROR(\"lgetxattr failed for %s in read_attrs,\"\n\t\t\t\t\t\" because %s\\n\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tfree(xattr_list[i].full_name);\n\t\t\t\tgoto failed;\n\t\t\t}\n\n\t\t\txattr_list[i].value = malloc(vsize);\n\t\t\tif(xattr_list[i].value == NULL) {\n\t\t\t\tERROR(\"Out of memory in read_attrs\\n\");\n\t\t\t\tfree(xattr_list[i].full_name);\n\t\t\t\tgoto failed;\n\t\t\t}\n\n\t\t\tvsize = lgetxattr(filename, xattr_list[i].full_name,\n\t\t\t\t\t\txattr_list[i].value, vsize);\n\t\t\tif(vsize < 0) {\n\t\t\t\tfree(xattr_list[i].value);\n\t\t\t\tif(errno == ERANGE)\n\t\t\t\t\t/* xattr grew?  Try again */\n\t\t\t\t\tcontinue;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"lgetxattr failed for %s in \"\n\t\t\t\t\t\t\"read_attrs, because %s\\n\",\n\t\t\t\t\t\tfilename, strerror(errno));\n\t\t\t\t\tfree(xattr_list[i].full_name);\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tbreak;\n\t\t}\n\t\txattr_list[i].vsize = vsize;\n\n\t\tTRACE(\"read_xattrs_from_system: filename %s, xattr name %s,\"\n\t\t\t\" vsize %d\\n\", filename, xattr_list[i].full_name,\n\t\t\txattr_list[i].vsize);\n\t}\n\tfree(xattr_names);\n\t*xattrs = xattr_list;\n\treturn i;\n\nfailed:\n\twhile(--i >= 0) {\n\t\tfree(xattr_list[i].full_name);\n\t\tfree(xattr_list[i].value);\n\t}\n\tfree(xattr_list);\n\tfree(xattr_names);\n\treturn 0;\n}\n\n\nstatic int get_xattr_size(struct xattr_list *xattr)\n{\n\tint size = sizeof(struct squashfs_xattr_entry) +\n\t\tsizeof(struct squashfs_xattr_val) + xattr->size;\n\n\tif(xattr->type & XATTR_VALUE_OOL)\n\t\tsize += XATTR_VALUE_OOL_SIZE;\n\telse\n\t\tsize += xattr->vsize;\n\n\treturn size;\n}\n\n\nstatic void *get_xattr_space(unsigned int req_size, long long *disk)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\t/*\n\t * Move and compress cached uncompressed data into xattr table.\n\t */\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((xattr_size - xattr_bytes) <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\txattr_table = realloc(xattr_table, xattr_size +\n\t\t\t\t(SQUASHFS_METADATA_SIZE << 1) + 2);\n\t\t\tif(xattr_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\txattr_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(xattr_table + xattr_bytes + BLOCK_OFFSET,\n\t\t\tdata_cache, SQUASHFS_METADATA_SIZE,\n\t\t\tSQUASHFS_METADATA_SIZE, noX, 0);\n\t\tTRACE(\"Xattr block @ 0x%x, size %d\\n\", xattr_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, xattr_table + xattr_bytes, 1);\n\t\txattr_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\tmemmove(data_cache, data_cache + SQUASHFS_METADATA_SIZE,\n\t\t\tcache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\t/*\n\t * Ensure there's enough space in the uncompressed data cache\n\t */\n\tdata_space = cache_size - cache_bytes;\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = req_size - data_space;\n\t\t\tdata_cache = realloc(data_cache, cache_size +\n\t\t\t\trealloc_size);\n\t\t\tif(data_cache == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tif(disk)\n\t\t*disk = ((long long) xattr_bytes << 16) | cache_bytes;\n\tcache_bytes += req_size;\n\treturn data_cache + cache_bytes - req_size;\n\nfailed:\n\tERROR(\"Out of memory in inode table reallocation!\\n\");\n\treturn NULL;\n}\n\n\nstatic struct dupl_id *check_id_dupl(struct xattr_list *xattr_list, int xattrs)\n{\n\tstruct dupl_id *entry;\n\tint i;\n\tunsigned short checksum = 0;\n\n\t/* compute checksum over all xattrs */\n\tfor(i = 0; i < xattrs; i++) {\n\t\tstruct xattr_list *xattr = &xattr_list[i];\n\n\t\tchecksum = get_checksum(xattr->full_name,\n\t\t\t\t\tstrlen(xattr->full_name), checksum);\n\t\tchecksum = get_checksum(xattr->value,\n\t\t\t\t\txattr->vsize, checksum);\n\t}\n\n\tfor(entry = dupl_id[checksum]; entry; entry = entry->next) {\n\t\tif (entry->xattrs != xattrs)\n\t\t\tcontinue;\n\n\t\tfor(i = 0; i < xattrs; i++) {\n\t\t\tstruct xattr_list *xattr = &xattr_list[i];\n\t\t\tstruct xattr_list *dup_xattr = &entry->xattr_list[i];\n\n\t\t\tif(strcmp(xattr->full_name, dup_xattr->full_name))\n\t\t\t\tbreak;\n\n\t\t\tif(memcmp(xattr->value, dup_xattr->value, xattr->vsize))\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif(i == xattrs)\n\t\t\tbreak;\n\t}\n\n\tif(entry == NULL) {\n\t\t/* no duplicate exists */\n\t\tentry = malloc(sizeof(*entry));\n\t\tif(entry == NULL) {\n\t\t\tERROR(\"malloc failed in check_ip_dupl\\n\");\n\t\t\treturn NULL;\n\t\t}\n\t\tentry->xattrs = xattrs;\n\t\tentry->xattr_list = xattr_list;\n\t\tentry->xattr_id = SQUASHFS_INVALID_XATTR;\n\t\tentry->next = dupl_id[checksum];\n\t\tdupl_id[checksum] = entry;\n\t}\n\t\t\n\treturn entry;\n}\n\n\nstatic void check_value_dupl(struct xattr_list *xattr)\n{\n\tstruct xattr_list *entry;\n\n\tif(xattr->vsize < XATTR_VALUE_OOL_SIZE)\n\t\treturn;\n\n\t/* Check if this is a duplicate of an existing value */\n\txattr->vchecksum = get_checksum(xattr->value, xattr->vsize, 0);\n\tfor(entry = dupl[xattr->vchecksum]; entry; entry = entry->vnext) {\n\t\tif(entry->vsize != xattr->vsize)\n\t\t\tcontinue;\n\t\t\n\t\tif(memcmp(entry->value, xattr->value, xattr->vsize) == 0)\n\t\t\tbreak;\n\t}\n\n\tif(entry == NULL) {\n\t\t/*\n\t\t * No duplicate exists, add to hash table, and mark as\n\t\t * requiring writing\n\t\t */\n\t\txattr->vnext = dupl[xattr->vchecksum];\n\t\tdupl[xattr->vchecksum] = xattr;\n\t\txattr->ool_value = SQUASHFS_INVALID_BLK;\n\t} else {\n\t\t/*\n\t\t * Duplicate exists, make type XATTR_VALUE_OOL, and\n\t\t * remember where the duplicate is\n\t\t */\n\t\txattr->type |= XATTR_VALUE_OOL;\n\t\txattr->ool_value = entry->ool_value;\n\t\t/* on appending don't free duplicate values because the\n\t\t * duplicate value already points to the non-duplicate value */\n\t\tif(xattr->value != entry->value) {\n\t\t\tfree(xattr->value);\n\t\t\txattr->value = entry->value;\n\t\t}\n\t}\n}\n\n\nstatic int get_xattr_id(int xattrs, struct xattr_list *xattr_list,\n\t\tlong long xattr_disk, struct dupl_id *xattr_dupl)\n{\n\tint i, size = 0;\n\tstruct squashfs_xattr_id *xattr_id;\n\n\txattr_id_table = realloc(xattr_id_table, (xattr_ids + 1) *\n\t\tsizeof(struct squashfs_xattr_id));\n\tif(xattr_id_table == NULL) {\n\t\tERROR(\"Out of memory in xattr_id_table reallocation!\\n\");\n\t\treturn -1;\n\t}\n\n\t/* get total uncompressed size of xattr data, needed for stat */\n\tfor(i = 0; i < xattrs; i++)\n\t\tsize += strlen(xattr_list[i].full_name) + 1 +\n\t\t\txattr_list[i].vsize;\n\n\txattr_id = &xattr_id_table[xattr_ids];\n\txattr_id->xattr = xattr_disk;\n\txattr_id->count = xattrs;\n\txattr_id->size = size;\n\n\t/*\n\t * keep track of total uncompressed xattr data, needed for mksquashfs\n\t * file system summary\n\t */\n\ttotal_xattr_bytes += size;\n\n\txattr_dupl->xattr_id = xattr_ids ++;\n\treturn xattr_dupl->xattr_id;\n}\n\t\n\nlong long write_xattrs()\n{\n\tunsigned short c_byte;\n\tint i, avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\tstruct squashfs_xattr_table header;\n\n\tif(xattr_ids == 0)\n\t\treturn SQUASHFS_INVALID_BLK;\n\n\t/*\n\t * Move and compress cached uncompressed data into xattr table.\n\t */\n\twhile(cache_bytes) {\n\t\tif((xattr_size - xattr_bytes) <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\txattr_table = realloc(xattr_table, xattr_size +\n\t\t\t\t(SQUASHFS_METADATA_SIZE << 1) + 2);\n\t\t\tif(xattr_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\txattr_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(xattr_table + xattr_bytes + BLOCK_OFFSET, datap,\n\t\t\tavail_bytes, SQUASHFS_METADATA_SIZE, noX, 0);\n\t\tTRACE(\"Xattr block @ 0x%x, size %d\\n\", xattr_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, xattr_table + xattr_bytes, 1);\n\t\txattr_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\t/*\n\t * Write compressed xattr table to file system\n\t */\n\twrite_destination(fd, bytes, xattr_bytes, xattr_table);\n        bytes += xattr_bytes;\n\n\t/*\n\t * Swap if necessary the xattr id table\n\t */\n\tfor(i = 0; i < xattr_ids; i++)\n\t\tSQUASHFS_INSWAP_XATTR_ID(&xattr_id_table[i]);\n\n\theader.xattr_ids = xattr_ids;\n\theader.xattr_table_start = start_bytes;\n\tSQUASHFS_INSWAP_XATTR_TABLE(&header);\n\n\treturn generic_write_table(xattr_ids * sizeof(struct squashfs_xattr_id),\n\t\txattr_id_table, sizeof(header), &header, noX);\n\nfailed:\n\tERROR(\"Out of memory in xattr_table reallocation!\\n\");\n\treturn -1;\n}\n\n\nint generate_xattrs(int xattrs, struct xattr_list *xattr_list)\n{\n\tint total_size, i;\n\tint xattr_value_max;\n\tvoid *xp;\n\tlong long xattr_disk;\n\tstruct dupl_id *xattr_dupl;\n\n\t/*\n\t * check if the file xattrs are a complete duplicate of a pre-existing\n\t * id\n\t */\n\txattr_dupl = check_id_dupl(xattr_list, xattrs);\n\tif (xattr_dupl == NULL)\n\t\treturn SQUASHFS_INVALID_XATTR;\n\tif(xattr_dupl->xattr_id != SQUASHFS_INVALID_XATTR)\n\t\treturn xattr_dupl->xattr_id;\n\t \n\t/*\n\t * Scan the xattr_list deciding which type to assign to each\n\t * xattr.  The choice is fairly straightforward, and depends on the\n\t * size of each xattr name/value and the overall size of the\n\t * resultant xattr list stored in the xattr metadata table.\n\t *\n\t * Choices are whether to store data inline or out of line.\n\t *\n\t * The overall goal is to optimise xattr scanning and lookup, and\n\t * to enable the file system layout to scale from a couple of\n\t * small xattr name/values to a large number of large xattr\n\t * names/values without affecting performance.  While hopefully\n\t * enabling the common case of a couple of small xattr name/values\n\t * to be stored efficiently\n\t *\n\t * Code repeatedly scans, doing the following\n\t *\t\tmove xattr data out of line if it exceeds\n\t *\t\txattr_value_max.  Where xattr_value_max is\n\t *\t\tinitially XATTR_INLINE_MAX.  If the final uncompressed\n\t *\t\txattr list is larger than XATTR_TARGET_MAX then more\n\t *\t\taggressively move xattr data out of line by repeatedly\n\t *\t \tsetting inline threshold to 1/2, then 1/4, 1/8 of\n\t *\t\tXATTR_INLINE_MAX until target achieved or there's\n\t *\t\tnothing left to move out of line\n\t */\n\txattr_value_max = XATTR_INLINE_MAX;\n\twhile(1) {\n\t\tfor(total_size = 0, i = 0; i < xattrs; i++) {\n\t\t\tstruct xattr_list *xattr = &xattr_list[i];\n\t\t\txattr->type &= XATTR_PREFIX_MASK; /* all inline */\n\t\t\tif (xattr->vsize > xattr_value_max)\n\t\t\t\txattr->type |= XATTR_VALUE_OOL;\n\n\t\t\ttotal_size += get_xattr_size(xattr);\n\t\t}\n\n\t\t/*\n\t\t * If the total size of the uncompressed xattr list is <=\n\t\t * XATTR_TARGET_MAX we're done\n\t\t */\n\t\tif(total_size <= XATTR_TARGET_MAX)\n\t\t\tbreak;\n\n\t\tif(xattr_value_max == XATTR_VALUE_OOL_SIZE)\n\t\t\tbreak;\n\n\t\t/*\n\t\t * Inline target not yet at minimum and so reduce it, and\n\t\t * try again\n\t\t */\n\t\txattr_value_max /= 2;\n\t\tif(xattr_value_max < XATTR_VALUE_OOL_SIZE)\n\t\t\txattr_value_max = XATTR_VALUE_OOL_SIZE;\n\t}\n\n\t/*\n\t * Check xattr values for duplicates\n\t */\n\tfor(i = 0; i < xattrs; i++) {\n\t\tcheck_value_dupl(&xattr_list[i]);\n\t}\n\n\t/*\n\t * Add each out of line value to the file system xattr table\n\t * if it doesn't already exist as a duplicate\n\t */\n\tfor(i = 0; i < xattrs; i++) {\n\t\tstruct xattr_list *xattr = &xattr_list[i];\n\n\t\tif((xattr->type & XATTR_VALUE_OOL) &&\n\t\t\t\t(xattr->ool_value == SQUASHFS_INVALID_BLK)) {\n\t\t\tstruct squashfs_xattr_val val;\n\t\t\tint size = sizeof(val) + xattr->vsize;\n\t\t\txp = get_xattr_space(size, &xattr->ool_value);\n\t\t\tval.vsize = xattr->vsize;\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, xp);\n\t\t\tmemcpy(xp + sizeof(val), xattr->value, xattr->vsize);\n\t\t}\n\t}\n\n\t/*\n\t * Create xattr list and add to file system xattr table\n\t */\n\tget_xattr_space(0, &xattr_disk);\n\tfor(i = 0; i < xattrs; i++) {\n\t\tstruct xattr_list *xattr = &xattr_list[i];\n\t\tstruct squashfs_xattr_entry entry;\n\t\tstruct squashfs_xattr_val val;\n\n\t\txp = get_xattr_space(sizeof(entry) + xattr->size, NULL);\n\t\tentry.type = xattr->type;\n\t\tentry.size = xattr->size;\n\t\tSQUASHFS_SWAP_XATTR_ENTRY(&entry, xp);\n\t\tmemcpy(xp + sizeof(entry), xattr->name, xattr->size);\n\n\t\tif(xattr->type & XATTR_VALUE_OOL) {\n\t\t\tint size = sizeof(val) + XATTR_VALUE_OOL_SIZE;\n\t\t\txp = get_xattr_space(size, NULL);\n\t\t\tval.vsize = XATTR_VALUE_OOL_SIZE;\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, xp);\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(&xattr->ool_value, xp +\n\t\t\t\tsizeof(val), 1);\n\t\t} else {\n\t\t\tint size = sizeof(val) + xattr->vsize;\n\t\t\txp = get_xattr_space(size, &xattr->ool_value);\n\t\t\tval.vsize = xattr->vsize;\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, xp);\n\t\t\tmemcpy(xp + sizeof(val), xattr->value, xattr->vsize);\n\t\t}\n\t}\n\n\t/*\n\t * Add to xattr id lookup table\n\t */\n\treturn get_xattr_id(xattrs, xattr_list, xattr_disk, xattr_dupl);\n}\n\n\nint read_xattrs(void *d)\n{\n\tstruct dir_ent *dir_ent = d;\n\tstruct inode_info *inode = dir_ent->inode;\n\tchar *filename = dir_ent->pathname;\n\tstruct xattr_list *xattr_list;\n\tint xattrs;\n\n\tif(no_xattrs || IS_PSEUDO(inode) || inode->root_entry)\n\t\treturn SQUASHFS_INVALID_XATTR;\n\n\txattrs = read_xattrs_from_system(filename, &xattr_list);\n\tif(xattrs == 0)\n\t\treturn SQUASHFS_INVALID_XATTR;\n\n\treturn generate_xattrs(xattrs, xattr_list);\n}\n\n\n/*\n * Add the existing xattr ids and xattr metadata in the file system being\n * appended to, to the in-memory xattr cache.  This allows duplicate checking to\n * take place against the xattrs already in the file system being appended to,\n * and ensures the pre-existing xattrs are written out along with any new xattrs\n */\nint get_xattrs(int fd, struct squashfs_super_block *sBlk)\n{\n\tint ids, res, i, id;\n\tunsigned int count;\n\n\tTRACE(\"get_xattrs\\n\");\n\n\tres = read_xattrs_from_disk(fd, sBlk);\n\tif(res == SQUASHFS_INVALID_BLK || res == 0)\n\t\tgoto done;\n\tids = res;\n\n\t/*\n\t * for each xattr id read and construct its list of xattr\n\t * name:value pairs, and add them to the in-memory xattr cache\n\t */\n\tfor(i = 0; i < ids; i++) {\n\t\tstruct xattr_list *xattr_list = get_xattr(i, &count);\n\t\tif(xattr_list == NULL) {\n\t\t\tres = 0;\n\t\t\tgoto done;\n\t\t}\n\t\tid = generate_xattrs(count, xattr_list);\n\n\t\t/*\n\t\t * Sanity check, the new xattr id should be the same as the\n\t\t * xattr id in the original file system\n\t\t */\n\t\tif(id != i) {\n\t\t\tERROR(\"BUG, different xattr_id in get_xattrs\\n\");\n\t\t\tres = 0;\n\t\t\tgoto done;\n\t\t}\n\t}\n\ndone:\n\treturn res;\n}\n\n\n/*\n * Save current state of xattrs, needed for restoring state in the event of an\n * abort in appending\n */\nint save_xattrs()\n{\n\t/* save the current state of the compressed xattr data */\n\tsxattr_bytes = xattr_bytes;\n\tstotal_xattr_bytes = total_xattr_bytes;\n\n\t/*\n\t * save the current state of the cached uncompressed xattr data.\n\t * Note we have to save the contents of the data cache because future\n\t * operations will delete the current contents\n\t */\n\tsdata_cache = malloc(cache_bytes);\n\tif(sdata_cache == NULL)\n\t\tgoto failed;\n\n\tmemcpy(sdata_cache, data_cache, cache_bytes);\n\tscache_bytes = cache_bytes;\n\n\t/* save the current state of the xattr id table */\n\tsxattr_ids = xattr_ids;\n\n\treturn TRUE;\n\nfailed:\n\tERROR(\"Out of memory in save_xattrs\\n\");\n\treturn FALSE;\n}\n\n\n/*\n * Restore xattrs in the event of an abort in appending\n */\nvoid restore_xattrs()\n{\n\t/* restore the state of the compressed xattr data */\n\txattr_bytes = sxattr_bytes;\n\ttotal_xattr_bytes = stotal_xattr_bytes;\n\n\t/* restore the state of the uncomoressed xattr data */\n\tmemcpy(data_cache, sdata_cache, scache_bytes);\n\tcache_bytes = scache_bytes;\n\n\t/* restore the state of the xattr id table */\n\txattr_ids = sxattr_ids;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/xattr.h",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * xattr.h\n */\n\n#define XATTR_VALUE_OOL\t\tSQUASHFS_XATTR_VALUE_OOL\n#define XATTR_PREFIX_MASK\tSQUASHFS_XATTR_PREFIX_MASK\n\n#define XATTR_VALUE_OOL_SIZE\tsizeof(long long)\n\n/* maximum size of xattr value data that will be inlined */\n#define XATTR_INLINE_MAX \t128\n\n/* the target size of an inode's xattr name:value list.  If it\n * exceeds this, then xattr value data will be successively out of lined\n * until it meets the target */\n#define XATTR_TARGET_MAX\t65536\n\n#define IS_XATTR(a)\t\t(a != SQUASHFS_INVALID_XATTR)\n\nstruct xattr_list {\n\tchar\t\t\t*name;\n\tchar\t\t\t*full_name;\n\tint\t\t\tsize;\n\tint\t\t\tvsize;\n\tvoid\t\t\t*value;\n\tint\t\t\ttype;\n\tlong long\t\tool_value;\n\tunsigned short\t\tvchecksum;\n\tstruct xattr_list\t*vnext;\n};\n\nstruct dupl_id {\n\tstruct xattr_list\t*xattr_list;\n\tint\t\t\txattrs;\n\tint\t\t\txattr_id;\n\tstruct dupl_id\t\t*next;\n};\n\nstruct prefix {\n\tchar\t\t\t*prefix;\n\tint\t\t\ttype;\n};\n\nextern int generate_xattrs(int, struct xattr_list *);\n\n#ifdef XATTR_SUPPORT\nextern int get_xattrs(int, struct squashfs_super_block *);\nextern int read_xattrs(void *);\nextern long long write_xattrs();\nextern int save_xattrs();\nextern void restore_xattrs();\nextern unsigned int xattr_bytes, total_xattr_bytes;\nextern void write_xattr(char *, unsigned int);\nextern int read_xattrs_from_disk(int, struct squashfs_super_block *);\nextern struct xattr_list *get_xattr(int, unsigned int *);\n#else\nstatic inline int get_xattrs(int fd, struct squashfs_super_block *sBlk)\n{\n\tif(sBlk->xattr_id_table_start != SQUASHFS_INVALID_BLK) {\n\t\tfprintf(stderr, \"Xattrs in filesystem! These are not \"\n\t\t\t\"supported on this version of Squashfs\\n\");\n\t\treturn 0;\n\t} else\n\t\treturn SQUASHFS_INVALID_BLK;\n}\n\n\nstatic inline int read_xattrs(void *dir_ent)\n{\n\treturn SQUASHFS_INVALID_XATTR;\n}\n\n\nstatic inline long long write_xattrs()\n{\n\treturn SQUASHFS_INVALID_BLK;\n}\n\n\nstatic inline int save_xattrs()\n{\n\treturn 1;\n}\n\n\nstatic inline void restore_xattrs()\n{\n}\n\n\nstatic inline void write_xattr(char *pathname, unsigned int xattr)\n{\n}\n\n\nstatic inline int read_xattrs_from_disk(int fd, struct squashfs_super_block *sBlk)\n{\n\tif(sBlk->xattr_id_table_start != SQUASHFS_INVALID_BLK) {\n\t\tfprintf(stderr, \"Xattrs in filesystem! These are not \"\n\t\t\t\"supported on this version of Squashfs\\n\");\n\t\treturn 0;\n\t} else\n\t\treturn SQUASHFS_INVALID_BLK;\n}\n\n\nstatic inline struct xattr_list *get_xattr(int i, unsigned int *count)\n{\n\treturn NULL;\n}\n#endif\n\n#ifdef XATTR_SUPPORT\n#ifdef XATTR_DEFAULT\n#define NOXOPT_STR\n#define XOPT_STR \" (default)\"\n#define XATTR_DEF 0\n#else\n#define NOXOPT_STR \" (default)\"\n#define XOPT_STR\n#define XATTR_DEF 1\n#endif\n#else\n#define NOXOPT_STR \" (default)\"\n#define XOPT_STR \" (unsupported)\"\n#define XATTR_DEF 1\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/xz_wrapper.c",
    "content": "/*\n * Copyright (c) 2010, 2011\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * xz_wrapper.c\n *\n * Support for XZ (LZMA2) compression using XZ Utils liblzma\n * http://tukaani.org/xz/\n */\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <lzma.h>\n\n#include \"squashfs_fs.h\"\n#include \"xz_wrapper.h\"\n#include \"compressor.h\"\n#include \"lzma_xz_options.h\"\n\nstatic struct bcj bcj[] = {\n\t{ \"x86\", LZMA_FILTER_X86, 0 },\n\t{ \"powerpc\", LZMA_FILTER_POWERPC, 0 },\n\t{ \"ia64\", LZMA_FILTER_IA64, 0 },\n\t{ \"arm\", LZMA_FILTER_ARM, 0 },\n\t{ \"armthumb\", LZMA_FILTER_ARMTHUMB, 0 },\n\t{ \"sparc\", LZMA_FILTER_SPARC, 0 },\n\t{ NULL, LZMA_VLI_UNKNOWN, 0 }\n};\n\nstatic int filter_count = 1;\n\n\nstatic int xz_options(char *argv[], int argc)\n{\n\tif(strcmp(argv[0], \"-Xbcj\") == 0) {\n\t\tint i;\n\t\tchar *name;\n\n\t\tif(argc < 2) {\n\t\t\tfprintf(stderr, \"xz: -Xbcj missing filter\\n\");\n\t\t\treturn -2;\n\t\t}\n\n\t\tname = argv[1];\n\t\twhile(name[0] != '\\0') {\n\t\t\tfor(i = 0; bcj[i].name; i++) {\n\t\t\t\tint n = strlen(bcj[i].name);\n\t\t\t\tif((strncmp(name, bcj[i].name, n) == 0) &&\n\t\t\t\t\t\t(name[n] == '\\0' ||\n\t\t\t\t\t\t name[n] == ',')) {\n\t\t\t\t\tif(bcj[i].selected == 0) {\n\t\t\t\t \t\tbcj[i].selected = 1;\n\t\t\t\t\t\tfilter_count++;\n\t\t\t\t\t}\n\t\t\t\t\tname += name[n] == ',' ? n + 1 : n;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(bcj[i].name == NULL) {\n\t\t\t\tfprintf(stderr, \"xz: -Xbcj unrecognised \"\n\t\t\t\t\t\t\"filter\\n\");\n\t\t\t\treturn -2;\n\t\t\t}\n\t\t}\n\t\treturn 1;\n\t} else {\n\t\treturn lzma_xz_options(argv, argc, LZMA_OPT_XZ);\n\t}\n}\n\n\nstatic int xz_options_post(int block_size)\n{\n\treturn lzma_xz_options_post(block_size, LZMA_OPT_XZ);\n}\n\n\nstatic void *xz_dump_options(int block_size, int *size)\n{\n\tint i, flags = 0;\n\n\tfor(i = 0; bcj[i].name; i++)\n\t\tflags |= bcj[i].selected << i;\n\n\treturn lzma_xz_dump_options(block_size, size, flags);\n}\n\n\nstatic int xz_extract_options(int block_size, void *buffer, int size)\n{\n\tint ret = lzma_xz_extract_options(block_size, buffer, size, LZMA_OPT_XZ);\n\n\tif (!ret) {\n\t\tint i;\n\t\tstruct lzma_xz_options *opts = lzma_xz_get_options();\n\t\tfor(i = 0; bcj[i].name; i++) {\n\t\t\tif((opts->flags >> i) & 1) {\n\t\t\t\tbcj[i].selected = 1;\n\t\t\t\tfilter_count ++;\n\t\t\t} else\n\t\t\t\tbcj[i].selected = 0;\n\t\t}\n\t}\n\treturn ret;\n}\n\n\nstatic int xz_init(void **strm, int block_size, int datablock)\n{\n\tint i, j, filters = datablock ? filter_count : 1;\n\tstruct filter *filter = malloc(filters * sizeof(struct filter));\n\tstruct xz_stream *stream;\n\tstruct lzma_xz_options *opts = lzma_xz_get_options();\n\n\tif(filter == NULL)\n\t\tgoto failed;\n\n\tstream = *strm = malloc(sizeof(struct xz_stream));\n\tif(stream == NULL)\n\t\tgoto failed2;\n\n\tstream->filter = filter;\n\tstream->filters = filters;\n\n\tmemset(filter, 0, filters * sizeof(struct filter));\n\n\tstream->dictionary_size = datablock ? opts->dict_size :\n\t\tSQUASHFS_METADATA_SIZE;\n\n\tfilter[0].filter[0].id = LZMA_FILTER_LZMA2;\n\tfilter[0].filter[0].options = &stream->opt;\n\tfilter[0].filter[1].id = LZMA_VLI_UNKNOWN;\n\n\tfor(i = 0, j = 1; datablock && bcj[i].name; i++) {\n\t\tif(bcj[i].selected) {\n\t\t\tfilter[j].buffer = malloc(block_size);\n\t\t\tif(filter[j].buffer == NULL)\n\t\t\t\tgoto failed3;\n\t\t\tfilter[j].filter[0].id = bcj[i].id;\n\t\t\tfilter[j].filter[1].id = LZMA_FILTER_LZMA2;\n\t\t\tfilter[j].filter[1].options = &stream->opt;\n\t\t\tfilter[j].filter[2].id = LZMA_VLI_UNKNOWN;\n\t\t\tj++;\n\t\t}\n\t}\n\n\treturn 0;\n\nfailed3:\n\tfor(i = 1; i < filters; i++)\n\t\tfree(filter[i].buffer);\n\tfree(stream);\n\nfailed2:\n\tfree(filter);\n\nfailed:\n\treturn -1;\n}\n\n\nstatic int xz_compress(void *strm, void *dest, void *src,  int size,\n\tint block_size, int *error)\n{\n\tint i;\n        lzma_ret res = 0;\n\tstruct xz_stream *stream = strm;\n\tstruct filter *selected = NULL;\n\tstruct lzma_xz_options *opts = lzma_xz_get_options();\n\n\tstream->filter[0].buffer = dest;\n\n\tfor(i = 0; i < stream->filters; i++) {\n\t\tuint32_t preset = opts->preset;\n\t\tstruct filter *filter = &stream->filter[i];\n\n\t\tif (opts->extreme)\n\t\t\tpreset |= LZMA_PRESET_EXTREME;\n\n        if(lzma_lzma_preset(&stream->opt, preset))\n               \tgoto failed;\n\n        stream->opt.lc = opts->lc;\n    \tstream->opt.lp = opts->lp;\n    \tstream->opt.pb = opts->pb;\n    \tif (opts->fb)\n    \t\tstream->opt.nice_len = opts->fb;\n\n\t\tstream->opt.dict_size = stream->dictionary_size;\n\n\t\tfilter->length = 0;\n\t\tres = lzma_stream_buffer_encode(filter->filter,\n\t\t\tLZMA_CHECK_CRC32, NULL, src, size, filter->buffer,\n\t\t\t&filter->length, block_size);\n\t\n\t\tif(res == LZMA_OK) {\n\t\t\tif(!selected || selected->length > filter->length)\n\t\t\t\tselected = filter;\n\t\t} else if(res != LZMA_BUF_ERROR)\n\t\t\tgoto failed;\n\t}\n\n\tif(!selected)\n\t\t/*\n\t \t * Output buffer overflow.  Return out of buffer space\n\t \t */\n\t\treturn 0;\n\n\tif(selected->buffer != dest)\n\t\tmemcpy(dest, selected->buffer, selected->length);\n\n\treturn (int) selected->length;\n\nfailed:\n\t/*\n\t * All other errors return failure, with the compressor\n\t * specific error code in *error\n\t */\n\t*error = res;\n\treturn -1;\n}\n\n\nstatic int xz_uncompress(void *dest, void *src, int size, int block_size,\n\tint *error)\n{\n\tsize_t src_pos = 0;\n\tsize_t dest_pos = 0;\n\tuint64_t memlimit = MEMLIMIT;\n\n\tlzma_ret res = lzma_stream_buffer_decode(&memlimit, 0, NULL,\n\t\t\tsrc, &src_pos, size, dest, &dest_pos, block_size);\n\n\t*error = res;\n\treturn res == LZMA_OK && size == (int) src_pos ? (int) dest_pos : -1;\n}\n\n\nvoid xz_usage()\n{\n\tlzma_xz_usage(LZMA_OPT_XZ);\n\tfprintf(stderr, \"\\t  -Xbcj filter1,filter2,...,filterN\\n\");\n\tfprintf(stderr, \"\\t\\tCompress using filter1,filter2,...,filterN in\");\n\tfprintf(stderr, \" turn\\n\\t\\t(in addition to no filter), and choose\");\n\tfprintf(stderr, \" the best compression.\\n\");\n\tfprintf(stderr, \"\\t\\tAvailable filters: x86, arm, armthumb,\");\n\tfprintf(stderr, \" powerpc, sparc, ia64\\n\");\n}\n\n\nstruct compressor xz_comp_ops = {\n\t.init = xz_init,\n\t.compress = xz_compress,\n\t.uncompress = xz_uncompress,\n\t.options = xz_options,\n\t.options_post = xz_options_post,\n\t.dump_options = xz_dump_options,\n\t.extract_options = xz_extract_options,\n\t.usage = xz_usage,\n\t.id = XZ_COMPRESSION,\n\t.name = \"xz\",\n\t.supported = 1\n};\n"
  },
  {
    "path": "src/others/squashfs-4.2/squashfs-tools/xz_wrapper.h",
    "content": "#ifndef XZ_WRAPPER_H\n#define XZ_WRAPPER_H\n/*\n * Squashfs\n *\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * xz_wrapper.h\n *\n */\n\n#define MEMLIMIT (32 * 1024 * 1024)\n\nstruct bcj {\n\tchar\t \t*name;\n\tlzma_vli\tid;\n\tint\t\tselected;\n};\n\nstruct filter {\n\tvoid\t\t*buffer;\n\tlzma_filter\tfilter[3];\n\tsize_t\t\tlength;\n};\n\nstruct xz_stream {\n\tstruct filter\t*filter;\n\tint\t\tfilters;\n\tint\t\tdictionary_size;\n\tlzma_options_lzma opt;\n};\n\nstruct comp_opts {\n\tint dictionary_size;\n\tint flags;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/Makefile",
    "content": "###############################################\n#          Compression build options          #\n###############################################\n#\n#\n############# Building gzip support ###########\n#\n# Gzip support is by default enabled, and the compression type default\n# (COMP_DEFAULT) is gzip.\n#\n# If you don't want/need gzip support then comment out the GZIP SUPPORT line\n# below, and change COMP_DEFAULT to one of the compression types you have\n# selected.\n#\n# Obviously, you must select at least one of the available gzip, lzma, lzo\n# compression types.\n#\nGZIP_SUPPORT = 1\n\n########### Building XZ support #############\n#\n# LZMA2 compression.\n#\n# XZ Utils liblzma (http://tukaani.org/xz/) is supported\n#\n# To build using XZ Utils liblzma - install the library and uncomment\n# the XZ_SUPPORT line below.\n#\nXZ_SUPPORT = 1\n\n\n############ Building LZO support ##############\n#\n# The LZO library (http://www.oberhumer.com/opensource/lzo/) is supported.\n#\n# To build using the LZO library - install the library and uncomment the\n# LZO_SUPPORT line below. If needed, uncomment and set LZO_DIR to the\n# installation prefix.\n#\n#LZO_SUPPORT = 1\n#LZO_DIR = /usr/local\n\n########### Building LZMA support #############\n#\n# LZMA1 compression.\n#\n# LZMA1 compression is deprecated, and the newer and better XZ (LZMA2)\n# compression should be used in preference.\n#\n# Both XZ Utils liblzma (http://tukaani.org/xz/) and LZMA SDK\n# (http://www.7-zip.org/sdk.html) are supported\n#\n# To build using XZ Utils liblzma - install the library and uncomment\n# the LZMA_XZ_SUPPORT line below.\n#\n# To build using the LZMA SDK (4.65 used in development, other versions may\n# work) - download and unpack it, uncomment and set LZMA_DIR to unpacked source,\n# and uncomment the LZMA_SUPPORT line below.\n#\nLZMA_XZ_SUPPORT = 1\n#LZMA_SUPPORT = 1\n#LZMA_DIR = ../../../../LZMA/lzma465\n\n######## Specifying default compression ########\n#\n# The next line specifies which compression algorithm is used by default\n# in Mksquashfs.  Obviously the compression algorithm must have been\n# selected to be built\n#\nCOMP_DEFAULT = gzip\n\n###############################################\n#  Extended attribute (XATTRs) build options  #\n###############################################\n#\n# Building XATTR support for Mksquashfs and Unsquashfs\n#\n# If your C library or build/target environment doesn't support XATTRs then\n# comment out the next line to build Mksquashfs and Unsquashfs without XATTR\n# support\nXATTR_SUPPORT = 1\n\n# Select whether you wish xattrs to be stored by Mksquashfs and extracted\n# by Unsquashfs by default.  If selected users can disable xattr support by\n# using the -no-xattrs option\n#\n# If unselected, Mksquashfs/Unsquashfs won't store and extract xattrs by\n# default.  Users can enable xattrs by using the -xattrs option.\nXATTR_DEFAULT = 1\n\n\n###############################################\n#        End of BUILD options section         #\n###############################################\n\nINCLUDEDIR = -I.\nINSTALL_DIR = /usr/local/bin\n\nMKSQUASHFS_OBJS = mksquashfs.o read_fs.o sort.o swap.o pseudo.o compressor.o\n\nUNSQUASHFS_OBJS = unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o \\\n\tunsquash-4.o swap.o compressor.o\n\nCFLAGS ?= -O2\nCFLAGS += $(EXTRA_CFLAGS) $(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 \\\n\t-D_LARGEFILE_SOURCE -D_GNU_SOURCE -DCOMP_DEFAULT=\\\"$(COMP_DEFAULT)\\\" \\\n\t-Wall\n\nLIBS = -lpthread -lm\nifeq ($(GZIP_SUPPORT),1)\nCFLAGS += -DGZIP_SUPPORT\nMKSQUASHFS_OBJS += gzip_wrapper.o\nUNSQUASHFS_OBJS += gzip_wrapper.o\nLIBS += -lz\nCOMPRESSORS += gzip\nendif\n\nifeq ($(LZMA_SUPPORT),1)\nLZMA_OBJS = $(LZMA_DIR)/C/Alloc.o $(LZMA_DIR)/C/LzFind.o \\\n\t$(LZMA_DIR)/C/LzmaDec.o $(LZMA_DIR)/C/LzmaEnc.o $(LZMA_DIR)/C/LzmaLib.o\nINCLUDEDIR += -I$(LZMA_DIR)/C\nCFLAGS += -DLZMA_SUPPORT\nMKSQUASHFS_OBJS += lzma_wrapper.o $(LZMA_OBJS)\nUNSQUASHFS_OBJS += lzma_wrapper.o $(LZMA_OBJS)\nCOMPRESSORS += lzma\nendif\n\nifeq ($(LZMA_XZ_SUPPORT),1)\nCFLAGS += -DLZMA_SUPPORT\nMKSQUASHFS_OBJS += lzma_xz_wrapper.o\nUNSQUASHFS_OBJS += lzma_xz_wrapper.o\nLIBS += -llzma\nCOMPRESSORS += lzma\nendif\n\nifeq ($(XZ_SUPPORT),1)\nCFLAGS += -DXZ_SUPPORT\nMKSQUASHFS_OBJS += xz_wrapper.o\nUNSQUASHFS_OBJS += xz_wrapper.o\nLIBS += -llzma\nCOMPRESSORS += xz\nendif\n\nifeq ($(LZO_SUPPORT),1)\nCFLAGS += -DLZO_SUPPORT\nifdef LZO_DIR\nINCLUDEDIR += -I$(LZO_DIR)/include\nLZO_LIBDIR = -L$(LZO_DIR)/lib\nendif\nMKSQUASHFS_OBJS += lzo_wrapper.o\nUNSQUASHFS_OBJS += lzo_wrapper.o\nLIBS += $(LZO_LIBDIR) -llzo2\nCOMPRESSORS += lzo\nendif\n\nifeq ($(XATTR_SUPPORT),1)\nifeq ($(XATTR_DEFAULT),1)\nCFLAGS += -DXATTR_SUPPORT -DXATTR_DEFAULT\nelse\nCFLAGS += -DXATTR_SUPPORT\nendif\nMKSQUASHFS_OBJS += xattr.o read_xattrs.o\nUNSQUASHFS_OBJS += read_xattrs.o unsquashfs_xattr.o\nendif\n\n#\n# If LZMA_SUPPORT is specified then LZMA_DIR must be specified too\n#\nifeq ($(LZMA_SUPPORT),1)\nifndef LZMA_DIR\n$(error \"LZMA_SUPPORT requires LZMA_DIR to be also defined\")\nendif\nendif\n\n#\n# Both LZMA_XZ_SUPPORT and LZMA_SUPPORT cannot be specified\n#\nifeq ($(LZMA_XZ_SUPPORT),1)\nifeq ($(LZMA_SUPPORT),1)\n$(error \"Both LZMA_XZ_SUPPORT and LZMA_SUPPORT cannot be specified\")\nendif\nendif\n\n#\n# At least one compressor must have been selected\n#\nifndef COMPRESSORS\n$(error \"No compressor selected! Select one or more of GZIP, LZMA, XZ or LZO!\")\nendif\n\n#\n# COMP_DEFAULT must be a selected compressor\n#\nifeq (, $(findstring $(COMP_DEFAULT), $(COMPRESSORS)))\n$(error \"COMP_DEFAULT isn't selected to be built!\")\nendif\n\n.PHONY: all\nall: mksquashfs unsquashfs\n\nmksquashfs: $(MKSQUASHFS_OBJS)\n\t$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) $(MKSQUASHFS_OBJS) $(LIBS) -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h sort.h squashfs_swap.h \\\n\txattr.h pseudo.h compressor.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h squashfs_swap.h compressor.h \\\n\txattr.h\n\nsort.o: sort.c squashfs_fs.h sort.h mksquashfs.h\n\nswap.o: swap.c\n\npseudo.o: pseudo.c pseudo.h\n\ncompressor.o: compressor.c compressor.h squashfs_fs.h\n\nxattr.o: xattr.c xattr.h squashfs_fs.h squashfs_swap.h mksquashfs.h\n\nread_xattrs.o: read_xattrs.c xattr.h squashfs_fs.h squashfs_swap.h read_fs.h\n\ngzip_wrapper.o: gzip_wrapper.c compressor.h squashfs_fs.h\n\nlzma_wrapper.o: lzma_wrapper.c compressor.h squashfs_fs.h\n\nlzma_xz_wrapper.o: lzma_xz_wrapper.c compressor.h squashfs_fs.h\n\nlzo_wrapper.o: lzo_wrapper.c compressor.h squashfs_fs.h\n\nxz_wrapper.o: xz_wrapper.c compressor.h squashfs_fs.h\n\nunsquashfs: $(UNSQUASHFS_OBJS)\n\t$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) $(UNSQUASHFS_OBJS) $(LIBS) -o $@\n\nunsquashfs.o: unsquashfs.h unsquashfs.c squashfs_fs.h squashfs_swap.h \\\n\tsquashfs_compat.h xattr.h read_fs.h compressor.h\n\nunsquash-1.o: unsquashfs.h unsquash-1.c squashfs_fs.h squashfs_compat.h\n\nunsquash-2.o: unsquashfs.h unsquash-2.c squashfs_fs.h squashfs_compat.h\n\nunsquash-3.o: unsquashfs.h unsquash-3.c squashfs_fs.h squashfs_compat.h\n\nunsquash-4.o: unsquashfs.h unsquash-4.c squashfs_fs.h squashfs_swap.h \\\n\tread_fs.h\n\nunsquashfs_xattr.o: unsquashfs_xattr.c unsquashfs.h squashfs_fs.h xattr.h\n\n\n.PHONY: clean\nclean:\n\t-rm -f *.o mksquashfs unsquashfs\n\n.PHONY: install\ninstall: mksquashfs unsquashfs\n\tmkdir -p $(INSTALL_DIR)\n\tcp mksquashfs $(INSTALL_DIR)\n\tcp unsquashfs $(INSTALL_DIR)\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/compressor.c",
    "content": "/*\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * compressor.c\n */\n\n#include <stdio.h>\n#include <string.h>\n#include \"compressor.h\"\n#include \"squashfs_fs.h\"\n\n#ifndef GZIP_SUPPORT\nstatic struct compressor gzip_comp_ops =  {\n\tNULL, NULL, NULL, NULL, NULL, NULL, ZLIB_COMPRESSION, \"gzip\", 0\n};\n#else\nextern struct compressor gzip_comp_ops;\n#endif\n\n#ifndef LZMA_SUPPORT\nstatic struct compressor lzma_comp_ops = {\n\tNULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, LZMA_COMPRESSION,\n\t\"lzma\", 0\n};\n#else\nextern struct compressor lzma_comp_ops;\n#endif\n\n#ifndef LZO_SUPPORT\nstatic struct compressor lzo_comp_ops = {\n\tNULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, LZO_COMPRESSION, \"lzo\",\n\t0\n};\n#else\nextern struct compressor lzo_comp_ops;\n#endif\n\n#ifndef XZ_SUPPORT\nstatic struct compressor xz_comp_ops = {\n\tNULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, XZ_COMPRESSION, \"xz\", 0\n};\n#else\nextern struct compressor xz_comp_ops;\n#endif\n\n\nstatic struct compressor unknown_comp_ops = {\n\tNULL, NULL, NULL , NULL, NULL, NULL, NULL, NULL, 0, \"unknown\", 0\n};\n\n\nstruct compressor *compressor[] = {\n\t&gzip_comp_ops,\n\t&lzma_comp_ops,\n\t&lzo_comp_ops,\n\t&xz_comp_ops,\n\t&unknown_comp_ops\n};\n\n\nstruct compressor *lookup_compressor(char *name)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i]->id; i++)\n\t\tif(strcmp(compressor[i]->name, name) == 0)\n\t\t\tbreak;\n\n\treturn compressor[i];\n}\n\n\nstruct compressor *lookup_compressor_id(int id)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i]->id; i++)\n\t\tif(id == compressor[i]->id)\n\t\t\tbreak;\n\n\treturn compressor[i];\n}\n\n\nvoid display_compressors(char *indent, char *def_comp)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i]->id; i++)\n\t\tif(compressor[i]->supported)\n\t\t\tfprintf(stderr, \"%s\\t%s%s\\n\", indent,\n\t\t\t\tcompressor[i]->name,\n\t\t\t\tstrcmp(compressor[i]->name, def_comp) == 0 ?\n\t\t\t\t\" (default)\" : \"\");\n}\n\n\nvoid display_compressor_usage(char *def_comp)\n{\n\tint i;\n\n\tfor(i = 0; compressor[i]->id; i++)\n\t\tif(compressor[i]->supported) {\n\t\t\tchar *str = strcmp(compressor[i]->name, def_comp) == 0 ?\n\t\t\t\t\" (default)\" : \"\";\n\t\t\tif(compressor[i]->usage) {\n\t\t\t\tfprintf(stderr, \"\\t%s%s\\n\",\n\t\t\t\t\tcompressor[i]->name, str);\n\t\t\t\tcompressor[i]->usage();\n\t\t\t} else\n\t\t\t\tfprintf(stderr, \"\\t%s (no options)%s\\n\",\n\t\t\t\t\tcompressor[i]->name, str);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/compressor.h",
    "content": "/*\n *\n * Copyright (c) 2009, 2010, 2011\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * compressor.h\n */\n\nstruct compressor {\n\tint (*init)(void **, int, int);\n\tint (*compress)(void *, void *, void *, int, int, int *);\n\tint (*uncompress)(void *, void *, int, int, int *);\n\tint (*options)(char **, int);\n\tint (*options_post)(int);\n\tvoid *(*dump_options)(int, int *);\n\tint (*extract_options)(int, void *, int);\n\tvoid (*usage)();\n\tint id;\n\tchar *name;\n\tint supported;\n};\n\nextern struct compressor *lookup_compressor(char *);\nextern struct compressor *lookup_compressor_id(int);\nextern void display_compressors(char *, char *);\nextern void display_compressor_usage(char *);\n\nstatic inline int compressor_init(struct compressor *comp, void **stream,\n\tint block_size, int datablock)\n{\n\tif(comp->init == NULL)\n\t\treturn 0;\n\treturn comp->init(stream, block_size, datablock);\n}\n\n\nstatic inline int compressor_compress(struct compressor *comp, void *strm,\n\tvoid *dest, void *src, int size, int block_size, int *error)\n{\n\treturn comp->compress(strm, dest, src, size, block_size, error);\n}\n\n\nstatic inline int compressor_uncompress(struct compressor *comp, void *dest,\n\tvoid *src, int size, int block_size, int *error)\n{\n\treturn comp->uncompress(dest, src, size, block_size, error);\n}\n\n\nstatic inline int compressor_options(struct compressor *comp, char *argv[],\n\tint argc)\n{\n\tif(comp->options == NULL)\n\t\treturn -1;\n\n\treturn comp->options(argv, argc);\n}\n\n\nstatic inline int compressor_options_post(struct compressor *comp, int block_size)\n{\n\tif(comp->options_post == NULL)\n\t\treturn 0;\n\treturn comp->options_post(block_size);\n}\n\n\nstatic inline void *compressor_dump_options(struct compressor *comp,\n\tint block_size, int *size)\n{\n\tif(comp->dump_options == NULL)\n\t\treturn NULL;\n\treturn comp->dump_options(block_size, size);\n}\n\n\nstatic inline int compressor_extract_options(struct compressor *comp,\n\tint block_size, void *buffer, int size)\n{\n\tif(comp->extract_options == NULL)\n\t\treturn size ? -1 : 0;\n\treturn comp->extract_options(block_size, buffer, size);\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/gzip_wrapper.c",
    "content": "/*\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * gzip_wrapper.c\n */\n\n#include <stdlib.h>\n#include <zlib.h>\n\n#include \"squashfs_fs.h\"\n#include \"compressor.h\"\n\nstatic int gzip_init(void **strm, int block_size, int flags)\n{\n\tint res;\n\tz_stream *stream;\n\n\tstream = *strm = malloc(sizeof(z_stream));\n\tif(stream == NULL)\n\t\tgoto failed;\n\n\tstream->zalloc = Z_NULL;\n\tstream->zfree = Z_NULL;\n\tstream->opaque = 0;\n\n\tres = deflateInit(stream, 9);\n\tif(res != Z_OK)\n\t\tgoto failed2;\n\n\treturn 0;\n\nfailed2:\n\tfree(stream);\nfailed:\n\treturn -1;\n}\n\n\nstatic int gzip_compress(void *strm, void *d, void *s, int size, int block_size,\n\t\tint *error)\n{\n\tint res;\n\tz_stream *stream = strm;\n\n\tres = deflateReset(stream);\n\tif(res != Z_OK)\n\t\tgoto failed;\n\n\tstream->next_in = s;\n\tstream->avail_in = size;\n\tstream->next_out = d;\n\tstream->avail_out = block_size;\n\n\tres = deflate(stream, Z_FINISH);\n\tif(res == Z_STREAM_END)\n\t\t/*\n\t\t * Success, return the compressed size.\n\t\t */\n\t\treturn (int) stream->total_out;\n\tif(res == Z_OK)\n\t\t/*\n\t\t * Output buffer overflow.  Return out of buffer space\n\t\t */\n\t\treturn 0;\nfailed:\n\t/*\n\t * All other errors return failure, with the compressor\n\t * specific error code in *error\n\t */\n\t*error = res;\n\treturn -1;\n}\n\n\nstatic int gzip_uncompress(void *d, void *s, int size, int block_size, int *error)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\n\tres = uncompress(d, &bytes, s, size);\n\n\t*error = res;\n\treturn res == Z_OK ? (int) bytes : -1;\n}\n\n\nstruct compressor gzip_comp_ops = {\n\t.init = gzip_init,\n\t.compress = gzip_compress,\n\t.uncompress = gzip_uncompress,\n\t.options = NULL,\n\t.usage = NULL,\n\t.id = ZLIB_COMPRESSION,\n\t.name = \"gzip\",\n\t.supported = 1\n};\n\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/lzma_wrapper.c",
    "content": "/*\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * lzma_wrapper.c\n *\n * Support for LZMA1 compression using LZMA SDK (4.65 used in\n * development, other versions may work) http://www.7-zip.org/sdk.html\n */\n\n#include <LzmaLib.h>\n\n#include \"squashfs_fs.h\"\n#include \"compressor.h\"\n\n#define LZMA_HEADER_SIZE\t(LZMA_PROPS_SIZE + 8)\n\nstatic int lzma_compress(void *strm, void *dest, void *src, int size, int block_size,\n\t\tint *error)\n{\n\tunsigned char *d = dest;\n\tsize_t props_size = LZMA_PROPS_SIZE,\n\t\toutlen = block_size - LZMA_HEADER_SIZE;\n\tint res;\n\n\tres = LzmaCompress(dest + LZMA_HEADER_SIZE, &outlen, src, size, dest,\n\t\t&props_size, 5, block_size, 3, 0, 2, 32, 1);\n\t\n\tif(res == SZ_ERROR_OUTPUT_EOF) {\n\t\t/*\n\t\t * Output buffer overflow.  Return out of buffer space error\n\t\t */\n\t\treturn 0;\n\t}\n\n\tif(res != SZ_OK) {\n\t\t/*\n\t\t * All other errors return failure, with the compressor\n\t\t * specific error code in *error\n\t\t */\n\t\t*error = res;\n\t\treturn -1;\n\t}\n\n\t/*\n\t * Fill in the 8 byte little endian uncompressed size field in the\n\t * LZMA header.  8 bytes is excessively large for squashfs but\n\t * this is the standard LZMA header and which is expected by the kernel\n\t * code\n\t */\n\td[LZMA_PROPS_SIZE] = size & 255;\n\td[LZMA_PROPS_SIZE + 1] = (size >> 8) & 255;\n\td[LZMA_PROPS_SIZE + 2] = (size >> 16) & 255;\n\td[LZMA_PROPS_SIZE + 3] = (size >> 24) & 255;\n\td[LZMA_PROPS_SIZE + 4] = 0;\n\td[LZMA_PROPS_SIZE + 5] = 0;\n\td[LZMA_PROPS_SIZE + 6] = 0;\n\td[LZMA_PROPS_SIZE + 7] = 0;\n\n\t/*\n\t * Success, return the compressed size.  Outlen returned by the LZMA\n\t * compressor does not include the LZMA header space\n\t */\n\treturn outlen + LZMA_HEADER_SIZE;\n}\n\n\nstatic int lzma_uncompress(void *dest, void *src, int size, int block_size,\n\tint *error)\n{\n\tunsigned char *s = src;\n\tsize_t outlen, inlen = size - LZMA_HEADER_SIZE;\n\tint res;\n\n\toutlen = s[LZMA_PROPS_SIZE] |\n\t\t(s[LZMA_PROPS_SIZE + 1] << 8) |\n\t\t(s[LZMA_PROPS_SIZE + 2] << 16) |\n\t\t(s[LZMA_PROPS_SIZE + 3] << 24);\n\n\tres = LzmaUncompress(dest, &outlen, src + LZMA_HEADER_SIZE, &inlen, src,\n\t\tLZMA_PROPS_SIZE);\n\t\n\t*error = res;\n\treturn res == SZ_OK ? outlen : -1;\n}\n\n\nstruct compressor lzma_comp_ops = {\n\t.init = NULL,\n\t.compress = lzma_compress,\n\t.uncompress = lzma_uncompress,\n\t.options = NULL,\n\t.usage = NULL,\n\t.id = LZMA_COMPRESSION,\n\t.name = \"lzma\",\n\t.supported = 1\n};\n\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/lzma_xz_wrapper.c",
    "content": "/*\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * lzma_xz_wrapper.c\n *\n * Support for LZMA1 compression using XZ Utils liblzma http://tukaani.org/xz/\n */\n\n#include <stdio.h>\n#include <string.h>\n#include <lzma.h>\n\n#include \"squashfs_fs.h\"\n#include \"compressor.h\"\n\n#define LZMA_PROPS_SIZE 5\n#define LZMA_UNCOMP_SIZE 8\n#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + LZMA_UNCOMP_SIZE)\n\n#define LZMA_OPTIONS 5\n#define MEMLIMIT (32 * 1024 * 1024)\n\nstatic int lzma_compress(void *dummy, void *dest, void *src,  int size,\n\tint block_size, int *error)\n{\n\tunsigned char *d = (unsigned char *) dest;\n\tlzma_options_lzma opt;\n\tlzma_stream strm = LZMA_STREAM_INIT;\n\tint res;\n\n\tlzma_lzma_preset(&opt, LZMA_OPTIONS);\n\topt.dict_size = block_size;\n\n\tres = lzma_alone_encoder(&strm, &opt);\n\tif(res != LZMA_OK) {\n\t\tlzma_end(&strm);\n\t\tgoto failed;\n\t}\n\n\tstrm.next_out = dest;\n\tstrm.avail_out = block_size;\n\tstrm.next_in = src;\n\tstrm.avail_in = size;\n\n\tres = lzma_code(&strm, LZMA_FINISH);\n\tlzma_end(&strm);\n\n\tif(res == LZMA_STREAM_END) {\n\t\t/*\n\t \t * Fill in the 8 byte little endian uncompressed size field in\n\t\t * the LZMA header.  8 bytes is excessively large for squashfs\n\t\t * but this is the standard LZMA header and which is expected by\n\t\t * the kernel code\n\t \t */\n\n\t\td[LZMA_PROPS_SIZE] = size & 255;\n\t\td[LZMA_PROPS_SIZE + 1] = (size >> 8) & 255;\n\t\td[LZMA_PROPS_SIZE + 2] = (size >> 16) & 255;\n\t\td[LZMA_PROPS_SIZE + 3] = (size >> 24) & 255;\n\t\td[LZMA_PROPS_SIZE + 4] = 0;\n\t\td[LZMA_PROPS_SIZE + 5] = 0;\n\t\td[LZMA_PROPS_SIZE + 6] = 0;\n\t\td[LZMA_PROPS_SIZE + 7] = 0;\n\n\t\treturn (int) strm.total_out;\n\t}\n\n\tif(res == LZMA_OK)\n\t\t/*\n\t \t * Output buffer overflow.  Return out of buffer space\n\t \t */\n\t\treturn 0;\n\nfailed:\n\t/*\n\t * All other errors return failure, with the compressor\n\t * specific error code in *error\n\t */\n\t*error = res;\n\treturn -1;\n}\n\n\nstatic int lzma_uncompress(void *dest, void *src, int size, int block_size,\n\tint *error)\n{\n\tlzma_stream strm = LZMA_STREAM_INIT;\n\tint uncompressed_size = 0, res;\n\tunsigned char lzma_header[LZMA_HEADER_SIZE];\n\n\tres = lzma_alone_decoder(&strm, MEMLIMIT);\n\tif(res != LZMA_OK) {\n\t\tlzma_end(&strm);\n\t\tgoto failed;\n\t}\n\n\tmemcpy(lzma_header, src, LZMA_HEADER_SIZE);\n\tuncompressed_size = lzma_header[LZMA_PROPS_SIZE] |\n\t\t(lzma_header[LZMA_PROPS_SIZE + 1] << 8) |\n\t\t(lzma_header[LZMA_PROPS_SIZE + 2] << 16) |\n\t\t(lzma_header[LZMA_PROPS_SIZE + 3] << 24);\n\tmemset(lzma_header + LZMA_PROPS_SIZE, 255, LZMA_UNCOMP_SIZE);\n\n\tstrm.next_out = dest;\n\tstrm.avail_out = block_size;\n\tstrm.next_in = lzma_header;\n\tstrm.avail_in = LZMA_HEADER_SIZE;\n\n\tres = lzma_code(&strm, LZMA_RUN);\n\n\tif(res != LZMA_OK || strm.avail_in != 0) {\n\t\tlzma_end(&strm);\n\t\tgoto failed;\n\t}\n\n\tstrm.next_in = src + LZMA_HEADER_SIZE;\n\tstrm.avail_in = size - LZMA_HEADER_SIZE;\n\n\tres = lzma_code(&strm, LZMA_FINISH);\n\tlzma_end(&strm);\n\n\tif(res == LZMA_STREAM_END || (res == LZMA_OK &&\n\t\tstrm.total_out >= uncompressed_size && strm.avail_in == 0))\n\t\treturn uncompressed_size;\n\nfailed:\n\t*error = res;\n\treturn -1;\n}\n\n\nstruct compressor lzma_comp_ops = {\n\t.init = NULL,\n\t.compress = lzma_compress,\n\t.uncompress = lzma_uncompress,\n\t.options = NULL,\n\t.usage = NULL,\n\t.id = LZMA_COMPRESSION,\n\t.name = \"lzma\",\n\t.supported = 1\n};\n\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/lzo_wrapper.c",
    "content": "/*\n * Copyright (c) 2010 LG Electronics\n * Chan Jeong <chan.jeong@lge.com>\n *\n * All modifications Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * lzo_wrapper.c\n */\n\n#include <stdlib.h>\n#include <string.h>\n\n#include <lzo/lzoconf.h>\n#include <lzo/lzo1x.h>\n\n#include \"squashfs_fs.h\"\n#include \"compressor.h\"\n\n/* worst-case expansion calculation during compression,\n   see LZO FAQ for more information */\n#define LZO_OUTPUT_BUFFER_SIZE(size)\t(size + (size/16) + 64 + 3)\n\nstruct lzo_stream {\n\tlzo_voidp wrkmem;\n\tlzo_bytep out;\n};\n\n\nstatic int squashfs_lzo_init(void **strm, int block_size, int flags)\n{\n\tstruct lzo_stream *stream;\n\n\tif((stream = *strm = malloc(sizeof(struct lzo_stream))) == NULL)\n\t\tgoto failed;\n\t/* work memory for compression */\n\tif((stream->wrkmem = malloc(LZO1X_999_MEM_COMPRESS)) == NULL)\n\t\tgoto failed2;\n\t/* temporal output buffer */\n\tif((stream->out = malloc(LZO_OUTPUT_BUFFER_SIZE(block_size))) == NULL)\n\t\tgoto failed3;\n\n\treturn 0;\n\nfailed3:\n\tfree(stream->wrkmem);\nfailed2:\n\tfree(stream);\nfailed:\n\treturn -1;\n}\n\n\nstatic int lzo_compress(void *strm, void *d, void *s, int size, int block_size,\n\t\tint *error)\n{\n\tint res;\n\tlzo_uint outlen;\n\tstruct lzo_stream *stream = strm;\n\n\tres = lzo1x_999_compress(s, size, stream->out, &outlen, stream->wrkmem);\n\tif(res != LZO_E_OK)\n\t\tgoto failed;\n\tif(outlen >= size)\n\t\t/*\n\t\t * Output buffer overflow. Return out of buffer space\n\t\t */\n\t\treturn 0;\n\n\t/*\n\t * Success, return the compressed size.\n\t */\n\tmemcpy(d, stream->out, outlen);\n\treturn outlen;\n\nfailed:\n\t/*\n\t * All other errors return failure, with the compressor\n\t * specific error code in *error\n\t */\n\t*error = res;\n\treturn -1;\n}\n\n\nstatic int lzo_uncompress(void *d, void *s, int size, int block_size, int *error)\n{\n\tint res;\n\tlzo_uint bytes = block_size;\n\n\tres = lzo1x_decompress_safe(s, size, d, &bytes, NULL);\n\n\t*error = res;\n\treturn res == LZO_E_OK ? bytes : -1;\n}\n\n\nstruct compressor lzo_comp_ops = {\n\t.init = squashfs_lzo_init,\n\t.compress = lzo_compress,\n\t.uncompress = lzo_uncompress,\n\t.options = NULL,\n\t.usage = NULL,\n\t.id = LZO_COMPRESSION,\n\t.name = \"lzo\",\n\t.supported = 1\n};\n\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <stddef.h>\n#include <sys/time.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/ioctl.h>\n#include <sys/types.h>\n#include <sys/mman.h>\n#include <pthread.h>\n#include <math.h>\n#include <regex.h>\n#include <fnmatch.h>\n#include <sys/wait.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#include <sys/sysctl.h>\n#else\n#include <endian.h>\n#include <sys/sysinfo.h>\n#endif\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tprintf(\"\\n\"); \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...) \\\n\t\tdo {\\\n\t\t\t if(!silent)\\\n\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t} while(0)\n\n#define ERROR(s, args...) \\\n\t\tdo {\\\n\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t} while(0)\n\n#define EXIT_MKSQUASHFS() \\\n\t\tdo {\\\n\t\t\tif(restore)\\\n\t\t\t\trestorefs();\\\n\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\tunlink(destination_file);\\\n\t\t\texit(1);\\\n\t\t} while(0)\n\n#define BAD_ERROR(s, args...) \\\n\t\tdo {\\\n\t\t\tpthread_mutex_lock(&progress_mutex); \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\tpthread_mutex_unlock(&progress_mutex); \\\n\t\t\tEXIT_MKSQUASHFS();\\\n\t\t} while(0)\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"mksquashfs.h\"\n#include \"sort.h\"\n#include \"pseudo.h\"\n#include \"compressor.h\"\n#include \"xattr.h\"\n\nint delete = FALSE;\nint fd;\nint cur_uncompressed = 0, estimated_uncompressed = 0;\nint columns;\n\n/* filesystem flags for building */\nint comp_opts = FALSE;\nint no_xattrs = XATTR_DEF, noX = 0;\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0;\nint silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint exportable = TRUE;\nint progress = TRUE;\nint progress_enabled = FALSE;\nint sparse_files = TRUE;\nint old_exclude = TRUE;\nint use_regex = FALSE;\nint first_freelist = TRUE;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned int id_count = 0;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0,\n\tsock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* inode lookup table */\nsquashfs_inode *inode_lookup_table = NULL;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tstruct squashfs_dir_index\tindex;\n\tchar\t\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536];\nint dup_files = 0;\n\n/* exclude file handling */\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint old_excluded(char *filename, struct stat *buf);\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\nstruct pathnames *paths = NULL;\nstruct pathname *path = NULL;\nstruct pathname *stickypath = NULL;\nint excluded(struct pathnames *paths, char *name, struct pathnames **new);\n\n/* fragment block data structures */\nint fragments = 0;\nstruct file_buffer *fragment_data = NULL;\nint fragment_size = 0;\n\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n\n#define FRAG_SIZE 32768\n#define FRAG_INDEX (1LL << 32)\n\nstruct squashfs_fragment_entry *fragment_table = NULL;\nint fragments_outstanding = 0;\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\t*name;\n\tstruct inode_info\tinode;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tfile_size;\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned short\t\tfragment_checksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tchar\t\t\tchecksum_flag;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* flag if we're restoring existing filesystem */\nint restoring = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is\n * cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache, *sdirectory_compressed;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, sdirectory_compressed_bytes,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count = 0, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\nint threads;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* recovery file for abnormal exit on appending */\nchar recovery_file[1024] = \"\";\nint recover = TRUE;\n\n/* struct describing a cache entry passed between threads */\nstruct file_buffer {\n\tstruct cache *cache;\n\tint keep;\n\tlong long file_size;\n\tlong long index;\n\tlong long block;\n\tlong long sequence;\n\tint size;\n\tint c_byte;\n\tint used;\n\tint\tfragment;\n\tint error;\n\tstruct file_buffer *hash_next;\n\tstruct file_buffer *hash_prev;\n\tstruct file_buffer *free_next;\n\tstruct file_buffer *free_prev;\n\tstruct file_buffer *next;\n\tchar data[0];\n};\n\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\t\t\tsize;\n\tint\t\t\treadp;\n\tint\t\t\twritep;\n\tpthread_mutex_t\t\tmutex;\n\tpthread_cond_t\t\tempty;\n\tpthread_cond_t\t\tfull;\n\tvoid\t\t\t**data;\n};\n\n\n/* in memory uid tables */\n#define ID_ENTRIES 256\n#define ID_HASH(id) (id & (ID_ENTRIES - 1))\n#define ISA_UID 1\n#define ISA_GID 2\nstruct id {\n\tunsigned int id;\n\tint\tindex;\n\tchar\tflags;\n\tstruct id *next;\n};\nstruct id *id_hash_table[ID_ENTRIES];\nstruct id *id_table[SQUASHFS_IDS], *sid_table[SQUASHFS_IDS];\nunsigned int uid_count = 0, guid_count = 0;\nunsigned int sid_count = 0, suid_count = 0, sguid_count = 0;\n\nstruct cache *reader_buffer, *writer_buffer, *fragment_buffer;\nstruct queue *to_reader, *from_reader, *to_writer, *from_writer, *from_deflate,\n\t*to_frag;\npthread_t *thread, *deflator_thread, *frag_deflator_thread, progress_thread;\npthread_mutex_t\tfragment_mutex;\npthread_cond_t fragment_waiting;\npthread_mutex_t\tpos_mutex;\npthread_mutex_t progress_mutex;\npthread_cond_t progress_wait;\nint rotate = 0;\nstruct pseudo *pseudo = NULL;\n\n/* user options that control parallelisation */\nint processors = -1;\n/* default size of output buffer in Mbytes */\n#define WRITER_BUFFER_DEFAULT 512\n/* default size of input buffer in Mbytes */\n#define READER_BUFFER_DEFAULT 64\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 64\nint writer_buffer_size;\n\n/* compression operations */\nstatic struct compressor *comp;\nint compressor_opts_parsed = 0;\nvoid *stream = NULL;\n\n/* xattr stats */\nunsigned int xattr_bytes = 0, total_xattr_bytes = 0;\n\nchar *read_from_disk(long long start, unsigned int avail_bytes);\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type);\nextern struct compressor  *read_super(int fd, struct squashfs_super_block *sBlk,\n\tchar *source);\nextern long long read_filesystem(char *root_name, int fd,\n\tstruct squashfs_super_block *sBlk, char **cinode_table, char **data_cache,\n\tchar **cdirectory_table, char **directory_data_cache,\n\tunsigned int *last_directory_block, unsigned int *inode_dir_offset,\n\tunsigned int *inode_dir_file_size, unsigned int *root_inode_size,\n\tunsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\tlong long *uncompressed_file, unsigned int *uncompressed_inode,\n\tunsigned int *uncompressed_directory,\n\tunsigned int *inode_dir_inode_number,\n\tunsigned int *inode_dir_parent_inode,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\tstruct squashfs_fragment_entry **fragment_table,\n\tsquashfs_inode **inode_lookup_table);\nextern int read_sort_file(char *filename, int source, char *source_path[]);\nextern void sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag);\nstruct dir_info *dir_scan1(char *, struct pathnames *, int (_readdir)(char *,\n\tchar *, struct dir_info *));\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo);\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info);\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag);\nextern int generate_file_priorities(struct dir_info *dir, int priority,\n\tstruct stat *buf);\nextern struct priority_entry *priority_list[65536];\nvoid progress_bar(long long current, long long max, int columns);\nlong long generic_write_table(int, void *, int, void *, int);\nvoid restorefs();\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\tgoto failed;\n\n\tqueue->data = malloc(sizeof(void *) * (size + 1));\n\tif(queue->data == NULL) {\n\t\tfree(queue);\n\t\tgoto failed;\n\t}\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in queue_init\\n\");\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tstruct file_buffer *free_list;\n\tstruct file_buffer *hash_table[65536];\n};\n\n\n#define INSERT_LIST(NAME, TYPE) \\\nvoid insert_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(*list) { \\\n\t\tentry->NAME##_next = *list; \\\n\t\tentry->NAME##_prev = (*list)->NAME##_prev; \\\n\t\t(*list)->NAME##_prev->NAME##_next = entry; \\\n\t\t(*list)->NAME##_prev = entry; \\\n\t} else { \\\n\t\t*list = entry; \\\n\t\tentry->NAME##_prev = entry->NAME##_next = entry; \\\n\t} \\\n}\n\n\n#define REMOVE_LIST(NAME, TYPE) \\\nvoid remove_##NAME##_list(TYPE **list, TYPE *entry) { \\\n\tif(entry->NAME##_prev == entry && entry->NAME##_next == entry) { \\\n\t\t/* only this entry in the list */ \\\n\t\t*list = NULL; \\\n\t} else if(entry->NAME##_prev != NULL && entry->NAME##_next != NULL) { \\\n\t\t/* more than one entry in the list */ \\\n\t\tentry->NAME##_next->NAME##_prev = entry->NAME##_prev; \\\n\t\tentry->NAME##_prev->NAME##_next = entry->NAME##_next; \\\n\t\tif(*list == entry) \\\n\t\t\t*list = entry->NAME##_next; \\\n\t} \\\n\tentry->NAME##_prev = entry->NAME##_next = NULL; \\\n}\n\n\n#define CALCULATE_HASH(start)\t(start & 0xffff) \\\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tint hash = CALCULATE_HASH(entry->index);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct file_buffer *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->index)] =\n\t\t\tentry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nINSERT_LIST(free, struct file_buffer)\n\n/* Called with the cache mutex held */\nREMOVE_LIST(free, struct file_buffer)\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\tBAD_ERROR(\"Out of memory in cache_init\\n\");\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct file_buffer *) * 65536);\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\n\treturn cache;\n}\n\n\nstruct file_buffer *cache_lookup(struct cache *cache, long long index)\n{\n\t/* Lookup block in the cache, if found return with usage count\n \t * incremented, if not found return NULL */\n\tint hash = CALCULATE_HASH(index);\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->index == index)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/* found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(&cache->free_list, entry);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n}\n\n\nstruct file_buffer *cache_get(struct cache *cache, long long index, int keep)\n{\n\t/* Get a free block out of the cache indexed on index. */\n\tstruct file_buffer *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\twhile(1) {\n\t\t/* first try to get a block from the free list */\n\t\tif(first_freelist && cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t} else if(cache->count < cache->max_buffers) {\n\t\t\t/* next try to allocate new block */\n\t\t\tentry = malloc(sizeof(struct file_buffer) +\n\t\t\t\tcache->buffer_size);\n\t\t\tif(entry == NULL)\n\t\t\t\tgoto failed;\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t\tbreak;\n\t\t} else if(!first_freelist && cache->free_list) {\n\t\t\t/* a block on the free_list is a \"keep\" block */\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(&cache->free_list, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t\tbreak;\n\t\t} else\n\t\t\t/* wait for a block */\n\t\t\tpthread_cond_wait(&cache->wait_for_free, &cache->mutex);\n\t}\n\n\t/* initialise block and if a keep block insert into the hash table */\n\tentry->used = 1;\n\tentry->error = FALSE;\n\tentry->keep = keep;\n\tif(keep) {\n\t\tentry->index = index;\n\t\tinsert_hash_table(cache, entry);\n\t}\n\tpthread_mutex_unlock(&cache->mutex);\n\n\treturn entry;\n\nfailed:\n\tpthread_mutex_unlock(&cache->mutex);\n\tBAD_ERROR(\"Out of memory in cache_get\\n\");\n}\n\n\nvoid cache_rehash(struct file_buffer *entry, long long index)\n{\n\tstruct cache *cache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\tif(entry->keep)\n\t\tremove_hash_table(cache, entry);\n\tentry->keep = TRUE;\n\tentry->index = index;\n\tinsert_hash_table(cache, entry);\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\nvoid cache_block_put(struct file_buffer *entry)\n{\n\tstruct cache *cache;\n\n\t/* finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and if a keep block put onto the free list.  As keep\n \t * blocks remain accessible via the hash table they can be found\n \t * getting a new lease of life before they are reused. */\n\n\tif(entry == NULL)\n\t\treturn;\n\n\tcache = entry->cache;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tif(entry->keep)\n\t\t\tinsert_free_list(&cache->free_list, entry);\n\t\telse {\n\t\t\tfree(entry);\n\t\t\tcache->count --;\n\t\t}\n\n\t\t/* One or more threads may be waiting on this block */\n\t\tpthread_cond_signal(&cache->wait_for_free);\n\t}\n\n\tpthread_mutex_unlock(&cache->mutex);\n}\n\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) \\\n\t\t\t+ (((char *)A) - data_cache)))\n\n\ninline void inc_progress_bar()\n{\n\tcur_uncompressed ++;\n}\n\n\ninline void update_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\ninline void waitforthread(int i)\n{\n\tTRACE(\"Waiting for thread %d\\n\", i);\n\twhile(thread[i] != 0)\n\t\tsched_yield();\n}\n\n\nvoid restorefs()\n{\n\tint i;\n\n\tif(thread == NULL || thread[0] == 0)\n\t\treturn;\n\n\tif(restoring++)\n\t\t/*\n\t\t * Recursive failure when trying to restore filesystem!\n\t\t * Nothing to do except to exit, otherwise we'll just appear\n\t\t * to hang.  The user should be able to restore from the\n\t\t * recovery file (which is why it was added, in case of\n\t\t * catastrophic failure in Mksquashfs)\n\t\t */\n\t\texit(1);\n\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\tif(thread[i])\n\t\t\tpthread_kill(thread[i], SIGUSR1);\n\tfor(i = 0; i < 2 + processors * 2; i++)\n\t\twaitforthread(i);\n\tTRACE(\"All threads in signal handler\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache,\n\t\tsdirectory_cache_bytes);\n\tdirectory_cache_bytes = sdirectory_cache_bytes;\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n \tmemcpy(directory_table + directory_bytes, sdirectory_compressed,\n\t\tsdirectory_compressed_bytes);\n \tdirectory_bytes += sdirectory_compressed_bytes;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tid_count = sid_count;\n\trestore_xattrs();\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(++interrupted > 2)\n\t\treturn;\n\tif(interrupted == 2)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nvoid sigusr1_handler()\n{\n\tint i;\n\tsigset_t sigmask;\n\tpthread_t thread_id = pthread_self();\n\n\tfor(i = 0; i < (2 + processors * 2) && thread[i] != thread_id; i++);\n\tthread[i] = (pthread_t) 0;\n\n\tTRACE(\"Thread %d(%p) in sigusr1_handler\\n\", i, &thread_id);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tsigaddset(&sigmask, SIGUSR1);\n\twhile(1) {\n\t\tsigsuspend(&sigmask);\n\t\tTRACE(\"After wait in sigusr1_handler :(\\n\");\n\t}\n}\n\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nint mangle2(void *strm, char *d, char *s, int size,\n\tint block_size, int uncompressed, int data_block)\n{\n\tint error, c_byte = 0;\n\n\tif(!uncompressed) {\n\t\tc_byte = compressor_compress(comp, strm, d, s, size, block_size,\n\t\t\t &error);\n\t\tif(c_byte == -1)\n\t\t\tBAD_ERROR(\"mangle2:: %s compress failed with error \"\n\t\t\t\t\"code %d\\n\", comp->name, error);\n\t}\n\n\tif(c_byte == 0 || c_byte >= size) {\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK :\n\t\t\tSQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn c_byte;\n}\n\n\nint mangle(char *d, char *s, int size, int block_size,\n\tint uncompressed, int data_block)\n{\n\treturn mangle2(stream, d, s, size, block_size, uncompressed,\n\t\tdata_block);\n}\n\n\nvoid *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tvoid *it = realloc(inode_table, inode_size +\n\t\t\t\t(SQUASHFS_METADATA_SIZE << 1) + 2);\n\t\t\tif(it == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_table = it;\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET,\n\t\t\tdata_cache, SQUASHFS_METADATA_SIZE,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, inode_table + inode_bytes, 1);\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemmove(data_cache, data_cache + SQUASHFS_METADATA_SIZE,\n\t\t\tcache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ?\n\t\t\t\t((req_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : req_size -\n\t\t\t\tdata_space;\n\n\t\t\tvoid *dc = realloc(data_cache, cache_size +\n\t\t\t\trealloc_size);\n\t\t\tif(dc == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t\t\tdata_cache = dc;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn data_cache + cache_bytes - req_size;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nint read_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = read(fd, buff + count, bytes - count);\n\t\tif(res < 1) {\n\t\t\tif(res == 0)\n\t\t\t\tgoto bytes_read;\n\t\t\telse if(errno != EINTR) {\n\t\t\t\tERROR(\"Read failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t} else\n\t\t\t\tres = 0;\n\t\t}\n\t}\n\nbytes_read:\n\treturn count;\n}\n\n\nint read_fs_bytes(int fd, long long byte, int bytes, void *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_fs_bytes: reading from position 0x%llx, bytes %d\\n\",\n\t\tbyte, bytes);\n\n\tpthread_mutex_lock(&pos_mutex);\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\t\tgoto failed;\n\t}\n\n\tif(read_bytes(fd, buff, bytes) < bytes) {\n\t\tERROR(\"Read on destination failed\\n\");\n\t\tgoto failed;\n\t}\n\n\tpthread_mutex_unlock(&pos_mutex);\n\treturn 1;\n\nfailed:\n\tpthread_mutex_unlock(&pos_mutex);\n\treturn 0;\n}\n\n\nint write_bytes(int fd, void *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = write(fd, buff + count, bytes - count);\n\t\tif(res == -1) {\n\t\t\tif(errno != EINTR) {\n\t\t\t\tERROR(\"Write failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nvoid write_destination(int fd, long long byte, int bytes, void *buff)\n{\n\toff_t off = byte;\n\n\tif(!restoring)\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\tif(lseek(fd, off, SEEK_SET) == -1)\n\t\tBAD_ERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(fd, buff, bytes) == -1)\n\t\tBAD_ERROR(\"Write on destination failed\\n\");\n\t\n\tif(!restoring)\n\t\tpthread_mutex_unlock(&pos_mutex);\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tvoid *it = realloc(inode_table, inode_size +\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2));\n\t\t\tif(it == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t\tinode_table = it;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + BLOCK_OFFSET, datap,\n\t\t\tavail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ 0x%x, size %d\\n\", inode_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, inode_table + inode_bytes, 1); \n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\ttotal_inode_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_destination(fd, bytes, inode_bytes,  inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tvoid *dt = realloc(directory_table,\n\t\t\t\tdirectory_size + ((SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2));\n\t\t\tif(dt == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table \"\n\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t\tdirectory_table = dt;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\tBLOCK_OFFSET, directoryp, avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\tdirectory_table + directory_bytes, 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += avail_bytes + BLOCK_OFFSET;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_destination(fd, bytes, directory_bytes, directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_id_table()\n{\n\tunsigned int id_bytes = SQUASHFS_ID_BYTES(id_count);\n\tunsigned int p[id_count];\n\tint i;\n\n\tTRACE(\"write_id_table: ids %d, id_bytes %d\\n\", id_count, id_bytes);\n\tfor(i = 0; i < id_count; i++) {\n\t\tTRACE(\"write_id_table: id index %d, id %d\", i, id_table[i]->id);\n\t\tSQUASHFS_SWAP_INTS(&id_table[i]->id, p + i, 1);\n\t}\n\n\treturn generic_write_table(id_bytes, p, 0, NULL, noI);\n}\n\n\nstruct id *get_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = id_hash_table[hash];\n\n\tfor(; entry; entry = entry->next)\n\t\tif(entry->id == id)\n\t\t\tbreak;\n\n\treturn entry;\n}\n\n\nstruct id *create_id(unsigned int id)\n{\n\tint hash = ID_HASH(id);\n\tstruct id *entry = malloc(sizeof(struct id));\n\tif(entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in create_id\\n\");\n\tentry->id = id;\n\tentry->index = id_count ++;\n\tentry->flags = 0;\n\tentry->next = id_hash_table[hash];\n\tid_hash_table[hash] = entry;\n\tid_table[entry->index] = entry;\n\treturn entry;\n}\n\n\nunsigned int get_uid(unsigned int uid)\n{\n\tstruct id *entry = get_id(uid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of uids!\\n\");\n\t\tentry = create_id(uid);\n\t}\n\n\tif((entry->flags & ISA_UID) == 0) {\n\t\tentry->flags |= ISA_UID;\n\t\tuid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nunsigned int get_guid(unsigned int guid)\n{\n\tstruct id *entry = get_id(guid);\n\n\tif(entry == NULL) {\n\t\tif(id_count == SQUASHFS_IDS)\n\t\t\tBAD_ERROR(\"Out of gids!\\n\");\n\t\tentry = create_id(guid);\n\t}\n\n\tif((entry->flags & ISA_GID) == 0) {\n\t\tentry->flags |= ISA_GID;\n\t\tguid_count ++;\n\t}\n\n\treturn entry->index;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_info *dir_info,\n\tstruct dir_ent *dir_ent, int type, long long byte_size,\n\tlong long start_block, unsigned int offset, unsigned int *block_list,\n\tstruct fragment *fragment, struct directory *dir_in, long long sparse)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tunion squashfs_inode_header inode_header;\n\tstruct squashfs_base_inode_header *base = &inode_header.base;\n\tvoid *inode;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = type == SQUASHFS_DIR_TYPE ?\n\t\tdir_ent->inode->inode_number :\n\t\tdir_ent->inode->inode_number + dir_inode_no;\n\tint xattr = read_xattrs(dir_ent);\n\n\tswitch(type) {\n\tcase SQUASHFS_FILE_TYPE:\n\t\tif(dir_ent->inode->nlink > 1 ||\n\t\t\t\tbyte_size >= (1LL << 32) ||\n\t\t\t\tstart_block >= (1LL << 32) ||\n\t\t\t\tsparse || IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LREG_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_DIR_TYPE:\n\t\tif(dir_info->dir_is_ldir || IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LDIR_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_SYMLINK_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LSYMLINK_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_BLKDEV_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LBLKDEV_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_CHRDEV_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LCHRDEV_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_FIFO_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LFIFO_TYPE;\n\t\tbreak;\n\tcase SQUASHFS_SOCKET_TYPE:\n\t\tif(IS_XATTR(xattr))\n\t\t\ttype = SQUASHFS_LSOCKET_TYPE;\n\t\tbreak;\n\t}\n\t\t\t\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((unsigned int) global_uid == -1 ?\n\t\tbuf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((unsigned int) global_gid == -1 ?\n\t\tbuf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tstruct squashfs_reg_inode_header *reg = &inode_header.reg;\n\t\tsize_t off = offsetof(struct squashfs_reg_inode_header, block_list);\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inode);\n\t\tSQUASHFS_SWAP_INTS(block_list, inode + off, offset);\n\t\tTRACE(\"File inode, file_size %lld, start_block 0x%llx, blocks \"\n\t\t\t\"%d, fragment %d, offset %d, size %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset,\n\t\t\tfragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tstruct squashfs_lreg_inode_header *reg = &inode_header.lreg;\n\t\tsize_t off = offsetof(struct squashfs_lreg_inode_header, block_list);\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(sparse && sparse >= byte_size)\n\t\t\tsparse = byte_size - 1;\n\t\treg->sparse = sparse;\n\t\treg->xattr = xattr;\n\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inode);\n\t\tSQUASHFS_SWAP_INTS(block_list, inode + off, offset);\n\t\tTRACE(\"Long file inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"blocks %d, fragment %d, offset %d, size %d, nlink %d\"\n\t\t\t\"\\n\", byte_size, start_block, offset, fragment->index,\n\t\t\tfragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tstruct squashfs_ldir_inode_header *dir = &inode_header.ldir;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\t\tdir->xattr = xattr;\n\n\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = inode + offsetof(struct squashfs_ldir_inode_header, index);\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tp += offsetof(struct squashfs_dir_index, name);\n\t\t\tmemcpy(p, index[i].name, index[i].index.size + 1);\n\t\t\tp += index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %lld, start_block \"\n\t\t\t\"0x%llx, offset 0x%x, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tstruct squashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ?\n\t\t\tdir_ent->our_dir->dir_ent->inode->inode_number :\n\t\t\tdir_inode_no + inode_no;\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %lld, start_block 0x%llx, \"\n\t\t\t\"offset 0x%x, nlink %d\\n\", byte_size, start_block,\n\t\t\toffset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tstruct squashfs_dev_inode_header *dev = &inode_header.dev;\n\t\tunsigned int major = major(buf->st_rdev);\n\t\tunsigned int minor = minor(buf->st_rdev);\n\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", major, filename,\n\t\t\t\tmajor & 0xfff);\n\t\t\tmajor &= 0xfff;\n\t\t}\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", minor, filename,\n\t\t\t\tminor & 0xfffff);\n\t\t\tminor &= 0xfffff;\n\t\t}\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (major << 8) | (minor & 0xff) |\n\t\t\t\t((minor & ~0xff) << 12);\n\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_LCHRDEV_TYPE || type == SQUASHFS_LBLKDEV_TYPE) {\n\t\tstruct squashfs_ldev_inode_header *dev = &inode_header.ldev;\n\t\tunsigned int major = major(buf->st_rdev);\n\t\tunsigned int minor = minor(buf->st_rdev);\n\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", major, filename,\n\t\t\t\tmajor & 0xfff);\n\t\t\tmajor &= 0xfff;\n\t\t}\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range in device node %s, \"\n\t\t\t\t\"truncating to %d\\n\", minor, filename,\n\t\t\t\tminor & 0xfffff);\n\t\t\tminor &= 0xfffff;\n\t\t}\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (major << 8) | (minor & 0xff) |\n\t\t\t\t((minor & ~0xff) << 12);\n\t\tdev->xattr = xattr;\n\t\tSQUASHFS_SWAP_LDEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev 0x%x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tstruct squashfs_symlink_inode_header *symlink = &inode_header.symlink;\n\t\tint byte;\n\t\tchar buff[65536];\n\t\tsize_t off = offsetof(struct squashfs_symlink_inode_header, symlink);\n\n\t\tbyte = readlink(filename, buff, 65536);\n\t\tif(byte == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty \"\n\t\t\t\t\"symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! \"\n\t\t\t\t\"Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tsymlink->symlink_size = byte;\n\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inode + off, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte,\n\t\t\tnlink);\n\t}\n\telse if(type == SQUASHFS_LSYMLINK_TYPE) {\n\t\tstruct squashfs_symlink_inode_header *symlink = &inode_header.symlink;\n\t\tint byte;\n\t\tchar buff[65536];\n\t\tsize_t off = offsetof(struct squashfs_symlink_inode_header, symlink);\n\n\t\tbyte = readlink(filename, buff, 65536);\n\t\tif(byte == -1) {\n\t\t\tERROR(\"Failed to read symlink %s, creating empty \"\n\t\t\t\t\"symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink %s is greater than 65536 bytes! \"\n\t\t\t\t\"Creating empty symlink\\n\", filename);\n\t\t\tbyte = 0;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte +\n\t\t\t\t\t\tsizeof(unsigned int));\n\t\tsymlink->nlink = nlink;\n\t\tsymlink->symlink_size = byte;\n\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inode + off, buff, byte);\n\t\tSQUASHFS_SWAP_INTS(&xattr, inode + off + byte, 1);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte,\n\t\t\tnlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tstruct squashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type ==\n\t\t\tSQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t}\n\telse if(type == SQUASHFS_LFIFO_TYPE || type == SQUASHFS_LSOCKET_TYPE) {\n\t\tstruct squashfs_lipc_inode_header *ipc = &inode_header.lipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tipc->xattr = xattr;\n\t\tSQUASHFS_SWAP_LIPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type ==\n\t\t\tSQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\tBAD_ERROR(\"Unrecognised inode %d in create_inode\\n\", type);\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type,\n\t\tbase->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan3_init_dir(struct directory *dir)\n{\n\tdir->buff = malloc(SQUASHFS_METADATA_SIZE);\n\tif(dir->buff == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name,\n\tint type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tstruct squashfs_dir_entry idir;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size = strlen(name);\n\tsize_t name_off = offsetof(struct squashfs_dir_entry, name);\n\n\tif(size > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\"\n\t\t\t\"\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(struct squashfs_dir_entry) + size +\n\t\t\tsizeof(struct squashfs_dir_header)\n\t\t\t>= dir->buff + dir->size) {\n\t\tbuff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE);\n\t\tif(buff == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\"\n\t\t\t\t\"\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff +\n\t\t\tbuff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block ||\n\t\t\t((dir->entry_count_p != NULL) &&\n\t\t\t((dir->p + sizeof(struct squashfs_dir_entry) + size -\n\t\t\tdir->index_count_p) > SQUASHFS_METADATA_SIZE)) ||\n\t\t\t((long long) inode_number - dir->inode_number) > 32767\n\t\t\t|| ((long long) inode_number - dir->inode_number)\n\t\t\t< -32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tstruct squashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(struct squashfs_dir_entry) + size -\n\t\t\t\t\tdir->index_count_p) >\n\t\t\t\t\tSQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0) {\n\t\t\t\t\tdir->index = realloc(dir->index,\n\t\t\t\t\t\t(dir->i_count + I_COUNT_SIZE) *\n\t\t\t\t\t\tsizeof(struct cached_dir_index));\n\t\t\t\t\tif(dir->index == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in \"\n\t\t\t\t\t\t\t\"directory index table \"\n\t\t\t\t\t\t\t\"reallocation!\\n\");\n\t\t\t\t}\n\t\t\t\tdir->index[dir->i_count].index.index =\n\t\t\t\t\tdir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(struct squashfs_dir_index)\n\t\t\t\t\t+ size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header,\n\t\t\t\tdir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(struct squashfs_dir_header);\n\t}\n\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tSQUASHFS_SWAP_DIR_ENTRY(&idir, dir->p);\n\tstrncpy((char *) dir->p + name_off, name, size);\n\tdir->p += sizeof(struct squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nvoid write_dir(squashfs_inode *inode, struct dir_info *dir_info,\n\tstruct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = directory_cache_size - directory_cache_bytes;\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ?\n\t\t\t((dir_size + SQUASHFS_METADATA_SIZE) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tvoid *dc = realloc(directory_data_cache,\n\t\t\tdirectory_cache_size + realloc_size);\n\t\tif(dc == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t\tdirectory_data_cache = dc;\n\t}\n\n\tif(dir_size) {\n\t\tstruct squashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dir_header, dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff,\n\t\t\tdir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count &&\n\t\t\t\tdir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block =\n\t\t\t\tdirectory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) <\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tvoid *dt = realloc(directory_table,\n\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1)\n\t\t\t\t+ 2);\n\t\t\tif(dt == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t\tdirectory_table = dt;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes +\n\t\t\t\tBLOCK_OFFSET, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE,\n\t\t\t\tnoI, 0);\n\t\tTRACE(\"Directory block @ 0x%x, size %d\\n\", directory_bytes,\n\t\t\tc_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte,\n\t\t\tdirectory_table + directory_bytes, 1);\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + BLOCK_OFFSET;\n\t\tmemmove(directory_data_cache, directory_data_cache +\n\t\t\tSQUASHFS_METADATA_SIZE, directory_cache_bytes -\n\t\t\tSQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tcreate_inode(inode, dir_info, dir_info->dir_ent, SQUASHFS_DIR_TYPE,\n\t\tdir_size + 3, directory_block, directory_offset, NULL, NULL,\n\t\tdir, 0);\n\n#ifdef SQUASHFS_TRACE\n\t{\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tstruct squashfs_dir_entry idir, *idirp;\n\t\t\tstruct squashfs_dir_header dirh;\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((struct squashfs_dir_header *) dirp,\n\t\t\t\t&dirh);\n\t\t\tcount = dirh.count + 1;\n\t\t\tdirp += sizeof(struct squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\",\n\t\t\t\tdirh.start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (struct squashfs_dir_entry *) dirp;\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(idirp, &idir);\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type \"\n\t\t\t\t\t\"%d\\n\", buffer, idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(struct squashfs_dir_entry) + idir.size +\n\t\t\t\t\t1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nstruct file_buffer *get_fragment(struct fragment *fragment)\n{\n\tstruct squashfs_fragment_entry *disk_fragment;\n\tint res, size;\n\tlong long start_block;\n\tstruct file_buffer *buffer, *compressed_buffer;\n\n\tif(fragment->index == SQUASHFS_INVALID_FRAG)\n\t\treturn NULL;\n\n\tbuffer = cache_lookup(fragment_buffer, fragment->index);\n\tif(buffer)\n\t\treturn buffer;\n\n\tcompressed_buffer = cache_lookup(writer_buffer, fragment->index +\n\t\tFRAG_INDEX);\n\n\tbuffer = cache_get(fragment_buffer, fragment->index, 1);\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tdisk_fragment = &fragment_table[fragment->index];\n\tsize = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\tstart_block = disk_fragment->start_block;\n\tpthread_mutex_unlock(&fragment_mutex);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint error;\n\t\tchar *data;\n\n\t\tif(compressed_buffer)\n\t\t\tdata = compressed_buffer->data;\n\t\telse\n\t\t\tdata = read_from_disk(start_block, size);\n\n\t\tres = compressor_uncompress(comp, buffer->data, data, size,\n\t\t\tblock_size, &error);\n\t\tif(res == -1)\n\t\t\tBAD_ERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t} else if(compressed_buffer)\n\t\tmemcpy(buffer->data, compressed_buffer->data, size);\n\telse {\n\t\tres = read_fs_bytes(fd, start_block, size, buffer->data);\n\t\tif(res == 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tcache_block_put(compressed_buffer);\n\n\treturn buffer;\n}\n\n\nstruct frag_locked {\n\tstruct file_buffer *buffer;\n\tint c_byte;\n\tint fragment;\n\tstruct frag_locked *fragment_prev;\n\tstruct frag_locked *fragment_next;\n};\n\nint fragments_locked = FALSE;\nstruct frag_locked *frag_locked_list = NULL;\n\nINSERT_LIST(fragment, struct frag_locked)\nREMOVE_LIST(fragment, struct frag_locked)\n\nint lock_fragments()\n{\n\tint count;\n\tpthread_mutex_lock(&fragment_mutex);\n\tfragments_locked = TRUE;\n\tcount = fragments_outstanding;\n\tpthread_mutex_unlock(&fragment_mutex);\n\treturn count;\n}\n\n\nvoid unlock_fragments()\n{\n\tstruct frag_locked *entry;\n\tint compressed_size;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\twhile(frag_locked_list) {\n\t\tentry = frag_locked_list;\n\t\tremove_fragment_list(&frag_locked_list, entry);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(entry->c_byte);\n\t\tfragment_table[entry->fragment].size = entry->c_byte;\n\t\tfragment_table[entry->fragment].start_block = bytes;\n\t\tentry->buffer->block = bytes;\n\t\tbytes += compressed_size;\n\t\tfragments_outstanding --;\n\t\tqueue_put(to_writer, entry->buffer);\n\t\tTRACE(\"fragment_locked writing fragment %d, compressed size %d\"\n\t\t\t\"\\n\", entry->fragment, compressed_size);\n\t\tfree(entry);\n\t}\n\tfragments_locked = FALSE;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid add_pending_fragment(struct file_buffer *write_buffer, int c_byte,\n\tint fragment)\n{\n\tstruct frag_locked *entry = malloc(sizeof(struct frag_locked));\n\tif(entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in add_pending fragment\\n\");\n\tentry->buffer = write_buffer;\n\tentry->c_byte = c_byte;\n\tentry->fragment = fragment;\n\tentry->fragment_prev = entry->fragment_next = NULL;\n\tpthread_mutex_lock(&fragment_mutex);\n\tinsert_fragment_list(&frag_locked_list, entry);\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nvoid write_fragment()\n{\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tpthread_mutex_lock(&fragment_mutex);\n\tif(fragments % FRAG_SIZE == 0) {\n\t\tvoid *ft = realloc(fragment_table, (fragments +\n\t\t\tFRAG_SIZE) * sizeof(struct squashfs_fragment_entry));\n\t\tif(ft == NULL) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\t\t}\n\t\tfragment_table = ft;\n\t}\n\tfragment_data->size = fragment_size;\n\tfragment_data->block = fragments;\n\tfragment_table[fragments].unused = 0;\n\tfragments_outstanding ++;\n\tqueue_put(to_frag, fragment_data);\n\tfragments ++;\n\tfragment_size = 0;\n\tpthread_mutex_unlock(&fragment_mutex);\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(struct file_buffer *file_buffer)\n{\n\tstruct fragment *ffrg;\n\t\n\n\tif(file_buffer == NULL || file_buffer->size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + file_buffer->size > block_size)\n\t\twrite_fragment();\n\n\tffrg = malloc(sizeof(struct fragment));\n\tif(ffrg == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tif(fragment_size == 0)\n\t\tfragment_data = cache_get(fragment_buffer, fragments, 1);\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = file_buffer->size;\n\tmemcpy(fragment_data->data + fragment_size, file_buffer->data,\n\t\tfile_buffer->size);\n\tfragment_size += file_buffer->size;\n\n\treturn ffrg;\n}\n\n\nlong long generic_write_table(int length, void *buffer, int length2,\n\tvoid *buffer2, int uncompressed)\n{\n\tint meta_blocks = (length + SQUASHFS_METADATA_SIZE - 1) /\n\t\tSQUASHFS_METADATA_SIZE;\n\tlong long list[meta_blocks], start_bytes;\n\tint compressed_size, i;\n\tunsigned short c_byte;\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2];\n\t\n#ifdef SQUASHFS_TRACE\n\tlong long obytes = bytes;\n\tint olength = length;\n#endif\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = length > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : length;\n\t\tc_byte = mangle(cbuffer + BLOCK_OFFSET, buffer + i *\n\t\t\tSQUASHFS_METADATA_SIZE , avail_bytes,\n\t\t\tSQUASHFS_METADATA_SIZE, uncompressed, 0);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, cbuffer, 1);\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) +\n\t\t\tBLOCK_OFFSET;\n\t\tTRACE(\"block %d @ 0x%llx, compressed size %d\\n\", i, bytes,\n\t\t\tcompressed_size);\n\t\twrite_destination(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t\ttotal_bytes += avail_bytes;\n\t\tlength -= avail_bytes;\n\t}\n\n\tstart_bytes = bytes;\n\tif(length2) {\n\t\twrite_destination(fd, bytes, length2, buffer2);\n\t\tbytes += length2;\n\t\ttotal_bytes += length2;\n\t}\n\t\t\n\tSQUASHFS_INSWAP_LONG_LONGS(list, meta_blocks);\n\twrite_destination(fd, bytes, sizeof(list), list);\n\tbytes += sizeof(list);\n\ttotal_bytes += sizeof(list);\n\n\tTRACE(\"generic_write_table: total uncompressed %d compressed %lld\\n\",\n\t\tolength, bytes - obytes);\n\n\treturn start_bytes;\n}\n\n\nlong long write_fragment_table()\n{\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments);\n\tstruct squashfs_fragment_entry p[fragments];\n\tint i;\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d\\n\", fragments,\n\t\tfrag_bytes);\n\tfor(i = 0; i < fragments; i++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block 0x%llx, \"\n\t\t\t\"size %d\\n\", i, fragment_table[i].start_block,\n\t\t\tfragment_table[i].size);\n\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p + i);\n\t}\n\n\treturn generic_write_table(frag_bytes, p, 0, NULL, noF);\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk(long long start, unsigned int avail_bytes)\n{\n\tint res;\n\n\tres = read_fs_bytes(fd, start, avail_bytes, read_from_file_buffer);\n\tif(res == 0)\n\t\tEXIT_MKSQUASHFS();\n\n\treturn read_from_file_buffer;\n}\n\n\nchar read_from_file_buffer2[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_disk2(long long start, unsigned int avail_bytes)\n{\n\tint res;\n\n\tres = read_fs_bytes(fd, start, avail_bytes, read_from_file_buffer2);\n\tif(res == 0)\n\t\tEXIT_MKSQUASHFS();\n\n\treturn read_from_file_buffer2;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *buff, int bytes, unsigned short chksum)\n{\n\tunsigned char *b = (unsigned char *) buff;\n\n\twhile(bytes --) {\n\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\tchksum += *b++;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_disk(long long start, long long l,\n\tunsigned int *blocks)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes;\n\tstruct file_buffer *write_buffer;\n\tint i;\n\n\tfor(i = 0; l; i++)  {\n\t\tbytes = SQUASHFS_COMPRESSED_SIZE_BLOCK(blocks[i]);\n\t\tif(bytes == 0) /* sparse block */\n\t\t\tcontinue;\n\t\twrite_buffer = cache_lookup(writer_buffer, start);\n\t\tif(write_buffer) {\n\t\t\tchksum = get_checksum(write_buffer->data, bytes,\n\t\t\t\tchksum);\n\t\t\tcache_block_put(write_buffer);\n\t\t} else\n\t\t\tchksum = get_checksum(read_from_disk(start, bytes),\n\t\t\t\tbytes, chksum);\n\t\tl -= bytes;\n\t\tstart += bytes;\n\t}\n\n\treturn chksum;\n}\n\n\nunsigned short get_checksum_mem(char *buff, int bytes)\n{\n\treturn get_checksum(buff, bytes, 0);\n}\n\n\nunsigned short get_checksum_mem_buffer(struct file_buffer *file_buffer)\n{\n\tif(file_buffer == NULL)\n\t\treturn 0;\n\telse\n\t\treturn get_checksum(file_buffer->data, file_buffer->size, 0);\n}\n\n\n#define DUP_HASH(a) (a & 0xffff)\nvoid add_file(long long start, long long file_size, long long file_bytes,\n\tunsigned int *block_listp, int blocks, unsigned int fragment,\n\tint offset, int bytes)\n{\n\tstruct fragment *frg;\n\tunsigned int *block_list = block_listp;\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tif(!duplicate_checking || file_size == 0)\n\t\treturn;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next) {\n\t\tif(file_size != dupl_ptr->file_size)\n\t\t\tcontinue;\n\t\tif(blocks != 0 && start != dupl_ptr->start)\n\t\t\tcontinue;\n\t\tif(fragment != dupl_ptr->fragment->index)\n\t\t\tcontinue;\n\t\tif(fragment != SQUASHFS_INVALID_FRAG && (offset !=\n\t\t\t\tdupl_ptr->fragment->offset || bytes !=\n\t\t\t\tdupl_ptr->fragment->size))\n\t\t\tcontinue;\n\t\treturn;\n\t}\n\n\tfrg = malloc(sizeof(struct fragment));\n\tif(frg == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\n\tadd_non_dup(file_size, file_bytes, block_list, start, frg, 0, 0, FALSE);\n}\n\n\nint pre_duplicate(long long file_size)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(dupl_ptr->file_size == file_size)\n\t\t\treturn TRUE;\n\n\treturn FALSE;\n}\n\n\nint pre_duplicate_frag(long long file_size, unsigned short checksum)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && file_size ==\n\t\t\t\tdupl_ptr->fragment->size) {\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, file_size);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\t\t\tif(dupl_ptr->fragment_checksum == checksum)\n\t\t\t\treturn TRUE;\n\t\t}\n\n\treturn FALSE;\n}\n\n\nstruct file_info *add_non_dup(long long file_size, long long bytes,\n\tunsigned int *block_list, long long start, struct fragment *fragment,\n\tunsigned short checksum, unsigned short fragment_checksum,\n\tint checksum_flag)\n{\n\tstruct file_info *dupl_ptr = malloc(sizeof(struct file_info));\n\n\tif(dupl_ptr == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->file_size = file_size;\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->block_list = block_list;\n\tdupl_ptr->start = start;\n\tdupl_ptr->fragment = fragment;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->checksum_flag = checksum_flag;\n\tdupl_ptr->next = dupl[DUP_HASH(file_size)];\n\tdupl[DUP_HASH(file_size)] = dupl_ptr;\n\tdup_files ++;\n\n\treturn dupl_ptr;\n}\n\n\nstruct file_info *duplicate(long long file_size, long long bytes,\n\tunsigned int **block_list, long long *start, struct fragment **fragment,\n\tstruct file_buffer *file_buffer, int blocks, unsigned short checksum,\n\tunsigned short fragment_checksum, int checksum_flag)\n{\n\tstruct file_info *dupl_ptr = dupl[DUP_HASH(file_size)];\n\tint frag_bytes = file_buffer ? file_buffer->size : 0;\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(file_size == dupl_ptr->file_size && bytes == dupl_ptr->bytes\n\t\t\t\t && frag_bytes == dupl_ptr->fragment->size) {\n\t\t\tlong long target_start, dup_start = dupl_ptr->start;\n\t\t\tint block;\n\n\t\t\tif(memcmp(*block_list, dupl_ptr->block_list, blocks *\n\t\t\t\t\tsizeof(unsigned int)) != 0)\n\t\t\t\tcontinue;\n\n\t\t\tif(checksum_flag == FALSE) {\n\t\t\t\tchecksum = get_checksum_disk(*start, bytes,\n\t\t\t\t\t*block_list);\n\t\t\t\tfragment_checksum =\n\t\t\t\t\tget_checksum_mem_buffer(file_buffer);\n\t\t\t\tchecksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(dupl_ptr->checksum_flag == FALSE) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\t\t\t\tdupl_ptr->checksum =\n\t\t\t\t\tget_checksum_disk(dupl_ptr->start,\n\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->block_list);\n\t\t\t\tdupl_ptr->fragment_checksum =\n\t\t\t\t\tget_checksum_mem(frag_buffer->data +\n\t\t\t\t\tdupl_ptr->fragment->offset, frag_bytes);\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\tdupl_ptr->checksum_flag = TRUE;\n\t\t\t}\n\n\t\t\tif(checksum != dupl_ptr->checksum ||\n\t\t\t\t\tfragment_checksum !=\n\t\t\t\t\tdupl_ptr->fragment_checksum)\n\t\t\t\tcontinue;\n\n\t\t\ttarget_start = *start;\n\t\t\tfor(block = 0; block < blocks; block ++) {\n\t\t\t\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t((*block_list)[block]);\n\t\t\t\tstruct file_buffer *target_buffer = NULL;\n\t\t\t\tstruct file_buffer *dup_buffer = NULL;\n\t\t\t\tchar *target_data, *dup_data;\n\t\t\t\tint res;\n\n\t\t\t\tif(size == 0)\n\t\t\t\t\tcontinue;\n\t\t\t\ttarget_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\ttarget_start);\n\t\t\t\tif(target_buffer)\n\t\t\t\t\ttarget_data = target_buffer->data;\n\t\t\t\telse\n\t\t\t\t\ttarget_data =\n\t\t\t\t\t\tread_from_disk(target_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tdup_buffer = cache_lookup(writer_buffer,\n\t\t\t\t\tdup_start);\n\t\t\t\tif(dup_buffer)\n\t\t\t\t\tdup_data = dup_buffer->data;\n\t\t\t\telse\n\t\t\t\t\tdup_data = read_from_disk2(dup_start,\n\t\t\t\t\t\tsize);\n\n\t\t\t\tres = memcmp(target_data, dup_data, size);\n\t\t\t\tcache_block_put(target_buffer);\n\t\t\t\tcache_block_put(dup_buffer);\n\t\t\t\tif(res != 0)\n\t\t\t\t\tbreak;\n\t\t\t\ttarget_start += size;\n\t\t\t\tdup_start += size;\n\t\t\t}\n\t\t\tif(block == blocks) {\n\t\t\t\tstruct file_buffer *frag_buffer =\n\t\t\t\t\tget_fragment(dupl_ptr->fragment);\n\n\t\t\t\tif(frag_bytes == 0 ||\n\t\t\t\t\t\tmemcmp(file_buffer->data,\n\t\t\t\t\t\tfrag_buffer->data +\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfrag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start \"\n\t\t\t\t\t\t\"0x%llx, size %lld, checksum \"\n\t\t\t\t\t\t\"0x%x, fragment %d, size %d, \"\n\t\t\t\t\t\t\"offset %d, checksum 0x%x\\n\",\n\t\t\t\t\t\tdupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes,\n\t\t\t\t\t\tdupl_ptr->checksum,\n\t\t\t\t\t\tdupl_ptr->fragment->index,\n\t\t\t\t\t\tfrag_bytes,\n\t\t\t\t\t\tdupl_ptr->fragment->offset,\n\t\t\t\t\t\tfragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\tcache_block_put(frag_buffer);\n\t\t\t}\n\t\t}\n\n\n\treturn add_non_dup(file_size, bytes, *block_list, *start, *fragment,\n\t\tchecksum, fragment_checksum, checksum_flag);\n}\n\n\nstatic int seq = 0;\nvoid reader_read_process(struct dir_ent *dir_ent)\n{\n\tstruct file_buffer *prev_buffer = NULL, *file_buffer;\n\tint status, res, byte, count = 0;\n\tint file = get_pseudo_file(dir_ent->inode->pseudo_id)->fd;\n\tint child = get_pseudo_file(dir_ent->inode->pseudo_id)->child;\n\tlong long bytes = 0;\n\n\twhile(1) {\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = seq ++;\n\n\t\tbyte = read_bytes(file, file_buffer->data, block_size);\n\t\tif(byte == -1)\n\t\t\tgoto read_err;\n\n\t\tfile_buffer->size = byte;\n\t\tfile_buffer->file_size = -1;\n\t\tfile_buffer->block = count ++;\n\t\tfile_buffer->error = FALSE;\n\t\tfile_buffer->fragment = FALSE;\n\t\tbytes += byte;\n\n\t\tif(byte == 0)\n\t\t\tbreak;\n\n\t\t/*\n\t\t * Update estimated_uncompressed block count.  This is done\n\t\t * on every block rather than waiting for all blocks to be\n\t\t * read incase write_file_process() is running in parallel\n\t\t * with this.  Otherwise cur uncompressed block count may\n\t\t * get ahead of the total uncompressed block count.\n\t\t */ \n\t\testimated_uncompressed ++;\n\n\t\tif(prev_buffer)\n\t\t\tqueue_put(from_reader, prev_buffer);\n\t\tprev_buffer = file_buffer;\n\t}\n\n\t/*\n \t * Update inode file size now that the size of the dynamic pseudo file\n\t * is known.  This is needed for the -info option.\n\t */\n\tdir_ent->inode->buf.st_size = bytes;\n\n\tres = waitpid(child, &status, 0);\n\tif(res == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)\n\t\tgoto read_err;\n\n\tif(prev_buffer == NULL)\n\t\tprev_buffer = file_buffer;\n\telse {\n\t\tcache_block_put(file_buffer);\n\t\tseq --;\n\t}\n\tprev_buffer->file_size = bytes;\n\tprev_buffer->fragment = !no_fragments &&\n\t\t(count == 2 || always_use_fragments) && (byte < block_size);\n\tqueue_put(from_reader, prev_buffer);\n\n\treturn;\n\nread_err:\n\tif(prev_buffer) {\n\t\tcache_block_put(file_buffer);\n\t\tseq --;\n\t\tfile_buffer = prev_buffer;\n\t}\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_read_file(struct dir_ent *dir_ent)\n{\n\tstruct stat *buf = &dir_ent->inode->buf, buf2;\n\tstruct file_buffer *file_buffer;\n\tint blocks, byte, count, expected, file, frag_block;\n\tlong long bytes, read_size;\n\n\tif(dir_ent->inode->read)\n\t\treturn;\n\n\tdir_ent->inode->read = TRUE;\nagain:\n\tbytes = 0;\n\tcount = 0;\n\tfile_buffer = NULL;\n\tread_size = buf->st_size;\n\tblocks = (read_size + block_size - 1) >> block_log;\n\tfrag_block = !no_fragments && (always_use_fragments ||\n\t\t(read_size < block_size)) ? read_size >> block_log : -1;\n\n\tfile = open(dir_ent->pathname, O_RDONLY);\n\tif(file == -1) {\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = seq ++;\n\t\tgoto read_err;\n\t}\n\n\tdo {\n\t\texpected = read_size - ((long long) count * block_size) >\n\t\t\tblock_size ? block_size :\n\t\t\tread_size - ((long long) count * block_size);\n\n\t\tif(file_buffer)\n\t\t\tqueue_put(from_reader, file_buffer);\n\t\tfile_buffer = cache_get(reader_buffer, 0, 0);\n\t\tfile_buffer->sequence = seq ++;\n\n\t\t/*\n\t\t * Always try to read block_size bytes from the file rather\n\t\t * than expected bytes (which will be less than the block_size\n\t\t * at the file tail) to check that the file hasn't grown\n\t\t * since being stated.  If it is longer (or shorter) than\n\t\t * expected, then restat, and try again.  Note the special\n\t\t * case where the file is an exact multiple of the block_size\n\t\t * is dealt with later.\n\t\t */\n\t\tbyte = file_buffer->size = read_bytes(file, file_buffer->data,\n\t\t\tblock_size);\n\n\t\tfile_buffer->file_size = read_size;\n\n\t\tif(byte == -1)\n\t\t\tgoto read_err;\n\n\t\tif(byte != expected)\n\t\t\tgoto restat;\n\n\t\tfile_buffer->block = count;\n\t\tfile_buffer->error = FALSE;\n\t\tfile_buffer->fragment = (file_buffer->block == frag_block);\n\n\t\tbytes += byte;\n\t\tcount ++;\n\t} while(count < blocks);\n\n\tif(read_size != bytes)\n\t\tgoto restat;\n\n\tif(expected == block_size) {\n\t\t/*\n\t\t * Special case where we've not tried to read past the end of\n\t\t * the file.  We expect to get EOF, i.e. the file isn't larger\n\t\t * than we expect.\n\t\t */\n\t\tchar buffer;\n\t\tint res;\n\n\t\tres = read_bytes(file, &buffer, 1);\n\t\tif(res == -1)\n\t\t\tgoto read_err;\n\n\t\tif(res != 0)\n\t\t\tgoto restat;\n\t}\n\n\tqueue_put(from_reader, file_buffer);\n\n\tclose(file);\n\n\treturn;\n\nrestat:\n\tfstat(file, &buf2);\n\tclose(file);\n\tif(read_size != buf2.st_size) {\n\t\tmemcpy(buf, &buf2, sizeof(struct stat));\n\t\tfile_buffer->error = 2;\n\t\tqueue_put(from_deflate, file_buffer);\n\t\tgoto again;\n\t}\nread_err:\n\tfile_buffer->error = TRUE;\n\tqueue_put(from_deflate, file_buffer);\n}\n\n\nvoid reader_scan(struct dir_info *dir) {\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tstruct dir_ent *dir_ent = dir->list[i];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->inode->root_entry)\n\t\t\tcontinue;\n\n\t\tif(IS_PSEUDO_PROCESS(dir_ent->inode)) {\n\t\t\treader_read_process(dir_ent);\n\t\t\tcontinue;\n\t\t}\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\treader_read_file(dir_ent);\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\treader_scan(dir_ent->dir);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n\nvoid *reader(void *arg)\n{\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tif(!sorted)\n\t\treader_scan(queue_get(to_reader));\n\telse {\n\t\tint i;\n\t\tstruct priority_entry *entry;\n\n\t\tqueue_get(to_reader);\n\t\tfor(i = 65535; i >= 0; i--)\n\t\t\tfor(entry = priority_list[i]; entry;\n\t\t\t\t\t\t\tentry = entry->next)\n\t\t\t\treader_read_file(entry->dir);\n\t}\n\n\tthread[0] = 0;\n\n\tpthread_exit(NULL);\n}\n\n\nvoid *writer(void *arg)\n{\n\tint write_error = FALSE;\n\tint oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(to_writer);\n\t\toff_t off;\n\n\t\tif(file_buffer == NULL) {\n\t\t\tqueue_put(from_writer,\n\t\t\t\twrite_error ? &write_error : NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\toff = file_buffer->block;\n\n\t\tpthread_mutex_lock(&pos_mutex);\n\n\t\tif(!write_error && lseek(fd, off, SEEK_SET) == -1) {\n\t\t\tERROR(\"Lseek on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\n\t\tif(!write_error && write_bytes(fd, file_buffer->data,\n\t\t\t\tfile_buffer->size) == -1) {\n\t\t\tERROR(\"Write on destination failed because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t\t\twrite_error = TRUE;\n\t\t}\n\t\tpthread_mutex_unlock(&pos_mutex);\n\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\nint all_zero(struct file_buffer *file_buffer)\n{\n\tint i;\n\tlong entries = file_buffer->size / sizeof(long);\n\tlong *p = (long *) file_buffer->data;\n\n\tfor(i = 0; i < entries && p[i] == 0; i++);\n\n\tif(i == entries) {\n\t\tfor(i = file_buffer->size & ~(sizeof(long) - 1);\n\t\t\ti < file_buffer->size && file_buffer->data[i] == 0;\n\t\t\ti++);\n\n\t\treturn i == file_buffer->size;\n\t}\n\n\treturn 0;\n}\n\n\nvoid *deflator(void *arg)\n{\n\tvoid *stream = NULL;\n\tint res, oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tres = compressor_init(comp, &stream, block_size, 1);\n\tif(res)\n\t\tBAD_ERROR(\"deflator:: compressor_init failed\\n\");\n\n\twhile(1) {\n\t\tstruct file_buffer *file_buffer = queue_get(from_reader);\n\t\tstruct file_buffer *write_buffer;\n\n\t\tif(sparse_files && all_zero(file_buffer)) { \n\t\t\tfile_buffer->c_byte = 0;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else if(file_buffer->fragment) {\n\t\t\tfile_buffer->c_byte = file_buffer->size;\n\t\t\tqueue_put(from_deflate, file_buffer);\n\t\t} else {\n\t\t\twrite_buffer = cache_get(writer_buffer, 0, 0);\n\t\t\twrite_buffer->c_byte = mangle2(stream,\n\t\t\t\twrite_buffer->data, file_buffer->data,\n\t\t\t\tfile_buffer->size, block_size, noD, 1);\n\t\t\twrite_buffer->sequence = file_buffer->sequence;\n\t\t\twrite_buffer->file_size = file_buffer->file_size;\n\t\t\twrite_buffer->block = file_buffer->block;\n\t\t\twrite_buffer->size = SQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t(write_buffer->c_byte);\n\t\t\twrite_buffer->fragment = FALSE;\n\t\t\twrite_buffer->error = FALSE;\n\t\t\tcache_block_put(file_buffer);\n\t\t\tqueue_put(from_deflate, write_buffer);\n\t\t}\n\t}\n}\n\n\nvoid *frag_deflator(void *arg)\n{\n\tvoid *stream = NULL;\n\tint res, oldstate;\n\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\n\n\tres = compressor_init(comp, &stream, block_size, 1);\n\tif(res)\n\t\tBAD_ERROR(\"frag_deflator:: compressor_init failed\\n\");\n\n\twhile(1) {\n\t\tint c_byte, compressed_size;\n\t\tstruct file_buffer *file_buffer = queue_get(to_frag);\n\t\tstruct file_buffer *write_buffer =\n\t\t\tcache_get(writer_buffer, file_buffer->block +\n\t\t\tFRAG_INDEX, 1);\n\n\t\tc_byte = mangle2(stream, write_buffer->data, file_buffer->data,\n\t\t\tfile_buffer->size, block_size, noF, 1);\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\twrite_buffer->size = compressed_size;\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\tif(fragments_locked == FALSE) {\n\t\t\tfragment_table[file_buffer->block].size = c_byte;\n\t\t\tfragment_table[file_buffer->block].start_block = bytes;\n\t\t\twrite_buffer->block = bytes;\n\t\t\tbytes += compressed_size;\n\t\t\tfragments_outstanding --;\n\t\t\tqueue_put(to_writer, write_buffer);\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tTRACE(\"Writing fragment %lld, uncompressed size %d, \"\n\t\t\t\t\"compressed size %d\\n\", file_buffer->block,\n\t\t\t\tfile_buffer->size, compressed_size);\n\t\t} else {\n\t\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\t\tadd_pending_fragment(write_buffer, c_byte,\n\t\t\t\t\tfile_buffer->block);\n\t\t}\n\t\tcache_block_put(file_buffer);\n\t}\n}\n\n\n#define HASH_ENTRIES\t\t256\n#define BLOCK_HASH(a)\t\t(a % HASH_ENTRIES)\nstruct file_buffer\t\t*block_hash[HASH_ENTRIES];\n\nvoid push_buffer(struct file_buffer *file_buffer)\n{\n\tint hash = BLOCK_HASH(file_buffer->sequence);\n\n\tfile_buffer->next = block_hash[hash];\n\tblock_hash[hash] = file_buffer;\n}\n\n\nstruct file_buffer *get_file_buffer(struct queue *queue)\n{\n\tstatic unsigned int sequence = 0;\n\tint hash = BLOCK_HASH(sequence);\n\tstruct file_buffer *file_buffer = block_hash[hash], *prev = NULL;\n\n\tfor(;file_buffer; prev = file_buffer, file_buffer = file_buffer->next)\n\t\tif(file_buffer->sequence == sequence)\n\t\t\tbreak;\n\n\tif(file_buffer) {\n\t\tif(prev)\n\t\t\tprev->next = file_buffer->next;\n\t\telse\n\t\t\tblock_hash[hash] = file_buffer->next;\n\t} else {\n\t\twhile(1) {\n\t\t\tfile_buffer = queue_get(queue);\n\t\t\tif(file_buffer->sequence == sequence)\n\t\t\t\tbreak;\n\t\t\tpush_buffer(file_buffer);\n\t\t}\n\t}\n\n\tsequence ++;\n\n\treturn file_buffer;\n}\n\n\nvoid *progress_thrd(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tprintf(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&progress_mutex);\n\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) *\n\t\t\t1000;\n\t\tpthread_cond_timedwait(&progress_wait, &progress_mutex,\n\t\t\t&timespec);\n\t\tif(progress_enabled && estimated_uncompressed)\n\t\t\tprogress_bar(cur_uncompressed, estimated_uncompressed,\n\t\t\t\tcolumns);\n\t}\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&progress_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&progress_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits, used, hashes, spaces;\n\tstatic int tty = -1;\n\n\tif(max == 0)\n\t\treturn;\n\n\tmax_digits = floor(log10(max)) + 1;\n\tused = max_digits * 2 + 11;\n\thashes = (current * (columns - used)) / max;\n\tspaces = columns - used - hashes;\n\n\tif((current > max) || (columns - used < 0))\n\t\treturn;\n\n\tif(tty == -1)\n\t\ttty = isatty(STDOUT_FILENO);\n\tif(!tty) {\n\t\tstatic long long previous = -1;\n\n\t\t/* Updating much more frequently than this results in huge\n\t\t * log files. */\n\t\tif((current % 100) != 0 && current != max)\n\t\t\treturn;\n\t\t/* Don't update just to rotate the spinner. */\n\t\tif(current == previous)\n\t\t\treturn;\n\t\tprevious = current;\n\t}\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\nvoid write_file_empty(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tfile_count ++;\n\t*duplicate_file = FALSE;\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, 0, 0, 0,\n\t\t NULL, &empty_fragment, NULL, 0);\n}\n\n\nvoid write_file_frag_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint size, int *duplicate_file, struct file_buffer *file_buffer,\n\tunsigned short checksum)\n{\n\tstruct file_info *dupl_ptr;\n\tstruct fragment *fragment;\n\tunsigned int *block_listp = NULL;\n\tlong long start = 0;\n\n\tdupl_ptr = duplicate(size, 0, &block_listp, &start, &fragment,\n\t\tfile_buffer, 0, 0, checksum, TRUE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfragment = get_and_fill_fragment(file_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else\n\t\t*duplicate_file = TRUE;\n\n\tcache_block_put(file_buffer);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\tinc_progress_bar();\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, size, 0,\n\t\t\t0, NULL, fragment, NULL, 0);\n}\n\n\nvoid write_file_frag(squashfs_inode *inode, struct dir_ent *dir_ent, int size,\n\tstruct file_buffer *file_buffer, int *duplicate_file)\n{\n\tstruct fragment *fragment;\n\tunsigned short checksum;\n\n\tchecksum = get_checksum_mem_buffer(file_buffer);\n\n\tif(pre_duplicate_frag(size, checksum)) {\n\t\twrite_file_frag_dup(inode, dir_ent, size, duplicate_file,\n\t\t\tfile_buffer, checksum);\n\t\treturn;\n\t}\n\t\t\n\tfragment = get_and_fill_fragment(file_buffer);\n\n\tcache_block_put(file_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(size, 0, NULL, 0, fragment, 0, checksum, TRUE);\n\n\ttotal_bytes += size;\n\tfile_count ++;\n\n\t*duplicate_file = FALSE;\n\n\tinc_progress_bar();\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, size, 0,\n\t\t\t0, NULL, fragment, NULL, 0);\n\n\treturn;\n}\n\n\nint write_file_process(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tstruct file_buffer *read_buffer, int *duplicate_file)\n{\n\tlong long read_size, file_bytes, start;\n\tstruct fragment *fragment;\n\tunsigned int *block_list = NULL;\n\tint block = 0, status;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\t*duplicate_file = FALSE;\n\n\tlock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\twhile (1) {\n\t\tread_size = read_buffer->file_size;\n\t\tif(read_buffer->fragment && read_buffer->c_byte)\n\t\t\tfragment_buffer = read_buffer;\n\t\telse {\n\t\t\tblock_list = realloc(block_list, (block + 1) *\n\t\t\t\tsizeof(unsigned int));\n\t\t\tif(block_list == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory allocating block_list\"\n\t\t\t\t\t\"\\n\");\n\t\t\tblock_list[block ++] = read_buffer->c_byte;\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else {\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(read_size != -1)\n\t\t\tbreak;\n\n\t\tread_buffer = get_file_buffer(from_deflate);\n\t\tif(read_buffer->error)\n\t\t\tgoto read_err;\n\t}\n\n\tunlock_fragments();\n\tfragment = get_and_fill_fragment(fragment_buffer);\n\tcache_block_put(fragment_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment,\n\t\t\t0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, read_size, start,\n\t\t block, block_list, fragment, NULL, sparse);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(!block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tlong long file_bytes, start;\n\tstruct fragment *fragment;\n\tunsigned int *block_list;\n\tint block, status;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\t*duplicate_file = FALSE;\n\n\tblock_list = malloc(blocks * sizeof(unsigned int));\n\tif(block_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\n\tlock_fragments();\n\n\tfile_bytes = 0;\n\tstart = bytes;\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t} else {\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tfragment = get_and_fill_fragment(fragment_buffer);\n\tcache_block_put(fragment_buffer);\n\n\tif(duplicate_checking)\n\t\tadd_non_dup(read_size, file_bytes, block_list, start, fragment,\n\t\t\t0, 0, FALSE);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, read_size, start,\n\t\t blocks, block_list, fragment, NULL, sparse);\n\n\tif(duplicate_checking == FALSE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(!block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nint write_file_blocks_dup(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tlong long read_size, struct file_buffer *read_buffer,\n\tint *duplicate_file)\n{\n\tint block, thresh;\n\tlong long file_bytes, dup_start, start;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr;\n\tint blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int *block_list, *block_listp;\n\tstruct file_buffer **buffer_list;\n\tint status, num_locked_fragments;\n\tlong long sparse = 0;\n\tstruct file_buffer *fragment_buffer = NULL;\n\n\tblock_list = malloc(blocks * sizeof(unsigned int));\n\tif(block_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tbuffer_list = malloc(blocks * sizeof(struct file_buffer *));\n\tif(buffer_list == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating file block list\\n\");\n\n\tnum_locked_fragments = lock_fragments();\n\n\tfile_bytes = 0;\n\tstart = dup_start = bytes;\n\tthresh = blocks > (writer_buffer_size - num_locked_fragments) ?\n\t\tblocks - (writer_buffer_size - num_locked_fragments): 0;\n\n\tfor(block = 0; block < blocks;) {\n\t\tif(read_buffer->fragment && read_buffer->c_byte) {\n\t\t\tfragment_buffer = read_buffer;\n\t\t\tblocks = read_size >> block_log;\n\t\t} else {\n\t\t\tblock_list[block] = read_buffer->c_byte;\n\n\t\t\tif(read_buffer->c_byte) {\n\t\t\t\tread_buffer->block = bytes;\n\t\t\t\tbytes += read_buffer->size;\n\t\t\t\tfile_bytes += read_buffer->size;\n\t\t\t\tcache_rehash(read_buffer, read_buffer->block);\n\t\t\t\tif(block < thresh) {\n\t\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\t\tqueue_put(to_writer, read_buffer);\n\t\t\t\t} else\n\t\t\t\t\tbuffer_list[block] = read_buffer;\n\t\t\t} else {\n\t\t\t\tbuffer_list[block] = NULL;\n\t\t\t\tsparse += read_buffer->size;\n\t\t\t\tcache_block_put(read_buffer);\n\t\t\t}\n\t\t}\n\t\tinc_progress_bar();\n\n\t\tif(++block < blocks) {\n\t\t\tread_buffer = get_file_buffer(from_deflate);\n\t\t\tif(read_buffer->error)\n\t\t\t\tgoto read_err;\n\t\t}\n\t}\n\n\tdupl_ptr = duplicate(read_size, file_bytes, &block_listp, &dup_start,\n\t\t&fragment, fragment_buffer, blocks, 0, 0, FALSE);\n\n\tif(dupl_ptr) {\n\t\t*duplicate_file = FALSE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tif(buffer_list[block])\n\t\t\t\tqueue_put(to_writer, buffer_list[block]);\n\t\tfragment = get_and_fill_fragment(fragment_buffer);\n\t\tdupl_ptr->fragment = fragment;\n\t} else {\n\t\t*duplicate_file = TRUE;\n\t\tfor(block = thresh; block < blocks; block ++)\n\t\t\tcache_block_put(buffer_list[block]);\n\t\tbytes = start;\n\t\tif(thresh && !block_device) {\n\t\t\tint res;\n\n\t\t\tqueue_put(to_writer, NULL);\n\t\t\tif(queue_get(from_writer) != 0)\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\tres = ftruncate(fd, bytes);\n\t\t\tif(res != 0)\n\t\t\t\tBAD_ERROR(\"Failed to truncate dest file because\"\n\t\t\t\t\t\"  %s\\n\", strerror(errno));\n\t\t}\n\t}\n\n\tunlock_fragments();\n\tcache_block_put(fragment_buffer);\n\tfree(buffer_list);\n\tfile_count ++;\n\ttotal_bytes += read_size;\n\n\t/*\n\t * sparse count is needed to ensure squashfs correctly reports a\n \t * a smaller block count on stat calls to sparse files.  This is\n \t * to ensure intelligent applications like cp correctly handle the\n \t * file as a sparse file.  If the file in the original filesystem isn't\n \t * stored as a sparse file then still store it sparsely in squashfs, but\n \t * report it as non-sparse on stat calls to preserve semantics\n \t */\n\tif(sparse && (dir_ent->inode->buf.st_blocks << 9) >= read_size)\n\t\tsparse = 0;\n\n\tcreate_inode(inode, NULL, dir_ent, SQUASHFS_FILE_TYPE, read_size,\n\t\tdup_start, blocks, block_listp, fragment, NULL, sparse);\n\n\tif(*duplicate_file == TRUE)\n\t\tfree(block_list);\n\n\treturn 0;\n\nread_err:\n\tcur_uncompressed -= block;\n\tstatus = read_buffer->error;\n\tbytes = start;\n\tif(thresh && !block_device) {\n\t\tint res;\n\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t\tres = ftruncate(fd, bytes);\n\t\tif(res != 0)\n\t\t\tBAD_ERROR(\"Failed to truncate dest file because %s\\n\",\n\t\t\t\tstrerror(errno));\n\t}\n\tunlock_fragments();\n\tfor(blocks = thresh; blocks < block; blocks ++)\n\t\tcache_block_put(buffer_list[blocks]);\n\tfree(buffer_list);\n\tfree(block_list);\n\tcache_block_put(read_buffer);\n\treturn status;\n}\n\n\nvoid write_file(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *duplicate_file)\n{\n\tint status;\n\tstruct file_buffer *read_buffer;\n\tlong long read_size;\n\nagain:\n\tread_buffer = get_file_buffer(from_deflate);\n\n\tstatus = read_buffer->error;\n\tif(status) {\n\t\tcache_block_put(read_buffer);\n\t\tgoto file_err;\n\t}\n\t\n\tread_size = read_buffer->file_size;\n\n\tif(read_size == -1)\n\t\tstatus = write_file_process(inode, dir_ent, read_buffer,\n\t\t\tduplicate_file);\n\telse if(read_size == 0) {\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t\tcache_block_put(read_buffer);\n\t} else if(read_buffer->fragment && read_buffer->c_byte)\n\t\twrite_file_frag(inode, dir_ent, read_size, read_buffer,\n\t\t\tduplicate_file);\n\telse if(pre_duplicate(read_size))\n\t\tstatus = write_file_blocks_dup(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\telse\n\t\tstatus = write_file_blocks(inode, dir_ent, read_size,\n\t\t\tread_buffer, duplicate_file);\n\nfile_err:\n\tif(status == 2) {\n\t\tERROR(\"File %s changed size while reading filesystem, \"\n\t\t\t\"attempting to re-read\\n\", dir_ent->pathname);\n\t\tgoto again;\n\t} else if(status == 1) {\n\t\tERROR(\"Failed to read file %s, creating empty file\\n\",\n\t\t\tdir_ent->pathname);\n\t\twrite_file_empty(inode, dir_ent, duplicate_file);\n\t}\n}\n\n\n#define BUFF_SIZE 8192\nchar b_buffer[BUFF_SIZE];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getcwd(b_buffer, BUFF_SIZE);\n\t\tif(result == NULL)\n\t\t\treturn NULL;\n\t\tstrcat(strcat(b_buffer, \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) ||\n\t\t\t\t((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tinode = malloc(sizeof(struct inode_info));\n\tif(inode == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\"\n\t\t\t\"\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->read = FALSE;\n\tinode->root_entry = FALSE;\n\tinode->pseudo_file = FALSE;\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\n\tif((buf->st_mode & S_IFMT) == S_IFREG)\n\t\testimated_uncompressed += (buf->st_size + block_size - 1) >>\n\t\t\tblock_log;\n\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir,\n\tstruct inode_info *inode_info, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0) {\n\t\tdir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) *\n\t\t\t\tsizeof(struct dir_ent *));\n\t\tif(dir->list == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\t}\n\n\tdir->list[dir->count] = malloc(sizeof(struct dir_ent));\n\tif(dir->list[dir->count] == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) :\n\t\tNULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count++]->our_dir = dir;\n\tdir->byte_count += strlen(name) + sizeof(struct squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tstruct dir_info *dir;\n\n\tdir = malloc(sizeof(struct dir_info));\n\tif(dir == NULL)\n\t\tBAD_ERROR(\"Out of memory in scan1_opendir\\n\");\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count\n\t\t= 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries) {\n\t\tint i;\n\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].inode.type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL,\n\t\t\t\t&old_root_entry[i].inode, dir);\n\t\t}\n\t}\n\n\twhile(index < source) {\n\t\tchar *basename = getbase(source_path[index]);\n\t\tint n, pass = 1;\n\n\t\tif(basename == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\",\n\t\t\t\tsource_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count &&\n\t\t\t\tstrcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i;\n\n\tif(dir->count < old_root_entries) {\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].inode.type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL,\n\t\t\t\t&old_root_entry[i].inode, dir);\n\t\t}\n\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tint pass = 1;\n\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count &&\n\t\t\t\tstrcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying\"\n\t\t\t\t\" \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name = readdir(dir->linuxdir);\n\n\tif(d_name != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"),\n\t\t\td_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->inode->root_entry)\n\t\t\tcontinue;\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nstruct dir_ent *scan2_lookup(struct dir_info *dir, char *name)\n{\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++)\n\t\tif(strcmp(dir->list[i]->name, name) == 0)\n\t\t\treturn dir->list[i];\n\n\treturn NULL;\n}\n\n\nstruct dir_ent *scan3_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->inode->root_entry)\n\t\t\tadd_dir(dir_info->list[current_count]->inode->inode,\n\t\t\t\tdir_info->list[current_count]->inode->inode_number,\n\t\t\t\tdir_info->list[current_count]->name,\n\t\t\t\tdir_info->list[current_count]->inode->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn NULL;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n\tfree(dir->pathname);\n\tdir->pathname = NULL;\n}\n\n\nvoid scan2_freedir(struct dir_info *dir)\n{\n\tdir->current_count = 0;\n\tif(dir->pathname) {\n\t\tfree(dir->pathname);\n\t\tdir->pathname = NULL;\n\t}\n}\n\n\nvoid scan3_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct stat buf;\n\tstruct dir_info *dir_info = dir_scan1(pathname, paths, _readdir);\n\tstruct dir_ent *dir_ent;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tdir_scan2(dir_info, pseudo);\n\n\tdir_ent = malloc(sizeof(struct dir_ent));\n\tif(dir_ent == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif(pathname[0] == '\\0') {\n\t\t/*\n \t\t * dummy top level directory, if multiple sources specified on\n\t\t * command line\n\t\t */\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_dev = 0;\n\t\tbuf.st_ino = 0;\n\t\tdir_ent->inode = lookup_inode(&buf);\n\t\tdir_ent->inode->pseudo_file = PSEUDO_FILE_OTHER;\n\t} else {\n\t\tif(lstat(pathname, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\",\n\t\t\t\tpathname, strerror(errno));\n\t\t\treturn;\n\t\t}\n\t\tdir_ent->inode = lookup_inode(&buf);\n\t}\n\n\tif(root_inode_number) {\n\t\tdir_ent->inode->inode_number = root_inode_number;\n\t\tdir_inode_no --;\n\t}\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->our_dir = NULL;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(sorted) {\n\t\tint res = generate_file_priorities(dir_info, 0,\n\t\t\t&dir_info->dir_ent->inode->buf);\n\n\t\tif(res == FALSE)\n\t\t\tBAD_ERROR(\"generate_file_priorities failed\\n\");\n\t}\n\tqueue_put(to_reader, dir_info);\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tif(progress)\n\t\tenable_progress_bar();\n\tdir_scan3(inode, dir_info);\n\tdir_ent->inode->inode = *inode;\n\tdir_ent->inode->type = SQUASHFS_DIR_TYPE;\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, struct pathnames *paths,\n\tint (_readdir)(char *, char *, struct dir_info *))\n{\n\tchar filename[8192], dir_name[8192];\n\tstruct dir_info *dir = scan1_opendir(pathname);\n\n\tif(dir == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\t\tstruct dir_info *sub_dir;\n\t\tstruct stat buf;\n\t\tstruct pathnames *new;\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat dir/file %s because %s, ignoring\",\n\t\t\t\tfilename, strerror(errno));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) != S_IFREG &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFDIR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFLNK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFCHR &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFBLK &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFIFO &&\n\t\t\t(buf.st_mode & S_IFMT) != S_IFSOCK) {\n\t\t\tERROR(\"File %s has unrecognised filetype %d, ignoring\"\n\t\t\t\t\"\\n\", filename, buf.st_mode & S_IFMT);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(old_exclude) {\n\t\t\tif(old_excluded(filename, &buf))\n\t\t\t\tcontinue;\n\t\t} else {\n\t\t\tif(excluded(paths, dir_name, &new))\n\t\t\t\tcontinue;\n\t\t}\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tsub_dir = dir_scan1(filename, new, scan1_readdir);\n\t\t\tif(sub_dir == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf),\n\t\t\tdir);\n\t}\n\n\tscan1_freedir(dir);\n\nerror:\n\treturn dir;\n}\n\n\nstruct dir_info *dir_scan2(struct dir_info *dir, struct pseudo *pseudo)\n{\n\tstruct dir_info *sub_dir;\n\tstruct dir_ent *dir_ent;\n\tstruct pseudo_entry *pseudo_ent;\n\tstruct stat buf;\n\tstatic int pseudo_ino = 1;\n\t\n\tif(dir == NULL && (dir = scan1_opendir(\"\")) == NULL)\n\t\treturn NULL;\n\t\n\twhile((dir_ent = scan2_readdir(dir)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *name = dir_ent->name;\n\n\t\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\tdir_scan2(dir_ent->dir, pseudo_subdir(name, pseudo));\n\t}\n\n\twhile((pseudo_ent = pseudo_readdir(pseudo)) != NULL) {\n\t\tdir_ent = scan2_lookup(dir, pseudo_ent->name);\n\t\tif(pseudo_ent->dev->type == 'm') {\n\t\t\tstruct stat *buf;\n\t\t\tif(dir_ent == NULL) {\n\t\t\t\tERROR(\"Pseudo modify file \\\"%s\\\" does not exist \"\n\t\t\t\t\t\"in source filesystem.  Ignoring.\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(dir_ent->inode->root_entry) {\n\t\t\t\tERROR(\"Pseudo modify file \\\"%s\\\" is a pre-existing\"\n\t\t\t\t\t\" file in the filesystem being appended\"\n\t\t\t\t\t\"  to.  It cannot be modified. \"\n\t\t\t\t\t\"Ignoring.\\n\", pseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tbuf = &dir_ent->inode->buf;\n\t\t\tbuf->st_mode = (buf->st_mode & S_IFMT) |\n\t\t\t\tpseudo_ent->dev->mode;\n\t\t\tbuf->st_uid = pseudo_ent->dev->uid;\n\t\t\tbuf->st_gid = pseudo_ent->dev->gid;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(dir_ent) {\n\t\t\tif(dir_ent->inode->root_entry)\n\t\t\t\tERROR(\"Pseudo file \\\"%s\\\" is a pre-existing\"\n\t\t\t\t\t\" file in the filesystem being appended\"\n\t\t\t\t\t\"  to.  Ignoring.\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\telse\n\t\t\t\tERROR(\"Pseudo file \\\"%s\\\" exists in source \"\n\t\t\t\t\t\"filesystem \\\"%s\\\".\\nIgnoring, \"\n\t\t\t\t\t\"exclude it (-e/-ef) to override.\\n\",\n\t\t\t\t\tpseudo_ent->pathname,\n\t\t\t\t\tdir_ent->pathname);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(pseudo_ent->dev->type == 'd') {\n\t\t\tsub_dir = dir_scan2(NULL, pseudo_ent->pseudo);\n\t\t\tif(sub_dir == NULL) {\n\t\t\t\tERROR(\"Could not create pseudo directory \\\"%s\\\"\"\n\t\t\t\t\t\", skipping...\\n\",\n\t\t\t\t\tpseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tmemset(&buf, 0, sizeof(buf));\n\t\tbuf.st_mode = pseudo_ent->dev->mode;\n\t\tbuf.st_uid = pseudo_ent->dev->uid;\n\t\tbuf.st_gid = pseudo_ent->dev->gid;\n\t\tbuf.st_rdev = makedev(pseudo_ent->dev->major,\n\t\t\tpseudo_ent->dev->minor);\n\t\tbuf.st_mtime = time(NULL);\n\t\tbuf.st_ino = pseudo_ino ++;\n\n\t\tif(pseudo_ent->dev->type == 'f') {\n#ifdef USE_TMP_FILE\n\t\t\tstruct stat buf2;\n\t\t\tint res = stat(pseudo_ent->dev->filename, &buf2);\n\t\t\tstruct inode_info *inode;\n\t\t\tif(res == -1) {\n\t\t\t\tERROR(\"Stat on pseudo file \\\"%s\\\" failed, \"\n\t\t\t\t\t\"skipping...\", pseudo_ent->pathname);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tbuf.st_size = buf2.st_size;\n\t\t\tinode = lookup_inode(&buf);\n\t\t\tinode->pseudo_file = PSEUDO_FILE_OTHER;\t\t\n\t\t\tadd_dir_entry(pseudo_ent->name,\n\t\t\t\tpseudo_ent->dev->filename, sub_dir, inode,\n\t\t\t\tdir);\n#else\n\t\t\tstruct inode_info *inode = lookup_inode(&buf);\n\t\t\tinode->pseudo_id = pseudo_ent->dev->pseudo_id;\n\t\t\tinode->pseudo_file = PSEUDO_FILE_PROCESS;\t\t\n\t\t\tadd_dir_entry(pseudo_ent->name, pseudo_ent->pathname,\n\t\t\t\tsub_dir, inode, dir);\n#endif\n\t\t} else {\n\t\t\tstruct inode_info *inode = lookup_inode(&buf);\n\t\t\tinode->pseudo_file = PSEUDO_FILE_OTHER;\t\t\n\t\t\tadd_dir_entry(pseudo_ent->name, pseudo_ent->pathname,\n\t\t\t\tsub_dir, inode, dir);\n\t\t}\n\t}\n\n\tscan2_freedir(dir);\n\tsort_directory(dir);\n\n\treturn dir;\n}\n\n\nvoid dir_scan3(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint duplicate_file;\n\tchar *pathname = dir_info->dir_ent->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan3_init_dir(&dir);\n\t\n\twhile((dir_ent = scan3_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\t\t?  dir_ent->inode->inode_number :\n\t\t\tdir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\twrite_file(inode, dir_ent,\n\t\t\t\t\t\t&duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld \"\n\t\t\t\t\t\t\"bytes %s\\n\", filename,\n\t\t\t\t\t\t(long long) buf->st_size,\n\t\t\t\t\t\tduplicate_file ?  \"DUPLICATE\" :\n\t\t\t\t\t\t \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tdir_scan3(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\"\n\t\t\t\t\t\t\"\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\",dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tcreate_inode(inode, NULL, dir_ent,\n\t\t\t\t\t\tsquashfs_type, 0, 0, 0, NULL,\n\t\t\t\t\t\tNULL, NULL, 0);\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tBAD_ERROR(\"%s unrecognised file type, \"\n\t\t\t\t\t\t\"mode is %x\\n\", filename,\n\t\t\t\t\t\tbuf->st_mode);\n\t\t\t}\n\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed \"\n\t\t\t\t\t\t\t\"size %lld bytes LINK\"\n\t\t\t\t\t\t\t\"\\n\", filename,\n\t\t\t\t\t\t\t(long long)\n\t\t\t\t\t\t\tbuf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx \"\n\t\t\t\t\t\t\"LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\",\n\t\t\t\t\t\tdir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode \"\n\t\t\t\t\t\t\"0x%llx LINK\\n\", dir_name,\n\t\t\t\t\t\t*inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t\tupdate_progress_bar();\n\t}\n\n\twrite_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan3_freedir(&dir);\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 20; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint old_excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) &&\n\t\t\t\t(exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) { \\\n\t\texclude_paths = realloc(exclude_paths, (exclude + EXCLUDE_SIZE) \\\n\t\t\t* sizeof(struct exclude_info)); \\\n\t\tif(exclude_paths == NULL) \\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\"); \\\n\t} \\\n\texclude_paths[exclude].st_dev = buf.st_dev; \\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint old_add_exclude(char *path)\n{\n\tint i;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 ||\n\t\t\tstrncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tERROR(\"Cannot stat exclude dir/file %s because %s, \"\n\t\t\t\t\"ignoring\", path, strerror(errno));\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tERROR(\"Cannot stat exclude dir/file %s because \"\n\t\t\t\t\t\"%s, ignoring\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number,\n\tint type)\n{\n\told_root_entry = realloc(old_root_entry,\n\t\tsizeof(struct old_root_entry_info) * (old_root_entries + 1));\n\tif(old_root_entry == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries \"\n\t\t\t\"reallocation\\n\");\n\n\told_root_entry[old_root_entries].name = strdup(name);\n\told_root_entry[old_root_entries].inode.inode = inode;\n\told_root_entry[old_root_entries].inode.inode_number = inode_number;\n\told_root_entry[old_root_entries].inode.type = type;\n\told_root_entry[old_root_entries++].inode.root_entry = TRUE;\n}\n\n\nvoid initialise_threads(int readb_mbytes, int writeb_mbytes,\n\tint fragmentb_mbytes)\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\tint reader_buffer_size = readb_mbytes << (20 - block_log);\n\tint fragment_buffer_size = fragmentb_mbytes << (20 - block_log);\n\n\t/*\n\t * writer_buffer_size is global because it is needed in\n\t * write_file_blocks_dup()\n\t */\n\twriter_buffer_size = writeb_mbytes << (20 - block_log);\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n\n\tsignal(SIGUSR1, sigusr1_handler);\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  \"\n\t\t\t\t\"Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = sysconf(_SC_NPROCESSORS_ONLN);\n#endif\n\t}\n\n\tthread = malloc((2 + processors * 2) * sizeof(pthread_t));\n\tif(thread == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[2];\n\tfrag_deflator_thread = &deflator_thread[processors];\n\n\tto_reader = queue_init(1);\n\tfrom_reader = queue_init(reader_buffer_size);\n\tto_writer = queue_init(writer_buffer_size);\n\tfrom_writer = queue_init(1);\n\tfrom_deflate = queue_init(reader_buffer_size);\n\tto_frag = queue_init(fragment_buffer_size);\n\treader_buffer = cache_init(block_size, reader_buffer_size);\n\twriter_buffer = cache_init(block_size, writer_buffer_size);\n\tfragment_buffer = cache_init(block_size, fragment_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&progress_thread, NULL, progress_thrd, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\tpthread_cond_init(&fragment_waiting, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) !=\n\t\t\t\t 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t\tif(pthread_create(&frag_deflator_thread[i], NULL, frag_deflator,\n\t\t\t\tNULL) != 0)\n\t\t\tBAD_ERROR(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel mksquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tBAD_ERROR(\"Failed to set signal mask in intialise_threads\\n\");\n}\n\n\nlong long write_inode_lookup_table()\n{\n\tint i, inode_number, lookup_bytes = SQUASHFS_LOOKUP_BYTES(inode_count);\n\tvoid *it;\n\n\tif(inode_count == sinode_count)\n\t\tgoto skip_inode_hash_table;\n\n\tit = realloc(inode_lookup_table, lookup_bytes);\n\tif(it == NULL)\n\t\tBAD_ERROR(\"Out of memory in write_inode_table\\n\");\n\tinode_lookup_table = it;\n\n\tfor(i = 0; i < INODE_HASH_SIZE; i ++) {\n\t\tstruct inode_info *inode = inode_info[i];\n\n\t\tfor(inode = inode_info[i]; inode; inode = inode->next) {\n\n\t\t\tinode_number = inode->type == SQUASHFS_DIR_TYPE ?\n\t\t\t\tinode->inode_number : inode->inode_number +\n\t\t\t\tdir_inode_no;\n\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(&inode->inode,\n\t\t\t\t&inode_lookup_table[inode_number - 1], 1);\n\n\t\t}\n\t}\n\nskip_inode_hash_table:\n\treturn generic_write_table(lookup_bytes, inode_lookup_table, 0, NULL,\n\t\tnoI);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tpaths = malloc(sizeof(struct pathname));\n\t\tif(paths == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/* allocate new name entry */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) *\n\t\t\tsizeof(struct path_entry));\n\t\tif(paths->name == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add path\\n\");\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\tif(paths->name[i].preg == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory in add_path\\n\");\n\t\t\terror = regcomp(paths->name[i].preg, targname,\n\t\t\t\tREG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tBAD_ERROR(\"invalid regex %s in export %s, \"\n\t\t\t\t\t\"because %s\\n\", targname, alltarget,\n\t\t\t\t\tstr);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/* at leaf pathname component */\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/* recurse adding child components */\n\t\t\tpaths->name[i].paths = add_path(NULL, target,\n\t\t\t\talltarget);\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing exclude which subsumes\n\t\t\t * the exclude currently being added, in which case stop\n\t\t\t * adding components */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component and child components exist\n\t\t\t * from more specific excludes, delete as they're\n\t\t\t * subsumed by this exclude */\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/* recurse adding child components */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nvoid add_exclude(char *target)\n{\n\n\tif(target[0] == '/' || strncmp(target, \"./\", 2) == 0 ||\n\t\t\tstrncmp(target, \"../\", 3) == 0)\n\t\tBAD_ERROR(\"/, ./ and ../ prefixed excludes not supported with \"\n\t\t\t\"-wildcards or -regex options\\n\");\t\n\telse if(strncmp(target, \"... \", 4) == 0)\n\t\tstickypath = add_path(stickypath, target + 4, target + 4);\n\telse\t\n\t\tpath = add_path(path, target, target);\n}\n\n\nvoid display_path(int depth, struct pathname *paths)\n{\n\tint i, n;\n\n\tif(paths == NULL)\n\t\treturn;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tfor(n = 0; n < depth; n++)\n\t\t\tprintf(\"\\t\");\n\t\tprintf(\"%d: %s\\n\", depth, paths->name[i].name);\n\t\tdisplay_path(depth + 1, paths->name[i].paths);\n\t}\n}\n\n\nvoid display_path2(struct pathname *paths, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tif(paths == NULL) {\n\t\tprintf(\"%s\\n\", string);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tstrcat(strcat(strcpy(path, string), \"/\"), paths->name[i].name);\n\t\tdisplay_path2(paths->name[i].paths, path);\n\t}\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames));\n\tif(new == NULL)\n\t\tBAD_ERROR(\"Out of memory in init_subdir\\n\");\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0) {\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) +\n\t\t\t(paths->count + PATHS_ALLOC_SIZE) *\n\t\t\tsizeof(struct pathname *));\n\t\tif(paths == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_subdir\\n\");\n\t}\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint excluded(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n, res;\n\t\t\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\n\t*new = init_subdir();\n\tif(stickypath)\n\t\t*new = add_subdir(*new, stickypath);\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0,\n\t\t\t\t\tNULL, 0) == 0 :\n\t\t\t\tfnmatch(path->name[i].name, name,\n\t\t\t\t\tFNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) ==\n\t\t\t\t\t 0;\n\n\t\t\tif(match && path->name[i].paths == NULL) {\n\t\t\t\t/* match on a leaf component, any subdirectories\n\t\t\t\t * in the filesystem should be excluded */\n\t\t\t\tres = TRUE;\n\t\t\t\tgoto empty_set;\n\t\t\t}\n\n\t\t\tif(match)\n\t\t\t\t/* match on a non-leaf component, add any\n\t\t\t\t * subdirectories to the new set of\n\t\t\t\t * subdirectories to scan for this name */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t\t/* no matching names found, return empty new search set\n\t\t\t */\n\t\t\tres = FALSE;\n\t\t\tgoto empty_set;\n\t}\n\n\t/* one or more matches with sub-directories found (no leaf matches).\n\t * Return new set */\n\treturn FALSE;\n\nempty_set:\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn res;\n}\n\n\n#define RECOVER_ID \"Squashfs recovery file v1.0\\n\"\n#define RECOVER_ID_SIZE 28\n\nvoid write_recovery_data(struct squashfs_super_block *sBlk)\n{\n\tint res, recoverfd, bytes = sBlk->bytes_used - sBlk->inode_table_start;\n\tpid_t pid = getpid();\n\tchar *metadata;\n\tchar header[] = RECOVER_ID;\n\n\tif(recover == FALSE) {\n\t\tprintf(\"No recovery data option specified.\\n\");\n\t\tprintf(\"Skipping saving recovery file.\\n\\n\");\n\t\treturn;\n\t}\n\n\tmetadata = malloc(bytes);\n\tif(metadata == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"write_recovery_data\\n\");\n\n\tres = read_fs_bytes(fd, sBlk->inode_table_start, bytes, metadata);\n\tif(res == 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tsprintf(recovery_file, \"squashfs_recovery_%s_%d\",\n\t\tgetbase(destination_file), pid);\n\trecoverfd = open(recovery_file, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);\n\tif(recoverfd == -1)\n\t\tBAD_ERROR(\"Failed to create recovery file, because %s.  \"\n\t\t\t\"Aborting\\n\", strerror(errno));\n\t\t\n\tif(write_bytes(recoverfd, header, RECOVER_ID_SIZE) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, sBlk, sizeof(struct squashfs_super_block)) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(write_bytes(recoverfd, metadata, bytes) == -1)\n\t\tBAD_ERROR(\"Failed to write recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tclose(recoverfd);\n\tfree(metadata);\n\t\n\tprintf(\"Recovery file \\\"%s\\\" written\\n\", recovery_file);\n\tprintf(\"If Mksquashfs aborts abnormally (i.e. power failure), run\\n\");\n\tprintf(\"mksquashfs dummy %s -recover %s\\n\", destination_file,\n\t\trecovery_file);\n\tprintf(\"to restore filesystem\\n\\n\");\n}\n\n\nvoid read_recovery_data(char *recovery_file, char *destination_file)\n{\n\tint fd, recoverfd, bytes;\n\tstruct squashfs_super_block orig_sBlk, sBlk;\n\tchar *metadata;\n\tint res;\n\tstruct stat buf;\n\tchar header[] = RECOVER_ID;\n\tchar header2[RECOVER_ID_SIZE];\n\n\trecoverfd = open(recovery_file, O_RDONLY);\n\tif(recoverfd == -1)\n\t\tBAD_ERROR(\"Failed to open recovery file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tif(stat(destination_file, &buf) == -1)\n\t\tBAD_ERROR(\"Failed to stat destination file, because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tfd = open(destination_file, O_RDWR);\n\tif(fd == -1)\n\t\tBAD_ERROR(\"Failed to open destination file because %s\\n\",\n\t\t\tstrerror(errno));\n\n\tres = read_bytes(recoverfd, header2, RECOVER_ID_SIZE);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < RECOVER_ID_SIZE)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\tif(strncmp(header, header2, RECOVER_ID_SIZE) !=0 )\n\t\tBAD_ERROR(\"Not a recovery file\\n\");\n\n\tres = read_bytes(recoverfd, &sBlk, sizeof(struct squashfs_super_block));\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < sizeof(struct squashfs_super_block))\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\tres = read_fs_bytes(fd, 0, sizeof(struct squashfs_super_block), &orig_sBlk);\n\tif(res == 0)\n\t\tEXIT_MKSQUASHFS();\n\n\tif(memcmp(((char *) &sBlk) + 4, ((char *) &orig_sBlk) + 4,\n\t\t\tsizeof(struct squashfs_super_block) - 4) != 0)\n\t\tBAD_ERROR(\"Recovery file and destination file do not seem to \"\n\t\t\t\"match\\n\");\n\n\tbytes = sBlk.bytes_used - sBlk.inode_table_start;\n\n\tmetadata = malloc(bytes);\n\tif(metadata == NULL)\n\t\tBAD_ERROR(\"Failed to alloc metadata buffer in \"\n\t\t\t\"read_recovery_data\\n\");\n\n\tres = read_bytes(recoverfd, metadata, bytes);\n\tif(res == -1)\n\t\tBAD_ERROR(\"Failed to read recovery file, because %s\\n\",\n\t\t\tstrerror(errno));\n\tif(res < bytes)\n\t\tBAD_ERROR(\"Recovery file appears to be truncated\\n\");\n\n\twrite_destination(fd, 0, sizeof(struct squashfs_super_block), &sBlk);\n\n\twrite_destination(fd, sBlk.inode_table_start, bytes, metadata);\n\n\tclose(recoverfd);\n\tclose(fd);\n\n\tprintf(\"Successfully wrote recovery file \\\"%s\\\".  Exiting\\n\",\n\t\trecovery_file);\n\t\n\texit(0);\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 4.2 (2011/02/28)\\n\");\\\n\tprintf(\"copyright (C) 2011 Phillip Lougher \"\\\n\t\t\"<phillip@lougher.demon.co.uk>\\n\\n\"); \\\n\tprintf(\"This program is free software; you can redistribute it and/or\"\\\n\t\t\"\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\"\\\n\t\t\"\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version \"\\\n\t\t\"2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be \"\\\n\t\t\"useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty \"\\\n\t\t\"of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\"\\\n\t\t\"\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf, source_buf;\n\tint res, i;\n\tstruct squashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint nopad = FALSE, keep_as_directory = FALSE;\n\tsquashfs_inode inode;\n\tint readb_mbytes = READER_BUFFER_DEFAULT,\n\t\twriteb_mbytes = WRITER_BUFFER_DEFAULT,\n\t\tfragmentb_mbytes = FRAGMENT_BUFFER_DEFAULT;\n\n\tpthread_mutex_init(&progress_mutex, NULL);\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\t/*\n\t * lookup default compressor.  Note the Makefile ensures the default\n\t * compressor has been built, and so we don't need to to check\n\t * for failure here\n\t */\n\tcomp = lookup_compressor(COMP_DEFAULT);\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-comp\") == 0) {\n\t\t\tif(compressor_opts_parsed) {\n\t\t\t\tERROR(\"%s: -comp must appear before -X options\"\n\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -comp missing compression type\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tcomp = lookup_compressor(argv[i]);\n\t\t\tif(!comp->supported) {\n\t\t\t\tERROR(\"%s: Compressor \\\"%s\\\" is not supported!\"\n\t\t\t\t\t\"\\n\", argv[0], argv[i]);\n\t\t\t\tERROR(\"%s: Compressors available:\\n\", argv[0]);\n\t\t\t\tdisplay_compressors(\"\", COMP_DEFAULT);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t} else if(strncmp(argv[i], \"-X\", 2) == 0) {\n\t\t\tint args = compressor_options(comp, argv + i, argc - i);\n\t\t\tif(args < 0) {\n\t\t\t\tif(args == -1) {\n\t\t\t\t\tERROR(\"%s: Unrecognised compressor\"\n\t\t\t\t\t\t\" option %s\\n\", argv[0],\n\t\t\t\t\t\targv[i]);\n\t\t\t\t\tERROR(\"%s: Did you forget to specify\"\n\t\t\t\t\t\t\" -comp, or specify it after\"\n\t\t\t\t\t\t\" the compressor specific\"\n\t\t\t\t\t\t\" option?\\n\", argv[0]);\n\t\t\t\t\t}\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\ti += args;\n\t\t\tcompressor_opts_parsed = 1;\n\n\t\t} else if(strcmp(argv[i], \"-pf\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -pf missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_file(&pseudo, argv[i]) == FALSE)\n\t\t\t\texit(1);\n\t\t} else if(strcmp(argv[i], \"-p\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -p missing pseudo file definition\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(read_pseudo_def(&pseudo, argv[i]) == FALSE)\n\t\t\t\texit(1);\n\t\t} else if(strcmp(argv[i], \"-recover\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -recover missing recovery file\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tread_recovery_data(argv[i], argv[source + 1]);\n\t\t} else if(strcmp(argv[i], \"-no-recovery\") == 0)\n\t\t\trecover = FALSE;\n\t\telse if(strcmp(argv[i], \"-wildcards\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = FALSE;\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0) {\n\t\t\told_exclude = FALSE;\n\t\t\tuse_regex = TRUE;\n\t\t} else if(strcmp(argv[i], \"-no-sparse\") == 0)\n\t\t\tsparse_files = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-exports\") == 0)\n\t\t\texportable = FALSE;\n\t\telse if(strcmp(argv[i], \"-processors\") == 0) {\n\t\t\tif((++i == argc) || (processors =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid \"\n\t\t\t\t\t\"processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-read-queue\") == 0) {\n\t\t\tif((++i == argc) || (readb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -read-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(readb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -read-queue should be 1 megabyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-write-queue\") == 0) {\n\t\t\tif((++i == argc) || (writeb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -write-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(writeb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -write-queue should be 1 megabyte \"\n\t\t\t\t\t\"or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-fragment-queue\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(fragmentb_mbytes =\n\t\t\t\t\tstrtol(argv[i], &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -fragment-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragmentb_mbytes < 1) {\n\t\t\t\tERROR(\"%s: -fragment-queue should be 1 \"\n\t\t\t\t\t\"megabyte or larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -b missing block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_size = strtol(argv[i], &b, 10);\n\t\t\tif(*b == 'm' || *b == 'M')\n\t\t\t\tblock_size *= 1048576;\n\t\t\telse if(*b == 'k' || *b == 'K')\n\t\t\t\tblock_size *= 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tERROR(\"%s: -b invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or \"\n\t\t\t\t\t\"not between 4096 and 1Mbyte\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or \"\n\t\t\t\t\t\t\"unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid >\n\t\t\t\t\t\t(((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\"\n\t\t\t\t\t\t\"\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or \"\n\t\t\t\t\t\t\"unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noX\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noXattrCompression\") == 0)\n\t\t\tnoX = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-no-xattrs\") == 0)\n\t\t\tno_xattrs = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-xattrs\") == 0)\n\t\t\tno_xattrs = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0) {\n\t\t\tsilent = FALSE;\n\t\t\tprogress = FALSE;\n\t\t}\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] \"\n\t\t\t\t\"[-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nFilesystem build options:\\n\");\n\t\t\tERROR(\"-comp <comp>\\t\\tselect <comp> compression\\n\");\n\t\t\tERROR(\"\\t\\t\\tCompressors available:\\n\");\n\t\t\tdisplay_compressors(\"\\t\\t\\t\", COMP_DEFAULT);\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to \"\n\t\t\t\t\"<block_size>.  Default %d bytes\\n\",\n\t\t\t\tSQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-no-exports\\t\\tdon't make the filesystem \"\n\t\t\t\t\"exportable via NFS\\n\");\n\t\t\tERROR(\"-no-sparse\\t\\tdon't detect sparse files\\n\");\n\t\t\tERROR(\"-no-xattrs\\t\\tdon't store extended attributes\"\n\t\t\t\tNOXOPT_STR \"\\n\");\n\t\t\tERROR(\"-xattrs\\t\\t\\tstore extended attributes\" XOPT_STR\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-noX\\t\\t\\tdo not compress extended \"\n\t\t\t\t\"attributes\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for \"\n\t\t\t\t\"files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate \"\n\t\t\t\t\"checking\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple \"\n\t\t\t\t\"of 4K\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is \"\n\t\t\t\t\"specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, \"\n\t\t\t\t\"rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"\\nFilesystem filter options:\\n\");\n\t\t\tERROR(\"-p <pseudo-definition>\\tAdd pseudo file \"\n\t\t\t\t\"definition\\n\");\n\t\t\tERROR(\"-pf <pseudo-file>\\tAdd list of pseudo file \"\n\t\t\t\t\"definitions\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to \"\n\t\t\t\t\"priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  \"\n\t\t\t\t\"Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.\"\n\t\t\t\t\"  One per line\\n\");\n\t\t\tERROR(\"-wildcards\\t\\tAllow extended shell wildcards \"\n\t\t\t\t\"(globbing) to be used in\\n\\t\\t\\texclude \"\n\t\t\t\t\"dirs/files\\n\");\n\t\t\tERROR(\"-regex\\t\\t\\tAllow POSIX regular expressions to \"\n\t\t\t\t\"be used in exclude\\n\\t\\t\\tdirs/files\\n\");\n\t\t\tERROR(\"\\nFilesystem append options:\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing \"\n\t\t\t\t\"filesystem\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source \"\n\t\t\t\t\"files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in \"\n\t\t\t\t\"the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new \"\n\t\t\t\t\"source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"\\nMksquashfs runtime options:\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and \"\n\t\t\t\t\"copyright message\\n\");\n\t\t\tERROR(\"-recover <name>\\t\\trecover filesystem data \"\n\t\t\t\t\"using recovery file <name>\\n\");\n\t\t\tERROR(\"-no-recovery\\t\\tdon't generate a recovery \"\n\t\t\t\t\"file\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-no-progress\\t\\tdon't display the progress \"\n\t\t\t\t\"bar\\n\");\n\t\t\tERROR(\"-processors <number>\\tUse <number> processors.\"\n\t\t\t\t\"  By default will use number of\\n\");\n\t\t\tERROR(\"\\t\\t\\tprocessors available\\n\");\n\t\t\tERROR(\"-read-queue <size>\\tSet input queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tREADER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-write-queue <size>\\tSet output queue to <size> \"\n\t\t\t\t\"Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tWRITER_BUFFER_DEFAULT);\n\t\t\tERROR(\"-fragment-queue <size>\\tSet fragment queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d Mbytes\\n\",\n\t\t\t\tFRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\nMiscellaneous options:\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for \"\n\t\t\t\t\"-noF\\n\");\n\t\t\tERROR(\"-noXattrCompression\\talternative name for \"\n\t\t\t\t\"-noX\\n\");\n\t\t\tERROR(\"\\nCompressors available and compressor specific \"\n\t\t\t\t\"options:\\n\");\n\t\t\tdisplay_compressor_usage(COMP_DEFAULT);\n\t\t\texit(1);\n\t\t}\n\t}\n\n\t/*\n\t * Some compressors may need the options to be checked for validity\n\t * once all the options have been processed\n\t */\n\tres = compressor_options_post(comp, block_size);\n\tif(res)\n\t\tEXIT_MKSQUASHFS();\n\n\tfor(i = 0; i < source; i++)\n\t\tif(lstat(source_path[i], &source_buf) == -1) {\n\t\t\tfprintf(stderr, \"Cannot stat source directory \\\"%s\\\" \"\n\t\t\t\t\"because %s\\n\", source_path[i],\n\t\t\t\tstrerror(errno));\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tfd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR,\n\t\t\t\tS_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as \"\n\t\t\t\t\t\"destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tfd = open(argv[source + 1], (delete ? O_TRUNC : 0) |\n\t\t\t\tO_RDWR);\n\t\t\tif(fd == -1) {\n\t\t\t\tperror(\"Could not open regular file for \"\n\t\t\t\t\t\"writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tsignal(SIGTERM, sighandler2);\n\tsignal(SIGINT, sighandler2);\n\n\t/*\n\t * process the exclude files - must be done afer destination file has\n\t * been possibly created\n\t */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\t\tif(old_exclude)\n\t\t\t\t\t\told_add_exclude(filename);\n\t\t\t\t\telse\n\t\t\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-sort\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-comp\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc)\n\t\t\tif(old_exclude)\n\t\t\t\told_add_exclude(argv[i++]);\n\t\t\telse\n\t\t\t\tadd_exclude(argv[i++]);\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tint res = read_sort_file(argv[++i], source,\n\t\t\t\t\t\t\t\tsource_path);\n\t\t\tif(res == FALSE)\n\t\t\t\tBAD_ERROR(\"Failed to read sort file\\n\");\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-ef\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-pf\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-comp\") == 0)\n\t\t\ti++;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(!delete) {\n\t        comp = read_super(fd, &sBlk, argv[source + 1]);\n\t        if(comp == NULL) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tnoX = SQUASHFS_UNCOMPRESSED_XATTRS(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\texportable = SQUASHFS_EXPORTABLE(sBlk.flags);\n\t\tno_xattrs = SQUASHFS_NO_XATTRS(sBlk.flags);\n\t\tcomp_opts = SQUASHFS_COMP_OPTS(sBlk.flags);\n\t}\n\n\tinitialise_threads(readb_mbytes, writeb_mbytes, fragmentb_mbytes);\n\n\tres = compressor_init(comp, &stream, SQUASHFS_METADATA_SIZE, 0);\n\tif(res)\n\t\tBAD_ERROR(\"compressor_init failed\\n\");\n\n\tif(delete) {\n\t\tint size;\n\t\tvoid *comp_data = compressor_dump_options(comp, block_size,\n\t\t\t&size);\n\n\t\tprintf(\"Creating %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\tSQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\n\t\t/*\n\t\t * store any compressor specific options after the superblock,\n\t\t * and set the COMP_OPT flag to show that the filesystem has\n\t\t * compressor specfic options\n\t\t */\n\t\tif(comp_data) {\n\t\t\tunsigned short c_byte = size | SQUASHFS_COMPRESSED_BIT;\n\t\n\t\t\tSQUASHFS_INSWAP_SHORTS(&c_byte, 1);\n\t\t\twrite_destination(fd, sizeof(struct squashfs_super_block),\n\t\t\t\tsizeof(c_byte), &c_byte);\n\t\t\twrite_destination(fd, sizeof(struct squashfs_super_block) +\n\t\t\t\tsizeof(c_byte), size, comp_data);\n\t\t\tbytes = sizeof(struct squashfs_super_block) + sizeof(c_byte)\n\t\t\t\t+ size;\n\t\t\tcomp_opts = TRUE;\n\t\t} else\t\t\t\n\t\t\tbytes = sizeof(struct squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset,\n\t\t\tinode_dir_file_size, root_inode_size,\n\t\t\tinode_dir_start_block, uncompressed_data,\n\t\t\tcompressed_data, inode_dir_inode_number,\n\t\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start =\n\t\t\tSQUASHFS_INODE_BLK(sBlk.root_inode),\n\t\t\troot_inode_offset =\n\t\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table,\n\t\t\t\t&data_cache, &directory_table,\n\t\t\t\t&directory_data_cache, &last_directory_block,\n\t\t\t\t&inode_dir_offset, &inode_dir_file_size,\n\t\t\t\t&root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count,\n\t\t\t\t&fifo_count, &sock_count, &total_bytes,\n\t\t\t\t&total_inode_bytes, &total_directory_bytes,\n\t\t\t\t&inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry,\n\t\t\t\t&fragment_table, &inode_lookup_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not \"\n\t\t\t\t\"overwrite - ABORTING!\\n\");\n\t\t\tERROR(\"To force Mksquashfs to write to this block \"\n\t\t\t\t\"device or file use -noappend\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments)) {\n\t\t\tfragment_table = realloc((char *) fragment_table,\n\t\t\t\t((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1))\n\t\t\t\t * sizeof(struct squashfs_fragment_entry)); \n\t\t\tif(fragment_table == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory in save filesystem state\\n\");\n\t\t}\n\n\t\tprintf(\"Appending to existing %d.%d filesystem on %s, block \"\n\t\t\t\"size %d\\n\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1],\n\t\t\tblock_size);\n\t\tprintf(\"All -b, -noI, -noD, -noF, -noX, no-duplicates, no-fragments, \"\n\t\t\t\"-always-use-fragments,\\n-exportable and -comp options \"\n\t\t\t\"ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with \"\n\t\t\t\"-noappend specified!\\n\\n\");\n\n\t\tcompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = (inode_dir_offset + inode_dir_file_size) &\n\t\t\t(SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tscache_bytes = root_inode_offset + root_inode_size;\n\t\tsdirectory_cache_bytes = uncompressed_data;\n\t\tsdata_cache = malloc(scache_bytes);\n\t\tif(sdata_cache == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in save filesystem state\\n\");\n\t\tsdirectory_data_cache = malloc(sdirectory_cache_bytes);\n\t\tif(sdirectory_data_cache == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in save filesystem state\\n\");\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache +\n\t\t\tcompressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes +\n\t\t\tcompressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\tsid_count = id_count;\n\t\twrite_recovery_data(&sBlk);\n\t\tif(save_xattrs() == FALSE)\n\t\t\tBAD_ERROR(\"Failed to save xattrs from existing \"\n\t\t\t\t\"filesystem\\n\");\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_destination(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/*\n\t\t * set the filesystem state up to be able to append to the\n\t\t * original filesystem.  The filesystem state differs depending\n\t\t * on whether we're appending to the original root directory, or\n\t\t * if the original root directory becomes a sub-directory\n\t\t * (root-becomes specified on command line, here root_name !=\n\t\t * NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\tsdirectory_bytes = last_directory_block;\n\t\t\tsdirectory_compressed_bytes = 0;\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache +\n\t\t\t\tcompressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode,\n\t\t\t\tinode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\tsdirectory_compressed_bytes = last_directory_block -\n\t\t\t\tinode_dir_start_block;\n\t\t\tsdirectory_compressed =\n\t\t\t\tmalloc(sdirectory_compressed_bytes);\n\t\t\tif(sdirectory_compressed == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory in save filesystem \"\n\t\t\t\t\t\"state\\n\");\n\t\t\tmemcpy(sdirectory_compressed, directory_table +\n\t\t\t\tinode_dir_start_block,\n\t\t\t\tsdirectory_compressed_bytes); \n\t\t\tsdirectory_bytes = inode_dir_start_block;\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count +\n\t\t\tfifo_count + sock_count;\n\n\t\t/*\n\t\t * The default use freelist before growing cache policy behaves\n\t\t * poorly with appending - with many deplicates the caches\n\t\t * do not grow due to the fact that large queues of outstanding\n\t\t * fragments/writer blocks do not occur, leading to small caches\n\t\t * and un-uncessary performance loss to frequent cache\n\t\t * replacement in the small caches.  Therefore with appending\n\t\t * change the policy to grow the caches before reusing blocks\n\t\t * from the freelist\n\t\t */\n\t\tfirst_freelist = FALSE;\n\t}\n\n\tif(path || stickypath) {\n\t\tpaths = init_subdir();\n\t\tif(path)\n\t\t\tpaths = add_subdir(paths, path);\n\t\tif(stickypath)\n\t\t\tpaths = add_subdir(paths, stickypath);\n\t}\n\n\tif(delete && !keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 &&\n\t\t\tS_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, noX, no_fragments,\n\t\talways_use_fragments, duplicate_checking, exportable,\n\t\tno_xattrs, comp_opts);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\tif(progress && estimated_uncompressed) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(cur_uncompressed, estimated_uncompressed, columns);\n\t}\n\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tif(!restoring) {\n\t\tunlock_fragments();\n\t\tpthread_mutex_lock(&fragment_mutex);\n\t\twhile(fragments_outstanding) {\n\t\t\tpthread_mutex_unlock(&fragment_mutex);\n\t\t\tsched_yield();\n\t\t\tpthread_mutex_lock(&fragment_mutex);\n\t\t}\n\t\tqueue_put(to_writer, NULL);\n\t\tif(queue_get(from_writer) != 0)\n\t\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tsBlk.no_ids = id_count;\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\tsBlk.lookup_table_start = exportable ? write_inode_lookup_table() :\n\t\tSQUASHFS_INVALID_BLK;\n\tsBlk.id_table_start = write_id_table();\n\tsBlk.xattr_id_table_start = write_xattrs();\n\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\",\n\t\tsBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk.fragment_table_start);\n\tif(exportable)\n\t\tTRACE(\"sBlk->lookup_table_start 0x%llx\\n\",\n\t\t\tsBlk.lookup_table_start);\n\n\tsBlk.bytes_used = bytes;\n\n\tsBlk.compression = comp->id;\n\n\tSQUASHFS_INSWAP_SUPER_BLOCK(&sBlk); \n\twrite_destination(fd, SQUASHFS_START, sizeof(sBlk), &sBlk);\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_destination(fd, bytes, 4096 - i, temp);\n\t}\n\n\tclose(fd);\n\n\tdelete_pseudo_files();\n\n\tif(recovery_file[0] != '\\0')\n\t\tunlink(recovery_file);\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes +\n\t\tsizeof(struct squashfs_super_block) + total_xattr_bytes;\n\n\tprintf(\"\\n%sSquashfs %d.%d filesystem, %s compressed, data block size\"\n\t\t\" %d\\n\", exportable ? \"Exportable \" : \"\", SQUASHFS_MAJOR,\n\t\tSQUASHFS_MINOR, comp->name, block_size);\n\tprintf(\"\\t%s data, %s metadata, %s fragments, %s xattrs\\n\",\n\t\tnoD ? \"uncompressed\" : \"compressed\", noI ?  \"uncompressed\" :\n\t\t\"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" :\n\t\t\"compressed\", no_xattrs ? \"no\" : noX ? \"uncompressed\" :\n\t\t\"compressed\");\n\tprintf(\"\\tduplicates are %sremoved\\n\", duplicate_checking ? \"\" :\n\t\t\"not \");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0,\n\t\tbytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0,\n\t\ttotal_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0,\n\t\ttotal_directory_bytes);\n\tif(total_xattr_bytes) {\n\t\tprintf(\"Xattr table size %d bytes (%.2f Kbytes)\\n\",\n\t\t\txattr_bytes, xattr_bytes / 1024.0);\n\t\tprintf(\"\\t%.2f%% of uncompressed xattr table size (%d bytes)\\n\",\n\t\t\t((float) xattr_bytes / total_xattr_bytes) * 100.0,\n\t\t\ttotal_xattr_bytes);\n\t}\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count -\n\t\t\tdup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of ids (unique uids + gids) %d\\n\", id_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_UID) {\n\t\t\tstruct passwd *user = getpwuid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" :\n\t\t\t\tuser->pw_name, id_table[i]->id);\n\t\t}\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < id_count; i++) {\n\t\tif(id_table[i]->flags & ISA_GID) {\n\t\t\tstruct group *group = getgrgid(id_table[i]->id);\n\t\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" :\n\t\t\t\tgroup->gr_name, id_table[i]->id);\n\t\t}\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/mksquashfs.h",
    "content": "#ifndef MKSQUASHFS_H\n#define MKSQUASHFS_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define SQUASHFS_SWAP_SHORTS(s, d, n) swap_le16_num(s, d, n)\n#define SQUASHFS_SWAP_INTS(s, d, n) swap_le32_num(s, d, n)\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) swap_le64_num(s, d, n)\n\n#define SWAP_LE16(s, d)\t\tswap_le16(s, d)\n#define SWAP_LE32(s, d)\t\tswap_le32(s, d)\n#define SWAP_LE64(s, d)\t\tswap_le64(s, d)\n#else\n#define SQUASHFS_MEMCPY(s, d, n)\tmemcpy(d, s, n)\n#define SQUASHFS_SWAP_SHORTS(s, d, n)\tmemcpy(d, s, n * sizeof(short))\n#define SQUASHFS_SWAP_INTS(s, d, n)\tmemcpy(d, s, n * sizeof(int))\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) \\\n\t\t\t\t\tmemcpy(d, s, n * sizeof(long long))\n#endif\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n};\n\nstruct inode_info {\n\tstruct stat\t\tbuf;\n\tstruct inode_info\t*next;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\tnlink;\n\tint\t\t\tpseudo_id;\n\tchar\t\t\ttype;\n\tchar\t\t\tread;\n\tchar\t\t\troot_entry;\n\tchar\t\t\tpseudo_file;\n};\n#endif\n\n#define PSEUDO_FILE_OTHER\t1\n#define PSEUDO_FILE_PROCESS\t2\n\n#define IS_PSEUDO(a)\t\t((a)->pseudo_file)\n#define IS_PSEUDO_PROCESS(a)\t((a)->pseudo_file & PSEUDO_FILE_PROCESS)\n#define IS_PSEUDO_OTHER(a)\t((a)->pseudo_file & PSEUDO_FILE_OTHER)\n\n/* offset of data in compressed metadata blocks (allowing room for\n * compressed size */\n#define BLOCK_OFFSET 2\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/pseudo.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * pseudo.c\n */\n\n#include <pwd.h>\n#include <grp.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <stdlib.h>\n#include <sys/types.h>\n#include <sys/wait.h>\n\n#include \"pseudo.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\n#define EXIT_MKSQUASHFS() \\\n\t\tdo { \\\n\t\t\texit(1); \\\n\t\t} while(0)\n\n#define BAD_ERROR(s, args...) \\\n\t\tdo {\\\n\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\tEXIT_MKSQUASHFS();\\\n\t\t} while(0);\n\n#define TRUE 1\n#define FALSE 0\n\nstruct pseudo_dev **pseudo_file = NULL;\nint pseudo_count = 0;\n\nstatic void dump_pseudo(struct pseudo *pseudo, char *string)\n{\n\tint i;\n\tchar path[1024];\n\n\tfor(i = 0; i < pseudo->names; i++) {\n\t\tstruct pseudo_entry *entry = &pseudo->name[i];\n\t\tif(string)\n\t\t\tstrcat(strcat(strcpy(path, string), \"/\"), entry->name);\n\t\telse\n\t\t\tstrcpy(path, entry->name);\n\t\tif(entry->pseudo == NULL)\n\t\t\tERROR(\"%s %c %o %d %d %d %d\\n\", path, entry->dev->type,\n\t\t\t\tentry->dev->mode, entry->dev->uid,\n\t\t\t\tentry->dev->gid, entry->dev->major,\n\t\t\t\tentry->dev->minor);\n\t\telse\n\t\t\tdump_pseudo(entry->pseudo, path);\n\t}\n}\n\n\nstatic char *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\n/*\n * Add pseudo device target to the set of pseudo devices.  Pseudo_dev\n * describes the pseudo device attributes.\n */\nstruct pseudo *add_pseudo(struct pseudo *pseudo, struct pseudo_dev *pseudo_dev,\n\tchar *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i;\n\n\ttarget = get_component(target, targname);\n\n\tif(pseudo == NULL) {\n\t\tif((pseudo = malloc(sizeof(struct pseudo))) == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate pseudo file\\n\");\n\n\t\tpseudo->names = 0;\n\t\tpseudo->count = 0;\n\t\tpseudo->name = NULL;\n\t}\n\n\tfor(i = 0; i < pseudo->names; i++)\n\t\tif(strcmp(pseudo->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == pseudo->names) {\n\t\t/* allocate new name entry */\n\t\tpseudo->names ++;\n\t\tpseudo->name = realloc(pseudo->name, (i + 1) *\n\t\t\tsizeof(struct pseudo_entry));\n\t\tif(pseudo->name == NULL)\n\t\t\tBAD_ERROR(\"failed to allocate pseudo file\\n\");\n\t\tpseudo->name[i].name = strdup(targname);\n\n\t\tif(target[0] == '\\0') {\n\t\t\t/* at leaf pathname component */\n\t\t\tpseudo->name[i].pseudo = NULL;\n\t\t\tpseudo->name[i].pathname = strdup(alltarget);\n\t\t\tpseudo->name[i].dev = pseudo_dev;\n\t\t} else {\n\t\t\t/* recurse adding child components */\n\t\t\tpseudo->name[i].dev = NULL;\n\t\t\tpseudo->name[i].pseudo = add_pseudo(NULL, pseudo_dev,\n\t\t\t\ttarget, alltarget);\n\t\t}\n\t} else {\n\t\t/* existing matching entry */\n\t\tif(pseudo->name[i].pseudo == NULL) {\n\t\t\t/* No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing pseudo file.\n\t\t\t */\n\t\t\tif(target[0] != '\\0') {\n\t\t\t\t/* entry must exist as a 'd' type pseudo file */\n\t\t\t\tif(pseudo->name[i].dev->type == 'd')\n\t\t\t\t\t/* recurse adding child components */\n\t\t\t\t\tpseudo->name[i].pseudo =\n\t\t\t\t\t\tadd_pseudo(NULL, pseudo_dev,\n\t\t\t\t\t\ttarget, alltarget);\n\t\t\t\telse\n\t\t\t\t\tERROR(\"%s already exists as a non \"\n\t\t\t\t\t\t\"directory.  Ignoring %s!\\n\",\n\t\t\t\t\t\t targname, alltarget);\n\t\t\t} else if(memcmp(pseudo_dev, pseudo->name[i].dev,\n\t\t\t\t\tsizeof(struct pseudo_dev)) != 0)\n\t\t\t\tERROR(\"%s already exists as a different pseudo \"\n\t\t\t\t\t\"definition.  Ignoring!\\n\", alltarget);\n\t\t\telse ERROR(\"%s already exists as an identical \"\n\t\t\t\t\t\"pseudo definition!\\n\", alltarget);\n\t\t} else {\n\t\t\t/* sub-directory exists which means this can only be a\n\t\t\t * 'd' type pseudo file */\n\t\t\tif(target[0] == '\\0') {\n\t\t\t\tif(pseudo->name[i].dev == NULL &&\n\t\t\t\t\t\tpseudo_dev->type == 'd') {\n\t\t\t\t\tpseudo->name[i].pathname =\n\t\t\t\t\t\tstrdup(alltarget);\n\t\t\t\t\tpseudo->name[i].dev = pseudo_dev;\n\t\t\t\t} else\n\t\t\t\t\tERROR(\"%s already exists as a \"\n\t\t\t\t\t\t\"directory.  Ignoring %s!\\n\",\n\t\t\t\t\t\ttargname, alltarget);\n\t\t\t} else\n\t\t\t\t/* recurse adding child components */\n\t\t\t\tadd_pseudo(pseudo->name[i].pseudo, pseudo_dev,\n\t\t\t\t\ttarget, alltarget);\n\t\t}\n\t}\n\n\treturn pseudo;\n}\n\n\n/*\n * Find subdirectory in pseudo directory referenced by pseudo, matching\n * filename.  If filename doesn't exist or if filename is a leaf file\n * return NULL\n */\nstruct pseudo *pseudo_subdir(char *filename, struct pseudo *pseudo)\n{\n\tint i;\n\n\tif(pseudo == NULL)\n\t\treturn NULL;\n\n\tfor(i = 0; i < pseudo->names; i++)\n\t\tif(strcmp(filename, pseudo->name[i].name) == 0)\n\t\t\treturn pseudo->name[i].pseudo;\n\n\treturn NULL;\n}\n\n\nstruct pseudo_entry *pseudo_readdir(struct pseudo *pseudo)\n{\n\tif(pseudo == NULL)\n\t\treturn NULL;\n\n\twhile(pseudo->count < pseudo->names) {\n\t\tif(pseudo->name[pseudo->count].dev != NULL)\n\t\t\treturn &pseudo->name[pseudo->count++];\n\t\telse\n\t\t\tpseudo->count++;\n\t}\n\n\treturn NULL;\n}\n\n\nint exec_file(char *command, struct pseudo_dev *dev)\n{\n\tint child, res;\n\tstatic pid_t pid = -1;\n\tint pipefd[2];\n#ifdef USE_TMP_FILE\n\tchar filename[1024];\n\tint status;\n\tstatic int number = 0;\n#endif\n\n\tif(pid == -1)\n\t\tpid = getpid();\n\n#ifdef USE_TMP_FILE\n\tsprintf(filename, \"/tmp/squashfs_pseudo_%d_%d\", pid, number ++);\n\tpipefd[1] = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);\n\tif(pipefd[1] == -1) {\n\t\tprintf(\"open failed\\n\");\n\t\treturn -1;\n\t}\n#else\n\tres = pipe(pipefd);\n\tif(res == -1) {\n\t\tprintf(\"pipe failed\\n\");\n\t\treturn -1;\n\t}\n#endif\n\n\tchild = fork();\n\tif(child == -1) {\n\t\tprintf(\"fork failed\\n\");\n\t\tgoto failed;\n\t}\n\n\tif(child == 0) {\n\t\tclose(STDOUT_FILENO);\n\t\tres = dup(pipefd[1]);\n\t\tif(res == -1) {\n\t\t\tprintf(\"dup failed\\n\");\n\t\t\texit(EXIT_FAILURE);\n\t\t}\n\t\texecl(\"/bin/sh\", \"sh\", \"-c\", command, (char *) NULL);\n\t\tprintf(\"execl failed\\n\");\n\t\texit(EXIT_FAILURE);\n\t}\n\n#ifdef USE_TMP_FILE\n\tres = waitpid(child, &status, 0);\n\tclose(pipefd[1]);\n\tif(res != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0) {\n\t\tdev->filename = strdup(filename);\n\t\treturn 0;\n\t}\nfailed:\n\tunlink(filename);\n\treturn -1;\n#else\n\tclose(pipefd[1]);\n\tdev->fd = pipefd[0];\n\tdev->child = child;\n\treturn 0;\nfailed:\n\treturn -1;\n#endif\n}\n\n\nvoid add_pseudo_file(struct pseudo_dev *dev)\n{\n\tpseudo_file = realloc(pseudo_file, (pseudo_count + 1) *\n\t\tsizeof(struct pseudo_dev *));\n\tif(pseudo_file == NULL)\n\t\tBAD_ERROR(\"Failed to realloc pseudo_file\\n\");\n\n\tdev->pseudo_id = pseudo_count;\n\tpseudo_file[pseudo_count ++] = dev;\n}\n\n\nvoid delete_pseudo_files()\n{\n#ifdef USE_TMP_FILE\n\tint i;\n\n\tfor(i = 0; i < pseudo_count; i++)\n\t\tunlink(pseudo_file[i]->filename);\n#endif\n}\n\n\nstruct pseudo_dev *get_pseudo_file(int pseudo_id)\n{\n\treturn pseudo_file[pseudo_id];\n}\n\n\nint read_pseudo_def(struct pseudo **pseudo, char *def)\n{\n\tint n, bytes;\n\tunsigned int major = 0, minor = 0, mode;\n\tchar filename[2048], type, suid[100], sgid[100], *ptr;\n\tlong long uid, gid;\n\tstruct pseudo_dev *dev;\n\n\tn = sscanf(def, \"%s %c %o %s %s %n\", filename, &type, &mode, suid,\n\t\t\tsgid, &bytes);\n\n\tif(n < 5) {\n\t\tERROR(\"Not enough or invalid arguments in pseudo file \"\n\t\t\t\"definition\\n\");\n\t\tgoto error;\n\t}\n\n\tswitch(type) {\n\tcase 'b':\n\tcase 'c':\n\t\tn = sscanf(def + bytes,  \"%u %u\", &major, &minor);\n\n\t\tif(n < 2) {\n\t\t\tERROR(\"Not enough or invalid arguments in pseudo file \"\n\t\t\t\t\"definition\\n\");\n\t\t\tgoto error;\n\t\t}\t\n\t\t\n\t\tif(major > 0xfff) {\n\t\t\tERROR(\"Major %d out of range\\n\", major);\n\t\t\tgoto error;\n\t\t}\n\n\t\tif(minor > 0xfffff) {\n\t\t\tERROR(\"Minor %d out of range\\n\", minor);\n\t\t\tgoto error;\n\t\t}\n\n\tcase 'f':\n\t\tif(def[bytes] == '\\0') {\n\t\t\tERROR(\"Not enough arguments in pseudo file \"\n\t\t\t\t\"definition\\n\");\n\t\t\tgoto error;\n\t\t}\t\n\t\tbreak;\n\tcase 'd':\n\tcase 'm':\n\t\tbreak;\n\tdefault:\n\t\tERROR(\"Unsupported type %c\\n\", type);\n\t\tgoto error;\n\t}\n\n\n\tif(mode > 07777) {\n\t\tERROR(\"Mode %o out of range\\n\", mode);\n\t\tgoto error;\n\t}\n\n\tuid = strtoll(suid, &ptr, 10);\n\tif(*ptr == '\\0') {\n\t\tif(uid < 0 || uid > ((1LL << 32) - 1)) {\n\t\t\tERROR(\"Uid %s out of range\\n\", suid);\n\t\t\tgoto error;\n\t\t}\n\t} else {\n\t\tstruct passwd *pwuid = getpwnam(suid);\n\t\tif(pwuid)\n\t\t\tuid = pwuid->pw_uid;\n\t\telse {\n\t\t\tERROR(\"Uid %s invalid uid or unknown user\\n\", suid);\n\t\t\tgoto error;\n\t\t}\n\t}\n\t\t\n\tgid = strtoll(sgid, &ptr, 10);\n\tif(*ptr == '\\0') {\n\t\tif(gid < 0 || gid > ((1LL << 32) - 1)) {\n\t\t\tERROR(\"Gid %s out of range\\n\", sgid);\n\t\t\tgoto error;\n\t\t}\n\t} else {\n\t\tstruct group *grgid = getgrnam(sgid);\n\t\tif(grgid)\n\t\t\tgid = grgid->gr_gid;\n\t\telse {\n\t\t\tERROR(\"Gid %s invalid uid or unknown user\\n\", sgid);\n\t\t\tgoto error;\n\t\t}\n\t}\n\n\tswitch(type) {\n\tcase 'b':\n\t\tmode |= S_IFBLK;\n\t\tbreak;\n\tcase 'c':\n\t\tmode |= S_IFCHR;\n\t\tbreak;\n\tcase 'd':\n\t\tmode |= S_IFDIR;\n\t\tbreak;\n\tcase 'f':\n\t\tmode |= S_IFREG;\n\t\tbreak;\n\t}\n\n\tdev = malloc(sizeof(struct pseudo_dev));\n\tif(dev == NULL)\n\t\tBAD_ERROR(\"Failed to create pseudo_dev\\n\");\n\n\tdev->type = type;\n\tdev->mode = mode;\n\tdev->uid = uid;\n\tdev->gid = gid;\n\tdev->major = major;\n\tdev->minor = minor;\n\n\tif(type == 'f') {\n\t\tint res;\n\n\t\tprintf(\"Executing dynamic pseudo file\\n\");\n\t\tprintf(\"\\t\\\"%s\\\"\\n\", def);\n\t\tres = exec_file(def + bytes, dev);\n\t\tif(res == -1) {\n\t\t\tERROR(\"Failed to execute dynamic pseudo file definition\"\n\t\t\t\t\" \\\"%s\\\"\\n\", def);\n\t\t\treturn FALSE;\n\t\t}\n\t\tadd_pseudo_file(dev);\n\t}\n\n\t*pseudo = add_pseudo(*pseudo, dev, filename, filename);\n\n\treturn TRUE;\n\nerror:\n\tERROR(\"Bad pseudo file definition \\\"%s\\\"\\n\", def);\n\treturn FALSE;\n}\n\t\t\n\n\n#define MAX_LINE 2048\n\nint read_pseudo_file(struct pseudo **pseudo, char *filename)\n{\n\tFILE *fd;\n\tchar *line = NULL;\n\tint size = 0;\n\tint res = TRUE;\n\n\tfd = fopen(filename, \"r\");\n\tif(fd == NULL) {\n\t\tERROR(\"Could not open pseudo device file \\\"%s\\\" because %s\\n\",\n\t\t\t\tfilename, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(1) {\n\t\tint total = 0;\n\n\t\twhile(1) {\n\t\t\tint n, err;\n\n\t\t\tif(total + MAX_LINE > size) {\n\t\t\t\tline = realloc(line, size += MAX_LINE);\n\t\t\t\tif(line == NULL) {\n\t\t\t\t\tERROR(\"No space in read_pseudo_file\\n\");\n\t\t\t\t\treturn FALSE;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\terr = fscanf(fd, \"%2047[^\\n]%n\\n\", line + total, &n);\n\t\t\tif(err <= 0)\n\t\t\t\tgoto done;\n\n\t\t\tif(line[total] == '#')\n\t\t\t\tcontinue;\n\n\t\t\tif(line[total + n - 1] != '\\\\')\n\t\t\t\tbreak;\n\n\t\t\ttotal += n - 1;\n\t\t}\t\n\n\t\tres = read_pseudo_def(pseudo, line);\n\t\tif(res == FALSE)\n\t\t\tbreak;\n\t}\n\ndone:\n\tfclose(fd);\n\tfree(line);\n\treturn res;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/pseudo.h",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * pseudo.h\n */\nstruct pseudo_dev {\n\tchar\t\ttype;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tgid;\n\tunsigned int\tmajor;\n\tunsigned int\tminor;\n\tint\t\tpseudo_id;\n\tint\t\tfd;\n\tint\t\tchild;\n#ifdef USE_TMP_FILE\n\tchar\t\t*filename;\n#endif\n};\n\nstruct pseudo_entry {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct pseudo\t\t*pseudo;\n\tstruct pseudo_dev\t*dev;\n};\n\t\nstruct pseudo {\n\tint\t\t\tnames;\n\tint\t\t\tcount;\n\tstruct pseudo_entry\t*name;\n};\n\nextern int read_pseudo_def(struct pseudo **, char *);\nextern int read_pseudo_file(struct pseudo **, char *);\nextern struct pseudo *pseudo_subdir(char *, struct pseudo *);\nextern struct pseudo_entry *pseudo_readdir(struct pseudo *);\nextern struct pseudo_dev *get_pseudo_file(int);\nextern void delete_pseudo_files();\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n#include \"compressor.h\"\n#include \"xattr.h\"\n\nextern int read_fs_bytes(int, long long, int, void *);\nextern int add_file(long long, long long, long long, unsigned int *, int,\n\tunsigned int, int, int);\nextern void *create_id(unsigned int);\nextern unsigned int get_uid(unsigned int);\nextern unsigned int get_guid(unsigned int);\n\nstatic struct compressor *comp;\n\nint read_block(int fd, long long start, long long *next, void *block)\n{\n\tunsigned short c_byte;\n\tint res;\n\t\n\tres = read_fs_bytes(fd, start, 2, &c_byte);\n\tif(res == 0)\n\t\treturn 0;\n\n\tSQUASHFS_INSWAP_SHORTS(&c_byte, 1);\n\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint error, res;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tres = read_fs_bytes(fd, start + 2, c_byte, buffer);\n\t\tif(res == 0)\n\t\t\treturn 0;\n\n\t\tres = compressor_uncompress(comp, block, buffer, c_byte,\n\t\t\tSQUASHFS_METADATA_SIZE, &error);\n\t\tif(res == -1) {\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + 2 + c_byte;\n\t\treturn res;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tres = read_fs_bytes(fd, start + 2, c_byte, block);\n\t\tif(res == 0)\n\t\t\treturn 0;\n\n\t\tif(next)\n\t\t\t*next = start + 2 + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end,\n\tlong long root_inode_start, int root_inode_offset,\n\tstruct squashfs_super_block *sBlk, union squashfs_inode_header *dir_inode,\n\tunsigned char **inode_table, unsigned int *root_inode_block,\n\tunsigned int *root_inode_size, long long *uncompressed_file,\n\tunsigned int *uncompressed_directory, int *file_count, int *sym_count,\n\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count,\n\tunsigned int *id_table)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tstruct squashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start \"\n\t\t\"0x%llx\\n\", start, end, root_inode_start);\n\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx \"\n\t\t\t\t\"containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE) {\n\t\t\t*inode_table = realloc(*inode_table, size\n\t\t\t\t+= SQUASHFS_METADATA_SIZE);\n\t\t\tif(*inode_table == NULL)\n\t\t\t\treturn FALSE;\n\t\t}\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tbyte = read_block(fd, start, &start, *inode_table + bytes);\n\t\tif(byte == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain\n\t * the last directory start block index.  This is used when calculating\n\t * the total uncompressed directory size.  The directory bytes in the\n\t * last * block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, *inode_table + bytes);\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir,\n\t\t\t*inode_table + bytes);\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir,\n\t\t\t*inode_table + bytes);\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\tget_uid(id_table[dir_inode->base.uid]);\n\tget_guid(id_table[dir_inode->base.guid]);\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, cur_ptr);\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position \"\n\t\t\t\"0x%x, type 0x%x\\n\",\n\t\t\t(unsigned int) (cur_ptr - *inode_table),\n\t\t\tinode.inode_type);\n\n\t\tget_uid(id_table[inode.uid]);\n\t\tget_guid(id_table[inode.guid]);\n\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? 0 :\n\t\t\t\t\tinode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >>\n\t\t\t\t\tsBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, \"\n\t\t\t\t\t\"file_size %d, blocks %d\\n\",\n\t\t\t\t\tinode.file_size, blocks);\n\n\t\t\t\tblock_list = malloc(blocks *\n\t\t\t\t\tsizeof(unsigned int));\n\t\t\t\tif(block_list == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list \"\n\t\t\t\t\t\t\"malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tSQUASHFS_SWAP_INTS(block_list, cur_ptr, blocks);\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes +=\n\t\t\t\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t\t(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes,\n\t\t\t\t\tblock_list, blocks, inode.fragment,\n\t\t\t\t\tinode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tstruct squashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i;\n\t\t\t\tlong long start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, cur_ptr);\n\n\t\t\t\tfrag_bytes = inode.fragment ==\n\t\t\t\t\tSQUASHFS_INVALID_FRAG ? 0 :\n\t\t\t\t\tinode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t\t?  (inode.file_size +\n\t\t\t\t\tsBlk->block_size - 1) >>\n\t\t\t\t\tsBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular \"\n\t\t\t\t\t\"file, file_size %lld, blocks %d\\n\",\n\t\t\t\t\tinode.file_size, blocks);\n\n\t\t\t\tblock_list = malloc(blocks *\n\t\t\t\t\tsizeof(unsigned int));\n\t\t\t\tif(block_list == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list \"\n\t\t\t\t\t\t\"malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tSQUASHFS_SWAP_INTS(block_list, cur_ptr, blocks);\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes +=\n\t\t\t\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK\n\t\t\t\t\t\t(block_list[i]);\n\n\t                        add_file(start, inode.file_size, file_bytes,\n\t\t\t\t\tblock_list, blocks, inode.fragment,\n\t\t\t\t\tinode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\tcase SQUASHFS_LSYMLINK_TYPE: {\n\t\t\t\tstruct squashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep,\n\t\t\t\t\tcur_ptr);\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\n\t\t\t\tif (inode.inode_type == SQUASHFS_LSYMLINK_TYPE)\n\t\t\t\t\tcur_ptr += sizeof(unsigned int);\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tstruct squashfs_dir_inode_header dir_inode;\n\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode,\n\t\t\t\t\tcur_ptr);\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory +=\n\t\t\t\t\tdir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tstruct squashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode,\n\t\t\t\t\tcur_ptr);\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory +=\n\t\t\t\t\tdir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tstruct squashfs_dir_index index;\n\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index,\n\t\t\t\t\t\tcur_ptr);\n\t\t\t\t\tcur_ptr += sizeof(struct squashfs_dir_index) +\n\t\t\t\t\t\tindex.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\t\t \tcase SQUASHFS_LBLKDEV_TYPE:\n\t\t \tcase SQUASHFS_LCHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_ldev_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_LFIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_lipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_LSOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(struct squashfs_lipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in \"\n\t\t\t\t\t\"scan_inode_table!\\n\",\n\t\t\t\t\tinode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\treturn TRUE;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nstruct compressor *read_super(int fd, struct squashfs_super_block *sBlk, char *source)\n{\n\tint res, bytes = 0;\n\tchar buffer[SQUASHFS_METADATA_SIZE] __attribute__ ((aligned));\n\n\tres = read_fs_bytes(fd, SQUASHFS_START, sizeof(struct squashfs_super_block),\n\t\tsBlk);\n\tif(res == 0)\n\t\tgoto failed_mount;\n\n\tSQUASHFS_INSWAP_SUPER_BLOCK(sBlk);\n\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP)\n\t\t\tERROR(\"Pre 4.0 big-endian filesystem on %s, appending\"\n\t\t\t\t\" to this is unsupported\\n\", source);\n\t\telse\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n\t\t\t\tsource);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 4)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.\"\n\t\t\t\t\"  Appending\\nto SQUASHFS %d.%d filesystems is \"\n\t\t\t\t\"not supported.  Please convert it to a \"\n\t\t\t\t\"SQUASHFS 4 filesystem\\n\", source,\n\t\t\t\tsBlk->s_major,\n\t\t\t\tsBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Filesystem on %s is %d.%d, which is a later \"\n\t\t\t\t\"filesystem version than I support\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n\t/* Check the compression type */\n\tcomp = lookup_compressor_id(sBlk->compression);\n\tif(!comp->supported) {\n\t\tERROR(\"Filesystem on %s uses %s compression, this is\"\n\t\t\t\"unsupported by this version\\n\", source, comp->name);\n\t\tERROR(\"Compressors available:\\n\");\n\t\tdisplay_compressors(\"\", \"\");\n\t\tgoto failed_mount;\n\t}\n\n\t/*\n\t * Read extended superblock information from disk.\n\t *\n\t * Read compressor specific options from disk if present, and pass\n\t * to compressor to set compressor options.\n\t *\n\t * Note, if there's no compressor options present, the compressor\n\t * is still called to set the default options (the defaults may have\n\t * been changed by the user specifying options on the command\n\t * line which need to be over-ridden).\n\t */\n\tif(SQUASHFS_COMP_OPTS(sBlk->flags)) {\n\t\tbytes = read_block(fd, sizeof(*sBlk), NULL, buffer);\n\n\t\tif(bytes == 0)\n\t\t\tgoto failed_mount;\n\t}\n\n\tres = compressor_extract_options(comp, sBlk->block_size, buffer, bytes);\n\tif(res == -1) {\n\t\tERROR(\"Compressor failed to set compressor options\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\tprintf(\"Found a valid %sSQUASHFS superblock on %s.\\n\",\n\t\tSQUASHFS_EXPORTABLE(sBlk->flags) ? \"exportable \" : \"\", source);\n\tprintf(\"\\tCompression used %s\\n\", comp->name);\n\tprintf(\"\\tInodes are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tXattrs are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_XATTRS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %spresent in the filesystem\\n\",\n\t\tSQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %sspecified\\n\",\n\t\tSQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tDuplicates are %sremoved\\n\",\n\t\tSQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not \");\n\tprintf(\"\\tXattrs are %sstored\\n\",\n\t\tSQUASHFS_NO_XATTRS(sBlk->flags) ? \"not \" : \"\");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\",\n\t\tsBlk->bytes_used / 1024.0, sBlk->bytes_used\n\t\t/ (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of ids %d\\n\", sBlk->no_ids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\",\n\t\tsBlk->directory_table_start);\n\tTRACE(\"sBlk->id_table_start %llx\\n\", sBlk->id_table_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"sBlk->lookup_table_start %llx\\n\", sBlk->lookup_table_start);\n\tTRACE(\"sBlk->xattr_id_table_start %llx\\n\", sBlk->xattr_id_table_start);\n\tprintf(\"\\n\");\n\n\treturn comp;\n\nfailed_mount:\n\treturn NULL;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries,\n\tunsigned int directory_start_block, int offset, int size,\n\tunsigned int *last_directory_block, struct squashfs_super_block *sBlk,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tstruct squashfs_dir_header dirh;\n\tchar buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1]\n\t\t__attribute__ ((aligned));\n\tstruct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block,\n\t\tlast_start_block = start; \n\n\tsize += offset;\n\tdirectory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) &\n\t\t~(SQUASHFS_METADATA_SIZE - 1));\n\tif(directory_table == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so \"\n\t\t\t\"far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tbyte = read_block(fd, start, &start, directory_table + bytes);\n\t\tif(byte == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, directory_table + bytes);\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position \"\n\t\t\t\"0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, directory_table + bytes);\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, \"\n\t\t\t\t\"inode %x:%x, type 0x%x\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name,\n\t\t\t\tSQUASHFS_MKINODE(dirh.start_block,\n\t\t\t\tdire->offset), dirh.inode_number +\n\t\t\t\tdire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block -\n\t\tsBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nunsigned int *read_id_table(int fd, struct squashfs_super_block *sBlk)\n{\n\tint indexes = SQUASHFS_ID_BLOCKS(sBlk->no_ids);\n\tlong long index[indexes];\n\tint bytes = SQUASHFS_ID_BYTES(sBlk->no_ids);\n\tunsigned int *id_table;\n\tint res, i;\n\n\tid_table = malloc(bytes);\n\tif(id_table == NULL) {\n\t\tERROR(\"Failed to allocate id table\\n\");\n\t\treturn NULL;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk->id_table_start,\n\t\tSQUASHFS_ID_BLOCK_BYTES(sBlk->no_ids), index);\n\tif(res == 0) {\n\t\tfree(id_table);\n\t\treturn NULL;\n\t}\n\n\tSQUASHFS_INSWAP_ID_BLOCKS(index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) id_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read id table block %d, from 0x%llx, length %d\\n\", i,\n\t\t\tindex[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read id table block %d, from 0x%llx, \"\n\t\t\t\t\"length %d\\n\", i, index[i], length);\n\t\t\tfree(id_table);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_INTS(id_table, sBlk->no_ids);\n\n\tfor(i = 0; i < sBlk->no_ids; i++) {\n\t\tTRACE(\"Adding id %d to id tables\\n\", id_table[i]);\n\t\tcreate_id(id_table[i]);\n\t}\n\n\treturn id_table;\n}\n\n\nint read_fragment_table(int fd, struct squashfs_super_block *sBlk,\n\tstruct squashfs_fragment_entry **fragment_table)\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tlong long fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk->fragments, indexes,\n\t\tsBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\t*fragment_table = malloc(sBlk->fragments *\n\t\tsizeof(struct squashfs_fragment_entry));\n\tif(*fragment_table == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk->fragment_table_start,\n\t\tSQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments),\n\t\tfragment_table_index);\n\tif(res == 0) {\n\t\tfree(*fragment_table);\n\t\treturn 0;\n\t}\n\n\tSQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((unsigned char *) *fragment_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read fragment table block %d, from \"\n\t\t\t\t\"0x%llx, length %d\\n\", i,\n\t\t\t\tfragment_table_index[i], length);\n\t\t\tfree(*fragment_table);\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tfor(i = 0; i < sBlk->fragments; i++)\n\t\tSQUASHFS_INSWAP_FRAGMENT_ENTRY(&(*fragment_table)[i]);\n\n\treturn 1;\n}\n\n\nint read_inode_lookup_table(int fd, struct squashfs_super_block *sBlk,\n\tsquashfs_inode **inode_lookup_table)\n{\n\tint lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);\n\tint indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);\n\tlong long index[indexes];\n\tint res, i;\n\n\tif(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn 1;\n\n\t*inode_lookup_table = malloc(lookup_bytes);\n\tif(*inode_lookup_table == NULL) {\n\t\tERROR(\"Failed to allocate inode lookup table\\n\");\n\t\treturn 0;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk->lookup_table_start,\n\t\tSQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), index);\n\tif(res == 0) {\n\t\tfree(*inode_lookup_table);\n\t\treturn 0;\n\t}\n\n\tSQUASHFS_INSWAP_LONG_LONGS(index, indexes);\n\n\tfor(i = 0; i <  indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) *inode_lookup_table) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read inode lookup table block %d, from 0x%llx, length \"\n\t\t\t\"%d\\n\", i, index[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read inode lookup table block %d, \"\n\t\t\t\t\"from 0x%llx, length %d\\n\", i, index[i],\n\t\t\t\tlength);\n\t\t\tfree(*inode_lookup_table);\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_LONG_LONGS(*inode_lookup_table, sBlk->inodes);\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, struct squashfs_super_block *sBlk,\n\tchar **cinode_table, char **data_cache, char **cdirectory_table,\n\tchar **directory_data_cache, unsigned int *last_directory_block,\n\tunsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block,\n\tint *file_count, int *sym_count, int *dev_count, int *dir_count,\n\tint *fifo_count, int *sock_count, long long *uncompressed_file,\n\tunsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\tunsigned int *inode_dir_inode_number,\n\tunsigned int *inode_dir_parent_inode,\n\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\tstruct squashfs_fragment_entry **fragment_table,\n\tsquashfs_inode **inode_lookup_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start;\n\tlong long end = sBlk->directory_table_start;\n\tlong long root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk->root_inode);\n\tunsigned int root_inode_block;\n\tunion squashfs_inode_header inode;\n\tunsigned int *id_table;\n\tint res;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(get_xattrs(fd, sBlk) == 0)\n\t\tgoto error;\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif(read_inode_lookup_table(fd, sBlk, inode_lookup_table) == 0)\n\t\tgoto error;\n\n\tid_table = read_id_table(fd, sBlk);\n\tif(id_table == NULL)\n\t\tgoto error;\n\n\tres = scan_inode_table(fd, start, end, root_inode_start,\n\t\troot_inode_offset, sBlk, &inode, &inode_table,\n\t\t&root_inode_block, root_inode_size, uncompressed_file,\n\t\tuncompressed_directory, file_count, sym_count, dev_count,\n\t\tdir_count, fifo_count, sock_count, id_table);\n\tif(res == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE ||\n\t\t\tinode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tdirectory_table = squashfs_readdir(fd, !root_name,\n\t\t\t*inode_dir_start_block, *inode_dir_offset,\n\t\t\t*inode_dir_file_size, last_directory_block, sBlk,\n\t\t\tpush_directory_entry);\n\t\tif(directory_table == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\"\n\t\t\t\t\"\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\t*cinode_table = malloc(root_inode_start);\n\t\tif(*cinode_table == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for \"\n\t\t\t\t\"existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tres = read_fs_bytes(fd, start, root_inode_start, *cinode_table);\n\t\tif(res == 0)\n\t\t\tgoto error;\n\n\t\t*cdirectory_table = malloc(*last_directory_block);\n\t\tif(*cdirectory_table == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for \"\n\t\t\t\t\"existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tres = read_fs_bytes(fd, sBlk->directory_table_start,\n\t\t\t*last_directory_block, *cdirectory_table);\n\t\tif(res == 0)\n\t\t\tgoto error;\n\n\t\t*data_cache = malloc(root_inode_offset + *root_inode_size);\n\t\tif(*data_cache == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block,\n\t\t\troot_inode_offset + *root_inode_size);\n\n\t\t*directory_data_cache = malloc(*inode_dir_offset +\n\t\t\t*inode_dir_file_size);\n\t\tif(*directory_data_cache == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory \"\n\t\t\t\t\"cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table,\n\t\t\t*inode_dir_offset + *inode_dir_file_size);\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/read_fs.h",
    "content": "#ifndef READ_FS_H\n#define READ_FS_H\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.h\n *\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define SQUASHFS_SWAP_SHORTS(d, s, n) swap_le16_num(s, d, n)\n#define SQUASHFS_SWAP_INTS(d, s, n) swap_le32_num(s, d, n)\n#define SQUASHFS_SWAP_LONG_LONGS(d, s, n) swap_le64_num(s, d, n)\n\n#define SWAP_LE16(d, s)\t\tswap_le16(s, d)\n#define SWAP_LE32(d, s)\t\tswap_le32(s, d)\n#define SWAP_LE64(d, s)\t\tswap_le64(s, d)\n#else\n#define SQUASHFS_MEMCPY(d, s, n)\tmemcpy(d, s, n)\n#define SQUASHFS_SWAP_SHORTS(d, s, n)\tmemcpy(d, s, n * sizeof(short))\n#define SQUASHFS_SWAP_INTS(d, s, n)\tmemcpy(d, s, n * sizeof(int))\n#define SQUASHFS_SWAP_LONG_LONGS(d, s, n) \\\n\t\t\t\t\tmemcpy(d, s, n * sizeof(long long))\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/read_xattrs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_xattrs.c\n */\n\n/*\n * Common xattr read code shared between mksquashfs and unsquashfs\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <string.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n#include \"xattr.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"read_xattrs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\nextern int read_fs_bytes(int, long long, int, void *);\nextern int read_block(int, long long, long long *, void *);\n\nstatic struct hash_entry {\n\tlong long\t\tstart;\n\tunsigned int\t\toffset;\n\tstruct hash_entry\t*next;\n} *hash_table[65536];\n\nstatic struct squashfs_xattr_id *xattr_ids;\nstatic void *xattrs = NULL;\nstatic long long xattr_table_start;\n\n/*\n * Prefix lookup table, storing mapping to/from prefix string and prefix id\n */\nstruct prefix prefix_table[] = {\n\t{ \"user.\", SQUASHFS_XATTR_USER },\n\t{ \"trusted.\", SQUASHFS_XATTR_TRUSTED },\n\t{ \"security.\", SQUASHFS_XATTR_SECURITY },\n\t{ \"\", -1 }\n};\n\n/*\n * store mapping from location of compressed block in fs ->\n * location of uncompressed block in memory\n */\nstatic int save_xattr_block(long long start, int offset)\n{\n\tstruct hash_entry *hash_entry = malloc(sizeof(*hash_entry));\n\tint hash = start & 0xffff;\n\n\tTRACE(\"save_xattr_block: start %lld, offset %d\\n\", start, offset);\n\n\tif(hash_entry == NULL) {\n\t\tERROR(\"Failed to allocate hash entry\\n\");\n\t\treturn -1;\n\t}\n\n\thash_entry->start = start;\n\thash_entry->offset = offset;\n\thash_entry->next = hash_table[hash];\n\thash_table[hash] = hash_entry;\n\n\treturn 1;\n}\n\n\n/*\n * map from location of compressed block in fs ->\n * location of uncompressed block in memory\n */\nstatic int get_xattr_block(long long start)\n{\n\tint hash = start & 0xffff;\n\tstruct hash_entry *hash_entry = hash_table[hash];\n\n\tfor(; hash_entry; hash_entry = hash_entry->next)\n\t\tif(hash_entry->start == start)\n\t\t\tbreak;\n\n\tTRACE(\"get_xattr_block: start %lld, offset %d\\n\", start,\n\t\thash_entry ? hash_entry->offset : -1);\n\n\treturn hash_entry ? hash_entry->offset : -1;\n}\n\n\n/*\n * construct the xattr_list entry from the fs xattr, including\n * mapping name and prefix into a full name\n */\nstatic int read_xattr_entry(struct xattr_list *xattr,\n\tstruct squashfs_xattr_entry *entry, void *name)\n{\n\tint i, len, type = entry->type & XATTR_PREFIX_MASK;\n\n\tfor(i = 0; prefix_table[i].type != -1; i++)\n\t\tif(prefix_table[i].type == type)\n\t\t\tbreak;\n\n\tif(prefix_table[i].type == -1) {\n\t\tERROR(\"Unrecognised type in read_xattr_entry\\n\");\n\t\treturn 0;\n\t}\n\n\tlen = strlen(prefix_table[i].prefix);\n\txattr->full_name = malloc(len + entry->size + 1);\n\tif(xattr->full_name == NULL) {\n\t\tERROR(\"Out of memory in read_xattr_entry\\n\");\n\t\treturn -1;\n\t}\n\tmemcpy(xattr->full_name, prefix_table[i].prefix, len);\n\tmemcpy(xattr->full_name + len, name, entry->size);\n\txattr->full_name[len + entry->size] = '\\0';\n\txattr->name = xattr->full_name + len;\n\txattr->size = entry->size;\n\txattr->type = type;\n\n\treturn 1;\n}\n\n\n/*\n * Read and decompress the xattr id table and the xattr metadata.\n * This is cached in memory for later use by get_xattr()\n */\nint read_xattrs_from_disk(int fd, struct squashfs_super_block *sBlk)\n{\n\tint res, bytes, i, indexes, index_bytes, ids;\n\tlong long *index, start, end;\n\tstruct squashfs_xattr_table id_table;\n\n\tTRACE(\"read_xattrs_from_disk\\n\");\n\n\tif(sBlk->xattr_id_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn SQUASHFS_INVALID_BLK;\n\n\t/*\n\t * Read xattr id table, containing start of xattr metadata and the\n\t * number of xattrs in the file system\n\t */\n\tres = read_fs_bytes(fd, sBlk->xattr_id_table_start, sizeof(id_table),\n\t\t&id_table);\n\tif(res == 0)\n\t\treturn 0;\n\n\tSQUASHFS_INSWAP_XATTR_TABLE(&id_table);\n\n\t/*\n\t * Allocate and read the index to the xattr id table metadata\n\t * blocks\n\t */\n\tids = id_table.xattr_ids;\n\txattr_table_start = id_table.xattr_table_start;\n\tindex_bytes = SQUASHFS_XATTR_BLOCK_BYTES(ids);\n\tindexes = SQUASHFS_XATTR_BLOCKS(ids);\n\tindex = malloc(index_bytes);\n\tif(index == NULL) {\n\t\tERROR(\"Failed to allocate index array\\n\");\n\t\treturn 0;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk->xattr_id_table_start + sizeof(id_table),\n\t\tindex_bytes, index);\n\tif(res ==0)\n\t\tgoto failed1;\n\n\tSQUASHFS_INSWAP_LONG_LONGS(index, indexes);\n\n\t/*\n\t * Allocate enough space for the uncompressed xattr id table, and\n\t * read and decompress it\n\t */\n\tbytes = SQUASHFS_XATTR_BYTES(ids);\n\txattr_ids = malloc(bytes);\n\tif(xattr_ids == NULL) {\n\t\tERROR(\"Failed to allocate xattr id table\\n\");\n\t\tgoto failed1;\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, index[i], NULL,\n\t\t\t((unsigned char *) xattr_ids) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read xattr id table block %d, from 0x%llx, length \"\n\t\t\t\"%d\\n\", i, index[i], length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read xattr id table block %d, \"\n\t\t\t\t\"from 0x%llx, length %d\\n\", i, index[i],\n\t\t\t\tlength);\n\t\t\tgoto failed2;\n\t\t}\n\t}\n\n\t/*\n\t * Read and decompress the xattr metadata\n\t *\n\t * Note the first xattr id table metadata block is immediately after\n\t * the last xattr metadata block, so we can use index[0] to work out\n\t * the end of the xattr metadata\n\t */\n\tstart = xattr_table_start;\n\tend = index[0];\n\tfor(i = 0; start < end; i++) {\n\t\tint length;\n\t\tvoid *x = realloc(xattrs, (i + 1) * SQUASHFS_METADATA_SIZE);\n\t\tif(x == NULL) {\n\t\t\tERROR(\"Failed to realloc xattr data\\n\");\n\t\t\tgoto failed3;\n\t\t}\n\t\txattrs = x;\n\n\t\t/* store mapping from location of compressed block in fs ->\n\t\t * location of uncompressed block in memory */\n\t\tres = save_xattr_block(start, i * SQUASHFS_METADATA_SIZE);\n\t\tif(res == -1)\n\t\t\tgoto failed3;\n\n\t\tlength = read_block(fd, start, &start,\n\t\t\t((unsigned char *) xattrs) +\n\t\t\t(i * SQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read xattr block %d, length %d\\n\", i, length);\n\t\tif(length == 0) {\n\t\t\tERROR(\"Failed to read xattr block %d\\n\", i);\n\t\t\tgoto failed3;\n\t\t}\n\t}\n\n\t/* swap if necessary the xattr id entries */\n\tfor(i = 0; i < ids; i++)\n\t\tSQUASHFS_INSWAP_XATTR_ID(&xattr_ids[i]);\n\n\tfree(index);\n\n\treturn ids;\n\nfailed3:\n\tfree(xattrs);\nfailed2:\n\tfree(xattr_ids);\nfailed1:\n\tfree(index);\n\n\treturn 0;\n}\n\n\n/*\n * Construct and return the list of xattr name:value pairs for the passed xattr\n * id\n */\nstruct xattr_list *get_xattr(int i, unsigned int *count)\n{\n\tlong long start;\n\tstruct xattr_list *xattr_list = NULL;\n\tunsigned int offset;\n\tvoid *xptr;\n\tint j;\n\n\tTRACE(\"get_xattr\\n\");\n\n\t*count = xattr_ids[i].count;\n\tstart = SQUASHFS_XATTR_BLK(xattr_ids[i].xattr) + xattr_table_start;\n\toffset = SQUASHFS_XATTR_OFFSET(xattr_ids[i].xattr);\n\txptr = xattrs + get_xattr_block(start) + offset;\n\n\tTRACE(\"get_xattr: xattr_id %d, count %d, start %lld, offset %d\\n\", i,\n\t\t\t*count, start, offset);\n\n\tfor(j = 0; j < *count; j++) {\n\t\tstruct squashfs_xattr_entry entry;\n\t\tstruct squashfs_xattr_val val;\n\t\tint res;\n\n\t\txattr_list = realloc(xattr_list, (j + 1) *\n\t\t\t\t\t\tsizeof(struct xattr_list));\n\t\tif(xattr_list == NULL) {\n\t\t\tERROR(\"Out of memory in get_xattrs\\n\");\n\t\t\tgoto failed;\n\t\t}\n\t\t\t\n\t\tSQUASHFS_SWAP_XATTR_ENTRY(&entry, xptr);\n\t\txptr += sizeof(entry);\n\t\tres = read_xattr_entry(&xattr_list[j], &entry, xptr);\n\t\tif(res != 1)\n\t\t\tgoto failed;\n\t\txptr += entry.size;\n\t\t\t\n\t\tTRACE(\"get_xattr: xattr %d, type %d, size %d, name %s\\n\", j,\n\t\t\tentry.type, entry.size, xattr_list[j].full_name); \n\n\t\tif(entry.type & SQUASHFS_XATTR_VALUE_OOL) {\n\t\t\tlong long xattr;\n\t\t\tvoid *ool_xptr;\n\n\t\t\txptr += sizeof(val);\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(&xattr, xptr, 1);\n\t\t\txptr += sizeof(xattr);\t\n\t\t\tstart = SQUASHFS_XATTR_BLK(xattr) + xattr_table_start;\n\t\t\toffset = SQUASHFS_XATTR_OFFSET(xattr);\n\t\t\tool_xptr = xattrs + get_xattr_block(start) + offset;\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, ool_xptr);\n\t\t\txattr_list[j].value = ool_xptr + sizeof(val);\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, xptr);\n\t\t\txattr_list[j].value = xptr + sizeof(val);\n\t\t\txptr += sizeof(val) + val.vsize;\n\t\t}\n\n\t\tTRACE(\"get_xattr: xattr %d, vsize %d\\n\", j, val.vsize);\n\n\t\txattr_list[j].vsize = val.vsize;\n\t}\n\n\treturn xattr_list;\n\nfailed:\n\tfree(xattr_list);\n\n\treturn NULL;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include \"squashfs_fs.h\"\n#include \"mksquashfs.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...) \\\n\t\tdo { \\\n\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern void write_file(squashfs_inode *inode, struct dir_ent *dir_ent,\n\tint *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority,\n\t\t\t\tfilename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 ||\n\t\t\tstrncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %d, st_ino \"\n\t\t\t\"%lld\\n\", path, priority, (int) buf.st_dev,\n\t\t\t(long long) buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is \"\n\t\t\t\"supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry\");\n\t        ERROR(\" should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to \"\n\t\t\t\"$PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source \"\n\t\t\t\"directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory \"\n\t\t\t\"test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1) {\n\t\tERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more \"\n\t\t\t\"than one source entry!  Please use an absolute path.\"\n\t\t\t\"\\n\", path);\n\t\treturn FALSE;\n\t}\n\nerror:\n        ERROR(\"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        ERROR(\"This is probably because you're using the wrong file\\n\");\n        ERROR(\"path relative to the source directories\\n\");\n\t/*\n\t * Historical note\n\t * Failure to stat a sortlist entry is deliberately ignored, even\n\t * though it is an error.  Squashfs release 2.2 changed the behaviour\n\t * to treat it as a fatal error, but it was changed back to\n\t * the original behaviour to ignore it in release 2.2-r2 following\n\t * feedback from users at the time.\n\t */\n        return TRUE;\n}\n\n\nint generate_file_priorities(struct dir_info *dir, int priority,\n\tstruct stat *buf)\n{\n\tint res;\n\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->inode->root_entry)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tres = add_priority_list(dir_ent,\n\t\t\t\t\tget_priority(dir_ent->pathname, buf,\n\t\t\t\t\tpriority));\n\t\t\t\tif(res == FALSE)\n\t\t\t\t\treturn FALSE;\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tres = generate_file_priorities(dir_ent->dir,\n\t\t\t\t\tpriority, buf);\n\t\t\t\tif(res == FALSE)\n\t\t\t\t\treturn FALSE;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n\n\treturn TRUE;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint res, priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767) {\n\t\t\tres = add_sort_list(sort_filename, priority, source,\n\t\t\t\tsource_path);\n\t\t\tif(res == FALSE)\n\t\t\t\treturn FALSE;\n\t\t} else\n\t\t\tERROR(\"Sort file %s, priority %d outside range of \"\n\t\t\t\t\"-32767:32768 - skipping...\\n\", sort_filename,\n\t\t\t\tpriority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\twrite_file(&inode, entry->dir, &duplicate_file);\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\"\n\t\t\t\t\t\"\\n\", entry->dir->pathname,\n\t\t\t\t\t(long long)\n\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes \"\n\t\t\t\t\t\"LINK\\n\", entry->dir->pathname,\n\t\t\t\t\t(long long)\n\t\t\t\t\tentry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/squashfs_compat.h",
    "content": "#ifndef SQUASHFS_COMPAT\n#define SQUASHFS_COMPAT\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_compat.h\n */\n\n/*\n * definitions for structures on disk - layout 3.x\n */\n\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\nstruct squashfs_super_block_3 {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode\t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index_3 {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER_3\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tsquashfs_block\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tsquashfs_block\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_3 {\n\tSQUASHFS_BASE_INODE_HEADER_3;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index_3\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_3 {\n\tstruct squashfs_base_inode_header_3\tbase;\n\tstruct squashfs_dev_inode_header_3\tdev;\n\tstruct squashfs_symlink_inode_header_3\tsymlink;\n\tstruct squashfs_reg_inode_header_3\treg;\n\tstruct squashfs_lreg_inode_header_3\tlreg;\n\tstruct squashfs_dir_inode_header_3\tdir;\n\tstruct squashfs_ldir_inode_header_3\tldir;\n\tstruct squashfs_ipc_inode_header_3\tipc;\n};\n\t\nstruct squashfs_dir_entry_3 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header_3 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_3 {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tpending;\n} __attribute__ ((packed));\n\n\ntypedef struct squashfs_super_block_3 squashfs_super_block_3;\ntypedef struct squashfs_dir_index_3 squashfs_dir_index_3;\ntypedef struct squashfs_base_inode_header_3 squashfs_base_inode_header_3;\ntypedef struct squashfs_ipc_inode_header_3 squashfs_ipc_inode_header_3;\ntypedef struct squashfs_dev_inode_header_3 squashfs_dev_inode_header_3;\ntypedef struct squashfs_symlink_inode_header_3 squashfs_symlink_inode_header_3;\ntypedef struct squashfs_reg_inode_header_3 squashfs_reg_inode_header_3;\ntypedef struct squashfs_lreg_inode_header_3 squashfs_lreg_inode_header_3;\ntypedef struct squashfs_dir_inode_header_3 squashfs_dir_inode_header_3;\ntypedef struct squashfs_ldir_inode_header_3 squashfs_ldir_inode_header_3;\ntypedef struct squashfs_dir_entry_3 squashfs_dir_entry_3;\ntypedef struct squashfs_dir_header_3 squashfs_dir_header_3;\ntypedef struct squashfs_fragment_entry_3 squashfs_fragment_entry_3;\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block_3));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_3(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_3))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_3)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_3));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_3));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_3));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_3));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_INODE_T_3(s, d) SQUASHFS_SWAP_LONG_LONGS_3(s, d, 1)\n\n#define SQUASHFS_SWAP_SHORTS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS_3(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_3(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_3));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_3(A)\t((A) * sizeof(struct squashfs_fragment_entry_3))\n\n#define SQUASHFS_FRAGMENT_INDEX_3(A)\t(SQUASHFS_FRAGMENT_BYTES_3(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_3(A)\t(SQUASHFS_FRAGMENT_BYTES_3(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_3(A)\t((SQUASHFS_FRAGMENT_BYTES_3(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_3(A)\t(SQUASHFS_FRAGMENT_INDEXES_3(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/*\n * definitions for structures on disk - layout 1.x\n */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_1 {\n\tstruct squashfs_base_inode_header_1\tbase;\n\tstruct squashfs_dev_inode_header_1\tdev;\n\tstruct squashfs_symlink_inode_header_1\tsymlink;\n\tstruct squashfs_reg_inode_header_1\treg;\n\tstruct squashfs_dir_inode_header_1\tdir;\n\tstruct squashfs_ipc_inode_header_1\tipc;\n};\n\ntypedef struct squashfs_dir_index_1 squashfs_dir_index_1;\ntypedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1;\ntypedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1;\ntypedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1;\ntypedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1;\ntypedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1;\ntypedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1;\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n/*\n * definitions for structures on disk - layout 2.x\n */\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\ntypedef struct squashfs_dir_index_2 squashfs_dir_index_2;\ntypedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2;\ntypedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2;\ntypedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2;\ntypedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2;\ntypedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2;\ntypedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2;\ntypedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2;\ntypedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2;\ntypedef struct squashfs_dir_entry_2 squashfs_dir_entry_2;\ntypedef struct squashfs_dir_header_2 squashfs_dir_header_2;\ntypedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2;\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS_3(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t((A) * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#define SQUASHFS_CACHED_FRAGMENTS\tCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE\t\n#define SQUASHFS_MAJOR\t\t\t4\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/* Max number of uids and gids */\n#define SQUASHFS_IDS\t\t\t65536\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_XATTR\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_EXPORT\t\t\t7\n#define SQUASHFS_NOX\t\t\t8\n#define SQUASHFS_NO_XATTR\t\t9\n#define SQUASHFS_COMP_OPT\t\t10\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_EXPORTABLE(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_EXPORT)\n\n#define SQUASHFS_UNCOMPRESSED_XATTRS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOX)\n\n#define SQUASHFS_NO_XATTRS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_XATTR)\n\n#define SQUASHFS_COMP_OPTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_COMP_OPT)\n\n#define SQUASHFS_MKFLAGS(noi, nod, nof, nox, no_frag, always_frag, \\\n\t\tduplicate_checking, exportable, no_xattr, comp_opt) (noi | \\\n\t\t(nod << 1) | (nof << 3) | (no_frag << 4) | \\\n\t\t(always_frag << 5) | (duplicate_checking << 6) | \\\n\t\t(exportable << 7) | (nox << 8) | (no_xattr << 9) | \\\n\t\t(comp_opt << 10))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n#define SQUASHFS_LSYMLINK_TYPE\t\t10\n#define SQUASHFS_LBLKDEV_TYPE\t\t11\n#define SQUASHFS_LCHRDEV_TYPE\t\t12\n#define SQUASHFS_LFIFO_TYPE\t\t13\n#define SQUASHFS_LSOCKET_TYPE\t\t14\n\n/* Xattr types */\n#define SQUASHFS_XATTR_USER\t\t0\n#define SQUASHFS_XATTR_TRUSTED\t\t1\n#define SQUASHFS_XATTR_SECURITY\t\t2\n#define SQUASHFS_XATTR_VALUE_OOL\t256\n#define SQUASHFS_XATTR_PREFIX_MASK\t0xff\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode)(((squashfs_inode) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t((A) * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n/* inode lookup table defines */\n#define SQUASHFS_LOOKUP_BYTES(A)\t((A) * sizeof(squashfs_inode))\n\n#define SQUASHFS_LOOKUP_BLOCK(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)\t\t(SQUASHFS_LOOKUP_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCKS(A)\t((SQUASHFS_LOOKUP_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_LOOKUP_BLOCK_BYTES(A)\t(SQUASHFS_LOOKUP_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* uid lookup table defines */\n#define SQUASHFS_ID_BYTES(A)\t((A) * sizeof(unsigned int))\n\n#define SQUASHFS_ID_BLOCK(A)\t\t(SQUASHFS_ID_BYTES(A) / \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCK_OFFSET(A)\t\t(SQUASHFS_ID_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCKS(A)\t((SQUASHFS_ID_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_ID_BLOCK_BYTES(A)\t(SQUASHFS_ID_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n/* xattr id lookup table defines */\n#define SQUASHFS_XATTR_BYTES(A)\t\t((A) * sizeof(struct squashfs_xattr_id))\n\n#define SQUASHFS_XATTR_BLOCK(A)\t\t(SQUASHFS_XATTR_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_XATTR_BLOCK_OFFSET(A)\t(SQUASHFS_XATTR_BYTES(A) % \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_XATTR_BLOCKS(A)\t((SQUASHFS_XATTR_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_XATTR_BLOCK_BYTES(A)\t(SQUASHFS_XATTR_BLOCKS(A) *\\\n\t\t\t\t\tsizeof(long long))\n\n#define SQUASHFS_XATTR_BLK(A)\t\t((unsigned int) ((A) >> 16))\n\n#define SQUASHFS_XATTR_OFFSET(A)\t((unsigned int) ((A) & 0xffff))\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/* meta index cache */\n#define SQUASHFS_META_INDEXES\t(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))\n#define SQUASHFS_META_ENTRIES\t31\n#define SQUASHFS_META_NUMBER\t8\n#define SQUASHFS_SLOTS\t\t4\n\nstruct meta_entry {\n\tlong long\t\tdata_block;\n\tunsigned int\t\tindex_block;\n\tunsigned short\t\toffset;\n\tunsigned short\t\tpad;\n};\n\nstruct meta_index {\n\tunsigned int\t\tinode_number;\n\tunsigned int\t\toffset;\n\tunsigned short\t\tentries;\n\tunsigned short\t\tskip;\n\tunsigned short\t\tlocked;\n\tunsigned short\t\tpad;\n\tstruct meta_entry\tmeta_entry[SQUASHFS_META_ENTRIES];\n};\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block;\ntypedef long long\t\tsquashfs_inode;\n\n#define ZLIB_COMPRESSION\t1\n#define LZMA_COMPRESSION\t2\n#define LZO_COMPRESSION\t\t3\n#define XZ_COMPRESSION\t\t4\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned short\t\tcompression;\n\tunsigned short\t\tblock_log;\n\tunsigned short\t\tflags;\n\tunsigned short\t\tno_ids;\n\tunsigned short\t\ts_major;\n\tunsigned short\t\ts_minor;\n\tsquashfs_inode\t\troot_inode;\n\tlong long\t\tbytes_used;\n\tlong long\t\tid_table_start;\n\tlong long\t\txattr_id_table_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tlookup_table_start;\n};\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\tname[0];\n};\n\nstruct squashfs_base_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n};\n\nstruct squashfs_ipc_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n};\n\nstruct squashfs_lipc_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\txattr;\n};\n\nstruct squashfs_dev_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\trdev;\n};\n\t\nstruct squashfs_ldev_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\trdev;\n\tunsigned int\t\txattr;\n};\n\t\nstruct squashfs_symlink_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n};\n\nstruct squashfs_reg_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned int\t\tblock_list[0];\n};\n\nstruct squashfs_lreg_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tsquashfs_block\t\tstart_block;\n\tlong long\t\tfile_size;\n\tlong long\t\tsparse;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\txattr;\n\tunsigned int\t\tblock_list[0];\n};\n\nstruct squashfs_dir_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tfile_size;\n\tunsigned short\t\toffset;\n\tunsigned int\t\tparent_inode;\n};\n\nstruct squashfs_ldir_inode_header {\n\tunsigned short\t\tinode_type;\n\tunsigned short\t\tmode;\n\tunsigned short\t\tuid;\n\tunsigned short\t\tguid;\n\tunsigned int\t\tmtime;\n\tunsigned int \t\tinode_number;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n\tunsigned short\t\ti_count;\n\tunsigned short\t\toffset;\n\tunsigned int\t\txattr;\n\tstruct squashfs_dir_index\tindex[0];\n};\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_ldev_inode_header\tldev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n\tstruct squashfs_lipc_inode_header\tlipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned short\t\toffset;\n\tshort\t\t\tinode_number;\n\tunsigned short\t\ttype;\n\tunsigned short\t\tsize;\n\tchar\t\t\tname[0];\n};\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n};\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tunused;\n};\n\nstruct squashfs_xattr_entry {\n\tunsigned short\t\ttype;\n\tunsigned short\t\tsize;\n\tchar\t\t\tdata[0];\n};\n\nstruct squashfs_xattr_val {\n\tunsigned int\t\tvsize;\n\tchar\t\t\tvalue[0];\n};\n\nstruct squashfs_xattr_id {\n\tlong long\t\txattr;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tsize;\n};\n\nstruct squashfs_xattr_table {\n\tlong long\t\txattr_table_start;\n\tunsigned int\t\txattr_ids;\n\tunsigned int\t\tunused;\n};\n\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/squashfs_swap.h",
    "content": "#ifndef SQUASHFS_SWAP_H\n#define SQUASHFS_SWAP_H\n/*\n * Squashfs\n *\n * Copyright (c) 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_swap.h\n */\n\n/*\n * macros to convert each stucture from big endian to little endian\n */\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#include <stddef.h>\nextern void swap_le16(void *, void *);\nextern void swap_le32(void *, void *);\nextern void swap_le64(void *, void *);\nextern void swap_le16_num(void *, void *, int);\nextern void swap_le32_num(void *, void *, int);\nextern void swap_le64_num(void *, void *, int);\nextern unsigned short inswap_le16(unsigned short);\nextern unsigned int inswap_le32(unsigned int);\nextern long long inswap_le64(long long);\nextern void inswap_le16_num(unsigned short *, int);\nextern void inswap_le32_num(unsigned int *, int);\nextern void inswap_le64_num(long long *, int);\n\n#define _SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(32, s, d, s_magic, struct squashfs_super_block);\\\n\tSWAP_FUNC(32, s, d, inodes, struct squashfs_super_block);\\\n\tSWAP_FUNC(32, s, d, mkfs_time, struct squashfs_super_block);\\\n\tSWAP_FUNC(32, s, d, block_size, struct squashfs_super_block);\\\n\tSWAP_FUNC(32, s, d, fragments, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, compression, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, block_log, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, flags, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, no_ids, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, s_major, struct squashfs_super_block);\\\n\tSWAP_FUNC(16, s, d, s_minor, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, root_inode, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, bytes_used, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, id_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, xattr_id_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, inode_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, directory_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, fragment_table_start, struct squashfs_super_block);\\\n\tSWAP_FUNC(64, s, d, lookup_table_start, struct squashfs_super_block);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(32, s, d, index, struct squashfs_dir_index);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_dir_index);\\\n\tSWAP_FUNC(32, s, d, size, struct squashfs_dir_index);\\\n}\n\n#define _SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_base_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_base_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_ipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_ipc_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_lipc_inode_header);\\\n\tSWAP_FUNC(32, s, d, xattr, struct squashfs_lipc_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_dev_inode_header);\\\n\tSWAP_FUNC(32, s, d, rdev, struct squashfs_dev_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, rdev, struct squashfs_ldev_inode_header);\\\n\tSWAP_FUNC(32, s, d, xattr, struct squashfs_ldev_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_symlink_inode_header);\\\n\tSWAP_FUNC(32, s, d, symlink_size, struct squashfs_symlink_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, fragment, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, offset, struct squashfs_reg_inode_header);\\\n\tSWAP_FUNC(32, s, d, file_size, struct squashfs_reg_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(64, s, d, start_block, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(64, s, d, file_size, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(64, s, d, sparse, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, fragment, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, offset, struct squashfs_lreg_inode_header);\\\n\tSWAP_FUNC(32, s, d, xattr, struct squashfs_lreg_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, file_size, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(16, s, d, offset, struct squashfs_dir_inode_header);\\\n\tSWAP_FUNC(32, s, d, parent_inode, struct squashfs_dir_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, inode_type, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, mode, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, uid, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, guid, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, mtime, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, nlink, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, file_size, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, parent_inode, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, i_count, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(16, s, d, offset, struct squashfs_ldir_inode_header);\\\n\tSWAP_FUNC(32, s, d, xattr, struct squashfs_ldir_inode_header);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, offset, struct squashfs_dir_entry);\\\n\tSWAP_FUNC##S(16, s, d, inode_number, struct squashfs_dir_entry);\\\n\tSWAP_FUNC(16, s, d, type, struct squashfs_dir_entry);\\\n\tSWAP_FUNC(16, s, d, size, struct squashfs_dir_entry);\\\n}\n\n#define _SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(32, s, d, count, struct squashfs_dir_header);\\\n\tSWAP_FUNC(32, s, d, start_block, struct squashfs_dir_header);\\\n\tSWAP_FUNC(32, s, d, inode_number, struct squashfs_dir_header);\\\n}\n\n#define _SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(64, s, d, start_block, struct squashfs_fragment_entry);\\\n\tSWAP_FUNC(32, s, d, size, struct squashfs_fragment_entry);\\\n}\n\n#define _SQUASHFS_SWAP_XATTR_ENTRY(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(16, s, d, type, struct squashfs_xattr_entry);\\\n\tSWAP_FUNC(16, s, d, size, struct squashfs_xattr_entry);\\\n}\n\n#define _SQUASHFS_SWAP_XATTR_VAL(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(32, s, d, vsize, struct squashfs_xattr_val);\\\n}\n\n#define _SQUASHFS_SWAP_XATTR_ID(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(64, s, d, xattr, struct squashfs_xattr_id);\\\n\tSWAP_FUNC(32, s, d, count, struct squashfs_xattr_id);\\\n\tSWAP_FUNC(32, s, d, size, struct squashfs_xattr_id);\\\n}\n\n#define _SQUASHFS_SWAP_XATTR_TABLE(s, d, SWAP_FUNC) {\\\n\tSWAP_FUNC(64, s, d, xattr_table_start, struct squashfs_xattr_table);\\\n\tSWAP_FUNC(32, s, d, xattr_ids, struct squashfs_xattr_table);\\\n}\n\n/* big endian architecture copy and swap macros */\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d)\t\\\n\t\t\t_SQUASHFS_SWAP_SUPER_BLOCK(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INDEX(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_IPC_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DEV_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_REG_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LREG_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) \\\n\t\t\t_SQUASHFS_SWAP_DIR_HEADER(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \\\n\t\t\t_SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_XATTR_ENTRY(s, d) \\\n\t\t\t _SQUASHFS_SWAP_XATTR_ENTRY(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_XATTR_VAL(s, d) \\\n\t\t\t_SQUASHFS_SWAP_XATTR_VAL(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_XATTR_ID(s, d) \\\n\t\t\t _SQUASHFS_SWAP_XATTR_ID(s, d, SWAP_LE)\n#define SQUASHFS_SWAP_XATTR_TABLE(s, d) \\\n\t\t\t_SQUASHFS_SWAP_XATTR_TABLE(s, d, SWAP_LE)\n#define SWAP_LE(bits, s, d, field, type) \\\n\t\t\tSWAP_LE##bits(((void *)(s)) + offsetof(type, field), \\\n\t\t\t\t((void *)(d)) + offsetof(type, field))\n#define SWAP_LES(bits, s, d, field, type) \\\n\t\t\tSWAP_LE(bits, s, d, field, type)\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) \\\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n/* big endian architecture swap in-place macros */\n#define SQUASHFS_INSWAP_SUPER_BLOCK(s) \\\n\t\t\t_SQUASHFS_SWAP_SUPER_BLOCK(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_INDEX(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INDEX(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_BASE_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_BASE_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_IPC_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_IPC_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LIPC_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LIPC_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DEV_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DEV_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LDEV_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LDEV_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_REG_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_REG_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LREG_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LREG_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_LDIR_INODE_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_ENTRY(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_ENTRY(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_DIR_HEADER(s) \\\n\t\t\t_SQUASHFS_SWAP_DIR_HEADER(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s) \\\n\t\t\t_SQUASHFS_SWAP_FRAGMENT_ENTRY(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_XATTR_ENTRY(s) \\\n\t\t\t _SQUASHFS_SWAP_XATTR_ENTRY(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_XATTR_VAL(s) \\\n\t\t\t_SQUASHFS_SWAP_XATTR_VAL(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_XATTR_ID(s) \\\n\t\t\t _SQUASHFS_SWAP_XATTR_ID(s, s, INSWAP_LE)\n#define SQUASHFS_INSWAP_XATTR_TABLE(s) \\\n\t\t\t_SQUASHFS_SWAP_XATTR_TABLE(s, s, INSWAP_LE)\n#define INSWAP_LE(bits, s, d, field, type) \\\n\t\t\t(s)->field = inswap_le##bits((s)->field)\n#define INSWAP_LES(bits, s, d, field, type) \\\n\t\t\t(s)->field = (short) inswap_le##bits((unsigned short) \\\n\t\t\t\t(s)->field)\n#define SQUASHFS_INSWAP_INODE_T(s) s = inswap_le64(s)\n#define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_ID_BLOCKS(s, n) inswap_le64_num(s, n)\n#define SQUASHFS_INSWAP_SHORTS(s, n) inswap_le16_num(s, n)\n#define SQUASHFS_INSWAP_INTS(s, n) inswap_le32_num(s, n)\n#define SQUASHFS_INSWAP_LONG_LONGS(s, n) inswap_le64_num(s, n)\n#else\n/* little endian architecture, just copy */\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d)\t\\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LIPC_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LDEV_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_XATTR_ENTRY(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_XATTR_VAL(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_XATTR_ID(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_XATTR_TABLE(s, d) \\\n\t\tSQUASHFS_MEMCPY(s, d, sizeof(*(s)))\n#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) \\\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n#define SQUASHFS_SWAP_ID_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n/* little endian architecture, data already in place so do nothing */\n#define SQUASHFS_INSWAP_SUPER_BLOCK(s)\n#define SQUASHFS_INSWAP_DIR_INDEX(s)\n#define SQUASHFS_INSWAP_BASE_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_IPC_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LIPC_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DEV_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LDEV_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_SYMLINK_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_REG_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LREG_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DIR_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_LDIR_INODE_HEADER(s)\n#define SQUASHFS_INSWAP_DIR_ENTRY(s)\n#define SQUASHFS_INSWAP_DIR_HEADER(s)\n#define SQUASHFS_INSWAP_FRAGMENT_ENTRY(s)\n#define SQUASHFS_INSWAP_XATTR_ENTRY(s)\n#define SQUASHFS_INSWAP_XATTR_VAL(s)\n#define SQUASHFS_INSWAP_XATTR_ID(s)\n#define SQUASHFS_INSWAP_XATTR_TABLE(s)\n#define SQUASHFS_INSWAP_INODE_T(s)\n#define SQUASHFS_INSWAP_FRAGMENT_INDEXES(s, n)\n#define SQUASHFS_INSWAP_LOOKUP_BLOCKS(s, n)\n#define SQUASHFS_INSWAP_ID_BLOCKS(s, n)\n#define SQUASHFS_INSWAP_SHORTS(s, n)\n#define SQUASHFS_INSWAP_INTS(s, n)\n#define SQUASHFS_INSWAP_LONG_LONGS(s, n)\n#endif\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/swap.c",
    "content": "/*\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * swap.c\n */\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#if __BYTE_ORDER == __BIG_ENDIAN\nvoid swap_le16(void *src, void *dest)\n{\n\tunsigned char *s = src;\n\tunsigned char *d = dest;\n\n\td[0] = s[1];\n\td[1] = s[0];\n}\n\n\nvoid swap_le32(void *src, void *dest)\n{\n\tunsigned char *s = src;\n\tunsigned char *d = dest;\n\n\td[0] = s[3];\n\td[1] = s[2];\n\td[2] = s[1];\n\td[3] = s[0];\n}\n\n\nvoid swap_le64(void *src, void *dest)\n{\n\tunsigned char *s = src;\n\tunsigned char *d = dest;\n\n\td[0] = s[7];\n\td[1] = s[6];\n\td[2] = s[5];\n\td[3] = s[4];\n\td[4] = s[3];\n\td[5] = s[2];\n\td[6] = s[1];\n\td[7] = s[0];\n}\n\n\nunsigned short inswap_le16(unsigned short num)\n{\n\treturn (num >> 8) |\n\t\t((num & 0xff) << 8);\n}\n\n\nunsigned int inswap_le32(unsigned int num)\n{\n\treturn (num >> 24) |\n\t\t((num & 0xff0000) >> 8) |\n\t\t((num & 0xff00) << 8) |\n\t\t((num & 0xff) << 24);\n}\n\n\nlong long inswap_le64(long long n)\n{\n\tunsigned long long num = n;\n\n\treturn (num >> 56) |\n\t\t((num & 0xff000000000000LL) >> 40) |\n\t\t((num & 0xff0000000000LL) >> 24) |\n\t\t((num & 0xff00000000LL) >> 8) |\n\t\t((num & 0xff000000) << 8) |\n\t\t((num & 0xff0000) << 24) |\n\t\t((num & 0xff00) << 40) |\n\t\t((num & 0xff) << 56);\n}\n\n\n#define SWAP_LE_NUM(BITS) \\\nvoid swap_le##BITS##_num(void *s, void *d, int n) \\\n{\\\n\tint i;\\\n\tfor(i = 0; i < n; i++, s += BITS / 8, d += BITS / 8)\\\n\t\tswap_le##BITS(s, d);\\\n}\n\nSWAP_LE_NUM(16)\nSWAP_LE_NUM(32)\nSWAP_LE_NUM(64)\n\n#define INSWAP_LE_NUM(BITS, TYPE) \\\nvoid inswap_le##BITS##_num(TYPE *s, int n) \\\n{\\\n\tint i;\\\n\tfor(i = 0; i < n; i++)\\\n\t\ts[i] = inswap_le##BITS(s[i]);\\\n}\n\nINSWAP_LE_NUM(16, unsigned short)\nINSWAP_LE_NUM(32, unsigned int)\nINSWAP_LE_NUM(64, long long)\n#endif\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/unsquash-1.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-1.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nvoid read_block_list_1(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tunsigned short block_size;\n\tint i;\n\n\tTRACE(\"read_block_list: blocks %d\\n\", blocks);\n\n\tfor(i = 0; i < blocks; i++, block_ptr += 2) {\n\t\tif(swap) {\n\t\t\tunsigned short sblock_size;\n\t\t\tmemcpy(&sblock_size, block_ptr, sizeof(unsigned short));\n\t\t\tSQUASHFS_SWAP_SHORTS_3((&block_size), &sblock_size, 1);\n\t\t} else\n\t\t\tmemcpy(&block_size, block_ptr, sizeof(unsigned short));\n\t\tblock_list[i] = SQUASHFS_COMPRESSED_SIZE(block_size) |\n\t\t\t(SQUASHFS_COMPRESSED(block_size) ? 0 :\n\t\t\tSQUASHFS_COMPRESSED_BIT_BLOCK);\n\t}\n}\n\n\nint read_fragment_table_1()\n{\n\tTRACE(\"read_fragment_table\\n\");\n\treturn TRUE;\n}\n\n\nstruct inode *read_inode_1(unsigned int start_block, unsigned int offset)\n{\n\tstatic union squashfs_inode_header_1 header;\n\tlong long start = sBlk.s.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"read_inode: inode table block %lld not found\\n\",\n\t\t\t start); \n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_1 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_1));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.uid = (uid_t) uid_table[(header.base.inode_type - 1) /\n\t\tSQUASHFS_TYPES * 16 + header.base.uid];\n\tif(header.base.inode_type == SQUASHFS_IPC_TYPE) {\n\t\tsquashfs_ipc_inode_header_1 *inodep = &header.ipc;\n\n\t\tif(swap) {\n\t\t\tsquashfs_ipc_inode_header_1 sinodep;\n\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER_1(inodep, &sinodep);\n\t\t} else\n\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\tif(inodep->type == SQUASHFS_SOCKET_TYPE) {\n\t\t\ti.mode = S_IFSOCK | header.base.mode;\n\t\t\ti.type = SQUASHFS_SOCKET_TYPE;\n\t\t} else {\n\t\t\ti.mode = S_IFIFO | header.base.mode;\n\t\t\ti.type = SQUASHFS_FIFO_TYPE;\n\t\t}\n\t\ti.uid = (uid_t) uid_table[inodep->offset * 16 + inodep->uid];\n\t} else {\n\t\ti.mode = lookup_type[(header.base.inode_type - 1) %\n\t\t\tSQUASHFS_TYPES + 1] | header.base.mode;\n\t\ti.type = (header.base.inode_type - 1) % SQUASHFS_TYPES + 1;\n\t}\n\n\ti.xattr = SQUASHFS_INVALID_XATTR;\n\ti.gid = header.base.guid == 15 ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.time = sBlk.s.mkfs_time;\n\ti.inode_number = inode_number ++;\n\n\tswitch(i.type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_1 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_1(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\tmemcpy(inode, block_ptr, sizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_1 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_1 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_1(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.blocks = (i.data + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.fragment = 0;\n\t\t\ti.frag_bytes = 0;\n\t\t\ti.offset = 0;\n\t\t\ti.sparse = 0;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_1 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_1),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_1 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_1 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_1(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE: {\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\t\t}\n\t\tdefault:\n\t\t\tEXIT_UNSQUASH(\"Unknown inode type %d in \"\n\t\t\t\t\" read_inode_header_1!\\n\",\n\t\t\t\theader.base.inode_type);\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_1(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header_2 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1]\n\t\t__attribute__((aligned));\n\tsquashfs_dir_entry_2 *dire = (squashfs_dir_entry_2 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\t*i = s_ops.read_inode(block_start, offset);\n\tstart = sBlk.s.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: directory block %d not \"\n\t\t\t\"found!\\n\", block_start);\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes;\n\n\tdir = malloc(sizeof(struct dir));\n\tif(dir == NULL)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: malloc failed!\\n\");\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->xattr = (*i)->xattr;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_2 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_2 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes,\n\t\t\t\t\tsizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes,\n\t\t\t\t\tsizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL)\n\t\t\t\t\tEXIT_UNSQUASH(\"squashfs_opendir: \"\n\t\t\t\t\t\t\"realloc failed!\\n\");\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint read_uids_guids_1()\n{\n\tint res;\n\n\tTRACE(\"read_uids_guids: no_uids %d, no_guids %d\\n\", sBlk.no_uids,\n\t\tsBlk.no_guids);\n\n\tuid_table = malloc((sBlk.no_uids + sBlk.no_guids) *\n\t\tsizeof(unsigned int));\n\tif(uid_table == NULL) {\n\t\tERROR(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\t\treturn FALSE;\n\t}\n\n\tguid_table = uid_table + sBlk.no_uids;\n\n\tif(swap) {\n\t\tunsigned int suid_table[sBlk.no_uids + sBlk.no_guids];\n\n\t\tres = read_fs_bytes(fd, sBlk.uid_start, (sBlk.no_uids +\n\t\t\tsBlk.no_guids) * sizeof(unsigned int), suid_table);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read uid/gid table\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_INTS_3(uid_table, suid_table,\n\t\t\tsBlk.no_uids + sBlk.no_guids);\n\t} else {\n\t\tres = read_fs_bytes(fd, sBlk.uid_start, (sBlk.no_uids +\n\t\t\tsBlk.no_guids) * sizeof(unsigned int), uid_table);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read uid/gid table\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/unsquash-2.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-2.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nstatic squashfs_fragment_entry_2 *fragment_table;\n\nvoid read_block_list_2(unsigned int *block_list, char *block_ptr, int blocks)\n{\n\tTRACE(\"read_block_list: blocks %d\\n\", blocks);\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS_3(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n}\n\n\nint read_fragment_table_2()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.s.fragments);\n\tunsigned int fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.s.fragments, indexes,\n\t\tsBlk.s.fragment_table_start);\n\n\tif(sBlk.s.fragments == 0)\n\t\treturn TRUE;\n\n\tfragment_table = malloc(sBlk.s.fragments *\n\t\tsizeof(squashfs_fragment_entry_2));\n\tif(fragment_table == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tif(swap) {\n\t\t unsigned int sfragment_table_index[indexes];\n\n\t\t res = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.s.fragments),\n\t\t\tsfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index,\n\t\t\tsfragment_table_index, indexes);\n\t} else {\n\t\tres = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.s.fragments),\n\t\t\tfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%x, length %d\\n\", i,\n\t\t\tfragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table block\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_2 sfragment;\n\t\tfor(i = 0; i < sBlk.s.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_2((&sfragment),\n\t\t\t\t(&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment,\n\t\t\t\tsizeof(squashfs_fragment_entry_2));\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_2(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_2 *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_2(unsigned int start_block, unsigned int offset)\n{\n\tstatic union squashfs_inode_header_2 header;\n\tlong long start = sBlk.s.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"read_inode: inode table block %lld not found\\n\",\n\t\t\tstart); \n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_2 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_2));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.xattr = SQUASHFS_INVALID_XATTR;\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = sBlk.s.mkfs_time;\n\ti.inode_number = inode_number++;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_2 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_2(&header.dir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr,\n\t\t\t\t\tsizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_2 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_2(&header.ldir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr,\n\t\t\t\t\tsizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.time = inode->mtime;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_2 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_2 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_2(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.time = inode->mtime;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(i.data + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log : i.data >>\n\t\t\t\tsBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_2 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_2),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_2 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_2 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tEXIT_UNSQUASH(\"Unknown inode type %d in \"\n\t\t\t\t\"read_inode_header_2!\\n\",\n\t\t\t\theader.base.inode_type);\n\t}\n\treturn &i;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/unsquash-3.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-3.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_compat.h\"\n\nstatic squashfs_fragment_entry_3 *fragment_table;\n\nint read_fragment_table_3()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES_3(sBlk.s.fragments);\n\tlong long fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.s.fragments, indexes,\n\t\tsBlk.s.fragment_table_start);\n\n\tif(sBlk.s.fragments == 0)\n\t\treturn TRUE;\n\n\tfragment_table = malloc(sBlk.s.fragments *\n\t\tsizeof(squashfs_fragment_entry_3));\n\tif(fragment_table == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tif(swap) {\n\t\tlong long sfragment_table_index[indexes];\n\n\t\tres = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.s.fragments),\n\t\t\tsfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES_3(fragment_table_index,\n\t\t\tsfragment_table_index, indexes);\n\t} else {\n\t\tres = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\t\tSQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.s.fragments),\n\t\t\tfragment_table_index);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table block\\n\");       \n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry_3 sfragment;\n\t\tfor(i = 0; i < sBlk.s.fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY_3((&sfragment),\n\t\t\t\t(&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment,\n\t\t\t\tsizeof(squashfs_fragment_entry_3));\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_3(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tsquashfs_fragment_entry_3 *fragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_3(unsigned int start_block, unsigned int offset)\n{\n\tstatic union squashfs_inode_header_3 header;\n\tlong long start = sBlk.s.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"read_inode: inode table block %lld not found\\n\",\n\t\t\tstart); \n\n\tif(swap) {\n\t\tsquashfs_base_inode_header_3 sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER_3(&header.base, &sinode,\n\t\t\tsizeof(squashfs_base_inode_header_3));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\ti.xattr = SQUASHFS_INVALID_XATTR;\n\ti.uid = (uid_t) uid_table[header.base.uid];\n\ti.gid = header.base.guid == SQUASHFS_GUIDS ? i.uid :\n\t\t(uid_t) guid_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tsquashfs_dir_inode_header_3 *inode = &header.dir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER_3(&header.dir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.dir, block_ptr,\n\t\t\t\t\tsizeof(header.dir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tsquashfs_ldir_inode_header_3 *inode = &header.ldir;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER_3(&header.ldir,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr,\n\t\t\t\t\tsizeof(header.ldir));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tsquashfs_reg_inode_header_3 *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER_3(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(i.data + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log :\n\t\t\t\ti.data >> sBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 1;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tsquashfs_lreg_inode_header_3 *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header_3 sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER_3(inode,\n\t\t\t\t\t&sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log :\n\t\t\t\tinode->file_size >> sBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 1;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header_3 *inodep =\n\t\t\t\t&header.symlink;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header_3 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.symlink = malloc(inodep->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(squashfs_symlink_inode_header_3),\n\t\t\t\tinodep->symlink_size);\n\t\t\ti.symlink[inodep->symlink_size] = '\\0';\n\t\t\ti.data = inodep->symlink_size;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header_3 *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header_3 sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER_3(inodep,\n\t\t\t\t\t&sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\ti.data = inodep->rdev;\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tEXIT_UNSQUASH(\"Unknown inode type %d in read_inode!\\n\",\n\t\t\t\theader.base.inode_type);\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_3(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tsquashfs_dir_header_3 dirh;\n\tchar buffer[sizeof(squashfs_dir_entry_3) + SQUASHFS_NAME_LEN + 1]\n\t\t__attribute__((aligned));\n\tsquashfs_dir_entry_3 *dire = (squashfs_dir_entry_3 *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\t*i = s_ops.read_inode(block_start, offset);\n\tstart = sBlk.s.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: directory block %d not \"\n\t\t\t\"found!\\n\", block_start);\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tdir = malloc(sizeof(struct dir));\n\tif(dir == NULL)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: malloc failed!\\n\");\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->xattr = (*i)->xattr;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header_3 sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER_3(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry_3 sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes,\n\t\t\t\t\tsizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY_3(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes,\n\t\t\t\t\tsizeof(*dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL)\n\t\t\t\t\tEXIT_UNSQUASH(\"squashfs_opendir: \"\n\t\t\t\t\t\t\"realloc failed!\\n\");\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/unsquash-4.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash-4.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_swap.h\"\n#include \"read_fs.h\"\n\nstatic struct squashfs_fragment_entry *fragment_table;\nstatic unsigned int *id_table;\n\nint read_fragment_table_4()\n{\n\tint res, i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.s.fragments);\n\tlong long fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes \"\n\t\t\"from 0x%llx\\n\", sBlk.s.fragments, indexes,\n\t\tsBlk.s.fragment_table_start);\n\n\tif(sBlk.s.fragments == 0)\n\t\treturn TRUE;\n\n\tfragment_table = malloc(sBlk.s.fragments *\n\t\tsizeof(struct squashfs_fragment_entry));\n\tif(fragment_table == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate \"\n\t\t\t\"fragment table\\n\");\n\n\tres = read_fs_bytes(fd, sBlk.s.fragment_table_start,\n\t\tSQUASHFS_FRAGMENT_INDEX_BYTES(sBlk.s.fragments),\n\t\tfragment_table_index);\n\tif(res == FALSE) {\n\t\tERROR(\"read_fragment_table: failed to read fragment table \"\n\t\t\t\"index\\n\");\n\t\treturn FALSE;\n\t}\n\tSQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL,\n\t\t\t((char *) fragment_table) + (i *\n\t\t\tSQUASHFS_METADATA_SIZE));\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\",\n\t\t\ti, fragment_table_index[i], length);\n\t\tif(length == FALSE) {\n\t\t\tERROR(\"read_fragment_table: failed to read fragment \"\n\t\t\t\t\"table index\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tfor(i = 0; i < sBlk.s.fragments; i++) \n\t\tSQUASHFS_INSWAP_FRAGMENT_ENTRY(&fragment_table[i]);\n\n\treturn TRUE;\n}\n\n\nvoid read_fragment_4(unsigned int fragment, long long *start_block, int *size)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tstruct squashfs_fragment_entry *fragment_entry;\n\n\tfragment_entry = &fragment_table[fragment];\n\t*start_block = fragment_entry->start_block;\n\t*size = fragment_entry->size;\n}\n\n\nstruct inode *read_inode_4(unsigned int start_block, unsigned int offset)\n{\n\tstatic union squashfs_inode_header header;\n\tlong long start = sBlk.s.inode_table_start + start_block;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tchar *block_ptr = inode_table + bytes + offset;\n\tstatic struct inode i;\n\n\tTRACE(\"read_inode: reading inode [%d:%d]\\n\", start_block,  offset);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"read_inode: inode table block %lld not found\\n\",\n\t\t\tstart); \t\t\n\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, block_ptr);\n\n\ti.uid = (uid_t) id_table[header.base.uid];\n\ti.gid = (uid_t) id_table[header.base.guid];\n\ti.mode = lookup_type[header.base.inode_type] | header.base.mode;\n\ti.type = header.base.inode_type;\n\ti.time = header.base.mtime;\n\ti.inode_number = header.base.inode_number;\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\tstruct squashfs_dir_inode_header *inode = &header.dir;\n\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\tstruct squashfs_ldir_inode_header *inode = &header.ldir;\n\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.xattr = inode->xattr;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tstruct squashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(i.data + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log :\n\t\t\t\ti.data >> sBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tstruct squashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->file_size;\n\t\t\ti.frag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG\n\t\t\t\t?  0 : inode->file_size % sBlk.s.block_size;\n\t\t\ti.fragment = inode->fragment;\n\t\t\ti.offset = inode->offset;\n\t\t\ti.blocks = inode->fragment == SQUASHFS_INVALID_FRAG ?\n\t\t\t\t(inode->file_size + sBlk.s.block_size - 1) >>\n\t\t\t\tsBlk.s.block_log :\n\t\t\t\tinode->file_size >> sBlk.s.block_log;\n\t\t\ti.start = inode->start_block;\n\t\t\ti.sparse = inode->sparse != 0;\n\t\t\ti.block_ptr = block_ptr + sizeof(*inode);\n\t\t\ti.xattr = inode->xattr;\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\tcase SQUASHFS_LSYMLINK_TYPE: {\n\t\t\tstruct squashfs_symlink_inode_header *inode = &header.symlink;\n\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.symlink = malloc(inode->symlink_size + 1);\n\t\t\tif(i.symlink == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"read_inode: failed to malloc \"\n\t\t\t\t\t\"symlink data\\n\");\n\t\t\tstrncpy(i.symlink, block_ptr +\n\t\t\t\tsizeof(struct squashfs_symlink_inode_header),\n\t\t\t\tinode->symlink_size);\n\t\t\ti.symlink[inode->symlink_size] = '\\0';\n\t\t\ti.data = inode->symlink_size;\n\n\t\t\tif(header.base.inode_type == SQUASHFS_LSYMLINK_TYPE)\n\t\t\t\tSQUASHFS_SWAP_INTS(&i.xattr, block_ptr +\n\t\t\t\t\tsizeof(struct squashfs_symlink_inode_header) +\n\t\t\t\t\tinode->symlink_size, 1);\n\t\t\telse\n\t\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tstruct squashfs_dev_inode_header *inode = &header.dev;\n\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->rdev;\n\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_LBLKDEV_TYPE:\n\t \tcase SQUASHFS_LCHRDEV_TYPE: {\n\t\t\tstruct squashfs_ldev_inode_header *inode = &header.ldev;\n\n\t\t\tSQUASHFS_SWAP_LDEV_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = inode->rdev;\n\t\t\ti.xattr = inode->xattr;\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\ti.data = 0;\n\t\t\ti.xattr = SQUASHFS_INVALID_XATTR;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LFIFO_TYPE:\n\t\tcase SQUASHFS_LSOCKET_TYPE: {\n\t\t\tstruct squashfs_lipc_inode_header *inode = &header.lipc;\n\n\t\t\tSQUASHFS_SWAP_LIPC_INODE_HEADER(inode, block_ptr);\n\n\t\t\ti.data = 0;\n\t\t\ti.xattr = inode->xattr;\n\t\t\tbreak;\n\t\t}\n\t\tdefault:\n\t\t\tEXIT_UNSQUASH(\"Unknown inode type %d in read_inode!\\n\",\n\t\t\t\theader.base.inode_type);\n\t}\n\treturn &i;\n}\n\n\nstruct dir *squashfs_opendir_4(unsigned int block_start, unsigned int offset,\n\tstruct inode **i)\n{\n\tstruct squashfs_dir_header dirh;\n\tchar buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1]\n\t\t__attribute__((aligned));\n\tstruct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;\n\tlong long start;\n\tint bytes;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\",\n\t\tblock_start, offset);\n\n\t*i = s_ops.read_inode(block_start, offset);\n\tstart = sBlk.s.directory_table_start + (*i)->start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: directory block %d not \"\n\t\t\t\"found!\\n\", block_start);\n\n\tbytes += (*i)->offset;\n\tsize = (*i)->data + bytes - 3;\n\n\tdir = malloc(sizeof(struct dir));\n\tif(dir == NULL)\n\t\tEXIT_UNSQUASH(\"squashfs_opendir: malloc failed!\\n\");\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = (*i)->mode;\n\tdir->uid = (*i)->uid;\n\tdir->guid = (*i)->gid;\n\tdir->mtime = (*i)->time;\n\tdir->xattr = (*i)->xattr;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, directory_table + bytes);\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position \"\n\t\t\t\"%d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, directory_table + bytes);\n\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes,\n\t\t\t\tdire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode \"\n\t\t\t\t\"%d:%d, type %d\\n\", dire->name,\n\t\t\t\tdirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tnew_dir = realloc(dir->dirs, (dir->dir_count +\n\t\t\t\t\tDIR_ENT_SIZE) * sizeof(struct dir_ent));\n\t\t\t\tif(new_dir == NULL)\n\t\t\t\t\tEXIT_UNSQUASH(\"squashfs_opendir: \"\n\t\t\t\t\t\t\"realloc failed!\\n\");\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block =\n\t\t\t\tdirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint read_uids_guids_4()\n{\n\tint res, i, indexes = SQUASHFS_ID_BLOCKS(sBlk.s.no_ids);\n\tlong long id_index_table[indexes];\n\n\tTRACE(\"read_uids_guids: no_ids %d\\n\", sBlk.s.no_ids);\n\n\tid_table = malloc(SQUASHFS_ID_BYTES(sBlk.s.no_ids));\n\tif(id_table == NULL) {\n\t\tERROR(\"read_uids_guids: failed to allocate id table\\n\");\n\t\treturn FALSE;\n\t}\n\n\tres = read_fs_bytes(fd, sBlk.s.id_table_start,\n\t\tSQUASHFS_ID_BLOCK_BYTES(sBlk.s.no_ids), id_index_table);\n\tif(res == FALSE) {\n\t\tERROR(\"read_uids_guids: failed to read id index table\\n\");\n\t\treturn FALSE;\n\t}\n\tSQUASHFS_INSWAP_ID_BLOCKS(id_index_table, indexes);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tres = read_block(fd, id_index_table[i], NULL,\n\t\t\t((char *) id_table) + i * SQUASHFS_METADATA_SIZE);\n\t\tif(res == FALSE) {\n\t\t\tERROR(\"read_uids_guids: failed to read id table block\"\n\t\t\t\t\"\\n\");\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\tSQUASHFS_INSWAP_INTS(id_table, sBlk.s.no_ids);\n\n\treturn TRUE;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs.c\n */\n\n#include \"unsquashfs.h\"\n#include \"squashfs_swap.h\"\n#include \"squashfs_compat.h\"\n#include \"read_fs.h\"\n#include \"compressor.h\"\n#include \"xattr.h\"\n\n#include <sys/sysinfo.h>\n#include <sys/types.h>\n\nstruct cache *fragment_cache, *data_cache;\nstruct queue *to_reader, *to_deflate, *to_writer, *from_writer;\npthread_t *thread, *deflator_thread;\npthread_mutex_t\tfragment_mutex;\n\n/* user options that control parallelisation */\nint processors = -1;\n\nstruct super_block sBlk;\nsquashfs_operations s_ops;\nstruct compressor *comp;\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0,\n\tdev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nunsigned int block_log;\nint lsonly = FALSE, info = FALSE, force = FALSE, short_ls = TRUE;\nint use_regex = FALSE;\nchar **created_inode;\nint root_process;\nint columns;\nint rotate = 0;\npthread_mutex_t\tscreen_mutex;\npthread_cond_t progress_wait;\nint progress = TRUE, progress_enabled = FALSE;\nunsigned int total_blocks = 0, total_files = 0, total_inodes = 0;\nunsigned int cur_blocks = 0;\nint inode_number = 1;\nint no_xattrs = XATTR_DEF;\n\nint lookup_type[] = {\n\t0,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK,\n\tS_IFDIR,\n\tS_IFREG,\n\tS_IFLNK,\n\tS_IFBLK,\n\tS_IFCHR,\n\tS_IFIFO,\n\tS_IFSOCK\n};\n\nstruct test table[] = {\n\t{ S_IFMT, S_IFSOCK, 0, 's' },\n\t{ S_IFMT, S_IFLNK, 0, 'l' },\n\t{ S_IFMT, S_IFBLK, 0, 'b' },\n\t{ S_IFMT, S_IFDIR, 0, 'd' },\n\t{ S_IFMT, S_IFCHR, 0, 'c' },\n\t{ S_IFMT, S_IFIFO, 0, 'p' },\n\t{ S_IRUSR, S_IRUSR, 1, 'r' },\n\t{ S_IWUSR, S_IWUSR, 2, 'w' },\n\t{ S_IRGRP, S_IRGRP, 4, 'r' },\n\t{ S_IWGRP, S_IWGRP, 5, 'w' },\n\t{ S_IROTH, S_IROTH, 7, 'r' },\n\t{ S_IWOTH, S_IWOTH, 8, 'w' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR | S_ISUID, 3, 's' },\n\t{ S_IXUSR | S_ISUID, S_ISUID, 3, 'S' },\n\t{ S_IXUSR | S_ISUID, S_IXUSR, 3, 'x' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP | S_ISGID, 6, 's' },\n\t{ S_IXGRP | S_ISGID, S_ISGID, 6, 'S' },\n\t{ S_IXGRP | S_ISGID, S_IXGRP, 6, 'x' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH | S_ISVTX, 9, 't' },\n\t{ S_IXOTH | S_ISVTX, S_ISVTX, 9, 'T' },\n\t{ S_IXOTH | S_ISVTX, S_IXOTH, 9, 'x' },\n\t{ 0, 0, 0, 0}\n};\n\nvoid progress_bar(long long current, long long max, int columns);\nvoid update_progress_bar();\n\nvoid sigwinch_handler()\n{\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n}\n\n\nvoid sigalrm_handler()\n{\n\trotate = (rotate + 1) % 4;\n}\n\n\nstruct queue *queue_init(int size)\n{\n\tstruct queue *queue = malloc(sizeof(struct queue));\n\n\tif(queue == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in queue_init\\n\");\n\n\tqueue->data = malloc(sizeof(void *) * (size + 1));\n\tif(queue->data == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in queue_init\\n\");\n\n\tqueue->size = size + 1;\n\tqueue->readp = queue->writep = 0;\n\tpthread_mutex_init(&queue->mutex, NULL);\n\tpthread_cond_init(&queue->empty, NULL);\n\tpthread_cond_init(&queue->full, NULL);\n\n\treturn queue;\n}\n\n\nvoid queue_put(struct queue *queue, void *data)\n{\n\tint nextp;\n\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile((nextp = (queue->writep + 1) % queue->size) == queue->readp)\n\t\tpthread_cond_wait(&queue->full, &queue->mutex);\n\n\tqueue->data[queue->writep] = data;\n\tqueue->writep = nextp;\n\tpthread_cond_signal(&queue->empty);\n\tpthread_mutex_unlock(&queue->mutex);\n}\n\n\nvoid *queue_get(struct queue *queue)\n{\n\tvoid *data;\n\tpthread_mutex_lock(&queue->mutex);\n\n\twhile(queue->readp == queue->writep)\n\t\tpthread_cond_wait(&queue->empty, &queue->mutex);\n\n\tdata = queue->data[queue->readp];\n\tqueue->readp = (queue->readp + 1) % queue->size;\n\tpthread_cond_signal(&queue->full);\n\tpthread_mutex_unlock(&queue->mutex);\n\n\treturn data;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tint hash = CALCULATE_HASH(entry->block);\n\n\tentry->hash_next = cache->hash_table[hash];\n\tcache->hash_table[hash] = entry;\n\tentry->hash_prev = NULL;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry;\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_hash_table(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->hash_prev)\n\t\tentry->hash_prev->hash_next = entry->hash_next;\n\telse\n\t\tcache->hash_table[CALCULATE_HASH(entry->block)] =\n\t\t\tentry->hash_next;\n\tif(entry->hash_next)\n\t\tentry->hash_next->hash_prev = entry->hash_prev;\n\n\tentry->hash_prev = entry->hash_next = NULL;\n}\n\n\n/* Called with the cache mutex held */\nvoid insert_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(cache->free_list) {\n\t\tentry->free_next = cache->free_list;\n\t\tentry->free_prev = cache->free_list->free_prev;\n\t\tcache->free_list->free_prev->free_next = entry;\n\t\tcache->free_list->free_prev = entry;\n\t} else {\n\t\tcache->free_list = entry;\n\t\tentry->free_prev = entry->free_next = entry;\n\t}\n}\n\n\n/* Called with the cache mutex held */\nvoid remove_free_list(struct cache *cache, struct cache_entry *entry)\n{\n\tif(entry->free_prev == NULL && entry->free_next == NULL)\n\t\t/* not in free list */\n\t\treturn;\n\telse if(entry->free_prev == entry && entry->free_next == entry) {\n\t\t/* only this entry in the free list */\n\t\tcache->free_list = NULL;\n\t} else {\n\t\t/* more than one entry in the free list */\n\t\tentry->free_next->free_prev = entry->free_prev;\n\t\tentry->free_prev->free_next = entry->free_next;\n\t\tif(cache->free_list == entry)\n\t\t\tcache->free_list = entry->free_next;\n\t}\n\n\tentry->free_prev = entry->free_next = NULL;\n}\n\n\nstruct cache *cache_init(int buffer_size, int max_buffers)\n{\n\tstruct cache *cache = malloc(sizeof(struct cache));\n\n\tif(cache == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in cache_init\\n\");\n\n\tcache->max_buffers = max_buffers;\n\tcache->buffer_size = buffer_size;\n\tcache->count = 0;\n\tcache->free_list = NULL;\n\tmemset(cache->hash_table, 0, sizeof(struct cache_entry *) * 65536);\n\tcache->wait_free = FALSE;\n\tcache->wait_pending = FALSE;\n\tpthread_mutex_init(&cache->mutex, NULL);\n\tpthread_cond_init(&cache->wait_for_free, NULL);\n\tpthread_cond_init(&cache->wait_for_pending, NULL);\n\n\treturn cache;\n}\n\n\nstruct cache_entry *cache_get(struct cache *cache, long long block, int size)\n{\n\t/*\n\t * Get a block out of the cache.  If the block isn't in the cache\n \t * it is added and queued to the reader() and deflate() threads for\n \t * reading off disk and decompression.  The cache grows until max_blocks\n \t * is reached, once this occurs existing discarded blocks on the free\n \t * list are reused\n \t */\n\tint hash = CALCULATE_HASH(block);\n\tstruct cache_entry *entry;\n\n\tpthread_mutex_lock(&cache->mutex);\n\n\tfor(entry = cache->hash_table[hash]; entry; entry = entry->hash_next)\n\t\tif(entry->block == block)\n\t\t\tbreak;\n\n\tif(entry) {\n\t\t/*\n \t\t * found the block in the cache, increment used count and\n \t\t * if necessary remove from free list so it won't disappear\n \t\t */\n\t\tentry->used ++;\n\t\tremove_free_list(cache, entry);\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t} else {\n\t\t/*\n \t\t * not in the cache\n\t\t *\n\t\t * first try to allocate new block\n\t\t */\n\t\tif(cache->count < cache->max_buffers) {\n\t\t\tentry = malloc(sizeof(struct cache_entry));\n\t\t\tif(entry == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in cache_get\\n\");\n\t\t\tentry->data = malloc(cache->buffer_size);\n\t\t\tif(entry->data == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in cache_get\\n\");\n\t\t\tentry->cache = cache;\n\t\t\tentry->free_prev = entry->free_next = NULL;\n\t\t\tcache->count ++;\n\t\t} else {\n\t\t\t/*\n\t\t\t * try to get from free list\n\t\t\t */\n\t\t\twhile(cache->free_list == NULL) {\n\t\t\t\tcache->wait_free = TRUE;\n\t\t\t\tpthread_cond_wait(&cache->wait_for_free,\n\t\t\t\t\t&cache->mutex);\n\t\t\t}\n\t\t\tentry = cache->free_list;\n\t\t\tremove_free_list(cache, entry);\n\t\t\tremove_hash_table(cache, entry);\n\t\t}\n\n\t\t/*\n\t\t * initialise block and insert into the hash table\n\t\t */\n\t\tentry->block = block;\n\t\tentry->size = size;\n\t\tentry->used = 1;\n\t\tentry->error = FALSE;\n\t\tentry->pending = TRUE;\n\t\tinsert_hash_table(cache, entry);\n\n\t\t/*\n\t\t * queue to read thread to read and ultimately (via the\n\t\t * decompress threads) decompress the buffer\n \t\t */\n\t\tpthread_mutex_unlock(&cache->mutex);\n\t\tqueue_put(to_reader, entry);\n\t}\n\n\treturn entry;\n}\n\n\t\nvoid cache_block_ready(struct cache_entry *entry, int error)\n{\n\t/*\n\t * mark cache entry as being complete, reading and (if necessary)\n \t * decompression has taken place, and the buffer is valid for use.\n \t * If an error occurs reading or decompressing, the buffer also \n \t * becomes ready but with an error...\n \t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\tentry->pending = FALSE;\n\tentry->error = error;\n\n\t/*\n\t * if the wait_pending flag is set, one or more threads may be waiting\n\t * on this buffer\n\t */\n\tif(entry->cache->wait_pending) {\n\t\tentry->cache->wait_pending = FALSE;\n\t\tpthread_cond_broadcast(&entry->cache->wait_for_pending);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_wait(struct cache_entry *entry)\n{\n\t/*\n\t * wait for this cache entry to become ready, when reading and (if\n\t * necessary) decompression has taken place\n\t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\twhile(entry->pending) {\n\t\tentry->cache->wait_pending = TRUE;\n\t\tpthread_cond_wait(&entry->cache->wait_for_pending,\n\t\t\t&entry->cache->mutex);\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nvoid cache_block_put(struct cache_entry *entry)\n{\n\t/*\n\t * finished with this cache entry, once the usage count reaches zero it\n \t * can be reused and is put onto the free list.  As it remains\n \t * accessible via the hash table it can be found getting a new lease of\n \t * life before it is reused.\n \t */\n\tpthread_mutex_lock(&entry->cache->mutex);\n\n\tentry->used --;\n\tif(entry->used == 0) {\n\t\tinsert_free_list(entry->cache, entry);\n\n\t\t/*\n\t\t * if the wait_free flag is set, one or more threads may be\n\t\t * waiting on this buffer\n\t\t */\n\t\tif(entry->cache->wait_free) {\n\t\t\tentry->cache->wait_free = FALSE;\n\t\t\tpthread_cond_broadcast(&entry->cache->wait_for_free);\n\t\t}\n\t}\n\n\tpthread_mutex_unlock(&entry->cache->mutex);\n}\n\n\nchar *modestr(char *str, int mode)\n{\n\tint i;\n\n\tstrcpy(str, \"----------\");\n\n\tfor(i = 0; table[i].mask != 0; i++) {\n\t\tif((mode & table[i].mask) == table[i].value)\n\t\t\tstr[table[i].position] = table[i].mode;\n\t}\n\n\treturn str;\n}\n\n\n#define TOTALCHARS  25\nint print_filename(char *pathname, struct inode *inode)\n{\n\tchar str[11], dummy[100], dummy2[100], *userstr, *groupstr;\n\tint padchars;\n\tstruct passwd *user;\n\tstruct group *group;\n\tstruct tm *t;\n\n\tif(short_ls) {\n\t\tprintf(\"%s\\n\", pathname);\n\t\treturn 1;\n\t}\n\n\tuser = getpwuid(inode->uid);\n\tif(user == NULL) {\n\t\tsprintf(dummy, \"%d\", inode->uid);\n\t\tuserstr = dummy;\n\t} else\n\t\tuserstr = user->pw_name;\n\t\t \n\tgroup = getgrgid(inode->gid);\n\tif(group == NULL) {\n\t\tsprintf(dummy2, \"%d\", inode->gid);\n\t\tgroupstr = dummy2;\n\t} else\n\t\tgroupstr = group->gr_name;\n\n\tprintf(\"%s %s/%s \", modestr(str, inode->mode), userstr, groupstr);\n\n\tswitch(inode->mode & S_IFMT) {\n\t\tcase S_IFREG:\n\t\tcase S_IFDIR:\n\t\tcase S_IFSOCK:\n\t\tcase S_IFIFO:\n\t\tcase S_IFLNK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) -\n\t\t\t\tstrlen(groupstr);\n\n\t\t\tprintf(\"%*lld \", padchars > 0 ? padchars : 0,\n\t\t\t\tinode->data);\n\t\t\tbreak;\n\t\tcase S_IFCHR:\n\t\tcase S_IFBLK:\n\t\t\tpadchars = TOTALCHARS - strlen(userstr) -\n\t\t\t\tstrlen(groupstr) - 7; \n\n\t\t\tprintf(\"%*s%3d,%3d \", padchars > 0 ? padchars : 0, \" \",\n\t\t\t\t(int) inode->data >> 8, (int) inode->data &\n\t\t\t\t0xff);\n\t\t\tbreak;\n\t}\n\n\tt = localtime(&inode->time);\n\n\tprintf(\"%d-%02d-%02d %02d:%02d %s\", t->tm_year + 1900, t->tm_mon + 1,\n\t\tt->tm_mday, t->tm_hour, t->tm_min, pathname);\n\tif((inode->mode & S_IFMT) == S_IFLNK)\n\t\tprintf(\" -> %s\", inode->symlink);\n\tprintf(\"\\n\");\n\t\t\n\treturn 1;\n}\n\t\n\nvoid add_entry(struct hash_table_entry *hash_table[], long long start,\n\tint bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\thash_table_entry = malloc(sizeof(struct hash_table_entry));\n\tif(hash_table_entry == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in add_entry\\n\");\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], long long start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry;\n\t\t\t\thash_table_entry = hash_table_entry->next)\n\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_fs_bytes(int fd, long long byte, int bytes, void *buff)\n{\n\toff_t off = byte;\n\tint res, count;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte,\n\t\tbytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = read(fd, buff + count, bytes - count);\n\t\tif(res < 1) {\n\t\t\tif(res == 0) {\n\t\t\t\tERROR(\"Read on filesystem failed because \"\n\t\t\t\t\t\"EOF\\n\");\n\t\t\t\treturn FALSE;\n\t\t\t} else if(errno != EINTR) {\n\t\t\t\tERROR(\"Read on filesystem failed because %s\\n\",\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn FALSE;\n\t\t\t} else\n\t\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(int fd, long long start, long long *next, void *block)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_fs_bytes(fd, start, 2, &c_byte) == FALSE)\n\t\t\tgoto failed;\n\t\tc_byte = (c_byte >> 8) | ((c_byte & 0xff) << 8);\n\t} else \n\t\tif(read_fs_bytes(fd, start, 2, &c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start,\n\t\tSQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ?\n\t\t\"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk.s.flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint error, res;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_fs_bytes(fd, start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tres = compressor_uncompress(comp, block, buffer, c_byte,\n\t\t\tSQUASHFS_METADATA_SIZE, &error);\n\n\t\tif(res == -1) {\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn res;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_fs_bytes(fd, start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\tERROR(\"read_block: failed to read block @0x%llx\\n\", start);\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint error, res;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start,\n\t\tc_byte, SQUASHFS_COMPRESSED_BLOCK(size) ? \"compressed\" :\n\t\t\"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_fs_bytes(fd, start, c_byte, data) == FALSE)\n\t\t\tgoto failed;\n\n\t\tres = compressor_uncompress(comp, block, data, c_byte,\n\t\t\tblock_size, &error);\n\n\t\tif(res == -1) {\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\t\tgoto failed;\n\t\t}\n\n\t\treturn res;\n\t} else {\n\t\tif(read_fs_bytes(fd, start, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\n\t\treturn c_byte;\n\t}\n\nfailed:\n\tERROR(\"read_data_block: failed to read block @0x%llx, size %d\\n\", start,\n\t\tc_byte);\n\treturn FALSE;\n}\n\n\nvoid uncompress_inode_table(long long start, long long end)\n{\n\tint size = 0, bytes = 0, res;\n\n\tTRACE(\"uncompress_inode_table: start %lld, end %lld\\n\", start, end);\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE) {\n\t\t\tinode_table = realloc(inode_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE);\n\t\t\tif(inode_table == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in \"\n\t\t\t\t\t\"uncompress_inode_table\");\n\t\t}\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tres = read_block(fd, start, &start, inode_table + bytes);\n\t\tif(res == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read \"\n\t\t\t\t\"block \\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, int mode, uid_t uid, gid_t guid, time_t time,\n\tunsigned int xattr, unsigned int set_mode)\n{\n\tstruct utimbuf times = { time, time };\n\n\twrite_xattr(pathname, xattr);\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(root_process) {\n\t\tif(chown(pathname, uid, guid) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids \"\n\t\t\t\t\"on %s, because %s\\n\", pathname,\n\t\t\t\tstrerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t} else\n\t\tmode &= ~07000;\n\n\tif((set_mode || (mode & 07000)) && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint write_bytes(int fd, char *buff, int bytes)\n{\n\tint res, count;\n\n\tfor(count = 0; count < bytes; count += res) {\n\t\tres = write(fd, buff + count, bytes - count);\n\t\tif(res == -1) {\n\t\t\tif(errno != EINTR) {\n\t\t\t\tERROR(\"Write on output file failed because \"\n\t\t\t\t\t\"%s\\n\", strerror(errno));\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tres = 0;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\n\nint lseek_broken = FALSE;\nchar *zero_data = NULL;\n\nint write_block(int file_fd, char *buffer, int size, long long hole, int sparse)\n{\n\toff_t off = hole;\n\n\tif(hole) {\n\t\tif(sparse && lseek_broken == FALSE) {\n\t\t\t int error = lseek(file_fd, off, SEEK_CUR);\n\t\t\t if(error == -1)\n\t\t\t\t/* failed to seek beyond end of file */\n\t\t\t\tlseek_broken = TRUE;\n\t\t}\n\n\t\tif((sparse == FALSE || lseek_broken) && zero_data == NULL) {\n\t\t\tif((zero_data = malloc(block_size)) == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"write_block: failed to alloc \"\n\t\t\t\t\t\"zero data block\\n\");\n\t\t\tmemset(zero_data, 0, block_size);\n\t\t}\n\n\t\tif(sparse == FALSE || lseek_broken) {\n\t\t\tint blocks = (hole + block_size -1) / block_size;\n\t\t\tint avail_bytes, i;\n\t\t\tfor(i = 0; i < blocks; i++, hole -= avail_bytes) {\n\t\t\t\tavail_bytes = hole > block_size ? block_size :\n\t\t\t\t\thole;\n\t\t\t\tif(write_bytes(file_fd, zero_data, avail_bytes)\n\t\t\t\t\t\t== -1)\n\t\t\t\t\tgoto failure;\n\t\t\t}\n\t\t}\n\t}\n\n\tif(write_bytes(file_fd, buffer, size) == -1)\n\t\tgoto failure;\n\n\treturn TRUE;\n\nfailure:\n\treturn FALSE;\n}\n\n\nint write_file(struct inode *inode, char *pathname)\n{\n\tunsigned int file_fd, i;\n\tunsigned int *block_list;\n\tint file_end = inode->data / block_size;\n\tlong long start = inode->start;\n\tstruct squashfs_file *file;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", inode->blocks);\n\n\tfile_fd = open(pathname, O_CREAT | O_WRONLY | (force ? O_TRUNC : 0),\n\t\t(mode_t) inode->mode & 0777);\n\tif(file_fd == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\",\n\t\t\tpathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tblock_list = malloc(inode->blocks * sizeof(unsigned int));\n\tif(block_list == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc block list\\n\");\n\n\ts_ops.read_block_list(block_list, inode->block_ptr, inode->blocks);\n\n\tfile = malloc(sizeof(struct squashfs_file));\n\tif(file == NULL)\n\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\n\t/*\n\t * the writer thread is queued a squashfs_file structure describing the\n \t * file.  If the file has one or more blocks or a fragments they are\n \t * queued separately (references to blocks in the cache).\n \t */\n\tfile->fd = file_fd;\n\tfile->file_size = inode->data;\n\tfile->mode = inode->mode;\n\tfile->gid = inode->gid;\n\tfile->uid = inode->uid;\n\tfile->time = inode->time;\n\tfile->pathname = strdup(pathname);\n\tfile->blocks = inode->blocks + (inode->frag_bytes > 0);\n\tfile->sparse = inode->sparse;\n\tfile->xattr = inode->xattr;\n\tqueue_put(to_writer, file);\n\n\tfor(i = 0; i < inode->blocks; i++) {\n\t\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\tblock->offset = 0;\n\t\tblock->size = i == file_end ? inode->data & (block_size - 1) :\n\t\t\tblock_size;\n\t\tif(block_list[i] == 0) /* sparse file */\n\t\t\tblock->buffer = NULL;\n\t\telse {\n\t\t\tblock->buffer = cache_get(data_cache, start,\n\t\t\t\tblock_list[i]);\n\t\t\tstart += c_byte;\n\t\t}\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tif(inode->frag_bytes) {\n\t\tint size;\n\t\tlong long start;\n\t\tstruct file_entry *block = malloc(sizeof(struct file_entry));\n\n\t\tif(block == NULL)\n\t\t\tEXIT_UNSQUASH(\"write_file: unable to malloc file\\n\");\n\t\ts_ops.read_fragment(inode->fragment, &start, &size);\n\t\tblock->buffer = cache_get(fragment_cache, start, size);\n\t\tblock->offset = inode->offset;\n\t\tblock->size = inode->frag_bytes;\n\t\tqueue_put(to_writer, block);\n\t}\n\n\tfree(block_list);\n\treturn TRUE;\n}\n\n\nint create_inode(char *pathname, struct inode *i)\n{\n\tTRACE(\"create_inode: pathname %s\\n\", pathname);\n\n\tif(created_inode[i->inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(force)\n\t\t\tunlink(pathname);\n\n\t\tif(link(created_inode[i->inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, \"\n\t\t\t\t\"because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(i->type) {\n\t\tcase SQUASHFS_FILE_TYPE:\n\t\tcase SQUASHFS_LREG_TYPE:\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, \"\n\t\t\t\t\"blocks %d\\n\", i->data, i->blocks);\n\n\t\t\tif(write_file(i, pathname))\n\t\t\t\tfile_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\tcase SQUASHFS_LSYMLINK_TYPE:\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %lld\\n\",\n\t\t\t\ti->data);\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(symlink(i->symlink, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink \"\n\t\t\t\t\t\"%s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\twrite_xattr(pathname, i->xattr);\n\t\n\t\t\tif(root_process) {\n\t\t\t\tif(lchown(pathname, i->uid, i->gid) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change \"\n\t\t\t\t\t\t\"uid and gids on %s, because \"\n\t\t\t\t\t\t\"%s\\n\", pathname,\n\t\t\t\t\t\tstrerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE:\n \t\tcase SQUASHFS_LBLKDEV_TYPE:\n\t \tcase SQUASHFS_LCHRDEV_TYPE: {\n\t\t\tint chrdev = i->type == SQUASHFS_CHRDEV_TYPE;\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%llx\\n\", i->data);\n\n\t\t\tif(root_process) {\n\t\t\t\tif(force)\n\t\t\t\t\tunlink(pathname);\n\n\t\t\t\tif(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,\n\t\t\t\t\t\tmakedev((i->data >> 8) & 0xff,\n\t\t\t\t\t\ti->data & 0xff)) == -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create \"\n\t\t\t\t\t\t\"%s device %s, because %s\\n\",\n\t\t\t\t\t\tchrdev ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, i->mode, i->uid,\n\t\t\t\t\ti->gid, i->time, i->xattr, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s \"\n\t\t\t\t\t\"device %s, because you're not \"\n\t\t\t\t\t\"superuser!\\n\", chrdev ? \"character\" :\n\t\t\t\t\t\"block\", pathname);\n\t\t\tbreak;\n\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\tcase SQUASHFS_LFIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(force)\n\t\t\t\tunlink(pathname);\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, \"\n\t\t\t\t\t\"because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, i->mode, i->uid, i->gid,\n\t\t\t\ti->time, i->xattr, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\tcase SQUASHFS_LSOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\",\n\t\t\t\ti->type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[i->inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end)\n{\n\tint bytes = 0, size = 0, res;\n\n\tTRACE(\"uncompress_directory_table: start %lld, end %lld\\n\", start, end);\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE) {\n\t\t\tdirectory_table = realloc(directory_table, size +=\n\t\t\t\tSQUASHFS_METADATA_SIZE);\n\t\t\tif(directory_table == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in \"\n\t\t\t\t\t\"uncompress_directory_table\\n\");\n\t\t}\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\",\n\t\t\t\tstart);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tres = read_block(fd, start, &start, directory_table + bytes);\n\t\tif(res == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to \"\n\t\t\t\t\"read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block,\nunsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nchar *get_component(char *target, char *targname)\n{\n\twhile(*target == '/')\n\t\ttarget ++;\n\n\twhile(*target != '/' && *target!= '\\0')\n\t\t*targname ++ = *target ++;\n\n\t*targname = '\\0';\n\n\treturn target;\n}\n\n\nvoid free_path(struct pathname *paths)\n{\n\tint i;\n\n\tfor(i = 0; i < paths->names; i++) {\n\t\tif(paths->name[i].paths)\n\t\t\tfree_path(paths->name[i].paths);\n\t\tfree(paths->name[i].name);\n\t\tif(paths->name[i].preg) {\n\t\t\tregfree(paths->name[i].preg);\n\t\t\tfree(paths->name[i].preg);\n\t\t}\n\t}\n\n\tfree(paths);\n}\n\n\nstruct pathname *add_path(struct pathname *paths, char *target, char *alltarget)\n{\n\tchar targname[1024];\n\tint i, error;\n\n\tTRACE(\"add_path: adding \\\"%s\\\" extract file\\n\", target);\n\n\ttarget = get_component(target, targname);\n\n\tif(paths == NULL) {\n\t\tpaths = malloc(sizeof(struct pathname));\n\t\tif(paths == NULL)\n\t\t\tEXIT_UNSQUASH(\"failed to allocate paths\\n\");\n\n\t\tpaths->names = 0;\n\t\tpaths->name = NULL;\n\t}\n\n\tfor(i = 0; i < paths->names; i++)\n\t\tif(strcmp(paths->name[i].name, targname) == 0)\n\t\t\tbreak;\n\n\tif(i == paths->names) {\n\t\t/*\n\t\t * allocate new name entry\n\t\t */\n\t\tpaths->names ++;\n\t\tpaths->name = realloc(paths->name, (i + 1) *\n\t\t\tsizeof(struct path_entry));\n\t\tif(paths->name == NULL)\n\t\t\tEXIT_UNSQUASH(\"Out of memory in add_path\\n\");\t\n\t\tpaths->name[i].name = strdup(targname);\n\t\tpaths->name[i].paths = NULL;\n\t\tif(use_regex) {\n\t\t\tpaths->name[i].preg = malloc(sizeof(regex_t));\n\t\t\tif(paths->name[i].preg == NULL)\n\t\t\t\tEXIT_UNSQUASH(\"Out of memory in add_path\\n\");\n\t\t\terror = regcomp(paths->name[i].preg, targname,\n\t\t\t\tREG_EXTENDED|REG_NOSUB);\n\t\t\tif(error) {\n\t\t\t\tchar str[1024];\n\n\t\t\t\tregerror(error, paths->name[i].preg, str, 1024);\n\t\t\t\tEXIT_UNSQUASH(\"invalid regex %s in export %s, \"\n\t\t\t\t\t\"because %s\\n\", targname, alltarget,\n\t\t\t\t\tstr);\n\t\t\t}\n\t\t} else\n\t\t\tpaths->name[i].preg = NULL;\n\n\t\tif(target[0] == '\\0')\n\t\t\t/*\n\t\t\t * at leaf pathname component\n\t\t\t*/\n\t\t\tpaths->name[i].paths = NULL;\n\t\telse\n\t\t\t/*\n\t\t\t * recurse adding child components\n\t\t\t */\n\t\t\tpaths->name[i].paths = add_path(NULL, target, alltarget);\n\t} else {\n\t\t/*\n\t\t * existing matching entry\n\t\t */\n\t\tif(paths->name[i].paths == NULL) {\n\t\t\t/*\n\t\t\t * No sub-directory which means this is the leaf\n\t\t\t * component of a pre-existing extract which subsumes\n\t\t\t * the extract currently being added, in which case stop\n\t\t\t * adding components\n\t\t\t */\n\t\t} else if(target[0] == '\\0') {\n\t\t\t/*\n\t\t\t * at leaf pathname component and child components exist\n\t\t\t * from more specific extracts, delete as they're\n\t\t\t * subsumed by this extract\n\t\t\t */\n\t\t\tfree_path(paths->name[i].paths);\n\t\t\tpaths->name[i].paths = NULL;\n\t\t} else\n\t\t\t/*\n\t\t\t * recurse adding child components\n\t\t\t */\n\t\t\tadd_path(paths->name[i].paths, target, alltarget);\n\t}\n\n\treturn paths;\n}\n\n\nstruct pathnames *init_subdir()\n{\n\tstruct pathnames *new = malloc(sizeof(struct pathnames));\n\tif(new == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory in init_subdir\\n\");\n\tnew->count = 0;\n\treturn new;\n}\n\n\nstruct pathnames *add_subdir(struct pathnames *paths, struct pathname *path)\n{\n\tif(paths->count % PATHS_ALLOC_SIZE == 0) {\n\t\tpaths = realloc(paths, sizeof(struct pathnames *) +\n\t\t\t(paths->count + PATHS_ALLOC_SIZE) *\n\t\t\tsizeof(struct pathname *));\n\t\tif(paths == NULL)\n\t\t\tEXIT_UNSQUASH(\"Out of memory in add_subdir\\n\");\n\t}\n\n\tpaths->path[paths->count++] = path;\n\treturn paths;\n}\n\n\nvoid free_subdir(struct pathnames *paths)\n{\n\tfree(paths);\n}\n\n\nint matches(struct pathnames *paths, char *name, struct pathnames **new)\n{\n\tint i, n;\n\n\tif(paths == NULL) {\n\t\t*new = NULL;\n\t\treturn TRUE;\n\t}\n\n\t*new = init_subdir();\n\n\tfor(n = 0; n < paths->count; n++) {\n\t\tstruct pathname *path = paths->path[n];\n\t\tfor(i = 0; i < path->names; i++) {\n\t\t\tint match = use_regex ?\n\t\t\t\tregexec(path->name[i].preg, name, (size_t) 0,\n\t\t\t\tNULL, 0) == 0 : fnmatch(path->name[i].name,\n\t\t\t\tname, FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) ==\n\t\t\t\t0;\n\t\t\tif(match && path->name[i].paths == NULL)\n\t\t\t\t/*\n\t\t\t\t * match on a leaf component, any subdirectories\n\t\t\t\t * will implicitly match, therefore return an\n\t\t\t\t * empty new search set\n\t\t\t\t */\n\t\t\t\tgoto empty_set;\n\n\t\t\tif(match)\n\t\t\t\t/*\n\t\t\t\t * match on a non-leaf component, add any\n\t\t\t\t * subdirectories to the new set of\n\t\t\t\t * subdirectories to scan for this name\n\t\t\t\t */\n\t\t\t\t*new = add_subdir(*new, path->name[i].paths);\n\t\t}\n\t}\n\n\tif((*new)->count == 0) {\n\t\t/*\n\t\t * no matching names found, delete empty search set, and return\n\t\t * FALSE\n\t\t */\n\t\tfree_subdir(*new);\n\t\t*new = NULL;\n\t\treturn FALSE;\n\t}\n\n\t/*\n\t * one or more matches with sub-directories found (no leaf matches),\n\t * return new search set and return TRUE\n\t */\n\treturn TRUE;\n\nempty_set:\n\t/*\n\t * found matching leaf exclude, return empty search set and return TRUE\n\t */\n\tfree_subdir(*new);\n\t*new = NULL;\n\treturn TRUE;\n}\n\n\nvoid pre_scan(char *parent_name, unsigned int start_block, unsigned int offset,\n\tstruct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tstruct inode *i;\n\n\t\tTRACE(\"pre_scan: name %s, start_block %d, offset %d, type %d\\n\",\n\t\t\tname, start_block, offset, type);\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tpre_scan(parent_name, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\tif(type == SQUASHFS_FILE_TYPE ||\n\t\t\t\t\ttype == SQUASHFS_LREG_TYPE) {\n\t\t\t\ti = s_ops.read_inode(start_block, offset);\n\t\t\t\tif(created_inode[i->inode_number - 1] == NULL) {\n\t\t\t\t\tcreated_inode[i->inode_number - 1] =\n\t\t\t\t\t\t(char *) i;\n\t\t\t\t\ttotal_blocks += (i->data +\n\t\t\t\t\t\t(block_size - 1)) >> block_log;\n\t\t\t\t}\n\t\t\t\ttotal_files ++;\n\t\t\t}\n\t\t\ttotal_inodes ++;\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tsquashfs_closedir(dir);\n}\n\n\nvoid dir_scan(char *parent_name, unsigned int start_block, unsigned int offset,\n\tstruct pathnames *paths)\n{\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\tstruct pathnames *new;\n\tstruct inode *i;\n\tstruct dir *dir = s_ops.squashfs_opendir(start_block, offset, &i);\n\n\tif(lsonly || info)\n\t\tprint_filename(parent_name, i);\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1 &&\n\t\t\t(!force || errno != EEXIST)) {\n\t\tERROR(\"dir_scan: failed to make directory %s, because %s\\n\",\n\t\t\tparent_name, strerror(errno));\n\t\tsquashfs_closedir(dir);\n\t\treturn;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\",\n\t\t\tname, start_block, offset, type);\n\n\n\t\tif(!matches(paths, name, &new))\n\t\t\tcontinue;\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, new);\n\t\telse if(new == NULL) {\n\t\t\ti = s_ops.read_inode(start_block, offset);\n\n\t\t\tif(lsonly || info)\n\t\t\t\tprint_filename(pathname, i);\n\n\t\t\tif(!lsonly) {\n\t\t\t\tcreate_inode(pathname, i);\n\t\t\t\tupdate_progress_bar();\n\t\t\t\t}\n\n\t\t\tif(i->type == SQUASHFS_SYMLINK_TYPE ||\n\t\t\t\t\ti->type == SQUASHFS_LSYMLINK_TYPE)\n\t\t\t\tfree(i->symlink);\n\t\t}\n\n\t\tfree_subdir(new);\n\t}\n\n\tif(!lsonly)\n\t\tset_attributes(parent_name, dir->mode, dir->uid, dir->guid,\n\t\t\tdir->mtime, dir->xattr, force);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n}\n\n\nvoid squashfs_stat(char *source)\n{\n\ttime_t mkfs_time = (time_t) sBlk.s.mkfs_time;\n\tchar *mkfs_str = ctime(&mkfs_time);\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tprintf(\"Found a valid %sSQUASHFS %d:%d superblock on %s.\\n\",\n\t\tsBlk.s.s_major == 4 ? \"\" : swap ? \"little endian \" :\n\t\t\"big endian \", sBlk.s.s_major, sBlk.s.s_minor, source);\n#else\n\tprintf(\"Found a valid %sSQUASHFS %d:%d superblock on %s.\\n\",\n\t\tsBlk.s.s_major == 4 ? \"\" : swap ? \"big endian \" :\n\t\t\"little endian \", sBlk.s.s_major, sBlk.s.s_minor, source);\n#endif\n\n\tprintf(\"Creation or last append time %s\", mkfs_str ? mkfs_str :\n\t\t\"failed to get time\\n\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\",\n\t\tsBlk.s.bytes_used / 1024.0, sBlk.s.bytes_used /\n\t\t(1024.0 * 1024.0));\n\n\tif(sBlk.s.s_major == 4)\n\t\tprintf(\"Compression %s\\n\", comp->name);\n\n\tprintf(\"Block size %d\\n\", sBlk.s.block_size);\n\tprintf(\"Filesystem is %sexportable via NFS\\n\",\n\t\tSQUASHFS_EXPORTABLE(sBlk.s.flags) ? \"\" : \"not \");\n\tprintf(\"Inodes are %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_INODES(sBlk.s.flags) ? \"un\" : \"\");\n\tprintf(\"Data is %scompressed\\n\",\n\t\tSQUASHFS_UNCOMPRESSED_DATA(sBlk.s.flags) ? \"un\" : \"\");\n\n\tif(sBlk.s.s_major > 1) {\n\t\tif(SQUASHFS_NO_FRAGMENTS(sBlk.s.flags))\n\t\t\tprintf(\"Fragments are not stored\\n\");\n\t\telse {\n\t\t\tprintf(\"Fragments are %scompressed\\n\",\n\t\t\t\tSQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.s.flags) ?\n\t\t\t\t\"un\" : \"\");\n\t\t\tprintf(\"Always_use_fragments option is %sspecified\\n\",\n\t\t\t\tSQUASHFS_ALWAYS_FRAGMENTS(sBlk.s.flags) ? \"\" :\n\t\t\t\t\"not \");\n\t\t}\n\t}\n\n\tif(sBlk.s.s_major == 4) {\n\t\tif(SQUASHFS_NO_XATTRS(sBlk.s.flags))\n\t\t\tprintf(\"Xattrs are not stored\\n\");\n\t\telse\n\t\t\tprintf(\"Xattrs are %scompressed\\n\",\n\t\t\t\tSQUASHFS_UNCOMPRESSED_XATTRS(sBlk.s.flags) ?\n\t\t\t\t\"un\" : \"\");\n\t}\n\n\tif(sBlk.s.s_major < 4)\n\t\t\tprintf(\"Check data is %spresent in the filesystem\\n\",\n\t\t\t\tSQUASHFS_CHECK_DATA(sBlk.s.flags) ? \"\" :\n\t\t\t\t\"not \");\n\n\tif(sBlk.s.s_major > 1)\n\t\tprintf(\"Duplicates are %sremoved\\n\",\n\t\t\tSQUASHFS_DUPLICATES(sBlk.s.flags) ? \"\" : \"not \");\n\telse\n\t\tprintf(\"Duplicates are removed\\n\");\n\n\tif(sBlk.s.s_major > 1)\n\t\tprintf(\"Number of fragments %d\\n\", sBlk.s.fragments);\n\n\tprintf(\"Number of inodes %d\\n\", sBlk.s.inodes);\n\n\tif(sBlk.s.s_major == 4)\n\t\tprintf(\"Number of ids %d\\n\", sBlk.s.no_ids);\n\telse {\n\t\tprintf(\"Number of uids %d\\n\", sBlk.no_uids);\n\t\tprintf(\"Number of gids %d\\n\", sBlk.no_guids);\n\t}\n\n\tTRACE(\"sBlk.s.inode_table_start 0x%llx\\n\", sBlk.s.inode_table_start);\n\tTRACE(\"sBlk.s.directory_table_start 0x%llx\\n\",\n\t\tsBlk.s.directory_table_start);\n\n\tif(sBlk.s.s_major == 4) {\n\t\tTRACE(\"sBlk.s.id_table_start 0x%llx\\n\", sBlk.s.id_table_start);\n\t\tTRACE(\"sBlk.s.xattr_id_table_start 0x%llx\\n\",\n\t\t\tsBlk.s.xattr_id_table_start);\n\t} else {\n\t\tTRACE(\"sBlk.uid_start 0x%llx\\n\", sBlk.uid_start);\n\t\tTRACE(\"sBlk.guid_start 0x%llx\\n\", sBlk.guid_start);\n\t}\n\n\tif(sBlk.s.s_major > 1)\n\t\tTRACE(\"sBlk.s.fragment_table_start 0x%llx\\n\\n\",\n\t\t\tsBlk.s.fragment_table_start);\n}\n\n\nint read_super(char *source)\n{\n\tsquashfs_super_block_3 sBlk_3;\n\tstruct squashfs_super_block sBlk_4;\n\n\t/*\n\t * Try to read a Squashfs 4 superblock\n\t */\n\tread_fs_bytes(fd, SQUASHFS_START, sizeof(struct squashfs_super_block),\n\t\t&sBlk_4);\n\tswap = sBlk_4.s_magic != SQUASHFS_MAGIC;\n\tSQUASHFS_INSWAP_SUPER_BLOCK(&sBlk_4);\n\n\tif(sBlk_4.s_magic == SQUASHFS_MAGIC && sBlk_4.s_major == 4 &&\n\t\t\tsBlk_4.s_minor == 0) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir_4;\n\t\ts_ops.read_fragment = read_fragment_4;\n\t\ts_ops.read_fragment_table = read_fragment_table_4;\n\t\ts_ops.read_block_list = read_block_list_2;\n\t\ts_ops.read_inode = read_inode_4;\n\t\ts_ops.read_uids_guids = read_uids_guids_4;\n\t\tmemcpy(&sBlk, &sBlk_4, sizeof(sBlk_4));\n\n\t\t/*\n\t\t * Check the compression type\n\t\t */\n\t\tcomp = lookup_compressor_id(sBlk.s.compression);\n\t\treturn TRUE;\n\t}\n\n\t/*\n \t * Not a Squashfs 4 superblock, try to read a squashfs 3 superblock\n \t * (compatible with 1 and 2 filesystems)\n \t */\n\tread_fs_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block_3),\n\t\t&sBlk_3);\n\n\t/*\n\t * Check it is a SQUASHFS superblock\n\t */\n\tswap = 0;\n\tif(sBlk_3.s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk_3.s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block_3 sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem \"\n\t\t\t\t\"on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK_3(&sblk, &sBlk_3);\n\t\t\tmemcpy(&sBlk_3, &sblk, sizeof(squashfs_super_block_3));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\",\n\t\t\t\tsource);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\tsBlk.s.s_magic = sBlk_3.s_magic;\n\tsBlk.s.inodes = sBlk_3.inodes;\n\tsBlk.s.mkfs_time = sBlk_3.mkfs_time;\n\tsBlk.s.block_size = sBlk_3.block_size;\n\tsBlk.s.fragments = sBlk_3.fragments;\n\tsBlk.s.block_log = sBlk_3.block_log;\n\tsBlk.s.flags = sBlk_3.flags;\n\tsBlk.s.s_major = sBlk_3.s_major;\n\tsBlk.s.s_minor = sBlk_3.s_minor;\n\tsBlk.s.root_inode = sBlk_3.root_inode;\n\tsBlk.s.bytes_used = sBlk_3.bytes_used;\n\tsBlk.s.inode_table_start = sBlk_3.inode_table_start;\n\tsBlk.s.directory_table_start = sBlk_3.directory_table_start;\n\tsBlk.s.fragment_table_start = sBlk_3.fragment_table_start;\n\tsBlk.s.lookup_table_start = sBlk_3.lookup_table_start;\n\tsBlk.no_uids = sBlk_3.no_uids;\n\tsBlk.no_guids = sBlk_3.no_guids;\n\tsBlk.uid_start = sBlk_3.uid_start;\n\tsBlk.guid_start = sBlk_3.guid_start;\n\tsBlk.s.xattr_id_table_start = SQUASHFS_INVALID_BLK;\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk.s.s_major == 1 || sBlk.s.s_major == 2) {\n\t\tsBlk.s.bytes_used = sBlk_3.bytes_used_2;\n\t\tsBlk.uid_start = sBlk_3.uid_start_2;\n\t\tsBlk.guid_start = sBlk_3.guid_start_2;\n\t\tsBlk.s.inode_table_start = sBlk_3.inode_table_start_2;\n\t\tsBlk.s.directory_table_start = sBlk_3.directory_table_start_2;\n\t\t\n\t\tif(sBlk.s.s_major == 1) {\n\t\t\tsBlk.s.block_size = sBlk_3.block_size_1;\n\t\t\tsBlk.s.fragment_table_start = sBlk.uid_start;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_1;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_1;\n\t\t\ts_ops.read_block_list = read_block_list_1;\n\t\t\ts_ops.read_inode = read_inode_1;\n\t\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t\t} else {\n\t\t\tsBlk.s.fragment_table_start =\n\t\t\t\tsBlk_3.fragment_table_start_2;\n\t\t\ts_ops.squashfs_opendir = squashfs_opendir_1;\n\t\t\ts_ops.read_fragment = read_fragment_2;\n\t\t\ts_ops.read_fragment_table = read_fragment_table_2;\n\t\t\ts_ops.read_block_list = read_block_list_2;\n\t\t\ts_ops.read_inode = read_inode_2;\n\t\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t\t}\n\t} else if(sBlk.s.s_major == 3) {\n\t\ts_ops.squashfs_opendir = squashfs_opendir_3;\n\t\ts_ops.read_fragment = read_fragment_3;\n\t\ts_ops.read_fragment_table = read_fragment_table_3;\n\t\ts_ops.read_block_list = read_block_list_2;\n\t\ts_ops.read_inode = read_inode_3;\n\t\ts_ops.read_uids_guids = read_uids_guids_1;\n\t} else {\n\t\tERROR(\"Filesystem on %s is (%d:%d), \", source, sBlk.s.s_major,\n\t\t\tsBlk.s.s_minor);\n\t\tERROR(\"which is a later filesystem version than I support!\\n\");\n\t\tgoto failed_mount;\n\t}\n\n\t/*\n\t * 1.x, 2.x and 3.x filesystems use gzip compression.\n\t */\n\tcomp = lookup_compressor(\"gzip\");\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nstruct pathname *process_extract_files(struct pathname *path, char *filename)\n{\n\tFILE *fd;\n\tchar name[16384];\n\n\tfd = fopen(filename, \"r\");\n\tif(fd == NULL)\n\t\tEXIT_UNSQUASH(\"Could not open %s, because %s\\n\", filename,\n\t\t\tstrerror(errno));\n\n\twhile(fscanf(fd, \"%16384[^\\n]\\n\", name) != EOF)\n\t\tpath = add_path(path, name, name);\n\n\tfclose(fd);\n\treturn path;\n}\n\t\t\n\n/*\n * reader thread.  This thread processes read requests queued by the\n * cache_get() routine.\n */\nvoid *reader(void *arg)\n{\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_reader);\n\t\tint res = read_fs_bytes(fd, entry->block,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size),\n\t\t\tentry->data);\n\n\t\tif(res && SQUASHFS_COMPRESSED_BLOCK(entry->size))\n\t\t\t/*\n\t\t\t * queue successfully read block to the deflate\n\t\t\t * thread(s) for further processing\n \t\t\t */\n\t\t\tqueue_put(to_deflate, entry);\n\t\telse\n\t\t\t/*\n\t\t\t * block has either been successfully read and is\n\t\t\t * uncompressed, or an error has occurred, clear pending\n\t\t\t * flag, set error appropriately, and wake up any\n\t\t\t * threads waiting on this buffer\n\t\t\t */\n\t\t\tcache_block_ready(entry, !res);\n\t}\n}\n\n\n/*\n * writer thread.  This processes file write requests queued by the\n * write_file() routine.\n */\nvoid *writer(void *arg)\n{\n\tint i;\n\n\twhile(1) {\n\t\tstruct squashfs_file *file = queue_get(to_writer);\n\t\tint file_fd;\n\t\tlong long hole = 0;\n\t\tint failed = FALSE;\n\t\tint error;\n\n\t\tif(file == NULL) {\n\t\t\tqueue_put(from_writer, NULL);\n\t\t\tcontinue;\n\t\t}\n\n\t\tTRACE(\"writer: regular file, blocks %d\\n\", file->blocks);\n\n\t\tfile_fd = file->fd;\n\n\t\tfor(i = 0; i < file->blocks; i++, cur_blocks ++) {\n\t\t\tstruct file_entry *block = queue_get(to_writer);\n\n\t\t\tif(block->buffer == 0) { /* sparse file */\n\t\t\t\thole += block->size;\n\t\t\t\tfree(block);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcache_block_wait(block->buffer);\n\n\t\t\tif(block->buffer->error)\n\t\t\t\tfailed = TRUE;\n\n\t\t\tif(failed)\n\t\t\t\tcontinue;\n\n\t\t\terror = write_block(file_fd, block->buffer->data +\n\t\t\t\tblock->offset, block->size, hole, file->sparse);\n\n\t\t\tif(error == FALSE) {\n\t\t\t\tERROR(\"writer: failed to write data block %d\\n\",\n\t\t\t\t\ti);\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\n\t\t\thole = 0;\n\t\t\tcache_block_put(block->buffer);\n\t\t\tfree(block);\n\t\t}\n\n\t\tif(hole && failed == FALSE) {\n\t\t\t/*\n\t\t\t * corner case for hole extending to end of file\n\t\t\t */\n\t\t\tif(file->sparse == FALSE ||\n\t\t\t\t\tlseek(file_fd, hole, SEEK_CUR) == -1) {\n\t\t\t\t/*\n\t\t\t\t * for files which we don't want to write\n\t\t\t\t * sparsely, or for broken lseeks which cannot\n\t\t\t\t * seek beyond end of file, write_block will do\n\t\t\t\t * the right thing\n\t\t\t\t */\n\t\t\t\thole --;\n\t\t\t\tif(write_block(file_fd, \"\\0\", 1, hole,\n\t\t\t\t\t\tfile->sparse) == FALSE) {\n\t\t\t\t\tERROR(\"writer: failed to write sparse \"\n\t\t\t\t\t\t\"data block\\n\");\n\t\t\t\t\tfailed = TRUE;\n\t\t\t\t}\n\t\t\t} else if(ftruncate(file_fd, file->file_size) == -1) {\n\t\t\t\tERROR(\"writer: failed to write sparse data \"\n\t\t\t\t\t\"block\\n\");\n\t\t\t\tfailed = TRUE;\n\t\t\t}\n\t\t}\n\n\t\tclose(file_fd);\n\t\tif(failed == FALSE)\n\t\t\tset_attributes(file->pathname, file->mode, file->uid,\n\t\t\t\tfile->gid, file->time, file->xattr, force);\n\t\telse {\n\t\t\tERROR(\"Failed to write %s, skipping\\n\", file->pathname);\n\t\t\tunlink(file->pathname);\n\t\t}\n\t\tfree(file->pathname);\n\t\tfree(file);\n\n\t}\n}\n\n\n/*\n * decompress thread.  This decompresses buffers queued by the read thread\n */\nvoid *deflator(void *arg)\n{\n\tchar tmp[block_size];\n\n\twhile(1) {\n\t\tstruct cache_entry *entry = queue_get(to_deflate);\n\t\tint error, res;\n\n\t\tres = compressor_uncompress(comp, tmp, entry->data,\n\t\t\tSQUASHFS_COMPRESSED_SIZE_BLOCK(entry->size), block_size,\n\t\t\t&error);\n\n\t\tif(res == -1)\n\t\t\tERROR(\"%s uncompress failed with error code %d\\n\",\n\t\t\t\tcomp->name, error);\n\t\telse\n\t\t\tmemcpy(entry->data, tmp, res);\n\n\t\t/*\n\t\t * block has been either successfully decompressed, or an error\n \t\t * occurred, clear pending flag, set error appropriately and\n \t\t * wake up any threads waiting on this block\n \t\t */ \n\t\tcache_block_ready(entry, res == -1);\n\t}\n}\n\n\nvoid *progress_thread(void *arg)\n{\n\tstruct timeval timeval;\n\tstruct timespec timespec;\n\tstruct itimerval itimerval;\n\tstruct winsize winsize;\n\n\tif(ioctl(1, TIOCGWINSZ, &winsize) == -1) {\n\t\tif(isatty(STDOUT_FILENO))\n\t\t\tERROR(\"TIOCGWINSZ ioctl failed, defaulting to 80 \"\n\t\t\t\t\"columns\\n\");\n\t\tcolumns = 80;\n\t} else\n\t\tcolumns = winsize.ws_col;\n\tsignal(SIGWINCH, sigwinch_handler);\n\tsignal(SIGALRM, sigalrm_handler);\n\n\titimerval.it_value.tv_sec = 0;\n\titimerval.it_value.tv_usec = 250000;\n\titimerval.it_interval.tv_sec = 0;\n\titimerval.it_interval.tv_usec = 250000;\n\tsetitimer(ITIMER_REAL, &itimerval, NULL);\n\n\tpthread_cond_init(&progress_wait, NULL);\n\n\tpthread_mutex_lock(&screen_mutex);\n\twhile(1) {\n\t\tgettimeofday(&timeval, NULL);\n\t\ttimespec.tv_sec = timeval.tv_sec;\n\t\tif(timeval.tv_usec + 250000 > 999999)\n\t\t\ttimespec.tv_sec++;\n\t\ttimespec.tv_nsec = ((timeval.tv_usec + 250000) % 1000000) *\n\t\t\t1000;\n\t\tpthread_cond_timedwait(&progress_wait, &screen_mutex,\n\t\t\t&timespec);\n\t\tif(progress_enabled)\n\t\t\tprogress_bar(sym_count + dev_count +\n\t\t\t\tfifo_count + cur_blocks, total_inodes -\n\t\t\t\ttotal_files + total_blocks, columns);\n\t}\n}\n\n\nvoid initialise_threads(int fragment_buffer_size, int data_buffer_size)\n{\n\tint i;\n\tsigset_t sigmask, old_mask;\n\tint all_buffers_size = fragment_buffer_size + data_buffer_size;\n\n\tsigemptyset(&sigmask);\n\tsigaddset(&sigmask, SIGINT);\n\tsigaddset(&sigmask, SIGQUIT);\n\tif(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\"\n\t\t\t\"\\n\");\n\n\tif(processors == -1) {\n#ifndef linux\n\t\tint mib[2];\n\t\tsize_t len = sizeof(processors);\n\n\t\tmib[0] = CTL_HW;\n#ifdef HW_AVAILCPU\n\t\tmib[1] = HW_AVAILCPU;\n#else\n\t\tmib[1] = HW_NCPU;\n#endif\n\n\t\tif(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {\n\t\t\tERROR(\"Failed to get number of available processors.  \"\n\t\t\t\t\"Defaulting to 1\\n\");\n\t\t\tprocessors = 1;\n\t\t}\n#else\n\t\tprocessors = sysconf(_SC_NPROCESSORS_ONLN);\n#endif\n\t}\n\n\tthread = malloc((3 + processors) * sizeof(pthread_t));\n\tif(thread == NULL)\n\t\tEXIT_UNSQUASH(\"Out of memory allocating thread descriptors\\n\");\n\tdeflator_thread = &thread[3];\n\n\tto_reader = queue_init(all_buffers_size);\n\tto_deflate = queue_init(all_buffers_size);\n\tto_writer = queue_init(1000);\n\tfrom_writer = queue_init(1);\n\tfragment_cache = cache_init(block_size, fragment_buffer_size);\n\tdata_cache = cache_init(block_size, data_buffer_size);\n\tpthread_create(&thread[0], NULL, reader, NULL);\n\tpthread_create(&thread[1], NULL, writer, NULL);\n\tpthread_create(&thread[2], NULL, progress_thread, NULL);\n\tpthread_mutex_init(&fragment_mutex, NULL);\n\n\tfor(i = 0; i < processors; i++) {\n\t\tif(pthread_create(&deflator_thread[i], NULL, deflator, NULL) !=\n\t\t\t\t 0)\n\t\t\tEXIT_UNSQUASH(\"Failed to create thread\\n\");\n\t}\n\n\tprintf(\"Parallel unsquashfs: Using %d processor%s\\n\", processors,\n\t\t\tprocessors == 1 ? \"\" : \"s\");\n\n\tif(sigprocmask(SIG_SETMASK, &old_mask, NULL) == -1)\n\t\tEXIT_UNSQUASH(\"Failed to set signal mask in intialise_threads\"\n\t\t\t\"\\n\");\n}\n\n\nvoid enable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = TRUE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid disable_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tprogress_enabled = FALSE;\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid update_progress_bar()\n{\n\tpthread_mutex_lock(&screen_mutex);\n\tpthread_cond_signal(&progress_wait);\n\tpthread_mutex_unlock(&screen_mutex);\n}\n\n\nvoid progress_bar(long long current, long long max, int columns)\n{\n\tchar rotate_list[] = { '|', '/', '-', '\\\\' };\n\tint max_digits, used, hashes, spaces;\n\tstatic int tty = -1;\n\n\tif(max == 0)\n\t\treturn;\n\n\tmax_digits = floor(log10(max)) + 1;\n\tused = max_digits * 2 + 11;\n\thashes = (current * (columns - used)) / max;\n\tspaces = columns - used - hashes;\n\n\tif((current > max) || (columns - used < 0))\n\t\treturn;\n\n\tif(tty == -1)\n\t\ttty = isatty(STDOUT_FILENO);\n\tif(!tty) {\n\t\tstatic long long previous = -1;\n\n\t\t/*\n\t\t * Updating much more frequently than this results in huge\n\t\t * log files.\n\t\t */\n\t\tif((current % 100) != 0 && current != max)\n\t\t\treturn;\n\t\t/* Don't update just to rotate the spinner. */\n\t\tif(current == previous)\n\t\t\treturn;\n\t\tprevious = current;\n\t}\n\n\tprintf(\"\\r[\");\n\n\twhile (hashes --)\n\t\tputchar('=');\n\n\tputchar(rotate_list[rotate]);\n\n\twhile(spaces --)\n\t\tputchar(' ');\n\n\tprintf(\"] %*lld/%*lld\", max_digits, current, max_digits, max);\n\tprintf(\" %3lld%%\", current * 100 / max);\n\tfflush(stdout);\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 4.2 (2011/02/28)\\n\");\\\n\tprintf(\"copyright (C) 2011 Phillip Lougher \"\\\n\t\t\"<phillip@lougher.demon.co.uk>\\n\\n\");\\\n    \tprintf(\"This program is free software; you can redistribute it and/or\"\\\n\t\t\"\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\"\\\n\t\t\"\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version \"\\\n\t\t\"2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be \"\\\n\t\t\"useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\"\\\n\t\t\"\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\"\\\n\t\t\"\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tchar *dest = \"squashfs-root\";\n\tint i, stat_sys = FALSE, version = FALSE;\n\tint n;\n\tstruct pathnames *paths = NULL;\n\tstruct pathname *path = NULL;\n\tint fragment_buffer_size = FRAGMENT_BUFFER_DEFAULT;\n\tint data_buffer_size = DATA_BUFFER_DEFAULT;\n\tchar *b;\n\n\tpthread_mutex_init(&screen_mutex, NULL);\n\troot_process = geteuid() == 0;\n\tif(root_process)\n\t\tumask(0);\n\t\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-v\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-i\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-l\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-no-progress\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-n\") == 0)\n\t\t\tprogress = FALSE;\n\t\telse if(strcmp(argv[i], \"-no-xattrs\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-no\") == 0)\n\t\t\tno_xattrs = TRUE;\n\t\telse if(strcmp(argv[i], \"-xattrs\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-x\") == 0)\n\t\t\tno_xattrs = FALSE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-d\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -dest missing filename\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdest = argv[i];\n\t\t} else if(strcmp(argv[i], \"-processors\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-p\") == 0) {\n\t\t\tif((++i == argc) || \n\t\t\t\t\t(processors = strtol(argv[i], &b, 10),\n\t\t\t\t\t*b != '\\0')) {\n\t\t\t\tERROR(\"%s: -processors missing or invalid \"\n\t\t\t\t\t\"processor number\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(processors < 1) {\n\t\t\t\tERROR(\"%s: -processors should be 1 or larger\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-data-queue\") == 0 ||\n\t\t\t\t\t strcmp(argv[i], \"-da\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(data_buffer_size = strtol(argv[i], &b,\n\t\t\t\t\t 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -data-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(data_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -data-queue should be 1 Mbyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-frag-queue\") == 0 ||\n\t\t\t\t\tstrcmp(argv[i], \"-fr\") == 0) {\n\t\t\tif((++i == argc) ||\n\t\t\t\t\t(fragment_buffer_size = strtol(argv[i],\n\t\t\t\t\t &b, 10), *b != '\\0')) {\n\t\t\t\tERROR(\"%s: -frag-queue missing or invalid \"\n\t\t\t\t\t\"queue size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif(fragment_buffer_size < 1) {\n\t\t\t\tERROR(\"%s: -frag-queue should be 1 Mbyte or \"\n\t\t\t\t\t\"larger\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-f\") == 0)\n\t\t\tforce = TRUE;\n\t\telse if(strcmp(argv[i], \"-stat\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-s\") == 0)\n\t\t\tstat_sys = TRUE;\n\t\telse if(strcmp(argv[i], \"-lls\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-ll\") == 0) {\n\t\t\tlsonly = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-linfo\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-li\") == 0) {\n\t\t\tinfo = TRUE;\n\t\t\tshort_ls = FALSE;\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-e\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tfprintf(stderr, \"%s: -ef missing filename\\n\",\n\t\t\t\t\targv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tpath = process_extract_files(path, argv[i]);\n\t\t} else if(strcmp(argv[i], \"-regex\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-r\") == 0)\n\t\t\tuse_regex = TRUE;\n\t\telse\n\t\t\tgoto options;\n\t}\n\n\tif(lsonly || info)\n\t\tprogress = FALSE;\n\n#ifdef SQUASHFS_TRACE\n\tprogress = FALSE;\n#endif\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [options] filesystem [directories or \"\n\t\t\t\t\"files to extract]\\n\", argv[0]);\n\t\t\tERROR(\"\\t-v[ersion]\\t\\tprint version, licence and \"\n\t\t\t\t\"copyright information\\n\");\n\t\t\tERROR(\"\\t-d[est] <pathname>\\tunsquash to <pathname>, \"\n\t\t\t\t\"default \\\"squashfs-root\\\"\\n\");\n\t\t\tERROR(\"\\t-n[o-progress]\\t\\tdon't display the progress \"\n\t\t\t\t\"bar\\n\");\n\t\t\tERROR(\"\\t-no[-xattrs]\\t\\tdon't extract xattrs in file system\"\n\t\t\t\tNOXOPT_STR\"\\n\");\n\t\t\tERROR(\"\\t-x[attrs]\\t\\textract xattrs in file system\"\n\t\t\t\tXOPT_STR \"\\n\");\n\t\t\tERROR(\"\\t-p[rocessors] <number>\\tuse <number> \"\n\t\t\t\t\"processors.  By default will use\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tnumber of processors available\\n\");\n\t\t\tERROR(\"\\t-i[nfo]\\t\\t\\tprint files as they are \"\n\t\t\t\t\"unsquashed\\n\");\n\t\t\tERROR(\"\\t-li[nfo]\\t\\tprint files as they are \"\n\t\t\t\t\"unsquashed with file\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tattributes (like ls -l output)\\n\");\n\t\t\tERROR(\"\\t-l[s]\\t\\t\\tlist filesystem, but don't unsquash\"\n\t\t\t\t\"\\n\");\n\t\t\tERROR(\"\\t-ll[s]\\t\\t\\tlist filesystem with file \"\n\t\t\t\t\"attributes (like\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\tls -l output), but don't unsquash\\n\");\n\t\t\tERROR(\"\\t-f[orce]\\t\\tif file already exists then \"\n\t\t\t\t\"overwrite\\n\");\n\t\t\tERROR(\"\\t-s[tat]\\t\\t\\tdisplay filesystem superblock \"\n\t\t\t\t\"information\\n\");\n\t\t\tERROR(\"\\t-e[f] <extract file>\\tlist of directories or \"\n\t\t\t\t\"files to extract.\\n\\t\\t\\t\\tOne per line\\n\");\n\t\t\tERROR(\"\\t-da[ta-queue] <size>\\tSet data queue to \"\n\t\t\t\t\"<size> Mbytes.  Default %d\\n\\t\\t\\t\\tMbytes\\n\",\n\t\t\t\tDATA_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-fr[ag-queue] <size>\\tSet fragment queue to \"\n\t\t\t\t\"<size> Mbytes.  Default\\n\\t\\t\\t\\t%d Mbytes\\n\",\n\t\t\t\tFRAGMENT_BUFFER_DEFAULT);\n\t\t\tERROR(\"\\t-r[egex]\\t\\ttreat extract names as POSIX \"\n\t\t\t\t\"regular expressions\\n\");\n\t\t\tERROR(\"\\t\\t\\t\\trather than use the default shell \"\n\t\t\t\t\"wildcard\\n\\t\\t\\t\\texpansion (globbing)\\n\");\n\t\t\tERROR(\"\\nDecompressors available:\\n\");\n\t\t\tdisplay_compressors(\"\", \"\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tfor(n = i + 1; n < argc; n++)\n\t\tpath = add_path(path, argv[n], argv[n]);\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i],\n\t\t\tstrerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(argv[i]) == FALSE)\n\t\texit(1);\n\n\tif(stat_sys) {\n\t\tsquashfs_stat(argv[i]);\n\t\texit(0);\n\t}\n\n\tif(!comp->supported) {\n\t\tERROR(\"Filesystem uses %s compression, this is \"\n\t\t\t\"unsupported by this version\\n\", comp->name);\n\t\tERROR(\"Decompressors available:\\n\");\n\t\tdisplay_compressors(\"\", \"\");\n\t\texit(1);\n\t}\n\n\tblock_size = sBlk.s.block_size;\n\tblock_log = sBlk.s.block_log;\n\n\tfragment_buffer_size <<= 20 - block_log;\n\tdata_buffer_size <<= 20 - block_log;\n\tinitialise_threads(fragment_buffer_size, data_buffer_size);\n\n\tfragment_data = malloc(block_size);\n\tif(fragment_data == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tfile_data = malloc(block_size);\n\tif(file_data == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tdata = malloc(block_size);\n\tif(data == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate data\\n\");\n\n\tcreated_inode = malloc(sBlk.s.inodes * sizeof(char *));\n\tif(created_inode == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.s.inodes * sizeof(char *));\n\n\tif(s_ops.read_uids_guids() == FALSE)\n\t\tEXIT_UNSQUASH(\"failed to uid/gid table\\n\");\n\n\tif(s_ops.read_fragment_table() == FALSE)\n\t\tEXIT_UNSQUASH(\"failed to read fragment table\\n\");\n\n\tuncompress_inode_table(sBlk.s.inode_table_start,\n\t\tsBlk.s.directory_table_start);\n\n\tuncompress_directory_table(sBlk.s.directory_table_start,\n\t\tsBlk.s.fragment_table_start);\n\n\tif(no_xattrs)\n\t\tsBlk.s.xattr_id_table_start = SQUASHFS_INVALID_BLK;\n\n\tif(read_xattrs_from_disk(fd, &sBlk.s) == 0)\n\t\tEXIT_UNSQUASH(\"failed to read the xattr table\\n\");\n\n\tif(path) {\n\t\tpaths = init_subdir();\n\t\tpaths = add_subdir(paths, path);\n\t}\n\n\tpre_scan(dest, SQUASHFS_INODE_BLK(sBlk.s.root_inode),\n\t\tSQUASHFS_INODE_OFFSET(sBlk.s.root_inode), paths);\n\n\tmemset(created_inode, 0, sBlk.s.inodes * sizeof(char *));\n\tinode_number = 1;\n\n\tprintf(\"%d inodes (%d blocks) to write\\n\\n\", total_inodes,\n\t\ttotal_inodes - total_files + total_blocks);\n\n\tif(progress)\n\t\tenable_progress_bar();\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.s.root_inode),\n\t\tSQUASHFS_INODE_OFFSET(sBlk.s.root_inode), paths);\n\n\tqueue_put(to_writer, NULL);\n\tqueue_get(from_writer);\n\n\tif(progress) {\n\t\tdisable_progress_bar();\n\t\tprogress_bar(sym_count + dev_count + fifo_count + cur_blocks,\n\t\t\ttotal_inodes - total_files + total_blocks, columns);\n\t}\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/unsquashfs.h",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs.h\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <sys/mman.h>\n#include <utime.h>\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <regex.h>\n#include <fnmatch.h>\n#include <signal.h>\n#include <pthread.h>\n#include <math.h>\n#include <sys/ioctl.h>\n#include <sys/time.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include \"squashfs_fs.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tprintf(\"\\n\"); \\\n\t\t\tprintf(\"unsquashfs: \"s, ## args); \\\n\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\tif(progress_enabled) \\\n\t\t\t\tfprintf(stderr, \"\\n\"); \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...) \\\n\t\tdo { \\\n\t\t\tpthread_mutex_lock(&screen_mutex); \\\n\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\tpthread_mutex_unlock(&screen_mutex);\\\n\t\t\texit(1); \\\n\t\t} while(0)\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\n/*\n * Unified superblock containing fields for all superblocks\n */\nstruct super_block {\n\tstruct squashfs_super_block s;\n\t/* fields only used by squashfs 3 and earlier layouts */\n\tunsigned int\t\tno_uids;\n\tunsigned int\t\tno_guids;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n};\n\nstruct hash_table_entry {\n\tlong long\tstart;\n\tint\t\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nstruct inode {\n\tint blocks;\n\tchar *block_ptr;\n\tlong long data;\n\tint fragment;\n\tint frag_bytes;\n\tgid_t gid;\n\tint inode_number;\n\tint mode;\n\tint offset;\n\tlong long start;\n\tchar *symlink;\n\ttime_t time;\n\tint type;\n\tuid_t uid;\n\tchar sparse;\n\tunsigned int xattr;\n};\n\ntypedef struct squashfs_operations {\n\tstruct dir *(*squashfs_opendir)(unsigned int block_start,\n\t\tunsigned int offset, struct inode **i);\n\tvoid (*read_fragment)(unsigned int fragment, long long *start_block,\n\t\tint *size);\n\tint (*read_fragment_table)();\n\tvoid (*read_block_list)(unsigned int *block_list, char *block_ptr,\n\t\tint blocks);\n\tstruct inode *(*read_inode)(unsigned int start_block,\n\t\tunsigned int offset);\n\tint (*read_uids_guids)();\n} squashfs_operations;\n\nstruct test {\n\tint mask;\n\tint value;\n\tint position;\n\tchar mode;\n};\n\n\n/* Cache status struct.  Caches are used to keep\n  track of memory buffers passed between different threads */\nstruct cache {\n\tint\tmax_buffers;\n\tint\tcount;\n\tint\tbuffer_size;\n\tint\twait_free;\n\tint\twait_pending;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t wait_for_free;\n\tpthread_cond_t wait_for_pending;\n\tstruct cache_entry *free_list;\n\tstruct cache_entry *hash_table[65536];\n};\n\n/* struct describing a cache entry passed between threads */\nstruct cache_entry {\n\tstruct cache *cache;\n\tlong long block;\n\tint\tsize;\n\tint\tused;\n\tint error;\n\tint\tpending;\n\tstruct cache_entry *hash_next;\n\tstruct cache_entry *hash_prev;\n\tstruct cache_entry *free_next;\n\tstruct cache_entry *free_prev;\n\tchar *data;\n};\n\n/* struct describing queues used to pass data between threads */\nstruct queue {\n\tint\tsize;\n\tint\treadp;\n\tint\twritep;\n\tpthread_mutex_t\tmutex;\n\tpthread_cond_t empty;\n\tpthread_cond_t full;\n\tvoid **data;\n};\n\n/* default size of fragment buffer in Mbytes */\n#define FRAGMENT_BUFFER_DEFAULT 256\n/* default size of data buffer in Mbytes */\n#define DATA_BUFFER_DEFAULT 256\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tuid_t\t\tuid;\n\tgid_t\t\tguid;\n\tunsigned int\tmtime;\n\tunsigned int xattr;\n\tstruct dir_ent\t*dirs;\n};\n\nstruct file_entry {\n\tint offset;\n\tint size;\n\tstruct cache_entry *buffer;\n};\n\n\nstruct squashfs_file {\n\tint fd;\n\tint blocks;\n\tlong long file_size;\n\tint mode;\n\tuid_t uid;\n\tgid_t gid;\n\ttime_t time;\n\tchar *pathname;\n\tchar sparse;\n\tunsigned int xattr;\n};\n\nstruct path_entry {\n\tchar *name;\n\tregex_t *preg;\n\tstruct pathname *paths;\n};\n\nstruct pathname {\n\tint names;\n\tstruct path_entry *name;\n};\n\nstruct pathnames {\n\tint count;\n\tstruct pathname *path[0];\n};\n#define PATHS_ALLOC_SIZE 10\n\n/* globals */\nextern struct super_block sBlk;\nextern squashfs_operations s_ops;\nextern int swap;\nextern char *inode_table, *directory_table;\nextern struct hash_table_entry *inode_table_hash[65536],\n\t*directory_table_hash[65536];\nextern unsigned int *uid_table, *guid_table;\nextern pthread_mutex_t screen_mutex;\nextern int progress_enabled;\nextern int inode_number;\nextern int lookup_type[];\nextern int fd;\n\n/* unsquashfs.c */\nextern int lookup_entry(struct hash_table_entry **, long long);\nextern int read_fs_bytes(int fd, long long, int, void *);\nextern int read_block(int, long long, long long *, void *);\n\n/* unsquash-1.c */\nextern void read_block_list_1(unsigned int *, char *, int);\nextern int read_fragment_table_1();\nextern struct inode *read_inode_1(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_1(unsigned int, unsigned int,\n\tstruct inode **);\nextern int read_uids_guids_1();\n\n/* unsquash-2.c */\nextern void read_block_list_2(unsigned int *, char *, int);\nextern int read_fragment_table_2();\nextern void read_fragment_2(unsigned int, long long *, int *);\nextern struct inode *read_inode_2(unsigned int, unsigned int);\n\n/* unsquash-3.c */\nextern int read_fragment_table_3();\nextern void read_fragment_3(unsigned int, long long *, int *);\nextern struct inode *read_inode_3(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_3(unsigned int, unsigned int,\n\tstruct inode **);\n\n/* unsquash-4.c */\nextern int read_fragment_table_4();\nextern void read_fragment_4(unsigned int, long long *, int *);\nextern struct inode *read_inode_4(unsigned int, unsigned int);\nextern struct dir *squashfs_opendir_4(unsigned int, unsigned int,\n\tstruct inode **);\nextern int read_uids_guids_4();\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/unsquashfs_xattr.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquashfs_xattr.c\n */\n\n#include \"unsquashfs.h\"\n#include \"xattr.h\"\n\n#include <sys/xattr.h>\n\nextern int root_process;\n\nvoid write_xattr(char *pathname, unsigned int xattr)\n{\n\tunsigned int count;\n\tstruct xattr_list *xattr_list;\n\tint i;\n\n\tif(xattr == SQUASHFS_INVALID_XATTR ||\n\t\t\tsBlk.s.xattr_id_table_start == SQUASHFS_INVALID_BLK)\n\t\treturn;\n\n\txattr_list = get_xattr(xattr, &count);\n\tif(xattr_list == NULL) {\n\t\tERROR(\"Failed to read xattrs for file %s\\n\", pathname);\n\t\treturn;\n\t}\n\n\tfor(i = 0; i < count; i++) {\n\t\tint prefix = xattr_list[i].type & SQUASHFS_XATTR_PREFIX_MASK;\n\n\t\tif(root_process || prefix == SQUASHFS_XATTR_USER) {\n\t\t\tint res = lsetxattr(pathname, xattr_list[i].full_name,\n\t\t\t\txattr_list[i].value, xattr_list[i].vsize, 0);\n\n\t\t\tif(res == -1)\n\t\t\t\tERROR(\"write_xattr: failed to write xattr %s\"\n\t\t\t\t\t\" for file %s because %s\\n\",\n\t\t\t\t\txattr_list[i].full_name, pathname,\n\t\t\t\t\terrno == ENOSPC || errno == EDQUOT ?\n\t\t\t\t\t\"no extended attribute space remaining \"\n\t\t\t\t\t\"on destination filesystem\" :\n\t\t\t\t\terrno == ENOTSUP ?\n\t\t\t\t\t\"extended attributes are not supported \"\n\t\t\t\t\t\"by the destination filesystem\" :\n\t\t\t\t\t\"a weird error occurred\");\n\t\t} else\n\t\t\tERROR(\"write_xattr: could not write xattr %s \"\n\t\t\t\t\t\"for file %s because you're not \"\n\t\t\t\t\t\"superuser!\\n\",\n\t\t\t\t\txattr_list[i].full_name, pathname);\n\t}\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/xattr.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2008, 2009, 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * xattr.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n#include <sys/xattr.h>\n\n#include \"squashfs_fs.h\"\n#include \"squashfs_swap.h\"\n#include \"mksquashfs.h\"\n#include \"xattr.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...) \\\n\t\tdo { \\\n\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...) \\\n\t\tdo { \\\n\t\t\tfprintf(stderr, s, ## args); \\\n\t\t} while(0)\n\n/* compressed xattr table */\nstatic char *xattr_table = NULL;\nstatic unsigned int xattr_size = 0;\n\n/* cached uncompressed xattr data */\nstatic char *data_cache = NULL;\nstatic int cache_bytes = 0, cache_size = 0;\n\n/* cached uncompressed xattr id table */\nstatic struct squashfs_xattr_id *xattr_id_table = NULL;\nstatic int xattr_ids = 0;\n\n/* saved compressed xattr table */\nunsigned int sxattr_bytes = 0, stotal_xattr_bytes = 0;\n\n/* saved cached uncompressed xattr data */\nstatic char *sdata_cache = NULL;\nstatic int scache_bytes = 0;\n\n/* saved cached uncompressed xattr id table */\nstatic int sxattr_ids = 0;\n\n/* xattr hash table for value duplicate detection */\nstatic struct xattr_list *dupl[65536];\n\n/* xattr hash table for id duplicate detection */\nstatic struct dupl_id *dupl_id[65536];\n\n/* file system globals from mksquashfs.c */\nextern int no_xattrs, noX;\nextern long long bytes;\nextern int fd;\nextern unsigned int xattr_bytes, total_xattr_bytes;\n\n/* helper functions from mksquashfs.c */\nextern unsigned short get_checksum(char *, int, unsigned short);\nextern void write_destination(int, long long, int, void *);\nextern long long generic_write_table(int, void *, int, void *, int);\nextern int mangle(char *, char *, int, int, int, int);\n\n/* helper functions and definitions from read_xattrs.c */\nextern int read_xattrs_from_disk(int, struct squashfs_super_block *);\nextern struct xattr_list *get_xattr(int, unsigned int *);\nextern struct prefix prefix_table[];\n\n\nstatic int get_prefix(struct xattr_list *xattr, char *name)\n{\n\tint i;\n\n\txattr->full_name = strdup(name);\n\n\tfor(i = 0; prefix_table[i].type != -1; i++) {\n\t\tstruct prefix *p = &prefix_table[i];\n\t\tif(strncmp(xattr->full_name, p->prefix, strlen(p->prefix)) == 0)\n\t\t\tbreak;\n\t}\n\n\tif(prefix_table[i].type != -1) {\n\t\txattr->name = xattr->full_name + strlen(prefix_table[i].prefix);\n\t\txattr->size = strlen(xattr->name);\n\t}\n\n\treturn prefix_table[i].type;\n}\n\n\t\nstatic int read_xattrs_from_system(char *filename, struct xattr_list **xattrs)\n{\n\tssize_t size, vsize;\n\tchar *xattr_names, *p;\n\tint i;\n\tstruct xattr_list *xattr_list = NULL;\n\n\twhile(1) {\n\t\tsize = llistxattr(filename, NULL, 0);\n\t\tif(size <= 0) {\n\t\t\tif(size < 0 && errno != ENOTSUP)\n\t\t\t\tERROR(\"llistxattr for %s failed in read_attrs,\"\n\t\t\t\t\t\" because %s\\n\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\treturn 0;\n\t\t}\n\n\t\txattr_names = malloc(size);\n\t\tif(xattr_names == NULL) {\n\t\t\tERROR(\"Out of memory in read_attrs\\n\");\n\t\t\treturn 0;\n\t\t}\n\n\t\tsize = llistxattr(filename, xattr_names, size);\n\t\tif(size < 0) {\n\t\t\tfree(xattr_names);\n\t\t\tif(errno == ERANGE)\n\t\t\t\t/* xattr list grew?  Try again */\n\t\t\t\tcontinue;\n\t\t\telse {\n\t\t\t\tERROR(\"llistxattr for %s failed in read_attrs,\"\n\t\t\t\t\t\" because %s\\n\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\n\t\tbreak;\n\t}\n\n\tfor(i = 0, p = xattr_names; p < xattr_names + size; i++) {\n\t\tstruct xattr_list *x = realloc(xattr_list, (i + 1) *\n\t\t\t\t\t\tsizeof(struct xattr_list));\n\t\tif(x == NULL) {\n\t\t\tERROR(\"Out of memory in read_attrs\\n\");\n\t\t\tgoto failed;\n\t\t} else\n\t\t\txattr_list = x;\n\n\t\txattr_list[i].type = get_prefix(&xattr_list[i], p);\n\t\tp += strlen(p) + 1;\n\t\tif(xattr_list[i].type == -1) {\n\t\t\tERROR(\"Unrecognised xattr prefix %s\\n\",\n\t\t\t\txattr_list[i].full_name);\n\t\t\tfree(xattr_list[i].full_name);\n\t\t\ti--;\n\t\t\tcontinue;\n\t\t}\n\n\t\twhile(1) {\n\t\t\tvsize = lgetxattr(filename, xattr_list[i].full_name,\n\t\t\t\t\t\t\t\tNULL, 0);\n\t\t\tif(vsize < 0) {\n\t\t\t\tERROR(\"lgetxattr failed for %s in read_attrs,\"\n\t\t\t\t\t\" because %s\\n\", filename,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tfree(xattr_list[i].full_name);\n\t\t\t\tgoto failed;\n\t\t\t}\n\n\t\t\txattr_list[i].value = malloc(vsize);\n\t\t\tif(xattr_list[i].value == NULL) {\n\t\t\t\tERROR(\"Out of memory in read_attrs\\n\");\n\t\t\t\tfree(xattr_list[i].full_name);\n\t\t\t\tgoto failed;\n\t\t\t}\n\n\t\t\tvsize = lgetxattr(filename, xattr_list[i].full_name,\n\t\t\t\t\t\txattr_list[i].value, vsize);\n\t\t\tif(vsize < 0) {\n\t\t\t\tfree(xattr_list[i].value);\n\t\t\t\tif(errno == ERANGE)\n\t\t\t\t\t/* xattr grew?  Try again */\n\t\t\t\t\tcontinue;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"lgetxattr failed for %s in \"\n\t\t\t\t\t\t\"read_attrs, because %s\\n\",\n\t\t\t\t\t\tfilename, strerror(errno));\n\t\t\t\t\tfree(xattr_list[i].full_name);\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tbreak;\n\t\t}\n\t\txattr_list[i].vsize = vsize;\n\n\t\tTRACE(\"read_xattrs_from_system: filename %s, xattr name %s,\"\n\t\t\t\" vsize %d\\n\", filename, xattr_list[i].full_name,\n\t\t\txattr_list[i].vsize);\n\t}\n\tfree(xattr_names);\n\t*xattrs = xattr_list;\n\treturn i;\n\nfailed:\n\twhile(--i >= 0) {\n\t\tfree(xattr_list[i].full_name);\n\t\tfree(xattr_list[i].value);\n\t}\n\tfree(xattr_list);\n\tfree(xattr_names);\n\treturn 0;\n}\n\n\nstatic int get_xattr_size(struct xattr_list *xattr)\n{\n\tint size = sizeof(struct squashfs_xattr_entry) +\n\t\tsizeof(struct squashfs_xattr_val) + xattr->size;\n\n\tif(xattr->type & XATTR_VALUE_OOL)\n\t\tsize += XATTR_VALUE_OOL_SIZE;\n\telse\n\t\tsize += xattr->vsize;\n\n\treturn size;\n}\n\n\nstatic void *get_xattr_space(unsigned int req_size, long long *disk)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\t/*\n\t * Move and compress cached uncompressed data into xattr table.\n\t */\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((xattr_size - xattr_bytes) <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\txattr_table = realloc(xattr_table, xattr_size +\n\t\t\t\t(SQUASHFS_METADATA_SIZE << 1) + 2);\n\t\t\tif(xattr_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\txattr_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(xattr_table + xattr_bytes + BLOCK_OFFSET,\n\t\t\tdata_cache, SQUASHFS_METADATA_SIZE,\n\t\t\tSQUASHFS_METADATA_SIZE, noX, 0);\n\t\tTRACE(\"Xattr block @ 0x%x, size %d\\n\", xattr_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, xattr_table + xattr_bytes, 1);\n\t\txattr_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\tmemmove(data_cache, data_cache + SQUASHFS_METADATA_SIZE,\n\t\t\tcache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\t/*\n\t * Ensure there's enough space in the uncompressed data cache\n\t */\n\tdata_space = cache_size - cache_bytes;\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = req_size - data_space;\n\t\t\tdata_cache = realloc(data_cache, cache_size +\n\t\t\t\trealloc_size);\n\t\t\tif(data_cache == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tif(disk)\n\t\t*disk = ((long long) xattr_bytes << 16) | cache_bytes;\n\tcache_bytes += req_size;\n\treturn data_cache + cache_bytes - req_size;\n\nfailed:\n\tERROR(\"Out of memory in inode table reallocation!\\n\");\n\treturn NULL;\n}\n\n\nstatic struct dupl_id *check_id_dupl(struct xattr_list *xattr_list, int xattrs)\n{\n\tstruct dupl_id *entry;\n\tint i;\n\tunsigned short checksum = 0;\n\n\t/* compute checksum over all xattrs */\n\tfor(i = 0; i < xattrs; i++) {\n\t\tstruct xattr_list *xattr = &xattr_list[i];\n\n\t\tchecksum = get_checksum(xattr->full_name,\n\t\t\t\t\tstrlen(xattr->full_name), checksum);\n\t\tchecksum = get_checksum(xattr->value,\n\t\t\t\t\txattr->vsize, checksum);\n\t}\n\n\tfor(entry = dupl_id[checksum]; entry; entry = entry->next) {\n\t\tif (entry->xattrs != xattrs)\n\t\t\tcontinue;\n\n\t\tfor(i = 0; i < xattrs; i++) {\n\t\t\tstruct xattr_list *xattr = &xattr_list[i];\n\t\t\tstruct xattr_list *dup_xattr = &entry->xattr_list[i];\n\n\t\t\tif(strcmp(xattr->full_name, dup_xattr->full_name))\n\t\t\t\tbreak;\n\n\t\t\tif(memcmp(xattr->value, dup_xattr->value, xattr->vsize))\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif(i == xattrs)\n\t\t\tbreak;\n\t}\n\n\tif(entry == NULL) {\n\t\t/* no duplicate exists */\n\t\tentry = malloc(sizeof(*entry));\n\t\tif(entry == NULL) {\n\t\t\tERROR(\"malloc failed in check_ip_dupl\\n\");\n\t\t\treturn NULL;\n\t\t}\n\t\tentry->xattrs = xattrs;\n\t\tentry->xattr_list = xattr_list;\n\t\tentry->xattr_id = SQUASHFS_INVALID_XATTR;\n\t\tentry->next = dupl_id[checksum];\n\t\tdupl_id[checksum] = entry;\n\t}\n\t\t\n\treturn entry;\n}\n\n\nstatic void check_value_dupl(struct xattr_list *xattr)\n{\n\tstruct xattr_list *entry;\n\n\tif(xattr->vsize < XATTR_VALUE_OOL_SIZE)\n\t\treturn;\n\n\t/* Check if this is a duplicate of an existing value */\n\txattr->vchecksum = get_checksum(xattr->value, xattr->vsize, 0);\n\tfor(entry = dupl[xattr->vchecksum]; entry; entry = entry->vnext) {\n\t\tif(entry->vsize != xattr->vsize)\n\t\t\tcontinue;\n\t\t\n\t\tif(memcmp(entry->value, xattr->value, xattr->vsize) == 0)\n\t\t\tbreak;\n\t}\n\n\tif(entry == NULL) {\n\t\t/*\n\t\t * No duplicate exists, add to hash table, and mark as\n\t\t * requiring writing\n\t\t */\n\t\txattr->vnext = dupl[xattr->vchecksum];\n\t\tdupl[xattr->vchecksum] = xattr;\n\t\txattr->ool_value = SQUASHFS_INVALID_BLK;\n\t} else {\n\t\t/*\n\t\t * Duplicate exists, make type XATTR_VALUE_OOL, and\n\t\t * remember where the duplicate is\n\t\t */\n\t\txattr->type |= XATTR_VALUE_OOL;\n\t\txattr->ool_value = entry->ool_value;\n\t\t/* on appending don't free duplicate values because the\n\t\t * duplicate value already points to the non-duplicate value */\n\t\tif(xattr->value != entry->value) {\n\t\t\tfree(xattr->value);\n\t\t\txattr->value = entry->value;\n\t\t}\n\t}\n}\n\n\nstatic int get_xattr_id(int xattrs, struct xattr_list *xattr_list,\n\t\tlong long xattr_disk, struct dupl_id *xattr_dupl)\n{\n\tint i, size = 0;\n\tstruct squashfs_xattr_id *xattr_id;\n\n\txattr_id_table = realloc(xattr_id_table, (xattr_ids + 1) *\n\t\tsizeof(struct squashfs_xattr_id));\n\tif(xattr_id_table == NULL) {\n\t\tERROR(\"Out of memory in xattr_id_table reallocation!\\n\");\n\t\treturn -1;\n\t}\n\n\t/* get total uncompressed size of xattr data, needed for stat */\n\tfor(i = 0; i < xattrs; i++)\n\t\tsize += strlen(xattr_list[i].full_name) + 1 +\n\t\t\txattr_list[i].vsize;\n\n\txattr_id = &xattr_id_table[xattr_ids];\n\txattr_id->xattr = xattr_disk;\n\txattr_id->count = xattrs;\n\txattr_id->size = size;\n\n\t/*\n\t * keep track of total uncompressed xattr data, needed for mksquashfs\n\t * file system summary\n\t */\n\ttotal_xattr_bytes += size;\n\n\txattr_dupl->xattr_id = xattr_ids ++;\n\treturn xattr_dupl->xattr_id;\n}\n\t\n\nlong long write_xattrs()\n{\n\tunsigned short c_byte;\n\tint i, avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\tstruct squashfs_xattr_table header;\n\n\tif(xattr_ids == 0)\n\t\treturn SQUASHFS_INVALID_BLK;\n\n\t/*\n\t * Move and compress cached uncompressed data into xattr table.\n\t */\n\twhile(cache_bytes) {\n\t\tif((xattr_size - xattr_bytes) <\n\t\t\t\t((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\txattr_table = realloc(xattr_table, xattr_size +\n\t\t\t\t(SQUASHFS_METADATA_SIZE << 1) + 2);\n\t\t\tif(xattr_table == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\txattr_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ?\n\t\t\tSQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(xattr_table + xattr_bytes + BLOCK_OFFSET, datap,\n\t\t\tavail_bytes, SQUASHFS_METADATA_SIZE, noX, 0);\n\t\tTRACE(\"Xattr block @ 0x%x, size %d\\n\", xattr_bytes, c_byte);\n\t\tSQUASHFS_SWAP_SHORTS(&c_byte, xattr_table + xattr_bytes, 1);\n\t\txattr_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + BLOCK_OFFSET;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\t/*\n\t * Write compressed xattr table to file system\n\t */\n\twrite_destination(fd, bytes, xattr_bytes, xattr_table);\n        bytes += xattr_bytes;\n\n\t/*\n\t * Swap if necessary the xattr id table\n\t */\n\tfor(i = 0; i < xattr_ids; i++)\n\t\tSQUASHFS_INSWAP_XATTR_ID(&xattr_id_table[i]);\n\n\theader.xattr_ids = xattr_ids;\n\theader.xattr_table_start = start_bytes;\n\tSQUASHFS_INSWAP_XATTR_TABLE(&header);\n\n\treturn generic_write_table(xattr_ids * sizeof(struct squashfs_xattr_id),\n\t\txattr_id_table, sizeof(header), &header, noX);\n\nfailed:\n\tERROR(\"Out of memory in xattr_table reallocation!\\n\");\n\treturn -1;\n}\n\n\nint generate_xattrs(int xattrs, struct xattr_list *xattr_list)\n{\n\tint total_size, i;\n\tint xattr_value_max;\n\tvoid *xp;\n\tlong long xattr_disk;\n\tstruct dupl_id *xattr_dupl;\n\n\t/*\n\t * check if the file xattrs are a complete duplicate of a pre-existing\n\t * id\n\t */\n\txattr_dupl = check_id_dupl(xattr_list, xattrs);\n\tif (xattr_dupl == NULL)\n\t\treturn SQUASHFS_INVALID_XATTR;\n\tif(xattr_dupl->xattr_id != SQUASHFS_INVALID_XATTR)\n\t\treturn xattr_dupl->xattr_id;\n\t \n\t/*\n\t * Scan the xattr_list deciding which type to assign to each\n\t * xattr.  The choice is fairly straightforward, and depends on the\n\t * size of each xattr name/value and the overall size of the\n\t * resultant xattr list stored in the xattr metadata table.\n\t *\n\t * Choices are whether to store data inline or out of line.\n\t *\n\t * The overall goal is to optimise xattr scanning and lookup, and\n\t * to enable the file system layout to scale from a couple of\n\t * small xattr name/values to a large number of large xattr\n\t * names/values without affecting performance.  While hopefully\n\t * enabling the common case of a couple of small xattr name/values\n\t * to be stored efficiently\n\t *\n\t * Code repeatedly scans, doing the following\n\t *\t\tmove xattr data out of line if it exceeds\n\t *\t\txattr_value_max.  Where xattr_value_max is\n\t *\t\tinitially XATTR_INLINE_MAX.  If the final uncompressed\n\t *\t\txattr list is larger than XATTR_TARGET_MAX then more\n\t *\t\taggressively move xattr data out of line by repeatedly\n\t *\t \tsetting inline threshold to 1/2, then 1/4, 1/8 of\n\t *\t\tXATTR_INLINE_MAX until target achieved or there's\n\t *\t\tnothing left to move out of line\n\t */\n\txattr_value_max = XATTR_INLINE_MAX;\n\twhile(1) {\n\t\tfor(total_size = 0, i = 0; i < xattrs; i++) {\n\t\t\tstruct xattr_list *xattr = &xattr_list[i];\n\t\t\txattr->type &= XATTR_PREFIX_MASK; /* all inline */\n\t\t\tif (xattr->vsize > xattr_value_max)\n\t\t\t\txattr->type |= XATTR_VALUE_OOL;\n\n\t\t\ttotal_size += get_xattr_size(xattr);\n\t\t}\n\n\t\t/*\n\t\t * If the total size of the uncompressed xattr list is <=\n\t\t * XATTR_TARGET_MAX we're done\n\t\t */\n\t\tif(total_size <= XATTR_TARGET_MAX)\n\t\t\tbreak;\n\n\t\tif(xattr_value_max == XATTR_VALUE_OOL_SIZE)\n\t\t\tbreak;\n\n\t\t/*\n\t\t * Inline target not yet at minimum and so reduce it, and\n\t\t * try again\n\t\t */\n\t\txattr_value_max /= 2;\n\t\tif(xattr_value_max < XATTR_VALUE_OOL_SIZE)\n\t\t\txattr_value_max = XATTR_VALUE_OOL_SIZE;\n\t}\n\n\t/*\n\t * Check xattr values for duplicates\n\t */\n\tfor(i = 0; i < xattrs; i++) {\n\t\tcheck_value_dupl(&xattr_list[i]);\n\t}\n\n\t/*\n\t * Add each out of line value to the file system xattr table\n\t * if it doesn't already exist as a duplicate\n\t */\n\tfor(i = 0; i < xattrs; i++) {\n\t\tstruct xattr_list *xattr = &xattr_list[i];\n\n\t\tif((xattr->type & XATTR_VALUE_OOL) &&\n\t\t\t\t(xattr->ool_value == SQUASHFS_INVALID_BLK)) {\n\t\t\tstruct squashfs_xattr_val val;\n\t\t\tint size = sizeof(val) + xattr->vsize;\n\t\t\txp = get_xattr_space(size, &xattr->ool_value);\n\t\t\tval.vsize = xattr->vsize;\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, xp);\n\t\t\tmemcpy(xp + sizeof(val), xattr->value, xattr->vsize);\n\t\t}\n\t}\n\n\t/*\n\t * Create xattr list and add to file system xattr table\n\t */\n\tget_xattr_space(0, &xattr_disk);\n\tfor(i = 0; i < xattrs; i++) {\n\t\tstruct xattr_list *xattr = &xattr_list[i];\n\t\tstruct squashfs_xattr_entry entry;\n\t\tstruct squashfs_xattr_val val;\n\n\t\txp = get_xattr_space(sizeof(entry) + xattr->size, NULL);\n\t\tentry.type = xattr->type;\n\t\tentry.size = xattr->size;\n\t\tSQUASHFS_SWAP_XATTR_ENTRY(&entry, xp);\n\t\tmemcpy(xp + sizeof(entry), xattr->name, xattr->size);\n\n\t\tif(xattr->type & XATTR_VALUE_OOL) {\n\t\t\tint size = sizeof(val) + XATTR_VALUE_OOL_SIZE;\n\t\t\txp = get_xattr_space(size, NULL);\n\t\t\tval.vsize = XATTR_VALUE_OOL_SIZE;\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, xp);\n\t\t\tSQUASHFS_SWAP_LONG_LONGS(&xattr->ool_value, xp +\n\t\t\t\tsizeof(val), 1);\n\t\t} else {\n\t\t\tint size = sizeof(val) + xattr->vsize;\n\t\t\txp = get_xattr_space(size, &xattr->ool_value);\n\t\t\tval.vsize = xattr->vsize;\n\t\t\tSQUASHFS_SWAP_XATTR_VAL(&val, xp);\n\t\t\tmemcpy(xp + sizeof(val), xattr->value, xattr->vsize);\n\t\t}\n\t}\n\n\t/*\n\t * Add to xattr id lookup table\n\t */\n\treturn get_xattr_id(xattrs, xattr_list, xattr_disk, xattr_dupl);\n}\n\n\nint read_xattrs(void *d)\n{\n\tstruct dir_ent *dir_ent = d;\n\tstruct inode_info *inode = dir_ent->inode;\n\tchar *filename = dir_ent->pathname;\n\tstruct xattr_list *xattr_list;\n\tint xattrs;\n\n\tif(no_xattrs || IS_PSEUDO(inode) || inode->root_entry)\n\t\treturn SQUASHFS_INVALID_XATTR;\n\n\txattrs = read_xattrs_from_system(filename, &xattr_list);\n\tif(xattrs == 0)\n\t\treturn SQUASHFS_INVALID_XATTR;\n\n\treturn generate_xattrs(xattrs, xattr_list);\n}\n\n\n/*\n * Add the existing xattr ids and xattr metadata in the file system being\n * appended to, to the in-memory xattr cache.  This allows duplicate checking to\n * take place against the xattrs already in the file system being appended to,\n * and ensures the pre-existing xattrs are written out along with any new xattrs\n */\nint get_xattrs(int fd, struct squashfs_super_block *sBlk)\n{\n\tint ids, res, i, id;\n\tunsigned int count;\n\n\tTRACE(\"get_xattrs\\n\");\n\n\tres = read_xattrs_from_disk(fd, sBlk);\n\tif(res == SQUASHFS_INVALID_BLK || res == 0)\n\t\tgoto done;\n\tids = res;\n\n\t/*\n\t * for each xattr id read and construct its list of xattr\n\t * name:value pairs, and add them to the in-memory xattr cache\n\t */\n\tfor(i = 0; i < ids; i++) {\n\t\tstruct xattr_list *xattr_list = get_xattr(i, &count);\n\t\tif(xattr_list == NULL) {\n\t\t\tres = 0;\n\t\t\tgoto done;\n\t\t}\n\t\tid = generate_xattrs(count, xattr_list);\n\n\t\t/*\n\t\t * Sanity check, the new xattr id should be the same as the\n\t\t * xattr id in the original file system\n\t\t */\n\t\tif(id != i) {\n\t\t\tERROR(\"BUG, different xattr_id in get_xattrs\\n\");\n\t\t\tres = 0;\n\t\t\tgoto done;\n\t\t}\n\t}\n\ndone:\n\treturn res;\n}\n\n\n/*\n * Save current state of xattrs, needed for restoring state in the event of an\n * abort in appending\n */\nint save_xattrs()\n{\n\t/* save the current state of the compressed xattr data */\n\tsxattr_bytes = xattr_bytes;\n\tstotal_xattr_bytes = total_xattr_bytes;\n\n\t/*\n\t * save the current state of the cached uncompressed xattr data.\n\t * Note we have to save the contents of the data cache because future\n\t * operations will delete the current contents\n\t */\n\tsdata_cache = malloc(cache_bytes);\n\tif(sdata_cache == NULL)\n\t\tgoto failed;\n\n\tmemcpy(sdata_cache, data_cache, cache_bytes);\n\tscache_bytes = cache_bytes;\n\n\t/* save the current state of the xattr id table */\n\tsxattr_ids = xattr_ids;\n\n\treturn TRUE;\n\nfailed:\n\tERROR(\"Out of memory in save_xattrs\\n\");\n\treturn FALSE;\n}\n\n\n/*\n * Restore xattrs in the event of an abort in appending\n */\nvoid restore_xattrs()\n{\n\t/* restore the state of the compressed xattr data */\n\txattr_bytes = sxattr_bytes;\n\ttotal_xattr_bytes = stotal_xattr_bytes;\n\n\t/* restore the state of the uncomoressed xattr data */\n\tmemcpy(data_cache, sdata_cache, scache_bytes);\n\tcache_bytes = scache_bytes;\n\n\t/* restore the state of the xattr id table */\n\txattr_ids = sxattr_ids;\n}\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/xattr.h",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only\n * filesystem.\n *\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * xattr.h\n */\n\n#define XATTR_VALUE_OOL\t\tSQUASHFS_XATTR_VALUE_OOL\n#define XATTR_PREFIX_MASK\tSQUASHFS_XATTR_PREFIX_MASK\n\n#define XATTR_VALUE_OOL_SIZE\tsizeof(long long)\n\n/* maximum size of xattr value data that will be inlined */\n#define XATTR_INLINE_MAX \t128\n\n/* the target size of an inode's xattr name:value list.  If it\n * exceeds this, then xattr value data will be successively out of lined\n * until it meets the target */\n#define XATTR_TARGET_MAX\t65536\n\n#define IS_XATTR(a)\t\t(a != SQUASHFS_INVALID_XATTR)\n\nstruct xattr_list {\n\tchar\t\t\t*name;\n\tchar\t\t\t*full_name;\n\tint\t\t\tsize;\n\tint\t\t\tvsize;\n\tvoid\t\t\t*value;\n\tint\t\t\ttype;\n\tlong long\t\tool_value;\n\tunsigned short\t\tvchecksum;\n\tstruct xattr_list\t*vnext;\n};\n\nstruct dupl_id {\n\tstruct xattr_list\t*xattr_list;\n\tint\t\t\txattrs;\n\tint\t\t\txattr_id;\n\tstruct dupl_id\t\t*next;\n};\n\nstruct prefix {\n\tchar\t\t\t*prefix;\n\tint\t\t\ttype;\n};\n\nextern int generate_xattrs(int, struct xattr_list *);\n\n#ifdef XATTR_SUPPORT\nextern int get_xattrs(int, struct squashfs_super_block *);\nextern int read_xattrs(void *);\nextern long long write_xattrs();\nextern int save_xattrs();\nextern void restore_xattrs();\nextern unsigned int xattr_bytes, total_xattr_bytes;\nextern void write_xattr(char *, unsigned int);\nextern int read_xattrs_from_disk(int, struct squashfs_super_block *);\nextern struct xattr_list *get_xattr(int, unsigned int *);\n#else\nstatic inline int get_xattrs(int fd, struct squashfs_super_block *sBlk)\n{\n\tif(sBlk->xattr_id_table_start != SQUASHFS_INVALID_BLK) {\n\t\tfprintf(stderr, \"Xattrs in filesystem! These are not \"\n\t\t\t\"supported on this version of Squashfs\\n\");\n\t\treturn 0;\n\t} else\n\t\treturn SQUASHFS_INVALID_BLK;\n}\n\n\nstatic inline int read_xattrs(void *dir_ent)\n{\n\treturn SQUASHFS_INVALID_XATTR;\n}\n\n\nstatic inline long long write_xattrs()\n{\n\treturn SQUASHFS_INVALID_BLK;\n}\n\n\nstatic inline int save_xattrs()\n{\n\treturn 1;\n}\n\n\nstatic inline void restore_xattrs()\n{\n}\n\n\nstatic inline void write_xattr(char *pathname, unsigned int xattr)\n{\n}\n\n\nstatic inline int read_xattrs_from_disk(int fd, struct squashfs_super_block *sBlk)\n{\n\tif(sBlk->xattr_id_table_start != SQUASHFS_INVALID_BLK) {\n\t\tfprintf(stderr, \"Xattrs in filesystem! These are not \"\n\t\t\t\"supported on this version of Squashfs\\n\");\n\t\treturn 0;\n\t} else\n\t\treturn SQUASHFS_INVALID_BLK;\n}\n\n\nstatic inline struct xattr_list *get_xattr(int i, unsigned int *count)\n{\n\treturn NULL;\n}\n#endif\n\n#ifdef XATTR_SUPPORT\n#ifdef XATTR_DEFAULT\n#define NOXOPT_STR\n#define XOPT_STR \" (default)\"\n#define XATTR_DEF 0\n#else\n#define NOXOPT_STR \" (default)\"\n#define XOPT_STR\n#define XATTR_DEF 1\n#endif\n#else\n#define NOXOPT_STR \" (default)\"\n#define XOPT_STR \" (unsupported)\"\n#define XATTR_DEF 1\n#endif\n\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/xz_wrapper.c",
    "content": "/*\n * Copyright (c) 2010, 2011\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * xz_wrapper.c\n *\n * Support for XZ (LZMA2) compression using XZ Utils liblzma\n * http://tukaani.org/xz/\n */\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <lzma.h>\n\n#include \"squashfs_fs.h\"\n#include \"xz_wrapper.h\"\n#include \"compressor.h\"\n\nstatic struct bcj bcj[] = {\n\t{ \"x86\", LZMA_FILTER_X86, 0 },\n\t{ \"powerpc\", LZMA_FILTER_POWERPC, 0 },\n\t{ \"ia64\", LZMA_FILTER_IA64, 0 },\n\t{ \"arm\", LZMA_FILTER_ARM, 0 },\n\t{ \"armthumb\", LZMA_FILTER_ARMTHUMB, 0 },\n\t{ \"sparc\", LZMA_FILTER_SPARC, 0 },\n\t{ NULL, LZMA_VLI_UNKNOWN, 0 }\n};\n\nstatic struct comp_opts comp_opts;\n\nstatic int filter_count = 1;\nstatic int dictionary_size = 0;\nstatic float dictionary_percent = 0;\n\n\nstatic int xz_options(char *argv[], int argc)\n{\n\tint i;\n\tchar *name;\n\n\tif(strcmp(argv[0], \"-Xbcj\") == 0) {\n\t\tif(argc < 2) {\n\t\t\tfprintf(stderr, \"xz: -Xbcj missing filter\\n\");\n\t\t\tgoto failed;\n\t\t}\n\n\t\tname = argv[1];\n\t\twhile(name[0] != '\\0') {\n\t\t\tfor(i = 0; bcj[i].name; i++) {\n\t\t\t\tint n = strlen(bcj[i].name);\n\t\t\t\tif((strncmp(name, bcj[i].name, n) == 0) &&\n\t\t\t\t\t\t(name[n] == '\\0' ||\n\t\t\t\t\t\t name[n] == ',')) {\n\t\t\t\t\tif(bcj[i].selected == 0) {\n\t\t\t\t \t\tbcj[i].selected = 1;\n\t\t\t\t\t\tfilter_count++;\n\t\t\t\t\t}\n\t\t\t\t\tname += name[n] == ',' ? n + 1 : n;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(bcj[i].name == NULL) {\n\t\t\t\tfprintf(stderr, \"xz: -Xbcj unrecognised \"\n\t\t\t\t\t\"filter\\n\");\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t}\n\t\n\t\treturn 1;\n\t} else if(strcmp(argv[0], \"-Xdict-size\") == 0) {\n\t\tchar *b;\n\t\tfloat size;\n\n\t\tif(argc < 2) {\n\t\t\tfprintf(stderr, \"xz: -Xdict-size missing dict-size\\n\");\n\t\t\tgoto failed;\n\t\t}\n\n\t\tsize = strtof(argv[1], &b);\n\t\tif(*b == '%') {\n\t\t\tif(size <= 0 || size > 100) {\n\t\t\t\tfprintf(stderr, \"xz: -Xdict-size percentage \"\n\t\t\t\t\t\"should be 0 < dict-size <= 100\\n\");\n\t\t\t\tgoto failed;\n\t\t\t}\n\n\t\t\tdictionary_percent = size;\n\t\t\tdictionary_size = 0;\n\t\t} else {\n\t\t\tif((float) ((int) size) != size) {\n\t\t\t\tfprintf(stderr, \"xz: -Xdict-size can't be \"\n\t\t\t\t\t\"fractional unless a percentage of the\"\n\t\t\t\t\t\" block size\\n\");\n\t\t\t\tgoto failed;\n\t\t\t}\n\n\t\t\tdictionary_percent = 0;\n\t\t\tdictionary_size = (int) size;\n\n\t\t\tif(*b == 'k' || *b == 'K')\n\t\t\t\tdictionary_size *= 1024;\n\t\t\telse if(*b == 'm' || *b == 'M')\n\t\t\t\tdictionary_size *= 1024 * 1024;\n\t\t\telse if(*b != '\\0') {\n\t\t\t\tfprintf(stderr, \"xz: -Xdict-size invalid \"\n\t\t\t\t\t\"dict-size\\n\");\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t}\n\n\t\treturn 1;\n\t}\n\n\treturn -1;\n\t\nfailed:\n\treturn -2;\n}\n\n\nstatic int xz_options_post(int block_size)\n{\n\t/*\n\t * if -Xdict-size has been specified use this to compute the datablock\n\t * dictionary size\n\t */\n\tif(dictionary_size || dictionary_percent) {\n\t\tint n;\n\n\t\tif(dictionary_size) {\n\t\t\tif(dictionary_size > block_size) {\n\t\t\t\tfprintf(stderr, \"xz: -Xdict-size is larger than\"\n\t\t\t\t\" block_size\\n\");\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t} else\n\t\t\tdictionary_size = block_size * dictionary_percent / 100;\n\n\t\tif(dictionary_size < 8192) {\n\t\t\tfprintf(stderr, \"xz: -Xdict-size should be 8192 bytes \"\n\t\t\t\t\"or larger\\n\");\n\t\t\tgoto failed;\n\t\t}\n\n\t\t/*\n\t\t * dictionary_size must be storable in xz header as either\n\t\t * 2^n or as  2^n+2^(n+1)\n\t \t*/\n\t\tn = ffs(dictionary_size) - 1;\n\t\tif(dictionary_size != (1 << n) && \n\t\t\t\tdictionary_size != ((1 << n) + (1 << (n + 1)))) {\n\t\t\tfprintf(stderr, \"xz: -Xdict-size is an unsupported \"\n\t\t\t\t\"value, dict-size must be storable in xz \"\n\t\t\t\t\"header\\n\");\n\t\t\tfprintf(stderr, \"as either 2^n or as 2^n+2^(n+1).  \"\n\t\t\t\t\"Example dict-sizes are 75%%, 50%%, 37.5%%, \"\n\t\t\t\t\"25%%,\\n\");\n\t\t\tfprintf(stderr, \"or 32K, 16K, 8K etc.\\n\");\n\t\t\tgoto failed;\n\t\t}\n\n\t} else\n\t\t/* No -Xdict-size specified, use defaults */\n\t\tdictionary_size = block_size;\n\n\treturn 0;\n\nfailed:\n\treturn -1;\n}\n\n\nstatic void *xz_dump_options(int block_size, int *size)\n{\n\tint flags = 0, i;\n\n\t/*\n\t * don't store compressor specific options in file system if the\n\t * default options are being used - no compressor options in the\n\t * file system means the default options are always assumed\n\t *\n\t * Defaults are:\n\t *  metadata dictionary size: SQUASHFS_METADATA_SIZE\n\t *  datablock dictionary size: block_size\n\t *  1 filter\n\t */\n\tif(dictionary_size == block_size && filter_count == 1)\n\t\treturn NULL;\n\n\tfor(i = 0; bcj[i].name; i++)\n\t\tflags |= bcj[i].selected << i;\n\n\tcomp_opts.dictionary_size = dictionary_size;\n\tcomp_opts.flags = flags;\n\n\tSQUASHFS_INSWAP_COMP_OPTS(&comp_opts);\n\n\t*size = sizeof(comp_opts);\n\treturn &comp_opts;\n}\n\n\nstatic int xz_extract_options(int block_size, void *buffer, int size)\n{\n\tstruct comp_opts *comp_opts = buffer;\n\tint flags, i, n;\n\n\tif(size == 0) {\n\t\t/* set defaults */\n\t\tdictionary_size = block_size;\n\t\tflags = 0;\n\t} else {\n\t\t/* check passed comp opts struct is of the correct length */\n\t\tif(size != sizeof(struct comp_opts))\n\t\t\tgoto failed;\n\t\t\t\t\t \n\t\tSQUASHFS_INSWAP_COMP_OPTS(comp_opts);\n\n\t\tdictionary_size = comp_opts->dictionary_size;\n\t\tflags = comp_opts->flags;\n\n\t\t/*\n\t\t * check that the dictionary size seems correct - the dictionary\n\t\t * size should 2^n or 2^n+2^(n+1)\n\t\t */\n\t\tn = ffs(dictionary_size) - 1;\n\t\tif(dictionary_size != (1 << n) && \n\t\t\t\tdictionary_size != ((1 << n) + (1 << (n + 1))))\n\t\t\tgoto failed;\n\t}\n\n\tfilter_count = 1;\n\tfor(i = 0; bcj[i].name; i++) {\n\t\tif((flags >> i) & 1) {\n\t\t\tbcj[i].selected = 1;\n\t\t\tfilter_count ++;\n\t\t} else\n\t\t\tbcj[i].selected = 0;\n\t}\n\n\treturn 0;\n\nfailed:\n\tfprintf(stderr, \"xz: error reading stored compressor options from \"\n\t\t\"filesystem!\\n\");\n\n\treturn -1;\n}\n\n\nstatic int xz_init(void **strm, int block_size, int datablock)\n{\n\tint i, j, filters = datablock ? filter_count : 1;\n\tstruct filter *filter = malloc(filters * sizeof(struct filter));\n\tstruct xz_stream *stream;\n\n\tif(filter == NULL)\n\t\tgoto failed;\n\n\tstream = *strm = malloc(sizeof(struct xz_stream));\n\tif(stream == NULL)\n\t\tgoto failed2;\n\n\tstream->filter = filter;\n\tstream->filters = filters;\n\n\tmemset(filter, 0, filters * sizeof(struct filter));\n\n\tstream->dictionary_size = datablock ? dictionary_size :\n\t\tSQUASHFS_METADATA_SIZE;\n\n\tfilter[0].filter[0].id = LZMA_FILTER_LZMA2;\n\tfilter[0].filter[0].options = &stream->opt;\n\tfilter[0].filter[1].id = LZMA_VLI_UNKNOWN;\n\n\tfor(i = 0, j = 1; datablock && bcj[i].name; i++) {\n\t\tif(bcj[i].selected) {\n\t\t\tfilter[j].buffer = malloc(block_size);\n\t\t\tif(filter[j].buffer == NULL)\n\t\t\t\tgoto failed3;\n\t\t\tfilter[j].filter[0].id = bcj[i].id;\n\t\t\tfilter[j].filter[1].id = LZMA_FILTER_LZMA2;\n\t\t\tfilter[j].filter[1].options = &stream->opt;\n\t\t\tfilter[j].filter[2].id = LZMA_VLI_UNKNOWN;\n\t\t\tj++;\n\t\t}\n\t}\n\n\treturn 0;\n\nfailed3:\n\tfor(i = 1; i < filters; i++)\n\t\tfree(filter[i].buffer);\n\tfree(stream);\n\nfailed2:\n\tfree(filter);\n\nfailed:\n\treturn -1;\n}\n\n\nstatic int xz_compress(void *strm, void *dest, void *src,  int size,\n\tint block_size, int *error)\n{\n\tint i;\n        lzma_ret res = 0;\n\tstruct xz_stream *stream = strm;\n\tstruct filter *selected = NULL;\n\n\tstream->filter[0].buffer = dest;\n\n\tfor(i = 0; i < stream->filters; i++) {\n\t\tstruct filter *filter = &stream->filter[i];\n\n        \tif(lzma_lzma_preset(&stream->opt, LZMA_PRESET_DEFAULT))\n                \tgoto failed;\n\n\t\tstream->opt.dict_size = stream->dictionary_size;\n\n\t\tfilter->length = 0;\n\t\tres = lzma_stream_buffer_encode(filter->filter,\n\t\t\tLZMA_CHECK_CRC32, NULL, src, size, filter->buffer,\n\t\t\t&filter->length, block_size);\n\t\n\t\tif(res == LZMA_OK) {\n\t\t\tif(!selected || selected->length > filter->length)\n\t\t\t\tselected = filter;\n\t\t} else if(res != LZMA_BUF_ERROR)\n\t\t\tgoto failed;\n\t}\n\n\tif(!selected)\n\t\t/*\n\t \t * Output buffer overflow.  Return out of buffer space\n\t \t */\n\t\treturn 0;\n\n\tif(selected->buffer != dest)\n\t\tmemcpy(dest, selected->buffer, selected->length);\n\n\treturn (int) selected->length;\n\nfailed:\n\t/*\n\t * All other errors return failure, with the compressor\n\t * specific error code in *error\n\t */\n\t*error = res;\n\treturn -1;\n}\n\n\nstatic int xz_uncompress(void *dest, void *src, int size, int block_size,\n\tint *error)\n{\n\tsize_t src_pos = 0;\n\tsize_t dest_pos = 0;\n\tuint64_t memlimit = MEMLIMIT;\n\n\tlzma_ret res = lzma_stream_buffer_decode(&memlimit, 0, NULL,\n\t\t\tsrc, &src_pos, size, dest, &dest_pos, block_size);\n\n\t*error = res;\n\treturn res == LZMA_OK && size == (int) src_pos ? (int) dest_pos : -1;\n}\n\n\nvoid xz_usage()\n{\n\tfprintf(stderr, \"\\t  -Xbcj filter1,filter2,...,filterN\\n\");\n\tfprintf(stderr, \"\\t\\tCompress using filter1,filter2,...,filterN in\");\n\tfprintf(stderr, \" turn\\n\\t\\t(in addition to no filter), and choose\");\n\tfprintf(stderr, \" the best compression.\\n\");\n\tfprintf(stderr, \"\\t\\tAvailable filters: x86, arm, armthumb,\");\n\tfprintf(stderr, \" powerpc, sparc, ia64\\n\");\n\tfprintf(stderr, \"\\t  -Xdict-size <dict-size>\\n\");\n\tfprintf(stderr, \"\\t\\tUse <dict-size> as the XZ dictionary size.  The\");\n\tfprintf(stderr, \" dictionary size\\n\\t\\tcan be specified as a\");\n\tfprintf(stderr, \" percentage of the block size, or as an\\n\\t\\t\");\n\tfprintf(stderr, \"absolute value.  The dictionary size must be less\");\n\tfprintf(stderr, \" than or equal\\n\\t\\tto the block size and 8192 bytes\");\n\tfprintf(stderr, \" or larger.  It must also be\\n\\t\\tstorable in the xz\");\n\tfprintf(stderr, \" header as either 2^n or as 2^n+2^(n+1).\\n\\t\\t\");\n\tfprintf(stderr, \"Example dict-sizes are 75%%, 50%%, 37.5%%, 25%%, or\");\n\tfprintf(stderr, \" 32K, 16K, 8K\\n\\t\\tetc.\\n\");\n}\n\n\nstruct compressor xz_comp_ops = {\n\t.init = xz_init,\n\t.compress = xz_compress,\n\t.uncompress = xz_uncompress,\n\t.options = xz_options,\n\t.options_post = xz_options_post,\n\t.dump_options = xz_dump_options,\n\t.extract_options = xz_extract_options,\n\t.usage = xz_usage,\n\t.id = XZ_COMPRESSION,\n\t.name = \"xz\",\n\t.supported = 1\n};\n"
  },
  {
    "path": "src/others/squashfs-4.2-official/xz_wrapper.h",
    "content": "#ifndef XZ_WRAPPER_H\n#define XZ_WRAPPER_H\n/*\n * Squashfs\n *\n * Copyright (c) 2010\n * Phillip Lougher <phillip@lougher.demon.co.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * xz_wrapper.h\n *\n */\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#if __BYTE_ORDER == __BIG_ENDIAN\nextern unsigned int inswap_le32(unsigned int);\n\n#define SQUASHFS_INSWAP_COMP_OPTS(s) { \\\n\t(s)->dictionary_size = inswap_le32((s)->dictionary_size); \\\n\t(s)->flags = inswap_le32((s)->flags); \\\n}\n#else\n#define SQUASHFS_INSWAP_COMP_OPTS(s)\n#endif\n\n#define MEMLIMIT (32 * 1024 * 1024)\n\nstruct bcj {\n\tchar\t \t*name;\n\tlzma_vli\tid;\n\tint\t\tselected;\n};\n\nstruct filter {\n\tvoid\t\t*buffer;\n\tlzma_filter\tfilter[3];\n\tsize_t\t\tlength;\n};\n\nstruct xz_stream {\n\tstruct filter\t*filter;\n\tint\t\tfilters;\n\tint\t\tdictionary_size;\n\tlzma_options_lzma opt;\n};\n\nstruct comp_opts {\n\tint dictionary_size;\n\tint flags;\n};\n#endif\n"
  },
  {
    "path": "src/others/squashfs-hg55x-bin/README",
    "content": "This is a binary grabbed from the internet with no source code. It appears OK, but no guaruntees. \nFor most systems, the squashfs-2.0-nb4 tools should be a suitable substitute for this binary.\nUse them instead.\n"
  },
  {
    "path": "src/splitter3.cc",
    "content": "/* splitter3.cc\n * Copyright (C) 2010 Jeremy Collake  <jeremy.collake@gmail.com>\n * A product of Bitsum Technologies\n * http://www.bitsum.com\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n *\n **********************************************************************************\n *\n * This little utility patches a specific type of simple OpenWrt (embedded linux) \n * based firmware found on a particular manufacturer's router.\n *\n */\n \n #define _VERSION_ \"0.10 beta\"\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <sys/types.h>\n\n#include <endian.h>\n#include <byteswap.h>\n#include <sys/types.h>\n\n#include \"untrx.h\"\n\n/*************************************************************************\n* IdentifySegment\n*\n* identifies segments (i.e. squashfs, cramfs) and their version numbers\n*\n**************************************************************************/\nSEGMENT_TYPE IdentifySegment(unsigned char *pData, unsigned int nLength)\n{\n\tsquashfs_super_block *sqblock=(squashfs_super_block *)pData;\n\tcramfs_super *crblock=(cramfs_super *)pData;\n\t\n\tif(sqblock->s_magic==SQUASHFS_MAGIC \n\t\t|| sqblock->s_magic==SQUASHFS_MAGIC_SWAP\n\t\t|| sqblock->s_magic==SQUASHFS_MAGIC_ALT\n\t\t|| sqblock->s_magic==SQUASHFS_MAGIC_ALT_SWAP)\n\t{\t\t\n\t\tfprintf(stderr, \" SQUASHFS magic: 0x%x\\n\", sqblock->s_magic);\n\t\tshort major = READ16_LE(sqblock->s_major);\n\t\tshort minor = READ16_LE(sqblock->s_minor);\n\t\tfprintf(stderr, \" SQUASHFS version: %d.%d\\n\", major, minor);\n\t\n\t\tswitch(major)\n\t\t{\n\t\t\tcase 3:\n\t\t\t\tswitch (minor)\n\t\t\t\t{\n\t\t\t\t\tcase 0:\t\t\t\t\t\t\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_3_0;\n\t\t\t\t\tcase 1:\t\t\t\t\t\t\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_3_1;\t\t\t\n\t\t\t\t\tcase 2:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_3_2;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_3_x;\t\t\t\t\t\t\n\t\t\t\t}\n\t\t\tcase 2:\n\t\t\t\tswitch (minor)\n\t\t\t\t{\n\t\t\t\t\tcase 0:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_2_0;\n\t\t\t\t\tcase 1:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_2_1;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_2_x;\t\t\t\t\t\t\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_OTHER;\t\t\t\t\n\t\t}\n\t}\t\n\telse if(crblock->magic==CRAMFS_MAGIC || crblock->magic==CRAMFS_MAGIC_SWAP)\n\t{\n\t\treturn SEGMENT_TYPE_CRAMFS_x_x;\t\n\t}\t\n\treturn SEGMENT_TYPE_UNTYPED;\n}\n\n/*************************************************************************\n* EmitSquashfsMagic\n*\n* writes the squashfs root block signature to a file, as a fix for\n* Brainslayer of DD-WRT deciding to change it to some arbitrary value\n* to break compatibility with this kit.\n*\n**************************************************************************/\nint EmitSquashfsMagic(squashfs_super_block *pSuper, char *pszOutFile)\n{\n\tfprintf(stderr, \"  Writing %s\\n\", pszOutFile);\n\tFILE *fOut=fopen(pszOutFile,\"wb\");\n\tif(!fOut) return 0;\n\tif(fwrite(pSuper,1,4,fOut)!=4)\n\t{\n\t\tfclose(fOut);\n\t\treturn 0;\n\t}\n\tfclose(fOut);\t\n\treturn 1;\n}\n\n/*************************************************************************\n* ShowUsage\n*\n*\n**************************************************************************/\nvoid ShowUsage()\n{\t\t\t\n\tfprintf(stderr, \" ERROR: Invalid usage.\\n\"\t\t\n\t\t\" USAGE: splitter3 binfile outfolder\\n\");\t\n\texit(9);\n}\n\n/*************************************************************************\n* main\n*\n*\n**************************************************************************/\nint main(int argc, char **argv)\n{\n\tfprintf(stderr, \" splitter3 \" _VERSION_ \" - (c)2010 Jeremy Collake\\n\");\n\t\n\tif(argc<3)\n\t{\n\t\tShowUsage();\n\t}\n\t\n\tfprintf(stderr, \" Opening %s\\n\", argv[1]);\n\tFILE *fIn=fopen(argv[1],\"rb\");\n\tif(!fIn)\n\t{\n\t\tfprintf(stderr, \" ERROR opening %s\\n\", argv[1]);\n\t\texit(1);\n\t}\n\t\n\tchar *pszOutFolder=(char *)malloc(strlen(argv[2])+sizeof(char));\n\tstrcpy(pszOutFolder,argv[2]);\n\tif(pszOutFolder[strlen(pszOutFolder)-1]=='/')\n\t{\n\t\tpszOutFolder[strlen(pszOutFolder)-1]=0;\t\t\n\t}\t\n\t\n\tfseek(fIn,0,SEEK_END);\n\tsize_t nFilesize=ftell(fIn);\n\tfseek(fIn,0,SEEK_SET);\t\t\n\tunsigned char *pData=(unsigned char *)malloc(nFilesize);\t\n\tunsigned char *pDataOrg=pData;\n\tif(fread(pData,1,nFilesize,fIn)!=nFilesize)\n\t{\n\t\tfprintf(stderr,\" ERROR reading %s\\n\", argv[1]);\t\t\n\t\tfclose(fIn);\t\n\t\tfree(pDataOrg);\n\t\tfree(pszOutFolder);\t\n\t\texit(1);\n\t}\t\n\tfclose(fIn);\t\n\tfprintf(stderr, \" read %u bytes\\n\", nFilesize);\n\t\n\t/* Extract the segments */\n\tunsigned int nKernelLength=0;\n\t// do stupid linear search for 'sqsh' (yes, I'm that lazy)\n\tfor(unsigned int nI=0;nI<(nFilesize-4);nI++)\n\t{\t\t\n\t\t// TODO: add extra bounds check to IdentifySegment\n\t\tSEGMENT_TYPE segType=IdentifySegment(pDataOrg+nI,4);\n\t\tif(segType!=SEGMENT_TYPE_UNTYPED)\n\t\t{\n\t\t\tfprintf(stderr, \" Found segment type 0x%x\", segType);\n\t\t\tnKernelLength=nI;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif(!nKernelLength)\n\t{\n\t\tfprintf(stderr, \" ERROR: Could not locate any file system in image. Perhaps obfuscated or unknown FS\");\n\t\tfree(pDataOrg);\n\t\texit(2);\n\t}\t\n\n\t// now go to last 4096 block of file, as the FS will end on this and trailer begin\n\t// alternate way nTrailerOffset&0xfffff000 but may not be great for platform compatibility\n\tunsigned int nTrailerOffset=(nFilesize/4096)*4096;\t// do safe method, 32-bit, 64-bit, any size ints\n\tunsigned int nTrailerLength=nFilesize-nTrailerOffset;\n\tunsigned int nFilesystemLength=nTrailerOffset-nKernelLength;\n\tfprintf(stderr, \n\t\t\" Kernel length is %x\\n File system length is %x\\n Trailer is %x bytes\\n\", \n\t\tnKernelLength, nFilesystemLength, nTrailerLength);\n\n\t// allocate filename buffer\n\tchar *pszTemp=(char *)\n\t\tmalloc((strlen(pszOutFolder)*sizeof(char))+(128*sizeof(char)));\t\t\t\n\n\tfor(unsigned int nI=0;nI<3;nI++)\n\t{\n\t\tFILE *fOut;\t\n\n\t\tunsigned int nOffset,nLength;\n\t\tswitch(nI)\n\t\t{\n\t\t\tcase 0:\n\t\t\t\tnOffset=0;\n\t\t\t\tnLength=nKernelLength;\n\t\t\t\tbreak;\n\t\t\tcase 1:\n\t\t\t\tnOffset=nKernelLength;\n\t\t\t\tnLength=nFilesystemLength;\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tnOffset=nTrailerOffset;\n\t\t\t\tnLength=nTrailerLength;\n\t\t\t\tbreak;\n\t\t\tdefault: \n\t\t\t\t// assert here\n\t\t\t\tbreak;\n\t\t\t\n\t\t}\n\t\t\t\n\t\tswitch(IdentifySegment(pDataOrg+nOffset,nLength))\n\t\t{\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_3_0:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v3.0 image detected\\n\");\t\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs_magic\",pszOutFolder);\t\t\t\t\t\t\t\t\n\t\t\t\tif(!EmitSquashfsMagic((squashfs_super_block *)pData,pszTemp))\n\t\t\t\t{\n\t\t\t\t\tfprintf(stderr,\"  ERROR - writing %s\\n\", pszTemp);\n\t\t\t\t\tfree(pDataOrg);\n\t\t\t\t\tfree(pszOutFolder);\t\n\t\t\t\t\tfree(pszTemp);\n\t\t\t\t\texit(3);\t\t\n\t\t\t\t}\t\t\t\t\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-3_0\",pszOutFolder);\t\t\t\t\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_3_1:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v3.1 image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-3_1\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_3_2:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v3.2 image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-3_2\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_3_x:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v3.x (>3.2) image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-3_x\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_2_0:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v2.0 image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-2_0\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_2_1:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v2.1 image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-2_1\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_2_x:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v2.x image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-2_x\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_OTHER:\n\t\t\t\tfprintf(stderr, \"  ! WARNING: Unknown squashfs version.\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-x_x\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_CRAMFS_x_x:\n\t\t\t\tfprintf(stderr, \"  CRAMFS v? image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/cramfs-image-x_x\",pszOutFolder);\n\t\t\t\tbreak;\t\t\t\t\n\t\t\tdefault:\n\t\t\t\tif(!nI)\n\t\t\t\t{\n\t\t\t\t\tsprintf(pszTemp,\"%s/vmlinuz\",pszOutFolder);\n\t\t\t\t}\n\t\t\t\telse if(nI==2)\n\t\t\t\t{\n\t\t\t\t\tsprintf(pszTemp,\"%s/hwid.txt\",pszOutFolder);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t// should add assertion\n\t\t\t\t\tsprintf(pszTemp,\"%s/part%d.bin\",pszOutFolder,nI);\n\t\t\t\t}\n\t\t\t\tbreak;\t\t\t\n\t\t}\t\t\n\t\tfprintf(stderr,\"  Writing %s\\n    size %d from offset %d ...\\n\", \n\t\t\tpszTemp, \n\t\t\tnLength,\n\t\t\tpData-pDataOrg);\t\t\n\n\t\tfOut=fopen(pszTemp,\"wb\");\n\t\tif(!fOut)\n\t\t{\n\t\t\tfprintf(stderr,\"  ERROR could not open %s\\n\", pszTemp);\n\t\t\tfree(pDataOrg);\n\t\t\tfree(pszOutFolder);\t\n\t\t\tfree(pszTemp);\n\t\t\texit(3);\t\t\n\t\t}\t\t\t\t\n\t\tif(!fwrite(pData,1,nLength,fOut))\n\t\t{\n\t\t\tfprintf(stderr,\" ERROR could not write %s\\n\", pszTemp);\n\t\t\tfclose(fOut);\n\t\t\tfree(pDataOrg);\n\t\t\tfree(pszOutFolder);\t\n\t\t\tfree(pszTemp);\n\t\t\texit(4);\t\t\t\t\n\t\t}\n\t\tfclose(fOut);\t\n\t\tpData+=nLength;\n\t}\n\t\n\tfree(pDataOrg);\n\tfree(pszOutFolder);\t\n\tfree(pszTemp);\n\tprintf(\"  Done!\\n\");\n\texit(0);\n}\n"
  },
  {
    "path": "src/squashfs-2.1-r2/Makefile",
    "content": "CC := gcc\nCXX := g++\nINCLUDEDIR = .\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\nLZMAPATH = ../lzma/C/7zip/Compress/LZMA_Lib\n\nall: mksquashfs-lzma mksquashfs unsquashfs-lzma unsquashfs\n\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\t$(CC) mksquashfs.o read_fs.o sort.o -lz -o $@\n\nmksquashfs-lzma: mksquashfs.o read_fs.o sort.o\n\tmake -C $(LZMAPATH)\n\t$(CXX) -O3 mksquashfs.o read_fs.o sort.o -L$(LZMAPATH) -llzma -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h \n\nsort.o: sort.c squashfs_fs.h \n\nunsquashfs-lzma: unsquashfs.o\n\tmake -C $(LZMAPATH)\n\t$(CXX) -O3 unsquashfs.o -L$(LZMAPATH) -llzma -o $@\n\nunsquashfs: unsquashfs.o\n\t$(CC) unsquashfs.o -lz -o $@\n\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h\n\nclean:\n\trm -f *.o\n\trm -f mksquashfs\n\trm -f unsquashfs\n\trm -f mksquashfs-lzma\n\trm -f unsquashfs-lzma\n\trm -f mksquashfs.exe\n\trm -f unsquashfs.exe\n\trm -f mksquashfs-lzma.exe\n\trm -f unsquashfs-lzma.exe\n\tmake -C $(LZMAPATH) clean\n"
  },
  {
    "path": "src/squashfs-2.1-r2/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n#define TRUE 1\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <endian.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/mman.h>\n\n#include \"mksquashfs.h\"\n#include <squashfs_fs.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tprintf(\"mksquashfs: \"s, ## args)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { if(!silent) printf(\"mksquashfs: \"s, ## args); } while(0)\n#define ERROR(s, args...)\t\tdo { fprintf(stderr, s, ## args); } while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { if(restore)\\\n\t\t\t\t\trestorefs();\\\n\t\t\t\t\texit(1); } while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0)\n\nint total_compressed = 0, total_uncompressed = 0;\nint fd;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\nint filesystem_minor_version = SQUASHFS_MINOR;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n\n/* write position within data section */\nunsigned int bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tstruct dir_ent\t\t**list;\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tunsigned char\t\t*index_count_p;\n};\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536], *frag_dups[65536];\nint dup_files = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nchar fragment_data[SQUASHFS_FILE_SIZE];\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\n\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tunsigned int\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tunsigned int\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tunsigned short\t\tfragment_checksum;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\nunsigned int sbytes, sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_bytes, stotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* structure to used to pass in a pointer or an integer\n * to duplicate buffer read helper functions.\n */\nstruct duplicate_buffer_handle {\n\tunsigned char\t*ptr;\n\tunsigned int\tstart;\n};\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern int read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache, unsigned int *last_directory_block,\n\t\tunsigned int *inode_dir_offset, unsigned int *inode_dir_file_size, unsigned int *root_inode_size,\n\t\tunsigned int *inode_dir_start_block, int *file_count, int *sym_count, int *dev_count, int *dir_count,\n\t\tint *fifo_count, int *sock_count, squashfs_uid *uids, unsigned short *uid_count, squashfs_uid *guids,\n\t\tunsigned short *guid_count, unsigned int *uncompressed_file, unsigned int *uncompressed_inode,\n\t\tunsigned int *uncompressed_directory, void (push_directory_entry)(char *, squashfs_inode, int),\n\t\tsquashfs_fragment_entry **fragment_table);\nsquashfs_inode get_sorted_inode(struct stat *buf);\nint read_sort_file(char *filename, int source, char *source_path[]);\nvoid sort_files_and_write(int source, char *source_path[]);\nstruct file_info *duplicate(unsigned char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, int bytes, unsigned int **block_list, int *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes);\n\n#define FALSE 0\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\nvoid restorefs()\n{\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(interrupted == 1)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t\tinterrupted ++;\n\t}\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte = block_size << 1;\n\tunsigned int res;\n\n\tif(!uncompressed && (res = compress2(d, &c_byte, s, size, 9)) != Z_OK) {\n\t\tif(res == Z_MEM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\telse if(res == Z_BUF_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, not enough room in output buffer\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\treturn 0;\n\t}\n\n\tif(uncompressed || c_byte >= size) {\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, unsigned int byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nvoid write_bytes(int fd, unsigned int byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(off + bytes > ((long long)1<<32) - 1 )\n\t\tBAD_ERROR(\"Filesystem greater than maximum size 2^32 - 1\\n\");\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nunsigned int write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tunsigned int start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tunsigned int start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, char *filename, int type, int byte_size, squashfs_block start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct cached_dir_index *index, unsigned int i_count, unsigned int i_size)\n{\n\tstruct stat buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\n\tif(filename[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tbuf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO;\n\t\tbuf.st_uid = getuid();\n\t\tbuf.st_gid = getgid();\n\t\tbuf.st_mtime = time(NULL);\n\t} else if(lstat(filename, &buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\tperror(buffer);\n\t\treturn FALSE;\n\t}\n\n\tbase->mode = SQUASHFS_MODE(buf.st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf.st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf.st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf.st_gid : global_gid);\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->mtime = buf.st_mtime;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %x, blocks %d, fragment %d, offset %d, size %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->mtime = buf.st_mtime;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %x, offset %x\\n\", byte_size,\n\t\t\tstart_block, offset);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->mtime = buf.st_mtime;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %x, offset %x\\n\", byte_size,\n\t\t\tstart_block, offset);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->rdev = (unsigned short) ((major(buf.st_rdev) << 8) |\n\t\t\t(minor(buf.st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x\\n\", dev->rdev);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d\\n\",\t byte);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\");\n\t} else\n\t\treturn FALSE;\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%Lx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid init_dir(struct directory *dir)\n{\n\tif((dir->buff = (char *)malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->list = NULL;\n\tdir->pathname = NULL;\n\tdir->count = dir->current_count = dir->i_count = dir->byte_count = dir->i_size = 0;\n\tdir->dir_is_ldir = TRUE;\n}\n\n\nvoid add_dir(squashfs_inode inode, char *name, int type, struct directory *dir)\n{\n\tchar *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + 6 >= dir->buff + dir->size) {\n\t\tif((buff = (char *) realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE))) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nint write_dir(squashfs_inode *inode, char *filename, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir->dir_is_ldir) {\n\t\tif(create_inode(inode, filename, SQUASHFS_LDIR_TYPE, dir_size, directory_block, directory_offset, NULL, NULL, dir->index, dir->i_count, dir->i_size) == FALSE)\n\t\t\treturn FALSE;\n\t} else {\n\t\tif(create_inode(inode, filename, SQUASHFS_DIR_TYPE, dir_size, directory_block, directory_offset, NULL, NULL, NULL, 0, 0) == FALSE)\n\t\t\treturn FALSE;\n\t}\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%Lx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn TRUE;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment = &fragment_table[fragment->index];\n\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tlong bytes = block_size;\n\t\tchar cbuffer[block_size];\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\n\t\tif((res = uncompress(buffer, &bytes, (const char *) cbuffer, size)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid write_fragment()\n{\n\tint compressed_size;\n\tunsigned char buffer[block_size << 1];\n\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tif(fragments % FRAG_SIZE == 0)\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\tfragment_table[fragments].size = mangle(buffer, fragment_data, fragment_size, block_size, noF, 1);\n\tfragment_table[fragments].start_block = bytes;\n\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(fragment_table[fragments].size);\n\twrite_bytes(fd, bytes, compressed_size, buffer);\n\tbytes += compressed_size;\n\ttotal_uncompressed += fragment_size;\n\ttotal_compressed += compressed_size;\n\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\",fragments, fragment_size, compressed_size);\n\tfragments ++;\n\tfragment_size = 0;\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_BLK, 0, 0};\nstruct fragment *get_and_fill_fragment(char *buff, int size)\n{\n\tstruct fragment *ffrg;\n\n\tif(size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = size;\n\tmemcpy(fragment_data + fragment_size, buff, size);\n\tfragment_size += size;\n\n\treturn ffrg;\n}\n\n\nunsigned int write_fragment_table()\n{\n\tunsigned int start_bytes, frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments),\n\t\tmeta_blocks = SQUASHFS_FRAGMENT_INDEXES(fragments);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2], buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tunsigned short c_byte;\n\tint i, compressed_size;\n\tsquashfs_fragment_index list[meta_blocks];\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d, meta_blocks %d\\n\", fragments, frag_bytes, meta_blocks);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %x, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = i == meta_blocks - 1 ? frag_bytes % SQUASHFS_METADATA_SIZE : SQUASHFS_METADATA_SIZE;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, noF, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tsquashfs_fragment_index slist[meta_blocks];\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\treturn start_bytes;\n}\n\n\nunsigned char *read_from_buffer(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tunsigned char *v = handle->ptr;\n\thandle->ptr += avail_bytes;\t\n\treturn v;\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nunsigned char *read_from_file(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tread_bytes(fd, handle->start, avail_bytes, read_from_file_buffer);\n\thandle->start += avail_bytes;\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(unsigned char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *handle, int l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes = 0;\n\tunsigned char *b;\n\tstruct duplicate_buffer_handle position = *handle;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tb = get_next_file_block(&position, bytes);\n\t\twhile(bytes--) {\n\t\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\t\tchksum += *b++;\n\t\t}\n\t}\n\n\treturn chksum;\n}\n\n\nint cached_frag = -1;\nvoid add_file(int start, int file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tstruct file_info *dupl_ptr;\n\tchar *datap;\n\tstruct duplicate_buffer_handle handle;\n\t\n\tif(!duplicate_checking)\n\t\treturn;\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\tif(fragment == cached_frag || fragment == SQUASHFS_INVALID_BLK)\n\t\tdatap = fragment_data + offset;\n\telse\n\t\tdatap = get_fragment(fragment_data, frg);\n\thandle.start = start;\n\tif((dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &frg, datap, bytes)) != NULL)\n\t\tdupl_ptr->fragment = frg;\n\tcached_frag = fragment;\n}\n\n\nchar cached_fragment[SQUASHFS_FILE_SIZE];\nint cached_frag1 = -1;\n\nstruct file_info *duplicate(unsigned char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, int bytes, unsigned int **block_list, int *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes)\n{\n\tunsigned short checksum = get_checksum(get_next_file_block, file_start, bytes);\n\tstruct duplicate_buffer_handle handle = { frag_data, 0 };\n\tunsigned short fragment_checksum = get_checksum(read_from_buffer, &handle, frag_bytes);\n\tstruct file_info *dupl_ptr = bytes ? dupl[checksum] : frag_dups[fragment_checksum];\n\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size && fragment_checksum == dupl_ptr->fragment_checksum) {\n\t\t\tunsigned char buffer1[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tunsigned int dup_bytes = dupl_ptr->bytes, dup_start = dupl_ptr->start;\n\t\t\tstruct duplicate_buffer_handle position = *file_start;\n\t\t\tunsigned char *buffer;\n\t\t\twhile(dup_bytes) {\n\t\t\t\tint avail_bytes = dup_bytes > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : dup_bytes;\n\n\t\t\t\tbuffer = get_next_file_block(&position, avail_bytes);\n\t\t\t\tread_bytes(fd, dup_start, avail_bytes, buffer1);\n\t\t\t\tif(memcmp(buffer, buffer1, avail_bytes) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_bytes -= avail_bytes;\n\t\t\t\tdup_start += avail_bytes;\n\t\t\t}\n\t\t\tif(dup_bytes == 0) {\n\t\t\t\tchar *fragment_buffer1;\n\t\t\t\t\n\t\t\t\tif(dupl_ptr->fragment->index == fragments || dupl_ptr->fragment->index == SQUASHFS_INVALID_BLK)\n\t\t\t\t\tfragment_buffer1 = fragment_data + dupl_ptr->fragment->offset;\n\t\t\t\telse if(dupl_ptr->fragment->index == cached_frag1)\n\t\t\t\t\tfragment_buffer1 = cached_fragment + dupl_ptr->fragment->offset;\n\t\t\t\telse {\n\t\t\t\t\tfragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment);\n\t\t\t\t\tcached_frag1 = dupl_ptr->fragment->index;\n\t\t\t\t}\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(frag_data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%x, size %d, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->start = *start;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tif((dupl_ptr->block_list = (unsigned int *) malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\t}\n\t\n\tmemcpy(dupl_ptr->block_list, *block_list, blocks * sizeof(unsigned int));\n\tdup_files ++;\n\tif(bytes) {\n\t\tdupl_ptr->next = dupl[checksum];\n\t\tdupl[checksum] = dupl_ptr;\n\t} else {\n\t\tdupl_ptr->next = frag_dups[fragment_checksum];\n\t\tfrag_dups[fragment_checksum] = dupl_ptr;\n\t}\n\n\treturn dupl_ptr;\n}\n\n\n#define MINALLOCBYTES (1024 * 1024)\nint write_file(squashfs_inode *inode, char *filename, long long size, int *duplicate_file)\n{\n\tunsigned int frag_bytes, file, start, file_bytes = 0, block = 0;\n\tunsigned int c_byte;\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\tunsigned int blocks = (read_size + block_size - 1) >> block_log;\n\tunsigned int block_list[blocks], *block_listp = block_list;\n\tchar buff[block_size], *c_buffer;\n\tint allocated_blocks = blocks, i, bbytes, whole_file = 1;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr = NULL;\n\tstruct duplicate_buffer_handle handle;\n\n\tif(!no_fragments && (read_size < block_size || always_use_fragments)) {\n\t\tallocated_blocks = blocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %Ld bytes\\n\", filename, SQUASHFS_MAX_FILE_SIZE);\n\n\ttotal_bytes += read_size;\n\tif((file = open(filename, O_RDONLY)) == -1) {\n\t\tperror(\"Error in opening file, skipping...\");\n\t\treturn FALSE;\n\t}\n\n\tdo {\n\t\tif((c_buffer = (char *) malloc((allocated_blocks + 1) << block_log)) == NULL) {\n\t\t\tTRACE(\"Out of memory allocating write_file buffer, allocated_blocks %d, blocks %d\\n\", allocated_blocks, blocks);\n\t\t\twhole_file = 0;\n\t\t\tif((allocated_blocks << (block_log - 1)) < MINALLOCBYTES)\n\t\t\t\tBAD_ERROR(\"Out of memory allocating write_file buffer, could not allocate %d blocks (%d Kbytes)\\n\", allocated_blocks, allocated_blocks << (block_log - 10));\n\t\t\tallocated_blocks >>= 1;\n\t\t}\n\t} while(!c_buffer);\n\n\tfor(start = bytes; block < blocks; file_bytes += bbytes) {\n\t\tfor(i = 0, bbytes = 0; (i < allocated_blocks) && (block < blocks); i++) {\n\t\t\tint available_bytes = read_size - (block * block_size) > block_size ? block_size : read_size - (block * block_size);\n\t\t\tif(read(file, buff, available_bytes) == -1)\n\t\t\t\tgoto read_err;\n\t\t\tc_byte = mangle(c_buffer + bbytes, buff, available_bytes, block_size, noD, 1);\n\t\t\tblock_list[block ++] = c_byte;\n\t\t\tbbytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\t}\n\t\tif(!whole_file) {\n\t\t\twrite_bytes(fd, bytes, bbytes, c_buffer);\n\t\t\tbytes += bbytes;\n\t\t}\n\t}\n\n\tif(frag_bytes != 0)\n\t\tif(read(file, buff, frag_bytes) == -1)\n\t\t\tgoto read_err;\n\n\tclose(file);\n\tif(whole_file) {\n\t\thandle.ptr = c_buffer;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_buffer, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t\twrite_bytes(fd, bytes, file_bytes, c_buffer);\n\t\tbytes += file_bytes;\n\t} else {\n\t\thandle.start = start;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\tbytes = start;\n\t\t\tif(!block_device)\n\t\t\t\tftruncate(fd, bytes);\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t}\n\n\tfragment = get_and_fill_fragment(buff, frag_bytes);\n\tif(duplicate_checking)\n\t\tdupl_ptr->fragment = fragment;\n\n\t*duplicate_file = FALSE;\n\nwr_inode:\n\tfree(c_buffer);\n\tfile_count ++;\n\treturn create_inode(inode, filename, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL, 0, 0);\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tfree(c_buffer);\n\treturn FALSE;\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\n#define DIR_ENTRIES 256\n\nstruct dir_ent {\n\tchar *name;\n\tchar *pathname;\n\tstruct old_root_entry_info *data;\n};\n\n\nvoid inline add_dir_entry(char *name, char *pathname, void *data, struct directory *dir)\n{\n\t\tif((dir->count % DIR_ENTRIES) == 0)\n\t\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\t\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\t\tdir->list[dir->count]->name = strdup(name);\n\t\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\t\tdir->list[dir->count ++]->data = data;\n\t\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct directory *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif(filesystem_minor_version == 0 || (dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nint linux_opendir(char *pathname, struct directory *dir)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\n\tdir->pathname = strdup(pathname);\n\tif((linuxdir = opendir(pathname)) == NULL)\n\t\treturn 0;\n\n\twhile((d_name = readdir(linuxdir)) != NULL) {\n\t\tif(strcmp(d_name->d_name, \".\") != 0 && strcmp(d_name->d_name, \"..\") != 0)\n\t\t\tadd_dir_entry(d_name->d_name, NULL, NULL, dir);\n\t}\n\n\tclosedir(linuxdir);\n\tsort_directory(dir);\n\treturn 1;\n}\n\n\nint encomp_opendir(char *pathname, struct directory *dir)\n{\n\tint i, n, pass;\n\tchar *basename, dir_name[8192];\n\n\tfor(i = 0; i < old_root_entries; i++)\n\t\tadd_dir_entry(old_root_entry[i].name, \"\", &old_root_entry[i], dir);\n\n\tfor(i = 0; i < source; i++) {\n\t\tif((basename = getbase(source_path[i])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[i]);\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tadd_dir_entry(dir_name, source_path[i], NULL, dir);\n\t}\n\tsort_directory(dir);\n\treturn 1;\n}\n\n\nint single_opendir(char *pathname, struct directory *dir)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tint i, pass;\n\tchar dir_name[1024], filename[8192];\n\n\tfor(i = 0; i < old_root_entries; i++)\n\t\tadd_dir_entry(old_root_entry[i].name, \"\", &old_root_entry[i], dir);\n\n\tif((linuxdir = opendir(pathname)) == NULL)\n\t\treturn 0;\n\n\twhile((d_name = readdir(linuxdir)) != NULL) {\n\t\tif(strcmp(d_name->d_name, \".\") == 0 || strcmp(d_name->d_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(filename, pathname), \"/\"), d_name->d_name);\n\t\tadd_dir_entry(dir_name, filename, NULL, dir);\n\t}\n\n\tclosedir(linuxdir);\n\tsort_directory(dir);\n\treturn 1;\n}\n\n\nint linux_readdir(struct directory *dir, char **filename, char **dir_name)\n{\n\tint current_count;\n\n\twhile((current_count = dir->current_count++) < dir->count)\n\t\tif(dir->list[current_count]->data)\n\t\t\tadd_dir(dir->list[current_count]->data->inode, dir->list[current_count]->name,\n\t\t\t\tdir->list[current_count]->data->type, dir);\n\t\telse {\n\t\t\tif(dir->list[current_count]->pathname)\n\t\t\t\t*filename = dir->list[current_count]->pathname;\n\t\t\telse\n\t\t\t\tstrcat(strcat(strcpy(*filename, dir->pathname), \"/\"), dir->list[current_count]->name);\n\t\t\t*dir_name = dir->list[current_count]->name;\n\t\t\treturn 1;\n\t\t}\n\treturn FALSE;\t\n}\n\n\nvoid linux_freedir(struct directory *dir)\n{\n\tint i;\n\n\tfor(i = 0; i < dir->count; i++) {\n\t\tif(dir->list[i]->pathname)\n\t\t\tfree(dir->list[i]->pathname);\n\t\tfree(dir->list[i]->name);\n\t\tfree(dir->list[i]);\n\t}\n\tif(dir->index)\n\t\tfree(dir->index);\n\tif(dir->list)\n\t\tfree(dir->list);\n\tfree(dir->buff);\n}\n\n\nint dir_scan(squashfs_inode *inode, char *pathname, int (_opendir)(char *, struct directory *))\n{\n\tstruct stat buf;\n\tchar filename2[8192], *filename = filename2, *dir_name;\n\tint squashfs_type;\n\tstruct directory dir;\n\tint result = FALSE;\n\t\n\tinit_dir(&dir);\n\tif(_opendir(pathname, &dir) == 0) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\t\n\twhile(linux_readdir(&dir, &filename, &dir_name) != FALSE) {\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tswitch(buf.st_mode & S_IFMT) {\n\t\t\tcase S_IFREG: {\n\t\t\t\tint duplicate_file;\n\n\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\tif(!sorted) {\n\t\t\t\t\tresult = write_file(inode, filename, buf.st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %Ld bytes, %s\\n\", filename, buf.st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t} else\n\t\t\t\t\t*inode = get_sorted_inode(&buf);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase S_IFDIR:\n\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\tresult = dir_scan(inode, filename, linux_opendir);\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFLNK:\n\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\tresult = create_inode(inode, filename, squashfs_type, 0, 0, 0, NULL, NULL, NULL, 0, 0);\n\t\t\t\tINFO(\"symbolic link %s inode 0x%Lx\\n\", dir_name, *inode);\n\t\t\t\tsym_count ++;\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFCHR:\n\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\tresult = create_inode(inode, filename, squashfs_type, 0, 0, 0, NULL, NULL, NULL, 0, 0);\n\t\t\t\tINFO(\"character device %s inode 0x%Lx\\n\", dir_name, *inode);\n\t\t\t\tdev_count ++;\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFBLK:\n\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\tresult = create_inode(inode, filename, squashfs_type, 0, 0, 0, NULL, NULL, NULL, 0, 0);\n\t\t\t\tINFO(\"block device %s inode 0x%Lx\\n\", dir_name, *inode);\n\t\t\t\tdev_count ++;\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFIFO:\n\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\tresult = create_inode(inode, filename, squashfs_type, 0, 0, 0, NULL, NULL, NULL, 0, 0);\n\t\t\t\tINFO(\"fifo %s inode 0x%Lx\\n\", dir_name, *inode);\n\t\t\t\tfifo_count ++;\n\t\t\t\tbreak;\n\n\t\t\tcase S_IFSOCK:\n\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\tresult = create_inode(inode, filename, squashfs_type, 0, 0, 0, NULL, NULL, NULL, 0, 0);\n\t\t\t\tINFO(\"unix domain socket %s inode 0x%Lx\\n\", dir_name, *inode);\n\t\t\t\tsock_count ++;\n\t\t\t\tbreak;\n\n\t\t\t default:\n\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf.st_mode);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\tif(result)\n\t\t\tadd_dir(*inode, dir_name, squashfs_type, &dir);\n\t}\n\n\tresult = write_dir(inode, pathname, &dir);\n\tINFO(\"directory %s inode 0x%Lx\\n\", pathname, *inode);\n\nerror:\n\tlinux_freedir(&dir);\n\n\treturn result;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 9; i <= 16; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 2.1\\n\");\\\n\tprintf(\"copyright (C) 2004 Phillip Lougher (plougher@users.sourceforge.net)\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, delete = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 512 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-2.0\") == 0)\n\t\t\tfilesystem_minor_version = 0;\n\n\t\telse if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-2.0\\t\\t\\tcreate a 2.0 filesystem\\n\");\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t\tif(!delete) {\n\t\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\t\tif(S_ISREG(buf.st_mode)) { /* reopen truncating file */\n\t\t\t\t\tclose(fd);\n\t\t\t                if((fd = open(argv[source + 1], O_TRUNC  | O_RDWR)) == -1) {\n\t\t\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\t\t\texit(1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdelete = TRUE;\n\t\t\t}\n\n\t\t}\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\texit(1);\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, filesystem_minor_version, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data;\n\t\tunsigned root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\tfilesystem_minor_version = sBlk.s_minor;\n\t\t\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, add_old_root_entry, &fragment_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\texit(1);\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, filesystem_minor_version, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -2.0 options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + (inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1));\n\t\tuncompressed_data = inode_dir_offset + (inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1));\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(stat(source_path[0], &buf) == -1) {\n\t\tperror(\"Cannot stat source directory\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(sorted)\n\t\tsort_files_and_write(source, source_path);\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], linux_opendir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], single_opendir);\n\telse\n\t\tdir_scan(&inode, \"\", encomp_opendir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = filesystem_minor_version;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\n\tTRACE(\"sBlk->inode_table_start 0x%x\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%x\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%x\\n\", sBlk.fragment_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tunsigned char temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s filesystem, data block size %d, %s data, %s metadata, %s fragments\\n\", be ?\n\t\t\"Big endian\" : \"Little endian\", block_size, noD ? \"uncompressed\" : \"compressed\", noI ?\n\t\"uncompressed\" : \"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\tclose(fd);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/squashfs-2.1-r2/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/squashfs-2.1-r2/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, unsigned int, int, char *);\nextern int add_file(int, int, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#include <endian.h>\n#include \"read_fs.h\"\n#include <squashfs_fs.h>\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tprintf(\"mksquashfs: \"s, ## args)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tfprintf(stderr, s, ## args)\n\nint swap;\n\nint read_block(int fd, int start, int *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tunsigned char buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tlong bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tif((res = uncompress(block, &bytes, (const char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, int start, int end, int root_inode_start, int root_inode_offset, squashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, unsigned int *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%x, end 0x%x, root_inode_start 0x%x\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%x containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%x\\n\", start);\n\t\tif((bytes += read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_BLK ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_BLK ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tint file_bytes = 0, i, start = inode.start_block;\n\t\t\t\tunsigned int block_list[blocks];\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %d, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tfree(*inode_table);\n\t\t\t\treturn FALSE;\n\t\t}\n\t}\n\t\n\treturn files;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major == 1)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS 1.x filesystem.  Appending\\nto SQUASHFS 1.x filesystems is not supported.  Please convert it to a SQUASHFS 2.1 filesystem...n\", source);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d), I support (%d: <= %d)\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid SQUASHFS superblock on %s.\\n\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not\" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFilesystem size %d bytes\\n\", sBlk->bytes_used);\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %x\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %x\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %x\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %x\\n\", sBlk->fragment_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, int start, int offset, int size, int *last_directory_block,\n\t\tsquashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint bytes = 0, dir_count;\n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%x, bytes read so far %d\\n\", start, bytes);\n\t\t*last_directory_block = start;\n\t\tif((bytes += read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%x\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%x, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nint read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache, unsigned int *last_directory_block,\n\t\tunsigned int *inode_dir_offset, unsigned int *inode_dir_file_size, unsigned int *root_inode_size,\n\t\tunsigned int *inode_dir_start_block, int *file_count, int *sym_count, int *dev_count, int *dir_count,\n\t\tint *fifo_count, int *sock_count, squashfs_uid *uids, unsigned short *uid_count, squashfs_uid *guids,\n\t\tunsigned short *guid_count, unsigned int *uncompressed_file, unsigned int *uncompressed_inode,\n\t\tunsigned int *uncompressed_directory, void (push_directory_entry)(char *, squashfs_inode, int),\n\t\tsquashfs_fragment_entry **fragment_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tunsigned int start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode), root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode),\n\t\troot_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd,  sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, sBlk->directory_table_start + *inode_dir_start_block,\n\t\t\t\t*inode_dir_offset, *inode_dir_file_size, last_directory_block, sBlk, push_directory_entry))\n\t\t\t\t== NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\t*last_directory_block -= sBlk->directory_table_start;\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/squashfs-2.1-r2/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/squashfs-2.1-r2/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tprintf(\"mksquashfs: \"s, ## args)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tif(!silent) printf(\"mksquashfs: \"s, ## args)\n#define ERROR(s, args...)\t\tfprintf(stderr, s, ## args)\n#define EXIT_MKSQUASHFS()\t\texit(1)\n#define BAD_ERROR(s, args...)\t\t{\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t}\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry {\n\tchar *filename;\n\tlong long size;\n\tino_t st_ino;\n\tdev_t st_dev;\n\tstruct priority_entry *next;\n};\n\nstruct priority_entry *priority_list[65536];\n\nstruct sorted_inode_entry {\n\tsquashfs_inode inode;\n\tino_t\tst_ino;\n\tdev_t\tst_dev;\n\tstruct sorted_inode_entry *next;\n};\n\nstruct sorted_inode_entry *sorted_inode_list[65536];\n\nextern int silent;\nextern int excluded(char *filename, struct stat *buf);\nextern squashfs_inode write_file(char *filename, long long size, int *c_size);\n\n\nint add_to_sorted_inode_list(squashfs_inode inode, dev_t st_dev, ino_t st_ino)\n{\n\tint hash = st_ino & 0xffff;\n\tstruct sorted_inode_entry *new_sorted_inode_entry;\n\n\tif((new_sorted_inode_entry = malloc(sizeof(struct sorted_inode_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating sorted inode entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_sorted_inode_entry->inode = inode;\n\tnew_sorted_inode_entry->st_ino = st_ino;\n\tnew_sorted_inode_entry->st_dev = st_dev;\n\tnew_sorted_inode_entry->next = sorted_inode_list[hash];\n\tsorted_inode_list[hash] = new_sorted_inode_entry;\n\n\treturn TRUE;\n}\n\n\t\nsquashfs_inode get_sorted_inode(struct stat *buf)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sorted_inode_entry *sorted_inode_entry;\n\n\tfor(sorted_inode_entry = sorted_inode_list[hash]; sorted_inode_entry; sorted_inode_entry = sorted_inode_entry->next)\n\t\tif(buf->st_ino == sorted_inode_entry->st_ino && buf->st_dev == sorted_inode_entry->st_dev)\n\t\t\tbreak;\n\n\tif(sorted_inode_entry)\n\t\treturn sorted_inode_entry->inode;\n\telse\n\t\treturn (squashfs_inode) 0;\n}\n\n\nint add_priority_list(char *filename, struct stat *buf, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->filename = strdup(filename);\n\tnew_priority_entry->size = buf->st_size;\n\tnew_priority_entry->st_dev = buf->st_dev;\n\tnew_priority_entry->st_ino = buf->st_ino;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat sort_list dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %Lx, st_ino %Lx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat sort_list dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t}\n\treturn TRUE;\n}\n\n\nvoid generate_file_priorities(char *pathname, int priority, struct stat *buf)\n{\n\tchar filename[8192];\n\tDIR *linuxdir;\n\tstruct dirent *d_name;\n\t\n\tpriority = get_priority(pathname, buf, priority);\n\n\tif((linuxdir = opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\treturn;\n\t}\n\t\n\twhile((d_name = readdir(linuxdir)) != NULL) {\n\t\tif(strcmp(d_name->d_name, \".\") == 0 || strcmp(d_name->d_name, \"..\") == 0)\n\t\t\tcontinue;\n\t\tstrcat(strcat(strcpy(filename, pathname), \"/\"), d_name->d_name);\n\n\t\tif(lstat(filename, buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(excluded(filename, buf))\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(filename, buf, get_priority(filename, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(filename, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tclosedir(linuxdir);\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(int source, char *source_path[])\n{\n\tstruct stat buf;\n\tint i, c_size;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\n\tfor(i = 0; i < source; i++) {\n\t\tif(lstat(source_path[i], &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", source_path[i]);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif(excluded(source_path[i], &buf))\n\t\t\tcontinue;\n\n\t\tswitch(buf.st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(source_path[i], &buf, get_priority(source_path[i], &buf, 0));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(source_path[i], 0, &buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor(i = 0; i < 65536; i++)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->filename);\n\t\t\tinode = write_file(entry->filename, entry->size, &c_size);\n\t\t\tINFO(\"file %s, size %d bytes, inode 0x%Lx\\n\", entry->filename, c_size, inode);\n\t\t\tINFO(\"\\t%.2f%% of uncompressed file size (%Ld bytes)\\n\", ((float) c_size / entry->size) * 100.0, entry->size);\n\t\t\tadd_to_sorted_inode_list(inode, entry->st_dev, entry->st_ino);\n\t\t}\n}\n"
  },
  {
    "path": "src/squashfs-2.1-r2/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#define SQUASHFS_MAJOR\t\t\t2\n#define SQUASHFS_MINOR\t\t\t1\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) 0xffffffff)\n#define SQUASHFS_USED_BLK\t\t((long long) 0xfffffffe)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, SQUASHFS_NOI)\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, SQUASHFS_NOD)\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, SQUASHFS_NOF)\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, SQUASHFS_CHECK)\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, duplicate_checking)\t(noi | (nod << 1) | (check_data << 2) | (nof << 3) | (no_frag << 4) | (always_frag << 5) | (duplicate_checking << 6))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t\t\t\t(B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \\\n\t\t\t\t\t(B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an uncompressed\n * offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode)(((squashfs_inode) (A) << 16)\\\n\t\t\t\t\t+ (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + ((b) >> 2) + 1))\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\ntypedef unsigned int\t\t\tsquashfs_fragment_index;\n#define SQUASHFS_FRAGMENT_BYTES(A)\t(A * sizeof(squashfs_fragment_entry))\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))\n#define SQUASHFS_CACHED_FRAGMENTS\t3\n\n/* from squashfs 3.0 */\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t32\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n\n/*\n * definitions for structures on disk\n */\n\ntypedef unsigned int\t\tsquashfs_block;\ntypedef long long\t\tsquashfs_inode;\n\ntypedef unsigned int\t\tsquashfs_uid;\n\ntypedef struct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used;\n\tunsigned int\t\tuid_start;\n\tunsigned int\t\tguid_start;\n\tunsigned int\t\tinode_table_start;\n\tunsigned int\t\tdirectory_table_start;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode\t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start;\n} __attribute__ ((packed)) squashfs_super_block;\n\ntypedef struct {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed)) squashfs_dir_index;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed)) squashfs_base_inode_header;\n\ntypedef squashfs_base_inode_header squashfs_ipc_inode_header;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed)) squashfs_dev_inode_header;\n\t\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed)) squashfs_symlink_inode_header;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tsquashfs_block\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:SQUASHFS_MAX_FILE_SIZE_LOG;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed)) squashfs_reg_inode_header;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed)) squashfs_dir_inode_header;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tsquashfs_dir_index\tindex[0];\n} __attribute__  ((packed)) squashfs_ldir_inode_header;\n\ntypedef union {\n\tsquashfs_base_inode_header\tbase;\n\tsquashfs_dev_inode_header\tdev;\n\tsquashfs_symlink_inode_header\tsymlink;\n\tsquashfs_reg_inode_header\treg;\n\tsquashfs_dir_inode_header\tdir;\n\tsquashfs_ldir_inode_header\tldir;\n\tsquashfs_ipc_inode_header\tipc;\n} squashfs_inode_header;\n\t\ntypedef struct {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed)) squashfs_dir_entry;\n\ntypedef struct {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed)) squashfs_dir_header;\n\ntypedef struct {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed)) squashfs_fragment_entry;\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n#ifdef SQUASHFS_1_0_COMPATIBILITY\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed)) squashfs_base_inode_header_1;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed)) squashfs_ipc_inode_header_1;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed)) squashfs_dev_inode_header_1;\n\t\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed)) squashfs_symlink_inode_header_1;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tsquashfs_block\t\tstart_block;\n\tunsigned int\t\tfile_size:SQUASHFS_MAX_FILE_SIZE_LOG;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed)) squashfs_reg_inode_header_1;\n\ntypedef struct {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed)) squashfs_dir_inode_header_1;\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n#endif\n\n#ifdef __KERNEL__\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#include <asm/byteorder.h>\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n#endif\n#endif\n"
  },
  {
    "path": "src/squashfs-2.1-r2/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n *  Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * 08/11/06: this copy modified to handle DD-WRT images with changed\n *  superblock signature.\n *\n * unsquash.c\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n/*#include \"global.h\"*/\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0, dev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE;\nchar **created_inode;\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry; hash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes, (const unsigned char *) data, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end, squashfs_super_block *sBlk)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, unsigned int mode, unsigned int uid, unsigned int guid,\nunsigned int mtime, unsigned int set_mode)\n{\n\tstruct utimbuf times = { (time_t) mtime, (time_t) mtime };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(set_mode && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(geteuid() == 0) {\n\t\tuid_t uid_value = (uid_t) uid_table[uid];\n\t\tuid_t guid_value = guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[guid];\n\n\t\tif(chown(pathname, uid_value, guid_value) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids(squashfs_super_block *sBlk)\n{\n\tif((uid_table = malloc((sBlk->no_uids + sBlk->no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk->no_uids;\n\n\tif(read_bytes(sBlk->uid_start, (sBlk->no_uids + sBlk->no_guids) * sizeof(unsigned int), (char *) uid_table) ==\n\t\t\tFALSE)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table(squashfs_super_block *sBlk)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL, ((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint write_file(char *pathname, unsigned int fragment, unsigned int frag_bytes, unsigned int offset,\nunsigned int blocks, long long start, char *block_ptr, unsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY, (mode_t) mode)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write(file_fd, file_data, bytes) < bytes) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write(file_fd, fragment_data + offset, frag_bytes) < frag_bytes) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\t\t\n\nint create_inode(char *pathname, unsigned int start_block, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tlong long start = sBlk->inode_table_start + start_block;\n\tsquashfs_inode_header header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n/*\n\tif(created_inode[header.base.inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(link(created_inode[header.base.inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n*/\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size\n\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>\n\t\t\t\tsBlk->block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,\n\t\t\t\t\tblock_ptr + sizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n/*\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size\n\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>\n\t\t\t\tsBlk->block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,\n\t\t\t\t\tblock_ptr + sizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n*/\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(geteuid() == 0) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(geteuid() == 0) {\n\t\t\t\tif(mknod(pathname, inodep->inode_type == SQUASHFS_CHRDEV_TYPE ? S_IFCHR : S_IFBLK,\n\t\t\t\t\t\t\tmakedev((inodep->rdev >> 8) & 0xff, inodep->rdev & 0xff))\n\t\t\t\t\t\t\t== -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, 0/*inodep->mtime todo: fix proper*/, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\t0 /* header.base.mtime todo */, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\t/*created_inode[header.base.inode_number - 1] = strdup(pathname);*/\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end, squashfs_super_block *sBlk)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table = realloc(directory_table, size += SQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes, sBlk)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_openddir(unsigned int block_start, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start = sBlk->inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk->directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block, unsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tstruct dir *dir = squashfs_openddir(start_block, offset, sBlk);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(lsonly || info)\n\t\t\tprintf(\"%s\\n\", pathname);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, sBlk);\n\t\telse\n\t\t\tif(!lsonly)\n\t\t\t\tcreate_inode(pathname, start_block, offset, sBlk);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, TRUE);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nint read_super(squashfs_super_block *sBlk, char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d)\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tERROR(\"I only support Squashfs 3.0 filesystems!  Later releases will support older Squashfs filesystems\\n\");\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tTRACE(\"Found a valid %s endian SQUASHFS superblock on %s.\\n\", swap ? \"little\" : \"big\", source);\n#else\n\tTRACE(\"Found a valid %s endian SQUASHFS superblock on %s.\\n\", swap ? \"big\" : \"little\", source);\n#endif\n\n\tTRACE(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not\" : \"\");\n\tTRACE(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tTRACE(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tTRACE(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tTRACE(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tTRACE(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tTRACE(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start 0x%llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.0 for suqashfs 2.x images \\n\");\\\n\tprintf(\"copyright (C) 2006 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tsquashfs_super_block sBlk;\n\tchar *dest = \"squashfs-root\";\n\tint i, version = FALSE;\n\tint retval = EXIT_FAILURE;\n\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0) {\n\t\t\tif(++i == argc)\n\t\t\t\tgoto options;\n\t\t\tdest = argv[i];\n\t\t}\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [-ls | -dest] filesystem\\n\", argv[0]);\n\t\t\tERROR(\"\\t-version\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-info\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-ls\\t\\t\\tlist filesystem only\\n\");\n\t\t\tERROR(\"\\t-dest <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(&sBlk, argv[i]) == FALSE)\n\t\texit(1);\n\n\tblock_size = sBlk.block_size;\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids(&sBlk);\n\tread_fragment_table(&sBlk);\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start, &sBlk);\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start, &sBlk);\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), &sBlk);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n\tif(file_count > 0)\n\t{\n\t\tretval = EXIT_SUCCESS;\n\t}\n\n\treturn retval;\n}\n"
  },
  {
    "path": "src/squashfs-3.0/Makefile",
    "content": "CC := gcc\nCXX := g++\nINCLUDEDIR = .\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -O2\nLZMAPATH = ../lzma/C/7zip/Compress/LZMA_Lib\n\nall: unsquashfs mksquashfs unsquashfs-lzma mksquashfs-lzma\n\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\t$(CC) mksquashfs.o read_fs.o sort.o -lz -o $@\n\nmksquashfs-lzma: mksquashfs.o read_fs.o sort.o\n\tmake -C $(LZMAPATH)\n\t$(CXX) -O3 mksquashfs.o read_fs.o sort.o -L$(LZMAPATH) -llzma -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nunsquashfs-lzma: unsquashfs.o\n\tmake -C $(LZMAPATH)\n\t$(CXX) -O3 unsquashfs.o -L$(LZMAPATH) -llzma -o $@\n\nunsquashfs: unsquashfs.o\n\t$(CC) unsquashfs.o -lz -o $@\n\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h\n\nclean:\n\trm -f *.o\n\trm -f mksquashfs\n\trm -f unsquashfs\n\trm -f mksquashfs-lzma\n\trm -f unsquashfs-lzma\n\trm -f mksquashfs.exe\n\trm -f unsquashfs.exe\n\trm -f mksquashfs-lzma.exe\n\trm -f unsquashfs-lzma.exe\n\tmake -C $(LZMAPATH) clean\n"
  },
  {
    "path": "src/squashfs-3.0/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\n\ntypedef union squashfs_inode_header squashfs_inode_header;\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n#endif\n"
  },
  {
    "path": "src/squashfs-3.0/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>no\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.c\n */\n\n/*\n jc: This build tweaked to add -magic [file] parameter to fix brainslayer's mod\n  of 08/10/06 firmware squashfs image signature change.\n*/\n\n\n#define FALSE 0\n#define TRUE 1\n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/mman.h>\n\n/* jc */\n//#define SQUASHFS_TRACE\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n/* jc debugging */\n#warning \"mksquashfs: (jc) building on non-linux system.\"\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n\n\n/*********************************************************/\n/* jc */\nu_int32_t g_nMagic=SQUASHFS_MAGIC;\n// always flip, regardless of endianness of machine\nu_int32_t flip_endian(u_int32_t nValue)\n{\n\t// my crappy endian switch\n\tu_int32_t nR;\n\tu_int32_t nByte1=(nValue&0xff000000)>>24;\n\tu_int32_t nByte2=(nValue&0x00ff0000)>>16;\n\tu_int32_t nByte3=(nValue&0x0000ff00)>>8;\n\tu_int32_t nByte4=nValue&0x0ff;\n\tnR=nByte4<<24;\n\tnR|=(nByte3<<16);\n\tnR|=(nByte2<<8);\n\tnR|=nByte1;\n\treturn nR;\n}\n/*********************************************************/\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536], *frag_dups[65536];\nint dup_files = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nchar fragment_data[SQUASHFS_FILE_SIZE];\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\n\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tunsigned short\t\tfragment_checksum;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* structure to used to pass in a pointer or an integer\n * to duplicate buffer read helper functions.\n */\nstruct duplicate_buffer_handle {\n\tchar\t*ptr;\n\tlong long\tstart;\n};\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table);\nint get_sorted_inode(squashfs_inode *inode, struct stat *buf);\nint read_sort_file(char *filename, int source, char *source_path[]);\nvoid sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, long long bytes, unsigned int **block_list, long long *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes);\nstruct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\nvoid restorefs()\n{\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(interrupted == 1)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t\tinterrupted ++;\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte = block_size << 1;\n\tunsigned int res;\n\n\tif(!uncompressed && (res = compress2((unsigned char *) d, &c_byte, (unsigned char *) s, size, 9)) != Z_OK) {\n\t\tif(res == Z_MEM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\telse if(res == Z_BUF_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, not enough room in output buffer\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\treturn 0;\n\t}\n\n\tif(uncompressed || c_byte >= size) {\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\treturn FALSE;\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nint write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir) {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir) == FALSE)\n\t\t\treturn FALSE;\n\t} else {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL) == FALSE)\n\t\t\treturn FALSE;\n\t}\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn TRUE;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment = &fragment_table[fragment->index];\n\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\n\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid write_fragment()\n{\n\tint compressed_size;\n\tchar buffer[block_size << 1];\n\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tif(fragments % FRAG_SIZE == 0)\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\tfragment_table[fragments].size = mangle(buffer, fragment_data, fragment_size, block_size, noF, 1);\n\tfragment_table[fragments].start_block = bytes;\n\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(fragment_table[fragments].size);\n\twrite_bytes(fd, bytes, compressed_size, buffer);\n\tbytes += compressed_size;\n\ttotal_uncompressed += fragment_size;\n\ttotal_compressed += compressed_size;\n\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\",fragments, fragment_size, compressed_size);\n\tfragments ++;\n\tfragment_size = 0;\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(char *buff, int size)\n{\n\tstruct fragment *ffrg;\n\n\tif(size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = size;\n\tmemcpy(fragment_data + fragment_size, buff, size);\n\tfragment_size += size;\n\n\treturn ffrg;\n}\n\n\nlong long write_fragment_table()\n{\n\tlong long start_bytes;\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments),\n\t\tmeta_blocks = SQUASHFS_FRAGMENT_INDEXES(fragments);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2], buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tunsigned short c_byte;\n\tint i, compressed_size;\n\tsquashfs_fragment_index list[meta_blocks];\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d, meta_blocks %d\\n\", fragments, frag_bytes, meta_blocks);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = i == meta_blocks - 1 ? frag_bytes % SQUASHFS_METADATA_SIZE : SQUASHFS_METADATA_SIZE;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, noF, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tsquashfs_fragment_index slist[meta_blocks];\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\treturn start_bytes;\n}\n\n\nchar *read_from_buffer(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tchar *v = handle->ptr;\n\thandle->ptr += avail_bytes;\t\n\treturn v;\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_file(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tread_bytes(fd, handle->start, avail_bytes, read_from_file_buffer);\n\thandle->start += avail_bytes;\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *handle, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes = 0;\n\tunsigned char *b;\n\tstruct duplicate_buffer_handle position = *handle;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tb = (unsigned char *) get_next_file_block(&position, bytes);\n\t\twhile(bytes--) {\n\t\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\t\tchksum += *b++;\n\t\t}\n\t}\n\n\treturn chksum;\n}\n\n\nint cached_frag = -1;\nvoid add_file(long long start, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tstruct file_info *dupl_ptr;\n\tchar *datap;\n\tstruct duplicate_buffer_handle handle;\n\tunsigned int *block_list = block_listp;\n\n\tif(!duplicate_checking)\n\t\treturn;\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\tif(fragment == cached_frag || fragment == SQUASHFS_INVALID_FRAG)\n\t\tdatap = fragment_data + offset;\n\telse\n\t\tdatap = get_fragment(fragment_data, frg);\n\thandle.start = start;\n\tif((dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &frg, datap, bytes)) != NULL)\n\t\tdupl_ptr->fragment = frg;\n\telse\n\t\tfree(block_list);\n\tcached_frag = fragment;\n}\n\n\nchar cached_fragment[SQUASHFS_FILE_SIZE];\nint cached_frag1 = -1;\n\nstruct file_info *duplicate(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, long long bytes, unsigned int **block_list, long long *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes)\n{\n\tunsigned short checksum = get_checksum(get_next_file_block, file_start, bytes);\n\tstruct duplicate_buffer_handle handle = { frag_data, 0 };\n\tunsigned short fragment_checksum = get_checksum(read_from_buffer, &handle, frag_bytes);\n\tstruct file_info *dupl_ptr = bytes ? dupl[checksum] : frag_dups[fragment_checksum];\n\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size && fragment_checksum == dupl_ptr->fragment_checksum) {\n\t\t\tchar buffer1[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tlong long dup_bytes = dupl_ptr->bytes;\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tstruct duplicate_buffer_handle position = *file_start;\n\t\t\tchar *buffer;\n\t\t\twhile(dup_bytes) {\n\t\t\t\tint avail_bytes = dup_bytes > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : dup_bytes;\n\n\t\t\t\tbuffer = get_next_file_block(&position, avail_bytes);\n\t\t\t\tread_bytes(fd, dup_start, avail_bytes, buffer1);\n\t\t\t\tif(memcmp(buffer, buffer1, avail_bytes) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_bytes -= avail_bytes;\n\t\t\t\tdup_start += avail_bytes;\n\t\t\t}\n\t\t\tif(dup_bytes == 0) {\n\t\t\t\tchar *fragment_buffer1;\n\t\t\t\t\n\t\t\t\tif(dupl_ptr->fragment->index == fragments || dupl_ptr->fragment->index == SQUASHFS_INVALID_FRAG)\n\t\t\t\t\tfragment_buffer1 = fragment_data + dupl_ptr->fragment->offset;\n\t\t\t\telse if(dupl_ptr->fragment->index == cached_frag1)\n\t\t\t\t\tfragment_buffer1 = cached_fragment + dupl_ptr->fragment->offset;\n\t\t\t\telse {\n\t\t\t\t\tfragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment);\n\t\t\t\t\tcached_frag1 = dupl_ptr->fragment->index;\n\t\t\t\t}\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(frag_data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->start = *start;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->block_list = *block_list;\n\n\tdup_files ++;\n\tif(bytes) {\n\t\tdupl_ptr->next = dupl[checksum];\n\t\tdupl[checksum] = dupl_ptr;\n\t} else {\n\t\tdupl_ptr->next = frag_dups[fragment_checksum];\n\t\tfrag_dups[fragment_checksum] = dupl_ptr;\n\t}\n\n\treturn dupl_ptr;\n}\n\n\n#define MINALLOCBYTES (1024 * 1024)\nint write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)\n{\n\tint block = 0, i, file, whole_file = 1, status;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes = 0, start;\n\tchar buff[block_size], *c_buffer = NULL, *filename = dir_ent->pathname;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr = NULL;\n\tstruct duplicate_buffer_handle handle;\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\tint blocks = (read_size + block_size - 1) >> block_log, allocated_blocks = blocks;\n\tunsigned int *block_list, *block_listp;\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif(!no_fragments && (read_size < block_size || always_use_fragments)) {\n\t\tallocated_blocks = blocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %lld bytes\\n\", filename, SQUASHFS_MAX_FILE_SIZE);\n\n\ttotal_bytes += read_size;\n\tif((file = open(filename, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\tlong long bytes = (((long long) allocated_blocks) + 1) << block_log;\n\t\tif(bytes != ((size_t) bytes) || (c_buffer = (char *) malloc(bytes)) == NULL) {\n\t\t\tTRACE(\"Out of memory allocating write_file buffer, allocated_blocks %ld, blocks %d\\n\", allocated_blocks, blocks);\n\t\t\twhole_file = 0;\n\t\t\tif(bytes < MINALLOCBYTES)\n\t\t\t\tBAD_ERROR(\"Out of memory allocating write_file buffer, could not allocate %ld blocks (%d Kbytes)\\n\", allocated_blocks, allocated_blocks << (block_log - 10));\n\t\t\tallocated_blocks >>= 1;\n\t\t}\n\t} while(!c_buffer);\n\n\tfor(start = bytes; block < blocks; file_bytes += bbytes) {\n\t\tfor(i = 0, bbytes = 0; (i < allocated_blocks) && (block < blocks); i++) {\n\t\t\tint available_bytes = read_size - (block * block_size) > block_size ? block_size : read_size - (block * block_size);\n\t\t\tif(read(file, buff, available_bytes) == -1)\n\t\t\t\tgoto read_err;\n\t\t\tc_byte = mangle(c_buffer + bbytes, buff, available_bytes, block_size, noD, 1);\n\t\t\tblock_list[block ++] = c_byte;\n\t\t\tbbytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\t}\n\t\tif(!whole_file) {\n\t\t\twrite_bytes(fd, bytes, bbytes, c_buffer);\n\t\t\tbytes += bbytes;\n\t\t}\n\t}\n\n\tif(frag_bytes != 0)\n\t\tif(read(file, buff, frag_bytes) == -1)\n\t\t\tgoto read_err;\n\n\tclose(file);\n\tif(whole_file) {\n\t\thandle.ptr = c_buffer;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_buffer, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t\twrite_bytes(fd, bytes, file_bytes, c_buffer);\n\t\tbytes += file_bytes;\n\t} else {\n\t\thandle.start = start;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\tbytes = start;\n\t\t\tif(!block_device)\n\t\t\t\tftruncate(fd, bytes);\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t}\n\n\tfragment = get_and_fill_fragment(buff, frag_bytes);\n\tif(duplicate_checking)\n\t\tdupl_ptr->fragment = fragment;\n\n\t*duplicate_file = FALSE;\n\nwr_inode:\n\tfree(c_buffer);\n\tfile_count ++;\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\tif(duplicate_checking == FALSE || *duplicate_file == TRUE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tfree(c_buffer);\n\tfree(block_list);\n\treturn FALSE;\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir_info = dir_scan1(pathname, _readdir);\n\tstruct dir_ent *dir_ent;\n\tstruct inode_info *inode_info;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif((inode_info = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->inode = inode_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tinode_info->nlink = 1;\n\tinode_info->inode_number = root_inode_number ? root_inode_number : dir_inode_no++;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tinode_info->buf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO;\n\t\tinode_info->buf.st_uid = getuid();\n\t\tinode_info->buf.st_gid = getgid();\n\t\tinode_info->buf.st_mtime = time(NULL);\n\t} else if(lstat(pathname, &inode_info->buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\n\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint result = FALSE;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\tresult = write_file(inode, dir_ent, buf->st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tresult = dir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n\t\t\t\t}\n\t\t\tif(result)\n\t\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcaseSQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult = TRUE;\n\t\t}\n\t\t\n\n\t\tif(result)\n\t\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\tresult = write_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n\n\treturn result;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 16; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.0 (2006/03/15)\\n\");\\\n\tprintf(\"copyright (C) 2006 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} \n\t\t\n\t\t/*\n\t\tjc: new -magic param\n\t\t*/\n\t\telse if(strcmp(argv[i], \"-magic\") == 0)\n\t\t{\t\t\t\n\t\t\tif(++i == argc)\n\t\t\t{\n\t\t\t\tERROR(\"%s: -magic missing signature file\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tTRACE(\" debug.mksquashfs-magic: reading %s\\n\", argv[i]);\n\t\t\tFILE *fMagic=fopen(argv[i],\"rb\");\t\t\t\n\t\t\tif(!fMagic)\n\t\t\t{\n\t\t\t\tERROR(\"cannot open %s\\n\", argv[i]);\n\t\t\t\tfclose(fMagic);\n\t\t\t\texit(1);\n\t\t\t}\t\t\t\n\t\t\tif(fread(&g_nMagic,1,sizeof(u_int32_t),fMagic)!=sizeof(u_int32_t))\n\t\t\t{\n\t\t\t\tERROR(\"cannot read %s\\n\", argv[i]);\n\t\t\t\tfclose(fMagic);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tfclose(fMagic);\t\t\t\n\t\t\t/* lame fix for big endiannes problem with new signatures */\n\t\t\t/* am I sure this isn't actually a problem with dd-wrt kernel */\n\t\t\t/* changes were he didn't also update the _ALT endian-flipped */\n\t\t\t/* version of the signature? doesn't matter, I fix it here. */\n\t\t\t#if __BYTE_ORDER == __BIG_ENDIAN\n\t\t\tTRACE(\" debug.mksquashfs-magic: flipping endian\\n\");\n\t\t\tg_nMagic=flip_endian(g_nMagic);\n\t\t\t#endif\n\t\t\tTRACE(\" debug.mksquashfs-magic: signature is 0x%x\\n\", g_nMagic);\n\t\t}\n\t\t\n\t\telse {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\texit(1);\n\t\t}\n\t}\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t} else  {\n\t\tsignal(SIGTERM, sighandler2);\n\t\tsignal(SIGINT, sighandler2);\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\t\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -2.0 options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = inode_dir_offset + inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\t\n\tsBlk.s_magic = g_nMagic; //jc\n\tTRACE(\" stored superblock signature of 0x%x\\n\", sBlk.s_magic);\n\t//sBlk.s_magic = SQUASHFS_MAGIC;\t\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\n\tTRACE(\"sBlk->inode_table_start 0x%x\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%x\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%x\\n\", sBlk.fragment_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tsBlk.unused = SQUASHFS_INVALID_BLK;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s filesystem, data block size %d, %s data, %s metadata, %s fragments\\n\", be ?\n\t\t\"Big endian\" : \"Little endian\", block_size, noD ? \"uncompressed\" : \"compressed\", noI ?\n\t\"uncompressed\" : \"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\tclose(fd);\n\n\treturn 0;\n}\n"
  },
  {
    "path": "src/squashfs-3.0/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/squashfs-3.0/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i, start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i, start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3.0 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is %d.%d, I support 3.0\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid SQUASHFS superblock on %s.\\n\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not\" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block; \n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/squashfs-3.0/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/squashfs-3.0/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern squashfs_inode write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tgenerate_file_priorities(dir, 0, &dir->dir_ent->inode->buf);\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\tif(write_file(&inode, entry->dir, entry->dir->inode->buf.st_size,\n\t\t\t\t\t\t\t&duplicate_file)) {\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/squashfs-3.0/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tstruct inode_info\t*next;\n};\n#endif\n"
  },
  {
    "path": "src/squashfs-3.0/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n\n// jc: for dd-wrt build as of 09/10/06\n#define SQUASHFS_MAGIC_ALT\t\t0x74717368\n#define SQUASHFS_MAGIC_ALT_SWAP\t0x68737174\n\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t3\n#define SQUASHFS_BLKDEV_TYPE\t4\n#define SQUASHFS_CHRDEV_TYPE\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t(A * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n#define SQUASHFS_CACHED_FRAGMENTS\t3\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tunused;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tunused;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->unused, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/squashfs-3.0/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n *  Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * 08/11/06: this copy modified to handle DD-WRT images with changed\n *  superblock signature.\n *\n * unsquash.c\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0, dev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE;\nchar **created_inode;\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry; hash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse {\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes, (const unsigned char *) data, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse {\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end, squashfs_super_block *sBlk)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\t\t\t\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, unsigned int mode, unsigned int uid, unsigned int guid,\nunsigned int mtime, unsigned int set_mode)\n{\n\tstruct utimbuf times = { (time_t) mtime, (time_t) mtime };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(set_mode && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(geteuid() == 0) {\n\t\tuid_t uid_value = (uid_t) uid_table[uid];\n\t\tuid_t guid_value = guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[guid];\n\n\t\tif(chown(pathname, uid_value, guid_value) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids(squashfs_super_block *sBlk)\n{\n\tif((uid_table = malloc((sBlk->no_uids + sBlk->no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk->no_uids;\n\n\tif(read_bytes(sBlk->uid_start, (sBlk->no_uids + sBlk->no_guids) * sizeof(unsigned int), (char *) uid_table) ==\n\t\t\tFALSE)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table(squashfs_super_block *sBlk)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL, ((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint write_file(char *pathname, unsigned int fragment, unsigned int frag_bytes, unsigned int offset,\nunsigned int blocks, long long start, char *block_ptr, unsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY, (mode_t) mode)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write(file_fd, file_data, bytes) < bytes) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write(file_fd, fragment_data + offset, frag_bytes) < frag_bytes) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\t\t\n\nint create_inode(char *pathname, unsigned int start_block, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tlong long start = sBlk->inode_table_start + start_block;\n\tsquashfs_inode_header header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tif(created_inode[header.base.inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(link(created_inode[header.base.inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size\n\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>\n\t\t\t\tsBlk->block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,\n\t\t\t\t\tblock_ptr + sizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size\n\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>\n\t\t\t\tsBlk->block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,\n\t\t\t\t\tblock_ptr + sizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(geteuid() == 0) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(geteuid() == 0) {\n\t\t\t\tif(mknod(pathname, inodep->inode_type == SQUASHFS_CHRDEV_TYPE ? S_IFCHR : S_IFBLK,\n\t\t\t\t\t\t\tmakedev((inodep->rdev >> 8) & 0xff, inodep->rdev & 0xff))\n\t\t\t\t\t\t\t== -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\theader.base.mtime, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[header.base.inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end, squashfs_super_block *sBlk)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table = realloc(directory_table, size += SQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes, sBlk)) == 0)\n\t\t{\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\t\texit(1);\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_openddir(unsigned int block_start, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start = sBlk->inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk->directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block, unsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tstruct dir *dir = squashfs_openddir(start_block, offset, sBlk);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(lsonly || info)\n\t\t\tprintf(\"%s\\n\", pathname);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, sBlk);\n\t\telse\n\t\t\tif(!lsonly)\n\t\t\t\tcreate_inode(pathname, start_block, offset, sBlk);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, TRUE);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nint read_super(squashfs_super_block *sBlk, char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC && sBlk->s_magic != SQUASHFS_MAGIC_ALT) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP || sBlk->s_magic == SQUASHFS_MAGIC_ALT_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d)\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tERROR(\"I only support Squashfs 3.0 filesystems!  Later releases will support older Squashfs filesystems\\n\");\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tTRACE(\"Found a valid %s endian SQUASHFS superblock on %s.\\n\", swap ? \"little\" : \"big\", source);\n#else\n\tTRACE(\"Found a valid %s endian SQUASHFS superblock on %s.\\n\", swap ? \"big\" : \"little\", source);\n#endif\n\n\tTRACE(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not\" : \"\");\n\tTRACE(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tTRACE(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tTRACE(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tTRACE(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tTRACE(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tTRACE(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start 0x%llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.0 (2006/03/15)\\n\");\\\n\tprintf(\"copyright (C) 2006 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tsquashfs_super_block sBlk;\n\tchar *dest = \"squashfs-root\";\n\tint i, version = FALSE;\n\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0) {\n\t\t\tif(++i == argc)\n\t\t\t\tgoto options;\n\t\t\tdest = argv[i];\n\t\t}\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [-ls | -dest] filesystem\\n\", argv[0]);\n\t\t\tERROR(\"\\t-version\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-info\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-ls\\t\\t\\tlist filesystem only\\n\");\n\t\t\tERROR(\"\\t-dest <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(&sBlk, argv[i]) == FALSE)\n\t\texit(1);\n\n\tblock_size = sBlk.block_size;\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids(&sBlk);\n\tread_fragment_table(&sBlk);\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start, &sBlk);\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start, &sBlk);\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), &sBlk);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n}\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/Makefile",
    "content": "INCLUDEDIR = .\nLZMAPATH = ./lzma/C/7zip/Compress/LZMA_Lib\n\nCFLAGS := -I$(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -funroll-loops -mtune=opteron -march=opteron -mfpmath=sse -m3dnow -msse2 -O3 -D_LZMA_PARAMS \n\nall: mksquashfs-lzma unsquashfs-lzma\n\nmksquashfs: mksquashfs.o read_fs.o sort.o\n\t$(CC) mksquashfs.o read_fs.o sort.o -lz -o $@\n\nmksquashfs-lzma: mksquashfs.o read_fs.o sort.o\n\tmake -C $(LZMAPATH)\n\t$(CXX) mksquashfs.o read_fs.o sort.o -L$(LZMAPATH) -llzma -lpthread -o $@\n\nmksquashfs.o: mksquashfs.c squashfs_fs.h mksquashfs.h global.h sort.h\n\nread_fs.o: read_fs.c squashfs_fs.h read_fs.h global.h\n\nsort.o: sort.c squashfs_fs.h global.h sort.h\n\nunsquashfs: unsquashfs.o\n\t$(CC) unsquashfs.o -lz -o $@\n\nunsquashfs-lzma: unsquashfs.o\n\t$(CXX) $(CFLAGS) unsquashfs.o -L$(LZMAPATH) -llzma -lpthread -o $@ \n\nunsquashfs.o: unsquashfs.c squashfs_fs.h read_fs.h global.h\n\nclean:\n\tmake -C $(LZMAPATH) clean\n\trm -f *.o \n\trm -f mksquashfs-lzma\n\trm -f unsquashfs-lzma\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/global.h",
    "content": "#ifndef GLOBAL_H \n#define GLOBAL_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * global.h\n */\n\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef struct squashfs_dir_index squashfs_dir_index;\ntypedef struct squashfs_base_inode_header squashfs_base_inode_header;\ntypedef struct squashfs_ipc_inode_header squashfs_ipc_inode_header;\ntypedef struct squashfs_dev_inode_header squashfs_dev_inode_header;\ntypedef struct squashfs_symlink_inode_header squashfs_symlink_inode_header;\ntypedef struct squashfs_reg_inode_header squashfs_reg_inode_header;\ntypedef struct squashfs_lreg_inode_header squashfs_lreg_inode_header;\ntypedef struct squashfs_dir_inode_header squashfs_dir_inode_header;\ntypedef struct squashfs_ldir_inode_header squashfs_ldir_inode_header;\ntypedef struct squashfs_dir_entry squashfs_dir_entry;\ntypedef struct squashfs_dir_header squashfs_dir_header;\ntypedef struct squashfs_fragment_entry squashfs_fragment_entry;\n\ntypedef union squashfs_inode_header squashfs_inode_header;\ntypedef unsigned int squashfs_uid;\ntypedef long long squashfs_fragment_index;\ntypedef squashfs_inode_t squashfs_inode;\ntypedef squashfs_block_t squashfs_block;\n#endif\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/.built",
    "content": ""
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/.unpacked",
    "content": ""
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/7zC.txt",
    "content": "7z ANSI-C Decoder 4.23\r\n----------------------\r\n\r\n7z ANSI-C Decoder 4.23 Copyright (C) 1999-2005 Igor Pavlov\r\n\r\n7z ANSI-C provides 7z/LZMA decoding.\r\n7z ANSI-C version is simplified version ported from C++ code.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nRead lzma.txt for information about license.\r\n\r\n\r\nFiles\r\n---------------------\r\n\r\n7zAlloc.*    - Allocate and Free\r\n7zBuffer.*   - Buffer structure\r\n7zCrc.*      - CRC32 code\r\n7zDecode.*   - Low level memory->memory decoding\r\n7zExtract.*  - High level stream->memory decoding\r\n7zHeader.*   - .7z format constants\r\n7zIn.*       - .7z archive opening\r\n7zItem.*     - .7z structures\r\n7zMain.c     - Test application\r\n7zMethodID.* - MethodID structure\r\n7zTypes.h    - Base types and constants\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nYou must download 7-Zip program from www.7-zip.org.\r\n\r\nYou can create .7z archive with 7z.exe or 7za.exe:\r\n\r\n  7za.exe a archive.7z *.htm -r -mx -m0fb=255\r\n\r\nIf you have big number of files in archive, and you need fast extracting, \r\nyou can use partly-solid archives:\r\n  \r\n  7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K\r\n\r\nIn that example 7-Zip will use 512KB solid blocks. So it needs to decompress only \r\n512KB for extracting one file from such archive.\r\n\r\n\r\nLimitations of current version of 7z ANSI-C Decoder\r\n---------------------------------------------------\r\n\r\n - It reads only \"FileName\", \"Size\", and \"CRC\" information for each file in archive.\r\n - It supports only LZMA and Copy (no compression) methods.\r\n - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.\r\n \r\nThese limitations will be fixed in future versions.\r\n\r\n\r\nUsing 7z ANSI-C Decoder Test application:\r\n-----------------------------------------\r\n\r\nUsage: 7zDec <command> <archive_name>\r\n\r\n<Command>:\r\n  e: Extract files from archive\r\n  l: List contents of archive\r\n  t: Test integrity of archive\r\n\r\nExample: \r\n\r\n  7zDec l archive.7z\r\n\r\nlists contents of archive.7z\r\n\r\n  7zDec e archive.7z\r\n\r\nextracts files from archive.7z to current folder.\r\n\r\n\r\nHow to use .7z Decoder\r\n----------------------\r\n\r\n.7z Decoder can be compiled in one of two modes:\r\n\r\n1) Default mode. In that mode 7z Decoder will read full compressed \r\n   block to RAM before decompressing.\r\n  \r\n2) Mode with defined _LZMA_IN_CB. In that mode 7z Decoder can read\r\n   compressed block by parts. And you can specify desired buffer size. \r\n   So memory requirements can be reduced. But decompressing speed will \r\n   be 5-10% lower and code size is slightly larger.\r\n\r\n   \r\nMemory allocation\r\n~~~~~~~~~~~~~~~~~\r\n\r\n7z Decoder uses two memory pools:\r\n1) Temporary pool\r\n2) Main pool\r\nSuch scheme can allow you to avoid fragmentation of allocated blocks.\r\n\r\nSteps for using 7z decoder\r\n--------------------------\r\n\r\nUse code at 7zMain.c as example.\r\n\r\n1) Declare variables:\r\n  inStream                     /* implements ISzInStream interface */\r\n  CArchiveDatabaseEx db;       /* 7z archive database structure */\r\n  ISzAlloc allocImp;           /* memory functions for main pool */\r\n  ISzAlloc allocTempImp;       /* memory functions for temporary pool */\r\n\r\n2) call InitCrcTable(); function to initialize CRC structures.\r\n\r\n3) call SzArDbExInit(&db); function to initialize db structures.\r\n\r\n4) call SzArchiveOpen(inStream, &db, &allocMain, &allocTemp) to open archive\r\n\r\nThis function opens archive \"inStream\" and reads headers to \"db\".\r\nAll items in \"db\" will be allocated with \"allocMain\" functions.\r\nSzArchiveOpen function allocates and frees temporary structures by \"allocTemp\" functions.\r\n\r\n5) List items or Extract items\r\n\r\n  Listing code:\r\n  ~~~~~~~~~~~~~\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n\r\n  Extracting code:\r\n  ~~~~~~~~~~~~~~~~\r\n\r\n  SZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n  If you need to decompress more than one file, you can send these values from previous call:\r\n    blockIndex, \r\n    outBuffer, \r\n    outBufferSize,\r\n  You can consider \"outBuffer\" as cache of solid block. If your archive is solid, \r\n  it will increase decompression speed.\r\n\r\n  After decompressing you must free \"outBuffer\":\r\n  allocImp.Free(outBuffer);\r\n\r\n6) call SzArDbExFree(&db, allocImp.Free) to free allocated items in \"db\".\r\n\r\n\r\n\r\n\r\nMemory requirements for .7z decoding \r\n------------------------------------\r\n\r\nMemory usage for Archive opening:\r\n  - Temporary pool:\r\n     - Memory for compressed .7z headers (if _LZMA_IN_CB is not defined)\r\n     - Memory for uncompressed .7z headers\r\n     - some other temporary blocks\r\n  - Main pool:\r\n     - Memory for database: \r\n       Estimated size of one file structures in solid archive:\r\n         - Size (4 or 8 Bytes)\r\n         - CRC32 (4 bytes)\r\n         - Some file information (4 bytes)\r\n         - File Name (variable length) + pointer + allocation structures\r\n\r\nMemory usage for archive Decompressing:\r\n  - Temporary pool:\r\n     - Memory for compressed solid block (if _LZMA_IN_CB is not defined)\r\n     - Memory for LZMA decompressing structures\r\n  - Main pool:\r\n     - Memory for decompressed solid block\r\n  \r\n\r\nIf _LZMA_IN_CB is defined, 7z Decoder will not allocate memory for \r\ncompressed blocks. Instead of this, you must allocate buffer with desired \r\nsize before calling 7z Decoder. Use 7zMain.c as example.\r\n\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\n7z Decoder functions can return one of the following codes:\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_CRC_ERROR (3)\r\n\r\n#define SZE_NOTIMPL (4)\r\n#define SZE_FAIL (5)\r\n\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB       - Use special callback mode for input stream to reduce memory requirements\r\n\r\n_SZ_FILE_SIZE_64  - define it if you need support for files larger than 4 GB\r\n_SZ_NO_INT_64     - define it if your compiler doesn't support long long int\r\n\r\n_LZMA_PROB32      - it can increase LZMA decompressing speed on some 32-bit CPUs.\r\n\r\n_SZ_ONE_DIRECTORY - define it if you want to locate all source files to one directory\r\n_SZ_ALLOC_DEBUG   - define it if you want to debug alloc/free operations to stderr.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/7zFormat.txt",
    "content": "7z Format description (2.30 Beta 25)\r\n-----------------------------------\r\n\r\nThis file contains description of 7z archive format. \r\n7z archive can contain files compressed with any method.\r\nSee \"Methods.txt\" for description for defined compressing methods.\r\n\r\n\r\nFormat structure Overview\r\n-------------------------\r\n\r\nSome fields can be optional.\r\n\r\nArchive structure\r\n~~~~~~~~~~~~~~~~~  \r\nSignatureHeader\r\n[PackedStreams]\r\n[PackedStreamsForHeaders]\r\n[\r\n  Header \r\n  or \r\n  {\r\n    Packed Header\r\n    HeaderInfo\r\n  }\r\n]\r\n\r\n\r\n\r\nHeader structure\r\n~~~~~~~~~~~~~~~~  \r\n{\r\n  ArchiveProperties\r\n  AdditionalStreams\r\n  {\r\n    PackInfo\r\n    {\r\n      PackPos\r\n      NumPackStreams\r\n      Sizes[NumPackStreams]\r\n      CRCs[NumPackStreams]\r\n    }\r\n    CodersInfo\r\n    {\r\n      NumFolders\r\n      Folders[NumFolders]\r\n      {\r\n        NumCoders\r\n        CodersInfo[NumCoders]\r\n        {\r\n          ID\r\n          NumInStreams;\r\n          NumOutStreams;\r\n          PropertiesSize\r\n          Properties[PropertiesSize]\r\n        }\r\n        NumBindPairs\r\n        BindPairsInfo[NumBindPairs]\r\n        {\r\n          InIndex;\r\n          OutIndex;\r\n        }\r\n        PackedIndices\r\n      }\r\n      UnPackSize[Folders][Folders.NumOutstreams]\r\n      CRCs[NumFolders]\r\n    }\r\n    SubStreamsInfo\r\n    {\r\n      NumUnPackStreamsInFolders[NumFolders];\r\n      UnPackSizes[]\r\n      CRCs[]\r\n    }\r\n  }\r\n  MainStreamsInfo\r\n  {\r\n    (Same as in AdditionalStreams)\r\n  }\r\n  FilesInfo\r\n  {\r\n    NumFiles\r\n    Properties[]\r\n    {\r\n      ID\r\n      Size\r\n      Data\r\n    }\r\n  }\r\n}\r\n\r\nHeaderInfo structure\r\n~~~~~~~~~~~~~~~~~~~~\r\n{\r\n  (Same as in AdditionalStreams)\r\n}\r\n\r\n\r\n\r\nNotes about Notation and encoding\r\n---------------------------------\r\n\r\n7z uses little endian encoding.\r\n\r\n7z archive format has optional headers that are marked as\r\n[]\r\nHeader\r\n[]\r\n\r\nREAL_UINT64 means real UINT64.\r\n\r\nUINT64 means real UINT64 encoded with the following scheme:\r\n\r\n  Size of encoding sequence depends from first byte:\r\n  First_Byte  Extra_Bytes        Value\r\n  (binary)   \r\n  0xxxxxxx               : ( xxxxxxx           )\r\n  10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y\r\n  110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y\r\n  ...\r\n  1111110x    BYTE y[6]  : (       x << (8 * 6)) + y\r\n  11111110    BYTE y[7]  :                         y\r\n  11111111    BYTE y[8]  :                         y\r\n\r\n\r\n\r\nProperty IDs\r\n------------\r\n\r\n0x00 = kEnd,\r\n\r\n0x01 = kHeader,\r\n\r\n0x02 = kArchiveProperties,\r\n    \r\n0x03 = kAdditionalStreamsInfo,\r\n0x04 = kMainStreamsInfo,\r\n0x05 = kFilesInfo,\r\n    \r\n0x06 = kPackInfo,\r\n0x07 = kUnPackInfo,\r\n0x08 = kSubStreamsInfo,\r\n\r\n0x09 = kSize,\r\n0x0A = kCRC,\r\n\r\n0x0B = kFolder,\r\n\r\n0x0C = kCodersUnPackSize,\r\n0x0D = kNumUnPackStream,\r\n\r\n0x0E = kEmptyStream,\r\n0x0F = kEmptyFile,\r\n0x10 = kAnti,\r\n\r\n0x11 = kName,\r\n0x12 = kCreationTime,\r\n0x13 = kLastAccessTime,\r\n0x14 = kLastWriteTime,\r\n0x15 = kWinAttributes,\r\n0x16 = kComment,\r\n\r\n0x17 = kEncodedHeader,\r\n\r\n\r\n7z format headers\r\n-----------------\r\n\r\nSignatureHeader\r\n~~~~~~~~~~~~~~~\r\n  BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n\r\n  ArchiveVersion\r\n  {\r\n    BYTE Major;   // now = 0\r\n    BYTE Minor;   // now = 2\r\n  };\r\n\r\n  UINT32 StartHeaderCRC;\r\n\r\n  StartHeader\r\n  {\r\n    REAL_UINT64 NextHeaderOffset\r\n    REAL_UINT64 NextHeaderSize\r\n    UINT32 NextHeaderCRC\r\n  }\r\n\r\n\r\n...........................\r\n\r\n\r\nArchiveProperties\r\n~~~~~~~~~~~~~~~~~\r\nBYTE NID::kArchiveProperties (0x02)\r\nwhile(true)\r\n{\r\n  BYTE PropertyType;\r\n  if (aType == 0)\r\n    break;\r\n  UINT64 PropertySize;\r\n  BYTE PropertyData[PropertySize];\r\n}\r\n\r\n\r\nDigests (NumStreams)\r\n~~~~~~~~~~~~~~~~~~~~~\r\n  BYTE AllAreDefined\r\n  if (AllAreDefined == 0)\r\n  {\r\n    for(NumStreams)\r\n      BIT Defined\r\n  }\r\n  UINT32 CRCs[NumDefined]\r\n\r\n\r\nPackInfo\r\n~~~~~~~~~~~~\r\n  BYTE NID::kPackInfo  (0x06)\r\n  UINT64 PackPos\r\n  UINT64 NumPackStreams\r\n\r\n  []\r\n  BYTE NID::kSize    (0x09)\r\n  UINT64 PackSizes[NumPackStreams]\r\n  []\r\n\r\n  []\r\n  BYTE NID::kCRC      (0x0A)\r\n  PackStreamDigests[NumPackStreams]\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFolder\r\n~~~~~~\r\n  UINT64 NumCoders;\r\n  for (NumCoders)\r\n  {\r\n    BYTE \r\n    {\r\n      0:3 DecompressionMethod.IDSize\r\n      4:\r\n        0 - IsSimple\r\n        1 - Is not simple\r\n      5:\r\n        0 - No Attributes\r\n        1 - There Are Attributes\r\n      7:\r\n        0 - Last Method in Alternative_Method_List\r\n        1 - There are more alternative methods\r\n    } \r\n    BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]\r\n    if (!IsSimple)\r\n    {\r\n      UINT64 NumInStreams;\r\n      UINT64 NumOutStreams;\r\n    }\r\n    if (DecompressionMethod[0] != 0)\r\n    {\r\n      UINT64 PropertiesSize\r\n      BYTE Properties[PropertiesSize]\r\n    }\r\n  }\r\n    \r\n  NumBindPairs = NumOutStreamsTotal - 1;\r\n\r\n  for (NumBindPairs)\r\n  {\r\n    UINT64 InIndex;\r\n    UINT64 OutIndex;\r\n  }\r\n\r\n  NumPackedStreams = NumInStreamsTotal - NumBindPairs;\r\n  if (NumPackedStreams > 1)\r\n    for(NumPackedStreams)\r\n    {\r\n      UINT64 Index;\r\n    };\r\n\r\n\r\n\r\n\r\nCoders Info\r\n~~~~~~~~~~~\r\n\r\n  BYTE NID::kUnPackInfo  (0x07)\r\n\r\n\r\n  BYTE NID::kFolder  (0x0B)\r\n  UINT64 NumFolders\r\n  BYTE External\r\n  switch(External)\r\n  {\r\n    case 0:\r\n      Folders[NumFolders]\r\n    case 1:\r\n      UINT64 DataStreamIndex\r\n  }\r\n\r\n\r\n  BYTE ID::kCodersUnPackSize  (0x0C)\r\n  for(Folders)\r\n    for(Folder.NumOutStreams)\r\n     UINT64 UnPackSize;\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC   (0x0A)\r\n  UnPackDigests[NumFolders]\r\n  []\r\n\r\n  \r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\n\r\nSubStreams Info\r\n~~~~~~~~~~~~~~\r\n  BYTE NID::kSubStreamsInfo; (0x08)\r\n\r\n  []\r\n  BYTE NID::kNumUnPackStream; (0x0D)\r\n  UINT64 NumUnPackStreamsInFolders[NumFolders];\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kSize  (0x09)\r\n  UINT64 UnPackSizes[]\r\n  []\r\n\r\n\r\n  []\r\n  BYTE NID::kCRC  (0x0A)\r\n  Digests[Number of streams with unknown CRC]\r\n  []\r\n\r\n  \r\n  BYTE NID::kEnd\r\n\r\n\r\nStreams Info\r\n~~~~~~~~~~~~\r\n\r\n  []\r\n  PackInfo\r\n  []\r\n\r\n\r\n  []\r\n  CodersInfo\r\n  []\r\n\r\n\r\n  []\r\n  SubStreamsInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nFilesInfo\r\n~~~~~~~~~\r\n  BYTE NID::kFilesInfo;  (0x05)\r\n  UINT64 NumFiles\r\n\r\n  while(true)\r\n  {\r\n    BYTE PropertyType;\r\n    if (aType == 0)\r\n      break;\r\n\r\n    UINT64 Size;\r\n\r\n    switch(PropertyType)\r\n    {\r\n      kEmptyStream:   (0x0E)\r\n        for(NumFiles)\r\n          BIT IsEmptyStream\r\n\r\n      kEmptyFile:     (0x0F)\r\n        for(EmptyStreams)\r\n          BIT IsEmptyFile\r\n\r\n      kAnti:          (0x10)\r\n        for(EmptyStreams)\r\n          BIT IsAntiFile\r\n      \r\n      case kCreationTime:   (0x12)\r\n      case kLastAccessTime: (0x13)\r\n      case kLastWriteTime:  (0x14)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT TimeDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Items)\r\n          UINT32 Time\r\n        []\r\n      \r\n      kNames:     (0x11)\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Files)\r\n        {\r\n          wchar_t Names[NameSize];\r\n          wchar_t 0;\r\n        }\r\n        []\r\n\r\n      kAttributes:  (0x15)\r\n        BYTE AllAreDefined\r\n        if (AllAreDefined == 0)\r\n        {\r\n          for(NumFiles)\r\n            BIT AttributesAreDefined\r\n        }\r\n        BYTE External;\r\n        if(External != 0)\r\n          UINT64 DataIndex\r\n        []\r\n        for(Definded Attributes)\r\n          UINT32 Attributes\r\n        []\r\n    }\r\n  }\r\n\r\n\r\nHeader\r\n~~~~~~\r\n  BYTE NID::kHeader (0x01)\r\n\r\n  []\r\n  ArchiveProperties\r\n  []\r\n\r\n  []\r\n  BYTE NID::kAdditionalStreamsInfo; (0x03)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  BYTE NID::kMainStreamsInfo;    (0x04)\r\n  StreamsInfo\r\n  []\r\n\r\n  []\r\n  FilesInfo\r\n  []\r\n\r\n  BYTE NID::kEnd\r\n\r\n\r\nHeaderInfo\r\n~~~~~~~~~~\r\n  []\r\n  BYTE NID::kEncodedHeader; (0x17)\r\n  StreamsInfo for Encoded Header\r\n  []\r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zAlloc.c",
    "content": "/* 7zAlloc.c */\r\n\r\n#include <stdlib.h>\r\n#include \"7zAlloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n\r\n#ifdef _SZ_ALLOC_DEBUG\r\n\r\n#ifdef _WIN32\r\n#include <windows.h>\r\n#endif\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountTemp = 0;\r\n#endif\r\n\r\nvoid *SzAlloc(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount);\r\n  g_allocCount++;\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFree(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCount--;\r\n    fprintf(stderr, \"\\nFree; count = %10d\", g_allocCount);\r\n  }\r\n  #endif\r\n  free(address);\r\n}\r\n\r\nvoid *SzAllocTemp(size_t size)\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_temp %10d bytes;  count = %10d\", size, g_allocCountTemp);\r\n  g_allocCountTemp++;\r\n  #ifdef _WIN32\r\n  return HeapAlloc(GetProcessHeap(), 0, size);\r\n  #endif\r\n  #endif\r\n  return malloc(size);\r\n}\r\n\r\nvoid SzFreeTemp(void *address)\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n  {\r\n    g_allocCountTemp--;\r\n    fprintf(stderr, \"\\nFree_temp; count = %10d\", g_allocCountTemp);\r\n  }\r\n  #ifdef _WIN32\r\n  HeapFree(GetProcessHeap(), 0, address);\r\n  return;\r\n  #endif\r\n  #endif\r\n  free(address);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zAlloc.h",
    "content": "/* 7zAlloc.h */\r\n\r\n#ifndef __7Z_ALLOC_H\r\n#define __7Z_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\ntypedef struct _ISzAlloc\r\n{\r\n  void *(*Alloc)(size_t size);\r\n  void (*Free)(void *address); /* address can be 0 */\r\n} ISzAlloc;\r\n\r\nvoid *SzAlloc(size_t size);\r\nvoid SzFree(void *address);\r\n\r\nvoid *SzAllocTemp(size_t size);\r\nvoid SzFreeTemp(void *address);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zBuffer.c",
    "content": "/* 7zBuffer.c */\r\n\r\n#include \"7zBuffer.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer)\r\n{\r\n  buffer->Capacity = 0;\r\n  buffer->Items = 0;\r\n}\r\n\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))\r\n{\r\n  buffer->Capacity = newCapacity;\r\n  if (newCapacity == 0)\r\n  {\r\n    buffer->Items = 0;\r\n    return 1;\r\n  }\r\n  buffer->Items = (Byte *)allocFunc(newCapacity);\r\n  return (buffer->Items != 0);\r\n}\r\n\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(buffer->Items);\r\n  buffer->Items = 0;\r\n  buffer->Capacity = 0;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zBuffer.h",
    "content": "/* 7zBuffer.h */\r\n\r\n#ifndef __7Z_BUFFER_H\r\n#define __7Z_BUFFER_H\r\n\r\n#include <stddef.h>\r\n#include \"7zTypes.h\"\r\n\r\ntypedef struct _CSzByteBuffer\r\n{    \r\n\tsize_t Capacity;\r\n  Byte *Items;\r\n}CSzByteBuffer;\r\n\r\nvoid SzByteBufferInit(CSzByteBuffer *buffer);\r\nint SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));\r\nvoid SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zCrc.c",
    "content": "/* 7zCrc.c */\r\n\r\n#include \"7zCrc.h\"\r\n\r\n#define kCrcPoly 0xEDB88320\r\n\r\nUInt32 g_CrcTable[256];\r\n\r\nvoid InitCrcTable()\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    int j;\r\n    for (j = 0; j < 8; j++)\r\n      if (r & 1) \r\n        r = (r >> 1) ^ kCrcPoly;\r\n      else     \r\n        r >>= 1;\r\n    g_CrcTable[i] = r;\r\n  }\r\n}\r\n\r\nvoid CrcInit(UInt32 *crc) { *crc = 0xFFFFFFFF; }\r\nUInt32 CrcGetDigest(UInt32 *crc) { return *crc ^ 0xFFFFFFFF; } \r\n\r\nvoid CrcUpdateByte(UInt32 *crc, Byte b)\r\n{\r\n  *crc = g_CrcTable[((Byte)(*crc)) ^ b] ^ (*crc >> 8);\r\n}\r\n\r\nvoid CrcUpdateUInt16(UInt32 *crc, UInt16 v)\r\n{\r\n  CrcUpdateByte(crc, (Byte)v);\r\n  CrcUpdateByte(crc, (Byte)(v >> 8));\r\n}\r\n\r\nvoid CrcUpdateUInt32(UInt32 *crc, UInt32 v)\r\n{\r\n  int i;\r\n  for (i = 0; i < 4; i++)\r\n    CrcUpdateByte(crc, (Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CrcUpdateUInt64(UInt32 *crc, UInt64 v)\r\n{\r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    CrcUpdateByte(crc, (Byte)(v));\r\n    v >>= 8;\r\n  }\r\n}\r\n\r\nvoid CrcUpdate(UInt32 *crc, const void *data, size_t size)\r\n{\r\n  UInt32 v = *crc;\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = g_CrcTable[((Byte)(v)) ^ *p] ^ (v >> 8);\r\n  *crc = v;\r\n}\r\n\r\nUInt32 CrcCalculateDigest(const void *data, size_t size)\r\n{\r\n  UInt32 crc;\r\n  CrcInit(&crc);\r\n  CrcUpdate(&crc, data, size);\r\n  return CrcGetDigest(&crc);\r\n}\r\n\r\nint CrcVerifyDigest(UInt32 digest, const void *data, size_t size)\r\n{\r\n  return (CrcCalculateDigest(data, size) == digest);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zCrc.h",
    "content": "/* 7zCrc.h */\r\n\r\n#ifndef __7Z_CRC_H\r\n#define __7Z_CRC_H\r\n\r\n#include <stddef.h>\r\n\r\n#include \"7zTypes.h\"\r\n\r\nextern UInt32 g_CrcTable[256];\r\nvoid InitCrcTable();\r\n\r\nvoid CrcInit(UInt32 *crc);\r\nUInt32 CrcGetDigest(UInt32 *crc);\r\nvoid CrcUpdateByte(UInt32 *crc, Byte v);\r\nvoid CrcUpdateUInt16(UInt32 *crc, UInt16 v);\r\nvoid CrcUpdateUInt32(UInt32 *crc, UInt32 v);\r\nvoid CrcUpdateUInt64(UInt32 *crc, UInt64 v);\r\nvoid CrcUpdate(UInt32 *crc, const void *data, size_t size);\r\n \r\nUInt32 CrcCalculateDigest(const void *data, size_t size);\r\nint CrcVerifyDigest(UInt32 digest, const void *data, size_t size);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zDecode.c",
    "content": "/* 7zDecode.c */\r\n\r\n#include \"7zDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#else\r\n#include \"../../Compress/LZMA_C/LzmaDecode.h\"\r\n#endif\r\n\r\nCMethodID k_Copy = { { 0x0 }, 1 };\r\nCMethodID k_LZMA = { { 0x3, 0x1, 0x1 }, 3 };\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\ntypedef struct _CLzmaInCallbackImp\r\n{\r\n  ILzmaInCallback InCallback;\r\n  ISzInStream *InStream;\r\n  size_t Size;\r\n} CLzmaInCallbackImp;\r\n\r\nint LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object;\r\n  size_t processedSize;\r\n  SZ_RESULT res;\r\n  *size = 0;\r\n  res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, cb->Size, &processedSize);\r\n  *size = (SizeT)processedSize;\r\n  if (processedSize > cb->Size)\r\n    return (int)SZE_FAIL;\r\n  cb->Size -= processedSize;\r\n  if (res == SZ_OK)\r\n    return 0;\r\n  return (int)res;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *inStream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, \r\n    size_t *outSizeProcessed, ISzAlloc *allocMain)\r\n{\r\n  UInt32 si;\r\n  size_t inSize = 0;\r\n  CCoderInfo *coder;\r\n  if (folder->NumPackStreams != 1)\r\n    return SZE_NOTIMPL;\r\n  if (folder->NumCoders != 1)\r\n    return SZE_NOTIMPL;\r\n  coder = folder->Coders;\r\n  *outSizeProcessed = 0;\r\n\r\n  for (si = 0; si < folder->NumPackStreams; si++)\r\n    inSize += (size_t)packSizes[si];\r\n\r\n  if (AreMethodsEqual(&coder->MethodID, &k_Copy))\r\n  {\r\n    size_t i;\r\n    if (inSize != outSize)\r\n      return SZE_DATA_ERROR;\r\n    #ifdef _LZMA_IN_CB\r\n    for (i = 0; i < inSize;)\r\n    {\r\n      size_t j;\r\n      Byte *inBuffer;\r\n      size_t bufferSize;\r\n      RINOK(inStream->Read((void *)inStream,  (void **)&inBuffer, inSize - i, &bufferSize));\r\n      if (bufferSize == 0)\r\n        return SZE_DATA_ERROR;\r\n      if (bufferSize > inSize - i)\r\n        return SZE_FAIL;\r\n      *outSizeProcessed += bufferSize;\r\n      for (j = 0; j < bufferSize && i < inSize; j++, i++)\r\n        outBuffer[i] = inBuffer[j];\r\n    }\r\n    #else\r\n    for (i = 0; i < inSize; i++)\r\n      outBuffer[i] = inBuffer[i];\r\n    *outSizeProcessed = inSize;\r\n    #endif\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (AreMethodsEqual(&coder->MethodID, &k_LZMA))\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    CLzmaInCallbackImp lzmaCallback;\r\n    #else\r\n    SizeT inProcessed;\r\n    #endif\r\n\r\n    CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n    int result;\r\n    SizeT outSizeProcessedLoc;\r\n\r\n    #ifdef _LZMA_IN_CB\r\n    lzmaCallback.Size = inSize;\r\n    lzmaCallback.InStream = inStream;\r\n    lzmaCallback.InCallback.Read = LzmaReadImp;\r\n    #endif\r\n\r\n    if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, \r\n        coder->Properties.Capacity) != LZMA_RESULT_OK)\r\n      return SZE_FAIL;\r\n\r\n    state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n    if (state.Probs == 0)\r\n      return SZE_OUTOFMEMORY;\r\n\r\n    #ifdef _LZMA_OUT_READ\r\n    if (state.Properties.DictionarySize == 0)\r\n      state.Dictionary = 0;\r\n    else\r\n    {\r\n      state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize);\r\n      if (state.Dictionary == 0)\r\n      {\r\n        allocMain->Free(state.Probs);\r\n        return SZE_OUTOFMEMORY;\r\n      }\r\n    }\r\n    LzmaDecoderInit(&state);\r\n    #endif\r\n\r\n    result = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &lzmaCallback.InCallback,\r\n        #else\r\n        inBuffer, (SizeT)inSize, &inProcessed,\r\n        #endif\r\n        outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n    *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n    allocMain->Free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    allocMain->Free(state.Dictionary);\r\n    #endif\r\n    if (result == LZMA_RESULT_DATA_ERROR)\r\n      return SZE_DATA_ERROR;\r\n    if (result != LZMA_RESULT_OK)\r\n      return SZE_FAIL;\r\n    return SZ_OK;\r\n  }\r\n  return SZE_NOTIMPL;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zDecode.h",
    "content": "/* 7zDecode.h */\r\n\r\n#ifndef __7Z_DECODE_H\r\n#define __7Z_DECODE_H\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n#ifdef _LZMA_IN_CB\r\n#include \"7zIn.h\"\r\n#endif\r\n\r\nSZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,\r\n    #ifdef _LZMA_IN_CB\r\n    ISzInStream *stream,\r\n    #else\r\n    const Byte *inBuffer,\r\n    #endif\r\n    Byte *outBuffer, size_t outSize, \r\n    size_t *outSizeProcessed, ISzAlloc *allocMain);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zExtract.c",
    "content": "/* 7zExtract.c */\r\n\r\n#include \"7zExtract.h\"\r\n#include \"7zDecode.h\"\r\n#include \"7zCrc.h\"\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,\r\n    UInt32 *blockIndex,\r\n    Byte **outBuffer, \r\n    size_t *outBufferSize,\r\n    size_t *offset, \r\n    size_t *outSizeProcessed, \r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];\r\n  SZ_RESULT res = SZ_OK;\r\n  *offset = 0;\r\n  *outSizeProcessed = 0;\r\n  if (folderIndex == (UInt32)-1)\r\n  {\r\n    allocMain->Free(*outBuffer);\r\n    *blockIndex = folderIndex;\r\n    *outBuffer = 0;\r\n    *outBufferSize = 0;\r\n    return SZ_OK;\r\n  }\r\n\r\n  if (*outBuffer == 0 || *blockIndex != folderIndex)\r\n  {\r\n    CFolder *folder = db->Database.Folders + folderIndex;\r\n    CFileSize unPackSize = SzFolderGetUnPackSize(folder);\r\n    #ifndef _LZMA_IN_CB\r\n    CFileSize packSize = SzArDbGetFolderFullPackSize(db, folderIndex);\r\n    Byte *inBuffer = 0;\r\n    size_t processedSize;\r\n    #endif\r\n    *blockIndex = folderIndex;\r\n    allocMain->Free(*outBuffer);\r\n    *outBuffer = 0;\r\n    \r\n    RINOK(inStream->Seek(inStream, SzArDbGetFolderStreamPos(db, folderIndex, 0)));\r\n    \r\n    #ifndef _LZMA_IN_CB\r\n    if (packSize != 0)\r\n    {\r\n      inBuffer = (Byte *)allocTemp->Alloc((size_t)packSize);\r\n      if (inBuffer == 0)\r\n        return SZE_OUTOFMEMORY;\r\n    }\r\n    res = inStream->Read(inStream, inBuffer, (size_t)packSize, &processedSize);\r\n    if (res == SZ_OK && processedSize != (size_t)packSize)\r\n      res = SZE_FAIL;\r\n    #endif\r\n    if (res == SZ_OK)\r\n    {\r\n      *outBufferSize = (size_t)unPackSize;\r\n      if (unPackSize != 0)\r\n      {\r\n        *outBuffer = (Byte *)allocMain->Alloc((size_t)unPackSize);\r\n        if (*outBuffer == 0)\r\n          res = SZE_OUTOFMEMORY;\r\n      }\r\n      if (res == SZ_OK)\r\n      {\r\n        size_t outRealSize;\r\n        res = SzDecode(db->Database.PackSizes + \r\n          db->FolderStartPackStreamIndex[folderIndex], folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream,\r\n          #else\r\n          inBuffer, \r\n          #endif\r\n          *outBuffer, (size_t)unPackSize, &outRealSize, allocTemp);\r\n        if (res == SZ_OK)\r\n        {\r\n          if (outRealSize == (size_t)unPackSize)\r\n          {\r\n            if (folder->UnPackCRCDefined)\r\n            {\r\n              if (!CrcVerifyDigest(folder->UnPackCRC, *outBuffer, (size_t)unPackSize))\r\n                res = SZE_FAIL;\r\n            }\r\n          }\r\n          else\r\n            res = SZE_FAIL;\r\n        }\r\n      }\r\n    }\r\n    #ifndef _LZMA_IN_CB\r\n    allocTemp->Free(inBuffer);\r\n    #endif\r\n  }\r\n  if (res == SZ_OK)\r\n  {\r\n    UInt32 i; \r\n    CFileItem *fileItem = db->Database.Files + fileIndex;\r\n    *offset = 0;\r\n    for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)\r\n      *offset += (UInt32)db->Database.Files[i].Size;\r\n    *outSizeProcessed = (size_t)fileItem->Size;\r\n    if (*offset + *outSizeProcessed > *outBufferSize)\r\n      return SZE_FAIL;\r\n    {\r\n      if (fileItem->IsFileCRCDefined)\r\n      {\r\n        if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer + *offset, *outSizeProcessed))\r\n          res = SZE_FAIL;\r\n      }\r\n    }\r\n  }\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zExtract.h",
    "content": "/* 7zExtract.h */\r\n\r\n#ifndef __7Z_EXTRACT_H\r\n#define __7Z_EXTRACT_H\r\n\r\n#include \"7zIn.h\"\r\n\r\n/*\r\n  SzExtract extracts file from archive\r\n\r\n  *outBuffer must be 0 before first call for each new archive. \r\n\r\n  Extracting cache:\r\n    If you need to decompress more than one file, you can send \r\n    these values from previous call:\r\n      *blockIndex, \r\n      *outBuffer, \r\n      *outBufferSize\r\n    You can consider \"*outBuffer\" as cache of solid block. If your archive is solid, \r\n    it will increase decompression speed.\r\n  \r\n    If you use external function, you can declare these 3 cache variables \r\n    (blockIndex, outBuffer, outBufferSize) as static in that external function.\r\n    \r\n    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.\r\n*/\r\n\r\nSZ_RESULT SzExtract(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    UInt32 fileIndex,         /* index of file */\r\n    UInt32 *blockIndex,       /* index of solid block */\r\n    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */\r\n    size_t *outBufferSize,    /* buffer size for output buffer */\r\n    size_t *offset,           /* offset of stream for required file in *outBuffer */\r\n    size_t *outSizeProcessed, /* size of file in *outBuffer */\r\n    ISzAlloc *allocMain,\r\n    ISzAlloc *allocTemp);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zHeader.c",
    "content": "/*  7zHeader.c */\r\n\r\n#include \"7zHeader.h\"\r\n\r\nByte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zHeader.h",
    "content": "/* 7zHeader.h */\r\n\r\n#ifndef __7Z_HEADER_H\r\n#define __7Z_HEADER_H\r\n\r\n#include \"7zTypes.h\"\r\n\r\n#define k7zSignatureSize 6\r\nextern Byte k7zSignature[k7zSignatureSize];\r\n\r\n#define k7zMajorVersion 0\r\n\r\n#define k7zStartHeaderSize 0x20\r\n\r\nenum EIdEnum\r\n{\r\n  k7zIdEnd,\r\n    \r\n  k7zIdHeader,\r\n    \r\n  k7zIdArchiveProperties,\r\n    \r\n  k7zIdAdditionalStreamsInfo,\r\n  k7zIdMainStreamsInfo,\r\n  k7zIdFilesInfo,\r\n  \r\n  k7zIdPackInfo,\r\n  k7zIdUnPackInfo,\r\n  k7zIdSubStreamsInfo,\r\n  \r\n  k7zIdSize,\r\n  k7zIdCRC,\r\n  \r\n  k7zIdFolder,\r\n  \r\n  k7zIdCodersUnPackSize,\r\n  k7zIdNumUnPackStream,\r\n  \r\n  k7zIdEmptyStream,\r\n  k7zIdEmptyFile,\r\n  k7zIdAnti,\r\n  \r\n  k7zIdName,\r\n  k7zIdCreationTime,\r\n  k7zIdLastAccessTime,\r\n  k7zIdLastWriteTime,\r\n  k7zIdWinAttributes,\r\n  k7zIdComment,\r\n  \r\n  k7zIdEncodedHeader,\r\n  \r\n  k7zIdStartPos\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zIn.c",
    "content": "/* 7zIn.c */\r\n\r\n#include \"7zIn.h\"\r\n#include \"7zCrc.h\"\r\n#include \"7zDecode.h\"\r\n\r\n#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; }\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db)\r\n{\r\n  SzArchiveDatabaseInit(&db->Database);\r\n  db->FolderStartPackStreamIndex = 0;\r\n  db->PackStreamStartPositions = 0;\r\n  db->FolderStartFileIndex = 0;\r\n  db->FileIndexToFolderIndexMap = 0;\r\n}\r\n\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *))\r\n{\r\n  freeFunc(db->FolderStartPackStreamIndex);\r\n  freeFunc(db->PackStreamStartPositions);\r\n  freeFunc(db->FolderStartFileIndex);\r\n  freeFunc(db->FileIndexToFolderIndexMap);\r\n  SzArchiveDatabaseFree(&db->Database, freeFunc);\r\n  SzArDbExInit(db);\r\n}\r\n\r\n/*\r\nCFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const \r\n{\r\n  return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];\r\n}\r\n\r\nCFileSize GetFilePackSize(int fileIndex) const\r\n{\r\n  int folderIndex = FileIndexToFolderIndexMap[fileIndex];\r\n  if (folderIndex >= 0)\r\n  {\r\n    const CFolder &folderInfo = Folders[folderIndex];\r\n    if (FolderStartFileIndex[folderIndex] == fileIndex)\r\n    return GetFolderFullPackSize(folderIndex);\r\n  }\r\n  return 0;\r\n}\r\n*/\r\n\r\n\r\nSZ_RESULT MySzInAlloc(void **p, size_t size, void * (*allocFunc)(size_t size))\r\n{\r\n  if (size == 0)\r\n    *p = 0;\r\n  else\r\n  {\r\n    *p = allocFunc(size);\r\n    RINOM(*p);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 startPos = 0;\r\n  CFileSize startPosSize = 0;\r\n  UInt32 i;\r\n  UInt32 folderIndex = 0;\r\n  UInt32 indexInFolder = 0;\r\n  RINOK(MySzInAlloc((void **)&db->FolderStartPackStreamIndex, db->Database.NumFolders * sizeof(UInt32), allocFunc));\r\n  for(i = 0; i < db->Database.NumFolders; i++)\r\n  {\r\n    db->FolderStartPackStreamIndex[i] = startPos;\r\n    startPos += db->Database.Folders[i].NumPackStreams;\r\n  }\r\n\r\n  RINOK(MySzInAlloc((void **)&db->PackStreamStartPositions, db->Database.NumPackStreams * sizeof(CFileSize), allocFunc));\r\n\r\n  for(i = 0; i < db->Database.NumPackStreams; i++)\r\n  {\r\n    db->PackStreamStartPositions[i] = startPosSize;\r\n    startPosSize += db->Database.PackSizes[i];\r\n  }\r\n\r\n  RINOK(MySzInAlloc((void **)&db->FolderStartFileIndex, db->Database.NumFolders * sizeof(UInt32), allocFunc));\r\n  RINOK(MySzInAlloc((void **)&db->FileIndexToFolderIndexMap, db->Database.NumFiles * sizeof(UInt32), allocFunc));\r\n\r\n  for (i = 0; i < db->Database.NumFiles; i++)\r\n  {\r\n    CFileItem *file = db->Database.Files + i;\r\n    int emptyStream = !file->HasStream;\r\n    if (emptyStream && indexInFolder == 0)\r\n    {\r\n      db->FileIndexToFolderIndexMap[i] = (UInt32)-1;\r\n      continue;\r\n    }\r\n    if (indexInFolder == 0)\r\n    {\r\n      /*\r\n      v3.13 incorrectly worked with empty folders\r\n      v4.07: Loop for skipping empty folders\r\n      */\r\n      while(1)\r\n      {\r\n        if (folderIndex >= db->Database.NumFolders)\r\n          return SZE_ARCHIVE_ERROR;\r\n        db->FolderStartFileIndex[folderIndex] = i;\r\n        if (db->Database.Folders[folderIndex].NumUnPackStreams != 0)\r\n          break;\r\n        folderIndex++;\r\n      }\r\n    }\r\n    db->FileIndexToFolderIndexMap[i] = folderIndex;\r\n    if (emptyStream)\r\n      continue;\r\n    indexInFolder++;\r\n    if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams)\r\n    {\r\n      folderIndex++;\r\n      indexInFolder = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\n\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder)\r\n{\r\n  return db->ArchiveInfo.DataStartPosition + \r\n    db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder];\r\n}\r\n\r\nCFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex)\r\n{\r\n  UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex];\r\n  CFolder *folder = db->Database.Folders + folderIndex;\r\n  CFileSize size = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumPackStreams; i++)\r\n    size += db->Database.PackSizes[packStreamIndex + i];\r\n  return size;\r\n}\r\n\r\n\r\n/*\r\nSZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,\r\n    CObjectVector<CFileItem> &files, UInt64 type)\r\n{\r\n  CBoolVector boolVector;\r\n  RINOK(ReadBoolVector2(files.Size(), boolVector))\r\n\r\n  CStreamSwitch streamSwitch;\r\n  RINOK(streamSwitch.Set(this, &dataVector));\r\n\r\n  for(int i = 0; i < files.Size(); i++)\r\n  {\r\n    CFileItem &file = files[i];\r\n    CArchiveFileTime fileTime;\r\n    bool defined = boolVector[i];\r\n    if (defined)\r\n    {\r\n      UInt32 low, high;\r\n      RINOK(SzReadUInt32(low));\r\n      RINOK(SzReadUInt32(high));\r\n      fileTime.dwLowDateTime = low;\r\n      fileTime.dwHighDateTime = high;\r\n    }\r\n    switch(type)\r\n    {\r\n      case k7zIdCreationTime:\r\n        file.IsCreationTimeDefined = defined;\r\n        if (defined)\r\n          file.CreationTime = fileTime;\r\n        break;\r\n      case k7zIdLastWriteTime:\r\n        file.IsLastWriteTimeDefined = defined;\r\n        if (defined)\r\n          file.LastWriteTime = fileTime;\r\n        break;\r\n      case k7zIdLastAccessTime:\r\n        file.IsLastAccessTimeDefined = defined;\r\n        if (defined)\r\n          file.LastAccessTime = fileTime;\r\n        break;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n*/\r\n\r\nSZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  while (size > 0)\r\n  {\r\n    Byte *inBuffer;\r\n    size_t processedSize;\r\n    RINOK(inStream->Read(inStream, (void **)&inBuffer, size, &processedSize));\r\n    if (processedSize == 0 || processedSize > size)\r\n      return SZE_FAIL;\r\n    size -= processedSize;\r\n    do\r\n    {\r\n      *data++ = *inBuffer++;\r\n    }\r\n    while (--processedSize != 0);\r\n  }\r\n  #else\r\n  size_t processedSize;\r\n  RINOK(inStream->Read(inStream, data, size, &processedSize));\r\n  if (processedSize != size)\r\n    return SZE_FAIL;\r\n  #endif\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data)\r\n{\r\n  return SafeReadDirect(inStream, data, 1);\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SafeReadDirectByte(inStream, &b));\r\n    *value |= ((UInt32)b << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nint TestSignatureCandidate(Byte *testBytes)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < k7zSignatureSize; i++)\r\n    if (testBytes[i] != k7zSignature[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n\r\ntypedef struct _CSzState\r\n{\r\n  Byte *Data;\r\n  size_t Size;\r\n}CSzData;\r\n\r\nSZ_RESULT SzReadByte(CSzData *sd, Byte *b)\r\n{\r\n  if (sd->Size == 0)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size--;\r\n  *b = *sd->Data++;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)\r\n{\r\n  size_t i;\r\n  for (i = 0; i < size; i++)\r\n  {\r\n    RINOK(SzReadByte(sd, data + i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)\r\n{\r\n  int i;\r\n  *value = 0;\r\n  for (i = 0; i < 4; i++)\r\n  {\r\n    Byte b;\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt32)(b) << (8 * i));\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)\r\n{\r\n  Byte firstByte;\r\n  Byte mask = 0x80;\r\n  int i;\r\n  RINOK(SzReadByte(sd, &firstByte));\r\n  *value = 0;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    Byte b;\r\n    if ((firstByte & mask) == 0)\r\n    {\r\n      UInt64 highPart = firstByte & (mask - 1);\r\n      *value += (highPart << (8 * i));\r\n      return SZ_OK;\r\n    }\r\n    RINOK(SzReadByte(sd, &b));\r\n    *value |= ((UInt64)b << (8 * i));\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  *value = (CFileSize)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value)\r\n{\r\n  UInt64 value64;\r\n  RINOK(SzReadNumber(sd, &value64));\r\n  if (value64 >= 0x80000000)\r\n    return SZE_NOTIMPL;\r\n  if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))\r\n    return SZE_NOTIMPL;\r\n  *value = (UInt32)value64;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadID(CSzData *sd, UInt64 *value) \r\n{ \r\n  return SzReadNumber(sd, value); \r\n}\r\n\r\nSZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size)\r\n{\r\n  if (size > sd->Size)\r\n    return SZE_ARCHIVE_ERROR;\r\n  sd->Size -= (size_t)size;\r\n  sd->Data += (size_t)size;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzSkeepData(CSzData *sd)\r\n{\r\n  UInt64 size;\r\n  RINOK(SzReadNumber(sd, &size));\r\n  return SzSkeepDataSize(sd, size);\r\n}\r\n\r\nSZ_RESULT SzReadArchiveProperties(CSzData *sd)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    SzSkeepData(sd);\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == attribute)\r\n      return SZ_OK;\r\n    if (type == k7zIdEnd)\r\n      return SZE_ARCHIVE_ERROR;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte b = 0;\r\n  Byte mask = 0;\r\n  size_t i;\r\n  RINOK(MySzInAlloc((void **)v, numItems * sizeof(Byte), allocFunc));\r\n  for(i = 0; i < numItems; i++)\r\n  {\r\n    if (mask == 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &b));\r\n      mask = 0x80;\r\n    }\r\n    (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0);\r\n    mask >>= 1;\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))\r\n{\r\n  Byte allAreDefined;\r\n  size_t i;\r\n  RINOK(SzReadByte(sd, &allAreDefined));\r\n  if (allAreDefined == 0)\r\n    return SzReadBoolVector(sd, numItems, v, allocFunc);\r\n  RINOK(MySzInAlloc((void **)v, numItems * sizeof(Byte), allocFunc));\r\n  for(i = 0; i < numItems; i++)\r\n    (*v)[i] = 1;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHashDigests(\r\n    CSzData *sd, \r\n    size_t numItems,\r\n    Byte **digestsDefined, \r\n    UInt32 **digests, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  size_t i;\r\n  RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc));\r\n  RINOK(MySzInAlloc((void **)digests, numItems * sizeof(UInt32), allocFunc));\r\n  for(i = 0; i < numItems; i++)\r\n    if ((*digestsDefined)[i])\r\n    {\r\n      RINOK(SzReadUInt32(sd, (*digests) + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadPackInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    UInt32 *numPackStreams,\r\n    CFileSize **packSizes,\r\n    Byte **packCRCsDefined,\r\n    UInt32 **packCRCs,\r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  RINOK(SzReadSize(sd, dataOffset));\r\n  RINOK(SzReadNumber32(sd, numPackStreams));\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdSize));\r\n\r\n  RINOK(MySzInAlloc((void **)packSizes, (size_t)*numPackStreams * sizeof(CFileSize), allocFunc));\r\n\r\n  for(i = 0; i < *numPackStreams; i++)\r\n  {\r\n    RINOK(SzReadSize(sd, (*packSizes) + i));\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc)); \r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n  if (*packCRCsDefined == 0)\r\n  {\r\n    RINOK(MySzInAlloc((void **)packCRCsDefined, (size_t)*numPackStreams * sizeof(Byte), allocFunc));\r\n    RINOK(MySzInAlloc((void **)packCRCs, (size_t)*numPackStreams * sizeof(UInt32), allocFunc));\r\n    for(i = 0; i < *numPackStreams; i++)\r\n    {\r\n      (*packCRCsDefined)[i] = 0;\r\n      (*packCRCs)[i] = 0;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadSwitch(CSzData *sd)\r\n{\r\n  Byte external;\r\n  RINOK(SzReadByte(sd, &external));\r\n  return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR;\r\n}\r\n\r\nSZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 numCoders;\r\n  UInt32 numBindPairs;\r\n  UInt32 numPackedStreams;\r\n  UInt32 i;\r\n  UInt32 numInStreams = 0;\r\n  UInt32 numOutStreams = 0;\r\n  RINOK(SzReadNumber32(sd, &numCoders));\r\n  folder->NumCoders = numCoders;\r\n\r\n  RINOK(MySzInAlloc((void **)&folder->Coders, (size_t)numCoders * sizeof(CCoderInfo), allocFunc));\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n    SzCoderInfoInit(folder->Coders + i);\r\n\r\n  for (i = 0; i < numCoders; i++)\r\n  {\r\n    Byte mainByte;\r\n    CCoderInfo *coder = folder->Coders + i;\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      coder->MethodID.IDSize = (Byte)(mainByte & 0xF);\r\n      RINOK(SzReadBytes(sd, coder->MethodID.ID, coder->MethodID.IDSize));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        RINOK(SzReadNumber32(sd, &coder->NumInStreams));\r\n        RINOK(SzReadNumber32(sd, &coder->NumOutStreams));\r\n      }\r\n      else\r\n      {\r\n        coder->NumInStreams = 1;\r\n        coder->NumOutStreams = 1;\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc))\r\n          return SZE_OUTOFMEMORY;\r\n        RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize));\r\n      }\r\n    }\r\n    while ((mainByte & 0x80) != 0)\r\n    {\r\n      RINOK(SzReadByte(sd, &mainByte));\r\n      RINOK(SzSkeepDataSize(sd, (mainByte & 0xF)));\r\n      if ((mainByte & 0x10) != 0)\r\n      {\r\n        UInt32 n;\r\n        RINOK(SzReadNumber32(sd, &n));\r\n        RINOK(SzReadNumber32(sd, &n));\r\n      }\r\n      if ((mainByte & 0x20) != 0)\r\n      {\r\n        UInt64 propertiesSize = 0;\r\n        RINOK(SzReadNumber(sd, &propertiesSize));\r\n        RINOK(SzSkeepDataSize(sd, propertiesSize));\r\n      }\r\n    }\r\n    numInStreams += (UInt32)coder->NumInStreams;\r\n    numOutStreams += (UInt32)coder->NumOutStreams;\r\n  }\r\n\r\n  numBindPairs = numOutStreams - 1;\r\n  folder->NumBindPairs = numBindPairs;\r\n\r\n\r\n  RINOK(MySzInAlloc((void **)&folder->BindPairs, (size_t)numBindPairs * sizeof(CBindPair), allocFunc));\r\n\r\n  for (i = 0; i < numBindPairs; i++)\r\n  {\r\n    CBindPair *bindPair = folder->BindPairs + i;;\r\n    RINOK(SzReadNumber32(sd, &bindPair->InIndex));\r\n    RINOK(SzReadNumber32(sd, &bindPair->OutIndex)); \r\n  }\r\n\r\n  numPackedStreams = numInStreams - (UInt32)numBindPairs;\r\n\r\n  folder->NumPackStreams = numPackedStreams;\r\n  RINOK(MySzInAlloc((void **)&folder->PackStreams, (size_t)numPackedStreams * sizeof(UInt32), allocFunc));\r\n\r\n  if (numPackedStreams == 1)\r\n  {\r\n    UInt32 j;\r\n    UInt32 pi = 0;\r\n    for (j = 0; j < numInStreams; j++)\r\n      if (SzFolderFindBindPairForInStream(folder, j) < 0)\r\n      {\r\n        folder->PackStreams[pi++] = j;\r\n        break;\r\n      }\r\n  }\r\n  else\r\n    for(i = 0; i < numPackedStreams; i++)\r\n    {\r\n      RINOK(SzReadNumber32(sd, folder->PackStreams + i));\r\n    }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadUnPackInfo(\r\n    CSzData *sd, \r\n    UInt32 *numFolders,\r\n    CFolder **folders,  /* for allocFunc */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt32 i;\r\n  RINOK(SzWaitAttribute(sd, k7zIdFolder));\r\n  RINOK(SzReadNumber32(sd, numFolders));\r\n  {\r\n    RINOK(SzReadSwitch(sd));\r\n\r\n\r\n    RINOK(MySzInAlloc((void **)folders, (size_t)*numFolders * sizeof(CFolder), allocFunc));\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n      SzFolderInit((*folders) + i);\r\n\r\n    for(i = 0; i < *numFolders; i++)\r\n    {\r\n      RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc));\r\n    }\r\n  }\r\n\r\n  RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));\r\n\r\n  for(i = 0; i < *numFolders; i++)\r\n  {\r\n    UInt32 j;\r\n    CFolder *folder = (*folders) + i;\r\n    UInt32 numOutStreams = SzFolderGetNumOutStreams(folder);\r\n\r\n    RINOK(MySzInAlloc((void **)&folder->UnPackSizes, (size_t)numOutStreams * sizeof(CFileSize), allocFunc));\r\n\r\n    for(j = 0; j < numOutStreams; j++)\r\n    {\r\n      RINOK(SzReadSize(sd, folder->UnPackSizes + j));\r\n    }\r\n  }\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    if (type == k7zIdCRC)\r\n    {\r\n      SZ_RESULT res;\r\n      Byte *crcsDefined = 0;\r\n      UInt32 *crcs = 0;\r\n      res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc); \r\n      if (res == SZ_OK)\r\n      {\r\n        for(i = 0; i < *numFolders; i++)\r\n        {\r\n          CFolder *folder = (*folders) + i;\r\n          folder->UnPackCRCDefined = crcsDefined[i];\r\n          folder->UnPackCRC = crcs[i];\r\n        }\r\n      }\r\n      allocTemp->Free(crcs);\r\n      allocTemp->Free(crcsDefined);\r\n      RINOK(res);\r\n      continue;\r\n    }\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n}\r\n\r\nSZ_RESULT SzReadSubStreamsInfo(\r\n    CSzData *sd, \r\n    UInt32 numFolders,\r\n    CFolder *folders,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type = 0;\r\n  UInt32 i;\r\n  UInt32 si = 0;\r\n  UInt32 numDigests = 0;\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n    folders[i].NumUnPackStreams = 1;\r\n  *numUnPackStreams = numFolders;\r\n\r\n  while(1)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdNumUnPackStream)\r\n    {\r\n      *numUnPackStreams = 0;\r\n      for(i = 0; i < numFolders; i++)\r\n      {\r\n        UInt32 numStreams;\r\n        RINOK(SzReadNumber32(sd, &numStreams));\r\n        folders[i].NumUnPackStreams = numStreams;\r\n        *numUnPackStreams += numStreams;\r\n      }\r\n      continue;\r\n    }\r\n    if (type == k7zIdCRC || type == k7zIdSize)\r\n      break;\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzSkeepData(sd));\r\n  }\r\n\r\n  if (*numUnPackStreams == 0)\r\n  {\r\n    *unPackSizes = 0;\r\n    *digestsDefined = 0;\r\n    *digests = 0;\r\n  }\r\n  else\r\n  {\r\n    *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize));\r\n    RINOM(*unPackSizes);\r\n    *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte));\r\n    RINOM(*digestsDefined);\r\n    *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32));\r\n    RINOM(*digests);\r\n  }\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    /*\r\n    v3.13 incorrectly worked with empty folders\r\n    v4.07: we check that folder is empty\r\n    */\r\n    CFileSize sum = 0;\r\n    UInt32 j;\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams == 0)\r\n      continue;\r\n    if (type == k7zIdSize)\r\n    for (j = 1; j < numSubstreams; j++)\r\n    {\r\n      CFileSize size;\r\n      RINOK(SzReadSize(sd, &size));\r\n      (*unPackSizes)[si++] = size;\r\n      sum += size;\r\n    }\r\n    (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;\r\n  }\r\n  if (type == k7zIdSize)\r\n  {\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  for(i = 0; i < *numUnPackStreams; i++)\r\n  {\r\n    (*digestsDefined)[i] = 0;\r\n    (*digests)[i] = 0;\r\n  }\r\n\r\n\r\n  for(i = 0; i < numFolders; i++)\r\n  {\r\n    UInt32 numSubstreams = folders[i].NumUnPackStreams;\r\n    if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)\r\n      numDigests += numSubstreams;\r\n  }\r\n\r\n \r\n  si = 0;\r\n  while(1)\r\n  {\r\n    if (type == k7zIdCRC)\r\n    {\r\n      int digestIndex = 0;\r\n      Byte *digestsDefined2 = 0; \r\n      UInt32 *digests2 = 0;\r\n      SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc);\r\n      if (res == SZ_OK)\r\n      {\r\n        for (i = 0; i < numFolders; i++)\r\n        {\r\n          CFolder *folder = folders + i;\r\n          UInt32 numSubstreams = folder->NumUnPackStreams;\r\n          if (numSubstreams == 1 && folder->UnPackCRCDefined)\r\n          {\r\n            (*digestsDefined)[si] = 1;\r\n            (*digests)[si] = folder->UnPackCRC;\r\n            si++;\r\n          }\r\n          else\r\n          {\r\n            UInt32 j;\r\n            for (j = 0; j < numSubstreams; j++, digestIndex++)\r\n            {\r\n              (*digestsDefined)[si] = digestsDefined2[digestIndex];\r\n              (*digests)[si] = digests2[digestIndex];\r\n              si++;\r\n            }\r\n          }\r\n        }\r\n      }\r\n      allocTemp->Free(digestsDefined2);\r\n      allocTemp->Free(digests2);\r\n      RINOK(res);\r\n    }\r\n    else if (type == k7zIdEnd)\r\n      return SZ_OK;\r\n    else\r\n    {\r\n      RINOK(SzSkeepData(sd));\r\n    }\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n}\r\n\r\n\r\nSZ_RESULT SzReadStreamsInfo(\r\n    CSzData *sd, \r\n    CFileSize *dataOffset,\r\n    CArchiveDatabase *db,\r\n    UInt32 *numUnPackStreams,\r\n    CFileSize **unPackSizes, /* allocTemp */\r\n    Byte **digestsDefined,   /* allocTemp */\r\n    UInt32 **digests,        /* allocTemp */\r\n    void * (*allocFunc)(size_t size),\r\n    ISzAlloc *allocTemp)\r\n{\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    RINOK(SzReadID(sd, &type));\r\n    if ((UInt64)(int)type != type)\r\n      return SZE_FAIL;\r\n    switch((int)type)\r\n    {\r\n      case k7zIdEnd:\r\n        return SZ_OK;\r\n      case k7zIdPackInfo:\r\n      {\r\n        RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams, \r\n            &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc));\r\n        break;\r\n      }\r\n      case k7zIdUnPackInfo:\r\n      {\r\n        RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp));\r\n        break;\r\n      }\r\n      case k7zIdSubStreamsInfo:\r\n      {\r\n        RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders, \r\n            numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));\r\n        break;\r\n      }\r\n      default:\r\n        return SZE_FAIL;\r\n    }\r\n  }\r\n}\r\n\r\nByte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };\r\n\r\nSZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files, \r\n    void * (*allocFunc)(size_t size))\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < numFiles; i++)\r\n  {\r\n    UInt32 len = 0;\r\n    UInt32 pos = 0;\r\n    CFileItem *file = files + i;\r\n    while(pos + 2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n      pos += 2;\r\n      len++;\r\n      if (value == 0)\r\n        break;\r\n      if (value < 0x80)\r\n        continue;\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2;\r\n        if (value >= 0xDC00)\r\n          return SZE_ARCHIVE_ERROR;\r\n        if (pos + 2 > sd->Size)\r\n          return SZE_ARCHIVE_ERROR;\r\n        c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));\r\n        pos += 2;\r\n        if (c2 < 0xDC00 || c2 >= 0xE000)\r\n          return SZE_ARCHIVE_ERROR;\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      len += numAdds;\r\n    }\r\n\r\n    RINOK(MySzInAlloc((void **)&file->Name, (size_t)len * sizeof(char), allocFunc));\r\n\r\n    len = 0;\r\n    while(2 <= sd->Size)\r\n    {\r\n      int numAdds;\r\n      UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n      SzSkeepDataSize(sd, 2);\r\n      if (value < 0x80)\r\n      {\r\n        file->Name[len++] = (char)value;\r\n        if (value == 0)\r\n          break;\r\n        continue;\r\n      }\r\n      if (value >= 0xD800 && value < 0xE000)\r\n      {\r\n        UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8));\r\n        SzSkeepDataSize(sd, 2);\r\n        value = ((value - 0xD800) << 10) | (c2 - 0xDC00);\r\n      }\r\n      for (numAdds = 1; numAdds < 5; numAdds++)\r\n        if (value < (((UInt32)1) << (numAdds * 5 + 6)))\r\n          break;\r\n      file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds)));\r\n      do\r\n      {\r\n        numAdds--;\r\n        file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F));\r\n      }\r\n      while(numAdds > 0);\r\n\r\n      len += numAdds;\r\n    }\r\n  }\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadHeader2(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db,   /* allocMain */\r\n    CFileSize **unPackSizes,  /* allocTemp */\r\n    Byte **digestsDefined,    /* allocTemp */\r\n    UInt32 **digests,         /* allocTemp */\r\n    Byte **emptyStreamVector, /* allocTemp */\r\n    Byte **emptyFileVector,   /* allocTemp */\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  UInt64 type;\r\n  UInt32 numUnPackStreams = 0;\r\n  UInt32 numFiles = 0;\r\n  CFileItem *files = 0;\r\n  UInt32 numEmptyStreams = 0;\r\n  UInt32 i;\r\n\r\n  RINOK(SzReadID(sd, &type));\r\n\r\n  if (type == k7zIdArchiveProperties)\r\n  {\r\n    RINOK(SzReadArchiveProperties(sd));\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n \r\n \r\n  if (type == k7zIdMainStreamsInfo)\r\n  {\r\n    RINOK(SzReadStreamsInfo(sd,\r\n        &db->ArchiveInfo.DataStartPosition,\r\n        &db->Database, \r\n        &numUnPackStreams,\r\n        unPackSizes,\r\n        digestsDefined,\r\n        digests, allocMain->Alloc, allocTemp));\r\n    db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader;\r\n    RINOK(SzReadID(sd, &type));\r\n  }\r\n\r\n  if (type == k7zIdEnd)\r\n    return SZ_OK;\r\n  if (type != k7zIdFilesInfo)\r\n    return SZE_ARCHIVE_ERROR;\r\n  \r\n  RINOK(SzReadNumber32(sd, &numFiles));\r\n  db->Database.NumFiles = numFiles;\r\n\r\n  RINOK(MySzInAlloc((void **)&files, (size_t)numFiles * sizeof(CFileItem), allocMain->Alloc));\r\n\r\n  db->Database.Files = files;\r\n  for(i = 0; i < numFiles; i++)\r\n    SzFileInit(files + i);\r\n\r\n  while(1)\r\n  {\r\n    UInt64 type;\r\n    UInt64 size;\r\n    RINOK(SzReadID(sd, &type));\r\n    if (type == k7zIdEnd)\r\n      break;\r\n    RINOK(SzReadNumber(sd, &size));\r\n\r\n    if ((UInt64)(int)type != type)\r\n    {\r\n      RINOK(SzSkeepDataSize(sd, size));\r\n    }\r\n    else\r\n    switch((int)type)\r\n    {\r\n      case k7zIdName:\r\n      {\r\n        RINOK(SzReadSwitch(sd));\r\n        RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc))\r\n        break;\r\n      }\r\n      case k7zIdEmptyStream:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc));\r\n        numEmptyStreams = 0;\r\n        for (i = 0; i < numFiles; i++)\r\n          if ((*emptyStreamVector)[i])\r\n            numEmptyStreams++;\r\n        break;\r\n      }\r\n      case k7zIdEmptyFile:\r\n      {\r\n        RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc));\r\n        break;\r\n      }\r\n      default:\r\n      {\r\n        RINOK(SzSkeepDataSize(sd, size));\r\n      }\r\n    }\r\n  }\r\n\r\n  {\r\n    UInt32 emptyFileIndex = 0;\r\n    UInt32 sizeIndex = 0;\r\n    for(i = 0; i < numFiles; i++)\r\n    {\r\n      CFileItem *file = files + i;\r\n      file->IsAnti = 0;\r\n      if (*emptyStreamVector == 0)\r\n        file->HasStream = 1;\r\n      else\r\n        file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);\r\n      if(file->HasStream)\r\n      {\r\n        file->IsDirectory = 0;\r\n        file->Size = (*unPackSizes)[sizeIndex];\r\n        file->FileCRC = (*digests)[sizeIndex];\r\n        file->IsFileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];\r\n        sizeIndex++;\r\n      }\r\n      else\r\n      {\r\n        if (*emptyFileVector == 0)\r\n          file->IsDirectory = 1;\r\n        else\r\n          file->IsDirectory = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);\r\n        emptyFileIndex++;\r\n        file->Size = 0;\r\n        file->IsFileCRCDefined = 0;\r\n      }\r\n    }\r\n  }\r\n  return SzArDbExFill(db, allocMain->Alloc);\r\n}\r\n\r\nSZ_RESULT SzReadHeader(\r\n    CSzData *sd, \r\n    CArchiveDatabaseEx *db, \r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  Byte *emptyStreamVector = 0;\r\n  Byte *emptyFileVector = 0;\r\n  SZ_RESULT res = SzReadHeader2(sd, db, \r\n      &unPackSizes, &digestsDefined, &digests,\r\n      &emptyStreamVector, &emptyFileVector,\r\n      allocMain, allocTemp);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  allocTemp->Free(emptyStreamVector);\r\n  allocTemp->Free(emptyFileVector);\r\n  return res;\r\n} \r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams2(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    CArchiveDatabase *db,\r\n    CFileSize **unPackSizes,\r\n    Byte **digestsDefined,\r\n    UInt32 **digests,\r\n    #ifndef _LZMA_IN_CB\r\n    Byte **inBuffer,\r\n    #endif\r\n    ISzAlloc *allocTemp)\r\n{\r\n\r\n  UInt32 numUnPackStreams = 0;\r\n  CFileSize dataStartPos;\r\n  CFolder *folder;\r\n  #ifndef _LZMA_IN_CB\r\n  CFileSize packSize = 0;\r\n  UInt32 i = 0;\r\n  #endif\r\n  CFileSize unPackSize;\r\n  size_t outRealSize;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SzReadStreamsInfo(sd, &dataStartPos, db,\r\n      &numUnPackStreams,  unPackSizes, digestsDefined, digests, \r\n      allocTemp->Alloc, allocTemp));\r\n  \r\n  dataStartPos += baseOffset;\r\n  if (db->NumFolders != 1)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  folder = db->Folders;\r\n  unPackSize = SzFolderGetUnPackSize(folder);\r\n  \r\n  RINOK(inStream->Seek(inStream, dataStartPos));\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  for (i = 0; i < db->NumPackStreams; i++)\r\n    packSize += db->PackSizes[i];\r\n\r\n  RINOK(MySzInAlloc((void **)inBuffer, (size_t)packSize, allocTemp->Alloc));\r\n\r\n  RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize));\r\n  #endif\r\n\r\n  if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  res = SzDecode(db->PackSizes, folder, \r\n          #ifdef _LZMA_IN_CB\r\n          inStream,\r\n          #else\r\n          *inBuffer, \r\n          #endif\r\n          outBuffer->Items, (size_t)unPackSize,\r\n          &outRealSize, allocTemp);\r\n  RINOK(res)\r\n  if (outRealSize != (UInt32)unPackSize)\r\n    return SZE_FAIL;\r\n  if (folder->UnPackCRCDefined)\r\n    if (!CrcVerifyDigest(folder->UnPackCRC, outBuffer->Items, (size_t)unPackSize))\r\n      return SZE_FAIL;\r\n  return SZ_OK;\r\n}\r\n\r\nSZ_RESULT SzReadAndDecodePackedStreams(\r\n    ISzInStream *inStream, \r\n    CSzData *sd,\r\n    CSzByteBuffer *outBuffer,\r\n    CFileSize baseOffset, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  CArchiveDatabase db;\r\n  CFileSize *unPackSizes = 0;\r\n  Byte *digestsDefined = 0;\r\n  UInt32 *digests = 0;\r\n  #ifndef _LZMA_IN_CB\r\n  Byte *inBuffer = 0;\r\n  #endif\r\n  SZ_RESULT res;\r\n  SzArchiveDatabaseInit(&db);\r\n  res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset, \r\n    &db, &unPackSizes, &digestsDefined, &digests, \r\n    #ifndef _LZMA_IN_CB\r\n    &inBuffer,\r\n    #endif\r\n    allocTemp);\r\n  SzArchiveDatabaseFree(&db, allocTemp->Free);\r\n  allocTemp->Free(unPackSizes);\r\n  allocTemp->Free(digestsDefined);\r\n  allocTemp->Free(digests);\r\n  #ifndef _LZMA_IN_CB\r\n  allocTemp->Free(inBuffer);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen2(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  Byte signature[k7zSignatureSize];\r\n  Byte version;\r\n  UInt32 crcFromArchive;\r\n  UInt64 nextHeaderOffset;\r\n  UInt64 nextHeaderSize;\r\n  UInt32 nextHeaderCRC;\r\n  UInt32 crc;\r\n  CFileSize pos = 0;\r\n  CSzByteBuffer buffer;\r\n  CSzData sd;\r\n  SZ_RESULT res;\r\n\r\n  RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize));\r\n\r\n  if (!TestSignatureCandidate(signature))\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  /*\r\n  db.Clear();\r\n  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;\r\n  */\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n  if (version != k7zMajorVersion)\r\n    return SZE_ARCHIVE_ERROR;\r\n  RINOK(SafeReadDirectByte(inStream, &version));\r\n\r\n  RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive));\r\n\r\n  CrcInit(&crc);\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset));\r\n  CrcUpdateUInt64(&crc, nextHeaderOffset);\r\n  RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize));\r\n  CrcUpdateUInt64(&crc, nextHeaderSize);\r\n  RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC));\r\n  CrcUpdateUInt32(&crc, nextHeaderCRC);\r\n\r\n  pos = k7zStartHeaderSize;\r\n  db->ArchiveInfo.StartPositionAfterHeader = pos;\r\n  \r\n  if (CrcGetDigest(&crc) != crcFromArchive)\r\n    return SZE_ARCHIVE_ERROR;\r\n\r\n  if (nextHeaderSize == 0)\r\n    return SZ_OK;\r\n\r\n  RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset)));\r\n\r\n  if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc))\r\n    return SZE_OUTOFMEMORY;\r\n\r\n  res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize);\r\n  if (res == SZ_OK)\r\n  {\r\n    if (CrcVerifyDigest(nextHeaderCRC, buffer.Items, (UInt32)nextHeaderSize))\r\n    {\r\n      while (1)\r\n      {\r\n        UInt64 type;\r\n        sd.Data = buffer.Items;\r\n        sd.Size = buffer.Capacity;\r\n        res = SzReadID(&sd, &type);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (type == k7zIdHeader)\r\n        {\r\n          res = SzReadHeader(&sd, db, allocMain, allocTemp);\r\n          break;\r\n        }\r\n        if (type != k7zIdEncodedHeader)\r\n        {\r\n          res = SZE_ARCHIVE_ERROR;\r\n          break;\r\n        }\r\n        {\r\n          CSzByteBuffer outBuffer;\r\n          res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, \r\n              db->ArchiveInfo.StartPositionAfterHeader, \r\n              allocTemp);\r\n          if (res != SZ_OK)\r\n          {\r\n            SzByteBufferFree(&outBuffer, allocTemp->Free);\r\n            break;\r\n          }\r\n          SzByteBufferFree(&buffer, allocTemp->Free);\r\n          buffer.Items = outBuffer.Items;\r\n          buffer.Capacity = outBuffer.Capacity;\r\n        }\r\n      }\r\n    }\r\n  }\r\n  SzByteBufferFree(&buffer, allocTemp->Free);\r\n  return res;\r\n}\r\n\r\nSZ_RESULT SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp)\r\n{\r\n  SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp);\r\n  if (res != SZ_OK)\r\n    SzArDbExFree(db, allocMain->Free);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zIn.h",
    "content": "/* 7zIn.h */\r\n\r\n#ifndef __7Z_IN_H\r\n#define __7Z_IN_H\r\n\r\n#include \"7zHeader.h\"\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n \r\ntypedef struct _CInArchiveInfo\r\n{\r\n  CFileSize StartPositionAfterHeader; \r\n  CFileSize DataStartPosition;\r\n}CInArchiveInfo;\r\n\r\ntypedef struct _CArchiveDatabaseEx\r\n{\r\n  CArchiveDatabase Database;\r\n  CInArchiveInfo ArchiveInfo;\r\n  UInt32 *FolderStartPackStreamIndex;\r\n  CFileSize *PackStreamStartPositions;\r\n  UInt32 *FolderStartFileIndex;\r\n  UInt32 *FileIndexToFolderIndexMap;\r\n}CArchiveDatabaseEx;\r\n\r\nvoid SzArDbExInit(CArchiveDatabaseEx *db);\r\nvoid SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));\r\nCFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);\r\nCFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex);\r\n\r\ntypedef struct _ISzInStream\r\n{\r\n  #ifdef _LZMA_IN_CB\r\n  SZ_RESULT (*Read)(\r\n      void *object,           /* pointer to ISzInStream itself */\r\n      void **buffer,          /* out: pointer to buffer with data */\r\n      size_t maxRequiredSize, /* max required size to read */\r\n      size_t *processedSize); /* real processed size. \r\n                                 processedSize can be less than maxRequiredSize.\r\n                                 If processedSize == 0, then there are no more \r\n                                 bytes in stream. */\r\n  #else\r\n  SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);\r\n  #endif\r\n  SZ_RESULT (*Seek)(void *object, CFileSize pos);\r\n} ISzInStream;\r\n\r\n \r\nint SzArchiveOpen(\r\n    ISzInStream *inStream, \r\n    CArchiveDatabaseEx *db,\r\n    ISzAlloc *allocMain, \r\n    ISzAlloc *allocTemp);\r\n \r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zItem.c",
    "content": "/* 7zItem.c */\r\n\r\n#include \"7zItem.h\"\r\n#include \"7zAlloc.h\"\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder)\r\n{\r\n  SzByteBufferInit(&coder->Properties);\r\n}\r\n\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))\r\n{\r\n  SzByteBufferFree(&coder->Properties, freeFunc);\r\n  SzCoderInfoInit(coder);\r\n}\r\n\r\nvoid SzFolderInit(CFolder *folder)\r\n{\r\n  folder->NumCoders = 0;\r\n  folder->Coders = 0;\r\n  folder->NumBindPairs = 0;\r\n  folder->BindPairs = 0;\r\n  folder->NumPackStreams = 0;\r\n  folder->PackStreams = 0;\r\n  folder->UnPackSizes = 0;\r\n  folder->UnPackCRCDefined = 0;\r\n  folder->UnPackCRC = 0;\r\n  folder->NumUnPackStreams = 0;\r\n}\r\n\r\nvoid SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    SzCoderInfoFree(&folder->Coders[i], freeFunc);\r\n  freeFunc(folder->Coders);\r\n  freeFunc(folder->BindPairs);\r\n  freeFunc(folder->PackStreams);\r\n  freeFunc(folder->UnPackSizes);\r\n  SzFolderInit(folder);\r\n}\r\n\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder)\r\n{\r\n  UInt32 result = 0;\r\n  UInt32 i;\r\n  for (i = 0; i < folder->NumCoders; i++)\r\n    result += folder->Coders[i].NumOutStreams;\r\n  return result;\r\n}\r\n\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].InIndex == inStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\n\r\nint SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)\r\n{\r\n  UInt32 i;\r\n  for(i = 0; i < folder->NumBindPairs; i++)\r\n    if (folder->BindPairs[i].OutIndex == outStreamIndex)\r\n      return i;\r\n  return -1;\r\n}\r\n\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder)\r\n{ \r\n  int i = (int)SzFolderGetNumOutStreams(folder);\r\n  if (i == 0)\r\n    return 0;\r\n  for (i--; i >= 0; i--)\r\n    if (SzFolderFindBindPairForOutStream(folder, i) < 0)\r\n      return folder->UnPackSizes[i];\r\n  /* throw 1; */\r\n  return 0;\r\n}\r\n\r\n/*\r\nint FindPackStreamArrayIndex(int inStreamIndex) const\r\n{\r\n  for(int i = 0; i < PackStreams.Size(); i++)\r\n  if (PackStreams[i] == inStreamIndex)\r\n    return i;\r\n  return -1;\r\n}\r\n*/\r\n\r\nvoid SzFileInit(CFileItem *fileItem)\r\n{\r\n  fileItem->IsFileCRCDefined = 0;\r\n  fileItem->HasStream = 1;\r\n  fileItem->IsDirectory = 0;\r\n  fileItem->IsAnti = 0;\r\n  fileItem->Name = 0;\r\n}\r\n\r\nvoid SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))\r\n{\r\n  freeFunc(fileItem->Name);\r\n  SzFileInit(fileItem);\r\n}\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db)\r\n{\r\n  db->NumPackStreams = 0;\r\n  db->PackSizes = 0;\r\n  db->PackCRCsDefined = 0;\r\n  db->PackCRCs = 0;\r\n  db->NumFolders = 0;\r\n  db->Folders = 0;\r\n  db->NumFiles = 0;\r\n  db->Files = 0;\r\n}\r\n\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < db->NumFolders; i++)\r\n    SzFolderFree(&db->Folders[i], freeFunc);\r\n  for (i = 0; i < db->NumFiles; i++)\r\n    SzFileFree(&db->Files[i], freeFunc);\r\n  freeFunc(db->PackSizes);\r\n  freeFunc(db->PackCRCsDefined);\r\n  freeFunc(db->PackCRCs);\r\n  freeFunc(db->Folders);\r\n  freeFunc(db->Files);\r\n  SzArchiveDatabaseInit(db);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zItem.h",
    "content": "/* 7zItem.h */\r\n\r\n#ifndef __7Z_ITEM_H\r\n#define __7Z_ITEM_H\r\n\r\n#include \"7zMethodID.h\"\r\n#include \"7zHeader.h\"\r\n#include \"7zBuffer.h\"\r\n\r\ntypedef struct _CCoderInfo\r\n{\r\n  UInt32 NumInStreams;\r\n  UInt32 NumOutStreams;\r\n  CMethodID MethodID;\r\n  CSzByteBuffer Properties;\r\n}CCoderInfo;\r\n\r\nvoid SzCoderInfoInit(CCoderInfo *coder);\r\nvoid SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));\r\n\r\ntypedef struct _CBindPair\r\n{\r\n  UInt32 InIndex;\r\n  UInt32 OutIndex;\r\n}CBindPair;\r\n\r\ntypedef struct _CFolder\r\n{\r\n  UInt32 NumCoders;\r\n  CCoderInfo *Coders;\r\n  UInt32 NumBindPairs;\r\n  CBindPair *BindPairs;\r\n  UInt32 NumPackStreams; \r\n  UInt32 *PackStreams;\r\n  CFileSize *UnPackSizes;\r\n  int UnPackCRCDefined;\r\n  UInt32 UnPackCRC;\r\n\r\n  UInt32 NumUnPackStreams;\r\n}CFolder;\r\n\r\nvoid SzFolderInit(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\nint SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);\r\nUInt32 SzFolderGetNumOutStreams(CFolder *folder);\r\nCFileSize SzFolderGetUnPackSize(CFolder *folder);\r\n\r\n/* #define CArchiveFileTime UInt64 */\r\n\r\ntypedef struct _CFileItem\r\n{\r\n  /*\r\n  CArchiveFileTime LastWriteTime;\r\n  CFileSize StartPos;\r\n  UInt32 Attributes; \r\n  */\r\n  CFileSize Size;\r\n  UInt32 FileCRC;\r\n  char *Name;\r\n\r\n  Byte IsFileCRCDefined;\r\n  Byte HasStream;\r\n  Byte IsDirectory;\r\n  Byte IsAnti;\r\n  /*\r\n  int AreAttributesDefined;\r\n  int IsLastWriteTimeDefined;\r\n  int IsStartPosDefined;\r\n  */\r\n}CFileItem;\r\n\r\nvoid SzFileInit(CFileItem *fileItem);\r\n\r\ntypedef struct _CArchiveDatabase\r\n{\r\n  UInt32 NumPackStreams;\r\n  CFileSize *PackSizes;\r\n  Byte *PackCRCsDefined;\r\n  UInt32 *PackCRCs;\r\n  UInt32 NumFolders;\r\n  CFolder *Folders;\r\n  UInt32 NumFiles;\r\n  CFileItem *Files;\r\n}CArchiveDatabase;\r\n\r\nvoid SzArchiveDatabaseInit(CArchiveDatabase *db);\r\nvoid SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));\r\n\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zMain.c",
    "content": "/* \r\n7zMain.c\r\nTest application for 7z Decoder\r\nLZMA SDK 4.26 Copyright (c) 1999-2005 Igor Pavlov (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"7zCrc.h\"\r\n#include \"7zIn.h\"\r\n#include \"7zExtract.h\"\r\n\r\ntypedef struct _CFileInStream\r\n{\r\n  ISzInStream InStream;\r\n  FILE *File;\r\n} CFileInStream;\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define kBufferSize (1 << 12)\r\nByte g_Buffer[kBufferSize];\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc;\r\n  if (maxRequiredSize > kBufferSize)\r\n    maxRequiredSize = kBufferSize;\r\n  processedSizeLoc = fread(g_Buffer, 1, maxRequiredSize, s->File);\r\n  *buffer = g_Buffer;\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#else\r\n\r\nSZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  size_t processedSizeLoc = fread(buffer, 1, size, s->File);\r\n  if (processedSize != 0)\r\n    *processedSize = processedSizeLoc;\r\n  return SZ_OK;\r\n}\r\n\r\n#endif\r\n\r\nSZ_RESULT SzFileSeekImp(void *object, CFileSize pos)\r\n{\r\n  CFileInStream *s = (CFileInStream *)object;\r\n  int res = fseek(s->File, (long)pos, SEEK_SET);\r\n  if (res == 0)\r\n    return SZ_OK;\r\n  return SZE_FAIL;\r\n}\r\n\r\nvoid PrintError(char *sz)\r\n{\r\n  printf(\"\\nERROR: %s\\n\", sz);\r\n}\r\n\r\nint main(int numargs, char *args[])\r\n{\r\n  CFileInStream archiveStream;\r\n  CArchiveDatabaseEx db;\r\n  SZ_RESULT res;\r\n  ISzAlloc allocImp;\r\n  ISzAlloc allocTempImp;\r\n\r\n  printf(\"\\n7z ANSI-C Decoder 4.30  Copyright (c) 1999-2005 Igor Pavlov  2005-11-20\\n\");\r\n  if (numargs == 1)\r\n  {\r\n    printf(\r\n      \"\\nUsage: 7zDec <command> <archive_name>\\n\\n\"\r\n      \"<Commands>\\n\"\r\n      \"  e: Extract files from archive\\n\"\r\n      \"  l: List contents of archive\\n\"\r\n      \"  t: Test integrity of archive\\n\");\r\n    return 0;\r\n  }\r\n  if (numargs < 3)\r\n  {\r\n    PrintError(\"incorrect command\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.File = fopen(args[2], \"rb\");\r\n  if (archiveStream.File == 0)\r\n  {\r\n    PrintError(\"can not open input file\");\r\n    return 1;\r\n  }\r\n\r\n  archiveStream.InStream.Read = SzFileReadImp;\r\n  archiveStream.InStream.Seek = SzFileSeekImp;\r\n\r\n  allocImp.Alloc = SzAlloc;\r\n  allocImp.Free = SzFree;\r\n\r\n  allocTempImp.Alloc = SzAllocTemp;\r\n  allocTempImp.Free = SzFreeTemp;\r\n\r\n  InitCrcTable();\r\n  SzArDbExInit(&db);\r\n  res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);\r\n  if (res == SZ_OK)\r\n  {\r\n    char *command = args[1];\r\n    int listCommand = 0;\r\n    int testCommand = 0;\r\n    int extractCommand = 0;\r\n    if (strcmp(command, \"l\") == 0)\r\n      listCommand = 1;\r\n    if (strcmp(command, \"t\") == 0)\r\n      testCommand = 1;\r\n    else if (strcmp(command, \"e\") == 0)\r\n      extractCommand = 1;\r\n\r\n    if (listCommand)\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        CFileItem *f = db.Database.Files + i;\r\n        printf(\"%10d  %s\\n\", (int)f->Size, f->Name);\r\n      }\r\n    }\r\n    else if (testCommand || extractCommand)\r\n    {\r\n      UInt32 i;\r\n\r\n      // if you need cache, use these 3 variables.\r\n      // if you use external function, you can make these variable as static.\r\n      UInt32 blockIndex = 0xFFFFFFFF; // it can have any value before first call (if outBuffer = 0) \r\n      Byte *outBuffer = 0; // it must be 0 before first call for each new archive. \r\n      size_t outBufferSize = 0;  // it can have any value before first call (if outBuffer = 0) \r\n\r\n      printf(\"\\n\");\r\n      for (i = 0; i < db.Database.NumFiles; i++)\r\n      {\r\n        size_t offset;\r\n        size_t outSizeProcessed;\r\n        CFileItem *f = db.Database.Files + i;\r\n        if (f->IsDirectory)\r\n          printf(\"Directory \");\r\n        else\r\n          printf(testCommand ? \r\n            \"Testing   \":\r\n            \"Extracting\");\r\n        printf(\" %s\", f->Name);\r\n        if (f->IsDirectory)\r\n        {\r\n          printf(\"\\n\");\r\n          continue;\r\n        }\r\n        res = SzExtract(&archiveStream.InStream, &db, i, \r\n            &blockIndex, &outBuffer, &outBufferSize, \r\n            &offset, &outSizeProcessed, \r\n            &allocImp, &allocTempImp);\r\n        if (res != SZ_OK)\r\n          break;\r\n        if (!testCommand)\r\n        {\r\n          FILE *outputHandle;\r\n          UInt32 processedSize;\r\n          char *fileName = f->Name;\r\n          size_t nameLen = strlen(f->Name);\r\n          for (; nameLen > 0; nameLen--)\r\n            if (f->Name[nameLen - 1] == '/')\r\n            {\r\n              fileName = f->Name + nameLen;\r\n              break;\r\n            }\r\n            \r\n          outputHandle = fopen(fileName, \"wb+\");\r\n          if (outputHandle == 0)\r\n          {\r\n            PrintError(\"can not open output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          processedSize = fwrite(outBuffer + offset, 1, outSizeProcessed, outputHandle);\r\n          if (processedSize != outSizeProcessed)\r\n          {\r\n            PrintError(\"can not write output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n          if (fclose(outputHandle))\r\n          {\r\n            PrintError(\"can not close output file\");\r\n            res = SZE_FAIL;\r\n            break;\r\n          }\r\n        }\r\n        printf(\"\\n\");\r\n      }\r\n      allocImp.Free(outBuffer);\r\n    }\r\n    else\r\n    {\r\n      PrintError(\"incorrect command\");\r\n      res = SZE_FAIL;\r\n    }\r\n  }\r\n  SzArDbExFree(&db, allocImp.Free);\r\n\r\n  fclose(archiveStream.File);\r\n  if (res == SZ_OK)\r\n  {\r\n    printf(\"\\nEverything is Ok\\n\");\r\n    return 0;\r\n  }\r\n  if (res == SZE_OUTOFMEMORY)\r\n    PrintError(\"can not allocate memory\");\r\n  else     \r\n    printf(\"\\nERROR #%d\\n\", res);\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zMethodID.c",
    "content": "/* 7zMethodID.c */\r\n\r\n#include \"7zMethodID.h\"\r\n\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2)\r\n{\r\n  int i;\r\n  if (a1->IDSize != a2->IDSize)\r\n    return 0;\r\n  for (i = 0; i < a1->IDSize; i++)\r\n    if (a1->ID[i] != a2->ID[i])\r\n      return 0;\r\n  return 1;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zMethodID.h",
    "content": "/* 7zMethodID.h */\r\n\r\n#ifndef __7Z_METHOD_ID_H\r\n#define __7Z_METHOD_ID_H\r\n\r\n#include \"7zTypes.h\"\r\n\r\n#define kMethodIDSize 15\r\n  \r\ntypedef struct _CMethodID\r\n{\r\n  Byte ID[kMethodIDSize];\r\n  Byte IDSize;\r\n} CMethodID;\r\n\r\nint AreMethodsEqual(CMethodID *a1, CMethodID *a2);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7zTypes.h",
    "content": "/* 7zTypes.h */\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\n#ifndef UInt32\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\n#define UInt32 unsigned long\r\n#else\r\n#define UInt32 unsigned int\r\n#endif\r\n#endif\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#ifndef UInt16\r\n#define UInt16 unsigned short\r\n#endif\r\n\r\n/* #define _SZ_NO_INT_64 */\r\n/* define it your compiler doesn't support long long int */\r\n\r\n#ifdef _SZ_NO_INT_64\r\n#define UInt64 unsigned long\r\n#else\r\n#ifdef _MSC_VER\r\n#define UInt64 unsigned __int64\r\n#else\r\n#define UInt64 unsigned long long int\r\n#endif\r\n#endif\r\n\r\n\r\n/* #define _SZ_FILE_SIZE_64 */\r\n/* Use _SZ_FILE_SIZE_64 if you need support for files larger than 4 GB*/\r\n\r\n#ifndef CFileSize\r\n#ifdef _SZ_FILE_SIZE_64\r\n#define CFileSize UInt64\r\n#else\r\n#define CFileSize UInt32\r\n#endif\r\n#endif\r\n\r\n#define SZ_RESULT int\r\n\r\n#define SZ_OK (0)\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_CRC_ERROR (3)\r\n\r\n#define SZE_NOTIMPL (4)\r\n#define SZE_FAIL (5)\r\n\r\n#define SZE_ARCHIVE_ERROR (6)\r\n\r\n#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7z_C.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"7z_C\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=7z_C - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"7z_C.mak\" CFG=\"7z_C - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"7z_C - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"7z_C - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"7z_C - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /W4 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"Release/7zDec.exe\"\r\n\r\n!ELSEIF  \"$(CFG)\" == \"7z_C - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"_MBCS\" /D \"_LZMA_PROB32\" /D \"_LZMA_IN_CB\" /YX /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"Debug/7zDec.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"7z_C - Win32 Release\"\r\n# Name \"7z_C - Win32 Debug\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_C\\LzmaDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Compress\\LZMA_C\\LzmaDecode.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zAlloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zCrc.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zCrc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zDecode.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zExtract.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zHeader.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zIn.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zItem.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMain.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zMethodID.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\7zTypes.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/7z_C.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"7z_C\"=.\\7z_C.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/makefile",
    "content": "PROG = 7zDec.exe\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\n7Z_OBJS = \\\r\n  $O\\7zAlloc.obj \\\r\n  $O\\7zBuffer.obj \\\r\n  $O\\7zCrc.obj \\\r\n  $O\\7zDecode.obj \\\r\n  $O\\7zExtract.obj \\\r\n  $O\\7zHeader.obj \\\r\n  $O\\7zIn.obj \\\r\n  $O\\7zItem.obj \\\r\n  $O\\7zMain.obj \\\r\n  $O\\7zMethodID.obj \\\r\n\r\nOBJS = \\\r\n  $(7Z_OBJS) \\\r\n  $O\\LzmaDecode.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(7Z_OBJS): $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/LZMA_C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Archive/7z_C/makefile.gcc",
    "content": "PROG = 7zDec\r\nCXX = g++\r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall\r\n\r\nOBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o \r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\n7zAlloc.o: 7zAlloc.c\r\n\t$(CXX) $(CFLAGS) 7zAlloc.c\r\n\r\n7zBuffer.o: 7zBuffer.c\r\n\t$(CXX) $(CFLAGS) 7zBuffer.c\r\n\r\n7zCrc.o: 7zCrc.c\r\n\t$(CXX) $(CFLAGS) 7zCrc.c\r\n\r\n7zDecode.o: 7zDecode.c\r\n\t$(CXX) $(CFLAGS) 7zDecode.c\r\n\r\n7zExtract.o: 7zExtract.c\r\n\t$(CXX) $(CFLAGS) 7zExtract.c\r\n\r\n7zHeader.o: 7zHeader.c\r\n\t$(CXX) $(CFLAGS) 7zHeader.c\r\n\r\n7zIn.o: 7zIn.c\r\n\t$(CXX) $(CFLAGS) 7zIn.c\r\n\r\n7zItem.o: 7zItem.c\r\n\t$(CXX) $(CFLAGS) 7zItem.c\r\n\r\n7zMain.o: 7zMain.c\r\n\t$(CXX) $(CFLAGS) 7zMain.c\r\n\r\n7zMethodID.o: 7zMethodID.c\r\n\t$(CXX) $(CFLAGS) 7zMethodID.c\r\n\r\nLzmaDecode.o: ../../Compress/LZMA_C/LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) ../../Compress/LZMA_C/LzmaDecode.c\r\n\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifndef _WIN32\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#endif\r\n\r\n#include \"FileStreams.h\"\r\n\r\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\r\n{\r\n  // return result ? S_OK: E_FAIL;\r\n  #ifdef _WIN32\r\n  return result ? S_OK: (::GetLastError());\r\n  #else\r\n  return result ? S_OK: E_FAIL;\r\n  #endif\r\n}\r\n\r\nbool CInFileStream::Open(LPCTSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool CInFileStream::Open(LPCWSTR fileName)\r\n{\r\n  return File.Open(fileName);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  \r\n  UInt32 realProcessedSize;\r\n  bool result = File.ReadPart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Read(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), \r\n      data, size, (DWORD *)&realProcessedSize, NULL);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\r\n    return S_OK;\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n  \r\n  #else\r\n\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = read(0, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\n#endif\r\n\r\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n\r\n  #ifdef _WIN32\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\r\n{\r\n  return ConvertBoolToHRESULT(File.GetLength(*size));\r\n}\r\n\r\n\r\n//////////////////////////\r\n// COutFileStream\r\n\r\nbool COutFileStream::Create(LPCTSTR fileName, bool createAlways)\r\n{\r\n  return File.Create(fileName, createAlways);\r\n}\r\n\r\n#ifdef _WIN32\r\n#ifndef _UNICODE\r\nbool COutFileStream::Create(LPCWSTR fileName, bool createAlways)\r\n{\r\n  return File.Create(fileName, createAlways);\r\n}\r\n#endif\r\n#endif\r\n\r\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  #ifdef _WIN32\r\n\r\n  UInt32 realProcessedSize;\r\n  bool result = File.WritePart(data, size, realProcessedSize);\r\n  if(processedSize != NULL)\r\n    *processedSize = realProcessedSize;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n  ssize_t res = File.Write(data, (size_t)size);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, \r\n    UInt64 *newPosition)\r\n{\r\n  if(seekOrigin >= 3)\r\n    return STG_E_INVALIDFUNCTION;\r\n  #ifdef _WIN32\r\n\r\n  UInt64 realNewPosition;\r\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\r\n  if(newPosition != NULL)\r\n    *newPosition = realNewPosition;\r\n  return ConvertBoolToHRESULT(result);\r\n  \r\n  #else\r\n  \r\n  off_t res = File.Seek(offset, seekOrigin);\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(newPosition != NULL)\r\n    *newPosition = (UInt64)res;\r\n  return S_OK;\r\n  \r\n  #endif\r\n}\r\n\r\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\r\n{\r\n  #ifdef _WIN32\r\n  UInt64 currentPos;\r\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\r\n    return E_FAIL;\r\n  bool result = File.SetLength(newSize);\r\n  UInt64 currentPos2;\r\n  result = result && File.Seek(currentPos, currentPos2);\r\n  return result ? S_OK : E_FAIL;\r\n  #else\r\n  return E_FAIL;\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if(processedSize != NULL)\r\n    *processedSize = 0;\r\n\r\n  #ifdef _WIN32\r\n  UInt32 realProcessedSize;\r\n  BOOL res = TRUE;\r\n  if (size > 0)\r\n  {\r\n    // Seems that Windows doesn't like big amounts writing to stdout.\r\n    // So we limit portions by 32KB.\r\n    UInt32 sizeTemp = (1 << 15); \r\n    if (sizeTemp > size)\r\n      sizeTemp = size;\r\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), \r\n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\r\n    size -= realProcessedSize;\r\n    data = (const void *)((const Byte *)data + realProcessedSize);\r\n    if(processedSize != NULL)\r\n      *processedSize += realProcessedSize;\r\n  }\r\n  return ConvertBoolToHRESULT(res != FALSE);\r\n\r\n  #else\r\n  \r\n  ssize_t res;\r\n  do \r\n  {\r\n    res = write(1, data, (size_t)size);\r\n  } \r\n  while (res < 0 && (errno == EINTR));\r\n  if (res == -1)\r\n    return E_FAIL;\r\n  if(processedSize != NULL)\r\n    *processedSize = (UInt32)res;\r\n  return S_OK;\r\n  \r\n  return S_OK;\r\n  #endif\r\n}\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\r\n\r\n#ifndef __FILESTREAMS_H\r\n#define __FILESTREAMS_H\r\n\r\n#ifdef _WIN32\r\n#include \"../../Windows/FileIO.h\"\r\n#else\r\n#include \"../../Common/C_FileIO.h\"\r\n#endif\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\nclass CInFileStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef _WIN32\r\n  NWindows::NFile::NIO::CInFile File;\r\n  #else\r\n  NC::NFile::NIO::CInFile File;\r\n  #endif\r\n  CInFileStream() {}\r\n  virtual ~CInFileStream() {}\r\n\r\n  bool Open(LPCTSTR fileName);\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  #endif\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdInFileStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  // HANDLE File;\r\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\r\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdInFileStream() {}\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\nclass COutFileStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  #ifdef _WIN32\r\n  NWindows::NFile::NIO::COutFile File;\r\n  #else\r\n  NC::NFile::NIO::COutFile File;\r\n  #endif\r\n  virtual ~COutFileStream() {}\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n  #ifdef _WIN32\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n  #endif\r\n  \r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r\n  STDMETHOD(SetSize)(Int64 newSize);\r\n};\r\n\r\n#ifndef _WIN32_WCE\r\nclass CStdOutFileStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n\r\n  virtual ~CStdOutFileStream() {}\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"InBuffer.h\"\r\n\r\n#include \"../../Common/Alloc.h\"\r\n\r\nCInBuffer::CInBuffer(): \r\n  _buffer(0), \r\n  _bufferLimit(0), \r\n  _bufferBase(0), \r\n  _stream(0),\r\n  _bufferSize(0)\r\n{}\r\n\r\nbool CInBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _bufferBase = (Byte *)::MidAlloc(bufferSize);\r\n  return (_bufferBase != 0);\r\n}\r\n\r\nvoid CInBuffer::Free()\r\n{\r\n  ::MidFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid CInBuffer::Init()\r\n{\r\n  _processedSize = 0;\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer;\r\n  _wasFinished = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nbool CInBuffer::ReadBlock()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return false;\r\n  #endif\r\n  if (_wasFinished)\r\n    return false;\r\n  _processedSize += (_buffer - _bufferBase);\r\n  UInt32 numProcessedBytes;\r\n  HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw CInBufferException(result);\r\n  #endif\r\n  _buffer = _bufferBase;\r\n  _bufferLimit = _buffer + numProcessedBytes;\r\n  _wasFinished = (numProcessedBytes == 0);\r\n  return (!_wasFinished);\r\n}\r\n\r\nByte CInBuffer::ReadBlock2()\r\n{\r\n  if(!ReadBlock())\r\n    return 0xFF;\r\n  return *_buffer++;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\r\n\r\n#ifndef __INBUFFER_H\r\n#define __INBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nclass CInBufferException\r\n{\r\npublic:\r\n  HRESULT ErrorCode;\r\n  CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass CInBuffer\r\n{\r\n  Byte *_buffer;\r\n  Byte *_bufferLimit;\r\n  Byte *_bufferBase;\r\n  CMyComPtr<ISequentialInStream> _stream;\r\n  UInt64 _processedSize;\r\n  UInt32 _bufferSize;\r\n  bool _wasFinished;\r\n\r\n  bool ReadBlock();\r\n  Byte ReadBlock2();\r\n\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  CInBuffer();\r\n  ~CInBuffer() { Free(); }\r\n\r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n  \r\n  void SetStream(ISequentialInStream *stream);\r\n  void Init();\r\n  void ReleaseStream() { _stream.Release(); }\r\n\r\n  bool ReadByte(Byte &b)\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      if(!ReadBlock())\r\n        return false;\r\n    b = *_buffer++;\r\n    return true;\r\n  }\r\n  Byte ReadByte()\r\n  {\r\n    if(_buffer >= _bufferLimit)\r\n      return ReadBlock2();\r\n    return *_buffer++;\r\n  }\r\n  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)\r\n  {\r\n    for(processedSize = 0; processedSize < size; processedSize++)\r\n      if (!ReadByte(((Byte *)data)[processedSize]))\r\n        return;\r\n  }\r\n  bool ReadBytes(void *data, UInt32 size)\r\n  {\r\n    UInt32 processedSize;\r\n    ReadBytes(data, size, processedSize);\r\n    return (processedSize == size);\r\n  }\r\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r\n  bool WasFinished() const { return _wasFinished; }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"OutBuffer.h\"\r\n\r\n#include \"../../Common/Alloc.h\"\r\n\r\nbool COutBuffer::Create(UInt32 bufferSize)\r\n{\r\n  const UInt32 kMinBlockSize = 1;\r\n  if (bufferSize < kMinBlockSize)\r\n    bufferSize = kMinBlockSize;\r\n  if (_buffer != 0 && _bufferSize == bufferSize)\r\n    return true;\r\n  Free();\r\n  _bufferSize = bufferSize;\r\n  _buffer = (Byte *)::MidAlloc(bufferSize);\r\n  return (_buffer != 0);\r\n}\r\n\r\nvoid COutBuffer::Free()\r\n{\r\n  ::MidFree(_buffer);\r\n  _buffer = 0;\r\n}\r\n\r\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\r\n{\r\n  _stream = stream;\r\n}\r\n\r\nvoid COutBuffer::Init()\r\n{\r\n  _streamPos = 0;\r\n  _limitPos = _bufferSize;\r\n  _pos = 0;\r\n  _processedSize = 0;\r\n  _overDict = false;\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\nUInt64 COutBuffer::GetProcessedSize() const\r\n{ \r\n  UInt64 res = _processedSize + _pos - _streamPos;\r\n  if (_streamPos > _pos) \r\n    res += _bufferSize;\r\n  return res;\r\n}\r\n\r\n\r\nHRESULT COutBuffer::FlushPart()\r\n{\r\n  // _streamPos < _bufferSize\r\n  UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);\r\n  HRESULT result = S_OK;\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    result = ErrorCode;\r\n  #endif\r\n  if (_buffer2 != 0)\r\n  {\r\n    memmove(_buffer2, _buffer + _streamPos, size);\r\n    _buffer2 += size;\r\n  }\r\n\r\n  if (_stream != 0\r\n      #ifdef _NO_EXCEPTIONS\r\n      && (ErrorCode != S_OK)\r\n      #endif\r\n     )\r\n  {\r\n    UInt32 processedSize = 0;\r\n    result = _stream->Write(_buffer + _streamPos, size, &processedSize);\r\n    size = processedSize;\r\n  }\r\n  _streamPos += size;\r\n  if (_streamPos == _bufferSize)\r\n    _streamPos = 0;\r\n  if (_pos == _bufferSize)\r\n  {\r\n    _overDict = true;\r\n    _pos = 0;\r\n  }\r\n  _limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;\r\n  _processedSize += size;\r\n  return result;\r\n}\r\n\r\nHRESULT COutBuffer::Flush()\r\n{\r\n  #ifdef _NO_EXCEPTIONS\r\n  if (ErrorCode != S_OK)\r\n    return ErrorCode;\r\n  #endif\r\n\r\n  while(_streamPos != _pos)\r\n  {\r\n    HRESULT result = FlushPart();\r\n    if (result != S_OK)\r\n      return result;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nvoid COutBuffer::FlushWithCheck()\r\n{\r\n  HRESULT result = FlushPart();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = result;\r\n  #else\r\n  if (result != S_OK)\r\n    throw COutBufferException(result);\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\r\n\r\n#ifndef __OUTBUFFER_H\r\n#define __OUTBUFFER_H\r\n\r\n#include \"../IStream.h\"\r\n#include \"../../Common/MyCom.h\"\r\n\r\n#ifndef _NO_EXCEPTIONS\r\nstruct COutBufferException\r\n{\r\n  HRESULT ErrorCode;\r\n  COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n\r\nclass COutBuffer\r\n{\r\nprotected:\r\n  Byte *_buffer;\r\n  UInt32 _pos;\r\n  UInt32 _limitPos;\r\n  UInt32 _streamPos;\r\n  UInt32 _bufferSize;\r\n  CMyComPtr<ISequentialOutStream> _stream;\r\n  UInt64 _processedSize;\r\n  Byte  *_buffer2;\r\n  bool _overDict;\r\n\r\n  HRESULT FlushPart();\r\n  void FlushWithCheck();\r\npublic:\r\n  #ifdef _NO_EXCEPTIONS\r\n  HRESULT ErrorCode;\r\n  #endif\r\n\r\n  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r\n  ~COutBuffer() { Free(); }\r\n  \r\n  bool Create(UInt32 bufferSize);\r\n  void Free();\r\n\r\n  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r\n  void SetStream(ISequentialOutStream *stream);\r\n  void Init();\r\n  HRESULT Flush();\r\n  void ReleaseStream() {  _stream.Release(); }\r\n\r\n  void WriteByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if(_pos == _limitPos)\r\n      FlushWithCheck();\r\n  }\r\n  void WriteBytes(const void *data, size_t size)\r\n  {\r\n    for (size_t i = 0; i < size; i++)\r\n      WriteByte(((const Byte *)data)[i]);\r\n  }\r\n\r\n  UInt64 GetProcessedSize() const;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../Common/MyWindows.h\"\r\n#include \"../../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Common/StreamUtils.cpp",
    "content": "// StreamUtils.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../Common/MyCom.h\"\r\n#include \"StreamUtils.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Read(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (Byte *)((Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      return S_OK;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  if (processedSize != 0)\r\n    *processedSize = 0;\r\n  while(size != 0)\r\n  {\r\n    UInt32 processedSizeLoc; \r\n    HRESULT res = stream->Write(data, size, &processedSizeLoc);\r\n    if (processedSize != 0)\r\n      *processedSize += processedSizeLoc;\r\n    data = (const void *)((const Byte *)data + processedSizeLoc);\r\n    size -= processedSizeLoc;\r\n    RINOK(res);\r\n    if (processedSizeLoc == 0)\r\n      break;\r\n  }\r\n  return S_OK;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Common/StreamUtils.h",
    "content": "// StreamUtils.h\r\n\r\n#ifndef __STREAMUTILS_H\r\n#define __STREAMUTILS_H\r\n\r\n#include \"../IStream.h\"\r\n\r\nHRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);\r\nHRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/ARM.cpp",
    "content": "// ARM.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARM.h\"\r\n\r\n#include \"BranchARM.c\"\r\n\r\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARM_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/ARM.h",
    "content": "// ARM.h\r\n\r\n#ifndef __ARM_H\r\n#define __ARM_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARM, 0x05, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/ARMThumb.cpp",
    "content": "// ARMThumb.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"ARMThumb.h\"\r\n\r\n#include \"BranchARMThumb.c\"\r\n\r\nUInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::ARMThumb_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/ARMThumb.h",
    "content": "// ARMThumb.h\r\n\r\n#ifndef __ARMTHUMB_H\r\n#define __ARMTHUMB_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_ARMThumb, 0x07, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchARM.c",
    "content": "// BranchARM.c\r\n\r\n#include \"BranchARM.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i + 3] == 0xEB)\r\n    {\r\n      UInt32 src = (data[i + 2] << 16) | (data[i + 1] << 8) | (data[i + 0]);\r\n      src <<= 2;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + 8 + src;\r\n      else\r\n        dest = src - (nowPos + i + 8);\r\n      dest >>= 2;\r\n      data[i + 2] = (dest >> 16);\r\n      data[i + 1] = (dest >> 8);\r\n      data[i + 0] = dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchARM.h",
    "content": "// BranchARM.h\r\n\r\n#ifndef __BRANCH_ARM_H\r\n#define __BRANCH_ARM_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchARMThumb.c",
    "content": "// BranchARMThumb.c\r\n\r\n#include \"BranchARMThumb.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 2)\r\n  {\r\n    if ((data[i + 1] & 0xF8) == 0xF0 && \r\n        (data[i + 3] & 0xF8) == 0xF8)\r\n    {\r\n      UInt32 src = \r\n        ((data[i + 1] & 0x7) << 19) |\r\n        (data[i + 0] << 11) |\r\n        ((data[i + 3] & 0x7) << 8) |\r\n        (data[i + 2]);\r\n      \r\n      src <<= 1;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + 4 + src;\r\n      else\r\n        dest = src - (nowPos + i + 4);\r\n      dest >>= 1;\r\n      \r\n      data[i + 1] = 0xF0 | ((dest >> 19) & 0x7);\r\n      data[i + 0] = (dest >> 11);\r\n      data[i + 3] = 0xF8 | ((dest >> 8) & 0x7);\r\n      data[i + 2] = (dest);\r\n      i += 2;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchARMThumb.h",
    "content": "// BranchARMThumb.h\r\n\r\n#ifndef __BRANCH_ARM_THUMB_H\r\n#define __BRANCH_ARM_THUMB_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"BranchCoder.h\"\r\n\r\nSTDMETHODIMP CBranchConverter::Init()\r\n{\r\n  _bufferPos = 0;\r\n  SubInit();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\r\n{\r\n  UInt32 processedSize = SubFilter(data, size);\r\n  _bufferPos += processedSize;\r\n  return processedSize;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchCoder.h",
    "content": "// BranchCoder.h\r\n\r\n#ifndef __BRANCH_CODER_H\r\n#define __BRANCH_CODER_H\r\n\r\n#include \"Common/MyCom.h\"\r\n#include \"Common/Types.h\"\r\n#include \"Common/Alloc.h\"\r\n\r\n#include \"../../ICoder.h\"\r\n\r\nclass CBranchConverter:\r\n  public ICompressFilter,\r\n  public CMyUnknownImp\r\n{\r\nprotected:\r\n  UInt32 _bufferPos;\r\n  virtual void SubInit() {}\r\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\r\npublic:\r\n  MY_UNKNOWN_IMP;\r\n  STDMETHOD(Init)();\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\r\n};\r\n\r\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \r\n\r\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\r\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \r\n\r\n#define MyClass2b(Name, id, subId, encodingId)  \\\r\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\r\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00); \r\n\r\n#define MyClassA(Name, id, subId)  \\\r\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClassEncoderA(Name ## _Encoder) \\\r\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\r\nMyClassDecoderA(Name ## _Decoder)\r\n\r\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\r\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\r\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\r\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchIA64.c",
    "content": "// BranchIA64.c\r\n\r\n#include \"BranchIA64.h\"\r\n\r\nconst Byte kBranchTable[32] = \r\n{ \r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  0, 0, 0, 0, 0, 0, 0, 0,\r\n  4, 4, 6, 6, 0, 0, 7, 7,\r\n  4, 4, 0, 0, 4, 4, 0, 0 \r\n};\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 16 <= size; i += 16)\r\n  {\r\n    UInt32 instrTemplate = data[i] & 0x1F;\r\n    UInt32 mask = kBranchTable[instrTemplate];\r\n    UInt32 bitPos = 5;\r\n    for (int slot = 0; slot < 3; slot++, bitPos += 41)\r\n    {\r\n      if (((mask >> slot) & 1) == 0)\r\n        continue;\r\n      UInt32 bytePos = (bitPos >> 3);\r\n      UInt32 bitRes = bitPos & 0x7;\r\n      // UInt64 instruction = *(UInt64 *)(data + i + bytePos);\r\n      UInt64 instruction = 0;\r\n      int j;\r\n      for (j = 0; j < 6; j++)\r\n        instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);\r\n\r\n      UInt64 instNorm = instruction >> bitRes;\r\n      if (((instNorm >> 37) & 0xF) == 0x5 \r\n        &&  ((instNorm >> 9) & 0x7) == 0 \r\n        // &&  (instNorm & 0x3F)== 0 \r\n        )\r\n      {\r\n        UInt32 src = UInt32((instNorm >> 13) & 0xFFFFF);\r\n        src |= ((instNorm >> 36) & 1) << 20;\r\n        \r\n        src <<= 4;\r\n        \r\n        UInt32 dest;\r\n        if (encoding)\r\n          dest = nowPos + i + src;\r\n        else\r\n          dest = src - (nowPos + i);\r\n        \r\n        dest >>= 4;\r\n        \r\n        instNorm &= ~(UInt64(0x8FFFFF) << 13);\r\n        instNorm |= (UInt64(dest & 0xFFFFF) << 13);\r\n        instNorm |= (UInt64(dest & 0x100000) << (36 - 20));\r\n        \r\n        instruction &= (1 << bitRes) - 1;\r\n        instruction |= (instNorm << bitRes);\r\n        // *(UInt64 *)(data + i + bytePos) = instruction;\r\n        for (j = 0; j < 6; j++)\r\n          data[i + j + bytePos] = Byte(instruction >> (8 * j));\r\n      }\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchIA64.h",
    "content": "// BranchIA64.h\r\n\r\n#ifndef __BRANCH_IA64_H\r\n#define __BRANCH_IA64_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchPPC.c",
    "content": "// BranchPPC.c\r\n\r\n#include \"BranchPPC.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    // PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link)\r\n    if ((data[i] >> 2) == 0x12 && \r\n    (\r\n      (data[i + 3] & 3) == 1 \r\n      // || (data[i+3] & 3) == 3\r\n      )\r\n    )\r\n    {\r\n      UInt32 src = ((data[i + 0] & 3) << 24) |\r\n        (data[i + 1] << 16) |\r\n        (data[i + 2] << 8) |\r\n        (data[i + 3] & (~3));\r\n      \r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      data[i + 0] = 0x48 | ((dest >> 24) &  0x3);\r\n      data[i + 1] = (dest >> 16);\r\n      data[i + 2] = (dest >> 8);\r\n      data[i + 3] &= 0x3;\r\n      data[i + 3] |= dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchPPC.h",
    "content": "// BranchPPC.h\r\n\r\n#ifndef __BRANCH_PPC_H\r\n#define __BRANCH_PPC_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchSPARC.c",
    "content": "// BranchSPARC.c\r\n\r\n#include \"BranchSPARC.h\"\r\n\r\nUInt32 SPARC_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i + 4 <= size; i += 4)\r\n  {\r\n    if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || \r\n        data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)data[i + 0] << 24) |\r\n        ((UInt32)data[i + 1] << 16) |\r\n        ((UInt32)data[i + 2] << 8) |\r\n        ((UInt32)data[i + 3]);\r\n      \r\n      src <<= 2;\r\n      UInt32 dest;\r\n      if (encoding)\r\n        dest = nowPos + i + src;\r\n      else\r\n        dest = src - (nowPos + i);\r\n      dest >>= 2;\r\n      \r\n      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;\r\n\r\n      data[i + 0] = (Byte)(dest >> 24);\r\n      data[i + 1] = (Byte)(dest >> 16);\r\n      data[i + 2] = (Byte)(dest >> 8);\r\n      data[i + 3] = (Byte)dest;\r\n    }\r\n  }\r\n  return i;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchSPARC.h",
    "content": "// BranchSPARC.h\r\n\r\n#ifndef __BRANCH_SPARC_H\r\n#define __BRANCH_SPARC_H\r\n\r\n#include \"Common/Types.h\"\r\n\r\nUInt32 SPARC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchX86.c",
    "content": "/* BranchX86.c */\r\n\r\n#include \"BranchX86.h\"\r\n\r\n/*\r\nstatic int inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n*/\r\n#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r\n\r\nconst int kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r\n\r\n/*\r\nvoid x86_Convert_Init(UInt32 *prevMask, UInt32 *prevPos)\r\n{\r\n  *prevMask = 0;\r\n  *prevPos = (UInt32)(-5);\r\n}\r\n*/\r\n\r\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \r\n    UInt32 *prevMask, UInt32 *prevPos, int encoding)\r\n{\r\n  UInt32 bufferPos = 0;\r\n  UInt32 limit;\r\n\r\n  if (endPos < 5)\r\n    return 0;\r\n  \r\n  if (nowPos - *prevPos > 5)\r\n    *prevPos = nowPos - 5;\r\n  \r\n  limit = endPos - 5;\r\n  while(bufferPos <= limit)\r\n  {\r\n    Byte b = buffer[bufferPos];\r\n    UInt32 offset;\r\n    if (b != 0xE8 && b != 0xE9)\r\n    {\r\n      bufferPos++;\r\n      continue;\r\n    }\r\n    offset = (nowPos + bufferPos - *prevPos);\r\n    *prevPos = (nowPos + bufferPos);\r\n    if (offset > 5)\r\n      *prevMask = 0;\r\n    else\r\n    {\r\n      UInt32 i;\r\n      for (i = 0; i < offset; i++)\r\n      {\r\n        *prevMask &= 0x77;\r\n        *prevMask <<= 1;\r\n      }\r\n    }\r\n    b = buffer[bufferPos + 4];\r\n    if (Test86MSByte(b) && kMaskToAllowedStatus[(*prevMask >> 1) & 0x7] && \r\n      (*prevMask >> 1) < 0x10)\r\n    {\r\n      UInt32 src = \r\n        ((UInt32)(b) << 24) |\r\n        ((UInt32)(buffer[bufferPos + 3]) << 16) |\r\n        ((UInt32)(buffer[bufferPos + 2]) << 8) |\r\n        (buffer[bufferPos + 1]);\r\n      \r\n      UInt32 dest;\r\n      while(1)\r\n      {\r\n        UInt32 index;\r\n        if (encoding)\r\n          dest = (nowPos + bufferPos + 5) + src;\r\n        else\r\n          dest = src - (nowPos + bufferPos + 5);\r\n        if (*prevMask == 0)\r\n          break;\r\n        index = kMaskToBitNumber[*prevMask >> 1];\r\n        b = (Byte)(dest >> (24 - index * 8));\r\n        if (!Test86MSByte(b))\r\n          break;\r\n        src = dest ^ ((1 << (32 - index * 8)) - 1);\r\n      }\r\n      buffer[bufferPos + 4] = (Byte)(~(((dest >> 24) & 1) - 1));\r\n      buffer[bufferPos + 3] = (Byte)(dest >> 16);\r\n      buffer[bufferPos + 2] = (Byte)(dest >> 8);\r\n      buffer[bufferPos + 1] = (Byte)dest;\r\n      bufferPos += 5;\r\n      *prevMask = 0;\r\n    }\r\n    else\r\n    {\r\n      bufferPos++;\r\n      *prevMask |= 1;\r\n      if (Test86MSByte(b))\r\n        *prevMask |= 0x10;\r\n    }\r\n  }\r\n  return bufferPos;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/BranchX86.h",
    "content": "/* BranchX86.h */\r\n\r\n#ifndef __BRANCHX86_H\r\n#define __BRANCHX86_H\r\n\r\n#ifndef UInt32\r\n#define UInt32 unsigned int\r\n#endif\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#define x86_Convert_Init(prevMask, prevPos) { prevMask = 0; prevPos = (UInt32)(-5); }\r\n\r\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \r\n    UInt32 *prevMask, UInt32 *prevPos, int encoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/IA64.cpp",
    "content": "// IA64.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"IA64.h\"\r\n\r\n#include \"BranchIA64.c\"\r\n\r\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::IA64_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/IA64.h",
    "content": "// IA64.h\r\n\r\n#ifndef __IA64_H\r\n#define __IA64_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_IA64, 0x04, 1)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/PPC.cpp",
    "content": "// PPC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"PPC.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"BranchPPC.c\"\r\n\r\nUInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::PPC_B_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/PPC.h",
    "content": "// PPC.h\r\n\r\n#ifndef __PPC_H\r\n#define __PPC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_PPC_B, 0x02, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/SPARC.cpp",
    "content": "// SPARC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"SPARC.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n#include \"BranchSPARC.c\"\r\n\r\nUInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 1);\r\n}\r\n\r\nUInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::SPARC_Convert(data, size, _bufferPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/SPARC.h",
    "content": "// SPARC.h\r\n\r\n#ifndef __SPARC_H\r\n#define __SPARC_H\r\n\r\n#include \"BranchCoder.h\"\r\n\r\nMyClassA(BC_SPARC, 0x08, 5)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/x86.cpp",
    "content": "// x86.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86.h\"\r\n\r\n#include \"Windows/Defs.h\"\r\n\r\n#include \"BranchX86.c\"\r\n\r\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 1);\r\n}\r\n\r\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\r\n{\r\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 0);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/x86.h",
    "content": "// x86.h\r\n\r\n#ifndef __X86_H\r\n#define __X86_H\r\n\r\n#include \"BranchCoder.h\"\r\n#include \"BranchX86.h\"\r\n\r\nstruct CBranch86\r\n{\r\n  UInt32 _prevMask;\r\n  UInt32 _prevPos;\r\n  void x86Init() { x86_Convert_Init(_prevMask, _prevPos); }\r\n};\r\n\r\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 , \r\n    virtual void SubInit() { x86Init(); })\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/x86_2.cpp",
    "content": "// x86_2.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"x86_2.h\"\r\n\r\n#include \"../../../Common/Alloc.h\"\r\n\r\nstatic const int kBufferSize = 1 << 17;\r\n\r\ninline bool IsJcc(Byte b0, Byte b1)\r\n{\r\n  return (b0 == 0x0F && (b1 & 0xF0) == 0x80);\r\n}\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nstatic bool inline Test86MSByte(Byte b)\r\n{\r\n  return (b == 0 || b == 0xFF);\r\n}\r\n\r\nbool CBCJ2_x86_Encoder::Create()\r\n{\r\n  if (!_mainStream.Create(1 << 16))\r\n    return false;\r\n  if (!_callStream.Create(1 << 20))\r\n    return false;\r\n  if (!_jumpStream.Create(1 << 20))\r\n    return false;\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return false;\r\n  if (_buffer == 0)\r\n  {\r\n    _buffer = (Byte *)MidAlloc(kBufferSize);\r\n    if (_buffer == 0)\r\n      return false;\r\n  }\r\n  return true;\r\n}\r\n\r\nCBCJ2_x86_Encoder::~CBCJ2_x86_Encoder()\r\n{\r\n  ::MidFree(_buffer);\r\n}\r\n\r\nHRESULT CBCJ2_x86_Encoder::Flush()\r\n{\r\n  RINOK(_mainStream.Flush());\r\n  RINOK(_callStream.Flush());\r\n  RINOK(_jumpStream.Flush());\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nconst UInt32 kDefaultLimit = (1 << 24);\r\n\r\nHRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 1 || numOutStreams != 4)\r\n    return E_INVALIDARG;\r\n\r\n  if (!Create())\r\n    return E_OUTOFMEMORY;\r\n\r\n  bool sizeIsDefined = false;\r\n  UInt64 inSize;\r\n  if (inSizes != NULL)\r\n    if (inSizes[0] != NULL)\r\n    {\r\n      inSize = *inSizes[0];\r\n      if (inSize <= kDefaultLimit)\r\n        sizeIsDefined = true;\r\n    }\r\n\r\n  ISequentialInStream *inStream = inStreams[0];\r\n\r\n  _mainStream.SetStream(outStreams[0]);\r\n  _mainStream.Init();\r\n  _callStream.SetStream(outStreams[1]);\r\n  _callStream.Init();\r\n  _jumpStream.SetStream(outStreams[2]);\r\n  _jumpStream.Init();\r\n  _rangeEncoder.SetStream(outStreams[3]);\r\n  _rangeEncoder.Init();\r\n  for (int i = 0; i < 256; i++)\r\n    _statusE8Encoder[i].Init();\r\n  _statusE9Encoder.Init();\r\n  _statusJccEncoder.Init();\r\n  CCoderReleaser releaser(this);\r\n\r\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\r\n  {\r\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\r\n  }\r\n\r\n  UInt32 nowPos = 0;\r\n  UInt64 nowPos64 = 0;\r\n  UInt32 bufferPos = 0;\r\n\r\n  Byte prevByte = 0;\r\n\r\n  UInt64 subStreamIndex = 0;\r\n  UInt64 subStreamStartPos  = 0;\r\n  UInt64 subStreamEndPos = 0;\r\n\r\n  while(true)\r\n  {\r\n    UInt32 processedSize = 0;\r\n    while(true)\r\n    {\r\n      UInt32 size = kBufferSize - (bufferPos + processedSize);\r\n      UInt32 processedSizeLoc;\r\n      if (size == 0)\r\n        break;\r\n      RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));\r\n      if (processedSizeLoc == 0)\r\n        break;\r\n      processedSize += processedSizeLoc;\r\n    }\r\n    UInt32 endPos = bufferPos + processedSize;\r\n    \r\n    if (endPos < 5)\r\n    {\r\n      // change it \r\n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\r\n      {\r\n        Byte b = _buffer[bufferPos];\r\n        _mainStream.WriteByte(b);\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\r\n        else if (IsJcc(prevByte, b))\r\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\r\n        prevByte = b;\r\n      }\r\n      return Flush();\r\n    }\r\n\r\n    bufferPos = 0;\r\n\r\n    UInt32 limit = endPos - 5;\r\n    while(bufferPos <= limit)\r\n    {\r\n      Byte b = _buffer[bufferPos];\r\n      _mainStream.WriteByte(b);\r\n      if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\r\n      {\r\n        bufferPos++;\r\n        prevByte = b;\r\n        continue;\r\n      }\r\n      Byte nextByte = _buffer[bufferPos + 4];\r\n      UInt32 src = \r\n        (UInt32(nextByte) << 24) |\r\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\r\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\r\n        (_buffer[bufferPos + 1]);\r\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\r\n      // if (Test86MSByte(nextByte))\r\n      bool convert;\r\n      if (getSubStreamSize != NULL)\r\n      {\r\n        UInt64 currentPos = (nowPos64 + bufferPos);\r\n        while (subStreamEndPos < currentPos)\r\n        {\r\n          UInt64 subStreamSize;\r\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\r\n          if (result == S_OK)\r\n          {\r\n            subStreamStartPos = subStreamEndPos;\r\n            subStreamEndPos += subStreamSize;          \r\n            subStreamIndex++;\r\n          }\r\n          else if (result == S_FALSE || result == E_NOTIMPL)\r\n          {\r\n            getSubStreamSize.Release();\r\n            subStreamStartPos = 0;\r\n            subStreamEndPos = subStreamStartPos - 1;          \r\n          }\r\n          else\r\n            return result;\r\n        }\r\n        if (getSubStreamSize == NULL)\r\n        {\r\n          if (sizeIsDefined)\r\n            convert = (dest < inSize);\r\n          else\r\n            convert = Test86MSByte(nextByte);\r\n        }\r\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\r\n          convert = Test86MSByte(nextByte);\r\n        else\r\n        {\r\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\r\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\r\n        }\r\n      }\r\n      else if (sizeIsDefined)\r\n        convert = (dest < inSize);\r\n      else\r\n        convert = Test86MSByte(nextByte);\r\n      if (convert)\r\n      {\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 1);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 1);\r\n        else \r\n          _statusJccEncoder.Encode(&_rangeEncoder, 1);\r\n\r\n        bufferPos += 5;\r\n        if (b == 0xE8)\r\n        {\r\n          _callStream.WriteByte((Byte)(dest >> 24));\r\n          _callStream.WriteByte((Byte)(dest >> 16));\r\n          _callStream.WriteByte((Byte)(dest >> 8));\r\n          _callStream.WriteByte((Byte)(dest));\r\n        }\r\n        else \r\n        {\r\n          _jumpStream.WriteByte((Byte)(dest >> 24));\r\n          _jumpStream.WriteByte((Byte)(dest >> 16));\r\n          _jumpStream.WriteByte((Byte)(dest >> 8));\r\n          _jumpStream.WriteByte((Byte)(dest));\r\n        }\r\n        prevByte = nextByte;\r\n      }\r\n      else\r\n      {\r\n        if (b == 0xE8)\r\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\r\n        else if (b == 0xE9)\r\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\r\n        else\r\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\r\n        bufferPos++;\r\n        prevByte = b;\r\n      }\r\n    }\r\n    nowPos += bufferPos;\r\n    nowPos64 += bufferPos;\r\n\r\n    if (progress != NULL)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\r\n    }\r\n \r\n    UInt32 i = 0;\r\n    while(bufferPos < endPos)\r\n      _buffer[i++] = _buffer[bufferPos++];\r\n    bufferPos = i;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n      outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n\r\n#endif\r\n\r\nHRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  if (numInStreams != 4 || numOutStreams != 1)\r\n    return E_INVALIDARG;\r\n\r\n  if (!_mainInStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_callStream.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_jumpStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_outStream.Create(1 << 16))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _mainInStream.SetStream(inStreams[0]);\r\n  _callStream.SetStream(inStreams[1]);\r\n  _jumpStream.SetStream(inStreams[2]);\r\n  _rangeDecoder.SetStream(inStreams[3]);\r\n  _outStream.SetStream(outStreams[0]);\r\n\r\n  _mainInStream.Init();\r\n  _callStream.Init();\r\n  _jumpStream.Init();\r\n  _rangeDecoder.Init();\r\n  _outStream.Init();\r\n\r\n  for (int i = 0; i < 256; i++)\r\n    _statusE8Decoder[i].Init();\r\n  _statusE9Decoder.Init();\r\n  _statusJccDecoder.Init();\r\n\r\n  CCoderReleaser releaser(this);\r\n\r\n  Byte prevByte = 0;\r\n  UInt32 processedBytes = 0;\r\n  while(true)\r\n  {\r\n    if (processedBytes > (1 << 20) && progress != NULL)\r\n    {\r\n      UInt64 nowPos64 = _outStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\r\n      processedBytes = 0;\r\n    }\r\n    processedBytes++;\r\n    Byte b;\r\n    if (!_mainInStream.ReadByte(b))\r\n      return Flush();\r\n    _outStream.WriteByte(b);\r\n    if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\r\n    {\r\n      prevByte = b;\r\n      continue;\r\n    }\r\n    bool status;\r\n    if (b == 0xE8)\r\n      status = (_statusE8Decoder[prevByte].Decode(&_rangeDecoder) == 1);\r\n    else if (b == 0xE9)\r\n      status = (_statusE9Decoder.Decode(&_rangeDecoder) == 1);\r\n    else\r\n      status = (_statusJccDecoder.Decode(&_rangeDecoder) == 1);\r\n    if (status)\r\n    {\r\n      UInt32 src;\r\n      if (b == 0xE8)\r\n      {\r\n        Byte b0;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src = ((UInt32)b0) << 24;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 16;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 8;\r\n        if(!_callStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      else\r\n      {\r\n        Byte b0;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src = ((UInt32)b0) << 24;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 16;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0) << 8;\r\n        if(!_jumpStream.ReadByte(b0))\r\n          return S_FALSE;\r\n        src |= ((UInt32)b0);\r\n      }\r\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\r\n      _outStream.WriteByte((Byte)(dest));\r\n      _outStream.WriteByte((Byte)(dest >> 8));\r\n      _outStream.WriteByte((Byte)(dest >> 16));\r\n      _outStream.WriteByte((Byte)(dest >> 24));\r\n      prevByte = (dest >> 24);\r\n      processedBytes += 4;\r\n    }\r\n    else\r\n      prevByte = b;\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CBCJ2_x86_Decoder::Code(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  try\r\n  {\r\n    return CodeReal(inStreams, inSizes, numInStreams,\r\n        outStreams, outSizes,numOutStreams, progress);\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return S_FALSE; }\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/Branch/x86_2.h",
    "content": "// x86_2.h\r\n\r\n#ifndef __BRANCH_X86_2_H\r\n#define __BRANCH_X86_2_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../RangeCoder/RangeCoderBit.h\"\r\n#include \"../../ICoder.h\"\r\n\r\n// {23170F69-40C1-278B-0303-010100000100}\r\n#define MyClass2_a(Name, id, subId, encodingId)  \\\r\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\r\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00);\r\n\r\n#define MyClass_a(Name, id, subId)  \\\r\nMyClass2_a(Name ## _Encoder, id, subId, 0x01) \\\r\nMyClass2_a(Name ## _Decoder, id, subId, 0x00) \r\n\r\nMyClass_a(BCJ2_x86, 0x01, 0x1B)\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n#ifndef EXTRACT_ONLY\r\n\r\nclass CBCJ2_x86_Encoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{\r\n  Byte *_buffer;\r\npublic:\r\n  CBCJ2_x86_Encoder(): _buffer(0) {};\r\n  ~CBCJ2_x86_Encoder();\r\n  bool Create();\r\n\r\n  COutBuffer _mainStream;\r\n  COutBuffer _callStream;\r\n  COutBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE8Encoder[256];\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE9Encoder;\r\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusJccEncoder;\r\n\r\n  HRESULT Flush();\r\n  void ReleaseStreams()\r\n  {\r\n    _mainStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeEncoder.ReleaseStream();\r\n  }\r\n\r\n  class CCoderReleaser\r\n  {\r\n    CBCJ2_x86_Encoder *_coder;\r\n  public:\r\n    CCoderReleaser(CBCJ2_x86_Encoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n\r\n  MY_UNKNOWN_IMP\r\n\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n\r\nclass CBCJ2_x86_Decoder:\r\n  public ICompressCoder2,\r\n  public CMyUnknownImp\r\n{ \r\npublic:\r\n  CInBuffer _mainInStream;\r\n  CInBuffer _callStream;\r\n  CInBuffer _jumpStream;\r\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE8Decoder[256];\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE9Decoder;\r\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusJccDecoder;\r\n\r\n  COutBuffer _outStream;\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _mainInStream.ReleaseStream();\r\n    _callStream.ReleaseStream();\r\n    _jumpStream.ReleaseStream();\r\n    _rangeDecoder.ReleaseStream();\r\n    _outStream.ReleaseStream();\r\n  }\r\n\r\n  HRESULT Flush() { return _outStream.Flush(); }\r\n  class CCoderReleaser\r\n  {\r\n    CBCJ2_x86_Decoder *_coder;\r\n  public:\r\n    CCoderReleaser(CBCJ2_x86_Decoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\r\n  };\r\n\r\npublic: \r\n  MY_UNKNOWN_IMP\r\n  HRESULT CodeReal(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes,\r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams,\r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress);\r\n}; \r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/BinTree/BinTree.h",
    "content": "// BinTree.h\r\n\r\n#include \"../LZInWindow.h\"\r\n#include \"../IMatchFinder.h\"\r\n \r\nnamespace BT_NAMESPACE {\r\n\r\ntypedef UInt32 CIndex;\r\nconst UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\r\n\r\nclass CMatchFinderBinTree: \r\n  public IMatchFinder,\r\n  public IMatchFinderSetCallback,\r\n  public CLZInWindow,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 _cyclicBufferPos;\r\n  UInt32 _cyclicBufferSize; // it must be historySize + 1\r\n  UInt32 _matchMaxLen;\r\n  CIndex *_hash;\r\n  UInt32 _cutValue;\r\n\r\n  CMyComPtr<IMatchFinderCallback> m_Callback;\r\n\r\n  void Normalize();\r\n  void FreeThisClassMemory();\r\n  void FreeMemory();\r\n\r\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\r\n\r\n  STDMETHOD(Init)(ISequentialInStream *inStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(MovePos)();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\r\n  STDMETHOD_(void, DummyLongestMatch)();\r\n\r\n  // IMatchFinderSetCallback\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\r\n\r\n  virtual void BeforeMoveBlock();\r\n  virtual void AfterMoveBlock();\r\n\r\npublic:\r\n  CMatchFinderBinTree();\r\n  virtual ~CMatchFinderBinTree();\r\n  void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/BinTree/BinTree2.h",
    "content": "// BinTree2.h\r\n\r\n#ifndef __BINTREE2_H\r\n#define __BINTREE2_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT2\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/BinTree/BinTree3.h",
    "content": "// BinTree3.h\r\n\r\n#ifndef __BINTREE3_H\r\n#define __BINTREE3_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT3\r\n\r\n#define HASH_ARRAY_2\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/BinTree/BinTree3Z.h",
    "content": "// BinTree3Z.h\r\n\r\n#ifndef __BINTREE3Z_H\r\n#define __BINTREE3Z_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT3Z\r\n\r\n#define HASH_ZIP\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ZIP\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/BinTree/BinTree4.h",
    "content": "// BinTree4.h\r\n\r\n#ifndef __BINTREE4_H\r\n#define __BINTREE4_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT4\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/BinTree/BinTree4b.h",
    "content": "// BinTree4b.h\r\n\r\n#ifndef __BINTREE4B_H\r\n#define __BINTREE4B_H\r\n\r\n#undef BT_NAMESPACE\r\n#define BT_NAMESPACE NBT4B\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n#define HASH_BIG\r\n\r\n#include \"BinTree.h\"\r\n#include \"BinTreeMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n#undef HASH_BIG\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/BinTree/BinTreeMain.h",
    "content": "// BinTreeMain.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/CRC.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\nnamespace BT_NAMESPACE {\r\n\r\n#ifdef HASH_ARRAY_2\r\n  static const UInt32 kHash2Size = 1 << 10;\r\n  #ifdef HASH_ARRAY_3\r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 4;\r\n    static const UInt32 kHash3Size = 1 << 18;\r\n    #ifdef HASH_BIG\r\n    static const UInt32 kHashSize = 1 << 23;\r\n    #else\r\n    static const UInt32 kHashSize = 1 << 20;\r\n    #endif\r\n  #else\r\n    static const UInt32 kNumHashDirectBytes = 3;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n  #endif\r\n#else\r\n  #ifdef HASH_ZIP \r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << 16;\r\n  #else\r\n    #define THERE_ARE_DIRECT_HASH_BYTES\r\n    static const UInt32 kNumHashDirectBytes = 2;\r\n    static const UInt32 kNumHashBytes = 2;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n  #endif\r\n#endif\r\n\r\nstatic const UInt32 kHashSizeSum = kHashSize\r\n    #ifdef HASH_ARRAY_2\r\n    + kHash2Size\r\n    #ifdef HASH_ARRAY_3\r\n    + kHash3Size\r\n    #endif\r\n    #endif\r\n    ;\r\n\r\n#ifdef HASH_ARRAY_2\r\nstatic const UInt32 kHash2Offset = kHashSize;\r\n#ifdef HASH_ARRAY_3\r\nstatic const UInt32 kHash3Offset = kHashSize + kHash2Size;\r\n#endif\r\n#endif\r\n\r\nCMatchFinderBinTree::CMatchFinderBinTree():\r\n  _hash(0),\r\n  _cutValue(0xFF)\r\n{\r\n}\r\n\r\nvoid CMatchFinderBinTree::FreeThisClassMemory()\r\n{\r\n  BigFree(_hash);\r\n  _hash = 0;\r\n}\r\n\r\nvoid CMatchFinderBinTree::FreeMemory()\r\n{\r\n  FreeThisClassMemory();\r\n  CLZInWindow::Free();\r\n}\r\n\r\nCMatchFinderBinTree::~CMatchFinderBinTree()\r\n{ \r\n  FreeMemory();\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderBinTree::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  UInt32 sizeReserv = (historySize + keepAddBufferBefore + \r\n      matchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n  if (CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, sizeReserv))\r\n  {\r\n    if (historySize + 256 > kMaxValForNormalize)\r\n    {\r\n      FreeMemory();\r\n      return E_INVALIDARG;\r\n    }\r\n    _matchMaxLen = matchMaxLen;\r\n    UInt32 newCyclicBufferSize = historySize + 1;\r\n    if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)\r\n      return S_OK;\r\n    FreeThisClassMemory();\r\n    _cyclicBufferSize = newCyclicBufferSize; // don't change it\r\n    _hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize * 2) * sizeof(CIndex));\r\n    if (_hash != 0)\r\n      return S_OK;\r\n  }\r\n  FreeMemory();\r\n  return E_OUTOFMEMORY;\r\n}\r\n\r\nstatic const UInt32 kEmptyHashValue = 0;\r\n\r\nSTDMETHODIMP CMatchFinderBinTree::Init(ISequentialInStream *stream)\r\n{\r\n  RINOK(CLZInWindow::Init(stream));\r\n  for(UInt32 i = 0; i < kHashSizeSum; i++)\r\n    _hash[i] = kEmptyHashValue;\r\n  _cyclicBufferPos = 0;\r\n  ReduceOffsets(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderBinTree::ReleaseStream()\r\n{ \r\n  // ReleaseStream(); \r\n}\r\n\r\n#ifdef HASH_ARRAY_2\r\n#ifdef HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)\r\n{\r\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\r\n  hash2Value = temp & (kHash2Size - 1);\r\n  hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);\r\n  return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) & \r\n      (kHashSize - 1);\r\n}\r\n#else // no HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)\r\n{\r\n  hash2Value = (CCRC::Table[pointer[0]] ^ pointer[1]) & (kHash2Size - 1);\r\n  return ((UInt32(pointer[0]) << 16)) | ((UInt32(pointer[1]) << 8)) | pointer[2];\r\n}\r\n#endif // HASH_ARRAY_3\r\n#else // no HASH_ARRAY_2\r\n#ifdef HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return ((UInt32(pointer[0]) << 8) ^ \r\n      CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\r\n}\r\n#else // no HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return pointer[0] ^ (UInt32(pointer[1]) << 8);\r\n}\r\n#endif // HASH_ZIP\r\n#endif // HASH_ARRAY_2\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetLongestMatch(UInt32 *distances)\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kNumHashBytes)\r\n      return 0; \r\n  }\r\n\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  Byte *cur = _buffer + _pos;\r\n\r\n  UInt32 maxLen = 0;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[hashValue];\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n  #endif\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  distances[2] = 0xFFFFFFFF;\r\n  if(curMatch2 > matchMinPos)\r\n    if (_buffer[curMatch2] == cur[0])\r\n    {\r\n      distances[2] = _pos - curMatch2 - 1;\r\n      maxLen = 2;\r\n    }\r\n\r\n  #ifdef HASH_ARRAY_3\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  distances[3] = 0xFFFFFFFF;\r\n  if(curMatch3 > matchMinPos)\r\n    if (_buffer[curMatch3] == cur[0])\r\n    {\r\n      distances[3] = _pos - curMatch3 - 1;\r\n      maxLen = 3;\r\n    }\r\n  #endif\r\n  #endif\r\n\r\n  _hash[hashValue] = _pos;\r\n\r\n  CIndex *son = _hash + kHashSizeSum;\r\n  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r\n\r\n  distances[kNumHashBytes] = 0xFFFFFFFF;\r\n\r\n  #ifdef THERE_ARE_DIRECT_HASH_BYTES\r\n  if (lenLimit == kNumHashDirectBytes)\r\n  {\r\n    if(curMatch > matchMinPos)\r\n      while (maxLen < kNumHashDirectBytes)\r\n        distances[++maxLen] = _pos - curMatch - 1;\r\n    // We don't need tree in this case\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 len0, len1;\r\n    len0 = len1 = kNumHashDirectBytes;\r\n    UInt32 count = _cutValue;\r\n    while(true)\r\n    {\r\n      if(curMatch <= matchMinPos || count-- == 0)\r\n      {\r\n        *ptr0 = kEmptyHashValue;\r\n        *ptr1 = kEmptyHashValue;\r\n        break;\r\n      }\r\n      Byte *pb = _buffer + curMatch;\r\n      UInt32 len = MyMin(len0, len1);\r\n      do\r\n      {\r\n        if (pb[len] != cur[len])\r\n          break;\r\n      }\r\n      while(++len != lenLimit);\r\n      \r\n      UInt32 delta = _pos - curMatch;\r\n      while (maxLen < len)\r\n        distances[++maxLen] = delta - 1;\r\n      \r\n      UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n          (_cyclicBufferPos - delta):\r\n          (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n      CIndex *pair = son + (cyclicPos << 1);\r\n      \r\n      if (len != lenLimit)\r\n      {\r\n        if (pb[len] < cur[len])\r\n        {\r\n          *ptr1 = curMatch;\r\n          ptr1 = pair + 1;\r\n          curMatch = *ptr1;\r\n          len1 = len;\r\n        }\r\n        else\r\n        {\r\n          *ptr0 = curMatch;\r\n          ptr0 = pair;\r\n          curMatch = *ptr0;\r\n          len0 = len;\r\n        }\r\n      }\r\n      else\r\n      {\r\n        *ptr1 = pair[0];\r\n        *ptr0 = pair[1];\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  #ifdef HASH_ARRAY_2\r\n  #ifdef HASH_ARRAY_3\r\n  if (distances[4] < distances[3])\r\n    distances[3] = distances[4];\r\n  #endif\r\n  if (distances[3] < distances[2])\r\n    distances[2] = distances[3];\r\n  #endif\r\n  return maxLen;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderBinTree::DummyLongestMatch()\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kNumHashBytes)\r\n      return; \r\n  }\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  Byte *cur = _buffer + _pos;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[hashValue];\r\n  _hash[hashValue] = _pos;\r\n\r\n  CIndex *son = _hash + kHashSizeSum;\r\n  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r\n  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r\n\r\n  #ifdef THERE_ARE_DIRECT_HASH_BYTES\r\n  if (lenLimit != kNumHashDirectBytes)\r\n  #endif\r\n  {\r\n    UInt32 len0, len1;\r\n    len0 = len1 = kNumHashDirectBytes;\r\n    UInt32 count = _cutValue;\r\n    while(true)\r\n    {\r\n      if(curMatch <= matchMinPos || count-- == 0)\r\n        break;\r\n      Byte *pb = _buffer + curMatch;\r\n      UInt32 len = MyMin(len0, len1);\r\n      do\r\n      {\r\n        if (pb[len] != cur[len])\r\n          break;\r\n      }\r\n      while(++len != lenLimit);\r\n      \r\n      UInt32 delta = _pos - curMatch;\r\n      UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n        (_cyclicBufferPos - delta):\r\n      (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n      CIndex *pair = son + (cyclicPos << 1);\r\n      \r\n      if (len != lenLimit)\r\n      {\r\n        if (pb[len] < cur[len])\r\n        {\r\n          *ptr1 = curMatch;\r\n          ptr1 = pair + 1;\r\n          curMatch = *ptr1;\r\n          len1 = len;\r\n        }\r\n        else \r\n        {\r\n          *ptr0 = curMatch;\r\n          ptr0 = pair;\r\n          curMatch = *ptr0;\r\n          len0 = len;\r\n        }\r\n      }\r\n      else\r\n      {\r\n        *ptr1 = pair[0];\r\n        *ptr0 = pair[1];\r\n        return;\r\n      }\r\n    }\r\n  }\r\n  *ptr0 = kEmptyHashValue;\r\n  *ptr1 = kEmptyHashValue;\r\n}\r\n\r\nvoid CMatchFinderBinTree::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _cyclicBufferSize;\r\n  CIndex *items = _hash;\r\n  UInt32 numItems = (kHashSizeSum + _cyclicBufferSize * 2);\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n  ReduceOffsets(subValue);\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderBinTree::MovePos()\r\n{\r\n  if (++_cyclicBufferPos == _cyclicBufferSize)\r\n    _cyclicBufferPos = 0;\r\n  RINOK(CLZInWindow::MovePos());\r\n  if (_pos == kMaxValForNormalize)\r\n    Normalize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(Byte) CMatchFinderBinTree::GetIndexByte(Int32 index)\r\n  { return CLZInWindow::GetIndexByte(index); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetMatchLen(Int32 index, \r\n    UInt32 back, UInt32 limit)\r\n  { return CLZInWindow::GetMatchLen(index, back, limit); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetNumAvailableBytes()\r\n  { return CLZInWindow::GetNumAvailableBytes(); }\r\n\r\nSTDMETHODIMP_(const Byte *) CMatchFinderBinTree::GetPointerToCurrentPos()\r\n  { return CLZInWindow::GetPointerToCurrentPos(); }\r\n\r\n// IMatchFinderSetCallback\r\nSTDMETHODIMP CMatchFinderBinTree::SetCallback(IMatchFinderCallback *callback)\r\n{\r\n  m_Callback = callback;\r\n  return S_OK;\r\n}\r\n\r\nvoid CMatchFinderBinTree::BeforeMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->BeforeChangingBufferPos();\r\n  CLZInWindow::BeforeMoveBlock();\r\n}\r\n\r\nvoid CMatchFinderBinTree::AfterMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->AfterChangingBufferPos();\r\n  CLZInWindow::AfterMoveBlock();\r\n}\r\n \r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/HashChain/HC.h",
    "content": "// HC.h\r\n\r\n#include \"../LZInWindow.h\"\r\n#include \"../IMatchFinder.h\"\r\n \r\nnamespace HC_NAMESPACE {\r\n\r\ntypedef UInt32 CIndex;\r\nconst UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\r\n\r\nclass CMatchFinderHC: \r\n  public IMatchFinder,\r\n  public IMatchFinderSetCallback,\r\n  public CLZInWindow,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 _cyclicBufferPos;\r\n  UInt32 _cyclicBufferSize; // it must be historySize + 1\r\n  UInt32 _matchMaxLen;\r\n  CIndex *_hash;\r\n  UInt32 _cutValue;\r\n\r\n  CMyComPtr<IMatchFinderCallback> m_Callback;\r\n\r\n  void Normalize();\r\n  void FreeThisClassMemory();\r\n  void FreeMemory();\r\n\r\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\r\n\r\n  STDMETHOD(Init)(ISequentialInStream *inStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(MovePos)();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\r\n  STDMETHOD_(void, DummyLongestMatch)();\r\n\r\n  // IMatchFinderSetCallback\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\r\n\r\n  virtual void BeforeMoveBlock();\r\n  virtual void AfterMoveBlock();\r\n\r\npublic:\r\n  CMatchFinderHC();\r\n  virtual ~CMatchFinderHC();\r\n  void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n};\r\n\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/HashChain/HC2.h",
    "content": "// HC2.h\r\n\r\n#ifndef __HC2_H\r\n#define __HC2_H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC2\r\n\r\n#include \"HCMF.h\"\r\n#include \"HCMFMain.h\"\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/HashChain/HC3.h",
    "content": "// HC3.h\r\n\r\n#ifndef __HC3_H\r\n#define __HC3_H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC3\r\n\r\n#define HASH_ARRAY_2\r\n\r\n#include \"HC.h\"\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/HashChain/HC4.h",
    "content": "// HC4.h\r\n\r\n#ifndef __HC4_H\r\n#define __HC4_H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC4\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n\r\n#include \"HC.h\"\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/HashChain/HC4b.h",
    "content": "// HC4b.h\r\n\r\n#ifndef __HC4B__H\r\n#define __HC4B__H\r\n\r\n#undef HC_NAMESPACE\r\n#define HC_NAMESPACE NHC4b\r\n\r\n#define HASH_ARRAY_2\r\n#define HASH_ARRAY_3\r\n#define HASH_BIG\r\n\r\n#include \"HC.h\"\r\n#include \"HCMain.h\"\r\n\r\n#undef HASH_ARRAY_2\r\n#undef HASH_ARRAY_3\r\n#undef HASH_BIG\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/HashChain/HCMain.h",
    "content": "// HC.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/CRC.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\nnamespace HC_NAMESPACE {\r\n\r\n#ifdef HASH_ARRAY_2\r\n  static const UInt32 kHash2Size = 1 << 10;\r\n  #ifdef HASH_ARRAY_3\r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 4;\r\n    static const UInt32 kHash3Size = 1 << 18;\r\n    #ifdef HASH_BIG\r\n    static const UInt32 kHashSize = 1 << 23;\r\n    #else\r\n    static const UInt32 kHashSize = 1 << 20;\r\n    #endif\r\n  #else\r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << (16);\r\n  #endif\r\n#else\r\n  #ifdef HASH_ZIP \r\n    static const UInt32 kNumHashDirectBytes = 0;\r\n    static const UInt32 kNumHashBytes = 3;\r\n    static const UInt32 kHashSize = 1 << 16;\r\n  #else\r\n    #define THERE_ARE_DIRECT_HASH_BYTES\r\n    static const UInt32 kNumHashDirectBytes = 2;\r\n    static const UInt32 kNumHashBytes = 2;\r\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n  #endif\r\n#endif\r\n\r\nstatic const UInt32 kHashSizeSum = kHashSize\r\n    #ifdef HASH_ARRAY_2\r\n    + kHash2Size\r\n    #ifdef HASH_ARRAY_3\r\n    + kHash3Size\r\n    #endif\r\n    #endif\r\n    ;\r\n\r\n#ifdef HASH_ARRAY_2\r\nstatic const UInt32 kHash2Offset = kHashSize;\r\n#ifdef HASH_ARRAY_3\r\nstatic const UInt32 kHash3Offset = kHashSize + kHash2Size;\r\n#endif\r\n#endif\r\n\r\nCMatchFinderHC::CMatchFinderHC():\r\n  _hash(0),\r\n  _cutValue(16)\r\n{\r\n}\r\n\r\nvoid CMatchFinderHC::FreeThisClassMemory()\r\n{\r\n  BigFree(_hash);\r\n  _hash = 0;\r\n}\r\n\r\nvoid CMatchFinderHC::FreeMemory()\r\n{\r\n  FreeThisClassMemory();\r\n  CLZInWindow::Free();\r\n}\r\n\r\nCMatchFinderHC::~CMatchFinderHC()\r\n{ \r\n  FreeMemory();\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderHC::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  UInt32 sizeReserv = (historySize + keepAddBufferBefore + \r\n      matchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n  if (CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, sizeReserv))\r\n  {\r\n    if (historySize + 256 > kMaxValForNormalize)\r\n    {\r\n      FreeMemory();\r\n      return E_INVALIDARG;\r\n    }\r\n    _matchMaxLen = matchMaxLen;\r\n    UInt32 newCyclicBufferSize = historySize + 1;\r\n    if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)\r\n      return S_OK;\r\n    FreeThisClassMemory();\r\n    _cyclicBufferSize = newCyclicBufferSize; // don't change it\r\n    _hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize) * sizeof(CIndex));\r\n    if (_hash != 0)\r\n      return S_OK;\r\n  }\r\n  FreeMemory();\r\n  return E_OUTOFMEMORY;\r\n}\r\n\r\nstatic const UInt32 kEmptyHashValue = 0;\r\n\r\nSTDMETHODIMP CMatchFinderHC::Init(ISequentialInStream *stream)\r\n{\r\n  RINOK(CLZInWindow::Init(stream));\r\n  for(UInt32 i = 0; i < kHashSizeSum; i++)\r\n    _hash[i] = kEmptyHashValue;\r\n  _cyclicBufferPos = 0;\r\n  ReduceOffsets(-1);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderHC::ReleaseStream()\r\n{ \r\n  // ReleaseStream(); \r\n}\r\n\r\n#ifdef HASH_ARRAY_2\r\n#ifdef HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)\r\n{\r\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\r\n  hash2Value = temp & (kHash2Size - 1);\r\n  hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);\r\n  return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) & \r\n      (kHashSize - 1);\r\n}\r\n#else // no HASH_ARRAY_3\r\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)\r\n{\r\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\r\n  hash2Value = temp & (kHash2Size - 1);\r\n  return (temp ^ (UInt32(pointer[2]) << 8)) & (kHashSize - 1);;\r\n}\r\n#endif // HASH_ARRAY_3\r\n#else // no HASH_ARRAY_2\r\n#ifdef HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return ((UInt32(pointer[0]) << 8) ^ \r\n      CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\r\n}\r\n#else // no HASH_ZIP \r\ninline UInt32 Hash(const Byte *pointer)\r\n{\r\n  return pointer[0] ^ (UInt32(pointer[1]) << 8);\r\n}\r\n#endif // HASH_ZIP\r\n#endif // HASH_ARRAY_2\r\n\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetLongestMatch(UInt32 *distances)\r\n{\r\n  UInt32 lenLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    lenLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    lenLimit = _streamPos - _pos;\r\n    if(lenLimit < kNumHashBytes)\r\n      return 0; \r\n  }\r\n\r\n  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r\n  Byte *cur = _buffer + _pos;\r\n  \r\n  UInt32 maxLen = 0;\r\n\r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n  #ifdef HASH_ARRAY_2\r\n\r\n  UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  distances[2] = 0xFFFFFFFF;\r\n  if(curMatch2 > matchMinPos)\r\n    if (_buffer[curMatch2] == cur[0])\r\n    {\r\n      distances[2] = _pos - curMatch2 - 1;\r\n      maxLen = 2;\r\n    }\r\n\r\n  #ifdef HASH_ARRAY_3\r\n  \r\n  UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  distances[3] = 0xFFFFFFFF;\r\n  if(curMatch3 > matchMinPos)\r\n    if (_buffer[curMatch3] == cur[0])\r\n    {\r\n      distances[3] = _pos - curMatch3 - 1;\r\n      maxLen = 3;\r\n    }\r\n  \r\n  #endif\r\n  #endif\r\n\r\n  UInt32 curMatch = _hash[hashValue];\r\n  _hash[hashValue] = _pos;\r\n  CIndex *chain = _hash + kHashSizeSum;\r\n  chain[_cyclicBufferPos] = curMatch;\r\n  distances[kNumHashBytes] = 0xFFFFFFFF;\r\n  #ifdef THERE_ARE_DIRECT_HASH_BYTES\r\n  if (lenLimit == kNumHashDirectBytes)\r\n  {\r\n    if(curMatch > matchMinPos)\r\n      while (maxLen < kNumHashDirectBytes)\r\n        distances[++maxLen] = _pos - curMatch - 1;\r\n  }\r\n  else\r\n  #endif\r\n  {\r\n    UInt32 count = _cutValue;\r\n    do\r\n    {\r\n      if(curMatch <= matchMinPos)\r\n        break;\r\n      Byte *pby1 = _buffer + curMatch;\r\n      UInt32 currentLen = kNumHashDirectBytes;\r\n      do \r\n      {\r\n        if (pby1[currentLen] != cur[currentLen])\r\n          break;\r\n      }\r\n      while(++currentLen != lenLimit);\r\n      \r\n      UInt32 delta = _pos - curMatch;\r\n      while (maxLen < currentLen)\r\n        distances[++maxLen] = delta - 1;\r\n      if(currentLen == lenLimit)\r\n        break;\r\n      \r\n      UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r\n        (_cyclicBufferPos - delta):\r\n      (_cyclicBufferPos - delta + _cyclicBufferSize);\r\n      \r\n      curMatch = chain[cyclicPos];\r\n    }\r\n    while(--count != 0);\r\n  }\r\n  #ifdef HASH_ARRAY_2\r\n  #ifdef HASH_ARRAY_3\r\n  if (distances[4] < distances[3])\r\n    distances[3] = distances[4];\r\n  #endif\r\n  if (distances[3] < distances[2])\r\n    distances[2] = distances[3];\r\n  #endif\r\n  return maxLen;\r\n}\r\n\r\nSTDMETHODIMP_(void) CMatchFinderHC::DummyLongestMatch()\r\n{\r\n  if (_streamPos - _pos < kNumHashBytes)\r\n    return; \r\n  \r\n  Byte *cur = _buffer + _pos;\r\n  \r\n  #ifdef HASH_ARRAY_2\r\n  UInt32 hash2Value;\r\n  #ifdef HASH_ARRAY_3\r\n  UInt32 hash3Value;\r\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\r\n  _hash[kHash3Offset + hash3Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur, hash2Value);\r\n  #endif\r\n  _hash[kHash2Offset + hash2Value] = _pos;\r\n  #else\r\n  UInt32 hashValue = Hash(cur);\r\n  #endif\r\n\r\n  _hash[kHashSizeSum + _cyclicBufferPos] = _hash[hashValue];\r\n  _hash[hashValue] = _pos;\r\n}\r\n\r\nvoid CMatchFinderHC::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _cyclicBufferSize;\r\n  CIndex *items = _hash;\r\n  UInt32 numItems = kHashSizeSum + _cyclicBufferSize;\r\n  for (UInt32 i = 0; i < numItems; i++)\r\n  {\r\n    UInt32 value = items[i];\r\n    if (value <= subValue)\r\n      value = kEmptyHashValue;\r\n    else\r\n      value -= subValue;\r\n    items[i] = value;\r\n  }\r\n  ReduceOffsets(subValue);\r\n}\r\n\r\nSTDMETHODIMP CMatchFinderHC::MovePos()\r\n{\r\n  if (++_cyclicBufferPos == _cyclicBufferSize)\r\n    _cyclicBufferPos = 0;\r\n  RINOK(CLZInWindow::MovePos());\r\n  if (_pos == kMaxValForNormalize)\r\n    Normalize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(Byte) CMatchFinderHC::GetIndexByte(Int32 index)\r\n  { return CLZInWindow::GetIndexByte(index); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetMatchLen(Int32 index, \r\n    UInt32 back, UInt32 limit)\r\n  { return CLZInWindow::GetMatchLen(index, back, limit); }\r\n\r\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetNumAvailableBytes()\r\n  { return CLZInWindow::GetNumAvailableBytes(); }\r\n\r\nSTDMETHODIMP_(const Byte *) CMatchFinderHC::GetPointerToCurrentPos()\r\n  { return CLZInWindow::GetPointerToCurrentPos(); }\r\n\r\n// IMatchFinderSetCallback\r\nSTDMETHODIMP CMatchFinderHC::SetCallback(IMatchFinderCallback *callback)\r\n{\r\n  m_Callback = callback;\r\n  return S_OK;\r\n}\r\n\r\nvoid CMatchFinderHC::BeforeMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->BeforeChangingBufferPos();\r\n  CLZInWindow::BeforeMoveBlock();\r\n}\r\n\r\nvoid CMatchFinderHC::AfterMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->AfterChangingBufferPos();\r\n  CLZInWindow::AfterMoveBlock();\r\n}\r\n \r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/IMatchFinder.h",
    "content": "// MatchFinders/IMatchFinder.h\r\n\r\n#ifndef __IMATCHFINDER_H\r\n#define __IMATCHFINDER_H\r\n\r\n// {23170F69-40C1-278A-0000-000200010000}\r\nDEFINE_GUID(IID_IInWindowStream, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200010000\")\r\nIInWindowStream: public IUnknown\r\n{\r\n  STDMETHOD(Init)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD_(void, ReleaseStream)() PURE;\r\n  STDMETHOD(MovePos)() PURE;\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;\r\n};\r\n \r\n// {23170F69-40C1-278A-0000-000200020000}\r\nDEFINE_GUID(IID_IMatchFinder, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020000\")\r\nIMatchFinder: public IInWindowStream\r\n{\r\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances) PURE;\r\n  STDMETHOD_(void, DummyLongestMatch)() PURE;\r\n};\r\n\r\n// {23170F69-40C1-278A-0000-000200020100}\r\nDEFINE_GUID(IID_IMatchFinderCallback, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020100\")\r\nIMatchFinderCallback: public IUnknown\r\n{\r\n  STDMETHOD(BeforeChangingBufferPos)() PURE;\r\n  STDMETHOD(AfterChangingBufferPos)() PURE;\r\n};\r\n\r\n// {23170F69-40C1-278A-0000-000200020200}\r\nDEFINE_GUID(IID_IMatchFinderSetCallback, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020200\")\r\nIMatchFinderSetCallback: public IUnknown\r\n{\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback) PURE;\r\n};\r\n\r\n/*\r\n// {23170F69-40C1-278A-0000-000200030000}\r\nDEFINE_GUID(IID_IInitMatchFinder, \r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00);\r\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200030000\")\r\nIMatchFinderInit: public IUnknown\r\n{\r\n  STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder) PURE;\r\n};\r\n*/\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/LZInWindow.cpp",
    "content": "// LZInWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZInWindow.h\"\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n\r\nvoid CLZInWindow::Free()\r\n{\r\n  ::BigFree(_bufferBase);\r\n  _bufferBase = 0;\r\n}\r\n\r\nbool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n{\r\n  _keepSizeBefore = keepSizeBefore;\r\n  _keepSizeAfter = keepSizeAfter;\r\n  _keepSizeReserv = keepSizeReserv;\r\n  UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n  if (_bufferBase == 0 || _blockSize != blockSize)\r\n  {\r\n    Free();\r\n    _blockSize = blockSize;\r\n    if (_blockSize != 0)\r\n      _bufferBase = (Byte *)::BigAlloc(_blockSize);\r\n  }\r\n  _pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;\r\n  if (_blockSize == 0)\r\n    return true;\r\n  return (_bufferBase != 0);\r\n}\r\n\r\n\r\nHRESULT CLZInWindow::Init(ISequentialInStream *stream)\r\n{\r\n  _stream = stream;\r\n  _buffer = _bufferBase;\r\n  _pos = 0;\r\n  _streamPos = 0;\r\n  _streamEndWasReached = false;\r\n  return ReadBlock();\r\n}\r\n\r\n/*\r\nvoid CLZInWindow::ReleaseStream()\r\n{\r\n  _stream.Release();\r\n}\r\n*/\r\n\r\n///////////////////////////////////////////\r\n// ReadBlock\r\n\r\n// In State:\r\n//   (_buffer + _streamPos) <= (_bufferBase + _blockSize)\r\n// Out State:\r\n//   _posLimit <= _blockSize - _keepSizeAfter;\r\n//   if(_streamEndWasReached == false):\r\n//     _streamPos >= _pos + _keepSizeAfter\r\n//     _posLimit = _streamPos - _keepSizeAfter;\r\n//   else\r\n//          \r\n  \r\nHRESULT CLZInWindow::ReadBlock()\r\n{\r\n  if(_streamEndWasReached)\r\n    return S_OK;\r\n  while(true)\r\n  {\r\n    UInt32 size = UInt32(_bufferBase - _buffer) + _blockSize - _streamPos;\r\n    if(size == 0)\r\n      return S_OK;\r\n    UInt32 numReadBytes;\r\n    RINOK(_stream->Read(_buffer + _streamPos, size, &numReadBytes));\r\n    if(numReadBytes == 0)\r\n    {\r\n      _posLimit = _streamPos;\r\n      const Byte *pointerToPostion = _buffer + _posLimit;\r\n      if(pointerToPostion > _pointerToLastSafePosition)\r\n        _posLimit = (UInt32)(_pointerToLastSafePosition - _buffer);\r\n      _streamEndWasReached = true;\r\n      return S_OK;\r\n    }\r\n    _streamPos += numReadBytes;\r\n    if(_streamPos >= _pos + _keepSizeAfter)\r\n    {\r\n      _posLimit = _streamPos - _keepSizeAfter;\r\n      return S_OK;\r\n    }\r\n  }\r\n}\r\n\r\nvoid CLZInWindow::MoveBlock()\r\n{\r\n  BeforeMoveBlock();\r\n  UInt32 offset = UInt32(_buffer - _bufferBase) + _pos - _keepSizeBefore;\r\n  UInt32 numBytes = UInt32(_buffer - _bufferBase) + _streamPos -  offset;\r\n  memmove(_bufferBase, _bufferBase + offset, numBytes);\r\n  _buffer -= offset;\r\n  AfterMoveBlock();\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/LZInWindow.h",
    "content": "// LZInWindow.h\r\n\r\n#ifndef __LZ_IN_WINDOW_H\r\n#define __LZ_IN_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n\r\nclass CLZInWindow\r\n{\r\n  Byte *_bufferBase; // pointer to buffer with data\r\n  ISequentialInStream *_stream;\r\n  UInt32 _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n  bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n  const Byte *_pointerToLastSafePosition;\r\nprotected:\r\n  Byte  *_buffer;   // Pointer to virtual Buffer begin\r\n  UInt32 _blockSize;  // Size of Allocated memory block\r\n  UInt32 _pos;             // offset (from _buffer) of curent byte\r\n  UInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n  UInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n  UInt32 _keepSizeReserv;  // how many BYTEs must be kept as reserv\r\n  UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\r\n  virtual void BeforeMoveBlock() {};\r\n  virtual void AfterMoveBlock() {};\r\n  void MoveBlock();\r\n  virtual HRESULT ReadBlock();\r\n  void Free();\r\npublic:\r\n  CLZInWindow(): _bufferBase(0) {}\r\n  virtual ~CLZInWindow() { Free(); }\r\n\r\n  bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, \r\n      UInt32 keepSizeReserv = (1<<17));\r\n\r\n  HRESULT Init(ISequentialInStream *stream);\r\n  // void ReleaseStream();\r\n\r\n  Byte *GetBuffer() const { return _buffer; }\r\n\r\n  const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }\r\n\r\n  HRESULT MovePos()\r\n  {\r\n    _pos++;\r\n    if (_pos > _posLimit)\r\n    {\r\n      const Byte *pointerToPostion = _buffer + _pos;\r\n      if(pointerToPostion > _pointerToLastSafePosition)\r\n        MoveBlock();\r\n      return ReadBlock();\r\n    }\r\n    else\r\n      return S_OK;\r\n  }\r\n  Byte GetIndexByte(Int32 index)const\r\n    {  return _buffer[(size_t)_pos + index]; }\r\n\r\n  // index + limit have not to exceed _keepSizeAfter;\r\n  UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const\r\n  {  \r\n    if(_streamEndWasReached)\r\n      if ((_pos + index) + limit > _streamPos)\r\n        limit = _streamPos - (_pos + index);\r\n    distance++;\r\n    Byte *pby = _buffer + (size_t)_pos + index;\r\n    UInt32 i;\r\n    for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);\r\n    return i;\r\n  }\r\n\r\n  UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }\r\n\r\n  void ReduceOffsets(Int32 subValue)\r\n  {\r\n    _buffer += subValue;\r\n    _posLimit -= subValue;\r\n    _pos -= subValue;\r\n    _streamPos -= subValue;\r\n  }\r\n\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/LZOutWindow.cpp",
    "content": "// LZOutWindow.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"LZOutWindow.h\"\r\n\r\nvoid CLZOutWindow::Init(bool solid)\r\n{\r\n  if(!solid)\r\n    COutBuffer::Init();\r\n  #ifdef _NO_EXCEPTIONS\r\n  ErrorCode = S_OK;\r\n  #endif\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/LZOutWindow.h",
    "content": "// LZOutWindow.h\r\n\r\n#ifndef __LZ_OUT_WINDOW_H\r\n#define __LZ_OUT_WINDOW_H\r\n\r\n#include \"../../IStream.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\n/*\r\n#ifndef _NO_EXCEPTIONS\r\nclass CLZOutWindowException\r\n{\r\npublic:\r\n  HRESULT ErrorCode;\r\n  CLZOutWindowException(HRESULT errorCode): ErrorCode(errorCode) {}\r\n};\r\n#endif\r\n*/\r\ntypedef COutBufferException CLZOutWindowException;\r\n\r\nclass CLZOutWindow: public COutBuffer\r\n{\r\npublic:\r\n  void Init(bool solid = false);\r\n  \r\n  // distance >= 0, len > 0, \r\n  bool CopyBlock(UInt32 distance, UInt32 len)\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n    {\r\n      if (!_overDict)\r\n        return false;\r\n      pos += _bufferSize;\r\n    }\r\n    do\r\n    {\r\n      if (pos == _bufferSize)\r\n        pos = 0;\r\n      _buffer[_pos++] = _buffer[pos++];\r\n      if (_pos == _limitPos)\r\n        FlushWithCheck();  \r\n    }\r\n    while(--len != 0);\r\n    return true;\r\n  }\r\n  \r\n  void PutByte(Byte b)\r\n  {\r\n    _buffer[_pos++] = b;\r\n    if (_pos == _limitPos)\r\n      FlushWithCheck();  \r\n  }\r\n  \r\n  Byte GetByte(UInt32 distance) const\r\n  {\r\n    UInt32 pos = _pos - distance - 1;\r\n    if (pos >= _bufferSize)\r\n      pos += _bufferSize;\r\n    return _buffer[pos]; \r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/Patricia/Pat.h",
    "content": "// Pat.h\r\n\r\n// #ifndef __PATRICIA__H\r\n// #define __PATRICIA__H\r\n\r\n#include \"../../../../Common/MyCom.h\"\r\n#include \"../../../../Common/Types.h\"\r\n#include \"../LZInWindow.h\"\r\n\r\nnamespace PAT_NAMESPACE {\r\n\r\nstruct CNode;\r\n\r\ntypedef CNode *CNodePointer;\r\n\r\n// #define __AUTO_REMOVE\r\n\r\n// #define __NODE_4_BITS\r\n// #define __NODE_3_BITS\r\n// #define __NODE_2_BITS\r\n// #define __NODE_2_BITS_PADDING\r\n\r\n// #define __HASH_3\r\n\r\n\r\ntypedef UInt32 CIndex;\r\n\r\n#ifdef __NODE_4_BITS\r\n  typedef UInt32 CIndex2;\r\n  typedef UInt32 CSameBitsType;\r\n#else\r\n#ifdef __NODE_3_BITS\r\n  typedef UInt32 CIndex2;\r\n  typedef UInt32 CSameBitsType;\r\n#else\r\n\r\n  typedef UInt32 CIndex;\r\n  typedef UInt32 CSameBitsType;\r\n\r\n  typedef CIndex CIndex2;\r\n#endif\r\n#endif\r\n\r\nconst UInt32 kNumBitsInIndex = sizeof(CIndex) * 8;\r\nconst UInt32 kMatchStartValue = UInt32(1) << (kNumBitsInIndex - 1);\r\n// don't change kMatchStartValue definition, since it is used in \r\n// PatMain.h: \r\n\r\ntypedef CIndex CMatchPointer;\r\n\r\nconst UInt32 kDescendantEmptyValue = kMatchStartValue - 1;\r\n\r\nunion CDescendant \r\n{\r\n  CIndex NodePointer;\r\n  CMatchPointer MatchPointer;\r\n  bool IsEmpty() const { return NodePointer == kDescendantEmptyValue; }\r\n  bool IsNode() const { return NodePointer < kDescendantEmptyValue; }\r\n  bool IsMatch() const { return NodePointer > kDescendantEmptyValue; }\r\n  void MakeEmpty() { NodePointer = kDescendantEmptyValue; }\r\n};\r\n\r\n#undef MY_BYTE_SIZE\r\n\r\n#ifdef __NODE_4_BITS\r\n  #define MY_BYTE_SIZE 8\r\n  const UInt32 kNumSubBits = 4;\r\n#else\r\n#ifdef __NODE_3_BITS\r\n  #define MY_BYTE_SIZE 9\r\n  const UInt32 kNumSubBits = 3;\r\n#else\r\n  #define MY_BYTE_SIZE 8\r\n  #ifdef __NODE_2_BITS\r\n    const UInt32 kNumSubBits = 2;\r\n  #else\r\n    const UInt32 kNumSubBits = 1;\r\n  #endif\r\n#endif\r\n#endif\r\n\r\nconst UInt32 kNumSubNodes = 1 << kNumSubBits;\r\nconst UInt32 kSubNodesMask = kNumSubNodes - 1;\r\n\r\nstruct CNode\r\n{\r\n  CIndex2 LastMatch;\r\n  CSameBitsType NumSameBits;\r\n  union\r\n  {\r\n    CDescendant  Descendants[kNumSubNodes];\r\n    UInt32 NextFreeNode;\r\n  };\r\n  #ifdef __NODE_2_BITS\r\n  #ifdef __NODE_2_BITS_PADDING\r\n  UInt32 Padding[2];\r\n  #endif\r\n  #endif\r\n};\r\n\r\n#undef kIDNumBitsByte\r\n#undef kIDNumBitsString\r\n\r\n#ifdef __NODE_4_BITS\r\n  #define kIDNumBitsByte 0x30\r\n  #define kIDNumBitsString TEXT(\"4\")\r\n#else\r\n#ifdef __NODE_3_BITS\r\n  #define kIDNumBitsByte 0x20\r\n  #define kIDNumBitsString TEXT(\"3\")\r\n#else\r\n#ifdef __NODE_2_BITS\r\n  #define kIDNumBitsByte 0x10\r\n  #define kIDNumBitsString TEXT(\"2\")\r\n#else\r\n  #define kIDNumBitsByte 0x00\r\n  #define kIDNumBitsString TEXT(\"1\")\r\n#endif\r\n#endif\r\n#endif\r\n\r\n#undef kIDManualRemoveByte\r\n#undef kIDManualRemoveString\r\n\r\n#ifdef __AUTO_REMOVE\r\n  #define kIDManualRemoveByte 0x00\r\n  #define kIDManualRemoveString TEXT(\"\")\r\n#else\r\n  #define kIDManualRemoveByte 0x08\r\n  #define kIDManualRemoveString TEXT(\"R\")\r\n#endif\r\n\r\n#undef kIDHash3Byte\r\n#undef kIDHash3String\r\n\r\n#ifdef __HASH_3\r\n  #define kIDHash3Byte 0x04\r\n  #define kIDHash3String TEXT(\"H\")\r\n#else\r\n  #define kIDHash3Byte 0x00\r\n  #define kIDHash3String TEXT(\"\")\r\n#endif\r\n\r\n#undef kIDUse3BytesByte\r\n#undef kIDUse3BytesString\r\n\r\n#define kIDUse3BytesByte 0x00\r\n#define kIDUse3BytesString TEXT(\"\")\r\n\r\n#undef kIDPaddingByte\r\n#undef kIDPaddingString\r\n\r\n#ifdef __NODE_2_BITS_PADDING\r\n  #define kIDPaddingByte 0x01\r\n  #define kIDPaddingString TEXT(\"P\")\r\n#else\r\n  #define kIDPaddingByte 0x00\r\n  #define kIDPaddingString TEXT(\"\")\r\n#endif\r\n\r\n\r\n// #undef kIDString\r\n// #define kIDString TEXT(\"Compress.MatchFinderPat\") kIDNumBitsString kIDManualRemoveString kIDUse3BytesString kIDPaddingString kIDHash3String\r\n\r\n// {23170F69-40C1-278C-01XX-0000000000}\r\n\r\nDEFINE_GUID(PAT_CLSID, \r\n0x23170F69, 0x40C1, 0x278C, 0x01, \r\nkIDNumBitsByte | \r\nkIDManualRemoveByte | kIDHash3Byte | kIDUse3BytesByte | kIDPaddingByte, \r\n0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\r\n\r\n// III(PAT_NAMESPACE)\r\n\r\nclass CPatricia: \r\n  public IMatchFinder,\r\n  public IMatchFinderSetCallback,\r\n  public CMyUnknownImp,\r\n  CLZInWindow\r\n{ \r\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\r\n\r\n  STDMETHOD(Init)(ISequentialInStream *aStream);\r\n  STDMETHOD_(void, ReleaseStream)();\r\n  STDMETHOD(MovePos)();\r\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r\n  STDMETHOD(Create)(UInt32 historySize, \r\n      UInt32 keepAddBufferBefore, UInt32 matchMaxLen, \r\n      UInt32 keepAddBufferAfter);\r\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\r\n  STDMETHOD_(void, DummyLongestMatch)();\r\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r\n\r\n  void FreeMemory();\r\npublic:\r\n  CPatricia();\r\n  ~CPatricia();\r\n\r\n  UInt32 _sizeHistory;\r\n  UInt32 _matchMaxLen;\r\n\r\n  CDescendant *m_HashDescendants;\r\n  #ifdef __HASH_3\r\n  CDescendant *m_Hash2Descendants;\r\n  #endif\r\n\r\n  CNode *m_Nodes;\r\n\r\n  UInt32 m_FreeNode;\r\n  UInt32 m_FreeNodeMax;\r\n\r\n  #ifdef __AUTO_REMOVE\r\n  UInt32 m_NumUsedNodes;\r\n  UInt32 m_NumNodes;\r\n  #else\r\n  bool  m_SpecialRemoveMode;\r\n  #endif\r\n\r\n  bool  m_SpecialMode;\r\n  UInt32 m_NumNotChangedCycles;\r\n  UInt32 *m_TmpBacks;\r\n\r\n  CMyComPtr<IMatchFinderCallback> m_Callback;\r\n\r\n  virtual void BeforeMoveBlock();\r\n  virtual void AfterMoveBlock();\r\n\r\n  // IMatchFinderSetCallback\r\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\r\n\r\n  void ChangeLastMatch(UInt32 hashValue);\r\n  \r\n  #ifdef __AUTO_REMOVE\r\n  void TestRemoveDescendant(CDescendant &descendant, UInt32 limitPos);\r\n  void TestRemoveNodes();\r\n  void RemoveNode(UInt32 index);\r\n  void TestRemoveAndNormalizeDescendant(CDescendant &descendant, \r\n      UInt32 limitPos, UInt32 subValue);\r\n  void TestRemoveNodesAndNormalize();\r\n  #else\r\n  void NormalizeDescendant(CDescendant &descendant, UInt32 subValue);\r\n  void Normalize();\r\n  void RemoveMatch();\r\n  #endif\r\nprivate:\r\n  void AddInternalNode(CNodePointer aNode, CIndex *aNodePointerPointer, \r\n      Byte aByte, Byte aByteXOR, UInt32 aNumSameBits, UInt32 aPos)\r\n  {\r\n    while((aByteXOR & kSubNodesMask) == 0)\r\n    {\r\n      aByteXOR >>= kNumSubBits;\r\n      aByte >>= kNumSubBits;\r\n      aNumSameBits -= kNumSubBits;\r\n    }\r\n    // Insert New Node\r\n    CNodePointer aNewNode = &m_Nodes[m_FreeNode];\r\n    UInt32 aNodeIndex = *aNodePointerPointer;\r\n    *aNodePointerPointer = m_FreeNode;\r\n    m_FreeNode = aNewNode->NextFreeNode;\r\n    #ifdef __AUTO_REMOVE\r\n    m_NumUsedNodes++;\r\n    #endif\r\n    if (m_FreeNode > m_FreeNodeMax)\r\n    {\r\n      m_FreeNodeMax = m_FreeNode;\r\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\r\n    }\r\n\r\n    UInt32 aBitsNew = aByte & kSubNodesMask;\r\n    UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;\r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n      aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;\r\n    aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;\r\n    aNewNode->Descendants[aBitsOld].NodePointer = aNodeIndex;\r\n    aNewNode->NumSameBits = CSameBitsType(aNode->NumSameBits - aNumSameBits);\r\n    aNewNode->LastMatch = aPos;\r\n    \r\n    aNode->NumSameBits = CSameBitsType(aNumSameBits - kNumSubBits);\r\n  }\r\n\r\n  void AddLeafNode(CNodePointer aNode, Byte aByte, Byte aByteXOR, \r\n      UInt32 aNumSameBits, UInt32 aPos, UInt32 aDescendantIndex)\r\n  {\r\n    for(;(aByteXOR & kSubNodesMask) == 0; aNumSameBits += kNumSubBits)\r\n    {\r\n      aByte >>= kNumSubBits;\r\n      aByteXOR >>= kNumSubBits;\r\n    }\r\n    UInt32 aNewNodeIndex = m_FreeNode;\r\n    CNodePointer aNewNode = &m_Nodes[m_FreeNode];\r\n    m_FreeNode = aNewNode->NextFreeNode;\r\n    #ifdef __AUTO_REMOVE\r\n    m_NumUsedNodes++;\r\n    #endif\r\n    if (m_FreeNode > m_FreeNodeMax)\r\n    {\r\n      m_FreeNodeMax = m_FreeNode;\r\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\r\n    }\r\n\r\n    UInt32 aBitsNew = (aByte & kSubNodesMask);\r\n    UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;\r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n      aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;\r\n    aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;\r\n    aNewNode->Descendants[aBitsOld].MatchPointer = \r\n      aNode->Descendants[aDescendantIndex].MatchPointer;\r\n    aNewNode->NumSameBits = CSameBitsType(aNumSameBits);\r\n    aNewNode->LastMatch = aPos;\r\n    aNode->Descendants[aDescendantIndex].NodePointer = aNewNodeIndex;\r\n  }\r\n};\r\n\r\n}\r\n\r\n// #endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/Patricia/Pat2.h",
    "content": "// Pat2.h\r\n\r\n#ifndef __PAT2__H\r\n#define __PAT2__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat2\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat2\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_2_BITS\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef  __NODE_2_BITS\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/Patricia/Pat2H.h",
    "content": "// Pat2H.h\r\n\r\n#ifndef __PAT2H__H\r\n#define __PAT2H__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat2H\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat2H\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_2_BITS\r\n#define __HASH_3\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef __NODE_2_BITS\r\n#undef __HASH_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/Patricia/Pat2R.h",
    "content": "// Pat2R.h\r\n\r\n#ifndef __PAT2R__H\r\n#define __PAT2R__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat2R\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat2R\r\n\r\n#define __NODE_2_BITS\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef  __NODE_2_BITS\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/Patricia/Pat3H.h",
    "content": "// Pat3H.h\r\n\r\n#ifndef __PAT3H__H\r\n#define __PAT3H__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat3H\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat3H\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_3_BITS\r\n#define __HASH_3\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef __NODE_3_BITS\r\n#undef __HASH_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/Patricia/Pat4H.h",
    "content": "// Pat4H.h\r\n\r\n#ifndef __PAT4H__H\r\n#define __PAT4H__H\r\n\r\n#undef PAT_CLSID\r\n#define PAT_CLSID CLSID_CMatchFinderPat4H\r\n\r\n#undef PAT_NAMESPACE\r\n#define PAT_NAMESPACE NPat4H\r\n\r\n#define __AUTO_REMOVE\r\n#define __NODE_4_BITS\r\n#define __HASH_3\r\n\r\n#include \"Pat.h\"\r\n#include \"PatMain.h\"\r\n\r\n#undef __AUTO_REMOVE\r\n#undef __NODE_4_BITS\r\n#undef __HASH_3\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/Patricia/PatMain.h",
    "content": "// PatMain.h\r\n\r\n#include \"../../../../Common/Defs.h\"\r\n#include \"../../../../Common/Alloc.h\"\r\n\r\nnamespace PAT_NAMESPACE {\r\n\r\nSTDMETHODIMP CPatricia::SetCallback(IMatchFinderCallback *callback)\r\n{\r\n  m_Callback = callback;\r\n  return S_OK;\r\n}\r\n\r\nvoid CPatricia::BeforeMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->BeforeChangingBufferPos();\r\n  CLZInWindow::BeforeMoveBlock();\r\n}\r\n\r\nvoid CPatricia::AfterMoveBlock()\r\n{\r\n  if (m_Callback)\r\n    m_Callback->AfterChangingBufferPos();\r\n  CLZInWindow::AfterMoveBlock();\r\n}\r\n\r\nconst UInt32 kMatchStartValue2 = 2;\r\nconst UInt32 kDescendantEmptyValue2 = kMatchStartValue2 - 1;\r\nconst UInt32 kDescendantsNotInitilized2 = kDescendantEmptyValue2 - 1;\r\n\r\n#ifdef __HASH_3\r\n\r\nstatic const UInt32 kNumHashBytes = 3;\r\nstatic const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\n\r\nstatic const UInt32 kNumHash2Bytes = 2;\r\nstatic const UInt32 kHash2Size = 1 << (8 * kNumHash2Bytes);\r\nstatic const UInt32 kPrevHashSize = kNumHash2Bytes;\r\n\r\n#else\r\n\r\nstatic const UInt32 kNumHashBytes = 2;\r\nstatic const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r\nstatic const UInt32 kPrevHashSize = 0;\r\n\r\n#endif\r\n\r\n\r\nCPatricia::CPatricia():\r\n  m_HashDescendants(0),\r\n  #ifdef __HASH_3\r\n  m_Hash2Descendants(0),\r\n  #endif\r\n  m_Nodes(0),\r\n  m_TmpBacks(0)\r\n{\r\n}\r\n\r\nCPatricia::~CPatricia()\r\n{\r\n  FreeMemory();\r\n}\r\n\r\nvoid CPatricia::FreeMemory()\r\n{\r\n  MyFree(m_TmpBacks);\r\n  m_TmpBacks = 0;\r\n\r\n  ::BigFree(m_Nodes);\r\n  m_Nodes = 0;\r\n\r\n  ::BigFree(m_HashDescendants);\r\n  m_HashDescendants = 0;\r\n\r\n  #ifdef __HASH_3\r\n\r\n  ::BigFree(m_Hash2Descendants);\r\n  m_Hash2Descendants = 0;\r\n\r\n  CLZInWindow::Free();\r\n\r\n  #endif\r\n}\r\n  \r\nSTDMETHODIMP CPatricia::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r\n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n{\r\n  FreeMemory();\r\n  int kNumBitsInNumSameBits = sizeof(CSameBitsType) * 8;\r\n  if (kNumBitsInNumSameBits < 32 && ((matchMaxLen * MY_BYTE_SIZE) > ((UInt32)1 << kNumBitsInNumSameBits)))\r\n    return E_INVALIDARG;\r\n\r\n  const UInt32 kAlignMask = (1 << 16) - 1;\r\n  UInt32 windowReservSize = historySize;\r\n  windowReservSize += kAlignMask;\r\n  windowReservSize &= ~(kAlignMask);\r\n\r\n  const UInt32 kMinReservSize = (1 << 19);\r\n  if (windowReservSize < kMinReservSize)\r\n    windowReservSize = kMinReservSize;\r\n  windowReservSize += 256;\r\n\r\n  if (!CLZInWindow::Create(historySize + keepAddBufferBefore, \r\n      matchMaxLen + keepAddBufferAfter, windowReservSize))\r\n    return E_OUTOFMEMORY;\r\n\r\n  _sizeHistory = historySize;\r\n  _matchMaxLen = matchMaxLen;\r\n  m_HashDescendants = (CDescendant *)BigAlloc(kHashSize * sizeof(CDescendant));\r\n  if (m_HashDescendants == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n\r\n  #ifdef __HASH_3\r\n  m_Hash2Descendants = (CDescendant *)BigAlloc(kHash2Size  * sizeof(CDescendant));\r\n  if (m_Hash2Descendants == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n  #endif\r\n  \r\n  #ifdef __AUTO_REMOVE\r\n  \r\n  #ifdef __HASH_3\r\n  m_NumNodes = historySize + _sizeHistory * 4 / 8 + (1 << 19);\r\n  #else\r\n  m_NumNodes = historySize + _sizeHistory * 4 / 8 + (1 << 10);\r\n  #endif\r\n  \r\n  #else\r\n  \r\n  UInt32 m_NumNodes = historySize;\r\n  \r\n  #endif\r\n  \r\n  const UInt32 kMaxNumNodes = UInt32(1) << (sizeof(CIndex) * 8 - 1);\r\n  if (m_NumNodes + 32 > kMaxNumNodes)\r\n    return E_INVALIDARG;\r\n  \r\n  // m_Nodes = (CNode *)::BigAlloc((m_NumNodes + 2) * sizeof(CNode));\r\n  m_Nodes = (CNode *)::BigAlloc((m_NumNodes + 12) * sizeof(CNode));\r\n  if (m_Nodes == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n  \r\n  m_TmpBacks = (UInt32 *)MyAlloc((_matchMaxLen + 1) * sizeof(UInt32));\r\n  if (m_TmpBacks == 0)\r\n  {\r\n    FreeMemory();\r\n    return E_OUTOFMEMORY;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CPatricia::Init(ISequentialInStream *aStream)\r\n{\r\n  RINOK(CLZInWindow::Init(aStream));\r\n\r\n  // memset(m_HashDescendants, 0xFF, kHashSize * sizeof(m_HashDescendants[0]));\r\n\r\n  #ifdef __HASH_3\r\n  for (UInt32 i = 0; i < kHash2Size; i++)\r\n    m_Hash2Descendants[i].MatchPointer = kDescendantsNotInitilized2;\r\n  #else\r\n  for (UInt32 i = 0; i < kHashSize; i++)\r\n    m_HashDescendants[i].MakeEmpty();\r\n  #endif\r\n\r\n  m_Nodes[0].NextFreeNode = 1;\r\n  m_FreeNode = 0;\r\n  m_FreeNodeMax = 0;\r\n  #ifdef __AUTO_REMOVE\r\n  m_NumUsedNodes = 0;\r\n  #else\r\n  m_SpecialRemoveMode = false;\r\n  #endif\r\n  m_SpecialMode = false;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP_(void) CPatricia::ReleaseStream()\r\n{\r\n  // CLZInWindow::ReleaseStream();\r\n}\r\n\r\n// pos = _pos + kNumHashBytes\r\n// fullCurrentLimit = currentLimit + kNumHashBytes\r\n// fullMatchLen = matchLen + kNumHashBytes\r\n\r\nvoid CPatricia::ChangeLastMatch(UInt32 hashValue)\r\n{\r\n  UInt32 pos = _pos + kNumHashBytes - 1;\r\n  UInt32 descendantIndex;\r\n  const Byte *currentBytePointer = _buffer + pos;\r\n  UInt32 numLoadedBits = 0;\r\n  Byte curByte = 0;  // = 0 to disable warning of GCC\r\n  CNodePointer node = &m_Nodes[m_HashDescendants[hashValue].NodePointer];\r\n\r\n  while(true)\r\n  {\r\n    UInt32 numSameBits = node->NumSameBits;\r\n    if(numSameBits > 0)\r\n    {\r\n      if (numLoadedBits < numSameBits)\r\n      {\r\n        numSameBits -= numLoadedBits;\r\n        currentBytePointer += (numSameBits / MY_BYTE_SIZE);\r\n        numSameBits %= MY_BYTE_SIZE;\r\n        curByte = *currentBytePointer++;\r\n        numLoadedBits = MY_BYTE_SIZE; \r\n      }\r\n      curByte >>= numSameBits;\r\n      numLoadedBits -= numSameBits;\r\n    }\r\n    if(numLoadedBits == 0)\r\n    {\r\n      curByte = *currentBytePointer++;\r\n      numLoadedBits = MY_BYTE_SIZE; \r\n    }\r\n    descendantIndex = (curByte & kSubNodesMask);\r\n    node->LastMatch = pos;\r\n    numLoadedBits -= kNumSubBits;\r\n    curByte >>= kNumSubBits;\r\n    if(node->Descendants[descendantIndex].IsNode())\r\n      node = &m_Nodes[node->Descendants[descendantIndex].NodePointer];\r\n    else\r\n      break;\r\n  }\r\n  node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n}\r\n\r\nUInt32 CPatricia::GetLongestMatch(UInt32 *distances)\r\n{\r\n  UInt32 fullCurrentLimit;\r\n  if (_pos + _matchMaxLen <= _streamPos)\r\n    fullCurrentLimit = _matchMaxLen;\r\n  else\r\n  {\r\n    fullCurrentLimit = _streamPos - _pos;\r\n    if(fullCurrentLimit < kNumHashBytes)\r\n      return 0; \r\n  }\r\n  UInt32 pos = _pos + kNumHashBytes;\r\n\r\n  #ifdef __HASH_3\r\n  UInt32 hash2Value = ((UInt32(_buffer[_pos])) << 8) | _buffer[_pos + 1];\r\n  UInt32 hashValue = (hash2Value << 8) | _buffer[_pos + 2];\r\n  CDescendant &hash2Descendant = m_Hash2Descendants[hash2Value];\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  if(hash2Descendant.MatchPointer <= kDescendantEmptyValue2)\r\n  {\r\n    if(hash2Descendant.MatchPointer == kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hashValue & 0xFFFF00;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n        m_HashDescendants[base + i].MakeEmpty();\r\n    }\r\n    hash2Descendant.MatchPointer = pos + kMatchStartValue2;\r\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n    return 0;\r\n  }\r\n\r\n  distances[kNumHash2Bytes] = pos - (hash2Descendant.MatchPointer - kMatchStartValue2) - 1;\r\n  hash2Descendant.MatchPointer = pos + kMatchStartValue2;\r\n  #ifdef __AUTO_REMOVE\r\n  if (distances[kNumHash2Bytes] >= _sizeHistory)\r\n  {\r\n    if (hashDescendant.IsNode())\r\n      RemoveNode(hashDescendant.NodePointer);\r\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n    return 0;\r\n  }\r\n  #endif\r\n  if (fullCurrentLimit == kNumHash2Bytes)\r\n    return kNumHash2Bytes;\r\n\r\n  #else\r\n  UInt32 hashValue = UInt32(GetIndexByte(1))  | (UInt32(GetIndexByte(0)) << 8);\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  #endif\r\n\r\n\r\n  if(m_SpecialMode)\r\n  {\r\n    if(hashDescendant.IsMatch())\r\n      m_NumNotChangedCycles = 0;\r\n    if(m_NumNotChangedCycles >= _sizeHistory - 1)\r\n    {\r\n      ChangeLastMatch(hashValue);\r\n      m_NumNotChangedCycles = 0;\r\n    }\r\n    if(GetIndexByte(fullCurrentLimit - 1) == GetIndexByte(fullCurrentLimit - 2)) \r\n    {\r\n      if(hashDescendant.IsMatch())\r\n        hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n      else\r\n        m_NumNotChangedCycles++;\r\n      for(UInt32 i = kNumHashBytes; i <= fullCurrentLimit; i++)\r\n        distances[i] = 0;\r\n      return fullCurrentLimit;\r\n    }\r\n    else if(m_NumNotChangedCycles > 0)\r\n      ChangeLastMatch(hashValue);\r\n    m_SpecialMode = false;\r\n  }\r\n\r\n  if(hashDescendant.IsEmpty())\r\n  {\r\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n    return kPrevHashSize;\r\n  }\r\n\r\n  UInt32 currentLimit = fullCurrentLimit - kNumHashBytes;\r\n\r\n  if(hashDescendant.IsMatch())\r\n  {\r\n    CMatchPointer matchPointer = hashDescendant.MatchPointer;\r\n    UInt32 backReal = pos - (matchPointer - kMatchStartValue);\r\n    UInt32 back = backReal - 1;\r\n    #ifdef __AUTO_REMOVE\r\n    if (back >= _sizeHistory)\r\n    {\r\n      hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n      return kPrevHashSize;\r\n    }\r\n    #endif\r\n\r\n    UInt32 matchLen;\r\n    distances += kNumHashBytes;\r\n    Byte *buffer = _buffer + pos;\r\n    for(matchLen = 0; true; matchLen++)\r\n    {\r\n      *distances++ = back;\r\n      if (matchLen == currentLimit)\r\n      {\r\n        hashDescendant.MatchPointer = pos + kMatchStartValue;\r\n        return kNumHashBytes + matchLen;\r\n      }\r\n      if (buffer[matchLen] != buffer[(size_t)matchLen - backReal])\r\n        break;\r\n    }\r\n     \r\n    // UInt32 matchLen = GetMatchLen(kNumHashBytes, back, currentLimit);\r\n    \r\n    UInt32 fullMatchLen = matchLen + kNumHashBytes; \r\n    hashDescendant.NodePointer = m_FreeNode;\r\n    CNodePointer node = &m_Nodes[m_FreeNode];\r\n    m_FreeNode = node->NextFreeNode;\r\n    #ifdef __AUTO_REMOVE\r\n    m_NumUsedNodes++;\r\n    #endif\r\n    if (m_FreeNode > m_FreeNodeMax)\r\n    {\r\n      m_FreeNodeMax = m_FreeNode;\r\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\r\n    }\r\n      \r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n      node->Descendants[i].NodePointer = kDescendantEmptyValue;\r\n    node->LastMatch = pos;\r\n      \r\n    Byte byteNew = GetIndexByte(fullMatchLen);\r\n    Byte byteOld = GetIndexByte(fullMatchLen - backReal);\r\n    Byte bitsNew, bitsOld;\r\n    UInt32 numSameBits = matchLen * MY_BYTE_SIZE;\r\n    while (true)\r\n    {\r\n      bitsNew = (byteNew & kSubNodesMask);\r\n      bitsOld = (byteOld & kSubNodesMask);\r\n      if(bitsNew != bitsOld) \r\n        break;\r\n      byteNew >>= kNumSubBits;\r\n      byteOld >>= kNumSubBits;\r\n      numSameBits += kNumSubBits;\r\n    }\r\n    node->NumSameBits = CSameBitsType(numSameBits);\r\n    node->Descendants[bitsNew].MatchPointer = pos + kMatchStartValue;\r\n    node->Descendants[bitsOld].MatchPointer = matchPointer;\r\n    return fullMatchLen;\r\n  }\r\n  const Byte *baseCurrentBytePointer = _buffer + pos;\r\n  const Byte *currentBytePointer = baseCurrentBytePointer;\r\n  UInt32 numLoadedBits = 0;\r\n  Byte curByte = 0;\r\n  CIndex *nodePointerPointer = &hashDescendant.NodePointer;\r\n  CNodePointer node = &m_Nodes[*nodePointerPointer];\r\n  distances += kNumHashBytes;\r\n  const Byte *bytePointerLimit = baseCurrentBytePointer + currentLimit;\r\n  const Byte *currentAddingOffset = _buffer;\r\n\r\n  #ifdef __AUTO_REMOVE\r\n  UInt32 lowPos;\r\n  if (pos > _sizeHistory)\r\n    lowPos = pos - _sizeHistory;\r\n  else\r\n    lowPos = 0;\r\n  #endif\r\n\r\n  while(true)\r\n  {\r\n    #ifdef __AUTO_REMOVE\r\n    if (node->LastMatch < lowPos)\r\n    {\r\n      RemoveNode(*nodePointerPointer);\r\n      *nodePointerPointer = pos + kMatchStartValue;\r\n      if (currentBytePointer == baseCurrentBytePointer)\r\n        return kPrevHashSize;\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n    #endif\r\n    if(numLoadedBits == 0)\r\n    {\r\n      *distances++ = pos - node->LastMatch - 1;\r\n      if(currentBytePointer >= bytePointerLimit)\r\n      {\r\n        for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n          node->Descendants[i].MatchPointer = pos + kMatchStartValue;\r\n        node->LastMatch = pos;\r\n        node->NumSameBits = 0;\r\n        return fullCurrentLimit;\r\n      }\r\n      curByte = (*currentBytePointer++);\r\n      currentAddingOffset++;\r\n      numLoadedBits = MY_BYTE_SIZE; \r\n    }\r\n    UInt32 numSameBits = node->NumSameBits;\r\n    if(numSameBits > 0)\r\n    {\r\n      Byte byteXOR = ((*(currentAddingOffset + node->LastMatch -1)) >> \r\n          (MY_BYTE_SIZE - numLoadedBits)) ^ curByte;\r\n      while(numLoadedBits <= numSameBits)\r\n      {\r\n        if(byteXOR != 0)\r\n        {\r\n          AddInternalNode(node, nodePointerPointer, curByte, byteXOR,\r\n              numSameBits, pos);\r\n          return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n        }\r\n        *distances++ = pos - node->LastMatch - 1;\r\n        numSameBits -= numLoadedBits;\r\n        if(currentBytePointer >= bytePointerLimit)\r\n        {\r\n          for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n            node->Descendants[i].MatchPointer = pos + kMatchStartValue;\r\n          node->LastMatch = pos;\r\n          node->NumSameBits = CSameBitsType(node->NumSameBits - numSameBits);\r\n          return fullCurrentLimit;\r\n        }\r\n        numLoadedBits = MY_BYTE_SIZE; \r\n        curByte = (*currentBytePointer++);\r\n        byteXOR = curByte ^ (*(currentAddingOffset + node->LastMatch));\r\n        currentAddingOffset++;\r\n      }\r\n      if((byteXOR & ((1 << numSameBits) - 1)) != 0)\r\n      {\r\n        AddInternalNode(node, nodePointerPointer, curByte, byteXOR,\r\n            numSameBits, pos);\r\n        return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n      }\r\n      curByte >>= numSameBits;\r\n      numLoadedBits -= numSameBits;\r\n    }\r\n    UInt32 descendantIndex = (curByte & kSubNodesMask);\r\n    numLoadedBits -= kNumSubBits;\r\n    nodePointerPointer = &node->Descendants[descendantIndex].NodePointer;\r\n    UInt32 nextNodeIndex = *nodePointerPointer;\r\n    node->LastMatch = pos;\r\n    if (nextNodeIndex < kDescendantEmptyValue)\r\n    {\r\n      curByte >>= kNumSubBits;\r\n      node = &m_Nodes[nextNodeIndex];\r\n    }\r\n    else if (nextNodeIndex == kDescendantEmptyValue)\r\n    {\r\n      node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n    else \r\n      break;\r\n  }\r\n \r\n  UInt32 descendantIndex = (curByte & kSubNodesMask);\r\n  curByte >>= kNumSubBits;\r\n  CMatchPointer matchPointer = node->Descendants[descendantIndex].MatchPointer;\r\n  CMatchPointer realMatchPointer;\r\n  realMatchPointer = matchPointer - kMatchStartValue;\r\n\r\n  #ifdef __AUTO_REMOVE\r\n  if (realMatchPointer < lowPos)\r\n  {\r\n    node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n    return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n  }\r\n  #endif\r\n\r\n  Byte byteXOR;\r\n  UInt32 numSameBits = 0;\r\n  if(numLoadedBits != 0)\r\n  {\r\n    Byte matchByte = *(currentAddingOffset + realMatchPointer -1);  \r\n    matchByte >>= (MY_BYTE_SIZE - numLoadedBits);\r\n    byteXOR = matchByte ^ curByte;\r\n    if(byteXOR != 0)\r\n    {\r\n      AddLeafNode(node, curByte, byteXOR, numSameBits, pos, descendantIndex);\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n    numSameBits += numLoadedBits;\r\n  }\r\n\r\n  const Byte *matchBytePointer = _buffer + realMatchPointer + \r\n      (currentBytePointer - baseCurrentBytePointer);\r\n  for(; currentBytePointer < bytePointerLimit; numSameBits += MY_BYTE_SIZE)\r\n  {\r\n    curByte = (*currentBytePointer++);\r\n    *distances++ = pos - realMatchPointer - 1;\r\n    byteXOR = curByte ^ (*matchBytePointer++);\r\n    if(byteXOR != 0)\r\n    {\r\n      AddLeafNode(node, curByte, byteXOR, numSameBits, pos, descendantIndex);\r\n      return kNumHashBytes + (UInt32)(currentBytePointer - baseCurrentBytePointer - 1);\r\n    }\r\n  }\r\n  *distances = pos - realMatchPointer - 1;\r\n  node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\r\n\r\n  if(*distances == 0)\r\n  {\r\n    m_SpecialMode = true;\r\n    m_NumNotChangedCycles = 0;\r\n  }\r\n  return fullCurrentLimit;\r\n}\r\n\r\nSTDMETHODIMP_(void) CPatricia::DummyLongestMatch()\r\n{\r\n  GetLongestMatch(m_TmpBacks);\r\n}\r\n\r\n\r\n// ------------------------------------\r\n// Remove Match\r\n\r\ntypedef Byte CRemoveDataWord;\r\n\r\nstatic const int kSizeRemoveDataWordInBits = MY_BYTE_SIZE * sizeof(CRemoveDataWord);\r\n\r\n#ifndef __AUTO_REMOVE\r\n\r\nvoid CPatricia::RemoveMatch()\r\n{\r\n  if(m_SpecialRemoveMode)\r\n  {\r\n    if(GetIndexByte(_matchMaxLen - 1 - _sizeHistory) ==\r\n        GetIndexByte(_matchMaxLen - _sizeHistory))\r\n      return;\r\n    m_SpecialRemoveMode = false;\r\n  }\r\n  UInt32 pos = _pos + kNumHashBytes - _sizeHistory;\r\n\r\n  #ifdef __HASH_3\r\n  const Byte *pp = _buffer + _pos - _sizeHistory;\r\n  UInt32 hash2Value = ((UInt32(pp[0])) << 8) | pp[1];\r\n  UInt32 hashValue = (hash2Value << 8) | pp[2];\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  CDescendant &hash2Descendant = m_Hash2Descendants[hash2Value];\r\n  if (hash2Descendant >= kMatchStartValue2)\r\n    if(hash2Descendant.MatchPointer == pos + kMatchStartValue2)\r\n      hash2Descendant.MatchPointer = kDescendantEmptyValue2;\r\n  #else\r\n  UInt32 hashValue = UInt32(GetIndexByte(1 - _sizeHistory))  | \r\n      (UInt32(GetIndexByte(0 - _sizeHistory)) << 8);\r\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\r\n  #endif\r\n    \r\n  if(hashDescendant.IsEmpty())\r\n    return;\r\n  if(hashDescendant.IsMatch())\r\n  {\r\n    if(hashDescendant.MatchPointer == pos + kMatchStartValue)\r\n      hashDescendant.MakeEmpty();\r\n    return;\r\n  }\r\n  \r\n  UInt32 descendantIndex;\r\n  const CRemoveDataWord *currentPointer = (const CRemoveDataWord *)(_buffer + pos);\r\n  UInt32 numLoadedBits = 0;\r\n  CRemoveDataWord curWord = 0; // = 0 to disable GCC warning\r\n\r\n  CIndex *nodePointerPointer = &hashDescendant.NodePointer;\r\n\r\n  CNodePointer node = &m_Nodes[hashDescendant.NodePointer];\r\n  \r\n  while(true)\r\n  {\r\n    if(numLoadedBits == 0)\r\n    {\r\n      curWord = *currentPointer++;\r\n      numLoadedBits = kSizeRemoveDataWordInBits; \r\n    }\r\n    UInt32 numSameBits = node->NumSameBits;\r\n    if(numSameBits > 0)\r\n    {\r\n      if (numLoadedBits <= numSameBits)\r\n      {\r\n        numSameBits -= numLoadedBits;\r\n        currentPointer += (numSameBits / kSizeRemoveDataWordInBits);\r\n        numSameBits %= kSizeRemoveDataWordInBits;\r\n        curWord = *currentPointer++;\r\n        numLoadedBits = kSizeRemoveDataWordInBits; \r\n      }\r\n      curWord >>= numSameBits;\r\n      numLoadedBits -= numSameBits;\r\n    }\r\n    descendantIndex = (curWord & kSubNodesMask);\r\n    numLoadedBits -= kNumSubBits;\r\n    curWord >>= kNumSubBits;\r\n    UInt32 nextNodeIndex = node->Descendants[descendantIndex].NodePointer;\r\n    if (nextNodeIndex < kDescendantEmptyValue)\r\n    {\r\n      nodePointerPointer = &node->Descendants[descendantIndex].NodePointer;\r\n      node = &m_Nodes[nextNodeIndex];\r\n    }\r\n    else\r\n      break;\r\n  }\r\n  if (node->Descendants[descendantIndex].MatchPointer != pos + kMatchStartValue)\r\n  {\r\n    const Byte *currentBytePointer = _buffer + _pos - _sizeHistory;\r\n    const Byte *currentBytePointerLimit = currentBytePointer + _matchMaxLen;\r\n    for(;currentBytePointer < currentBytePointerLimit; currentBytePointer++)\r\n      if(*currentBytePointer != *(currentBytePointer+1))\r\n        return;\r\n    m_SpecialRemoveMode = true;\r\n    return;\r\n  }\r\n\r\n  UInt32 numNodes = 0, numMatches = 0;\r\n\r\n  UInt32 i;\r\n  for (i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    UInt32 nodeIndex = node->Descendants[i].NodePointer;\r\n    if (nodeIndex < kDescendantEmptyValue)\r\n      numNodes++;\r\n    else if (nodeIndex > kDescendantEmptyValue)\r\n      numMatches++;\r\n  }\r\n  numMatches -= 1;\r\n  if (numNodes + numMatches > 1)\r\n  {\r\n    node->Descendants[descendantIndex].MakeEmpty();\r\n    return;\r\n  }\r\n  if(numNodes == 1)\r\n  {\r\n    UInt32 i;\r\n    for (i = 0; i < kNumSubNodes; i++)\r\n      if (node->Descendants[i].IsNode())\r\n        break;\r\n    UInt32 nextNodeIndex = node->Descendants[i].NodePointer;\r\n    CNodePointer nextNode = &m_Nodes[nextNodeIndex];\r\n    nextNode->NumSameBits += node->NumSameBits + kNumSubBits;\r\n    *node = *nextNode;\r\n\r\n    nextNode->NextFreeNode = m_FreeNode;\r\n    m_FreeNode = nextNodeIndex;\r\n    return;\r\n  }\r\n  UInt32 matchPointer = 0; // = 0 to disable GCC warning\r\n  for (i = 0; i < kNumSubNodes; i++)\r\n    if (node->Descendants[i].IsMatch() && i != descendantIndex)\r\n    {\r\n      matchPointer = node->Descendants[i].MatchPointer;\r\n      break;\r\n    }\r\n  node->NextFreeNode = m_FreeNode;\r\n  m_FreeNode = *nodePointerPointer;\r\n  *nodePointerPointer = matchPointer;\r\n}\r\n#endif\r\n\r\n\r\n// Commented code is more correct, but it gives warning \r\n// on GCC: (1 << 32)\r\n// So we use kMatchStartValue twice:\r\n// kMatchStartValue = UInt32(1) << (kNumBitsInIndex - 1);\r\n// must be defined in Pat.h\r\n/*\r\nconst UInt32 kNormalizeStartPos = (UInt32(1) << (kNumBitsInIndex)) - \r\n    kMatchStartValue - kNumHashBytes - 1;\r\n*/\r\nconst UInt32 kNormalizeStartPos = kMatchStartValue - kNumHashBytes - 1;\r\n\r\nSTDMETHODIMP CPatricia::MovePos()\r\n{\r\n  #ifndef __AUTO_REMOVE\r\n  if(_pos >= _sizeHistory)\r\n    RemoveMatch();\r\n  #endif\r\n  RINOK(CLZInWindow::MovePos());\r\n  #ifdef __AUTO_REMOVE\r\n  if (m_NumUsedNodes >= m_NumNodes)\r\n    TestRemoveNodes();\r\n  #endif\r\n  if (_pos >= kNormalizeStartPos)\r\n  {\r\n    #ifdef __AUTO_REMOVE\r\n    TestRemoveNodesAndNormalize();\r\n    #else\r\n    Normalize();\r\n    #endif\r\n  }\r\n  return S_OK;\r\n}\r\n\r\n#ifndef __AUTO_REMOVE\r\n\r\nvoid CPatricia::NormalizeDescendant(CDescendant &descendant, UInt32 subValue)\r\n{\r\n  if (descendant.IsEmpty())\r\n    return;\r\n  if (descendant.IsMatch())\r\n    descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n  else\r\n  {\r\n    CNode &node = m_Nodes[descendant.NodePointer];\r\n    node.LastMatch = node.LastMatch - subValue;\r\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n       NormalizeDescendant(node.Descendants[i], subValue);\r\n  }\r\n}\r\n\r\nvoid CPatricia::Normalize()\r\n{\r\n  UInt32 subValue = _pos - _sizeHistory;\r\n  CLZInWindow::ReduceOffsets(subValue);\r\n  \r\n  #ifdef __HASH_3\r\n\r\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\r\n  {\r\n    CDescendant &descendant = m_Hash2Descendants[hash];\r\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hash << 8;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n        NormalizeDescendant(m_HashDescendants[base + i], subValue);\r\n    }\r\n    if (descendant.MatchPointer < kMatchStartValue2)\r\n      continue;\r\n    descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n  }\r\n  \r\n  #else\r\n  \r\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\r\n    NormalizeDescendant(m_HashDescendants[hash], subValue);\r\n  \r\n  #endif\r\n\r\n}\r\n\r\n#else\r\n\r\nvoid CPatricia::TestRemoveDescendant(CDescendant &descendant, UInt32 limitPos)\r\n{\r\n  CNode &node = m_Nodes[descendant.NodePointer];\r\n  UInt32 numChilds = 0;\r\n  UInt32 childIndex = 0; // = 0 to disable GCC warning\r\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    CDescendant &descendant2 = node.Descendants[i];\r\n    if (descendant2.IsEmpty())\r\n      continue;\r\n    if (descendant2.IsMatch())\r\n    {\r\n      if (descendant2.MatchPointer < limitPos)\r\n        descendant2.MakeEmpty();\r\n      else\r\n      {\r\n        numChilds++;\r\n        childIndex = i;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      TestRemoveDescendant(descendant2, limitPos);\r\n      if (!descendant2.IsEmpty())\r\n      {\r\n        numChilds++;\r\n        childIndex = i;\r\n      }\r\n    }\r\n  }\r\n  if (numChilds > 1)\r\n    return;\r\n\r\n  CIndex nodePointerTemp = descendant.NodePointer;\r\n  if (numChilds == 1)\r\n  {\r\n    const CDescendant &descendant2 = node.Descendants[childIndex];\r\n    if (descendant2.IsNode())\r\n      m_Nodes[descendant2.NodePointer].NumSameBits += node.NumSameBits + kNumSubBits;\r\n    descendant = descendant2;\r\n  }\r\n  else\r\n    descendant.MakeEmpty();\r\n  node.NextFreeNode = m_FreeNode;\r\n  m_FreeNode = nodePointerTemp;\r\n  m_NumUsedNodes--;\r\n}\r\n\r\nvoid CPatricia::RemoveNode(UInt32 index)\r\n{\r\n  CNode &node = m_Nodes[index];\r\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    CDescendant &descendant2 = node.Descendants[i];\r\n    if (descendant2.IsNode())\r\n      RemoveNode(descendant2.NodePointer);\r\n  }\r\n  node.NextFreeNode = m_FreeNode;\r\n  m_FreeNode = index;\r\n  m_NumUsedNodes--;\r\n}\r\n\r\nvoid CPatricia::TestRemoveNodes()\r\n{\r\n  UInt32 limitPos = kMatchStartValue + _pos - _sizeHistory + kNumHashBytes;\r\n  \r\n  #ifdef __HASH_3\r\n  \r\n  UInt32 limitPos2 = kMatchStartValue2 + _pos - _sizeHistory + kNumHashBytes;\r\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\r\n  {\r\n    CDescendant &descendant = m_Hash2Descendants[hash];\r\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hash << 8;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n      {\r\n        CDescendant &descendant = m_HashDescendants[base + i];\r\n        if (descendant.IsEmpty())\r\n          continue;\r\n        if (descendant.IsMatch())\r\n        {\r\n          if (descendant.MatchPointer < limitPos)\r\n            descendant.MakeEmpty();\r\n        }\r\n        else\r\n          TestRemoveDescendant(descendant, limitPos);\r\n      }\r\n    }\r\n    if (descendant.MatchPointer < kMatchStartValue2)\r\n      continue;\r\n    if (descendant.MatchPointer < limitPos2)\r\n      descendant.MatchPointer = kDescendantEmptyValue2;\r\n  }\r\n  \r\n  #else\r\n  \r\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\r\n  {\r\n    CDescendant &descendant = m_HashDescendants[hash];\r\n    if (descendant.IsEmpty())\r\n      continue;\r\n    if (descendant.IsMatch())\r\n    {\r\n      if (descendant.MatchPointer < limitPos)\r\n        descendant.MakeEmpty();\r\n    }\r\n    else\r\n      TestRemoveDescendant(descendant, limitPos);\r\n  }\r\n  \r\n  #endif\r\n}\r\n\r\nvoid CPatricia::TestRemoveAndNormalizeDescendant(CDescendant &descendant, \r\n    UInt32 limitPos, UInt32 subValue)\r\n{\r\n  if (descendant.IsEmpty())\r\n    return;\r\n  if (descendant.IsMatch())\r\n  {\r\n    if (descendant.MatchPointer < limitPos)\r\n      descendant.MakeEmpty();\r\n    else\r\n      descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n    return;\r\n  }\r\n  CNode &node = m_Nodes[descendant.NodePointer];\r\n  UInt32 numChilds = 0;\r\n  UInt32 childIndex = 0; // = 0 to disable GCC warning\r\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\r\n  {\r\n    CDescendant &descendant2 = node.Descendants[i];\r\n    TestRemoveAndNormalizeDescendant(descendant2, limitPos, subValue);\r\n    if (!descendant2.IsEmpty())\r\n    {\r\n      numChilds++;\r\n      childIndex = i;\r\n    }\r\n  }\r\n  if (numChilds > 1)\r\n  {\r\n    node.LastMatch = node.LastMatch - subValue;\r\n    return;\r\n  }\r\n\r\n  CIndex nodePointerTemp = descendant.NodePointer;\r\n  if (numChilds == 1)\r\n  {\r\n    const CDescendant &descendant2 = node.Descendants[childIndex];\r\n    if (descendant2.IsNode())\r\n      m_Nodes[descendant2.NodePointer].NumSameBits += node.NumSameBits + kNumSubBits;\r\n    descendant = descendant2;\r\n  }\r\n  else\r\n    descendant.MakeEmpty();\r\n  node.NextFreeNode = m_FreeNode;\r\n  m_FreeNode = nodePointerTemp;\r\n  m_NumUsedNodes--;\r\n}\r\n\r\nvoid CPatricia::TestRemoveNodesAndNormalize()\r\n{\r\n  UInt32 subValue = _pos - _sizeHistory;\r\n  UInt32 limitPos = kMatchStartValue + _pos - _sizeHistory + kNumHashBytes;\r\n  CLZInWindow::ReduceOffsets(subValue);\r\n\r\n  #ifdef __HASH_3\r\n  \r\n  UInt32 limitPos2 = kMatchStartValue2 + _pos - _sizeHistory + kNumHashBytes;\r\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\r\n  {\r\n    CDescendant &descendant = m_Hash2Descendants[hash];\r\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\r\n    {\r\n      UInt32 base = hash << 8;\r\n      for (UInt32 i = 0; i < 0x100; i++)\r\n        TestRemoveAndNormalizeDescendant(m_HashDescendants[base + i], limitPos, subValue);\r\n    }\r\n    if (descendant.MatchPointer < kMatchStartValue2)\r\n      continue;\r\n    if (descendant.MatchPointer < limitPos2)\r\n      descendant.MatchPointer = kDescendantEmptyValue2;\r\n    else\r\n      descendant.MatchPointer = descendant.MatchPointer - subValue;\r\n  }\r\n  \r\n  #else\r\n\r\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\r\n    TestRemoveAndNormalizeDescendant(m_HashDescendants[hash], limitPos, subValue);\r\n\r\n  #endif\r\n}\r\n\r\n#endif\r\n\r\nSTDMETHODIMP_(Byte) CPatricia::GetIndexByte(Int32 index)\r\n{\r\n  return CLZInWindow::GetIndexByte(index);\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CPatricia::GetMatchLen(Int32 index, UInt32 back, UInt32 limit)\r\n{\r\n  return CLZInWindow::GetMatchLen(index, back, limit);\r\n}\r\n\r\nSTDMETHODIMP_(UInt32) CPatricia::GetNumAvailableBytes()\r\n{\r\n  return CLZInWindow::GetNumAvailableBytes();\r\n}\r\n\r\nSTDMETHODIMP_(const Byte *) CPatricia::GetPointerToCurrentPos()\r\n{\r\n  return CLZInWindow::GetPointerToCurrentPos();\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZ/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA/LZMA.h",
    "content": "// LZMA.h\r\n\r\n#ifndef __LZMA_H\r\n#define __LZMA_H\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst UInt32 kNumRepDistances = 4;\r\n\r\nconst int kNumStates = 12;\r\n\r\nconst Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\nconst Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\nconst Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\nconst Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\nclass CState\r\n{\r\npublic:\r\n  Byte Index;\r\n  void Init() { Index = 0; }\r\n  void UpdateChar() { Index = kLiteralNextStates[Index]; }\r\n  void UpdateMatch() { Index = kMatchNextStates[Index]; }\r\n  void UpdateRep() { Index = kRepNextStates[Index]; }\r\n  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }\r\n  bool IsCharState() const { return Index < 7; }\r\n};\r\n\r\nconst int kNumPosSlotBits = 6; \r\nconst int kDicLogSizeMin = 0; \r\nconst int kDicLogSizeMax = 32; \r\nconst int kDistTableSizeMax = kDicLogSizeMax * 2; \r\n\r\nconst UInt32 kNumLenToPosStates = 4;\r\n\r\ninline UInt32 GetLenToPosState(UInt32 len)\r\n{\r\n  len -= 2;\r\n  if (len < kNumLenToPosStates)\r\n    return len;\r\n  return kNumLenToPosStates - 1;\r\n}\r\n\r\nnamespace NLength {\r\n\r\nconst int kNumPosStatesBitsMax = 4;\r\nconst UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\r\nconst int kNumPosStatesBitsEncodingMax = 4;\r\nconst UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\nconst int kNumLowBits = 3;\r\nconst int kNumMidBits = 3;\r\nconst int kNumHighBits = 8;\r\nconst UInt32 kNumLowSymbols = 1 << kNumLowBits;\r\nconst UInt32 kNumMidSymbols = 1 << kNumMidBits;\r\nconst UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\r\n\r\n}\r\n\r\nconst UInt32 kMatchMinLen = 2;\r\nconst UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\r\n\r\nconst int kNumAlignBits = 4;\r\nconst UInt32 kAlignTableSize = 1 << kNumAlignBits;\r\nconst UInt32 kAlignMask = (kAlignTableSize - 1);\r\n\r\nconst UInt32 kStartPosModelIndex = 4;\r\nconst UInt32 kEndPosModelIndex = 14;\r\nconst UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\nconst UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\r\nconst int kNumLitPosStatesBitsEncodingMax = 4;\r\nconst int kNumLitContextBitsMax = 8;\r\n\r\nconst int kNumMoveBits = 5;\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA/LZMADecoder.cpp",
    "content": "// LZMADecoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LZMADecoder.h\"\r\n#include \"../../../Common/Defs.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kLenIdFinished = -1;\r\nconst int kLenIdNeedInit = -2;\r\n\r\nvoid CDecoder::Init()\r\n{\r\n  { \r\n    for(int i = 0; i < kNumStates; i++)\r\n    {\r\n      for (UInt32 j = 0; j <= _posStateMask; j++)\r\n      {\r\n        _isMatch[i][j].Init();\r\n        _isRep0Long[i][j].Init();\r\n      }\r\n      _isRep[i].Init();\r\n      _isRepG0[i].Init();\r\n      _isRepG1[i].Init();\r\n      _isRepG2[i].Init();\r\n    }\r\n  }\r\n  { \r\n    for (UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n    _posSlotDecoder[i].Init();\r\n  }\r\n  { \r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posDecoders[i].Init();\r\n  }\r\n  _posAlignDecoder.Init();\r\n  _lenDecoder.Init(_posStateMask + 1);\r\n  _repMatchLenDecoder.Init(_posStateMask + 1);\r\n  _literalDecoder.Init();\r\n\r\n  _state.Init();\r\n  _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0;\r\n}\r\n\r\nHRESULT CDecoder::CodeSpec(UInt32 curSize)\r\n{\r\n  if (_outSizeDefined)\r\n  {\r\n    const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize();\r\n    if (curSize > rem)\r\n      curSize = (UInt32)rem;\r\n  }\r\n\r\n  if (_remainLen == kLenIdFinished)\r\n    return S_OK;\r\n  if (_remainLen == kLenIdNeedInit)\r\n  {\r\n    _rangeDecoder.Init();\r\n    Init();\r\n    _remainLen = 0;\r\n  }\r\n  if (curSize == 0)\r\n    return S_OK;\r\n\r\n  UInt32 rep0 = _reps[0];\r\n  UInt32 rep1 = _reps[1];\r\n  UInt32 rep2 = _reps[2];\r\n  UInt32 rep3 = _reps[3];\r\n  CState state = _state;\r\n  Byte previousByte;\r\n\r\n  while(_remainLen > 0 && curSize > 0)\r\n  {\r\n    previousByte = _outWindowStream.GetByte(rep0);\r\n    _outWindowStream.PutByte(previousByte);\r\n    _remainLen--;\r\n    curSize--;\r\n  }\r\n  UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n  if (nowPos64 == 0)\r\n    previousByte = 0;\r\n  else\r\n    previousByte = _outWindowStream.GetByte(0);\r\n\r\n  while(curSize > 0)\r\n  {\r\n    {\r\n      #ifdef _NO_EXCEPTIONS\r\n      if (_rangeDecoder.Stream.ErrorCode != S_OK)\r\n        return _rangeDecoder.Stream.ErrorCode;\r\n      #endif\r\n      if (_rangeDecoder.Stream.WasFinished())\r\n        return S_FALSE;\r\n      UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n      if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n      {\r\n        if(!state.IsCharState())\r\n          previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte, _outWindowStream.GetByte(rep0));\r\n        else\r\n          previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder, \r\n              (UInt32)nowPos64, previousByte);\r\n        _outWindowStream.PutByte(previousByte);\r\n        state.UpdateChar();\r\n        curSize--;\r\n        nowPos64++;\r\n      }\r\n      else             \r\n      {\r\n        UInt32 len;\r\n        if(_isRep[state.Index].Decode(&_rangeDecoder) == 1)\r\n        {\r\n          len = 0;\r\n          if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0)\r\n          {\r\n            if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0)\r\n            {\r\n              state.UpdateShortRep();\r\n              len = 1;\r\n            }\r\n          }\r\n          else\r\n          {\r\n            UInt32 distance;\r\n            if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0)\r\n              distance = rep1;\r\n            else \r\n            {\r\n              if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0)\r\n                distance = rep2;\r\n              else\r\n              {\r\n                distance = rep3;\r\n                rep3 = rep2;\r\n              }\r\n              rep2 = rep1;\r\n            }\r\n            rep1 = rep0;\r\n            rep0 = distance;\r\n          }\r\n          if (len == 0)\r\n          {\r\n            len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;\r\n            state.UpdateRep();\r\n          }\r\n        }\r\n        else\r\n        {\r\n          rep3 = rep2;\r\n          rep2 = rep1;\r\n          rep1 = rep0;\r\n          len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);\r\n          state.UpdateMatch();\r\n          UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);\r\n          if (posSlot >= kStartPosModelIndex)\r\n          {\r\n            UInt32 numDirectBits = (posSlot >> 1) - 1;\r\n            rep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\r\n            if (posSlot < kEndPosModelIndex)\r\n              rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders + \r\n                  rep0 - posSlot - 1, &_rangeDecoder, numDirectBits);\r\n            else\r\n            {\r\n              rep0 += (_rangeDecoder.DecodeDirectBits(\r\n                  numDirectBits - kNumAlignBits) << kNumAlignBits);\r\n              rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder);\r\n              if (rep0 == 0xFFFFFFFF)\r\n              {\r\n                _remainLen = kLenIdFinished;\r\n                return S_OK;\r\n              }\r\n            }\r\n          }\r\n          else\r\n            rep0 = posSlot;\r\n        }\r\n        UInt32 locLen = len;\r\n        if (len > curSize)\r\n          locLen = (UInt32)curSize;\r\n        if (!_outWindowStream.CopyBlock(rep0, locLen))\r\n          return S_FALSE;\r\n        previousByte = _outWindowStream.GetByte(0);\r\n        curSize -= locLen;\r\n        nowPos64 += locLen;\r\n        len -= locLen;\r\n        if (len != 0)\r\n        {\r\n          _remainLen = (Int32)len;\r\n          break;\r\n        }\r\n\r\n        #ifdef _NO_EXCEPTIONS\r\n        if (_outWindowStream.ErrorCode != S_OK)\r\n          return _outWindowStream.ErrorCode;\r\n        #endif\r\n      }\r\n    }\r\n  }\r\n  if (_rangeDecoder.Stream.WasFinished())\r\n    return S_FALSE;\r\n  _reps[0] = rep0;\r\n  _reps[1] = rep1;\r\n  _reps[2] = rep2;\r\n  _reps[3] = rep3;\r\n  _state = state;\r\n\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, \r\n    const UInt64 *, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  SetInStream(inStream);\r\n  _outWindowStream.SetStream(outStream);\r\n  SetOutStreamSize(outSize);\r\n  CDecoderFlusher flusher(this);\r\n\r\n  while (true)\r\n  {\r\n    UInt32 curSize = 1 << 18;\r\n    RINOK(CodeSpec(curSize));\r\n    if (_remainLen == kLenIdFinished)\r\n      break;\r\n    if (progress != NULL)\r\n    {\r\n      UInt64 inSize = _rangeDecoder.GetProcessedSize();\r\n      UInt64 nowPos64 = _outWindowStream.GetProcessedSize();\r\n      RINOK(progress->SetRatioInfo(&inSize, &nowPos64));\r\n    }\r\n    if (_outSizeDefined)\r\n      if (_outWindowStream.GetProcessedSize() >= _outSize)\r\n        break;\r\n  } \r\n  flusher.NeedFlush = false;\r\n  return Flush();\r\n}\r\n\r\n\r\n#ifdef _NO_EXCEPTIONS\r\n\r\n#define LZMA_TRY_BEGIN\r\n#define LZMA_TRY_END\r\n\r\n#else\r\n\r\n#define LZMA_TRY_BEGIN try { \r\n#define LZMA_TRY_END } \\\r\n  catch(const CInBufferException &e)  { return e.ErrorCode; } \\\r\n  catch(const CLZOutWindowException &e)  { return e.ErrorCode; } \\\r\n  catch(...) { return S_FALSE; }\r\n\r\n#endif\r\n\r\n\r\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  LZMA_TRY_END\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size)\r\n{\r\n  if (size < 5)\r\n    return E_INVALIDARG;\r\n  int lc = properties[0] % 9;\r\n  Byte remainder = (Byte)(properties[0] / 9);\r\n  int lp = remainder % 5;\r\n  int pb = remainder / 5;\r\n  UInt32 dictionarySize = 0;\r\n  for (int i = 0; i < 4; i++)\r\n    dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n  return SetDecoderPropertiesRaw(lc, lp, pb, dictionarySize);\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetDecoderPropertiesRaw(int lc, int lp, int pb, UInt32 dictionarySize)\r\n{\r\n  if (pb > NLength::kNumPosStatesBitsMax)\r\n    return E_INVALIDARG;\r\n  _posStateMask = (1 << pb) - 1;\r\n  if (!_outWindowStream.Create(dictionarySize))\r\n    return E_OUTOFMEMORY;\r\n  if (!_literalDecoder.Create(lp, lc))\r\n    return E_OUTOFMEMORY;\r\n  if (!_rangeDecoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)\r\n{\r\n  *value = _rangeDecoder.GetProcessedSize();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)\r\n{\r\n  _rangeDecoder.SetStream(inStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::ReleaseInStream()\r\n{\r\n  _rangeDecoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\r\n{\r\n  if (_outSizeDefined = (outSize != NULL))\r\n    _outSize = *outSize;\r\n  _remainLen = kLenIdNeedInit;\r\n  _outWindowStream.Init();\r\n  return S_OK;\r\n}\r\n\r\n#ifdef _ST_MODE\r\n\r\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  LZMA_TRY_BEGIN\r\n  if (processedSize)\r\n    *processedSize = 0;\r\n  const UInt64 startPos = _outWindowStream.GetProcessedSize();\r\n  _outWindowStream.SetMemStream((Byte *)data);\r\n  RINOK(CodeSpec(size));\r\n  if (processedSize)\r\n    *processedSize = (UInt32)(_outWindowStream.GetProcessedSize() - startPos);\r\n  return Flush();\r\n  LZMA_TRY_END\r\n}\r\n\r\n#endif\r\n\r\n}}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA/LZMADecoder.h",
    "content": "// LZMA/Decoder.h\r\n\r\n#ifndef __LZMA_DECODER_H\r\n#define __LZMA_DECODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/LZOutWindow.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;\r\n\r\nclass CLiteralDecoder2\r\n{\r\n  CMyBitDecoder _decoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _decoders[i].Init();\r\n  }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n      RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, Byte matchByte)\r\n  {\r\n    UInt32 symbol = 1;\r\n    RC_INIT_VAR\r\n    do\r\n    {\r\n      UInt32 matchBit = (matchByte >> 7) & 1;\r\n      matchByte <<= 1;\r\n      // UInt32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);\r\n      // symbol = (symbol << 1) | bit;\r\n      UInt32 bit;\r\n      RC_GETBIT2(kNumMoveBits, _decoders[0x100 + (matchBit << 8) + symbol].Prob, symbol, \r\n          bit = 0, bit = 1)\r\n      if (matchBit != bit)\r\n      {\r\n        while (symbol < 0x100)\r\n        {\r\n          // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\r\n          RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\r\n        }\r\n        break;\r\n      }\r\n    }\r\n    while (symbol < 0x100);\r\n    RC_FLUSH_VAR\r\n    return (Byte)symbol;\r\n  }\r\n};\r\n\r\nclass CLiteralDecoder\r\n{\r\n  CLiteralDecoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralDecoder(): _coders(0) {}\r\n  ~CLiteralDecoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte, Byte matchByte)\r\n    { return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CDecoder\r\n{\r\n  CMyBitDecoder _choice;\r\n  CMyBitDecoder _choice2;\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesMax];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder; \r\npublic:\r\n  void Init(UInt32 numPosStates)\r\n  {\r\n    _choice.Init();\r\n    _choice2.Init();\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n    {\r\n      _lowCoder[posState].Init();\r\n      _midCoder[posState].Init();\r\n    }\r\n    _highCoder.Init();\r\n  }\r\n  UInt32 Decode(NRangeCoder::CDecoder *rangeDecoder, UInt32 posState)\r\n  {\r\n    if(_choice.Decode(rangeDecoder) == 0)\r\n      return _lowCoder[posState].Decode(rangeDecoder);\r\n    if(_choice2.Decode(rangeDecoder) == 0)\r\n      return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);\r\n    return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CDecoder: \r\n  public ICompressCoder,\r\n  public ICompressSetDecoderProperties2,\r\n  #ifdef _ST_MODE\r\n  public ICompressSetInStream,\r\n  public ICompressSetOutStreamSize,\r\n  public ISequentialInStream,\r\n  #endif\r\n  public CMyUnknownImp\r\n{\r\n  CLZOutWindow _outWindowStream;\r\n  NRangeCoder::CDecoder _rangeDecoder;\r\n\r\n  CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax];\r\n  CMyBitDecoder _isRep[kNumStates];\r\n  CMyBitDecoder _isRepG0[kNumStates];\r\n  CMyBitDecoder _isRepG1[kNumStates];\r\n  CMyBitDecoder _isRepG2[kNumStates];\r\n  CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax];\r\n\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];\r\n\r\n  CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;\r\n  \r\n  NLength::CDecoder _lenDecoder;\r\n  NLength::CDecoder _repMatchLenDecoder;\r\n\r\n  CLiteralDecoder _literalDecoder;\r\n\r\n  UInt32 _posStateMask;\r\n\r\n  ///////////////////\r\n  // State\r\n  UInt32 _reps[4];\r\n  CState _state;\r\n  Int32 _remainLen; // -1 means end of stream. // -2 means need Init\r\n  UInt64 _outSize;\r\n  bool _outSizeDefined;\r\n\r\n  void Init();\r\n  HRESULT CodeSpec(UInt32 size);\r\npublic:\r\n\r\n  #ifdef _ST_MODE\r\n  MY_UNKNOWN_IMP4(\r\n      ICompressSetDecoderProperties2, \r\n      ICompressSetInStream, \r\n      ICompressSetOutStreamSize, \r\n      ISequentialInStream)\r\n  #else\r\n  MY_UNKNOWN_IMP1(\r\n      ICompressSetDecoderProperties2)\r\n  #endif\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    _outWindowStream.ReleaseStream();\r\n    ReleaseInStream();\r\n  }\r\n\r\n  class CDecoderFlusher\r\n  {\r\n    CDecoder *_decoder;\r\n  public:\r\n    bool NeedFlush;\r\n    CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}\r\n    ~CDecoderFlusher() \r\n    { \r\n      if (NeedFlush)\r\n        _decoder->Flush();\r\n      _decoder->ReleaseStreams(); \r\n    }\r\n  };\r\n\r\n  HRESULT Flush() {  return _outWindowStream.Flush(); }  \r\n\r\n  STDMETHOD(CodeReal)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n  \r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r\n  STDMETHOD(SetDecoderPropertiesRaw)(int lc, int lp, int pb, UInt32 dictionarySize);\r\n\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r\n\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\r\n  STDMETHOD(ReleaseInStream)();\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\r\n\r\n  #ifdef _ST_MODE\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n  #endif\r\n\r\n  CDecoder(): _outSizeDefined(false) {}\r\n  virtual ~CDecoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA/LZMAEncoder.cpp",
    "content": "// LZMA/Encoder.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/Defs.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"LZMAEncoder.h\"\r\n\r\n// for minimal compressing code size define these:\r\n// #define COMPRESS_MF_BT\r\n// #define COMPRESS_MF_BT4\r\n\r\n#if !defined(COMPRESS_MF_BT) && !defined(COMPRESS_MF_PAT) && !defined(COMPRESS_MF_HC)\r\n#define COMPRESS_MF_BT\r\n#define COMPRESS_MF_PAT\r\n#define COMPRESS_MF_HC\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_BT\r\n#if !defined(COMPRESS_MF_BT2) && !defined(COMPRESS_MF_BT3) && !defined(COMPRESS_MF_BT4) && !defined(COMPRESS_MF_BT4B)\r\n#define COMPRESS_MF_BT2\r\n#define COMPRESS_MF_BT3\r\n#define COMPRESS_MF_BT4\r\n#define COMPRESS_MF_BT4B\r\n#endif\r\n#ifdef COMPRESS_MF_BT2\r\n#include \"../LZ/BinTree/BinTree2.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT3\r\n#include \"../LZ/BinTree/BinTree3.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT4\r\n#include \"../LZ/BinTree/BinTree4.h\"\r\n#endif\r\n#ifdef COMPRESS_MF_BT4B\r\n#include \"../LZ/BinTree/BinTree4b.h\"\r\n#endif\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_PAT\r\n#include \"../LZ/Patricia/Pat2.h\"\r\n#include \"../LZ/Patricia/Pat2H.h\"\r\n#include \"../LZ/Patricia/Pat3H.h\"\r\n#include \"../LZ/Patricia/Pat4H.h\"\r\n#include \"../LZ/Patricia/Pat2R.h\"\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_HC\r\n#include \"../LZ/HashChain/HC3.h\"\r\n#include \"../LZ/HashChain/HC4.h\"\r\n#endif\r\n\r\n#ifdef COMPRESS_MF_MT\r\n#include \"../LZ/MT/MT.h\"\r\n#endif\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\nconst int kDefaultDictionaryLogSize = 20;\r\nconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\nenum \r\n{\r\n  kBT2,\r\n  kBT3,\r\n  kBT4,\r\n  kBT4B,\r\n  kPat2,\r\n  kPat2H,\r\n  kPat3H,\r\n  kPat4H,\r\n  kPat2R,\r\n  kHC3,\r\n  kHC4\r\n};\r\n\r\nstatic const wchar_t *kMatchFinderIDs[] = \r\n{\r\n  L\"BT2\",\r\n  L\"BT3\",\r\n  L\"BT4\",\r\n  L\"BT4B\",\r\n  L\"PAT2\",\r\n  L\"PAT2H\",\r\n  L\"PAT3H\",\r\n  L\"PAT4H\",\r\n  L\"PAT2R\",\r\n  L\"HC3\",\r\n  L\"HC4\"\r\n};\r\n\r\nByte g_FastPos[1024];\r\n\r\nclass CFastPosInit\r\n{\r\npublic:\r\n  CFastPosInit() { Init(); }\r\n  void Init()\r\n  {\r\n    const Byte kFastSlots = 20;\r\n    int c = 2;\r\n    g_FastPos[0] = 0;\r\n    g_FastPos[1] = 1;\r\n\r\n    for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n    {\r\n      UInt32 k = (1 << ((slotFast >> 1) - 1));\r\n      for (UInt32 j = 0; j < k; j++, c++)\r\n        g_FastPos[c] = slotFast;\r\n    }\r\n  }\r\n} g_FastPosInit;\r\n\r\n\r\nvoid CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    _encoders[context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nvoid CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, \r\n    Byte matchByte, Byte symbol)\r\n{\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  do \r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    UInt32 matchBit = (matchByte >> i) & 1;\r\n    _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit);\r\n    context = (context << 1) | bit;\r\n    if (matchBit != bit)\r\n    {\r\n      while(i != 0)\r\n      {\r\n        i--;\r\n        UInt32 bit = (symbol >> i) & 1;\r\n        _encoders[context].Encode(rangeEncoder, bit);\r\n        context = (context << 1) | bit;\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while(i != 0);\r\n}\r\n\r\nUInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 context = 1;\r\n  int i = 8;\r\n  if (matchMode)\r\n  {\r\n    do \r\n    {\r\n      i--;\r\n      UInt32 matchBit = (matchByte >> i) & 1;\r\n      UInt32 bit = (symbol >> i) & 1;\r\n      price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit);\r\n      context = (context << 1) | bit;\r\n      if (matchBit != bit)\r\n        break;\r\n    }\r\n    while (i != 0);\r\n  }\r\n  while(i != 0)\r\n  {\r\n    i--;\r\n    UInt32 bit = (symbol >> i) & 1;\r\n    price += _encoders[context].GetPrice(bit);\r\n    context = (context << 1) | bit;\r\n  }\r\n  return price;\r\n};\r\n\r\n\r\nnamespace NLength {\r\n\r\nvoid CEncoder::Init(UInt32 numPosStates)\r\n{\r\n  _choice.Init();\r\n  _choice2.Init();\r\n  for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n  {\r\n    _lowCoder[posState].Init();\r\n    _midCoder[posState].Init();\r\n  }\r\n  _highCoder.Init();\r\n}\r\n\r\nvoid CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n  {\r\n    _choice.Encode(rangeEncoder, 0);\r\n    _lowCoder[posState].Encode(rangeEncoder, symbol);\r\n  }\r\n  else\r\n  {\r\n    _choice.Encode(rangeEncoder, 1);\r\n    if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n    {\r\n      _choice2.Encode(rangeEncoder, 0);\r\n      _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols);\r\n    }\r\n    else\r\n    {\r\n      _choice2.Encode(rangeEncoder, 1);\r\n      _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols);\r\n    }\r\n  }\r\n}\r\n\r\nUInt32 CEncoder::GetPrice(UInt32 symbol, UInt32 posState) const\r\n{\r\n  if(symbol < kNumLowSymbols)\r\n    return _choice.GetPrice0() + _lowCoder[posState].GetPrice(symbol);\r\n  UInt32 price = _choice.GetPrice1();\r\n  if(symbol < kNumLowSymbols + kNumMidSymbols)\r\n  {\r\n    price += _choice2.GetPrice0();\r\n    price += _midCoder[posState].GetPrice(symbol - kNumLowSymbols);\r\n  }\r\n  else\r\n  {\r\n    price += _choice2.GetPrice1();\r\n    price += _highCoder.GetPrice(symbol - kNumLowSymbols - kNumMidSymbols);\r\n  }\r\n  return price;\r\n}\r\n\r\n}\r\nCEncoder::CEncoder():\r\n  _numFastBytes(kNumFastBytesDefault),\r\n  _distTableSize(kDefaultDictionaryLogSize * 2),\r\n  _posStateBits(2),\r\n  _posStateMask(4 - 1),\r\n  _numLiteralPosStateBits(0),\r\n  _numLiteralContextBits(3),\r\n  _dictionarySize(1 << kDefaultDictionaryLogSize),\r\n  _dictionarySizePrev(UInt32(-1)),\r\n  _numFastBytesPrev(UInt32(-1)),\r\n  _matchFinderIndex(kBT4),\r\n   #ifdef COMPRESS_MF_MT\r\n  _multiThread(false),\r\n   #endif\r\n  _writeEndMark(false)\r\n{\r\n  _maxMode = false;\r\n  _fastMode = false;\r\n}\r\n\r\nHRESULT CEncoder::Create()\r\n{\r\n  if (!_rangeEncoder.Create(1 << 20))\r\n    return E_OUTOFMEMORY;\r\n  if (!_matchFinder)\r\n  {\r\n    switch(_matchFinderIndex)\r\n    {\r\n      #ifdef COMPRESS_MF_BT\r\n      #ifdef COMPRESS_MF_BT2\r\n      case kBT2:\r\n        _matchFinder = new NBT2::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT3\r\n      case kBT3:\r\n        _matchFinder = new NBT3::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT4\r\n      case kBT4:\r\n        _matchFinder = new NBT4::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #ifdef COMPRESS_MF_BT4B\r\n      case kBT4B:\r\n        _matchFinder = new NBT4B::CMatchFinderBinTree;\r\n        break;\r\n      #endif\r\n      #endif\r\n      \r\n      #ifdef COMPRESS_MF_PAT\r\n      case kPat2:\r\n        _matchFinder = new NPat2::CPatricia;\r\n        break;\r\n      case kPat2H:\r\n        _matchFinder = new NPat2H::CPatricia;\r\n        break;\r\n      case kPat3H:\r\n        _matchFinder = new NPat3H::CPatricia;\r\n        break;\r\n      case kPat4H:\r\n        _matchFinder = new NPat4H::CPatricia;\r\n        break;\r\n      case kPat2R:\r\n        _matchFinder = new NPat2R::CPatricia;\r\n        break;\r\n      #endif\r\n\r\n      #ifdef COMPRESS_MF_HC\r\n      case kHC3:\r\n        _matchFinder = new NHC3::CMatchFinderHC;\r\n        break;\r\n      case kHC4:\r\n        _matchFinder = new NHC4::CMatchFinderHC;\r\n        break;\r\n      #endif\r\n    }\r\n    if (_matchFinder == 0)\r\n      return E_OUTOFMEMORY;\r\n\r\n    #ifdef COMPRESS_MF_MT\r\n    if (_multiThread && !(_fastMode && (_matchFinderIndex == kHC3 || _matchFinderIndex == kHC4)))\r\n    {\r\n      CMatchFinderMT *mfSpec = new CMatchFinderMT;\r\n      if (mfSpec == 0)\r\n        return E_OUTOFMEMORY;\r\n      CMyComPtr<IMatchFinder> mf = mfSpec;\r\n      RINOK(mfSpec->SetMatchFinder(_matchFinder));\r\n      _matchFinder.Release();\r\n      _matchFinder = mf;\r\n    }\r\n    #endif\r\n  }\r\n  \r\n  if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))\r\n    return E_OUTOFMEMORY;\r\n\r\n  if (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n    return S_OK;\r\n  RINOK(_matchFinder->Create(_dictionarySize, kNumOpts, _numFastBytes, \r\n      kMatchMaxLen * 2 + 1 - _numFastBytes));\r\n  _dictionarySizePrev = _dictionarySize;\r\n  _numFastBytesPrev = _numFastBytes;\r\n  return S_OK;\r\n}\r\n\r\nstatic bool AreStringsEqual(const wchar_t *base, const wchar_t *testString)\r\n{\r\n  while (true)\r\n  {\r\n    wchar_t c = *testString;\r\n    if (c >= 'a' && c <= 'z')\r\n      c -= 0x20;\r\n    if (*base != c)\r\n      return false;\r\n    if (c == 0)\r\n      return true;\r\n    base++;\r\n    testString++;\r\n  }\r\n}\r\n\r\n#include <stdio.h>\n\nstatic int FindMatchFinder(const wchar_t *s)\r\n{\r\n  for (int m = 0; m < (int)(sizeof(kMatchFinderIDs) / sizeof(kMatchFinderIDs[0])); m++)\r\n    if (AreStringsEqual(kMatchFinderIDs[m], s))\r\n      return m;\r\n  return -1;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, \r\n    const PROPVARIANT *properties, UInt32 numProperties)\r\n{\r\n  for (UInt32 i = 0; i < numProperties; i++)\r\n  {\r\n    const PROPVARIANT &prop = properties[i];\r\n    switch(propIDs[i])\r\n    {\r\n      case NCoderPropID::kNumFastBytes:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 numFastBytes = prop.ulVal;\r\n        if(numFastBytes < 5 || numFastBytes > kMatchMaxLen)\r\n          return E_INVALIDARG;\r\n        _numFastBytes = numFastBytes;\r\n        break;\r\n      }\r\n      case NCoderPropID::kAlgorithm:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 maximize = prop.ulVal;\r\n        _fastMode = (maximize == 0); \r\n        _maxMode = (maximize >= 2);\r\n        break;\r\n      }\r\n      case NCoderPropID::kMatchFinder:\r\n      {\r\n        if (prop.vt != VT_BSTR)\r\n          return E_INVALIDARG;\r\n        int matchFinderIndexPrev = _matchFinderIndex;\r\n        int m = FindMatchFinder(prop.bstrVal);\n        if (m < 0)\r\n          return E_INVALIDARG;\r\n        _matchFinderIndex = m;\r\n        if (_matchFinder && matchFinderIndexPrev != _matchFinderIndex)\r\n        {\r\n          _dictionarySizePrev = UInt32(-1);\r\n          _matchFinder.Release();\r\n        }\r\n        break;\r\n      }\r\n      #ifdef COMPRESS_MF_MT\r\n      case NCoderPropID::kMultiThread:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        bool newMultiThread = (prop.boolVal == VARIANT_TRUE);\r\n        if (newMultiThread != _multiThread)\r\n        {\r\n          _dictionarySizePrev = UInt32(-1);\r\n          _matchFinder.Release();\r\n        }\r\n        _multiThread = newMultiThread;\r\n        break;\r\n      }\r\n      #endif\r\n      case NCoderPropID::kDictionarySize:\r\n      {\r\n        const int kDicLogSizeMaxCompress = 28;\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 dictionarySize = prop.ulVal;\r\n        if (dictionarySize < UInt32(1 << kDicLogSizeMin) ||\r\n            dictionarySize > UInt32(1 << kDicLogSizeMaxCompress))\r\n          return E_INVALIDARG;\r\n        _dictionarySize = dictionarySize;\r\n        UInt32 dicLogSize;\r\n        for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n          if (dictionarySize <= (UInt32(1) << dicLogSize))\r\n            break;\r\n        _distTableSize = dicLogSize * 2;\r\n        break;\r\n      }\r\n      case NCoderPropID::kPosStateBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _posStateBits = value;\r\n        _posStateMask = (1 << _posStateBits) - 1;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitPosBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitPosStatesBitsEncodingMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralPosStateBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kLitContextBits:\r\n      {\r\n        if (prop.vt != VT_UI4)\r\n          return E_INVALIDARG;\r\n        UInt32 value = prop.ulVal;\r\n        if (value > (UInt32)kNumLitContextBitsMax)\r\n          return E_INVALIDARG;\r\n        _numLiteralContextBits = value;\r\n        break;\r\n      }\r\n      case NCoderPropID::kEndMarker:\r\n      {\r\n        if (prop.vt != VT_BOOL)\r\n          return E_INVALIDARG;\r\n        SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE);\r\n        break;\r\n      }\r\n      default:\r\n        return E_INVALIDARG;\r\n    }\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\r\n{ \r\n  const UInt32 kPropSize = 5;\r\n  Byte properties[kPropSize];\r\n  properties[0] = (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits;\r\n  for (int i = 0; i < 4; i++)\r\n    properties[1 + i] = Byte(_dictionarySize >> (8 * i));\r\n  return WriteStream(outStream, properties, kPropSize, NULL);\r\n}\r\n\r\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\r\n{\r\n  _rangeEncoder.SetStream(outStream);\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::ReleaseOutStream()\r\n{\r\n  _rangeEncoder.ReleaseStream();\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Init()\r\n{\r\n  CBaseState::Init();\r\n\r\n  // RINOK(_matchFinder->Init(inStream));\r\n  _rangeEncoder.Init();\r\n\r\n  for(int i = 0; i < kNumStates; i++)\r\n  {\r\n    for (UInt32 j = 0; j <= _posStateMask; j++)\r\n    {\r\n      _isMatch[i][j].Init();\r\n      _isRep0Long[i][j].Init();\r\n    }\r\n    _isRep[i].Init();\r\n    _isRepG0[i].Init();\r\n    _isRepG1[i].Init();\r\n    _isRepG2[i].Init();\r\n  }\r\n\r\n  _literalEncoder.Init();\r\n\r\n  // _repMatchLenEncoder.Init();\r\n  \r\n  {\r\n    for(UInt32 i = 0; i < kNumLenToPosStates; i++)\r\n      _posSlotEncoder[i].Init();\r\n  }\r\n  {\r\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\r\n      _posEncoders[i].Init();\r\n  }\r\n\r\n  _lenEncoder.Init(1 << _posStateBits);\r\n  _repMatchLenEncoder.Init(1 << _posStateBits);\r\n\r\n  _posAlignEncoder.Init();\r\n\r\n  _longestMatchWasFound = false;\r\n  _optimumEndIndex = 0;\r\n  _optimumCurrentIndex = 0;\r\n  _additionalOffset = 0;\r\n\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::MovePos(UInt32 num)\r\n{\r\n  for (;num != 0; num--)\r\n  {\r\n    _matchFinder->DummyLongestMatch();\r\n    RINOK(_matchFinder->MovePos());\r\n    _additionalOffset++;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nUInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)\r\n{\r\n  _optimumEndIndex = cur;\r\n  UInt32 posMem = _optimum[cur].PosPrev;\r\n  UInt32 backMem = _optimum[cur].BackPrev;\r\n  do\r\n  {\r\n    if (_optimum[cur].Prev1IsChar)\r\n    {\r\n      _optimum[posMem].MakeAsChar();\r\n      _optimum[posMem].PosPrev = posMem - 1;\r\n      if (_optimum[cur].Prev2)\r\n      {\r\n        _optimum[posMem - 1].Prev1IsChar = false;\r\n        _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n        _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n      }\r\n    }\r\n    UInt32 posPrev = posMem;\r\n    UInt32 backCur = backMem;\r\n\r\n    backMem = _optimum[posPrev].BackPrev;\r\n    posMem = _optimum[posPrev].PosPrev;\r\n\r\n    _optimum[posPrev].BackPrev = backCur;\r\n    _optimum[posPrev].PosPrev = cur;\r\n    cur = posPrev;\r\n  }\r\n  while(cur != 0);\r\n  backRes = _optimum[0].BackPrev;\r\n  _optimumCurrentIndex  = _optimum[0].PosPrev;\r\n  return _optimumCurrentIndex; \r\n}\r\n\r\n/*\r\ninline UInt32 GetMatchLen(const Byte *data, UInt32 back, UInt32 limit)\r\n{  \r\n  back++;\r\n  for(UInt32 i = 0; i < limit && data[i] == data[i - back]; i++);\r\n  return i;\r\n}\r\n*/\r\n\r\n\r\n/*\r\nOut:\r\n  (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal\r\n*/\r\n\r\nHRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\r\n{\r\n  if(_optimumEndIndex != _optimumCurrentIndex)\r\n  {\r\n    const COptimal &optimum = _optimum[_optimumCurrentIndex];\r\n    lenRes = optimum.PosPrev - _optimumCurrentIndex;\r\n    backRes = optimum.BackPrev;\r\n    _optimumCurrentIndex = optimum.PosPrev;\r\n    return S_OK;\r\n  }\r\n  _optimumCurrentIndex = 0;\r\n  _optimumEndIndex = 0; // test it;\r\n  \r\n  UInt32 lenMain;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    RINOK(ReadMatchDistances(lenMain));\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    _longestMatchWasFound = false;\r\n  }\r\n\r\n\r\n  UInt32 reps[kNumRepDistances];\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  UInt32 i;\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    reps[i] = _repDistances[i];\r\n    repLens[i] = _matchFinder->GetMatchLen(0 - 1, reps[i], kMatchMaxLen);\r\n    if (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    return MovePos(lenRes - 1);\r\n  }\r\n\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = _matchDistances[_numFastBytes] + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 1);\r\n  }\r\n  Byte currentByte = _matchFinder->GetIndexByte(0 - 1);\r\n\r\n  _optimum[0].State = _state;\r\n\r\n  Byte matchByte;\r\n  \r\n  matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\r\n  UInt32 posState = (position & _posStateMask);\r\n\r\n  _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() + \r\n      _literalEncoder.GetPrice(position, _previousByte, !_state.IsCharState(), matchByte, currentByte);\r\n  _optimum[1].MakeAsChar();\r\n\r\n  _optimum[1].PosPrev = 0;\r\n\r\n  for (i = 0; i < kNumRepDistances; i++)\r\n    _optimum[0].Backs[i] = reps[i];\r\n\r\n  UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1();\r\n  UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n  if(matchByte == currentByte)\r\n  {\r\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n    if(shortRepPrice < _optimum[1].Price)\r\n    {\r\n      _optimum[1].Price = shortRepPrice;\r\n      _optimum[1].MakeAsShortRep();\r\n    }\r\n  }\r\n  if(lenMain < 2)\r\n  {\r\n    backRes = _optimum[1].BackPrev;\r\n    lenRes = 1;\r\n    return S_OK;\r\n  }\r\n\r\n  \r\n  UInt32 normalMatchPrice = matchPrice + \r\n      _isRep[_state.Index].GetPrice0();\r\n\r\n  if (lenMain <= repLens[repMaxIndex])\r\n    lenMain = 0;\r\n\r\n  UInt32 len;\r\n  for(len = 2; len <= lenMain; len++)\r\n  {\r\n    _optimum[len].PosPrev = 0;\r\n    _optimum[len].BackPrev = _matchDistances[len] + kNumRepDistances;\r\n    _optimum[len].Price = normalMatchPrice + \r\n        GetPosLenPrice(_matchDistances[len], len, posState);\r\n    _optimum[len].Prev1IsChar = false;\r\n  }\r\n\r\n  if (lenMain < repLens[repMaxIndex])\r\n    lenMain = repLens[repMaxIndex];\r\n\r\n  for (; len <= lenMain; len++)\r\n    _optimum[len].Price = kIfinityPrice;\r\n\r\n  for(i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    UInt32 repLen = repLens[i];\r\n    for(UInt32 lenTest = 2; lenTest <= repLen; lenTest++)\r\n    {\r\n      UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\r\n      COptimal &optimum = _optimum[lenTest];\r\n      if (curAndLenPrice < optimum.Price) \r\n      {\r\n        optimum.Price = curAndLenPrice;\r\n        optimum.PosPrev = 0;\r\n        optimum.BackPrev = i;\r\n        optimum.Prev1IsChar = false;\r\n      }\r\n    }\r\n  }\r\n\r\n  UInt32 cur = 0;\r\n  UInt32 lenEnd = lenMain;\r\n\r\n  while(true)\r\n  {\r\n    cur++;\r\n    if(cur == lenEnd)\r\n    {\r\n      lenRes = Backward(backRes, cur);\r\n      return S_OK;\r\n    }\r\n    position++;\r\n    COptimal &curOptimum = _optimum[cur];\r\n    UInt32 posPrev = curOptimum.PosPrev;\r\n    CState state;\r\n    if (curOptimum.Prev1IsChar)\r\n    {\r\n      posPrev--;\r\n      if (curOptimum.Prev2)\r\n      {\r\n        state = _optimum[curOptimum.PosPrev2].State;\r\n        if (curOptimum.BackPrev2 < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      else\r\n        state = _optimum[posPrev].State;\r\n      state.UpdateChar();\r\n    }\r\n    else\r\n      state = _optimum[posPrev].State;\r\n    if (posPrev == cur - 1)\r\n    {\r\n      if (curOptimum.IsShortRep())\r\n        state.UpdateShortRep();\r\n      else\r\n        state.UpdateChar();\r\n      /*\r\n      if (curOptimum.Prev1IsChar)\r\n        for(int i = 0; i < kNumRepDistances; i++)\r\n          reps[i] = _optimum[posPrev].Backs[i];\r\n      */\r\n    }\r\n    else\r\n    {\r\n      UInt32 pos;\r\n      if (curOptimum.Prev1IsChar && curOptimum.Prev2)\r\n      {\r\n        posPrev = curOptimum.PosPrev2;\r\n        pos = curOptimum.BackPrev2;\r\n        state.UpdateRep();\r\n      }\r\n      else\r\n      {\r\n        pos = curOptimum.BackPrev;\r\n        if (pos < kNumRepDistances)\r\n          state.UpdateRep();\r\n        else\r\n          state.UpdateMatch();\r\n      }\r\n      const COptimal &prevOptimum = _optimum[posPrev];\r\n      if (pos < kNumRepDistances)\r\n      {\r\n        reps[0] = prevOptimum.Backs[pos];\r\n    \t\tUInt32 i;\r\n        for(i = 1; i <= pos; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n        for(; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i];\r\n      }\r\n      else\r\n      {\r\n        reps[0] = (pos - kNumRepDistances);\r\n        for(UInt32 i = 1; i < kNumRepDistances; i++)\r\n          reps[i] = prevOptimum.Backs[i - 1];\r\n      }\r\n    }\r\n    curOptimum.State = state;\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n      curOptimum.Backs[i] = reps[i];\r\n    UInt32 newLen;\r\n    RINOK(ReadMatchDistances(newLen));\r\n    if(newLen >= _numFastBytes)\r\n    {\r\n      _longestMatchLength = newLen;\r\n      _longestMatchWasFound = true;\r\n      lenRes = Backward(backRes, cur);\r\n      return S_OK;\r\n    }\r\n    UInt32 curPrice = curOptimum.Price; \r\n    // Byte currentByte  = _matchFinder->GetIndexByte(0 - 1);\r\n    // Byte matchByte = _matchFinder->GetIndexByte(0 - reps[0] - 1 - 1);\r\n    const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;\r\n    Byte currentByte = *data;\r\n    Byte matchByte = data[(size_t)0 - reps[0] - 1];\r\n\r\n    UInt32 posState = (position & _posStateMask);\r\n\r\n    UInt32 curAnd1Price = curPrice +\r\n        _isMatch[state.Index][posState].GetPrice0() +\r\n        _literalEncoder.GetPrice(position, data[(size_t)0 - 1], !state.IsCharState(), matchByte, currentByte);\r\n\r\n    COptimal &nextOptimum = _optimum[cur + 1];\r\n\r\n    bool nextIsChar = false;\r\n    if (curAnd1Price < nextOptimum.Price) \r\n    {\r\n      nextOptimum.Price = curAnd1Price;\r\n      nextOptimum.PosPrev = cur;\r\n      nextOptimum.MakeAsChar();\r\n      nextIsChar = true;\r\n    }\r\n\r\n    UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();\r\n    UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n    \r\n    if(matchByte == currentByte &&\r\n        !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n    {\r\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n      if(shortRepPrice <= nextOptimum.Price)\r\n      {\r\n        nextOptimum.Price = shortRepPrice;\r\n        nextOptimum.PosPrev = cur;\r\n        nextOptimum.MakeAsShortRep();\r\n        // nextIsChar = false;\r\n      }\r\n    }\r\n    /*\r\n    if(newLen == 2 && _matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n      continue;\r\n    */\r\n\r\n    UInt32 numAvailableBytesFull = _matchFinder->GetNumAvailableBytes() + 1;\r\n    numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n    UInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n    if (numAvailableBytes < 2)\r\n      continue;\r\n    if (numAvailableBytes > _numFastBytes)\r\n      numAvailableBytes = _numFastBytes;\r\n    if (numAvailableBytes >= 3 && !nextIsChar)\r\n    {\r\n      // try Literal + rep0\r\n      UInt32 backOffset = reps[0] + 1;\r\n      UInt32 temp;\r\n      for (temp = 1; temp < numAvailableBytes; temp++)\r\n        if (data[temp] != data[(size_t)temp - backOffset])\r\n          break;\r\n      UInt32 lenTest2 = temp - 1;\r\n      if (lenTest2 >= 2)\r\n      {\r\n        CState state2 = state;\r\n        state2.UpdateChar();\r\n        UInt32 posStateNext = (position + 1) & _posStateMask;\r\n        UInt32 nextRepMatchPrice = curAnd1Price + \r\n            _isMatch[state2.Index][posStateNext].GetPrice1() +\r\n            _isRep[state2.Index].GetPrice1();\r\n        // for (; lenTest2 >= 2; lenTest2--)\r\n        {\r\n          while(lenEnd < cur + 1 + lenTest2)\r\n            _optimum[++lenEnd].Price = kIfinityPrice;\r\n          UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n              0, lenTest2, state2, posStateNext);\r\n          COptimal &optimum = _optimum[cur + 1 + lenTest2];\r\n          if (curAndLenPrice < optimum.Price) \r\n          {\r\n            optimum.Price = curAndLenPrice;\r\n            optimum.PosPrev = cur + 1;\r\n            optimum.BackPrev = 0;\r\n            optimum.Prev1IsChar = true;\r\n            optimum.Prev2 = false;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)\r\n    {\r\n      // UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n      UInt32 backOffset = reps[repIndex] + 1;\r\n      if (data[0] != data[(size_t)0 - backOffset] ||\r\n          data[1] != data[(size_t)1 - backOffset])\r\n        continue;\r\n      UInt32 lenTest;\r\n      for (lenTest = 2; lenTest < numAvailableBytes; lenTest++)\r\n        if (data[lenTest] != data[(size_t)lenTest - backOffset])\r\n          break;\r\n      UInt32 lenTestTemp = lenTest;\r\n      do\r\n      {\r\n        while(lenEnd < cur + lenTest)\r\n          _optimum[++lenEnd].Price = kIfinityPrice;\r\n        UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = repIndex;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n      }\r\n      while(--lenTest >= 2);\r\n      lenTest = lenTestTemp;\r\n\r\n        if (_maxMode)\r\n        {\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit; lenTest2++)\r\n            if (data[lenTest2] != data[(size_t)lenTest2 - backOffset])\r\n              break;\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateRep();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = \r\n                repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1], \r\n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice1();\r\n            UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = lenTest + 1 + lenTest2;\r\n              while(lenEnd < cur + offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[cur + offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = repIndex;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    \r\n    //    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n    if (newLen > numAvailableBytes)\r\n      newLen = numAvailableBytes;\r\n    if (newLen >= 2)\r\n    {\r\n      if (newLen == 2 && _matchDistances[2] >= 0x80)\r\n        continue;\r\n      UInt32 normalMatchPrice = matchPrice + \r\n        _isRep[state.Index].GetPrice0();\r\n      while(lenEnd < cur + newLen)\r\n        _optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n      for(UInt32 lenTest = newLen; lenTest >= 2; lenTest--)\r\n      {\r\n        UInt32 curBack = _matchDistances[lenTest];\r\n        UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n        COptimal &optimum = _optimum[cur + lenTest];\r\n        if (curAndLenPrice < optimum.Price) \r\n        {\r\n          optimum.Price = curAndLenPrice;\r\n          optimum.PosPrev = cur;\r\n          optimum.BackPrev = curBack + kNumRepDistances;\r\n          optimum.Prev1IsChar = false;\r\n        }\r\n\r\n        if (_maxMode && (lenTest == newLen || curBack != _matchDistances[lenTest + 1]))\r\n        {\r\n          // Try Match + Literal + Rep0\r\n          UInt32 backOffset = curBack + 1;\r\n          UInt32 lenTest2 = lenTest + 1;\r\n          UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n          for (; lenTest2 < limit; lenTest2++)\r\n            if (data[lenTest2] != data[(size_t)lenTest2 - backOffset])\r\n              break;\r\n          lenTest2 -= lenTest + 1;\r\n          if (lenTest2 >= 2)\r\n          {\r\n            CState state2 = state;\r\n            state2.UpdateMatch();\r\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n            UInt32 curAndLenCharPrice = curAndLenPrice + \r\n                _isMatch[state2.Index][posStateNext].GetPrice0() +\r\n                _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1], \r\n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\r\n            state2.UpdateChar();\r\n            posStateNext = (position + lenTest + 1) & _posStateMask;\r\n            UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice1();\r\n            UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n            \r\n            // for(; lenTest2 >= 2; lenTest2--)\r\n            {\r\n              UInt32 offset = lenTest + 1 + lenTest2;\r\n              while(lenEnd < cur + offset)\r\n                _optimum[++lenEnd].Price = kIfinityPrice;\r\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n                  0, lenTest2, state2, posStateNext);\r\n              COptimal &optimum = _optimum[cur + offset];\r\n              if (curAndLenPrice < optimum.Price) \r\n              {\r\n                optimum.Price = curAndLenPrice;\r\n                optimum.PosPrev = cur + lenTest + 1;\r\n                optimum.BackPrev = 0;\r\n                optimum.Prev1IsChar = true;\r\n                optimum.Prev2 = true;\r\n                optimum.PosPrev2 = cur;\r\n                optimum.BackPrev2 = curBack + kNumRepDistances;\r\n              }\r\n            }\r\n          }\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nstatic inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n{\r\n  const int kDif = 7;\r\n  return (smallDist < (UInt32(1) << (32-kDif)) && bigDist >= (smallDist << kDif));\r\n}\r\n\r\n\r\nHRESULT CEncoder::ReadMatchDistances(UInt32 &lenRes)\r\n{\r\n  lenRes = _matchFinder->GetLongestMatch(_matchDistances);\r\n  if (lenRes == _numFastBytes)\r\n    lenRes += _matchFinder->GetMatchLen(lenRes, _matchDistances[lenRes], \r\n        kMatchMaxLen - lenRes);\r\n  _additionalOffset++;\r\n  return _matchFinder->MovePos();\r\n}\r\n\r\nHRESULT CEncoder::GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\r\n{\r\n  UInt32 lenMain;\r\n  if (!_longestMatchWasFound)\r\n  {\r\n    RINOK(ReadMatchDistances(lenMain));\r\n  }\r\n  else\r\n  {\r\n    lenMain = _longestMatchLength;\r\n    _longestMatchWasFound = false;\r\n  }\r\n  UInt32 repLens[kNumRepDistances];\r\n  UInt32 repMaxIndex = 0;\r\n  for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n  {\r\n    repLens[i] = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);\r\n    if (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n      repMaxIndex = i;\r\n  }\r\n  if(repLens[repMaxIndex] >= _numFastBytes)\r\n  {\r\n    backRes = repMaxIndex;\r\n    lenRes = repLens[repMaxIndex];\r\n    return MovePos(lenRes - 1);\r\n  }\r\n  if(lenMain >= _numFastBytes)\r\n  {\r\n    backRes = _matchDistances[_numFastBytes] + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 1);\r\n  }\r\n  while (lenMain > 2)\r\n  {\r\n    if (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\r\n      break;\r\n    lenMain--;\r\n  }\r\n  if (lenMain == 2 && _matchDistances[2] >= 0x80)\r\n    lenMain = 1;\r\n\r\n  UInt32 backMain = _matchDistances[lenMain];\r\n  if (repLens[repMaxIndex] >= 2)\r\n  {\r\n    if (repLens[repMaxIndex] + 1 >= lenMain || \r\n        repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1<<12)))\r\n    {\r\n      backRes = repMaxIndex;\r\n      lenRes = repLens[repMaxIndex];\r\n      return MovePos(lenRes - 1);\r\n    }\r\n  }\r\n  \r\n\r\n  if (lenMain >= 2)\r\n  {\r\n    RINOK(ReadMatchDistances(_longestMatchLength));\r\n    if (_longestMatchLength >= 2 &&\r\n      (\r\n        (_longestMatchLength >= lenMain && _matchDistances[lenMain] < backMain) || \r\n        _longestMatchLength == lenMain + 1 && \r\n          !ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\r\n        _longestMatchLength > lenMain + 1 ||\r\n        _longestMatchLength + 1 >= lenMain && lenMain >= 3 &&\r\n          ChangePair(_matchDistances[lenMain - 1], backMain)\r\n      )\r\n      )\r\n    {\r\n      _longestMatchWasFound = true;\r\n      backRes = UInt32(-1);\r\n      lenRes = 1;\r\n      return S_OK;\r\n    }\r\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\r\n    {\r\n      UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);\r\n      if (repLen >= 2 && repLen + 1 >= lenMain)\r\n      {\r\n        _longestMatchWasFound = true;\r\n        backRes = UInt32(-1);\r\n        lenRes = 1;\r\n        return S_OK;\r\n      }\r\n    }\r\n    backRes = backMain + kNumRepDistances; \r\n    lenRes = lenMain;\r\n    return MovePos(lenMain - 2);\r\n  }\r\n  backRes = UInt32(-1);\r\n  lenRes = 1;\r\n  return S_OK;\r\n}\r\n\r\nSTDMETHODIMP CEncoder::InitMatchFinder(IMatchFinder *matchFinder)\r\n{\r\n  _matchFinder = matchFinder;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::Flush(UInt32 nowPos)\r\n{\r\n  ReleaseMFStream();\r\n  WriteEndMarker(nowPos & _posStateMask);\r\n  _rangeEncoder.FlushData();\r\n  return _rangeEncoder.FlushStream();\r\n}\r\n\r\nvoid CEncoder::WriteEndMarker(UInt32 posState)\r\n{\r\n  // This function for writing End Mark for stream version of LZMA. \r\n  // In current version this feature is not used.\r\n  if (!_writeEndMark)\r\n    return;\r\n\r\n  _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n  _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n  _state.UpdateMatch();\r\n  UInt32 len = kMatchMinLen; // kMatchMaxLen;\r\n  _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\r\n  UInt32 posSlot = (1 << kNumPosSlotBits)  - 1;\r\n  UInt32 lenToPosState = GetLenToPosState(len);\r\n  _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n  UInt32 footerBits = 30;\r\n  UInt32 posReduced = (UInt32(1) << footerBits) - 1;\r\n  _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n  _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n}\r\n\r\nHRESULT CEncoder::CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress)\r\n{\r\n  _needReleaseMFStream = false;\r\n  CCoderReleaser coderReleaser(this);\r\n  RINOK(SetStreams(inStream, outStream, inSize, outSize));\r\n  while(true)\r\n  {\r\n    UInt64 processedInSize;\r\n    UInt64 processedOutSize;\r\n    Int32 finished;\r\n    RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished));\r\n    if (finished != 0)\r\n      return S_OK;\r\n    if (progress != 0)\r\n    {\r\n      RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize));\r\n    }\r\n  }\r\n}\r\n\r\nHRESULT CEncoder::SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  _inStream = inStream;\r\n  _finished = false;\r\n  RINOK(Create());\r\n  RINOK(SetOutStream(outStream));\r\n  RINOK(Init());\r\n  \r\n  // CCoderReleaser releaser(this);\r\n\r\n  /*\r\n  if (_matchFinder->GetNumAvailableBytes() == 0)\r\n    return Flush();\r\n  */\r\n\r\n  if (!_fastMode)\r\n  {\r\n    FillPosSlotPrices();\r\n    FillDistancesPrices();\r\n    FillAlignPrices();\r\n  }\r\n\r\n  _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _lenEncoder.UpdateTables(1 << _posStateBits);\r\n  _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen);\r\n  _repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\r\n  lastPosSlotFillingPos = 0;\r\n  nowPos64 = 0;\r\n  return S_OK;\r\n}\r\n\r\nHRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)\r\n{\r\n  if (_inStream != 0)\r\n  {\r\n    RINOK(_matchFinder->Init(_inStream));\r\n    _needReleaseMFStream = true;\r\n    _inStream = 0;\r\n  }\r\n\r\n\r\n  *finished = 1;\r\n  if (_finished)\r\n    return S_OK;\r\n  _finished = true;\r\n\r\n\r\n  UInt64 progressPosValuePrev = nowPos64;\r\n  if (nowPos64 == 0)\r\n  {\r\n    if (_matchFinder->GetNumAvailableBytes() == 0)\r\n      return Flush(UInt32(nowPos64));\r\n    UInt32 len; // it's not used\r\n    RINOK(ReadMatchDistances(len));\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n    _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n    _state.UpdateChar();\r\n    Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\r\n    _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte);\r\n    _previousByte = curByte;\r\n    _additionalOffset--;\r\n    nowPos64++;\r\n  }\r\n  if (_matchFinder->GetNumAvailableBytes() == 0)\r\n    return Flush(UInt32(nowPos64));\r\n  while(true)\r\n  {\r\n    #ifdef _NO_EXCEPTIONS\r\n    if (_rangeEncoder.Stream.ErrorCode != S_OK)\r\n      return _rangeEncoder.Stream.ErrorCode;\r\n    #endif\r\n    UInt32 pos;\r\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\r\n\r\n    UInt32 len;\r\n    HRESULT result;\r\n    if (_fastMode)\r\n      result = GetOptimumFast(UInt32(nowPos64), pos, len);\r\n    else\r\n      result = GetOptimum(UInt32(nowPos64), pos, len);\r\n    RINOK(result);\r\n\r\n    if(len == 1 && pos == 0xFFFFFFFF)\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n      Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\r\n      CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte);\r\n      if(!_state.IsCharState())\r\n      {\r\n        Byte matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - _additionalOffset);\r\n        subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);\r\n      }\r\n      else\r\n        subCoder->Encode(&_rangeEncoder, curByte);\r\n      _state.UpdateChar();\r\n      _previousByte = curByte;\r\n    }\r\n    else\r\n    {\r\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n      if(pos < kNumRepDistances)\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 1);\r\n        if(pos == 0)\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 0);\r\n          if(len == 1)\r\n            _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 0);\r\n          else\r\n            _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 1);\r\n        }\r\n        else\r\n        {\r\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 1);\r\n          if (pos == 1)\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 0);\r\n          else\r\n          {\r\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 1);\r\n            _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);\r\n          }\r\n        }\r\n        if (len == 1)\r\n          _state.UpdateShortRep();\r\n        else\r\n        {\r\n          _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\r\n          _state.UpdateRep();\r\n        }\r\n\r\n\r\n        UInt32 distance = _repDistances[pos];\r\n        if (pos != 0)\r\n        {\r\n          for(UInt32 i = pos; i >= 1; i--)\r\n            _repDistances[i] = _repDistances[i - 1];\r\n          _repDistances[0] = distance;\r\n        }\r\n      }\r\n      else\r\n      {\r\n        _isRep[_state.Index].Encode(&_rangeEncoder, 0);\r\n        _state.UpdateMatch();\r\n        _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\r\n        pos -= kNumRepDistances;\r\n        UInt32 posSlot = GetPosSlot(pos);\r\n        UInt32 lenToPosState = GetLenToPosState(len);\r\n        _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\r\n        \r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          UInt32 footerBits = ((posSlot >> 1) - 1);\r\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n          UInt32 posReduced = pos - base;\r\n\r\n          if (posSlot < kEndPosModelIndex)\r\n            NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1, \r\n                &_rangeEncoder, footerBits, posReduced);\r\n          else\r\n          {\r\n            _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\r\n            _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\r\n            if (!_fastMode)\r\n              if (--_alignPriceCount == 0)\r\n                FillAlignPrices();\r\n          }\r\n        }\r\n        UInt32 distance = pos;\r\n        for(UInt32 i = kNumRepDistances - 1; i >= 1; i--)\r\n          _repDistances[i] = _repDistances[i - 1];\r\n        _repDistances[0] = distance;\r\n      }\r\n      _previousByte = _matchFinder->GetIndexByte(len - 1 - _additionalOffset);\r\n    }\r\n    _additionalOffset -= len;\r\n    nowPos64 += len;\r\n    if (!_fastMode)\r\n      if (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\r\n      {\r\n        FillPosSlotPrices();\r\n        FillDistancesPrices();\r\n        lastPosSlotFillingPos = nowPos64;\r\n      }\r\n    if (_additionalOffset == 0)\r\n    {\r\n      *inSize = nowPos64;\r\n      *outSize = _rangeEncoder.GetProcessedSize();\r\n      if (_matchFinder->GetNumAvailableBytes() == 0)\r\n        return Flush(UInt32(nowPos64));\r\n      if (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n      {\r\n        _finished = false;\r\n        *finished = 0;\r\n        return S_OK;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,\r\n    ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\r\n    ICompressProgressInfo *progress)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try \r\n  { \r\n  #endif\r\n    return CodeReal(inStream, outStream, inSize, outSize, progress); \r\n  #ifndef _NO_EXCEPTIONS\r\n  }\r\n  catch(const COutBufferException &e) { return e.ErrorCode; }\r\n  catch(...) { return E_FAIL; }\r\n  #endif\r\n}\r\n  \r\nvoid CEncoder::FillPosSlotPrices()\r\n{\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n\t  UInt32 posSlot;\r\n    for (posSlot = 0; posSlot < kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\r\n      _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\r\n    for (; posSlot < _distTableSize; posSlot++)\r\n      _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) + \r\n      ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);\r\n  }\r\n}\r\n\r\nvoid CEncoder::FillDistancesPrices()\r\n{\r\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\r\n  {\r\n\t  UInt32 i;\r\n    for (i = 0; i < kStartPosModelIndex; i++)\r\n      _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][i];\r\n    for (; i < kNumFullDistances; i++)\r\n    { \r\n      UInt32 posSlot = GetPosSlot(i);\r\n      UInt32 footerBits = ((posSlot >> 1) - 1);\r\n      UInt32 base = ((2 | (posSlot & 1)) << footerBits);\r\n\r\n      _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][posSlot] +\r\n          NRangeCoder::ReverseBitTreeGetPrice(_posEncoders + \r\n              base - posSlot - 1, footerBits, i - base);\r\n            \r\n    }\r\n  }\r\n}\r\n\r\nvoid CEncoder::FillAlignPrices()\r\n{\r\n  for (UInt32 i = 0; i < kAlignTableSize; i++)\r\n    _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n  _alignPriceCount = kAlignTableSize;\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA/LZMAEncoder.h",
    "content": "// LZMA/Encoder.h\r\n\r\n#ifndef __LZMA_ENCODER_H\r\n#define __LZMA_ENCODER_H\r\n\r\n#include \"../../../Common/MyCom.h\"\r\n#include \"../../../Common/Alloc.h\"\r\n#include \"../../ICoder.h\"\r\n#include \"../LZ/IMatchFinder.h\"\r\n#include \"../RangeCoder/RangeCoderBitTree.h\"\r\n\r\n#include \"LZMA.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NLZMA {\r\n\r\ntypedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;\r\n\r\nclass CBaseState\r\n{\r\nprotected:\r\n  CState _state;\r\n  Byte _previousByte;\r\n  UInt32 _repDistances[kNumRepDistances];\r\n  void Init()\r\n  {\r\n    _state.Init();\r\n    _previousByte = 0;\r\n    for(UInt32 i = 0 ; i < kNumRepDistances; i++)\r\n      _repDistances[i] = 0;\r\n  }\r\n};\r\n\r\nstruct COptimal\r\n{\r\n  CState State;\r\n\r\n  bool Prev1IsChar;\r\n  bool Prev2;\r\n\r\n  UInt32 PosPrev2;\r\n  UInt32 BackPrev2;     \r\n\r\n  UInt32 Price;    \r\n  UInt32 PosPrev;         // posNext;\r\n  UInt32 BackPrev;     \r\n  UInt32 Backs[kNumRepDistances];\r\n  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }\r\n  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n  bool IsShortRep() { return (BackPrev == 0); }\r\n};\r\n\r\n\r\nextern Byte g_FastPos[1024];\r\ninline UInt32 GetPosSlot(UInt32 pos)\r\n{\r\n  if (pos < (1 << 10))\r\n    return g_FastPos[pos];\r\n  if (pos < (1 << 19))\r\n    return g_FastPos[pos >> 9] + 18;\r\n  return g_FastPos[pos >> 18] + 36;\r\n}\r\n\r\ninline UInt32 GetPosSlot2(UInt32 pos)\r\n{\r\n  if (pos < (1 << 16))\r\n    return g_FastPos[pos >> 6] + 12;\r\n  if (pos < (1 << 25))\r\n    return g_FastPos[pos >> 15] + 30;\r\n  return g_FastPos[pos >> 24] + 48;\r\n}\r\n\r\nconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\nconst UInt32 kNumOpts = 1 << 12;\r\n\r\n\r\nclass CLiteralEncoder2\r\n{\r\n  CMyBitEncoder _encoders[0x300];\r\npublic:\r\n  void Init()\r\n  {\r\n    for (int i = 0; i < 0x300; i++)\r\n      _encoders[i].Init();\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);\r\n  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;\r\n};\r\n\r\nclass CLiteralEncoder\r\n{\r\n  CLiteralEncoder2 *_coders;\r\n  int _numPrevBits;\r\n  int _numPosBits;\r\n  UInt32 _posMask;\r\npublic:\r\n  CLiteralEncoder(): _coders(0) {}\r\n  ~CLiteralEncoder()  { Free(); }\r\n  void Free()\r\n  { \r\n    MyFree(_coders);\r\n    _coders = 0;\r\n  }\r\n  bool Create(int numPosBits, int numPrevBits)\r\n  {\r\n    if (_coders == 0 || (numPosBits + numPrevBits) != \r\n        (_numPrevBits + _numPosBits) )\r\n    {\r\n      Free();\r\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r\n      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));\r\n    }\r\n    _numPosBits = numPosBits;\r\n    _posMask = (1 << numPosBits) - 1;\r\n    _numPrevBits = numPrevBits;\r\n    return (_coders != 0);\r\n  }\r\n  void Init()\r\n  {\r\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r\n    for (UInt32 i = 0; i < numStates; i++)\r\n      _coders[i].Init();\r\n  }\r\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\r\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\r\n  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)\r\n    { return &_coders[GetState(pos, prevByte)]; }\r\n  /*\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte, \r\n      Byte symbol)\r\n    { _coders[GetState(pos, prevByte)].Encode(rangeEncoder, symbol); }\r\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte, \r\n      Byte matchByte, Byte symbol)\r\n    { _coders[GetState(pos, prevByte)].Encode(rangeEncoder,\r\n      matchByte, symbol); }\r\n  */\r\n  UInt32 GetPrice(UInt32 pos, Byte prevByte, bool matchMode, Byte matchByte, Byte symbol) const\r\n    { return _coders[GetState(pos, prevByte)].GetPrice(matchMode, matchByte, symbol); }\r\n};\r\n\r\nnamespace NLength {\r\n\r\nclass CEncoder\r\n{\r\n  CMyBitEncoder _choice;\r\n  CMyBitEncoder  _choice2;\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesEncodingMax];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits>  _highCoder;\r\npublic:\r\n  void Init(UInt32 numPosStates);\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const;\r\n};\r\n\r\nconst UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\r\n\r\nclass CPriceTableEncoder: public CEncoder\r\n{\r\n  UInt32 _prices[kNumSymbolsTotal][kNumPosStatesEncodingMax];\r\n  UInt32 _tableSize;\r\n  UInt32 _counters[kNumPosStatesEncodingMax];\r\npublic:\r\n  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }\r\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const\r\n    { return _prices[symbol][posState]; }\r\n  void UpdateTable(UInt32 posState)\r\n  {\r\n    for (UInt32 len = 0; len < _tableSize; len++)\r\n      _prices[len][posState] = CEncoder::GetPrice(len, posState);\r\n    _counters[posState] = _tableSize;\r\n  }\r\n  void UpdateTables(UInt32 numPosStates)\r\n  {\r\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\r\n      UpdateTable(posState);\r\n  }\r\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\r\n  {\r\n    CEncoder::Encode(rangeEncoder, symbol, posState);\r\n    if (--_counters[posState] == 0)\r\n      UpdateTable(posState);\r\n  }\r\n};\r\n\r\n}\r\n\r\nclass CEncoder : \r\n  public ICompressCoder,\r\n  public ICompressSetOutStream,\r\n  public ICompressSetCoderProperties,\r\n  public ICompressWriteCoderProperties,\r\n  public CBaseState,\r\n  public CMyUnknownImp\r\n{\r\n  COptimal _optimum[kNumOpts];\r\n  CMyComPtr<IMatchFinder> _matchFinder; // test it\r\n  NRangeCoder::CEncoder _rangeEncoder;\r\n\r\n  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n  CMyBitEncoder _isRep[kNumStates];\r\n  CMyBitEncoder _isRepG0[kNumStates];\r\n  CMyBitEncoder _isRepG1[kNumStates];\r\n  CMyBitEncoder _isRepG2[kNumStates];\r\n  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];\r\n\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];\r\n\r\n  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];\r\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;\r\n  \r\n  NLength::CPriceTableEncoder _lenEncoder;\r\n  NLength::CPriceTableEncoder _repMatchLenEncoder;\r\n\r\n  CLiteralEncoder _literalEncoder;\r\n\r\n  UInt32 _matchDistances[kMatchMaxLen + 1];\r\n\r\n  bool _fastMode;\r\n  bool _maxMode;\r\n  UInt32 _numFastBytes;\r\n  UInt32 _longestMatchLength;    \r\n\r\n  UInt32 _additionalOffset;\r\n\r\n  UInt32 _optimumEndIndex;\r\n  UInt32 _optimumCurrentIndex;\r\n\r\n  bool _longestMatchWasFound;\r\n\r\n  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r\n  \r\n  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];\r\n\r\n  UInt32 _alignPrices[kAlignTableSize];\r\n  UInt32 _alignPriceCount;\r\n\r\n  UInt32 _distTableSize;\r\n\r\n  UInt32 _posStateBits;\r\n  UInt32 _posStateMask;\r\n  UInt32 _numLiteralPosStateBits;\r\n  UInt32 _numLiteralContextBits;\r\n\r\n  UInt32 _dictionarySize;\r\n\r\n  UInt32 _dictionarySizePrev;\r\n  UInt32 _numFastBytesPrev;\r\n\r\n  UInt64 lastPosSlotFillingPos;\r\n  UInt64 nowPos64;\r\n  bool _finished;\r\n  ISequentialInStream *_inStream;\r\n\r\n  int _matchFinderIndex;\r\n  #ifdef COMPRESS_MF_MT\r\n  bool _multiThread;\r\n  #endif\r\n\r\n  bool _writeEndMark;\r\n\r\n  bool _needReleaseMFStream;\r\n  \r\n  HRESULT ReadMatchDistances(UInt32 &len);\r\n\r\n  HRESULT MovePos(UInt32 num);\r\n  UInt32 GetRepLen1Price(CState state, UInt32 posState) const\r\n  {\r\n    return _isRepG0[state.Index].GetPrice0() +\r\n        _isRep0Long[state.Index][posState].GetPrice0();\r\n  }\r\n  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const\r\n  {\r\n    UInt32 price = _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n    if(repIndex == 0)\r\n    {\r\n      price += _isRepG0[state.Index].GetPrice0();\r\n      price += _isRep0Long[state.Index][posState].GetPrice1();\r\n    }\r\n    else\r\n    {\r\n      price += _isRepG0[state.Index].GetPrice1();\r\n      if (repIndex == 1)\r\n        price += _isRepG1[state.Index].GetPrice0();\r\n      else\r\n      {\r\n        price += _isRepG1[state.Index].GetPrice1();\r\n        price += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n      }\r\n    }\r\n    return price;\r\n  }\r\n  /*\r\n  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const\r\n  {\r\n    if (pos >= kNumFullDistances)\r\n      return kIfinityPrice;\r\n    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);\r\n  }\r\n  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n  */\r\n  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const\r\n  {\r\n    if (len == 2 && pos >= 0x80)\r\n      return kIfinityPrice;\r\n    UInt32 price;\r\n    UInt32 lenToPosState = GetLenToPosState(len);\r\n    if (pos < kNumFullDistances)\r\n      price = _distancesPrices[lenToPosState][pos];\r\n    else\r\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r\n          _alignPrices[pos & kAlignMask];\r\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r\n  }\r\n\r\n  UInt32 Backward(UInt32 &backRes, UInt32 cur);\r\n  HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r\n  HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r\n\r\n  void FillPosSlotPrices();\r\n  void FillDistancesPrices();\r\n  void FillAlignPrices();\r\n    \r\n  void ReleaseMFStream()\r\n  {\r\n    if (_matchFinder && _needReleaseMFStream)\r\n    {\r\n      _matchFinder->ReleaseStream();\r\n      _needReleaseMFStream = false;\r\n    }\r\n  }\r\n\r\n  void ReleaseStreams()\r\n  {\r\n    ReleaseMFStream();\r\n    ReleaseOutStream();\r\n  }\r\n\r\n  HRESULT Flush(UInt32 nowPos);\r\n  class CCoderReleaser\r\n  {\r\n    CEncoder *_coder;\r\n  public:\r\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r\n    ~CCoderReleaser()\r\n    {\r\n      _coder->ReleaseStreams();\r\n    }\r\n  };\r\n  friend class CCoderReleaser;\r\n\r\n  void WriteEndMarker(UInt32 posState);\r\n\r\npublic:\r\n  CEncoder();\r\n  void SetWriteEndMarkerMode(bool writeEndMarker)\r\n    { _writeEndMark= writeEndMarker; }\r\n\r\n  HRESULT Create();\r\n\r\n  MY_UNKNOWN_IMP3(\r\n      ICompressSetOutStream,\r\n      ICompressSetCoderProperties,\r\n      ICompressWriteCoderProperties\r\n      )\r\n    \r\n  HRESULT Init();\r\n  \r\n  // ICompressCoder interface\r\n  HRESULT SetStreams(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream,\r\n      const UInt64 *inSize, const UInt64 *outSize);\r\n  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);\r\n\r\n  HRESULT CodeReal(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // ICompressCoder interface\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, const UInt64 *outSize,\r\n      ICompressProgressInfo *progress);\r\n\r\n  // IInitMatchFinder interface\r\n  STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder);\r\n\r\n  // ICompressSetCoderProperties2\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties);\r\n  \r\n  // ICompressWriteCoderProperties\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r\n\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r\n  STDMETHOD(ReleaseOutStream)();\r\n\r\n  virtual ~CEncoder() {}\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /I \"..\\..\\..\\\\\" /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I \"..\\..\\..\\\\\" /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"Pat\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2R.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat3H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat4H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\PatMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"BT\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3Z.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3ZMain.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree4b.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTreeMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"HC\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC3.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC4b.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HCMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\IMatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Branch\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\Branch\\BranchX86.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\Branch\\BranchX86.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZMA_C\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA_C\\LzmaDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA_C\\LzmaDecode.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\StreamUtils.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRam.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.c\r\n# SUBTRACT CPP /YX /Yc /Yu\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaRamDecode.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../../../Common/MyInitGuid.h\"\r\n\r\n#include <stdio.h>\r\n\r\n#if defined(_WIN32) || defined(OS2) || defined(MSDOS)\r\n#include <fcntl.h>\r\n#include <io.h>\r\n#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)\r\n#else\r\n#define MY_SET_BINARY_MODE(file)\r\n#endif\r\n\r\n#include \"../../../Common/CommandLineParser.h\"\r\n#include \"../../../Common/StringConvert.h\"\r\n#include \"../../../Common/StringToInt.h\"\r\n\r\n#include \"../../Common/FileStreams.h\"\r\n#include \"../../Common/StreamUtils.h\"\r\n\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"LzmaRamDecode.h\"\r\n}\r\n\r\nusing namespace NCommandLineParser;\r\n\r\n#ifdef _WIN32\r\nbool g_IsNT = false;\r\nstatic inline bool IsItWindowsNT()\r\n{\r\n  OSVERSIONINFO versionInfo;\r\n  versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);\r\n  if (!::GetVersionEx(&versionInfo)) \r\n    return false;\r\n  return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);\r\n}\r\n#endif\r\n\r\nstatic const char *kCantAllocate = \"Can not allocate memory\";\r\nstatic const char *kReadError = \"Read error\";\r\nstatic const char *kWriteError = \"Write error\";\r\n\r\nnamespace NKey {\r\nenum Enum\r\n{\r\n  kHelp1 = 0,\r\n  kHelp2,\r\n  kMode,\r\n  kDictionary,\r\n  kFastBytes,\r\n  kLitContext,\r\n  kLitPos,\r\n  kPosBits,\r\n  kMatchFinder,\r\n  kEOS,\r\n  kStdIn,\r\n  kStdOut,\r\n  kFilter86\r\n};\r\n}\r\n\r\nstatic const CSwitchForm kSwitchForms[] = \r\n{\r\n  { L\"?\",  NSwitchType::kSimple, false },\r\n  { L\"H\",  NSwitchType::kSimple, false },\r\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\r\n  { L\"EOS\", NSwitchType::kSimple, false },\r\n  { L\"SI\",  NSwitchType::kSimple, false },\r\n  { L\"SO\",  NSwitchType::kSimple, false },\r\n  { L\"F86\",  NSwitchType::kSimple, false }\r\n};\r\n\r\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\r\n\r\nstatic void PrintHelp()\r\n{\r\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\r\n             \"  e: encode file\\n\"\r\n             \"  d: decode file\\n\"\r\n             \"  b: Benchmark\\n\"\r\n    \"<Switches>\\n\"\r\n    \"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\"\r\n    \"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\"\r\n    \"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\"\r\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\r\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\r\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\r\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, bt4b, pat2r, pat2,\\n\"\r\n    \"              pat2h, pat3h, pat4h, hc3, hc4], default: bt4\\n\"\r\n    \"  -eos:   write End Of Stream marker\\n\"\r\n    \"  -si:    read data from stdin\\n\"\r\n    \"  -so:    write data to stdout\\n\"\r\n    );\r\n}\r\n\r\nstatic void PrintHelpAndExit(const char *s)\r\n{\r\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\r\n  PrintHelp();\r\n  throw -1;\r\n}\r\n\r\nstatic void IncorrectCommand()\r\n{\r\n  PrintHelpAndExit(\"Incorrect command\");\r\n}\r\n\r\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[], \r\n    UStringVector &strings)\r\n{\r\n  for(int i = 1; i < numArguments; i++)\r\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\r\n}\r\n\r\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\r\n{\r\n  value = 0;\r\n  if (MyStringLen(s) == 0)\r\n    return false;\r\n  const wchar_t *end;\r\n  UInt64 res = ConvertStringToUInt64(s, &end);\r\n  if (*end != L'\\0')\r\n    return false;\r\n  if (res > 0xFFFFFFFF)\r\n    return false;\r\n  value = UInt32(res);\r\n  return true;\r\n}\r\n\r\nint main2(int n, const char *args[])\r\n{\r\n  #ifdef _WIN32\r\n  g_IsNT = IsItWindowsNT();\r\n  #endif\r\n\r\n  fprintf(stderr, \"\\nLZMA 4.32 Copyright (c) 1999-2005 Igor Pavlov  2005-12-09\\n\");\r\n\r\n  if (n == 1)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n\r\n  if (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4)\r\n  {\r\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\r\n    return 1;\r\n  }   \r\n\r\n  UStringVector commandStrings;\r\n  WriteArgumentsToStringList(n, args, commandStrings);\r\n  CParser parser(kNumSwitches);\r\n  try\r\n  {\r\n    parser.ParseStrings(kSwitchForms, commandStrings);\r\n  }\r\n  catch(...) \r\n  {\r\n    IncorrectCommand();\r\n  }\r\n\r\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\r\n  {\r\n    PrintHelp();\r\n    return 0;\r\n  }\r\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n  int paramIndex = 0;\r\n  if (paramIndex >= nonSwitchStrings.Size())\r\n    IncorrectCommand();\r\n  const UString &command = nonSwitchStrings[paramIndex++]; \r\n\r\n  bool dictionaryIsDefined = false;\r\n  UInt32 dictionary = 1 << 21;\r\n  if(parser[NKey::kDictionary].ThereIs)\r\n  {\r\n    UInt32 dicLog;\r\n    if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))\r\n      IncorrectCommand();\r\n    dictionary = 1 << dicLog;\r\n    dictionaryIsDefined = true;\r\n  }\r\n  UString mf = L\"BT4\";\r\n  if (parser[NKey::kMatchFinder].ThereIs)\r\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\r\n\r\n  if (command.CompareNoCase(L\"b\") == 0)\r\n  {\r\n    const UInt32 kNumDefaultItereations = 10;\r\n    UInt32 numIterations = kNumDefaultItereations;\r\n    {\r\n      if (paramIndex < nonSwitchStrings.Size())\r\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\r\n          numIterations = kNumDefaultItereations;\r\n    }\r\n    return LzmaBenchmark(stderr, numIterations, dictionary, \r\n        mf.CompareNoCase(L\"BT4\") == 0);\r\n  }\r\n\r\n  bool encodeMode = false;\r\n  if (command.CompareNoCase(L\"e\") == 0)\r\n    encodeMode = true;\r\n  else if (command.CompareNoCase(L\"d\") == 0)\r\n    encodeMode = false;\r\n  else\r\n    IncorrectCommand();\r\n\r\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\r\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\r\n\r\n  CMyComPtr<ISequentialInStream> inStream;\r\n  CInFileStream *inStreamSpec = 0;\r\n  if (stdInMode)\r\n  {\r\n    inStream = new CStdInFileStream;\r\n    MY_SET_BINARY_MODE(stdin);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &inputName = nonSwitchStrings[paramIndex++]; \r\n    inStreamSpec = new CInFileStream;\r\n    inStream = inStreamSpec;\r\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\", \r\n          (const char *)GetOemString(inputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  CMyComPtr<ISequentialOutStream> outStream;\r\n  if (stdOutMode)\r\n  {\r\n    outStream = new CStdOutFileStream;\r\n    MY_SET_BINARY_MODE(stdout);\r\n  }\r\n  else\r\n  {\r\n    if (paramIndex >= nonSwitchStrings.Size())\r\n      IncorrectCommand();\r\n    const UString &outputName = nonSwitchStrings[paramIndex++]; \r\n    COutFileStream *outStreamSpec = new COutFileStream;\r\n    outStream = outStreamSpec;\r\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\r\n    {\r\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\", \r\n        (const char *)GetOemString(outputName));\r\n      return 1;\r\n    }\r\n  }\r\n\r\n  if (parser[NKey::kFilter86].ThereIs)\r\n  {\r\n    // -f86 switch is for x86 filtered mode: BCJ + LZMA.\r\n    if (parser[NKey::kEOS].ThereIs || stdInMode)\r\n      throw \"Can not use stdin in this mode\";\r\n    UInt64 fileSize;\r\n    inStreamSpec->File.GetLength(fileSize);\r\n    if (fileSize > 0xF0000000)\r\n      throw \"File is too big\";\r\n    UInt32 inSize = (UInt32)fileSize;\r\n    Byte *inBuffer = 0;\r\n    if (inSize != 0)\r\n    {\r\n      inBuffer = (Byte *)MyAlloc((size_t)inSize); \r\n      if (inBuffer == 0)\r\n        throw kCantAllocate;\r\n    }\r\n    \r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)\r\n      throw \"Can not read\";\r\n    if ((UInt32)inSize != processedSize)\r\n      throw \"Read size error\";\r\n\r\n    Byte *outBuffer = 0;\r\n    size_t outSizeProcessed;\r\n    if (encodeMode)\r\n    {\r\n      // we allocate 105% of original size for output buffer\r\n      size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc((size_t)outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      if (!dictionaryIsDefined)\r\n        dictionary = 1 << 23;\r\n      int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, \r\n          dictionary, SZ_FILTER_AUTO);\r\n      if (res != 0)\r\n      {\r\n        fprintf(stderr, \"\\nEncoder error = %d\\n\", (int)res);\r\n        return 1;\r\n      }\r\n    }\r\n    else\r\n    {\r\n      size_t outSize;\r\n      if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)\r\n        throw \"data error\";\r\n      if (outSize != 0)\r\n      {\r\n        outBuffer = (Byte *)MyAlloc(outSize); \r\n        if (outBuffer == 0)\r\n          throw kCantAllocate;\r\n      }\r\n      int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);\r\n      if (res != 0)\r\n        throw \"LzmaDecoder error\";\r\n    }\r\n    if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)\r\n      throw kWriteError;\r\n    MyFree(outBuffer);\r\n    MyFree(inBuffer);\r\n    return 0;\r\n  }\r\n\r\n\r\n  UInt64 fileSize;\r\n  if (encodeMode)\r\n  {\r\n    NCompress::NLZMA::CEncoder *encoderSpec = \r\n      new NCompress::NLZMA::CEncoder;\r\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n    if (!dictionaryIsDefined)\r\n      dictionary = 1 << 23;\r\n\r\n    UInt32 posStateBits = 2;\r\n    UInt32 litContextBits = 3; // for normal files\r\n    // UInt32 litContextBits = 0; // for 32-bit data\r\n    UInt32 litPosBits = 0;\r\n    // UInt32 litPosBits = 2; // for 32-bit data\r\n    UInt32 algorithm = 2;\r\n    UInt32 numFastBytes = 128;\r\n\r\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\r\n \r\n    if(parser[NKey::kMode].ThereIs)\r\n      if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))\r\n        IncorrectCommand();\r\n\r\n    if(parser[NKey::kFastBytes].ThereIs)\r\n      if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitContext].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kLitPos].ThereIs)\r\n      if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))\r\n        IncorrectCommand();\r\n    if(parser[NKey::kPosBits].ThereIs)\r\n      if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))\r\n        IncorrectCommand();\r\n\r\n    PROPID propIDs[] = \r\n    {\r\n      NCoderPropID::kDictionarySize,\r\n      NCoderPropID::kPosStateBits,\r\n      NCoderPropID::kLitContextBits,\r\n      NCoderPropID::kLitPosBits,\r\n      NCoderPropID::kAlgorithm,\r\n      NCoderPropID::kNumFastBytes,\r\n      NCoderPropID::kMatchFinder,\r\n      NCoderPropID::kEndMarker\r\n    };\r\n    const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n    /*\r\n    NWindows::NCOM::CPropVariant properties[kNumProps];\r\n    properties[0] = UInt32(dictionary);\r\n    properties[1] = UInt32(posStateBits);\r\n    properties[2] = UInt32(litContextBits);\r\n   \r\n    properties[3] = UInt32(litPosBits);\r\n    properties[4] = UInt32(algorithm);\r\n    properties[5] = UInt32(numFastBytes);\r\n    properties[6] = mf;\r\n    properties[7] = eos;\r\n    */\r\n    PROPVARIANT properties[kNumProps];\r\n    for (int p = 0; p < 6; p++)\r\n      properties[p].vt = VT_UI4;\r\n    properties[0].ulVal = UInt32(dictionary);\r\n    properties[1].ulVal = UInt32(posStateBits);\r\n    properties[2].ulVal = UInt32(litContextBits);\r\n    properties[3].ulVal = UInt32(litPosBits);\r\n    properties[4].ulVal = UInt32(algorithm);\r\n    properties[5].ulVal = UInt32(numFastBytes);\r\n    \r\n    properties[6].vt = VT_BSTR;\r\n    properties[6].bstrVal = (BSTR)(const wchar_t *)mf;\r\n\r\n    properties[7].vt = VT_BOOL;\r\n    properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\r\n\r\n    if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n      IncorrectCommand();\r\n    encoderSpec->WriteCoderProperties(outStream);\r\n\r\n    if (eos || stdInMode)\r\n      fileSize = (UInt64)(Int64)-1;\r\n    else\r\n      inStreamSpec->File.GetLength(fileSize);\r\n\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b = Byte(fileSize >> (8 * i));\r\n      if (outStream->Write(&b, 1, 0) != S_OK)\r\n      {\r\n        fprintf(stderr, kWriteError);\r\n        return 1;\r\n      }\r\n    }\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    if (result == E_OUTOFMEMORY)\r\n    {\r\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\r\n      return 1;\r\n    }   \r\n    else if (result != S_OK)\r\n    {\r\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\r\n      return 1;\r\n    }   \r\n  }\r\n  else\r\n  {\r\n    NCompress::NLZMA::CDecoder *decoderSpec = \r\n        new NCompress::NLZMA::CDecoder;\r\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n    const UInt32 kPropertiesSize = 5;\r\n    Byte properties[kPropertiesSize];\r\n    UInt32 processedSize;\r\n    if (ReadStream(inStream, properties, kPropertiesSize, &processedSize) != S_OK)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (processedSize != kPropertiesSize)\r\n    {\r\n      fprintf(stderr, kReadError);\r\n      return 1;\r\n    }\r\n    if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)\r\n    {\r\n      fprintf(stderr, \"SetDecoderProperties error\");\r\n      return 1;\r\n    }\r\n    fileSize = 0;\r\n    for (int i = 0; i < 8; i++)\r\n    {\r\n      Byte b;\r\n      if (inStream->Read(&b, 1, &processedSize) != S_OK)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      if (processedSize != 1)\r\n      {\r\n        fprintf(stderr, kReadError);\r\n        return 1;\r\n      }\r\n      fileSize |= ((UInt64)b) << (8 * i);\r\n    }\r\n    if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n    {\r\n      fprintf(stderr, \"Decoder error\");\r\n      return 1;\r\n    }   \r\n  }\r\n  return 0;\r\n}\r\n\r\nint main(int n, const char *args[])\r\n{\r\n  try { return main2(n, args); }\r\n  catch(const char *s) \r\n  { \r\n    fprintf(stderr, \"\\nError: %s\\n\", s);\r\n    return 1; \r\n  }\r\n  catch(...) \r\n  { \r\n    fprintf(stderr, \"\\nError\\n\");\r\n    return 1; \r\n  }\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"LzmaBench.h\"\r\n\r\n#ifndef _WIN32\r\n#include <time.h>\r\n#endif\r\n\r\n#include \"../../../Common/CRC.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\nstatic const UInt32 kAdditionalSize = \r\n#ifdef _WIN32_WCE\r\n(1 << 20);\r\n#else\r\n(6 << 20);\r\n#endif\r\n\r\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\r\nstatic const UInt32 kMaxLzmaPropSize = 10;\r\n\r\nclass CRandomGenerator\r\n{\r\n  UInt32 A1;\r\n  UInt32 A2;\r\npublic:\r\n  CRandomGenerator() { Init(); }\r\n  void Init() { A1 = 362436069; A2 = 521288629;}\r\n  UInt32 GetRnd() \r\n  {\r\n    return \r\n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\r\n  }\r\n};\r\n\r\nclass CBitRandomGenerator\r\n{\r\n  CRandomGenerator RG;\r\n  UInt32 Value;\r\n  int NumBits;\r\npublic:\r\n  void Init()\r\n  {\r\n    Value = 0;\r\n    NumBits = 0;\r\n  }\r\n  UInt32 GetRnd(int numBits) \r\n  {\r\n    if (NumBits > numBits)\r\n    {\r\n      UInt32 result = Value & ((1 << numBits) - 1);\r\n      Value >>= numBits;\r\n      NumBits -= numBits;\r\n      return result;\r\n    }\r\n    numBits -= NumBits;\r\n    UInt32 result = (Value << numBits);\r\n    Value = RG.GetRnd();\r\n    result |= Value & ((1 << numBits) - 1);\r\n    Value >>= numBits;\r\n    NumBits = 32 - numBits;\r\n    return result;\r\n  }\r\n};\r\n\r\nclass CBenchRandomGenerator\r\n{\r\n  CBitRandomGenerator RG;\r\n  UInt32 Pos;\r\npublic:\r\n  UInt32 BufferSize;\r\n  Byte *Buffer;\r\n  CBenchRandomGenerator(): Buffer(0) {} \r\n  ~CBenchRandomGenerator() { delete []Buffer; }\r\n  void Init() { RG.Init(); }\r\n  void Set(UInt32 bufferSize) \r\n  {\r\n    delete []Buffer;\r\n    Buffer = 0;\r\n    Buffer = new Byte[bufferSize];\r\n    Pos = 0;\r\n    BufferSize = bufferSize;\r\n  }\r\n  UInt32 GetRndBit() { return RG.GetRnd(1); }\r\n  /*\r\n  UInt32 GetLogRand(int maxLen)\r\n  {\r\n    UInt32 len = GetRnd() % (maxLen + 1);\r\n    return GetRnd() & ((1 << len) - 1);\r\n  }\r\n  */\r\n  UInt32 GetLogRandBits(int numBits)\r\n  {\r\n    UInt32 len = RG.GetRnd(numBits);\r\n    return RG.GetRnd(len);\r\n  }\r\n  UInt32 GetOffset()\r\n  {\r\n    if (GetRndBit() == 0)\r\n      return GetLogRandBits(4);\r\n    return (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n  }\r\n  UInt32 GetLen()\r\n  {\r\n    if (GetRndBit() == 0)\r\n      return RG.GetRnd(2);\r\n    if (GetRndBit() == 0)\r\n      return 4 + RG.GetRnd(3);\r\n    return 12 + RG.GetRnd(4);\r\n  }\r\n  void Generate()\r\n  {\r\n    while(Pos < BufferSize)\r\n    {\r\n      if (GetRndBit() == 0 || Pos < 1)\r\n        Buffer[Pos++] = Byte(RG.GetRnd(8));\r\n      else\r\n      {\r\n        UInt32 offset = GetOffset();\r\n        while (offset >= Pos)\r\n          offset >>= 1;\r\n        offset += 1;\r\n        UInt32 len = 2 + GetLen();\r\n        for (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n          Buffer[Pos] = Buffer[Pos - offset];\r\n      }\r\n    }\r\n  }\r\n};\r\n\r\nclass CBenchmarkInStream: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  UInt32 Pos;\r\n  UInt32 Size;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, UInt32 size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 remain = Size - Pos;\r\n  if (size > remain)\r\n    size = remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass CBenchmarkOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  UInt32 BufferSize;\r\n  FILE *_f;\r\npublic:\r\n  UInt32 Pos;\r\n  Byte *Buffer;\r\n  CBenchmarkOutStream(): _f(0), Buffer(0) {} \r\n  virtual ~CBenchmarkOutStream() { delete []Buffer; }\r\n  void Init(FILE *f, UInt32 bufferSize) \r\n  {\r\n    delete []Buffer;\r\n    Buffer = 0;\r\n    Buffer = new Byte[bufferSize];\r\n    Pos = 0;\r\n    BufferSize = bufferSize;\r\n    _f = f;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < BufferSize; i++)\r\n    Buffer[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    fprintf(_f, \"\\nERROR: Buffer is full\\n\");\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\nclass CCrcOutStream: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CCRC CRC;\r\n  MY_UNKNOWN_IMP\r\n  void Init() { CRC.Init(); }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  CRC.Update(data, size);\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nstatic UInt64 GetTimeCount()\r\n{\r\n  #ifdef _WIN32\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceCounter(&value))\r\n    return value.QuadPart;\r\n  return GetTickCount();\r\n  #else\r\n  return clock();\r\n  #endif \r\n}\r\n\r\nstatic UInt64 GetFreq()\r\n{\r\n  #ifdef _WIN32\r\n  LARGE_INTEGER value;\r\n  if (::QueryPerformanceFrequency(&value))\r\n    return value.QuadPart;\r\n  return 1000;\r\n  #else\r\n  return CLOCKS_PER_SEC;\r\n  #endif \r\n}\r\n\r\nstruct CProgressInfo:\r\n  public ICompressProgressInfo,\r\n  public CMyUnknownImp\r\n{\r\n  UInt64 ApprovedStart;\r\n  UInt64 InSize;\r\n  UInt64 Time;\r\n  void Init()\r\n  {\r\n    InSize = 0;\r\n    Time = 0;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\r\n};\r\n\r\nSTDMETHODIMP CProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\r\n{\r\n  if (*inSize >= ApprovedStart && InSize == 0)\r\n  {\r\n    Time = ::GetTimeCount();\r\n    InSize = *inSize;\r\n  }\r\n  return S_OK;\r\n}\r\n\r\nstatic const int kSubBits = 8;\r\n\r\nstatic UInt32 GetLogSize(UInt32 size)\r\n{\r\n  for (int i = kSubBits; i < 32; i++)\r\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n        return (i << kSubBits) + j;\r\n  return (32 << kSubBits);\r\n}\r\n\r\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n{\r\n  UInt64 freq = GetFreq();\r\n  UInt64 elTime = elapsedTime;\r\n  while(freq > 1000000)\r\n  {\r\n    freq >>= 1;\r\n    elTime >>= 1;\r\n  }\r\n  if (elTime == 0)\r\n    elTime = 1;\r\n  return value * freq / elTime;\r\n}\r\n\r\nstatic UInt64 GetCompressRating(UInt32 dictionarySize, bool isBT4,\r\n    UInt64 elapsedTime, UInt64 size)\r\n{\r\n  UInt64 numCommandsForOne;\r\n  if (isBT4)\r\n  {\r\n    UInt64 t = GetLogSize(dictionarySize) - (19 << kSubBits);\r\n    numCommandsForOne = 2000 + ((t * t * 68) >> (2 * kSubBits));\r\n  }\r\n  else\r\n  {\r\n    UInt64 t = GetLogSize(dictionarySize) - (15 << kSubBits);\r\n    numCommandsForOne = 1500 + ((t * t * 41) >> (2 * kSubBits));\r\n  }\r\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n  return MyMultDiv64(numCommands, elapsedTime);\r\n}\r\n\r\nstatic UInt64 GetDecompressRating(UInt64 elapsedTime, \r\n    UInt64 outSize, UInt64 inSize)\r\n{\r\n  UInt64 numCommands = inSize * 250 + outSize * 21;\r\n  return MyMultDiv64(numCommands, elapsedTime);\r\n}\r\n\r\n/*\r\nstatic UInt64 GetTotalRating(\r\n    UInt32 dictionarySize, \r\n    bool isBT4,\r\n    UInt64 elapsedTimeEn, UInt64 sizeEn,\r\n    UInt64 elapsedTimeDe, \r\n    UInt64 inSizeDe, UInt64 outSizeDe)\r\n{\r\n  return (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) + \r\n    GetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n}\r\n*/\r\n\r\nstatic void PrintRating(FILE *f, UInt64 rating)\r\n{\r\n  fprintf(f, \"%5d MIPS\", (unsigned int)(rating / 1000000));\r\n}\r\n\r\nstatic void PrintResults(\r\n    FILE *f, \r\n    UInt32 dictionarySize,\r\n    bool isBT4,\r\n    UInt64 elapsedTime, \r\n    UInt64 size, \r\n    bool decompressMode, UInt64 secondSize)\r\n{\r\n  UInt64 speed = MyMultDiv64(size, elapsedTime);\r\n  fprintf(f, \"%6d KB/s  \", (unsigned int)(speed / 1024));\r\n  UInt64 rating;\r\n  if (decompressMode)\r\n    rating = GetDecompressRating(elapsedTime, size, secondSize);\r\n  else\r\n    rating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\r\n  PrintRating(f, rating);\r\n}\r\n\r\nstatic void ThrowError(FILE *f, HRESULT result, const char *s)\r\n{\r\n  fprintf(f, \"\\nError: \");\r\n  if (result == E_ABORT)\r\n    fprintf(f, \"User break\");\r\n  if (result == E_OUTOFMEMORY)\r\n    fprintf(f, \"Can not allocate memory\");\r\n  else\r\n    fprintf(f, s);\r\n  fprintf(f, \"\\n\");\r\n}\r\n\r\nconst wchar_t *bt2 = L\"BT2\";\r\nconst wchar_t *bt4 = L\"BT4\";\r\n\r\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize, bool isBT4)\r\n{\r\n  if (numIterations == 0)\r\n    return 0;\r\n  if (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\r\n  {\r\n    fprintf(f, \"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\\n\");\r\n    return 1;\r\n  }\r\n  fprintf(f, \"\\n       Compressing                Decompressing\\n\\n\");\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;\r\n  CMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n\r\n  CBenchmarkOutStream *propStreamSpec = new CBenchmarkOutStream;\r\n  CMyComPtr<ISequentialOutStream> propStream = propStreamSpec;\r\n  propStreamSpec->Init(f, kMaxLzmaPropSize);\r\n  \r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kMatchFinder  \r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[0].ulVal = UInt32(dictionarySize);\r\n\r\n  properties[1].vt = VT_BSTR;\r\n  properties[1].bstrVal = isBT4 ? (BSTR)bt4: (BSTR)bt2;\r\n\r\n  const UInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n  {\r\n    fprintf(f, \"\\nError: Incorrect command\\n\");\r\n    return 1;\r\n  }\r\n  encoderSpec->WriteCoderProperties(propStream);\r\n\r\n  CBenchRandomGenerator rg;\r\n  rg.Init();\r\n  rg.Set(kBufferSize);\r\n  rg.Generate();\r\n  CCRC crc;\r\n  crc.Update(rg.Buffer, rg.BufferSize);\r\n\r\n  CProgressInfo *progressInfoSpec = new CProgressInfo;\r\n  CMyComPtr<ICompressProgressInfo> progressInfo = progressInfoSpec;\r\n\r\n  progressInfoSpec->ApprovedStart = dictionarySize;\r\n\r\n  UInt64 totalBenchSize = 0;\r\n  UInt64 totalEncodeTime = 0;\r\n  UInt64 totalDecodeTime = 0;\r\n  UInt64 totalCompressedSize = 0;\r\n\r\n  for (UInt32 i = 0; i < numIterations; i++)\r\n  {\r\n    progressInfoSpec->Init();\r\n    CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\r\n    inStreamSpec->Init(rg.Buffer, rg.BufferSize);\r\n    CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n    CBenchmarkOutStream *outStreamSpec = new CBenchmarkOutStream;\r\n    outStreamSpec->Init(f, kCompressedBufferSize);\r\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, progressInfo);\r\n    UInt64 encodeTime = ::GetTimeCount() - progressInfoSpec->Time;\r\n    UInt32 compressedSize = outStreamSpec->Pos;\r\n    if(result != S_OK)\r\n    {\r\n      ThrowError(f, result, \"Encoder Error\");\r\n      return 1;\r\n    }\r\n    if (progressInfoSpec->InSize == 0)\r\n    {\r\n      fprintf(f, \"\\nError: Internal ERROR 1282\\n\");\r\n      return 1;\r\n    }\r\n  \r\n    ///////////////////////\r\n    // Decompressing\r\n  \r\n    CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\r\n    CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\r\n    \r\n    UInt64 decodeTime;\r\n    for (int j = 0; j < 2; j++)\r\n    {\r\n      inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\r\n      crcOutStreamSpec->Init();\r\n      \r\n      if (decoderSpec->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos) != S_OK)\r\n      {\r\n        fprintf(f, \"\\nError: Set Decoder Properties Error\\n\");\r\n        return 1;\r\n      }\r\n      UInt64 outSize = kBufferSize;\r\n      UInt64 startTime = ::GetTimeCount();\r\n      result = decoder->Code(inStream, crcOutStream, 0, &outSize, 0);\r\n      decodeTime = ::GetTimeCount() - startTime;\r\n      if(result != S_OK)\r\n      {\r\n        ThrowError(f, result, \"Decode Error\");\r\n        return 1;\r\n      }\r\n      if (crcOutStreamSpec->CRC.GetDigest() != crc.GetDigest())\r\n      {\r\n        fprintf(f, \"\\nError: CRC Error\\n\");\r\n        return 1;\r\n      }\r\n    }\r\n    UInt64 benchSize = kBufferSize - progressInfoSpec->InSize;\r\n    PrintResults(f, dictionarySize, isBT4, encodeTime, benchSize, false, 0);\r\n    fprintf(f, \"     \");\r\n    PrintResults(f, dictionarySize, isBT4, decodeTime, kBufferSize, true, compressedSize);\r\n    fprintf(f, \"\\n\");\r\n\r\n    totalBenchSize += benchSize;\r\n    totalEncodeTime += encodeTime;\r\n    totalDecodeTime += decodeTime;\r\n    totalCompressedSize += compressedSize;\r\n  }\r\n  fprintf(f, \"---------------------------------------------------\\n\");\r\n  PrintResults(f, dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\r\n  fprintf(f, \"     \");\r\n  PrintResults(f, dictionarySize, isBT4, totalDecodeTime, \r\n      kBufferSize * numIterations, true, totalCompressedSize);\r\n  fprintf(f, \"    Average\\n\");\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\r\n\r\n#ifndef __LzmaBench_h\r\n#define __LzmaBench_h\r\n\r\n#include <stdio.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize, bool isBT4);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/LzmaRam.cpp",
    "content": "// LzmaRam.cpp\r\n\r\n#include \"StdAfx.h\"\r\n#include \"../../../Common/Types.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n#include \"LzmaRam.h\"\r\n\r\nextern \"C\"\r\n{\r\n#include \"../Branch/BranchX86.h\"\r\n}\r\n\r\nclass CInStreamRam: \r\n  public ISequentialInStream,\r\n  public CMyUnknownImp\r\n{\r\n  const Byte *Data;\r\n  size_t Size;\r\n  size_t Pos;\r\npublic:\r\n  MY_UNKNOWN_IMP\r\n  void Init(const Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n  }\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 remain = Size - Pos;\r\n  if (size > remain)\r\n    size = remain;\r\n  for (UInt32 i = 0; i < size; i++)\r\n    ((Byte *)data)[i] = Data[Pos + i];\r\n  Pos += size;\r\n  if(processedSize != NULL)\r\n    *processedSize = size;\r\n  return S_OK;\r\n}\r\n  \r\nclass COutStreamRam: \r\n  public ISequentialOutStream,\r\n  public CMyUnknownImp\r\n{\r\n  size_t Size;\r\npublic:\r\n  Byte *Data;\r\n  size_t Pos;\r\n  bool Overflow;\r\n  void Init(Byte *data, size_t size)\r\n  {\r\n    Data = data;\r\n    Size = size;\r\n    Pos = 0;\r\n    Overflow = false;\r\n  }\r\n  void SetPos(size_t pos)\r\n  {\r\n    Overflow = false;\r\n    Pos = pos;\r\n  }\r\n  MY_UNKNOWN_IMP\r\n  HRESULT WriteByte(Byte b)\r\n  {\r\n    if (Pos >= Size)\r\n    {\r\n      Overflow = true;\r\n      return E_FAIL;\r\n    }\r\n    Data[Pos++] = b;\r\n    return S_OK;\r\n  }\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\r\n};\r\n\r\nSTDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)\r\n{\r\n  UInt32 i;\r\n  for (i = 0; i < size && Pos < Size; i++)\r\n    Data[Pos++] = ((const Byte *)data)[i];\r\n  if(processedSize != NULL)\r\n    *processedSize = i;\r\n  if (i != size)\r\n  {\r\n    Overflow = true;\r\n    return E_FAIL;\r\n  }\r\n  return S_OK;\r\n}\r\n  \r\n#define SZE_FAIL (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n#define SZE_OUT_OVERFLOW (3)\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode)\r\n{\r\n  #ifndef _NO_EXCEPTIONS\r\n  try { \r\n  #endif\r\n\r\n  *outSizeProcessed = 0;\r\n  const size_t kIdSize = 1;\r\n  const size_t kLzmaPropsSize = 5;\r\n  const size_t kMinDestSize = kIdSize + kLzmaPropsSize + 8;\r\n  if (outSize < kMinDestSize)\r\n    return SZE_OUT_OVERFLOW;\r\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\r\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\r\n  PROPID propIDs[] = \r\n  { \r\n    NCoderPropID::kAlgorithm,\r\n    NCoderPropID::kDictionarySize,  \r\n    NCoderPropID::kNumFastBytes,\r\n  };\r\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n  PROPVARIANT properties[kNumProps];\r\n  properties[0].vt = VT_UI4;\r\n  properties[1].vt = VT_UI4;\r\n  properties[2].vt = VT_UI4;\r\n  properties[0].ulVal = (UInt32)2;\r\n  properties[1].ulVal = (UInt32)dictionarySize;\r\n  properties[2].ulVal = (UInt32)64;\r\n\r\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n    return 1;\r\n  \r\n  COutStreamRam *outStreamSpec = new COutStreamRam;\r\n  if (outStreamSpec == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n  CInStreamRam *inStreamSpec = new CInStreamRam;\r\n  if (inStreamSpec == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\r\n  outStreamSpec->Init(outBuffer, outSize);\r\n  if (outStreamSpec->WriteByte(0) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n\r\n  if (encoderSpec->WriteCoderProperties(outStream) != S_OK)\r\n    return SZE_OUT_OVERFLOW;\r\n  if (outStreamSpec->Pos != kIdSize + kLzmaPropsSize)\r\n    return 1;\r\n  \r\n  int i;\r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    UInt64 t = (UInt64)(inSize);\r\n    if (outStreamSpec->WriteByte((Byte)((t) >> (8 * i))) != S_OK)\r\n      return SZE_OUT_OVERFLOW;\r\n  }\r\n\r\n  Byte *filteredStream = 0;\r\n\r\n  bool useFilter = (filterMode != SZ_FILTER_NO);\r\n  if (useFilter)\r\n  {\r\n    if (inSize != 0)\r\n    {\r\n      filteredStream = (Byte *)MyAlloc(inSize);\r\n      if (filteredStream == 0)\r\n        return SZE_OUTOFMEMORY;\r\n      memmove(filteredStream, inBuffer, inSize);\r\n    }\r\n    UInt32 _prevMask;\r\n    UInt32 _prevPos;\r\n    x86_Convert_Init(_prevMask, _prevPos);\r\n    x86_Convert(filteredStream, (UInt32)inSize, 0, &_prevMask, &_prevPos, 1);\r\n  }\r\n  \r\n  UInt32 minSize = 0;\r\n  int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;\r\n  bool bestIsFiltered = false;\r\n  int mainResult = 0;\r\n  size_t startPos = outStreamSpec->Pos;\r\n  for (i = 0; i < numPasses; i++)\r\n  {\r\n    if (numPasses > 1 && i == numPasses - 1 && !bestIsFiltered)\r\n      break;\r\n    outStreamSpec->SetPos(startPos);\r\n    bool curModeIsFiltered = false;\r\n    if (useFilter && i == 0)\r\n      curModeIsFiltered = true;\r\n    if (numPasses > 1 && i == numPasses - 1)\r\n      curModeIsFiltered = true;\r\n\r\n    inStreamSpec->Init(curModeIsFiltered ? filteredStream : inBuffer, inSize);\r\n    \r\n    HRESULT lzmaResult = encoder->Code(inStream, outStream, 0, 0, 0);\r\n    \r\n    mainResult = 0;\r\n    if (lzmaResult == E_OUTOFMEMORY)\r\n    {\r\n      mainResult = SZE_OUTOFMEMORY;\r\n      break;\r\n    } \r\n    if (i == 0 || outStreamSpec->Pos <= minSize)\r\n    {\r\n      minSize = outStreamSpec->Pos;\r\n      bestIsFiltered = curModeIsFiltered;\r\n    }\r\n    if (outStreamSpec->Overflow)\r\n      mainResult = SZE_OUT_OVERFLOW;\r\n    else if (lzmaResult != S_OK)\r\n    {\r\n      mainResult = SZE_FAIL;\r\n      break;\r\n    } \r\n  }\r\n  *outSizeProcessed = outStreamSpec->Pos;\r\n  if (bestIsFiltered)\r\n    outBuffer[0] = 1;\r\n  if (useFilter)\r\n    MyFree(filteredStream);\r\n  return mainResult;\r\n  \r\n  #ifndef _NO_EXCEPTIONS\r\n  } catch(...) { return SZE_OUTOFMEMORY; }\r\n  #endif\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/LzmaRam.h",
    "content": "// LzmaRam.h\r\n\r\n#ifndef __LzmaRam_h\r\n#define __LzmaRam_h\r\n\r\n#include <stdlib.h>\r\n#include \"../../../Common/Types.h\"\r\n\r\n/*\r\nLzmaRamEncode: BCJ + LZMA RAM->RAM compressing.\r\nIt uses .lzma format, but it writes one additional byte to .lzma file:\r\n  0: - no filter\r\n  1: - x86(BCJ) filter.\r\n\r\nTo provide best compression ratio dictionarySize mustbe >= inSize\r\n\r\nLzmaRamEncode allocates Data with MyAlloc/BigAlloc functions.\r\nRAM Requirements:\r\n  RamSize = dictionarySize * 9.5 + 6MB + FilterBlockSize \r\n    FilterBlockSize = 0, if useFilter == false\r\n    FilterBlockSize = inSize, if useFilter == true\r\n\r\n  Return code:\r\n    0 - OK\r\n    1 - Unspecified Error\r\n    2 - Memory allocating error\r\n    3 - Output buffer OVERFLOW\r\n\r\nIf you use SZ_FILTER_AUTO mode, then encoder will use 2 or 3 passes:\r\n  2 passes when FILTER_NO provides better compression.\r\n  3 passes when FILTER_YES provides better compression.\r\n*/\r\n\r\nenum ESzFilterMode \r\n{\r\n  SZ_FILTER_NO,\r\n  SZ_FILTER_YES,\r\n  SZ_FILTER_AUTO\r\n};\r\n\r\nint LzmaRamEncode(\r\n    const Byte *inBuffer, size_t inSize, \r\n    Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, \r\n    UInt32 dictionarySize, ESzFilterMode filterMode);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.c",
    "content": "/* LzmaRamDecode.c */\r\n\r\n#include \"LzmaRamDecode.h\"\r\n#ifdef _SZ_ONE_DIRECTORY\r\n#include \"LzmaDecode.h\"\r\n#include \"BranchX86.h\"\r\n#else\r\n#include \"../LZMA_C/LzmaDecode.h\"\r\n#include \"../Branch/BranchX86.h\"\r\n#endif\r\n\r\n#define LZMA_PROPS_SIZE 14\r\n#define LZMA_SIZE_OFFSET 6\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize, \r\n    size_t *outSize)\r\n{\r\n  unsigned int i;\r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  *outSize = 0;\r\n  for(i = 0; i < sizeof(size_t); i++)\r\n    *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i);\r\n  for(; i < 8; i++)\r\n    if (inBuffer[LZMA_SIZE_OFFSET + i] != 0)\r\n      return 1;\r\n  return 0;\r\n}\r\n\r\n#define SZE_DATA_ERROR (1)\r\n#define SZE_OUTOFMEMORY (2)\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *))\r\n{\r\n  CLzmaDecoderState state;  /* it's about 24 bytes structure, if int is 32-bit */\r\n  int result;\r\n  SizeT outSizeProcessedLoc;\r\n  SizeT inProcessed;\r\n  int useFilter;\r\n  \r\n  if (inSize < LZMA_PROPS_SIZE)\r\n    return 1;\r\n  useFilter = inBuffer[0];\r\n\r\n  *outSizeProcessed = 0;\r\n  if (useFilter > 1)\r\n    return 1;\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return 1;\r\n  state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return SZE_OUTOFMEMORY;\r\n  \r\n  result = LzmaDecode(&state,\r\n    inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed,\r\n    outBuffer, (SizeT)outSize, &outSizeProcessedLoc);\r\n  freeFunc(state.Probs);\r\n  if (result != LZMA_RESULT_OK)\r\n    return 1;\r\n  *outSizeProcessed = (size_t)outSizeProcessedLoc;\r\n  if (useFilter == 1)\r\n  {\r\n    UInt32 _prevMask;\r\n    UInt32 _prevPos;\r\n    x86_Convert_Init(_prevMask, _prevPos);\r\n    x86_Convert(outBuffer, (UInt32)outSizeProcessedLoc, 0, &_prevMask, &_prevPos, 0);\r\n  }\r\n  return 0;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/LzmaRamDecode.h",
    "content": "/* LzmaRamDecode.h */\r\n\r\n#ifndef __LzmaRamDecode_h\r\n#define __LzmaRamDecode_h\r\n\r\n#include <stdlib.h>\r\n\r\n/*\r\nLzmaRamGetUncompressedSize:\r\n  In: \r\n    inBuffer - input data\r\n    inSize   - input data size\r\n  Out: \r\n    outSize  - uncompressed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers\r\n*/\r\n\r\nint LzmaRamGetUncompressedSize(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    size_t *outSize);\r\n\r\n\r\n/*\r\nLzmaRamDecompress:\r\n  In: \r\n    inBuffer  - input data\r\n    inSize    - input data size\r\n    outBuffer - output data\r\n    outSize   - output size\r\n    allocFunc - alloc function (can be malloc)\r\n    freeFunc  - free function (can be free)\r\n  Out: \r\n    outSizeProcessed - processed size\r\n  Return code:\r\n    0 - OK\r\n    1 - Error in headers / data stream\r\n    2 - Memory allocating error\r\n\r\nMemory requirements depend from properties of LZMA stream.\r\nWith default lzma settings it's about 16 KB.\r\n*/\r\n\r\nint LzmaRamDecompress(\r\n    const unsigned char *inBuffer, \r\n    size_t inSize,\r\n    unsigned char *outBuffer,\r\n    size_t outSize,\r\n    size_t *outSizeProcessed,\r\n    void * (*allocFunc)(size_t size), \r\n    void (*freeFunc)(void *));\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\r\n\r\n#include \"StdAfx.h\"\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/makefile",
    "content": "PROG = lzma.exe\r\nCFLAGS = $(CFLAGS) -I ../../../\r\nLIBS = $(LIBS) oleaut32.lib user32.lib\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nLZMA_OBJS = \\\r\n  $O\\LzmaAlone.obj \\\r\n  $O\\LzmaBench.obj \\\r\n  $O\\LzmaRam.obj \\\r\n\r\nLZMA_OPT_OBJS = \\\r\n  $O\\LZMADecoder.obj \\\r\n  $O\\LZMAEncoder.obj \\\r\n\r\nCOMMON_OBJS = \\\r\n  $O\\Alloc.obj \\\r\n  $O\\CRC.obj \\\r\n  $O\\CommandLineParser.obj \\\r\n  $O\\String.obj \\\r\n  $O\\StringConvert.obj \\\r\n  $O\\StringToInt.obj \\\r\n  $O\\Vector.obj\r\n\r\n7ZIP_COMMON_OBJS = \\\r\n  $O\\InBuffer.obj \\\r\n  $O\\OutBuffer.obj \\\r\n  $O\\StreamUtils.obj \\\r\n\r\nLZ_OBJS = \\\r\n  $O\\LZInWindow.obj \\\r\n  $O\\LZOutWindow.obj \\\r\n\r\n\r\nOBJS = \\\r\n  $(LZMA_OBJS) \\\r\n  $(LZMA_OPT_OBJS) \\\r\n  $(COMMON_OBJS) \\\r\n  $(7ZIP_COMMON_OBJS) \\\r\n  $(LZ_OBJS) \\\r\n  $O\\LzmaRamDecode.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n  $O\\FileStreams.obj \\\r\n  $O\\FileIO.obj \\\r\n  $O\\RangeCoderBit.obj \\\r\n  $O\\BranchX86.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$(LZMA_OBJS): $(*B).cpp\r\n\t$(COMPL)\r\n$(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp\r\n\t$(COMPL_O2)\r\n$(COMMON_OBJS): ../../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp\r\n\t$(COMPL)\r\n$(LZ_OBJS): ../LZ/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp\r\n\t$(COMPL)\r\n$O\\LzmaRamDecode.obj: LzmaRamDecode.c\r\n\t$(COMPL_O1)\r\n$O\\LzmaDecode.obj: ../LZMA_C/LzmaDecode.c\r\n\t$(COMPL_O2)\r\n$O\\BranchX86.obj: ../Branch/BranchX86.c\r\n\t$(COMPL_O2)\r\n$O\\FileStreams.obj: ../../Common/FileStreams.cpp\r\n\t$(COMPL)\r\n$O\\FileIO.obj: ../../../Windows/FileIO.cpp\r\n\t$(COMPL)\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Alone/makefile.gcc",
    "content": "PROG = lzma\r\nCXX = g++ -O2 -Wall\r\nCXX_C = gcc -O2 -Wall\r\nLIB = -lm\r\nRM = rm -f\r\nCFLAGS = -c -I ../../../\r\n\r\nOBJS = \\\r\n  LzmaAlone.o \\\r\n  LzmaBench.o \\\r\n  LzmaRam.o \\\r\n  LzmaRamDecode.o \\\r\n  LzmaDecode.o \\\r\n  BranchX86.o \\\r\n  LZMADecoder.o \\\r\n  LZMAEncoder.o \\\r\n  LZInWindow.o \\\r\n  LZOutWindow.o \\\r\n  RangeCoderBit.o \\\r\n  InBuffer.o \\\r\n  OutBuffer.o \\\r\n  FileStreams.o \\\r\n  StreamUtils.o \\\r\n  Alloc.o \\\r\n  C_FileIO.o \\\r\n  CommandLineParser.o \\\r\n  CRC.o \\\r\n  String.o \\\r\n  StringConvert.o \\\r\n  StringToInt.o \\\r\n  Vector.o \\\r\n\r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\nLzmaAlone.o: LzmaAlone.cpp\r\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\r\n\r\nLzmaBench.o: LzmaBench.cpp\r\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\r\n\r\nLzmaRam.o: LzmaRam.cpp\r\n\t$(CXX) $(CFLAGS) LzmaRam.cpp\r\n\r\nLzmaRamDecode.o: LzmaRamDecode.c\r\n\t$(CXX_C) $(CFLAGS) LzmaRamDecode.c\r\n\r\nLzmaDecode.o: ../LZMA_C/LzmaDecode.c\r\n\t$(CXX_C) $(CFLAGS) ../LZMA_C/LzmaDecode.c\r\n\r\nBranchX86.o: ../Branch/BranchX86.c\r\n\t$(CXX_C) $(CFLAGS) ../Branch/BranchX86.c\r\n\r\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\r\n\r\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\r\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\r\n\r\nLZInWindow.o: ../LZ/LZInWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp\r\n\r\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\r\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\r\n\r\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\r\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\r\n\r\nInBuffer.o: ../../Common/InBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\r\n\r\nOutBuffer.o: ../../Common/OutBuffer.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\r\n\r\nFileStreams.o: ../../Common/FileStreams.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\r\n\r\nStreamUtils.o: ../../Common/StreamUtils.cpp\r\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\r\n\r\nAlloc.o: ../../../Common/Alloc.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/Alloc.cpp\r\n\r\nC_FileIO.o: ../../../Common/C_FileIO.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp\r\n\r\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\r\n\r\nCRC.o: ../../../Common/CRC.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\r\n\r\nMyWindows.o: ../../../Common/MyWindows.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\r\n\r\nString.o: ../../../Common/String.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/String.cpp\r\n\r\nStringConvert.o: ../../../Common/StringConvert.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\r\n\r\nStringToInt.o: ../../../Common/StringToInt.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\r\n\r\nVector.o: ../../../Common/Vector.cpp\r\n\t$(CXX) $(CFLAGS) ../../../Common/Vector.cpp\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_C/LzmaDecode.c",
    "content": "/*\r\n  LzmaDecode.c\r\n  LZMA Decoder (optimized for Speed version)\r\n  \r\n  LZMA SDK 4.22 Copyright (c) 1999-2005 Igor Pavlov (2005-06-10)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#ifdef _LZMA_IN_CB\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) \\\r\n  { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \\\r\n  BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}\r\n\r\n#define RC_INIT Buffer = BufferLim = 0; RC_INIT2\r\n\r\n#else\r\n\r\n#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }\r\n\r\n#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2\r\n \r\n#endif\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  const Byte *Buffer = vs->Buffer;\r\n  const Byte *BufferLim = vs->BufferLim;\r\n  #else\r\n  const Byte *Buffer = inStream;\r\n  const Byte *BufferLim = inStream + inSize;\r\n  #endif\r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      #ifdef _LZMA_IN_CB\r\n      RC_INIT;\r\n      #else\r\n      RC_INIT(inStream, inSize);\r\n      #endif\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  RC_INIT;\r\n  #else\r\n  RC_INIT(inStream, inSize);\r\n  #endif\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (Byte)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n            UpdateBit0(prob);\r\n            \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            \r\n            state = state < kNumLitStates ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = Buffer;\r\n  vs->BufferLim = BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_C/LzmaDecode.h",
    "content": "/* \r\n  LzmaDecode.h\r\n  LZMA Decoder interface\r\n\r\n  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMADECODE_H\r\n#define __LZMADECODE_H\r\n\r\n/* #define _LZMA_IN_CB */\r\n/* Use callback for input data */\r\n\r\n/* #define _LZMA_OUT_READ */\r\n/* Use read function for output data */\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_LOC_OPT */\r\n/* Enable local speed optimizations inside code */\r\n\r\n/* #define _LZMA_SYSTEM_SIZE_T */\r\n/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/\r\n\r\n#ifndef UInt32\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\n#define UInt32 unsigned long\r\n#else\r\n#define UInt32 unsigned int\r\n#endif\r\n#endif\r\n\r\n#ifndef SizeT\r\n#ifdef _LZMA_SYSTEM_SIZE_T\r\n#include <stddef.h>\r\n#define SizeT size_t\r\n#else\r\n#define SizeT UInt32\r\n#endif\r\n#endif\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb unsigned short\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#ifdef _LZMA_IN_CB\r\ntypedef struct _ILzmaInCallback\r\n{\r\n  int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);\r\n} ILzmaInCallback;\r\n#endif\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  #ifdef _LZMA_OUT_READ\r\n  UInt32 DictionarySize;\r\n  #endif\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  const unsigned char *Buffer;\r\n  const unsigned char *BufferLim;\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  unsigned char *Dictionary;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;\r\n  unsigned char TempDictionary[4];\r\n  #endif\r\n} CLzmaDecoderState;\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }\r\n#endif\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *inCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_C/LzmaDecodeSize.c",
    "content": "/*\r\n  LzmaDecodeSize.c\r\n  LZMA Decoder (optimized for Size version)\r\n  \r\n  LZMA SDK 4.27 Copyright (c) 1999-2005 Igor Pavlov (2005-08-07)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\n#ifndef Byte\r\n#define Byte unsigned char\r\n#endif\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\ntypedef struct _CRangeDecoder\r\n{\r\n  const Byte *Buffer;\r\n  const Byte *BufferLim;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  #ifdef _LZMA_IN_CB\r\n  ILzmaInCallback *InCallback;\r\n  int Result;\r\n  #endif\r\n  int ExtraBytes;\r\n} CRangeDecoder;\r\n\r\nByte RangeDecoderReadByte(CRangeDecoder *rd)\r\n{\r\n  if (rd->Buffer == rd->BufferLim)\r\n  {\r\n    #ifdef _LZMA_IN_CB\r\n    SizeT size;\r\n    rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);\r\n    rd->BufferLim = rd->Buffer + size;\r\n    if (size == 0)\r\n    #endif\r\n    {\r\n      rd->ExtraBytes = 1;\r\n      return 0xFF;\r\n    }\r\n  }\r\n  return (*rd->Buffer++);\r\n}\r\n\r\n/* #define ReadByte (*rd->Buffer++) */\r\n#define ReadByte (RangeDecoderReadByte(rd))\r\n\r\nvoid RangeDecoderInit(CRangeDecoder *rd\r\n  #ifndef _LZMA_IN_CB\r\n    , const Byte *stream, SizeT bufferSize\r\n  #endif\r\n    )\r\n{\r\n  int i;\r\n  #ifdef _LZMA_IN_CB\r\n  rd->Buffer = rd->BufferLim = 0;\r\n  #else\r\n  rd->Buffer = stream;\r\n  rd->BufferLim = stream + bufferSize;\r\n  #endif\r\n  rd->ExtraBytes = 0;\r\n  rd->Code = 0;\r\n  rd->Range = (0xFFFFFFFF);\r\n  for(i = 0; i < 5; i++)\r\n    rd->Code = (rd->Code << 8) | ReadByte;\r\n}\r\n\r\n#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;        \r\n#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;\r\n#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }\r\n\r\nUInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)\r\n{\r\n  RC_INIT_VAR\r\n  UInt32 result = 0;\r\n  int i;\r\n  for (i = numTotalBits; i != 0; i--)\r\n  {\r\n    /* UInt32 t; */\r\n    range >>= 1;\r\n\r\n    result <<= 1;\r\n    if (code >= range)\r\n    {\r\n      code -= range;\r\n      result |= 1;\r\n    }\r\n    /*\r\n    t = (code - range) >> 31;\r\n    t &= 1;\r\n    code -= range & (t - 1);\r\n    result = (result + result) | (1 - t);\r\n    */\r\n    RC_NORMALIZE\r\n  }\r\n  RC_FLUSH_VAR\r\n  return result;\r\n}\r\n\r\nint RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)\r\n{\r\n  UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;\r\n  if (rd->Code < bound)\r\n  {\r\n    rd->Range = bound;\r\n    *prob += (kBitModelTotal - *prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 0;\r\n  }\r\n  else\r\n  {\r\n    rd->Range -= bound;\r\n    rd->Code -= bound;\r\n    *prob -= (*prob) >> kNumMoveBits;\r\n    if (rd->Range < kTopValue)\r\n    {\r\n      rd->Code = (rd->Code << 8) | ReadByte;\r\n      rd->Range <<= 8;\r\n    }\r\n    return 1;\r\n  }\r\n}\r\n\r\n#define RC_GET_BIT2(prob, mi, A0, A1) \\\r\n  UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \\\r\n  if (code < bound) \\\r\n    { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \\\r\n  else \\\r\n    { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)               \r\n\r\nint RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = numLevels; i != 0; i--)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT(prob, mi)\r\n    #else\r\n    mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return mi - (1 << numLevels);\r\n}\r\n\r\nint RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\r\n{\r\n  int mi = 1;\r\n  int i;\r\n  int symbol = 0;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  for(i = 0; i < numLevels; i++)\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + mi;\r\n    RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))\r\n    #else\r\n    int bit = RangeDecoderBitDecode(probs + mi, rd);\r\n    mi = mi + mi + bit;\r\n    symbol |= (bit << i);\r\n    #endif\r\n  }\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    #ifdef _LZMA_LOC_OPT\r\n    CProb *prob = probs + symbol;\r\n    RC_GET_BIT(prob, symbol)\r\n    #else\r\n    symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n    #endif\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\nByte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)\r\n{ \r\n  int symbol = 1;\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_INIT_VAR\r\n  #endif\r\n  do\r\n  {\r\n    int bit;\r\n    int matchBit = (matchByte >> 7) & 1;\r\n    matchByte <<= 1;\r\n    #ifdef _LZMA_LOC_OPT\r\n    {\r\n      CProb *prob = probs + 0x100 + (matchBit << 8) + symbol;\r\n      RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)\r\n    }\r\n    #else\r\n    bit = RangeDecoderBitDecode(probs + 0x100 + (matchBit << 8) + symbol, rd);\r\n    symbol = (symbol << 1) | bit;\r\n    #endif\r\n    if (matchBit != bit)\r\n    {\r\n      while (symbol < 0x100)\r\n      {\r\n        #ifdef _LZMA_LOC_OPT\r\n        CProb *prob = probs + symbol;\r\n        RC_GET_BIT(prob, symbol)\r\n        #else\r\n        symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\r\n        #endif\r\n      }\r\n      break;\r\n    }\r\n  }\r\n  while (symbol < 0x100);\r\n  #ifdef _LZMA_LOC_OPT\r\n  RC_FLUSH_VAR\r\n  #endif\r\n  return symbol;\r\n}\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\nint LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)\r\n{\r\n  if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)\r\n    return RangeDecoderBitTreeDecode(p + LenLow +\r\n        (posState << kLenNumLowBits), kLenNumLowBits, rd);\r\n  if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)\r\n    return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +\r\n        (posState << kLenNumMidBits), kLenNumMidBits, rd);\r\n  return kLenNumLowSymbols + kLenNumMidSymbols + \r\n      RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);\r\n}\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n  }\r\n  #endif\r\n  return LZMA_RESULT_OK;\r\n}\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    #ifdef _LZMA_IN_CB\r\n    ILzmaInCallback *InCallback,\r\n    #else\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    #endif\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)\r\n{\r\n  CProb *p = vs->Probs;\r\n  SizeT nowPos = 0;\r\n  Byte previousByte = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  CRangeDecoder rd;\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  \r\n  int state = vs->State;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  Byte *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  Byte tempDictionary[4];\r\n\r\n  rd.Range = vs->Range;\r\n  rd.Code = vs->Code;\r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  rd.Buffer = vs->Buffer;\r\n  rd.BufferLim = vs->BufferLim;\r\n  #else\r\n  rd.Buffer = inStream;\r\n  rd.BufferLim = inStream + inSize;\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RangeDecoderInit(&rd\r\n          #ifndef _LZMA_IN_CB\r\n          , inStream, inSize\r\n          #endif\r\n          );\r\n      #ifdef _LZMA_IN_CB\r\n      if (rd.Result != LZMA_RESULT_OK)\r\n        return rd.Result;\r\n      #endif\r\n      if (rd.ExtraBytes != 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  rd.Result = LZMA_RESULT_OK;\r\n  #endif\r\n  rd.ExtraBytes = 0;\r\n\r\n  #else /* if !_LZMA_OUT_READ */\r\n\r\n  int state = 0;\r\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\r\n  int len = 0;\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  *inSizeProcessed = 0;\r\n  #endif\r\n  *outSizeProcessed = 0;\r\n\r\n  {\r\n    UInt32 i;\r\n    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n    for (i = 0; i < numProbs; i++)\r\n      p[i] = kBitModelTotal >> 1;\r\n  }\r\n  \r\n  #ifdef _LZMA_IN_CB\r\n  rd.InCallback = InCallback;\r\n  #endif\r\n  RangeDecoderInit(&rd\r\n      #ifndef _LZMA_IN_CB\r\n      , inStream, inSize\r\n      #endif\r\n      );\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  if (rd.Result != LZMA_RESULT_OK)\r\n    return rd.Result;\r\n  #endif\r\n  if (rd.ExtraBytes != 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n\r\n  #endif /* _LZMA_OUT_READ */\r\n\r\n\r\n  while(nowPos < outSize)\r\n  {\r\n    int posState = (int)(\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & posStateMask);\r\n    #ifdef _LZMA_IN_CB\r\n    if (rd.Result != LZMA_RESULT_OK)\r\n      return rd.Result;\r\n    #endif\r\n    if (rd.ExtraBytes != 0)\r\n      return LZMA_RESULT_DATA_ERROR;\r\n    if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n    {\r\n      CProb *probs = p + Literal + (LZMA_LIT_SIZE * \r\n        (((\r\n        (nowPos \r\n        #ifdef _LZMA_OUT_READ\r\n        + globalPos\r\n        #endif\r\n        )\r\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        Byte matchByte;\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        #else\r\n        matchByte = outStream[nowPos - rep0];\r\n        #endif\r\n        previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);\r\n      }\r\n      else\r\n        previousByte = LzmaLiteralDecode(probs, &rd);\r\n      outStream[nowPos++] = previousByte;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      #endif\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)\r\n      {\r\n        if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)\r\n        {\r\n          if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)\r\n          {\r\n            #ifdef _LZMA_OUT_READ\r\n            UInt32 pos;\r\n            #endif\r\n      \r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit == 0)\r\n            #else\r\n            if (nowPos == 0)\r\n            #endif\r\n              return LZMA_RESULT_DATA_ERROR;\r\n\r\n            state = state < 7 ? 9 : 11;\r\n            #ifdef _LZMA_OUT_READ\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            #else\r\n            previousByte = outStream[nowPos - rep0];\r\n            #endif\r\n            outStream[nowPos++] = previousByte;\r\n\r\n            #ifdef _LZMA_OUT_READ\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            #endif\r\n            continue;\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)\r\n            distance = rep1;\r\n          else \r\n          {\r\n            if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)\r\n              distance = rep2;\r\n            else\r\n            {\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        len = LzmaLenDecode(p + RepLenCoder, &rd, posState);\r\n        state = state < 7 ? 8 : 11;\r\n      }\r\n      else\r\n      {\r\n        int posSlot;\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < 7 ? 7 : 10;\r\n        len = LzmaLenDecode(p + LenCoder, &rd, posState);\r\n        posSlot = RangeDecoderBitTreeDecode(p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits), kNumPosSlotBits, &rd);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 += RangeDecoderReverseBitTreeDecode(\r\n                p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);\r\n          }\r\n          else\r\n          {\r\n            rep0 += RangeDecoderDecodeDirectBits(&rd, \r\n                numDirectBits - kNumAlignBits) << kNumAlignBits;\r\n            rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      #ifdef _LZMA_OUT_READ\r\n      if (rep0 > distanceLimit) \r\n      #else\r\n      if (rep0 > nowPos)\r\n      #endif\r\n        return LZMA_RESULT_DATA_ERROR;\r\n\r\n      #ifdef _LZMA_OUT_READ\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n      #endif\r\n\r\n      do\r\n      {\r\n        #ifdef _LZMA_OUT_READ\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        #else\r\n        previousByte = outStream[nowPos - rep0];\r\n        #endif\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n  }\r\n\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  vs->Range = rd.Range;\r\n  vs->Code = rd.Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = globalPos + (UInt32)nowPos;\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n  #endif\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  vs->Buffer = rd.Buffer;\r\n  vs->BufferLim = rd.BufferLim;\r\n  #else\r\n  *inSizeProcessed = (SizeT)(rd.Buffer - inStream);\r\n  #endif\r\n  *outSizeProcessed = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_C/LzmaStateDecode.c",
    "content": "/*\r\n  LzmaStateDecode.c\r\n  LZMA Decoder (State version)\r\n  \r\n  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this Code, expressly permits you to \r\n  statically or dynamically link your Code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked Code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\n#define kNumTopBits 24\r\n#define kTopValue ((UInt32)1 << kNumTopBits)\r\n\r\n#define kNumBitModelTotalBits 11\r\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\r\n#define kNumMoveBits 5\r\n\r\n#define RC_READ_BYTE (*Buffer++)\r\n\r\n#define RC_INIT Code = 0; Range = 0xFFFFFFFF; \\\r\n  { int i; for(i = 0; i < 5; i++) { Code = (Code << 8) | RC_READ_BYTE; }}\r\n\r\n#define RC_NORMALIZE if (Range < kTopValue) { Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }\r\n\r\n#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)\r\n#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;\r\n#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;\r\n\r\n#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \\\r\n  { UpdateBit0(p); mi <<= 1; A0; } else \\\r\n  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } \r\n  \r\n#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               \r\n\r\n#define RangeDecoderBitTreeDecode(probs, numLevels, res) \\\r\n  { int i = numLevels; res = 1; \\\r\n  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \\\r\n  res -= (1 << numLevels); }\r\n\r\n\r\n#define kNumPosBitsMax 4\r\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\r\n\r\n#define kLenNumLowBits 3\r\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\r\n#define kLenNumMidBits 3\r\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\r\n#define kLenNumHighBits 8\r\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\r\n\r\n#define LenChoice 0\r\n#define LenChoice2 (LenChoice + 1)\r\n#define LenLow (LenChoice2 + 1)\r\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\r\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\r\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \r\n\r\n\r\n#define kNumStates 12\r\n#define kNumLitStates 7\r\n\r\n#define kStartPosModelIndex 4\r\n#define kEndPosModelIndex 14\r\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r\n\r\n#define kNumPosSlotBits 6\r\n#define kNumLenToPosStates 4\r\n\r\n#define kNumAlignBits 4\r\n#define kAlignTableSize (1 << kNumAlignBits)\r\n\r\n#define kMatchMinLen 2\r\n\r\n#define IsMatch 0\r\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\r\n#define IsRepG0 (IsRep + kNumStates)\r\n#define IsRepG1 (IsRepG0 + kNumStates)\r\n#define IsRepG2 (IsRepG1 + kNumStates)\r\n#define IsRep0Long (IsRepG2 + kNumStates)\r\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\r\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\r\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\r\n#define LenCoder (Align + kAlignTableSize)\r\n#define RepLenCoder (LenCoder + kNumLenProbs)\r\n#define Literal (RepLenCoder + kNumLenProbs)\r\n\r\n#if Literal != LZMA_BASE_SIZE\r\nStopCompilingDueBUG\r\n#endif\r\n\r\n/* kRequiredInBufferSize = number of required input bytes for worst case: \r\n   longest match with longest distance.\r\n   kLzmaInBufferSize must be larger than kRequiredInBufferSize \r\n   23 bits = 2 (match select) + 10 (len) + 6 (distance) + 4(align) + 1 (RC_NORMALIZE)\r\n*/\r\n\r\n#define kRequiredInBufferSize ((23 * (kNumBitModelTotalBits - kNumMoveBits + 1) + 26 + 9) / 8)\r\n\r\n#define kLzmaStreamWasFinishedId (-1)\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)\r\n{\r\n  unsigned char prop0;\r\n  if (size < LZMA_PROPERTIES_SIZE)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  prop0 = propsData[0];\r\n  if (prop0 >= (9 * 5 * 5))\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));\r\n    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);\r\n    propsRes->lc = prop0;\r\n    /*\r\n    unsigned char remainder = (unsigned char)(prop0 / 9);\r\n    propsRes->lc = prop0 % 9;\r\n    propsRes->pb = remainder / 5;\r\n    propsRes->lp = remainder % 5;\r\n    */\r\n  }\r\n\r\n  {\r\n    int i;\r\n    propsRes->DictionarySize = 0;\r\n    for (i = 0; i < 4; i++)\r\n      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);\r\n    if (propsRes->DictionarySize == 0)\r\n      propsRes->DictionarySize = 1;\r\n    return LZMA_RESULT_OK;\r\n  }\r\n}\r\n\r\nint LzmaDecode(\r\n    CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding)\r\n{\r\n  UInt32 Range = vs->Range;\r\n  UInt32 Code = vs->Code;\r\n\r\n  unsigned char *Buffer = vs->Buffer;\r\n  int BufferSize = vs->BufferSize; /* don't change it to unsigned int */\r\n  CProb *p = vs->Probs;\r\n\r\n  int state = vs->State;\r\n  unsigned char previousByte;\r\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\r\n  SizeT nowPos = 0;\r\n  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;\r\n  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;\r\n  int lc = vs->Properties.lc;\r\n  int len = vs->RemainLen;\r\n  UInt32 globalPos = vs->GlobalPos;\r\n  UInt32 distanceLimit = vs->DistanceLimit;\r\n\r\n  unsigned char *dictionary = vs->Dictionary;\r\n  UInt32 dictionarySize = vs->Properties.DictionarySize;\r\n  UInt32 dictionaryPos = vs->DictionaryPos;\r\n\r\n  unsigned char tempDictionary[4];\r\n\r\n  (*inSizeProcessed) = 0;\r\n  (*outSizeProcessed) = 0;\r\n  if (len == kLzmaStreamWasFinishedId)\r\n    return LZMA_RESULT_OK;\r\n\r\n  if (dictionarySize == 0)\r\n  {\r\n    dictionary = tempDictionary;\r\n    dictionarySize = 1;\r\n    tempDictionary[0] = vs->TempDictionary[0];\r\n  }\r\n\r\n  if (len == kLzmaNeedInitId)\r\n  {\r\n    while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n    {\r\n      Buffer[BufferSize++] = *inStream++;\r\n      (*inSizeProcessed)++;\r\n      inSize--;\r\n    }\r\n    if (BufferSize < 5)\r\n    {\r\n      vs->BufferSize = BufferSize;\r\n      return finishDecoding ? LZMA_RESULT_DATA_ERROR : LZMA_RESULT_OK;\r\n    }\r\n    {\r\n      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));\r\n      UInt32 i;\r\n      for (i = 0; i < numProbs; i++)\r\n        p[i] = kBitModelTotal >> 1; \r\n      rep0 = rep1 = rep2 = rep3 = 1;\r\n      state = 0;\r\n      globalPos = 0;\r\n      distanceLimit = 0;\r\n      dictionaryPos = 0;\r\n      dictionary[dictionarySize - 1] = 0;\r\n      RC_INIT;\r\n    }\r\n    len = 0;\r\n  }\r\n  while(len != 0 && nowPos < outSize)\r\n  {\r\n    UInt32 pos = dictionaryPos - rep0;\r\n    if (pos >= dictionarySize)\r\n      pos += dictionarySize;\r\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\r\n    if (++dictionaryPos == dictionarySize)\r\n      dictionaryPos = 0;\r\n    len--;\r\n  }\r\n  if (dictionaryPos == 0)\r\n    previousByte = dictionary[dictionarySize - 1];\r\n  else\r\n    previousByte = dictionary[dictionaryPos - 1];\r\n\r\n  while(1)\r\n  {\r\n    int bufferPos = (int)(Buffer - vs->Buffer);\r\n    if (BufferSize - bufferPos < kRequiredInBufferSize)\r\n    {\r\n      int i;\r\n      BufferSize -= bufferPos;\r\n      if (BufferSize < 0)\r\n        return LZMA_RESULT_DATA_ERROR;\r\n      for (i = 0; i < BufferSize; i++)\r\n        vs->Buffer[i] = Buffer[i];\r\n      Buffer = vs->Buffer;\r\n      while (inSize > 0 && BufferSize < kLzmaInBufferSize)\r\n      {\r\n        Buffer[BufferSize++] = *inStream++;\r\n        (*inSizeProcessed)++;\r\n        inSize--;\r\n      }\r\n      if (BufferSize < kRequiredInBufferSize && !finishDecoding)\r\n        break;\r\n    }\r\n    if (nowPos >= outSize)\r\n      break;\r\n    {\r\n    CProb *prob;\r\n    UInt32 bound;\r\n    int posState = (int)((nowPos + globalPos) & posStateMask);\r\n\r\n    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;\r\n    IfBit0(prob)\r\n    {\r\n      int symbol = 1;\r\n      UpdateBit0(prob)\r\n      prob = p + Literal + (LZMA_LIT_SIZE * \r\n        ((((nowPos + globalPos)& literalPosMask) << lc) + (previousByte >> (8 - lc))));\r\n\r\n      if (state >= kNumLitStates)\r\n      {\r\n        int matchByte;\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        matchByte = dictionary[pos];\r\n        do\r\n        {\r\n          int bit;\r\n          CProb *probLit;\r\n          matchByte <<= 1;\r\n          bit = (matchByte & 0x100);\r\n          probLit = prob + 0x100 + bit + symbol;\r\n          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)\r\n        }\r\n        while (symbol < 0x100);\r\n      }\r\n      while (symbol < 0x100)\r\n      {\r\n        CProb *probLit = prob + symbol;\r\n        RC_GET_BIT(probLit, symbol)\r\n      }\r\n      previousByte = (unsigned char)symbol;\r\n\r\n      outStream[nowPos++] = previousByte;\r\n      if (distanceLimit < dictionarySize)\r\n        distanceLimit++;\r\n\r\n      dictionary[dictionaryPos] = previousByte;\r\n      if (++dictionaryPos == dictionarySize)\r\n        dictionaryPos = 0;\r\n      if (state < 4) state = 0;\r\n      else if (state < 10) state -= 3;\r\n      else state -= 6;\r\n    }\r\n    else             \r\n    {\r\n      UpdateBit1(prob);\r\n      prob = p + IsRep + state;\r\n      IfBit0(prob)\r\n      {\r\n        UpdateBit0(prob);\r\n        rep3 = rep2;\r\n        rep2 = rep1;\r\n        rep1 = rep0;\r\n        state = state < kNumLitStates ? 0 : 3;\r\n        prob = p + LenCoder;\r\n      }\r\n      else\r\n      {\r\n        UpdateBit1(prob);\r\n        prob = p + IsRepG0 + state;\r\n        IfBit0(prob)\r\n        {\r\n          UpdateBit0(prob);\r\n          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;\r\n          IfBit0(prob)\r\n          {\r\n            UInt32 pos;\r\n            UpdateBit0(prob);\r\n            if (distanceLimit == 0)\r\n              return LZMA_RESULT_DATA_ERROR;\r\n            if (distanceLimit < dictionarySize)\r\n              distanceLimit++;\r\n            state = state < kNumLitStates ? 9 : 11;\r\n            pos = dictionaryPos - rep0;\r\n            if (pos >= dictionarySize)\r\n              pos += dictionarySize;\r\n            previousByte = dictionary[pos];\r\n            dictionary[dictionaryPos] = previousByte;\r\n            if (++dictionaryPos == dictionarySize)\r\n              dictionaryPos = 0;\r\n            outStream[nowPos++] = previousByte;\r\n            continue;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(prob);\r\n          }\r\n        }\r\n        else\r\n        {\r\n          UInt32 distance;\r\n          UpdateBit1(prob);\r\n          prob = p + IsRepG1 + state;\r\n          IfBit0(prob)\r\n          {\r\n            UpdateBit0(prob);\r\n            distance = rep1;\r\n          }\r\n          else \r\n          {\r\n            UpdateBit1(prob);\r\n            prob = p + IsRepG2 + state;\r\n            IfBit0(prob)\r\n            {\r\n              UpdateBit0(prob);\r\n              distance = rep2;\r\n            }\r\n            else\r\n            {\r\n              UpdateBit1(prob);\r\n              distance = rep3;\r\n              rep3 = rep2;\r\n            }\r\n            rep2 = rep1;\r\n          }\r\n          rep1 = rep0;\r\n          rep0 = distance;\r\n        }\r\n        state = state < kNumLitStates ? 8 : 11;\r\n        prob = p + RepLenCoder;\r\n      }\r\n      {\r\n        int numBits, offset;\r\n        CProb *probLen = prob + LenChoice;\r\n        IfBit0(probLen)\r\n        {\r\n          UpdateBit0(probLen);\r\n          probLen = prob + LenLow + (posState << kLenNumLowBits);\r\n          offset = 0;\r\n          numBits = kLenNumLowBits;\r\n        }\r\n        else\r\n        {\r\n          UpdateBit1(probLen);\r\n          probLen = prob + LenChoice2;\r\n          IfBit0(probLen)\r\n          {\r\n            UpdateBit0(probLen);\r\n            probLen = prob + LenMid + (posState << kLenNumMidBits);\r\n            offset = kLenNumLowSymbols;\r\n            numBits = kLenNumMidBits;\r\n          }\r\n          else\r\n          {\r\n            UpdateBit1(probLen);\r\n            probLen = prob + LenHigh;\r\n            offset = kLenNumLowSymbols + kLenNumMidSymbols;\r\n            numBits = kLenNumHighBits;\r\n          }\r\n        }\r\n        RangeDecoderBitTreeDecode(probLen, numBits, len);\r\n        len += offset;\r\n      }\r\n\r\n      if (state < 4)\r\n      {\r\n        int posSlot;\r\n        state += kNumLitStates;\r\n        prob = p + PosSlot +\r\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \r\n            kNumPosSlotBits);\r\n        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);\r\n        if (posSlot >= kStartPosModelIndex)\r\n        {\r\n          int numDirectBits = ((posSlot >> 1) - 1);\r\n          rep0 = (2 | ((UInt32)posSlot & 1));\r\n          if (posSlot < kEndPosModelIndex)\r\n          {\r\n            rep0 <<= numDirectBits;\r\n            prob = p + SpecPos + rep0 - posSlot - 1;\r\n          }\r\n          else\r\n          {\r\n            numDirectBits -= kNumAlignBits;\r\n            do\r\n            {\r\n              RC_NORMALIZE\r\n              Range >>= 1;\r\n              rep0 <<= 1;\r\n              if (Code >= Range)\r\n              {\r\n                Code -= Range;\r\n                rep0 |= 1;\r\n              }\r\n            }\r\n            while (--numDirectBits != 0);\r\n            prob = p + Align;\r\n            rep0 <<= kNumAlignBits;\r\n            numDirectBits = kNumAlignBits;\r\n          }\r\n          {\r\n            int i = 1;\r\n            int mi = 1;\r\n            do\r\n            {\r\n              CProb *prob3 = prob + mi;\r\n              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);\r\n              i <<= 1;\r\n            }\r\n            while(--numDirectBits != 0);\r\n          }\r\n        }\r\n        else\r\n          rep0 = posSlot;\r\n        if (++rep0 == (UInt32)(0))\r\n        {\r\n          /* it's for stream version */\r\n          len = kLzmaStreamWasFinishedId;\r\n          break;\r\n        }\r\n      }\r\n\r\n      len += kMatchMinLen;\r\n      if (rep0 > distanceLimit) \r\n        return LZMA_RESULT_DATA_ERROR;\r\n      if (dictionarySize - distanceLimit > (UInt32)len)\r\n        distanceLimit += len;\r\n      else\r\n        distanceLimit = dictionarySize;\r\n\r\n      do\r\n      {\r\n        UInt32 pos = dictionaryPos - rep0;\r\n        if (pos >= dictionarySize)\r\n          pos += dictionarySize;\r\n        previousByte = dictionary[pos];\r\n        dictionary[dictionaryPos] = previousByte;\r\n        if (++dictionaryPos == dictionarySize)\r\n          dictionaryPos = 0;\r\n        len--;\r\n        outStream[nowPos++] = previousByte;\r\n      }\r\n      while(len != 0 && nowPos < outSize);\r\n    }\r\n    }\r\n  }\r\n  RC_NORMALIZE;\r\n\r\n  BufferSize -= (int)(Buffer - vs->Buffer);\r\n  if (BufferSize < 0)\r\n    return LZMA_RESULT_DATA_ERROR;\r\n  {\r\n    int i;\r\n    for (i = 0; i < BufferSize; i++)\r\n      vs->Buffer[i] = Buffer[i];\r\n  }\r\n  vs->BufferSize = BufferSize;\r\n  vs->Range = Range;\r\n  vs->Code = Code;\r\n  vs->DictionaryPos = dictionaryPos;\r\n  vs->GlobalPos = (UInt32)(globalPos + nowPos);\r\n  vs->DistanceLimit = distanceLimit;\r\n  vs->Reps[0] = rep0;\r\n  vs->Reps[1] = rep1;\r\n  vs->Reps[2] = rep2;\r\n  vs->Reps[3] = rep3;\r\n  vs->State = state;\r\n  vs->RemainLen = len;\r\n  vs->TempDictionary[0] = tempDictionary[0];\r\n\r\n  (*outSizeProcessed) = nowPos;\r\n  return LZMA_RESULT_OK;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_C/LzmaStateDecode.h",
    "content": "/* \r\n  LzmaStateDecode.h\r\n  LZMA Decoder interface (State version)\r\n\r\n  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)\r\n  http://www.7-zip.org/\r\n\r\n  LZMA SDK is licensed under two licenses:\r\n  1) GNU Lesser General Public License (GNU LGPL)\r\n  2) Common Public License (CPL)\r\n  It means that you can select one of these two licenses and \r\n  follow rules of that license.\r\n\r\n  SPECIAL EXCEPTION:\r\n  Igor Pavlov, as the author of this code, expressly permits you to \r\n  statically or dynamically link your code (or bind by name) to the \r\n  interfaces of this file without subjecting your linked code to the \r\n  terms of the CPL or GNU LGPL. Any modifications or additions \r\n  to this file, however, are subject to the LGPL or CPL terms.\r\n*/\r\n\r\n#ifndef __LZMASTATEDECODE_H\r\n#define __LZMASTATEDECODE_H\r\n\r\n/* #define _LZMA_PROB32 */\r\n/* It can increase speed on some 32-bit CPUs, \r\n   but memory usage will be doubled in that case */\r\n\r\n/* #define _LZMA_SYSTEM_SIZE_T */\r\n/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/\r\n\r\n\r\n#ifndef UInt32\r\n#ifdef _LZMA_UINT32_IS_ULONG\r\n#define UInt32 unsigned long\r\n#else\r\n#define UInt32 unsigned int\r\n#endif\r\n#endif\r\n\r\n#ifndef SizeT\r\n#ifdef _LZMA_SYSTEM_SIZE_T\r\n#include <stddef.h>\r\n#define SizeT size_t\r\n#else\r\n#define SizeT UInt32\r\n#endif\r\n#endif\r\n\r\n#ifdef _LZMA_PROB32\r\n#define CProb UInt32\r\n#else\r\n#define CProb unsigned short\r\n#endif\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\n#define LZMA_BASE_SIZE 1846\r\n#define LZMA_LIT_SIZE 768\r\n\r\n#define LZMA_PROPERTIES_SIZE 5\r\n\r\ntypedef struct _CLzmaProperties\r\n{\r\n  int lc;\r\n  int lp;\r\n  int pb;\r\n  UInt32 DictionarySize;\r\n}CLzmaProperties;\r\n\r\nint LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);\r\n\r\n#define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))\r\n\r\n#define kLzmaInBufferSize 64   /* don't change it. it must be larger than kRequiredInBufferSize */\r\n\r\n#define kLzmaNeedInitId (-2)\r\n\r\ntypedef struct _CLzmaDecoderState\r\n{\r\n  CLzmaProperties Properties;\r\n  CProb *Probs;\r\n  unsigned char *Dictionary;\r\n\r\n  unsigned char Buffer[kLzmaInBufferSize];\r\n  int BufferSize;\r\n\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  UInt32 DictionaryPos;\r\n  UInt32 GlobalPos;\r\n  UInt32 DistanceLimit;\r\n  UInt32 Reps[4];\r\n  int State;\r\n  int RemainLen;  /* -2: decoder needs internal initialization\r\n                     -1: stream was finished, \r\n                      0: ok\r\n                    > 0: need to write RemainLen bytes as match Reps[0],\r\n                  */\r\n  unsigned char TempDictionary[4];  /* it's required when DictionarySize = 0 */\r\n} CLzmaDecoderState;\r\n\r\n#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }\r\n\r\n/* LzmaDecode: decoding from input stream to output stream.\r\n  If finishDecoding != 0, then there are no more bytes in input stream\r\n  after inStream[inSize - 1]. */\r\n\r\nint LzmaDecode(CLzmaDecoderState *vs,\r\n    const unsigned char *inStream, SizeT inSize,  SizeT *inSizeProcessed,\r\n    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,\r\n    int finishDecoding);\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_C/LzmaStateTest.c",
    "content": "/* \r\nLzmaStateTest.c\r\nTest application for LZMA Decoder (State version)\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-02)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaStateDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\n#define kInBufferSize (1 << 15)\r\n#define kOutBufferSize (1 << 15)\r\n\r\nunsigned char g_InBuffer[kInBufferSize];\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n  { return fread(data, 1, size, file); }\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size); }\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0; \r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  int i;\r\n  int res = 0;\r\n  CLzmaDecoderState state;  /* it's about 140 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n  SizeT inAvail = 0;\r\n  unsigned char *inBuffer = 0;\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n  \r\n  for (i = 0; i < 8; i++)\r\n  {\r\n    unsigned char b;\r\n    if (!MyReadFileAndCheck(inFile, &b, 1))\r\n      return PrintError(rs, kCantReadMessage);\r\n    if (b != 0xFF)\r\n      waitEOS = 0;\r\n    if (i < 4)\r\n      outSize += (UInt32)(b) << (i * 8);\r\n    else\r\n      outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  \r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n  {\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n    if (state.Dictionary == 0)\r\n    {\r\n      free(state.Probs);\r\n      return PrintError(rs, kCantAllocateMessage);\r\n    }\r\n  }\r\n  \r\n  /* Decompress */\r\n  \r\n  LzmaDecoderInit(&state);\r\n  \r\n  do\r\n  {\r\n    SizeT inProcessed, outProcessed;\r\n    int finishDecoding;\r\n    UInt32 outAvail = kOutBufferSize;\r\n    if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n      outAvail = outSize;\r\n    if (inAvail == 0)\r\n    {\r\n      inAvail = (SizeT)MyReadFile(inFile, g_InBuffer, kInBufferSize);\r\n      inBuffer = g_InBuffer;\r\n    }\r\n    finishDecoding = (inAvail == 0);\r\n    res = LzmaDecode(&state,\r\n        inBuffer, inAvail, &inProcessed,\r\n        g_OutBuffer, outAvail, &outProcessed,\r\n        finishDecoding);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n      break;\r\n    }\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n    \r\n    if (outFile != 0)  \r\n      if (fwrite(g_OutBuffer, 1, outProcessed, outFile) != outProcessed)\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n        break;\r\n      }\r\n      \r\n    if (outSize < outProcessed)\r\n      outSizeHigh--;\r\n    outSize -= (UInt32)outProcessed;\r\n    outSize &= 0xFFFFFFFF;\r\n\r\n    if (outProcessed == 0 && finishDecoding)\r\n    {\r\n      if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n        res = 1;\r\n      break;\r\n    }\r\n  }\r\n  while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n\r\n  free(state.Dictionary);\r\n  free(state.Probs);\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-02\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_C/LzmaTest.c",
    "content": "/* \r\nLzmaTest.c\r\nTest application for LZMA Decoder\r\n\r\nThis file written and distributed to public domain by Igor Pavlov.\r\nThis file is part of LZMA SDK 4.26 (2005-08-05)\r\n*/\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <string.h>\r\n\r\n#include \"LzmaDecode.h\"\r\n\r\nconst char *kCantReadMessage = \"Can not read input file\";\r\nconst char *kCantWriteMessage = \"Can not write output file\";\r\nconst char *kCantAllocateMessage = \"Can not allocate memory\";\r\n\r\nsize_t MyReadFile(FILE *file, void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fread(data, 1, size, file); \r\n}\r\n\r\nint MyReadFileAndCheck(FILE *file, void *data, size_t size)\r\n  { return (MyReadFile(file, data, size) == size);} \r\n\r\nsize_t MyWriteFile(FILE *file, const void *data, size_t size)\r\n{ \r\n  if (size == 0)\r\n    return 0;\r\n  return fwrite(data, 1, size, file); \r\n}\r\n\r\nint MyWriteFileAndCheck(FILE *file, const void *data, size_t size)\r\n  { return (MyWriteFile(file, data, size) == size); }\r\n\r\n#ifdef _LZMA_IN_CB\r\n#define kInBufferSize (1 << 15)\r\ntypedef struct _CBuffer\r\n{\r\n  ILzmaInCallback InCallback;\r\n  FILE *File;\r\n  unsigned char Buffer[kInBufferSize];\r\n} CBuffer;\r\n\r\nint LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n{\r\n  CBuffer *b = (CBuffer *)object;\r\n  *buffer = b->Buffer;\r\n  *size = (SizeT)MyReadFile(b->File, b->Buffer, kInBufferSize);\r\n  return LZMA_RESULT_OK;\r\n}\r\nCBuffer g_InBuffer;\r\n\r\n#endif\r\n\r\n#ifdef _LZMA_OUT_READ\r\n#define kOutBufferSize (1 << 15)\r\nunsigned char g_OutBuffer[kOutBufferSize];\r\n#endif\r\n\r\nint PrintError(char *buffer, const char *message)\r\n{\r\n  sprintf(buffer + strlen(buffer), \"\\nError: \");\r\n  sprintf(buffer + strlen(buffer), message);\r\n  return 1;\r\n}\r\n\r\nint main3(FILE *inFile, FILE *outFile, char *rs)\r\n{\r\n  /* We use two 32-bit integers to construct 64-bit integer for file size.\r\n     You can remove outSizeHigh, if you don't need >= 4GB supporting,\r\n     or you can use UInt64 outSize, if your compiler supports 64-bit integers*/\r\n  UInt32 outSize = 0;\r\n  UInt32 outSizeHigh = 0;\r\n  #ifndef _LZMA_OUT_READ\r\n  SizeT outSizeFull;\r\n  unsigned char *outStream;\r\n  #endif\r\n  \r\n  int waitEOS = 1; \r\n  /* waitEOS = 1, if there is no uncompressed size in headers, \r\n   so decoder will wait EOS (End of Stream Marker) in compressed stream */\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  SizeT compressedSize;\r\n  unsigned char *inStream;\r\n  #endif\r\n\r\n  CLzmaDecoderState state;  /* it's about 24-80 bytes structure, if int is 32-bit */\r\n  unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n  int res;\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.File = inFile;\r\n  #endif\r\n\r\n  if (sizeof(UInt32) < 4)\r\n    return PrintError(rs, \"LZMA decoder needs correct UInt32\");\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  {\r\n    long length;\r\n    fseek(inFile, 0, SEEK_END);\r\n    length = ftell(inFile);\r\n    fseek(inFile, 0, SEEK_SET);\r\n    if ((long)(SizeT)length != length)\r\n      return PrintError(rs, \"Too big compressed stream\");\r\n    compressedSize = (SizeT)(length - (LZMA_PROPERTIES_SIZE + 8));\r\n  }\r\n  #endif\r\n\r\n  /* Read LZMA properties for compressed stream */\r\n\r\n  if (!MyReadFileAndCheck(inFile, properties, sizeof(properties)))\r\n    return PrintError(rs, kCantReadMessage);\r\n\r\n  /* Read uncompressed size */\r\n\r\n  {\r\n    int i;\r\n    for (i = 0; i < 8; i++)\r\n    {\r\n      unsigned char b;\r\n      if (!MyReadFileAndCheck(inFile, &b, 1))\r\n        return PrintError(rs, kCantReadMessage);\r\n      if (b != 0xFF)\r\n        waitEOS = 0;\r\n      if (i < 4)\r\n        outSize += (UInt32)(b) << (i * 8);\r\n      else\r\n        outSizeHigh += (UInt32)(b) << ((i - 4) * 8);\r\n    }\r\n    \r\n    #ifndef _LZMA_OUT_READ\r\n    if (waitEOS)\r\n      return PrintError(rs, \"Stream with EOS marker is not supported\");\r\n    outSizeFull = (SizeT)outSize;\r\n    if (sizeof(SizeT) >= 8)\r\n      outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);\r\n    else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)\r\n      return PrintError(rs, \"Too big uncompressed stream\");\r\n    #endif\r\n  }\r\n\r\n  /* Decode LZMA properties and allocate memory */\r\n  \r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  if (state.Properties.DictionarySize == 0)\r\n    state.Dictionary = 0;\r\n  else\r\n    state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n  #else\r\n  if (outSizeFull == 0)\r\n    outStream = 0;\r\n  else\r\n    outStream = (unsigned char *)malloc(outSizeFull);\r\n  #endif\r\n\r\n  #ifndef _LZMA_IN_CB\r\n  if (compressedSize == 0)\r\n    inStream = 0;\r\n  else\r\n    inStream = (unsigned char *)malloc(compressedSize);\r\n  #endif\r\n\r\n  if (state.Probs == 0 \r\n    #ifdef _LZMA_OUT_READ\r\n    || (state.Dictionary == 0 && state.Properties.DictionarySize != 0)\r\n    #else\r\n    || (outStream == 0 && outSizeFull != 0)\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    || (inStream == 0 && compressedSize != 0)\r\n    #endif\r\n    )\r\n  {\r\n    free(state.Probs);\r\n    #ifdef _LZMA_OUT_READ\r\n    free(state.Dictionary);\r\n    #else\r\n    free(outStream);\r\n    #endif\r\n    #ifndef _LZMA_IN_CB\r\n    free(inStream);\r\n    #endif\r\n    return PrintError(rs, kCantAllocateMessage);\r\n  }\r\n\r\n  /* Decompress */\r\n\r\n  #ifdef _LZMA_IN_CB\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  #else\r\n  if (!MyReadFileAndCheck(inFile, inStream, compressedSize))\r\n    return PrintError(rs, kCantReadMessage);\r\n  #endif\r\n\r\n  #ifdef _LZMA_OUT_READ\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inAvail = compressedSize;\r\n    const unsigned char *inBuffer = inStream;\r\n    #endif\r\n    LzmaDecoderInit(&state);\r\n    do\r\n    {\r\n      #ifndef _LZMA_IN_CB\r\n      SizeT inProcessed;\r\n      #endif\r\n      SizeT outProcessed;\r\n      SizeT outAvail = kOutBufferSize;\r\n      if (!waitEOS && outSizeHigh == 0 && outAvail > outSize)\r\n        outAvail = (SizeT)outSize;\r\n      res = LzmaDecode(&state,\r\n        #ifdef _LZMA_IN_CB\r\n        &g_InBuffer.InCallback,\r\n        #else\r\n        inBuffer, inAvail, &inProcessed,\r\n        #endif\r\n        g_OutBuffer, outAvail, &outProcessed);\r\n      if (res != 0)\r\n      {\r\n        sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n        res = 1;\r\n        break;\r\n      }\r\n      #ifndef _LZMA_IN_CB\r\n      inAvail -= inProcessed;\r\n      inBuffer += inProcessed;\r\n      #endif\r\n      \r\n      if (outFile != 0)  \r\n        if (!MyWriteFileAndCheck(outFile, g_OutBuffer, (size_t)outProcessed))\r\n        {\r\n          PrintError(rs, kCantWriteMessage);\r\n          res = 1;\r\n          break;\r\n        }\r\n        \r\n      if (outSize < outProcessed)\r\n        outSizeHigh--;\r\n      outSize -= (UInt32)outProcessed;\r\n      outSize &= 0xFFFFFFFF;\r\n        \r\n      if (outProcessed == 0)\r\n      {\r\n        if (!waitEOS && (outSize != 0 || outSizeHigh != 0))\r\n          res = 1;\r\n        break;\r\n      }\r\n    }\r\n    while ((outSize != 0 && outSizeHigh == 0) || outSizeHigh != 0  || waitEOS);\r\n  }\r\n\r\n  #else\r\n  {\r\n    #ifndef _LZMA_IN_CB\r\n    SizeT inProcessed;\r\n    #endif\r\n    SizeT outProcessed;\r\n    res = LzmaDecode(&state,\r\n      #ifdef _LZMA_IN_CB\r\n      &g_InBuffer.InCallback,\r\n      #else\r\n      inStream, compressedSize, &inProcessed,\r\n      #endif\r\n      outStream, outSizeFull, &outProcessed);\r\n    if (res != 0)\r\n    {\r\n      sprintf(rs + strlen(rs), \"\\nDecoding error = %d\\n\", res);\r\n      res = 1;\r\n    }\r\n    else if (outFile != 0)\r\n    {\r\n      if (!MyWriteFileAndCheck(outFile, outStream, (size_t)outProcessed))\r\n      {\r\n        PrintError(rs, kCantWriteMessage);\r\n        res = 1;\r\n      }\r\n    }\r\n  }\r\n  #endif\r\n\r\n  free(state.Probs);\r\n  #ifdef _LZMA_OUT_READ\r\n  free(state.Dictionary);\r\n  #else\r\n  free(outStream);\r\n  #endif\r\n  #ifndef _LZMA_IN_CB\r\n  free(inStream);\r\n  #endif\r\n  return res;\r\n}\r\n\r\nint main2(int numArgs, const char *args[], char *rs)\r\n{\r\n  FILE *inFile = 0;\r\n  FILE *outFile = 0;\r\n  int res;\r\n\r\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov  2005-08-05\\n\");\r\n  if (numArgs < 2 || numArgs > 3)\r\n  {\r\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmadec file.lzma [outFile]\\n\");\r\n    return 1;\r\n  }\r\n\r\n  inFile = fopen(args[1], \"rb\");\r\n  if (inFile == 0)\r\n    return PrintError(rs, \"Can not open input file\");\r\n\r\n  if (numArgs > 2)\r\n  {\r\n    outFile = fopen(args[2], \"wb+\");\r\n    if (outFile == 0)\r\n      return PrintError(rs, \"Can not open output file\");\r\n  }\r\n\r\n  res = main3(inFile, outFile, rs);\r\n\r\n  if (outFile != 0)\r\n    fclose(outFile);\r\n  fclose(inFile);\r\n  return res;\r\n}\r\n\r\nint main(int numArgs, const char *args[])\r\n{\r\n  char rs[800] = { 0 };\r\n  int res = main2(numArgs, args, rs);\r\n  printf(rs);\r\n  return res;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_C/makefile",
    "content": "PROG = lzmaDec.exe\r\n\r\n!IFNDEF O\r\n!IFDEF CPU\r\nO=$(CPU)\r\n!ELSE\r\nO=O\r\n!ENDIF\r\n!ENDIF\r\n\r\nCFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -GS- \r\nCFLAGS_O1 = $(CFLAGS) -O1\r\nCFLAGS_O2 = $(CFLAGS) -O2\r\n\r\nLFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98\r\n\r\nPROGPATH = $O\\$(PROG)\r\n\r\nCOMPL_O1   = $(CPP) $(CFLAGS_O1) $**\r\nCOMPL_O2   = $(CPP) $(CFLAGS_O2) $**\r\nCOMPL      = $(CPP) $(CFLAGS_O1) $**\r\n\r\n\r\nOBJS = \\\r\n  $O\\LzmaTest.obj \\\r\n  $O\\LzmaDecode.obj \\\r\n\r\nall: $(PROGPATH) \r\n\r\nclean:\r\n\t-del /Q $(PROGPATH) $O\\*.exe $O\\*.dll $O\\*.obj $O\\*.lib $O\\*.exp $O\\*.res $O\\*.pch \r\n\r\n$O:\r\n\tif not exist \"$O\" mkdir \"$O\"\r\n\r\n$(PROGPATH): $O $(OBJS)\r\n\tlink $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)\r\n\r\n\r\n$O\\LzmaTest.obj: $(*B).c\r\n\t$(COMPL)\r\n$O\\LzmaDecode.obj: ../../Compress/LZMA_C/$(*B).c\r\n\t$(COMPL_O2)\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_C/makefile.gcc",
    "content": "PROG = lzmadec\r\nCXX = gcc \r\nLIB = \r\nRM = rm -f\r\nCFLAGS = -c -O2 -Wall -pedantic -D _LZMA_PROB32 \r\n\r\nOBJS = LzmaTest.o LzmaDecode.o \r\n\r\nall: $(PROG)\r\n\r\n$(PROG): $(OBJS)\r\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\r\n\r\nLzmaTest.o: LzmaTest.c\r\n\t$(CXX) $(CFLAGS) LzmaTest.c\r\n\r\nLzmaDecode.o: LzmaDecode.c\r\n\t$(CXX) $(CFLAGS) LzmaDecode.c\r\n\r\n\r\nclean:\r\n\t-$(RM) $(PROG) $(OBJS)\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Lib/ZLib.cpp",
    "content": "/*\r\n * lzma zlib simplified wrapper\r\n *\r\n * Copyright (c) 2005-2006 Oleg I. Vdovikin <oleg@cs.msu.su>\r\n *\r\n * This library is free software; you can redistribute \r\n * it and/or modify it under the terms of the GNU Lesser \r\n * General Public License as published by the Free Software \r\n * Foundation; either version 2.1 of the License, or \r\n * (at your option) any later version.\r\n *\r\n * This library is distributed in the hope that it will be \r\n * useful, but WITHOUT ANY WARRANTY; without even the implied \r\n * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r\n * PURPOSE. See the GNU Lesser General Public License \r\n * for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General \r\n * Public License along with this library; if not, write to \r\n * the Free Software Foundation, Inc., 59 Temple Place, \r\n * Suite 330, Boston, MA 02111-1307 USA \r\n *\t\t\t\t \r\n */\r\n\r\n/*\r\n * default values for encoder/decoder used by wrapper\r\n */\r\n\r\n#include <zlib.h>\r\n\r\n/* jc: undef to kill compress2_lzma */\r\n#define _LZMA_PARAMS \r\n\r\n#define ZLIB_LC 3\r\n#define ZLIB_LP 0\r\n#define ZLIB_PB 2\r\n#define ZLIB_FB 128 /* jc: add default fast bytes param */\r\n\r\n#ifdef WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#endif\r\n\r\n#include \"../../../Common/MyWindows.h\"\r\n#include \"../LZMA/LZMADecoder.h\"\r\n#include \"../LZMA/LZMAEncoder.h\"\r\n\r\n#define STG_E_SEEKERROR                  ((HRESULT)0x80030019L)\r\n#define STG_E_MEDIUMFULL                 ((HRESULT)0x80030070L)\r\n\r\nclass CInMemoryStream: \r\n  public IInStream,\r\n  public IStreamGetSize,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  CInMemoryStream(const Bytef *data, UInt64 size) : \r\n\t  m_data(data), m_size(size), m_offset(0) {}\r\n\r\n  virtual ~CInMemoryStream() {}\r\n\r\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r\n\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\t  if (size > m_size - m_offset) \r\n\t\t  size = m_size - m_offset;\r\n\r\n\t  if (size) {\r\n\t\t  memcpy(data, m_data + m_offset, size);\r\n\t  }\r\n\r\n\t  m_offset += size;\r\n\r\n\t  if (processedSize) \r\n\t\t  *processedSize = size;\r\n\r\n\t  return S_OK;\r\n  }\r\n\r\n  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\treturn Read(data, size, processedSize);\r\n  }\r\n\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n  {\r\n\t  UInt64 _offset;\r\n\r\n\t  if (seekOrigin == STREAM_SEEK_SET) _offset = offset;\r\n\t  else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset; \r\n\t  else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;\r\n\t  else return STG_E_INVALIDFUNCTION;\r\n\r\n\t  if (_offset < 0 || _offset > m_size)\r\n\t\t  return STG_E_SEEKERROR;\r\n\r\n\t  m_offset = _offset;\r\n\r\n\t  if (newPosition)\r\n\t\t  *newPosition = m_offset;\r\n\r\n\t  return S_OK;\r\n  }\r\n\r\n  STDMETHOD(GetSize)(UInt64 *size)\r\n  {\r\n\t  *size = m_size;\r\n\t  return S_OK;\r\n  }\r\nprotected:\r\n\tconst Bytef *m_data;\r\n\tUInt64 m_size;\r\n\tUInt64 m_offset;\r\n};\r\n\r\nclass COutMemoryStream: \r\n  public IOutStream,\r\n  public CMyUnknownImp\r\n{\r\npublic:\r\n  COutMemoryStream(Bytef *data, UInt64 maxsize) : \r\n\t  m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}\r\n  virtual ~COutMemoryStream() {}\r\n  \r\n  MY_UNKNOWN_IMP1(IOutStream)\r\n\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\t  if (size > m_maxsize - m_offset) \r\n\t\t  size = m_maxsize - m_offset;\r\n\r\n\t  if (size) {\r\n\t\t  memcpy(m_data + m_offset, data, size);\r\n\t  }\r\n\r\n\t  m_offset += size;\r\n\r\n\t  if (m_offset > m_size)\r\n\t\tm_size = m_offset;\r\n\r\n\t  if (processedSize) \r\n\t\t  *processedSize = size;\r\n\r\n\t  return S_OK;\r\n  }\r\n  \r\n  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)\r\n  {\r\n\t  return Write(data, size, processedSize);\r\n  }\r\n\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r\n  {\r\n\t  UInt64 _offset;\r\n\r\n\t  if (seekOrigin == STREAM_SEEK_SET) _offset = offset;\r\n\t  else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset; \r\n\t  else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;\r\n\t  else return STG_E_INVALIDFUNCTION;\r\n\r\n\t  if (_offset < 0 || _offset > m_maxsize)\r\n\t\t  return STG_E_SEEKERROR;\r\n\r\n\t  m_offset = _offset;\r\n\r\n\t  if (newPosition)\r\n\t\t  *newPosition = m_offset;\r\n\r\n\t  return S_OK;\r\n  }\r\n  \r\n  STDMETHOD(SetSize)(Int64 newSize)\r\n  {\r\n\t  if ((UInt64)newSize > m_maxsize) \r\n\t\t  return STG_E_MEDIUMFULL;\r\n\r\n\t  return S_OK;\r\n  }\r\nprotected:\r\n\tBytef *m_data;\r\n\tUInt64 m_size;\r\n\tUInt64 m_maxsize;\r\n\tUInt64 m_offset;\r\n};\r\n\r\n\r\n#ifdef _LZMA_PARAMS\r\n\r\n\r\n\r\n/* jc: new compress2 proxy that allows lzma param specification */\r\nextern \"C\" int compress2_lzma_test (Bytef *dest,   uLongf *destLen,\r\n                                  \tconst Bytef *source, uLong sourceLen,\r\n                                  \tint level, int fb, int lc, int lp, int pb)\r\n{\t\r\n\tCInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);\r\n\tCMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\t\r\n\tCOutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);\r\n\tCMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n\t\r\n\tNCompress::NLZMA::CEncoder *encoderSpec = \r\n\t\tnew NCompress::NLZMA::CEncoder;\r\n\tCMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\t\r\n\tPROPID propIDs[] = \r\n\t{\r\n\t\tNCoderPropID::kDictionarySize,\r\n\t\tNCoderPropID::kPosStateBits,\r\n\t\tNCoderPropID::kLitContextBits,\r\n\t\tNCoderPropID::kLitPosBits,\r\n\t\tNCoderPropID::kAlgorithm,\r\n\t\tNCoderPropID::kNumFastBytes,\r\n\t\tNCoderPropID::kMatchFinder,\r\n\t\tNCoderPropID::kEndMarker\r\n\t};\r\n\tconst int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\t\r\n\tif(pb<0) pb=ZLIB_PB;\r\n\tif(lc<0) lc=ZLIB_LC;\r\n\tif(lp<0) lp=ZLIB_LP;\r\n\tif(fb<0) fb=ZLIB_FB;\r\n\tPROPVARIANT properties[kNumProps];\r\n\tfor (int p = 0; p < 6; p++)\r\n\t\tproperties[p].vt = VT_UI4;\r\n\tproperties[0].ulVal = UInt32(1 << (level + 14));\r\n\tproperties[1].ulVal = UInt32(pb);\r\n\tproperties[2].ulVal = UInt32(lc); // for normal files\r\n\tproperties[3].ulVal = UInt32(lp); // for normal files\r\n\tproperties[4].ulVal = UInt32(2);       // todo\r\n\tproperties[5].ulVal = UInt32(fb); \r\n\t\r\n\tproperties[6].vt = VT_BSTR;\r\n\tproperties[6].bstrVal = (BSTR)(const wchar_t *)L\"BT4\";\r\n\t\r\n\tproperties[7].vt = VT_BOOL;\r\n\tproperties[7].boolVal = VARIANT_TRUE;\r\n\t\r\n\tif (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n\t\treturn Z_MEM_ERROR; // should not happen\r\n\t\r\n\tHRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n\tif (result == E_OUTOFMEMORY)\r\n\t{\r\n\t\treturn Z_MEM_ERROR;\r\n\t}   \r\n\telse if (result != S_OK)\r\n\t{\r\n\t\treturn Z_BUF_ERROR;\t// should not happen\r\n\t}   \r\n\t\r\n\tUInt64 fileSize;\r\n\toutStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);\r\n\t*destLen = fileSize;\r\n\t\r\n\treturn Z_OK;\r\n}\r\n\r\n#include <malloc.h>\r\n#include <stdio.h>\r\n#include <pthread.h>\r\n\r\n\r\nunsigned char pbmatrix[3]={0,1,2};\r\nunsigned char lcmatrix[4]={0,1,2,3};\r\nunsigned char lpmatrix[4]={0,1,2,3};\r\n\r\nstruct MATRIXENTRY\r\n{\r\nint pb;\r\nint lc;\r\nint lp;\r\n};\r\n\r\nstruct MATRIXENTRY matrix[]={\r\n{2,0,0},\r\n{2,0,1},\r\n{2,0,2},\r\n{2,1,0},\r\n{2,1,2},\r\n{2,2,0},\r\n{2,3,0},\r\n{0,2,0},\r\n{0,2,1},\r\n{0,3,0},\r\n{0,0,0},\r\n{0,0,2},\r\n{1,0,1},\r\n{1,2,0},\r\n{1,3,0}\r\n};\r\n\r\n\r\n\r\nint pbsave = -1;\r\nint lcsave = -1;\r\nint lpsave = -1;\r\n\r\n\r\nint testcount=0;\r\n\r\nint testlevel;\r\nint testfb;\r\npthread_mutex_t\tpos_mutex;\r\nBytef *test1;\r\nconst Bytef *testsource;\r\n\r\nuLongf test2len;\r\nuLongf test1len;\r\nuLongf testsourcelen;\r\nint running=0;\r\nextern \"C\" void *brute(void *arg)\r\n{\r\n\tint oldstate;\r\n\tuLongf test3len = test2len;\r\n\tpthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);\r\n\tpthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);\r\n\r\npthread_mutex_lock(&pos_mutex);\r\nint takelcvalue = matrix[testcount].lc;\r\nint takepbvalue = matrix[testcount].pb;\r\nint takelpvalue = matrix[testcount].lp;\r\ntestcount++;\r\nif (testcount==(sizeof(matrix)/sizeof(struct MATRIXENTRY)))\r\n    {\r\n    running--;\r\n    pthread_mutex_unlock(&pos_mutex);\r\n    return NULL;\r\n    }\r\npthread_mutex_unlock(&pos_mutex);\r\nBytef *test2 = (Bytef*)malloc(test2len);\r\nint ret =  compress2_lzma_test(test2,&test3len,testsource,testsourcelen,testlevel,testfb,takelcvalue,takelpvalue,takepbvalue);\r\npthread_mutex_lock(&pos_mutex);\r\nif (test3len<test1len)\r\n    {\r\n    test1len = test3len;\r\n    memcpy(test1,test2,test3len);\r\n    pbsave = takepbvalue;\r\n    lcsave = takelcvalue;\r\n    lpsave = takelpvalue;\r\n    }\r\nrunning--;\r\npthread_mutex_unlock(&pos_mutex);\r\nfree(test2);\r\nreturn NULL;\r\n}\r\n\r\n\r\n\r\nextern \"C\" int compress2_lzma (Bytef *dest,   uLongf *destLen,\r\n                                  \tconst Bytef *source, uLong sourceLen,\r\n                                  \tint level, int fb, int lc, int lp, int pb)\r\n{\r\nint i,a;\r\npthread_t *thread;\r\ntest1 = (Bytef*)malloc(*destLen);\r\ntest1len = *destLen+*destLen;\r\ntest2len = *destLen;\r\ntestsource = source;\r\ntestfb = fb;\r\ntestsourcelen = sourceLen;\r\ntestlevel = level;\r\ntestcount=0;\r\n\tif((thread = (pthread_t *)malloc((8) * sizeof(pthread_t))) == NULL)\r\n\t\tfprintf(stderr,\"Out of memory allocating thread descriptors\\n\");\r\nfor (a=0;a<2;a++)\r\n{\r\nrunning=8;\r\n\tfor(i = 0; i < 8; i++) {\r\n\t\tif(pthread_create(&thread[i], NULL, brute, NULL) != 0 )\r\n\t\t\tfprintf(stderr,\"Failed to create thread\\n\");\r\n\t}\r\n\tfor (i=0;i<8;i++)\r\n\t    {\r\n\t    pthread_join(thread[i],NULL);\r\n\t    }\r\n}\r\n    memcpy(dest+4,test1,test1len);\r\n    dest[0]=pbsave;\r\n    dest[1]=lcsave;\r\n    dest[2]=lpsave;\r\n    dest[3]=fb;\r\n    *destLen=test1len+4;\r\nfree(thread);\r\n    free(test1);\r\n    return Z_OK;\r\n}\r\n\r\n\r\n#endif\r\n\r\nZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,\r\n                                  const Bytef *source, uLong sourceLen,\r\n                                  int level))\r\n{\r\n\tCInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);\r\n\tCMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\t\r\n\tCOutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);\r\n\tCMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n\t\r\n\tNCompress::NLZMA::CEncoder *encoderSpec = \r\n\t\tnew NCompress::NLZMA::CEncoder;\r\n\tCMyComPtr<ICompressCoder> encoder = encoderSpec;\r\n\t\r\n\tPROPID propIDs[] = \r\n\t{\r\n\t\tNCoderPropID::kDictionarySize,\r\n\t\tNCoderPropID::kPosStateBits,\r\n\t\tNCoderPropID::kLitContextBits,\r\n\t\tNCoderPropID::kLitPosBits,\r\n\t\tNCoderPropID::kAlgorithm,\r\n\t\tNCoderPropID::kNumFastBytes,\r\n\t\tNCoderPropID::kMatchFinder,\r\n\t\tNCoderPropID::kEndMarker\r\n\t};\r\n\tconst int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r\n\t\r\n\tPROPVARIANT properties[kNumProps];\r\n\tfor (int p = 0; p < 6; p++)\r\n\t\tproperties[p].vt = VT_UI4;\r\n\tproperties[0].ulVal = UInt32(1 << (level + 14));\r\n\tproperties[1].ulVal = UInt32(ZLIB_PB);\r\n\tproperties[2].ulVal = UInt32(ZLIB_LC); // for normal files\r\n\tproperties[3].ulVal = UInt32(ZLIB_LP); // for normal files\r\n\tproperties[4].ulVal = UInt32(2);\r\n\tproperties[5].ulVal = UInt32(ZLIB_FB);\r\n\t\r\n\tproperties[6].vt = VT_BSTR;\r\n\tproperties[6].bstrVal = (BSTR)(const wchar_t *)L\"BT4\";\r\n\t\r\n\tproperties[7].vt = VT_BOOL;\r\n\tproperties[7].boolVal = VARIANT_TRUE;\r\n\t\r\n\tif (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r\n\t\t{\r\n\t\tfprintf(stderr,\"coder properties error\\n\");\r\n\t\treturn Z_MEM_ERROR; // should not happen\r\n\t\r\n\t}\r\n\tHRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r\n\tif (result == E_OUTOFMEMORY)\r\n\t{\r\n\t\tfprintf(stderr,\"mem error\\n\");\r\n\t\treturn Z_MEM_ERROR;\r\n\t}   \r\n\telse if (result != S_OK)\r\n\t{\r\n\t\treturn Z_BUF_ERROR;\t// should not happen\r\n\t}   \r\n\t\r\n\tUInt64 fileSize;\r\n\toutStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);\r\n\t*destLen = fileSize;\r\n\t\r\n\treturn Z_OK;\r\n}\r\n\r\nZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,\r\n                                   const Bytef *source, uLong sourceLen))\r\n{\r\n\tCInMemoryStream *inStreamSpec = new CInMemoryStream(source+4, sourceLen-4);\r\n\tCMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r\n\t\r\n\tCOutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);\r\n\tCMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r\n\t\r\n\tNCompress::NLZMA::CDecoder *decoderSpec = \r\n\t\tnew NCompress::NLZMA::CDecoder;\r\n\tCMyComPtr<ICompressCoder> decoder = decoderSpec;\r\n\t\r\n\tif (decoderSpec->SetDecoderPropertiesRaw(source[1], \r\n\t\tsource[2], source[0], (1 << 23)) != S_OK) return Z_DATA_ERROR;\r\n\t\r\n\tUInt64 fileSize = *destLen;\r\n\t\r\n\tif (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r\n\t{\r\n\t\treturn Z_DATA_ERROR;\r\n\t}\r\n\t\r\n\toutStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);\r\n\t*destLen = fileSize;\r\n\t\r\n\treturn Z_OK;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Lib/lzmaext.h",
    "content": "/*\n * lzmaext.h\n *\n * LZMA Parameter extensions\n * these minor additions by Jeremy Collake <jeremy@bitsum.com>\n *\n * This library is free software; you can redistribute \n * it and/or modify it under the terms of the GNU Lesser \n * General Public License as published by the Free Software \n * Foundation; either version 2.1 of the License, or \n * (at your option) any later version.\n *\n * This library is distributed in the hope that it will be \n * useful, but WITHOUT ANY WARRANTY; without even the implied \n * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR \n * PURPOSE. See the GNU Lesser General Public License \n * for more details.\n *\n * You should have received a copy of the GNU Lesser General \n * Public License along with this library; if not, write to \n * the Free Software Foundation, Inc., 59 Temple Place, \n * Suite 330, Boston, MA 02111-1307 USA \n */\nint compress2_lzma (Bytef *dest, uLongf *destLen,\n                    const Bytef *source, uLong sourceLen,\t\t\t\t\n                    int level, int fb,\tint lc,\tint lp,\tint pb);\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/LZMA_Lib/makefile",
    "content": "PROG = liblzma.a\nCXX = g++ -O3  -funroll-loops -mtune=opteron -march=opteron -mfpmath=sse -m3dnow -msse2 -mmmx -msse -msse3 -O3 -Wall -finline-functions\nAR = ar\nRM = rm -f\nCFLAGS = -c  -I ../../../\n\nOBJS = \\\n  ZLib.o \\\n  LZMADecoder.o \\\n  LZMAEncoder.o \\\n  LZInWindow.o \\\n  LZOutWindow.o \\\n  RangeCoderBit.o \\\n  InBuffer.o \\\n  OutBuffer.o \\\n  FileStreams.o \\\n  Alloc.o \\\n  C_FileIO.o \\\n  CommandLineParser.o \\\n  CRC.o \\\n  StreamUtils.o \\\n  String.o \\\n  StringConvert.o \\\n  StringToInt.o \\\n  Vector.o \\\n\n\nall: $(PROG)\n\n$(PROG): $(OBJS)\n\t$(AR) r $(PROG) $(OBJS)\n\nZLib.o: ZLib.cpp\n\t$(CXX) $(CFLAGS) ZLib.cpp\n\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\n\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\n\nLZInWindow.o: ../LZ/LZInWindow.cpp\n\t$(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp\n\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\n\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\n\nInBuffer.o: ../../Common/InBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\n\nOutBuffer.o: ../../Common/OutBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\n\nStreamUtils.o: ../../Common/StreamUtils.cpp\n\t$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp\n\nFileStreams.o: ../../Common/FileStreams.cpp\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\n\nAlloc.o: ../../../Common/Alloc.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/Alloc.cpp\n\nC_FileIO.o: ../../../Common/C_FileIO.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp\n\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\n\nCRC.o: ../../../Common/CRC.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\n\nMyWindows.o: ../../../Common/MyWindows.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\n\nString.o: ../../../Common/String.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/String.cpp\n\nStringConvert.o: ../../../Common/StringConvert.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\n\nStringToInt.o: ../../../Common/StringToInt.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\n\nVector.o: ../../../Common/Vector.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/Vector.cpp\n\nclean:\n\t-$(RM) $(PROG) $(OBJS)\n\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/RangeCoder/RangeCoder.h",
    "content": "// Compress/RangeCoder/RangeCoder.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_H\r\n#define __COMPRESS_RANGECODER_H\r\n\r\n#include \"../../Common/InBuffer.h\"\r\n#include \"../../Common/OutBuffer.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumTopBits = 24;\r\nconst UInt32 kTopValue = (1 << kNumTopBits);\r\n\r\nclass CEncoder\r\n{\r\n  UInt32 _cacheSize;\r\n  Byte _cache;\r\npublic:\r\n  UInt64 Low;\r\n  UInt32 Range;\r\n  COutBuffer Stream;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Low = 0;\r\n    Range = 0xFFFFFFFF;\r\n    _cacheSize = 1;\r\n    _cache = 0;\r\n  }\r\n\r\n  void FlushData()\r\n  {\r\n    // Low += 1; \r\n    for(int i = 0; i < 5; i++)\r\n      ShiftLow();\r\n  }\r\n\r\n  HRESULT FlushStream() { return Stream.Flush();  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\r\n  {\r\n    Low += start * (Range /= total);\r\n    Range *= size;\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  void ShiftLow()\r\n  {\r\n    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) \r\n    {\r\n      Byte temp = _cache;\r\n      do\r\n      {\r\n        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r\n        temp = 0xFF;\r\n      }\r\n      while(--_cacheSize != 0);\r\n      _cache = (Byte)((UInt32)Low >> 24);                      \r\n    } \r\n    _cacheSize++;                               \r\n    Low = (UInt32)Low << 8;                           \r\n  }\r\n  \r\n  void EncodeDirectBits(UInt32 value, int numTotalBits)\r\n  {\r\n    for (int i = numTotalBits - 1; i >= 0; i--)\r\n    {\r\n      Range >>= 1;\r\n      if (((value >> i) & 1) == 1)\r\n        Low += Range;\r\n      if (Range < kTopValue)\r\n      {\r\n        Range <<= 8;\r\n        ShiftLow();\r\n      }\r\n    }\r\n  }\r\n\r\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    if (symbol == 0)\r\n      Range = newBound;\r\n    else\r\n    {\r\n      Low += newBound;\r\n      Range -= newBound;\r\n    }\r\n    while (Range < kTopValue)\r\n    {\r\n      Range <<= 8;\r\n      ShiftLow();\r\n    }\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r\n};\r\n\r\nclass CDecoder\r\n{\r\npublic:\r\n  CInBuffer Stream;\r\n  UInt32 Range;\r\n  UInt32 Code;\r\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r\n\r\n  void Normalize()\r\n  {\r\n    while (Range < kTopValue)\r\n    {\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n      Range <<= 8;\r\n    }\r\n  }\r\n  \r\n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r\n  void Init()\r\n  {\r\n    Stream.Init();\r\n    Code = 0;\r\n    Range = 0xFFFFFFFF;\r\n    for(int i = 0; i < 5; i++)\r\n      Code = (Code << 8) | Stream.ReadByte();\r\n  }\r\n\r\n  void ReleaseStream() { Stream.ReleaseStream(); }\r\n\r\n  UInt32 GetThreshold(UInt32 total)\r\n  {\r\n    return (Code) / ( Range /= total);\r\n  }\r\n\r\n  void Decode(UInt32 start, UInt32 size)\r\n  {\r\n    Code -= start * Range;\r\n    Range *= size;\r\n    Normalize();\r\n  }\r\n\r\n  UInt32 DecodeDirectBits(int numTotalBits)\r\n  {\r\n    UInt32 range = Range;\r\n    UInt32 code = Code;        \r\n    UInt32 result = 0;\r\n    for (int i = numTotalBits; i != 0; i--)\r\n    {\r\n      range >>= 1;\r\n      /*\r\n      result <<= 1;\r\n      if (code >= range)\r\n      {\r\n        code -= range;\r\n        result |= 1;\r\n      }\r\n      */\r\n      UInt32 t = (code - range) >> 31;\r\n      code -= range & (t - 1);\r\n      result = (result << 1) | (1 - t);\r\n\r\n      if (range < kTopValue)\r\n      {\r\n        code = (code << 8) | Stream.ReadByte();\r\n        range <<= 8; \r\n      }\r\n    }\r\n    Range = range;\r\n    Code = code;\r\n    return result;\r\n  }\r\n\r\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r\n  {\r\n    UInt32 newBound = (Range >> numTotalBits) * size0;\r\n    UInt32 symbol;\r\n    if (Code < newBound)\r\n    {\r\n      symbol = 0;\r\n      Range = newBound;\r\n    }\r\n    else\r\n    {\r\n      symbol = 1;\r\n      Code -= newBound;\r\n      Range -= newBound;\r\n    }\r\n    Normalize();\r\n    return symbol;\r\n  }\r\n\r\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/RangeCoder/RangeCoderBit.cpp",
    "content": "// Compress/RangeCoder/RangeCoderBit.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"RangeCoderBit.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nUInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\nstatic CPriceTables g_PriceTables;\r\n\r\nCPriceTables::CPriceTables() { Init(); }\r\n\r\nvoid CPriceTables::Init()\r\n{\r\n  const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n  for(int i = kNumBits - 1; i >= 0; i--)\r\n  {\r\n    UInt32 start = 1 << (kNumBits - i - 1);\r\n    UInt32 end = 1 << (kNumBits - i);\r\n    for (UInt32 j = start; j < end; j++)\r\n      ProbPrices[j] = (i << kNumBitPriceShiftBits) + \r\n          (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n  }\r\n\r\n  /*\r\n  // simplest: bad solution\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = kBitPrice;\r\n  */\r\n  \r\n  /*\r\n  const double kDummyMultMid = (1.0 / kBitPrice) / 2;\r\n  const double kDummyMultMid = 0;\r\n  // float solution\r\n  double ln2 = log(double(2));\r\n  double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n    ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);\r\n  */\r\n  \r\n  /*\r\n  // experimental, slow, solution:\r\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\r\n  {\r\n    const int kCyclesBits = 5;\r\n    const UInt32 kCycles = (1 << kCyclesBits);\r\n\r\n    UInt32 range = UInt32(-1);\r\n    UInt32 bitCount = 0;\r\n    for (UInt32 j = 0; j < kCycles; j++)\r\n    {\r\n      range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n      range *= i;\r\n      while(range < (1 << 31))\r\n      {\r\n        range <<= 1;\r\n        bitCount++;\r\n      }\r\n    }\r\n    bitCount <<= kNumBitPriceShiftBits;\r\n    range -= (1 << 31);\r\n    for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)\r\n    {\r\n      range <<= 1;\r\n      if (range > (1 << 31))\r\n      {\r\n        bitCount += (1 << k);\r\n        range -= (1 << 31);\r\n      }\r\n    }\r\n    ProbPrices[i] = (bitCount \r\n      // + (1 << (kCyclesBits - 1))\r\n      ) >> kCyclesBits;\r\n  }\r\n  */\r\n}\r\n\r\n}}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/RangeCoder/RangeCoderBit.h",
    "content": "// Compress/RangeCoder/RangeCoderBit.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_H\r\n#define __COMPRESS_RANGECODER_BIT_H\r\n\r\n#include \"RangeCoder.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\nconst int kNumBitModelTotalBits  = 11;\r\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\r\nconst int kNumMoveReducingBits = 2;\r\n\r\nconst int kNumBitPriceShiftBits = 6;\r\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r\n\r\nclass CPriceTables\r\n{\r\npublic:\r\n  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r\n  static void Init();\r\n  CPriceTables();\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitModel\r\n{\r\npublic:\r\n  UInt32 Prob;\r\n  void UpdateModel(UInt32 symbol)\r\n  {\r\n    /*\r\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r\n    */\r\n    if (symbol == 0)\r\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r\n    else\r\n      Prob -= (Prob) >> numMoveBits;\r\n  }\r\npublic:\r\n  void Init() { Prob = kBitModelTotal / 2; }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitEncoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  void Encode(CEncoder *encoder, UInt32 symbol)\r\n  {\r\n    /*\r\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r\n    this->UpdateModel(symbol);\r\n    */\r\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (symbol == 0)\r\n    {\r\n      encoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n    }\r\n    else\r\n    {\r\n      encoder->Low += newBound;\r\n      encoder->Range -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n    }\r\n    if (encoder->Range < kTopValue)\r\n    {\r\n      encoder->Range <<= 8;\r\n      encoder->ShiftLow();\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    return CPriceTables::ProbPrices[\r\n      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n  }\r\n  UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r\n  UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }\r\n};\r\n\r\n\r\ntemplate <int numMoveBits>\r\nclass CBitDecoder: public CBitModel<numMoveBits>\r\n{\r\npublic:\r\n  UInt32 Decode(CDecoder *decoder)\r\n  {\r\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r\n    if (decoder->Code < newBound)\r\n    {\r\n      decoder->Range = newBound;\r\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 0;\r\n    }\r\n    else\r\n    {\r\n      decoder->Range -= newBound;\r\n      decoder->Code -= newBound;\r\n      this->Prob -= (this->Prob) >> numMoveBits;\r\n      if (decoder->Range < kTopValue)\r\n      {\r\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r\n        decoder->Range <<= 8;\r\n      }\r\n      return 1;\r\n    }\r\n  }\r\n};\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/RangeCoder/RangeCoderBitTree.h",
    "content": "// Compress/RangeCoder/RangeCoderBitTree.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_BIT_TREE_H\r\n#define __COMPRESS_RANGECODER_BIT_TREE_H\r\n\r\n#include \"RangeCoderBit.h\"\r\n#include \"RangeCoderOpt.h\"\r\n\r\nnamespace NCompress {\r\nnamespace NRangeCoder {\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeEncoder\r\n{\r\n  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  void Encode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int bitIndex = NumBitLevels; bitIndex != 0 ;)\r\n    {\r\n      bitIndex--;\r\n      UInt32 bit = (symbol >> bitIndex) & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n  };\r\n  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    for (int i = 0; i < NumBitLevels; i++)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      Models[modelIndex].Encode(rangeEncoder, bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n      symbol >>= 1;\r\n    }\r\n  }\r\n  UInt32 GetPrice(UInt32 symbol) const\r\n  {\r\n    symbol |= (1 << NumBitLevels);\r\n    UInt32 price = 0;\r\n    while (symbol != 1)\r\n    {\r\n      price += Models[symbol >> 1].GetPrice(symbol & 1);\r\n      symbol >>= 1;\r\n    }\r\n    return price;\r\n  }\r\n  UInt32 ReverseGetPrice(UInt32 symbol) const\r\n  {\r\n    UInt32 price = 0;\r\n    UInt32 modelIndex = 1;\r\n    for (int i = NumBitLevels; i != 0; i--)\r\n    {\r\n      UInt32 bit = symbol & 1;\r\n      symbol >>= 1;\r\n      price += Models[modelIndex].GetPrice(bit);\r\n      modelIndex = (modelIndex << 1) | bit;\r\n    }\r\n    return price;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits, int NumBitLevels>\r\nclass CBitTreeDecoder\r\n{\r\n  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];\r\npublic:\r\n  void Init()\r\n  {\r\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r\n      Models[i].Init();\r\n  }\r\n  UInt32 Decode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n    {\r\n      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);\r\n      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)\r\n    }\r\n    RC_FLUSH_VAR\r\n    return modelIndex - (1 << NumBitLevels);\r\n  };\r\n  UInt32 ReverseDecode(CDecoder *rangeDecoder)\r\n  {\r\n    UInt32 modelIndex = 1;\r\n    UInt32 symbol = 0;\r\n    RC_INIT_VAR\r\n    for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n    {\r\n      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n      // modelIndex <<= 1;\r\n      // modelIndex += bit;\r\n      // symbol |= (bit << bitIndex);\r\n      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n    }\r\n    RC_FLUSH_VAR\r\n    return symbol;\r\n  }\r\n};\r\n\r\ntemplate <int numMoveBits>\r\nvoid ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models, \r\n    CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  for (int i = 0; i < NumBitLevels; i++)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    Models[modelIndex].Encode(rangeEncoder, bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n    symbol >>= 1;\r\n  }\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models, \r\n    UInt32 NumBitLevels, UInt32 symbol)\r\n{\r\n  UInt32 price = 0;\r\n  UInt32 modelIndex = 1;\r\n  for (int i = NumBitLevels; i != 0; i--)\r\n  {\r\n    UInt32 bit = symbol & 1;\r\n    symbol >>= 1;\r\n    price += Models[modelIndex].GetPrice(bit);\r\n    modelIndex = (modelIndex << 1) | bit;\r\n  }\r\n  return price;\r\n}\r\n\r\ntemplate <int numMoveBits>\r\nUInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models, \r\n    CDecoder *rangeDecoder, int NumBitLevels)\r\n{\r\n  UInt32 modelIndex = 1;\r\n  UInt32 symbol = 0;\r\n  RC_INIT_VAR\r\n  for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n  {\r\n    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r\n    // modelIndex <<= 1;\r\n    // modelIndex += bit;\r\n    // symbol |= (bit << bitIndex);\r\n    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r\n  }\r\n  RC_FLUSH_VAR\r\n  return symbol;\r\n}\r\n\r\n}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/RangeCoder/RangeCoderOpt.h",
    "content": "// Compress/RangeCoder/RangeCoderOpt.h\r\n\r\n#ifndef __COMPRESS_RANGECODER_OPT_H\r\n#define __COMPRESS_RANGECODER_OPT_H\r\n\r\n#define RC_INIT_VAR \\\r\n  UInt32 range = rangeDecoder->Range; \\\r\n  UInt32 code = rangeDecoder->Code;        \r\n\r\n#define RC_FLUSH_VAR \\\r\n  rangeDecoder->Range = range; \\\r\n  rangeDecoder->Code = code;\r\n\r\n#define RC_NORMALIZE \\\r\n  if (range < NCompress::NRangeCoder::kTopValue) \\\r\n    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }\r\n\r\n#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \\\r\n  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \\\r\n  if (code < bound) \\\r\n  { A0; range = bound; \\\r\n    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \\\r\n    mi <<= 1; } \\\r\n  else \\\r\n  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \\\r\n    mi = (mi + mi) + 1; }} \\\r\n  RC_NORMALIZE\r\n\r\n#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/Compress/RangeCoder/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/ICoder.h",
    "content": "// ICoder.h\r\n\r\n#ifndef __ICODER_H\r\n#define __ICODER_H\r\n\r\n#include \"IStream.h\"\r\n\r\n// \"23170F69-40C1-278A-0000-000400xx0000\"\r\n#define CODER_INTERFACE(i, x) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \\\r\nstruct i: public IUnknown\r\n\r\nCODER_INTERFACE(ICompressProgressInfo, 0x04)\r\n{\r\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder, 0x05)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream *inStream,\r\n      ISequentialOutStream *outStream, \r\n      const UInt64 *inSize, \r\n      const UInt64 *outSize,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressCoder2, 0x18)\r\n{\r\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\r\n      const UInt64 **inSizes, \r\n      UInt32 numInStreams,\r\n      ISequentialOutStream **outStreams, \r\n      const UInt64 **outSizes,\r\n      UInt32 numOutStreams,\r\n      ICompressProgressInfo *progress) PURE;\r\n};\r\n\r\nnamespace NCoderPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kDictionarySize = 0x400,\r\n    kUsedMemorySize,\r\n    kOrder,\r\n    kPosStateBits = 0x440,\r\n    kLitContextBits,\r\n    kLitPosBits,\r\n    kNumFastBytes = 0x450,\r\n    kMatchFinder,\r\n    kNumPasses = 0x460, \r\n    kAlgorithm = 0x470,\r\n    kMultiThread = 0x480,\r\n    kEndMarker = 0x490\r\n  };\r\n}\r\n\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r\n{\r\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r\n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r\n};\r\n\r\n/*\r\nCODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r\n{\r\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r\n};\r\n*/\r\n\r\nCODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r\n{\r\n  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r\n{\r\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r\n{\r\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r\n{\r\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStream, 0x31)\r\n{\r\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r\n  STDMETHOD(ReleaseInStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStream, 0x32)\r\n{\r\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r\n  STDMETHOD(ReleaseOutStream)() PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r\n{\r\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r\n{\r\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICompressFilter, 0x40)\r\n{\r\n  STDMETHOD(Init)() PURE;\r\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r\n  // Filter return outSize (UInt32)\r\n  // if (outSize <= size): Filter have converted outSize bytes\r\n  // if (outSize > size): Filter have not converted anything.\r\n  //      and it needs at least outSize bytes to convert one block \r\n  //      (it's for crypto block algorithms).\r\n};\r\n\r\nCODER_INTERFACE(ICryptoProperties, 0x80)\r\n{\r\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetPassword, 0x90)\r\n{\r\n  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r\n};\r\n\r\nCODER_INTERFACE(ICryptoSetCRC, 0xA0)\r\n{\r\n  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r\n};\r\n\r\n//////////////////////\r\n// It's for DLL file\r\nnamespace NMethodPropID\r\n{\r\n  enum EEnum\r\n  {\r\n    kID,\r\n    kName,\r\n    kDecoder,\r\n    kEncoder,\r\n    kInStreams,\r\n    kOutStreams,\r\n    kDescription\r\n  };\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/7zip/IStream.h",
    "content": "// IStream.h\r\n\r\n#ifndef __ISTREAM_H\r\n#define __ISTREAM_H\r\n\r\n#include \"../Common/MyUnknown.h\"\r\n#include \"../Common/Types.h\"\r\n\r\n// \"23170F69-40C1-278A-0000-000300xx0000\"\r\n\r\n#define STREAM_INTERFACE_SUB(i, b, x) \\\r\nDEFINE_GUID(IID_ ## i, \\\r\n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \\\r\nstruct i: public b\r\n\r\n#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r\n\r\nSTREAM_INTERFACE(ISequentialInStream, 0x01)\r\n{\r\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r\n    then there are no more bytes in stream.\r\n  if (size > 0) && there are bytes in stream, \r\n  this function must read at least 1 byte.\r\n  This function is allowed to read less than number of remaining bytes in stream.\r\n  You must call Read function in loop, if you need exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE(ISequentialOutStream, 0x02)\r\n{\r\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r\n  /*\r\n  if (size > 0) this function must write at least 1 byte.\r\n  This function is allowed to write less than \"size\".\r\n  You must call Write function in loop, if you need to write exact amount of data\r\n  */\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r\n{\r\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r\n  STDMETHOD(SetSize)(Int64 newSize) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IStreamGetSize, 0x06)\r\n{\r\n  STDMETHOD(GetSize)(UInt64 *size) PURE;\r\n};\r\n\r\nSTREAM_INTERFACE(IOutStreamFlush, 0x07)\r\n{\r\n  STDMETHOD(Flush)() PURE;\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/Alloc.cpp",
    "content": "// Common/Alloc.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#else\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#include \"Alloc.h\"\r\n\r\n/* #define _SZ_ALLOC_DEBUG */\r\n/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */\r\n#ifdef _SZ_ALLOC_DEBUG\r\n#include <stdio.h>\r\nint g_allocCount = 0;\r\nint g_allocCountMid = 0;\r\nint g_allocCountBig = 0;\r\n#endif\r\n\r\nvoid *MyAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc %10d bytes; count = %10d\", size, g_allocCount++);\r\n  #endif\r\n  return ::malloc(size);\r\n}\r\n\r\nvoid MyFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree; count = %10d\", --g_allocCount);\r\n  #endif\r\n  \r\n  ::free(address);\r\n}\r\n\r\n#ifdef _WIN32\r\n\r\nvoid *MidAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Mid %10d bytes;  count = %10d\", size, g_allocCountMid++);\r\n  #endif\r\n  return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid MidFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Mid; count = %10d\", --g_allocCountMid);\r\n  #endif\r\n  if (address == 0)\r\n    return;\r\n  ::VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\nstatic SIZE_T g_LargePageSize = \r\n    #ifdef _WIN64\r\n    (1 << 21);\r\n    #else\r\n    (1 << 22);\r\n    #endif\r\n\r\ntypedef SIZE_T (WINAPI *GetLargePageMinimumP)();\r\n\r\nbool SetLargePageSize()\r\n{\r\n  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)\r\n        ::GetProcAddress(::GetModuleHandle(TEXT(\"kernel32.dll\")), \"GetLargePageMinimum\");\r\n  if (largePageMinimum == 0)\r\n    return false;\r\n  SIZE_T size = largePageMinimum();\r\n  if (size == 0 || (size & (size - 1)) != 0)\r\n    return false;\r\n  g_LargePageSize = size;\r\n  return true;\r\n}\r\n\r\n\r\nvoid *BigAlloc(size_t size) throw()\r\n{\r\n  if (size == 0)\r\n    return 0;\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  fprintf(stderr, \"\\nAlloc_Big %10d bytes;  count = %10d\", size, g_allocCountBig++);\r\n  #endif\r\n  \r\n  if (size >= (1 << 18))\r\n  {\r\n    void *res = ::VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), \r\n        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);\r\n    if (res != 0)\r\n      return res;\r\n  }\r\n  return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\r\n}\r\n\r\nvoid BigFree(void *address) throw()\r\n{\r\n  #ifdef _SZ_ALLOC_DEBUG\r\n  if (address != 0)\r\n    fprintf(stderr, \"\\nFree_Big; count = %10d\", --g_allocCountBig);\r\n  #endif\r\n  \r\n  if (address == 0)\r\n    return;\r\n  ::VirtualFree(address, 0, MEM_RELEASE);\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/Alloc.h",
    "content": "// Common/Alloc.h\r\n\r\n#ifndef __COMMON_ALLOC_H\r\n#define __COMMON_ALLOC_H\r\n\r\n#include <stddef.h>\r\n\r\nvoid *MyAlloc(size_t size) throw();\r\nvoid MyFree(void *address) throw();\r\n\r\n#ifdef _WIN32\r\n\r\nbool SetLargePageSize();\r\n\r\nvoid *MidAlloc(size_t size) throw();\r\nvoid MidFree(void *address) throw();\r\nvoid *BigAlloc(size_t size) throw();\r\nvoid BigFree(void *address) throw();\r\n\r\n#else\r\n\r\n#define MidAlloc(size) MyAlloc(size)\r\n#define MidFree(address) MyFree(address)\r\n#define BigAlloc(size) MyAlloc(size)\r\n#define BigFree(address) MyFree(address)\r\n\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CRC.h\"\r\n\r\nstatic const UInt32 kCRCPoly = 0xEDB88320;\r\n\r\nUInt32 CCRC::Table[256];\r\n\r\nvoid CCRC::InitTable()\r\n{\r\n  for (UInt32 i = 0; i < 256; i++)\r\n  {\r\n    UInt32 r = i;\r\n    for (int j = 0; j < 8; j++)\r\n      if (r & 1) \r\n        r = (r >> 1) ^ kCRCPoly;\r\n      else     \r\n        r >>= 1;\r\n    CCRC::Table[i] = r;\r\n  }\r\n}\r\n\r\nclass CCRCTableInit\r\n{\r\npublic:\r\n  CCRCTableInit() { CCRC::InitTable(); }\r\n} g_CRCTableInit;\r\n\r\nvoid CCRC::UpdateByte(Byte b)\r\n{\r\n  _value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);\r\n}\r\n\r\nvoid CCRC::UpdateUInt16(UInt16 v)\r\n{\r\n  UpdateByte(Byte(v));\r\n  UpdateByte(Byte(v >> 8));\r\n}\r\n\r\nvoid CCRC::UpdateUInt32(UInt32 v)\r\n{\r\n  for (int i = 0; i < 4; i++)\r\n    UpdateByte((Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CCRC::UpdateUInt64(UInt64 v)\r\n{\r\n  for (int i = 0; i < 8; i++)\r\n    UpdateByte((Byte)(v >> (8 * i)));\r\n}\r\n\r\nvoid CCRC::Update(const void *data, size_t size)\r\n{\r\n  UInt32 v = _value;\r\n  const Byte *p = (const Byte *)data;\r\n  for (; size > 0 ; size--, p++)\r\n    v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);\r\n  _value = v;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/CRC.h",
    "content": "// Common/CRC.h\r\n\r\n#ifndef __COMMON_CRC_H\r\n#define __COMMON_CRC_H\r\n\r\n#include <stddef.h>\r\n#include \"Types.h\"\r\n\r\nclass CCRC\r\n{\r\n  UInt32 _value;\r\npublic:\r\n\tstatic UInt32 Table[256];\r\n\tstatic void InitTable();\r\n\r\n  CCRC():  _value(0xFFFFFFFF){};\r\n  void Init() { _value = 0xFFFFFFFF; }\r\n  void UpdateByte(Byte v);\r\n  void UpdateUInt16(UInt16 v);\r\n  void UpdateUInt32(UInt32 v);\r\n  void UpdateUInt64(UInt64 v);\r\n  void Update(const void *data, size_t size);\r\n  UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } \r\n  static UInt32 CalculateDigest(const void *data, size_t size)\r\n  {\r\n    CCRC crc;\r\n    crc.Update(data, size);\r\n    return crc.GetDigest();\r\n  }\r\n  static bool VerifyDigest(UInt32 digest, const void *data, size_t size)\r\n  {\r\n    return (CalculateDigest(data, size) == digest);\r\n  }\r\n};\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\r\n\r\n#include \"C_FileIO.h\"\r\n\r\n#include <fcntl.h>\r\n#include <unistd.h>\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nbool CFileBase::OpenBinary(const char *name, int flags)\r\n{\r\n  #ifdef O_BINARY\r\n  flags |= O_BINARY;\r\n  #endif\r\n  Close();\r\n  _handle = ::open(name, flags, 0666);\r\n  return _handle != -1;\r\n}\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(_handle == -1)\r\n    return true;\r\n  if (close(_handle) != 0)\r\n    return false;\r\n  _handle = -1;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  off_t curPos = Seek(0, SEEK_CUR);\r\n  off_t lengthTemp = Seek(0, SEEK_END);\r\n  Seek(curPos, SEEK_SET);\r\n  length = (UInt64)lengthTemp;\r\n  return true;\r\n}\r\n\r\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\r\n{\r\n  return ::lseek(_handle, distanceToMove, moveMethod);\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(const char *name)\r\n{\r\n  return CFileBase::OpenBinary(name, O_RDONLY);\r\n}\r\n\r\nssize_t CInFile::Read(void *data, size_t size)\r\n{\r\n  return read(_handle, data, size);\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Create(const char *name, bool createAlways)\r\n{\r\n  if (createAlways)\r\n  {\r\n    Close();\r\n    _handle = ::creat(name, 0666);\r\n    return _handle != -1;\r\n  }\r\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\r\n}\r\n\r\nssize_t COutFile::Write(const void *data, size_t size)\r\n{\r\n  return write(_handle, data, size);\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\r\n\r\n#ifndef __COMMON_C_FILEIO_H\r\n#define __COMMON_C_FILEIO_H\r\n\r\n#include <stdio.h>\r\n#include <sys/types.h>\r\n\r\n#include \"Types.h\"\r\n#include \"MyWindows.h\"\r\n\r\nnamespace NC {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  int _handle;\r\n  bool OpenBinary(const char *name, int flags);\r\npublic:\r\n  CFileBase(): _handle(-1) {};\r\n  ~CFileBase() { Close(); }\r\n  bool Close();\r\n  bool GetLength(UInt64 &length) const;\r\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(const char *name);\r\n  ssize_t Read(void *data, size_t size);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\npublic:\r\n  bool Create(const char *name, bool createAlways);\r\n  ssize_t Write(const void *data, size_t size);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/ComTry.h",
    "content": "// ComTry.h\r\n\r\n#ifndef __COM_TRY_H\r\n#define __COM_TRY_H\r\n\r\n#include \"MyWindows.h\"\r\n// #include \"Exception.h\"\r\n// #include \"NewHandler.h\"\r\n\r\n#define COM_TRY_BEGIN try {\r\n#define COM_TRY_END } catch(...) { return E_OUTOFMEMORY; }\r\n  \r\n  // catch(const CNewException &) { return E_OUTOFMEMORY; }\\\r\n  // catch(const CSystemException &e) { return e.ErrorCode; }\\\r\n  // catch(...) { return E_FAIL; }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"CommandLineParser.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\r\n{\r\n  dest1.Empty();\r\n  dest2.Empty();\r\n  bool quoteMode = false;\r\n  int i;\r\n  for (i = 0; i < src.Length(); i++)\r\n  {\r\n    wchar_t c = src[i];\r\n    if (c == L'\\\"')\r\n      quoteMode = !quoteMode;\r\n    else if (c == L' ' && !quoteMode)\r\n    {\r\n      i++;\r\n      break;\r\n    }\r\n    else \r\n      dest1 += c;\r\n  }\r\n  dest2 = src.Mid(i);\r\n}\r\n\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\r\n{\r\n  UString sTemp = s;\r\n  sTemp.Trim();\r\n  parts.Clear();\r\n  while (true)\r\n  {\r\n    UString s1, s2;\r\n    SplitCommandLine(sTemp, s1, s2);\r\n    // s1.Trim();\r\n    // s2.Trim();\r\n    if (!s1.IsEmpty())\r\n      parts.Add(s1);\r\n    if (s2.IsEmpty())\r\n      return;\r\n    sTemp = s2;\r\n  }\r\n}\r\n\r\n\r\nstatic const wchar_t kSwitchID1 = '-';\r\n// static const wchar_t kSwitchID2 = '/';\r\n\r\nstatic const wchar_t kSwitchMinus = '-';\r\nstatic const wchar_t *kStopSwitchParsing = L\"--\";\r\n\r\nstatic bool IsItSwitchChar(wchar_t c)\r\n{ \r\n  return (c == kSwitchID1 /*|| c == kSwitchID2 */); \r\n}\r\n\r\nCParser::CParser(int numSwitches):\r\n  _numSwitches(numSwitches)\r\n{\r\n  _switches = new CSwitchResult[_numSwitches];\r\n}\r\n\r\nCParser::~CParser()\r\n{\r\n  delete []_switches;\r\n}\r\n\r\nvoid CParser::ParseStrings(const CSwitchForm *switchForms, \r\n  const UStringVector &commandStrings)\r\n{\r\n  int numCommandStrings = commandStrings.Size();\r\n  bool stopSwitch = false;\r\n  for (int i = 0; i < numCommandStrings; i++)\r\n  {\r\n    const UString &s = commandStrings[i];\r\n    if (stopSwitch)\r\n      NonSwitchStrings.Add(s);\r\n    else\r\n      if (s == kStopSwitchParsing)\r\n        stopSwitch = true;\r\n      else\r\n        if (!ParseString(s, switchForms))\r\n          NonSwitchStrings.Add(s);\r\n  }\r\n}\r\n\r\n// if string contains switch then function updates switch structures\r\n// out: (string is a switch)\r\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\r\n{\r\n  int len = s.Length();\r\n  if (len == 0) \r\n    return false;\r\n  int pos = 0;\r\n  if (!IsItSwitchChar(s[pos]))\r\n    return false;\r\n  while(pos < len)\r\n  {\r\n    if (IsItSwitchChar(s[pos]))\r\n      pos++;\r\n    const int kNoLen = -1;\r\n    int matchedSwitchIndex = 0; // GCC Warning\r\n    int maxLen = kNoLen;\r\n    for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\r\n    {\r\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\r\n      if (switchLen <= maxLen || pos + switchLen > len) \r\n        continue;\r\n\r\n      UString temp = s + pos;\r\n      temp = temp.Left(switchLen);\r\n      if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\r\n      // if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\r\n      {\r\n        matchedSwitchIndex = switchIndex;\r\n        maxLen = switchLen;\r\n      }\r\n    }\r\n    if (maxLen == kNoLen)\r\n      throw \"maxLen == kNoLen\";\r\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\r\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\r\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n      throw \"switch must be single\";\r\n    matchedSwitch.ThereIs = true;\r\n    pos += maxLen;\r\n    int tailSize = len - pos;\r\n    NSwitchType::EEnum type = switchForm.Type;\r\n    switch(type)\r\n    {\r\n      case NSwitchType::kPostMinus:\r\n        {\r\n          if (tailSize == 0)\r\n            matchedSwitch.WithMinus = false;\r\n          else\r\n          {\r\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\r\n            if (matchedSwitch.WithMinus)\r\n              pos++;\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kPostChar:\r\n        {\r\n          if (tailSize < switchForm.MinLen)\r\n            throw \"switch is not full\";\r\n          UString set = switchForm.PostCharSet;\r\n          const int kEmptyCharValue = -1;\r\n          if (tailSize == 0)\r\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\r\n          else\r\n          {\r\n            int index = set.Find(s[pos]);\r\n            if (index < 0)\r\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\r\n            else\r\n            {\r\n              matchedSwitch.PostCharIndex = index;\r\n              pos++;\r\n            }\r\n          }\r\n          break;\r\n        }\r\n      case NSwitchType::kLimitedPostString: \r\n      case NSwitchType::kUnLimitedPostString: \r\n        {\r\n          int minLen = switchForm.MinLen;\r\n          if (tailSize < minLen)\r\n            throw \"switch is not full\";\r\n          if (type == NSwitchType::kUnLimitedPostString)\r\n          {\r\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\r\n            return true;\r\n          }\r\n          int maxLen = switchForm.MaxLen;\r\n          UString stringSwitch = s.Mid(pos, minLen);\r\n          pos += minLen;\r\n          for(int i = minLen; i < maxLen && pos < len; i++, pos++)\r\n          {\r\n            wchar_t c = s[pos];\r\n            if (IsItSwitchChar(c))\r\n              break;\r\n            stringSwitch += c;\r\n          }\r\n          matchedSwitch.PostStrings.Add(stringSwitch);\r\n          break;\r\n        }\r\n      case NSwitchType::kSimple:\r\n          break;\r\n    }\r\n  }\r\n  return true;\r\n}\r\n\r\nconst CSwitchResult& CParser::operator[](size_t index) const\r\n{\r\n  return _switches[index];\r\n}\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString)\r\n{\r\n  for(int i = 0; i < numCommandForms; i++)\r\n  {\r\n    const UString id = commandForms[i].IDString;\r\n    if (commandForms[i].PostStringMode)\r\n    {\r\n      if(commandString.Find(id) == 0)\r\n      {\r\n        postString = commandString.Mid(id.Length());\r\n        return i;\r\n      }\r\n    }\r\n    else\r\n      if (commandString == id)\r\n      {\r\n        postString.Empty();\r\n        return i;\r\n      }\r\n  }\r\n  return -1;\r\n}\r\n   \r\nbool ParseSubCharsCommand(int numForms, const CCommandSubCharsSet *forms, \r\n    const UString &commandString, CIntVector &indices)\r\n{\r\n  indices.Clear();\r\n  int numUsedChars = 0;\r\n  for(int i = 0; i < numForms; i++)\r\n  {\r\n    const CCommandSubCharsSet &set = forms[i];\r\n    int currentIndex = -1;\r\n    int len = MyStringLen(set.Chars);\r\n    for(int j = 0; j < len; j++)\r\n    {\r\n      wchar_t c = set.Chars[j];\r\n      int newIndex = commandString.Find(c);\r\n      if (newIndex >= 0)\r\n      {\r\n        if (currentIndex >= 0)\r\n          return false;\r\n        if (commandString.Find(c, newIndex + 1) >= 0)\r\n          return false;\r\n        currentIndex = j;\r\n        numUsedChars++;\r\n      }\r\n    }\r\n    if(currentIndex == -1 && !set.EmptyAllowed)\r\n      return false;\r\n    indices.Add(currentIndex);\r\n  }\r\n  return (numUsedChars == commandString.Length());\r\n}\r\n\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\r\n\r\n#ifndef __COMMON_COMMANDLINEPARSER_H\r\n#define __COMMON_COMMANDLINEPARSER_H\r\n\r\n#include \"Common/String.h\"\r\n\r\nnamespace NCommandLineParser {\r\n\r\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\r\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\r\n\r\nnamespace NSwitchType {\r\n  enum EEnum\r\n  { \r\n    kSimple,\r\n    kPostMinus,\r\n    kLimitedPostString,\r\n    kUnLimitedPostString,\r\n    kPostChar\r\n  };\r\n}\r\n\r\nstruct CSwitchForm\r\n{\r\n  const wchar_t *IDString;\r\n  NSwitchType::EEnum Type;\r\n  bool Multi;\r\n  int MinLen;\r\n  int MaxLen;\r\n  const wchar_t *PostCharSet;\r\n};\r\n\r\nstruct CSwitchResult\r\n{\r\n  bool ThereIs;\r\n  bool WithMinus;\r\n  UStringVector PostStrings;\r\n  int PostCharIndex;\r\n  CSwitchResult(): ThereIs(false) {};\r\n};\r\n  \r\nclass CParser\r\n{\r\n  int _numSwitches;\r\n  CSwitchResult *_switches;\r\n  bool ParseString(const UString &s, const CSwitchForm *switchForms); \r\npublic:\r\n  UStringVector NonSwitchStrings;\r\n  CParser(int numSwitches);\r\n  ~CParser();\r\n  void ParseStrings(const CSwitchForm *switchForms, \r\n    const UStringVector &commandStrings);\r\n  const CSwitchResult& operator[](size_t index) const;\r\n};\r\n\r\n/////////////////////////////////\r\n// Command parsing procedures\r\n\r\nstruct CCommandForm\r\n{\r\n  wchar_t *IDString;\r\n  bool PostStringMode;\r\n};\r\n\r\n// Returns: Index of form and postString; -1, if there is no match\r\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \r\n    const UString &commandString, UString &postString);\r\n\r\nstruct CCommandSubCharsSet\r\n{\r\n  wchar_t *Chars;\r\n  bool EmptyAllowed;\r\n};\r\n\r\n// Returns: indices of finded chars; -1 if there is no match\r\nbool ParseSubCharsCommand(int numForms, const CCommandSubCharsSet *forms, \r\n    const UString &commandString, CIntVector &indices);\r\n\r\n}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/Defs.h",
    "content": "// Common/Defs.h\r\n\r\n#ifndef __COMMON_DEFS_H\r\n#define __COMMON_DEFS_H\r\n\r\ntemplate <class T> inline T MyMin(T a, T b)\r\n  {  return a < b ? a : b; }\r\ntemplate <class T> inline T MyMax(T a, T b)\r\n  {  return a > b ? a : b; }\r\n\r\ntemplate <class T> inline int MyCompare(T a, T b)\r\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\r\n\r\ninline int BoolToInt(bool value)\r\n  { return (value ? 1: 0); }\r\n\r\ninline bool IntToBool(int value)\r\n  { return (value != 0); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/MyCom.h",
    "content": "// MyCom.h\r\n\r\n#ifndef __MYCOM_H\r\n#define __MYCOM_H\r\n\r\n#include \"MyWindows.h\"\r\n\r\n#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }\r\n\r\ntemplate <class T>\r\nclass CMyComPtr\r\n{\r\n  T* _p;\r\npublic:\r\n  // typedef T _PtrClass;\r\n  CMyComPtr() { _p = NULL;}\r\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r\n  CMyComPtr(const CMyComPtr<T>& lp)\r\n  {\r\n    if ((_p = lp._p) != NULL)\r\n      _p->AddRef();\r\n  }\r\n  ~CMyComPtr() { if (_p) _p->Release(); }\r\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r\n  operator T*() const {  return (T*)_p;  }\r\n  // T& operator*() const {  return *_p; }\r\n  T** operator&() { return &_p; }\r\n  T* operator->() const { return _p; }\r\n  T* operator=(T* p) \r\n  { \r\n    if (p != 0)\r\n      p->AddRef();\r\n    if (_p) \r\n      _p->Release();\r\n    _p = p;\r\n    return p;\r\n  }\r\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r\n  bool operator!() const { return (_p == NULL); }\r\n  // bool operator==(T* pT) const {  return _p == pT; }\r\n  // Compare two objects for equivalence\r\n  void Attach(T* p2)\r\n  {\r\n    Release();\r\n    _p = p2;\r\n  }\r\n  T* Detach()\r\n  {\r\n    T* pt = _p;\r\n    _p = NULL;\r\n    return pt;\r\n  }\r\n  #ifdef _WIN32\r\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r\n  }\r\n  #endif\r\n  /*\r\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r\n  {\r\n    CLSID clsid;\r\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r\n    ATLASSERT(_p == NULL);\r\n    if (SUCCEEDED(hr))\r\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r\n    return hr;\r\n  }\r\n  */\r\n  template <class Q>\r\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r\n  {\r\n    return _p->QueryInterface(iid, (void**)pp);\r\n  }\r\n};\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyComBSTR\r\n{\r\npublic:\r\n  BSTR m_str;\r\n  CMyComBSTR() { m_str = NULL; }\r\n  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }\r\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r\n  /*\r\n  CMyComBSTR(REFGUID src)\r\n  {\r\n    LPOLESTR szGuid;\r\n    StringFromCLSID(src, &szGuid);\r\n    m_str = ::SysAllocString(szGuid);\r\n    CoTaskMemFree(szGuid);\r\n  }\r\n  */\r\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\r\n  CMyComBSTR& operator=(const CMyComBSTR& src)\r\n  {\r\n    if (m_str != src.m_str)\r\n    {\r\n      if (m_str)\r\n        ::SysFreeString(m_str);\r\n      m_str = src.MyCopy();\r\n    }\r\n    return *this;\r\n  }\r\n  CMyComBSTR& operator=(LPCOLESTR pSrc)\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = ::SysAllocString(pSrc);\r\n    return *this;\r\n  }\r\n  unsigned int Length() const { return ::SysStringLen(m_str); }\r\n  operator BSTR() const { return m_str; }\r\n  BSTR* operator&() { return &m_str; }\r\n  BSTR MyCopy() const \r\n  { \r\n    int byteLen = ::SysStringByteLen(m_str);\r\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r\n    memmove(res, m_str, byteLen);\r\n    return res;\r\n  }\r\n  void Attach(BSTR src) {  m_str = src; }\r\n  BSTR Detach()\r\n  {\r\n    BSTR s = m_str;\r\n    m_str = NULL;\r\n    return s;\r\n  }\r\n  void Empty()\r\n  {\r\n    ::SysFreeString(m_str);\r\n    m_str = NULL;\r\n  }\r\n  bool operator!() const {  return (m_str == NULL); }\r\n};\r\n\r\n\r\n//////////////////////////////////////////////////////////\r\n\r\nclass CMyUnknownImp\r\n{\r\npublic:\r\n  ULONG __m_RefCount;\r\n  CMyUnknownImp(): __m_RefCount(0) {}\r\n};\r\n\r\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\r\n    (REFGUID iid, void **outObject) { \r\n\r\n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\r\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r\n\r\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r\n\r\n#define MY_ADDREF_RELEASE \\\r\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\r\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\r\n  return __m_RefCount; delete this; return 0; }\r\n\r\n#define MY_UNKNOWN_IMP_SPEC(i) \\\r\n  MY_QUERYINTERFACE_BEGIN \\\r\n  i \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n\r\n#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \\\r\n  MY_QUERYINTERFACE_END \\\r\n  MY_ADDREF_RELEASE\r\n\r\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  )\r\n\r\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\r\n  MY_QUERYINTERFACE_ENTRY(i1) \\\r\n  MY_QUERYINTERFACE_ENTRY(i2) \\\r\n  MY_QUERYINTERFACE_ENTRY(i3) \\\r\n  MY_QUERYINTERFACE_ENTRY(i4) \\\r\n  MY_QUERYINTERFACE_ENTRY(i5) \\\r\n  )\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/MyGuidDef.h",
    "content": "// Common/MyGuidDef.h\r\n\r\n#ifndef GUID_DEFINED\r\n#define GUID_DEFINED\r\n\r\n#include \"Types.h\"\r\n\r\ntypedef struct {\r\n  UInt32 Data1;\r\n  UInt16 Data2;\r\n  UInt16 Data3;\r\n  unsigned char Data4[8];\r\n} GUID;\r\n\r\n#ifdef __cplusplus\r\n#define REFGUID const GUID &\r\n#else\r\n#define REFGUID const GUID *\r\n#endif\r\n\r\n#define REFCLSID REFGUID\r\n#define REFIID REFGUID\r\n\r\n#ifdef __cplusplus\r\ninline bool operator==(REFGUID g1, REFGUID g2)\r\n{ \r\n  for (int i = 0; i < (int)sizeof(g1); i++)\r\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\r\n      return false;\r\n  return true;\r\n}\r\ninline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r\n#endif\r\n\r\n#ifdef __cplusplus\r\n  #define MY_EXTERN_C extern \"C\"\r\n#else\r\n  #define MY_EXTERN_C extern\r\n#endif\r\n\r\n#endif // GUID_DEFINED\r\n\r\n\r\n#ifdef DEFINE_GUID\r\n#undef DEFINE_GUID\r\n#endif\r\n\r\n#ifdef INITGUID\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r\n#else\r\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\r\n    MY_EXTERN_C const GUID name\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/MyInitGuid.h",
    "content": "// Common/MyInitGuid.h\r\n\r\n#ifndef __COMMON_MYINITGUID_H\r\n#define __COMMON_MYINITGUID_H\r\n\r\n#ifdef _WIN32\r\n#include <initguid.h>\r\n#else\r\n#define INITGUID\r\n#include \"MyGuidDef.h\"\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/MyUnknown.h",
    "content": "// MyUnknown.h\r\n\r\n#ifndef __MYUNKNOWN_H\r\n#define __MYUNKNOWN_H\r\n\r\n#ifdef _WIN32\r\n\r\n#ifdef _WIN32_WCE\r\n#if (_WIN32_WCE > 300)\r\n#include <basetyps.h>\r\n#else\r\n#define MIDL_INTERFACE(x) struct \r\n#endif\r\n#else\r\n#include <basetyps.h>\r\n#endif\r\n\r\n#include <unknwn.h>\r\n\r\n#else \r\n#include \"MyWindows.h\"\r\n#endif\r\n  \r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/MyWindows.h",
    "content": "// MyWindows.h\r\n\r\n#ifndef __MYWINDOWS_H\r\n#define __MYWINDOWS_H\r\n\r\n#ifdef _WIN32\r\n\r\n#include <windows.h>\r\n\r\n#else\r\n\r\n#include <stddef.h> // for wchar_t\r\n#include <string.h>\r\n\r\n#include \"MyGuidDef.h\"\r\n\r\ntypedef char CHAR;\r\ntypedef unsigned char UCHAR;\r\ntypedef unsigned char BYTE;\r\n\r\ntypedef short SHORT;\r\ntypedef unsigned short USHORT;\r\ntypedef unsigned short WORD;\r\ntypedef short VARIANT_BOOL;\r\n\r\ntypedef int INT;\r\ntypedef Int32 INT32;\r\ntypedef unsigned int UINT;\r\ntypedef UInt32 UINT32;\r\ntypedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r\ntypedef UINT32 ULONG;\r\ntypedef UINT32 DWORD;\r\n\r\ntypedef Int64 LONGLONG;\r\ntypedef UInt64 ULONGLONG;\r\n\r\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r\n\r\ntypedef const CHAR *LPCSTR;\r\ntypedef CHAR TCHAR;\r\ntypedef const TCHAR *LPCTSTR;\r\ntypedef wchar_t WCHAR;\r\ntypedef WCHAR OLECHAR;\r\ntypedef const WCHAR *LPCWSTR;\r\ntypedef OLECHAR *BSTR;\r\ntypedef const OLECHAR *LPCOLESTR;\r\ntypedef OLECHAR *LPOLESTR;\r\n\r\ntypedef struct _FILETIME\r\n{\r\n  DWORD dwLowDateTime;\r\n  DWORD dwHighDateTime;\r\n}FILETIME;\r\n\r\n#define HRESULT LONG\r\n#define FAILED(Status) ((HRESULT)(Status)<0)\r\ntypedef ULONG PROPID;\r\ntypedef LONG SCODE;\r\n\r\n#define S_OK    ((HRESULT)0x00000000L)\r\n#define S_FALSE ((HRESULT)0x00000001L)\r\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\r\n#define E_ABORT ((HRESULT)0x80004004L)\r\n#define E_FAIL ((HRESULT)0x80004005L)\r\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r\n#define E_INVALIDARG ((HRESULT)0x80070057L)\r\n\r\n#ifdef _MSC_VER\r\n#define STDMETHODCALLTYPE __stdcall \r\n#else\r\n#define STDMETHODCALLTYPE \r\n#endif\r\n\r\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r\n\r\n#define PURE = 0\r\n\r\n#define MIDL_INTERFACE(x) struct \r\n\r\nstruct IUnknown\r\n{\r\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r\n  STDMETHOD_(ULONG, AddRef)() PURE;\r\n  STDMETHOD_(ULONG, Release)() PURE;\r\n};\r\n\r\ntypedef IUnknown *LPUNKNOWN;\r\n\r\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\r\n\r\nenum VARENUM\r\n{\t\r\n  VT_EMPTY\t= 0,\r\n\tVT_NULL\t= 1,\r\n\tVT_I2\t= 2,\r\n\tVT_I4\t= 3,\r\n\tVT_R4\t= 4,\r\n\tVT_R8\t= 5,\r\n\tVT_CY\t= 6,\r\n\tVT_DATE\t= 7,\r\n\tVT_BSTR\t= 8,\r\n\tVT_DISPATCH\t= 9,\r\n\tVT_ERROR\t= 10,\r\n\tVT_BOOL\t= 11,\r\n\tVT_VARIANT\t= 12,\r\n\tVT_UNKNOWN\t= 13,\r\n\tVT_DECIMAL\t= 14,\r\n\tVT_I1\t= 16,\r\n\tVT_UI1\t= 17,\r\n\tVT_UI2\t= 18,\r\n\tVT_UI4\t= 19,\r\n\tVT_I8\t= 20,\r\n\tVT_UI8\t= 21,\r\n\tVT_INT\t= 22,\r\n\tVT_UINT\t= 23,\r\n\tVT_VOID\t= 24,\r\n\tVT_HRESULT\t= 25,\r\n\tVT_FILETIME\t= 64\r\n};\r\n\r\ntypedef unsigned short VARTYPE;\r\ntypedef WORD PROPVAR_PAD1;\r\ntypedef WORD PROPVAR_PAD2;\r\ntypedef WORD PROPVAR_PAD3;\r\n\r\ntypedef struct tagPROPVARIANT\r\n{\r\n  VARTYPE vt;\r\n  PROPVAR_PAD1 wReserved1;\r\n  PROPVAR_PAD2 wReserved2;\r\n  PROPVAR_PAD3 wReserved3;\r\n  union \r\n  {\r\n    CHAR cVal;\r\n    UCHAR bVal;\r\n    SHORT iVal;\r\n    USHORT uiVal;\r\n    LONG lVal;\r\n    ULONG ulVal;\r\n    INT intVal;\r\n    UINT uintVal;\r\n    LARGE_INTEGER hVal;\r\n    ULARGE_INTEGER uhVal;\r\n    VARIANT_BOOL boolVal;\r\n    SCODE scode;\r\n    FILETIME filetime;\r\n    BSTR bstrVal;\r\n  };\r\n} PROPVARIANT;\r\n\r\ntypedef PROPVARIANT tagVARIANT;\r\ntypedef tagVARIANT VARIANT;\r\ntypedef VARIANT VARIANTARG;\r\n\r\nMY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r\nMY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r\nMY_EXTERN_C void SysFreeString(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r\nMY_EXTERN_C UINT SysStringLen(BSTR bstr);\r\n\r\nMY_EXTERN_C DWORD GetLastError();\r\nMY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r\nMY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r\nMY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r\n\r\n#define CP_ACP    0\r\n#define CP_OEMCP  1\r\n\r\ntypedef enum tagSTREAM_SEEK\r\n{\t\r\n  STREAM_SEEK_SET\t= 0,\r\n  STREAM_SEEK_CUR\t= 1,\r\n  STREAM_SEEK_END\t= 2\r\n} STREAM_SEEK;\r\n\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\r\n \r\n#include \"StdAfx.h\"\r\n\r\n#include <stdlib.h>\r\n\r\n#include \"NewHandler.h\"\r\n\r\n// #define DEBUG_MEMORY_LEAK\r\n\r\n#ifndef DEBUG_MEMORY_LEAK\r\n\r\nvoid * \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator new(size_t size)\r\n{\r\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\r\n  void *p = ::malloc(size);\r\n  if (p == 0)\r\n    throw CNewException();\r\n  return p;\r\n}\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw()\r\n{\r\n  /*\r\n  if (p == 0)\r\n    return;\r\n  ::HeapFree(::GetProcessHeap(), 0, p);\r\n  */\r\n  ::free(p);\r\n}\r\n\r\n#else\r\n\r\n#pragma init_seg(lib)\r\nconst int kDebugSize = 1000000;\r\nstatic void *a[kDebugSize];\r\nstatic int index = 0;\r\n\r\nstatic int numAllocs = 0;\r\nvoid * __cdecl operator new(size_t size)\r\n{\r\n  numAllocs++;\r\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\r\n  if (index == 40)\r\n  {\r\n    int t = 1;\r\n  }\r\n  if (index < kDebugSize)\r\n  {\r\n    a[index] = p;\r\n    index++;\r\n  }\r\n  if (p == 0)\r\n    throw CNewException();\r\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\r\n  return p;\r\n}\r\n\r\nclass CC\r\n{\r\npublic:\r\n  CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      a[i] = 0;\r\n  }\r\n  ~CC()\r\n  {\r\n    for (int i = 0; i < kDebugSize; i++)\r\n      if (a[i] != 0)\r\n        return;\r\n  }\r\n} g_CC;\r\n\r\n\r\nvoid __cdecl operator delete(void *p)\r\n{\r\n  if (p == 0)\r\n    return;\r\n  /*\r\n  for (int i = 0; i < index; i++)\r\n    if (a[i] == p)\r\n      a[i] = 0;\r\n  */\r\n  HeapFree(GetProcessHeap(), 0, p);\r\n  numAllocs--;\r\n  printf(\"Free %d\\n\", numAllocs);\r\n}\r\n\r\n#endif\r\n\r\n/*\r\nint MemErrorVC(size_t)\r\n{\r\n  throw CNewException();\r\n  // return 1;\r\n}\r\nCNewHandlerSetter::CNewHandlerSetter()\r\n{\r\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\r\n}\r\nCNewHandlerSetter::~CNewHandlerSetter()\r\n{\r\n  // _set_new_handler(MemErrorOldVCFunction);\r\n}\r\n*/\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\r\n\r\n#ifndef __COMMON_NEWHANDLER_H\r\n#define __COMMON_NEWHANDLER_H\r\n\r\nclass CNewException {};\r\n\r\nvoid \r\n#ifdef _MSC_VER\r\n__cdecl \r\n#endif\r\noperator delete(void *p) throw();\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n// #include \"MyWindows.h\"\r\n#include \"NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/String.cpp",
    "content": "// Common/String.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"StringConvert.h\"\r\n#else\r\n#include <ctype.h>\r\n#endif\r\n\r\n#include \"Common/String.h\"\r\n\r\n\r\n#ifdef _WIN32\r\n\r\n#ifndef _UNICODE\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW((LPWSTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharUpperA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t MyCharLower(wchar_t c)\r\n{\r\n  if (c == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW((LPWSTR)(unsigned int)c);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return (wchar_t)(unsigned int)res;\r\n  const int kBufferSize = 4;\r\n  char s[kBufferSize + 1];\r\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\r\n  if (numChars == 0 || numChars > kBufferSize)\r\n    return c;\r\n  s[numChars] = 0;\r\n  ::CharLowerA(s);\r\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\r\n  return c;\r\n}\r\n\r\nwchar_t * MyStringUpper(wchar_t *s)\r\n{\r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharUpperW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeUpper();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\nwchar_t * MyStringLower(wchar_t *s)\r\n{ \r\n  if (s == 0)\r\n    return 0;\r\n  wchar_t *res = CharLowerW(s);\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return res;\r\n  AString a = UnicodeStringToMultiByte(s);\r\n  a.MakeLower();\r\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\r\n}\r\n\r\n#endif\r\n\r\n/*\r\ninline int ConvertCompareResult(int r) { return r - 2; }\r\n\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollate(UnicodeStringToMultiByte(s1), \r\n        UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n\r\nint MyStringCollateNoCase(const char *s1, const char *s2)\r\n{ \r\n  return ConvertCompareResult(CompareStringA(\r\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); \r\n}\r\n#endif\r\n\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  int res = CompareStringW(\r\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); \r\n  #ifdef _UNICODE\r\n  return ConvertCompareResult(res);\r\n  #else\r\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\r\n    return ConvertCompareResult(res);\r\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), \r\n      UnicodeStringToMultiByte(s2));\r\n  #endif\r\n}\r\n*/\r\n\r\n#else\r\n\r\nwchar_t MyCharUpper(wchar_t c)\r\n{\r\n  return toupper(c);\r\n}\r\n\r\n/*\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    wchar_t u1 = MyCharUpper(c1);\r\n    wchar_t u2 = MyCharUpper(c2);\r\n\r\n    if (u1 < u2) return -1;\r\n    if (u1 > u2) return 1;\r\n    if (u1 == 0) return 0;\r\n  }\r\n}\r\n*/\r\n\r\n#endif\r\n\r\nint MyStringCompare(const char *s1, const char *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    unsigned char c1 = (unsigned char)*s1++;\r\n    unsigned char c2 = (unsigned char)*s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 < c2) return -1;\r\n    if (c1 > c2) return 1;\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2)\r\n{ \r\n  while (true)\r\n  {\r\n    wchar_t c1 = *s1++;\r\n    wchar_t c2 = *s2++;\r\n    if (c1 != c2)\r\n    {\r\n      wchar_t u1 = MyCharUpper(c1);\r\n      wchar_t u2 = MyCharUpper(c2);\r\n      if (u1 < u2) return -1;\r\n      if (u1 > u2) return 1;\r\n    }\r\n    if (c1 == 0) return 0;\r\n  }\r\n}\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char *s2)\r\n{ \r\n  return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2));\r\n}\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/String.h",
    "content": "// Common/String.h\r\n\r\n#ifndef __COMMON_STRING_H\r\n#define __COMMON_STRING_H\r\n\r\n#include <string.h>\r\n// #include <wchar.h>\r\n\r\n#include \"Vector.h\"\r\n\r\n#ifdef _WIN32\r\n#include \"MyWindows.h\"\r\n#endif\r\n\r\nstatic const char *kTrimDefaultCharSet  = \" \\n\\t\";\r\n\r\ntemplate <class T>\r\ninline int MyStringLen(const T *s)\r\n{ \r\n  int i;\r\n  for (i = 0; s[i] != '\\0'; i++);\r\n  return i;\r\n}\r\n\r\ntemplate <class T>\r\ninline T * MyStringCopy(T *dest, const T *src)\r\n{ \r\n  T *destStart = dest;\r\n  while((*dest++ = *src++) != 0);\r\n  return destStart;\r\n}\r\n\r\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\r\n  { return (p + 1); }\r\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\r\n  { return (p + 1); }\r\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p)\r\n  { return (p - 1); }\r\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p)\r\n  { return (p - 1); }\r\n\r\n#ifdef _WIN32\r\n\r\ninline char* MyStringGetNextCharPointer(char *p)\r\n  { return CharNextA(p); }\r\ninline const char* MyStringGetNextCharPointer(const char *p)\r\n  { return CharNextA(p); }\r\n\r\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\r\n  { return CharPrevA(base, p); }\r\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\r\n  { return CharPrevA(base, p); }\r\n\r\ninline char MyCharUpper(char c)\r\n  { return (char)(unsigned int)CharUpperA((LPSTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharUpper(wchar_t c)\r\n  { return (wchar_t)CharUpperW((LPWSTR)c); }\r\n#else\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\ninline char MyCharLower(char c)\r\n  { return (char)(unsigned int)CharLowerA((LPSTR)(unsigned int)(unsigned char)c); }\r\n#ifdef _UNICODE\r\ninline wchar_t MyCharLower(wchar_t c)\r\n  { return (wchar_t)CharLowerW((LPWSTR)c); }\r\n#else\r\nwchar_t MyCharLower(wchar_t c);\r\n#endif\r\n\r\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\r\n#else\r\nwchar_t * MyStringUpper(wchar_t *s);\r\n#endif\r\n\r\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\r\n#ifdef _UNICODE\r\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\r\n#else\r\nwchar_t * MyStringLower(wchar_t *s);\r\n#endif\r\n\r\n#else // Standard-C\r\nwchar_t MyCharUpper(wchar_t c);\r\n#endif\r\n\r\n//////////////////////////////////////\r\n// Compare\r\n\r\n/*\r\n#ifndef _WIN32_WCE\r\nint MyStringCollate(const char *s1, const char *s2);\r\nint MyStringCollateNoCase(const char *s1, const char *s2);\r\n#endif\r\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\r\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\r\n*/\r\n\r\nint MyStringCompare(const char *s1, const char  *s2);\r\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\r\n\r\n#ifdef _WIN32\r\nint MyStringCompareNoCase(const char *s1, const char  *s2);\r\n#endif\r\n\r\nint MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2);\r\n\r\ntemplate <class T>\r\nclass CStringBase\r\n{\r\n  void TrimLeftWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    while (charSet.Find(*p) >= 0 && (*p != 0))\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, (int)(p - _chars));\r\n  }\r\n  void TrimRightWithCharSet(const CStringBase &charSet)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (charSet.Find(*p) >= 0)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = (int)(pLast - _chars);\r\n      Delete(i, _length - i);\r\n    }\r\n\r\n  }\r\n  void MoveItems(int destIndex, int srcIndex)\r\n  {\r\n    memmove(_chars + destIndex, _chars + srcIndex, \r\n        sizeof(T) * (_length - srcIndex + 1));\r\n  }\r\n  \r\n  void InsertSpace(int &index, int size)\r\n  {\r\n    CorrectIndex(index);\r\n    GrowLength(size);\r\n    MoveItems(index + size, index);\r\n  }\r\n\r\n  static T *GetNextCharPointer(T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static const T *GetNextCharPointer(const T *p)\r\n    { return MyStringGetNextCharPointer(p); }\r\n  static T *GetPrevCharPointer(T *base, T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\n  static const T *GetPrevCharPointer(const T *base, const T *p)\r\n    { return MyStringGetPrevCharPointer(base, p); }\r\nprotected:\r\n  T *_chars;\r\n  int _length;\r\n\tint _capacity;\r\n  \r\n  void SetCapacity(int newCapacity)\r\n  {\r\n    int realCapacity = newCapacity + 1;\r\n    if(realCapacity == _capacity)\r\n      return;\r\n    /*\r\n    const int kMaxStringSize = 0x20000000;\r\n    #ifndef _WIN32_WCE\r\n    if(newCapacity > kMaxStringSize || newCapacity < _length)\r\n      throw 1052337;\r\n    #endif\r\n    */\r\n    T *newBuffer = new T[realCapacity];\r\n    if(_capacity > 0)\r\n    {\r\n      for (int i = 0; i < (_length + 1); i++)\r\n        newBuffer[i] = _chars[i];\r\n      delete []_chars;\r\n      _chars = newBuffer;\r\n    }\r\n    else\r\n    {\r\n      _chars = newBuffer;\r\n      _chars[0] = 0;\r\n    }\r\n    _capacity = realCapacity;\r\n  }\r\n\r\n  void GrowLength(int n)\r\n  {\r\n    int freeSize = _capacity - _length - 1;\r\n    if (n <= freeSize) \r\n      return;\r\n    int delta;\r\n    if (_capacity > 64)\r\n      delta = _capacity / 2;\r\n    else if (_capacity > 8)\r\n      delta = 16;\r\n    else\r\n      delta = 4;\r\n    if (freeSize + delta < n)\r\n      delta = n - freeSize;\r\n    SetCapacity(_capacity + delta);\r\n  }\r\n\r\n  void CorrectIndex(int &index) const\r\n  {\r\n    if (index > _length)\r\n      index = _length;\r\n  }\r\n\r\npublic:\r\n  CStringBase(): _chars(0), _length(0), _capacity(0)\r\n    { SetCapacity(16 - 1); }\r\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n  }\r\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\r\n  {\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars); // can be optimized by memove()\r\n    _length = length;\r\n  }\r\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\r\n  {\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n  }\r\n  ~CStringBase() {  delete []_chars; }\r\n\r\n  operator const T*() const { return _chars;} \r\n\r\n  // The minimum size of the character buffer in characters. \r\n  // This value does not include space for a null terminator.\r\n  T* GetBuffer(int minBufLength)\r\n  {\r\n    if(minBufLength >= _capacity)\r\n      SetCapacity(minBufLength + 1);\r\n    return _chars;\r\n  }\r\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\r\n  void ReleaseBuffer(int newLength)\r\n  {\r\n    /*\r\n    #ifndef _WIN32_WCE\r\n    if(newLength >= _capacity)\r\n      throw 282217;\r\n    #endif\r\n    */\r\n    _chars[newLength] = 0;\r\n    _length = newLength;\r\n  }\r\n\r\n  CStringBase& operator=(T c)\r\n  {\r\n    Empty();\r\n    SetCapacity(1);\r\n    _chars[0] = c;\r\n    _chars[1] = 0;\r\n    _length = 1;\r\n    return *this;\r\n  }\r\n  CStringBase& operator=(const T *chars)\r\n  {\r\n    Empty();\r\n    int length = MyStringLen(chars);\r\n    SetCapacity(length);\r\n    MyStringCopy(_chars, chars);\r\n    _length = length; \r\n    return *this;\r\n  }  \r\n  CStringBase& operator=(const CStringBase& s)\r\n  {\r\n    if(&s == this)\r\n      return *this;\r\n    Empty();\r\n    SetCapacity(s._length);\r\n    MyStringCopy(_chars, s._chars);\r\n    _length = s._length;\r\n    return *this;\r\n  }\r\n  \r\n  CStringBase& operator+=(T c)\r\n  {\r\n    GrowLength(1);\r\n    _chars[_length] = c;\r\n    _chars[++_length] = 0;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const T *s)\r\n  {\r\n    int len = MyStringLen(s);\r\n    GrowLength(len);\r\n    MyStringCopy(_chars + _length, s);\r\n    _length += len;\r\n    return *this;\r\n  }\r\n  CStringBase& operator+=(const CStringBase &s)\r\n  {\r\n    GrowLength(s._length);\r\n    MyStringCopy(_chars + _length, s._chars);\r\n    _length += s._length;\r\n    return *this;\r\n  }\r\n  void Empty()\r\n  {\r\n    _length = 0;\r\n    _chars[0] = 0;\r\n  }\r\n  int Length() const { return _length; }\r\n  bool IsEmpty() const { return (_length == 0); }\r\n\r\n  CStringBase Mid(int startIndex) const\r\n    { return Mid(startIndex, _length - startIndex); }\r\n  CStringBase Mid(int startIndex, int count ) const\r\n  {\r\n    if (startIndex + count > _length)\r\n      count = _length - startIndex;\r\n    \r\n    if (startIndex == 0 && startIndex + count == _length)\r\n      return *this;\r\n    \r\n    CStringBase<T> result;\r\n    result.SetCapacity(count);\r\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\r\n    for (int i = 0; i < count; i++)\r\n      result._chars[i] = _chars[startIndex + i];\r\n    result._chars[count] = 0;\r\n    result._length = count;\r\n    return result;\r\n  }\r\n  CStringBase Left(int count) const\r\n    { return Mid(0, count); }\r\n  CStringBase Right(int count) const\r\n  {\r\n    if (count > _length)\r\n      count = _length;\r\n    return Mid(_length - count, count);\r\n  }\r\n\r\n  void MakeUpper()\r\n    { MyStringUpper(_chars); }\r\n  void MakeLower()\r\n    { MyStringLower(_chars); }\r\n\r\n  int Compare(const CStringBase& s) const\r\n    { return MyStringCompare(_chars, s._chars); }\r\n\r\n  int CompareNoCase(const CStringBase& s) const\r\n    { return MyStringCompareNoCase(_chars, s._chars); }\r\n  /*\r\n  int Collate(const CStringBase& s) const\r\n    { return MyStringCollate(_chars, s._chars); }\r\n  int CollateNoCase(const CStringBase& s) const\r\n    { return MyStringCollateNoCase(_chars, s._chars); }\r\n  */\r\n\r\n  int Find(T c) const { return Find(c, 0); }\r\n  int Find(T c, int startIndex) const\r\n  {\r\n    T *p = _chars + startIndex;\r\n    while (true)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (*p == 0)\r\n        return -1;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n  }\r\n  int Find(const CStringBase &s) const { return Find(s, 0); }\r\n  int Find(const CStringBase &s, int startIndex) const\r\n  {\r\n    if (s.IsEmpty())\r\n      return startIndex;\r\n    for (; startIndex < _length; startIndex++)\r\n    {\r\n      int j;\r\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\r\n        if (_chars[startIndex+j] != s._chars[j])\r\n          break;\r\n      if (j == s._length)\r\n        return startIndex;\r\n    }\r\n    return -1;\r\n  }\r\n  int ReverseFind(T c) const\r\n  {\r\n    if (_length == 0)\r\n      return -1;\r\n    T *p = _chars + _length - 1;\r\n    while (true)\r\n    {\r\n      if (*p == c)\r\n        return (int)(p - _chars);\r\n      if (p == _chars)\r\n        return -1;\r\n      p = GetPrevCharPointer(_chars, p);\r\n    }\r\n  }\r\n  int FindOneOf(const CStringBase &s) const\r\n  {\r\n    for(int i = 0; i < _length; i++)\r\n      if (s.Find(_chars[i]) >= 0)\r\n        return i;\r\n      return -1;\r\n  }\r\n\r\n  void TrimLeft(T c)\r\n  {\r\n    const T *p = _chars;\r\n    while (c == *p)\r\n      p = GetNextCharPointer(p);\r\n    Delete(0, p - _chars);\r\n  }\r\n  private:\r\n  CStringBase GetTrimDefaultCharSet()\r\n  {\r\n    CStringBase<T> charSet;\r\n    for(int i = 0; i < (int)(sizeof(kTrimDefaultCharSet) /\r\n      sizeof(kTrimDefaultCharSet[0])); i++)\r\n      charSet += (T)kTrimDefaultCharSet[i];\r\n    return charSet;\r\n  }\r\n  public:\r\n\r\n  void TrimLeft()\r\n  {\r\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight()\r\n  {\r\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\r\n  }\r\n  void TrimRight(T c)\r\n  {\r\n    const T *p = _chars;\r\n    const T *pLast = NULL;\r\n    while (*p != 0)\r\n    {\r\n      if (*p == c)\r\n      {\r\n        if (pLast == NULL)\r\n          pLast = p;\r\n      }\r\n      else\r\n        pLast = NULL;\r\n      p = GetNextCharPointer(p);\r\n    }\r\n    if(pLast != NULL)\r\n    {\r\n      int i = pLast - _chars;\r\n      Delete(i, _length - i);\r\n    }\r\n  }\r\n  void Trim()\r\n  {\r\n    TrimRight();\r\n    TrimLeft();\r\n  }\r\n\r\n  int Insert(int index, T c)\r\n  {\r\n    InsertSpace(index, 1);\r\n    _chars[index] = c;\r\n    _length++;\r\n    return _length;\r\n  }\r\n  int Insert(int index, const CStringBase &s)\r\n  {\r\n    CorrectIndex(index);\r\n    if (s.IsEmpty())\r\n      return _length;\r\n    int numInsertChars = s.Length();\r\n    InsertSpace(index, numInsertChars);\r\n    for(int i = 0; i < numInsertChars; i++)\r\n      _chars[index + i] = s[i];\r\n    _length += numInsertChars;\r\n    return _length;\r\n  }\r\n\r\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\r\n  int Replace(T oldChar, T newChar)\r\n  {\r\n    if (oldChar == newChar)\r\n      return 0;\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < Length())\r\n    {\r\n      pos = Find(oldChar, pos);\r\n      if (pos < 0) \r\n        break;\r\n      _chars[pos] = newChar;\r\n      pos++;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\r\n  {\r\n    if (oldString.IsEmpty())\r\n      return 0;\r\n    if (oldString == newString)\r\n      return 0;\r\n    int oldStringLength = oldString.Length();\r\n    int newStringLength = newString.Length();\r\n    int number  = 0;\r\n    int pos  = 0;\r\n    while (pos < _length)\r\n    {\r\n      pos = Find(oldString, pos);\r\n      if (pos < 0) \r\n        break;\r\n      Delete(pos, oldStringLength);\r\n      Insert(pos, newString);\r\n      pos += newStringLength;\r\n      number++;\r\n    }\r\n    return number;\r\n  }\r\n  int Delete(int index, int count = 1 )\r\n  {\r\n    if (index + count > _length)\r\n      count = _length - index;\r\n    if (count > 0)\r\n    {\r\n      MoveItems(index, index + count);\r\n      _length -= count;\r\n    }\r\n    return _length;\r\n  }\r\n};\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n{\r\n  CStringBase<T> result(s1);\r\n  result += s2;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += c;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(c);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\r\n{\r\n  CStringBase<T> result(s);\r\n  result += chars;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\r\n{\r\n  CStringBase<T> result(chars);\r\n  result += s;\r\n  return result; \r\n}\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) < 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator==(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) == 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const T *s1, const CStringBase<T>& s2)\r\n  { return (s2.Compare(s1) != 0); }\r\n\r\ntemplate <class T>\r\nbool operator!=(const CStringBase<T>& s1, const T *s2)\r\n  { return (s1.Compare(s2) != 0); }\r\n\r\ntypedef CStringBase<char> AString;\r\ntypedef CStringBase<wchar_t> UString;\r\n\r\ntypedef CObjectVector<AString> AStringVector;\r\ntypedef CObjectVector<UString> UStringVector;\r\n\r\n#ifdef _UNICODE\r\n  typedef UString CSysString;\r\n#else\r\n  typedef AString CSysString;\r\n#endif\r\n\r\ntypedef CObjectVector<CSysString> CSysStringVector;\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringConvert.h\"\r\n\r\n#ifndef _WIN32\r\n#include <stdlib.h>\r\n#endif\r\n\r\n#ifdef _WIN32\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = MultiByteToWideChar(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(srcString.Length()), \r\n      srcString.Length() + 1);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282228;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 2;\r\n    int numChars = WideCharToMultiByte(codePage, 0, srcString, \r\n      srcString.Length(), resultString.GetBuffer(numRequiredBytes), \r\n      numRequiredBytes + 1, NULL, NULL);\r\n    #ifndef _WIN32_WCE\r\n    if(numChars == 0)\r\n      throw 282229;\r\n    #endif\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  return resultString;\r\n}\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString)\r\n{\r\n  AString result;\r\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\r\n  result.ReleaseBuffer();\r\n  return result;\r\n}\r\n#endif\r\n\r\n#else\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\r\n{\r\n  UString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += wchar_t(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\r\n{\r\n  AString resultString;\r\n  for (int i = 0; i < srcString.Length(); i++)\r\n    resultString += char(srcString[i]);\r\n  /*\r\n  if(!srcString.IsEmpty())\r\n  {\r\n    int numRequiredBytes = srcString.Length() * 6 + 1;\r\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\r\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\r\n    resultString.ReleaseBuffer(numChars);\r\n  }\r\n  */\r\n  return resultString;\r\n}\r\n\r\n#endif\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\r\n\r\n#ifndef __COMMON_STRINGCONVERT_H\r\n#define __COMMON_STRINGCONVERT_H\r\n\r\n#include \"MyWindows.h\"\r\n#include \"Common/String.h\"\r\n#include \"Types.h\"\r\n\r\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\r\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\r\n\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString)\r\n  { return unicodeString; }\r\ninline UString GetUnicodeString(const AString &ansiString)\r\n  { return MultiByteToUnicodeString(ansiString); }\r\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\r\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\r\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT)\r\n  { return unicodeString; }\r\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT)\r\n  { return unicodeString; }\r\n\r\ninline const char* GetAnsiString(const char* ansiString)\r\n  { return ansiString; }\r\ninline const AString& GetAnsiString(const AString &ansiString)\r\n  { return ansiString; }\r\ninline AString GetAnsiString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString); }\r\n\r\ninline const char* GetOemString(const char* oemString)\r\n  { return oemString; }\r\ninline const AString& GetOemString(const AString &oemString)\r\n  { return oemString; }\r\ninline AString GetOemString(const UString &unicodeString)\r\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\r\n\r\n\r\n#ifdef _UNICODE\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString)\r\n    { return unicodeString;}\r\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT codePage)\r\n    { return unicodeString;}\r\n  inline const UString& GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return unicodeString;}\r\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\r\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\r\n  inline UString GetSystemString(const AString &multiByteString)\r\n    { return MultiByteToUnicodeString(multiByteString);}\r\n#else\r\n  inline const char* GetSystemString(const char *ansiString)\r\n    { return ansiString; }\r\n  inline const AString& GetSystemString(const AString &multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline const char * GetSystemString(const char *multiByteString, UINT)\r\n    { return multiByteString; }\r\n  inline AString GetSystemString(const UString &unicodeString)\r\n    { return UnicodeStringToMultiByte(unicodeString); }\r\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\r\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\r\n#endif\r\n\r\n#ifndef _WIN32_WCE\r\nAString SystemStringToOemString(const CSysString &srcString);\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"StringToInt.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    char c = *s;\r\n    if (c < '0' || c > '7')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result <<= 3;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\r\n{\r\n  UInt64 result = 0;\r\n  while(true)\r\n  {\r\n    wchar_t c = *s;\r\n    if (c < '0' || c > '9')\r\n    {\r\n      if (end != NULL)\r\n        *end = s;\r\n      return result;\r\n    }\r\n    result *= 10;\r\n    result += (c - '0');\r\n    s++;\r\n  }\r\n}\r\n\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end)\r\n{\r\n  if (*s == '-')\r\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\r\n  return ConvertStringToUInt64(s, end);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\r\n\r\n#ifndef __COMMON_STRINGTOINT_H\r\n#define __COMMON_STRINGTOINT_H\r\n\r\n#include <string.h>\r\n#include \"Types.h\"\r\n\r\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertOctStringToUInt64(const char *s, const char **end);\r\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\r\n\r\nInt64 ConvertStringToInt64(const char *s, const char **end);\r\n\r\n#endif\r\n\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/Types.h",
    "content": "// Common/Types.h\r\n\r\n#ifndef __COMMON_TYPES_H\r\n#define __COMMON_TYPES_H\r\n\r\ntypedef unsigned char Byte;\r\ntypedef short Int16;\r\ntypedef unsigned short UInt16;\r\ntypedef int Int32;\r\ntypedef unsigned int UInt32;\r\n#ifdef _MSC_VER\r\ntypedef __int64 Int64;\r\ntypedef unsigned __int64 UInt64;\r\n#else\r\ntypedef long long int Int64;\r\ntypedef unsigned long long int UInt64;\r\n#endif\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/Vector.cpp",
    "content": "// Common/Vector.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include <string.h>\r\n\r\n#include \"Vector.h\"\r\n\r\nCBaseRecordVector::~CBaseRecordVector()\r\n  { delete []((unsigned char *)_items); }\r\nvoid CBaseRecordVector::Clear() \r\n  { DeleteFrom(0); }\r\nvoid CBaseRecordVector::DeleteBack() \r\n  { Delete(_size - 1); }\r\nvoid CBaseRecordVector::DeleteFrom(int index)\r\n  { Delete(index, _size - index); }\r\n\r\nvoid CBaseRecordVector::ReserveOnePosition()\r\n{\r\n  if(_size != _capacity)\r\n    return;\r\n  int delta;\r\n  if (_capacity > 64)\r\n    delta = _capacity / 2;\r\n  else if (_capacity > 8)\r\n    delta = 8;\r\n  else\r\n    delta = 4;\r\n  Reserve(_capacity + delta);\r\n}\r\n\r\nvoid CBaseRecordVector::Reserve(int newCapacity)\r\n{\r\n  if(newCapacity <= _capacity)\r\n    return;\r\n  /*\r\n  #ifndef _DEBUG\r\n  static const unsigned int kMaxVectorSize = 0xF0000000;\r\n  if(newCapacity < _size || \r\n      ((unsigned int )newCapacity * (unsigned int )_itemSize) > kMaxVectorSize) \r\n    throw 1052354;\r\n  #endif\r\n  */\r\n  unsigned char *p = new unsigned char[newCapacity * _itemSize];\r\n  int numRecordsToMove = _capacity;\r\n  memmove(p, _items, _itemSize * numRecordsToMove);\r\n  delete [](unsigned char *)_items;\r\n  _items = p;\r\n  _capacity = newCapacity;\r\n}\r\n\r\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\r\n{\r\n  memmove(((unsigned char *)_items) + destIndex * _itemSize, \r\n    ((unsigned char  *)_items) + srcIndex * _itemSize, \r\n    _itemSize * (_size - srcIndex));\r\n}\r\n\r\nvoid CBaseRecordVector::InsertOneItem(int index)\r\n{\r\n  ReserveOnePosition();\r\n  MoveItems(index + 1, index);\r\n  _size++;\r\n}\r\n\r\nvoid CBaseRecordVector::Delete(int index, int num)\r\n{\r\n  TestIndexAndCorrectNum(index, num);\r\n  if (num > 0)\r\n  {\r\n    MoveItems(index, index + num);\r\n    _size -= num;\r\n  }\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Common/Vector.h",
    "content": "// Common/Vector.h\r\n\r\n#ifndef __COMMON_VECTOR_H\r\n#define __COMMON_VECTOR_H\r\n\r\n#include \"Defs.h\"\r\n\r\nclass CBaseRecordVector\r\n{\r\n  void MoveItems(int destIndex, int srcIndex);\r\nprotected:\r\n\tint _capacity;\r\n  int _size;\r\n\tvoid *_items;\r\n  size_t _itemSize;\r\n\r\n\tvoid ReserveOnePosition();\r\n  void InsertOneItem(int index);\r\n  void TestIndexAndCorrectNum(int index, int &num) const\r\n    { if (index + num > _size) num = _size - index; } \r\npublic:\r\n  CBaseRecordVector(size_t itemSize):\r\n      _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\r\n\tvirtual ~CBaseRecordVector();\r\n  int Size() const { return _size; }\r\n\tbool IsEmpty() const { return (_size == 0); }\r\n\tvoid Reserve(int newCapacity);\r\n\tvirtual void Delete(int index, int num = 1);\r\n\tvoid Clear();\r\n  void DeleteFrom(int index);\r\n  void DeleteBack();\r\n};\r\n\r\ntemplate <class T>\r\nclass CRecordVector: public CBaseRecordVector\r\n{\r\npublic:\r\n  CRecordVector():CBaseRecordVector(sizeof(T)){};\r\n  CRecordVector(const CRecordVector &v):\r\n    CBaseRecordVector(sizeof(T)) { *this = v;}\r\n\tCRecordVector& operator=(const CRecordVector &v)\r\n  {\r\n    Clear();\r\n    return (*this += v);\r\n  }\r\n  CRecordVector& operator+=(const CRecordVector &v)\r\n  {\r\n    int size = v.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(v[i]);\r\n    return *this;\r\n  }\r\n\tint Add(T item)\r\n  {\r\n    ReserveOnePosition();\r\n    ((T *)_items)[_size] = item;\r\n    return _size++;\r\n  }\r\n\tvoid Insert(int index, T item)\r\n  {\r\n    InsertOneItem(index);\r\n    ((T *)_items)[index] = item;\r\n  }\r\n  // T* GetPointer() const { return (T*)_items; }\r\n  // operator const T *() const { return _items; };\r\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\r\n\tT& operator[](int index) { return ((T *)_items)[index]; }\r\n\tconst T& Front() const { return operator[](0); }\r\n  T& Front()   { return operator[](0); }\r\n\tconst T& Back() const { return operator[](_size - 1); }\r\n  T& Back()   { return operator[](_size - 1); }\r\n\r\n  void Swap(int i, int j)\r\n  {\r\n    T temp = operator[](i);\r\n    operator[](i) = operator[](j);\r\n    operator[](j) = temp;\r\n  }\r\n\r\n  void Sort(int left, int right)\r\n  { \r\n    if (right - left < 2)\r\n      return;\r\n    Swap(left, (left + right) / 2);\r\n    int last = left;\r\n    for (int i = left; i < right; i++)\r\n      if (operator[](i) < operator[](left))\r\n        Swap(++last, i);\r\n    Swap(left, last);\r\n    Sort(left, last);\r\n    Sort(last + 1, right);\r\n  }\r\n  void Sort() { Sort(0, Size());  }\r\n  void Sort(int left, int right, int (*compare)(const T*, const T*, void *), void *param)\r\n  { \r\n    if (right - left < 2)\r\n      return;\r\n    Swap(left, (left + right) / 2);\r\n    int last = left;\r\n    for (int i = left; i < right; i++)\r\n      if (compare(&operator[](i), &operator[](left), param) < 0)\r\n        Swap(++last, i);\r\n    Swap(left, last);\r\n    Sort(left, last, compare, param);\r\n    Sort(last + 1, right, compare, param);\r\n  }\r\n\r\n  void Sort(int (*compare)(const T*, const T*, void *), void *param) \r\n  {  \r\n    Sort(0, Size(), compare, param);  \r\n  }\r\n};\r\n\r\ntypedef CRecordVector<int> CIntVector;\r\ntypedef CRecordVector<unsigned int> CUIntVector;\r\ntypedef CRecordVector<bool> CBoolVector;\r\ntypedef CRecordVector<unsigned char> CByteVector;\r\ntypedef CRecordVector<void *> CPointerVector;\r\n\r\ntemplate <class T>\r\nclass CObjectVector: public CPointerVector\r\n{\r\npublic:\r\n  CObjectVector(){};\r\n  ~CObjectVector() { Clear(); }\r\n  CObjectVector(const CObjectVector &objectVector)\r\n    { *this = objectVector; }\r\n\tCObjectVector& operator=(const CObjectVector &objectVector)\r\n  {\r\n    Clear();\r\n    return (*this += objectVector);\r\n  }\r\n\tCObjectVector& operator+=(const CObjectVector &objectVector)\r\n  {\r\n    int size = objectVector.Size();\r\n    Reserve(Size() + size);\r\n    for(int i = 0; i < size; i++)\r\n      Add(objectVector[i]);\r\n    return *this;\r\n  }\r\n\tconst T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\r\n\tT& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\r\n\tT& Front() { return operator[](0); }\r\n\tconst T& Front() const { return operator[](0); }\r\n\tT& Back() { return operator[](_size - 1); }\r\n\tconst T& Back() const { return operator[](_size - 1); }\r\n\tint Add(const T& item)\r\n    { return CPointerVector::Add(new T(item)); }\r\n\tvoid Insert(int index, const T& item)\r\n    { CPointerVector::Insert(index, new T(item)); }\r\n\tvirtual void Delete(int index, int num = 1)\r\n  {\r\n    TestIndexAndCorrectNum(index, num);\r\n    for(int i = 0; i < num; i++)\r\n      delete (T *)(((void **)_items)[index + i]);\r\n    CPointerVector::Delete(index, num);\r\n  }\r\n  int Find(const T& item) const\r\n  {\r\n    for(int i = 0; i < Size(); i++)\r\n      if (item == (*this)[i])\r\n        return i;\r\n      return -1;\r\n  }\r\n  int FindInSorted(const T& item) const\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n        return mid;\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    return -1;\r\n  }\r\n  int AddToSorted(const T& item)\r\n  {\r\n    int left = 0, right = Size(); \r\n    while (left != right)\r\n    {\r\n      int mid = (left + right) / 2;\r\n      const T& midValue = (*this)[mid];\r\n      if (item == midValue)\r\n      {\r\n        right = mid + 1;\r\n        break;\r\n      }\r\n      if (item < midValue)\r\n        right = mid;\r\n      else\r\n        left = mid + 1;\r\n    }\r\n    Insert(right, item);\r\n    return right;\r\n  }\r\n\r\n  void Sort(int (*compare)(void *const *, void *const *, void *), void *param) \r\n    { CPointerVector::Sort(compare, param); }\r\n\r\n  static int CompareObjectItems(void *const *a1, void *const *a2, void *param)\r\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\r\n  void Sort() { CPointerVector::Sort(CompareObjectItems, 0); }\r\n};\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Windows/Defs.h",
    "content": "// Windows/Defs.h\r\n\r\n#ifndef __WINDOWS_DEFS_H\r\n#define __WINDOWS_DEFS_H\r\n\r\ninline bool BOOLToBool(BOOL value)\r\n  { return (value != FALSE); }\r\n\r\ninline BOOL BoolToBOOL(bool value)\r\n  { return (value ? TRUE: FALSE); }\r\n\r\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\r\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\r\n\r\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\r\n  { return (value != VARIANT_FALSE); }\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\r\n\r\n#include \"StdAfx.h\"\r\n\r\n#include \"FileIO.h\"\r\n#include \"Defs.h\"\r\n#ifndef _UNICODE\r\n#include \"../Common/StringConvert.h\"\r\n#endif\r\n\r\n#ifndef _UNICODE\r\nextern bool g_IsNT;\r\n#endif\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nCFileBase::~CFileBase() { Close(); }\r\n\r\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  Close();\r\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE) NULL);\r\n  return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));\r\n}\r\n\r\n#ifndef _UNICODE\r\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\r\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n{\r\n  if (g_IsNT)\r\n  {\r\n    Close();\r\n    _handle = ::CreateFileW(fileName, desiredAccess, shareMode, \r\n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \r\n      flagsAndAttributes, (HANDLE) NULL);\r\n    return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));\r\n  }\r\n  return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP), \r\n    desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\r\n}\r\n#endif\r\n\r\nbool CFileBase::Close()\r\n{\r\n  if(!_fileIsOpen)\r\n    return true;\r\n  bool result = BOOLToBool(::CloseHandle(_handle));\r\n  _fileIsOpen = !result;\r\n  return result;\r\n}\r\n\r\nbool CFileBase::GetPosition(UInt64 &position) const\r\n{\r\n  return Seek(0, FILE_CURRENT, position);\r\n}\r\n\r\nbool CFileBase::GetLength(UInt64 &length) const\r\n{\r\n  DWORD sizeHigh;\r\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\r\n  if(sizeLow == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR)\r\n      return false;\r\n  length = (((UInt64)sizeHigh) << 32) + sizeLow;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const\r\n{\r\n  LARGE_INTEGER value;\r\n  value.QuadPart = distanceToMove;\r\n  value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);\r\n  if (value.LowPart == 0xFFFFFFFF)\r\n    if(::GetLastError() != NO_ERROR) \r\n      return false;\r\n  newPosition = value.QuadPart;\r\n  return true;\r\n}\r\n\r\nbool CFileBase::Seek(UInt64 position, UInt64 &newPosition)\r\n{\r\n  return Seek(position, FILE_BEGIN, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToBegin()\r\n{\r\n  UInt64 newPosition;\r\n  return Seek(0, newPosition);\r\n}\r\n\r\nbool CFileBase::SeekToEnd(UInt64 &newPosition)\r\n{\r\n  return Seek(0, FILE_END, newPosition);\r\n}\r\n\r\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\r\n{\r\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\r\n  if(!::GetFileInformationByHandle(_handle, &winFileInfo))\r\n    return false;\r\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\r\n  fileInfo.CreationTime = winFileInfo.ftCreationTime;\r\n  fileInfo.LastAccessTime = winFileInfo.ftLastAccessTime;\r\n  fileInfo.LastWriteTime = winFileInfo.ftLastWriteTime;\r\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes; \r\n  fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) +  winFileInfo.nFileSizeLow;\r\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\r\n  fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// CInFile\r\n\r\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::Open(LPCTSTR fileName)\r\n  { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n\r\n#ifndef _UNICODE\r\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nbool CInFile::Open(LPCWSTR fileName)\r\n  { return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }\r\n#endif\r\n\r\n// ReadFile and WriteFile functions in Windows have BUG:\r\n// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) \r\n// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES \r\n// (Insufficient system resources exist to complete the requested service).\r\n\r\nstatic UInt32 kChunkSizeMax = (1 << 24);\r\n\r\nbool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = ReadPart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (void *)((unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\n/////////////////////////\r\n// COutFile\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }\r\n\r\nstatic inline DWORD GetCreationDisposition(bool createAlways)\r\n  { return createAlways? CREATE_ALWAYS: CREATE_NEW; }\r\n\r\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#ifndef _UNICODE\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\r\n  { return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,      creationDisposition, flagsAndAttributes); }\r\n\r\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\r\n  { return Open(fileName, FILE_SHARE_READ,  creationDisposition, FILE_ATTRIBUTE_NORMAL); }\r\n\r\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\r\n  { return Open(fileName, GetCreationDisposition(createAlways)); }\r\n\r\n#endif\r\n\r\nbool COutFile::SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\r\n  { return BOOLToBool(::SetFileTime(_handle, creationTime, lastAccessTime, lastWriteTime)); }\r\n\r\nbool COutFile::SetLastWriteTime(const FILETIME *lastWriteTime)\r\n  {  return SetTime(NULL, NULL, lastWriteTime); }\r\n\r\nbool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  if (size > kChunkSizeMax)\r\n    size = kChunkSizeMax;\r\n  DWORD processedLoc = 0;\r\n  bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));\r\n  processedSize = (UInt32)processedLoc;\r\n  return res;\r\n}\r\n\r\nbool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)\r\n{\r\n  processedSize = 0;\r\n  do\r\n  {\r\n    UInt32 processedLoc = 0;\r\n    bool res = WritePart(data, size, processedLoc);\r\n    processedSize += processedLoc;\r\n    if (!res)\r\n      return false;\r\n    if (processedLoc == 0)\r\n      return true;\r\n    data = (const void *)((const unsigned char *)data + processedLoc);\r\n    size -= processedLoc;\r\n  }\r\n  while (size > 0);\r\n  return true;\r\n}\r\n\r\nbool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }\r\n\r\nbool COutFile::SetLength(UInt64 length)\r\n{\r\n  UInt64 newPosition;\r\n  if(!Seek(length, newPosition))\r\n    return false;\r\n  if(newPosition != length)\r\n    return false;\r\n  return SetEndOfFile();\r\n}\r\n\r\n}}}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\r\n\r\n#ifndef __WINDOWS_FILEIO_H\r\n#define __WINDOWS_FILEIO_H\r\n\r\n#include \"../Common/Types.h\"\r\n\r\nnamespace NWindows {\r\nnamespace NFile {\r\nnamespace NIO {\r\n\r\nstruct CByHandleFileInfo\r\n{ \r\n  DWORD    Attributes; \r\n  FILETIME CreationTime; \r\n  FILETIME LastAccessTime; \r\n  FILETIME LastWriteTime; \r\n  DWORD    VolumeSerialNumber; \r\n  UInt64   Size;\r\n  DWORD    NumberOfLinks; \r\n  UInt64   FileIndex; \r\n};\r\n\r\nclass CFileBase\r\n{\r\nprotected:\r\n  bool _fileIsOpen;\r\n  HANDLE _handle;\r\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #ifndef _UNICODE\r\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\r\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\r\n  #endif\r\n\r\npublic:\r\n  CFileBase(): _fileIsOpen(false){};\r\n  virtual ~CFileBase();\r\n\r\n  virtual bool Close();\r\n\r\n  bool GetPosition(UInt64 &position) const;\r\n  bool GetLength(UInt64 &length) const;\r\n\r\n  bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;\r\n  bool Seek(UInt64 position, UInt64 &newPosition); \r\n  bool SeekToBegin(); \r\n  bool SeekToEnd(UInt64 &newPosition); \r\n  \r\n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\r\n};\r\n\r\nclass CInFile: public CFileBase\r\n{\r\npublic:\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName);\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName);\r\n  #endif\r\n  bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Read(void *data, UInt32 size, UInt32 &processedSize);\r\n};\r\n\r\nclass COutFile: public CFileBase\r\n{\r\n  // DWORD m_CreationDisposition;\r\npublic:\r\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\r\n  bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCTSTR fileName, bool createAlways);\r\n\r\n  #ifndef _UNICODE\r\n  bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);\r\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\r\n  bool Create(LPCWSTR fileName, bool createAlways);\r\n  #endif\r\n\r\n  /*\r\n  void SetOpenCreationDisposition(DWORD creationDisposition)\r\n    { m_CreationDisposition = creationDisposition; }\r\n  void SetOpenCreationDispositionCreateAlways()\r\n    { m_CreationDisposition = CREATE_ALWAYS; }\r\n  */\r\n\r\n  bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\r\n  bool SetLastWriteTime(const FILETIME *lastWriteTime);\r\n  bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool Write(const void *data, UInt32 size, UInt32 &processedSize);\r\n  bool SetEndOfFile();\r\n  bool SetLength(UInt64 length);\r\n};\r\n\r\n}}}\r\n\r\n#endif\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/C/Windows/StdAfx.h",
    "content": "// StdAfx.h\r\n\r\n#ifndef __STDAFX_H\r\n#define __STDAFX_H\r\n\r\n#include \"../Common/MyWindows.h\"\r\n#include \"../Common/NewHandler.h\"\r\n\r\n#endif \r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CPL.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n<HTML><HEAD><TITLE>Common Public License - v 1.0</TITLE>\r\n<META http-equiv=Content-Type content=\"text/html; charset=ISO-8859-1\">\r\n<BODY vLink=#800000 bgColor=#ffffff>\r\n<P align=center><B>Common Public License - v 1.0</B> \r\n<P><B></B><FONT size=3></FONT>\r\n<P><FONT size=3></FONT><FONT size=2>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER \r\nTHE TERMS OF THIS COMMON PUBLIC LICENSE (\"AGREEMENT\"). ANY USE, REPRODUCTION OR \r\nDISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS \r\nAGREEMENT.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2><B>1. DEFINITIONS</B></FONT> \r\n<P><FONT size=2>\"Contribution\" means:</FONT> \r\n<UL><FONT size=2>a) in the case of the initial Contributor, the initial code \r\n  and documentation distributed under this Agreement, and<BR clear=left>b) in \r\n  the case of each subsequent Contributor:</FONT></UL>\r\n<UL><FONT size=2>i) changes to the Program, and</FONT></UL>\r\n<UL><FONT size=2>ii) additions to the Program;</FONT></UL>\r\n<UL><FONT size=2>where such changes and/or additions to the Program originate \r\n  from and are distributed by that particular Contributor. </FONT><FONT size=2>A \r\n  Contribution 'originates' from a Contributor if it was added to the Program by \r\n  such Contributor itself or anyone acting on such Contributor's behalf. \r\n  </FONT><FONT size=2>Contributions do not include additions to the Program \r\n  which: (i) are separate modules of software distributed in conjunction with \r\n  the Program under their own license agreement, and (ii) are not derivative \r\n  works of the Program. </FONT></UL>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>\"Contributor\" means any person or entity that distributes the \r\nProgram.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2>\"Licensed Patents \" mean patent claims licensable by a \r\nContributor which are necessarily infringed by the use or sale of its \r\nContribution alone or when combined with the Program. </FONT>\r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2>\"Program\" means the Contributions \r\ndistributed in accordance with this Agreement.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>\"Recipient\" means anyone who receives the Program under this \r\nAgreement, including all Contributors.</FONT> \r\n<P><FONT size=2><B></B></FONT>\r\n<P><FONT size=2><B>2. GRANT OF RIGHTS</B></FONT> \r\n<UL><FONT size=2></FONT><FONT size=2>a) </FONT><FONT size=2>Subject to the \r\n  terms of this Agreement, each Contributor hereby grants</FONT><FONT size=2> \r\n  Recipient a non-exclusive, worldwide, royalty-free copyright license \r\n  to</FONT><FONT color=#ff0000 size=2> </FONT><FONT size=2>reproduce, prepare \r\n  derivative works of, publicly display, publicly perform, distribute and \r\n  sublicense the Contribution of such Contributor, if any, and such derivative \r\n  works, in source code and object code form.</FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2></FONT><FONT size=2>b) Subject to the terms of this \r\n  Agreement, each Contributor hereby grants </FONT><FONT size=2>Recipient a \r\n  non-exclusive, worldwide,</FONT><FONT color=#008000 size=2> </FONT><FONT \r\n  size=2>royalty-free patent license under Licensed Patents to make, use, sell, \r\n  offer to sell, import and otherwise transfer the Contribution of such \r\n  Contributor, if any, in source code and object code form. This patent license \r\n  shall apply to the combination of the Contribution and the Program if, at the \r\n  time the Contribution is added by the Contributor, such addition of the \r\n  Contribution causes such combination to be covered by the Licensed Patents. \r\n  The patent license shall not apply to any other combinations which include the \r\n  Contribution. No hardware per se is licensed hereunder. </FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2>c) Recipient understands that although each Contributor \r\n  grants the licenses to its Contributions set forth herein, no assurances are \r\n  provided by any Contributor that the Program does not infringe the patent or \r\n  other intellectual property rights of any other entity. Each Contributor \r\n  disclaims any liability to Recipient for claims brought by any other entity \r\n  based on infringement of intellectual property rights or otherwise. As a \r\n  condition to exercising the rights and licenses granted hereunder, each \r\n  Recipient hereby assumes sole responsibility to secure any other intellectual \r\n  property rights needed, if any. For example, if a third party patent license \r\n  is required to allow Recipient to distribute the Program, it is Recipient's \r\n  responsibility to acquire that license before distributing the \r\nProgram.</FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<UL><FONT size=2>d) Each Contributor represents that to its knowledge it has \r\n  sufficient copyright rights in its Contribution, if any, to grant the \r\n  copyright license set forth in this Agreement. </FONT></UL>\r\n<UL><FONT size=2></FONT></UL>\r\n<P><FONT size=2><B>3. REQUIREMENTS</B></FONT> \r\n<P><FONT size=2><B></B>A Contributor may choose to distribute the Program in \r\nobject code form under its own license agreement, provided that:</FONT> \r\n<UL><FONT size=2>a) it complies with the terms and conditions of this \r\n  Agreement; and</FONT></UL>\r\n<UL><FONT size=2>b) its license agreement:</FONT></UL>\r\n<UL><FONT size=2>i) effectively disclaims</FONT><FONT size=2> on behalf of all \r\n  Contributors all warranties and conditions, express and implied, including \r\n  warranties or conditions of title and non-infringement, and implied warranties \r\n  or conditions of merchantability and fitness for a particular purpose; \r\n</FONT></UL>\r\n<UL><FONT size=2>ii) effectively excludes on behalf of all Contributors all \r\n  liability for damages, including direct, indirect, special, incidental and \r\n  consequential damages, such as lost profits; </FONT></UL>\r\n<UL><FONT size=2>iii)</FONT><FONT size=2> states that any provisions which \r\n  differ from this Agreement are offered by that Contributor alone and not by \r\n  any other party; and</FONT></UL>\r\n<UL><FONT size=2>iv) states that source code for the Program is available from \r\n  such Contributor, and informs licensees how to obtain it in a reasonable \r\n  manner on or through a medium customarily used for software \r\n  exchange.</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 \r\n  size=2></FONT></UL>\r\n<UL><FONT color=#ff0000 size=2></FONT><FONT size=2></FONT></UL>\r\n<P><FONT size=2>When the Program is made available in source code form:</FONT> \r\n<UL><FONT size=2>a) it must be made available under this Agreement; and \r\n</FONT></UL>\r\n<UL><FONT size=2>b) a copy of this Agreement must be included with each copy \r\n  of the Program. </FONT></UL>\r\n<P><FONT size=2></FONT><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT>\r\n<P><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT><FONT size=2>Contributors \r\nmay not remove or alter any copyright notices contained within the Program. \r\n</FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>Each Contributor must identify itself as the originator of its \r\nContribution, if any, in a manner that reasonably allows subsequent Recipients \r\nto identify the originator of the Contribution. </FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2><B>4. COMMERCIAL DISTRIBUTION</B></FONT> \r\n<P><FONT size=2>Commercial distributors of software may accept certain \r\nresponsibilities with respect to end users, business partners and the like. \r\nWhile this license is intended to facilitate the commercial use of the Program, \r\nthe Contributor who includes the Program in a commercial product offering should \r\ndo so in a manner which does not create potential liability for other \r\nContributors. Therefore, if a Contributor includes the Program in a commercial \r\nproduct offering, such Contributor (\"Commercial Contributor\") hereby agrees to \r\ndefend and indemnify every other Contributor (\"Indemnified Contributor\") against \r\nany losses, damages and costs (collectively \"Losses\") arising from claims, \r\nlawsuits and other legal actions brought by a third party against the \r\nIndemnified Contributor to the extent caused by the acts or omissions of such \r\nCommercial Contributor in connection with its distribution of the Program in a \r\ncommercial product offering. The obligations in this section do not apply to any \r\nclaims or Losses relating to any actual or alleged intellectual property \r\ninfringement. In order to qualify, an Indemnified Contributor must: a) promptly \r\nnotify the Commercial Contributor in writing of such claim, and b) allow the \r\nCommercial Contributor to control, and cooperate with the Commercial Contributor \r\nin, the defense and any related settlement negotiations. The Indemnified \r\nContributor may participate in any such claim at its own expense.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>For example, a Contributor might include the Program in a \r\ncommercial product offering, Product X. That Contributor is then a Commercial \r\nContributor. If that Commercial Contributor then makes performance claims, or \r\noffers warranties related to Product X, those performance claims and warranties \r\nare such Commercial Contributor's responsibility alone. Under this section, the \r\nCommercial Contributor would have to defend claims against the other \r\nContributors related to those performance claims and warranties, and if a court \r\nrequires any other Contributor to pay any damages as a result, the Commercial \r\nContributor must pay those damages.</FONT> \r\n<P><FONT size=2></FONT><FONT color=#0000ff size=2></FONT>\r\n<P><FONT color=#0000ff size=2></FONT><FONT size=2><B>5. NO WARRANTY</B></FONT> \r\n<P><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS \r\nPROVIDED ON AN \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \r\nEITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR \r\nCONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A \r\nPARTICULAR PURPOSE. Each Recipient is</FONT><FONT size=2> solely responsible for \r\ndetermining the appropriateness of using and distributing </FONT><FONT \r\nsize=2>the Program</FONT><FONT size=2> and assumes all risks associated with its \r\nexercise of rights under this Agreement</FONT><FONT size=2>, including but not \r\nlimited to the risks and costs of program errors, compliance with applicable \r\nlaws, damage to or loss of data, </FONT><FONT size=2>programs or equipment, and \r\nunavailability or interruption of operations</FONT><FONT size=2>. </FONT><FONT \r\nsize=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2><B>6. DISCLAIMER OF LIABILITY</B></FONT> \r\n<P><FONT size=2></FONT><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS \r\nAGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR \r\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r\n</FONT><FONT size=2>(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT \r\nsize=2> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, \r\nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \r\nOUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS \r\nGRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2><B>7. GENERAL</B></FONT> \r\n<P><FONT size=2></FONT><FONT size=2>If any provision of this Agreement is \r\ninvalid or unenforceable under applicable law, it shall not affect the validity \r\nor enforceability of the remainder of the terms of this Agreement, and without \r\nfurther action by the parties hereto, such provision shall be reformed to the \r\nminimum extent necessary to make such provision valid and enforceable.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>If Recipient institutes patent litigation against a Contributor \r\nwith respect to a patent applicable to software (including a cross-claim or \r\ncounterclaim in a lawsuit), then any patent licenses granted by that Contributor \r\nto such Recipient under this Agreement shall terminate as of the date such \r\nlitigation is filed. In addition, if Recipient institutes patent litigation \r\nagainst any entity (including a cross-claim or counterclaim in a lawsuit) \r\nalleging that the Program itself (excluding combinations of the Program with \r\nother software or hardware) infringes such Recipient's patent(s), then such \r\nRecipient's rights granted under Section 2(b) shall terminate as of the date \r\nsuch litigation is filed. </FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>All Recipient's rights under this Agreement shall terminate if \r\nit fails to comply with any of the material terms or conditions of this \r\nAgreement and does not cure such failure in a reasonable period of time after \r\nbecoming aware of such noncompliance. If all Recipient's rights under this \r\nAgreement terminate, Recipient agrees to cease use and distribution of the \r\nProgram as soon as reasonably practicable. However, Recipient's obligations \r\nunder this Agreement and any licenses granted by Recipient relating to the \r\nProgram shall continue and survive. </FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2></FONT><FONT size=2>Everyone is permitted to copy and distribute \r\ncopies of this Agreement, but in order to avoid inconsistency the Agreement is \r\ncopyrighted and may only be modified in the following manner. The Agreement \r\nSteward reserves the right to </FONT><FONT size=2>publish new versions \r\n(including revisions) of this Agreement from time to </FONT><FONT size=2>time. \r\nNo one other than the Agreement Steward has the right to modify this Agreement. \r\nIBM is the initial Agreement Steward. IBM may assign the responsibility to serve \r\nas the Agreement Steward to a suitable separate entity. </FONT><FONT size=2>Each \r\nnew version of the Agreement will be given a distinguishing version number. The \r\nProgram (including Contributions) may always be distributed subject to the \r\nversion of the Agreement under which it was received. In addition, after a new \r\nversion of the Agreement is published, Contributor may elect to distribute the \r\nProgram (including its Contributions) under the new </FONT><FONT size=2>version. \r\n</FONT><FONT size=2>Except as expressly stated in Sections 2(a) and 2(b) above, \r\nRecipient receives no rights or licenses to the intellectual property of any \r\nContributor under this Agreement, whether expressly, </FONT><FONT size=2>by \r\nimplication, estoppel or otherwise</FONT><FONT size=2>.</FONT><FONT size=2> All \r\nrights in the Program not expressly granted under this Agreement are \r\nreserved.</FONT> \r\n<P><FONT size=2></FONT>\r\n<P><FONT size=2>This Agreement is governed by the laws of the State of New York \r\nand the intellectual property laws of the United States of America. No party to \r\nthis Agreement will bring a legal action under this Agreement more than one year \r\nafter the cause of action arose. Each party waives its rights to a jury trial in \r\nany resulting litigation.</FONT> \r\n<P><FONT size=2></FONT><FONT size=2></FONT>\r\n<P><FONT size=2></FONT></P></BODY></HTML>\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Common/CRC.cs",
    "content": "// Common/CRC.cs\r\n\r\nnamespace SevenZip\r\n{\r\n\tclass CRC\r\n\t{\r\n\t\tpublic static readonly uint[] Table;\r\n\r\n\t\tstatic CRC()\r\n\t\t{\r\n\t\t\tTable = new uint[256];\r\n\t\t\tconst uint kPoly = 0xEDB88320;\r\n\t\t\tfor (uint i = 0; i < 256; i++)\r\n\t\t\t{\r\n\t\t\t\tuint r = i;\r\n\t\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\t\tr = (r >> 1) ^ kPoly;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tr >>= 1;\r\n\t\t\t\tTable[i] = r;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tuint _value = 0xFFFFFFFF;\r\n\r\n\t\tpublic void Init() { _value = 0xFFFFFFFF; }\r\n\r\n\t\tpublic void UpdateByte(byte b)\r\n\t\t{\r\n\t\t\t_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic void Update(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tfor (uint i = 0; i < size; i++)\r\n\t\t\t\t_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);\r\n\t\t}\r\n\r\n\t\tpublic uint GetDigest() { return _value ^ 0xFFFFFFFF; }\r\n\r\n\t\tstatic uint CalculateDigest(byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\t// crc.Init();\r\n\t\t\tcrc.Update(data, offset, size);\r\n\t\t\treturn crc.GetDigest();\r\n\t\t}\r\n\r\n\t\tstatic bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)\r\n\t\t{\r\n\t\t\treturn (CalculateDigest(data, offset, size) == digest);\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Common/CommandLineParser.cs",
    "content": "// CommandLineParser.cs\r\n\r\nusing System;\r\nusing System.Collections;\r\n\r\nnamespace SevenZip.CommandLineParser\r\n{\r\n\tpublic enum SwitchType\r\n\t{\r\n\t\tSimple,\r\n\t\tPostMinus,\r\n\t\tLimitedPostString,\r\n\t\tUnLimitedPostString,\r\n\t\tPostChar\r\n\t}\r\n\r\n\tpublic class SwitchForm\r\n\t{\r\n\t\tpublic string IDString;\r\n\t\tpublic SwitchType Type;\r\n\t\tpublic bool Multi;\r\n\t\tpublic int MinLen;\r\n\t\tpublic int MaxLen;\r\n\t\tpublic string PostCharSet;\r\n\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi,\r\n\t\t\tint minLen, int maxLen, string postCharSet)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tType = type;\r\n\t\t\tMulti = multi;\r\n\t\t\tMinLen = minLen;\r\n\t\t\tMaxLen = maxLen;\r\n\t\t\tPostCharSet = postCharSet;\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi, int minLen):\r\n\t\t\tthis(idString, type, multi, minLen, 0, \"\")\r\n\t\t{\r\n\t\t}\r\n\t\tpublic SwitchForm(string idString, SwitchType type, bool multi):\r\n\t\t\tthis(idString, type, multi, 0)\r\n\t\t{\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class SwitchResult\r\n\t{\r\n\t\tpublic bool ThereIs;\r\n\t\tpublic bool WithMinus;\r\n\t\tpublic ArrayList PostStrings = new ArrayList();\r\n\t\tpublic int PostCharIndex;\r\n\t\tpublic SwitchResult()\r\n\t\t{\r\n\t\t\tThereIs = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class Parser\r\n\t{\r\n\t\tpublic ArrayList NonSwitchStrings = new ArrayList();\r\n\t\tSwitchResult[] _switches;\r\n\r\n\t\tpublic Parser(int numSwitches)\r\n\t\t{\r\n\t\t\t_switches = new SwitchResult[numSwitches];\r\n\t\t\tfor (int i = 0; i < numSwitches; i++)\r\n\t\t\t\t_switches[i] = new SwitchResult();\r\n\t\t}\r\n\r\n\t\tbool ParseString(string srcString, SwitchForm[] switchForms)\r\n\t\t{\r\n\t\t\tint len = srcString.Length;\r\n\t\t\tif (len == 0)\r\n\t\t\t\treturn false;\r\n\t\t\tint pos = 0;\r\n\t\t\tif (!IsItSwitchChar(srcString[pos]))\r\n\t\t\t\treturn false;\r\n\t\t\twhile (pos < len)\r\n\t\t\t{\r\n\t\t\t\tif (IsItSwitchChar(srcString[pos]))\r\n\t\t\t\t\tpos++;\r\n\t\t\t\tconst int kNoLen = -1;\r\n\t\t\t\tint matchedSwitchIndex = 0;\r\n\t\t\t\tint maxLen = kNoLen;\r\n\t\t\t\tfor (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint switchLen = switchForms[switchIndex].IDString.Length;\r\n\t\t\t\t\tif (switchLen <= maxLen || pos + switchLen > len)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tif (String.Compare(switchForms[switchIndex].IDString, 0,\r\n\t\t\t\t\t\t\tsrcString, pos, switchLen, true) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tmatchedSwitchIndex = switchIndex;\r\n\t\t\t\t\t\tmaxLen = switchLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (maxLen == kNoLen)\r\n\t\t\t\t\tthrow new Exception(\"maxLen == kNoLen\");\r\n\t\t\t\tSwitchResult matchedSwitch = _switches[matchedSwitchIndex];\r\n\t\t\t\tSwitchForm switchForm = switchForms[matchedSwitchIndex];\r\n\t\t\t\tif ((!switchForm.Multi) && matchedSwitch.ThereIs)\r\n\t\t\t\t\tthrow new Exception(\"switch must be single\");\r\n\t\t\t\tmatchedSwitch.ThereIs = true;\r\n\t\t\t\tpos += maxLen;\r\n\t\t\t\tint tailSize = len - pos;\r\n\t\t\t\tSwitchType type = switchForm.Type;\r\n\t\t\t\tswitch (type)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase SwitchType.PostMinus:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = false;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);\r\n\t\t\t\t\t\t\t\tif (matchedSwitch.WithMinus)\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.PostChar:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (tailSize < switchForm.MinLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tstring charSet = switchForm.PostCharSet;\r\n\t\t\t\t\t\t\tconst int kEmptyCharValue = -1;\r\n\t\t\t\t\t\t\tif (tailSize == 0)\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint index = charSet.IndexOf(srcString[pos]);\r\n\t\t\t\t\t\t\t\tif (index < 0)\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = kEmptyCharValue;\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tmatchedSwitch.PostCharIndex = index;\r\n\t\t\t\t\t\t\t\t\tpos++;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase SwitchType.LimitedPostString:\r\n\t\t\t\t\tcase SwitchType.UnLimitedPostString:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint minLen = switchForm.MinLen;\r\n\t\t\t\t\t\t\tif (tailSize < minLen)\r\n\t\t\t\t\t\t\t\tthrow new Exception(\"switch is not full\");\r\n\t\t\t\t\t\t\tif (type == SwitchType.UnLimitedPostString)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(srcString.Substring(pos));\r\n\t\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tString stringSwitch = srcString.Substring(pos, minLen);\r\n\t\t\t\t\t\t\tpos += minLen;\r\n\t\t\t\t\t\t\tfor (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tchar c = srcString[pos];\r\n\t\t\t\t\t\t\t\tif (IsItSwitchChar(c))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\tstringSwitch += c;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmatchedSwitch.PostStrings.Add(stringSwitch);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\r\n\t\t}\r\n\r\n\t\tpublic void ParseStrings(SwitchForm[] switchForms, string[] commandStrings)\r\n\t\t{\r\n\t\t\tint numCommandStrings = commandStrings.Length;\r\n\t\t\tbool stopSwitch = false;\r\n\t\t\tfor (int i = 0; i < numCommandStrings; i++)\r\n\t\t\t{\r\n\t\t\t\tstring s = commandStrings[i];\r\n\t\t\t\tif (stopSwitch)\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t\telse\r\n\t\t\t\t\tif (s == kStopSwitchParsing)\r\n\t\t\t\t\tstopSwitch = true;\r\n\t\t\t\telse\r\n\t\t\t\t\tif (!ParseString(s, switchForms))\r\n\t\t\t\t\tNonSwitchStrings.Add(s);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic SwitchResult this[int index] { get { return _switches[index]; } }\r\n\r\n\t\tpublic static int ParseCommand(CommandForm[] commandForms, string commandString,\r\n\t\t\tout string postString)\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < commandForms.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tstring id = commandForms[i].IDString;\r\n\t\t\t\tif (commandForms[i].PostStringMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (commandString.IndexOf(id) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpostString = commandString.Substring(id.Length);\r\n\t\t\t\t\t\treturn i;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tif (commandString == id)\r\n\t\t\t\t{\r\n\t\t\t\t\tpostString = \"\";\r\n\t\t\t\t\treturn i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tpostString = \"\";\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tstatic bool ParseSubCharsCommand(int numForms, CommandSubCharsSet[] forms,\r\n\t\t\tstring commandString, ArrayList indices)\r\n\t\t{\r\n\t\t\tindices.Clear();\r\n\t\t\tint numUsedChars = 0;\r\n\t\t\tfor (int i = 0; i < numForms; i++)\r\n\t\t\t{\r\n\t\t\t\tCommandSubCharsSet charsSet = forms[i];\r\n\t\t\t\tint currentIndex = -1;\r\n\t\t\t\tint len = charsSet.Chars.Length;\r\n\t\t\t\tfor (int j = 0; j < len; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tchar c = charsSet.Chars[j];\r\n\t\t\t\t\tint newIndex = commandString.IndexOf(c);\r\n\t\t\t\t\tif (newIndex >= 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (currentIndex >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tif (commandString.IndexOf(c, newIndex + 1) >= 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\tcurrentIndex = j;\r\n\t\t\t\t\t\tnumUsedChars++;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (currentIndex == -1 && !charsSet.EmptyAllowed)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tindices.Add(currentIndex);\r\n\t\t\t}\r\n\t\t\treturn (numUsedChars == commandString.Length);\r\n\t\t}\r\n\t\tconst char kSwitchID1 = '-';\r\n\t\tconst char kSwitchID2 = '/';\r\n\r\n\t\tconst char kSwitchMinus = '-';\r\n\t\tconst string kStopSwitchParsing = \"--\";\r\n\r\n\t\tstatic bool IsItSwitchChar(char c)\r\n\t\t{\r\n\t\t\treturn (c == kSwitchID1 || c == kSwitchID2);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class CommandForm\r\n\t{\r\n\t\tpublic string IDString = \"\";\r\n\t\tpublic bool PostStringMode = false;\r\n\t\tpublic CommandForm(string idString, bool postStringMode)\r\n\t\t{\r\n\t\t\tIDString = idString;\r\n\t\t\tPostStringMode = postStringMode;\r\n\t\t}\r\n\t}\r\n\r\n\tclass CommandSubCharsSet\r\n\t{\r\n\t\tpublic string Chars = \"\";\r\n\t\tpublic bool EmptyAllowed = false;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Common/InBuffer.cs",
    "content": "// InBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class InBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_Limit;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tbool m_StreamWasExhausted;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic InBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tm_Stream = stream;\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Limit = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_StreamWasExhausted = false;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadBlock()\r\n\t\t{\r\n\t\t\tif (m_StreamWasExhausted)\r\n\t\t\t\treturn false;\r\n\t\t\tm_ProcessedSize += m_Pos;\r\n\t\t\tint aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);\r\n\t\t\tm_Pos = 0;\r\n\t\t\tm_Limit = (uint)aNumProcessedBytes;\r\n\t\t\tm_StreamWasExhausted = (aNumProcessedBytes == 0);\r\n\t\t\treturn (!m_StreamWasExhausted);\r\n\t\t}\r\n\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// m_Stream.Close(); \r\n\t\t\tm_Stream = null;\r\n\t\t}\r\n\r\n\t\tpublic bool ReadByte(byte b) // check it\r\n\t\t{\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn false;\r\n\t\t\tb = m_Buffer[m_Pos++];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tpublic byte ReadByte()\r\n\t\t{\r\n\t\t\t// return (byte)m_Stream.ReadByte();\r\n\t\t\tif (m_Pos >= m_Limit)\r\n\t\t\t\tif (!ReadBlock())\r\n\t\t\t\t\treturn 0xFF;\r\n\t\t\treturn m_Buffer[m_Pos++];\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize()\r\n\t\t{\r\n\t\t\treturn m_ProcessedSize + m_Pos;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Common/OutBuffer.cs",
    "content": "// OutBuffer.cs\r\n\r\nnamespace SevenZip.Buffer\r\n{\r\n\tpublic class OutBuffer\r\n\t{\r\n\t\tbyte[] m_Buffer;\r\n\t\tuint m_Pos;\r\n\t\tuint m_BufferSize;\r\n\t\tSystem.IO.Stream m_Stream;\r\n\t\tulong m_ProcessedSize;\r\n\r\n\t\tpublic OutBuffer(uint bufferSize)\r\n\t\t{\r\n\t\t\tm_Buffer = new byte[bufferSize];\r\n\t\t\tm_BufferSize = bufferSize;\r\n\t\t}\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream) { m_Stream = stream; }\r\n\t\tpublic void FlushStream() { m_Stream.Flush(); }\r\n\t\tpublic void CloseStream() { m_Stream.Close(); }\r\n\t\tpublic void ReleaseStream() { m_Stream = null; }\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tm_ProcessedSize = 0;\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void WriteByte(byte b)\r\n\t\t{\r\n\t\t\tm_Buffer[m_Pos++] = b;\r\n\t\t\tif (m_Pos >= m_BufferSize)\r\n\t\t\t\tFlushData();\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tif (m_Pos == 0)\r\n\t\t\t\treturn;\r\n\t\t\tm_Stream.Write(m_Buffer, 0, (int)m_Pos);\r\n\t\t\tm_Pos = 0;\r\n\t\t}\r\n\r\n\t\tpublic ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LZ/IMatchFinder.cs",
    "content": "// IMatchFinder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tinterface IInWindowStream\r\n\t{\r\n\t\tvoid Init(System.IO.Stream inStream);\r\n\t\tvoid ReleaseStream();\r\n\t\tvoid MovePos();\r\n\t\tByte GetIndexByte(Int32 index);\r\n\t\tUInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);\r\n\t\tUInt32 GetNumAvailableBytes();\r\n\t}\r\n\r\n\tinterface IMatchFinder : IInWindowStream\r\n\t{\r\n\t\tvoid Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r\n\t\tUInt32 GetLongestMatch(UInt32[] distances);\r\n\t\tvoid DummyLongestMatch();\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LZ/LzBinTree.cs",
    "content": "// LzBinTree.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class BinTree : InWindow, IMatchFinder\r\n\t{\r\n\t\tUInt32 _cyclicBufferPos;\r\n\t\tUInt32 _cyclicBufferSize;\r\n\t\tUInt32 _historySize;\r\n\t\tUInt32 _matchMaxLen;\r\n\r\n\t\t// UInt32 []_dummy;\r\n\t\tUInt32[] _son;\r\n\r\n\t\tUInt32[] _hash;\r\n\t\tUInt32[] _hash2;\r\n\t\tUInt32[] _hash3;\r\n\r\n\t\tUInt32 _cutValue = 0xFF;\r\n\r\n\t\tbool HASH_ARRAY = true;\r\n\t\tbool HASH_BIG = false;\r\n\r\n\t\tconst UInt32 kHash3Size = 1 << 18;\r\n\r\n\t\tconst UInt32 kBT2HashSize = 1 << 16;\r\n\t\tconst UInt32 kBT4Hash2Size = 1 << 10;\r\n\t\tconst UInt32 kBT4Hash4Size = 1 << 20;\r\n\t\tconst UInt32 kBT4bHash4Size = 1 << 23;\r\n\t\tconst UInt32 kBT2NumHashDirectBytes = 2;\r\n\t\tconst UInt32 kBT4NumHashDirectBytes = 0;\r\n\r\n\t\tUInt32 kHash2Size = kBT4Hash2Size;\r\n\t\tUInt32 kNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\t\tUInt32 kNumHashBytes = 4;\r\n\t\tUInt32 kHashSize = kBT4Hash4Size;\r\n\r\n\t\tpublic void SetType(int numHashBytes, bool big)\r\n\t\t{\r\n\t\t\tHASH_ARRAY = numHashBytes > 2;\r\n\t\t\tHASH_BIG = big;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tkHash2Size = kBT4Hash2Size;\r\n\t\t\t\tkNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\t\t\t\tkNumHashBytes = 4;\r\n\t\t\t\tkHashSize = HASH_BIG ? kBT4bHash4Size : kBT4Hash4Size;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tkNumHashDirectBytes = kBT2NumHashDirectBytes;\r\n\t\t\t\tkNumHashBytes = 2;\r\n\t\t\t\tkHashSize = kBT2HashSize;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kEmptyHashValue = 0;\r\n\r\n\t\tconst UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;\r\n\r\n\t\tUInt32 Hash(UInt32 offset, out UInt32 hash2Value, out UInt32 hash3Value)\r\n\t\t{\r\n\t\t\tUInt32 temp = CRC.Table[_bufferBase[offset]] ^ _bufferBase[offset + 1];\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((UInt32)(_bufferBase[offset + 2]) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\treturn (temp ^ (CRC.Table[_bufferBase[offset + 3]] << 5)) & (kHashSize - 1);\r\n\t\t}\r\n\r\n\t\tUInt32 Hash(UInt32 offset)\r\n\t\t{\r\n\t\t\treturn _bufferBase[offset] ^ ((UInt32)(_bufferBase[offset + 1]) << 8);\r\n\t\t}\r\n\r\n\t\tpublic new void Init(System.IO.Stream inStream)\r\n\t\t{\r\n\t\t\tbase.Init(inStream);\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < kHashSize; i++)\r\n\t\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tfor (i = 0; i < kHash2Size; i++)\r\n\t\t\t\t\t_hash2[i] = kEmptyHashValue;\r\n\t\t\t\tfor (i = 0; i < kHash3Size; i++)\r\n\t\t\t\t\t_hash3[i] = kEmptyHashValue;\r\n\t\t\t}\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tReduceOffsets(-1);\r\n\t\t}\r\n\r\n\t\tpublic new void ReleaseStream() { base.ReleaseStream(); }\r\n\r\n\t\tpublic new void MovePos()\r\n\t\t{\r\n\t\t\t_cyclicBufferPos++;\r\n\t\t\tif (_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t\t_cyclicBufferPos = 0;\r\n\t\t\tbase.MovePos();\r\n\t\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }\r\n\r\n\t\tpublic new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{ return base.GetMatchLen(index, distance, limit); }\r\n\r\n\t\tpublic new UInt32 GetNumAvailableBytes() { return base.GetNumAvailableBytes(); }\r\n\r\n\t\tpublic void Create(UInt32 historySize, UInt32 keepAddBufferBefore,\r\n\t\t\tUInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r\n\t\t{\r\n\t\t\t// _dummy = new UInt32[matchMaxLen + 1];\r\n\t\t\tUInt32 windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\r\n\t\t\t_son = null;\r\n\t\t\t_hash = null;\r\n\t\t\t_hash2 = null;\r\n\t\t\t_hash3 = null;\r\n\r\n\t\t\tbase.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\r\n\t\t\tif (_blockSize + 256 > kMaxValForNormalize)\r\n\t\t\t\tthrow new Exception();\r\n\r\n\t\t\t_historySize = historySize;\r\n\t\t\t_matchMaxLen = matchMaxLen;\r\n\r\n\t\t\t_cyclicBufferSize = historySize + 1;\r\n\t\t\t_son = new UInt32[_cyclicBufferSize * 2];\r\n\r\n\t\t\t_hash = new UInt32[kHashSize];\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\t_hash2 = new UInt32[kHash2Size];\r\n\t\t\t\t_hash3 = new UInt32[kHash3Size];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetLongestMatch(UInt32[] distances)\r\n\t\t{\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\tUInt32 matchHashLenMax = 0;\r\n\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t\thashValue = Hash(cur, out hash2Value, out hash3Value);\r\n\t\t\telse\r\n\t\t\t\thashValue = Hash(cur);\r\n\r\n\t\t\tUInt32 curMatch = _hash[hashValue];\r\n\t\t\tUInt32 curMatch2 = 0, curMatch3 = 0;\r\n\t\t\tUInt32 len2Distance = 0;\r\n\t\t\tUInt32 len3Distance = 0;\r\n\t\t\tbool matchLen2Exist = false;\r\n\t\t\tbool matchLen3Exist = false;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\t\tif (curMatch2 >= matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen2Distance = _pos - curMatch2 - 1;\r\n\t\t\t\t\t\tmatchHashLenMax = 2;\r\n\t\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t\t\t\tif (curMatch3 >= matchMinPos)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tlen3Distance = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\t\tmatchHashLenMax = 3;\r\n\t\t\t\t\t\t\tmatchLen3Exist = true;\r\n\t\t\t\t\t\t\tif (matchLen2Exist)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (len3Distance < len2Distance)\r\n\t\t\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t_hash[hashValue] = _pos;\r\n\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t{\r\n\t\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\r\n\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t}\r\n\t\t\t\treturn matchHashLenMax;\r\n\t\t\t}\r\n\t\t\tUInt32 ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptrRight = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 maxLen, minLeft, minRight;\r\n\t\t\tmaxLen = minLeft = minRight = kNumHashDirectBytes;\r\n\r\n\t\t\tdistances[maxLen] = _pos - curMatch - 1;\r\n\r\n\t\t\tfor (UInt32 count = _cutValue; count > 0; count--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 currentLen = Math.Min(minLeft, minRight);\r\n\t\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\t\t\t\twhile (currentLen > maxLen)\r\n\t\t\t\t\tdistances[++maxLen] = delta - 1;\r\n\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tif (currentLen != lenLimit)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] < _bufferBase[cur + currentLen])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\r\n\t\t\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (matchLen2Exist && len2Distance < distances[2])\r\n\t\t\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\t\t\tif (matchLen3Exist && len3Distance < distances[3])\r\n\t\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\treturn maxLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t\t_son[ptrRight] = kEmptyHashValue;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tif (matchLen2Exist)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (maxLen < 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\t\tmaxLen = 2;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (len2Distance < distances[2])\r\n\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tif (matchLen3Exist)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (maxLen < 3)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t\t\tmaxLen = 3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (len3Distance < distances[3])\r\n\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn maxLen;\r\n\t\t}\r\n\r\n\t\tpublic void DummyLongestMatch()\r\n\t\t{\r\n\t\t\t// GetLongestMatch(_dummy);\r\n\r\n\t\t\tUInt32 lenLimit;\r\n\t\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\t\tlenLimit = _matchMaxLen;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\r\n\t\t\tUInt32 cur = _bufferOffset + _pos;\r\n\r\n\t\t\tUInt32 hashValue, hash2Value = 0, hash3Value = 0;\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t\thashValue = Hash(cur, out hash2Value, out hash3Value);\r\n\t\t\telse\r\n\t\t\t\thashValue = Hash(cur);\r\n\r\n\t\t\tUInt32 curMatch = _hash[hashValue];\r\n\t\t\tUInt32 curMatch2 = 0, curMatch3 = 0;\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t\t}\r\n\t\t\t_hash[hashValue] = _pos;\r\n\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t{\r\n\t\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tUInt32 ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\t\tUInt32 ptrRight = (_cyclicBufferPos << 1);\r\n\r\n\t\t\tUInt32 minLeft, minRight;\r\n\t\t\tminLeft = minRight = kNumHashDirectBytes;\r\n\r\n\t\t\tfor (UInt32 count = _cutValue; count > 0; count--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pby1 = _bufferOffset + curMatch;\r\n\t\t\t\tUInt32 currentLen = Math.Min(minLeft, minRight);\r\n\t\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tUInt32 delta = _pos - curMatch;\r\n\r\n\t\t\t\tUInt32 cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\r\n\t\t\t\tif (currentLen != lenLimit)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[pby1 + currentLen] < _bufferBase[cur + currentLen])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t\t_son[ptrRight] = kEmptyHashValue;\r\n\t\t}\r\n\r\n\t\tvoid NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < numItems; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 value = items[i];\r\n\t\t\t\tif (value <= subValue)\r\n\t\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\t\telse\r\n\t\t\t\t\tvalue -= subValue;\r\n\t\t\t\titems[i] = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Normalize()\r\n\t\t{\r\n\t\t\tUInt32 startItem = _pos - _historySize;\r\n\t\t\tUInt32 subValue = startItem - 1;\r\n\t\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\r\n\t\t\tNormalizeLinks(_hash, kHashSize, subValue);\r\n\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tNormalizeLinks(_hash2, kHash2Size, subValue);\r\n\t\t\t\tNormalizeLinks(_hash3, kHash3Size, subValue);\r\n\t\t\t}\r\n\t\t\tReduceOffsets((Int32)subValue);\r\n\t\t}\r\n\r\n\t\tpublic void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LZ/LzInWindow.cs",
    "content": "// LzInWindow.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class InWindow\r\n\t{\r\n\t\tpublic Byte[] _bufferBase = null; // pointer to buffer with data\r\n\t\tSystem.IO.Stream _stream;\r\n\t\tUInt32 _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\t\tbool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\r\n\t\tUInt32 _pointerToLastSafePosition;\r\n\r\n\t\tpublic UInt32 _bufferOffset;\r\n\r\n\t\tpublic UInt32 _blockSize;  // Size of Allocated memory block\r\n\t\tpublic UInt32 _pos;             // offset (from _buffer) of curent byte\r\n\t\tUInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\t\tUInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\t\tUInt32 _keepSizeReserv;  // how many BYTEs must be kept as reserv\r\n\t\tpublic UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\r\n\t\tpublic virtual void BeforeMoveBlock() { }\r\n\t\tpublic virtual void AfterMoveBlock() { }\r\n\r\n\t\tpublic void MoveBlock()\r\n\t\t{\r\n\t\t\tBeforeMoveBlock();\r\n\t\t\tUInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;\r\n\t\t\tUInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;\r\n\r\n\t\t\t// check negative offset ????\r\n\t\t\tfor (UInt32 i = 0; i < numBytes; i++)\r\n\t\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t\t_bufferOffset -= offset;\r\n\t\t\tAfterMoveBlock();\r\n\t\t}\r\n\r\n\t\tpublic virtual void ReadBlock()\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\treturn;\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tint size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);\r\n\t\t\t\tif (size == 0)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tint numReadBytes = _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size);\r\n\t\t\t\tif (numReadBytes == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t\t_posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);\r\n\r\n\t\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t_streamPos += (UInt32)numReadBytes;\r\n\t\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid Free() { _bufferBase = null; }\r\n\r\n\t\tpublic void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\r\n\t\t{\r\n\t\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t\t_keepSizeReserv = keepSizeReserv;\r\n\t\t\tUInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t\t{\r\n\t\t\t\tFree();\r\n\t\t\t\t_blockSize = blockSize;\r\n\t\t\t\t_bufferBase = new Byte[_blockSize];\r\n\t\t\t}\r\n\t\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t_stream = stream;\r\n\t\t\t_bufferOffset = 0;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_streamEndWasReached = false;\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream() { _stream = null; }\r\n\r\n\t\tpublic void MovePos()\r\n\t\t{\r\n\t\t\t_pos++;\r\n\t\t\tif (_pos > _posLimit)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pointerToPostion = _bufferOffset + _pos;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\tMoveBlock();\r\n\t\t\t\tReadBlock();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Byte GetIndexByte(Int32 index) { return _bufferBase[_bufferOffset + _pos + index]; }\r\n\r\n\t\t// index + limit have not to exceed _keepSizeAfter;\r\n\t\tpublic UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)\r\n\t\t{\r\n\t\t\tif (_streamEndWasReached)\r\n\t\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\t\tlimit = _streamPos - (UInt32)(_pos + index);\r\n\t\t\tdistance++;\r\n\t\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\t\tUInt32 pby = _bufferOffset + _pos + (UInt32)index;\r\n\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++) ;\r\n\t\t\treturn i;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetNumAvailableBytes() { return _streamPos - _pos; }\r\n\r\n\t\tpublic void ReduceOffsets(Int32 subValue)\r\n\t\t{\r\n\t\t\t_bufferOffset += (UInt32)subValue;\r\n\t\t\t_posLimit -= (UInt32)subValue;\r\n\t\t\t_pos -= (UInt32)subValue;\r\n\t\t\t_streamPos -= (UInt32)subValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LZ/LzOutWindow.cs",
    "content": "// LzOutWindow.cs\r\n\r\nnamespace SevenZip.Compression.LZ\r\n{\r\n\tpublic class OutWindow\r\n\t{\r\n\t\tbyte[] _buffer = null;\r\n\t\tuint _pos;\r\n\t\tuint _windowSize = 0;\r\n\t\tuint _streamPos;\r\n\t\tSystem.IO.Stream _stream;\r\n\r\n\t\tpublic void Create(uint windowSize)\r\n\t\t{\r\n\t\t\tif (_windowSize != windowSize)\r\n\t\t\t{\r\n\t\t\t\t// System.GC.Collect();\r\n\t\t\t\t_buffer = new byte[windowSize];\r\n\t\t\t}\r\n\t\t\t_windowSize = windowSize;\r\n\t\t\t_pos = 0;\r\n\t\t\t_streamPos = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream, bool solid)\r\n\t\t{\r\n\t\t\tReleaseStream();\r\n\t\t\t_stream = stream;\r\n\t\t\tif (!solid)\r\n\t\t\t{\r\n\t\t\t\t_streamPos = 0;\r\n\t\t\t\t_pos = 0;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Init(System.IO.Stream stream) { Init(stream, false); }\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tFlush();\r\n\t\t\t_stream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Flush()\r\n\t\t{\r\n\t\t\tuint size = _pos - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\t_stream.Write(_buffer, (int)_streamPos, (int)size);\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t_pos = 0;\r\n\t\t\t_streamPos = _pos;\r\n\t\t}\r\n\r\n\t\tpublic void CopyBlock(uint distance, uint len)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\tfor (; len > 0; len--)\r\n\t\t\t{\r\n\t\t\t\tif (pos >= _windowSize)\r\n\t\t\t\t\tpos = 0;\r\n\t\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\t\tFlush();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void PutByte(byte b)\r\n\t\t{\r\n\t\t\t_buffer[_pos++] = b;\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\r\n\t\tpublic byte GetByte(uint distance)\r\n\t\t{\r\n\t\t\tuint pos = _pos - distance - 1;\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos += _windowSize;\r\n\t\t\treturn _buffer[pos];\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LZMA/LzmaBase.cs",
    "content": "// LzmaBase.cs\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tinternal abstract class Base\r\n\t{\r\n\t\tpublic const uint kNumRepDistances = 4;\r\n\t\tpublic const uint kNumStates = 12;\r\n\r\n\t\t// static byte []kLiteralNextStates  = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r\n\t\t// static byte []kMatchNextStates    = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r\n\t\t// static byte []kRepNextStates      = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r\n\t\t// static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r\n\r\n\t\tpublic struct State\r\n\t\t{\r\n\t\t\tpublic uint Index;\r\n\t\t\tpublic void Init() { Index = 0; }\r\n\t\t\tpublic void UpdateChar()\r\n\t\t\t{\r\n\t\t\t\tif (Index < 4) Index = 0;\r\n\t\t\t\telse if (Index < 10) Index -= 3;\r\n\t\t\t\telse Index -= 6;\r\n\t\t\t}\r\n\t\t\tpublic void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }\r\n\t\t\tpublic void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }\r\n\t\t\tpublic void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }\r\n\t\t  public bool IsCharState() { return Index < 7; }\r\n\t\t}\r\n\r\n\t\tpublic const int kNumPosSlotBits = 6;\r\n\t\tpublic const int kDicLogSizeMin = 0;\r\n\t\tpublic const int kDicLogSizeMax = 28;\r\n\t\tpublic const uint kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\r\n\t\tpublic const int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\t\tpublic const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\r\n\t\tpublic const uint kMatchMinLen = 2;\r\n\r\n\t\tpublic static uint GetLenToPosState(uint len)\r\n\t\t{\r\n\t\t\tlen -= kMatchMinLen;\r\n\t\t\tif (len < kNumLenToPosStates)\r\n\t\t\t\treturn len;\r\n\t\t\treturn (uint)(kNumLenToPosStates - 1);\r\n\t\t}\r\n\r\n\t\tpublic const int kNumAlignBits = 4;\r\n\t\tpublic const uint kAlignTableSize = 1 << kNumAlignBits;\r\n\t\tpublic const uint kAlignMask = (kAlignTableSize - 1);\r\n\r\n\t\tpublic const uint kStartPosModelIndex = 4;\r\n\t\tpublic const uint kEndPosModelIndex = 14;\r\n\t\tpublic const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\r\n\t\tpublic const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);\r\n\r\n\t\tpublic const uint kNumLitPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumLitContextBitsMax = 8;\r\n\r\n\t\tpublic const int kNumPosStatesBitsMax = 4;\r\n\t\tpublic const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\t\tpublic const int kNumPosStatesBitsEncodingMax = 4;\r\n\t\tpublic const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\r\n\t\tpublic const int kNumLowLenBits = 3;\r\n\t\tpublic const int kNumMidLenBits = 3;\r\n\t\tpublic const int kNumHighLenBits = 8;\r\n\t\tpublic const uint kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\t\tpublic const uint kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\t\tpublic const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t\t(1 << kNumHighLenBits);\r\n\t\tpublic const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LZMA/LzmaDecoder.cs",
    "content": "// LzmaDecoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream\r\n\t{\r\n\t\tclass LenDecoder\r\n\t\t{\r\n\t\t\tBitDecoder m_Choice = new BitDecoder();\r\n\t\t\tBitDecoder m_Choice2 = new BitDecoder();\r\n\t\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\t\tuint m_NumPosStates = 0;\r\n\r\n\t\t\tpublic void Create(uint numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (uint posState = m_NumPosStates; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\t\tm_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t\tm_NumPosStates = numPosStates;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tm_Choice.Init();\r\n\t\t\t\tfor (uint posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_Choice2.Init();\r\n\t\t\t\tm_HighCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)\r\n\t\t\t{\r\n\t\t\t\tif (m_Choice.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = Base.kNumLowLenSymbols;\r\n\t\t\t\t\tif (m_Choice2.Decode(rangeDecoder) == 0)\r\n\t\t\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tsymbol += Base.kNumMidLenSymbols;\r\n\t\t\t\t\t\tsymbol += m_HighCoder.Decode(rangeDecoder);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tclass LiteralDecoder\r\n\t\t{\r\n\t\t\tstruct Decoder2\r\n\t\t\t{\r\n\t\t\t\tBitDecoder[] m_Decoders;\r\n\t\t\t\tpublic void Create() { m_Decoders = new BitDecoder[0x300]; }\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Decoders[i].Init(); }\r\n\r\n\t\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint symbol = 1;\r\n\t\t\t\t\tdo\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> 7) & 1;\r\n\t\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\t\tuint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\t\tsymbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\t\treturn (byte)symbol;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tDecoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\r\n\r\n\t\t\tpublic byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\r\n\t\t};\r\n\r\n\t\tLZ.OutWindow m_OutWindow = new LZ.OutWindow();\r\n\t\tRangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();\r\n\r\n\t\tBitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tBitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];\r\n\t\tBitDecoder[] m_IsRep0LongDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\t\tBitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\r\n\t\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\r\n\t\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\t\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\r\n\t\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\r\n\t\tuint m_DictionarySize;\r\n\t\tuint m_DictionarySizeCheck;\r\n\r\n\t\tuint m_PosStateMask;\r\n\r\n\t\tpublic Decoder()\r\n\t\t{\r\n\t\t\tm_DictionarySize = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetDictionarySize(uint dictionarySize)\r\n\t\t{\r\n\t\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t\t{\r\n\t\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\t\tm_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);\r\n\t\t\t\tuint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));\r\n\t\t\t\tm_OutWindow.Create(blockSize);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetLiteralProperties(int lp, int lc)\r\n\t\t{\r\n\t\t\tif (lp > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tif (lc > 8)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\t}\r\n\r\n\t\tvoid SetPosBitsProperties(int pb)\r\n\t\t{\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tuint numPosStates = (uint)1 << pb;\r\n\t\t\tm_LenDecoder.Create(numPosStates);\r\n\t\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\t\tm_PosStateMask = numPosStates - 1;\r\n\t\t}\r\n\r\n\t\tvoid Init(System.IO.Stream inStream, System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tm_RangeDecoder.Init(inStream);\r\n\t\t\tm_OutWindow.Init(outStream);\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= m_PosStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint index = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\tm_IsMatchDecoders[index].Init();\r\n\t\t\t\t\tm_IsRep0LongDecoders[index].Init();\r\n\t\t\t\t}\r\n\t\t\t\tm_IsRepDecoders[i].Init();\r\n\t\t\t\tm_IsRepG0Decoders[i].Init();\r\n\t\t\t\tm_IsRepG1Decoders[i].Init();\r\n\t\t\t\tm_IsRepG2Decoders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tm_LiteralDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\t\t// m_PosSpecDecoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\tm_PosDecoders[i].Init();\r\n\r\n\t\t\tm_LenDecoder.Init();\r\n\t\t\tm_RepLenDecoder.Init();\r\n\t\t\tm_PosAlignDecoder.Init();\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\tInit(inStream, outStream);\r\n\r\n\t\t\tBase.State state = new Base.State();\r\n\t\t\tstate.Init();\r\n\t\t\tuint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\r\n\t\t\tUInt64 nowPos64 = 0;\r\n\t\t\tUInt64 outSize64 = (UInt64)outSize;\r\n\t\t\tif (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\tif (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)\r\n\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\tstate.UpdateChar();\r\n\t\t\t\tbyte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);\r\n\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\twhile (nowPos64 < outSize64)\r\n\t\t\t{\r\n\t\t\t\t// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);\r\n\t\t\t\t\t// while(nowPos64 < next)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint posState = (uint)nowPos64 & m_PosStateMask;\r\n\t\t\t\t\tif (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tbyte b;\r\n\t\t\t\t\t\tbyte prevByte = m_OutWindow.GetByte(0);\r\n\t\t\t\t\t\tif (!state.IsCharState())\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,\r\n\t\t\t\t\t\t\t\t(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tb = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);\r\n\t\t\t\t\t\tm_OutWindow.PutByte(b);\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint len;\r\n\t\t\t\t\t\tif (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\t\t\t\t\tm_OutWindow.PutByte(m_OutWindow.GetByte(rep0));\r\n\t\t\t\t\t\t\t\t\tnowPos64++;\r\n\t\t\t\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 distance;\r\n\t\t\t\t\t\t\t\tif (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tif (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t\t\tuint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint numDirectBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (rep0 == 0xFFFFFFFF)\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tthrow new DataErrorException();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\t\t\tnowPos64 += len;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tm_OutWindow.Flush();\r\n\t\t\tm_OutWindow.ReleaseStream();\r\n\t\t\tm_RangeDecoder.ReleaseStream();\r\n\t\t}\r\n\r\n\t\tpublic void SetDecoderProperties(byte[] properties)\r\n\t\t{\r\n\t\t\tif (properties.Length < 5)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tint lc = properties[0] % 9;\r\n\t\t\tint remainder = properties[0] / 9;\r\n\t\t\tint lp = remainder % 5;\r\n\t\t\tint pb = remainder / 5;\r\n\t\t\tif (pb > Base.kNumPosStatesBitsMax)\r\n\t\t\t\tthrow new InvalidParamException();\r\n\t\t\tUInt32 dictionarySize = 0;\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tdictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r\n\t\t\tSetDictionarySize(dictionarySize);\r\n\t\t\tSetLiteralProperties(lp, lc);\r\n\t\t\tSetPosBitsProperties(pb);\r\n\t\t}\r\n\r\n\t\t/*\r\n\t\tpublic override bool CanRead { get { return true; }}\r\n\t\tpublic override bool CanWrite { get { return true; }}\r\n\t\tpublic override bool CanSeek { get { return true; }}\r\n\t\tpublic override long Length { get  { return 0; }}\r\n\t\tpublic override long Position  \r\n\t\t{\r\n\t\t\tget { return 0;\t}\r\n\t\t\tset { }\r\n\t\t}\r\n\t\tpublic override void Flush() { }\r\n\t\tpublic override int Read(byte[] buffer, int offset, int count) \r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t{\r\n\t\t}\r\n\t\tpublic override long Seek(long offset, System.IO.SeekOrigin origin)\r\n\t\t{\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\tpublic override void SetLength(long value) {}\r\n\t\t*/\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LZMA/LzmaEncoder.cs",
    "content": "// LzmaEncoder.cs\r\n\r\nusing System;\r\n\r\nnamespace SevenZip.Compression.LZMA\r\n{\r\n\tusing RangeCoder;\r\n\r\n\tpublic class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties\r\n\t{\r\n\t\tenum EMatchFinderType\r\n\t\t{\r\n\t\t\tBT2,\r\n\t\t\tBT4,\r\n\t\t\tBT4B\r\n\t\t};\r\n\r\n\t\tstatic string[] kMatchFinderIDs = \r\n\t\t{\r\n\t\t\t\"BT2\",\r\n\t\t\t\"BT4\",\r\n\t\t\t\"BT4B\",\r\n\t\t};\r\n\r\n\t\tstatic int FindMatchFinder(string s)\r\n\t\t{\r\n\t\t\tfor (int m = 0; m < kMatchFinderIDs.Length; m++)\r\n\t\t\t\tif (s == kMatchFinderIDs[m])\r\n\t\t\t\t\treturn m;\r\n\t\t\treturn -1;\r\n\t\t}\r\n\r\n\t\tconst UInt32 kIfinityPrice = 0xFFFFFFF;\r\n\r\n\t\tstatic Byte[] g_FastPos = new Byte[1024];\r\n\r\n\t\tstatic Encoder()\r\n\t\t{\r\n\t\t\tconst Byte kFastSlots = 20;\r\n\t\t\tint c = 2;\r\n\t\t\tg_FastPos[0] = 0;\r\n\t\t\tg_FastPos[1] = 1;\r\n\t\t\tfor (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));\r\n\t\t\t\tfor (UInt32 j = 0; j < k; j++, c++)\r\n\t\t\t\t\tg_FastPos[c] = slotFast;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 10))\r\n\t\t\t\treturn g_FastPos[pos];\r\n\t\t\tif (pos < (1 << 19))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 9] + 18);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 18] + 36);\r\n\t\t}\r\n\r\n\t\tstatic UInt32 GetPosSlot2(UInt32 pos)\r\n\t\t{\r\n\t\t\tif (pos < (1 << 16))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 6] + 12);\r\n\t\t\tif (pos < (1 << 25))\r\n\t\t\t\treturn (UInt32)(g_FastPos[pos >> 15] + 30);\r\n\t\t\treturn (UInt32)(g_FastPos[pos >> 24] + 48);\r\n\t\t}\r\n\r\n\t\tBase.State _state = new Base.State();\r\n\t\tByte _previousByte;\r\n\t\tUInt32[] _repDistances = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tvoid BaseInit()\r\n\t\t{\r\n\t\t\t_state.Init();\r\n\t\t\t_previousByte = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t_repDistances[i] = 0;\r\n\t\t}\r\n\r\n\t\tconst int kDefaultDictionaryLogSize = 20;\r\n\t\tconst UInt32 kNumFastBytesDefault = 0x20;\r\n\r\n\t\tclass LiteralEncoder\r\n\t\t{\r\n\t\t\tpublic struct Encoder2\r\n\t\t\t{\r\n\t\t\t\tBitEncoder[] m_Encoders;\r\n\r\n\t\t\t\tpublic void Create() { m_Encoders = new BitEncoder[0x300]; }\r\n\r\n\t\t\t\tpublic void Init() { for (int i = 0; i < 0x300; i++) m_Encoders[i].Init(); }\r\n\r\n\t\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tm_Encoders[context].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tbool same = true;\r\n\t\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)((symbol >> i) & 1);\r\n\t\t\t\t\t\tuint state = context;\r\n\t\t\t\t\t\tif (same)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)((matchByte >> i) & 1);\r\n\t\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tm_Encoders[state].Encode(rangeEncoder, bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tpublic uint GetPrice(bool matchMode, byte matchByte, byte symbol)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint price = 0;\r\n\t\t\t\t\tuint context = 1;\r\n\t\t\t\t\tint i = 7;\r\n\t\t\t\t\tif (matchMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tuint matchBit = (uint)(matchByte >> i) & 1;\r\n\t\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\t\tprice += m_Encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\r\n\t\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tuint bit = (uint)(symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += m_Encoders[context].GetPrice(bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn price;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tEncoder2[] m_Coders;\r\n\t\t\tint m_NumPrevBits;\r\n\t\t\tint m_NumPosBits;\r\n\t\t\tuint m_PosMask;\r\n\r\n\t\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t\t{\r\n\t\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits &&\r\n\t\t\t\t\tm_NumPosBits == numPosBits)\r\n\t\t\t\t\treturn;\r\n\t\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\t\tm_PosMask = ((uint)1 << numPosBits) - 1;\r\n\t\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Create();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tuint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\t\tfor (uint i = 0; i < numStates; i++)\r\n\t\t\t\t\tm_Coders[i].Init();\r\n\t\t\t}\r\n\r\n\t\t\tuint GetState(uint pos, byte prevByte)\r\n\t\t\t{ return ((pos & m_PosMask) << m_NumPrevBits) + (uint)(prevByte >> (8 - m_NumPrevBits)); }\r\n\r\n\t\t\tpublic Encoder2 GetSubCoder(UInt32 pos, Byte prevByte)\r\n\t\t\t{ return m_Coders[GetState(pos, prevByte)]; }\r\n\t\t}\r\n\r\n\t\tclass LenEncoder\r\n\t\t{\r\n\t\t\tRangeCoder.BitEncoder _choice = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitEncoder _choice2 = new RangeCoder.BitEncoder();\r\n\t\t\tRangeCoder.BitTreeEncoder[] _lowCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax]; // kNumLowBits\r\n\t\t\tRangeCoder.BitTreeEncoder[] _midCoder = new RangeCoder.BitTreeEncoder[Base.kNumPosStatesEncodingMax]; // kNumMidBits\r\n\t\t\tRangeCoder.BitTreeEncoder _highCoder = new RangeCoder.BitTreeEncoder(Base.kNumHighLenBits);\r\n\r\n\t\t\tpublic LenEncoder()\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t\t_midCoder[posState] = new RangeCoder.BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Init(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\t_choice.Init();\r\n\t\t\t\t_choice2.Init();\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t{\r\n\t\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_highCoder.Init();\r\n\t\t\t}\r\n\r\n\t\t\tpublic void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\t_choice.Encode(rangeEncoder, 1);\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 0);\r\n\t\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_choice2.Encode(rangeEncoder, 1);\r\n\t\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tpublic UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tUInt32 price = 0;\r\n\t\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _choice.GetPrice0();\r\n\t\t\t\t\tprice += _lowCoder[posState].GetPrice(symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\t\tprice += _choice.GetPrice1();\r\n\t\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprice += _choice2.GetPrice0();\r\n\t\t\t\t\t\tprice += _midCoder[posState].GetPrice(symbol);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprice += _choice2.GetPrice1();\r\n\t\t\t\t\t\tprice += _highCoder.GetPrice(symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst UInt32 kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\r\n\t\tclass LenPriceTableEncoder : LenEncoder\r\n\t\t{\r\n\t\t\tUInt32[] _prices = new UInt32[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\t\tUInt32 _tableSize;\r\n\t\t\tUInt32[] _counters = new UInt32[Base.kNumPosStatesEncodingMax];\r\n\r\n\t\t\tpublic void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; }\r\n\r\n\t\t\tpublic new UInt32 GetPrice(UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\treturn _prices[(symbol << Base.kNumPosStatesBitsEncodingMax) + posState];\r\n\t\t\t}\r\n\r\n\t\t\tvoid UpdateTable(UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 len = 0; len < _tableSize; len++)\r\n\t\t\t\t\t_prices[(len << Base.kNumPosStatesBitsEncodingMax) + posState] = base.GetPrice(len, posState);\r\n\t\t\t\t_counters[posState] = _tableSize;\r\n\t\t\t}\r\n\r\n\t\t\tpublic void UpdateTables(UInt32 numPosStates)\r\n\t\t\t{\r\n\t\t\t\tfor (UInt32 posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\r\n\t\t\tpublic new void Encode(RangeCoder.Encoder rangeEncoder, UInt32 symbol, UInt32 posState)\r\n\t\t\t{\r\n\t\t\t\tbase.Encode(rangeEncoder, symbol, posState);\r\n\t\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\t\tUpdateTable(posState);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst UInt32 kNumOpts = 1 << 12;\r\n\t\tclass Optimal\r\n\t\t{\r\n\t\t\tpublic Base.State State;\r\n\r\n\t\t\tpublic bool Prev1IsChar;\r\n\t\t\tpublic bool Prev2;\r\n\r\n\t\t\tpublic UInt32 PosPrev2;\r\n\t\t\tpublic UInt32 BackPrev2;\r\n\r\n\t\t\tpublic UInt32 Price;\r\n\t\t\tpublic UInt32 PosPrev;         // posNext;\r\n\t\t\tpublic UInt32 BackPrev;\r\n\r\n\t\t\t// public UInt32 []Backs = new UInt32[Base.kNumRepDistances];\r\n\t\t\tpublic UInt32 Backs0;\r\n\t\t\tpublic UInt32 Backs1;\r\n\t\t\tpublic UInt32 Backs2;\r\n\t\t\tpublic UInt32 Backs3;\r\n\r\n\t\t\tpublic void MakeAsChar() { BackPrev = 0xFFFFFFFF; Prev1IsChar = false; }\r\n\t\t\tpublic void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\t\tpublic bool IsShortRep() { return (BackPrev == 0); }\r\n\t\t};\r\n\t\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\r\n\t\tLZ.IMatchFinder _matchFinder = null; // test it\r\n\t\tRangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder();\r\n\r\n\t\tRangeCoder.BitEncoder[] _isMatch = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\tRangeCoder.BitEncoder[] _isRep = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG0 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG1 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRepG2 = new RangeCoder.BitEncoder[Base.kNumStates];\r\n\t\tRangeCoder.BitEncoder[] _isRep0Long = new RangeCoder.BitEncoder[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\r\n\t\tRangeCoder.BitTreeEncoder[] _posSlotEncoder = new RangeCoder.BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\t\tRangeCoder.BitEncoder[] _posEncoders = new RangeCoder.BitEncoder[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\tRangeCoder.BitTreeEncoder _posAlignEncoder = new RangeCoder.BitTreeEncoder(Base.kNumAlignBits);\r\n\r\n\t\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\t\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\r\n\t\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\r\n\t\tUInt32[] _matchDistances = new UInt32[Base.kMatchMaxLen + 1];\r\n\t\tbool _fastMode = false;\r\n\t\tbool _maxMode = false;\r\n\t\tUInt32 _numFastBytes = kNumFastBytesDefault;\r\n\t\tUInt32 _longestMatchLength;\r\n\t\tUInt32 _additionalOffset;\r\n\r\n\t\tUInt32 _optimumEndIndex;\r\n\t\tUInt32 _optimumCurrentIndex;\r\n\r\n\t\tbool _longestMatchWasFound;\r\n\r\n\t\tUInt32[] _posSlotPrices = new UInt32[Base.kDistTableSizeMax << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _distancesPrices = new UInt32[Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\t\tUInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];\r\n\t\tUInt32 _alignPriceCount;\r\n\r\n\t\tUInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\r\n\t\tint _posStateBits = 2;\r\n\t\tUInt32 _posStateMask = (4 - 1);\r\n\t\tint _numLiteralPosStateBits = 0;\r\n\t\tint _numLiteralContextBits = 3;\r\n\r\n\t\tUInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\t\tUInt32 _dictionarySizePrev = 0xFFFFFFFF;\r\n\t\tUInt32 _numFastBytesPrev = 0xFFFFFFFF;\r\n\r\n\t\tInt64 lastPosSlotFillingPos;\r\n\t\tInt64 nowPos64;\r\n\t\tbool _finished;\r\n\r\n\t\tSystem.IO.Stream _inStream;\r\n\t\tEMatchFinderType _matchFinderType = EMatchFinderType.BT4;\r\n\t\tbool _writeEndMark;\r\n\t\tbool _needReleaseMFStream;\r\n\r\n\t\tvoid Create()\r\n\t\t{\r\n\t\t\t// _rangeEncoder.Create(1 << 20);\r\n\t\t\tif (_matchFinder == null)\r\n\t\t\t{\r\n\t\t\t\tLZ.BinTree bt = new LZ.BinTree();\r\n\t\t\t\tint numHashBytes = 4;\r\n\t\t\t\tbool big = false;\r\n\t\t\t\tswitch (_matchFinderType)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase EMatchFinderType.BT2:\r\n\t\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase EMatchFinderType.BT4:\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase EMatchFinderType.BT4B:\r\n\t\t\t\t\t\tbig = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tbt.SetType(numHashBytes, big);\r\n\t\t\t\t_matchFinder = bt;\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\r\n\t\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\t\treturn;\r\n\t\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes,\r\n\t\t\t\tBase.kMatchMaxLen * 2 + 1 - _numFastBytes);\r\n\t\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t\t_numFastBytesPrev = _numFastBytes;\r\n\t\t}\r\n\r\n\t\tpublic Encoder()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t\t_optimum[i] = new Optimal();\r\n\t\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i] = new RangeCoder.BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t\t}\r\n\r\n\t\tvoid SetWriteEndMarkerMode(bool writeEndMarker)\r\n\t\t{\r\n\t\t\t_writeEndMark = writeEndMarker;\r\n\t\t}\r\n\t\tvoid Init()\r\n\t\t{\r\n\t\t\tBaseInit();\r\n\t\t\t_rangeEncoder.Init();\r\n\r\n\t\t\tuint i;\r\n\t\t\tfor (i = 0; i < Base.kNumStates; i++)\r\n\t\t\t{\r\n\t\t\t\tfor (uint j = 0; j <= _posStateMask; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tuint complexState = (i << Base.kNumPosStatesBitsMax) + j;\r\n\t\t\t\t\t_isMatch[complexState].Init();\r\n\t\t\t\t\t_isRep0Long[complexState].Init();\r\n\t\t\t\t}\r\n\t\t\t\t_isRep[i].Init();\r\n\t\t\t\t_isRepG0[i].Init();\r\n\t\t\t\t_isRepG1[i].Init();\r\n\t\t\t\t_isRepG2[i].Init();\r\n\t\t\t}\r\n\t\t\t_literalEncoder.Init();\r\n\t\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\tfor (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)\r\n\t\t\t\t_posEncoders[i].Init();\r\n\r\n\t\t\t_lenEncoder.Init((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.Init((UInt32)1 << _posStateBits);\r\n\r\n\t\t\t_posAlignEncoder.Init();\r\n\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t\t_optimumEndIndex = 0;\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_additionalOffset = 0;\r\n\t\t}\r\n\r\n\t\tvoid ReadMatchDistances(out UInt32 lenRes)\r\n\t\t{\r\n\t\t\tlenRes = _matchFinder.GetLongestMatch(_matchDistances);\r\n\t\t\tif (lenRes == _numFastBytes)\r\n\t\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes, _matchDistances[lenRes],\r\n\t\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t\t_additionalOffset++;\r\n\t\t\t_matchFinder.MovePos();\r\n\t\t}\r\n\r\n\t\tvoid MovePos(UInt32 num)\r\n\t\t{\r\n\t\t\tfor (; num > 0; num--)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.DummyLongestMatch();\r\n\t\t\t\t_matchFinder.MovePos();\r\n\t\t\t\t_additionalOffset++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepLen1Price(Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\treturn _isRepG0[state.Index].GetPrice0() +\r\n\t\t\t\t\t_isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0();\r\n\t\t}\r\n\r\n\t\tUInt32 GetRepPrice(UInt32 repIndex, UInt32 len, Base.State state, UInt32 posState)\r\n\t\t{\r\n\t\t\tUInt32 price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t\tif (repIndex == 0)\r\n\t\t\t{\r\n\t\t\t\tprice += _isRepG0[state.Index].GetPrice0();\r\n\t\t\t\tprice += _isRep0Long[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += _isRepG0[state.Index].GetPrice1();\r\n\t\t\t\tif (repIndex == 1)\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice0();\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += _isRepG1[state.Index].GetPrice1();\r\n\t\t\t\t\tprice += _isRepG2[state.Index].GetPrice(repIndex - 2);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tUInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState)\r\n\t\t{\r\n\t\t\tif (len == 2 && pos >= 0x80)\r\n\t\t\t\treturn kIfinityPrice;\r\n\t\t\tUInt32 price;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\t\tprice = _distancesPrices[(pos << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\t\telse\r\n\t\t\t\tprice = _posSlotPrices[(GetPosSlot2(pos) << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\t}\r\n\r\n\t\tUInt32 Backward(out UInt32 backRes, UInt32 cur)\r\n\t\t{\r\n\t\t\t_optimumEndIndex = cur;\r\n\t\t\tUInt32 posMem = _optimum[cur].PosPrev;\r\n\t\t\tUInt32 backMem = _optimum[cur].BackPrev;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 posPrev = posMem;\r\n\t\t\t\tUInt32 backCur = backMem;\r\n\r\n\t\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\r\n\t\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\t\tcur = posPrev;\r\n\t\t\t}\r\n\t\t\twhile (cur > 0);\r\n\t\t\tbackRes = _optimum[0].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\t\treturn _optimumCurrentIndex;\r\n\t\t}\r\n\r\n\r\n\t\tUInt32[] reps = new UInt32[Base.kNumRepDistances];\r\n\t\tUInt32[] repLens = new UInt32[Base.kNumRepDistances];\r\n\r\n\t\tUInt32 GetOptimum(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t\t{\r\n\t\t\t\tUInt32 lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\t\tbackRes = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\t_optimumCurrentIndex = 0;\r\n\t\t\t_optimumEndIndex = 0; // test it;\r\n\r\n\t\t\tUInt32 lenMain;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tUInt32 i;\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\treps[i] = _repDistances[i];\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tUInt32 backMain = (lenMain < _numFastBytes) ? _matchDistances[lenMain] :\r\n\t\t\t\t\t_matchDistances[_numFastBytes];\r\n\t\t\t\tbackRes = backMain + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\tByte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\r\n\t\t\t_optimum[0].State = _state;\r\n\r\n\t\t\tByte matchByte;\r\n\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - 1));\r\n\r\n\t\t\tUInt32 posState = (position & _posStateMask);\r\n\r\n\t\t\t_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);\r\n\t\t\t_optimum[1].MakeAsChar();\r\n\r\n\t\t\t_optimum[1].PosPrev = 0;\r\n\r\n\t\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t\t_optimum[0].Backs3 = reps[3];\r\n\r\n\r\n\t\t\tUInt32 matchPrice = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\tUInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1();\r\n\r\n\t\t\tif (matchByte == currentByte)\r\n\t\t\t{\r\n\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (lenMain < 2)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _optimum[1].BackPrev;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\r\n\r\n\t\t\tUInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();\r\n\r\n\t\t\tif (lenMain <= repLens[repMaxIndex])\r\n\t\t\t\tlenMain = 0;\r\n\r\n\t\t\tUInt32 len;\r\n\t\t\tfor (len = 2; len <= lenMain; len++)\r\n\t\t\t{\r\n\t\t\t\t_optimum[len].PosPrev = 0;\r\n\t\t\t\t_optimum[len].BackPrev = _matchDistances[len] + Base.kNumRepDistances;\r\n\t\t\t\t_optimum[len].Price = normalMatchPrice +\r\n\t\t\t\t\tGetPosLenPrice(_matchDistances[len], len, posState);\r\n\t\t\t\t_optimum[len].Prev1IsChar = false;\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain < repLens[repMaxIndex])\r\n\t\t\t\tlenMain = repLens[repMaxIndex];\r\n\r\n\t\t\tfor (; len <= lenMain; len++)\r\n\t\t\t\t_optimum[len].Price = kIfinityPrice;\r\n\r\n\t\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 repLen = repLens[i];\r\n\t\t\t\tfor (UInt32 lenTest = 2; lenTest <= repLen; lenTest++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tUInt32 cur = 0;\r\n\t\t\tUInt32 lenEnd = lenMain;\r\n\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tcur++;\r\n\t\t\t\tif (cur == lenEnd)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tposition++;\r\n\t\t\t\tUInt32 posPrev = _optimum[cur].PosPrev;\r\n\t\t\t\tBase.State state;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev--;\r\n\t\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tif (posPrev == cur - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\t\tstate.UpdateShortRep();\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 pos;\r\n\t\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\t\tstate.UpdateRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\tstate.UpdateMatch();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t_optimum[cur].State = state;\r\n\t\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\t\tUInt32 newLen;\r\n\t\t\t\tReadMatchDistances(out newLen);\r\n\t\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t\t{\r\n\t\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\treturn Backward(out backRes, cur);\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 curPrice = _optimum[cur].Price;\r\n\r\n\t\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\t\tmatchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));\r\n\r\n\t\t\t\tposState = (position & _posStateMask);\r\n\r\n\t\t\t\tUInt32 curAnd1Price = curPrice +\r\n\t\t\t\t\t_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!state.IsCharState(), matchByte, currentByte);\r\n\r\n\t\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\r\n\t\t\t\tbool nextIsChar = false;\r\n\t\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\t\tnextIsChar = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tmatchPrice = curPrice + _isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice1();\r\n\t\t\t\trepMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();\r\n\r\n\t\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t\t// nextIsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t/*\r\n\t\t\t\tif(newLen == 2 && _matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t*/\r\n\r\n\t\t\t\tUInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\t\tnumAvailableBytesFull = Math.Min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\t\tUInt32 numAvailableBytes = numAvailableBytesFull;\r\n\r\n\t\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\t\tif (numAvailableBytes >= 3 && !nextIsChar)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 backOffset = reps[0] + 1;\r\n\t\t\t\t\tUInt32 temp;\r\n\t\t\t\t\tfor (temp = 1; temp < numAvailableBytes; temp++)\r\n\t\t\t\t\t\t// if (data[temp] != data[(size_t)temp - backOffset])\r\n\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)temp - 1) != _matchFinder.GetIndexByte((Int32)temp - (Int32)backOffset - 1))\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tUInt32 lenTest2 = temp - 1;\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\tUInt32 posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\t\tUInt32 nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1() +\r\n\t\t\t\t\t\t\t_isRep[state2.Index].GetPrice1();\r\n\t\t\t\t\t\t// for (; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\twhile (lenEnd < cur + 1 + lenTest2)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + 1 + lenTest2];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (UInt32 repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t\t{\r\n\t\t\t\t\t// UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n\t\t\t\t\tUInt32 backOffset = reps[repIndex] + 1;\r\n\t\t\t\t\tif (_matchFinder.GetIndexByte(-1) != \r\n\t\t\t\t\t\t  _matchFinder.GetIndexByte((Int32)(-1 - (Int32)backOffset)) ||\r\n\t\t\t\t\t\t\t_matchFinder.GetIndexByte(0) != \r\n\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)(0 - (Int32)backOffset)))\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tUInt32 lenTest;\r\n\t\t\t\t\tfor (lenTest = 2; lenTest < numAvailableBytes; lenTest++)\r\n\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)lenTest - 1) != \r\n\t\t\t\t\t\t    _matchFinder.GetIndexByte((Int32)lenTest - 1 - (Int32)backOffset))\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tUInt32 lenTestTemp = lenTest;\r\n\t\t\t\t  do\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\t\tlenTest = lenTestTemp;\r\n\r\n\t\t\t\t\tif (_maxMode)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 lenTest2 = lenTest + 1;\r\n\t\t\t\t\t\tUInt32 limit = Math.Min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)((Int32)lenTest2 - 1)) !=\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest2 - 1 - (Int32)backOffset)))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\tstate2.UpdateRep();\r\n\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = \r\n\t\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + \r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest, \r\n\t\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)((Int32)lenTest - 1 - (Int32)backOffset)), \r\n\t\t\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1));\r\n\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\t            \r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price) \r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t//    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n\t\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\t\tif (newLen >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (newLen == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tnormalMatchPrice = matchPrice +\r\n\t\t\t\t\t\t_isRep[state.Index].GetPrice0();\r\n\t\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\r\n\t\t\t\t\tfor (UInt32 lenTest = newLen; lenTest >= 2; lenTest--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 curBack = _matchDistances[lenTest];\r\n\t\t\t\t\t\tUInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (_maxMode && (lenTest == newLen || curBack != _matchDistances[lenTest + 1]))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tUInt32 backOffset = curBack + 1;\r\n\t\t\t\t\t\t\tUInt32 lenTest2 = lenTest + 1;\r\n\t\t\t\t\t\t\tUInt32 limit = Math.Min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\t\t\tif (_matchFinder.GetIndexByte((Int32)lenTest2 - 1) != _matchFinder.GetIndexByte((Int32)lenTest2 - (Int32)backOffset - 1))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tBase.State state2 = state;\r\n\t\t\t\t\t\t\t\tstate2.UpdateMatch();\r\n\t\t\t\t\t\t\t\tUInt32 posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\t\tUInt32 curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\t_isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice0() +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t// data[(size_t)lenTest - 1], \r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t// data[(size_t)lenTest - backOffset], data[lenTest]\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - (Int32)backOffset - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte((Int32)lenTest - 1)\r\n\t\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\tstate2.UpdateChar();\r\n\t\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\t\tUInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[(state2.Index << Base.kNumPosStatesBitsMax) + posStateNext].GetPrice1();\r\n\t\t\t\t\t\t\t\tUInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice1();\r\n\r\n\t\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\tUInt32 offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tbool ChangePair(UInt32 smallDist, UInt32 bigDist)\r\n\t\t{\r\n\t\t\tconst int kDif = 7;\r\n\t\t\treturn (smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t\t}\r\n\r\n\t\tUInt32 GetOptimumFast(UInt32 position, out UInt32 backRes)\r\n\t\t{\r\n\t\t\tUInt32 lenMain;\r\n\t\t\tif (!_longestMatchWasFound)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out lenMain);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t\t_longestMatchWasFound = false;\r\n\t\t\t}\r\n\t\t\tUInt32 repMaxIndex = 0;\r\n\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\t\trepMaxIndex = i;\r\n\t\t\t}\r\n\t\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t\tif (lenMain >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\tbackRes = _matchDistances[_numFastBytes] + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 1);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\twhile (lenMain > 2)\r\n\t\t\t{\r\n\t\t\t\tif (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tlenMain--;\r\n\t\t\t}\r\n\t\t\tif (lenMain == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\t\tlenMain = 1;\r\n\r\n\t\t\tUInt32 backMain = _matchDistances[lenMain];\r\n\t\t\tif (repLens[repMaxIndex] >= 2)\r\n\t\t\t{\r\n\t\t\t\tif (repLens[repMaxIndex] + 1 >= lenMain ||\r\n\t\t\t\t\trepLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 12)))\r\n\t\t\t\t{\r\n\t\t\t\t\tbackRes = repMaxIndex;\r\n\t\t\t\t\tUInt32 lenRes = repLens[repMaxIndex];\r\n\t\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\t\treturn lenRes;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (lenMain >= 2)\r\n\t\t\t{\r\n\t\t\t\tReadMatchDistances(out _longestMatchLength);\r\n\t\t\t\tif (_longestMatchLength >= 2 &&\r\n\t\t\t\t\t(\r\n\t\t\t\t\t(_longestMatchLength >= lenMain &&\r\n\t\t\t\t\t_matchDistances[lenMain] < backMain) ||\r\n\t\t\t\t\t_longestMatchLength == lenMain + 1 &&\r\n\t\t\t\t\t!ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\r\n\t\t\t\t\t_longestMatchLength > lenMain + 1 ||\r\n\t\t\t\t\t_longestMatchLength + 1 >= lenMain && lenMain >= 3 &&\r\n\t\t\t\t\tChangePair(_matchDistances[lenMain - 1], backMain)\r\n\t\t\t\t\t)\r\n\t\t\t\t\t)\r\n\t\t\t\t{\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n\t\t\t\tfor (UInt32 i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 repLen = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\t\t\tif (repLen >= 2 && repLen + 1 >= lenMain)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\t\t\t\treturn 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbackRes = backMain + Base.kNumRepDistances;\r\n\t\t\t\tMovePos(lenMain - 2);\r\n\t\t\t\treturn lenMain;\r\n\t\t\t}\r\n\t\t\tbackRes = 0xFFFFFFFF;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tvoid InitMatchFinder(LZ.IMatchFinder matchFinder)\r\n\t\t{\r\n\t\t\t_matchFinder = matchFinder;\r\n\t\t}\r\n\r\n\t\tvoid WriteEndMarker(UInt32 posState)\r\n\t\t{\r\n\t\t\tif (!_writeEndMark)\r\n\t\t\t\treturn;\r\n\r\n\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 1);\r\n\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t_state.UpdateMatch();\r\n\t\t\tUInt32 len = Base.kMatchMinLen; // kMatchMaxLen;\r\n\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\tUInt32 posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\tint footerBits = 30;\r\n\t\t\tUInt32 posReduced = (((UInt32)1) << footerBits) - 1;\r\n\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t}\r\n\r\n\t\tvoid Flush(UInt32 nowPos)\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t\t_rangeEncoder.FlushData();\r\n\t\t\t_rangeEncoder.FlushStream();\r\n\t\t}\r\n\r\n\t\tpublic void CodeOneBlock(out Int64 inSize, out Int64 outSize, out bool finished)\r\n\t\t{\r\n\t\t\tinSize = 0;\r\n\t\t\toutSize = 0;\r\n\t\t\tfinished = true;\r\n\r\n\t\t\tif (_inStream != null)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.Init(_inStream);\r\n\t\t\t\t_needReleaseMFStream = true;\r\n\t\t\t\t_inStream = null;\r\n\t\t\t}\r\n\r\n\t\t\tif (_finished)\r\n\t\t\t\treturn;\r\n\t\t\t_finished = true;\r\n\r\n\r\n\t\t\tInt64 progressPosValuePrev = nowPos64;\r\n\t\t\tif (nowPos64 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tUInt32 len; // it's not used\r\n\t\t\t\tReadMatchDistances(out len);\r\n\t\t\t\tUInt32 posState = (UInt32)(nowPos64) & _posStateMask;\r\n\t\t\t\t_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t_state.UpdateChar();\r\n\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_additionalOffset--;\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tUInt32 pos;\r\n\t\t\t\tUInt32 posState = ((UInt32)nowPos64) & _posStateMask;\r\n\r\n\t\t\t\tUInt32 len;\r\n\t\t\t\tif (_fastMode)\r\n\t\t\t\t\tlen = GetOptimumFast((UInt32)nowPos64, out pos);\r\n\t\t\t\telse\r\n\t\t\t\t\tlen = GetOptimum((UInt32)nowPos64, out pos);\r\n\r\n\t\t\t\tUInt32 complexState = (_state.Index << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\t\tif (len == 1 && pos == 0xFFFFFFFF)\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\tByte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));\r\n\t\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte);\r\n\t\t\t\t\tif (!_state.IsCharState())\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tByte matchByte = _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t\t_state.UpdateChar();\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_isMatch[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t_isRep0Long[complexState].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_isRepG0[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_isRepG1[_state.Index].Encode(_rangeEncoder, 1);\r\n\t\t\t\t\t\t\t\t_isRepG2[_state.Index].Encode(_rangeEncoder, pos - 2);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_state.UpdateShortRep();\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t\t_state.UpdateRep();\r\n\t\t\t\t\t\t}\r\n\r\n\r\n\t\t\t\t\t\tUInt32 distance = _repDistances[pos];\r\n\t\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tfor (UInt32 i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_isRep[_state.Index].Encode(_rangeEncoder, 0);\r\n\t\t\t\t\t\t_state.UpdateMatch();\r\n\t\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\t\tUInt32 posSlot = GetPosSlot(pos);\r\n\t\t\t\t\t\tUInt32 lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\r\n\t\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\t\tUInt32 posReduced = pos - baseVal;\r\n\r\n\t\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\t\tif (!_fastMode)\r\n\t\t\t\t\t\t\t\t\tif (--_alignPriceCount == 0)\r\n\t\t\t\t\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tUInt32 distance = pos;\r\n\t\t\t\t\t\tfor (UInt32 i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t_previousByte = _matchFinder.GetIndexByte((Int32)(len - 1 - _additionalOffset));\r\n\t\t\t\t}\r\n\t\t\t\t_additionalOffset -= len;\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tif (!_fastMode)\r\n\t\t\t\t\tif (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFillPosSlotPrices();\r\n\t\t\t\t\t\tFillDistancesPrices();\r\n\t\t\t\t\t\tlastPosSlotFillingPos = nowPos64;\r\n\t\t\t\t\t}\r\n\t\t\t\tif (_additionalOffset == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tinSize = nowPos64;\r\n\t\t\t\t\toutSize = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tFlush((UInt32)nowPos64);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_finished = false;\r\n\t\t\t\t\t\tfinished = false;\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid ReleaseMFStream()\r\n\t\t{\r\n\t\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t\t{\r\n\t\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t\t_needReleaseMFStream = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid SetOutStream(System.IO.Stream outStream) { _rangeEncoder.SetStream(outStream); }\r\n\t\tvoid ReleaseOutStream() { _rangeEncoder.ReleaseStream(); }\r\n\r\n\t\tvoid ReleaseStreams()\r\n\t\t{\r\n\t\t\tReleaseMFStream();\r\n\t\t\tReleaseOutStream();\r\n\t\t}\r\n\r\n\t\tvoid SetStreams(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\t\tInt64 inSize, Int64 outSize)\r\n\t\t{\r\n\t\t\t_inStream = inStream;\r\n\t\t\t_finished = false;\r\n\t\t\tCreate();\r\n\t\t\tSetOutStream(outStream);\r\n\t\t\tInit();\r\n\r\n\t\t\t// CCoderReleaser releaser(this);\r\n\r\n\t\t\t/*\r\n\t\t\tif (_matchFinder->GetNumAvailableBytes() == 0)\r\n\t\t\t\treturn Flush();\r\n\t\t\t*/\r\n\r\n\t\t\tif (!_fastMode)\r\n\t\t\t{\r\n\t\t\t\tFillPosSlotPrices();\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tFillAlignPrices();\r\n\t\t\t}\r\n\r\n\t\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_lenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\t\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t\t_repMatchLenEncoder.UpdateTables((UInt32)1 << _posStateBits);\r\n\r\n\t\t\tlastPosSlotFillingPos = 0;\r\n\t\t\tnowPos64 = 0;\r\n\t\t}\r\n\r\n\t\tpublic void Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress)\r\n\t\t{\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\t\twhile (true)\r\n\t\t\t\t{\r\n\t\t\t\t\tInt64 processedInSize;\r\n\t\t\t\t\tInt64 processedOutSize;\r\n\t\t\t\t\tbool finished;\r\n\t\t\t\t\tCodeOneBlock(out processedInSize, out processedOutSize, out finished);\r\n\t\t\t\t\tif (finished)\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t\tif (progress != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tprogress.SetProgress(processedInSize, processedOutSize);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfinally\r\n\t\t\t{\r\n\t\t\t\tReleaseStreams();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void SetCoderProperties(CoderPropID[] propIDs, object[] properties)\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < properties.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tobject prop = properties[i];\r\n\t\t\t\tswitch (propIDs[i])\r\n\t\t\t\t{\r\n\t\t\t\t\tcase CoderPropID.NumFastBytes:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 numFastBytes = (Int32)prop;\r\n\t\t\t\t\t\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_numFastBytes = (UInt32)numFastBytes;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.Algorithm:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 maximize = (Int32)prop;\r\n\t\t\t\t\t\t\t_fastMode = (maximize == 0);\r\n\t\t\t\t\t\t\t_maxMode = (maximize >= 2);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.MatchFinder:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is String))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tEMatchFinderType matchFinderIndexPrev = _matchFinderType;\r\n\t\t\t\t\t\t\tint m = FindMatchFinder(((string)prop).ToUpper());\r\n\t\t\t\t\t\t\tif (m < 0)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_matchFinderType = (EMatchFinderType)m;\r\n\t\t\t\t\t\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t_dictionarySizePrev = 0xFFFFFFFF;\r\n\t\t\t\t\t\t\t\t_matchFinder = null;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.DictionarySize:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tconst int kDicLogSizeMaxCompress = 28;\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t\tInt32 dictionarySize = (Int32)prop;\r\n\t\t\t\t\t\t\tif (dictionarySize < (UInt32)(1 << Base.kDicLogSizeMin) ||\r\n\t\t\t\t\t\t\t\tdictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_dictionarySize = (UInt32)dictionarySize;\r\n\t\t\t\t\t\t\tint dicLogSize;\r\n\t\t\t\t\t\t\tfor (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\r\n\t\t\t\t\t\t\t\tif (dictionarySize <= ((UInt32)(1) << dicLogSize))\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t_distTableSize = (UInt32)dicLogSize * 2;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.PosStateBits:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_posStateBits = (int)v;\r\n\t\t\t\t\t\t\t_posStateMask = (((UInt32)1) << (int)_posStateBits) - 1;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitPosBits:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitPosStatesBitsEncodingMax)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\t_numLiteralPosStateBits = (int)v;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.LitContextBits:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Int32))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tInt32 v = (Int32)prop;\r\n\t\t\t\t\t\t\tif (v < 0 || v > (UInt32)Base.kNumLitContextBitsMax)\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException(); ;\r\n\t\t\t\t\t\t\t_numLiteralContextBits = (int)v;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tcase CoderPropID.EndMarker:\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!(prop is Boolean))\r\n\t\t\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t\t\t\tSetWriteEndMarkerMode((Boolean)prop);\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new InvalidParamException();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst int kPropSize = 5;\r\n\t\tByte[] properties = new Byte[kPropSize];\r\n\r\n\t\tpublic void WriteCoderProperties(System.IO.Stream outStream)\r\n\t\t{\r\n\t\t\tproperties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\t\tproperties[1 + i] = (Byte)(_dictionarySize >> (8 * i));\r\n\t\t\toutStream.Write(properties, 0, kPropSize);\r\n\t\t}\r\n\r\n\t\tvoid FillPosSlotPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 posSlot;\r\n\t\t\t\tfor (posSlot = 0; posSlot < Base.kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\r\n\t\t\t\tfor (; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) +\r\n\t\t\t\t\t\t((((posSlot >> 1) - 1) - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid FillDistancesPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 i;\r\n\t\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tUInt32 posSlot = GetPosSlot(i);\r\n\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\tUInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\r\n\t\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\tRangeCoder.BitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvoid FillAlignPrices()\r\n\t\t{\r\n\t\t\tfor (UInt32 i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t\t_alignPriceCount = Base.kAlignTableSize;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.cs",
    "content": "using System;\r\nusing System.IO;\r\nnamespace SevenZip\r\n{\r\n\tusing CommandLineParser;\r\n\tclass LzmaAlone\r\n\t{\r\n\t\tenum Key\r\n\t\t{\r\n\t\t\tHelp1 = 0,\r\n\t\t\tHelp2,\r\n\t\t\tMode,\r\n\t\t\tDictionary,\r\n\t\t\tFastBytes,\r\n\t\t\tLitContext,\r\n\t\t\tLitPos,\r\n\t\t\tPosBits,\r\n\t\t\tMatchFinder,\r\n\t\t\tEOS,\r\n\t\t\tStdIn,\r\n\t\t\tStdOut\r\n\t\t};\r\n\r\n\t\tstatic void PrintHelp()\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t\"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4, bt4b], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t// + \"  -si:    read data from stdin\\n\"\r\n\t\t\t\t// + \"  -so:    write data to stdout\\n\"\r\n\t\t\t\t);\r\n\t\t}\r\n\r\n\t\tstatic bool GetNumber(string s, out Int32 v)\r\n\t\t{\r\n\t\t\tv = 0;\r\n\t\t\tfor (int i = 0; i < s.Length; i++)\r\n\t\t\t{\r\n\t\t\t\tchar c = s[i];\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tv *= 10;\r\n\t\t\t\tv += (Int32)(c - '0');\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tstatic int IncorrectCommand()\r\n\t\t{\r\n\t\t\tthrow (new Exception(\"Command line error\"));\r\n\t\t\t// System.Console.WriteLine(\"\\nCommand line error\\n\");\r\n\t\t\t// return 1;\r\n\t\t}\r\n\t\tstatic int Main2(string[] args)\r\n\t\t{\r\n\t\t\tSystem.Console.WriteLine(\"\\nLZMA# 4.32 Copyright (c) 1999-2005 Igor Pavlov  2005-12-09\\n\");\r\n\r\n\t\t\tif (args.Length == 0)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSwitchForm[] kSwitchForms = new SwitchForm[12];\r\n\t\t\tint sw = 0;\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"?\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"H\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"A\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"D\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"FB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LC\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"LP\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"PB\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"MF\", SwitchType.UnLimitedPostString, false, 1);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"EOS\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SI\", SwitchType.Simple, false);\r\n\t\t\tkSwitchForms[sw++] = new SwitchForm(\"SO\", SwitchType.Simple, false);\r\n\r\n\r\n\t\t\tParser parser = new Parser(sw);\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tparser.ParseStrings(kSwitchForms, args);\r\n\t\t\t}\r\n\t\t\tcatch\r\n\t\t\t{\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\t}\r\n\r\n\t\t\tif (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tPrintHelp();\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\r\n\t\t\tSystem.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;\r\n\r\n\t\t\tint paramIndex = 0;\r\n\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\treturn IncorrectCommand();\r\n\t\t\tstring command = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\tcommand = command.ToLower();\r\n\r\n\t\t\tbool dictionaryIsDefined = false;\r\n\t\t\tInt32 dictionary = 1 << 21;\r\n\t\t\tif (parser[(int)Key.Dictionary].ThereIs)\r\n\t\t\t{\r\n\t\t\t\tInt32 dicLog;\r\n\t\t\t\tif (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tdictionary = (Int32)1 << dicLog;\r\n\t\t\t\tdictionaryIsDefined = true;\r\n\t\t\t}\r\n\t\t\tstring mf = \"bt4\";\r\n\t\t\tif (parser[(int)Key.MatchFinder].ThereIs)\r\n\t\t\t\tmf = (string)parser[(int)Key.MatchFinder].PostStrings[0];\r\n\t\t\tmf = mf.ToLower();\r\n\r\n\t\t\tif (command == \"b\")\r\n\t\t\t{\r\n\t\t\t\tconst Int32 kNumDefaultItereations = 10;\r\n\t\t\t\tInt32 numIterations = kNumDefaultItereations;\r\n\t\t\t\tif (paramIndex < nonSwitchStrings.Count)\r\n\t\t\t\t\tif (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))\r\n\t\t\t\t\t\tnumIterations = kNumDefaultItereations;\r\n\t\t\t\treturn LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary, mf == \"bt4\");\r\n\t\t\t}\r\n\r\n\t\t\tbool encodeMode = false;\r\n\t\t\tif (command == \"e\")\r\n\t\t\t\tencodeMode = true;\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t\tencodeMode = false;\r\n\t\t\telse\r\n\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\tbool stdInMode = parser[(int)Key.StdIn].ThereIs;\r\n\t\t\tbool stdOutMode = parser[(int)Key.StdOut].ThereIs;\r\n\r\n\t\t\tFileStream inStream = null;\r\n\t\t\tif (stdInMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring inputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\tinStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);\r\n\t\t\t}\r\n\r\n\t\t\tFileStream outStream = null;\r\n\t\t\tif (stdOutMode)\r\n\t\t\t{\r\n\t\t\t\tthrow (new Exception(\"Not implemeted\"));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (paramIndex >= nonSwitchStrings.Count)\r\n\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tstring outputName = (string)nonSwitchStrings[paramIndex++];\r\n\t\t\t\toutStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);\r\n\t\t\t}\r\n\r\n\t\t\tif (encodeMode)\r\n\t\t\t{\r\n\t\t\t\tif (!dictionaryIsDefined)\r\n\t\t\t\t\tdictionary = 1 << 23;\r\n\r\n\t\t\t\tInt32 posStateBits = 2;\r\n\t\t\t\tInt32 litContextBits = 3; // for normal files\r\n\t\t\t\t// UInt32 litContextBits = 0; // for 32-bit data\r\n\t\t\t\tInt32 litPosBits = 0;\r\n\t\t\t\t// UInt32 litPosBits = 2; // for 32-bit data\r\n\t\t\t\tInt32 algorithm = 2;\r\n\t\t\t\tInt32 numFastBytes = 128;\r\n\r\n\t\t\t\tbool eos = parser[(int)Key.EOS].ThereIs || stdInMode;\r\n\r\n\t\t\t\tif (parser[(int)Key.Mode].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tif (parser[(int)Key.FastBytes].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitContext].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.LitPos].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\t\t\t\tif (parser[(int)Key.PosBits].ThereIs)\r\n\t\t\t\t\tif (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))\r\n\t\t\t\t\t\tIncorrectCommand();\r\n\r\n\t\t\t\tCoderPropID[] propIDs = \r\n\t\t\t\t{\r\n\t\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\t\tCoderPropID.PosStateBits,\r\n\t\t\t\t\tCoderPropID.LitContextBits,\r\n\t\t\t\t\tCoderPropID.LitPosBits,\r\n\t\t\t\t\tCoderPropID.Algorithm,\r\n\t\t\t\t\tCoderPropID.NumFastBytes,\r\n\t\t\t\t\tCoderPropID.MatchFinder,\r\n\t\t\t\t\tCoderPropID.EndMarker\r\n\t\t\t\t};\r\n\t\t\t\tobject[] properties = \r\n\t\t\t\t{\r\n\t\t\t\t\t(Int32)(dictionary),\r\n\t\t\t\t\t(Int32)(posStateBits),\r\n\t\t\t\t\t(Int32)(litContextBits),\r\n\t\t\t\t\t(Int32)(litPosBits),\r\n\t\t\t\t\t(Int32)(algorithm),\r\n\t\t\t\t\t(Int32)(numFastBytes),\r\n\t\t\t\t\tmf,\r\n\t\t\t\t\teos\r\n\t\t\t\t};\r\n\r\n\t\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tInt64 fileSize;\r\n\t\t\t\tif (eos || stdInMode)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inStream.Length;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.WriteByte((Byte)(fileSize >> (8 * i)));\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse if (command == \"d\")\r\n\t\t\t{\r\n\t\t\t\tbyte[] properties = new byte[5];\r\n\t\t\t\tif (inStream.Read(properties, 0, 5) != 5)\r\n\t\t\t\t\tthrow (new Exception(\"input .lzma is too short\"));\r\n\t\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\t\t\t\tdecoder.SetDecoderProperties(properties);\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.ReadByte();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow (new Exception(\"Can't Read 1\"));\r\n\t\t\t\t\toutSize |= ((long)(byte)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tlong compressedSize = inStream.Length - inStream.Position;\r\n\t\t\t\tdecoder.Code(inStream, outStream, compressedSize, outSize, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tthrow (new Exception(\"Command Error\"));\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\t[STAThread]\r\n\t\tstatic int Main(string[] args)\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\treturn Main2(args);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tConsole.WriteLine(\"{0} Caught exception #1.\", e);\r\n\t\t\t\t// throw e;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.csproj",
    "content": "﻿<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n    <ProductVersion>8.0.40607</ProductVersion>\r\n    <SchemaVersion>2.0</SchemaVersion>\r\n    <ProjectGuid>{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}</ProjectGuid>\r\n    <OutputType>Exe</OutputType>\r\n    <RootNamespace>LzmaAlone</RootNamespace>\r\n    <AssemblyName>Lzma#</AssemblyName>\r\n    <WarningLevel>4</WarningLevel>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\r\n    <DebugSymbols>true</DebugSymbols>\r\n    <DebugType>full</DebugType>\r\n    <Optimize>false</Optimize>\r\n    <OutputPath>.\\bin\\Debug\\</OutputPath>\r\n    <DefineConstants>DEBUG;TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\r\n    <DebugSymbols>false</DebugSymbols>\r\n    <Optimize>true</Optimize>\r\n    <OutputPath>.\\bin\\Release\\</OutputPath>\r\n    <DefineConstants>TRACE</DefineConstants>\r\n  </PropertyGroup>\r\n  <ItemGroup>\r\n    <Reference Include=\"System\" />\r\n    <Reference Include=\"System.Data\" />\r\n    <Reference Include=\"System.Xml\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Compile Include=\"..\\..\\Common\\CommandLineParser.cs\">\r\n      <Link>Common\\CommandLineParser.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\Common\\CRC.cs\">\r\n      <Link>Common\\CRC.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\..\\ICoder.cs\">\r\n      <Link>ICoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\IMatchFinder.cs\">\r\n      <Link>LZ\\IMatchFinder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzBinTree.cs\">\r\n      <Link>LZ\\LzBinTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzInWindow.cs\">\r\n      <Link>LZ\\LzInWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZ\\LzOutWindow.cs\">\r\n      <Link>LZ\\LzOutWindow.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaBase.cs\">\r\n      <Link>LZMA\\LzmaBase.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaDecoder.cs\">\r\n      <Link>LZMA\\LzmaDecoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\LZMA\\LzmaEncoder.cs\">\r\n      <Link>LZMA\\LzmaEncoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoder.cs\">\r\n      <Link>RangeCoder\\RangeCoder.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBit.cs\">\r\n      <Link>RangeCoder\\RangeCoderBit.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"..\\RangeCoder\\RangeCoderBitTree.cs\">\r\n      <Link>RangeCoder\\RangeCoderBitTree.cs</Link>\r\n    </Compile>\r\n    <Compile Include=\"LzmaAlone.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"LzmaBench.cs\">\r\n      <SubType>Code</SubType>\r\n    </Compile>\r\n    <Compile Include=\"Properties\\AssemblyInfo.cs\" />\r\n    <Compile Include=\"Properties\\Settings.cs\">\r\n      <AutoGen>True</AutoGen>\r\n      <DependentUpon>Settings.settings</DependentUpon>\r\n    </Compile>\r\n    <None Include=\"Properties\\Settings.settings\">\r\n      <Generator>SettingsSingleFileGenerator</Generator>\r\n      <LastGenOutput>Settings.cs</LastGenOutput>\r\n    </None>\r\n    <AppDesigner Include=\"Properties\\\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSHARP.Targets\" />\r\n</Project>\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LzmaAlone/LzmaAlone.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 9.00\r\n# Visual C# Express 2005\r\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LzmaAlone\", \"LzmaAlone.csproj\", \"{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|Any CPU = Debug|Any CPU\r\n\t\tRelease|Any CPU = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Debug|Any CPU.Build.0 = Debug|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.ActiveCfg = Release|Any CPU\r\n\t\t{CE33DF18-F9C8-4D6F-9057-DBB4DB96E973}.Release|Any CPU.Build.0 = Release|Any CPU\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LzmaAlone/LzmaBench.cs",
    "content": "// LzmaBench.cs\r\n\r\nusing System;\r\nusing System.IO;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// LZMA Benchmark\r\n\t/// </summary>\r\n\tinternal abstract class LzmaBench\r\n\t{\r\n\t\tconst UInt32 kAdditionalSize = (6 << 20);\r\n\t\tconst UInt32 kCompressedAdditionalSize = (1 << 10);\r\n\t\tconst UInt32 kMaxLzmaPropSize = 10;\r\n\r\n\t\tclass CRandomGenerator\r\n\t\t{\r\n\t\t\tUInt32 A1;\r\n\t\t\tUInt32 A2;\r\n\t\t\tpublic CRandomGenerator() { Init(); }\r\n\t\t\tpublic void Init() { A1 = 362436069; A2 = 521288629; }\r\n\t\t\tpublic UInt32 GetRnd()\r\n\t\t\t{\r\n\t\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)));\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBitRandomGenerator\r\n\t\t{\r\n\t\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\t\tUInt32 Value;\r\n\t\t\tint NumBits;\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tValue = 0;\r\n\t\t\t\tNumBits = 0;\r\n\t\t\t}\r\n\t\t\tpublic UInt32 GetRnd(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 result;\r\n\t\t\t\tif (NumBits > numBits)\r\n\t\t\t\t{\r\n\t\t\t\t\tresult = Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\t\tValue >>= numBits;\r\n\t\t\t\t\tNumBits -= numBits;\r\n\t\t\t\t\treturn result;\r\n\t\t\t\t}\r\n\t\t\t\tnumBits -= NumBits;\r\n\t\t\t\tresult = (Value << numBits);\r\n\t\t\t\tValue = RG.GetRnd();\r\n\t\t\t\tresult |= Value & (((UInt32)1 << numBits) - 1);\r\n\t\t\t\tValue >>= numBits;\r\n\t\t\t\tNumBits = 32 - numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CBenchRandomGenerator\r\n\t\t{\r\n\t\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\t\tUInt32 Pos;\r\n\t\t\tpublic UInt32 BufferSize;\r\n\t\t\tpublic Byte[] Buffer = null;\r\n\t\t\tpublic CBenchRandomGenerator() { }\r\n\t\t\tpublic void Init() { RG.Init(); }\r\n\t\t\tpublic void Set(UInt32 bufferSize)\r\n\t\t\t{\r\n\t\t\t\tBuffer = new Byte[bufferSize];\r\n\t\t\t\tPos = 0;\r\n\t\t\t\tBufferSize = bufferSize;\r\n\t\t\t}\r\n\t\t\tUInt32 GetRndBit() { return RG.GetRnd(1); }\r\n\t\t\t/*\r\n\t\t\tUInt32 GetLogRand(int maxLen)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = GetRnd() % (maxLen + 1);\r\n\t\t\t\treturn GetRnd() & ((1 << len) - 1);\r\n\t\t\t}\r\n\t\t\t*/\r\n\t\t\tUInt32 GetLogRandBits(int numBits)\r\n\t\t\t{\r\n\t\t\t\tUInt32 len = RG.GetRnd(numBits);\r\n\t\t\t\treturn RG.GetRnd((int)len);\r\n\t\t\t}\r\n\t\t\tUInt32 GetOffset()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t\t}\r\n\t\t\tUInt32 GetLen()\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn RG.GetRnd(2);\r\n\t\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\t\treturn 4 + RG.GetRnd(3);\r\n\t\t\t\treturn 12 + RG.GetRnd(4);\r\n\t\t\t}\r\n\t\t\tpublic void Generate()\r\n\t\t\t{\r\n\t\t\t\twhile (Pos < BufferSize)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\t\tBuffer[Pos++] = (Byte)(RG.GetRnd(8));\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tUInt32 offset = GetOffset();\r\n\t\t\t\t\t\twhile (offset >= Pos)\r\n\t\t\t\t\t\t\toffset >>= 1;\r\n\t\t\t\t\t\toffset += 1;\r\n\t\t\t\t\t\tUInt32 len = 2 + GetLen();\r\n\t\t\t\t\t\tfor (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - offset];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CrcOutStream : System.IO.Stream\r\n\t\t{\r\n\t\t\tpublic CRC CRC = new CRC();\r\n\t\t\tpublic void Init() { CRC.Init(); }\r\n\t\t\tpublic UInt32 GetDigest() { return CRC.GetDigest(); }\r\n\r\n\t\t\tpublic override bool CanRead { get { return false; } }\r\n\t\t\tpublic override bool CanSeek { get { return false; } }\r\n\t\t\tpublic override bool CanWrite { get { return true; } }\r\n\t\t\tpublic override Int64 Length { get { return 0; } }\r\n\t\t\tpublic override Int64 Position { get { return 0; } set { } }\r\n\t\t\tpublic override void Flush() { }\r\n\t\t\tpublic override long Seek(long offset, SeekOrigin origin) { return 0; }\r\n\t\t\tpublic override void SetLength(long value) { }\r\n\t\t\tpublic override int Read(byte[] buffer, int offset, int count) { return 0; }\r\n\r\n\t\t\tpublic override void WriteByte(byte b)\r\n\t\t\t{\r\n\t\t\t\tCRC.UpdateByte(b);\r\n\t\t\t}\r\n\t\t\tpublic override void Write(byte[] buffer, int offset, int count)\r\n\t\t\t{\r\n\t\t\t\tCRC.Update(buffer, (uint)offset, (uint)count);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tclass CProgressInfo : ICodeProgress\r\n\t\t{\r\n\t\t\tpublic Int64 ApprovedStart;\r\n\t\t\tpublic Int64 InSize;\r\n\t\t\tpublic System.DateTime Time;\r\n\t\t\tpublic void Init() { InSize = 0; }\r\n\t\t\tpublic void SetProgress(Int64 inSize, Int64 outSize)\r\n\t\t\t{\r\n\t\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tTime = DateTime.UtcNow;\r\n\t\t\t\t\tInSize = inSize;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tconst int kSubBits = 8;\r\n\r\n\t\tstatic UInt32 GetLogSize(UInt32 size)\r\n\t\t{\r\n\t\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\t\tfor (UInt32 j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\t\tif (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\t\treturn (UInt32)(i << kSubBits) + j;\r\n\t\t\treturn (32 << kSubBits);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\r\n\t\t{\r\n\t\t\tUInt64 freq = TimeSpan.TicksPerSecond;\r\n\t\t\tUInt64 elTime = elapsedTime;\r\n\t\t\twhile (freq > 1000000)\r\n\t\t\t{\r\n\t\t\t\tfreq >>= 1;\r\n\t\t\t\telTime >>= 1;\r\n\t\t\t}\r\n\t\t\tif (elTime == 0)\r\n\t\t\t\telTime = 1;\r\n\t\t\treturn value * freq / elTime;\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetCompressRating(UInt32 dictionarySize, bool isBT4,\r\n\t\t\tUInt64 elapsedTime, UInt64 size)\r\n\t\t{\r\n\t\t\tUInt64 numCommandsForOne;\r\n\t\t\tif (isBT4)\r\n\t\t\t{\r\n\t\t\t\tUInt64 t = GetLogSize(dictionarySize) - (19 << kSubBits);\r\n\t\t\t\tnumCommandsForOne = 2000 + ((t * t * 68) >> (2 * kSubBits));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tUInt64 t = GetLogSize(dictionarySize) - (15 << kSubBits);\r\n\t\t\t\tnumCommandsForOne = 1500 + ((t * t * 41) >> (2 * kSubBits));\r\n\t\t\t}\r\n\t\t\tUInt64 numCommands = (UInt64)(size) * numCommandsForOne;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetDecompressRating(UInt64 elapsedTime,\r\n\t\t\tUInt64 outSize, UInt64 inSize)\r\n\t\t{\r\n\t\t\tUInt64 numCommands = inSize * 250 + outSize * 21;\r\n\t\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t\t}\r\n\r\n\t\tstatic UInt64 GetTotalRating(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tbool isBT4,\r\n\t\t\tUInt64 elapsedTimeEn, UInt64 sizeEn,\r\n\t\t\tUInt64 elapsedTimeDe,\r\n\t\t\tUInt64 inSizeDe, UInt64 outSizeDe)\r\n\t\t{\r\n\t\t\treturn (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t\t}\r\n\r\n\t\tstatic void PrintValue(UInt64 v)\r\n\t\t{\r\n\t\t\tstring s = v.ToString();\r\n\t\t\tfor (int i = 0; i + s.Length < 6; i++)\r\n\t\t\t\tSystem.Console.Write(\" \");\r\n\t\t\tSystem.Console.Write(s);\r\n\t\t}\r\n\r\n\t\tstatic void PrintRating(UInt64 rating)\r\n\t\t{\r\n\t\t\tPrintValue(rating / 1000000);\r\n\t\t\tSystem.Console.Write(\" MIPS\");\r\n\t\t}\r\n\r\n\t\tstatic void PrintResults(\r\n\t\t\tUInt32 dictionarySize,\r\n\t\t\tbool isBT4,\r\n\t\t\tUInt64 elapsedTime,\r\n\t\t\tUInt64 size,\r\n\t\t\tbool decompressMode, UInt64 secondSize)\r\n\t\t{\r\n\t\t\tUInt64 speed = MyMultDiv64(size, elapsedTime);\r\n\t\t\tPrintValue(speed / 1024);\r\n\t\t\tSystem.Console.Write(\" KB/s  \");\r\n\t\t\tUInt64 rating;\r\n\t\t\tif (decompressMode)\r\n\t\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\t\telse\r\n\t\t\t\trating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\r\n\t\t\tPrintRating(rating);\r\n\t\t}\r\n\r\n\t\tconst string bt2 = \"BT2\";\r\n\t\tconst string bt4 = \"BT4\";\r\n\r\n\t\tstatic public int LzmaBenchmark(Int32 numIterations, UInt32 dictionarySize, bool isBT4)\r\n\t\t{\r\n\t\t\tif (numIterations <= 0)\r\n\t\t\t\treturn 0;\r\n\t\t\tif (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\r\n\t\t\t{\r\n\t\t\t\tSystem.Console.WriteLine(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tSystem.Console.Write(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\r\n\t\t\tCompression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();\r\n\t\t\tCompression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();\r\n\r\n\r\n\t\t\tCoderPropID[] propIDs = \r\n\t\t\t{ \r\n\t\t\t\tCoderPropID.DictionarySize,\r\n\t\t\t\tCoderPropID.MatchFinder  \r\n\t\t\t};\r\n\t\t\tobject[] properties = \r\n\t\t\t{\r\n\t\t\t\t(Int32)(dictionarySize),\r\n\t\t\t\tisBT4 ? bt4: bt2\r\n\t\t\t};\r\n\r\n\t\t\tUInt32 kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\t\tUInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\r\n\t\t\tencoder.SetCoderProperties(propIDs, properties);\r\n\t\t\tSystem.IO.MemoryStream propStream = new System.IO.MemoryStream();\r\n\t\t\tencoder.WriteCoderProperties(propStream);\r\n\t\t\tbyte[] propArray = propStream.ToArray();\r\n\r\n\t\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\t\trg.Init();\r\n\t\t\trg.Set(kBufferSize);\r\n\t\t\trg.Generate();\r\n\t\t\tCRC crc = new CRC();\r\n\t\t\tcrc.Init();\r\n\t\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\r\n\t\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\r\n\t\t\tUInt64 totalBenchSize = 0;\r\n\t\t\tUInt64 totalEncodeTime = 0;\r\n\t\t\tUInt64 totalDecodeTime = 0;\r\n\t\t\tUInt64 totalCompressedSize = 0;\r\n\r\n\t\t\tMemoryStream inStream = new MemoryStream(rg.Buffer, 0, (int)rg.BufferSize);\r\n\t\t\tMemoryStream compressedStream = new MemoryStream((int)kCompressedBufferSize);\r\n\t\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\t\tfor (Int32 i = 0; i < numIterations; i++)\r\n\t\t\t{\r\n\t\t\t\tprogressInfo.Init();\r\n\t\t\t\tinStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\t\tTimeSpan sp2 = DateTime.UtcNow - progressInfo.Time;\r\n\t\t\t\tUInt64 encodeTime = (UInt64)sp2.Ticks;\r\n\r\n\t\t\t\tlong compressedSize = compressedStream.Position;\r\n\t\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\t\tUInt64 decodeTime = 0;\r\n\t\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t\t{\r\n\t\t\t\t\tcompressedStream.Seek(0, SeekOrigin.Begin);\r\n\t\t\t\t\tcrcOutStream.Init();\r\n\r\n\t\t\t\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\t\t\tUInt64 outSize = kBufferSize;\r\n\t\t\t\t\tSystem.DateTime startTime = DateTime.UtcNow;\r\n\t\t\t\t\tdecoder.Code(compressedStream, crcOutStream, 0, (Int64)outSize, null);\r\n\t\t\t\t\tTimeSpan sp = (DateTime.UtcNow - startTime);\r\n\t\t\t\t\tdecodeTime = (ulong)sp.Ticks;\r\n\t\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t\t}\r\n\t\t\t\tUInt64 benchSize = kBufferSize - (UInt64)progressInfo.InSize;\r\n\t\t\t\tPrintResults(dictionarySize, isBT4, encodeTime, benchSize, false, 0);\r\n\t\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\t\tPrintResults(dictionarySize, isBT4, decodeTime, kBufferSize, true, (ulong)compressedSize);\r\n\t\t\t\tSystem.Console.WriteLine();\r\n\r\n\t\t\t\ttotalBenchSize += benchSize;\r\n\t\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\t\ttotalCompressedSize += (ulong)compressedSize;\r\n\t\t\t}\r\n\t\t\tSystem.Console.WriteLine(\"---------------------------------------------------\");\r\n\t\t\tPrintResults(dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\t\tSystem.Console.Write(\"     \");\r\n\t\t\tPrintResults(dictionarySize, isBT4, totalDecodeTime,\r\n\t\t\t\t\tkBufferSize * (UInt64)numIterations, true, totalCompressedSize);\r\n\t\t\tSystem.Console.WriteLine(\"    Average\");\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs",
    "content": "﻿#region Using directives\r\n\r\nusing System.Reflection;\r\nusing System.Runtime.CompilerServices;\r\n\r\n#endregion\r\n\r\n// General Information about an assembly is controlled through the following \r\n// set of attributes. Change these attribute values to modify the information\r\n// associated with an assembly.\r\n[assembly: AssemblyTitle(\"LZMA#\")]\r\n[assembly: AssemblyDescription(\"\")]\r\n[assembly: AssemblyConfiguration(\"\")]\r\n[assembly: AssemblyCompany(\"Igor Pavlov\")]\r\n[assembly: AssemblyProduct(\"LZMA# SDK\")]\r\n[assembly: AssemblyCopyright(\"Copyright @ Igor Pavlov 1999-2004\")]\r\n[assembly: AssemblyTrademark(\"\")]\r\n[assembly: AssemblyCulture(\"\")]\r\n\r\n// Version information for an assembly consists of the following four values:\r\n//\r\n//      Major Version\r\n//      Minor Version \r\n//      Build Number\r\n//      Revision\r\n//\r\n// You can specify all the values or you can default the Revision and Build Numbers \r\n// by using the '*' as shown below:\r\n[assembly: AssemblyVersion(\"4.12.*\")]\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LzmaAlone/Properties/Resources.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Resources;\r\n\r\n\t/// <summary>\r\n\t///    A strongly-typed resource class, for looking up localized strings, etc.\r\n\t/// </summary>\r\n\t// This class was auto-generated by the Strongly Typed Resource Builder\r\n\t// class via a tool like ResGen or Visual Studio.NET.\r\n\t// To add or remove a member, edit your .ResX file then rerun ResGen\r\n\t// with the /str option, or rebuild your VS project.\r\n\tclass Resources\r\n\t{\r\n\r\n\t\tprivate static System.Resources.ResourceManager _resMgr;\r\n\r\n\t\tprivate static System.Globalization.CultureInfo _resCulture;\r\n\r\n\t\t/*FamANDAssem*/\r\n\t\tinternal Resources()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Returns the cached ResourceManager instance used by this class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Resources.ResourceManager ResourceManager\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((_resMgr == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Resources.ResourceManager temp = new System.Resources.ResourceManager(\"Resources\", typeof(Resources).Assembly);\r\n\t\t\t\t\t_resMgr = temp;\r\n\t\t\t\t}\r\n\t\t\t\treturn _resMgr;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t///    Overrides the current thread's CurrentUICulture property for all\r\n\t\t///    resource lookups using this strongly typed resource class.\r\n\t\t/// </summary>\r\n\t\t[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]\r\n\t\tpublic static System.Globalization.CultureInfo Culture\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\treturn _resCulture;\r\n\t\t\t}\r\n\t\t\tset\r\n\t\t\t{\r\n\t\t\t\t_resCulture = value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/LzmaAlone/Properties/Settings.cs",
    "content": "﻿//------------------------------------------------------------------------------\r\n// <autogenerated>\r\n//     This code was generated by a tool.\r\n//     Runtime Version:2.0.40607.42\r\n//\r\n//     Changes to this file may cause incorrect behavior and will be lost if\r\n//     the code is regenerated.\r\n// </autogenerated>\r\n//------------------------------------------------------------------------------\r\n\r\nnamespace LzmaAlone.Properties\r\n{\r\n\tpublic partial class Settings : System.Configuration.ApplicationSettingsBase\r\n\t{\r\n\t\tprivate static Settings m_Value;\r\n\r\n\t\tprivate static object m_SyncObject = new object();\r\n\r\n\t\tpublic static Settings Value\r\n\t\t{\r\n\t\t\tget\r\n\t\t\t{\r\n\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t{\r\n\t\t\t\t\tSystem.Threading.Monitor.Enter(Settings.m_SyncObject);\r\n\t\t\t\t\tif ((Settings.m_Value == null))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSettings.m_Value = new Settings();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tfinally\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tSystem.Threading.Monitor.Exit(Settings.m_SyncObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn Settings.m_Value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/RangeCoder/RangeCoder.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tclass Encoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\r\n\t\tSystem.IO.Stream Stream;\r\n\r\n\t\tpublic UInt64 Low;\r\n\t\tpublic uint Range;\r\n\t\tuint _cacheSize;\r\n\t\tbyte _cache;\r\n\r\n\t\tlong StartPosition;\r\n\r\n\t\tpublic void SetStream(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\tStream = stream;\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tStartPosition = Stream.Position;\r\n\r\n\t\t\tLow = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\t_cacheSize = 1;\r\n\t\t\t_cache = 0;\r\n\t\t}\r\n\r\n\t\tpublic void FlushData()\r\n\t\t{\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tShiftLow();\r\n\t\t}\r\n\r\n\t\tpublic void FlushStream()\r\n\t\t{\r\n\t\t\tStream.Flush();\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tLow += start * (Range /= total);\r\n\t\t\tRange *= size;\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ShiftLow()\r\n\t\t{\r\n\t\t\tif ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)\r\n\t\t\t{\r\n\t\t\t\tbyte temp = _cache;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tStream.WriteByte((byte)(temp + (Low >> 32)));\r\n\t\t\t\t\ttemp = 0xFF;\r\n\t\t\t\t}\r\n\t\t\t\twhile (--_cacheSize != 0);\r\n\t\t\t\t_cache = (byte)(((uint)Low) >> 24);\r\n\t\t\t}\r\n\t\t\t_cacheSize++;\r\n\t\t\tLow = ((uint)Low) << 8;\r\n\t\t}\r\n\r\n\t\tpublic void EncodeDirectBits(uint v, int numTotalBits)\r\n\t\t{\r\n\t\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tRange >>= 1;\r\n\t\t\t\tif (((v >> i) & 1) == 1)\r\n\t\t\t\t\tLow += Range;\r\n\t\t\t\tif (Range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tRange <<= 8;\r\n\t\t\t\t\tShiftLow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void EncodeBit(uint size0, int numTotalBits, uint symbol)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tRange = newBound;\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tLow += newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic long GetProcessedSizeAdd()\r\n\t\t{\r\n\t\t\treturn _cacheSize +\r\n\t\t\t\tStream.Position - StartPosition + 4;\r\n\t\t\t// (long)Stream.GetProcessedSize();\r\n\t\t}\r\n\t}\r\n\r\n\tclass Decoder\r\n\t{\r\n\t\tpublic const uint kTopValue = (1 << 24);\r\n\t\tpublic uint Range;\r\n\t\tpublic uint Code;\r\n\t\t// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);\r\n\t\tpublic System.IO.Stream Stream;\r\n\r\n\t\tpublic void Init(System.IO.Stream stream)\r\n\t\t{\r\n\t\t\t// Stream.Init(stream);\r\n\t\t\tStream = stream;\r\n\r\n\t\t\tCode = 0;\r\n\t\t\tRange = 0xFFFFFFFF;\r\n\t\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t}\r\n\r\n\t\tpublic void ReleaseStream()\r\n\t\t{\r\n\t\t\t// Stream.ReleaseStream();\r\n\t\t\tStream = null;\r\n\t\t}\r\n\r\n\t\tpublic void CloseStream()\r\n\t\t{\r\n\t\t\tStream.Close();\r\n\t\t}\r\n\r\n\t\tpublic void Normalize()\r\n\t\t{\r\n\t\t\twhile (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void Normalize2()\r\n\t\t{\r\n\t\t\tif (Range < kTopValue)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetThreshold(uint total)\r\n\t\t{\r\n\t\t\treturn Code / (Range /= total);\r\n\t\t}\r\n\r\n\t\tpublic void Decode(uint start, uint size, uint total)\r\n\t\t{\r\n\t\t\tCode -= start * Range;\r\n\t\t\tRange *= size;\r\n\t\t\tNormalize();\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeDirectBits(int numTotalBits)\r\n\t\t{\r\n\t\t\tuint range = Range;\r\n\t\t\tuint code = Code;\r\n\t\t\tuint result = 0;\r\n\t\t\tfor (int i = numTotalBits; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\trange >>= 1;\r\n\t\t\t\t/*\r\n\t\t\t\tresult <<= 1;\r\n\t\t\t\tif (code >= range)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode -= range;\r\n\t\t\t\t\tresult |= 1;\r\n\t\t\t\t}\r\n\t\t\t\t*/\r\n\t\t\t\tuint t = (code - range) >> 31;\r\n\t\t\t\tcode -= range & (t - 1);\r\n\t\t\t\tresult = (result << 1) | (1 - t);\r\n\r\n\t\t\t\tif (range < kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\tcode = (code << 8) | (byte)Stream.ReadByte();\r\n\t\t\t\t\trange <<= 8;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tRange = range;\r\n\t\t\tCode = code;\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tpublic uint DecodeBit(uint size0, int numTotalBits)\r\n\t\t{\r\n\t\t\tuint newBound = (Range >> numTotalBits) * size0;\r\n\t\t\tuint symbol;\r\n\t\t\tif (Code < newBound)\r\n\t\t\t{\r\n\t\t\t\tsymbol = 0;\r\n\t\t\t\tRange = newBound;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol = 1;\r\n\t\t\t\tCode -= newBound;\r\n\t\t\t\tRange -= newBound;\r\n\t\t\t}\r\n\t\t\tNormalize();\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\t// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBit.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitEncoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\t\tconst int kNumMoveReducingBits = 2;\r\n\t\tpublic const int kNumBitPriceShiftBits = 6;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic void UpdateModel(uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder encoder, uint symbol)\r\n\t\t{\r\n\t\t\t// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);\r\n\t\t\t// UpdateModel(symbol);\r\n\t\t\tuint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob;\r\n\t\t\tif (symbol == 0)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tencoder.Low += newBound;\r\n\t\t\t\tencoder.Range -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t}\r\n\t\t\tif (encoder.Range < Encoder.kTopValue)\r\n\t\t\t{\r\n\t\t\t\tencoder.Range <<= 8;\r\n\t\t\t\tencoder.ShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];\r\n\r\n\t\tstatic BitEncoder()\r\n\t\t{\r\n\t\t\tconst int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 start = (UInt32)1 << (kNumBits - i - 1);\r\n\t\t\t\tUInt32 end = (UInt32)1 << (kNumBits - i);\r\n\t\t\t\tfor (UInt32 j = start; j < end; j++)\r\n\t\t\t\t\tProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic uint GetPrice(uint symbol)\r\n\t\t{\r\n\t\t\treturn ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r\n\t\t}\r\n\t  public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }\r\n\t\tpublic uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }\r\n\t}\r\n\r\n\tstruct BitDecoder\r\n\t{\r\n\t\tpublic const int kNumBitModelTotalBits = 11;\r\n\t\tpublic const uint kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\t\tconst int kNumMoveBits = 5;\r\n\r\n\t\tuint Prob;\r\n\r\n\t\tpublic void UpdateModel(int numMoveBits, uint symbol)\r\n\t\t{\r\n\t\t\tif (symbol == 0)\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> numMoveBits;\r\n\t\t\telse\r\n\t\t\t\tProb -= (Prob) >> numMoveBits;\r\n\t\t}\r\n\r\n\t\tpublic void Init() { Prob = kBitModelTotal >> 1; }\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;\r\n\t\t\tif (rangeDecoder.Code < newBound)\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range = newBound;\r\n\t\t\t\tProb += (kBitModelTotal - Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trangeDecoder.Range -= newBound;\r\n\t\t\t\trangeDecoder.Code -= newBound;\r\n\t\t\t\tProb -= (Prob) >> kNumMoveBits;\r\n\t\t\t\tif (rangeDecoder.Range < Decoder.kTopValue)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();\r\n\t\t\t\t\trangeDecoder.Range <<= 8;\r\n\t\t\t\t}\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/Compress/RangeCoder/RangeCoderBitTree.cs",
    "content": "using System;\r\n\r\nnamespace SevenZip.Compression.RangeCoder\r\n{\r\n\tstruct BitTreeEncoder\r\n\t{\r\n\t\tBitEncoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeEncoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitEncoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic void Encode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (UInt32 i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic UInt32 GetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; )\r\n\t\t\t{\r\n\t\t\t\tbitIndex--;\r\n\t\t\t\tUInt32 bit = (symbol >> bitIndex) & 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) + bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic UInt32 ReverseGetPrice(UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tint NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 price = 0;\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = NumBitLevels; i > 0; i--)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t\tprice += Models[startIndex + m].GetPrice(bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\r\n\t\tpublic static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, UInt32 symbol)\r\n\t\t{\r\n\t\t\tUInt32 m = 1;\r\n\t\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t\t{\r\n\t\t\t\tUInt32 bit = symbol & 1;\r\n\t\t\t\tModels[startIndex + m].Encode(rangeEncoder, bit);\r\n\t\t\t\tm = (m << 1) | bit;\r\n\t\t\t\tsymbol >>= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstruct BitTreeDecoder\r\n\t{\r\n\t\tBitDecoder[] Models;\r\n\t\tint NumBitLevels;\r\n\r\n\t\tpublic BitTreeDecoder(int numBitLevels)\r\n\t\t{\r\n\t\t\tNumBitLevels = numBitLevels;\r\n\t\t\tModels = new BitDecoder[1 << numBitLevels];\r\n\t\t}\r\n\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tfor (uint i = 1; i < (1 << NumBitLevels); i++)\r\n\t\t\t\tModels[i].Init();\r\n\t\t}\r\n\r\n\t\tpublic uint Decode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tfor (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\r\n\t\t\t\tm = (m << 1) + Models[m].Decode(rangeDecoder);\r\n\t\t\treturn m - ((uint)1 << NumBitLevels);\r\n\t\t}\r\n\r\n\t\tpublic uint ReverseDecode(RangeCoder.Decoder rangeDecoder)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\r\n\t\tpublic static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,\r\n\t\t\tRangeCoder.Decoder rangeDecoder, int NumBitLevels)\r\n\t\t{\r\n\t\t\tuint m = 1;\r\n\t\t\tuint symbol = 0;\r\n\t\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t\t{\r\n\t\t\t\tuint bit = Models[startIndex + m].Decode(rangeDecoder);\r\n\t\t\t\tm <<= 1;\r\n\t\t\t\tm += bit;\r\n\t\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t\t}\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/CS/7zip/ICoder.cs",
    "content": "// ICoder.h\r\n\r\nusing System;\r\n\r\nnamespace SevenZip\r\n{\r\n\t/// <summary>\r\n\t/// The exception that is thrown when an error in input stream occurs during decoding.\r\n\t/// </summary>\r\n\tclass DataErrorException : ApplicationException\r\n\t{\r\n\t\tpublic DataErrorException(): base(\"Data Error\") { }\r\n\t}\r\n\r\n\t/// <summary>\r\n\t/// The exception that is thrown when the value of an argument is outside the allowable range.\r\n\t/// </summary>\r\n\tclass InvalidParamException : ApplicationException\r\n\t{\r\n\t\tpublic InvalidParamException(): base(\"Invalid Parameter\") { }\r\n\t}\r\n\r\n\tpublic interface ICodeProgress\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Callback progress.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\tvoid SetProgress(Int64 inSize, Int64 outSize);\r\n\t};\r\n\r\n\tpublic interface ICoder\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Codes streams.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"inStream\">\r\n\t\t/// input Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outStream\">\r\n\t\t/// output Stream.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"inSize\">\r\n\t\t/// input Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"outSize\">\r\n\t\t/// output Size. -1 if unknown.\r\n\t\t/// </param>\r\n\t\t/// <param name=\"progress\">\r\n\t\t/// callback progress reference.\r\n\t\t/// </param>\r\n\t\t/// <exception cref=\"SevenZip.DataErrorException\">\r\n\t\t/// if input stream is not valid\r\n\t\t/// </exception>\r\n\t\tvoid Code(System.IO.Stream inStream, System.IO.Stream outStream,\r\n\t\t\tInt64 inSize, Int64 outSize, ICodeProgress progress);\r\n\t};\r\n\r\n\t/*\r\n\tpublic interface ICoder2\r\n\t{\r\n\t\t void Code(ISequentialInStream []inStreams,\r\n\t\t\t\tconst UInt64 []inSizes, \r\n\t\t\t\tISequentialOutStream []outStreams, \r\n\t\t\t\tUInt64 []outSizes,\r\n\t\t\t\tICodeProgress progress);\r\n\t};\r\n  */\r\n\r\n\t/// <summary>\r\n\t/// Provides the fields that represent properties idenitifiers for compressing.\r\n\t/// </summary>\r\n\tpublic enum CoderPropID\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of dictionary.\r\n\t\t/// </summary>\r\n\t\tDictionarySize = 0x400,\r\n\t\t/// <summary>\r\n\t\t/// Specifies size of memory for PPM*.\r\n\t\t/// </summary>\r\n\t\tUsedMemorySize,\r\n\t\t/// <summary>\r\n\t\t/// Specifies order for PPM methods.\r\n\t\t/// </summary>\r\n\t\tOrder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of postion state bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tPosStateBits = 0x440,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal context bits for LZMA (0 <= x <= 8).\r\n\t\t/// </summary>\r\n\t\tLitContextBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of literal position bits for LZMA (0 <= x <= 4).\r\n\t\t/// </summary>\r\n\t\tLitPosBits,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of fast bytes for LZ*.\r\n\t\t/// </summary>\r\n\t\tNumFastBytes = 0x450,\r\n\t\t/// <summary>\r\n\t\t/// Specifies match finder. LZMA: \"BT2\", \"BT4\" or \"BT4B\".\r\n\t\t/// </summary>\r\n\t\tMatchFinder,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of passes.\r\n\t\t/// </summary>\r\n\t\tNumPasses = 0x460,\r\n\t\t/// <summary>\r\n\t\t/// Specifies number of algorithm.\r\n\t\t/// </summary>\r\n\t\tAlgorithm = 0x470,\r\n\t\t/// <summary>\r\n\t\t/// Specifies multithread mode.\r\n\t\t/// </summary>\r\n\t\tMultiThread = 0x480,\r\n\t\t/// <summary>\r\n\t\t/// Specifies mode with end marker.\r\n\t\t/// </summary>\r\n\t\tEndMarker = 0x490\r\n\t};\r\n\r\n\r\n\tpublic interface ISetCoderProperties\r\n\t{\r\n\t\tvoid SetCoderProperties(CoderPropID[] propIDs, object[] properties);\r\n\t};\r\n\r\n\tpublic interface IWriteCoderProperties\r\n\t{\r\n\t\tvoid WriteCoderProperties(System.IO.Stream outStream);\r\n\t}\r\n\r\n\tpublic interface ISetDecoderProperties\r\n\t{\r\n\t\tvoid SetDecoderProperties(byte[] properties);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/CRC.java",
    "content": "// SevenZip/CRC.java\r\n\r\npackage SevenZip;\r\n\r\npublic class CRC\r\n{\r\n\tstatic public int[] Table = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint _value = -1;\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_value = -1;\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data, int offset, int size)\r\n\t{\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void Update(byte[] data)\r\n\t{\r\n\t\tint size = data.length;\r\n\t\tfor (int i = 0; i < size; i++)\r\n\t\t\t_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic void UpdateByte(int b)\r\n\t{\r\n\t\t_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);\r\n\t}\r\n\t\r\n\tpublic int GetDigest()\r\n\t{\r\n\t\treturn _value ^ (-1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/ICodeProgress.java",
    "content": "package SevenZip;\r\n\r\npublic interface ICodeProgress\r\n{\r\n\tpublic void SetProgress(long inSize, long outSize);\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/LZ/BinTree.java",
    "content": "package SevenZip.Compression.LZ;\r\nimport java.io.IOException;\r\n\t\t\r\npublic class BinTree extends InWindow\r\n{\r\n\tint _cyclicBufferPos;\r\n\tint _cyclicBufferSize;\r\n\tint _historySize;\r\n\tint _matchMaxLen;\r\n\t\r\n\tint[] _son;\r\n\t\r\n\tint[] _hash;\r\n\tint[] _hash2;\r\n\tint[] _hash3;\r\n\t\r\n\tint _cutValue = 0xFF;\r\n\t\r\n\tboolean HASH_ARRAY = true;\r\n\tboolean HASH_BIG = false;\r\n\t\r\n\tstatic final int kHash3Size = 1 << 18;\r\n\t\r\n\tstatic final int kBT2HashSize = 1 << 16;\r\n\tstatic final int kBT4Hash2Size = 1 << 10;\r\n\tstatic final int kBT4Hash4Size = 1 << 20;\r\n\tstatic final int kBT4bHash4Size = 1 << 23;\r\n\tstatic final int kBT2NumHashDirectBytes = 2;\r\n\tstatic final int kBT4NumHashDirectBytes = 0;\r\n\t\r\n\tint kHash2Size = kBT4Hash2Size;\r\n\tint kNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\tint kNumHashBytes = 4;\r\n\tint kHashSize = kBT4Hash4Size;\r\n\r\n\tprivate static final int[] CrcTable = new int[256];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tfor (int i = 0; i < 256; i++)\r\n\t\t{\r\n\t\t\tint r = i;\r\n\t\t\tfor (int j = 0; j < 8; j++)\r\n\t\t\t\tif ((r & 1) != 0)\r\n\t\t\t\t\tr = (r >>> 1) ^ 0xEDB88320;\r\n\t\t\t\telse\r\n\t\t\t\t\tr >>>= 1;\r\n\t\t\tCrcTable[i] = r;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void SetType(int numHashBytes, boolean big)\r\n\t{\r\n\t\tHASH_ARRAY = numHashBytes > 2;\r\n\t\tHASH_BIG = big;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tkHash2Size = kBT4Hash2Size;\r\n\t\t\tkNumHashDirectBytes = kBT4NumHashDirectBytes;\r\n\t\t\tkNumHashBytes = 4;\r\n\t\t\tkHashSize = (HASH_BIG ? kBT4bHash4Size : kBT4Hash4Size);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tkNumHashDirectBytes = kBT2NumHashDirectBytes;\r\n\t\t\tkNumHashBytes = 2;\r\n\t\t\tkHashSize = kBT2HashSize;\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic final int kEmptyHashValue = 0;\r\n\t\r\n\tstatic final int kMaxValForNormalize = ((int)1 << 30) - 1;\r\n\t\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\tsuper.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < kHashSize; i++)\r\n\t\t\t_hash[i] = kEmptyHashValue;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tfor (i = 0; i < kHash2Size; i++)\r\n\t\t\t\t_hash2[i] = kEmptyHashValue;\r\n\t\t\tfor (i = 0; i < kHash3Size; i++)\r\n\t\t\t\t_hash3[i] = kEmptyHashValue;\r\n\t\t}\r\n\t\t_cyclicBufferPos = 0;\r\n\t\tReduceOffsets(-1);\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\tif (++_cyclicBufferPos >= _cyclicBufferSize)\r\n\t\t\t_cyclicBufferPos = 0;\r\n\t\tsuper.MovePos();\r\n\t\tif (_pos == kMaxValForNormalize)\r\n\t\t\tNormalize();\r\n\t}\r\n\t\r\n\tpublic boolean Create(int historySize, int keepAddBufferBefore,\r\n\t\t\tint matchMaxLen, int keepAddBufferAfter)\r\n\t{\r\n\t\tint windowReservSize = (historySize + keepAddBufferBefore +\r\n\t\t\t\tmatchMaxLen + keepAddBufferAfter) / 2 + 256;\r\n\t\t\r\n\t\t_son = null;\r\n\t\t_hash = null;\r\n\t\t_hash2 = null;\r\n\t\t_hash3 = null;\r\n\t\t\r\n\t\tsuper.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);\r\n\t\t\r\n\t\tif (_blockSize + 256 > kMaxValForNormalize)\r\n\t\t\treturn false;\r\n\t\t\r\n\t\t_historySize = historySize;\r\n\t\t_matchMaxLen = matchMaxLen;\r\n\t\t\r\n\t\t_cyclicBufferSize = historySize + 1;\r\n\t\t_son = new int[_cyclicBufferSize * 2];\r\n\t\t\r\n\t\t_hash = new int[kHashSize];\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\t_hash2 = new int[kHash2Size];\r\n\t\t\t_hash3 = new int[kHash3Size];\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic int GetLongestMatch(int[] distances)\r\n\t{\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\treturn 0;\r\n\t\t}\r\n\t\t\r\n\t\tint matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\t\t\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\t\r\n\t\tint matchHashLenMax = 0;\r\n\t\t\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & (kHashSize - 1);\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8)) & (kHashSize - 1);\r\n\t\t\r\n\t\tint curMatch = _hash[hashValue];\r\n\t\tint curMatch2 = 0, curMatch3 = 0;\r\n\t\tint len2Distance = 0;\r\n\t\tint len3Distance = 0;\r\n\t\tboolean matchLen2Exist = false;\r\n\t\tboolean matchLen3Exist = false;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\tif (curMatch2 >= matchMinPos)\r\n\t\t\t{\r\n\t\t\t\tif (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tlen2Distance = _pos - curMatch2 - 1;\r\n\t\t\t\t\tmatchHashLenMax = 2;\r\n\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t{\r\n\t\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t\t\tif (curMatch3 >= matchMinPos)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen3Distance = _pos - curMatch3 - 1;\r\n\t\t\t\t\t\tmatchHashLenMax = 3;\r\n\t\t\t\t\t\tmatchLen3Exist = true;\r\n\t\t\t\t\t\tif (matchLen2Exist)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (len3Distance < len2Distance)\r\n\t\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tlen2Distance = len3Distance;\r\n\t\t\t\t\t\t\tmatchLen2Exist = true;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t_hash[hashValue] = _pos;\r\n\t\t\r\n\t\tif (curMatch < matchMinPos)\r\n\t\t{\r\n\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\t\t\t\r\n\t\t\tif (HASH_ARRAY)\r\n\t\t\t{\r\n\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t}\r\n\t\t\treturn matchHashLenMax;\r\n\t\t}\r\n\t\tint ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptrRight = (_cyclicBufferPos << 1);\r\n\t\t\r\n\t\tint maxLen, minLeft, minRight;\r\n\t\tmaxLen = minLeft = minRight = kNumHashDirectBytes;\r\n\t\t\r\n\t\tdistances[maxLen] = _pos - curMatch - 1;\r\n\t\t\r\n\t\tfor (int count = _cutValue; count != 0; count--)\r\n\t\t{\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint currentLen = Math.min(minLeft, minRight);\r\n\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\tbreak;\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\twhile (currentLen > maxLen)\r\n\t\t\t\tdistances[++maxLen] = delta - 1;\r\n\t\t\t\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\t\t\t\r\n\t\t\tif (currentLen != lenLimit)\r\n\t\t\t{\r\n\t\t\t\tif ((_bufferBase[pby1 + currentLen] & 0xFF) < (_bufferBase[cur + currentLen] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (HASH_ARRAY)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (matchLen2Exist && len2Distance < distances[2])\r\n\t\t\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\t\tif (matchLen3Exist && len3Distance < distances[3])\r\n\t\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn maxLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t_son[ptrRight] = kEmptyHashValue;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tif (matchLen2Exist)\r\n\t\t\t{\r\n\t\t\t\tif (maxLen < 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t\t\tmaxLen = 2;\r\n\t\t\t\t}\r\n\t\t\t\telse if (len2Distance < distances[2])\r\n\t\t\t\t\tdistances[2] = len2Distance;\r\n\t\t\t}\r\n\t\t\t{\r\n\t\t\t\tif (matchLen3Exist)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (maxLen < 3)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t\t\tmaxLen = 3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (len3Distance < distances[3])\r\n\t\t\t\t\t\tdistances[3] = len3Distance;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn maxLen;\r\n\t}\r\n\t\r\n\tpublic void DummyLongestMatch()\r\n\t{\r\n\t\t// GetLongestMatch(_dummy);\r\n\t\t\r\n\t\tint lenLimit;\r\n\t\tif (_pos + _matchMaxLen <= _streamPos)\r\n\t\t\tlenLimit = _matchMaxLen;\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenLimit = _streamPos - _pos;\r\n\t\t\tif (lenLimit < kNumHashBytes)\r\n\t\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tint matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\r\n\t\t\r\n\t\tint cur = _bufferOffset + _pos;\r\n\t\t\r\n\t\tint hashValue, hash2Value = 0, hash3Value = 0;\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tint temp = CrcTable[_bufferBase[cur] & 0xFF] ^ (_bufferBase[cur + 1] & 0xFF);\r\n\t\t\thash2Value = temp & (kHash2Size - 1);\r\n\t\t\ttemp ^= ((int)(_bufferBase[cur + 2] & 0xFF) << 8);\r\n\t\t\thash3Value = temp & (kHash3Size - 1);\r\n\t\t\thashValue = (temp ^ (CrcTable[_bufferBase[cur + 3] & 0xFF] << 5)) & (kHashSize - 1);\r\n\t\t}\r\n\t\telse\r\n\t\t\thashValue = ((_bufferBase[cur] & 0xFF) ^ ((int)(_bufferBase[cur + 1] & 0xFF) << 8)) & (kHashSize - 1);\r\n\t\t\r\n\t\tint curMatch = _hash[hashValue];\r\n\t\tint curMatch2 = 0, curMatch3 = 0;\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tcurMatch2 = _hash2[hash2Value];\r\n\t\t\tcurMatch3 = _hash3[hash3Value];\r\n\t\t\t_hash2[hash2Value] = _pos;\r\n\t\t\t_hash3[hash3Value] = _pos;\r\n\t\t}\r\n\t\t_hash[hashValue] = _pos;\r\n\t\t\r\n\t\tif (curMatch < matchMinPos)\r\n\t\t{\r\n\t\t\t_son[(_cyclicBufferPos << 1)] = kEmptyHashValue;\r\n\t\t\t_son[(_cyclicBufferPos << 1) + 1] = kEmptyHashValue;\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tint ptrLeft = (_cyclicBufferPos << 1) + 1;\r\n\t\tint ptrRight = (_cyclicBufferPos << 1);\r\n\t\t\r\n\t\tint minLeft, minRight;\r\n\t\tminLeft = minRight = kNumHashDirectBytes;\r\n\t\t\r\n\t\tfor (int count = _cutValue; count != 0; count--)\r\n\t\t{\r\n\t\t\tint pby1 = _bufferOffset + curMatch;\r\n\t\t\tint currentLen = Math.min(minLeft, minRight);\r\n\t\t\tfor (; currentLen < lenLimit; currentLen++)\r\n\t\t\t\tif (_bufferBase[pby1 + currentLen] != _bufferBase[cur + currentLen])\r\n\t\t\t\t\tbreak;\r\n\t\t\tint delta = _pos - curMatch;\r\n\t\t\t\r\n\t\t\tint cyclicPos = ((delta <= _cyclicBufferPos) ?\r\n\t\t\t\t(_cyclicBufferPos - delta) :\r\n\t\t\t\t(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;\r\n\t\t\t\r\n\t\t\tif (currentLen != lenLimit)\r\n\t\t\t{\r\n\t\t\t\tif ((_bufferBase[pby1 + currentLen] & 0xFF) < (_bufferBase[cur + currentLen] & 0xFF))\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrRight] = curMatch;\r\n\t\t\t\t\tptrRight = cyclicPos + 1;\r\n\t\t\t\t\tcurMatch = _son[ptrRight];\r\n\t\t\t\t\tif (currentLen > minLeft)\r\n\t\t\t\t\t\tminLeft = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (currentLen < _matchMaxLen)\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = curMatch;\r\n\t\t\t\t\tptrLeft = cyclicPos;\r\n\t\t\t\t\tcurMatch = _son[ptrLeft];\r\n\t\t\t\t\tif (currentLen > minRight)\r\n\t\t\t\t\t\tminRight = currentLen;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_son[ptrLeft] = _son[cyclicPos + 1];\r\n\t\t\t\t\t_son[ptrRight] = _son[cyclicPos];\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (curMatch < matchMinPos)\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\t_son[ptrLeft] = kEmptyHashValue;\r\n\t\t_son[ptrRight] = kEmptyHashValue;\r\n\t}\r\n\t\r\n\tvoid NormalizeLinks(int[] items, int numItems, int subValue)\r\n\t{\r\n\t\tfor (int i = 0; i < numItems; i++)\r\n\t\t{\r\n\t\t\tint value = items[i];\r\n\t\t\tif (value <= subValue)\r\n\t\t\t\tvalue = kEmptyHashValue;\r\n\t\t\telse\r\n\t\t\t\tvalue -= subValue;\r\n\t\t\titems[i] = value;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Normalize()\r\n\t{\r\n\t\tint startItem = _pos - _historySize;\r\n\t\tint subValue = startItem - 1;\r\n\t\tNormalizeLinks(_son, _cyclicBufferSize * 2, subValue);\r\n\t\t\r\n\t\tNormalizeLinks(_hash, kHashSize, subValue);\r\n\t\t\r\n\t\tif (HASH_ARRAY)\r\n\t\t{\r\n\t\t\tNormalizeLinks(_hash2, kHash2Size, subValue);\r\n\t\t\tNormalizeLinks(_hash3, kHash3Size, subValue);\r\n\t\t}\r\n\t\tReduceOffsets(subValue);\r\n\t}\r\n\t\r\n\tpublic void SetCutValue(int cutValue)\r\n\t{ _cutValue = cutValue; }\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/LZ/InWindow.java",
    "content": "// LZ.InWindows\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class InWindow\r\n{\r\n\tpublic byte[] _bufferBase; // pointer to buffer with data\r\n\tjava.io.InputStream _stream;\r\n\tint _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\r\n\tboolean _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r\n\t\r\n\tint _pointerToLastSafePosition;\r\n\t\r\n\tpublic int _bufferOffset;\r\n\t\r\n\tpublic int _blockSize;  // Size of Allocated memory block\r\n\tpublic int _pos;             // offset (from _buffer) of curent byte\r\n\tint _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r\n\tint _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r\n\tint _keepSizeReserv;  // how many BYTEs must be kept as reserv\r\n\tpublic int _streamPos;   // offset (from _buffer) of first not read byte from Stream\r\n\t\r\n\tpublic void MoveBlock()\r\n\t{\r\n\t\tint offset = _bufferOffset + _pos - _keepSizeBefore;\r\n\t\tint numBytes = _bufferOffset + _streamPos - offset;\r\n\t\t\r\n\t\t// check negative offset ????\r\n\t\tfor (int i = 0; i < numBytes; i++)\r\n\t\t\t_bufferBase[i] = _bufferBase[offset + i];\r\n\t\t_bufferOffset -= offset;\r\n\t}\r\n\t\r\n\tpublic void ReadBlock() throws IOException\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\treturn;\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint size = (0 - _bufferOffset) + _blockSize - _streamPos;\r\n\t\t\tif (size == 0)\r\n\t\t\t\treturn;\r\n\t\t\tint numReadBytes = _stream.read(_bufferBase, _bufferOffset + _streamPos, size);\r\n\t\t\tif (numReadBytes == -1)\r\n\t\t\t{\r\n\t\t\t\t_posLimit = _streamPos;\r\n\t\t\t\tint pointerToPostion = _bufferOffset + _posLimit;\r\n\t\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\t\t_posLimit = _pointerToLastSafePosition - _bufferOffset;\r\n\t\t\t\t\r\n\t\t\t\t_streamEndWasReached = true;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t_streamPos += numReadBytes;\r\n\t\t\tif (_streamPos >= _pos + _keepSizeAfter)\r\n\t\t\t\t_posLimit = _streamPos - _keepSizeAfter;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid Free()\r\n\t{ _bufferBase = null; }\r\n\t\r\n\tpublic void Create(int keepSizeBefore, int keepSizeAfter, int keepSizeReserv)\r\n\t{\r\n\t\t_keepSizeBefore = keepSizeBefore;\r\n\t\t_keepSizeAfter = keepSizeAfter;\r\n\t\t_keepSizeReserv = keepSizeReserv;\r\n\t\tint blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\r\n\t\tif (_bufferBase == null || _blockSize != blockSize)\r\n\t\t{\r\n\t\t\tFree();\r\n\t\t\t_blockSize = blockSize;\r\n\t\t\t_bufferBase = new byte[_blockSize];\r\n\t\t}\r\n\t\t_pointerToLastSafePosition = _blockSize - keepSizeAfter;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.InputStream stream)\r\n\t{ _stream = stream; \t}\r\n\r\n\tpublic void ReleaseStream()\r\n\t{ _stream = null; }\r\n\r\n\tpublic void Init() throws IOException\r\n\t{\r\n\t\t_bufferOffset = 0;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t\t_streamEndWasReached = false;\r\n\t\tReadBlock();\r\n\t}\r\n\t\r\n\tpublic void MovePos() throws IOException\r\n\t{\r\n\t\t_pos++;\r\n\t\tif (_pos > _posLimit)\r\n\t\t{\r\n\t\t\tint pointerToPostion = _bufferOffset + _pos;\r\n\t\t\tif (pointerToPostion > _pointerToLastSafePosition)\r\n\t\t\t\tMoveBlock();\r\n\t\t\tReadBlock();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic byte GetIndexByte(int index)\r\n\t{ return _bufferBase[_bufferOffset + _pos + index]; }\r\n\t\r\n\t// index + limit have not to exceed _keepSizeAfter;\r\n\tpublic int GetMatchLen(int index, int distance, int limit)\r\n\t{\r\n\t\tif (_streamEndWasReached)\r\n\t\t\tif ((_pos + index) + limit > _streamPos)\r\n\t\t\t\tlimit = _streamPos - (_pos + index);\r\n\t\tdistance++;\r\n\t\t// Byte *pby = _buffer + (size_t)_pos + index;\r\n\t\tint pby = _bufferOffset + _pos + index;\r\n\t\t\r\n\t\tint i;\r\n\t\tfor (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++);\r\n\t\treturn i;\r\n\t}\r\n\t\r\n\tpublic int GetNumAvailableBytes()\r\n\t{ return _streamPos - _pos; }\r\n\t\r\n\tpublic void ReduceOffsets(int subValue)\r\n\t{\r\n\t\t_bufferOffset += subValue;\r\n\t\t_posLimit -= subValue;\r\n\t\t_pos -= subValue;\r\n\t\t_streamPos -= subValue;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/LZ/OutWindow.java",
    "content": "// LZ.OutWindow\r\n\r\npackage SevenZip.Compression.LZ;\r\n\r\nimport java.io.IOException;\r\n\r\npublic class OutWindow\r\n{\r\n\tbyte[] _buffer;\r\n\tint _pos;\r\n\tint _windowSize = 0;\r\n\tint _streamPos;\r\n\tjava.io.OutputStream _stream;\r\n\t\r\n\tpublic void Create(int windowSize)\r\n\t{\r\n\t\tif (_buffer == null || _windowSize != windowSize)\r\n\t\t\t_buffer = new byte[windowSize];\r\n\t\t_windowSize = windowSize;\r\n\t\t_pos = 0;\r\n\t\t_streamPos = 0;\r\n\t}\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream) throws IOException\r\n\t{\r\n\t\tReleaseStream();\r\n\t\t_stream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream() throws IOException\r\n\t{\r\n\t\tFlush();\r\n\t\t_stream = null;\r\n\t}\r\n\t\r\n\tpublic void Init(boolean solid)\r\n\t{\r\n\t\tif (!solid)\r\n\t\t{\r\n\t\t\t_streamPos = 0;\r\n\t\t\t_pos = 0;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void Flush() throws IOException\r\n\t{\r\n\t\tint size = _pos - _streamPos;\r\n\t\tif (size == 0)\r\n\t\t\treturn;\r\n\t\t_stream.write(_buffer, _streamPos, size);\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\t_pos = 0;\r\n\t\t_streamPos = _pos;\r\n\t}\r\n\t\r\n\tpublic void CopyBlock(int distance, int len) throws IOException\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\tfor (; len != 0; len--)\r\n\t\t{\r\n\t\t\tif (pos >= _windowSize)\r\n\t\t\t\tpos = 0;\r\n\t\t\t_buffer[_pos++] = _buffer[pos++];\r\n\t\t\tif (_pos >= _windowSize)\r\n\t\t\t\tFlush();\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void PutByte(byte b) throws IOException\r\n\t{\r\n\t\t_buffer[_pos++] = b;\r\n\t\tif (_pos >= _windowSize)\r\n\t\t\tFlush();\r\n\t}\r\n\t\r\n\tpublic byte GetByte(int distance)\r\n\t{\r\n\t\tint pos = _pos - distance - 1;\r\n\t\tif (pos < 0)\r\n\t\t\tpos += _windowSize;\r\n\t\treturn _buffer[pos];\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/LZMA/Base.java",
    "content": "// Base.java\r\n\r\npackage SevenZip.Compression.LZMA;\r\n\r\npublic class Base\r\n{\r\n\tpublic static final int kNumRepDistances = 4;\r\n\tpublic static final int kNumStates = 12;\r\n\t\r\n\tpublic static final int StateInit()\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateChar(int index)\r\n\t{\r\n\t\tif (index < 4) \r\n\t\t\treturn 0;\r\n\t\tif (index < 10) \r\n\t\t\treturn index - 3;\r\n\t\treturn index - 6;\r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateMatch(int index)\r\n\t{\r\n\t\treturn (index < 7 ? 7 : 10); \r\n\t}\r\n\r\n\tpublic static final int StateUpdateRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 8 : 11); \r\n\t}\r\n\t\r\n\tpublic static final int StateUpdateShortRep(int index)\r\n\t{ \r\n\t\treturn (index < 7 ? 9 : 11); \r\n\t}\r\n\r\n\tpublic static final boolean StateIsCharState(int index)\r\n\t{ \r\n\t\treturn index < 7; \r\n\t}\r\n\t\r\n\tpublic static final int kNumPosSlotBits = 6;\r\n\tpublic static final int kDicLogSizeMin = 0;\r\n\tpublic static final int kDicLogSizeMax = 28;\r\n\tpublic static final int kDistTableSizeMax = kDicLogSizeMax * 2;\r\n\t\r\n\tpublic static final int kNumLenToPosStatesBits = 2; // it's for speed optimization\r\n\tpublic static final int kNumLenToPosStates = 1 << kNumLenToPosStatesBits;\r\n\t\r\n\tpublic static final int kMatchMinLen = 2;\r\n\t\r\n\tpublic static final int GetLenToPosState(int len)\r\n\t{\r\n\t\tlen -= kMatchMinLen;\r\n\t\tif (len < kNumLenToPosStates)\r\n\t\t\treturn len;\r\n\t\treturn (int)(kNumLenToPosStates - 1);\r\n\t}\r\n\t\r\n\tpublic static final int kNumAlignBits = 4;\r\n\tpublic static final int kAlignTableSize = 1 << kNumAlignBits;\r\n\tpublic static final int kAlignMask = (kAlignTableSize - 1);\r\n\t\r\n\tpublic static final int kStartPosModelIndex = 4;\r\n\tpublic static final int kEndPosModelIndex = 14;\r\n\tpublic static final int kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r\n\t\r\n\tpublic static final  int kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r\n\t\r\n\tpublic static final  int kNumLitPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumLitContextBitsMax = 8;\r\n\t\r\n\tpublic static final  int kNumPosStatesBitsMax = 4;\r\n\tpublic static final  int kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r\n\tpublic static final  int kNumPosStatesBitsEncodingMax = 4;\r\n\tpublic static final  int kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r\n\t\r\n\tpublic static final  int kNumLowLenBits = 3;\r\n\tpublic static final  int kNumMidLenBits = 3;\r\n\tpublic static final  int kNumHighLenBits = 8;\r\n\tpublic static final  int kNumLowLenSymbols = 1 << kNumLowLenBits;\r\n\tpublic static final  int kNumMidLenSymbols = 1 << kNumMidLenBits;\r\n\tpublic static final  int kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +\r\n\t\t\t(1 << kNumHighLenBits);\r\n\tpublic static final  int kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/LZMA/Decoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeDecoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.OutWindow;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tclass LenDecoder\r\n\t{\r\n\t\tshort[] m_Choice = new short[2];\r\n\t\tBitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];\r\n\t\tBitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);\r\n\t\tint m_NumPosStates = 0;\r\n\t\t\r\n\t\tpublic void Create(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (; m_NumPosStates < numPosStates; m_NumPosStates++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumLowLenBits);\r\n\t\t\t\tm_MidCoder[m_NumPosStates] = new BitTreeDecoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Choice);\r\n\t\t\tfor (int posState = 0; posState < m_NumPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\tm_LowCoder[posState].Init();\r\n\t\t\t\tm_MidCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\tm_HighCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic int Decode(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 0) == 0)\r\n\t\t\t\treturn m_LowCoder[posState].Decode(rangeDecoder);\r\n\t\t\tint symbol = Base.kNumLowLenSymbols;\r\n\t\t\tif (rangeDecoder.DecodeBit(m_Choice, 1) == 0)\r\n\t\t\t\tsymbol += m_MidCoder[posState].Decode(rangeDecoder);\r\n\t\t\telse\r\n\t\t\t\tsymbol += Base.kNumMidLenSymbols + m_HighCoder.Decode(rangeDecoder);\r\n\t\t\treturn symbol;\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass LiteralDecoder\r\n\t{\r\n\t\tclass Decoder2\r\n\t\t{\r\n\t\t\tshort[] m_Decoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_Decoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeNormal(SevenZip.Compression.RangeCoder.Decoder rangeDecoder) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic byte DecodeWithMatchByte(SevenZip.Compression.RangeCoder.Decoder rangeDecoder, byte matchByte) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint symbol = 1;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tint matchBit = (matchByte >> 7) & 1;\r\n\t\t\t\t\tmatchByte <<= 1;\r\n\t\t\t\t\tint bit = rangeDecoder.DecodeBit(m_Decoders, ((1 + matchBit) << 8) + symbol);\r\n\t\t\t\t\tsymbol = (symbol << 1) | bit;\r\n\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (symbol < 0x100)\r\n\t\t\t\t\t\t\tsymbol = (symbol << 1) | rangeDecoder.DecodeBit(m_Decoders, symbol);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile (symbol < 0x100);\r\n\t\t\t\treturn (byte)symbol;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Decoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Decoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tDecoder2 GetDecoder(int pos, byte prevByte)\r\n\t\t{\r\n\t\t\treturn m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))];\r\n\t\t}\r\n\t}\r\n\t\r\n\tOutWindow m_OutWindow = new OutWindow();\r\n\tSevenZip.Compression.RangeCoder.Decoder m_RangeDecoder = new SevenZip.Compression.RangeCoder.Decoder();\r\n\t\r\n\tshort[] m_IsMatchDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] m_IsRepDecoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG0Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG1Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRepG2Decoders = new short[Base.kNumStates];\r\n\tshort[] m_IsRep0LongDecoders = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];\r\n\tshort[] m_PosDecoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\t\r\n\tBitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);\r\n\t\r\n\tLenDecoder m_LenDecoder = new LenDecoder();\r\n\tLenDecoder m_RepLenDecoder = new LenDecoder();\r\n\t\r\n\tLiteralDecoder m_LiteralDecoder = new LiteralDecoder();\r\n\t\r\n\tint m_DictionarySize = -1;\r\n\tint m_DictionarySizeCheck =  -1;\r\n\t\r\n\tint m_PosStateMask;\r\n\t\r\n\tpublic Decoder()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tboolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tif (dictionarySize < 0)\r\n\t\t\treturn false;\r\n\t\tif (m_DictionarySize != dictionarySize)\r\n\t\t{\r\n\t\t\tm_DictionarySize = dictionarySize;\r\n\t\t\tm_DictionarySizeCheck = Math.max(m_DictionarySize, 1);\r\n\t\t\tm_OutWindow.Create(Math.max(m_DictionarySizeCheck, (1 << 12)));\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tboolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (lc > Base.kNumLitContextBitsMax || lp > 4 || pb > Base.kNumPosStatesBitsMax)\r\n\t\t\treturn false;\r\n\t\tm_LiteralDecoder.Create(lp, lc);\r\n\t\tint numPosStates = 1 << pb;\r\n\t\tm_LenDecoder.Create(numPosStates);\r\n\t\tm_RepLenDecoder.Create(numPosStates);\r\n\t\tm_PosStateMask = numPosStates - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tvoid Init() throws IOException\r\n\t{\r\n\t\tm_OutWindow.Init(false);\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsMatchDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRep0LongDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepDecoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG0Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG1Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_IsRepG2Decoders);\r\n\t\tSevenZip.Compression.RangeCoder.Decoder.InitBitModels(m_PosDecoders);\r\n\t\t\r\n\t\tm_LiteralDecoder.Init();\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\tm_PosSlotDecoder[i].Init();\r\n\t\tm_LenDecoder.Init();\r\n\t\tm_RepLenDecoder.Init();\r\n\t\tm_PosAlignDecoder.Init();\r\n\t\tm_RangeDecoder.Init();\r\n\t}\r\n\t\r\n\tpublic boolean Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong outSize) throws IOException\r\n\t{\r\n\t\tm_RangeDecoder.SetStream(inStream);\r\n\t\tm_OutWindow.SetStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tint state = Base.StateInit();\r\n\t\tint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;\r\n\t\t\r\n\t\tlong nowPos64 = 0;\r\n\t\tbyte prevByte = 0;\r\n\t\twhile (outSize < 0 || nowPos64 < outSize)\r\n\t\t{\r\n\t\t\tint posState = (int)nowPos64 & m_PosStateMask;\r\n\t\t\tif (m_RangeDecoder.DecodeBit(m_IsMatchDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t{\r\n\t\t\t\tLiteralDecoder.Decoder2 decoder2 = m_LiteralDecoder.GetDecoder((int)nowPos64, prevByte);\r\n\t\t\t\tif (!Base.StateIsCharState(state))\r\n\t\t\t\t\tprevByte = decoder2.DecodeWithMatchByte(m_RangeDecoder, m_OutWindow.GetByte(rep0));\r\n\t\t\t\telse\r\n\t\t\t\t\tprevByte = decoder2.DecodeNormal(m_RangeDecoder);\r\n\t\t\t\tm_OutWindow.PutByte(prevByte);\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t\tnowPos64++;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint len;\r\n\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepDecoders, state) == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tlen = 0;\r\n\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG0Decoders, state) == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRep0LongDecoders, (state << Base.kNumPosStatesBitsMax) + posState) == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\t\t\t\tlen = 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint distance;\r\n\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG1Decoders, state) == 0)\r\n\t\t\t\t\t\t\tdistance = rep1;\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (m_RangeDecoder.DecodeBit(m_IsRepG2Decoders, state) == 0)\r\n\t\t\t\t\t\t\t\tdistance = rep2;\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdistance = rep3;\r\n\t\t\t\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\t\trep0 = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlen = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trep3 = rep2;\r\n\t\t\t\t\trep2 = rep1;\r\n\t\t\t\t\trep1 = rep0;\r\n\t\t\t\t\tlen = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);\r\n\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t\tint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint numDirectBits = (posSlot >> 1) - 1;\r\n\t\t\t\t\t\trep0 = ((2 | (posSlot & 1)) << numDirectBits);\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\trep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,\r\n\t\t\t\t\t\t\t\t\trep0 - posSlot - 1, m_RangeDecoder, numDirectBits);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\trep0 += (m_RangeDecoder.DecodeDirectBits(\r\n\t\t\t\t\t\t\t\t\tnumDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);\r\n\t\t\t\t\t\t\trep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);\r\n\t\t\t\t\t\t\tif (rep0 < 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tif (rep0 == -1)\r\n\t\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\trep0 = posSlot;\r\n\t\t\t\t}\r\n\t\t\t\tif (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)\r\n\t\t\t\t{\r\n\t\t\t\t\t// m_OutWindow.Flush();\r\n\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\tm_OutWindow.CopyBlock(rep0, len);\r\n\t\t\t\tnowPos64 += len;\r\n\t\t\t\tprevByte = m_OutWindow.GetByte(0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tm_OutWindow.Flush();\r\n\t\tm_OutWindow.ReleaseStream();\r\n\t\tm_RangeDecoder.ReleaseStream();\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDecoderProperties(byte[] properties)\r\n\t{\r\n\t\tif (properties.length < 5)\r\n\t\t\treturn false;\r\n\t\tint val = properties[0] & 0xFF;\r\n\t\tint lc = val % 9;\r\n\t\tint remainder = val / 9;\r\n\t\tint lp = remainder % 5;\r\n\t\tint pb = remainder / 5;\r\n\t\tint dictionarySize = 0;\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tdictionarySize += ((int)(properties[1 + i]) & 0xFF) << (i * 8);\r\n\t\tif (!SetLcLpPb(lc, lp, pb))\r\n\t\t\treturn false;\r\n\t\treturn SetDictionarySize(dictionarySize);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/LZMA/Encoder.java",
    "content": "package SevenZip.Compression.LZMA;\r\n\r\nimport SevenZip.Compression.RangeCoder.BitTreeEncoder;\r\nimport SevenZip.Compression.LZMA.Base;\r\nimport SevenZip.Compression.LZ.BinTree;\r\nimport SevenZip.ICodeProgress;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tpublic static final int EMatchFinderTypeBT2 = 0;\r\n\tpublic static final int EMatchFinderTypeBT4 = 1;\r\n\tpublic static final int EMatchFinderTypeBT4B = 2;\r\n\t\r\n\t\r\n\tstatic final int kIfinityPrice = 0xFFFFFFF;\r\n\t\r\n\tstatic byte[] g_FastPos = new byte[1024];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kFastSlots = 20;\r\n\t\tint c = 2;\r\n\t\tg_FastPos[0] = 0;\r\n\t\tg_FastPos[1] = 1;\r\n\t\tfor (int slotFast = 2; slotFast < kFastSlots; slotFast++)\r\n\t\t{\r\n\t\t\tint k = (1 << ((slotFast >> 1) - 1));\r\n\t\t\tfor (int j = 0; j < k; j++, c++)\r\n\t\t\t\tg_FastPos[c] = (byte)slotFast;\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic int GetPosSlot(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 10))\r\n\t\t\treturn g_FastPos[pos];\r\n\t\tif (pos < (1 << 19))\r\n\t\t\treturn g_FastPos[pos >> 9] + 18;\r\n\t\treturn g_FastPos[pos >> 18] + 36;\r\n\t}\r\n\t\r\n\tstatic int GetPosSlot2(int pos)\r\n\t{\r\n\t\tif (pos < (1 << 16))\r\n\t\t\treturn g_FastPos[pos >> 6] + 12;\r\n\t\tif (pos < (1 << 25))\r\n\t\t\treturn g_FastPos[pos >> 15] + 30;\r\n\t\treturn g_FastPos[pos >> 24] + 48;\r\n\t}\r\n\t\r\n\tint _state = Base.StateInit();\r\n\tbyte _previousByte;\r\n\tint[] _repDistances = new int[Base.kNumRepDistances];\r\n\t\r\n\tvoid BaseInit()\r\n\t{\r\n\t\t_state = Base.StateInit();\r\n\t\t_previousByte = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t_repDistances[i] = 0;\r\n\t}\r\n\t\r\n\tstatic final int kDefaultDictionaryLogSize = 20;\r\n\tstatic final int kNumFastBytesDefault = 0x20;\r\n\t\r\n\tclass LiteralEncoder\r\n\t{\r\n\t\tclass Encoder2\r\n\t\t{\r\n\t\t\tshort[] m_Encoders = new short[0x300];\r\n\t\t\t\r\n\t\t\tpublic void Init()\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(m_Encoders);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, context, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic void EncodeMatched(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) throws IOException\r\n\t\t\t{\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tboolean same = true;\r\n\t\t\t\tfor (int i = 7; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = ((symbol >> i) & 1);\r\n\t\t\t\t\tint state = context;\r\n\t\t\t\t\tif (same)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = ((matchByte >> i) & 1);\r\n\t\t\t\t\t\tstate += ((1 + matchBit) << 8);\r\n\t\t\t\t\t\tsame = (matchBit == bit);\r\n\t\t\t\t\t}\r\n\t\t\t\t\trangeEncoder.Encode(m_Encoders, state, bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tpublic int GetPrice(boolean matchMode, byte matchByte, byte symbol)\r\n\t\t\t{\r\n\t\t\t\tint price = 0;\r\n\t\t\t\tint context = 1;\r\n\t\t\t\tint i = 7;\r\n\t\t\t\tif (matchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint matchBit = (matchByte >> i) & 1;\r\n\t\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[((1 + matchBit) << 8) + context], bit);\r\n\t\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t\t\tif (matchBit != bit)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ti--;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor (; i >= 0; i--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint bit = (symbol >> i) & 1;\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(m_Encoders[context], bit);\r\n\t\t\t\t\tcontext = (context << 1) | bit;\r\n\t\t\t\t}\r\n\t\t\t\treturn price;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tEncoder2[] m_Coders;\r\n\t\tint m_NumPrevBits;\r\n\t\tint m_NumPosBits;\r\n\t\tint m_PosMask;\r\n\t\t\r\n\t\tpublic void Create(int numPosBits, int numPrevBits)\r\n\t\t{\r\n\t\t\tif (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)\r\n\t\t\t\treturn;\r\n\t\t\tm_NumPosBits = numPosBits;\r\n\t\t\tm_PosMask = (1 << numPosBits) - 1;\r\n\t\t\tm_NumPrevBits = numPrevBits;\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tm_Coders = new Encoder2[numStates];\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i] = new Encoder2();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tint numStates = 1 << (m_NumPrevBits + m_NumPosBits);\r\n\t\t\tfor (int i = 0; i < numStates; i++)\r\n\t\t\t\tm_Coders[i].Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic Encoder2 GetSubCoder(int pos, byte prevByte)\r\n\t\t{ return m_Coders[((pos & m_PosMask) << m_NumPrevBits) + ((prevByte & 0xFF) >>> (8 - m_NumPrevBits))]; }\r\n\t}\r\n\t\r\n\tclass LenEncoder\r\n\t{\r\n\t\tshort[] _choice = new short[2];\r\n\t\tBitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.kNumPosStatesEncodingMax];\r\n\t\tBitTreeEncoder _highCoder = new BitTreeEncoder(Base.kNumHighLenBits);\r\n\t\t\r\n\t\tpublic LenEncoder()\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < Base.kNumPosStatesEncodingMax; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState] = new BitTreeEncoder(Base.kNumLowLenBits);\r\n\t\t\t\t_midCoder[posState] = new BitTreeEncoder(Base.kNumMidLenBits);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Init(int numPosStates)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_choice);\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t{\r\n\t\t\t\t_lowCoder[posState].Init();\r\n\t\t\t\t_midCoder[posState].Init();\r\n\t\t\t}\r\n\t\t\t_highCoder.Init();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 0);\r\n\t\t\t\t_lowCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\trangeEncoder.Encode(_choice, 0, 1);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 0);\r\n\t\t\t\t\t_midCoder[posState].Encode(rangeEncoder, symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\trangeEncoder.Encode(_choice, 1, 1);\r\n\t\t\t\t\t_highCoder.Encode(rangeEncoder, symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\tint price = 0;\r\n\t\t\tif (symbol < Base.kNumLowLenSymbols)\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[0]);\r\n\t\t\t\tprice += _lowCoder[posState].GetPrice(symbol);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tsymbol -= Base.kNumLowLenSymbols;\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[0]);\r\n\t\t\t\tif (symbol < Base.kNumMidLenSymbols)\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_choice[1]);\r\n\t\t\t\t\tprice += _midCoder[posState].GetPrice(symbol);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_choice[1]);\r\n\t\t\t\t\tprice += _highCoder.GetPrice(symbol - Base.kNumMidLenSymbols);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn price;\r\n\t\t}\r\n\t};\r\n\t\r\n\tpublic static final int kNumLenSpecSymbols = Base.kNumLowLenSymbols + Base.kNumMidLenSymbols;\r\n\t\r\n\tclass LenPriceTableEncoder extends LenEncoder\r\n\t{\r\n\t\tint[] _prices = new int[Base.kNumLenSymbols << Base.kNumPosStatesBitsEncodingMax];\r\n\t\tint _tableSize;\r\n\t\tint[] _counters = new int[Base.kNumPosStatesEncodingMax];\r\n\t\t\r\n\t\tpublic void SetTableSize(int tableSize)\r\n\t\t{ _tableSize = tableSize; }\r\n\t\t\r\n\t\tpublic int GetPrice(int symbol, int posState)\r\n\t\t{\r\n\t\t\treturn _prices[(symbol << Base.kNumPosStatesBitsEncodingMax) + posState];\r\n\t\t}\r\n\t\t\r\n\t\tvoid UpdateTable(int posState)\r\n\t\t{\r\n\t\t\tfor (int len = 0; len < _tableSize; len++)\r\n\t\t\t\t_prices[(len << Base.kNumPosStatesBitsEncodingMax) + posState] = super.GetPrice(len, posState);\r\n\t\t\t_counters[posState] = _tableSize;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void UpdateTables(int numPosStates)\r\n\t\t{\r\n\t\t\tfor (int posState = 0; posState < numPosStates; posState++)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void Encode(SevenZip.Compression.RangeCoder.Encoder rangeEncoder, int symbol, int posState) throws IOException\r\n\t\t{\r\n\t\t\tsuper.Encode(rangeEncoder, symbol, posState);\r\n\t\t\tif (--_counters[posState] == 0)\r\n\t\t\t\tUpdateTable(posState);\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static final int kNumOpts = 1 << 12;\r\n\tclass Optimal\r\n\t{\r\n\t\tpublic int State;\r\n\t\t\r\n\t\tpublic boolean Prev1IsChar;\r\n\t\tpublic boolean Prev2;\r\n\t\t\r\n\t\tpublic int PosPrev2;\r\n\t\tpublic int BackPrev2;\r\n\t\t\r\n\t\tpublic int Price;\r\n\t\tpublic int PosPrev;         // posNext;\r\n\t\tpublic int BackPrev;\r\n\t\t\r\n\t\t// public UInt32 []Backs = new UInt32[Base.kNumRepDistances];\r\n\t\tpublic int Backs0;\r\n\t\tpublic int Backs1;\r\n\t\tpublic int Backs2;\r\n\t\tpublic int Backs3;\r\n\t\t\r\n\t\tpublic void MakeAsChar()\r\n\t\t{ BackPrev = -1; Prev1IsChar = false; }\r\n\t\tpublic void MakeAsShortRep()\r\n\t\t{ BackPrev = 0; ; Prev1IsChar = false; }\r\n\t\tpublic boolean IsShortRep()\r\n\t\t{ return (BackPrev == 0); }\r\n\t};\r\n\tOptimal[] _optimum = new Optimal[kNumOpts];\r\n\t\r\n\tSevenZip.Compression.LZ.BinTree _matchFinder = null; // test it\r\n\tSevenZip.Compression.RangeCoder.Encoder _rangeEncoder = new SevenZip.Compression.RangeCoder.Encoder();\r\n\t\r\n\tshort[] _isMatch = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\tshort[] _isRep = new short[Base.kNumStates];\r\n\tshort[] _isRepG0 = new short[Base.kNumStates];\r\n\tshort[] _isRepG1 = new short[Base.kNumStates];\r\n\tshort[] _isRepG2 = new short[Base.kNumStates];\r\n\tshort[] _isRep0Long = new short[Base.kNumStates << Base.kNumPosStatesBitsMax];\r\n\t\r\n\tBitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.kNumLenToPosStates]; // kNumPosSlotBits\r\n\tshort[] _posEncoders = new short[Base.kNumFullDistances - Base.kEndPosModelIndex];\r\n\tBitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.kNumAlignBits);\r\n\t\r\n\tLenPriceTableEncoder _lenEncoder = new LenPriceTableEncoder();\r\n\tLenPriceTableEncoder _repMatchLenEncoder = new LenPriceTableEncoder();\r\n\t\r\n\tLiteralEncoder _literalEncoder = new LiteralEncoder();\r\n\t\r\n\tint[] _matchDistances = new int[Base.kMatchMaxLen + 1];\r\n\tboolean _fastMode = false;\r\n\tboolean _maxMode = true;\r\n\tint _numFastBytes = kNumFastBytesDefault;\r\n\tint _longestMatchLength;\r\n\tint _additionalOffset;\r\n\t\r\n\tint _optimumEndIndex;\r\n\tint _optimumCurrentIndex;\r\n\t\r\n\tboolean _longestMatchWasFound;\r\n\t\r\n\tint [] _posSlotPrices = new int [Base.kDistTableSizeMax << Base.kNumLenToPosStatesBits];\r\n\tint [] _distancesPrices = new int [Base.kNumFullDistances << Base.kNumLenToPosStatesBits];\r\n\tint [] _alignPrices = new int [Base.kAlignTableSize];\r\n\tint _alignPriceCount;\r\n\t\r\n\tint _distTableSize = (kDefaultDictionaryLogSize * 2);\r\n\t\r\n\tint _posStateBits = 2;\r\n\tint _posStateMask = (4 - 1);\r\n\tint _numLiteralPosStateBits = 0;\r\n\tint _numLiteralContextBits = 3;\r\n\t\r\n\tint _dictionarySize = (1 << kDefaultDictionaryLogSize);\r\n\tint _dictionarySizePrev = -1;\r\n\tint _numFastBytesPrev = -1;\r\n\t\r\n\tlong lastPosSlotFillingPos;\r\n\tlong nowPos64;\r\n\tboolean _finished;\r\n\t\r\n\tjava.io.InputStream _inStream;\r\n\tint _matchFinderType = EMatchFinderTypeBT4;\r\n\tboolean _writeEndMark = false;\r\n\tboolean _needReleaseMFStream = false;\r\n\t\r\n\tvoid Create()\r\n\t{\r\n\t\t// _rangeEncoder.Create(1 << 20);\r\n\t\tif (_matchFinder == null)\r\n\t\t{\r\n\t\t\tSevenZip.Compression.LZ.BinTree bt = new SevenZip.Compression.LZ.BinTree();\r\n\t\t\tint numHashBytes = 4;\r\n\t\t\tboolean big = false;\r\n\t\t\tswitch (_matchFinderType)\r\n\t\t\t{\r\n\t\t\t\tcase EMatchFinderTypeBT2:\r\n\t\t\t\t\tnumHashBytes = 2;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase EMatchFinderTypeBT4:\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase EMatchFinderTypeBT4B:\r\n\t\t\t\t\tbig = true;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tbt.SetType(numHashBytes, big);\r\n\t\t\t_matchFinder = bt;\r\n\t\t}\r\n\t\t_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits);\r\n\t\t\r\n\t\tif (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\r\n\t\t\treturn;\r\n\t\t_matchFinder.Create(_dictionarySize, kNumOpts, _numFastBytes,\r\n\t\t\t\tBase.kMatchMaxLen * 2 + 1 - _numFastBytes);\r\n\t\t_dictionarySizePrev = _dictionarySize;\r\n\t\t_numFastBytesPrev = _numFastBytes;\r\n\t}\r\n\t\r\n\tpublic Encoder()\r\n\t{\r\n\t\tfor (int i = 0; i < kNumOpts; i++)\r\n\t\t\t_optimum[i] = new Optimal();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i] = new BitTreeEncoder(Base.kNumPosSlotBits);\r\n\t}\r\n\t\r\n\tvoid Init()\r\n\t{\r\n\t\tBaseInit();\r\n\t\t_rangeEncoder.Init();\r\n\t\t\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isMatch);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep0Long);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRep);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG0);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG1);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_isRepG2);\r\n\t\tSevenZip.Compression.RangeCoder.Encoder.InitBitModels(_posEncoders);\r\n\t\t\r\n\t\t_literalEncoder.Init();\r\n\t\tfor (int i = 0; i < Base.kNumLenToPosStates; i++)\r\n\t\t\t_posSlotEncoder[i].Init();\r\n\t\t\r\n\t\t_lenEncoder.Init(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.Init(1 << _posStateBits);\r\n\t\t\r\n\t\t_posAlignEncoder.Init();\r\n\t\t\r\n\t\t_longestMatchWasFound = false;\r\n\t\t_optimumEndIndex = 0;\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_additionalOffset = 0;\r\n\t}\r\n\t\r\n\tint ReadMatchDistances() throws java.io.IOException\r\n\t{\r\n\t\tint lenRes = _matchFinder.GetLongestMatch(_matchDistances);\r\n\t\tif (lenRes == _numFastBytes)\r\n\t\t\tlenRes += _matchFinder.GetMatchLen((int)lenRes, _matchDistances[lenRes],\r\n\t\t\t\t\tBase.kMatchMaxLen - lenRes);\r\n\t\t_additionalOffset++;\r\n\t\t_matchFinder.MovePos();\r\n\t\treturn lenRes;\r\n\t}\r\n\t\r\n\tvoid MovePos(int num) throws java.io.IOException\r\n\t{\r\n\t\tfor (; num > 0; num--)\r\n\t\t{\r\n\t\t\t_matchFinder.DummyLongestMatch();\r\n\t\t\t_matchFinder.MovePos();\r\n\t\t\t_additionalOffset++;\r\n\t\t}\r\n\t}\r\n\t\r\n\tint GetRepLen1Price(int state, int posState)\r\n\t{\r\n\t\treturn SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]) +\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t}\r\n\t\r\n\tint GetRepPrice(int repIndex, int len, int state, int posState)\r\n\t{\r\n\t\tint price = _repMatchLenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t\tif (repIndex == 0)\r\n\t\t{\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG0[state]);\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep0Long[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG0[state]);\r\n\t\t\tif (repIndex == 1)\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRepG1[state]);\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRepG1[state]);\r\n\t\t\t\tprice += SevenZip.Compression.RangeCoder.Encoder.GetPrice(_isRepG2[state], repIndex - 2);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tint GetPosLenPrice(int pos, int len, int posState)\r\n\t{\r\n\t\tif (len == 2 && pos >= 0x80)\r\n\t\t\treturn kIfinityPrice;\r\n\t\tint price;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\tif (pos < Base.kNumFullDistances)\r\n\t\t\tprice = _distancesPrices[(pos << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\telse\r\n\t\t\tprice = _posSlotPrices[(GetPosSlot2(pos) << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\t_alignPrices[pos & Base.kAlignMask];\r\n\t\treturn price + _lenEncoder.GetPrice(len - Base.kMatchMinLen, posState);\r\n\t}\r\n\t\r\n\tint Backward(int[] backRes, int cur)\r\n\t{\r\n\t\t_optimumEndIndex = cur;\r\n\t\tint posMem = _optimum[cur].PosPrev;\r\n\t\tint backMem = _optimum[cur].BackPrev;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\t_optimum[posMem].MakeAsChar();\r\n\t\t\t\t_optimum[posMem].PosPrev = posMem - 1;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\t_optimum[posMem - 1].Prev1IsChar = false;\r\n\t\t\t\t\t_optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\t_optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tint posPrev = posMem;\r\n\t\t\tint backCur = backMem;\r\n\t\t\t\r\n\t\t\tbackMem = _optimum[posPrev].BackPrev;\r\n\t\t\tposMem = _optimum[posPrev].PosPrev;\r\n\t\t\t\r\n\t\t\t_optimum[posPrev].BackPrev = backCur;\r\n\t\t\t_optimum[posPrev].PosPrev = cur;\r\n\t\t\tcur = posPrev;\r\n\t\t}\r\n\t\twhile (cur > 0);\r\n\t\tbackRes[0] = _optimum[0].BackPrev;\r\n\t\t_optimumCurrentIndex = _optimum[0].PosPrev;\r\n\t\treturn _optimumCurrentIndex;\r\n\t}\r\n\t\r\n\tint[] reps = new int[Base.kNumRepDistances];\r\n\tint[] repLens = new int[Base.kNumRepDistances];\r\n\t\r\n\tint GetOptimum(int position, int []backRes) throws IOException\r\n\t{\r\n\t\tif (_optimumEndIndex != _optimumCurrentIndex)\r\n\t\t{\r\n\t\t\tint lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\r\n\t\t\tbackRes[0] = _optimum[_optimumCurrentIndex].BackPrev;\r\n\t\t\t_optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t_optimumCurrentIndex = 0;\r\n\t\t_optimumEndIndex = 0; // test it;\r\n\t\t\r\n\t\tint lenMain;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\t\r\n\t\tint repMaxIndex = 0;\r\n\t\tint i;\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\treps[i] = _repDistances[i];\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, reps[i], Base.kMatchMaxLen);\r\n\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes[0] = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\t\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tint backMain = (lenMain < _numFastBytes) ? _matchDistances[lenMain] :\r\n\t\t\t\t_matchDistances[_numFastBytes];\r\n\t\t\tbackRes[0] = backMain + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\t\tbyte currentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\r\n\t\t_optimum[0].State = _state;\r\n\t\t\r\n\t\tbyte matchByte;\r\n\t\t\r\n\t\tmatchByte = _matchFinder.GetIndexByte(0 - _repDistances[0] - 1 - 1);\r\n\t\t\r\n\t\tint posState = (position & _posStateMask);\r\n\t\t\r\n\t\t_optimum[1].Price =\r\n\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!Base.StateIsCharState(_state), matchByte, currentByte);\r\n\t\t_optimum[1].MakeAsChar();\r\n\t\t\r\n\t\t_optimum[1].PosPrev = 0;\r\n\t\t\r\n\t\t_optimum[0].Backs0 = reps[0];\r\n\t\t_optimum[0].Backs1 = reps[1];\r\n\t\t_optimum[0].Backs2 = reps[2];\r\n\t\t_optimum[0].Backs3 = reps[3];\r\n\t\t\r\n\t\t\r\n\t\tint matchPrice = SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(_state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\tint repMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[_state]);\r\n\t\t\r\n\t\tif (matchByte == currentByte)\r\n\t\t{\r\n\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\r\n\t\t\tif (shortRepPrice < _optimum[1].Price)\r\n\t\t\t{\r\n\t\t\t\t_optimum[1].Price = shortRepPrice;\r\n\t\t\t\t_optimum[1].MakeAsShortRep();\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (lenMain < 2)\r\n\t\t{\r\n\t\t\tbackRes[0] = _optimum[1].BackPrev;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t\tint normalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[_state]);\r\n\t\t\r\n\t\tif (lenMain <= repLens[repMaxIndex])\r\n\t\t\tlenMain = 0;\r\n\t\t\r\n\t\tint len;\r\n\t\tfor (len = 2; len <= lenMain; len++)\r\n\t\t{\r\n\t\t\t_optimum[len].PosPrev = 0;\r\n\t\t\t_optimum[len].BackPrev = _matchDistances[len] + Base.kNumRepDistances;\r\n\t\t\t_optimum[len].Price = normalMatchPrice +\r\n\t\t\t\t\tGetPosLenPrice(_matchDistances[len], len, posState);\r\n\t\t\t_optimum[len].Prev1IsChar = false;\r\n\t\t}\r\n\t\t\r\n\t\tif (lenMain < repLens[repMaxIndex])\r\n\t\t\tlenMain = repLens[repMaxIndex];\r\n\t\t\r\n\t\tfor (; len <= lenMain; len++)\r\n\t\t\t_optimum[len].Price = kIfinityPrice;\r\n\t\t\r\n\t\tfor (i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\tint repLen = repLens[i];\r\n\t\t\tfor (int lenTest = 2; lenTest <= repLen; lenTest++)\r\n\t\t\t{\r\n\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\r\n\t\t\t\tOptimal optimum = _optimum[lenTest];\r\n\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\toptimum.PosPrev = 0;\r\n\t\t\t\t\toptimum.BackPrev = i;\r\n\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tint cur = 0;\r\n\t\tint lenEnd = lenMain;\r\n\t\t\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tcur++;\r\n\t\t\tif (cur == lenEnd)\r\n\t\t\t{\r\n\t\t\t\treturn Backward(backRes, cur);\r\n\t\t\t}\r\n\t\t\tposition++;\r\n\t\t\tint posPrev = _optimum[cur].PosPrev;\r\n\t\t\tint state;\r\n\t\t\tif (_optimum[cur].Prev1IsChar)\r\n\t\t\t{\r\n\t\t\t\tposPrev--;\r\n\t\t\t\tif (_optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tstate = _optimum[_optimum[cur].PosPrev2].State;\r\n\t\t\t\t\tif (_optimum[cur].BackPrev2 < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tstate = _optimum[posPrev].State;\r\n\t\t\tif (posPrev == cur - 1)\r\n\t\t\t{\r\n\t\t\t\tif (_optimum[cur].IsShortRep())\r\n\t\t\t\t\tstate = Base.StateUpdateShortRep(state);\r\n\t\t\t\telse\r\n\t\t\t\t\tstate = Base.StateUpdateChar(state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint pos;\r\n\t\t\t\tif (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\r\n\t\t\t\t{\r\n\t\t\t\t\tposPrev = _optimum[cur].PosPrev2;\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev2;\r\n\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = _optimum[cur].BackPrev;\r\n\t\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t\t\tstate = Base.StateUpdateRep(state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tstate = Base.StateUpdateMatch(state);\r\n\t\t\t\t}\r\n\t\t\t\tOptimal opt = _optimum[posPrev];\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs0;\r\n\t\t\t\t\t\treps[1] = opt.Backs1;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs1;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs2;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse if (pos == 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs2;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs3;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\treps[0] = opt.Backs3;\r\n\t\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\treps[0] = (pos - Base.kNumRepDistances);\r\n\t\t\t\t\treps[1] = opt.Backs0;\r\n\t\t\t\t\treps[2] = opt.Backs1;\r\n\t\t\t\t\treps[3] = opt.Backs2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t_optimum[cur].State = state;\r\n\t\t\t_optimum[cur].Backs0 = reps[0];\r\n\t\t\t_optimum[cur].Backs1 = reps[1];\r\n\t\t\t_optimum[cur].Backs2 = reps[2];\r\n\t\t\t_optimum[cur].Backs3 = reps[3];\r\n\t\t\tint newLen = ReadMatchDistances();\r\n\t\t\tif (newLen >= _numFastBytes)\r\n\t\t\t{\r\n\t\t\t\t_longestMatchLength = newLen;\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\treturn Backward(backRes, cur);\r\n\t\t\t}\r\n\t\t\tint curPrice = _optimum[cur].Price;\r\n\t\t\t\r\n\t\t\tcurrentByte = _matchFinder.GetIndexByte(0 - 1);\r\n\t\t\tmatchByte = _matchFinder.GetIndexByte(0 - reps[0] - 1 - 1);\r\n\t\t\t\r\n\t\t\tposState = (position & _posStateMask);\r\n\t\t\t\r\n\t\t\tint curAnd1Price = curPrice +\r\n\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]) +\r\n\t\t\t\t\t_literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)).\r\n\t\t\t\t\tGetPrice(!Base.StateIsCharState(state), matchByte, currentByte);\r\n\t\t\t\r\n\t\t\tOptimal nextOptimum = _optimum[cur + 1];\r\n\t\t\t\r\n\t\t\tboolean nextIsChar = false;\r\n\t\t\tif (curAnd1Price < nextOptimum.Price)\r\n\t\t\t{\r\n\t\t\t\tnextOptimum.Price = curAnd1Price;\r\n\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\tnextOptimum.MakeAsChar();\r\n\t\t\t\tnextIsChar = true;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tmatchPrice = curPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state << Base.kNumPosStatesBitsMax) + posState]);\r\n\t\t\trepMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state]);\r\n\t\t\t\r\n\t\t\tif (matchByte == currentByte &&\r\n\t\t\t\t\t!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\r\n\t\t\t{\r\n\t\t\t\tint shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\r\n\t\t\t\tif (shortRepPrice <= nextOptimum.Price)\r\n\t\t\t\t{\r\n\t\t\t\t\tnextOptimum.Price = shortRepPrice;\r\n\t\t\t\t\tnextOptimum.PosPrev = cur;\r\n\t\t\t\t\tnextOptimum.MakeAsShortRep();\r\n\t\t\t\t\t// nextIsChar = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tint numAvailableBytesFull = _matchFinder.GetNumAvailableBytes() + 1;\r\n\t\t\tnumAvailableBytesFull = Math.min(kNumOpts - 1 - cur, numAvailableBytesFull);\r\n\t\t\tint numAvailableBytes = numAvailableBytesFull;\r\n\t\t\t\r\n\t\t\tif (numAvailableBytes < 2)\r\n\t\t\t\tcontinue;\r\n\t\t\tif (numAvailableBytes > _numFastBytes)\r\n\t\t\t\tnumAvailableBytes = _numFastBytes;\r\n\t\t\tif (numAvailableBytes >= 3 && !nextIsChar)\r\n\t\t\t{\r\n\t\t\t\tint backOffset = reps[0] + 1;\r\n\t\t\t\tint temp;\r\n\t\t\t\tfor (temp = 1; temp < numAvailableBytes; temp++)\r\n\t\t\t\t\t// if (data[temp] != data[(size_t)temp - backOffset])\r\n\t\t\t\t\tif (_matchFinder.GetIndexByte(temp - 1) != _matchFinder.GetIndexByte(temp - backOffset - 1))\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tint lenTest2 = temp - 1;\r\n\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint state2 = Base.StateUpdateChar(state);\r\n\t\t\t\t\tint posStateNext = (position + 1) & _posStateMask;\r\n\t\t\t\t\tint nextRepMatchPrice = curAnd1Price +\r\n\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t// for (; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\twhile (lenEnd < cur + 1 + lenTest2)\r\n\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\tOptimal optimum = _optimum[cur + 1 + lenTest2];\r\n\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\toptimum.PosPrev = cur + 1;\r\n\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\toptimum.Prev2 = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor (int repIndex = 0; repIndex < Base.kNumRepDistances; repIndex++)\r\n\t\t\t{\r\n\t\t\t\t// int repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\r\n\t\t\t\tint backOffset = reps[repIndex] + 1;\r\n\t\t\t\tif (_matchFinder.GetIndexByte(-1) !=\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(-1 - backOffset) ||\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(0) !=\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(0 - backOffset))\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tint lenTest;\r\n\t\t\t\tfor (lenTest = 2; lenTest < numAvailableBytes; lenTest++)\r\n\t\t\t\t\tif (_matchFinder.GetIndexByte(lenTest - 1) !=\r\n\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - backOffset))\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\tint lenTestTemp = lenTest;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\twhile (lenEnd < cur + lenTest)\r\n\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\tint curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = repIndex;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\twhile(--lenTest >= 2);\r\n\t\t\t\tlenTest = lenTestTemp;\r\n\t\t\t\t\r\n\t\t\t\tif (_maxMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tint lenTest2 = lenTest + 1;\r\n\t\t\t\t\tint limit = Math.min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\tif (_matchFinder.GetIndexByte(lenTest2 - 1) !=\r\n\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest2 - 1 - backOffset))\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint state2 = Base.StateUpdateRep(state);\r\n\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\tint curAndLenCharPrice =\r\n\t\t\t\t\t\t\t\trepMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).GetPrice(true,\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - backOffset),\r\n\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1));\r\n\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice +\r\n\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\twhile(lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\tint curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\tOptimal optimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\toptimum.BackPrev2 = repIndex;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t//    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\r\n\t\t\tif (newLen > numAvailableBytes)\r\n\t\t\t\tnewLen = numAvailableBytes;\r\n\t\t\tif (newLen >= 2)\r\n\t\t\t{\r\n\t\t\t\tif (newLen == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\tnormalMatchPrice = matchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isRep[state]);\r\n\t\t\t\twhile (lenEnd < cur + newLen)\r\n\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\r\n\t\t\t\tfor (int lenTest = newLen; lenTest >= 2; lenTest--)\r\n\t\t\t\t{\r\n\t\t\t\t\tint curBack = _matchDistances[lenTest];\r\n\t\t\t\t\tint curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\r\n\t\t\t\t\tOptimal optimum = _optimum[cur + lenTest];\r\n\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\toptimum.PosPrev = cur;\r\n\t\t\t\t\t\toptimum.BackPrev = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\toptimum.Prev1IsChar = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (_maxMode && (lenTest == newLen || curBack != _matchDistances[lenTest + 1]))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint backOffset = curBack + 1;\r\n\t\t\t\t\t\tint lenTest2 = lenTest + 1;\r\n\t\t\t\t\t\tint limit = Math.min(numAvailableBytesFull, lenTest2 + _numFastBytes);\r\n\t\t\t\t\t\tfor (; lenTest2 < limit; lenTest2++)\r\n\t\t\t\t\t\t\tif (_matchFinder.GetIndexByte(lenTest2 - 1) != _matchFinder.GetIndexByte(lenTest2 - backOffset - 1))\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\tlenTest2 -= lenTest + 1;\r\n\t\t\t\t\t\tif (lenTest2 >= 2)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint state2 = Base.StateUpdateMatch(state);\r\n\t\t\t\t\t\t\tint posStateNext = (position + lenTest) & _posStateMask;\r\n\t\t\t\t\t\t\tint curAndLenCharPrice = curAndLenPrice +\r\n\t\t\t\t\t\t\t\t\tSevenZip.Compression.RangeCoder.Encoder.GetPrice0(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]) +\r\n\t\t\t\t\t\t\t\t\t_literalEncoder.GetSubCoder(position + lenTest,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1 - 1)).\r\n\t\t\t\t\t\t\t\t\tGetPrice(true,\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - backOffset - 1),\r\n\t\t\t\t\t\t\t\t\t_matchFinder.GetIndexByte(lenTest - 1)\r\n\t\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\tstate2 = Base.StateUpdateChar(state2);\r\n\t\t\t\t\t\t\tposStateNext = (position + lenTest + 1) & _posStateMask;\r\n\t\t\t\t\t\t\tint nextMatchPrice = curAndLenCharPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isMatch[(state2 << Base.kNumPosStatesBitsMax) + posStateNext]);\r\n\t\t\t\t\t\t\tint nextRepMatchPrice = nextMatchPrice + SevenZip.Compression.RangeCoder.Encoder.GetPrice1(_isRep[state2]);\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t// for(; lenTest2 >= 2; lenTest2--)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tint offset = lenTest + 1 + lenTest2;\r\n\t\t\t\t\t\t\t\twhile (lenEnd < cur + offset)\r\n\t\t\t\t\t\t\t\t\t_optimum[++lenEnd].Price = kIfinityPrice;\r\n\t\t\t\t\t\t\t\tcurAndLenPrice = nextRepMatchPrice + GetRepPrice(\r\n\t\t\t\t\t\t\t\t\t\t0, lenTest2, state2, posStateNext);\r\n\t\t\t\t\t\t\t\toptimum = _optimum[cur + offset];\r\n\t\t\t\t\t\t\t\tif (curAndLenPrice < optimum.Price)\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\toptimum.Price = curAndLenPrice;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev = cur + lenTest + 1;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev = 0;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev1IsChar = true;\r\n\t\t\t\t\t\t\t\t\toptimum.Prev2 = true;\r\n\t\t\t\t\t\t\t\t\toptimum.PosPrev2 = cur;\r\n\t\t\t\t\t\t\t\t\toptimum.BackPrev2 = curBack + Base.kNumRepDistances;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tboolean ChangePair(int smallDist, int bigDist)\r\n\t{\r\n\t\tint kDif = 7;\r\n\t\treturn (smallDist < (1 << (32 - kDif)) && bigDist >= (smallDist << kDif));\r\n\t}\r\n\t\r\n\tint GetOptimumFast(int position, int[] backRes) throws IOException\r\n\t{\r\n\t\tint lenMain;\r\n\t\tif (!_longestMatchWasFound)\r\n\t\t{\r\n\t\t\tlenMain = ReadMatchDistances();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlenMain = _longestMatchLength;\r\n\t\t\t_longestMatchWasFound = false;\r\n\t\t}\r\n\t\tint repMaxIndex = 0;\r\n\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t{\r\n\t\t\trepLens[i] = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\tif (i == 0 || repLens[i] > repLens[repMaxIndex])\r\n\t\t\t\trepMaxIndex = i;\r\n\t\t}\r\n\t\tif (repLens[repMaxIndex] >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes[0] = repMaxIndex;\r\n\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\tMovePos(lenRes - 1);\r\n\t\t\treturn lenRes;\r\n\t\t}\r\n\t\tif (lenMain >= _numFastBytes)\r\n\t\t{\r\n\t\t\tbackRes[0] = _matchDistances[_numFastBytes] + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 1);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\t\twhile (lenMain > 2)\r\n\t\t{\r\n\t\t\tif (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\r\n\t\t\t\tbreak;\r\n\t\t\tlenMain--;\r\n\t\t}\r\n\t\tif (lenMain == 2 && _matchDistances[2] >= 0x80)\r\n\t\t\tlenMain = 1;\r\n\t\t\r\n\t\tint backMain = _matchDistances[lenMain];\r\n\t\tif (repLens[repMaxIndex] >= 2)\r\n\t\t{\r\n\t\t\tif (repLens[repMaxIndex] + 1 >= lenMain ||\r\n\t\t\t\t\trepLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 12)))\r\n\t\t\t{\r\n\t\t\t\tbackRes[0] = repMaxIndex;\r\n\t\t\t\tint lenRes = repLens[repMaxIndex];\r\n\t\t\t\tMovePos(lenRes - 1);\r\n\t\t\t\treturn lenRes;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif (lenMain >= 2)\r\n\t\t{\r\n\t\t\t_longestMatchLength = ReadMatchDistances();\r\n\t\t\tif (_longestMatchLength >= 2 &&\r\n\t\t\t\t\t(\r\n\t\t\t\t\t(_longestMatchLength >= lenMain &&\r\n\t\t\t\t\t_matchDistances[lenMain] < backMain) ||\r\n\t\t\t\t\t_longestMatchLength == lenMain + 1 &&\r\n\t\t\t\t\t!ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\r\n\t\t\t\t\t_longestMatchLength > lenMain + 1 ||\r\n\t\t\t\t\t_longestMatchLength + 1 >= lenMain && lenMain >= 3 &&\r\n\t\t\t\t\tChangePair(_matchDistances[lenMain - 1], backMain)\r\n\t\t\t\t\t)\r\n\t\t\t\t\t)\r\n\t\t\t{\r\n\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\tbackRes[0] = -1;\r\n\t\t\t\treturn 1;\r\n\t\t\t}\r\n\t\t\tfor (int i = 0; i < Base.kNumRepDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tint repLen = _matchFinder.GetMatchLen(0 - 1, _repDistances[i], Base.kMatchMaxLen);\r\n\t\t\t\tif (repLen >= 2 && repLen + 1 >= lenMain)\r\n\t\t\t\t{\r\n\t\t\t\t\t_longestMatchWasFound = true;\r\n\t\t\t\t\tbackRes[0] = -1;\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tbackRes[0] = backMain + Base.kNumRepDistances;\r\n\t\t\tMovePos(lenMain - 2);\r\n\t\t\treturn lenMain;\r\n\t\t}\r\n\t\tbackRes[0] = -1;\r\n\t\treturn 1;\r\n\t}\r\n\t\r\n\tvoid WriteEndMarker(int posState) throws IOException\r\n\t{\r\n\t\tif (!_writeEndMark)\r\n\t\t\treturn;\r\n\t\t\r\n\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 1);\r\n\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\tint len = Base.kMatchMinLen; // kMatchMaxLen;\r\n\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\tint posSlot = (1 << Base.kNumPosSlotBits) - 1;\r\n\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\tint footerBits = 30;\r\n\t\tint posReduced = (1 << footerBits) - 1;\r\n\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t}\r\n\t\r\n\tvoid Flush(int nowPos) throws IOException\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tWriteEndMarker(nowPos & _posStateMask);\r\n\t\t_rangeEncoder.FlushData();\r\n\t\t_rangeEncoder.FlushStream();\r\n\t}\r\n\t\r\n\tint[] posTemp = new int[1];\r\n\tpublic void CodeOneBlock(long[] inSize, long[] outSize, boolean[] finished) throws IOException\r\n\t{\r\n\t\tinSize[0] = 0;\r\n\t\toutSize[0] = 0;\r\n\t\tfinished[0] = true;\r\n\t\t\r\n\t\tif (_inStream != null)\r\n\t\t{\r\n\t\t\t_matchFinder.SetStream(_inStream);\r\n\t\t\t_matchFinder.Init();\r\n\t\t\t_needReleaseMFStream = true;\r\n\t\t\t_inStream = null;\r\n\t\t}\r\n\t\t\r\n\t\tif (_finished)\r\n\t\t\treturn;\r\n\t\t_finished = true;\r\n\t\t\r\n\t\t\r\n\t\tlong progressPosValuePrev = nowPos64;\r\n\t\tif (nowPos64 == 0)\r\n\t\t{\r\n\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t{\r\n\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tReadMatchDistances();\r\n\t\t\tint posState = (int)(nowPos64) & _posStateMask;\r\n\t\t\t_rangeEncoder.Encode(_isMatch, (_state << Base.kNumPosStatesBitsMax) + posState, 0);\r\n\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\tbyte curByte = _matchFinder.GetIndexByte(0 - _additionalOffset);\r\n\t\t\t_literalEncoder.GetSubCoder((int)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);\r\n\t\t\t_previousByte = curByte;\r\n\t\t\t_additionalOffset--;\r\n\t\t\tnowPos64++;\r\n\t\t}\r\n\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t{\r\n\t\t\tFlush((int)nowPos64);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint posState = ((int)nowPos64) & _posStateMask;\r\n\t\t\t\r\n\t\t\tint len;\r\n\t\t\tif (_fastMode)\r\n\t\t\t\tlen = GetOptimumFast((int)nowPos64, posTemp);\r\n\t\t\telse\r\n\t\t\t\tlen = GetOptimum((int)nowPos64, posTemp);\r\n\t\t\t\r\n\t\t\tint pos = posTemp[0];\r\n\t\t\t\r\n\t\t\tint complexState = (_state << Base.kNumPosStatesBitsMax) + posState;\r\n\t\t\tif (len == 1 && pos == -1)\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 0);\r\n\t\t\t\tbyte curByte = _matchFinder.GetIndexByte((int)(0 - _additionalOffset));\r\n\t\t\t\t\r\n\t\t\t\tLiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((int)nowPos64, _previousByte);\r\n\t\t\t\tif (!Base.StateIsCharState(_state))\r\n\t\t\t\t{\r\n\t\t\t\t\tbyte matchByte = _matchFinder.GetIndexByte((int)(0 - _repDistances[0] - 1 - _additionalOffset));\r\n\t\t\t\t\tsubCoder.EncodeMatched(_rangeEncoder, matchByte, curByte);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\tsubCoder.Encode(_rangeEncoder, curByte);\r\n\t\t\t\t_previousByte = curByte;\r\n\t\t\t\t_state = Base.StateUpdateChar(_state);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t_rangeEncoder.Encode(_isMatch, complexState, 1);\r\n\t\t\t\tif (pos < Base.kNumRepDistances)\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 1);\r\n\t\t\t\t\tif (pos == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 0);\r\n\t\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRep0Long, complexState, 1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG0, _state, 1);\r\n\t\t\t\t\t\tif (pos == 1)\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 0);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG1, _state, 1);\r\n\t\t\t\t\t\t\t_rangeEncoder.Encode(_isRepG2, _state, pos - 2);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (len == 1)\r\n\t\t\t\t\t\t_state = Base.StateUpdateShortRep(_state);\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_repMatchLenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\t\t_state = Base.StateUpdateRep(_state);\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t\tint distance = _repDistances[pos];\r\n\t\t\t\t\tif (pos != 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tfor (int i = pos; i >= 1; i--)\r\n\t\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_rangeEncoder.Encode(_isRep, _state, 0);\r\n\t\t\t\t\t_state = Base.StateUpdateMatch(_state);\r\n\t\t\t\t\t_lenEncoder.Encode(_rangeEncoder, len - Base.kMatchMinLen, posState);\r\n\t\t\t\t\tpos -= Base.kNumRepDistances;\r\n\t\t\t\t\tint posSlot = GetPosSlot(pos);\r\n\t\t\t\t\tint lenToPosState = Base.GetLenToPosState(len);\r\n\t\t\t\t\t_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (posSlot >= Base.kStartPosModelIndex)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint footerBits = (int)((posSlot >> 1) - 1);\r\n\t\t\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\t\tint posReduced = pos - baseVal;\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tif (posSlot < Base.kEndPosModelIndex)\r\n\t\t\t\t\t\t\tBitTreeEncoder.ReverseEncode(_posEncoders,\r\n\t\t\t\t\t\t\t\t\tbaseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);\r\n\t\t\t\t\t\t\t_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);\r\n\t\t\t\t\t\t\tif (!_fastMode)\r\n\t\t\t\t\t\t\t\tif (--_alignPriceCount == 0)\r\n\t\t\t\t\t\t\t\t\tFillAlignPrices();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tint distance = pos;\r\n\t\t\t\t\tfor (int i = Base.kNumRepDistances - 1; i >= 1; i--)\r\n\t\t\t\t\t\t_repDistances[i] = _repDistances[i - 1];\r\n\t\t\t\t\t_repDistances[0] = distance;\r\n\t\t\t\t}\r\n\t\t\t\t_previousByte = _matchFinder.GetIndexByte(len - 1 - _additionalOffset);\r\n\t\t\t}\r\n\t\t\t_additionalOffset -= len;\r\n\t\t\tnowPos64 += len;\r\n\t\t\tif (!_fastMode)\r\n\t\t\t\tif (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\r\n\t\t\t\t{\r\n\t\t\t\tFillPosSlotPrices();\r\n\t\t\t\tFillDistancesPrices();\r\n\t\t\t\tlastPosSlotFillingPos = nowPos64;\r\n\t\t\t\t}\r\n\t\t\tif (_additionalOffset == 0)\r\n\t\t\t{\r\n\t\t\t\tinSize[0] = nowPos64;\r\n\t\t\t\toutSize[0] = _rangeEncoder.GetProcessedSizeAdd();\r\n\t\t\t\tif (_matchFinder.GetNumAvailableBytes() == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tFlush((int)nowPos64);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tif (nowPos64 - progressPosValuePrev >= (1 << 12))\r\n\t\t\t\t{\r\n\t\t\t\t\t_finished = false;\r\n\t\t\t\t\tfinished[0] = false;\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid ReleaseMFStream()\r\n\t{\r\n\t\tif (_matchFinder != null && _needReleaseMFStream)\r\n\t\t{\r\n\t\t\t_matchFinder.ReleaseStream();\r\n\t\t\t_needReleaseMFStream = false;\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid SetOutStream(java.io.OutputStream outStream)\r\n\t{ _rangeEncoder.SetStream(outStream); }\r\n\tvoid ReleaseOutStream()\r\n\t{ _rangeEncoder.ReleaseStream(); }\r\n\t\r\n\tvoid ReleaseStreams()\r\n\t{\r\n\t\tReleaseMFStream();\r\n\t\tReleaseOutStream();\r\n\t}\r\n\t\r\n\tvoid SetStreams(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize)\r\n\t{\r\n\t\t_inStream = inStream;\r\n\t\t_finished = false;\r\n\t\tCreate();\r\n\t\tSetOutStream(outStream);\r\n\t\tInit();\r\n\t\t\r\n\t\tif (!_fastMode)\r\n\t\t{\r\n\t\t\tFillPosSlotPrices();\r\n\t\t\tFillDistancesPrices();\r\n\t\t\tFillAlignPrices();\r\n\t\t}\r\n\t\t\r\n\t\t_lenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_lenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t_repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - Base.kMatchMinLen);\r\n\t\t_repMatchLenEncoder.UpdateTables(1 << _posStateBits);\r\n\t\t\r\n\t\tlastPosSlotFillingPos = 0;\r\n\t\tnowPos64 = 0;\r\n\t}\r\n\t\r\n\tlong[] processedInSize = new long[1];\r\n\tlong[] processedOutSize = new long[1];\r\n\tboolean[] finished = new boolean[1];\r\n\tpublic void Code(java.io.InputStream inStream, java.io.OutputStream outStream,\r\n\t\t\tlong inSize, long outSize, ICodeProgress progress) throws IOException\r\n\t{\r\n\t\t_needReleaseMFStream = false;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tSetStreams(inStream, outStream, inSize, outSize);\r\n\t\t\twhile (true)\r\n\t\t\t{\r\n\t\t\t\tCodeOneBlock(processedInSize, processedOutSize, finished);\r\n\t\t\t\tif (finished[0])\r\n\t\t\t\t\treturn;\r\n\t\t\t\tif (progress != null)\r\n\t\t\t\t{\r\n\t\t\t\t\tprogress.SetProgress(processedInSize[0], processedOutSize[0]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\tReleaseStreams();\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic static final int kPropSize = 5;\r\n\tbyte[] properties = new byte[kPropSize];\r\n\tpublic void WriteCoderProperties(java.io.OutputStream outStream) throws IOException\r\n\t{\r\n\t\tproperties[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits);\r\n\t\tfor (int i = 0; i < 4; i++)\r\n\t\t\tproperties[1 + i] = (byte)(_dictionarySize >> (8 * i));\r\n\t\toutStream.write(properties, 0, kPropSize);\r\n\t}\r\n\t\r\n\tvoid FillPosSlotPrices()\r\n\t{\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint posSlot;\r\n\t\t\tfor (posSlot = 0; posSlot < Base.kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\r\n\t\t\tfor (; posSlot < _distTableSize; posSlot++)\r\n\t\t\t\t_posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) +\r\n\t\t\t\t\t\t((((posSlot >> 1) - 1) - Base.kNumAlignBits) << SevenZip.Compression.RangeCoder.Encoder.kNumBitPriceShiftBits);\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid FillDistancesPrices()\r\n\t{\r\n\t\tfor (int lenToPosState = 0; lenToPosState < Base.kNumLenToPosStates; lenToPosState++)\r\n\t\t{\r\n\t\t\tint i;\r\n\t\t\tfor (i = 0; i < Base.kStartPosModelIndex; i++)\r\n\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState];\r\n\t\t\tfor (; i < Base.kNumFullDistances; i++)\r\n\t\t\t{\r\n\t\t\t\tint posSlot = GetPosSlot(i);\r\n\t\t\t\tint footerBits = ((posSlot >> 1) - 1);\r\n\t\t\t\tint baseVal = ((2 | (posSlot & 1)) << footerBits);\r\n\t\t\t\t\r\n\t\t\t\t_distancesPrices[(i << Base.kNumLenToPosStatesBits) + lenToPosState] = _posSlotPrices[(posSlot << Base.kNumLenToPosStatesBits) + lenToPosState] +\r\n\t\t\t\t\t\tBitTreeEncoder.ReverseGetPrice(_posEncoders,\r\n\t\t\t\t\t\tbaseVal - posSlot - 1, footerBits, i - baseVal);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tvoid FillAlignPrices()\r\n\t{\r\n\t\tfor (int i = 0; i < Base.kAlignTableSize; i++)\r\n\t\t\t_alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\r\n\t\t_alignPriceCount = Base.kAlignTableSize;\r\n\t}\r\n\t\r\n\t\r\n\tpublic boolean SetAlgorithm(int algorithm)\r\n\t{\r\n\t\tif (algorithm < 0 || algorithm > 2)\r\n\t\t\treturn false;\r\n\t\t_fastMode = (algorithm == 0);\r\n\t\t_maxMode = (algorithm >= 2);\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetDictionarySize(int dictionarySize)\r\n\t{\r\n\t\tint kDicLogSizeMaxCompress = Base.kDicLogSizeMax;\r\n\t\tif (dictionarySize < (1 << Base.kDicLogSizeMin) || dictionarySize > (1 << kDicLogSizeMaxCompress))\r\n\t\t\treturn false;\r\n\t\t_dictionarySize = dictionarySize;\r\n\t\tint dicLogSize;\r\n\t\tfor (dicLogSize = 0; dictionarySize > (1 << dicLogSize); dicLogSize++);\r\n\t\t_distTableSize = dicLogSize * 2;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SeNumFastBytes(int numFastBytes)\r\n\t{\r\n\t\tif (numFastBytes < 5 || numFastBytes > Base.kMatchMaxLen)\r\n\t\t\treturn false;\r\n\t\t_numFastBytes = numFastBytes;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetMatchFinder(int matchFinderIndex)\r\n\t{\r\n\t\tif (matchFinderIndex < 0 || matchFinderIndex > 2)\r\n\t\t\treturn false;\r\n\t\tint matchFinderIndexPrev = _matchFinderType;\r\n\t\t_matchFinderType = matchFinderIndex;\r\n\t\tif (_matchFinder != null && matchFinderIndexPrev != _matchFinderType)\r\n\t\t{\r\n\t\t\t_dictionarySizePrev = -1;\r\n\t\t\t_matchFinder = null;\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic boolean SetLcLpPb(int lc, int lp, int pb)\r\n\t{\r\n\t\tif (\r\n\t\t\t\tlp < 0 || lp > Base.kNumLitPosStatesBitsEncodingMax ||\r\n\t\t\t\tlc < 0 || lc > Base.kNumLitContextBitsMax ||\r\n\t\t\t\tpb < 0 || pb > Base.kNumPosStatesBitsEncodingMax)\r\n\t\t\treturn false;\r\n\t\t_numLiteralPosStateBits = lp;\r\n\t\t_numLiteralContextBits = lc;\r\n\t\t_posStateBits = pb;\r\n\t\t_posStateMask = ((1) << _posStateBits) - 1;\r\n\t\treturn true;\r\n\t}\r\n\t\r\n\tpublic void SetEndMarkerMode(boolean endMarkerMode)\r\n\t{\r\n\t\t_writeEndMark = endMarkerMode;\r\n\t}\r\n\t\r\n\t\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeDecoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\n\r\npublic class BitTreeDecoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeDecoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic int Decode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r\n\t\t\tm = (m << 1) + rangeDecoder.DecodeBit(Models, m);\r\n\t\treturn m - (1 << NumBitLevels);\r\n\t}\r\n\t\r\n\tpublic int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n\t\r\n\tpublic static int ReverseDecode(short[] Models, int startIndex,\r\n\t\t\tDecoder rangeDecoder, int NumBitLevels) throws java.io.IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tint symbol = 0;\r\n\t\tfor (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r\n\t\t{\r\n\t\t\tint bit = rangeDecoder.DecodeBit(Models, startIndex + m);\r\n\t\t\tm <<= 1;\r\n\t\t\tm += bit;\r\n\t\t\tsymbol |= (bit << bitIndex);\r\n\t\t}\r\n\t\treturn symbol;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class BitTreeEncoder\r\n{\r\n\tshort[] Models;\r\n\tint NumBitLevels;\r\n\t\r\n\tpublic BitTreeEncoder(int numBitLevels)\r\n\t{\r\n\t\tNumBitLevels = numBitLevels;\r\n\t\tModels = new short[1 << numBitLevels];\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\tDecoder.InitBitModels(Models);\r\n\t}\r\n\t\r\n\tpublic void Encode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int  i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic int GetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int bitIndex = NumBitLevels; bitIndex != 0; )\r\n\t\t{\r\n\t\t\tbitIndex--;\r\n\t\t\tint bit = (symbol >>> bitIndex) & 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) + bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic int ReverseGetPrice(int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static int ReverseGetPrice(short[] Models, int startIndex,\r\n\t\t\tint NumBitLevels, int symbol)\r\n\t{\r\n\t\tint price = 0;\r\n\t\tint m = 1;\r\n\t\tfor (int i = NumBitLevels; i != 0; i--)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\tsymbol >>>= 1;\r\n\t\t\tprice += Encoder.GetPrice(Models[startIndex + m], bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t}\r\n\t\treturn price;\r\n\t}\r\n\t\r\n\tpublic static void ReverseEncode(short[] Models, int startIndex,\r\n\t\t\tEncoder rangeEncoder, int NumBitLevels, int symbol) throws IOException\r\n\t{\r\n\t\tint m = 1;\r\n\t\tfor (int i = 0; i < NumBitLevels; i++)\r\n\t\t{\r\n\t\t\tint bit = symbol & 1;\r\n\t\t\trangeEncoder.Encode(Models, startIndex + m, bit);\r\n\t\t\tm = (m << 1) | bit;\r\n\t\t\tsymbol >>= 1;\r\n\t\t}\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/RangeCoder/Decoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Decoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tint Range;\r\n\tint Code;\r\n\r\n\tjava.io.InputStream Stream;\r\n\t\r\n\tpublic final void SetStream(java.io.InputStream stream)\r\n\t{ \r\n\t\tStream = stream; \r\n\t}\r\n\t\r\n\tpublic final void ReleaseStream()\r\n\t{ \r\n\t\tStream = null; \r\n\t}\r\n\t\r\n\tpublic final void Init() throws IOException\r\n\t{\r\n\t\tCode = 0;\r\n\t\tRange = -1;\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tCode = (Code << 8) | Stream.read();\r\n\t}\r\n\t\r\n\tpublic final int DecodeDirectBits(int numTotalBits) throws IOException\r\n\t{\r\n\t\tint result = 0;\r\n\t\tfor (int i = numTotalBits; i != 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tint t = ((Code - Range) >>> 31);\r\n\t\t\tCode -= Range & (t - 1);\r\n\t\t\tresult = (result << 1) | (1 - t);\r\n\t\t\t\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\tpublic int DecodeBit(short []probs, int index) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif ((Code ^ 0x80000000) < (newBound ^ 0x80000000))\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRange -= newBound;\r\n\t\t\tCode -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t\tif ((Range & kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tCode = (Code << 8) | Stream.read();\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t}\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/Compression/RangeCoder/Encoder.java",
    "content": "package SevenZip.Compression.RangeCoder;\r\nimport java.io.IOException;\r\n\r\npublic class Encoder\r\n{\r\n\tstatic final int kTopMask = ~((1 << 24) - 1);\r\n\t\r\n\tstatic final int kNumBitModelTotalBits = 11;\r\n\tstatic final int kBitModelTotal = (1 << kNumBitModelTotalBits);\r\n\tstatic final int kNumMoveBits = 5;\r\n\t\r\n\tjava.io.OutputStream Stream;\r\n\r\n\tlong Low;\r\n\tint Range;\r\n\tint _cacheSize;\r\n\tint _cache;\r\n\t\r\n\tlong _position;\r\n\t\r\n\tpublic void SetStream(java.io.OutputStream stream)\r\n\t{\r\n\t\tStream = stream;\r\n\t}\r\n\t\r\n\tpublic void ReleaseStream()\r\n\t{\r\n\t\tStream = null;\r\n\t}\r\n\t\r\n\tpublic void Init()\r\n\t{\r\n\t\t_position = 0;\r\n\t\tLow = 0;\r\n\t\tRange = -1;\r\n\t\t_cacheSize = 1;\r\n\t\t_cache = 0;\r\n\t}\r\n\t\r\n\tpublic void FlushData() throws IOException\r\n\t{\r\n\t\tfor (int i = 0; i < 5; i++)\r\n\t\t\tShiftLow();\r\n\t}\r\n\t\r\n\tpublic void FlushStream() throws IOException\r\n\t{\r\n\t\tStream.flush();\r\n\t}\r\n\t\r\n\tpublic void ShiftLow() throws IOException\r\n\t{\r\n\t\tint LowHi = (int)(Low >>> 32);\r\n\t\tif (LowHi != 0 || Low < 0xFF000000L)\r\n\t\t{\r\n\t\t\t_position += _cacheSize;\r\n\t\t\tint temp = _cache;\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\tStream.write(temp + LowHi);\r\n\t\t\t\ttemp = 0xFF;\r\n\t\t\t}\r\n\t\t\twhile(--_cacheSize != 0);\r\n\t\t\t_cache = (((int)Low) >>> 24);\r\n\t\t}\r\n\t\t_cacheSize++;\r\n\t\tLow = (Low & 0xFFFFFF) << 8;\r\n\t}\r\n\t\r\n\tpublic void EncodeDirectBits(int v, int numTotalBits) throws IOException\r\n\t{\r\n\t\tfor (int i = numTotalBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tRange >>>= 1;\r\n\t\t\tif (((v >>> i) & 1) == 1)\r\n\t\t\t\tLow += Range;\r\n\t\t\tif ((Range & Encoder.kTopMask) == 0)\r\n\t\t\t{\r\n\t\t\t\tRange <<= 8;\r\n\t\t\t\tShiftLow();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tpublic long GetProcessedSizeAdd()\r\n\t{\r\n\t\treturn _cacheSize + _position + 4;\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\tstatic final int kNumMoveReducingBits = 2;\r\n\tpublic static final int kNumBitPriceShiftBits = 6;\r\n\t\r\n\tpublic static void InitBitModels(short []probs)\r\n\t{\r\n\t\tfor (int i = 0; i < probs.length; i++)\r\n\t\t\tprobs[i] = (kBitModelTotal >>> 1);\r\n\t}\r\n\t\r\n\tpublic void Encode(short []probs, int index, int symbol) throws IOException\r\n\t{\r\n\t\tint prob = probs[index];\r\n\t\tint newBound = (Range >>> kNumBitModelTotalBits) * prob;\r\n\t\tif (symbol == 0)\r\n\t\t{\r\n\t\t\tRange = newBound;\r\n\t\t\tprobs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLow += (newBound & 0xFFFFFFFFL);\r\n\t\t\tRange -= newBound;\r\n\t\t\tprobs[index] = (short)(prob - ((prob) >>> kNumMoveBits));\r\n\t\t}\r\n\t\tif ((Range & kTopMask) == 0)\r\n\t\t{\r\n\t\t\tRange <<= 8;\r\n\t\t\tShiftLow();\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static int[] ProbPrices = new int[kBitModelTotal >>> kNumMoveReducingBits];\r\n\t\r\n\tstatic\r\n\t{\r\n\t\tint kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\r\n\t\tfor (int i = kNumBits - 1; i >= 0; i--)\r\n\t\t{\r\n\t\t\tint start = 1 << (kNumBits - i - 1);\r\n\t\t\tint end = 1 << (kNumBits - i);\r\n\t\t\tfor (int j = start; j < end; j++)\r\n\t\t\t\tProbPrices[j] = (i << kNumBitPriceShiftBits) +\r\n\t\t\t\t\t\t(((end - j) << kNumBitPriceShiftBits) >>> (kNumBits - i - 1));\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic public int GetPrice(int Prob, int symbol)\r\n\t{\r\n\t\treturn ProbPrices[(((Prob - symbol) ^ ((-symbol))) & (kBitModelTotal - 1)) >>> kNumMoveReducingBits];\r\n\t}\r\n\tstatic public int GetPrice0(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[Prob >>> kNumMoveReducingBits]; \r\n\t}\r\n\tstatic public int GetPrice1(int Prob)\r\n\t{ \r\n\t\treturn ProbPrices[(kBitModelTotal - Prob) >>> kNumMoveReducingBits]; \r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/LzmaAlone.java",
    "content": "package SevenZip;\r\n\r\npublic class LzmaAlone\r\n{\r\n\tstatic public class CommandLine\r\n\t{\r\n\t\tpublic static final int kEncode = 0;\r\n\t\tpublic static final int kDecode = 1;\r\n\t\tpublic static final int kBenchmak = 2;\r\n\t\t\r\n\t\tpublic int Command = -1;\r\n\t\tpublic int NumBenchmarkPasses = 10;\r\n\t\t\r\n\t\tpublic int DictionarySize = 1 << 23;\r\n\t\tpublic boolean DictionarySizeIsDefined = false;\r\n\t\t\r\n\t\tpublic int Lc = 3;\r\n\t\tpublic int Lp = 0;\r\n\t\tpublic int Pb = 2;\r\n\t\t\r\n\t\tpublic int Fb = 128;\r\n\t\tpublic boolean FbIsDefined = false;\r\n\t\t\r\n\t\tpublic boolean Eos = false;\r\n\t\t\r\n\t\tpublic int Algorithm = 2;\r\n\t\tpublic int MatchFinder = 1;\r\n\t\t\r\n\t\tpublic String InFile;\r\n\t\tpublic String OutFile;\r\n\t\t\r\n\t\tboolean ParseSwitch(String s)\r\n\t\t{\r\n\t\t\tif (s.startsWith(\"d\"))\r\n\t\t\t{\r\n\t\t\t\tDictionarySize = 1 << Integer.parseInt(s.substring(1));\r\n\t\t\t\tDictionarySizeIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"fb\"))\r\n\t\t\t{\r\n\t\t\t\tFb = Integer.parseInt(s.substring(2));\r\n\t\t\t\tFbIsDefined = true;\r\n\t\t\t}\r\n\t\t\telse if (s.startsWith(\"a\"))\r\n\t\t\t\tAlgorithm = Integer.parseInt(s.substring(1));\r\n\t\t\telse if (s.startsWith(\"lc\"))\r\n\t\t\t\tLc = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"lp\"))\r\n\t\t\t\tLp = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"pb\"))\r\n\t\t\t\tPb = Integer.parseInt(s.substring(2));\r\n\t\t\telse if (s.startsWith(\"eos\"))\r\n\t\t\t\tEos = true;\r\n\t\t\telse if (s.startsWith(\"mf\"))\r\n\t\t\t{\r\n\t\t\t\tString mfs = s.substring(2);\r\n\t\t\t\tif (mfs.equals(\"bt2\"))\r\n\t\t\t\t\tMatchFinder = 0;\r\n\t\t\t\telse if (mfs.equals(\"bt4\"))\r\n\t\t\t\t\tMatchFinder = 1;\r\n\t\t\t\telse if (mfs.equals(\"bt4b\"))\r\n\t\t\t\t\tMatchFinder = 2;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\t\r\n\t\tpublic boolean Parse(String[] args) throws Exception\r\n\t\t{\r\n\t\t\tint pos = 0;\r\n\t\t\tboolean switchMode = true;\r\n\t\t\tfor (int i = 0; i < args.length; i++)\r\n\t\t\t{\r\n\t\t\t\tString s = args[i];\r\n\t\t\t\tif (s.length() == 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tif (switchMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.compareTo(\"--\") == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tswitchMode = false;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (s.charAt(0) == '-')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tString sw = s.substring(1).toLowerCase();\r\n\t\t\t\t\t\tif (sw.length() == 0)\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (!ParseSwitch(sw))\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif (pos == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s.equalsIgnoreCase(\"e\"))\r\n\t\t\t\t\t\tCommand = kEncode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"d\"))\r\n\t\t\t\t\t\tCommand = kDecode;\r\n\t\t\t\t\telse if (s.equalsIgnoreCase(\"b\"))\r\n\t\t\t\t\t\tCommand = kBenchmak;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\treturn false;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (Command == kBenchmak)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttry\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tNumBenchmarkPasses = Integer.parseInt(s);\r\n\t\t\t\t\t\t\tif (NumBenchmarkPasses < 1)\r\n\t\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (NumberFormatException e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\treturn false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\tInFile = s;\r\n\t\t\t\t}\r\n\t\t\t\telse if(pos == 2)\r\n\t\t\t\t\tOutFile = s;\r\n\t\t\t\telse\r\n\t\t\t\t\treturn false;\r\n\t\t\t\tpos++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\r\n\tstatic void PrintHelp()\r\n\t{\r\n\t\tSystem.out.println(\r\n\t\t\t\t\"\\nUsage:  LZMA <e|d> [<switches>...] inputFile outputFile\\n\" +\r\n\t\t\t\t\"  e: encode file\\n\" +\r\n\t\t\t\t\"  d: decode file\\n\" +\r\n\t\t\t\t\"  b: Benchmark\\n\" +\r\n\t\t\t\t\"<Switches>\\n\" +\r\n\t\t\t\t\"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\" +\r\n\t\t\t\t\"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\" +\r\n\t\t\t\t\"  -fb{N}: set number of fast bytes - [5, 273], default: 128\\n\" +\r\n\t\t\t\t\"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\" +\r\n\t\t\t\t\"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\" +\r\n\t\t\t\t\"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\" +\r\n\t\t\t\t\"  -mf{MF_ID}: set Match Finder: [bt2, bt4, bt4b], default: bt4\\n\" +\r\n\t\t\t\t\"  -eos:   write End Of Stream marker\\n\"\r\n\t\t\t\t);\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception\r\n\t{\r\n\t\tSystem.out.println(\"\\nLZMA (Java) 4.32 Copyright (c) 1999-2005 Igor Pavlov  2005-12-09\\n\");\r\n\t\t\r\n\t\tif (args.length < 1)\r\n\t\t{\r\n\t\t\tPrintHelp();\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tCommandLine params = new CommandLine();\r\n\t\tif (!params.Parse(args))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nIncorrect command\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tif (params.Command == CommandLine.kBenchmak)\r\n\t\t{\r\n\t\t\tint dictionary = (1 << 21);\r\n\t\t\tif (params.DictionarySizeIsDefined)\r\n\t\t\t\tdictionary = params.DictionarySize;\r\n\t\t\tif (params.MatchFinder > 1)\r\n\t\t\t\tthrow new Exception(\"Unsupported match finder\");\r\n\t\t\tSevenZip.LzmaBench.LzmaBenchmark(params.NumBenchmarkPasses, dictionary, params.MatchFinder >= 1);\r\n\t\t}\r\n\t\telse if (params.Command == CommandLine.kEncode || params.Command == CommandLine.kDecode)\r\n\t\t{\r\n\t\t\tjava.io.File inFile = new java.io.File(params.InFile);\r\n\t\t\tjava.io.File outFile = new java.io.File(params.OutFile);\r\n\t\t\t\r\n\t\t\tjava.io.BufferedInputStream inStream  = new java.io.BufferedInputStream(new java.io.FileInputStream(inFile));\r\n\t\t\tjava.io.BufferedOutputStream outStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outFile));\r\n\t\t\t\r\n\t\t\tboolean eos = false;\r\n\t\t\tif (params.Eos)\r\n\t\t\t\teos = true;\r\n\t\t\tif (params.Command == CommandLine.kEncode)\r\n\t\t\t{\r\n\t\t\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\t\t\tif (!encoder.SetAlgorithm(params.Algorithm))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect compression mode\");\r\n\t\t\t\tif (!encoder.SetDictionarySize(params.DictionarySize))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\t\t\tif (!encoder.SeNumFastBytes(params.Fb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -fb value\");\r\n\t\t\t\tif (!encoder.SetMatchFinder(params.MatchFinder))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -mf value\");\r\n\t\t\t\tif (!encoder.SetLcLpPb(params.Lc, params.Lp, params.Pb))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect -lc or -lp or -pb value\");\r\n\t\t\t\tencoder.SetEndMarkerMode(eos);\r\n\t\t\t\tencoder.WriteCoderProperties(outStream);\r\n\t\t\t\tlong fileSize;\r\n\t\t\t\tif (eos)\r\n\t\t\t\t\tfileSize = -1;\r\n\t\t\t\telse\r\n\t\t\t\t\tfileSize = inFile.length();\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t\toutStream.write((int)(fileSize >>> (8 * i)) & 0xFF);\r\n\t\t\t\tencoder.Code(inStream, outStream, -1, -1, null);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tint propertiesSize = 5;\r\n\t\t\t\tbyte[] properties = new byte[propertiesSize];\r\n\t\t\t\tif (inStream.read(properties, 0, propertiesSize) != propertiesSize)\r\n\t\t\t\t\tthrow new Exception(\"input .lzma file is too short\");\r\n\t\t\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\t\tif (!decoder.SetDecoderProperties(properties))\r\n\t\t\t\t\tthrow new Exception(\"Incorrect stream properties\");\r\n\t\t\t\tlong outSize = 0;\r\n\t\t\t\tfor (int i = 0; i < 8; i++)\r\n\t\t\t\t{\r\n\t\t\t\t\tint v = inStream.read();\r\n\t\t\t\t\tif (v < 0)\r\n\t\t\t\t\t\tthrow new Exception(\"Can't read stream size\");\r\n\t\t\t\t\toutSize |= ((long)v) << (8 * i);\r\n\t\t\t\t}\r\n\t\t\t\tif (!decoder.Code(inStream, outStream, outSize))\r\n\t\t\t\t\tthrow new Exception(\"Error in data stream\");\r\n\t\t\t}\r\n\t\t\toutStream.flush();\r\n\t\t\toutStream.close();\r\n\t\t\tinStream.close();\r\n\t\t}\r\n\t\telse\r\n\t\t\tthrow new Exception(\"Incorrect command\");\r\n\t\treturn;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Java/SevenZip/LzmaBench.java",
    "content": "package SevenZip;\r\n\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class LzmaBench\r\n{\r\n\tstatic final int kAdditionalSize = (1 << 21);\r\n\tstatic final int kCompressedAdditionalSize = (1 << 10);\r\n\t\r\n\tstatic class CRandomGenerator\r\n\t{\r\n\t\tint A1;\r\n\t\tint A2;\r\n\t\tpublic CRandomGenerator()\r\n\t\t{ Init(); }\r\n\t\tpublic void Init()\r\n\t\t{ A1 = 362436069; A2 = 521288629; }\r\n\t\tpublic int GetRnd()\r\n\t\t{\r\n\t\t\treturn\r\n\t\t\t\t\t((A1 = 36969 * (A1 & 0xffff) + (A1 >>> 16)) << 16) ^\r\n\t\t\t\t\t((A2 = 18000 * (A2 & 0xffff) + (A2 >>> 16)));\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBitRandomGenerator\r\n\t{\r\n\t\tCRandomGenerator RG = new CRandomGenerator();\r\n\t\tint Value;\r\n\t\tint NumBits;\r\n\t\tpublic void Init()\r\n\t\t{\r\n\t\t\tValue = 0;\r\n\t\t\tNumBits = 0;\r\n\t\t}\r\n\t\tpublic int GetRnd(int numBits)\r\n\t\t{\r\n\t\t\tint result;\r\n\t\t\tif (NumBits > numBits)\r\n\t\t\t{\r\n\t\t\t\tresult = Value & ((1 << numBits) - 1);\r\n\t\t\t\tValue >>>= numBits;\r\n\t\t\t\tNumBits -= numBits;\r\n\t\t\t\treturn result;\r\n\t\t\t}\r\n\t\t\tnumBits -= NumBits;\r\n\t\t\tresult = (Value << numBits);\r\n\t\t\tValue = RG.GetRnd();\r\n\t\t\tresult |= Value & (((int)1 << numBits) - 1);\r\n\t\t\tValue >>>= numBits;\r\n\t\t\tNumBits = 32 - numBits;\r\n\t\t\treturn result;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CBenchRandomGenerator\r\n\t{\r\n\t\tCBitRandomGenerator RG = new CBitRandomGenerator();\r\n\t\tint Pos;\r\n\t\tpublic int BufferSize;\r\n\t\tpublic byte[] Buffer = null;\r\n\t\tpublic CBenchRandomGenerator()\r\n\t\t{ }\r\n\t\tpublic void Init()\r\n\t\t{ RG.Init(); }\r\n\t\tpublic void Set(int bufferSize)\r\n\t\t{\r\n\t\t\tBuffer = new byte[bufferSize];\r\n\t\t\tPos = 0;\r\n\t\t\tBufferSize = bufferSize;\r\n\t\t}\r\n\t\tint GetRndBit()\r\n\t\t{ return RG.GetRnd(1); }\r\n\t\tint GetLogRandBits(int numBits)\r\n\t\t{\r\n\t\t\tint len = RG.GetRnd(numBits);\r\n\t\t\treturn RG.GetRnd((int)len);\r\n\t\t}\r\n\t\tint GetOffset()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn GetLogRandBits(4);\r\n\t\t\treturn (GetLogRandBits(4) << 10) | RG.GetRnd(10);\r\n\t\t}\r\n\t\tint GetLen()\r\n\t\t{\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn RG.GetRnd(2);\r\n\t\t\tif (GetRndBit() == 0)\r\n\t\t\t\treturn 4 + RG.GetRnd(3);\r\n\t\t\treturn 12 + RG.GetRnd(4);\r\n\t\t}\r\n\t\tpublic void Generate()\r\n\t\t{\r\n\t\t\twhile (Pos < BufferSize)\r\n\t\t\t{\r\n\t\t\t\tif (GetRndBit() == 0 || Pos < 1)\r\n\t\t\t\t\tBuffer[Pos++] = (byte)(RG.GetRnd(8));\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint offset = GetOffset();\r\n\t\t\t\t\twhile (offset >= Pos)\r\n\t\t\t\t\t\toffset >>>= 1;\r\n\t\t\t\t\toffset += 1;\r\n\t\t\t\t\tint len = 2 + GetLen();\r\n\t\t\t\t\tfor (int i = 0; i < len && Pos < BufferSize; i++, Pos++)\r\n\t\t\t\t\t\tBuffer[Pos] = Buffer[Pos - offset];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CrcOutStream extends java.io.OutputStream\r\n\t{\r\n\t\tpublic CRC CRC = new CRC();\r\n\t\t\r\n\t\tpublic void Init()\r\n\t\t{ \r\n\t\t\tCRC.Init(); \r\n\t\t}\r\n\t\tpublic int GetDigest()\r\n\t\t{ \r\n\t\t\treturn CRC.GetDigest(); \r\n\t\t}\r\n\t\tpublic void write(byte[] b)\r\n\t\t{\r\n\t\t\tCRC.Update(b);\r\n\t\t}\r\n\t\tpublic void write(byte[] b, int off, int len)\r\n\t\t{\r\n\t\t\tCRC.Update(b, off, len);\r\n\t\t}\r\n\t\tpublic void write(int b)\r\n\t\t{\r\n\t\t\tCRC.UpdateByte(b);\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyOutputStream extends java.io.OutputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyOutputStream(byte[] buffer)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = _buffer.length;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic void write(int b) throws IOException\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\tthrow new IOException(\"Error\");\r\n\t\t\t_buffer[_pos++] = (byte)b;\r\n\t\t}\r\n\t\t\r\n\t\tpublic int size()\r\n\t\t{\r\n\t\t\treturn _pos;\r\n\t\t}\r\n\t};\r\n\r\n\tstatic class MyInputStream extends java.io.InputStream\r\n\t{\r\n\t\tbyte[] _buffer;\r\n\t\tint _size;\r\n\t\tint _pos;\r\n\t\t\r\n\t\tpublic MyInputStream(byte[] buffer, int size)\r\n\t\t{\r\n\t\t\t_buffer = buffer;\r\n\t\t\t_size = size;\r\n\t\t}\r\n\t\t\r\n\t\tpublic void reset()\r\n\t\t{ \r\n\t\t\t_pos = 0; \r\n\t\t}\r\n\t\t\r\n\t\tpublic int read()\r\n\t\t{\r\n\t\t\tif (_pos >= _size)\r\n\t\t\t\treturn -1;\r\n\t\t\treturn _buffer[_pos++] & 0xFF;\r\n\t\t}\r\n\t};\r\n\t\r\n\tstatic class CProgressInfo implements ICodeProgress\r\n\t{\r\n\t\tpublic long ApprovedStart;\r\n\t\tpublic long InSize;\r\n\t\tpublic long Time;\r\n\t\tpublic void Init()\r\n\t\t{ InSize = 0; }\r\n\t\tpublic void SetProgress(long inSize, long outSize)\r\n\t\t{\r\n\t\t\tif (inSize >= ApprovedStart && InSize == 0)\r\n\t\t\t{\r\n\t\t\t\tTime = System.currentTimeMillis();\r\n\t\t\t\tInSize = inSize;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic final int kSubBits = 8;\r\n\t\r\n\tstatic int GetLogSize(int size)\r\n\t{\r\n\t\tfor (int i = kSubBits; i < 32; i++)\r\n\t\t\tfor (int j = 0; j < (1 << kSubBits); j++)\r\n\t\t\t\tif (size <= ((1) << i) + (j << (i - kSubBits)))\r\n\t\t\t\t\treturn (i << kSubBits) + j;\r\n\t\treturn (32 << kSubBits);\r\n\t}\r\n\t\r\n\tstatic long MyMultDiv64(long value, long elapsedTime)\r\n\t{\r\n\t\tlong freq = 1000; // ms\r\n\t\tlong elTime = elapsedTime;\r\n\t\twhile (freq > 1000000)\r\n\t\t{\r\n\t\t\tfreq >>>= 1;\r\n\t\t\telTime >>>= 1;\r\n\t\t}\r\n\t\tif (elTime == 0)\r\n\t\t\telTime = 1;\r\n\t\treturn value * freq / elTime;\r\n\t}\r\n\t\r\n\tstatic long GetCompressRating(int dictionarySize, boolean isBT4, long elapsedTime, long size)\r\n\t{\r\n\t\tlong numCommandsForOne;\r\n\t\tif (isBT4)\r\n\t\t{\r\n\t\t\tlong t = GetLogSize(dictionarySize) - (19 << kSubBits);\r\n\t\t\tnumCommandsForOne = 2000 + ((t * t * 68) >>> (2 * kSubBits));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong t = GetLogSize(dictionarySize) - (15 << kSubBits);\r\n\t\t\tnumCommandsForOne = 1500 + ((t * t * 41) >>> (2 * kSubBits));\r\n\t\t}\r\n\t\tlong numCommands = (long)(size) * numCommandsForOne;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetDecompressRating(long elapsedTime,\r\n\t\t\tlong outSize, long inSize)\r\n\t{\r\n\t\tlong numCommands = inSize * 250 + outSize * 21;\r\n\t\treturn MyMultDiv64(numCommands, elapsedTime);\r\n\t}\r\n\t\r\n\tstatic long GetTotalRating(\r\n\t\t\tint dictionarySize,\r\n\t\t\tboolean isBT4,\r\n\t\t\tlong elapsedTimeEn, long sizeEn,\r\n\t\t\tlong elapsedTimeDe,\r\n\t\t\tlong inSizeDe, long outSizeDe)\r\n\t{\r\n\t\treturn (GetCompressRating(dictionarySize, isBT4, elapsedTimeEn, sizeEn) +\r\n\t\t\t\tGetDecompressRating(elapsedTimeDe, inSizeDe, outSizeDe)) / 2;\r\n\t}\r\n\t\r\n\tstatic void PrintValue(long v)\r\n\t{\r\n\t\tString s = \"\";\r\n\t\ts += v;\r\n\t\tfor (int i = 0; i + s.length() < 6; i++)\r\n\t\t\tSystem.out.print(\" \");\r\n\t\tSystem.out.print(s);\r\n\t}\r\n\t\r\n\tstatic void PrintRating(long rating)\r\n\t{\r\n\t\tPrintValue(rating / 1000000);\r\n\t\tSystem.out.print(\" MIPS\");\r\n\t}\r\n\t\r\n\tstatic void PrintResults(\r\n\t\t\tint dictionarySize,\r\n\t\t\tboolean isBT4,\r\n\t\t\tlong elapsedTime,\r\n\t\t\tlong size,\r\n\t\t\tboolean decompressMode, long secondSize)\r\n\t{\r\n\t\tlong speed = MyMultDiv64(size, elapsedTime);\r\n\t\tPrintValue(speed / 1024);\r\n\t\tSystem.out.print(\" KB/s  \");\r\n\t\tlong rating;\r\n\t\tif (decompressMode)\r\n\t\t\trating = GetDecompressRating(elapsedTime, size, secondSize);\r\n\t\telse\r\n\t\t\trating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\r\n\t\tPrintRating(rating);\r\n\t}\r\n\t\r\n\tString bt2 = \"BT2\";\r\n\tString bt4 = \"BT4\";\r\n\t\r\n\tstatic public int LzmaBenchmark(int numIterations, int dictionarySize, boolean isBT4) throws Exception\r\n\t{\r\n\t\tif (numIterations <= 0)\r\n\t\t\treturn 0;\r\n\t\tif (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\");\r\n\t\t\treturn 1;\r\n\t\t}\r\n\t\tSystem.out.print(\"\\n       Compressing                Decompressing\\n\\n\");\r\n\t\t\r\n\t\tSevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder();\r\n\t\tSevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();\r\n\t\t\r\n\t\t\tif (!encoder.SetDictionarySize(dictionarySize))\r\n\t\t\tthrow new Exception(\"Incorrect dictionary size\");\r\n\t\tif (!encoder.SetMatchFinder(isBT4 ?\r\n\t\t\tSevenZip.Compression.LZMA.Encoder.EMatchFinderTypeBT4:\r\n\t\t\tSevenZip.Compression.LZMA.Encoder.EMatchFinderTypeBT2))\r\n\t\t\tthrow new Exception(\"Incorrect MatchFinder\");\r\n\t\t\r\n\t\tint kBufferSize = dictionarySize + kAdditionalSize;\r\n\t\tint kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\r\n\t\t\r\n\t\tByteArrayOutputStream propStream = new ByteArrayOutputStream();\r\n\t\tencoder.WriteCoderProperties(propStream);\r\n\t\tbyte[] propArray = propStream.toByteArray();\r\n\t\tdecoder.SetDecoderProperties(propArray);\r\n\t\t\r\n\t\tCBenchRandomGenerator rg = new CBenchRandomGenerator();\r\n\r\n\t\trg.Init();\r\n\t\trg.Set(kBufferSize);\r\n\t\trg.Generate();\r\n\t\tCRC crc = new CRC();\r\n\t\tcrc.Init();\r\n\t\tcrc.Update(rg.Buffer, 0, rg.BufferSize);\r\n\t\t\r\n\t\tCProgressInfo progressInfo = new CProgressInfo();\r\n\t\tprogressInfo.ApprovedStart = dictionarySize;\r\n\t\t\r\n\t\tlong totalBenchSize = 0;\r\n\t\tlong totalEncodeTime = 0;\r\n\t\tlong totalDecodeTime = 0;\r\n\t\tlong totalCompressedSize = 0;\r\n\t\t\r\n\t\tMyInputStream inStream = new MyInputStream(rg.Buffer, rg.BufferSize);\r\n\r\n\t\tbyte[] compressedBuffer = new byte[kCompressedBufferSize];\r\n\t\tMyOutputStream compressedStream = new MyOutputStream(compressedBuffer);\r\n\t\tCrcOutStream crcOutStream = new CrcOutStream();\r\n\t\tMyInputStream inputCompressedStream = null;\r\n\t\tint compressedSize = 0;\r\n\t\tfor (int i = 0; i < numIterations; i++)\r\n\t\t{\r\n\t\t\tprogressInfo.Init();\r\n\t\t\tinStream.reset();\r\n\t\t\tcompressedStream.reset();\r\n\t\t\tencoder.Code(inStream, compressedStream, -1, -1, progressInfo);\r\n\t\t\tlong encodeTime = System.currentTimeMillis() - progressInfo.Time;\r\n\t\t\t\r\n\t\t\tif (i == 0)\r\n\t\t\t{\r\n\t\t\t\tcompressedSize = compressedStream.size();\r\n\t\t\t\tinputCompressedStream = new MyInputStream(compressedBuffer, compressedSize);\r\n\t\t\t}\r\n\t\t\telse if (compressedSize != compressedStream.size())\r\n\t\t\t\tthrow (new Exception(\"Encoding error\"));\r\n\t\t\t\t\r\n\t\t\tif (progressInfo.InSize == 0)\r\n\t\t\t\tthrow (new Exception(\"Internal ERROR 1282\"));\r\n\r\n\t\t\tlong decodeTime = 0;\r\n\t\t\tfor (int j = 0; j < 2; j++)\r\n\t\t\t{\r\n\t\t\t\tinputCompressedStream.reset();\r\n\t\t\t\tcrcOutStream.Init();\r\n\t\t\t\t\r\n\t\t\t\tlong outSize = kBufferSize;\r\n\t\t\t\tlong startTime = System.currentTimeMillis();\r\n\t\t\t\tif (!decoder.Code(inputCompressedStream, crcOutStream, outSize))\r\n\t\t\t\t\tthrow (new Exception(\"Decoding Error\"));;\r\n\t\t\t\tdecodeTime = System.currentTimeMillis() - startTime;\r\n\t\t\t\tif (crcOutStream.GetDigest() != crc.GetDigest())\r\n\t\t\t\t\tthrow (new Exception(\"CRC Error\"));\r\n\t\t\t}\r\n\t\t\tlong benchSize = kBufferSize - (long)progressInfo.InSize;\r\n\t\t\tPrintResults(dictionarySize, isBT4, encodeTime, benchSize, false, 0);\r\n\t\t\tSystem.out.print(\"     \");\r\n\t\t\tPrintResults(dictionarySize, isBT4, decodeTime, kBufferSize, true, compressedSize);\r\n\t\t\tSystem.out.println();\r\n\t\t\t\r\n\t\t\ttotalBenchSize += benchSize;\r\n\t\t\ttotalEncodeTime += encodeTime;\r\n\t\t\ttotalDecodeTime += decodeTime;\r\n\t\t\ttotalCompressedSize += compressedSize;\r\n\t\t}\r\n\t\tSystem.out.println(\"---------------------------------------------------\");\r\n\t\tPrintResults(dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\r\n\t\tSystem.out.print(\"     \");\r\n\t\tPrintResults(dictionarySize, isBT4, totalDecodeTime,\r\n\t\t\t\tkBufferSize * (long)numIterations, true, totalCompressedSize);\r\n\t\tSystem.out.println(\"    Average\");\r\n\t\treturn 0;\r\n\t}\r\n}\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/LGPL.txt",
    "content": "      GNU LESSER GENERAL PUBLIC LICENSE\r\n           Version 2.1, February 1999\r\n\r\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\r\n     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n Everyone is permitted to copy and distribute verbatim copies\r\n of this license document, but changing it is not allowed.\r\n\r\n[This is the first released version of the Lesser GPL.  It also counts\r\n as the successor of the GNU Library Public License, version 2, hence\r\n the version number 2.1.]\r\n\r\n          Preamble\r\n\r\n  The licenses for most software are designed to take away your\r\nfreedom to share and change it.  By contrast, the GNU General Public\r\nLicenses are intended to guarantee your freedom to share and change\r\nfree software--to make sure the software is free for all its users.\r\n\r\n  This license, the Lesser General Public License, applies to some\r\nspecially designated software packages--typically libraries--of the\r\nFree Software Foundation and other authors who decide to use it.  You\r\ncan use it too, but we suggest you first think carefully about whether\r\nthis license or the ordinary General Public License is the better\r\nstrategy to use in any particular case, based on the explanations below.\r\n\r\n  When we speak of free software, we are referring to freedom of use,\r\nnot price.  Our General Public Licenses are designed to make sure that\r\nyou have the freedom to distribute copies of free software (and charge\r\nfor this service if you wish); that you receive source code or can get\r\nit if you want it; that you can change the software and use pieces of\r\nit in new free programs; and that you are informed that you can do\r\nthese things.\r\n\r\n  To protect your rights, we need to make restrictions that forbid\r\ndistributors to deny you these rights or to ask you to surrender these\r\nrights.  These restrictions translate to certain responsibilities for\r\nyou if you distribute copies of the library or if you modify it.\r\n\r\n  For example, if you distribute copies of the library, whether gratis\r\nor for a fee, you must give the recipients all the rights that we gave\r\nyou.  You must make sure that they, too, receive or can get the source\r\ncode.  If you link other code with the library, you must provide\r\ncomplete object files to the recipients, so that they can relink them\r\nwith the library after making changes to the library and recompiling\r\nit.  And you must show them these terms so they know their rights.\r\n\r\n  We protect your rights with a two-step method: (1) we copyright the\r\nlibrary, and (2) we offer you this license, which gives you legal\r\npermission to copy, distribute and/or modify the library.\r\n\r\n  To protect each distributor, we want to make it very clear that\r\nthere is no warranty for the free library.  Also, if the library is\r\nmodified by someone else and passed on, the recipients should know\r\nthat what they have is not the original version, so that the original\r\nauthor's reputation will not be affected by problems that might be\r\nintroduced by others.\r\n\f\r\n  Finally, software patents pose a constant threat to the existence of\r\nany free program.  We wish to make sure that a company cannot\r\neffectively restrict the users of a free program by obtaining a\r\nrestrictive license from a patent holder.  Therefore, we insist that\r\nany patent license obtained for a version of the library must be\r\nconsistent with the full freedom of use specified in this license.\r\n\r\n  Most GNU software, including some libraries, is covered by the\r\nordinary GNU General Public License.  This license, the GNU Lesser\r\nGeneral Public License, applies to certain designated libraries, and\r\nis quite different from the ordinary General Public License.  We use\r\nthis license for certain libraries in order to permit linking those\r\nlibraries into non-free programs.\r\n\r\n  When a program is linked with a library, whether statically or using\r\na shared library, the combination of the two is legally speaking a\r\ncombined work, a derivative of the original library.  The ordinary\r\nGeneral Public License therefore permits such linking only if the\r\nentire combination fits its criteria of freedom.  The Lesser General\r\nPublic License permits more lax criteria for linking other code with\r\nthe library.\r\n\r\n  We call this license the \"Lesser\" General Public License because it\r\ndoes Less to protect the user's freedom than the ordinary General\r\nPublic License.  It also provides other free software developers Less\r\nof an advantage over competing non-free programs.  These disadvantages\r\nare the reason we use the ordinary General Public License for many\r\nlibraries.  However, the Lesser license provides advantages in certain\r\nspecial circumstances.\r\n\r\n  For example, on rare occasions, there may be a special need to\r\nencourage the widest possible use of a certain library, so that it becomes\r\na de-facto standard.  To achieve this, non-free programs must be\r\nallowed to use the library.  A more frequent case is that a free\r\nlibrary does the same job as widely used non-free libraries.  In this\r\ncase, there is little to gain by limiting the free library to free\r\nsoftware only, so we use the Lesser General Public License.\r\n\r\n  In other cases, permission to use a particular library in non-free\r\nprograms enables a greater number of people to use a large body of\r\nfree software.  For example, permission to use the GNU C Library in\r\nnon-free programs enables many more people to use the whole GNU\r\noperating system, as well as its variant, the GNU/Linux operating\r\nsystem.\r\n\r\n  Although the Lesser General Public License is Less protective of the\r\nusers' freedom, it does ensure that the user of a program that is\r\nlinked with the Library has the freedom and the wherewithal to run\r\nthat program using a modified version of the Library.\r\n\r\n  The precise terms and conditions for copying, distribution and\r\nmodification follow.  Pay close attention to the difference between a\r\n\"work based on the library\" and a \"work that uses the library\".  The\r\nformer contains code derived from the library, whereas the latter must\r\nbe combined with the library in order to run.\r\n\f\r\n      GNU LESSER GENERAL PUBLIC LICENSE\r\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\r\n\r\n  0. This License Agreement applies to any software library or other\r\nprogram which contains a notice placed by the copyright holder or\r\nother authorized party saying it may be distributed under the terms of\r\nthis Lesser General Public License (also called \"this License\").\r\nEach licensee is addressed as \"you\".\r\n\r\n  A \"library\" means a collection of software functions and/or data\r\nprepared so as to be conveniently linked with application programs\r\n(which use some of those functions and data) to form executables.\r\n\r\n  The \"Library\", below, refers to any such software library or work\r\nwhich has been distributed under these terms.  A \"work based on the\r\nLibrary\" means either the Library or any derivative work under\r\ncopyright law: that is to say, a work containing the Library or a\r\nportion of it, either verbatim or with modifications and/or translated\r\nstraightforwardly into another language.  (Hereinafter, translation is\r\nincluded without limitation in the term \"modification\".)\r\n\r\n  \"Source code\" for a work means the preferred form of the work for\r\nmaking modifications to it.  For a library, complete source code means\r\nall the source code for all modules it contains, plus any associated\r\ninterface definition files, plus the scripts used to control compilation\r\nand installation of the library.\r\n\r\n  Activities other than copying, distribution and modification are not\r\ncovered by this License; they are outside its scope.  The act of\r\nrunning a program using the Library is not restricted, and output from\r\nsuch a program is covered only if its contents constitute a work based\r\non the Library (independent of the use of the Library in a tool for\r\nwriting it).  Whether that is true depends on what the Library does\r\nand what the program that uses the Library does.\r\n  \r\n  1. You may copy and distribute verbatim copies of the Library's\r\ncomplete source code as you receive it, in any medium, provided that\r\nyou conspicuously and appropriately publish on each copy an\r\nappropriate copyright notice and disclaimer of warranty; keep intact\r\nall the notices that refer to this License and to the absence of any\r\nwarranty; and distribute a copy of this License along with the\r\nLibrary.\r\n\r\n  You may charge a fee for the physical act of transferring a copy,\r\nand you may at your option offer warranty protection in exchange for a\r\nfee.\r\n\f\r\n  2. You may modify your copy or copies of the Library or any portion\r\nof it, thus forming a work based on the Library, and copy and\r\ndistribute such modifications or work under the terms of Section 1\r\nabove, provided that you also meet all of these conditions:\r\n\r\n    a) The modified work must itself be a software library.\r\n\r\n    b) You must cause the files modified to carry prominent notices\r\n    stating that you changed the files and the date of any change.\r\n\r\n    c) You must cause the whole of the work to be licensed at no\r\n    charge to all third parties under the terms of this License.\r\n\r\n    d) If a facility in the modified Library refers to a function or a\r\n    table of data to be supplied by an application program that uses\r\n    the facility, other than as an argument passed when the facility\r\n    is invoked, then you must make a good faith effort to ensure that,\r\n    in the event an application does not supply such function or\r\n    table, the facility still operates, and performs whatever part of\r\n    its purpose remains meaningful.\r\n\r\n    (For example, a function in a library to compute square roots has\r\n    a purpose that is entirely well-defined independent of the\r\n    application.  Therefore, Subsection 2d requires that any\r\n    application-supplied function or table used by this function must\r\n    be optional: if the application does not supply it, the square\r\n    root function must still compute square roots.)\r\n\r\nThese requirements apply to the modified work as a whole.  If\r\nidentifiable sections of that work are not derived from the Library,\r\nand can be reasonably considered independent and separate works in\r\nthemselves, then this License, and its terms, do not apply to those\r\nsections when you distribute them as separate works.  But when you\r\ndistribute the same sections as part of a whole which is a work based\r\non the Library, the distribution of the whole must be on the terms of\r\nthis License, whose permissions for other licensees extend to the\r\nentire whole, and thus to each and every part regardless of who wrote\r\nit.\r\n\r\nThus, it is not the intent of this section to claim rights or contest\r\nyour rights to work written entirely by you; rather, the intent is to\r\nexercise the right to control the distribution of derivative or\r\ncollective works based on the Library.\r\n\r\nIn addition, mere aggregation of another work not based on the Library\r\nwith the Library (or with a work based on the Library) on a volume of\r\na storage or distribution medium does not bring the other work under\r\nthe scope of this License.\r\n\r\n  3. You may opt to apply the terms of the ordinary GNU General Public\r\nLicense instead of this License to a given copy of the Library.  To do\r\nthis, you must alter all the notices that refer to this License, so\r\nthat they refer to the ordinary GNU General Public License, version 2,\r\ninstead of to this License.  (If a newer version than version 2 of the\r\nordinary GNU General Public License has appeared, then you can specify\r\nthat version instead if you wish.)  Do not make any other change in\r\nthese notices.\r\n\f\r\n  Once this change is made in a given copy, it is irreversible for\r\nthat copy, so the ordinary GNU General Public License applies to all\r\nsubsequent copies and derivative works made from that copy.\r\n\r\n  This option is useful when you wish to copy part of the code of\r\nthe Library into a program that is not a library.\r\n\r\n  4. You may copy and distribute the Library (or a portion or\r\nderivative of it, under Section 2) in object code or executable form\r\nunder the terms of Sections 1 and 2 above provided that you accompany\r\nit with the complete corresponding machine-readable source code, which\r\nmust be distributed under the terms of Sections 1 and 2 above on a\r\nmedium customarily used for software interchange.\r\n\r\n  If distribution of object code is made by offering access to copy\r\nfrom a designated place, then offering equivalent access to copy the\r\nsource code from the same place satisfies the requirement to\r\ndistribute the source code, even though third parties are not\r\ncompelled to copy the source along with the object code.\r\n\r\n  5. A program that contains no derivative of any portion of the\r\nLibrary, but is designed to work with the Library by being compiled or\r\nlinked with it, is called a \"work that uses the Library\".  Such a\r\nwork, in isolation, is not a derivative work of the Library, and\r\ntherefore falls outside the scope of this License.\r\n\r\n  However, linking a \"work that uses the Library\" with the Library\r\ncreates an executable that is a derivative of the Library (because it\r\ncontains portions of the Library), rather than a \"work that uses the\r\nlibrary\".  The executable is therefore covered by this License.\r\nSection 6 states terms for distribution of such executables.\r\n\r\n  When a \"work that uses the Library\" uses material from a header file\r\nthat is part of the Library, the object code for the work may be a\r\nderivative work of the Library even though the source code is not.\r\nWhether this is true is especially significant if the work can be\r\nlinked without the Library, or if the work is itself a library.  The\r\nthreshold for this to be true is not precisely defined by law.\r\n\r\n  If such an object file uses only numerical parameters, data\r\nstructure layouts and accessors, and small macros and small inline\r\nfunctions (ten lines or less in length), then the use of the object\r\nfile is unrestricted, regardless of whether it is legally a derivative\r\nwork.  (Executables containing this object code plus portions of the\r\nLibrary will still fall under Section 6.)\r\n\r\n  Otherwise, if the work is a derivative of the Library, you may\r\ndistribute the object code for the work under the terms of Section 6.\r\nAny executables containing that work also fall under Section 6,\r\nwhether or not they are linked directly with the Library itself.\r\n\f\r\n  6. As an exception to the Sections above, you may also combine or\r\nlink a \"work that uses the Library\" with the Library to produce a\r\nwork containing portions of the Library, and distribute that work\r\nunder terms of your choice, provided that the terms permit\r\nmodification of the work for the customer's own use and reverse\r\nengineering for debugging such modifications.\r\n\r\n  You must give prominent notice with each copy of the work that the\r\nLibrary is used in it and that the Library and its use are covered by\r\nthis License.  You must supply a copy of this License.  If the work\r\nduring execution displays copyright notices, you must include the\r\ncopyright notice for the Library among them, as well as a reference\r\ndirecting the user to the copy of this License.  Also, you must do one\r\nof these things:\r\n\r\n    a) Accompany the work with the complete corresponding\r\n    machine-readable source code for the Library including whatever\r\n    changes were used in the work (which must be distributed under\r\n    Sections 1 and 2 above); and, if the work is an executable linked\r\n    with the Library, with the complete machine-readable \"work that\r\n    uses the Library\", as object code and/or source code, so that the\r\n    user can modify the Library and then relink to produce a modified\r\n    executable containing the modified Library.  (It is understood\r\n    that the user who changes the contents of definitions files in the\r\n    Library will not necessarily be able to recompile the application\r\n    to use the modified definitions.)\r\n\r\n    b) Use a suitable shared library mechanism for linking with the\r\n    Library.  A suitable mechanism is one that (1) uses at run time a\r\n    copy of the library already present on the user's computer system,\r\n    rather than copying library functions into the executable, and (2)\r\n    will operate properly with a modified version of the library, if\r\n    the user installs one, as long as the modified version is\r\n    interface-compatible with the version that the work was made with.\r\n\r\n    c) Accompany the work with a written offer, valid for at\r\n    least three years, to give the same user the materials\r\n    specified in Subsection 6a, above, for a charge no more\r\n    than the cost of performing this distribution.\r\n\r\n    d) If distribution of the work is made by offering access to copy\r\n    from a designated place, offer equivalent access to copy the above\r\n    specified materials from the same place.\r\n\r\n    e) Verify that the user has already received a copy of these\r\n    materials or that you have already sent this user a copy.\r\n\r\n  For an executable, the required form of the \"work that uses the\r\nLibrary\" must include any data and utility programs needed for\r\nreproducing the executable from it.  However, as a special exception,\r\nthe materials to be distributed need not include anything that is\r\nnormally distributed (in either source or binary form) with the major\r\ncomponents (compiler, kernel, and so on) of the operating system on\r\nwhich the executable runs, unless that component itself accompanies\r\nthe executable.\r\n\r\n  It may happen that this requirement contradicts the license\r\nrestrictions of other proprietary libraries that do not normally\r\naccompany the operating system.  Such a contradiction means you cannot\r\nuse both them and the Library together in an executable that you\r\ndistribute.\r\n\f\r\n  7. You may place library facilities that are a work based on the\r\nLibrary side-by-side in a single library together with other library\r\nfacilities not covered by this License, and distribute such a combined\r\nlibrary, provided that the separate distribution of the work based on\r\nthe Library and of the other library facilities is otherwise\r\npermitted, and provided that you do these two things:\r\n\r\n    a) Accompany the combined library with a copy of the same work\r\n    based on the Library, uncombined with any other library\r\n    facilities.  This must be distributed under the terms of the\r\n    Sections above.\r\n\r\n    b) Give prominent notice with the combined library of the fact\r\n    that part of it is a work based on the Library, and explaining\r\n    where to find the accompanying uncombined form of the same work.\r\n\r\n  8. You may not copy, modify, sublicense, link with, or distribute\r\nthe Library except as expressly provided under this License.  Any\r\nattempt otherwise to copy, modify, sublicense, link with, or\r\ndistribute the Library is void, and will automatically terminate your\r\nrights under this License.  However, parties who have received copies,\r\nor rights, from you under this License will not have their licenses\r\nterminated so long as such parties remain in full compliance.\r\n\r\n  9. You are not required to accept this License, since you have not\r\nsigned it.  However, nothing else grants you permission to modify or\r\ndistribute the Library or its derivative works.  These actions are\r\nprohibited by law if you do not accept this License.  Therefore, by\r\nmodifying or distributing the Library (or any work based on the\r\nLibrary), you indicate your acceptance of this License to do so, and\r\nall its terms and conditions for copying, distributing or modifying\r\nthe Library or works based on it.\r\n\r\n  10. Each time you redistribute the Library (or any work based on the\r\nLibrary), the recipient automatically receives a license from the\r\noriginal licensor to copy, distribute, link with or modify the Library\r\nsubject to these terms and conditions.  You may not impose any further\r\nrestrictions on the recipients' exercise of the rights granted herein.\r\nYou are not responsible for enforcing compliance by third parties with\r\nthis License.\r\n\f\r\n  11. If, as a consequence of a court judgment or allegation of patent\r\ninfringement or for any other reason (not limited to patent issues),\r\nconditions are imposed on you (whether by court order, agreement or\r\notherwise) that contradict the conditions of this License, they do not\r\nexcuse you from the conditions of this License.  If you cannot\r\ndistribute so as to satisfy simultaneously your obligations under this\r\nLicense and any other pertinent obligations, then as a consequence you\r\nmay not distribute the Library at all.  For example, if a patent\r\nlicense would not permit royalty-free redistribution of the Library by\r\nall those who receive copies directly or indirectly through you, then\r\nthe only way you could satisfy both it and this License would be to\r\nrefrain entirely from distribution of the Library.\r\n\r\nIf any portion of this section is held invalid or unenforceable under any\r\nparticular circumstance, the balance of the section is intended to apply,\r\nand the section as a whole is intended to apply in other circumstances.\r\n\r\nIt is not the purpose of this section to induce you to infringe any\r\npatents or other property right claims or to contest validity of any\r\nsuch claims; this section has the sole purpose of protecting the\r\nintegrity of the free software distribution system which is\r\nimplemented by public license practices.  Many people have made\r\ngenerous contributions to the wide range of software distributed\r\nthrough that system in reliance on consistent application of that\r\nsystem; it is up to the author/donor to decide if he or she is willing\r\nto distribute software through any other system and a licensee cannot\r\nimpose that choice.\r\n\r\nThis section is intended to make thoroughly clear what is believed to\r\nbe a consequence of the rest of this License.\r\n\r\n  12. If the distribution and/or use of the Library is restricted in\r\ncertain countries either by patents or by copyrighted interfaces, the\r\noriginal copyright holder who places the Library under this License may add\r\nan explicit geographical distribution limitation excluding those countries,\r\nso that distribution is permitted only in or among countries not thus\r\nexcluded.  In such case, this License incorporates the limitation as if\r\nwritten in the body of this License.\r\n\r\n  13. The Free Software Foundation may publish revised and/or new\r\nversions of the Lesser General Public License from time to time.\r\nSuch new versions will be similar in spirit to the present version,\r\nbut may differ in detail to address new problems or concerns.\r\n\r\nEach version is given a distinguishing version number.  If the Library\r\nspecifies a version number of this License which applies to it and\r\n\"any later version\", you have the option of following the terms and\r\nconditions either of that version or of any later version published by\r\nthe Free Software Foundation.  If the Library does not specify a\r\nlicense version number, you may choose any version ever published by\r\nthe Free Software Foundation.\r\n\f\r\n  14. If you wish to incorporate parts of the Library into other free\r\nprograms whose distribution conditions are incompatible with these,\r\nwrite to the author to ask for permission.  For software which is\r\ncopyrighted by the Free Software Foundation, write to the Free\r\nSoftware Foundation; we sometimes make exceptions for this.  Our\r\ndecision will be guided by the two goals of preserving the free status\r\nof all derivatives of our free software and of promoting the sharing\r\nand reuse of software generally.\r\n\r\n          NO WARRANTY\r\n\r\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\r\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\r\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\r\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\r\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\r\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\r\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\r\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\r\n\r\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\r\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\r\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\r\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\r\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\r\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\r\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\r\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\r\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\r\nDAMAGES.\r\n\r\n         END OF TERMS AND CONDITIONS\r\n\f\r\n           How to Apply These Terms to Your New Libraries\r\n\r\n  If you develop a new library, and you want it to be of the greatest\r\npossible use to the public, we recommend making it free software that\r\neveryone can redistribute and change.  You can do so by permitting\r\nredistribution under these terms (or, alternatively, under the terms of the\r\nordinary General Public License).\r\n\r\n  To apply these terms, attach the following notices to the library.  It is\r\nsafest to attach them to the start of each source file to most effectively\r\nconvey the exclusion of warranty; and each file should have at least the\r\n\"copyright\" line and a pointer to where the full notice is found.\r\n\r\n    <one line to give the library's name and a brief idea of what it does.>\r\n    Copyright (C) <year>  <name of author>\r\n\r\n    This library is free software; you can redistribute it and/or\r\n    modify it under the terms of the GNU Lesser General Public\r\n    License as published by the Free Software Foundation; either\r\n    version 2.1 of the License, or (at your option) any later version.\r\n\r\n    This library is distributed in the hope that it will be useful,\r\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r\n    Lesser General Public License for more details.\r\n\r\n    You should have received a copy of the GNU Lesser General Public\r\n    License along with this library; if not, write to the Free Software\r\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nAlso add information on how to contact you by electronic and paper mail.\r\n\r\nYou should also get your employer (if you work as a programmer) or your\r\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\r\nnecessary.  Here is a sample; alter the names:\r\n\r\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\r\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\r\n\r\n  <signature of Ty Coon>, 1 April 1990\r\n  Ty Coon, President of Vice\r\n\r\nThat's all there is to it!\r\n\r\n\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/Methods.txt",
    "content": "Compression method IDs (4.27)\r\n-----------------------------\r\n\r\nEach compression method in 7z has unique binary value (ID).\r\nThe length of ID in bytes is arbitrary but it can not exceed 15 bytes.\r\n\r\nList of defined IDs\r\n-------------------\r\n      \r\n00 - Copy\r\n01 - Reserved\r\n02 - Common\r\n   03 Swap\r\n      - 2 Swap2\r\n      - 4 Swap4\r\n   04 Delta (subject to change)\r\n\r\n03 - 7z\r\n   01 - LZMA\r\n      01 - Version\r\n  \r\n   03 - Branch\r\n      01 - x86\r\n         03  - BCJ\r\n         1B  - BCJ2\r\n      02 - PPC\r\n         05 - BC_PPC_B (Big Endian)\r\n      03 - Alpha\r\n         01 - BC_Alpha\r\n      04 - IA64\r\n         01 - BC_IA64\r\n      05 - ARM\r\n         01 - BC_ARM\r\n      06 - M68\r\n         05 - BC_M68_B (Big Endian)\r\n      07 - ARM Thumb\r\n         01 - BC_ARMThumb\r\n      08 - SPARC\r\n         05 - BC_SPARC\r\n\r\n   04 - PPMD\r\n      01 - Version\r\n\r\n04 - Misc\r\n   00 - Reserved\r\n   01 - Zip\r\n      00 - Copy (not used). Use {00} instead\r\n      01 - Shrink\r\n      06 - Implode\r\n      08 - Deflate\r\n      09 - Deflate64\r\n      12 - BZip2 (not used). Use {04 02 02} instead\r\n   02 - BZip\r\n      02 - BZip2\r\n   03 - Rar\r\n      01 - Rar15\r\n      02 - Rar20\r\n      03 - Rar29\r\n   04 - Arj\r\n      01 - Arj (1,2,3)\r\n      02 - Arj 4\r\n   05 - Z\r\n   06 - Lzh\r\n   07 - Reserved for 7z\r\n   08 - Cab\r\n\r\n\r\n06 - Crypto \r\n   00 - \r\n   01 - AES\r\n      0x - AES-128\r\n      4x - AES-192\r\n      8x - AES-256\r\n\r\n      x0 - ECB\r\n      x1 - CBC\r\n      x2 - CFB\r\n      x3 - OFB\r\n\r\n   07 - Reserved\r\n   0F - Reserved\r\n\r\n   F0 - Misc Ciphers (Real Ciphers without hashing algo)\r\n\r\n   F1 - Misc Ciphers (Combine)\r\n      01 - Zip\r\n         01 - Main Zip crypto algo\r\n      03 - RAR\r\n         02 - \r\n         03 - Rar29 AES-128 + (modified SHA-1)\r\n      07 - 7z\r\n         01 - AES-256 + SHA-256\r\n\r\n07 - Hash (subject to change)\r\n   00 - \r\n   01 - CRC\r\n   02 - SHA-1\r\n   03 - SHA-256\r\n   04 - SHA-384\r\n   05 - SHA-512\r\n\r\n   F0 - Misc Hash\r\n\r\n   F1 - Misc\r\n      03 - RAR\r\n         03 - Rar29 Password Hashing (modified SHA1)\r\n      07 - 7z \r\n         01 - SHA-256 Password Hashing\r\n    \r\n   \r\n\r\n\r\n---\r\nEnd of document\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/history.txt",
    "content": "HISTORY of the LZMA SDK\r\n-----------------------\r\n\r\n  Version 4.32                2005-12-09\r\n  --------------------------------------\r\n    - Java version of LZMA SDK was included\r\n\r\n\r\n  Version 4.30                2005-11-20\r\n  --------------------------------------\r\n    - Compression ratio was improved in -a2 mode\r\n    - Speed optimizations for compressing in -a2 mode\r\n    - -fb switch now supports values up to 273\r\n    - Bug in 7z_C (7zIn.c) was fixed:\r\n      It used Alloc/Free functions from different memory pools.\r\n      So if program used two memory pools, it worked incorrectly.\r\n    - 7z_C: .7z format supporting was improved\r\n    - LZMA# SDK (C#.NET version) was included\r\n\r\n\r\n  Version 4.27 (Updated)      2005-09-21\r\n  --------------------------------------\r\n   - Some GUIDs/interfaces in C++ were changed.\r\n     IStream.h:\r\n       ISequentialInStream::Read now works as old ReadPart\r\n       ISequentialOutStream::Write now works as old WritePart\r\n\r\n  \r\n  Version 4.27                2005-08-07\r\n  --------------------------------------\r\n    - Bug in LzmaDecodeSize.c was fixed:\r\n       if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r\n       decompressing worked incorrectly.\r\n\r\n\r\n  Version 4.26                2005-08-05\r\n  --------------------------------------\r\n    - Fixes in 7z_C code and LzmaTest.c:\r\n      previous versions could work incorrectly,\r\n      if malloc(0) returns 0\r\n\r\n\r\n  Version 4.23                2005-06-29\r\n  --------------------------------------\r\n    - Small fixes in C++ code\r\n\r\n\r\n  Version 4.22                2005-06-10\r\n  --------------------------------------\r\n    - Small fixes\r\n\r\n\r\n  Version 4.21                2005-06-08\r\n  --------------------------------------\r\n    - Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r\n    - New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r\n        - LzmaStateDecode.h\r\n        - LzmaStateDecode.c\r\n        - LzmaStateTest.c\r\n    - ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r\n\r\n  \r\n  Version 4.17                2005-04-18\r\n  --------------------------------------\r\n    - New example for RAM->RAM compressing/decompressing: \r\n      LZMA + BCJ (filter for x86 code):\r\n        - LzmaRam.h\r\n        - LzmaRam.cpp\r\n        - LzmaRamDecode.h\r\n        - LzmaRamDecode.c\r\n        - -f86 switch for lzma.exe\r\n\r\n  \r\n  Version 4.16                2005-03-29\r\n  --------------------------------------\r\n    - Bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r\n       If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r\n       decoder could access memory outside of allocated range.\r\n    - Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r\n      Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r\n      LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r\n    - Small speed optimization in LZMA C++ code\r\n    - filter for SPARC's code was added\r\n    - Simplified version of .7z ANSI-C Decoder was included\r\n\r\n\r\n  Version 4.06                2004-09-05\r\n  --------------------------------------\r\n    - Bug in v4.05 was fixed:\r\n        LZMA-Encoder didn't release output stream in some cases.\r\n\r\n\r\n  Version 4.05                2004-08-25\r\n  --------------------------------------\r\n    - Source code of filters for x86, IA-64, ARM, ARM-Thumb \r\n      and PowerPC code was included to SDK\r\n    - Some internal minor changes\r\n\r\n\r\n  Version 4.04                2004-07-28\r\n  --------------------------------------\r\n    - More compatibility with some C++ compilers\r\n\r\n\r\n  Version 4.03                2004-06-18\r\n  --------------------------------------\r\n    - \"Benchmark\" command was added. It measures compressing \r\n      and decompressing speed and shows rating values. \r\n      Also it checks hardware errors.\r\n\r\n\r\n  Version 4.02                2004-06-10\r\n  --------------------------------------\r\n    - C++ LZMA Encoder/Decoder code now is more portable\r\n      and it can be compiled by GCC on Linux.\r\n\r\n\r\n  Version 4.01                2004-02-15\r\n  --------------------------------------\r\n    - Some detection of data corruption was enabled.\r\n        LzmaDecode.c / RangeDecoderReadByte\r\n        .....\r\n        {\r\n          rd->ExtraBytes = 1;\r\n          return 0xFF;\r\n        }\r\n\r\n\r\n  Version 4.00                2004-02-13\r\n  --------------------------------------\r\n    - Original version of LZMA SDK\r\n\r\n\r\n\r\nHISTORY of the LZMA\r\n-------------------\r\n  2001-2004:  Improvements to LZMA compressing/decompressing code, \r\n              keeping compatibility with original LZMA format\r\n  1996-2001:  Development of LZMA compression format\r\n\r\n  Some milestones:\r\n\r\n  2001-08-30: LZMA compression was added to 7-Zip\r\n  1999-01-02: First version of 7-Zip was released\r\n  \r\n\r\nEnd of document\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/lzma/lzma.txt",
    "content": "LZMA SDK 4.32\r\n-------------\r\n\r\nLZMA SDK 4.32  Copyright (C) 1999-2005 Igor Pavlov\r\n\r\nLZMA SDK provides the documentation, samples, header files, libraries, \r\nand tools you need to develop applications that use LZMA compression.\r\n\r\nLZMA is default and general compression method of 7z format\r\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \r\ncompression ratio and very fast decompression.\r\n\r\nLZMA is an improved version of famous LZ77 compression algorithm. \r\nIt was improved in way of maximum increasing of compression ratio,\r\nkeeping high decompression speed and low memory requirements for \r\ndecompressing.\r\n\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\nLZMA SDK is available under any of the following licenses:\r\n\r\n1) GNU Lesser General Public License (GNU LGPL)\r\n2) Common Public License (CPL)\r\n3) Simplified license for unmodified code (read SPECIAL EXCEPTION) \r\n4) Proprietary license \r\n\r\nIt means that you can select one of these four options and follow rules of that license.\r\n\r\n\r\n1,2) GNU LGPL and CPL licenses are pretty similar and both these\r\nlicenses are classified as \r\n - \"Free software licenses\" at http://www.gnu.org/ \r\n - \"OSI-approved\" at http://www.opensource.org/\r\n\r\n\r\n3) SPECIAL EXCEPTION\r\n\r\nIgor Pavlov, as the author of this code, expressly permits you \r\nto statically or dynamically link your code (or bind by name) \r\nto the files from LZMA SDK without subjecting your linked \r\ncode to the terms of the CPL or GNU LGPL. \r\nAny modifications or additions to files from LZMA SDK, however, \r\nare subject to the GNU LGPL or CPL terms.\r\n\r\nSPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code, \r\nwhile you keep LZMA SDK code unmodified.\r\n\r\n\r\nSPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use this code under the same terms and conditions contained in the License \r\nAgreement you have for any previous version of LZMA SDK developed by Igor Pavlov.\r\n\r\nSPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version \r\nof LZMA SDK as update for previous versions.\r\n\r\n\r\nSPECIAL EXCEPTION #3: Igor Pavlov, as the author of this code, expressly permits \r\nyou to use code of examples (LzmaTest.c, LzmaStateTest.c, LzmaAlone.cpp, \r\nLzmaAlone.cs, LzmaAlone.java) as public domain code. \r\n\r\n\r\n4) Proprietary license\r\n\r\nLZMA SDK also can be available under a proprietary license which \r\ncan include:\r\n\r\n1) Right to modify code without subjecting modified code to the \r\nterms of the CPL or GNU LGPL\r\n2) Technical support for code\r\n\r\nTo request such proprietary license or any additional consultations,\r\nsend email message from that page:\r\nhttp://www.7-zip.org/support.html\r\n\r\n\r\nYou should have received a copy of the GNU Lesser General Public\r\nLicense along with this library; if not, write to the Free Software\r\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r\n\r\nYou should have received a copy of the Common Public License\r\nalong with this library.\r\n\r\n\r\nLZMA SDK Contents\r\n-----------------\r\n\r\nLZMA SDK includes:\r\n\r\n  - C++ source code of LZMA compressing and decompressing\r\n  - ANSI-C compatible source code for LZMA decompressing\r\n  - C# source code for LZMA compressing and decompressing\r\n  - Java source code for LZMA compressing and decompressing\r\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\r\n\r\nANSI-C LZMA decompression code was ported from original C++ sources to C.\r\nAlso it was simplified and optimized for code size. \r\nBut it is fully compatible with LZMA from 7-Zip.\r\n\r\n\r\nUNIX/Linux version \r\n------------------\r\nTo compile C++ version of file->file LZMA, go to directory\r\nC/7zip/Compress/LZMA_Alone \r\nand type \"make\" or \"make clean all\" to recompile all.\r\n\r\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\r\nTo compile with static libraries, change string in makefile\r\nLIB = -lm\r\nto string  \r\nLIB = -lm -static\r\n\r\n\r\nFiles\r\n---------------------\r\nC        - C / CPP source code\r\nCS       - C# source code\r\nJava     - Java source code\r\nlzma.txt - LZMA SDK description (this file)\r\n7zFormat.txt - 7z Format description\r\n7zC.txt  - 7z ANSI-C Decoder description (this file)\r\nmethods.txt  - Compression method IDs for .7z\r\nLGPL.txt - GNU Lesser General Public License\r\nCPL.html - Common Public License\r\nlzma.exe - Compiled file->file LZMA encoder/decoder for Windows\r\nhistory.txt - history of the LZMA SDK\r\n\r\n\r\nSource code structure\r\n---------------------\r\n\r\nC  - C / CPP files\r\n  Common  - common files for C++ projects\r\n  Windows - common files for Windows related code\r\n  7zip    - files related to 7-Zip Project\r\n    Common   - common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n        BinTree    - Binary Tree Match Finder for LZ algorithm\r\n        HashChain  - Hash Chain Match Finder for LZ algorithm\r\n        Patricia   - Patricia Match Finder for LZ algorithm\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n      LZMA         - LZMA compression/decompression on C++\r\n      LZMA_Alone   - file->file LZMA compression/decompression\r\n      LZMA_C       - ANSI-C compatible LZMA decompressor\r\n        LzmaDecode.h  - interface for LZMA decoding on ANSI-C\r\n        LzmaDecode.c      - LZMA decoding on ANSI-C (new fastest version)\r\n        LzmaDecodeSize.c  - LZMA decoding on ANSI-C (old size-optimized version)\r\n        LzmaTest.c        - test application that decodes LZMA encoded file\r\n        LzmaStateDecode.h - interface for LZMA decoding (State version)\r\n        LzmaStateDecode.c - LZMA decoding on ANSI-C (State version)\r\n        LzmaStateTest.c   - test application (State version)\r\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r\n    Archive - files related to archiving\r\n      7z_C     - 7z ANSI-C Decoder\r\n\r\nCS - C# files\r\n  7zip\r\n    Common   - some common files for 7-Zip\r\n    Compress - files related to compression/decompression\r\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      LzmaAlone    - file->file LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nJava  - Java files\r\n  SevenZip\r\n    Compression    - files related to compression/decompression\r\n      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r\n      LZMA         - LZMA compression/decompression\r\n      RangeCoder   - Range Coder (special code of compression/decompression)\r\n\r\nC/C++ source code of LZMA SDK is part of 7-Zip project.\r\n\r\nYou can find ANSI-C LZMA decompressing code at folder \r\n  C/7zip/Compress/LZMA_C\r\n7-Zip doesn't use that ANSI-C LZMA code and that code was developed \r\nspecially for this SDK. And files from LZMA_C do not need files from \r\nother directories of SDK for compiling.\r\n\r\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r\n\r\n  http://sourceforge.net/projects/sevenzip/\r\n\r\n\r\nLZMA Decompression features\r\n---------------------------\r\n  - Variable dictionary size (up to 256 MB)\r\n  - Estimated compressing speed: about 500 KB/s on 1 GHz CPU\r\n  - Estimated decompressing speed: \r\n      - 8-12 MB/s on 1 GHz Intel Pentium 3 or AMD Athlon\r\n      - 500-1000 KB/s on 100 MHz ARM, MIPS, PowerPC or other simple RISC\r\n  - Small memory requirements for decompressing (8-32 KB + DictionarySize)\r\n  - Small code size for decompressing: 2-8 KB (depending from \r\n    speed optimizations) \r\n\r\nLZMA decoder uses only integer operations and can be \r\nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r\n\r\nSome critical operations that affect to speed of LZMA decompression:\r\n  1) 32*16 bit integer multiply\r\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\r\n  3) 32-bit shift and arithmetic operations\r\n\r\nSpeed of LZMA decompressing mostly depends from CPU speed.\r\nMemory speed has no big meaning. But if your CPU has small data cache, \r\noverall weight of memory speed will slightly increase.\r\n\r\n\r\nHow To Use\r\n----------\r\n\r\nUsing LZMA encoder/decoder executable\r\n--------------------------------------\r\n\r\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\r\n\r\n  e: encode file\r\n\r\n  d: decode file\r\n\r\n  b: Benchmark. There are two tests: compressing and decompressing \r\n     with LZMA method. Benchmark shows rating in MIPS (million \r\n     instructions per second). Rating value is calculated from \r\n     measured speed and it is normalized with AMD Athlon XP CPU\r\n     results. Also Benchmark checks possible hardware errors (RAM \r\n     errors in most cases). Benchmark uses these settings:\r\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d. Also you \r\n     can change number of iterations. Example for 30 iterations:\r\n\tLZMA b 30\r\n     Default number of iterations is 10.\r\n\r\n<Switches>\r\n  \r\n\r\n  -a{N}:  set compression mode 0 = fast, 1 = normal, 2 = max\r\n          default: 2 (max)\r\n\r\n  d{N}:   Sets Dictionary size - [0, 28], default: 23 (8MB)\r\n          The maximum value for dictionary size is 256 MB = 2^28 bytes.\r\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \r\n          For decompressing file compressed by LZMA method with dictionary \r\n          size D = 2^N you need about D bytes of memory (RAM).\r\n\r\n  -fb{N}: set number of fast bytes - [5, 273], default: 128\r\n          Usually big number gives a little bit better compression ratio \r\n          and slower compression process.\r\n\r\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\r\n          Sometimes lc=4 gives gain for big files.\r\n\r\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r\n          lp switch is intended for periodical data when period is \r\n          equal 2^N. For example, for 32-bit (4 bytes) \r\n          periodical data you can use lp=2. Often it's better to set lc0, \r\n          if you change lp switch.\r\n\r\n  -pb{N}: set number of pos bits - [0, 4], default: 2\r\n          pb switch is intended for periodical data \r\n          when period is equal 2^N.\r\n\r\n  -mf{MF_ID}: set Match Finder. Default: bt4. \r\n              Compression ratio for all bt* and pat* almost the same.\r\n              Algorithms from hc* group doesn't provide good compression \r\n              ratio, but they often works pretty fast in combination with \r\n              fast mode (-a0). Methods from bt* group require less memory \r\n              than methods from pat* group. Usually bt4 works faster than \r\n              any pat*, but for some types of files pat* can work faster. \r\n\r\n              Memory requirements depend from dictionary size \r\n              (parameter \"d\" in table below). \r\n\r\n               MF_ID     Memory                   Description\r\n\r\n                bt2    d*9.5 +  1MB  Binary Tree with 2 bytes hashing.\r\n                bt3    d*9.5 + 65MB  Binary Tree with 2-3(full) bytes hashing.\r\n                bt4    d*9.5 +  6MB  Binary Tree with 2-3-4 bytes hashing.\r\n                bt4b   d*9.5 + 34MB  Binary Tree with 2-3-4(big) bytes hashing.\r\n                pat2r  d*26  +  1MB  Patricia Tree with 2-bits nodes, removing.\r\n                pat2   d*38  +  1MB  Patricia Tree with 2-bits nodes.\r\n                pat2h  d*38  + 77MB  Patricia Tree with 2-bits nodes, 2-3 bytes hashing.\r\n                pat3h  d*62  + 85MB  Patricia Tree with 3-bits nodes, 2-3 bytes hashing.\r\n                pat4h  d*110 +101MB  Patricia Tree with 4-bits nodes, 2-3 bytes hashing.\r\n                hc3    d*5.5 +  1MB  Hash Chain with 2-3 bytes hashing.\r\n                hc4    d*5.5 +  6MB  Hash Chain with 2-3-4 bytes hashing.\r\n\r\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \r\n          eos marker, since LZMA decoder knows uncompressed size \r\n          stored in .lzma file header.\r\n\r\n  -si:    Read data from stdin (it will write End Of Stream marker).\r\n  -so:    Write data to stdout\r\n\r\n\r\nExamples:\r\n\r\n1) LZMA e file.bin file.lzma -d16 -lc0 \r\n\r\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r\nand 0 literal context bits. -lc0 allows to reduce memory requirements \r\nfor decompression.\r\n\r\n\r\n2) LZMA e file.bin file.lzma -lc0 -lp2\r\n\r\ncompresses file.bin to file.lzma with settings suitable \r\nfor 32-bit periodical data (for example, ARM or MIPS code).\r\n\r\n3) LZMA d file.lzma file.bin\r\n\r\ndecompresses file.lzma to file.bin.\r\n\r\n\r\nCompression ratio hints\r\n-----------------------\r\n\r\nRecommendations\r\n---------------\r\n\r\nTo increase compression ratio for LZMA compressing it's desirable \r\nto have aligned data (if it's possible) and also it's desirable to locate\r\ndata in such order, where code is grouped in one place and data is \r\ngrouped in other place (it's better than such mixing: code, data, code,\r\ndata, ...).\r\n\r\n\r\nUsing Filters\r\n-------------\r\nYou can increase compression ratio for some data types, using\r\nspecial filters before compressing. For example, it's possible to \r\nincrease compression ratio on 5-10% for code for those CPU ISAs: \r\nx86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r\n\r\nYou can find C/C++ source code of such filters in folder \"7zip/Compress/Branch\"\r\n\r\nYou can check compression ratio gain of these filters with such \r\n7-Zip commands (example for ARM code):\r\nNo filter:\r\n  7z a a1.7z a.bin -m0=lzma\r\n\r\nWith filter for little-endian ARM code:\r\n  7z a a2.7z a.bin -m0=bc_arm -m1=lzma        \r\n\r\nWith filter for big-endian ARM code (using additional Swap4 filter):\r\n  7z a a3.7z a.bin -m0=swap4 -m1=bc_arm -m2=lzma\r\n\r\nIt works in such manner:\r\nCompressing    = Filter_encoding + LZMA_encoding\r\nDecompressing  = LZMA_decoding + Filter_decoding\r\n\r\nCompressing and decompressing speed of such filters is very high,\r\nso it will not increase decompressing time too much.\r\nMoreover, it reduces decompression time for LZMA_decoding, \r\nsince compression ratio with filtering is higher.\r\n\r\nThese filters convert CALL (calling procedure) instructions \r\nfrom relative offsets to absolute addresses, so such data becomes more \r\ncompressible. Source code of these CALL filters is pretty simple\r\n(about 20 lines of C++), so you can convert it from C++ version yourself.\r\n\r\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r\n\r\n\r\nLZMA compressed file format\r\n---------------------------\r\nOffset Size Description\r\n  0     1   Special LZMA properties for compressed data\r\n  1     4   Dictionary size (little endian)\r\n  5     8   Uncompressed size (little endian). -1 means unknown size\r\n 13         Compressed data\r\n\r\n\r\nANSI-C LZMA Decoder\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\nTo compile ANSI-C LZMA Decoder you can use one of the following files sets:\r\n1) LzmaDecode.h + LzmaDecode.c + LzmaTest.c  (fastest version)\r\n2) LzmaDecode.h + LzmaDecodeSize.c + LzmaTest.c  (old size-optimized version)\r\n3) LzmaStateDecode.h + LzmaStateDecode.c + LzmaStateTest.c  (zlib-like interface)\r\n\r\n\r\nMemory requirements for LZMA decoding\r\n-------------------------------------\r\n\r\nLZMA decoder doesn't allocate memory itself, so you must \r\nallocate memory and send it to LZMA.\r\n\r\nStack usage of LZMA decoding function for local variables is not \r\nlarger than 200 bytes.\r\n\r\nHow To decompress data\r\n----------------------\r\n\r\nLZMA Decoder (ANSI-C version) now supports 5 interfaces:\r\n1) Single-call Decompressing\r\n2) Single-call Decompressing with input stream callback\r\n3) Multi-call Decompressing with output buffer\r\n4) Multi-call Decompressing with input callback and output buffer\r\n5) Multi-call State Decompressing (zlib-like interface)\r\n\r\nVariant-5 is similar to Variant-4, but Variant-5 doesn't use callback functions.\r\n\r\nDecompressing steps\r\n-------------------\r\n\r\n1) read LZMA properties (5 bytes):\r\n   unsigned char properties[LZMA_PROPERTIES_SIZE];\r\n\r\n2) read uncompressed size (8 bytes, little-endian)\r\n\r\n3) Decode properties:\r\n\r\n  CLzmaDecoderState state;  /* it's 24-140 bytes structure, if int is 32-bit */\r\n\r\n  if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)\r\n    return PrintError(rs, \"Incorrect stream properties\");\r\n\r\n4) Allocate memory block for internal Structures:\r\n\r\n  state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));\r\n  if (state.Probs == 0)\r\n    return PrintError(rs, kCantAllocateMessage);\r\n\r\n  LZMA decoder uses array of CProb variables as internal structure.\r\n  By default, CProb is unsigned_short. But you can define _LZMA_PROB32 to make \r\n  it unsigned_int. It can increase speed on some 32-bit CPUs, but memory \r\n  usage will be doubled in that case.\r\n\r\n\r\n5) Main Decompressing\r\n\r\nYou must use one of the following interfaces:\r\n\r\n5.1 Single-call Decompressing\r\n-----------------------------\r\nWhen to use: RAM->RAM decompressing\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: no defines\r\nMemory Requirements:\r\n  - Input buffer: compressed size\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  int res = LzmaDecode(&state, \r\n      inStream, compressedSize, &inProcessed,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.2 Single-call Decompressing with input stream callback\r\n--------------------------------------------------------\r\nWhen to use: File->RAM or Flash->RAM decompressing.\r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB\r\nMemory Requirements:\r\n  - Buffer for input stream: any size (for example, 16 KB)\r\n  - Output buffer: uncompressed size\r\n  - LZMA Internal Structures (~16 KB for default settings) \r\n\r\nInterface:\r\n  typedef struct _CBuffer\r\n  {\r\n    ILzmaInCallback InCallback;\r\n    FILE *File;\r\n    unsigned char Buffer[kInBufferSize];\r\n  } CBuffer;\r\n\r\n  int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)\r\n  {\r\n    CBuffer *bo = (CBuffer *)object;\r\n    *buffer = bo->Buffer;\r\n    *size = MyReadFile(bo->File, bo->Buffer, kInBufferSize);\r\n    return LZMA_RESULT_OK;\r\n  }\r\n\r\n  CBuffer g_InBuffer;\r\n\r\n  g_InBuffer.File = inFile;\r\n  g_InBuffer.InCallback.Read = LzmaReadCompressed;\r\n  int res = LzmaDecode(&state, \r\n      &g_InBuffer.InCallback,\r\n      outStream, outSize, &outProcessed);\r\n\r\n\r\n5.3 Multi-call decompressing with output buffer\r\n-----------------------------------------------\r\nWhen to use: RAM->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Input buffer: compressed size\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details.\r\n\r\n\r\n5.4 Multi-call decompressing with input callback and output buffer\r\n------------------------------------------------------------------\r\nWhen to use: File->File decompressing \r\nCompile files: LzmaDecode.h, LzmaDecode.c\r\nCompile defines: _LZMA_IN_CB, _LZMA_OUT_READ\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    LzmaDecode(&state,\r\n      &bo.InCallback,\r\n      g_OutBuffer, outAvail, &outProcessed);\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaTest.c for more details:\r\n\r\n\r\n5.5 Multi-call State Decompressing (zlib-like interface)\r\n------------------------------------------------------------------\r\nWhen to use: file->file decompressing \r\nCompile files: LzmaStateDecode.h, LzmaStateDecode.c\r\nCompile defines:\r\nMemory Requirements:\r\n - Buffer for input stream: any size (for example, 16 KB)\r\n - Buffer for output stream: any size (for example, 16 KB)\r\n - LZMA Internal Structures (~16 KB for default settings) \r\n - LZMA dictionary (dictionary size is encoded in stream properties)\r\n \r\nInterface:\r\n\r\n  state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);\r\n\r\n  \r\n  LzmaDecoderInit(&state);\r\n  do\r\n  {\r\n    res = LzmaDecode(&state,\r\n      inBuffer, inAvail, &inProcessed,\r\n      g_OutBuffer, outAvail, &outProcessed,\r\n      finishDecoding);\r\n    inAvail -= inProcessed;\r\n    inBuffer += inProcessed;\r\n  }\r\n  while you need more bytes\r\n\r\n  see LzmaStateTest.c for more details:\r\n\r\n\r\n6) Free all allocated blocks\r\n\r\n\r\nNote\r\n----\r\nLzmaDecodeSize.c is size-optimized version of LzmaDecode.c.\r\nBut compiled code of LzmaDecodeSize.c can be larger than \r\ncompiled code of LzmaDecode.c. So it's better to use \r\nLzmaDecode.c in most cases.\r\n\r\n\r\nEXIT codes\r\n-----------\r\n\r\nLZMA decoder can return one of the following codes:\r\n\r\n#define LZMA_RESULT_OK 0\r\n#define LZMA_RESULT_DATA_ERROR 1\r\n\r\nIf you use callback function for input data and you return some \r\nerror code, LZMA Decoder also returns that code.\r\n\r\n\r\n\r\nLZMA Defines\r\n------------\r\n\r\n_LZMA_IN_CB    - Use callback for input data\r\n\r\n_LZMA_OUT_READ - Use read function for output data\r\n\r\n_LZMA_LOC_OPT  - Enable local speed optimizations inside code.\r\n                 _LZMA_LOC_OPT is only for LzmaDecodeSize.c (size-optimized version).\r\n                 _LZMA_LOC_OPT doesn't affect LzmaDecode.c (speed-optimized version)\r\n                 and LzmaStateDecode.c\r\n\r\n_LZMA_PROB32   - It can increase speed on some 32-bit CPUs, \r\n                 but memory usage will be doubled in that case\r\n\r\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler\r\n                         and long is 32-bit.\r\n\r\n_LZMA_SYSTEM_SIZE_T  - Define it if you want to use system's size_t.\r\n                       You can use it to enable 64-bit sizes supporting\r\n\r\n\r\n\r\nC++ LZMA Encoder/Decoder \r\n~~~~~~~~~~~~~~~~~~~~~~~~\r\nC++ LZMA code use COM-like interfaces. So if you want to use it, \r\nyou can study basics of COM/OLE.\r\n\r\nBy default, LZMA Encoder contains all Match Finders.\r\nBut for compressing it's enough to have just one of them.\r\nSo for reducing size of compressing code you can define:\r\n  #define COMPRESS_MF_BT\r\n  #define COMPRESS_MF_BT4\r\nand it will use only bt4 match finder.\r\n\r\n\r\n---\r\n\r\nhttp://www.7-zip.org\r\nhttp://www.7-zip.org/support.html\r\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/mksquashfs.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * 07/10/06 - jc - Added LZMA encoding parameter specification (_LZMA_PARAMS)\n *\t\t\t\t   contact: jeremy@bitsum.com\n *\n * mksquashfs.c\n */\n\n#define FALSE 0\n#define TRUE 1\n\n/* jc: Define to enable LZMA encoding parameters on command line */\n#define _LZMA_PARAMS \n\n#include <pwd.h>\n#include <grp.h>\n#include <time.h>\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <zlib.h>\n#include <stdlib.h>\n#include <signal.h>\n#include <setjmp.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"mksquashfs.h\"\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\tdo { \\\n\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\tdo {\\\n\t\t\t\t\t if(!silent)\\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args);\\\n\t\t\t\t} while(0)\n#define ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, s, ## args);\\\n\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\tdo {\\\n\t\t\t\t\tif(restore)\\\n\t\t\t\t\t\trestorefs();\\\n\t\t\t\t\tif(delete && destination_file && !block_device)\\\n\t\t\t\t\t\tunlink(destination_file);\\\n\t\t\t\t\texit(1);\\\n\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\tdo {\\\n\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t} while(0)\n\t\t\t\n\n#ifdef _LZMA_PARAMS\n#include \"./lzma/C/7zip/Compress/LZMA_Lib/lzmaext.h\"\t\t\t\t\t\n/* jc: be lame and use some globals.. this app is single threaded*/\t\t\t\t\t\n\nint g_fb=-1;\nint g_lc=1;\nint g_lp=2;\nint g_pb=2;\t\t\t\t\n#endif\n\t\t\t\t\nint delete = FALSE;\nlong long total_compressed = 0, total_uncompressed = 0;\nint fd;\n\n/* filesystem flags for building */\nint duplicate_checking = 1, noF = 0, no_fragments = 0, always_use_fragments = 0;\nint noI = 0, noD = 0, check_data = 0;\nint swap, silent = TRUE;\nlong long global_uid = -1, global_gid = -1;\n\n/* superblock attributes */\nint block_size = SQUASHFS_FILE_SIZE, block_log;\nunsigned short uid_count = 0, guid_count = 0;\nsquashfs_uid uids[SQUASHFS_UIDS], guids[SQUASHFS_GUIDS];\nint block_offset;\nint file_count = 0, sym_count = 0, dev_count = 0, dir_count = 0, fifo_count = 0, sock_count = 0;\n\n/* write position within data section */\nlong long bytes = 0, total_bytes = 0;\n\n/* in memory directory table - possibly compressed */\nchar *directory_table = NULL;\nunsigned int directory_bytes = 0, directory_size = 0, total_directory_bytes = 0;\n\n/* cached directory table */\nchar *directory_data_cache = NULL;\nunsigned int directory_cache_bytes = 0, directory_cache_size = 0;\n\n/* in memory inode table - possibly compressed */\nchar *inode_table = NULL;\nunsigned int inode_bytes = 0, inode_size = 0, total_inode_bytes = 0;\n\n/* cached inode table */\nchar *data_cache = NULL;\nunsigned int cache_bytes = 0, cache_size = 0, inode_count = 0;\n\n/* in memory directory data */\n#define I_COUNT_SIZE\t\t128\n#define DIR_ENTRIES\t\t32\n#define INODE_HASH_SIZE\t\t65536\n#define INODE_HASH_MASK\t\t(INODE_HASH_SIZE - 1)\n#define INODE_HASH(dev, ino)\t(ino & INODE_HASH_MASK)\n\nstruct cached_dir_index {\n\tsquashfs_dir_index\tindex;\n\tchar\t\t\t*name;\n};\n\nstruct directory {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned char\t\t*buff;\n\tunsigned char\t\t*p;\n\tunsigned int\t\tentry_count;\n\tunsigned char\t\t*entry_count_p;\n\tunsigned int\t\ti_count;\n\tunsigned int\t\ti_size;\n\tstruct cached_dir_index\t*index;\n\tunsigned char\t\t*index_count_p;\n\tunsigned int\t\tinode_number;\n};\n\nstruct inode_info *inode_info[INODE_HASH_SIZE];\n\n/* hash tables used to do fast duplicate searches in duplicate check */\nstruct file_info *dupl[65536], *frag_dups[65536];\nint dup_files = 0;\n\n/* list of exclude dirs/files */\nstruct exclude_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n};\n\n#define EXCLUDE_SIZE 8192\nint exclude = 0;\nstruct exclude_info *exclude_paths = NULL;\nint excluded(char *filename, struct stat *buf);\n\n/* fragment block data structures */\nint fragments = 0;\nchar fragment_data[SQUASHFS_FILE_MAX_SIZE];\nint fragment_size = 0;\nstruct fragment {\n\tunsigned int\t\tindex;\n\tint\t\t\toffset;\n\tint\t\t\tsize;\n};\n#define FRAG_SIZE 32768\nsquashfs_fragment_entry *fragment_table = NULL;\n\n\n/* current inode number for directories and non directories */\nunsigned int dir_inode_no = 1;\nunsigned int inode_no = 0;\nunsigned int root_inode_number = 0;\n\n/* list of source dirs/files */\nint source = 0;\nchar **source_path;\n\n/* list of root directory entries read from original filesystem */\nint old_root_entries = 0;\nstruct old_root_entry_info {\n\tchar\t\t\tname[SQUASHFS_NAME_LEN + 1];\n\tsquashfs_inode\t\tinode;\n\tint\t\t\ttype;\n\tint\t\t\tinode_number;\n};\nstruct old_root_entry_info *old_root_entry;\n\n/* in memory file info */\nstruct file_info {\n\tlong long\t\tbytes;\n\tunsigned short\t\tchecksum;\n\tlong long\t\tstart;\n\tunsigned int\t\t*block_list;\n\tstruct file_info\t*next;\n\tstruct fragment\t\t*fragment;\n\tunsigned short\t\tfragment_checksum;\n};\n\n/* count of how many times SIGINT or SIGQUIT has been sent */\nint interrupted = 0;\n\n/* restore orignal filesystem state if appending to existing filesystem is cancelled */\njmp_buf env;\nchar *sdata_cache, *sdirectory_data_cache;\n\nlong long sbytes, stotal_bytes;\n\nunsigned int sinode_bytes, scache_bytes, sdirectory_bytes,\n\tsdirectory_cache_bytes, suid_count, sguid_count,\n\tstotal_inode_bytes, stotal_directory_bytes,\n\tsinode_count, sfile_count, ssym_count, sdev_count,\n\tsdir_count, sfifo_count, ssock_count, sdup_files;\nint sfragments;\nint restore = 0;\n\n/* flag whether destination file is a block device */\nint block_device = 0;\n\n/* flag indicating whether files are sorted using sort list(s) */\nint sorted = 0;\n\n/* save destination file name for deleting on error */\nchar *destination_file = NULL;\n\n/* structure to used to pass in a pointer or an integer\n * to duplicate buffer read helper functions.\n */\nstruct duplicate_buffer_handle {\n\tchar\t*ptr;\n\tlong long\tstart;\n};\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type);\nextern int read_super(int fd, squashfs_super_block *sBlk, int *be, char *source);\nextern long long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int),\n\t\tsquashfs_fragment_entry **fragment_table);\nint get_sorted_inode(squashfs_inode *inode, struct stat *buf);\nint read_sort_file(char *filename, int source, char *source_path[]);\nvoid sort_files_and_write(struct dir_info *dir);\nstruct file_info *duplicate(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, long long bytes, unsigned int **block_list, long long *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes);\nstruct dir_info *dir_scan1(char *, int (_readdir)(char *, char *, struct dir_info *));\n\n#define MKINODE(A)\t((squashfs_inode)(((squashfs_inode) inode_bytes << 16) + (((char *)A) - data_cache)))\n\n\nvoid restorefs()\n{\n\tERROR(\"Exiting - restoring original filesystem!\\n\\n\");\n\tbytes = sbytes;\n\tmemcpy(data_cache, sdata_cache, cache_bytes = scache_bytes);\n\tmemcpy(directory_data_cache, sdirectory_data_cache, directory_cache_bytes = sdirectory_cache_bytes);\n\tinode_bytes = sinode_bytes;\n\tdirectory_bytes = sdirectory_bytes;\n\tuid_count = suid_count;\n\tguid_count = sguid_count;\n\ttotal_bytes = stotal_bytes;\n\ttotal_inode_bytes = stotal_inode_bytes;\n\ttotal_directory_bytes = stotal_directory_bytes;\n\tinode_count = sinode_count;\n\tfile_count = sfile_count;\n\tsym_count = ssym_count;\n\tdev_count = sdev_count;\n\tdir_count = sdir_count;\n\tfifo_count = sfifo_count;\n\tsock_count = ssock_count;\n\tdup_files = sdup_files;\n\tfragments = sfragments;\n\tfragment_size = 0;\n\tlongjmp(env, 1);\n}\n\n\nvoid sighandler()\n{\n\tif(interrupted == 1)\n\t\trestorefs();\n\telse {\n\t\tERROR(\"Interrupting will restore original filesystem!\\n\");\n\t\tERROR(\"Interrupt again to quit\\n\");\n\t\tinterrupted ++;\n\t}\n}\n\n\nvoid sighandler2()\n{\n\tEXIT_MKSQUASHFS();\n}\n\n\nunsigned int mangle(char *d, char *s, int size, int block_size, int uncompressed, int data_block)\n{\n\tunsigned long c_byte = block_size << 1;\n\tunsigned int res;\n\n#ifdef _LZMA_PARAMS\n\tif(!uncompressed && (res = compress2_lzma((unsigned char *) d, &c_byte, (unsigned char *) s, size, 9, g_fb, g_lc, g_lp, g_pb)) != Z_OK) {\n#else\t\n\tif(!uncompressed && (res = compress2((unsigned char *) d, &c_byte, (unsigned char *) s, size, 9)) != Z_OK) {\n#endif\t\t\n\t\tif(res == Z_MEM_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, not enough memory\\n\");\n\t\telse if(res == Z_BUF_ERROR)\n\t\t\tBAD_ERROR(\"zlib::compress failed, not enough room in output buffer\\n\");\n\t\telse\n\t\t\tBAD_ERROR(\"zlib::compress failed, unknown error %d\\n\", res);\n\t\treturn 0;\n\t}\n\n\tif(uncompressed || c_byte >= size) {\n\t\tmemcpy(d, s, size);\n\t\treturn size | (data_block ? SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT);\n\t}\n\n\treturn (unsigned int) c_byte;\n}\n\n\nsquashfs_base_inode_header *get_inode(int req_size)\n{\n\tint data_space;\n\tunsigned short c_byte;\n\n\twhile(cache_bytes >= SQUASHFS_METADATA_SIZE) {\n\t\tif((inode_size - inode_bytes) < ((SQUASHFS_METADATA_SIZE << 1)) + 2) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + (SQUASHFS_METADATA_SIZE << 1) + 2))\n\t\t\t\t\t== NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, data_cache,\n\t\t\t\t\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(data_cache, data_cache + SQUASHFS_METADATA_SIZE, cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tcache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tdata_space = (cache_size - cache_bytes);\n\tif(data_space < req_size) {\n\t\t\tint realloc_size = cache_size == 0 ? ((req_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : req_size - data_space;\n\n\t\t\tif((data_cache = (char *) realloc(data_cache, cache_size + realloc_size)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tcache_size += realloc_size;\n\t}\n\n\tcache_bytes += req_size;\n\n\treturn (squashfs_base_inode_header *)(data_cache + (cache_bytes - req_size));\n\nfailed:\n\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n}\n\n\nvoid read_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tperror(\"Read on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nvoid write_bytes(int fd, long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tperror(\"Lseek on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n\n\tif(write(fd, buff, bytes) == -1) {\n\t\tperror(\"Write on destination failed\");\n\t\tEXIT_MKSQUASHFS();\n\t}\n}\n\n\nlong long write_inodes()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *datap = data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(cache_bytes) {\n\t\tif(inode_size - inode_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((inode_table = (char *) realloc(inode_table, inode_size + ((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in inode table reallocation!\\n\");\n\t\t\t}\n\t\t\tinode_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : cache_bytes;\n\t\tc_byte = mangle(inode_table + inode_bytes + block_offset, datap, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Inode block @ %x, size %d\\n\", inode_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(inode_table + inode_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (inode_table + inode_bytes), 1); \n\t\tif(check_data)\n\t\t\t*((unsigned char *)(inode_table + inode_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tinode_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_inode_bytes += avail_bytes + block_offset;\n\t\tdatap += avail_bytes;\n\t\tcache_bytes -= avail_bytes;\n\t}\n\n\twrite_bytes(fd, bytes, inode_bytes, (char *) inode_table);\n\tbytes += inode_bytes;\n\n\treturn start_bytes;\n}\n\n\nlong long write_directories()\n{\n\tunsigned short c_byte;\n\tint avail_bytes;\n\tchar *directoryp = directory_data_cache;\n\tlong long start_bytes = bytes;\n\n\twhile(directory_cache_bytes) {\n\t\tif(directory_size - directory_bytes < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table, directory_size +\n\t\t\t\t\t((SQUASHFS_METADATA_SIZE << 1) + 2))) == NULL) {\n\t\t\t\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n\t\t\t}\n\t\t\tdirectory_size += (SQUASHFS_METADATA_SIZE << 1) + 2;\n\t\t}\n\t\tavail_bytes = directory_cache_bytes > SQUASHFS_METADATA_SIZE ? SQUASHFS_METADATA_SIZE : directory_cache_bytes;\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directoryp, avail_bytes, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += avail_bytes + block_offset;\n\t\tdirectoryp += avail_bytes;\n\t\tdirectory_cache_bytes -= avail_bytes;\n\t}\n\twrite_bytes(fd, bytes, directory_bytes, (char *) directory_table);\n\tbytes += directory_bytes;\n\n\treturn start_bytes;\n}\n\n\nunsigned int get_uid(squashfs_uid uid)\n{\n\tint i;\n\n\tfor(i = 0; (i < uid_count) && uids[i] != uid; i++);\n\tif(i == uid_count) {\n\t\tif(uid_count == SQUASHFS_UIDS) {\n\t\t\tERROR(\"Out of uids! - using uid 0 - probably not what's wanted!\\n\");\n\t\t\ti = 0;\n\t\t} else\n\t\t\tuids[uid_count++] = uid;\n\t}\n\n\treturn i;\n}\n\n\nunsigned int get_guid(squashfs_uid uid, squashfs_uid guid)\n{\n\tint i;\n\n\tif(uid == guid)\n\t\treturn SQUASHFS_GUIDS;\n\n\tfor(i = 0; (i < guid_count) && guids[i] != guid; i++);\n\tif(i == guid_count) {\n\t\tif(guid_count == SQUASHFS_GUIDS) {\n\t\t\tERROR(\"Out of gids! - using gid 0 - probably not what's wanted!\\n\");\n\t\t\treturn SQUASHFS_GUIDS;\n\t\t} else\n\t\t\tguids[guid_count++] = guid;\n\t}\n\n\treturn i;\n}\n\n\nint create_inode(squashfs_inode *i_no, struct dir_ent *dir_ent, int type, long long byte_size, long long start_block, unsigned int offset, unsigned int *block_list, struct fragment *fragment, struct directory *dir_in)\n{\n\tstruct stat *buf = &dir_ent->inode->buf;\n\tsquashfs_inode_header inode_header;\n\tsquashfs_base_inode_header *inode, *base = &inode_header.base;\n\tchar *filename = dir_ent->pathname;\n\tint nlink = dir_ent->inode->nlink;\n\tint inode_number = (type == SQUASHFS_LDIR_TYPE || type == SQUASHFS_DIR_TYPE) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\tbase->mode = SQUASHFS_MODE(buf->st_mode);\n\tbase->uid = get_uid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid);\n\tbase->inode_type = type;\n\tbase->guid = get_guid((squashfs_uid) global_uid == -1 ? buf->st_uid : global_uid, (squashfs_uid) global_gid == -1 ? buf->st_gid : global_gid);\n\tbase->mtime = buf->st_mtime;\n\tbase->inode_number = inode_number;\n\n\tif(type == SQUASHFS_FILE_TYPE) {\n\t\tint i;\n\t\tsquashfs_reg_inode_header *reg = &inode_header.reg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_reg_inode_header *) inode;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"File inode, file_size %d, start_block %llx, blocks %d, fragment %d, offset %d, size %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LREG_TYPE) {\n\t\tint i;\n\t\tsquashfs_lreg_inode_header *reg = &inode_header.lreg, *inodep;\n\n\t\tinode = get_inode(sizeof(*reg) + offset * sizeof(unsigned int));\n\t\tinodep = (squashfs_lreg_inode_header *) inode;\n\t\treg->nlink = nlink;\n\t\treg->file_size = byte_size;\n\t\treg->start_block = start_block;\n\t\treg->fragment = fragment->index;\n\t\treg->offset = fragment->offset;\n\t\tif(!swap) {\n\t\t\tmemcpy(inodep, reg, sizeof(*reg));\n\t\t\tmemcpy(inodep->block_list, block_list, offset * sizeof(unsigned int));\n\t\t} else {\n\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(reg, inodep);\n\t\t\tSQUASHFS_SWAP_INTS(block_list, inodep->block_list, offset);\n\t\t}\n\t\tTRACE(\"Long file inode, file_size %lld, start_block %llx, blocks %d, fragment %d, offset %d, size %d, nlink %d\\n\", byte_size,\n\t\t\tstart_block, offset, fragment->index, fragment->offset, fragment->size, nlink);\n\t\tfor(i = 0; i < offset; i++)\n\t\t\tTRACE(\"Block %d, size %d\\n\", i, block_list[i]);\n\t}\n\telse if(type == SQUASHFS_LDIR_TYPE) {\n\t\tint i;\n\t\tunsigned char *p;\n\t\tsquashfs_ldir_inode_header *dir = &inode_header.ldir, *inodep;\n\t\tstruct cached_dir_index *index = dir_in->index;\n\t\tunsigned int i_count = dir_in->i_count;\n\t\tunsigned int i_size = dir_in->i_size;\n\n\t\tif(byte_size >= 1 << 27)\n\t\t\tBAD_ERROR(\"directory greater than 2^27-1 bytes!\\n\");\n\n\t\tinode = get_inode(sizeof(*dir) + i_size);\n\t\tinodep = (squashfs_ldir_inode_header *) inode;\n\t\tdir->inode_type = SQUASHFS_LDIR_TYPE;\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->i_count = i_count;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(dir, inode);\n\t\tp = (unsigned char *) inodep->index;\n\t\tfor(i = 0; i < i_count; i++) {\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(p, &index[i].index, sizeof(squashfs_dir_index));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index[i].index, p);\n\t\t\tmemcpy(((squashfs_dir_index *)p)->name, index[i].name, index[i].index.size + 1);\n\t\t\tp += sizeof(squashfs_dir_index) + index[i].index.size + 1;\n\t\t}\n\t\tTRACE(\"Long directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_DIR_TYPE) {\n\t\tsquashfs_dir_inode_header *dir = &inode_header.dir;\n\n\t\tinode = get_inode(sizeof(*dir));\n\t\tdir->nlink = dir_ent->dir->directory_count + 2;\n\t\tdir->file_size = byte_size;\n\t\tdir->offset = offset;\n\t\tdir->start_block = start_block;\n\t\tdir->parent_inode = dir_ent->our_dir ? dir_ent->our_dir->dir_ent->inode->inode_number : dir_inode_no + inode_no;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dir, sizeof(*dir));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(dir, inode);\n\t\tTRACE(\"Directory inode, file_size %d, start_block %llx, offset %x, nlink %d\\n\", (int) byte_size,\n\t\t\tstart_block, offset, dir_ent->dir->directory_count + 2);\n\t}\n\telse if(type == SQUASHFS_CHRDEV_TYPE || type == SQUASHFS_BLKDEV_TYPE) {\n\t\tsquashfs_dev_inode_header *dev = &inode_header.dev;\n\n\t\tinode = get_inode(sizeof(*dev));\n\t\tdev->nlink = nlink;\n\t\tdev->rdev = (unsigned short) ((major(buf->st_rdev) << 8) |\n\t\t\t(minor(buf->st_rdev) & 0xff));\n\t\tif(!swap)\n\t\t\tmemcpy(inode, dev, sizeof(*dev));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(dev, inode);\n\t\tTRACE(\"Device inode, rdev %x, nlink %d\\n\", dev->rdev, nlink);\n\t}\n\telse if(type == SQUASHFS_SYMLINK_TYPE) {\n\t\tsquashfs_symlink_inode_header *symlink = &inode_header.symlink, *inodep;\n\t\tint byte;\n\t\tchar buff[65536];\n\n\t\tif((byte = readlink(filename, buff, 65536)) == -1) {\n\t\t\tperror(\"Error in reading symbolic link, skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tif(byte == 65536) {\n\t\t\tERROR(\"Symlink is greater than 65536 bytes! skipping...\");\n\t\t\treturn FALSE;\n\t\t}\n\n\t\tinode = get_inode(sizeof(*symlink) + byte);\n\t\tsymlink->nlink = nlink;\n\t\tinodep = (squashfs_symlink_inode_header *) inode;\n\t\tsymlink->symlink_size = byte;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, symlink, sizeof(*symlink));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(symlink, inode);\n\t\tstrncpy(inodep->symlink, buff, byte);\n\t\tTRACE(\"Symbolic link inode, symlink_size %d, nlink %d\\n\", byte, nlink);\n\t}\n\telse if(type == SQUASHFS_FIFO_TYPE || type == SQUASHFS_SOCKET_TYPE) {\n\t\tsquashfs_ipc_inode_header *ipc = &inode_header.ipc;\n\n\t\tinode = get_inode(sizeof(*ipc));\n\t\tipc->nlink = nlink;\n\t\tif(!swap)\n\t\t\tmemcpy(inode, ipc, sizeof(*ipc));\n\t\telse\n\t\t\tSQUASHFS_SWAP_IPC_INODE_HEADER(ipc, inode);\n\t\tTRACE(\"ipc inode, type %s, nlink %d\\n\", type == SQUASHFS_FIFO_TYPE ? \"fifo\" : \"socket\", nlink);\n\t} else\n\t\treturn FALSE;\n\n\t*i_no = MKINODE(inode);\n\tinode_count ++;\n\n\tTRACE(\"Created inode 0x%llx, type %d, uid %d, guid %d\\n\", *i_no, type, base->uid, base->guid);\n\n\treturn TRUE;\n}\n\n\nvoid scan2_init_dir(struct directory *dir)\n{\n\tif((dir->buff = malloc(SQUASHFS_METADATA_SIZE)) == NULL) {\n\t\tBAD_ERROR(\"Out of memory allocating directory buffer\\n\");\n\t}\n\n\tdir->size = SQUASHFS_METADATA_SIZE;\n\tdir->p = dir->index_count_p = dir->buff;\n\tdir->entry_count = 256;\n\tdir->entry_count_p = NULL;\n\tdir->index = NULL;\n\tdir->i_count = dir->i_size = 0;\n}\n\n\nvoid add_dir(squashfs_inode inode, unsigned int inode_number, char *name, int type, struct directory *dir)\n{\n\tunsigned char *buff;\n\tsquashfs_dir_entry idir, *idirp;\n\tunsigned int start_block = inode >> 16;\n\tunsigned int offset = inode & 0xffff;\n\tunsigned int size;\n\n\tif((size = strlen(name)) > SQUASHFS_NAME_LEN) {\n\t\tsize = SQUASHFS_NAME_LEN;\n\t\tERROR(\"Filename is greater than %d characters, truncating! ...\\n\", SQUASHFS_NAME_LEN);\n\t}\n\n\tif(dir->p + sizeof(squashfs_dir_entry) + size + sizeof(squashfs_dir_header) >= dir->buff + dir->size) {\n\t\tif((buff = realloc(dir->buff, dir->size += SQUASHFS_METADATA_SIZE)) == NULL)  {\n\t\t\tBAD_ERROR(\"Out of memory reallocating directory buffer\\n\");\n\t\t}\n\n\t\tdir->p = (dir->p - dir->buff) + buff;\n\t\tif(dir->entry_count_p) \n\t\t\tdir->entry_count_p = (dir->entry_count_p - dir->buff + buff);\n\t\tdir->index_count_p = dir->index_count_p - dir->buff + buff;\n\t\tdir->buff = buff;\n\t}\n\n\tif(dir->entry_count == 256 || start_block != dir->start_block || ((dir->entry_count_p != NULL) && ((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE)) || ((long long) inode_number - dir->inode_number) > 32767 || ((long long) inode_number - dir->inode_number) < - 32768) {\n\t\tif(dir->entry_count_p) {\n\t\t\tsquashfs_dir_header dir_header;\n\n\t\t\tif((dir->p + sizeof(squashfs_dir_entry) + size - dir->index_count_p) > SQUASHFS_METADATA_SIZE) {\n\t\t\t\tif(dir->i_count % I_COUNT_SIZE == 0)\n\t\t\t\t\tif((dir->index = realloc(dir->index, (dir->i_count + I_COUNT_SIZE) * sizeof(struct cached_dir_index))) == NULL)\n\t\t\t\t\t\tBAD_ERROR(\"Out of memory in directory index table reallocation!\\n\");\n\t\t\t\tdir->index[dir->i_count].index.index = dir->p - dir->buff;\n\t\t\t\tdir->index[dir->i_count].index.size = size - 1;\n\t\t\t\tdir->index[dir->i_count++].name = name;\n\t\t\t\tdir->i_size += sizeof(squashfs_dir_index) + size;\n\t\t\t\tdir->index_count_p = dir->p;\n\t\t\t}\n\n\t\t\tdir_header.count = dir->entry_count - 1;\n\t\t\tdir_header.start_block = dir->start_block;\n\t\t\tdir_header.inode_number = dir->inode_number;\n\t\t\tif(!swap)\n\t\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\t\telse\n\t\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\n\t\t}\n\n\n\t\tdir->entry_count_p = dir->p;\n\t\tdir->start_block = start_block;\n\t\tdir->entry_count = 0;\n\t\tdir->inode_number = inode_number;\n\t\tdir->p += sizeof(squashfs_dir_header);\n\t}\n\n\tidirp = (squashfs_dir_entry *) dir->p;\n\tidir.offset = offset;\n\tidir.type = type;\n\tidir.size = size - 1;\n\tidir.inode_number = ((long long) inode_number - dir->inode_number);\n\tif(!swap)\n\t\tmemcpy(idirp, &idir, sizeof(idir));\n\telse\n\t\tSQUASHFS_SWAP_DIR_ENTRY((&idir), idirp);\n\tstrncpy(idirp->name, name, size);\n\tdir->p += sizeof(squashfs_dir_entry) + size;\n\tdir->entry_count ++;\n}\n\n\nint write_dir(squashfs_inode *inode, struct dir_info *dir_info, struct directory *dir)\n{\n\tunsigned int dir_size = dir->p - dir->buff;\n\tint data_space = (directory_cache_size - directory_cache_bytes);\n\tunsigned int directory_block, directory_offset, i_count, index;\n\tunsigned short c_byte;\n\n\tif(data_space < dir_size) {\n\t\tint realloc_size = directory_cache_size == 0 ? ((dir_size + SQUASHFS_METADATA_SIZE) & ~(SQUASHFS_METADATA_SIZE - 1)) : dir_size - data_space;\n\n\t\tif((directory_data_cache = (char *) realloc(directory_data_cache, directory_cache_size + realloc_size)) == NULL) {\n\t\t\tgoto failed;\n\t\t}\n\t\tdirectory_cache_size += realloc_size;\n\t}\n\n\tif(dir_size) {\n\t\tsquashfs_dir_header dir_header;\n\n\t\tdir_header.count = dir->entry_count - 1;\n\t\tdir_header.start_block = dir->start_block;\n\t\tdir_header.inode_number = dir->inode_number;\n\t\tif(!swap)\n\t\t\tmemcpy(dir->entry_count_p, &dir_header, sizeof(dir_header));\n\t\telse\n\t\t\tSQUASHFS_SWAP_DIR_HEADER((&dir_header), (squashfs_dir_header *) dir->entry_count_p);\n\t\tmemcpy(directory_data_cache + directory_cache_bytes, dir->buff, dir_size);\n\t}\n\tdirectory_offset = directory_cache_bytes;\n\tdirectory_block = directory_bytes;\n\tdirectory_cache_bytes += dir_size;\n\ti_count = 0;\n\tindex = SQUASHFS_METADATA_SIZE - directory_offset;\n\n\twhile(1) {\n\t\twhile(i_count < dir->i_count && dir->index[i_count].index.index < index)\n\t\t\tdir->index[i_count++].index.start_block = directory_bytes;\n\t\tindex += SQUASHFS_METADATA_SIZE;\n\n\t\tif(directory_cache_bytes < SQUASHFS_METADATA_SIZE)\n\t\t\tbreak;\n\n\t\tif((directory_size - directory_bytes) < ((SQUASHFS_METADATA_SIZE << 1) + 2)) {\n\t\t\tif((directory_table = (char *) realloc(directory_table,\n\t\t\t\t\t\t\tdirectory_size + (SQUASHFS_METADATA_SIZE << 1) + 2)) == NULL) {\n\t\t\t\tgoto failed;\n\t\t\t}\n\t\t\tdirectory_size += SQUASHFS_METADATA_SIZE << 1;\n\t\t}\n\n\t\tc_byte = mangle(directory_table + directory_bytes + block_offset, directory_data_cache,\n\t\t\t\tSQUASHFS_METADATA_SIZE, SQUASHFS_METADATA_SIZE, noI, 0);\n\t\tTRACE(\"Directory block @ %x, size %d\\n\", directory_bytes, c_byte);\n\t\tif(!swap)\n\t\t\tmemcpy(directory_table + directory_bytes, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), (directory_table + directory_bytes), 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(directory_table + directory_bytes + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tdirectory_bytes += SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\ttotal_directory_bytes += SQUASHFS_METADATA_SIZE + block_offset;\n\t\tmemcpy(directory_data_cache, directory_data_cache + SQUASHFS_METADATA_SIZE, directory_cache_bytes - SQUASHFS_METADATA_SIZE);\n\t\tdirectory_cache_bytes -= SQUASHFS_METADATA_SIZE;\n\t}\n\n\tif(dir_info->dir_is_ldir) {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_LDIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, dir) == FALSE)\n\t\t\treturn FALSE;\n\t} else {\n\t\tif(create_inode(inode, dir_info->dir_ent, SQUASHFS_DIR_TYPE, dir_size + 3, directory_block, directory_offset, NULL, NULL, NULL) == FALSE)\n\t\t\treturn FALSE;\n\t}\n\n#ifdef SQUASHFS_TRACE\n\tif(!swap) {\n\t\tunsigned char *dirp;\n\t\tint count;\n\n\t\tTRACE(\"Directory contents of inode 0x%llx\\n\", *inode);\n\t\tdirp = dir->buff;\n\t\twhile(dirp < dir->p) {\n\t\t\tchar buffer[SQUASHFS_NAME_LEN + 1];\n\t\t\tsquashfs_dir_entry idir, *idirp;\n\t\t\tsquashfs_dir_header *dirh = (squashfs_dir_header *) dirp;\n\t\t\tcount = dirh->count + 1;\n\t\t\tdirp += sizeof(squashfs_dir_header);\n\n\t\t\tTRACE(\"\\tStart block 0x%x, count %d\\n\", dirh->start_block, count);\n\n\t\t\twhile(count--) {\n\t\t\t\tidirp = (squashfs_dir_entry *) dirp;\n\t\t\t\tmemcpy((char *) &idir, (char *) idirp, sizeof(idir));\n\t\t\t\tstrncpy(buffer, idirp->name, idir.size + 1);\n\t\t\t\tbuffer[idir.size + 1] = '\\0';\n\t\t\t\tTRACE(\"\\t\\tname %s, inode offset 0x%x, type %d\\n\", buffer,\n\t\t\t\t\t\t  idir.offset, idir.type);\n\t\t\t\tdirp += sizeof(squashfs_dir_entry) + idir.size + 1;\n\t\t\t}\n\t\t}\n\t}\n#endif\n\tdir_count ++;\n\n\treturn TRUE;\n\nfailed:\n\tBAD_ERROR(\"Out of memory in directory table reallocation!\\n\");\n}\n\n\nchar *get_fragment(char *buffer, struct fragment *fragment)\n{\n\tsquashfs_fragment_entry *disk_fragment = &fragment_table[fragment->index];\n\tint size = SQUASHFS_COMPRESSED_SIZE_BLOCK(disk_fragment->size);\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(disk_fragment->size)) {\n\t\tint res;\n\t\tunsigned long bytes = block_size;\n\t\tchar cbuffer[block_size];\n\n\t\tread_bytes(fd, disk_fragment->start_block, size, cbuffer);\n\n\t\tif((res = uncompress((unsigned char *) buffer, &bytes, (const unsigned char *) cbuffer, size)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tBAD_ERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t}\n\t} else\n\t\tread_bytes(fd, disk_fragment->start_block, size, buffer);\n\n\treturn buffer + fragment->offset;\n}\n\n\t\nvoid write_fragment()\n{\n\tint compressed_size;\n\tchar buffer[block_size << 1];\n\n\tif(fragment_size == 0)\n\t\treturn;\n\n\tif(fragments % FRAG_SIZE == 0)\n\t\tif((fragment_table = (squashfs_fragment_entry *) realloc(fragment_table, (fragments + FRAG_SIZE) * sizeof(squashfs_fragment_entry))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in fragment table\\n\");\n\tfragment_table[fragments].size = mangle(buffer, fragment_data, fragment_size, block_size, noF, 1);\n\tfragment_table[fragments].start_block = bytes;\n\tcompressed_size = SQUASHFS_COMPRESSED_SIZE_BLOCK(fragment_table[fragments].size);\n\twrite_bytes(fd, bytes, compressed_size, buffer);\n\tbytes += compressed_size;\n\ttotal_uncompressed += fragment_size;\n\ttotal_compressed += compressed_size;\n\tTRACE(\"Writing fragment %d, uncompressed size %d, compressed size %d\\n\",fragments, fragment_size, compressed_size);\n\tfragments ++;\n\tfragment_size = 0;\n}\n\n\nstatic struct fragment empty_fragment = {SQUASHFS_INVALID_FRAG, 0, 0};\nstruct fragment *get_and_fill_fragment(char *buff, int size)\n{\n\tstruct fragment *ffrg;\n\n\tif(size == 0)\n\t\treturn &empty_fragment;\n\n\tif(fragment_size + size > block_size)\n\t\twrite_fragment();\n\n\tif((ffrg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tffrg->index = fragments;\n\tffrg->offset = fragment_size;\n\tffrg->size = size;\n\tmemcpy(fragment_data + fragment_size, buff, size);\n\tfragment_size += size;\n\n\treturn ffrg;\n}\n\n\nlong long write_fragment_table()\n{\n\tlong long start_bytes;\n\tunsigned int frag_bytes = SQUASHFS_FRAGMENT_BYTES(fragments),\n\t\tmeta_blocks = SQUASHFS_FRAGMENT_INDEXES(fragments);\n\tchar cbuffer[(SQUASHFS_METADATA_SIZE << 2) + 2], buffer[frag_bytes];\n\tsquashfs_fragment_entry *p = (squashfs_fragment_entry *) buffer;\n\tunsigned short c_byte;\n\tint i, compressed_size;\n\tsquashfs_fragment_index list[meta_blocks];\n\n\tTRACE(\"write_fragment_table: fragments %d, frag_bytes %d, meta_blocks %d\\n\", fragments, frag_bytes, meta_blocks);\n\tfor(i = 0; i < fragments; i++, p++) {\n\t\tTRACE(\"write_fragment_table: fragment %d, start_block %llx, size %d\\n\", i, fragment_table[i].start_block, fragment_table[i].size);\n\t\tif(!swap)\n\t\t\tmemcpy(p, &fragment_table[i], sizeof(squashfs_fragment_entry));\n\t\telse\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_table[i], p);\n\t}\n\n\tfor(i = 0; i < meta_blocks; i++) {\n\t\tint avail_bytes = i == meta_blocks - 1 ? frag_bytes % SQUASHFS_METADATA_SIZE : SQUASHFS_METADATA_SIZE;\n\t\tc_byte = mangle(cbuffer + block_offset, buffer + i * SQUASHFS_METADATA_SIZE , avail_bytes, SQUASHFS_METADATA_SIZE, noF, 0);\n\t\tif(!swap)\n\t\t\tmemcpy(cbuffer, &c_byte, sizeof(unsigned short));\n\t\telse\n\t\t\tSQUASHFS_SWAP_SHORTS((&c_byte), cbuffer, 1);\n\t\tif(check_data)\n\t\t\t*((unsigned char *)(cbuffer + block_offset - 1)) = SQUASHFS_MARKER_BYTE;\n\t\tlist[i] = bytes;\n\t\tcompressed_size = SQUASHFS_COMPRESSED_SIZE(c_byte) + block_offset;\n\t\twrite_bytes(fd, bytes, compressed_size, cbuffer);\n\t\tbytes += compressed_size;\n\t}\n\n\tif(!swap)\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) list);\n\telse {\n\t\tsquashfs_fragment_index slist[meta_blocks];\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(list, slist, meta_blocks);\n\t\twrite_bytes(fd, bytes, sizeof(list), (char *) slist);\n\t}\n\n\tstart_bytes = bytes;\n\tbytes += sizeof(list);\n\n\treturn start_bytes;\n}\n\n\nchar *read_from_buffer(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tchar *v = handle->ptr;\n\thandle->ptr += avail_bytes;\t\n\treturn v;\n}\n\n\nchar read_from_file_buffer[SQUASHFS_FILE_MAX_SIZE];\nchar *read_from_file(struct duplicate_buffer_handle *handle, unsigned int avail_bytes)\n{\n\tread_bytes(fd, handle->start, avail_bytes, read_from_file_buffer);\n\thandle->start += avail_bytes;\n\treturn read_from_file_buffer;\n}\n\n\n/*\n * Compute 16 bit BSD checksum over the data\n */\nunsigned short get_checksum(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *handle, long long l)\n{\n\tunsigned short chksum = 0;\n\tunsigned int bytes = 0;\n\tunsigned char *b;\n\tstruct duplicate_buffer_handle position = *handle;\n\n\twhile(l) {\n\t\tbytes = l > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : l;\n\t\tl -= bytes;\n\t\tb = (unsigned char *) get_next_file_block(&position, bytes);\n\t\twhile(bytes--) {\n\t\t\tchksum = (chksum & 1) ? (chksum >> 1) | 0x8000 : chksum >> 1;\n\t\t\tchksum += *b++;\n\t\t}\n\t}\n\n\treturn chksum;\n}\n\n\nint cached_frag = -1;\nvoid add_file(long long start, long long file_bytes, unsigned int *block_listp, int blocks, unsigned int fragment, int offset, int bytes)\n{\n\tstruct fragment *frg;\n\tstruct file_info *dupl_ptr;\n\tchar *datap;\n\tstruct duplicate_buffer_handle handle;\n\tunsigned int *block_list = block_listp;\n\n\tif(!duplicate_checking)\n\t\treturn;\n\n\tif((frg = (struct fragment *) malloc(sizeof(struct fragment))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in fragment block allocation!\\n\");\n\n\tfrg->index = fragment;\n\tfrg->offset = offset;\n\tfrg->size = bytes;\n\tif(fragment == cached_frag || fragment == SQUASHFS_INVALID_FRAG)\n\t\tdatap = fragment_data + offset;\n\telse\n\t\tdatap = get_fragment(fragment_data, frg);\n\thandle.start = start;\n\tif((dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &frg, datap, bytes)) != NULL)\n\t\tdupl_ptr->fragment = frg;\n\telse\n\t\tfree(block_list);\n\tcached_frag = fragment;\n}\n\n\nchar cached_fragment[SQUASHFS_FILE_SIZE];\nint cached_frag1 = -1;\n\nstruct file_info *duplicate(char *(get_next_file_block)(struct duplicate_buffer_handle *, unsigned int), struct duplicate_buffer_handle *file_start, long long bytes, unsigned int **block_list, long long *start, int blocks, struct fragment **fragment, char *frag_data, int frag_bytes)\n{\n\tunsigned short checksum = get_checksum(get_next_file_block, file_start, bytes);\n\tstruct duplicate_buffer_handle handle = { frag_data, 0 };\n\tunsigned short fragment_checksum = get_checksum(read_from_buffer, &handle, frag_bytes);\n\tstruct file_info *dupl_ptr = bytes ? dupl[checksum] : frag_dups[fragment_checksum];\n\n\n\tfor(; dupl_ptr; dupl_ptr = dupl_ptr->next)\n\t\tif(bytes == dupl_ptr->bytes && frag_bytes == dupl_ptr->fragment->size && fragment_checksum == dupl_ptr->fragment_checksum) {\n\t\t\tchar buffer1[SQUASHFS_FILE_MAX_SIZE];\n\t\t\tlong long dup_bytes = dupl_ptr->bytes;\n\t\t\tlong long dup_start = dupl_ptr->start;\n\t\t\tstruct duplicate_buffer_handle position = *file_start;\n\t\t\tchar *buffer;\n\t\t\twhile(dup_bytes) {\n\t\t\t\tint avail_bytes = dup_bytes > SQUASHFS_FILE_MAX_SIZE ? SQUASHFS_FILE_MAX_SIZE : dup_bytes;\n\n\t\t\t\tbuffer = get_next_file_block(&position, avail_bytes);\n\t\t\t\tread_bytes(fd, dup_start, avail_bytes, buffer1);\n\t\t\t\tif(memcmp(buffer, buffer1, avail_bytes) != 0)\n\t\t\t\t\tbreak;\n\t\t\t\tdup_bytes -= avail_bytes;\n\t\t\t\tdup_start += avail_bytes;\n\t\t\t}\n\t\t\tif(dup_bytes == 0) {\n\t\t\t\tchar *fragment_buffer1;\n\t\t\t\t\n\t\t\t\tif(dupl_ptr->fragment->index == fragments || dupl_ptr->fragment->index == SQUASHFS_INVALID_FRAG)\n\t\t\t\t\tfragment_buffer1 = fragment_data + dupl_ptr->fragment->offset;\n\t\t\t\telse if(dupl_ptr->fragment->index == cached_frag1)\n\t\t\t\t\tfragment_buffer1 = cached_fragment + dupl_ptr->fragment->offset;\n\t\t\t\telse {\n\t\t\t\t\tfragment_buffer1 = get_fragment(cached_fragment, dupl_ptr->fragment);\n\t\t\t\t\tcached_frag1 = dupl_ptr->fragment->index;\n\t\t\t\t}\n\n\t\t\t\tif(frag_bytes == 0 || memcmp(frag_data, fragment_buffer1, frag_bytes) == 0) {\n\t\t\t\t\tTRACE(\"Found duplicate file, start 0x%llx, size %lld, checksum 0x%x, fragment %d, size %d, offset %d, checksum 0x%x\\n\", dupl_ptr->start,\n\t\t\t\t\t\tdupl_ptr->bytes, dupl_ptr->checksum, dupl_ptr->fragment->index, frag_bytes, dupl_ptr->fragment->offset, fragment_checksum);\n\t\t\t\t\t*block_list = dupl_ptr->block_list;\n\t\t\t\t\t*start = dupl_ptr->start;\n\t\t\t\t\t*fragment = dupl_ptr->fragment;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\tif((dupl_ptr = (struct file_info *) malloc(sizeof(struct file_info))) == NULL) {\n\t\tBAD_ERROR(\"Out of memory in dup_files allocation!\\n\");\n\t}\n\n\tdupl_ptr->bytes = bytes;\n\tdupl_ptr->checksum = checksum;\n\tdupl_ptr->start = *start;\n\tdupl_ptr->fragment_checksum = fragment_checksum;\n\tdupl_ptr->block_list = *block_list;\n\n\tdup_files ++;\n\tif(bytes) {\n\t\tdupl_ptr->next = dupl[checksum];\n\t\tdupl[checksum] = dupl_ptr;\n\t} else {\n\t\tdupl_ptr->next = frag_dups[fragment_checksum];\n\t\tfrag_dups[fragment_checksum] = dupl_ptr;\n\t}\n\n\treturn dupl_ptr;\n}\n\n\n#define MINALLOCBYTES (1024 * 1024)\nint write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *duplicate_file)\n{\n\tint block = 0, i, file, whole_file = 1, status;\n\tunsigned int c_byte, frag_bytes;\n\tlong long bbytes, file_bytes = 0, start;\n\tchar *c_buffer = NULL, *filename = dir_ent->pathname;\n\tstruct fragment *fragment;\n\tstruct file_info *dupl_ptr = NULL;\n\tstruct duplicate_buffer_handle handle;\n\tlong long read_size = (size > SQUASHFS_MAX_FILE_SIZE) ? SQUASHFS_MAX_FILE_SIZE : size;\n\tint blocks = (read_size + block_size - 1) >> block_log, allocated_blocks = blocks;\n\tunsigned int *block_list, *block_listp;\n\tchar *buff = (char*)malloc(SQUASHFS_FILE_MAX_SIZE);\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL)\n\t\tBAD_ERROR(\"Out of memory allocating block_list\\n\");\n\tblock_listp = block_list;\n\n\tif(!no_fragments && (read_size < block_size || always_use_fragments)) {\n\t\tallocated_blocks = blocks = read_size >> block_log;\n\t\tfrag_bytes = read_size % block_size;\n\t} else\n\t\tfrag_bytes = 0;\n\n\tif(size > read_size)\n\t\tERROR(\"file %s truncated to %lld bytes\\n\", filename, SQUASHFS_MAX_FILE_SIZE);\n\n\ttotal_bytes += read_size;\n\tif((file = open(filename, O_RDONLY)) == -1)\n\t\tgoto read_err;\n\n\tdo {\n\t\tlong long bytes = (((long long) allocated_blocks) + 1) << block_log;\n\t\tif(bytes != ((size_t) bytes) || (c_buffer = (char *) malloc(bytes)) == NULL) {\n\t\t\tTRACE(\"Out of memory allocating write_file buffer, allocated_blocks %ld, blocks %d\\n\", allocated_blocks, blocks);\n\t\t\twhole_file = 0;\n\t\t\tif(bytes < MINALLOCBYTES)\n\t\t\t\tBAD_ERROR(\"Out of memory allocating write_file buffer, could not allocate %ld blocks (%d Kbytes)\\n\", allocated_blocks, allocated_blocks << (block_log - 10));\n\t\t\tallocated_blocks >>= 1;\n\t\t}\n\t} while(!c_buffer);\n\n\tfor(start = bytes; block < blocks; file_bytes += bbytes) {\n\t\tfor(i = 0, bbytes = 0; (i < allocated_blocks) && (block < blocks); i++) {\n\t\t\tint available_bytes = read_size - (block * block_size) > block_size ? block_size : read_size - (block * block_size);\n\t\t\tif(read(file, buff, available_bytes) == -1)\n\t\t\t\tgoto read_err;\n\t\t\tc_byte = mangle(c_buffer + bbytes, buff, available_bytes, block_size, noD, 1);\n\t\t\tblock_list[block ++] = c_byte;\n\t\t\tbbytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);\n\t\t}\n\t\tif(!whole_file) {\n\t\t\twrite_bytes(fd, bytes, bbytes, c_buffer);\n\t\t\tbytes += bbytes;\n\t\t}\n\t}\n\n\tif(frag_bytes != 0)\n\t\t{\n\t\tif(read(file, buff, frag_bytes) == -1)\n\t\t\tgoto read_err;\n\t\t}\n\n\tclose(file);\n\tif(whole_file) {\n\t\thandle.ptr = c_buffer;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_buffer, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t\twrite_bytes(fd, bytes, file_bytes, c_buffer);\n\t\tbytes += file_bytes;\n\t} else {\n\t\thandle.start = start;\n\t\tif(duplicate_checking && (dupl_ptr = duplicate(read_from_file, &handle, file_bytes, &block_listp, &start, blocks, &fragment, buff, frag_bytes)) == NULL) {\n\t\t\tbytes = start;\n\t\t\tif(!block_device)\n\t\t\t\tftruncate(fd, bytes);\n\t\t\t*duplicate_file = TRUE;\n\t\t\tgoto wr_inode;\n\t\t}\n\t}\n\n\tfragment = get_and_fill_fragment(buff, frag_bytes);\n\tif(duplicate_checking)\n\t\tdupl_ptr->fragment = fragment;\n\n\t*duplicate_file = FALSE;\n\nwr_inode:\n\tfree(c_buffer);\n\tfile_count ++;\n\tif(dir_ent->inode->nlink == 1 && read_size < ((long long) (1<<30) - 1))\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_FILE_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\telse\n\t\tstatus = create_inode(inode, dir_ent, SQUASHFS_LREG_TYPE, read_size, start, blocks, block_listp, fragment, NULL);\n\tif(duplicate_checking == FALSE || *duplicate_file == TRUE)\n\t\tfree(block_list);\n\treturn status;\n\nread_err:\n\tperror(\"Error in reading file, skipping...\");\n\tfree(buff);\n\tfree(c_buffer);\n\tfree(block_list);\n\treturn FALSE;\n}\n\n\nchar b_buffer[8192];\nchar *name;\nchar *basename_r();\n\nchar *getbase(char *pathname)\n{\n\tchar *result;\n\n\tif(*pathname != '/') {\n\t\tresult = getenv(\"PWD\");\n\t\tstrcat(strcat(strcpy(b_buffer, result), \"/\"), pathname);\n\t} else\n\t\tstrcpy(b_buffer, pathname);\n\tname = b_buffer;\n\tif(((result = basename_r()) == NULL) || (strcmp(result, \"..\") == 0))\n\t\treturn NULL;\n\telse\n\t\treturn result;\n}\n\n\nchar *basename_r()\n{\n\tchar *s;\n\tchar *p;\n\tint n = 1;\n\n\tfor(;;) {\n\t\ts = name;\n\t\tif(*name == '\\0')\n\t\t\treturn NULL;\n\t\tif(*name != '/') {\n\t\t\twhile(*name != '\\0' && *name != '/') name++;\n\t\t\tn = name - s;\n\t\t}\n\t\twhile(*name == '/') name++;\n\t\tif(strncmp(s, \".\", n) == 0)\n\t\t\tcontinue;\n\t\tif((*name == '\\0') || (strncmp(s, \"..\", n) == 0) || ((p = basename_r()) == NULL)) {\n\t\t\ts[n] = '\\0';\n\t\t\treturn s;\n\t\t}\n\t\tif(strcmp(p, \"..\") == 0)\n\t\t\tcontinue;\n\t\treturn p;\n\t}\n}\n\n\nstruct inode_info *lookup_inode(struct stat *buf)\n{\n\tint inode_hash = INODE_HASH(buf->st_dev, buf->st_ino);\n\tstruct inode_info *inode = inode_info[inode_hash];\n\n\twhile(inode != NULL) {\n\t\tif(memcmp(buf, &inode->buf, sizeof(struct stat)) == 0) {\n\t\t\tinode->nlink ++;\n\t\t\treturn inode;\n\t\t}\n\t\tinode = inode->next;\n\t}\n\n\tif((inode = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in inode hash table entry allocation\\n\");\n\n\tmemcpy(&inode->buf, buf, sizeof(struct stat));\n\tinode->inode = SQUASHFS_INVALID_BLK;\n\tinode->nlink = 1;\n\tif((buf->st_mode & S_IFMT) == S_IFDIR)\n\t\tinode->inode_number = dir_inode_no ++;\n\telse\n\t\tinode->inode_number = inode_no ++;\n\n\tinode->next = inode_info[inode_hash];\n\tinode_info[inode_hash] = inode;\n\n\treturn inode;\n}\n\n\ninline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, struct inode_info *inode_info, void *data, struct dir_info *dir)\n{\n\tif((dir->count % DIR_ENTRIES) == 0)\n\t\tif((dir->list = realloc(dir->list, (dir->count + DIR_ENTRIES) * sizeof(struct dir_ent *))) == NULL)\n\t\t\tBAD_ERROR(\"Out of memory in add_dir_entry\\n\");\n\n\tif((dir->list[dir->count] = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in linux_opendir\\n\");\n\n\tif(sub_dir)\n\t\tsub_dir->dir_ent = dir->list[dir->count];\n\tdir->list[dir->count]->name = strdup(name);\n\tdir->list[dir->count]->pathname = pathname != NULL ? strdup(pathname) : NULL;\n\tdir->list[dir->count]->inode = inode_info;\n\tdir->list[dir->count]->dir = sub_dir;\n\tdir->list[dir->count]->our_dir = dir;\n\tdir->list[dir->count++]->data = data;\n\tdir->byte_count += strlen(name) + sizeof(squashfs_dir_entry);\n}\n\n\nint compare_name(const void *ent1_ptr, const void *ent2_ptr)\n{\n\tstruct dir_ent *ent1 = *((struct dir_ent **) ent1_ptr);\n\tstruct dir_ent *ent2 = *((struct dir_ent **) ent2_ptr);\n\n\treturn strcmp(ent1->name, ent2->name);\n}\n\n\nvoid sort_directory(struct dir_info *dir)\n{\n\tqsort(dir->list, dir->count, sizeof(struct dir_ent *), compare_name);\n\n\tif((dir->count < 257 && dir->byte_count < SQUASHFS_METADATA_SIZE))\n\t\tdir->dir_is_ldir = FALSE;\n}\n\n\nstruct dir_info *scan1_opendir(char *pathname)\n{\n\tDIR\t*linuxdir;\n\tstruct dirent *d_name;\n\tstruct dir_info *dir;\n\n\tif((dir = malloc(sizeof(struct dir_info))) == NULL)\n\t\treturn NULL;\n\n\tif(pathname[0] != '\\0' && (dir->linuxdir = opendir(pathname)) == NULL) {\n\t\tfree(dir);\n\t\treturn NULL;\n\t}\n\tdir->pathname = strdup(pathname);\n\tdir->count = dir->directory_count = dir->current_count = dir->byte_count = 0;\n\tdir->dir_is_ldir = TRUE;\n\tdir->list = NULL;\n\n\treturn dir;\n}\n\n\nint scan1_encomp_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tint i, n, pass;\n\tchar *basename;\n\tstatic int index = 0;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\twhile(index < source) {\n\t\tif((basename = getbase(source_path[index])) == NULL) {\n\t\t\tERROR(\"Bad source directory %s - skipping ...\\n\", source_path[index]);\n\t\t\tindex ++;\n\t\t\tcontinue;\n\t\t}\n\t\tstrcpy(dir_name, basename);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(n = 0; n < dir->count && strcmp(dir->list[n]->name, dir_name) != 0; n++);\n\t\t\tif(n == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", basename, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcpy(pathname, source_path[index ++]);\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n\nint scan1_single_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\tint i, pass;\n\n\tif(dir->count < old_root_entries)\n\t\tfor(i = 0; i < old_root_entries; i++) {\n\t\t\tif(old_root_entry[i].type == SQUASHFS_DIR_TYPE)\n\t\t\t\tdir->directory_count ++;\n\t\t\tadd_dir_entry(old_root_entry[i].name, \"\", NULL, NULL, &old_root_entry[i], dir);\n\t\t}\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tpass = 1;\n\t\tfor(;;) {\n\t\t\tfor(i = 0; i < dir->count && strcmp(dir->list[i]->name, dir_name) != 0; i++);\n\t\t\tif(i == dir->count)\n\t\t\t\tbreak;\n\t\t\tERROR(\"Source directory entry %s already used! - trying \", dir_name);\n\t\t\tsprintf(dir_name, \"%s_%d\", d_name->d_name, pass++);\n\t\t\tERROR(\"%s\\n\", dir_name);\n\t\t}\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nint scan1_readdir(char *pathname, char *dir_name, struct dir_info *dir)\n{\n\tstruct dirent *d_name;\n\n\tif((d_name = readdir(dir->linuxdir)) != NULL) {\n\t\tstrcpy(dir_name, d_name->d_name);\n\t\tstrcat(strcat(strcpy(pathname, dir->pathname), \"/\"), d_name->d_name);\n\t\treturn 1;\n\t}\n\n\treturn 0;\n}\n\n\nstruct dir_ent *scan2_readdir(struct directory *dir, struct dir_info *dir_info)\n{\n\tint current_count;\n\n\twhile((current_count = dir_info->current_count++) < dir_info->count)\n\t\tif(dir_info->list[current_count]->data)\n\t\t\tadd_dir(dir_info->list[current_count]->data->inode, dir_info->list[current_count]->data->inode_number,\n\t\t\t\tdir_info->list[current_count]->name, dir_info->list[current_count]->data->type, dir);\n\t\telse \n\t\t\treturn dir_info->list[current_count];\n\treturn FALSE;\t\n}\n\n\nvoid scan1_freedir(struct dir_info *dir)\n{\n\tif(dir->pathname[0] != '\\0')\n\t\tclosedir(dir->linuxdir);\n}\n\n\nvoid scan2_freedir(struct directory *dir)\n{\n\tif(dir->index)\n\t\tfree(dir->index);\n\tfree(dir->buff);\n}\n\n\nvoid dir_scan(squashfs_inode *inode, char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir_info = dir_scan1(pathname, _readdir);\n\tstruct dir_ent *dir_ent;\n\tstruct inode_info *inode_info;\n\t\n\tif(dir_info == NULL)\n\t\treturn;\n\n\tif((dir_ent = malloc(sizeof(struct dir_ent))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tif((inode_info = malloc(sizeof(struct inode_info))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in dir_scan\\n\");\n\n\tdir_ent->name = dir_ent->pathname = strdup(pathname);\n\tdir_ent->dir = dir_info;\n\tdir_ent->inode = inode_info;\n\tdir_ent->our_dir = NULL;\n\tdir_ent->data = NULL;\n\tinode_info->nlink = 1;\n\tinode_info->inode_number = root_inode_number ? root_inode_number : dir_inode_no++;\n\tdir_info->dir_ent = dir_ent;\n\n\tif(pathname[0] == '\\0') {\n\t\t/* dummy top level directory, if multiple sources specified on command line */\n\t\tinode_info->buf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO;\n\t\tinode_info->buf.st_uid = getuid();\n\t\tinode_info->buf.st_gid = getgid();\n\t\tinode_info->buf.st_mtime = time(NULL);\n\t} else if(lstat(pathname, &inode_info->buf) == -1) {\n\t\tchar buffer[8192];\n\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", pathname);\n\t\tperror(buffer);\n\t\treturn;\n\t}\n\tif(sorted)\n\t\tsort_files_and_write(dir_info);\n\tdir_scan2(inode, dir_info);\n}\n\n\nstruct dir_info *dir_scan1(char *pathname, int (_readdir)(char *, char *, struct dir_info *))\n{\n\tstruct dir_info *dir, *sub_dir;\n\tstruct stat buf;\n\tchar filename[8192], dir_name[8192];\n\n\tif((dir = scan1_opendir(pathname)) == NULL) {\n\t\tERROR(\"Could not open %s, skipping...\\n\", pathname);\n\t\tgoto error;\n\t}\n\n\twhile(_readdir(filename, dir_name, dir) != FALSE) {\n\n\t\tif(strcmp(dir_name, \".\") == 0 || strcmp(dir_name, \"..\") == 0)\n\t\t\tcontinue;\n\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tchar buffer[8192];\n\t\t\tsprintf(buffer, \"Cannot stat dir/file %s, ignoring\", filename);\n\t\t\tperror(buffer);\n\t\t\tcontinue;\n\t\t}\n\t\tif(excluded(filename, &buf))\n\t\t\tcontinue;\n\n\t\tif((buf.st_mode & S_IFMT) == S_IFDIR) {\n\t\t\tif((sub_dir = dir_scan1(filename, scan1_readdir)) == NULL)\n\t\t\t\tcontinue;\n\t\t\tdir->directory_count ++;\n\t\t} else\n\t\t\tsub_dir = NULL;\n\n\t\tadd_dir_entry(dir_name, filename, sub_dir, lookup_inode(&buf), NULL, dir);\n\t}\n\n\tscan1_freedir(dir);\n\tsort_directory(dir);\n\nerror:\n\treturn dir;\n}\n\n\nint dir_scan2(squashfs_inode *inode, struct dir_info *dir_info)\n{\n\tint squashfs_type;\n\tint result = FALSE;\n\tint duplicate_file;\n\tchar *pathname = dir_info->pathname;\n\tstruct directory dir;\n\tstruct dir_ent *dir_ent;\n\t\n\tscan2_init_dir(&dir);\n\t\n\twhile((dir_ent = scan2_readdir(&dir, dir_info)) != NULL) {\n\t\tstruct inode_info *inode_info = dir_ent->inode;\n\t\tstruct stat *buf = &inode_info->buf;\n\t\tchar *filename = dir_ent->pathname;\n\t\tchar *dir_name = dir_ent->name;\n\t\tunsigned int inode_number = ((buf->st_mode & S_IFMT) == S_IFDIR) ? dir_ent->inode->inode_number : dir_ent->inode->inode_number + dir_inode_no;\n\n\t\tif(dir_ent->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\t\tcase S_IFREG:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FILE_TYPE;\n\t\t\t\t\tresult = write_file(inode, dir_ent, buf->st_size, &duplicate_file);\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\", filename, buf->st_size, duplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFDIR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_DIR_TYPE;\n\t\t\t\t\tresult = dir_scan2(inode, dir_ent->dir);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFLNK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SYMLINK_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsym_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFCHR:\n\t\t\t\t\tsquashfs_type = SQUASHFS_CHRDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFBLK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_BLKDEV_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tdev_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFIFO:\n\t\t\t\t\tsquashfs_type = SQUASHFS_FIFO_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tfifo_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase S_IFSOCK:\n\t\t\t\t\tsquashfs_type = SQUASHFS_SOCKET_TYPE;\n\t\t\t\t\tresult = create_inode(inode, dir_ent, squashfs_type, 0, 0, 0, NULL, NULL, NULL);\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx\\n\", dir_name, *inode);\n\t\t\t\t\tsock_count ++;\n\t\t\t\t\tbreak;\n\n\t\t\t \tdefault:\n\t\t\t\t\tERROR(\"%s unrecognised file type, mode is %x\\n\", filename, buf->st_mode);\n\t\t\t\t\tresult = FALSE;\n\t\t\t\t}\n\t\t\tif(result)\n\t\t\t\tdir_ent->inode->inode = *inode;\n\t\t\tdir_ent->inode->type = squashfs_type;\n\t\t } else {\n\t\t\t*inode = dir_ent->inode->inode;\n\t\t\tsquashfs_type = dir_ent->inode->type;\n\t\t\tswitch(squashfs_type) {\n\t\t\t\tcase SQUASHFS_FILE_TYPE:\n\t\t\t\t\tif(!sorted)\n\t\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\", filename, buf->st_size);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SYMLINK_TYPE:\n\t\t\t\t\tINFO(\"symbolic link %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t\tINFO(\"character device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcaseSQUASHFS_BLKDEV_TYPE:\n\t\t\t\t\tINFO(\"block device %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t\tINFO(\"fifo %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t\tINFO(\"unix domain socket %s inode 0x%llx LINK\\n\", dir_name, *inode);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult = TRUE;\n\t\t}\n\t\t\n\n\t\tif(result)\n\t\t\tadd_dir(*inode, inode_number, dir_name, squashfs_type, &dir);\n\t}\n\n\tresult = write_dir(inode, dir_info, &dir);\n\tINFO(\"directory %s inode 0x%llx\\n\", pathname, *inode);\n\n\tscan2_freedir(&dir);\n\n\treturn result;\n}\n\n\nunsigned int slog(unsigned int block)\n{\n\tint i;\n\n\tfor(i = 12; i <= 20; i++)\n\t\tif(block == (1 << i))\n\t\t\treturn i;\n\treturn 0;\n}\n\n\nint excluded(char *filename, struct stat *buf)\n{\n\tint i;\n\n\tfor(i = 0; i < exclude; i++)\n\t\tif((exclude_paths[i].st_dev == buf->st_dev) && (exclude_paths[i].st_ino == buf->st_ino))\n\t\t\treturn TRUE;\n\treturn FALSE;\n}\n\n\n#define ADD_ENTRY(buf) \\\n\tif(exclude % EXCLUDE_SIZE == 0) {\\\n\t\tif((exclude_paths = (struct exclude_info *) realloc(exclude_paths, (exclude + EXCLUDE_SIZE) * sizeof(struct exclude_info))) == NULL)\\\n\t\t\tBAD_ERROR(\"Out of memory in exclude dir/file table\\n\");\\\n\t}\\\n\texclude_paths[exclude].st_dev = buf.st_dev;\\\n\texclude_paths[exclude++].st_ino = buf.st_ino;\nint add_exclude(char *path)\n{\n\tint i;\n\tchar buffer[4096], filename[4096];\n\tstruct stat buf;\n\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0) {\n\t\tif(lstat(path, &buf) == -1) {\n\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", path);\n\t\t\tperror(buffer);\n\t\t\treturn TRUE;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR)) {\n\t\t\t\tsprintf(buffer, \"Cannot stat exclude dir/file %s, ignoring\", filename);\n\t\t\t\tperror(buffer);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf);\n\t}\n\treturn TRUE;\n}\n\n\nvoid add_old_root_entry(char *name, squashfs_inode inode, int inode_number, int type)\n{\n\tif((old_root_entry = (struct old_root_entry_info *) realloc(old_root_entry, sizeof(struct old_root_entry_info)\n\t\t\t\t* (old_root_entries + 1))) == NULL)\n\t\tBAD_ERROR(\"Out of memory in old root directory entries reallocation\\n\");\n\n\tstrcpy(old_root_entry[old_root_entries].name, name);\n\told_root_entry[old_root_entries].inode = inode;\n\told_root_entry[old_root_entries].inode_number = inode_number;\n\told_root_entry[old_root_entries++].type = type;\n}\n\n\n#define VERSION() \\\n\tprintf(\"mksquashfs version 3.0 (2006/03/15)\\n\");\\\n\tprintf(\"copyright (C) 2006 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tstruct stat buf, source_buf;\n\tint i;\n\tsquashfs_super_block sBlk;\n\tchar *b, *root_name = NULL;\n\tint be, nopad = FALSE, keep_as_directory = FALSE, orig_be;\n\tsquashfs_inode inode;\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tbe = TRUE;\n#else\n\tbe = FALSE;\n#endif\n\n\tblock_log = slog(block_size);\n\tif(argc > 1 && strcmp(argv[1], \"-version\") == 0) {\n\t\tVERSION();\n\t\texit(0);\n\t}\n        for(i = 1; i < argc && argv[i][0] != '-'; i++);\n\tif(i < 3)\n\t\tgoto printOptions;\n\tsource_path = argv + 1;\n\tsource = i - 2;\n\tfor(; i < argc; i++) {\n\t\tif(strcmp(argv[i], \"-b\") == 0) {\n\t\t\tif((++i == argc) || (block_size = strtol(argv[i], &b, 10), *b !='\\0')) {\n\t\t\t\tERROR(\"%s: -b missing or invalid block size\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\n\t\t\tif((block_log = slog(block_size)) == 0) {\n\t\t\t\tERROR(\"%s: -b block size not power of two or not between 4096 and 64K\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -ef missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-no-duplicates\") == 0)\n\t\t\tduplicate_checking = FALSE;\n\n#ifdef _LZMA_PARAMS\t\t\n\t\telse if(strcmp(argv[i], \"-lc\") == 0)\n\t\t{\n\t\t\tif(++i == argc) \n\t\t\t{\n\t\t\t    ERROR(\"%s: -lc missing or invalid value\\n\", argv[0]);\n\t\t\t    exit(1);\n\t\t\t}\n\t\t\tg_lc = strtol(argv[i], NULL, 10);\n\t\t\tif(g_lc<0 || g_lc>8)\n\t\t\t{\n\t\t\t\tERROR(\"lc is out of bounds (0-8).\\n\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse if(strcmp(argv[i], \"-lp\") == 0)\n\t\t{\n\t\t\tif(++i == argc) \n\t\t\t{\n\t\t\t    ERROR(\"%s: -lp missing or invalid value\\n\", argv[0]);\n\t\t\t    exit(1);\n\t\t\t}\n\t\t\tg_lp = strtol(argv[i], NULL, 10);\n\t\t\tif(g_lp<0 || g_lp>4)\n\t\t\t{\n\t\t\t\tERROR(\"lp is out of bounds (0-4).\\n\");\n\t\t\t\texit(1);\t\t\t\t\n\t\t\t}\t\t\t\n\t\t}\n\t\telse if(strcmp(argv[i], \"-pb\") == 0)\n\t\t{\n\t\t\tif(++i == argc) \n\t\t\t{\n\t\t\t    ERROR(\"%s: -pb missing or invalid value\\n\", argv[0]);\n\t\t\t    exit(1);\n\t\t\t}\n\t\t\tg_pb = strtol(argv[i], NULL, 10);\n\t\t\tif(g_pb<0 || g_pb>4)\n\t\t\t{\n\t\t\t\tERROR(\"pb is out of bounds (0-4).\\n\");\n\t\t\t\texit(1);\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\telse if(strcmp(argv[i], \"-fb\") == 0)\n\t\t{\n\t\t\tif(++i == argc) \n\t\t\t{\n\t\t\t    ERROR(\"%s: -fb missing or invalid value\\n\", argv[0]);\n\t\t\t    exit(1);\n\t\t\t}\n\t\t\tg_fb = strtol(argv[i], NULL, 10);\n\t\t\tif(g_fb<5 || g_fb>273)\n\t\t\t{\n\t\t\t\tERROR(\"fb is out of bounds (5-272).\\n\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n#endif\t\t\n\t\telse if(strcmp(argv[i], \"-no-fragments\") == 0)\n\t\t\tno_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-always-use-fragments\") == 0)\n\t\t\talways_use_fragments = TRUE;\n\n\t\t else if(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -sort missing filename\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-all-root\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-root-owned\") == 0)\n\t\t\tglobal_uid = global_gid = 0;\n\n\t\telse if(strcmp(argv[i], \"-force-uid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-uid missing uid or user\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_uid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_uid < 0 || global_uid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-uid uid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct passwd *uid = getpwnam(argv[i]);\n\t\t\t\tif(uid)\n\t\t\t\t\tglobal_uid = uid->pw_uid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-uid invalid uid or unknown user\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-force-gid\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -force-gid missing gid or group\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tif((global_gid = strtoll(argv[i], &b, 10)), *b =='\\0') {\n\t\t\t\tif(global_gid < 0 || global_gid > (((long long) 1 << 32) - 1)) {\n\t\t\t\t\tERROR(\"%s: -force-gid gid out of range\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tstruct group *gid = getgrnam(argv[i]);\n\t\t\t\tif(gid)\n\t\t\t\t\tglobal_gid = gid->gr_gid;\n\t\t\t\telse {\n\t\t\t\t\tERROR(\"%s: -force-gid invalid gid or unknown group\\n\", argv[0]);\n\t\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if(strcmp(argv[i], \"-noI\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noInodeCompression\") == 0)\n\t\t\tnoI = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noD\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noDataCompression\") == 0)\n\t\t\tnoD = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-noF\") == 0 ||\n\t\t\t\tstrcmp(argv[i], \"-noFragmentCompression\") == 0)\n\t\t\tnoF = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-nopad\") == 0)\n\t\t\tnopad = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-check_data\") == 0)\n\t\t\tcheck_data = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tsilent = 0;\n\n\t\telse if(strcmp(argv[i], \"-be\") == 0)\n\t\t\tbe = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-le\") == 0)\n\t\t\tbe = FALSE;\n\n\t\telse if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\n\t\telse if(strcmp(argv[i], \"-noappend\") == 0)\n\t\t\tdelete = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-keep-as-directory\") == 0)\n\t\t\tkeep_as_directory = TRUE;\n\n\t\telse if(strcmp(argv[i], \"-root-becomes\") == 0) {\n\t\t\tif(++i == argc) {\n\t\t\t\tERROR(\"%s: -root-becomes: missing name\\n\", argv[0]);\n\t\t\t\texit(1);\n\t\t\t}\t\n\t\t\troot_name = argv[i];\n\t\t} else if(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t} else {\n\t\t\tERROR(\"%s: invalid option\\n\\n\", argv[0]);\nprintOptions:\n\t\t\tERROR(\"SYNTAX:%s source1 source2 ...  dest [options] [-e list of exclude\\ndirs/files]\\n\", argv[0]);\n\t\t\tERROR(\"\\nOptions are\\n\");\n\t\t\tERROR(\"-version\\t\\tprint version, licence and copyright message\\n\");\n\t\t\tERROR(\"-info\\t\\t\\tprint files written to filesystem\\n\");\n\t\t\tERROR(\"-b <block_size>\\t\\tset data block to <block_size>.  Default %d bytes\\n\", SQUASHFS_FILE_SIZE);\n\t\t\tERROR(\"-noI\\t\\t\\tdo not compress inode table\\n\");\n\t\t\tERROR(\"-noD\\t\\t\\tdo not compress data blocks\\n\");\n\t\t\tERROR(\"-noF\\t\\t\\tdo not compress fragment blocks\\n\");\n\t\t\tERROR(\"-no-fragments\\t\\tdo not use fragments\\n\");\n\t\t\tERROR(\"-always-use-fragments\\tuse fragment blocks for files larger than block size\\n\");\n\t\t\tERROR(\"-no-duplicates\\t\\tdo not perform duplicate checking\\n\");\n\t\t\tERROR(\"-noappend\\t\\tdo not append to existing filesystem\\n\");\n\t\t\tERROR(\"-keep-as-directory\\tif one source directory is specified, create a root\\n\");\n\t\t\tERROR(\"\\t\\t\\tdirectory containing that directory, rather than the\\n\");\n\t\t\tERROR(\"\\t\\t\\tcontents of the directory\\n\");\n\t\t\tERROR(\"-root-becomes <name>\\twhen appending source files/directories, make the\\n\");\n\t\t\tERROR(\"\\t\\t\\toriginal root become a subdirectory in the new root\\n\");\n\t\t\tERROR(\"\\t\\t\\tcalled <name>, rather than adding the new source items\\n\");\n\t\t\tERROR(\"\\t\\t\\tto the original root\\n\");\n\t\t\tERROR(\"-all-root\\t\\tmake all files owned by root\\n\");\n\t\t\tERROR(\"-force-uid uid\\t\\tset all file uids to uid\\n\");\n\t\t\tERROR(\"-force-gid gid\\t\\tset all file gids to gid\\n\");\n\t\t\tERROR(\"-le\\t\\t\\tcreate a little endian filesystem\\n\");\n\t\t\tERROR(\"-be\\t\\t\\tcreate a big endian filesystem\\n\");\n\t\t\tERROR(\"-nopad\\t\\t\\tdo not pad filesystem to a multiple of 4K\\n\");\n\t\t\tERROR(\"-check_data\\t\\tadd checkdata for greater filesystem checks\\n\");\n\t\t\tERROR(\"-root-owned\\t\\talternative name for -all-root\\n\");\n\t\t\tERROR(\"-noInodeCompression\\talternative name for -noI\\n\");\n\t\t\tERROR(\"-noDataCompression\\talternative name for -noD\\n\");\n\t\t\tERROR(\"-noFragmentCompression\\talternative name for -noF\\n\");\n\t\t\tERROR(\"-sort <sort_file>\\tsort files according to priorities in <sort_file>.  One\\n\");\n\t\t\tERROR(\"\\t\\t\\tfile or dir with priority per line.  Priority -32768 to\\n\");\n\t\t\tERROR(\"\\t\\t\\t32767, default priority 0\\n\");\n\t\t\tERROR(\"-ef <exclude_file>\\tlist of exclude dirs/files.  One per line\\n\");\n\t\t\t#ifdef _LZMA_PARAMS\n\t\t\tERROR(\"-fb x\\t\\t\\tset lzma fast bytes to x (5-272)\\n\");\t\t\t\n\t\t\tERROR(\"-lc x\\t\\t\\tset lzma literal context bits to x (0-8)\\n\");\n\t\t\tERROR(\"-lp x\\t\\t\\tset lzma literal pos bits to x (0-4)\\n\");\n\t\t\tERROR(\"-pb x\\t\\t\\tset lzma pos bits to x (0-4)\\n\");\n\t\t\t#endif\t\t\t\n\t\t\texit(1);\n\t\t}\n\t}\n\n        for(i = 0; i < source; i++)\n                if(stat(source_path[i], &source_buf) == -1) {\n                        fprintf(stderr, \"Cannot stat source directory \\\"%s\\\" because %s\\n\", source_path[i], strerror(errno));\n                        EXIT_MKSQUASHFS();\n                }\n\n\tdestination_file = argv[source + 1];\n\tif(stat(argv[source + 1], &buf) == -1) {\n\t\tif(errno == ENOENT) { /* Does not exist */\n\t\t\tif((fd = open(argv[source + 1], O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) == -1) {\n\t\t\t\tperror(\"Could not create destination file\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tdelete = TRUE;\n\t\t} else {\n\t\t\tperror(\"Could not stat destination file\");\n\t\t\texit(1);\n\t\t}\n\n\t} else {\n\t\tif(S_ISBLK(buf.st_mode)) {\n\t\t\tif((fd = open(argv[source + 1], O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open block device as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t\tblock_device = 1;\n\n\t\t} else if(S_ISREG(buf.st_mode))\t {\n\t\t\tif((fd = open(argv[source + 1], (delete ? O_TRUNC : 0) | O_RDWR)) == -1) {\n\t\t\t\tperror(\"Could not open regular file for writing as destination\");\n\t\t\t\texit(1);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tERROR(\"Destination not block device or regular file\\n\");\n\t\t\texit(1);\n\t\t}\n\n\t}\n\n\tif(!delete) {\n\t        if(read_super(fd, &sBlk, &orig_be, argv[source + 1]) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t} else  {\n\t\tsignal(SIGTERM, sighandler2);\n\t\tsignal(SIGINT, sighandler2);\n\t}\n\n\t/* process the exclude files - must be done afer destination file has been possibly created */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-ef\") == 0) {\n\t\t\tFILE *fd;\n\t\t\tchar filename[16385];\n\t\t\tif((fd = fopen(argv[++i], \"r\")) == NULL) {\n\t\t\t\tperror(\"Could not open exclude file...\");\n\t\t\t\tEXIT_MKSQUASHFS();\n\t\t\t}\n\t\t\twhile(fscanf(fd, \"%16384[^\\n]\\n\", filename) != EOF)\n\t\t\t\tadd_exclude(filename);\n\t\t\tfclose(fd);\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-sort\") == 0)\n\t\t\ti++;\n\n\tif(i != argc) {\n\t\tif(++i == argc) {\n\t\t\tERROR(\"%s: -e missing arguments\\n\", argv[0]);\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\twhile(i < argc && add_exclude(argv[i++]));\n\t}\n\n\t/* process the sort files - must be done afer the exclude files  */\n\tfor(i = source + 2; i < argc; i++)\n\t\tif(strcmp(argv[i], \"-sort\") == 0) {\n\t\t\tread_sort_file(argv[++i], source, source_path);\n\t\t\tsorted ++;\n\t\t} else if(strcmp(argv[i], \"-e\") == 0)\n\t\t\tbreak;\n\t\telse if(strcmp(argv[i], \"-b\") == 0 || strcmp(argv[i], \"-root-becomes\") == 0 || strcmp(argv[i], \"-ef\") == 0)\n\t\t\ti++;\n\n\tif(delete) {\n\t\tprintf(\"Creating %s %d.%d filesystem on %s, block size %d.\\n\",\n\t\t\t\tbe ? \"big endian\" : \"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tbytes = sizeof(squashfs_super_block);\n\t} else {\n\t\tunsigned int last_directory_block, inode_dir_offset, inode_dir_file_size, root_inode_size,\n\t\tinode_dir_start_block, uncompressed_data, compressed_data, inode_dir_inode_number,\n\t\tinode_dir_parent_inode;\n\t\tunsigned int root_inode_start = SQUASHFS_INODE_BLK(sBlk.root_inode), root_inode_offset =\n\t\tSQUASHFS_INODE_OFFSET(sBlk.root_inode);\n\n\t\tbe = orig_be;\n\t\tblock_log = slog(block_size = sBlk.block_size);\n\t\tnoI = SQUASHFS_UNCOMPRESSED_INODES(sBlk.flags);\n\t\tnoD = SQUASHFS_UNCOMPRESSED_DATA(sBlk.flags);\n\t\tnoF = SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk.flags);\n\t\tcheck_data = SQUASHFS_CHECK_DATA(sBlk.flags);\n\t\tno_fragments = SQUASHFS_NO_FRAGMENTS(sBlk.flags);\n\t\talways_use_fragments = SQUASHFS_ALWAYS_FRAGMENTS(sBlk.flags);\n\t\tduplicate_checking = SQUASHFS_DUPLICATES(sBlk.flags);\n\t\t\n\t\tif((bytes = read_filesystem(root_name, fd, &sBlk, &inode_table, &data_cache,\n\t\t\t\t&directory_table, &directory_data_cache, &last_directory_block, &inode_dir_offset,\n\t\t\t\t&inode_dir_file_size, &root_inode_size, &inode_dir_start_block,\n\t\t\t\t&file_count, &sym_count, &dev_count, &dir_count, &fifo_count, &sock_count,\n\t\t\t\t(squashfs_uid *) uids, &uid_count, (squashfs_uid *) guids, &guid_count,\n\t\t\t\t&total_bytes, &total_inode_bytes, &total_directory_bytes, &inode_dir_inode_number,\n\t\t\t\t&inode_dir_parent_inode, add_old_root_entry, &fragment_table)) == 0) {\n\t\t\tERROR(\"Failed to read existing filesystem - will not overwrite - ABORTING!\\n\");\n\t\t\tEXIT_MKSQUASHFS();\n\t\t}\n\t\tif((fragments = sBlk.fragments))\n\t\t\tfragment_table = (squashfs_fragment_entry *) realloc((char *) fragment_table, ((fragments + FRAG_SIZE - 1) & ~(FRAG_SIZE - 1)) * sizeof(squashfs_fragment_entry)); \n\n\t\tprintf(\"Appending to existing %s %d.%d filesystem on %s, block size %d\\n\", be ? \"big endian\" :\n\t\t\t\"little endian\", SQUASHFS_MAJOR, SQUASHFS_MINOR, argv[source + 1], block_size);\n\t\tprintf(\"All -be, -le, -b, -noI, -noD, -noF, -check_data, no-duplicates, no-fragments, -always-use-fragments and -2.0 options ignored\\n\");\n\t\tprintf(\"\\nIf appending is not wanted, please re-run with -noappend specified!\\n\\n\");\n\n\t\tcompressed_data = inode_dir_offset + inode_dir_file_size & ~(SQUASHFS_METADATA_SIZE - 1);\n\t\tuncompressed_data = inode_dir_offset + inode_dir_file_size & (SQUASHFS_METADATA_SIZE - 1);\n\t\t\n\t\t/* save original filesystem state for restoring ... */\n\t\tsfragments = fragments;\n\t\tsbytes = bytes;\n\t\tsinode_count = sBlk.inodes;\n\t\tsdata_cache = (char *)malloc(scache_bytes = root_inode_offset + root_inode_size);\n\t\tsdirectory_data_cache = (char *)malloc(sdirectory_cache_bytes = uncompressed_data);\n\t\tmemcpy(sdata_cache, data_cache, scache_bytes);\n\t\tmemcpy(sdirectory_data_cache, directory_data_cache + compressed_data, sdirectory_cache_bytes);\n\t\tsinode_bytes = root_inode_start;\n\t\tsdirectory_bytes = last_directory_block;\n\t\tsuid_count = uid_count;\n\t\tsguid_count = guid_count;\n\t\tstotal_bytes = total_bytes;\n\t\tstotal_inode_bytes = total_inode_bytes;\n\t\tstotal_directory_bytes = total_directory_bytes + compressed_data;\n\t\tsfile_count = file_count;\n\t\tssym_count = sym_count;\n\t\tsdev_count = dev_count;\n\t\tsdir_count = dir_count + 1;\n\t\tsfifo_count = fifo_count;\n\t\tssock_count = sock_count;\n\t\tsdup_files = dup_files;\n\t\trestore = TRUE;\n\t\tif(setjmp(env))\n\t\t\tgoto restore_filesystem;\n\t\tsignal(SIGTERM, sighandler);\n\t\tsignal(SIGINT, sighandler);\n\t\twrite_bytes(fd, SQUASHFS_START, 4, \"\\0\\0\\0\\0\");\n\n\t\t/* set the filesystem state up to be able to append to the original filesystem.  The filesystem state\n\t\t * differs depending on whether we're appending to the original root directory, or if the original\n\t\t * root directory becomes a sub-directory (root-becomes specified on command line, here root_name != NULL)\n\t\t */\n\t\tinode_bytes = inode_size = root_inode_start;\n\t\tdirectory_size = last_directory_block;\n\t\tcache_size = root_inode_offset + root_inode_size;\n\t\tdirectory_cache_size = inode_dir_offset + inode_dir_file_size;\n\t\tif(root_name) {\n\t\t\troot_inode_number = inode_dir_parent_inode;\n\t\t\tdir_inode_no = sBlk.inodes + 2;\n\t\t\tdirectory_bytes = last_directory_block;\n\t\t\tdirectory_cache_bytes = uncompressed_data;\n\t\t\tmemmove(directory_data_cache, directory_data_cache + compressed_data, uncompressed_data);\n\t\t\tcache_bytes = root_inode_offset + root_inode_size;\n\t\t\tadd_old_root_entry(root_name, sBlk.root_inode, inode_dir_inode_number, SQUASHFS_DIR_TYPE);\n\t\t\ttotal_directory_bytes += compressed_data;\n\t\t\tdir_count ++;\n\t\t} else {\n\t\t\troot_inode_number = inode_dir_inode_number;\n\t\t\tdir_inode_no = sBlk.inodes + 1;\n\t\t\tdirectory_bytes = inode_dir_start_block;\n\t\t\tdirectory_cache_bytes = inode_dir_offset;\n\t\t\tcache_bytes = root_inode_offset;\n\t\t}\n\n\t\tinode_count = file_count + dir_count + sym_count + dev_count + fifo_count + sock_count;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tswap = !be;\n#else\n\tswap = be;\n#endif\n\n\tblock_offset = check_data ? 3 : 2;\n\n\tif(delete && !keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_readdir);\n\telse if(!keep_as_directory && source == 1 && S_ISDIR(source_buf.st_mode))\n\t\tdir_scan(&inode, source_path[0], scan1_single_readdir);\n\telse\n\t\tdir_scan(&inode, \"\", scan1_encomp_readdir);\n\tsBlk.root_inode = inode;\n\tsBlk.inodes = inode_count;\n\tsBlk.s_magic = SQUASHFS_MAGIC;\n\tsBlk.s_major = SQUASHFS_MAJOR;\n\tsBlk.s_minor = SQUASHFS_MINOR;\n\tsBlk.block_size = block_size;\n\tsBlk.block_log = block_log;\n\tsBlk.flags = SQUASHFS_MKFLAGS(noI, noD, check_data, noF, no_fragments, always_use_fragments, duplicate_checking);\n\tsBlk.mkfs_time = time(NULL);\n\nrestore_filesystem:\n\twrite_fragment();\n\tsBlk.fragments = fragments;\n\tsBlk.inode_table_start = write_inodes();\n\tsBlk.directory_table_start = write_directories();\n\tsBlk.fragment_table_start = write_fragment_table();\n\n\tTRACE(\"sBlk->inode_table_start 0x%x\\n\", sBlk.inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%x\\n\", sBlk.directory_table_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%x\\n\", sBlk.fragment_table_start);\n\n\tif(sBlk.no_uids = uid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[uid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, uid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, uid_count * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t}\n\t\tsBlk.uid_start = bytes;\n\t\tbytes += uid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.uid_start = 0;\n\n\tif(sBlk.no_guids = guid_count) {\n\t\tif(!swap)\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[guid_count];\n\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, guid_count, sizeof(squashfs_uid) * 8);\n\t\t\twrite_bytes(fd, bytes, guid_count * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t}\n\t\tsBlk.guid_start = bytes;\n\t\tbytes += guid_count * sizeof(squashfs_uid);\n\t} else\n\t\tsBlk.guid_start = 0;\n\n\tsBlk.bytes_used = bytes;\n\n\tsBlk.unused = SQUASHFS_INVALID_BLK;\n\n\tif(!swap)\n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk);\n\telse {\n\t\tsquashfs_super_block sBlk_copy;\n\n\t\tSQUASHFS_SWAP_SUPER_BLOCK((&sBlk), &sBlk_copy); \n\t\twrite_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) &sBlk_copy);\n\t}\n\n\tif(!nopad && (i = bytes & (4096 - 1))) {\n\t\tchar temp[4096] = {0};\n\t\twrite_bytes(fd, bytes, 4096 - i, temp);\n\t}\n\n\ttotal_bytes += total_inode_bytes + total_directory_bytes + uid_count\n\t\t* sizeof(unsigned short) + guid_count * sizeof(unsigned short) +\n\t\tsizeof(squashfs_super_block);\n\n\tprintf(\"\\n%s filesystem, data block size %d, %s data, %s metadata, %s fragments\\n\", be ?\n\t\t\"Big endian\" : \"Little endian\", block_size, noD ? \"uncompressed\" : \"compressed\", noI ?\n\t\"uncompressed\" : \"compressed\", no_fragments ? \"no\" : noF ? \"uncompressed\" : \"compressed\");\n\tprintf(\"Filesystem size %.2f Kbytes (%.2f Mbytes)\\n\", bytes / 1024.0, bytes / (1024.0 * 1024.0));\n\tprintf(\"\\t%.2f%% of uncompressed filesystem size (%.2f Kbytes)\\n\",\n\t\t((float) bytes / total_bytes) * 100.0, total_bytes / 1024.0);\n\tprintf(\"Inode table size %d bytes (%.2f Kbytes)\\n\",\n\t\tinode_bytes, inode_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed inode table size (%d bytes)\\n\",\n\t\t((float) inode_bytes / total_inode_bytes) * 100.0, total_inode_bytes);\n\tprintf(\"Directory table size %d bytes (%.2f Kbytes)\\n\",\n\t\tdirectory_bytes, directory_bytes / 1024.0);\n\tprintf(\"\\t%.2f%% of uncompressed directory table size (%d bytes)\\n\",\n\t\t((float) directory_bytes / total_directory_bytes) * 100.0, total_directory_bytes);\n\tif(duplicate_checking)\n\t\tprintf(\"Number of duplicate files found %d\\n\", file_count - dup_files);\n\telse\n\t\tprintf(\"No duplicate files removed\\n\");\n\tprintf(\"Number of inodes %d\\n\", inode_count);\n\tprintf(\"Number of files %d\\n\", file_count);\n\tif(!no_fragments)\n\t\tprintf(\"Number of fragments %d\\n\", fragments);\n\tprintf(\"Number of symbolic links  %d\\n\", sym_count);\n\tprintf(\"Number of device nodes %d\\n\", dev_count);\n\tprintf(\"Number of fifo nodes %d\\n\", fifo_count);\n\tprintf(\"Number of socket nodes %d\\n\", sock_count);\n\tprintf(\"Number of directories %d\\n\", dir_count);\n\tprintf(\"Number of uids %d\\n\", uid_count);\n\n\tfor(i = 0; i < uid_count; i++) {\n\t\tstruct passwd *user = getpwuid(uids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", user == NULL ? \"unknown\" : user->pw_name, uids[i]);\n\t}\n\n\tprintf(\"Number of gids %d\\n\", guid_count);\n\n\tfor(i = 0; i < guid_count; i++) {\n\t\tstruct group *group = getgrgid(guids[i]);\n\t\tprintf(\"\\t%s (%d)\\n\", group == NULL ? \"unknown\" : group->gr_name, guids[i]);\n\t}\n\tclose(fd);\n\treturn 0;\n}\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/mksquashfs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.demon.co.uK>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = (long long) value << (SHIFT);\\\n\tunsigned char *s = ((unsigned char *) &val) + 7;\\\n\tunsigned char *d = ((unsigned char *)p) + (pos / 8);\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d++ |= *s--;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(d, 0, n);\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/read_fs.c",
    "content": "/*\n * Read a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * read_fs.c\n */\n\nextern void read_bytes(int, long long, int, char *);\nextern int add_file(long long, long long, unsigned int *, int, unsigned int, int, int);\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\nint swap;\n\nint read_block(int fd, long long start, long long *next, unsigned char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tread_bytes(fd, start, 2, (char *) block);\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tread_bytes(fd, start, 2, (char *)&c_byte);\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, buffer);\n\n\t\tif((res = uncompress(block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tread_bytes(fd, start + offset, c_byte, (char *) block);\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n}\n\n\nint scan_inode_table(int fd, long long start, long long end, long long root_inode_start, int root_inode_offset,\n\t\tsquashfs_super_block *sBlk,\n\t\tsquashfs_inode_header *dir_inode, unsigned char **inode_table, unsigned int *root_inode_block,\n\t\tunsigned int *root_inode_size, long long *uncompressed_file, unsigned int *uncompressed_directory,\n\t\tint *file_count, int *sym_count, int *dev_count, int *dir_count, int *fifo_count, int *sock_count)\n{\n\tunsigned char *cur_ptr;\n\tint byte, bytes = 0, size = 0, files = 0;\n\tsquashfs_reg_inode_header inode;\n\tunsigned int directory_start_block;\n\n\tTRACE(\"scan_inode_table: start 0x%llx, end 0x%llx, root_inode_start 0x%llx\\n\", start, end, root_inode_start);\n\twhile(start < end) {\n\t\tif(start == root_inode_start) {\n\t\t\tTRACE(\"scan_inode_table: read compressed block 0x%llx containing root inode\\n\", start);\n\t\t\t*root_inode_block = bytes;\n\t\t}\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((*inode_table = realloc(*inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\treturn FALSE;\n\t\tTRACE(\"scan_inode_table: reading block 0x%llx\\n\", start);\n\t\tif((byte = read_block(fd, start, &start, *inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(*inode_table);\n\t\t\treturn FALSE;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\t/*\n\t * Read last inode entry which is the root directory inode, and obtain the last\n\t * directory start block index.  This is used when calculating the total uncompressed\n\t * directory size.  The directory bytes in the last block will be counted as normal.\n\t *\n\t * The root inode is ignored in the inode scan.  This ensures there is\n\t * always enough bytes left to read a regular file inode entry\n\t */\n\t*root_inode_size = bytes - (*root_inode_block + root_inode_offset);\n\tbytes = *root_inode_block + root_inode_offset;\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&dir_inode->base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&dir_inode->base, *inode_table + bytes, sizeof(dir_inode->base));\n\tif(dir_inode->base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\tif(swap) {\n\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode->dir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->dir, *inode_table + bytes, sizeof(dir_inode->dir));\n\t\tdirectory_start_block = dir_inode->dir.start_block;\n\t} else {\n\t\tif(swap) {\n\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\tmemcpy(&sinode, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode->ldir, &sinode);\n\t\t} else\n\t\t\tmemcpy(&dir_inode->ldir, *inode_table + bytes, sizeof(dir_inode->ldir));\n\t\tdirectory_start_block = dir_inode->ldir.start_block;\n\t}\n\n\tfor(cur_ptr = *inode_table; cur_ptr < *inode_table + bytes; files ++) {\n\t\tif(swap) {\n\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\tmemcpy(&sinode, cur_ptr, sizeof(inode));\n\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(&inode, &sinode);\n\t\t} else\n\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\tTRACE(\"scan_inode_table: processing inode @ byte position 0x%x, type 0x%x\\n\", cur_ptr - *inode_table,\n\t\t\t\tinode.inode_type);\n\t\tswitch(inode.inode_type) {\n\t\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\t\tint frag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tint blocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i, start = inode.start_block;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tTRACE(\"scan_inode_table: regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\t\tsquashfs_lreg_inode_header inode;\n\t\t\t\tint frag_bytes;\n\t\t\t\tint blocks;\n\t\t\t\tlong long file_bytes = 0;\n\t\t\t\tint i, start;\n\t\t\t\tunsigned int *block_list;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_lreg_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(&inode, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inode, cur_ptr, sizeof(inode));\n\n\t\t\t\tTRACE(\"scan_inode_table: extended regular file, file_size %lld, blocks %d\\n\", inode.file_size, blocks);\n\n\t\t\t\tcur_ptr += sizeof(inode);\n\t\t\t\tfrag_bytes = inode.fragment == SQUASHFS_INVALID_FRAG ? 0 : inode.file_size % sBlk->block_size;\n\t\t\t\tblocks = inode.fragment == SQUASHFS_INVALID_FRAG ? (inode.file_size\n\t\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode.file_size >>\n\t\t\t\t\tsBlk->block_log;\n\t\t\t\tstart = inode.start_block;\n\n\t\t\t\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\t\t\t\tERROR(\"Out of memory in block list malloc\\n\");\n\t\t\t\t\tgoto failed;\n\t\t\t\t}\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tunsigned int sblock_list[blocks];\n\t\t\t\t\tmemcpy(sblock_list, cur_ptr, blocks * sizeof(unsigned int));\n\t\t\t\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(block_list, cur_ptr, blocks * sizeof(unsigned int));\n\n\t\t\t\t*uncompressed_file += inode.file_size;\n\t\t\t\t(*file_count) ++;\n\n\t\t\t\tfor(i = 0; i < blocks; i++)\n\t\t\t\t\tfile_bytes += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\n\t                        add_file(start, file_bytes, block_list, blocks, inode.fragment, inode.offset, frag_bytes);\n\t\t\t\tcur_ptr += blocks * sizeof(unsigned int);\n\t\t\t\tbreak;\n\t\t\t}\t\n\t\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\t\tsquashfs_symlink_inode_header inodep;\n\t\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\t\tmemcpy(&sinodep, cur_ptr, sizeof(sinodep));\n\t\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&inodep, cur_ptr, sizeof(inodep));\n\t\t\t\t(*sym_count) ++;\n\t\t\t\tcur_ptr += sizeof(inodep) + inodep.symlink_size;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_DIR_TYPE: {\n\t\t\t\tsquashfs_dir_inode_header dir_inode;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_dir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dir_inode_header);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SQUASHFS_LDIR_TYPE: {\n\t\t\t\tsquashfs_ldir_inode_header dir_inode;\n\t\t\t\tint i;\n\n\t\t\t\tif(swap) {\n\t\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\t\tmemcpy(&sinode, cur_ptr, sizeof(dir_inode));\n\t\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&dir_inode, &sinode);\n\t\t\t\t} else\n\t\t\t\t\tmemcpy(&dir_inode, cur_ptr, sizeof(dir_inode));\n\t\t\t\tif(dir_inode.start_block < directory_start_block)\n\t\t\t\t\t*uncompressed_directory += dir_inode.file_size;\n\t\t\t\t(*dir_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ldir_inode_header);\n\t\t\t\tfor(i = 0; i < dir_inode.i_count; i++) {\n\t\t\t\t\tsquashfs_dir_index index;\n\t\t\t\t\tif(swap) {\n\t\t\t\t\t\tsquashfs_dir_index sindex;\n\t\t\t\t\t\tmemcpy(&sindex, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\t\tSQUASHFS_SWAP_DIR_INDEX(&index, &sindex);\n\t\t\t\t\t} else\n\t\t\t\t\t\tmemcpy(&index, cur_ptr, sizeof(squashfs_dir_index));\n\t\t\t\t\tcur_ptr += sizeof(squashfs_dir_index) + index.size + 1;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t \tcase SQUASHFS_BLKDEV_TYPE:\n\t\t \tcase SQUASHFS_CHRDEV_TYPE:\n\t\t\t\t(*dev_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_dev_inode_header);\n\t\t\t\tbreak;\n\n\t\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\t\t(*fifo_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\t\t(*sock_count) ++;\n\t\t\t\tcur_ptr += sizeof(squashfs_ipc_inode_header);\n\t\t\t\tbreak;\n\t\t \tdefault:\n\t\t\t\tERROR(\"Unknown inode type %d in scan_inode_table!\\n\", inode.inode_type);\n\t\t\t\tgoto failed;\n\t\t}\n\t}\n\t\n\treturn files;\n\n\nfailed:\n\tfree(*inode_table);\n\treturn FALSE;\n}\n\n\nint read_super(int fd, squashfs_super_block *sBlk, int *be, char *source)\n{\n\tread_bytes(fd, SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s - ignoring -le/-be options\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tif(sBlk->s_major < 3)\n\t\t\tERROR(\"Filesystem on %s is a SQUASHFS %d.%d filesystem.  Appending\\nto SQUASHFS %d.%d filesystems is not supported.  Please convert it to a SQUASHFS 3.0 filesystem\\n\", source, sBlk->s_major, sBlk->s_minor, sBlk->s_major, sBlk->s_minor);\n\t\telse\n\t\t\tERROR(\"Major/Minor mismatch, filesystem on %s is %d.%d, I support 3.0\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t*be = !swap;\n#else\n\t*be = swap;\n#endif\n\n\tprintf(\"Found a valid SQUASHFS superblock on %s.\\n\", source);\n\tprintf(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tprintf(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not\" : \"\");\n\tprintf(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not\");\n\tprintf(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tprintf(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tprintf(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tprintf(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tprintf(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tprintf(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start %llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start %llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start %llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start %llx\\n\", sBlk->fragment_table_start);\n\tprintf(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\nunsigned char *squashfs_readdir(int fd, int root_entries, unsigned int directory_start_block, int offset, int size,\n\t\tunsigned int *last_directory_block, squashfs_super_block *sBlk, void (push_directory_entry)(char *, squashfs_inode, int, int))\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tunsigned char *directory_table = NULL;\n\tint byte, bytes = 0, dir_count;\n\tlong long start = sBlk->directory_table_start + directory_start_block, last_start_block; \n\n\tsize += offset;\n\tif((directory_table = malloc((size + SQUASHFS_METADATA_SIZE * 2 - 1) & ~(SQUASHFS_METADATA_SIZE - 1))) == NULL)\n\t\treturn NULL;\n\twhile(bytes < size) {\n\t\tTRACE(\"squashfs_readdir: reading block 0x%llx, bytes read so far %d\\n\", start, bytes);\n\t\tlast_start_block = start;\n\t\tif((byte = read_block(fd, start, &start, directory_table + bytes, sBlk)) == 0) {\n\t\t\tfree(directory_table);\n\t\t\treturn NULL;\n\t\t}\n\t\tbytes += byte;\n\t}\n\n\tif(!root_entries)\n\t\tgoto all_done;\n\n\tbytes = offset;\n \twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_readdir: Read directory header @ byte position 0x%x, 0x%x directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_readdir: pushing directory entry %s, inode %x:%x, type 0x%x\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tpush_directory_entry(dire->name, SQUASHFS_MKINODE(dirh.start_block, dire->offset), dire->inode_number, dire->type);\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\nall_done:\n\t*last_directory_block = (unsigned int) last_start_block - sBlk->directory_table_start;\n\treturn directory_table;\n}\n\n\nint read_fragment_table(int fd, squashfs_super_block *sBlk, squashfs_fragment_entry **fragment_table)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn 1;\n\n\tif((*fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL) {\n\t\tERROR(\"Failed to allocate fragment table\\n\");\n\t\treturn 0;\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(fd, sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fd, fragment_table_index[i], NULL, ((unsigned char *) *fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&(*fragment_table)[i]));\n\t\t\tmemcpy((char *) &(*fragment_table)[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n\n\treturn 1;\n}\n\n\nlong long read_filesystem(char *root_name, int fd, squashfs_super_block *sBlk, char **cinode_table,\n\t\tchar **data_cache, char **cdirectory_table, char **directory_data_cache,\n\t\tunsigned int *last_directory_block, unsigned int *inode_dir_offset, unsigned int *inode_dir_file_size,\n\t\tunsigned int *root_inode_size, unsigned int *inode_dir_start_block, int *file_count, int *sym_count,\n\t\tint *dev_count, int *dir_count, int *fifo_count, int *sock_count, squashfs_uid *uids,\n\t\tunsigned short *uid_count, squashfs_uid *guids, unsigned short *guid_count,\n\t\tlong long *uncompressed_file, unsigned int *uncompressed_inode, unsigned int *uncompressed_directory,\n\t\tunsigned int *inode_dir_inode_number, unsigned int *inode_dir_parent_inode,\n\t\tvoid (push_directory_entry)(char *, squashfs_inode, int, int), squashfs_fragment_entry **fragment_table)\n{\n\tunsigned char *inode_table = NULL, *directory_table;\n\tlong long start = sBlk->inode_table_start, end = sBlk->directory_table_start, root_inode_start = start +\n\t\tSQUASHFS_INODE_BLK(sBlk->root_inode);\n\tunsigned int root_inode_offset = SQUASHFS_INODE_OFFSET(sBlk->root_inode), root_inode_block, files;\n\tsquashfs_inode_header inode;\n\n\tprintf(\"Scanning existing filesystem...\\n\");\n\n\tif(read_fragment_table(fd, sBlk, fragment_table) == 0)\n\t\tgoto error;\n\n\tif((files = scan_inode_table(fd, start, end, root_inode_start, root_inode_offset, sBlk, &inode, &inode_table,\n\t\t\t&root_inode_block, root_inode_size, uncompressed_file, uncompressed_directory, file_count, sym_count,\n\t\t\tdev_count, dir_count, fifo_count, sock_count)) == 0) {\n\t\tERROR(\"read_filesystem: inode table read failed\\n\");\n\t\tgoto error;\n\t}\n\n\t*uncompressed_inode = root_inode_block;\n\n\tprintf(\"Read existing filesystem, %d inodes scanned\\n\", files);\n\n\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE || inode.base.inode_type == SQUASHFS_LDIR_TYPE) {\n\t\tif(inode.base.inode_type == SQUASHFS_DIR_TYPE) {\n\t\t\t*inode_dir_start_block = inode.dir.start_block;\n\t\t\t*inode_dir_offset = inode.dir.offset;\n\t\t\t*inode_dir_file_size = inode.dir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.dir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.dir.parent_inode;\n\t\t} else {\n\t\t\t*inode_dir_start_block = inode.ldir.start_block;\n\t\t\t*inode_dir_offset = inode.ldir.offset;\n\t\t\t*inode_dir_file_size = inode.ldir.file_size - 3;\n\t\t\t*inode_dir_inode_number = inode.ldir.inode_number;\n\t\t\t*inode_dir_parent_inode = inode.ldir.parent_inode;\n\t\t}\n\n\t\tif((directory_table = squashfs_readdir(fd, !root_name, *inode_dir_start_block, *inode_dir_offset,\n\t\t\t\t*inode_dir_file_size, last_directory_block, sBlk, push_directory_entry)) == NULL) {\n\t\t\tERROR(\"read_filesystem: Could not read root directory\\n\");\n\t\t\tgoto error;\n\t\t}\n\n\t\troot_inode_start -= start;\n\t\tif((*cinode_table = (char *) malloc(root_inode_start)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem inode table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t       \tread_bytes(fd, start, root_inode_start, *cinode_table);\n\n\t\tif((*cdirectory_table = (char *) malloc(*last_directory_block)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc space for existing filesystem directory table\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tread_bytes(fd, sBlk->directory_table_start, *last_directory_block, *cdirectory_table);\n\n\t\tif((*data_cache = (char *) malloc(root_inode_offset + *root_inode_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc inode cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*data_cache, inode_table + root_inode_block, root_inode_offset + *root_inode_size);\n\n\t\tif((*directory_data_cache = (char *) malloc(*inode_dir_offset + *inode_dir_file_size)) == NULL) {\n\t\t\tERROR(\"read_filesystem: failed to alloc directory cache\\n\");\n\t\t\tgoto error;\n\t\t}\n\t\tmemcpy(*directory_data_cache, directory_table, *inode_dir_offset + *inode_dir_file_size);\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids);\n\t\telse {\n\t\t\tsquashfs_uid uids_copy[sBlk->no_uids];\n\n\t\t\tread_bytes(fd, sBlk->uid_start, sBlk->no_uids * sizeof(squashfs_uid), (char *) uids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(uids, uids_copy, sBlk->no_uids, sizeof(squashfs_uid) * 8);\n\t\t}\n\n\t\tif(!swap)\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids);\n\t\telse {\n\t\t\tsquashfs_uid guids_copy[sBlk->no_guids];\n\n\t\t\tread_bytes(fd, sBlk->guid_start, sBlk->no_guids * sizeof(squashfs_uid), (char *) guids_copy);\n\t\t\tSQUASHFS_SWAP_DATA(guids, guids_copy, sBlk->no_guids, sizeof(squashfs_uid) * 8);\n\t\t}\n\t\t*uid_count = sBlk->no_uids;\n\t\t*guid_count = sBlk->no_guids;\n\n\t\tfree(inode_table);\n\t\tfree(directory_table);\n\t\treturn sBlk->inode_table_start;\n\t}\n\nerror:\n\treturn 0;\n}\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/read_fs.h",
    "content": "/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating a filesystem on a\n * machine with different byte ordering to the target architecture.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * mksquashfs.h\n *\n */\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing architectures\n */\n#if __BYTE_ORDER == __BIG_ENDIAN\n\t/* convert from big endian to little endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)\n#else\n\t/* convert from little endian to big endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tint bits;\\\n\tint b_pos = pos % 8;\\\n\tunsigned long long val = 0;\\\n\tunsigned char *s = (unsigned char *)p + (pos / 8);\\\n\tunsigned char *d = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/sort.c",
    "content": "/*\n * Create a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.c\n */\n\n#define TRUE 1\n#define FALSE 0\n\n#include <unistd.h>\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <dirent.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include <squashfs_fs.h>\n#include \"global.h\"\n#include \"sort.h\"\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define INFO(s, args...)\t\tdo { \\\n\t\t\t\t\t\tif(!silent) printf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n#define EXIT_MKSQUASHFS()\t\tdo { \\\n\t\t\t\t\t\texit(1); \\\n\t\t\t\t\t} while(0)\n#define BAD_ERROR(s, args...)\t\tdo {\\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR:\" s, ##args);\\\n\t\t\t\t\t\tEXIT_MKSQUASHFS();\\\n\t\t\t\t\t} while(0);\n\nint mkisofs_style = -1;\n\nstruct sort_info {\n\tdev_t\t\t\tst_dev;\n\tino_t\t\t\tst_ino;\n\tint\t\t\tpriority;\n\tstruct sort_info\t*next;\n};\n\nstruct sort_info *sort_info_list[65536];\n\nstruct priority_entry {\n\tstruct dir_ent *dir;\n\tstruct priority_entry *next;\n};\n\nstruct priority_entry *priority_list[65536];\n\nextern int silent;\nextern squashfs_inode write_file(squashfs_inode *inode, struct dir_ent *dir_ent, long long size, int *c_size);\n\n\nint add_priority_list(struct dir_ent *dir, int priority)\n{\n\tstruct priority_entry *new_priority_entry;\n\n\tpriority += 32768;\n\tif((new_priority_entry = malloc(sizeof(struct priority_entry))) == NULL) {\n\t\tERROR(\"Out of memory allocating priority entry\\n\");\n\t\treturn FALSE;\n\t}\n\n\tnew_priority_entry->dir = dir;;\n\tnew_priority_entry->next = priority_list[priority];\n\tpriority_list[priority] = new_priority_entry;\n\treturn TRUE;\n}\n\n\nint get_priority(char *filename, struct stat *buf, int priority)\n{\n\tint hash = buf->st_ino & 0xffff;\n\tstruct sort_info *s;\n\n\tfor(s = sort_info_list[hash]; s; s = s->next)\n\t\tif((s->st_dev == buf->st_dev) && (s->st_ino == buf->st_ino)) {\n\t\t\tTRACE(\"returning priority %d (%s)\\n\", s->priority, filename);\n\t\t\treturn s->priority;\n\t\t}\n\tTRACE(\"returning priority %d (%s)\\n\", priority, filename);\n\treturn priority;\n}\n\n\n#define ADD_ENTRY(buf, priority) {\\\n\tint hash = buf.st_ino & 0xffff;\\\n\tstruct sort_info *s;\\\n\tif((s = malloc(sizeof(struct sort_info))) == NULL) {\\\n\t\tERROR(\"Out of memory allocating sort list entry\\n\");\\\n\t\treturn FALSE;\\\n\t}\\\n\ts->st_dev = buf.st_dev;\\\n\ts->st_ino = buf.st_ino;\\\n\ts->priority = priority;\\\n\ts->next = sort_info_list[hash];\\\n\tsort_info_list[hash] = s;\\\n\t}\nint add_sort_list(char *path, int priority, int source, char *source_path[])\n{\n\tint i, n;\n\tchar filename[4096];\n\tstruct stat buf;\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\n\tif(strlen(path) > 1 && strcmp(path + strlen(path) - 2, \"/*\") == 0)\n\t\tpath[strlen(path) - 2] = '\\0';\n\n\tTRACE(\"add_sort_list: filename %s, priority %d\\n\", path, priority);\nre_read:\n\tif(path[0] == '/' || strncmp(path, \"./\", 2) == 0 || strncmp(path, \"../\", 3) == 0 || mkisofs_style == 1) {\n\t\tif(lstat(path, &buf) == -1)\n\t\t\tgoto error;\n\t\tTRACE(\"adding filename %s, priority %d, st_dev %llx, st_ino %llx\\n\", path, priority, buf.st_dev, buf.st_ino);\n\t\tADD_ENTRY(buf, priority);\n\t\treturn TRUE;\n\t}\n\n\tfor(i = 0, n = 0; i < source; i++) {\n\t\tstrcat(strcat(strcpy(filename, source_path[i]), \"/\"), path);\n\t\tif(lstat(filename, &buf) == -1) {\n\t\t\tif(!(errno == ENOENT || errno == ENOTDIR))\n\t\t\t\tgoto error;\n\t\t\tcontinue;\n\t\t}\n\t\tADD_ENTRY(buf, priority);\n\t\tn ++;\n\t}\n\n\tif(n == 0 && mkisofs_style == -1 && lstat(path, &buf) != -1) {\n\t\tERROR(\"WARNING: Mkisofs style sortlist detected! This is supported but please\\n\");\n\t\tERROR(\"convert to mksquashfs style sortlist! A sortlist entry \");\n\t        ERROR(\"should be\\neither absolute (starting with \");\n\t\tERROR(\"'/') start with './' or '../' (taken to be\\nrelative to $PWD), otherwise it \");\n\t\tERROR(\"is assumed the entry is relative to one\\nof the source directories, i.e. with \");\n\t\tERROR(\"\\\"mksquashfs test test.sqsh\\\",\\nthe sortlist \");\n\t\tERROR(\"entry \\\"file\\\" is assumed to be inside the directory test.\\n\\n\");\n\t\tmkisofs_style = 1;\n\t\tgoto re_read;\n\t}\n\n\tmkisofs_style = 0;\n\n\tif(n == 1)\n\t\treturn TRUE;\n\tif(n > 1)\n\t\tBAD_ERROR(\" Ambiguous sortlist entry \\\"%s\\\"\\n\\nIt maps to more than one source entry!  Please use an absolute path.\\n\", path);\n\nerror:\n        fprintf(stderr, \"Cannot stat sortlist entry \\\"%s\\\"\\n\", path);\n        fprintf(stderr, \"This is probably because you're using the wrong file\\n\");\n        fprintf(stderr, \"path relative to the source directories\\n\");\n        return FALSE;\n}\n\n\nvoid generate_file_priorities(struct dir_info *dir, int priority, struct stat *buf)\n{\n\tpriority = get_priority(dir->pathname, buf, priority);\n\n\twhile(dir->current_count < dir->count) {\n\t\tstruct dir_ent *dir_ent = dir->list[dir->current_count++];\n\t\tstruct stat *buf = &dir_ent->inode->buf;\n\t\tif(dir_ent->data)\n\t\t\tcontinue;\n\n\t\tswitch(buf->st_mode & S_IFMT) {\n\t\t\tcase S_IFREG:\n\t\t\t\tadd_priority_list(dir_ent, get_priority(dir_ent->pathname, buf, priority));\n\t\t\t\tbreak;\n\t\t\tcase S_IFDIR:\n\t\t\t\tgenerate_file_priorities(dir_ent->dir, priority, buf);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tdir->current_count = 0;\n}\n\n\nint read_sort_file(char *filename, int source, char *source_path[])\n{\n\tFILE *fd;\n\tchar sort_filename[16385];\n\tint priority;\n\n\tif((fd = fopen(filename, \"r\")) == NULL) {\n\t\tperror(\"Could not open sort_list file...\");\n\t\treturn FALSE;\n\t}\n\twhile(fscanf(fd, \"%s %d\", sort_filename, &priority) != EOF)\n\t\tif(priority >= -32768 && priority <= 32767)\n\t\t\tadd_sort_list(sort_filename, priority, source, source_path);\n\t\telse\n\t\t\tERROR(\"Sort file %s, priority %d outside range of -32767:32768 - skipping...\\n\", sort_filename, priority);\n\tfclose(fd);\n\treturn TRUE;\n}\n\n\nvoid sort_files_and_write(struct dir_info *dir)\n{\n\tint i;\n\tstruct priority_entry *entry;\n\tsquashfs_inode inode;\n\tint duplicate_file;\n\n\tgenerate_file_priorities(dir, 0, &dir->dir_ent->inode->buf);\n\n\tfor(i = 65535; i >= 0; i--)\n\t\tfor(entry = priority_list[i]; entry; entry = entry->next) {\n\t\t\tTRACE(\"%d: %s\\n\", i - 32768, entry->dir->pathname);\n\t\t\tif(entry->dir->inode->inode == SQUASHFS_INVALID_BLK) {\n\t\t\t\tif(write_file(&inode, entry->dir, entry->dir->inode->buf.st_size,\n\t\t\t\t\t\t\t&duplicate_file)) {\n\t\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes %s\\n\",\n\t\t\t\t\t\tentry->dir->pathname,\n\t\t\t\t\t\tentry->dir->inode->buf.st_size,\n\t\t\t\t\t\tduplicate_file ? \"DUPLICATE\" : \"\");\n\t\t\t\t\tentry->dir->inode->inode = inode;\n\t\t\t\t\tentry->dir->inode->type = SQUASHFS_FILE_TYPE;\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tINFO(\"file %s, uncompressed size %lld bytes LINK\\n\",\n\t\t\t\t\tentry->dir->pathname, entry->dir->inode->buf.st_size);\n\t\t}\n}\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/sort.h",
    "content": "#ifndef SORT_H \n#define SORT_H\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * sort.h\n */\n\nstruct dir_info {\n\tchar\t\t\t*pathname;\n\tunsigned int\t\tcount;\n\tunsigned int\t\tdirectory_count;\n\tunsigned int\t\tcurrent_count;\n\tunsigned int\t\tbyte_count;\n\tchar\t\t\tdir_is_ldir;\n\tstruct dir_ent\t\t*dir_ent;\n\tstruct dir_ent\t\t**list;\n\tDIR\t\t\t*linuxdir;\n};\n\nstruct dir_ent {\n\tchar\t\t\t*name;\n\tchar\t\t\t*pathname;\n\tstruct inode_info\t*inode;\n\tstruct dir_info\t\t*dir;\n\tstruct dir_info\t\t*our_dir;\n\tstruct old_root_entry_info *data;\n};\n\nstruct inode_info {\n\tunsigned int\t\tnlink;\n\tstruct stat\t\tbuf;\n\tsquashfs_inode\t\tinode;\n\tunsigned int\t\ttype;\n\tunsigned int\t\tinode_number;\n\tstruct inode_info\t*next;\n};\n#endif\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/squashfs_fs.h",
    "content": "#ifndef SQUASHFS_FS\n#define SQUASHFS_FS\n\n/*\n * Squashfs\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n * Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * squashfs_fs.h\n */\n\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x74717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737174\n#define SQUASHFS_START\t\t\t0\n\n/* size of metadata (inode and directory) blocks */\n#define SQUASHFS_METADATA_SIZE\t\t8192\n#define SQUASHFS_METADATA_LOG\t\t13\n\n/* default size of data blocks */\n#define SQUASHFS_FILE_SIZE\t\t131072\n#define SQUASHFS_FILE_LOG\t\t17\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t1048576\n\n/*#define SQUASHFS_FILE_SIZE\t\t65536\n#define SQUASHFS_FILE_LOG\t\t16\n\n#define SQUASHFS_FILE_MAX_SIZE\t\t65536\n*/\n\n/* Max number of uids and gids */\n#define SQUASHFS_UIDS\t\t\t256\n#define SQUASHFS_GUIDS\t\t\t255\n\n/* Max length of filename (not 255) */\n#define SQUASHFS_NAME_LEN\t\t256\n\n#define SQUASHFS_INVALID\t\t((long long) 0xffffffffffff)\n#define SQUASHFS_INVALID_FRAG\t\t((unsigned int) 0xffffffff)\n#define SQUASHFS_INVALID_BLK\t\t((long long) -1)\n#define SQUASHFS_USED_BLK\t\t((long long) -2)\n\n/* Filesystem flags */\n#define SQUASHFS_NOI\t\t\t0\n#define SQUASHFS_NOD\t\t\t1\n#define SQUASHFS_CHECK\t\t\t2\n#define SQUASHFS_NOF\t\t\t3\n#define SQUASHFS_NO_FRAG\t\t4\n#define SQUASHFS_ALWAYS_FRAG\t\t5\n#define SQUASHFS_DUPLICATE\t\t6\n\n#define SQUASHFS_BIT(flag, bit)\t\t((flag >> bit) & 1)\n\n#define SQUASHFS_UNCOMPRESSED_INODES(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOI)\n\n#define SQUASHFS_UNCOMPRESSED_DATA(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOD)\n\n#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NOF)\n\n#define SQUASHFS_NO_FRAGMENTS(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_NO_FRAG)\n\n#define SQUASHFS_ALWAYS_FRAGMENTS(flags)\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_ALWAYS_FRAG)\n\n#define SQUASHFS_DUPLICATES(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_DUPLICATE)\n\n#define SQUASHFS_CHECK_DATA(flags)\t\tSQUASHFS_BIT(flags, \\\n\t\t\t\t\t\tSQUASHFS_CHECK)\n\n#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \\\n\t\tduplicate_checking)\t(noi | (nod << 1) | (check_data << 2) \\\n\t\t| (nof << 3) | (no_frag << 4) | (always_frag << 5) | \\\n\t\t(duplicate_checking << 6))\n\n/* Max number of types and file types */\n#define SQUASHFS_DIR_TYPE\t\t1\n#define SQUASHFS_FILE_TYPE\t\t2\n#define SQUASHFS_SYMLINK_TYPE\t\t3\n#define SQUASHFS_BLKDEV_TYPE\t\t4\n#define SQUASHFS_CHRDEV_TYPE\t\t5\n#define SQUASHFS_FIFO_TYPE\t\t6\n#define SQUASHFS_SOCKET_TYPE\t\t7\n#define SQUASHFS_LDIR_TYPE\t\t8\n#define SQUASHFS_LREG_TYPE\t\t9\n\n/* 1.0 filesystem type definitions */\n#define SQUASHFS_TYPES\t\t\t5\n#define SQUASHFS_IPC_TYPE\t\t0\n\n/* Flag whether block is compressed or uncompressed, bit is set if block is\n * uncompressed */\n#define SQUASHFS_COMPRESSED_BIT\t\t(1 << 15)\n\n\n#define SQUASHFS_COMPRESSED_SIZE(B)\t(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \\\n\t\t(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)\n\n\n#define SQUASHFS_COMPRESSED(B)\t\t(!((B) & SQUASHFS_COMPRESSED_BIT))\n\n#define SQUASHFS_COMPRESSED_BIT_BLOCK\t\t(1 << 24)\n\n\n#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t((B) & \\\n\t~SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n\n//#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)\t(((B) & \\\n//\t~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \\\n//\t~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)\n\n#define SQUASHFS_COMPRESSED_BLOCK(B)\t(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))\n\n/*\n * Inode number ops.  Inodes consist of a compressed block number, and an\n * uncompressed  offset within that block\n */\n#define SQUASHFS_INODE_BLK(a)\t\t((unsigned int) ((a) >> 16))\n\n#define SQUASHFS_INODE_OFFSET(a)\t((unsigned int) ((a) & 0xffff))\n\n#define SQUASHFS_MKINODE(A, B)\t\t((squashfs_inode_t)(((squashfs_inode_t) (A)\\\n\t\t\t\t\t<< 16) + (B)))\n\n/* Compute 32 bit VFS inode number from squashfs inode number */\n#define SQUASHFS_MK_VFS_INODE(a, b)\t((unsigned int) (((a) << 8) + \\\n\t\t\t\t\t((b) >> 2) + 1))\n/* XXX */\n\n/* Translate between VFS mode and squashfs mode */\n#define SQUASHFS_MODE(a)\t\t((a) & 0xfff)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES(A)\t(A * sizeof(struct squashfs_fragment_entry))\n\n#define SQUASHFS_FRAGMENT_INDEX(A)\t(SQUASHFS_FRAGMENT_BYTES(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)\t(SQUASHFS_FRAGMENT_BYTES(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES(A)\t((SQUASHFS_FRAGMENT_BYTES(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)\t(SQUASHFS_FRAGMENT_INDEXES(A) *\\\n\t\t\t\t\t\tsizeof(long long))\n\n#define SQUASHFS_CACHED_FRAGMENTS\t3\n\n/* cached data constants for filesystem */\n#define SQUASHFS_CACHED_BLKS\t\t8\n\n#define SQUASHFS_MAX_FILE_SIZE_LOG\t64\n\n#define SQUASHFS_MAX_FILE_SIZE\t\t((long long) 1 << \\\n\t\t\t\t\t(SQUASHFS_MAX_FILE_SIZE_LOG - 2))\n\n#define SQUASHFS_MARKER_BYTE\t\t0xff\n\n/*\n * definitions for structures on disk\n */\n\ntypedef long long\t\tsquashfs_block_t;\ntypedef long long\t\tsquashfs_inode_t;\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tunused;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_index {\n\tunsigned int\t\tindex;\n\tunsigned int\t\tstart_block;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\n#define SQUASHFS_BASE_INODE_HEADER\t\t\\\n\tunsigned int\t\tinode_type:4;\t\\\n\tunsigned int\t\tmode:12;\t\\\n\tunsigned int\t\tuid:8;\t\t\\\n\tunsigned int\t\tguid:8;\t\t\\\n\tunsigned int\t\tmtime;\t\t\\\n\tunsigned int \t\tinode_number;\n\nstruct squashfs_base_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_lreg_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tsquashfs_block_t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tlong long\t\tfile_size;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tparent_inode;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header {\n\tSQUASHFS_BASE_INODE_HEADER;\n\tunsigned int\t\tnlink;\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\ti_count:16;\n\tunsigned int\t\tparent_inode;\n\tstruct squashfs_dir_index\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header {\n\tstruct squashfs_base_inode_header\tbase;\n\tstruct squashfs_dev_inode_header\tdev;\n\tstruct squashfs_symlink_inode_header\tsymlink;\n\tstruct squashfs_reg_inode_header\treg;\n\tstruct squashfs_lreg_inode_header\tlreg;\n\tstruct squashfs_dir_inode_header\tdir;\n\tstruct squashfs_ldir_inode_header\tldir;\n\tstruct squashfs_ipc_inode_header\tipc;\n};\n\t\nstruct squashfs_dir_entry {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tint\t\t\tinode_number:16;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_header {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tinode_number;\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry {\n\tlong long\t\tstart_block;\n\tunsigned int\t\tsize;\n\tunsigned int\t\tunused;\n} __attribute__ ((packed));\n\nextern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);\nextern int squashfs_uncompress_init(void);\nextern int squashfs_uncompress_exit(void);\n\n/*\n * macros to convert each packed bitfield structure from little endian to big\n * endian and vice versa.  These are needed when creating or using a filesystem\n * on a machine with different byte ordering to the target architecture.\n *\n */\n\n#define SQUASHFS_SWAP_START \\\n\tint bits;\\\n\tint b_pos;\\\n\tunsigned long long val;\\\n\tunsigned char *s;\\\n\tunsigned char *d;\n\n#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\\\n\tSQUASHFS_SWAP((s)->s_magic, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->inodes, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->s_major, d, 224, 16);\\\n\tSQUASHFS_SWAP((s)->s_minor, d, 240, 16);\\\n\tSQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\\\n\tSQUASHFS_SWAP((s)->block_log, d, 272, 16);\\\n\tSQUASHFS_SWAP((s)->flags, d, 288, 8);\\\n\tSQUASHFS_SWAP((s)->no_uids, d, 296, 8);\\\n\tSQUASHFS_SWAP((s)->no_guids, d, 304, 8);\\\n\tSQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\\\n\tSQUASHFS_SWAP((s)->root_inode, d, 344, 64);\\\n\tSQUASHFS_SWAP((s)->block_size, d, 408, 32);\\\n\tSQUASHFS_SWAP((s)->fragments, d, 440, 32);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\\\n\tSQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\\\n\tSQUASHFS_SWAP((s)->uid_start, d, 568, 64);\\\n\tSQUASHFS_SWAP((s)->guid_start, d, 632, 64);\\\n\tSQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\\\n\tSQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\\\n\tSQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\\\n\tSQUASHFS_SWAP((s)->unused, d, 888, 64);\\\n}\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 64, 32);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header))\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header)); \\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->rdev, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 224, 32);\\\n}\n\n#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_lreg_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 128, 64);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 192, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 224, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 256, 64);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 147, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 160, 32);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header));\\\n\tSQUASHFS_SWAP((s)->nlink, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 128, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 155, 13);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 168, 32);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 200, 16);\\\n\tSQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 8);\\\n}\n\n#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 32);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 40, 32);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->inode_number, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 64);\\\n\tSQUASHFS_SWAP((s)->size, d, 64, 32);\\\n}\n\n#define SQUASHFS_SWAP_SHORTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 2);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t16)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 16);\\\n}\n\n#define SQUASHFS_SWAP_INTS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 4);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t32)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 32);\\\n}\n\n#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\t64)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, 64);\\\n}\n\n#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\\\n\tint entry;\\\n\tint bit_position;\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, n * bits / 8);\\\n\tfor(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \\\n\t\t\tbits)\\\n\t\tSQUASHFS_SWAP(s[entry], d, bit_position, bits);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)\n\n#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY\n\nstruct squashfs_base_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\ttype:4;\n\tunsigned int\t\toffset:4;\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_1 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:4; /* index into uid table */\n\tunsigned int\t\tguid:4; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 4);\\\n\tSQUASHFS_SWAP((s)->guid, d, 20, 4);\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_ipc_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->type, d, 24, 4);\\\n\tSQUASHFS_SWAP((s)->offset, d, 28, 4);\\\n}\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->rdev, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 24, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_1));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 24, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 43, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 56, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 88, 24);\\\n}\n\n#endif\n\n#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY\n\nstruct squashfs_dir_index_2 {\n\tunsigned int\t\tindex:27;\n\tunsigned int\t\tstart_block:29;\n\tunsigned char\t\tsize;\n\tunsigned char\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_base_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_ipc_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n} __attribute__ ((packed));\n\nstruct squashfs_dev_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\trdev;\n} __attribute__ ((packed));\n\t\nstruct squashfs_symlink_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned short\t\tsymlink_size;\n\tchar\t\t\tsymlink[0];\n} __attribute__ ((packed));\n\nstruct squashfs_reg_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tfragment;\n\tunsigned int\t\toffset;\n\tunsigned int\t\tfile_size:32;\n\tunsigned short\t\tblock_list[0];\n} __attribute__ ((packed));\n\nstruct squashfs_dir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:19;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n} __attribute__  ((packed));\n\nstruct squashfs_ldir_inode_header_2 {\n\tunsigned int\t\tinode_type:4;\n\tunsigned int\t\tmode:12; /* protection */\n\tunsigned int\t\tuid:8; /* index into uid table */\n\tunsigned int\t\tguid:8; /* index into guid table */\n\tunsigned int\t\tfile_size:27;\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\tmtime;\n\tunsigned int\t\tstart_block:24;\n\tunsigned int\t\ti_count:16;\n\tstruct squashfs_dir_index_2\tindex[0];\n} __attribute__  ((packed));\n\nunion squashfs_inode_header_2 {\n\tstruct squashfs_base_inode_header_2\tbase;\n\tstruct squashfs_dev_inode_header_2\tdev;\n\tstruct squashfs_symlink_inode_header_2\tsymlink;\n\tstruct squashfs_reg_inode_header_2\treg;\n\tstruct squashfs_dir_inode_header_2\tdir;\n\tstruct squashfs_ldir_inode_header_2\tldir;\n\tstruct squashfs_ipc_inode_header_2\tipc;\n};\n\t\nstruct squashfs_dir_header_2 {\n\tunsigned int\t\tcount:8;\n\tunsigned int\t\tstart_block:24;\n} __attribute__ ((packed));\n\nstruct squashfs_dir_entry_2 {\n\tunsigned int\t\toffset:13;\n\tunsigned int\t\ttype:3;\n\tunsigned int\t\tsize:8;\n\tchar\t\t\tname[0];\n} __attribute__ ((packed));\n\nstruct squashfs_fragment_entry_2 {\n\tunsigned int\t\tstart_block;\n\tunsigned int\t\tsize;\n} __attribute__ ((packed));\n\n#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n\tSQUASHFS_MEMSET(s, d, n);\\\n\tSQUASHFS_SWAP((s)->inode_type, d, 0, 4);\\\n\tSQUASHFS_SWAP((s)->mode, d, 4, 12);\\\n\tSQUASHFS_SWAP((s)->uid, d, 16, 8);\\\n\tSQUASHFS_SWAP((s)->guid, d, 24, 8);\\\n\n#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\\\n}\n\n#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \\\n\tSQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))\n\n#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dev_inode_header_2)); \\\n\tSQUASHFS_SWAP((s)->rdev, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_symlink_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\\\n}\n\n#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_reg_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->mtime, d, 32, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->fragment, d, 96, 32);\\\n\tSQUASHFS_SWAP((s)->offset, d, 128, 32);\\\n\tSQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_dir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 19);\\\n\tSQUASHFS_SWAP((s)->offset, d, 51, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 64, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 96, 24);\\\n}\n\n#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \\\n\t\t\tsizeof(struct squashfs_ldir_inode_header_2));\\\n\tSQUASHFS_SWAP((s)->file_size, d, 32, 27);\\\n\tSQUASHFS_SWAP((s)->offset, d, 59, 13);\\\n\tSQUASHFS_SWAP((s)->mtime, d, 72, 32);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 104, 24);\\\n\tSQUASHFS_SWAP((s)->i_count, d, 128, 16);\\\n}\n\n#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\\\n\tSQUASHFS_SWAP((s)->index, d, 0, 27);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 27, 29);\\\n\tSQUASHFS_SWAP((s)->size, d, 56, 8);\\\n}\n#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\\\n\tSQUASHFS_SWAP((s)->count, d, 0, 8);\\\n\tSQUASHFS_SWAP((s)->start_block, d, 8, 24);\\\n}\n\n#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\\\n\tSQUASHFS_SWAP((s)->offset, d, 0, 13);\\\n\tSQUASHFS_SWAP((s)->type, d, 13, 3);\\\n\tSQUASHFS_SWAP((s)->size, d, 16, 8);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\\\n\tSQUASHFS_SWAP_START\\\n\tSQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\\\n\tSQUASHFS_SWAP((s)->start_block, d, 0, 32);\\\n\tSQUASHFS_SWAP((s)->size, d, 32, 32);\\\n}\n\n#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)\n\n/* fragment and fragment table defines */\n#define SQUASHFS_FRAGMENT_BYTES_2(A)\t(A * sizeof(struct squashfs_fragment_entry_2))\n\n#define SQUASHFS_FRAGMENT_INDEX_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)\t(SQUASHFS_FRAGMENT_BYTES_2(A) % \\\n\t\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEXES_2(A)\t((SQUASHFS_FRAGMENT_BYTES_2(A) + \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE - 1) / \\\n\t\t\t\t\tSQUASHFS_METADATA_SIZE)\n\n#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)\t(SQUASHFS_FRAGMENT_INDEXES_2(A) *\\\n\t\t\t\t\t\tsizeof(int))\n\n#endif\n\n#ifdef __KERNEL__\n\n/*\n * macros used to swap each structure entry, taking into account\n * bitfields and different bitfield placing conventions on differing\n * architectures\n */\n\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n\t/* convert from little endian to big endian */\n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, b_pos)\n#else\n\t/* convert from big endian to little endian */ \n#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \\\n\t\ttbits, 64 - tbits - b_pos)\n#endif\n\n#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\\\n\tb_pos = pos % 8;\\\n\tval = 0;\\\n\ts = (unsigned char *)p + (pos / 8);\\\n\td = ((unsigned char *) &val) + 7;\\\n\tfor(bits = 0; bits < (tbits + b_pos); bits += 8) \\\n\t\t*d-- = *s++;\\\n\tvalue = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\\\n}\n\n#define SQUASHFS_MEMSET(s, d, n)\tmemset(s, 0, n);\n\n#endif\n#endif\n"
  },
  {
    "path": "src/squashfs-3.0-lzma-damn-small-variant/unsquashfs.c",
    "content": "/*\n * Unsquash a squashfs filesystem.  This is a highly compressed read only filesystem.\n *\n * Copyright (c) 2002, 2003, 2004, 2005, 2006\n *  Phillip Lougher <phillip@lougher.org.uk>\n *\n * This program is free software; you can redistribute it and/or\n * modify it under the terms of the GNU General Public License\n * as published by the Free Software Foundation; either version 2,\n * or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n *\n * unsquash.c\n */\n\n#define TRUE 1\n#define FALSE 0\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <string.h>\n#include <zlib.h>\n#include <sys/mman.h>\n#include <utime.h>\n\n#ifndef linux\n#define __BYTE_ORDER BYTE_ORDER\n#define __BIG_ENDIAN BIG_ENDIAN\n#define __LITTLE_ENDIAN LITTLE_ENDIAN\n#else\n#include <endian.h>\n#endif\n\n#include <squashfs_fs.h>\n#include \"read_fs.h\"\n#include \"global.h\"\n\n#include <stdlib.h>\n\n#ifdef SQUASHFS_TRACE\n#define TRACE(s, args...)\t\tdo { \\\n\t\t\t\t\t\tprintf(\"mksquashfs: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n#else\n#define TRACE(s, args...)\n#endif\n\n#define ERROR(s, args...)\t\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, s, ## args); \\\n\t\t\t\t\t} while(0)\n\n#define EXIT_UNSQUASH(s, args...)\tdo { \\\n\t\t\t\t\t\tfprintf(stderr, \"FATAL ERROR aborting: \"s, ## args); \\\n\t\t\t\t\t} while(0)\n\nstruct hash_table_entry {\n\tint\tstart;\n\tint\tbytes;\n\tstruct hash_table_entry *next;\n};\n\nint bytes = 0, swap, file_count = 0, dir_count = 0, sym_count = 0, dev_count = 0, fifo_count = 0;\nchar *inode_table = NULL, *directory_table = NULL;\nstruct hash_table_entry *inode_table_hash[65536], *directory_table_hash[65536];\nint fd;\nsquashfs_fragment_entry *fragment_table;\nunsigned int *uid_table, *guid_table;\nunsigned int cached_frag = SQUASHFS_INVALID_FRAG;\nchar *fragment_data;\nchar *file_data;\nchar *data;\nunsigned int block_size;\nint lsonly = FALSE, info = FALSE;\nchar **created_inode;\n\n#define CALCULATE_HASH(start)\t(start & 0xffff)\n\nint add_entry(struct hash_table_entry *hash_table[], int start, int bytes)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tif((hash_table_entry = malloc(sizeof(struct hash_table_entry))) == NULL) {\n\t\tERROR(\"add_hash: out of memory in malloc\\n\");\n\t\treturn FALSE;\n\t}\n\n\thash_table_entry->start = start;\n\thash_table_entry->bytes = bytes;\n\thash_table_entry->next = hash_table[hash];\n\thash_table[hash] = hash_table_entry;\n\n\treturn TRUE;\n}\n\n\nint lookup_entry(struct hash_table_entry *hash_table[], int start)\n{\n\tint hash = CALCULATE_HASH(start);\n\tstruct hash_table_entry *hash_table_entry;\n\n\tfor(hash_table_entry = hash_table[hash]; hash_table_entry; hash_table_entry = hash_table_entry->next)\n\t\tif(hash_table_entry->start == start)\n\t\t\treturn hash_table_entry->bytes;\n\n\treturn -1;\n}\n\n\nint read_bytes(long long byte, int bytes, char *buff)\n{\n\toff_t off = byte;\n\n\tTRACE(\"read_bytes: reading from position 0x%llx, bytes %d\\n\", byte, bytes);\n\n\tif(lseek(fd, off, SEEK_SET) == -1) {\n\t\tERROR(\"Lseek failed because %s\\b\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(read(fd, buff, bytes) == -1) {\n\t\tERROR(\"Read on destination failed because %s\\n\", strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\treturn TRUE;\n}\n\n\nint read_block(long long start, long long *next, char *block, squashfs_super_block *sBlk)\n{\n\tunsigned short c_byte;\n\tint offset = 2;\n\t\n\tif(swap) {\n\t\tif(read_bytes(start, 2, block) == FALSE)\n\t\t\tgoto failed;\n\t\t((unsigned char *) &c_byte)[1] = block[0];\n\t\t((unsigned char *) &c_byte)[0] = block[1]; \n\t} else \n\t\tif(read_bytes(start, 2, (char *)&c_byte) == FALSE)\n\t\t\tgoto failed;\n\n\tTRACE(\"read_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE(c_byte), SQUASHFS_COMPRESSED(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_CHECK_DATA(sBlk->flags))\n\t\toffset = 3;\n\tif(SQUASHFS_COMPRESSED(c_byte)) {\n\t\tchar buffer[SQUASHFS_METADATA_SIZE];\n\t\tint res;\n\t\tunsigned long bytes = SQUASHFS_METADATA_SIZE;\n\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, buffer) == FALSE)\n\t\t\tgoto failed;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes, (const unsigned char *) buffer, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\tgoto failed;\n\t\t}\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn bytes;\n\t} else {\n\t\tc_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);\n\t\tif(read_bytes(start + offset, c_byte, block) == FALSE)\n\t\t\tgoto failed;\n\t\tif(next)\n\t\t\t*next = start + offset + c_byte;\n\t\treturn c_byte;\n\t}\n\nfailed:\n\treturn FALSE;\n}\n\n\nint read_data_block(long long start, unsigned int size, char *block)\n{\n\tint res;\n\tunsigned long bytes = block_size;\n\tint c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(size);\n\n\tTRACE(\"read_data_block: block @0x%llx, %d %s bytes\\n\", start, SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte), SQUASHFS_COMPRESSED_BLOCK(c_byte) ? \"compressed\" : \"uncompressed\");\n\n\tif(SQUASHFS_COMPRESSED_BLOCK(size)) {\n\t\tif(read_bytes(start, c_byte, data) == FALSE)\n\t\t\treturn 0;\n\n\t\tif((res = uncompress((unsigned char *) block, &bytes, (const unsigned char *) data, c_byte)) != Z_OK) {\n\t\t\tif(res == Z_MEM_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough memory\\n\");\n\t\t\telse if(res == Z_BUF_ERROR)\n\t\t\t\tERROR(\"zlib::uncompress failed, not enough room in output buffer\\n\");\n\t\t\telse\n\t\t\t\tERROR(\"zlib::uncompress failed, unknown error %d\\n\", res);\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn bytes;\n\t} else {\n\t\tif(read_bytes(start, c_byte, block) == FALSE)\n\t\t\treturn 0;\n\n\t\treturn c_byte;\n\t}\n}\n\n\nvoid uncompress_inode_table(long long start, long long end, squashfs_super_block *sBlk)\n{\n\tint size = 0, bytes = 0, res;\n\n\twhile(start < end) {\n\t\tif((size - bytes < SQUASHFS_METADATA_SIZE) &&\n\t\t\t\t((inode_table = realloc(inode_table, size += SQUASHFS_METADATA_SIZE)) == NULL))\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_inode_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(inode_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, inode_table + bytes, sBlk)) == 0) {\n\t\t\tfree(inode_table);\n\t\t\tEXIT_UNSQUASH(\"uncompress_inode_table: failed to read block\\n\");\n\t\t}\n\t\tbytes += res;\n\t}\n}\n\n\nint set_attributes(char *pathname, unsigned int mode, unsigned int uid, unsigned int guid,\nunsigned int mtime, unsigned int set_mode)\n{\n\tstruct utimbuf times = { (time_t) mtime, (time_t) mtime };\n\n\tif(utime(pathname, &times) == -1) {\n\t\tERROR(\"set_attributes: failed to set time on %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(set_mode && chmod(pathname, (mode_t) mode) == -1) {\n\t\tERROR(\"set_attributes: failed to change mode %s, because %s\\n\", pathname, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\tif(geteuid() == 0) {\n\t\tuid_t uid_value = (uid_t) uid_table[uid];\n\t\tuid_t guid_value = guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[guid];\n\n\t\tif(chown(pathname, uid_value, guid_value) == -1) {\n\t\t\tERROR(\"set_attributes: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\n\treturn TRUE;\n}\n\n\nvoid read_uids_guids(squashfs_super_block *sBlk)\n{\n\tif((uid_table = malloc((sBlk->no_uids + sBlk->no_guids) * sizeof(unsigned int))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to allocate uid/gid table\\n\");\n\n\tguid_table = uid_table + sBlk->no_uids;\n\n\tif(read_bytes(sBlk->uid_start, (sBlk->no_uids + sBlk->no_guids) * sizeof(unsigned int), (char *) uid_table) ==\n\t\t\tFALSE)\n\t\tEXIT_UNSQUASH(\"read_uids_guids: failed to read uid/gid table\\n\");\n}\n\n\nvoid read_fragment_table(squashfs_super_block *sBlk)\n{\n\tint i, indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);\n\tsquashfs_fragment_index fragment_table_index[indexes];\n\n\tTRACE(\"read_fragment_table: %d fragments, reading %d fragment indexes from 0x%llx\\n\", sBlk->fragments, indexes, sBlk->fragment_table_start);\n\tif(sBlk->fragments == 0)\n\t\treturn;\n\n\tif((fragment_table = (squashfs_fragment_entry *) malloc(sBlk->fragments * sizeof(squashfs_fragment_entry))) == NULL)\n\t\tEXIT_UNSQUASH(\"read_fragment_table: failed to allocate fragment table\\n\");\n\n\tif(swap) {\n\t\tsquashfs_fragment_index sfragment_table_index[indexes];\n\n\t\tread_bytes(sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) sfragment_table_index);\n\t\tSQUASHFS_SWAP_FRAGMENT_INDEXES(fragment_table_index, sfragment_table_index, indexes);\n\t} else\n\t\tread_bytes(sBlk->fragment_table_start, SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), (char *) fragment_table_index);\n\n\tfor(i = 0; i < indexes; i++) {\n\t\tint length = read_block(fragment_table_index[i], NULL, ((char *) fragment_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);\n\t\tTRACE(\"Read fragment table block %d, from 0x%llx, length %d\\n\", i, fragment_table_index[i], length);\n\t}\n\n\tif(swap) {\n\t\tsquashfs_fragment_entry sfragment;\n\t\tfor(i = 0; i < sBlk->fragments; i++) {\n\t\t\tSQUASHFS_SWAP_FRAGMENT_ENTRY((&sfragment), (&fragment_table[i]));\n\t\t\tmemcpy((char *) &fragment_table[i], (char *) &sfragment, sizeof(squashfs_fragment_entry));\n\t\t}\n\t}\n}\n\n\nchar *read_fragment(unsigned int fragment)\n{\n\tTRACE(\"read_fragment: reading fragment %d\\n\", fragment);\n\n\tif(cached_frag == SQUASHFS_INVALID_FRAG || fragment != cached_frag) {\n\t\tsquashfs_fragment_entry *fragment_entry = &fragment_table[fragment];\n\t\tif(read_data_block(fragment_entry->start_block, fragment_entry->size, fragment_data) == 0) {\n\t\t\tERROR(\"read_fragment: failed to read fragment %d\\n\", fragment);\n\t\t\tcached_frag = SQUASHFS_INVALID_FRAG;\n\t\t\treturn NULL;\n\t\t}\n\t\tcached_frag = fragment;\n\t}\n\n\treturn fragment_data;\n}\n\n\nint write_file(char *pathname, unsigned int fragment, unsigned int frag_bytes, unsigned int offset,\nunsigned int blocks, long long start, char *block_ptr, unsigned int mode)\n{\n\tunsigned int file_fd, bytes, i;\n\tunsigned int *block_list;\n\n\tTRACE(\"write_file: regular file, blocks %d\\n\", blocks);\n\n\tif((block_list = malloc(blocks * sizeof(unsigned int))) == NULL) {\n\t\tERROR(\"write_file: unable to malloc block list\\n\");\n\t\treturn FALSE;\n\t}\n\n\tif(swap) {\n\t\tunsigned int sblock_list[blocks];\n\t\tmemcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));\n\t\tSQUASHFS_SWAP_INTS(block_list, sblock_list, blocks);\n\t} else\n\t\tmemcpy(block_list, block_ptr, blocks * sizeof(unsigned int));\n\n\tif((file_fd = open(pathname, O_CREAT | O_WRONLY, (mode_t) mode)) == -1) {\n\t\tERROR(\"write_file: failed to create file %s, because %s\\n\", pathname,\n\t\t\tstrerror(errno));\n\t\tfree(block_list);\n\t\treturn FALSE;\n\t}\n\n\tfor(i = 0; i < blocks; i++) {\n\t\tif((bytes = read_data_block(start, block_list[i], file_data)) == 0) {\n\t\t\tERROR(\"write_file: failed to read data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tif(write(file_fd, file_data, bytes) < bytes) {\n\t\t\tERROR(\"write_file: failed to write data block 0x%llx\\n\", start);\n\t\t\tgoto failure;\n\t\t}\n\n\t\tstart += SQUASHFS_COMPRESSED_SIZE_BLOCK(block_list[i]);\n\t}\n\n\tif(frag_bytes != 0) {\n\t\tchar *fragment_data = read_fragment(fragment);\n\n\t\tif(fragment_data == NULL)\n\t\t\tgoto failure;\n\n\t\tif(write(file_fd, fragment_data + offset, frag_bytes) < frag_bytes) {\n\t\t\tERROR(\"write_file: failed to write fragment %d\\n\", fragment);\n\t\t\tgoto failure;\n\t\t}\n\t}\n\n\tclose(file_fd);\n\treturn TRUE;\n\nfailure:\n\tclose(file_fd);\n\tfree(block_list);\n\treturn FALSE;\n}\n\t\t\n\nint create_inode(char *pathname, unsigned int start_block, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tlong long start = sBlk->inode_table_start + start_block;\n\tsquashfs_inode_header header;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start), file_fd;\n\n\tTRACE(\"create_inode: pathname %s, start 0x%llx, offset %d\\n\", pathname, start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"create_inode: inode block 0x%llx out of range!\\n\", start);\n\t\treturn FALSE;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_base_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.base));\n\t\tSQUASHFS_SWAP_BASE_INODE_HEADER(&header.base, &sinode, sizeof(squashfs_base_inode_header));\n\t} else\n\t\tmemcpy(&header.base, block_ptr, sizeof(header.base));\n\n\tif(created_inode[header.base.inode_number - 1]) {\n\t\tTRACE(\"create_inode: hard link\\n\");\n\t\tif(link(created_inode[header.base.inode_number - 1], pathname) == -1) {\n\t\t\tERROR(\"create_inode: failed to create hardlink, because %s\\n\", strerror(errno));\n\t\t\treturn FALSE;\n\t\t}\n\n\t\treturn TRUE;\n\t}\n\n\tswitch(header.base.inode_type) {\n\t\tcase SQUASHFS_FILE_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_reg_inode_header *inode = &header.reg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_reg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_REG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size\n\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>\n\t\t\t\tsBlk->block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,\n\t\t\t\t\tblock_ptr + sizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_LREG_TYPE: {\n\t\t\tunsigned int frag_bytes;\n\t\t\tunsigned int blocks;\n\t\t\tunsigned int offset;\n\t\t\tlong long start;\n\t\t\tsquashfs_lreg_inode_header *inode = &header.lreg;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_lreg_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(sinode));\n\t\t\t\tSQUASHFS_SWAP_LREG_INODE_HEADER(inode, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(inode, block_ptr, sizeof(*inode));\n\n\t\t\tfrag_bytes = inode->fragment == SQUASHFS_INVALID_FRAG ? 0 : inode->file_size % sBlk->block_size;\n\t\t\toffset = inode->offset;\n\t\t\tblocks = inode->fragment == SQUASHFS_INVALID_FRAG ? (inode->file_size\n\t\t\t\t+ sBlk->block_size - 1) >> sBlk->block_log : inode->file_size >>\n\t\t\t\tsBlk->block_log;\n\t\t\tstart = inode->start_block;\n\n\t\t\tTRACE(\"create_inode: regular file, file_size %lld, blocks %d\\n\", inode->file_size, blocks);\n\n\t\t\tif(write_file(pathname, inode->fragment, frag_bytes, offset, blocks, start,\n\t\t\t\t\tblock_ptr + sizeof(*inode), inode->mode)) {\n\t\t\t\tset_attributes(pathname, inode->mode, inode->uid, inode->guid, inode->mtime, FALSE);\n\t\t\t\tfile_count ++;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\t\n\t\tcase SQUASHFS_SYMLINK_TYPE: {\n\t\t\tsquashfs_symlink_inode_header *inodep = &header.symlink;\n\t\t\tchar name[65536];\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_symlink_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: symlink, symlink_size %d\\n\", inodep->symlink_size);\n\n\t\t\tstrncpy(name, block_ptr + sizeof(squashfs_symlink_inode_header), inodep->symlink_size);\n\t\t\tname[inodep->symlink_size] = '\\0';\n\n\t\t\tif(symlink(name, pathname) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create symlink %s, because %s\\n\", pathname,\n\t\t\t\t\tstrerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(geteuid() == 0) {\n\t\t\t\tuid_t uid_value = (uid_t) uid_table[inodep->uid];\n\t\t\t\tuid_t guid_value = inodep->guid == SQUASHFS_GUIDS ? uid_value : (uid_t) guid_table[inodep->guid];\n\n\t\t\t\tif(lchown(pathname, uid_value, guid_value) == -1)\n\t\t\t\t\tERROR(\"create_inode: failed to change uid and gids on %s, because %s\\n\", pathname, strerror(errno));\n\t\t\t}\n\n\t\t\tsym_count ++;\n\t\t\tbreak;\n\t\t}\n \t\tcase SQUASHFS_BLKDEV_TYPE:\n\t \tcase SQUASHFS_CHRDEV_TYPE: {\n\t\t\tsquashfs_dev_inode_header *inodep = &header.dev;\n\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dev_inode_header sinodep;\n\t\t\t\tmemcpy(&sinodep, block_ptr, sizeof(sinodep));\n\t\t\t\tSQUASHFS_SWAP_DEV_INODE_HEADER(inodep, &sinodep);\n\t\t\t} else\n\t\t\t\tmemcpy(inodep, block_ptr, sizeof(*inodep));\n\n\t\t\tTRACE(\"create_inode: dev, rdev 0x%x\\n\", inodep->rdev);\n\n\t\t\tif(geteuid() == 0) {\n\t\t\t\tif(mknod(pathname, inodep->inode_type == SQUASHFS_CHRDEV_TYPE ? S_IFCHR : S_IFBLK,\n\t\t\t\t\t\t\tmakedev((inodep->rdev >> 8) & 0xff, inodep->rdev & 0xff))\n\t\t\t\t\t\t\t== -1) {\n\t\t\t\t\tERROR(\"create_inode: failed to create %s device %s, because %s\\n\",\n\t\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tset_attributes(pathname, inodep->mode, inodep->uid, inodep->guid, inodep->mtime, TRUE);\n\t\t\t\tdev_count ++;\n\t\t\t} else\n\t\t\t\tERROR(\"create_inode: could not create %s device %s, because you're not superuser!\\n\",\n\t\t\t\t\tinodep->inode_type == SQUASHFS_CHRDEV_TYPE ? \"character\" : \"block\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\tbreak;\n\t\t\t}\n\t\tcase SQUASHFS_FIFO_TYPE:\n\t\t\tTRACE(\"create_inode: fifo\\n\");\n\n\t\t\tif(mknod(pathname, S_IFIFO, 0) == -1) {\n\t\t\t\tERROR(\"create_inode: failed to create fifo %s, because %s\\n\",\n\t\t\t\t\tpathname, strerror(errno));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset_attributes(pathname, header.base.mode, header.base.uid, header.base.guid,\n\t\t\t\theader.base.mtime, TRUE);\n\t\t\tfifo_count ++;\n\t\t\tbreak;\n\t\tcase SQUASHFS_SOCKET_TYPE:\n\t\t\tTRACE(\"create_inode: socket\\n\");\n\t\t\tERROR(\"create_inode: socket %s ignored\\n\", pathname);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"Unknown inode type %d in create_inode_table!\\n\", header.base.inode_type);\n\t\t\treturn FALSE;\n\t}\n\n\tcreated_inode[header.base.inode_number - 1] = strdup(pathname);\n\n\treturn TRUE;\n}\n\n\nvoid uncompress_directory_table(long long start, long long end, squashfs_super_block *sBlk)\n{\n\tint bytes = 0, size = 0, res;\n\n\twhile(start < end) {\n\t\tif(size - bytes < SQUASHFS_METADATA_SIZE && (directory_table = realloc(directory_table, size += SQUASHFS_METADATA_SIZE)) == NULL)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: out of memory in realloc\\n\");\n\t\tTRACE(\"uncompress_directory_table: reading block 0x%llx\\n\", start);\n\t\tadd_entry(directory_table_hash, start, bytes);\n\t\tif((res = read_block(start, &start, directory_table + bytes, sBlk)) == 0)\n\t\t\tEXIT_UNSQUASH(\"uncompress_directory_table: failed to read block\\n\");\n\t\tbytes += res;\n\t}\n}\n\n\n#define DIR_ENT_SIZE\t16\n\nstruct dir_ent\t{\n\tchar\t\tname[SQUASHFS_NAME_LEN + 1];\n\tunsigned int\tstart_block;\n\tunsigned int\toffset;\n\tunsigned int\ttype;\n};\n\nstruct dir {\n\tint\t\tdir_count;\n\tint \t\tcur_entry;\n\tunsigned int\tmode;\n\tunsigned int\tuid;\n\tunsigned int\tguid;\n\tunsigned int\tmtime;\n\tstruct dir_ent\t*dirs;\n};\n\n\nstruct dir *squashfs_openddir(unsigned int block_start, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tsquashfs_dir_header dirh;\n\tchar buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];\n\tsquashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;\n\tlong long start = sBlk->inode_table_start + block_start;\n\tchar *block_ptr;\n\tint bytes = lookup_entry(inode_table_hash, start);\n\tsquashfs_inode_header header;\n\tint dir_count, size;\n\tstruct dir_ent *new_dir;\n\tstruct dir *dir;\n\n\tTRACE(\"squashfs_opendir: inode start block %d, offset %d\\n\", block_start, offset);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: inode block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tblock_ptr = inode_table + bytes + offset;\n\n\tif(swap) {\n\t\tsquashfs_dir_inode_header sinode;\n\t\tmemcpy(&sinode, block_ptr, sizeof(header.dir));\n\t\tSQUASHFS_SWAP_DIR_INODE_HEADER(&header.dir, &sinode);\n\t} else\n\t\tmemcpy(&header.dir, block_ptr, sizeof(header.dir));\n\n\tswitch(header.dir.inode_type) {\n\t\tcase SQUASHFS_DIR_TYPE:\n\t\t\tblock_start = header.dir.start_block;\n\t\t\toffset = header.dir.offset;\n\t\t\tsize = header.dir.file_size;\n\t\t\tbreak;\n\t\tcase SQUASHFS_LDIR_TYPE:\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_ldir_inode_header sinode;\n\t\t\t\tmemcpy(&sinode, block_ptr, sizeof(header.ldir));\n\t\t\t\tSQUASHFS_SWAP_LDIR_INODE_HEADER(&header.ldir, &sinode);\n\t\t\t} else\n\t\t\t\tmemcpy(&header.ldir, block_ptr, sizeof(header.ldir));\n\t\t\tblock_start = header.ldir.start_block;\n\t\t\toffset = header.ldir.offset;\n\t\t\tsize = header.ldir.file_size;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tERROR(\"squashfs_opendir: inode not a directory\\n\");\n\t\t\treturn NULL;\n\t}\n\n\tstart = sBlk->directory_table_start + block_start;\n\tbytes = lookup_entry(directory_table_hash, start);\n\n\tif(bytes == -1) {\n\t\tERROR(\"squashfs_opendir: directory block %d not found!\\n\", block_start);\n\t\treturn NULL;\n\t}\n\tbytes += offset;\n\tsize += bytes - 3;\n\n\tif((dir = malloc(sizeof(struct dir))) == NULL) {\n\t\tERROR(\"squashfs_opendir: malloc failed!\\n\");\n\t\treturn NULL;\n\t}\n\n\tdir->dir_count = 0;\n\tdir->cur_entry = 0;\n\tdir->mode = header.dir.mode;\n\tdir->uid = header.dir.uid;\n\tdir->guid = header.dir.guid;\n\tdir->mtime = header.dir.mtime;\n\tdir->dirs = NULL;\n\n\twhile(bytes < size) {\t\t\t\n\t\tif(swap) {\n\t\t\tsquashfs_dir_header sdirh;\n\t\t\tmemcpy(&sdirh, directory_table + bytes, sizeof(sdirh));\n\t\t\tSQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);\n\t\t} else\n\t\t\tmemcpy(&dirh, directory_table + bytes, sizeof(dirh));\n\t\n\t\tdir_count = dirh.count + 1;\n\t\tTRACE(\"squashfs_opendir: Read directory header @ byte position %d, %d directory entries\\n\", bytes, dir_count);\n\t\tbytes += sizeof(dirh);\n\n\t\twhile(dir_count--) {\n\t\t\tif(swap) {\n\t\t\t\tsquashfs_dir_entry sdire;\n\t\t\t\tmemcpy(&sdire, directory_table + bytes, sizeof(sdire));\n\t\t\t\tSQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);\n\t\t\t} else\n\t\t\t\tmemcpy(dire, directory_table + bytes, sizeof(dire));\n\t\t\tbytes += sizeof(*dire);\n\n\t\t\tmemcpy(dire->name, directory_table + bytes, dire->size + 1);\n\t\t\tdire->name[dire->size + 1] = '\\0';\n\t\t\tTRACE(\"squashfs_opendir: directory entry %s, inode %d:%d, type %d\\n\", dire->name, dirh.start_block, dire->offset, dire->type);\n\t\t\tif((dir->dir_count % DIR_ENT_SIZE) == 0) {\n\t\t\t\tif((new_dir = realloc(dir->dirs, (dir->dir_count + DIR_ENT_SIZE) * sizeof(struct dir_ent))) == NULL) {\n\t\t\t\t\tERROR(\"squashfs_opendir: realloc failed!\\n\");\n\t\t\t\t\tfree(dir->dirs);\n\t\t\t\t\tfree(dir);\n\t\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\t\tdir->dirs = new_dir;\n\t\t\t}\n\t\t\tstrcpy(dir->dirs[dir->dir_count].name, dire->name);\n\t\t\tdir->dirs[dir->dir_count].start_block = dirh.start_block;\n\t\t\tdir->dirs[dir->dir_count].offset = dire->offset;\n\t\t\tdir->dirs[dir->dir_count].type = dire->type;\n\t\t\tdir->dir_count ++;\n\t\t\tbytes += dire->size + 1;\n\t\t}\n\t}\n\n\treturn dir;\n}\n\n\nint squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block, unsigned int *offset, unsigned int *type)\n{\n\tif(dir->cur_entry == dir->dir_count)\n\t\treturn FALSE;\n\n\t*name = dir->dirs[dir->cur_entry].name;\n\t*start_block = dir->dirs[dir->cur_entry].start_block;\n\t*offset = dir->dirs[dir->cur_entry].offset;\n\t*type = dir->dirs[dir->cur_entry].type;\n\tdir->cur_entry ++;\n\n\treturn TRUE;\n}\n\n\nvoid squashfs_closedir(struct dir *dir)\n{\n\tfree(dir->dirs);\n\tfree(dir);\n}\n\n\nint dir_scan(char *parent_name, unsigned int start_block, unsigned int offset, squashfs_super_block *sBlk)\n{\n\tstruct dir *dir = squashfs_openddir(start_block, offset, sBlk);\n\tunsigned int type;\n\tchar *name, pathname[1024];\n\n\tif(dir == NULL) {\n\t\tERROR(\"dir_scan: Failed to read directory %s (%x:%x)\\n\", parent_name, start_block, offset);\n\t\treturn FALSE;\n\t}\n\n\tif(!lsonly && mkdir(parent_name, (mode_t) dir->mode) == -1) {\n\t\tERROR(\"dir_scan: failed to open directory %s, because %s\\n\", parent_name, strerror(errno));\n\t\treturn FALSE;\n\t}\n\n\twhile(squashfs_readdir(dir, &name, &start_block, &offset, &type)) {\n\t\tTRACE(\"dir_scan: name %s, start_block %d, offset %d, type %d\\n\", name, start_block, offset, type);\n\n\t\tstrcat(strcat(strcpy(pathname, parent_name), \"/\"), name);\n\n\t\tif(lsonly || info)\n\t\t\tprintf(\"%s\\n\", pathname);\n\n\t\tif(type == SQUASHFS_DIR_TYPE)\n\t\t\tdir_scan(pathname, start_block, offset, sBlk);\n\t\telse\n\t\t\tif(!lsonly)\n\t\t\t\tcreate_inode(pathname, start_block, offset, sBlk);\n\t}\n\n\t!lsonly && set_attributes(parent_name, dir->mode, dir->uid, dir->guid, dir->mtime, TRUE);\n\n\tsquashfs_closedir(dir);\n\tdir_count ++;\n\n\treturn TRUE;\n}\n\n\nint read_super(squashfs_super_block *sBlk, char *source)\n{\n\tread_bytes(SQUASHFS_START, sizeof(squashfs_super_block), (char *) sBlk);\n\n\t/* Check it is a SQUASHFS superblock */\n\tswap = 0;\n\tif(sBlk->s_magic != SQUASHFS_MAGIC) {\n\t\tif(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {\n\t\t\tsquashfs_super_block sblk;\n\t\t\tERROR(\"Reading a different endian SQUASHFS filesystem on %s\\n\", source);\n\t\t\tSQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);\n\t\t\tmemcpy(sBlk, &sblk, sizeof(squashfs_super_block));\n\t\t\tswap = 1;\n\t\t} else  {\n\t\t\tERROR(\"Can't find a SQUASHFS superblock on %s\\n\", source);\n\t\t\tgoto failed_mount;\n\t\t}\n\t}\n\n\t/* Check the MAJOR & MINOR versions */\n\tif(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {\n\t\tERROR(\"Major/Minor mismatch, filesystem on %s is (%d:%d)\\n\",\n\t\t\t\tsource, sBlk->s_major, sBlk->s_minor);\n\t\tERROR(\"I only support Squashfs 3.0 filesystems!  Later releases will support older Squashfs filesystems\\n\");\n\t\tgoto failed_mount;\n\t}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n\tTRACE(\"Found a valid %s endian SQUASHFS superblock on %s.\\n\", swap ? \"little\" : \"big\", source);\n#else\n\tTRACE(\"Found a valid %s endian SQUASHFS superblock on %s.\\n\", swap ? \"big\" : \"little\", source);\n#endif\n\n\tTRACE(\"\\tInodes are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tData is %scompressed\\n\", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tFragments are %scompressed\\n\", SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? \"un\" : \"\");\n\tTRACE(\"\\tCheck data is %s present in the filesystem\\n\", SQUASHFS_CHECK_DATA(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFragments are %s present in the filesystem\\n\", SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? \"not\" : \"\");\n\tTRACE(\"\\tAlways_use_fragments option is %s specified\\n\", SQUASHFS_ALWAYS_FRAGMENTS(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tDuplicates are %s removed\\n\", SQUASHFS_DUPLICATES(sBlk->flags) ? \"\" : \"not\");\n\tTRACE(\"\\tFilesystem size %.2f Kbytes (%.2f Mbytes)\\n\", sBlk->bytes_used / 1024.0, sBlk->bytes_used / (1024.0 * 1024.0));\n\tTRACE(\"\\tBlock size %d\\n\", sBlk->block_size);\n\tTRACE(\"\\tNumber of fragments %d\\n\", sBlk->fragments);\n\tTRACE(\"\\tNumber of inodes %d\\n\", sBlk->inodes);\n\tTRACE(\"\\tNumber of uids %d\\n\", sBlk->no_uids);\n\tTRACE(\"\\tNumber of gids %d\\n\", sBlk->no_guids);\n\tTRACE(\"sBlk->inode_table_start 0x%llx\\n\", sBlk->inode_table_start);\n\tTRACE(\"sBlk->directory_table_start 0x%llx\\n\", sBlk->directory_table_start);\n\tTRACE(\"sBlk->uid_start 0x%llx\\n\", sBlk->uid_start);\n\tTRACE(\"sBlk->fragment_table_start 0x%llx\\n\", sBlk->fragment_table_start);\n\tTRACE(\"\\n\");\n\n\treturn TRUE;\n\nfailed_mount:\n\treturn FALSE;\n}\n\n\n#define VERSION() \\\n\tprintf(\"unsquashfs version 1.0 (2006/03/15)\\n\");\\\n\tprintf(\"copyright (C) 2006 Phillip Lougher <phillip@lougher.org.uk>\\n\\n\"); \\\n    \tprintf(\"This program is free software; you can redistribute it and/or\\n\");\\\n\tprintf(\"modify it under the terms of the GNU General Public License\\n\");\\\n\tprintf(\"as published by the Free Software Foundation; either version 2,\\n\");\\\n\tprintf(\"or (at your option) any later version.\\n\\n\");\\\n\tprintf(\"This program is distributed in the hope that it will be useful,\\n\");\\\n\tprintf(\"but WITHOUT ANY WARRANTY; without even the implied warranty of\\n\");\\\n\tprintf(\"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n\");\\\n\tprintf(\"GNU General Public License for more details.\\n\");\nint main(int argc, char *argv[])\n{\n\tsquashfs_super_block sBlk;\n\tchar *dest = \"squashfs-root\";\n\tint i, version = FALSE;\n\n\tfor(i = 1; i < argc; i++) {\n\t\tif(*argv[i] != '-')\n\t\t\tbreak;\n\t\tif(strcmp(argv[i], \"-version\") == 0) {\n\t\t\tVERSION();\n\t\t\tversion = TRUE;\n\t\t} else if(strcmp(argv[i], \"-info\") == 0)\n\t\t\tinfo = TRUE;\n\t\telse if(strcmp(argv[i], \"-ls\") == 0)\n\t\t\tlsonly = TRUE;\n\t\telse if(strcmp(argv[i], \"-dest\") == 0) {\n\t\t\tif(++i == argc)\n\t\t\t\tgoto options;\n\t\t\tdest = argv[i];\n\t\t}\n\t}\n\n\tif(i == argc) {\n\t\tif(!version) {\noptions:\n\t\t\tERROR(\"SYNTAX: %s [-ls | -dest] filesystem\\n\", argv[0]);\n\t\t\tERROR(\"\\t-version\\t\\tprint version, licence and copyright information\\n\");\n\t\t\tERROR(\"\\t-info\\t\\t\\tprint files as they are unsquashed\\n\");\n\t\t\tERROR(\"\\t-ls\\t\\t\\tlist filesystem only\\n\");\n\t\t\tERROR(\"\\t-dest <pathname>\\tunsquash to <pathname>, default \\\"squashfs-root\\\"\\n\");\n\t\t}\n\t\texit(1);\n\t}\n\n\tif((fd = open(argv[i], O_RDONLY)) == -1) {\n\t\tERROR(\"Could not open %s, because %s\\n\", argv[i], strerror(errno));\n\t\texit(1);\n\t}\n\n\tif(read_super(&sBlk, argv[i]) == FALSE)\n\t\texit(1);\n\n\tblock_size = sBlk.block_size;\n\tif((fragment_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate fragment_data\\n\");\n\n\tif((file_data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate file_data\");\n\n\tif((data = malloc(block_size)) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate datan\\n\");\n\n\tif((created_inode = malloc(sBlk.inodes * sizeof(char *))) == NULL)\n\t\tEXIT_UNSQUASH(\"failed to allocate created_inode\\n\");\n\n\tmemset(created_inode, 0, sBlk.inodes * sizeof(char *));\n\n\tread_uids_guids(&sBlk);\n\tread_fragment_table(&sBlk);\n\tuncompress_inode_table(sBlk.inode_table_start, sBlk.directory_table_start, &sBlk);\n\tuncompress_directory_table(sBlk.directory_table_start, sBlk.fragment_table_start, &sBlk);\n\n\tdir_scan(dest, SQUASHFS_INODE_BLK(sBlk.root_inode), SQUASHFS_INODE_OFFSET(sBlk.root_inode), &sBlk);\n\n\tif(!lsonly) {\n\t\tprintf(\"\\n\");\n\t\tprintf(\"created %d files\\n\", file_count);\n\t\tprintf(\"created %d directories\\n\", dir_count);\n\t\tprintf(\"created %d symlinks\\n\", sym_count);\n\t\tprintf(\"created %d devices\\n\", dev_count);\n\t\tprintf(\"created %d fifos\\n\", fifo_count);\n\t}\n\n}\n"
  },
  {
    "path": "src/tpl-tool/doc/Image_layout",
    "content": "Standard TP-Link firmware images for their router products consist of a\nheader, kernel and a root filesystem in the format shown below.\n\n    ------------------\n    |     |     |    |\n    |  h  |  k  |  r |\n    |  e  |  e  |  o |\n    |  a  |  r  |  o |\n    |  d  |  n  |  t |\n    |  r  |  e  |  f |\n    |     |  l  |  s |\n    |     |     |    |\n    ------------------\n\nThe header is 0x200 bytes in length. The kernel is padded to 0x100000\nand rootfs to either 0x3C0000 or 0x7C0000 depending on the device.\n\nFirmware images which include a bootloader have an 'image within image'\nstructure consisting of a 'standard' kernel/rootfs image within a\nlarger image as shown below.\n\n-----------------------------------------\n|     |     |                           |\n|     |     |    -------------------    |\n|     |     |    |     |     |     |    |\n|  h  |  b  |    |  h  |  k  |  r  |    |\n|  e  |  o  |    |  e  |  e  |  o  |    |\n|  a  |  o  |    |  a  |  r  |  o  |    |\n|  d  |  t  |    |  d  |  n  |  t  |    |\n|  r  |  l  |    |  e  |  e  |  f  |    |\n|     |  d  |    |  r  |  l  |  s  |    |\n|     |  r  |    |     |     |     |    |\n|     |     |    -------------------    |\n|     |     |                           |\n-----------------------------------------\n\n\nThe header layout for both types of image is the same with the exception\nof the bootloader length and the MD5Key used to salt the image checksum.\n\nThe layout shown below is for a 'standard' image which does not include\na bootloader.\n\n\nHeader version          00000000  01000000\nImage vendor            00000004  TP-LINK Technologies\nImage version           0000001C  ver. 1.0\nProduct Id              00000040  25430001\nProduct Version         00000044  00000001\n                        00000048  00 00 00 00\nImage checksum          0000004C  df 9b c7 3f 89 d6 13 da 7f c3 c9 40 ea bc c2 0d   (salted MD5)\n                        0000005C  00 00 00 00\nKernel checksum         00000060  a3 88 3e 97 46 17 a3 45 54 b6 75 6e 53 6b fa 03   (salted MD5 ?)\n                        00000070  00 00 00 00\nKernel load address     00000074  80002000\nKernel entrypoint       00000078  801a0910\nImage length            0000007C  007c0000\nKernel offset           00000080  00000200\nKernel length           00000084  000be024\nRootfs offset           00000088  00100000\nRootfs length           0000008C  006c0000\nBootloader offset       00000090  00000000\nBootloader length       00000094  00000000\nFirmware version        00000098  0003          (3.13.6)\n                        0000009A  000d\n                        0000009C  0006\n                        0000009E  00 00 00 00\n                        *\n                        000001FC  00 00 00 00\n\n\nNotes:\n\n    I was unable to determine precisely how the kernel checksum is\n    calculated nor the MD5Key used as this is not referred to anywhere\n    in the TP-Link router program (/usr/bin/httpd).\n\n    However I am certain that this is the kernel checksum as I have two\n    pairs of images with the same checksum in this position, from two\n    different devices. Extracting and decompressing the kernel from these\n    images gave me four files with the same MD5 hash. It seems obvious to\n    me that the difference between the pairs is due to the different\n    product ids in the header.\n\n\nLicense:\n\n    Copyright (c) 2012 Jonathan McGowan\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License version 2 or\n    later as published by the Free Software Foundation.\n"
  },
  {
    "path": "src/tpl-tool/doc/Readme",
    "content": "Description:\r\n\r\n    tpl-tool is a tool for extracting and rebuilding official TP-Link\r\n    firmware images for their router products.\r\n\r\n    It has been successfully tested with twenty four different images\r\n    from seven different products. This is only a very small selection of\r\n    the hundred and something available from the TP-Link website. However\r\n    it should work with any official or third-party firmware image which\r\n    uses the same format with the exception of OpenWrt images.\r\n\r\n    OpenWrt images do NOT have a 'standard' TP-Link image layout despite\r\n    having a valid header and do NOT extract correctly.\r\n\r\n\r\nUsage:\r\n\r\n    tpl-tool <option> <file> [-o <file>]\r\n\r\n    -s <file>   Show image header information in a human readable form.\r\n\r\n    -x <file>   Extracts the individual parts of an image to the following\r\n                files.\r\n\r\n                    <file>-header\r\n                    <file>-bootldr  (when present)\r\n                    <file>-kernel\r\n                    <file>-rootfs\r\n\r\n                Where <file> is either the input filename or that\r\n                specified with -o\r\n\r\n    -b <file>   Rebuilds an image from the individual parts extracted\r\n                with -x\r\n\r\n                    <file>-header\r\n                    <file>-bootldr  (when present)\r\n                    <file>-kernel\r\n                    <file>-rootfs\r\n\r\n                Where <file> is the input filename and the output file\r\n                either <file>-new or that specified with -o\r\n\r\n    -o <file>   Specify an alternative output filename.\r\n\r\n    -h          Show version and usage info.\r\n\r\n\r\nLicense:\r\n\r\n    Copyright (c) 2012 Jonathan McGowan\r\n\r\n    This program is free software; you can redistribute it and/or modify\r\n    it under the terms of the GNU General Public License version 2 or\r\n    later as published by the Free Software Foundation.\r\n"
  },
  {
    "path": "src/tpl-tool/src/Makefile",
    "content": "CC=gcc\nCFLAGS=-O2\nTARGET=tpl-tool\n\n$(TARGET): $(TARGET).o md5.o\n\t$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET).o md5.o -o $(TARGET)\n\n$(TARGET).o: $(TARGET).c\n\t$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET).c -c\n\nmd5.o:\n\t$(CC) $(CFLAGS) $(LDFLAGS) md5.c -c\n\nclean:\n\trm -f $(TARGET) *.o\n"
  },
  {
    "path": "src/tpl-tool/src/md5.c",
    "content": "\n\n/*\n ***********************************************************************\n ** md5.c -- the source code for MD5 routines                         **\n ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **\n ** Created: 2/17/90 RLR                                              **\n ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **\n ***********************************************************************\n */\n\n/*\n ***********************************************************************\n ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **\n **                                                                   **\n ** License to copy and use this software is granted provided that    **\n ** it is identified as the \"RSA Data Security, Inc. MD5 Message-     **\n ** Digest Algorithm\" in all material mentioning or referencing this  **\n ** software or this function.                                        **\n **                                                                   **\n ** License is also granted to make and use derivative works          **\n ** provided that such works are identified as \"derived from the RSA  **\n ** Data Security, Inc. MD5 Message-Digest Algorithm\" in all          **\n ** material mentioning or referencing the derived work.              **\n **                                                                   **\n ** RSA Data Security, Inc. makes no representations concerning       **\n ** either the merchantability of this software or the suitability    **\n ** of this software for any particular purpose.  It is provided \"as  **\n ** is\" without express or implied warranty of any kind.              **\n **                                                                   **\n ** These notices must be retained in any copies of any part of this  **\n ** documentation and/or software.                                    **\n ***********************************************************************\n */\n\n#include <string.h>\n#include \"md5.h\"\n\n/*\n ***********************************************************************\n **  Message-digest routines:                                         **\n **  To form the message digest for a message M                       **\n **    (1) Initialize a context buffer mdContext using MD5_Init       **\n **    (2) Call MD5_Update on mdContext and M                         **\n **    (3) Call MD5_Final on mdContext                                **\n **  The message digest is now in mdContext->digest[0...15]           **\n ***********************************************************************\n */\n\n/* forward declaration */\nstatic void Transform ();\n\nstatic unsigned char PADDING[64] = {\n  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\n};\n\n/* F, G, H and I are basic MD5 functions */\n#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))\n#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))\n#define H(x, y, z) ((x) ^ (y) ^ (z))\n#define I(x, y, z) ((y) ^ ((x) | (~z)))\n\n/* ROTATE_LEFT rotates x left n bits */\n#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))\n\n/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */\n/* Rotation is separate from addition to prevent recomputation */\n#define FF(a, b, c, d, x, s, ac) \\\n  {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n#define GG(a, b, c, d, x, s, ac) \\\n  {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n#define HH(a, b, c, d, x, s, ac) \\\n  {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n#define II(a, b, c, d, x, s, ac) \\\n  {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \\\n   (a) = ROTATE_LEFT ((a), (s)); \\\n   (a) += (b); \\\n  }\n\n#ifdef __STDC__\n#define UL(x)\tx##U\n#else\n#define UL(x)\tx\n#endif\n\n/* The routine MD5_Init initializes the message-digest context\n   mdContext. All fields are set to zero.\n */\nvoid MD5_Init (mdContext)\nMD5_CTX *mdContext;\n{\n  mdContext->i[0] = mdContext->i[1] = (UINT4)0;\n\n  /* Load magic initialization constants.\n   */\n  mdContext->buf[0] = (UINT4)0x67452301;\n  mdContext->buf[1] = (UINT4)0xefcdab89;\n  mdContext->buf[2] = (UINT4)0x98badcfe;\n  mdContext->buf[3] = (UINT4)0x10325476;\n}\n\n/* The routine MD5Update updates the message-digest context to\n   account for the presence of each of the characters inBuf[0..inLen-1]\n   in the message whose digest is being computed.\n */\nvoid MD5_Update (mdContext, inBuf, inLen)\nMD5_CTX *mdContext;\nunsigned char *inBuf;\nunsigned int inLen;\n{\n  UINT4 in[16];\n  int mdi;\n  unsigned int i, ii;\n\n  /* compute number of bytes mod 64 */\n  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);\n\n  /* update number of bits */\n  if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])\n    mdContext->i[1]++;\n  mdContext->i[0] += ((UINT4)inLen << 3);\n  mdContext->i[1] += ((UINT4)inLen >> 29);\n\n  while (inLen--) {\n    /* add new character to buffer, increment mdi */\n    mdContext->in[mdi++] = *inBuf++;\n\n    /* transform if necessary */\n    if (mdi == 0x40) {\n      for (i = 0, ii = 0; i < 16; i++, ii += 4)\n        in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |\n                (((UINT4)mdContext->in[ii+2]) << 16) |\n                (((UINT4)mdContext->in[ii+1]) << 8) |\n                ((UINT4)mdContext->in[ii]);\n      Transform (mdContext->buf, in);\n      mdi = 0;\n    }\n  }\n}\n\n/* The routine MD5Final terminates the message-digest computation and\n   ends with the desired message digest in mdContext->digest[0...15].\n */\nvoid MD5_Final (hash, mdContext)\nunsigned char hash[];\nMD5_CTX *mdContext;\n{\n  UINT4 in[16];\n  int mdi;\n  unsigned int i, ii;\n  unsigned int padLen;\n\n  /* save number of bits */\n  in[14] = mdContext->i[0];\n  in[15] = mdContext->i[1];\n\n  /* compute number of bytes mod 64 */\n  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);\n\n  /* pad out to 56 mod 64 */\n  padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);\n  MD5_Update (mdContext, PADDING, padLen);\n\n  /* append length in bits and transform */\n  for (i = 0, ii = 0; i < 14; i++, ii += 4)\n    in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |\n            (((UINT4)mdContext->in[ii+2]) << 16) |\n            (((UINT4)mdContext->in[ii+1]) << 8) |\n            ((UINT4)mdContext->in[ii]);\n  Transform (mdContext->buf, in);\n\n  /* store buffer in digest */\n  for (i = 0, ii = 0; i < 4; i++, ii += 4) {\n    mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);\n    mdContext->digest[ii+1] =\n      (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);\n    mdContext->digest[ii+2] =\n      (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);\n    mdContext->digest[ii+3] =\n      (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);\n  }\n  memcpy(hash, mdContext->digest, 16);\n}\n\n/* Basic MD5 step. Transforms buf based on in.\n */\nstatic void Transform (buf, in)\nUINT4 *buf;\nUINT4 *in;\n{\n  UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];\n\n  /* Round 1 */\n#define S11 7\n#define S12 12\n#define S13 17\n#define S14 22\n  FF ( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */\n  FF ( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */\n  FF ( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */\n  FF ( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */\n  FF ( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */\n  FF ( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */\n  FF ( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */\n  FF ( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */\n  FF ( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */\n  FF ( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */\n  FF ( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */\n  FF ( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */\n  FF ( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */\n  FF ( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */\n  FF ( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */\n  FF ( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */\n\n  /* Round 2 */\n#define S21 5\n#define S22 9\n#define S23 14\n#define S24 20\n  GG ( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */\n  GG ( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */\n  GG ( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */\n  GG ( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */\n  GG ( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */\n  GG ( d, a, b, c, in[10], S22, UL(  38016083)); /* 22 */\n  GG ( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */\n  GG ( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */\n  GG ( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */\n  GG ( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */\n  GG ( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */\n  GG ( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */\n  GG ( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */\n  GG ( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */\n  GG ( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */\n  GG ( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */\n\n  /* Round 3 */\n#define S31 4\n#define S32 11\n#define S33 16\n#define S34 23\n  HH ( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */\n  HH ( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */\n  HH ( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */\n  HH ( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */\n  HH ( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */\n  HH ( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */\n  HH ( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */\n  HH ( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */\n  HH ( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */\n  HH ( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */\n  HH ( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */\n  HH ( b, c, d, a, in[ 6], S34, UL(  76029189)); /* 44 */\n  HH ( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */\n  HH ( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */\n  HH ( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */\n  HH ( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */\n\n  /* Round 4 */\n#define S41 6\n#define S42 10\n#define S43 15\n#define S44 21\n  II ( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */\n  II ( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */\n  II ( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */\n  II ( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */\n  II ( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */\n  II ( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */\n  II ( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */\n  II ( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */\n  II ( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */\n  II ( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */\n  II ( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */\n  II ( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */\n  II ( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */\n  II ( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */\n  II ( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */\n  II ( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */\n\n  buf[0] += a;\n  buf[1] += b;\n  buf[2] += c;\n  buf[3] += d;\n}\n\n/*\n ***********************************************************************\n ** End of md5.c                                                      **\n ******************************** (cut) ********************************\n */\n"
  },
  {
    "path": "src/tpl-tool/src/md5.h",
    "content": "/*\n ***********************************************************************\n ** md5.h -- header file for implementation of MD5                    **\n ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **\n ** Created: 2/17/90 RLR                                              **\n ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version               **\n ** Revised (for MD5): RLR 4/27/91                                    **\n **   -- G modified to have y&~z instead of y&z                       **\n **   -- FF, GG, HH modified to add in last register done             **\n **   -- Access pattern: round 2 works mod 5, round 3 works mod 3     **\n **   -- distinct additive constant for each step                     **\n **   -- round 4 added, working mod 7                                 **\n ***********************************************************************\n */\n\n/*\n ***********************************************************************\n ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **\n **                                                                   **\n ** License to copy and use this software is granted provided that    **\n ** it is identified as the \"RSA Data Security, Inc. MD5 Message-     **\n ** Digest Algorithm\" in all material mentioning or referencing this  **\n ** software or this function.                                        **\n **                                                                   **\n ** License is also granted to make and use derivative works          **\n ** provided that such works are identified as \"derived from the RSA  **\n ** Data Security, Inc. MD5 Message-Digest Algorithm\" in all          **\n ** material mentioning or referencing the derived work.              **\n **                                                                   **\n ** RSA Data Security, Inc. makes no representations concerning       **\n ** either the merchantability of this software or the suitability    **\n ** of this software for any particular purpose.  It is provided \"as  **\n ** is\" without express or implied warranty of any kind.              **\n **                                                                   **\n ** These notices must be retained in any copies of any part of this  **\n ** documentation and/or software.                                    **\n ***********************************************************************\n */\n\n#ifndef __MD5_INCLUDE__\n\n/* typedef a 32-bit type */\n#ifdef _LP64\ntypedef unsigned int UINT4;\ntypedef int          INT4;\n#else\ntypedef unsigned long UINT4;\ntypedef long          INT4;\n#endif\n#define _UINT4_T\n\n/* Data structure for MD5 (Message-Digest) computation */\ntypedef struct {\n  UINT4 i[2];                   /* number of _bits_ handled mod 2^64 */\n  UINT4 buf[4];                                    /* scratch buffer */\n  unsigned char in[64];                              /* input buffer */\n  unsigned char digest[16];     /* actual digest after MD5Final call */\n} MD5_CTX;\n\nvoid MD5_Init ();\nvoid MD5_Update ();\nvoid MD5_Final ();\n\n#define __MD5_INCLUDE__\n#endif /* __MD5_INCLUDE__ */\n"
  },
  {
    "path": "src/tpl-tool/src/tpl-factory-to-sysupgrade.sh",
    "content": "#!/bin/sh\n# Jeremy Collake\n# convert vendor firmware images from TP-Link to 'sysupgrade' format expected by OpenWrt and derivatives (e.g. Gargoyle)\n# strips first 0x20200 bytes (yes, that much)\nIN_IMG=\"${1}\"\nOUT_IMG=\"${2}\"\nif [ \"${IN_IMG}\" = \"\" ] || [ \"${IN_IMG}\" = \"-h\" ] || [ \"${OUT_IMG}\" = \"\" ] || [ \"${OUT_IMG}\" = \"-h\" ]; then\n\tprintf \" Usage: tpl-factory-to-sysupgrade.sh input_firmware output_firmware\\r\\n\"\n\texit 1\nfi\ndd \"if=${IN_IMG}\" \"of=${OUT_IMG}\" skip=257 bs=512 2>/dev/null\nTPL_SANITY_TMP_FILE=`mktemp`\ndd \"if=${OUT_IMG}\" \"of=${TPL_SANITY_TMP_FILE}\" skip=1 bs=4 count=6 2>/dev/null\nVENDOR_SIGNATURE=`cat \"${TPL_SANITY_TMP_FILE}\"`\nprintf \"\\r\\n The vendor signature appears to be: \" ${VENDOR_SIGNATURE}\necho $VENDOR_SIGNATURE # use echo since it will handle invalid chars differently on output\nprintf \" This is NOT a guarantee that this image is valid.\\r\\n\"\nprintf \" If the above is empty or gibberish, the image is likely not valid though.\\r\\n\\r\\n\"\nrm -f \"${TPL_SANITY_TMP_FILE}\"\n\n\n\n\n\n"
  },
  {
    "path": "src/tpl-tool/src/tpl-tool.c",
    "content": "/*\n * TP-Link firmware image extraction and rebuilding tool.\n *\n * Copyright (c) 2012 Jonathan McGowan <jonathan@howlingwolf.org.uk>\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License version 2 or later\n * as published by the Free Software Foundation.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <unistd.h>     \t/* for unlink() */\n#include <getopt.h>\n#include <stdarg.h>\n#include <errno.h>\n#include <sys/stat.h>\n\n#include <netinet/in.h>\t\t/* for network / host byte order conversions */\n\n#include \"md5.h\"\n\n\n#define PROGRAM_NAME\t\"tpl-tool\"\n#define PROGRAM_VER\t\t\"1.2\"\n\n/*\n * During testing against non-official firmware images I discovered that\n * OpenWrt images are broken despite having a valid image header. The\n * root filesystem follows directly after the kernel and not at the\n * offset specified.\n *\n * As a result they do *NOT* extract correctly.\n *\n * It would be possible to handle this but as they have their own build\n * system which is probably better suited, and everything else seems to\n * be handled correctly I decided to simply reject OpenWrt images rather\n * than risk a bad rebuild which might pass firmware update checks.\n */\n\n#define BAD_VENDOR\t\t\"OpenWrt\"\n\n/*\n * All of the official firmware images available from the TP-Link website\n * at this time use the values defined below.\n */\n\n#define HEADER_VERSION\t\t0x01000000\n#define\tIMAGE2_OFFSET\t\t0x00020200\n#define ROOTFS_OFFSET\t\t0x00100000\n#define FLASH_4M\t\t\t0x003c0000\n#define FLASH_8M\t\t\t0x007c0000\n\n#define MD5SUM_LEN\t16\n\n\nstruct image_header {\n\tuint32_t\theader_version;\n\tchar\t\timage_vendor[24];\n\tchar\t\timage_version[36];\n\tuint32_t\tproduct_id;\n\tuint32_t\tproduct_ver;\n\tuint32_t\tpadding1;\n\tuint8_t\timage_checksum[MD5SUM_LEN];\n\tuint32_t\tpadding2;\n\tuint8_t\tkernel_checksum[MD5SUM_LEN];\n\tuint32_t\tpadding3;\n\tuint32_t\tkernel_loadaddr;\t/* kernel load address */\n\tuint32_t\tkernel_entrypoint;\t/* kernel entry point */\n\tuint32_t\timage_length;\n\tuint32_t\tkernel_offset;\t\t/* kernel data offset */\n\tuint32_t\tkernel_length;\t\t/* kernel data length */\n\tuint32_t\trootfs_offset;\t\t/* rootfs data offset */\n\tuint32_t\trootfs_length;\t\t/* rootfs data length */\n\tuint32_t\tbootldr_offset;\t\t/* bootloader data offset */\n\tuint32_t\tbootldr_length;\t\t/* bootloader data length */\n\tuint16_t\tfw_ver_major;\t\t/* firmware version */\n\tuint16_t\tfw_ver_minor;\n\tuint16_t\tfw_ver_point;\n\tuint8_t\tpadding4[354];\n} __attribute__ ((packed));\n\nstruct device_info {\n\tuint32_t\tprod_id;\n\tuint32_t\tprod_ver;\n\tchar\t\t*name;\n\tuint32_t\tflash_size;\n};\n\nstruct file_info {\n\tchar\t\t*name;\n\tuint32_t\tsize;\n};\n\nchar MD5Key[MD5SUM_LEN] = {\n\t0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb,\n\t0xdd, 0xf9, 0xe7, 0xf4, 0x0e, 0xae, 0x47, 0x38,\n};\n\nchar MD5Key_bootldr[MD5SUM_LEN] = {\n\t0x8c, 0xef, 0x33, 0x5b, 0xd5, 0xc5, 0xce, 0xfa,\n\t0xa7, 0x9c, 0x28, 0xda, 0xb2, 0xe9, 0x0f, 0x42,\n};\n\n/*\n * Adding new devices.\n *\n * Create a new entry in the structure below and fill in the appropriate\n * values for the new device.\n *\n * Name from the image filename or the TP-Link website.\n * Product id and version from the header using the -s option.\n * Flash size from the header Image Size or Image2 Size if a bootloader\n * is present. ie. 0x003c0000 is 4M and 0x007c0000 is 8M.\n */\n\nstatic struct device_info devices[] = {\n\t/* Product id, Product version, Name, Flash size */\n\t{0x08010001,\t1,\t\"TL-WA801NDv1\",\t\tFLASH_4M},\n\t{0x09010001,\t1,\t\"TL-WA901NDv1\",\t\tFLASH_4M},\n\t{0x09010002,\t1,\t\"TL-WA901NDv2\",\t\tFLASH_4M},\n\t{0x09410002,\t2,\t\"TL-WR941NDv2\",\t\tFLASH_4M},\n\t{0x09410004,\t1,\t\"TL-WR941NDv4\",\t\tFLASH_4M},\n\t{0x10420001,\t1,\t\"TL-WR1042NDv1\",\tFLASH_8M},\n\t{0x10430001,\t1,\t\"TL-WR1043NDv1\",\tFLASH_8M},\n\t{0x25430001,\t1,\t\"TL-WR2543Nv1\",\t\tFLASH_8M},\n\t{0x43000001,\t1,\t\"TL-WDR4300v1\",\t\tFLASH_8M},\n\t{\t/* Null entry to mark end of table */\t}\n};\n\n\n/*\n * Console output macros.\n */\n\n#define ERROR(fmt, ...) \\\n\tdo { \\\n\t\tfflush(0); \\\n\t\tfprintf(stderr, \"[%s] *** ERROR: \" fmt \"\\n\", PROGRAM_NAME, ## __VA_ARGS__ ); \\\n\t} while (0)\n\n#define WARN(fmt, ...) \\\n\tdo { \\\n\t\tfprintf(stderr, \"[%s] WARNING: \" fmt \"\\n\", PROGRAM_NAME, ## __VA_ARGS__ ); \\\n\t} while (0)\n\n#define PRINT_STR(label, str) printf(\"%-19s: %s\\n\", label, str)\n\n#define PRINT_HEX(label, value, str) printf(\"%-19s: 0x%08x%s\\n\", label, value, str)\n\n#define PRINT_BOTH(label, value) printf(\"%-19s: 0x%08x / %7u\\n\", label, value, value)\n\n#define PRINT_PROD_ID(label, value, str) printf(\"%-19s: 0x%08x  (%s)\\n\", label, value, str)\n\n\nstatic void usage(void)\n{\n\tfprintf(stderr, \"%s %s (%s)\\n\", PROGRAM_NAME, PROGRAM_VER, __DATE__);\n\tfprintf(stderr, \"Copyright (C) 2012 Jonathan McGowan\\n\\n\");\n\tfprintf(stderr, \"Usage: %s <option> <file> [-o <file>]\\n\", PROGRAM_NAME);\n\tfprintf(stderr,\n\t\t\"\\n\"\n\t\t\"Options:\\n\"\n\t\t\"  -s <file>    Show firmware image header information.\\n\"\n\t\t\"  -b <file>    Rebuild firmware image.\\n\"\n\t\t\"  -x <file>    Extract firmware image.\\n\"\n\t\t\"  -o <file>    Specify an alternative output filename.\\n\"\n\t\t\"\\n\"\n\t\t\"  -h           Show this message.\\n\"\n\t);\n}\n\n\nstatic struct device_info *get_device_info(uint32_t prod_id)\n{\n\tstruct device_info *ret;\n\tstruct device_info *device;\n\n\tret = NULL;\n\tif (prod_id == 0)\n\t\tgoto out;\n\n\tfor (device = devices; device->name != NULL; device++) {\n\t\tif (prod_id == device->prod_id) {\n\t\t\tret = device;\n\t\t\tbreak;\n\t\t}\n\t};\n\n out:\n\treturn ret;\n}\n\n/*\n * Helper function used to simplify checksum generation/verification code.\n *\n * Selects the appropriate key value (normal/bootldr), generates an\n * MD5 hash of the data specified and returns the result of comparing\n * the new MD5 hash with the original. A flag value controls restoration\n * of the original hash value.\n */\n\nstatic int checksum(char *buf, int len, int overwrite)\n{\n\tMD5_CTX ctx;\n\tstruct image_header *hdr;\n\tuint8_t old_checksum[MD5SUM_LEN];\n\tint ret;\n\n\thdr = (struct image_header *)buf;\n\tmemcpy(old_checksum, hdr->image_checksum, MD5SUM_LEN);\n\n\tif (ntohl(hdr->bootldr_length) == 0)\n\t\tmemcpy(hdr->image_checksum, MD5Key, MD5SUM_LEN);\n\telse\n\t\tmemcpy(hdr->image_checksum, MD5Key_bootldr, MD5SUM_LEN);\n\n\tMD5_Init(&ctx);\n\tMD5_Update(&ctx, buf, len);\n\tMD5_Final(hdr->image_checksum, &ctx);\n\n\tret = memcmp(hdr->image_checksum, old_checksum, MD5SUM_LEN);\n\n\tif (!overwrite)\n\t\tmemcpy(hdr->image_checksum, old_checksum, MD5SUM_LEN);\n\n\treturn ret;\n}\n\n\n/*\n * File I/O functions.\n */\n\nstatic int get_file_size(struct file_info *fdata)\n{\n\tstruct stat st;\n\tint ret = EXIT_FAILURE;\n\n\tif (fdata->name == NULL)\n\t\tgoto out;\n\n\tret = stat(fdata->name, &st);\n\tif (ret)\n\t\tgoto out;\n\n\tfdata->size = st.st_size;\n\tret = EXIT_SUCCESS;\n\n out:\n\treturn ret;\n}\n\nstatic int read_to_buffer(struct file_info *fdata, char *buf)\n{\n\tFILE *fp;\n\tint ret = EXIT_FAILURE;\n\n\tfp = fopen(fdata->name, \"r\");\n\tif (fp == NULL)\n\t\tgoto out;\n\n\terrno = 0;\n\tint c = fread(buf, fdata->size, 1, fp);\n\tif (errno != 0)\n\t\tgoto out_close;\n\n\tret = EXIT_SUCCESS;\n\n out_close:\n\tfclose(fp);\n out:\n\treturn ret;\n}\n\nstatic int write_from_buffer(struct file_info *fdata, char *buf)\n{\n\tFILE *fp;\n\tint ret = EXIT_FAILURE;\n\n\tfp = fopen(fdata->name, \"w\");\n\tif (fp == NULL)\n\t\tgoto out;\n\n\terrno = 0;\n\tfwrite(buf, fdata->size, 1, fp);\n\tif (errno != 0)\n\t\tgoto out_flush;\n\n\tret = EXIT_SUCCESS;\n\n out_flush:\n\tfflush(fp);\n\tfclose(fp);\n\tif (ret != EXIT_SUCCESS)\n\t\tunlink(fdata->name);\n out:\n\treturn ret;\n}\n\n\n/*\n * Helper function used to output the image checksums and verification\n * status.\n */\n\nstatic void print_checksum(char *label, uint8_t *chksum, int valid)\n{\n\tint i;\n\n\tprintf(\"%-19s:\", label);\n\tfor (i=0; i<MD5SUM_LEN; i++)\n\t\tprintf(\" %02x\", chksum[i]);\n\n\tswitch (valid) {\n\t\tcase 0:\n\t\t\tprintf(\"  (Invalid)\\n\");\n\t\t\tbreak;\n\t\tcase 1:\n\t\t\tprintf(\"  (Valid)\\n\");\n\t\t\tbreak;\n\t\tcase -1:\n\t\t\tprintf(\"  (Not Verified)\\n\");\n\t\t\tbreak;\n\t}\n}\n\n\n/*\n * Show firmware image header.\n *\n * Outputs the image header in a human readable format.\n */\n\nstatic int show_image_header(char *fname_in)\n{\n\tchar *buf;\n\tstruct file_info fdata;\n\tstruct image_header *hdr;\n\tstruct device_info *device;\n\tint ret = EXIT_FAILURE;\n\n\tfdata.name = fname_in;\n\tret = get_file_size(&fdata);\n\tif (ret) {\n\t\tERROR(\"Image file not found \\\"%s\\\".\", fdata.name);\n\t\tgoto out;\n\t}\n\n\tbuf = malloc(fdata.size);\n\tif (!buf) {\n\t\tERROR(\"Unable to allocate image buffer.\");\n\t\tgoto out;\n\t}\n\n\tret = read_to_buffer(&fdata, buf);\n\tif (ret) {\n\t\tERROR(\"Unable to read image file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_buf;\n\t}\n\n\thdr = (struct image_header *)buf;\n\n\tPRINT_STR(\"Filename\", fdata.name);\n\tPRINT_BOTH(\"Filesize\", fdata.size);\n\tprintf(\"\\n\");\n\n\tif (ntohl(hdr->header_version) != HEADER_VERSION) {\n\t\tERROR(\"Unsupported image header version (%u).\", ntohl(hdr->header_version));\n\t\tgoto out_free_buf;\n\t}\n\n\tPRINT_STR(\"Image Vendor\", hdr->image_vendor);\n\tPRINT_STR(\"Image Version\", hdr->image_version);\n\tPRINT_BOTH(\"Image Size\", ntohl(hdr->image_length));\n\n\tint tmp = (checksum(buf, fdata.size, 0)) ? 0 : 1;\n\tprint_checksum(\"Image Checksum\", hdr->image_checksum, tmp);\n\tprintf(\"\\n\");\n\n\tchar *tmp_str = \"Unknown\";\n\tdevice = get_device_info(ntohl(hdr->product_id));\n\tif (device)\n\t\ttmp_str = device->name;\n\tPRINT_PROD_ID(\"Product Id\", ntohl(hdr->product_id), tmp_str);\n\n\ttmp_str = \"\";\n\tif (device && (device->prod_ver != ntohl(hdr->product_ver)))\n\t\ttmp_str = \"  (Unknown)\";\n\tPRINT_HEX(\"Product Version\", ntohl(hdr->product_ver), tmp_str);\n\n\tprintf(\"%-19s: %u.%u.%u\\n\\n\", \"Firmware Version\", ntohs(hdr->fw_ver_major), \\\n\t\tntohs(hdr->fw_ver_minor), ntohs(hdr->fw_ver_point));\n\n\n\t/* Display bootloader info and shift pointer to inner image */\n\tif (ntohl(hdr->bootldr_length) != 0) {\n\t\tPRINT_BOTH(\"Bootldr Offset\", ntohl(hdr->bootldr_offset));\n\t\tPRINT_BOTH(\"Bootldr Length\", ntohl(hdr->bootldr_length));\n\t\tprintf(\"\\n\");\n\n\t\thdr = (struct image_header *)(buf + IMAGE2_OFFSET);\n\n\t\tPRINT_BOTH(\"Image2 Size\", ntohl(hdr->image_length));\n\n\t\ttmp = (checksum((char *)hdr, fdata.size - IMAGE2_OFFSET, 0)) ? 0 : 1;\n\t\tprint_checksum(\"Image2 Checksum\", hdr->image_checksum, tmp);\n\t\tprintf(\"\\n\");\n\t}\n\n\n\tPRINT_BOTH(\"Kernel Offset\", ntohl(hdr->kernel_offset));\n\tPRINT_BOTH(\"Kernel Length\", ntohl(hdr->kernel_length));\n\tPRINT_HEX(\"Kernel Load Address\", ntohl(hdr->kernel_loadaddr), \"\");\n\tPRINT_HEX(\"Kernel Entry Point\", ntohl(hdr->kernel_entrypoint), \"\");\n\tprint_checksum(\"Kernel Checksum\", hdr->kernel_checksum, -1);\n\tprintf(\"\\n\");\n\n\tPRINT_BOTH(\"Rootfs Offset\", ntohl(hdr->rootfs_offset));\n\tPRINT_BOTH(\"Rootfs Length\", ntohl(hdr->rootfs_length));\n\n\n out_free_buf:\n\tfree(buf);\n out:\n\treturn ret;\n}\n\n\n/*\n * Extract firmware image.\n *\n * Extracts the individual parts of an image to the following files.\n * \n * <file>-header\n * <file>-bootldr  (when present)\n * <file>-kernel\n * <file>-rootfs\n * \n * Where <file> is either the input filename or that specified with -o\n */\n\nstatic int extract_image(char *fname_in, char *fname_out)\n{\n\tchar *buf;\n\tchar *new_name;\n\tstruct file_info fdata;\n\tstruct image_header *hdr;\n\tstruct device_info *device;\n\tint buf_offset;\n\tint bootldr_present = 0;\n\tint ret = EXIT_FAILURE;\n\n\tif (fname_out == NULL)\n\t\tfname_out = fname_in;\n\n\tfdata.name = fname_in;\n\tret = get_file_size(&fdata);\n\tif (ret) {\n\t\tERROR(\"Image file not found \\\"%s\\\".\", fdata.name);\n\t\tgoto out;\n\t}\n\n\tbuf = malloc(fdata.size);\n\tif (!buf) {\n\t\tERROR(\"Unable to allocate image buffer.\");\n\t\tgoto out;\n\t}\n\n\tret = read_to_buffer(&fdata, buf);\n\tif (ret) {\n\t\tERROR(\"Unable to read image file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_buf;\n\t}\n\n\thdr = (struct image_header *)buf;\n\n\n\t/* Check header version and hardware id */\n\tif (ntohl(hdr->header_version) != HEADER_VERSION) {\n\t\tERROR(\"Unsupported image header version (%u).\", ntohl(hdr->header_version));\n\t\tgoto out_free_buf;\n\t}\n\n\t/* OpenWrt images are broken */\n\tif (!strncasecmp(hdr->image_vendor, BAD_VENDOR, sizeof(hdr->image_vendor))) {\n\t\tERROR(\"OpenWrt images do not extract correctly.\");\n\t\tgoto out_free_buf;\n\t}\n\n\tdevice = get_device_info(ntohl(hdr->product_id));\n\tif (!device) {\n\t\tWARN(\"Unknown device (0x%08x).\", ntohl(hdr->product_id));\n\t\tWARN(\"Component files may not be valid.\");\n\t}\n\n\t/* Verify image checksum */\n\tif (checksum(buf, fdata.size, 0)) {\n\t\tWARN(\"Invalid Image Checksum.\");\n\t\tWARN(\"Component files may not be valid.\");\n\t}\n\n\tbootldr_present = (ntohl(hdr->bootldr_length) == 0) ? 0 : 1;\n\n\tnew_name = malloc(strlen(fname_out) + 9);\n\tif (!new_name) {\n\t\tERROR(\"Unable to allocate space for filenames.\");\n\t\tgoto out_free_buf;\n\t}\n\tfdata.name = new_name;\n\n\n\t/* Save header block */\n\tsprintf(fdata.name, \"%s-header\", fname_out);\n\tfdata.size = sizeof(struct image_header);\n\tret = write_from_buffer(&fdata, buf);\n\tif (ret) {\n\t\tERROR(\"Unable to create image header file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_name;\n\t}\n\n\n\t/* Save bootloader image */\n\tif (bootldr_present) {\n\t\tfdata.size = ntohl(hdr->bootldr_length);\n\t\tsprintf(fdata.name, \"%s-bootldr\", fname_out);\n\n\t\tret = write_from_buffer(&fdata, buf + sizeof(struct image_header));\n\t\tif (ret) {\n\t\t\tERROR(\"Unable to create bootloader file \\\"%s\\\".\", fdata.name);\n\t\t\tgoto out_free_name;\n\t\t}\n\t}\n\n\n\t/* Move pointer to inner image and verify checksum */\n\tif (bootldr_present) {\n\t\thdr = (struct image_header *)(buf + IMAGE2_OFFSET);\n\n\t\tif (checksum((char *)hdr, ntohl(hdr->image_length), 0)) {\n\t\t\tWARN(\"Invalid Image2 Checksum.\");\n\t\t\tWARN(\"kernel/rootfs files may not be valid.\");\n\t\t}\n\t}\n\n\t/* Save kernel image */\n\tbuf_offset = ntohl(hdr->kernel_offset);\n\tif (buf_offset != sizeof(struct image_header))\n\t\tWARN(\"Non standard kernel offset (0x%08x).\", buf_offset);\n\n\tsprintf(fdata.name, \"%s-kernel\", fname_out);\n\tfdata.size = ntohl(hdr->kernel_length);\n\n\tret = write_from_buffer(&fdata, ((char *)hdr) + buf_offset);\n\tif (ret) {\n\t\tERROR(\"Unable to create kernel file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_name;\n\t}\n\n\n\t/* Save root filesystem image */\n\tbuf_offset = ntohl(hdr->rootfs_offset);\n\tif (buf_offset != ROOTFS_OFFSET)\n\t\tWARN(\"Non standard rootfs offset (0x%08x).\", buf_offset);\n\n\tsprintf(fdata.name, \"%s-rootfs\", fname_out);\n\tfdata.size = ntohl(hdr->rootfs_length);\n\n\tret = write_from_buffer(&fdata, ((char *)hdr) + buf_offset);\n\tif (ret) {\n\t\tERROR(\"Unable to create rootfs file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_name;\n\t}\n\n\tprintf(\"Image file \\\"%s\\\" successfully extracted.\\n\", fname_in);\n\n\n out_free_name:\n\tfree(new_name);\n out_free_buf:\n\tfree(buf);\n out:\n\treturn ret;\n}\n\n\n/*\n * Rebuild firmware image.\n *\n * Rebuilds an image from the individual parts extracted with -x\n * \n * <file>-header\n * <file>-bootldr  (when present)\n * <file>-kernel\n * <file>-rootfs\n *\n * Where <file> is the input filename and the output file either\n * <file>-new or that specified with -o\n *\n * Firmware images which include a bootloader have an 'image within image'\n * structure consisting of a 'standard' kernel/rootfs image within a\n * larger image.\n *\n * -----------------------------------------\n * |     |     |                           |\n * |     |     |    -------------------    |\n * |     |     |    |     |     |     |    |\n * |  h  |  b  |    |  h  |  k  |  r  |    |\n * |  e  |  o  |    |  e  |  e  |  o  |    |\n * |  a  |  o  |    |  a  |  r  |  o  |    |\n * |  d  |  t  |    |  d  |  n  |  t  |    |\n * |  r  |  l  |    |  e  |  e  |  f  |    |\n * |     |  d  |    |  r  |  l  |  s  |    |\n * |     |  r  |    |     |     |     |    |\n * |     |     |    -------------------    |\n * |     |     |                           |\n * -----------------------------------------\n */\n\nstatic int build_image(char *fname_in, char *fname_out)\n{\n\tchar *new_name;\n\tchar *hdr_buf;\n\tchar *img_buf;\n\tstruct file_info fdata;\n\tstruct image_header *hdr;\n\tstruct device_info *device;\n\n\tstruct {\n\t\tstruct image_header *hdr;\n\t\tchar *kernel_buf;\n\t\tchar *rootfs_buf;\n\t} img;\n\n\tstruct {\n\t\tstruct image_header *hdr;\n\t\tchar *bootldr_buf;\n\t} img_b;\n\n\tint max_length;\n\tint buf_size;\n\tint ret = EXIT_FAILURE;\n\n\n\tnew_name = malloc(strlen(fname_in) + 9);\n\tif (!new_name) {\n\t\tERROR(\"Unable to allocate space for filenames.\");\n\t\tgoto out;\n\t}\n\tfdata.name = new_name;\n\n\n\t/* Read image header file */\n\tsprintf(fdata.name, \"%s-header\", fname_in);\n\tret = get_file_size(&fdata);\n\tif (ret) {\n\t\tERROR(\"Header file not found \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_name;\n\t}\n\n\tif (fdata.size != sizeof(struct image_header)) {\t\t/* Sanity check */\n\t\tERROR(\"Wrong size header file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_name;\n\t}\n\n\thdr_buf = malloc(sizeof(struct image_header));\n\tif (!hdr_buf) {\n\t\tERROR(\"Unable to allocate space for image header.\");\n\t\tgoto out_free_name;\n\t}\n\n\tret = read_to_buffer(&fdata, hdr_buf);\n\tif (ret) {\n\t\tERROR(\"Unable to read image header file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_hdr;\n\t}\n\n\thdr = (struct image_header *)hdr_buf;\n\n\n\t/* Header sanity checks */\n\tif (ntohl(hdr->header_version) != HEADER_VERSION) {\n\t\tERROR(\"Unsupported image header version (%u).\", ntohl(hdr->header_version));\n\t\tgoto out_free_hdr;\n\t}\n\n\tif (ntohl(hdr->bootldr_offset) != 0) {\n\t\tERROR(\"Bootloader offset must be 0 (0x%08x).\", ntohl(hdr->bootldr_offset));\n\t\tgoto out_free_hdr;\n\t}\n\n\t/* OpenWrt images are broken */\n\tif (!strncasecmp(hdr->image_vendor, BAD_VENDOR, sizeof(hdr->image_vendor))) {\n\t\tERROR(\"Rebuilding OpenWrt images is not supported.\");\n\t\tgoto out_free_hdr;\n\t}\n\n\tif (ntohl(hdr->kernel_offset) != sizeof(struct image_header))\n\t\tWARN(\"Non standard kernel offset (0x%08x).\", ntohl(hdr->kernel_offset));\n\n\tif (ntohl(hdr->rootfs_offset) != ROOTFS_OFFSET)\n\t\tWARN(\"Non standard rootfs offset (0x%08x).\", ntohl(hdr->rootfs_offset));\n\n\n\t/* Get image size from device info or header and set buffer size */\n\tdevice = get_device_info(ntohl(hdr->product_id));\n\tif (device) {\n\t\tbuf_size = device->flash_size + IMAGE2_OFFSET;\n\t\tmax_length = device->flash_size;\n\t}\n\telse {\n\t\tWARN(\"Unknown device (0x%08x).\", ntohl(hdr->product_id));\n\t\tWARN(\"Using image size from header.\");\n\n\t\tbuf_size = ntohl(hdr->image_length);\n\t\tif (ntohl(hdr->bootldr_length) != 0)\n\t\t\tmax_length = buf_size - IMAGE2_OFFSET;\n\t\telse {\n\t\t\tmax_length = buf_size;\n\t\t\tbuf_size += IMAGE2_OFFSET;\n\t\t}\n\t}\n\n\n\t/* Allocate buffer, set pointers and copy image header to buffer */\n\timg_buf = malloc(buf_size);\n\tif (!img_buf) {\n\t\tERROR(\"Unable to allocate image buffer.\");\n\t\tgoto out_free_hdr;\n\t}\n\n\tmemset(img_buf, 0xff, buf_size);\n\n\timg_b.hdr = (struct image_header *)img_buf;\n\timg_b.bootldr_buf = img_buf + sizeof(struct image_header);\n\n\timg.hdr = (struct image_header *)(img_buf + IMAGE2_OFFSET);\n\timg.kernel_buf = ((char *)img.hdr) + ntohl(hdr->kernel_offset);\n\timg.rootfs_buf = ((char *)img.hdr) + ntohl(hdr->rootfs_offset);\n\n\thdr->bootldr_length = 0;\n\tmemcpy((char *)img.hdr, (char *)hdr, sizeof(struct image_header));\n\n\n\t/* Read kernel image file */\n\tsprintf(fdata.name, \"%s-kernel\", fname_in);\n\tret = get_file_size(&fdata);\n\tif (ret) {\n\t\tERROR(\"Kernel file not found \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_img;\n\t}\n\n\tint tmp = img.hdr->rootfs_offset - img.hdr->kernel_offset;\n\tif (fdata.size > tmp) { \t\t\t\t\t/* Kernel size check */\n\t\tERROR(\"Kernel image too large for image layout.\");\n\t\tgoto out_free_img;\n\t}\n\n\tret = read_to_buffer(&fdata, img.kernel_buf);\n\tif (ret) {\n\t\tERROR(\"Unable to read kernel file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_img;\n\t}\n\timg.hdr->kernel_length = htonl(fdata.size);\n\n\n\t/* Read root filesystem image file */\n\tsprintf(fdata.name, \"%s-rootfs\", fname_in);\n\tret = get_file_size(&fdata);\n\tif (ret) {\n\t\tERROR(\"Rootfs file not found \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_img;\n\t}\n\n\ttmp = max_length - img.hdr->rootfs_offset;\n\tif (fdata.size > tmp) {\t\t\t\t\t\t/* Rootfs size check */\n\t\tERROR(\"Root filesystem too large for image layout.\");\n\t\tgoto out_free_img;\n\t}\n\n\tret = read_to_buffer(&fdata, img.rootfs_buf);\n\tif (ret) {\n\t\tERROR(\"Unable to read rootfs file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_img;\n\t}\n\timg.hdr->rootfs_length = htonl(fdata.size);\n\n\n\t/* Set image length and checksum */\n\timg.hdr->image_length = htonl(max_length);\n\tchecksum((char *)img.hdr, max_length, 1);\n\n\n\t/* read bootloader image file */\n\tsprintf(fdata.name, \"%s-bootldr\", fname_in);\n\tret = get_file_size(&fdata);\n\tif (ret && (ntohl(hdr->bootldr_length) != 0)) {\n\t\tWARN(\"Bootloader length set in header and no bootloader image file was found.\");\n\t\tWARN(\"Bootloader will be omitted from image.\");\n\t}\n\n\tif (!ret) {\n\t\t/* Copy header from inner image */\n\t\tmemcpy((char *)img_b.hdr, (char *)img.hdr, sizeof(struct image_header));\n\n\t\ttmp = sizeof(struct image_header);\n\t\tif ((tmp + fdata.size) > IMAGE2_OFFSET) {\n\t\t\tERROR(\"Bootloader image too large for image layout.\");\n\t\t\tgoto out_free_img;\n\t\t}\n\n\t\tret = read_to_buffer(&fdata, img_b.bootldr_buf);\n\t\tif (ret) {\n\t\t\tERROR(\"Unable to read bootloader file \\\"%s\\\".\", fdata.name);\n\t\t\tgoto out_free_img;\n\t\t}\n\t\timg_b.hdr->bootldr_length = htonl(fdata.size);\n\n\t\t/* Set image length and checksum */\n\t\timg_b.hdr->image_length = htonl(buf_size);\n\t\tchecksum((char *)img_b.hdr, buf_size, 1);\n\n\t\t/* Set image pointer and length for output */\n\t\timg.hdr = img_b.hdr;\n\t\tmax_length = buf_size;\n\t}\n\n\t/* Save new firmware image */\n\tif (fname_out != NULL)\n\t\tfdata.name = fname_out;\n\telse\n\t\tsprintf(fdata.name, \"%s-new\", fname_in);\n\n\tfdata.size = max_length;\n\tret = write_from_buffer(&fdata, (char *)img.hdr);\n\tif (ret) {\n\t\tERROR(\"Unable to create image file \\\"%s\\\".\", fdata.name);\n\t\tgoto out_free_img;\n\t}\n\n\tprintf(\"Image file \\\"%s\\\" successfully rebuilt.\\n\", fdata.name);\n\n out_free_img:\n\tfree(img_buf);\n\n out_free_hdr:\n\tfree(hdr_buf);\n\n out_free_name:\n\tfree(new_name);\n\n out:\n\treturn ret;\n}\n\n\n/*\n * Main Entry Point.\n *\n * Handles options processing and function selection.\n */\n\nint main(int argc, char *argv[])\n{\n\tchar *fname_in;\n\tchar *fname_out = NULL;\n\tint ret = EXIT_FAILURE;\n\tint cmd, opt;\n\n\n\twhile ( 1 ) {\n\t\topt = getopt(argc, argv, \"b:x:s:o:h\");\n\t\tif (opt == -1)\n\t\t\tbreak;\n\n\t\tswitch (opt) {\n\t\t\tcase 'b':\n\t\t\tcase 'x':\n\t\t\t\tcmd = opt;\n\t\t\t\tfname_in = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\tret = show_image_header(optarg);\n\t\t\t\tgoto out;\n\t\t\tcase 'o':\n\t\t\t\tfname_out = optarg;\n\t\t\t\tbreak;\n\t\t\tcase 'h':\n\t\t\tdefault:\n\t\t\t\tusage();\n\t\t\t\tgoto out;\n\t\t}\n\t}\n\n\tswitch (cmd) {\n\t\tcase 'b':\n\t\t\tret = build_image(fname_in, fname_out);\n\t\t\tbreak;\n\t\tcase 'x':\n\t\t\tret = extract_image(fname_in, fname_out);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tusage();\n\t\t\tbreak;\n\t}\n\n out:\n\treturn ret;\n}\n"
  },
  {
    "path": "src/uncramfs/Makefile",
    "content": "# \n# Makefile for uncramfs\n#\n# Copyright Andrew Stitcher, 2001\n#\n# Distributed under the terms of the GPL\n#\n\n.PHONY: clean dist\n\nCOFLAGS:=-r$(TAG)\nCPPFLAGS:=-g -O\nCFLAGS:=-g -O\nLDLIBS:=-lz\n\n#COFILES:=uncramfs.cc uncramfs.c cramfs.h Makefile VERSION README respin.sh uncramfs-w.pl\nCOFILES:=uncramfs.c cramfs.h Makefile VERSION README uncramfs-w.pl\nTARGET:=uncramfs\nDISTFILES=$(COFILES) $(TARGET)\n\ninclude VERSION\nVERSIONED_NAME=$(TARGET)-$(subst \",,$(VERSION))\nDISTFILE=$(VERSIONED_NAME).tar.gz\n\nall: $(TARGET)\n\ndist: $(DISTFILE)\n\nco: $(COFILES)\n\n$(DISTFILE): $(DISTFILES)\n\tmkdir $(VERSIONED_NAME)\n\tcp $^ $(VERSIONED_NAME)\n\ttar cfz $(DISTFILE) $(VERSIONED_NAME)\n\trm -rf $(VERSIONED_NAME)\n\nclean:\n\t-rm $(TARGET)\n\t-rm $(DISTFILE)\n\t-rcsclean\n\n#cuncramfs: uncramfs.c\n#\t$(CC) $(CFLAGS) $< -o $@ $(LDLIBS)\n\n#uncramfs.cc: cramfs.h VERSION\nuncramfs.c: cramfs.h VERSION\n"
  },
  {
    "path": "src/uncramfs/README",
    "content": "Uncramfs v0.7\n-------------\n\nUncramfs is a simple program currently written in C (but I'm working on a more\nfunctional C++ version). Its only purpose in life is to unpack and list the\nfiles in a cramfs image.\n\nNB. this uncramfs includes unconditional support for the non-standard XIP\n(execute in place) feature, whereby executable files are stored uncompressed,\nso they will run directly from ROM (or flash). To activate this you have to\nchmod o+t <file> This feature is currently used by the Agenda Computing VR3 \nLinux PDA.\n\nIt takes 2 command line arguments; the directory to unpack into, and the name\nof the cramfs image.\n\nIf the the unpacking directory name is (or begins with) \"-\" then unpacking is\nturned off and you only get the listing.\n\nIt will print some \"Reassuring\" info about the cramfs image, and the listing\nhas been extensively reworked to look quite like the listing from ls.\n\nIf the effective uid of the execuatble isn't root then it won't even attempt\nto create device nodes, or to set the correct owner and group on the extracted\nfiles.\n\nIt currently doesn't handle unix sockets (but there aren't any in the stock VR3\nimages).\n\nFor example:\n\tuncramfs unpack root-0.20.0.cramfs\nWill unpack the root-0.20.0.cramfs image into the unpack directory;\n\n        uncramfs - root-0.20.0.cramfs\nWill just list the contents of the image.\n\nUncramfs is copyright Andrew Stitcher and licensed under the terms\nof the GNU GPL version 2.\n\nAndrew Stitcher\n6 June 2001\n\nPlease report bugs, send patches, feature suggestions etc. to\n    astitcher@bigfoot.com\n\n---------------\n\nVersion history:\n\nv0.2: First packaged version released to net. Had a killer bug in uncompresssing\n      files that lost all the files blocks after the first!\n\nv0.3: Fix release from cam to remedy the killer bug\n\nv0.3.1: Release from cam which includes some of his scripts\n\nv0.4: [Not released to net]\n      Ported original C++ code to C;\n      Ported cam's bug fix (actually I had independently fixed the bug in my own \n       codebase);\n      Extensively reworked the listing to be as much like ls as possible;\n      Set umask to 0 in uncramfs so the images modes are correctly respected;\n      Don't try to do privileged things unless we are running as root;\n     \nv0.5: [Released to net 6 June 2001]\n      Added README\n      Added some summary stats\n      Can turn off the unpacking so we just get the listing (and summary)\n      All summary info is in [] brackets for easy stripping\n      \nv0.6: [Released on wiki site, 8 June 2001]\n      Context added to notes\n      Fixed bug whereby suid information was reset on chown, leaving suid \n      files without suid permission. Credit to Luis Maria Cruz Vazquez for \n      assistance in nailing this bug. -Cam\n\nv0.7: [Released on wiki site, 24 Oct 2001]\n      Patched by Lev Serebryakov to allow non superuser to unpack safely. \n      Also includes mapping of UID and GID. -Cam\n"
  },
  {
    "path": "src/uncramfs/USE_CRAMFSCK_TO_EXTRACT_INSTEAD_SEE_CRAMFS-2.X_FOLDER",
    "content": "abc\n"
  },
  {
    "path": "src/uncramfs/VERSION",
    "content": "VERSION=\"0.7\"\n"
  },
  {
    "path": "src/uncramfs/cramfs.h",
    "content": "#ifndef __CRAMFS_H\n#define __CRAMFS_H\n\n#define CRAMFS_MAGIC\t\t0x28cd3d45\t/* some random number */\n#define CRAMFS_SIGNATURE\t\"Compressed ROMFS\"\n\n/*\n * Reasonably terse representation of the inode data.\n */\nstruct cramfs_inode {\n\tu32 mode:16, uid:16;\n\t/* SIZE for device files is i_rdev */\n\tu32 size:24, gid:8;\n\t/* NAMELEN is the length of the file name, divided by 4 and\n           rounded up.  (cramfs doesn't support hard links.) */\n\t/* OFFSET: For symlinks and non-empty regular files, this\n\t   contains the offset (divided by 4) of the file data in\n\t   compressed form (starting with an array of block pointers;\n\t   see README).  For non-empty directories it is the offset\n\t   (divided by 4) of the inode of the first file in that\n\t   directory.  For anything else, offset is zero. */\n\tu32 namelen:6, offset:26;\n};\n\n/*\n * Superblock information at the beginning of the FS.\n */\nstruct cramfs_super {\n\tu32 magic;\t\t/* 0x28cd3d45 - random number */\n\tu32 size;\t\t/* Not used.  mkcramfs currently\n                                   writes a constant 1<<16 here. */\n\tu32 flags;\t\t/* 0 */\n\tu32 future;\t\t/* 0 */\n\tu8 signature[16];\t/* \"Compressed ROMFS\" */\n\tu8 fsid[16];\t\t/* random number */\n\tu8 name[16];\t\t/* user-defined name */\n\tstruct cramfs_inode root;\t/* Root inode data */\n};\n\n/*\n * Valid values in super.flags.  Currently we refuse to mount\n * if (flags & ~CRAMFS_SUPPORTED_FLAGS).  Maybe that should be\n * changed to test super.future instead.\n */\n#define CRAMFS_SUPPORTED_FLAGS (0xff)\n\n/* Uncompression interfaces to the underlying zlib */\nint cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);\nint cramfs_uncompress_init(void);\nint cramfs_uncompress_exit(void);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs/uncramfs-w.pl",
    "content": "#!/usr/bin/perl -w\n#---------------------------------------------------------------------------\n# $Id$\n#---------------------------------------------------------------------------\n\n# uncramfs.pl\n\n# start download of root.cramfs.gz then\n# tail -fc +0 root.cramfs.gz |gunzip|../uncramfs.pl|less\n\n# for uncompressed\n# tail -fc +0 root.cramfs |../uncramfs.pl|less\n\nmy $fn = shift @ARGV;\n\n# some definitions\nmy $inode_size = 4+4+4;\nmy $super_size = 4+4+4+4+16+16+16;\n\nmy $address=0;\n\n#subs\nsub decode{\n    my ($buf, @pat) = @_;\n\n    my @types;\n    my @names;\n    \n    while (@pat){\n\tpush @types, shift @pat;\n\tpush @names, shift @pat;\n    }\n    my $spat = join '', @types;\n    my (@values) = unpack $spat, $buf;\n    \n#    print \"pattern \",Dumper($spat, \\@values);\n    \n    my $result = {map {$_ => shift @values} @names};\n    return $result;\n}\n\n# test for directoryness\nsub is_directory{\n    my ($modebits) = @_;\n\n    return ($modebits & 0x4000);\n}\n\nsub rwxbits {\n    my ($modebits) = @_;\n    my $result =\n\t(($modebits & 0x4)?'r':'-').\n\t(($modebits & 0x2)?'w':'-').\n\t(($modebits & 0x1)?'x':'-');\n    return $result;\n}\n\nsub fancymodebits {\n    my ($modebits) = @_;\n\n    my $result;\n    \n    if ($modebits & 0x2000){\n\t$result = 'l';\n    }elsif($modebits & 0x4000){\n\t$result = 'd';\n    }else{\n\t$result = '-';\n    }\n\n    my $or;\n    if ($modebits & 0x800){\n\t$or->{u} = 's';\n    }\n    if ($modebits & 0x400){\n\t$or->{g} = 's';\n    }\n\n    $result .= rwxbits($modebits>>6);\n    $result .= rwxbits($modebits>>3);\n    $result .= rwxbits($modebits);\n}\nsub main {\n    if ($fn){\n\tclose STDIN;\n\topen STDIN, \"<$fn\";\n    }\n    \n    my $cramfs_super='';\n    while (length($cramfs_super) < $super_size){\n\tmy $nread = sysread(STDIN,\n\t\t\t    $cramfs_super,\n\t\t\t    $super_size - length($cramfs_super),\n\t\t\t    length($cramfs_super));\n\tdie \"read failed\"\n\t    if ($nread < 0);\n\t$address += $nread;\n#\tprint \"read $nread\\n\";\n    }\n\n    # NB use 'L' which is endian-sensitive, this matches\n    # cramfs being endian sensitive.\n    my $cramfs_s = decode($cramfs_super, (L=>'magic',\n\t\t\t\t\t  L=>'size',\n\t\t\t\t\t  L=>'flags',\n\t\t\t\t\t  L=>'future',\n\t\t\t\t\t  A16=>'sig',\n\t\t\t\t\t  A16=>'fsid',\n\t\t\t\t\t  A16=>'name'\n\t\t\t\t\t  ));\n    \n    # checks\n    die \"bad magic number\" unless\n\t($cramfs_s->{magic} == 0x28cd3d45);\n#    die \"unexpected size\" unless\n#\t($cramfs_s->{size} == 0x10000);\n    die \"unexpected future\" unless\n\t($cramfs_s->{future} == 0x0);\n#    die \"unexpected flags\" unless\n#\t($cramfs_s->{flags} == 0x0);\n\n    use Data::Dumper;\n#    print Dumper($cramfs_s);\n    printf \"CRAMFS volume ID 0x%s \", (unpack 'H*', $cramfs_s->{fsid});\n    print \"'\",$cramfs_s->{name},\"'\\n\";\n    if ($cramfs_s->{size} != 0x10000){\n\t    print \"size: \",$cramfs_s->{size},\"\\n\";\n    }\n    if ($cramfs_s->{flags} != 0x0){\n\t    printf \"flags: 0x%-8.8x\\n\",$cramfs_s->{flags};\n    }\n\n    # read inodes\n    my $fileOffsets;\n    my $dirOffsets;\n    \n    my $currentPath = '.';\n\n    while(1){\n\tmy $cramfs_inode='';\n\twhile (length($cramfs_inode) < $inode_size){\n\t    my $nread = sysread(STDIN,\n\t\t\t\t$cramfs_inode,\n\t\t\t\t$inode_size - length($cramfs_inode),\n\t\t\t\tlength($cramfs_inode));\n\t    die \"read failed\"\n\t\tif ($nread < 0);\n\t    $address += $nread;\n#\t    print \"read $nread\\n\";\n\t}\n\t\n\tmy $cramfs_i = decode($cramfs_inode, (L=>'modeuid',\n\t\t\t\t\t      L=>'sizegid',\n\t\t\t\t\t      L=>'namelenoffset')\n\t\t\t     );\n\t\n\t# unpack the C compiler's packed fields\n\t$cramfs_i->{mode} = ($cramfs_i->{modeuid} & 0xffff);\n\t$cramfs_i->{uid} = ($cramfs_i->{modeuid} & 0xffff0000)>>16;\n\n\t$cramfs_i->{size} = ($cramfs_i->{sizegid} & 0xffffff);\n\t$cramfs_i->{gid} = ($cramfs_i->{sizegid} & 0xff000000)>>24;\n\n\t$cramfs_i->{namelen} = ($cramfs_i->{namelenoffset} & 0x3f);\n\t$cramfs_i->{offset} = ($cramfs_i->{namelenoffset} & 0xffffffc0)>>6;\n\n\n\tif ($cramfs_i->{namelen}){\n\n\t    # read filename\n\t    my $namebuflen = $cramfs_i->{namelen} * 4;\n\t    my $filename='';\n\t    while (length($filename) < $namebuflen){\n\t\tmy $nread = sysread(STDIN,\n\t\t\t\t    $filename,\n\t\t\t\t    $namebuflen - length($filename),\n\t\t\t\t    length($filename));\n\t\tdie \"read failed\"\n\t\t    if ($nread < 0);\n\t\t$address += $nread;\n#\t\tprint \"read $nread\\n\";\n\t    }\n\t    $filename =~ s/\\0*$//; # remove trailing nulls\n\t    $cramfs_i->{filename} = $currentPath.$filename;\n\t}else{\n\n\t    # no fname to read (root only!!)\n\t    $cramfs_i->{filename} = $currentPath;\n\t}\n#\tprint Dumper($cramfs_i);\n\tmy $debug = '';\n#\t$debug = '(offset %d : %d)';\n\tprintf \"%s %4d %4d %8d %s $debug\\n\",\n\tfancymodebits($cramfs_i->{mode}),\n\t$cramfs_i->{uid},\n\t$cramfs_i->{gid},\n\t$cramfs_i->{size},\n\t$cramfs_i->{filename},\n\t4*$cramfs_i->{offset}, $address;\n\tif (is_directory($cramfs_i->{mode})){\n\t    # insert entry in directory inode map\n\t    $dirOffsets->{4*$cramfs_i->{offset}} = $cramfs_i->{filename}. '/';\n#\t    print Dumper($dirOffsets);\n\t}else{\n\t    # insert entry into data file pointer map\n\t    $fileOffsets->{4*$cramfs_i->{offset}} =\n\t    {\n\t     name => $cramfs_i->{filename},\n\t     size => $cramfs_i->{size},\n\t     mode => $cramfs_i->{mode},\n\t     uid => $cramfs_i->{uid},\n\t     gid => $cramfs_i->{gid}\n\t     };\n\t}\n#\tprint \"Address $address\\n\";\n\t# check if we have moved to the first file in a new directory\n\tif (exists($dirOffsets->{$address})){\n\t    $currentPath = $dirOffsets->{$address};\n\t}\n\t# check if we have seen all the dir entries\n\tif (exists($fileOffsets->{$address})){\n\t    print \"At $address file data for \",\n\t    $fileOffsets->{$address}->{name}, \"\\n\";\n\t    exit 0;\n\t}\n\t\n    }\n}\n\n\t   # do it\nmain();\n\n\n\n"
  },
  {
    "path": "src/uncramfs/uncramfs.c",
    "content": "//\n// Uncramfs\n// A program to unpack a cramfs image\n//\n// Copyright Andrew Stitcher, 2001\n//\n// Licensed according to the GNU GPL v2\n//\n\n// C things\n#include <stdio.h>\n//#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n\n// Unix things\n#include <unistd.h>\n#include <errno.h>\n//#include <dirent.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <sys/mman.h>\n#include <sys/fcntl.h>\n\n// Application libraries\n#include <zlib.h>\n\n// Needed by cramfs\ntypedef unsigned char u8;\ntypedef unsigned short u16;\ntypedef unsigned int u32;\n\n// Cramfs definitions\n#include \"cramfs.h\"\n\n#define PAGE_CACHE_SIZE (4096)\n\n/* The kernel assumes PAGE_CACHE_SIZE as block size. */\nstatic unsigned int blksize = PAGE_CACHE_SIZE;\n\nstatic const char* progname = \"uncramfs\";\n\nstatic char *opt_devfile = NULL;\nstatic char *opt_idsfile = NULL;\n\n// Get version number from external file\nstatic const char*\n#include \"VERSION\"\n;\n\nvoid do_file_entry(const u8* base,\n\t\t   const char* dir,\n\t\t   const char* path,\n\t\t   const char* name, int namelen,\n\t\t   const struct cramfs_inode* inode);\n\nvoid do_dir_entry(const u8* base,\n\t\t  const char* dir,\n\t\t  const char* path,\n\t\t  const char* name, int namelen,\n\t\t  const struct cramfs_inode* inode);\n\n///////////////////////////////////////////////////////////////////////////////\n\nstatic void usage(void)\n{\n   printf(\n     \"%s v%s by Andrew Stitcher\\n\"\n     \"Usage: '%s [-d devfilename] [-m modefilename] dirname infile'\\n\"\n     \" where <dirname> is the root for the\\n\"\n     \" uncompressed (output) filesystem.\\n\", progname, VERSION, progname);\n   exit(1);\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nu32 compressed_size(const u8* base, const u8* data, u32 size)\n{\n   const u32* buffs=(const u32*)(data);\n   int nblocks=(size-1)/blksize+1;\n   const u8* buffend=base+*(buffs+nblocks-1);\n   \n   if (size == 0)\n     return 0;\n   else\n     return buffend-data;\n}\n\nvoid uncompress_data(const u8* base, const u8* data, u32 size, u8* dstdata)\n{\n   const u32* buffs=(const u32*)(data);\n   int nblocks=(size-1)/blksize+1;\n   const u8* buff=(const u8*)(buffs+nblocks);\n   const u8* nbuff;\n   int block=0;\n   uLongf len=size;\n   \n   if (size == 0) {\n     return;\n   }\n   \n   for (;\n\tblock < nblocks;\n\t++block, buff=nbuff, dstdata+=blksize, len-=blksize\n\t) {\n      uLongf tran=(len < blksize) ? len : blksize;\n      nbuff=base+*(buffs+block);\n      if (uncompress(dstdata, &tran, buff, nbuff-buff) != Z_OK) {\n\t fprintf(stderr,\"Uncompression failed\");\n\t return;\n      }\n   }\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nint stats_totalsize;\nint stats_totalcsize;\nint stats_count;\nint stats_compresses;\nint stats_expands;\n\nvoid clearstats()\n{\n   stats_totalsize=0;\n   stats_totalcsize=0;\n   stats_count=0;\n   stats_compresses=0;\n   stats_expands=0;\n}\n\nvoid updatestats(int size, int csize)\n{\n   ++stats_count;\n   stats_totalsize+=size;\n   stats_totalcsize+=csize;\n   \n   if (size>=csize) {\n      stats_compresses++;\n   } else {\n      stats_expands++;\n   }\n}\n\nvoid printstats()\n{\n   printf(\"\\n[Summary:]\\n\");\n   printf(\"[Total uncompressed size:    %9d]\\n\", stats_totalsize);\n   printf(\"[Total compressed size:      %9d]\\n\", stats_totalcsize);\n   printf(\"[Number of entries:          %9d]\\n\", stats_count);\n   printf(\"[Number of files compressed: %9d]\\n\", stats_compresses);\n   printf(\"[Number of files expanded:   %9d]\\n\", stats_expands);\n   printf(\"\\n\");\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nvoid printmode(const struct cramfs_inode* inode)\n{\n   u16 mode=inode->mode;\n   \n   // Deal with file type bitsetc\n   if (S_ISDIR(mode)) printf(\"d\");\n   else if(S_ISLNK(mode)) printf(\"l\");\n   else if(S_ISBLK(mode)) printf(\"b\");\n   else if(S_ISCHR(mode)) printf(\"c\");\n   else if(S_ISFIFO(mode)) printf(\"p\");\n   else if(S_ISSOCK(mode)) printf(\"s\");\n   else printf(\"-\");\n   \n   // Deal with mode bits\n   if (mode & S_IRUSR) printf(\"r\"); else printf(\"-\");\n   if (mode & S_IWUSR) printf(\"w\"); else printf(\"-\");\n   if (mode & S_IXUSR)\n     if (mode & S_ISUID) printf(\"s\"); else printf(\"x\");\n   else\n     if (mode & S_ISUID) printf(\"S\"); else printf(\"-\");\n   if (mode & S_IRGRP) printf(\"r\"); else printf(\"-\");\n   if (mode & S_IWGRP) printf(\"w\"); else printf(\"-\");\n   if (mode & S_IXGRP)\n     if (mode & S_ISGID) printf(\"s\"); else printf(\"x\");\n   else\n     if (mode & S_ISGID) printf(\"S\"); else printf(\"-\");\n   if (mode & S_IROTH) printf(\"r\"); else printf(\"-\");\n   if (mode & S_IWOTH) printf(\"w\"); else printf(\"-\");\n   if (mode & S_IXOTH)\n     if (mode & S_ISVTX) printf(\"t\"); else printf(\"x\");\n   else\n     if (mode & S_ISVTX) printf(\"T\"); else printf(\"-\");\n}\n\nvoid printuidgid(const struct cramfs_inode* inode)\n{\n   char res[14];\n   \n   snprintf(res, 14, \"%d/%d\", inode->uid, inode->gid);\n   printf(\" %-14s\", res);\n   \n}\n\nvoid printsize(int size, int csize)\n{\n   char s[17];\n\n   // As a side effect update the size stats\n   updatestats(size, csize);\n   \n   snprintf(s, 17, \"%7d(%d)\", size, csize);\n   printf(\"%-16s \", s);\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nvoid do_file(const u8* base, u32 offset, u32 size,\n\t     const char* path, const char* name, int mode)\n{\n   int fd;\n   u8* file_data;\n   const u8* srcdata;\n   \n   // Allow for uncompressed XIP executable\n   if (mode & S_ISVTX) {\n      // It seems that the offset may not necessarily be page\n      // aligned. This is silly because mkcramfs wastes\n      // the alignment space, whereas it might be used if it wasn't\n      // bogusly in our file extent.\n      //\n      // blksize must be a power of 2 for the following to work, but it seems\n      // quite likely.\n \n      srcdata=(const u8*)(((u32)(base+offset)+blksize-1) & ~(blksize-1));\n      printsize(size, srcdata+size-(base+offset));\n      printf(\"%s\", name);\n   } else {\n      printsize(size, compressed_size(base, base+offset, size) );\n      printf(\"%s\", name);\n   }\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   fd=open(path, O_CREAT|O_TRUNC|O_RDWR, mode);\n   if (fd == -1) {\n      perror(\"create\");\n      return;\n   };\n\n   if (ftruncate(fd, size) == -1) {\n      perror(\"ftruncate\");\n      close(fd);\n      return;\n   }\n   \n   file_data = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);\n   if (file_data == MAP_FAILED) {\n      perror(\"mmap\");\n      close(fd);\n      return;\n   }\n\n   // Allow for uncompressed XIP executable\n   if (mode & S_ISVTX) {\n      memcpy(file_data, srcdata, size);\n   } else {\n      uncompress_data(base, base+offset, size, file_data);\n   }\n   \n   munmap(file_data, size);\n   close(fd);\n\n}\n\nvoid do_directory(const u8* base, u32 offset, u32 size,\n\t\t  const char* path, const char* name, int mode)\n{\n   printsize(size, size);\n   printf(\"%s\", name);\n   \n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make the local directory\n   if (mkdir(path, mode) == -1) {\n      perror(path);\n      return;\n   }\n}\n\nvoid do_symlink(const u8* base, u32 offset, u32 size,\n\t\tconst char* path, const char* name, int mode)\n{\n   // Allocate the uncompressed string\n   u8 link_contents[size+1];\n   \n   // do uncompression\n   uncompress_data(base, base+offset, size, link_contents);\n   link_contents[size]=0;\n   \n   printsize(size, compressed_size(base, base+offset, size) );\n   printf(\"%s -> %s\", name, link_contents );\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   if (symlink(link_contents, path) == -1) {\n      perror(path);\n      exit(1);\n   }\n}\n\nvoid do_chrdev(const u8* base, u32 offset, u32 size,\n\t       const char* path, const char* name, int mode, int uid, int gid)\n{\n   {\n      char s[17];\n      snprintf(s, 17, \"%3d, %3d\", major(size), minor(size) );\n      printf(\"%-16s %s\", s, name);\n   }\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   if (geteuid() == 0) {\n      if (mknod(path, S_IFCHR | mode, size) == -1)\n         perror(path);\n   } else if (opt_devfile) {\n      char dfp[1024];\n      char *p;\n      FILE *f;\n\n      strcpy(dfp,path);\n      p = strrchr(dfp,'/');\n      if (!p) {\n         fprintf(stderr,\"Could not find path in '%s'\\n\",path);\n         return;\n      }\n      strcpy(p+1,opt_devfile);\n      f = fopen(dfp,\"at\");\n      if (!f) {\n   \t    perror(dfp);\n   \t    return;\n      }\n      fprintf(f,\"%s,%08x,%u,%u,%08x\\n\",name,mode,uid,gid,size);\n      fclose(f);\n   }\n}\n\nvoid do_blkdev(const u8* base, u32 offset, u32 size,\n\t       const char* path, const char* name, int mode, int uid, int gid)\n{\n   {\n      char s[17];\n      snprintf(s, 17, \"%3d, %3d\", major(size), minor(size) );\n      printf(\"%-16s %s\", s, name);\n   }\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   if (geteuid() == 0) {\n      if (mknod(path, S_IFBLK | mode, size) == -1)\n         perror(path);\n   } else if (opt_devfile) {\n      char dfp[1024];\n      char *p;\n      FILE *f;\n\n      strcpy(dfp,path);\n      p = strrchr(dfp,'/');\n      if (!p) {\n         fprintf(stderr,\"Could not find path in '%s'\\n\",path);\n         return;\n      }\n      strcpy(p+1,opt_devfile);\n      f = fopen(dfp,\"at\");\n      if (!f) {\n   \t    perror(dfp);\n   \t    return;\n      }\n      fprintf(f,\"%s,%08x,%u,%u,%08x\\n\",name,mode,uid,gid,size);\n      fclose(f);\n   }\n}\n\nvoid do_fifo(const u8* base, u32 offset, u32 size,\n\t     const char* path, const char* name, int mode, int gid, int uid)\n{\n   printf(\"                 %s\", name);\n   \n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   if (geteuid() == 0) {\n      if (mknod(path, S_IFIFO | mode, 0) == -1)\n         perror(path);\n   } else if (opt_devfile) {\n      char dfp[1024];\n      char *p;\n      FILE *f;\n\n      strcpy(dfp,path);\n      p = strrchr(dfp,'/');\n      if (!p) {\n         fprintf(stderr,\"Could not find path in '%s'\\n\",path);\n         return;\n      }\n      strcpy(p+1,opt_devfile);\n      f = fopen(dfp,\"at\");\n      if (!f) {\n   \t    perror(dfp);\n   \t    return;\n      }\n      fprintf(f,\"%s,%08x,%u,%u,%08x\\n\",name,mode,uid,gid,size);\n      fclose(f);\n   }\n}\n\nvoid do_socket(const u8* base, u32 offset, u32 size,\n\t       const char* path, const char* name, int mode)\n{\n   printf(\"<UNIMPLEMENTED>  %s\", name);\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n}\n\nvoid do_unknown(const u8* base, u32 offset, u32 size,\n\t        const char* path, const char* name, int mode)\n{\n   printf(\"<UNKNOWN TYPE>   %s\", name);\n}\n\nvoid process_directory(const u8* base, const char* dir, u32 offset, u32 size,\n\t\t  const char* path)\n{\n   struct cramfs_inode* de;\n   char* name;\n   int namelen;\n   u32 current=offset;\n   u32 dirend=offset+size;\n   \n   // Do files\n   while (current < dirend) {\n      u32 nextoffset;\n      \n      de=(struct cramfs_inode*)(base+current);\n      namelen=de->namelen<<2;\n      nextoffset=current+sizeof(struct cramfs_inode)+namelen;\n      \n      name=(char*)(de+1);\n      \n      while (1) {\n\t assert(namelen!=0);\n\t \n\t if (name[namelen-1])\n\t   break;\n\t namelen--;\n      }\n\n      do_file_entry(base, dir, path, name, namelen, de);\n      \n      current=nextoffset;\n   }\n\n   // Recurse into directories\n   current=offset;\n   while (current < dirend) {\n      u32 nextoffset;\n      \n      de=(struct cramfs_inode*)(base+current);\n      namelen=de->namelen<<2;\n      nextoffset=current+sizeof(struct cramfs_inode)+namelen;\n      \n      name=(char*)(de+1);\n      \n      while (1) {\n\t assert(namelen!=0);\n\t \n\t if (name[namelen-1])\n\t   break;\n\t namelen--;\n      }\n\n      do_dir_entry(base, dir, path, name, namelen, de);\n      \n      current=nextoffset;\n   }\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nvoid do_file_entry(const u8* base,\n\t\t   const char* dir,\n\t           const char* path,\n\t\t   const char* name, int namelen, \n\t\t   const struct cramfs_inode* inode)\n{\n   int dirlen=strlen(dir);\n   int pathlen=strlen(path);\n   char pname[dirlen+pathlen+namelen+3];\n   const char* basename;\n   \n   if (dirlen) {\n      strncpy(pname, dir, dirlen);\n   }\n   \n   if (pathlen) {\n      if (dirlen) {\n\t pname[dirlen]='/';\n\t ++dirlen;\n      }\n      strncpy(pname+dirlen, path, pathlen);\n   }\n   \n   if (namelen) {\n      if (pathlen+dirlen) {\n\t pname[dirlen+pathlen]='/';\n\t ++pathlen;\n      }\n      strncpy(pname+dirlen+pathlen, name, namelen);\n   }\n\n   pname[pathlen+dirlen+namelen]=0;\n   basename=namelen ? pname+dirlen+pathlen : \"/\";\n   \n   // Create things here\n   printmode(inode);\n   printuidgid(inode);\n   \n   if (S_ISREG(inode->mode)) {\n      do_file(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   } else  if (S_ISDIR(inode->mode)) {\n      do_directory(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   } else  if (S_ISLNK(inode->mode)) {\n      do_symlink(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   } else  if (S_ISFIFO(inode->mode)) {\n      do_fifo(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);\n   } else  if (S_ISSOCK(inode->mode)) {\n      do_socket(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   } else  if (S_ISCHR(inode->mode)) {\n      do_chrdev(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);\n   } else  if (S_ISBLK(inode->mode)) {\n      do_blkdev(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);\n   } else {\n      do_unknown(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   }\n   \n   if (geteuid() == 0) {\n      if (lchown(pname, inode->uid, inode->gid) == -1)\n         perror(\"cannot change owner or group\");\n   } else if(opt_idsfile && path && path[0]) {\n      char dfp[1024];\n      char *p;\n      FILE *f;\n\n      strcpy(dfp,pname);\n      p = strrchr(dfp,'/');\n      if (!p) {\n         fprintf(stderr,\"could not find path in '%s'\\n\",pname);\n         return;\n      }\n      strcpy(p+1,opt_idsfile);\n      f = fopen(dfp,\"at\");\n      if (!f) {\n   \t    perror(dfp);\n   \t    return;\n      }\n\t  fprintf(f,\"%s,%u,%u,%08x\\n\",basename,inode->uid,inode->gid,inode->mode);\n      fclose(f);\n   }\n\n   if (geteuid() == 0 || !opt_idsfile) {\n      if (inode->mode & (S_ISGID|S_ISUID|S_ISVTX)) {\n        if (0 != chmod(pname, inode->mode)){\n          perror(\"chmod\");\n          return;\n        }\n      }\n   }\n\n\n   \n   printf(\"\\n\");\n}\n\nvoid do_dir_entry(const u8* base,\n\t\t  const char* dir,\n\t\t  const char* path,\n\t\t  const char* name, int namelen, \n\t\t  const struct cramfs_inode* inode)\n{\n   int pathlen=strlen(path);\n   char pname[pathlen+namelen+2];\n   \n   if (pathlen) {\n      strncpy(pname, path, pathlen);\n   }\n   \n   if (namelen) {\n      if (pathlen) {\n\t pname[pathlen]='/';\n\t ++pathlen;\n      }\n      strncpy(pname+pathlen, name, namelen);\n   }\n\n   pname[pathlen+namelen]=0;\n\n   // Only process directories here   \n   if (S_ISDIR(inode->mode)) {\n      printf(\"\\n/%s:\\n\", pname);\n      process_directory(base, dir, inode->offset<<2, inode->size, pname);\n   }\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n/*\n * Usage:\n *\n *      uncramfs directory-name outfile\n *\n * where \"directory-name\" is simply the root of the directory\n * tree that we want to expand the compressed filesystem into.\n */\nint main(int argc, char **argv)\n{\n   char const* dirname;\n   char const* imagefile;\n   struct stat st;\n   int fd;\n   size_t fslen_ub;\n   u8 const* rom_image;\n   struct cramfs_super const* sb;\n   int i;\n\n   // Check the program usage\n   if (argc)\n     progname = argv[0];\n   if (argc != 3 && argc != 5 && argc != 7)\n     usage();\n\n   if (argc == 3) {\n      dirname=argv[1];\n      imagefile=argv[2];\n   } else if (argc == 5) {\n      if (strcmp(argv[1],\"-d\")==0) {\n         opt_devfile = argv[2];\n      } else if (strcmp(argv[1],\"-m\")==0) {\n         opt_idsfile = argv[2];\n      } else\n         usage();\n      dirname=argv[3];\n      imagefile=argv[4];\n   } else {\n      if (strcmp(argv[1],\"-d\")==0) {\n         opt_devfile = argv[2];\n      } else if (strcmp(argv[1],\"-m\")==0) {\n         opt_idsfile = argv[2];\n      } else\n         usage();\n\n      if (strcmp(argv[3],\"-d\")==0 && !opt_devfile) {\n         opt_devfile = argv[4];\n      } else if (strcmp(argv[3],\"-m\")==0 && !opt_idsfile) {\n         opt_idsfile = argv[4];\n      } else\n         usage();\n      dirname=argv[5];\n      imagefile=argv[6];\n   }\n   \n   // Check the directory\n   if (access(dirname, W_OK) == -1) {\n      if (errno != ENOENT ) {\n\t perror(dirname);\n\t exit(1);\n      }\n   }\n   \n   // Check the image file\n   if (stat(imagefile, &st) == -1) {\n      perror(imagefile);\n      exit(1);\n   }\n\n   // Map the cramfs image\n   fd = open(imagefile, O_RDONLY);\n   fslen_ub = st.st_size;\n   rom_image = mmap(0, fslen_ub, PROT_READ, MAP_SHARED, fd, 0);\n   if (rom_image == MAP_FAILED) {\n      perror(\"Mapping cramfs file\");\n      exit(1);\n   }\n   \n   sb=(struct cramfs_super const*)(rom_image);\n   // Check cramfs magic number and signature\n   if (CRAMFS_MAGIC != sb->magic ||\n       0 != memcmp(sb->signature, CRAMFS_SIGNATURE, sizeof(sb->signature))) {\n      fprintf(stderr,\"The image file doesn't have cramfs signatures\\n\");\n      exit(1);\n   }\n\n   // Set umask to 0 to let the image modes shine through\n   umask(0);\n   \n   // Print some reassuring blurb\n   printf(\"[Volume size: 0x%x]\\n\", fslen_ub);\n   printf(\"[Volume serial: \");\n   for (i=0; i< sizeof(sb->fsid); ++i)\n     printf(\"%02x\", sb->fsid[i]);\n   printf(\"]\\n\");\n   printf(\"[Volume name: %s]\\n\", sb->name);\n   printf(\"\\n\");\n\n   clearstats();\n   \n   // Start doing...\n   do_file_entry(rom_image, dirname, \"\", \"\", 0, &sb->root);\n   do_dir_entry(rom_image, dirname, \"\", \"\", 0, &sb->root);\n   \n   //process_directory(rom_image, dirname, sb->root.offset<<2, sb->root.size, \".\");\n   \n   printstats();\n   return 0;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/Makefile",
    "content": "PROG = uncramfs-lzma\nCC = gcc -O3 -Wall\nLIB = -lm\nRM = rm -f\nCFLAGS = -c\n\nOBJS = \\\n  lzma-uncramfs.o \\\n  lzma-rg/SRC/7zip/Compress/LZMA_C/decode.o \\\n  lzma-rg/SRC/7zip/Compress/LZMA_C/LzmaDecode.o \\\n\n\nall: $(PROG)\n\n$(PROG): $(OBJS)\n\t$(CC) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\n\nlzma-uncramfs.o: lzma-uncramfs.c\n\t$(CC) $(CFLAGS) lzma-uncramfs.c\n\nlzma-rg/SRC/7zip/Compress/LZMA_C/decode.o:\n\tcd lzma-rg/SRC/7zip/Compress/LZMA_C;make\n\nclean:\n\t-$(RM) $(PROG) $(OBJS)\n\tcd lzma-rg/SRC/7zip/Compress/LZMA_C;make clean\n\n"
  },
  {
    "path": "src/uncramfs-lzma/README",
    "content": "lzma-uncramfs v0.7rg - Feb 2011 by Valerio Di Giampietro (http://va.ler.io)\n------------------------------------------------------------------------------\nlzma-uncramfs is a modification of the uncramfs program to be able to\nunpack cramfs images included in some openrg based home routers.\nIt includes lzma decompression and a different PAGE_CACHE_SIZE.\n\nTo successfully compile lzma-uncramfs an old version of lzma modified\nby Jungo/OpenRG team is included.\n\nUncramfs v0.7\n-------------\n\nUncramfs is a simple program currently written in C (but I'm working on a more\nfunctional C++ version). Its only purpose in life is to unpack and list the\nfiles in a cramfs image.\n\nNB. this uncramfs includes unconditional support for the non-standard XIP\n(execute in place) feature, whereby executable files are stored uncompressed,\nso they will run directly from ROM (or flash). To activate this you have to\nchmod o+t <file> This feature is currently used by the Agenda Computing VR3 \nLinux PDA.\n\nIt takes 2 command line arguments; the directory to unpack into, and the name\nof the cramfs image.\n\nIf the the unpacking directory name is (or begins with) \"-\" then unpacking is\nturned off and you only get the listing.\n\nIt will print some \"Reassuring\" info about the cramfs image, and the listing\nhas been extensively reworked to look quite like the listing from ls.\n\nIf the effective uid of the execuatble isn't root then it won't even attempt\nto create device nodes, or to set the correct owner and group on the extracted\nfiles.\n\nIt currently doesn't handle unix sockets (but there aren't any in the stock VR3\nimages).\n\nFor example:\n\tuncramfs unpack root-0.20.0.cramfs\nWill unpack the root-0.20.0.cramfs image into the unpack directory;\n\n        uncramfs - root-0.20.0.cramfs\nWill just list the contents of the image.\n\nUncramfs is copyright Andrew Stitcher and licensed under the terms\nof the GNU GPL version 2.\n\nAndrew Stitcher\n6 June 2001\n\nPlease report bugs, send patches, feature suggestions etc. to\n    astitcher@bigfoot.com\n\n---------------\n\nVersion history:\n\nv0.2: First packaged version released to net. Had a killer bug in uncompresssing\n      files that lost all the files blocks after the first!\n\nv0.3: Fix release from cam to remedy the killer bug\n\nv0.3.1: Release from cam which includes some of his scripts\n\nv0.4: [Not released to net]\n      Ported original C++ code to C;\n      Ported cam's bug fix (actually I had independently fixed the bug in my own \n       codebase);\n      Extensively reworked the listing to be as much like ls as possible;\n      Set umask to 0 in uncramfs so the images modes are correctly respected;\n      Don't try to do privileged things unless we are running as root;\n     \nv0.5: [Released to net 6 June 2001]\n      Added README\n      Added some summary stats\n      Can turn off the unpacking so we just get the listing (and summary)\n      All summary info is in [] brackets for easy stripping\n      \nv0.6: [Released on wiki site, 8 June 2001]\n      Context added to notes\n      Fixed bug whereby suid information was reset on chown, leaving suid \n      files without suid permission. Credit to Luis Maria Cruz Vazquez for \n      assistance in nailing this bug. -Cam\n\nv0.7: [Released on wiki site, 24 Oct 2001]\n      Patched by Lev Serebryakov to allow non superuser to unpack safely. \n      Also includes mapping of UID and GID. -Cam\n"
  },
  {
    "path": "src/uncramfs-lzma/VERSION",
    "content": "VERSION=\"0.7rg\"\n"
  },
  {
    "path": "src/uncramfs-lzma/cramfs.h",
    "content": "#ifndef __CRAMFS_H\n#define __CRAMFS_H\n\n#define CRAMFS_MAGIC\t\t0x28cd3d45\t/* some random number */\n#define CRAMFS_SIGNATURE\t\"Compressed ROMFS\"\n\n/*\n * Reasonably terse representation of the inode data.\n */\nstruct cramfs_inode {\n\tu32 mode:16, uid:16;\n\t/* SIZE for device files is i_rdev */\n\tu32 size:24, gid:8;\n\t/* NAMELEN is the length of the file name, divided by 4 and\n           rounded up.  (cramfs doesn't support hard links.) */\n\t/* OFFSET: For symlinks and non-empty regular files, this\n\t   contains the offset (divided by 4) of the file data in\n\t   compressed form (starting with an array of block pointers;\n\t   see README).  For non-empty directories it is the offset\n\t   (divided by 4) of the inode of the first file in that\n\t   directory.  For anything else, offset is zero. */\n\tu32 namelen:6, offset:26;\n};\n\n/*\n * Superblock information at the beginning of the FS.\n */\nstruct cramfs_super {\n\tu32 magic;\t\t/* 0x28cd3d45 - random number */\n\tu32 size;\t\t/* Not used.  mkcramfs currently\n                                   writes a constant 1<<16 here. */\n\tu32 flags;\t\t/* 0 */\n\tu32 future;\t\t/* 0 */\n\tu8 signature[16];\t/* \"Compressed ROMFS\" */\n\tu8 fsid[16];\t\t/* random number */\n\tu8 name[16];\t\t/* user-defined name */\n\tstruct cramfs_inode root;\t/* Root inode data */\n};\n\n/*\n * Valid values in super.flags.  Currently we refuse to mount\n * if (flags & ~CRAMFS_SUPPORTED_FLAGS).  Maybe that should be\n * changed to test super.future instead.\n */\n#define CRAMFS_SUPPORTED_FLAGS (0xff)\n\n/* Uncompression interfaces to the underlying zlib */\nint cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);\nint cramfs_uncompress_init(void);\nint cramfs_uncompress_exit(void);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/cramfs_fs.h",
    "content": "#ifndef __CRAMFS_FS_H\n#define __CRAMFS_FS_H\n\n#ifdef __KERNEL__\n\n#include <asm/byteorder.h>\n\n/* Uncompression interfaces to the underlying compression lib (none, zlib,\n * other) */\nint cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen,\n    int comp_method);\nint cramfs_uncompress_init(int comp_method);\nint cramfs_uncompress_exit(int comp_method);\n\n#else /* not __KERNEL__ */\n\n//#include <rg_config.h>\n#include <byteswap.h>\n#include <endian.h>\n\ntypedef unsigned char u8;\ntypedef unsigned short u16;\ntypedef unsigned int u32;\n\n#endif /* not __KERNEL__ */\n\n#define CRAMFS_MAGIC\t\t0x28cd3d45\t/* some random number */\n#define CRAMFS_SIGNATURE\t\"Compressed ROMFS\"\n\n/*\n * Width of various bitfields in struct cramfs_inode.\n * Primarily used to generate warnings in mkcramfs.\n */\n#define CRAMFS_MODE_WIDTH 16\n#define CRAMFS_UID_WIDTH 16\n#define CRAMFS_GID_WIDTH 8\n#define CRAMFS_NAMELEN_WIDTH 6\n#define CRAMFS_OFFSET_WIDTH 26\n\n/*\n * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs\n * path length is 63 << 2 = 252.\n */\n#define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)\n#define CRAMFS_SIZE_WIDTH 24\n/*\n * Reasonably terse representation of the inode data.\n */\nstruct cramfs_inode {\n\tu32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH;\n\t/* SIZE for device files is i_rdev */\n\tu32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH;\n\t/* NAMELEN is the length of the file name, divided by 4 and\n           rounded up.  (cramfs doesn't support hard links.) */\n\t/* OFFSET: For symlinks and non-empty regular files, this\n\t   contains the offset (divided by 4) of the file data in\n\t   compressed form (starting with an array of block pointers;\n\t   see README).  For non-empty directories it is the offset\n\t   (divided by 4) of the inode of the first file in that\n\t   directory.  For anything else, offset is zero. */\n\tu32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH;\n};\n\nstruct cramfs_info {\n\tu32 crc;\n\tu32 edition;\n\tu32 blocks;\n\tu32 files;\n};\n\n/*\n * Superblock information at the beginning of the FS.\n */\nstruct cramfs_super {\n\tu32 magic;\t\t\t/* 0x28cd3d45 - random number */\n\tu32 size;\t\t\t/* length in bytes */\n\tu32 flags;\t\t\t/* feature flags */\n\tu32 future;\t\t\t/* reserved for future use */\n\tu8 signature[16];\t\t/* \"Compressed ROMFS\" */\n\tstruct cramfs_info fsid;\t/* unique filesystem info */\n\tu8 name[16];\t\t\t/* user-defined name */\n\tstruct cramfs_inode root;\t/* root inode data */\n};\n\n/*\n * Feature flags\n *\n * 0x00000000 - 0x000000ff: features that work for all past kernels\n * 0x00000100 - 0xffffffff: features that don't work for past kernels\n */\n#define CRAMFS_FLAG_FSID_VERSION_2\t0x00000001\t/* fsid version #2 */\n#define CRAMFS_FLAG_SORTED_DIRS\t\t0x00000002\t/* sorted dirs */\n#define CRAMFS_FLAG_HOLES\t\t0x00000100\t/* support for holes */\n#define CRAMFS_FLAG_WRONG_SIGNATURE\t0x00000200\t/* reserved */\n#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET\t0x00000400\t/* shifted root fs */\n#define CRAMFS_FLAG_BLKSZ_MASK\t\t0x00003800\t/* Block size mask */\n#define CRAMFS_FLAG_COMP_METHOD_MASK\t0x0000C000\t/* Compression method\n\t\t\t\t\t\t\t * mask */  \n\n#define CRAMFS_FLAG_BLKSZ_SHIFT\t11\n#define CRAMFS_FLAG_COMP_METHOD_SHIFT 14\n\n#define CRAMFS_FLAG_COMP_METHOD_NONE 0\n#define CRAMFS_FLAG_COMP_METHOD_GZIP 1\n#define CRAMFS_FLAG_COMP_METHOD_LZMA 2\n\n/*\n * Valid values in super.flags.  Currently we refuse to mount\n * if (flags & ~CRAMFS_SUPPORTED_FLAGS).  Maybe that should be\n * changed to test super.future instead.\n */\n#define CRAMFS_SUPPORTED_FLAGS\t( 0x000000ff \\\n\t\t\t\t| CRAMFS_FLAG_HOLES \\\n\t\t\t\t| CRAMFS_FLAG_WRONG_SIGNATURE \\\n\t\t\t\t| CRAMFS_FLAG_SHIFTED_ROOT_OFFSET \\\n\t\t\t\t| CRAMFS_FLAG_BLKSZ_MASK \\\n\t\t\t\t| CRAMFS_FLAG_COMP_METHOD_MASK)\n\n/*\n * Since cramfs is little-endian, provide macros to swab the bitfields.\n */\n\n#ifndef __BYTE_ORDER\n#if defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)\n#define __BYTE_ORDER __LITTLE_ENDIAN\n#elif defined(__BIG_ENDIAN) && !defined(__LITTLE_ENDIAN)\n#define __BYTE_ORDER __BIG_ENDIAN\n#else\n#error \"unable to define __BYTE_ORDER\"\n#endif\n#endif /* not __BYTE_ORDER */\n\n#if __BYTE_ORDER == __LITTLE_ENDIAN\n#define CRAMFS_16(x)\t(x)\n#define CRAMFS_24(x)\t(x)\n#define CRAMFS_32(x)\t(x)\n#define CRAMFS_GET_NAMELEN(x)\t((x)->namelen)\n#define CRAMFS_GET_SIZE(x)\t((x)->size)\n#define CRAMFS_GET_OFFSET(x)\t((x)->offset)\n#define CRAMFS_SET_OFFSET(x,y)\t((x)->offset = (y))\n#define CRAMFS_SET_NAMELEN(x,y)\t((x)->namelen = (y))\n#elif __BYTE_ORDER == __BIG_ENDIAN\n#ifdef __KERNEL__\n#define CRAMFS_16(x)\tswab16(x)\n#define CRAMFS_24(x)\t((swab32(x)) >> 8)\n#define CRAMFS_32(x)\tswab32(x)\n#else /* not __KERNEL__ */\n#define CRAMFS_16(x)\tbswap_16(x)\n#define CRAMFS_24(x)\t((bswap_32(x)) >> 8)\n#define CRAMFS_32(x)\tbswap_32(x)\n#endif /* not __KERNEL__ */\n#define CRAMFS_GET_NAMELEN(x)\t(((u8*)(x))[8] & 0x3f)\n#define CRAMFS_GET_OFFSET(x)\t((CRAMFS_24(((u32*)(x))[2] & 0xffffff) << 2) |\\\n\t\t\t\t ((((u32*)(x))[2] & 0xc0000000) >> 30))\n#define CRAMFS_GET_SIZE(x)\t((CRAMFS_32(((u32*)(x))[1] & 0xffffff00)))\n#define CRAMFS_SET_NAMELEN(x,y)\t(((u8*)(x))[8] = (((0x3f & (y))) | \\\n\t\t\t\t\t\t  (0xc0 & ((u8*)(x))[8])))\n#define CRAMFS_SET_OFFSET(x,y)\t(((u32*)(x))[2] = (((y) & 3) << 30) | \\\n\t\t\t\t CRAMFS_24((((y) & 0x03ffffff) >> 2)) | \\\n\t\t\t\t (((u32)(((u8*)(x))[8] & 0x3f)) << 24))\n#else\n#error \"__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN\"\n#endif\n\n#endif /* not __CRAMFS_FS_H */\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/CPL.html",
    "content": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML><HEAD><TITLE>Common Public License - v 1.0</TITLE>\n<META http-equiv=Content-Type content=\"text/html; charset=ISO-8859-1\">\n<BODY vLink=#800000 bgColor=#ffffff>\n<P align=center><B>Common Public License - v 1.0</B> \n<P><B></B><FONT size=3></FONT>\n<P><FONT size=3></FONT><FONT size=2>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER \nTHE TERMS OF THIS COMMON PUBLIC LICENSE (\"AGREEMENT\"). ANY USE, REPRODUCTION OR \nDISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS \nAGREEMENT.</FONT> \n<P><FONT size=2></FONT>\n<P><FONT size=2><B>1. DEFINITIONS</B></FONT> \n<P><FONT size=2>\"Contribution\" means:</FONT> \n<UL><FONT size=2>a) in the case of the initial Contributor, the initial code \n  and documentation distributed under this Agreement, and<BR clear=left>b) in \n  the case of each subsequent Contributor:</FONT></UL>\n<UL><FONT size=2>i) changes to the Program, and</FONT></UL>\n<UL><FONT size=2>ii) additions to the Program;</FONT></UL>\n<UL><FONT size=2>where such changes and/or additions to the Program originate \n  from and are distributed by that particular Contributor. </FONT><FONT size=2>A \n  Contribution 'originates' from a Contributor if it was added to the Program by \n  such Contributor itself or anyone acting on such Contributor's behalf. \n  </FONT><FONT size=2>Contributions do not include additions to the Program \n  which: (i) are separate modules of software distributed in conjunction with \n  the Program under their own license agreement, and (ii) are not derivative \n  works of the Program. </FONT></UL>\n<P><FONT size=2></FONT>\n<P><FONT size=2>\"Contributor\" means any person or entity that distributes the \nProgram.</FONT> \n<P><FONT size=2></FONT><FONT size=2></FONT>\n<P><FONT size=2>\"Licensed Patents \" mean patent claims licensable by a \nContributor which are necessarily infringed by the use or sale of its \nContribution alone or when combined with the Program. </FONT>\n<P><FONT size=2></FONT><FONT size=2></FONT>\n<P><FONT size=2></FONT><FONT size=2>\"Program\" means the Contributions \ndistributed in accordance with this Agreement.</FONT> \n<P><FONT size=2></FONT>\n<P><FONT size=2>\"Recipient\" means anyone who receives the Program under this \nAgreement, including all Contributors.</FONT> \n<P><FONT size=2><B></B></FONT>\n<P><FONT size=2><B>2. GRANT OF RIGHTS</B></FONT> \n<UL><FONT size=2></FONT><FONT size=2>a) </FONT><FONT size=2>Subject to the \n  terms of this Agreement, each Contributor hereby grants</FONT><FONT size=2> \n  Recipient a non-exclusive, worldwide, royalty-free copyright license \n  to</FONT><FONT color=#ff0000 size=2> </FONT><FONT size=2>reproduce, prepare \n  derivative works of, publicly display, publicly perform, distribute and \n  sublicense the Contribution of such Contributor, if any, and such derivative \n  works, in source code and object code form.</FONT></UL>\n<UL><FONT size=2></FONT></UL>\n<UL><FONT size=2></FONT><FONT size=2>b) Subject to the terms of this \n  Agreement, each Contributor hereby grants </FONT><FONT size=2>Recipient a \n  non-exclusive, worldwide,</FONT><FONT color=#008000 size=2> </FONT><FONT \n  size=2>royalty-free patent license under Licensed Patents to make, use, sell, \n  offer to sell, import and otherwise transfer the Contribution of such \n  Contributor, if any, in source code and object code form. This patent license \n  shall apply to the combination of the Contribution and the Program if, at the \n  time the Contribution is added by the Contributor, such addition of the \n  Contribution causes such combination to be covered by the Licensed Patents. \n  The patent license shall not apply to any other combinations which include the \n  Contribution. No hardware per se is licensed hereunder. </FONT></UL>\n<UL><FONT size=2></FONT></UL>\n<UL><FONT size=2>c) Recipient understands that although each Contributor \n  grants the licenses to its Contributions set forth herein, no assurances are \n  provided by any Contributor that the Program does not infringe the patent or \n  other intellectual property rights of any other entity. Each Contributor \n  disclaims any liability to Recipient for claims brought by any other entity \n  based on infringement of intellectual property rights or otherwise. As a \n  condition to exercising the rights and licenses granted hereunder, each \n  Recipient hereby assumes sole responsibility to secure any other intellectual \n  property rights needed, if any. For example, if a third party patent license \n  is required to allow Recipient to distribute the Program, it is Recipient's \n  responsibility to acquire that license before distributing the \nProgram.</FONT></UL>\n<UL><FONT size=2></FONT></UL>\n<UL><FONT size=2>d) Each Contributor represents that to its knowledge it has \n  sufficient copyright rights in its Contribution, if any, to grant the \n  copyright license set forth in this Agreement. </FONT></UL>\n<UL><FONT size=2></FONT></UL>\n<P><FONT size=2><B>3. REQUIREMENTS</B></FONT> \n<P><FONT size=2><B></B>A Contributor may choose to distribute the Program in \nobject code form under its own license agreement, provided that:</FONT> \n<UL><FONT size=2>a) it complies with the terms and conditions of this \n  Agreement; and</FONT></UL>\n<UL><FONT size=2>b) its license agreement:</FONT></UL>\n<UL><FONT size=2>i) effectively disclaims</FONT><FONT size=2> on behalf of all \n  Contributors all warranties and conditions, express and implied, including \n  warranties or conditions of title and non-infringement, and implied warranties \n  or conditions of merchantability and fitness for a particular purpose; \n</FONT></UL>\n<UL><FONT size=2>ii) effectively excludes on behalf of all Contributors all \n  liability for damages, including direct, indirect, special, incidental and \n  consequential damages, such as lost profits; </FONT></UL>\n<UL><FONT size=2>iii)</FONT><FONT size=2> states that any provisions which \n  differ from this Agreement are offered by that Contributor alone and not by \n  any other party; and</FONT></UL>\n<UL><FONT size=2>iv) states that source code for the Program is available from \n  such Contributor, and informs licensees how to obtain it in a reasonable \n  manner on or through a medium customarily used for software \n  exchange.</FONT><FONT color=#0000ff size=2> </FONT><FONT color=#ff0000 \n  size=2></FONT></UL>\n<UL><FONT color=#ff0000 size=2></FONT><FONT size=2></FONT></UL>\n<P><FONT size=2>When the Program is made available in source code form:</FONT> \n<UL><FONT size=2>a) it must be made available under this Agreement; and \n</FONT></UL>\n<UL><FONT size=2>b) a copy of this Agreement must be included with each copy \n  of the Program. </FONT></UL>\n<P><FONT size=2></FONT><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT>\n<P><FONT color=#0000ff size=2><STRIKE></STRIKE></FONT><FONT size=2>Contributors \nmay not remove or alter any copyright notices contained within the Program. \n</FONT>\n<P><FONT size=2></FONT>\n<P><FONT size=2>Each Contributor must identify itself as the originator of its \nContribution, if any, in a manner that reasonably allows subsequent Recipients \nto identify the originator of the Contribution. </FONT>\n<P><FONT size=2></FONT>\n<P><FONT size=2><B>4. COMMERCIAL DISTRIBUTION</B></FONT> \n<P><FONT size=2>Commercial distributors of software may accept certain \nresponsibilities with respect to end users, business partners and the like. \nWhile this license is intended to facilitate the commercial use of the Program, \nthe Contributor who includes the Program in a commercial product offering should \ndo so in a manner which does not create potential liability for other \nContributors. Therefore, if a Contributor includes the Program in a commercial \nproduct offering, such Contributor (\"Commercial Contributor\") hereby agrees to \ndefend and indemnify every other Contributor (\"Indemnified Contributor\") against \nany losses, damages and costs (collectively \"Losses\") arising from claims, \nlawsuits and other legal actions brought by a third party against the \nIndemnified Contributor to the extent caused by the acts or omissions of such \nCommercial Contributor in connection with its distribution of the Program in a \ncommercial product offering. The obligations in this section do not apply to any \nclaims or Losses relating to any actual or alleged intellectual property \ninfringement. In order to qualify, an Indemnified Contributor must: a) promptly \nnotify the Commercial Contributor in writing of such claim, and b) allow the \nCommercial Contributor to control, and cooperate with the Commercial Contributor \nin, the defense and any related settlement negotiations. The Indemnified \nContributor may participate in any such claim at its own expense.</FONT> \n<P><FONT size=2></FONT>\n<P><FONT size=2>For example, a Contributor might include the Program in a \ncommercial product offering, Product X. That Contributor is then a Commercial \nContributor. If that Commercial Contributor then makes performance claims, or \noffers warranties related to Product X, those performance claims and warranties \nare such Commercial Contributor's responsibility alone. Under this section, the \nCommercial Contributor would have to defend claims against the other \nContributors related to those performance claims and warranties, and if a court \nrequires any other Contributor to pay any damages as a result, the Commercial \nContributor must pay those damages.</FONT> \n<P><FONT size=2></FONT><FONT color=#0000ff size=2></FONT>\n<P><FONT color=#0000ff size=2></FONT><FONT size=2><B>5. NO WARRANTY</B></FONT> \n<P><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS \nPROVIDED ON AN \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \nEITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR \nCONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A \nPARTICULAR PURPOSE. Each Recipient is</FONT><FONT size=2> solely responsible for \ndetermining the appropriateness of using and distributing </FONT><FONT \nsize=2>the Program</FONT><FONT size=2> and assumes all risks associated with its \nexercise of rights under this Agreement</FONT><FONT size=2>, including but not \nlimited to the risks and costs of program errors, compliance with applicable \nlaws, damage to or loss of data, </FONT><FONT size=2>programs or equipment, and \nunavailability or interruption of operations</FONT><FONT size=2>. </FONT><FONT \nsize=2></FONT>\n<P><FONT size=2></FONT>\n<P><FONT size=2></FONT><FONT size=2><B>6. DISCLAIMER OF LIABILITY</B></FONT> \n<P><FONT size=2></FONT><FONT size=2>EXCEPT AS EXPRESSLY SET FORTH IN THIS \nAGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR \nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \n</FONT><FONT size=2>(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT \nsize=2> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, \nSTRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \nOUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS \nGRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT> \n<P><FONT size=2></FONT><FONT size=2></FONT>\n<P><FONT size=2><B>7. GENERAL</B></FONT> \n<P><FONT size=2></FONT><FONT size=2>If any provision of this Agreement is \ninvalid or unenforceable under applicable law, it shall not affect the validity \nor enforceability of the remainder of the terms of this Agreement, and without \nfurther action by the parties hereto, such provision shall be reformed to the \nminimum extent necessary to make such provision valid and enforceable.</FONT> \n<P><FONT size=2></FONT>\n<P><FONT size=2>If Recipient institutes patent litigation against a Contributor \nwith respect to a patent applicable to software (including a cross-claim or \ncounterclaim in a lawsuit), then any patent licenses granted by that Contributor \nto such Recipient under this Agreement shall terminate as of the date such \nlitigation is filed. In addition, if Recipient institutes patent litigation \nagainst any entity (including a cross-claim or counterclaim in a lawsuit) \nalleging that the Program itself (excluding combinations of the Program with \nother software or hardware) infringes such Recipient's patent(s), then such \nRecipient's rights granted under Section 2(b) shall terminate as of the date \nsuch litigation is filed. </FONT><FONT size=2></FONT>\n<P><FONT size=2></FONT>\n<P><FONT size=2>All Recipient's rights under this Agreement shall terminate if \nit fails to comply with any of the material terms or conditions of this \nAgreement and does not cure such failure in a reasonable period of time after \nbecoming aware of such noncompliance. If all Recipient's rights under this \nAgreement terminate, Recipient agrees to cease use and distribution of the \nProgram as soon as reasonably practicable. However, Recipient's obligations \nunder this Agreement and any licenses granted by Recipient relating to the \nProgram shall continue and survive. </FONT><FONT size=2></FONT>\n<P><FONT size=2></FONT>\n<P><FONT size=2></FONT><FONT size=2>Everyone is permitted to copy and distribute \ncopies of this Agreement, but in order to avoid inconsistency the Agreement is \ncopyrighted and may only be modified in the following manner. The Agreement \nSteward reserves the right to </FONT><FONT size=2>publish new versions \n(including revisions) of this Agreement from time to </FONT><FONT size=2>time. \nNo one other than the Agreement Steward has the right to modify this Agreement. \nIBM is the initial Agreement Steward. IBM may assign the responsibility to serve \nas the Agreement Steward to a suitable separate entity. </FONT><FONT size=2>Each \nnew version of the Agreement will be given a distinguishing version number. The \nProgram (including Contributions) may always be distributed subject to the \nversion of the Agreement under which it was received. In addition, after a new \nversion of the Agreement is published, Contributor may elect to distribute the \nProgram (including its Contributions) under the new </FONT><FONT size=2>version. \n</FONT><FONT size=2>Except as expressly stated in Sections 2(a) and 2(b) above, \nRecipient receives no rights or licenses to the intellectual property of any \nContributor under this Agreement, whether expressly, </FONT><FONT size=2>by \nimplication, estoppel or otherwise</FONT><FONT size=2>.</FONT><FONT size=2> All \nrights in the Program not expressly granted under this Agreement are \nreserved.</FONT> \n<P><FONT size=2></FONT>\n<P><FONT size=2>This Agreement is governed by the laws of the State of New York \nand the intellectual property laws of the United States of America. No party to \nthis Agreement will bring a legal action under this Agreement more than one year \nafter the cause of action arose. Each party waives its rights to a jury trial in \nany resulting litigation.</FONT> \n<P><FONT size=2></FONT><FONT size=2></FONT>\n<P><FONT size=2></FONT></P></BODY></HTML>\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/LGPL.txt",
    "content": "      GNU LESSER GENERAL PUBLIC LICENSE\n           Version 2.1, February 1999\n\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n[This is the first released version of the Lesser GPL.  It also counts\n as the successor of the GNU Library Public License, version 2, hence\n the version number 2.1.]\n\n          Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicenses are intended to guarantee your freedom to share and change\nfree software--to make sure the software is free for all its users.\n\n  This license, the Lesser General Public License, applies to some\nspecially designated software packages--typically libraries--of the\nFree Software Foundation and other authors who decide to use it.  You\ncan use it too, but we suggest you first think carefully about whether\nthis license or the ordinary General Public License is the better\nstrategy to use in any particular case, based on the explanations below.\n\n  When we speak of free software, we are referring to freedom of use,\nnot price.  Our General Public Licenses are designed to make sure that\nyou have the freedom to distribute copies of free software (and charge\nfor this service if you wish); that you receive source code or can get\nit if you want it; that you can change the software and use pieces of\nit in new free programs; and that you are informed that you can do\nthese things.\n\n  To protect your rights, we need to make restrictions that forbid\ndistributors to deny you these rights or to ask you to surrender these\nrights.  These restrictions translate to certain responsibilities for\nyou if you distribute copies of the library or if you modify it.\n\n  For example, if you distribute copies of the library, whether gratis\nor for a fee, you must give the recipients all the rights that we gave\nyou.  You must make sure that they, too, receive or can get the source\ncode.  If you link other code with the library, you must provide\ncomplete object files to the recipients, so that they can relink them\nwith the library after making changes to the library and recompiling\nit.  And you must show them these terms so they know their rights.\n\n  We protect your rights with a two-step method: (1) we copyright the\nlibrary, and (2) we offer you this license, which gives you legal\npermission to copy, distribute and/or modify the library.\n\n  To protect each distributor, we want to make it very clear that\nthere is no warranty for the free library.  Also, if the library is\nmodified by someone else and passed on, the recipients should know\nthat what they have is not the original version, so that the original\nauthor's reputation will not be affected by problems that might be\nintroduced by others.\n\f\n  Finally, software patents pose a constant threat to the existence of\nany free program.  We wish to make sure that a company cannot\neffectively restrict the users of a free program by obtaining a\nrestrictive license from a patent holder.  Therefore, we insist that\nany patent license obtained for a version of the library must be\nconsistent with the full freedom of use specified in this license.\n\n  Most GNU software, including some libraries, is covered by the\nordinary GNU General Public License.  This license, the GNU Lesser\nGeneral Public License, applies to certain designated libraries, and\nis quite different from the ordinary General Public License.  We use\nthis license for certain libraries in order to permit linking those\nlibraries into non-free programs.\n\n  When a program is linked with a library, whether statically or using\na shared library, the combination of the two is legally speaking a\ncombined work, a derivative of the original library.  The ordinary\nGeneral Public License therefore permits such linking only if the\nentire combination fits its criteria of freedom.  The Lesser General\nPublic License permits more lax criteria for linking other code with\nthe library.\n\n  We call this license the \"Lesser\" General Public License because it\ndoes Less to protect the user's freedom than the ordinary General\nPublic License.  It also provides other free software developers Less\nof an advantage over competing non-free programs.  These disadvantages\nare the reason we use the ordinary General Public License for many\nlibraries.  However, the Lesser license provides advantages in certain\nspecial circumstances.\n\n  For example, on rare occasions, there may be a special need to\nencourage the widest possible use of a certain library, so that it becomes\na de-facto standard.  To achieve this, non-free programs must be\nallowed to use the library.  A more frequent case is that a free\nlibrary does the same job as widely used non-free libraries.  In this\ncase, there is little to gain by limiting the free library to free\nsoftware only, so we use the Lesser General Public License.\n\n  In other cases, permission to use a particular library in non-free\nprograms enables a greater number of people to use a large body of\nfree software.  For example, permission to use the GNU C Library in\nnon-free programs enables many more people to use the whole GNU\noperating system, as well as its variant, the GNU/Linux operating\nsystem.\n\n  Although the Lesser General Public License is Less protective of the\nusers' freedom, it does ensure that the user of a program that is\nlinked with the Library has the freedom and the wherewithal to run\nthat program using a modified version of the Library.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.  Pay close attention to the difference between a\n\"work based on the library\" and a \"work that uses the library\".  The\nformer contains code derived from the library, whereas the latter must\nbe combined with the library in order to run.\n\f\n      GNU LESSER GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License Agreement applies to any software library or other\nprogram which contains a notice placed by the copyright holder or\nother authorized party saying it may be distributed under the terms of\nthis Lesser General Public License (also called \"this License\").\nEach licensee is addressed as \"you\".\n\n  A \"library\" means a collection of software functions and/or data\nprepared so as to be conveniently linked with application programs\n(which use some of those functions and data) to form executables.\n\n  The \"Library\", below, refers to any such software library or work\nwhich has been distributed under these terms.  A \"work based on the\nLibrary\" means either the Library or any derivative work under\ncopyright law: that is to say, a work containing the Library or a\nportion of it, either verbatim or with modifications and/or translated\nstraightforwardly into another language.  (Hereinafter, translation is\nincluded without limitation in the term \"modification\".)\n\n  \"Source code\" for a work means the preferred form of the work for\nmaking modifications to it.  For a library, complete source code means\nall the source code for all modules it contains, plus any associated\ninterface definition files, plus the scripts used to control compilation\nand installation of the library.\n\n  Activities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning a program using the Library is not restricted, and output from\nsuch a program is covered only if its contents constitute a work based\non the Library (independent of the use of the Library in a tool for\nwriting it).  Whether that is true depends on what the Library does\nand what the program that uses the Library does.\n  \n  1. You may copy and distribute verbatim copies of the Library's\ncomplete source code as you receive it, in any medium, provided that\nyou conspicuously and appropriately publish on each copy an\nappropriate copyright notice and disclaimer of warranty; keep intact\nall the notices that refer to this License and to the absence of any\nwarranty; and distribute a copy of this License along with the\nLibrary.\n\n  You may charge a fee for the physical act of transferring a copy,\nand you may at your option offer warranty protection in exchange for a\nfee.\n\f\n  2. You may modify your copy or copies of the Library or any portion\nof it, thus forming a work based on the Library, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) The modified work must itself be a software library.\n\n    b) You must cause the files modified to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    c) You must cause the whole of the work to be licensed at no\n    charge to all third parties under the terms of this License.\n\n    d) If a facility in the modified Library refers to a function or a\n    table of data to be supplied by an application program that uses\n    the facility, other than as an argument passed when the facility\n    is invoked, then you must make a good faith effort to ensure that,\n    in the event an application does not supply such function or\n    table, the facility still operates, and performs whatever part of\n    its purpose remains meaningful.\n\n    (For example, a function in a library to compute square roots has\n    a purpose that is entirely well-defined independent of the\n    application.  Therefore, Subsection 2d requires that any\n    application-supplied function or table used by this function must\n    be optional: if the application does not supply it, the square\n    root function must still compute square roots.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Library,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Library, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote\nit.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Library.\n\nIn addition, mere aggregation of another work not based on the Library\nwith the Library (or with a work based on the Library) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may opt to apply the terms of the ordinary GNU General Public\nLicense instead of this License to a given copy of the Library.  To do\nthis, you must alter all the notices that refer to this License, so\nthat they refer to the ordinary GNU General Public License, version 2,\ninstead of to this License.  (If a newer version than version 2 of the\nordinary GNU General Public License has appeared, then you can specify\nthat version instead if you wish.)  Do not make any other change in\nthese notices.\n\f\n  Once this change is made in a given copy, it is irreversible for\nthat copy, so the ordinary GNU General Public License applies to all\nsubsequent copies and derivative works made from that copy.\n\n  This option is useful when you wish to copy part of the code of\nthe Library into a program that is not a library.\n\n  4. You may copy and distribute the Library (or a portion or\nderivative of it, under Section 2) in object code or executable form\nunder the terms of Sections 1 and 2 above provided that you accompany\nit with the complete corresponding machine-readable source code, which\nmust be distributed under the terms of Sections 1 and 2 above on a\nmedium customarily used for software interchange.\n\n  If distribution of object code is made by offering access to copy\nfrom a designated place, then offering equivalent access to copy the\nsource code from the same place satisfies the requirement to\ndistribute the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  5. A program that contains no derivative of any portion of the\nLibrary, but is designed to work with the Library by being compiled or\nlinked with it, is called a \"work that uses the Library\".  Such a\nwork, in isolation, is not a derivative work of the Library, and\ntherefore falls outside the scope of this License.\n\n  However, linking a \"work that uses the Library\" with the Library\ncreates an executable that is a derivative of the Library (because it\ncontains portions of the Library), rather than a \"work that uses the\nlibrary\".  The executable is therefore covered by this License.\nSection 6 states terms for distribution of such executables.\n\n  When a \"work that uses the Library\" uses material from a header file\nthat is part of the Library, the object code for the work may be a\nderivative work of the Library even though the source code is not.\nWhether this is true is especially significant if the work can be\nlinked without the Library, or if the work is itself a library.  The\nthreshold for this to be true is not precisely defined by law.\n\n  If such an object file uses only numerical parameters, data\nstructure layouts and accessors, and small macros and small inline\nfunctions (ten lines or less in length), then the use of the object\nfile is unrestricted, regardless of whether it is legally a derivative\nwork.  (Executables containing this object code plus portions of the\nLibrary will still fall under Section 6.)\n\n  Otherwise, if the work is a derivative of the Library, you may\ndistribute the object code for the work under the terms of Section 6.\nAny executables containing that work also fall under Section 6,\nwhether or not they are linked directly with the Library itself.\n\f\n  6. As an exception to the Sections above, you may also combine or\nlink a \"work that uses the Library\" with the Library to produce a\nwork containing portions of the Library, and distribute that work\nunder terms of your choice, provided that the terms permit\nmodification of the work for the customer's own use and reverse\nengineering for debugging such modifications.\n\n  You must give prominent notice with each copy of the work that the\nLibrary is used in it and that the Library and its use are covered by\nthis License.  You must supply a copy of this License.  If the work\nduring execution displays copyright notices, you must include the\ncopyright notice for the Library among them, as well as a reference\ndirecting the user to the copy of this License.  Also, you must do one\nof these things:\n\n    a) Accompany the work with the complete corresponding\n    machine-readable source code for the Library including whatever\n    changes were used in the work (which must be distributed under\n    Sections 1 and 2 above); and, if the work is an executable linked\n    with the Library, with the complete machine-readable \"work that\n    uses the Library\", as object code and/or source code, so that the\n    user can modify the Library and then relink to produce a modified\n    executable containing the modified Library.  (It is understood\n    that the user who changes the contents of definitions files in the\n    Library will not necessarily be able to recompile the application\n    to use the modified definitions.)\n\n    b) Use a suitable shared library mechanism for linking with the\n    Library.  A suitable mechanism is one that (1) uses at run time a\n    copy of the library already present on the user's computer system,\n    rather than copying library functions into the executable, and (2)\n    will operate properly with a modified version of the library, if\n    the user installs one, as long as the modified version is\n    interface-compatible with the version that the work was made with.\n\n    c) Accompany the work with a written offer, valid for at\n    least three years, to give the same user the materials\n    specified in Subsection 6a, above, for a charge no more\n    than the cost of performing this distribution.\n\n    d) If distribution of the work is made by offering access to copy\n    from a designated place, offer equivalent access to copy the above\n    specified materials from the same place.\n\n    e) Verify that the user has already received a copy of these\n    materials or that you have already sent this user a copy.\n\n  For an executable, the required form of the \"work that uses the\nLibrary\" must include any data and utility programs needed for\nreproducing the executable from it.  However, as a special exception,\nthe materials to be distributed need not include anything that is\nnormally distributed (in either source or binary form) with the major\ncomponents (compiler, kernel, and so on) of the operating system on\nwhich the executable runs, unless that component itself accompanies\nthe executable.\n\n  It may happen that this requirement contradicts the license\nrestrictions of other proprietary libraries that do not normally\naccompany the operating system.  Such a contradiction means you cannot\nuse both them and the Library together in an executable that you\ndistribute.\n\f\n  7. You may place library facilities that are a work based on the\nLibrary side-by-side in a single library together with other library\nfacilities not covered by this License, and distribute such a combined\nlibrary, provided that the separate distribution of the work based on\nthe Library and of the other library facilities is otherwise\npermitted, and provided that you do these two things:\n\n    a) Accompany the combined library with a copy of the same work\n    based on the Library, uncombined with any other library\n    facilities.  This must be distributed under the terms of the\n    Sections above.\n\n    b) Give prominent notice with the combined library of the fact\n    that part of it is a work based on the Library, and explaining\n    where to find the accompanying uncombined form of the same work.\n\n  8. You may not copy, modify, sublicense, link with, or distribute\nthe Library except as expressly provided under this License.  Any\nattempt otherwise to copy, modify, sublicense, link with, or\ndistribute the Library is void, and will automatically terminate your\nrights under this License.  However, parties who have received copies,\nor rights, from you under this License will not have their licenses\nterminated so long as such parties remain in full compliance.\n\n  9. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Library or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Library (or any work based on the\nLibrary), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Library or works based on it.\n\n  10. Each time you redistribute the Library (or any work based on the\nLibrary), the recipient automatically receives a license from the\noriginal licensor to copy, distribute, link with or modify the Library\nsubject to these terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties with\nthis License.\n\f\n  11. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Library at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Library by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Library.\n\nIf any portion of this section is held invalid or unenforceable under any\nparticular circumstance, the balance of the section is intended to apply,\nand the section as a whole is intended to apply in other circumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  12. If the distribution and/or use of the Library is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Library under this License may add\nan explicit geographical distribution limitation excluding those countries,\nso that distribution is permitted only in or among countries not thus\nexcluded.  In such case, this License incorporates the limitation as if\nwritten in the body of this License.\n\n  13. The Free Software Foundation may publish revised and/or new\nversions of the Lesser General Public License from time to time.\nSuch new versions will be similar in spirit to the present version,\nbut may differ in detail to address new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Library\nspecifies a version number of this License which applies to it and\n\"any later version\", you have the option of following the terms and\nconditions either of that version or of any later version published by\nthe Free Software Foundation.  If the Library does not specify a\nlicense version number, you may choose any version ever published by\nthe Free Software Foundation.\n\f\n  14. If you wish to incorporate parts of the Library into other free\nprograms whose distribution conditions are incompatible with these,\nwrite to the author to ask for permission.  For software which is\ncopyrighted by the Free Software Foundation, write to the Free\nSoftware Foundation; we sometimes make exceptions for this.  Our\ndecision will be guided by the two goals of preserving the free status\nof all derivatives of our free software and of promoting the sharing\nand reuse of software generally.\n\n          NO WARRANTY\n\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\nDAMAGES.\n\n         END OF TERMS AND CONDITIONS\n\f\n           How to Apply These Terms to Your New Libraries\n\n  If you develop a new library, and you want it to be of the greatest\npossible use to the public, we recommend making it free software that\neveryone can redistribute and change.  You can do so by permitting\nredistribution under these terms (or, alternatively, under the terms of the\nordinary General Public License).\n\n  To apply these terms, attach the following notices to the library.  It is\nsafest to attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least the\n\"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the library's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This library is free software; you can redistribute it and/or\n    modify it under the terms of the GNU Lesser General Public\n    License as published by the Free Software Foundation; either\n    version 2.1 of the License, or (at your option) any later version.\n\n    This library is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n    Lesser General Public License for more details.\n\n    You should have received a copy of the GNU Lesser General Public\n    License along with this library; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\nAlso add information on how to contact you by electronic and paper mail.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\n\n  <signature of Ty Coon>, 1 April 1990\n  Ty Coon, President of Vice\n\nThat's all there is to it!\n\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/Makefile",
    "content": "RGSRC=../..\ninclude $(RGSRC)/envir.mak\n\nSUBDIRS=SRC\n\nCD_EXPORTED_FILES+=CPL.html history.txt LGPL.txt lzma.txt\nJPKG_EXPORTED_DIR+=SRC\nLINK_DIRS+=SRC\n\ninclude $(RGMK)\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/.cvsignore",
    "content": "lzma\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Common/FileStreams.cpp",
    "content": "// FileStreams.cpp\n\n#include \"StdAfx.h\"\n\n#ifndef WIN32\n#include <fcntl.h>\n#include <unistd.h>\n#endif\n\n#include \"FileStreams.h\"\n\nstatic inline HRESULT ConvertBoolToHRESULT(bool result)\n{\n  // return result ? S_OK: E_FAIL;\n  #ifdef WIN32\n  return result ? S_OK: (::GetLastError());\n  #else\n  return result ? S_OK: E_FAIL;\n  #endif\n}\n\nbool CInFileStream::Open(LPCTSTR fileName)\n{\n  return File.Open(fileName);\n}\n\n#ifdef WIN32\n#ifndef _UNICODE\nbool CInFileStream::Open(LPCWSTR fileName)\n{\n  return File.Open(fileName);\n}\n#endif\n#endif\n\nSTDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  #ifdef WIN32\n  \n  UInt32 realProcessedSize;\n  bool result = File.Read(data, size, realProcessedSize);\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return ConvertBoolToHRESULT(result);\n  \n  #else\n  \n  if(processedSize != NULL)\n    *processedSize = 0;\n  ssize_t res = File.Read(data, (size_t)size);\n  if (res == -1)\n    return E_FAIL;\n  if(processedSize != NULL)\n    *processedSize = (UInt32)res;\n  return S_OK;\n  \n  #endif\n}\n  \nSTDMETHODIMP CInFileStream::ReadPart(void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Read(data, size, processedSize);\n}\n\n#ifndef _WIN32_WCE\nSTDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  #ifdef WIN32\n  UInt32 realProcessedSize;\n  BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), \n      data, size, (DWORD *)&realProcessedSize, NULL);\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE)\n    return S_OK;\n  return ConvertBoolToHRESULT(res != FALSE);\n  \n  #else\n\n  if(processedSize != NULL)\n    *processedSize = 0;\n  ssize_t res = read(0, data, (size_t)size);\n  if (res == -1)\n    return E_FAIL;\n  if(processedSize != NULL)\n    *processedSize = (UInt32)res;\n  return S_OK;\n  \n  #endif\n}\n  \nSTDMETHODIMP CStdInFileStream::ReadPart(void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Read(data, size, processedSize);\n}\n#endif\n\nSTDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, \n    UInt64 *newPosition)\n{\n  if(seekOrigin >= 3)\n    return STG_E_INVALIDFUNCTION;\n\n  #ifdef WIN32\n\n  UInt64 realNewPosition;\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\n  if(newPosition != NULL)\n    *newPosition = realNewPosition;\n  return ConvertBoolToHRESULT(result);\n  \n  #else\n  \n  off_t res = File.Seek(offset, seekOrigin);\n  if (res == -1)\n    return E_FAIL;\n  if(newPosition != NULL)\n    *newPosition = (UInt64)res;\n  return S_OK;\n  \n  #endif\n}\n\nSTDMETHODIMP CInFileStream::GetSize(UInt64 *size)\n{\n  return ConvertBoolToHRESULT(File.GetLength(*size));\n}\n\n\n//////////////////////////\n// COutFileStream\n\nbool COutFileStream::Create(LPCTSTR fileName, bool createAlways)\n{\n  return File.Create(fileName, createAlways);\n}\n\n#ifdef WIN32\n#ifndef _UNICODE\nbool COutFileStream::Create(LPCWSTR fileName, bool createAlways)\n{\n  return File.Create(fileName, createAlways);\n}\n#endif\n#endif\n\nSTDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  #ifdef WIN32\n\n  UInt32 realProcessedSize;\n  bool result = File.Write(data, size, realProcessedSize);\n  if(processedSize != NULL)\n    *processedSize = realProcessedSize;\n  return ConvertBoolToHRESULT(result);\n  \n  #else\n  \n  if(processedSize != NULL)\n    *processedSize = 0;\n  ssize_t res = File.Write(data, (size_t)size);\n  if (res == -1)\n    return E_FAIL;\n  if(processedSize != NULL)\n    *processedSize = (UInt32)res;\n  return S_OK;\n  \n  #endif\n}\n  \nSTDMETHODIMP COutFileStream::WritePart(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Write(data, size, processedSize);\n}\n\n\nSTDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, \n    UInt64 *newPosition)\n{\n  if(seekOrigin >= 3)\n    return STG_E_INVALIDFUNCTION;\n  #ifdef WIN32\n\n  UInt64 realNewPosition;\n  bool result = File.Seek(offset, seekOrigin, realNewPosition);\n  if(newPosition != NULL)\n    *newPosition = realNewPosition;\n  return ConvertBoolToHRESULT(result);\n  \n  #else\n  \n  off_t res = File.Seek(offset, seekOrigin);\n  if (res == -1)\n    return E_FAIL;\n  if(newPosition != NULL)\n    *newPosition = (UInt64)res;\n  return S_OK;\n  \n  #endif\n}\n\nSTDMETHODIMP COutFileStream::SetSize(Int64 newSize)\n{\n  #ifdef WIN32\n  UInt64 currentPos;\n  if(!File.Seek(0, FILE_CURRENT, currentPos))\n    return E_FAIL;\n  bool result = File.SetLength(newSize);\n  UInt64 currentPos2;\n  result = result && File.Seek(currentPos, currentPos2);\n  return result ? S_OK : E_FAIL;\n  #else\n  return E_FAIL;\n  #endif\n}\n\n#ifndef _WIN32_WCE\nSTDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  if(processedSize != NULL)\n    *processedSize = 0;\n\n  #ifdef WIN32\n  UInt32 realProcessedSize;\n  BOOL res = TRUE;\n  while (size > 0)\n  {\n    // Seems that Windows doesn't like big amounts writing to stdout.\n    // So we limit portions by 32KB.\n    UInt32 sizeTemp = (1 << 15); \n    if (sizeTemp > size)\n      sizeTemp = size;\n    res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), \n        data, sizeTemp, (DWORD *)&realProcessedSize, NULL);\n    if (realProcessedSize == 0)\n      break;\n    size -= realProcessedSize;\n    data = (const void *)((const Byte *)data + realProcessedSize);\n    if(processedSize != NULL)\n      *processedSize += realProcessedSize;\n  }\n  return ConvertBoolToHRESULT(res != FALSE);\n\n  #else\n  \n  ssize_t res = write(1, data, (size_t)size);\n  if (res == -1)\n    return E_FAIL;\n  if(processedSize != NULL)\n    *processedSize = (UInt32)res;\n  return S_OK;\n  \n  return S_OK;\n  #endif\n}\n  \nSTDMETHODIMP CStdOutFileStream::WritePart(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Write(data, size, processedSize);\n}\n#endif\n\nSTDMETHODIMP CMemInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  if(processedSize != NULL)\n    *processedSize = 0;\n\n  if (size > _buf_size - _pos)\n    size = _buf_size - _pos;\n\n  memcpy(data, (char *)_buf + _pos, size);\n  _pos += size;\n    \n  if(processedSize != NULL)\n    *processedSize = size;\n  return S_OK;\n}\n  \nSTDMETHODIMP CMemInFileStream::ReadPart(void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Read(data, size, processedSize);\n}\n\nSTDMETHODIMP CMemOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  if(processedSize != NULL)\n    *processedSize = 0;\n\n  /* Consider not enough space in buffer as failure */\n  if (size > _buf_size - _pos)\n    return E_FAIL;\n\n  memcpy((char *)_buf + _pos, data, size);\n  _pos += size;\n  \t\n  if(processedSize != NULL)\n    *processedSize = size;\n\n  return S_OK;\n}\n\nSTDMETHODIMP CMemOutFileStream::WritePart(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Write(data, size, processedSize);\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Common/FileStreams.h",
    "content": "// FileStreams.h\n\n#ifndef __FILESTREAMS_H\n#define __FILESTREAMS_H\n\n#ifdef WIN32\n#include \"../../Windows/FileIO.h\"\n#else\n#include \"../../Common/C_FileIO.h\"\n#endif\n\n#include \"../IStream.h\"\n#include \"../../Common/MyCom.h\"\n\nclass CInFileStream: \n  public IInStream,\n  public IStreamGetSize,\n  public CMyUnknownImp\n{\npublic:\n  #ifdef WIN32\n  NWindows::NFile::NIO::CInFile File;\n  #else\n  NC::NFile::NIO::CInFile File;\n  #endif\n  CInFileStream() {}\n  virtual ~CInFileStream() {}\n\n  bool Open(LPCTSTR fileName);\n  #ifdef WIN32\n  #ifndef _UNICODE\n  bool Open(LPCWSTR fileName);\n  #endif\n  #endif\n\n  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\n\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\n\n  STDMETHOD(GetSize)(UInt64 *size);\n};\n\n#ifndef _WIN32_WCE\nclass CStdInFileStream: \n  public ISequentialInStream,\n  public CMyUnknownImp\n{\npublic:\n  // HANDLE File;\n  // CStdInFileStream() File(INVALID_HANDLE_VALUE): {}\n  // void Open() { File = GetStdHandle(STD_INPUT_HANDLE); };\n  MY_UNKNOWN_IMP\n\n  virtual ~CStdInFileStream() {}\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);\n};\n#endif\n\nclass COutFileStream: \n  public IOutStream,\n  public CMyUnknownImp\n{\npublic:\n  #ifdef WIN32\n  NWindows::NFile::NIO::COutFile File;\n  #else\n  NC::NFile::NIO::COutFile File;\n  #endif\n  virtual ~COutFileStream() {}\n  bool Create(LPCTSTR fileName, bool createAlways);\n  #ifdef WIN32\n  #ifndef _UNICODE\n  bool Create(LPCWSTR fileName, bool createAlways);\n  #endif\n  #endif\n  \n  MY_UNKNOWN_IMP1(IOutStream)\n\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\n  STDMETHOD(SetSize)(Int64 newSize);\n};\n\n#ifndef _WIN32_WCE\nclass CStdOutFileStream: \n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n\n  virtual ~CStdOutFileStream() {}\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n#endif\n\nclass CMemInFileStream: \n  public ISequentialInStream,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n  UInt32 _pos, _buf_size;\n  void *_buf;\n\n  CMemInFileStream() { _pos = 0; _buf = NULL; }\n  virtual ~CMemInFileStream() {}\n  void SetBuffer(void *buf, int buf_size) { _buf = buf; _buf_size = buf_size; }\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);\n};\n\nclass CMemOutFileStream: \n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\npublic:\n  MY_UNKNOWN_IMP\n  UInt32 _pos, _buf_size;\n  void *_buf;\n\n  CMemOutFileStream() { _pos = 0; _buf = NULL; }\n  UInt32 DataSize(void) { return _pos; }\n  virtual ~CMemOutFileStream() {}\n  void SetBuffer(void *buf, int buf_size) { _buf = buf; _buf_size = buf_size; }\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Common/InBuffer.cpp",
    "content": "// InBuffer.cpp\n\n#include \"StdAfx.h\"\n\n#include \"InBuffer.h\"\n\n#include \"../../Common/Alloc.h\"\n\nCInBuffer::CInBuffer(): \n  _bufferBase(0), \n  _bufferSize(0),\n  _buffer(0), \n  _bufferLimit(0), \n  _stream(0) \n{}\n\nbool CInBuffer::Create(UInt32 bufferSize)\n{\n  const UInt32 kMinBlockSize = 1;\n  if (bufferSize < kMinBlockSize)\n    bufferSize = kMinBlockSize;\n  if (_bufferBase != 0 && _bufferSize == bufferSize)\n    return true;\n  Free();\n  _bufferSize = bufferSize;\n  _bufferBase = (Byte *)::BigAlloc(bufferSize);\n  return (_bufferBase != 0);\n}\n\nvoid CInBuffer::Free()\n{\n  BigFree(_bufferBase);\n  _bufferBase = 0;\n}\n\nvoid CInBuffer::SetStream(ISequentialInStream *stream)\n{\n  _stream = stream;\n}\n\nvoid CInBuffer::Init()\n{\n  _processedSize = 0;\n  _buffer = _bufferBase;\n  _bufferLimit = _buffer;\n  _wasFinished = false;\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = S_OK;\n  #endif\n}\n\nbool CInBuffer::ReadBlock()\n{\n  #ifdef _NO_EXCEPTIONS\n  if (ErrorCode != S_OK)\n    return false;\n  #endif\n  if (_wasFinished)\n    return false;\n  _processedSize += (_buffer - _bufferBase);\n  UInt32 numProcessedBytes;\n  HRESULT result = _stream->ReadPart(_bufferBase, _bufferSize, &numProcessedBytes);\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = result;\n  #else\n  if (result != S_OK)\n    throw CInBufferException(result);\n  #endif\n  _buffer = _bufferBase;\n  _bufferLimit = _buffer + numProcessedBytes;\n  _wasFinished = (numProcessedBytes == 0);\n  return (!_wasFinished);\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Common/InBuffer.h",
    "content": "// InBuffer.h\n\n#ifndef __INBUFFER_H\n#define __INBUFFER_H\n\n#include \"../IStream.h\"\n#include \"../../Common/MyCom.h\"\n\n#ifndef _NO_EXCEPTIONS\nclass CInBufferException\n{\npublic:\n  HRESULT ErrorCode;\n  CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\n};\n#endif\n\nclass CInBuffer\n{\n  UInt64 _processedSize;\n  Byte *_bufferBase;\n  UInt32 _bufferSize;\n  Byte *_buffer;\n  Byte *_bufferLimit;\n  CMyComPtr<ISequentialInStream> _stream;\n  bool _wasFinished;\n\n  bool ReadBlock();\n\npublic:\n  #ifdef _NO_EXCEPTIONS\n  HRESULT ErrorCode;\n  #endif\n\n  CInBuffer();\n  ~CInBuffer() { Free(); }\n\n  bool Create(UInt32 bufferSize);\n  void Free();\n  \n  void SetStream(ISequentialInStream *stream);\n  void Init();\n  void ReleaseStream() { _stream.Release(); }\n\n  bool ReadByte(Byte &b)\n  {\n    if(_buffer >= _bufferLimit)\n      if(!ReadBlock())\n        return false;\n    b = *_buffer++;\n    return true;\n  }\n  Byte ReadByte()\n  {\n    if(_buffer >= _bufferLimit)\n      if(!ReadBlock())\n        return 0xFF;\n    return *_buffer++;\n  }\n  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)\n  {\n    for(processedSize = 0; processedSize < size; processedSize++)\n      if (!ReadByte(((Byte *)data)[processedSize]))\n        return;\n  }\n  bool ReadBytes(void *data, UInt32 size)\n  {\n    UInt32 processedSize;\n    ReadBytes(data, size, processedSize);\n    return (processedSize == size);\n  }\n  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\n  bool WasFinished() const { return _wasFinished; }\n};\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Common/Makefile",
    "content": "RGSRC=../../../../..\ninclude $(RGSRC)/envir.mak\n\nOBJS=InBuffer.o OutBuffer.o FileStreams.o\n\ninclude $(LZMAMK)\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Common/OutBuffer.cpp",
    "content": "// OutByte.cpp\n\n#include \"StdAfx.h\"\n\n#include \"OutBuffer.h\"\n\n#include \"../../Common/Alloc.h\"\n\nbool COutBuffer::Create(UInt32 bufferSize)\n{\n  const UInt32 kMinBlockSize = 1;\n  if (bufferSize < kMinBlockSize)\n    bufferSize = kMinBlockSize;\n  if (_buffer != 0 && _bufferSize == bufferSize)\n    return true;\n  Free();\n  _bufferSize = bufferSize;\n  _buffer = (Byte *)::BigAlloc(bufferSize);\n  return (_buffer != 0);\n}\n\nvoid COutBuffer::Free()\n{\n  BigFree(_buffer);\n  _buffer = 0;\n}\n\nvoid COutBuffer::SetStream(ISequentialOutStream *stream)\n{\n  _stream = stream;\n}\n\nvoid COutBuffer::Init()\n{\n  _processedSize = 0;\n  _pos = 0;\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = S_OK;\n  #endif\n}\n\nHRESULT COutBuffer::Flush()\n{\n  if (_pos == 0)\n    return S_OK;\n  UInt32 processedSize;\n  HRESULT result = _stream->Write(_buffer, _pos, &processedSize);\n  if (result != S_OK)\n    return result;\n  if (_pos != processedSize)\n    return E_FAIL;\n  _processedSize += processedSize;\n  _pos = 0;\n  return S_OK;\n}\n\nvoid COutBuffer::WriteBlock()\n{\n  #ifdef _NO_EXCEPTIONS\n  if (ErrorCode != S_OK)\n    return;\n  #endif\n  HRESULT result = Flush();\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = result;\n  #else\n  if (result != S_OK)\n    throw COutBufferException(result);\n  #endif\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Common/OutBuffer.h",
    "content": "// OutBuffer.h\n\n#ifndef __OUTBUFFER_H\n#define __OUTBUFFER_H\n\n#include \"../IStream.h\"\n#include \"../../Common/MyCom.h\"\n\n#ifndef _NO_EXCEPTIONS\nstruct COutBufferException\n{\n  HRESULT ErrorCode;\n  COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\n};\n#endif\n\nclass COutBuffer\n{\n  Byte *_buffer;\n  UInt32 _pos;\n  UInt32 _bufferSize;\n  CMyComPtr<ISequentialOutStream> _stream;\n  UInt64 _processedSize;\n\n  void WriteBlock();\npublic:\n  #ifdef _NO_EXCEPTIONS\n  HRESULT ErrorCode;\n  #endif\n\n  COutBuffer(): _buffer(0), _pos(0), _stream(0) {}\n  ~COutBuffer() { Free(); }\n  \n  bool Create(UInt32 bufferSize);\n  void Free();\n\n  void SetStream(ISequentialOutStream *stream);\n  void Init();\n  HRESULT Flush();\n  void ReleaseStream() {  _stream.Release(); }\n\n  /*\n  void *GetBuffer(UInt32 &sizeAvail)\n  {\n    sizeAvail = _bufferSize - _pos;\n    return _buffer + _pos;\n  }\n  void MovePos(UInt32 num)\n  {\n    _pos += num;\n    if(_pos >= _bufferSize)\n      WriteBlock();\n  }\n  */\n\n  void WriteByte(Byte b)\n  {\n    _buffer[_pos++] = b;\n    if(_pos >= _bufferSize)\n      WriteBlock();\n  }\n  void WriteBytes(const void *data, UInt32 size)\n  {\n    for (UInt32 i = 0; i < size; i++)\n      WriteByte(((const Byte *)data)[i]);\n  }\n\n  UInt64 GetProcessedSize() const { return _processedSize + _pos; }\n};\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Common/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#ifdef WIN32\n#include <windows.h>\n#endif\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/ARM.cpp",
    "content": "// ARM.cpp\n\n#include \"StdAfx.h\"\n#include \"ARM.h\"\n\n#include \"BranchARM.c\"\n\nUInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::ARM_Convert(data, size, _bufferPos, 1);\n}\n\nUInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::ARM_Convert(data, size, _bufferPos, 0);\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/ARM.h",
    "content": "// ARM.h\n\n#ifndef __ARM_H\n#define __ARM_H\n\n#include \"BranchCoder.h\"\n\nMyClassA(BC_ARM, 0x05, 1)\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/ARMThumb.cpp",
    "content": "// ARMThumb.cpp\n\n#include \"StdAfx.h\"\n#include \"ARMThumb.h\"\n\n#include \"BranchARMThumb.c\"\n\nUInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::ARMThumb_Convert(data, size, _bufferPos, 1);\n}\n\nUInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::ARMThumb_Convert(data, size, _bufferPos, 0);\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/ARMThumb.h",
    "content": "// ARMThumb.h\n\n#ifndef __ARMTHUMB_H\n#define __ARMTHUMB_H\n\n#include \"BranchCoder.h\"\n\nMyClassA(BC_ARMThumb, 0x07, 1)\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchARM.c",
    "content": "// BranchARM.c\n\n#include \"BranchARM.h\"\n\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\n{\n  UInt32 i;\n  for (i = 0; i + 4 <= size; i += 4)\n  {\n    if (data[i + 3] == 0xEB)\n    {\n      UInt32 src = (data[i + 2] << 16) | (data[i + 1] << 8) | (data[i + 0]);\n      src <<= 2;\n      UInt32 dest;\n      if (encoding)\n        dest = nowPos + i + 8 + src;\n      else\n        dest = src - (nowPos + i + 8);\n      dest >>= 2;\n      data[i + 2] = (dest >> 16);\n      data[i + 1] = (dest >> 8);\n      data[i + 0] = dest;\n    }\n  }\n  return i;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchARM.h",
    "content": "// BranchARM.h\n\n#ifndef __BRANCH_ARM_H\n#define __BRANCH_ARM_H\n\n#include \"Common/Types.h\"\n\nUInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchARMThumb.c",
    "content": "// BranchARMThumb.c\n\n#include \"BranchARMThumb.h\"\n\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\n{\n  UInt32 i;\n  for (i = 0; i + 4 <= size; i += 2)\n  {\n    if ((data[i + 1] & 0xF8) == 0xF0 && \n        (data[i + 3] & 0xF8) == 0xF8)\n    {\n      UInt32 src = \n        ((data[i + 1] & 0x7) << 19) |\n        (data[i + 0] << 11) |\n        ((data[i + 3] & 0x7) << 8) |\n        (data[i + 2]);\n      \n      src <<= 1;\n      UInt32 dest;\n      if (encoding)\n        dest = nowPos + i + 4 + src;\n      else\n        dest = src - (nowPos + i + 4);\n      dest >>= 1;\n      \n      data[i + 1] = 0xF0 | ((dest >> 19) & 0x7);\n      data[i + 0] = (dest >> 11);\n      data[i + 3] = 0xF8 | ((dest >> 8) & 0x7);\n      data[i + 2] = (dest);\n      i += 2;\n    }\n  }\n  return i;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchARMThumb.h",
    "content": "// BranchARMThumb.h\n\n#ifndef __BRANCH_ARM_THUMB_H\n#define __BRANCH_ARM_THUMB_H\n\n#include \"Common/Types.h\"\n\nUInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchCoder.cpp",
    "content": "// BranchCoder.cpp\n\n#include \"StdAfx.h\"\n#include \"BranchCoder.h\"\n\nSTDMETHODIMP CBranchConverter::Init()\n{\n  _bufferPos = 0;\n  SubInit();\n  return S_OK;\n}\n\nSTDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)\n{\n  UInt32 processedSize = SubFilter(data, size);\n  _bufferPos += processedSize;\n  return processedSize;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchCoder.h",
    "content": "// BranchCoder.h\n\n#ifndef __BRANCH_CODER_H\n#define __BRANCH_CODER_H\n\n#include \"Common/MyCom.h\"\n#include \"Common/Types.h\"\n#include \"Common/Alloc.h\"\n\n#include \"../../ICoder.h\"\n\nclass CBranchConverter:\n  public ICompressFilter,\n  public CMyUnknownImp\n{\nprotected:\n  UInt32 _bufferPos;\n  virtual void SubInit() {}\n  virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;\npublic:\n  MY_UNKNOWN_IMP;\n  STDMETHOD(Init)();\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);\n};\n\n#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \\\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \n\n#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \\\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); }; \n\n#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \n\n#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \\\n  { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT}; \n\n#define MyClass2b(Name, id, subId, encodingId)  \\\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00); \n\n#define MyClassA(Name, id, subId)  \\\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\nMyClassEncoderA(Name ## _Encoder) \\\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\nMyClassDecoderA(Name ## _Decoder)\n\n#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT)  \\\nMyClass2b(Name ## _Encoder, id, subId, 0x01) \\\nMyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \\\nMyClass2b(Name ## _Decoder, id, subId, 0x00) \\\nMyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchIA64.c",
    "content": "// BranchIA64.c\n\n#include \"BranchIA64.h\"\n\nconst Byte kBranchTable[32] = \n{ \n  0, 0, 0, 0, 0, 0, 0, 0,\n  0, 0, 0, 0, 0, 0, 0, 0,\n  4, 4, 6, 6, 0, 0, 7, 7,\n  4, 4, 0, 0, 4, 4, 0, 0 \n};\n\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\n{\n  UInt32 i;\n  for (i = 0; i + 16 <= size; i += 16)\n  {\n    UInt32 instrTemplate = data[i] & 0x1F;\n    UInt32 mask = kBranchTable[instrTemplate];\n    UInt32 bitPos = 5;\n    for (int slot = 0; slot < 3; slot++, bitPos += 41)\n    {\n      if (((mask >> slot) & 1) == 0)\n        continue;\n      UInt32 bytePos = (bitPos >> 3);\n      UInt32 bitRes = bitPos & 0x7;\n      // UInt64 instruction = *(UInt64 *)(data + i + bytePos);\n      UInt64 instruction = 0;\n      int j;\n      for (j = 0; j < 6; j++)\n        instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);\n\n      UInt64 instNorm = instruction >> bitRes;\n      if (((instNorm >> 37) & 0xF) == 0x5 \n        &&  ((instNorm >> 9) & 0x7) == 0 \n        // &&  (instNorm & 0x3F)== 0 \n        )\n      {\n        UInt32 src = UInt32((instNorm >> 13) & 0xFFFFF);\n        src |= ((instNorm >> 36) & 1) << 20;\n        \n        src <<= 4;\n        \n        UInt32 dest;\n        if (encoding)\n          dest = nowPos + i + src;\n        else\n          dest = src - (nowPos + i);\n        \n        dest >>= 4;\n        \n        instNorm &= ~(UInt64(0x8FFFFF) << 13);\n        instNorm |= (UInt64(dest & 0xFFFFF) << 13);\n        instNorm |= (UInt64(dest & 0x100000) << (36 - 20));\n        \n        instruction &= (1 << bitRes) - 1;\n        instruction |= (instNorm << bitRes);\n        // *(UInt64 *)(data + i + bytePos) = instruction;\n        for (j = 0; j < 6; j++)\n          data[i + j + bytePos] = Byte(instruction >> (8 * j));\n      }\n    }\n  }\n  return i;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchIA64.h",
    "content": "// BranchIA64.h\n\n#ifndef __BRANCH_IA64_H\n#define __BRANCH_IA64_H\n\n#include \"Common/Types.h\"\n\nUInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchPPC.c",
    "content": "// BranchPPC.c\n\n#include \"BranchPPC.h\"\n\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)\n{\n  UInt32 i;\n  for (i = 0; i + 4 <= size; i += 4)\n  {\n    // PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link)\n    if ((data[i] >> 2) == 0x12 && \n    (\n      (data[i + 3] & 3) == 1 \n      // || (data[i+3] & 3) == 3\n      )\n    )\n    {\n      UInt32 src = ((data[i + 0] & 3) << 24) |\n        (data[i + 1] << 16) |\n        (data[i + 2] << 8) |\n        (data[i + 3] & (~3));\n      \n      UInt32 dest;\n      if (encoding)\n        dest = nowPos + i + src;\n      else\n        dest = src - (nowPos + i);\n      data[i + 0] = 0x48 | ((dest >> 24) &  0x3);\n      data[i + 1] = (dest >> 16);\n      data[i + 2] = (dest >> 8);\n      data[i + 3] &= 0x3;\n      data[i + 3] |= dest;\n    }\n  }\n  return i;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchPPC.h",
    "content": "// BranchPPC.h\n\n#ifndef __BRANCH_PPC_H\n#define __BRANCH_PPC_H\n\n#include \"Common/Types.h\"\n\nUInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchX86.c",
    "content": "// BranchX86.c\n\n#include \"BranchX86.h\"\n\nstatic int inline Test86MSByte(Byte b)\n{\n  return (b == 0 || b == 0xFF);\n}\n\nconst int kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\nconst Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\n\nvoid x86_Convert_Init(UInt32 *prevMask, UInt32 *prevPos)\n{\n  *prevMask = 0;\n  *prevPos = (-5);\n}\n\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \n    UInt32 *prevMask, UInt32 *prevPos, int encoding)\n{\n  UInt32 bufferPos = 0;\n\n  if (endPos < 5)\n    return 0;\n  \n  if (nowPos - *prevPos > 5)\n    *prevPos = nowPos - 5;\n  \n  UInt32 limit = endPos - 5;\n  while(bufferPos <= limit)\n  {\n    Byte b = buffer[bufferPos];\n    if (b != 0xE8 && b != 0xE9)\n    {\n      bufferPos++;\n      continue;\n    }\n    UInt32 offset = (nowPos + bufferPos - *prevPos);\n    *prevPos = (nowPos + bufferPos);\n    if (offset > 5)\n      *prevMask = 0;\n    else\n    {\n      for (UInt32 i = 0; i < offset; i++)\n      {\n        *prevMask &= 0x77;\n        *prevMask <<= 1;\n      }\n    }\n    Byte &nextByte = buffer[bufferPos + 4];\n    if (Test86MSByte(nextByte) && kMaskToAllowedStatus[(*prevMask >> 1) & 0x7] && \n      (*prevMask >> 1) < 0x10)\n    {\n      UInt32 src = \n        (UInt32(nextByte) << 24) |\n        (UInt32(buffer[bufferPos + 3]) << 16) |\n        (UInt32(buffer[bufferPos + 2]) << 8) |\n        (buffer[bufferPos + 1]);\n      \n      UInt32 dest;\n      while(true)\n      {\n        if (encoding)\n          dest = (nowPos + bufferPos + 5) + src;\n        else\n          dest = src - (nowPos + bufferPos + 5);\n        if (*prevMask == 0)\n          break;\n        UInt32 index = kMaskToBitNumber[*prevMask >> 1];\n        if (!Test86MSByte(dest >> (24 - index * 8)))\n          break;\n        src = dest ^ ((1 << (32 - index * 8)) - 1);\n        // src = dest;\n      }\n      nextByte = ~(((dest >> 24) & 1) - 1);\n      buffer[bufferPos + 3] = (dest >> 16);\n      buffer[bufferPos + 2] = (dest >> 8);\n      buffer[bufferPos + 1] = dest;\n      bufferPos += 5;\n      *prevMask = 0;\n    }\n    else\n    {\n      bufferPos++;\n      *prevMask |= 1;\n      if (Test86MSByte(nextByte))\n        *prevMask |= 0x10;\n    }\n  }\n  return bufferPos;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/BranchX86.h",
    "content": "// BranchX86.h\n\n#ifndef __BRANCHX86_H\n#define __BRANCHX86_H\n\n#include \"Common/Types.h\"\n\nvoid x86_Convert_Init(UInt32 *prevMask, UInt32 *prevPos);\nUInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, \n    UInt32 *prevMask, UInt32 *prevPos, int encoding);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/IA64.cpp",
    "content": "// IA64.cpp\n\n#include \"StdAfx.h\"\n#include \"IA64.h\"\n\n#include \"BranchIA64.c\"\n\nUInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::IA64_Convert(data, size, _bufferPos, 1);\n}\n\nUInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::IA64_Convert(data, size, _bufferPos, 0);\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/IA64.h",
    "content": "// IA64.h\n\n#ifndef __IA64_H\n#define __IA64_H\n\n#include \"BranchCoder.h\"\n\nMyClassA(BC_IA64, 0x04, 1)\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/PPC.cpp",
    "content": "// PPC.cpp\n\n#include \"StdAfx.h\"\n#include \"PPC.h\"\n\n#include \"Windows/Defs.h\"\n#include \"BranchPPC.c\"\n\nUInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::PPC_B_Convert(data, size, _bufferPos, 1);\n}\n\nUInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::PPC_B_Convert(data, size, _bufferPos, 0);\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/PPC.h",
    "content": "// PPC.h\n\n#ifndef __PPC_H\n#define __PPC_H\n\n#include \"BranchCoder.h\"\n\nMyClassA(BC_PPC_B, 0x02, 5)\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/StdAfx.h",
    "content": "// stdafx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#include <windows.h>\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/x86.cpp",
    "content": "// x86.cpp\n\n#include \"StdAfx.h\"\n#include \"x86.h\"\n\n#include \"Windows/Defs.h\"\n\n#include \"BranchX86.c\"\n\nUInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 1);\n}\n\nUInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)\n{\n  return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 0);\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/x86.h",
    "content": "// x86.h\n\n#ifndef __X86_H\n#define __X86_H\n\n#include \"BranchCoder.h\"\n#include \"BranchX86.h\"\n\nstruct CBranch86\n{\n  UInt32 _prevMask;\n  UInt32 _prevPos;\npublic:\n  void x86Init()\n  {\n    x86_Convert_Init(&_prevMask, &_prevPos);\n  }\n};\n\nMyClassB(BCJ_x86, 0x01, 3, CBranch86 , \n    virtual void SubInit() { x86Init(); })\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/x86_2.cpp",
    "content": "// x86_2.cpp\n\n#include \"StdAfx.h\"\n#include \"x86_2.h\"\n\n#include \"../../../Common/Alloc.h\"\n\nstatic const int kBufferSize = 1 << 17;\n\ninline UInt32 Swap4(UInt32 value)\n{\n  return (value << 24) | (value >> 24) | \n    ( (value >> 8) & 0xFF00) | ( (value << 8) & 0xFF0000);\n}\n\ninline bool IsJcc(Byte b0, Byte b1)\n{\n  return (b0 == 0x0F && (b1 & 0xF0) == 0x80);\n}\n\n#ifndef EXTRACT_ONLY\n\nstatic bool inline Test86MSByte(Byte b)\n{\n  return (b == 0 || b == 0xFF);\n}\n\nbool CBCJ2_x86_Encoder::Create()\n{\n  if (!_mainStream.Create(1 << 16))\n    return false;\n  if (!_callStream.Create(1 << 20))\n    return false;\n  if (!_jumpStream.Create(1 << 20))\n    return false;\n  if (!_rangeEncoder.Create(1 << 20))\n    return false;\n  if (_buffer == 0)\n  {\n    _buffer = (Byte *)BigAlloc(kBufferSize);\n    if (_buffer == 0)\n      return false;\n  }\n  return true;\n}\n\nCBCJ2_x86_Encoder::~CBCJ2_x86_Encoder()\n{\n  BigFree(_buffer);\n}\n\nHRESULT CBCJ2_x86_Encoder::Flush()\n{\n  RINOK(_mainStream.Flush());\n  RINOK(_callStream.Flush());\n  RINOK(_jumpStream.Flush());\n  _rangeEncoder.FlushData();\n  return _rangeEncoder.FlushStream();\n}\n\nconst UInt32 kDefaultLimit = (1 << 24);\n\nHRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress)\n{\n  if (numInStreams != 1 || numOutStreams != 4)\n    return E_INVALIDARG;\n\n  if (!Create())\n    return E_OUTOFMEMORY;\n\n  bool sizeIsDefined = false;\n  UInt64 inSize;\n  if (inSizes != NULL)\n    if (inSizes[0] != NULL)\n    {\n      inSize = *inSizes[0];\n      if (inSize <= kDefaultLimit)\n        sizeIsDefined = true;\n    }\n\n  ISequentialInStream *inStream = inStreams[0];\n\n  _mainStream.SetStream(outStreams[0]);\n  _mainStream.Init();\n  _callStream.SetStream(outStreams[1]);\n  _callStream.Init();\n  _jumpStream.SetStream(outStreams[2]);\n  _jumpStream.Init();\n  _rangeEncoder.SetStream(outStreams[3]);\n  _rangeEncoder.Init();\n  for (int i = 0; i < 256; i++)\n    _statusE8Encoder[i].Init();\n  _statusE9Encoder.Init();\n  _statusJccEncoder.Init();\n  CCoderReleaser releaser(this);\n\n  CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;\n  {\n    inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);\n  }\n\n  UInt32 nowPos = 0;\n  UInt64 nowPos64 = 0;\n  UInt32 bufferPos = 0;\n  UInt32 processedSize;\n\n  Byte prevByte = 0;\n\n  UInt64 subStreamIndex = 0;\n  UInt64 subStreamStartPos  = 0;\n  UInt64 subStreamEndPos = 0;\n\n  while(true)\n  {\n    UInt32 size = kBufferSize - bufferPos;\n    RINOK(inStream->Read(_buffer + bufferPos, size, &processedSize));\n    UInt32 endPos = bufferPos + processedSize;\n    \n    if (endPos < 5)\n    {\n      // change it \n      for (bufferPos = 0; bufferPos < endPos; bufferPos++)\n      {\n        Byte b = _buffer[bufferPos];\n        _mainStream.WriteByte(b);\n        if (b == 0xE8)\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\n        else if (b == 0xE9)\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\n        else if (IsJcc(prevByte, b))\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\n        prevByte = b;\n      }\n      return Flush();\n    }\n\n    bufferPos = 0;\n\n    UInt32 limit = endPos - 5;\n    while(bufferPos <= limit)\n    {\n      Byte b = _buffer[bufferPos];\n      _mainStream.WriteByte(b);\n      if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\n      {\n        bufferPos++;\n        prevByte = b;\n        continue;\n      }\n      Byte nextByte = _buffer[bufferPos + 4];\n      UInt32 src = \n        (UInt32(nextByte) << 24) |\n        (UInt32(_buffer[bufferPos + 3]) << 16) |\n        (UInt32(_buffer[bufferPos + 2]) << 8) |\n        (_buffer[bufferPos + 1]);\n      UInt32 dest = (nowPos + bufferPos + 5) + src;\n      // if (Test86MSByte(nextByte))\n      bool convert;\n      if (getSubStreamSize != NULL)\n      {\n        UInt64 currentPos = (nowPos64 + bufferPos);\n        while (subStreamEndPos < currentPos)\n        {\n          UInt64 subStreamSize;\n          HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);\n          if (result == S_OK)\n          {\n            subStreamStartPos = subStreamEndPos;\n            subStreamEndPos += subStreamSize;          \n            subStreamIndex++;\n          }\n          else if (result == S_FALSE || result == E_NOTIMPL)\n          {\n            getSubStreamSize.Release();\n            subStreamStartPos = 0;\n            subStreamEndPos = subStreamStartPos - 1;          \n          }\n          else\n            return result;\n        }\n        if (getSubStreamSize == NULL)\n        {\n          if (sizeIsDefined)\n            convert = (dest < inSize);\n          else\n            convert = Test86MSByte(nextByte);\n        }\n        else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)\n          convert = Test86MSByte(nextByte);\n        else\n        {\n          UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));\n          convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);\n        }\n      }\n      else if (sizeIsDefined)\n        convert = (dest < inSize);\n      else\n        convert = Test86MSByte(nextByte);\n      if (convert)\n      {\n        if (b == 0xE8)\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 1);\n        else if (b == 0xE9)\n          _statusE9Encoder.Encode(&_rangeEncoder, 1);\n        else \n          _statusJccEncoder.Encode(&_rangeEncoder, 1);\n\n        dest = Swap4(dest);\n\n        bufferPos += 5;\n        if (b == 0xE8)\n          _callStream.WriteBytes(&dest, sizeof(dest));\n        else \n          _jumpStream.WriteBytes(&dest, sizeof(dest));\n        prevByte = nextByte;\n      }\n      else\n      {\n        if (b == 0xE8)\n          _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);\n        else if (b == 0xE9)\n          _statusE9Encoder.Encode(&_rangeEncoder, 0);\n        else\n          _statusJccEncoder.Encode(&_rangeEncoder, 0);\n        bufferPos++;\n        prevByte = b;\n      }\n    }\n    nowPos += bufferPos;\n    nowPos64 += bufferPos;\n\n    if (progress != NULL)\n    {\n      RINOK(progress->SetRatioInfo(&nowPos64, NULL));\n    }\n \n    UInt32 i = 0;\n    while(bufferPos < endPos)\n      _buffer[i++] = _buffer[bufferPos++];\n    bufferPos = i;\n  }\n}\n\nSTDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress)\n{\n  try\n  {\n    return CodeReal(inStreams, inSizes, numInStreams,\n      outStreams, outSizes,numOutStreams, progress);\n  }\n  catch(const COutBufferException &e) { return e.ErrorCode; }\n  catch(...) { return S_FALSE; }\n}\n\n#endif\n\nHRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress)\n{\n  if (numInStreams != 4 || numOutStreams != 1)\n    return E_INVALIDARG;\n\n  if (!_mainInStream.Create(1 << 16))\n    return E_OUTOFMEMORY;\n  if (!_callStream.Create(1 << 20))\n    return E_OUTOFMEMORY;\n  if (!_jumpStream.Create(1 << 16))\n    return E_OUTOFMEMORY;\n  if (!_rangeDecoder.Create(1 << 20))\n    return E_OUTOFMEMORY;\n  if (!_outStream.Create(1 << 16))\n    return E_OUTOFMEMORY;\n\n  _mainInStream.SetStream(inStreams[0]);\n  _callStream.SetStream(inStreams[1]);\n  _jumpStream.SetStream(inStreams[2]);\n  _rangeDecoder.SetStream(inStreams[3]);\n  _outStream.SetStream(outStreams[0]);\n\n  _mainInStream.Init();\n  _callStream.Init();\n  _jumpStream.Init();\n  _rangeDecoder.Init();\n  _outStream.Init();\n\n  for (int i = 0; i < 256; i++)\n    _statusE8Decoder[i].Init();\n  _statusE9Decoder.Init();\n  _statusJccDecoder.Init();\n\n  CCoderReleaser releaser(this);\n\n  Byte prevByte = 0;\n  UInt32 processedBytes = 0;\n  while(true)\n  {\n    if (processedBytes > (1 << 20) && progress != NULL)\n    {\n      UInt64 nowPos64 = _outStream.GetProcessedSize();\n      RINOK(progress->SetRatioInfo(NULL, &nowPos64));\n      processedBytes = 0;\n    }\n    processedBytes++;\n    Byte b;\n    if (!_mainInStream.ReadByte(b))\n      return Flush();\n    _outStream.WriteByte(b);\n    if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))\n    {\n      prevByte = b;\n      continue;\n    }\n    bool status;\n    if (b == 0xE8)\n      status = (_statusE8Decoder[prevByte].Decode(&_rangeDecoder) == 1);\n    else if (b == 0xE9)\n      status = (_statusE9Decoder.Decode(&_rangeDecoder) == 1);\n    else\n      status = (_statusJccDecoder.Decode(&_rangeDecoder) == 1);\n    if (status)\n    {\n      UInt32 src;\n      if (b == 0xE8)\n      {\n        if (!_callStream.ReadBytes(&src, sizeof(src)))\n          return S_FALSE;\n      }\n      else\n      {\n        if (!_jumpStream.ReadBytes(&src, sizeof(src)))\n          return S_FALSE;\n      }\n      src = Swap4(src);\n      UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;\n      _outStream.WriteBytes(&dest, sizeof(dest));\n      prevByte = (dest >> 24);\n      processedBytes += 4;\n    }\n    else\n      prevByte = b;\n  }\n}\n\nSTDMETHODIMP CBCJ2_x86_Decoder::Code(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress)\n{\n  try\n  {\n    return CodeReal(inStreams, inSizes, numInStreams,\n        outStreams, outSizes,numOutStreams, progress);\n  }\n  catch(const COutBufferException &e) { return e.ErrorCode; }\n  catch(...) { return S_FALSE; }\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/Branch/x86_2.h",
    "content": "// x86_2.h\n\n#ifndef __BRANCH_X86_2_H\n#define __BRANCH_X86_2_H\n\n#include \"../../../Common/MyCom.h\"\n#include \"../RangeCoder/RangeCoderBit.h\"\n#include \"../../ICoder.h\"\n\n// {23170F69-40C1-278B-0303-010100000100}\n#define MyClass2_a(Name, id, subId, encodingId)  \\\nDEFINE_GUID(CLSID_CCompressConvert ## Name,  \\\n0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00);\n\n#define MyClass_a(Name, id, subId)  \\\nMyClass2_a(Name ## _Encoder, id, subId, 0x01) \\\nMyClass2_a(Name ## _Decoder, id, subId, 0x00) \n\nMyClass_a(BCJ2_x86, 0x01, 0x1B)\n\nconst int kNumMoveBits = 5;\n\n#ifndef EXTRACT_ONLY\n\nclass CBCJ2_x86_Encoder:\n  public ICompressCoder2,\n  public CMyUnknownImp\n{\n  Byte *_buffer;\npublic:\n  CBCJ2_x86_Encoder(): _buffer(0) {};\n  ~CBCJ2_x86_Encoder();\n  bool Create();\n\n  COutBuffer _mainStream;\n  COutBuffer _callStream;\n  COutBuffer _jumpStream;\n  NCompress::NRangeCoder::CEncoder _rangeEncoder;\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE8Encoder[256];\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE9Encoder;\n  NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusJccEncoder;\n\n  HRESULT Flush();\n  void ReleaseStreams()\n  {\n    _mainStream.ReleaseStream();\n    _callStream.ReleaseStream();\n    _jumpStream.ReleaseStream();\n    _rangeEncoder.ReleaseStream();\n  }\n\n  class CCoderReleaser\n  {\n    CBCJ2_x86_Encoder *_coder;\n  public:\n    CCoderReleaser(CBCJ2_x86_Encoder *coder): _coder(coder) {}\n    ~CCoderReleaser() {  _coder->ReleaseStreams(); }\n  };\n\npublic: \n\n  MY_UNKNOWN_IMP\n\n  HRESULT CodeReal(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress);\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress);\n}; \n\n#endif\n\nclass CBCJ2_x86_Decoder:\n  public ICompressCoder2,\n  public CMyUnknownImp\n{ \npublic:\n  CInBuffer _mainInStream;\n  CInBuffer _callStream;\n  CInBuffer _jumpStream;\n  NCompress::NRangeCoder::CDecoder _rangeDecoder;\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE8Decoder[256];\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE9Decoder;\n  NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusJccDecoder;\n\n  COutBuffer _outStream;\n\n  void ReleaseStreams()\n  {\n    _mainInStream.ReleaseStream();\n    _callStream.ReleaseStream();\n    _jumpStream.ReleaseStream();\n    _rangeDecoder.ReleaseStream();\n    _outStream.ReleaseStream();\n  }\n\n  HRESULT Flush() { return _outStream.Flush(); }\n  class CCoderReleaser\n  {\n    CBCJ2_x86_Decoder *_coder;\n  public:\n    CCoderReleaser(CBCJ2_x86_Decoder *coder): _coder(coder) {}\n    ~CCoderReleaser()  { _coder->ReleaseStreams(); }\n  };\n\npublic: \n  MY_UNKNOWN_IMP\n  HRESULT CodeReal(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress);\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\n      const UInt64 **inSizes,\n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams,\n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress);\n}; \n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTree.h",
    "content": "// BinTree.h\n\n// #ifndef __BINTREE_H\n// #define __BINTREE_H\n\n#include \"../LZInWindow.h\"\n \nnamespace BT_NAMESPACE {\n\ntypedef UInt32 CIndex;\nconst UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\n\n// #define HASH_ARRAY_2\n\n// #ifdef HASH_ARRAY_2\n\n// #define HASH_ARRAY_3\n\n// #else\n\n// #define HASH_ZIP\n\n// #endif\n\nstruct CPair\n{\n  CIndex Left;\n  CIndex Right;\n};\n\n/*\nconst int kNumBundleBits = 2;\nconst UInt32 kNumPairsInBundle = 1 << kNumBundleBits;\nconst UInt32 kBundleMask = kNumPairsInBundle - 1;\nconst UInt32 kNumBundleBytes = kNumPairsInBundle * sizeof(CPair);\n\nstruct CBundle\n{\n  CPair Pairs[kNumPairsInBundle];\n  Byte Bytes[kNumBundleBytes];\n};\n*/\n\nclass CInTree: public CLZInWindow\n{\n  UInt32 _cyclicBufferPos;\n  UInt32 _cyclicBufferSize;\n  UInt32 _historySize;\n  UInt32 _matchMaxLen;\n\n  CIndex *_hash;\n  \n  #ifdef HASH_ARRAY_2\n  CIndex *_hash2;\n  #ifdef HASH_ARRAY_3\n  CIndex *_hash3;\n  #endif\n  #endif\n  \n  // CBundle *_son;\n  CPair *_son;\n\n  UInt32 _cutValue;\n\n  void NormalizeLinks(CIndex *items, UInt32 numItems, UInt32 subValue);\n  void Normalize();\n  void FreeMemory();\n\npublic:\n  CInTree();\n  ~CInTree();\n  HRESULT Create(UInt32 sizeHistory, UInt32 keepAddBufferBefore, UInt32 matchMaxLen, \n      UInt32 keepAddBufferAfter, UInt32 sizeReserv = (1<<17));\n\tHRESULT Init(ISequentialInStream *stream);\n  void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\n  UInt32 GetLongestMatch(UInt32 *distances);\n  void DummyLongestMatch();\n  HRESULT MovePos()\n  {\n    _cyclicBufferPos++;\n    if (_cyclicBufferPos >= _cyclicBufferSize)\n      _cyclicBufferPos = 0;\n    RINOK(CLZInWindow::MovePos());\n    if (_pos == kMaxValForNormalize)\n      Normalize();\n    return S_OK;\n  }\n};\n\n}\n\n// #endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTree2.h",
    "content": "// BinTree2.h\n\n#ifndef __BINTREE2__H\n#define __BINTREE2__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT2\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT2\n\n#include \"BinTreeMF.h\"\n#include \"BinTreeMFMain.h\"\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTree3.h",
    "content": "// BinTree3.h\n\n#ifndef __BINTREE3__H\n#define __BINTREE3__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT3\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT3\n\n#define HASH_ARRAY_2\n\n#include \"BinTreeMF.h\"\n#include \"BinTreeMFMain.h\"\n\n#undef HASH_ARRAY_2\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTree3Z.h",
    "content": "// BinTree3Z.h\n\n#ifndef __BINTREE3Z__H\n#define __BINTREE3Z__H\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT3Z\n\n#define HASH_ZIP\n\n#include \"BinTree.h\"\n// #include \"BinTreeMain.h\"\n\n#undef HASH_ZIP\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTree3ZMain.h",
    "content": "// BinTree3ZMain.h\n\n#ifndef __BINTREE3ZMAIN__H\n#define __BINTREE3ZMAIN__H\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT3Z\n\n#define HASH_ZIP\n\n#include \"BinTreeMain.h\"\n\n#undef HASH_ZIP\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTree4.h",
    "content": "// BinTree4.h\n\n#ifndef __BINTREE4__H\n#define __BINTREE4__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT4\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT4\n\n#define HASH_ARRAY_2\n#define HASH_ARRAY_3\n\n#include \"BinTreeMF.h\"\n#include \"BinTreeMFMain.h\"\n\n#undef HASH_ARRAY_2\n#undef HASH_ARRAY_3\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTree4b.h",
    "content": "// BinTree4b.h\n\n#ifndef __BINTREE4B__H\n#define __BINTREE4B__H\n\n#undef BT_CLSID\n#define BT_CLSID CLSID_CMatchFinderBT4b\n\n#undef BT_NAMESPACE\n#define BT_NAMESPACE NBT4B\n\n#define HASH_ARRAY_2\n#define HASH_ARRAY_3\n#define HASH_BIG\n\n#include \"BinTreeMF.h\"\n#include \"BinTreeMFMain.h\"\n\n#undef HASH_ARRAY_2\n#undef HASH_ARRAY_3\n#undef HASH_BIG\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTreeMF.h",
    "content": "// BinTreeMF.h\n\n// #ifndef __BINTREEMF_H\n// #define __BINTREEMF_H\n\n#include \"../../../ICoder.h\"\n#include \"BinTree.h\"\n\nnamespace BT_NAMESPACE {\n\n#undef kIDByte\n#undef kIDString\n\n#ifdef HASH_ARRAY_2\n  #ifdef HASH_ARRAY_3\n    #ifdef HASH_BIG\n      #define kIDByte 0x4\n      #define kIDString TEXT(\"4b\")\n    #else\n      #define kIDByte 0x3\n      #define kIDString TEXT(\"4\")\n    #endif\n  #else\n    #define kIDByte 0x2\n    #define kIDString TEXT(\"3\")\n  #endif\n#else\n  #ifdef HASH_ZIP\n    #define kIDByte 0x0\n    #define kIDString TEXT(\"3Z\")\n  #else\n    #define kIDByte 0x1\n    #define kIDString TEXT(\"2\")\n  #endif\n#endif\n\n#undef kIDUse3BytesByte\n#undef kIDUse3BytesString\n\n#define kIDUse3BytesByte 0x00\n#define kIDUse3BytesString TEXT(\"\")\n\n// #undef kIDStringFull\n\n// #define kIDStringFull TEXT(\"Compress.MatchFinderBT\") kIDString kIDUse3BytesString\n\n// {23170F69-40C1-278C-02XX-0000000000}\nDEFINE_GUID(BT_CLSID, \n0x23170F69, 0x40C1, 0x278C, 0x02, kIDByte | kIDUse3BytesByte, \n0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\n\nclass CInTree2: public CInTree\n{\n  CMyComPtr<IMatchFinderCallback> _callback;\n  virtual void BeforeMoveBlock();\n  virtual void AfterMoveBlock();\npublic:\n  void SetCallback(IMatchFinderCallback *callback)\n  {\n    _callback = callback;\n  }\n};\n\nclass CMatchFinderBinTree: \n  public IMatchFinder,\n  public IMatchFinderSetCallback,\n  public CMyUnknownImp\n{\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\n\n  STDMETHOD(Init)(ISequentialInStream *stream);\n  STDMETHOD_(void, ReleaseStream)();\n  STDMETHOD(MovePos)();\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\n  STDMETHOD(Create)(UInt32 sizeHistory, \n      UInt32 keepAddBufferBefore, UInt32 matchMaxLen, \n      UInt32 keepAddBufferAfter);\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\n  STDMETHOD_(void, DummyLongestMatch)();\n\n  // IMatchFinderSetCallback\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\n\nprivate:\n  // UInt32 m_WindowReservSize;\n  CInTree2 _matchFinder;\npublic:\n  // CMatchFinderBinTree(): m_WindowReservSize((1 << 19) + 256) {};\n  void SetCutValue(UInt32 cutValue) \n    { _matchFinder.SetCutValue(cutValue); }\n  /*\n  void SetWindowReservSize(UInt32 reservWindowSize)\n    { m_WindowReservSize = reservWindowSize; }\n  */\n  virtual ~CMatchFinderBinTree() {}\n};\n \n}\n\n// #endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTreeMFMain.h",
    "content": "// BinTreeMFMain.h\n\n// #include \"StdAfx.h\"\n\n// #include \"BinTreeMF.h\"\n#include \"BinTreeMain.h\"\n\nnamespace BT_NAMESPACE {\n\nvoid CInTree2::BeforeMoveBlock()\n{\n  if (_callback)\n    _callback->BeforeChangingBufferPos();\n  CInTree::BeforeMoveBlock();\n}\n\nvoid CInTree2::AfterMoveBlock()\n{\n  CInTree::AfterMoveBlock();\n  if (_callback)\n    _callback->AfterChangingBufferPos();\n}\n\nSTDMETHODIMP CMatchFinderBinTree::Init(ISequentialInStream *stream)\n  { return _matchFinder.Init(stream); }\n\nSTDMETHODIMP_(void) CMatchFinderBinTree::ReleaseStream()\n{ \n  // _matchFinder.ReleaseStream(); \n}\n\nSTDMETHODIMP CMatchFinderBinTree::MovePos()\n  { return _matchFinder.MovePos(); }\n\nSTDMETHODIMP_(Byte) CMatchFinderBinTree::GetIndexByte(Int32 index)\n  { return _matchFinder.GetIndexByte(index); }\n\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetMatchLen(Int32 index, \n    UInt32 back, UInt32 limit)\n  { return _matchFinder.GetMatchLen(index, back, limit); }\n\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetNumAvailableBytes()\n  { return _matchFinder.GetNumAvailableBytes(); }\n  \nSTDMETHODIMP CMatchFinderBinTree::Create(UInt32 sizeHistory, \n      UInt32 keepAddBufferBefore, UInt32 matchMaxLen, \n      UInt32 keepAddBufferAfter)\n{ \n  UInt32 windowReservSize = (sizeHistory + keepAddBufferBefore + \n      matchMaxLen + keepAddBufferAfter) / 2 + 256;\n  // try \n  {\n    return _matchFinder.Create(sizeHistory, keepAddBufferBefore, \n        matchMaxLen, keepAddBufferAfter, windowReservSize); \n  }\n  /*\n  catch(...)\n  {\n    return E_OUTOFMEMORY;\n  }\n  */\n}\n\nSTDMETHODIMP_(UInt32) CMatchFinderBinTree::GetLongestMatch(UInt32 *distances)\n  { return _matchFinder.GetLongestMatch(distances); }\n\nSTDMETHODIMP_(void) CMatchFinderBinTree::DummyLongestMatch()\n  { _matchFinder.DummyLongestMatch(); }\n\nSTDMETHODIMP_(const Byte *) CMatchFinderBinTree::GetPointerToCurrentPos()\n{\n  return _matchFinder.GetPointerToCurrentPos();\n}\n\n// IMatchFinderSetCallback\nSTDMETHODIMP CMatchFinderBinTree::SetCallback(IMatchFinderCallback *callback)\n{\n  _matchFinder.SetCallback(callback);\n  return S_OK;\n}\n\n\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/BinTree/BinTreeMain.h",
    "content": "// BinTreeMain.h\n\n#include \"../../../../Common/Defs.h\"\n#include \"../../../../Common/CRC.h\"\n#include \"../../../../Common/Alloc.h\"\n\nnamespace BT_NAMESPACE {\n\n#ifdef HASH_ARRAY_2\n  static const UInt32 kHash2Size = 1 << 10;\n  #ifdef HASH_ARRAY_3\n    static const UInt32 kNumHashDirectBytes = 0;\n    static const UInt32 kNumHashBytes = 4;\n    static const UInt32 kHash3Size = 1 << 18;\n    #ifdef HASH_BIG\n    static const UInt32 kHashSize = 1 << 23;\n    #else\n    static const UInt32 kHashSize = 1 << 20;\n    #endif\n  #else\n    static const UInt32 kNumHashDirectBytes = 3;\n    static const UInt32 kNumHashBytes = 3;\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\n  #endif\n#else\n  #ifdef HASH_ZIP \n    static const UInt32 kNumHashDirectBytes = 0;\n    static const UInt32 kNumHashBytes = 3;\n    static const UInt32 kHashSize = 1 << 16;\n  #else\n    static const UInt32 kNumHashDirectBytes = 2;\n    static const UInt32 kNumHashBytes = 2;\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\n  #endif\n#endif\n\n\nCInTree::CInTree():\n  _hash(0),\n  #ifdef HASH_ARRAY_2\n  _hash2(0),\n  #ifdef HASH_ARRAY_3\n  _hash3(0),\n  #endif\n  #endif\n  _son(0),\n  _cutValue(0xFF)\n{\n}\n\nvoid CInTree::FreeMemory()\n{\n  BigFree(_son);\n  _son = 0;\n  BigFree(_hash);\n  _hash = 0;\n  CLZInWindow::Free();\n}\n\nCInTree::~CInTree()\n{ \n  FreeMemory();\n}\n\nHRESULT CInTree::Create(UInt32 sizeHistory, UInt32 keepAddBufferBefore, \n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, UInt32 sizeReserv)\n{\n  FreeMemory();\n  if (!CLZInWindow::Create(sizeHistory + keepAddBufferBefore, \n      matchMaxLen + keepAddBufferAfter, sizeReserv))\n    return E_OUTOFMEMORY;\n  \n  if (_blockSize + 256 > kMaxValForNormalize)\n    return E_INVALIDARG;\n  \n  _historySize = sizeHistory;\n  _matchMaxLen = matchMaxLen;\n  \n  _cyclicBufferSize = sizeHistory + 1;\n  \n  \n  UInt32 size = kHashSize;\n  #ifdef HASH_ARRAY_2\n  size += kHash2Size;\n  #ifdef HASH_ARRAY_3\n  size += kHash3Size;\n  #endif\n  #endif\n  \n  _son = (CPair *)BigAlloc((_cyclicBufferSize + 1) * sizeof(CPair));\n  if (_son == 0)\n  {\n    FreeMemory();\n    return E_OUTOFMEMORY;\n  }\n  \n  // UInt32 numBundles = (_cyclicBufferSize + kNumPairsInBundle) >> kNumBundleBits;\n  // _son = (CBundle *)::VirtualAlloc(0, numBundles * sizeof(CBundle), MEM_COMMIT, PAGE_READWRITE);\n  _hash = (CIndex *)BigAlloc((size + 1) * sizeof(CIndex));\n  if (_hash == 0)\n  {\n    FreeMemory();\n    return E_OUTOFMEMORY;\n  }\n  \n  // _hash = &m_RightBase[_blockSize];\n  #ifdef HASH_ARRAY_2\n  _hash2 = &_hash[kHashSize]; \n  #ifdef HASH_ARRAY_3\n  _hash3 = &_hash2[kHash2Size]; \n  #endif\n  #endif\n  return S_OK;\n}\n\nstatic const UInt32 kEmptyHashValue = 0;\n\nHRESULT CInTree::Init(ISequentialInStream *stream)\n{\n  RINOK(CLZInWindow::Init(stream));\n  UInt32 i;\n  for(i = 0; i < kHashSize; i++)\n    _hash[i] = kEmptyHashValue;\n\n  #ifdef HASH_ARRAY_2\n  for(i = 0; i < kHash2Size; i++)\n    _hash2[i] = kEmptyHashValue;\n  #ifdef HASH_ARRAY_3\n  for(i = 0; i < kHash3Size; i++)\n    _hash3[i] = kEmptyHashValue;\n  #endif\n  #endif\n\n  _cyclicBufferPos = 0;\n\n  ReduceOffsets(-1);\n  return S_OK;\n}\n\n\n#ifdef HASH_ARRAY_2\n#ifdef HASH_ARRAY_3\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)\n{\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\n  hash2Value = temp & (kHash2Size - 1);\n  hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);\n  return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) & \n      (kHashSize - 1);\n}\n#else // no HASH_ARRAY_3\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)\n{\n  hash2Value = (CCRC::Table[pointer[0]] ^ pointer[1]) & (kHash2Size - 1);\n  return ((UInt32(pointer[0]) << 16)) | ((UInt32(pointer[1]) << 8)) | pointer[2];\n}\n#endif // HASH_ARRAY_3\n#else // no HASH_ARRAY_2\n#ifdef HASH_ZIP \ninline UInt32 Hash(const Byte *pointer)\n{\n  return ((UInt32(pointer[0]) << 8) ^ \n      CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\n}\n#else // no HASH_ZIP \ninline UInt32 Hash(const Byte *pointer)\n{\n  return pointer[0] ^ (UInt32(pointer[1]) << 8);\n}\n#endif // HASH_ZIP\n#endif // HASH_ARRAY_2\n\nUInt32 CInTree::GetLongestMatch(UInt32 *distances)\n{\n  UInt32 lenLimit;\n  if (_pos + _matchMaxLen <= _streamPos)\n    lenLimit = _matchMaxLen;\n  else\n  {\n    lenLimit = _streamPos - _pos;\n    if(lenLimit < kNumHashBytes)\n      return 0; \n  }\n\n  UInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\n  Byte *cur = _buffer + _pos;\n\n  /*\n  if ((_cyclicBufferPos & kBundleMask) == 0)\n  {\n    Byte *bytes = _son[_cyclicBufferPos >> kNumBundleBits].Bytes;\n    UInt32 bundleLimit = kNumBundleBytes;\n    if (bundleLimit > lenLimit)\n      bundleLimit = lenLimit;\n    for (UInt32 i = 0; i < bundleLimit; i++)\n      bytes[i] = cur[i];\n  }\n  */\n  \n  UInt32 matchHashLenMax = 0;\n\n  #ifdef HASH_ARRAY_2\n  UInt32 hash2Value;\n  #ifdef HASH_ARRAY_3\n  UInt32 hash3Value;\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\n  #else\n  UInt32 hashValue = Hash(cur, hash2Value);\n  #endif\n  #else\n  UInt32 hashValue = Hash(cur);\n  #endif\n\n  UInt32 curMatch = _hash[hashValue];\n  #ifdef HASH_ARRAY_2\n  UInt32 curMatch2 = _hash2[hash2Value];\n  #ifdef HASH_ARRAY_3\n  UInt32 curMatch3 = _hash3[hash3Value];\n  #endif\n  _hash2[hash2Value] = _pos;\n  bool matchLen2Exist = false;\n  UInt32 len2Distance = 0;\n  if(curMatch2 >= matchMinPos)\n  {\n    if (_buffer[curMatch2] == cur[0])\n    {\n      len2Distance = _pos - curMatch2 - 1;\n      matchHashLenMax = 2;\n      matchLen2Exist = true;\n    }\n  }\n\n  #ifdef HASH_ARRAY_3\n  _hash3[hash3Value] = _pos;\n  UInt32 matchLen3Exist = false;\n  UInt32 len3Distance = 0;\n  if(curMatch3 >= matchMinPos)\n  {\n    if (_buffer[curMatch3] == cur[0])\n    {\n      len3Distance = _pos - curMatch3 - 1;\n      matchHashLenMax = 3;\n      matchLen3Exist = true;\n      if (matchLen2Exist)\n      {\n        if (len3Distance < len2Distance)\n          len2Distance = len3Distance;\n      }\n      else\n      {\n        len2Distance = len3Distance;\n        matchLen2Exist = true;\n      }\n    }\n  }\n  #endif\n  #endif\n\n  _hash[hashValue] = _pos;\n\n  // UInt32 bi = _cyclicBufferPos >> kNumBundleBits;\n  // UInt32 bo = _cyclicBufferPos & kBundleMask;\n  // CPair &pair = _son[bi].Pairs[bo];\n  CPair &pair = _son[_cyclicBufferPos];\n  if(curMatch < matchMinPos)\n  {\n    pair.Left = kEmptyHashValue; \n    pair.Right = kEmptyHashValue; \n\n    #ifdef HASH_ARRAY_2\n    distances[2] = len2Distance;\n    #ifdef HASH_ARRAY_3\n    distances[3] = len3Distance;\n    #endif\n    #endif\n\n    return matchHashLenMax;\n  }\n  CIndex *ptrLeft = &pair.Right;\n  CIndex *ptrRight = &pair.Left;\n\n  UInt32 maxLen, minLeft, minRight;\n  maxLen = minLeft = minRight = kNumHashDirectBytes;\n\n  #ifdef HASH_ARRAY_2\n  #ifndef HASH_ARRAY_3\n    if (matchLen2Exist)\n      distances[2] = len2Distance;\n    else\n      if (kNumHashDirectBytes >= 2)\n        distances[2] = _pos - curMatch - 1;\n  #endif\n  #endif\n\n  distances[maxLen] = _pos - curMatch - 1;\n  \n  for(UInt32 count = _cutValue; count > 0; count--)\n  {\n    /*\n    UInt32 delta = _pos - curMatch;\n    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\n        (_cyclicBufferPos - delta):\n        (_cyclicBufferPos - delta + _cyclicBufferSize);\n\n    CBundle &bundle = _son[cyclicPos >> kNumBundleBits];\n    UInt32 bo = cyclicPos & kBundleMask;\n    CPair &pair = bundle.Pairs[bo];\n\n    Byte *pby1 = bundle.Bytes + bo;\n    UInt32 bundleLimit = kNumBundleBytes - bo;\n    UInt32 currentLen = minSame;\n    if (bundleLimit > lenLimit)\n      bundleLimit = lenLimit;\n    for(; currentLen < bundleLimit; currentLen++)\n      if (pby1[currentLen] != cur[currentLen])\n        break;\n    if (currentLen >= bundleLimit)\n    {\n      pby1 = _buffer + curMatch;\n      for(; currentLen < lenLimit; currentLen++)\n        if (pby1[currentLen] != cur[currentLen])\n          break;\n    }\n    */\n    Byte *pby1 = _buffer + curMatch;\n    // CIndex left = pair.Left; // it's prefetch\n    UInt32 currentLen = MyMin(minLeft, minRight);\n    for(; currentLen < lenLimit; currentLen++)\n      if (pby1[currentLen] != cur[currentLen])\n        break;\n    UInt32 delta = _pos - curMatch;\n    while (currentLen > maxLen)\n      distances[++maxLen] = delta - 1;\n\n    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\n        (_cyclicBufferPos - delta):\n        (_cyclicBufferPos - delta + _cyclicBufferSize);\n    CPair &pair = _son[cyclicPos];\n    \n    if (currentLen != lenLimit)\n    {\n      if (pby1[currentLen] < cur[currentLen])\n      {\n        *ptrRight = curMatch;\n        ptrRight = &pair.Right;\n        curMatch = pair.Right;\n        if(currentLen > minLeft)\n          minLeft = currentLen;\n      }\n      else\n      {\n        *ptrLeft = curMatch;\n        ptrLeft = &pair.Left;\n        curMatch = pair.Left;\n        if(currentLen > minRight)\n          minRight = currentLen;\n      }\n    }\n    else\n    {\n      if(currentLen < _matchMaxLen)\n      {\n        *ptrLeft = curMatch;\n        ptrLeft = &pair.Left;\n        curMatch = pair.Left;\n        if(currentLen > minRight)\n          minRight = currentLen;\n      }\n      else\n      {\n        *ptrLeft = pair.Right;\n        *ptrRight = pair.Left;\n\n        #ifdef HASH_ARRAY_2\n        if (matchLen2Exist && len2Distance < distances[2])\n          distances[2] = len2Distance;\n        #ifdef HASH_ARRAY_3\n        if (matchLen3Exist && len3Distance < distances[3])\n          distances[3] = len3Distance;\n        #endif\n        #endif\n\n        return maxLen;\n      }\n    }\n    if(curMatch < matchMinPos)\n      break;\n  }\n  *ptrLeft = kEmptyHashValue;\n  *ptrRight = kEmptyHashValue;\n  #ifdef HASH_ARRAY_2\n  if (matchLen2Exist)\n  {\n    if (maxLen < 2)\n    {\n      distances[2] = len2Distance;\n      maxLen = 2;\n    }\n    else if (len2Distance < distances[2])\n      distances[2] = len2Distance;\n  }\n  #ifdef HASH_ARRAY_3\n  if (matchLen3Exist)\n  {\n    if (maxLen < 3)\n    {\n      distances[3] = len3Distance;\n      maxLen = 3;\n    }\n    else if (len3Distance < distances[3])\n      distances[3] = len3Distance;\n  }\n  #endif\n  #endif\n  return maxLen;\n}\n\nvoid CInTree::DummyLongestMatch()\n{\n  UInt32 lenLimit;\n  if (_pos + _matchMaxLen <= _streamPos)\n    lenLimit = _matchMaxLen;\n  else\n  {\n    lenLimit = _streamPos - _pos;\n    if(lenLimit < kNumHashBytes)\n      return; \n  }\n  UInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\n  Byte *cur = _buffer + _pos;\n\n  #ifdef HASH_ARRAY_2\n  UInt32 hash2Value;\n  #ifdef HASH_ARRAY_3\n  UInt32 hash3Value;\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\n  _hash3[hash3Value] = _pos;\n  #else\n  UInt32 hashValue = Hash(cur, hash2Value);\n  #endif\n  _hash2[hash2Value] = _pos;\n  #else\n  UInt32 hashValue = Hash(cur);\n  #endif\n\n  UInt32 curMatch = _hash[hashValue];\n  _hash[hashValue] = _pos;\n\n  CPair &pair = _son[_cyclicBufferPos];\n\n  if(curMatch < matchMinPos)\n  {\n    pair.Left = kEmptyHashValue; \n    pair.Right = kEmptyHashValue; \n    return;\n  }\n  CIndex *ptrLeft = &pair.Right;\n  CIndex *ptrRight = &pair.Left;\n\n  UInt32 maxLen, minLeft, minRight;\n  maxLen = minLeft = minRight = kNumHashDirectBytes;\n  for(UInt32 count = _cutValue; count > 0; count--)\n  {\n    Byte *pby1 = _buffer + curMatch;\n    UInt32 currentLen = MyMin(minLeft, minRight);\n    for(; currentLen < lenLimit; currentLen++)\n      if (pby1[currentLen] != cur[currentLen])\n        break;\n\n    UInt32 delta = _pos - curMatch;\n    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\n        (_cyclicBufferPos - delta):\n        (_cyclicBufferPos - delta + _cyclicBufferSize);\n    CPair &pair = _son[cyclicPos];\n\n    if (currentLen != lenLimit)\n    {\n      if (pby1[currentLen] < cur[currentLen])\n      {\n        *ptrRight = curMatch;\n        ptrRight = &pair.Right;\n        curMatch = pair.Right;\n        if(currentLen > minLeft)\n          minLeft = currentLen;\n      }\n      else \n      {\n        *ptrLeft = curMatch;\n        ptrLeft = &pair.Left;\n        curMatch = pair.Left;\n        if(currentLen > minRight)\n          minRight = currentLen;\n      }\n    }\n    else\n    {\n      if(currentLen < _matchMaxLen)\n      {\n        *ptrLeft = curMatch;\n        ptrLeft = &pair.Left;\n        curMatch = pair.Left;\n        if(currentLen > minRight)\n          minRight = currentLen;\n      }\n      else\n      {\n        *ptrLeft = pair.Right;\n        *ptrRight = pair.Left;\n        return;\n      }\n    }\n    if(curMatch < matchMinPos)\n      break;\n  }\n  *ptrLeft = kEmptyHashValue;\n  *ptrRight = kEmptyHashValue;\n}\n\nvoid CInTree::NormalizeLinks(CIndex *items, UInt32 numItems, UInt32 subValue)\n{\n  for (UInt32 i = 0; i < numItems; i++)\n  {\n    UInt32 value = items[i];\n    if (value <= subValue)\n      value = kEmptyHashValue;\n    else\n      value -= subValue;\n    items[i] = value;\n  }\n}\n\nvoid CInTree::Normalize()\n{\n  UInt32 startItem = _pos - _historySize;\n  UInt32 subValue = startItem - 1;\n  // NormalizeLinks((CIndex *)(_son + startItem), _historySize * 2, subValue);\n  NormalizeLinks((CIndex *)_son, _cyclicBufferSize * 2, subValue);\n  \n  NormalizeLinks(_hash, kHashSize, subValue);\n\n  #ifdef HASH_ARRAY_2\n  NormalizeLinks(_hash2, kHash2Size, subValue);\n  #ifdef HASH_ARRAY_3\n  NormalizeLinks(_hash3, kHash3Size, subValue);\n  #endif\n  #endif\n\n  ReduceOffsets(subValue);\n}\n \n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/HashChain/HC.h",
    "content": "// HC.h\n\n// #ifndef __HC_H\n// #define __HC_H\n\n#include \"../LZInWindow.h\"\n \nnamespace HC_NAMESPACE {\n\ntypedef UInt32 CIndex;\nconst UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\n\n// #define HASH_ARRAY_2\n\n// #ifdef HASH_ARRAY_2\n\n// #define HASH_ARRAY_3\n\n// #else\n\n// #define HASH_ZIP\n\n// #endif\n\nclass CInTree: public CLZInWindow\n{\n  UInt32 _cyclicBufferPos;\n  UInt32 _cyclicBufferSize;\n\n  UInt32 _historySize;\n  UInt32 _matchMaxLen;\n\n  CIndex *_hash;\n  \n  #ifdef HASH_ARRAY_2\n  CIndex *_hash2;\n  #ifdef HASH_ARRAY_3\n  CIndex *_hash3;\n  #endif\n  #endif\n  \n  CIndex *_chain;\n\n  UInt32 _cutValue;\n\n  void NormalizeLinks(CIndex *anArray, UInt32 aNumItems, UInt32 aSubValue);\n  void Normalize();\n  void FreeMemory();\n\npublic:\n  CInTree();\n  ~CInTree();\n  HRESULT Create(UInt32 historySize, UInt32 keepAddBufferBefore, UInt32 matchMaxLen, \n      UInt32 keepAddBufferAfter, UInt32 _sizeReserv = (1<<17));\n\tHRESULT Init(ISequentialInStream *inStream);\n  void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }\n  UInt32 GetLongestMatch(UInt32 *distances);\n  void DummyLongestMatch();\n  HRESULT MovePos()\n  {\n    _cyclicBufferPos++;\n    if (_cyclicBufferPos >= _cyclicBufferSize)\n      _cyclicBufferPos = 0;\n    RINOK(CLZInWindow::MovePos());\n    if (_pos == kMaxValForNormalize)\n      Normalize();\n    return S_OK;\n  }\n};\n\n}\n\n// #endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/HashChain/HC2.h",
    "content": "// HC2.h\n\n#ifndef __HC2__H\n#define __HC2__H\n\n#undef HC_CLSID\n#define HC_CLSID CLSID_CMatchFinderHC2\n\n#undef HC_NAMESPACE\n#define HC_NAMESPACE NHC2\n\n#include \"HCMF.h\"\n#include \"HCMFMain.h\"\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/HashChain/HC3.h",
    "content": "// HC3.h\n\n#ifndef __HC3__H\n#define __HC3__H\n\n#undef HC_CLSID\n#define HC_CLSID CLSID_CMatchFinderHC3\n\n#undef HC_NAMESPACE\n#define HC_NAMESPACE NHC3\n\n#define HASH_ARRAY_2\n\n#include \"HCMF.h\"\n#include \"HCMFMain.h\"\n\n#undef HASH_ARRAY_2\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/HashChain/HC4.h",
    "content": "// HC4.h\n\n#ifndef __HC4__H\n#define __HC4__H\n\n#undef HC_CLSID\n#define HC_CLSID CLSID_CMatchFinderHC4\n\n#undef HC_NAMESPACE\n#define HC_NAMESPACE NHC4\n\n#define HASH_ARRAY_2\n#define HASH_ARRAY_3\n\n#include \"HCMF.h\"\n#include \"HCMFMain.h\"\n\n#undef HASH_ARRAY_2\n#undef HASH_ARRAY_3\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/HashChain/HC4b.h",
    "content": "// HC4b.h\n\n#ifndef __HC4B__H\n#define __HC4B__H\n\n#undef HC_CLSID\n#define HC_CLSID CLSID_CMatchFinderHC4b\n\n#undef HC_NAMESPACE\n#define HC_NAMESPACE NHC4b\n\n#define HASH_ARRAY_2\n#define HASH_ARRAY_3\n#define HASH_BIG\n\n#include \"HCMF.h\"\n#include \"HCMFMain.h\"\n\n#undef HASH_ARRAY_2\n#undef HASH_ARRAY_3\n#undef HASH_BIG\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/HashChain/HCMF.h",
    "content": "// HCMF.h\n\n// #ifndef __HCMF_H\n// #define __HCMF_H\n\n#include \"HC.h\"\n\nnamespace HC_NAMESPACE {\n\n#undef kIDByte\n#undef kIDString\n\n#ifdef HASH_ARRAY_2\n  #ifdef HASH_ARRAY_3\n    #ifdef HASH_BIG\n      #define kIDByte 0x4\n      #define kIDString TEXT(\"4b\")\n    #else\n      #define kIDByte 0x3\n      #define kIDString TEXT(\"4\")\n    #endif\n  #else\n    #define kIDByte 0x2\n    #define kIDString TEXT(\"3\")\n  #endif\n#else\n  #ifdef HASH_ZIP\n    #define kIDByte 0x0\n    #define kIDString TEXT(\"3Z\")\n  #else\n    #define kIDByte 0x1\n    #define kIDString TEXT(\"2\")\n  #endif\n#endif\n\n#undef kIDUse3BytesByte\n#undef kIDUse3BytesString\n\n#define kIDUse3BytesByte 0x00\n#define kIDUse3BytesString TEXT(\"\")\n\n// #undef kIDStringFull\n\n// #define kIDStringFull TEXT(\"Compress.MatchFinderHC\") kIDString kIDUse3BytesString\n\n// {23170F69-40C1-278C-03XX-0000000000}\nDEFINE_GUID(HC_CLSID, \n0x23170F69, 0x40C1, 0x278C, 0x03, kIDByte | kIDUse3BytesByte, \n0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\n\nclass CInTree2: public CInTree\n{\n  CMyComPtr<IMatchFinderCallback> m_Callback;\n  virtual void BeforeMoveBlock();\n  virtual void AfterMoveBlock();\npublic:\n  void SetCallback(IMatchFinderCallback *callback) { m_Callback = callback; }\n};\n\nclass CMatchFinderHC: \n  public IMatchFinder,\n  public IMatchFinderSetCallback,\n  public CMyUnknownImp\n{\n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\n\n  STDMETHOD(Init)(ISequentialInStream *inStream);\n  STDMETHOD_(void, ReleaseStream)();\n  STDMETHOD(MovePos)();\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\n  STDMETHOD_(void, DummyLongestMatch)();\n\n  // IMatchFinderSetCallback\n  STDMETHOD(SetCallback)(IMatchFinderCallback *aCallback);\n\nprivate:\n  // UInt32 m_WindowReservSize;\n  CInTree2 m_MatchFinder;\npublic:\n  // CMatchFinderHC(): m_WindowReservSize((1 << 19) + 256) {};\n  void SetCutValue(UInt32 cutValue) \n    { m_MatchFinder.SetCutValue(cutValue); }\n  /*\n  void SetWindowReservSize(UInt32 aReservWindowSize)\n    { m_WindowReservSize = aReservWindowSize; }\n  */\n  virtual ~CMatchFinderHC() {}\n};\n \n}\n\n// #endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/HashChain/HCMFMain.h",
    "content": "// HCMFMain.h\n\n#include \"HCMain.h\"\n\nnamespace HC_NAMESPACE {\n\nvoid CInTree2::BeforeMoveBlock()\n{\n  if (m_Callback)\n    m_Callback->BeforeChangingBufferPos();\n  CInTree::BeforeMoveBlock();\n}\n\nvoid CInTree2::AfterMoveBlock()\n{\n  if (m_Callback)\n    m_Callback->AfterChangingBufferPos();\n  CInTree::AfterMoveBlock();\n}\n\nSTDMETHODIMP CMatchFinderHC::Init(ISequentialInStream *inStream)\n  { return m_MatchFinder.Init(inStream); }\n\nSTDMETHODIMP_(void) CMatchFinderHC::ReleaseStream()\n{ \n  // m_MatchFinder.ReleaseStream(); \n}\n\nSTDMETHODIMP CMatchFinderHC::MovePos()\n  { return m_MatchFinder.MovePos(); }\n\nSTDMETHODIMP_(Byte) CMatchFinderHC::GetIndexByte(Int32 index)\n  { return m_MatchFinder.GetIndexByte(index); }\n\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetMatchLen(Int32 index, \n    UInt32 back, UInt32 limit)\n  { return m_MatchFinder.GetMatchLen(index, back, limit); }\n\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetNumAvailableBytes()\n  { return m_MatchFinder.GetNumAvailableBytes(); }\n  \nSTDMETHODIMP CMatchFinderHC::Create(UInt32 historySize, \n      UInt32 keepAddBufferBefore, UInt32 matchMaxLen, \n      UInt32 keepAddBufferAfter)\n{ \n  UInt32 windowReservSize = (historySize + keepAddBufferBefore + \n      matchMaxLen + keepAddBufferAfter) / 2 + 256;\n  // try \n  {\n    return m_MatchFinder.Create(historySize, keepAddBufferBefore, matchMaxLen, \n      keepAddBufferAfter, windowReservSize); \n  }\n  /*\n  catch(...)\n  {\n    return E_OUTOFMEMORY;\n  }\n  */\n}\n\nSTDMETHODIMP_(UInt32) CMatchFinderHC::GetLongestMatch(UInt32 *distances)\n  { return m_MatchFinder.GetLongestMatch(distances); }\n\nSTDMETHODIMP_(void) CMatchFinderHC::DummyLongestMatch()\n  { m_MatchFinder.DummyLongestMatch(); }\n\nSTDMETHODIMP_(const Byte *) CMatchFinderHC::GetPointerToCurrentPos()\n{\n  return m_MatchFinder.GetPointerToCurrentPos();\n}\n\n// IMatchFinderSetCallback\nSTDMETHODIMP CMatchFinderHC::SetCallback(IMatchFinderCallback *callback)\n{\n  m_MatchFinder.SetCallback(callback);\n  return S_OK;\n}\n\n\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/HashChain/HCMain.h",
    "content": "// HC.h\n\n#include \"../../../../Common/Defs.h\"\n#include \"../../../../Common/CRC.h\"\n#include \"../../../../Common/Alloc.h\"\n\nnamespace HC_NAMESPACE {\n\n#ifdef HASH_ARRAY_2\n  static const UInt32 kHash2Size = 1 << 10;\n  #ifdef HASH_ARRAY_3\n    static const UInt32 kNumHashDirectBytes = 0;\n    static const UInt32 kNumHashBytes = 4;\n    static const UInt32 kHash3Size = 1 << 18;\n    #ifdef HASH_BIG\n    static const UInt32 kHashSize = 1 << 23;\n    #else\n    static const UInt32 kHashSize = 1 << 20;\n    #endif\n  #else\n    static const UInt32 kNumHashBytes = 3;\n    // static const UInt32 kNumHashDirectBytes = 3;\n    // static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\n    static const UInt32 kNumHashDirectBytes = 0;\n    static const UInt32 kHashSize = 1 << (16);\n  #endif\n#else\n  #ifdef HASH_ZIP \n    static const UInt32 kNumHashDirectBytes = 0;\n    static const UInt32 kNumHashBytes = 3;\n    static const UInt32 kHashSize = 1 << 16;\n  #else\n    static const UInt32 kNumHashDirectBytes = 2;\n    static const UInt32 kNumHashBytes = 2;\n    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\n  #endif\n#endif\n\n\nCInTree::CInTree():\n  _hash(0),\n  #ifdef HASH_ARRAY_2\n  _hash2(0),\n  #ifdef HASH_ARRAY_3\n  _hash3(0),\n  #endif\n  #endif\n  _chain(0),\n  _cutValue(16)\n{\n}\n\nvoid CInTree::FreeMemory()\n{\n  BigFree(_chain);\n  _chain = 0;\n  BigFree(_hash);\n  _hash = 0;\n  CLZInWindow::Free();\n}\n\nCInTree::~CInTree()\n{ \n  FreeMemory();\n}\n\nHRESULT CInTree::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, UInt32 sizeReserv)\n{\n  FreeMemory();\n  if (!CLZInWindow::Create(historySize + keepAddBufferBefore, \n      matchMaxLen + keepAddBufferAfter, sizeReserv))\n    return E_OUTOFMEMORY;\n\n  \n  if (_blockSize + 256 > kMaxValForNormalize)\n    return E_INVALIDARG;\n  \n  _historySize = historySize;\n  _matchMaxLen = matchMaxLen;\n  _cyclicBufferSize = historySize + 1;\n  \n  \n  UInt32 size = kHashSize;\n  #ifdef HASH_ARRAY_2\n  size += kHash2Size;\n  #ifdef HASH_ARRAY_3\n  size += kHash3Size;\n  #endif\n  #endif\n  \n  _chain = (CIndex *)::BigAlloc((_cyclicBufferSize + 1) * sizeof(CIndex));\n  if (_chain == 0)\n  {\n    FreeMemory();\n    return E_OUTOFMEMORY;\n  }\n  _hash = (CIndex *)::BigAlloc((size + 1) * sizeof(CIndex));\n  if (_hash == 0)\n  {\n    FreeMemory();\n    return E_OUTOFMEMORY;\n  }\n  \n  // m_RightBase = &m_LeftBase[_blockSize];\n  \n  // _hash = &m_RightBase[_blockSize];\n  #ifdef HASH_ARRAY_2\n  _hash2 = &_hash[kHashSize]; \n  #ifdef HASH_ARRAY_3\n  _hash3 = &_hash2[kHash2Size]; \n  #endif\n  #endif\n  return S_OK;\n}\n\nstatic const UInt32 kEmptyHashValue = 0;\n\nHRESULT CInTree::Init(ISequentialInStream *aStream)\n{\n  RINOK(CLZInWindow::Init(aStream));\n  UInt32 i;\n  for(i = 0; i < kHashSize; i++)\n    _hash[i] = kEmptyHashValue;\n\n  #ifdef HASH_ARRAY_2\n  for(i = 0; i < kHash2Size; i++)\n    _hash2[i] = kEmptyHashValue;\n  #ifdef HASH_ARRAY_3\n  for(i = 0; i < kHash3Size; i++)\n    _hash3[i] = kEmptyHashValue;\n  #endif\n  #endif\n\n  _cyclicBufferPos = 0;\n\n  ReduceOffsets(-1);\n  return S_OK;\n}\n\n\n#ifdef HASH_ARRAY_2\n#ifdef HASH_ARRAY_3\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)\n{\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\n  hash2Value = temp & (kHash2Size - 1);\n  hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);\n  return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) & \n      (kHashSize - 1);\n}\n#else // no HASH_ARRAY_3\ninline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)\n{\n  UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];\n  hash2Value = temp & (kHash2Size - 1);\n  return (temp ^ (UInt32(pointer[2]) << 8)) & (kHashSize - 1);;\n}\n#endif // HASH_ARRAY_3\n#else // no HASH_ARRAY_2\n#ifdef HASH_ZIP \ninline UInt32 Hash(const Byte *pointer)\n{\n  return ((UInt32(pointer[0]) << 8) ^ \n      CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\n}\n#else // no HASH_ZIP \ninline UInt32 Hash(const Byte *pointer)\n{\n  return pointer[0] ^ (UInt32(pointer[1]) << 8);\n}\n#endif // HASH_ZIP\n#endif // HASH_ARRAY_2\n\n\nUInt32 CInTree::GetLongestMatch(UInt32 *distances)\n{\n  UInt32 lenLimit;\n  if (_pos + _matchMaxLen <= _streamPos)\n    lenLimit = _matchMaxLen;\n  else\n  {\n    lenLimit = _streamPos - _pos;\n    if(lenLimit < kNumHashBytes)\n      return 0; \n  }\n\n  UInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\n  Byte *cur = _buffer + _pos;\n  \n  UInt32 matchHashLenMax = 0;\n\n  #ifdef HASH_ARRAY_2\n \n  UInt32 hash2Value;\n  \n  #ifdef HASH_ARRAY_3\n  \n  UInt32 hash3Value;\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\n  \n  #else // no HASH_ARRAY_3\n  \n  UInt32 hashValue = Hash(cur, hash2Value);\n  \n  #endif // HASH_ARRAY_3\n  \n  #else // no HASH_ARRAY_2\n  \n  UInt32 hashValue = Hash(cur);\n\n  #endif\n\n  #ifdef HASH_ARRAY_2\n\n  UInt32 curMatch2 = _hash2[hash2Value];\n  _hash2[hash2Value] = _pos;\n  bool matchLen2Exist = false;\n  UInt32 len2Distance = 0;\n  if(curMatch2 >= matchMinPos)\n  {\n    if (_buffer[curMatch2] == cur[0])\n    {\n      len2Distance = _pos - curMatch2 - 1;\n      matchHashLenMax = 2;\n      matchLen2Exist = true;\n    }\n  }\n\n  #ifdef HASH_ARRAY_3\n  \n  UInt32 curMatch3 = _hash3[hash3Value];\n  _hash3[hash3Value] = _pos;\n  UInt32 matchLen3Exist = false;\n  UInt32 len3Distance = 0;\n  if(curMatch3 >= matchMinPos)\n  {\n    if (_buffer[curMatch3] == cur[0])\n    {\n      len3Distance = _pos - curMatch3 - 1;\n      matchHashLenMax = 3;\n      matchLen3Exist = true;\n      if (matchLen2Exist)\n      {\n        if (len3Distance < len2Distance)\n          len2Distance = len3Distance;\n      }\n      else\n      {\n        len2Distance = len3Distance;\n        matchLen2Exist = true;\n      }\n    }\n  }\n  \n  #endif\n  #endif\n\n  UInt32 curMatch = _hash[hashValue];\n  _hash[hashValue] = _pos;\n  if(curMatch < matchMinPos)\n  {\n    _chain[_cyclicBufferPos] = kEmptyHashValue; \n\n    #ifdef HASH_ARRAY_2\n    distances[2] = len2Distance;\n    #ifdef HASH_ARRAY_3\n    distances[3] = len3Distance;\n    #endif\n    #endif\n\n    return matchHashLenMax;\n  }\n  _chain[_cyclicBufferPos] = curMatch;\n\n \n  #ifdef HASH_ARRAY_2\n  #ifndef HASH_ARRAY_3\n    if (matchLen2Exist)\n      distances[2] = len2Distance;\n    else\n      if (kNumHashDirectBytes >= 2)\n        distances[2] = _pos - curMatch - 1;\n  #endif\n  #endif\n\n  UInt32 maxLen, minSame;\n  \n  maxLen = minSame = kNumHashDirectBytes;\n\n  distances[maxLen] = _pos - curMatch - 1;\n  \n  for(UInt32 aCount = _cutValue; aCount > 0; aCount--)\n  {\n    Byte *pby1 = _buffer + curMatch;\n    UInt32 currentLen;\n    for(currentLen = minSame; currentLen < lenLimit; currentLen++/*, dwComps++*/)\n      if (pby1[currentLen] != cur[currentLen])\n        break;\n    if (currentLen > maxLen)\n    {\n      UInt32 back =  _pos - curMatch - 1;\n      for(UInt32 len = maxLen + 1; len <= currentLen; len++)\n        distances[len] = back;\n      maxLen = currentLen;\n    }\n    if(currentLen == lenLimit)\n      break;\n\n    UInt32 delta = _pos - curMatch;\n    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\n        (_cyclicBufferPos - delta):\n        (_cyclicBufferPos - delta + _cyclicBufferSize);\n\n    curMatch = _chain[cyclicPos];\n    if(curMatch < matchMinPos)\n      break;\n  }\n  #ifdef HASH_ARRAY_2\n  if (matchLen2Exist)\n  {\n    if (maxLen < 2)\n    {\n      distances[2] = len2Distance;\n      maxLen = 2;\n    }\n    else if (len2Distance < distances[2])\n      distances[2] = len2Distance;\n  }\n  #ifdef HASH_ARRAY_3\n  if (matchLen3Exist)\n  {\n    if (maxLen < 3)\n    {\n      distances[3] = len3Distance;\n      maxLen = 3;\n    }\n    else if (len3Distance < distances[3])\n      distances[3] = len3Distance;\n  }\n  #endif\n  #endif\n  return maxLen;\n}\n\nvoid CInTree::DummyLongestMatch()\n{\n  UInt32 lenLimit;\n  if (_pos + _matchMaxLen <= _streamPos)\n    lenLimit = _matchMaxLen;\n  else\n  {\n    lenLimit = _streamPos - _pos;\n    if(lenLimit < kNumHashBytes)\n      return; \n  }\n  UInt32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;\n  Byte *cur = _buffer + _pos;\n  \n\n  #ifdef HASH_ARRAY_2\n  UInt32 hash2Value;\n  #ifdef HASH_ARRAY_3\n  UInt32 hash3Value;\n  UInt32 hashValue = Hash(cur, hash2Value, hash3Value);\n  _hash3[hash3Value] = _pos;\n  #else\n  UInt32 hashValue = Hash(cur, hash2Value);\n  #endif\n  _hash2[hash2Value] = _pos;\n\n  \n  #else // no hash\n  UInt32 hashValue = Hash(cur);\n  #endif\n\n  UInt32 curMatch = _hash[hashValue];\n  _hash[hashValue] = _pos;\n  if(curMatch < matchMinPos)\n  {\n    _chain[_cyclicBufferPos] = kEmptyHashValue; \n    return;\n  }\n  _chain[_cyclicBufferPos] = curMatch;\n}\n\nvoid CInTree::NormalizeLinks(CIndex *items, UInt32 numItems, UInt32 subValue)\n{\n  for (UInt32 i = 0; i < numItems; i++)\n  {\n    UInt32 value = items[i];\n    if (value <= subValue)\n      value = kEmptyHashValue;\n    else\n      value -= subValue;\n    items[i] = value;\n  }\n}\n\nvoid CInTree::Normalize()\n{\n  UInt32 startItem = _pos - _historySize;\n  UInt32 subValue = startItem - 1;\n  \n  // NormalizeLinks(_chain + startItem, _historySize, subValue);\n  NormalizeLinks(_chain, _cyclicBufferSize, subValue);\n\n  NormalizeLinks(_hash, kHashSize, subValue);\n\n  #ifdef HASH_ARRAY_2\n  NormalizeLinks(_hash2, kHash2Size, subValue);\n  #ifdef HASH_ARRAY_3\n  NormalizeLinks(_hash3, kHash3Size, subValue);\n  #endif\n  #endif\n\n  ReduceOffsets(subValue);\n}\n \n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/IMatchFinder.h",
    "content": "// MatchFinders/IMatchFinder.h\n\n#ifndef __IMATCHFINDER_H\n#define __IMATCHFINDER_H\n\n// {23170F69-40C1-278A-0000-000200010000}\nDEFINE_GUID(IID_IInWindowStream, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200010000\")\nIInWindowStream: public IUnknown\n{\n  STDMETHOD(Init)(ISequentialInStream *inStream) PURE;\n  STDMETHOD_(void, ReleaseStream)() PURE;\n  STDMETHOD(MovePos)() PURE;\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;\n  STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;\n};\n \n// {23170F69-40C1-278A-0000-000200020000}\nDEFINE_GUID(IID_IMatchFinder, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020000\")\nIMatchFinder: public IInWindowStream\n{\n  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \n      UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances) PURE;\n  STDMETHOD_(void, DummyLongestMatch)() PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200020100}\nDEFINE_GUID(IID_IMatchFinderCallback, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x01, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020100\")\nIMatchFinderCallback: public IUnknown\n{\n  STDMETHOD(BeforeChangingBufferPos)() PURE;\n  STDMETHOD(AfterChangingBufferPos)() PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200020200}\nDEFINE_GUID(IID_IMatchFinderSetCallback, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200020200\")\nIMatchFinderSetCallback: public IUnknown\n{\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback) PURE;\n};\n\n/*\n// {23170F69-40C1-278A-0000-000200030000}\nDEFINE_GUID(IID_IInitMatchFinder, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200030000\")\nIMatchFinderInit: public IUnknown\n{\n  STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder) PURE;\n};\n*/\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/LZInWindow.cpp",
    "content": "// LZInWindow.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LZInWindow.h\"\n#include \"../../../Common/MyCom.h\"\n#include \"../../../Common/Alloc.h\"\n\nvoid CLZInWindow::Free()\n{\n  ::BigFree(_bufferBase);\n  _bufferBase = 0;\n}\n\nbool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)\n{\n  _keepSizeBefore = keepSizeBefore;\n  _keepSizeAfter = keepSizeAfter;\n  _keepSizeReserv = keepSizeReserv;\n  UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;\n  if (_bufferBase == 0 || _blockSize != blockSize)\n  {\n    Free();\n    _blockSize = blockSize;\n    _bufferBase = (Byte *)::BigAlloc(_blockSize);\n  }\n  _pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;\n  return (_bufferBase != 0);\n}\n\n\nHRESULT CLZInWindow::Init(ISequentialInStream *stream)\n{\n  _stream = stream;\n  _buffer = _bufferBase;\n  _pos = 0;\n  _streamPos = 0;\n  _streamEndWasReached = false;\n  return ReadBlock();\n}\n\n/*\nvoid CLZInWindow::ReleaseStream()\n{\n  _stream.Release();\n}\n*/\n\n///////////////////////////////////////////\n// ReadBlock\n\n// In State:\n//   (_buffer + _streamPos) <= (_bufferBase + _blockSize)\n// Out State:\n//   _posLimit <= _blockSize - _keepSizeAfter;\n//   if(_streamEndWasReached == false):\n//     _streamPos >= _pos + _keepSizeAfter\n//     _posLimit = _streamPos - _keepSizeAfter;\n//   else\n//          \n  \nHRESULT CLZInWindow::ReadBlock()\n{\n  if(_streamEndWasReached)\n    return S_OK;\n  while(true)\n  {\n    UInt32 size = UInt32(_bufferBase - _buffer) + _blockSize - _streamPos;\n    if(size == 0)\n      return S_OK;\n    UInt32 numReadBytes;\n    RINOK(_stream->ReadPart(_buffer + _streamPos, size, &numReadBytes));\n    if(numReadBytes == 0)\n    {\n      _posLimit = _streamPos;\n      const Byte *pointerToPostion = _buffer + _posLimit;\n      if(pointerToPostion > _pointerToLastSafePosition)\n        _posLimit = (UInt32)(_pointerToLastSafePosition - _buffer);\n      _streamEndWasReached = true;\n      return S_OK;\n    }\n    _streamPos += numReadBytes;\n    if(_streamPos >= _pos + _keepSizeAfter)\n    {\n      _posLimit = _streamPos - _keepSizeAfter;\n      return S_OK;\n    }\n  }\n}\n\nvoid CLZInWindow::MoveBlock()\n{\n  BeforeMoveBlock();\n  UInt32 offset = UInt32(_buffer - _bufferBase) + _pos - _keepSizeBefore;\n  UInt32 numBytes = UInt32(_buffer - _bufferBase) + _streamPos -  offset;\n  memmove(_bufferBase, _bufferBase + offset, numBytes);\n  _buffer -= offset;\n  AfterMoveBlock();\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/LZInWindow.h",
    "content": "// LZInWindow.h\n\n#ifndef __LZ_IN_WINDOW_H\n#define __LZ_IN_WINDOW_H\n\n#include \"../../IStream.h\"\n\nclass CLZInWindow\n{\n  Byte *_bufferBase; // pointer to buffer with data\n  ISequentialInStream *_stream;\n  UInt32 _posLimit;  // offset (from _buffer) of first byte when new block reading must be done\n  bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\n  const Byte *_pointerToLastSafePosition;\nprotected:\n  Byte  *_buffer;   // Pointer to virtual Buffer begin\n  UInt32 _blockSize;  // Size of Allocated memory block\n  UInt32 _pos;             // offset (from _buffer) of curent byte\n  UInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\n  UInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\n  UInt32 _keepSizeReserv;  // how many BYTEs must be kept as reserv\n  UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream\n\n  virtual void BeforeMoveBlock() {};\n  virtual void AfterMoveBlock() {};\n  void MoveBlock();\n  virtual HRESULT ReadBlock();\n  void Free();\npublic:\n  CLZInWindow(): _bufferBase(0) {}\n  virtual ~CLZInWindow() { Free(); }\n\n  bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, \n      UInt32 keepSizeReserv = (1<<17));\n\n  HRESULT Init(ISequentialInStream *stream);\n  // void ReleaseStream();\n\n  Byte *GetBuffer() const { return _buffer; }\n\n  const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }\n\n  HRESULT MovePos()\n  {\n    _pos++;\n    if (_pos > _posLimit)\n    {\n      const Byte *pointerToPostion = _buffer + _pos;\n      if(pointerToPostion > _pointerToLastSafePosition)\n        MoveBlock();\n      return ReadBlock();\n    }\n    else\n      return S_OK;\n  }\n  Byte GetIndexByte(Int32 index)const\n    {  return _buffer[(size_t)_pos + index]; }\n\n  // index + limit have not to exceed _keepSizeAfter;\n  UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const\n  {  \n    if(_streamEndWasReached)\n      if ((_pos + index) + limit > _streamPos)\n        limit = _streamPos - (_pos + index);\n    distance++;\n    Byte *pby = _buffer + (size_t)_pos + index;\n    UInt32 i;\n    for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);\n    return i;\n  }\n\n  UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }\n\n  void ReduceOffsets(Int32 subValue)\n  {\n    _buffer += subValue;\n    _posLimit -= subValue;\n    _pos -= subValue;\n    _streamPos -= subValue;\n  }\n\n};\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/LZOutWindow.cpp",
    "content": "// LZOutWindow.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../../Common/Alloc.h\"\n#include \"LZOutWindow.h\"\n\nbool CLZOutWindow::Create(UInt32 windowSize)\n{\n  const UInt32 kMinBlockSize = 1;\n  if (windowSize < kMinBlockSize)\n    windowSize = kMinBlockSize;\n  if (_buffer != 0 && _windowSize == windowSize)\n    return true;\n\n  // It's here to allow Solid decoding / and calling Create for RAR\n  _pos = 0;\n  _streamPos = 0;\n  \n  Free();\n  _windowSize = windowSize;\n  _buffer = (Byte *)::BigAlloc(windowSize);\n  return (_buffer != 0);\n}\n\nvoid CLZOutWindow::Free()\n{\n  ::BigFree(_buffer);\n  _buffer = 0;\n}\n\nvoid CLZOutWindow::SetStream(ISequentialOutStream *stream)\n{\n  ReleaseStream();\n  _stream = stream;\n  _stream->AddRef();\n}\n\nvoid CLZOutWindow::Init(bool solid)\n{\n  if(!solid)\n  {\n    _streamPos = 0;\n    _pos = 0;\n  }\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = S_OK;\n  #endif\n}\n\nvoid CLZOutWindow::ReleaseStream()\n{\n  if(_stream != 0)\n  {\n    // Flush(); // Test it\n    _stream->Release();\n    _stream = 0;\n  }\n}\n\nvoid CLZOutWindow::FlushWithCheck()\n{\n  HRESULT result = Flush();\n  #ifdef _NO_EXCEPTIONS\n  ErrorCode = result;\n  #else\n  if (result != S_OK)\n    throw CLZOutWindowException(result);\n  #endif\n}\n\nHRESULT CLZOutWindow::Flush()\n{\n  UInt32 size = _pos - _streamPos;\n  if(size == 0)\n    return S_OK;\n  #ifdef _NO_EXCEPTIONS\n  if (ErrorCode != S_OK)\n    return ErrorCode;\n  #endif\n\n  if(_stream != 0)\n  {\n    UInt32 processedSize;\n    HRESULT result = _stream->Write(_buffer + _streamPos, size, &processedSize);\n    if (result != S_OK)\n      return result;\n    if (size != processedSize)\n      return E_FAIL;\n  }\n  if (_pos >= _windowSize)\n    _pos = 0;\n  _streamPos = _pos;\n  return S_OK;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/LZOutWindow.h",
    "content": "// LZOutWindow.h\n\n#ifndef __LZ_OUT_WINDOW_H\n#define __LZ_OUT_WINDOW_H\n\n#include \"../../IStream.h\"\n\n#ifndef _NO_EXCEPTIONS\nclass CLZOutWindowException\n{\npublic:\n  HRESULT ErrorCode;\n  CLZOutWindowException(HRESULT errorCode): ErrorCode(errorCode) {}\n};\n#endif\n\nclass CLZOutWindow\n{\n  Byte  *_buffer;\n  UInt32 _pos;\n  UInt32 _windowSize;\n  UInt32 _streamPos;\n  ISequentialOutStream *_stream;\n  void FlushWithCheck();\npublic:\n  #ifdef _NO_EXCEPTIONS\n  HRESULT ErrorCode;\n  #endif\n\n  void Free();\n  CLZOutWindow(): _buffer(0), _stream(0) {}\n  ~CLZOutWindow() { Free();  /* ReleaseStream(); */ }\n  bool Create(UInt32 windowSize);\n  \n  void SetStream(ISequentialOutStream *stream);\n  void Init(bool solid = false);\n  HRESULT Flush();\n  void ReleaseStream();\n  \n  void CopyBlock(UInt32 distance, UInt32 len)\n  {\n    UInt32 pos = _pos - distance - 1;\n    if (pos >= _windowSize)\n      pos += _windowSize;\n    for(; len > 0; len--)\n    {\n      if (pos >= _windowSize)\n        pos = 0;\n      _buffer[_pos++] = _buffer[pos++];\n      if (_pos >= _windowSize)\n        FlushWithCheck();  \n      // PutOneByte(GetOneByte(distance));\n    }\n  }\n  \n  void PutByte(Byte b)\n  {\n    _buffer[_pos++] = b;\n    if (_pos >= _windowSize)\n      FlushWithCheck();  \n  }\n  \n  Byte GetByte(UInt32 distance) const\n  {\n    UInt32 pos = _pos - distance - 1;\n    if (pos >= _windowSize)\n      pos += _windowSize;\n    return _buffer[pos]; \n  }\n};\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/Makefile",
    "content": "RGSRC=../../../../../..\ninclude $(RGSRC)/envir.mak\n\nOBJS=LZInWindow.o LZOutWindow.o\n\ninclude $(LZMAMK)\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/Patricia/Pat.h",
    "content": "// Pat.h\n\n// #ifndef __PATRICIA__H\n// #define __PATRICIA__H\n\n#include \"../../../../Common/MyCom.h\"\n#include \"../../../../Common/Types.h\"\n#include \"../LZInWindow.h\"\n\nnamespace PAT_NAMESPACE {\n\nstruct CNode;\n\ntypedef CNode *CNodePointer;\n\n// #define __AUTO_REMOVE\n\n// #define __NODE_4_BITS\n// #define __NODE_3_BITS\n// #define __NODE_2_BITS\n// #define __NODE_2_BITS_PADDING\n\n// #define __HASH_3\n\n\ntypedef UInt32 CIndex;\n\n#ifdef __NODE_4_BITS\n  typedef UInt32 CIndex2;\n  typedef UInt32 CSameBitsType;\n#else\n#ifdef __NODE_3_BITS\n  typedef UInt32 CIndex2;\n  typedef UInt32 CSameBitsType;\n#else\n\n  typedef UInt32 CIndex;\n  typedef UInt32 CSameBitsType;\n\n  typedef CIndex CIndex2;\n#endif\n#endif\n\nconst UInt32 kNumBitsInIndex = sizeof(CIndex) * 8;\nconst UInt32 kMatchStartValue = UInt32(1) << (kNumBitsInIndex - 1);\n// don't change kMatchStartValue definition, since it is used in \n// PatMain.h: \n\ntypedef CIndex CMatchPointer;\n\nconst UInt32 kDescendantEmptyValue = kMatchStartValue - 1;\n\nunion CDescendant \n{\n  CIndex NodePointer;\n  CMatchPointer MatchPointer;\n  bool IsEmpty() const { return NodePointer == kDescendantEmptyValue; }\n  bool IsNode() const { return NodePointer < kDescendantEmptyValue; }\n  bool IsMatch() const { return NodePointer > kDescendantEmptyValue; }\n  void MakeEmpty() { NodePointer = kDescendantEmptyValue; }\n};\n\n#undef MY_BYTE_SIZE\n\n#ifdef __NODE_4_BITS\n  #define MY_BYTE_SIZE 8\n  const UInt32 kNumSubBits = 4;\n#else\n#ifdef __NODE_3_BITS\n  #define MY_BYTE_SIZE 9\n  const UInt32 kNumSubBits = 3;\n#else\n  #define MY_BYTE_SIZE 8\n  #ifdef __NODE_2_BITS\n    const UInt32 kNumSubBits = 2;\n  #else\n    const UInt32 kNumSubBits = 1;\n  #endif\n#endif\n#endif\n\nconst UInt32 kNumSubNodes = 1 << kNumSubBits;\nconst UInt32 kSubNodesMask = kNumSubNodes - 1;\n\nstruct CNode\n{\n  CIndex2 LastMatch;\n  CSameBitsType NumSameBits;\n  union\n  {\n    CDescendant  Descendants[kNumSubNodes];\n    UInt32 NextFreeNode;\n  };\n  #ifdef __NODE_2_BITS\n  #ifdef __NODE_2_BITS_PADDING\n  UInt32 Padding[2];\n  #endif\n  #endif\n};\n\n#undef kIDNumBitsByte\n#undef kIDNumBitsString\n\n#ifdef __NODE_4_BITS\n  #define kIDNumBitsByte 0x30\n  #define kIDNumBitsString TEXT(\"4\")\n#else\n#ifdef __NODE_3_BITS\n  #define kIDNumBitsByte 0x20\n  #define kIDNumBitsString TEXT(\"3\")\n#else\n#ifdef __NODE_2_BITS\n  #define kIDNumBitsByte 0x10\n  #define kIDNumBitsString TEXT(\"2\")\n#else\n  #define kIDNumBitsByte 0x00\n  #define kIDNumBitsString TEXT(\"1\")\n#endif\n#endif\n#endif\n\n#undef kIDManualRemoveByte\n#undef kIDManualRemoveString\n\n#ifdef __AUTO_REMOVE\n  #define kIDManualRemoveByte 0x00\n  #define kIDManualRemoveString TEXT(\"\")\n#else\n  #define kIDManualRemoveByte 0x08\n  #define kIDManualRemoveString TEXT(\"R\")\n#endif\n\n#undef kIDHash3Byte\n#undef kIDHash3String\n\n#ifdef __HASH_3\n  #define kIDHash3Byte 0x04\n  #define kIDHash3String TEXT(\"H\")\n#else\n  #define kIDHash3Byte 0x00\n  #define kIDHash3String TEXT(\"\")\n#endif\n\n#undef kIDUse3BytesByte\n#undef kIDUse3BytesString\n\n#define kIDUse3BytesByte 0x00\n#define kIDUse3BytesString TEXT(\"\")\n\n#undef kIDPaddingByte\n#undef kIDPaddingString\n\n#ifdef __NODE_2_BITS_PADDING\n  #define kIDPaddingByte 0x01\n  #define kIDPaddingString TEXT(\"P\")\n#else\n  #define kIDPaddingByte 0x00\n  #define kIDPaddingString TEXT(\"\")\n#endif\n\n\n// #undef kIDString\n// #define kIDString TEXT(\"Compress.MatchFinderPat\") kIDNumBitsString kIDManualRemoveString kIDUse3BytesString kIDPaddingString kIDHash3String\n\n// {23170F69-40C1-278C-01XX-0000000000}\n\nDEFINE_GUID(PAT_CLSID, \n0x23170F69, 0x40C1, 0x278C, 0x01, \nkIDNumBitsByte | \nkIDManualRemoveByte | kIDHash3Byte | kIDUse3BytesByte | kIDPaddingByte, \n0x00, 0x00, 0x00, 0x00, 0x00, 0x00);\n\n// III(PAT_NAMESPACE)\n\nclass CPatricia: \n  public IMatchFinder,\n  public IMatchFinderSetCallback,\n  public CMyUnknownImp,\n  CLZInWindow\n{ \n  MY_UNKNOWN_IMP1(IMatchFinderSetCallback)\n\n  STDMETHOD(Init)(ISequentialInStream *aStream);\n  STDMETHOD_(void, ReleaseStream)();\n  STDMETHOD(MovePos)();\n  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\n  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\n  STDMETHOD_(UInt32, GetNumAvailableBytes)();\n  STDMETHOD(Create)(UInt32 historySize, \n      UInt32 keepAddBufferBefore, UInt32 matchMaxLen, \n      UInt32 keepAddBufferAfter);\n  STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);\n  STDMETHOD_(void, DummyLongestMatch)();\n  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\n\n  void FreeMemory();\npublic:\n  CPatricia();\n  ~CPatricia();\n\n  UInt32 _sizeHistory;\n  UInt32 _matchMaxLen;\n\n  CDescendant *m_HashDescendants;\n  #ifdef __HASH_3\n  CDescendant *m_Hash2Descendants;\n  #endif\n\n  CNode *m_Nodes;\n\n  UInt32 m_FreeNode;\n  UInt32 m_FreeNodeMax;\n\n  #ifdef __AUTO_REMOVE\n  UInt32 m_NumUsedNodes;\n  UInt32 m_NumNodes;\n  #else\n  bool  m_SpecialRemoveMode;\n  #endif\n\n  bool  m_SpecialMode;\n  UInt32 m_NumNotChangedCycles;\n  UInt32 *m_TmpBacks;\n\n  CMyComPtr<IMatchFinderCallback> m_Callback;\n\n  virtual void BeforeMoveBlock();\n  virtual void AfterMoveBlock();\n\n  // IMatchFinderSetCallback\n  STDMETHOD(SetCallback)(IMatchFinderCallback *callback);\n\n  void ChangeLastMatch(UInt32 hashValue);\n  \n  #ifdef __AUTO_REMOVE\n  void TestRemoveDescendant(CDescendant &descendant, UInt32 limitPos);\n  void TestRemoveNodes();\n  void RemoveNode(UInt32 index);\n  void TestRemoveAndNormalizeDescendant(CDescendant &descendant, \n      UInt32 limitPos, UInt32 subValue);\n  void TestRemoveNodesAndNormalize();\n  #else\n  void NormalizeDescendant(CDescendant &descendant, UInt32 subValue);\n  void Normalize();\n  void RemoveMatch();\n  #endif\nprivate:\n  void AddInternalNode(CNodePointer aNode, CIndex *aNodePointerPointer, \n      Byte aByte, Byte aByteXOR, UInt32 aNumSameBits, UInt32 aPos)\n  {\n    while((aByteXOR & kSubNodesMask) == 0)\n    {\n      aByteXOR >>= kNumSubBits;\n      aByte >>= kNumSubBits;\n      aNumSameBits -= kNumSubBits;\n    }\n    // Insert New Node\n    CNodePointer aNewNode = &m_Nodes[m_FreeNode];\n    UInt32 aNodeIndex = *aNodePointerPointer;\n    *aNodePointerPointer = m_FreeNode;\n    m_FreeNode = aNewNode->NextFreeNode;\n    #ifdef __AUTO_REMOVE\n    m_NumUsedNodes++;\n    #endif\n    if (m_FreeNode > m_FreeNodeMax)\n    {\n      m_FreeNodeMax = m_FreeNode;\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\n    }\n\n    UInt32 aBitsNew = aByte & kSubNodesMask;\n    UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\n      aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;\n    aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;\n    aNewNode->Descendants[aBitsOld].NodePointer = aNodeIndex;\n    aNewNode->NumSameBits = CSameBitsType(aNode->NumSameBits - aNumSameBits);\n    aNewNode->LastMatch = aPos;\n    \n    aNode->NumSameBits = CSameBitsType(aNumSameBits - kNumSubBits);\n  }\n\n  void AddLeafNode(CNodePointer aNode, Byte aByte, Byte aByteXOR, \n      UInt32 aNumSameBits, UInt32 aPos, UInt32 aDescendantIndex)\n  {\n    for(;(aByteXOR & kSubNodesMask) == 0; aNumSameBits += kNumSubBits)\n    {\n      aByte >>= kNumSubBits;\n      aByteXOR >>= kNumSubBits;\n    }\n    UInt32 aNewNodeIndex = m_FreeNode;\n    CNodePointer aNewNode = &m_Nodes[m_FreeNode];\n    m_FreeNode = aNewNode->NextFreeNode;\n    #ifdef __AUTO_REMOVE\n    m_NumUsedNodes++;\n    #endif\n    if (m_FreeNode > m_FreeNodeMax)\n    {\n      m_FreeNodeMax = m_FreeNode;\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\n    }\n\n    UInt32 aBitsNew = (aByte & kSubNodesMask);\n    UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\n      aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;\n    aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;\n    aNewNode->Descendants[aBitsOld].MatchPointer = \n      aNode->Descendants[aDescendantIndex].MatchPointer;\n    aNewNode->NumSameBits = CSameBitsType(aNumSameBits);\n    aNewNode->LastMatch = aPos;\n    aNode->Descendants[aDescendantIndex].NodePointer = aNewNodeIndex;\n  }\n};\n\n}\n\n// #endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/Patricia/Pat2.h",
    "content": "// Pat2.h\n\n#ifndef __PAT2__H\n#define __PAT2__H\n\n#undef PAT_CLSID\n#define PAT_CLSID CLSID_CMatchFinderPat2\n\n#undef PAT_NAMESPACE\n#define PAT_NAMESPACE NPat2\n\n#define __AUTO_REMOVE\n#define __NODE_2_BITS\n\n#include \"Pat.h\"\n#include \"PatMain.h\"\n\n#undef __AUTO_REMOVE\n#undef  __NODE_2_BITS\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/Patricia/Pat2H.h",
    "content": "// Pat2H.h\n\n#ifndef __PAT2H__H\n#define __PAT2H__H\n\n#undef PAT_CLSID\n#define PAT_CLSID CLSID_CMatchFinderPat2H\n\n#undef PAT_NAMESPACE\n#define PAT_NAMESPACE NPat2H\n\n#define __AUTO_REMOVE\n#define __NODE_2_BITS\n#define __HASH_3\n\n#include \"Pat.h\"\n#include \"PatMain.h\"\n\n#undef __AUTO_REMOVE\n#undef __NODE_2_BITS\n#undef __HASH_3\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/Patricia/Pat2R.h",
    "content": "// Pat2R.h\n\n#ifndef __PAT2R__H\n#define __PAT2R__H\n\n#undef PAT_CLSID\n#define PAT_CLSID CLSID_CMatchFinderPat2R\n\n#undef PAT_NAMESPACE\n#define PAT_NAMESPACE NPat2R\n\n#define __NODE_2_BITS\n\n#include \"Pat.h\"\n#include \"PatMain.h\"\n\n#undef  __NODE_2_BITS\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/Patricia/Pat3H.h",
    "content": "// Pat3H.h\n\n#ifndef __PAT3H__H\n#define __PAT3H__H\n\n#undef PAT_CLSID\n#define PAT_CLSID CLSID_CMatchFinderPat3H\n\n#undef PAT_NAMESPACE\n#define PAT_NAMESPACE NPat3H\n\n#define __AUTO_REMOVE\n#define __NODE_3_BITS\n#define __HASH_3\n\n#include \"Pat.h\"\n#include \"PatMain.h\"\n\n#undef __AUTO_REMOVE\n#undef __NODE_3_BITS\n#undef __HASH_3\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/Patricia/Pat4H.h",
    "content": "// Pat4H.h\n\n#ifndef __PAT4H__H\n#define __PAT4H__H\n\n#undef PAT_CLSID\n#define PAT_CLSID CLSID_CMatchFinderPat4H\n\n#undef PAT_NAMESPACE\n#define PAT_NAMESPACE NPat4H\n\n#define __AUTO_REMOVE\n#define __NODE_4_BITS\n#define __HASH_3\n\n#include \"Pat.h\"\n#include \"PatMain.h\"\n\n#undef __AUTO_REMOVE\n#undef __NODE_4_BITS\n#undef __HASH_3\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/Patricia/PatMain.h",
    "content": "// PatMain.h\n\n#include \"../../../../Common/Defs.h\"\n#include \"../../../../Common/Alloc.h\"\n\nnamespace PAT_NAMESPACE {\n\nSTDMETHODIMP CPatricia::SetCallback(IMatchFinderCallback *callback)\n{\n  m_Callback = callback;\n  return S_OK;\n}\n\nvoid CPatricia::BeforeMoveBlock()\n{\n  if (m_Callback)\n    m_Callback->BeforeChangingBufferPos();\n  CLZInWindow::BeforeMoveBlock();\n}\n\nvoid CPatricia::AfterMoveBlock()\n{\n  if (m_Callback)\n    m_Callback->AfterChangingBufferPos();\n  CLZInWindow::AfterMoveBlock();\n}\n\nconst UInt32 kMatchStartValue2 = 2;\nconst UInt32 kDescendantEmptyValue2 = kMatchStartValue2 - 1;\nconst UInt32 kDescendantsNotInitilized2 = kDescendantEmptyValue2 - 1;\n\n#ifdef __HASH_3\n\nstatic const UInt32 kNumHashBytes = 3;\nstatic const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\n\nstatic const UInt32 kNumHash2Bytes = 2;\nstatic const UInt32 kHash2Size = 1 << (8 * kNumHash2Bytes);\nstatic const UInt32 kPrevHashSize = kNumHash2Bytes;\n\n#else\n\nstatic const UInt32 kNumHashBytes = 2;\nstatic const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\nstatic const UInt32 kPrevHashSize = 0;\n\n#endif\n\n\nCPatricia::CPatricia():\n  m_HashDescendants(0),\n  #ifdef __HASH_3\n  m_Hash2Descendants(0),\n  #endif\n  m_Nodes(0),\n  m_TmpBacks(0)\n{\n}\n\nCPatricia::~CPatricia()\n{\n  FreeMemory();\n}\n\nvoid CPatricia::FreeMemory()\n{\n  MyFree(m_TmpBacks);\n  m_TmpBacks = 0;\n\n  ::BigFree(m_Nodes);\n  m_Nodes = 0;\n\n  ::BigFree(m_HashDescendants);\n  m_HashDescendants = 0;\n\n  #ifdef __HASH_3\n\n  ::BigFree(m_Hash2Descendants);\n  m_Hash2Descendants = 0;\n\n  CLZInWindow::Free();\n\n  #endif\n}\n  \nSTDMETHODIMP CPatricia::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \n    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\n{\n  FreeMemory();\n  int kNumBitsInNumSameBits = sizeof(CSameBitsType) * 8;\n  if (kNumBitsInNumSameBits < 32 && ((matchMaxLen * MY_BYTE_SIZE) > ((UInt32)1 << kNumBitsInNumSameBits)))\n    return E_INVALIDARG;\n\n  const UInt32 kAlignMask = (1 << 16) - 1;\n  UInt32 windowReservSize = historySize;\n  windowReservSize += kAlignMask;\n  windowReservSize &= ~(kAlignMask);\n\n  const UInt32 kMinReservSize = (1 << 19);\n  if (windowReservSize < kMinReservSize)\n    windowReservSize = kMinReservSize;\n  windowReservSize += 256;\n\n  if (!CLZInWindow::Create(historySize + keepAddBufferBefore, \n      matchMaxLen + keepAddBufferAfter, windowReservSize))\n    return E_OUTOFMEMORY;\n\n  _sizeHistory = historySize;\n  _matchMaxLen = matchMaxLen;\n  m_HashDescendants = (CDescendant *)BigAlloc(kHashSize * sizeof(CDescendant));\n  if (m_HashDescendants == 0)\n  {\n    FreeMemory();\n    return E_OUTOFMEMORY;\n  }\n\n  #ifdef __HASH_3\n  m_Hash2Descendants = (CDescendant *)BigAlloc(kHash2Size  * sizeof(CDescendant));\n  if (m_Hash2Descendants == 0)\n  {\n    FreeMemory();\n    return E_OUTOFMEMORY;\n  }\n  #endif\n  \n  #ifdef __AUTO_REMOVE\n  \n  #ifdef __HASH_3\n  m_NumNodes = historySize + _sizeHistory * 4 / 8 + (1 << 19);\n  #else\n  m_NumNodes = historySize + _sizeHistory * 4 / 8 + (1 << 10);\n  #endif\n  \n  #else\n  \n  UInt32 m_NumNodes = historySize;\n  \n  #endif\n  \n  const UInt32 kMaxNumNodes = UInt32(1) << (sizeof(CIndex) * 8 - 1);\n  if (m_NumNodes + 32 > kMaxNumNodes)\n    return E_INVALIDARG;\n  \n  // m_Nodes = (CNode *)::BigAlloc((m_NumNodes + 2) * sizeof(CNode));\n  m_Nodes = (CNode *)::BigAlloc((m_NumNodes + 12) * sizeof(CNode));\n  if (m_Nodes == 0)\n  {\n    FreeMemory();\n    return E_OUTOFMEMORY;\n  }\n  \n  m_TmpBacks = (UInt32 *)MyAlloc((_matchMaxLen + 1) * sizeof(UInt32));\n  if (m_TmpBacks == 0)\n  {\n    FreeMemory();\n    return E_OUTOFMEMORY;\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP CPatricia::Init(ISequentialInStream *aStream)\n{\n  RINOK(CLZInWindow::Init(aStream));\n\n  // memset(m_HashDescendants, 0xFF, kHashSize * sizeof(m_HashDescendants[0]));\n\n  #ifdef __HASH_3\n  for (UInt32 i = 0; i < kHash2Size; i++)\n    m_Hash2Descendants[i].MatchPointer = kDescendantsNotInitilized2;\n  #else\n  for (UInt32 i = 0; i < kHashSize; i++)\n    m_HashDescendants[i].MakeEmpty();\n  #endif\n\n  m_Nodes[0].NextFreeNode = 1;\n  m_FreeNode = 0;\n  m_FreeNodeMax = 0;\n  #ifdef __AUTO_REMOVE\n  m_NumUsedNodes = 0;\n  #else\n  m_SpecialRemoveMode = false;\n  #endif\n  m_SpecialMode = false;\n  return S_OK;\n}\n\nSTDMETHODIMP_(void) CPatricia::ReleaseStream()\n{\n  // CLZInWindow::ReleaseStream();\n}\n\n// pos = _pos + kNumHashBytes\n// fullCurrentLimit = currentLimit + kNumHashBytes\n// fullMatchLen = matchLen + kNumHashBytes\n\nvoid CPatricia::ChangeLastMatch(UInt32 hashValue)\n{\n  UInt32 pos = _pos + kNumHashBytes - 1;\n  UInt32 descendantIndex;\n  const Byte *currentBytePointer = _buffer + pos;\n  UInt32 numLoadedBits = 0;\n  Byte curByte = 0;  // = 0 to disable warning of GCC\n  CNodePointer node = &m_Nodes[m_HashDescendants[hashValue].NodePointer];\n\n  while(true)\n  {\n    UInt32 numSameBits = node->NumSameBits;\n    if(numSameBits > 0)\n    {\n      if (numLoadedBits < numSameBits)\n      {\n        numSameBits -= numLoadedBits;\n        currentBytePointer += (numSameBits / MY_BYTE_SIZE);\n        numSameBits %= MY_BYTE_SIZE;\n        curByte = *currentBytePointer++;\n        numLoadedBits = MY_BYTE_SIZE; \n      }\n      curByte >>= numSameBits;\n      numLoadedBits -= numSameBits;\n    }\n    if(numLoadedBits == 0)\n    {\n      curByte = *currentBytePointer++;\n      numLoadedBits = MY_BYTE_SIZE; \n    }\n    descendantIndex = (curByte & kSubNodesMask);\n    node->LastMatch = pos;\n    numLoadedBits -= kNumSubBits;\n    curByte >>= kNumSubBits;\n    if(node->Descendants[descendantIndex].IsNode())\n      node = &m_Nodes[node->Descendants[descendantIndex].NodePointer];\n    else\n      break;\n  }\n  node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\n}\n\nUInt32 CPatricia::GetLongestMatch(UInt32 *distances)\n{\n  UInt32 fullCurrentLimit;\n  if (_pos + _matchMaxLen <= _streamPos)\n    fullCurrentLimit = _matchMaxLen;\n  else\n  {\n    fullCurrentLimit = _streamPos - _pos;\n    if(fullCurrentLimit < kNumHashBytes)\n      return 0; \n  }\n  UInt32 pos = _pos + kNumHashBytes;\n\n  #ifdef __HASH_3\n  UInt32 hash2Value = ((UInt32(_buffer[_pos])) << 8) | _buffer[_pos + 1];\n  UInt32 hashValue = (hash2Value << 8) | _buffer[_pos + 2];\n  CDescendant &hash2Descendant = m_Hash2Descendants[hash2Value];\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\n  if(hash2Descendant.MatchPointer <= kDescendantEmptyValue2)\n  {\n    if(hash2Descendant.MatchPointer == kDescendantsNotInitilized2)\n    {\n      UInt32 base = hashValue & 0xFFFF00;\n      for (UInt32 i = 0; i < 0x100; i++)\n        m_HashDescendants[base + i].MakeEmpty();\n    }\n    hash2Descendant.MatchPointer = pos + kMatchStartValue2;\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\n    return 0;\n  }\n\n  distances[kNumHash2Bytes] = pos - (hash2Descendant.MatchPointer - kMatchStartValue2) - 1;\n  hash2Descendant.MatchPointer = pos + kMatchStartValue2;\n  #ifdef __AUTO_REMOVE\n  if (distances[kNumHash2Bytes] >= _sizeHistory)\n  {\n    if (hashDescendant.IsNode())\n      RemoveNode(hashDescendant.NodePointer);\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\n    return 0;\n  }\n  #endif\n  if (fullCurrentLimit == kNumHash2Bytes)\n    return kNumHash2Bytes;\n\n  #else\n  UInt32 hashValue = UInt32(GetIndexByte(1))  | (UInt32(GetIndexByte(0)) << 8);\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\n  #endif\n\n\n  if(m_SpecialMode)\n  {\n    if(hashDescendant.IsMatch())\n      m_NumNotChangedCycles = 0;\n    if(m_NumNotChangedCycles >= _sizeHistory - 1)\n    {\n      ChangeLastMatch(hashValue);\n      m_NumNotChangedCycles = 0;\n    }\n    if(GetIndexByte(fullCurrentLimit - 1) == GetIndexByte(fullCurrentLimit - 2)) \n    {\n      if(hashDescendant.IsMatch())\n        hashDescendant.MatchPointer = pos + kMatchStartValue;\n      else\n        m_NumNotChangedCycles++;\n      for(UInt32 i = kNumHashBytes; i <= fullCurrentLimit; i++)\n        distances[i] = 0;\n      return fullCurrentLimit;\n    }\n    else if(m_NumNotChangedCycles > 0)\n      ChangeLastMatch(hashValue);\n    m_SpecialMode = false;\n  }\n\n  if(hashDescendant.IsEmpty())\n  {\n    hashDescendant.MatchPointer = pos + kMatchStartValue;\n    return kPrevHashSize;\n  }\n\n  UInt32 currentLimit = fullCurrentLimit - kNumHashBytes;\n\n  if(hashDescendant.IsMatch())\n  {\n    CMatchPointer matchPointer = hashDescendant.MatchPointer;\n    UInt32 backReal = pos - (matchPointer - kMatchStartValue);\n    UInt32 back = backReal - 1;\n    #ifdef __AUTO_REMOVE\n    if (back >= _sizeHistory)\n    {\n      hashDescendant.MatchPointer = pos + kMatchStartValue;\n      return kPrevHashSize;\n    }\n    #endif\n\n    UInt32 matchLen;\n    distances += kNumHashBytes;\n    Byte *buffer = _buffer + pos;\n    for(matchLen = 0; true; matchLen++)\n    {\n      *distances++ = back;\n      if (matchLen == currentLimit)\n      {\n        hashDescendant.MatchPointer = pos + kMatchStartValue;\n        return kNumHashBytes + matchLen;\n      }\n      if (buffer[matchLen] != buffer[(size_t)matchLen - backReal])\n        break;\n    }\n     \n    // UInt32 matchLen = GetMatchLen(kNumHashBytes, back, currentLimit);\n    \n    UInt32 fullMatchLen = matchLen + kNumHashBytes; \n    hashDescendant.NodePointer = m_FreeNode;\n    CNodePointer node = &m_Nodes[m_FreeNode];\n    m_FreeNode = node->NextFreeNode;\n    #ifdef __AUTO_REMOVE\n    m_NumUsedNodes++;\n    #endif\n    if (m_FreeNode > m_FreeNodeMax)\n    {\n      m_FreeNodeMax = m_FreeNode;\n      m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;\n    }\n      \n    for (UInt32 i = 0; i < kNumSubNodes; i++)\n      node->Descendants[i].NodePointer = kDescendantEmptyValue;\n    node->LastMatch = pos;\n      \n    Byte byteNew = GetIndexByte(fullMatchLen);\n    Byte byteOld = GetIndexByte(fullMatchLen - backReal);\n    Byte bitsNew, bitsOld;\n    UInt32 numSameBits = matchLen * MY_BYTE_SIZE;\n    while (true)\n    {\n      bitsNew = (byteNew & kSubNodesMask);\n      bitsOld = (byteOld & kSubNodesMask);\n      if(bitsNew != bitsOld) \n        break;\n      byteNew >>= kNumSubBits;\n      byteOld >>= kNumSubBits;\n      numSameBits += kNumSubBits;\n    }\n    node->NumSameBits = CSameBitsType(numSameBits);\n    node->Descendants[bitsNew].MatchPointer = pos + kMatchStartValue;\n    node->Descendants[bitsOld].MatchPointer = matchPointer;\n    return fullMatchLen;\n  }\n  const Byte *baseCurrentBytePointer = _buffer + pos;\n  const Byte *currentBytePointer = baseCurrentBytePointer;\n  UInt32 numLoadedBits = 0;\n  Byte curByte = 0;\n  CIndex *nodePointerPointer = &hashDescendant.NodePointer;\n  CNodePointer node = &m_Nodes[*nodePointerPointer];\n  distances += kNumHashBytes;\n  const Byte *bytePointerLimit = baseCurrentBytePointer + currentLimit;\n  const Byte *currentAddingOffset = _buffer;\n\n  #ifdef __AUTO_REMOVE\n  UInt32 lowPos;\n  if (pos > _sizeHistory)\n    lowPos = pos - _sizeHistory;\n  else\n    lowPos = 0;\n  #endif\n\n  while(true)\n  {\n    #ifdef __AUTO_REMOVE\n    if (node->LastMatch < lowPos)\n    {\n      RemoveNode(*nodePointerPointer);\n      *nodePointerPointer = pos + kMatchStartValue;\n      if (currentBytePointer == baseCurrentBytePointer)\n        return kPrevHashSize;\n      return kNumHashBytes + (currentBytePointer - baseCurrentBytePointer - 1);\n    }\n    #endif\n    if(numLoadedBits == 0)\n    {\n      *distances++ = pos - node->LastMatch - 1;\n      if(currentBytePointer >= bytePointerLimit)\n      {\n        for (UInt32 i = 0; i < kNumSubNodes; i++)\n          node->Descendants[i].MatchPointer = pos + kMatchStartValue;\n        node->LastMatch = pos;\n        node->NumSameBits = 0;\n        return fullCurrentLimit;\n      }\n      curByte = (*currentBytePointer++);\n      currentAddingOffset++;\n      numLoadedBits = MY_BYTE_SIZE; \n    }\n    UInt32 numSameBits = node->NumSameBits;\n    if(numSameBits > 0)\n    {\n      Byte byteXOR = ((*(currentAddingOffset + node->LastMatch -1)) >> \n          (MY_BYTE_SIZE - numLoadedBits)) ^ curByte;\n      while(numLoadedBits <= numSameBits)\n      {\n        if(byteXOR != 0)\n        {\n          AddInternalNode(node, nodePointerPointer, curByte, byteXOR,\n              numSameBits, pos);\n          return kNumHashBytes + (currentBytePointer - baseCurrentBytePointer - 1);\n        }\n        *distances++ = pos - node->LastMatch - 1;\n        numSameBits -= numLoadedBits;\n        if(currentBytePointer >= bytePointerLimit)\n        {\n          for (UInt32 i = 0; i < kNumSubNodes; i++)\n            node->Descendants[i].MatchPointer = pos + kMatchStartValue;\n          node->LastMatch = pos;\n          node->NumSameBits = CSameBitsType(node->NumSameBits - numSameBits);\n          return fullCurrentLimit;\n        }\n        numLoadedBits = MY_BYTE_SIZE; \n        curByte = (*currentBytePointer++);\n        byteXOR = curByte ^ (*(currentAddingOffset + node->LastMatch));\n        currentAddingOffset++;\n      }\n      if((byteXOR & ((1 << numSameBits) - 1)) != 0)\n      {\n        AddInternalNode(node, nodePointerPointer, curByte, byteXOR,\n            numSameBits, pos);\n        return kNumHashBytes + (currentBytePointer - baseCurrentBytePointer - 1);\n      }\n      curByte >>= numSameBits;\n      numLoadedBits -= numSameBits;\n    }\n    UInt32 descendantIndex = (curByte & kSubNodesMask);\n    numLoadedBits -= kNumSubBits;\n    nodePointerPointer = &node->Descendants[descendantIndex].NodePointer;\n    UInt32 nextNodeIndex = *nodePointerPointer;\n    node->LastMatch = pos;\n    if (nextNodeIndex < kDescendantEmptyValue)\n    {\n      curByte >>= kNumSubBits;\n      node = &m_Nodes[nextNodeIndex];\n    }\n    else if (nextNodeIndex == kDescendantEmptyValue)\n    {\n      node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\n      return kNumHashBytes + (currentBytePointer - baseCurrentBytePointer - 1);\n    }\n    else \n      break;\n  }\n \n  UInt32 descendantIndex = (curByte & kSubNodesMask);\n  curByte >>= kNumSubBits;\n  CMatchPointer matchPointer = node->Descendants[descendantIndex].MatchPointer;\n  CMatchPointer realMatchPointer;\n  realMatchPointer = matchPointer - kMatchStartValue;\n\n  #ifdef __AUTO_REMOVE\n  if (realMatchPointer < lowPos)\n  {\n    node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\n    return kNumHashBytes + (currentBytePointer - baseCurrentBytePointer - 1);\n  }\n  #endif\n\n  Byte byteXOR;\n  UInt32 numSameBits = 0;\n  if(numLoadedBits != 0)\n  {\n    Byte matchByte = *(currentAddingOffset + realMatchPointer -1);  \n    matchByte >>= (MY_BYTE_SIZE - numLoadedBits);\n    byteXOR = matchByte ^ curByte;\n    if(byteXOR != 0)\n    {\n      AddLeafNode(node, curByte, byteXOR, numSameBits, pos, descendantIndex);\n      return kNumHashBytes + (currentBytePointer - baseCurrentBytePointer - 1);\n    }\n    numSameBits += numLoadedBits;\n  }\n\n  const Byte *matchBytePointer = _buffer + realMatchPointer + \n      (currentBytePointer - baseCurrentBytePointer);\n  for(; currentBytePointer < bytePointerLimit; numSameBits += MY_BYTE_SIZE)\n  {\n    curByte = (*currentBytePointer++);\n    *distances++ = pos - realMatchPointer - 1;\n    byteXOR = curByte ^ (*matchBytePointer++);\n    if(byteXOR != 0)\n    {\n      AddLeafNode(node, curByte, byteXOR, numSameBits, pos, descendantIndex);\n      return kNumHashBytes + (currentBytePointer - baseCurrentBytePointer - 1);\n    }\n  }\n  *distances = pos - realMatchPointer - 1;\n  node->Descendants[descendantIndex].MatchPointer = pos + kMatchStartValue;\n\n  if(*distances == 0)\n  {\n    m_SpecialMode = true;\n    m_NumNotChangedCycles = 0;\n  }\n  return fullCurrentLimit;\n}\n\nSTDMETHODIMP_(void) CPatricia::DummyLongestMatch()\n{\n  GetLongestMatch(m_TmpBacks);\n}\n\n\n// ------------------------------------\n// Remove Match\n\ntypedef Byte CRemoveDataWord;\n\nstatic const int kSizeRemoveDataWordInBits = MY_BYTE_SIZE * sizeof(CRemoveDataWord);\n\n#ifndef __AUTO_REMOVE\n\nvoid CPatricia::RemoveMatch()\n{\n  if(m_SpecialRemoveMode)\n  {\n    if(GetIndexByte(_matchMaxLen - 1 - _sizeHistory) ==\n        GetIndexByte(_matchMaxLen - _sizeHistory))\n      return;\n    m_SpecialRemoveMode = false;\n  }\n  UInt32 pos = _pos + kNumHashBytes - _sizeHistory;\n\n  #ifdef __HASH_3\n  const Byte *pp = _buffer + _pos - _sizeHistory;\n  UInt32 hash2Value = ((UInt32(pp[0])) << 8) | pp[1];\n  UInt32 hashValue = (hash2Value << 8) | pp[2];\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\n  CDescendant &hash2Descendant = m_Hash2Descendants[hash2Value];\n  if (hash2Descendant >= kMatchStartValue2)\n    if(hash2Descendant.MatchPointer == pos + kMatchStartValue2)\n      hash2Descendant.MatchPointer = kDescendantEmptyValue2;\n  #else\n  UInt32 hashValue = UInt32(GetIndexByte(1 - _sizeHistory))  | \n      (UInt32(GetIndexByte(0 - _sizeHistory)) << 8);\n  CDescendant &hashDescendant = m_HashDescendants[hashValue];\n  #endif\n    \n  if(hashDescendant.IsEmpty())\n    return;\n  if(hashDescendant.IsMatch())\n  {\n    if(hashDescendant.MatchPointer == pos + kMatchStartValue)\n      hashDescendant.MakeEmpty();\n    return;\n  }\n  \n  UInt32 descendantIndex;\n  const CRemoveDataWord *currentPointer = (const CRemoveDataWord *)(_buffer + pos);\n  UInt32 numLoadedBits = 0;\n  CRemoveDataWord curWord = 0; // = 0 to disable GCC warning\n\n  CIndex *nodePointerPointer = &hashDescendant.NodePointer;\n\n  CNodePointer node = &m_Nodes[hashDescendant.NodePointer];\n  \n  while(true)\n  {\n    if(numLoadedBits == 0)\n    {\n      curWord = *currentPointer++;\n      numLoadedBits = kSizeRemoveDataWordInBits; \n    }\n    UInt32 numSameBits = node->NumSameBits;\n    if(numSameBits > 0)\n    {\n      if (numLoadedBits <= numSameBits)\n      {\n        numSameBits -= numLoadedBits;\n        currentPointer += (numSameBits / kSizeRemoveDataWordInBits);\n        numSameBits %= kSizeRemoveDataWordInBits;\n        curWord = *currentPointer++;\n        numLoadedBits = kSizeRemoveDataWordInBits; \n      }\n      curWord >>= numSameBits;\n      numLoadedBits -= numSameBits;\n    }\n    descendantIndex = (curWord & kSubNodesMask);\n    numLoadedBits -= kNumSubBits;\n    curWord >>= kNumSubBits;\n    UInt32 nextNodeIndex = node->Descendants[descendantIndex].NodePointer;\n    if (nextNodeIndex < kDescendantEmptyValue)\n    {\n      nodePointerPointer = &node->Descendants[descendantIndex].NodePointer;\n      node = &m_Nodes[nextNodeIndex];\n    }\n    else\n      break;\n  }\n  if (node->Descendants[descendantIndex].MatchPointer != pos + kMatchStartValue)\n  {\n    const Byte *currentBytePointer = _buffer + _pos - _sizeHistory;\n    const Byte *currentBytePointerLimit = currentBytePointer + _matchMaxLen;\n    for(;currentBytePointer < currentBytePointerLimit; currentBytePointer++)\n      if(*currentBytePointer != *(currentBytePointer+1))\n        return;\n    m_SpecialRemoveMode = true;\n    return;\n  }\n\n  UInt32 numNodes = 0, numMatches = 0;\n\n  UInt32 i;\n  for (i = 0; i < kNumSubNodes; i++)\n  {\n    UInt32 nodeIndex = node->Descendants[i].NodePointer;\n    if (nodeIndex < kDescendantEmptyValue)\n      numNodes++;\n    else if (nodeIndex > kDescendantEmptyValue)\n      numMatches++;\n  }\n  numMatches -= 1;\n  if (numNodes + numMatches > 1)\n  {\n    node->Descendants[descendantIndex].MakeEmpty();\n    return;\n  }\n  if(numNodes == 1)\n  {\n    UInt32 i;\n    for (i = 0; i < kNumSubNodes; i++)\n      if (node->Descendants[i].IsNode())\n        break;\n    UInt32 nextNodeIndex = node->Descendants[i].NodePointer;\n    CNodePointer nextNode = &m_Nodes[nextNodeIndex];\n    nextNode->NumSameBits += node->NumSameBits + kNumSubBits;\n    *node = *nextNode;\n\n    nextNode->NextFreeNode = m_FreeNode;\n    m_FreeNode = nextNodeIndex;\n    return;\n  }\n  UInt32 matchPointer = 0; // = 0 to disable GCC warning\n  for (i = 0; i < kNumSubNodes; i++)\n    if (node->Descendants[i].IsMatch() && i != descendantIndex)\n    {\n      matchPointer = node->Descendants[i].MatchPointer;\n      break;\n    }\n  node->NextFreeNode = m_FreeNode;\n  m_FreeNode = *nodePointerPointer;\n  *nodePointerPointer = matchPointer;\n}\n#endif\n\n\n// Commented code is more correct, but it gives warning \n// on GCC: (1 << 32)\n// So we use kMatchStartValue twice:\n// kMatchStartValue = UInt32(1) << (kNumBitsInIndex - 1);\n// must be defined in Pat.h\n/*\nconst UInt32 kNormalizeStartPos = (UInt32(1) << (kNumBitsInIndex)) - \n    kMatchStartValue - kNumHashBytes - 1;\n*/\nconst UInt32 kNormalizeStartPos = kMatchStartValue - kNumHashBytes - 1;\n\nSTDMETHODIMP CPatricia::MovePos()\n{\n  #ifndef __AUTO_REMOVE\n  if(_pos >= _sizeHistory)\n    RemoveMatch();\n  #endif\n  RINOK(CLZInWindow::MovePos());\n  #ifdef __AUTO_REMOVE\n  if (m_NumUsedNodes >= m_NumNodes)\n    TestRemoveNodes();\n  #endif\n  if (_pos >= kNormalizeStartPos)\n  {\n    #ifdef __AUTO_REMOVE\n    TestRemoveNodesAndNormalize();\n    #else\n    Normalize();\n    #endif\n  }\n  return S_OK;\n}\n\n#ifndef __AUTO_REMOVE\n\nvoid CPatricia::NormalizeDescendant(CDescendant &descendant, UInt32 subValue)\n{\n  if (descendant.IsEmpty())\n    return;\n  if (descendant.IsMatch())\n    descendant.MatchPointer = descendant.MatchPointer - subValue;\n  else\n  {\n    CNode &node = m_Nodes[descendant.NodePointer];\n    node.LastMatch = node.LastMatch - subValue;\n    for (UInt32 i = 0; i < kNumSubNodes; i++)\n       NormalizeDescendant(node.Descendants[i], subValue);\n  }\n}\n\nvoid CPatricia::Normalize()\n{\n  UInt32 subValue = _pos - _sizeHistory;\n  CLZInWindow::ReduceOffsets(subValue);\n  \n  #ifdef __HASH_3\n\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\n  {\n    CDescendant &descendant = m_Hash2Descendants[hash];\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\n    {\n      UInt32 base = hash << 8;\n      for (UInt32 i = 0; i < 0x100; i++)\n        NormalizeDescendant(m_HashDescendants[base + i], subValue);\n    }\n    if (descendant.MatchPointer < kMatchStartValue2)\n      continue;\n    descendant.MatchPointer = descendant.MatchPointer - subValue;\n  }\n  \n  #else\n  \n  for(UInt32 hash = 0; hash < kHashSize; hash++)\n    NormalizeDescendant(m_HashDescendants[hash], subValue);\n  \n  #endif\n\n}\n\n#else\n\nvoid CPatricia::TestRemoveDescendant(CDescendant &descendant, UInt32 limitPos)\n{\n  CNode &node = m_Nodes[descendant.NodePointer];\n  UInt32 numChilds = 0;\n  UInt32 childIndex = 0; // = 0 to disable GCC warning\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\n  {\n    CDescendant &descendant2 = node.Descendants[i];\n    if (descendant2.IsEmpty())\n      continue;\n    if (descendant2.IsMatch())\n    {\n      if (descendant2.MatchPointer < limitPos)\n        descendant2.MakeEmpty();\n      else\n      {\n        numChilds++;\n        childIndex = i;\n      }\n    }\n    else\n    {\n      TestRemoveDescendant(descendant2, limitPos);\n      if (!descendant2.IsEmpty())\n      {\n        numChilds++;\n        childIndex = i;\n      }\n    }\n  }\n  if (numChilds > 1)\n    return;\n\n  CIndex nodePointerTemp = descendant.NodePointer;\n  if (numChilds == 1)\n  {\n    const CDescendant &descendant2 = node.Descendants[childIndex];\n    if (descendant2.IsNode())\n      m_Nodes[descendant2.NodePointer].NumSameBits += node.NumSameBits + kNumSubBits;\n    descendant = descendant2;\n  }\n  else\n    descendant.MakeEmpty();\n  node.NextFreeNode = m_FreeNode;\n  m_FreeNode = nodePointerTemp;\n  m_NumUsedNodes--;\n}\n\nvoid CPatricia::RemoveNode(UInt32 index)\n{\n  CNode &node = m_Nodes[index];\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\n  {\n    CDescendant &descendant2 = node.Descendants[i];\n    if (descendant2.IsNode())\n      RemoveNode(descendant2.NodePointer);\n  }\n  node.NextFreeNode = m_FreeNode;\n  m_FreeNode = index;\n  m_NumUsedNodes--;\n}\n\nvoid CPatricia::TestRemoveNodes()\n{\n  UInt32 limitPos = kMatchStartValue + _pos - _sizeHistory + kNumHashBytes;\n  \n  #ifdef __HASH_3\n  \n  UInt32 limitPos2 = kMatchStartValue2 + _pos - _sizeHistory + kNumHashBytes;\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\n  {\n    CDescendant &descendant = m_Hash2Descendants[hash];\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\n    {\n      UInt32 base = hash << 8;\n      for (UInt32 i = 0; i < 0x100; i++)\n      {\n        CDescendant &descendant = m_HashDescendants[base + i];\n        if (descendant.IsEmpty())\n          continue;\n        if (descendant.IsMatch())\n        {\n          if (descendant.MatchPointer < limitPos)\n            descendant.MakeEmpty();\n        }\n        else\n          TestRemoveDescendant(descendant, limitPos);\n      }\n    }\n    if (descendant.MatchPointer < kMatchStartValue2)\n      continue;\n    if (descendant.MatchPointer < limitPos2)\n      descendant.MatchPointer = kDescendantEmptyValue2;\n  }\n  \n  #else\n  \n  for(UInt32 hash = 0; hash < kHashSize; hash++)\n  {\n    CDescendant &descendant = m_HashDescendants[hash];\n    if (descendant.IsEmpty())\n      continue;\n    if (descendant.IsMatch())\n    {\n      if (descendant.MatchPointer < limitPos)\n        descendant.MakeEmpty();\n    }\n    else\n      TestRemoveDescendant(descendant, limitPos);\n  }\n  \n  #endif\n}\n\nvoid CPatricia::TestRemoveAndNormalizeDescendant(CDescendant &descendant, \n    UInt32 limitPos, UInt32 subValue)\n{\n  if (descendant.IsEmpty())\n    return;\n  if (descendant.IsMatch())\n  {\n    if (descendant.MatchPointer < limitPos)\n      descendant.MakeEmpty();\n    else\n      descendant.MatchPointer = descendant.MatchPointer - subValue;\n    return;\n  }\n  CNode &node = m_Nodes[descendant.NodePointer];\n  UInt32 numChilds = 0;\n  UInt32 childIndex = 0; // = 0 to disable GCC warning\n  for (UInt32 i = 0; i < kNumSubNodes; i++)\n  {\n    CDescendant &descendant2 = node.Descendants[i];\n    TestRemoveAndNormalizeDescendant(descendant2, limitPos, subValue);\n    if (!descendant2.IsEmpty())\n    {\n      numChilds++;\n      childIndex = i;\n    }\n  }\n  if (numChilds > 1)\n  {\n    node.LastMatch = node.LastMatch - subValue;\n    return;\n  }\n\n  CIndex nodePointerTemp = descendant.NodePointer;\n  if (numChilds == 1)\n  {\n    const CDescendant &descendant2 = node.Descendants[childIndex];\n    if (descendant2.IsNode())\n      m_Nodes[descendant2.NodePointer].NumSameBits += node.NumSameBits + kNumSubBits;\n    descendant = descendant2;\n  }\n  else\n    descendant.MakeEmpty();\n  node.NextFreeNode = m_FreeNode;\n  m_FreeNode = nodePointerTemp;\n  m_NumUsedNodes--;\n}\n\nvoid CPatricia::TestRemoveNodesAndNormalize()\n{\n  UInt32 subValue = _pos - _sizeHistory;\n  UInt32 limitPos = kMatchStartValue + _pos - _sizeHistory + kNumHashBytes;\n  CLZInWindow::ReduceOffsets(subValue);\n\n  #ifdef __HASH_3\n  \n  UInt32 limitPos2 = kMatchStartValue2 + _pos - _sizeHistory + kNumHashBytes;\n  for(UInt32 hash = 0; hash < kHash2Size; hash++)\n  {\n    CDescendant &descendant = m_Hash2Descendants[hash];\n    if (descendant.MatchPointer != kDescendantsNotInitilized2)\n    {\n      UInt32 base = hash << 8;\n      for (UInt32 i = 0; i < 0x100; i++)\n        TestRemoveAndNormalizeDescendant(m_HashDescendants[base + i], limitPos, subValue);\n    }\n    if (descendant.MatchPointer < kMatchStartValue2)\n      continue;\n    if (descendant.MatchPointer < limitPos2)\n      descendant.MatchPointer = kDescendantEmptyValue2;\n    else\n      descendant.MatchPointer = descendant.MatchPointer - subValue;\n  }\n  \n  #else\n\n  for(UInt32 hash = 0; hash < kHashSize; hash++)\n    TestRemoveAndNormalizeDescendant(m_HashDescendants[hash], limitPos, subValue);\n\n  #endif\n}\n\n#endif\n\nSTDMETHODIMP_(Byte) CPatricia::GetIndexByte(Int32 index)\n{\n  return CLZInWindow::GetIndexByte(index);\n}\n\nSTDMETHODIMP_(UInt32) CPatricia::GetMatchLen(Int32 index, UInt32 back, UInt32 limit)\n{\n  return CLZInWindow::GetMatchLen(index, back, limit);\n}\n\nSTDMETHODIMP_(UInt32) CPatricia::GetNumAvailableBytes()\n{\n  return CLZInWindow::GetNumAvailableBytes();\n}\n\nSTDMETHODIMP_(const Byte *) CPatricia::GetPointerToCurrentPos()\n{\n  return CLZInWindow::GetPointerToCurrentPos();\n}\n\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZ/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA/LZMA.h",
    "content": "// LZMA.h\n\n#ifndef __LZMA_H\n#define __LZMA_H\n\nnamespace NCompress {\nnamespace NLZMA {\n\nconst UInt32 kNumRepDistances = 4;\n\nconst int kNumStates = 12;\n\nconst Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\nconst Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\nconst Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\nconst Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\n\nclass CState\n{\npublic:\n  Byte Index;\n  void Init() { Index = 0; }\n  void UpdateChar() { Index = kLiteralNextStates[Index]; }\n  void UpdateMatch() { Index = kMatchNextStates[Index]; }\n  void UpdateRep() { Index = kRepNextStates[Index]; }\n  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }\n};\n\nconst int kNumPosSlotBits = 6; \nconst int kDicLogSizeMin = 0; \nconst int kDicLogSizeMax = 32; \nconst int kDistTableSizeMax = kDicLogSizeMax * 2; \n\nconst UInt32 kNumLenToPosStates = 4;\n\ninline UInt32 GetLenToPosState(UInt32 len)\n{\n  len -= 2;\n  if (len < kNumLenToPosStates)\n    return len;\n  return kNumLenToPosStates - 1;\n}\n\nnamespace NLength {\n\nconst int kNumPosStatesBitsMax = 4;\nconst UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\n\nconst int kNumPosStatesBitsEncodingMax = 4;\nconst UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\n\nconst int kNumLowBits = 3;\nconst int kNumMidBits = 3;\nconst int kNumHighBits = 8;\nconst UInt32 kNumLowSymbols = 1 << kNumLowBits;\nconst UInt32 kNumMidSymbols = 1 << kNumMidBits;\nconst UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\n\n}\n\nconst UInt32 kMatchMinLen = 2;\nconst UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\n\nconst int kNumAlignBits = 4;\nconst UInt32 kAlignTableSize = 1 << kNumAlignBits;\nconst UInt32 kAlignMask = (kAlignTableSize - 1);\n\nconst UInt32 kStartPosModelIndex = 4;\nconst UInt32 kEndPosModelIndex = 14;\nconst UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\n\nconst UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);\n\nconst int kNumLitPosStatesBitsEncodingMax = 4;\nconst int kNumLitContextBitsMax = 8;\n\nconst int kNumMoveBits = 5;\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA/LZMADecoder.cpp",
    "content": "// LZMADecoder.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LZMADecoder.h\"\n#include \"../../../Common/Defs.h\"\n\nnamespace NCompress {\nnamespace NLZMA {\n\nvoid CDecoder::Init()\n{\n  { \n    for(int i = 0; i < kNumStates; i++)\n    {\n      for (UInt32 j = 0; j <= _posStateMask; j++)\n      {\n        _isMatch[i][j].Init();\n        _isRep0Long[i][j].Init();\n      }\n      _isRep[i].Init();\n      _isRepG0[i].Init();\n      _isRepG1[i].Init();\n      _isRepG2[i].Init();\n    }\n  }\n  { \n    for (UInt32 i = 0; i < kNumLenToPosStates; i++)\n    _posSlotDecoder[i].Init();\n  }\n  { \n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\n      _posDecoders[i].Init();\n  }\n  _posAlignDecoder.Init();\n  _lenDecoder.Init(_posStateMask + 1);\n  _repMatchLenDecoder.Init(_posStateMask + 1);\n  _literalDecoder.Init();\n\n  _state.Init();\n  _previousIsMatch = false;\n  _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0;\n}\n\nHRESULT CDecoder::CodeSpec(Byte *buffer, UInt32 curSize)\n{\n  int len = _remainLen;\n  if (len == -1 || curSize == 0)\n    return S_OK;\n\n  UInt64 nowPos64 = _nowPos64;\n  if (nowPos64 == 0)\n  {\n    _rangeDecoder.Init();\n    Init();\n  }\n  UInt32 rep0 = _reps[0];\n  UInt32 rep1 = _reps[1];\n  UInt32 rep2 = _reps[2];\n  UInt32 rep3 = _reps[3];\n  bool previousIsMatch = _previousIsMatch;\n  CState state = _state;\n  Byte previousByte;\n\n  while(len > 0 && curSize > 0)\n  {\n    previousByte = _outWindowStream.GetByte(rep0);\n    _outWindowStream.PutByte(previousByte);\n    if (buffer)\n      *buffer++ = previousByte;\n    nowPos64++;\n    len--;\n    curSize--;\n  }\n  if (nowPos64 == 0)\n    previousByte = 0;\n  else\n    previousByte = _outWindowStream.GetByte(0);\n\n  _remainLen = len;\n  while(curSize > 0)\n  {\n    {\n      #ifdef _NO_EXCEPTIONS\n      if (_rangeDecoder.Stream.ErrorCode != S_OK)\n        return _rangeDecoder.Stream.ErrorCode;\n      #endif\n      if (_rangeDecoder.Stream.WasFinished())\n        return S_FALSE;\n      UInt32 posState = UInt32(nowPos64) & _posStateMask;\n      if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0)\n      {\n        state.UpdateChar();\n        if(previousIsMatch)\n        {\n          Byte matchByte = _outWindowStream.GetByte(rep0);\n          previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder, \n              UInt32(nowPos64), previousByte, matchByte);\n          previousIsMatch = false;\n        }\n        else\n          previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder, \n              UInt32(nowPos64), previousByte);\n        _outWindowStream.PutByte(previousByte);\n        if (buffer)\n          *buffer++ = previousByte;\n        curSize--;\n        nowPos64++;\n      }\n      else             \n      {\n        previousIsMatch = true;\n        UInt32 len;\n        if(_isRep[state.Index].Decode(&_rangeDecoder) == 1)\n        {\n          if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0)\n          {\n            if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0)\n            {\n              if (nowPos64 == 0)\n                return S_FALSE;\n              state.UpdateShortRep();\n              previousByte = _outWindowStream.GetByte(rep0);\n              _outWindowStream.PutByte(previousByte);\n              if (buffer)\n                *buffer++ = previousByte;\n              curSize--;\n              nowPos64++;\n              continue;\n            }\n          }\n          else\n          {\n            UInt32 distance;\n            if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0)\n              distance = rep1;\n            else \n            {\n              if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0)\n                distance = rep2;\n              else\n              {\n                distance = rep3;\n                rep3 = rep2;\n              }\n              rep2 = rep1;\n            }\n            rep1 = rep0;\n            rep0 = distance;\n          }\n          len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;\n          state.UpdateRep();\n        }\n        else\n        {\n          rep3 = rep2;\n          rep2 = rep1;\n          rep1 = rep0;\n          len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);\n          state.UpdateMatch();\n          UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);\n          if (posSlot >= kStartPosModelIndex)\n          {\n            UInt32 numDirectBits = (posSlot >> 1) - 1;\n            rep0 = ((2 | (posSlot & 1)) << numDirectBits);\n\n            if (posSlot < kEndPosModelIndex)\n              rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders + \n                  rep0 - posSlot - 1, &_rangeDecoder, numDirectBits);\n            else\n            {\n              rep0 += (_rangeDecoder.DecodeDirectBits(\n                  numDirectBits - kNumAlignBits) << kNumAlignBits);\n              rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder);\n            }\n          }\n          else\n            rep0 = posSlot;\n        }\n        if (rep0 >= nowPos64 || rep0 >= _dictionarySizeCheck)\n        {\n          if (rep0 == (UInt32)(Int32)(-1))\n          {\n            _nowPos64 = nowPos64;\n            _remainLen = -1;\n            return S_OK;\n          }\n          return S_FALSE;\n        }\n        UInt32 locLen = len;\n        if (locLen > curSize)\n          locLen = (UInt32)curSize;\n        if (buffer)\n        {\n          for (UInt32 i = 0; i < locLen; i++)\n          {\n            previousByte = _outWindowStream.GetByte(rep0);\n            *buffer++ = previousByte;\n            _outWindowStream.PutByte(previousByte);\n          }\n        }\n        else\n        {\n          _outWindowStream.CopyBlock(rep0, locLen);\n          previousByte = _outWindowStream.GetByte(0);\n        }\n        curSize -= locLen;\n        nowPos64 += locLen;\n        len -= locLen;\n        if (len != 0)\n        {\n          _remainLen = (Int32)len;\n          break;\n        }\n\n        #ifdef _NO_EXCEPTIONS\n        if (_outWindowStream.ErrorCode != S_OK)\n          return _outWindowStream.ErrorCode;\n        #endif\n      }\n    }\n  }\n  _nowPos64 = nowPos64;\n  _reps[0] = rep0;\n  _reps[1] = rep1;\n  _reps[2] = rep2;\n  _reps[3] = rep3;\n  _previousIsMatch = previousIsMatch;\n  _state = state;\n\n  return S_OK;\n}\n\nSTDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,\n    ISequentialOutStream *outStream, \n    const UInt64 *, const UInt64 *outSize,\n    ICompressProgressInfo *progress)\n{\n  SetInStream(inStream);\n  _outWindowStream.SetStream(outStream);\n  SetOutStreamSize(outSize);\n  CDecoderFlusher flusher(this);\n\n  while (_nowPos64 < _outSize)\n  {\n    UInt32 curSize = 1 << 18;\n    if (_outSize != (UInt64)(Int64)(-1))\n      if (curSize > _outSize - _nowPos64)\n        curSize = (UInt32)(_outSize - _nowPos64);\n    RINOK(CodeSpec(0, curSize));\n    if (_remainLen == -1)\n      break;\n    if (progress != NULL)\n    {\n      UInt64 inSize = _rangeDecoder.GetProcessedSize();\n      RINOK(progress->SetRatioInfo(&inSize, &_nowPos64));\n    }\n  }\n  flusher.NeedFlush = false;\n  return Flush();\n}\n\nSTDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\n      ICompressProgressInfo *progress)\n{\n  #ifndef _NO_EXCEPTIONS\n  try \n  { \n  #endif\n    return CodeReal(inStream, outStream, inSize, outSize, progress); \n  #ifndef _NO_EXCEPTIONS\n  }\n  catch(const CInBufferException &e)  { return e.ErrorCode; }\n  catch(const CLZOutWindowException &e)  { return e.ErrorCode; }\n  catch(...) { return S_FALSE; }\n  #endif\n}\n\nSTDMETHODIMP CDecoder::SetDecoderProperties(ISequentialInStream *inStream)\n{\n  UInt32 processesedSize;\n  Byte properties[5];\n  RINOK(inStream->Read(properties, sizeof(properties), &processesedSize));\n  if (processesedSize != sizeof(properties))\n    return E_INVALIDARG;\n  int lc = properties[0] % 9;\n  Byte remainder = (Byte)(properties[0] / 9);\n  int lp = remainder % 5;\n  int pb = remainder / 5;\n  if (pb > NLength::kNumPosStatesBitsMax)\n    return E_INVALIDARG;\n  _posStateMask = (1 << pb) - 1;\n  UInt32 dictionarySize = 0;\n  for (int i = 0; i < 4; i++)\n    dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\n  _dictionarySizeCheck = MyMax(dictionarySize, UInt32(1));\n  UInt32 blockSize = MyMax(_dictionarySizeCheck, UInt32(1 << 12));\n  if (!_outWindowStream.Create(blockSize))\n    return E_OUTOFMEMORY;\n  if (!_literalDecoder.Create(lp, lc))\n    return E_OUTOFMEMORY;\n  if (!_rangeDecoder.Create(1 << 20))\n    return E_OUTOFMEMORY;\n  return S_OK;\n}\n\nSTDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value)\n{\n  *value = _rangeDecoder.GetProcessedSize();\n  return S_OK;\n}\n\nSTDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)\n{\n  _rangeDecoder.SetStream(inStream);\n  return S_OK;\n}\n\nSTDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)\n{\n  _outSize = (outSize == NULL) ? (UInt64)(Int64)(-1) : *outSize;\n  _nowPos64 = 0;\n  _remainLen = 0;\n  _outWindowStream.Init();\n  return S_OK;\n}\n\nSTDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  #ifndef _NO_EXCEPTIONS\n  try \n  { \n  #endif\n  UInt64 startPos = _nowPos64;\n  if (_outSize != (UInt64)(Int64)(-1))\n    if (size > _outSize - _nowPos64)\n      size = (UInt32)(_outSize - _nowPos64);\n  HRESULT res = CodeSpec((Byte *)data, size);\n  if (processedSize)\n    *processedSize = (UInt32)(_nowPos64 - startPos);\n  return res;\n  #ifndef _NO_EXCEPTIONS\n  }\n  catch(const CInBufferException &e)  { return e.ErrorCode; }\n  catch(const CLZOutWindowException &e)  { return e.ErrorCode; }\n  catch(...) { return S_FALSE; }\n  #endif\n}\n\nSTDMETHODIMP CDecoder::ReadPart(void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Read(data, size, processedSize);\n}\n\n}}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA/LZMADecoder.h",
    "content": "// LZMA/Decoder.h\n\n#ifndef __LZMA_DECODER_H\n#define __LZMA_DECODER_H\n\n#include \"../../../Common/MyCom.h\"\n#include \"../../../Common/Alloc.h\"\n#include \"../../ICoder.h\"\n#include \"../LZ/LZOutWindow.h\"\n#include \"../RangeCoder/RangeCoderBitTree.h\"\n\n#include \"LZMA.h\"\n\nnamespace NCompress {\nnamespace NLZMA {\n\ntypedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;\n\nclass CLiteralDecoder2\n{\n  CMyBitDecoder _decoders[0x300];\npublic:\n  void Init()\n  {\n    for (int i = 0; i < 0x300; i++)\n      _decoders[i].Init();\n  }\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)\n  {\n    UInt32 symbol = 1;\n    RC_INIT_VAR\n    do\n    {\n      // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\n      RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\n    }\n    while (symbol < 0x100);\n    RC_FLUSH_VAR\n    return (Byte)symbol;\n  }\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, Byte matchByte)\n  {\n    UInt32 symbol = 1;\n    RC_INIT_VAR\n    do\n    {\n      UInt32 matchBit = (matchByte >> 7) & 1;\n      matchByte <<= 1;\n      // UInt32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);\n      // symbol = (symbol << 1) | bit;\n      UInt32 bit;\n      RC_GETBIT2(kNumMoveBits, _decoders[((1 + matchBit) << 8) + symbol].Prob, symbol, \n          bit = 0, bit = 1)\n      if (matchBit != bit)\n      {\n        while (symbol < 0x100)\n        {\n          // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);\n          RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol)\n        }\n        break;\n      }\n    }\n    while (symbol < 0x100);\n    RC_FLUSH_VAR\n    return (Byte)symbol;\n  }\n};\n\nclass CLiteralDecoder\n{\n  CLiteralDecoder2 *_coders;\n  int _numPrevBits;\n  int _numPosBits;\n  UInt32 _posMask;\npublic:\n  CLiteralDecoder(): _coders(0) {}\n  ~CLiteralDecoder()  { Free(); }\n  void Free()\n  { \n    MyFree(_coders);\n    _coders = 0;\n  }\n  bool Create(int numPosBits, int numPrevBits)\n  {\n    if (_coders == 0 || (numPosBits + numPrevBits) != \n        (_numPrevBits + _numPosBits) )\n    {\n      Free();\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\n      _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2));\n    }\n    _numPosBits = numPosBits;\n    _posMask = (1 << numPosBits) - 1;\n    _numPrevBits = numPrevBits;\n    return (_coders != 0);\n  }\n  void Init()\n  {\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\n    for (UInt32 i = 0; i < numStates; i++)\n      _coders[i].Init();\n  }\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\n  Byte DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte)\n    { return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }\n  Byte DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UInt32 pos, Byte prevByte, Byte matchByte)\n    { return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }\n};\n\nnamespace NLength {\n\nclass CDecoder\n{\n  CMyBitDecoder _choice;\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesMax];\n  CMyBitDecoder _choice2;\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesMax];\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder; \npublic:\n  void Init(UInt32 numPosStates)\n  {\n    _choice.Init();\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\n    {\n      _lowCoder[posState].Init();\n      _midCoder[posState].Init();\n    }\n    _choice2.Init();\n    _highCoder.Init();\n  }\n  UInt32 Decode(NRangeCoder::CDecoder *rangeDecoder, UInt32 posState)\n  {\n    if(_choice.Decode(rangeDecoder) == 0)\n      return _lowCoder[posState].Decode(rangeDecoder);\n    if(_choice2.Decode(rangeDecoder) == 0)\n      return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);\n    return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);\n  }\n};\n\n}\n\nclass CDecoder: \n  public ICompressCoder,\n  public ICompressSetDecoderProperties,\n  public ICompressSetInStream,\n  public ICompressSetOutStreamSize,\n  public ISequentialInStream,\n  public CMyUnknownImp\n{\n  CLZOutWindow _outWindowStream;\n  NRangeCoder::CDecoder _rangeDecoder;\n\n  CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax];\n  CMyBitDecoder _isRep[kNumStates];\n  CMyBitDecoder _isRepG0[kNumStates];\n  CMyBitDecoder _isRepG1[kNumStates];\n  CMyBitDecoder _isRepG2[kNumStates];\n  CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax];\n\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];\n\n  CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex];\n  NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;\n  \n  NLength::CDecoder _lenDecoder;\n  NLength::CDecoder _repMatchLenDecoder;\n\n  CLiteralDecoder _literalDecoder;\n\n  UInt32 _dictionarySizeCheck;\n  \n  UInt32 _posStateMask;\n\n  ///////////////////\n  // State\n  UInt64 _outSize;\n  UInt64 _nowPos64;\n  UInt32 _reps[4];\n  CState _state;\n  bool _previousIsMatch;\n  Int32 _remainLen; // -1 means end of stream.\n\n\n  HRESULT CodeSpec(Byte *buffer, UInt32 size);\npublic:\n  MY_UNKNOWN_IMP4(\n      ICompressSetDecoderProperties, \n      ICompressSetInStream, \n      ICompressSetOutStreamSize, \n      ISequentialInStream)\n\n  void Init();\n  void ReleaseStreams()\n  {\n    _outWindowStream.ReleaseStream();\n    _rangeDecoder.ReleaseStream();\n  }\n\n  class CDecoderFlusher\n  {\n    CDecoder *_decoder;\n  public:\n    bool NeedFlush;\n    CDecoderFlusher(CDecoder *decoder): \n          _decoder(decoder), NeedFlush(true) {}\n    ~CDecoderFlusher() \n    { \n      if (NeedFlush)\n        _decoder->Flush();\n      _decoder->ReleaseStreams(); \n    }\n  };\n\n  HRESULT Flush() {  return _outWindowStream.Flush(); }  \n\n  STDMETHOD(CodeReal)(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\n      ICompressProgressInfo *progress);\n  \n  STDMETHOD(Code)(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\n      ICompressProgressInfo *progress);\n\n  // ICompressSetDecoderProperties\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream);\n\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\n\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream);\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);\n\n  virtual ~CDecoder() {}\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA/LZMAEncoder.cpp",
    "content": "// LZMA/Encoder.cpp\n\n#include \"StdAfx.h\"\n\n#include \"../../../Common/Defs.h\"\n\n#include \"LZMAEncoder.h\"\n\n// for minimal compressing code size define these:\n// #define COMPRESS_MF_BT\n// #define COMPRESS_MF_BT4\n\n#if !defined(COMPRESS_MF_BT) && !defined(COMPRESS_MF_PAT) && !defined(COMPRESS_MF_HC)\n#define COMPRESS_MF_BT\n#define COMPRESS_MF_PAT\n#define COMPRESS_MF_HC\n#endif\n\n#ifdef COMPRESS_MF_BT\n#if !defined(COMPRESS_MF_BT2) && !defined(COMPRESS_MF_BT3) && !defined(COMPRESS_MF_BT4) && !defined(COMPRESS_MF_BT4B)\n#define COMPRESS_MF_BT2\n#define COMPRESS_MF_BT3\n#define COMPRESS_MF_BT4\n#define COMPRESS_MF_BT4B\n#endif\n#ifdef COMPRESS_MF_BT2\n#include \"../LZ/BinTree/BinTree2.h\"\n#endif\n#ifdef COMPRESS_MF_BT3\n#include \"../LZ/BinTree/BinTree3.h\"\n#endif\n#ifdef COMPRESS_MF_BT4\n#include \"../LZ/BinTree/BinTree4.h\"\n#endif\n#ifdef COMPRESS_MF_BT4B\n#include \"../LZ/BinTree/BinTree4b.h\"\n#endif\n#endif\n\n#ifdef COMPRESS_MF_PAT\n#include \"../LZ/Patricia/Pat2.h\"\n#include \"../LZ/Patricia/Pat2H.h\"\n#include \"../LZ/Patricia/Pat3H.h\"\n#include \"../LZ/Patricia/Pat4H.h\"\n#include \"../LZ/Patricia/Pat2R.h\"\n#endif\n\n#ifdef COMPRESS_MF_HC\n#include \"../LZ/HashChain/HC3.h\"\n#include \"../LZ/HashChain/HC4.h\"\n#endif\n\n#ifdef COMPRESS_MF_MT\n#include \"../LZ/MT/MT.h\"\n#endif\n\nnamespace NCompress {\nnamespace NLZMA {\n\nconst int kDefaultDictionaryLogSize = 20;\nconst UInt32 kNumFastBytesDefault = 0x20;\n\nenum \n{\n  kBT2,\n  kBT3,\n  kBT4,\n  kBT4B,\n  kPat2,\n  kPat2H,\n  kPat3H,\n  kPat4H,\n  kPat2R,\n  kHC3,\n  kHC4\n};\n\nstatic const wchar_t *kMatchFinderIDs[] = \n{\n  L\"BT2\",\n  L\"BT3\",\n  L\"BT4\",\n  L\"BT4B\",\n  L\"PAT2\",\n  L\"PAT2H\",\n  L\"PAT3H\",\n  L\"PAT4H\",\n  L\"PAT2R\",\n  L\"HC3\",\n  L\"HC4\"\n};\n\nByte g_FastPos[1024];\n\nclass CFastPosInit\n{\npublic:\n  CFastPosInit() { Init(); }\n  void Init()\n  {\n    const Byte kFastSlots = 20;\n    int c = 2;\n    g_FastPos[0] = 0;\n    g_FastPos[1] = 1;\n\n    for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)\n    {\n      UInt32 k = (1 << ((slotFast >> 1) - 1));\n      for (UInt32 j = 0; j < k; j++, c++)\n        g_FastPos[c] = slotFast;\n    }\n  }\n} g_FastPosInit;\n\n\nvoid CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol)\n{\n  UInt32 context = 1;\n  for (int i = 7; i >= 0; i--)\n  {\n    UInt32 bit = (symbol >> i) & 1;\n    UInt32 state = context;\n    _encoders[state].Encode(rangeEncoder, bit);\n    context = (context << 1) | bit;\n  }\n}\n\nvoid CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, \n    Byte matchByte, Byte symbol)\n{\n  UInt32 context = 1;\n  bool same = true;\n  for (int i = 7; i >= 0; i--)\n  {\n    UInt32 bit = (symbol >> i) & 1;\n    UInt32 state = context;\n    if (same)\n    {\n      UInt32 matchBit = (matchByte >> i) & 1;\n      state += (1 + matchBit) << 8;\n      same = (matchBit == bit);\n    }\n    _encoders[state].Encode(rangeEncoder, bit);\n    context = (context << 1) | bit;\n  }\n}\n\nUInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const\n{\n  UInt32 price = 0;\n  UInt32 context = 1;\n  int i = 7;\n  if (matchMode)\n  {\n    for (; i >= 0; i--)\n    {\n      UInt32 matchBit = (matchByte >> i) & 1;\n      UInt32 bit = (symbol >> i) & 1;\n      price += _encoders[((1 + matchBit) << 8) + context].GetPrice(bit);\n      context = (context << 1) | bit;\n      if (matchBit != bit)\n      {\n        i--;\n        break;\n      }\n    }\n  }\n  for (; i >= 0; i--)\n  {\n    UInt32 bit = (symbol >> i) & 1;\n    price += _encoders[context].GetPrice(bit);\n    context = (context << 1) | bit;\n  }\n  return price;\n};\n\n\nnamespace NLength {\n\nvoid CEncoder::Init(UInt32 numPosStates)\n{\n  _choice.Init();\n  for (UInt32 posState = 0; posState < numPosStates; posState++)\n  {\n    _lowCoder[posState].Init();\n    _midCoder[posState].Init();\n  }\n  _choice2.Init();\n  _highCoder.Init();\n}\n\nvoid CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\n{\n  if(symbol < kNumLowSymbols)\n  {\n    _choice.Encode(rangeEncoder, 0);\n    _lowCoder[posState].Encode(rangeEncoder, symbol);\n  }\n  else\n  {\n    symbol -= kNumLowSymbols;\n    _choice.Encode(rangeEncoder, 1);\n    if(symbol < kNumMidSymbols)\n    {\n      _choice2.Encode(rangeEncoder, 0);\n      _midCoder[posState].Encode(rangeEncoder, symbol);\n    }\n    else\n    {\n      _choice2.Encode(rangeEncoder, 1);\n      _highCoder.Encode(rangeEncoder, symbol - kNumMidSymbols);\n    }\n  }\n}\n\nUInt32 CEncoder::GetPrice(UInt32 symbol, UInt32 posState) const\n{\n  UInt32 price = 0;\n  if(symbol < kNumLowSymbols)\n  {\n    price += _choice.GetPrice(0);\n    price += _lowCoder[posState].GetPrice(symbol);\n  }\n  else\n  {\n    symbol -= kNumLowSymbols;\n    price += _choice.GetPrice(1);\n    if(symbol < kNumMidSymbols)\n    {\n      price += _choice2.GetPrice(0);\n      price += _midCoder[posState].GetPrice(symbol);\n    }\n    else\n    {\n      price += _choice2.GetPrice(1);\n      price += _highCoder.GetPrice(symbol - kNumMidSymbols);\n    }\n  }\n  return price;\n}\n\n}\nCEncoder::CEncoder():\n  _numFastBytes(kNumFastBytesDefault),\n  _distTableSize(kDefaultDictionaryLogSize * 2),\n  _posStateBits(2),\n  _posStateMask(4 - 1),\n  _numLiteralPosStateBits(0),\n  _numLiteralContextBits(3),\n  _dictionarySize(1 << kDefaultDictionaryLogSize),\n  _dictionarySizePrev(UInt32(-1)),\n  _numFastBytesPrev(UInt32(-1)),\n  _matchFinderIndex(kBT4),\n   #ifdef COMPRESS_MF_MT\n  _multiThread(false),\n   #endif\n  _writeEndMark(false)\n{\n  _maxMode = false;\n  _fastMode = false;\n}\n\nHRESULT CEncoder::Create()\n{\n  if (!_rangeEncoder.Create(1 << 20))\n    return E_OUTOFMEMORY;\n  if (!_matchFinder)\n  {\n    switch(_matchFinderIndex)\n    {\n      #ifdef COMPRESS_MF_BT\n      #ifdef COMPRESS_MF_BT2\n      case kBT2:\n        _matchFinder = new NBT2::CMatchFinderBinTree;\n        break;\n      #endif\n      #ifdef COMPRESS_MF_BT3\n      case kBT3:\n        _matchFinder = new NBT3::CMatchFinderBinTree;\n        break;\n      #endif\n      #ifdef COMPRESS_MF_BT4\n      case kBT4:\n        _matchFinder = new NBT4::CMatchFinderBinTree;\n        break;\n      #endif\n      #ifdef COMPRESS_MF_BT4B\n      case kBT4B:\n        _matchFinder = new NBT4B::CMatchFinderBinTree;\n        break;\n      #endif\n      #endif\n      \n      #ifdef COMPRESS_MF_PAT\n      case kPat2:\n        _matchFinder = new NPat2::CPatricia;\n        break;\n      case kPat2H:\n        _matchFinder = new NPat2H::CPatricia;\n        break;\n      case kPat3H:\n        _matchFinder = new NPat3H::CPatricia;\n        break;\n      case kPat4H:\n        _matchFinder = new NPat4H::CPatricia;\n        break;\n      case kPat2R:\n        _matchFinder = new NPat2R::CPatricia;\n        break;\n      #endif\n\n      #ifdef COMPRESS_MF_HC\n      case kHC3:\n        _matchFinder = new NHC3::CMatchFinderHC;\n        break;\n      case kHC4:\n        _matchFinder = new NHC4::CMatchFinderHC;\n        break;\n      #endif\n    }\n    #ifdef COMPRESS_MF_MT\n    if (_multiThread)\n    {\n      CMatchFinderMT *mfSpec = new CMatchFinderMT;\n      CMyComPtr<IMatchFinder> mf = mfSpec;\n      RINOK(mfSpec->SetMatchFinder(_matchFinder));\n      _matchFinder.Release();\n      _matchFinder = mf;\n    }\n    #endif\n  }\n  \n  if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))\n    return E_OUTOFMEMORY;\n\n  if (_dictionarySize == _dictionarySizePrev && _numFastBytesPrev == _numFastBytes)\n    return S_OK;\n  RINOK(_matchFinder->Create(_dictionarySize, kNumOpts, _numFastBytes, \n      kMatchMaxLen - _numFastBytes));\n  _dictionarySizePrev = _dictionarySize;\n  _numFastBytesPrev = _numFastBytes;\n  return S_OK;\n}\n\nstatic bool AreStringsEqual(const wchar_t *base, const wchar_t *testString)\n{\n  while (true)\n  {\n    wchar_t c = *testString;\n    if (c >= 'a' && c <= 'z')\n      c -= 0x20;\n    if (*base != c)\n      return false;\n    if (c == 0)\n      return true;\n    base++;\n    testString++;\n  }\n}\n\nstatic int FindMatchFinder(const wchar_t *s)\n{\n  for (int m = 0; m < (int)(sizeof(kMatchFinderIDs) / sizeof(kMatchFinderIDs[0])); m++)\n    if (AreStringsEqual(kMatchFinderIDs[m], s))\n      return m;\n  return -1;\n}\n\nSTDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, \n    const PROPVARIANT *properties, UInt32 numProperties)\n{\n  for (UInt32 i = 0; i < numProperties; i++)\n  {\n    const PROPVARIANT &prop = properties[i];\n    switch(propIDs[i])\n    {\n      case NCoderPropID::kNumFastBytes:\n      {\n        if (prop.vt != VT_UI4)\n          return E_INVALIDARG;\n        UInt32 numFastBytes = prop.ulVal;\n        if(numFastBytes < 2 || numFastBytes > kMatchMaxLen)\n          return E_INVALIDARG;\n        _numFastBytes = numFastBytes;\n        break;\n      }\n      case NCoderPropID::kAlgorithm:\n      {\n        if (prop.vt != VT_UI4)\n          return E_INVALIDARG;\n        UInt32 maximize = prop.ulVal;\n        _fastMode = (maximize == 0); \n        _maxMode = (maximize >= 2);\n        break;\n      }\n      case NCoderPropID::kMatchFinder:\n      {\n        if (prop.vt != VT_BSTR)\n          return E_INVALIDARG;\n        int matchFinderIndexPrev = _matchFinderIndex;\n        int m = FindMatchFinder(prop.bstrVal);\n        if (m < 0)\n          return E_INVALIDARG;\n        _matchFinderIndex = m;\n        if (!_matchFinder && matchFinderIndexPrev != _matchFinderIndex)\n        {\n          _dictionarySizePrev = UInt32(-1);\n          _matchFinder.Release();\n        }\n        break;\n      }\n      #ifdef COMPRESS_MF_MT\n      case NCoderPropID::kMultiThread:\n      {\n        if (prop.vt != VT_BOOL)\n          return E_INVALIDARG;\n        bool newMultiThread = (prop.boolVal == VARIANT_TRUE);\n        if (newMultiThread != _multiThread)\n        {\n          _dictionarySizePrev = UInt32(-1);\n          _matchFinder.Release();\n        }\n        _multiThread = newMultiThread;\n        break;\n      }\n      #endif\n      case NCoderPropID::kDictionarySize:\n      {\n        const int kDicLogSizeMaxCompress = 28;\n        if (prop.vt != VT_UI4)\n          return E_INVALIDARG;\n        UInt32 dictionarySize = prop.ulVal;\n        if (dictionarySize < UInt32(1 << kDicLogSizeMin) ||\n            dictionarySize > UInt32(1 << kDicLogSizeMaxCompress))\n          return E_INVALIDARG;\n        _dictionarySize = dictionarySize;\n        UInt32 dicLogSize;\n        for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)\n          if (dictionarySize <= (UInt32(1) << dicLogSize))\n            break;\n        _distTableSize = dicLogSize * 2;\n        break;\n      }\n      case NCoderPropID::kPosStateBits:\n      {\n        if (prop.vt != VT_UI4)\n          return E_INVALIDARG;\n        UInt32 value = prop.ulVal;\n        if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax)\n          return E_INVALIDARG;\n        _posStateBits = value;\n        _posStateMask = (1 << _posStateBits) - 1;\n        break;\n      }\n      case NCoderPropID::kLitPosBits:\n      {\n        if (prop.vt != VT_UI4)\n          return E_INVALIDARG;\n        UInt32 value = prop.ulVal;\n        if (value > (UInt32)kNumLitPosStatesBitsEncodingMax)\n          return E_INVALIDARG;\n        _numLiteralPosStateBits = value;\n        break;\n      }\n      case NCoderPropID::kLitContextBits:\n      {\n        if (prop.vt != VT_UI4)\n          return E_INVALIDARG;\n        UInt32 value = prop.ulVal;\n        if (value > (UInt32)kNumLitContextBitsMax)\n          return E_INVALIDARG;\n        _numLiteralContextBits = value;\n        break;\n      }\n      case NCoderPropID::kEndMarker:\n      {\n        if (prop.vt != VT_BOOL)\n          return E_INVALIDARG;\n        SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE);\n        break;\n      }\n      default:\n        return E_INVALIDARG;\n    }\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)\n{ \n  Byte firstByte = (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits;\n  RINOK(outStream->Write(&firstByte, sizeof(firstByte), NULL));\n  for (int i = 0; i < 4; i++)\n  {\n    Byte b = Byte(_dictionarySize >> (8 * i));\n    RINOK(outStream->Write(&b, sizeof(b), NULL));\n  }\n  return S_OK;\n}\n\nSTDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream)\n{\n  _rangeEncoder.SetStream(outStream);\n  return S_OK;\n}\n\nHRESULT CEncoder::Init()\n{\n  CBaseState::Init();\n\n  // RINOK(_matchFinder->Init(inStream));\n  _rangeEncoder.Init();\n\n  for(int i = 0; i < kNumStates; i++)\n  {\n    for (UInt32 j = 0; j <= _posStateMask; j++)\n    {\n      _isMatch[i][j].Init();\n      _isRep0Long[i][j].Init();\n    }\n    _isRep[i].Init();\n    _isRepG0[i].Init();\n    _isRepG1[i].Init();\n    _isRepG2[i].Init();\n  }\n\n  _literalEncoder.Init();\n\n  // _repMatchLenEncoder.Init();\n  \n  {\n    for(UInt32 i = 0; i < kNumLenToPosStates; i++)\n      _posSlotEncoder[i].Init();\n  }\n  {\n    for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)\n      _posEncoders[i].Init();\n  }\n\n  _lenEncoder.Init(1 << _posStateBits);\n  _repMatchLenEncoder.Init(1 << _posStateBits);\n\n  _posAlignEncoder.Init();\n\n  _longestMatchWasFound = false;\n  _optimumEndIndex = 0;\n  _optimumCurrentIndex = 0;\n  _additionalOffset = 0;\n\n  return S_OK;\n}\n\nHRESULT CEncoder::MovePos(UInt32 num)\n{\n  for (;num > 0; num--)\n  {\n    _matchFinder->DummyLongestMatch();\n    RINOK(_matchFinder->MovePos());\n    _additionalOffset++;\n  }\n  return S_OK;\n}\n\nUInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur)\n{\n  _optimumEndIndex = cur;\n  UInt32 posMem = _optimum[cur].PosPrev;\n  UInt32 backMem = _optimum[cur].BackPrev;\n  do\n  {\n    if (_optimum[cur].Prev1IsChar)\n    {\n      _optimum[posMem].MakeAsChar();\n      _optimum[posMem].PosPrev = posMem - 1;\n      if (_optimum[cur].Prev2)\n      {\n        _optimum[posMem - 1].Prev1IsChar = false;\n        _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2;\n        _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2;\n      }\n    }\n    UInt32 posPrev = posMem;\n    UInt32 backCur = backMem;\n\n    backMem = _optimum[posPrev].BackPrev;\n    posMem = _optimum[posPrev].PosPrev;\n\n    _optimum[posPrev].BackPrev = backCur;\n    _optimum[posPrev].PosPrev = cur;\n    cur = posPrev;\n  }\n  while(cur > 0);\n  backRes = _optimum[0].BackPrev;\n  _optimumCurrentIndex  = _optimum[0].PosPrev;\n  return _optimumCurrentIndex; \n}\n\n/*\ninline UInt32 GetMatchLen(const Byte *data, UInt32 back, UInt32 limit)\n{  \n  back++;\n  for(UInt32 i = 0; i < limit && data[i] == data[i - back]; i++);\n  return i;\n}\n*/\n\nHRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\n{\n  if(_optimumEndIndex != _optimumCurrentIndex)\n  {\n    lenRes = _optimum[_optimumCurrentIndex].PosPrev - _optimumCurrentIndex;\n    backRes = _optimum[_optimumCurrentIndex].BackPrev;\n    _optimumCurrentIndex = _optimum[_optimumCurrentIndex].PosPrev;\n    return S_OK;\n  }\n  _optimumCurrentIndex = 0;\n  _optimumEndIndex = 0; // test it;\n  \n  UInt32 lenMain;\n  if (!_longestMatchWasFound)\n  {\n    RINOK(ReadMatchDistances(lenMain));\n  }\n  else\n  {\n    lenMain = _longestMatchLength;\n    _longestMatchWasFound = false;\n  }\n\n\n  UInt32 reps[kNumRepDistances];\n  UInt32 repLens[kNumRepDistances];\n  UInt32 repMaxIndex = 0;\n  UInt32 i;\n  for(i = 0; i < kNumRepDistances; i++)\n  {\n    reps[i] = _repDistances[i];\n    repLens[i] = _matchFinder->GetMatchLen(0 - 1, reps[i], kMatchMaxLen);\n    if (i == 0 || repLens[i] > repLens[repMaxIndex])\n      repMaxIndex = i;\n  }\n  if(repLens[repMaxIndex] > _numFastBytes)\n  {\n    backRes = repMaxIndex;\n    lenRes = repLens[repMaxIndex];\n    MovePos(lenRes - 1);\n    return S_OK;\n  }\n\n  if(lenMain > _numFastBytes)\n  {\n    UInt32 backMain = (lenMain < _numFastBytes) ? _matchDistances[lenMain] :\n        _matchDistances[_numFastBytes];\n    backRes = backMain + kNumRepDistances; \n    MovePos(lenMain - 1);\n    lenRes = lenMain;\n    return S_OK;\n  }\n  Byte currentByte = _matchFinder->GetIndexByte(0 - 1);\n\n  _optimum[0].State = _state;\n\n  Byte matchByte;\n  \n  matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - 1);\n\n  UInt32 posState = (position & _posStateMask);\n\n  _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice(0) + \n      _literalEncoder.GetPrice(position, _previousByte, _peviousIsMatch, matchByte, currentByte);\n  _optimum[1].MakeAsChar();\n\n  _optimum[1].PosPrev = 0;\n\n  for (i = 0; i < kNumRepDistances; i++)\n    _optimum[0].Backs[i] = reps[i];\n\n  UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice(1);\n  UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice(1);\n\n  if(matchByte == currentByte)\n  {\n    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState);\n    if(shortRepPrice < _optimum[1].Price)\n    {\n      _optimum[1].Price = shortRepPrice;\n      _optimum[1].MakeAsShortRep();\n    }\n  }\n  if(lenMain < 2)\n  {\n    backRes = _optimum[1].BackPrev;\n    lenRes = 1;\n    return S_OK;\n  }\n\n  \n  UInt32 normalMatchPrice = matchPrice + \n      _isRep[_state.Index].GetPrice(0);\n\n  if (lenMain <= repLens[repMaxIndex])\n    lenMain = 0;\n\n  UInt32 len;\n  for(len = 2; len <= lenMain; len++)\n  {\n    _optimum[len].PosPrev = 0;\n    _optimum[len].BackPrev = _matchDistances[len] + kNumRepDistances;\n    _optimum[len].Price = normalMatchPrice + \n        GetPosLenPrice(_matchDistances[len], len, posState);\n    _optimum[len].Prev1IsChar = false;\n  }\n\n  if (lenMain < repLens[repMaxIndex])\n    lenMain = repLens[repMaxIndex];\n\n  for (; len <= lenMain; len++)\n    _optimum[len].Price = kIfinityPrice;\n\n  for(i = 0; i < kNumRepDistances; i++)\n  {\n    UInt32 repLen = repLens[i];\n    for(UInt32 lenTest = 2; lenTest <= repLen; lenTest++)\n    {\n      UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(i, lenTest, _state, posState);\n      COptimal &optimum = _optimum[lenTest];\n      if (curAndLenPrice < optimum.Price) \n      {\n        optimum.Price = curAndLenPrice;\n        optimum.PosPrev = 0;\n        optimum.BackPrev = i;\n        optimum.Prev1IsChar = false;\n      }\n    }\n  }\n\n  UInt32 cur = 0;\n  UInt32 lenEnd = lenMain;\n\n  while(true)\n  {\n    cur++;\n    if(cur == lenEnd)\n    {\n      lenRes = Backward(backRes, cur);\n      return S_OK;\n    }\n    position++;\n    UInt32 posPrev = _optimum[cur].PosPrev;\n    CState state;\n    if (_optimum[cur].Prev1IsChar)\n    {\n      posPrev--;\n      if (_optimum[cur].Prev2)\n      {\n        state = _optimum[_optimum[cur].PosPrev2].State;\n        if (_optimum[cur].BackPrev2 < kNumRepDistances)\n          state.UpdateRep();\n        else\n          state.UpdateMatch();\n      }\n      else\n        state = _optimum[posPrev].State;\n      state.UpdateChar();\n    }\n    else\n      state = _optimum[posPrev].State;\n    bool prevWasMatch;\n    if (posPrev == cur - 1)\n    {\n      if (_optimum[cur].IsShortRep())\n      {\n        prevWasMatch = true;\n        state.UpdateShortRep();\n      }\n      else\n      {\n        prevWasMatch = false;\n        state.UpdateChar();\n      }\n      /*\n      if (_optimum[cur].Prev1IsChar)\n        for(int i = 0; i < kNumRepDistances; i++)\n          reps[i] = _optimum[posPrev].Backs[i];\n      */\n    }\n    else\n    {\n      prevWasMatch = true;\n      UInt32 pos;\n      if (_optimum[cur].Prev1IsChar && _optimum[cur].Prev2)\n      {\n        posPrev = _optimum[cur].PosPrev2;\n        pos = _optimum[cur].BackPrev2;\n        state.UpdateRep();\n      }\n      else\n      {\n        pos = _optimum[cur].BackPrev;\n        if (pos < kNumRepDistances)\n          state.UpdateRep();\n        else\n          state.UpdateMatch();\n      }\n      if (pos < kNumRepDistances)\n      {\n        reps[0] = _optimum[posPrev].Backs[pos];\n    \t\tUInt32 i;\n        for(i = 1; i <= pos; i++)\n          reps[i] = _optimum[posPrev].Backs[i - 1];\n        for(; i < kNumRepDistances; i++)\n          reps[i] = _optimum[posPrev].Backs[i];\n      }\n      else\n      {\n        reps[0] = (pos - kNumRepDistances);\n        for(UInt32 i = 1; i < kNumRepDistances; i++)\n          reps[i] = _optimum[posPrev].Backs[i - 1];\n      }\n    }\n    _optimum[cur].State = state;\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\n      _optimum[cur].Backs[i] = reps[i];\n    UInt32 newLen;\n    RINOK(ReadMatchDistances(newLen));\n    if(newLen > _numFastBytes)\n    {\n      _longestMatchLength = newLen;\n      _longestMatchWasFound = true;\n      lenRes = Backward(backRes, cur);\n      return S_OK;\n    }\n    UInt32 curPrice = _optimum[cur].Price; \n    // Byte currentByte  = _matchFinder->GetIndexByte(0 - 1);\n    // Byte matchByte = _matchFinder->GetIndexByte(0 - reps[0] - 1 - 1);\n    const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;\n    Byte currentByte = *data;\n    Byte matchByte = data[(size_t)0 - reps[0] - 1];\n\n    UInt32 posState = (position & _posStateMask);\n\n    UInt32 curAnd1Price = curPrice +\n        _isMatch[state.Index][posState].GetPrice(0) +\n        _literalEncoder.GetPrice(position, data[(size_t)0 - 1], prevWasMatch, matchByte, currentByte);\n\n    COptimal &nextOptimum = _optimum[cur + 1];\n\n    bool nextIsChar = false;\n    if (curAnd1Price < nextOptimum.Price) \n    {\n      nextOptimum.Price = curAnd1Price;\n      nextOptimum.PosPrev = cur;\n      nextOptimum.MakeAsChar();\n      nextIsChar = true;\n    }\n\n    UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice(1);\n    UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice(1);\n    \n    if(matchByte == currentByte &&\n        !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))\n    {\n      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState);\n      if(shortRepPrice <= nextOptimum.Price)\n      {\n        nextOptimum.Price = shortRepPrice;\n        nextOptimum.PosPrev = cur;\n        nextOptimum.MakeAsShortRep();\n        // nextIsChar = false;\n      }\n    }\n    /*\n    if(newLen == 2 && _matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ?\n      continue;\n    */\n\n    UInt32 numAvailableBytes = _matchFinder->GetNumAvailableBytes() + 1;\n    numAvailableBytes = MyMin(kNumOpts - 1 - cur, numAvailableBytes);\n\n    if (numAvailableBytes < 2)\n      continue;\n    if (numAvailableBytes > _numFastBytes)\n      numAvailableBytes = _numFastBytes;\n    if (numAvailableBytes >= 3 && !nextIsChar)\n    {\n      UInt32 backOffset = reps[0] + 1;\n      UInt32 temp;\n      for (temp = 1; temp < numAvailableBytes; temp++)\n        if (data[temp] != data[(size_t)temp - backOffset])\n          break;\n      UInt32 lenTest2 = temp - 1;\n      if (lenTest2 >= 2)\n      {\n        CState state2 = state;\n        state2.UpdateChar();\n        UInt32 posStateNext = (position + 1) & _posStateMask;\n        UInt32 nextRepMatchPrice = curAnd1Price + \n            _isMatch[state2.Index][posStateNext].GetPrice(1) +\n            _isRep[state2.Index].GetPrice(1);\n        // for (; lenTest2 >= 2; lenTest2--)\n        {\n          while(lenEnd < cur + 1 + lenTest2)\n            _optimum[++lenEnd].Price = kIfinityPrice;\n          UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\n              0, lenTest2, state2, posStateNext);\n          COptimal &optimum = _optimum[cur + 1 + lenTest2];\n          if (curAndLenPrice < optimum.Price) \n          {\n            optimum.Price = curAndLenPrice;\n            optimum.PosPrev = cur + 1;\n            optimum.BackPrev = 0;\n            optimum.Prev1IsChar = true;\n            optimum.Prev2 = false;\n          }\n        }\n      }\n    }\n    for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)\n    {\n      // UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;\n      UInt32 backOffset = reps[repIndex] + 1;\n      UInt32 lenTest;\n      for (lenTest = 0; lenTest < numAvailableBytes; lenTest++)\n        if (data[lenTest] != data[(size_t)lenTest - backOffset])\n          break;\n      for(; lenTest >= 2; lenTest--)\n      {\n        while(lenEnd < cur + lenTest)\n          _optimum[++lenEnd].Price = kIfinityPrice;\n        UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState);\n        COptimal &optimum = _optimum[cur + lenTest];\n        if (curAndLenPrice < optimum.Price) \n        {\n          optimum.Price = curAndLenPrice;\n          optimum.PosPrev = cur;\n          optimum.BackPrev = repIndex;\n          optimum.Prev1IsChar = false;\n        }\n\n        /*\n        if (_maxMode)\n        {\n          UInt32 temp;\n          for (temp = lenTest + 1; temp < numAvailableBytes; temp++)\n            if (data[temp] != data[(size_t)temp - backOffset])\n              break;\n          UInt32 lenTest2 = temp - (lenTest + 1);\n          if (lenTest2 >= 2)\n          {\n            CState state2 = state;\n            state2.UpdateRep();\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\n            UInt32 curAndLenCharPrice = curAndLenPrice + \n                _isMatch[state2.Index][posStateNext].GetPrice(0) +\n                _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1], \n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\n            state2.UpdateChar();\n            posStateNext = (position + lenTest + 1) & _posStateMask;\n            UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice(1);\n            UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice(1);\n            \n            // for(; lenTest2 >= 2; lenTest2--)\n            {\n              UInt32 offset = lenTest + 1 + lenTest2;\n              while(lenEnd < cur + offset)\n                _optimum[++lenEnd].Price = kIfinityPrice;\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\n                  0, lenTest2, state2, posStateNext);\n              COptimal &optimum = _optimum[cur + offset];\n              if (curAndLenPrice < optimum.Price) \n              {\n                optimum.Price = curAndLenPrice;\n                optimum.PosPrev = cur + lenTest + 1;\n                optimum.BackPrev = 0;\n                optimum.Prev1IsChar = true;\n                optimum.Prev2 = true;\n                optimum.PosPrev2 = cur;\n                optimum.BackPrev2 = repIndex;\n              }\n            }\n          }\n        }\n        */\n      }\n    }\n    \n    //    for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)\n    if (newLen > numAvailableBytes)\n      newLen = numAvailableBytes;\n    if (newLen >= 2)\n    {\n      if (newLen == 2 && _matchDistances[2] >= 0x80)\n        continue;\n      UInt32 normalMatchPrice = matchPrice + \n        _isRep[state.Index].GetPrice(0);\n      while(lenEnd < cur + newLen)\n        _optimum[++lenEnd].Price = kIfinityPrice;\n\n      for(UInt32 lenTest = newLen; lenTest >= 2; lenTest--)\n      {\n        UInt32 curBack = _matchDistances[lenTest];\n        UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState);\n        COptimal &optimum = _optimum[cur + lenTest];\n        if (curAndLenPrice < optimum.Price) \n        {\n          optimum.Price = curAndLenPrice;\n          optimum.PosPrev = cur;\n          optimum.BackPrev = curBack + kNumRepDistances;\n          optimum.Prev1IsChar = false;\n        }\n\n        if (_maxMode)\n        {\n          UInt32 backOffset = curBack + 1;\n          UInt32 temp;\n          for (temp = lenTest + 1; temp < numAvailableBytes; temp++)\n            if (data[temp] != data[(size_t)temp - backOffset])\n              break;\n          UInt32 lenTest2 = temp - (lenTest + 1);\n          if (lenTest2 >= 2)\n          {\n            CState state2 = state;\n            state2.UpdateMatch();\n            UInt32 posStateNext = (position + lenTest) & _posStateMask;\n            UInt32 curAndLenCharPrice = curAndLenPrice + \n                _isMatch[state2.Index][posStateNext].GetPrice(0) +\n                _literalEncoder.GetPrice(position + lenTest, data[(size_t)lenTest - 1], \n                true, data[(size_t)lenTest - backOffset], data[lenTest]);\n            state2.UpdateChar();\n            posStateNext = (position + lenTest + 1) & _posStateMask;\n            UInt32 nextMatchPrice = curAndLenCharPrice + _isMatch[state2.Index][posStateNext].GetPrice(1);\n            UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2.Index].GetPrice(1);\n            \n            // for(; lenTest2 >= 2; lenTest2--)\n            {\n              UInt32 offset = lenTest + 1 + lenTest2;\n              while(lenEnd < cur + offset)\n                _optimum[++lenEnd].Price = kIfinityPrice;\n              UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(\n                  0, lenTest2, state2, posStateNext);\n              COptimal &optimum = _optimum[cur + offset];\n              if (curAndLenPrice < optimum.Price) \n              {\n                optimum.Price = curAndLenPrice;\n                optimum.PosPrev = cur + lenTest + 1;\n                optimum.BackPrev = 0;\n                optimum.Prev1IsChar = true;\n                optimum.Prev2 = true;\n                optimum.PosPrev2 = cur;\n                optimum.BackPrev2 = curBack + kNumRepDistances;\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}\n\nstatic inline bool ChangePair(UInt32 smallDist, UInt32 bigDist)\n{\n  const int kDif = 7;\n  return (smallDist < (UInt32(1) << (32-kDif)) && bigDist >= (smallDist << kDif));\n}\n\n\nHRESULT CEncoder::ReadMatchDistances(UInt32 &lenRes)\n{\n  lenRes = _matchFinder->GetLongestMatch(_matchDistances);\n  if (lenRes == _numFastBytes)\n    lenRes += _matchFinder->GetMatchLen(lenRes, _matchDistances[lenRes], \n        kMatchMaxLen - lenRes);\n  _additionalOffset++;\n  return _matchFinder->MovePos();\n}\n\nHRESULT CEncoder::GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes)\n{\n  UInt32 lenMain;\n  if (!_longestMatchWasFound)\n  {\n    RINOK(ReadMatchDistances(lenMain));\n  }\n  else\n  {\n    lenMain = _longestMatchLength;\n    _longestMatchWasFound = false;\n  }\n  UInt32 repLens[kNumRepDistances];\n  UInt32 repMaxIndex = 0;\n  for(UInt32 i = 0; i < kNumRepDistances; i++)\n  {\n    repLens[i] = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);\n    if (i == 0 || repLens[i] > repLens[repMaxIndex])\n      repMaxIndex = i;\n  }\n  if(repLens[repMaxIndex] >= _numFastBytes)\n  {\n    backRes = repMaxIndex;\n    lenRes = repLens[repMaxIndex];\n    MovePos(lenRes - 1);\n    return S_OK;\n  }\n  if(lenMain >= _numFastBytes)\n  {\n    backRes = _matchDistances[_numFastBytes] + kNumRepDistances; \n    MovePos(lenMain - 1);\n    lenRes = lenMain;\n    return S_OK;\n  }\n  while (lenMain > 2)\n  {\n    if (!ChangePair(_matchDistances[lenMain - 1], _matchDistances[lenMain]))\n      break;\n    lenMain--;\n  }\n  if (lenMain == 2 && _matchDistances[2] >= 0x80)\n    lenMain = 1;\n\n  UInt32 backMain = _matchDistances[lenMain];\n  if (repLens[repMaxIndex] >= 2)\n  {\n    if (repLens[repMaxIndex] + 1 >= lenMain || \n        repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1<<12)))\n    {\n      backRes = repMaxIndex;\n      lenRes = repLens[repMaxIndex];\n      MovePos(lenRes - 1);\n      return S_OK;\n    }\n  }\n  \n\n  if (lenMain >= 2)\n  {\n    RINOK(ReadMatchDistances(_longestMatchLength));\n    if (_longestMatchLength >= 2 &&\n      (\n        (_longestMatchLength >= lenMain && \n          _matchDistances[lenMain] < backMain) || \n        _longestMatchLength == lenMain + 1 && \n          !ChangePair(backMain, _matchDistances[_longestMatchLength]) ||\n        _longestMatchLength > lenMain + 1 ||\n        _longestMatchLength + 1 >= lenMain && \n          ChangePair(_matchDistances[lenMain - 1], backMain)\n      )\n      )\n    {\n      _longestMatchWasFound = true;\n      backRes = UInt32(-1);\n      lenRes = 1;\n      return S_OK;\n    }\n    for(UInt32 i = 0; i < kNumRepDistances; i++)\n    {\n      UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, _repDistances[i], kMatchMaxLen);\n      if (repLen >= 2 && repLen + 1 >= lenMain)\n      {\n        _longestMatchWasFound = true;\n        backRes = UInt32(-1);\n        lenRes = 1;\n        return S_OK;\n      }\n    }\n    backRes = backMain + kNumRepDistances; \n    MovePos(lenMain - 2);\n    lenRes = lenMain;\n    return S_OK;\n  }\n  backRes = UInt32(-1);\n  lenRes = 1;\n  return S_OK;\n}\n\nSTDMETHODIMP CEncoder::InitMatchFinder(IMatchFinder *matchFinder)\n{\n  _matchFinder = matchFinder;\n  return S_OK;\n}\n\nHRESULT CEncoder::Flush(UInt32 nowPos)\n{\n  ReleaseMFStream();\n  WriteEndMarker(nowPos & _posStateMask);\n  _rangeEncoder.FlushData();\n  return _rangeEncoder.FlushStream();\n}\n\nvoid CEncoder::WriteEndMarker(UInt32 posState)\n{\n  // This function for writing End Mark for stream version of LZMA. \n  // In current version this feature is not used.\n  if (!_writeEndMark)\n    return;\n\n  _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\n  _isRep[_state.Index].Encode(&_rangeEncoder, 0);\n  _state.UpdateMatch();\n  UInt32 len = kMatchMinLen; // kMatchMaxLen;\n  _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\n  UInt32 posSlot = (1 << kNumPosSlotBits)  - 1;\n  UInt32 lenToPosState = GetLenToPosState(len);\n  _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\n  UInt32 footerBits = 30;\n  UInt32 posReduced = (UInt32(1) << footerBits) - 1;\n  _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\n  _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\n}\n\nHRESULT CEncoder::CodeReal(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, \n      const UInt64 *inSize, const UInt64 *outSize,\n      ICompressProgressInfo *progress)\n{\n  _needReleaseMFStream = false;\n  CCoderReleaser coderReleaser(this);\n  RINOK(SetStreams(inStream, outStream, inSize, outSize));\n  while(true)\n  {\n    UInt64 processedInSize;\n    UInt64 processedOutSize;\n    Int32 finished;\n    RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished));\n    if (finished != 0)\n      return S_OK;\n    if (progress != 0)\n    {\n      RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize));\n    }\n  }\n}\n\nHRESULT CEncoder::SetStreams(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, \n      const UInt64 *inSize, const UInt64 *outSize)\n{\n  _inStream = inStream;\n  _finished = false;\n  RINOK(Create());\n  RINOK(SetOutStream(outStream));\n  RINOK(Init());\n  \n  // CCoderReleaser releaser(this);\n\n  /*\n  if (_matchFinder->GetNumAvailableBytes() == 0)\n    return Flush();\n  */\n\n  if (!_fastMode)\n  {\n    FillPosSlotPrices();\n    FillDistancesPrices();\n    FillAlignPrices();\n  }\n\n  _lenEncoder.SetTableSize(_numFastBytes);\n  _lenEncoder.UpdateTables(1 << _posStateBits);\n  _repMatchLenEncoder.SetTableSize(_numFastBytes);\n  _repMatchLenEncoder.UpdateTables(1 << _posStateBits);\n\n  lastPosSlotFillingPos = 0;\n  nowPos64 = 0;\n  return S_OK;\n}\n\nHRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished)\n{\n  if (_inStream != 0)\n  {\n    RINOK(_matchFinder->Init(_inStream));\n    _needReleaseMFStream = true;\n    _inStream = 0;\n  }\n\n\n  *finished = 1;\n  if (_finished)\n    return S_OK;\n  _finished = true;\n\n\n  UInt64 progressPosValuePrev = nowPos64;\n  if (nowPos64 == 0)\n  {\n    if (_matchFinder->GetNumAvailableBytes() == 0)\n      return Flush(UInt32(nowPos64));\n    UInt32 len; // it's not used\n    RINOK(ReadMatchDistances(len));\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\n    _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\n    _state.UpdateChar();\n    Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\n    _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte);\n    _previousByte = curByte;\n    _additionalOffset--;\n    nowPos64++;\n  }\n  if (_matchFinder->GetNumAvailableBytes() == 0)\n    return Flush(UInt32(nowPos64));\n  while(true)\n  {\n    #ifdef _NO_EXCEPTIONS\n    if (_rangeEncoder.Stream.ErrorCode != S_OK)\n      return _rangeEncoder.Stream.ErrorCode;\n    #endif\n    UInt32 pos;\n    UInt32 posState = UInt32(nowPos64) & _posStateMask;\n\n    UInt32 len;\n    HRESULT result;\n    if (_fastMode)\n      result = GetOptimumFast(UInt32(nowPos64), pos, len);\n    else\n      result = GetOptimum(UInt32(nowPos64), pos, len);\n    RINOK(result);\n\n    if(len == 1 && pos == 0xFFFFFFFF)\n    {\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0);\n      _state.UpdateChar();\n      Byte curByte = _matchFinder->GetIndexByte(0 - _additionalOffset);\n      CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte);\n      if(_peviousIsMatch)\n      {\n        Byte matchByte = _matchFinder->GetIndexByte(0 - _repDistances[0] - 1 - _additionalOffset);\n        subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte);\n      }\n      else\n        subCoder->Encode(&_rangeEncoder, curByte);\n      _previousByte = curByte;\n      _peviousIsMatch = false;\n    }\n    else\n    {\n      _peviousIsMatch = true;\n      _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1);\n      if(pos < kNumRepDistances)\n      {\n        _isRep[_state.Index].Encode(&_rangeEncoder, 1);\n        if(pos == 0)\n        {\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 0);\n          if(len == 1)\n            _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 0);\n          else\n            _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, 1);\n        }\n        else\n        {\n          _isRepG0[_state.Index].Encode(&_rangeEncoder, 1);\n          if (pos == 1)\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 0);\n          else\n          {\n            _isRepG1[_state.Index].Encode(&_rangeEncoder, 1);\n            _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2);\n          }\n        }\n        if (len == 1)\n          _state.UpdateShortRep();\n        else\n        {\n          _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\n          _state.UpdateRep();\n        }\n\n\n        UInt32 distance = _repDistances[pos];\n        if (pos != 0)\n        {\n          for(UInt32 i = pos; i >= 1; i--)\n            _repDistances[i] = _repDistances[i - 1];\n          _repDistances[0] = distance;\n        }\n      }\n      else\n      {\n        _isRep[_state.Index].Encode(&_rangeEncoder, 0);\n        _state.UpdateMatch();\n        _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState);\n        pos -= kNumRepDistances;\n        UInt32 posSlot = GetPosSlot(pos);\n        UInt32 lenToPosState = GetLenToPosState(len);\n        _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot);\n        \n        if (posSlot >= kStartPosModelIndex)\n        {\n          UInt32 footerBits = ((posSlot >> 1) - 1);\n          UInt32 base = ((2 | (posSlot & 1)) << footerBits);\n          UInt32 posReduced = pos - base;\n\n          if (posSlot < kEndPosModelIndex)\n            NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1, \n                &_rangeEncoder, footerBits, posReduced);\n          else\n          {\n            _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits);\n            _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask);\n            if (!_fastMode)\n              if (--_alignPriceCount == 0)\n                FillAlignPrices();\n          }\n        }\n        UInt32 distance = pos;\n        for(UInt32 i = kNumRepDistances - 1; i >= 1; i--)\n          _repDistances[i] = _repDistances[i - 1];\n        _repDistances[0] = distance;\n      }\n      _previousByte = _matchFinder->GetIndexByte(len - 1 - _additionalOffset);\n    }\n    _additionalOffset -= len;\n    nowPos64 += len;\n    if (!_fastMode)\n      if (nowPos64 - lastPosSlotFillingPos >= (1 << 9))\n      {\n        FillPosSlotPrices();\n        FillDistancesPrices();\n        lastPosSlotFillingPos = nowPos64;\n      }\n    if (_additionalOffset == 0)\n    {\n      *inSize = nowPos64;\n      *outSize = _rangeEncoder.GetProcessedSize();\n      if (_matchFinder->GetNumAvailableBytes() == 0)\n        return Flush(UInt32(nowPos64));\n      if (nowPos64 - progressPosValuePrev >= (1 << 12))\n      {\n        _finished = false;\n        *finished = 0;\n        return S_OK;\n      }\n    }\n  }\n}\n\nSTDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,\n    ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,\n    ICompressProgressInfo *progress)\n{\n  #ifndef _NO_EXCEPTIONS\n  try \n  { \n  #endif\n    return CodeReal(inStream, outStream, inSize, outSize, progress); \n  #ifndef _NO_EXCEPTIONS\n  }\n  catch(const COutBufferException &e) { return e.ErrorCode; }\n  catch(...) { return E_FAIL; }\n  #endif\n}\n  \nvoid CEncoder::FillPosSlotPrices()\n{\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\n  {\n\t  UInt32 posSlot;\n    for (posSlot = 0; posSlot < kEndPosModelIndex && posSlot < _distTableSize; posSlot++)\n      _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot);\n    for (; posSlot < _distTableSize; posSlot++)\n      _posSlotPrices[lenToPosState][posSlot] = _posSlotEncoder[lenToPosState].GetPrice(posSlot) + \n      ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits);\n  }\n}\n\nvoid CEncoder::FillDistancesPrices()\n{\n  for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)\n  {\n\t  UInt32 i;\n    for (i = 0; i < kStartPosModelIndex; i++)\n      _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][i];\n    for (; i < kNumFullDistances; i++)\n    { \n      UInt32 posSlot = GetPosSlot(i);\n      UInt32 footerBits = ((posSlot >> 1) - 1);\n      UInt32 base = ((2 | (posSlot & 1)) << footerBits);\n\n      _distancesPrices[lenToPosState][i] = _posSlotPrices[lenToPosState][posSlot] +\n          NRangeCoder::ReverseBitTreeGetPrice(_posEncoders + \n              base - posSlot - 1, footerBits, i - base);\n            \n    }\n  }\n}\n\nvoid CEncoder::FillAlignPrices()\n{\n  for (UInt32 i = 0; i < kAlignTableSize; i++)\n    _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i);\n  _alignPriceCount = kAlignTableSize;\n}\n\n}}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA/LZMAEncoder.h",
    "content": "// LZMA/Encoder.h\n\n#ifndef __LZMA_ENCODER_H\n#define __LZMA_ENCODER_H\n\n#include \"../../../Common/MyCom.h\"\n#include \"../../../Common/Alloc.h\"\n#include \"../../ICoder.h\"\n#include \"../LZ/IMatchFinder.h\"\n#include \"../RangeCoder/RangeCoderBitTree.h\"\n\n#include \"LZMA.h\"\n\nnamespace NCompress {\nnamespace NLZMA {\n\ntypedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;\n\nclass CBaseState\n{\nprotected:\n  CState _state;\n  Byte _previousByte;\n  bool _peviousIsMatch;\n  UInt32 _repDistances[kNumRepDistances];\n  void Init()\n  {\n    _state.Init();\n    _previousByte = 0;\n    _peviousIsMatch = false;\n    for(UInt32 i = 0 ; i < kNumRepDistances; i++)\n      _repDistances[i] = 0;\n  }\n};\n\nstruct COptimal\n{\n  CState State;\n\n  bool Prev1IsChar;\n  bool Prev2;\n\n  UInt32 PosPrev2;\n  UInt32 BackPrev2;     \n\n  UInt32 Price;    \n  UInt32 PosPrev;         // posNext;\n  UInt32 BackPrev;     \n  UInt32 Backs[kNumRepDistances];\n  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }\n  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\n  bool IsShortRep() { return (BackPrev == 0); }\n};\n\n\nextern Byte g_FastPos[1024];\ninline UInt32 GetPosSlot(UInt32 pos)\n{\n  if (pos < (1 << 10))\n    return g_FastPos[pos];\n  if (pos < (1 << 19))\n    return g_FastPos[pos >> 9] + 18;\n  return g_FastPos[pos >> 18] + 36;\n}\n\ninline UInt32 GetPosSlot2(UInt32 pos)\n{\n  if (pos < (1 << 16))\n    return g_FastPos[pos >> 6] + 12;\n  if (pos < (1 << 25))\n    return g_FastPos[pos >> 15] + 30;\n  return g_FastPos[pos >> 24] + 48;\n}\n\nconst UInt32 kIfinityPrice = 0xFFFFFFF;\n\nconst UInt32 kNumOpts = 1 << 12;\n\n\nclass CLiteralEncoder2\n{\n  CMyBitEncoder _encoders[0x300];\npublic:\n  void Init()\n  {\n    for (int i = 0; i < 0x300; i++)\n      _encoders[i].Init();\n  }\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);\n  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;\n};\n\nclass CLiteralEncoder\n{\n  CLiteralEncoder2 *_coders;\n  int _numPrevBits;\n  int _numPosBits;\n  UInt32 _posMask;\npublic:\n  CLiteralEncoder(): _coders(0) {}\n  ~CLiteralEncoder()  { Free(); }\n  void Free()\n  { \n    MyFree(_coders);\n    _coders = 0;\n  }\n  bool Create(int numPosBits, int numPrevBits)\n  {\n    if (_coders == 0 || (numPosBits + numPrevBits) != \n        (_numPrevBits + _numPosBits) )\n    {\n      Free();\n      UInt32 numStates = 1 << (numPosBits + numPrevBits);\n      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));\n    }\n    _numPosBits = numPosBits;\n    _posMask = (1 << numPosBits) - 1;\n    _numPrevBits = numPrevBits;\n    return (_coders != 0);\n  }\n  void Init()\n  {\n    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\n    for (UInt32 i = 0; i < numStates; i++)\n      _coders[i].Init();\n  }\n  UInt32 GetState(UInt32 pos, Byte prevByte) const\n    { return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }\n  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)\n    { return &_coders[GetState(pos, prevByte)]; }\n  /*\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte, \n      Byte symbol)\n    { _coders[GetState(pos, prevByte)].Encode(rangeEncoder, symbol); }\n  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, UInt32 pos, Byte prevByte, \n      Byte matchByte, Byte symbol)\n    { _coders[GetState(pos, prevByte)].Encode(rangeEncoder,\n      matchByte, symbol); }\n  */\n  UInt32 GetPrice(UInt32 pos, Byte prevByte, bool matchMode, Byte matchByte, Byte symbol) const\n    { return _coders[GetState(pos, prevByte)].GetPrice(matchMode, matchByte, symbol); }\n};\n\nnamespace NLength {\n\nclass CEncoder\n{\n  CMyBitEncoder _choice;\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits>  _lowCoder[kNumPosStatesEncodingMax];\n  CMyBitEncoder  _choice2;\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits>  _midCoder[kNumPosStatesEncodingMax];\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits>  _highCoder;\npublic:\n  void Init(UInt32 numPosStates);\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const;\n};\n\nconst UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\n\nclass CPriceTableEncoder: public CEncoder\n{\n  UInt32 _prices[kNumSymbolsTotal][kNumPosStatesEncodingMax];\n  UInt32 _tableSize;\n  UInt32 _counters[kNumPosStatesEncodingMax];\npublic:\n  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }\n  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const\n    { return _prices[symbol][posState]; }\n  void UpdateTable(UInt32 posState)\n  {\n    for (UInt32 len = 0; len < _tableSize; len++)\n      _prices[len][posState] = CEncoder::GetPrice(len, posState);\n    _counters[posState] = _tableSize;\n  }\n  void UpdateTables(UInt32 numPosStates)\n  {\n    for (UInt32 posState = 0; posState < numPosStates; posState++)\n      UpdateTable(posState);\n  }\n  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState)\n  {\n    CEncoder::Encode(rangeEncoder, symbol, posState);\n    if (--_counters[posState] == 0)\n      UpdateTable(posState);\n  }\n};\n\n}\n\nclass CEncoder : \n  public ICompressCoder,\n  public ICompressSetOutStream,\n  public ICompressSetCoderProperties,\n  public ICompressWriteCoderProperties,\n  public CBaseState,\n  public CMyUnknownImp\n{\n  COptimal _optimum[kNumOpts];\n  CMyComPtr<IMatchFinder> _matchFinder; // test it\n  NRangeCoder::CEncoder _rangeEncoder;\n\n  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];\n  CMyBitEncoder _isRep[kNumStates];\n  CMyBitEncoder _isRepG0[kNumStates];\n  CMyBitEncoder _isRepG1[kNumStates];\n  CMyBitEncoder _isRepG2[kNumStates];\n  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];\n\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];\n\n  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];\n  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;\n  \n  NLength::CPriceTableEncoder _lenEncoder;\n  NLength::CPriceTableEncoder _repMatchLenEncoder;\n\n  CLiteralEncoder _literalEncoder;\n\n  UInt32 _matchDistances[kMatchMaxLen + 1];\n\n  bool _fastMode;\n  bool _maxMode;\n  UInt32 _numFastBytes;\n  UInt32 _longestMatchLength;    \n\n  UInt32 _additionalOffset;\n\n  UInt32 _optimumEndIndex;\n  UInt32 _optimumCurrentIndex;\n\n  bool _longestMatchWasFound;\n\n  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\n  \n  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];\n\n  UInt32 _alignPrices[kAlignTableSize];\n  UInt32 _alignPriceCount;\n\n  UInt32 _distTableSize;\n\n  UInt32 _posStateBits;\n  UInt32 _posStateMask;\n  UInt32 _numLiteralPosStateBits;\n  UInt32 _numLiteralContextBits;\n\n  UInt32 _dictionarySize;\n\n  UInt32 _dictionarySizePrev;\n  UInt32 _numFastBytesPrev;\n\n  UInt64 lastPosSlotFillingPos;\n  UInt64 nowPos64;\n  bool _finished;\n  ISequentialInStream *_inStream;\n\n  int _matchFinderIndex;\n  #ifdef COMPRESS_MF_MT\n  bool _multiThread;\n  #endif\n\n  bool _writeEndMark;\n\n  bool _needReleaseMFStream;\n  \n  HRESULT ReadMatchDistances(UInt32 &len);\n\n  HRESULT MovePos(UInt32 num);\n  UInt32 GetRepLen1Price(CState state, UInt32 posState) const\n  {\n    return _isRepG0[state.Index].GetPrice(0) +\n        _isRep0Long[state.Index][posState].GetPrice(0);\n  }\n  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const\n  {\n    UInt32 price = _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState);\n    if(repIndex == 0)\n    {\n      price += _isRepG0[state.Index].GetPrice(0);\n      price += _isRep0Long[state.Index][posState].GetPrice(1);\n    }\n    else\n    {\n      price += _isRepG0[state.Index].GetPrice(1);\n      if (repIndex == 1)\n        price += _isRepG1[state.Index].GetPrice(0);\n      else\n      {\n        price += _isRepG1[state.Index].GetPrice(1);\n        price += _isRepG2[state.Index].GetPrice(repIndex - 2);\n      }\n    }\n    return price;\n  }\n  /*\n  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const\n  {\n    if (pos >= kNumFullDistances)\n      return kIfinityPrice;\n    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);\n  }\n  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const\n  {\n    UInt32 price;\n    UInt32 lenToPosState = GetLenToPosState(len);\n    if (pos < kNumFullDistances)\n      price = _distancesPrices[lenToPosState][pos];\n    else\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \n          _alignPrices[pos & kAlignMask];\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\n  }\n  */\n  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const\n  {\n    if (len == 2 && pos >= 0x80)\n      return kIfinityPrice;\n    UInt32 price;\n    UInt32 lenToPosState = GetLenToPosState(len);\n    if (pos < kNumFullDistances)\n      price = _distancesPrices[lenToPosState][pos];\n    else\n      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \n          _alignPrices[pos & kAlignMask];\n    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\n  }\n\n  UInt32 Backward(UInt32 &backRes, UInt32 cur);\n  HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\n  HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\n\n  void FillPosSlotPrices();\n  void FillDistancesPrices();\n  void FillAlignPrices();\n    \n  void ReleaseMFStream()\n  {\n    if (_matchFinder && _needReleaseMFStream)\n    {\n      _matchFinder->ReleaseStream();\n      _needReleaseMFStream = false;\n    }\n  }\n\n  void ReleaseStreams()\n  {\n    ReleaseMFStream();\n    _rangeEncoder.ReleaseStream();\n  }\n\n  HRESULT Flush(UInt32 nowPos);\n  class CCoderReleaser\n  {\n    CEncoder *_coder;\n  public:\n    CCoderReleaser(CEncoder *coder): _coder(coder) {}\n    ~CCoderReleaser()\n    {\n      _coder->ReleaseStreams();\n    }\n  };\n  friend class CCoderReleaser;\n\n  void WriteEndMarker(UInt32 posState);\n\npublic:\n  CEncoder();\n  void SetWriteEndMarkerMode(bool writeEndMarker)\n    { _writeEndMark= writeEndMarker; }\n\n  HRESULT Create();\n\n  MY_UNKNOWN_IMP3(\n      ICompressSetOutStream,\n      ICompressSetCoderProperties,\n      ICompressWriteCoderProperties\n      )\n    \n  HRESULT Init();\n  \n  // ICompressCoder interface\n  HRESULT SetStreams(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream,\n      const UInt64 *inSize, const UInt64 *outSize);\n  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);\n\n  HRESULT CodeReal(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, \n      const UInt64 *inSize, const UInt64 *outSize,\n      ICompressProgressInfo *progress);\n\n  // ICompressCoder interface\n  STDMETHOD(Code)(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, \n      const UInt64 *inSize, const UInt64 *outSize,\n      ICompressProgressInfo *progress);\n\n  // IInitMatchFinder interface\n  STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder);\n\n  // ICompressSetCoderProperties2\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \n      const PROPVARIANT *properties, UInt32 numProperties);\n  \n  // ICompressWriteCoderProperties\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\n\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\n\n  virtual ~CEncoder() {}\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA/Makefile",
    "content": "RGSRC=../../../../../..\ninclude $(RGSRC)/envir.mak\n\nOBJS=LZMADecoder.o LZMAEncoder.o\n\ninclude $(LZMAMK)\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#ifdef WIN32\n#include <windows.h>\n#endif\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_Alone/AloneLZMA.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"AloneLZMA\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n\r\nCFG=AloneLZMA - Win32 DebugU\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"AloneLZMA.mak\" CFG=\"AloneLZMA - Win32 DebugU\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"AloneLZMA - Win32 Release\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 ReleaseU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \"AloneLZMA - Win32 DebugU\" (based on \"Win32 (x86) Console Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"AloneLZMA - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\r\n# ADD CPP /nologo /MT /W3 /GX /O2 /D \"NDEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"_MBCS\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 ReleaseU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"ReleaseU\"\r\n# PROP BASE Intermediate_Dir \"ReleaseU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"ReleaseU\"\r\n# PROP Intermediate_Dir \"ReleaseU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD CPP /nologo /MD /W3 /GX /O2 /D \"NDEBUG\" /D \"UNICODE\" /D \"_UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /c\r\n# ADD BASE RSC /l 0x419 /d \"NDEBUG\"\r\n# ADD RSC /l 0x419 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /opt:NOWIN98\r\n# SUBTRACT BASE LINK32 /pdb:none\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /opt:NOWIN98\r\n# SUBTRACT LINK32 /pdb:none\r\n\r\n!ELSEIF  \"$(CFG)\" == \"AloneLZMA - Win32 DebugU\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"DebugU\"\r\n# PROP BASE Intermediate_Dir \"DebugU\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"DebugU\"\r\n# PROP Intermediate_Dir \"DebugU\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"WIN32\" /D \"_CONSOLE\" /D \"EXCLUDE_COM\" /D \"NO_REGISTRY\" /D \"FORMAT_7Z\" /D \"FORMAT_BZIP2\" /D \"FORMAT_ZIP\" /D \"FORMAT_TAR\" /D \"FORMAT_GZIP\" /D \"COMPRESS_LZMA\" /D \"COMPRESS_BCJ_X86\" /D \"COMPRESS_BCJ2\" /D \"COMPRESS_COPY\" /D \"COMPRESS_MF_PAT\" /D \"COMPRESS_MF_BT\" /D \"COMPRESS_PPMD\" /D \"COMPRESS_DEFLATE\" /D \"COMPRESS_IMPLODE\" /D \"COMPRESS_BZIP2\" /D \"CRYPTO_ZIP\" /D \"_MBCS\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_DEBUG\" /D \"_UNICODE\" /D \"UNICODE\" /D \"WIN32\" /D \"_CONSOLE\" /Yu\"StdAfx.h\" /FD /GZ /c\r\n# ADD BASE RSC /l 0x419 /d \"_DEBUG\"\r\n# ADD RSC /l 0x419 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\7za2.exe\" /pdbtype:sept\r\n# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:\"c:\\UTIL\\lzma.exe\" /pdbtype:sept\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"AloneLZMA - Win32 Release\"\r\n# Name \"AloneLZMA - Win32 Debug\"\r\n# Name \"AloneLZMA - Win32 ReleaseU\"\r\n# Name \"AloneLZMA - Win32 DebugU\"\r\n# Begin Group \"Spec\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.cpp\r\n# ADD CPP /Yc\"StdAfx.h\"\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\StdAfx.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Compress\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"LZMA\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMA.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMADecoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZMA\\LZMAEncoder.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"RangeCoder\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBit.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderBitTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\RangeCoder\\RangeCoderOpt.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"LZ\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Group \"Pat\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat2R.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat3H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\Pat4H.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\Patricia\\PatMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"BT\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3Z.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree3ZMain.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTree4b.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTreeMain.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTreeMF.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\BinTree\\BinTreeMFMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"HC\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC2.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC3.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC4.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HC4b.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HCMain.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HCMF.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\HashChain\\HCMFMain.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\IMatchFinder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZInWindow.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\LZ\\LZOutWindow.h\r\n# End Source File\r\n# End Group\r\n# End Group\r\n# Begin Group \"Windows\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Windows\\FileIO.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Alloc.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CommandLineParser.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\CRC.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Defs.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyCom.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\MyWindows.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\NewHandler.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\String.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringConvert.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\StringToInt.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Types.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\..\\Common\\Vector.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"7zip Common\"\r\n\r\n# PROP Default_Filter \"\"\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\FileStreams.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\InBuffer.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\Common\\OutBuffer.h\r\n# End Source File\r\n# End Group\r\n# Begin Source File\r\n\r\nSOURCE=..\\..\\ICoder.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaAlone.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.cpp\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\LzmaBench.h\r\n# End Source File\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_Alone/AloneLZMA.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"AloneLZMA\"=.\\AloneLZMA.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_Alone/LzmaAlone.cpp",
    "content": "// LzmaAlone.cpp\n\n#include \"StdAfx.h\"\n\n#ifdef WIN32\n#include <initguid.h>\n#else\n#define INITGUID\n#endif\n\n#include \"../../../Common/MyWindows.h\"\n\n// #include <limits.h>\n#include <stdio.h>\n\n#if defined(WIN32) || defined(OS2) || defined(MSDOS)\n#include <fcntl.h>\n#include <io.h>\n#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)\n#else\n#define MY_SET_BINARY_MODE(file)\n#endif\n\n#include \"../../../Common/CommandLineParser.h\"\n#include \"../../../Common/StringConvert.h\"\n#include \"../../../Common/StringToInt.h\"\n\n// #include \"Windows/PropVariant.h\"\n\n#include \"../../Common/FileStreams.h\"\n\n#include \"../LZMA/LZMADecoder.h\"\n#include \"../LZMA/LZMAEncoder.h\"\n\n#include \"LzmaBench.h\"\n\nusing namespace NCommandLineParser;\n\nnamespace NKey {\nenum Enum\n{\n  kHelp1 = 0,\n  kHelp2,\n  kMode,\n  kDictionary,\n  kFastBytes,\n  kLitContext,\n  kLitPos,\n  kPosBits,\n  kMatchFinder,\n  kEOS,\n  kStdIn,\n  kStdOut\n};\n}\n\nstatic const CSwitchForm kSwitchForms[] = \n{\n  { L\"?\",  NSwitchType::kSimple, false },\n  { L\"H\",  NSwitchType::kSimple, false },\n  { L\"A\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"D\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"FB\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"LC\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"LP\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"PB\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"MF\", NSwitchType::kUnLimitedPostString, false, 1 },\n  { L\"EOS\", NSwitchType::kSimple, false },\n  { L\"SI\",  NSwitchType::kSimple, false },\n  { L\"SO\",  NSwitchType::kSimple, false }\n};\n\nstatic const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);\n\nstatic void PrintHelp()\n{\n  fprintf(stderr, \"\\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\\n\"\n             \"  e: encode file\\n\"\n             \"  d: decode file\\n\"\n             \"  b: Benchmark\\n\"\n    \"<Switches>\\n\"\n    \"  -a{N}:  set compression mode - [0, 2], default: 2 (max)\\n\"\n    \"  -d{N}:  set dictionary - [0,28], default: 23 (8MB)\\n\"\n    \"  -fb{N}: set number of fast bytes - [5, 255], default: 128\\n\"\n    \"  -lc{N}: set number of literal context bits - [0, 8], default: 3\\n\"\n    \"  -lp{N}: set number of literal pos bits - [0, 4], default: 0\\n\"\n    \"  -pb{N}: set number of pos bits - [0, 4], default: 2\\n\"\n    \"  -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, bt4b, pat2r, pat2,\\n\"\n    \"              pat2h, pat3h, pat4h, hc3, hc4], default: bt4\\n\"\n    \"  -eos:   write End Of Stream marker\\n\"\n    \"  -si:    Read data from stdin\\n\"\n    \"  -so:    Write data to stdout\\n\"\n    );\n}\n\nstatic void PrintHelpAndExit(const char *s)\n{\n  fprintf(stderr, \"\\nError: %s\\n\\n\", s);\n  PrintHelp();\n  throw -1;\n}\n\nstatic void IncorrectCommand()\n{\n  PrintHelpAndExit(\"Incorrect command\");\n}\n\nstatic void WriteArgumentsToStringList(int numArguments, const char *arguments[], \n    UStringVector &strings)\n{\n  for(int i = 1; i < numArguments; i++)\n    strings.Add(MultiByteToUnicodeString(arguments[i]));\n}\n\nstatic bool GetNumber(const wchar_t *s, UInt32 &value)\n{\n  value = 0;\n  if (MyStringLen(s) == 0)\n    return false;\n  const wchar_t *end;\n  UInt64 res = ConvertStringToUInt64(s, &end);\n  if (*end != L'\\0')\n    return false;\n  if (res > 0xFFFFFFFF)\n    return false;\n  value = UInt32(res);\n  return true;\n}\n\nint main2(int n, const char *args[])\n{\n  fprintf(stderr, \"\\nLZMA 4.06 Copyright (c) 1999-2004 Igor Pavlov  2004-09-05\\n\");\n\n  if (n == 1)\n  {\n    PrintHelp();\n    return 0;\n  }\n\n  if (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4)\n  {\n    fprintf(stderr, \"Unsupported base types. Edit Common/Types.h and recompile\");\n    return 1;\n  }   \n\n  UStringVector commandStrings;\n  WriteArgumentsToStringList(n, args, commandStrings);\n  CParser parser(kNumSwitches);\n  try\n  {\n    parser.ParseStrings(kSwitchForms, commandStrings);\n  }\n  catch(...) \n  {\n    IncorrectCommand();\n  }\n\n  if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)\n  {\n    PrintHelp();\n    return 0;\n  }\n  const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;\n\n  int paramIndex = 0;\n  if (paramIndex >= nonSwitchStrings.Size())\n    IncorrectCommand();\n  const UString &command = nonSwitchStrings[paramIndex++]; \n\n  bool dictionaryIsDefined = false;\n  UInt32 dictionary = 1 << 21;\n  if(parser[NKey::kDictionary].ThereIs)\n  {\n    UInt32 dicLog;\n    if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))\n      IncorrectCommand();\n    dictionary = 1 << dicLog;\n    dictionaryIsDefined = true;\n  }\n  UString mf = L\"BT4\";\n  if (parser[NKey::kMatchFinder].ThereIs)\n    mf = parser[NKey::kMatchFinder].PostStrings[0];\n\n  if (command.CompareNoCase(L\"b\") == 0)\n  {\n    const UInt32 kNumDefaultItereations = 10;\n    UInt32 numIterations = kNumDefaultItereations;\n    {\n      if (paramIndex < nonSwitchStrings.Size())\n        if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))\n          numIterations = kNumDefaultItereations;\n    }\n    return LzmaBenchmark(stderr, numIterations, dictionary, \n        mf.CompareNoCase(L\"BT4\") == 0);\n  }\n\n  bool encodeMode;\n  if (command.CompareNoCase(L\"e\") == 0)\n    encodeMode = true;\n  else if (command.CompareNoCase(L\"d\") == 0)\n    encodeMode = false;\n  else\n    IncorrectCommand();\n\n  bool stdInMode = parser[NKey::kStdIn].ThereIs;\n  bool stdOutMode = parser[NKey::kStdOut].ThereIs;\n\n  CMyComPtr<ISequentialInStream> inStream;\n  CInFileStream *inStreamSpec = 0;\n  if (stdInMode)\n  {\n    inStream = new CStdInFileStream;\n    MY_SET_BINARY_MODE(stdin);\n  }\n  else\n  {\n    if (paramIndex >= nonSwitchStrings.Size())\n      IncorrectCommand();\n    const UString &inputName = nonSwitchStrings[paramIndex++]; \n    inStreamSpec = new CInFileStream;\n    inStream = inStreamSpec;\n    if (!inStreamSpec->Open(GetSystemString(inputName)))\n    {\n      fprintf(stderr, \"\\nError: can not open input file %s\\n\", \n          (const char *)GetOemString(inputName));\n      return 1;\n    }\n  }\n\n  CMyComPtr<ISequentialOutStream> outStream;\n  if (stdOutMode)\n  {\n    outStream = new CStdOutFileStream;\n    MY_SET_BINARY_MODE(stdout);\n  }\n  else\n  {\n    if (paramIndex >= nonSwitchStrings.Size())\n      IncorrectCommand();\n    const UString &outputName = nonSwitchStrings[paramIndex++]; \n    COutFileStream *outStreamSpec = new COutFileStream;\n    outStream = outStreamSpec;\n    if (!outStreamSpec->Create(GetSystemString(outputName), true))\n    {\n      fprintf(stderr, \"\\nError: can not open output file %s\\n\", \n        (const char *)GetOemString(outputName));\n      return 1;\n    }\n  }\n\n  UInt64 fileSize;\n  if (encodeMode)\n  {\n    NCompress::NLZMA::CEncoder *encoderSpec = \n      new NCompress::NLZMA::CEncoder;\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\n\n    if (!dictionaryIsDefined)\n      dictionary = 1 << 23;\n\n    UInt32 posStateBits = 2;\n    UInt32 litContextBits = 3; // for normal files\n    // UInt32 litContextBits = 0; // for 32-bit data\n    UInt32 litPosBits = 0;\n    // UInt32 litPosBits = 2; // for 32-bit data\n    UInt32 algorithm = 2;\n    UInt32 numFastBytes = 128;\n\n    bool eos = parser[NKey::kEOS].ThereIs || stdInMode;\n \n    if(parser[NKey::kMode].ThereIs)\n      if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))\n        IncorrectCommand();\n\n    if(parser[NKey::kFastBytes].ThereIs)\n      if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))\n        IncorrectCommand();\n    if(parser[NKey::kLitContext].ThereIs)\n      if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))\n        IncorrectCommand();\n    if(parser[NKey::kLitPos].ThereIs)\n      if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))\n        IncorrectCommand();\n    if(parser[NKey::kPosBits].ThereIs)\n      if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))\n        IncorrectCommand();\n\n    PROPID propIDs[] = \n    {\n      NCoderPropID::kDictionarySize,\n      NCoderPropID::kPosStateBits,\n      NCoderPropID::kLitContextBits,\n      NCoderPropID::kLitPosBits,\n      NCoderPropID::kAlgorithm,\n      NCoderPropID::kNumFastBytes,\n      NCoderPropID::kMatchFinder,\n      NCoderPropID::kEndMarker\n    };\n    const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\n    /*\n    NWindows::NCOM::CPropVariant properties[kNumProps];\n    properties[0] = UInt32(dictionary);\n    properties[1] = UInt32(posStateBits);\n    properties[2] = UInt32(litContextBits);\n   \n    properties[3] = UInt32(litPosBits);\n    properties[4] = UInt32(algorithm);\n    properties[5] = UInt32(numFastBytes);\n    properties[6] = mf;\n    properties[7] = eos;\n    */\n    PROPVARIANT properties[kNumProps];\n    for (int p = 0; p < 6; p++)\n      properties[p].vt = VT_UI4;\n    properties[0].ulVal = UInt32(dictionary);\n    properties[1].ulVal = UInt32(posStateBits);\n    properties[2].ulVal = UInt32(litContextBits);\n    properties[3].ulVal = UInt32(litPosBits);\n    properties[4].ulVal = UInt32(algorithm);\n    properties[5].ulVal = UInt32(numFastBytes);\n    \n    properties[6].vt = VT_BSTR;\n    properties[6].bstrVal = (BSTR)(const wchar_t *)mf;\n\n    properties[7].vt = VT_BOOL;\n    properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;\n\n    if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\n      IncorrectCommand();\n    encoderSpec->WriteCoderProperties(outStream);\n\n    if (eos || stdInMode)\n      fileSize = (UInt64)(Int64)-1;\n    else\n      inStreamSpec->File.GetLength(fileSize);\n\n    for (int i = 0; i < 4; i++)\n    {\n      Byte b = Byte(fileSize >> (8 * i));\n      if (outStream->Write(&b, sizeof(b), 0) != S_OK)\n      {\n        fprintf(stderr, \"Write error\");\n        return 1;\n      }\n    }\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\n    if (result == E_OUTOFMEMORY)\n    {\n      fprintf(stderr, \"\\nError: Can not allocate memory\\n\");\n      return 1;\n    }   \n    else if (result != S_OK)\n    {\n      fprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\n      return 1;\n    }   \n  }\n  else\n  {\n    NCompress::NLZMA::CDecoder *decoderSpec = \n        new NCompress::NLZMA::CDecoder;\n    CMyComPtr<ICompressCoder> decoder = decoderSpec;\n    if (decoderSpec->SetDecoderProperties(inStream) != S_OK)\n    {\n      fprintf(stderr, \"SetDecoderProperties error\");\n      return 1;\n    }\n    fileSize = 0;\n    for (int i = 0; i < 4; i++)\n    {\n      Byte b;\n      UInt32 processedSize;\n      if (inStream->Read(&b, sizeof(b), &processedSize) != S_OK)\n      {\n        fprintf(stderr, \"Read error\");\n        return 1;\n      }\n      if (processedSize != 1)\n      {\n        fprintf(stderr, \"Read error\");\n        return 1;\n      }\n      fileSize |= ((UInt64)b) << (8 * i);\n    }\n    if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\n    {\n      fprintf(stderr, \"Decoder error\");\n      return 1;\n    }   \n  }\n  return 0;\n}\n\nint main(int n, const char *args[])\n{\n  try { return main2(n, args); }\n  catch(const char *s) \n  { \n    fprintf(stderr, \"\\nError: %s\\n\", s);\n    return 1; \n  }\n  catch(...) \n  { \n    fprintf(stderr, \"\\nError\\n\");\n    return 1; \n  }\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_Alone/LzmaBench.cpp",
    "content": "// LzmaBench.cpp\n\n#include \"StdAfx.h\"\n\n#include \"LzmaBench.h\"\n\n#ifndef WIN32\n#include <time.h>\n#endif\n\n#include \"../../../Common/CRC.h\"\n#include \"../LZMA/LZMADecoder.h\"\n#include \"../LZMA/LZMAEncoder.h\"\n\nstatic const UInt32 kAdditionalSize = \n#ifdef _WIN32_WCE\n(1 << 20);\n#else\n(6 << 20);\n#endif\n\nstatic const UInt32 kCompressedAdditionalSize = (1 << 10);\nstatic const UInt32 kMaxLzmaPropSize = 10;\n\nclass CRandomGenerator\n{\n  UInt32 A1;\n  UInt32 A2;\npublic:\n  CRandomGenerator() { Init(); }\n  void Init() { A1 = 362436069; A2 = 521288629;}\n  UInt32 GetRnd() \n  {\n    return \n      ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) ^\n      ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );\n  }\n};\n\nclass CBitRandomGenerator\n{\n  CRandomGenerator RG;\n  UInt32 Value;\n  int NumBits;\npublic:\n  void Init()\n  {\n    Value = 0;\n    NumBits = 0;\n  }\n  UInt32 GetRnd(int numBits) \n  {\n    if (NumBits > numBits)\n    {\n      UInt32 result = Value & ((1 << numBits) - 1);\n      Value >>= numBits;\n      NumBits -= numBits;\n      return result;\n    }\n    numBits -= NumBits;\n    UInt32 result = (Value << numBits);\n    Value = RG.GetRnd();\n    result |= Value & ((1 << numBits) - 1);\n    Value >>= numBits;\n    NumBits = 32 - numBits;\n    return result;\n  }\n};\n\nclass CBenchRandomGenerator\n{\n  CBitRandomGenerator RG;\n  UInt32 Pos;\npublic:\n  UInt32 BufferSize;\n  Byte *Buffer;\n  CBenchRandomGenerator(): Buffer(0) {} \n  ~CBenchRandomGenerator() { delete []Buffer; }\n  void Init() { RG.Init(); }\n  void Set(UInt32 bufferSize) \n  {\n    delete []Buffer;\n    Buffer = 0;\n    Buffer = new Byte[bufferSize];\n    Pos = 0;\n    BufferSize = bufferSize;\n  }\n  UInt32 GetRndBit() { return RG.GetRnd(1); }\n  /*\n  UInt32 GetLogRand(int maxLen)\n  {\n    UInt32 len = GetRnd() % (maxLen + 1);\n    return GetRnd() & ((1 << len) - 1);\n  }\n  */\n  UInt32 GetLogRandBits(int numBits)\n  {\n    UInt32 len = RG.GetRnd(numBits);\n    return RG.GetRnd(len);\n  }\n  UInt32 GetOffset()\n  {\n    if (GetRndBit() == 0)\n      return GetLogRandBits(4);\n    return (GetLogRandBits(4) << 10) | RG.GetRnd(10);\n  }\n  UInt32 GetLen()\n  {\n    if (GetRndBit() == 0)\n      return RG.GetRnd(2);\n    if (GetRndBit() == 0)\n      return 4 + RG.GetRnd(3);\n    return 12 + RG.GetRnd(4);\n  }\n  void Generate()\n  {\n    while(Pos < BufferSize)\n    {\n      if (GetRndBit() == 0 || Pos < 1)\n        Buffer[Pos++] = Byte(RG.GetRnd(8));\n      else\n      {\n        UInt32 offset = GetOffset();\n        while (offset >= Pos)\n          offset >>= 1;\n        offset += 1;\n        UInt32 len = 2 + GetLen();\n        for (UInt32 i = 0; i < len && Pos < BufferSize; i++, Pos++)\n          Buffer[Pos] = Buffer[Pos - offset];\n      }\n    }\n  }\n};\n\nclass CBenchmarkInStream: \n  public ISequentialInStream,\n  public CMyUnknownImp\n{\n  const Byte *Data;\n  UInt32 Pos;\n  UInt32 Size;\npublic:\n  MY_UNKNOWN_IMP\n  void Init(const Byte *data, UInt32 size)\n  {\n    Data = data;\n    Size = size;\n    Pos = 0;\n  }\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);\n};\n\nSTDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 remain = Size - Pos;\n  if (size > remain)\n    size = remain;\n  for (UInt32 i = 0; i < size; i++)\n  {\n    ((Byte *)data)[i] = Data[Pos + i];\n  }\n  Pos += size;\n  if(processedSize != NULL)\n    *processedSize = size;\n  return S_OK;\n}\n  \nSTDMETHODIMP CBenchmarkInStream::ReadPart(void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Read(data, size, processedSize);\n}\n\nclass CBenchmarkOutStream: \n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\n  UInt32 BufferSize;\n  FILE *_f;\npublic:\n  UInt32 Pos;\n  Byte *Buffer;\n  CBenchmarkOutStream(): _f(0), Buffer(0) {} \n  virtual ~CBenchmarkOutStream() { delete []Buffer; }\n  void Init(FILE *f, UInt32 bufferSize) \n  {\n    delete []Buffer;\n    Buffer = 0;\n    Buffer = new Byte[bufferSize];\n    Pos = 0;\n    BufferSize = bufferSize;\n    _f = f;\n  }\n  MY_UNKNOWN_IMP\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\nSTDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  UInt32 i;\n  for (i = 0; i < size && Pos < BufferSize; i++)\n    Buffer[Pos++] = ((const Byte *)data)[i];\n  if(processedSize != NULL)\n    *processedSize = i;\n  if (i != size)\n  {\n    fprintf(_f, \"\\nERROR: Buffer is full\\n\");\n    return E_FAIL;\n  }\n  return S_OK;\n}\n  \nSTDMETHODIMP CBenchmarkOutStream::WritePart(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Write(data, size, processedSize);\n}\n\nclass CCrcOutStream: \n  public ISequentialOutStream,\n  public CMyUnknownImp\n{\npublic:\n  CCRC CRC;\n  MY_UNKNOWN_IMP\n  void Init() { CRC.Init(); }\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);\n  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);\n};\n\nSTDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  CRC.Update(data, size);\n  if(processedSize != NULL)\n    *processedSize = size;\n  return S_OK;\n}\n  \nSTDMETHODIMP CCrcOutStream::WritePart(const void *data, UInt32 size, UInt32 *processedSize)\n{\n  return Write(data, size, processedSize);\n}\n\nstatic UInt64 GetTimeCount()\n{\n  #ifdef WIN32\n  LARGE_INTEGER value;\n  if (::QueryPerformanceCounter(&value))\n    return value.QuadPart;\n  return GetTickCount();\n  #else\n  return clock();\n  #endif \n}\n\nstatic UInt64 GetFreq()\n{\n  #ifdef WIN32\n  LARGE_INTEGER value;\n  if (::QueryPerformanceFrequency(&value))\n    return value.QuadPart;\n  return 1000;\n  #else\n  return CLOCKS_PER_SEC;\n  #endif \n}\n\nstruct CProgressInfo:\n  public ICompressProgressInfo,\n  public CMyUnknownImp\n{\n  UInt64 ApprovedStart;\n  UInt64 InSize;\n  UInt64 Time;\n  void Init()\n  {\n    InSize = 0;\n    Time = 0;\n  }\n  MY_UNKNOWN_IMP\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);\n};\n\nSTDMETHODIMP CProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)\n{\n  if (*inSize >= ApprovedStart && InSize == 0)\n  {\n    Time = ::GetTimeCount();\n    InSize = *inSize;\n  }\n  return S_OK;\n}\n\nstatic const int kSubBits = 8;\n\nstatic UInt32 GetLogSize(UInt32 size)\n{\n  for (int i = kSubBits; i < 32; i++)\n    for (UInt32 j = 0; j < (1 << kSubBits); j++)\n      if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))\n        return (i << kSubBits) + j;\n  return (32 << kSubBits);\n}\n\nstatic UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime)\n{\n  UInt64 freq = GetFreq();\n  UInt64 elTime = elapsedTime;\n  while(freq > 1000000)\n  {\n    freq >>= 1;\n    elTime >>= 1;\n  }\n  if (elTime == 0)\n    elTime = 1;\n  return value * freq / elTime;\n}\n\nstatic UInt64 GetCompressRating(UInt32 dictionarySize, bool isBT4,\n    UInt64 elapsedTime, UInt64 size)\n{\n  UInt64 numCommandsForOne;\n  if (isBT4)\n  {\n    UInt64 t = GetLogSize(dictionarySize) - (19 << kSubBits);\n    numCommandsForOne = 2000 + ((t * t * 68) >> (2 * kSubBits));\n  }\n  else\n  {\n    UInt64 t = GetLogSize(dictionarySize) - (15 << kSubBits);\n    numCommandsForOne = 1500 + ((t * t * 41) >> (2 * kSubBits));\n  }\n  UInt64 numCommands = (UInt64)(size) * numCommandsForOne;\n  return MyMultDiv64(numCommands, elapsedTime);\n}\n\nstatic UInt64 GetDecompressRating(UInt64 elapsedTime, \n    UInt64 outSize, UInt64 inSize)\n{\n  UInt64 numCommands = inSize * 250 + outSize * 21;\n  return MyMultDiv64(numCommands, elapsedTime);\n}\n\nstatic void PrintRating(FILE *f, UInt64 rating)\n{\n  fprintf(f, \"%5d MIPS\", (unsigned int)(rating / 1000000));\n}\n\nstatic void PrintResults(\n    FILE *f, \n    UInt32 dictionarySize,\n    bool isBT4,\n    UInt64 elapsedTime, \n    UInt64 size, \n    bool decompressMode, UInt64 secondSize)\n{\n  UInt64 speed = MyMultDiv64(size, elapsedTime);\n  fprintf(f, \"%6d KB/s  \", (unsigned int)(speed / 1024));\n  UInt64 rating;\n  if (decompressMode)\n    rating = GetDecompressRating(elapsedTime, size, secondSize);\n  else\n    rating = GetCompressRating(dictionarySize, isBT4, elapsedTime, size);\n  PrintRating(f, rating);\n}\n\nstatic void ThrowError(FILE *f, HRESULT result, const char *s)\n{\n  fprintf(f, \"\\nError: \");\n  if (result == E_ABORT)\n    fprintf(f, \"User break\");\n  if (result == E_OUTOFMEMORY)\n    fprintf(f, \"Can not allocate memory\");\n  else\n    fprintf(f, s);\n  fprintf(f, \"\\n\");\n}\n\nconst wchar_t *bt2 = L\"BT2\";\nconst wchar_t *bt4 = L\"BT4\";\n\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize, bool isBT4)\n{\n  if (numIterations == 0)\n    return 0;\n  if (dictionarySize < (1 << 19) && isBT4 || dictionarySize < (1 << 15))\n  {\n    fprintf(f, \"\\nError: dictionary size for benchmark must be >= 19 (512 KB)\\n\");\n    return 1;\n  }\n  fprintf(f, \"\\n       Compressing                Decompressing\\n\\n\");\n  NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\n  CMyComPtr<ICompressCoder> encoder = encoderSpec;\n\n  NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;\n  CMyComPtr<ICompressCoder> decoder = decoderSpec;\n\n  CBenchmarkOutStream *propStreamSpec = new CBenchmarkOutStream;\n  CMyComPtr<ISequentialOutStream> propStream = propStreamSpec;\n  propStreamSpec->Init(f, kMaxLzmaPropSize);\n  \n  CBenchmarkInStream *propDecoderStreamSpec = new CBenchmarkInStream;\n  CMyComPtr<ISequentialInStream> propDecoderStream = propDecoderStreamSpec;\n\n  PROPID propIDs[] = \n  { \n    NCoderPropID::kDictionarySize,  \n    NCoderPropID::kMatchFinder  \n  };\n  const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\n  PROPVARIANT properties[kNumProps];\n  properties[0].vt = VT_UI4;\n  properties[0].ulVal = UInt32(dictionarySize);\n\n  properties[1].vt = VT_BSTR;\n  properties[1].bstrVal = isBT4 ? (BSTR)bt4: (BSTR)bt2;\n\n  const UInt32 kBufferSize = dictionarySize + kAdditionalSize;\n  const UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;\n\n  if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\n  {\n    fprintf(f, \"\\nError: Incorrect command\\n\");\n    return 1;\n  }\n  encoderSpec->WriteCoderProperties(propStream);\n\n  CBenchRandomGenerator rg;\n  rg.Init();\n  rg.Set(kBufferSize);\n  rg.Generate();\n  CCRC crc;\n  crc.Update(rg.Buffer, rg.BufferSize);\n\n  CProgressInfo *progressInfoSpec = new CProgressInfo;\n  CMyComPtr<ICompressProgressInfo> progressInfo = progressInfoSpec;\n\n  progressInfoSpec->ApprovedStart = dictionarySize;\n\n  UInt64 totalBenchSize = 0;\n  UInt64 totalEncodeTime = 0;\n  UInt64 totalDecodeTime = 0;\n  UInt64 totalCompressedSize = 0;\n\n  for (UInt32 i = 0; i < numIterations; i++)\n  {\n    progressInfoSpec->Init();\n    CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;\n    inStreamSpec->Init(rg.Buffer, rg.BufferSize);\n    CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\n    CBenchmarkOutStream *outStreamSpec = new CBenchmarkOutStream;\n    outStreamSpec->Init(f, kCompressedBufferSize);\n    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, progressInfo);\n    UInt64 encodeTime = ::GetTimeCount() - progressInfoSpec->Time;\n    UInt32 compressedSize = outStreamSpec->Pos;\n    if(result != S_OK)\n    {\n      ThrowError(f, result, \"Encoder Error\");\n      return 1;\n    }\n    if (progressInfoSpec->InSize == 0)\n    {\n      fprintf(f, \"\\nError: Internal ERROR 1282\\n\");\n      return 1;\n    }\n  \n    ///////////////////////\n    // Decompressing\n  \n    CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;\n    CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;\n    \n    UInt64 decodeTime;\n    for (int i = 0; i < 2; i++)\n    {\n      inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);\n      crcOutStreamSpec->Init();\n      \n      propDecoderStreamSpec->Init(propStreamSpec->Buffer, propStreamSpec->Pos);\n      if (decoderSpec->SetDecoderProperties(propDecoderStream) != S_OK)\n      {\n        fprintf(f, \"\\nError: Set Decoder Properties Error\\n\");\n        return 1;\n      }\n      UInt64 outSize = kBufferSize;\n      UInt64 startTime = ::GetTimeCount();\n      result = decoder->Code(inStream, crcOutStream, 0, &outSize, 0);\n      decodeTime = ::GetTimeCount() - startTime;\n      if(result != S_OK)\n      {\n        ThrowError(f, result, \"Decode Error\");\n        return 1;\n      }\n      if (crcOutStreamSpec->CRC.GetDigest() != crc.GetDigest())\n      {\n        fprintf(f, \"\\nError: CRC Error\\n\");\n        return 1;\n      }\n    }\n    UInt64 benchSize = kBufferSize - progressInfoSpec->InSize;\n    PrintResults(f, dictionarySize, isBT4, encodeTime, benchSize, false, 0);\n    fprintf(f, \"     \");\n    PrintResults(f, dictionarySize, isBT4, decodeTime, kBufferSize, true, compressedSize);\n    fprintf(f, \"\\n\");\n\n    totalBenchSize += benchSize;\n    totalEncodeTime += encodeTime;\n    totalDecodeTime += decodeTime;\n    totalCompressedSize += compressedSize;\n  }\n  fprintf(f, \"---------------------------------------------------\\n\");\n  PrintResults(f, dictionarySize, isBT4, totalEncodeTime, totalBenchSize, false, 0);\n  fprintf(f, \"     \");\n  PrintResults(f, dictionarySize, isBT4, totalDecodeTime, \n      kBufferSize * numIterations, true, totalCompressedSize);\n  fprintf(f, \"    Average\\n\");\n  return 0;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_Alone/LzmaBench.h",
    "content": "// LzmaBench.h\n\n#ifndef __LzmaBench_h\n#define __LzmaBench_h\n\n#include <stdio.h>\n#include \"../../../Common/Types.h\"\n\nint LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize, bool isBT4);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_Alone/Makefile",
    "content": "PROG = lzma\nCXX = g++ -O3 -Wall\nLIB = -lm\nRM = rm -f\nCFLAGS = -c\n\nOBJS = \\\n  LzmaAlone.o \\\n  LzmaBench.o \\\n  LZMADecoder.o \\\n  LZMAEncoder.o \\\n  LZInWindow.o \\\n  LZOutWindow.o \\\n  RangeCoderBit.o \\\n  InBuffer.o \\\n  OutBuffer.o \\\n  FileStreams.o \\\n  Alloc.o \\\n  C_FileIO.o \\\n  CommandLineParser.o \\\n  CRC.o \\\n  String.o \\\n  StringConvert.o \\\n  StringToInt.o \\\n  Vector.o \\\n\n\nall: $(PROG)\n\n$(PROG): $(OBJS)\n\t$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\n\nLzmaAlone.o: LzmaAlone.cpp\n\t$(CXX) $(CFLAGS) LzmaAlone.cpp\n\nLzmaBench.o: LzmaBench.cpp\n\t$(CXX) $(CFLAGS) LzmaBench.cpp\n\nLZMADecoder.o: ../LZMA/LZMADecoder.cpp\n\t$(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp\n\nLZMAEncoder.o: ../LZMA/LZMAEncoder.cpp\n\t$(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp\n\nLZInWindow.o: ../LZ/LZInWindow.cpp\n\t$(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp\n\nLZOutWindow.o: ../LZ/LZOutWindow.cpp\n\t$(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp\n\nRangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp\n\t$(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp\n\nInBuffer.o: ../../Common/InBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/InBuffer.cpp\n\nOutBuffer.o: ../../Common/OutBuffer.cpp\n\t$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp\n\nFileStreams.o: ../../Common/FileStreams.cpp\n\t$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp\n\nAlloc.o: ../../../Common/Alloc.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/Alloc.cpp\n\nC_FileIO.o: ../../../Common/C_FileIO.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp\n\nCommandLineParser.o: ../../../Common/CommandLineParser.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp\n\nCRC.o: ../../../Common/CRC.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/CRC.cpp\n\nMyWindows.o: ../../../Common/MyWindows.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp\n\nString.o: ../../../Common/String.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/String.cpp\n\nStringConvert.o: ../../../Common/StringConvert.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp\n\nStringToInt.o: ../../../Common/StringToInt.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp\n\nVector.o: ../../../Common/Vector.cpp\n\t$(CXX) $(CFLAGS) ../../../Common/Vector.cpp\n\nclean:\n\t-$(RM) $(PROG) $(OBJS)\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_Alone/Makefile.rg",
    "content": "RGSRC=../../../../../..\ninclude $(RGSRC)/envir.mak\n\nOBJS=LzmaAlone.o LzmaBench.o\n\ninclude $(LZMAMK)\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_Alone/StdAfx.cpp",
    "content": "// StdAfx.cpp\n\n#include \"StdAfx.h\"\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_Alone/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#ifdef WIN32\n#include <windows.h>\n#endif\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_C/LzmaDecode.c",
    "content": "/*\n  LzmaDecode.c\n  LZMA Decoder\n  \n  LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)\n  http://www.7-zip.org/\n\n  LZMA SDK is licensed under two licenses:\n  1) GNU Lesser General Public License (GNU LGPL)\n  2) Common Public License (CPL)\n  It means that you can select one of these two licenses and \n  follow rules of that license.\n\n  SPECIAL EXCEPTION:\n  Igor Pavlov, as the author of this code, expressly permits you to \n  statically or dynamically link your code (or bind by name) to the \n  interfaces of this file without subjecting your linked code to the \n  terms of the CPL or GNU LGPL. Any modifications or additions \n  to this file, however, are subject to the LGPL or CPL terms.\n*/\n\n#include \"LzmaDecode.h\"\n\n#ifndef Byte\n#define Byte unsigned char\n#endif\n\n#define kNumTopBits 24\n#define kTopValue ((UInt32)1 << kNumTopBits)\n\n#define kNumBitModelTotalBits 11\n#define kBitModelTotal (1 << kNumBitModelTotalBits)\n#define kNumMoveBits 5\n\ntypedef struct _CRangeDecoder\n{\n  Byte *Buffer;\n  Byte *BufferLim;\n  UInt32 Range;\n  UInt32 Code;\n  #ifdef _LZMA_IN_CB\n  ILzmaInCallback *InCallback;\n  int Result;\n  #endif\n  int ExtraBytes;\n} CRangeDecoder;\n\nByte RangeDecoderReadByte(CRangeDecoder *rd)\n{\n  if (rd->Buffer == rd->BufferLim)\n  {\n    #ifdef _LZMA_IN_CB\n    UInt32 size;\n    rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);\n    rd->BufferLim = rd->Buffer + size;\n    if (size == 0)\n    #endif\n    {\n      rd->ExtraBytes = 1;\n      return 0xFF;\n    }\n  }\n  return (*rd->Buffer++);\n}\n\n/* #define ReadByte (*rd->Buffer++) */\n#define ReadByte (RangeDecoderReadByte(rd))\n\nvoid RangeDecoderInit(CRangeDecoder *rd,\n  #ifdef _LZMA_IN_CB\n    ILzmaInCallback *inCallback\n  #else\n    Byte *stream, UInt32 bufferSize\n  #endif\n    )\n{\n  int i;\n  #ifdef _LZMA_IN_CB\n  rd->InCallback = inCallback;\n  rd->Buffer = rd->BufferLim = 0;\n  #else\n  rd->Buffer = stream;\n  rd->BufferLim = stream + bufferSize;\n  #endif\n  rd->ExtraBytes = 0;\n  rd->Code = 0;\n  rd->Range = (0xFFFFFFFF);\n  for(i = 0; i < 5; i++)\n    rd->Code = (rd->Code << 8) | ReadByte;\n}\n\n#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;        \n#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;\n#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }\n\nUInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)\n{\n  RC_INIT_VAR\n  UInt32 result = 0;\n  int i;\n  for (i = numTotalBits; i > 0; i--)\n  {\n    /* UInt32 t; */\n    range >>= 1;\n\n    result <<= 1;\n    if (code >= range)\n    {\n      code -= range;\n      result |= 1;\n    }\n    /*\n    t = (code - range) >> 31;\n    t &= 1;\n    code -= range & (t - 1);\n    result = (result + result) | (1 - t);\n    */\n    RC_NORMALIZE\n  }\n  RC_FLUSH_VAR\n  return result;\n}\n\nint RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)\n{\n  UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;\n  if (rd->Code < bound)\n  {\n    rd->Range = bound;\n    *prob += (kBitModelTotal - *prob) >> kNumMoveBits;\n    if (rd->Range < kTopValue)\n    {\n      rd->Code = (rd->Code << 8) | ReadByte;\n      rd->Range <<= 8;\n    }\n    return 0;\n  }\n  else\n  {\n    rd->Range -= bound;\n    rd->Code -= bound;\n    *prob -= (*prob) >> kNumMoveBits;\n    if (rd->Range < kTopValue)\n    {\n      rd->Code = (rd->Code << 8) | ReadByte;\n      rd->Range <<= 8;\n    }\n    return 1;\n  }\n}\n\n#define RC_GET_BIT2(prob, mi, A0, A1) \\\n  UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \\\n  if (code < bound) \\\n    { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \\\n  else \\\n    { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \\\n  RC_NORMALIZE\n\n#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)               \n\nint RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\n{\n  int mi = 1;\n  int i;\n  #ifdef _LZMA_LOC_OPT\n  RC_INIT_VAR\n  #endif\n  for(i = numLevels; i > 0; i--)\n  {\n    #ifdef _LZMA_LOC_OPT\n    CProb *prob = probs + mi;\n    RC_GET_BIT(prob, mi)\n    #else\n    mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);\n    #endif\n  }\n  #ifdef _LZMA_LOC_OPT\n  RC_FLUSH_VAR\n  #endif\n  return mi - (1 << numLevels);\n}\n\nint RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)\n{\n  int mi = 1;\n  int i;\n  int symbol = 0;\n  #ifdef _LZMA_LOC_OPT\n  RC_INIT_VAR\n  #endif\n  for(i = 0; i < numLevels; i++)\n  {\n    #ifdef _LZMA_LOC_OPT\n    CProb *prob = probs + mi;\n    RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))\n    #else\n    int bit = RangeDecoderBitDecode(probs + mi, rd);\n    mi = mi + mi + bit;\n    symbol |= (bit << i);\n    #endif\n  }\n  #ifdef _LZMA_LOC_OPT\n  RC_FLUSH_VAR\n  #endif\n  return symbol;\n}\n\nByte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)\n{ \n  int symbol = 1;\n  #ifdef _LZMA_LOC_OPT\n  RC_INIT_VAR\n  #endif\n  do\n  {\n    #ifdef _LZMA_LOC_OPT\n    CProb *prob = probs + symbol;\n    RC_GET_BIT(prob, symbol)\n    #else\n    symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\n    #endif\n  }\n  while (symbol < 0x100);\n  #ifdef _LZMA_LOC_OPT\n  RC_FLUSH_VAR\n  #endif\n  return symbol;\n}\n\nByte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)\n{ \n  int symbol = 1;\n  #ifdef _LZMA_LOC_OPT\n  RC_INIT_VAR\n  #endif\n  do\n  {\n    int bit;\n    int matchBit = (matchByte >> 7) & 1;\n    matchByte <<= 1;\n    #ifdef _LZMA_LOC_OPT\n    {\n      CProb *prob = probs + ((1 + matchBit) << 8) + symbol;\n      RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)\n    }\n    #else\n    bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd);\n    symbol = (symbol << 1) | bit;\n    #endif\n    if (matchBit != bit)\n    {\n      while (symbol < 0x100)\n      {\n        #ifdef _LZMA_LOC_OPT\n        CProb *prob = probs + symbol;\n        RC_GET_BIT(prob, symbol)\n        #else\n        symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);\n        #endif\n      }\n      break;\n    }\n  }\n  while (symbol < 0x100);\n  #ifdef _LZMA_LOC_OPT\n  RC_FLUSH_VAR\n  #endif\n  return symbol;\n}\n\n#define kNumPosBitsMax 4\n#define kNumPosStatesMax (1 << kNumPosBitsMax)\n\n#define kLenNumLowBits 3\n#define kLenNumLowSymbols (1 << kLenNumLowBits)\n#define kLenNumMidBits 3\n#define kLenNumMidSymbols (1 << kLenNumMidBits)\n#define kLenNumHighBits 8\n#define kLenNumHighSymbols (1 << kLenNumHighBits)\n\n#define LenChoice 0\n#define LenChoice2 (LenChoice + 1)\n#define LenLow (LenChoice2 + 1)\n#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))\n#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))\n#define kNumLenProbs (LenHigh + kLenNumHighSymbols) \n\nint LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)\n{\n  if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)\n    return RangeDecoderBitTreeDecode(p + LenLow +\n        (posState << kLenNumLowBits), kLenNumLowBits, rd);\n  if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)\n    return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +\n        (posState << kLenNumMidBits), kLenNumMidBits, rd);\n  return kLenNumLowSymbols + kLenNumMidSymbols + \n      RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);\n}\n\n#define kNumStates 12\n\n#define kStartPosModelIndex 4\n#define kEndPosModelIndex 14\n#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\n\n#define kNumPosSlotBits 6\n#define kNumLenToPosStates 4\n\n#define kNumAlignBits 4\n#define kAlignTableSize (1 << kNumAlignBits)\n\n#define kMatchMinLen 2\n\n#define IsMatch 0\n#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))\n#define IsRepG0 (IsRep + kNumStates)\n#define IsRepG1 (IsRepG0 + kNumStates)\n#define IsRepG2 (IsRepG1 + kNumStates)\n#define IsRep0Long (IsRepG2 + kNumStates)\n#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))\n#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))\n#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)\n#define LenCoder (Align + kAlignTableSize)\n#define RepLenCoder (LenCoder + kNumLenProbs)\n#define Literal (RepLenCoder + kNumLenProbs)\n\n#if Literal != LZMA_BASE_SIZE\nStopCompilingDueBUG\n#endif\n\n#ifdef _LZMA_OUT_READ\n\ntypedef struct _LzmaVarState\n{\n  CRangeDecoder RangeDecoder;\n  Byte *Dictionary;\n  UInt32 DictionarySize;\n  UInt32 DictionaryPos;\n  UInt32 GlobalPos;\n  UInt32 Reps[4];\n  int lc;\n  int lp;\n  int pb;\n  int State;\n  int PreviousIsMatch;\n  int RemainLen;\n} LzmaVarState;\n\nint LzmaDecoderInit(\n    unsigned char *buffer, UInt32 bufferSize,\n    int lc, int lp, int pb,\n    unsigned char *dictionary, UInt32 dictionarySize,\n    #ifdef _LZMA_IN_CB\n    ILzmaInCallback *inCallback\n    #else\n    unsigned char *inStream, UInt32 inSize\n    #endif\n    )\n{\n  LzmaVarState *vs = (LzmaVarState *)buffer;\n  CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));\n  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));\n  UInt32 i;\n  if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))\n    return LZMA_RESULT_NOT_ENOUGH_MEM;\n  vs->Dictionary = dictionary;\n  vs->DictionarySize = dictionarySize;\n  vs->DictionaryPos = 0;\n  vs->GlobalPos = 0;\n  vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;\n  vs->lc = lc;\n  vs->lp = lp;\n  vs->pb = pb;\n  vs->State = 0;\n  vs->PreviousIsMatch = 0;\n  vs->RemainLen = 0;\n  dictionary[dictionarySize - 1] = 0;\n  for (i = 0; i < numProbs; i++)\n    p[i] = kBitModelTotal >> 1; \n  RangeDecoderInit(&vs->RangeDecoder, \n      #ifdef _LZMA_IN_CB\n      inCallback\n      #else\n      inStream, inSize\n      #endif\n  );\n  return LZMA_RESULT_OK;\n}\n\nint LzmaDecode(unsigned char *buffer, \n    unsigned char *outStream, UInt32 outSize,\n    UInt32 *outSizeProcessed)\n{\n  LzmaVarState *vs = (LzmaVarState *)buffer;\n  CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));\n  CRangeDecoder rd = vs->RangeDecoder;\n  int state = vs->State;\n  int previousIsMatch = vs->PreviousIsMatch;\n  Byte previousByte;\n  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];\n  UInt32 nowPos = 0;\n  UInt32 posStateMask = (1 << (vs->pb)) - 1;\n  UInt32 literalPosMask = (1 << (vs->lp)) - 1;\n  int lc = vs->lc;\n  int len = vs->RemainLen;\n  UInt32 globalPos = vs->GlobalPos;\n\n  Byte *dictionary = vs->Dictionary;\n  UInt32 dictionarySize = vs->DictionarySize;\n  UInt32 dictionaryPos = vs->DictionaryPos;\n\n  if (len == -1)\n  {\n    *outSizeProcessed = 0;\n    return LZMA_RESULT_OK;\n  }\n\n  while(len > 0 && nowPos < outSize)\n  {\n    UInt32 pos = dictionaryPos - rep0;\n    if (pos >= dictionarySize)\n      pos += dictionarySize;\n    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];\n    if (++dictionaryPos == dictionarySize)\n      dictionaryPos = 0;\n    len--;\n  }\n  if (dictionaryPos == 0)\n    previousByte = dictionary[dictionarySize - 1];\n  else\n    previousByte = dictionary[dictionaryPos - 1];\n#else\n\nint LzmaDecode(\n    Byte *buffer, UInt32 bufferSize,\n    int lc, int lp, int pb,\n    #ifdef _LZMA_IN_CB\n    ILzmaInCallback *inCallback,\n    #else\n    unsigned char *inStream, UInt32 inSize,\n    #endif\n    unsigned char *outStream, UInt32 outSize,\n    UInt32 *outSizeProcessed)\n{\n  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));\n  CProb *p = (CProb *)buffer;\n  CRangeDecoder rd;\n  UInt32 i;\n  int state = 0;\n  int previousIsMatch = 0;\n  Byte previousByte = 0;\n  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;\n  UInt32 nowPos = 0;\n  UInt32 posStateMask = (1 << pb) - 1;\n  UInt32 literalPosMask = (1 << lp) - 1;\n  int len = 0;\n#ifdef __LZMA_UNCOMPRESS_KERNEL__\n  UInt32 prev_ind = 0;\n#endif\n  if (bufferSize < numProbs * sizeof(CProb))\n    return LZMA_RESULT_NOT_ENOUGH_MEM;\n  for (i = 0; i < numProbs; i++)\n    p[i] = kBitModelTotal >> 1; \n  RangeDecoderInit(&rd, \n      #ifdef _LZMA_IN_CB\n      inCallback\n      #else\n      inStream, inSize\n      #endif\n      );\n#endif\n\n  *outSizeProcessed = 0;\n  while(nowPos < outSize)\n  {\n    int posState = (int)(\n        (nowPos \n        #ifdef _LZMA_OUT_READ\n        + globalPos\n        #endif\n        )\n        & posStateMask);\n\n#ifdef __LZMA_UNCOMPRESS_KERNEL__\n    if (prev_ind < (nowPos >> 15))\n    {\n\tprev_ind = nowPos >> 15;\n\tputs(\".\");\n    }\n#endif\n    \n    #ifdef _LZMA_IN_CB\n    if (rd.Result != LZMA_RESULT_OK)\n      return rd.Result;\n    #endif\n    if (rd.ExtraBytes != 0)\n      return LZMA_RESULT_DATA_ERROR;\n    if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)\n    {\n      CProb *probs = p + Literal + (LZMA_LIT_SIZE * \n        (((\n        (nowPos \n        #ifdef _LZMA_OUT_READ\n        + globalPos\n        #endif\n        )\n        & literalPosMask) << lc) + (previousByte >> (8 - lc))));\n\n      if (state < 4) state = 0;\n      else if (state < 10) state -= 3;\n      else state -= 6;\n      if (previousIsMatch)\n      {\n        Byte matchByte;\n        #ifdef _LZMA_OUT_READ\n        UInt32 pos = dictionaryPos - rep0;\n        if (pos >= dictionarySize)\n          pos += dictionarySize;\n        matchByte = dictionary[pos];\n        #else\n        matchByte = outStream[nowPos - rep0];\n        #endif\n        previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);\n        previousIsMatch = 0;\n      }\n      else\n        previousByte = LzmaLiteralDecode(probs, &rd);\n      outStream[nowPos++] = previousByte;\n      #ifdef _LZMA_OUT_READ\n      dictionary[dictionaryPos] = previousByte;\n      if (++dictionaryPos == dictionarySize)\n        dictionaryPos = 0;\n      #endif\n    }\n    else             \n    {\n      previousIsMatch = 1;\n      if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)\n      {\n        if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)\n        {\n          if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)\n          {\n            #ifdef _LZMA_OUT_READ\n            UInt32 pos;\n            #endif\n            if (\n               (nowPos \n                #ifdef _LZMA_OUT_READ\n                + globalPos\n                #endif\n               )\n               == 0)\n              return LZMA_RESULT_DATA_ERROR;\n            state = state < 7 ? 9 : 11;\n            #ifdef _LZMA_OUT_READ\n            pos = dictionaryPos - rep0;\n            if (pos >= dictionarySize)\n              pos += dictionarySize;\n            previousByte = dictionary[pos];\n            dictionary[dictionaryPos] = previousByte;\n            if (++dictionaryPos == dictionarySize)\n              dictionaryPos = 0;\n            #else\n            previousByte = outStream[nowPos - rep0];\n            #endif\n            outStream[nowPos++] = previousByte;\n            continue;\n          }\n        }\n        else\n        {\n          UInt32 distance;\n          if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)\n            distance = rep1;\n          else \n          {\n            if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)\n              distance = rep2;\n            else\n            {\n              distance = rep3;\n              rep3 = rep2;\n            }\n            rep2 = rep1;\n          }\n          rep1 = rep0;\n          rep0 = distance;\n        }\n        len = LzmaLenDecode(p + RepLenCoder, &rd, posState);\n        state = state < 7 ? 8 : 11;\n      }\n      else\n      {\n        int posSlot;\n        rep3 = rep2;\n        rep2 = rep1;\n        rep1 = rep0;\n        state = state < 7 ? 7 : 10;\n        len = LzmaLenDecode(p + LenCoder, &rd, posState);\n        posSlot = RangeDecoderBitTreeDecode(p + PosSlot +\n            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << \n            kNumPosSlotBits), kNumPosSlotBits, &rd);\n        if (posSlot >= kStartPosModelIndex)\n        {\n          int numDirectBits = ((posSlot >> 1) - 1);\n          rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);\n          if (posSlot < kEndPosModelIndex)\n          {\n            rep0 += RangeDecoderReverseBitTreeDecode(\n                p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);\n          }\n          else\n          {\n            rep0 += RangeDecoderDecodeDirectBits(&rd, \n                numDirectBits - kNumAlignBits) << kNumAlignBits;\n            rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);\n          }\n        }\n        else\n          rep0 = posSlot;\n        rep0++;\n      }\n      if (rep0 == (UInt32)(0))\n      {\n        /* it's for stream version */\n        len = -1;\n        break;\n      }\n      if (rep0 > nowPos \n        #ifdef _LZMA_OUT_READ\n        + globalPos\n        #endif\n        )\n      {\n        return LZMA_RESULT_DATA_ERROR;\n      }\n      len += kMatchMinLen;\n      do\n      {\n        #ifdef _LZMA_OUT_READ\n        UInt32 pos = dictionaryPos - rep0;\n        if (pos >= dictionarySize)\n          pos += dictionarySize;\n        previousByte = dictionary[pos];\n        dictionary[dictionaryPos] = previousByte;\n        if (++dictionaryPos == dictionarySize)\n          dictionaryPos = 0;\n        #else\n        previousByte = outStream[nowPos - rep0];\n        #endif\n        outStream[nowPos++] = previousByte;\n        len--;\n      }\n      while(len > 0 && nowPos < outSize);\n    }\n  }\n\n  #ifdef _LZMA_OUT_READ\n  vs->RangeDecoder = rd;\n  vs->DictionaryPos = dictionaryPos;\n  vs->GlobalPos = globalPos + nowPos;\n  vs->Reps[0] = rep0;\n  vs->Reps[1] = rep1;\n  vs->Reps[2] = rep2;\n  vs->Reps[3] = rep3;\n  vs->State = state;\n  vs->PreviousIsMatch = previousIsMatch;\n  vs->RemainLen = len;\n  #endif\n\n  *outSizeProcessed = nowPos;\n  return LZMA_RESULT_OK;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_C/LzmaDecode.h",
    "content": "/* \n  LzmaDecode.h\n  LZMA Decoder interface\n\n  LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)\n  http://www.7-zip.org/\n\n  LZMA SDK is licensed under two licenses:\n  1) GNU Lesser General Public License (GNU LGPL)\n  2) Common Public License (CPL)\n  It means that you can select one of these two licenses and \n  follow rules of that license.\n\n  SPECIAL EXCEPTION:\n  Igor Pavlov, as the author of this code, expressly permits you to \n  statically or dynamically link your code (or bind by name) to the \n  interfaces of this file without subjecting your linked code to the \n  terms of the CPL or GNU LGPL. Any modifications or additions \n  to this file, however, are subject to the LGPL or CPL terms.\n*/\n\n#ifndef __LZMADECODE_H\n#define __LZMADECODE_H\n\n/* #define _LZMA_IN_CB */\n/* Use callback for input data */\n\n/* #define _LZMA_OUT_READ */\n/* Use read function for output data */\n\n/* #define _LZMA_PROB32 */\n/* It can increase speed on some 32-bit CPUs, \n   but memory usage will be doubled in that case */\n\n/* #define _LZMA_LOC_OPT */\n/* Enable local speed optimizations inside code */\n\n#ifndef UInt32\n#ifdef _LZMA_UINT32_IS_ULONG\n#define UInt32 unsigned long\n#else\n#define UInt32 unsigned int\n#endif\n#endif\n\n#ifdef _LZMA_PROB32\n#define CProb UInt32\n#else\n#define CProb unsigned short\n#endif\n\n#define LZMA_RESULT_OK 0\n#define LZMA_RESULT_DATA_ERROR 1\n#define LZMA_RESULT_NOT_ENOUGH_MEM 2\n\n#ifdef _LZMA_IN_CB\ntypedef struct _ILzmaInCallback\n{\n  int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);\n} ILzmaInCallback;\n#endif\n\n#define LZMA_BASE_SIZE 1846\n#define LZMA_LIT_SIZE 768\n\n/* \nbufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)\nbufferSize += 100 in case of _LZMA_OUT_READ\nby default CProb is unsigned short, \nbut if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)\n*/\n\n#ifdef _LZMA_OUT_READ\nint LzmaDecoderInit(\n    unsigned char *buffer, UInt32 bufferSize,\n    int lc, int lp, int pb,\n    unsigned char *dictionary, UInt32 dictionarySize,\n  #ifdef _LZMA_IN_CB\n    ILzmaInCallback *inCallback\n  #else\n    unsigned char *inStream, UInt32 inSize\n  #endif\n);\n#endif\n\nint LzmaDecode(\n    unsigned char *buffer, \n  #ifndef _LZMA_OUT_READ\n    UInt32 bufferSize,\n    int lc, int lp, int pb,\n  #ifdef _LZMA_IN_CB\n    ILzmaInCallback *inCallback,\n  #else\n    unsigned char *inStream, UInt32 inSize,\n  #endif\n  #endif\n    unsigned char *outStream, UInt32 outSize,\n    UInt32 *outSizeProcessed);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_C/LzmaTest.c",
    "content": "/* \nLzmaTest.c\nTest application for LZMA Decoder\nLZMA SDK 4.02 Copyright (c) 1999-2004 Igor Pavlov (2004-06-10)\n*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"LzmaDecode.h\"\n\nsize_t MyReadFile(FILE *file, void *data, size_t size)\n{\n  return (fread(data, 1, size, file) == size);\n}\n\n#ifdef _LZMA_IN_CB\ntypedef struct _CBuffer\n{\n  ILzmaInCallback InCallback;\n  unsigned char *Buffer;\n  unsigned int Size;\n} CBuffer;\n\nint LzmaReadCompressed(void *object, unsigned char **buffer, unsigned int *size)\n{\n  CBuffer *bo = (CBuffer *)object;\n  *size = bo->Size; /* You can specify any available size here */\n  *buffer = bo->Buffer;\n  bo->Buffer += *size; \n  bo->Size -= *size;\n  return LZMA_RESULT_OK;\n}\n#endif\n\nint main2(int numargs, const char *args[], char *rs)\n{\n  FILE *inputHandle, *outputHandle;\n  unsigned int length, processedSize;\n  unsigned int compressedSize, outSize, outSizeProcessed, lzmaInternalSize;\n  void *inStream, *outStream, *lzmaInternalData;\n  unsigned char properties[5];\n  unsigned char prop0;\n  int ii;\n  int lc, lp, pb;\n  int res;\n  #ifdef _LZMA_IN_CB\n  CBuffer bo;\n  #endif\n\n  sprintf(rs + strlen(rs), \"\\nLZMA Decoder 4.02 Copyright (c) 1999-2004 Igor Pavlov  2004-06-10\\n\");\n  if (numargs < 2 || numargs > 3)\n  {\n    sprintf(rs + strlen(rs), \"\\nUsage:  lzmaDec file.lzma [outFile]\\n\");\n    return 1;\n  }\n\n  inputHandle = fopen(args[1], \"rb\");\n  if (inputHandle == 0)\n  {\n    sprintf(rs + strlen(rs), \"\\n Open input file error\");\n    return 1;\n  }\n\n  fseek(inputHandle, 0, SEEK_END);\n  length = ftell(inputHandle);\n  fseek(inputHandle, 0, SEEK_SET);\n\n  if (!MyReadFile(inputHandle, properties, sizeof(properties)))\n    return 1;\n  \n  outSize = 0;\n  for (ii = 0; ii < 4; ii++)\n  {\n    unsigned char b;\n    if (!MyReadFile(inputHandle, &b, sizeof(b)))\n      return 1;\n    outSize += (unsigned int)(b) << (ii * 8);\n  }\n\n  if (outSize == 0xFFFFFFFF)\n  {\n    sprintf(rs + strlen(rs), \"\\nstream version is not supported\");\n    return 1;\n  }\n\n  for (ii = 0; ii < 4; ii++)\n  {\n    unsigned char b;\n    if (!MyReadFile(inputHandle, &b, sizeof(b)))\n      return 1;\n    if (b != 0)\n    {\n      sprintf(rs + strlen(rs), \"\\n too long file\");\n      return 1;\n    }\n  }\n\n  compressedSize = length - 13;\n  inStream = malloc(compressedSize);\n  if (inStream == 0)\n  {\n    sprintf(rs + strlen(rs), \"\\n can't allocate\");\n    return 1;\n  }\n  if (!MyReadFile(inputHandle, inStream, compressedSize))\n  {\n    sprintf(rs + strlen(rs), \"\\n can't read\");\n    return 1;\n  }\n\n  fclose(inputHandle);\n\n  prop0 = properties[0];\n  if (prop0 >= (9*5*5))\n  {\n    sprintf(rs + strlen(rs), \"\\n Properties error\");\n    return 1;\n  }\n  for (pb = 0; prop0 >= (9 * 5); \n    pb++, prop0 -= (9 * 5));\n  for (lp = 0; prop0 >= 9; \n    lp++, prop0 -= 9);\n  lc = prop0;\n\n  lzmaInternalSize = \n    (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb);\n\n  #ifdef _LZMA_OUT_READ\n  lzmaInternalSize += 100;\n  #endif\n\n  outStream = malloc(outSize);\n  lzmaInternalData = malloc(lzmaInternalSize);\n  if (outStream == 0 || lzmaInternalData == 0)\n  {\n    sprintf(rs + strlen(rs), \"\\n can't allocate\");\n    return 1;\n  }\n\n  #ifdef _LZMA_IN_CB\n  bo.InCallback.Read = LzmaReadCompressed;\n  bo.Buffer = (unsigned char *)inStream;\n  bo.Size = compressedSize;\n  #endif\n\n  #ifdef _LZMA_OUT_READ\n  {\n    UInt32 nowPos;\n    unsigned char *dictionary;\n    UInt32 dictionarySize = 0;\n    int i;\n    for (i = 0; i < 4; i++)\n      dictionarySize += (UInt32)(properties[1 + i]) << (i * 8);\n    dictionary = malloc(dictionarySize);\n    if (dictionary == 0)\n    {\n      sprintf(rs + strlen(rs), \"\\n can't allocate\");\n      return 1;\n    }\n    LzmaDecoderInit((unsigned char *)lzmaInternalData, lzmaInternalSize,\n        lc, lp, pb,\n        dictionary, dictionarySize,\n        #ifdef _LZMA_IN_CB\n        &bo.InCallback\n        #else\n        (unsigned char *)inStream, compressedSize\n        #endif\n        );\n    for (nowPos = 0; nowPos < outSize;)\n    {\n      UInt32 blockSize = outSize - nowPos;\n      UInt32 kBlockSize = 0x10000;\n      if (blockSize > kBlockSize)\n        blockSize = kBlockSize;\n      res = LzmaDecode((unsigned char *)lzmaInternalData, \n      ((unsigned char *)outStream) + nowPos, blockSize, &outSizeProcessed);\n      if (res != 0)\n      {\n        sprintf(rs + strlen(rs), \"\\nerror = %d\\n\", res);\n        return 1;\n      }\n      if (outSizeProcessed == 0)\n      {\n        outSize = nowPos;\n        break;\n      }\n      nowPos += outSizeProcessed;\n    }\n    free(dictionary);\n  }\n\n  #else\n  res = LzmaDecode((unsigned char *)lzmaInternalData, lzmaInternalSize,\n      lc, lp, pb,\n      #ifdef _LZMA_IN_CB\n      &bo.InCallback,\n      #else\n      (unsigned char *)inStream, compressedSize,\n      #endif\n      (unsigned char *)outStream, outSize, &outSizeProcessed);\n  outSize = outSizeProcessed;\n  #endif\n\n  if (res != 0)\n  {\n    sprintf(rs + strlen(rs), \"\\nerror = %d\\n\", res);\n    return 1;\n  }\n\n  if (numargs > 2)\n  {\n    outputHandle = fopen(args[2], \"wb+\");\n    if (outputHandle == 0)\n    {\n      sprintf(rs + strlen(rs), \"\\n Open output file error\");\n      return 1;\n    }\n    processedSize = fwrite(outStream, 1, outSize, outputHandle);\n    if (processedSize != outSize)\n    {\n      sprintf(rs + strlen(rs), \"\\n can't write\");\n      return 1;\n    }\n    fclose(outputHandle);\n  }\n  free(lzmaInternalData);\n  free(outStream);\n  free(inStream);\n  return 0;\n}\n\nint main(int numargs, const char *args[])\n{\n  char sz[800] = { 0 };\n  int code = main2(numargs, args, sz);\n  printf(sz);\n  return code;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_C/Makefile",
    "content": "PROG = decode\nCC = gcc -O3 -Wall\nLIB = -lm\nRM = rm -f\nCFLAGS = -c\n\nOBJS = \\\n  LzmaDecode.o \\\n  LzmaTest.o \\\n  decode.o\n\nall: $(PROG)\n\n$(PROG): $(OBJS)\n\t$(CC) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)\n\nLzmaDecode.o: LzmaDecode.c\n\t$(CC) $(CFLAGS) LzmaDecode.c\n\nLzmaTest.o: LzmaTest.c\n\t$(CC) $(CFLAGS) LzmaTest.c\n\ndecode.o: decode.c decode.h\n\t$(CC) $(CFLAGS) decode.c\n\nclean:\n\t-$(RM) $(PROG) $(OBJS)\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_C/Makefile.rg",
    "content": "RGSRC=../../../../../..\ninclude $(RGSRC)/envir.mak\n\nMOD_TARGET=lzma_decode.o\nMOD_2_STAT=lzma_decode.o\nO_OBJS=LzmaDecode.o decode.o\n\nLINK_DIR=$(BUILDDIR)/os/linux/lib/lzma_decode\n\ninclude $(RGMK)\n\nifdef CONFIG_RG_LZMA_COMPRESSED_KERNEL\n$(LINK_DIR):\n\tmkdir -p $(BUILDDIR)/os/linux/lib\n\t$(RG_LN) $(PWD_SRC) $@\n\narchconfig::$(LINK_DIR)\nendif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_C/decode.c",
    "content": "/****************************************************************************\n *\n * rg/pkg/lzma/SRC/7zip/Compress/LZMA_C/decode.c\n * \n * Copyright (C) Jungo LTD 2004\n * \n * This program is free software; you can redistribute it\n * and/or modify it under the terms of the GNU General \n * Public License as published by the Free Software\n * Foundation; either version 2 of the License, or (at\n * your option) any later version.\n * \n * This program is distributed in the hope that it will be\n * useful, but WITHOUT ANY WARRANTY; without even the implied\n * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n * See the GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public\n * License along with this program; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n * MA 02111-1307, USA.\n *\n * Developed by Jungo LTD.\n * Residential Gateway Software Division\n * www.jungo.com\n * info@jungo.com\n */\n\n/* Note: This file is included by the kernel and receives its __OS_*__\n * definition from the kernel CFLAGS using -D. This is why we don't\n * include rg_os.h.\n */\n\n//#include <linux/types.h>\n#include <asm/types.h>\n#define u32 __u32\n#define u8  __u8\n#if defined(__KERNEL__) && !defined(__OS_VXWORKS__)\n#include <linux/kernel.h>\n#include <linux/slab.h>\n#include <linux/mm.h>\n#else\n#ifdef __OS_VXWORKS__\n#include <kos/kos.h>\n#endif\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#endif\n\n#include \"LzmaDecode.h\"\n#include \"decode.h\"\n\nstatic u32 lzma_internal_size = 0;\nstatic void *lzma_internal_data = NULL;\n\n#ifdef __LZMA_UNCOMPRESS_KERNEL__\n#define LZMA_ERR(args...) puts(\"LZMA Decode error\\n\");\n#define LZMA_ALLOC(size) malloc(size)\n#define LZMA_FREE free\n#elif defined(__KERNEL__) && !defined(__OS_VXWORKS__)\n#define LZMA_ERR(args...) printk(\"LZMA decode error: \" args)\n#define LZMA_ALLOC(size) kmalloc(size, GFP_KERNEL)\n#define LZMA_FREE kfree\n#else\n#define LZMA_ERR(args...) fprintf(stderr, \"LZMA decode error: \" args)\n#define LZMA_ALLOC(size) malloc(size)\n#define LZMA_FREE free\n#endif\n\nint lzma_decode(void *dst, int dstlen, void *src, int srclen)\n{\n    u8 properties[5], prop0;\n    u32 out_len = 0;\n    int i, lc, lp, pb;\n    int calc_internal_size, res;\n\n    /* Compressed buffer's structure is:\n     * 5 bytes properties\n     * 4 bytes uncompressed length\n     * rest is compressed data. */\n\n    /* Read properties */\n    memcpy(properties, src, 5);\n    src += 5;\n\n    /* Read length */\n    for (i = 0; i < 4; i++)\n\tout_len += (u32)(((u8 *)src)[i]) << (i * 8);\n\n    if (out_len > dstlen)\n    {\n\tLZMA_ERR(\"Out buffer too small - have %d and need %d\\n\", dstlen,\n\t    out_len);\n\treturn -1;\n    }\n    \n    src += 4;\n    srclen -= 9;\n    \n    prop0 = properties[0];\n    if (prop0 >= 9 * 5 * 5)\n    {\n\tLZMA_ERR(\"Properties Error\\n\");\n\treturn -1;\n    }\n    for (pb = 0; prop0 >= 9 * 5; pb++, prop0 -= 9 * 5);\n    for (lp = 0; prop0 >= 9; lp++, prop0 -= 9);\n    lc = prop0;\n   \n    calc_internal_size = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) *\n\tsizeof(CProb);\n    if (calc_internal_size > lzma_internal_size)\n    {\n\tif (lzma_internal_data)\n\t    LZMA_FREE(lzma_internal_data);\n\tif (!(lzma_internal_data = LZMA_ALLOC(calc_internal_size)))\n\t{\n\t    lzma_internal_size = 0;\n\t    LZMA_ERR(\"Error allocating internal data\\n\");\n\t    return -1;\n\t}\n\tlzma_internal_size = calc_internal_size;\n    }\n\n    res = LzmaDecode((u8 *)lzma_internal_data, lzma_internal_size, lc, lp, pb,\n\t(u8 *)src, srclen, (u8 *)dst, out_len, &dstlen);\n\n    if (res)\n    {\n\tLZMA_ERR(\"Decoder internal error (%d)\\n\", res);\n\treturn -1;\n    }\n\n    return dstlen;\n}\n\nvoid lzma_decode_uninit(void)\n{\n   if (lzma_internal_data)\n       LZMA_FREE(lzma_internal_data);\n   lzma_internal_data = NULL;\n   lzma_internal_size = 0;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_C/decode.c.orig",
    "content": "/****************************************************************************\n *\n * rg/pkg/lzma/SRC/7zip/Compress/LZMA_C/decode.c\n * \n * Copyright (C) Jungo LTD 2004\n * \n * This program is free software; you can redistribute it\n * and/or modify it under the terms of the GNU General \n * Public License as published by the Free Software\n * Foundation; either version 2 of the License, or (at\n * your option) any later version.\n * \n * This program is distributed in the hope that it will be\n * useful, but WITHOUT ANY WARRANTY; without even the implied\n * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n * See the GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public\n * License along with this program; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n * MA 02111-1307, USA.\n *\n * Developed by Jungo LTD.\n * Residential Gateway Software Division\n * www.jungo.com\n * info@jungo.com\n */\n\n/* Note: This file is included by the kernel and receives its __OS_*__\n * definition from the kernel CFLAGS using -D. This is why we don't\n * include rg_os.h.\n */\n\n#if defined(__KERNEL__) && !defined(__OS_VXWORKS__)\n#include <linux/kernel.h>\n#include <linux/slab.h>\n#include <linux/mm.h>\n#else\n#ifdef __OS_VXWORKS__\n#include <kos/kos.h>\n#endif\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#endif\n\n#include \"LzmaDecode.h\"\n\nstatic u32 lzma_internal_size = 0;\nstatic void *lzma_internal_data = NULL;\n\n#ifdef __LZMA_UNCOMPRESS_KERNEL__\n#define LZMA_ERR(args...) puts(\"LZMA Decode error\\n\");\n#define LZMA_ALLOC(size) malloc(size)\n#define LZMA_FREE free\n#elif defined(__KERNEL__) && !defined(__OS_VXWORKS__)\n#define LZMA_ERR(args...) printk(\"LZMA decode error: \" args)\n#define LZMA_ALLOC(size) kmalloc(size, GFP_KERNEL)\n#define LZMA_FREE kfree\n#else\n#define LZMA_ERR(args...) fprintf(stderr, \"LZMA decode error: \" args)\n#define LZMA_ALLOC(size) malloc(size)\n#define LZMA_FREE free\n#endif\n\nint lzma_decode(void *dst, int dstlen, void *src, int srclen)\n{\n    u8 properties[5], prop0;\n    u32 out_len = 0;\n    int i, lc, lp, pb;\n    int calc_internal_size, res;\n\n    /* Compressed buffer's structure is:\n     * 5 bytes properties\n     * 4 bytes uncompressed length\n     * rest is compressed data. */\n\n    /* Read properties */\n    memcpy(properties, src, 5);\n    src += 5;\n\n    /* Read length */\n    for (i = 0; i < 4; i++)\n\tout_len += (u32)(((u8 *)src)[i]) << (i * 8);\n\n    if (out_len > dstlen)\n    {\n\tLZMA_ERR(\"Out buffer too small - have %d and need %d\\n\", dstlen,\n\t    out_len);\n\treturn -1;\n    }\n    \n    src += 4;\n    srclen -= 9;\n    \n    prop0 = properties[0];\n    if (prop0 >= 9 * 5 * 5)\n    {\n\tLZMA_ERR(\"Properties Error\\n\");\n\treturn -1;\n    }\n    for (pb = 0; prop0 >= 9 * 5; pb++, prop0 -= 9 * 5);\n    for (lp = 0; prop0 >= 9; lp++, prop0 -= 9);\n    lc = prop0;\n   \n    calc_internal_size = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) *\n\tsizeof(CProb);\n    if (calc_internal_size > lzma_internal_size)\n    {\n\tif (lzma_internal_data)\n\t    LZMA_FREE(lzma_internal_data);\n\tif (!(lzma_internal_data = LZMA_ALLOC(calc_internal_size)))\n\t{\n\t    lzma_internal_size = 0;\n\t    LZMA_ERR(\"Error allocating internal data\\n\");\n\t    return -1;\n\t}\n\tlzma_internal_size = calc_internal_size;\n    }\n\n    res = LzmaDecode((u8 *)lzma_internal_data, lzma_internal_size, lc, lp, pb,\n\t(u8 *)src, srclen, (u8 *)dst, out_len, &dstlen);\n\n    if (res)\n    {\n\tLZMA_ERR(\"Decoder internal error (%d)\\n\", res);\n\treturn -1;\n    }\n\n    return dstlen;\n}\n\nvoid lzma_decode_uninit(void)\n{\n   if (lzma_internal_data)\n       LZMA_FREE(lzma_internal_data);\n   lzma_internal_data = NULL;\n   lzma_internal_size = 0;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/LZMA_C/decode.h",
    "content": "/****************************************************************************\n *\n * rg/pkg/lzma/SRC/7zip/Compress/LZMA_C/decode.c\n * \n * Copyright (C) Jungo LTD 2004\n * \n * This program is free software; you can redistribute it\n * and/or modify it under the terms of the GNU General \n * Public License as published by the Free Software\n * Foundation; either version 2 of the License, or (at\n * your option) any later version.\n * \n * This program is distributed in the hope that it will be\n * useful, but WITHOUT ANY WARRANTY; without even the implied\n * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n * See the GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public\n * License along with this program; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n * MA 02111-1307, USA.\n *\n * Developed by Jungo LTD.\n * Residential Gateway Software Division\n * www.jungo.com\n * info@jungo.com\n */\n\nint lzma_decode(void *dst, int dstlen, void *src, int srclen);\nvoid lzma_decode_uninit(void);\n\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/RangeCoder/Makefile",
    "content": "RGSRC=../../../../../..\ninclude $(RGSRC)/envir.mak\n\nOBJS=RangeCoderBit.o\n\ninclude $(LZMAMK)\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/RangeCoder/RangeCoder.h",
    "content": "// Compress/RangeCoder/RangeCoder.h\n\n#ifndef __COMPRESS_RANGECODER_H\n#define __COMPRESS_RANGECODER_H\n\n#include \"../../Common/InBuffer.h\"\n#include \"../../Common/OutBuffer.h\"\n\nnamespace NCompress {\nnamespace NRangeCoder {\n\nconst int kNumTopBits = 24;\nconst UInt32 kTopValue = (1 << kNumTopBits);\n\nclass CEncoder\n{\n  UInt64 Low;\n  UInt32 Range;\n  UInt32 _ffNum;\n  Byte _cache;\npublic:\n  COutBuffer Stream;\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\n\n  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\n  void Init()\n  {\n    Stream.Init();\n    Low = 0;\n    Range = 0xFFFFFFFF;\n    _ffNum = 0;\n    _cache = 0;\n  }\n\n  void FlushData()\n  {\n    // Low += 1; \n    for(int i = 0; i < 5; i++)\n      ShiftLow();\n  }\n\n  HRESULT FlushStream() { return Stream.Flush();  }\n\n  void ReleaseStream() { Stream.ReleaseStream(); }\n\n  void Encode(UInt32 start, UInt32 size, UInt32 total)\n  {\n    Low += start * (Range /= total);\n    Range *= size;\n    while (Range < kTopValue)\n    {\n      Range <<= 8;\n      ShiftLow();\n    }\n  }\n\n  /*\n  void EncodeDirectBitsDiv(UInt32 value, UInt32 numTotalBits)\n  {\n    Low += value * (Range >>= numTotalBits);\n    Normalize();\n  }\n  \n  void EncodeDirectBitsDiv2(UInt32 value, UInt32 numTotalBits)\n  {\n    if (numTotalBits <= kNumBottomBits)\n      EncodeDirectBitsDiv(value, numTotalBits);\n    else\n    {\n      EncodeDirectBitsDiv(value >> kNumBottomBits, (numTotalBits - kNumBottomBits));\n      EncodeDirectBitsDiv(value & ((1 << kBottomValueBits) - 1), kNumBottomBits);\n    }\n  }\n  */\n  void ShiftLow()\n  {\n    if (Low < (UInt32)0xFF000000 || UInt32(Low >> 32) == 1) \n    {\n      Stream.WriteByte(Byte(_cache + Byte(Low >> 32)));            \n      for (;_ffNum != 0; _ffNum--) \n        Stream.WriteByte(Byte(0xFF + Byte(Low >> 32)));\n      _cache = Byte(UInt32(Low) >> 24);                      \n    } \n    else \n      _ffNum++;                               \n    Low = UInt32(Low) << 8;                           \n  }\n  \n  void EncodeDirectBits(UInt32 value, int numTotalBits)\n  {\n    for (int i = numTotalBits - 1; i >= 0; i--)\n    {\n      Range >>= 1;\n      if (((value >> i) & 1) == 1)\n        Low += Range;\n      if (Range < kTopValue)\n      {\n        Range <<= 8;\n        ShiftLow();\n      }\n    }\n  }\n\n  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\n  {\n    UInt32 newBound = (Range >> numTotalBits) * size0;\n    if (symbol == 0)\n      Range = newBound;\n    else\n    {\n      Low += newBound;\n      Range -= newBound;\n    }\n    while (Range < kTopValue)\n    {\n      Range <<= 8;\n      ShiftLow();\n    }\n  }\n\n  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _ffNum; }\n};\n\nclass CDecoder\n{\npublic:\n  CInBuffer Stream;\n  UInt32 Range;\n  UInt32 Code;\n  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\n\n  void Normalize()\n  {\n    while (Range < kTopValue)\n    {\n      Code = (Code << 8) | Stream.ReadByte();\n      Range <<= 8;\n    }\n  }\n  \n  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\n  void Init()\n  {\n    Stream.Init();\n    Code = 0;\n    Range = 0xFFFFFFFF;\n    for(int i = 0; i < 5; i++)\n      Code = (Code << 8) | Stream.ReadByte();\n  }\n\n  void ReleaseStream() { Stream.ReleaseStream(); }\n\n  UInt32 GetThreshold(UInt32 total)\n  {\n    return (Code) / ( Range /= total);\n  }\n\n  void Decode(UInt32 start, UInt32 size)\n  {\n    Code -= start * Range;\n    Range *= size;\n    Normalize();\n  }\n\n  /*\n  UInt32 DecodeDirectBitsDiv(UInt32 numTotalBits)\n  {\n    Range >>= numTotalBits;\n    UInt32 threshold = Code / Range;\n    Code -= threshold * Range;\n    \n    Normalize();\n    return threshold;\n  }\n\n  UInt32 DecodeDirectBitsDiv2(UInt32 numTotalBits)\n  {\n    if (numTotalBits <= kNumBottomBits)\n      return DecodeDirectBitsDiv(numTotalBits);\n    UInt32 result = DecodeDirectBitsDiv(numTotalBits - kNumBottomBits) << kNumBottomBits;\n    return (result | DecodeDirectBitsDiv(kNumBottomBits));\n  }\n  */\n\n  UInt32 DecodeDirectBits(UInt32 numTotalBits)\n  {\n    UInt32 range = Range;\n    UInt32 code = Code;        \n    UInt32 result = 0;\n    for (UInt32 i = numTotalBits; i > 0; i--)\n    {\n      range >>= 1;\n      /*\n      result <<= 1;\n      if (code >= range)\n      {\n        code -= range;\n        result |= 1;\n      }\n      */\n      UInt32 t = (code - range) >> 31;\n      code -= range & (t - 1);\n      // range = rangeTmp + ((range & 1) & (1 - t));\n      result = (result << 1) | (1 - t);\n\n      if (range < kTopValue)\n      {\n        code = (code << 8) | Stream.ReadByte();\n        range <<= 8; \n      }\n    }\n    Range = range;\n    Code = code;\n    return result;\n  }\n\n  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\n  {\n    UInt32 newBound = (Range >> numTotalBits) * size0;\n    UInt32 symbol;\n    if (Code < newBound)\n    {\n      symbol = 0;\n      Range = newBound;\n    }\n    else\n    {\n      symbol = 1;\n      Code -= newBound;\n      Range -= newBound;\n    }\n    Normalize();\n    return symbol;\n  }\n\n  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/RangeCoder/RangeCoderBit.cpp",
    "content": "// Compress/RangeCoder/RangeCoderBit.cpp\n\n#include \"StdAfx.h\"\n\n#include \"RangeCoderBit.h\"\n\nnamespace NCompress {\nnamespace NRangeCoder {\n\nUInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\nstatic CPriceTables g_PriceTables;\n\nCPriceTables::CPriceTables() { Init(); }\n\nvoid CPriceTables::Init()\n{\n  const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);\n  for(int i = kNumBits - 1; i >= 0; i--)\n  {\n    UInt32 start = 1 << (kNumBits - i - 1);\n    UInt32 end = 1 << (kNumBits - i);\n    for (UInt32 j = start; j < end; j++)\n      ProbPrices[j] = (i << kNumBitPriceShiftBits) + \n          (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));\n  }\n\n  /*\n  // simplest: bad solution\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\n    ProbPrices[i] = kBitPrice;\n  */\n  \n  /*\n  const double kDummyMultMid = (1.0 / kBitPrice) / 2;\n  const double kDummyMultMid = 0;\n  // float solution\n  double ln2 = log(double(2));\n  double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\n    ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);\n  */\n  \n  /*\n  // experimental, slow, solution:\n  for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)\n  {\n    const int kCyclesBits = 5;\n    const UInt32 kCycles = (1 << kCyclesBits);\n\n    UInt32 range = UInt32(-1);\n    UInt32 bitCount = 0;\n    for (UInt32 j = 0; j < kCycles; j++)\n    {\n      range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);\n      range *= i;\n      while(range < (1 << 31))\n      {\n        range <<= 1;\n        bitCount++;\n      }\n    }\n    bitCount <<= kNumBitPriceShiftBits;\n    range -= (1 << 31);\n    for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)\n    {\n      range <<= 1;\n      if (range > (1 << 31))\n      {\n        bitCount += (1 << k);\n        range -= (1 << 31);\n      }\n    }\n    ProbPrices[i] = (bitCount \n      // + (1 << (kCyclesBits - 1))\n      ) >> kCyclesBits;\n  }\n  */\n}\n\n}}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/RangeCoder/RangeCoderBit.h",
    "content": "// Compress/RangeCoder/RangeCoderBit.h\n\n#ifndef __COMPRESS_RANGECODER_BIT_H\n#define __COMPRESS_RANGECODER_BIT_H\n\n#include \"RangeCoder.h\"\n\nnamespace NCompress {\nnamespace NRangeCoder {\n\nconst int kNumBitModelTotalBits  = 11;\nconst UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\n\nconst int kNumMoveReducingBits = 2;\n\nconst int kNumBitPriceShiftBits = 6;\nconst UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\n\nclass CPriceTables\n{\npublic:\n  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\n  static void Init();\n  CPriceTables();\n};\n\ntemplate <int numMoveBits>\nclass CBitModel\n{\npublic:\n  UInt32 Prob;\n  void UpdateModel(UInt32 symbol)\n  {\n    /*\n    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\n    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\n    */\n    if (symbol == 0)\n      Prob += (kBitModelTotal - Prob) >> numMoveBits;\n    else\n      Prob -= (Prob) >> numMoveBits;\n  }\npublic:\n  void Init() { Prob = kBitModelTotal / 2; }\n};\n\ntemplate <int numMoveBits>\nclass CBitEncoder: public CBitModel<numMoveBits>\n{\npublic:\n  void Encode(CEncoder *encoder, UInt32 symbol)\n  {\n    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\n    this->UpdateModel(symbol);\n    /*\n    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\n    if (symbol == 0)\n    {\n      encoder->Range = newBound;\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\n    }\n    else\n    {\n      encoder->Low += newBound;\n      encoder->Range -= newBound;\n      this->Prob -= (this->Prob) >> numMoveBits;\n    }\n    while (encoder->Range < kTopValue)\n    {\n      encoder->Range <<= 8;\n      encoder->ShiftLow();\n    }\n    */\n  }\n  UInt32 GetPrice(UInt32 symbol) const\n  {\n    return CPriceTables::ProbPrices[\n      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\n  }\n};\n\n\ntemplate <int numMoveBits>\nclass CBitDecoder: public CBitModel<numMoveBits>\n{\npublic:\n  UInt32 Decode(CDecoder *decoder)\n  {\n    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\n    if (decoder->Code < newBound)\n    {\n      decoder->Range = newBound;\n      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\n      if (decoder->Range < kTopValue)\n      {\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\n        decoder->Range <<= 8;\n      }\n      return 0;\n    }\n    else\n    {\n      decoder->Range -= newBound;\n      decoder->Code -= newBound;\n      this->Prob -= (this->Prob) >> numMoveBits;\n      if (decoder->Range < kTopValue)\n      {\n        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\n        decoder->Range <<= 8;\n      }\n      return 1;\n    }\n  }\n};\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/RangeCoder/RangeCoderBitTree.h",
    "content": "// Compress/RangeCoder/RangeCoderBitTree.h\n\n#ifndef __COMPRESS_RANGECODER_BIT_TREE_H\n#define __COMPRESS_RANGECODER_BIT_TREE_H\n\n#include \"RangeCoderBit.h\"\n#include \"RangeCoderOpt.h\"\n\nnamespace NCompress {\nnamespace NRangeCoder {\n\ntemplate <int numMoveBits, UInt32 NumBitLevels>\nclass CBitTreeEncoder\n{\n  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];\npublic:\n  void Init()\n  {\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\n      Models[i].Init();\n  }\n  void Encode(CEncoder *rangeEncoder, UInt32 symbol)\n  {\n    UInt32 modelIndex = 1;\n    for (UInt32 bitIndex = NumBitLevels; bitIndex > 0 ;)\n    {\n      bitIndex--;\n      UInt32 bit = (symbol >> bitIndex) & 1;\n      Models[modelIndex].Encode(rangeEncoder, bit);\n      modelIndex = (modelIndex << 1) | bit;\n    }\n  };\n  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)\n  {\n    UInt32 modelIndex = 1;\n    for (UInt32 i = 0; i < NumBitLevels; i++)\n    {\n      UInt32 bit = symbol & 1;\n      Models[modelIndex].Encode(rangeEncoder, bit);\n      modelIndex = (modelIndex << 1) | bit;\n      symbol >>= 1;\n    }\n  }\n  UInt32 GetPrice(UInt32 symbol) const\n  {\n    UInt32 price = 0;\n    UInt32 modelIndex = 1;\n    for (UInt32 bitIndex = NumBitLevels; bitIndex > 0 ;)\n    {\n      bitIndex--;\n      UInt32 bit = (symbol >> bitIndex) & 1;\n      price += Models[modelIndex].GetPrice(bit);\n      modelIndex = (modelIndex << 1) + bit;\n    }\n    return price;\n  }\n  UInt32 ReverseGetPrice(UInt32 symbol) const\n  {\n    UInt32 price = 0;\n    UInt32 modelIndex = 1;\n    for (UInt32 i = NumBitLevels; i > 0; i--)\n    {\n      UInt32 bit = symbol & 1;\n      symbol >>= 1;\n      price += Models[modelIndex].GetPrice(bit);\n      modelIndex = (modelIndex << 1) | bit;\n    }\n    return price;\n  }\n};\n\ntemplate <int numMoveBits, UInt32 NumBitLevels>\nclass CBitTreeDecoder\n{\n  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];\npublic:\n  void Init()\n  {\n    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\n      Models[i].Init();\n  }\n  UInt32 Decode(CDecoder *rangeDecoder)\n  {\n    UInt32 modelIndex = 1;\n    RC_INIT_VAR\n    for(UInt32 bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)\n    {\n      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);\n      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)\n    }\n    RC_FLUSH_VAR\n    return modelIndex - (1 << NumBitLevels);\n  };\n  UInt32 ReverseDecode(CDecoder *rangeDecoder)\n  {\n    UInt32 modelIndex = 1;\n    UInt32 symbol = 0;\n    RC_INIT_VAR\n    for(UInt32 bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\n    {\n      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\n      // modelIndex <<= 1;\n      // modelIndex += bit;\n      // symbol |= (bit << bitIndex);\n      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\n    }\n    RC_FLUSH_VAR\n    return symbol;\n  }\n};\n\ntemplate <int numMoveBits>\nvoid ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models, \n    CEncoder *rangeEncoder, UInt32 NumBitLevels, UInt32 symbol)\n{\n  UInt32 modelIndex = 1;\n  for (UInt32 i = 0; i < NumBitLevels; i++)\n  {\n    UInt32 bit = symbol & 1;\n    Models[modelIndex].Encode(rangeEncoder, bit);\n    modelIndex = (modelIndex << 1) | bit;\n    symbol >>= 1;\n  }\n}\n\ntemplate <int numMoveBits>\nUInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models, \n    UInt32 NumBitLevels, UInt32 symbol)\n{\n  UInt32 price = 0;\n  UInt32 modelIndex = 1;\n  for (UInt32 i = NumBitLevels; i > 0; i--)\n  {\n    UInt32 bit = symbol & 1;\n    symbol >>= 1;\n    price += Models[modelIndex].GetPrice(bit);\n    modelIndex = (modelIndex << 1) | bit;\n  }\n  return price;\n}\n\ntemplate <int numMoveBits>\nUInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models, \n    CDecoder *rangeDecoder, UInt32 NumBitLevels)\n{\n  UInt32 modelIndex = 1;\n  UInt32 symbol = 0;\n  RC_INIT_VAR\n  for(UInt32 bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\n  {\n    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\n    // modelIndex <<= 1;\n    // modelIndex += bit;\n    // symbol |= (bit << bitIndex);\n    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\n  }\n  RC_FLUSH_VAR\n  return symbol;\n}\n\n}}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/RangeCoder/RangeCoderOpt.h",
    "content": "// Compress/RangeCoder/RangeCoderOpt.h\n\n#ifndef __COMPRESS_RANGECODER_OPT_H\n#define __COMPRESS_RANGECODER_OPT_H\n\n#define RC_INIT_VAR \\\n  UInt32 range = rangeDecoder->Range; \\\n  UInt32 code = rangeDecoder->Code;        \n\n#define RC_FLUSH_VAR \\\n  rangeDecoder->Range = range; \\\n  rangeDecoder->Code = code;\n\n#define RC_NORMALIZE \\\n  if (range < NCompress::NRangeCoder::kTopValue) \\\n    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }\n\n#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \\\n  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \\\n  if (code < bound) \\\n  { A0; range = bound; \\\n    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \\\n    mi <<= 1; } \\\n  else \\\n  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \\\n    mi = (mi + mi) + 1; }} \\\n  RC_NORMALIZE\n\n#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Compress/RangeCoder/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#ifdef WIN32\n#include <windows.h>\n#endif\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/ICoder.h",
    "content": "// ICoder.h\n\n#ifndef __ICODER_H\n#define __ICODER_H\n\n#include \"IStream.h\"\n\n// {23170F69-40C1-278A-0000-000200040000}\nDEFINE_GUID(IID_ICompressProgressInfo, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200040000\")\nICompressProgressInfo: public IUnknown\n{\n  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) = 0;\n};\n\n// {23170F69-40C1-278A-0000-000200050000}\nDEFINE_GUID(IID_ICompressCoder, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200050000\")\nICompressCoder: public IUnknown\n{\n  STDMETHOD(Code)(ISequentialInStream *inStream,\n      ISequentialOutStream *outStream, \n      const UInt64 *inSize, \n      const UInt64 *outSize,\n      ICompressProgressInfo *progress) = 0;\n};\n\n// {23170F69-40C1-278A-0000-000200180000}\nDEFINE_GUID(IID_ICompressCoder2, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x18, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200180000\")\nICompressCoder2: public IUnknown\n{\n  STDMETHOD(Code)(ISequentialInStream **inStreams,\n      const UInt64 **inSizes, \n      UInt32 numInStreams,\n      ISequentialOutStream **outStreams, \n      const UInt64 **outSizes,\n      UInt32 numOutStreams,\n      ICompressProgressInfo *progress) PURE;\n};\n\nnamespace NCoderPropID\n{\n  enum EEnum\n  {\n    kDictionarySize = 0x400,\n    kUsedMemorySize,\n    kOrder,\n    kPosStateBits = 0x440,\n    kLitContextBits,\n    kLitPosBits,\n    kNumFastBytes = 0x450,\n    kMatchFinder,\n    kNumPasses = 0x460, \n    kAlgorithm = 0x470,\n    kMultiThread = 0x480,\n    kEndMarker = 0x490\n  };\n}\n\n// {23170F69-40C1-278A-0000-000200200000}\nDEFINE_GUID(IID_ICompressSetCoderProperties, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x20, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200200000\")\nICompressSetCoderProperties: public IUnknown\n{\n  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \n      const PROPVARIANT *properties, UInt32 numProperties) PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200210000}\nDEFINE_GUID(IID_ICompressSetDecoderProperties, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x21, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200210000\")\nICompressSetDecoderProperties: public IUnknown\n{\n  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200230000}\nDEFINE_GUID(IID_ICompressWriteCoderProperties, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x23, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200230000\")\nICompressWriteCoderProperties: public IUnknown\n{\n  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200240000}\nDEFINE_GUID(IID_ICompressGetInStreamProcessedSize, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x24, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200240000\")\nICompressGetInStreamProcessedSize: public IUnknown\n{\n  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200250000}\nDEFINE_GUID(IID_ICompressGetSubStreamSize, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x25, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200250000\")\nICompressGetSubStreamSize: public IUnknown\n{\n  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200260000}\nDEFINE_GUID(IID_ICompressSetInStream, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x26, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200260000\")\nICompressSetInStream: public IUnknown\n{\n  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200270000}\nDEFINE_GUID(IID_ICompressSetOutStream, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x27, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200270000\")\nICompressSetOutStream: public IUnknown\n{\n  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200280000}\nDEFINE_GUID(IID_ICompressSetInStreamSize, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x28, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200280000\")\nICompressSetInStreamSize: public IUnknown\n{\n  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200290000}\nDEFINE_GUID(IID_ICompressSetOutStreamSize, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x29, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200290000\")\nICompressSetOutStreamSize: public IUnknown\n{\n  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\n};\n\n// {23170F69-40C1-278A-0000-000200400000}\nDEFINE_GUID(IID_ICompressFilter, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x40, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200400000\")\nICompressFilter: public IUnknown\n{\n  STDMETHOD(Init)() PURE;\n  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\n  // Filter return outSize (UInt32)\n  // if (outSize <= size): Filter have converted outSize bytes\n  // if (outSize > size): Filter have not converted anything.\n  //      and it needs at least outSize bytes to convert one block \n  //      (it's for crypto block algorithms).\n};\n\n// {23170F69-40C1-278A-0000-000200800000}\nDEFINE_GUID(IID_ICryptoProperties, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x80, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000200800000\")\nICryptoProperties: public IUnknown\n{\n  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\n  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\n};\n\n//////////////////////\n// It's for DLL file\nnamespace NMethodPropID\n{\n  enum EEnum\n  {\n    kID,\n    kName,\n    kDecoder,\n    kEncoder,\n    kInStreams,\n    kOutStreams,\n    kDescription\n  };\n}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/IStream.h",
    "content": "// IStream.h\n\n#ifndef __ISTREAMS_H\n#define __ISTREAMS_H\n\n#include \"../Common/MyUnknown.h\"\n#include \"../Common/Types.h\"\n\n// {23170F69-40C1-278A-0000-000000010000}\nDEFINE_GUID(IID_ISequentialInStream, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000010000\")\nISequentialInStream : public IUnknown\n{\npublic:\n  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) = 0;\n  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize) = 0;\n  \n  // For both function Out: if (*processedSize == 0) then there are \n  // no more bytes in stream.\n  // Read function always tries to read \"size\" bytes from stream. It\n  // can read less only if it reaches end of stream.\n  // ReadPart function can read X bytes: (0<=X<=\"size\") and X can \n  // be less than number of remaining bytes in stream.\n};\n\n// {23170F69-40C1-278A-0000-000000020000}\nDEFINE_GUID(IID_ISequentialOutStream, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000020000\")\nISequentialOutStream : public IUnknown\n{\npublic:\n  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) = 0;\n  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize) = 0;\n};\n\n// {23170F69-40C1-278A-0000-000000030000}\nDEFINE_GUID(IID_IInStream, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000030000\")\nIInStream : public ISequentialInStream\n{\npublic:\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) = 0;\n};\n\n// {23170F69-40C1-278A-0000-000000040000}\nDEFINE_GUID(IID_IOutStream, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000040000\")\nIOutStream : public ISequentialOutStream\n{\npublic:\n  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) = 0;\n  STDMETHOD(SetSize)(Int64 newSize) = 0;\n};\n\n// {23170F69-40C1-278A-0000-000000060000}\nDEFINE_GUID(IID_IStreamGetSize, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000060000\")\nIStreamGetSize : public IUnknown\n{\npublic:\n  STDMETHOD(GetSize)(UInt64 *size) = 0;\n};\n\n// {23170F69-40C1-278A-0000-000000070000}\nDEFINE_GUID(IID_IOutStreamFlush, \n0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00);\nMIDL_INTERFACE(\"23170F69-40C1-278A-0000-000000070000\")\nIOutStreamFlush : public IUnknown\n{\npublic:\n  STDMETHOD(Flush)() = 0;\n};\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/Makefile",
    "content": "RGSRC=../../../..\ninclude $(RGSRC)/envir.mak\n\nOBJS=lzma_encode.o\n\ninclude $(LZMAMK)\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/7zip/lzma_encode.cpp",
    "content": "/****************************************************************************\n *  Copyright (c) 2002 Jungo LTD. All Rights Reserved.\n * \n *  rg/pkg/lzma/SRC/7zip/lzma_encode.cpp\n *\n *  Developed by Jungo LTD.\n *  Residential Gateway Software Division\n *  www.jungo.com\n *  info@jungo.com\n *\n *  This file is part of the OpenRG Software and may not be distributed,\n *  sold, reproduced or copied in any way.\n *\n *  This copyright notice should not be removed\n *\n */\n\n#define INITGUID\n#include \"../Common/MyWindows.h\"\n#include <stdio.h>\n#include \"../Common/StringConvert.h\"\n#include \"../Common/StringToInt.h\"\n#include \"Compress/LZMA/LZMAEncoder.h\"\n#include \"Common/FileStreams.h\"\n\nextern \"C\" int lzma_encode_extended(char *dest, unsigned long *dest_len,\n    char *source, unsigned long src_len, unsigned int dicLog,\n    unsigned int posStateBits, unsigned int litContextBits,\n    unsigned int litPosBits,\n    unsigned int algorithm, unsigned int numFastBytes)\n{\n\n    UString mf = L\"BT4\";\n    UInt32 dictionary = 1 << dicLog;\n\n    CMyComPtr<ISequentialInStream> inStream;\n    CMemInFileStream *memIn = new CMemInFileStream;\n    inStream = memIn;\n    memIn->SetBuffer(source, src_len);\n\n    CMyComPtr<ISequentialOutStream> outStream;\n    CMemOutFileStream *memOut = new CMemOutFileStream;\n    outStream = memOut;\n    memOut->SetBuffer(dest, *dest_len);\n\n    NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;\n    CMyComPtr<ICompressCoder> encoder = encoderSpec;\n\n    PROPID propIDs[] = \n    {\n\tNCoderPropID::kDictionarySize,\n\tNCoderPropID::kPosStateBits,\n\tNCoderPropID::kLitContextBits,\n\tNCoderPropID::kLitPosBits,\n\tNCoderPropID::kAlgorithm,\n\tNCoderPropID::kNumFastBytes,\n\tNCoderPropID::kMatchFinder,\n\tNCoderPropID::kEndMarker\n    };\n\n    const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\n\n    PROPVARIANT properties[kNumProps];\n    for (int p = 0; p < 6; p++)\n\tproperties[p].vt = VT_UI4;\n    properties[0].ulVal = UInt32(dictionary);\n    properties[1].ulVal = UInt32(posStateBits);\n    properties[2].ulVal = UInt32(litContextBits);\n    properties[3].ulVal = UInt32(litPosBits);\n    properties[4].ulVal = UInt32(algorithm);\n    properties[5].ulVal = UInt32(numFastBytes);\n\n    properties[6].vt = VT_BSTR;\n    properties[6].bstrVal = (BSTR)(const wchar_t *)mf;\n\n    properties[7].vt = VT_BOOL;\n    properties[7].boolVal = VARIANT_TRUE;\n\n    if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\n    {\n\tfprintf(stderr, \"Error setting encoder properties\\n\");\n\treturn -1;\n    }\n    encoderSpec->WriteCoderProperties(outStream);\n\n    /* Write the uncompressed size. Original code supported 64bit file size,\n     * but 32 bits are enough for us. */\n    for (int i = 0; i < 4; i++)\n    {\n\tByte b = Byte(src_len >> (8 * i));\n\tif (outStream->Write(&b, sizeof(b), 0) != S_OK)\n\t{\n\t    fprintf(stderr, \"Write error\");\n\t    return -1;\n\t}\n    }\n\n    HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\n    if (result == E_OUTOFMEMORY)\n    {\n\tfprintf(stderr, \"\\nError: Can not allocate memory\\n\");\n\treturn -1;\n    }   \n    else if (result != S_OK)\n    {\n\tfprintf(stderr, \"\\nEncoder error = %X\\n\", (unsigned int)result);\n\treturn -1;\n    }   \n\n    *dest_len = memOut->DataSize();\n    return 0;\n}\n\nextern \"C\" int lzma_encode(char *dest, unsigned long *dest_len, char *source,\n    unsigned long src_len)\n{\n    return lzma_encode_extended(dest, dest_len, source, src_len,\n\t21, /* Dictionary size log */\n\t2, /* Position state bits */\n\t0, /* Literal context bits (3 for normal files, 0 for 32-bit data) */\n\t2, /* Literal position bits (0 for normal files, 2 for 32-bit data) */\n\t2, /* Algorithm (2 is best compression) */\n\t128); /* Number of fast bytes */\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/Alloc.cpp",
    "content": "// Common/Alloc.cpp\n\n#include \"StdAfx.h\"\n\n#ifndef WIN32\n#include <stdlib.h>\n#endif\n\n#include \"Alloc.h\"\n// #include \"NewHandler.h\"\n\nvoid *MyAlloc(size_t size)\n{\n  return ::malloc(size);\n}\n\nvoid MyFree(void *address)\n{\n  ::free(address);\n}\n\nvoid *BigAlloc(size_t size)\n{\n  #ifdef WIN32\n  return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);\n  #else\n  return ::malloc(size);\n  #endif\n}\n\nvoid BigFree(void *address)\n{\n  if (address == 0)\n    return;\n  #ifdef WIN32\n  ::VirtualFree(address, 0, MEM_RELEASE);\n  #else\n  ::free(address);\n  #endif\n}\n\n/*\nvoid *BigAllocE(size_t size)\n{\n  void *res = BigAlloc(size);\n  #ifndef _NO_EXCEPTIONS\n  if (res == 0)\n    throw CNewException();\n  #endif\n  return res;\n}\n*/\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/Alloc.h",
    "content": "// Common/Alloc.h\n\n#ifndef __COMMON_ALLOC_H\n#define __COMMON_ALLOC_H\n\n#include <stddef.h>\n\nvoid *MyAlloc(size_t size);\nvoid MyFree(void *address);\nvoid *BigAlloc(size_t size);\nvoid BigFree(void *address);\n// void *BigAllocE(size_t size);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/CRC.cpp",
    "content": "// Common/CRC.cpp\n\n#include \"StdAfx.h\"\n\n#include \"CRC.h\"\n\nstatic const UInt32 kCRCPoly = 0xEDB88320;\n\nUInt32 CCRC::Table[256];\n\nvoid CCRC::InitTable()\n{\n  for (UInt32 i = 0; i < 256; i++)\n  {\n    UInt32 r = i;\n    for (int j = 0; j < 8; j++)\n      if (r & 1) \n        r = (r >> 1) ^ kCRCPoly;\n      else     \n        r >>= 1;\n    CCRC::Table[i] = r;\n  }\n}\n\nclass CCRCTableInit\n{\npublic:\n  CCRCTableInit() { CCRC::InitTable(); }\n} g_CRCTableInit;\n\nvoid CCRC::UpdateByte(Byte b)\n{\n  _value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);\n}\n\nvoid CCRC::UpdateUInt16(UInt16 v)\n{\n  UpdateByte(Byte(v));\n  UpdateByte(Byte(v >> 8));\n}\n\nvoid CCRC::UpdateUInt32(UInt32 v)\n{\n  for (int i = 0; i < 4; i++)\n    UpdateByte((Byte)(v >> (8 * i)));\n}\n\nvoid CCRC::UpdateUInt64(const UInt64 &v)\n{\n  for (int i = 0; i < 8; i++)\n    UpdateByte((Byte)(v >> (8 * i)));\n}\n\nvoid CCRC::Update(const void *data, UInt32 size)\n{\n  UInt32 v = _value;\n  const Byte *p = (const Byte *)data;\n  for (; size > 0 ; size--, p++)\n    v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);\n  _value = v;\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/CRC.h",
    "content": "// Common/CRC.h\n\n#ifndef __COMMON_CRC_H\n#define __COMMON_CRC_H\n\n#include \"Types.h\"\n\nclass CCRC\n{\n  UInt32 _value;\npublic:\n\tstatic UInt32 Table[256];\n\tstatic void InitTable();\n\n  CCRC():  _value(0xFFFFFFFF){};\n  void Init() { _value = 0xFFFFFFFF; }\n  void UpdateByte(Byte v);\n  void UpdateUInt16(UInt16 v);\n  void UpdateUInt32(UInt32 v);\n  void UpdateUInt64(const UInt64 &v);\n  void Update(const void *data, UInt32 size);\n  UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } \n  static UInt32 CalculateDigest(const void *data, UInt32 size)\n  {\n    CCRC crc;\n    crc.Update(data, size);\n    return crc.GetDigest();\n  }\n  static bool VerifyDigest(UInt32 digest, const void *data, UInt32 size)\n  {\n    return (CalculateDigest(data, size) == digest);\n  }\n};\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/C_FileIO.cpp",
    "content": "// Common/C_FileIO.h\n\n#include \"C_FileIO.h\"\n\n#include <fcntl.h>\n#include <unistd.h>\n\nnamespace NC {\nnamespace NFile {\nnamespace NIO {\n\nbool CFileBase::OpenBinary(const char *name, int flags)\n{\n  #ifdef O_BINARY\n  flags |= O_BINARY;\n  #endif\n  Close();\n  _handle = ::open(name, flags, 0666);\n  return _handle != -1;\n}\n\nbool CFileBase::Close()\n{\n  if(_handle == -1)\n    return true;\n  if (close(_handle) != 0)\n    return false;\n  _handle = -1;\n  return true;\n}\n\nbool CFileBase::GetLength(UInt64 &length) const\n{\n  off_t curPos = Seek(0, SEEK_CUR);\n  off_t lengthTemp = Seek(0, SEEK_END);\n  Seek(curPos, SEEK_SET);\n  length = (UInt64)lengthTemp;\n  return true;\n}\n\noff_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const\n{\n  return ::lseek(_handle, distanceToMove, moveMethod);\n}\n\n/////////////////////////\n// CInFile\n\nbool CInFile::Open(const char *name)\n{\n  return CFileBase::OpenBinary(name, O_RDONLY);\n}\n\nssize_t CInFile::Read(void *data, size_t size)\n{\n  return read(_handle, data, size);\n}\n\n/////////////////////////\n// COutFile\n\nbool COutFile::Create(const char *name, bool createAlways)\n{\n  if (createAlways)\n  {\n    Close();\n    _handle = ::creat(name, 0666);\n    return _handle != -1;\n  }\n  return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);\n}\n\nssize_t COutFile::Write(const void *data, size_t size)\n{\n  return write(_handle, data, size);\n}\n\n}}}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/C_FileIO.h",
    "content": "// Common/C_FileIO.h\n\n#ifndef __COMMON_C_FILEIO_H\n#define __COMMON_C_FILEIO_H\n\n#include <stdio.h>\n#include <sys/types.h>\n\n#include \"Types.h\"\n#include \"MyWindows.h\"\n\nnamespace NC {\nnamespace NFile {\nnamespace NIO {\n\nclass CFileBase\n{\nprotected:\n  int _handle;\n  bool OpenBinary(const char *name, int flags);\npublic:\n  CFileBase(): _handle(-1) {};\n  ~CFileBase() { Close(); }\n  bool Close();\n  bool GetLength(UInt64 &length) const;\n  off_t Seek(off_t distanceToMove, int moveMethod) const;\n};\n\nclass CInFile: public CFileBase\n{\npublic:\n  bool Open(const char *name);\n  ssize_t Read(void *data, size_t size);\n};\n\nclass COutFile: public CFileBase\n{\npublic:\n  bool Create(const char *name, bool createAlways);\n  ssize_t Write(const void *data, size_t size);\n};\n\n}}}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/ComTry.h",
    "content": "// ComTry.h\n\n#ifndef __COM_TRY_H\n#define __COM_TRY_H\n\n#include \"Exception.h\"\n\n#define COM_TRY_BEGIN try {\n#define COM_TRY_END } catch(const CSystemException &e) { return e.ErrorCode; }\\\n    catch(...) { return E_FAIL; }\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/CommandLineParser.cpp",
    "content": "// CommandLineParser.cpp\n\n#include \"StdAfx.h\"\n\n#include \"CommandLineParser.h\"\n\nnamespace NCommandLineParser {\n\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2)\n{\n  dest1.Empty();\n  dest2.Empty();\n  bool quoteMode = false;\n  int i;\n  for (i = 0; i < src.Length(); i++)\n  {\n    wchar_t c = src[i];\n    if (c == L'\\\"')\n      quoteMode = !quoteMode;\n    else if (c == L' ' && !quoteMode)\n    {\n      i++;\n      break;\n    }\n    else \n      dest1 += c;\n  }\n  dest2 = src.Mid(i);\n}\n\nvoid SplitCommandLine(const UString &s, UStringVector &parts)\n{\n  UString sTemp = s;\n  sTemp.Trim();\n  parts.Clear();\n  while (true)\n  {\n    UString s1, s2;\n    SplitCommandLine(sTemp, s1, s2);\n    // s1.Trim();\n    // s2.Trim();\n    if (!s1.IsEmpty())\n      parts.Add(s1);\n    if (s2.IsEmpty())\n      return;\n    sTemp = s2;\n  }\n}\n\n\nstatic const wchar_t kSwitchMinus = '-';\n\nstatic bool IsItSwitchChar(wchar_t c)\n{ \n  return (c == kSwitchMinus); \n}\n\nCParser::CParser(int numSwitches):\n  _numSwitches(numSwitches)\n{\n  _switches = new CSwitchResult[_numSwitches];\n}\n\nCParser::~CParser()\n{\n  delete []_switches;\n}\n\nvoid CParser::ParseStrings(const CSwitchForm *switchForms, \n  const UStringVector &commandStrings)\n{\n  int numCommandStrings = commandStrings.Size();\n  for (int i = 0; i < numCommandStrings; i++)\n    if (!ParseString(commandStrings[i], switchForms))\n      NonSwitchStrings.Add(commandStrings[i]);\n}\n\n// if string contains switch then function updates switch structures\n// out: (string is a switch)\nbool CParser::ParseString(const UString &s, const CSwitchForm *switchForms)\n{\n  int len = s.Length();\n  if (len == 0) \n    return false;\n  int pos = 0;\n  if (!IsItSwitchChar(s[pos]))\n    return false;\n  while(pos < len)\n  {\n    if (IsItSwitchChar(s[pos]))\n      pos++;\n    const int kNoLen = -1;\n    int matchedSwitchIndex = 0; // GCC Warning\n    int maxLen = kNoLen;\n    for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++)\n    {\n      int switchLen = MyStringLen(switchForms[switchIndex].IDString);\n      if (switchLen <= maxLen || pos + switchLen > len) \n        continue;\n\n      UString temp = s + pos;\n      temp = temp.Left(switchLen);\n      if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0)\n      // if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0)\n      {\n        matchedSwitchIndex = switchIndex;\n        maxLen = switchLen;\n      }\n    }\n    if (maxLen == kNoLen)\n      throw \"maxLen == kNoLen\";\n    CSwitchResult &matchedSwitch = _switches[matchedSwitchIndex];\n    const CSwitchForm &switchForm = switchForms[matchedSwitchIndex];\n    if ((!switchForm.Multi) && matchedSwitch.ThereIs)\n      throw \"switch must be single\";\n    matchedSwitch.ThereIs = true;\n    pos += maxLen;\n    int tailSize = len - pos;\n    NSwitchType::EEnum type = switchForm.Type;\n    switch(type)\n    {\n      case NSwitchType::kPostMinus:\n        {\n          if (tailSize == 0)\n            matchedSwitch.WithMinus = false;\n          else\n          {\n            matchedSwitch.WithMinus = (s[pos] == kSwitchMinus);\n            if (matchedSwitch.WithMinus)\n              pos++;\n          }\n          break;\n        }\n      case NSwitchType::kPostChar:\n        {\n          if (tailSize < switchForm.MinLen)\n            throw \"switch is not full\";\n          UString set = switchForm.PostCharSet;\n          const int kEmptyCharValue = -1;\n          if (tailSize == 0)\n            matchedSwitch.PostCharIndex = kEmptyCharValue;\n          else\n          {\n            int index = set.Find(s[pos]);\n            if (index < 0)\n              matchedSwitch.PostCharIndex =  kEmptyCharValue;\n            else\n            {\n              matchedSwitch.PostCharIndex = index;\n              pos++;\n            }\n          }\n          break;\n        }\n      case NSwitchType::kLimitedPostString: \n      case NSwitchType::kUnLimitedPostString: \n        {\n          int minLen = switchForm.MinLen;\n          if (tailSize < minLen)\n            throw \"switch is not full\";\n          if (type == NSwitchType::kUnLimitedPostString)\n          {\n            matchedSwitch.PostStrings.Add(s.Mid(pos));\n            return true;\n          }\n          int maxLen = switchForm.MaxLen;\n          UString stringSwitch = s.Mid(pos, minLen);\n          pos += minLen;\n          for(int i = minLen; i < maxLen && pos < len; i++, pos++)\n          {\n            wchar_t c = s[pos];\n            if (IsItSwitchChar(c))\n              break;\n            stringSwitch += c;\n          }\n          matchedSwitch.PostStrings.Add(stringSwitch);\n          break;\n        }\n      case NSwitchType::kSimple:\n          break;\n    }\n  }\n  return true;\n}\n\nconst CSwitchResult& CParser::operator[](size_t index) const\n{\n  return _switches[index];\n}\n\n/////////////////////////////////\n// Command parsing procedures\n\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \n    const UString &commandString, UString &postString)\n{\n  for(int i = 0; i < numCommandForms; i++)\n  {\n    const UString id = commandForms[i].IDString;\n    if (commandForms[i].PostStringMode)\n    {\n      if(commandString.Find(id) == 0)\n      {\n        postString = commandString.Mid(id.Length());\n        return i;\n      }\n    }\n    else\n      if (commandString == id)\n      {\n        postString.Empty();\n        return i;\n      }\n  }\n  return -1;\n}\n   \nbool ParseSubCharsCommand(int numForms, const CCommandSubCharsSet *forms, \n    const UString &commandString, CIntVector &indices)\n{\n  indices.Clear();\n  int numUsedChars = 0;\n  for(int i = 0; i < numForms; i++)\n  {\n    const CCommandSubCharsSet &set = forms[i];\n    int currentIndex = -1;\n    int len = MyStringLen(set.Chars);\n    for(int j = 0; j < len; j++)\n    {\n      wchar_t c = set.Chars[j];\n      int newIndex = commandString.Find(c);\n      if (newIndex >= 0)\n      {\n        if (currentIndex >= 0)\n          return false;\n        if (commandString.Find(c, newIndex + 1) >= 0)\n          return false;\n        currentIndex = j;\n        numUsedChars++;\n      }\n    }\n    if(currentIndex == -1 && !set.EmptyAllowed)\n      return false;\n    indices.Add(currentIndex);\n  }\n  return (numUsedChars == commandString.Length());\n}\n\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/CommandLineParser.h",
    "content": "// Common/CommandLineParser.h\n\n#ifndef __COMMON_COMMANDLINEPARSER_H\n#define __COMMON_COMMANDLINEPARSER_H\n\n#include \"String.h\"\n\nnamespace NCommandLineParser {\n\nvoid SplitCommandLine(const UString &src, UString &dest1, UString &dest2);\nvoid SplitCommandLine(const UString &s, UStringVector &parts);\n\nnamespace NSwitchType {\n  enum EEnum\n  { \n    kSimple,\n    kPostMinus,\n    kLimitedPostString,\n    kUnLimitedPostString,\n    kPostChar\n  };\n}\n\nstruct CSwitchForm\n{\n  const wchar_t *IDString;\n  NSwitchType::EEnum Type;\n  bool Multi;\n  int MinLen;\n  int MaxLen;\n  const wchar_t *PostCharSet;\n};\n\nstruct CSwitchResult\n{\n  bool ThereIs;\n  bool WithMinus;\n  UStringVector PostStrings;\n  int PostCharIndex;\n  CSwitchResult(): ThereIs(false) {};\n};\n  \nclass CParser\n{\n  int _numSwitches;\n  CSwitchResult *_switches;\n  bool ParseString(const UString &s, const CSwitchForm *switchForms); \npublic:\n  UStringVector NonSwitchStrings;\n  CParser(int numSwitches);\n  ~CParser();\n  void ParseStrings(const CSwitchForm *switchForms, \n    const UStringVector &commandStrings);\n  const CSwitchResult& operator[](size_t index) const;\n};\n\n/////////////////////////////////\n// Command parsing procedures\n\nstruct CCommandForm\n{\n  wchar_t *IDString;\n  bool PostStringMode;\n};\n\n// Returns: Index of form and postString; -1, if there is no match\nint ParseCommand(int numCommandForms, const CCommandForm *commandForms, \n    const UString &commandString, UString &postString);\n\nstruct CCommandSubCharsSet\n{\n  wchar_t *Chars;\n  bool EmptyAllowed;\n};\n\n// Returns: indices of finded chars; -1 if there is no match\nbool ParseSubCharsCommand(int numForms, const CCommandSubCharsSet *forms, \n    const UString &commandString, CIntVector &indices);\n\n}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/Defs.h",
    "content": "// Common/Defs.h\n\n#ifndef __COMMON_DEFS_H\n#define __COMMON_DEFS_H\n\ntemplate <class T> inline T MyMin(T a, T b)\n  {  return a < b ? a : b; }\ntemplate <class T> inline T MyMax(T a, T b)\n  {  return a > b ? a : b; }\n\ntemplate <class T> inline int MyCompare(T a, T b)\n  {  return a < b ? -1 : (a == b ? 0 : 1); }\n\ninline int BoolToInt(bool value)\n  { return (value ? 1: 0); }\n\ninline bool IntToBool(int value)\n  { return (value != 0); }\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/Makefile",
    "content": "RGSRC=../../../..\ninclude $(RGSRC)/envir.mak\n\nOBJS=Alloc.o C_FileIO.o CRC.o String.o StringConvert.o \\\n  StringToInt.o Vector.o CommandLineParser.o\n\ninclude $(LZMAMK)\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/MyCom.h",
    "content": "// MyCom.h\n\n#ifndef __MYCOM_H\n#define __MYCOM_H\n\n#include \"MyWindows.h\"\n\n#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }\n\ntemplate <class T>\nclass CMyComPtr\n{\n  T* _p;\npublic:\n  // typedef T _PtrClass;\n  CMyComPtr() { _p = NULL;}\n  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\n  CMyComPtr(const CMyComPtr<T>& lp)\n  {\n    if ((_p = lp._p) != NULL)\n      _p->AddRef();\n  }\n  ~CMyComPtr() { if (_p) _p->Release(); }\n  void Release() { if (_p) { _p->Release(); _p = NULL; } }\n  operator T*() const {  return (T*)_p;  }\n  // T& operator*() const {  return *_p; }\n  T** operator&() { return &_p; }\n  T* operator->() const { return _p; }\n  T* operator=(T* p) \n  { \n    if (p != 0)\n      p->AddRef();\n    if (_p) \n      _p->Release();\n    _p = p;\n    return p;\n  }\n  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\n  bool operator!() const { return (_p == NULL); }\n  // bool operator==(T* pT) const {  return _p == pT; }\n  // Compare two objects for equivalence\n  void Attach(T* p2)\n  {\n    Release();\n    _p = p2;\n  }\n  T* Detach()\n  {\n    T* pt = _p;\n    _p = NULL;\n    return pt;\n  }\n  #ifdef WIN32\n  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\n  {\n    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\n  }\n  #endif\n  /*\n  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\n  {\n    CLSID clsid;\n    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\n    ATLASSERT(_p == NULL);\n    if (SUCCEEDED(hr))\n      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\n    return hr;\n  }\n  */\n  template <class Q>\n  HRESULT QueryInterface(REFGUID iid, Q** pp) const\n  {\n    return _p->QueryInterface(iid, (void**)pp);\n  }\n};\n\n//////////////////////////////////////////////////////////\n\nclass CMyComBSTR\n{\npublic:\n  BSTR m_str;\n  CMyComBSTR() { m_str = NULL; }\n  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }\n  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\n  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\n  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\n  /*\n  CMyComBSTR(REFGUID src)\n  {\n    LPOLESTR szGuid;\n    StringFromCLSID(src, &szGuid);\n    m_str = ::SysAllocString(szGuid);\n    CoTaskMemFree(szGuid);\n  }\n  */\n  ~CMyComBSTR() { ::SysFreeString(m_str); }\n  CMyComBSTR& operator=(const CMyComBSTR& src)\n  {\n    if (m_str != src.m_str)\n    {\n      if (m_str)\n        ::SysFreeString(m_str);\n      m_str = src.MyCopy();\n    }\n    return *this;\n  }\n  CMyComBSTR& operator=(LPCOLESTR pSrc)\n  {\n    ::SysFreeString(m_str);\n    m_str = ::SysAllocString(pSrc);\n    return *this;\n  }\n  unsigned int Length() const { return ::SysStringLen(m_str); }\n  operator BSTR() const { return m_str; }\n  BSTR* operator&() { return &m_str; }\n  BSTR MyCopy() const \n  { \n    int byteLen = ::SysStringByteLen(m_str);\n    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\n    memmove(res, m_str, byteLen);\n    return res;\n  }\n  void Attach(BSTR src) {  m_str = src; }\n  BSTR Detach()\n  {\n    BSTR s = m_str;\n    m_str = NULL;\n    return s;\n  }\n  void Empty()\n  {\n    ::SysFreeString(m_str);\n    m_str = NULL;\n  }\n  bool operator!() const {  return (m_str == NULL); }\n};\n\n\n//////////////////////////////////////////////////////////\n\nclass CMyUnknownImp\n{\npublic:\n  ULONG __m_RefCount;\n  CMyUnknownImp(): __m_RefCount(0) {}\n};\n\n#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\\n    (REFGUID iid, void **outObject) { \n#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\\n    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\n#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\n\n#define MY_ADDREF_RELEASE \\\nSTDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\\nSTDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\\n  return __m_RefCount; delete this; return 0; }\n\n#define MY_UNKNOWN_IMP_SPEC(i) \\\n  MY_QUERYINTERFACE_BEGIN \\\n  i \\\n  MY_QUERYINTERFACE_END \\\n  MY_ADDREF_RELEASE\n\n\n#define MY_UNKNOWN_IMP MY_UNKNOWN_IMP_SPEC(;)\n\n#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY(i) \\\n  )\n\n#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i2) \\\n  )\n#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i2) \\\n  MY_QUERYINTERFACE_ENTRY(i3) \\\n  )\n#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i2) \\\n  MY_QUERYINTERFACE_ENTRY(i3) \\\n  MY_QUERYINTERFACE_ENTRY(i4) \\\n  )\n\n#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\\n  MY_QUERYINTERFACE_ENTRY(i1) \\\n  MY_QUERYINTERFACE_ENTRY(i2) \\\n  MY_QUERYINTERFACE_ENTRY(i3) \\\n  MY_QUERYINTERFACE_ENTRY(i4) \\\n  MY_QUERYINTERFACE_ENTRY(i5) \\\n  )\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/MyUnknown.h",
    "content": "// MyUnknown.h\n\n#ifndef __MYUNKNOWN_H\n#define __MYUNKNOWN_H\n\n#ifdef WIN32\n\n// #include <guiddef.h>\n#ifdef _WIN32_WCE\n#if (_WIN32_WCE > 300)\n#include <basetyps.h>\n#else\n#define MIDL_INTERFACE(x) struct \n#endif\n#else\n#include <basetyps.h>\n#endif\n\n#include <unknwn.h>\n\n#else \n#include \"MyWindows.h\"\n#endif\n  \n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/MyWindows.h",
    "content": "// MyWindows.h\n\n#ifndef __MYWINDOWS_H\n#define __MYWINDOWS_H\n\n#ifndef WIN32\n\n#include <string.h>\n\n#include \"Types.h\"\n\ntypedef char CHAR;\ntypedef unsigned char UCHAR;\ntypedef unsigned char BYTE;\n\ntypedef short SHORT;\ntypedef unsigned short USHORT;\ntypedef unsigned short WORD;\ntypedef short VARIANT_BOOL;\n\ntypedef int INT;\ntypedef Int32 INT32;\ntypedef unsigned int UINT;\ntypedef UInt32 UINT32;\ntypedef long LONG;\ntypedef unsigned long ULONG;\ntypedef unsigned long DWORD;\n\ntypedef Int64 LONGLONG;\ntypedef UInt64 ULONGLONG;\n\ntypedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\ntypedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\n\ntypedef const CHAR *LPCSTR;\ntypedef CHAR TCHAR;\ntypedef const TCHAR *LPCTSTR;\ntypedef wchar_t WCHAR;\ntypedef WCHAR OLECHAR;\ntypedef const WCHAR *LPCWSTR;\ntypedef OLECHAR *BSTR;\ntypedef const OLECHAR *LPCOLESTR;\ntypedef OLECHAR *LPOLESTR;\n\ntypedef struct _FILETIME\n{\n  DWORD dwLowDateTime;\n  DWORD dwHighDateTime;\n}FILETIME;\n\n#define HRESULT LONG\n#define FAILED(Status) ((HRESULT)(Status)<0)\ntypedef ULONG PROPID;\ntypedef LONG SCODE;\n\n#define S_OK    ((HRESULT)0x00000000L)\n#define S_FALSE ((HRESULT)0x00000001L)\n#define E_NOINTERFACE ((HRESULT)0x80004002L)\n#define E_ABORT ((HRESULT)0x80004004L)\n#define E_FAIL ((HRESULT)0x80004005L)\n#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\n#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\n#define E_INVALIDARG ((HRESULT)0x80070057L)\n\n#ifdef _MSC_VER\n#define STDMETHODCALLTYPE __stdcall \n#else\n#define STDMETHODCALLTYPE \n#endif\n\n#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\n#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\n#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\n#define STDMETHODIMP STDMETHODIMP_(HRESULT)\n\n#define PURE = 0\n\ntypedef struct {\n  unsigned long  Data1;\n  unsigned short Data2;\n  unsigned short Data3;\n  unsigned char Data4[8];\n} GUID;\n\n#ifdef __cplusplus\n    #define MY_EXTERN_C    extern \"C\"\n#else\n    #define MY_EXTERN_C    extern\n#endif\n\n#ifdef INITGUID\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\n      MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\n#else\n  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\\n      MY_EXTERN_C const GUID name\n#endif\n\n#ifdef __cplusplus\n#define REFGUID const GUID &\n#else\n#define REFGUID const GUID * __MIDL_CONST\n#endif\n\n#define REFCLSID REFGUID\n#define REFIID REFGUID\n\n#define MIDL_INTERFACE(x) struct \ninline bool operator==(REFGUID g1, REFGUID g2)\n{ \n  for (size_t i = 0; i < sizeof(g1); i++)\n    if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])\n      return false;\n  return true;\n}\ninline bool operator!=(REFGUID g1, REFGUID g2)\n  { return !(g1 == g2); }\n\nstruct IUnknown\n{\n  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\n  STDMETHOD_(ULONG, AddRef)() PURE;\n  STDMETHOD_(ULONG, Release)() PURE;\n};\n\ntypedef IUnknown *LPUNKNOWN;\n\n#define VARIANT_TRUE ((VARIANT_BOOL)-1)\n#define VARIANT_FALSE ((VARIANT_BOOL)0)\n\nenum VARENUM\n{\t\n  VT_EMPTY\t= 0,\n\tVT_NULL\t= 1,\n\tVT_I2\t= 2,\n\tVT_I4\t= 3,\n\tVT_R4\t= 4,\n\tVT_R8\t= 5,\n\tVT_CY\t= 6,\n\tVT_DATE\t= 7,\n\tVT_BSTR\t= 8,\n\tVT_DISPATCH\t= 9,\n\tVT_ERROR\t= 10,\n\tVT_BOOL\t= 11,\n\tVT_VARIANT\t= 12,\n\tVT_UNKNOWN\t= 13,\n\tVT_DECIMAL\t= 14,\n\tVT_I1\t= 16,\n\tVT_UI1\t= 17,\n\tVT_UI2\t= 18,\n\tVT_UI4\t= 19,\n\tVT_I8\t= 20,\n\tVT_UI8\t= 21,\n\tVT_INT\t= 22,\n\tVT_UINT\t= 23,\n\tVT_VOID\t= 24,\n\tVT_HRESULT\t= 25,\n\tVT_FILETIME\t= 64\n};\n\ntypedef unsigned short VARTYPE;\ntypedef WORD PROPVAR_PAD1;\ntypedef WORD PROPVAR_PAD2;\ntypedef WORD PROPVAR_PAD3;\n\ntypedef struct tagPROPVARIANT\n{\n  VARTYPE vt;\n  PROPVAR_PAD1 wReserved1;\n  PROPVAR_PAD2 wReserved2;\n  PROPVAR_PAD3 wReserved3;\n  union \n  {\n    CHAR cVal;\n    UCHAR bVal;\n    SHORT iVal;\n    USHORT uiVal;\n    LONG lVal;\n    ULONG ulVal;\n    INT intVal;\n    UINT uintVal;\n    LARGE_INTEGER hVal;\n    ULARGE_INTEGER uhVal;\n    VARIANT_BOOL boolVal;\n    SCODE scode;\n    FILETIME filetime;\n    BSTR bstrVal;\n  };\n} PROPVARIANT;\n\ntypedef tagPROPVARIANT tagVARIANT;\ntypedef tagVARIANT VARIANT;\ntypedef VARIANT VARIANTARG;\n\nBSTR SysAllocStringByteLen(LPCSTR psz, unsigned int len);\nBSTR SysAllocString(const OLECHAR *sz);\nvoid SysFreeString(BSTR bstr);\nUINT SysStringByteLen(BSTR bstr);\nUINT SysStringLen(BSTR bstr);\n\nDWORD GetLastError();\nHRESULT VariantClear(VARIANTARG *prop);\nHRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\nLONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\n\n#define CP_ACP    0\n#define CP_OEMCP  1\n\ntypedef enum tagSTREAM_SEEK\n{\t\n  STREAM_SEEK_SET\t= 0,\n  STREAM_SEEK_CUR\t= 1,\n  STREAM_SEEK_END\t= 2\n} STREAM_SEEK;\n\n#endif\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/NewHandler.cpp",
    "content": "// NewHandler.cpp\n \n#include \"StdAfx.h\"\n\n#include \"NewHandler.h\"\n\n// #define DEBUG_MEMORY_LEAK\n\n#ifndef DEBUG_MEMORY_LEAK\n\n\nvoid * __cdecl operator new(size_t size)\n{\n  // void *p = ::HeapAlloc(::GetProcessHeap(), 0, size);\n  void *p = ::malloc(size);\n  if (p == 0)\n    throw CNewException();\n  return p;\n}\n\nvoid __cdecl operator delete(void *p)\n{\n  /*\n  if (p == 0)\n    return;\n  ::HeapFree(::GetProcessHeap(), 0, p);\n  */\n  ::free(p);\n}\n\n#else\n\n#pragma init_seg(lib)\nconst int kDebugSize = 1000000;\nstatic void *a[kDebugSize];\nstatic int index = 0;\n\nstatic int numAllocs = 0;\nvoid * __cdecl operator new(size_t size)\n{\n  numAllocs++;\n  void *p = HeapAlloc(GetProcessHeap(), 0, size);\n  if (index == 40)\n  {\n    int t = 1;\n  }\n  if (index < kDebugSize)\n  {\n    a[index] = p;\n    index++;\n  }\n  if (p == 0)\n    throw CNewException();\n  printf(\"Alloc %6d, size = %8d\\n\", numAllocs, size);\n  return p;\n}\n\nclass CC\n{\npublic:\n  CC()\n  {\n    for (int i = 0; i < kDebugSize; i++)\n      a[i] = 0;\n  }\n  ~CC()\n  {\n    for (int i = 0; i < kDebugSize; i++)\n      if (a[i] != 0)\n        return;\n  }\n} g_CC;\n\n\nvoid __cdecl operator delete(void *p)\n{\n  if (p == 0)\n    return;\n  /*\n  for (int i = 0; i < index; i++)\n    if (a[i] == p)\n      a[i] = 0;\n  */\n  HeapFree(GetProcessHeap(), 0, p);\n  numAllocs--;\n  printf(\"Free %d\\n\", numAllocs);\n}\n\n#endif\n\n/*\nint MemErrorVC(size_t)\n{\n  throw CNewException();\n  // return 1;\n}\nCNewHandlerSetter::CNewHandlerSetter()\n{\n  // MemErrorOldVCFunction = _set_new_handler(MemErrorVC);\n}\nCNewHandlerSetter::~CNewHandlerSetter()\n{\n  // _set_new_handler(MemErrorOldVCFunction);\n}\n*/\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/NewHandler.h",
    "content": "// Common/NewHandler.h\n\n#ifndef __COMMON_NEWHANDLER_H\n#define __COMMON_NEWHANDLER_H\n\nclass CNewException {};\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#ifdef WIN32\n#include <windows.h>\n#endif\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/String.cpp",
    "content": "// Common/String.cpp\n\n#include \"StdAfx.h\"\n\n#ifdef WIN32\n#include \"StringConvert.h\"\n#else\n#include \"ctype.h\"\n#endif\n\n#include \"String.h\"\n\n\n#ifdef WIN32\n\n#ifndef _UNICODE\n\nwchar_t MyCharUpper(wchar_t c)\n{\n  if (c == 0)\n    return 0;\n  wchar_t *res = CharUpperW((LPWSTR)(unsigned int)c);\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return (wchar_t)(unsigned int)res;\n  const int kBufferSize = 4;\n  char s[kBufferSize];\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\n  ::CharUpperA(s);\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\n  return c;\n}\n\nwchar_t MyCharLower(wchar_t c)\n{\n  if (c == 0)\n    return 0;\n  wchar_t *res = CharLowerW((LPWSTR)(unsigned int)c);\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return (wchar_t)(unsigned int)res;\n  const int kBufferSize = 4;\n  char s[kBufferSize];\n  int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0);\n  ::CharLowerA(s);\n  ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1);\n  return c;\n}\n\nwchar_t * MyStringUpper(wchar_t *s)\n{\n  if (s == 0)\n    return 0;\n  wchar_t *res = CharUpperW(s);\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return res;\n  AString a = UnicodeStringToMultiByte(s);\n  a.MakeUpper();\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\n}\n\nwchar_t * MyStringLower(wchar_t *s)\n{ \n  if (s == 0)\n    return 0;\n  wchar_t *res = CharLowerW(s);\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return res;\n  AString a = UnicodeStringToMultiByte(s);\n  a.MakeLower();\n  return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a));\n}\n\n#endif\n\ninline int ConvertCompareResult(int r) { return r - 2; }\n\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2)\n{ \n  int res = CompareStringW(\n        LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); \n  #ifdef _UNICODE\n  return ConvertCompareResult(res);\n  #else\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return ConvertCompareResult(res);\n  return MyStringCollate(UnicodeStringToMultiByte(s1), \n        UnicodeStringToMultiByte(s2));\n  #endif\n}\n\n#ifndef _WIN32_WCE\nint MyStringCollate(const char *s1, const char *s2)\n{ \n  return ConvertCompareResult(CompareStringA(\n    LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); \n}\n\nint MyStringCollateNoCase(const char *s1, const char *s2)\n{ \n  return ConvertCompareResult(CompareStringA(\n    LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); \n}\n#endif\n\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\n{ \n  int res = CompareStringW(\n        LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); \n  #ifdef _UNICODE\n  return ConvertCompareResult(res);\n  #else\n  if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)\n    return ConvertCompareResult(res);\n  return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), \n      UnicodeStringToMultiByte(s2));\n  #endif\n}\n\n#else\n\ninline int NormalizeCompareResult(int res)\n{\n  if (res < 0) return -1;\n  if (res > 0) return 1;\n  return 0;\n}\n\n/*\ninline wchar_t MyCharUpper(wchar_t c)\n  { return towupper(c); }\n*/\nwchar_t MyCharUpper(wchar_t c)\n{\n  return toupper(c);\n}\n\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2)\n{ \n  while (true)\n  {\n    wchar_t c1 = *s1++;\n    wchar_t c2 = *s2++;\n    wchar_t u1 = MyCharUpper(c1);\n    wchar_t u2 = MyCharUpper(c2);\n\n    if (u1 < u2) return -1;\n    if (u1 > u2) return 1;\n    if (u1 == 0) return 0;\n  }\n}\n\n#endif\n\nint MyStringCompare(const char *s1, const char *s2)\n{ \n  while (true)\n  {\n    unsigned char c1 = (unsigned char)*s1++;\n    unsigned char c2 = (unsigned char)*s2++;\n    if (c1 < c2) return -1;\n    if (c1 > c2) return 1;\n    if (c1 == 0) return 0;\n  }\n}\n\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2)\n{ \n  while (true)\n  {\n    wchar_t c1 = *s1++;\n    wchar_t c2 = *s2++;\n    if (c1 < c2) return -1;\n    if (c1 > c2) return 1;\n    if (c1 == 0) return 0;\n  }\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/String.h",
    "content": "// Common/String.h\n\n#ifndef __COMMON_STRING_H\n#define __COMMON_STRING_H\n\n#include <string.h>\n// #include <wchar.h>\n\n#include \"Vector.h\"\n\nstatic const char *kTrimDefaultCharSet  = \" \\n\\t\";\n\ntemplate <class T>\ninline size_t MyStringLen(const T *s)\n{ \n  int i;\n  for (i = 0; s[i] != '\\0'; i++);\n  return i;\n}\n\ntemplate <class T>\ninline T * MyStringCopy(T *dest, const T *src)\n{ \n  T *destStart = dest;\n  while((*dest++ = *src++) != 0);\n  return destStart;\n}\n\ninline wchar_t* MyStringGetNextCharPointer(wchar_t *p)\n  { return (p + 1); }\ninline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p)\n  { return (p + 1); }\ninline wchar_t* MyStringGetPrevCharPointer(const wchar_t *base, wchar_t *p)\n  { return (p - 1); }\ninline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *base, const wchar_t *p)\n  { return (p - 1); }\n\n#ifdef WIN32\n\ninline char* MyStringGetNextCharPointer(char *p)\n  { return CharNextA(p); }\ninline const char* MyStringGetNextCharPointer(const char *p)\n  { return CharNextA(p); }\n\ninline char* MyStringGetPrevCharPointer(char *base, char *p)\n  { return CharPrevA(base, p); }\ninline const char* MyStringGetPrevCharPointer(const char *base, const char *p)\n  { return CharPrevA(base, p); }\n\ninline char MyCharUpper(char c)\n  { return (char)(unsigned int)CharUpperA((LPSTR)(unsigned int)(unsigned char)c); }\n#ifdef _UNICODE\ninline wchar_t MyCharUpper(wchar_t c)\n  { return (wchar_t)CharUpperW((LPWSTR)c); }\n#else\nwchar_t MyCharUpper(wchar_t c);\n#endif\n\ninline char MyCharLower(char c)\n  { return (char)(unsigned int)CharLowerA((LPSTR)(unsigned int)(unsigned char)c); }\n#ifdef _UNICODE\ninline wchar_t MyCharLower(wchar_t c)\n  { return (wchar_t)CharLowerW((LPWSTR)c); }\n#else\nwchar_t MyCharLower(wchar_t c);\n#endif\n\ninline char * MyStringUpper(char *s) { return CharUpperA(s); }\n#ifdef _UNICODE\ninline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); }\n#else\nwchar_t * MyStringUpper(wchar_t *s);\n#endif\n\ninline char * MyStringLower(char *s) { return CharLowerA(s); }\n#ifdef _UNICODE\ninline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); }\n#else\nwchar_t * MyStringLower(wchar_t *s);\n#endif\n\n#else // Standard-C\nwchar_t MyCharUpper(wchar_t c);\n#endif\n\n//////////////////////////////////////\n// Compare\n\n#ifndef _WIN32_WCE\nint MyStringCollate(const char *s1, const char *s2);\nint MyStringCollateNoCase(const char *s1, const char *s2);\n#endif\nint MyStringCollate(const wchar_t *s1, const wchar_t *s2);\nint MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2);\n\nint MyStringCompare(const char *s1, const char  *s2);\nint MyStringCompare(const wchar_t *s1, const wchar_t *s2);\n\ntemplate <class T>\ninline int MyStringCompareNoCase(const T *s1, const T *s2)\n  { return MyStringCollateNoCase(s1, s2); }\n\ntemplate <class T>\nclass CStringBase\n{\n  void TrimLeftWithCharSet(const CStringBase &charSet)\n  {\n    const T *p = _chars;\n    while (charSet.Find(*p) >= 0 && (*p != 0))\n      p = GetNextCharPointer(p);\n    Delete(0, p - _chars);\n  }\n  void TrimRightWithCharSet(const CStringBase &charSet)\n  {\n    const T *p = _chars;\n    const T *pLast = NULL;\n    while (*p != 0)\n    {\n      if (charSet.Find(*p) >= 0)\n      {\n        if (pLast == NULL)\n          pLast = p;\n      }\n      else\n        pLast = NULL;\n      p = GetNextCharPointer(p);\n    }\n    if(pLast != NULL)\n    {\n      int i = pLast - _chars;\n      Delete(i, _length - i);\n    }\n\n  }\n  void MoveItems(int destIndex, int srcIndex)\n  {\n    memmove(_chars + destIndex, _chars + srcIndex, \n        sizeof(T) * (_length - srcIndex + 1));\n  }\n  \n  void InsertSpace(int &index, int size)\n  {\n    CorrectIndex(index);\n    GrowLength(size);\n    MoveItems(index + size, index);\n  }\n\n  static T *GetNextCharPointer(T *p)\n    { return MyStringGetNextCharPointer(p); }\n  static const T *GetNextCharPointer(const T *p)\n    { return MyStringGetNextCharPointer(p); }\n  static T *GetPrevCharPointer(T *base, T *p)\n    { return MyStringGetPrevCharPointer(base, p); }\n  static const T *GetPrevCharPointer(const T *base, const T *p)\n    { return MyStringGetPrevCharPointer(base, p); }\nprotected:\n  T *_chars;\n  int _length;\n\tint _capacity;\n  \n  void SetCapacity(int newCapacity)\n  {\n    int realCapacity = newCapacity + 1;\n    if(realCapacity == _capacity)\n      return;\n    /*\n    const int kMaxStringSize = 0x20000000;\n    #ifndef _WIN32_WCE\n    if(newCapacity > kMaxStringSize || newCapacity < _length)\n      throw 1052337;\n    #endif\n    */\n    T *newBuffer = new T[realCapacity];\n    if(_capacity > 0)\n    {\n      for (int i = 0; i < (_length + 1); i++)\n        newBuffer[i] = _chars[i];\n      delete []_chars;\n      _chars = newBuffer;\n    }\n    else\n    {\n      _chars = newBuffer;\n      _chars[0] = 0;\n    }\n    _capacity = realCapacity;\n  }\n\n  void GrowLength(int n)\n  {\n    int freeSize = _capacity - _length - 1;\n    if (n <= freeSize) \n      return;\n    int delta;\n    if (_capacity > 64)\n      delta = _capacity / 2;\n    else if (_capacity > 8)\n      delta = 16;\n    else\n      delta = 4;\n    if (freeSize + delta < n)\n      delta = n - freeSize;\n    SetCapacity(_capacity + delta);\n  }\n\n  void CorrectIndex(int &index) const\n  {\n    if (index > _length)\n      index = _length;\n  }\n\npublic:\n  CStringBase(): _chars(0), _length(0), _capacity(0)\n    { SetCapacity(16 - 1); }\n  CStringBase(T c):  _chars(0), _length(0), _capacity(0)\n  {\n    SetCapacity(1);\n    _chars[0] = c;\n    _chars[1] = 0;\n    _length = 1;\n  }\n  CStringBase(const T *chars): _chars(0), _length(0), _capacity(0)\n  {\n    int length = MyStringLen(chars);\n    SetCapacity(length);\n    MyStringCopy(_chars, chars); // can be optimized by memove()\n    _length = length;\n  }\n  CStringBase(const CStringBase &s):  _chars(0), _length(0), _capacity(0)\n  {\n    SetCapacity(s._length);\n    MyStringCopy(_chars, s._chars);\n    _length = s._length;\n  }\n  ~CStringBase() {  delete []_chars; }\n\n  operator const T*() const { return _chars;} \n\n  // The minimum size of the character buffer in characters. \n  // This value does not include space for a null terminator.\n  T* GetBuffer(int minBufLength)\n  {\n    if(minBufLength >= _capacity)\n      SetCapacity(minBufLength + 1);\n    return _chars;\n  }\n  void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); }\n  void ReleaseBuffer(int newLength)\n  {\n    /*\n    #ifndef _WIN32_WCE\n    if(newLength >= _capacity)\n      throw 282217;\n    #endif\n    */\n    _chars[newLength] = 0;\n    _length = newLength;\n  }\n\n  CStringBase& operator=(T c)\n  {\n    Empty();\n    SetCapacity(1);\n    _chars[0] = c;\n    _chars[1] = 0;\n    _length = 1;\n    return *this;\n  }\n  CStringBase& operator=(const T *chars)\n  {\n    Empty();\n    int length = MyStringLen(chars);\n    SetCapacity(length);\n    MyStringCopy(_chars, chars);\n    _length = length; \n    return *this;\n  }  \n  CStringBase& operator=(const CStringBase& s)\n  {\n    if(&s == this)\n      return *this;\n    Empty();\n    SetCapacity(s._length);\n    MyStringCopy(_chars, s._chars);\n    _length = s._length;\n    return *this;\n  }\n  \n  CStringBase& operator+=(T c)\n  {\n    GrowLength(1);\n    _chars[_length] = c;\n    _chars[++_length] = 0;\n    return *this;\n  }\n  CStringBase& operator+=(const T *s)\n  {\n    int len = MyStringLen(s);\n    GrowLength(len);\n    MyStringCopy(_chars + _length, s);\n    _length += len;\n    return *this;\n  }\n  CStringBase& operator+=(const CStringBase &s)\n  {\n    GrowLength(s._length);\n    MyStringCopy(_chars + _length, s._chars);\n    _length += s._length;\n    return *this;\n  }\n  void Empty()\n  {\n    _length = 0;\n    _chars[0] = 0;\n  }\n  int Length() const { return _length; }\n  bool IsEmpty() const { return (_length == 0); }\n\n  CStringBase Mid(int startIndex) const\n    { return Mid(startIndex, _length - startIndex); }\n  CStringBase Mid(int startIndex, int count ) const\n  {\n    if (startIndex + count > _length)\n      count = _length - startIndex;\n    \n    if (startIndex == 0 && startIndex + count == _length)\n      return *this;\n    \n    CStringBase<T> result;\n    result.SetCapacity(count);\n    // MyStringNCopy(result._chars, _chars + startIndex, count);\n    for (int i = 0; i < count; i++)\n      result._chars[i] = _chars[startIndex + i];\n    result._chars[count] = 0;\n    result._length = count;\n    return result;\n  }\n  CStringBase Left(int count) const\n    { return Mid(0, count); }\n  CStringBase Right(int count) const\n  {\n    if (count > _length)\n      count = _length;\n    return Mid(_length - count, count);\n  }\n\n  void MakeUpper()\n    { MyStringUpper(_chars); }\n  void MakeLower()\n    { MyStringLower(_chars); }\n\n  int Compare(const CStringBase& s) const\n    { return MyStringCompare(_chars, s._chars); }\n\n  int CompareNoCase(const CStringBase& s) const\n    { return MyStringCompareNoCase(_chars, s._chars); }\n  int Collate(const CStringBase& s) const\n    { return MyStringCollate(_chars, s._chars); }\n  int CollateNoCase(const CStringBase& s) const\n    { return MyStringCollateNoCase(_chars, s._chars); }\n\n  int Find(T c) const { return Find(c, 0); }\n  int Find(T c, int startIndex) const\n  {\n    T *p = _chars + startIndex;\n    while (true)\n    {\n      if (*p == c)\n        return p - _chars;\n      if (*p == 0)\n        return -1;\n      p = GetNextCharPointer(p);\n    }\n  }\n  int Find(const CStringBase &s) const { return Find(s, 0); }\n  int Find(const CStringBase &s, int startIndex) const\n  {\n    if (s.IsEmpty())\n      return startIndex;\n    for (; startIndex < _length; startIndex++)\n    {\n      int j;\n      for (j = 0; j < s._length && startIndex + j < _length; j++)\n        if (_chars[startIndex+j] != s._chars[j])\n          break;\n      if (j == s._length)\n        return startIndex;\n    }\n    return -1;\n  }\n  int ReverseFind(T c) const\n  {\n    if (_length == 0)\n      return -1;\n    T *p = _chars + _length - 1;\n    while (true)\n    {\n      if (*p == c)\n        return p - _chars;\n      if (p == _chars)\n        return -1;\n      p = GetPrevCharPointer(_chars, p);\n    }\n  }\n  int FindOneOf(const CStringBase &s) const\n  {\n    for(int i = 0; i < _length; i++)\n      if (s.Find(_chars[i]) >= 0)\n        return i;\n      return -1;\n  }\n\n  void TrimLeft(T c)\n  {\n    const T *p = _chars;\n    while (c == *p)\n      p = GetNextCharPointer(p);\n    Delete(0, p - _chars);\n  }\n  private:\n  CStringBase GetTrimDefaultCharSet()\n  {\n    CStringBase<T> charSet;\n    for(int i = 0; i < (int)(sizeof(kTrimDefaultCharSet) /\n      sizeof(kTrimDefaultCharSet[0])); i++)\n      charSet += (T)kTrimDefaultCharSet[i];\n    return charSet;\n  }\n  public:\n\n  void TrimLeft()\n  {\n    TrimLeftWithCharSet(GetTrimDefaultCharSet());\n  }\n  void TrimRight()\n  {\n    TrimRightWithCharSet(GetTrimDefaultCharSet());\n  }\n  void TrimRight(T c)\n  {\n    const T *p = _chars;\n    const T *pLast = NULL;\n    while (*p != 0)\n    {\n      if (*p == c)\n      {\n        if (pLast == NULL)\n          pLast = p;\n      }\n      else\n        pLast = NULL;\n      p = GetNextCharPointer(p);\n    }\n    if(pLast != NULL)\n    {\n      int i = pLast - _chars;\n      Delete(i, _length - i);\n    }\n  }\n  void Trim()\n  {\n    TrimRight();\n    TrimLeft();\n  }\n\n  int Insert(int index, T c)\n  {\n    InsertSpace(index, 1);\n    _chars[index] = c;\n    _length++;\n    return _length;\n  }\n  int Insert(int index, const CStringBase &s)\n  {\n    CorrectIndex(index);\n    if (s.IsEmpty())\n      return _length;\n    int numInsertChars = s.Length();\n    InsertSpace(index, numInsertChars);\n    for(int i = 0; i < numInsertChars; i++)\n      _chars[index + i] = s[i];\n    _length += numInsertChars;\n    return _length;\n  }\n\n  // !!!!!!!!!!!!!!! test it if newChar = '\\0'\n  int Replace(T oldChar, T newChar)\n  {\n    if (oldChar == newChar)\n      return 0;\n    int number  = 0;\n    int pos  = 0;\n    while (pos < Length())\n    {\n      pos = Find(oldChar, pos);\n      if (pos < 0) \n        break;\n      _chars[pos] = newChar;\n      pos++;\n      number++;\n    }\n    return number;\n  }\n  int Replace(const CStringBase &oldString, const CStringBase &newString)\n  {\n    if (oldString.IsEmpty())\n      return 0;\n    if (oldString == newString)\n      return 0;\n    int oldStringLength = oldString.Length();\n    int newStringLength = newString.Length();\n    int number  = 0;\n    int pos  = 0;\n    while (pos < _length)\n    {\n      pos = Find(oldString, pos);\n      if (pos < 0) \n        break;\n      Delete(pos, oldStringLength);\n      Insert(pos, newString);\n      pos += newStringLength;\n      number++;\n    }\n    return number;\n  }\n  int Delete(int index, int count = 1 )\n  {\n    if (index + count > _length)\n      count = _length - index;\n    if (count > 0)\n    {\n      MoveItems(index, index + count);\n      _length -= count;\n    }\n    return _length;\n  }\n};\n\ntemplate <class T>\nCStringBase<T> operator+(const CStringBase<T>& s1, const CStringBase<T>& s2)\n{\n  CStringBase<T> result(s1);\n  result += s2;\n  return result; \n}\n\ntemplate <class T>\nCStringBase<T> operator+(const CStringBase<T>& s, T c)\n{\n  CStringBase<T> result(s);\n  result += c;\n  return result; \n}\n\ntemplate <class T>\nCStringBase<T> operator+(T c, const CStringBase<T>& s)\n{\n  CStringBase<T> result(c);\n  result += s;\n  return result; \n}\n\ntemplate <class T>\nCStringBase<T> operator+(const CStringBase<T>& s, const T * chars)\n{\n  CStringBase<T> result(s);\n  result += chars;\n  return result; \n}\n\ntemplate <class T>\nCStringBase<T> operator+(const T * chars, const CStringBase<T>& s)\n{\n  CStringBase<T> result(chars);\n  result += s;\n  return result; \n}\n\ntemplate <class T>\nbool operator==(const CStringBase<T>& s1, const CStringBase<T>& s2)\n  { return (s1.Compare(s2) == 0); }\n\ntemplate <class T>\nbool operator<(const CStringBase<T>& s1, const CStringBase<T>& s2)\n  { return (s1.Compare(s2) < 0); }\n\ntemplate <class T>\nbool operator==(const T *s1, const CStringBase<T>& s2)\n  { return (s2.Compare(s1) == 0); }\n\ntemplate <class T>\nbool operator==(const CStringBase<T>& s1, const T *s2)\n  { return (s1.Compare(s2) == 0); }\n\ntemplate <class T>\nbool operator!=(const CStringBase<T>& s1, const CStringBase<T>& s2)\n  { return (s1.Compare(s2) != 0); }\n\ntemplate <class T>\nbool operator!=(const T *s1, const CStringBase<T>& s2)\n  { return (s2.Compare(s1) != 0); }\n\ntemplate <class T>\nbool operator!=(const CStringBase<T>& s1, const T *s2)\n  { return (s1.Compare(s2) != 0); }\n\ntypedef CStringBase<char> AString;\ntypedef CStringBase<wchar_t> UString;\n\ntypedef CObjectVector<AString> AStringVector;\ntypedef CObjectVector<UString> UStringVector;\n\n#ifdef _UNICODE\n  typedef UString CSysString;\n#else\n  typedef AString CSysString;\n#endif\n\ntypedef CObjectVector<CSysString> CSysStringVector;\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/StringConvert.cpp",
    "content": "// Common/StringConvert.cpp\n\n#include \"StdAfx.h\"\n\n#include \"StringConvert.h\"\n\n#ifndef WIN32\n#include <stdlib.h>\n#endif\n\n#ifdef WIN32\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\n{\n  UString resultString;\n  if(!srcString.IsEmpty())\n  {\n    int numChars = MultiByteToWideChar(codePage, 0, srcString, \n      srcString.Length(), resultString.GetBuffer(srcString.Length()), \n      srcString.Length() + 1);\n    #ifndef _WIN32_WCE\n    if(numChars == 0)\n      throw 282228;\n    #endif\n    resultString.ReleaseBuffer(numChars);\n  }\n  return resultString;\n}\n\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\n{\n  AString resultString;\n  if(!srcString.IsEmpty())\n  {\n    int numRequiredBytes = srcString.Length() * 2;\n    int numChars = WideCharToMultiByte(codePage, 0, srcString, \n      srcString.Length(), resultString.GetBuffer(numRequiredBytes), \n      numRequiredBytes + 1, NULL, NULL);\n    #ifndef _WIN32_WCE\n    if(numChars == 0)\n      throw 282229;\n    #endif\n    resultString.ReleaseBuffer(numChars);\n  }\n  return resultString;\n}\n\n#ifndef _WIN32_WCE\nAString SystemStringToOemString(const CSysString &srcString)\n{\n  AString result;\n  CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));\n  result.ReleaseBuffer();\n  return result;\n}\n#endif\n\n#else\n\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage)\n{\n  UString resultString;\n  for (int i = 0; i < srcString.Length(); i++)\n    resultString += wchar_t(srcString[i]);\n  /*\n  if(!srcString.IsEmpty())\n  {\n    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\n    resultString.ReleaseBuffer(numChars);\n  }\n  */\n  return resultString;\n}\n\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)\n{\n  AString resultString;\n  for (int i = 0; i < srcString.Length(); i++)\n    resultString += char(srcString[i]);\n  /*\n  if(!srcString.IsEmpty())\n  {\n    int numRequiredBytes = srcString.Length() * 6 + 1;\n    int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);\n    if (numChars < 0) throw \"Your environment does not support UNICODE\";\n    resultString.ReleaseBuffer(numChars);\n  }\n  */\n  return resultString;\n}\n\n#endif\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/StringConvert.h",
    "content": "// Common/StringConvert.h\n\n#ifndef __COMMON_STRINGCONVERT_H\n#define __COMMON_STRINGCONVERT_H\n\n#include \"MyWindows.h\"\n#include \"String.h\"\n#include \"Types.h\"\n\nUString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP);\nAString UnicodeStringToMultiByte(const UString &srcString, UINT codePage = CP_ACP);\n\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString)\n  { return unicodeString; }\ninline const UString& GetUnicodeString(const UString &unicodeString)\n  { return unicodeString; }\ninline UString GetUnicodeString(const AString &ansiString)\n  { return MultiByteToUnicodeString(ansiString); }\ninline UString GetUnicodeString(const AString &multiByteString, UINT codePage)\n  { return MultiByteToUnicodeString(multiByteString, codePage); }\ninline const wchar_t* GetUnicodeString(const wchar_t* unicodeString, UINT codePage)\n  { return unicodeString; }\ninline const UString& GetUnicodeString(const UString &unicodeString, UINT codePage)\n  { return unicodeString; }\n\ninline const char* GetAnsiString(const char* ansiString)\n  { return ansiString; }\ninline const AString& GetAnsiString(const AString &ansiString)\n  { return ansiString; }\ninline AString GetAnsiString(const UString &unicodeString)\n  { return UnicodeStringToMultiByte(unicodeString); }\n\ninline const char* GetOemString(const char* oemString)\n  { return oemString; }\ninline const AString& GetOemString(const AString &oemString)\n  { return oemString; }\ninline AString GetOemString(const UString &unicodeString)\n  { return UnicodeStringToMultiByte(unicodeString, CP_OEMCP); }\n\n\n#ifdef _UNICODE\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString)\n    { return unicodeString;}\n  inline const UString& GetSystemString(const UString &unicodeString)\n    { return unicodeString;}\n  inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT codePage)\n    { return unicodeString;}\n  inline const UString& GetSystemString(const UString &unicodeString, UINT codePage)\n    { return unicodeString;}\n  inline UString GetSystemString(const AString &multiByteString, UINT codePage)\n    { return MultiByteToUnicodeString(multiByteString, codePage);}\n  inline UString GetSystemString(const AString &multiByteString)\n    { return MultiByteToUnicodeString(multiByteString);}\n#else\n  inline const char* GetSystemString(const char *ansiString)\n    { return ansiString; }\n  inline const AString& GetSystemString(const AString &multiByteString, UINT codePage)\n    { return multiByteString; }\n  inline const char * GetSystemString(const char *multiByteString, UINT codePage)\n    { return multiByteString; }\n  inline AString GetSystemString(const UString &unicodeString)\n    { return UnicodeStringToMultiByte(unicodeString); }\n  inline AString GetSystemString(const UString &unicodeString, UINT codePage)\n    { return UnicodeStringToMultiByte(unicodeString, codePage); }\n#endif\n\n#ifndef _WIN32_WCE\nAString SystemStringToOemString(const CSysString &srcString);\n#endif\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/StringToInt.cpp",
    "content": "// Common/StringToInt.cpp\n\n#include \"StdAfx.h\"\n\n#include \"StringToInt.h\"\n\nUInt64 ConvertStringToUInt64(const char *s, const char **end)\n{\n  UInt64 result = 0;\n  while(true)\n  {\n    char c = *s;\n    if (c < '0' || c > '9')\n    {\n      if (end != NULL)\n        *end = s;\n      return result;\n    }\n    result *= 10;\n    result += (c - '0');\n    s++;\n  }\n}\n\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end)\n{\n  UInt64 result = 0;\n  while(true)\n  {\n    wchar_t c = *s;\n    if (c < '0' || c > '9')\n    {\n      if (end != NULL)\n        *end = s;\n      return result;\n    }\n    result *= 10;\n    result += (c - '0');\n    s++;\n  }\n}\n\n\nInt64 ConvertStringToInt64(const char *s, const char **end)\n{\n  if (*s == '-')\n    return -(Int64)ConvertStringToUInt64(s + 1, end);\n  return ConvertStringToUInt64(s, end);\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/StringToInt.h",
    "content": "// Common/StringToInt.h\n\n#ifndef __COMMON_STRINGTOINT_H\n#define __COMMON_STRINGTOINT_H\n\n#include <string.h>\n#include \"Types.h\"\n\nUInt64 ConvertStringToUInt64(const char *s, const char **end);\nUInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end);\n\nInt64 ConvertStringToInt64(const char *s, const char **end);\n\n#endif\n\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/Types.h",
    "content": "// Common/Types.h\n\n#ifndef __COMMON_TYPES_H\n#define __COMMON_TYPES_H\n\ntypedef unsigned char Byte;\ntypedef short Int16;\ntypedef unsigned short UInt16;\ntypedef int Int32;\ntypedef unsigned int UInt32;\n#ifdef _MSC_VER\ntypedef __int64 Int64;\ntypedef unsigned __int64 UInt64;\n#else\ntypedef long long int Int64;\ntypedef unsigned long long int UInt64;\n#endif\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/Vector.cpp",
    "content": "// Common/Vector.cpp\n\n#include \"StdAfx.h\"\n\n#include <string.h>\n\n#include \"Vector.h\"\n\nCBaseRecordVector::~CBaseRecordVector()\n  { delete []((unsigned char *)_items); }\nvoid CBaseRecordVector::Clear() \n  { DeleteFrom(0); }\nvoid CBaseRecordVector::DeleteBack() \n  { Delete(_size - 1); }\nvoid CBaseRecordVector::DeleteFrom(int index)\n  { Delete(index, _size - index); }\n\nvoid CBaseRecordVector::ReserveOnePosition()\n{\n  if(_size != _capacity)\n    return;\n  int delta;\n  if (_capacity > 64)\n    delta = _capacity / 2;\n  else if (_capacity > 8)\n    delta = 8;\n  else\n    delta = 4;\n  Reserve(_capacity + delta);\n}\n\nvoid CBaseRecordVector::Reserve(int newCapacity)\n{\n  if(newCapacity <= _capacity)\n    return;\n  /*\n  #ifndef _DEBUG\n  static const unsigned int kMaxVectorSize = 0xF0000000;\n  if(newCapacity < _size || \n      ((unsigned int )newCapacity * (unsigned int )_itemSize) > kMaxVectorSize) \n    throw 1052354;\n  #endif\n  */\n  unsigned char *p = new unsigned char[newCapacity * _itemSize];\n  int numRecordsToMove = _capacity;\n  memmove(p, _items, _itemSize * numRecordsToMove);\n  delete [](unsigned char *)_items;\n  _items = p;\n  _capacity = newCapacity;\n}\n\nvoid CBaseRecordVector::MoveItems(int destIndex, int srcIndex)\n{\n  memmove(((unsigned char *)_items) + destIndex * _itemSize, \n    ((unsigned char  *)_items) + srcIndex * _itemSize, \n    _itemSize * (_size - srcIndex));\n}\n\nvoid CBaseRecordVector::InsertOneItem(int index)\n{\n  ReserveOnePosition();\n  MoveItems(index + 1, index);\n  _size++;\n}\n\nvoid CBaseRecordVector::Delete(int index, int num)\n{\n  TestIndexAndCorrectNum(index, num);\n  if (num > 0)\n  {\n    MoveItems(index, index + num);\n    _size -= num;\n  }\n}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Common/Vector.h",
    "content": "// Common/Vector.h\n\n#ifndef __COMMON_VECTOR_H\n#define __COMMON_VECTOR_H\n\n#include \"Defs.h\"\n\nclass CBaseRecordVector\n{\n  void MoveItems(int destIndex, int srcIndex);\nprotected:\n\tint _capacity;\n  int _size;\n\tvoid *_items;\n  size_t _itemSize;\n\n\tvoid ReserveOnePosition();\n  void InsertOneItem(int index);\n  void TestIndexAndCorrectNum(int index, int &num) const\n    { if (index + num > _size) num = _size - index; } \npublic:\n  CBaseRecordVector(size_t itemSize):\n      _capacity(0), _size(0), _items(0), _itemSize(itemSize) {}\n\tvirtual ~CBaseRecordVector();\n  int Size() const { return _size; }\n\tbool IsEmpty() const { return (_size == 0); }\n\tvoid Reserve(int newCapacity);\n\tvirtual void Delete(int index, int num = 1);\n\tvoid Clear();\n  void DeleteFrom(int index);\n  void DeleteBack();\n};\n\ntemplate <class T>\nclass CRecordVector: public CBaseRecordVector\n{\npublic:\n  CRecordVector():CBaseRecordVector(sizeof(T)){};\n  CRecordVector(const CRecordVector &v):\n    CBaseRecordVector(sizeof(T)) { *this = v;}\n\tCRecordVector& operator=(const CRecordVector &v)\n  {\n    Clear();\n    return (*this += v);\n  }\n  CRecordVector& operator+=(const CRecordVector &v)\n  {\n    int size = v.Size();\n    Reserve(Size() + size);\n    for(int i = 0; i < size; i++)\n      Add(v[i]);\n    return *this;\n  }\n\tint Add(T item)\n  {\n    ReserveOnePosition();\n    ((T *)_items)[_size] = item;\n    return _size++;\n  }\n\tvoid Insert(int index, T item)\n  {\n    InsertOneItem(index);\n    ((T *)_items)[index] = item;\n  }\n  // T* GetPointer() const { return (T*)_items; }\n  // operator const T *() const { return _items; };\n  const T& operator[](int index) const { return ((T *)_items)[index]; }\n\tT& operator[](int index) { return ((T *)_items)[index]; }\n\tconst T& Front() const { return operator[](0); }\n  T& Front()   { return operator[](0); }\n\tconst T& Back() const { return operator[](_size - 1); }\n  T& Back()   { return operator[](_size - 1); }\n  static int \n  #ifdef _MSC_VER\n  __cdecl\n  #endif\n  CompareRecordItems(const void *a1, const void *a2)\n    { return MyCompare(*((const T *)a1), *((const T *)a2)); }\n  void Sort()\n    { qsort(&Front(), Size(), _itemSize, CompareRecordItems); }\n};\n\ntypedef CRecordVector<int> CIntVector;\ntypedef CRecordVector<unsigned int> CUIntVector;\ntypedef CRecordVector<bool> CBoolVector;\ntypedef CRecordVector<unsigned char> CByteVector;\ntypedef CRecordVector<void *> CPointerVector;\n\ntemplate <class T>\nclass CObjectVector: public CPointerVector\n{\npublic:\n  CObjectVector(){};\n  ~CObjectVector() { Clear(); }\n  CObjectVector(const CObjectVector &objectVector)\n    { *this = objectVector; }\n\tCObjectVector& operator=(const CObjectVector &objectVector)\n  {\n    Clear();\n    return (*this += objectVector);\n  }\n\tCObjectVector& operator+=(const CObjectVector &objectVector)\n  {\n    int size = objectVector.Size();\n    Reserve(Size() + size);\n    for(int i = 0; i < size; i++)\n      Add(objectVector[i]);\n    return *this;\n  }\n\tconst T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); }\n\tT& operator[](int index) { return *((T *)CPointerVector::operator[](index)); }\n\tT& Front() { return operator[](0); }\n\tconst T& Front() const { return operator[](0); }\n\tT& Back() { return operator[](_size - 1); }\n\tconst T& Back() const { return operator[](_size - 1); }\n\tint Add(const T& item)\n    { return CPointerVector::Add(new T(item)); }\n\tvoid Insert(int index, const T& item)\n    { CPointerVector::Insert(index, new T(item)); }\n\tvirtual void Delete(int index, int num = 1)\n  {\n    TestIndexAndCorrectNum(index, num);\n    for(int i = 0; i < num; i++)\n      delete (T *)(((void **)_items)[index + i]);\n    CPointerVector::Delete(index, num);\n  }\n  int Find(const T& item) const\n  {\n    for(int i = 0; i < Size(); i++)\n      if (item == (*this)[i])\n        return i;\n      return -1;\n  }\n  int FindInSorted(const T& item) const\n  {\n    int left = 0, right = Size(); \n    while (left != right)\n    {\n      int mid = (left + right) / 2;\n      const T& midValue = (*this)[mid];\n      if (item == midValue)\n        return mid;\n      if (item < midValue)\n        right = mid;\n      else\n        left = mid + 1;\n    }\n    return -1;\n  }\n  int AddToSorted(const T& item)\n  {\n    int left = 0, right = Size(); \n    while (left != right)\n    {\n      int mid = (left + right) / 2;\n      const T& midValue = (*this)[mid];\n      if (item == midValue)\n      {\n        right = mid + 1;\n        break;\n      }\n      if (item < midValue)\n        right = mid;\n      else\n        left = mid + 1;\n    }\n    Insert(right, item);\n    return right;\n  }\n  static int\n  #ifdef _MSC_VER\n  __cdecl\n  #endif\n  CompareObjectItems(const void *a1, const void *a2)\n    { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); }\n  void Sort()\n  {\n    CPointerVector &pointerVector = *this;\n    qsort(&pointerVector[0], Size(), sizeof(void *), CompareObjectItems);\n  }\n};\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Makefile",
    "content": "RGSRC=../../..\ninclude $(RGSRC)/envir.mak\n\nSUBDIRS=Common 7zip/Compress/LZMA 7zip/Compress/LZ 7zip/Compress/RangeCoder \\\n  7zip/Common 7zip 7zip/Compress/LZMA_C 7zip/Compress/LZMA_Alone\n\nLZMA_LIB=liblocal_lzma.a\nEXPORT_LIBS+=$(LZMA_LIB)\nLZMA_LIB_OBJS=7zip/Compress/LZ/LZInWindow.o 7zip/Compress/LZ/LZOutWindow.o \\\n  7zip/Compress/LZMA/LZMADecoder.o 7zip/Compress/LZMA/LZMAEncoder.o \\\n  7zip/Compress/RangeCoder/RangeCoderBit.o 7zip/Common/InBuffer.o \\\n  7zip/Common/OutBuffer.o 7zip/Common/FileStreams.o Common/C_FileIO.o \\\n  Common/Alloc.o Common/String.o Common/CRC.o \\\n  Common/StringConvert.o Common/StringToInt.o Common/Vector.o 7zip/lzma_encode.o\n\nLOCAL_A_TARGET=$(LZMA_LIB)\nL_OBJS_$(LZMA_LIB)=$(LZMA_LIB_OBJS)\nJPKG_EXPORTED_FILES+=lzma.mak\n\nLZMA_BIN=lzma\nLOCAL_CXX_TARGET=$(LZMA_BIN)\nL_OBJS_$(LZMA_BIN)=Common/CommandLineParser.o \\\n  7zip/Compress/LZMA_Alone/LzmaAlone.o 7zip/Compress/LZMA_Alone/LzmaBench.o\n\nLOCAL_LDLIBS:=-llocal_lzma $(LOCAL_LDLIBS)\n\ninclude $(RGMK)\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Windows/Defs.h",
    "content": "// Windows/Defs.h\n\n#ifndef __WINDOWS_DEFS_H\n#define __WINDOWS_DEFS_H\n\ninline bool BOOLToBool(BOOL value)\n  { return (value != FALSE); }\n\ninline BOOL BoolToBOOL(bool value)\n  { return (value ? TRUE: FALSE); }\n\ninline VARIANT_BOOL BoolToVARIANT_BOOL(bool value)\n  { return (value ? VARIANT_TRUE: VARIANT_FALSE); }\n\ninline bool VARIANT_BOOLToBool(VARIANT_BOOL value)\n  { return (value != VARIANT_FALSE); }\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Windows/FileIO.cpp",
    "content": "// Windows/FileIO.cpp\n\n#include \"StdAfx.h\"\n\n#include \"FileIO.h\"\n#include \"Defs.h\"\n#ifndef _UNICODE\n#include \"../Common/StringConvert.h\"\n#endif\n\nnamespace NWindows {\nnamespace NFile {\nnamespace NIO {\n\nCFileBase::~CFileBase()\n{\n  Close();\n}\n\nbool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\n{\n  Close();\n  _handle = ::CreateFile(fileName, desiredAccess, shareMode, \n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \n      flagsAndAttributes, (HANDLE) NULL);\n  _fileIsOpen = _handle != INVALID_HANDLE_VALUE;\n  return _fileIsOpen;\n}\n\n#ifndef _UNICODE\nbool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,\n    DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)\n{\n  Close();\n  // MessageBoxW(0, fileName, 0, 0);\n  // ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\n  _handle = ::CreateFileW(fileName, desiredAccess, shareMode, \n      (LPSECURITY_ATTRIBUTES)NULL, creationDisposition, \n      flagsAndAttributes, (HANDLE) NULL);\n  if ((_handle == INVALID_HANDLE_VALUE ||  _handle == 0) &&\n      ::GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)\n    return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP), \n      desiredAccess, shareMode, creationDisposition, flagsAndAttributes);\n  return (_fileIsOpen = _handle != INVALID_HANDLE_VALUE);\n}\n#endif\n\nbool CFileBase::Close()\n{\n  if(!_fileIsOpen)\n    return true;\n  bool result = BOOLToBool(::CloseHandle(_handle));\n  _fileIsOpen = !result;\n  return result;\n}\n\nbool CFileBase::GetPosition(UINT64 &position) const\n{\n  return Seek(0, FILE_CURRENT, position);\n}\n\nbool CFileBase::GetLength(UINT64 &length) const\n{\n  DWORD sizeHigh;\n  DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);\n  if(sizeLow == 0xFFFFFFFF)\n    if(::GetLastError() != NO_ERROR )\n      return false;\n  length = (((UINT64)sizeHigh) << 32) + sizeLow;\n  return true;\n}\n\nbool CFileBase::Seek(INT64 distanceToMove, DWORD moveMethod, UINT64 &newPosition) const\n{\n  LARGE_INTEGER *pointer = (LARGE_INTEGER *)&distanceToMove;\n  pointer->LowPart = ::SetFilePointer(_handle, pointer->LowPart, \n      &pointer->HighPart, moveMethod);\n  if (pointer->LowPart == 0xFFFFFFFF)\n    if(::GetLastError() != NO_ERROR) \n      return false;\n  newPosition = *((UINT64 *)pointer);\n  return true;\n}\n\nbool CFileBase::Seek(UINT64 position, UINT64 &newPosition)\n{\n  return Seek(position, FILE_BEGIN, newPosition);\n}\n\nbool CFileBase::SeekToBegin()\n{\n  UINT64 newPosition;\n  return Seek(0, newPosition);\n}\n\nbool CFileBase::SeekToEnd(UINT64 &newPosition)\n{\n  return Seek(0, FILE_END, newPosition);\n}\n\nbool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const\n{\n  BY_HANDLE_FILE_INFORMATION winFileInfo;\n  if(!::GetFileInformationByHandle(_handle, &winFileInfo))\n    return false;\n  fileInfo.Attributes = winFileInfo.dwFileAttributes;\n  fileInfo.CreationTime = winFileInfo.ftCreationTime;\n  fileInfo.LastAccessTime = winFileInfo.ftLastAccessTime;\n  fileInfo.LastWriteTime = winFileInfo.ftLastWriteTime;\n  fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes; \n  fileInfo.Size = (((UINT64)winFileInfo.nFileSizeHigh) << 32) + \n      winFileInfo.nFileSizeLow;\n  fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;\n  fileInfo.FileIndex = (((UINT64)winFileInfo.nFileIndexHigh) << 32) + \n      winFileInfo.nFileIndexLow;\n  return true;\n}\n\n/////////////////////////\n// CInFile\n\nbool CInFile::Open(LPCTSTR fileName, DWORD shareMode, \n    DWORD creationDisposition,  DWORD flagsAndAttributes)\n{\n  return Create(fileName, GENERIC_READ, shareMode, \n      creationDisposition, flagsAndAttributes);\n}\n\nbool CInFile::Open(LPCTSTR fileName)\n{\n  return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);\n}\n\n#ifndef _UNICODE\nbool CInFile::Open(LPCWSTR fileName, DWORD shareMode, \n    DWORD creationDisposition,  DWORD flagsAndAttributes)\n{\n  return Create(fileName, GENERIC_READ, shareMode, \n      creationDisposition, flagsAndAttributes);\n}\n\nbool CInFile::Open(LPCWSTR fileName)\n{\n  return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);\n}\n#endif\n\nbool CInFile::Read(void *data, UINT32 size, UINT32 &processedSize)\n{\n  return BOOLToBool(::ReadFile(_handle, data, size, \n      (DWORD *)&processedSize, NULL));\n}\n\n/////////////////////////\n// COutFile\n\nbool COutFile::Open(LPCTSTR fileName, DWORD shareMode, \n    DWORD creationDisposition, DWORD flagsAndAttributes)\n{\n  return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, \n      creationDisposition, flagsAndAttributes);\n}\n\nstatic inline DWORD GetCreationDisposition(bool createAlways)\n  {  return createAlways? CREATE_ALWAYS: CREATE_NEW; }\n\nbool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)\n{\n  return Open(fileName, FILE_SHARE_READ, \n      creationDisposition, FILE_ATTRIBUTE_NORMAL);\n}\n\nbool COutFile::Create(LPCTSTR fileName, bool createAlways)\n{\n  return Open(fileName, GetCreationDisposition(createAlways));\n}\n\n#ifndef _UNICODE\n\nbool COutFile::Open(LPCWSTR fileName, DWORD shareMode, \n    DWORD creationDisposition, DWORD flagsAndAttributes)\n{\n  return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, \n      creationDisposition, flagsAndAttributes);\n}\n\nbool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)\n{\n  return Open(fileName, FILE_SHARE_READ, \n      creationDisposition, FILE_ATTRIBUTE_NORMAL);\n}\n\nbool COutFile::Create(LPCWSTR fileName, bool createAlways)\n{\n  return Open(fileName, GetCreationDisposition(createAlways));\n}\n\n#endif\n\nbool COutFile::SetTime(const FILETIME *creationTime,\n  const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)\n{\n  return BOOLToBool(::SetFileTime(_handle, creationTime,\n      lastAccessTime, lastWriteTime));\n}\n\nbool COutFile::SetLastWriteTime(const FILETIME *lastWriteTime)\n{\n  return SetTime(NULL, NULL, lastWriteTime);\n}\n\nbool COutFile::Write(const void *data, UINT32 size, UINT32 &processedSize)\n{\n  return BOOLToBool(::WriteFile(_handle, data, size, \n      (DWORD *)&processedSize, NULL));\n}\n\nbool COutFile::SetEndOfFile()\n{\n  return BOOLToBool(::SetEndOfFile(_handle));\n}\n\nbool COutFile::SetLength(UINT64 length)\n{\n  UINT64 newPosition;\n  if(!Seek(length, newPosition))\n    return false;\n  if(newPosition != length)\n    return false;\n  return SetEndOfFile();\n}\n\n}}}\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Windows/FileIO.h",
    "content": "// Windows/FileIO.h\n\n#ifndef __WINDOWS_FILEIO_H\n#define __WINDOWS_FILEIO_H\n\nnamespace NWindows {\nnamespace NFile {\nnamespace NIO {\n\nstruct CByHandleFileInfo\n{ \n  DWORD    Attributes; \n  FILETIME CreationTime; \n  FILETIME LastAccessTime; \n  FILETIME LastWriteTime; \n  DWORD    VolumeSerialNumber; \n  UINT64   Size;\n  DWORD    NumberOfLinks; \n  UINT64   FileIndex; \n};\n\nclass CFileBase\n{\nprotected:\n  bool _fileIsOpen;\n  HANDLE _handle;\n  bool Create(LPCTSTR fileName, DWORD desiredAccess,\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\n  #ifndef _UNICODE\n  bool Create(LPCWSTR fileName, DWORD desiredAccess,\n      DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);\n  #endif\n\npublic:\n  CFileBase():\n    _fileIsOpen(false){};\n  virtual ~CFileBase();\n\n  virtual bool Close();\n\n  bool GetPosition(UINT64 &position) const;\n  bool GetLength(UINT64 &length) const;\n\n  bool Seek(INT64 distanceToMove, DWORD moveMethod, UINT64 &newPosition) const;\n  bool Seek(UINT64 position, UINT64 &newPosition); \n  bool SeekToBegin(); \n  bool SeekToEnd(UINT64 &newPosition); \n  \n  bool GetFileInformation(CByHandleFileInfo &fileInfo) const;\n};\n\nclass CInFile: public CFileBase\n{\npublic:\n  bool Open(LPCTSTR fileName, DWORD shareMode, \n      DWORD creationDisposition,  DWORD flagsAndAttributes);\n  bool Open(LPCTSTR fileName);\n  #ifndef _UNICODE\n  bool Open(LPCWSTR fileName, DWORD shareMode, \n      DWORD creationDisposition,  DWORD flagsAndAttributes);\n  bool Open(LPCWSTR fileName);\n  #endif\n  bool Read(void *data, UINT32 size, UINT32 &processedSize);\n};\n\nclass COutFile: public CFileBase\n{\n  // DWORD m_CreationDisposition;\npublic:\n  // COutFile(): m_CreationDisposition(CREATE_NEW){};\n  bool Open(LPCTSTR fileName, DWORD shareMode, \n      DWORD creationDisposition, DWORD flagsAndAttributes);\n  bool Open(LPCTSTR fileName, DWORD creationDisposition);\n  bool Create(LPCTSTR fileName, bool createAlways);\n\n  #ifndef _UNICODE\n  bool Open(LPCWSTR fileName, DWORD shareMode, \n      DWORD creationDisposition, DWORD flagsAndAttributes);\n  bool Open(LPCWSTR fileName, DWORD creationDisposition);\n  bool Create(LPCWSTR fileName, bool createAlways);\n  #endif\n\n  /*\n  void SetOpenCreationDisposition(DWORD creationDisposition)\n    { m_CreationDisposition = creationDisposition; }\n  void SetOpenCreationDispositionCreateAlways()\n    { m_CreationDisposition = CREATE_ALWAYS; }\n  */\n\n  bool SetTime(const FILETIME *creationTime,\n      const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);\n  bool SetLastWriteTime(const FILETIME *lastWriteTime);\n  bool Write(const void *data, UINT32 size, UINT32 &processedSize);\n  bool SetEndOfFile();\n  bool SetLength(UINT64 length);\n};\n\n}}}\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/Windows/StdAfx.h",
    "content": "// StdAfx.h\n\n#ifndef __STDAFX_H\n#define __STDAFX_H\n\n#ifdef WIN32\n#include <windows.h>\n#endif\n\n#endif \n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/lzma.mak",
    "content": "LOCAL_OBJS=$(OBJS:%.o=local_%.o)\n\nOTHER_TASKS=$(LOCAL_OBJS)\nCLEAN=$(LOCAL_OBJS)\n\nLOCAL_CFLAGS+=-D_NO_EXCEPTIONS\n\ninclude $(RGMK)\n\n$(LOCAL_OBJS) : local_%.o : %.cpp\n\t$(CXX_FOR_BUILD) $(LOCAL_CFLAGS) $(CFLAGS_$@) -I$(RGSRC)/pkg/include -c -o $@ $<\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/SRC/lzma_encode.h",
    "content": "/****************************************************************************\n *\n * rg/pkg/lzma/SRC/lzma_encode.h\n * \n * Copyright (C) Jungo LTD 2004\n * \n * This program is free software; you can redistribute it\n * and/or modify it under the terms of the GNU General \n * Public License as published by the Free Software\n * Foundation; either version 2 of the License, or (at\n * your option) any later version.\n * \n * This program is distributed in the hope that it will be\n * useful, but WITHOUT ANY WARRANTY; without even the implied\n * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n * See the GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public\n * License along with this program; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,\n * MA 02111-1307, USA.\n *\n * Developed by Jungo LTD.\n * Residential Gateway Software Division\n * www.jungo.com\n * info@jungo.com\n */\n\n#ifndef _LZMA_ENCODE_H_\n#define _LZMA_ENCODE_H_\n\n/* Compress a buffer usinf LZMA method. This function allows the user to set\n * most of compression parameters. */\nint lzma_encode_extended(char *dest, unsigned long *dest_len,\n    char *source, unsigned long src_len, unsigned int dicLog,\n    unsigned int posStateBits, unsigned int litContextBits,\n    unsigned int litPosBits,\n    unsigned int algorithm, unsigned int numFastBytes);\n\n/* Compress a buffer usinf LZMA method using default compression settings */\nint lzma_encode(char *dest, unsigned long *dest_len, char *source,\n    unsigned long src_len);\n\n#endif\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/history.txt",
    "content": "HISTORY of the LZMA SDK\n-----------------------\n\n  Version 4.06                2004-09-05\n  --------------------------------------\n    - Bug in v4.05 was fixed:\n        LZMA-Encoder didn't release output stream in some cases.\n\n\n  Version 4.05                2004-08-25\n  --------------------------------------\n    - Source code of filters for x86, IA-64, ARM, ARM-Thumb \n      and PowerPC code was included to SDK\n    - Some internal minor changes\n\n\n  Version 4.04                2004-07-28\n  --------------------------------------\n    - More compatibility with some C++ compilers\n\n\n  Version 4.03                2004-06-18\n  --------------------------------------\n    - \"Benchmark\" command was added. It measures compressing \n      and decompressing speed and shows rating values. \n      Also it checks hardware errors.\n\n\n  Version 4.02                2004-06-10\n  --------------------------------------\n    - C++ LZMA Encoder/Decoder code now is more portable\n      and it can be compiled by GCC on Linux.\n\n\n  Version 4.01                2004-02-15\n  --------------------------------------\n    - Some detection of data corruption was enabled.\n        LzmaDecode.c / RangeDecoderReadByte\n        .....\n        {\n          rd->ExtraBytes = 1;\n          return 0xFF;\n        }\n\n\n  Version 4.00                2004-02-13\n  --------------------------------------\n    - Original version of LZMA SDK\n\n\n\nHISTORY of the LZMA\n-------------------\n  2001-2004:  Improvements to LZMA compressing/decompressing code, \n              keeping compatibility with original LZMA format\n  1996-2001:  Development of LZMA compression format\n\n  Some milestones:\n\n  2001-08-30: LZMA compression was added to 7-Zip\n  1999-01-02: First version of 7-Zip was released\n  \n\nEnd of document\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-rg/lzma.txt",
    "content": "LZMA SDK 4.06\n-------------\n\nLZMA SDK 4.06  Copyright (C) 1999-2004 Igor Pavlov\n\nLZMA SDK provides developers with documentation, source code,\nand sample code necessary to write software that uses LZMA compression. \n\nLZMA is default and general compression method of 7z format\nin 7-Zip compression program (www.7-zip.org). LZMA provides high \ncompression ratio and very fast decompression.\n\nLZMA is an improved version of famous LZ77 compression algorithm. \nIt was improved in way of maximum increasing of compression ratio,\nkeeping high decompression speed and low memory requirements for \ndecompressing.\n\n\n\nLICENSE\n-------\n\nLZMA SDK is licensed under two licenses:\n\n1) GNU Lesser General Public License (GNU LGPL)\n2) Common Public License (CPL)\n\nIt means that you can select one of these two licenses and \nfollow rules of that license.\n\nSPECIAL EXCEPTION\nIgor Pavlov, as the author of this code, expressly permits you \nto statically or dynamically link your code (or bind by name) \nto the files from LZMA SDK without subjecting your linked \ncode to the terms of the CPL or GNU LGPL. \nAny modifications or additions to files from LZMA SDK, however, \nare subject to the GNU LGPL or CPL terms.\n\n\nGNU LGPL and CPL licenses are pretty similar and both these\nlicenses are classified as \n\n1) \"Free software licenses\" at http://www.gnu.org/ \n2) \"OSI-approved\" at http://www.opensource.org/\n\n\nLZMA SDK also can be available under a proprietary license for \nthose who cannot use the GNU LGPL or CPL in their code. To request\nsuch proprietary license or any additional consultations,\nsend email message from that page:\nhttp://www.7-zip.org/support.html\n\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\nYou should have received a copy of the Common Public License\nalong with this library.\n\n\nLZMA SDK Contents\n-----------------\n\nLZMA SDK includes:\n\n  - C++ source code of LZMA Encoder and Decoder\n  - C++ source code for file->file LZMA compressing and decompressing\n  - ANSI-C compatible source code for LZMA decompressing\n  - Compiled file->file LZMA compressing/decompressing program for Windows system\n\nANSI-C LZMA decompression code was ported from original C++ sources to C.\nAlso it was simplified and optimized for code size. \nBut it is fully compatible with LZMA from 7-Zip.\n\n\nUNIX/Linux version \n------------------\nTo compile C++ version of file->file LZMA, go to directory\nSRC/7zip/Compress/LZMA_Alone \nand type \"make\" or \"make clean all\" to recompile all.\n\nIn some UNIX/Linux versions you must compile LZMA with static libraries.\nTo compile with static libraries, change string in makefile\nLIB = -lm\nto string  \nLIB = -lm -static\n\n\nFiles\n---------------------\nSRC      - directory with source code\nlzma.txt - LZMA SDK description (this file)\nLGPL.txt - GNU Lesser General Public License\nCPL.html - Common Public License\nlzma.exe - Compiled file->file LZMA encoder/decoder for Windows\nhistory.txt - history of the LZMA SDK\n\n\nSource code structure\n---------------------\n\nSRC\n  Common  - common files for C++ projects\n  Windows - common files for Windows related code\n  7zip    - files related to 7-Zip Project\n    Common   - common files for 7-Zip\n    Compress - files related to compression/decompression\n      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\n        BinTree    - Binary Tree Match Finder for LZ algorithm\n        HashChain  - Hash Chain Match Finder for LZ algorithm\n        Patricia   - Patricia Match Finder for LZ algorithm\n      RangeCoder   - Range Coder (special code of compression/decompression)\n      LZMA         - LZMA compression/decompression on C++\n      LZMA_Alone   - file->file LZMA compression/decompression\n      LZMA_C       - ANSI-C compatible LZMA decompressor\n        LzmaDecode.h  - interface for LZMA decoding on ANSI-C\n        LzmaDecode.c  - LZMA decoding on ANSI-C\n        LzmaTest.c    - test application that decodes LZMA encoded file\n      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb and PowerPC code\n\nSource code of LZMA SDK is only part of big 7-Zip project. That is \nwhy LZMA SDK uses such complex source code structure. \n\nYou can find ANSI-C LZMA decompressing code at folder \n  SRC/7zip/Compress/LZMA_C\n7-Zip doesn't use that ANSI-C LZMA code and that code was developed \nspecially for this SDK. And files from LZMA_C do not need files from \nother directories of SDK for compiling.\n\n7-Zip source code can be downloaded from 7-Zip's SourceForge page:\n\n  http://sourceforge.net/projects/sevenzip/\n\n\nLZMA Decompression features\n---------------------------\n  - Variable dictionary size (up to 256 MB)\n  - Estimated compressing speed: about 500 KB/s on 1 GHz CPU\n  - Estimated decompressing speed: \n      - 8-12 MB/s on 1 GHz Intel Pentium 3 or AMD Athlon\n      - 500-1000 KB/s on 100 MHz ARM, MIPS, PowerPC or other simple RISC\n  - Small memory requirements for decompressing (8-32 KB + DictionarySize)\n  - Small code size for decompressing: 2-8 KB (depending from \n    speed optimizations) \n\nLZMA decoder uses only integer operations and can be \nimplemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\n\nSome critical operations that affect to speed of LZMA decompression:\n  1) 32*16 bit integer multiply\n  2) Misspredicted branches (penalty mostly depends from pipeline length)\n  3) 32-bit shift and arithmetic operations\n\nSpeed of LZMA decompression mostly depends from CPU speed.\nMemory speed has no big meaning. But if your CPU has small data cache, \noverall weight of memory speed will slightly increase.\n\n\nHow To Use\n----------\n\nUsing LZMA encoder/decoder executable\n--------------------------------------\n\nUsage:  LZMA <e|d> inputFile outputFile [<switches>...]\n\n  e: encode file\n\n  d: decode file\n\n  b: Benchmark. There are two tests: compressing and decompressing \n     with LZMA method. Benchmark shows rating in MIPS (million \n     instructions per second). Rating value is calculated from \n     measured speed and it is normalized with AMD Athlon XP CPU\n     results. Also Benchmark checks possible hardware errors (RAM \n     errors in most cases). Benchmark uses these settings:\n     (-a1, -d21, -fb32, -mfbt4). You can change only -d. Also you \n     can change number of iterations. Example for 30 iterations:\n\tLZMA b 30\n     Default number of iterations is 10.\n\n<Switches>\n  \n\n  -a{N}:  set compression mode 0 = fast, 1 = normal, 2 = max\n          default: 2 (max)\n\n  d{N}:   Sets Dictionary size - [0, 28], default: 23 (8MB)\n          The maximum value for dictionary size is 256 MB = 2^28 bytes.\n          Dictionary size is calculated as DictionarySize = 2^N bytes. \n          For decompressing file compressed by LZMA method with dictionary \n          size D = 2^N you need about D bytes of memory (RAM).\n\n  -fb{N}: set number of fast bytes - [5, 255], default: 128\n          Usually big number gives a little bit better compression ratio \n          and slower compression process.\n\n  -lc{N}: set number of literal context bits - [0, 8], default: 3\n          Sometimes lc=4 gives gain for big files.\n\n  -lp{N}: set number of literal pos bits - [0, 4], default: 0\n          lp switch is intended for periodical data when period is \n          equal 2^N. For example, for 32-bit (4 bytes) \n          periodical data you can use lp=2. Often it's better to set lc0, \n          if you change lp switch.\n\n  -pb{N}: set number of pos bits - [0, 4], default: 2\n          pb switch is intended for periodical data \n          when period is equal 2^N.\n\n  -mf{MF_ID}: set Match Finder. Default: bt4. \n              Compression ratio for all bt* and pat* almost the same.\n              Algorithms from hc* group doesn't provide good compression \n              ratio, but they often works pretty fast in combination with \n              fast mode (-a0). Methods from bt* group require less memory \n              than methods from pat* group. Usually bt4 works faster than \n              any pat*, but for some types of files pat* can work faster. \n\n              Memory requirements depend from dictionary size \n              (parameter \"d\" in table below). \n\n               MF_ID     Memory                   Description\n\n                bt2    d*9.5 +  1MB  Binary Tree with 2 bytes hashing.\n                bt3    d*9.5 + 65MB  Binary Tree with 2-3(full) bytes hashing.\n                bt4    d*9.5 +  6MB  Binary Tree with 2-3-4 bytes hashing.\n                bt4b   d*9.5 + 34MB  Binary Tree with 2-3-4(big) bytes hashing.\n                pat2r  d*26  +  1MB  Patricia Tree with 2-bits nodes, removing.\n                pat2   d*38  +  1MB  Patricia Tree with 2-bits nodes.\n                pat2h  d*38  + 77MB  Patricia Tree with 2-bits nodes, 2-3 bytes hashing.\n                pat3h  d*62  + 85MB  Patricia Tree with 3-bits nodes, 2-3 bytes hashing.\n                pat4h  d*110 +101MB  Patricia Tree with 4-bits nodes, 2-3 bytes hashing.\n                hc3    d*5.5 +  1MB  Hash Chain with 2-3 bytes hashing.\n                hc4    d*5.5 +  6MB  Hash Chain with 2-3-4 bytes hashing.\n\n  -eos:   write End Of Stream marker. By default LZMA doesn't write \n          eos marker, since LZMA decoder knows uncompressed size \n          stored in .lzma file header.\n\n  -si:    Read data from stdin (it will write End Of Stream marker).\n  -so:    Write data to stdout\n\n\nExamples:\n\n1) LZMA e file.bin file.lzma -d16 -lc0 \n\ncompresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \nand 0 literal context bits. -lc0 allows to reduce memory requirements \nfor decompression.\n\n\n2) LZMA e file.bin file.lzma -lc0 -lp2\n\ncompresses file.bin to file.lzma with settings suitable \nfor 32-bit periodical data (for example, ARM or MIPS code).\n\n3) LZMA d file.lzma file.bin\n\ndecompresses file.lzma to file.bin.\n\n\nCompression ratio hints\n-----------------------\n\nRecommendations\n---------------\n\nTo increase compression ratio for LZMA compressing it's desirable \nto have aligned data (if it's possible) and also it's desirable to locate\ndata in such order, where code is grouped in one place and data is \ngrouped in other place (it's better than such mixing: code, data, code,\ndata, ...).\n\n\nUsing Filters\n-------------\nYou can increase compression ratio for some data types, using\nspecial filters before compressing. For example, it's possible to \nincrease compression ratio on 5-10% for code for those CPU ISAs: \nx86, IA-64, ARM, ARM-Thumb, PowerPC.\n\nYou can find C/C++ source code of such filters in folder \"7zip/Compress/Branch\"\n\nYou can check compression ratio gain of these filters with such \n7-Zip commands (example for ARM code):\nNo filter:\n  7z a a1.7z a.bin -m0=lzma\n\nWith filter for little-endian ARM code:\n  7z a a2.7z a.bin -m0=bc_arm -m1=lzma        \n\nWith filter for big-endian ARM code (using additional Swap4 filter):\n  7z a a3.7z a.bin -m0=swap4 -m1=bc_arm -m2=lzma\n\nIt works in such manner:\nCompressing    = Filter_encodeing + LZMA_encoding\nDecompressing  = LZMA_decoding + Filter_decodeing\n\nCompressing and decompressing speed of such filters is very high,\nso it will not increase decompressing time too much.\nMoreover, it reduces decompression time for LZMA_decoding, \nsince compression ratio with filtering is higher.\n\nThese filters convert CALL (calling procedure) instructions \nfrom relative offsets to absolute addresses, so such data becomes more \ncompressible. Source code of these CALL filters is pretty simple\n(about 20 lines of C++), so you can convert it from C++ version yourself.\n\nFor some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\n\n\nLZMA compressed file format\n---------------------------\nOffset Size Description\n  0     1   Special LZMA properties for compressed data\n  1     4   Dictionary size (little endian)\n  5     8   Uncompressed size (little endian). -1 means unknown size\n 13         Compressed data\n\n\nANSI-C LZMA Decoder\n~~~~~~~~~~~~~~~~~~~\n\nMemory requirements for LZMA decoding\n-------------------------------------\n\nLZMA decoder doesn't allocate memory itself, so you must \ncalculate required memory, allocate it and send it to LZMA.\n\nStack usage of LZMA function for local variables is not \nlarger than 200 bytes.\n\nMemory requirements for decompression depend \nfrom interface that you want to use:\n\n  a) Memory to memory decompression:\n    \n    M1 = (inputSize + outputSize + lzmaInternalSize).\n\n  b) Decompression with buffering:\n\n    M2 = (inputBufferSize + outputBufferSize + dictionarySize + lzmaInternalSize)\n\n\nHow To decompress data\n----------------------\n\n1) Read first byte of properties for LZMA compressed stream, \n   check that it has correct value and calculate three \n   LZMA property variables:\n\n  int lc, lp, pb;\n  unsigned char prop0 = properties[0];\n  if (prop0 >= (9*5*5))\n  {\n    sprintf(rs + strlen(rs), \"\\n properties error\");\n    return 1;\n  }\n  for (pb = 0; prop0 >= (9 * 5); \n    pb++, prop0 -= (9 * 5));\n  for (lp = 0; prop0 >= 9; \n    lp++, prop0 -= 9);\n  lc = prop0;\n\n2) Calculate required amount for LZMA lzmaInternalSize:\n\n  lzmaInternalSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp))) * \n     sizeof(CProb)\n\n  LZMA_BASE_SIZE = 1846\n  LZMA_LIT_SIZE = 768\n\n  LZMA decoder uses array of CProb variables as internal structure.\n  By default, CProb is (unsigned short)\n  But you can define _LZMA_PROB32 to make it (unsigned int)\n  It can increase speed on some 32-bit CPUs, but memory usage will \n  be doubled in that case.\n\n\n  2b) If you use Decompression with buffering, add 100 bytes to \n      lzmaInternalSize:\n     \n      #ifdef _LZMA_OUT_READ\n      lzmaInternalSize += 100;\n      #endif\n\n3) Allocate that memory with malloc or some other function:\n\n  lzmaInternalData = malloc(lzmaInternalSize);\n\n\n4) Decompress data:\n\n  4a) If you use simple memory to memory decompression:\n\n    int result = LzmaDecode(lzmaInternalData, lzmaInternalSize,\n        lc, lp, pb,\n        unsigned char *inStream, unsigned int inSize,\n        unsigned char *outStream, unsigned int outSize, \n        &outSizeProcessed);\n\n  4b) If you use Decompression with buffering\n\n    4.1) Read dictionary size from properties\n\n      unsigned int dictionarySize = 0;\n      int i;\n      for (i = 0; i < 4; i++)\n        dictionarySize += (unsigned int)(b) << (i * 8);\n\n    4.2) Allocate memory for dictionary\n\n      unsigned char *dictionary = malloc(dictionarySize);\n\n    4.3) Initialize LZMA decoder:\n\n    LzmaDecoderInit((unsigned char *)lzmaInternalData, lzmaInternalSize,\n        lc, lp, pb,\n        dictionary, dictionarySize,\n        &bo.ReadCallback);\n\n    4.4) In loop call LzmaDecoderCode function:\n\n    for (nowPos = 0; nowPos < outSize;)\n    {\n      unsigned int blockSize = outSize - nowPos;\n      unsigned int kBlockSize = 0x10000;\n      if (blockSize > kBlockSize)\n        blockSize = kBlockSize;\n      res = LzmaDecode((unsigned char *)lzmaInternalData, \n      ((unsigned char *)outStream) + nowPos, blockSize, &outSizeProcessed);\n      if (res != 0)\n      {\n        printf(\"\\nerror = %d\\n\", res);\n        break;\n      }\n      nowPos += outSizeProcessed;\n      if (outSizeProcessed == 0)\n      {\n        outSize = nowPos;\n        break;\n      }\n    }\n\n\nEXIT codes\n-----------\n\nLZMA decoder can return on of the following codes:\n\n#define LZMA_RESULT_OK 0\n#define LZMA_RESULT_DATA_ERROR 1\n#define LZMA_RESULT_NOT_ENOUGH_MEM 2\n\nIf you use callback function for input data and you return some \nerror code, LZMA Decoder also returns that code.\n\n\n\nLZMA Defines\n------------\n\n_LZMA_IN_CB    - Use callback for input data\n\n_LZMA_OUT_READ - Use read function for output data\n\n_LZMA_LOC_OPT  - Enable local speed optimizations inside code\n\n_LZMA_PROB32   - It can increase speed on some 32-bit CPUs, \n                 but memory usage will be doubled in that case\n\n_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler\n                         and long is 32-bit.\n\n\nNOTES\n-----\n1) please note that LzmaTest.c doesn't free allocated memory in some cases. \nBut in your real applicaions you must free memory after decompression.\n\n2) All numbers above were calculated for case when int is not more than \n  32-bit in your compiler. If in your compiler int is 64-bit or larger \n  probably LZMA can require more memory for some structures.\n\n\n\nC++ LZMA Encoder/Decoder \n~~~~~~~~~~~~~~~~~~~~~~~~\nC++ LZMA code use COM-like interfaces. So if you want to use it, \nyou can study basics of COM/OLE.\n\nBy default, LZMA Encoder contains all Match Finders.\nBut for compressing it's enough to have just one of them.\nSo for reducing size of compressing code you can define:\n  #define COMPRESS_MF_BT\n  #define COMPRESS_MF_BT4\nand it will use only bt4 match finder.\n\n\n---\n\nhttp://www.7-zip.org\nhttp://www.7-zip.org/support.html\n\n\n"
  },
  {
    "path": "src/uncramfs-lzma/lzma-uncramfs.c",
    "content": "//\n// Uncramfs\n// A program to unpack a cramfs image\n//\n// Copyright Andrew Stitcher, 2001\n//\n// Licensed according to the GNU GPL v2\n//\n\n// C things\n#include <stdio.h>\n//#include <stdlib.h>\n#include <string.h>\n#include <assert.h>\n\n// Unix things\n#include <unistd.h>\n#include <errno.h>\n//#include <dirent.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <sys/mman.h>\n#include <sys/fcntl.h>\n#include <stdlib.h>\n\n// Application libraries\n#include <zlib.h>\n\n// Needed by cramfs\ntypedef unsigned char u8;\ntypedef unsigned short u16;\ntypedef unsigned int u32;\n\n// Cramfs definitions\n#include \"cramfs.h\"\n#include \"lzma-rg/SRC/7zip/Compress/LZMA_C/LzmaDecode.h\"\n#include \"lzma-rg/SRC/7zip/Compress/LZMA_C/decode.h\"\n\n#define PAGE_CACHE_SIZE (65536)\n\n/* The kernel assumes PAGE_CACHE_SIZE as block size. */\nstatic unsigned int blksize = PAGE_CACHE_SIZE;\n\nstatic const char* progname = \"uncramfs\";\n\nstatic char *opt_devfile = NULL;\nstatic char *opt_idsfile = NULL;\n\n// Get version number from external file\nstatic const char*\n#include \"VERSION\"\n;\n\nvoid do_file_entry(const u8* base,\n\t\t   const char* dir,\n\t\t   const char* path,\n\t\t   const char* name, int namelen,\n\t\t   const struct cramfs_inode* inode);\n\nvoid do_dir_entry(const u8* base,\n\t\t  const char* dir,\n\t\t  const char* path,\n\t\t  const char* name, int namelen,\n\t\t  const struct cramfs_inode* inode);\n\n///////////////////////////////////////////////////////////////////////////////\n\nstatic void usage(void)\n{\n   printf(\n     \"%s v%s by Andrew Stitcher, lzma for openrg  by V. Di Giampietro (v@ler.io)\\n\"\n     \"Usage: '%s [-d devfilename] [-m modefilename] dirname infile'\\n\"\n     \" where <dirname> is the root for the\\n\"\n     \" uncompressed (output) filesystem.\\n\", progname, VERSION, progname);\n   exit(1);\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nu32 compressed_size(const u8* base, const u8* data, u32 size)\n{\n   const u32* buffs=(const u32*)(data);\n   int nblocks=(size-1)/blksize+1;\n   const u8* buffend=base+*(buffs+nblocks-1);\n   \n   if (size == 0)\n     return 0;\n   else\n     return buffend-data;\n}\n\nvoid uncompress_data(const u8* base, const u8* data, u32 size, u8* dstdata)\n{\n  printf(\"entering uncompress_data\\n\");\n   const u32* buffs=(const u32*)(data);\n   int nblocks=(size-1)/blksize+1;\n   const u8* buff=(const u8*)(buffs+nblocks);\n   const u8* nbuff;\n   int block=0;\n   uLongf len=size;\n   \n   if (size == 0) {\n     return;\n   }\n   \n   for (;\n\tblock < nblocks;\n\t++block, buff=nbuff, dstdata+=blksize, len-=blksize\n\t) {\n      uLongf tran=(len < blksize) ? len : blksize;\n      nbuff=base+*(buffs+block);\n      printf(\"dstlen %d compresslen %d\\n\",tran,nbuff-buff);\n      if (lzma_decode(dstdata, tran, buff, nbuff-buff) == Z_OK) {\n\t fprintf(stderr,\"Uncompression failed\");\n\t return;\n      }\n   }\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nint stats_totalsize;\nint stats_totalcsize;\nint stats_count;\nint stats_compresses;\nint stats_expands;\n\nvoid clearstats()\n{\n   stats_totalsize=0;\n   stats_totalcsize=0;\n   stats_count=0;\n   stats_compresses=0;\n   stats_expands=0;\n}\n\nvoid updatestats(int size, int csize)\n{\n   ++stats_count;\n   stats_totalsize+=size;\n   stats_totalcsize+=csize;\n   \n   if (size>=csize) {\n      stats_compresses++;\n   } else {\n      stats_expands++;\n   }\n}\n\nvoid printstats()\n{\n   printf(\"\\n[Summary:]\\n\");\n   printf(\"[Total uncompressed size:    %9d]\\n\", stats_totalsize);\n   printf(\"[Total compressed size:      %9d]\\n\", stats_totalcsize);\n   printf(\"[Number of entries:          %9d]\\n\", stats_count);\n   printf(\"[Number of files compressed: %9d]\\n\", stats_compresses);\n   printf(\"[Number of files expanded:   %9d]\\n\", stats_expands);\n   printf(\"\\n\");\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nvoid printmode(const struct cramfs_inode* inode)\n{\n   u16 mode=inode->mode;\n   \n   // Deal with file type bitsetc\n   if (S_ISDIR(mode)) printf(\"d\");\n   else if(S_ISLNK(mode)) printf(\"l\");\n   else if(S_ISBLK(mode)) printf(\"b\");\n   else if(S_ISCHR(mode)) printf(\"c\");\n   else if(S_ISFIFO(mode)) printf(\"p\");\n   else if(S_ISSOCK(mode)) printf(\"s\");\n   else printf(\"-\");\n   \n   // Deal with mode bits\n   if (mode & S_IRUSR) printf(\"r\"); else printf(\"-\");\n   if (mode & S_IWUSR) printf(\"w\"); else printf(\"-\");\n   if (mode & S_IXUSR)\n     if (mode & S_ISUID) printf(\"s\"); else printf(\"x\");\n   else\n     if (mode & S_ISUID) printf(\"S\"); else printf(\"-\");\n   if (mode & S_IRGRP) printf(\"r\"); else printf(\"-\");\n   if (mode & S_IWGRP) printf(\"w\"); else printf(\"-\");\n   if (mode & S_IXGRP)\n     if (mode & S_ISGID) printf(\"s\"); else printf(\"x\");\n   else\n     if (mode & S_ISGID) printf(\"S\"); else printf(\"-\");\n   if (mode & S_IROTH) printf(\"r\"); else printf(\"-\");\n   if (mode & S_IWOTH) printf(\"w\"); else printf(\"-\");\n   if (mode & S_IXOTH)\n     if (mode & S_ISVTX) printf(\"t\"); else printf(\"x\");\n   else\n     if (mode & S_ISVTX) printf(\"T\"); else printf(\"-\");\n}\n\nvoid printuidgid(const struct cramfs_inode* inode)\n{\n   char res[14];\n   \n   snprintf(res, 14, \"%d/%d\", inode->uid, inode->gid);\n   printf(\" %-14s\", res);\n   \n}\n\nvoid printsize(int size, int csize)\n{\n   char s[17];\n\n   // As a side effect update the size stats\n   updatestats(size, csize);\n   \n   snprintf(s, 17, \"%7d(%d)\", size, csize);\n   printf(\"%-16s \", s);\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nvoid do_file(const u8* base, u32 offset, u32 size,\n\t     const char* path, const char* name, int mode)\n{\n   int fd;\n   u8* file_data;\n   const u8* srcdata;\n   \n   // Allow for uncompressed XIP executable\n   if (mode & S_ISVTX) {\n      // It seems that the offset may not necessarily be page\n      // aligned. This is silly because mkcramfs wastes\n      // the alignment space, whereas it might be used if it wasn't\n      // bogusly in our file extent.\n      //\n      // blksize must be a power of 2 for the following to work, but it seems\n      // quite likely.\n \n      srcdata=(const u8*)(((u32)(base+offset)+blksize-1) & ~(blksize-1));\n      printsize(size, srcdata+size-(base+offset));\n      printf(\"%s\", name);\n   } else {\n      printsize(size, compressed_size(base, base+offset, size) );\n      printf(\"%s\", name);\n   }\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   fd=open(path, O_CREAT|O_TRUNC|O_RDWR, mode);\n   if (fd == -1) {\n      perror(\"create\");\n      return;\n   };\n\n   if (ftruncate(fd, size) == -1) {\n      perror(\"ftruncate\");\n      close(fd);\n      return;\n   }\n   \n   file_data = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);\n   if (file_data == MAP_FAILED) {\n      perror(\"mmap\");\n      close(fd);\n      return;\n   }\n\n   // Allow for uncompressed XIP executable\n   if (mode & S_ISVTX) {\n      memcpy(file_data, srcdata, size);\n   } else {\n      uncompress_data(base, base+offset, size, file_data);\n   }\n   \n   munmap(file_data, size);\n   close(fd);\n\n}\n\nvoid do_directory(const u8* base, u32 offset, u32 size,\n\t\t  const char* path, const char* name, int mode)\n{\n   printsize(size, size);\n   printf(\"%s\", name);\n   \n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make the local directory\n   if (mkdir(path, mode) == -1) {\n      perror(path);\n      return;\n   }\n}\n\nvoid do_symlink(const u8* base, u32 offset, u32 size,\n\t\tconst char* path, const char* name, int mode)\n{\n   // Allocate the uncompressed string\n   u8 link_contents[size+1];\n   \n   // do uncompression\n   uncompress_data(base, base+offset, size, link_contents);\n   link_contents[size]=0;\n   \n   printsize(size, compressed_size(base, base+offset, size) );\n   printf(\"%s -> %s\", name, link_contents );\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   if (symlink(link_contents, path) == -1) {\n      perror(path);\n      exit(1);\n   }\n}\n\nvoid do_chrdev(const u8* base, u32 offset, u32 size,\n\t       const char* path, const char* name, int mode, int uid, int gid)\n{\n   {\n      char s[17];\n      snprintf(s, 17, \"%3d, %3d\", major(size), minor(size) );\n      printf(\"%-16s %s\", s, name);\n   }\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   if (geteuid() == 0) {\n      if (mknod(path, S_IFCHR | mode, size) == -1)\n         perror(path);\n   } else if (opt_devfile) {\n      char dfp[1024];\n      char *p;\n      FILE *f;\n\n      strcpy(dfp,path);\n      p = strrchr(dfp,'/');\n      if (!p) {\n         fprintf(stderr,\"Could not find path in '%s'\\n\",path);\n         return;\n      }\n      strcpy(p+1,opt_devfile);\n      f = fopen(dfp,\"at\");\n      if (!f) {\n   \t    perror(dfp);\n   \t    return;\n      }\n      fprintf(f,\"%s,%08x,%u,%u,%08x\\n\",name,mode,uid,gid,size);\n      fclose(f);\n   }\n}\n\nvoid do_blkdev(const u8* base, u32 offset, u32 size,\n\t       const char* path, const char* name, int mode, int uid, int gid)\n{\n   {\n      char s[17];\n      snprintf(s, 17, \"%3d, %3d\", major(size), minor(size) );\n      printf(\"%-16s %s\", s, name);\n   }\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   if (geteuid() == 0) {\n      if (mknod(path, S_IFBLK | mode, size) == -1)\n         perror(path);\n   } else if (opt_devfile) {\n      char dfp[1024];\n      char *p;\n      FILE *f;\n\n      strcpy(dfp,path);\n      p = strrchr(dfp,'/');\n      if (!p) {\n         fprintf(stderr,\"Could not find path in '%s'\\n\",path);\n         return;\n      }\n      strcpy(p+1,opt_devfile);\n      f = fopen(dfp,\"at\");\n      if (!f) {\n   \t    perror(dfp);\n   \t    return;\n      }\n      fprintf(f,\"%s,%08x,%u,%u,%08x\\n\",name,mode,uid,gid,size);\n      fclose(f);\n   }\n}\n\nvoid do_fifo(const u8* base, u32 offset, u32 size,\n\t     const char* path, const char* name, int mode, int gid, int uid)\n{\n   printf(\"                 %s\", name);\n   \n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n\n   // Make local copy\n   if (geteuid() == 0) {\n      if (mknod(path, S_IFIFO | mode, 0) == -1)\n         perror(path);\n   } else if (opt_devfile) {\n      char dfp[1024];\n      char *p;\n      FILE *f;\n\n      strcpy(dfp,path);\n      p = strrchr(dfp,'/');\n      if (!p) {\n         fprintf(stderr,\"Could not find path in '%s'\\n\",path);\n         return;\n      }\n      strcpy(p+1,opt_devfile);\n      f = fopen(dfp,\"at\");\n      if (!f) {\n   \t    perror(dfp);\n   \t    return;\n      }\n      fprintf(f,\"%s,%08x,%u,%u,%08x\\n\",name,mode,uid,gid,size);\n      fclose(f);\n   }\n}\n\nvoid do_socket(const u8* base, u32 offset, u32 size,\n\t       const char* path, const char* name, int mode)\n{\n   printf(\"<UNIMPLEMENTED>  %s\", name);\n\n   // Check if we are actually unpacking\n   if (path[0]=='-') {\n      return;\n   }\n}\n\nvoid do_unknown(const u8* base, u32 offset, u32 size,\n\t        const char* path, const char* name, int mode)\n{\n   printf(\"<UNKNOWN TYPE>   %s\", name);\n}\n\nvoid process_directory(const u8* base, const char* dir, u32 offset, u32 size,\n\t\t  const char* path)\n{\n   struct cramfs_inode* de;\n   char* name;\n   int namelen;\n   u32 current=offset;\n   u32 dirend=offset+size;\n   \n   // Do files\n   while (current < dirend) {\n      u32 nextoffset;\n      \n      de=(struct cramfs_inode*)(base+current);\n      namelen=de->namelen<<2;\n      nextoffset=current+sizeof(struct cramfs_inode)+namelen;\n      \n      name=(char*)(de+1);\n      \n      while (1) {\n\t assert(namelen!=0);\n\t \n\t if (name[namelen-1])\n\t   break;\n\t namelen--;\n      }\n\n      do_file_entry(base, dir, path, name, namelen, de);\n      \n      current=nextoffset;\n   }\n\n   // Recurse into directories\n   current=offset;\n   while (current < dirend) {\n      u32 nextoffset;\n      \n      de=(struct cramfs_inode*)(base+current);\n      namelen=de->namelen<<2;\n      nextoffset=current+sizeof(struct cramfs_inode)+namelen;\n      \n      name=(char*)(de+1);\n      \n      while (1) {\n\t assert(namelen!=0);\n\t \n\t if (name[namelen-1])\n\t   break;\n\t namelen--;\n      }\n\n      do_dir_entry(base, dir, path, name, namelen, de);\n      \n      current=nextoffset;\n   }\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\nvoid do_file_entry(const u8* base,\n\t\t   const char* dir,\n\t           const char* path,\n\t\t   const char* name, int namelen, \n\t\t   const struct cramfs_inode* inode)\n{\n   int dirlen=strlen(dir);\n   int pathlen=strlen(path);\n   char pname[dirlen+pathlen+namelen+3];\n   const char* basename;\n   \n   if (dirlen) {\n      strncpy(pname, dir, dirlen);\n   }\n   \n   if (pathlen) {\n      if (dirlen) {\n\t pname[dirlen]='/';\n\t ++dirlen;\n      }\n      strncpy(pname+dirlen, path, pathlen);\n   }\n   \n   if (namelen) {\n      if (pathlen+dirlen) {\n\t pname[dirlen+pathlen]='/';\n\t ++pathlen;\n      }\n      strncpy(pname+dirlen+pathlen, name, namelen);\n   }\n\n   pname[pathlen+dirlen+namelen]=0;\n   basename=namelen ? pname+dirlen+pathlen : \"/\";\n   \n   // Create things here\n   printmode(inode);\n   printuidgid(inode);\n   \n   if (S_ISREG(inode->mode)) {\n      do_file(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   } else  if (S_ISDIR(inode->mode)) {\n      do_directory(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   } else  if (S_ISLNK(inode->mode)) {\n      do_symlink(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   } else  if (S_ISFIFO(inode->mode)) {\n      do_fifo(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);\n   } else  if (S_ISSOCK(inode->mode)) {\n      do_socket(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   } else  if (S_ISCHR(inode->mode)) {\n      do_chrdev(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);\n   } else  if (S_ISBLK(inode->mode)) {\n      do_blkdev(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);\n   } else {\n      do_unknown(base, inode->offset<<2, inode->size, pname, basename, inode->mode);\n   }\n   \n   if (geteuid() == 0) {\n      if (lchown(pname, inode->uid, inode->gid) == -1)\n         perror(\"cannot change owner or group\");\n   } else if(opt_idsfile && path && path[0]) {\n      char dfp[1024];\n      char *p;\n      FILE *f;\n\n      strcpy(dfp,pname);\n      p = strrchr(dfp,'/');\n      if (!p) {\n         fprintf(stderr,\"could not find path in '%s'\\n\",pname);\n         return;\n      }\n      strcpy(p+1,opt_idsfile);\n      f = fopen(dfp,\"at\");\n      if (!f) {\n   \t    perror(dfp);\n   \t    return;\n      }\n\t  fprintf(f,\"%s,%u,%u,%08x\\n\",basename,inode->uid,inode->gid,inode->mode);\n      fclose(f);\n   }\n\n   if (geteuid() == 0 || !opt_idsfile) {\n      if (inode->mode & (S_ISGID|S_ISUID|S_ISVTX)) {\n        if (0 != chmod(pname, inode->mode)){\n          perror(\"chmod\");\n          return;\n        }\n      }\n   }\n\n\n   \n   printf(\"\\n\");\n}\n\nvoid do_dir_entry(const u8* base,\n\t\t  const char* dir,\n\t\t  const char* path,\n\t\t  const char* name, int namelen, \n\t\t  const struct cramfs_inode* inode)\n{\n   int pathlen=strlen(path);\n   char pname[pathlen+namelen+2];\n   \n   if (pathlen) {\n      strncpy(pname, path, pathlen);\n   }\n   \n   if (namelen) {\n      if (pathlen) {\n\t pname[pathlen]='/';\n\t ++pathlen;\n      }\n      strncpy(pname+pathlen, name, namelen);\n   }\n\n   pname[pathlen+namelen]=0;\n\n   // Only process directories here   \n   if (S_ISDIR(inode->mode)) {\n      printf(\"\\n/%s:\\n\", pname);\n      process_directory(base, dir, inode->offset<<2, inode->size, pname);\n   }\n}\n\n///////////////////////////////////////////////////////////////////////////////\n\n/*\n * Usage:\n *\n *      uncramfs directory-name outfile\n *\n * where \"directory-name\" is simply the root of the directory\n * tree that we want to expand the compressed filesystem into.\n */\nint main(int argc, char **argv)\n{\n   char const* dirname;\n   char const* imagefile;\n   struct stat st;\n   int fd;\n   size_t fslen_ub;\n   u8 const* rom_image;\n   struct cramfs_super const* sb;\n   int i;\n\n   // Check the program usage\n   if (argc)\n     progname = argv[0];\n   if (argc != 3 && argc != 5 && argc != 7)\n     usage();\n\n   if (argc == 3) {\n      dirname=argv[1];\n      imagefile=argv[2];\n   } else if (argc == 5) {\n      if (strcmp(argv[1],\"-d\")==0) {\n         opt_devfile = argv[2];\n      } else if (strcmp(argv[1],\"-m\")==0) {\n         opt_idsfile = argv[2];\n      } else\n         usage();\n      dirname=argv[3];\n      imagefile=argv[4];\n   } else {\n      if (strcmp(argv[1],\"-d\")==0) {\n         opt_devfile = argv[2];\n      } else if (strcmp(argv[1],\"-m\")==0) {\n         opt_idsfile = argv[2];\n      } else\n         usage();\n\n      if (strcmp(argv[3],\"-d\")==0 && !opt_devfile) {\n         opt_devfile = argv[4];\n      } else if (strcmp(argv[3],\"-m\")==0 && !opt_idsfile) {\n         opt_idsfile = argv[4];\n      } else\n         usage();\n      dirname=argv[5];\n      imagefile=argv[6];\n   }\n   \n   // Check the directory\n   if (access(dirname, W_OK) == -1) {\n      if (errno != ENOENT ) {\n\t perror(dirname);\n\t exit(1);\n      }\n   }\n   \n   // Check the image file\n   if (stat(imagefile, &st) == -1) {\n      perror(imagefile);\n      exit(1);\n   }\n\n   // Map the cramfs image\n   fd = open(imagefile, O_RDONLY);\n   fslen_ub = st.st_size;\n   rom_image = mmap(0, fslen_ub, PROT_READ, MAP_SHARED, fd, 0);\n   if (rom_image == MAP_FAILED) {\n      perror(\"Mapping cramfs file\");\n      exit(1);\n   }\n   \n   sb=(struct cramfs_super const*)(rom_image);\n   // Check cramfs magic number and signature\n   if (CRAMFS_MAGIC != sb->magic ||\n       0 != memcmp(sb->signature, CRAMFS_SIGNATURE, sizeof(sb->signature))) {\n      fprintf(stderr,\"The image file doesn't have cramfs signatures\\n\");\n      exit(1);\n   }\n\n   // Set umask to 0 to let the image modes shine through\n   umask(0);\n   \n   // Print some reassuring blurb\n   printf(\"[Volume size: 0x%x]\\n\", fslen_ub);\n   printf(\"[Volume serial: \");\n   for (i=0; i< sizeof(sb->fsid); ++i)\n     printf(\"%02x\", sb->fsid[i]);\n   printf(\"]\\n\");\n   printf(\"[Volume name: %s]\\n\", sb->name);\n   printf(\"\\n\");\n\n   clearstats();\n   \n   // Start doing...\n   printf(\"do file entry \\n\");\n   do_file_entry(rom_image, dirname, \"\", \"\", 0, &sb->root);\n   printf(\"do dir entry\\n\");\n   do_dir_entry(rom_image, dirname, \"\", \"\", 0, &sb->root);\n   \n   //process_directory(rom_image, dirname, sb->root.offset<<2, sb->root.size, \".\");\n   \n   printstats();\n   return 0;\n}\n"
  },
  {
    "path": "src/untrx.cc",
    "content": "/* untrx\n * Copyright (C) 2006-2010 Jeremy Collake  <jeremy@bitsum.com>\n * http://www.bitsum.com\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n *\n * Additional patch contributors (add your own name if you submit a patch): \n *\n *    0.55 - Jeremy Collake - minor syntax fix in a buffer size calc\n *    0.54 - Jiafu Gao (fixed sqfs signature check on big endian CPUs)\n *\n */\n \n #define _VERSION_ \"0.54 beta\"\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <sys/types.h>\n\n#include <endian.h>\n#include <byteswap.h>\n#include <sys/types.h>\n\n#include \"untrx.h\"\n\n/*************************************************************************\n* IdentifySegment\n*\n* identifies segments (i.e. squashfs, cramfs) and their version numbers\n*\n**************************************************************************/\nSEGMENT_TYPE IdentifySegment(unsigned char *pData, unsigned long nLength)\n{\n\tsquashfs_super_block *sqblock=(squashfs_super_block *)pData;\n\tcramfs_super *crblock=(cramfs_super *)pData;\n\t\n\tif(sqblock->s_magic==SQUASHFS_MAGIC \n\t\t|| sqblock->s_magic==SQUASHFS_MAGIC_SWAP\n\t\t|| sqblock->s_magic==SQUASHFS_MAGIC_ALT\n\t\t|| sqblock->s_magic==SQUASHFS_MAGIC_ALT_SWAP)\n\t{\t\t\n\t\tfprintf(stderr, \" SQUASHFS magic: 0x%x\\n\", sqblock->s_magic);\n\t\tshort major = READ16_LE(sqblock->s_major);\n\t\tshort minor = READ16_LE(sqblock->s_minor);\n\t\tfprintf(stderr, \" SQUASHFS version: %d.%d\\n\", major, minor);\n\t\n\t\tswitch(major)\n\t\t{\n\t\t\tcase 3:\n\t\t\t\tswitch (minor)\n\t\t\t\t{\n\t\t\t\t\tcase 0:\t\t\t\t\t\t\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_3_0;\n\t\t\t\t\tcase 1:\t\t\t\t\t\t\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_3_1;\t\t\t\n\t\t\t\t\tcase 2:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_3_2;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_3_x;\t\t\t\t\t\t\n\t\t\t\t}\n\t\t\tcase 2:\n\t\t\t\tswitch (minor)\n\t\t\t\t{\n\t\t\t\t\tcase 0:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_2_0;\n\t\t\t\t\tcase 1:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_2_1;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_2_x;\t\t\t\t\t\t\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn SEGMENT_TYPE_SQUASHFS_OTHER;\t\t\t\t\n\t\t}\n\t}\t\n\telse if(crblock->magic==CRAMFS_MAGIC || crblock->magic==CRAMFS_MAGIC_SWAP)\n\t{\n\t\treturn SEGMENT_TYPE_CRAMFS_x_x;\t\n\t}\t\n\treturn SEGMENT_TYPE_UNTYPED;\n}\n\n/*************************************************************************\n* EmitSquashfsMagic\n*\n* writes the squashfs root block signature to a file, as a fix for\n* Brainslayer of DD-WRT deciding to change it to some arbitrary value\n* to break compatibility with this kit.\n*\n**************************************************************************/\nbool EmitSquashfsMagic(squashfs_super_block *pSuper, char *pszOutFile)\n{\n\tfprintf(stderr, \"  Writing %s\\n\", pszOutFile);\n\tFILE *fOut=fopen(pszOutFile,\"wb\");\n\tif(!fOut) return false;\n\tif(fwrite(pSuper,1,4,fOut)!=4)\n\t{\n\t\tfclose(fOut);\n\t\treturn false;\n\t}\n\tfclose(fOut);\t\n\treturn true;\n}\n\n/*************************************************************************\n* ShowUsage\n*\n*\n**************************************************************************/\nvoid ShowUsage()\n{\t\t\t\n\tfprintf(stderr, \" ERROR: Invalid usage.\\n\"\t\t\n\t\t\" USAGE: untrx binfile outfolder\\n\");\t\n\texit(9);\n}\n\n/*************************************************************************\n* main\n*\n*\n**************************************************************************/\nint main(int argc, char **argv)\n{\n\tfprintf(stderr, \" untrx \" _VERSION_ \" - (c)2006-2010 Jeremy Collake\\n\");\n\t\n\tif(argc<3)\n\t{\n\t\tShowUsage();\n\t}\n\t\n\tfprintf(stderr, \" Opening %s\\n\", argv[1]);\n\tFILE *fIn=fopen(argv[1],\"rb\");\n\tif(!fIn)\n\t{\n\t\tfprintf(stderr, \" ERROR opening %s\\n\", argv[1]);\n\t\texit(1);\n\t}\n\t\n\tchar *pszOutFolder=(char *)malloc(strlen(argv[2])+sizeof(char));\n\tstrcpy(pszOutFolder,argv[2]);\n\tif(pszOutFolder[strlen(pszOutFolder)-1]=='/')\n\t{\n\t\tpszOutFolder[strlen(pszOutFolder)-1]=0;\t\t\n\t}\t\n\t\n\tfseek(fIn,0,SEEK_END);\n\tsize_t nFilesize=ftell(fIn);\n\tfseek(fIn,0,SEEK_SET);\t\t\n\tunsigned char *pData=(unsigned char *)malloc(nFilesize);\t\n\tunsigned char *pDataOrg=pData;\n\tif(fread(pData,1,nFilesize,fIn)!=nFilesize)\n\t{\n\t\tfprintf(stderr,\" ERROR reading %s\\n\", argv[1]);\t\t\n\t\tfclose(fIn);\t\n\t\tfree(pDataOrg);\n\t\tfree(pszOutFolder);\t\n\t\texit(1);\n\t}\t\n\tfclose(fIn);\t\n\tfprintf(stderr, \" read %u bytes\\n\", nFilesize);\n\t\n\t// uf U2ND header present, skip past it (pData is preserved above)\n\tunsigned long nDataSkip=0;\n\ttrx_header *trx=(trx_header *)pData;\n\tif(READ32_LE(trx->magic)!=TRX_MAGIC)\n\t{\n\t\tpData+=U2ND_HEADER_SIZE;\t\t\t\n\t\ttrx=(trx_header *)pData;\t\n\t\tif(READ32_LE(trx->magic)!=TRX_MAGIC)\n\t\t{\n\t\t\tfprintf(stderr,\" ERROR trx header not found\\n\");\n\t\t\tfree(pDataOrg);\n\t\t\tfree(pszOutFolder);\t\n\t\t\texit(2);\t\t\t\n\t\t}\n\t}\n\t\n\t// allocate filename buffer\n\tchar *pszTemp=(char *)\n\t\tmalloc((strlen(pszOutFolder)*sizeof(char))+(128*sizeof(char)));\t\t\t\n\t\n\t/* Extract the segments */\n\tfor(int nI=0;nI<3 && READ32_LE(trx->offsets[nI]);nI++)\n\t{\n\t\tFILE *fOut;\t\t\t\n\t\t\n\t\tunsigned long nEndOffset=0;\n\t\tif(nI<2)\n\t\t{\n\t\t\tnEndOffset=READ32_LE(trx->offsets[nI+1]);\n\t\t}\n\t\tif(!nEndOffset)\n\t\t{\n\t\t\tnEndOffset=nFilesize;\n\t\t}\t\t\n\t\t\n\t\tswitch(IdentifySegment(pData+READ32_LE(trx->offsets[nI]),\n\t\t\tnEndOffset-READ32_LE(trx->offsets[nI])))\n\t\t{\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_3_0:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v3.0 image detected\\n\");\t\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs_magic\",pszOutFolder);\t\t\t\t\t\t\t\t\n\t\t\t\tif(!EmitSquashfsMagic((squashfs_super_block *)((char *)pData\n\t\t\t\t\t+READ32_LE(trx->offsets[nI])),pszTemp))\n\t\t\t\t{\n\t\t\t\t\tfprintf(stderr,\"  ERROR - writing %s\\n\", pszTemp);\n\t\t\t\t\tfree(pDataOrg);\n\t\t\t\t\tfree(pszOutFolder);\t\n\t\t\t\t\tfree(pszTemp);\n\t\t\t\t\texit(3);\t\t\n\t\t\t\t}\t\t\t\t\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-3_0\",pszOutFolder);\t\t\t\t\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_3_1:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v3.1 image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-3_1\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_3_2:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v3.2 image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-3_2\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_3_x:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v3.x (>3.2) image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-3_x\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_2_0:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v2.0 image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-2_0\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_2_1:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v2.1 image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-2_1\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_2_x:\n\t\t\t\tfprintf(stderr, \"  SQUASHFS v2.x image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-2_x\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_SQUASHFS_OTHER:\n\t\t\t\tfprintf(stderr, \"  ! WARNING: Unknown squashfs version.\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/squashfs-lzma-image-x_x\",pszOutFolder);\n\t\t\t\tbreak;\n\t\t\tcase SEGMENT_TYPE_CRAMFS_x_x:\n\t\t\t\tfprintf(stderr, \"  CRAMFS v? image detected\\n\");\n\t\t\t\tsprintf(pszTemp,\"%s/cramfs-image-x_x\",pszOutFolder);\n\t\t\t\tbreak;\t\t\t\t\n\t\t\tdefault:\n\t\t\t\tsprintf(pszTemp,\"%s/segment%d\",pszOutFolder,nI+1);\n\t\t\t\tbreak;\t\t\t\n\t\t}\t\t\n\t\tfprintf(stderr,\"  Writing %s\\n    size %d from offset %d ...\\n\", \n\t\t\tpszTemp, \n\t\t\tnEndOffset-READ32_LE(trx->offsets[nI]),\n\t\t\tREAD32_LE(trx->offsets[nI]));\t\t\n\n\t\tfOut=fopen(pszTemp,\"wb\");\n\t\tif(!fOut)\n\t\t{\n\t\t\tfprintf(stderr,\"  ERROR could not open %s\\n\", pszTemp);\n\t\t\tfree(pDataOrg);\n\t\t\tfree(pszOutFolder);\t\n\t\t\tfree(pszTemp);\n\t\t\texit(3);\t\t\n\t\t}\t\t\t\t\n\t\tif(!fwrite(pData+READ32_LE(trx->offsets[nI]),1,\n\t\t\tnEndOffset-READ32_LE(trx->offsets[nI]),fOut))\n\t\t{\n\t\t\tfprintf(stderr,\" ERROR could not write %s\\n\", pszTemp);\n\t\t\tfclose(fOut);\n\t\t\tfree(pDataOrg);\n\t\t\tfree(pszOutFolder);\t\n\t\t\tfree(pszTemp);\n\t\t\texit(4);\t\t\t\t\n\t\t}\n\t\tfclose(fOut);\t\n\t}\n\t\n\tfree(pDataOrg);\n\tfree(pszOutFolder);\t\n\tfree(pszTemp);\n\tprintf(\"  Done!\\n\");\n\texit(0);\n}\n"
  },
  {
    "path": "src/untrx.h",
    "content": "/***************************************************************************\n *            untrx.h\n *\n *  Thu Aug 24 19:58:55 2006\n *  Copyright  2006  Jeremy Collake\n *  jeremy@bitsum.com\n ****************************************************************************/\n\n/*\n *  This program is free software; you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation; either version 2 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program; if not, write to the Free Software\n *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n */\n \n#ifndef _UNTRX_H\n#define _UNTRX_H\n\n/*\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif\n*/\n\t\n/************************************************************\n\tVarious stuff\t\n************************************************************/\t\n\t\n/* bit size specific type fixes for msvc and other systems */\n#ifndef __int8_t_defined\n#ifdef __int32\n\t#typedef u_int32_t unsigned __int32\n#else\t\n\t#warning \"u_int32_t may be undefined. please define as 32-bit type.\"\n\t//#define u_int32_t unsigned long\t /* for 32-bit builds .. */\n#endif\n#endif\n\n\n/* stuff for quick OS X compatibility by Jeremy Collake */\n#ifndef bswap_32\n#define bswap_32 flip_endian\n#endif\n\n#ifndef bswap_16\n#define bswap_16 flip_endian16\n\nshort flip_endian16(short n)\n{\n\treturn (n>>8) | (n<<8);\n}\n#endif\n\n// always flip, regardless of endianness of machine\nu_int32_t flip_endian(u_int32_t nValue)\n{\n\t// my crappy endian switch\n\tu_int32_t nR;\n\tu_int32_t nByte1=(nValue&0xff000000)>>24;\n\tu_int32_t nByte2=(nValue&0x00ff0000)>>16;\n\tu_int32_t nByte3=(nValue&0x0000ff00)>>8;\n\tu_int32_t nByte4=nValue&0x0ff;\n\tnR=nByte4<<24;\n\tnR|=(nByte3<<16);\n\tnR|=(nByte2<<8);\n\tnR|=nByte1;\n\treturn nR;\n}\n\n#if __BYTE_ORDER == __BIG_ENDIAN\n#define STORE32_LE(X)\t\tbswap_32(X)\n#define READ32_LE(X)        bswap_32(X)\n#define STORE16_LE(X)\t\tbswap_16(X)\n#define READ16_LE(X)        bswap_16(X)\n#elif __BYTE_ORDER == __LITTLE_ENDIAN\n#define STORE32_LE(X)\t\t(X)\n#define READ32_LE(X)        (X)\n#define STORE16_LE(X)        (X)\n#define READ16_LE(X)        (X)\n#else\n#error unkown endianness!\n#endif\n\n/**********************************************************************/\n/* from trxhdr.h */\n\n#define TRX_MAGIC\t0x30524448\t/* \"HDR0\" */\n\ntypedef struct _trx_header {\n\tu_int32_t magic;\t\t\t/* \"HDR0\" */\n\tu_int32_t len;\t\t\t/* Length of file including header */\n\tu_int32_t crc32;\t\t\t/* 32-bit CRC from flag_version to end of file */\n\tu_int32_t flag_version;\t/* 0:15 flags, 16:31 version */\n\tu_int32_t offsets[3];\t/* Offsets of partitions from start of header */\n} trx_header;\n\n/**********************************************************************/\n\n#define HDR0_SIZE (sizeof(trx_header))\n\n// size of header added by addpattern\n#define U2ND_HEADER_SIZE 32\t\n\n/* segment stuff */\n#define SEGMENT_BASE_NAME \"trx_segment\"\t\ntypedef enum _SEGMENT_TYPE\n{\n\tSEGMENT_TYPE_UNTYPED,\n\tSEGMENT_TYPE_SQUASHFS_2_0,\n\tSEGMENT_TYPE_SQUASHFS_2_1,\n\tSEGMENT_TYPE_SQUASHFS_2_x,\n\tSEGMENT_TYPE_SQUASHFS_3_0,\n\tSEGMENT_TYPE_SQUASHFS_3_1,\n\tSEGMENT_TYPE_SQUASHFS_3_2,\n\tSEGMENT_TYPE_SQUASHFS_3_x,\n\tSEGMENT_TYPE_SQUASHFS_OTHER,\n\tSEGMENT_TYPE_CRAMFS_x_x,\n\tSEGMENT_TYPE_CRAMFS_OTHER\t\n} SEGMENT_TYPE, *PSEGMENT_TYPE;\n\t\n/************************************************************\n\tsquashfs v3.0 stuff (hopefully applies to other versions too)\n************************************************************/\n\ntypedef long long\t\tsquashfs_inode_t;\n\t\ntypedef struct squashfs_super_block squashfs_super_block;\ntypedef squashfs_inode_t squashfs_inode;\n\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n\n/* jc: for dd-wrt build as of 09/10/06\n   note: thanks a bunch Brainslayer <sarcasm> */\n#define SQUASHFS_MAGIC_ALT\t\t0x74717368\n#define SQUASHFS_MAGIC_ALT_SWAP\t0x68737174\n\nstruct squashfs_super_block {\n\tunsigned int\t\ts_magic;\n\tunsigned int\t\tinodes;\n\tunsigned int\t\tbytes_used_2;\n\tunsigned int\t\tuid_start_2;\n\tunsigned int\t\tguid_start_2;\n\tunsigned int\t\tinode_table_start_2;\n\tunsigned int\t\tdirectory_table_start_2;\n\tunsigned int\t\ts_major:16;\n\tunsigned int\t\ts_minor:16;\n\tunsigned int\t\tblock_size_1:16;\n\tunsigned int\t\tblock_log:16;\n\tunsigned int\t\tflags:8;\n\tunsigned int\t\tno_uids:8;\n\tunsigned int\t\tno_guids:8;\n\tunsigned int\t\tmkfs_time /* time of filesystem creation */;\n\tsquashfs_inode_t\troot_inode;\n\tunsigned int\t\tblock_size;\n\tunsigned int\t\tfragments;\n\tunsigned int\t\tfragment_table_start_2;\n\tlong long\t\tbytes_used;\n\tlong long\t\tuid_start;\n\tlong long\t\tguid_start;\n\tlong long\t\tinode_table_start;\n\tlong long\t\tdirectory_table_start;\n\tlong long\t\tfragment_table_start;\n\tlong long\t\tunused;\n} __attribute__ ((packed));\t\n\n#define SQUASHFS_MAJOR\t\t\t3\n#define SQUASHFS_MINOR\t\t\t0\n#define SQUASHFS_MAGIC\t\t\t0x73717368\n#define SQUASHFS_MAGIC_SWAP\t\t0x68737173\n\n// jc: for dd-wrt build as of 09/10/06\n#define SQUASHFS_MAGIC_ALT\t\t0x74717368\n#define SQUASHFS_MAGIC_ALT_SWAP\t0x68737174\n\n/************************************************************\n\tcramfs v? stuff\n************************************************************/\n#define CRAMFS_MAGIC 0x28cd3d45\n#define CRAMFS_MAGIC_SWAP 0x453dcd28 \n\nstruct cramfs_super {\n\tu_int32_t magic;\t\t/* 0x28cd3d45 - random number */\n\tu_int32_t size;\t\t/* Not used.  mkcramfs currently\n                                   writes a constant 1<<16 here. */\n\tu_int32_t flags;\t\t/* 0 */\n\tu_int32_t future;\t\t/* 0 */\n\tu_int8_t signature[16];\t/* \"Compressed ROMFS\" */\n\tu_int8_t fsid[16];\t\t/* random number */\n\tu_int8_t name[16];\t\t/* user-defined name */\n\t//struct cramfs_inode root;\t/* Root inode data */\n};\n\n/*\n#ifdef __cplusplus\n}\n#endif\n*/\n\n#endif /* _UNTRX_H */\n"
  },
  {
    "path": "src/webcomp-tools/Makefile",
    "content": "CC=gcc\nCFLAGS=-g -Wall\n\nall: webdecomp\n\nwebdecomp: common.o\n\t$(CC) $(CFLAGS) $(LDFLAGS) *.o webdecomp.c -o webdecomp\n\ncommon.o:\n\t$(CC) $(CFLAGS) $(LDFLAGS) -c common.c\n\nclean:\n\trm -f webdecomp\n\trm -f *.o\n\ndistclean: clean\n"
  },
  {
    "path": "src/webcomp-tools/README",
    "content": "DESCRIPTION\n\t\n\tWebcomp tools are a set of utilities for modifying the Web UI files embedded in DD-WRT firmware.\n\nHOW IT WORKS:\n\n\tThe Web files for all DD-WRT firmware are embedded in binary files, rather than storing the Web \n\tfiles individually on the file system.\n\n\tThere are two files involved with this system:\n\n\t\t1) The httpd binary (/usr/sbin/httpd)\n\t\t2) The www file (/etc/www)\n\t\n\tThe actual Web file contents are concatenated together into the /etc/www file, while the names, \n\tsizes and offsets of each file are stored in an array of data structures inside the httpd binary.\n\n\tThe structure for each file entry in the httpd binary is:\n\n\t\tstruct file_entry\n\t\t{\n\t\t\tchar *file_name;\t/* Pointer to the file name */\n\t\t\tuint32_t file_offset;\t/* Offset of the file data in the /etc/www file */\n\t\t\tuint32_t file_size;\t/* Total size of the file data */\n\t\t\t\t\t\t/* jc: the indexes may be added by a constant that varies between builds */\n\t\t};\n\t\n\tAn array of these structures can be found in the httpd binary. The beginning of the array is located\n\tat the address indicated by the websRomPageIndex object:\n\n\t\t$ readelf --arch-specific usr/sbin/httpd\n\t\t...\n\t\t004372e8 -31416(gp) <unknown> 004352c8 OBJECT   19 websRomPageIndex\n\t\t...\n\n\tIn the above example, websRomPageIndex is loaded at address 0x004352c8 at run time. Knowing this, the \n\tphysical location of this object in the httpd binary can be calculated, and the file names, offsets, and \n\tsizes of the Web UI files can be extracted.\n\nUSAGE:\n\n\tUsage is fairly straight forward. You must supply webdecomp with the paths to the www and httpd files.\n\n\tTo extract files:\n\n\t\t$ ./webdecomp --httpd=rootfs/usr/sbin/httpd --www=rootfs/etc/www --extract\n\n\tTo restore modified files:\n\n\t\t$ ./webdecomp --httpd=rootfs/usr/sbin/httpd --www=rootfs/etc/www --restore\n\n\tThe default input/output directory is 'www'. You may specify an alternate directory with the --dir argument.\n\n\t\t\n"
  },
  {
    "path": "src/webcomp-tools/common.c",
    "content": "#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <string.h>\n#include <arpa/inet.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include <elf.h>\n#include \"common.h\"\n\n/* Given the physical and virtual section loading addresses, convert a virtual address to a physical file offset */\nuint32_t file_offset(uint32_t address, uint32_t virtual, uint32_t physical)\n{\n        uint32_t offset = 0;\n\n        offset = (address-virtual+physical);\n\n        return offset;\n}\n\n/* Given the literal file offset and virtual section loading addresses, convert a physical file offset to a virtual address */\nuint32_t virtual_address(uint32_t offset, uint32_t virtual, uint32_t physical)\n{\n\tuint32_t address = 0;\n\n\taddress = (offset+virtual-physical);\n\n\treturn address;\n}\n\n/* Check to see if the data offsets reported by next_entry make sense; this is used to detect if the new or old webcomp data structures are in use. */\nint are_entry_offsets_valid(unsigned char *data, uint32_t size)\n{\n\tint retval = 0;\n\tstruct entry_info *first = NULL;\n\n\tfirst = next_entry(data, size);\n\tif(first)\n\t{\n\t\tif(first->offset == 0 && (first->size < first->name_ptr))\n\t\t{\n\t\t\tretval = 1;\n\t\t}\n\n\t\tfree(first);\n\t}\n\n\tnext_entry(NULL, 0);\n\n\treturn retval;\n}\n\n\n/* Returns the next web file entry */\nstruct entry_info *next_entry(unsigned char *data, uint32_t size)\n{\n\tstatic int n = 0, total_size = 0;\n\tuint32_t entry_size = 0, offset = 0, str_offset = 0;\n\tstruct entry_info *info = NULL;\n\n\tif(data == NULL || size == 0)\n\t{\n\t\tn = 0;\n\t\ttotal_size = 0;\n\t\treturn NULL;\n\t}\n\n\tif(globals.use_new_format)\n\t{\n\t\tentry_size = sizeof(struct new_file_entry);\n\t}\n\telse\n\t{\n\t\tentry_size = sizeof(struct file_entry);\n\t}\n\n\t/* Calculate the offset into the array for the next entry */\n\toffset = globals.index_address + (entry_size * n);\n\n\tif(offset < size)\n\t{\n\t\tinfo = malloc(sizeof(struct entry_info));\n\t\tif(info)\n\t\t{\n\t\t\tmemset(info, 0, sizeof(struct entry_info));\n\n\t\t\t/* Calculate the offset if this firmware uses the new structure format */\n\t\t\tif(globals.use_new_format)\n\t\t\t{\n\t\t\t\tinfo->new_entry = (struct new_file_entry *) (data + offset);\n\t\t\t\tinfo->name_ptr = info->new_entry->name;\n\t\t\t\tinfo->size = info->new_entry->size;\n\t\t\t\tinfo->offset = total_size;\n\t\t\t\t/* Convert data to little endian, if necessary */\n\t\t\t\tntoh_struct(info);\n\t\t\t\tinfo->size -= globals.key;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tinfo->entry = (struct file_entry *) (data + offset);\n\t\t\t\tinfo->size = info->entry->size;\n\t\t\t\tinfo->offset = info->entry->offset;\n\t\t\t\tinfo->name_ptr = info->entry->name;\n\t\t\t\t/* Convert data to little endian, if necessary */\n\t\t\t\tntoh_struct(info);\n\t\t\t}\n\t\t\t\t\n\t\t\t/* A NULL entry name signifies the end of the array */\n\t\t\tif(info->name_ptr == 0)\n\t\t\t{\n\t\t\t\tfree(info);\n\t\t\t\tinfo = NULL;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* Get the physical offset of the file name string */\n\t\t\t\tstr_offset = file_offset(info->name_ptr, globals.tv_address, globals.tv_offset);\n\n\t\t\t\t/* Sanity check */\n\t\t\t\tif(str_offset >= size)\n\t\t\t\t{\n\t\t\t\t\tfree(info);\n\t\t\t\t\tinfo = NULL;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Point entry->name at the actual string */\n\t\t\t\t\tinfo->name = (char *) (data + str_offset);\n\n\t\t\t\t\t/* Track the total size of the processed entries so far, and increment the entry count */\n\t\t\t\t\ttotal_size += info->size;\n\t\t\t\t\tn++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn info;\n}\n\n/* Get the virtual addresses and physical offsets of the program headers in the ELF file */\nint parse_elf_header(unsigned char *data, size_t size)\n{\n\tint i = 0, n = 0, retval = 0;\n\tuint32_t phoff = 0, type = 0, flags = 0;\n\tuint16_t phnum = 0;\n\tElf32_Ehdr *header = NULL;\n\tElf32_Phdr *program = NULL;\n\n\tif(data && size > sizeof(Elf32_Ehdr))\n\t{\n\t\theader = (Elf32_Ehdr *) data;\n\n\t\tif(strncmp((char *) &header->e_ident, ELF_MAGIC, 4) == 0)\n\t\t{\n\t\t\tif(header->e_ident[EI_DATA] == ELFDATA2MSB)\n\t\t\t{\n\t\t\t\tglobals.endianess = BIG_ENDIAN;\n\n\t\t\t\tphnum = ntohs(header->e_phnum);\n\t\t\t\tphoff = ntohl(header->e_phoff);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tglobals.endianess = LITTLE_ENDIAN;\n\t\t\t\n\t\t\t\tphnum = header->e_phnum;\n\t\t\t\tphoff = header->e_phoff;\n\t\t\t}\n\n\t\t\t/* Loop through program headers looking for TEXT and DATA headers */\n\t\t\tfor(i=0; i<phnum; i++)\n\t\t\t{\n\t\t\t\tprogram = (Elf32_Phdr *) (data + phoff + (sizeof(Elf32_Phdr) * i));\n\n\t\t\t\tif(globals.endianess == LITTLE_ENDIAN)\n\t\t\t\t{\n\t\t\t\t\ttype = program->p_type;\n\t\t\t\t\tflags = program->p_flags;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ttype = htonl(program->p_type);\n\t\t\t\t\tflags = htonl(program->p_flags);\n\t\t\t\t}\n\n\t\t\t\tif(type == PT_LOAD)\n\t\t\t\t{\n\t\t\t\t\t/* TEXT */\n\t\t\t\t\tif((flags | PF_X) == flags)\n\t\t\t\t\t{\n\t\t\t\t\t\tglobals.tv_address = program->p_vaddr;\n\t\t\t\t\t\tglobals.tv_offset = program->p_offset;\n\t\t\t\t\t\tn++;\n\t\t\t\t\t}\n\t\t\t\t\t/* DATA */\n\t\t\t\t\telse if((flags | PF_R | PF_W) == flags)\n\t\t\t\t\t{\n\t\t\t\t\t\tglobals.dv_address = program->p_vaddr;\n\t\t\t\t\t\tglobals.dv_offset = program->p_offset;\n\t\t\t\t\t\tn++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/* Return true if both program headers were identified */\n\t\t\t\tif(n == NUM_PROGRAM_HEADERS)\n\t\t\t\t{\n\t\t\t\t\tretval = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\n\tif(globals.endianess == BIG_ENDIAN)\n\t{\n\t\tglobals.tv_address = htonl(globals.tv_address);\n\t\tglobals.tv_offset = htonl(globals.tv_offset);\n\t\tglobals.dv_address = htonl(globals.dv_address);\n\t\tglobals.dv_offset = htonl(globals.dv_offset);\n\t}\n\n\treturn retval;\n}\n\n/* Get the virtual offset to the websRomPageIndex variable */\nint find_websRomPageIndex(char *data, size_t size)\n{\n\tint i = 0, len = 0, poff = 0, tmpoff = 0, retval = 0;\n\tstruct file_entry entry = { 0 };\n\tuint32_t string_vaddr = 0;\n\n\t/* Index may have already been set by user. If so, trust the user. */\n\tif(globals.index_address != 0)\n\t{\n\t\tretval = 1;\n\t}\n\telse\n\t{\n\t\twhile(tmpoff < size)\n\t\t{\n\t\t\t/* Find the location of the first string that ends in '.asp'  */\n\t\t\ttmpoff = find(ASP, (data+tmpoff), (size-tmpoff));\n\n\t\t\t/* Find the beginning of the string by looping backwards from the '.asp' until we get a non-ASCII character */\n\t\t\twhile(is_ascii((data+tmpoff), 1))\n\t\t\t{\n\t\t\t\ttmpoff--;\n\t\t\t}\n\t\t\ttmpoff++;\n\n\t\t\tlen = strlen(data+tmpoff);\n\n\t\t\tif(len > ASP_LEN)\n\t\t\t{\n\t\t\t\tpoff = tmpoff;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ttmpoff += len;\n\t\t\t}\n\t\t}\n\t\n\t\tif(poff)\n\t\t{\n\t\t\t/* Convert the file offset to a virtual address */\n\t\t\tstring_vaddr = virtual_address(poff, globals.tv_address, globals.tv_offset);\n\n\t\t\t/* Swap the virtual address endinaess, if necessary */\n\t\t\tif(globals.endianess == BIG_ENDIAN)\n\t\t\t{\n\t\t\t\tstring_vaddr = htonl(string_vaddr);\n\t\t\t}\n\n\t\t\t/* Loop through the binary looking for references to the string's virtual address */\t\n\t\t\tfor(i=globals.tv_offset; i<(size-sizeof(struct file_entry)); i++)\n\t\t\t{\n\t\t\t\tmemcpy((void *) &entry, data+i, sizeof(struct file_entry));\n\n\t\t\t\t/* The first entry in the structure array should have an offset of zero and a size greater than zero */\n\t\t\t\tif(entry.name == string_vaddr && \n\t\t\t\t  ((entry.offset == 0 && entry.size < entry.name) || \n\t\t\t\t   (entry.size > 0)))\n\t\t\t\t{\n\t\t\t\t\tglobals.index_address = i;\n\t\t\t\t\tretval = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Convert structure members from big to little endian, if necessary */\nvoid ntoh_struct(struct entry_info *info)\n{\n\tif(globals.endianess == BIG_ENDIAN)\n\t{\n\t\tinfo->name_ptr = (uint32_t) ntohl(info->name_ptr);\n\t\tinfo->size = (uint32_t) ntohl(info->size);\n\t\t\n\t\t/* If using the new format, we calculate the offset, so it is going to be in host byte format */\n\t\tif(!globals.use_new_format)\n\t\t{\n\t\t\tinfo->offset = (uint32_t) ntohl(info->offset);\n\t\t}\n\t}\n\n\treturn;\n}\n\n/* Convert structure members from little to big endian, if necessary */\nvoid hton_struct(struct entry_info *info)\n{\n\tif(globals.endianess == BIG_ENDIAN)\n\t{\n\t\tinfo->name_ptr = (uint32_t) htonl(info->name_ptr);\n\t\tinfo->size = (uint32_t) htonl(info->size);\n\t\tinfo->offset = (uint32_t) htonl(info->offset);\n\t}\n\n\treturn;\n}\n\n/* Convert entry data values from little to big endian, if necessary */\nvoid hton_entries(struct entry_info *info)\n{\n\tif(globals.endianess == BIG_ENDIAN)\n\t{\n\t\tif(info->entry)\n\t\t{\n\t\t\tinfo->entry->size = (uint32_t) htonl(info->entry->size);\n\t\t\tinfo->entry->offset = (uint32_t) htonl(info->entry->offset);\n\t\t}\n\n\t\tif(info->new_entry)\n\t\t{\n\t\t\tinfo->new_entry->size = (uint32_t) htonl(info->new_entry->size);\n\t\t}\n\t}\n\n\treturn;\n}\n\n/* Verify if the given data is printable ASCII */\nint is_ascii(char *data, int len)\n{\n\tint i = 0, retval = 0;\n\n\tfor(i=0; i<len; i++)\n\t{\n\t\tif(data[i] < ' ' || data[i] > 'z')\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif(i == len)\n\t{\n\t\tretval = 1;\n\t}\n\n\treturn retval;\n}\n\n/* Find a needle in a haystack */\nint find(char *needle, char *haystack, size_t size)\n{\n        int i = 0, offset = 0, len = 0;\n\n        if(haystack && needle)\n        {\n\t\tlen = strlen(needle);\n\n                for(i=0; i<(size-len); i++)\n                {\n                        if(memcmp(haystack+i, needle, len) == 0)\n                        {\n                                offset = i;\n                                break;\n                        }\n                }\n        }\n\n        return offset;\n}\n\n/* Reads in and returns the contents and size of a given file */\nchar *file_read(char *file, size_t *fsize)\n{\n        int fd = 0;\n        struct stat _fstat = { 0 };\n        char *buffer = NULL;\n\n\t*fsize = 0;\n\n        if(stat(file, &_fstat) == -1)\n        {\n                perror(file);\n                goto end;\n        }\n\n        if(_fstat.st_size == 0)\n        {\n                fprintf(stderr, \"%s: zero size file\\n\", file);\n                goto end;\n        }\n\n        fd = open(file,O_RDONLY);\n        if(!fd)\n        {\n                perror(file);\n                goto end;\n        }\n\n        buffer = malloc(_fstat.st_size);\n        if(!buffer)\n        {\n                perror(\"malloc\");\n                goto end;\n        }\n        memset(buffer, 0 ,_fstat.st_size);\n\n        if(read(fd, buffer, _fstat.st_size) != _fstat.st_size)\n        {\n                perror(file);\n                if(buffer) free(buffer);\n                buffer = NULL;\n        }\n        else\n        {\n                *fsize = _fstat.st_size;\n        }\n\nend:\n        if(fd) close(fd);\n        return buffer;\n}\n\n/* Writes data to the specified file */\nint file_write(char *file, unsigned char *data, size_t size)\n{\n\tFILE *fp = NULL;\n\tint retval = 0;\n\n\tfp = fopen(file, \"wb\");\n\tif(fp)\n\t{\n\t\tif(fwrite(data, 1, size, fp) != size)\n\t\t{\n\t\t\tperror(\"fwrite\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tretval = 1;\n\t\t}\n\n\t\tfclose(fp);\n\t}\n\telse\n\t{\n\t\tperror(\"fopen\");\n\t}\n\n\treturn retval;\n}\n\n/* Recursive mkdir (same as mkdir -p) */\nvoid mkdir_p(char *dir) \n{\n        char tmp[FILENAME_MAX] = { 0 };\n        char *p = NULL;\n        size_t len = 0;\n \n        snprintf(tmp, sizeof(tmp),\"%s\",dir);\n        len = strlen(tmp);\n\n        if(tmp[len - 1] == '/')\n\t{\n\t\ttmp[len - 1] = 0;\n\t}\n\n        for(p = tmp + 1; *p; p++)\n\t{\n                if(*p == '/') \n\t\t{\n                        *p = 0;\n                        mkdir(tmp, S_IRWXU);\n                        *p = '/';\n                }\n\t}\n\n        mkdir(tmp, S_IRWXU);\n\n\treturn;\n}\n\n/* Sanitize the specified file path */\nchar *make_path_safe(char *path)\n{\n\tint size = 0;\n\tchar *safe = NULL;\n\n\t/* Make sure the specified path is valid, and that there are no traversal issues */\n\tif(path != NULL && strstr(path, DIRECTORY_TRAVERSAL) == NULL)\n\t{\n\t\t/* Append a './' to the beginning of the file path */\n\t\tsize = strlen(path) + strlen(PATH_PREFIX) + 1;\n\t\tsafe = malloc(size);\n\t\tif(safe)\n\t\t{\n\t\t\tmemset(safe, 0, size);\n\t\t\tmemcpy(safe, PATH_PREFIX, 2);\n\t\t\tstrcat(safe, path);\n\t\t}\n\t}\n\n\treturn safe;\n}\n"
  },
  {
    "path": "src/webcomp-tools/common.h",
    "content": "#ifndef _COMMON_H_\n#define _COMMON_H_\n\n#include <stdint.h>\n\n#define DEFAULT_OUTDIR \t\t\"www\"\n#define DIRECTORY_TRAVERSAL \t\"..\"\n#define PATH_PREFIX \t\t\"./\"\n#define ASP\t\t\t\".asp\\x00\"\n#define ASP_LEN\t\t\t5\n#define ELF_MAGIC\t\t\"\\x7F\\x45\\x4C\\x46\"\n#define NUM_PROGRAM_HEADERS\t2\n\n#pragma pack(1)\n\n/* Used by later versions of DD-WRT */\nstruct new_file_entry\n{\n\tuint32_t name;\n\tuint32_t size;\n};\n\n/* Used by most versions of DD-WRT */\nstruct file_entry\n{\n\tuint32_t name;\n\tuint32_t offset;\n\tuint32_t size;\n};\n\nstruct entry_info\n{\n\tchar *name;\n\tuint32_t name_ptr;\n\tuint32_t size;\n\tuint32_t offset;\n\tstruct file_entry *entry;\n\tstruct new_file_entry *new_entry;\n};\n\nstruct global\n{\n\tint endianess;\n\tint use_new_format;\n\tuint32_t index_address;\n\tuint32_t dv_address;\n\tuint32_t dv_offset;\n\tuint32_t tv_address;\n\tuint32_t tv_offset;\n\tuint32_t key;\n} globals;\n\nvoid mkdir_p(char *dir);\nchar *make_path_safe(char *path);\nint is_ascii(char *data, int len);\nchar *file_read(char *file, size_t *fsize);\nvoid ntoh_struct(struct entry_info *info);\nvoid hton_struct(struct entry_info *info);\nvoid hton_entries(struct entry_info *info);\nint find_websRomPageIndex(char *data, size_t size);\nint find(char *needle, char *haystack, size_t size);\nint parse_elf_header(unsigned char *data, size_t size);\nint file_write(char *file, unsigned char *data, size_t size);\nint are_entry_offsets_valid(unsigned char *data, uint32_t size);\nstruct entry_info *next_entry(unsigned char *data, uint32_t size);\nuint32_t file_offset(uint32_t address, uint32_t virtual, uint32_t physical);\nuint32_t virtual_address(uint32_t offset, uint32_t virtual, uint32_t physical);\n\n#endif\n"
  },
  {
    "path": "src/webcomp-tools/webdecomp.c",
    "content": "/*\n * Extracts the embedded Web GUI files from DD-WRT file systems.\n *\n * Craig Heffner\n * 07 September 2011\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <libgen.h>\n#include <getopt.h>\n#include \"common.h\"\n#include \"webdecomp.h\"\n\nint main(int argc, char *argv[])\n{\n\tchar *httpd = NULL, *www = NULL, *dir = NULL, *key = NULL;\n\tint retval = EXIT_FAILURE, action = NONE, long_opt_index = 0, n = 0;\n\tchar c = 0;\n\n\tchar *short_options = \"b:w:d:k:i:erh\";\n\tstruct option long_options[] = {\n\t\t{ \"httpd\", required_argument, NULL, 'b' },\n\t\t{ \"www\", required_argument, NULL, 'w' },\n\t\t{ \"dir\", required_argument, NULL, 'd' },\n\t\t{ \"key\", optional_argument, NULL, 'k' },\n\t\t{ \"index\", required_argument, NULL, 'i' },\n\t\t{ \"extract\", no_argument, NULL, 'e' },\n\t\t{ \"restore\", no_argument, NULL, 'r' },\n\t\t{ \"help\", no_argument, NULL, 'h' },\n\t\t{ 0, 0, 0, 0 }\n\t};\n\n\tmemset((void *) &globals, 0, sizeof(globals));\n\t\n\twhile((c = getopt_long(argc, argv, short_options, long_options, &long_opt_index)) != -1)\n\t{\n\t\tswitch(c)\n\t\t{\n\t\t\tcase 'b':\n\t\t\t\thttpd = strdup(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'w':\n\t\t\t\twww = strdup(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'd':\n\t\t\t\tdir = strdup(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'k':\n\t\t\t\tkey = strdup(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\t\taction = EXTRACT;\n\t\t\t\tbreak;\n\t\t\tcase 'r':\n\t\t\t\taction = RESTORE;\n\t\t\t\tbreak;\n\t\t\tcase 'i':\n\t\t\t\tglobals.index_address = atoi(optarg);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tusage(argv[0]);\n\t\t\t\tgoto end;\n\t\t\t\n\t\t}\n\t}\n\n\t/* Verify that all required options were specified  */\n\t/* Keyfile is optional */\n\tif(action == NONE || httpd == NULL || www == NULL)\n\t{\n\t\tusage(argv[0]);\n\t\tgoto end;\n\t}\n\n\t/* If no output directory was specified, use the default (www) */\n\tif(!dir)\n\t{\n\t\tdir = strdup(DEFAULT_OUTDIR);\n\t}\n\n\t/* Extract! */\n\tif(action == EXTRACT)\n\t{\n\t\tn = extract(httpd, www, dir, key);\n\t}\n\t/* Restore! */\n\telse if(action == RESTORE)\n\t{\n\t\tn = restore(httpd, www, dir, key);\n\t}\n\n\tif(n > 0)\n\t{\n\t\tprintf(\"\\nProcessed %d Web files.\\n\\n\", n);\n\t\tretval = EXIT_SUCCESS;\n\t}\n\telse\n\t{\n\t\tfprintf(stderr, \"Failed to process Web files!\\n\");\n\t}\n\nend:\n\tif(httpd) free(httpd);\n\tif(www) free(www);\n\tif(dir) free(dir);\n\treturn retval;\n}\n\n/* Initializes everything for extract() and restore() */\nint detect_settings(unsigned char *httpd, size_t httpd_size)\n{\n\tint retval = 0;\n\n\tif(parse_elf_header(httpd, httpd_size))\n\t{\n\t\tif(find_websRomPageIndex((char *) httpd, httpd_size))\n\t\t{\n\t\t\t/* If the entry offsets are not valid, then the firmware must be using the new webcomp structure format */\n\t\t\tif(!are_entry_offsets_valid(httpd, httpd_size))\n\t\t\t{\n\t\t\t\tglobals.use_new_format = 1;\n\t\t\t}\n\n\t\t\tretval = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfprintf(stderr, \"Failed to locate websRomPageIndex!\\n\");\n\t\t}\n\t}\n\telse\n\t{\n\t\tfprintf(stderr, \"Failed to parse ELF header!\\n\");\n\t}\n\n\treturn retval;\n}\n\n/* Dynamically detect the key offset to be subtracted from each entry size.  */\nvoid detect_key(char *httpd, char *www)\n{\n\tint total_size = 0, total_entries = 0;\n\tsize_t hsize = 0, wsize = 0;\n\tunsigned char *hdata = NULL, *wdata = NULL;\n\tstruct entry_info *info = NULL;\n\n\thdata = (unsigned char *) file_read(httpd, &hsize);\n\twdata = (unsigned char *) file_read(www, &wsize);\n\n\tif(hdata && wdata)\n\t{\n\t\twhile((info = next_entry(hdata, hsize)) != NULL)\n\t\t{\n\t\t\ttotal_size += info->size;\n\t\t\ttotal_entries++;\n\t\t}\n\t}\n\n\t/* Reset the next_entry counters for subsequent entry processing */\n\tnext_entry(NULL, 0);\n\n\tif(hdata) free(hdata);\n\tif(wdata) free(wdata);\n\n\t/* This should always be evenly divisble. */\n\tif(((total_size - wsize) % total_entries) == 0)\n\t{\n\t\tglobals.key = ((total_size - wsize) / total_entries);\n\t}\n\telse\n\t{\n\t\tglobals.key = 0;\n\t}\n\n\treturn;\n}\n\n/* Extract embedded file contents from binary file(s) */\nint extract(char *httpd, char *www, char *outdir, char *key)\n{\n\tint n = 0;\n\tFILE *fp = NULL;\n\tsize_t hsize = 0, wsize = 0;\n\tstruct entry_info *info = NULL;\n\tunsigned char *hdata = NULL, *wdata = NULL;\n\tchar *dir_tmp = NULL, *path = NULL;\n\n\t/* Read in the httpd and www files */\n\thdata = (unsigned char *) file_read(httpd, &hsize);\n\twdata = (unsigned char *) file_read(www, &wsize);\n\t\n\tif(hdata != NULL && wdata != NULL && detect_settings(hdata, hsize))\n\t{\n\t\t/* Detect the key */\n\t\tdetect_key(httpd, www);\n\n\t\t/* Create the output directory, if it doesn't already exist */\n\t\tmkdir_p(outdir);\n\n\t\t/* Change directories to the output directory */\n        \tif(chdir(outdir) == -1)\n        \t{\n                \tperror(outdir);\n        \t}\n\t\telse \n\t\t{\n\t\t\t/* Get the next entry until we get a blank entry */\n\t\t\twhile((info = next_entry(hdata, hsize)) != NULL)\n\t\t\t{\n\t\t\t\t/* Make sure the full file path is safe (i.e., it won't overwrite something critical on the host system) */\n\t\t\t\tpath = make_path_safe(info->name);\n\t\t\t\tif(path)\n\t\t\t\t{\n\t\t\t\t\t/* dirname() clobbers the string you pass it, so make a temporary one */\n\t\t\t\t\tdir_tmp = strdup(path);\n\t\t\t\t\tmkdir_p(dirname(dir_tmp));\n\t\t\t\t\tfree(dir_tmp);\n\n\t\t\t\t\t/* Sanity checks on our buffer offsets and sizes */\n\t\t\t\t\tif(info->offset >= 0 && info->size >= 0 && (info->offset + info->size) <= wsize)\n\t\t\t\t\t{\n\t\t\t\t\t\t/* Write the data to disk */\n\t\t\t\t\t\tif(!file_write(path, (wdata + info->offset), info->size))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfprintf(stderr, \"ERROR: Failed to extract file '%s'\\n\", info->name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* Display the file name */\n\t\t\t\t\t\t\tprintf(\"%s\\n\", info->name);\n\t\t\t\t\t\t\tn++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tfprintf(stderr, \"ERROR: Bad file size/offset for %s [ %d %d ]\\n\", info->name, info->size, info->offset);\n\t\t\t\t\t}\n\n\t\t\t\t\tfree(path);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tfprintf(stderr, \"File path '%s' is not safe! Skipping...\\n\", info->name);\n\t\t\t\t}\n\n\t\t\t\tfree(info);\n\t\t\t}\n\t\t}\n\t\t/* we have globals.key populated now, save it to disk for later restore */\n\t\tif(key)\n\t\t{\n\t\t\tfp = fopen(key, \"wb\");\n\t\t\tif(!fp || ferror(fp))\n\t\t\t{\n\t\t\t\tfprintf(stderr, \"\\nERROR opening keyfile, aborting\\n\");\n\t\t\t\tn=-1;\n\t\t\t}\t\t\t\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(fwrite(&globals.key, 1, sizeof(globals.key), fp) != sizeof(globals.key))\n\t\t\t\t{\n\t\t\t\t\tfprintf(stderr, \"\\nERROR writing keyfile, aborting\\n\");\n\t\t\t\t\tn=-1;\t\t\n\t\t\t\t}\n\t\t\t\tfclose(fp);\n\t\t\t}\n\t\t\tfp = NULL;\n\t\t}\n\t}\n\telse\n\t{\n\t\tprintf(\"Failed to parse ELF header!\\n\");\n\t}\n\n\tif(hdata) free(hdata);\n\tif(wdata) free(wdata);\n\treturn n;\n}\n\n/* Restore embedded file contents to binary file(s) */\nint restore(char *httpd, char *www, char *indir, char *key)\n{\n\tint n = 0, total = 0;\n\tFILE *fp = NULL;\n\tsize_t hsize = 0, fsize = 0;\n\tstruct entry_info *info = NULL;\n\tunsigned char *hdata = NULL, *fdata = NULL;\n\tchar origdir[FILENAME_MAX] = { 0 };\n\tchar *path = NULL;\t\n\n\tif(key)\n\t{\n\t\tfp = fopen(key, \"rb\");\n\t\tif(!fp || ferror(fp))\n\t\t{\n\t\t\tfprintf(stderr, \"ERROR opening keyfile %s, aborting\", key);\n\t\t\treturn -1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif(fread(&globals.key, 1, sizeof(globals.key), fp) != sizeof(globals.key))\n\t\t\t{\n\t\t\t\tfclose(fp);\n\t\t\t\tfprintf(stderr, \"ERROR reading keyfile %s, aborting\", key);\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tfclose(fp);\n\t\t}\n\t\tfp = NULL;\n\t}\n\n\t/* Read in the httpd file */\n\thdata = (unsigned char *) file_read(httpd, &hsize);\n\t\n\t/* Get the current working directory */\n\tgetcwd((char *) &origdir, sizeof(origdir));\n\n\t/* Open the www file for writing */\n\tfp = fopen(www, \"wb\");\n\n\tif(hdata != NULL && fp != NULL && detect_settings(hdata, hsize))\n\t{\n\t\t/* Detect the key */\n\t\tdetect_key(httpd, www);\n\n\t\t/* Change directories to the target directory */\n        \tif(chdir(indir) == -1)\n        \t{\n                \tperror(indir);\n        \t}\n\t\telse \n\t\t{\n\t\t\t/* Get the next entry until we get a blank entry */\n\t\t\twhile((info = next_entry(hdata, hsize)) != NULL)\n\t\t\t{\n\t\t\t\t/* Count the number of files we process */\n\t\t\t\tn++;\n\t\t\t\n\t\t\t\t/* Make sure the full file path is safe (i.e., it won't overwrite something critical on the host system) */\n\t\t\t\tpath = make_path_safe(info->name);\n\t\t\t\tif(path)\n\t\t\t\t{\n\t\t\t\t\t/* Display the file name */\n\t\t\t\t\tprintf(\"%s\\n\", info->name);\n\n\t\t\t\t\t/* Read in the file */\n\t\t\t\t\tfdata = (unsigned char *) file_read(path, &fsize);\n\t\t\t\t\n\t\t\t\t\t/* Update the entry size and file offset */\n\t\t\t\t\tif(globals.use_new_format)\n\t\t\t\t\t{\n\t\t\t\t\t\tinfo->new_entry->size = fsize + globals.key;\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tinfo->entry->size = fsize;\n\t\t\t\t\t\tinfo->entry->offset = total;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t/* Byte swap, if necessary */\n\t\t\t\t\thton_entries(info);\n\n\t\t\t\t\t/* Write the new file to the www blob file */\n\t\t\t\t\tif(fdata)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(fwrite(fdata, 1, fsize, fp) != fsize)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfprintf(stderr, \"ERROR: Failed to restore file '%s'\\n\", info->name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* Update the total size written to the www blob */\n\t\t\t\t\t\t\ttotal += fsize;\n\t\t\t\t\t\t}\n\t\n\t\t\t\t\t\tfree(fdata);\n\t\t\t\t\t}\n\t\n\t\t\t\t\tfree(path);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tfprintf(stderr, \"File path '%s' is not safe! Skipping...\\n\", info->name);\n\t\t\t\t}\n\t\t\n\t\t\t\tfree(info);\n\t\t\t}\n\n\t\t\t/* The www blob file always appears to be null byte terminated */\n\t\t\tfwrite(\"\\x00\", 1, 1, fp);\n\n\t\t\t/* Change back to our original directory, so that relative paths for httpd will still work */\n\t\t\tif(chdir((char *) &origdir) != -1)\n\t\t\t{\n\t\t\t\t/* Write the modified httpd binary back to disk */\n\t\t\t\tfile_write(httpd, hdata, hsize);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tperror(origdir);\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tperror(\"restore\");\n\t}\n\t\n\tif(fp) fclose(fp);\n\tif(hdata) free(hdata);\n\treturn n;\n}\n\nvoid usage(char *progname)\n{\n\tfprintf(stderr, \"\\n\");\n\tfprintf(stderr, USAGE, progname, DEFAULT_OUTDIR);\n\tfprintf(stderr, \"\\n\");\n\n\treturn;\n}\n"
  },
  {
    "path": "src/webcomp-tools/webdecomp.h",
    "content": "#ifndef _WEBDECOMP_H_\n#define _WEBDECOMP_H_\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <stdint.h>\n\n#define NONE \t0\n#define EXTRACT 1\n#define RESTORE 2\n\n#define USAGE \"\\\nwebdecomp v.0.5, (c) 2011, Craig Heffner\\n\\\n\\n\\\nExtracts and restores the Web UI pages from and to DD-WRT firmware.\\n\\\n\\n\\\nUsage: %s [OPTIONS]\\n\\\n\\n\\\nRequired Options:\\n\\\n\\n\\\n\\t-b, --httpd=<file>                    Path to the DD-WRT httpd binary (ex: usr/sbin/httpd)\\n\\\n\\t-w, --www=<file>                      Path to the DD-WRT www binary (ex: etc/www)\\n\\\n\\t-k, --key=<file>                      Path to the file to store or retrieve the key\\n\\\n\\t-e, --extract                         Extract Web files to a directory\\n\\\n\\t-r, --restore                         Restore Web files from a directory\\n\\\n\\n\\\nAdditional Options:\\n\\\n\\n\\\n\\t-i, --index=<offset>                  File offset of the websRomPageIndex structure array\\n\\\n\\t-d, --dir=<directory>                 Web files directory [default: %s]\\n\\\n\\t-h, --help                            Show help\\n\\\n\"\n\nvoid usage(char *progname);\nint restore(char *httpd, char *www, char *dir, char *key);\nint extract(char *httpd, char *www, char *outdir, char *key);\nint detect_settings(unsigned char *httpd, size_t httpd_size);\nvoid detect_key(char *httpd, char *www);\n\n#endif\n"
  },
  {
    "path": "src/wrt_vx_imgtool/Makefile",
    "content": "# this makefile is for linux, use cl for Windows and undefine _LINUX\nINCLUDEDIR = .\nCXX := g++\nCFLAGS := -O3 -D_LINUX\n\nall: wrt_vx_imgtool\n\nwrt_vx_imgtool: \n\t$(CXX) $(CFLAGS) wrt54gv5_img.cpp -o $@\n\t\nclean:\n\trm -f *.o\n\trm -f wrt_vx_imgtool\n"
  },
  {
    "path": "src/wrt_vx_imgtool/imghdr.h",
    "content": "/* see README.TXT for license information. You are bound by this license. */\r\n\r\n////////////////////////////////////////////////////////////////\r\n// Linksys VxWorks based firmware image format\r\n// Author: Jeremy Collake (jeremy@bitsum.com)\r\n// WARNING: Work In Progress. Mistakes and guesses are present.\r\n//\r\n// The firmware image header \r\n//\r\n//  Revisions:\r\n//  \r\n//    06/25/06     - Switched to bit size specific data types.\r\n//\t  06/23/06     - Added BOOTROM_BOOTP_DATA_SIZE (at end of BSP).\r\n//    06/22/06     - Identified TrailingFiles descriptors.\r\n//\t\t\t\t\t Added VX_FILE_ID_BOOTROM.BIN (1)\r\n//                   Minor tweaks\r\n//    06/21/06     - Put to use in code, found minor typos.\r\n//                 - Several fixes\r\n//    06/19/06     - Minor tweaks\r\n//    06/18/06     - Quick draft\r\n//        \r\n// Basic format:\r\n//\r\n//    VxLinksysHeader\r\n//      VxFileDescriptor array\r\n//    File1\r\n//    File2\r\n//    File3\r\n//    ....\r\n//    TrailingFile1\r\n//    TrailingFile2\r\n//    TrailingFile3\r\n//    ...\r\n//  \r\n// NOTES:  \r\n//\r\n//  1. Files of pre-defined type ids are included in the firmware images\r\n//  and indicate to the part of the flash they should be written.\r\n//  For example, type 2 is vxworks.bin (the main OS). See \r\n//   VX_FILE_ID_ definitions for a complete list.\r\n//\r\n//  2. Field sizes are for a 32-bit processor. \r\n//  \r\n//  3. Example field values are taken from version 1.00.9_US:\r\n//  wrt54gv5_v6_fw_1.00.9_US_code.bin\r\n//\r\n//  4. Many fields are stored big endian and operated\r\n//  on my endian neutral code.\r\n//\r\n//  5. The file descriptor sizes sum up like so:\r\n//  1120664+183064+29432+28972+31280+33152+31644+30244 = 1488452\r\n//  1488452 + 512 = 1488964\r\n//\r\n//  real file size is 1551880:\r\n//\r\n//  1551880 - 1488964 = 62916\r\n// \r\n//  The last 62916 (in the case of 1.00.9) is the\r\n//  trailing parts/files, as indicated by the\r\n//  TrailingFiles array of file descriptors.\r\n//\r\n// \r\n//\r\n\r\n// todo: add defintions for 64-bit systems\r\n#ifndef DWORD\r\n#define DWORD unsigned long\r\n#define WORD unsigned short\r\n#define BYTE unsigned char\r\n#endif\r\n\r\n\r\n/////////////////////////////////////////////////////////////////\r\n// VxFileDescriptor\r\n//\r\n// file descriptor structure (array at end of VxLinksysHeader)\r\n//  describes a file inside the firmware image\r\n//\r\n// fields are stored big endian, and should be read by\r\n// endian neutral code.\r\n//\r\ntypedef struct _VxFileDescriptor\r\n{ \t\r\n  DWORD nFileId_BigEnd;     // file type (see below)\r\n  DWORD nFileSize_BigEnd;   \r\n} VxFileDescriptor, *pVxFileDescriptor;\r\n\r\n// Note: VX_FILE_ID_BOOTROMBIN can not be combined with any other types\r\n// of flash images. If it exists prior to other types, it will be the\r\n// only area updated, and if it exists subsequent to other types it\r\n// will not be flashed.\r\n#define VX_FILE_ID_BOOTROMBIN 1 \r\n#define VX_FILE_ID_VXWORKSBIN 2\r\n#define VX_FILE_ID_IGWHTMDAT 3\r\n#define VX_FILE_ID_LANGPAK_EN 6\r\n\r\n// the BOOTP storage area holds the\r\n// serial number and boot string.\r\n// It exists at the end of the BSP.\r\n#define BOOTROM_BOOTP_DATA_SIZE 0x400\r\n// hard coded bootrom size.. \r\n// shave off 0x400 bytes for reserved BOOTP area\r\n// at the end of the bootrom.\r\n#define BOOTROM_SIZE 327680-0x400\r\n\r\n/////////////////////////////////////////////////////////////////\r\n// VxLinksysHeader\r\n//\r\n//\r\n#pragma pack(push,1)\r\ntypedef struct _VxLinksysHeader\r\n{\r\n  DWORD nCodePattern;\t\t\t\r\n  BYTE cUnknown_4[4];\r\n  BYTE cYear;       \r\n  BYTE cMonth;      \r\n  BYTE cDay;        \r\n  BYTE nProductVersion_0;   \r\n  BYTE nMinorVersion_0;   \r\n  BYTE cZUnknown_0D;\r\n  BYTE cImageFormatVersion[4];    \r\n  BYTE cZUnknown_12[238];  \r\n  //\r\n  // offset 0x100  -- begining of an secondary header?\r\n  //  \r\n  // After this point, all integers are stored big endian \r\n  // and should be read by endian neutral code \r\n  // (that is, read as big endian). \r\n  //\r\n  BYTE nProductVersion_1;   \r\n  BYTE nMinorVersion_1;     \r\n  WORD nMajorVersion_1;       \r\n  BYTE cZUnknown_104[2];  \r\n  WORD nHeaderSizeBigEnd;// 0x02, 0x00\r\n  DWORD nChecksumBigEnd;   // checksum, big endian (0x611697AE)\r\n  BYTE cZUnknown_10B[2];  \r\n  WORD nUnknown_10D;      // 0x00, 0x02\r\n  // 0x110\r\n  BYTE cZUnknown_110[0x30]; \r\n  BYTE cModelName[0x20];  // 'WRT54G'\r\n  BYTE cVendorName[0x20]; // 'LINKSYS'\r\n  VxFileDescriptor TrailingFiles[8]; // parts of file that follow primary file descriptors\t\t\t\t\t\t\t\t\t \r\n  VxFileDescriptor FileDescriptors[8]; // primary file descriptors, immediately follow header  \r\n} VxLinksysHeader, *pVxLinksysHeader;\r\n#pragma pack(pop)\n"
  },
  {
    "path": "src/wrt_vx_imgtool/stdafx.cpp",
    "content": "// stdafx.cpp : source file that includes just the standard includes\r\n// wrt54gv5_imgbuild.pch will be the pre-compiled header\r\n// stdafx.obj will contain the pre-compiled type information\r\n\r\n#include \"stdafx.h\"\r\n\r\n// TODO: reference any additional headers you need in STDAFX.H\r\n// and not in this file\r\n"
  },
  {
    "path": "src/wrt_vx_imgtool/stdafx.h",
    "content": "// stdafx.h : include file for standard system include files,\r\n// or project specific include files that are used frequently, but\r\n// are changed infrequently\r\n//\r\n\r\n#pragma once\r\n\r\n#ifndef _LINUX\r\n#define WIN32_LEAN_AND_MEAN\t\t// Exclude rarely-used stuff from Windows headers\r\n#endif\r\n#include <stdio.h>\r\n\r\n\r\n\r\n// TODO: reference additional headers your program requires here\n"
  },
  {
    "path": "src/wrt_vx_imgtool/wrt54gv5_img.cpp",
    "content": "/* see README.TXT for license information. You are bound by this license. */\n\n////////////////////////////////////////////////////////////////\n// wrt_vx_imgtool\n// wrt54gv5_imgbuild.cpp \n// Author: Jeremy Collake (jeremy@bitsum.com)\n// Site: http://www.bitsum.com (see Wiki, WRT54Gv5 linux flashing)\n#define VERSION_TEXT \"v0.94 beta\"\n//\n// Extracts, views, and builds WRT54G/GS v5 and WRT54G/GS v6 firmware format.\n//\n// Revisions:\n//\n//\t\t0.94 beta  - fixed bug where -v and -x require -c (oops). Thanks wa6725.\n//      0.92 beta  - added linux g++ compatibility and linux Makefile\n//\t    0.91 beta  - cosmetic tweaks\n//      0.90 beta  - Renamed to wrt_vx_imgtool\n//                   Added support for WRT54GSv5 and unknown models.\n//                   Added -d switch to provide device name.\n//                   Added -m switch to over-ride vendor name.\n//                   Added -c switch to over-ride code pattern.\n//                   Added sanity check for non-32-bit builds.\n//      0.06 alpha - Polished up a bit.\n//      0.05 alpha - Subtracted BOOTP size from BOOTROM image for BOOTP area,\n//                    so it's now padded to 319kb.\n//      0.04 alpha - Added 'trailer' file types and sizes as a result\n//                    identification of these previously unknown members\n//                    of VxLinksysHeader.\n//      0.03 alpha - Added -f (fix checksum of existing firmware)\n//                   Added support for bootrom.bin (1). Auto pads if incorrect size.\n//                   Fixed problem with -v incorrectly calculating checksums on images with last DWORD not NULL.                  \n//      0.02 alpha - Added build capability.\n//\t\t0.01 alpha - Early alpha. No firmware building supoprt yet.\n//\n//\n//\n//\n\n#include <stdio.h>\n#include <time.h>\n#include <string>\n#include <cstring>\n#include <cstdlib>\n#include <climits>\n#include <vector>\n#include \"imghdr.h\"\n\n// for linux you should define this on g++ cmd line\n//#define _LINUX\n\n#ifdef _LINUX\n#define _strcmpi strcasecmp\n#define strcmpi strcasecmp\n// oh come on...no strlwr in ISO standard? here's my own \nchar *strlwr(char *str)\n{\n\tif(!str) return str;\n\tfor(int nI=0;str[nI];nI++)\n\t{\n\t\tstr[nI]=tolower(str[nI]);\n\t}\n\treturn str;\n}\n#endif\n\nusing namespace std;\n\n// parallel arrays giving known devices\n//  and their code patterns, model names, and vendors\nchar *g_pszDeviceNames[]=\n{\n\t\"WRT54Gv5\",\n\t\"WRT54Gv6\",\n\t\"WRT54GSv5\",\n\tNULL\n};\nchar *g_pszModelNames[]=\n{\n\t\"WRT54G\",\n\t\"WRT54G\",\n\t\"WRT54GS\",\n\tNULL\n};\nchar *g_pszVendorNames[]=\n{\n\t\"LINKSYS\",\n\t\"LINKSYS\",\n\t\"LINKSYS\",\n\tNULL\n};\nchar *g_pszCodePatterns[]=\n{\n\t\"WGV5\",\n\t\"WGV5\",\n\t\"WGS5\",\n\tNULL\n};\n\n// always flip, regardless of endianness of machine\nunsigned long flip_endian(unsigned long nValue)\n{\n\t// my crappy endian switch\n\tunsigned long nR;\n\tunsigned long nByte1=(nValue&0xff000000)>>24;\n\tunsigned long nByte2=(nValue&0x00ff0000)>>16;\n\tunsigned long nByte3=(nValue&0x0000ff00)>>8;\n\tunsigned long nByte4=nValue&0x0ff;\n\tnR=nByte4<<24;\n\tnR|=(nByte3<<16);\n\tnR|=(nByte2<<8);\n\tnR|=nByte1;\n\treturn nR;\n}\n\n\nunsigned long big_endian_l(unsigned long nValue)\n{\n#ifdef BIG_ENDIAN\n\treturn nValue;\n#else\n\t// my crappy endian switch\n\tunsigned long nR;\n\tunsigned long nByte1=(nValue&0xff000000)>>24;\n\tunsigned long nByte2=(nValue&0x00ff0000)>>16;\n\tunsigned long nByte3=(nValue&0x0000ff00)>>8;\n\tunsigned long nByte4=nValue&0x0ff;\n\tnR=nByte4<<24;\n\tnR|=(nByte3<<16);\n\tnR|=(nByte2<<8);\n\tnR|=nByte1;\n\treturn nR;\n#endif\n}\n\nunsigned short big_endian_s(unsigned short nValue)\n{\n#ifdef BIG_ENDIAN\n\treturn nValue;\n#else\n\t// my crappy endian switch\n\tunsigned long nR;\n\tunsigned long nByte1=(nValue&0xff00)>>8;\n\tunsigned long nByte2=nValue&0x0ff;\n\tnR=nByte1;\t\n\tnR|=(nByte2<<8);\n\treturn (unsigned short)nR;\n#endif\n}\n/////////////////////////////////////////////////////////////\n// Checksum_Linksys_WRT54Gv5_v6\n//\n// unsigned 32bit checksum of 32bit unsigned integer - endian neutral\n//\nunsigned long\nChecksum_Linksys_WRT54Gv5_v6(unsigned long *pStart, unsigned long *pEnd)\n{\n\tunsigned long nChecksum=0;\n\twhile(pStart<pEnd)\n\t{        \n\t\tnChecksum+=big_endian_l(*pStart++);        \n\t}\n\treturn ~(nChecksum-1); // return two's compliment\n}\n\nbool SanityChecks()\n{\n#ifndef BIG_ENDIAN\n\tif(big_endian_l(0x11223344)==0x11223344)\n\t{\n\t\tprintf(\"\\n ! ERROR: Endianness not set correctly. Define BIG_ENDIAN.\");\n\t\treturn false;\n\t}\n#endif\n\tif(sizeof(VxLinksysHeader)!=0x200)\n\t{\n\t\tprintf(\"\\n ! ERROR: Header definition is incorrect .. %d (%X)\",sizeof(VxLinksysHeader),sizeof(VxLinksysHeader));\n\t\treturn false;\n\t}\t\n\tif(sizeof(DWORD)!=4)\n\t{\n\t\tprintf(\"\\n ! Please update data type defintions in imghdr.h for this system.\");\n\t\treturn false;\n\t}\n\telse\n\t{\n\t\t//printf(\"\\n + Sanity check: Header size is 0x%X\",sizeof(VxLinksysHeader));\n\t}\n\treturn true;\n}\n\n\nint VxFileIdToName(int nId, char *pszFilename, int nMaxLen)\n{\n\t// \n\t// todo: switch to strcpy_n.. see if g++ has 'em \n\t// todo: add other lang packs.. if anyone cares\n\t//\n\tswitch(nId)\n\t{\n\tcase VX_FILE_ID_BOOTROMBIN:\n\t\tstrcpy(pszFilename,\"bootrom.bin\");\n\t\treturn 1;\n\tcase VX_FILE_ID_VXWORKSBIN:\n\t\tstrcpy(pszFilename,\"vxworks.bin\");\n\t\treturn 1;\n\tcase VX_FILE_ID_IGWHTMDAT:\n\t\tstrcpy(pszFilename,\"igwhtm.dat\");\n\t\treturn 1;\n\tcase VX_FILE_ID_LANGPAK_EN:\n\t\tstrcpy(pszFilename,\"langpak_en.dat\");\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\nint VxFileNameToId(const char *pszFilename)\n{\n\tif(!pszFilename || !strlen(pszFilename)) return -1;\n\tchar *pszFile=new char[strlen(pszFilename)+1];\n\tstrcpy(pszFile,pszFilename);\n\tstrlwr(pszFile);\n\tint nR=0;\n\n\tif(strstr(pszFile,\"bootrom.bin\"))\n\t{\n\t\tnR=VX_FILE_ID_BOOTROMBIN;\n\t}\n\telse if(strstr(pszFile,\"vxworks.bin\"))\n\t{\n\t\tnR=VX_FILE_ID_VXWORKSBIN;\n\t}\n\telse if(strstr(pszFile,\"igwhtm.dat\"))\n\t{\n\t\tnR=VX_FILE_ID_IGWHTMDAT;\n\t}\n\telse if(strstr(pszFile,\"langpak_en.dat\"))\n\t{\n\t\tnR=VX_FILE_ID_LANGPAK_EN;\n\t}\n\tdelete pszFile;\n\treturn nR;\n}\n\nlong EmitFile(unsigned char *pFirmwareImage, unsigned long nOffset, unsigned long nSize, const char *pszFilename)\n{\n\tprintf(\"\\n   Writing file %s\", pszFilename);\n\tFILE *fOut=fopen(pszFilename,\"wb\");\n\tif(!fOut)\n\t{\n\t\tprintf(\"\\n ! ERROR: Opening %s\", pszFilename);\n\t\treturn -1;\n\t}\t\n\tunsigned char *p1=pFirmwareImage+nOffset;\n\tif(fwrite(p1,1,nSize,fOut)!=nSize)\n\t{\n\t\tprintf(\"\\n ! ERROR: Writing %s\", pszFilename);\n\t\tfclose(fOut);\n\t\treturn -1;\n\t}\n\n\tfclose(fOut);\n\treturn nSize;\n}\n\nvoid store_bigendian_l(unsigned long *pDest, unsigned long nValue)\n{\n\t*pDest=big_endian_l(nValue);\n}\nvoid store_bigendian_s(unsigned short *pDest, unsigned short nValue)\n{\n\t*pDest=big_endian_s(nValue);\n}\n\n///////////////////////////////////////////\n// BuildImage\n//\n// return: number of files extracted, or <= 0 for error.\n//\nint BuildImage(vector<string> &vInputFiles, const char *pszOutFile, char *pszCodePattern, char *pszModelName, char *pszVendorName)\n{\n\tprintf(\"\\n\\n Building firmware image %s\", pszOutFile);\n\n\tFILE *fOut=fopen(pszOutFile,\"wb\");\n\tif(!fOut)\n\t{\n\t\tprintf(\"\\n ! ERROR: Opening %s for writing\", pszOutFile);\n\t\treturn -1;\n\t}\n\n\t// first, calculate total size\n\tunsigned long nFirmwareSize=sizeof(VxLinksysHeader);\n\tfor(unsigned int nI=0;nI<vInputFiles.size();nI++)\n\t{\n\t\tFILE *fTest=fopen(vInputFiles[nI].c_str(),\"rb\");\n\t\tif(!fTest)\n\t\t{\n\t\t\tprintf(\"\\n ! ERROR: Opening %s\", vInputFiles[nI].c_str());\n\t\t\tfclose(fOut);\n\t\t\treturn -1;\n\t\t}\n\t\tfseek(fTest,0,SEEK_END);\n\t\tunsigned long nSize=\n\t\t\tftell(fTest);\n\t\tprintf(\"\\n + Size of %s is %d bytes.\", vInputFiles[nI].c_str(), nSize);\n\n\t\t//todo: warn if size >\n\t\tif(VxFileNameToId(vInputFiles[nI].c_str())==VX_FILE_ID_BOOTROMBIN && nSize<BOOTROM_SIZE)\n\t\t{\n\t\t\tunsigned long nDifference=BOOTROM_SIZE-nSize;\n\t\t\tprintf(\"\\n ! WARNING: BOOTROM.BIN must be %d bytes. Padding end to make correct size.\", BOOTROM_SIZE);\n\t\t\tprintf(\"\\n   Padding will be %d bytes in length.\", nDifference);\n\t\t\tnSize=BOOTROM_SIZE;\n\t\t}\n\t\tnFirmwareSize+=nSize;\n\t\tfclose(fTest);\n\t}\n\n\t// align to 32-bit boundary\n\tnFirmwareSize+=3;\n\tnFirmwareSize/=4;\n\tnFirmwareSize*=4;\n\n\t// allocate buffer\n\tunsigned char *buffer=new unsigned char[nFirmwareSize];\n\tmemset(buffer,0,nFirmwareSize);\n\tpVxLinksysHeader pHeader=(pVxLinksysHeader)buffer;\n\n\tprintf(\"\\n + Building header\");\n\t// fill header\ttodo: don't use strcpy on longs..\n\t// reverse code pattern\n\tDWORD *lRevCodePattern=(DWORD *)pszCodePattern; \n\tDWORD lNewCodePattern=flip_endian(*lRevCodePattern);\n\tmemcpy(&pHeader->nCodePattern,&lNewCodePattern,sizeof(DWORD));\t\n\tstrcpy((char *)&pHeader->cImageFormatVersion,\"U2ND\"); \t\t\n\tstrcpy((char *)&pHeader->cVendorName[0],pszVendorName); //\"LINKSYS\");\n\tstrcpy((char *)&pHeader->cModelName[0],pszModelName); //\"WRT54G\");\n\n\t// store local time\t\n\ttime_t t;\n\tstruct tm *pTime;\n\ttime(&t);\t\n\tpTime = localtime(&t);\t\n\tpHeader->cDay=pTime->tm_mday;\n\tpHeader->cMonth=pTime->tm_mon+1;\n\tpHeader->cYear=pTime->tm_year-100;\n\n\t//todo: versions not defined right yet\n\tpHeader->nProductVersion_0=0x05;  \n\tpHeader->nMinorVersion_0=0x90;   // x.00.9 is 0x90 here.. x.00.6 is 0x60\t\n\tpHeader->nProductVersion_1=0x05;\n\tpHeader->nMajorVersion_1=0x01;\t\n\tpHeader->nMajorVersion_1=0x90;\t\n\n\tstore_bigendian_s(&pHeader->nHeaderSizeBigEnd,0x200);\n\tstore_bigendian_s(&pHeader->nUnknown_10D,2);\n\n\t// todo: skip these for now since they seem to have no effect\n\tprintf(\"\\n + Setting trailer file sizes to 0.. (todo: add support?)\");\n\t// of course, they're already 0.. just saying that to remmeber about them\n\n\t// now store file descriptors and read files\n\tunsigned long nCurrentPos=sizeof(VxLinksysHeader);\n\tfor(unsigned int nI=0;nI<vInputFiles.size();nI++)\n\t{\n\t\tprintf(\"\\n + Storing %s\", vInputFiles[nI].c_str());\n\t\tFILE *fTest=fopen(vInputFiles[nI].c_str(),\"rb\");\n\t\tif(!fTest)\n\t\t{\n\t\t\tprintf(\"\\n ! ERROR: Opening %s\", vInputFiles[nI].c_str());\n\t\t\tdelete buffer;\n\t\t\tfclose(fOut);\n\t\t\treturn -1;\n\t\t}\n\t\tfseek(fTest,0,SEEK_END);\n\t\tunsigned long nSize=\n\t\t\tftell(fTest);\t\t\n\t\tfseek(fTest,0,SEEK_SET);\n\t\tunsigned char *tmp=new unsigned char[nSize];\n\t\tif(fread(tmp,1,nSize,fTest)!=nSize)\n\t\t{\n\t\t\tprintf(\"\\n ! ERROR: Reading %s\", vInputFiles[nI].c_str());\n\t\t\tdelete buffer;\n\t\t\tdelete tmp;\n\t\t\tfclose(fOut);\n\t\t\treturn -1;\n\t\t}\n\t\tmemcpy(buffer+nCurrentPos,tmp,nSize);\n\t\tdelete tmp;\n\t\tnCurrentPos+=nSize;\n\n\t\t// now store the descriptor\n\t\tpVxFileDescriptor pFileDescriptor=&pHeader->FileDescriptors[nI];\n\t\tstore_bigendian_l(&pFileDescriptor->nFileId_BigEnd,VxFileNameToId(vInputFiles[nI].c_str()));\n\t\tif(!pFileDescriptor->nFileId_BigEnd)\n\t\t{\n\t\t\tprintf(\"\\n ! WARNING: Unrecognized file id! Remember to name your OS ELF vxworks.bin (even if its vmlinux).\");\n\t\t}\n\t\telse if(big_endian_l(pFileDescriptor->nFileId_BigEnd)==VX_FILE_ID_BOOTROMBIN)\n\t\t{\n\t\t\tif(nSize<BOOTROM_SIZE)\n\t\t\t{\t\t\t\t\n\t\t\t\tunsigned long nDifference=BOOTROM_SIZE-nSize;\n\t\t\t\tunsigned char *pPad=new unsigned char[nDifference];\n\t\t\t\tprintf(\"\\n + Padding bootrom.bin with %d bytes\", nDifference);\n\t\t\t\tmemset(pPad,0,nDifference);\n\t\t\t\tmemcpy(buffer+nCurrentPos,pPad,nDifference);\n\t\t\t\tnSize=BOOTROM_SIZE;\n\t\t\t\tnCurrentPos+=nDifference;\n\t\t\t\tdelete pPad;\n\t\t\t}\n\t\t}\n\n\t\tfclose(fTest);\n\n\t\tchar szName[256];\n\t\tVxFileIdToName(big_endian_l(pFileDescriptor->nFileId_BigEnd),szName,sizeof(szName));\n\t\tprintf(\"\\n + Stored with file type %d (%s)\", big_endian_l(pFileDescriptor->nFileId_BigEnd),szName);\n\t\tstore_bigendian_l(&pFileDescriptor->nFileSize_BigEnd,nSize);\t\t\n\t}\n\n\tif(nCurrentPos>nFirmwareSize)\n\t{\n\t\tprintf(\"\\n ERROR: Sanity check fails. current pos > firmware size\");\n\t\tdelete buffer;\n\t\tfclose(fOut);\n\t\treturn -1;\n\t}\n\n\tunsigned char *pEnd=buffer+nFirmwareSize;\n\tstore_bigendian_l(&pHeader->nChecksumBigEnd,Checksum_Linksys_WRT54Gv5_v6((unsigned long *)buffer,(unsigned long *)pEnd));\n\tprintf(\"\\n + Checksum is %08X\", big_endian_l(pHeader->nChecksumBigEnd));\n\n\tif(fwrite(buffer,1,nFirmwareSize,fOut)!=nFirmwareSize)\n\t{\n\t\tprintf(\"\\n ERROR: Writing firmware image to disk.\");\n\t\tdelete buffer;\n\t\tfclose(fOut);\t\t\n\t\treturn -1;\n\t}\n\tprintf(\"\\n Firmware size is %d bytes.\", nFirmwareSize);\n\tdelete buffer;\n\tfclose(fOut);\n\treturn nFirmwareSize;\n}\n\n\n///////////////////////////////////////////\n// ExtractImage\n//\n// return: number of files extracted, or <= 0 for error.\n//\nint ExtractImage(const char *pszInput, const char *pszOutFolder, bool bViewOnly)\n{\n\tprintf(\"\\n\\n Extracting firmware %s\", pszInput);\n\t// make a local copy of the output folder for safe modification\n\tchar szOutputFolder[4096];\n\tif(pszOutFolder && strlen(pszOutFolder))\n\t{\n\t\tstrcpy(szOutputFolder,pszOutFolder);\n\t\tif(szOutputFolder[strlen(pszOutFolder)-1]!='\\\\'\n\t\t\t&&\n\t\t\tszOutputFolder[strlen(pszOutFolder)-1]!='/')\n\t\t{\n\t\t\t//\n\t\t\t// I've never coded for *nix before, do file i/o\n\t\t\t// functions handle backslashes in pathnames like a forward\n\t\t\t// slash? Here's a BAD check in case since we\n\t\t\t// night not be using MSC under Windows...\n\t\t\t//\n#ifdef _MSC_VER \n\t\t\tstrcat(szOutputFolder,\"\\\\\");\n#else\n\t\t\tstrcat(szOutputFolder,\"/\");\n#endif\n\t\t}\t\t\n\t}\n\telse\n\t{\n\t\tszOutputFolder[0]=0;\n\t}\n\n\tFILE *fIn=fopen(pszInput,\"rb\");\n\tif(!fIn)\n\t{\n\t\tprintf(\"\\n ERROR: Opening file %s\", pszInput);\n\t\treturn -1;\n\t}\n\tfseek(fIn,0,SEEK_END);\n\tlong nFilesize=ftell(fIn);\n\tfseek(fIn,0,SEEK_SET);\n\tif(nFilesize<sizeof(VxLinksysHeader))\n\t{\n\t\tprintf(\"\\n ERROR: File too small: %s\", pszInput);\n\t\treturn -1;\n\t}\n\tprintf(\"\\n Firmare file size is %d bytes\", nFilesize);\n\n\tunsigned char *buffer=new unsigned char[nFilesize];\n\tfread((void *)&buffer[0],1,nFilesize,fIn);\t\n\tpVxLinksysHeader pHeader=(pVxLinksysHeader)buffer;\n\n\tunsigned long nChecksum=big_endian_l(pHeader->nChecksumBigEnd);\n\tpHeader->nChecksumBigEnd=0;\n\tunsigned char *pEnd=buffer+nFilesize;\n\tunsigned long nCalculatedChecksum=Checksum_Linksys_WRT54Gv5_v6(\n\t\t(unsigned long *)buffer,\n\t\t(unsigned long *)pEnd);\n\n\tunsigned int cMonth=pHeader->cMonth;\n\tunsigned int cDay=pHeader->cDay;\n\tunsigned short cYear=pHeader->cYear;\n\t/*\n\tunsigned short nMajorVer0=pHeader->nProductVersion_0;\n\tunsigned short nMinorVer0=pHeader->nMinorVersion_0;\n\tunsigned short nProductVer1=big_endian_s(pHeader->nProductVersion_1);\n\tunsigned short nMajorVer1=pHeader->nProductVersion_1;\n\tunsigned short nMinorVer1=pHeader->nMinorVersion_1;\n\t*/\n\n\tprintf(\"\\n\"\n\t\t\"\\n Code pattern: %s\"\t\t\n\t\t//\"\\n Version: %d.%d [%d.%d.%x]\"\n\t\t\"\\n Build date: %02d-%02d-%02d\"\t    \t\t\n\t\t\"\\n Vendor name: %s\"\n\t\t\"\\n Device name: %s\"\t\t\n\t\t\"\\n Checksum: 0x%08X (given)\"\n\t\t\"\\n Checksum: 0x%08X (calculated)\"\n\t\t\"\\n Checksum %s\", \t\t\n\t\t(char *)&pHeader->nCodePattern,\n\t\t//nMajorVer0,\n\t\t//nMinorVer0,\n\t\t//nProductVer1,\n\t\t//nMajorVer1,\n\t\t//nMinorVer1,\n\t\tcMonth,\n\t\tcDay,\n\t\tcYear,\n\t\t(char *)&pHeader->cVendorName,\n\t\tpHeader->cModelName,\n\t\tnChecksum,\n\t\tnCalculatedChecksum,\n\t\tnChecksum==nCalculatedChecksum?\"CORRECT\":\"INCORRECT\");\n\n\tprintf(\"\\n\\n + Trailing files:\");\n\tint nFileCount=0;\n\tunsigned long nFilesizeSum=sizeof(VxLinksysHeader);\n\tfor(int nI=0;nI<8;nI++)\n\t{\t\t\n\t\tpVxFileDescriptor pFileDescriptor=&pHeader->TrailingFiles[nI];\n\t\tunsigned long nIntFilesize=big_endian_l(pFileDescriptor->nFileSize_BigEnd);\n\t\tif(nIntFilesize)\n\t\t{\n\t\t\tprintf(\n\t\t\t\t\"\\n   -\"\n\t\t\t\t\"\\n   File descriptor %d\"\n\t\t\t\t\"\\n   Type Id: %d\"\n\t\t\t\t\"\\n   Name: unknown\"\t\t\t\n\t\t\t\t\"\\n   Size: %d\",\t\t\t\n\t\t\t\tnI,\t\t\t\n\t\t\t\tbig_endian_l(pFileDescriptor->nFileId_BigEnd),\t\t\t\n\t\t\t\tnIntFilesize);\t\t\n\n\t\t\tif(!bViewOnly && nIntFilesize)\n\t\t\t{\n\t\t\t\tchar szIntFilename[256];\n\t\t\t\tsprintf(szIntFilename,\"trailing_file_%d\",nI);\n\t\t\t\tstring sFullpath=szOutputFolder;\n\t\t\t\tsFullpath+=szIntFilename;\n\t\t\t\tif(!EmitFile(buffer,nFilesizeSum,big_endian_l(pFileDescriptor->nFileSize_BigEnd),sFullpath.c_str()))\n\t\t\t\t{\n\t\t\t\t\tnFileCount=-1;\n\t\t\t\t\tprintf(\"\\n ERROR: Extracting file from firmware (disk/filesystem problem).\");\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnFilesizeSum+=nIntFilesize;\n\t\t\tif(nFileCount!=-1) nFileCount++;\t\n\t\t}\n\t}\n\n\tprintf(\"\\n\\n + Primary files:\");\t\t\n\tfor(int nI=0;nI<8;nI++)\n\t{\t\t\n\t\tpVxFileDescriptor pFileDescriptor=&pHeader->FileDescriptors[nI];\n\t\tchar szIntFilename[256]={0};\n\t\tVxFileIdToName(big_endian_l(pFileDescriptor->nFileId_BigEnd),szIntFilename,sizeof(szIntFilename));\n\t\tunsigned long nIntFilesize=big_endian_l(pFileDescriptor->nFileSize_BigEnd);\n\t\tprintf(\n\t\t\t\"\\n   -\"\n\t\t\t\"\\n   File descriptor %d\"\n\t\t\t\"\\n   Type Id: %d\"\n\t\t\t\"\\n   Name: %s\"\t\t\t\n\t\t\t\"\\n   Size: %d\",\t\t\t\n\t\t\tnI,\t\t\t\n\t\t\tbig_endian_l(pFileDescriptor->nFileId_BigEnd),\n\t\t\tszIntFilename,\n\t\t\tnIntFilesize);\t\t\n\n\t\tif(!bViewOnly && nIntFilesize)\n\t\t{\n\t\t\tif(!szIntFilename[0])\n\t\t\t{\n\t\t\t\tsprintf(szIntFilename,\"__unused_file_%d\",nI);\n\t\t\t}\n\t\t\tstring sFullpath=szOutputFolder;\n\t\t\tsFullpath+=szIntFilename;\n\t\t\tif(!EmitFile(buffer,nFilesizeSum,big_endian_l(pFileDescriptor->nFileSize_BigEnd),sFullpath.c_str()))\n\t\t\t{\n\t\t\t\tnFileCount=-1;\n\t\t\t\tprintf(\"\\n ERROR: Extracting file from firmware (disk/filesystem problem).\");\t\t\t\t\n\t\t\t}\n\t\t}\n\n\t\tnFilesizeSum+=nIntFilesize;\n\t\tif(nFileCount!=-1) nFileCount++;\t\t\n\t}\n\n\t//todo: figure out why 4 off when trailing files presnt\n\t/*\n\tif(nFilesizeSum!=nFilesize)\n\t{\n\tprintf(\"\\n ! WARNING: Firmware file size does not add up! It is %d and supposed to be %d.\",nFilesize,nFilesizeSum);\n\t}\n\t*/\n\n\tdelete buffer;\n\tfclose(fIn);\t\t\n\treturn nFileCount;\t\n}\n\nint FixImage(const char *pszImage)\n{\n\tprintf(\"\\n\\n Fixing checksum on %s\", pszImage);\n\tFILE *fIn=fopen(pszImage,\"r+b\");\n\tif(!fIn)\n\t{\n\t\tprintf(\"\\n ! ERROR: Opening image.\");\n\t\treturn -1;\n\t}\n\tfseek(fIn,0,SEEK_END);\n\tunsigned long nFilesize=ftell(fIn);\n\tfseek(fIn,0,SEEK_SET);\n\tunsigned char *buffer=new unsigned char[nFilesize];\n\tif(fread(buffer,1,nFilesize,fIn)!=nFilesize)\n\t{\n\t\tprintf(\"\\n ! ERROR: Reading image.\");\n\t\tdelete buffer;\n\t\tfclose(fIn);\n\t\treturn -1;\n\t}\t\t\n\n\tpVxLinksysHeader pHeader=(pVxLinksysHeader)buffer;\n\tprintf(\"\\n Original checksum was 0x%08X\", big_endian_l(pHeader->nChecksumBigEnd));\n\tpHeader->nChecksumBigEnd=0;\n\tunsigned char *pEnd=buffer+nFilesize;\n\tunsigned long nChecksum=Checksum_Linksys_WRT54Gv5_v6((unsigned long *)buffer, (unsigned long *)pEnd);\n\tstore_bigendian_l(&pHeader->nChecksumBigEnd,nChecksum);\n\tprintf(\"\\n New checksum is       0x%08X\", big_endian_l(pHeader->nChecksumBigEnd));\n\n\tfseek(fIn,0,SEEK_SET);\n\tif(fwrite(buffer,1,nFilesize,fIn)!=nFilesize)\n\t{\n\t\tprintf(\"\\n ! ERROR: Writing image.\");\n\t\tdelete buffer;\n\t\tfclose(fIn);\n\t\treturn -1;\t\n\t}\n\tfclose(fIn);\n\treturn 1;\n}\n\nint main(int argc, char* argv[])\n{\n\tprintf(\"\\n WRT54G/GS v5-v6 firmware image builder, extractor, fixer, and viewer\");\n\tprintf(\"\\n \"VERSION_TEXT \" - \" __DATE__ \" by Jeremy Collake (jeremy@bitsum.com)\");\t\t\n\t//printf(\"\\n For info see: http://www.bitsum.com/openwiking/owbase/ow.asp?WRT54G5%5FCFE\");\t\n\tprintf(\"\\n ------------------------------------------------------------------------------\");\n\n\tif(argc<2)\n\t{\nshowhelp:\n\t\tprintf(\"\\n\\n Usage:\"\n\t\t\t\"\\n\"\n\t\t\t\"\\n wrt_vx_imgtool\"\n\t\t\t\"\\n  [-x|v|f|b] [-d device] [-c abc] [-m abc] -o outfile infile1 infile2 ...\"\n\t\t\t\"\\n\"\t\t\t   \t\t\t   \n\t\t\t\"\\n Operations:\"\n\t\t\t\"\\n\"\n\t\t\t\"\\n [-b] Build the firmware (default)\"\n\t\t\t\"\\n [-x] Extract the firmware\"\n\t\t\t\"\\n       The image filename should be provided as the first, and only, 'infile'\"\n\t\t\t\"\\n       parameter. The -o switch can specify an output directory, if the CWD\"\n\t\t\t\"\\n       isn't desired. All files, primary and trailing, are extacted to \"\n\t\t\t\"\\n       the output folder, named in accordance with their type.\"\n\t\t\t\"\\n [-v] Dump/analyze the firmware\"\n\t\t\t\"\\n       Similar to extraction, but no files are writen to disk\"\n\t\t\t\"\\n [-f] Just fix the checksum of given input firmware\"\n\t\t\t\"\\n\"\n\t\t\t\"\\n Options:\"\n\t\t\t\"\\n\"\n\t\t\t\"\\n [-d] Set target device. Causes the code pattern and vendor name to be set to\"\n\t\t\t\"\\n      proper values. By default the device is the WRT54G. Valid devices:\"\n\t\t\t\"\\n       WRT54Gv5\"\n\t\t\t\"\\n       WRT54Gv6\"\n\t\t\t\"\\n       WRT54GSv5\"\t\t\t   \n\t\t\t\"\\n [-c] Over-rides the code pattern. Not recommended.\"\n\t\t\t\"\\n [-m] Over-rides the vendor name. Not recommended.\"\n\t\t\t\"\\n\"\n\t\t\t\"\\n Notes:\"\n\t\t\t\"\\n\"\n\t\t\t\"\\n The deafult action is to build a new firmware, saved in outfile,\"\n\t\t\t\"\\n and containing files supplied as input. The files should be named\"\n\t\t\t\"\\n in accordance with their file type/flash area.\"\n\t\t\t\"\\n\"\n\t\t\t\"\\n The following files are normally included in the firmware images:\"\n\t\t\t\"\\n   vxWorks.bin\"\n\t\t\t\"\\n   igwhtm.dat\"\n\t\t\t\"\\n   langpak_en\"\n\t\t\t\"\\n   __trailing__file_1\"\n\t\t\t\"\\n   __trailing__file_2\"\n\t\t\t\"\\n   ...\"\n\t\t\t\"\\n\"\t\t\t   \n\t\t\t\"\\n These files will be created if extraction is chosen, or should be\"\t\t\t   \n\t\t\t\"\\n supplied when building a firmware image.\"\t\t\t   \n\t\t\t\"\\n\\n\");\t\t\t   \t\t\n\n\t\treturn 1;\n\t}\n\n\tbool bExtract=false;\n\tbool bView=false;\n\tbool bFix=false;\n\tbool bPause=false;\n\tchar *pszDeviceName=g_pszDeviceNames[0];\n\tchar *pszVendorName=g_pszVendorNames[0];\n\tchar *pszModelName=g_pszModelNames[0];\n\tchar *pszCodePattern=NULL;\n\n\tstring sOutParam;\n\tvector<string> vInFiles;\n\n\tfor(int nI=1;nI<argc;nI++)\n\t{\t\t\n\t\tif(argv[nI][0]=='-')\n\t\t{\n\t\t\tswitch(argv[nI][1])\n\t\t\t{\n\t\t\tcase '?':\n\t\t\tcase 'h':\n\t\t\tcase 'H':\n\t\t\t\tgoto showhelp;\n\t\t\tcase 'o':\n\t\t\tcase 'O':\n\t\t\t\tif(nI+1>=argc)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"\\n ERROR: Missing parameter second half.\");\n\t\t\t\t\tprintf(\"\\n\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tprintf(\"\\n + Found parameter, outfile %s\", argv[++nI]);\n\t\t\t\tsOutParam=argv[nI];\n\t\t\t\tbreak;\n\t\t\tcase 'X':\n\t\t\tcase 'x':\n\t\t\t\tif(bView) printf(\"\\n WARNING: Conflicts with -v\");\n\t\t\t\tprintf(\"\\n + Found parameter, extract firmware\");\t\t\t\t\n\t\t\t\tbExtract=true;\n\t\t\t\tbreak;\n\t\t\tcase 'V':\n\t\t\tcase 'v':\n\t\t\t\tif(bExtract) printf(\"\\n WARNING: Conflicts with -x\");\n\t\t\t\tprintf(\"\\n + Found parameter, view firmware\");\t\t\t\t\t\t\t\t\n\t\t\t\tbView=true;\n\t\t\t\tbreak;\t\n\t\t\tcase 'F':\n\t\t\tcase 'f':\n\t\t\t\tif(bExtract) printf(\"\\n WARNING: Conflicts with -x\");\n\t\t\t\tprintf(\"\\n + Found parameter, fixing firmware\");\n\t\t\t\tbFix=true;\n\t\t\t\tbreak;\n\t\t\tcase 'B':\n\t\t\tcase 'b':\t\t\t\t\n\t\t\t\t// default option\n\t\t\t\tbreak;\n\t\t\tcase 'p':\n\t\t\tcase 'P':\n\t\t\t\tbPause=true;\n\t\t\t\tbreak;\n\t\t\tcase 'C':\n\t\t\tcase 'c':\n\t\t\t\tif(nI+1>=argc)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"\\n ERROR: Missing parameter second half.\");\n\t\t\t\t\tprintf(\"\\n\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tpszCodePattern=argv[++nI];\n\t\t\t\tprintf(\"\\n + Found parameter, code pattern: %s\", pszCodePattern);\n\t\t\t\tbreak;\n\t\t\tcase 'D':\n\t\t\tcase 'd':\n\t\t\t\tif(nI+1>=argc)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"\\n ERROR: Missing parameter second half.\");\n\t\t\t\t\tprintf(\"\\n\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tpszDeviceName=argv[++nI];\n\t\t\t\tprintf(\"\\n + Found parameter, device name: %s\", pszDeviceName);\n\t\t\t\tbreak;\t\t\n\t\t\tcase 'M':\n\t\t\tcase 'm':\n\t\t\t\tif(nI+1>=argc)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"\\n ERROR: Missing parameter second half.\");\n\t\t\t\t\tprintf(\"\\n\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tpszVendorName=argv[++nI];\n\t\t\t\tprintf(\"\\n + Found parameter, vendor name: %s\", pszVendorName);\n\t\t\t\tbreak;\t\n\t\t\tdefault:\n\t\t\t\tif(argv[nI][2]==0)\n\t\t\t\t{\n\t\t\t\t\tprintf(\"\\n ! WARNING: Invalid parameter %s\", argv[nI]);\t\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\t\n\t\telse \n\t\t{\n\t\t\tprintf(\"\\n + Infile parameter %s\", argv[nI]);\n\t\t\tvInFiles.push_back(argv[nI]);\n\t\t}\n\t}\n\n\t// make sure nothing is screwy\n\tif(!SanityChecks())\n\t{\n\t\treturn 2;\n\t}\t\t\n\n\tif(!bExtract && !bView)\n\t{\n\t\tprintf(\"\\n + Building firmware image\");\n\t}\n\n\tif(!bExtract && !bView && !bFix && (!vInFiles.size() || !sOutParam.length()))\n\t{\n\t\tprintf(\"\\n ! ERROR: Missing input or output file parameter(s). Aborting.\");\n\t\treturn 1;\n\t}\n\n\tif(!vInFiles.size())\n\t{\n\t\tprintf(\"\\n ! ERROR: Missing input or output file parameter(s). Aborting.\");\n\t\treturn 1;\n\t}\n\n\t// determine code pattern and vendor name\n\t// if code pattern is already supplied, then over-ride if\n\t// matched, else if no match pszCodePattern will already\n\t// be set and accepted below.\n\tif(!bExtract && !bView)\n\t{\n\t\tfor(int nC=0;g_pszDeviceNames[nC];nC++)\n\t\t{\t\t\t\n\t\t\tif(_strcmpi(g_pszDeviceNames[nC],pszDeviceName)==0)\n\t\t\t{\n\t\t\t\tpszCodePattern=g_pszCodePatterns[nC];\n\t\t\t\tpszVendorName=g_pszVendorNames[nC];\n\t\t\t\tpszModelName=g_pszModelNames[nC];\n\t\t\t\tprintf(\n\t\t\t\t\t\"\\n + Found device match.\"\n\t\t\t\t\t\"\\n   Code pattern is %s.\"\n\t\t\t\t\t\"\\n   Vendor name is %s.\"\n\t\t\t\t\t\"\\n   Model name is %s\"\n\t\t\t\t\t, pszCodePattern,pszVendorName,pszModelName);\t\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(!pszCodePattern)\n\t\t{\n\t\t\tprintf(\"\\n ! Could not find a code pattern for specified device, %s.\\n\", pszDeviceName);\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\tif(bFix)\n\t{\t\t\n\t\tFixImage(vInFiles[0].c_str());\n\t}\n\telse if(bExtract || bView)\n\t{\n\t\tif(!vInFiles.size())\n\t\t{\n\t\t\tprintf(\"\\n ! ERROR: Missing input or output file parameter(s). Aborting.\");\n\t\t\treturn 1;\n\t\t}\n\t\tif(ExtractImage(vInFiles[0].c_str(),sOutParam.c_str(),bView)<=0)\n\t\t{\n\t\t\tprintf(\"\\n\\n Failed in view or extract\\n\");\n\t\t\treturn 1;\n\t\t}\n\t}\n\telse\n\t{\n\t\tBuildImage(vInFiles,sOutParam.c_str(),pszCodePattern,pszModelName,pszVendorName);\n\t}\n\n\tprintf(\"\\n\\n Done!\\n\");\n\n\tif(bPause) getchar();\n\n\treturn 0;\n}\n"
  },
  {
    "path": "trunk/NOTE_no_need_to_sync_ver_file.txt",
    "content": "No need to keep this ver txt file in sync - old users will be notified of AN upgrade and then get the updated check_for_upgrade.sh from that point forward\n"
  },
  {
    "path": "trunk/README",
    "content": "FMK's repository has been cleaned up.\n\nIf you checked out /trunk/trunk, then please do a new fresh checkout\nof http://firmware-mod-kit.googlecode.com/svn/trunk\n\nOtherwise if you checked out /trunk, then just go there.\n\nSorry for the inconvenience\nThe Firmware-Mod-Kit Team\n"
  },
  {
    "path": "trunk/firmware_mod_kit_version.txt",
    "content": "0.78 beta\n"
  },
  {
    "path": "uncpio.sh",
    "content": "#!/bin/bash\n\nFSIMG=\"$1\"\nROOTFS=\"$2\"\nROOTFS_CREATED=0\n\nif [ \"$FSIMG\" == \"\" ] || [ \"$FSIMG\" == \"-h\" ]\nthen\n\techo \"Usage: $(basename $0) <cpio archive> [output directory]\\n\"\n\texit 1\nfi\n\nif [ \"$ROOTFS\" == \"\" ]\nthen\n\tROOTFS=\"./cpio-root\"\nfi\n\nFSIMG=$(readlink -f $FSIMG)\nROOTFS=$(readlink -f $ROOTFS)\n\nif [ ! -e $ROOTFS ]\nthen\n\tmkdir -p $ROOTFS\n\tROOTFS_CREATED=1\nfi\n\ncd $ROOTFS && cpio -i --no-absolute-filenames < $FSIMG\n\nif [ \"$(ls $ROOTFS)\" == \"\" ] && [ \"$ROOTFS_CREATED\" == \"1\" ]\nthen\n\trm -rf $ROOTFS\nfi\n"
  },
  {
    "path": "uncramfs_all.sh",
    "content": "#!/bin/bash\n\nFSIMG=\"$1\"\nROOTFS=\"$2\"\nENDIANESS=\"$3\"\nMKFS=\"\"\n\nfunction finish\n{\n\trm -f \"$FSIMG.le\"\n\techo \"MKFS=\\\"$MKFS\\\"\"\n}\n\nif [ \"$FSIMG\" == \"\" ] || [ \"$FSIMG\" == \"-h\" ]\nthen\n\techo \"Usage: $(basename $0) <cramfs image> [output directory] [-be | -le]\\n\"\n\texit 1\nfi\n\nif [ $UID -ne 0 ]\nthen\n\tSUDO=\"sudo\"\nfi\n\nif [ \"$ENDIANESS\" == \"\" ]\nthen\n\tif [ \"$(file $FSIMG | grep 'big endian')\" != \"\" ]\n\tthen\n\t\tENDIANESS=\"-be\"\n\tfi\nfi\n\nif [ \"$ROOTFS\" == \"\" ]\nthen\n\tROOTFS=\"./cramfs-root\"\n\tBDIR=$ROOTFS\n\tI=1\n\n\twhile [ -e $ROOTFS ]\n\tdo\n\t\tROOTFS=$BDIR-$I\n\t\t((I=$I+1))\n\tdone\nfi\n\nFSIMG=$(readlink -f $FSIMG)\nROOTFS=$(readlink -f $ROOTFS)\n\n# Make sure we're operating out of the FMK directory\ncd $(dirname $(readlink -f $0))\n\nif [ \"$ENDIANESS\" == \"-be\" ]\nthen\n\t./src/cramfsswap/cramfsswap \"$FSIMG\" \"$FSIMG.le\"\nelse\n\tcp \"$FSIMG\" \"$FSIMG.le\"\nfi\n\nif [ -e \"$FSIMG.le\" ]\nthen\n\t# If this is an OpenRG firmware, try uncramfs-lzma first.\n\tif [ \"$(strings \"$FSIMG.le\" | grep openrg)\" != \"\" ]\n\tthen\n\t\t./src/uncramfs-lzma/uncramfs-lzma \"$ROOTFS\" \"$FSIMG.le\" 2>/dev/null\n\t\tif [ $? -eq 0 ]\n\t\tthen\n\t\t\t# Does not exist, will not be able to re-build the file system!\n\t\t\tMKFS=\"./src/uncramfs-lzma/mkcramfs-lzma\"\n\t\t\tfinish\n\t\t\texit 0\n\t\tfi\n\tfi\n\n\t./src/cramfs-2.x/cramfsck -x \"$ROOTFS\" \"$FSIMG.le\" 2>/dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tMKFS=\"./src/cramfs-2.x/mkcramfs\"\n\t\tfinish\n\t\texit 0\n\tfi\n\n\t./src/uncramfs/uncramfs \"$ROOTFS\" \"$FSIMG.le\" 2>/dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tMKFS=\"./src/cramfs-2.x/mkcramfs\"\n\t\tfinish\n\t\texit 0\n\tfi\n\n\t./src/uncramfs-lzma/uncramfs-lzma \"$ROOTFS\" \"$FSIMG.le\" 2>/dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\t# Does not exist, will not be able to re-build the file system!\n\t\tMKFS=\"./src/uncramfs-lzma/mkcramfs-lzma\"\n\t\tfinish\n\t\texit 0\n\tfi\nfi\n\necho \"File extraction failed!\"\nfinish\nexit 1\n"
  },
  {
    "path": "unsquashfs_all.sh",
    "content": "#!/bin/bash\n# Script to attempt to extract files from a SquashFS image using all of the available unsquashfs utilities in FMK until one is successful.\n#\n# Craig Heffner\n# 27 August 2011\n\nIMG=\"$1\"\nDIR=\"$2\"\n\nROOT=\"./src\"\nSUBDIRS=\"squashfs-2.1-r2 \\\nsquashfs-3.0 \\\nsquashfs-3.0-lzma-damn-small-variant \\\nothers/squashfs-2.0-nb4 \\\nothers/squashfs-3.0-e2100 \\\nothers/squashfs-3.2-r2 \\\nothers/squashfs-3.2-r2-lzma \\\nothers/squashfs-3.2-r2-lzma/squashfs3.2-r2/squashfs-tools \\\nothers/squashfs-3.2-r2-hg612-lzma \\\nothers/squashfs-3.2-r2-wnr1000 \\\nothers/squashfs-3.2-r2-rtn12 \\\nothers/squashfs-3.3 \\\nothers/squashfs-3.3-lzma/squashfs3.3/squashfs-tools \\\nothers/squashfs-3.3-grml-lzma/squashfs3.3/squashfs-tools \\\nothers/squashfs-3.4-cisco \\\nothers/squashfs-3.4-nb4 \\\nothers/squashfs-4.2-official \\\nothers/squashfs-4.2 \\\nothers/squashfs-4.0-lzma \\\nothers/squashfs-4.0-realtek \\\nothers/squashfs-hg55x-bin\"\nTIMEOUT=\"15\"\nMKFS=\"\"\nDEST=\"\"\n\nfunction wait_for_complete()\n{\n\tI=0\n\tPNAME=\"$1\"\n\n\twhile [ $I -lt $TIMEOUT ]\n\tdo\n\t\tsleep 1\n\n\t\tif [ \"$(pgrep $PNAME)\" == \"\" ]\n\t\tthen\n\t\t\tbreak\n\t\tfi\n\n\t\t((I=$I+1))\n\tdone\n\n\tif [ \"$I\" == \"$TIMEOUT\" ]\n\tthen\n\t\tkill -9 $(pgrep $PNAME) 2>/dev/null\n\tfi\n}\n\nif [ \"$IMG\" == \"\" ] || [ \"$IMG\" == \"-h\" ]\nthen\n\techo \"Usage: $0 <squashfs image> [output directory]\"\n\texit 1\nfi\n\nif [ \"$DIR\" == \"\" ]\nthen\n\tBDIR=\"./squashfs-root\"\n\tDIR=$BDIR\n\tI=1\n\n\twhile [ -e $DIR ]\n\tdo\n\t\tDIR=$BDIR-$I\n\t\t((I=$I+1))\n\tdone\nfi\n\nIMG=$(readlink -f $IMG)\nDIR=$(readlink -f $DIR)\n\n# Make sure we're operating out of the FMK directory\ncd $(dirname $(readlink -f $0))\n\nDEST=\"-dest $DIR\"\nMAJOR=$(./src/binwalk -m ./src/binwalk-*/src/magic.binwalk -l 1 \"$IMG\" | head -4 | tail -1 | sed -e 's/.*version //' | cut -d'.' -f1)\n\necho -e \"Attempting to extract SquashFS $MAJOR.X file system...\\n\"\n\nfor SUBDIR in $SUBDIRS\ndo\n\tif [ \"$(echo $SUBDIR | grep \"$MAJOR\\.\")\" == \"\" ]\n\tthen\n\t\techo \"Skipping $SUBDIR (wrong version)...\"\n\t\tcontinue\n\tfi\n\n\tunsquashfs=\"$ROOT/$SUBDIR/unsquashfs\"\n\tmksquashfs=\"$ROOT/$SUBDIR/mksquashfs\"\n\n\tif [ -e $unsquashfs ]\n\tthen\n\t\techo -ne \"\\nTrying $unsquashfs... \"\n\n\t\t$unsquashfs $DEST $IMG 2>/dev/null &\n\t\t#sleep $TIMEOUT && kill $! 1>&2 >/dev/null\n\t\twait_for_complete $unsquashfs\n\n\t\tif [ -d \"$DIR\" ]\n\t\tthen\n\t\t\tif [ \"$(ls $DIR)\" != \"\" ]\n\t\t\tthen\n\t\t\t\t# Most systems will have busybox - make sure it's a non-zero file size\n\t\t\t\tif [ -e \"$DIR/bin/sh\" ]\n\t\t\t\tthen\n\t\t\t\t\tif [ \"$(wc -c $DIR/bin/sh | cut -d' ' -f1)\" != \"0\" ]\n\t\t\t\t\tthen\n\t\t\t\t\t\tMKFS=\"$mksquashfs\"\n\t\t\t\t\tfi\n\t\t\t\telse\n\t\t\t\t\tMKFS=\"$mksquashfs\"\n\t\t\t\tfi\n\t\t\tfi\n\n\t\t\tif [ \"$MKFS\" == \"\" ]\n\t\t\tthen\n\t\t\t\trm -rf \"$DIR\"\n\t\t\tfi\n\t\tfi\n\tfi\n\t\n\tif [ \"$MKFS\" == \"\" ] && [ -e $unsquashfs-lzma ]\n\tthen\n\t\techo -ne \"\\nTrying $unsquashfs-lzma... \"\n\n\t\t$unsquashfs-lzma $DEST $IMG 2>/dev/null &\n\t\t#sleep $TIMEOUT && kill $! 1>&2 >/dev/null\n\t\twait_for_complete $unsquashfs-lzma\n\t\t\n\t\tif [ -d \"$DIR\" ]\n                then\n\t\t\tif [ \"$(ls $DIR)\" != \"\" ]\n\t\t\tthen\n\t\t\t\t# Most systems will have busybox - make sure it's a non-zero file size\n\t\t\t\tif [ -e \"$DIR/bin/sh\" ]\n\t\t\t\tthen\n\t\t\t\t\tif [ \"$(wc -c $DIR/bin/sh | cut -d' ' -f1)\" != \"0\" ]\n\t\t\t\t\tthen\n\t\t\t\t\t\tMKFS=\"$mksquashfs-lzma\"\n\t\t\t\t\tfi\n\t\t\t\telse\n                        \t\tMKFS=\"$mksquashfs-lzma\"\n\t\t\t\tfi\n\t\t\tfi\n\t\t\t\n\t\t\tif [ \"$MKFS\" == \"\" ]\n\t\t\tthen\n\t\t\t\trm -rf \"$DIR\"\n\t\t\tfi\n                fi\n\tfi\n\n\tif [ \"$MKFS\" != \"\" ]\n\tthen\n\t\techo \"File system sucessfully extracted!\"\n\t\techo \"MKFS=\\\"$MKFS\\\"\"\n\t\texit 0\n\tfi\ndone\n\necho \"File extraction failed!\"\nexit 1\n"
  }
]